axiam-sdk 1.1.1 → 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 (42) hide show
  1. package/README.md +20 -4
  2. package/dist/browser/index.d.cts +1 -1
  3. package/dist/browser/index.d.ts +1 -1
  4. package/dist/{client-D34sXV8p.d.cts → client-BGFn1VQh.d.cts} +7 -1
  5. package/dist/{client-BMNQi36J.d.ts → client-DrQZZ1js.d.ts} +7 -1
  6. package/dist/{cookieJar-DcrMe93Q.d.ts → cookieJar-BTmpjXZe.d.ts} +8 -2
  7. package/dist/{cookieJar-C_xPuniu.d.cts → cookieJar-BqYOnNN-.d.cts} +8 -2
  8. package/dist/grpc/index.d.cts +4 -4
  9. package/dist/grpc/index.d.ts +4 -4
  10. package/dist/grpc/index.js +32 -2
  11. package/dist/grpc/index.js.map +1 -1
  12. package/dist/grpc/index.mjs +32 -2
  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 +24 -2
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +24 -2
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/middleware/index.d.cts +3 -3
  21. package/dist/middleware/index.d.ts +3 -3
  22. package/dist/middleware/index.js +149 -22
  23. package/dist/middleware/index.js.map +1 -1
  24. package/dist/middleware/index.mjs +149 -22
  25. package/dist/middleware/index.mjs.map +1 -1
  26. package/dist/node/index.d.cts +3 -3
  27. package/dist/node/index.d.ts +3 -3
  28. package/dist/node/index.js +178 -23
  29. package/dist/node/index.js.map +1 -1
  30. package/dist/node/index.mjs +178 -23
  31. package/dist/node/index.mjs.map +1 -1
  32. package/dist/{oidcState-BFIHt7_Y.d.cts → oidcState-BaJ-SM_R.d.cts} +37 -6
  33. package/dist/{oidcState-qoy2vsYG.d.ts → oidcState-C3VLn3eD.d.ts} +37 -6
  34. package/dist/rest/index.d.cts +3 -3
  35. package/dist/rest/index.d.ts +3 -3
  36. package/dist/rest/index.js +24 -2
  37. package/dist/rest/index.js.map +1 -1
  38. package/dist/rest/index.mjs +24 -2
  39. package/dist/rest/index.mjs.map +1 -1
  40. package/dist/{session-BbPFTpMZ.d.ts → session-B03NsqVs.d.ts} +16 -0
  41. package/dist/{session-C9WlP6DV.d.cts → session-plDr4lFu.d.cts} +16 -0
  42. package/package.json +1 -1
@@ -1,13 +1,13 @@
1
- export { A as ACCESS_COOKIE, C as CSRF_COOKIE, N as NodeSession, R as REFRESH_COOKIE, T as TokenManager, c as createJar, a as createNodeClient, b as createNodeSession, e as extractCookieValue, w as wrapAxios } from '../cookieJar-C_xPuniu.cjs';
1
+ export { A as ACCESS_COOKIE, C as CSRF_COOKIE, N as NodeSession, R as REFRESH_COOKIE, T as TokenManager, c as createJar, a as createNodeClient, b as createNodeSession, e as extractCookieValue, w as wrapAxios } from '../cookieJar-BqYOnNN-.cjs';
2
2
  export { D as DEFAULT_POLL_INTERVAL_MS, M as MAX_ENTRIES, a as MIN_POLL_INTERVAL_MS, R as RevocationFeed, b as RevocationFeedOptions } from '../revocationFeed-KQhvMMl8.cjs';
3
3
  export { a as AccessTokenExpectations, A as AxiamClaims, b as CLOCK_SKEW_LEEWAY_SEC, C as CnfClaim, d as ID_TOKEN_ALG, I as IdTokenClaims, e as IdTokenExpectations, f as IdTokenVerifier, J as JWKS_PATH, g as JwksVerifier, M as MAX_CLOCK_SKEW_SEC, P as PresentedProofs, V as Verifier, h as assertTenantClaim, i as certificateThumbprintS256, j as createJwksVerifier, c as createVerifier, v as verifyCertificateBinding, k as verifyTokenBinding } from '../jwks-CTVpOWzI.cjs';
