@theholocron/holocron-plugin-checkly 5.0.0-alpha.216 → 5.0.0-alpha.218

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
@@ -11,6 +11,10 @@ declare class ChecklyMonitoring implements Monitoring {
11
11
  private readonly client;
12
12
  readonly key: "monitoring";
13
13
  readonly providerName = "checkly";
14
+ readonly icon: {
15
+ readonly url: "https://s3.eu-central-1.amazonaws.com/cdn.checklyhq.com/slack/checkly-slack-icon.png";
16
+ readonly 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/IgknZqRVpmvvVombcWPFtCiuY0Y0VzCYzwJbeKL1M2CijGnP55plCr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cCioOsX/5zF1on/gCqJzk9+d3af/H1ZEGUQPC/XwOrH55TysIz8M9D+TEnr1rxM+H8/yeBB3UlW85vVmMHcbAfUwdRcppu1gqeBtl6nq7kR2FCWi9aSKfTaZrOF4WSGP84Xd3MFTxN1PrXgHNPYdlEiju48b6A5faQ+kVUBsfA8hdvMt958iBLc83CHLaSizvyj9N0s8zg6MjutCnTh5N1ZlfmSiyXU631HaO22RgzCcEV6Lzmx6cKP2mDMNbwCXUCskHhxgUNHDUwaLgWdmTTKHEzXDN4SMMcuUTe8OpwS+SNsTlgaIxtAEFjLF9Cg4E5t+3d12lQM/1oSIP7BnN5k0HDTpY3KynldLVpbDU0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ8LX4GOldjeT7Ifd8AAAAASUVORK5CYII=";
17
+ };
14
18
  readonly checks: readonly MonitoringCheckInput[];
15
19
  constructor(client: () => ChecklyClient, opts?: ChecklyMonitoringOptions);
16
20
  whoami(): Promise<{
@@ -25,8 +29,25 @@ declare class ChecklyMonitoring implements Monitoring {
25
29
  * kept up to date, not duplicated. Every check on the account is subscribed, since a check made through the API is
26
30
  * never subscribed on its own; subscriptions already there (including ones to checks outside Holocron) are kept.
27
31
  * An existing channel keeps its own message template and send settings.
32
+ *
33
+ * Subscriptions go through Checkly's subscriptions call and are then read back: its create and update accept a
34
+ * `subscriptions` list but were seen not to apply it, so the count returned is what Checkly holds, and a check that
35
+ * could not be subscribed is an error and not a number.
28
36
  */
29
37
  ensureAlertChannel(input: MonitoringAlertChannelInput): Promise<MonitoringAlertChannelResult>;
38
+ /**
39
+ * After an update replaced the channel: read it back and put back any subscription it had that did not survive, of
40
+ * every kind (a group, a check outside this account) and in the state it had (a deactivated one stays deactivated).
41
+ */
42
+ private restoreSubscriptions;
43
+ /** One subscribe call; Checkly's 409 means the subscription is already there, which is what was wanted. */
44
+ private subscribeTolerating;
45
+ /**
46
+ * Subscribe the checks a channel lacks, then read it back. A subscription someone switched off is a choice: it is left
47
+ * off, not added a second time, and not counted. A call that fails does not stop the others: the channel is read back
48
+ * and the shortfall reported, with the first failure's reason. Returns how many were added and how many checks now alert.
49
+ */
50
+ private subscribeMissing;
30
51
  /** The id of every check on the account, read a page at a time. */
31
52
  private allCheckIds;
32
53
  /** Checkly's `search` param is a case-insensitive partial match — narrow to the exact name ourselves. */
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { AuthError, createResolveToken, createRestClient } from "@theholocron/cli";
1
+ import { AuthError, ProviderApiError, createResolveToken, createRestClient } from "@theholocron/cli";
2
2
  import { DISCORD_TEMPLATE, createChecklyClient } from "@theholocron/checkly-client";
3
3
  import { errorMessage } from "@theholocron/misc-utils";
4
4
  //#region src/auth.ts
@@ -9,7 +9,29 @@ const resolveToken = createResolveToken({
9
9
  errorMessage: "no Checkly token found. Pass --token <TOKEN>, set HOLOCRON_CHECKLY_TOKEN / CHECKLY_API_KEY, or run: holocron auth set checkly <TOKEN>"
10
10
  });
11
11
  //#endregion
12
+ //#region src/icon.ts
13
+ /**
14
+ * Checkly's own icon, the one its Slack and Discord alerts carry. The Monitoring capability offers it so the webhook
15
+ * Checkly posts through can wear it without the config naming a picture. The URL is tried first; the image is embedded
16
+ * (a 304x304 PNG, about 3 KB) so setup still works when Checkly's CDN cannot be reached.
17
+ */
18
+ const CHECKLY_ICON = {
19
+ url: "https://s3.eu-central-1.amazonaws.com/cdn.checklyhq.com/slack/checkly-slack-icon.png",
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/k6lw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CwpHw9f4z8mg0/7QQlnf5LYvd4v/HZS17W/Mo442DYs5TRYcqAWOV6DDTUr+NyFc5XE4JB8ce0plwIB6ttHm0LKUtd8zDw4JN1+x22CMiXRhVdm6Ce/lnZ/kMfc0pgUCNDfprnBK7tyS2AvAMoy9jyBO7ID9Yw6xjUTzFR1hE/4BMZYDwovvXIFSFZ77Dxo4X2RGPvuLvG/xvsiNsYdZlkDoKFrGlX+1foFLfvqIR6JTmL2WYTYBzKG9kElNoVtoAgqL5TEejF9PaETMKuxNbK14MEP71f2DvLHAZDihTZjE4FhBMXIUCEmbb6YD+QEzGxsTB9g6BDLNV/U4aUxZCZjF/gMRh9iyuQr8qAkvK3KWsicr6AwY1zW/xojzpSV2DDbfxMIxlCcNSrrP9t2piyBsvFDzdnfkS2ynDb5D/yZsrKc/bOkFoksXv/1ILYIbGFIzu+dcvq3cOcCioOsX/5zF1on/gCqJzk9+d3af/H1ZEGUQPC/XwOrH55TysIz8M9D+TEnr1rxM+H8/yeBB3UlW85vVmMHcbAfUwdRcppu1gqeBtl6nq7kR2FCWi9aSKfTaZrOF4WSGP84Xd3MFTxN1PrXgHNPYdlEiju48b6A5faQ+kVUBsfA8hdvMt958iBLc83CHLaSizvyj9N0s8zg6MjutCnTh5N1ZlfmSiyXU631HaO22RgzCcEV6Lzmx6cKP2mDMNbwCXUCskHhxgUNHDUwaLgWdmTTKHEzXDN4SMMcuUTe8OpwS+SNsTlgaIxtAEFjLF9Cg4E5t+3d12lQM/1oSIP7BnN5k0HDTpY3KynldLVpbDU0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ8LX4GOldjeT7Ifd8AAAAASUVORK5CYII="
21
+ };
22
+ //#endregion
12
23
  //#region src/capabilities/monitoring.ts
24
+ /**
25
+ * `monitoring` capability for Checkly.
26
+ *
27
+ * `ensureCheck` is a find-or-create-or-update by name: Checkly's API has
28
+ * no separate idempotency key, so a `search` list call (case-insensitive
29
+ * partial match) narrows to candidates, then an exact-name match picks
30
+ * the one to update. `checks` carries whatever this provider was
31
+ * constructed with (from the provider config tuple's second argument —
32
+ * same place `Deployment.domain` comes from) for `holocron repo setup`
33
+ * to loop over generically.
34
+ */
13
35
  const SOURCE_MAP = {
14
36
  status_code: "STATUS_CODE",
15
37
  response_time: "RESPONSE_TIME",
@@ -48,6 +70,7 @@ var ChecklyMonitoring = class {
48
70
  client;
49
71
  key = "monitoring";
50
72
  providerName = "checkly";
73
+ icon = CHECKLY_ICON;
51
74
  checks;
52
75
  constructor(client, opts = {}) {
53
76
  this.client = client;
@@ -88,6 +111,10 @@ var ChecklyMonitoring = class {
88
111
  * kept up to date, not duplicated. Every check on the account is subscribed, since a check made through the API is
89
112
  * never subscribed on its own; subscriptions already there (including ones to checks outside Holocron) are kept.
90
113
  * An existing channel keeps its own message template and send settings.
114
+ *
115
+ * Subscriptions go through Checkly's subscriptions call and are then read back: its create and update accept a
116
+ * `subscriptions` list but were seen not to apply it, so the count returned is what Checkly holds, and a check that
117
+ * could not be subscribed is an error and not a number.
91
118
  */
92
119
  async ensureAlertChannel(input) {
93
120
  const client = this.client();
@@ -95,7 +122,7 @@ var ChecklyMonitoring = class {
95
122
  const existing = channels.find((c) => c.type === "WEBHOOK" && c.config.name === input.name);
96
123
  if (!existing) {
97
124
  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`);
98
- await client.alertChannels.create({
125
+ const created = await client.alertChannels.create({
99
126
  type: "WEBHOOK",
100
127
  config: {
101
128
  name: input.name,
@@ -109,66 +136,116 @@ var ChecklyMonitoring = class {
109
136
  sendFailure: true,
110
137
  sendRecovery: true,
111
138
  sendDegraded: true,
112
- autoSubscribe: false,
113
- subscriptions: checkIds.map((checkId) => ({
114
- checkId,
115
- activated: true
116
- }))
139
+ autoSubscribe: false
117
140
  });
141
+ const { active } = await this.subscribeMissing(created.id, input.name, checkIds);
118
142
  return {
119
143
  created: true,
120
144
  updated: [],
121
- subscribed: checkIds.length
145
+ subscribed: active
122
146
  };
123
147
  }
124
- const known = new Set(existing.subscriptions.flatMap((s) => s.checkId ? [s.checkId] : []));
125
- const active = new Set(existing.subscriptions.flatMap((s) => s.checkId && s.activated ? [s.checkId] : []));
126
- const missing = checkIds.filter((id) => !known.has(id));
127
148
  const urlChanged = input.url !== void 0 && existing.config.url !== input.url;
128
149
  const formatChanged = existing.config.webhookType !== "WEBHOOK_DISCORD";
129
- const updated = [
130
- ...urlChanged ? ["url"] : [],
131
- ...formatChanged ? ["format"] : [],
132
- ...missing.length > 0 ? ["subscriptions"] : []
133
- ];
134
- const total = active.size + missing.length;
135
- if (updated.length === 0) return {
150
+ let current;
151
+ if (urlChanged || formatChanged) {
152
+ const fresh = await client.alertChannels.get(existing.id);
153
+ const replacement = {
154
+ type: "WEBHOOK",
155
+ config: {
156
+ ...existing.config,
157
+ ...urlChanged ? { url: input.url } : {},
158
+ ...formatChanged ? {
159
+ webhookType: "WEBHOOK_DISCORD",
160
+ template: DISCORD_TEMPLATE
161
+ } : {}
162
+ },
163
+ sendRecovery: existing.sendRecovery,
164
+ sendFailure: existing.sendFailure,
165
+ sendDegraded: existing.sendDegraded,
166
+ sslExpiry: existing.sslExpiry,
167
+ sslExpiryThreshold: existing.sslExpiryThreshold,
168
+ autoSubscribe: existing.autoSubscribe,
169
+ subscriptions: fresh.subscriptions.map((s) => s.checkId ? {
170
+ checkId: s.checkId,
171
+ activated: s.activated
172
+ } : {
173
+ groupId: s.groupId,
174
+ activated: s.activated
175
+ })
176
+ };
177
+ await client.alertChannels.update(existing.id, replacement);
178
+ current = await this.restoreSubscriptions(existing.id, fresh.subscriptions);
179
+ }
180
+ const { added, active } = await this.subscribeMissing(existing.id, input.name, checkIds, current);
181
+ return {
136
182
  created: false,
137
- updated,
138
- subscribed: total
183
+ updated: [
184
+ ...urlChanged ? ["url"] : [],
185
+ ...formatChanged ? ["format"] : [],
186
+ ...added > 0 ? ["subscriptions"] : []
187
+ ],
188
+ subscribed: active
139
189
  };
140
- const replacement = {
141
- type: "WEBHOOK",
142
- config: {
143
- ...existing.config,
144
- ...urlChanged ? { url: input.url } : {},
145
- ...formatChanged ? {
146
- webhookType: "WEBHOOK_DISCORD",
147
- template: DISCORD_TEMPLATE
148
- } : {}
149
- },
150
- sendRecovery: existing.sendRecovery,
151
- sendFailure: existing.sendFailure,
152
- sendDegraded: existing.sendDegraded,
153
- sslExpiry: existing.sslExpiry,
154
- sslExpiryThreshold: existing.sslExpiryThreshold,
155
- autoSubscribe: existing.autoSubscribe,
156
- subscriptions: [...existing.subscriptions.map((s) => s.checkId ? {
157
- checkId: s.checkId,
158
- activated: s.activated
190
+ }
191
+ /**
192
+ * After an update replaced the channel: read it back and put back any subscription it had that did not survive, of
193
+ * every kind (a group, a check outside this account) and in the state it had (a deactivated one stays deactivated).
194
+ */
195
+ async restoreSubscriptions(channelId, had) {
196
+ const client = this.client();
197
+ const after = await client.alertChannels.get(channelId);
198
+ const held = (s) => after.subscriptions.some((a) => s.checkId ? a.checkId === s.checkId : a.groupId === s.groupId);
199
+ const lost = had.filter((s) => !held(s));
200
+ for (const s of lost) await this.subscribeTolerating(channelId, s);
201
+ return lost.length > 0 ? await client.alertChannels.get(channelId) : after;
202
+ }
203
+ /** One subscribe call; Checkly's 409 means the subscription is already there, which is what was wanted. */
204
+ async subscribeTolerating(channelId, subscription) {
205
+ try {
206
+ await this.client().alertChannels.subscribe(channelId, subscription.checkId ? {
207
+ checkId: subscription.checkId,
208
+ activated: subscription.activated
159
209
  } : {
160
- groupId: s.groupId,
161
- activated: s.activated
162
- }), ...missing.map((checkId) => ({
210
+ groupId: subscription.groupId,
211
+ activated: subscription.activated
212
+ });
213
+ return;
214
+ } catch (err) {
215
+ if (err instanceof ProviderApiError && err.status === 409) return void 0;
216
+ return err;
217
+ }
218
+ }
219
+ /**
220
+ * Subscribe the checks a channel lacks, then read it back. A subscription someone switched off is a choice: it is left
221
+ * off, not added a second time, and not counted. A call that fails does not stop the others: the channel is read back
222
+ * and the shortfall reported, with the first failure's reason. Returns how many were added and how many checks now alert.
223
+ */
224
+ async subscribeMissing(channelId, name, checkIds, current) {
225
+ const client = this.client();
226
+ const checkIdsOf = (channel, onlyActive) => new Set(channel.subscriptions.flatMap((s) => s.checkId && (!onlyActive || s.activated) ? [s.checkId] : []));
227
+ const before = current ?? await client.alertChannels.get(channelId);
228
+ const known = checkIdsOf(before, false);
229
+ const missing = checkIds.filter((id) => !known.has(id));
230
+ const failures = [];
231
+ for (const checkId of missing) {
232
+ const failure = await this.subscribeTolerating(channelId, {
163
233
  checkId,
164
234
  activated: true
165
- }))]
166
- };
167
- await client.alertChannels.update(existing.id, replacement);
235
+ });
236
+ if (failure) failures.push(failure);
237
+ }
238
+ const after = missing.length > 0 ? await client.alertChannels.get(channelId) : before;
239
+ const present = checkIdsOf(after, false);
240
+ const active = checkIdsOf(after, true);
241
+ const lacking = checkIds.filter((id) => !present.has(id) || missing.includes(id) && !active.has(id));
242
+ if (lacking.length > 0) {
243
+ const cause = failures[0] instanceof Error ? `: ${failures[0].message}` : "";
244
+ throw new Error(`Checkly did not subscribe ${lacking.length} of ${checkIds.length} checks to alert channel "${name}" (it holds ${active.size})${cause}; subscribe them in Checkly's alert settings and run setup again`);
245
+ }
168
246
  return {
169
- created: false,
170
- updated,
171
- subscribed: total
247
+ added: missing.length,
248
+ active: active.size
172
249
  };
173
250
  }
174
251
  /** The id of every check on the account, read a page at a time. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-checkly",
3
- "version": "5.0.0-alpha.216",
3
+ "version": "5.0.0-alpha.218",
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.52.0",
33
+ "@theholocron/checkly-client": "^1.53.0",
34
34
  "@theholocron/http-client": "^1.43.1",
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.216"
45
+ "@theholocron/cli": "5.0.0-alpha.218"
46
46
  },
47
47
  "peerDependencies": {
48
- "@theholocron/checkly-client": "^1.52.0",
48
+ "@theholocron/checkly-client": "^1.53.0",
49
49
  "@theholocron/misc-utils": "^1.16.0",
50
- "@theholocron/cli": "5.0.0-alpha.216"
50
+ "@theholocron/cli": "5.0.0-alpha.218"
51
51
  },
52
52
  "engines": {
53
53
  "node": ">=22"