@naylence/runtime 0.3.5-test.924 → 0.3.5-test.926

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.
@@ -98,12 +98,12 @@ installProcessEnvShim();
98
98
  // --- END ENV SHIM ---
99
99
 
100
100
  // This file is auto-generated during build - do not edit manually
101
- // Generated from package.json version: 0.3.5-test.924
101
+ // Generated from package.json version: 0.3.5-test.926
102
102
  /**
103
103
  * The package version, injected at build time.
104
104
  * @internal
105
105
  */
106
- const VERSION = '0.3.5-test.924';
106
+ const VERSION = '0.3.5-test.926';
107
107
 
108
108
  /**
109
109
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -34891,7 +34891,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
34891
34891
  }
34892
34892
  if (!certificateManager) {
34893
34893
  certificateManager =
34894
- await DefaultSecurityManagerFactory.createCertificateManagerFromConfig(config, policy);
34894
+ await DefaultSecurityManagerFactory.createCertificateManagerFromConfig(config, policy, trustStoreProvider);
34895
34895
  }
34896
34896
  return new DefaultSecurityManager(policy, envelopeSigner, envelopeVerifier, encryptionManager, keyManager, authorizer, certificateManager, secureChannelManager, keyValidator ?? null);
34897
34897
  }
@@ -35147,7 +35147,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
35147
35147
  throw error instanceof Error ? error : new Error(String(error));
35148
35148
  }
35149
35149
  }
35150
- static async createCertificateManagerFromConfig(config, policy) {
35150
+ static async createCertificateManagerFromConfig(config, policy, trustStoreProvider) {
35151
35151
  const certificateConfig = config.certificate_manager ?? null;
35152
35152
  if (certificateConfig &&
35153
35153
  DefaultSecurityManagerFactory.isConfigLike(certificateConfig)) {
@@ -35160,8 +35160,12 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
35160
35160
  return null;
35161
35161
  }
35162
35162
  const signing = policy.signing ?? null;
35163
+ const trustStorePem = trustStoreProvider
35164
+ ? async () => await trustStoreProvider.getTrustStorePem()
35165
+ : null;
35163
35166
  return await CertificateManagerFactory.createCertificateManager(null, {
35164
35167
  signing: signing ?? null,
35168
+ factoryArgs: trustStorePem ? [trustStorePem] : [],
35165
35169
  });
35166
35170
  }
35167
35171
  catch (error) {
@@ -39004,14 +39008,18 @@ function ensureFinitePositive(value, label) {
39004
39008
  }
39005
39009
  return Math.max(1, Math.floor(value));
39006
39010
  }
39011
+ /**
39012
+ * In-memory token cache for PKCE tokens.
39013
+ *
39014
+ * Tokens are intentionally NOT persisted to localStorage or sessionStorage to avoid
39015
+ * stale-token issues when the OAuth2 server restarts and generates new signing keys.
39016
+ * Each fresh page load triggers a new PKCE flow when a token is needed.
39017
+ */
39018
+ let inMemoryTokenCache = new Map();
39007
39019
  const STORAGE_NAMESPACE = 'naylence.oauth2_pkce.';
39008
- const TOKEN_STORAGE_SUFFIX = '.token';
39009
39020
  function getStorageKey(clientId) {
39010
39021
  return `${STORAGE_NAMESPACE}${clientId}`;
39011
39022
  }
