import {z} from 'zod' export type StringNoEdgeSpaces = string; export type CountryCodeForRequest = string; export type SubdivisionCodeForRequest = string; export type KybProfileIndustryBase = {sector: 'financial-institutions-and-money-services', subSector?: ('money-transmitters' | 'remittance-services' | 'vasp-casp' | 'payment-processors' | 'fx-providers' | 'other-regulated-nbfi') | undefined} | {sector: 'crypto-services-and-products', subSector?: ('exchanges' | 'custodial-wallet-providers' | 'non-custodial-wallet-providers' | 'miners' | 'nft-platforms' | 'defi-projects') | undefined} | {sector: 'personal-investment-vehicles', subSector?: ('private-trusts' | 'roth-ira' | 'llc-spe-for-holding-assets') | undefined} | {sector: 'family-offices-and-investment-funds', subSector?: ('family-offices' | 'pooled-investment-vehicles' | 'private-investment-funds') | undefined} | {sector: 'professional-services', subSector?: ('law-firms' | 'accounting-firms' | 'consultants' | 'company-formation-or-secretarial-services') | undefined} | {sector: 'technology-and-software', subSector?: ('it-services' | 'saas' | 'gaming-studios' | 'cybersecurity' | 'data-analytics' | 'ai-firms') | undefined} | {sector: 'ecommerce-and-retail', subSector?: ('online-marketplaces' | 'merchants' | 'wholesalers' | 'direct-to-consumer-retailers') | undefined} | {sector: 'real-estate-and-property-management', subSector?: ('brokerages' | 'property-developers' | 'management-companies' | 'investment-vehicles') | undefined} | {sector: 'high-value-goods-and-luxury-dealers', subSector?: ('jewelry' | 'art' | 'precious-metals' | 'automobiles' | 'auction-houses') | undefined}; export type PatchApiCoreKybProcessesProfileArgs = {'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: {input: {legalEntityName?: string | undefined, formationDate?: string | undefined, industry?: (KybProfileIndustryBase | {sector: 'other', otherSector?: string | undefined}) | undefined, legalIds?: (Array<{type?: ('tax-id' | 'registration-id') | undefined, id?: string | undefined, country?: string | undefined}>) | undefined, registrationAddress?: ({subdivision?: string | undefined, city?: string | undefined, line1?: string | undefined, line2?: (StringNoEdgeSpaces | null) | undefined, postalCode?: string | undefined}) | undefined, operatingAddress?: ({subdivision?: string | undefined, city?: string | undefined, line1?: string | undefined, line2?: (StringNoEdgeSpaces | null) | undefined, postalCode?: string | undefined}) | undefined}}}; export type PatchApiCoreKybProcessesProfileOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const kybProcessStatus = z.enum(["ok", "failed", "running", "pending", "exempt"]); export const businessLegalEntityType = z.enum(["government-entity", "non-profit", "partnership", "private-limited-company", "public-company", "sole-proprietor"]); export const kybProfileIndustryBase = z.union([z.object({sector: z.literal("financial-institutions-and-money-services"), subSector: z.enum(["money-transmitters", "remittance-services", "vasp-casp", "payment-processors", "fx-providers", "other-regulated-nbfi"]).optional()}), z.object({sector: z.literal("crypto-services-and-products"), subSector: z.enum(["exchanges", "custodial-wallet-providers", "non-custodial-wallet-providers", "miners", "nft-platforms", "defi-projects"]).optional()}), z.object({sector: z.literal("personal-investment-vehicles"), subSector: z.enum(["private-trusts", "roth-ira", "llc-spe-for-holding-assets"]).optional()}), z.object({sector: z.literal("family-offices-and-investment-funds"), subSector: z.enum(["family-offices", "pooled-investment-vehicles", "private-investment-funds"]).optional()}), z.object({sector: z.literal("professional-services"), subSector: z.enum(["law-firms", "accounting-firms", "consultants", "company-formation-or-secretarial-services"]).optional()}), z.object({sector: z.literal("technology-and-software"), subSector: z.enum(["it-services", "saas", "gaming-studios", "cybersecurity", "data-analytics", "ai-firms"]).optional()}), z.object({sector: z.literal("ecommerce-and-retail"), subSector: z.enum(["online-marketplaces", "merchants", "wholesalers", "direct-to-consumer-retailers"]).optional()}), z.object({sector: z.literal("real-estate-and-property-management"), subSector: z.enum(["brokerages", "property-developers", "management-companies", "investment-vehicles"]).optional()}), z.object({sector: z.literal("high-value-goods-and-luxury-dealers"), subSector: z.enum(["jewelry", "art", "precious-metals", "automobiles", "auction-houses"]).optional()})]); export const kybProfileIndustry = z.union([kybProfileIndustryBase, z.object({sector: z.literal("other"), otherSector: z.string().optional()})]); export const kybProfile = z.object({code: z.literal("profile"), status: kybProcessStatus, input: z.object({legalEntityType: businessLegalEntityType, legalEntityName: z.string().optional(), formationDate: z.string().optional(), industry: kybProfileIndustry.optional(), legalIds: z.array(z.object({type: z.enum(["tax-id", "registration-id"]), id: z.string(), country: z.string()})).optional(), registrationAddress: 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()}), operatingAddress: 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()}); export const patchApiCoreKybProcessesProfileResponse = z.object({profile: kybProfile}); 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 profile * * PATCH /core/kyb/processes/profile */ export const patchApiCoreKybProcessesProfile = async (args: PatchApiCoreKybProcessesProfileArgs, options?: PatchApiCoreKybProcessesProfileOptions) => { 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/kyb/processes/profile${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(patchApiCoreKybProcessesProfileResponse, await res.json()) };