import {z} from 'zod' export type StringNoEdgeSpaces = string; export type CountryCodeForRequest = string; export type SubdivisionCodeForRequest = string; export type GetApiCoreKybAssociatedPersonsPersonIdArgs = {personId: string, '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}; export type GetApiCoreKybAssociatedPersonsPersonIdOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const kybProcessStatus = z.enum(["ok", "failed", "running", "pending", "exempt"]); export const kybAssociatedPersonProfile = z.object({code: z.literal("profile"), status: kybProcessStatus, input: z.discriminatedUnion("type", [z.object({fullName: z.string().optional(), role: z.string().optional(), address: z.object({country: z.string().optional(), subdivision: z.string().optional(), city: z.string().optional(), line1: z.string().optional(), line2: z.string().optional(), postalCode: z.string().optional()}).optional(), birthdate: z.string().optional(), birthplace: z.object({town: z.string(), country: z.string()}).optional(), legalIds: z.array(z.object({type: z.literal("tax-id").optional(), country: z.string(), id: z.string()})).optional(), type: z.literal("beneficial-owner"), ownershipPercentage: z.number().gt(0).lte(100).optional()}), z.object({fullName: z.string().optional(), role: z.string().optional(), address: z.object({country: z.string().optional(), subdivision: z.string().optional(), city: z.string().optional(), line1: z.string().optional(), line2: z.string().optional(), postalCode: z.string().optional()}).optional(), birthdate: z.string().optional(), birthplace: z.object({town: z.string(), country: z.string()}).optional(), legalIds: z.array(z.object({type: z.literal("tax-id").optional(), country: z.string(), id: z.string()})).optional(), type: z.literal("authorized-signer")}), z.object({fullName: z.string().optional(), role: z.string().optional(), address: z.object({country: z.string().optional(), subdivision: z.string().optional(), city: z.string().optional(), line1: z.string().optional(), line2: z.string().optional(), postalCode: z.string().optional()}).optional(), birthdate: z.string().optional(), birthplace: z.object({town: z.string(), country: z.string()}).optional(), legalIds: z.array(z.object({type: z.literal("tax-id").optional(), country: z.string(), id: z.string()})).optional(), type: z.literal("beneficial-owner-and-authorized-signer"), ownershipPercentage: z.number().gt(0).lte(100).optional()})]).optional()}); export const kybAssociatedPersonIdentity = z.discriminatedUnion("type", [z.object({code: z.literal("identity"), status: kybProcessStatus, type: z.literal("none")}), z.object({code: z.literal("identity"), status: kybProcessStatus, type: z.literal("document-submission"), input: z.object({media: z.array(z.object({context: z.enum(["document-front", "document-back"]).optional(), fileId: z.string().optional()})).optional()}).optional(), output: z.object({provider: z.string(), reason: z.enum(["data-mismatch", "document-expired", "document-not-readable", "duplicate", "missing-declared-information", "underage", "timeout", "unknown"]).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()}).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()}).optional(), verifiedAt: z.string().optional()}).optional()})]); export const kybAssociatedPersonProofOfAddress = z.discriminatedUnion("type", [z.object({code: z.literal("proof-of-address"), status: kybProcessStatus, type: z.literal("none")}), z.object({code: z.literal("proof-of-address"), status: kybProcessStatus, type: z.literal("document-submission"), input: z.object({media: z.array(z.object({context: z.literal("address-proof").optional(), fileId: z.string().optional()})).optional()}).optional(), output: z.object({provider: z.string(), reason: z.enum(["address-mismatch", "name-mismatch"]).optional(), person: z.object({givenName: z.string(), familyName: z.string().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()})}), verifiedAt: z.string()}).optional()})]); export const kybAssociatedPersonProcesses = z.object({profile: kybAssociatedPersonProfile, identity: kybAssociatedPersonIdentity, proofOfAddress: kybAssociatedPersonProofOfAddress}); export const kybAssociatedPerson = z.object({id: z.string(), processes: kybAssociatedPersonProcesses, createdAt: z.string()}); export const getApiCoreKybAssociatedPersonsPersonIdResponse = z.object({associatedPerson: kybAssociatedPerson}); 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 }; /** * Get associated person * * GET /core/kyb/associated-persons/{personId} */ export const getApiCoreKybAssociatedPersonsPersonId = async (args: GetApiCoreKybAssociatedPersonsPersonIdArgs, options?: GetApiCoreKybAssociatedPersonsPersonIdOptions) => { const {baseUrl = "https://api.enterprise.sandbox.uphold.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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/kyb/associated-persons/${encodeURIComponent(String(args.personId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiCoreKybAssociatedPersonsPersonIdResponse, await res.json()) };