import {z} from 'zod' export type GetApiAccountsAidPaymentsCardTokensArgs = {customer_id?: string | undefined, relationship_id?: string | undefined, status?: (Array<'ACTIVE' | 'INACTIVE' | 'SUSPENDED' | 'CANCELLED' | 'DELETED'>) | undefined, include_deleted?: boolean | undefined, limit?: number | undefined, starting_after?: string | undefined}; export type GetApiAccountsAidPaymentsCardTokensOptions = {baseUrl?: string | undefined, JWT?: string | undefined, fetch?: typeof fetch | undefined}; export const cardTokenRead = z.object({id: z.string(), token: z.string().optional(), type: z.literal("payment_token"), status: z.enum(["ACTIVE", "INACTIVE", "SUSPENDED", "CANCELLED", "DELETED"]), card_brand: z.enum(["visa", "mastercard"]), masked_pan: z.string().optional(), pan_expiry_date: z.string().optional(), token_expiry_date: z.string().optional(), links: z.array(z.object({href: z.string(), rel: z.enum(["digital_card_art", "digital_card_art_background", "card_symbol", "terms_and_conditions"]), mime_type: z.enum(["image/png", "image/pdf", "text/plain", "text/html"]).optional()})).optional(), customer_id: z.string().optional(), account_id: z.string().min(9).max(9), relationship_id: z.string().optional(), transaction_id: z.string().optional(), external_token_references: z.array(z.string()).optional(), payment_product_type: z.string(), created_at: z.string(), created_by: z.string().optional(), updated_at: z.string(), deleted_at: z.string().optional(), deleted_by: z.string().optional()}); export const getApiAccountsAidPaymentsCardTokensResponse = z.array(cardTokenRead); 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 }; /** * card_tokens_get * * GET /accounts/{aid}/payments/card-tokens * * Also accepts auth: apikey */ export const getApiAccountsAidPaymentsCardTokens = async (args: GetApiAccountsAidPaymentsCardTokensArgs, options?: GetApiAccountsAidPaymentsCardTokensOptions) => { const {baseUrl = "https://api.dintero.com/v1", fetch: fetchFn = fetch, JWT} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.customer_id != null) query.append("customer_id", String(args.customer_id)) if (args.relationship_id != null) query.append("relationship_id", String(args.relationship_id)) for (const item of args.status ?? []) query.append("status", String(item)) if (args.include_deleted != null) query.append("include_deleted", String(args.include_deleted)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.starting_after != null) query.append("starting_after", String(args.starting_after)) if (JWT !== undefined) headers.set('authorization', `Bearer ${JWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.aid))}/payments/card-tokens${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(getApiAccountsAidPaymentsCardTokensResponse, await res.json()) };