axiam-sdk 1.0.0-alpha21 → 1.0.0-alpha24

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.
Files changed (46) hide show
  1. package/README.md +93 -2
  2. package/dist/{authzCore-DuRI1aJf.d.cts → authzCore-CA9zFm1n.d.cts} +38 -4
  3. package/dist/{authzCore-DtSN59if.d.ts → authzCore-a-wZL2P3.d.ts} +38 -4
  4. package/dist/{client-B_FqmZ0i.d.cts → client-CtT9nHQP.d.cts} +1 -1
  5. package/dist/{client-Dn1fs5MH.d.ts → client-utwuwc9m.d.ts} +1 -1
  6. package/dist/{cookieJar-Cl8Lq9dL.d.ts → cookieJar-C9fqLqbh.d.ts} +29 -6
  7. package/dist/{cookieJar-BTDnjjbL.d.cts → cookieJar-DeJKczxD.d.cts} +29 -6
  8. package/dist/grpc/index.d.cts +5 -5
  9. package/dist/grpc/index.d.ts +5 -5
  10. package/dist/grpc/index.js +81 -14
  11. package/dist/grpc/index.js.map +1 -1
  12. package/dist/grpc/index.mjs +81 -14
  13. package/dist/grpc/index.mjs.map +1 -1
  14. package/dist/index.d.cts +2 -2
  15. package/dist/index.d.ts +2 -2
  16. package/dist/index.js +32 -7
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +32 -7
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/{jwks-BgojMGC5.d.cts → jwks-DEiwxlku.d.cts} +84 -3
  21. package/dist/{jwks-BgojMGC5.d.ts → jwks-DEiwxlku.d.ts} +84 -3
  22. package/dist/middleware/index.d.cts +6 -6
  23. package/dist/middleware/index.d.ts +6 -6
  24. package/dist/middleware/index.js +177 -138
  25. package/dist/middleware/index.js.map +1 -1
  26. package/dist/middleware/index.mjs +176 -139
  27. package/dist/middleware/index.mjs.map +1 -1
  28. package/dist/nestjs/index.d.cts +2 -2
  29. package/dist/nestjs/index.d.ts +2 -2
  30. package/dist/node/index.d.cts +94 -6
  31. package/dist/node/index.d.ts +94 -6
  32. package/dist/node/index.js +183 -16
  33. package/dist/node/index.js.map +1 -1
  34. package/dist/node/index.mjs +179 -18
  35. package/dist/node/index.mjs.map +1 -1
  36. package/dist/{oidcState-CkFuCjpM.d.ts → oidcState-CfebuJ0n.d.ts} +2 -2
  37. package/dist/{oidcState-BGxqWUun.d.cts → oidcState-tHRAg5bu.d.cts} +2 -2
  38. package/dist/rest/index.d.cts +2 -2
  39. package/dist/rest/index.d.ts +2 -2
  40. package/dist/rest/index.js +32 -7
  41. package/dist/rest/index.js.map +1 -1
  42. package/dist/rest/index.mjs +32 -7
  43. package/dist/rest/index.mjs.map +1 -1
  44. package/dist/{session-BWUWhhyB.d.cts → session-ti3C9ZJU.d.cts} +28 -1
  45. package/dist/{session-BWUWhhyB.d.ts → session-ti3C9ZJU.d.ts} +28 -1
  46. package/package.json +2 -2
