@theholocron/holocron-plugin-checkly 5.0.0-alpha.522 → 5.0.0-alpha.524

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -5,7 +5,7 @@
5
5
  * Also exports `verifyToken` + `AUTH_HINT` for `holocron check token`. See
6
6
  * README for auth + config docs.
7
7
  */
8
- import { AuthError, Monitoring, MonitoringAlertChannelInput, MonitoringAlertChannelResult, MonitoringAlertChannelState, MonitoringCheck, MonitoringCheckInput, MonitoringDashboardInput, MonitoringDashboardState, MonitoringHeartbeatInput, MonitoringHeartbeatResult, MonitoringStatusPageInput, MonitoringStatusPageResult, MonitoringStatusPageState, PluginToken, ResolveTokenInput, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess } from "@theholocron/cli";
8
+ import { AuthError, Monitoring, MonitoringAlertChannelInput, MonitoringAlertChannelResult, MonitoringAlertChannelState, MonitoringCheck, MonitoringCheckInput, MonitoringDashboardInput, MonitoringDashboardState, MonitoringHeartbeatInput, MonitoringHeartbeatResult, MonitoringIncident, MonitoringIncidentQuery, MonitoringStatusPageInput, MonitoringStatusPageResult, MonitoringStatusPageState, PluginToken, ResolveTokenInput, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess } from "@theholocron/cli";
9
9
  import { ApiCheck, ApiCheckInput, ApiCheckRequest, Assertion, AssertionComparison, AssertionSource, ChecklyClient, ChecklyClientOptions, Dashboard, DashboardInput, Heartbeat, HeartbeatInput, HeartbeatUnit, HttpMethod, ListChecksParams, createChecklyClient } from "@theholocron/checkly-client";
10
10
  /** Resolves the Checkly API key from `--token`, `HOLOCRON_CHECKLY_TOKEN`, `CHECKLY_API_KEY` or the keyring, and throws an `AuthError` when none is set. */
11
11
  export declare const resolveToken: import("@theholocron/cli").TokenResolver;
@@ -97,6 +97,8 @@ export declare class ChecklyMonitoring implements Monitoring {
97
97
  ensureStatusPage(input: MonitoringStatusPageInput): Promise<MonitoringStatusPageResult>;
98
98
  /** Reads the status page `input.name` and compares it with the declaration. */
99
99
  inspectStatusPage(input: MonitoringStatusPageInput): Promise<MonitoringStatusPageState>;
100
+ /** The incidents of a status page, with their updates; see `capabilities/incidents.ts`. */
101
+ listIncidents(query: MonitoringIncidentQuery): Promise<MonitoringIncident[]>;
100
102
  /** Checkly's `search` param is a case-insensitive partial match — narrow to the exact name ourselves. */
101
103
  private findByExactName;
102
104
  /** Find-or-create-or-update a dashboard by its header; see `./dashboards.ts`. */
package/dist/index.mjs CHANGED
@@ -193,6 +193,58 @@ function result(h, alreadyExists) {
193
193
  ...h.heartbeat.pingUrl ? { pingUrl: h.heartbeat.pingUrl } : {}
194
194
  };
195
195
  }