4
- export { A as ACCESS_TOKEN_TYPE, a as AuthorizationRequest, B as BACKCHANNEL_LOGOUT_EVENT, C as CIBA_GRANT_TYPE, b as CIBA_SLOW_DOWN_INCREMENT_SECS, c as CibaAwaitParams, d as CibaClock, e as CibaDelivery, f as CibaInitiateParams, g as CibaInitiateResponse, h as CibaPingHeaders, i as CibaPollParams, j as CibaRequestSigner, k as CibaSignerDescription, l as CibaSigningAlg, m as CibaSigningKey, n as CibaUserHint, D as DEFAULT_CIBA_INTERVAL_SECS, o as DEFAULT_POLL_INTERVAL_SECS, p as DEVICE_CODE_GRANT_TYPE, q as DISCOVERY_PATH, r as DeviceAuthorization, s as DeviceAuthorizeParams, t as DeviceLoginParams, u as DevicePollParams, E as ExchangedToken, F as FederationProvider, v as FederationProviderList, H as HANDOFF_CODE_TTL_SECS, w as HANDOFF_QUERY_PARAM, I as IntrospectParams, x as IntrospectionResult, J as JWT_TOKEN_TYPE, L as LoginClientCredentialsParams, y as LogoutUrlParams, M as MAX_LOGOUT_TOKEN_AGE_SECS, z as MIN_DISCOVERY_TTL_MS, G as MemoryOidcStateStore, K as MtlsEndpointAliases, O as OIDC_STATE_TTL_MS, N as OidcBeginParams, P as OidcClient, Q as OidcClientOptions, R as OidcConfiguration, S as OidcExchangeParams, T as OidcParParams, U as OidcRefreshParams, V as OidcStateEntry, W as OidcStateStore, X as OidcTokenSet, Y as PROTOCOL_OAUTH2, Z as PROTOCOL_OIDC_CONNECT, _ as PROTOCOL_SAML, $ as PollSchedule, a0 as PushedAuthorizationRequest, a1 as RequestedPermission, a2 as RequestingPartyToken, a3 as ResourceSet, a4 as RevokeParams, a5 as RptPermission, a6 as SIGNED_REQUEST_LIFETIME_SECS, a7 as SLOW_DOWN_INCREMENT_SECS, a8 as SSO_CALLBACK_PATH, a9 as SSO_HANDOFF_PATH, aa as SSO_OAUTH2_CALLBACK_PATH, ab as SSO_OAUTH2_START_PATH, ac as SSO_PROVIDERS_PATH, ad as SSO_START_PATH, ae as SsoCompleteHandoffParams, af as SsoCompleteOauth2Params, ag as SsoCompleteParams, ah as SsoCompleteResult, ai as SsoProvidersParams, aj as SsoStartOauth2Params, ak as SsoStartParams, al as SsoStartResult, am as TOKEN_EXCHANGE_GRANT_TYPE, an as TokenExchangeParams, ao as UMA_CLAIM_TOKEN_FORMAT, ap as UMA_PROTECTION_SCOPE, aq as UMA_TICKET_GRANT_TYPE, ar as UmaChallenge, as as UmaExchangeTicketParams, at as VerifiedLogoutToken, au as createOidcClient, av as isAccessDenied, aw as isExpiredToken, ax as normalizeOrigin, ay as umaChallengeHeader, az as umaParseChallenge } from '../oidcState-BFIHt7_Y.cjs';
4
+ export { A as ACCESS_TOKEN_TYPE, a as AuthorizationRequest, B as BACKCHANNEL_LOGOUT_EVENT, C as CIBA_GRANT_TYPE, b as CIBA_SLOW_DOWN_INCREMENT_SECS, c as CibaAwaitParams, d as CibaClock, e as CibaDelivery, f as CibaInitiateParams, g as CibaInitiateResponse, h as CibaPingHeaders, i as CibaPollParams, j as CibaRequestSigner, k as CibaSignerDescription, l as CibaSigningAlg, m as CibaSigningKey, n as CibaUserHint, D as DEFAULT_CIBA_INTERVAL_SECS, o as DEFAULT_POLL_INTERVAL_SECS, p as DEVICE_CODE_GRANT_TYPE, q as DISCOVERY_PATH, r as DeviceAuthorization, s as DeviceAuthorizeParams, t as DeviceLoginParams, u as DevicePollParams, E as ExchangedToken, F as FederationProvider, v as FederationProviderList, H as HANDOFF_CODE_TTL_SECS, w as HANDOFF_QUERY_PARAM, I as IntrospectParams, x as IntrospectionResult, J as JWT_TOKEN_TYPE, L as LoginClientCredentialsParams, y as LogoutUrlParams, M as MAX_LOGOUT_TOKEN_AGE_SECS, z as MIN_DISCOVERY_TTL_MS, G as MemoryOidcStateStore, K as MtlsEndpointAliases, O as OIDC_STATE_TTL_MS, N as OidcBeginParams, P as OidcClient, Q as OidcClientOptions, R as OidcConfiguration, S as OidcExchangeParams, T as OidcParParams, U as OidcRefreshParams, V as OidcStateEntry, W as OidcStateStore, X as OidcTokenSet, Y as PROTOCOL_OAUTH2, Z as PROTOCOL_OIDC_CONNECT, _ as PROTOCOL_SAML, $ as PollSchedule, a0 as PushedAuthorizationRequest, a1 as RequestedPermission, a2 as RequestingPartyToken, a3 as ResourceSet, a4 as RevokeParams, a5 as RptPermission, a6 as SIGNED_REQUEST_LIFETIME_SECS, a7 as SLOW_DOWN_INCREMENT_SECS, a8 as SSO_CALLBACK_PATH, a9 as SSO_HANDOFF_PATH, aa as SSO_OAUTH2_CALLBACK_PATH, ab as SSO_OAUTH2_START_PATH, ac as SSO_PROVIDERS_PATH, ad as SSO_START_PATH, ae as SsoCompleteHandoffParams, af as SsoCompleteOauth2Params, ag as SsoCompleteParams, ah as SsoCompleteResult, ai as SsoProvidersParams, aj as SsoStartOauth2Params, ak as SsoStartParams, al as SsoStartResult, am as TOKEN_EXCHANGE_GRANT_TYPE, an as TokenExchangeParams, ao as UMA_CLAIM_TOKEN_FORMAT, ap as UMA_PROTECTION_SCOPE, aq as UMA_TICKET_GRANT_TYPE, ar as UmaChallenge, as as UmaExchangeTicketParams, at as VerifiedLogoutToken, au as createOidcClient, av as isAccessDenied, aw as isExpiredToken, ax as normalizeOrigin, ay as umaChallengeHeader, az as umaParseChallenge } from '../oidcState-BaJ-SM_R.cjs';
5
5
  import { S as Sensitive } from '../sensitive-BC_s7Rrd.cjs';
