axiam-sdk 1.1.0 → 1.1.2

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 (60) hide show
  1. package/README.md +27 -2
  2. package/dist/amqp/index.d.cts +3 -2
  3. package/dist/amqp/index.d.ts +3 -2
  4. package/dist/{authzCore-BQfX9qxN.d.cts → authzCore-CqXzLNmT.d.cts} +4 -3
  5. package/dist/{authzCore-BlSHwGnW.d.ts → authzCore-D-hquWSI.d.ts} +4 -3
  6. package/dist/browser/index.d.cts +8 -7
  7. package/dist/browser/index.d.ts +8 -7
  8. package/dist/{client-7ZKtfXW-.d.cts → client-BGFn1VQh.d.cts} +34 -24
  9. package/dist/{client-Putxo-yi.d.ts → client-DrQZZ1js.d.ts} +34 -24
  10. package/dist/{cookieJar-Cw6Zdeec.d.ts → cookieJar-BTmpjXZe.d.ts} +9 -3
  11. package/dist/{cookieJar-DkGcIr-i.d.cts → cookieJar-BqYOnNN-.d.cts} +9 -3
  12. package/dist/{errors-DMIlw2lN.d.ts → errors-DZ3k8a8i.d.cts} +2 -1
  13. package/dist/{errors-DMIlw2lN.d.cts → errors-DZ3k8a8i.d.ts} +2 -1
  14. package/dist/{errors-VpViVRSx.d.ts → errors-RvGlTyUj.d.cts} +3 -2
  15. package/dist/{errors-CtP_lviy.d.cts → errors-dlGXAsbh.d.ts} +3 -2
  16. package/dist/grpc/index.d.cts +10 -9
  17. package/dist/grpc/index.d.ts +10 -9
  18. package/dist/grpc/index.js +68 -7
  19. package/dist/grpc/index.js.map +1 -1
  20. package/dist/grpc/index.mjs +68 -7
  21. package/dist/grpc/index.mjs.map +1 -1
  22. package/dist/index.d.cts +6 -6
  23. package/dist/index.d.ts +6 -6
  24. package/dist/index.js +60 -7
  25. package/dist/index.js.map +1 -1
  26. package/dist/index.mjs +60 -7
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/{jwks-BR55d7-Z.d.cts → jwks-CTVpOWzI.d.cts} +2 -1
  29. package/dist/{jwks-BR55d7-Z.d.ts → jwks-CTVpOWzI.d.ts} +2 -1
  30. package/dist/middleware/index.d.cts +13 -12
  31. package/dist/middleware/index.d.ts +13 -12
  32. package/dist/middleware/index.js +176 -31
  33. package/dist/middleware/index.js.map +1 -1
  34. package/dist/middleware/index.mjs +176 -31
  35. package/dist/middleware/index.mjs.map +1 -1
  36. package/dist/nestjs/index.d.cts +5 -4
  37. package/dist/nestjs/index.d.ts +5 -4
  38. package/dist/node/index.d.cts +10 -9
  39. package/dist/node/index.d.ts +10 -9
  40. package/dist/node/index.js +215 -29
  41. package/dist/node/index.js.map +1 -1
  42. package/dist/node/index.mjs +215 -29
  43. package/dist/node/index.mjs.map +1 -1
  44. package/dist/{oidcState-Cz6erz0g.d.cts → oidcState-BaJ-SM_R.d.cts} +41 -9
  45. package/dist/{oidcState-zGt6VU6v.d.ts → oidcState-C3VLn3eD.d.ts} +41 -9
  46. package/dist/rest/index.d.cts +10 -9
  47. package/dist/rest/index.d.ts +10 -9
  48. package/dist/rest/index.js +60 -7
  49. package/dist/rest/index.js.map +1 -1
  50. package/dist/rest/index.mjs +60 -7
  51. package/dist/rest/index.mjs.map +1 -1
  52. package/dist/{revocationFeed-CDoD7Twr.d.cts → revocationFeed-KQhvMMl8.d.cts} +2 -1
  53. package/dist/{revocationFeed-CDoD7Twr.d.ts → revocationFeed-KQhvMMl8.d.ts} +2 -1
  54. package/dist/{session-CeG6P9GO.d.ts → session-B03NsqVs.d.ts} +19 -2
  55. package/dist/{session-BmjEMowX.d.cts → session-plDr4lFu.d.cts} +19 -2
  56. package/dist/{telemetry--0DwnNjV.d.cts → telemetry-Du0-zS5f.d.cts} +2 -1
  57. package/dist/{telemetry--0DwnNjV.d.ts → telemetry-Du0-zS5f.d.ts} +2 -1
  58. package/dist/{webauthnErrors-fLgfOflO.d.cts → webauthnErrors-m1LZiaRy.d.cts} +2 -1
  59. package/dist/{webauthnErrors-fLgfOflO.d.ts → webauthnErrors-m1LZiaRy.d.ts} +2 -1
  60. package/package.json +2 -2