39012
- function getTokenStorageKey(clientId) {
39013
- return `${STORAGE_NAMESPACE}${clientId}${TOKEN_STORAGE_SUFFIX}`;
39014
- }
39015
39023
  function isBrowserEnvironment() {
39016
39024
  return (typeof window !== 'undefined' &&
39017
39025
  typeof window.location !== 'undefined' &&
@@ -39063,57 +39071,23 @@ function stableScopeKey(scopes) {
39063
39071
  }
39064
39072
  return [...scopes].sort().join(' ');
39065
39073
  }
39074
+ /**
39075
+ * Read token from in-memory cache.
39076
+ * Returns null if no cached token exists for the given clientId.
39077
+ */
39066
39078
  function readPersistedToken(clientId) {
39067
- if (!isBrowserEnvironment()) {
39068
- return null;
39069
- }
39070
- try {
39071
- const raw = window.sessionStorage.getItem(getTokenStorageKey(clientId));
39072
- if (!raw) {
39073
- return null;
39074
- }
39075
- const parsed = JSON.parse(raw);
39076
- const value = coerceString(parsed.value);
39077
- if (!value) {
39078
- return null;
39079
- }
39080
- const expiresAt = coerceNumber(parsed.expiresAt);
39081
- const scopes = normalizeScopes(parsed.scopes);
39082
- const audience = coerceString(parsed.audience);
39083
- const record = {
39084
- value,
39085
- scopes,
39086
- audience,
39087
- };
39088
- if (typeof expiresAt === 'number') {
39089
- record.expiresAt = expiresAt;
39090
- }
39091
- return record;
39092
- }
39093
- catch (error) {
39094
- logger.debug('pkce_token_storage_read_failed', {
39095
- error: error instanceof Error ? error.message : String(error),
39096
- });
39097
- return null;
39098
- }
39079
+ return inMemoryTokenCache.get(clientId) ?? null;
39099
39080
  }
39081
+ /**
39082
+ * Write token to in-memory cache.
39083
+ * If token is null, removes the cached token for the given clientId.
39084
+ */
39100
39085
  function writePersistedToken(clientId, token) {
39101
- if (!isBrowserEnvironment()) {
39086
+ if (!token) {
39087
+ inMemoryTokenCache.delete(clientId);
39102
39088
  return;
39103
39089
  }
39104
- const key = getTokenStorageKey(clientId);
39105
- try {
39106
- if (!token) {
39107
- window.sessionStorage.removeItem(key);
39108
- return;
39109
- }
39110
- window.sessionStorage.setItem(key, JSON.stringify(token));
39111
- }
39112
- catch (error) {
39113
- logger.debug('pkce_token_storage_write_failed', {
39114
- error: error instanceof Error ? error.message : String(error),
39115
- });
39116
- }
39090
+ inMemoryTokenCache.set(clientId, token);
39117
39091
  }
39118
39092
  function clearOAuthParamsFromUrl(url) {
39119
39093
  if (!isBrowserEnvironment()) {
@@ -39414,6 +39388,17 @@ class OAuth2PkceTokenProvider {
39414
39388
  });
39415
39389
  return token;
39416
39390
  }
39391
+ /**
39392
+ * Clear the cached token for this provider instance.
39393
+ * This clears both the instance cache and the in-memory module cache.
39394
+ */
39395
+ clearToken() {
39396
+ this.cachedToken = undefined;
39397
+ writePersistedToken(this.options.clientId, null);
39398
+ logger.debug('oauth2_pkce_token_cleared', {
39399
+ authorize_url: this.options.authorizeUrl,
39400
+ });
39401
+ }
39417
39402
  }
39418
39403
 
39419
39404
  var oauth2PkceTokenProvider = /*#__PURE__*/Object.freeze({
@@ -96,12 +96,12 @@ installProcessEnvShim();
96
96
  // --- END ENV SHIM ---
97
97
 
98
98
  // This file is auto-generated during build - do not edit manually
99
- // Generated from package.json version: 0.3.5-test.924
99
+ // Generated from package.json version: 0.3.5-test.926
100
100
  /**
101
101
  * The package version, injected at build time.
102
102
  * @internal
103
103
  */
104
- const VERSION = '0.3.5-test.924';
104
+ const VERSION = '0.3.5-test.926';
105
105
 
106
106
  /**
107
107
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -34889,7 +34889,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
34889
34889
  }
34890
34890
  if (!certificateManager) {
34891
34891
  certificateManager =
34892
- await DefaultSecurityManagerFactory.createCertificateManagerFromConfig(config, policy);
34892
+ await DefaultSecurityManagerFactory.createCertificateManagerFromConfig(config, policy, trustStoreProvider);
34893
34893
  }
34894
34894
  return new DefaultSecurityManager(policy, envelopeSigner, envelopeVerifier, encryptionManager, keyManager, authorizer, certificateManager, secureChannelManager, keyValidator ?? null);
34895
34895
  }
@@ -35145,7 +35145,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
35145
35145
  throw error instanceof Error ? error : new Error(String(error));
35146
35146
  }
35147
35147
  }
35148
- static async createCertificateManagerFromConfig(config, policy) {
35148
+ static async createCertificateManagerFromConfig(config, policy, trustStoreProvider) {
35149
35149
  const certificateConfig = config.certificate_manager ?? null;
35150
35150
  if (certificateConfig &&
35151
35151
  DefaultSecurityManagerFactory.isConfigLike(certificateConfig)) {
@@ -35158,8 +35158,12 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
35158
35158
  return null;
35159
35159
  }
35160
35160
  const signing = policy.signing ?? null;
35161
+ const trustStorePem = trustStoreProvider
35162
+ ? async () => await trustStoreProvider.getTrustStorePem()
35163
+ : null;
35161
35164
  return await CertificateManagerFactory.createCertificateManager(null, {
35162
35165
  signing: signing ?? null,
35166
+ factoryArgs: trustStorePem ? [trustStorePem] : [],
35163
35167
  });
35164
35168
  }
35165
35169
  catch (error) {
@@ -39002,14 +39006,18 @@ function ensureFinitePositive(value, label) {
39002
39006
  }
39003
39007
  return Math.max(1, Math.floor(value));
39004
39008
  }
39009
+ /**
39010
+ * In-memory token cache for PKCE tokens.
39011
+ *
39012
+ * Tokens are intentionally NOT persisted to localStorage or sessionStorage to avoid
39013
+ * stale-token issues when the OAuth2 server restarts and generates new signing keys.
39014
+ * Each fresh page load triggers a new PKCE flow when a token is needed.
39015
+ */
39016
+ let inMemoryTokenCache = new Map();
39005
39017
  const STORAGE_NAMESPACE = 'naylence.oauth2_pkce.';
39006
- const TOKEN_STORAGE_SUFFIX = '.token';
39007
39018
  function getStorageKey(clientId) {
39008
39019
  return `${STORAGE_NAMESPACE}${clientId}`;
39009
39020
  }
39010
- function getTokenStorageKey(clientId) {
39011
- return `${STORAGE_NAMESPACE}${clientId}${TOKEN_STORAGE_SUFFIX}`;
39012
- }
39013
39021
  function isBrowserEnvironment() {
39014
39022
  return (typeof window !== 'undefined' &&
39015
39023
  typeof window.location !== 'undefined' &&
@@ -39061,57 +39069,23 @@ function stableScopeKey(scopes) {
39061
39069
  }
39062
39070
  return [...scopes].sort().join(' ');
39063
39071
  }
39072
+ /**
39073
+ * Read token from in-memory cache.
39074
+ * Returns null if no cached token exists for the given clientId.
39075
+ */
39064
39076
  function readPersistedToken(clientId) {
39065
- if (!isBrowserEnvironment()) {
39066
- return null;
39067
- }
39068
- try {
39069
- const raw = window.sessionStorage.getItem(getTokenStorageKey(clientId));
39070
- if (!raw) {
39071
- return null;
39072
- }
39073
- const parsed = JSON.parse(raw);
39074
- const value = coerceString(parsed.value);
39075
- if (!value) {
39076
- return null;
39077
- }
39078
- const expiresAt = coerceNumber(parsed.expiresAt);
39079
- const scopes = normalizeScopes(parsed.scopes);
39080
- const audience = coerceString(parsed.audience);
39081
- const record = {
39082
- value,
39083
- scopes,
39084
- audience,
39085
- };
39086
- if (typeof expiresAt === 'number') {
39087
- record.expiresAt = expiresAt;
39088
- }
39089
- return record;
39090
- }
39091
- catch (error) {
39092
- logger.debug('pkce_token_storage_read_failed', {
39093
- error: error instanceof Error ? error.message : String(error),
39094
- });
39095
- return null;
39096
- }
39077
+ return inMemoryTokenCache.get(clientId) ?? null;
39097
39078
  }
39079
+ /**
39080
+ * Write token to in-memory cache.
39081
+ * If token is null, removes the cached token for the given clientId.
39082
+ */
39098
39083
  function writePersistedToken(clientId, token) {
39099
- if (!isBrowserEnvironment()) {
39084
+ if (!token) {
39085
+ inMemoryTokenCache.delete(clientId);
39100
39086
  return;
39101
39087
  }
39102
- const key = getTokenStorageKey(clientId);
39103
- try {
39104
- if (!token) {
39105
- window.sessionStorage.removeItem(key);
39106
- return;
39107
- }
39108
- window.sessionStorage.setItem(key, JSON.stringify(token));
39109
- }
39110
- catch (error) {
39111
- logger.debug('pkce_token_storage_write_failed', {
39112
- error: error instanceof Error ? error.message : String(error),
39113
- });
39114
- }
39088
+ inMemoryTokenCache.set(clientId, token);
39115
39089
  }
39116
39090
  function clearOAuthParamsFromUrl(url) {
39117
39091
  if (!isBrowserEnvironment()) {
@@ -39412,6 +39386,17 @@ class OAuth2PkceTokenProvider {
39412
39386
  });
39413
39387
  return token;
39414
39388
  }
39389
+ /**
39390
+ * Clear the cached token for this provider instance.
39391
+ * This clears both the instance cache and the in-memory module cache.
39392
+ */
39393
+ clearToken() {
39394
+ this.cachedToken = undefined;
39395
+ writePersistedToken(this.options.clientId, null);
39396
+ logger.debug('oauth2_pkce_token_cleared', {
39397
+ authorize_url: this.options.authorizeUrl,
39398
+ });
39399
+ }
39415
39400
  }
39416
39401
 
39417
39402
  var oauth2PkceTokenProvider = /*#__PURE__*/Object.freeze({
@@ -145,14 +145,18 @@ function ensureFinitePositive(value, label) {
145
145
  }
146
146
  return Math.max(1, Math.floor(value));
147
147
  }
148
+ /**
149
+ * In-memory token cache for PKCE tokens.
150
+ *
151
+ * Tokens are intentionally NOT persisted to localStorage or sessionStorage to avoid
152
+ * stale-token issues when the OAuth2 server restarts and generates new signing keys.
153
+ * Each fresh page load triggers a new PKCE flow when a token is needed.
154
+ */
155
+ let inMemoryTokenCache = new Map();
148
156
  const STORAGE_NAMESPACE = 'naylence.oauth2_pkce.';
149
- const TOKEN_STORAGE_SUFFIX = '.token';
150
157
  function getStorageKey(clientId) {
151
158
  return `${STORAGE_NAMESPACE}${clientId}`;
152
159
  }
153
- function getTokenStorageKey(clientId) {
154
- return `${STORAGE_NAMESPACE}${clientId}${TOKEN_STORAGE_SUFFIX}`;
155
- }
156
160
  function isBrowserEnvironment() {
157
161
  return (typeof window !== 'undefined' &&
158
162
  typeof window.location !== 'undefined' &&
@@ -204,57 +208,23 @@ function stableScopeKey(scopes) {
204
208
  }
205
209
  return [...scopes].sort().join(' ');
206
210
  }
211
+ /**
212
+ * Read token from in-memory cache.
213
+ * Returns null if no cached token exists for the given clientId.
214
+ */
207
215
  function readPersistedToken(clientId) {
208
- if (!isBrowserEnvironment()) {
209
- return null;
210
- }
211
- try {
212
- const raw = window.sessionStorage.getItem(getTokenStorageKey(clientId));
213
- if (!raw) {
214
- return null;
215
- }
216
- const parsed = JSON.parse(raw);
217
- const value = coerceString(parsed.value);
218
- if (!value) {
219
- return null;
220
- }
221
- const expiresAt = coerceNumber(parsed.expiresAt);
222
- const scopes = normalizeScopes(parsed.scopes);
223
- const audience = coerceString(parsed.audience);
224
- const record = {
225
- value,
226
- scopes,
227
- audience,
228
- };
229
- if (typeof expiresAt === 'number') {
230
- record.expiresAt = expiresAt;
231
- }
232
- return record;
233
- }
234
- catch (error) {
235
- logger.debug('pkce_token_storage_read_failed', {
236
- error: error instanceof Error ? error.message : String(error),
237
- });
238
- return null;
239
- }
216
+ return inMemoryTokenCache.get(clientId) ?? null;
240
217
  }
218
+ /**
219
+ * Write token to in-memory cache.
220
+ * If token is null, removes the cached token for the given clientId.
221
+ */
241
222
  function writePersistedToken(clientId, token) {
242
- if (!isBrowserEnvironment()) {
223
+ if (!token) {
224
+ inMemoryTokenCache.delete(clientId);
243
225
  return;
244
226
  }
245
- const key = getTokenStorageKey(clientId);
246
- try {
247
- if (!token) {
248
- window.sessionStorage.removeItem(key);
249
- return;
250
- }
251
- window.sessionStorage.setItem(key, JSON.stringify(token));
252
- }
253
- catch (error) {
254
- logger.debug('pkce_token_storage_write_failed', {
255
- error: error instanceof Error ? error.message : String(error),
256
- });
257
- }
227
+ inMemoryTokenCache.set(clientId, token);
258
228
  }
259
229
  function clearOAuthParamsFromUrl(url) {
260
230
  if (!isBrowserEnvironment()) {
@@ -556,5 +526,16 @@ class OAuth2PkceTokenProvider {
556
526
  });
557
527
  return token;
558
528
  }
529
+ /**
530
+ * Clear the cached token for this provider instance.
531
+ * This clears both the instance cache and the in-memory module cache.
532
+ */
533
+ clearToken() {
534
+ this.cachedToken = undefined;
535
+ writePersistedToken(this.options.clientId, null);
536
+ logger.debug('oauth2_pkce_token_cleared', {
537
+ authorize_url: this.options.authorizeUrl,
538
+ });
539
+ }
559
540
  }
560
541
  exports.OAuth2PkceTokenProvider = OAuth2PkceTokenProvider;
@@ -168,7 +168,7 @@ class DefaultSecurityManagerFactory extends security_manager_factory_js_1.Securi
168
168
  }
169
169
  if (!certificateManager) {
170
170
  certificateManager =
171
- await DefaultSecurityManagerFactory.createCertificateManagerFromConfig(config, policy);
171
+ await DefaultSecurityManagerFactory.createCertificateManagerFromConfig(config, policy, trustStoreProvider);
172
172
  }
173
173
  return new default_security_manager_js_1.DefaultSecurityManager(policy, envelopeSigner, envelopeVerifier, encryptionManager, keyManager, authorizer, certificateManager, secureChannelManager, keyValidator ?? null);
174
174
  }
@@ -424,7 +424,7 @@ class DefaultSecurityManagerFactory extends security_manager_factory_js_1.Securi
424
424
  throw error instanceof Error ? error : new Error(String(error));
425
425
  }
426
426
  }
427
- static async createCertificateManagerFromConfig(config, policy) {
427
+ static async createCertificateManagerFromConfig(config, policy, trustStoreProvider) {
428
428
  const certificateConfig = config.certificate_manager ?? null;
429
429
  if (certificateConfig &&
430
430
  DefaultSecurityManagerFactory.isConfigLike(certificateConfig)) {
@@ -437,8 +437,12 @@ class DefaultSecurityManagerFactory extends security_manager_factory_js_1.Securi
437
437
  return null;
438
438
  }
439
439
  const signing = policy.signing ?? null;
440
+ const trustStorePem = trustStoreProvider
441
+ ? async () => await trustStoreProvider.getTrustStorePem()
442
+ : null;
440
443
  return await certificate_manager_factory_js_1.CertificateManagerFactory.createCertificateManager(null, {
441
444
  signing: signing ?? null,
445
+ factoryArgs: trustStorePem ? [trustStorePem] : [],
442
446
  });
443
447
  }
444
448
  catch (error) {
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  // This file is auto-generated during build - do not edit manually
3
- // Generated from package.json version: 0.3.5-test.924
3
+ // Generated from package.json version: 0.3.5-test.926
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.VERSION = void 0;
6
6
  /**
7
7
  * The package version, injected at build time.
8
8
  * @internal
9
9
  */
10
- exports.VERSION = '0.3.5-test.924';
10
+ exports.VERSION = '0.3.5-test.926';
@@ -142,14 +142,18 @@ function ensureFinitePositive(value, label) {
142
142
  }
143
143
  return Math.max(1, Math.floor(value));
144
144
  }
145
+ /**
146
+ * In-memory token cache for PKCE tokens.
147
+ *
148
+ * Tokens are intentionally NOT persisted to localStorage or sessionStorage to avoid
149
+ * stale-token issues when the OAuth2 server restarts and generates new signing keys.
150
+ * Each fresh page load triggers a new PKCE flow when a token is needed.
151
+ */
152
+ let inMemoryTokenCache = new Map();
145
153
  const STORAGE_NAMESPACE = 'naylence.oauth2_pkce.';
146
- const TOKEN_STORAGE_SUFFIX = '.token';
147
154
  function getStorageKey(clientId) {
148
155
  return `${STORAGE_NAMESPACE}${clientId}`;
149
156
  }
150
- function getTokenStorageKey(clientId) {
151
- return `${STORAGE_NAMESPACE}${clientId}${TOKEN_STORAGE_SUFFIX}`;
152
- }
153
157
  function isBrowserEnvironment() {
154
158
  return (typeof window !== 'undefined' &&
155
159
  typeof window.location !== 'undefined' &&
@@ -201,57 +205,23 @@ function stableScopeKey(scopes) {
201
205
  }
202
206
  return [...scopes].sort().join(' ');
203
207
  }
208
+ /**
209
+ * Read token from in-memory cache.
210
+ * Returns null if no cached token exists for the given clientId.
211
+ */
204
212
  function readPersistedToken(clientId) {
205
- if (!isBrowserEnvironment()) {
206
- return null;
207
- }
208
- try {
209
- const raw = window.sessionStorage.getItem(getTokenStorageKey(clientId));
210
- if (!raw) {
211
- return null;
212
- }
213
- const parsed = JSON.parse(raw);
214
- const value = coerceString(parsed.value);
215
- if (!value) {
216
- return null;
217
- }
218
- const expiresAt = coerceNumber(parsed.expiresAt);
219
- const scopes = normalizeScopes(parsed.scopes);
220
- const audience = coerceString(parsed.audience);
221
- const record = {
222
- value,
223
- scopes,
224
- audience,
225
- };
226
- if (typeof expiresAt === 'number') {
227
- record.expiresAt = expiresAt;
228
- }
229
- return record;
230
- }
231
- catch (error) {
232
- logger.debug('pkce_token_storage_read_failed', {
233
- error: error instanceof Error ? error.message : String(error),
234
- });
235
- return null;
236
- }
213
+ return inMemoryTokenCache.get(clientId) ?? null;
237
214
  }
215
+ /**
216
+ * Write token to in-memory cache.
217
+ * If token is null, removes the cached token for the given clientId.
218
+ */
238
219
  function writePersistedToken(clientId, token) {
239
- if (!isBrowserEnvironment()) {
220
+ if (!token) {
221
+ inMemoryTokenCache.delete(clientId);
240
222
  return;
241
223
  }
242
- const key = getTokenStorageKey(clientId);
243
- try {
244
- if (!token) {
245
- window.sessionStorage.removeItem(key);
246
- return;
247
- }
248
- window.sessionStorage.setItem(key, JSON.stringify(token));
249
- }
250
- catch (error) {
251
- logger.debug('pkce_token_storage_write_failed', {
252
- error: error instanceof Error ? error.message : String(error),
253
- });
254
- }
224
+ inMemoryTokenCache.set(clientId, token);
255
225
  }
256
226
  function clearOAuthParamsFromUrl(url) {
257
227
  if (!isBrowserEnvironment()) {
@@ -552,4 +522,15 @@ export class OAuth2PkceTokenProvider {
552
522
  });
553
523
  return token;
554
524
  }
525
+ /**
526
+ * Clear the cached token for this provider instance.
527
+ * This clears both the instance cache and the in-memory module cache.
528
+ */
529
+ clearToken() {
530
+ this.cachedToken = undefined;
531
+ writePersistedToken(this.options.clientId, null);
532
+ logger.debug('oauth2_pkce_token_cleared', {
533
+ authorize_url: this.options.authorizeUrl,
534
+ });
535
+ }
555
536
  }
@@ -165,7 +165,7 @@ export class DefaultSecurityManagerFactory extends SecurityManagerFactory {
165
165
  }
166
166
  if (!certificateManager) {
167
167
  certificateManager =
168
- await DefaultSecurityManagerFactory.createCertificateManagerFromConfig(config, policy);
168
+ await DefaultSecurityManagerFactory.createCertificateManagerFromConfig(config, policy, trustStoreProvider);
169
169
  }
170
170
  return new DefaultSecurityManager(policy, envelopeSigner, envelopeVerifier, encryptionManager, keyManager, authorizer, certificateManager, secureChannelManager, keyValidator ?? null);
171
171
  }
@@ -421,7 +421,7 @@ export class DefaultSecurityManagerFactory extends SecurityManagerFactory {
421
421
  throw error instanceof Error ? error : new Error(String(error));
422
422
  }
423
423
  }
424
- static async createCertificateManagerFromConfig(config, policy) {
424
+ static async createCertificateManagerFromConfig(config, policy, trustStoreProvider) {
425
425
  const certificateConfig = config.certificate_manager ?? null;
426
426
  if (certificateConfig &&
427
427
  DefaultSecurityManagerFactory.isConfigLike(certificateConfig)) {
@@ -434,8 +434,12 @@ export class DefaultSecurityManagerFactory extends SecurityManagerFactory {
434
434
  return null;
435
435
  }
436
436
  const signing = policy.signing ?? null;
437
+ const trustStorePem = trustStoreProvider
438
+ ? async () => await trustStoreProvider.getTrustStorePem()
439
+ : null;
437
440
  return await CertificateManagerFactory.createCertificateManager(null, {
438
441
  signing: signing ?? null,
442
+ factoryArgs: trustStorePem ? [trustStorePem] : [],
439
443
  });
440
444
  }
441
445
  catch (error) {
@@ -1,7 +1,7 @@
1
1
  // This file is auto-generated during build - do not edit manually
2
- // Generated from package.json version: 0.3.5-test.924
2
+ // Generated from package.json version: 0.3.5-test.926
3
3
  /**
4
4
  * The package version, injected at build time.
5
5
  * @internal
6
6
  */
7
- export const VERSION = '0.3.5-test.924';
7
+ export const VERSION = '0.3.5-test.926';
@@ -14,12 +14,12 @@ var fastify = require('fastify');
14
14
  var websocketPlugin = require('@fastify/websocket');
15
15
 
16
16
  // This file is auto-generated during build - do not edit manually
17
- // Generated from package.json version: 0.3.5-test.924
17
+ // Generated from package.json version: 0.3.5-test.926
18
18
  /**
19
19
  * The package version, injected at build time.
20
20
  * @internal
21
21
  */
22
- const VERSION = '0.3.5-test.924';
22
+ const VERSION = '0.3.5-test.926';
23
23
 
24
24
  /**
25
25
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -33613,7 +33613,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
33613
33613
  }
33614
33614
  if (!certificateManager) {
33615
33615
  certificateManager =
33616
- await DefaultSecurityManagerFactory.createCertificateManagerFromConfig(config, policy);
33616
+ await DefaultSecurityManagerFactory.createCertificateManagerFromConfig(config, policy, trustStoreProvider);
33617
33617
  }
33618
33618
  return new DefaultSecurityManager(policy, envelopeSigner, envelopeVerifier, encryptionManager, keyManager, authorizer, certificateManager, secureChannelManager, keyValidator ?? null);
33619
33619
  }
@@ -33869,7 +33869,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
33869
33869
  throw error instanceof Error ? error : new Error(String(error));
33870
33870
  }
33871
33871
  }
33872
- static async createCertificateManagerFromConfig(config, policy) {
33872
+ static async createCertificateManagerFromConfig(config, policy, trustStoreProvider) {
33873
33873
  const certificateConfig = config.certificate_manager ?? null;
33874
33874
  if (certificateConfig &&
33875
33875
  DefaultSecurityManagerFactory.isConfigLike(certificateConfig)) {
@@ -33882,8 +33882,12 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
33882
33882
  return null;
33883
33883
  }
33884
33884
  const signing = policy.signing ?? null;
33885
+ const trustStorePem = trustStoreProvider
33886
+ ? async () => await trustStoreProvider.getTrustStorePem()
33887
+ : null;
33885
33888
  return await CertificateManagerFactory.createCertificateManager(null, {
33886
33889
  signing: signing ?? null,
33890
+ factoryArgs: trustStorePem ? [trustStorePem] : [],
33887
33891
  });
33888
33892
  }
33889
33893
  catch (error) {
@@ -38918,14 +38922,18 @@ function ensureFinitePositive(value, label) {
38918
38922
  }
38919
38923
  return Math.max(1, Math.floor(value));
38920
38924
  }
38925
+ /**
38926
+ * In-memory token cache for PKCE tokens.
38927
+ *
38928
+ * Tokens are intentionally NOT persisted to localStorage or sessionStorage to avoid
38929
+ * stale-token issues when the OAuth2 server restarts and generates new signing keys.
38930
+ * Each fresh page load triggers a new PKCE flow when a token is needed.
38931
+ */
38932
+ let inMemoryTokenCache = new Map();
38921
38933
  const STORAGE_NAMESPACE = 'naylence.oauth2_pkce.';
38922
- const TOKEN_STORAGE_SUFFIX = '.token';
38923
38934
  function getStorageKey(clientId) {
38924
38935
  return `${STORAGE_NAMESPACE}${clientId}`;
38925
38936
  }
38926
- function getTokenStorageKey(clientId) {
38927
- return `${STORAGE_NAMESPACE}${clientId}${TOKEN_STORAGE_SUFFIX}`;
38928
- }
38929
38937
  function isBrowserEnvironment() {
38930
38938
  return (typeof window !== 'undefined' &&
38931
38939
  typeof window.location !== 'undefined' &&
@@ -38977,57 +38985,23 @@ function stableScopeKey(scopes) {
38977
38985
  }
38978
38986
  return [...scopes].sort().join(' ');
38979
38987
  }
38988
+ /**
38989
+ * Read token from in-memory cache.
38990
+ * Returns null if no cached token exists for the given clientId.
38991
+ */
38980
38992
  function readPersistedToken(clientId) {
38981
- if (!isBrowserEnvironment()) {
38982
- return null;
38983
- }
38984
- try {
38985
- const raw = window.sessionStorage.getItem(getTokenStorageKey(clientId));
38986
- if (!raw) {
38987
- return null;
38988
- }
38989
- const parsed = JSON.parse(raw);
38990
- const value = coerceString(parsed.value);
38991
- if (!value) {
38992
- return null;
38993
- }
38994
- const expiresAt = coerceNumber(parsed.expiresAt);
38995
- const scopes = normalizeScopes(parsed.scopes);
38996
- const audience = coerceString(parsed.audience);
38997
- const record = {
38998
- value,
38999
- scopes,
39000
- audience,
39001
- };
39002
- if (typeof expiresAt === 'number') {
39003
- record.expiresAt = expiresAt;
39004
- }
39005
- return record;
39006
- }
39007
- catch (error) {
39008
- logger.debug('pkce_token_storage_read_failed', {
39009
- error: error instanceof Error ? error.message : String(error),
39010
- });
39011
- return null;
39012
- }
38993
+ return inMemoryTokenCache.get(clientId) ?? null;
39013
38994
  }
38995
+ /**
38996
+ * Write token to in-memory cache.
38997
+ * If token is null, removes the cached token for the given clientId.
38998
+ */
39014
38999
  function writePersistedToken(clientId, token) {
39015
- if (!isBrowserEnvironment()) {
39000
+ if (!token) {
39001
+ inMemoryTokenCache.delete(clientId);
39016
39002
  return;
39017
39003
  }
39018
- const key = getTokenStorageKey(clientId);
39019
- try {
39020
- if (!token) {
39021
- window.sessionStorage.removeItem(key);
39022
- return;
39023
- }
39024
- window.sessionStorage.setItem(key, JSON.stringify(token));
39025
- }
39026
- catch (error) {
39027
- logger.debug('pkce_token_storage_write_failed', {
39028
- error: error instanceof Error ? error.message : String(error),
39029
- });
39030
- }
39004
+ inMemoryTokenCache.set(clientId, token);
39031
39005
  }
39032
39006
  function clearOAuthParamsFromUrl(url) {
39033
39007
  if (!isBrowserEnvironment()) {
@@ -39328,6 +39302,17 @@ class OAuth2PkceTokenProvider {
39328
39302
  });
39329
39303
  return token;
39330
39304
  }
39305
+ /**
39306
+ * Clear the cached token for this provider instance.
39307
+ * This clears both the instance cache and the in-memory module cache.
39308
+ */
39309
+ clearToken() {
39310
+ this.cachedToken = undefined;
39311
+ writePersistedToken(this.options.clientId, null);
39312
+ logger.debug('oauth2_pkce_token_cleared', {
39313
+ authorize_url: this.options.authorizeUrl,
39314
+ });
39315
+ }
39331
39316
  }
39332
39317
 
39333
39318
  var oauth2PkceTokenProvider = /*#__PURE__*/Object.freeze({
@@ -13,12 +13,12 @@ import fastify from 'fastify';
13
13
  import websocketPlugin from '@fastify/websocket';
14
14
 
15
15
  // This file is auto-generated during build - do not edit manually
16
- // Generated from package.json version: 0.3.5-test.924
16
+ // Generated from package.json version: 0.3.5-test.926
17
17
  /**
18
18
  * The package version, injected at build time.
19
19
  * @internal
20
20
  */
21
- const VERSION = '0.3.5-test.924';
21
+ const VERSION = '0.3.5-test.926';
22
22
 
23
23
  /**
24
24
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -33612,7 +33612,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
33612
33612
  }
33613
33613
  if (!certificateManager) {
33614
33614
  certificateManager =
33615
- await DefaultSecurityManagerFactory.createCertificateManagerFromConfig(config, policy);
33615
+ await DefaultSecurityManagerFactory.createCertificateManagerFromConfig(config, policy, trustStoreProvider);
33616
33616
  }
33617
33617
  return new DefaultSecurityManager(policy, envelopeSigner, envelopeVerifier, encryptionManager, keyManager, authorizer, certificateManager, secureChannelManager, keyValidator ?? null);
33618
33618
  }
@@ -33868,7 +33868,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
33868
33868
  throw error instanceof Error ? error : new Error(String(error));
33869
33869
  }
33870
33870
  }
33871
- static async createCertificateManagerFromConfig(config, policy) {
33871
+ static async createCertificateManagerFromConfig(config, policy, trustStoreProvider) {
33872
33872
  const certificateConfig = config.certificate_manager ?? null;
33873
33873
  if (certificateConfig &&
33874
33874
  DefaultSecurityManagerFactory.isConfigLike(certificateConfig)) {
@@ -33881,8 +33881,12 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
33881
33881
  return null;
33882
33882
  }
33883
33883
  const signing = policy.signing ?? null;
33884
+ const trustStorePem = trustStoreProvider
33885
+ ? async () => await trustStoreProvider.getTrustStorePem()
33886
+ : null;
33884
33887
  return await CertificateManagerFactory.createCertificateManager(null, {
33885
33888
  signing: signing ?? null,
33889
+ factoryArgs: trustStorePem ? [trustStorePem] : [],
33886
33890
  });
33887
33891
  }
33888
33892
  catch (error) {
@@ -38917,14 +38921,18 @@ function ensureFinitePositive(value, label) {
38917
38921
  }
38918
38922
  return Math.max(1, Math.floor(value));
38919
38923
  }
38924
+ /**
38925
+ * In-memory token cache for PKCE tokens.
38926
+ *
38927
+ * Tokens are intentionally NOT persisted to localStorage or sessionStorage to avoid
38928
+ * stale-token issues when the OAuth2 server restarts and generates new signing keys.
38929
+ * Each fresh page load triggers a new PKCE flow when a token is needed.
38930
+ */
38931
+ let inMemoryTokenCache = new Map();
38920
38932
  const STORAGE_NAMESPACE = 'naylence.oauth2_pkce.';
38921
- const TOKEN_STORAGE_SUFFIX = '.token';
38922
38933
  function getStorageKey(clientId) {
38923
38934
  return `${STORAGE_NAMESPACE}${clientId}`;
38924
38935
  }
38925
- function getTokenStorageKey(clientId) {
38926
- return `${STORAGE_NAMESPACE}${clientId}${TOKEN_STORAGE_SUFFIX}`;
38927
- }
38928
38936
  function isBrowserEnvironment() {
38929
38937
  return (typeof window !== 'undefined' &&
38930
38938
  typeof window.location !== 'undefined' &&
@@ -38976,57 +38984,23 @@ function stableScopeKey(scopes) {
38976
38984
  }
38977
38985
  return [...scopes].sort().join(' ');
38978
38986
  }
38987
+ /**
38988
+ * Read token from in-memory cache.
38989
+ * Returns null if no cached token exists for the given clientId.
38990
+ */
38979
38991
  function readPersistedToken(clientId) {
38980
- if (!isBrowserEnvironment()) {
38981
- return null;
38982
- }
38983
- try {
38984
- const raw = window.sessionStorage.getItem(getTokenStorageKey(clientId));
38985
- if (!raw) {
38986
- return null;
38987
- }
38988
- const parsed = JSON.parse(raw);
38989
- const value = coerceString(parsed.value);
38990
- if (!value) {
38991
- return null;
38992
- }
38993
- const expiresAt = coerceNumber(parsed.expiresAt);
38994
- const scopes = normalizeScopes(parsed.scopes);
38995
- const audience = coerceString(parsed.audience);
38996
- const record = {
38997
- value,
38998
- scopes,
38999
- audience,
39000
- };
39001
- if (typeof expiresAt === 'number') {
39002
- record.expiresAt = expiresAt;
39003
- }
39004
- return record;
39005
- }
39006
- catch (error) {
39007
- logger.debug('pkce_token_storage_read_failed', {
39008
- error: error instanceof Error ? error.message : String(error),
39009
- });
39010
- return null;
39011
- }
38992
+ return inMemoryTokenCache.get(clientId) ?? null;
39012
38993
  }
38994
+ /**
38995
+ * Write token to in-memory cache.
38996
+ * If token is null, removes the cached token for the given clientId.
38997
+ */
39013
38998
  function writePersistedToken(clientId, token) {
39014
- if (!isBrowserEnvironment()) {
38999
+ if (!token) {
39000
+ inMemoryTokenCache.delete(clientId);
39015
39001
  return;
39016
39002
  }
39017
- const key = getTokenStorageKey(clientId);
39018
- try {
39019
- if (!token) {
39020
- window.sessionStorage.removeItem(key);
39021
- return;
39022
- }
39023
- window.sessionStorage.setItem(key, JSON.stringify(token));
39024
- }
39025
- catch (error) {
39026
- logger.debug('pkce_token_storage_write_failed', {
39027
- error: error instanceof Error ? error.message : String(error),
39028
- });
39029
- }
39003
+ inMemoryTokenCache.set(clientId, token);
39030
39004
  }
39031
39005
  function clearOAuthParamsFromUrl(url) {
39032
39006
  if (!isBrowserEnvironment()) {
@@ -39327,6 +39301,17 @@ class OAuth2PkceTokenProvider {
39327
39301
  });
39328
39302
  return token;
39329
39303
  }
39304
+ /**
39305
+ * Clear the cached token for this provider instance.
39306
+ * This clears both the instance cache and the in-memory module cache.
39307
+ */
39308
+ clearToken() {
39309
+ this.cachedToken = undefined;
39310
+ writePersistedToken(this.options.clientId, null);
39311
+ logger.debug('oauth2_pkce_token_cleared', {
39312
+ authorize_url: this.options.authorizeUrl,
39313
+ });
39314
+ }
39330
39315
  }
39331
39316
 
39332
39317
  var oauth2PkceTokenProvider = /*#__PURE__*/Object.freeze({
@@ -5372,12 +5372,12 @@ for (const [name, config] of Object.entries(SQLITE_PROFILES)) {
5372
5372
  }
5373
5373
 
5374
5374
  // This file is auto-generated during build - do not edit manually
5375
- // Generated from package.json version: 0.3.5-test.924
5375
+ // Generated from package.json version: 0.3.5-test.926
5376
5376
  /**
5377
5377
  * The package version, injected at build time.
5378
5378
  * @internal
5379
5379
  */
5380
- const VERSION = '0.3.5-test.924';
5380
+ const VERSION = '0.3.5-test.926';
5381
5381
 
5382
5382
  /**
5383
5383
  * Fame errors module - Fame protocol specific error classes
@@ -38173,7 +38173,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
38173
38173
  }
38174
38174
  if (!certificateManager) {
38175
38175
  certificateManager =
38176
- await DefaultSecurityManagerFactory.createCertificateManagerFromConfig(config, policy);
38176
+ await DefaultSecurityManagerFactory.createCertificateManagerFromConfig(config, policy, trustStoreProvider);
38177
38177
  }
38178
38178
  return new DefaultSecurityManager(policy, envelopeSigner, envelopeVerifier, encryptionManager, keyManager, authorizer, certificateManager, secureChannelManager, keyValidator ?? null);
38179
38179
  }
@@ -38429,7 +38429,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
38429
38429
  throw error instanceof Error ? error : new Error(String(error));
38430
38430
  }
38431
38431
  }
38432
- static async createCertificateManagerFromConfig(config, policy) {
38432
+ static async createCertificateManagerFromConfig(config, policy, trustStoreProvider) {
38433
38433
  const certificateConfig = config.certificate_manager ?? null;
38434
38434
  if (certificateConfig &&
38435
38435
  DefaultSecurityManagerFactory.isConfigLike(certificateConfig)) {
@@ -38442,8 +38442,12 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
38442
38442
  return null;
38443
38443
  }
38444
38444
  const signing = policy.signing ?? null;
38445
+ const trustStorePem = trustStoreProvider
38446
+ ? async () => await trustStoreProvider.getTrustStorePem()
38447
+ : null;
38445
38448
  return await CertificateManagerFactory.createCertificateManager(null, {
38446
38449
  signing: signing ?? null,
38450
+ factoryArgs: trustStorePem ? [trustStorePem] : [],
38447
38451
  });
38448
38452
  }
38449
38453
  catch (error) {
@@ -41136,14 +41140,18 @@ function ensureFinitePositive(value, label) {
41136
41140
  }
41137
41141
  return Math.max(1, Math.floor(value));
41138
41142
  }
41143
+ /**
41144
+ * In-memory token cache for PKCE tokens.
41145
+ *
41146
+ * Tokens are intentionally NOT persisted to localStorage or sessionStorage to avoid
41147
+ * stale-token issues when the OAuth2 server restarts and generates new signing keys.
41148
+ * Each fresh page load triggers a new PKCE flow when a token is needed.
41149
+ */
41150
+ let inMemoryTokenCache = new Map();
41139
41151
  const STORAGE_NAMESPACE = 'naylence.oauth2_pkce.';
41140
- const TOKEN_STORAGE_SUFFIX = '.token';
41141
41152
  function getStorageKey(clientId) {
41142
41153
  return `${STORAGE_NAMESPACE}${clientId}`;
41143
41154
  }
41144
- function getTokenStorageKey(clientId) {
41145
- return `${STORAGE_NAMESPACE}${clientId}${TOKEN_STORAGE_SUFFIX}`;
41146
- }
41147
41155
  function isBrowserEnvironment() {
41148
41156
  return (typeof window !== 'undefined' &&
41149
41157
  typeof window.location !== 'undefined' &&
@@ -41195,57 +41203,23 @@ function stableScopeKey(scopes) {
41195
41203
  }
41196
41204
  return [...scopes].sort().join(' ');
41197
41205
  }
41206
+ /**
41207
+ * Read token from in-memory cache.
41208
+ * Returns null if no cached token exists for the given clientId.
41209
+ */
41198
41210
  function readPersistedToken(clientId) {
41199
- if (!isBrowserEnvironment()) {
41200
- return null;
41201
- }
41202
- try {
41203
- const raw = window.sessionStorage.getItem(getTokenStorageKey(clientId));
41204
- if (!raw) {
41205
- return null;
41206
- }
41207
- const parsed = JSON.parse(raw);
41208
- const value = coerceString(parsed.value);
41209
- if (!value) {
41210
- return null;
41211
- }
41212
- const expiresAt = coerceNumber(parsed.expiresAt);
41213
- const scopes = normalizeScopes(parsed.scopes);
41214
- const audience = coerceString(parsed.audience);
41215
- const record = {
41216
- value,
41217
- scopes,
41218
- audience,
41219
- };
41220
- if (typeof expiresAt === 'number') {
41221
- record.expiresAt = expiresAt;
41222
- }
41223
- return record;
41224
- }
41225
- catch (error) {
41226
- logger.debug('pkce_token_storage_read_failed', {
41227
- error: error instanceof Error ? error.message : String(error),
41228
- });
41229
- return null;
41230
- }
41211
+ return inMemoryTokenCache.get(clientId) ?? null;
41231
41212
  }
41213
+ /**
41214
+ * Write token to in-memory cache.
41215
+ * If token is null, removes the cached token for the given clientId.
41216
+ */
41232
41217
  function writePersistedToken(clientId, token) {
41233
- if (!isBrowserEnvironment()) {
41218
+ if (!token) {
41219
+ inMemoryTokenCache.delete(clientId);
41234
41220
  return;
41235
41221
  }
41236
- const key = getTokenStorageKey(clientId);
41237
- try {
41238
- if (!token) {
41239
- window.sessionStorage.removeItem(key);
41240
- return;
41241
- }
41242
- window.sessionStorage.setItem(key, JSON.stringify(token));
41243
- }
41244
- catch (error) {
41245
- logger.debug('pkce_token_storage_write_failed', {
41246
- error: error instanceof Error ? error.message : String(error),
41247
- });
41248
- }
41222
+ inMemoryTokenCache.set(clientId, token);
41249
41223
  }
41250
41224
  function clearOAuthParamsFromUrl(url) {
41251
41225
  if (!isBrowserEnvironment()) {
@@ -41546,6 +41520,17 @@ class OAuth2PkceTokenProvider {
41546
41520
  });
41547
41521
  return token;
41548
41522
  }
41523
+ /**
41524
+ * Clear the cached token for this provider instance.
41525
+ * This clears both the instance cache and the in-memory module cache.
41526
+ */
41527
+ clearToken() {
41528
+ this.cachedToken = undefined;
41529
+ writePersistedToken(this.options.clientId, null);
41530
+ logger.debug('oauth2_pkce_token_cleared', {
41531
+ authorize_url: this.options.authorizeUrl,
41532
+ });
41533
+ }
41549
41534
  }
41550
41535
 
41551
41536
  var oauth2PkceTokenProvider = /*#__PURE__*/Object.freeze({
@@ -5371,12 +5371,12 @@ for (const [name, config] of Object.entries(SQLITE_PROFILES)) {
5371
5371
  }
5372
5372
 
5373
5373
  // This file is auto-generated during build - do not edit manually
5374
- // Generated from package.json version: 0.3.5-test.924
5374
+ // Generated from package.json version: 0.3.5-test.926
5375
5375
  /**
5376
5376
  * The package version, injected at build time.
5377
5377
  * @internal
5378
5378
  */
5379
- const VERSION = '0.3.5-test.924';
5379
+ const VERSION = '0.3.5-test.926';
5380
5380
 
5381
5381
  /**
5382
5382
  * Fame errors module - Fame protocol specific error classes
@@ -38172,7 +38172,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
38172
38172
  }
38173
38173
  if (!certificateManager) {
38174
38174
  certificateManager =
38175
- await DefaultSecurityManagerFactory.createCertificateManagerFromConfig(config, policy);
38175
+ await DefaultSecurityManagerFactory.createCertificateManagerFromConfig(config, policy, trustStoreProvider);
38176
38176
  }
38177
38177
  return new DefaultSecurityManager(policy, envelopeSigner, envelopeVerifier, encryptionManager, keyManager, authorizer, certificateManager, secureChannelManager, keyValidator ?? null);
38178
38178
  }
@@ -38428,7 +38428,7 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
38428
38428
  throw error instanceof Error ? error : new Error(String(error));
38429
38429
  }
38430
38430
  }
38431
- static async createCertificateManagerFromConfig(config, policy) {
38431
+ static async createCertificateManagerFromConfig(config, policy, trustStoreProvider) {
38432
38432
  const certificateConfig = config.certificate_manager ?? null;
38433
38433
  if (certificateConfig &&
38434
38434
  DefaultSecurityManagerFactory.isConfigLike(certificateConfig)) {
@@ -38441,8 +38441,12 @@ class DefaultSecurityManagerFactory extends SecurityManagerFactory {
38441
38441
  return null;
38442
38442
  }
38443
38443
  const signing = policy.signing ?? null;
38444
+ const trustStorePem = trustStoreProvider
38445
+ ? async () => await trustStoreProvider.getTrustStorePem()
38446
+ : null;
38444
38447
  return await CertificateManagerFactory.createCertificateManager(null, {
38445
38448
  signing: signing ?? null,
38449
+ factoryArgs: trustStorePem ? [trustStorePem] : [],
38446
38450
  });
38447
38451
  }
38448
38452
  catch (error) {
@@ -41135,14 +41139,18 @@ function ensureFinitePositive(value, label) {
41135
41139
  }
41136
41140
  return Math.max(1, Math.floor(value));
41137
41141
  }
41142
+ /**
41143
+ * In-memory token cache for PKCE tokens.
41144
+ *
41145
+ * Tokens are intentionally NOT persisted to localStorage or sessionStorage to avoid
41146
+ * stale-token issues when the OAuth2 server restarts and generates new signing keys.
41147
+ * Each fresh page load triggers a new PKCE flow when a token is needed.
41148
+ */
41149
+ let inMemoryTokenCache = new Map();
41138
41150
  const STORAGE_NAMESPACE = 'naylence.oauth2_pkce.';
41139
- const TOKEN_STORAGE_SUFFIX = '.token';
41140
41151
  function getStorageKey(clientId) {
41141
41152
  return `${STORAGE_NAMESPACE}${clientId}`;
41142
41153
  }
41143
- function getTokenStorageKey(clientId) {
41144
- return `${STORAGE_NAMESPACE}${clientId}${TOKEN_STORAGE_SUFFIX}`;
41145
- }
41146
41154
  function isBrowserEnvironment() {
41147
41155
  return (typeof window !== 'undefined' &&
41148
41156
  typeof window.location !== 'undefined' &&
@@ -41194,57 +41202,23 @@ function stableScopeKey(scopes) {
41194
41202
  }
41195
41203
  return [...scopes].sort().join(' ');
41196
41204
  }
41205
+ /**
41206
+ * Read token from in-memory cache.
41207
+ * Returns null if no cached token exists for the given clientId.
41208
+ */
41197
41209
  function readPersistedToken(clientId) {
41198
- if (!isBrowserEnvironment()) {
41199
- return null;
41200
- }
41201
- try {
41202
- const raw = window.sessionStorage.getItem(getTokenStorageKey(clientId));
41203
- if (!raw) {
41204
- return null;
41205
- }
41206
- const parsed = JSON.parse(raw);
41207
- const value = coerceString(parsed.value);
41208
- if (!value) {
41209
- return null;
41210
- }
41211
- const expiresAt = coerceNumber(parsed.expiresAt);
41212
- const scopes = normalizeScopes(parsed.scopes);
41213
- const audience = coerceString(parsed.audience);
41214
- const record = {
41215
- value,
41216
- scopes,
41217
- audience,
41218
- };
41219
- if (typeof expiresAt === 'number') {
41220
- record.expiresAt = expiresAt;
41221
- }
41222
- return record;
41223
- }
41224
- catch (error) {
41225
- logger.debug('pkce_token_storage_read_failed', {
41226
- error: error instanceof Error ? error.message : String(error),
41227
- });
41228
- return null;
41229
- }
41210
+ return inMemoryTokenCache.get(clientId) ?? null;
41230
41211
  }
41212
+ /**
41213
+ * Write token to in-memory cache.
41214
+ * If token is null, removes the cached token for the given clientId.
41215
+ */
41231
41216
  function writePersistedToken(clientId, token) {
41232
- if (!isBrowserEnvironment()) {
41217
+ if (!token) {
41218
+ inMemoryTokenCache.delete(clientId);
41233
41219
  return;
41234
41220
  }
41235
- const key = getTokenStorageKey(clientId);
41236
- try {
41237
- if (!token) {
41238
- window.sessionStorage.removeItem(key);
41239
- return;
41240
- }
41241
- window.sessionStorage.setItem(key, JSON.stringify(token));
41242
- }
41243
- catch (error) {
41244
- logger.debug('pkce_token_storage_write_failed', {
41245
- error: error instanceof Error ? error.message : String(error),
41246
- });
41247
- }
41221
+ inMemoryTokenCache.set(clientId, token);
41248
41222
  }
41249
41223
  function clearOAuthParamsFromUrl(url) {
41250
41224
  if (!isBrowserEnvironment()) {
@@ -41545,6 +41519,17 @@ class OAuth2PkceTokenProvider {
41545
41519
  });
41546
41520
  return token;
41547
41521
  }
41522
+ /**
41523
+ * Clear the cached token for this provider instance.
41524
+ * This clears both the instance cache and the in-memory module cache.
41525
+ */
41526
+ clearToken() {
41527
+ this.cachedToken = undefined;
41528
+ writePersistedToken(this.options.clientId, null);
41529
+ logger.debug('oauth2_pkce_token_cleared', {
41530
+ authorize_url: this.options.authorizeUrl,
41531
+ });
41532
+ }
41548
41533
  }
41549
41534
 
41550
41535
  var oauth2PkceTokenProvider = /*#__PURE__*/Object.freeze({
@@ -38,5 +38,10 @@ export declare class OAuth2PkceTokenProvider implements TokenProvider {
38
38
  private resolveFetch;
39
39
  private resolveOptionalSecret;
40
40
  private exchangeToken;
41
+ /**
42
+ * Clear the cached token for this provider instance.
43
+ * This clears both the instance cache and the in-memory module cache.
44
+ */
45
+ clearToken(): void;
41
46
  }
42
47
  export {};
@@ -2,4 +2,4 @@
2
2
  * The package version, injected at build time.
3
3
  * @internal
4
4
  */
5
- export declare const VERSION = "0.3.5-test.924";
5
+ export declare const VERSION = "0.3.5-test.926";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naylence/runtime",
3
- "version": "0.3.5-test.924",
3
+ "version": "0.3.5-test.926",
4
4
  "type": "module",
5
5
  "description": "Naylence Runtime - Complete TypeScript runtime",
6
6
  "author": "Naylence Dev <naylencedev@gmail.com>",