package/README.md CHANGED
@@ -17,8 +17,37 @@ Official TypeScript/JavaScript client SDK for [AXIAM](https://github.com/ilpanic
17
17
 
18
18
  ## Contract conformance
19
19
 
20
- This SDK conforms to CONTRACT.md §1–§12 (including §6.1 mTLS client certificates and the §12
21
- OIDC/SSO relying-party helpers).
20
+ This SDK conforms to CONTRACT.md §1–§13 (including §6.1 mTLS client certificates, the
21
+ §10.1 minimum local-verification set, the §12 OIDC/SSO relying-party helpers, and the §13
22
+ `verifyWebhook` signature verifier).
23
+
24
+ ### §10.1 minimum local-verification set
25
+
26
+ `axiamMiddleware` / `axiamPlugin` (and the `requireAuth` / `requireAccess` / `requireRole`
27
+ helpers built on them) funnel through `authenticateRequest`, which applies **every** §10.1
28
+ rule on every inbound token: EdDSA `alg` pinned before the JWKS is consulted, a REQUIRED
29
+ `exp` (`jose` only checks `exp` *if present*, so `requiredClaims: ['exp']` is passed
30
+ explicitly), `nbf` honoured when present, `tenant_id` asserted against the session's
31
+ configured tenant, `iss`/`aud` checked when configured, all under a named 60-second
32
+ `CLOCK_SKEW_LEEWAY_SEC`.
33
+
34
+ Because the `/oauth2/jwks` trust anchor is **organization-wide**, the session guarding a
35
+ resource server must be configured with the tenant **UUID** (`tenantId`), since that is
36
+ what the `tenant_id` claim carries. `expectedIssuer` / `expectedAudience` are optional and
37
+ unset by default:
38
+
39
+ ```ts
40
+ const client = createNodeClient({
41
+ baseUrl: 'https://iam.example.com',
42
+ tenantId: '…-uuid-…', // §10.1 rule 4 — compared against the tenant_id claim
43
+ expectedAudience: 'axiam:user', // §10.1 rule 6 — optional, recommended
44
+ });
45
+ app.use(axiamMiddleware(client.session));
46
+ ```
47
+
48
+ `verifier.verifySignatureOnlyUnchecked(token)` is the §10.1 raw signature-only primitive,
49
+ for integrators implementing their own policy. It checks the signature and nothing else —
50
+ never use it to guard a route.
22
51
 
23
52
  See [`CONTRACT.md`](./CONTRACT.md) for the full cross-language behavioral contract.
24
53
 
@@ -478,6 +507,68 @@ strings.
478
507
 
479
508
  See `examples/express-oidc-login.ts` for a complete, runnable example.
480
509
 
510
+ ## Webhook signature verification (`axiam-sdk/node`, CONTRACT.md §13)
511
+
512
+ AXIAM signs every webhook delivery with a Stripe-style signed timestamp:
513
+
514
+ ```
515
+ X-Axiam-Signature: t=<unix_seconds>,v1=<hex_lowercase_hmac>
516
+ ```
517
+
518
+ where `v1 = HMAC-SHA256(secret_utf8_bytes, "<timestamp>.<raw_body>")`. `verifyWebhook`
519
+ recomputes and checks that signature — in constant time, with a two-sided freshness window —
520
+ so integrators never hand-roll (or skip) the comparison.
521
+
522
+ ```typescript
523
+ import { verifyWebhook, WebhookVerifyError, Sensitive } from 'axiam-sdk/node';
524
+
525
+ const secret = new Sensitive(process.env.AXIAM_WEBHOOK_SECRET!);
526
+
527
+ try {
528
+ const { event, id } = verifyWebhook(secret, req.header('X-Axiam-Signature')!, req.rawBody);
529
+ // `event`/`id` come from the verified body's own `event`/`id` fields; `X-Axiam-Delivery`
530
+ // is the at-least-once dedup key — keep a short-lived seen-set, since a retry replays a
531
+ // validly-signed request inside the freshness window.
532
+ console.log('verified webhook:', event, id);
533
+ } catch (err) {
534
+ if (err instanceof WebhookVerifyError) {
535
+ res.status(400).end(); // err.reason is a stable code; err.message never
536
+ // contains the secret or the expected signature
537
+ }
538
+ }
539
+ ```
540
+
541
+ **The raw body is load-bearing.** `verifyWebhook` MUST receive the *exact* bytes AXIAM sent —
542
+ `Buffer`, `Uint8Array`, or the identical raw string — never a `JSON.stringify` of the parsed
543
+ body. Re-serializing changes key order/whitespace and silently breaks the MAC; this is the
544
+ single most common integration mistake. Most JSON body-parsing middleware discards the raw
545
+ bytes by default, so capture them explicitly on the webhook route. With Express,
546
+ `express.json()` alone does **not** keep them — use its `verify` callback, or mount
547
+ `express.raw({ type: 'application/json' })` on that one route instead:
548
+
549
+ ```typescript
550
+ import express from 'express';
551
+
552
+ app.post(
553
+ '/webhooks/axiam',
554
+ express.json({
555
+ verify: (req, _res, buf) => {
556
+ (req as express.Request & { rawBody: Buffer }).rawBody = buf;
557
+ },
558
+ }),
559
+ (req, res) => {
560
+ const { rawBody } = req as express.Request & { rawBody: Buffer };
561
+ const event = verifyWebhook(secret, req.header('X-Axiam-Signature')!, rawBody);
562
+ // ...
563
+ },
564
+ );
565
+ ```
566
+
567
+ The freshness window defaults to 300 s and is two-sided — a future-dated `t=` is rejected just
568
+ like a stale one — and accepts a `tolerance` override plus a `now` injection seam for tests. A
569
+ failure always raises the typed `WebhookVerifyError` (never a generic exception whose message
570
+ could leak the expected signature).
571
+
481
572
  ## Error handling
482
573
 
483
574
  Every persona throws the three CONTRACT.md §2 error types — `AuthError`, `AuthzError`,
@@ -1,18 +1,42 @@
1
1
  import { A as AccessCheck, a as AccessDecision } from './types-BVkMoqLU.cjs';
2
- import { V as Verifier } from './jwks-BgojMGC5.cjs';
2
+ import { V as Verifier } from './jwks-DEiwxlku.cjs';
3
3
 
4
4
  /**
5
5
  * Minimal session shape the middleware needs: a JWKS verifier (D-11) and the
6
6
  * tenant this resource server is configured for (CR-03). JWKS is org-wide,
7
7
  * not tenant-scoped (node/jwks.ts) — `tenantHeaderValue` is what lets
8
8
  * `authenticateRequest` reject a validly-signed token minted for a
9
- * DIFFERENT tenant in the same org.
9
+ * DIFFERENT tenant in the same org (CONTRACT.md §10.1 rule 4).
10
10
  */
11
11
  interface VerifiableSession {
12
12
  /** Local JWKS verifier (D-11) — validates the token's EdDSA signature against the org-wide cached JWKS, offline on a cache hit. */
13
13
  jwksVerifier: Verifier;
14
- /** The tenant this resource server is configured for (CR-03); a validly-signed token minted for a different tenant in the same org is rejected. */
14
+ /**
15
+ * The tenant this resource server is configured for (CR-03, §10.1 rule 4);
16
+ * a validly-signed token minted for a different tenant in the same org is
17
+ * rejected.
18
+ *
19
+ * @remarks
20
+ * The claim it is compared against is the token's `tenant_id`, which is
21
+ * always a UUID — so a resource server guarding routes MUST be configured
22
+ * with `tenantId` (the UUID form), not `tenantSlug`. A slug-configured
23
+ * session can never match and therefore rejects every request; that is
24
+ * fail-closed by design, not a silent pass.
25
+ */
15
26
  tenantHeaderValue: string;
27
+ /**
28
+ * CONTRACT.md §10.1 rule 5 — expected token issuer. Optional and unset by
29
+ * default: the rule is conditional on configuration, and the SDK never
30
+ * hardcodes an issuer. When set, a token whose `iss` differs is rejected.
31
+ * Populated from `AxiamClientOptions.expectedIssuer`.
32
+ */
33
+ expectedIssuer?: string;
34
+ /**
35
+ * CONTRACT.md §10.1 rule 6 — expected token audience. Optional and unset by
36
+ * default. A resource server guarding user-facing routes SHOULD set
37
+ * `"axiam:user"`. Populated from `AxiamClientOptions.expectedAudience`.
38
+ */
39
+ expectedAudience?: string;
16
40
  }
17
41
  /** Authenticated identity injected as req.axiamUser / request.axiamUser (§10). */
18
42
  interface AxiamIdentity {
@@ -30,8 +54,18 @@ interface AxiamIdentity {
30
54
  * AXIAM's access token carries no dedicated `roles` claim server-side
31
55
  * (mirrors the Rust SDK's src/middleware/actix.rs).
32
56
  *
57
+ * This is the SDK's **documented §10 guard entry point** for TypeScript, and
58
+ * it applies the complete CONTRACT.md §10.1 minimum local-verification set:
59
+ * rules 1/2/3/5/6/7 inside `verifyAccessToken` (EdDSA `alg` pinned before key
60
+ * lookup, REQUIRED numeric `exp`, `nbf` when present, conditional `iss`/`aud`,
61
+ * a named bounded clock skew) and rule 4 — the `tenant_id` assertion — both
62
+ * there and again here, so a caller-supplied `Verifier` implementation that
63
+ * ignores its expectations still cannot get a cross-tenant token past the
64
+ * middleware.
65
+ *
33
66
  * Throws `AuthError` on any verification failure (missing/invalid/expired
34
- * token, or a malformed sub/tenant_id claim).
67
+ * token, a token with no `exp`, a not-yet-valid `nbf`, or a malformed /
68
+ * mismatched sub/tenant_id claim).
35
69
  */
36
70
  declare function authenticateRequest(session: VerifiableSession, token: string): Promise<AxiamIdentity>;
37
71
 
@@ -1,18 +1,42 @@
1
1
  import { A as AccessCheck, a as AccessDecision } from './types-BVkMoqLU.js';
2
- import { V as Verifier } from './jwks-BgojMGC5.js';
2
+ import { V as Verifier } from './jwks-DEiwxlku.js';
3
3
 
4
4
  /**
5
5
  * Minimal session shape the middleware needs: a JWKS verifier (D-11) and the
6
6
  * tenant this resource server is configured for (CR-03). JWKS is org-wide,
7
7
  * not tenant-scoped (node/jwks.ts) — `tenantHeaderValue` is what lets
8
8
  * `authenticateRequest` reject a validly-signed token minted for a
9
- * DIFFERENT tenant in the same org.
9
+ * DIFFERENT tenant in the same org (CONTRACT.md §10.1 rule 4).
10
10
  */
11
11
  interface VerifiableSession {
12
12
  /** Local JWKS verifier (D-11) — validates the token's EdDSA signature against the org-wide cached JWKS, offline on a cache hit. */
13
13
  jwksVerifier: Verifier;
14
- /** The tenant this resource server is configured for (CR-03); a validly-signed token minted for a different tenant in the same org is rejected. */
14
+ /**
15
+ * The tenant this resource server is configured for (CR-03, §10.1 rule 4);
16
+ * a validly-signed token minted for a different tenant in the same org is
17
+ * rejected.
18
+ *
19
+ * @remarks
20
+ * The claim it is compared against is the token's `tenant_id`, which is
21
+ * always a UUID — so a resource server guarding routes MUST be configured
22
+ * with `tenantId` (the UUID form), not `tenantSlug`. A slug-configured
23
+ * session can never match and therefore rejects every request; that is
24
+ * fail-closed by design, not a silent pass.
25
+ */
15
26
  tenantHeaderValue: string;
27
+ /**
28
+ * CONTRACT.md §10.1 rule 5 — expected token issuer. Optional and unset by
29
+ * default: the rule is conditional on configuration, and the SDK never
30
+ * hardcodes an issuer. When set, a token whose `iss` differs is rejected.
31
+ * Populated from `AxiamClientOptions.expectedIssuer`.
32
+ */
33
+ expectedIssuer?: string;
34
+ /**
35
+ * CONTRACT.md §10.1 rule 6 — expected token audience. Optional and unset by
36
+ * default. A resource server guarding user-facing routes SHOULD set
37
+ * `"axiam:user"`. Populated from `AxiamClientOptions.expectedAudience`.
38
+ */
39
+ expectedAudience?: string;
16
40
  }
17
41
  /** Authenticated identity injected as req.axiamUser / request.axiamUser (§10). */
18
42
  interface AxiamIdentity {
@@ -30,8 +54,18 @@ interface AxiamIdentity {
30
54
  * AXIAM's access token carries no dedicated `roles` claim server-side
31
55
  * (mirrors the Rust SDK's src/middleware/actix.rs).
32
56
  *
57
+ * This is the SDK's **documented §10 guard entry point** for TypeScript, and
58
+ * it applies the complete CONTRACT.md §10.1 minimum local-verification set:
59
+ * rules 1/2/3/5/6/7 inside `verifyAccessToken` (EdDSA `alg` pinned before key
60
+ * lookup, REQUIRED numeric `exp`, `nbf` when present, conditional `iss`/`aud`,
61
+ * a named bounded clock skew) and rule 4 — the `tenant_id` assertion — both
62
+ * there and again here, so a caller-supplied `Verifier` implementation that
63
+ * ignores its expectations still cannot get a cross-tenant token past the
64
+ * middleware.
65
+ *
33
66
  * Throws `AuthError` on any verification failure (missing/invalid/expired
34
- * token, or a malformed sub/tenant_id claim).
67
+ * token, a token with no `exp`, a not-yet-valid `nbf`, or a malformed /
68
+ * mismatched sub/tenant_id claim).
35
69
  */
36
70
  declare function authenticateRequest(session: VerifiableSession, token: string): Promise<AxiamIdentity>;
37
71
 
@@ -1,4 +1,4 @@
1
- import { S as SharedSession, A as AxiamClientOptions } from './session-BWUWhhyB.cjs';
1
+ import { S as SharedSession, A as AxiamClientOptions } from './session-ti3C9ZJU.cjs';
2
2
  import { L as LoginResult, A as AccessCheck, a as AccessDecision } from './types-BVkMoqLU.cjs';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { S as SharedSession, A as AxiamClientOptions } from './session-BWUWhhyB.js';
1
+ import { S as SharedSession, A as AxiamClientOptions } from './session-ti3C9ZJU.js';
2
2
  import { L as LoginResult, A as AccessCheck, a as AccessDecision } from './types-BVkMoqLU.js';
3
3
 
4
4
  /**
@@ -1,8 +1,8 @@
1
1
  import { CookieJar } from 'tough-cookie';
2
- import { S as SharedSession, A as AxiamClientOptions } from './session-BWUWhhyB.js';
3
- import { A as AxiamClient } from './client-Dn1fs5MH.js';
2
+ import { S as SharedSession, A as AxiamClientOptions, N as NodeTlsOptions } from './session-ti3C9ZJU.js';
3
+ import { A as AxiamClient } from './client-utwuwc9m.js';
4
4
  import { S as Sensitive } from './sensitive-BC_s7Rrd.js';
5
- import { V as Verifier } from './jwks-BgojMGC5.js';
5
+ import { V as Verifier } from './jwks-DEiwxlku.js';
6
6
  import { AxiosInstance } from 'axios';
7
7
 
8
8
  /** Tracks the access/refresh token pair for a Node session, kept in sync with the cookie jar after each REST call/refresh. */
@@ -106,12 +106,35 @@ declare const CSRF_COOKIE = "axiam_csrf";
106
106
  /** Construct a fresh, per-client-instance cookie jar (§4 — never process-global). */
107
107
  declare function createJar(): CookieJar;
108
108
  /**
109
- * Wrap an axios instance with `axios-cookiejar-support` so the jar persists
109
+ * Attach jar-aware agents to an axios instance so the jar persists
110
110
  * `Set-Cookie` responses across requests and replays them on subsequent
111
111
  * requests to the same origin/path (§4). Mutates and returns the same
112
- * instance (matches `axios-cookiejar-support`'s documented in-place wrap).
112
+ * instance.
113
+ *
114
+ * The agents are constructed HERE rather than via `axios-cookiejar-support`'s
115
+ * `wrapper()`, which used to do it. That wrapper is a thin convenience layer:
116
+ * all cookie handling lives in `http-cookie-agent`'s agents, which it builds
117
+ * for you inside a request interceptor — and that interceptor is hostile to
118
+ * any other agent. It THROWS
119
+ *
120
+ * axios-cookiejar-support does not support for use with other http(s).Agent.
121
+ *
122
+ * when it finds an `httpsAgent` it did not create, and otherwise replaces it.
123
+ * Since `createSession` attaches an `https.Agent` whenever `customCa` or a
124
+ * §6.1 client certificate is configured, the Node persona could never use
125
+ * either: with TLS material configured every request threw, and there was no
126
+ * seam to pass CA/cert/key through the wrapper's own agent construction.
127
+ *
128
+ * Building the agent ourselves closes that: ONE `HttpsCookieAgent` that is
129
+ * both jar-aware and TLS-configured. Cookie behaviour is unchanged — it is
130
+ * the same agent class the wrapper was constructing, just with the TLS
131
+ * options merged in.
132
+ *
133
+ * @param tls §6/§6.1 TLS material, or undefined for the default trust store.
134
+ * Never carries `rejectUnauthorized`: strict server verification
135
+ * is not negotiable (§6).
113
136
  */
114
- declare function wrapAxios(instance: AxiosInstance, jar: CookieJar): AxiosInstance;
137
+ declare function wrapAxios(instance: AxiosInstance, jar: CookieJar, tls?: NodeTlsOptions): AxiosInstance;
115
138
  /**
116
139
  * Read a single cookie's value out of the jar by name, for the given URL.
117
140
  * This is the ONLY token-source path (RESEARCH.md Area 3 — no JSON-body
@@ -1,8 +1,8 @@
1
1
  import { CookieJar } from 'tough-cookie';
2
- import { S as SharedSession, A as AxiamClientOptions } from './session-BWUWhhyB.cjs';
3
- import { A as AxiamClient } from './client-B_FqmZ0i.cjs';
2
+ import { S as SharedSession, A as AxiamClientOptions, N as NodeTlsOptions } from './session-ti3C9ZJU.cjs';
3
+ import { A as AxiamClient } from './client-CtT9nHQP.cjs';
4
4
  import { S as Sensitive } from './sensitive-BC_s7Rrd.cjs';
5
- import { V as Verifier } from './jwks-BgojMGC5.cjs';
5
+ import { V as Verifier } from './jwks-DEiwxlku.cjs';
6
6
  import { AxiosInstance } from 'axios';
7
7
 
8
8
  /** Tracks the access/refresh token pair for a Node session, kept in sync with the cookie jar after each REST call/refresh. */
@@ -106,12 +106,35 @@ declare const CSRF_COOKIE = "axiam_csrf";
106
106
  /** Construct a fresh, per-client-instance cookie jar (§4 — never process-global). */
107
107
  declare function createJar(): CookieJar;
108
108
  /**
109
- * Wrap an axios instance with `axios-cookiejar-support` so the jar persists
109
+ * Attach jar-aware agents to an axios instance so the jar persists
110
110
  * `Set-Cookie` responses across requests and replays them on subsequent
111
111
  * requests to the same origin/path (§4). Mutates and returns the same
112
- * instance (matches `axios-cookiejar-support`'s documented in-place wrap).
112
+ * instance.
113
+ *
114
+ * The agents are constructed HERE rather than via `axios-cookiejar-support`'s
115
+ * `wrapper()`, which used to do it. That wrapper is a thin convenience layer:
116
+ * all cookie handling lives in `http-cookie-agent`'s agents, which it builds
117
+ * for you inside a request interceptor — and that interceptor is hostile to
118
+ * any other agent. It THROWS
119
+ *
120
+ * axios-cookiejar-support does not support for use with other http(s).Agent.
121
+ *
122
+ * when it finds an `httpsAgent` it did not create, and otherwise replaces it.
123
+ * Since `createSession` attaches an `https.Agent` whenever `customCa` or a
124
+ * §6.1 client certificate is configured, the Node persona could never use
125
+ * either: with TLS material configured every request threw, and there was no
126
+ * seam to pass CA/cert/key through the wrapper's own agent construction.
127
+ *
128
+ * Building the agent ourselves closes that: ONE `HttpsCookieAgent` that is
129
+ * both jar-aware and TLS-configured. Cookie behaviour is unchanged — it is
130
+ * the same agent class the wrapper was constructing, just with the TLS
131
+ * options merged in.
132
+ *
133
+ * @param tls §6/§6.1 TLS material, or undefined for the default trust store.
134
+ * Never carries `rejectUnauthorized`: strict server verification
135
+ * is not negotiable (§6).
113
136
  */
114
- declare function wrapAxios(instance: AxiosInstance, jar: CookieJar): AxiosInstance;
137
+ declare function wrapAxios(instance: AxiosInstance, jar: CookieJar, tls?: NodeTlsOptions): AxiosInstance;
115
138
  /**
116
139
  * Read a single cookie's value out of the jar by name, for the given URL.
117
140
  * This is the ONLY token-source path (RESEARCH.md Area 3 — no JSON-body
@@ -1,13 +1,13 @@
1
1
  import * as grpc from '@grpc/grpc-js';
2
2
  import { Interceptor } from '@grpc/grpc-js';
3
- import { N as NodeSession } from '../cookieJar-BTDnjjbL.cjs';
4
- export { A as ACCESS_COOKIE, C as CSRF_COOKIE, R as REFRESH_COOKIE, T as TokenManager, c as createJar, a as createNodeClient, b as createNodeSession, e as extractCookieValue, w as wrapAxios } from '../cookieJar-BTDnjjbL.cjs';
3
+ import { N as NodeSession } from '../cookieJar-DeJKczxD.cjs';
4
+ export { A as ACCESS_COOKIE, C as CSRF_COOKIE, R as REFRESH_COOKIE, T as TokenManager, c as createJar, a as createNodeClient, b as createNodeSession, e as extractCookieValue, w as wrapAxios } from '../cookieJar-DeJKczxD.cjs';
5
5
  import { a as AccessDecision } from '../types-BVkMoqLU.cjs';
6
- export { A as AxiamClaims, J as JWKS_PATH, V as Verifier, f as createVerifier } from '../jwks-BgojMGC5.cjs';
6
+ export { a as AxiamClaims, J as JWKS_PATH, V as Verifier, h as createVerifier } from '../jwks-DEiwxlku.cjs';
7
7
  import 'tough-cookie';
8
- import '../session-BWUWhhyB.cjs';
8
+ import '../session-ti3C9ZJU.cjs';
9
9
  import 'axios';
10
- import '../client-B_FqmZ0i.cjs';
10
+ import '../client-CtT9nHQP.cjs';
11
11
  import '../sensitive-BC_s7Rrd.cjs';
12
12
 
13
13
  /**
@@ -1,13 +1,13 @@
1
1
  import * as grpc from '@grpc/grpc-js';
2
2
  import { Interceptor } from '@grpc/grpc-js';
3
- import { N as NodeSession } from '../cookieJar-Cl8Lq9dL.js';
4
- export { A as ACCESS_COOKIE, C as CSRF_COOKIE, R as REFRESH_COOKIE, T as TokenManager, c as createJar, a as createNodeClient, b as createNodeSession, e as extractCookieValue, w as wrapAxios } from '../cookieJar-Cl8Lq9dL.js';
3
+ import { N as NodeSession } from '../cookieJar-C9fqLqbh.js';
4
+ export { A as ACCESS_COOKIE, C as CSRF_COOKIE, R as REFRESH_COOKIE, T as TokenManager, c as createJar, a as createNodeClient, b as createNodeSession, e as extractCookieValue, w as wrapAxios } from '../cookieJar-C9fqLqbh.js';
5
5
  import { a as AccessDecision } from '../types-BVkMoqLU.js';
6
- export { A as AxiamClaims, J as JWKS_PATH, V as Verifier, f as createVerifier } from '../jwks-BgojMGC5.js';
6
+ export { a as AxiamClaims, J as JWKS_PATH, V as Verifier, h as createVerifier } from '../jwks-DEiwxlku.js';
7
7
  import 'tough-cookie';
8
- import '../session-BWUWhhyB.js';
8
+ import '../session-ti3C9ZJU.js';
9
9
  import 'axios';
10
- import '../client-Dn1fs5MH.js';
10
+ import '../client-utwuwc9m.js';
11
11
  import '../sensitive-BC_s7Rrd.js';
12
12
 
13
13
  /**
@@ -3,7 +3,7 @@
3
3
  var grpc2 = require('@grpc/grpc-js');
4
4
  var axios = require('axios');
5
5
  var toughCookie = require('tough-cookie');
6
- var axiosCookiejarSupport = require('axios-cookiejar-support');
6
+ var http = require('http-cookie-agent/http');
7
7
  var crypto = require('crypto');
8
8
 
9
9
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -537,6 +537,10 @@ var SharedSession = class {
537
537
  orgId;
538
538
  /** Configured organization slug (`AxiamClientOptions.orgSlug`), if supplied (§5). */
539
539
  orgSlug;
540
+ /** Expected `iss` for locally-verified access tokens (§10.1 rule 5), if configured; `undefined` means no issuer check. */
541
+ expectedIssuer;
542
+ /** Expected `aud` for locally-verified access tokens (§10.1 rule 6), if configured; `undefined` means no audience check. */
543
+ expectedAudience;
540
544
  /**
541
545
  * Resolved tenant UUID used to build the `refresh` body (`RefreshRequest`
542
546
  * requires the UUID form, not a slug). Seeded from `orgId`/`tenantId` config
@@ -574,6 +578,8 @@ var SharedSession = class {
574
578
  this.tenantSlug = options.tenantSlug;
575
579
  this.orgId = options.orgId;
576
580
  this.orgSlug = options.orgSlug;
581
+ this.expectedIssuer = options.expectedIssuer;
582
+ this.expectedAudience = options.expectedAudience;
577
583
  this.resolvedTenantId = options.tenantId;
578
584
  this.resolvedOrgId = options.orgId;
579
585
  this.refreshGuard = createRefreshGuard();
@@ -652,7 +658,20 @@ function resolveTenantHeaderValue(options) {
652
658
  "AxiamClient construction requires a tenant: provide either tenantSlug or tenantId (CONTRACT.md \xA75)."
653
659
  );
654
660
  }
655
- function maybeBuildHttpsAgent(customCa, identity) {
661
+ function loadNodeHttps() {
662
+ const getBuiltinModule = process.getBuiltinModule;
663
+ if (typeof getBuiltinModule === "function") {
664
+ return getBuiltinModule.call(process, "node:https");
665
+ }
666
+ try {
667
+ return __require("https");
668
+ } catch {
669
+ throw new Error(
670
+ `customCa and clientCert require Node's https module, which this ESM build cannot load on Node ${process.version}: process.getBuiltinModule is unavailable (added in Node 20.16 / 22.3) and \`require\` does not exist in an ES module. Upgrade Node to >= 20.16, or load the CommonJS build (CONTRACT.md \xA76 / \xA76.1).`
671
+ );
672
+ }
673
+ }
674
+ function tlsOptionsFrom(customCa, identity) {
656
675
  if (!customCa) {
657
676
  if (!identity) {
658
677
  return void 0;
@@ -662,15 +681,24 @@ function maybeBuildHttpsAgent(customCa, identity) {
662
681
  'customCa must be a PEM-encoded certificate (expected to contain "-----BEGIN CERTIFICATE-----") (CONTRACT.md \xA76).'
663
682
  );
664
683
  }
684
+ return {
685
+ ...customCa ? { ca: customCa } : {},
686
+ ...identity ? { cert: identity.cert, key: identity.key.expose() } : {}
687
+ };
688
+ }
689
+ function resolveNodeTlsOptions(options) {
690
+ return tlsOptionsFrom(options.customCa, resolveClientIdentity(options));
691
+ }
692
+ function maybeBuildHttpsAgent(customCa, identity) {
693
+ const tls = tlsOptionsFrom(customCa, identity);
694
+ if (!tls) {
695
+ return void 0;
696
+ }
665
697
  if (typeof process === "undefined") {
666
698
  return void 0;
667
699
  }
668
- const https = __require("https");
669
- return new https.Agent({
670
- ...customCa ? { ca: customCa } : {},
671
- // rejectUnauthorized is intentionally left at its secure default (true).
672
- ...identity ? { cert: identity.cert, key: identity.key.expose() } : {}
673
- });
700
+ const https = loadNodeHttps();
701
+ return new https.Agent(tls);
674
702
  }
675
703
  function createSession(options) {
676
704
  const tenantHeaderValue = resolveTenantHeaderValue(options);
@@ -993,10 +1021,11 @@ var CSRF_COOKIE = "axiam_csrf";
993
1021
  function createJar() {
994
1022
  return new toughCookie.CookieJar();
995
1023
  }
996
- function wrapAxios(instance, jar) {
997
- const wrapped = axiosCookiejarSupport.wrapper(instance);
998
- wrapped.defaults.jar = jar;
999
- return wrapped;
1024
+ function wrapAxios(instance, jar, tls) {
1025
+ const cookies = { jar };
1026
+ instance.defaults.httpAgent = new http.HttpCookieAgent({ cookies });
1027
+ instance.defaults.httpsAgent = new http.HttpsCookieAgent({ cookies, ...tls ?? {} });
1028
+ return instance;
1000
1029
  }
1001
1030
  async function extractCookieValue(jar, url, name) {
1002
1031
  const cookies = await jar.getCookies(url);
@@ -1166,6 +1195,7 @@ function checkIdTokenClaims(claims, expectations, nowSec = Math.floor(Date.now()
1166
1195
  var JWKS_PATH = "/oauth2/jwks";
1167
1196
  var COOLDOWN_DURATION_MS = 6e4;
1168
1197
  var TIMEOUT_DURATION_MS = 5e3;
1198
+ var CLOCK_SKEW_LEEWAY_SEC = 60;
1169
1199
  function createVerifier(baseUrl) {
1170
1200
  return createJwksVerifier(`${baseUrl}${JWKS_PATH}`);
1171
1201
  }
@@ -1183,7 +1213,20 @@ function createJwksVerifier(jwksUri) {
1183
1213
  return jwksPromise;
1184
1214
  }
1185
1215
  return {
1186
- async verifyAccessToken(token) {
1216
+ async verifyAccessToken(token, expectations) {
1217
+ const { jwtVerify } = await import('jose');
1218
+ const jwks = await getJwks();
1219
+ const { payload } = await jwtVerify(token, jwks, {
1220
+ algorithms: ["EdDSA"],
1221
+ requiredClaims: ["exp"],
1222
+ clockTolerance: CLOCK_SKEW_LEEWAY_SEC,
1223
+ ...expectations.expectedIssuer !== void 0 ? { issuer: expectations.expectedIssuer } : {},
1224
+ ...expectations.expectedAudience !== void 0 ? { audience: expectations.expectedAudience } : {}
1225
+ });
1226
+ assertTenantClaim(payload.tenant_id, expectations.expectedTenantId);
1227
+ return payload;
1228
+ },
1229
+ async verifySignatureOnlyUnchecked(token) {
1187
1230
  const { jwtVerify } = await import('jose');
1188
1231
  const jwks = await getJwks();
1189
1232
  const { payload } = await jwtVerify(token, jwks, { algorithms: ["EdDSA"] });
@@ -1217,6 +1260,30 @@ function createJwksVerifier(jwksUri) {
1217
1260
  }
1218
1261
  };
1219
1262
  }
1263
+ function assertTenantClaim(claim, expected) {
1264
+ if (typeof expected !== "string" || expected === "") {
1265
+ throw new AuthError(
1266
+ "no configured tenant to verify the token against; refusing the request (CONTRACT.md \xA710.1 rule 4 fails closed)"
1267
+ );
1268
+ }
1269
+ if (typeof claim !== "string" || claim === "") {
1270
+ throw new AuthError("invalid tenant_id claim");
1271
+ }
1272
+ if (claim !== expected) {
1273
+ warnOnceIfComparandLooksLikeASlug(claim, expected);
1274
+ throw new AuthError("token tenant_id does not match configured tenant");
1275
+ }
1276
+ }
1277
+ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1278
+ var slugComparandWarned = false;
1279
+ function warnOnceIfComparandLooksLikeASlug(claim, expected) {
1280
+ if (slugComparandWarned) return;
1281
+ if (!UUID_RE.test(claim) || UUID_RE.test(expected)) return;
1282
+ slugComparandWarned = true;
1283
+ console.warn(
1284
+ `AXIAM: the tenant this guard was configured with ("${expected}") is not a UUID, but access tokens carry the tenant UUID in their \`tenant_id\` claim, so this guard will reject every request. Configure it with the tenant UUID, not the slug. (CONTRACT.md \xA710.1 rule 4; logged once per process, and it does not affect the rejection itself.)`
1285
+ );
1286
+ }
1220
1287
  function mapJoseVerifyError(err) {
1221
1288
  const code = typeof err === "object" && err !== null && "code" in err ? String(err.code) : "";
1222
1289
  switch (code) {
@@ -1294,7 +1361,7 @@ var NodeSession = class extends SharedSession {
1294
1361
  function createNodeSession(options) {
1295
1362
  const base = createSession(options);
1296
1363
  const jar = createJar();
1297
- wrapAxios(base.axios, jar);
1364
+ wrapAxios(base.axios, jar, resolveNodeTlsOptions(options));
1298
1365
  const tokenManager = new TokenManager(jar, options.baseUrl, base.tenantHeaderValue);
1299
1366
  const jwksVerifier = createVerifier(options.baseUrl);
1300
1367
  return new NodeSession(options, base, tokenManager, jwksVerifier, jar);