import {z} from 'zod' export type UpdateApiApiOrgIdSyntheticsEnvironmentsEnvArgs = {org_id: string, env: string, body: Record}; export type UpdateApiApiOrgIdSyntheticsEnvironmentsEnvOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const syntheticsVariableView = z.union([z.object({has_value: z.boolean().optional(), kind: z.literal("plain"), value: z.string(), created_at: z.number().int(), description: z.string(), example: z.string(), id: z.string(), name: z.string(), owner: z.string().nullable().optional(), tags: z.array(z.string()), updated_at: z.number().int(), used_by: z.array(z.string()).optional(), used_by_checks: z.number().int().gte(0).optional()}), z.object({has_value: z.boolean(), kind: z.literal("secret"), created_at: z.number().int(), description: z.string(), example: z.string(), id: z.string(), name: z.string(), owner: z.string().nullable().optional(), tags: z.array(z.string()), updated_at: z.number().int(), used_by: z.array(z.string()).optional(), used_by_checks: z.number().int().gte(0).optional()})]); export const syntheticsEnvironmentView = z.object({checks_count: z.number().int().gte(0), created_at: z.number().int(), description: z.string(), id: z.string(), is_global: z.boolean(), name: z.string(), owner: z.string().nullable().optional(), updated_at: z.number().int(), variables: z.array(syntheticsVariableView)}); 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 environment's description * * PUT /api/{org_id}/synthetics/environments/{env} */ export const updateApiApiOrgIdSyntheticsEnvironmentsEnv = async (args: UpdateApiApiOrgIdSyntheticsEnvironmentsEnvArgs, options: UpdateApiApiOrgIdSyntheticsEnvironmentsEnvOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.org_id))}/synthetics/environments/${encodeURIComponent(String(args.env))}${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(syntheticsEnvironmentView, await res.json()) };