import {z} from 'zod' export type GetApiV0OrganizationsOrganizationIdBankAccountsArgs = {'filter[account-restricted][eq]'?: boolean | undefined, 'filter[beneficiary-url][eq]'?: string | undefined, 'page[size]'?: number | undefined, include?: (Array<'beneficiary' | 'owner'>) | undefined, 'filter[account-status][in][]'?: (Array<'closing' | 'open' | 'closed' | 'opening'>) | undefined, sort?: ('-created-at' | 'display-name' | 'created-at' | '-display-name') | undefined, 'page[after]'?: string | undefined, 'filter[pooled-funds][eq]'?: boolean | undefined, 'filter[bank-product-type][in][]'?: (Array<'savings-account' | 'client-money-account' | 'safeguarding-account' | 'embedded-account' | 'operational-account'>) | undefined, 'filter[owner-url][eq]'?: string | undefined, 'page[before]'?: string | undefined, 'organization-id': string}; export type GetApiV0OrganizationsOrganizationIdBankAccountsOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV0OrganizationsOrganizationIdBankAccountsResponse = z.object({accounts: z.array(z.object({"account-submissions-url": z.union([z.string(), z.string()]), "bank-account-product-url": z.union([z.string(), z.string()]).optional(), "account-restricted": z.boolean(), "account-payments-url": z.union([z.string(), z.string()]), "pooled-account-memberships-url": z.union([z.string(), z.string()]).optional(), "account-admissions-url": z.union([z.string(), z.string()]), "bank-product-type": z.enum(["savings-account", "client-money-account", "safeguarding-account", "embedded-account", "operational-account"]), "account-mandates-url": z.union([z.string(), z.string()]).optional(), "display-name": z.string().min(1).max(64), "controller-url": z.string(), "pooled-funds": z.boolean(), "accrued-interest": z.object({currency: z.literal("GBP"), value: z.string()}), "account-status": z.enum(["closing", "open", "closed", "opening"]), "client-money-type": z.enum(["designated-client-fund", "designated-client-money", "general-client-money"]).optional(), "owner-url": z.union([z.string(), z.string()]), "closed-at": z.string().optional(), "created-at": z.string(), "opened-at": z.string().optional(), "close-account-url": z.union([z.string(), z.string()]).optional(), "available-balance": z.object({currency: z.literal("GBP"), value: z.string()}), "pooled-account-membership-updates-url": z.union([z.string(), z.string()]).optional(), "bank-account-restrictions-url": z.union([z.string(), z.string()]).optional(), "bank-addresses": z.array(z.object({"account-holder": z.string().min(1), "bank-id-code": z.literal("gbdsc"), "bank-id": z.string().min(6).max(6), "account-number": z.string().min(8).max(8), "account-number-code": z.literal("bban")})).optional(), "account-transactions-url": z.union([z.string(), z.string()]), "account-url": z.union([z.string(), z.string()]), "bank-account-events-url": z.union([z.string(), z.string()]).optional(), "beneficiary-url": z.union([z.string(), z.string()]).optional(), "primary-account": z.boolean(), "account-balance": z.object({currency: z.literal("GBP"), value: z.string()}), "savings-type": z.enum(["easy-access", "bare-trust"]).optional(), "account-statements-url": z.union([z.string(), z.string()])})), links: z.object({prev: z.string().nullable(), next: z.string().nullable()}), included: z.unknown()}); 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 bank accounts * * GET /v0/organizations/{organization-id}/bank/accounts */ export const getApiV0OrganizationsOrganizationIdBankAccounts = async (args: GetApiV0OrganizationsOrganizationIdBankAccountsArgs, options?: GetApiV0OrganizationsOrganizationIdBankAccountsOptions) => { const {baseUrl = "https://api.griffin.com", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['filter[account-restricted][eq]'] != null) query.append("filter[account-restricted][eq]", String(args['filter[account-restricted][eq]'])) if (args['filter[beneficiary-url][eq]'] != null) query.append("filter[beneficiary-url][eq]", String(args['filter[beneficiary-url][eq]'])) if (args['page[size]'] != null) query.append("page[size]", String(args['page[size]'])) for (const item of args.include ?? []) query.append("include", String(item)) for (const item of args['filter[account-status][in][]'] ?? []) query.append("filter[account-status][in][]", String(item)) if (args.sort != null) query.append("sort", String(args.sort)) if (args['page[after]'] != null) query.append("page[after]", String(args['page[after]'])) if (args['filter[pooled-funds][eq]'] != null) query.append("filter[pooled-funds][eq]", String(args['filter[pooled-funds][eq]'])) for (const item of args['filter[bank-product-type][in][]'] ?? []) query.append("filter[bank-product-type][in][]", String(item)) if (args['filter[owner-url][eq]'] != null) query.append("filter[owner-url][eq]", String(args['filter[owner-url][eq]'])) if (args['page[before]'] != null) query.append("page[before]", String(args['page[before]'])) if (apiKeyAuth !== undefined) headers.set("Authorization", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v0/organizations/${encodeURIComponent(String(args['organization-id']))}/bank/accounts${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(getApiV0OrganizationsOrganizationIdBankAccountsResponse, await res.json()) };