6
6
  import { AuthError } from '../index.cjs';
7
7
  import { AxiamClient } from '../index.cjs';
8
8
  import 'axios';
9
9
  import 'tough-cookie';
10
- import '../session-C9WlP6DV.cjs';
10
+ import '../session-plDr4lFu.cjs';
11
11
  import '../telemetry-Du0-zS5f.cjs';
12
12
  import '../types-zXSpiQM-.cjs';
13
13
  import 'node:crypto';
@@ -1,13 +1,13 @@
1
- export { A as ACCESS_COOKIE, C as CSRF_COOKIE, N as NodeSession, R as REFRESH_COOKIE, T as TokenManager, c as createJar, a as createNodeClient, b as createNodeSession, e as extractCookieValue, w as wrapAxios } from '../cookieJar-DcrMe93Q.js';
1
+ export { A as ACCESS_COOKIE, C as CSRF_COOKIE, N as NodeSession, R as REFRESH_COOKIE, T as TokenManager, c as createJar, a as createNodeClient, b as createNodeSession, e as extractCookieValue, w as wrapAxios } from '../cookieJar-BTmpjXZe.js';
2
2
  export { D as DEFAULT_POLL_INTERVAL_MS, M as MAX_ENTRIES, a as MIN_POLL_INTERVAL_MS, R as RevocationFeed, b as RevocationFeedOptions } from '../revocationFeed-KQhvMMl8.js';
3
3
  export { a as AccessTokenExpectations, A as AxiamClaims, b as CLOCK_SKEW_LEEWAY_SEC, C as CnfClaim, d as ID_TOKEN_ALG, I as IdTokenClaims, e as IdTokenExpectations, f as IdTokenVerifier, J as JWKS_PATH, g as JwksVerifier, M as MAX_CLOCK_SKEW_SEC, P as PresentedProofs, V as Verifier, h as assertTenantClaim, i as certificateThumbprintS256, j as createJwksVerifier, c as createVerifier, v as verifyCertificateBinding, k as verifyTokenBinding } from '../jwks-CTVpOWzI.js';
