import {z} from 'zod' export type GetApiV1DeploymentTriggersArgs = {'x-checkly-account'?: string | undefined}; export type GetApiV1DeploymentTriggersOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const deploymentTrigger = z.object({id: z.number().optional(), checkId: z.string().nullable().optional(), groupId: z.number().nullable().optional(), provider: z.string().optional(), repoId: z.string().optional(), repoName: z.string().optional(), repoLink: z.string().nullable().optional(), useEnvironmentUrl: z.boolean().optional(), includeScreenshots: z.boolean().optional(), environmentRegexFilter: z.string().nullable().optional(), environmentUrlRegexFilter: z.string().nullable().optional(), runLocation: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().nullable().optional()}); export const deploymentTriggers = z.array(deploymentTrigger); 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 }; /** * List all deployment triggers * * GET /v1/deployment-triggers */ export const getApiV1DeploymentTriggers = async (args: GetApiV1DeploymentTriggersArgs, options?: GetApiV1DeploymentTriggersOptions) => { 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/deployment-triggers${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(deploymentTriggers, await res.json()) };