import {z} from 'zod' export type Id = string; export type GetApiCustomersCustomerIDCardAccountsCardAccountIDAuthControlsArgs = {customerID: Id, cardAccountID: Id}; export type GetApiCustomersCustomerIDCardAccountsCardAccountIDAuthControlsOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const fiatCurrency = z.literal("usd"); export const cardSpendingLimit = z.object({period: z.enum(["daily", "trial_lifetime"]), timezone: z.string().optional(), next_reset_at: z.string().optional(), total_amount: z.string(), remaining_amount: z.string(), currency: fiatCurrency.optional()}); export const getApiCustomersCustomerIDCardAccountsCardAccountIDAuthControlsResponse = z.object({customer_id: z.string(), card_account_id: z.string(), spending_limits: z.array(cardSpendingLimit)}); 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 }; /** * Retrieve authorization controls * * GET /customers/{customerID}/card_accounts/{cardAccountID}/auth_controls */ export const getApiCustomersCustomerIDCardAccountsCardAccountIDAuthControls = async (args: GetApiCustomersCustomerIDCardAccountsCardAccountIDAuthControlsArgs, options?: GetApiCustomersCustomerIDCardAccountsCardAccountIDAuthControlsOptions) => { const {baseUrl = "https://api.bridge.xyz/v0", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set("Api-Key", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/customers/${encodeURIComponent(String(args.customerID))}/card_accounts/${encodeURIComponent(String(args.cardAccountID))}/auth_controls${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(getApiCustomersCustomerIDCardAccountsCardAccountIDAuthControlsResponse, await res.json()) };