import {z} from 'zod' export type KeystoreEnvironmentDTO = {environmentName?: string | undefined, alias?: string | undefined, keyStoreType?: ('JKS' | 'PKCS12') | undefined}; export type KeystoreUpdateDTO = {name?: string | undefined, description?: string | undefined, keyStoreEnvironmentList?: Array | undefined}; export type UpdateApiApiopsProjectsProjectNameKeystoresKeystoreNameArgs = {projectName: string, keystoreName: string, jwkUpdateAction?: ('NULLIFY' | 'UPDATE') | undefined, updateScope?: ('SAME_PROJECT' | 'ALL_PROJECTS') | undefined, body: KeystoreUpdateDTO}; export type UpdateApiApiopsProjectsProjectNameKeystoresKeystoreNameOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const keystoreEnvironmentDTO = z.object({environmentName: z.string().optional(), alias: z.string().optional(), keyStoreType: z.enum(["JKS", "PKCS12"]).optional()}); export const keystoreManagementDTO = z.object({id: z.string().optional(), name: z.string().optional(), description: z.string().optional(), projectId: z.string().optional(), keyStoreEnvironmentList: z.array(keystoreEnvironmentDTO).optional()}); export const apiOpsResponseKeystore = z.object({status: z.enum(["SUCCESS", "FAILURE"]).optional(), resultMessage: z.string().optional(), resultList: z.array(keystoreManagementDTO).optional(), resultCount: z.number().int().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 }; /** * Update an existing Keystore * * PUT /apiops/projects/{projectName}/keystores/{keystoreName}/ */ export const updateApiApiopsProjectsProjectNameKeystoresKeystoreName = async (args: UpdateApiApiopsProjectsProjectNameKeystoresKeystoreNameArgs, options?: UpdateApiApiopsProjectsProjectNameKeystoresKeystoreNameOptions) => { const {baseUrl = "http://167.86.118.166:32080", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.jwkUpdateAction != null) query.append("jwkUpdateAction", String(args.jwkUpdateAction)) if (args.updateScope != null) query.append("updateScope", String(args.updateScope)) const url = `${baseUrl.replace(/\/+$/, '')}/apiops/projects/${encodeURIComponent(String(args.projectName))}/keystores/${encodeURIComponent(String(args.keystoreName))}/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(apiOpsResponseKeystore, await res.json()) };