import {z} from 'zod' export type GetApiFabricFabricApiKmsSecretArgs = {fabric: string, name?: string | undefined, keyName?: string | undefined, keyId?: string | undefined, offset?: number | undefined, count?: number | undefined, sortBy?: string | undefined, order?: ('ASC' | 'DESC') | undefined}; export type GetApiFabricFabricApiKmsSecretOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getAllSecretsExamplesRc200 = z.object({error: z.boolean().optional(), code: z.number().int().optional(), result: z.object({total: z.number().int().optional(), offset: z.number().int().optional(), count: z.number().int().optional(), items: z.array(z.object({name: z.string().optional(), value: z.string().optional(), fileName: z.string().optional(), tenant: z.string().optional(), fabric: z.string().optional(), createdAt: z.number().optional(), updatedAt: z.number().optional()})).optional()}).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 }; /** * List of secrets. * * GET /_fabric/{fabric}/_api/kms/secret * * Also accepts auth: BearerAuth */ export const getApiFabricFabricApiKmsSecret = async (args: GetApiFabricFabricApiKmsSecretArgs, options: GetApiFabricFabricApiKmsSecretOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.name != null) query.append("name", String(args.name)) if (args.keyName != null) query.append("keyName", String(args.keyName)) if (args.keyId != null) query.append("keyId", String(args.keyId)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.count != null) query.append("count", String(args.count)) if (args.sortBy != null) query.append("sortBy", String(args.sortBy)) if (args.order != null) query.append("order", String(args.order)) if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/_fabric/${encodeURIComponent(String(args.fabric))}/_api/kms/secret${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(getAllSecretsExamplesRc200, await res.json()) };