import {z} from 'zod' export type OmnibusJsonNullableListTenantCustomProperty = {present?: boolean | undefined}; export type OmnibusCreateOrUpdateTenantRequest = {alias: string, description?: string | undefined, status?: ('LOCKED' | 'UNLOCKED') | undefined, customProperties?: OmnibusJsonNullableListTenantCustomProperty | undefined}; export type CreateApiV1DomainsDomainIdOmnibusOmnibusIdTenantsArgs = {domainId: string, omnibusId: string, body: OmnibusCreateOrUpdateTenantRequest}; export type CreateApiV1DomainsDomainIdOmnibusOmnibusIdTenantsOptions = {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 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 }; /** * Create a new tenant within an omnibus structure * * POST /v1/domains/{domainId}/omnibus/{omnibusId}/tenants */ export const createApiV1DomainsDomainIdOmnibusOmnibusIdTenants = async (args: CreateApiV1DomainsDomainIdOmnibusOmnibusIdTenantsArgs, options: CreateApiV1DomainsDomainIdOmnibusOmnibusIdTenantsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") 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: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(omnibusTenantResponse, await res.json()) };