4
- export { A as ACCESS_TOKEN_TYPE, a as AuthorizationRequest, B as BACKCHANNEL_LOGOUT_EVENT, C as CIBA_GRANT_TYPE, b as CIBA_SLOW_DOWN_INCREMENT_SECS, c as CibaAwaitParams, d as CibaClock, e as CibaDelivery, f as CibaInitiateParams, g as CibaInitiateResponse, h as CibaPingHeaders, i as CibaPollParams, j as CibaRequestSigner, k as CibaSignerDescription, l as CibaSigningAlg, m as CibaSigningKey, n as CibaUserHint, D as DEFAULT_CIBA_INTERVAL_SECS, o as DEFAULT_POLL_INTERVAL_SECS, p as DEVICE_CODE_GRANT_TYPE, q as DISCOVERY_PATH, r as DeviceAuthorization, s as DeviceAuthorizeParams, t as DeviceLoginParams, u as DevicePollParams, E as ExchangedToken, F as FederationProvider, v as FederationProviderList, H as HANDOFF_CODE_TTL_SECS, w as HANDOFF_QUERY_PARAM, I as IntrospectParams, x as IntrospectionResult, J as JWT_TOKEN_TYPE, L as LoginClientCredentialsParams, y as LogoutUrlParams, M as MAX_LOGOUT_TOKEN_AGE_SECS, z as MIN_DISCOVERY_TTL_MS, G as MemoryOidcStateStore, K as MtlsEndpointAliases, O as OIDC_STATE_TTL_MS, N as OidcBeginParams, P as OidcClient, Q as OidcClientOptions, R as OidcConfiguration, S as OidcExchangeParams, T as OidcParParams, U as OidcRefreshParams, V as OidcStateEntry, W as OidcStateStore, X as OidcTokenSet, Y as PROTOCOL_OAUTH2, Z as PROTOCOL_OIDC_CONNECT, _ as PROTOCOL_SAML, $ as PollSchedule, a0 as PushedAuthorizationRequest, a1 as RequestedPermission, a2 as RequestingPartyToken, a3 as ResourceSet, a4 as RevokeParams, a5 as RptPermission, a6 as SIGNED_REQUEST_LIFETIME_SECS, a7 as SLOW_DOWN_INCREMENT_SECS, a8 as SSO_CALLBACK_PATH, a9 as SSO_HANDOFF_PATH, aa as SSO_OAUTH2_CALLBACK_PATH, ab as SSO_OAUTH2_START_PATH, ac as SSO_PROVIDERS_PATH, ad as SSO_START_PATH, ae as SsoCompleteHandoffParams, af as SsoCompleteOauth2Params, ag as SsoCompleteParams, ah as SsoCompleteResult, ai as SsoProvidersParams, aj as SsoStartOauth2Params, ak as SsoStartParams, al as SsoStartResult, am as TOKEN_EXCHANGE_GRANT_TYPE, an as TokenExchangeParams, ao as UMA_CLAIM_TOKEN_FORMAT, ap as UMA_PROTECTION_SCOPE, aq as UMA_TICKET_GRANT_TYPE, ar as UmaChallenge, as as UmaExchangeTicketParams, at as VerifiedLogoutToken, au as createOidcClient, av as isAccessDenied, aw as isExpiredToken, ax as normalizeOrigin, ay as umaChallengeHeader, az as umaParseChallenge } from '../oidcState-qoy2vsYG.js';
4
+ export { A as ACCESS_TOKEN_TYPE, a as AuthorizationRequest, B as BACKCHANNEL_LOGOUT_EVENT, C as CIBA_GRANT_TYPE, b as CIBA_SLOW_DOWN_INCREMENT_SECS, c as CibaAwaitParams, d as CibaClock, e as CibaDelivery, f as CibaInitiateParams, g as CibaInitiateResponse, h as CibaPingHeaders, i as CibaPollParams, j as CibaRequestSigner, k as CibaSignerDescription, l as CibaSigningAlg, m as CibaSigningKey, n as CibaUserHint, D as DEFAULT_CIBA_INTERVAL_SECS, o as DEFAULT_POLL_INTERVAL_SECS, p as DEVICE_CODE_GRANT_TYPE, q as DISCOVERY_PATH, r as DeviceAuthorization, s as DeviceAuthorizeParams, t as DeviceLoginParams, u as DevicePollParams, E as ExchangedToken, F as FederationProvider, v as FederationProviderList, H as HANDOFF_CODE_TTL_SECS, w as HANDOFF_QUERY_PARAM, I as IntrospectParams, x as IntrospectionResult, J as JWT_TOKEN_TYPE, L as LoginClientCredentialsParams, y as LogoutUrlParams, M as MAX_LOGOUT_TOKEN_AGE_SECS, z as MIN_DISCOVERY_TTL_MS, G as MemoryOidcStateStore, K as MtlsEndpointAliases, O as OIDC_STATE_TTL_MS, N as OidcBeginParams, P as OidcClient, Q as OidcClientOptions, R as OidcConfiguration, S as OidcExchangeParams, T as OidcParParams, U as OidcRefreshParams, V as OidcStateEntry, W as OidcStateStore, X as OidcTokenSet, Y as PROTOCOL_OAUTH2, Z as PROTOCOL_OIDC_CONNECT, _ as PROTOCOL_SAML, $ as PollSchedule, a0 as PushedAuthorizationRequest, a1 as RequestedPermission, a2 as RequestingPartyToken, a3 as ResourceSet, a4 as RevokeParams, a5 as RptPermission, a6 as SIGNED_REQUEST_LIFETIME_SECS, a7 as SLOW_DOWN_INCREMENT_SECS, a8 as SSO_CALLBACK_PATH, a9 as SSO_HANDOFF_PATH, aa as SSO_OAUTH2_CALLBACK_PATH, ab as SSO_OAUTH2_START_PATH, ac as SSO_PROVIDERS_PATH, ad as SSO_START_PATH, ae as SsoCompleteHandoffParams, af as SsoCompleteOauth2Params, ag as SsoCompleteParams, ah as SsoCompleteResult, ai as SsoProvidersParams, aj as SsoStartOauth2Params, ak as SsoStartParams, al as SsoStartResult, am as TOKEN_EXCHANGE_GRANT_TYPE, an as TokenExchangeParams, ao as UMA_CLAIM_TOKEN_FORMAT, ap as UMA_PROTECTION_SCOPE, aq as UMA_TICKET_GRANT_TYPE, ar as UmaChallenge, as as UmaExchangeTicketParams, at as VerifiedLogoutToken, au as createOidcClient, av as isAccessDenied, aw as isExpiredToken, ax as normalizeOrigin, ay as umaChallengeHeader, az as umaParseChallenge } from '../oidcState-C3VLn3eD.js';
5
5
  import { S as Sensitive } from '../sensitive-BC_s7Rrd.js';
6
6
  import { AuthError } from '../index.js';
7
7
  import { AxiamClient } from '../index.js';
8
8
  import 'axios';
9
9
  import 'tough-cookie';
10
- import '../session-BbPFTpMZ.js';
10
+ import '../session-B03NsqVs.js';
11
11
  import '../telemetry-Du0-zS5f.js';
12
12
  import '../types-BOX-6Srv.js';
13
13
  import 'node:crypto';
