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
@@ -1,7 +1,7 @@
1
1
  import * as grpc2 from '@grpc/grpc-js';
2
2
  import axios from 'axios';
3
3
  import { CookieJar } from 'tough-cookie';
4
- import { wrapper } from 'axios-cookiejar-support';
4
+ import { HttpCookieAgent, HttpsCookieAgent } from 'http-cookie-agent/http';
5
5
  import { timingSafeEqual } from 'crypto';
6
6
 
7
7
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
@@ -512,6 +512,10 @@ var SharedSession = class {
512
512
  orgId;
513
513
  /** Configured organization slug (`AxiamClientOptions.orgSlug`), if supplied (§5). */
514
514
  orgSlug;
515
+ /** Expected `iss` for locally-verified access tokens (§10.1 rule 5), if configured; `undefined` means no issuer check. */
516
+ expectedIssuer;
517
+ /** Expected `aud` for locally-verified access tokens (§10.1 rule 6), if configured; `undefined` means no audience check. */
518
+ expectedAudience;
515
519
  /**
516
520
  * Resolved tenant UUID used to build the `refresh` body (`RefreshRequest`
517
521
  * requires the UUID form, not a slug). Seeded from `orgId`/`tenantId` config
@@ -549,6 +553,8 @@ var SharedSession = class {
549
553
  this.tenantSlug = options.tenantSlug;
550
554
  this.orgId = options.orgId;
551
555
  this.orgSlug = options.orgSlug;
556
+ this.expectedIssuer = options.expectedIssuer;
557
+ this.expectedAudience = options.expectedAudience;
552
558
  this.resolvedTenantId = options.tenantId;
553
559
  this.resolvedOrgId = options.orgId;
554
560
  this.refreshGuard = createRefreshGuard();
@@ -627,7 +633,20 @@ function resolveTenantHeaderValue(options) {
627
633
  "AxiamClient construction requires a tenant: provide either tenantSlug or tenantId (CONTRACT.md \xA75)."
628
634
  );
629
635
  }
630
- function maybeBuildHttpsAgent(customCa, identity) {
636
+ function loadNodeHttps() {
637
+ const getBuiltinModule = process.getBuiltinModule;
638
+ if (typeof getBuiltinModule === "function") {
639
+ return getBuiltinModule.call(process, "node:https");
640
+ }
641
+ try {
642
+ return __require("https");
643
+ } catch {
644
+ throw new Error(
645
+ `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).`
646
+ );
647
+ }
648
+ }
649
+ function tlsOptionsFrom(customCa, identity) {
631
650
  if (!customCa) {
632
651
  if (!identity) {
633
652
  return void 0;
@@ -637,15 +656,24 @@ function maybeBuildHttpsAgent(customCa, identity) {
637
656
  'customCa must be a PEM-encoded certificate (expected to contain "-----BEGIN CERTIFICATE-----") (CONTRACT.md \xA76).'
638
657
  );
639
658
  }
659
+ return {
660
+ ...customCa ? { ca: customCa } : {},
661
+ ...identity ? { cert: identity.cert, key: identity.key.expose() } : {}
662
+ };
663
+ }
664
+ function resolveNodeTlsOptions(options) {
665
+ return tlsOptionsFrom(options.customCa, resolveClientIdentity(options));
666
+ }
667
+ function maybeBuildHttpsAgent(customCa, identity) {
668
+ const tls = tlsOptionsFrom(customCa, identity);
669
+ if (!tls) {
670
+ return void 0;
671
+ }
640
672
  if (typeof process === "undefined") {
641
673
  return void 0;
642
674
  }
643
- const https = __require("https");
644
- return new https.Agent({
645
- ...customCa ? { ca: customCa } : {},
646
- // rejectUnauthorized is intentionally left at its secure default (true).
647
- ...identity ? { cert: identity.cert, key: identity.key.expose() } : {}
648
- });
675
+ const https = loadNodeHttps();
676
+ return new https.Agent(tls);
649
677
  }
650
678
  function createSession(options) {
651
679
  const tenantHeaderValue = resolveTenantHeaderValue(options);
@@ -968,10 +996,11 @@ var CSRF_COOKIE = "axiam_csrf";
968
996
  function createJar() {
969
997
  return new CookieJar();
970
998
  }
971
- function wrapAxios(instance, jar) {
972
- const wrapped = wrapper(instance);
973
- wrapped.defaults.jar = jar;
974
- return wrapped;
999
+ function wrapAxios(instance, jar, tls) {
1000
+ const cookies = { jar };
1001
+ instance.defaults.httpAgent = new HttpCookieAgent({ cookies });
1002
+ instance.defaults.httpsAgent = new HttpsCookieAgent({ cookies, ...tls ?? {} });
1003
+ return instance;
975
1004
  }
976
1005
  async function extractCookieValue(jar, url, name) {
977
1006
  const cookies = await jar.getCookies(url);
@@ -1141,6 +1170,7 @@ function checkIdTokenClaims(claims, expectations, nowSec = Math.floor(Date.now()
1141
1170
  var JWKS_PATH = "/oauth2/jwks";
1142
1171
  var COOLDOWN_DURATION_MS = 6e4;
1143
1172
  var TIMEOUT_DURATION_MS = 5e3;
1173
+ var CLOCK_SKEW_LEEWAY_SEC = 60;
1144
1174
  function createVerifier(baseUrl) {
1145
1175
  return createJwksVerifier(`${baseUrl}${JWKS_PATH}`);
1146
1176
  }
@@ -1158,7 +1188,20 @@ function createJwksVerifier(jwksUri) {
1158
1188
  return jwksPromise;
1159
1189
  }
1160
1190
  return {
1161
- async verifyAccessToken(token) {
1191
+ async verifyAccessToken(token, expectations) {
1192
+ const { jwtVerify } = await import('jose');
1193
+ const jwks = await getJwks();
1194
+ const { payload } = await jwtVerify(token, jwks, {
1195
+ algorithms: ["EdDSA"],
1196
+ requiredClaims: ["exp"],
1197
+ clockTolerance: CLOCK_SKEW_LEEWAY_SEC,
1198
+ ...expectations.expectedIssuer !== void 0 ? { issuer: expectations.expectedIssuer } : {},
1199
+ ...expectations.expectedAudience !== void 0 ? { audience: expectations.expectedAudience } : {}
1200
+ });
1201
+ assertTenantClaim(payload.tenant_id, expectations.expectedTenantId);
1202
+ return payload;
1203
+ },
1204
+ async verifySignatureOnlyUnchecked(token) {
1162
1205
  const { jwtVerify } = await import('jose');
1163
1206
  const jwks = await getJwks();
1164
1207
  const { payload } = await jwtVerify(token, jwks, { algorithms: ["EdDSA"] });
@@ -1192,6 +1235,30 @@ function createJwksVerifier(jwksUri) {
1192
1235
  }
1193
1236
  };
1194
1237
  }
1238
+ function assertTenantClaim(claim, expected) {
1239
+ if (typeof expected !== "string" || expected === "") {
1240
+ throw new AuthError(
1241
+ "no configured tenant to verify the token against; refusing the request (CONTRACT.md \xA710.1 rule 4 fails closed)"
1242
+ );
1243
+ }
1244
+ if (typeof claim !== "string" || claim === "") {
1245
+ throw new AuthError("invalid tenant_id claim");
1246
+ }
1247
+ if (claim !== expected) {
1248
+ warnOnceIfComparandLooksLikeASlug(claim, expected);
1249
+ throw new AuthError("token tenant_id does not match configured tenant");
1250
+ }
1251
+ }
1252
+ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1253
+ var slugComparandWarned = false;
1254
+ function warnOnceIfComparandLooksLikeASlug(claim, expected) {
1255
+ if (slugComparandWarned) return;
1256
+ if (!UUID_RE.test(claim) || UUID_RE.test(expected)) return;
1257
+ slugComparandWarned = true;
1258
+ console.warn(
1259
+ `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.)`
1260
+ );
1261
+ }
1195
1262
  function mapJoseVerifyError(err) {
1196
1263
  const code = typeof err === "object" && err !== null && "code" in err ? String(err.code) : "";
1197
1264
  switch (code) {
@@ -1269,7 +1336,7 @@ var NodeSession = class extends SharedSession {
1269
1336
  function createNodeSession(options) {
1270
1337
  const base = createSession(options);
1271
1338
  const jar = createJar();
1272
- wrapAxios(base.axios, jar);
1339
+ wrapAxios(base.axios, jar, resolveNodeTlsOptions(options));
1273
1340
  const tokenManager = new TokenManager(jar, options.baseUrl, base.tenantHeaderValue);
1274
1341
  const jwksVerifier = createVerifier(options.baseUrl);
1275
1342
  return new NodeSession(options, base, tokenManager, jwksVerifier, jar);