import {z} from 'zod' export type CreateApiApiV1MerchantsIdDocumentsArgs = {id: string, body: BodyInit}; export type CreateApiApiV1MerchantsIdDocumentsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const documentUploadResponse = z.object({success: z.boolean(), data: z.object({id: z.string(), documentType: z.union([z.literal("ARTICLES_OF_INCORPORATION"), z.literal("BOARD_RESOLUTION"), z.literal("BUSINESS_BANK_STATEMENT"), z.literal("BUSINESS_DOCUMENTS"), z.literal("BUSINESS_PROOF_OF_ADDRESS"), z.literal("BUSINESS_TAX_ID"), z.literal("CERTIFICATE_OF_INCORPORATION"), z.literal("CERTIFICATE_OF_REGISTRATION"), z.literal("CORPORATE_DOCUMENTS_PACK"), z.literal("MEMORANDUM_AND_ARTICLES"), z.literal("ORGANIZATION_CHART"), z.literal("PARTNERSHIP_AGREEMENT"), z.literal("POWER_OF_ATTORNEY"), z.literal("PROOF_OF_ADDRESS"), z.literal("PROOF_OF_TAX_STATUS"), z.literal("SOURCE_OF_FUNDS"), z.literal("SOURCE_OF_WEALTH")]), fileName: z.string(), uploadedAt: z.string()})}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Upload a document for a merchant. Requires multipart/form-data with fields: file (binary) and documentType (string) * * POST /api/v1/merchants/{id}/documents */ export const createApiApiV1MerchantsIdDocuments = async (args: CreateApiApiV1MerchantsIdDocumentsArgs, options?: CreateApiApiV1MerchantsIdDocumentsOptions) => { const {baseUrl = "https://core.quidkey.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/merchants/${encodeURIComponent(String(args.id))}/documents${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(documentUploadResponse, await res.json()) };