import {z} from 'zod' export type GetApi1KmsConfigsKmsConfigIdArgs = {'icl-requestor-id': string}; export type GetApi1KmsConfigsKmsConfigIdOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const kmsConfigId = z.number().int().gte(1); export const awsKmsConfigNonsensitive = z.object({keyPath: z.object({keyID: z.string(), region: z.string()}), type: z.literal("AWS"), version: z.number().int().gte(1)}); export const azureKmsConfigNonsensitive = z.object({keyPath: z.object({keyName: z.string(), vaultBaseUrl: z.string()}), type: z.literal("AZURE"), version: z.number().int().gte(1)}); export const gcpKmsConfigNonsensitive = z.object({keyPath: z.object({cryptoKeyId: z.string(), keyRingId: z.string(), locationId: z.string(), projectId: z.string()}), type: z.literal("GCP"), version: z.number().int().gte(1)}); export const thalesKmsConfigNonsensitive = z.object({keyPath: z.object({keyId: z.string(), serviceUrl: z.string()}), type: z.literal("THALES"), version: z.number().int().gte(1)}); export const kmsConfigurationNonsensitive = z.union([awsKmsConfigNonsensitive, azureKmsConfigNonsensitive, gcpKmsConfigNonsensitive, thalesKmsConfigNonsensitive]); export const createdByType = z.enum(["Tsp", "Admin", "Va"]); export const createdBy = z.object({id: z.string(), name: z.string(), type: createdByType}); export const timestamp = z.string(); export const getApi1KmsConfigsKmsConfigIdResponse = z.object({id: kmsConfigId, decryptedConfig: kmsConfigurationNonsensitive, createdBy: createdBy, leasingAllowed: z.boolean(), assignmentCount: z.number().int(), secretCount: z.number().int().gte(0), 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 }; /** * KMS Config Get * * GET /1/kms/configs/{kmsConfigId} */ export const getApi1KmsConfigsKmsConfigId = async (args: GetApi1KmsConfigsKmsConfigIdArgs, options?: GetApi1KmsConfigsKmsConfigIdOptions) => { 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/kms/configs/${encodeURIComponent(String(args.kmsConfigId))}${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(getApi1KmsConfigsKmsConfigIdResponse, await res.json()) };