import {z} from 'zod' export type CompleteComplianceForm = {pci_saq_a: {ip_address?: string | undefined, name?: string | undefined, signed_at?: string | undefined, title?: string | undefined, user_agent?: string | undefined}}; export type UpdateApiComplianceFormsComplianceFormIdArgs = {body: CompleteComplianceForm}; export type UpdateApiComplianceFormsComplianceFormIdOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const id = z.string().min(1); export const createdAt = z.string(); export const updatedAt = z.string(); export const tags = z.record(z.string(), z.unknown()).nullable(); export const complianceForm = z.object({id: id.optional(), created_at: createdAt.optional(), updated_at: updatedAt.optional(), application: z.string().optional(), compliance_form_template: z.string().optional(), due_at: z.string().optional(), files: z.object({signed_file: z.string().nullable().optional(), unsigned_file: z.string().optional()}).optional(), linked_to: z.string().optional(), linked_type: z.literal("MERCHANT").optional(), pci_saq_a: z.object({ip_address: z.string().nullable().optional(), is_accepted: z.boolean().optional(), name: z.string().nullable().optional(), signed_at: z.string().nullable().optional(), title: z.string().nullable().optional(), user_agent: z.string().nullable().optional()}).optional(), state: z.enum(["INCOMPLETE", "OVERDUE", "COMPLETE", "EXPIRED", "INVALID"]).optional(), tags: tags.optional(), type: z.literal("PCI_SAQ_A").optional(), valid_from: z.string().nullable().optional(), valid_until: z.string().nullable().optional(), version: z.string().optional()}); 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 }; /** * Complete a Compliance Form * * PUT /compliance_forms/{compliance_form_id} */ export const updateApiComplianceFormsComplianceFormId = async (args: UpdateApiComplianceFormsComplianceFormIdArgs, options?: UpdateApiComplianceFormsComplianceFormIdOptions) => { const {baseUrl = "https://finix.sandbox-payments-api.com", fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/compliance_forms/${encodeURIComponent(String(args.compliance_form_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(complianceForm, await res.json()) };