@theholocron/holocron-plugin-axiom 5.0.0-alpha.364 → 5.0.0-alpha.365

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
@@ -42,7 +42,11 @@ interface VerifyTokenOptions {
42
42
  baseUrl?: string;
43
43
  fetch?: typeof fetch;
44
44
  }
45
- /** Checks an Axiom token by fetching the current user; the success subject is `user @` followed by the email, name or id, the failure carries the error message. */
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 that
48
+ * does not exist: a 404 means the token is accepted and may read datasets, and the subject says `API token`.
49
+ */
46
50
  export declare function verifyToken(token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult$1>;
47
51
  /** Options for the Axiom plugin: token resolution, the target dataset and test overrides. */
48
52
  export interface AxiomPluginOptions extends ResolveTokenInput, AxiomLogsOptions {
package/dist/index.mjs CHANGED
@@ -59,7 +59,21 @@ var AxiomLogs = class {
59
59
  }
60
60
  };
61
61
  // src/verify-token.ts
62
- /** Checks an Axiom token by fetching the current user; the success subject is `user @` followed by the email, name or id, the failure carries the error message. */
62
+ /**
63
+ * `verifyToken` — plugin-level export used by `holocron auth set axiom`
64
+ * + `holocron auth check`. Hits `GET /v2/user` and translates the
65
+ * response into the normalized `VerifyTokenResult` shape.
66
+ *
67
+ * Kept as a standalone function (not a capability method) so the auth
68
+ * command can call it without initializing the full plugin.
69
+ */
70
+ /** A dataset that does not exist: asking for it tells a token that may read datasets (404) from one that may not (403). */
71
+ const PROBE_DATASET = "holocron-token-check";
72
+ /**
73
+ * Checks an Axiom token by fetching the current user; the success subject is `user @` followed by the email, name or id,
74
+ * the failure carries the error message. An API token cannot read the user (403), so then it asks for a dataset that
75
+ * does not exist: a 404 means the token is accepted and may read datasets, and the subject says `API token`.
76
+ */
63
77
  async function verifyToken(token, opts = {}) {
64
78
  const client = createAxiomClient({
65
79
  token,
@@ -73,6 +87,25 @@ async function verifyToken(token, opts = {}) {
73
87
  subject: `user @ ${me.email ?? me.emails?.[0] ?? me.name ?? me.id ?? "unknown"}`
74
88
  };
75
89
  } catch (err) {
90
+ if (err instanceof ProviderApiError && err.status === 403) return verifyApiToken(client);
91
+ return {
92
+ ok: false,
93
+ message: errorMessage(err)
94
+ };
95
+ }
96
+ }
97
+ async function verifyApiToken(client) {
98
+ try {
99
+ await client.datasets.get(PROBE_DATASET);
100
+ return {
101
+ ok: true,
102
+ subject: "API token"
103
+ };
104
+ } catch (err) {
105
+ if (err instanceof ProviderApiError && err.status === 404) return {
106
+ ok: true,
107
+ subject: "API token"
108
+ };
76
109
  return {
77
110
  ok: false,
78
111
  message: errorMessage(err)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-axiom",
3
- "version": "5.0.0-alpha.364",
3
+ "version": "5.0.0-alpha.365",
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": "^5.9.3",
45
45
  "vitest": "^5.0.5",
46
- "@theholocron/axiom-client": "^1.58.0-alpha.15",
47
- "@theholocron/cli": "5.0.0-alpha.364",
46
+ "@theholocron/cli": "5.0.0-alpha.365",
47
+ "@theholocron/http-client": "^1.58.0-alpha.15",
48
48
  "@theholocron/eslint-config": "^8.9.0-alpha.11",
49
49
  "@theholocron/tsconfig": "^8.9.0-alpha.11",
50
- "@theholocron/http-client": "^1.58.0-alpha.15",
51
- "@theholocron/tsdown-config": "^8.9.0-alpha.11",
50
+ "@theholocron/axiom-client": "^1.58.0-alpha.15",
51
+ "@theholocron/misc-utils": "^1.17.0-alpha.1",
52
52
  "@theholocron/vitest-config": "^8.9.0-alpha.11",
53
- "@theholocron/misc-utils": "^1.17.0-alpha.1"
53
+ "@theholocron/tsdown-config": "^8.9.0-alpha.11"
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.364"
58
+ "@theholocron/cli": "5.0.0-alpha.365"
59
59
  },
60
60
  "engines": {
61
61
  "node": ">=22"