import {z} from 'zod' export type GetApiMotiveCardV1SpendProfilesArgs = {default_first?: boolean | undefined, sort_field?: ('name' | 'created_at' | 'updated_at') | undefined, sort_direction?: ('asc' | 'desc') | undefined, page_no?: number | undefined, per_page?: number | undefined}; export type GetApiMotiveCardV1SpendProfilesOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiMotiveCardV1SpendProfilesResponse = z.object({spend_control_profiles: z.array(z.object({id: z.string().optional(), name: z.string().optional(), is_default: z.boolean().optional(), created_at: z.string().optional(), updated_at: z.string().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()})).optional(), pagination: z.object({per_page: z.number().int().optional(), page_no: z.number().int().optional(), total: z.number().int().optional()}).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 }; /** * List all the spend profiles of your company * * GET /motive_card/v1/spend_profiles */ export const getApiMotiveCardV1SpendProfiles = async (args: GetApiMotiveCardV1SpendProfilesArgs, options?: GetApiMotiveCardV1SpendProfilesOptions) => { 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 (args.default_first != null) query.append("default_first", String(args.default_first)) if (args.sort_field != null) query.append("sort_field", String(args.sort_field)) if (args.sort_direction != null) query.append("sort_direction", String(args.sort_direction)) if (args.page_no != null) query.append("page_no", String(args.page_no)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/motive_card/v1/spend_profiles${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(getApiMotiveCardV1SpendProfilesResponse, await res.json()) };