@naylence/runtime 0.3.5-test.925 → 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.925
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.925';
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.
@@ -39008,14 +39008,18 @@ function ensureFinitePositive(value, label) {
39008
39008
  }
39009
39009
  return Math.max(1, Math.floor(value));
39010
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();
39011
39019
  const STORAGE_NAMESPACE = 'naylence.oauth2_pkce.';
39012
- const TOKEN_STORAGE_SUFFIX = '.token';
39013
39020
  function getStorageKey(clientId) {
39014
39021
  return `${STORAGE_NAMESPACE}${clientId}`;
39015
39022
  }
39016
- function getTokenStorageKey(clientId) {
39017
- return `${STORAGE_NAMESPACE}${clientId}${TOKEN_STORAGE_SUFFIX}`;
39018
- }
39019
39023
  function isBrowserEnvironment() {
39020
39024
  return (typeof window !== 'undefined' &&
39021
39025
  typeof window.location !== 'undefined' &&
@@ -39067,57 +39071,23 @@ function stableScopeKey(scopes) {
39067
39071
  }
39068
39072
  return [...scopes].sort().join(' ');
39069
39073
  }
39074
+ /**
39075
+ * Read token from in-memory cache.
39076
+ * Returns null if no cached token exists for the given clientId.
39077
+ */
39070
39078
  function readPersistedToken(clientId) {
39071
- if (!isBrowserEnvironment()) {
39072
- return null;
39073
- }
39074
- try {
39075
- const raw = window.sessionStorage.getItem(getTokenStorageKey(clientId));
39076
- if (!raw) {
39077
- return null;
39078
- }
39079
- const parsed = JSON.parse(raw);
39080
- const value = coerceString(parsed.value);
39081
- if (!value) {
39082
- return null;
39083
- }
39084
- const expiresAt = coerceNumber(parsed.expiresAt);
39085
- const scopes = normalizeScopes(parsed.scopes);
39086
- const audience = coerceString(parsed.audience);
39087
- const record = {
39088
- value,
39089
- scopes,
39090
- audience,
39091
- };
39092
- if (typeof expiresAt === 'number') {
39093
- record.expiresAt = expiresAt;
39094
- }
39095
- return record;
39096
- }
39097
- catch (error) {
39098
- logger.debug('pkce_token_storage_read_failed', {
39099
- error: error instanceof Error ? error.message : String(error),
39100
- });
39101
- return null;
39102
- }
39079
+ return inMemoryTokenCache.get(clientId) ?? null;
39103
39080
  }
39081
+ /**
39082
+ * Write token to in-memory cache.
39083
+ * If token is null, removes the cached token for the given clientId.
39084
+ */
39104
39085
  function writePersistedToken(clientId, token) {
39105
- if (!isBrowserEnvironment()) {
39086
+ if (!token) {
39087
+ inMemoryTokenCache.delete(clientId);
39106
39088
  return;
39107
39089
  }
39108
- const key = getTokenStorageKey(clientId);
39109
- try {
39110
- if (!token) {
39111
- window.sessionStorage.removeItem(key);
39112
- return;
39113
- }
39114
- window.sessionStorage.setItem(key, JSON.stringify(token));
39115
- }
39116
- catch (error) {
39117
- logger.debug('pkce_token_storage_write_failed', {
39118
- error: error instanceof Error ? error.message : String(error),
39119
- });
39120
- }
39090
+ inMemoryTokenCache.set(clientId, token);
39121
39091
  }
39122
39092
  function clearOAuthParamsFromUrl(url) {
39123
39093
  if (!isBrowserEnvironment()) {
@@ -39418,6 +39388,17 @@ class OAuth2PkceTokenProvider {
39418
39388
  });
39419
39389
  return token;
39420
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
+ }
39421
39402
  }
39422
39403
 
39423
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.925
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.925';
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.
@@ -39006,14 +39006,18 @@ function ensureFinitePositive(value, label) {
39006
39006
  }
39007
39007
  return Math.max(1, Math.floor(value));
39008
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();
39009
39017
  const STORAGE_NAMESPACE = 'naylence.oauth2_pkce.';
39010
- const TOKEN_STORAGE_SUFFIX = '.token';
39011
39018
  function getStorageKey(clientId) {
39012
39019
  return `${STORAGE_NAMESPACE}${clientId}`;
39013
39020
  }
39014
- function getTokenStorageKey(clientId) {
39015
- return `${STORAGE_NAMESPACE}${clientId}${TOKEN_STORAGE_SUFFIX}`;
39016
- }
39017
39021
  function isBrowserEnvironment() {
39018
39022
  return (typeof window !== 'undefined' &&
39019
39023
  typeof window.location !== 'undefined' &&
@@ -39065,57 +39069,23 @@ function stableScopeKey(scopes) {
39065
39069
  }
39066
39070
  return [...scopes].sort().join(' ');
39067
39071
  }
39072
+ /**
39073
+ * Read token from in-memory cache.
39074
+ * Returns null if no cached token exists for the given clientId.
39075
+ */
39068
39076
  function readPersistedToken(clientId) {
39069
- if (!isBrowserEnvironment()) {
39070
- return null;
39071
- }
39072
- try {
39073
- const raw = window.sessionStorage.getItem(getTokenStorageKey(clientId));
39074
- if (!raw) {
39075
- return null;
39076
- }
39077
- const parsed = JSON.parse(raw);
39078
- const value = coerceString(parsed.value);
39079
- if (!value) {
39080
- return null;
39081
- }
39082
- const expiresAt = coerceNumber(parsed.expiresAt);
39083
- const scopes = normalizeScopes(parsed.scopes);
39084
- const audience = coerceString(parsed.audience);
39085
- const record = {
39086
- value,
39087
- scopes,
39088
- audience,
39089
- };
39090
- if (typeof expiresAt === 'number') {
39091
- record.expiresAt = expiresAt;
39092
- }
39093
- return record;
39094
- }
39095
- catch (error) {
39096
- logger.debug('pkce_token_storage_read_failed', {
39097
- error: error instanceof Error ? error.message : String(error),
39098
- });
39099
- return null;
39100
- }
39077
+ return inMemoryTokenCache.get(clientId) ?? null;
39101
39078
  }
39079
+ /**
39080
+ * Write token to in-memory cache.
39081
+ * If token is null, removes the cached token for the given clientId.
39082
+ */
39102
39083
  function writePersistedToken(clientId, token) {
39103
- if (!isBrowserEnvironment()) {
39084
+ if (!token) {
39085
+ inMemoryTokenCache.delete(clientId);
39104
39086
  return;
39105
39087
  }
39106
- const key = getTokenStorageKey(clientId);
39107
- try {
39108
- if (!token) {
39109
- window.sessionStorage.removeItem(key);
39110
- return;
39111
- }
39112
- window.sessionStorage.setItem(key, JSON.stringify(token));
39113
- }
39114
- catch (error) {
39115
- logger.debug('pkce_token_storage_write_failed', {
39116
- error: error instanceof Error ? error.message : String(error),
39117
- });
39118
- }
39088
+ inMemoryTokenCache.set(clientId, token);
39119
39089
  }
39120
39090
  function clearOAuthParamsFromUrl(url) {
39121
39091
  if (!isBrowserEnvironment()) {
@@ -39416,6 +39386,17 @@ class OAuth2PkceTokenProvider {
39416
39386
  });
39417
39387
  return token;
39418
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
+ }
39419
39400
  }
39420
39401
 
39421
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;
@@ -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.925
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.925';
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
  }
@@ -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.925
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.925';
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.925
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.925';
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.
@@ -38922,14 +38922,18 @@ function ensureFinitePositive(value, label) {
38922
38922
  }
38923
38923
  return Math.max(1, Math.floor(value));
38924
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();
38925
38933
  const STORAGE_NAMESPACE = 'naylence.oauth2_pkce.';
38926
- const TOKEN_STORAGE_SUFFIX = '.token';
38927
38934
  function getStorageKey(clientId) {
38928
38935
  return `${STORAGE_NAMESPACE}${clientId}`;
38929
38936
  }
38930
- function getTokenStorageKey(clientId) {
38931
- return `${STORAGE_NAMESPACE}${clientId}${TOKEN_STORAGE_SUFFIX}`;
38932
- }
38933
38937
  function isBrowserEnvironment() {
38934
38938
  return (typeof window !== 'undefined' &&
38935
38939
  typeof window.location !== 'undefined' &&
@@ -38981,57 +38985,23 @@ function stableScopeKey(scopes) {
38981
38985
  }
38982
38986
  return [...scopes].sort().join(' ');
38983
38987
  }
38988
+ /**
38989
+ * Read token from in-memory cache.
38990
+ * Returns null if no cached token exists for the given clientId.
38991
+ */
38984
38992
  function readPersistedToken(clientId) {
38985
- if (!isBrowserEnvironment()) {
38986
- return null;
38987
- }
38988
- try {
38989
- const raw = window.sessionStorage.getItem(getTokenStorageKey(clientId));
38990
- if (!raw) {
38991
- return null;
38992
- }
38993
- const parsed = JSON.parse(raw);
38994
- const value = coerceString(parsed.value);
38995
- if (!value) {
38996
- return null;
38997
- }
38998
- const expiresAt = coerceNumber(parsed.expiresAt);
38999
- const scopes = normalizeScopes(parsed.scopes);
39000
- const audience = coerceString(parsed.audience);
39001
- const record = {
39002
- value,
39003
- scopes,
39004
- audience,
39005
- };
39006
- if (typeof expiresAt === 'number') {
39007
- record.expiresAt = expiresAt;
39008
- }
39009
- return record;
39010
- }
39011
- catch (error) {
39012
- logger.debug('pkce_token_storage_read_failed', {
39013
- error: error instanceof Error ? error.message : String(error),
39014
- });
39015
- return null;
39016
- }
38993
+ return inMemoryTokenCache.get(clientId) ?? null;
39017
38994
  }
38995
+ /**
38996
+ * Write token to in-memory cache.
38997
+ * If token is null, removes the cached token for the given clientId.
38998
+ */
39018
38999
  function writePersistedToken(clientId, token) {
39019
- if (!isBrowserEnvironment()) {
39000
+ if (!token) {
39001
+ inMemoryTokenCache.delete(clientId);
39020
39002
  return;
39021
39003
  }
39022
- const key = getTokenStorageKey(clientId);
39023
- try {
39024
- if (!token) {
39025
- window.sessionStorage.removeItem(key);
39026
- return;
39027
- }
39028
- window.sessionStorage.setItem(key, JSON.stringify(token));
39029
- }
39030
- catch (error) {
39031
- logger.debug('pkce_token_storage_write_failed', {
39032
- error: error instanceof Error ? error.message : String(error),
39033
- });
39034
- }
39004
+ inMemoryTokenCache.set(clientId, token);
39035
39005
  }
39036
39006
  function clearOAuthParamsFromUrl(url) {
39037
39007
  if (!isBrowserEnvironment()) {
@@ -39332,6 +39302,17 @@ class OAuth2PkceTokenProvider {
39332
39302
  });
39333
39303
  return token;
39334
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
+ }
39335
39316
  }
39336
39317
 
39337
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.925
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.925';
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.
@@ -38921,14 +38921,18 @@ function ensureFinitePositive(value, label) {
38921
38921
  }
38922
38922
  return Math.max(1, Math.floor(value));
38923
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();
38924
38932
  const STORAGE_NAMESPACE = 'naylence.oauth2_pkce.';
38925
- const TOKEN_STORAGE_SUFFIX = '.token';
38926
38933
  function getStorageKey(clientId) {
38927
38934
  return `${STORAGE_NAMESPACE}${clientId}`;
38928
38935
  }
38929
- function getTokenStorageKey(clientId) {
38930
- return `${STORAGE_NAMESPACE}${clientId}${TOKEN_STORAGE_SUFFIX}`;
38931
- }
38932
38936
  function isBrowserEnvironment() {
38933
38937
  return (typeof window !== 'undefined' &&
38934
38938
  typeof window.location !== 'undefined' &&
@@ -38980,57 +38984,23 @@ function stableScopeKey(scopes) {
38980
38984
  }
38981
38985
  return [...scopes].sort().join(' ');
38982
38986
  }
38987
+ /**
38988
+ * Read token from in-memory cache.
38989
+ * Returns null if no cached token exists for the given clientId.
38990
+ */
38983
38991
  function readPersistedToken(clientId) {
38984
- if (!isBrowserEnvironment()) {
38985
- return null;
38986
- }
38987
- try {
38988
- const raw = window.sessionStorage.getItem(getTokenStorageKey(clientId));
38989
- if (!raw) {
38990
- return null;
38991
- }
38992
- const parsed = JSON.parse(raw);
38993
- const value = coerceString(parsed.value);
38994
- if (!value) {
38995
- return null;
38996
- }
38997
- const expiresAt = coerceNumber(parsed.expiresAt);
38998
- const scopes = normalizeScopes(parsed.scopes);
38999
- const audience = coerceString(parsed.audience);
39000
- const record = {
39001
- value,
39002
- scopes,
39003
- audience,
39004
- };
39005
- if (typeof expiresAt === 'number') {
39006
- record.expiresAt = expiresAt;
39007
- }
39008
- return record;
39009
- }
39010
- catch (error) {
39011
- logger.debug('pkce_token_storage_read_failed', {
39012
- error: error instanceof Error ? error.message : String(error),
39013
- });
39014
- return null;
39015
- }
38992
+ return inMemoryTokenCache.get(clientId) ?? null;
39016
38993
  }
38994
+ /**
38995
+ * Write token to in-memory cache.
38996
+ * If token is null, removes the cached token for the given clientId.
38997
+ */
39017
38998
  function writePersistedToken(clientId, token) {
39018
- if (!isBrowserEnvironment()) {
38999
+ if (!token) {
39000
+ inMemoryTokenCache.delete(clientId);
39019
39001
  return;
39020
39002
  }
39021
- const key = getTokenStorageKey(clientId);
39022
- try {
39023
- if (!token) {
39024
- window.sessionStorage.removeItem(key);
39025
- return;
39026
- }
39027
- window.sessionStorage.setItem(key, JSON.stringify(token));
39028
- }
39029
- catch (error) {
39030
- logger.debug('pkce_token_storage_write_failed', {
39031
- error: error instanceof Error ? error.message : String(error),
39032
- });
39033
- }
39003
+ inMemoryTokenCache.set(clientId, token);
39034
39004
  }
39035
39005
  function clearOAuthParamsFromUrl(url) {
39036
39006
  if (!isBrowserEnvironment()) {
@@ -39331,6 +39301,17 @@ class OAuth2PkceTokenProvider {
39331
39301
  });
39332
39302
  return token;
39333
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
+ }
39334
39315
  }
39335
39316
 
39336
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.925
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.925';
5380
+ const VERSION = '0.3.5-test.926';
5381
5381
 
5382
5382
  /**
5383
5383
  * Fame errors module - Fame protocol specific error classes
@@ -41140,14 +41140,18 @@ function ensureFinitePositive(value, label) {
41140
41140
  }
41141
41141
  return Math.max(1, Math.floor(value));
41142
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();
41143
41151
  const STORAGE_NAMESPACE = 'naylence.oauth2_pkce.';
41144
- const TOKEN_STORAGE_SUFFIX = '.token';
41145
41152
  function getStorageKey(clientId) {
41146
41153
  return `${STORAGE_NAMESPACE}${clientId}`;
41147
41154
  }
41148
- function getTokenStorageKey(clientId) {
41149
- return `${STORAGE_NAMESPACE}${clientId}${TOKEN_STORAGE_SUFFIX}`;
41150
- }
41151
41155
  function isBrowserEnvironment() {
41152
41156
  return (typeof window !== 'undefined' &&
41153
41157
  typeof window.location !== 'undefined' &&
@@ -41199,57 +41203,23 @@ function stableScopeKey(scopes) {
41199
41203
  }
41200
41204
  return [...scopes].sort().join(' ');
41201
41205
  }
41206
+ /**
41207
+ * Read token from in-memory cache.
41208
+ * Returns null if no cached token exists for the given clientId.
41209
+ */
41202
41210
  function readPersistedToken(clientId) {
41203
- if (!isBrowserEnvironment()) {
41204
- return null;
41205
- }
41206
- try {
41207
- const raw = window.sessionStorage.getItem(getTokenStorageKey(clientId));
41208
- if (!raw) {
41209
- return null;
41210
- }
41211
- const parsed = JSON.parse(raw);
41212
- const value = coerceString(parsed.value);
41213
- if (!value) {
41214
- return null;
41215
- }
41216
- const expiresAt = coerceNumber(parsed.expiresAt);
41217
- const scopes = normalizeScopes(parsed.scopes);
41218
- const audience = coerceString(parsed.audience);
41219
- const record = {
41220
- value,
41221
- scopes,
41222
- audience,
41223
- };
41224
- if (typeof expiresAt === 'number') {
41225
- record.expiresAt = expiresAt;
41226
- }
41227
- return record;
41228
- }
41229
- catch (error) {
41230
- logger.debug('pkce_token_storage_read_failed', {
41231
- error: error instanceof Error ? error.message : String(error),
41232
- });
41233
- return null;
41234
- }
41211
+ return inMemoryTokenCache.get(clientId) ?? null;
41235
41212
  }
41213
+ /**
41214
+ * Write token to in-memory cache.
41215
+ * If token is null, removes the cached token for the given clientId.
41216
+ */
41236
41217
  function writePersistedToken(clientId, token) {
41237
- if (!isBrowserEnvironment()) {
41218
+ if (!token) {
41219
+ inMemoryTokenCache.delete(clientId);
41238
41220
  return;
41239
41221
  }
41240
- const key = getTokenStorageKey(clientId);
41241
- try {
41242
- if (!token) {
41243
- window.sessionStorage.removeItem(key);
41244
- return;
41245
- }
41246
- window.sessionStorage.setItem(key, JSON.stringify(token));
41247
- }
41248
- catch (error) {
41249
- logger.debug('pkce_token_storage_write_failed', {
41250
- error: error instanceof Error ? error.message : String(error),
41251
- });
41252
- }
41222
+ inMemoryTokenCache.set(clientId, token);
41253
41223
  }
41254
41224
  function clearOAuthParamsFromUrl(url) {
41255
41225
  if (!isBrowserEnvironment()) {
@@ -41550,6 +41520,17 @@ class OAuth2PkceTokenProvider {
41550
41520
  });
41551
41521
  return token;
41552
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
+ }
41553
41534
  }
41554
41535
 
41555
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.925
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.925';
5379
+ const VERSION = '0.3.5-test.926';
5380
5380
 
5381
5381
  /**
5382
5382
  * Fame errors module - Fame protocol specific error classes
@@ -41139,14 +41139,18 @@ function ensureFinitePositive(value, label) {
41139
41139
  }
41140
41140
  return Math.max(1, Math.floor(value));
41141
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();
41142
41150
  const STORAGE_NAMESPACE = 'naylence.oauth2_pkce.';
41143
- const TOKEN_STORAGE_SUFFIX = '.token';
41144
41151
  function getStorageKey(clientId) {
41145
41152
  return `${STORAGE_NAMESPACE}${clientId}`;
41146
41153
  }
41147
- function getTokenStorageKey(clientId) {
41148
- return `${STORAGE_NAMESPACE}${clientId}${TOKEN_STORAGE_SUFFIX}`;
41149
- }
41150
41154
  function isBrowserEnvironment() {
41151
41155
  return (typeof window !== 'undefined' &&
41152
41156
  typeof window.location !== 'undefined' &&
@@ -41198,57 +41202,23 @@ function stableScopeKey(scopes) {
41198
41202
  }
41199
41203
  return [...scopes].sort().join(' ');
41200
41204
  }
41205
+ /**
41206
+ * Read token from in-memory cache.
41207
+ * Returns null if no cached token exists for the given clientId.
41208
+ */
41201
41209
  function readPersistedToken(clientId) {
41202
- if (!isBrowserEnvironment()) {
41203
- return null;
41204
- }
41205
- try {
41206
- const raw = window.sessionStorage.getItem(getTokenStorageKey(clientId));
41207
- if (!raw) {
41208
- return null;
41209
- }
41210
- const parsed = JSON.parse(raw);
41211
- const value = coerceString(parsed.value);
41212
- if (!value) {
41213
- return null;
41214
- }
41215
- const expiresAt = coerceNumber(parsed.expiresAt);
41216
- const scopes = normalizeScopes(parsed.scopes);
41217
- const audience = coerceString(parsed.audience);
41218
- const record = {
41219
- value,
41220
- scopes,
41221
- audience,
41222
- };
41223
- if (typeof expiresAt === 'number') {
41224
- record.expiresAt = expiresAt;
41225
- }
41226
- return record;
41227
- }
41228
- catch (error) {
41229
- logger.debug('pkce_token_storage_read_failed', {
41230
- error: error instanceof Error ? error.message : String(error),
41231
- });
41232
- return null;
41233
- }
41210
+ return inMemoryTokenCache.get(clientId) ?? null;
41234
41211
  }
41212
+ /**
41213
+ * Write token to in-memory cache.
41214
+ * If token is null, removes the cached token for the given clientId.
41215
+ */
41235
41216
  function writePersistedToken(clientId, token) {
41236
- if (!isBrowserEnvironment()) {
41217
+ if (!token) {
41218
+ inMemoryTokenCache.delete(clientId);
41237
41219
  return;
41238
41220
  }
41239
- const key = getTokenStorageKey(clientId);
41240
- try {
41241
- if (!token) {
41242
- window.sessionStorage.removeItem(key);
41243
- return;
41244
- }
41245
- window.sessionStorage.setItem(key, JSON.stringify(token));
41246
- }
41247
- catch (error) {
41248
- logger.debug('pkce_token_storage_write_failed', {
41249
- error: error instanceof Error ? error.message : String(error),
41250
- });
41251
- }
41221
+ inMemoryTokenCache.set(clientId, token);
41252
41222
  }
41253
41223
  function clearOAuthParamsFromUrl(url) {
41254
41224
  if (!isBrowserEnvironment()) {
@@ -41549,6 +41519,17 @@ class OAuth2PkceTokenProvider {
41549
41519
  });
41550
41520
  return token;
41551
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
+ }
41552
41533
  }
41553
41534
 
41554
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.925";
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.925",
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>",