import {z} from 'zod' export type ResourceID = string; export type StatementPeriodType = 'EODY' | 'NONE'; export type Date = string; export type GetApiConnectivityV2betaConnectionsCidReportsIdBankStatementsArgs = {cid: string, id: string, limit?: number | undefined, token?: string | undefined, account_id?: ResourceID | undefined, type?: StatementPeriodType | undefined, from?: Date | undefined, to?: Date | undefined}; export type GetApiConnectivityV2betaConnectionsCidReportsIdBankStatementsOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const organizationID = z.string(); export const resourceID = z.string().min(32).max(64); export const statementType = z.enum(["BOOKED", "PENDING"]); export const metadata = z.record(z.string(), z.string()).nullable(); export const resourceVersion = z.number().int().gte(1); export const eTag = z.string(); export const createdTimestamp = z.string(); export const updatedTimestamp = z.string(); export const bankStatement = z.object({organizationId: organizationID, connectionId: z.string(), reportId: z.string(), accountId: resourceID.optional(), id: resourceID, type: statementType, financialDataAccountId: z.string().optional(), metadata: metadata.optional(), version: resourceVersion, etag: eTag, created: createdTimestamp, updated: updatedTimestamp}); export const getApiConnectivityV2betaConnectionsCidReportsIdBankStatementsResponse = z.object({items: z.array(bankStatement), nextToken: z.string(), token: z.string(), limit: 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 bank statements * * GET /connectivity/v2beta/connections/{cid}/reports/{id}/bank-statements */ export const getApiConnectivityV2betaConnectionsCidReportsIdBankStatements = async (args: GetApiConnectivityV2betaConnectionsCidReportsIdBankStatementsArgs, options?: GetApiConnectivityV2betaConnectionsCidReportsIdBankStatementsOptions) => { const {baseUrl = "https://api.atlar.com", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.token != null) query.append("token", String(args.token)) if (args.account_id != null) query.append("account_id", String(args.account_id)) if (args.type != null) query.append("type", String(args.type)) if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/connectivity/v2beta/connections/${encodeURIComponent(String(args.cid))}/reports/${encodeURIComponent(String(args.id))}/bank-statements${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(getApiConnectivityV2betaConnectionsCidReportsIdBankStatementsResponse, await res.json()) };