import {z} from 'zod' export type KrakenEmbedFullName = {first_name: string, middle_name?: (string | null) | undefined, last_name: string}; export type KrakenEmbedIdentityDocumentType = 'passport' | 'drivers_license' | 'id_card' | 'residence_card' | 'special_permanent_residence_card'; export type KrakenEmbedCountryCode = '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' | 'RU' | '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' | 'AC' | 'AN' | 'AP' | 'CP' | 'DG' | 'EA' | 'EU' | 'IC' | 'JX' | 'TA' | 'QO' | 'XK' | '0C'; export type KrakenEmbedResidenceDocumentType = 'bank_statement' | 'credit_card_statement' | 'employer_letter_or_work_contract' | 'government_issued_document' | 'home_or_rental_insurance' | 'internet_or_cable_bill' | 'mobile_phone_bill' | 'mortgage_statement' | 'official_government_letter' | 'passport_address_page' | 'rental_or_lease_agreement' | 'residence_certificate' | 'social_insurance_payment_receipt' | 'tax_receipt' | 'tax_return' | 'utility_bill' | 'other'; export type CreateApiV1KrakenEmbedUsersUserIdVerificationUrlsArgs = {user_id: string, 'privy-app-id': string, body: {type: 'identity_document', metadata: {verifier: string, verified_at: string, verifier_response: unknown, external_verification_id?: (string | null) | undefined, expiration_date?: (string | null) | undefined, identity: {full_name: KrakenEmbedFullName, date_of_birth: string}, document_type: KrakenEmbedIdentityDocumentType, document_number: string, issuing_country: KrakenEmbedCountryCode, nationality?: (KrakenEmbedCountryCode | null) | undefined}, front_url: string, back_url?: (string | null) | undefined, verifier_response_url?: (string | null) | undefined} | {type: 'residence_document', metadata: {verifier: string, verified_at: string, verifier_response: unknown, external_verification_id?: (string | null) | undefined, expiration_date?: (string | null) | undefined, address: {line1: string, line2?: (string | null) | undefined, city: string, postal_code: string, province?: (string | null) | undefined, country: KrakenEmbedCountryCode}, document_type: KrakenEmbedResidenceDocumentType}, document_url: string, verifier_response_url?: (string | null) | undefined} | {type: 'tax_id_document', metadata: {verifier: string, verified_at: string, verifier_response: unknown, external_verification_id?: (string | null) | undefined, expiration_date?: (string | null) | undefined, tax_id_type: 'ssn' | 'sin' | 'cpf' | 'curp' | 'tax_identification_number' | 'national_insurance_number' | 'personal_public_service_number' | 'individual_taxpayer_identification_number', document_type: 'tax_return' | 'other', country: KrakenEmbedCountryCode}, tax_id_url: string, verifier_response_url?: (string | null) | undefined} | {type: 'selfie', metadata: {verifier: string, verified_at: string, verifier_response: unknown, external_verification_id?: (string | null) | undefined, expiration_date?: (string | null) | undefined, selfie_type: 'selfie' | 'selfie_capture_video'}, selfie_url: string, verifier_response_url?: (string | null) | undefined} | {type: 'watchlists', metadata: {sanctions?: ({verifier: string, verified_at: string, verifier_response: unknown, external_verification_id?: (string | null) | undefined, expiration_date?: (string | null) | undefined, status: 'Cleared' | 'Matched'} | null) | undefined, negative_news?: ({verifier: string, verified_at: string, verifier_response: unknown, external_verification_id?: (string | null) | undefined, expiration_date?: (string | null) | undefined, status: 'Cleared' | 'Matched'} | null) | undefined, pep?: ({verifier: string, verified_at: string, verifier_response: unknown, external_verification_id?: (string | null) | undefined, expiration_date?: (string | null) | undefined, status: 'Cleared' | 'Matched'} | null) | undefined}, verifier_response_url?: (string | null) | undefined, sanctions_verifier_response_url?: (string | null) | undefined, pep_verifier_response_url?: (string | null) | undefined, negative_news_verifier_response_url?: (string | null) | undefined}}; export type CreateApiV1KrakenEmbedUsersUserIdVerificationUrlsOptions = {baseUrl?: string | undefined, appSecretAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const createApiV1KrakenEmbedUsersUserIdVerificationUrlsResponse = z.object({data: z.object({result: z.object({verification_id: z.string()})})}); 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 }; /** * Submit User Verification from URLs * * POST /v1/kraken_embed/users/{user_id}/verification_urls */ export const createApiV1KrakenEmbedUsersUserIdVerificationUrls = async (args: CreateApiV1KrakenEmbedUsersUserIdVerificationUrlsArgs, options?: CreateApiV1KrakenEmbedUsersUserIdVerificationUrlsOptions) => { const {baseUrl = "https://api.privy.io", fetch: fetchFn = fetch, appSecretAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['privy-app-id'] != null) headers.set("privy-app-id", String(args['privy-app-id'])) if (appSecretAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${appSecretAuth.username}:${appSecretAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/kraken_embed/users/${encodeURIComponent(String(args.user_id))}/verification_urls${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(createApiV1KrakenEmbedUsersUserIdVerificationUrlsResponse, await res.json()) };