import {z} from 'zod' export type StringNoEdgeSpaces = string; export type CountryCodeForRequest = string; export type SubdivisionCodeForRequest = string; export type GetApiCoreUsersMeArgs = {'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 GetApiCoreUsersMeOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; 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 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()}); export const user = z.discriminatedUnion("type", [z.object({id: z.string(), type: z.literal("individual"), email: z.string(), fullName: z.string().optional(), birthdate: z.string().optional(), primaryCitizenship: z.string(), citizenshipCountry: 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()}), phone: z.object({number: z.string(), country: z.string()}).optional(), createdAt: z.string(), updatedAt: z.string()}), z.object({id: z.string(), type: z.literal("business"), email: z.string(), 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()}).optional(), operatingAddress: address, name: 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()}), createdAt: z.string(), updatedAt: z.string()})]); export const getApiCoreUsersMeResponse = z.object({user: user}); 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 user * * GET /core/users/me */ export const getApiCoreUsersMe = async (args: GetApiCoreUsersMeArgs, options?: GetApiCoreUsersMeOptions) => { 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/users/me${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(getApiCoreUsersMeResponse, await res.json()) };