import {z} from 'zod' export type GetApiMotiveCardV1SpendProfilesSpendProfileIdArgs = {spend_profile_id: string}; export type GetApiMotiveCardV1SpendProfilesSpendProfileIdOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiMotiveCardV1SpendProfilesSpendProfileIdResponse = z.object({id: z.string().optional(), name: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), is_default: z.boolean().optional(), spend_limits: z.object({daily_limit_in_cents: z.number().int().optional(), weekly_limit_in_cents: z.number().int().optional(), monthly_limit_in_cents: z.number().int().optional(), transaction_limit_in_cents: z.number().int().optional(), billing_cycle_spend_limit_in_cents: z.number().int().optional(), daily_withdrawal_limit_in_cents: z.number().int().optional(), weekly_withdrawal_limit_in_cents: z.number().int().optional(), atm_withdrawal_enabled: z.boolean().optional(), enable_days: z.array(z.string()).optional(), enable_start_time: z.unknown(), enable_end_time: z.unknown(), created_by: z.number().int().optional()}).optional(), spend_categories: z.array(z.string()).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 }; /** * Fetch a particular spend profile * * GET /motive_card/v1/spend_profiles/{spend_profile_id} */ export const getApiMotiveCardV1SpendProfilesSpendProfileId = async (args: GetApiMotiveCardV1SpendProfilesSpendProfileIdArgs, options?: GetApiMotiveCardV1SpendProfilesSpendProfileIdOptions) => { const {baseUrl = "https://api.gomotive.com", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/motive_card/v1/spend_profiles/${encodeURIComponent(String(args.spend_profile_id))}${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(getApiMotiveCardV1SpendProfilesSpendProfileIdResponse, await res.json()) };