import {z} from 'zod' export type WasmExtensionPullPolicy = 'UNSPECIFIED_POLICY' | 'IfNotPresent' | 'Always'; export type V2WorkloadMode = 'UNDEFINED' | 'CLIENT' | 'SERVER' | 'CLIENT_AND_SERVER'; export type V2GlobalTrafficSelector = {mode?: V2WorkloadMode | undefined}; export type WasmExtensionPluginPhase = 'UNSPECIFIED_PHASE' | 'AUTHN' | 'AUTHZ' | 'STATS'; export type V2EnvValueSource = 'INLINE' | 'HOST'; export type V2EnvVar = {name: string, valueFrom: V2EnvValueSource, value?: string | undefined}; export type V2VmConfig = {env?: Array | undefined}; export type UpdateApiV2OrganizationsOrganizationExtensionsExtensionArgs = {organization: string, extension: string, body: {allowedIn?: Array | undefined, config?: Record | undefined, description?: string | undefined, displayName?: string | undefined, etag?: string | undefined, image?: string | undefined, imagePullPolicy?: WasmExtensionPullPolicy | undefined, imagePullSecret?: string | undefined, match?: V2GlobalTrafficSelector | undefined, phase?: WasmExtensionPluginPhase | undefined, priority?: number | undefined, source?: string | undefined, url: string, vmConfig?: V2VmConfig | undefined}}; export type UpdateApiV2OrganizationsOrganizationExtensionsExtensionOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const wasmExtensionPluginPhase = z.enum(["UNSPECIFIED_PHASE", "AUTHN", "AUTHZ", "STATS"]); export const wasmExtensionPullPolicy = z.enum(["UNSPECIFIED_POLICY", "IfNotPresent", "Always"]); export const v2EnvValueSource = z.enum(["INLINE", "HOST"]); export const v2EnvVar = z.object({name: z.string(), valueFrom: v2EnvValueSource, value: z.string().optional()}); export const v2VmConfig = z.object({env: z.array(v2EnvVar).optional()}); export const v2WorkloadMode = z.enum(["UNDEFINED", "CLIENT", "SERVER", "CLIENT_AND_SERVER"]); export const v2GlobalTrafficSelector = z.object({mode: v2WorkloadMode.optional()}); export const v2WasmExtension = z.object({fqn: z.string().optional(), displayName: z.string().optional(), etag: z.string().optional(), description: z.string().optional(), allowedIn: z.array(z.string()).optional(), image: z.string().optional(), source: z.string().optional(), phase: wasmExtensionPluginPhase.optional(), priority: z.number().int().optional(), config: z.object({}).optional(), imagePullPolicy: wasmExtensionPullPolicy.optional(), imagePullSecret: z.string().optional(), vmConfig: v2VmConfig.optional(), url: z.string(), match: v2GlobalTrafficSelector.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 }; /** * Modify an existing WasmExtension. * When modifying the details of an extension in use, such as the image property, enabled flag, phase, * or default configuration, a redeploy or reconfiguration of the extension may be triggered, affecting live * traffic in all those places that reference the extension. * Similarly, changes to the allowed_in property may trigger the removal of the extension from all places where * the extension was in use that are not allowed to use it anymore, affecting live traffic on the * relevant namespaces as well. * * PUT /v2/organizations/{organization}/extensions/{extension} */ export const updateApiV2OrganizationsOrganizationExtensionsExtension = async (args: UpdateApiV2OrganizationsOrganizationExtensionsExtensionArgs, options: UpdateApiV2OrganizationsOrganizationExtensionsExtensionOptions) => { const {baseUrl, 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(/\/+$/, '')}/v2/organizations/${encodeURIComponent(String(args.organization))}/extensions/${encodeURIComponent(String(args.extension))}${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(v2WasmExtension, await res.json()) };