@auth0/auth0-spa-js 2.19.0 → 2.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/auth0-spa-js.development.js +38 -24
  2. package/dist/auth0-spa-js.development.js.map +1 -1
  3. package/dist/auth0-spa-js.production.esm.js +1 -1
  4. package/dist/auth0-spa-js.production.esm.js.map +1 -1
  5. package/dist/auth0-spa-js.production.js +1 -1
  6. package/dist/auth0-spa-js.production.js.map +1 -1
  7. package/dist/lib/auth0-spa-js.cjs.js +38 -24
  8. package/dist/lib/auth0-spa-js.cjs.js.map +1 -1
  9. package/dist/typings/Auth0Client.d.ts +476 -476
  10. package/dist/typings/Auth0Client.utils.d.ts +90 -90
  11. package/dist/typings/MyAccountApiClient.d.ts +92 -92
  12. package/dist/typings/TokenExchange.d.ts +77 -77
  13. package/dist/typings/api.d.ts +33 -33
  14. package/dist/typings/cache/cache-localstorage.d.ts +7 -7
  15. package/dist/typings/cache/cache-manager.d.ts +69 -69
  16. package/dist/typings/cache/cache-memory.d.ts +4 -4
  17. package/dist/typings/cache/index.d.ts +4 -4
  18. package/dist/typings/cache/key-manifest.d.ts +12 -12
  19. package/dist/typings/cache/shared.d.ts +68 -68
  20. package/dist/typings/constants.d.ts +58 -58
  21. package/dist/typings/dpop/dpop.d.ts +17 -17
  22. package/dist/typings/dpop/storage.d.ts +27 -27
  23. package/dist/typings/dpop/utils.d.ts +15 -15
  24. package/dist/typings/errors.d.ts +96 -96
  25. package/dist/typings/fetcher.d.ts +54 -54
  26. package/dist/typings/global.d.ts +826 -826
  27. package/dist/typings/http.d.ts +11 -11
  28. package/dist/typings/index.d.ts +24 -24
  29. package/dist/typings/jwt.d.ts +21 -21
  30. package/dist/typings/lock.d.ts +32 -32
  31. package/dist/typings/mfa/MfaApiClient.d.ts +225 -225
  32. package/dist/typings/mfa/MfaContextManager.d.ts +79 -79
  33. package/dist/typings/mfa/constants.d.ts +23 -23
  34. package/dist/typings/mfa/errors.d.ts +117 -117
  35. package/dist/typings/mfa/index.d.ts +4 -4
  36. package/dist/typings/mfa/types.d.ts +181 -181
  37. package/dist/typings/mfa/utils.d.ts +23 -23
  38. package/dist/typings/promise-utils.d.ts +2 -2
  39. package/dist/typings/scope.d.ts +35 -35
  40. package/dist/typings/storage.d.ts +26 -26
  41. package/dist/typings/transaction-manager.d.ts +33 -33
  42. package/dist/typings/utils.d.ts +36 -36
  43. package/dist/typings/version.d.ts +2 -2
  44. package/dist/typings/worker/token.worker.d.ts +1 -1
  45. package/dist/typings/worker/worker.types.d.ts +27 -27
  46. package/dist/typings/worker/worker.utils.d.ts +13 -13
  47. package/package.json +1 -1
  48. package/src/api.ts +15 -11
  49. package/src/cache/cache-manager.ts +28 -9
  50. package/src/version.ts +1 -1
