import {z} from 'zod' export type PinFormat = {length?: number | undefined, prefix?: string | undefined, symbols?: boolean | undefined, numbers?: boolean | undefined, characters?: boolean | undefined, barcode?: boolean | undefined}; export type PinGenerator = {format?: PinFormat | undefined, pin?: ({value?: string | undefined, barcode_128?: string | undefined}) | undefined}; export type TokenGenerator = {format?: ({length?: number | undefined, prefix?: string | undefined, symbols?: boolean | undefined, numbers?: boolean | undefined, characters?: boolean | undefined, barcode?: boolean | undefined}) | undefined, expires_after_transaction?: boolean | undefined, expires_in: number, token?: ({value?: string | undefined, barcode_128?: string | undefined}) | undefined}; export type CreateApiAccountsAidWalletsCardsArgs = {aid: unknown, body: {brand?: string | undefined, masked_pan?: string | undefined, expiry_date?: unknown | undefined, type?: ('Credit' | 'Debit' | 'Credit Card' | 'Debit Card' | 'Prepaid') | undefined, region?: ('domestic' | 'eea' | 'eea-uk' | 'europe' | 'inter') | undefined, country?: unknown | undefined, product_platform?: ('consumer' | 'commercial') | undefined, issuing_bank?: string | undefined, acquirer_transaction_type?: ('3DSECURE' | 'SSL') | undefined, acquirer_stan?: string | undefined, acquirer_terminal_id?: string | undefined, acquirer_transaction_time?: string | undefined, authentication_status?: ('Y' | 'A' | 'U' | 'N') | undefined, three_ds_version?: string | undefined, three_ds_server_trans_id?: string | undefined, eci?: string | undefined, payment_system_type?: string | undefined, payment_token?: string | undefined, payment_token_id?: string | undefined, recurrence_token?: string | undefined, recurrence_token_id?: string | undefined, card_holder_tokenization_consent?: ('opt_in' | 'opt_out') | undefined, entry_method?: ('chip' | 'contactless' | 'magstripe') | undefined, pin?: PinGenerator | undefined, card_token?: TokenGenerator | undefined}}; export type CreateApiAccountsAidWalletsCardsOptions = {baseUrl?: string | undefined, JWT?: string | undefined, fetch?: typeof fetch | undefined}; export const pinFormat = z.object({length: z.number().int().gte(4).optional(), prefix: z.string().max(12).optional(), symbols: z.boolean().optional(), numbers: z.boolean().optional(), characters: z.boolean().optional(), barcode: z.boolean().optional()}); export const pinGenerator = z.object({format: pinFormat.optional(), pin: z.object({value: z.string().max(48).optional(), barcode_128: z.string().optional()}).optional()}); export const tokenGenerator = z.object({format: z.object({length: z.number().int().gte(6).optional(), prefix: z.string().max(12).optional(), symbols: z.boolean().optional(), numbers: z.boolean().optional(), characters: z.boolean().optional(), barcode: z.boolean().optional()}).optional(), expires_after_transaction: z.boolean().optional(), expires_in: z.number().int().gte(1), token: z.object({value: z.string().max(48).optional(), barcode_128: z.string().optional()}).optional()}); export const createApiAccountsAidWalletsCardsResponse = z.object({brand: z.string().optional(), masked_pan: z.string().optional(), expiry_date: z.string().optional(), type: z.enum(["Credit", "Debit", "Credit Card", "Debit Card", "Prepaid"]).optional(), region: z.enum(["domestic", "eea", "eea-uk", "europe", "inter"]).optional(), country: z.string().optional(), product_platform: z.enum(["consumer", "commercial"]).optional(), issuing_bank: z.string().optional(), acquirer_transaction_type: z.enum(["3DSECURE", "SSL"]).optional(), acquirer_stan: z.string().optional(), acquirer_terminal_id: z.string().optional(), acquirer_transaction_time: z.string().optional(), authentication_status: z.enum(["Y", "A", "U", "N"]).optional(), three_ds_version: z.string().optional(), three_ds_server_trans_id: z.string().optional(), eci: z.string().optional(), payment_system_type: z.string().optional(), payment_token: z.string().optional(), payment_token_id: z.string().optional(), recurrence_token: z.string().optional(), recurrence_token_id: z.string().optional(), card_holder_tokenization_consent: z.enum(["opt_in", "opt_out"]).optional(), entry_method: z.enum(["chip", "contactless", "magstripe"]).optional(), pin: pinGenerator.optional(), card_token: tokenGenerator.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 }; /** * aid_cards_post * * POST /accounts/{aid}/wallets/cards */ export const createApiAccountsAidWalletsCards = async (args: CreateApiAccountsAidWalletsCardsArgs, options?: CreateApiAccountsAidWalletsCardsOptions) => { const {baseUrl = "https://api.dintero.com/v1", fetch: fetchFn = fetch, JWT} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (JWT !== undefined) headers.set('authorization', `Bearer ${JWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.aid))}/wallets/cards${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(createApiAccountsAidWalletsCardsResponse, await res.json()) };