@theholocron/holocron-plugin-checkly 5.0.0-alpha.284 → 5.0.0-alpha.326

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/README.md CHANGED
@@ -41,7 +41,7 @@ holocron auth check checkly # verify — hits GET /v1/accounts
41
41
  header) — it is not a secret, the same status as Vercel's `teamId`.
42
42
  `checks` is the list of API checks `holocron repo setup` ensures exist,
43
43
  each matched and upserted by exact `name`. **`locations` is required** —
44
- Checkly rejects a check with neither `locations` nor `privateLocations`
44
+ Checkly refuses a check with neither `locations` nor `privateLocations`
45
45
  set (`400 "You have to set at least one location or privateLocation"`)
46
46
  on any account with no account-level default configured, which includes
47
47
  every free Hobby/trial account. **`shouldFail` is required whenever the
@@ -84,12 +84,23 @@ monitoring: [
84
84
  ];
85
85
  ```
86
86
 
87
+ ### Alert channels
88
+
89
+ The alert channel is declared in the notification layout (`feeds.monitoring`), whose `alerts` object sets what it
90
+ alerts about (`failure`, `recovery`, `degraded`, `sslExpiry`, `sslExpiryThreshold`; a new channel defaults to the first
91
+ three on and `sslExpiry` off, and on an existing one a setting left out is left alone). A check routes itself with
92
+ `alertChannels: ["Message to #uptime"]`, the names of the alert channels it alerts through; left out, it alerts through
93
+ all of them. Setup adds subscriptions and never removes one; `holocron doctor notifications` reports a check still
94
+ subscribed to a channel it is routed away from.
95
+
87
96
  ## What's implemented
88
97
 
89
98
  - `monitoring.ensureCheck(input)` — find-by-exact-name (Checkly's own
90
99
  `search` query param is a case-insensitive partial match, so results
91
100
  are filtered client-side for an exact match), then create or update
92
101
  the API check accordingly.
102
+ - `monitoring.ensureAlertChannel(input)` / `monitoring.inspectAlertChannel(name)` — the Discord alert channel, its
103
+ alert settings and its routed subscriptions.
93
104
  - `monitoring.whoami()` — lightweight auth probe (`GET /checks?limit=1`).
94
105
  - `monitoring.checks` — the configured check list, read by
95
106
  `holocron repo setup` to loop over `ensureCheck`.
package/dist/index.d.mts CHANGED
@@ -31,9 +31,12 @@ export declare class ChecklyMonitoring implements Monitoring {
31
31
  listChecks(): Promise<MonitoringCheckInput[]>;
32
32
  /**
33
33
  * A Discord alert channel: a `WEBHOOK` Checkly formats for Discord. Found by name, so one made by hand is adopted and
34
- * kept up to date, not duplicated. Every check on the account is subscribed, since a check made through the API is
35
- * never subscribed on its own; subscriptions already there (including ones to checks outside Holocron) are kept.
36
- * An existing channel keeps its own message template and send settings.
34
+ * kept up to date, not duplicated. Every check routed to the channel is subscribed (all of them, unless a configured
35
+ * check names its `alertChannels`; a check the config does not declare is not subject to routing), since a check
36
+ * made through the API is never subscribed on its own; subscriptions already there (including ones to checks outside
37
+ * Holocron, and ones to a check routed elsewhere) are kept, never removed. The alert settings the config states
38
+ * (`input.alerts`) are applied; an existing channel keeps every other send setting, and its message template only
39
+ * while it is the shipped one.
37
40
  *
38
41
  * Subscriptions go through Checkly's subscriptions call and are then read back: its create and update accept a
39
42
  * `subscriptions` list but were seen not to apply it, so the count returned is what Checkly holds, and a check that
@@ -43,6 +46,7 @@ export declare class ChecklyMonitoring implements Monitoring {
43
46
  /**
44
47
  * After an update replaced the channel: read it back and put back any subscription it had that did not survive, of
45
48
  * every kind (a group, a check outside this account) and in the state it had (a deactivated one stays deactivated).
49
+ * Then read it once more: a subscription that could not be put back is an error, not a quiet loss.
46
50
  */
47
51
  private restoreSubscriptions;
48
52
  /** One subscribe call; Checkly's 409 means the subscription is already there, which is what was wanted. */
@@ -58,8 +62,12 @@ export declare class ChecklyMonitoring implements Monitoring {
58
62
  * is a credential, so only the webhook id inside it is returned, enough to tell which webhook it is.
59
63
  */
60
64
  inspectAlertChannel(name: string): Promise<MonitoringAlertChannelState>;
61
- /** The id of every check on the account, read a page at a time. */
62
- private allCheckIds;
65
+ /**
66
+ * Which of the account's checks alert through the channel `name`: every one, except a declared check that names its
67
+ * `alertChannels` without it (see {@link routedAway}). A check the config does not declare is not subject to routing:
68
+ * it alerts through every channel, as one made by hand always has.
69
+ */
70
+ private routedTo;
63
71
  /** Every check on the account, read a page at a time. */
64
72
  private allChecks;
65
73
  /** Checkly's `search` param is a case-insensitive partial match — narrow to the exact name ourselves. */
package/dist/index.mjs CHANGED
@@ -23,6 +23,17 @@ const CHECKLY_ICON = {
23
23
  /** The icon embedded as a base64 PNG data URI, used when the URL cannot be reached. */
24
24
  dataUri: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAATAAAAEwCAMAAAAHJd3BAAAA6lBMVEX////f7v+/3f+fy/+Qwv+Auv9wsv9gqf9QoP9Al/8wj/8ghv8Qff8Adf/P5f/v9v+v1P+gy//f7f8Qfv9wsf+Qw/+w0/8wjv9Qof+v0/+Pwv/v9/9/uv+Pw/+/ydOAkqhQaoggQWgAJlIwT3Pv8fRvsf+QoLNgd5JAXH1gd5Ogrb7f5Omvu8kQNF3v8fWfrb7P197P1t5whZ6/ydSwu8l/k6lwhZ2PoLRvhZ6frr6PoLNfeJN/k6hfd5MwT3KAkqnP199fqP/P5P9gqP+vwNQQYL4QPXMASZ0AcPUAOn0AZt4AK10AWL5Qg77qkM9cAAALsUlEQVR4Aezbh4GsIBRG4QUHkfBPdlP/fb5cwLu7Zs5XwpEk47wAAAAAAAAAAAAAwD45533XnULoY4xD+iWXf6omU8s/6bchxhhC6Drvz+7ysgMXd+1CHHKp2oCSU+xPV7/JdO56irloo/LQX/12htW1T1U7kOPtvHos3xftSR1u9/Vqdalqh3K/ykDzQ9Vu5aXH2SUU7Vy8L5mr6v+R7GTJRTKfdByPMHuvp46lzDvI7lmHM845HasO6Dnfaq9jyjNNyyALFrIgUYxeXypGLylPfM141dEN056/ig5v0kN/UQM8C5hNuUw2IWXCkb/IgknZqRVpmvvVombcWPFtCiuY0Y0VzCYzwJbeKL1M2CijGnP55plCrRlZ8hedk4PEnGRGzjcnX9WexB5p8/jOnHxTgzxLmE1gCbNJfNtk8/h6sKQmuS8Hq7LgUuysNj252rF55wM6m8Kbt9GFTdLmzCZpc+PFyGbkVGETOVXYvHOfb5P5qML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84Xd3MFTxN1PrXgHNPYdlEiju48b6A5faQ+kVUBsfA8hdvMt958iBLc83CHLaSizvyj9N0s8zg6MjutCnTh5N1ZlfmSiyXU631HaO22RgzCcEV6Lzmx6cKP2mDMNbwCXUCskHhxgUNHDUwaLgWdmTTKHEzXDN4SMMcuUTe8OpwS+SNsTlgaIxtAEFjLF9Cg4E5t+3d12lQM/1oSIP7BnN5k0HDTpY3KynldLVpbDU0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ8LX4GOldjeT7Ifd8AAAAASUVORK5CYII="
25
25
  };
26
+ // src/routing.ts
27
+ /**
28
+ * Whether the config routes the check `checkName` away from the alert channel `channelName`: it declares the check with
29
+ * a non-empty `alertChannels` that does not name the channel (compared without regard to case, as `notifications setup`
30
+ * does). A check the config does not declare, or declares with no routes (or an empty list), alerts through every channel.
31
+ */
32
+ function routedAway(declared, checkName, channelName) {
33
+ const to = declared.find((d) => d.name === checkName)?.alertChannels;
34
+ if (to === void 0 || to.length === 0) return false;
35
+ return !to.some((n) => n.toLowerCase() === channelName.toLowerCase());
36
+ }
26
37
  // src/same-template.ts
27
38
  /** Whether two templates are the same message, whatever the whitespace between the lines. */
28
39
  const sameTemplate = (a, b) => (a ?? "").replace(/\s+/g, "") === b.replace(/\s+/g, "");
@@ -105,6 +116,16 @@ function toChecklyPayload(input) {
105
116
  }
106
117
  };
107
118
  }
119
+ /** The Checkly fields an alert channel's settings map to, for the settings the config states. */
120
+ function alertFields(alerts) {
121
+ return {
122
+ ...alerts?.failure !== void 0 ? { sendFailure: alerts.failure } : {},
123
+ ...alerts?.recovery !== void 0 ? { sendRecovery: alerts.recovery } : {},
124
+ ...alerts?.degraded !== void 0 ? { sendDegraded: alerts.degraded } : {},
125
+ ...alerts?.sslExpiry !== void 0 ? { sslExpiry: alerts.sslExpiry } : {},
126
+ ...alerts?.sslExpiryThreshold !== void 0 ? { sslExpiryThreshold: alerts.sslExpiryThreshold } : {}
127
+ };
128
+ }
108
129
  /** The Checkly implementation of the `monitoring` capability: ensures the configured API checks and alert channels exist. */
109
130
  var ChecklyMonitoring = class {
110
131
  client;
@@ -163,9 +184,12 @@ var ChecklyMonitoring = class {
163
184
  }
164
185
  /**
165
186
  * A Discord alert channel: a `WEBHOOK` Checkly formats for Discord. Found by name, so one made by hand is adopted and
166
- * kept up to date, not duplicated. Every check on the account is subscribed, since a check made through the API is
167
- * never subscribed on its own; subscriptions already there (including ones to checks outside Holocron) are kept.
168
- * An existing channel keeps its own message template and send settings.
187
+ * kept up to date, not duplicated. Every check routed to the channel is subscribed (all of them, unless a configured
188
+ * check names its `alertChannels`; a check the config does not declare is not subject to routing), since a check
189
+ * made through the API is never subscribed on its own; subscriptions already there (including ones to checks outside
190
+ * Holocron, and ones to a check routed elsewhere) are kept, never removed. The alert settings the config states
191
+ * (`input.alerts`) are applied; an existing channel keeps every other send setting, and its message template only
192
+ * while it is the shipped one.
169
193
  *
170
194
  * Subscriptions go through Checkly's subscriptions call and are then read back: its create and update accept a
171
195
  * `subscriptions` list but were seen not to apply it, so the count returned is what Checkly holds, and a check that
@@ -173,7 +197,8 @@ var ChecklyMonitoring = class {
173
197
  */
174
198
  async ensureAlertChannel(input) {
175
199
  const client = this.client();
176
- const [channels, checkIds] = await Promise.all([client.alertChannels.list(), this.allCheckIds()]);
200
+ const [channels, allChecks] = await Promise.all([client.alertChannels.list(), this.allChecks()]);
201
+ const checkIds = this.routedTo(input.name, allChecks).routed.map((c) => c.id);
177
202
  const existing = channels.find((c) => c.type === "WEBHOOK" && c.config.name === input.name);
178
203
  if (!existing) {
179
204
  if (!input.url) throw new Error(`cannot create alert channel "${input.name}": its webhook already exists and Discord shows a webhook URL only once, so delete that webhook and run setup again`);
@@ -191,7 +216,8 @@ var ChecklyMonitoring = class {
191
216
  sendFailure: true,
192
217
  sendRecovery: true,
193
218
  sendDegraded: true,
194
- autoSubscribe: false
219
+ autoSubscribe: false,
220
+ ...alertFields(input.alerts)
195
221
  });
196
222
  const { active } = await this.subscribeMissing(created.id, input.name, checkIds);
197
223
  return {
@@ -203,8 +229,10 @@ var ChecklyMonitoring = class {
203
229
  const urlChanged = input.url !== void 0 && existing.config.url !== input.url;
204
230
  const formatChanged = existing.config.webhookType !== "WEBHOOK_DISCORD";
205
231
  const templateChanged = !formatChanged && !sameTemplate(existing.config.template, DISCORD_TEMPLATE);
232
+ const wanted = alertFields(input.alerts);
233
+ const alertsChanged = Object.keys(wanted).some((k) => existing[k] !== wanted[k]);
206
234
  let current;
207
- if (urlChanged || formatChanged || templateChanged) {
235
+ if (urlChanged || formatChanged || templateChanged || alertsChanged) {
208
236
  const fresh = await client.alertChannels.get(existing.id);
209
237
  const replacement = {
210
238
  type: "WEBHOOK",
@@ -216,12 +244,13 @@ var ChecklyMonitoring = class {
216
244
  template: DISCORD_TEMPLATE
217
245
  } : {}
218
246
  },
219
- sendRecovery: existing.sendRecovery,
220
- sendFailure: existing.sendFailure,
221
- sendDegraded: existing.sendDegraded,
222
- sslExpiry: existing.sslExpiry,
223
- sslExpiryThreshold: existing.sslExpiryThreshold,
224
- autoSubscribe: existing.autoSubscribe,
247
+ sendRecovery: fresh.sendRecovery,
248
+ sendFailure: fresh.sendFailure,
249
+ sendDegraded: fresh.sendDegraded,
250
+ sslExpiry: fresh.sslExpiry,
251
+ sslExpiryThreshold: fresh.sslExpiryThreshold,
252
+ autoSubscribe: fresh.autoSubscribe,
253
+ ...wanted,
225
254
  subscriptions: fresh.subscriptions.map((s) => s.checkId ? {
226
255
  checkId: s.checkId,
227
256
  activated: s.activated
@@ -231,7 +260,7 @@ var ChecklyMonitoring = class {
231
260
  })
232
261
  };
233
262
  await client.alertChannels.update(existing.id, replacement);
234
- current = await this.restoreSubscriptions(existing.id, fresh.subscriptions);
263
+ current = await this.restoreSubscriptions(existing.id, input.name, fresh.subscriptions);
235
264
  }
236
265
  const { added, active } = await this.subscribeMissing(existing.id, input.name, checkIds, current);
237
266
  return {
@@ -240,6 +269,7 @@ var ChecklyMonitoring = class {
240
269
  ...urlChanged ? ["url"] : [],
241
270
  ...formatChanged ? ["format"] : [],
242
271
  ...templateChanged ? ["template"] : [],
272
+ ...alertsChanged ? ["alerts"] : [],
243
273
  ...added > 0 ? ["subscriptions"] : []
244
274
  ],
245
275
  subscribed: active
@@ -248,14 +278,26 @@ var ChecklyMonitoring = class {
248
278
  /**
249
279
  * After an update replaced the channel: read it back and put back any subscription it had that did not survive, of
250
280
  * every kind (a group, a check outside this account) and in the state it had (a deactivated one stays deactivated).
281
+ * Then read it once more: a subscription that could not be put back is an error, not a quiet loss.
251
282
  */
252
- async restoreSubscriptions(channelId, had) {
283
+ async restoreSubscriptions(channelId, name, had) {
253
284
  const client = this.client();
285
+ const held = (channel, s) => channel.subscriptions.some((a) => s.checkId ? a.checkId === s.checkId : a.groupId === s.groupId);
254
286
  const after = await client.alertChannels.get(channelId);
255
- const held = (s) => after.subscriptions.some((a) => s.checkId ? a.checkId === s.checkId : a.groupId === s.groupId);
256
- const lost = had.filter((s) => !held(s));
257
- for (const s of lost) await this.subscribeTolerating(channelId, s);
258
- return lost.length > 0 ? await client.alertChannels.get(channelId) : after;
287
+ const lost = had.filter((s) => !held(after, s));
288
+ if (lost.length === 0) return after;
289
+ const failures = [];
290
+ for (const s of lost) {
291
+ const failure = await this.subscribeTolerating(channelId, s);
292
+ if (failure) failures.push(failure);
293
+ }
294
+ const restored = await client.alertChannels.get(channelId);
295
+ const gone = lost.filter((s) => !held(restored, s));
296
+ if (gone.length > 0) {
297
+ const cause = failures[0] instanceof Error ? `: ${failures[0].message}` : "";
298
+ throw new Error(`updating alert channel "${name}" dropped ${gone.length} of its subscriptions and Checkly would not take them back${cause}; subscribe them again in Checkly's alert settings`);
299
+ }
300
+ return restored;
259
301
  }
