@naylence/agent-sdk 0.3.4-test.723 → 0.3.4-test.724

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.
@@ -15671,12 +15671,12 @@
15671
15671
  // --- END ENV SHIM ---
15672
15672
 
15673
15673
  // This file is auto-generated during build - do not edit manually
15674
- // Generated from package.json version: 0.3.5-test.925
15674
+ // Generated from package.json version: 0.3.5-test.926
15675
15675
  /**
15676
15676
  * The package version, injected at build time.
15677
15677
  * @internal
15678
15678
  */
15679
- const VERSION$1 = '0.3.5-test.925';
15679
+ const VERSION$1 = '0.3.5-test.926';
15680
15680
 
15681
15681
  /**
15682
15682
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -52959,14 +52959,18 @@
52959
52959
  }
52960
52960
  return Math.max(1, Math.floor(value));
52961
52961
  }
52962
+ /**
52963
+ * In-memory token cache for PKCE tokens.
52964
+ *
52965
+ * Tokens are intentionally NOT persisted to localStorage or sessionStorage to avoid
52966
+ * stale-token issues when the OAuth2 server restarts and generates new signing keys.
52967
+ * Each fresh page load triggers a new PKCE flow when a token is needed.
52968
+ */
52969
+ let inMemoryTokenCache = new Map();
52962
52970
  const STORAGE_NAMESPACE = 'naylence.oauth2_pkce.';
52963
- const TOKEN_STORAGE_SUFFIX = '.token';
52964
52971
  function getStorageKey(clientId) {
52965
52972
  return `${STORAGE_NAMESPACE}${clientId}`;
52966
52973
  }
52967
- function getTokenStorageKey(clientId) {
52968
- return `${STORAGE_NAMESPACE}${clientId}${TOKEN_STORAGE_SUFFIX}`;
52969
- }
52970
52974
  function isBrowserEnvironment() {
52971
52975
  return (typeof window !== 'undefined' &&
52972
52976
  typeof window.location !== 'undefined' &&
@@ -53018,57 +53022,23 @@
53018
53022
  }
53019
53023
  return [...scopes].sort().join(' ');
53020
53024
  }
53025
+ /**
53026
+ * Read token from in-memory cache.
53027
+ * Returns null if no cached token exists for the given clientId.
53028
+ */
53021
53029
  function readPersistedToken(clientId) {
53022
- if (!isBrowserEnvironment()) {
53023
- return null;
53024
- }
53025
- try {
53026
- const raw = window.sessionStorage.getItem(getTokenStorageKey(clientId));
53027
- if (!raw) {
53028
- return null;
53029
- }
53030
- const parsed = JSON.parse(raw);
53031
- const value = coerceString(parsed.value);
53032
- if (!value) {
53033
- return null;
53034
- }
53035
- const expiresAt = coerceNumber(parsed.expiresAt);
53036
- const scopes = normalizeScopes(parsed.scopes);
53037
- const audience = coerceString(parsed.audience);
53038
- const record = {
53039
- value,
53040
- scopes,
53041
- audience,
53042
- };
53043
- if (typeof expiresAt === 'number') {
53044
- record.expiresAt = expiresAt;
53045
- }
53046
- return record;
53047
- }
53048
- catch (error) {
53049
- logger$r.debug('pkce_token_storage_read_failed', {
53050
- error: error instanceof Error ? error.message : String(error),
53051
- });
53052
- return null;
53053
- }
53030
+ return inMemoryTokenCache.get(clientId) ?? null;
53054
53031
  }
53032
+ /**
53033
+ * Write token to in-memory cache.
53034
+ * If token is null, removes the cached token for the given clientId.
53035
+ */
53055
53036
  function writePersistedToken(clientId, token) {
53056
- if (!isBrowserEnvironment()) {
53037
+ if (!token) {
53038
+ inMemoryTokenCache.delete(clientId);
53057
53039
  return;
53058
53040
  }
53059
- const key = getTokenStorageKey(clientId);
53060
- try {
53061
- if (!token) {
53062
- window.sessionStorage.removeItem(key);
53063
- return;
53064
- }
53065
- window.sessionStorage.setItem(key, JSON.stringify(token));
53066
- }
53067
- catch (error) {
53068
- logger$r.debug('pkce_token_storage_write_failed', {
53069
- error: error instanceof Error ? error.message : String(error),
53070
- });
53071
- }
53041
+ inMemoryTokenCache.set(clientId, token);
53072
53042
  }
53073
53043
  function clearOAuthParamsFromUrl(url) {
53074
53044
  if (!isBrowserEnvironment()) {
@@ -53369,6 +53339,17 @@
53369
53339
  });
53370
53340
  return token;
53371
53341
  }
53342
+ /**
53343
+ * Clear the cached token for this provider instance.
53344
+ * This clears both the instance cache and the in-memory module cache.
53345
+ */
53346
+ clearToken() {
53347
+ this.cachedToken = undefined;
53348
+ writePersistedToken(this.options.clientId, null);
53349
+ logger$r.debug('oauth2_pkce_token_cleared', {
53350
+ authorize_url: this.options.authorizeUrl,
53351
+ });
53352
+ }
53372
53353
  }
53373
53354
 
53374
53355
  var oauth2PkceTokenProvider = /*#__PURE__*/Object.freeze({