@@ -681,6 +681,24 @@ var SharedSession = class {
681
681
  noCredentialsConfig() {
682
682
  return { withCredentials: false };
683
683
  }
684
+ /**
685
+ * Axios config for a request to an `/oauth2/*` endpoint (CONTRACT.md §12.1
686
+ * rule 3, §14.6; C163-12): {@link noCredentialsConfig} and, in the browser
687
+ * persona, the fetch adapter with `credentials: 'omit'`.
688
+ *
689
+ * `withCredentials: false` on axios's default XHR adapter is not enough: that
690
+ * adapter sends a same-origin cookie regardless, so an app served from the
691
+ * AXIAM origin would still present `axiam_*` on a token or device request.
692
+ * The fetch adapter derives its `credentials` from `withCredentials: false`
693
+ * (`'omit'`); `fetchOptions.credentials` is set as well for adapters that
694
+ * read it.
695
+ * `NodeSession` overrides this to {@link noCredentialsConfig}: its jar-free
696
+ * agent pair is what keeps the cookies off there, and the fetch adapter
697
+ * would bypass that pair.
698
+ */
699
+ oauth2RequestConfig() {
700
+ return { ...this.noCredentialsConfig(), adapter: "fetch", fetchOptions: { credentials: "omit" } };
701
+ }
684
702
  };