@@ -675,6 +675,24 @@ var SharedSession = class {
675
675
  noCredentialsConfig() {
676
676
  return { withCredentials: false };
677
677
  }
678
+ /**
679
+ * Axios config for a request to an `/oauth2/*` endpoint (CONTRACT.md §12.1
680
+ * rule 3, §14.6; C163-12): {@link noCredentialsConfig} and, in the browser
681
+ * persona, the fetch adapter with `credentials: 'omit'`.
682
+ *
683
+ * `withCredentials: false` on axios's default XHR adapter is not enough: that
684
+ * adapter sends a same-origin cookie regardless, so an app served from the
685
+ * AXIAM origin would still present `axiam_*` on a token or device request.
686
+ * The fetch adapter derives its `credentials` from `withCredentials: false`
687
+ * (`'omit'`); `fetchOptions.credentials` is set as well for adapters that
688
+ * read it.
689
+ * `NodeSession` overrides this to {@link noCredentialsConfig}: its jar-free
690
+ * agent pair is what keeps the cookies off there, and the fetch adapter
691
+ * would bypass that pair.
692
+ */
693
+ oauth2RequestConfig() {
694
+ return { ...this.noCredentialsConfig(), adapter: "fetch", fetchOptions: { credentials: "omit" } };
695
+ }
678
696
  };