@@ -1,36 +1,36 @@
1
- import { AuthenticationResult, PopupConfigOptions } from './global';
2
- export declare const parseAuthenticationResult: (queryString: string) => AuthenticationResult;
3
- export declare const runIframe: (authorizeUrl: string, eventOrigin: string, timeoutInSeconds?: number) => Promise<AuthenticationResult>;
4
- export declare const openPopup: (url: string) => Window | null;
5
- export declare const runPopup: (config: PopupConfigOptions, eventOrigin: string) => Promise<AuthenticationResult>;
6
- export declare const getCrypto: () => Crypto;
7
- export declare const createRandomString: () => string;
8
- export declare const encode: (value: string) => string;
9
- export declare const decode: (value: string) => string;
10
- /**
11
- * Strips any property that is not present in ALLOWED_AUTH0CLIENT_PROPERTIES
12
- * @param auth0Client - The full auth0Client object
13
- * @param excludeEnv - If true, excludes the 'env' property from the result
14
- * @returns The stripped auth0Client object
15
- */
16
- export declare const stripAuth0Client: (auth0Client: any, excludeEnv?: boolean) => any;
17
- export declare const createQueryParams: ({ clientId: client_id, ...params }: any) => string;
18
- export declare const sha256: (s: string) => Promise<any>;
19
- export declare const urlDecodeB64: (input: string) => string;
20
- export declare const bufferToBase64UrlEncoded: (input: number[] | Uint8Array) => string;
21
- export declare const validateCrypto: () => void;
22
- /**
23
- * @ignore
24
- */
25
- export declare const getDomain: (domainUrl: string) => string;
26
- /**
27
- * @ignore
28
- */
29
- export declare const getTokenIssuer: (issuer: string | undefined, domainUrl: string) => string;
30
- export declare const parseNumber: (value: any) => number | undefined;
31
- /**
32
- * Ponyfill for `Object.fromEntries()`, which is not available until ES2020.
33
- *
34
- * When the target of this project reaches ES2020, this can be removed.
35
- */
36
- export declare const fromEntries: <T = any>(iterable: Iterable<[PropertyKey, T]>) => Record<PropertyKey, T>;
1
+ import { AuthenticationResult, PopupConfigOptions } from './global';
2
+ export declare const parseAuthenticationResult: (queryString: string) => AuthenticationResult;
3
+ export declare const runIframe: (authorizeUrl: string, eventOrigin: string, timeoutInSeconds?: number) => Promise<AuthenticationResult>;
4
+ export declare const openPopup: (url: string) => Window | null;
5
+ export declare const runPopup: (config: PopupConfigOptions, eventOrigin: string) => Promise<AuthenticationResult>;
6
+ export declare const getCrypto: () => Crypto;
7
+ export declare const createRandomString: () => string;
8
+ export declare const encode: (value: string) => string;
9
+ export declare const decode: (value: string) => string;
10
+ /**
11
+ * Strips any property that is not present in ALLOWED_AUTH0CLIENT_PROPERTIES
12
+ * @param auth0Client - The full auth0Client object
13
+ * @param excludeEnv - If true, excludes the 'env' property from the result
14
+ * @returns The stripped auth0Client object
15
+ */
16
+ export declare const stripAuth0Client: (auth0Client: any, excludeEnv?: boolean) => any;
17
+ export declare const createQueryParams: ({ clientId: client_id, ...params }: any) => string;
18
+ export declare const sha256: (s: string) => Promise<any>;
19
+ export declare const urlDecodeB64: (input: string) => string;
20
+ export declare const bufferToBase64UrlEncoded: (input: number[] | Uint8Array) => string;
21
+ export declare const validateCrypto: () => void;
22
+ /**
23
+ * @ignore
24
+ */
25
+ export declare const getDomain: (domainUrl: string) => string;
26
+ /**
27
+ * @ignore
28
+ */
29
+ export declare const getTokenIssuer: (issuer: string | undefined, domainUrl: string) => string;
30
+ export declare const parseNumber: (value: any) => number | undefined;
31
+ /**
32
+ * Ponyfill for `Object.fromEntries()`, which is not available until ES2020.
33
+ *
34
+ * When the target of this project reaches ES2020, this can be removed.
35
+ */
36
+ export declare const fromEntries: <T = any>(iterable: Iterable<[PropertyKey, T]>) => Record<PropertyKey, T>;
@@ -1,2 +1,2 @@
1
- declare const _default: "2.19.0";
2
- export default _default;
1
+ declare const _default: "2.19.1";
2
+ export default _default;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,27 +1,27 @@
1
- import { FetchOptions } from '../global';
2
- export type WorkerInitMessage = {
3
- type: 'init';
4
- allowedBaseUrl: string;
5
- };
6
- type WorkerTokenMessage = {
7
- timeout: number;
8
- fetchUrl: string;
9
- fetchOptions: FetchOptions;
10
- useFormData?: boolean;
11
- auth: {
12
- audience: string;
13
- scope: string;
14
- };
15
- };
16
- export type WorkerRefreshTokenMessage = WorkerTokenMessage & {
17
- type: 'refresh';
18
- useMrrt?: boolean;
19
- };
20
- export type WorkerRevokeTokenMessage = Omit<WorkerTokenMessage, 'auth'> & {
21
- type: 'revoke';
22
- auth: {
23
- audience: string;
24
- };
25
- };
26
- export type WorkerMessage = WorkerInitMessage | WorkerRefreshTokenMessage | WorkerRevokeTokenMessage;
27
- export {};
1
+ import { FetchOptions } from '../global';
2
+ export type WorkerInitMessage = {
3
+ type: 'init';
4
+ allowedBaseUrl: string;
5
+ };
6
+ type WorkerTokenMessage = {
7
+ timeout: number;
8
+ fetchUrl: string;
9
+ fetchOptions: FetchOptions;
10
+ useFormData?: boolean;
11
+ auth: {
12
+ audience: string;
13
+ scope: string;
14
+ };
15
+ };
16
+ export type WorkerRefreshTokenMessage = WorkerTokenMessage & {
17
+ type: 'refresh';
18
+ useMrrt?: boolean;
19
+ };
20
+ export type WorkerRevokeTokenMessage = Omit<WorkerTokenMessage, 'auth'> & {
21
+ type: 'revoke';
22
+ auth: {
23
+ audience: string;
24
+ };
25
+ };
26
+ export type WorkerMessage = WorkerInitMessage | WorkerRefreshTokenMessage | WorkerRevokeTokenMessage;
27
+ export {};
@@ -1,13 +1,13 @@
1
- import { WorkerRefreshTokenMessage, WorkerRevokeTokenMessage } from './worker.types';
2
- /**
3
- * Sends a message to a Web Worker and returns a Promise that resolves with
4
- * the worker's response, or rejects if the worker replies with an error.
5
- *
6
- * Uses a {@link MessageChannel} so each call gets its own private reply port,
7
- * making concurrent calls safe without shared state.
8
- *
9
- * @param message - The typed message to send (`refresh` or `revoke`).
10
- * @param to - The target {@link Worker} instance.
11
- * @returns A Promise that resolves with the worker's response payload.
12
- */
13
- export declare const sendMessage: <T = any>(message: WorkerRefreshTokenMessage | WorkerRevokeTokenMessage, to: Worker) => Promise<T>;
1
+ import { WorkerRefreshTokenMessage, WorkerRevokeTokenMessage } from './worker.types';
2
+ /**
3
+ * Sends a message to a Web Worker and returns a Promise that resolves with
4
+ * the worker's response, or rejects if the worker replies with an error.
5
+ *
6
+ * Uses a {@link MessageChannel} so each call gets its own private reply port,
7
+ * making concurrent calls safe without shared state.
8
+ *
9
+ * @param message - The typed message to send (`refresh` or `revoke`).
10
+ * @param to - The target {@link Worker} instance.
11
+ * @returns A Promise that resolves with the worker's response payload.
12
+ */
13
+ export declare const sendMessage: <T = any>(message: WorkerRefreshTokenMessage | WorkerRevokeTokenMessage, to: Worker) => Promise<T>;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "@auth0/auth0-spa-js",
4
4
  "description": "Auth0 SDK for Single Page Applications using Authorization Code Grant Flow with PKCE",
