@theholocron/holocron-plugin-checkly 5.0.0-alpha.229 → 5.0.0-alpha.230

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
@@ -81,6 +81,7 @@ declare function createContext(options: ChecklyPluginOptions): PluginContext;
81
81
  declare function monitoring(ctx: PluginContext): Monitoring;
82
82
  declare function createPlugin(options: ChecklyPluginOptions): {
83
83
  name: string;
84
+ probes: import("@theholocron/cli").PluginProbes;
84
85
  capabilities: {
85
86
  monitoring: () => Monitoring;
86
87
  };
package/dist/index.mjs CHANGED
@@ -20,6 +20,10 @@ const CHECKLY_ICON = {
20
20
  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/U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lCcNSrrP9t2piyBsvFDzdnfkS2ynDb5D/yZsrKc/bOkFoksXv/1ILYIbGFIzu+dcvq3cOcCioOsX/5zF1on/gCqJzk9+d3af/H1ZEGUQPC/XwOrH55TysIz8M9D+TEnr1rxM+H8/yeBB3UlW85vVmMHcbAfUwdRcppu1gqeBtl6nq7kR2FCWi9aSKfTaZrOF4WSGP84Xd3MFTxN1PrXgHNPYdlEiju48b6A5faQ+kVUBsfA8hdvMt958iBLc83CHLaSizvyj9N0s8zg6MjutCnTh5N1ZlfmSiyXU631HaO22RgzCcEV6Lzmx6cKP2mDMNbwCXUCskHhxgUNHDUwaLgWdmTTKHEzXDN4SMMcuUTe8OpwS+SNsTlgaIxtAEFjLF9Cg4E5t+3d12lQM/1oSIP7BnN5k0HDTpY3KynldLVpbDU0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ8LX4GOldjeT7Ifd8AAAAASUVORK5CYII="
21
21
  };
22
22
  //#endregion
23
+ //#region src/same-template.ts
24
+ /** Whether two templates are the same message, whatever the whitespace between the lines. */
25
+ const sameTemplate = (a, b) => (a ?? "").replace(/\s+/g, "") === b.replace(/\s+/g, "");
26
+ //#endregion
23
27
  //#region src/capabilities/monitoring.ts
24
28
  /**
25
29
  * `monitoring` capability for Checkly.
@@ -66,8 +70,6 @@ function toChecklyPayload(input) {
66
70
  }
67
71
  };
68
72
  }
69
- /** Whether two templates are the same message, whatever the whitespace between the lines. */
70
- const sameTemplate = (a, b) => (a ?? "").replace(/\s+/g, "") === b.replace(/\s+/g, "");
71
73
  var ChecklyMonitoring = class {
72
74
  client;
73
75
  key = "monitoring";
@@ -270,6 +272,192 @@ var ChecklyMonitoring = class {
270
272
  return (await this.client().checks.list({ search: name })).find((c) => c.name === name);
271
273
  }
272
274
  };
275
+ const channelName = (deps) => (deps.env ?? process.env)["HOLOCRON_CHECKLY_PROBE_CHANNEL"] ?? "Message to #uptime";
276
+ //#endregion
277
+ //#region src/probes/find-channel.ts
278
+ /** The Discord webhook alert channel the probes work with, or an error that says how to name another. */
279
+ async function findChannel(client, deps) {
280
+ const name = channelName(deps);
281
+ const channel = (await client.alertChannels.list()).find((c) => c.type === "WEBHOOK" && c.config.name === name);
282
+ if (!channel) throw new Error(`no alert channel named "${name}" (run \`holocron notifications setup\`, or set HOLOCRON_CHECKLY_PROBE_CHANNEL)`);
283
+ return channel;
284
+ }
285
+ //#endregion
286
+ //#region src/probes/channel.ts
287
+ const PAGE = 100;
288
+ async function allCheckIds(client) {
289
+ const ids = [];
290
+ for (let page = 1;; page++) {
291
+ const batch = await client.checks.list({
292
+ limit: PAGE,
293
+ page
294
+ });
295
+ ids.push(...batch.map((c) => c.id));
296
+ if (batch.length < PAGE) return ids;
297
+ }
298
+ }
299
+ function channelProbe(deps) {
300
+ return {
301
+ summary: "Show the Discord alert channel: where it posts, whether its template is the shipped one, how many checks use it.",
302
+ writes: false,
303
+ async run(probe) {
304
+ const client = deps.client();
305
+ const channel = await findChannel(client, deps);
306
+ probe.secret(channel.config.url);
307
+ let host = "an unreadable URL";
308
+ try {
309
+ host = new URL(channel.config.url).host;
310
+ } catch {}
311
+ probe.say({
312
+ status: "ok",
313
+ label: `${channel.config.name} (${channel.id})`,
314
+ detail: [
315
+ `posts to ${host}`,
316
+ `format: ${channel.config.webhookType ?? "unset"}`,
317
+ `sends: ${[
318
+ channel.sendFailure && "failure",
319
+ channel.sendRecovery && "recovery",
320
+ channel.sendDegraded && "degraded"
321
+ ].filter(Boolean).join(", ") || "nothing"}`
322
+ ].join(" | ")
323
+ });
324
+ probe.say(sameTemplate(channel.config.template, DISCORD_TEMPLATE) ? {
325
+ status: "ok",
326
+ label: "template is the shipped one"
327
+ } : {
328
+ status: "fail",
329
+ label: "template differs from the shipped one",
330
+ detail: "run `holocron notifications setup` to put it back"
331
+ });
332
+ const [ids] = await Promise.all([allCheckIds(client)]);
333
+ const subscribed = new Set(channel.subscriptions.filter((s) => s.checkId && s.activated !== false).map((s) => s.checkId));
334
+ const missing = ids.filter((id) => !subscribed.has(id)).length;
335
+ probe.say(missing === 0 ? {
336
+ status: "ok",
337
+ label: `all ${ids.length} checks use it`
338
+ } : {
339
+ status: "fail",
340
+ label: `${ids.length - missing} of ${ids.length} checks use it`,
341
+ detail: "run `holocron notifications setup` to subscribe the rest"
342
+ });
343
+ }
344
+ };
345
+ }
346
+ //#endregion
347
+ //#region src/probes/deliver.ts
348
+ const CHECK_NAME = "holocron-delivery-proof (delete me)";
349
+ const TAG = "delivery-proof";
350
+ /** An API check on a URL that always answers 200: asserting 418 makes it fail, asserting 200 makes it pass. */
351
+ const checkInput = (status) => ({
352
+ name: CHECK_NAME,
353
+ frequency: 5,
354
+ locations: ["us-east-1"],
355
+ activated: true,
356
+ tags: [TAG],
357
+ request: {
358
+ url: "https://example.com",
359
+ method: "GET",
360
+ assertions: [{
361
+ source: "STATUS_CODE",
362
+ comparison: "EQUALS",
363
+ target: String(status)
364
+ }]
365
+ }
366
+ });
367
+ const isNotFound = (err) => err?.status === 404;
368
+ async function statusOf(client, id) {
369
+ try {
370
+ return await client.checkStatuses.get(id);
371
+ } catch (err) {
372
+ if (isNotFound(err)) return void 0;
373
+ throw err;
374
+ }
375
+ }
376
+ /** Reads the check's status until `done` accepts it, or the time is up. */
377
+ async function waitFor(deps, client, id, done) {
378
+ const sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
379
+ const pollMs = deps.pollMs ?? 15e3;
380
+ const timeoutMs = deps.timeoutMs ?? 72e4;
381
+ for (let waited = 0; waited <= timeoutMs; waited += pollMs) {
382
+ const status = await statusOf(client, id);
383
+ if (status && done(status)) return status;
384
+ await sleep(pollMs);
385
+ }
386
+ }
387
+ /** Take away a check of this probe's own that an earlier run left behind (it carries the probe's tag). */
388
+ async function removeLeftover(client, probe) {
389
+ const left = (await client.checks.list({ search: CHECK_NAME })).filter((c) => c.name === CHECK_NAME);
390
+ for (const check of left) {
391
+ if (!check.tags.includes(TAG)) throw new Error(`a check named "${CHECK_NAME}" exists but is not a probe's (no \`${TAG}\` tag); rename or delete it`);
392
+ await probe.write("remove a check an earlier run left behind", () => client.checks.delete(check.id));
393
+ }
394
+ }
395
+ function deliverProbe(deps) {
396
+ return {
397
+ summary: "Make a check that must fail, then pass, and follow both alerts to Discord (about 10 to 20 minutes). The check is always removed.",
398
+ writes: true,
399
+ async run(probe) {
400
+ const client = deps.client();
401
+ const channel = await findChannel(client, deps);
402
+ if (probe.dryRun) {
403
+ for (const step of [
404
+ `create the throwaway check "${CHECK_NAME}" (asserting 418, every 5 minutes)`,
405
+ `subscribe it to "${channelName(deps)}"`,
406
+ "wait for Checkly to see it fail",
407
+ "make it assert 200 and wait for Checkly to see it pass",
408
+ "delete the check"
409
+ ]) await probe.write(step, async () => {});
410
+ return;
411
+ }
412
+ await removeLeftover(client, probe);
413
+ const check = await probe.write("create the throwaway check", () => client.checks.create(checkInput(418)));
414
+ probe.cleanup("the throwaway check", () => client.checks.delete(check.id));
415
+ await probe.write(`subscribe it to "${channel.config.name}"`, () => client.alertChannels.subscribe(channel.id, {
416
+ checkId: check.id,
417
+ activated: true
418
+ }));
419
+ probe.say({
420
+ status: "info",
421
+ label: "created and subscribed",
422
+ detail: "Checkly runs it every 5 minutes"
423
+ });
424
+ const failing = await waitFor(deps, client, check.id, (s) => Boolean(s.lastCheckRunId) && s.hasFailures);
425
+ if (!failing) {
426
+ probe.say({
427
+ status: "fail",
428
+ label: "Checkly did not report the check failing in time"
429
+ });
430
+ return;
431
+ }
432
+ probe.say({
433
+ status: "ok",
434
+ label: "Checkly sees the check failing",
435
+ detail: `look in #uptime for a red "${CHECK_NAME} has failed" with Status code 200`
436
+ });
437
+ await probe.write("make it pass", () => client.checks.update(check.id, checkInput(200)));
438
+ if (!await waitFor(deps, client, check.id, (s) => Boolean(s.lastCheckRunId) && s.lastCheckRunId !== failing.lastCheckRunId && !s.hasFailures)) {
439
+ probe.say({
440
+ status: "fail",
441
+ label: "Checkly did not report the check passing in time"
442
+ });
443
+ return;
444
+ }
445
+ probe.say({
446
+ status: "ok",
447
+ label: "Checkly sees the check passing",
448
+ detail: `look in #uptime for a green "${CHECK_NAME} has recovered"`
449
+ });
450
+ }
451
+ };
452
+ }
453
+ //#endregion
454
+ //#region src/probes/index.ts
455
+ function checklyProbes(deps) {
456
+ return {
457
+ channel: channelProbe(deps),
458
+ deliver: deliverProbe(deps)
459
+ };
460
+ }
273
461
  //#endregion
274
462
  //#region src/verify-token.ts
275
463
  async function verifyToken(token, opts = {}) {
@@ -316,6 +504,7 @@ function createPlugin(options) {
316
504
  const ctx = createContext(options);
317
505
  return {
318
506
  name: "@theholocron/holocron-plugin-checkly",
507
+ probes: checklyProbes({ client: ctx.client }),
319
508
  capabilities: { monitoring: () => monitoring(ctx) }
320
509
  };
321
510
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-checkly",
3
- "version": "5.0.0-alpha.229",
3
+ "version": "5.0.0-alpha.230",
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",
@@ -30,7 +30,7 @@
30
30
  "dist"
31
31
  ],
32
32
  "devDependencies": {
33
- "@theholocron/checkly-client": "^1.54.1",
33
+ "@theholocron/checkly-client": "^1.55.0",
34
34
  "@theholocron/http-client": "^1.54.2",
35
35
  "@theholocron/misc-utils": "^1.16.0",
36
36
  "@theholocron/tsconfig": "^8.8.2",
@@ -42,12 +42,12 @@
42
42
  "tsx": "4.23.15",
43
43
  "typescript": "^5.9.3",
44
44
  "vitest": "^4.1.11",
45
- "@theholocron/cli": "5.0.0-alpha.229"
45
+ "@theholocron/cli": "5.0.0-alpha.230"
46
46
  },
47
47
  "peerDependencies": {
48
- "@theholocron/checkly-client": "^1.54.1",
48
+ "@theholocron/checkly-client": "^1.55.0",
49
49
  "@theholocron/misc-utils": "^1.16.0",
50
- "@theholocron/cli": "5.0.0-alpha.229"
50
+ "@theholocron/cli": "5.0.0-alpha.230"
51
51
  },
52
52
  "engines": {
53
53
  "node": ">=22"