196
+ // src/capabilities/incidents.ts
197
+ const IMPACTS = {
198
+ UNDER_MAINTENANCE: "maintenance",
199
+ DEGRADED_PERFORMANCE: "degraded",
200
+ PARTIAL_OUTAGE: "partial",
201
+ MAJOR_OUTAGE: "major"
202
+ };
203
+ function statusOf$1(status) {
204
+ const lower = (status ?? "investigating").toLowerCase();
205
+ return lower === "identified" || lower === "monitoring" || lower === "resolved" ? lower : "investigating";
206
+ }
207
+ /** True when the incident is still open or was updated on or after the day of `since`. */
208
+ function wanted(item, since) {
209
+ if (item.lastUpdateStatus !== "RESOLVED" || since === void 0 || !item.updated_at) return true;
210
+ return item.updated_at.slice(0, 10) >= since.slice(0, 10);
211
+ }
212
+ /** An incident as Checkly returns it, in the neutral shape; `names` maps a component id to its name. */
213
+ function fromChecklyIncident(incident, names) {
214
+ const updates = (incident.incidentUpdates ?? []).map((u) => ({
215
+ id: u.id,
216
+ status: statusOf$1(u.status),
217
+ text: u.description,
218
+ at: u.publicIncidentUpdateDate ?? u.created_at
219
+ })).sort((a, b) => a.at.localeCompare(b.at));
220
+ const last = updates.at(-1);
221
+ const status = last?.status ?? statusOf$1(incident.lastUpdateStatus);
222
+ return {
223
+ id: incident.id,
224
+ title: incident.name,
225
+ status,
226
+ impacts: (incident.componentImpacts ?? []).map((c) => ({
227
+ component: c.name ?? names.get(c.componentId ?? "") ?? c.componentId ?? "unknown",
228
+ impact: IMPACTS[c.impact] ?? "degraded"
229
+ })),
230
+ startedAt: incident.created_at,
231
+ ...status === "resolved" && last ? { resolvedAt: last.at } : {},
232
+ ...incident.duration != null ? { durationSeconds: incident.duration } : {},
233
+ updates
234
+ };
235
+ }
236
+ /** The incidents of the page named `query.statusPage`: every open one, and those updated since `query.since`. */
237
+ async function listChecklyIncidents(client, query) {
238
+ const page = (await client.statusPages.list()).find((p) => p.name === query.statusPage);
239
+ if (!page) throw new Error(`status page "${query.statusPage}" not found`);
240
+ const summaries = (await client.statusPages.incidents.list(page.id)).filter((i) => wanted(i, query.since));
241
+ if (summaries.length === 0) return [];
242
+ const incidents = await Promise.all(summaries.map((i) => client.statusPages.incidents.get(page.id, i.id)));
243
+ const needNames = incidents.some((i) => i.componentImpacts?.some((c) => !c.name));
244
+ const names = /* @__PURE__ */ new Map();
245
+ if (needNames) for (const c of await client.statusPages.components.list(page.id)) names.set(c.id, c.name);
246
+ return incidents.map((i) => fromChecklyIncident(i, names));
247
+ }
196
248
  // src/capabilities/status-pages.ts
197
249
  /**
198
250
  * Status pages for the Checkly `monitoring` capability (spec `tech-monitoring-dashboards-status-pages`, #2302).
@@ -957,6 +1009,10 @@ var ChecklyMonitoring = class {
957
1009
  inspectStatusPage(input) {
958
1010
  return inspectStatusPage(this.client(), input);
959
1011
  }
1012
+ /** The incidents of a status page, with their updates; see `capabilities/incidents.ts`. */
1013
+ listIncidents(query) {
1014
+ return listChecklyIncidents(this.client(), query);
1015
+ }
960
1016
  /** Checkly's `search` param is a case-insensitive partial match — narrow to the exact name ourselves. */
961
1017
  async findByExactName(name) {
962
1018
  return (await this.client().checks.list({ search: name })).find((c) => c.name === name);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-checkly",
3
- "version": "5.0.0-alpha.522",
3
+ "version": "5.0.0-alpha.524",
4
4
  "description": "Holocron plugin for Checkly. Implements the monitoring capability against Checkly's REST API, plus exports verifyToken + AUTH_HINT for `holocron auth`.",
5
5
  "keywords": [
6
6
  "checkly",
@@ -42,15 +42,15 @@
42
42
  "typescript": "^6.0.3",
43
43
  "vitest": "^5.1.0",
44
44
  "@theholocron/checkly-client": "^1.58.0-alpha.53",
45
- "@theholocron/cli": "5.0.0-alpha.522",
46
- "@theholocron/http-client": "^1.58.0-alpha.53",
47
45
  "@theholocron/misc-utils": "^1.17.0-alpha.5",
48
- "@theholocron/tsconfig": "^8.9.0-alpha.22"
46
+ "@theholocron/tsconfig": "^8.9.0-alpha.22",
47
+ "@theholocron/http-client": "^1.58.0-alpha.53",
48
+ "@theholocron/cli": "5.0.0-alpha.524"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@theholocron/checkly-client": "^1.55.0",
52
52
  "@theholocron/misc-utils": "^1.16.0",
53
- "@theholocron/cli": "5.0.0-alpha.522"
53
+ "@theholocron/cli": "5.0.0-alpha.524"
54
54
  },
55
55
  "engines": {
56
56
  "node": ">=22"