@theholocron/holocron-plugin-axiom 5.0.0-alpha.563 → 5.0.0-alpha.565

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
@@ -5,10 +5,16 @@
5
5
  * exports `verifyToken` + `AUTH_HINT` for `holocron check token`. See README
6
6
  * for auth + config docs.
7
7
  */
8
- import { AuthError, Logs, LogsDataset, PluginToken, ResolveTokenInput, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess } from "@theholocron/cli";
8
+ import { AuthError, Logs, LogsDataset, MintTokenInput, PluginToken, ResolveTokenInput, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess } from "@theholocron/cli";
9
9
  import { AxiomClient, AxiomClientOptions, AxiomDataset, AxiomUser, CreateAxiomDatasetInput, createAxiomClient } from "@theholocron/axiom-client";
10
10
  /** Resolves the Axiom token from `--token`, `HOLOCRON_AXIOM_TOKEN`, `AXIOM_TOKEN` or the keyring, and throws an `AuthError` when none is set. */
11
11
  export declare const resolveToken: import("@theholocron/cli").TokenResolver;
12
+ /**
13
+ * Resolves the Axiom **personal access token** that `holocron provider axiom token` makes API tokens with, from
14
+ * `HOLOCRON_AXIOM_PERSONAL_TOKEN`, the `credentials` providers or the keyring entry `axiom.personal`. It never falls
15
+ * back to the dataset API token above, which cannot make tokens.
16
+ */
17
+ export declare const resolvePersonalToken: import("@theholocron/cli").FeatureResolver;
12
18
  /** Every token this plugin takes, for `holocron doctor secrets --verify`, with what each layer's token must and must not be able to do. */
13
19
  export declare const tokens: PluginToken[];
14
20
  /** Options for the Axiom `logs` capability. */
@@ -99,6 +105,7 @@ export declare function createPlugin(options: AxiomPluginOptions): {
99
105
  connection: import("@theholocron/cli").Probe;
100
106
  };
101
107
  whoami: import("@theholocron/cli").ProviderAction;
108
+ mintToken: (input: MintTokenInput) => Promise<import("@theholocron/cli").MintTokenResult>;
102
109
  capabilities: {
103
110
  logs: () => Logs;
104
111
  };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { AuthError, ProviderApiError, connectionProbe, createResolveToken, resolveValue, tokenExpectations, whoamiAction } from "@theholocron/cli";
1
+ import { AuthError, ProviderApiError, connectionProbe, createFeatureResolver, createResolveToken, resolveValue, tokenExpectations, whoamiAction } from "@theholocron/cli";
2
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";
@@ -31,6 +31,12 @@ const EXPECTED = { permissions: {
31
31
  ci: RULES,
32
32
  prod: RULES
33
33
  } };
34
+ /**
35
+ * Where the personal access token that makes API tokens (`HOLOCRON_AXIOM_PERSONAL_TOKEN`) is held: a maintainer's own
36
+ * machine (`local`) only, never `ci`. It has no permission model to declare: a personal token can do everything its
37
+ * owner can. Change it and the personal-token note in `tokens.mdx` together.
38
+ */
39
+ const PERSONAL_EXPECTED = { layers: ["local"] };
34
40
  // src/verify-token.ts
35
41
  /**
36
42
  * `verifyToken` — plugin-level export used by `holocron new token axiom`
@@ -94,11 +100,25 @@ const resolveToken = createResolveToken({
94
100
  keyringService: "axiom",
95
101
  errorMessage: "no Axiom token found. Pass --token <TOKEN>, set HOLOCRON_AXIOM_TOKEN / AXIOM_TOKEN, or run: holocron new token axiom <TOKEN>"
96
102
  });
103
+ /**
104
+ * Resolves the Axiom **personal access token** that `holocron provider axiom token` makes API tokens with, from
105
+ * `HOLOCRON_AXIOM_PERSONAL_TOKEN`, the `credentials` providers or the keyring entry `axiom.personal`. It never falls
106
+ * back to the dataset API token above, which cannot make tokens.
107
+ */
108
+ const resolvePersonalToken = createFeatureResolver({
109
+ envName: "HOLOCRON_AXIOM_PERSONAL_TOKEN",
110
+ keyringKey: "axiom.personal",
111
+ vendor: "Axiom personal access"
112
+ });
97
113
  /** Every token this plugin takes, for `holocron doctor secrets --verify`, with what each layer's token must and must not be able to do. */
