@okta/okta-auth-js 6.1.0 → 6.2.0

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 (69) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +53 -23
  3. package/cjs/AuthStateManager.js +5 -4
  4. package/cjs/AuthStateManager.js.map +1 -1
  5. package/cjs/OktaAuth.js +30 -14
  6. package/cjs/OktaAuth.js.map +1 -1
  7. package/cjs/OktaUserAgent.js +2 -2
  8. package/cjs/ServiceManager.js +195 -0
  9. package/cjs/ServiceManager.js.map +1 -0
  10. package/cjs/TokenManager.js +6 -14
  11. package/cjs/TokenManager.js.map +1 -1
  12. package/cjs/browser/browserStorage.js +12 -7
  13. package/cjs/browser/browserStorage.js.map +1 -1
  14. package/cjs/crypto/node.js +19 -13
  15. package/cjs/crypto/node.js.map +1 -1
  16. package/cjs/idx/remediators/AuthenticatorVerificationData.js +44 -7
  17. package/cjs/idx/remediators/AuthenticatorVerificationData.js.map +1 -1
  18. package/cjs/idx/remediators/Base/AuthenticatorData.js.map +1 -1
  19. package/cjs/idx/run.js +6 -0
  20. package/cjs/idx/run.js.map +1 -1
  21. package/cjs/options/browser.js +81 -0
  22. package/cjs/options/browser.js.map +1 -0
  23. package/cjs/{options.js → options/index.js} +12 -78
  24. package/cjs/options/index.js.map +1 -0
  25. package/cjs/options/node.js +46 -0
  26. package/cjs/options/node.js.map +1 -0
  27. package/cjs/server/serverStorage.js +7 -4
  28. package/cjs/server/serverStorage.js.map +1 -1
  29. package/cjs/services/AutoRenewService.js +94 -0
  30. package/cjs/services/AutoRenewService.js.map +1 -0
  31. package/cjs/services/SyncStorageService.js +93 -0
  32. package/cjs/services/SyncStorageService.js.map +1 -0
  33. package/cjs/services/index.js +30 -0
  34. package/cjs/services/index.js.map +1 -0
  35. package/cjs/types/Service.js +2 -0
  36. package/cjs/types/Service.js.map +1 -0
  37. package/cjs/types/index.js +13 -0
  38. package/cjs/types/index.js.map +1 -1
  39. package/dist/okta-auth-js.min.js +1 -1
  40. package/dist/okta-auth-js.min.js.LICENSE.txt +0 -8
  41. package/dist/okta-auth-js.min.js.map +1 -1
  42. package/dist/okta-auth-js.umd.js +1 -1
  43. package/dist/okta-auth-js.umd.js.LICENSE.txt +1 -7
  44. package/dist/okta-auth-js.umd.js.map +1 -1
  45. package/esm/{index.js → esm.browser.js} +1184 -2399
  46. package/esm/esm.browser.js.map +1 -0
  47. package/esm/esm.node.mjs +9277 -0
  48. package/esm/esm.node.mjs.map +1 -0
  49. package/lib/AuthStateManager.d.ts +1 -3
  50. package/lib/OktaAuth.d.ts +5 -4
  51. package/lib/ServiceManager.d.ts +38 -0
  52. package/lib/TokenManager.d.ts +0 -1
  53. package/lib/idx/remediators/AuthenticatorVerificationData.d.ts +5 -5
  54. package/lib/idx/remediators/Base/AuthenticatorData.d.ts +5 -6
  55. package/lib/options/browser.d.ts +16 -0
  56. package/lib/{options.d.ts → options/index.d.ts} +1 -1
  57. package/lib/options/node.d.ts +16 -0
  58. package/lib/services/AutoRenewService.d.ts +27 -0
  59. package/lib/services/{TokenService.d.ts → SyncStorageService.d.ts} +8 -5
  60. package/lib/services/index.d.ts +13 -0
  61. package/lib/types/OktaAuthOptions.d.ts +5 -0
  62. package/lib/types/Service.d.ts +23 -0
  63. package/lib/types/api.d.ts +5 -2
  64. package/lib/types/index.d.ts +1 -0
  65. package/package.json +24 -10
  66. package/cjs/options.js.map +0 -1
  67. package/cjs/services/TokenService.js +0 -111
  68. package/cjs/services/TokenService.js.map +0 -1
  69. package/esm/index.js.map +0 -1
@@ -11,12 +11,11 @@
11
11
  */
12
12
  import { AuthState, AuthStateLogOptions } from './types';
13
13
  import { OktaAuth } from '.';
14
- declare const PCancelable: any;
15
14
  export declare const INITIAL_AUTH_STATE: null;
