@naylence/agent-sdk 0.3.4-test.722 → 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.924
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.924';
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.
@@ -48842,7 +48842,7 @@
48842
48842
  }
48843
48843
  if (!certificateManager) {
48844
48844
  certificateManager =
48845
- await DefaultSecurityManagerFactory.createCertificateManagerFromConfig(config, policy);
48845
+ await DefaultSecurityManagerFactory.createCertificateManagerFromConfig(config, policy, trustStoreProvider);
48846
48846
  }
48847
48847
  return new DefaultSecurityManager(policy, envelopeSigner, envelopeVerifier, encryptionManager, keyManager, authorizer, certificateManager, secureChannelManager, keyValidator ?? null);
48848
48848
  }
@@ -49098,7 +49098,7 @@
49098
49098
  throw error instanceof Error ? error : new Error(String(error));
49099
49099
  }
49100
49100
  }
49101
- static async createCertificateManagerFromConfig(config, policy) {
49101
+ static async createCertificateManagerFromConfig(config, policy, trustStoreProvider) {
49102
49102
  const certificateConfig = config.certificate_manager ?? null;
49103
49103
  if (certificateConfig &&
49104
49104
  DefaultSecurityManagerFactory.isConfigLike(certificateConfig)) {
@@ -49111,8 +49111,12 @@
49111
49111
  return null;
49112
49112
  }
49113
49113
  const signing = policy.signing ?? null;
49114
+ const trustStorePem = trustStoreProvider
49115
+ ? async () => await trustStoreProvider.getTrustStorePem()
49116
+ : null;
49114
49117
  return await CertificateManagerFactory.createCertificateManager(null, {
49115
49118
  signing: signing ?? null,
49119
+ factoryArgs: trustStorePem ? [trustStorePem] : [],
49116
49120
  });
49117
49121
  }
49118
49122
  catch (error) {
@@ -52955,14 +52959,18 @@
52955
52959
  }
52956
52960
  return Math.max(1, Math.floor(value));
52957
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();
52958
52970
  const STORAGE_NAMESPACE = 'naylence.oauth2_pkce.';
52959
- const TOKEN_STORAGE_SUFFIX = '.token';
52960
52971
  function getStorageKey(clientId) {
52961
52972
  return `${STORAGE_NAMESPACE}${clientId}`;
52962
52973
  }
52963
- function getTokenStorageKey(clientId) {
52964
- return `${STORAGE_NAMESPACE}${clientId}${TOKEN_STORAGE_SUFFIX}`;
52965
- }
52966
52974
  function isBrowserEnvironment() {
52967
52975
  return (typeof window !== 'undefined' &&
52968
52976
  typeof window.location !== 'undefined' &&
@@ -53014,57 +53022,23 @@
53014
53022
  }
53015
53023
  return [...scopes].sort().join(' ');
53016
53024
  }
53025
+ /**
53026
+ * Read token from in-memory cache.
53027
+ * Returns null if no cached token exists for the given clientId.
53028
+ */
53017
53029
  function readPersistedToken(clientId) {
53018
- if (!isBrowserEnvironment()) {
53019
- return null;
53020
- }
53021
- try {
53022
- const raw = window.sessionStorage.getItem(getTokenStorageKey(clientId));
53023
- if (!raw) {
53024
- return null;
53025
- }
53026
- const parsed = JSON.parse(raw);
53027
- const value = coerceString(parsed.value);
53028
- if (!value) {
53029
- return null;
53030
- }
53031
- const expiresAt = coerceNumber(parsed.expiresAt);
53032
- const scopes = normalizeScopes(parsed.scopes);
53033
- const audience = coerceString(parsed.audience);
53034
- const record = {
53035
- value,
53036
- scopes,
53037
- audience,
53038
- };
53039
- if (typeof expiresAt === 'number') {
53040
- record.expiresAt = expiresAt;
53041
- }
53042
- return record;
53043
- }
53044
- catch (error) {
53045
- logger$r.debug('pkce_token_storage_read_failed', {
53046
- error: error instanceof Error ? error.message : String(error),
53047
- });
53048
- return null;
53049
- }
53030
+ return inMemoryTokenCache.get(clientId) ?? null;
53050
53031
  }
53032
+ /**
53033
+ * Write token to in-memory cache.
53034
+ * If token is null, removes the cached token for the given clientId.
53035
+ */
53051
53036
  function writePersistedToken(clientId, token) {
53052
- if (!isBrowserEnvironment()) {
53037
+ if (!token) {
53038
+ inMemoryTokenCache.delete(clientId);
53053
53039
  return;
53054
53040
  }
53055
- const key = getTokenStorageKey(clientId);
53056
- try {
53057
- if (!token) {
53058
- window.sessionStorage.removeItem(key);
53059
- return;
53060
- }
53061
- window.sessionStorage.setItem(key, JSON.stringify(token));
53062
- }
53063
- catch (error) {
53064
- logger$r.debug('pkce_token_storage_write_failed', {
53065
- error: error instanceof Error ? error.message : String(error),
53066
- });
53067
- }
53041
+ inMemoryTokenCache.set(clientId, token);
53068
53042
  }
53069
53043
  function clearOAuthParamsFromUrl(url) {
53070
53044
  if (!isBrowserEnvironment()) {
@@ -53365,6 +53339,17 @@
53365
53339
  });
53366
53340
  return token;
53367
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
+ }
53368
53353
  }
53369
53354
 
53370
53355
  var oauth2PkceTokenProvider = /*#__PURE__*/Object.freeze({