import type { GitInformation } from '../services/util.js'; import { SharedFile } from '../constructs/index.js'; import { RestResource } from './rest-resource.js'; export interface Project { name: string; logicalId: string; repoUrl?: string; } type ProjectResponse = Project & { id: string; created_at: string; }; export interface Change { logicalId: string; physicalId?: string | number; type: string; action: string; } /** The API's stand-in for a sensitive value in a reported change. */ export interface DiffMaskedMarker { $masked: 'same' | 'changed'; } /** * One property of one resource that a deploy would change, or has changed. * * `origin` says which side moved since the last deploy: `code` for a local * edit, `remote` for one made outside the CLI (the web app, the API), `both` * when the property moved on both sides — in which case `remote` carries the * movement the deploy is about to overwrite. A value too large to inline is * reported as a `{ $hash }` object rather than in the clear; under * `detail: 'full'` the deployed text is in the entry's `before`, at the path * the import format gives it (the same one for a script or a request body). * A secret change (`secret: true`) carries its values with every sensitive * position replaced by a `DiffMaskedMarker`, `changed` on the element whose * secret moved on that side; never a value or a hash. A list holding an * unmoved secret carries `same` markers without the flag. * `cause` names the reason for a change with no user-facing property behind * it, such as a new code bundle. */ export interface DiffChange { path: string; /** * `unmanaged` marks an alert channel or private location attached to this * project's check or group from outside the project: reported on the resource * it belongs to, and only deleted with `--prune-unmanaged-relations`. */ origin: 'code' | 'remote' | 'both' | 'unmanaged'; before?: unknown; after?: unknown; remote?: { before?: unknown; after?: unknown; }; cause?: string; /** Set when a sensitive value moved or a sensitive list element could not be matched; see `DiffMaskedMarker`. */ secret?: true; } /** * One rule of the redaction table the API applies to an entry's `before`, as * a JSON Pointer pattern (`*` for every list position) and the flag test on * the holding element that decides it. The API reports the resource type's * whole table, whatever the deployed row held, so the local side blanks by * the same rules — a credential the code adds included. */ export interface DiffRedaction { path: string; /** What the rule blanks to: a `value` becomes the empty string, an `object` becomes null. */ kind: 'value' | 'object'; when?: 'locked' | 'lockedOrSecret'; } /** * A resource in a deploy plan or an applied deploy. `action` is CREATE, * UPDATE, DELETE, DETACH (removed from code but kept in the account) or * UNCHANGED. */ export interface DiffEntry extends Change { origin?: 'code' | 'remote' | 'unmanaged'; /** Absent under `detail: 'summary'`. */ changes?: DiffChange[]; /** * The resource as currently deployed, in the import format: the payload the * import plan returns for it, references as physical ids, a check's or * group's subscription and assignment rows on it, credential values blanked. * Only under `detail: 'full'`, and only for a retained resource with a * change to show. */ before?: Record; /** With `before`: the type's redaction rule table, applied to it. */ redactions?: DiffRedaction[]; /** * Set on a relation (an alert channel subscription, a private location * assignment) whose change is reported as part of the check or group it * belongs to, so a renderer can fold it into that resource instead of * listing it separately. */ foldedInto?: { type: string; logicalId: string; }; /** The file Checkly has recorded for the resource, or null if none. */ sourceFile?: string | null; /** * `live` when Checkly had no usable state from an earlier planned deploy to * compare the resource with (the project's first plan, the first after a * deploy without one, a resource added with `checkly import`, or a stored * state a Checkly update made unusable) and compared the code with the * deployed resource instead. The deploy * writes such a resource whatever the comparison found, to set the baseline * for later plans, and `changes` is not exhaustive: a value the deployed * resource holds on a property the code does not set is left out, although * the write may reset it. */ basis?: 'live'; /** * On a check the deploy created, updated or kept, other than a heartbeat * monitor: whether Checkly selected it to run right after the deploy. Only on * a deploy's result, never on a preview or a dry run, and absent from an API * that predates it. */ scheduled?: boolean; /** * Why `scheduled` is false: the deploy did not ask for scheduling, it had * more checks than the scheduling threshold allows, it left the check * unchanged while scheduling changed checks only, or the check runs more * often than the minimum frequency for scheduling on deploy. */ scheduleSkippedReason?: 'NOT_REQUESTED' | 'THRESHOLD' | 'UNCHANGED' | 'MIN_FREQUENCY'; } /** * Which checks a deploy schedules: the ones it created or updated, or every * check it deployed, the unchanged ones included. */ export type ScheduleOnDeployScope = 'changed' | 'all'; /** How much of each change a preview reports. */ export type ProjectPreviewDetail = 'summary' | 'changes' | 'full'; export interface ProjectPreviewResponse { /** The project as currently deployed; absent before its first deploy. */ project?: DeployedProject | null; /** * Opaque fingerprint of the Checkly-side state this plan was computed * against. Passing it to a deploy makes that deploy refuse, rather than * apply a different plan than the one that was reviewed, if anything moved * in between. */ planToken: string; diff: DiffEntry[]; } export interface ResourceSync { logicalId: string; physicalId?: string | number; type: string; member: boolean; payload: any; } /** * A resource as sent by `checkly deploy`. The import plan API returns plain * ResourceSync entries and never carries `sourceFile`. */ export interface DeployResourceSync extends ResourceSync { /** * The file that declares the construct, relative to the git repository * root with posix separators. Absent outside a git repository or when the * file lives outside the repository. A hint: constructs instantiated in a * module imported by a check file or checkly.config.ts report the * importing file, so the backend should verify before editing. */ sourceFile?: string; } export interface AlertChannelFriendResource { type: 'alert-channel'; logicalId: string; physicalId: number; } export interface CheckGroupFriendResource { type: 'check-group'; logicalId: string; physicalId: number; } export interface PrivateLocationFriendResource { type: 'private-location'; logicalId: string; physicalId: string; } export interface StatusPageServiceFriendResource { type: 'status-page-service'; logicalId: string; physicalId: string; } export interface StatusPageFriendResource { type: 'status-page'; logicalId: string; physicalId: string; } export interface StatusPageComponentFriendResource { type: 'status-page-component'; logicalId: string; physicalId: string; } export type FriendResourceSync = AlertChannelFriendResource | CheckGroupFriendResource | PrivateLocationFriendResource | StatusPageServiceFriendResource | StatusPageFriendResource | StatusPageComponentFriendResource; export interface AuxiliaryResourceSync { physicalId?: string | number; type: string; payload: any; } export interface ProjectSync { project: Project; sharedFiles?: SharedFile[]; resources: Array; repoInfo: GitInformation | null; } export interface DeployedProject extends Project { id: string; createdAt: string; updatedAt: string | null; } export interface ProjectDeployResponse { project: DeployedProject; diff: Array; /** * Whether Checkly scheduled the deployed checks to run. Set by `deploy()` * from the deployment; false when it was asked not to, and when the deploy * had more checks than the scheduling threshold allows. Absent from an API * that predates the threshold. */ scheduled?: boolean; } export type ProjectDeploymentStatus = 'PENDING' | 'RUNNING' | 'SUCCEEDED' | 'FAILED' | 'CANCELLED'; export interface ProjectDeployment { id: string; logicalId: string; status: ProjectDeploymentStatus; dryRun: boolean; /** Opaque progress percentage (0-100). */ progress: number; error: { code: string; message: string; } | null; /** The applied { project, diff }; present once the deployment has succeeded. */ result: ProjectDeployResponse | null; /** * Whether the deploy schedules its checks. False when it was sent with * scheduleOnDeploy=false, and when it had more checks than the scheduling * threshold allows, which is decided from the applied diff: until the * deployment has finished it is the request. Absent from an API that * predates the threshold. */ scheduleOnDeploy?: boolean; createdAt: string; startedAt: string | null; endedAt: string | null; /** When cancellation was requested for this deployment, or null if it was not. */ cancelRequestedAt: string | null; } export declare class ProjectDeployFailedError extends Error { constructor(message: string, options?: ErrorOptions); } /** The deployment was cancelled before it finished (e.g. superseded by a newer deploy). */ export declare class ProjectDeployCancelledError extends Error { constructor(message: string, options?: ErrorOptions); } export interface ImportPlanFilter { type: 'include' | 'exclude'; resource?: { type: string; physicalId?: string | number; }; } export interface ImportPlanFriend { type: string; logicalId: string; } export interface ImportPlanOptions { preview?: boolean; filters?: ImportPlanFilter[]; friends?: ImportPlanFriend[]; } export interface ImportPlanChanges { resources: ResourceSync[]; friends?: FriendResourceSync[]; auxiliary?: AuxiliaryResourceSync[]; } export interface ImportPlan { id: string; createdAt: string; appliedAt?: string; committedAt?: string; changes?: ImportPlanChanges; } export declare class ProjectNotFoundError extends Error { logicalId: string; constructor(logicalId: string, options?: ErrorOptions); } export declare class ProjectAlreadyExistsError extends Error { logicalId: string; constructor(logicalId: string, options?: ErrorOptions); } export declare class NoImportableResourcesFoundError extends Error { constructor(options?: ErrorOptions); } /** * The plan a deploy was pinned to no longer describes Checkly's state: a * change landed between the preview and the deploy, so the deploy applied * nothing. `diff` is the plan as it looks now. */ export declare class ProjectPlanStaleError extends Error { readonly diff: DiffEntry[]; constructor(message: string, diff: DiffEntry[], options?: ErrorOptions); } /** * A deployment that was already running finished while this one waited for it. * Whatever it wrote, it moved the state the plan was computed against, so the * plan is stale before the deploy is even attempted — reported here rather * than after re-sending the whole payload for a refusal that is certain. * * A subtype of {@link ProjectPlanStaleError}: callers recover from both the * same way, by planning again. It carries no diff, because no new plan has * been computed yet. */ export declare class ProjectPlanSupersededError extends ProjectPlanStaleError { constructor(options?: ErrorOptions); } /** * The preview could not be computed because another operation is holding the * project. Transient: the operation holding it finishes. */ export declare class ProjectPreviewUnavailableError extends Error { constructor(message: string, options?: ErrorOptions); } /** * The account's Checkly API does not have the preview endpoint yet (a * self-hosted or not-yet-updated backend). Callers fall back to the older, * coarser deploy preview. */ export declare class ProjectPreviewNotSupportedError extends Error { constructor(options?: ErrorOptions); } /** * The account's Checkly API has deploy plans switched off at the moment. Unlike * an API without the preview endpoint, it knows every payload field a planned * deploy sends, so callers fall back to a deploy without a plan and leave the * payload as it is. */ export declare class ProjectPlanDisabledError extends Error { constructor(options?: ErrorOptions); } /** * `code` of what the API answers with while plans are switched off: the 404 of * the preview endpoint, and the 400 a deploy that needs a plan is refused with. */ export declare const DEPLOY_PLAN_DISABLED = "DEPLOY_PLAN_DISABLED"; export declare class ImportPlanNotFoundError extends Error { constructor(options?: ErrorOptions); } export declare class InvalidImportPlanStateError extends Error { constructor(options?: ErrorOptions); } declare class Projects extends RestResource { getAll(): Promise>; /** * @throws {ProjectNotFoundError} If the project does not exist. */ get(logicalId: string): Promise>; /** * @throws {ProjectAlreadyExistsError} If the project already exists. */ create(project: Project): Promise>; /** * Delete a project. The deletion runs asynchronously on the backend: this * submits it, then follows its progress stream to completion, so large projects * are no longer bound by the API gateway request timeout. A project that does * not exist is treated as already deleted (the endpoint is idempotent). * * @throws {ProjectDeployFailedError} If the deletion finishes unsuccessfully. */ deleteProject(logicalId: string, { preserveResources, cancelInProgress, onProgress, onStatus }?: { preserveResources?: boolean; /** * On a 409 (a deploy or delete is already in progress), cancel that * operation instead of waiting for it to finish, then retry. */ cancelInProgress?: boolean; onProgress?: (progress: number) => void; /** Human-readable status updates (e.g. while waiting on a predecessor). */ onStatus?: (message: string) => void; }): Promise; /** * Submit the async delete and follow it to completion. The endpoint responds * either with a deployment to follow (202), or — when there is nothing to delete * (the project does not exist) — a plain result with no deployment to follow. */ private submitDeletion; /** * What deploying this payload would change, per resource and per property, * without writing anything. * * The returned `planToken` pins the plan: pass it to {@link deploy} and the * deploy refuses if Checkly's state moved in between. A code-side edit * between the two is not such a move — the token describes Checkly's state, * not the payload — so previewing, editing and deploying still works. * * @throws {ProjectPreviewNotSupportedError} If the API has no preview endpoint. * @throws {ProjectPlanDisabledError} If the API has deploy plans switched off. * @throws {ProjectPreviewUnavailableError} If the project stayed busy. */ preview(resources: ProjectSync, { detail, preserveResources, pruneRelations, onStatus, }?: { detail?: ProjectPreviewDetail; preserveResources?: boolean; pruneRelations?: boolean; /** Human-readable status updates (e.g. while retrying behind another operation). */ onStatus?: (message: string) => void; }): Promise; /** * Deploy a project. The deployment runs asynchronously on the backend: this * submits it, then follows its progress stream to completion, so large projects * are no longer bound by the API gateway request timeout. A dry run returns the * preview diff synchronously without starting a deployment. * * @throws {ProjectDeployFailedError} If the deployment finishes unsuccessfully. */ deploy(resources: ProjectSync, { dryRun, scheduleOnDeploy, scheduleOnDeployScope, scheduleOnDeployThreshold, scheduleOnDeployMinFrequency, preserveResources, plan, pruneRelations, planToken, cancelInProgress, onProgress, onStatus, }?: { dryRun?: boolean; scheduleOnDeploy?: boolean; /** Which checks to schedule: the changed ones, or every deployed check. */ scheduleOnDeployScope?: ScheduleOnDeployScope; /** * Schedule no checks if the deploy would schedule more than this many, * not counting the ones the scope and the minimum frequency leave out. * Without it Checkly applies its own threshold. */ scheduleOnDeployThreshold?: number; /** * Leave out of scheduling the checks that run more often than every this * many minutes. Without it Checkly applies its own minimum. */ scheduleOnDeployMinFrequency?: number; /** * Keep resources removed from code (and their run history) in the account * instead of deleting them. */ preserveResources?: boolean; /** * Apply a plan: compare every resource with what was last deployed and * with its current state, and write only the ones that differ. Without * it the deploy writes every resource. `pruneRelations` and `planToken` * are refused by the API unless this is set. */ plan?: boolean; /** * Delete the alert channel subscriptions and private location assignments * on this project's checks and groups that the project does not manage. */ pruneRelations?: boolean; /** * The `planToken` of the preview this deploy was reviewed against. The * deploy is refused with {@link ProjectPlanStaleError}, having written * nothing, if Checkly's state moved since that preview. */ planToken?: string; /** * On a 409 (another deployment is already in progress), cancel that * deployment instead of waiting for it to finish, then retry. */ cancelInProgress?: boolean; onProgress?: (progress: number) => void; /** Human-readable status updates (e.g. while waiting on a predecessor). */ onStatus?: (message: string) => void; }): Promise<{ data: ProjectDeployResponse; }>; private submitDeployment; /** * Resolve a collision with an in-progress deployment so the caller can retry: * optionally cancel it, then wait until it reaches a final state (or is gone) * before returning — so the caller re-POSTs only when the slot is actually * free, never re-uploading the payload while the predecessor is still running. * * @returns Whether the predecessor was observed to reach a final state. * `false` means the wait hit its deadline with the predecessor still running, * which is a different situation for the caller: nothing has changed, so a * plan computed before the wait still stands, and re-POSTing surfaces the * conflict the caller needs to hear about. */ private resolveInProgressDeployment; getDeployment(logicalId: string, deploymentId: string): Promise>; /** Request cancellation of an in-flight deployment (idempotent on the server). */ cancelDeployment(logicalId: string, deploymentId: string): Promise>; /** * Long-poll the completion endpoint once: the server blocks up to * `maxWaitSeconds` and returns the deployment when it reaches a final state, or * 408 (`RequestTimeoutError`) if it is still running when that window elapses. * The retry cadence lives in the caller, not here. */ awaitDeploymentCompletion(logicalId: string, deploymentId: string, { maxWaitSeconds }?: { maxWaitSeconds?: number; }): Promise; /** * Follow a deployment to completion over its Server-Sent Events stream, * invoking `onProgress` as progress frames arrive and resolving with the final * deployment on the terminal `complete` frame. If the stream drops before a * terminal frame (a transient network blip), it reconnects up to `maxReconnects` * times — the server is stateless and re-reads current state, so resuming needs * no cursor. */ streamDeploymentEvents(logicalId: string, deploymentId: string, { onProgress, maxReconnects }?: { onProgress?: (progress: number) => void; maxReconnects?: number; }): Promise; private openEventStream; private consumeEventStream; /** * @throws {ProjectNotFoundError} If the project does not exist. * @throws {NoImportableResourcesFoundError} If no importable resources were found. */ createImportPlan(logicalId: string, options?: ImportPlanOptions): Promise>; /** * @throws {ProjectNotFoundError} If the project does not exist. */ findImportPlans(logicalId: string, { onlyUnapplied, onlyUncommitted }?: { onlyUnapplied?: boolean | undefined; onlyUncommitted?: boolean | undefined; }): Promise>; listImportPlans({ onlyUnapplied, onlyUncommitted }?: { onlyUnapplied?: boolean | undefined; onlyUncommitted?: boolean | undefined; }): Promise>; /** * @throws {ImportPlanNotFoundError} If the import plan does not exist. * @throws {InvalidImportPlanStateError} If the operation is performed out of order. */ cancelImportPlan(importPlanId: string): Promise>; /** * @throws {ImportPlanNotFoundError} If the import plan does not exist. * @throws {InvalidImportPlanStateError} If the operation is performed out of order. */ applyImportPlan(importPlanId: string): Promise>; /** * @throws {ImportPlanNotFoundError} If the import plan does not exist. * @throws {InvalidImportPlanStateError} If the operation is performed out of order. */ commitImportPlan(importPlanId: string): Promise>; } export default Projects;