import {z} from 'zod' export type GetApiV1DefaultBanksBankIdDirectivesArgs = {bank_id: string, tags?: (Array | null) | undefined, tags_match?: ('any' | 'all' | 'exact') | undefined, active_only?: boolean | undefined, limit?: number | undefined, offset?: number | undefined, authorization?: (string | null) | undefined}; export type GetApiV1DefaultBanksBankIdDirectivesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const directiveResponse = z.object({id: z.string(), bank_id: z.string(), name: z.string(), content: z.string(), priority: z.number().int().optional(), is_active: z.boolean().optional(), tags: z.array(z.string()).optional(), created_at: z.string().nullable().optional(), updated_at: z.string().nullable().optional()}); export const directiveListResponse = z.object({items: z.array(directiveResponse), total: z.number().int(), limit: z.number().int(), offset: z.number().int()}); 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 directives * * GET /v1/default/banks/{bank_id}/directives */ export const getApiV1DefaultBanksBankIdDirectives = async (args: GetApiV1DefaultBanksBankIdDirectivesArgs, options: GetApiV1DefaultBanksBankIdDirectivesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.tags ?? []) query.append("tags", String(item)) if (args.tags_match != null) query.append("tags_match", String(args.tags_match)) if (args.active_only != null) query.append("active_only", String(args.active_only)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.authorization != null) headers.set("authorization", String(args.authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/default/banks/${encodeURIComponent(String(args.bank_id))}/directives${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(directiveListResponse, await res.json()) };