@theholocron/holocron-plugin-axiom 5.0.0-alpha.444 → 5.0.0-alpha.446
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 +4 -4
- package/dist/index.d.mts +8 -2
- package/dist/index.mjs +62 -59
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -70,7 +70,7 @@ synced from 1Password. Leave the token unset locally to skip Axiom entirely.
|
|
|
70
70
|
|
|
71
71
|
Plugin-level exports (not capability methods, per the auth-bootstrap convention):
|
|
72
72
|
|
|
73
|
-
| Export | Purpose
|
|
74
|
-
| ------------- |
|
|
75
|
-
| `verifyToken` | `GET /v2/user` — returns `{ ok: true, subject: "user @ …" }` or `{ ok: false, message }`.
|
|
76
|
-
| `AUTH_HINT` | One-line hint printed by `holocron new token` when no token is supplied or the token is bad.
|
|
73
|
+
| Export | Purpose |
|
|
74
|
+
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
75
|
+
| `verifyToken` | `GET /v2/user` — returns `{ ok: true, subject: "user @ …" }` or `{ ok: false, message }`. An API token cannot read the user (403), so it then reads the `dataset` option (`HOLOCRON_AXIOM_DATASET`), the dataset the token is scoped to: a 200 or a 404 is `API token`, a 403 or 401 there is rejected. |
|
|
76
|
+
| `AUTH_HINT` | One-line hint printed by `holocron new token` when no token is supplied or the token is bad. |
|
package/dist/index.d.mts
CHANGED
|
@@ -46,11 +46,17 @@ export declare class AxiomLogs implements Logs {
|
|
|
46
46
|
interface VerifyTokenOptions {
|
|
47
47
|
baseUrl?: string;
|
|
48
48
|
fetch?: typeof fetch;
|
|
49
|
+
/**
|
|
50
|
+
* The dataset the token is meant to read (`HOLOCRON_AXIOM_DATASET`). An API token that cannot read the user is asked
|
|
51
|
+
* about this one, because a token scoped per dataset is refused (403) for any other name.
|
|
52
|
+
*/
|
|
53
|
+
dataset?: string;
|
|
49
54
|
}
|
|
50
55
|
/**
|
|
51
56
|
* Checks an Axiom token by fetching the current user; the success subject is `user @` followed by the email, name or id,
|
|
52
|
-
* the failure carries the error message. An API token cannot read the user (403), so then it asks for a dataset
|
|
53
|
-
* does not exist
|
|
57
|
+
* the failure carries the error message. An API token cannot read the user (403), so then it asks for a dataset: the one
|
|
58
|
+
* the token is meant to read (`dataset`), else one that does not exist. A 200 or a 404 means the token is accepted and
|
|
59
|
+
* may read datasets, and the subject says `API token`; a 403 on the dataset it is meant to read still fails.
|
|
54
60
|
*/
|
|
55
61
|
export declare function verifyToken(token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult$1>;
|
|
56
62
|
/** Options for the Axiom plugin: token resolution, the target dataset and test overrides. */
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuthError, ProviderApiError, connectionProbe, createResolveToken, tokenExpectations } from "@theholocron/cli";
|
|
2
|
-
import { createEnvLookup, firstEnv } from "@theholocron/env-utils/lookup";
|
|
1
|
+
import { AuthError, ProviderApiError, connectionProbe, createResolveToken, resolveValue, tokenExpectations } from "@theholocron/cli";
|
|
2
|
+
import { PREFIX, createEnvLookup, firstEnv } from "@theholocron/env-utils/lookup";
|
|
3
3
|
import { errorMessage } from "@theholocron/misc-utils";
|
|
4
4
|
import { createAxiomClient } from "@theholocron/axiom-client";
|
|
5
5
|
// src/probes/token/expectations.ts
|
|
@@ -31,6 +31,61 @@ const EXPECTED = { permissions: {
|
|
|
31
31
|
ci: RULES,
|
|
32
32
|
prod: RULES
|
|
33
33
|
} };
|
|
34
|
+
// src/verify-token.ts
|
|
35
|
+
/**
|
|
36
|
+
* `verifyToken` — plugin-level export used by `holocron new token axiom`
|
|
37
|
+
* + `holocron check token`. Hits `GET /v2/user` and translates the
|
|
38
|
+
* response into the normalized `VerifyTokenResult` shape.
|
|
39
|
+
*
|
|
40
|
+
* Kept as a standalone function (not a capability method) so the auth
|
|
41
|
+
* command can call it without initializing the full plugin.
|
|
42
|
+
*/
|
|
43
|
+
/** Asked about when no dataset is known: one that does not exist, so a token that may read datasets answers 404. */
|
|
44
|
+
const PROBE_DATASET$1 = "holocron-token-check";
|
|
45
|
+
/**
|
|
46
|
+
* Checks an Axiom token by fetching the current user; the success subject is `user @` followed by the email, name or id,
|
|
47
|
+
* the failure carries the error message. An API token cannot read the user (403), so then it asks for a dataset: the one
|
|
48
|
+
* the token is meant to read (`dataset`), else one that does not exist. A 200 or a 404 means the token is accepted and
|
|
49
|
+
* may read datasets, and the subject says `API token`; a 403 on the dataset it is meant to read still fails.
|
|
50
|
+
*/
|
|
51
|
+
async function verifyToken(token, opts = {}) {
|
|
52
|
+
const client = createAxiomClient({
|
|
53
|
+
token,
|
|
54
|
+
baseUrl: opts.baseUrl,
|
|
55
|
+
fetch: opts.fetch
|
|
56
|
+
});
|
|
57
|
+
try {
|
|
58
|
+
const me = await client.user.me();
|
|
59
|
+
return {
|
|
60
|
+
ok: true,
|
|
61
|
+
subject: `user @ ${me.email ?? me.emails?.[0] ?? me.name ?? me.id ?? "unknown"}`
|
|
62
|
+
};
|
|
63
|
+
} catch (err) {
|
|
64
|
+
if (err instanceof ProviderApiError && err.status === 403) return verifyApiToken(client, opts.dataset);
|
|
65
|
+
return {
|
|
66
|
+
ok: false,
|
|
67
|
+
message: errorMessage(err)
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function verifyApiToken(client, dataset) {
|
|
72
|
+
try {
|
|
73
|
+
await client.datasets.get(dataset ?? PROBE_DATASET$1);
|
|
74
|
+
return {
|
|
75
|
+
ok: true,
|
|
76
|
+
subject: "API token"
|
|
77
|
+
};
|
|
78
|
+
} catch (err) {
|
|
79
|
+
if (err instanceof ProviderApiError && err.status === 404) return {
|
|
80
|
+
ok: true,
|
|
81
|
+
subject: "API token"
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
ok: false,
|
|
85
|
+
message: errorMessage(err)
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
34
89
|
// src/auth.ts
|
|
35
90
|
/** Resolves the Axiom token from `--token`, `HOLOCRON_AXIOM_TOKEN`, `AXIOM_TOKEN` or the keyring, and throws an `AuthError` when none is set. */
|
|
36
91
|
const resolveToken = createResolveToken({
|
|
@@ -42,11 +97,12 @@ const resolveToken = createResolveToken({
|
|
|
42
97
|
/** Every token this plugin takes, for `holocron doctor secrets --verify`, with what each layer's token must and must not be able to do. */
|
|
43
98
|
const tokens = [{
|
|
44
99
|
...resolveToken.token,
|
|
100
|
+
verify: (token) => verifyToken(token, { dataset: resolveValue(["AXIOM_DATASET"], void 0, { prefix: PREFIX }) }),
|
|
45
101
|
expect: EXPECTED
|
|
46
102
|
}];
|
|
47
103
|
// src/capabilities/logs.ts
|
|
48
104
|
/** A dataset that does not exist: asking for it tells a token Axiom accepts (404) from one it refuses (401). */
|
|
49
|
-
const PROBE_DATASET
|
|
105
|
+
const PROBE_DATASET = "holocron-token-check";
|
|
50
106
|
/** The `logs` capability for Axiom: checks a dataset is reachable and creates datasets that are missing. */
|
|
51
107
|
var AxiomLogs = class {
|
|
52
108
|
client;
|
|
@@ -93,7 +149,7 @@ var AxiomLogs = class {
|
|
|
93
149
|
}
|
|
94
150
|
async checkToken() {
|
|
95
151
|
try {
|
|
96
|
-
await this.client().datasets.get(PROBE_DATASET
|
|
152
|
+
await this.client().datasets.get(PROBE_DATASET);
|
|
97
153
|
return { ok: true };
|
|
98
154
|
} catch (err) {
|
|
99
155
|
if (err instanceof ProviderApiError) {
|
|
@@ -309,60 +365,6 @@ function tokenProbe(ctx) {
|
|
|
309
365
|
}
|
|
310
366
|
};
|
|
311
367
|
}
|
|
312
|
-
// src/verify-token.ts
|
|
313
|
-
/**
|
|
314
|
-
* `verifyToken` — plugin-level export used by `holocron new token axiom`
|
|
315
|
-
* + `holocron check token`. Hits `GET /v2/user` and translates the
|
|
316
|
-
* response into the normalized `VerifyTokenResult` shape.
|
|
317
|
-
*
|
|
318
|
-
* Kept as a standalone function (not a capability method) so the auth
|
|
319
|
-
* command can call it without initializing the full plugin.
|
|
320
|
-
*/
|
|
321
|
-
/** A dataset that does not exist: asking for it tells a token that may read datasets (404) from one that may not (403). */
|
|
322
|
-
const PROBE_DATASET = "holocron-token-check";
|
|
323
|
-
/**
|
|
324
|
-
* Checks an Axiom token by fetching the current user; the success subject is `user @` followed by the email, name or id,
|
|
325
|
-
* the failure carries the error message. An API token cannot read the user (403), so then it asks for a dataset that
|
|
326
|
-
* does not exist: a 404 means the token is accepted and may read datasets, and the subject says `API token`.
|
|
327
|
-
*/
|
|
328
|
-
async function verifyToken(token, opts = {}) {
|
|
329
|
-
const client = createAxiomClient({
|
|
330
|
-
token,
|
|
331
|
-
baseUrl: opts.baseUrl,
|
|
332
|
-
fetch: opts.fetch
|
|
333
|
-
});
|
|
334
|
-
try {
|
|
335
|
-
const me = await client.user.me();
|
|
336
|
-
return {
|
|
337
|
-
ok: true,
|
|
338
|
-
subject: `user @ ${me.email ?? me.emails?.[0] ?? me.name ?? me.id ?? "unknown"}`
|
|
339
|
-
};
|
|
340
|
-
} catch (err) {
|
|
341
|
-
if (err instanceof ProviderApiError && err.status === 403) return verifyApiToken(client);
|
|
342
|
-
return {
|
|
343
|
-
ok: false,
|
|
344
|
-
message: errorMessage(err)
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
async function verifyApiToken(client) {
|
|
349
|
-
try {
|
|
350
|
-
await client.datasets.get(PROBE_DATASET);
|
|
351
|
-
return {
|
|
352
|
-
ok: true,
|
|
353
|
-
subject: "API token"
|
|
354
|
-
};
|
|
355
|
-
} catch (err) {
|
|
356
|
-
if (err instanceof ProviderApiError && err.status === 404) return {
|
|
357
|
-
ok: true,
|
|
358
|
-
subject: "API token"
|
|
359
|
-
};
|
|
360
|
-
return {
|
|
361
|
-
ok: false,
|
|
362
|
-
message: errorMessage(err)
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
368
|
// src/index.ts
|
|
367
369
|
/** Creates the shared context for the given options; no token is resolved until `client()` is first called. */
|
|
368
370
|
function createContext(options) {
|
|
@@ -403,7 +405,8 @@ function createPlugin(options) {
|
|
|
403
405
|
token: () => resolveToken(options),
|
|
404
406
|
verify: (token) => verifyToken(token, {
|
|
405
407
|
baseUrl: options.baseUrl,
|
|
406
|
-
fetch: options.fetch
|
|
408
|
+
fetch: options.fetch,
|
|
409
|
+
dataset: ctx.options.dataset
|
|
407
410
|
})
|
|
408
411
|
})
|
|
409
412
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/holocron-plugin-axiom",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.446",
|
|
4
4
|
"description": "Holocron plugin for Axiom. Implements the logs capability against Axiom's REST API — dataset provisioning and connectivity checks, plus verifyToken + AUTH_HINT for `holocron auth`.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"axiom",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"tsx": "4.23.15",
|
|
44
44
|
"typescript": "^5.9.3",
|
|
45
45
|
"vitest": "^5.1.0",
|
|
46
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
47
|
-
"@theholocron/eslint-config": "^8.9.0-alpha.17",
|
|
46
|
+
"@theholocron/cli": "5.0.0-alpha.446",
|
|
48
47
|
"@theholocron/axiom-client": "^1.58.0-alpha.32",
|
|
48
|
+
"@theholocron/eslint-config": "^8.9.0-alpha.17",
|
|
49
49
|
"@theholocron/http-client": "^1.58.0-alpha.32",
|
|
50
50
|
"@theholocron/misc-utils": "^1.17.0-alpha.4",
|
|
51
51
|
"@theholocron/tsconfig": "^8.9.0-alpha.17",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"@theholocron/axiom-client": "^1.43.1",
|
|
57
57
|
"@theholocron/misc-utils": "^1.16.0",
|
|
58
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
58
|
+
"@theholocron/cli": "5.0.0-alpha.446"
|
|
59
59
|
},
|
|
60
60
|
"engines": {
|
|
61
61
|
"node": ">=22"
|