import {z} from 'zod' export type GetApiMerchantOpenInstitutionV1AccountsListArgs = {'X-GatePay-Certificate-ClientId': string, 'X-GatePay-Timestamp': string, 'X-GatePay-Nonce': string, 'X-GatePay-Signature': string, status?: 'ACTIVE' | undefined, request_id?: string | undefined, customer_id?: string | undefined, created_gte?: number | undefined, created_lte?: number | undefined, limit?: number | undefined, cursor?: number | undefined}; export type GetApiMerchantOpenInstitutionV1AccountsListOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const accountStatus = z.enum(["INIT", "PENDING", "ACTIVE", "FAIL", "RISK_SUSPEND", "NONE"]); export const accountInfo = z.object({request_id: z.string().optional(), account_id: z.string().optional(), customer_id: z.string().optional(), display_name: z.string().optional(), status: accountStatus.optional(), created: z.number().int().optional()}); export const listSubAccountsResponse = z.object({accounts: z.array(accountInfo).optional(), has_more: z.boolean().optional()}); export const listSubAccountsResponseWrapper = z.object({status: z.string().optional(), code: z.string().optional(), errorMessage: z.string().optional(), data: listSubAccountsResponse.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 Sub-Accounts * * GET /merchant/open/institution/v1/accounts/list */ export const getApiMerchantOpenInstitutionV1AccountsList = async (args: GetApiMerchantOpenInstitutionV1AccountsListArgs, options?: GetApiMerchantOpenInstitutionV1AccountsListOptions) => { const {baseUrl = "https://openplatform.gateapi.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-GatePay-Certificate-ClientId'] != null) headers.set("X-GatePay-Certificate-ClientId", String(args['X-GatePay-Certificate-ClientId'])) if (args['X-GatePay-Timestamp'] != null) headers.set("X-GatePay-Timestamp", String(args['X-GatePay-Timestamp'])) if (args['X-GatePay-Nonce'] != null) headers.set("X-GatePay-Nonce", String(args['X-GatePay-Nonce'])) if (args['X-GatePay-Signature'] != null) headers.set("X-GatePay-Signature", String(args['X-GatePay-Signature'])) if (args.status != null) query.append("status", String(args.status)) if (args.request_id != null) query.append("request_id", String(args.request_id)) if (args.customer_id != null) query.append("customer_id", String(args.customer_id)) if (args.created_gte != null) query.append("created_gte", String(args.created_gte)) if (args.created_lte != null) query.append("created_lte", String(args.created_lte)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) const url = `${baseUrl.replace(/\/+$/, '')}/merchant/open/institution/v1/accounts/list${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(listSubAccountsResponseWrapper, await res.json()) };