98
114
  const tokens = [{
99
115
  ...resolveToken.token,
100
116
  verify: (token) => verifyToken(token, { dataset: resolveValue(["AXIOM_DATASET"], void 0, { prefix: PREFIX }) }),
101
117
  expect: EXPECTED
118
+ }, {
119
+ ...resolvePersonalToken.token,
120
+ optional: true,
121
+ expect: PERSONAL_EXPECTED
102
122
  }];
103
123
  // src/capabilities/logs.ts
104
124
  /** The dataset asked for when the caller names none. It does not exist: asking for it tells a token Axiom accepts (404) from one it refuses (401). */
@@ -182,6 +202,74 @@ var AxiomLogs = class {
182
202
  return { alreadyExists: false };
183
203
  }
184
204
  };
205
+ // src/mint-token.ts
206
+ const DAY_MS = 864e5;
207
+ /**
208
+ * The dataset capability each declared permission grants. `read` (the dataset's own metadata, for `doctor logs`) has no
209
+ * capability Axiom documents, so it is not requested and a note says so rather than guessing a name.
210
+ */
211
+ const CAPABILITIES = {
212
+ ingest: {
213
+ name: "ingest",
214
+ capability: {
215
+ Access: "allow",
216
+ Actions: ["create"]
217
+ }
218
+ },
219
+ query: {
220
+ name: "query",
221
+ capability: {
222
+ Access: "allow",
223
+ Actions: ["read"]
224
+ }
225
+ }
226
+ };
227
+ /**
228
+ * Makes an Axiom API token for a layer through `POST /v2/tokens`, scoped to the one dataset and to the permissions the
229
+ * plugin declares `required` for that layer (`PluginToken.expect`), with an expiry from the declared rotation. It needs
230
+ * a personal access token (`HOLOCRON_AXIOM_PERSONAL_TOKEN`) and the organization id (`HOLOCRON_AXIOM_ORG`) and refuses,
231
+ * before any call, a layer with no declared permissions, no dataset, no org id or no personal token. It never grants an
232
+ * organization capability. The value is returned, never printed.
233
+ */
234
+ async function mintAxiomToken(input, options) {
235
+ const envName = resolveToken.token.envName;
236
+ const declared = tokenExpectations(tokens, {
237
+ layer: input.layer,
238
+ envName
239
+ })[0];
240
+ if (!declared || declared.required.length === 0) throw new Error(`the Axiom token declares no permissions for \`${input.layer}\`, so none can be made for it; a token with no declared scope is never made`);
241
+ const { dataset } = options;
242
+ if (!dataset) throw new Error("an Axiom dataset is required to make a token: set the plugin's dataset option or HOLOCRON_AXIOM_DATASET");
243
+ const orgId = resolveValue(["AXIOM_ORG"], options.env, { prefix: PREFIX });
244
+ if (!orgId) throw new Error("an Axiom organization id is required to make a token: set HOLOCRON_AXIOM_ORG (the `axiom-abcd` of your console URL)");
245
+ const personal = resolvePersonalToken({ env: options.env });
246
+ const granted = declared.required.flatMap((permission) => {
247
+ const entry = CAPABILITIES[permission];
248
+ return entry ? [entry] : [];
249
+ });
250
+ const unscoped = declared.required.filter((permission) => !CAPABILITIES[permission]);
251
+ const now = (input.now ?? (() => /* @__PURE__ */ new Date()))();
252
+ const days = input.expiresInDays ?? declared.rotation.maxAgeDays;
253
+ const created = await createAxiomClient({
254
+ token: personal,
255
+ orgId,
256
+ baseUrl: options.baseUrl,
257
+ fetch: options.fetch
258
+ }).tokens.create({
259
+ name: input.name,
260
+ description: `Made by holocron for the ${input.layer} layer`,
261
+ expiresAt: new Date(now.getTime() + days * DAY_MS).toISOString(),
262
+ datasetCapabilities: { [dataset]: Object.fromEntries(granted.map((g) => [g.name, g.capability])) }
263
+ });
264
+ if (!created.token) throw new Error("Axiom made the token but returned no value");
265
+ return {
266
+ value: created.token,
267
+ envName,
268
+ id: created.id,
269
+ ...created.expiresAt ? { expiresAt: created.expiresAt } : {},
270
+ notes: [`the token reaches the \`${dataset}\` dataset only, with no organization capability`, ...unscoped.map((permission) => `\`${permission}\` was not requested, because Axiom documents no capability for it; run \`holocron probe axiom token --environment ${input.layer}\` to see what the token reaches`)]
271
+ };
272
+ }
185
273
  // src/probes/token/parse-token-args.ts
