import {z} from 'zod' export type GetApi1TenantsTenantIdArgs = {'icl-requestor-id': string}; export type GetApi1TenantsTenantIdOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const tenantId = z.string(); export const tagId = z.number().int().gte(1); export const timestamp = z.string(); export const tag = z.object({id: tagId, tagText: z.string(), default: z.boolean(), created: timestamp}); export const createdByType = z.enum(["Tsp", "Admin", "Va"]); export const createdBy = z.object({id: z.string(), name: z.string(), type: createdByType}); export const tenantGetResponse = z.object({id: tenantId, name: z.string(), archived: z.boolean(), tenantCreatedConfigs: z.boolean(), invited: z.boolean(), keyLeasingRequired: z.boolean(), primaryKmsConfigId: z.number().int().nullable(), tags: z.array(tag), createdBy: createdBy, created: timestamp, updated: timestamp}); 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 }; /** * Tenant Get * * GET /1/tenants/{tenantId} */ export const getApi1TenantsTenantId = async (args: GetApi1TenantsTenantIdArgs, options?: GetApi1TenantsTenantIdOptions) => { const {baseUrl = "http://localhost:3000/api", fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['icl-requestor-id'] != null) headers.set("icl-requestor-id", String(args['icl-requestor-id'])) if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/1/tenants/${encodeURIComponent(String(args.tenantId))}${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(tenantGetResponse, await res.json()) };