import {z} from 'zod' export type GetApiApiV2EntitiesEntityIdAccountsArgs = {page?: number | undefined, page_size?: number | undefined, limit?: number | undefined, order?: ('asc' | 'desc') | undefined, next?: (string | null) | undefined, previous?: (string | null) | undefined}; export type GetApiApiV2EntitiesEntityIdAccountsOptions = {baseUrl?: string | undefined, ApiKeyId?: string | undefined, ApiSecretKey?: string | undefined, fetch?: typeof fetch | undefined}; export const jurisdiction1 = z.enum(["BASELINE", "US"]); export const account = z.object({id: z.string(), entity_id: z.string(), is_active: z.boolean(), created_dt: z.string(), jurisdiction: jurisdiction1, brokerage_account_id: z.string().nullable().optional()}); export const baseOpenApiPaginationMetadata = z.object({previous: z.string().optional(), next: z.string().optional()}); export const paginatedAccountResponse = z.object({_sv: z.literal("PaginatedAccountResponse:v1").optional(), data: z.array(account), pagination_metadata: baseOpenApiPaginationMetadata}); export const getApiApiV2EntitiesEntityIdAccountsResponse = z.union([z.array(account), paginatedAccountResponse]); 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 }; /** * Get Accounts for Entity * * GET /api/v2/entities/{entity_id}/accounts */ export const getApiApiV2EntitiesEntityIdAccounts = async (args: GetApiApiV2EntitiesEntityIdAccountsArgs, options?: GetApiApiV2EntitiesEntityIdAccountsOptions) => { const {baseUrl = "https://api-enterprise.sbt.dinari.com", fetch: fetchFn = fetch, ApiKeyId, ApiSecretKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.order != null) query.append("order", String(args.order)) if (args.next != null) query.append("next", String(args.next)) if (args.previous != null) query.append("previous", String(args.previous)) if (ApiKeyId !== undefined) headers.set("X-API-Key-Id", ApiKeyId) if (ApiSecretKey !== undefined) headers.set("X-API-Secret-Key", ApiSecretKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/entities/${encodeURIComponent(String(args.entity_id))}/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(getApiApiV2EntitiesEntityIdAccountsResponse, await res.json()) };