@theholocron/holocron-plugin-checkly 5.0.0-alpha.535 → 5.0.0-alpha.537
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 +8 -1
- package/dist/index.mjs +197 -3
- package/package.json +5 -5
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, MonitoringIncident, MonitoringIncidentQuery, 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, MonitoringIncidentInput, MonitoringIncidentQuery, MonitoringIncidentResolveInput, MonitoringIncidentUpdateInput, MonitoringIncidentWrite, 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;
|
|
@@ -99,6 +99,12 @@ export declare class ChecklyMonitoring implements Monitoring {
|
|
|
99
99
|
inspectStatusPage(input: MonitoringStatusPageInput): Promise<MonitoringStatusPageState>;
|
|
100
100
|
/** The incidents of a status page, with their updates; see `capabilities/incidents.ts`. */
|
|
101
101
|
listIncidents(query: MonitoringIncidentQuery): Promise<MonitoringIncident[]>;
|
|
102
|
+
/** Opens an incident with its first update; see `capabilities/incident-writes.ts`. */
|
|
103
|
+
openIncident(input: MonitoringIncidentInput): Promise<MonitoringIncidentWrite>;
|
|
104
|
+
/** Appends an update to an incident. */
|
|
105
|
+
updateIncident(input: MonitoringIncidentUpdateInput): Promise<MonitoringIncidentWrite>;
|
|
106
|
+
/** Appends a `resolved` update, which closes the incident. */
|
|
107
|
+
resolveIncident(input: MonitoringIncidentResolveInput): Promise<MonitoringIncidentWrite>;
|
|
102
108
|
/** Checkly's `search` param is a case-insensitive partial match — narrow to the exact name ourselves. */
|
|
103
109
|
private findByExactName;
|
|
104
110
|
/** Find-or-create-or-update a dashboard by its header; see `./dashboards.ts`. */
|
|
@@ -146,6 +152,7 @@ export declare function monitoring(ctx: PluginContext): Monitoring;
|
|
|
146
152
|
export declare function createPlugin(options: ChecklyPluginOptions): {
|
|
147
153
|
name: string;
|
|
148
154
|
probes: {
|
|
155
|
+
token: import("@theholocron/cli").Probe;
|
|
149
156
|
connection: import("@theholocron/cli").Probe;
|
|
150
157
|
};
|
|
151
158
|
capabilities: {
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import { AuthError, ProviderApiError, connectionProbe, createResolveToken, createRestClient } from "@theholocron/cli";
|
|
1
|
+
import { AuthError, ProviderApiError, connectionProbe, createResolveToken, createRestClient, tokenExpectations } from "@theholocron/cli";
|
|
2
2
|
import { DISCORD_TEMPLATE, createChecklyClient } from "@theholocron/checkly-client";
|
|
3
3
|
import { createEnvLookup } from "@theholocron/env-utils/lookup";
|
|
4
4
|
import { errorMessage } from "@theholocron/misc-utils";
|
|
5
|
+
// src/probes/token/expectations.ts
|
|
6
|
+
/**
|
|
7
|
+
* Where the Checkly API key (`HOLOCRON_CHECKLY_TOKEN`) is held and checked: `ci`, where the `sync-incidents` task
|
|
8
|
+
* reads the status pages' incidents with it. Checkly reports neither a key's role nor its scope (a user key inherits
|
|
9
|
+
* its user's role, a service key has one chosen at creation: Read Only, Read & Write or Admin), so no permissions are
|
|
10
|
+
* declared and the probe says so instead of guessing. This is the plugin's `tokens` declaration, read through
|
|
11
|
+
* `tokenExpectations()`; change it and the Checkly row in `docs/src/content/docs/tokens.mdx` together.
|
|
12
|
+
*/
|
|
13
|
+
const EXPECTED = { layers: ["ci"] };
|
|
5
14
|
// src/auth.ts
|
|
6
15
|
/** Resolves the Checkly API key from `--token`, `HOLOCRON_CHECKLY_TOKEN`, `CHECKLY_API_KEY` or the keyring, and throws an `AuthError` when none is set. */
|
|
7
16
|
const resolveToken = createResolveToken({
|
|
@@ -11,7 +20,10 @@ const resolveToken = createResolveToken({
|
|
|
11
20
|
errorMessage: "no Checkly token found. Pass --token <TOKEN>, set HOLOCRON_CHECKLY_TOKEN / CHECKLY_API_KEY, or run: holocron new token checkly <TOKEN>"
|
|
12
21
|
});
|
|
13
22
|
/** Every token this plugin takes, for `holocron doctor secrets --verify`. */
|
|
14
|
-
const tokens = [
|
|
23
|
+
const tokens = [{
|
|
24
|
+
...resolveToken.token,
|
|
25
|
+
expect: EXPECTED
|
|
26
|
+
}];
|
|
15
27
|
// src/icon.ts
|
|
16
28
|
/**
|
|
17
29
|
* Checkly's own icon, the one its Slack and Discord alerts carry. The Monitoring capability offers it so the webhook
|
|
@@ -245,6 +257,72 @@ async function listChecklyIncidents(client, query) {
|
|
|
245
257
|
if (needNames) for (const c of await client.statusPages.components.list(page.id)) names.set(c.id, c.name);
|
|
246
258
|
return incidents.map((i) => fromChecklyIncident(i, names));
|
|
247
259
|
}
|
|
260
|
+
// src/capabilities/incident-writes.ts
|
|
261
|
+
const STATUSES = {
|
|
262
|
+
investigating: "INVESTIGATING",
|
|
263
|
+
identified: "IDENTIFIED",
|
|
264
|
+
monitoring: "MONITORING",
|
|
265
|
+
resolved: "RESOLVED"
|
|
266
|
+
};
|
|
267
|
+
/** The neutral impact word for each Checkly impact, turned around. */
|
|
268
|
+
const CHECKLY_IMPACTS = Object.fromEntries(Object.entries(IMPACTS).map(([checkly, neutral]) => [neutral, checkly]));
|
|
269
|
+
/** The longest incident name Checkly accepts. */
|
|
270
|
+
const MAX_NAME = 255;
|
|
271
|
+
async function pageId(client, name) {
|
|
272
|
+
const page = (await client.statusPages.list()).find((p) => p.name === name);
|
|
273
|
+
if (!page) throw new Error(`status page "${name}" not found`);
|
|
274
|
+
return page.id;
|
|
275
|
+
}
|
|
276
|
+
async function impactsOf(client, id, impacts) {
|
|
277
|
+
if (impacts.length === 0) return [];
|
|
278
|
+
const components = await client.statusPages.components.list(id);
|
|
279
|
+
const ids = new Map(components.map((c) => [c.name, c.id]));
|
|
280
|
+
const unknown = impacts.filter((i) => !ids.has(i.component)).map((i) => i.component);
|
|
281
|
+
if (unknown.length > 0) throw new Error(`status page has no component named ${unknown.map((n) => `"${n}"`).join(", ")} (it has ${[...ids.keys()].join(", ") || "none"})`);
|
|
282
|
+
return impacts.map((i) => ({
|
|
283
|
+
componentId: ids.get(i.component),
|
|
284
|
+
status: CHECKLY_IMPACTS[i.impact]
|
|
285
|
+
}));
|
|
286
|
+
}
|
|
287
|
+
/** Opens an incident with its one opening update; the components it marks are looked up by name. */
|
|
288
|
+
async function openChecklyIncident(client, input) {
|
|
289
|
+
if (input.title.length > MAX_NAME) throw new Error(`an incident title is at most ${MAX_NAME} characters (this one is ${input.title.length})`);
|
|
290
|
+
const id = await pageId(client, input.statusPage);
|
|
291
|
+
const componentImpacts = await impactsOf(client, id, input.impacts);
|
|
292
|
+
const incident = await client.statusPages.incidents.create(id, {
|
|
293
|
+
name: input.title,
|
|
294
|
+
incidentUpdates: [{
|
|
295
|
+
description: input.message,
|
|
296
|
+
status: STATUSES[input.status],
|
|
297
|
+
notifySubscribers: input.notify
|
|
298
|
+
}],
|
|
299
|
+
...componentImpacts.length > 0 ? { componentImpacts } : {}
|
|
300
|
+
});
|
|
301
|
+
return {
|
|
302
|
+
id: incident.id,
|
|
303
|
+
status: statusOf$1(incident.lastUpdateStatus ?? STATUSES[input.status])
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
/** Appends an update with the status `input.status`. */
|
|
307
|
+
async function updateChecklyIncident(client, input) {
|
|
308
|
+
const id = await pageId(client, input.statusPage);
|
|
309
|
+
const incident = await client.statusPages.incidents.addUpdate(id, input.id, {
|
|
310
|
+
description: input.message,
|
|
311
|
+
status: STATUSES[input.status],
|
|
312
|
+
notifySubscribers: input.notify
|
|
313
|
+
});
|
|
314
|
+
return {
|
|
315
|
+
id: incident.id,
|
|
316
|
+
status: statusOf$1(incident.lastUpdateStatus ?? STATUSES[input.status])
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
/** Appends a `RESOLVED` update, which is how Checkly closes an incident. */
|
|
320
|
+
function resolveChecklyIncident(client, input) {
|
|
321
|
+
return updateChecklyIncident(client, {
|
|
322
|
+
...input,
|
|
323
|
+
status: "resolved"
|
|
324
|
+
});
|
|
325
|
+
}
|
|
248
326
|
// src/capabilities/status-pages.ts
|
|
249
327
|
/**
|
|
250
328
|
* Status pages for the Checkly `monitoring` capability (spec `tech-monitoring-dashboards-status-pages`, #2302).
|
|
@@ -1013,6 +1091,18 @@ var ChecklyMonitoring = class {
|
|
|
1013
1091
|
listIncidents(query) {
|
|
1014
1092
|
return listChecklyIncidents(this.client(), query);
|
|
1015
1093
|
}
|
|
1094
|
+
/** Opens an incident with its first update; see `capabilities/incident-writes.ts`. */
|
|
1095
|
+
openIncident(input) {
|
|
1096
|
+
return openChecklyIncident(this.client(), input);
|
|
1097
|
+
}
|
|
1098
|
+
/** Appends an update to an incident. */
|
|
1099
|
+
updateIncident(input) {
|
|
1100
|
+
return updateChecklyIncident(this.client(), input);
|
|
1101
|
+
}
|
|
1102
|
+
/** Appends a `resolved` update, which closes the incident. */
|
|
1103
|
+
resolveIncident(input) {
|
|
1104
|
+
return resolveChecklyIncident(this.client(), input);
|
|
1105
|
+
}
|
|
1016
1106
|
/** Checkly's `search` param is a case-insensitive partial match — narrow to the exact name ourselves. */
|
|
1017
1107
|
async findByExactName(name) {
|
|
1018
1108
|
return (await this.client().checks.list({ search: name })).find((c) => c.name === name);
|
|
@@ -1211,6 +1301,103 @@ function checklyProbes(deps) {
|
|
|
1211
1301
|
deliver: deliverProbe(deps)
|
|
1212
1302
|
};
|
|
1213
1303
|
}
|
|
1304
|
+
// src/probes/token/parse-token-args.ts
|
|
1305
|
+
/** Reads `--layer <word>` and `--token-name <VAR>` (either spelling) from the words after the probe name. */
|
|
1306
|
+
function parseTokenArgs(args) {
|
|
1307
|
+
let layer;
|
|
1308
|
+
let tokenName;
|
|
1309
|
+
for (let i = 0; i < args.length; i++) {
|
|
1310
|
+
const arg = args[i];
|
|
1311
|
+
if (arg === "--layer") layer = args[++i];
|
|
1312
|
+
else if (arg.startsWith("--layer=")) layer = arg.slice(8);
|
|
1313
|
+
else if (arg === "--token-name") tokenName = args[++i];
|
|
1314
|
+
else if (arg.startsWith("--token-name=")) tokenName = arg.slice(13);
|
|
1315
|
+
}
|
|
1316
|
+
return {
|
|
1317
|
+
...layer ? { layer } : {},
|
|
1318
|
+
...tokenName ? { tokenName } : {}
|
|
1319
|
+
};
|
|
1320
|
+
}
|
|
1321
|
+
// src/probes/token/token.ts
|
|
1322
|
+
/** What a failed read says: a key the API refuses (401, 403) is named, anything else is the error's own message. */
|
|
1323
|
+
function failure(err) {
|
|
1324
|
+
if (err instanceof ProviderApiError && (err.status === 401 || err.status === 403)) return `refused (${err.status}): the key cannot read this`;
|
|
1325
|
+
return err instanceof Error ? err.message : String(err);
|
|
1326
|
+
}
|
|
1327
|
+
/**
|
|
1328
|
+
* The `token` probe for Checkly. Checkly reports no role or scope for a key, so the probe proves only what a read
|
|
1329
|
+
* proves: it lists the account's status pages and the incidents of the first one (what `sync-incidents` reads). A
|
|
1330
|
+
* refusal or any error on either is a `fail`, because the `ci` key must read them. It cannot tell a Read Only key from
|
|
1331
|
+
* a Read & Write one without writing, so a row says so. With `--layer` it also says whether that layer is one that
|
|
1332
|
+
* should hold the key. Read-only; never prints the key.
|
|
1333
|
+
*/
|
|
1334
|
+
function tokenProbe(ctx) {
|
|
1335
|
+
return {
|
|
1336
|
+
summary: "List the Checkly account's status pages and the first one's incidents with a key, and for a layer check that it is one that should hold the key. Checkly reports no role, so a read-only key cannot be told from a writing one. Read-only.",
|
|
1337
|
+
writes: false,
|
|
1338
|
+
acceptsToken: true,
|
|
1339
|
+
async run(probe) {
|
|
1340
|
+
probe.secret(ctx.token());
|
|
1341
|
+
probe.say({
|
|
1342
|
+
status: "ok",
|
|
1343
|
+
label: "token",
|
|
1344
|
+
detail: "set"
|
|
1345
|
+
});
|
|
1346
|
+
const { layer, tokenName } = parseTokenArgs(probe.args ?? []);
|
|
1347
|
+
if (layer) {
|
|
1348
|
+
const declared = tokenExpectations(tokens, {
|
|
1349
|
+
layer,
|
|
1350
|
+
...tokenName ? { envName: tokenName } : {}
|
|
1351
|
+
}).length > 0;
|
|
1352
|
+
probe.say(declared ? {
|
|
1353
|
+
status: "ok",
|
|
1354
|
+
label: layer,
|
|
1355
|
+
detail: "a layer that should hold this token"
|
|
1356
|
+
} : {
|
|
1357
|
+
status: "info",
|
|
1358
|
+
label: layer,
|
|
1359
|
+
detail: "not a layer this token is declared for, so it is only described"
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
const client = ctx.client();
|
|
1363
|
+
let pageId;
|
|
1364
|
+
try {
|
|
1365
|
+
const pages = await client.statusPages.list();
|
|
1366
|
+
pageId = pages[0]?.id;
|
|
1367
|
+
probe.say({
|
|
1368
|
+
status: "ok",
|
|
1369
|
+
label: "status pages",
|
|
1370
|
+
detail: `read ${pages.length}`
|
|
1371
|
+
});
|
|
1372
|
+
} catch (err) {
|
|
1373
|
+
probe.say({
|
|
1374
|
+
status: "fail",
|
|
1375
|
+
label: "status pages",
|
|
1376
|
+
detail: failure(err)
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1379
|
+
if (pageId !== void 0) try {
|
|
1380
|
+
const incidents = await client.statusPages.incidents.list(pageId);
|
|
1381
|
+
probe.say({
|
|
1382
|
+
status: "ok",
|
|
1383
|
+
label: "incidents",
|
|
1384
|
+
detail: `read ${incidents.length} on the first status page`
|
|
1385
|
+
});
|
|
1386
|
+
} catch (err) {
|
|
1387
|
+
probe.say({
|
|
1388
|
+
status: "fail",
|
|
1389
|
+
label: "incidents",
|
|
1390
|
+
detail: failure(err)
|
|
1391
|
+
});
|
|
1392
|
+
}
|
|
1393
|
+
probe.say({
|
|
1394
|
+
status: "info",
|
|
1395
|
+
label: "permissions",
|
|
1396
|
+
detail: "Checkly reports no role for a key, so a Read Only key cannot be told from a writing one; sync-incidents only reads, so a Read Only key is enough"
|
|
1397
|
+
});
|
|
1398
|
+
}
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1214
1401
|
// src/verify-token.ts
|
|
1215
1402
|
/** Checks a Checkly API key by listing the accounts it can see; resolves to the account names and ids, or the failure message. */
|
|
1216
1403
|
async function verifyToken(token, opts = {}) {
|
|
@@ -1233,6 +1420,8 @@ async function verifyToken(token, opts = {}) {
|
|
|
1233
1420
|
}
|
|
1234
1421
|
}
|
|
1235
1422
|
// src/index.ts
|
|
1423
|
+
/** A request that has not answered after this long is abandoned, so a stalled API never hangs a command. */
|
|
1424
|
+
const REQUEST_TIMEOUT_MS = 3e4;
|
|
1236
1425
|
/** Builds the plugin context from its options; the API key is resolved lazily on the first client use. */
|
|
1237
1426
|
function createContext(options) {
|
|
1238
1427
|
let client;
|
|
@@ -1242,7 +1431,8 @@ function createContext(options) {
|
|
|
1242
1431
|
if (client) return client;
|
|
1243
1432
|
const clientOpts = {
|
|
1244
1433
|
token: resolveToken(options),
|
|
1245
|
-
accountId: options.accountId
|
|
1434
|
+
accountId: options.accountId,
|
|
1435
|
+
timeoutMs: REQUEST_TIMEOUT_MS
|
|
1246
1436
|
};
|
|
1247
1437
|
if (options.baseUrl !== void 0) clientOpts.baseUrl = options.baseUrl;
|
|
1248
1438
|
if (options.fetch !== void 0) clientOpts.fetch = options.fetch;
|
|
@@ -1269,6 +1459,10 @@ function createPlugin(options) {
|
|
|
1269
1459
|
client: ctx.client,
|
|
1270
1460
|
checks: options.checks
|
|
1271
1461
|
}),
|
|
1462
|
+
token: tokenProbe({
|
|
1463
|
+
token: () => resolveToken(options),
|
|
1464
|
+
client: ctx.client
|
|
1465
|
+
}),
|
|
1272
1466
|
connection: connectionProbe({
|
|
1273
1467
|
provider: "Checkly",
|
|
1274
1468
|
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.
|
|
3
|
+
"version": "5.0.0-alpha.537",
|
|
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",
|
|
@@ -41,16 +41,16 @@
|
|
|
41
41
|
"tsx": "4.23.15",
|
|
42
42
|
"typescript": "^6.0.3",
|
|
43
43
|
"vitest": "^5.1.0",
|
|
44
|
-
"@theholocron/
|
|
45
|
-
"@theholocron/
|
|
46
|
-
"@theholocron/
|
|
44
|
+
"@theholocron/cli": "5.0.0-alpha.537",
|
|
45
|
+
"@theholocron/http-client": "^1.58.0-alpha.56",
|
|
46
|
+
"@theholocron/checkly-client": "^1.58.0-alpha.56",
|
|
47
47
|
"@theholocron/misc-utils": "^1.17.0-alpha.5",
|
|
48
48
|
"@theholocron/tsconfig": "^8.9.0-alpha.22"
|
|
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.
|
|
53
|
+
"@theholocron/cli": "5.0.0-alpha.537"
|
|
54
54
|
},
|
|
55
55
|
"engines": {
|
|
56
56
|
"node": ">=22"
|