5
5
  "license": "MIT",
6
- "version": "2.19.0",
6
+ "version": "2.19.1",
7
7
  "main": "dist/lib/auth0-spa-js.cjs.js",
8
8
  "types": "dist/typings/index.d.ts",
9
9
  "module": "dist/auth0-spa-js.production.esm.js",
package/src/api.ts CHANGED
@@ -130,17 +130,21 @@ export async function revokeToken(
130
130
  ? createQueryParams(baseParams)
131
131
  : JSON.stringify(baseParams);
132
132
 
133
- return sendMessage(
134
- {
135
- type: 'revoke',
136
- timeout: resolvedTimeout,
137
- fetchUrl,
138
- fetchOptions: { method: 'POST', body, headers },
139
- useFormData,
140
- auth: { audience: audience ?? DEFAULT_AUDIENCE }
141
- },
142
- worker
143
- );
133
+ try {
134
+ return await sendMessage(
135
+ {
136
+ type: 'revoke',
137
+ timeout: resolvedTimeout,
138
+ fetchUrl,
139
+ fetchOptions: { method: 'POST', body, headers },
140
+ useFormData,
141
+ auth: { audience: audience ?? DEFAULT_AUDIENCE }
142
+ },
143
+ worker
144
+ );
145
+ } catch (e) {
146
+ throw new GenericError('revoke_error', (e as Error).message);
147
+ }
144
148
  }
