import {z} from 'zod' export type StringNoEdgeSpaces = string; export type CountryCodeForRequest = string; export type SubdivisionCodeForRequest = string; export type PatchApiCoreKycProcessesIdentityArgs = {'X-On-Behalf-Of'?: string | undefined, 'X-Uphold-User-Ip'?: (string | string) | undefined, 'X-Uphold-User-Agent'?: StringNoEdgeSpaces | undefined, 'X-Uphold-User-Origin'?: StringNoEdgeSpaces | undefined, 'X-Uphold-User-Country'?: CountryCodeForRequest | undefined, 'X-Uphold-User-Subdivision'?: SubdivisionCodeForRequest | undefined, 'X-Uphold-User-City'?: StringNoEdgeSpaces | undefined, body: {type: 'document-submission', input?: ({media?: (Array<{context: 'photo-document-front' | 'photo-document-back' | 'photo-selfie' | 'photo-selfie-and-document-front' | 'video', fileId: string}>) | undefined}) | undefined, output?: ({provider?: string | undefined, document: {type: 'driving-license' | 'id-card' | 'passport' | 'residence-permit', number: string, country: string, expiresAt?: string | undefined}, person: {givenName: string, familyName?: string | undefined, birthdate: string, gender?: ('female' | 'male') | undefined, address?: ({country: string, subdivision?: string | undefined, city?: string | undefined, line1?: string | undefined, line2?: string | undefined, postalCode?: string | undefined}) | undefined}, verifiedAt: string}) | undefined} | {type: 'electronic-verification', input: {data: {givenName: string, familyName?: string | undefined, birthdate: string, citizenshipCountry: string, gender?: ('female' | 'male') | undefined, address?: ({country: string, subdivision?: string | undefined, city?: string | undefined, line1?: string | undefined, line2?: string | undefined, postalCode?: string | undefined}) | undefined}}, output?: ({provider?: string | undefined, verifiedAt: string}) | undefined}}; export type PatchApiCoreKycProcessesIdentityOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const kycProcessStatus = z.enum(["ok", "failed", "running", "pending", "exempt"]); export const kycProcessDependencies = z.array(z.enum(["profile", "email", "phone", "identity", "proof-of-address", "customer-due-diligence", "enhanced-due-diligence", "crypto-risk-assessment", "self-categorization-statement", "tax-details"])); export const kycIdentityNone = z.object({code: z.string(), status: kycProcessStatus, type: z.literal("none").optional(), verification: z.object({model: z.enum(["none", "partner-verified", "uphold-verified"]), method: z.enum(["automatic", "manual"]), triggers: z.array(z.enum(["profile", "identity"])).optional(), dependencies: kycProcessDependencies, submittable: z.boolean()}).optional()}); export const kycIdentityDocumentSubmission = z.object({code: z.string(), status: kycProcessStatus, type: z.literal("document-submission"), verification: z.object({model: z.enum(["none", "partner-verified", "uphold-verified"]), method: z.enum(["automatic", "manual"]), triggers: z.array(z.enum(["profile", "identity"])).optional(), dependencies: kycProcessDependencies, submittable: z.boolean()}).optional(), input: z.object({media: z.array(z.object({context: z.enum(["photo-document-front", "photo-document-back", "photo-selfie", "photo-selfie-and-document-front", "video"]), fileId: z.string()}))}).optional(), output: z.object({provider: z.string(), providerDetails: z.object({reasons: z.array(z.string()).optional()}).optional(), reason: z.enum(["data-mismatch", "duplicate", "underage", "provider-verification-rejected"]).optional(), document: z.object({type: z.enum(["driving-license", "id-card", "passport", "residence-permit", "unsupported"]), number: z.string(), country: z.string(), expiresAt: z.string().optional()}), person: z.object({givenName: z.string(), familyName: z.string().optional(), birthdate: z.string(), gender: z.enum(["female", "male"]).optional(), address: z.object({country: z.string(), subdivision: z.string().optional(), city: z.string().optional(), line1: z.string().optional(), line2: z.string().optional(), postalCode: z.string().optional()}).optional()}), verifiedAt: z.string()}).optional()}); export const kycIdentityElectronicVerification = z.object({code: z.string(), status: kycProcessStatus, type: z.literal("electronic-verification"), verification: z.object({model: z.enum(["none", "partner-verified", "uphold-verified"]), method: z.enum(["automatic", "manual"]), triggers: z.array(z.enum(["profile", "identity"])).optional(), dependencies: kycProcessDependencies, submittable: z.boolean()}).optional(), input: z.object({data: z.object({givenName: z.string(), familyName: z.string().optional(), birthdate: z.string(), citizenshipCountry: z.string(), gender: z.enum(["female", "male"]).optional(), address: z.object({country: z.string(), subdivision: z.string().optional(), city: z.string().optional(), line1: z.string().optional(), line2: z.string().optional(), postalCode: z.string().optional()}).optional()})}).optional(), output: z.object({provider: z.string(), reason: z.enum(["data-mismatch", "duplicate", "missing-declared-information", "underage"]).optional(), verifiedAt: z.string()}).optional()}); export const kycIdentity = z.discriminatedUnion("type", [kycIdentityNone, kycIdentityDocumentSubmission, kycIdentityElectronicVerification]); export const warning = z.object({code: z.string(), message: z.string(), details: z.record(z.string(), z.unknown()).optional()}); export const processWarnings = z.record(z.string(), z.array(warning)); export const patchApiCoreKycProcessesIdentityResponse = z.object({identity: kycIdentity, warnings: processWarnings.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 }; /** * Update identity * * PATCH /core/kyc/processes/identity */ export const patchApiCoreKycProcessesIdentity = async (args: PatchApiCoreKycProcessesIdentityArgs, options?: PatchApiCoreKycProcessesIdentityOptions) => { const {baseUrl = "https://api.enterprise.sandbox.uphold.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-On-Behalf-Of'] != null) headers.set("X-On-Behalf-Of", String(args['X-On-Behalf-Of'])) if (args['X-Uphold-User-Ip'] != null) headers.set("X-Uphold-User-Ip", String(args['X-Uphold-User-Ip'])) if (args['X-Uphold-User-Agent'] != null) headers.set("X-Uphold-User-Agent", String(args['X-Uphold-User-Agent'])) if (args['X-Uphold-User-Origin'] != null) headers.set("X-Uphold-User-Origin", String(args['X-Uphold-User-Origin'])) if (args['X-Uphold-User-Country'] != null) headers.set("X-Uphold-User-Country", String(args['X-Uphold-User-Country'])) if (args['X-Uphold-User-Subdivision'] != null) headers.set("X-Uphold-User-Subdivision", String(args['X-Uphold-User-Subdivision'])) if (args['X-Uphold-User-City'] != null) headers.set("X-Uphold-User-City", String(args['X-Uphold-User-City'])) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/core/kyc/processes/identity${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiCoreKycProcessesIdentityResponse, await res.json()) };