679
697
  function resolveTenantHeaderValue(options) {
680
698
  if (options.tenantSlug) {
@@ -796,6 +814,9 @@ function installCsrfInterceptor(axiosInstance, session) {
796
814
  if (session.isForeignHost(config.url)) {
797
815
  return config;
798
816
  }
817
+ if (isOAuth2Endpoint(config.url, session.baseUrl)) {
818
+ return config;
819
+ }
799
820
  const method = (config.method ?? "get").toLowerCase();
800
821
  const cookieString = typeof document !== "undefined" ? document.cookie : "";
801
822
  const csrfToken = typeof document !== "undefined" ? csrfHeaderForMethod(method, cookieString) : csrfHeaderForMethod(method, session.csrfToken ? `axiam_csrf=${session.csrfToken}` : "");
@@ -849,23 +870,33 @@ function installRefreshInterceptor(axiosInstance, session) {
849
870
  }
850
871
  );
851
872
  }
852
- function isOAuth2Endpoint(url) {
873
+ function isOAuth2Endpoint(url, baseUrl) {
853
874
  if (!url) {
854
875
  return false;
855
876
  }
856
- const path = url.split(/[?#]/, 1)[0] ?? "";
857
- return path.includes("/oauth2/");
877
+ try {
878
+ const base = new URL(baseUrl);
879
+ let path = new URL(url, base).pathname;
880
+ const prefix = base.pathname.replace(/\/+$/, "");
881
+ if (prefix !== "" && path.startsWith(`${prefix}/`)) {
882
+ path = path.slice(prefix.length);
883
+ }
884
+ return path.startsWith("/oauth2/");
885
+ } catch {
886
+ return false;
887
+ }
858
888
  }
859
889
  function installDeviceTokenInterceptor(axiosInstance, session) {
860
890
  axiosInstance.interceptors.request.use((config) => {
861
891
  const deviceToken = session.deviceAccessToken;
862
- if (session.isForeignHost(config.url) || deviceToken === void 0) {
892
+ const oauth2 = isOAuth2Endpoint(config.url, session.baseUrl);
893
+ if (session.isForeignHost(config.url) || deviceToken === void 0 && !oauth2) {
863
894
  return config;
864
895
  }
865
- const noCred = session.noCredentialsConfig();
896
+ const noCred = oauth2 ? session.oauth2RequestConfig() : session.noCredentialsConfig();
866
897
  Object.assign(config, noCred);
867
898
  config.headers = config.headers ?? {};
868
- if (isOAuth2Endpoint(config.url)) {
899
+ if (oauth2) {
869
900
  return config;
870
901
  }
871
902
  config.headers["Authorization"] = `Bearer ${deviceToken.expose()}`;
@@ -1356,6 +1387,7 @@ async function withRetry(fn, options) {
1356
1387
  }
1357
1388
  const retryAfterMs2 = isRetryAfterCarrier(err) ? err.retryAfterMs : void 0;
1358
1389
  const delay = delayMs(attempt, retryAfterMs2, random());
1390
+ options.admit?.(delay);
1359
1391
  options.telemetry?.emit({
1360
1392
  type: "retry",
1361
1393
  operation: options.operation ?? "unknown",
@@ -1885,7 +1917,10 @@ async function bareRequest(session, operation, config) {
1885
1917
  // jar). Under the Node persona this is the jar-wrapped cookie agent, which
1886
1918
  // `noCredentialsConfig()` below replaces with a plain one.
1887
1919
  ...defaults.httpsAgent !== void 0 ? { httpsAgent: defaults.httpsAgent } : {},
1888
- ...session.noCredentialsConfig(),
1920
+ // The bare transport carries the RFC 7592 registration calls on `/oauth2/register/*`,
1921
+ // so it gets an `/oauth2/*` request's config: in the browser persona the fetch adapter
1922
+ // that omits credentials (C164-06; identical to `noCredentialsConfig()` under Node).
1923
+ ...session.oauth2RequestConfig(),
1889
1924
  withCredentials: false,
1890
1925
  maxRedirects: 0,
1891
1926
  validateStatus: () => true
@@ -2745,6 +2780,11 @@ function validateNetwork(network, problems) {
2745
2780
  problems.push(`network segment ${q(profile.segment)} has more than one profile in the manifest`);
2746
2781
  }
2747
2782
  profiled.add(profile.segment);
2783
+ if (profile.terminationAction === null) {
2784
+ problems.push(
2785
+ `network profile of segment ${q(profile.segment)} states terminationAction as null; it has no "none" in a manifest (leave it out to keep the server default)`
2786
+ );
2787
+ }
2748
2788
  }
2749
2789
  }
2750
2790
  function duplicates(kind, keys, problems) {
@@ -3702,11 +3742,24 @@ function profileDrifted(spec, read) {
3702
3742
  if (spec.serviceType !== void 0 && !sameOptional(spec.serviceType, read.service_type)) return true;
3703
3743
  return false;
3704
3744
  }
3745
+ var KNOWN_TERMINATION_ACTIONS = ["default", "radius_request"];
3746
+ var KNOWN_SERVICE_TYPES = ["framed_user"];
3747
+ function refuseUnknownCarried(member, stated, read, known) {
3748
+ if (stated !== void 0 || read == null || known.includes(read)) return;
3749
+ throw new ValidationError(
3750
+ "manifest.plan",
3751
+ 400,
3752
+ `network profile: ${member} was read as ${JSON.stringify(read)}, a value this SDK does not know, and the manifest does not state it; state ${member} to update this profile (CONTRACT.md \xA727.6.2 item 4)`,
3753
+ [{ field: member, message: `unknown value ${JSON.stringify(read)} on an unstated member` }]
3754
+ );
3755
+ }
3705
3756
  function profileReplaceInput(spec, read) {
3706
3757
  const profile = {
3707
3758
  dictionary: read.dictionary,
3708
3759
  session_timeout_secs: spec.sessionTimeoutSecs
3709
3760
  };
3761
+ refuseUnknownCarried("termination_action", spec.terminationAction, read.termination_action, KNOWN_TERMINATION_ACTIONS);
3762
+ refuseUnknownCarried("service_type", spec.serviceType, read.service_type, KNOWN_SERVICE_TYPES);
3710
3763
  const termination = spec.terminationAction === void 0 ? read.termination_action : spec.terminationAction;
3711
3764
  if (termination != null) profile.termination_action = termination;
3712
3765
  const idle = spec.idleTimeoutSecs === void 0 ? read.idle_timeout_secs : spec.idleTimeoutSecs;
@@ -8521,6 +8574,14 @@ var NodeSession = class extends SharedSession {
8521
8574
  withCredentials: false
8522
8575
  };
8523
8576
  }
8577
+ /**
8578
+ * Overrides {@link SharedSession.oauth2RequestConfig}: under Node the
8579
+ * jar-free agent pair of {@link noCredentialsConfig} is what withholds the
8580
+ * cookies; the browser's fetch adapter (`credentials: 'omit'`) is not used.
8581
+ */
8582
+ oauth2RequestConfig() {
8583
+ return this.noCredentialsConfig();
8584
+ }
8524
8585
  /**
8525
8586
  * Drives the actual `POST /api/v1/auth/refresh` HTTP call. Passed to this
8526
8587
  * session's per-instance `refreshGuard` (inherited from SharedSession) by
@@ -8917,6 +8978,8 @@ var MAX_LOGOUT_TOKEN_AGE_SECS = 300;
8917
8978
  var PollSchedule = class {
8918
8979
  #intervalSecs;
8919
8980
  #remainingSecs;
8981
+ /** A `Retry-After` still to be served by the next wait (§14.2 rule 9, contract 1.64). */
8982
+ #retryAfterSecs = 0;
8920
8983
  constructor(intervalSecs, expiresInSecs) {
8921
8984
  this.#intervalSecs = intervalSecs > 0 ? intervalSecs : DEFAULT_POLL_INTERVAL_SECS;
8922
8985
  this.#remainingSecs = expiresInSecs;
@@ -8925,6 +8988,21 @@ var PollSchedule = class {
8925
8988
  get intervalSecs() {
8926
8989
  return this.#intervalSecs;
8927
8990
  }
8991
+ /**
8992
+ * The delay before the next poll, in seconds: the interval, or the pending
8993
+ * `Retry-After` when that is longer (a minimum, §14.2 rule 9).
8994
+ */
8995
+ get waitSecs() {
8996
+ return Math.max(this.#intervalSecs, this.#retryAfterSecs);
8997
+ }
8998
+ /**
8999
+ * Record a `429 rate_limit_exceeded` (§14.2 rule 9, contract 1.64): the next
9000
+ * wait lasts at least `retryAfterSecs` and stands in for one interval. The
9001
+ * interval itself is **not** raised — only the `400 slow_down` does that.
9002
+ */
9003
+ rateLimited(retryAfterSecs) {
9004
+ this.#retryAfterSecs = retryAfterSecs !== void 0 && retryAfterSecs > 0 ? retryAfterSecs : 0;
9005
+ }
8928
9006
  /** Apply one `slow_down` (§14.2 rule 1): **cumulative, never reset.** */
8929
9007
  slowDown() {
8930
9008
  this.#intervalSecs += SLOW_DOWN_INCREMENT_SECS;
@@ -8937,14 +9015,27 @@ var PollSchedule = class {
8937
9015
  * the server is still answering `authorization_pending`.
8938
9016
  */
8939
9017
  tick() {
8940
- if (this.#intervalSecs >= this.#remainingSecs) {
9018
+ const waitSecs = this.waitSecs;
9019
+ this.#retryAfterSecs = 0;
9020
+ if (waitSecs >= this.#remainingSecs) {
8941
9021
  this.#remainingSecs = 0;
8942
9022
  return false;
8943
9023
  }
8944
- this.#remainingSecs -= this.#intervalSecs;
9024
+ this.#remainingSecs -= waitSecs;
8945
9025
  return true;
8946
9026
  }
8947
9027
  };
9028
+ var POLL_RETRY_AFTER_MS = /* @__PURE__ */ new WeakMap();
9029
+ function pollRateLimit(err) {
9030
+ if (axiosStatus3(err) !== 429) return void 0;
9031
+ const body = axiosBody(err);
9032
+ const description = body !== null && typeof body === "object" && typeof body.error_description === "string" ? body.error_description : "";
9033
+ const limited = new OAuthProtocolError("rate_limit_exceeded", description);
9034
+ const response = err.response;
9035
+ const retryAfter = response ? retryAfterMs(response) : void 0;
9036
+ if (retryAfter !== void 0) POLL_RETRY_AFTER_MS.set(limited, retryAfter);
9037
+ return limited;
9038
+ }
8948
9039
  function sleep(ms) {
8949
9040
  return new Promise((resolve) => {
8950
9041
  setTimeout(resolve, ms);
@@ -9078,6 +9169,19 @@ function transient(error) {
9078
9169
  return error;
9079
9170
  }
9080
9171
  var SYSTEM_CIBA_CLOCK = { now: () => Date.now(), sleep };
9172
+ function deadlineBoundedRetry(bound, what) {
9173
+ return {
9174
+ admit: (ms) => {
9175
+ if (bound.clock.now() + ms >= bound.deadline) {
9176
+ throw new OAuthProtocolError(
9177
+ "expired_token",
9178
+ `the ${what} expired before it was decided (client-side deadline from expires_in; CONTRACT.md \xA714.2 rule 4, \xA734.2 P10)`
9179
+ );
9180
+ }
9181
+ },
9182
+ sleepFn: (ms) => bound.clock.sleep(ms)
9183
+ };
9184
+ }
9081
9185
  function isAccessDenied(err) {
9082
9186
  return err instanceof OAuthProtocolError && err.error === "access_denied";
9083
9187
  }
@@ -9862,26 +9966,36 @@ var OidcClient = class {
9862
9966
  * The raw single call, so an application driving its own loop (a UI
9863
9967
  * rendering a countdown, say) can. The five RFC 8628 §3.5 answers surface as
9864
9968
  * {@link OAuthProtocolError} — `authorization_pending` and `slow_down`
9865
- * included — so a hand-rolled loop sees exactly what {@link deviceLogin}
9866
- * sees. Most callers want {@link deviceLogin}.
9969
+ * included — so a hand-rolled loop dispatches on the same answers
9970
+ * {@link deviceLogin} does. Most callers want {@link deviceLogin}.
9867
9971
  *
9868
9972
  * Client authentication is the one {@link deviceAuthorize} describes
9869
9973
  * (contract 1.62, §14.1 rule 2): a configured `clientSecret` is sent as
9870
9974
  * `client_secret` in the form body, never as `Authorization: Basic`; a public
9871
9975
  * client sends none; `client_id` is sent on **every** poll (§14.1 rule 3). A
9872
9976
  * `401 invalid_client` surfaces as {@link OAuthProtocolError}, is not retried
9873
- * and does not enter the §9 refresh guard (§14.2 rule 5). This SDK ships no
9977
+ * and does not enter the §9 refresh guard (§14.2 rule 5). Any `429`
9978
+ * is an {@link OAuthProtocolError} with `error == 'rate_limit_exceeded'` too
9979
+ * (rule 9, whatever its body names) — never `slow_down`; {@link deviceLogin}
9980
+ * waits it out. Its `Retry-After` is not exposed, so a hand-rolled loop
9981
+ * should wait at least one interval on it without raising the interval, or
9982
+ * use {@link deviceLogin}. This SDK ships no
9874
9983
  * DPoP proof generator, so it cannot drive a client registered for DPoP; it
9875
9984
  * surfaces that client's refusal as the same `invalid_client`.
9876
9985
  */
9877
9986
  async devicePoll(params) {
9987
+ return this.#devicePoll(params, void 0);
9988
+ }
9989
+ /** {@link devicePoll}; `bound` is the loop's deadline, which a §16 retry inside the poll must not pass. */
9990
+ async #devicePoll(params, bound) {
9878
9991
  const configuration = params.configuration ?? await this.oidcDiscover();
9879
9992
  const form = new URLSearchParams();
9880
9993
  form.set("grant_type", DEVICE_CODE_GRANT_TYPE);
9881
9994
  form.set("device_code", exposeSecret(params.deviceCode));
9882
9995
  form.set("client_id", this.#options.clientId);
9883
9996
  this.#appendClientSecret(form);
9884
- const wire = await this.#postToken(configuration, form, params.tenantId);
9997
+ const url = this.#endpointUrl(this.#requiredEndpoint(configuration, "token_endpoint"), params.tenantId);
9998
+ const wire = await this.#postDevicePoll(url, form, bound);
9885
9999
  return this.#toTokenSet(wire, configuration, void 0);
9886
10000
  }
9887
10001
  /**
@@ -9902,31 +10016,44 @@ var OidcClient = class {
9902
10016
  * even if the server has not yet said `expired_token`. A 5xx or transport
9903
10017
  * failure mid-poll is **not** terminal (rule 6) — the loop absorbs it and
9904
10018
  * tries again, bounded by the same deadline, because a server restart must
9905
- * not lose a grant the user has already approved.
10019
+ * not lose a grant the user has already approved: that bound holds for the
10020
+ * §16 retry inside a poll too, whose waits are served on the loop's clock and
10021
+ * never reach the deadline (`Retry-After` included; the typed `expired_token`
10022
+ * is raised at once, C164-36). A `429
10023
+ * rate_limit_exceeded` (rule 9, contract 1.64) is not terminal either: the
10024
+ * loop waits `Retry-After` as a minimum (capped at the `expires_in`
10025
+ * deadline), counts the wait as one interval, does **not** raise the
10026
+ * interval, and polls again.
9906
10027
  */
9907
10028
  async deviceLogin(params) {
9908
10029
  const configuration = params.configuration ?? await this.oidcDiscover();
10030
+ const clock = params.clock ?? SYSTEM_CIBA_CLOCK;
9909
10031
  const authorization = await this.deviceAuthorize({
9910
10032
  ...params.scope !== void 0 ? { scope: params.scope } : {},
9911
10033
  ...params.tenantId !== void 0 ? { tenantId: params.tenantId } : {},
9912
10034
  configuration
9913
10035
  });
10036
+ const deadline = clock.now() + authorization.expiresIn * 1e3;
9914
10037
  await params.onUserCode(authorization);
9915
10038
  const schedule = new PollSchedule(authorization.interval, authorization.expiresIn);
9916
10039
  for (; ; ) {
9917
- if (!schedule.tick()) {
10040
+ const waitSecs = schedule.waitSecs;
10041
+ if (!schedule.tick() || clock.now() + waitSecs * 1e3 >= deadline) {
9918
10042
  throw new OAuthProtocolError(
9919
10043
  "expired_token",
9920
10044
  "the device authorization expired before the user completed it (client-side deadline from expires_in; CONTRACT.md \xA714.2 rule 4)"
9921
10045
  );
9922
10046
  }
9923
- await sleep(schedule.intervalSecs * 1e3);
10047
+ await clock.sleep(waitSecs * 1e3);
9924
10048
  try {
9925
- return await this.devicePoll({
9926
- deviceCode: authorization.deviceCode,
9927
- ...params.tenantId !== void 0 ? { tenantId: params.tenantId } : {},
9928
- configuration
9929
- });
10049
+ return await this.#devicePoll(
10050
+ {
10051
+ deviceCode: authorization.deviceCode,
10052
+ ...params.tenantId !== void 0 ? { tenantId: params.tenantId } : {},
10053
+ configuration
10054
+ },
10055
+ { deadline, clock }
10056
+ );
9930
10057
  } catch (err) {
9931
10058
  if (err instanceof OAuthProtocolError) {
9932
10059
  if (err.error === "authorization_pending") {
@@ -9936,6 +10063,11 @@ var OidcClient = class {
9936
10063
  schedule.slowDown();
9937
10064
  continue;
9938
10065
  }
10066
+ if (err.error === "rate_limit_exceeded") {
10067
+ const pollWaitMs = POLL_RETRY_AFTER_MS.get(err);
10068
+ schedule.rateLimited(pollWaitMs === void 0 ? void 0 : pollWaitMs / 1e3);
10069
+ continue;
10070
+ }
9939
10071
  throw err;
9940
10072
  }
9941
10073
  if (err instanceof NetworkError) {
@@ -10456,6 +10588,10 @@ var OidcClient = class {
10456
10588
  * this client's credential.
10457
10589
  */
10458
10590
  async cibaPoll(params) {
10591
+ return this.#cibaPoll(params, void 0);
10592
+ }
10593
+ /** {@link cibaPoll}; `bound` is `cibaAwait`'s deadline, which a §16 retry inside the poll must not pass. */
10594
+ async #cibaPoll(params, bound) {
10459
10595
  const operation = "ciba_poll";
10460
10596
  const auth = this.#cibaClientAuth(operation);
10461
10597
  const configuration = params.configuration ?? await this.oidcDiscover();
@@ -10489,7 +10625,8 @@ var OidcClient = class {
10489
10625
  idempotent: true,
10490
10626
  operation,
10491
10627
  enabled: this.#session.retryEnabled,
10492
- telemetry: this.#session.telemetry.dispatcher
10628
+ telemetry: this.#session.telemetry.dispatcher,
10629
+ ...bound !== void 0 ? deadlineBoundedRetry(bound, "CIBA request") : {}
10493
10630
  }
10494
10631
  );
10495
10632
  if (outcome.error) throw outcome.error;
@@ -10509,7 +10646,9 @@ var OidcClient = class {
10509
10646
  * the interval and polls again.
10510
10647
  * - Polling stops at `receivedAt + expiresIn`, even if the server has not
10511
10648
  * said `expired_token`: when the next wait would reach the deadline, the
10512
- * same `expired_token` is raised locally, without a request.
10649
+ * same `expired_token` is raised locally, without a request. A §16 retry
10650
+ * inside {@link cibaPoll} is bounded the same way (§34.2 P10): a wait that
10651
+ * would reach the deadline is not served and nothing is sent after it.
10513
10652
  * - `access_denied`, `expired_token`, `invalid_grant` and any other answer
10514
10653
  * end the loop.
10515
10654
  *
@@ -10537,11 +10676,14 @@ var OidcClient = class {
10537
10676
  }
10538
10677
  await clock.sleep(waitMs);
10539
10678
  try {
10540
- return await this.cibaPoll({
10541
- authReqId: initiated.authReqId,
10542
- configuration,
10543
- ...params.tenantId !== void 0 ? { tenantId: params.tenantId } : {}
10544
- });
10679
+ return await this.#cibaPoll(
10680
+ {
10681
+ authReqId: initiated.authReqId,
10682
+ configuration,
10683
+ ...params.tenantId !== void 0 ? { tenantId: params.tenantId } : {}
10684
+ },
10685
+ { deadline, clock }
10686
+ );
10545
10687
  } catch (err) {
10546
10688
  if (err instanceof OAuthProtocolError) {
10547
10689
  if (err.error === "authorization_pending" || err.error === "rate_limit_exceeded") continue;
@@ -10637,6 +10779,46 @@ var OidcClient = class {
10637
10779
  throw transient(new NetworkError(`${operation}: the request failed before any response arrived${code}`));
10638
10780
  }
10639
10781
  }
10782
+ /**
10783
+ * One device-poll attempt under §16 (CONTRACT.md §14.2 rule 6, §16.2; C164-25): a `5xx` or
10784
+ * a transport failure is retried **inside** the poll (three requests in all, the `Retry-After`
10785
+ * a floor) before it surfaces as a `NetworkError`; the loop then takes its next interval. A
10786
+ * `429` is never retried here — it is rule 9's wait, the loop's — nor is any answer the
10787
+ * server decided (`400`, `401`).
10788
+ */
10789
+ async #postDevicePoll(url, form, bound) {
10790
+ const operation = "device_poll";
10791
+ const outcome = await withRetry(
10792
+ async () => {
10793
+ try {
10794
+ const response = await this.#session.axios.post(url, form.toString(), {
10795
+ headers: { "Content-Type": "application/x-www-form-urlencoded" }
10796
+ });
10797
+ return { wire: response.data };
10798
+ } catch (err) {
10799
+ if (err instanceof AxiamError) return { error: err };
10800
+ const status = axiosStatus3(err);
10801
+ const response = err.response;
10802
+ if (status === void 0) {
10803
+ throw new NetworkError(`${operation}: the request failed before any response arrived`, sanitizeAxiosError(err));
10804
+ }
10805
+ if (status >= 500) {
10806
+ throw retryableNetworkError(`${operation}: HTTP ${status}`, response);
10807
+ }
10808
+ return { error: pollRateLimit(err) ?? mapOidcError(err, url, "token request failed") };
10809
+ }
10810
+ },
10811
+ {
10812
+ idempotent: true,
10813
+ operation,
10814
+ enabled: this.#session.retryEnabled,
10815
+ telemetry: this.#session.telemetry.dispatcher,
10816
+ ...bound !== void 0 ? deadlineBoundedRetry(bound, "device authorization") : {}
10817
+ }
10818
+ );
10819
+ if (outcome.error) throw outcome.error;
10820
+ return outcome.wire;
10821
+ }
10640
10822
  /** POST a form body to the token endpoint from the discovery document. */
10641
10823
  async #postToken(configuration, form, tenantId) {
10642
10824
  const url = this.#endpointUrl(this.#requiredEndpoint(configuration, "token_endpoint"), tenantId);
@@ -10799,7 +10981,7 @@ var OidcClient = class {
10799
10981
  this.#session.axios.interceptors.request.use((config) => {
10800
10982
  const adopted = this.#adoptedCredential;
10801
10983
  const url = config.url ?? "";
10802
- if (!adopted || this.#session.isForeignHost(url) || url.includes("/oauth2/")) {
10984
+ if (!adopted || this.#session.isForeignHost(url) || isOAuth2Endpoint(url, this.#session.baseUrl)) {
10803
10985
  return config;
10804
10986
  }
10805
10987
  config.headers = config.headers ?? {};
@@ -10823,6 +11005,10 @@ var OidcClient = class {
10823
11005
  try {
10824
11006
  return await this.#session.axios.post(url, form.toString(), config);
10825
11007
  } catch (err) {
11008
+ if (axiosStatus3(err) === 429) {
11009
+ const protocol = oauth2ErrorFromBody(axiosBody(err));
11010
+ if (protocol) throw protocol;
11011
+ }
10826
11012
  throw mapOidcError(err, url, fallbackMessage);
10827
11013
  }
10828
11014
  }