import {z} from 'zod' export type GetApiV1PrivateLocationsIdArgs = {'x-checkly-account'?: string | undefined, id: string}; export type GetApiV1PrivateLocationsIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const privateLocationKeys = z.object({id: z.string(), rawKey: z.string(), maskedKey: z.string(), created_at: z.string(), updated_at: z.string().nullable().optional()}); export const keys = z.array(privateLocationKeys); export const runningAgentInfo = z.object({id: z.string(), lastSeenAt: z.string()}); export const agents = z.array(runningAgentInfo); export const runningAgent = z.object({version: z.string(), isOutdated: z.boolean(), count: z.number(), agents: agents}); export const runningAgents = z.array(runningAgent); export const bindingProjectV1 = z.object({id: z.string(), logicalId: z.string(), name: z.string()}); export const projectBindingDetailsV1 = z.object({logicalId: z.string(), pending: z.boolean(), sourceFile: z.string().nullable().optional()}); export const projectBindingOwnerV1 = z.object({project: bindingProjectV1, binding: projectBindingDetailsV1}).nullable(); export const projectBindingV1 = z.object({project: bindingProjectV1, binding: projectBindingDetailsV1}); export const projectBindingReferencesV1 = z.array(projectBindingV1); export const projectBindingsV1 = z.object({owner: projectBindingOwnerV1, references: projectBindingReferencesV1}); export const privateLocationsSchema = z.object({id: z.string(), name: z.string(), slugName: z.string(), icon: z.string().optional(), created_at: z.string(), updated_at: z.string().nullable().optional(), keys: keys.optional(), proxyUrl: z.string().nullable().optional(), lastSeen: z.string().nullable().optional(), agentCount: z.number().nullable().optional(), minAgentVersion: z.string().nullable().optional(), runningAgents: runningAgents.optional(), projectBindings: projectBindingsV1.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 }; /** * Retrieve a private location * * GET /v1/private-locations/{id} */ export const getApiV1PrivateLocationsId = async (args: GetApiV1PrivateLocationsIdArgs, options?: GetApiV1PrivateLocationsIdOptions) => { const {baseUrl = "https://api.checklyhq.com", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['x-checkly-account'] != null) headers.set("x-checkly-account", String(args['x-checkly-account'])) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/private-locations/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(privateLocationsSchema, await res.json()) };