import {z} from 'zod' export type GetApiV1DomainsDomainIdOmnibusOmnibusIdTenantsArgs = {domainId: string, omnibusId: string, page?: number | undefined, size?: number | undefined, search?: string | undefined, status?: ('LOCKED' | 'UNLOCKED') | undefined}; export type GetApiV1DomainsDomainIdOmnibusOmnibusIdTenantsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const omnibusTenantBalanceEntry = z.object({tickerId: z.string(), ledgerId: z.string(), reserved: z.string(), quarantined: z.string(), availableBalance: z.string().optional()}); export const omnibusTenantCustomProperty = z.object({key: z.string().min(1).max(200), value: z.string().min(1).max(5000)}); export const omnibusTenantResponse = z.object({id: z.string(), omnibusId: z.string(), alias: z.string(), isHost: z.boolean(), status: z.enum(["LOCKED", "UNLOCKED"]), createdAt: z.string(), updatedAt: z.string(), balances: z.array(omnibusTenantBalanceEntry).optional(), description: z.string().optional(), customProperties: z.array(omnibusTenantCustomProperty).optional()}); export const omnibusTenantPageMetadata = z.object({number: z.number().int().gte(0), size: z.number().int().gte(1), totalElements: z.number().int().gte(0).optional(), totalPages: z.number().int().gte(0).optional(), first: z.boolean(), last: z.boolean()}); export const omnibusTenantPageResponse = z.object({content: z.array(omnibusTenantResponse), page: omnibusTenantPageMetadata}); 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 all tenants within an omnibus structure * * GET /v1/domains/{domainId}/omnibus/{omnibusId}/tenants */ export const getApiV1DomainsDomainIdOmnibusOmnibusIdTenants = async (args: GetApiV1DomainsDomainIdOmnibusOmnibusIdTenantsArgs, options: GetApiV1DomainsDomainIdOmnibusOmnibusIdTenantsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = 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.size != null) query.append("size", String(args.size)) if (args.search != null) query.append("search", String(args.search)) if (args.status != null) query.append("status", String(args.status)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/domains/${encodeURIComponent(String(args.domainId))}/omnibus/${encodeURIComponent(String(args.omnibusId))}/tenants${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(omnibusTenantPageResponse, await res.json()) };