@theholocron/holocron-plugin-checkly 5.0.0-alpha.535 → 5.0.0-alpha.536
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 +1 -0
- package/dist/index.mjs +115 -2
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -146,6 +146,7 @@ export declare function monitoring(ctx: PluginContext): Monitoring;
|
|
|
146
146
|
export declare function createPlugin(options: ChecklyPluginOptions): {
|
|
147
147
|
name: string;
|
|
148
148
|
probes: {
|
|
149
|
+
token: import("@theholocron/cli").Probe;
|
|
149
150
|
connection: import("@theholocron/cli").Probe;
|
|
150
151
|
};
|
|
151
152
|
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
|
|
@@ -1211,6 +1223,103 @@ function checklyProbes(deps) {
|
|
|
1211
1223
|
deliver: deliverProbe(deps)
|
|
1212
1224
|
};
|
|
1213
1225
|
}
|
|
1226
|
+
// src/probes/token/parse-token-args.ts
|
|
1227
|
+
/** Reads `--layer <word>` and `--token-name <VAR>` (either spelling) from the words after the probe name. */
|
|
1228
|
+
function parseTokenArgs(args) {
|
|
1229
|
+
let layer;
|
|
1230
|
+
let tokenName;
|
|
1231
|
+
for (let i = 0; i < args.length; i++) {
|
|
1232
|
+
const arg = args[i];
|
|
1233
|
+
if (arg === "--layer") layer = args[++i];
|
|
1234
|
+
else if (arg.startsWith("--layer=")) layer = arg.slice(8);
|
|
1235
|
+
else if (arg === "--token-name") tokenName = args[++i];
|
|
1236
|
+
else if (arg.startsWith("--token-name=")) tokenName = arg.slice(13);
|
|
1237
|
+
}
|
|
1238
|
+
return {
|
|
1239
|
+
...layer ? { layer } : {},
|
|
1240
|
+
...tokenName ? { tokenName } : {}
|
|
1241
|
+
};
|
|
1242
|
+
}
|
|
1243
|
+
// src/probes/token/token.ts
|
|
1244
|
+
/** What a failed read says: a key the API refuses (401, 403) is named, anything else is the error's own message. */
|
|
1245
|
+
function failure(err) {
|
|
1246
|
+
if (err instanceof ProviderApiError && (err.status === 401 || err.status === 403)) return `refused (${err.status}): the key cannot read this`;
|
|
1247
|
+
return err instanceof Error ? err.message : String(err);
|
|
1248
|
+
}
|
|
1249
|
+
/**
|
|
1250
|
+
* The `token` probe for Checkly. Checkly reports no role or scope for a key, so the probe proves only what a read
|
|
1251
|
+
* proves: it lists the account's status pages and the incidents of the first one (what `sync-incidents` reads). A
|
|
1252
|
+
* refusal or any error on either is a `fail`, because the `ci` key must read them. It cannot tell a Read Only key from
|
|
1253
|
+
* a Read & Write one without writing, so a row says so. With `--layer` it also says whether that layer is one that
|
|
1254
|
+
* should hold the key. Read-only; never prints the key.
|
|
1255
|
+
*/
|
|
1256
|
+
function tokenProbe(ctx) {
|
|
1257
|
+
return {
|
|
1258
|
+
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.",
|
|
1259
|
+
writes: false,
|
|
1260
|
+
acceptsToken: true,
|
|
1261
|
+
async run(probe) {
|
|
1262
|
+
probe.secret(ctx.token());
|
|
1263
|
+
probe.say({
|
|
1264
|
+
status: "ok",
|
|
1265
|
+
label: "token",
|
|
1266
|
+
detail: "set"
|
|
1267
|
+
});
|
|
1268
|
+
const { layer, tokenName } = parseTokenArgs(probe.args ?? []);
|
|
1269
|
+
if (layer) {
|
|
1270
|
+
const declared = tokenExpectations(tokens, {
|
|
1271
|
+
layer,
|
|
1272
|
+
...tokenName ? { envName: tokenName } : {}
|
|
1273
|
+
}).length > 0;
|
|
1274
|
+
probe.say(declared ? {
|
|
1275
|
+
status: "ok",
|
|
1276
|
+
label: layer,
|
|
1277
|
+
detail: "a layer that should hold this token"
|
|
1278
|
+
} : {
|
|
1279
|
+
status: "info",
|
|
1280
|
+
label: layer,
|
|
1281
|
+
detail: "not a layer this token is declared for, so it is only described"
|
|
1282
|
+
});
|
|
1283
|
+
}
|
|
1284
|
+
const client = ctx.client();
|
|
1285
|
+
let pageId;
|
|
1286
|
+
try {
|
|
1287
|
+
const pages = await client.statusPages.list();
|
|
1288
|
+
pageId = pages[0]?.id;
|
|
1289
|
+
probe.say({
|
|
1290
|
+
status: "ok",
|
|
1291
|
+
label: "status pages",
|
|
1292
|
+
detail: `read ${pages.length}`
|
|
1293
|
+
});
|
|
1294
|
+
} catch (err) {
|
|
1295
|
+
probe.say({
|
|
1296
|
+
status: "fail",
|
|
1297
|
+
label: "status pages",
|
|
1298
|
+
detail: failure(err)
|
|
1299
|
+
});
|
|
1300
|
+
}
|
|
1301
|
+
if (pageId !== void 0) try {
|
|
1302
|
+
const incidents = await client.statusPages.incidents.list(pageId);
|
|
1303
|
+
probe.say({
|
|
1304
|
+
status: "ok",
|
|
1305
|
+
label: "incidents",
|
|
1306
|
+
detail: `read ${incidents.length} on the first status page`
|
|
1307
|
+
});
|
|
1308
|
+
} catch (err) {
|
|
1309
|
+
probe.say({
|
|
1310
|
+
status: "fail",
|
|
1311
|
+
label: "incidents",
|
|
1312
|
+
detail: failure(err)
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
probe.say({
|
|
1316
|
+
status: "info",
|
|
1317
|
+
label: "permissions",
|
|
1318
|
+
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"
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1321
|
+
};
|
|
1322
|
+
}
|
|
1214
1323
|
// src/verify-token.ts
|
|
1215
1324
|
/** Checks a Checkly API key by listing the accounts it can see; resolves to the account names and ids, or the failure message. */
|
|
1216
1325
|
async function verifyToken(token, opts = {}) {
|
|
@@ -1269,6 +1378,10 @@ function createPlugin(options) {
|
|
|
1269
1378
|
client: ctx.client,
|
|
1270
1379
|
checks: options.checks
|
|
1271
1380
|
}),
|
|
1381
|
+
token: tokenProbe({
|
|
1382
|
+
token: () => resolveToken(options),
|
|
1383
|
+
client: ctx.client
|
|
1384
|
+
}),
|
|
1272
1385
|
connection: connectionProbe({
|
|
1273
1386
|
provider: "Checkly",
|
|
1274
1387
|
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.536",
|
|
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/checkly-client": "^1.58.0-alpha.55",
|
|
45
|
-
"@theholocron/cli": "5.0.0-alpha.535",
|
|
46
44
|
"@theholocron/http-client": "^1.58.0-alpha.55",
|
|
45
|
+
"@theholocron/cli": "5.0.0-alpha.536",
|
|
46
|
+
"@theholocron/checkly-client": "^1.58.0-alpha.55",
|
|
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.536"
|
|
54
54
|
},
|
|
55
55
|
"engines": {
|
|
56
56
|
"node": ">=22"
|