import {z} from 'zod' export type VaultSecretStorageConfig = {url: string, role?: string | undefined, mount_path: string, path_prefix: string, auth_method: string, gcp_auth_type?: string | undefined, service_account_email?: string | undefined}; export type SecretStorageConfig = {vault?: VaultSecretStorageConfig | undefined}; export type SecretStorage = {id?: number | undefined, name: string, type: 'vault' | 'internal', scope: 'project' | 'global', project_id?: number | undefined, config: SecretStorageConfig, created_at?: string | undefined, updated_at?: string | undefined}; export type CreateApiV1ProjectsProjectIdSecretStoragesArgs = {project_id: number, body: SecretStorage}; export type CreateApiV1ProjectsProjectIdSecretStoragesOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const vaultSecretStorageConfig = z.object({url: z.string(), role: z.string().optional(), mount_path: z.string(), path_prefix: z.string(), auth_method: z.string(), gcp_auth_type: z.string().optional(), service_account_email: z.string().optional()}); export const secretStorageConfig = z.object({vault: vaultSecretStorageConfig.optional()}); export const secretStorage = z.object({id: z.number().int().optional(), name: z.string(), type: z.enum(["vault", "internal"]), scope: z.enum(["project", "global"]), project_id: z.number().int().optional(), config: secretStorageConfig, created_at: z.string().optional(), updated_at: z.string().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 }; /** * Create secret storage * * POST /v1/projects/{project_id}/secret_storages */ export const createApiV1ProjectsProjectIdSecretStorages = async (args: CreateApiV1ProjectsProjectIdSecretStoragesArgs, options?: CreateApiV1ProjectsProjectIdSecretStoragesOptions) => { const {baseUrl = "http://localhost:8080", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/v1/projects/${encodeURIComponent(String(args.project_id))}/secret_storages${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(secretStorage, await res.json()) };