16
15
  export declare class AuthStateManager {
17
16
  _sdk: OktaAuth;
18
17
  _pending: {
19
- updateAuthStatePromise: typeof PCancelable;
18
+ updateAuthStatePromise: any;
20
19
  canceledTimes: number;
21
20
  };
22
21
  _authState: AuthState | null;
@@ -30,4 +29,3 @@ export declare class AuthStateManager {
30
29
  subscribe(handler: any): void;
31
30
  unsubscribe(handler?: any): void;
32
31
  }
33
- export {};
package/lib/OktaAuth.d.ts CHANGED
@@ -9,15 +9,15 @@
9
9
  *
10
10
  * See the License for the specific language governing permissions and limitations under the License.
11
11
  */
12
- import { OktaAuthInterface, OktaAuthOptions, AccessToken, RefreshToken, TokenAPI, FeaturesAPI, CryptoAPI, WebauthnAPI, SignoutAPI, FingerprintAPI, UserClaims, SigninWithRedirectOptions, SigninWithCredentialsOptions, SignoutOptions, Tokens, ForgotPasswordOptions, VerifyRecoveryTokenOptions, TransactionAPI, SessionAPI, SigninAPI, PkceAPI, SigninOptions, IdxAPI, SignoutRedirectUrlOptions, HttpAPI, RequestOptions } from './types';
12
+ import { OktaAuthInterface, OktaAuthOptions, AccessToken, RefreshToken, TokenAPI, FeaturesAPI, CryptoAPI, WebauthnAPI, SignoutAPI, FingerprintAPI, UserClaims, SigninWithRedirectOptions, SigninWithCredentialsOptions, SignoutOptions, Tokens, ForgotPasswordOptions, VerifyRecoveryTokenOptions, TransactionAPI, SessionAPI, SigninAPI, PkceAPI, SigninOptions, IdxAPI, SignoutRedirectUrlOptions, HttpAPI, RequestOptions, IsAuthenticatedOptions } from './types';
13
13
  import { AuthTransaction } from './tx';
14
14
  import { TokenManager } from './TokenManager';
15
+ import { ServiceManager } from './ServiceManager';
15
16
  import PromiseQueue from './PromiseQueue';
16
17
  import { AuthStateManager } from './AuthStateManager';
17
18
  import { StorageManager } from './StorageManager';
18
19
  import TransactionManager from './TransactionManager';
19
20
  import { OktaUserAgent } from './OktaUserAgent';
20
- declare const Emitter: any;
21
21
  declare class OktaAuth implements OktaAuthInterface, SigninAPI, SignoutAPI {
22
22
  options: OktaAuthOptions;
23
23
  storageManager: StorageManager;
@@ -32,9 +32,10 @@ declare class OktaAuth implements OktaAuthInterface, SigninAPI, SignoutAPI {
32
32
  features: FeaturesAPI;
33
33
  token: TokenAPI;
34
34
  _tokenQueue: PromiseQueue;
35
- emitter: typeof Emitter;
35
+ emitter: any;
36
36
  tokenManager: TokenManager;
37
37
  authStateManager: AuthStateManager;
38
+ serviceManager: ServiceManager;
38
39
  http: HttpAPI;
39
40
  fingerprint: FingerprintAPI;
40
41
  _oktaUserAgent: OktaUserAgent;
@@ -54,7 +55,7 @@ declare class OktaAuth implements OktaAuthInterface, SigninAPI, SignoutAPI {
54
55
  getSignOutRedirectUrl(options?: SignoutRedirectUrlOptions): string;
55
56
  signOut(options?: SignoutOptions): Promise<void>;
56
57
  webfinger(opts: any): Promise<object>;
57
- isAuthenticated(): Promise<boolean>;
58
+ isAuthenticated(options?: IsAuthenticatedOptions): Promise<boolean>;
58
59
  getUser(): Promise<UserClaims>;
59
60
  getIdToken(): string | undefined;
60
61
  getAccessToken(): string | undefined;
@@ -0,0 +1,38 @@
1
+ /*!
2
+ * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.
3
+ * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
4
+ *
5
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
6
+ * Unless required by applicable law or agreed to in writing, software
7
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
8
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
+ *
10
+ * See the License for the specific language governing permissions and limitations under the License.
11
+ */
12
+ import { ServiceManagerInterface, ServiceInterface, ServiceManagerOptions } from './types';
13
+ import { OktaAuth } from '.';
14
+ export declare class ServiceManager implements ServiceManagerInterface {
15
+ private sdk;
16
+ private options;
17
+ private services;
18
+ private channel?;
19
+ private elector?;
20
+ private started;
21
+ private static knownServices;
22
+ private static defaultOptions;
23
+ constructor(sdk: OktaAuth, options?: ServiceManagerOptions);
24
+ static canUseLeaderElection(): boolean;
25
+ private onLeader;
26
+ private onLeaderDuplicate;
27
+ isLeader(): boolean;
28
+ hasLeader(): boolean | undefined;
29
+ isLeaderRequired(): boolean;
30
+ start(): void;
31
+ stop(): void;
32
+ getService(name: string): ServiceInterface | undefined;
33
+ private startServices;
34
+ private stopServices;
35
+ private startElector;
36
+ private stopElector;
37
+ private createService;
38
+ }
@@ -11,7 +11,6 @@ export declare class TokenManager implements TokenManagerInterface {
11
11
  private storage;
12
12
  private state;
13
13
  private options;
14
- private service;
15
14
  on: (event: string, handler: TokenManagerErrorEventHandler | TokenManagerEventHandler, context?: object) => void;
16
15
  off: (event: string, handler?: TokenManagerErrorEventHandler | TokenManagerEventHandler) => void;
17
16
  constructor(sdk: OktaAuthInterface, options?: TokenManagerOptions);
@@ -10,15 +10,15 @@
10
10
  * See the License for the specific language governing permissions and limitations under the License.
11
11
  */
12
12
  import { AuthenticatorData, AuthenticatorDataValues } from './Base/AuthenticatorData';
13
+ import { IdxRemediation } from '../types/idx-js';
13
14
  export declare type AuthenticatorVerificationDataValues = AuthenticatorDataValues;
14
15
  export declare class AuthenticatorVerificationData extends AuthenticatorData {
15
16
  static remediationName: string;
16
17
  values: AuthenticatorVerificationDataValues;
17
- mapAuthenticator(): {
18
- id: string | import("../types/idx-js").IdxRemediationValueForm | undefined;
19
- enrollmentId: string | import("../types/idx-js").IdxRemediationValueForm | undefined;
20
- methodType: string | undefined;
21
- };
18
+ shouldProceedWithEmailAuthenticator: boolean;
19
+ constructor(remediation: IdxRemediation, values?: AuthenticatorDataValues);
20
+ canRemediate(): boolean;
21
+ mapAuthenticator(): {} | undefined;
22
22
  getInputAuthenticator(): import("../types/idx-js").IdxRemediationValue[] | {
23
23
  name: string;
24
24
  type: string;
@@ -10,8 +10,7 @@
10
10
  * See the License for the specific language governing permissions and limitations under the License.
11
11
  */
12
12
  import { Remediator, RemediationValues } from './Remediator';
13
- import { IdxRemediationValue, IdxOption, IdxRemediation } from '../../types/idx-js';
14
- import { Authenticator } from '../../types';
13
+ import { IdxRemediationValue, IdxOption, IdxRemediation, IdxAuthenticator } from '../../types/idx-js';
15
14
  export declare type AuthenticatorDataValues = RemediationValues & {
16
15
  methodType?: string;
17
16
  };
@@ -20,20 +19,20 @@ export declare class AuthenticatorData extends Remediator {
20
19
  authenticator: never[];
21
20
  };
22
21
  values: AuthenticatorDataValues;
23
- authenticator: Authenticator;
22
+ authenticator: IdxAuthenticator;
24
23
  constructor(remediation: IdxRemediation, values?: AuthenticatorDataValues);
25
24
  protected formatAuthenticatorData(): void;
26
- protected getAuthenticatorData(): Authenticator | undefined;
25
+ protected getAuthenticatorData(): import("../../types").Authenticator | undefined;
27
26
  canRemediate(): boolean;
28
27
  getNextStep(): {
29
28
  options: IdxOption[];
30
29
  name: string;
31
- authenticator?: import("../../types").IdxAuthenticator | undefined;
30
+ authenticator?: IdxAuthenticator | undefined;
32
31
  canSkip?: boolean | undefined;
33
32
  canResend?: boolean | undefined;
34
33
  inputs?: import("../../types").Input[] | undefined;
35
34
  poll?: import("../../types").IdxPollOptions | undefined;
36
- authenticatorEnrollments?: import("../../types").IdxAuthenticator[] | undefined;
35
+ authenticatorEnrollments?: IdxAuthenticator[] | undefined;
37
36
  };
38
37
  protected mapAuthenticatorDataFromValues(authenticatorData?: any): any;
39
38
  protected getAuthenticatorFromRemediation(): IdxRemediationValue;
@@ -0,0 +1,16 @@
1
+ /*!
2
+ * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.
3
+ * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
4
+ *
5
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
6
+ * Unless required by applicable law or agreed to in writing, software
7
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
8
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
+ *
10
+ * See the License for the specific language governing permissions and limitations under the License.
11
+ */
12
+ import { StorageManagerOptions, OktaAuthOptions } from '../types';
13
+ export { default as storage } from '../browser/browserStorage';
14
+ export declare const STORAGE_MANAGER_OPTIONS: StorageManagerOptions;
15
+ export declare const enableSharedStorage = true;
16
+ export declare function getCookieSettings(args: OktaAuthOptions | undefined, isHTTPS: boolean): import("../types").CookieOptions;
@@ -9,6 +9,6 @@
9
9
  *
10
10
  * See the License for the specific language governing permissions and limitations under the License.
11
11
  */
12
- import { OktaAuthOptions } from './types';
12
+ import { OktaAuthOptions } from '../types';
13
13
  export declare function getDefaultOptions(): OktaAuthOptions;
14
14
  export declare function buildOptions(args?: OktaAuthOptions): OktaAuthOptions;
@@ -0,0 +1,16 @@
1
+ /*!
2
+ * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.
3
+ * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
4
+ *
5
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
6
+ * Unless required by applicable law or agreed to in writing, software
7
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
8
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
+ *
10
+ * See the License for the specific language governing permissions and limitations under the License.
11
+ */
12
+ import { StorageManagerOptions, OktaAuthOptions } from '../types';
13
+ export { default as storage } from '../server/serverStorage';
14
+ export declare const STORAGE_MANAGER_OPTIONS: StorageManagerOptions;
15
+ export declare const enableSharedStorage = false;
16
+ export declare function getCookieSettings(args?: OktaAuthOptions, isHTTPS?: boolean): import("../types").CookieOptions | undefined;
@@ -0,0 +1,27 @@
1
+ /*!
2
+ * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.
3
+ * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
4
+ *
5
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
6
+ * Unless required by applicable law or agreed to in writing, software
7
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
8
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
+ *
10
+ * See the License for the specific language governing permissions and limitations under the License.
11
+ */
12
+ import { TokenManager } from '../TokenManager';
13
+ import { ServiceInterface, ServiceManagerOptions } from '../types';
14
+ export declare class AutoRenewService implements ServiceInterface {
15
+ private tokenManager;
16
+ private options;
17
+ private renewTimeQueue;
18
+ private started;
19
+ constructor(tokenManager: TokenManager, options?: ServiceManagerOptions);
20
+ private shouldThrottleRenew;
21
+ requiresLeadership(): boolean;
22
+ private onTokenExpiredHandler;
23
+ canStart(): boolean;
24
+ start(): void;
25
+ stop(): void;
26
+ isStarted(): boolean;
27
+ }
@@ -10,14 +10,17 @@
10
10
  * See the License for the specific language governing permissions and limitations under the License.
11
11
  */
12
12
  import { TokenManager } from '../TokenManager';
13
- import { TokenManagerOptions } from '../types';
14
- export declare class TokenService {
13
+ import { ServiceManagerOptions, ServiceInterface } from '../types';
14
+ export declare class SyncStorageService implements ServiceInterface {
15
15
  private tokenManager;
16
16
  private options;
17
- private storageListener?;
18
- private onTokenExpiredHandler?;
19
17
  private syncTimeout;
20
- constructor(tokenManager: TokenManager, options?: TokenManagerOptions);
18
+ private started;
19
+ constructor(tokenManager: TokenManager, options?: ServiceManagerOptions);
20
+ private storageListener;
21
+ requiresLeadership(): boolean;
22
+ isStarted(): boolean;
23
+ canStart(): boolean;
21
24
  start(): void;
22
25
  stop(): void;
23
26
  }
@@ -0,0 +1,13 @@
1
+ /*!
2
+ * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.
3
+ * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
4
+ *
5
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
6
+ * Unless required by applicable law or agreed to in writing, software
7
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
8
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
+ *
10
+ * See the License for the specific language governing permissions and limitations under the License.
11
+ */
12
+ export * from './AutoRenewService';
13
+ export * from './SyncStorageService';
@@ -15,7 +15,11 @@ import { HttpRequestClient } from './http';
15
15
  import { AuthState } from './AuthState';
16
16
  import { TransactionManagerOptions } from './Transaction';
17
17
  import { FlowIdentifier } from '../idx/types';
18
+ import { ServiceManagerOptions } from './Service';
18
19
  import OktaAuth from '../OktaAuth';
20
+ export interface IsAuthenticatedOptions {
21
+ onExpiredToken?: 'renew' | 'remove' | 'none';
22
+ }
19
23
  export interface TokenManagerOptions {
20
24
  autoRenew?: boolean;
21
25
  autoRemove?: boolean;
@@ -59,6 +63,7 @@ export interface OktaAuthOptions extends CustomUrls {
59
63
  restoreOriginalUri?: (oktaAuth: OktaAuth, originalUri?: string) => Promise<void>;
60
64
  devMode?: boolean;
61
65
  storageManager?: StorageManagerOptions;
66
+ services?: ServiceManagerOptions;
62
67
  transactionManager?: TransactionManagerOptions;
63
68
  flow?: FlowIdentifier;
64
69
  codeChallenge?: string;
@@ -0,0 +1,23 @@
1
+ export interface ServiceManagerInterface {
2
+ isLeader(): boolean;
3
+ start(): void;
4
+ stop(): void;
5
+ getService(name: string): ServiceInterface | undefined;
6
+ }
7
+ export interface ServiceInterface {
8
+ start(): void;
9
+ stop(): void;
10
+ isStarted(): boolean;
11
+ canStart(): boolean;
12
+ requiresLeadership(): boolean;
13
+ }
14
+ export interface AutoRenewServiceOptions {
15
+ autoRenew?: boolean;
16
+ autoRemove?: boolean;
17
+ }
18
+ export interface SyncStorageServiceOptions {
19
+ syncStorage?: boolean;
20
+ }
21
+ export declare type ServiceManagerOptions = AutoRenewServiceOptions & SyncStorageServiceOptions & {
22
+ broadcastChannelName?: string;
23
+ };
@@ -17,6 +17,7 @@ import { CustomUrls, OktaAuthOptions } from './OktaAuthOptions';
17
17
  import { StorageManager } from '../StorageManager';
18
18
  import TransactionManager from '../TransactionManager';
19
19
  import { TokenManagerInterface } from './TokenManager';
20
+ import { ServiceManagerInterface } from './Service';
20
21
  import { OktaUserAgent } from '../OktaUserAgent';
21
22
  import { AuthenticationOptions, RegistrationOptions as IdxRegistrationOptions, PasswordRecoveryOptions, AccountUnlockOptions, ProceedOptions, CancelOptions, IdxOptions, IdxTransaction, IdxTransactionMeta, EmailVerifyCallbackResponse, IdxAuthenticator, ChallengeData, ActivationData, WebauthnEnrollValues, WebauthnVerificationValues, FlowIdentifier, IdxPollOptions } from '../idx/types';
22
23
  import { InteractOptions, InteractResponse } from '../idx/interact';
@@ -31,6 +32,7 @@ export interface OktaAuthInterface {
31
32
  storageManager: StorageManager;
32
33
  transactionManager: TransactionManager;
33
34
  tokenManager: TokenManagerInterface;
35
+ serviceManager: ServiceManagerInterface;
34
36
  idx: IdxAPI;
35
37
  features: FeaturesAPI;
36
38
  token: TokenAPI;
@@ -180,13 +182,14 @@ export interface SigninOptions extends SupportsCodeFlow, AuthenticationOptions {
180
182
  deviceToken?: string;
181
183
  };
182
184
  sendFingerprint?: boolean;
185
+ stateToken?: string;
183
186
  }
184
187
  export interface SigninWithRedirectOptions extends SigninOptions, TokenParams {
185
188
  originalUri?: string;
186
189
  }
187
190
  export interface SigninWithCredentialsOptions extends SigninOptions {
188
- username: string;
189
- password: string;
191
+ username?: string;
192
+ password?: string;
190
193
  }
191
194
  export interface SigninAPI {
192
195
  signIn(opts: SigninOptions): Promise<AuthTransaction>;
@@ -22,4 +22,5 @@ export * from './OktaAuthOptions';
22
22
  export * from './Storage';
23
23
  export * from './Token';
24
24
  export * from './TokenManager';
25
+ export * from './Service';
25
26
  export * from './UserClaims';
package/package.json CHANGED
@@ -2,13 +2,23 @@
2
2
  "private": false,
3
3
  "name": "@okta/okta-auth-js",
4
4
  "description": "The Okta Auth SDK",
5
- "version": "6.1.0",
5
+ "version": "6.2.0",
6
6
  "homepage": "https://github.com/okta/okta-auth-js",
7
7
  "license": "Apache-2.0",
8
8
  "main": "cjs/index.js",
9
- "module": "esm/index.js",
9
+ "module": "esm/esm.node.mjs",
10
10
  "browser": "dist/okta-auth-js.umd.js",
11
11
  "types": "lib/index.d.ts",
12
+ "exports": {
13
+ "node": {
14
+ "import": "./esm/esm.node.mjs",
15
+ "require": "./cjs/index.js"
16
+ },
17
+ "browser": {
18
+ "import": "./esm/esm.browser.js"
19
+ },
20
+ "default": "./dist/okta-auth-js.umd.js"
21
+ },
12
22
  "repository": {
13
23
  "type": "git",
14
24
  "url": "https://github.com/okta/okta-auth-js.git"
@@ -20,7 +30,7 @@
20
30
  "banners": "node ./scripts/maintain-banners.js",
21
31
  "clean": "yarn clean:build",
22
32
  "clean:build": "rimraf build && rimraf build2",
23
- "dev": "webpack --config webpack.dev.config.js",
33
+ "dev": "NODE_ENV=development yarn build:esm --watch",
24
34
  "lint": "eslint .",
25
35
  "tsd": "tsd",
26
36
  "lint:report": "eslint -f checkstyle -o ./build2/reports/lint/eslint-checkstyle-result.xml .",
@@ -36,6 +46,9 @@
36
46
  "test:report": "yarn test --ci --silent || true",
37
47
  "test:samples": "yarn workspace @okta/test.e2e.samples start",
38
48
  "test:integration": "jest --config ./jest.integration.js",
49
+ "test:bundle:esm:browser": "cross-env BUNDLE_ENV=browser NODE_OPTIONS=--experimental-vm-modules jest --config ./jest.esm.mjs",
50
+ "test:bundle:esm:node": "cross-env BUNDLE_ENV=node NODE_OPTIONS=--experimental-vm-modules jest --config ./jest.esm.mjs",
51
+ "test:bundle:cjs": "cross-env BUNDLE_ENV=node jest --config ./jest.cjs.js",
39
52
  "build": "node scripts/build.js",
40
53
  "build:cdn": "cross-env NODE_ENV=production webpack --config webpack.cdn.config.js",
41
54
  "build:web": "cross-env NODE_ENV=production webpack --config webpack.config.js",
@@ -74,10 +87,11 @@
74
87
  "@peculiar/webcrypto": "1.1.6",
75
88
  "Base64": "1.1.0",
76
89
  "atob": "^2.1.2",
90
+ "broadcast-channel": "^4.10.0",
77
91
  "btoa": "^1.2.1",
78
92
  "core-js": "^3.6.5",
79
93
  "cross-fetch": "^3.1.5",
80
- "js-cookie": "2.2.1",
94
+ "js-cookie": "^3.0.1",
81
95
  "jsonpath-plus": "^6.0.1",
82
96
  "node-cache": "^5.1.2",
83
97
  "p-cancelable": "^2.0.0",
@@ -99,7 +113,7 @@
99
113
  "@rollup/plugin-alias": "^3.1.8",
100
114
  "@rollup/plugin-babel": "^5.3.0",
101
115
  "@rollup/plugin-replace": "^3.0.0",
102
- "@types/jest": "^25.2.3",
116
+ "@types/jest": "^27.4.0",
103
117
  "@types/node": "^14.0.3",
104
118
  "@typescript-eslint/eslint-plugin": "^2.34.0",
105
119
  "@typescript-eslint/parser": "^2.34.0",
@@ -119,7 +133,7 @@
119
133
  "globby": "^6.1.0",
120
134
  "istanbul-instrumenter-loader": "^3.0.1",
121
135
  "jasmine-ajax": "^4.0.0",
122
- "jest": "^26.6.3",
136
+ "jest": "^27.5.1",
123
137
  "jest-junit": "^9.0.0",
124
138
  "json-loader": "0.5.4",
125
139
  "lodash": "4.17.20",
@@ -128,7 +142,7 @@
128
142
  "rollup-plugin-license": "^2.6.0",
129
143
  "rollup-plugin-typescript2": "^0.30.0",
130
144
  "shelljs": "0.8.4",
131
- "ts-jest": "^26.4.3",
145
+ "ts-jest": "^27.1.3",
132
146
  "ts-loader": "^9.2.6",
133
147
  "tsd": "^0.17.0",
134
148
  "typescript": "^4.2.3",
@@ -172,8 +186,8 @@
172
186
  }
173
187
  },
174
188
  "okta": {
175
- "commitSha": "1478c1930c4034d0033f5af740dc996cbe58ceb5",
176
- "fullVersion": "6.1.0-g1478c19",
177
- "testedSha": "fe1efe5ae03fe0fce892e1f2738f6fa3fa448c5a"
189
+ "commitSha": "c1146b767599072407241c5d85486f00a5a3d0b1",
190
+ "fullVersion": "6.2.0-gc1146b7",
191
+ "testedSha": "f1acdd465de85c20d3ac73cdba345c926a94caf4"
178
192
  }
179
193
  }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../lib/options.ts"],"names":["BROWSER_STORAGE","token","storageTypes","cache","transaction","SERVER_STORAGE","getCookieSettings","args","isHTTPS","cookieSettings","cookies","secure","sameSite","getDefaultOptions","storageUtil","browserStorage","serverStorage","storageManager","enableSharedStorage","devMode","httpRequestClient","fetchRequest","transactionManager","mergeOptions","options","buildOptions","issuer","tokenUrl","authorizeUrl","userinfoUrl","revokeUrl","logoutUrl","clientId","redirectUri","state","scopes","postLogoutRedirectUri","responseMode","responseType","pkce","useInteractionCodeFlow","transformErrorXHR","transformAuthState","restoreOriginalUri","headers","flow","codeChallenge","codeChallengeMethod","recoveryToken","activationToken","ignoreSignature","clientSecret"],"mappings":";;;;;;;;;AAcA;;AACA;;AAGA;;AACA;;AACA;;AACA;;AArBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AAUA,MAAMA,eAAsC,GAAG;AAC7CC,EAAAA,KAAK,EAAE;AACLC,IAAAA,YAAY,EAAE,CACZ,cADY,EAEZ,gBAFY,EAGZ,QAHY;AADT,GADsC;AAQ7CC,EAAAA,KAAK,EAAE;AACLD,IAAAA,YAAY,EAAE,CACZ,cADY,EAEZ,gBAFY,EAGZ,QAHY;AADT,GARsC;AAe7CE,EAAAA,WAAW,EAAE;AACXF,IAAAA,YAAY,EAAE,CACZ,gBADY,EAEZ,cAFY,EAGZ,QAHY;AADH,GAfgC;AAsB7C,wBAAsB;AACpBA,IAAAA,YAAY,EAAE,CACZ,cADY;AADM,GAtBuB;AA2B7C,kBAAgB;AACdA,IAAAA,YAAY,EAAE,CACZ,cADY;AADA;AA3B6B,CAA/C;AAkCA,MAAMG,cAAqC,GAAG;AAC5CJ,EAAAA,KAAK,EAAE;AACLC,IAAAA,YAAY,EAAE,CACZ,QADY;AADT,GADqC;AAM5CC,EAAAA,KAAK,EAAE;AACLD,IAAAA,YAAY,EAAE,CACZ,QADY;AADT,GANqC;AAW5CE,EAAAA,WAAW,EAAE;AACXF,IAAAA,YAAY,EAAE,CACZ,QADY;AADH;AAX+B,CAA9C;;AAkBA,SAASI,iBAAT,CAA2BC,IAAqB,GAAG,EAAnD,EAAuDC,OAAvD,EAAyE;AACvE;AACA;AACA;AACA,MAAIC,cAAc,GAAGF,IAAI,CAACG,OAAL,IAAgB,EAArC;;AACA,MAAI,OAAOD,cAAc,CAACE,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a,iBAnBR;AAoBhBqB,IAAAA,iBAAiB,EAAElC,IAAI,CAACkC,iBApBR;AAqBhBC,IAAAA,kBAAkB,EAAEnC,IAAI,CAACmC,kBArBT;AAsBhBC,IAAAA,kBAAkB,EAAEpC,IAAI,CAACoC,kBAtBT;AAuBhB7B,IAAAA,WAAW,EAAEP,IAAI,CAACO,WAvBF;AAwBhB8B,IAAAA,OAAO,EAAErC,IAAI,CAACqC,OAxBE;AAyBhBzB,IAAAA,OAAO,EAAE,CAAC,CAACZ,IAAI,CAACY,OAzBA;AA0BhBF,IAAAA,cAAc,EAAEV,IAAI,CAACU,cA1BL;AA2BhBK,IAAAA,kBAAkB,EAAEf,IAAI,CAACe,kBA3BT;AA4BhBZ,IAAAA,OAAO,EAAE,6BAAcJ,iBAAiB,CAACC,IAAD,EAAO,wBAAP,CAA/B,GAAmDA,IAAI,CAACG,OA5BjD;AA6BhBmC,IAAAA,IAAI,EAAEtC,IAAI,CAACsC,IA7BK;AA8BhBC,IAAAA,aAAa,EAAEvC,IAAI,CAACuC,aA9BJ;AA+BhBC,IAAAA,mBAAmB,EAAExC,IAAI,CAACwC,mBA/BV;AAgChBC,IAAAA,aAAa,EAAEzC,IAAI,CAACyC,aAhCJ;AAiChBC,IAAAA,eAAe,EAAE1C,IAAI,CAAC0C,eAjCN;AAmChB;AACAC,IAAAA,eAAe,EAAE,CAAC,CAAC3C,IAAI,CAAC2C,eApCR;AAsChB;AACAC,IAAAA,YAAY,EAAE5C,IAAI,CAAC4C;AAvCH,GAAX,CAAP;AAyCD","sourcesContent":["/*!\n * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * \n * See the License for the specific language governing permissions and limitations under the License.\n */\n\n\n/* eslint-disable complexity */\nimport { removeTrailingSlash, warn, removeNils } from './util';\nimport { assertValidConfig } from './builderUtil';\nimport { OktaAuthOptions, StorageManagerOptions } from './types';\n\nimport fetchRequest from './fetch/fetchRequest';\nimport browserStorage from './browser/browserStorage';\nimport serverStorage from './server/serverStorage';\nimport { isBrowser, isHTTPS } from './features';\n\nconst BROWSER_STORAGE: StorageManagerOptions = {\n token: {\n storageTypes: [\n 'localStorage',\n 'sessionStorage',\n 'cookie'\n ]\n },\n cache: {\n storageTypes: [\n 'localStorage',\n 'sessionStorage',\n 'cookie'\n ]\n },\n transaction: {\n storageTypes: [\n 'sessionStorage',\n 'localStorage',\n 'cookie'\n ]\n },\n 'shared-transaction': {\n storageTypes: [\n 'localStorage'\n ]\n },\n 'original-uri': {\n storageTypes: [\n 'localStorage'\n ]\n }\n};\n\nconst SERVER_STORAGE: StorageManagerOptions = {\n token: {\n storageTypes: [\n 'memory'\n ]\n },\n cache: {\n storageTypes: [\n 'memory'\n ]\n },\n transaction: {\n storageTypes: [\n 'memory'\n ]\n }\n};\n\nfunction getCookieSettings(args: OktaAuthOptions = {}, isHTTPS: boolean) {\n // Secure cookies will be automatically used on a HTTPS connection\n // Non-secure cookies will be automatically used on a HTTP connection\n // secure option can override the automatic behavior\n var cookieSettings = args.cookies || {};\n if (typeof cookieSettings.secure === 'undefined') {\n cookieSettings.secure = isHTTPS;\n }\n if (typeof cookieSettings.sameSite === 'undefined') {\n cookieSettings.sameSite = cookieSettings.secure ? 'none' : 'lax';\n }\n\n // If secure=true, but the connection is not HTTPS, set secure=false.\n if (cookieSettings.secure && !isHTTPS) {\n // eslint-disable-next-line no-console\n warn(\n 'The current page is not being served with the HTTPS protocol.\\n' +\n 'For security reasons, we strongly recommend using HTTPS.\\n' +\n 'If you cannot use HTTPS, set \"cookies.secure\" option to false.'\n );\n cookieSettings.secure = false;\n }\n\n // Chrome >= 80 will block cookies with SameSite=None unless they are also Secure\n // If sameSite=none, but the connection is not HTTPS, set sameSite=lax.\n if (cookieSettings.sameSite === 'none' && !cookieSettings.secure) {\n cookieSettings.sameSite = 'lax';\n }\n\n return cookieSettings;\n}\n\n\nexport function getDefaultOptions(): OktaAuthOptions {\n const storageUtil = isBrowser() ? browserStorage : serverStorage;\n const storageManager = isBrowser() ? BROWSER_STORAGE : SERVER_STORAGE;\n const enableSharedStorage = isBrowser() ? true : false; // localStorage for multi-tab flows (browser only)\n return {\n devMode: false,\n httpRequestClient: fetchRequest,\n storageUtil,\n storageManager,\n transactionManager: {\n enableSharedStorage\n }\n };\n}\n\nfunction mergeOptions(options, args): OktaAuthOptions {\n return Object.assign({}, options, removeNils(args), {\n storageManager: Object.assign({}, options.storageManager, args.storageManager),\n transactionManager: Object.assign({}, options.transactionManager, args.transactionManager),\n });\n}\n\nexport function buildOptions(args: OktaAuthOptions = {}): OktaAuthOptions {\n assertValidConfig(args);\n args = mergeOptions(getDefaultOptions(), args);\n return removeNils({\n // OIDC configuration\n issuer: removeTrailingSlash(args.issuer),\n tokenUrl: removeTrailingSlash(args.tokenUrl),\n authorizeUrl: removeTrailingSlash(args.authorizeUrl),\n userinfoUrl: removeTrailingSlash(args.userinfoUrl),\n revokeUrl: removeTrailingSlash(args.revokeUrl),\n logoutUrl: removeTrailingSlash(args.logoutUrl),\n clientId: args.clientId,\n redirectUri: args.redirectUri,\n state: args.state,\n scopes: args.scopes,\n postLogoutRedirectUri: args.postLogoutRedirectUri,\n responseMode: args.responseMode,\n responseType: args.responseType,\n pkce: args.pkce === false ? false : true, // PKCE defaults to true\n useInteractionCodeFlow: args.useInteractionCodeFlow,\n\n // Internal options\n httpRequestClient: args.httpRequestClient,\n transformErrorXHR: args.transformErrorXHR,\n transformAuthState: args.transformAuthState,\n restoreOriginalUri: args.restoreOriginalUri,\n storageUtil: args.storageUtil,\n headers: args.headers,\n devMode: !!args.devMode,\n storageManager: args.storageManager,\n transactionManager: args.transactionManager,\n cookies: isBrowser() ? getCookieSettings(args, isHTTPS()) : args.cookies,\n flow: args.flow,\n codeChallenge: args.codeChallenge,\n codeChallengeMethod: args.codeChallengeMethod,\n recoveryToken: args.recoveryToken,\n activationToken: args.activationToken,\n \n // Give the developer the ability to disable token signature validation.\n ignoreSignature: !!args.ignoreSignature,\n\n // Server-side web applications\n clientSecret: args.clientSecret\n });\n}\n"],"file":"options.js"}
@@ -1,111 +0,0 @@
1
- "use strict";
2
-
3
- exports.TokenService = void 0;
4
-
5
- var _TokenManager = require("../TokenManager");
6
-
7
- var _errors = require("../errors");
8
-
9
- var _features = require("../features");
10
-
11
- /*!
12
- * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.
13
- * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
14
- *
15
- * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- *
20
- * See the License for the specific language governing permissions and limitations under the License.
21
- */
22
-
23
- /* global window */
24
- function shouldThrottleRenew(renewTimeQueue) {
25
- let res = false;
26
- renewTimeQueue.push(Date.now());
27
-
28
- if (renewTimeQueue.length >= 10) {
29
- // get and remove first item from queue
30
- const firstTime = renewTimeQueue.shift();
31
- const lastTime = renewTimeQueue[renewTimeQueue.length - 1];
32
- res = lastTime - firstTime < 30 * 1000;
33
- }
34
-
35
- return res;
36
- }
37
-
38
- class TokenService {
39
- constructor(tokenManager, options = {}) {
40
- this.tokenManager = tokenManager;
41
- this.options = options;
42
- this.storageListener = undefined;
43
- this.onTokenExpiredHandler = undefined;
44
- }
45
-
46
- start() {
47
- const renewTimeQueue = [];
48
-
49
- this.onTokenExpiredHandler = key => {
50
- if (this.options.autoRenew) {
51
- if (shouldThrottleRenew(renewTimeQueue)) {
52
- const error = new _errors.AuthSdkError('Too many token renew requests');
53
- this.tokenManager.emitError(error);
54
- } else {
55
- this.tokenManager.renew(key).catch(() => {}); // Renew errors will emit an "error" event
56
- }
57
- } else if (this.options.autoRemove) {
58
- this.tokenManager.remove(key);
59
- }
60
- };
61
-
62
- this.tokenManager.on(_TokenManager.EVENT_EXPIRED, this.onTokenExpiredHandler);
63
- this.tokenManager.setExpireEventTimeoutAll();
64
-
65
- if (this.options.syncStorage && (0, _features.isBrowser)()) {
66
- // Sync authState cross multiple tabs when localStorage is used as the storageProvider
67
- // A StorageEvent is sent to a window when a storage area it has access to is changed
68
- // within the context of another document.
69
- // https://developer.mozilla.org/en-US/docs/Web/API/StorageEvent
70
- this.storageListener = ({
71
- key,
72
- newValue,
73
- oldValue
74
- }) => {
75
- const handleCrossTabsStorageChange = () => {
76
- this.tokenManager.resetExpireEventTimeoutAll();
77
- this.tokenManager.emitEventsForCrossTabsStorageUpdate(newValue, oldValue);
78
- }; // Skip if:
79
- // not from localStorage.clear (event.key is null)
80
- // event.key is not the storageKey
81
- // oldValue === newValue
82
-
83
-
84
- if (key && (key !== this.options.storageKey || newValue === oldValue)) {
85
- return;
86
- } // LocalStorage cross tabs update is not synced in IE, set a 1s timer by default to read latest value
87
- // https://stackoverflow.com/questions/24077117/localstorage-in-win8-1-ie11-does-not-synchronize
88
-
89
-
90
- this.syncTimeout = setTimeout(() => handleCrossTabsStorageChange(), this.options._storageEventDelay);
91
- };
92
-
93
- window.addEventListener('storage', this.storageListener);
94
- }
95
- }
96
-
97
- stop() {
98
- this.tokenManager.clearExpireEventTimeoutAll();
99
- this.tokenManager.off(_TokenManager.EVENT_EXPIRED, this.onTokenExpiredHandler);
100
-
101
- if (this.options.syncStorage && (0, _features.isBrowser)()) {
102
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
103
- window.removeEventListener('storage', this.storageListener);
104
- clearTimeout(this.syncTimeout);
105
- }
106
- }
107
-
108
- }
109
-
110
- exports.TokenService = TokenService;
111
- //# sourceMappingURL=TokenService.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../lib/services/TokenService.ts"],"names":["shouldThrottleRenew","renewTimeQueue","res","push","Date","now","length","firstTime","shift","lastTime","TokenService","constructor","tokenManager","options","storageListener","undefined","onTokenExpiredHandler","start","key","autoRenew","error","AuthSdkError","emitError","renew","catch","autoRemove","remove","on","EVENT_EXPIRED","setExpireEventTimeoutAll","syncStorage","newValue","oldValue","handleCrossTabsStorageChange","resetExpireEventTimeoutAll","emitEventsForCrossTabsStorageUpdate","storageKey","syncTimeout","setTimeout","_storageEventDelay","window","addEventListener","stop","clearExpireEventTimeoutAll","off","removeEventListener","clearTimeout"],"mappings":";;;;AAcA;;AACA;;AACA;;AAhBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AAMA,SAASA,mBAAT,CAA6BC,cAA7B,EAA6C;AAC3C,MAAIC,GAAG,GAAG,KAAV;AACAD,EAAAA,cAAc,CAACE,IAAf,CAAoBC,IAAI,CAACC,GAAL,EAApB;;AACA,MAAIJ,cAAc,CAACK,MAAf,IAAyB,EAA7B,EAAiC;AAC/B;AACA,UAAMC,SAAS,GAAGN,cAAc,CAACO,KAAf,EAAlB;AACA,UAAMC,QAAQ,GAAGR,cAAc,CAACA,cAAc,CAACK,MAAf,GAAwB,CAAzB,CAA/B;AACAJ,IAAAA,GAAG,GAAGO,QAAQ,GAAGF,SAAX,GAAuB,KAAK,IAAlC;AACD;;AACD,SAAOL,GAAP;AACD;;AAEM,MAAMQ,YAAN,CAAmB;AAOxBC,EAAAA,WAAW,CAACC,YAAD,EAA6BC,OAA4B,GAAG,EAA5D,EAAgE;AACzE,SAAKD,YAAL,GAAoBA,YAApB;AACA,SAAKC,OAAL,GAAeA,OAAf;AACA,SAAKC,eAAL,GAAuBC,SAAvB;AACA,SAAKC,qBAAL,GAA6BD,SAA7B;AACD;;AAEDE,EAAAA,KAAK,GAAG;AACN,UAAMhB,cAAc,GAAG,EAAvB;;AACA,SAAKe,qBAAL,GAA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AC,MAAAA,MAAM,CAACC,gBAAP,CAAwB,SAAxB,EAAmC,KAAK3B,eAAxC;AACD;AACF;;AAED4B,EAAAA,IAAI,GAAG;AACL,SAAK9B,YAAL,CAAkB+B,0BAAlB;AACA,SAAK/B,YAAL,CAAkBgC,GAAlB,CAAsBhB,2BAAtB,EAAqC,KAAKZ,qBAA1C;;AACA,QAAI,KAAKH,OAAL,CAAaiB,WAAb,IAA4B,0BAAhC,EAA6C;AAC3C;AACAU,MAAAA,MAAM,CAACK,mBAAP,CAA2B,SAA3B,EAAsC,KAAK/B,eAA3C;AACAgC,MAAAA,YAAY,CAAC,KAAKT,WAAN,CAAZ;AACD;AACF;;AArEuB","sourcesContent":["/*!\n * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * \n * See the License for the specific language governing permissions and limitations under the License.\n */\n\n\n/* global window */\nimport { TokenManager, EVENT_EXPIRED } from '../TokenManager';\nimport { AuthSdkError } from '../errors';\nimport { isBrowser } from '../features';\nimport { TokenManagerOptions } from '../types';\n\nfunction shouldThrottleRenew(renewTimeQueue) {\n let res = false;\n renewTimeQueue.push(Date.now());\n if (renewTimeQueue.length >= 10) {\n // get and remove first item from queue\n const firstTime = renewTimeQueue.shift();\n const lastTime = renewTimeQueue[renewTimeQueue.length - 1];\n res = lastTime - firstTime < 30 * 1000;\n }\n return res;\n}\n\nexport class TokenService {\n private tokenManager: TokenManager;\n private options: TokenManagerOptions;\n private storageListener?: (event: StorageEvent) => void;\n private onTokenExpiredHandler?: (key: string) => void;\n private syncTimeout: unknown;\n\n constructor(tokenManager: TokenManager, options: TokenManagerOptions = {}) {\n this.tokenManager = tokenManager;\n this.options = options;\n this.storageListener = undefined;\n this.onTokenExpiredHandler = undefined;\n }\n\n start() {\n const renewTimeQueue = [];\n this.onTokenExpiredHandler = (key) => {\n if (this.options.autoRenew) {\n if (shouldThrottleRenew(renewTimeQueue)) {\n const error = new AuthSdkError('Too many token renew requests');\n this.tokenManager.emitError(error);\n } else {\n this.tokenManager.renew(key).catch(() => {}); // Renew errors will emit an \"error\" event \n }\n } else if (this.options.autoRemove) {\n this.tokenManager.remove(key);\n }\n };\n this.tokenManager.on(EVENT_EXPIRED, this.onTokenExpiredHandler);\n\n this.tokenManager.setExpireEventTimeoutAll();\n\n if (this.options.syncStorage && isBrowser()) {\n // Sync authState cross multiple tabs when localStorage is used as the storageProvider\n // A StorageEvent is sent to a window when a storage area it has access to is changed \n // within the context of another document.\n // https://developer.mozilla.org/en-US/docs/Web/API/StorageEvent\n\n this.storageListener = ({ key, newValue, oldValue }: StorageEvent) => {\n const handleCrossTabsStorageChange = () => {\n this.tokenManager.resetExpireEventTimeoutAll();\n this.tokenManager.emitEventsForCrossTabsStorageUpdate(newValue, oldValue);\n };\n\n // Skip if:\n // not from localStorage.clear (event.key is null)\n // event.key is not the storageKey\n // oldValue === newValue\n if (key && (key !== this.options.storageKey || newValue === oldValue)) {\n return;\n }\n\n // LocalStorage cross tabs update is not synced in IE, set a 1s timer by default to read latest value\n // https://stackoverflow.com/questions/24077117/localstorage-in-win8-1-ie11-does-not-synchronize\n this.syncTimeout = setTimeout(() => handleCrossTabsStorageChange(), this.options._storageEventDelay);\n };\n\n window.addEventListener('storage', this.storageListener);\n }\n }\n\n stop() {\n this.tokenManager.clearExpireEventTimeoutAll();\n this.tokenManager.off(EVENT_EXPIRED, this.onTokenExpiredHandler);\n if (this.options.syncStorage && isBrowser()) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n window.removeEventListener('storage', this.storageListener!);\n clearTimeout(this.syncTimeout as any);\n }\n }\n}"],"file":"TokenService.js"}