feat: allow multipart requests for public api

Adds support for multipart/form-data requests in the public api
allowing documents to be uploaded without having to perform a secondary
request.

Need to rollout further endpoints for envelopes and templates.

Need to change how we store files to not use `putFileServerSide`
This commit is contained in:
Lucas Smith
2025-11-02 23:26:43 +11:00
parent 7e38d06ef5
commit a6e923dd8a
19 changed files with 1154 additions and 252 deletions

View File

@ -1,17 +1,23 @@
import { createTRPCClient, httpBatchLink, httpLink, splitLink } from '@trpc/client';
import SuperJSON from 'superjson';
import {
createTRPCClient,
httpBatchLink,
httpLink,
isNonJsonSerializable,
splitLink,
} from '@trpc/client';
import { getBaseUrl } from '@documenso/lib/universal/get-base-url';
import type { AppRouter } from '../server/router';
import { dataTransformer } from '../utils/data-transformer';
export const trpc = createTRPCClient<AppRouter>({
links: [
splitLink({
condition: (op) => op.context.skipBatch === true,
condition: (op) => op.context.skipBatch === true || isNonJsonSerializable(op.input),
true: httpLink({
url: `${getBaseUrl()}/api/trpc`,
transformer: SuperJSON,
transformer: dataTransformer,
headers: (opts) => {
if (typeof opts.op.context.teamId === 'string') {
return {
@ -24,7 +30,7 @@ export const trpc = createTRPCClient<AppRouter>({
}),
false: httpBatchLink({
url: `${getBaseUrl()}/api/trpc`,
transformer: SuperJSON,
transformer: dataTransformer,
headers: (opts) => {
const operationWithTeamId = opts.opList.find(
(op) => op.context.teamId && typeof op.context.teamId === 'string',