@asgardeo/browser 0.0.1 → 0.1.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.
package/dist/cjs/index.js CHANGED
@@ -1951,10 +1951,10 @@ __export(index_exports, {
1951
1951
  module.exports = __toCommonJS(index_exports);
1952
1952
 
1953
1953
  // src/__legacy__/client.ts
1954
- var import_javascript10 = require("@asgardeo/javascript");
1954
+ var import_javascript8 = require("@asgardeo/javascript");
1955
1955
 
1956
- // src/__legacy__/helpers/authentication-helper.ts
1957
- var import_javascript2 = require("@asgardeo/javascript");
1956
+ // src/__legacy__/clients/main-thread-client.ts
1957
+ var import_javascript6 = require("@asgardeo/javascript");
1958
1958
 
1959
1959
  // src/__legacy__/constants/messages-types.ts
1960
1960
  var INIT = "init";
@@ -2024,6 +2024,9 @@ var STATE_QUERY = "state";
2024
2024
  // src/__legacy__/constants/errors.ts
2025
2025
  var ACCESS_TOKEN_INVALID = "Access token is invalid";
2026
2026
 
2027
+ // src/__legacy__/helpers/authentication-helper.ts
2028
+ var import_javascript2 = require("@asgardeo/javascript");
2029
+
2027
2030
  // src/__legacy__/utils/message-utils.ts
2028
2031
  var MessageUtils = class {
2029
2032
  // eslint-disable-next-line @typescript-eslint/no-empty-function
@@ -2079,15 +2082,15 @@ var _SPAUtils = class _SPAUtils {
2079
2082
  static setPKCE(pkceKey, pkce) {
2080
2083
  sessionStorage.setItem(pkceKey, pkce);
2081
2084
  }
2082
- static setSignOutURL(url, clientID, instanceID) {
2085
+ static setSignOutURL(url, clientId, instanceID) {
2083
2086
  sessionStorage.setItem(
2084
- `${import_javascript.OIDCRequestConstants.SignOut.Storage.StorageKeys.SIGN_OUT_URL}-instance_${instanceID}-${clientID}`,
2087
+ `${import_javascript.OIDCRequestConstants.SignOut.Storage.StorageKeys.SIGN_OUT_URL}-instance_${instanceID}-${clientId}`,
2085
2088
  url
2086
2089
  );
2087
2090
  }
2088
- static getSignOutURL(clientID, instanceID) {
2091
+ static getSignOutUrl(clientId, instanceID) {
2089
2092
  return sessionStorage.getItem(
2090
- `${import_javascript.OIDCRequestConstants.SignOut.Storage.StorageKeys.SIGN_OUT_URL}-instance_${instanceID}-${clientID}`
2093
+ `${import_javascript.OIDCRequestConstants.SignOut.Storage.StorageKeys.SIGN_OUT_URL}-instance_${instanceID}-${clientId}`
2091
2094
  ) ?? "";
2092
2095
  }
2093
2096
  static removePKCE(pkceKey) {
@@ -2141,7 +2144,7 @@ var _SPAUtils = class _SPAUtils {
2141
2144
  if (import_javascript.AsgardeoAuthClient.isSignOutSuccessful(window.location.href)) {
2142
2145
  const newUrl = window.location.href.split("?")[0];
2143
2146
  history.pushState({}, document.title, newUrl);
2144
- await import_javascript.AsgardeoAuthClient.clearUserSessionData();
2147
+ await import_javascript.AsgardeoAuthClient.clearSession();
2145
2148
  return true;
2146
2149
  }
2147
2150
  return false;
@@ -2240,14 +2243,14 @@ var SPAUtils = _SPAUtils;
2240
2243
  var AuthenticationHelper = class {
2241
2244
  constructor(authClient, spaHelper) {
2242
2245
  __publicField(this, "_authenticationClient");
2243
- __publicField(this, "_dataLayer");
2246
+ __publicField(this, "_storageManager");
2244
2247
  __publicField(this, "_spaHelper");
2245
2248
  __publicField(this, "_instanceID");
2246
2249
  __publicField(this, "_isTokenRefreshing");
2247
2250
  this._authenticationClient = authClient;
2248
- this._dataLayer = this._authenticationClient.getDataLayer();
2251
+ this._storageManager = this._authenticationClient.getStorageManager();
2249
2252
  this._spaHelper = spaHelper;
2250
- this._instanceID = this._authenticationClient.getInstanceID();
2253
+ this._instanceID = this._authenticationClient.getInstanceId();
2251
2254
  this._isTokenRefreshing = false;
2252
2255
  }
2253
2256
  enableHttpHandler(httpClient) {
@@ -2258,22 +2261,22 @@ var AuthenticationHelper = class {
2258
2261
  }
2259
2262
  initializeSessionManger(config, oidcEndpoints, getSessionState, getAuthzURL, sessionManagementHelper) {
2260
2263
  sessionManagementHelper.initialize(
2261
- config.clientID,
2264
+ config.clientId,
2262
2265
  oidcEndpoints.checkSessionIframe ?? "",
2263
2266
  getSessionState,
2264
2267
  config.checkSessionInterval ?? 3,
2265
2268
  config.sessionRefreshInterval ?? 300,
2266
- config.signInRedirectURL,
2269
+ config.afterSignInUrl,
2267
2270
  getAuthzURL
2268
2271
  );
2269
2272
  }
2270
- async requestCustomGrant(config, enableRetrievingSignOutURLFromSession) {
2273
+ async exchangeToken(config, enableRetrievingSignOutURLFromSession) {
2271
2274
  let useDefaultEndpoint = true;
2272
2275
  let matches = false;
2273
2276
  if (config?.tokenEndpoint) {
2274
2277
  useDefaultEndpoint = false;
2275
2278
  for (const baseUrl of [
2276
- ...(await this._dataLayer.getConfigData())?.resourceServerURLs ?? [],
2279
+ ...(await this._storageManager.getConfigData())?.resourceServerURLs ?? [],
2277
2280
  config.baseUrl
2278
2281
  ]) {
2279
2282
  if (baseUrl && config.tokenEndpoint?.startsWith(baseUrl)) {
@@ -2283,16 +2286,16 @@ var AuthenticationHelper = class {
2283
2286
  }
2284
2287
  }
2285
2288
  if (config.shouldReplayAfterRefresh) {
2286
- this._dataLayer.setTemporaryDataParameter(CUSTOM_GRANT_CONFIG, JSON.stringify(config));
2289
+ this._storageManager.setTemporaryDataParameter(CUSTOM_GRANT_CONFIG, JSON.stringify(config));
2287
2290
  }
2288
2291
  if (useDefaultEndpoint || matches) {
2289
- return this._authenticationClient.requestCustomGrant(config).then(async (response) => {
2292
+ return this._authenticationClient.exchangeToken(config).then(async (response) => {
2290
2293
  if (enableRetrievingSignOutURLFromSession && typeof enableRetrievingSignOutURLFromSession === "function") {
2291
2294
  enableRetrievingSignOutURLFromSession(config);
2292
2295
  }
2293
2296
  if (config.returnsSession) {
2294
2297
  this._spaHelper.refreshAccessTokenAutomatically(this);
2295
- return this._authenticationClient.getBasicUserInfo();
2298
+ return this._authenticationClient.getUser();
2296
2299
  } else {
2297
2300
  return response;
2298
2301
  }
@@ -2310,7 +2313,7 @@ var AuthenticationHelper = class {
2310
2313
  }
2311
2314
  }
2312
2315
  async getCustomGrantConfigData() {
2313
- const configString = await this._dataLayer.getTemporaryDataParameter(CUSTOM_GRANT_CONFIG);
2316
+ const configString = await this._storageManager.getTemporaryDataParameter(CUSTOM_GRANT_CONFIG);
2314
2317
  if (configString) {
2315
2318
  return JSON.parse(configString);
2316
2319
  } else {
@@ -2322,10 +2325,10 @@ var AuthenticationHelper = class {
2322
2325
  await this._authenticationClient.refreshAccessToken();
2323
2326
  const customGrantConfig = await this.getCustomGrantConfigData();
2324
2327
  if (customGrantConfig) {
2325
- await this.requestCustomGrant(customGrantConfig, enableRetrievingSignOutURLFromSession);
2328
+ await this.exchangeToken(customGrantConfig, enableRetrievingSignOutURLFromSession);
2326
2329
  }
2327
2330
  this._spaHelper.refreshAccessTokenAutomatically(this);
2328
- return this._authenticationClient.getBasicUserInfo();
2331
+ return this._authenticationClient.getUser();
2329
2332
  } catch (error) {
2330
2333
  const refreshTokenError = {
2331
2334
  type: REFRESH_ACCESS_TOKEN_ERR0R
@@ -2358,7 +2361,7 @@ var AuthenticationHelper = class {
2358
2361
  }
2359
2362
  async httpRequest(httpClient, requestConfig, isHttpHandlerEnabled, httpErrorCallback, httpFinishCallback, enableRetrievingSignOutURLFromSession) {
2360
2363
  let matches = false;
2361
- const config = await this._dataLayer.getConfigData();
2364
+ const config = await this._storageManager.getConfigData();
2362
2365
  for (const baseUrl of [...await config?.resourceServerURLs ?? [], config.baseUrl]) {
2363
2366
  if (baseUrl && requestConfig?.url?.startsWith(baseUrl)) {
2364
2367
  matches = true;
@@ -2443,7 +2446,7 @@ var AuthenticationHelper = class {
2443
2446
  }
2444
2447
  async httpRequestAll(requestConfigs, httpClient, isHttpHandlerEnabled, httpErrorCallback, httpFinishCallback) {
2445
2448
  let matches = true;
2446
- const config = await this._dataLayer.getConfigData();
2449
+ const config = await this._storageManager.getConfigData();
2447
2450
  for (const requestConfig of requestConfigs) {
2448
2451
  let urlMatches = false;
2449
2452
  for (const baseUrl of [...(await config)?.resourceServerURLs ?? [], config.baseUrl]) {
@@ -2522,7 +2525,7 @@ var AuthenticationHelper = class {
2522
2525
  }
2523
2526
  }
2524
2527
  async requestAccessToken(authorizationCode, sessionState, checkSession, pkce, state, tokenRequestConfig) {
2525
- const config = await this._dataLayer.getConfigData();
2528
+ const config = await this._storageManager.getConfigData();
2526
2529
  if (config.storage === "browserMemory" /* BrowserMemory */ && config.enablePKCE && sessionState) {
2527
2530
  const pkce2 = SPAUtils.getPKCE((0, import_javascript2.extractPkceStorageKeyFromState)(sessionState));
2528
2531
  await this._authenticationClient.setPKCECode((0, import_javascript2.extractPkceStorageKeyFromState)(sessionState), pkce2);
@@ -2532,7 +2535,7 @@ var AuthenticationHelper = class {
2532
2535
  if (authorizationCode) {
2533
2536
  return this._authenticationClient.requestAccessToken(authorizationCode, sessionState ?? "", state ?? "", void 0, tokenRequestConfig).then(async () => {
2534
2537
  if (config.storage !== "webWorker" /* WebWorker */) {
2535
- SPAUtils.setSignOutURL(await this._authenticationClient.getSignOutURL(), config.clientID, this._instanceID);
2538
+ SPAUtils.setSignOutURL(await this._authenticationClient.getSignOutUrl(), config.clientId, this._instanceID);
2536
2539
  if (this._spaHelper) {
2537
2540
  this._spaHelper.clearRefreshTokenTimeout();
2538
2541
  this._spaHelper.refreshAccessTokenAutomatically(this);
@@ -2545,7 +2548,7 @@ var AuthenticationHelper = class {
2545
2548
  this._spaHelper.refreshAccessTokenAutomatically(this);
2546
2549
  }
2547
2550
  }
2548
- return this._authenticationClient.getBasicUserInfo();
2551
+ return this._authenticationClient.getUser();
2549
2552
  }).catch((error) => {
2550
2553
  return Promise.reject(error);
2551
2554
  });
@@ -2608,7 +2611,7 @@ var AuthenticationHelper = class {
2608
2611
  });
2609
2612
  }
2610
2613
  async handleSignIn(shouldStopAuthn, checkSession, tryRetrievingUserInfo) {
2611
- const config = await this._dataLayer.getConfigData();
2614
+ const config = await this._storageManager.getConfigData();
2612
2615
  if (await shouldStopAuthn()) {
2613
2616
  return Promise.resolve({
2614
2617
  allowedScopes: "",
@@ -2621,13 +2624,13 @@ var AuthenticationHelper = class {
2621
2624
  });
2622
2625
  }
2623
2626
  if (config.storage !== "webWorker" /* WebWorker */) {
2624
- if (await this._authenticationClient.isAuthenticated()) {
2627
+ if (await this._authenticationClient.isSignedIn()) {
2625
2628
  this._spaHelper.clearRefreshTokenTimeout();
2626
2629
  this._spaHelper.refreshAccessTokenAutomatically(this);
2627
2630
  if (config.enableOIDCSessionManagement) {
2628
2631
  checkSession();
2629
2632
  }
2630
- return Promise.resolve(await this._authenticationClient.getBasicUserInfo());
2633
+ return Promise.resolve(await this._authenticationClient.getUser());
2631
2634
  }
2632
2635
  }
2633
2636
  const error = new URL(window.location.href).searchParams.get(ERROR);
@@ -2663,35 +2666,35 @@ var AuthenticationHelper = class {
2663
2666
  }
2664
2667
  }
2665
2668
  }
2666
- async getBasicUserInfo() {
2667
- return this._authenticationClient.getBasicUserInfo();
2669
+ async getUser() {
2670
+ return this._authenticationClient.getUser();
2668
2671
  }
2669
- async getDecodedIDToken() {
2670
- return this._authenticationClient.getDecodedIDToken();
2672
+ async getDecodedIdToken() {
2673
+ return this._authenticationClient.getDecodedIdToken();
2671
2674
  }
2672
2675
  async getDecodedIDPIDToken() {
2673
- return this._authenticationClient.getDecodedIDToken();
2676
+ return this._authenticationClient.getDecodedIdToken();
2674
2677
  }
2675
- async getCryptoHelper() {
2676
- return this._authenticationClient.getCryptoHelper();
2678
+ async getCrypto() {
2679
+ return this._authenticationClient.getCrypto();
2677
2680
  }
2678
- async getIDToken() {
2679
- return this._authenticationClient.getIDToken();
2681
+ async getIdToken() {
2682
+ return this._authenticationClient.getIdToken();
2680
2683
  }
2681
- async getOIDCServiceEndpoints() {
2682
- return this._authenticationClient.getOIDCServiceEndpoints();
2684
+ async getOpenIDProviderEndpoints() {
2685
+ return this._authenticationClient.getOpenIDProviderEndpoints();
2683
2686
  }
2684
2687
  async getAccessToken() {
2685
2688
  return this._authenticationClient.getAccessToken();
2686
2689
  }
2687
2690
  async getIDPAccessToken() {
2688
- return (await this._dataLayer.getSessionData())?.access_token;
2691
+ return (await this._storageManager.getSessionData())?.access_token;
2689
2692
  }
2690
- getDataLayer() {
2691
- return this._dataLayer;
2693
+ getStorageManager() {
2694
+ return this._storageManager;
2692
2695
  }
2693
- async isAuthenticated() {
2694
- return this._authenticationClient.isAuthenticated();
2696
+ async isSignedIn() {
2697
+ return this._authenticationClient.isSignedIn();
2695
2698
  }
2696
2699
  };
2697
2700
 
@@ -2700,32 +2703,32 @@ var import_javascript3 = require("@asgardeo/javascript");
2700
2703
  var SPAHelper = class {
2701
2704
  constructor(authClient) {
2702
2705
  __publicField(this, "_authenticationClient");
2703
- __publicField(this, "_dataLayer");
2706
+ __publicField(this, "_storageManager");
2704
2707
  this._authenticationClient = authClient;
2705
- this._dataLayer = this._authenticationClient.getDataLayer();
2708
+ this._storageManager = this._authenticationClient.getStorageManager();
2706
2709
  }
2707
2710
  async refreshAccessTokenAutomatically(authenticationHelper) {
2708
- const shouldRefreshAutomatically = (await this._dataLayer.getConfigData())?.periodicTokenRefresh ?? false;
2711
+ const shouldRefreshAutomatically = (await this._storageManager.getConfigData())?.periodicTokenRefresh ?? false;
2709
2712
  if (!shouldRefreshAutomatically) {
2710
2713
  return;
2711
2714
  }
2712
- const sessionData = await this._dataLayer.getSessionData();
2715
+ const sessionData = await this._storageManager.getSessionData();
2713
2716
  if (sessionData.refresh_token) {
2714
2717
  const expiryTime = parseInt(sessionData.expires_in);
2715
2718
  const time = expiryTime <= 10 ? expiryTime : expiryTime - 10;
2716
2719
  const timer = setTimeout(async () => {
2717
2720
  await authenticationHelper.refreshAccessToken();
2718
2721
  }, time * 1e3);
2719
- await this._dataLayer.setTemporaryDataParameter(
2722
+ await this._storageManager.setTemporaryDataParameter(
2720
2723
  import_javascript3.TokenConstants.Storage.StorageKeys.REFRESH_TOKEN_TIMER,
2721
2724
  JSON.stringify(timer)
2722
2725
  );
2723
2726
  }
2724
2727
  }
2725
2728
  async getRefreshTimeoutTimer() {
2726
- if (await this._dataLayer.getTemporaryDataParameter(import_javascript3.TokenConstants.Storage.StorageKeys.REFRESH_TOKEN_TIMER)) {
2729
+ if (await this._storageManager.getTemporaryDataParameter(import_javascript3.TokenConstants.Storage.StorageKeys.REFRESH_TOKEN_TIMER)) {
2727
2730
  return JSON.parse(
2728
- await this._dataLayer.getTemporaryDataParameter(
2731
+ await this._storageManager.getTemporaryDataParameter(
2729
2732
  import_javascript3.TokenConstants.Storage.StorageKeys.REFRESH_TOKEN_TIMER
2730
2733
  )
2731
2734
  );
@@ -2758,15 +2761,15 @@ var SessionManagementHelper = /* @__PURE__ */ (() => {
2758
2761
  let _checkSessionIntervalTimeout;
2759
2762
  let _storage;
2760
2763
  let _setSessionState;
2761
- let _getAuthorizationURL;
2762
- const initialize = (clientID, checkSessionEndpoint, getSessionState, interval, sessionRefreshInterval, redirectURL, getAuthorizationURL) => {
2763
- _clientID = clientID;
2764
+ let _getSignInUrl;
2765
+ const initialize = (clientId, checkSessionEndpoint, getSessionState, interval, sessionRefreshInterval, redirectURL, getSignInUrl) => {
2766
+ _clientID = clientId;
2764
2767
  _checkSessionEndpoint = checkSessionEndpoint;
2765
2768
  _sessionState = getSessionState;
2766
2769
  _interval = interval;
2767
2770
  _redirectURL = redirectURL;
2768
2771
  _sessionRefreshInterval = sessionRefreshInterval;
2769
- _getAuthorizationURL = getAuthorizationURL;
2772
+ _getSignInUrl = getSignInUrl;
2770
2773
  if (_interval > -1) {
2771
2774
  initiateCheckSession();
2772
2775
  }
@@ -2832,7 +2835,7 @@ var SessionManagementHelper = /* @__PURE__ */ (() => {
2832
2835
  if (_storage === "browserMemory" /* BrowserMemory */ || _storage === "webWorker" /* WebWorker */) {
2833
2836
  window?.addEventListener("message", receiveMessageListener);
2834
2837
  }
2835
- const promptNoneURL = await _getAuthorizationURL({
2838
+ const promptNoneURL = await _getSignInUrl({
2836
2839
  prompt: "none",
2837
2840
  response_mode: "query",
2838
2841
  state: STATE
@@ -2890,7 +2893,7 @@ var SessionManagementHelper = /* @__PURE__ */ (() => {
2890
2893
  }
2891
2894
  SPAUtils.setPromptNoneRequestSent(false);
2892
2895
  const signOutURL = await _signOut();
2893
- await import_javascript4.AsgardeoAuthClient.clearUserSessionData();
2896
+ await import_javascript4.AsgardeoAuthClient.clearSession();
2894
2897
  parent.location.href = signOutURL;
2895
2898
  window.location.href = "about:blank";
2896
2899
  await SPAUtils.waitTillPageRedirect();
@@ -2939,12 +2942,6 @@ var SessionManagementHelper = /* @__PURE__ */ (() => {
2939
2942
  };
2940
2943
  })();
2941
2944
 
2942
- // src/__legacy__/worker/worker-receiver.ts
2943
- var import_javascript7 = require("@asgardeo/javascript");
2944
-
2945
- // src/__legacy__/worker/worker-core.ts
2946
- var import_javascript6 = require("@asgardeo/javascript");
2947
-
2948
2945
  // src/__legacy__/http-client/clients/axios-http-client.ts
2949
2946
  var import_axios = __toESM(require("axios"), 1);
2950
2947
 
@@ -3196,10 +3193,10 @@ var SPACryptoUtils = class {
3196
3193
  generateRandomBytes(length) {
3197
3194
  return (0, import_randombytes.default)(length);
3198
3195
  }
3199
- verifyJwt(idToken, jwk, algorithms, clientID, issuer, subject, clockTolerance, validateJwtIssuer) {
3196
+ verifyJwt(idToken, jwk, algorithms, clientId, issuer, subject, clockTolerance, validateJwtIssuer) {
3200
3197
  const jwtVerifyOptions = {
3201
3198
  algorithms,
3202
- audience: clientID,
3199
+ audience: clientId,
3203
3200
  clockTolerance,
3204
3201
  subject
3205
3202
  };
@@ -3226,19 +3223,42 @@ var SPACryptoUtils = class {
3226
3223
  }
3227
3224
  };
3228
3225
 
3229
- // src/__legacy__/worker/worker-core.ts
3230
- var WebWorkerCore = async (config, getAuthHelper) => {
3231
- const _store = new MemoryStore();
3226
+ // src/__legacy__/clients/main-thread-client.ts
3227
+ var initiateStore = (store) => {
3228
+ switch (store) {
3229
+ case "localStorage" /* LocalStorage */:
3230
+ return new LocalStore();
3231
+ case "sessionStorage" /* SessionStorage */:
3232
+ return new SessionStore();
3233
+ case "browserMemory" /* BrowserMemory */:
3234
+ return new MemoryStore();
3235
+ default:
3236
+ return new SessionStore();
3237
+ }
3238
+ };
3239
+ var MainThreadClient = async (instanceID, config, getAuthHelper) => {
3240
+ const _store = initiateStore(config.storage);
3232
3241
  const _cryptoUtils = new SPACryptoUtils();
3233
3242
  const _authenticationClient = new import_javascript6.AsgardeoAuthClient();
3234
- await _authenticationClient.initialize(config, _store, _cryptoUtils);
3243
+ await _authenticationClient.initialize(config, _store, _cryptoUtils, instanceID);
3235
3244
  const _spaHelper = new SPAHelper(_authenticationClient);
3236
- const _authenticationHelper = getAuthHelper(
3237
- _authenticationClient,
3238
- _spaHelper
3245
+ const _dataLayer = _authenticationClient.getStorageManager();
3246
+ const _sessionManagementHelper = await SessionManagementHelper(
3247
+ async () => {
3248
+ return _authenticationClient.getSignOutUrl();
3249
+ },
3250
+ config.storage ?? "sessionStorage" /* SessionStorage */,
3251
+ (sessionState) => _dataLayer.setSessionDataParameter(
3252
+ import_javascript6.OIDCRequestConstants.Params.SESSION_STATE,
3253
+ sessionState ?? ""
3254
+ )
3239
3255
  );
3240
- const _dataLayer = _authenticationClient.getDataLayer();
3256
+ const _authenticationHelper = getAuthHelper(_authenticationClient, _spaHelper);
3257
+ let _getSignOutURLFromSessionStorage = false;
3241
3258
  const _httpClient = HttpClient.getInstance();
3259
+ let _isHttpHandlerEnabled = true;
3260
+ let _httpErrorCallback;
3261
+ let _httpFinishCallback;
3242
3262
  const attachToken = async (request) => {
3243
3263
  await _authenticationHelper.attachTokenToRequestConfig(request);
3244
3264
  };
@@ -3252,47 +3272,156 @@ var WebWorkerCore = async (config, getAuthHelper) => {
3252
3272
  const setHttpRequestFinishCallback = (callback) => {
3253
3273
  _httpClient?.setHttpRequestFinishCallback && _httpClient.setHttpRequestFinishCallback(callback);
3254
3274
  };
3275
+ const setHttpRequestErrorCallback = (callback) => {
3276
+ _httpErrorCallback = callback;
3277
+ };
3255
3278
  const httpRequest = async (requestConfig) => {
3256
- return await _authenticationHelper.httpRequest(_httpClient, requestConfig);
3279
+ return await _authenticationHelper.httpRequest(
3280
+ _httpClient,
3281
+ requestConfig,
3282
+ _isHttpHandlerEnabled,
3283
+ _httpErrorCallback,
3284
+ _httpFinishCallback
3285
+ );
3257
3286
  };
3258
3287
  const httpRequestAll = async (requestConfigs) => {
3259
- return await _authenticationHelper.httpRequestAll(requestConfigs, _httpClient);
3288
+ return await _authenticationHelper.httpRequestAll(
3289
+ requestConfigs,
3290
+ _httpClient,
3291
+ _isHttpHandlerEnabled,
3292
+ _httpErrorCallback,
3293
+ _httpFinishCallback
3294
+ );
3295
+ };
3296
+ const getHttpClient = () => {
3297
+ return _httpClient;
3260
3298
  };
3261
3299
  const enableHttpHandler = () => {
3262
3300
  _authenticationHelper.enableHttpHandler(_httpClient);
3301
+ _isHttpHandlerEnabled = true;
3302
+ return true;
3263
3303
  };
3264
3304
  const disableHttpHandler = () => {
3265
3305
  _authenticationHelper.disableHttpHandler(_httpClient);
3306
+ _isHttpHandlerEnabled = false;
3307
+ return true;
3266
3308
  };
3267
- const getAuthorizationURL = async (params) => {
3268
- return _authenticationClient.getAuthorizationURL(params).then(async (url) => {
3269
- const urlObject = new URL(url);
3270
- const state = urlObject.searchParams.get(import_javascript6.OIDCRequestConstants.Params.STATE) ?? "";
3271
- const pkce = await _authenticationClient.getPKCECode(state);
3272
- return { authorizationURL: url, pkce };
3273
- }).catch((error) => Promise.reject(error));
3309
+ const checkSession = async () => {
3310
+ const oidcEndpoints = await _authenticationClient.getOpenIDProviderEndpoints();
3311
+ const config2 = await _dataLayer.getConfigData();
3312
+ _authenticationHelper.initializeSessionManger(
3313
+ config2,
3314
+ oidcEndpoints,
3315
+ async () => (await _authenticationClient.getUserSession()).sessionState,
3316
+ async (params) => _authenticationClient.getSignInUrl(params),
3317
+ _sessionManagementHelper
3318
+ );
3274
3319
  };
3275
- const startAutoRefreshToken = async () => {
3276
- _spaHelper.clearRefreshTokenTimeout();
3277
- _spaHelper.refreshAccessTokenAutomatically(_authenticationHelper);
3278
- return;
3320
+ const shouldStopAuthn = async () => {
3321
+ return await _sessionManagementHelper.receivePromptNoneResponse(async (sessionState) => {
3322
+ await _dataLayer.setSessionDataParameter(
3323
+ import_javascript6.OIDCRequestConstants.Params.SESSION_STATE,
3324
+ sessionState ?? ""
3325
+ );
3326
+ return;
3327
+ });
3279
3328
  };
3280
- const requestAccessToken = async (authorizationCode, sessionState, pkce, state) => {
3281
- return await _authenticationHelper.requestAccessToken(authorizationCode, sessionState, void 0, pkce, state);
3329
+ const setSessionStatus = async (sessionStatus) => {
3330
+ await _dataLayer.setSessionStatus(sessionStatus);
3331
+ };
3332
+ const signIn = async (signInConfig, authorizationCode, sessionState, state, tokenRequestConfig) => {
3333
+ if (signInConfig["flow"]) {
3334
+ return (0, import_javascript6.handleApplicationNativeAuthentication)({
3335
+ url: signInConfig["flow"]["requestConfig"]["url"],
3336
+ payload: signInConfig["flow"]["payload"]
3337
+ });
3338
+ }
3339
+ const basicUserInfo = await _authenticationHelper.handleSignIn(shouldStopAuthn, checkSession, void 0);
3340
+ if (basicUserInfo) {
3341
+ return basicUserInfo;
3342
+ } else {
3343
+ let resolvedAuthorizationCode;
3344
+ let resolvedSessionState;
3345
+ let resolvedState;
3346
+ let resolvedTokenRequestConfig = { params: {} };
3347
+ if (config?.responseMode === "form_post" && authorizationCode) {
3348
+ resolvedAuthorizationCode = authorizationCode;
3349
+ resolvedSessionState = sessionState ?? "";
3350
+ resolvedState = state ?? "";
3351
+ } else {
3352
+ resolvedAuthorizationCode = new URL(window.location.href).searchParams.get(import_javascript6.OIDCRequestConstants.Params.AUTHORIZATION_CODE) ?? "";
3353
+ resolvedSessionState = new URL(window.location.href).searchParams.get(import_javascript6.OIDCRequestConstants.Params.SESSION_STATE) ?? "";
3354
+ resolvedState = new URL(window.location.href).searchParams.get(import_javascript6.OIDCRequestConstants.Params.STATE) ?? "";
3355
+ SPAUtils.removeAuthorizationCode();
3356
+ }
3357
+ if (resolvedAuthorizationCode && resolvedState) {
3358
+ setSessionStatus("true");
3359
+ const storedTokenRequestConfig = await _dataLayer.getTemporaryDataParameter(TOKEN_REQUEST_CONFIG_KEY);
3360
+ if (storedTokenRequestConfig && typeof storedTokenRequestConfig === "string") {
3361
+ resolvedTokenRequestConfig = JSON.parse(storedTokenRequestConfig);
3362
+ }
3363
+ return requestAccessToken(
3364
+ resolvedAuthorizationCode,
3365
+ resolvedSessionState,
3366
+ resolvedState,
3367
+ resolvedTokenRequestConfig
3368
+ );
3369
+ }
3370
+ return _authenticationClient.getSignInUrl(signInConfig).then(async (url) => {
3371
+ if (config.storage === "browserMemory" /* BrowserMemory */ && config.enablePKCE) {
3372
+ const pkceKey = (0, import_javascript6.extractPkceStorageKeyFromState)(resolvedState);
3373
+ SPAUtils.setPKCE(pkceKey, await _authenticationClient.getPKCECode(resolvedState));
3374
+ }
3375
+ if (tokenRequestConfig) {
3376
+ _dataLayer.setTemporaryDataParameter(TOKEN_REQUEST_CONFIG_KEY, JSON.stringify(tokenRequestConfig));
3377
+ }
3378
+ if (signInConfig["response_mode"] === "direct") {
3379
+ const authorizeUrl = new URL(url);
3380
+ return (0, import_javascript6.initializeApplicationNativeAuthentication)({
3381
+ url: `${authorizeUrl.origin}${authorizeUrl.pathname}`,
3382
+ payload: Object.fromEntries(authorizeUrl.searchParams.entries())
3383
+ });
3384
+ } else {
3385
+ location.href = url;
3386
+ }
3387
+ await SPAUtils.waitTillPageRedirect();
3388
+ return Promise.resolve({
3389
+ allowedScopes: "",
3390
+ displayName: "",
3391
+ email: "",
3392
+ sessionState: "",
3393
+ sub: "",
3394
+ tenantDomain: "",
3395
+ username: ""
3396
+ });
3397
+ });
3398
+ }
3282
3399
  };
3283
3400
  const signOut = async () => {
3401
+ if (await _authenticationClient.isSignedIn() && !_getSignOutURLFromSessionStorage) {
3402
+ location.href = await _authenticationClient.getSignOutUrl();
3403
+ } else {
3404
+ location.href = SPAUtils.getSignOutUrl(config.clientId, instanceID);
3405
+ }
3284
3406
  _spaHelper.clearRefreshTokenTimeout();
3285
- return await _authenticationClient.getSignOutURL();
3407
+ await _dataLayer.removeOIDCProviderMetaData();
3408
+ await _dataLayer.removeTemporaryData();
3409
+ await _dataLayer.removeSessionData();
3410
+ await _dataLayer.removeSessionStatus();
3411
+ await SPAUtils.waitTillPageRedirect();
3412
+ return true;
3286
3413
  };
3287
- const getSignOutURL = async () => {
3288
- return await _authenticationClient.getSignOutURL();
3414
+ const enableRetrievingSignOutURLFromSession = (config2) => {
3415
+ if (config2.preventSignOutURLUpdate) {
3416
+ _getSignOutURLFromSessionStorage = true;
3417
+ }
3289
3418
  };
3290
- const requestCustomGrant = async (config2) => {
3291
- return await _authenticationHelper.requestCustomGrant(config2);
3419
+ const exchangeToken = async (config2) => {
3420
+ return await _authenticationHelper.exchangeToken(config2, enableRetrievingSignOutURLFromSession);
3292
3421
  };
3293
3422
  const refreshAccessToken = async () => {
3294
3423
  try {
3295
- return await _authenticationHelper.refreshAccessToken();
3424
+ return await _authenticationHelper.refreshAccessToken(enableRetrievingSignOutURLFromSession);
3296
3425
  } catch (error) {
3297
3426
  return Promise.reject(error);
3298
3427
  }
@@ -3300,295 +3429,122 @@ var WebWorkerCore = async (config, getAuthHelper) => {
3300
3429
  const revokeAccessToken = async () => {
3301
3430
  const timer = await _spaHelper.getRefreshTimeoutTimer();
3302
3431
  return _authenticationClient.revokeAccessToken().then(() => {
3432
+ _sessionManagementHelper.reset();
3303
3433
  _spaHelper.clearRefreshTokenTimeout(timer);
3304
3434
  return Promise.resolve(true);
3305
3435
  }).catch((error) => Promise.reject(error));
3306
3436
  };
3307
- const getBasicUserInfo = async () => {
3308
- return _authenticationHelper.getBasicUserInfo();
3437
+ const requestAccessToken = async (resolvedAuthorizationCode, resolvedSessionState, resolvedState, tokenRequestConfig) => {
3438
+ return await _authenticationHelper.requestAccessToken(
3439
+ resolvedAuthorizationCode,
3440
+ resolvedSessionState,
3441
+ checkSession,
3442
+ void 0,
3443
+ resolvedState,
3444
+ tokenRequestConfig
3445
+ );
3446
+ };
3447
+ const constructSilentSignInUrl = async (additionalParams = {}) => {
3448
+ const config2 = await _dataLayer.getConfigData();
3449
+ const urlString = await _authenticationClient.getSignInUrl({
3450
+ prompt: "none",
3451
+ state: SILENT_SIGN_IN_STATE,
3452
+ ...additionalParams
3453
+ });
3454
+ const urlObject = new URL(urlString);
3455
+ urlObject.searchParams.set("response_mode", "query");
3456
+ const url = urlObject.toString();
3457
+ if (config2.storage === "browserMemory" /* BrowserMemory */ && config2.enablePKCE) {
3458
+ const state = urlObject.searchParams.get(import_javascript6.OIDCRequestConstants.Params.STATE);
3459
+ SPAUtils.setPKCE(
3460
+ (0, import_javascript6.extractPkceStorageKeyFromState)(state ?? ""),
3461
+ await _authenticationClient.getPKCECode(state ?? "")
3462
+ );
3463
+ }
3464
+ return url;
3465
+ };
3466
+ const trySignInSilently = async (additionalParams, tokenRequestConfig) => {
3467
+ return await _authenticationHelper.trySignInSilently(
3468
+ constructSilentSignInUrl,
3469
+ requestAccessToken,
3470
+ _sessionManagementHelper,
3471
+ additionalParams,
3472
+ tokenRequestConfig
3473
+ );
3309
3474
  };
3310
- const getDecodedIDToken = async () => {
3311
- return _authenticationHelper.getDecodedIDToken();
3475
+ const getUser = async () => {
3476
+ return _authenticationHelper.getUser();
3312
3477
  };
3313
- const getCryptoHelper = async () => {
3314
- return _authenticationHelper.getCryptoHelper();
3478
+ const getDecodedIdToken = async () => {
3479
+ return _authenticationHelper.getDecodedIdToken();
3315
3480
  };
3316
- const getDecodedIDPIDToken = async () => {
3317
- return _authenticationHelper.getDecodedIDPIDToken();
3481
+ const getCrypto = async () => {
3482
+ return _authenticationHelper.getCrypto();
3318
3483
  };
3319
- const getIDToken = async () => {
3320
- return _authenticationHelper.getIDToken();
3484
+ const getIdToken = async () => {
3485
+ return _authenticationHelper.getIdToken();
3321
3486
  };
3322
- const getOIDCServiceEndpoints = async () => {
3323
- return _authenticationHelper.getOIDCServiceEndpoints();
3487
+ const getOpenIDProviderEndpoints = async () => {
3488
+ return _authenticationHelper.getOpenIDProviderEndpoints();
3324
3489
  };
3325
- const getAccessToken = () => {
3490
+ const getAccessToken = async () => {
3326
3491
  return _authenticationHelper.getAccessToken();
3327
3492
  };
3328
- const isAuthenticated = () => {
3329
- return _authenticationHelper.isAuthenticated();
3493
+ const getStorageManager = async () => {
3494
+ return _authenticationHelper.getStorageManager();
3330
3495
  };
3331
- const setSessionState = async (sessionState) => {
3332
- await _dataLayer.setSessionDataParameter(
3333
- import_javascript6.OIDCRequestConstants.Params.SESSION_STATE,
3334
- sessionState
3335
- );
3336
- return;
3496
+ const getConfigData = async () => {
3497
+ return await _dataLayer.getConfigData();
3337
3498
  };
3338
- const updateConfig = async (config2) => {
3339
- await _authenticationClient.updateConfig(config2);
3340
- return;
3499
+ const isSignedIn = async () => {
3500
+ return _authenticationHelper.isSignedIn();
3341
3501
  };
3342
- const getConfigData = async () => {
3343
- return _dataLayer.getConfigData();
3502
+ const isSessionActive = async () => {
3503
+ return await _dataLayer.getSessionStatus() === "true";
3504
+ };
3505
+ const reInitialize = async (newConfig) => {
3506
+ const existingConfig = await _dataLayer.getConfigData();
3507
+ const isCheckSessionIframeDifferent = !(existingConfig && existingConfig.endpoints && existingConfig.endpoints.checkSessionIframe && newConfig && newConfig.endpoints && newConfig.endpoints.checkSessionIframe && existingConfig.endpoints.checkSessionIframe === newConfig.endpoints.checkSessionIframe);
3508
+ const config2 = { ...existingConfig, ...newConfig };
3509
+ await _authenticationClient.reInitialize(config2);
3510
+ if (config2.enableOIDCSessionManagement && isCheckSessionIframeDifferent) {
3511
+ _sessionManagementHelper.reset();
3512
+ checkSession();
3513
+ }
3344
3514
  };
3345
3515
  return {
3346
3516
  disableHttpHandler,
3347
3517
  enableHttpHandler,
3348
3518
  getAccessToken,
3349
- getAuthorizationURL,
3350
- getBasicUserInfo,
3519
+ getUser,
3351
3520
  getConfigData,
3352
- getCryptoHelper,
3353
- getDecodedIDPIDToken,
3354
- getDecodedIDToken,
3355
- getIDToken,
3356
- getOIDCServiceEndpoints,
3357
- getSignOutURL,
3521
+ getCrypto,
3522
+ getStorageManager,
3523
+ getDecodedIdToken,
3524
+ getHttpClient,
3525
+ getIdToken,
3526
+ getOpenIDProviderEndpoints,
3358
3527
  httpRequest,
3359
3528
  httpRequestAll,
3360
- isAuthenticated,
3529
+ isSignedIn,
3530
+ isSessionActive,
3361
3531
  refreshAccessToken,
3362
- requestAccessToken,
3363
- requestCustomGrant,
3532
+ exchangeToken,
3364
3533
  revokeAccessToken,
3534
+ setHttpRequestErrorCallback,
3365
3535
  setHttpRequestFinishCallback,
3366
3536
  setHttpRequestStartCallback,
3367
3537
  setHttpRequestSuccessCallback,
3368
- setSessionState,
3538
+ signIn,
3369
3539
  signOut,
3370
- startAutoRefreshToken,
3371
- updateConfig
3540
+ trySignInSilently,
3541
+ reInitialize
3372
3542
  };
3373
3543
  };
3374
3544
 
3375
- // src/__legacy__/worker/worker-receiver.ts
3376
- var workerReceiver = (getAuthHelper) => {
3377
- const ctx = self;
3378
- let webWorker;
3379
- ctx.onmessage = async ({ data, ports }) => {
3380
- const port = ports[0];
3381
- if (data.type !== INIT && !webWorker) {
3382
- port.postMessage(
3383
- MessageUtils.generateFailureMessage(
3384
- new import_javascript7.AsgardeoAuthException(
3385
- "SPA-CLIENT_WORKER-ONMSG-NF01",
3386
- "The web worker has not been initialized yet.",
3387
- "The initialize method needs to be called before the specified operation can be carried out."
3388
- )
3389
- )
3390
- );
3391
- return;
3392
- }
3393
- switch (data.type) {
3394
- case INIT:
3395
- try {
3396
- const config = { ...data.data };
3397
- webWorker = await WebWorkerCore(config, getAuthHelper);
3398
- webWorker.setHttpRequestFinishCallback(onRequestFinishCallback);
3399
- webWorker.setHttpRequestStartCallback(onRequestStartCallback);
3400
- webWorker.setHttpRequestSuccessCallback(onRequestSuccessCallback);
3401
- port.postMessage(MessageUtils.generateSuccessMessage());
3402
- } catch (error) {
3403
- port.postMessage(MessageUtils.generateFailureMessage(error));
3404
- }
3405
- break;
3406
- case GET_AUTH_URL:
3407
- webWorker.getAuthorizationURL(data?.data).then((response) => {
3408
- port.postMessage(MessageUtils.generateSuccessMessage(response));
3409
- }).catch((error) => {
3410
- port.postMessage(MessageUtils.generateFailureMessage(error));
3411
- });
3412
- break;
3413
- case REQUEST_ACCESS_TOKEN:
3414
- webWorker.requestAccessToken(data?.data?.code, data?.data?.sessionState, data?.data?.pkce, data?.data?.state).then((response) => {
3415
- port.postMessage(MessageUtils.generateSuccessMessage(response));
3416
- }).catch((error) => {
3417
- port.postMessage(MessageUtils.generateFailureMessage(error));
3418
- });
3419
- break;
3420
- case HTTP_REQUEST: {
3421
- const request = data.data;
3422
- const requestData = request?.data;
3423
- if (data.data?.data?.formData === true) {
3424
- const formData = new FormData();
3425
- for (const key in requestData) {
3426
- if (key === "formData") {
3427
- continue;
3428
- }
3429
- formData.append(key, requestData[key]);
3430
- }
3431
- request.data = formData;
3432
- }
3433
- webWorker.httpRequest(request).then((response) => {
3434
- port.postMessage(MessageUtils.generateSuccessMessage(response));
3435
- }).catch((error) => {
3436
- port.postMessage(MessageUtils.generateFailureMessage(error));
3437
- });
3438
- break;
3439
- }
3440
- case HTTP_REQUEST_ALL:
3441
- webWorker.httpRequestAll(data.data).then((response) => {
3442
- port.postMessage(MessageUtils.generateSuccessMessage(response));
3443
- }).catch((error) => {
3444
- port.postMessage(MessageUtils.generateFailureMessage(error));
3445
- });
3446
- break;
3447
- case SIGN_OUT:
3448
- try {
3449
- port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.signOut()));
3450
- } catch (error) {
3451
- port.postMessage(MessageUtils.generateFailureMessage(error));
3452
- }
3453
- break;
3454
- case REQUEST_CUSTOM_GRANT:
3455
- webWorker.requestCustomGrant(data.data).then((response) => {
3456
- port.postMessage(MessageUtils.generateSuccessMessage(response));
3457
- }).catch((error) => {
3458
- port.postMessage(MessageUtils.generateFailureMessage(error));
3459
- });
3460
- break;
3461
- case REVOKE_ACCESS_TOKEN:
3462
- webWorker.revokeAccessToken().then((response) => {
3463
- port.postMessage(MessageUtils.generateSuccessMessage(response));
3464
- }).catch((error) => {
3465
- port.postMessage(MessageUtils.generateFailureMessage(error));
3466
- });
3467
- break;
3468
- case GET_OIDC_SERVICE_ENDPOINTS:
3469
- try {
3470
- port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getOIDCServiceEndpoints()));
3471
- } catch (error) {
3472
- port.postMessage(MessageUtils.generateFailureMessage(error));
3473
- }
3474
- break;
3475
- case GET_BASIC_USER_INFO:
3476
- try {
3477
- port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getBasicUserInfo()));
3478
- } catch (error) {
3479
- port.postMessage(MessageUtils.generateFailureMessage(error));
3480
- }
3481
- break;
3482
- case GET_DECODED_ID_TOKEN:
3483
- try {
3484
- port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getDecodedIDToken()));
3485
- } catch (error) {
3486
- port.postMessage(MessageUtils.generateFailureMessage(error));
3487
- }
3488
- break;
3489
- case GET_CRYPTO_HELPER:
3490
- try {
3491
- port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getCryptoHelper()));
3492
- } catch (error) {
3493
- port.postMessage(MessageUtils.generateFailureMessage(error));
3494
- }
3495
- break;
3496
- case GET_ID_TOKEN:
3497
- try {
3498
- port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getIDToken()));
3499
- } catch (error) {
3500
- port.postMessage(MessageUtils.generateFailureMessage(error));
3501
- }
3502
- break;
3503
- case ENABLE_HTTP_HANDLER:
3504
- webWorker.enableHttpHandler();
3505
- port.postMessage(MessageUtils.generateSuccessMessage());
3506
- break;
3507
- case DISABLE_HTTP_HANDLER:
3508
- webWorker.disableHttpHandler();
3509
- port.postMessage(MessageUtils.generateSuccessMessage());
3510
- break;
3511
- case IS_AUTHENTICATED:
3512
- try {
3513
- port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.isAuthenticated()));
3514
- } catch (error) {
3515
- port.postMessage(MessageUtils.generateFailureMessage(error));
3516
- }
3517
- break;
3518
- case GET_SIGN_OUT_URL:
3519
- try {
3520
- port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getSignOutURL()));
3521
- } catch (error) {
3522
- port.postMessage(MessageUtils.generateFailureMessage(error));
3523
- }
3524
- break;
3525
- case REFRESH_ACCESS_TOKEN:
3526
- try {
3527
- port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.refreshAccessToken()));
3528
- } catch (error) {
3529
- port.postMessage(MessageUtils.generateFailureMessage(error));
3530
- }
3531
- break;
3532
- case START_AUTO_REFRESH_TOKEN:
3533
- try {
3534
- port.postMessage(MessageUtils.generateSuccessMessage(webWorker.startAutoRefreshToken()));
3535
- } catch (error) {
3536
- port.postMessage(MessageUtils.generateFailureMessage(error));
3537
- }
3538
- break;
3539
- case SET_SESSION_STATE:
3540
- try {
3541
- port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.setSessionState(data?.data)));
3542
- } catch (error) {
3543
- port.postMessage(MessageUtils.generateFailureMessage(error));
3544
- }
3545
- break;
3546
- case UPDATE_CONFIG:
3547
- try {
3548
- port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.updateConfig(data?.data)));
3549
- } catch (error) {
3550
- port.postMessage(MessageUtils.generateFailureMessage(error));
3551
- }
3552
- break;
3553
- case GET_CONFIG_DATA:
3554
- try {
3555
- port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getConfigData()));
3556
- } catch (error) {
3557
- port.postMessage(MessageUtils.generateFailureMessage(error));
3558
- }
3559
- break;
3560
- default:
3561
- port?.postMessage(
3562
- MessageUtils.generateFailureMessage(
3563
- new import_javascript7.AsgardeoAuthException(
3564
- "SPA-CLIENT_WORKER-ONMSG-IV02",
3565
- "The message type is invalid.",
3566
- `The message type provided, ${data.type}, is invalid.`
3567
- )
3568
- )
3569
- );
3570
- }
3571
- };
3572
- const onRequestStartCallback = () => {
3573
- ctx.postMessage({ type: REQUEST_START });
3574
- };
3575
- const onRequestSuccessCallback = (response) => {
3576
- ctx.postMessage({ data: JSON.stringify(response ?? ""), type: REQUEST_SUCCESS });
3577
- };
3578
- const onRequestFinishCallback = () => {
3579
- ctx.postMessage({ type: REQUEST_FINISH });
3580
- };
3581
- };
3582
-
3583
- // src/worker.ts
3584
- workerReceiver((authClient, spaHelper) => {
3585
- return new AuthenticationHelper(authClient, spaHelper);
3586
- });
3587
- var worker_default = {};
3588
-
3589
- // src/__legacy__/clients/main-thread-client.ts
3590
- var import_javascript8 = require("@asgardeo/javascript");
3591
- var initiateStore = (store) => {
3545
+ // src/__legacy__/clients/web-worker-client.ts
3546
+ var import_javascript7 = require("@asgardeo/javascript");
3547
+ var initiateStore2 = (store) => {
3592
3548
  switch (store) {
3593
3549
  case "localStorage" /* LocalStorage */:
3594
3550
  return new LocalStore();
@@ -3600,140 +3556,322 @@ var initiateStore = (store) => {
3600
3556
  return new SessionStore();
3601
3557
  }
3602
3558
  };
3603
- var MainThreadClient = async (instanceID, config, getAuthHelper) => {
3604
- const _store = initiateStore(config.storage);
3559
+ var WebWorkerClient = async (instanceID, config, webWorker, getAuthHelper) => {
3560
+ let httpClientHandlers;
3561
+ const _requestTimeout = config?.requestTimeout ?? 6e4;
3562
+ let _isHttpHandlerEnabled = true;
3563
+ let _getSignOutURLFromSessionStorage = false;
3564
+ const _store = initiateStore2(config.storage);
3605
3565
  const _cryptoUtils = new SPACryptoUtils();
3606
- const _authenticationClient = new import_javascript8.AsgardeoAuthClient();
3566
+ const _authenticationClient = new import_javascript7.AsgardeoAuthClient();
3607
3567
  await _authenticationClient.initialize(config, _store, _cryptoUtils, instanceID);
3608
3568
  const _spaHelper = new SPAHelper(_authenticationClient);
3609
- const _dataLayer = _authenticationClient.getDataLayer();
3610
3569
  const _sessionManagementHelper = await SessionManagementHelper(
3611
3570
  async () => {
3612
- return _authenticationClient.getSignOutURL();
3571
+ const message = {
3572
+ type: SIGN_OUT
3573
+ };
3574
+ try {
3575
+ const signOutURL = await communicate(message);
3576
+ return signOutURL;
3577
+ } catch {
3578
+ return SPAUtils.getSignOutUrl(config.clientId, instanceID);
3579
+ }
3613
3580
  },
3614
- config.storage ?? "sessionStorage" /* SessionStorage */,
3615
- (sessionState) => _dataLayer.setSessionDataParameter(
3616
- import_javascript8.OIDCRequestConstants.Params.SESSION_STATE,
3617
- sessionState ?? ""
3618
- )
3581
+ config.storage,
3582
+ (sessionState) => setSessionState(sessionState)
3619
3583
  );
3620
- const _authenticationHelper = getAuthHelper(_authenticationClient, _spaHelper);
3621
- let _getSignOutURLFromSessionStorage = false;
3622
- const _httpClient = HttpClient.getInstance();
3623
- let _isHttpHandlerEnabled = true;
3624
- let _httpErrorCallback;
3625
- let _httpFinishCallback;
3626
- const attachToken = async (request) => {
3627
- await _authenticationHelper.attachTokenToRequestConfig(request);
3628
- };
3629
- _httpClient?.init && await _httpClient.init(true, attachToken);
3630
- const setHttpRequestStartCallback = (callback) => {
3631
- _httpClient?.setHttpRequestStartCallback && _httpClient.setHttpRequestStartCallback(callback);
3584
+ const _authenticationHelper = getAuthHelper(
3585
+ _authenticationClient,
3586
+ _spaHelper
3587
+ );
3588
+ const worker = new webWorker();
3589
+ const communicate = (message) => {
3590
+ const channel = new MessageChannel();
3591
+ worker.postMessage(message, [channel.port2]);
3592
+ return new Promise((resolve, reject) => {
3593
+ const timer = setTimeout(() => {
3594
+ reject(
3595
+ new import_javascript7.AsgardeoAuthException(
3596
+ "SPA-WEB_WORKER_CLIENT-COM-TO01",
3597
+ "Operation timed out.",
3598
+ "No response was received from the web worker for " + _requestTimeout / 1e3 + " since dispatching the request"
3599
+ )
3600
+ );
3601
+ }, _requestTimeout);
3602
+ return channel.port1.onmessage = ({ data }) => {
3603
+ clearTimeout(timer);
3604
+ channel.port1.close();
3605
+ channel.port2.close();
3606
+ if (data?.success) {
3607
+ const responseData = data?.data ? JSON.parse(data?.data) : null;
3608
+ if (data?.blob) {
3609
+ responseData.data = data?.blob;
3610
+ }
3611
+ resolve(responseData);
3612
+ } else {
3613
+ reject(data.error ? JSON.parse(data.error) : null);
3614
+ }
3615
+ };
3616
+ });
3632
3617
  };
3633
- const setHttpRequestSuccessCallback = (callback) => {
3634
- _httpClient?.setHttpRequestSuccessCallback && _httpClient.setHttpRequestSuccessCallback(callback);
3618
+ const exchangeToken = (requestParams) => {
3619
+ const message = {
3620
+ data: requestParams,
3621
+ type: REQUEST_CUSTOM_GRANT
3622
+ };
3623
+ return communicate(message).then((response) => {
3624
+ if (requestParams.preventSignOutURLUpdate) {
3625
+ _getSignOutURLFromSessionStorage = true;
3626
+ }
3627
+ return Promise.resolve(response);
3628
+ }).catch((error) => {
3629
+ return Promise.reject(error);
3630
+ });
3635
3631
  };
3636
- const setHttpRequestFinishCallback = (callback) => {
3637
- _httpClient?.setHttpRequestFinishCallback && _httpClient.setHttpRequestFinishCallback(callback);
3632
+ const httpRequest = (config2) => {
3633
+ if (config2?.data && config2?.data instanceof FormData) {
3634
+ config2.data = { ...Object.fromEntries((config2?.data).entries()), formData: true };
3635
+ }
3636
+ const message = {
3637
+ data: config2,
3638
+ type: HTTP_REQUEST
3639
+ };
3640
+ return communicate(message).then((response) => {
3641
+ return Promise.resolve(response);
3642
+ }).catch(async (error) => {
3643
+ if (_isHttpHandlerEnabled) {
3644
+ if (typeof httpClientHandlers.requestErrorCallback === "function") {
3645
+ await httpClientHandlers.requestErrorCallback(error);
3646
+ }
3647
+ if (typeof httpClientHandlers.requestFinishCallback === "function") {
3648
+ httpClientHandlers.requestFinishCallback();
3649
+ }
3650
+ }
3651
+ return Promise.reject(error);
3652
+ });
3638
3653
  };
3639
- const setHttpRequestErrorCallback = (callback) => {
3640
- _httpErrorCallback = callback;
3654
+ const httpRequestAll = (configs) => {
3655
+ const message = {
3656
+ data: configs,
3657
+ type: HTTP_REQUEST_ALL
3658
+ };
3659
+ return communicate(message).then((response) => {
3660
+ return Promise.resolve(response);
3661
+ }).catch(async (error) => {
3662
+ if (_isHttpHandlerEnabled) {
3663
+ if (typeof httpClientHandlers.requestErrorCallback === "function") {
3664
+ await httpClientHandlers.requestErrorCallback(error);
3665
+ }
3666
+ if (typeof httpClientHandlers.requestFinishCallback === "function") {
3667
+ httpClientHandlers.requestFinishCallback();
3668
+ }
3669
+ }
3670
+ return Promise.reject(error);
3671
+ });
3641
3672
  };
3642
- const httpRequest = async (requestConfig) => {
3643
- return await _authenticationHelper.httpRequest(
3644
- _httpClient,
3645
- requestConfig,
3646
- _isHttpHandlerEnabled,
3647
- _httpErrorCallback,
3648
- _httpFinishCallback
3649
- );
3673
+ const enableHttpHandler = () => {
3674
+ const message = {
3675
+ type: ENABLE_HTTP_HANDLER
3676
+ };
3677
+ return communicate(message).then(() => {
3678
+ _isHttpHandlerEnabled = true;
3679
+ return Promise.resolve(true);
3680
+ }).catch((error) => {
3681
+ return Promise.reject(error);
3682
+ });
3650
3683
  };
3651
- const httpRequestAll = async (requestConfigs) => {
3652
- return await _authenticationHelper.httpRequestAll(
3653
- requestConfigs,
3654
- _httpClient,
3655
- _isHttpHandlerEnabled,
3656
- _httpErrorCallback,
3657
- _httpFinishCallback
3658
- );
3684
+ const disableHttpHandler = () => {
3685
+ const message = {
3686
+ type: DISABLE_HTTP_HANDLER
3687
+ };
3688
+ return communicate(message).then(() => {
3689
+ _isHttpHandlerEnabled = false;
3690
+ return Promise.resolve(true);
3691
+ }).catch((error) => {
3692
+ return Promise.reject(error);
3693
+ });
3659
3694
  };
3660
- const getHttpClient = () => {
3661
- return _httpClient;
3695
+ const initialize = () => {
3696
+ if (!httpClientHandlers) {
3697
+ httpClientHandlers = {
3698
+ requestErrorCallback: () => Promise.resolve(),
3699
+ requestFinishCallback: () => null,
3700
+ requestStartCallback: () => null,
3701
+ requestSuccessCallback: () => null
3702
+ };
3703
+ }
3704
+ worker.onmessage = ({ data }) => {
3705
+ switch (data.type) {
3706
+ case REQUEST_FINISH:
3707
+ httpClientHandlers?.requestFinishCallback && httpClientHandlers?.requestFinishCallback();
3708
+ break;
3709
+ case REQUEST_START:
3710
+ httpClientHandlers?.requestStartCallback && httpClientHandlers?.requestStartCallback();
3711
+ break;
3712
+ case REQUEST_SUCCESS:
3713
+ httpClientHandlers?.requestSuccessCallback && httpClientHandlers?.requestSuccessCallback(data.data ? JSON.parse(data.data) : null);
3714
+ break;
3715
+ }
3716
+ };
3717
+ const message = {
3718
+ data: config,
3719
+ type: INIT
3720
+ };
3721
+ return communicate(message).then(() => {
3722
+ return Promise.resolve(true);
3723
+ }).catch((error) => {
3724
+ return Promise.reject(error);
3725
+ });
3662
3726
  };
3663
- const enableHttpHandler = () => {
3664
- _authenticationHelper.enableHttpHandler(_httpClient);
3665
- _isHttpHandlerEnabled = true;
3666
- return true;
3727
+ const setSessionState = (sessionState) => {
3728
+ const message = {
3729
+ data: sessionState,
3730
+ type: SET_SESSION_STATE
3731
+ };
3732
+ return communicate(message);
3667
3733
  };
3668
- const disableHttpHandler = () => {
3669
- _authenticationHelper.disableHttpHandler(_httpClient);
3670
- _isHttpHandlerEnabled = false;
3671
- return true;
3734
+ const startAutoRefreshToken = () => {
3735
+ const message = {
3736
+ type: START_AUTO_REFRESH_TOKEN
3737
+ };
3738
+ return communicate(message);
3672
3739
  };
3673
3740
  const checkSession = async () => {
3674
- const oidcEndpoints = await _authenticationClient.getOIDCServiceEndpoints();
3675
- const config2 = await _dataLayer.getConfigData();
3741
+ const oidcEndpoints = await getOpenIDProviderEndpoints();
3742
+ const config2 = await getConfigData();
3676
3743
  _authenticationHelper.initializeSessionManger(
3677
3744
  config2,
3678
3745
  oidcEndpoints,
3679
- async () => (await _authenticationClient.getBasicUserInfo()).sessionState,
3680
- async (params) => _authenticationClient.getAuthorizationURL(params),
3746
+ async () => (await _authenticationClient.getUserSession()).sessionState,
3747
+ async (params) => (await getSignInUrl(params)).authorizationURL,
3681
3748
  _sessionManagementHelper
3682
3749
  );
3683
3750
  };
3751
+ const constructSilentSignInUrl = async (additionalParams = {}) => {
3752
+ const config2 = await getConfigData();
3753
+ const message = {
3754
+ data: {
3755
+ prompt: "none",
3756
+ state: SILENT_SIGN_IN_STATE,
3757
+ ...additionalParams
3758
+ },
3759
+ type: GET_AUTH_URL
3760
+ };
3761
+ const response = await communicate(
3762
+ message
3763
+ );
3764
+ const pkceKey = (0, import_javascript7.extractPkceStorageKeyFromState)(
3765
+ new URL(response.authorizationURL).searchParams.get(import_javascript7.OIDCRequestConstants.Params.STATE) ?? ""
3766
+ );
3767
+ response.pkce && config2.enablePKCE && SPAUtils.setPKCE(pkceKey, response.pkce);
3768
+ const urlString = response.authorizationURL;
3769
+ const urlObject = new URL(urlString);
3770
+ urlObject.searchParams.set("response_mode", "query");
3771
+ const url = urlObject.toString();
3772
+ return url;
3773
+ };
3774
+ const trySignInSilently = async (additionalParams, tokenRequestConfig) => {
3775
+ return await _authenticationHelper.trySignInSilently(
3776
+ constructSilentSignInUrl,
3777
+ requestAccessToken,
3778
+ _sessionManagementHelper,
3779
+ additionalParams,
3780
+ tokenRequestConfig
3781
+ );
3782
+ };
3783
+ const getSignInUrl = async (params) => {
3784
+ const config2 = await getConfigData();
3785
+ const message = {
3786
+ data: params,
3787
+ type: GET_AUTH_URL
3788
+ };
3789
+ return communicate(message).then(
3790
+ async (response) => {
3791
+ if (response.pkce && config2.enablePKCE) {
3792
+ const pkceKey = (0, import_javascript7.extractPkceStorageKeyFromState)(
3793
+ new URL(response.authorizationURL).searchParams.get(import_javascript7.OIDCRequestConstants.Params.STATE) ?? ""
3794
+ );
3795
+ SPAUtils.setPKCE(pkceKey, response.pkce);
3796
+ }
3797
+ return Promise.resolve(response);
3798
+ }
3799
+ );
3800
+ };
3801
+ const requestAccessToken = async (resolvedAuthorizationCode, resolvedSessionState, resolvedState, tokenRequestConfig) => {
3802
+ const config2 = await getConfigData();
3803
+ const pkceKey = (0, import_javascript7.extractPkceStorageKeyFromState)(resolvedState);
3804
+ const message = {
3805
+ data: {
3806
+ code: resolvedAuthorizationCode,
3807
+ pkce: config2.enablePKCE ? SPAUtils.getPKCE(pkceKey) : void 0,
3808
+ sessionState: resolvedSessionState,
3809
+ state: resolvedState,
3810
+ tokenRequestConfig
3811
+ },
3812
+ type: REQUEST_ACCESS_TOKEN
3813
+ };
3814
+ config2.enablePKCE && SPAUtils.removePKCE(pkceKey);
3815
+ return communicate(message).then((response) => {
3816
+ const message2 = {
3817
+ type: GET_SIGN_OUT_URL
3818
+ };
3819
+ return communicate(message2).then((url) => {
3820
+ SPAUtils.setSignOutURL(url, config2.clientId, instanceID);
3821
+ if (config2.enableOIDCSessionManagement) {
3822
+ checkSession();
3823
+ }
3824
+ startAutoRefreshToken();
3825
+ return Promise.resolve(response);
3826
+ }).catch((error) => {
3827
+ return Promise.reject(error);
3828
+ });
3829
+ }).catch((error) => {
3830
+ return Promise.reject(error);
3831
+ });
3832
+ };
3684
3833
  const shouldStopAuthn = async () => {
3685
3834
  return await _sessionManagementHelper.receivePromptNoneResponse(async (sessionState) => {
3686
- await _dataLayer.setSessionDataParameter(
3687
- import_javascript8.OIDCRequestConstants.Params.SESSION_STATE,
3688
- sessionState ?? ""
3689
- );
3690
- return;
3835
+ return setSessionState(sessionState);
3691
3836
  });
3692
3837
  };
3693
- const setSessionStatus = async (sessionStatus) => {
3694
- await _dataLayer.setSessionStatus(sessionStatus);
3838
+ const tryRetrievingUserInfo = async () => {
3839
+ if (await isSignedIn()) {
3840
+ await startAutoRefreshToken();
3841
+ if (config.enableOIDCSessionManagement) {
3842
+ checkSession();
3843
+ }
3844
+ return getUser();
3845
+ }
3846
+ return Promise.resolve(void 0);
3695
3847
  };
3696
- const signIn = async (signInConfig, authorizationCode, sessionState, state, tokenRequestConfig) => {
3697
- const basicUserInfo = await _authenticationHelper.handleSignIn(shouldStopAuthn, checkSession, void 0);
3848
+ const signIn = async (params, authorizationCode, sessionState, state, tokenRequestConfig) => {
3849
+ const basicUserInfo = await _authenticationHelper.handleSignIn(
3850
+ shouldStopAuthn,
3851
+ checkSession,
3852
+ tryRetrievingUserInfo
3853
+ );
3698
3854
  if (basicUserInfo) {
3699
3855
  return basicUserInfo;
3700
3856
  } else {
3701
3857
  let resolvedAuthorizationCode;
3702
3858
  let resolvedSessionState;
3703
3859
  let resolvedState;
3704
- let resolvedTokenRequestConfig = { params: {} };
3705
- if (config?.responseMode === import_javascript8.ResponseMode.FormPost && authorizationCode) {
3860
+ if (config?.responseMode === "form_post" && authorizationCode) {
3706
3861
  resolvedAuthorizationCode = authorizationCode;
3707
3862
  resolvedSessionState = sessionState ?? "";
3708
3863
  resolvedState = state ?? "";
3709
3864
  } else {
3710
- resolvedAuthorizationCode = new URL(window.location.href).searchParams.get(import_javascript8.OIDCRequestConstants.Params.AUTHORIZATION_CODE) ?? "";
3711
- resolvedSessionState = new URL(window.location.href).searchParams.get(import_javascript8.OIDCRequestConstants.Params.SESSION_STATE) ?? "";
3712
- resolvedState = new URL(window.location.href).searchParams.get(import_javascript8.OIDCRequestConstants.Params.STATE) ?? "";
3865
+ resolvedAuthorizationCode = new URL(window.location.href).searchParams.get(import_javascript7.OIDCRequestConstants.Params.AUTHORIZATION_CODE) ?? "";
3866
+ resolvedSessionState = new URL(window.location.href).searchParams.get(import_javascript7.OIDCRequestConstants.Params.SESSION_STATE) ?? "";
3867
+ resolvedState = new URL(window.location.href).searchParams.get(import_javascript7.OIDCRequestConstants.Params.STATE) ?? "";
3713
3868
  SPAUtils.removeAuthorizationCode();
3714
3869
  }
3715
3870
  if (resolvedAuthorizationCode && resolvedState) {
3716
- setSessionStatus("true");
3717
- const storedTokenRequestConfig = await _dataLayer.getTemporaryDataParameter(TOKEN_REQUEST_CONFIG_KEY);
3718
- if (storedTokenRequestConfig && typeof storedTokenRequestConfig === "string") {
3719
- resolvedTokenRequestConfig = JSON.parse(storedTokenRequestConfig);
3720
- }
3721
- return requestAccessToken(
3722
- resolvedAuthorizationCode,
3723
- resolvedSessionState,
3724
- resolvedState,
3725
- resolvedTokenRequestConfig
3726
- );
3871
+ return requestAccessToken(resolvedAuthorizationCode, resolvedSessionState, resolvedState, tokenRequestConfig);
3727
3872
  }
3728
- return _authenticationClient.getAuthorizationURL(signInConfig).then(async (url) => {
3729
- if (config.storage === "browserMemory" /* BrowserMemory */ && config.enablePKCE) {
3730
- const pkceKey = (0, import_javascript8.extractPkceStorageKeyFromState)(resolvedState);
3731
- SPAUtils.setPKCE(pkceKey, await _authenticationClient.getPKCECode(resolvedState));
3732
- }
3733
- if (tokenRequestConfig) {
3734
- _dataLayer.setTemporaryDataParameter(TOKEN_REQUEST_CONFIG_KEY, JSON.stringify(tokenRequestConfig));
3735
- }
3736
- location.href = url;
3873
+ return getSignInUrl(params).then(async (response) => {
3874
+ location.href = response.authorizationURL;
3737
3875
  await SPAUtils.waitTillPageRedirect();
3738
3876
  return Promise.resolve({
3739
3877
  allowedScopes: "",
@@ -3744,119 +3882,158 @@ var MainThreadClient = async (instanceID, config, getAuthHelper) => {
3744
3882
  tenantDomain: "",
3745
3883
  username: ""
3746
3884
  });
3885
+ }).catch((error) => {
3886
+ return Promise.reject(error);
3747
3887
  });
3748
3888
  }
3749
3889
  };
3750
- const signOut = async () => {
3751
- if (await _authenticationClient.isAuthenticated() && !_getSignOutURLFromSessionStorage) {
3752
- location.href = await _authenticationClient.getSignOutURL();
3753
- } else {
3754
- location.href = SPAUtils.getSignOutURL(config.clientID, instanceID);
3755
- }
3756
- _spaHelper.clearRefreshTokenTimeout();
3757
- await _dataLayer.removeOIDCProviderMetaData();
3758
- await _dataLayer.removeTemporaryData();
3759
- await _dataLayer.removeSessionData();
3760
- await _dataLayer.removeSessionStatus();
3761
- await SPAUtils.waitTillPageRedirect();
3762
- return true;
3763
- };
3764
- const enableRetrievingSignOutURLFromSession = (config2) => {
3765
- if (config2.preventSignOutURLUpdate) {
3766
- _getSignOutURLFromSessionStorage = true;
3767
- }
3768
- };
3769
- const requestCustomGrant = async (config2) => {
3770
- return await _authenticationHelper.requestCustomGrant(config2, enableRetrievingSignOutURLFromSession);
3771
- };
3772
- const refreshAccessToken = async () => {
3773
- try {
3774
- return await _authenticationHelper.refreshAccessToken(enableRetrievingSignOutURLFromSession);
3775
- } catch (error) {
3776
- return Promise.reject(error);
3777
- }
3890
+ const signOut = () => {
3891
+ return new Promise((resolve, reject) => {
3892
+ if (!_getSignOutURLFromSessionStorage) {
3893
+ const message = {
3894
+ type: SIGN_OUT
3895
+ };
3896
+ return communicate(message).then(async (response) => {
3897
+ window.location.href = response;
3898
+ await SPAUtils.waitTillPageRedirect();
3899
+ return resolve(true);
3900
+ }).catch((error) => {
3901
+ return reject(error);
3902
+ });
3903
+ } else {
3904
+ window.location.href = SPAUtils.getSignOutUrl(config.clientId, instanceID);
3905
+ return SPAUtils.waitTillPageRedirect().then(() => {
3906
+ return Promise.resolve(true);
3907
+ });
3908
+ }
3909
+ });
3778
3910
  };
3779
- const revokeAccessToken = async () => {
3780
- const timer = await _spaHelper.getRefreshTimeoutTimer();
3781
- return _authenticationClient.revokeAccessToken().then(() => {
3911
+ const revokeAccessToken = () => {
3912
+ const message = {
3913
+ type: REVOKE_ACCESS_TOKEN
3914
+ };
3915
+ return communicate(message).then((response) => {
3782
3916
  _sessionManagementHelper.reset();
3783
- _spaHelper.clearRefreshTokenTimeout(timer);
3784
- return Promise.resolve(true);
3785
- }).catch((error) => Promise.reject(error));
3917
+ return Promise.resolve(response);
3918
+ }).catch((error) => {
3919
+ return Promise.reject(error);
3920
+ });
3786
3921
  };
3787
- const requestAccessToken = async (resolvedAuthorizationCode, resolvedSessionState, resolvedState, tokenRequestConfig) => {
3788
- return await _authenticationHelper.requestAccessToken(
3789
- resolvedAuthorizationCode,
3790
- resolvedSessionState,
3791
- checkSession,
3792
- void 0,
3793
- resolvedState,
3794
- tokenRequestConfig
3795
- );
3922
+ const getOpenIDProviderEndpoints = () => {
3923
+ const message = {
3924
+ type: GET_OIDC_SERVICE_ENDPOINTS
3925
+ };
3926
+ return communicate(message).then((response) => {
3927
+ return Promise.resolve(response);
3928
+ }).catch((error) => {
3929
+ return Promise.reject(error);
3930
+ });
3796
3931
  };
3797
- const constructSilentSignInUrl = async (additionalParams = {}) => {
3798
- const config2 = await _dataLayer.getConfigData();
3799
- const urlString = await _authenticationClient.getAuthorizationURL({
3800
- prompt: "none",
3801
- state: SILENT_SIGN_IN_STATE,
3802
- ...additionalParams
3932
+ const getConfigData = () => {
3933
+ const message = {
3934
+ type: GET_CONFIG_DATA
3935
+ };
3936
+ return communicate(message).then((response) => {
3937
+ return Promise.resolve(response);
3938
+ }).catch((error) => {
3939
+ return Promise.reject(error);
3803
3940
  });
3804
- const urlObject = new URL(urlString);
3805
- urlObject.searchParams.set("response_mode", "query");
3806
- const url = urlObject.toString();
3807
- if (config2.storage === "browserMemory" /* BrowserMemory */ && config2.enablePKCE) {
3808
- const state = urlObject.searchParams.get(import_javascript8.OIDCRequestConstants.Params.STATE);
3809
- SPAUtils.setPKCE(
3810
- (0, import_javascript8.extractPkceStorageKeyFromState)(state ?? ""),
3811
- await _authenticationClient.getPKCECode(state ?? "")
3812
- );
3813
- }
3814
- return url;
3815
3941
  };
3816
- const trySignInSilently = async (additionalParams, tokenRequestConfig) => {
3817
- return await _authenticationHelper.trySignInSilently(
3818
- constructSilentSignInUrl,
3819
- requestAccessToken,
3820
- _sessionManagementHelper,
3821
- additionalParams,
3822
- tokenRequestConfig
3823
- );
3942
+ const getUser = () => {
3943
+ const message = {
3944
+ type: GET_BASIC_USER_INFO
3945
+ };
3946
+ return communicate(message).then((response) => {
3947
+ return Promise.resolve(response);
3948
+ }).catch((error) => {
3949
+ return Promise.reject(error);
3950
+ });
3824
3951
  };
3825
- const getBasicUserInfo = async () => {
3826
- return _authenticationHelper.getBasicUserInfo();
3952
+ const getDecodedIdToken = () => {
3953
+ const message = {
3954
+ type: GET_DECODED_ID_TOKEN
3955
+ };
3956
+ return communicate(message).then((response) => {
3957
+ return Promise.resolve(response);
3958
+ }).catch((error) => {
3959
+ return Promise.reject(error);
3960
+ });
3827
3961
  };
3828
- const getDecodedIDToken = async () => {
3829
- return _authenticationHelper.getDecodedIDToken();
3962
+ const getDecodedIDPIDToken = () => {
3963
+ const message = {
3964
+ type: GET_DECODED_IDP_ID_TOKEN
3965
+ };
3966
+ return communicate(message).then((response) => {
3967
+ return Promise.resolve(response);
3968
+ }).catch((error) => {
3969
+ return Promise.reject(error);
3970
+ });
3830
3971
  };
3831
- const getCryptoHelper = async () => {
3832
- return _authenticationHelper.getCryptoHelper();
3972
+ const getCrypto = () => {
3973
+ const message = {
3974
+ type: GET_CRYPTO_HELPER
3975
+ };
3976
+ return communicate(message).then((response) => {
3977
+ return Promise.resolve(response);
3978
+ }).catch((error) => {
3979
+ return Promise.reject(error);
3980
+ });
3833
3981
  };
3834
- const getIDToken = async () => {
3835
- return _authenticationHelper.getIDToken();
3982
+ const getIdToken = () => {
3983
+ const message = {
3984
+ type: GET_ID_TOKEN
3985
+ };
3986
+ return communicate(message).then((response) => {
3987
+ return Promise.resolve(response);
3988
+ }).catch((error) => {
3989
+ return Promise.reject(error);
3990
+ });
3836
3991
  };
3837
- const getOIDCServiceEndpoints = async () => {
3838
- return _authenticationHelper.getOIDCServiceEndpoints();
3992
+ const isSignedIn = () => {
3993
+ const message = {
3994
+ type: IS_AUTHENTICATED
3995
+ };
3996
+ return communicate(message).then((response) => {
3997
+ return Promise.resolve(response);
3998
+ }).catch((error) => {
3999
+ return Promise.reject(error);
4000
+ });
3839
4001
  };
3840
- const getAccessToken = async () => {
3841
- return _authenticationHelper.getAccessToken();
4002
+ const refreshAccessToken = () => {
4003
+ const message = {
4004
+ type: REFRESH_ACCESS_TOKEN
4005
+ };
4006
+ return communicate(message);
3842
4007
  };
3843
- const getDataLayer = async () => {
3844
- return _authenticationHelper.getDataLayer();
4008
+ const setHttpRequestSuccessCallback = (callback) => {
4009
+ if (callback && typeof callback === "function") {
4010
+ httpClientHandlers.requestSuccessCallback = callback;
4011
+ }
3845
4012
  };
3846
- const getConfigData = async () => {
3847
- return await _dataLayer.getConfigData();
4013
+ const setHttpRequestErrorCallback = (callback) => {
4014
+ if (callback && typeof callback === "function") {
4015
+ httpClientHandlers.requestErrorCallback = callback;
4016
+ }
3848
4017
  };
3849
- const isAuthenticated = async () => {
3850
- return _authenticationHelper.isAuthenticated();
4018
+ const setHttpRequestStartCallback = (callback) => {
4019
+ if (callback && typeof callback === "function") {
4020
+ httpClientHandlers.requestStartCallback = callback;
4021
+ }
3851
4022
  };
3852
- const isSessionActive = async () => {
3853
- return await _dataLayer.getSessionStatus() === "true";
4023
+ const setHttpRequestFinishCallback = (callback) => {
4024
+ if (callback && typeof callback === "function") {
4025
+ httpClientHandlers.requestFinishCallback = callback;
4026
+ }
3854
4027
  };
3855
- const updateConfig = async (newConfig) => {
3856
- const existingConfig = await _dataLayer.getConfigData();
4028
+ const reInitialize = async (newConfig) => {
4029
+ const existingConfig = await getConfigData();
3857
4030
  const isCheckSessionIframeDifferent = !(existingConfig && existingConfig.endpoints && existingConfig.endpoints.checkSessionIframe && newConfig && newConfig.endpoints && newConfig.endpoints.checkSessionIframe && existingConfig.endpoints.checkSessionIframe === newConfig.endpoints.checkSessionIframe);
3858
4031
  const config2 = { ...existingConfig, ...newConfig };
3859
- await _authenticationClient.updateConfig(config2);
4032
+ const message = {
4033
+ data: config2,
4034
+ type: UPDATE_CONFIG
4035
+ };
4036
+ await communicate(message);
3860
4037
  if (config2.enableOIDCSessionManagement && isCheckSessionIframeDifferent) {
3861
4038
  _sessionManagementHelper.reset();
3862
4039
  checkSession();
@@ -3865,21 +4042,19 @@ var MainThreadClient = async (instanceID, config, getAuthHelper) => {
3865
4042
  return {
3866
4043
  disableHttpHandler,
3867
4044
  enableHttpHandler,
3868
- getAccessToken,
3869
- getBasicUserInfo,
4045
+ getUser,
3870
4046
  getConfigData,
3871
- getCryptoHelper,
3872
- getDataLayer,
3873
- getDecodedIDToken,
3874
- getHttpClient,
3875
- getIDToken,
3876
- getOIDCServiceEndpoints,
4047
+ getCrypto,
4048
+ getDecodedIDPIDToken,
4049
+ getDecodedIdToken,
4050
+ getIdToken,
4051
+ getOpenIDProviderEndpoints,
3877
4052
  httpRequest,
3878
4053
  httpRequestAll,
3879
- isAuthenticated,
3880
- isSessionActive,
4054
+ initialize,
4055
+ isSignedIn,
3881
4056
  refreshAccessToken,
3882
- requestCustomGrant,
4057
+ exchangeToken,
3883
4058
  revokeAccessToken,
3884
4059
  setHttpRequestErrorCallback,
3885
4060
  setHttpRequestFinishCallback,
@@ -3888,1072 +4063,543 @@ var MainThreadClient = async (instanceID, config, getAuthHelper) => {
3888
4063
  signIn,
3889
4064
  signOut,
3890
4065
  trySignInSilently,
3891
- updateConfig
4066
+ reInitialize
3892
4067
  };
3893
4068
  };
3894
4069
 
3895
- // src/__legacy__/clients/web-worker-client.ts
3896
- var import_javascript9 = require("@asgardeo/javascript");
3897
- var initiateStore2 = (store) => {
3898
- switch (store) {
3899
- case "localStorage" /* LocalStorage */:
3900
- return new LocalStore();
3901
- case "sessionStorage" /* SessionStorage */:
3902
- return new SessionStore();
3903
- case "browserMemory" /* BrowserMemory */:
3904
- return new MemoryStore();
3905
- default:
3906
- return new SessionStore();
3907
- }
4070
+ // src/__legacy__/client.ts
4071
+ var DefaultConfig = {
4072
+ autoLogoutOnTokenRefreshError: true,
4073
+ checkSessionInterval: 3,
4074
+ enableOIDCSessionManagement: false,
4075
+ periodicTokenRefresh: false,
4076
+ sessionRefreshInterval: 300,
4077
+ storage: "sessionStorage" /* SessionStorage */
3908
4078
  };
3909
- var WebWorkerClient = async (instanceID, config, webWorker, getAuthHelper) => {
3910
- let httpClientHandlers;
3911
- const _requestTimeout = config?.requestTimeout ?? 6e4;
3912
- let _isHttpHandlerEnabled = true;
3913
- let _getSignOutURLFromSessionStorage = false;
3914
- const _store = initiateStore2(config.storage);
3915
- const _cryptoUtils = new SPACryptoUtils();
3916
- const _authenticationClient = new import_javascript9.AsgardeoAuthClient();
3917
- await _authenticationClient.initialize(config, _store, _cryptoUtils, instanceID);
3918
- const _spaHelper = new SPAHelper(_authenticationClient);
3919
- const _sessionManagementHelper = await SessionManagementHelper(
3920
- async () => {
3921
- const message = {
3922
- type: SIGN_OUT
3923
- };
3924
- try {
3925
- const signOutURL = await communicate(message);
3926
- return signOutURL;
3927
- } catch {
3928
- return SPAUtils.getSignOutURL(config.clientID, instanceID);
3929
- }
3930
- },
3931
- config.storage,
3932
- (sessionState) => setSessionState(sessionState)
3933
- );
3934
- const _authenticationHelper = getAuthHelper(
3935
- _authenticationClient,
3936
- _spaHelper
3937
- );
3938
- const worker = new webWorker();
3939
- const communicate = (message) => {
3940
- const channel = new MessageChannel();
3941
- worker.postMessage(message, [channel.port2]);
3942
- return new Promise((resolve, reject) => {
3943
- const timer = setTimeout(() => {
3944
- reject(
3945
- new import_javascript9.AsgardeoAuthException(
3946
- "SPA-WEB_WORKER_CLIENT-COM-TO01",
3947
- "Operation timed out.",
3948
- "No response was received from the web worker for " + _requestTimeout / 1e3 + " since dispatching the request"
3949
- )
3950
- );
3951
- }, _requestTimeout);
3952
- return channel.port1.onmessage = ({ data }) => {
3953
- clearTimeout(timer);
3954
- channel.port1.close();
3955
- channel.port2.close();
3956
- if (data?.success) {
3957
- const responseData = data?.data ? JSON.parse(data?.data) : null;
3958
- if (data?.blob) {
3959
- responseData.data = data?.blob;
3960
- }
3961
- resolve(responseData);
3962
- } else {
3963
- reject(data.error ? JSON.parse(data.error) : null);
3964
- }
3965
- };
3966
- });
3967
- };
3968
- const requestCustomGrant = (requestParams) => {
3969
- const message = {
3970
- data: requestParams,
3971
- type: REQUEST_CUSTOM_GRANT
4079
+ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
4080
+ constructor(id) {
4081
+ __publicField(this, "_client");
4082
+ __publicField(this, "_storage");
4083
+ __publicField(this, "_authHelper", AuthenticationHelper);
4084
+ // protected _worker: new () => Worker = WorkerFile;
4085
+ __publicField(this, "_worker", null);
4086
+ __publicField(this, "_initialized", false);
4087
+ __publicField(this, "_startedInitialize", false);
4088
+ __publicField(this, "_onSignInCallback", () => null);
4089
+ __publicField(this, "_onSignOutCallback", () => null);
4090
+ __publicField(this, "_onSignOutFailedCallback", () => null);
4091
+ __publicField(this, "_onEndUserSession", () => null);
4092
+ __publicField(this, "_onInitialize", () => null);
4093
+ __publicField(this, "_onCustomGrant", /* @__PURE__ */ new Map());
4094
+ __publicField(this, "_instanceID");
4095
+ this._instanceID = id;
4096
+ }
4097
+ instantiateAuthHelper(authHelper) {
4098
+ if (authHelper) {
4099
+ this._authHelper = authHelper;
4100
+ } else {
4101
+ this._authHelper = AuthenticationHelper;
4102
+ }
4103
+ }
4104
+ // public instantiateWorker(worker: new () => Worker) {
4105
+ // if (worker) {
4106
+ // this._worker = worker;
4107
+ // } else {
4108
+ // this._worker = WorkerFile;
4109
+ // }
4110
+ // }
4111
+ /**
4112
+ * This method specifies if the `AsgardeoSPAClient` has been initialized or not.
4113
+ *
4114
+ * @return {Promise<boolean>} - Resolves to `true` if the client has been initialized.
4115
+ *
4116
+ * @memberof AsgardeoSPAClient
4117
+ *
4118
+ * @private
4119
+ */
4120
+ async isInitialized() {
4121
+ if (!this._startedInitialize) {
4122
+ return false;
4123
+ }
4124
+ let iterationToWait = 0;
4125
+ const sleep = () => {
4126
+ return new Promise((resolve) => setTimeout(resolve, 1));
3972
4127
  };
3973
- return communicate(message).then((response) => {
3974
- if (requestParams.preventSignOutURLUpdate) {
3975
- _getSignOutURLFromSessionStorage = true;
4128
+ while (!this._initialized) {
4129
+ if (iterationToWait === 1e4) {
4130
+ console.warn("It is taking longer than usual for the object to be initialized");
3976
4131
  }
3977
- return Promise.resolve(response);
3978
- }).catch((error) => {
3979
- return Promise.reject(error);
3980
- });
3981
- };
3982
- const httpRequest = (config2) => {
3983
- if (config2?.data && config2?.data instanceof FormData) {
3984
- config2.data = { ...Object.fromEntries((config2?.data).entries()), formData: true };
4132
+ await sleep();
4133
+ iterationToWait++;
3985
4134
  }
3986
- const message = {
3987
- data: config2,
3988
- type: HTTP_REQUEST
3989
- };
3990
- return communicate(message).then((response) => {
3991
- return Promise.resolve(response);
3992
- }).catch(async (error) => {
3993
- if (_isHttpHandlerEnabled) {
3994
- if (typeof httpClientHandlers.requestErrorCallback === "function") {
3995
- await httpClientHandlers.requestErrorCallback(error);
3996
- }
3997
- if (typeof httpClientHandlers.requestFinishCallback === "function") {
3998
- httpClientHandlers.requestFinishCallback();
3999
- }
4135
+ return true;
4136
+ }
4137
+ /**
4138
+ * This method checks if the SDK is initialized and the user is authenticated.
4139
+ *
4140
+ * @param validateAuthentication - should user's authenticated status be checked as part of validation
4141
+ *
4142
+ * @return {Promise<boolean>} - A Promise that resolves with `true` if the SDK is initialized and the
4143
+ * user is authenticated.
4144
+ *
4145
+ * @memberof AsgardeoSPAClient
4146
+ *
4147
+ * @private
4148
+ */
4149
+ async _validateMethod(validateAuthentication = true) {
4150
+ if (!await this.isInitialized()) {
4151
+ return Promise.reject(
4152
+ new import_javascript8.AsgardeoAuthException(
4153
+ "SPA-AUTH_CLIENT-VM-NF01",
4154
+ "The SDK is not initialized.",
4155
+ "The SDK must be initialized first."
4156
+ )
4157
+ );
4158
+ }
4159
+ if (validateAuthentication && !await this.isSignedIn()) {
4160
+ return Promise.reject(
4161
+ new import_javascript8.AsgardeoAuthException(
4162
+ "SPA-AUTH_CLIENT-VM-IV02",
4163
+ "The user is not authenticated.",
4164
+ "The user must be authenticated first."
4165
+ )
4166
+ );
4167
+ }
4168
+ return true;
4169
+ }
4170
+ /**
4171
+ * This method returns the instance of the singleton class.
4172
+ * If an ID is provided, it will return the instance with the given ID.
4173
+ * If no ID is provided, it will return the default instance value 0.
4174
+ *
4175
+ * @return {AsgardeoSPAClient} - Returns the instance of the singleton class.
4176
+ *
4177
+ * @example
4178
+ * ```
4179
+ * const auth = AsgardeoSPAClient.getInstance();
4180
+ * ```
4181
+ *
4182
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#getinstance
4183
+ *
4184
+ * @memberof AsgardeoSPAClient
4185
+ *
4186
+ * @preserve
4187
+ */
4188
+ static getInstance(id) {
4189
+ if (id && this._instances?.get(id)) {
4190
+ return this._instances.get(id);
4191
+ } else if (!id && this._instances?.get(0)) {
4192
+ return this._instances.get(0);
4193
+ }
4194
+ if (id) {
4195
+ this._instances.set(id, new _AsgardeoSPAClient(id));
4196
+ return this._instances.get(id);
4197
+ }
4198
+ this._instances.set(0, new _AsgardeoSPAClient(0));
4199
+ return this._instances.get(0);
4200
+ }
4201
+ /**
4202
+ * This method initializes the `AsgardeoSPAClient` instance.
4203
+ *
4204
+ * @param {ConfigInterface} config The config object to initialize with.
4205
+ *
4206
+ * @return {Promise<boolean>} - Resolves to `true` if initialization is successful.
4207
+ *
4208
+ * @example
4209
+ * ```
4210
+ * auth.initialize({
4211
+ * afterSignInUrl: "http://localhost:3000/sign-in",
4212
+ * clientId: "client ID",
4213
+ * baseUrl: "https://api.asgardeo.io"
4214
+ * });
4215
+ * ```
4216
+ *
4217
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#initialize
4218
+ *
4219
+ * @memberof AsgardeoSPAClient
4220
+ *
4221
+ * @preserve
4222
+ */
4223
+ async initialize(config, authHelper, workerFile) {
4224
+ this._storage = config.storage ?? "sessionStorage" /* SessionStorage */;
4225
+ this._initialized = false;
4226
+ this._startedInitialize = true;
4227
+ authHelper && this.instantiateAuthHelper(authHelper);
4228
+ const _config = await this._client?.getConfigData();
4229
+ if (!(this._storage === "webWorker" /* WebWorker */)) {
4230
+ const mainThreadClientConfig = config;
4231
+ const defaultConfig = { ...DefaultConfig };
4232
+ const mergedConfig = {
4233
+ ...defaultConfig,
4234
+ ...mainThreadClientConfig
4235
+ };
4236
+ if (!this._client || this._client && (!_config || Object.keys(_config)?.length === 0)) {
4237
+ this._client = await MainThreadClient(
4238
+ this._instanceID,
4239
+ mergedConfig,
4240
+ (authClient, spaHelper) => {
4241
+ return new this._authHelper(authClient, spaHelper);
4242
+ }
4243
+ );
4000
4244
  }
4001
- return Promise.reject(error);
4002
- });
4003
- };
4004
- const httpRequestAll = (configs) => {
4005
- const message = {
4006
- data: configs,
4007
- type: HTTP_REQUEST_ALL
4008
- };
4009
- return communicate(message).then((response) => {
4010
- return Promise.resolve(response);
4011
- }).catch(async (error) => {
4012
- if (_isHttpHandlerEnabled) {
4013
- if (typeof httpClientHandlers.requestErrorCallback === "function") {
4014
- await httpClientHandlers.requestErrorCallback(error);
4015
- }
4016
- if (typeof httpClientHandlers.requestFinishCallback === "function") {
4017
- httpClientHandlers.requestFinishCallback();
4245
+ this._initialized = true;
4246
+ if (this._onInitialize) {
4247
+ this._onInitialize(true);
4248
+ }
4249
+ if (!mergedConfig.autoLogoutOnTokenRefreshError) {
4250
+ return Promise.resolve(true);
4251
+ }
4252
+ window.addEventListener("message", (event) => {
4253
+ if (event?.data?.type === REFRESH_ACCESS_TOKEN_ERR0R) {
4254
+ this.signOut();
4018
4255
  }
4256
+ });
4257
+ return Promise.resolve(true);
4258
+ } else {
4259
+ if (!this._client || this._client && (!_config || Object.keys(_config)?.length === 0)) {
4260
+ const webWorkerClientConfig = config;
4261
+ this._client = await WebWorkerClient(
4262
+ this._instanceID,
4263
+ {
4264
+ ...DefaultConfig,
4265
+ ...webWorkerClientConfig
4266
+ },
4267
+ this._worker,
4268
+ (authClient, spaHelper) => {
4269
+ return new this._authHelper(authClient, spaHelper);
4270
+ }
4271
+ );
4272
+ return this._client.initialize().then(() => {
4273
+ if (this._onInitialize) {
4274
+ this._onInitialize(true);
4275
+ }
4276
+ this._initialized = true;
4277
+ return Promise.resolve(true);
4278
+ }).catch((error) => {
4279
+ return Promise.reject(error);
4280
+ });
4019
4281
  }
4020
- return Promise.reject(error);
4021
- });
4022
- };
4023
- const enableHttpHandler = () => {
4024
- const message = {
4025
- type: ENABLE_HTTP_HANDLER
4026
- };
4027
- return communicate(message).then(() => {
4028
- _isHttpHandlerEnabled = true;
4029
4282
  return Promise.resolve(true);
4030
- }).catch((error) => {
4031
- return Promise.reject(error);
4032
- });
4033
- };
4034
- const disableHttpHandler = () => {
4035
- const message = {
4036
- type: DISABLE_HTTP_HANDLER
4037
- };
4038
- return communicate(message).then(() => {
4039
- _isHttpHandlerEnabled = false;
4040
- return Promise.resolve(true);
4041
- }).catch((error) => {
4042
- return Promise.reject(error);
4043
- });
4044
- };
4045
- const initialize = () => {
4046
- if (!httpClientHandlers) {
4047
- httpClientHandlers = {
4048
- requestErrorCallback: () => Promise.resolve(),
4049
- requestFinishCallback: () => null,
4050
- requestStartCallback: () => null,
4051
- requestSuccessCallback: () => null
4052
- };
4053
4283
  }
4054
- worker.onmessage = ({ data }) => {
4055
- switch (data.type) {
4056
- case REQUEST_FINISH:
4057
- httpClientHandlers?.requestFinishCallback && httpClientHandlers?.requestFinishCallback();
4058
- break;
4059
- case REQUEST_START:
4060
- httpClientHandlers?.requestStartCallback && httpClientHandlers?.requestStartCallback();
4061
- break;
4062
- case REQUEST_SUCCESS:
4063
- httpClientHandlers?.requestSuccessCallback && httpClientHandlers?.requestSuccessCallback(data.data ? JSON.parse(data.data) : null);
4064
- break;
4065
- }
4066
- };
4067
- const message = {
4068
- data: config,
4069
- type: INIT
4070
- };
4071
- return communicate(message).then(() => {
4072
- return Promise.resolve(true);
4073
- }).catch((error) => {
4074
- return Promise.reject(error);
4075
- });
4076
- };
4077
- const setSessionState = (sessionState) => {
4078
- const message = {
4079
- data: sessionState,
4080
- type: SET_SESSION_STATE
4081
- };
4082
- return communicate(message);
4083
- };
4084
- const startAutoRefreshToken = () => {
4085
- const message = {
4086
- type: START_AUTO_REFRESH_TOKEN
4087
- };
4088
- return communicate(message);
4089
- };
4090
- const checkSession = async () => {
4091
- const oidcEndpoints = await getOIDCServiceEndpoints();
4092
- const config2 = await getConfigData();
4093
- _authenticationHelper.initializeSessionManger(
4094
- config2,
4095
- oidcEndpoints,
4096
- async () => (await getBasicUserInfo()).sessionState,
4097
- async (params) => (await getAuthorizationURL(params)).authorizationURL,
4098
- _sessionManagementHelper
4099
- );
4100
- };
4101
- const constructSilentSignInUrl = async (additionalParams = {}) => {
4102
- const config2 = await getConfigData();
4103
- const message = {
4104
- data: {
4105
- prompt: "none",
4106
- state: SILENT_SIGN_IN_STATE,
4107
- ...additionalParams
4108
- },
4109
- type: GET_AUTH_URL
4110
- };
4111
- const response = await communicate(message);
4112
- const pkceKey = (0, import_javascript9.extractPkceStorageKeyFromState)(
4113
- new URL(response.authorizationURL).searchParams.get(import_javascript9.OIDCRequestConstants.Params.STATE) ?? ""
4114
- );
4115
- response.pkce && config2.enablePKCE && SPAUtils.setPKCE(pkceKey, response.pkce);
4116
- const urlString = response.authorizationURL;
4117
- const urlObject = new URL(urlString);
4118
- urlObject.searchParams.set("response_mode", "query");
4119
- const url = urlObject.toString();
4120
- return url;
4121
- };
4122
- const trySignInSilently = async (additionalParams, tokenRequestConfig) => {
4123
- return await _authenticationHelper.trySignInSilently(
4124
- constructSilentSignInUrl,
4125
- requestAccessToken,
4126
- _sessionManagementHelper,
4127
- additionalParams,
4128
- tokenRequestConfig
4129
- );
4130
- };
4131
- const getAuthorizationURL = async (params) => {
4132
- const config2 = await getConfigData();
4133
- const message = {
4134
- data: params,
4135
- type: GET_AUTH_URL
4136
- };
4137
- return communicate(message).then(
4138
- async (response) => {
4139
- if (response.pkce && config2.enablePKCE) {
4140
- const pkceKey = (0, import_javascript9.extractPkceStorageKeyFromState)(
4141
- new URL(response.authorizationURL).searchParams.get(import_javascript9.OIDCRequestConstants.Params.STATE) ?? ""
4142
- );
4143
- SPAUtils.setPKCE(pkceKey, response.pkce);
4144
- }
4145
- return Promise.resolve(response);
4284
+ }
4285
+ /**
4286
+ * This method returns a Promise that resolves with the basic user information obtained from the ID token.
4287
+ *
4288
+ * @return {Promise<User>} - A promise that resolves with the user information.
4289
+ *
4290
+ * @example
4291
+ * ```
4292
+ * auth.getUser().then((response) => {
4293
+ * // console.log(response);
4294
+ * }).catch((error) => {
4295
+ * // console.error(error);
4296
+ * });
4297
+ * ```
4298
+ *
4299
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#getuserinfo
4300
+ *
4301
+ * @memberof AsgardeoSPAClient
4302
+ *
4303
+ * @preserve
4304
+ */
4305
+ async getUser() {
4306
+ await this._validateMethod();
4307
+ return this._client?.getUser();
4308
+ }
4309
+ /**
4310
+ * This method initiates the authentication flow. This should be called twice.
4311
+ * 1. To initiate the authentication flow.
4312
+ * 2. To obtain the access token after getting the authorization code.
4313
+ *
4314
+ * To satisfy the second condition, one of the two strategies mentioned below can be used:
4315
+ * 1. Redirect the user back to the same login page that initiated the authentication flow.
4316
+ * 2. Call the `signIn()` method in the page the user is redirected to after authentication.
4317
+ *
4318
+ * **To fire a callback function after signing in, use the `on()` method.**
4319
+ * **To learn more about the `on()` method:**
4320
+ * @see {@link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#on}
4321
+ *
4322
+ * @param {SignInConfig} config - The sign-in config.
4323
+ * The `SignInConfig` object has these two attributes in addition to any custom key-value pairs.
4324
+ * 1. fidp - Specifies the FIDP parameter that is used to take the user directly to an IdP login page.
4325
+ * 2. forceInit: Specifies if the OIDC Provider Meta Data should be loaded again from the `well-known`
4326
+ * endpoint.
4327
+ * 3. Any other parameters that should be appended to the authorization request.
4328
+ * @param {string} authorizationCode - The authorization code. (Optional)
4329
+ * @param {string} sessionState - The session state. (Optional)
4330
+ * @param {string} state - The state. (Optional)
4331
+ *
4332
+ * @return {Promise<User>} - A promise that resolves with the user information.
4333
+ *
4334
+ * @example
4335
+ * ```
4336
+ * auth.signIn();
4337
+ * ```
4338
+ *
4339
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#signin
4340
+ *
4341
+ * @memberof AsgardeoSPAClient
4342
+ *
4343
+ * @preserve
4344
+ */
4345
+ async signIn(config, authorizationCode, sessionState, state, tokenRequestConfig) {
4346
+ await this.isInitialized();
4347
+ if (!SPAUtils.canContinueSignIn(Boolean(config?.callOnlyOnRedirect), authorizationCode)) {
4348
+ return void 0;
4349
+ }
4350
+ delete config?.callOnlyOnRedirect;
4351
+ return this._client?.signIn(config, authorizationCode, sessionState, state, tokenRequestConfig).then((response) => {
4352
+ if (this._onSignInCallback) {
4353
+ this._onSignInCallback(response);
4146
4354
  }
4147
- );
4148
- };
4149
- const requestAccessToken = async (resolvedAuthorizationCode, resolvedSessionState, resolvedState, tokenRequestConfig) => {
4150
- const config2 = await getConfigData();
4151
- const pkceKey = (0, import_javascript9.extractPkceStorageKeyFromState)(resolvedState);
4152
- const message = {
4153
- data: {
4154
- code: resolvedAuthorizationCode,
4155
- pkce: config2.enablePKCE ? SPAUtils.getPKCE(pkceKey) : void 0,
4156
- sessionState: resolvedSessionState,
4157
- state: resolvedState,
4158
- tokenRequestConfig
4159
- },
4160
- type: REQUEST_ACCESS_TOKEN
4161
- };
4162
- config2.enablePKCE && SPAUtils.removePKCE(pkceKey);
4163
- return communicate(message).then((response) => {
4164
- const message2 = {
4165
- type: GET_SIGN_OUT_URL
4166
- };
4167
- return communicate(message2).then((url) => {
4168
- SPAUtils.setSignOutURL(url, config2.clientID, instanceID);
4169
- if (config2.enableOIDCSessionManagement) {
4170
- checkSession();
4171
- }
4172
- startAutoRefreshToken();
4173
- return Promise.resolve(response);
4174
- }).catch((error) => {
4175
- return Promise.reject(error);
4176
- });
4177
- }).catch((error) => {
4178
- return Promise.reject(error);
4179
- });
4180
- };
4181
- const shouldStopAuthn = async () => {
4182
- return await _sessionManagementHelper.receivePromptNoneResponse(async (sessionState) => {
4183
- return setSessionState(sessionState);
4355
+ return response;
4184
4356
  });
4185
- };
4186
- const tryRetrievingUserInfo = async () => {
4187
- if (await isAuthenticated()) {
4188
- await startAutoRefreshToken();
4189
- if (config.enableOIDCSessionManagement) {
4190
- checkSession();
4191
- }
4192
- return getBasicUserInfo();
4357
+ }
4358
+ /**
4359
+ * This method allows you to sign in silently.
4360
+ * First, this method sends a prompt none request to see if there is an active user session in the identity server.
4361
+ * If there is one, then it requests the access token and stores it. Else, it returns false.
4362
+ *
4363
+ * If this method is to be called on page load and the `signIn` method is also to be called on page load,
4364
+ * then it is advisable to call this method after the `signIn` call.
4365
+ *
4366
+ * @return {Promise<User | boolean>} - A Promise that resolves with the user information after signing in
4367
+ * or with `false` if the user is not signed in.
4368
+ *
4369
+ * @example
4370
+ *```
4371
+ * auth.trySignInSilently()
4372
+ *```
4373
+ */
4374
+ async trySignInSilently(additionalParams, tokenRequestConfig) {
4375
+ await this.isInitialized();
4376
+ if (SPAUtils.wasSignInCalled()) {
4377
+ return void 0;
4193
4378
  }
4194
- return Promise.resolve(void 0);
4195
- };
4196
- const signIn = async (params, authorizationCode, sessionState, state, tokenRequestConfig) => {
4197
- const basicUserInfo = await _authenticationHelper.handleSignIn(
4198
- shouldStopAuthn,
4199
- checkSession,
4200
- tryRetrievingUserInfo
4201
- );
4202
- if (basicUserInfo) {
4203
- return basicUserInfo;
4204
- } else {
4205
- let resolvedAuthorizationCode;
4206
- let resolvedSessionState;
4207
- let resolvedState;
4208
- if (config?.responseMode === import_javascript9.ResponseMode.FormPost && authorizationCode) {
4209
- resolvedAuthorizationCode = authorizationCode;
4210
- resolvedSessionState = sessionState ?? "";
4211
- resolvedState = state ?? "";
4212
- } else {
4213
- resolvedAuthorizationCode = new URL(window.location.href).searchParams.get(import_javascript9.OIDCRequestConstants.Params.AUTHORIZATION_CODE) ?? "";
4214
- resolvedSessionState = new URL(window.location.href).searchParams.get(import_javascript9.OIDCRequestConstants.Params.SESSION_STATE) ?? "";
4215
- resolvedState = new URL(window.location.href).searchParams.get(import_javascript9.OIDCRequestConstants.Params.STATE) ?? "";
4216
- SPAUtils.removeAuthorizationCode();
4217
- }
4218
- if (resolvedAuthorizationCode && resolvedState) {
4219
- return requestAccessToken(resolvedAuthorizationCode, resolvedSessionState, resolvedState, tokenRequestConfig);
4379
+ return this._client?.trySignInSilently(additionalParams, tokenRequestConfig).then((response) => {
4380
+ if (this._onSignInCallback && response) {
4381
+ this._onSignInCallback(response);
4220
4382
  }
4221
- return getAuthorizationURL(params).then(async (response) => {
4222
- location.href = response.authorizationURL;
4223
- await SPAUtils.waitTillPageRedirect();
4224
- return Promise.resolve({
4225
- allowedScopes: "",
4226
- displayName: "",
4227
- email: "",
4228
- sessionState: "",
4229
- sub: "",
4230
- tenantDomain: "",
4231
- username: ""
4232
- });
4233
- }).catch((error) => {
4234
- return Promise.reject(error);
4235
- });
4236
- }
4237
- };
4238
- const signOut = () => {
4239
- return new Promise((resolve, reject) => {
4240
- if (!_getSignOutURLFromSessionStorage) {
4241
- const message = {
4242
- type: SIGN_OUT
4243
- };
4244
- return communicate(message).then(async (response) => {
4245
- window.location.href = response;
4246
- await SPAUtils.waitTillPageRedirect();
4247
- return resolve(true);
4248
- }).catch((error) => {
4249
- return reject(error);
4250
- });
4251
- } else {
4252
- window.location.href = SPAUtils.getSignOutURL(config.clientID, instanceID);
4253
- return SPAUtils.waitTillPageRedirect().then(() => {
4254
- return Promise.resolve(true);
4255
- });
4256
- }
4257
- });
4258
- };
4259
- const revokeAccessToken = () => {
4260
- const message = {
4261
- type: REVOKE_ACCESS_TOKEN
4262
- };
4263
- return communicate(message).then((response) => {
4264
- _sessionManagementHelper.reset();
4265
- return Promise.resolve(response);
4266
- }).catch((error) => {
4267
- return Promise.reject(error);
4268
- });
4269
- };
4270
- const getOIDCServiceEndpoints = () => {
4271
- const message = {
4272
- type: GET_OIDC_SERVICE_ENDPOINTS
4273
- };
4274
- return communicate(message).then((response) => {
4275
- return Promise.resolve(response);
4276
- }).catch((error) => {
4277
- return Promise.reject(error);
4278
- });
4279
- };
4280
- const getConfigData = () => {
4281
- const message = {
4282
- type: GET_CONFIG_DATA
4283
- };
4284
- return communicate(message).then((response) => {
4285
- return Promise.resolve(response);
4286
- }).catch((error) => {
4287
- return Promise.reject(error);
4288
- });
4289
- };
4290
- const getBasicUserInfo = () => {
4291
- const message = {
4292
- type: GET_BASIC_USER_INFO
4293
- };
4294
- return communicate(message).then((response) => {
4295
- return Promise.resolve(response);
4296
- }).catch((error) => {
4297
- return Promise.reject(error);
4298
- });
4299
- };
4300
- const getDecodedIDToken = () => {
4301
- const message = {
4302
- type: GET_DECODED_ID_TOKEN
4303
- };
4304
- return communicate(message).then((response) => {
4305
- return Promise.resolve(response);
4306
- }).catch((error) => {
4307
- return Promise.reject(error);
4308
- });
4309
- };
4310
- const getDecodedIDPIDToken = () => {
4311
- const message = {
4312
- type: GET_DECODED_IDP_ID_TOKEN
4313
- };
4314
- return communicate(message).then((response) => {
4315
- return Promise.resolve(response);
4316
- }).catch((error) => {
4317
- return Promise.reject(error);
4318
- });
4319
- };
4320
- const getCryptoHelper = () => {
4321
- const message = {
4322
- type: GET_CRYPTO_HELPER
4323
- };
4324
- return communicate(message).then((response) => {
4325
- return Promise.resolve(response);
4326
- }).catch((error) => {
4327
- return Promise.reject(error);
4328
- });
4329
- };
4330
- const getIDToken = () => {
4331
- const message = {
4332
- type: GET_ID_TOKEN
4333
- };
4334
- return communicate(message).then((response) => {
4335
- return Promise.resolve(response);
4336
- }).catch((error) => {
4337
- return Promise.reject(error);
4338
- });
4339
- };
4340
- const isAuthenticated = () => {
4341
- const message = {
4342
- type: IS_AUTHENTICATED
4343
- };
4344
- return communicate(message).then((response) => {
4345
- return Promise.resolve(response);
4346
- }).catch((error) => {
4347
- return Promise.reject(error);
4383
+ return response;
4348
4384
  });
4349
- };
4350
- const refreshAccessToken = () => {
4351
- const message = {
4352
- type: REFRESH_ACCESS_TOKEN
4353
- };
4354
- return communicate(message);
4355
- };
4356
- const setHttpRequestSuccessCallback = (callback) => {
4357
- if (callback && typeof callback === "function") {
4358
- httpClientHandlers.requestSuccessCallback = callback;
4359
- }
4360
- };
4361
- const setHttpRequestErrorCallback = (callback) => {
4362
- if (callback && typeof callback === "function") {
4363
- httpClientHandlers.requestErrorCallback = callback;
4364
- }
4365
- };
4366
- const setHttpRequestStartCallback = (callback) => {
4367
- if (callback && typeof callback === "function") {
4368
- httpClientHandlers.requestStartCallback = callback;
4369
- }
4370
- };
4371
- const setHttpRequestFinishCallback = (callback) => {
4372
- if (callback && typeof callback === "function") {
4373
- httpClientHandlers.requestFinishCallback = callback;
4374
- }
4375
- };
4376
- const updateConfig = async (newConfig) => {
4377
- const existingConfig = await getConfigData();
4378
- const isCheckSessionIframeDifferent = !(existingConfig && existingConfig.endpoints && existingConfig.endpoints.checkSessionIframe && newConfig && newConfig.endpoints && newConfig.endpoints.checkSessionIframe && existingConfig.endpoints.checkSessionIframe === newConfig.endpoints.checkSessionIframe);
4379
- const config2 = { ...existingConfig, ...newConfig };
4380
- const message = {
4381
- data: config2,
4382
- type: UPDATE_CONFIG
4383
- };
4384
- await communicate(message);
4385
- if (config2.enableOIDCSessionManagement && isCheckSessionIframeDifferent) {
4386
- _sessionManagementHelper.reset();
4387
- checkSession();
4388
- }
4389
- };
4390
- return {
4391
- disableHttpHandler,
4392
- enableHttpHandler,
4393
- getBasicUserInfo,
4394
- getConfigData,
4395
- getCryptoHelper,
4396
- getDecodedIDPIDToken,
4397
- getDecodedIDToken,
4398
- getIDToken,
4399
- getOIDCServiceEndpoints,
4400
- httpRequest,
4401
- httpRequestAll,
4402
- initialize,
4403
- isAuthenticated,
4404
- refreshAccessToken,
4405
- requestCustomGrant,
4406
- revokeAccessToken,
4407
- setHttpRequestErrorCallback,
4408
- setHttpRequestFinishCallback,
4409
- setHttpRequestStartCallback,
4410
- setHttpRequestSuccessCallback,
4411
- signIn,
4412
- signOut,
4413
- trySignInSilently,
4414
- updateConfig
4415
- };
4416
- };
4417
-
4418
- // src/__legacy__/client.ts
4419
- var DefaultConfig = {
4420
- autoLogoutOnTokenRefreshError: true,
4421
- checkSessionInterval: 3,
4422
- clientHost: origin,
4423
- enableOIDCSessionManagement: false,
4424
- periodicTokenRefresh: false,
4425
- sessionRefreshInterval: 300,
4426
- storage: "sessionStorage" /* SessionStorage */
4427
- };
4428
- var _AsgardeoSPAClient = class _AsgardeoSPAClient {
4429
- constructor(id) {
4430
- __publicField(this, "_client");
4431
- __publicField(this, "_storage");
4432
- __publicField(this, "_authHelper", AuthenticationHelper);
4433
- __publicField(this, "_worker", worker_default);
4434
- __publicField(this, "_initialized", false);
4435
- __publicField(this, "_startedInitialize", false);
4436
- __publicField(this, "_onSignInCallback", () => null);
4437
- __publicField(this, "_onSignOutCallback", () => null);
4438
- __publicField(this, "_onSignOutFailedCallback", () => null);
4439
- __publicField(this, "_onEndUserSession", () => null);
4440
- __publicField(this, "_onInitialize", () => null);
4441
- __publicField(this, "_onCustomGrant", /* @__PURE__ */ new Map());
4442
- __publicField(this, "_instanceID");
4443
- this._instanceID = id;
4444
- }
4445
- instantiateAuthHelper(authHelper) {
4446
- if (authHelper) {
4447
- this._authHelper = authHelper;
4448
- } else {
4449
- this._authHelper = AuthenticationHelper;
4450
- }
4451
- }
4452
- instantiateWorker(worker) {
4453
- if (worker) {
4454
- this._worker = worker;
4455
- } else {
4456
- this._worker = worker_default;
4457
- }
4458
4385
  }
4459
4386
  /**
4460
- * This method specifies if the `AsgardeoSPAClient` has been initialized or not.
4387
+ * This method initiates the sign-out flow.
4461
4388
  *
4462
- * @return {Promise<boolean>} - Resolves to `true` if the client has been initialized.
4389
+ * **To fire a callback function after signing out, use the `on()` method.**
4390
+ * **To learn more about the `on()` method:**
4391
+ * @see {@link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#on}
4392
+ *
4393
+ * @return {Promise<boolean>} - Returns a promise that resolves with `true` if sign out is successful.
4394
+ *
4395
+ * @example
4396
+ * ```
4397
+ * auth.signOut();
4398
+ * ```
4399
+ *
4400
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#signout
4463
4401
  *
4464
4402
  * @memberof AsgardeoSPAClient
4465
4403
  *
4466
- * @private
4404
+ * @preserve
4467
4405
  */
4468
- async _isInitialized() {
4469
- if (!this._startedInitialize) {
4470
- return false;
4471
- }
4472
- let iterationToWait = 0;
4473
- const sleep = () => {
4474
- return new Promise((resolve) => setTimeout(resolve, 1));
4475
- };
4476
- while (!this._initialized) {
4477
- if (iterationToWait === 1e4) {
4478
- console.warn("It is taking longer than usual for the object to be initialized");
4479
- }
4480
- await sleep();
4481
- iterationToWait++;
4482
- }
4483
- return true;
4406
+ async signOut() {
4407
+ await this._validateMethod(false);
4408
+ const signOutResponse = await this._client?.signOut() ?? false;
4409
+ return signOutResponse;
4484
4410
  }
4485
4411
  /**
4486
- * This method checks if the SDK is initialized and the user is authenticated.
4412
+ * This method sends an API request to a protected endpoint.
4413
+ * The access token is automatically attached to the header of the request.
4414
+ * This is the only way by which protected endpoints can be accessed
4415
+ * when the web worker is used to store session information.
4487
4416
  *
4488
- * @param validateAuthentication - should user's authenticated status be checked as part of validation
4417
+ * @param {HttpRequestConfig} config - The config object containing attributes necessary to send a request.
4489
4418
  *
4490
- * @return {Promise<boolean>} - A Promise that resolves with `true` if the SDK is initialized and the
4491
- * user is authenticated.
4419
+ * @return {Promise<HttpResponse>} - Returns a Promise that resolves with the response to the request.
4420
+ *
4421
+ * @example
4422
+ * ```
4423
+ * const requestConfig = {
4424
+ * headers: {
4425
+ * "Accept": "application/json",
4426
+ * "Access-Control-Allow-Origin": "https://api.asgardeo.io/myaccount",
4427
+ * "Content-Type": "application/scim+json"
4428
+ * },
4429
+ * method: "GET",
4430
+ * url: "https://api.asgardeo.io/scim2/me"
4431
+ * };
4432
+ *
4433
+ * return auth.httpRequest(requestConfig)
4434
+ * .then((response) => {
4435
+ * // console.log(response);
4436
+ * })
4437
+ * .catch((error) => {
4438
+ * // console.error(error);
4439
+ * });
4440
+ * ```
4441
+ *
4442
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#httprequest
4492
4443
  *
4493
4444
  * @memberof AsgardeoSPAClient
4494
4445
  *
4495
- * @private
4446
+ * @preserve
4496
4447
  */
4497
- async _validateMethod(validateAuthentication = true) {
4498
- if (!await this._isInitialized()) {
4499
- return Promise.reject(
4500
- new import_javascript10.AsgardeoAuthException(
4501
- "SPA-AUTH_CLIENT-VM-NF01",
4502
- "The SDK is not initialized.",
4503
- "The SDK must be initialized first."
4504
- )
4505
- );
4506
- }
4507
- if (validateAuthentication && !await this.isAuthenticated()) {
4508
- return Promise.reject(
4509
- new import_javascript10.AsgardeoAuthException(
4510
- "SPA-AUTH_CLIENT-VM-IV02",
4511
- "The user is not authenticated.",
4512
- "The user must be authenticated first."
4513
- )
4514
- );
4515
- }
4516
- return true;
4448
+ async httpRequest(config) {
4449
+ await this._validateMethod(false);
4450
+ return this._client?.httpRequest(config);
4517
4451
  }
4518
4452
  /**
4519
- * This method returns the instance of the singleton class.
4520
- * If an ID is provided, it will return the instance with the given ID.
4521
- * If no ID is provided, it will return the default instance value 0.
4453
+ * This method sends multiple API requests to a protected endpoint.
4454
+ * The access token is automatically attached to the header of the request.
4455
+ * This is the only way by which multiple requests can be sent to protected endpoints
4456
+ * when the web worker is used to store session information.
4522
4457
  *
4523
- * @return {AsgardeoSPAClient} - Returns the instance of the singleton class.
4458
+ * @param {HttpRequestConfig[]} config - The config object containing attributes necessary to send a request.
4459
+ *
4460
+ * @return {Promise<HttpResponse[]>} - Returns a Promise that resolves with the responses to the requests.
4524
4461
  *
4525
4462
  * @example
4526
4463
  * ```
4527
- * const auth = AsgardeoSPAClient.getInstance();
4464
+ * const requestConfig = {
4465
+ * headers: {
4466
+ * "Accept": "application/json",
4467
+ * "Content-Type": "application/scim+json"
4468
+ * },
4469
+ * method: "GET",
4470
+ * url: "https://api.asgardeo.io/scim2/me"
4471
+ * };
4472
+ *
4473
+ * const requestConfig2 = {
4474
+ * headers: {
4475
+ * "Accept": "application/json",
4476
+ * "Content-Type": "application/scim+json"
4477
+ * },
4478
+ * method: "GET",
4479
+ * url: "https://api.asgardeo.io/scim2/me"
4480
+ * };
4481
+ *
4482
+ * return auth.httpRequest([requestConfig, requestConfig2])
4483
+ * .then((responses) => {
4484
+ * response.forEach((response)=>{
4485
+ * // console.log(response);
4486
+ * });
4487
+ * })
4488
+ * .catch((error) => {
4489
+ * // console.error(error);
4490
+ * });
4528
4491
  * ```
4529
4492
  *
4530
- * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#getinstance
4493
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#httprequestall
4531
4494
  *
4532
4495
  * @memberof AsgardeoSPAClient
4533
4496
  *
4534
4497
  * @preserve
4535
4498
  */
4536
- static getInstance(id) {
4537
- if (id && this._instances?.get(id)) {
4538
- return this._instances.get(id);
4539
- } else if (!id && this._instances?.get(0)) {
4540
- return this._instances.get(0);
4541
- }
4542
- if (id) {
4543
- this._instances.set(id, new _AsgardeoSPAClient(id));
4544
- return this._instances.get(id);
4545
- }
4546
- this._instances.set(0, new _AsgardeoSPAClient(0));
4547
- return this._instances.get(0);
4499
+ async httpRequestAll(config) {
4500
+ await this._validateMethod(false);
4501
+ return this._client?.httpRequestAll(config);
4548
4502
  }
4549
4503
  /**
4550
- * This method initializes the `AsgardeoSPAClient` instance.
4504
+ * This method allows you to send a request with a custom grant.
4551
4505
  *
4552
- * @param {ConfigInterface} config The config object to initialize with.
4506
+ * @param {CustomGrantRequestParams} config - The request parameters.
4553
4507
  *
4554
- * @return {Promise<boolean>} - Resolves to `true` if initialization is successful.
4508
+ * @return {Promise<HttpResponse<any> | SignInResponse>} - A Promise that resolves with
4509
+ * the value returned by the custom grant request.
4555
4510
  *
4556
4511
  * @example
4557
4512
  * ```
4558
- * auth.initialize({
4559
- * signInRedirectURL: "http://localhost:3000/sign-in",
4560
- * clientID: "client ID",
4561
- * baseUrl: "https://api.asgardeo.io"
4513
+ * auth.customGrant({
4514
+ * attachToken: false,
4515
+ * data: {
4516
+ * client_id: "{{clientId}}",
4517
+ * grant_type: "account_switch",
4518
+ * scope: "{{scope}}",
4519
+ * token: "{{token}}",
4520
+ * },
4521
+ * id: "account-switch",
4522
+ * returnResponse: true,
4523
+ * returnsSession: true,
4524
+ * signInRequired: true
4562
4525
  * });
4563
4526
  * ```
4564
4527
  *
4565
- * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#initialize
4528
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#customgrant
4566
4529
  *
4567
4530
  * @memberof AsgardeoSPAClient
4568
4531
  *
4569
4532
  * @preserve
4570
4533
  */
4571
- async initialize(config, authHelper, workerFile) {
4572
- this._storage = config.storage ?? "sessionStorage" /* SessionStorage */;
4573
- this._initialized = false;
4574
- this._startedInitialize = true;
4575
- authHelper && this.instantiateAuthHelper(authHelper);
4576
- workerFile && this.instantiateWorker(workerFile);
4577
- const _config = await this._client?.getConfigData();
4578
- if (!(this._storage === "webWorker" /* WebWorker */)) {
4579
- const mainThreadClientConfig = config;
4580
- const defaultConfig = { ...DefaultConfig };
4581
- const mergedConfig = {
4582
- ...defaultConfig,
4583
- ...mainThreadClientConfig
4584
- };
4585
- if (!this._client || this._client && (!_config || Object.keys(_config)?.length === 0)) {
4586
- this._client = await MainThreadClient(
4587
- this._instanceID,
4588
- mergedConfig,
4589
- (authClient, spaHelper) => {
4590
- return new this._authHelper(authClient, spaHelper);
4591
- }
4592
- );
4593
- }
4594
- this._initialized = true;
4595
- if (this._onInitialize) {
4596
- this._onInitialize(true);
4597
- }
4598
- if (!mergedConfig.autoLogoutOnTokenRefreshError) {
4599
- return Promise.resolve(true);
4600
- }
4601
- window.addEventListener("message", (event) => {
4602
- if (event?.data?.type === REFRESH_ACCESS_TOKEN_ERR0R) {
4603
- this.signOut();
4604
- }
4605
- });
4606
- return Promise.resolve(true);
4534
+ async exchangeToken(config) {
4535
+ if (config.signInRequired) {
4536
+ await this._validateMethod();
4607
4537
  } else {
4608
- if (!this._client || this._client && (!_config || Object.keys(_config)?.length === 0)) {
4609
- const webWorkerClientConfig = config;
4610
- this._client = await WebWorkerClient(
4611
- this._instanceID,
4612
- {
4613
- ...DefaultConfig,
4614
- ...webWorkerClientConfig
4615
- },
4616
- this._worker,
4617
- (authClient, spaHelper) => {
4618
- return new this._authHelper(authClient, spaHelper);
4619
- }
4620
- );
4621
- return this._client.initialize().then(() => {
4622
- if (this._onInitialize) {
4623
- this._onInitialize(true);
4624
- }
4625
- this._initialized = true;
4626
- return Promise.resolve(true);
4627
- }).catch((error) => {
4628
- return Promise.reject(error);
4629
- });
4630
- }
4631
- return Promise.resolve(true);
4538
+ await this._validateMethod();
4539
+ }
4540
+ if (!config.id) {
4541
+ return Promise.reject(
4542
+ new import_javascript8.AsgardeoAuthException(
4543
+ "SPA-AUTH_CLIENT-RCG-NF01",
4544
+ "The custom grant request id not found.",
4545
+ "The id attribute of the custom grant config object passed as an argument should have a value."
4546
+ )
4547
+ );
4632
4548
  }
4549
+ const customGrantResponse = await this._client?.exchangeToken(config);
4550
+ const customGrantCallback = this._onCustomGrant.get(config.id);
4551
+ customGrantCallback && customGrantCallback(this._onCustomGrant?.get(config.id));
4552
+ return customGrantResponse;
4633
4553
  }
4634
4554
  /**
4635
- * This method returns a Promise that resolves with the basic user information obtained from the ID token.
4555
+ * This method ends a user session. The access token is revoked and the session information is destroyed.
4556
+ *
4557
+ * **To fire a callback function after ending user session, use the `on()` method.**
4558
+ * **To learn more about the `on()` method:**
4559
+ * @see {@link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#on}
4636
4560
  *
4637
- * @return {Promise<BasicUserInfo>} - A promise that resolves with the user information.
4561
+ * @return {Promise<boolean>} - A promise that resolves with `true` if the process is successful.
4638
4562
  *
4639
4563
  * @example
4640
4564
  * ```
4641
- * auth.getBasicUserInfo().then((response) => {
4642
- * // console.log(response);
4643
- * }).catch((error) => {
4644
- * // console.error(error);
4645
- * });
4565
+ * auth.endUserSession();
4646
4566
  * ```
4647
4567
  *
4648
- * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#getuserinfo
4568
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#endusersession
4649
4569
  *
4650
4570
  * @memberof AsgardeoSPAClient
4651
4571
  *
4652
4572
  * @preserve
4653
4573
  */
4654
- async getBasicUserInfo() {
4574
+ async revokeAccessToken() {
4655
4575
  await this._validateMethod();
4656
- return this._client?.getBasicUserInfo();
4576
+ const revokeAccessToken = await this._client?.revokeAccessToken();
4577
+ this._onEndUserSession && await this._onEndUserSession(revokeAccessToken);
4578
+ return revokeAccessToken;
4657
4579
  }
4658
4580
  /**
4659
- * This method initiates the authentication flow. This should be called twice.
4660
- * 1. To initiate the authentication flow.
4661
- * 2. To obtain the access token after getting the authorization code.
4662
- *
4663
- * To satisfy the second condition, one of the two strategies mentioned below can be used:
4664
- * 1. Redirect the user back to the same login page that initiated the authentication flow.
4665
- * 2. Call the `signIn()` method in the page the user is redirected to after authentication.
4666
- *
4667
- * **To fire a callback function after signing in, use the `on()` method.**
4668
- * **To learn more about the `on()` method:**
4669
- * @see {@link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#on}
4670
- *
4671
- * @param {SignInConfig} config - The sign-in config.
4672
- * The `SignInConfig` object has these two attributes in addition to any custom key-value pairs.
4673
- * 1. fidp - Specifies the FIDP parameter that is used to take the user directly to an IdP login page.
4674
- * 2. forceInit: Specifies if the OIDC Provider Meta Data should be loaded again from the `well-known`
4675
- * endpoint.
4676
- * 3. Any other parameters that should be appended to the authorization request.
4677
- * @param {string} authorizationCode - The authorization code. (Optional)
4678
- * @param {string} sessionState - The session state. (Optional)
4679
- * @param {string} state - The state. (Optional)
4581
+ * This method returns a Promise that resolves with an object containing the service endpoints.
4680
4582
  *
4681
- * @return {Promise<BasicUserInfo>} - A promise that resolves with the user information.
4583
+ * @return {Promise<ServiceResourcesType} - A Promise that resolves with an object containing the service endpoints.
4682
4584
  *
4683
4585
  * @example
4684
4586
  * ```
4685
- * auth.signIn();
4587
+ * auth.getServiceEndpoints().then((endpoints) => {
4588
+ * // console.log(endpoints);
4589
+ * }).error((error) => {
4590
+ * // console.error(error);
4591
+ * });
4686
4592
  * ```
4687
4593
  *
4688
- * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#signin
4594
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#getserviceendpoints
4689
4595
  *
4690
4596
  * @memberof AsgardeoSPAClient
4691
4597
  *
4692
4598
  * @preserve
4693
4599
  */
4694
- async signIn(config, authorizationCode, sessionState, state, tokenRequestConfig) {
4695
- await this._isInitialized();
4696
- if (!SPAUtils.canContinueSignIn(Boolean(config?.callOnlyOnRedirect), authorizationCode)) {
4697
- return void 0;
4698
- }
4699
- delete config?.callOnlyOnRedirect;
4700
- return this._client?.signIn(config, authorizationCode, sessionState, state, tokenRequestConfig).then((response) => {
4701
- if (this._onSignInCallback) {
4702
- if (response.allowedScopes || response.displayName || response.email || response.username) {
4703
- this._onSignInCallback(response);
4704
- }
4705
- }
4706
- return response;
4707
- });
4708
- }
4709
- /**
4710
- * This method allows you to sign in silently.
4711
- * First, this method sends a prompt none request to see if there is an active user session in the identity server.
4712
- * If there is one, then it requests the access token and stores it. Else, it returns false.
4713
- *
4714
- * If this method is to be called on page load and the `signIn` method is also to be called on page load,
4715
- * then it is advisable to call this method after the `signIn` call.
4716
- *
4717
- * @return {Promise<BasicUserInfo | boolean>} - A Promise that resolves with the user information after signing in
4718
- * or with `false` if the user is not signed in.
4719
- *
4720
- * @example
4721
- *```
4722
- * auth.trySignInSilently()
4723
- *```
4724
- */
4725
- async trySignInSilently(additionalParams, tokenRequestConfig) {
4726
- await this._isInitialized();
4727
- if (SPAUtils.wasSignInCalled()) {
4728
- return void 0;
4729
- }
4730
- return this._client?.trySignInSilently(additionalParams, tokenRequestConfig).then((response) => {
4731
- if (this._onSignInCallback && response) {
4732
- const basicUserInfo = response;
4733
- if (basicUserInfo.allowedScopes || basicUserInfo.displayName || basicUserInfo.email || basicUserInfo.username) {
4734
- this._onSignInCallback(basicUserInfo);
4735
- }
4736
- }
4737
- return response;
4738
- });
4739
- }
4740
- /**
4741
- * This method initiates the sign-out flow.
4742
- *
4743
- * **To fire a callback function after signing out, use the `on()` method.**
4744
- * **To learn more about the `on()` method:**
4745
- * @see {@link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#on}
4746
- *
4747
- * @return {Promise<boolean>} - Returns a promise that resolves with `true` if sign out is successful.
4748
- *
4749
- * @example
4750
- * ```
4751
- * auth.signOut();
4752
- * ```
4753
- *
4754
- * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#signout
4755
- *
4756
- * @memberof AsgardeoSPAClient
4757
- *
4758
- * @preserve
4759
- */
4760
- async signOut() {
4761
- await this._validateMethod(false);
4762
- const signOutResponse = await this._client?.signOut() ?? false;
4763
- return signOutResponse;
4764
- }
4765
- /**
4766
- * This method sends an API request to a protected endpoint.
4767
- * The access token is automatically attached to the header of the request.
4768
- * This is the only way by which protected endpoints can be accessed
4769
- * when the web worker is used to store session information.
4770
- *
4771
- * @param {HttpRequestConfig} config - The config object containing attributes necessary to send a request.
4772
- *
4773
- * @return {Promise<HttpResponse>} - Returns a Promise that resolves with the response to the request.
4774
- *
4775
- * @example
4776
- * ```
4777
- * const requestConfig = {
4778
- * headers: {
4779
- * "Accept": "application/json",
4780
- * "Access-Control-Allow-Origin": "https://api.asgardeo.io/myaccount",
4781
- * "Content-Type": "application/scim+json"
4782
- * },
4783
- * method: "GET",
4784
- * url: "https://api.asgardeo.io/scim2/me"
4785
- * };
4786
- *
4787
- * return auth.httpRequest(requestConfig)
4788
- * .then((response) => {
4789
- * // console.log(response);
4790
- * })
4791
- * .catch((error) => {
4792
- * // console.error(error);
4793
- * });
4794
- * ```
4795
- *
4796
- * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#httprequest
4797
- *
4798
- * @memberof AsgardeoSPAClient
4799
- *
4800
- * @preserve
4801
- */
4802
- async httpRequest(config) {
4803
- await this._validateMethod(false);
4804
- return this._client?.httpRequest(config);
4805
- }
4806
- /**
4807
- * This method sends multiple API requests to a protected endpoint.
4808
- * The access token is automatically attached to the header of the request.
4809
- * This is the only way by which multiple requests can be sent to protected endpoints
4810
- * when the web worker is used to store session information.
4811
- *
4812
- * @param {HttpRequestConfig[]} config - The config object containing attributes necessary to send a request.
4813
- *
4814
- * @return {Promise<HttpResponse[]>} - Returns a Promise that resolves with the responses to the requests.
4815
- *
4816
- * @example
4817
- * ```
4818
- * const requestConfig = {
4819
- * headers: {
4820
- * "Accept": "application/json",
4821
- * "Content-Type": "application/scim+json"
4822
- * },
4823
- * method: "GET",
4824
- * url: "https://api.asgardeo.io/scim2/me"
4825
- * };
4826
- *
4827
- * const requestConfig2 = {
4828
- * headers: {
4829
- * "Accept": "application/json",
4830
- * "Content-Type": "application/scim+json"
4831
- * },
4832
- * method: "GET",
4833
- * url: "https://api.asgardeo.io/scim2/me"
4834
- * };
4835
- *
4836
- * return auth.httpRequest([requestConfig, requestConfig2])
4837
- * .then((responses) => {
4838
- * response.forEach((response)=>{
4839
- * // console.log(response);
4840
- * });
4841
- * })
4842
- * .catch((error) => {
4843
- * // console.error(error);
4844
- * });
4845
- * ```
4846
- *
4847
- * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#httprequestall
4848
- *
4849
- * @memberof AsgardeoSPAClient
4850
- *
4851
- * @preserve
4852
- */
4853
- async httpRequestAll(config) {
4854
- await this._validateMethod(false);
4855
- return this._client?.httpRequestAll(config);
4856
- }
4857
- /**
4858
- * This method allows you to send a request with a custom grant.
4859
- *
4860
- * @param {CustomGrantRequestParams} config - The request parameters.
4861
- *
4862
- * @return {Promise<HttpResponse<any> | SignInResponse>} - A Promise that resolves with
4863
- * the value returned by the custom grant request.
4864
- *
4865
- * @example
4866
- * ```
4867
- * auth.customGrant({
4868
- * attachToken: false,
4869
- * data: {
4870
- * client_id: "{{clientId}}",
4871
- * grant_type: "account_switch",
4872
- * scope: "{{scope}}",
4873
- * token: "{{token}}",
4874
- * },
4875
- * id: "account-switch",
4876
- * returnResponse: true,
4877
- * returnsSession: true,
4878
- * signInRequired: true
4879
- * });
4880
- * ```
4881
- *
4882
- * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#customgrant
4883
- *
4884
- * @memberof AsgardeoSPAClient
4885
- *
4886
- * @preserve
4887
- */
4888
- async requestCustomGrant(config) {
4889
- if (config.signInRequired) {
4890
- await this._validateMethod();
4891
- } else {
4892
- await this._validateMethod();
4893
- }
4894
- if (!config.id) {
4895
- return Promise.reject(
4896
- new import_javascript10.AsgardeoAuthException(
4897
- "SPA-AUTH_CLIENT-RCG-NF01",
4898
- "The custom grant request id not found.",
4899
- "The id attribute of the custom grant config object passed as an argument should have a value."
4900
- )
4901
- );
4902
- }
4903
- const customGrantResponse = await this._client?.requestCustomGrant(config);
4904
- const customGrantCallback = this._onCustomGrant.get(config.id);
4905
- customGrantCallback && customGrantCallback(this._onCustomGrant?.get(config.id));
4906
- return customGrantResponse;
4907
- }
4908
- /**
4909
- * This method ends a user session. The access token is revoked and the session information is destroyed.
4910
- *
4911
- * **To fire a callback function after ending user session, use the `on()` method.**
4912
- * **To learn more about the `on()` method:**
4913
- * @see {@link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#on}
4914
- *
4915
- * @return {Promise<boolean>} - A promise that resolves with `true` if the process is successful.
4916
- *
4917
- * @example
4918
- * ```
4919
- * auth.endUserSession();
4920
- * ```
4921
- *
4922
- * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#endusersession
4923
- *
4924
- * @memberof AsgardeoSPAClient
4925
- *
4926
- * @preserve
4927
- */
4928
- async revokeAccessToken() {
4929
- await this._validateMethod();
4930
- const revokeAccessToken = await this._client?.revokeAccessToken();
4931
- this._onEndUserSession && await this._onEndUserSession(revokeAccessToken);
4932
- return revokeAccessToken;
4933
- }
4934
- /**
4935
- * This method returns a Promise that resolves with an object containing the service endpoints.
4936
- *
4937
- * @return {Promise<ServiceResourcesType} - A Promise that resolves with an object containing the service endpoints.
4938
- *
4939
- * @example
4940
- * ```
4941
- * auth.getServiceEndpoints().then((endpoints) => {
4942
- * // console.log(endpoints);
4943
- * }).error((error) => {
4944
- * // console.error(error);
4945
- * });
4946
- * ```
4947
- *
4948
- * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#getserviceendpoints
4949
- *
4950
- * @memberof AsgardeoSPAClient
4951
- *
4952
- * @preserve
4953
- */
4954
- async getOIDCServiceEndpoints() {
4955
- await this._isInitialized();
4956
- return this._client?.getOIDCServiceEndpoints();
4600
+ async getOpenIDProviderEndpoints() {
4601
+ await this.isInitialized();
4602
+ return this._client?.getOpenIDProviderEndpoints();
4957
4603
  }
4958
4604
  /**
4959
4605
  * This methods returns the Axios http client.
@@ -4970,13 +4616,13 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
4970
4616
  const mainThreadClient = this._client;
4971
4617
  return mainThreadClient.getHttpClient();
4972
4618
  }
4973
- throw new import_javascript10.AsgardeoAuthException(
4619
+ throw new import_javascript8.AsgardeoAuthException(
4974
4620
  "SPA-AUTH_CLIENT-GHC-IV01",
4975
4621
  "Http client cannot be returned.",
4976
4622
  "The http client cannot be returned when the storage type is set to webWorker."
4977
4623
  );
4978
4624
  }
4979
- throw new import_javascript10.AsgardeoAuthException(
4625
+ throw new import_javascript8.AsgardeoAuthException(
4980
4626
  "SPA-AUTH_CLIENT-GHC-NF02",
4981
4627
  "The SDK is not initialized.",
4982
4628
  "The SDK has not been initialized yet. Initialize the SDK using the initialize method before calling this method."
@@ -4990,7 +4636,7 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
4990
4636
  *
4991
4637
  * @example
4992
4638
  * ```
4993
- * auth.getDecodedIDToken().then((response)=>{
4639
+ * auth.getDecodedIdToken().then((response)=>{
4994
4640
  * // console.log(response);
4995
4641
  * }).catch((error)=>{
4996
4642
  * // console.error(error);
@@ -5002,9 +4648,9 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
5002
4648
  *
5003
4649
  * @preserve
5004
4650
  */
5005
- async getDecodedIDToken() {
4651
+ async getDecodedIdToken() {
5006
4652
  await this._validateMethod();
5007
- return this._client?.getDecodedIDToken();
4653
+ return this._client?.getDecodedIdToken();
5008
4654
  }
5009
4655
  /**
5010
4656
  * This method returns the IsomorphicCrypto instance.
@@ -5014,21 +4660,21 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
5014
4660
  *
5015
4661
  * @example
5016
4662
  * ```
5017
- * auth.getCryptoHelper().then((response)=>{
4663
+ * auth.getCrypto().then((response)=>{
5018
4664
  * // console.log(response);
5019
4665
  * }).catch((error)=>{
5020
4666
  * // console.error(error);
5021
4667
  * });
5022
4668
  * ```
5023
- * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#getCryptoHelper
4669
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#getCrypto
5024
4670
  *
5025
4671
  * @memberof AsgardeoSPAClient
5026
4672
  *
5027
4673
  * @preserve
5028
4674
  */
5029
- async getCryptoHelper() {
4675
+ async getCrypto() {
5030
4676
  await this._validateMethod();
5031
- return this._client?.getCryptoHelper();
4677
+ return this._client?.getCrypto();
5032
4678
  }
5033
4679
  /**
5034
4680
  * This method return the ID token.
@@ -5037,18 +4683,18 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
5037
4683
  *
5038
4684
  * @example
5039
4685
  * ```
5040
- * const idToken = await auth.getIDToken();
4686
+ * const idToken = await auth.getIdToken();
5041
4687
  * ```
5042
4688
  *
5043
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getIDToken
4689
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getIdToken
5044
4690
  *
5045
4691
  * @memberof AsgardeoAuthClient
5046
4692
  *
5047
4693
  * @preserve
5048
4694
  */
5049
- async getIDToken() {
4695
+ async getIdToken() {
5050
4696
  await this._validateMethod();
5051
- return this._client?.getIDToken();
4697
+ return this._client?.getIdToken();
5052
4698
  }
5053
4699
  /**
5054
4700
  * This method return a Promise that resolves with the access token.
@@ -5076,7 +4722,7 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
5076
4722
  await this._validateMethod();
5077
4723
  if (this._storage && [("webWorker" /* WebWorker */, "browserMemory" /* BrowserMemory */)].includes(this._storage)) {
5078
4724
  return Promise.reject(
5079
- new import_javascript10.AsgardeoAuthException(
4725
+ new import_javascript8.AsgardeoAuthException(
5080
4726
  "SPA-AUTH_CLIENT-GAT-IV01",
5081
4727
  "The access token cannot be returned.",
5082
4728
  "The access token cannot be returned when the storage type is set to webWorker or browserMemory."
@@ -5112,7 +4758,7 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
5112
4758
  await this._validateMethod();
5113
4759
  if (this._storage && [("webWorker" /* WebWorker */, "browserMemory" /* BrowserMemory */)].includes(this._storage)) {
5114
4760
  return Promise.reject(
5115
- new import_javascript10.AsgardeoAuthException(
4761
+ new import_javascript8.AsgardeoAuthException(
5116
4762
  "SPA-AUTH_CLIENT-GIAT-IV01",
5117
4763
  "The access token cannot be returned.",
5118
4764
  "The access token cannot be returned when the storage type is set to webWorker or browserMemory."
@@ -5131,7 +4777,7 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
5131
4777
  *
5132
4778
  * @example
5133
4779
  * ```
5134
- * auth.getDataLayer().then((dataLayer) => {
4780
+ * auth.getStorageManager().then((dataLayer) => {
5135
4781
  * // console.log(dataLayer);
5136
4782
  * }).catch((error) => {
5137
4783
  * // console.error(error);
@@ -5144,11 +4790,11 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
5144
4790
  *
5145
4791
  * @preserve
5146
4792
  */
5147
- async getDataLayer() {
4793
+ async getStorageManager() {
5148
4794
  await this._validateMethod();
5149
4795
  if (this._storage && [("webWorker" /* WebWorker */, "browserMemory" /* BrowserMemory */)].includes(this._storage)) {
5150
4796
  return Promise.reject(
5151
- new import_javascript10.AsgardeoAuthException(
4797
+ new import_javascript8.AsgardeoAuthException(
5152
4798
  "SPA-AUTH_CLIENT-GDL-IV01",
5153
4799
  "The data layer cannot be returned.",
5154
4800
  "The data layer cannot be returned when the storage type is set to webWorker or browserMemory."
@@ -5156,7 +4802,7 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
5156
4802
  );
5157
4803
  }
5158
4804
  const mainThreadClient = this._client;
5159
- return mainThreadClient.getDataLayer();
4805
+ return mainThreadClient.getStorageManager();
5160
4806
  }
5161
4807
  /**
5162
4808
  * This method return a Promise that resolves with the config data stored in the storage.
@@ -5215,9 +4861,9 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
5215
4861
  *
5216
4862
  * @preserve
5217
4863
  */
5218
- async isAuthenticated() {
5219
- await this._isInitialized();
5220
- return this._client?.isAuthenticated();
4864
+ async isSignedIn() {
4865
+ await this.isInitialized();
4866
+ return this._client?.isSignedIn();
5221
4867
  }
5222
4868
  /**
5223
4869
  * This method specifies if there is an active session in the browser or not.
@@ -5229,10 +4875,10 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
5229
4875
  * @preserve
5230
4876
  */
5231
4877
  async isSessionActive() {
5232
- await this._isInitialized();
4878
+ await this.isInitialized();
5233
4879
  if (this._storage && [("webWorker" /* WebWorker */, "browserMemory" /* BrowserMemory */)].includes(this._storage)) {
5234
4880
  return Promise.reject(
5235
- new import_javascript10.AsgardeoAuthException(
4881
+ new import_javascript8.AsgardeoAuthException(
5236
4882
  "SPA-AUTH_CLIENT-ISA-IV01",
5237
4883
  "The active session cannot be returned.",
5238
4884
  "The active session cannot be returned when the storage type is set to webWorker or browserMemory."
@@ -5243,7 +4889,7 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
5243
4889
  return mainThreadClient?.isSessionActive();
5244
4890
  }
5245
4891
  async on(hook, callback, id) {
5246
- await this._isInitialized();
4892
+ await this.isInitialized();
5247
4893
  if (callback && typeof callback === "function") {
5248
4894
  switch (hook) {
5249
4895
  case "sign-in" /* SignIn */:
@@ -5285,10 +4931,10 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
5285
4931
  break;
5286
4932
  }
5287
4933
  default:
5288
- throw new import_javascript10.AsgardeoAuthException("SPA-AUTH_CLIENT-ON-IV01", "Invalid hook.", "The provided hook is invalid.");
4934
+ throw new import_javascript8.AsgardeoAuthException("SPA-AUTH_CLIENT-ON-IV01", "Invalid hook.", "The provided hook is invalid.");
5289
4935
  }
5290
4936
  } else {
5291
- throw new import_javascript10.AsgardeoAuthException(
4937
+ throw new import_javascript8.AsgardeoAuthException(
5292
4938
  "SPA-AUTH_CLIENT-ON-IV02",
5293
4939
  "Invalid callback function.",
5294
4940
  "The provided callback function is invalid."
@@ -5312,7 +4958,7 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
5312
4958
  * @preserve
5313
4959
  */
5314
4960
  async enableHttpHandler() {
5315
- await this._isInitialized();
4961
+ await this.isInitialized();
5316
4962
  return this._client?.enableHttpHandler();
5317
4963
  }
5318
4964
  /**
@@ -5332,7 +4978,7 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
5332
4978
  * @preserve
5333
4979
  */
5334
4980
  async disableHttpHandler() {
5335
- await this._isInitialized();
4981
+ await this.isInitialized();
5336
4982
  return this._client?.disableHttpHandler();
5337
4983
  }
5338
4984
  /**
@@ -5343,26 +4989,26 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
5343
4989
  * @example
5344
4990
  * ```
5345
4991
  * const config = {
5346
- * signInRedirectURL: "http://localhost:3000/sign-in",
5347
- * clientID: "client ID",
4992
+ * afterSignInUrl: "http://localhost:3000/sign-in",
4993
+ * clientId: "client ID",
5348
4994
  * baseUrl: "https://api.asgardeo.io"
5349
4995
  * }
5350
- * const auth.updateConfig(config);
4996
+ * const auth.reInitialize(config);
5351
4997
  * ```
5352
- * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master/lib#updateConfig
4998
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master/lib#reInitialize
5353
4999
  *
5354
5000
  * @memberof AsgardeoAuthClient
5355
5001
  *
5356
5002
  * @preserve
5357
5003
  */
5358
- async updateConfig(config) {
5359
- await this._isInitialized();
5004
+ async reInitialize(config) {
5005
+ await this.isInitialized();
5360
5006
  if (this._storage === "webWorker" /* WebWorker */) {
5361
5007
  const client = this._client;
5362
- await client.updateConfig(config);
5008
+ await client.reInitialize(config);
5363
5009
  } else {
5364
5010
  const client = this._client;
5365
- await client.updateConfig(config);
5011
+ await client.reInitialize(config);
5366
5012
  }
5367
5013
  return;
5368
5014
  }
@@ -5374,13 +5020,371 @@ var AsgardeoSPAClient = _AsgardeoSPAClient;
5374
5020
  var import_axios2 = require("axios");
5375
5021
 
5376
5022
  // src/__legacy__/models/web-worker.ts
5377
- var WebWorkerClass = class extends Worker {
5023
+ var WebWorkerClass = class {
5378
5024
  constructor() {
5379
- super(...arguments);
5380
5025
  __publicField(this, "onmessage", () => null);
5026
+ __publicField(this, "postMessage", () => null);
5381
5027
  }
5382
5028
  };
5383
5029
 
5030
+ // src/__legacy__/worker/worker-receiver.ts
5031
+ var import_javascript10 = require("@asgardeo/javascript");
5032
+
5033
+ // src/__legacy__/worker/worker-core.ts
5034
+ var import_javascript9 = require("@asgardeo/javascript");
5035
+ var WebWorkerCore = async (config, getAuthHelper) => {
5036
+ const _store = new MemoryStore();
5037
+ const _cryptoUtils = new SPACryptoUtils();
5038
+ const _authenticationClient = new import_javascript9.AsgardeoAuthClient();
5039
+ await _authenticationClient.initialize(config, _store, _cryptoUtils);
5040
+ const _spaHelper = new SPAHelper(_authenticationClient);
5041
+ const _authenticationHelper = getAuthHelper(
5042
+ _authenticationClient,
5043
+ _spaHelper
5044
+ );
5045
+ const _dataLayer = _authenticationClient.getStorageManager();
5046
+ const _httpClient = HttpClient.getInstance();
5047
+ const attachToken = async (request) => {
5048
+ await _authenticationHelper.attachTokenToRequestConfig(request);
5049
+ };
5050
+ _httpClient?.init && await _httpClient.init(true, attachToken);
5051
+ const setHttpRequestStartCallback = (callback) => {
5052
+ _httpClient?.setHttpRequestStartCallback && _httpClient.setHttpRequestStartCallback(callback);
5053
+ };
5054
+ const setHttpRequestSuccessCallback = (callback) => {
5055
+ _httpClient?.setHttpRequestSuccessCallback && _httpClient.setHttpRequestSuccessCallback(callback);
5056
+ };
5057
+ const setHttpRequestFinishCallback = (callback) => {
5058
+ _httpClient?.setHttpRequestFinishCallback && _httpClient.setHttpRequestFinishCallback(callback);
5059
+ };
5060
+ const httpRequest = async (requestConfig) => {
5061
+ return await _authenticationHelper.httpRequest(_httpClient, requestConfig);
5062
+ };
5063
+ const httpRequestAll = async (requestConfigs) => {
5064
+ return await _authenticationHelper.httpRequestAll(requestConfigs, _httpClient);
5065
+ };
5066
+ const enableHttpHandler = () => {
5067
+ _authenticationHelper.enableHttpHandler(_httpClient);
5068
+ };
5069
+ const disableHttpHandler = () => {
5070
+ _authenticationHelper.disableHttpHandler(_httpClient);
5071
+ };
5072
+ const getSignInUrl = async (params) => {
5073
+ return _authenticationClient.getSignInUrl(params).then(async (url) => {
5074
+ const urlObject = new URL(url);
5075
+ const state = urlObject.searchParams.get(import_javascript9.OIDCRequestConstants.Params.STATE) ?? "";
5076
+ const pkce = await _authenticationClient.getPKCECode(state);
5077
+ return { authorizationURL: url, pkce };
5078
+ }).catch((error) => Promise.reject(error));
5079
+ };
5080
+ const startAutoRefreshToken = async () => {
5081
+ _spaHelper.clearRefreshTokenTimeout();
5082
+ _spaHelper.refreshAccessTokenAutomatically(_authenticationHelper);
5083
+ return;
5084
+ };
5085
+ const requestAccessToken = async (authorizationCode, sessionState, pkce, state) => {
5086
+ return await _authenticationHelper.requestAccessToken(authorizationCode, sessionState, void 0, pkce, state);
5087
+ };
5088
+ const signOut = async () => {
5089
+ _spaHelper.clearRefreshTokenTimeout();
5090
+ return await _authenticationClient.getSignOutUrl();
5091
+ };
5092
+ const getSignOutUrl = async () => {
5093
+ return await _authenticationClient.getSignOutUrl();
5094
+ };
5095
+ const exchangeToken = async (config2) => {
5096
+ return await _authenticationHelper.exchangeToken(config2);
5097
+ };
5098
+ const refreshAccessToken = async () => {
5099
+ try {
5100
+ return await _authenticationHelper.refreshAccessToken();
5101
+ } catch (error) {
5102
+ return Promise.reject(error);
5103
+ }
5104
+ };
5105
+ const revokeAccessToken = async () => {
5106
+ const timer = await _spaHelper.getRefreshTimeoutTimer();
5107
+ return _authenticationClient.revokeAccessToken().then(() => {
5108
+ _spaHelper.clearRefreshTokenTimeout(timer);
5109
+ return Promise.resolve(true);
5110
+ }).catch((error) => Promise.reject(error));
5111
+ };
5112
+ const getUser = async () => {
5113
+ return _authenticationHelper.getUser();
5114
+ };
5115
+ const getDecodedIdToken = async () => {
5116
+ return _authenticationHelper.getDecodedIdToken();
5117
+ };
5118
+ const getCrypto = async () => {
5119
+ return _authenticationHelper.getCrypto();
5120
+ };
5121
+ const getDecodedIDPIDToken = async () => {
5122
+ return _authenticationHelper.getDecodedIDPIDToken();
5123
+ };
5124
+ const getIdToken = async () => {
5125
+ return _authenticationHelper.getIdToken();
5126
+ };
5127
+ const getOpenIDProviderEndpoints = async () => {
5128
+ return _authenticationHelper.getOpenIDProviderEndpoints();
5129
+ };
5130
+ const getAccessToken = () => {
5131
+ return _authenticationHelper.getAccessToken();
5132
+ };
5133
+ const isSignedIn = () => {
5134
+ return _authenticationHelper.isSignedIn();
5135
+ };
5136
+ const setSessionState = async (sessionState) => {
5137
+ await _dataLayer.setSessionDataParameter(
5138
+ import_javascript9.OIDCRequestConstants.Params.SESSION_STATE,
5139
+ sessionState
5140
+ );
5141
+ return;
5142
+ };
5143
+ const reInitialize = async (config2) => {
5144
+ await _authenticationClient.reInitialize(config2);
5145
+ return;
5146
+ };
5147
+ const getConfigData = async () => {
5148
+ return _dataLayer.getConfigData();
5149
+ };
5150
+ return {
5151
+ disableHttpHandler,
5152
+ enableHttpHandler,
5153
+ getAccessToken,
5154
+ getSignInUrl,
5155
+ getUser,
5156
+ getConfigData,
5157
+ getCrypto,
5158
+ getDecodedIDPIDToken,
5159
+ getDecodedIdToken,
5160
+ getIdToken,
5161
+ getOpenIDProviderEndpoints,
5162
+ getSignOutUrl,
5163
+ httpRequest,
5164
+ httpRequestAll,
5165
+ isSignedIn,
5166
+ refreshAccessToken,
5167
+ requestAccessToken,
5168
+ exchangeToken,
5169
+ revokeAccessToken,
5170
+ setHttpRequestFinishCallback,
5171
+ setHttpRequestStartCallback,
5172
+ setHttpRequestSuccessCallback,
5173
+ setSessionState,
5174
+ signOut,
5175
+ startAutoRefreshToken,
5176
+ reInitialize
5177
+ };
5178
+ };
5179
+
5180
+ // src/__legacy__/worker/worker-receiver.ts
5181
+ var workerReceiver = (getAuthHelper) => {
5182
+ const ctx = self;
5183
+ let webWorker;
5184
+ ctx.onmessage = async ({ data, ports }) => {
5185
+ const port = ports[0];
5186
+ if (data.type !== INIT && !webWorker) {
5187
+ port.postMessage(
5188
+ MessageUtils.generateFailureMessage(
5189
+ new import_javascript10.AsgardeoAuthException(
5190
+ "SPA-CLIENT_WORKER-ONMSG-NF01",
5191
+ "The web worker has not been initialized yet.",
5192
+ "The initialize method needs to be called before the specified operation can be carried out."
5193
+ )
5194
+ )
5195
+ );
5196
+ return;
5197
+ }
5198
+ switch (data.type) {
5199
+ case INIT:
5200
+ try {
5201
+ const config = { ...data.data };
5202
+ webWorker = await WebWorkerCore(config, getAuthHelper);
5203
+ webWorker.setHttpRequestFinishCallback(onRequestFinishCallback);
5204
+ webWorker.setHttpRequestStartCallback(onRequestStartCallback);
5205
+ webWorker.setHttpRequestSuccessCallback(onRequestSuccessCallback);
5206
+ port.postMessage(MessageUtils.generateSuccessMessage());
5207
+ } catch (error) {
5208
+ port.postMessage(MessageUtils.generateFailureMessage(error));
5209
+ }
5210
+ break;
5211
+ case GET_AUTH_URL:
5212
+ webWorker.getSignInUrl(data?.data).then((response) => {
5213
+ port.postMessage(MessageUtils.generateSuccessMessage(response));
5214
+ }).catch((error) => {
5215
+ port.postMessage(MessageUtils.generateFailureMessage(error));
5216
+ });
5217
+ break;
5218
+ case REQUEST_ACCESS_TOKEN:
5219
+ webWorker.requestAccessToken(data?.data?.code, data?.data?.sessionState, data?.data?.pkce, data?.data?.state).then((response) => {
5220
+ port.postMessage(MessageUtils.generateSuccessMessage(response));
5221
+ }).catch((error) => {
5222
+ port.postMessage(MessageUtils.generateFailureMessage(error));
5223
+ });
5224
+ break;
5225
+ case HTTP_REQUEST: {
5226
+ const request = data.data;
5227
+ const requestData = request?.data;
5228
+ if (data.data?.data?.formData === true) {
5229
+ const formData = new FormData();
5230
+ for (const key in requestData) {
5231
+ if (key === "formData") {
5232
+ continue;
5233
+ }
5234
+ formData.append(key, requestData[key]);
5235
+ }
5236
+ request.data = formData;
5237
+ }
5238
+ webWorker.httpRequest(request).then((response) => {
5239
+ port.postMessage(MessageUtils.generateSuccessMessage(response));
5240
+ }).catch((error) => {
5241
+ port.postMessage(MessageUtils.generateFailureMessage(error));
5242
+ });
5243
+ break;
5244
+ }
5245
+ case HTTP_REQUEST_ALL:
5246
+ webWorker.httpRequestAll(data.data).then((response) => {
5247
+ port.postMessage(MessageUtils.generateSuccessMessage(response));
5248
+ }).catch((error) => {
5249
+ port.postMessage(MessageUtils.generateFailureMessage(error));
5250
+ });
5251
+ break;
5252
+ case SIGN_OUT:
5253
+ try {
5254
+ port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.signOut()));
5255
+ } catch (error) {
5256
+ port.postMessage(MessageUtils.generateFailureMessage(error));
5257
+ }
5258
+ break;
5259
+ case REQUEST_CUSTOM_GRANT:
5260
+ webWorker.exchangeToken(data.data).then((response) => {
5261
+ port.postMessage(MessageUtils.generateSuccessMessage(response));
5262
+ }).catch((error) => {
5263
+ port.postMessage(MessageUtils.generateFailureMessage(error));
5264
+ });
5265
+ break;
5266
+ case REVOKE_ACCESS_TOKEN:
5267
+ webWorker.revokeAccessToken().then((response) => {
5268
+ port.postMessage(MessageUtils.generateSuccessMessage(response));
5269
+ }).catch((error) => {
5270
+ port.postMessage(MessageUtils.generateFailureMessage(error));
5271
+ });
5272
+ break;
5273
+ case GET_OIDC_SERVICE_ENDPOINTS:
5274
+ try {
5275
+ port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getOpenIDProviderEndpoints()));
5276
+ } catch (error) {
5277
+ port.postMessage(MessageUtils.generateFailureMessage(error));
5278
+ }
5279
+ break;
5280
+ case GET_BASIC_USER_INFO:
5281
+ try {
5282
+ port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getUser()));
5283
+ } catch (error) {
5284
+ port.postMessage(MessageUtils.generateFailureMessage(error));
5285
+ }
5286
+ break;
5287
+ case GET_DECODED_ID_TOKEN:
5288
+ try {
5289
+ port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getDecodedIdToken()));
5290
+ } catch (error) {
5291
+ port.postMessage(MessageUtils.generateFailureMessage(error));
5292
+ }
5293
+ break;
5294
+ case GET_CRYPTO_HELPER:
5295
+ try {
5296
+ port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getCrypto()));
5297
+ } catch (error) {
5298
+ port.postMessage(MessageUtils.generateFailureMessage(error));
5299
+ }
5300
+ break;
5301
+ case GET_ID_TOKEN:
5302
+ try {
5303
+ port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getIdToken()));
5304
+ } catch (error) {
5305
+ port.postMessage(MessageUtils.generateFailureMessage(error));
5306
+ }
5307
+ break;
5308
+ case ENABLE_HTTP_HANDLER:
5309
+ webWorker.enableHttpHandler();
5310
+ port.postMessage(MessageUtils.generateSuccessMessage());
5311
+ break;
5312
+ case DISABLE_HTTP_HANDLER:
5313
+ webWorker.disableHttpHandler();
5314
+ port.postMessage(MessageUtils.generateSuccessMessage());
5315
+ break;
5316
+ case IS_AUTHENTICATED:
5317
+ try {
5318
+ port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.isSignedIn()));
5319
+ } catch (error) {
5320
+ port.postMessage(MessageUtils.generateFailureMessage(error));
5321
+ }
5322
+ break;
5323
+ case GET_SIGN_OUT_URL:
5324
+ try {
5325
+ port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getSignOutUrl()));
5326
+ } catch (error) {
5327
+ port.postMessage(MessageUtils.generateFailureMessage(error));
5328
+ }
5329
+ break;
5330
+ case REFRESH_ACCESS_TOKEN:
5331
+ try {
5332
+ port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.refreshAccessToken()));
5333
+ } catch (error) {
5334
+ port.postMessage(MessageUtils.generateFailureMessage(error));
5335
+ }
5336
+ break;
5337
+ case START_AUTO_REFRESH_TOKEN:
5338
+ try {
5339
+ port.postMessage(MessageUtils.generateSuccessMessage(webWorker.startAutoRefreshToken()));
5340
+ } catch (error) {
5341
+ port.postMessage(MessageUtils.generateFailureMessage(error));
5342
+ }
5343
+ break;
5344
+ case SET_SESSION_STATE:
5345
+ try {
5346
+ port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.setSessionState(data?.data)));
5347
+ } catch (error) {
5348
+ port.postMessage(MessageUtils.generateFailureMessage(error));
5349
+ }
5350
+ break;
5351
+ case UPDATE_CONFIG:
5352
+ try {
5353
+ port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.reInitialize(data?.data)));
5354
+ } catch (error) {
5355
+ port.postMessage(MessageUtils.generateFailureMessage(error));
5356
+ }
5357
+ break;
5358
+ case GET_CONFIG_DATA:
5359
+ try {
5360
+ port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getConfigData()));
5361
+ } catch (error) {
5362
+ port.postMessage(MessageUtils.generateFailureMessage(error));
5363
+ }
5364
+ break;
5365
+ default:
5366
+ port?.postMessage(
5367
+ MessageUtils.generateFailureMessage(
5368
+ new import_javascript10.AsgardeoAuthException(
5369
+ "SPA-CLIENT_WORKER-ONMSG-IV02",
5370
+ "The message type is invalid.",
5371
+ `The message type provided, ${data.type}, is invalid.`
5372
+ )
5373
+ )
5374
+ );
5375
+ }
5376
+ };
5377
+ const onRequestStartCallback = () => {
5378
+ ctx.postMessage({ type: REQUEST_START });
5379
+ };
5380
+ const onRequestSuccessCallback = (response) => {
5381
+ ctx.postMessage({ data: JSON.stringify(response ?? ""), type: REQUEST_SUCCESS });
5382
+ };
5383
+ const onRequestFinishCallback = () => {
5384
+ ctx.postMessage({ type: REQUEST_FINISH });
5385
+ };
5386
+ };
5387
+
5384
5388
  // src/constants/StyleConstants.ts
5385
5389
  var StyleConstants = class {
5386
5390
  constructor() {