import {z} from 'zod' export type GetApiV1OrganizationsOrganizationIdLedgersArgs = {organization_id: string, 'Content-Type'?: string | undefined, 'X-Request-Id'?: string | undefined, Authorization?: string | undefined, limit?: number | undefined, start_date?: string | undefined, end_date?: string | undefined, sort_order?: ('asc' | 'desc') | undefined, page?: number | undefined, 'metadata.key'?: string | undefined, name?: string | undefined, status?: ('ACTIVE' | 'INACTIVE') | undefined}; export type GetApiV1OrganizationsOrganizationIdLedgersOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const statusOrganization = z.object({code: z.string().max(100).optional(), description: z.string().max(256).nullable().optional()}); export const metadata = z.record(z.string(), z.union([z.string().max(2000), z.number(), z.boolean()])); export const ledgerSettingsResponse = z.object({accounting: z.object({validateAccountType: z.boolean().optional(), validateRoutes: z.boolean().optional()}).optional()}); export const createLedgerResponse = z.object({id: z.string().optional(), organizationId: z.string().optional(), name: z.string().max(256).optional(), status: statusOrganization.optional(), metadata: metadata.optional(), settings: ledgerSettingsResponse.optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), deletedAt: z.string().nullable().optional()}); export const getApiV1OrganizationsOrganizationIdLedgersResponse = z.object({items: z.array(createLedgerResponse).optional(), page: z.number().int().optional(), limit: z.number().int().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 Ledgers * * GET /v1/organizations/{organization_id}/ledgers */ export const getApiV1OrganizationsOrganizationIdLedgers = async (args: GetApiV1OrganizationsOrganizationIdLedgersArgs, options?: GetApiV1OrganizationsOrganizationIdLedgersOptions) => { const {baseUrl = "https://identity.sandbox.lerian.net", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (args['X-Request-Id'] != null) headers.set("X-Request-Id", String(args['X-Request-Id'])) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.start_date != null) query.append("start_date", String(args.start_date)) if (args.end_date != null) query.append("end_date", String(args.end_date)) if (args.sort_order != null) query.append("sort_order", String(args.sort_order)) if (args.page != null) query.append("page", String(args.page)) if (args['metadata.key'] != null) query.append("metadata.key", String(args['metadata.key'])) if (args.name != null) query.append("name", String(args.name)) if (args.status != null) query.append("status", String(args.status)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/organizations/${encodeURIComponent(String(args.organization_id))}/ledgers${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(getApiV1OrganizationsOrganizationIdLedgersResponse, await res.json()) };