685
703
  function resolveTenantHeaderValue(options) {
686
704
  if (options.tenantSlug) {
@@ -881,7 +899,7 @@ function installDeviceTokenInterceptor(axiosInstance, session) {
881
899
  if (session.isForeignHost(config.url) || deviceToken === void 0 && !oauth2) {
882
900
  return config;
883
901
  }
884
- const noCred = session.noCredentialsConfig();
902
+ const noCred = oauth2 ? session.oauth2RequestConfig() : session.noCredentialsConfig();
885
903
  Object.assign(config, noCred);
886
904
  config.headers = config.headers ?? {};
887
905
  if (oauth2) {
@@ -1375,6 +1393,7 @@ async function withRetry(fn, options) {
1375
1393
  }
1376
1394
  const retryAfterMs2 = isRetryAfterCarrier(err) ? err.retryAfterMs : void 0;
1377
1395
  const delay = delayMs(attempt, retryAfterMs2, random());
1396
+ options.admit?.(delay);
1378
1397
  options.telemetry?.emit({
1379
1398
  type: "retry",
1380
1399
  operation: options.operation ?? "unknown",
@@ -1904,7 +1923,10 @@ async function bareRequest(session, operation, config) {
1904
1923
  // jar). Under the Node persona this is the jar-wrapped cookie agent, which
1905
1924
  // `noCredentialsConfig()` below replaces with a plain one.
1906
1925
  ...defaults.httpsAgent !== void 0 ? { httpsAgent: defaults.httpsAgent } : {},
1907
- ...session.noCredentialsConfig(),
1926
+ // The bare transport carries the RFC 7592 registration calls on `/oauth2/register/*`,
1927
+ // so it gets an `/oauth2/*` request's config: in the browser persona the fetch adapter
1928
+ // that omits credentials (C164-06; identical to `noCredentialsConfig()` under Node).
1929
+ ...session.oauth2RequestConfig(),
1908
1930
  withCredentials: false,
1909
1931
  maxRedirects: 0,
1910
1932
  validateStatus: () => true
@@ -8558,6 +8580,14 @@ var NodeSession = class extends SharedSession {
8558
8580
  withCredentials: false
8559
8581
  };
8560
8582
  }
8583
+ /**
8584
+ * Overrides {@link SharedSession.oauth2RequestConfig}: under Node the
8585
+ * jar-free agent pair of {@link noCredentialsConfig} is what withholds the
8586
+ * cookies; the browser's fetch adapter (`credentials: 'omit'`) is not used.
8587
+ */
8588
+ oauth2RequestConfig() {
8589
+ return this.noCredentialsConfig();
8590
+ }
8561
8591
  /**
8562
8592
  * Drives the actual `POST /api/v1/auth/refresh` HTTP call. Passed to this
8563
8593
  * session's per-instance `refreshGuard` (inherited from SharedSession) by
@@ -8954,6 +8984,8 @@ var MAX_LOGOUT_TOKEN_AGE_SECS = 300;
8954
8984
  var PollSchedule = class {
8955
8985
  #intervalSecs;
8956
8986
  #remainingSecs;
8987
+ /** A `Retry-After` still to be served by the next wait (§14.2 rule 9, contract 1.64). */
8988
+ #retryAfterSecs = 0;
8957
8989
  constructor(intervalSecs, expiresInSecs) {
8958
8990
  this.#intervalSecs = intervalSecs > 0 ? intervalSecs : DEFAULT_POLL_INTERVAL_SECS;
8959
8991
  this.#remainingSecs = expiresInSecs;
@@ -8962,6 +8994,21 @@ var PollSchedule = class {
8962
8994
  get intervalSecs() {
8963
8995
  return this.#intervalSecs;
8964
8996
  }
8997
+ /**
8998
+ * The delay before the next poll, in seconds: the interval, or the pending
8999
+ * `Retry-After` when that is longer (a minimum, §14.2 rule 9).
9000
+ */
9001
+ get waitSecs() {
9002
+ return Math.max(this.#intervalSecs, this.#retryAfterSecs);
9003
+ }
9004
+ /**
9005
+ * Record a `429 rate_limit_exceeded` (§14.2 rule 9, contract 1.64): the next
9006
+ * wait lasts at least `retryAfterSecs` and stands in for one interval. The
9007
+ * interval itself is **not** raised — only the `400 slow_down` does that.
9008
+ */
9009
+ rateLimited(retryAfterSecs) {
9010
+ this.#retryAfterSecs = retryAfterSecs !== void 0 && retryAfterSecs > 0 ? retryAfterSecs : 0;
9011
+ }
8965
9012
  /** Apply one `slow_down` (§14.2 rule 1): **cumulative, never reset.** */
8966
9013
  slowDown() {
8967
9014
  this.#intervalSecs += SLOW_DOWN_INCREMENT_SECS;
@@ -8974,14 +9021,27 @@ var PollSchedule = class {
8974
9021
  * the server is still answering `authorization_pending`.
8975
9022
  */
8976
9023
  tick() {
8977
- if (this.#intervalSecs >= this.#remainingSecs) {
9024
+ const waitSecs = this.waitSecs;
9025
+ this.#retryAfterSecs = 0;
9026
+ if (waitSecs >= this.#remainingSecs) {
8978
9027
  this.#remainingSecs = 0;
8979
9028
  return false;
8980
9029
  }
8981
- this.#remainingSecs -= this.#intervalSecs;
9030
+ this.#remainingSecs -= waitSecs;
8982
9031
  return true;
8983
9032
  }
8984
9033
  };
9034
+ var POLL_RETRY_AFTER_MS = /* @__PURE__ */ new WeakMap();
9035
+ function pollRateLimit(err) {
9036
+ if (axiosStatus3(err) !== 429) return void 0;
9037
+ const body = axiosBody(err);
9038
+ const description = body !== null && typeof body === "object" && typeof body.error_description === "string" ? body.error_description : "";
9039
+ const limited = new OAuthProtocolError("rate_limit_exceeded", description);
9040
+ const response = err.response;
9041
+ const retryAfter = response ? retryAfterMs(response) : void 0;
9042
+ if (retryAfter !== void 0) POLL_RETRY_AFTER_MS.set(limited, retryAfter);
9043
+ return limited;
9044
+ }
8985
9045
  function sleep(ms) {
8986
9046
  return new Promise((resolve) => {
8987
9047
  setTimeout(resolve, ms);
@@ -9115,6 +9175,19 @@ function transient(error) {
9115
9175
  return error;
9116
9176
  }
9117
9177
  var SYSTEM_CIBA_CLOCK = { now: () => Date.now(), sleep };
9178
+ function deadlineBoundedRetry(bound, what) {
9179
+ return {
9180
+ admit: (ms) => {
9181
+ if (bound.clock.now() + ms >= bound.deadline) {
9182
+ throw new OAuthProtocolError(
9183
+ "expired_token",
9184
+ `the ${what} expired before it was decided (client-side deadline from expires_in; CONTRACT.md \xA714.2 rule 4, \xA734.2 P10)`
9185
+ );
9186
+ }
9187
+ },
9188
+ sleepFn: (ms) => bound.clock.sleep(ms)
9189
+ };
9190
+ }
9118
9191
  function isAccessDenied(err) {
9119
9192
  return err instanceof OAuthProtocolError && err.error === "access_denied";
9120
9193
  }
@@ -9899,26 +9972,36 @@ var OidcClient = class {
9899
9972
  * The raw single call, so an application driving its own loop (a UI
9900
9973
  * rendering a countdown, say) can. The five RFC 8628 §3.5 answers surface as
9901
9974
  * {@link OAuthProtocolError} — `authorization_pending` and `slow_down`
9902
- * included — so a hand-rolled loop sees exactly what {@link deviceLogin}
9903
- * sees. Most callers want {@link deviceLogin}.
9975
+ * included — so a hand-rolled loop dispatches on the same answers
9976
+ * {@link deviceLogin} does. Most callers want {@link deviceLogin}.
9904
9977
  *
9905
9978
  * Client authentication is the one {@link deviceAuthorize} describes
9906
9979
  * (contract 1.62, §14.1 rule 2): a configured `clientSecret` is sent as
9907
9980
  * `client_secret` in the form body, never as `Authorization: Basic`; a public
9908
9981
  * client sends none; `client_id` is sent on **every** poll (§14.1 rule 3). A
9909
9982
  * `401 invalid_client` surfaces as {@link OAuthProtocolError}, is not retried
9910
- * and does not enter the §9 refresh guard (§14.2 rule 5). This SDK ships no
9983
+ * and does not enter the §9 refresh guard (§14.2 rule 5). Any `429`
9984
+ * is an {@link OAuthProtocolError} with `error == 'rate_limit_exceeded'` too
9985
+ * (rule 9, whatever its body names) — never `slow_down`; {@link deviceLogin}
9986
+ * waits it out. Its `Retry-After` is not exposed, so a hand-rolled loop
9987
+ * should wait at least one interval on it without raising the interval, or
9988
+ * use {@link deviceLogin}. This SDK ships no
9911
9989
  * DPoP proof generator, so it cannot drive a client registered for DPoP; it
9912
9990
  * surfaces that client's refusal as the same `invalid_client`.
9913
9991
  */
9914
9992
  async devicePoll(params) {
9993
+ return this.#devicePoll(params, void 0);
9994
+ }
9995
+ /** {@link devicePoll}; `bound` is the loop's deadline, which a §16 retry inside the poll must not pass. */
9996
+ async #devicePoll(params, bound) {
9915
9997
  const configuration = params.configuration ?? await this.oidcDiscover();
9916
9998
  const form = new URLSearchParams();
9917
9999
  form.set("grant_type", DEVICE_CODE_GRANT_TYPE);
9918
10000
  form.set("device_code", exposeSecret(params.deviceCode));
9919
10001
  form.set("client_id", this.#options.clientId);
9920
10002
  this.#appendClientSecret(form);
9921
- const wire = await this.#postToken(configuration, form, params.tenantId);
10003
+ const url = this.#endpointUrl(this.#requiredEndpoint(configuration, "token_endpoint"), params.tenantId);
10004
+ const wire = await this.#postDevicePoll(url, form, bound);
9922
10005
  return this.#toTokenSet(wire, configuration, void 0);
9923
10006
  }
9924
10007
  /**
@@ -9939,31 +10022,44 @@ var OidcClient = class {
9939
10022
  * even if the server has not yet said `expired_token`. A 5xx or transport
9940
10023
  * failure mid-poll is **not** terminal (rule 6) — the loop absorbs it and
9941
10024
  * tries again, bounded by the same deadline, because a server restart must
9942
- * not lose a grant the user has already approved.
10025
+ * not lose a grant the user has already approved: that bound holds for the
10026
+ * §16 retry inside a poll too, whose waits are served on the loop's clock and
10027
+ * never reach the deadline (`Retry-After` included; the typed `expired_token`
10028
+ * is raised at once, C164-36). A `429
10029
+ * rate_limit_exceeded` (rule 9, contract 1.64) is not terminal either: the
10030
+ * loop waits `Retry-After` as a minimum (capped at the `expires_in`
10031
+ * deadline), counts the wait as one interval, does **not** raise the
10032
+ * interval, and polls again.
9943
10033
  */
9944
10034
  async deviceLogin(params) {
9945
10035
  const configuration = params.configuration ?? await this.oidcDiscover();
10036
+ const clock = params.clock ?? SYSTEM_CIBA_CLOCK;
9946
10037
  const authorization = await this.deviceAuthorize({
9947
10038
  ...params.scope !== void 0 ? { scope: params.scope } : {},
9948
10039
  ...params.tenantId !== void 0 ? { tenantId: params.tenantId } : {},
9949
10040
  configuration
9950
10041
  });
10042
+ const deadline = clock.now() + authorization.expiresIn * 1e3;
9951
10043
  await params.onUserCode(authorization);
9952
10044
  const schedule = new PollSchedule(authorization.interval, authorization.expiresIn);
9953
10045
  for (; ; ) {
9954
- if (!schedule.tick()) {
10046
+ const waitSecs = schedule.waitSecs;
10047
+ if (!schedule.tick() || clock.now() + waitSecs * 1e3 >= deadline) {
9955
10048
  throw new OAuthProtocolError(
9956
10049
  "expired_token",
9957
10050
  "the device authorization expired before the user completed it (client-side deadline from expires_in; CONTRACT.md \xA714.2 rule 4)"
9958
10051
  );
9959
10052
  }
9960
- await sleep(schedule.intervalSecs * 1e3);
10053
+ await clock.sleep(waitSecs * 1e3);
9961
10054
  try {
9962
- return await this.devicePoll({
9963
- deviceCode: authorization.deviceCode,
9964
- ...params.tenantId !== void 0 ? { tenantId: params.tenantId } : {},
9965
- configuration
9966
- });
10055
+ return await this.#devicePoll(
10056
+ {
10057
+ deviceCode: authorization.deviceCode,
10058
+ ...params.tenantId !== void 0 ? { tenantId: params.tenantId } : {},
10059
+ configuration
10060
+ },
10061
+ { deadline, clock }
10062
+ );
9967
10063
  } catch (err) {
9968
10064
  if (err instanceof OAuthProtocolError) {
9969
10065
  if (err.error === "authorization_pending") {
@@ -9973,6 +10069,11 @@ var OidcClient = class {
9973
10069
  schedule.slowDown();
9974
10070
  continue;
9975
10071
  }
10072
+ if (err.error === "rate_limit_exceeded") {
10073
+ const pollWaitMs = POLL_RETRY_AFTER_MS.get(err);
10074
+ schedule.rateLimited(pollWaitMs === void 0 ? void 0 : pollWaitMs / 1e3);
10075
+ continue;
10076
+ }
9976
10077
  throw err;
9977
10078
  }
9978
10079
  if (err instanceof NetworkError) {
@@ -10493,6 +10594,10 @@ var OidcClient = class {
10493
10594
  * this client's credential.
10494
10595
  */
10495
10596
  async cibaPoll(params) {
10597
+ return this.#cibaPoll(params, void 0);
10598
+ }
10599
+ /** {@link cibaPoll}; `bound` is `cibaAwait`'s deadline, which a §16 retry inside the poll must not pass. */
10600
+ async #cibaPoll(params, bound) {
10496
10601
  const operation = "ciba_poll";
10497
10602
  const auth = this.#cibaClientAuth(operation);
10498
10603
  const configuration = params.configuration ?? await this.oidcDiscover();
@@ -10526,7 +10631,8 @@ var OidcClient = class {
10526
10631
  idempotent: true,
10527
10632
  operation,
10528
10633
  enabled: this.#session.retryEnabled,
10529
- telemetry: this.#session.telemetry.dispatcher
10634
+ telemetry: this.#session.telemetry.dispatcher,
10635
+ ...bound !== void 0 ? deadlineBoundedRetry(bound, "CIBA request") : {}
10530
10636
  }
10531
10637
  );
10532
10638
  if (outcome.error) throw outcome.error;
@@ -10546,7 +10652,9 @@ var OidcClient = class {
10546
10652
  * the interval and polls again.
10547
10653
  * - Polling stops at `receivedAt + expiresIn`, even if the server has not
10548
10654
  * said `expired_token`: when the next wait would reach the deadline, the
10549
- * same `expired_token` is raised locally, without a request.
10655
+ * same `expired_token` is raised locally, without a request. A §16 retry
10656
+ * inside {@link cibaPoll} is bounded the same way (§34.2 P10): a wait that
10657
+ * would reach the deadline is not served and nothing is sent after it.
10550
10658
  * - `access_denied`, `expired_token`, `invalid_grant` and any other answer
10551
10659
  * end the loop.
10552
10660
  *
@@ -10574,11 +10682,14 @@ var OidcClient = class {
10574
10682
  }
10575
10683
  await clock.sleep(waitMs);
10576
10684
  try {
10577
- return await this.cibaPoll({
10578
- authReqId: initiated.authReqId,
10579
- configuration,
10580
- ...params.tenantId !== void 0 ? { tenantId: params.tenantId } : {}
10581
- });
10685
+ return await this.#cibaPoll(
10686
+ {
10687
+ authReqId: initiated.authReqId,
10688
+ configuration,
10689
+ ...params.tenantId !== void 0 ? { tenantId: params.tenantId } : {}
10690
+ },
10691
+ { deadline, clock }
10692
+ );
10582
10693
  } catch (err) {
10583
10694
  if (err instanceof OAuthProtocolError) {
10584
10695
  if (err.error === "authorization_pending" || err.error === "rate_limit_exceeded") continue;
@@ -10674,6 +10785,46 @@ var OidcClient = class {
10674
10785
  throw transient(new NetworkError(`${operation}: the request failed before any response arrived${code}`));
10675
10786
  }
10676
10787
  }
10788
+ /**
10789
+ * One device-poll attempt under §16 (CONTRACT.md §14.2 rule 6, §16.2; C164-25): a `5xx` or
10790
+ * a transport failure is retried **inside** the poll (three requests in all, the `Retry-After`
10791
+ * a floor) before it surfaces as a `NetworkError`; the loop then takes its next interval. A
10792
+ * `429` is never retried here — it is rule 9's wait, the loop's — nor is any answer the
10793
+ * server decided (`400`, `401`).
10794
+ */
10795
+ async #postDevicePoll(url, form, bound) {
10796
+ const operation = "device_poll";
10797
+ const outcome = await withRetry(
10798
+ async () => {
10799
+ try {
10800
+ const response = await this.#session.axios.post(url, form.toString(), {
10801
+ headers: { "Content-Type": "application/x-www-form-urlencoded" }
10802
+ });
10803
+ return { wire: response.data };
10804
+ } catch (err) {
10805
+ if (err instanceof AxiamError) return { error: err };
10806
+ const status = axiosStatus3(err);
10807
+ const response = err.response;
10808
+ if (status === void 0) {
10809
+ throw new NetworkError(`${operation}: the request failed before any response arrived`, sanitizeAxiosError(err));
10810
+ }
10811
+ if (status >= 500) {
10812
+ throw retryableNetworkError(`${operation}: HTTP ${status}`, response);
10813
+ }
10814
+ return { error: pollRateLimit(err) ?? mapOidcError(err, url, "token request failed") };
10815
+ }
10816
+ },
10817
+ {
10818
+ idempotent: true,
10819
+ operation,
10820
+ enabled: this.#session.retryEnabled,
10821
+ telemetry: this.#session.telemetry.dispatcher,
10822
+ ...bound !== void 0 ? deadlineBoundedRetry(bound, "device authorization") : {}
10823
+ }
10824
+ );
10825
+ if (outcome.error) throw outcome.error;
10826
+ return outcome.wire;
10827
+ }
10677
10828
  /** POST a form body to the token endpoint from the discovery document. */
10678
10829
  async #postToken(configuration, form, tenantId) {
10679
10830
  const url = this.#endpointUrl(this.#requiredEndpoint(configuration, "token_endpoint"), tenantId);
@@ -10860,6 +11011,10 @@ var OidcClient = class {
10860
11011
  try {
10861
11012
  return await this.#session.axios.post(url, form.toString(), config);
10862
11013
  } catch (err) {
11014
+ if (axiosStatus3(err) === 429) {
11015
+ const protocol = oauth2ErrorFromBody(axiosBody(err));
11016
+ if (protocol) throw protocol;
11017
+ }
10863
11018
  throw mapOidcError(err, url, fallbackMessage);
10864
11019
  }
10865
11020
  }