@asgardeo/auth-spa 0.2.13 → 0.2.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +9 -4
  2. package/dist/asgardeo-spa.production.esm.js +10 -10
  3. package/dist/asgardeo-spa.production.esm.js.map +1 -1
  4. package/dist/asgardeo-spa.production.js +7 -7
  5. package/dist/asgardeo-spa.production.js.map +1 -1
  6. package/dist/asgardeo-spa.production.min.js +1 -1
  7. package/dist/asgardeo-spa.production.min.js.map +1 -1
  8. package/dist/polyfilled/asgardeo-spa.production.esm.js +35 -35
  9. package/dist/polyfilled/asgardeo-spa.production.esm.js.map +1 -1
  10. package/dist/polyfilled/asgardeo-spa.production.js +35 -35
  11. package/dist/polyfilled/asgardeo-spa.production.js.map +1 -1
  12. package/dist/polyfilled/asgardeo-spa.production.min.js +1 -1
  13. package/dist/polyfilled/asgardeo-spa.production.min.js.map +1 -1
  14. package/dist/src/client.js.map +1 -1
  15. package/dist/src/clients/main-thread-client.d.ts.map +1 -1
  16. package/dist/src/clients/main-thread-client.js +131 -54
  17. package/dist/src/clients/main-thread-client.js.map +1 -1
  18. package/dist/src/clients/web-worker-client.d.ts.map +1 -1
  19. package/dist/src/clients/web-worker-client.js +42 -19
  20. package/dist/src/clients/web-worker-client.js.map +1 -1
  21. package/dist/src/constants/parameters.d.ts +1 -0
  22. package/dist/src/constants/parameters.d.ts.map +1 -1
  23. package/dist/src/constants/parameters.js +1 -0
  24. package/dist/src/constants/parameters.js.map +1 -1
  25. package/dist/src/models/client.d.ts +2 -2
  26. package/dist/src/models/client.d.ts.map +1 -1
  27. package/dist/src/models/http-client.d.ts +1 -1
  28. package/dist/src/models/http-client.d.ts.map +1 -1
  29. package/dist/src/models/web-worker.d.ts +1 -2
  30. package/dist/src/models/web-worker.d.ts.map +1 -1
  31. package/dist/src/worker/client.worker.d.ts.map +1 -1
  32. package/dist/src/worker/client.worker.js +1 -7
  33. package/dist/src/worker/client.worker.js.map +1 -1
  34. package/dist/src/worker/worker-core.d.ts.map +1 -1
  35. package/dist/src/worker/worker-core.js +20 -7
  36. package/dist/src/worker/worker-core.js.map +1 -1
  37. package/dist/tsconfig.tsbuildinfo +1 -1
  38. package/package.json +6 -6
  39. package/src/client.ts +1 -1
  40. package/src/clients/main-thread-client.ts +156 -77
  41. package/src/clients/web-worker-client.ts +50 -24
  42. package/src/constants/parameters.ts +1 -0
  43. package/src/models/client.ts +2 -2
  44. package/src/models/http-client.ts +1 -1
  45. package/src/models/web-worker.ts +1 -2
  46. package/src/worker/client.worker.ts +3 -12
  47. package/src/worker/worker-core.ts +20 -8
@@ -28,6 +28,7 @@ import {
28
28
  Store,
29
29
  TokenResponse
30
30
  } from "@asgardeo/auth-js";
31
+ import { CUSTOM_GRANT_CONFIG } from "../constants";
31
32
  import { AsgardeoSPAException } from "../exception";
32
33
  import { SPAHelper } from "../helpers";
33
34
  import { HttpClient, HttpClientInstance } from "../http-client";
@@ -81,10 +82,6 @@ export const WebWorkerCore = async (
81
82
  _httpClient?.setHttpRequestFinishCallback && _httpClient.setHttpRequestFinishCallback(callback);
82
83
  };
83
84
 
84
- const setHttpRequestErrorCallback = (callback: (error: HttpError) => void): void => {
85
- _httpClient?.setHttpRequestErrorCallback && _httpClient.setHttpRequestErrorCallback(callback);
86
- };
87
-
88
85
  const httpRequest = async (requestConfig: HttpRequestConfig): Promise<HttpResponse> => {
89
86
  let matches = false;
90
87
  const config = await _dataLayer.getConfigData();
@@ -107,9 +104,8 @@ export const WebWorkerCore = async (
107
104
  return Promise.resolve(response);
108
105
  })
109
106
  .catch((error: HttpError) => {
110
- if (error?.response?.status === 401) {
111
- return _authenticationClient
112
- .refreshAccessToken()
107
+ if (error?.response?.status === 401 || !error?.response) {
108
+ return refreshAccessToken()
113
109
  .then(() => {
114
110
  return _httpClient
115
111
  .request(requestConfig)
@@ -327,6 +323,9 @@ export const WebWorkerCore = async (
327
323
  }
328
324
  }
329
325
 
326
+ if(config.shouldReplayAfterRefresh) {
327
+ _dataLayer.setTemporaryDataParameter(CUSTOM_GRANT_CONFIG, JSON.stringify(config));
328
+ }
330
329
  if (useDefaultEndpoint || matches) {
331
330
  return _authenticationClient
332
331
  .requestCustomGrant(config)
@@ -361,6 +360,11 @@ export const WebWorkerCore = async (
361
360
  return _authenticationClient
362
361
  .refreshAccessToken()
363
362
  .then(() => {
363
+ getCustomGrantConfigData().then((customGrantConfig) => {
364
+ if(customGrantConfig) {
365
+ requestCustomGrant(customGrantConfig)
366
+ }
367
+ });
364
368
  _spaHelper.refreshAccessTokenAutomatically();
365
369
 
366
370
  return _authenticationClient.getBasicUserInfo();
@@ -420,6 +424,15 @@ export const WebWorkerCore = async (
420
424
  return _dataLayer.getConfigData();
421
425
  };
422
426
 
427
+ const getCustomGrantConfigData = async (): Promise<AuthClientConfig<CustomGrantConfig> | null> => {
428
+ const configString = await _dataLayer.getTemporaryDataParameter(CUSTOM_GRANT_CONFIG);
429
+ if(configString) {
430
+ return JSON.parse(configString as string);
431
+ } else {
432
+ return null
433
+ }
434
+ };
435
+
423
436
  return {
424
437
  disableHttpHandler,
425
438
  enableHttpHandler,
@@ -438,7 +451,6 @@ export const WebWorkerCore = async (
438
451
  requestAccessToken,
439
452
  requestCustomGrant,
440
453
  revokeAccessToken,
441
- setHttpRequestErrorCallback,
442
454
  setHttpRequestFinishCallback,
443
455
  setHttpRequestStartCallback,
444
456
  setHttpRequestSuccessCallback,