import {z} from 'zod' export type ExecutorAuthenticationInput = {config?: {[key: string]: Record} | undefined, type: 'none' | 'api_key' | 'bearer' | 'basic' | 'oidc_client_credentials' | 'oidc_user'}; export type ExecutorEndpointInput = {method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS', name: string, path: string, timeout?: number | undefined}; export type UpdateExecutorConfigurationInput = {authentication: ExecutorAuthenticationInput, baseUrl: string, description?: string | undefined, endpoints: Array, metadata?: {[key: string]: Record} | undefined, name: string}; export type PatchApiV1ExecutorsIdArgs = {id: string, body: UpdateExecutorConfigurationInput}; export type PatchApiV1ExecutorsIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const executorAuthenticationOutput = z.object({config: z.record(z.string(), z.object({})).optional(), type: z.string().optional()}); export const executorEndpointOutput = z.object({method: z.string().optional(), name: z.string().optional(), path: z.string().optional(), timeout: z.number().int().optional()}); export const executorConfigurationOutput = z.object({authentication: executorAuthenticationOutput.optional(), baseUrl: z.string().optional(), createdAt: z.string().optional(), description: z.string().optional(), endpoints: z.array(executorEndpointOutput).optional(), id: z.string().optional(), lastTestedAt: z.string().optional(), metadata: z.record(z.string(), z.object({})).optional(), name: z.string().optional(), status: z.enum(["unconfigured", "configured", "tested", "active", "disabled"]).optional(), updatedAt: 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 }; /** * Update an Executor Configuration * * PATCH /v1/executors/{id} */ export const patchApiV1ExecutorsId = async (args: PatchApiV1ExecutorsIdArgs, options?: PatchApiV1ExecutorsIdOptions) => { const {baseUrl = "https://identity.sandbox.lerian.net", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/executors/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(executorConfigurationOutput, await res.json()) };