260
302
  /** One subscribe call; Checkly's 409 means the subscription is already there, which is what was wanted. */
261
303
  async subscribeTolerating(channelId, subscription) {
@@ -311,27 +353,47 @@ var ChecklyMonitoring = class {
311
353
  */
312
354
  async inspectAlertChannel(name) {
313
355
  const client = this.client();
314
- const [channels, checks] = await Promise.all([client.alertChannels.list(), this.allChecks()]);
356
+ const [channels, allChecks] = await Promise.all([client.alertChannels.list(), this.allChecks()]);
357
+ const { routed, routedAway: away } = this.routedTo(name, allChecks);
315
358
  const listed = channels.find((c) => c.type === "WEBHOOK" && c.config.name === name);
316
359
  if (!listed) return {
317
360
  exists: false,
318
361
  unsubscribed: [],
362
+ misrouted: [],
319
363
  deactivated: []
320
364
  };
321
365
  const channel = await client.alertChannels.get(listed.id);
322
366
  const subscribed = new Map(channel.subscriptions.flatMap((s) => s.checkId ? [[s.checkId, s.activated]] : []));
367
+ const groups = channel.subscriptions.filter((s) => s.groupId && s.activated).length;
323
368
  const webhookId = DISCORD_WEBHOOK_ID.exec(listed.config.url)?.[1];
324
369
  return {
325
370
  exists: true,
326
371
  discord: listed.config.webhookType === "WEBHOOK_DISCORD",
327
372
  ...webhookId ? { webhookId } : {},
328
- unsubscribed: checks.filter((c) => !subscribed.has(c.id)).map((c) => c.name),
329
- deactivated: checks.filter((c) => subscribed.get(c.id) === false).map((c) => c.name)
373
+ alerts: {
374
+ failure: channel.sendFailure,
375
+ recovery: channel.sendRecovery,
376
+ degraded: channel.sendDegraded,
377
+ sslExpiry: channel.sslExpiry,
378
+ sslExpiryThreshold: channel.sslExpiryThreshold
379
+ },
380
+ unsubscribed: routed.filter((c) => !subscribed.has(c.id)).map((c) => c.name),
381
+ misrouted: away.filter((c) => subscribed.has(c.id)).map((c) => c.name),
382
+ ...away.length > 0 && groups > 0 ? { groupSubscriptions: groups } : {},
383
+ deactivated: routed.filter((c) => subscribed.get(c.id) === false).map((c) => c.name)
330
384
  };
331
385
  }
332
- /** The id of every check on the account, read a page at a time. */
333
- async allCheckIds() {
334
- return (await this.allChecks()).map((c) => c.id);
386
+ /**
387
+ * Which of the account's checks alert through the channel `name`: every one, except a declared check that names its
388
+ * `alertChannels` without it (see {@link routedAway}). A check the config does not declare is not subject to routing:
389
+ * it alerts through every channel, as one made by hand always has.
390
+ */
391
+ routedTo(name, checks) {
392
+ const away = (c) => routedAway(this.checks, c.name, name);
393
+ return {
394
+ routed: checks.filter((c) => !away(c)),
395
+ routedAway: checks.filter(away)
396
+ };
335
397
  }
336
398
  /** Every check on the account, read a page at a time. */
337
399
  async allChecks() {
@@ -365,15 +427,18 @@ async function findChannel(client, deps) {
365
427
  }
366
428
  // src/probes/channel.ts
367
429
  const PAGE = 100;
368
- async function allCheckIds(client) {
369
- const ids = [];
430
+ async function allChecks(client) {
431
+ const found = [];
370
432
  for (let page = 1;; page++) {
371
433
  const batch = await client.checks.list({
372
434
  limit: PAGE,
373
435
  page
374
436
  });
375
- ids.push(...batch.map((c) => c.id));
376
- if (batch.length < PAGE) return ids;
437
+ found.push(...batch.map((c) => ({
438
+ id: c.id,
439
+ name: c.name
440
+ })));
441
+ if (batch.length < PAGE) return found;
377
442
  }
378
443
  }
379
444
  function channelProbe(deps) {
@@ -409,7 +474,7 @@ function channelProbe(deps) {
409
474
  label: "template differs from the shipped one",
410
475
  detail: "run `holocron notifications setup` to put it back"
411
476
  });
412
- const [ids] = await Promise.all([allCheckIds(client)]);
477
+ const ids = (await allChecks(client)).filter((c) => !routedAway(deps.checks ?? [], c.name, channel.config.name)).map((c) => c.id);
413
478
  const subscribed = new Set(channel.subscriptions.filter((s) => s.checkId && s.activated !== false).map((s) => s.checkId));
414
479
  const missing = ids.filter((id) => !subscribed.has(id)).length;
415
480
  probe.say(missing === 0 ? {
@@ -585,7 +650,10 @@ function createPlugin(options) {
585
650
  return {
586
651
  name: "@theholocron/holocron-plugin-checkly",
587
652
  probes: {
588
- ...checklyProbes({ client: ctx.client }),
653
+ ...checklyProbes({
654
+ client: ctx.client,
655
+ checks: options.checks
656
+ }),
589
657
  connection: connectionProbe({
590
658
  provider: "Checkly",
591
659
  url: options.baseUrl ?? "https://api.checklyhq.com",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-checkly",
3
- "version": "5.0.0-alpha.284",
3
+ "version": "5.0.0-alpha.326",
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",
@@ -38,16 +38,16 @@
38
38
  "tsx": "4.23.15",
39
39
  "typescript": "^5.9.3",
40
40
  "vitest": "^5.0.5",
41
- "@theholocron/checkly-client": "^1.58.0-alpha.3",
42
- "@theholocron/cli": "5.0.0-alpha.284",
43
- "@theholocron/http-client": "^1.58.0-alpha.3",
44
- "@theholocron/misc-utils": "^1.16.1-alpha.3",
45
- "@theholocron/tsconfig": "^8.9.0-alpha.5"
41
+ "@theholocron/checkly-client": "^1.58.0-alpha.7",
42
+ "@theholocron/cli": "5.0.0-alpha.326",
43
+ "@theholocron/http-client": "^1.58.0-alpha.7",
44
+ "@theholocron/tsconfig": "^8.9.0-alpha.8",
45
+ "@theholocron/misc-utils": "^1.17.0-alpha.1"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "@theholocron/checkly-client": "^1.55.0",
49
49
  "@theholocron/misc-utils": "^1.16.0",
50
- "@theholocron/cli": "5.0.0-alpha.284"
50
+ "@theholocron/cli": "5.0.0-alpha.326"
51
51
  },
52
52
  "engines": {
53
53
  "node": ">=22"
@@ -56,11 +56,11 @@
56
56
  "access": "public"
57
57
  },
58
58
  "scripts": {
59
- "delivery.build": "tsdown",
60
- "sourceQuality.staticAnalysis": "eslint .",
59
+ "build": "tsdown",
60
+ "lint:code": "eslint .",
61
+ "test:unit": "vitest run --coverage",
61
62
  "test:watch": "vitest",
62
- "validate": "tsx scripts/validate.mjs",
63
- "verification.typeSafety": "tsc --noEmit",
64
- "verification.unitTests": "vitest run"
63
+ "typecheck": "tsc --noEmit",
64
+ "validate:plugin": "tsx scripts/validate.mjs"
65
65
  }
66
66
  }