import {z} from 'zod' export type PostBeneficiariesBody = {first_name: string, last_name: string, email?: string | undefined, phone_number?: string | undefined, address_one: string, address_two?: string | undefined, city: string, zip?: string | undefined, jurisdiction_code: 'US-AL' | 'US-AK' | 'US-AZ' | 'US-AR' | 'US-CA' | 'US-CO' | 'US-CT' | 'US-DE' | 'US-FL' | 'US-GA' | 'US-HI' | 'US-ID' | 'US-IL' | 'US-IN' | 'US-IA' | 'US-KS' | 'US-KY' | 'US-LA' | 'US-ME' | 'US-MD' | 'US-MA' | 'US-MI' | 'US-MN' | 'US-MS' | 'US-MO' | 'US-MT' | 'US-NE' | 'US-NV' | 'US-NH' | 'US-NJ' | 'US-NM' | 'US-NY' | 'US-NC' | 'US-ND' | 'US-OH' | 'US-OK' | 'US-OR' | 'US-PA' | 'US-RI' | 'US-SC' | 'US-SD' | 'US-TN' | 'US-TX' | 'US-UT' | 'US-VT' | 'US-VA' | 'US-WA' | 'US-WV' | 'US-WI' | 'US-WY' | 'US-DC' | 'US-AS' | 'US-GU' | 'US-MP' | 'US-PR' | 'US-UM' | 'US-VI', date_of_birth: string, tax_id?: string | undefined, id_number_type?: ('us_drivers_license' | 'us_passport' | 'us_passport_card' | 'us_permanent_resident_card' | 'us_border_crossing_card' | 'us_alien_card' | 'us_id_card' | 'non_us_passport' | 'non_us_other' | 'passport' | 'eu_drivers_license' | 'national_id' | 'legal_entity_identifier' | 'chamber_of_commerce_number' | 'value_added_tax_number') | undefined, id_number?: string | undefined, citizenship_code?: ('AD' | 'AE' | 'AF' | 'AG' | 'AI' | 'AL' | 'AM' | 'AO' | 'AQ' | 'AR' | 'AS' | 'AT' | 'AU' | 'AW' | 'AX' | 'AZ' | 'BA' | 'BB' | 'BD' | 'BE' | 'BF' | 'BG' | 'BH' | 'BI' | 'BJ' | 'BL' | 'BM' | 'BN' | 'BO' | 'BQ' | 'BR' | 'BS' | 'BT' | 'BV' | 'BW' | 'BY' | 'BZ' | 'CA' | 'CC' | 'CD' | 'CF' | 'CG' | 'CH' | 'CI' | 'CK' | 'CL' | 'CM' | 'CN' | 'CO' | 'CR' | 'CU' | 'CV' | 'CW' | 'CX' | 'CY' | 'CZ' | 'DE' | 'DJ' | 'DK' | 'DM' | 'DO' | 'DZ' | 'EC' | 'EE' | 'EG' | 'EH' | 'ER' | 'ES' | 'ET' | 'FI' | 'FJ' | 'FK' | 'FM' | 'FO' | 'FR' | 'GA' | 'GB' | 'GD' | 'GE' | 'GF' | 'GG' | 'GH' | 'GI' | 'GL' | 'GM' | 'GN' | 'GP' | 'GQ' | 'GR' | 'GS' | 'GT' | 'GU' | 'GW' | 'GY' | 'HK' | 'HM' | 'HN' | 'HR' | 'HT' | 'HU' | 'ID' | 'IE' | 'IL' | 'IM' | 'IN' | 'IO' | 'IQ' | 'IR' | 'IS' | 'IT' | 'JE' | 'JM' | 'JO' | 'JP' | 'KE' | 'KG' | 'KH' | 'KI' | 'KM' | 'KN' | 'KP' | 'KR' | 'KW' | 'KY' | 'KZ' | 'LA' | 'LB' | 'LC' | 'LI' | 'LK' | 'LR' | 'LS' | 'LT' | 'LU' | 'LV' | 'LY' | 'MA' | 'MC' | 'MD' | 'ME' | 'MF' | 'MG' | 'MH' | 'MK' | 'ML' | 'MM' | 'MN' | 'MO' | 'MP' | 'MQ' | 'MR' | 'MS' | 'MT' | 'MU' | 'MV' | 'MW' | 'MX' | 'MY' | 'MZ' | 'NA' | 'NC' | 'NE' | 'NF' | 'NG' | 'NI' | 'NL' | 'NO' | 'NP' | 'NR' | 'NU' | 'NZ' | 'OM' | 'PA' | 'PE' | 'PF' | 'PG' | 'PH' | 'PK' | 'PL' | 'PM' | 'PN' | 'PR' | 'PS' | 'PT' | 'PW' | 'PY' | 'QA' | 'RE' | 'RO' | 'RS' | 'RW' | 'SA' | 'SB' | 'SC' | 'SD' | 'SE' | 'SG' | 'SH' | 'SI' | 'SJ' | 'SK' | 'SL' | 'SM' | 'SN' | 'SO' | 'SR' | 'SS' | 'ST' | 'SV' | 'SX' | 'SY' | 'SZ' | 'TC' | 'TD' | 'TF' | 'TG' | 'TH' | 'TJ' | 'TK' | 'TL' | 'TM' | 'TN' | 'TO' | 'TR' | 'TT' | 'TV' | 'TW' | 'TZ' | 'UA' | 'UG' | 'UM' | 'US' | 'UY' | 'UZ' | 'VA' | 'VC' | 'VE' | 'VG' | 'VI' | 'VN' | 'VU' | 'WF' | 'WS' | 'YE' | 'YT' | 'ZA' | 'ZM' | 'ZW') | undefined, non_us_other_type?: string | undefined, id_issuing_authority?: string | undefined}; export type CreateApiParticipantsBeneficiariesNewArgs = {'X-SCX-SIGNED': string, 'X-SCX-TIMESTAMP': string, 'X-Request-Id'?: string | undefined, body: PostBeneficiariesBody}; export type CreateApiParticipantsBeneficiariesNewOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, apiPassphrase?: string | undefined, fetch?: typeof fetch | undefined}; export const postBeneficiariesResponse = z.object({message: z.object({first_name: z.string().optional(), last_name: z.string().optional(), email: z.string().optional(), address_one: z.string().optional(), address_two: z.string().optional(), jurisdiction_code: z.enum(["US-AL", "US-AK", "US-AZ", "US-AR", "US-CA", "US-CO", "US-CT", "US-DE", "US-FL", "US-GA", "US-HI", "US-ID", "US-IL", "US-IN", "US-IA", "US-KS", "US-KY", "US-LA", "US-ME", "US-MD", "US-MA", "US-MI", "US-MN", "US-MS", "US-MO", "US-MT", "US-NE", "US-NV", "US-NH", "US-NJ", "US-NM", "US-NY", "US-NC", "US-ND", "US-OH", "US-OK", "US-OR", "US-PA", "US-RI", "US-SC", "US-SD", "US-TN", "US-TX", "US-UT", "US-VT", "US-VA", "US-WA", "US-WV", "US-WI", "US-WY", "US-DC", "US-AS", "US-GU", "US-MP", "US-PR", "US-UM", "US-VI"]).optional(), city: z.string().optional(), zip: z.string().optional(), date_of_birth: z.string().optional(), id_number_type: z.enum(["us_drivers_license", "us_passport", "us_passport_card", "us_permanent_resident_card", "us_border_crossing_card", "us_alien_card", "us_id_card", "non_us_passport", "non_us_other", "passport", "eu_drivers_license", "national_id", "legal_entity_identifier", "chamber_of_commerce_number", "value_added_tax_number"]).optional(), id_number: z.string().optional(), citizenship_code: z.enum(["AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW"]).optional(), non_us_other_type: z.string().optional(), id_issuing_authority: z.string().optional(), phone_number: z.string().optional(), platform_code: z.string().optional(), participant_code: z.string().optional()}).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 }; /** * Create beneficiary * * POST /participants/beneficiaries/new */ export const createApiParticipantsBeneficiariesNew = async (args: CreateApiParticipantsBeneficiariesNewArgs, options?: CreateApiParticipantsBeneficiariesNewOptions) => { const {baseUrl = "https://api.cert.zerohash.com", fetch: fetchFn = fetch, apiKey, apiPassphrase} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-SCX-SIGNED'] != null) headers.set("X-SCX-SIGNED", String(args['X-SCX-SIGNED'])) if (args['X-SCX-TIMESTAMP'] != null) headers.set("X-SCX-TIMESTAMP", String(args['X-SCX-TIMESTAMP'])) if (args['X-Request-Id'] != null) headers.set("X-Request-Id", String(args['X-Request-Id'])) if (apiKey !== undefined) headers.set("X-SCX-API-KEY", apiKey) if (apiPassphrase !== undefined) headers.set("X-SCX-PASSPHRASE", apiPassphrase) const url = `${baseUrl.replace(/\/+$/, '')}/participants/beneficiaries/new${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(postBeneficiariesResponse, await res.json()) };