145
149
 
146
150
  for (const refreshToken of refreshTokens) {
@@ -77,6 +77,11 @@ export class CacheManager {
77
77
  cacheKey.toKey()
78
78
  );
79
79
 
80
+ // Track the key where the entry was actually found, so that
81
+ // expiry-related writes (strip / remove) target the correct entry
82
+ // instead of creating a ghost entry under the lookup key.
83
+ let resolvedCacheKey = cacheKey;
84
+
80
85
  if (!wrappedEntry) {
81
86
  const keys = await this.getCacheKeys();
82
87
 
@@ -86,6 +91,7 @@ export class CacheManager {
86
91
 
87
92
  if (matchedKey) {
88
93
  wrappedEntry = await this.cache.get<WrappedCacheEntry>(matchedKey);
94
+ resolvedCacheKey = CacheKey.fromKey(matchedKey);
89
95
  }
90
96
 
91
97
  // To refresh using MRRT we need to send a request to the server
@@ -106,11 +112,11 @@ export class CacheManager {
106
112
 
107
113
  if (wrappedEntry.expiresAt - expiryAdjustmentSeconds < nowSeconds) {
108
114
  if (wrappedEntry.body.refresh_token) {
109
- return this.modifiedCachedEntry(wrappedEntry, cacheKey);
115
+ return this.modifiedCachedEntry(wrappedEntry, resolvedCacheKey);
110
116
  }
111
117
 
112
- await this.cache.remove(cacheKey.toKey());
113
- await this.keyManifest?.remove(cacheKey.toKey());
118
+ await this.cache.remove(resolvedCacheKey.toKey());
119
+ await this.keyManifest?.remove(resolvedCacheKey.toKey());
114
120
 
115
121
  return;
116
122
  }
@@ -121,18 +127,27 @@ export class CacheManager {
121
127
  private async modifiedCachedEntry(wrappedEntry: WrappedCacheEntry, cacheKey: CacheKey): Promise<Partial<CacheEntry>> {
122
128
  // We need to keep audience and scope in order to check them later when doing refresh
123
129
  // using MRRT. See getScopeToRequest method.
124
- wrappedEntry.body = {
130
+ //
131
+ // Build a new object instead of mutating wrappedEntry.body in-place,
132
+ // because InMemoryCache returns direct references — mutating would
133
+ // corrupt the original entry stored under a different (superset) key.
134
+ const strippedBody: Partial<CacheEntry> = {
125
135
  refresh_token: wrappedEntry.body.refresh_token,
126
136
  audience: wrappedEntry.body.audience,
127
137
  scope: wrappedEntry.body.scope,
128
138
  };
129
139
 
130
- await this.cache.set(cacheKey.toKey(), wrappedEntry);
140
+ const strippedEntry: WrappedCacheEntry = {
141
+ body: strippedBody,
142
+ expiresAt: wrappedEntry.expiresAt,
143
+ };
144
+
145
+ await this.cache.set(cacheKey.toKey(), strippedEntry);
131
146
 
132
147
  return {
133
- refresh_token: wrappedEntry.body.refresh_token,
134
- audience: wrappedEntry.body.audience,
135
- scope: wrappedEntry.body.scope,
148
+ refresh_token: strippedBody.refresh_token,
149
+ audience: strippedBody.audience,
150
+ scope: strippedBody.scope,
136
151
  };
137
152
  }
138
153
 
@@ -278,7 +293,11 @@ export class CacheManager {
278
293
  const cachedEntry = await this.cache.get<WrappedCacheEntry>(key);
279
294
 
280
295
  if (cachedEntry?.body?.refresh_token) {
281
- return this.modifiedCachedEntry(cachedEntry, keyToMatch);
296
+ return {
297
+ refresh_token: cachedEntry.body.refresh_token,
298
+ audience: cachedEntry.body.audience,
299
+ scope: cachedEntry.body.scope,
300
+ };
282
301
  }
283
302
  }
284
303
  }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export default '2.19.0';
1
+ export default '2.19.1';