import {z} from 'zod' export type TenantLimitsRequest = {rpm?: (number | null) | undefined, max_concurrent_jobs?: (number | null) | undefined}; export type GranularRetention = 'short' | 'zero_retention'; export type PutTenantRequest = {display_name?: (string | null) | undefined, disabled?: (boolean | null) | undefined, limits?: (TenantLimitsRequest | null) | undefined, workspace_storage_limit_bytes?: (number | null) | undefined, data_retention?: (GranularRetention | null) | undefined}; export type UpdateApiV1TenantsExternalRefArgs = {external_ref: string, body: PutTenantRequest | null}; export type UpdateApiV1TenantsExternalRefOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const tenantLimits = z.object({rpm: z.number().int(), max_concurrent_jobs: z.number().int()}); export const granularRetention = z.enum(["short", "zero_retention"]); export const tenant = z.object({id: z.string(), external_ref: z.string(), display_name: z.string().nullable(), disabled: z.boolean(), limits: tenantLimits, data_retention: granularRetention, created_at: z.string()}); 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 }; /** * put_tenant * * PUT /v1/tenants/{external_ref} */ export const updateApiV1TenantsExternalRef = async (args: UpdateApiV1TenantsExternalRefArgs, options: UpdateApiV1TenantsExternalRefOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (APIKeyHeader !== undefined) headers.set("X-API-Key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v1/tenants/${encodeURIComponent(String(args.external_ref))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(tenant, await res.json()) };