import {z} from 'zod' export type TenantSecretId = number; export type TagId = number; export type GetApi1TenantsSecretsArgs = {updatedSince?: string | undefined, createdSince?: string | undefined, secretType?: ('search' | 'deterministic-encryption' | 'vector') | undefined, migrationStatus?: ('current' | 'needs-migration') | undefined, rotationStatus?: ('current' | 'in-rotation' | 'archived') | undefined, page?: number | undefined, pageSize?: number | undefined, sortDirection?: ('asc' | 'desc') | undefined, sortColumn?: ('created' | 'updated') | undefined, query?: string | undefined, 'icl-requestor-id': string, body: {ids?: Array | undefined, tags?: Array | undefined}}; export type GetApi1TenantsSecretsOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const tenantSecretId = z.number().int().gte(1); export const base64 = z.string(); export const kmsConfigId = z.number().int().gte(1); export const tenantId = z.string(); export const tagId = z.number().int().gte(1); export const tenantSecretType = z.enum(["Search", "Deterministic", "Vector"]); export const tenantSecretMigrationStatus = z.enum(["Current", "NeedsMigration"]); export const tenantSecretRotationStatus = z.enum(["Current", "InRotation", "Archived"]); export const timestamp = z.string(); export const tenantSecretListResponseItem = z.object({id: tenantSecretId, encryptedSecret: base64, secretFingerprint: z.string(), secretPath: z.string(), kmsConfigId: kmsConfigId, tenantId: tenantId, tenantTags: z.array(tagId), secretType: tenantSecretType, migrationStatus: tenantSecretMigrationStatus, rotationStatus: tenantSecretRotationStatus, created: timestamp, updated: timestamp}); export const getApi1TenantsSecretsResponse = z.object({result: z.array(tenantSecretListResponseItem), page: z.number().int(), totalPages: z.number().int()}); 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 Secret List * * GET /1/tenants/secrets */ export const getApi1TenantsSecrets = async (args: GetApi1TenantsSecretsArgs, options?: GetApi1TenantsSecretsOptions) => { const {baseUrl = "http://localhost:3000/api", fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.updatedSince != null) query.append("updatedSince", String(args.updatedSince)) if (args.createdSince != null) query.append("createdSince", String(args.createdSince)) if (args.secretType != null) query.append("secretType", String(args.secretType)) if (args.migrationStatus != null) query.append("migrationStatus", String(args.migrationStatus)) if (args.rotationStatus != null) query.append("rotationStatus", String(args.rotationStatus)) if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.sortDirection != null) query.append("sortDirection", String(args.sortDirection)) if (args.sortColumn != null) query.append("sortColumn", String(args.sortColumn)) if (args.query != null) query.append("query", String(args.query)) 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/secrets${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", 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(getApi1TenantsSecretsResponse, await res.json()) };