import {z} from 'zod' export type GetApiAccountsAidTerminalsArgs = {aid: unknown, payout_destination_id?: Array | undefined, store_id?: Array | undefined, status?: (Array<'ACTIVE' | 'INACTIVE' | 'PENDING' | 'ACTION_REQUIRED' | 'ERROR' | 'DELETED'>) | undefined, device_model?: (Array<'SATURN1000' | 'Saturn_S1F4_Pro' | 'S1P2'>) | undefined, device_serial_number?: Array | undefined, includes?: Array<'store'> | undefined, terminal_id?: Array | undefined, search?: string | undefined, starting_after?: string | undefined, limit?: number | undefined}; export type GetApiAccountsAidTerminalsOptions = {baseUrl?: string | undefined, JWT?: string | undefined, fetch?: typeof fetch | undefined}; export const terminalStatus = z.enum(["DELETED", "PENDING", "ACTION_REQUIRED", "ACTIVE", "INACTIVE", "ERROR"]); export const terminalStatusReason = z.literal("CHECK_UPDATE"); export const terminalCollection = z.object({starting_after: z.string().optional(), terminals: z.array(z.object({id: z.string().optional(), created_at: z.string().optional(), created_by: z.string().optional(), updated_at: z.string().optional(), deleted_by: z.string().optional(), deleted_at: z.string().optional(), device_model: z.string().optional(), store_id: z.string().optional(), terminal_id: z.string(), device_serial_number: z.string(), status: terminalStatus.optional(), status_reason: terminalStatusReason.optional(), store: z.object({id: z.string().optional(), store_name: z.string().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 }; /** * aid_account_management_terminals_get * * GET /accounts/{aid}/terminals */ export const getApiAccountsAidTerminals = async (args: GetApiAccountsAidTerminalsArgs, options?: GetApiAccountsAidTerminalsOptions) => { 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") for (const item of args.payout_destination_id ?? []) query.append("payout_destination_id", String(item)) for (const item of args.store_id ?? []) query.append("store_id", String(item)) for (const item of args.status ?? []) query.append("status", String(item)) for (const item of args.device_model ?? []) query.append("device_model", String(item)) for (const item of args.device_serial_number ?? []) query.append("device_serial_number", String(item)) if (args.includes != null) query.append("includes", args.includes.join(',')) for (const item of args.terminal_id ?? []) query.append("terminal_id", String(item)) if (args.search != null) query.append("search", String(args.search)) if (args.starting_after != null) query.append("starting_after", String(args.starting_after)) if (args.limit != null) query.append("limit", String(args.limit)) if (JWT !== undefined) headers.set('authorization', `Bearer ${JWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.aid))}/terminals${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(terminalCollection, await res.json()) };