186
274
  /** Reads the words after the probe name: `--layer <word>`, `--token-name <VAR>` and any number of dataset names. */
187
275
  function parseTokenArgs(args) {
@@ -426,6 +514,12 @@ function createPlugin(options) {
426
514
  }),
427
515
  tokens
428
516
  }),
517
+ mintToken: (input) => mintAxiomToken(input, {
518
+ dataset: ctx.options.dataset,
519
+ env: options.env,
520
+ baseUrl: options.baseUrl,
521
+ fetch: options.fetch
522
+ }),
429
523
  capabilities: { logs: () => logs(ctx) }
430
524
  };
431
525
  }
@@ -434,4 +528,4 @@ function createPlugin(options) {
434
528
  * supplied or when the supplied token is rejected.
435
529
  */
436
530
  const AUTH_HINT = "generate an Axiom API token at https://app.axiom.co/settings/api-tokens with dataset read + create permissions, then run: holocron new token axiom <TOKEN>";
437
- export { AUTH_HINT, AuthError, AxiomLogs, createAxiomClient, createContext, createPlugin, logs, resolveToken, tokens, verifyToken };
531
+ export { AUTH_HINT, AuthError, AxiomLogs, createAxiomClient, createContext, createPlugin, logs, resolvePersonalToken, resolveToken, tokens, verifyToken };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-axiom",
3
- "version": "5.0.0-alpha.563",
3
+ "version": "5.0.0-alpha.565",
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,19 +43,19 @@
43
43
  "tsx": "4.23.15",
44
44
  "typescript": "^6.0.3",
45
45
  "vitest": "^5.1.1",
46
- "@theholocron/axiom-client": "^1.58.0-alpha.62",
47
- "@theholocron/cli": "5.0.0-alpha.563",
46
+ "@theholocron/cli": "5.0.0-alpha.565",
47
+ "@theholocron/axiom-client": "^1.58.0-alpha.64",
48
48
  "@theholocron/eslint-config": "^8.9.0-alpha.24",
49
- "@theholocron/http-client": "^1.58.0-alpha.62",
50
- "@theholocron/tsconfig": "^8.9.0-alpha.24",
49
+ "@theholocron/http-client": "^1.58.0-alpha.64",
51
50
  "@theholocron/misc-utils": "^1.17.0-alpha.8",
51
+ "@theholocron/tsconfig": "^8.9.0-alpha.24",
52
52
  "@theholocron/tsdown-config": "^8.9.0-alpha.24",
53
53
  "@theholocron/vitest-config": "^8.9.0-alpha.24"
54
54
  },
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.563"
58
+ "@theholocron/cli": "5.0.0-alpha.565"
59
59
  },
60
60
  "engines": {
61
61
  "node": ">=22"