@qlik/api 0.0.2 → 0.0.4

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 (171) hide show
  1. package/api-keys.d.mts +14 -0
  2. package/api-keys.d.ts +14 -0
  3. package/api-keys.js +14 -10
  4. package/api-keys.mjs +6 -2
  5. package/apps.d.mts +479 -149
  6. package/apps.d.ts +479 -149
  7. package/apps.js +100 -42
  8. package/apps.mjs +60 -2
  9. package/audits.d.mts +12 -0
  10. package/audits.d.ts +12 -0
  11. package/audits.js +10 -9
  12. package/audits.mjs +3 -2
  13. package/auth-AWZV4DPP.js +41 -0
  14. package/{auth-RTFXVSSK.mjs → auth-CPBNNC7S.mjs} +4 -1
  15. package/auth.js +4 -3
  16. package/auth.mjs +3 -2
  17. package/automations.d.mts +36 -0
  18. package/automations.d.ts +36 -0
  19. package/automations.js +28 -21
  20. package/automations.mjs +9 -2
  21. package/brands.d.mts +45 -4
  22. package/brands.d.ts +45 -4
  23. package/brands.js +20 -15
  24. package/brands.mjs +7 -2
  25. package/{chunk-ZT4C7KCQ.js → chunk-2STFUQKQ.js} +3 -3
  26. package/{chunk-7REWEWCX.mjs → chunk-3SVRHJII.mjs} +3 -3
  27. package/{chunk-CKPJE4IA.mjs → chunk-67GJTTPV.mjs} +1 -1
  28. package/{chunk-M7F4JFOB.js → chunk-7RY3NO6N.js} +2 -2
  29. package/{chunk-NALKLKZS.mjs → chunk-CYRLVHU3.mjs} +316 -53
  30. package/{chunk-RMKP2BDX.js → chunk-D52VW5UN.js} +318 -55
  31. package/{chunk-GUQBHY3H.mjs → chunk-GNWU6SP2.mjs} +1 -1
  32. package/{chunk-QN23TPIE.js → chunk-GV5SRHY2.js} +4 -4
  33. package/{chunk-OULT3V2U.js → chunk-JNGURO23.js} +3 -3
  34. package/chunk-P57PW2II.js +11 -0
  35. package/{chunk-3YE7EI7I.mjs → chunk-TE7XMBT5.mjs} +1 -1
  36. package/chunk-ZFXKCRJC.mjs +11 -0
  37. package/collections.d.mts +51 -17
  38. package/collections.d.ts +51 -17
  39. package/collections.js +28 -14
  40. package/collections.mjs +16 -2
  41. package/csp-origins.d.mts +16 -1
  42. package/csp-origins.d.ts +16 -1
  43. package/csp-origins.js +12 -9
  44. package/csp-origins.mjs +5 -2
  45. package/data-assets.d.mts +10 -0
  46. package/data-assets.d.ts +10 -0
  47. package/data-assets.js +13 -8
  48. package/data-assets.mjs +7 -2
  49. package/data-connections.d.mts +18 -0
  50. package/data-connections.d.ts +18 -0
  51. package/data-connections.js +19 -12
  52. package/data-connections.mjs +9 -2
  53. package/data-credentials.d.mts +8 -0
  54. package/data-credentials.d.ts +8 -0
  55. package/data-credentials.js +10 -7
  56. package/data-credentials.mjs +5 -2
  57. package/data-files.d.mts +98 -13
  58. package/data-files.d.ts +98 -13
  59. package/data-files.js +22 -15
  60. package/data-files.mjs +9 -2
  61. package/{enigma-session-VPPJMBEM.js → enigma-session-XPXDQAIV.js} +5 -4
  62. package/{enigma-session-HGXKZJVO.mjs → enigma-session-ZH6MYA54.mjs} +2 -1
  63. package/{esm-RX7B2TUN.js → esm-3VXX2GKL.js} +3 -1
  64. package/{esm-M5ZBFTVD.mjs → esm-OY4XVIJB.mjs} +3 -1
  65. package/extensions.d.mts +26 -2
  66. package/extensions.d.ts +26 -2
  67. package/extensions.js +13 -10
  68. package/extensions.mjs +5 -2
  69. package/glossaries.d.mts +55 -20
  70. package/glossaries.d.ts +55 -20
  71. package/glossaries.js +39 -27
  72. package/glossaries.mjs +14 -2
  73. package/groups.d.mts +16 -0
  74. package/groups.d.ts +16 -0
  75. package/groups.js +16 -11
  76. package/groups.mjs +7 -2
  77. package/identity-providers.d.mts +16 -0
  78. package/identity-providers.d.ts +16 -0
  79. package/identity-providers.js +14 -11
  80. package/identity-providers.mjs +5 -2
  81. package/index.js +135 -101
  82. package/index.mjs +131 -97
  83. package/{invoke-fetch-IMO4AMA3.mjs → invoke-fetch-3WZWAAZH.mjs} +4 -1
  84. package/invoke-fetch-UNTAUR7O.js +17 -0
  85. package/items.d.mts +6 -6
  86. package/items.d.ts +6 -6
  87. package/items.js +14 -11
  88. package/items.mjs +5 -2
  89. package/licenses.d.mts +18 -0
  90. package/licenses.d.ts +18 -0
  91. package/licenses.js +17 -12
  92. package/licenses.mjs +7 -2
  93. package/package.json +4 -4
  94. package/{qix-K22VHZRH.js → qix-UNWXPGMA.js} +9 -8
  95. package/{qix-57WD2ZE6.mjs → qix-ZSJ4PIK3.mjs} +3 -2
  96. package/qix.d.mts +1 -1
  97. package/qix.d.ts +1 -1
  98. package/qix.js +4 -3
  99. package/qix.mjs +3 -2
  100. package/quotas.d.mts +4 -0
  101. package/quotas.d.ts +4 -0
  102. package/quotas.js +6 -5
  103. package/quotas.mjs +3 -2
  104. package/reload-tasks.js +11 -8
  105. package/reload-tasks.mjs +5 -2
  106. package/reloads.d.mts +17 -10
  107. package/reloads.d.ts +17 -10
  108. package/reloads.js +9 -7
  109. package/reloads.mjs +4 -2
  110. package/roles.d.mts +4 -0
  111. package/roles.d.ts +4 -0
  112. package/roles.js +6 -5
  113. package/roles.mjs +3 -2
  114. package/spaces.d.mts +27 -4
  115. package/spaces.d.ts +27 -4
  116. package/spaces.js +21 -15
  117. package/spaces.mjs +8 -2
  118. package/temp-contents.d.mts +8 -3
  119. package/temp-contents.d.ts +8 -3
  120. package/temp-contents.js +8 -6
  121. package/temp-contents.mjs +4 -2
  122. package/tenants.d.mts +12 -0
  123. package/tenants.d.ts +12 -0
  124. package/tenants.js +14 -9
  125. package/tenants.mjs +7 -2
  126. package/themes.d.mts +26 -2
  127. package/themes.d.ts +26 -2
  128. package/themes.js +13 -10
  129. package/themes.mjs +5 -2
  130. package/transports.d.mts +12 -0
  131. package/transports.d.ts +12 -0
  132. package/transports.js +12 -9
  133. package/transports.mjs +5 -2
  134. package/users.d.mts +48 -29
  135. package/users.d.ts +48 -29
  136. package/users.js +18 -13
  137. package/users.mjs +7 -2
  138. package/web-integrations.d.mts +10 -0
  139. package/web-integrations.d.ts +10 -0
  140. package/web-integrations.js +11 -8
  141. package/web-integrations.mjs +5 -2
  142. package/web-notifications.d.mts +12 -0
  143. package/web-notifications.d.ts +12 -0
  144. package/web-notifications.js +12 -9
  145. package/web-notifications.mjs +5 -2
  146. package/webhooks.d.mts +25 -5
  147. package/webhooks.d.ts +25 -5
  148. package/webhooks.js +17 -13
  149. package/webhooks.mjs +6 -2
  150. package/auth-CSVTXOZX.js +0 -36
  151. package/auth-OU7OTB7Y.js +0 -38
  152. package/auth-TE272Q34.mjs +0 -36
  153. package/chunk-4ES65KO3.js +0 -57
  154. package/chunk-4FLMND6T.js +0 -25
  155. package/chunk-4OMEH5SW.mjs +0 -1337
  156. package/chunk-6JERR27K.js +0 -17
  157. package/chunk-E42WUFCK.mjs +0 -57
  158. package/chunk-H7SAZYEE.js +0 -21
  159. package/chunk-KMMWJZHM.mjs +0 -25
  160. package/chunk-W4J34XGA.mjs +0 -17
  161. package/chunk-WM7FQU2U.mjs +0 -21
  162. package/chunk-XASXL2NC.js +0 -1337
  163. package/enigma-session-4L373ALV.mjs +0 -10196
  164. package/enigma-session-TEB53FAF.js +0 -10196
  165. package/esm-4X3DKK5D.js +0 -63
  166. package/esm-SOWVJKOQ.mjs +0 -63
  167. package/invoke-fetch-7PKPQ3FD.js +0 -14
  168. package/invoke-fetch-MSSJAZ7K.mjs +0 -14
  169. package/invoke-fetch-PEI54KZO.js +0 -14
  170. package/qix-EU7PXRZ6.mjs +0 -573
  171. package/qix-RLTISYTB.js +0 -573
@@ -1,4 +1,8 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } async function _asyncOptionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/platform/platform-functions.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } async function _asyncOptionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _chunkP57PW2IIjs = require('./chunk-P57PW2II.js');
4
+
5
+ // src/platform/platform-functions.ts
2
6
  var getPlatform = async (options = {}) => {
3
7
  const isNodeEnvironment = typeof window === "undefined";
4
8
  if (isNodeEnvironment) {
@@ -175,6 +179,21 @@ var InvalidAuthTypeError = class extends Error {
175
179
  this.name = "InvalidAuthTypeError";
176
180
  }
177
181
  };
182
+ var AuthorizationError = class extends Error {
183
+ constructor(errors) {
184
+ const errorArray = Array.isArray(errors) ? errors : [errors];
185
+ super(
186
+ errorArray.map(
187
+ (error) => `
188
+ Code: ${error.code}
189
+ Status: ${error.status}
190
+ ${error.title}:
191
+ ${error.detail}
192
+ `
193
+ ).join(",\n")
194
+ );
195
+ }
196
+ };
178
197
 
179
198
  // src/auth/auth-functions.ts
180
199
  function isHostCrossOrigin(hostConfig) {
@@ -465,9 +484,17 @@ var none_default = {
465
484
  validateHostConfig: (hostConfig) => internalValidateHostConfig(hostConfig, { requiredProps: [], optionalProps: [] })
466
485
  };
467
486
 
487
+ // src/utils/utils.ts
488
+ function isBrowser() {
489
+ return typeof window === "object" && typeof window.document === "object";
490
+ }
491
+ function isNode() {
492
+ return typeof process === "object" && typeof _chunkP57PW2IIjs.__require === "function";
493
+ }
494
+
468
495
  // src/auth/internal/default-auth-modules/oauth/storage-helpers.ts
469
496
  var storagePrefix = "qlik-qmfe-api";
470
- var tokens = {};
497
+ var cachedTokens = {};
471
498
  function saveInLocalStorage(scope, name, value) {
472
499
  localStorage.setItem(`${storagePrefix}-${scope}-${name}`, value);
473
500
  }
@@ -480,11 +507,11 @@ function loadFromLocalStorage(scope, name) {
480
507
  function loadFromSessionStorage(scope, name) {
481
508
  return sessionStorage.getItem(`${storagePrefix}-${scope}-${name}`) || void 0;
482
509
  }
483
- function deleteFromLocalStorage(scope, name) {
484
- localStorage.removeItem(`${storagePrefix}-${scope}-${name}`);
510
+ function deleteFromLocalStorage(scope, names) {
511
+ names.forEach((name) => localStorage.removeItem(`${storagePrefix}-${scope}-${name}`));
485
512
  }
486
- function deleteFromSessionStorage(scope, name) {
487
- sessionStorage.removeItem(`${storagePrefix}-${scope}-${name}`);
513
+ function deleteFromSessionStorage(scope, names) {
514
+ names.forEach((name) => sessionStorage.removeItem(`${storagePrefix}-${scope}-${name}`));
488
515
  }
489
516
  function loadAndDeleteFromSessionStorage(scope, name) {
490
517
  const id = `${storagePrefix}-${scope}-${name}`;
@@ -492,43 +519,70 @@ function loadAndDeleteFromSessionStorage(scope, name) {
492
519
  sessionStorage.removeItem(id);
493
520
  return result2;
494
521
  }
495
- function loadAccessTokenFromStorage(hostConfig) {
522
+ function loadOauthTokensFromStorage(hostConfig) {
496
523
  if (!hostConfig.clientId) {
497
524
  return void 0;
498
525
  }
526
+ let accessToken;
527
+ let refreshToken;
499
528
  if (hostConfig.accessTokenStorage === "local") {
500
- return loadFromLocalStorage(hostConfig.clientId, "access-token");
529
+ accessToken = loadFromLocalStorage(hostConfig.clientId, "access-token");
530
+ refreshToken = loadFromLocalStorage(hostConfig.clientId, "refresh-token");
531
+ } else if (hostConfig.accessTokenStorage === "session") {
532
+ accessToken = loadFromSessionStorage(hostConfig.clientId, "access-token");
533
+ refreshToken = loadFromSessionStorage(hostConfig.clientId, "refresh-token");
501
534
  }
502
- if (hostConfig.accessTokenStorage === "session") {
503
- return loadFromSessionStorage(hostConfig.clientId, "access-token");
535
+ if (accessToken) {
536
+ return {
537
+ accessToken,
538
+ refreshToken
539
+ };
504
540
  }
505
541
  return void 0;
506
542
  }
507
- async function loadOrAcquireAccessToken(hostConfig, acquireToken) {
543
+ async function loadCachedOauthTokens(hostConfig) {
544
+ return cachedTokens[hostConfig.clientId];
545
+ }
546
+ async function loadOrAcquireAccessToken(hostConfig, acquireTokens) {
508
547
  if (!hostConfig.clientId) {
509
548
  throw new InvalidHostConfigError('A host config with authType set to "oauth2" has to also provide a clientId');
510
549
  }
511
- const storedToken = hostConfig.clientId ? tokens[hostConfig.clientId] || loadAccessTokenFromStorage(hostConfig) : void 0;
512
- if (storedToken) {
513
- return Promise.resolve(storedToken);
514
- }
515
- const token = acquireToken();
516
- tokens[hostConfig.clientId] = token;
517
- const awaitedToken = await token;
518
- if (hostConfig.accessTokenStorage === "local" && awaitedToken) {
519
- saveInLocalStorage(hostConfig.clientId, "access-token", awaitedToken);
520
- } else if (hostConfig.accessTokenStorage === "session" && awaitedToken) {
521
- saveInSessionStorage(hostConfig.clientId, "access-token", awaitedToken);
550
+ const mayUseStorage = isBrowser();
551
+ const storedOauthTokens = cachedTokens[hostConfig.clientId] || (mayUseStorage ? loadOauthTokensFromStorage(hostConfig) : void 0);
552
+ if (storedOauthTokens) {
553
+ return Promise.resolve(storedOauthTokens);
554
+ }
555
+ const tokensPromise = acquireTokens();
556
+ cachedTokens[hostConfig.clientId] = tokensPromise;
557
+ if (mayUseStorage) {
558
+ const tokens = await tokensPromise;
559
+ if (hostConfig.accessTokenStorage === "local" && tokens) {
560
+ if (tokens.accessToken) {
561
+ saveInLocalStorage(hostConfig.clientId, "access-token", tokens.accessToken);
562
+ }
563
+ if (tokens.refreshToken) {
564
+ saveInLocalStorage(hostConfig.clientId, "refresh-token", tokens.refreshToken);
565
+ }
566
+ } else if (hostConfig.accessTokenStorage === "session" && tokens) {
567
+ if (tokens.accessToken) {
568
+ saveInSessionStorage(hostConfig.clientId, "access-token", tokens.accessToken);
569
+ }
570
+ if (tokens.refreshToken) {
571
+ saveInSessionStorage(hostConfig.clientId, "refresh-token", tokens.refreshToken);
572
+ }
573
+ }
522
574
  }
523
- return token;
575
+ return tokensPromise;
524
576
  }
525
- function clearStoredAccessToken(hostConfig) {
577
+ function clearStoredOauthTokens(hostConfig) {
526
578
  if (!hostConfig.clientId) {
527
579
  throw new InvalidHostConfigError('A host config with authType set to "oauth2" has to also provide a clientId');
528
580
  }
529
- delete tokens[hostConfig.clientId];
530
- deleteFromLocalStorage(hostConfig.clientId, "access-token");
531
- deleteFromSessionStorage(hostConfig.clientId, "access-token");
581
+ delete cachedTokens[hostConfig.clientId];
582
+ if (isBrowser()) {
583
+ deleteFromLocalStorage(hostConfig.clientId, ["access-token", "refresh-token"]);
584
+ deleteFromSessionStorage(hostConfig.clientId, ["access-token", "refresh-token"]);
585
+ }
532
586
  }
533
587
 
534
588
  // src/auth/internal/default-auth-modules/oauth/callback.ts
@@ -575,16 +629,21 @@ function toBase64Url(uint8Array) {
575
629
  }
576
630
  function byteArrayToBase64(hashArray) {
577
631
  let result2 = "";
578
- if (typeof globalThis.Buffer !== "undefined") {
579
- result2 = Buffer.from(hashArray).toString("base64");
580
- } else if (typeof window !== "undefined" && typeof window.btoa === "function") {
632
+ if (isBrowser()) {
581
633
  const byteArrayToString = String.fromCharCode.apply(null, hashArray);
582
- result2 = window.btoa(byteArrayToString);
634
+ result2 = btoa(byteArrayToString);
635
+ } else if (isNode()) {
636
+ result2 = Buffer.from(hashArray).toString("base64");
583
637
  } else {
584
- throw new Error("Environment not supported");
638
+ throw new Error("Environment not supported for oauth2 authentication");
585
639
  }
586
640
  return result2;
587
641
  }
642
+ function handlePossibleErrors(data) {
643
+ if (data.errors) {
644
+ throw new AuthorizationError(data.errors);
645
+ }
646
+ }
588
647
  async function sha256(message) {
589
648
  const msgBuffer = new TextEncoder().encode(message);
590
649
  const hashBuffer = await globalThis.crypto.subtle.digest("SHA-256", msgBuffer);
@@ -606,7 +665,7 @@ async function startFullPageLoginFlow(hostConfig) {
606
665
  const codeChallenge = await sha256(verifier);
607
666
  const redirectUri = hostConfig.redirectUri || globalThis.location.href;
608
667
  const scopes = ["user_default"];
609
- clearStoredAccessToken(hostConfig);
668
+ clearStoredOauthTokens(hostConfig);
610
669
  saveInSessionStorage(clientId, "state", state);
611
670
  saveInSessionStorage(clientId, "verifier", verifier);
612
671
  saveInSessionStorage(clientId, "href", globalThis.location.href);
@@ -641,9 +700,11 @@ async function exchangeCodeAndVerifierForAccessTokenData(hostConfig, code, verif
641
700
  })
642
701
  });
643
702
  const data = await result2.json();
703
+ handlePossibleErrors(data);
644
704
  return {
645
705
  accessToken: data.access_token,
646
- refreshToken: data.refresh_token
706
+ refreshToken: data.refresh_token,
707
+ errors: data.errors
647
708
  };
648
709
  } catch (err) {
649
710
  console.error(err);
@@ -651,29 +712,85 @@ async function exchangeCodeAndVerifierForAccessTokenData(hostConfig, code, verif
651
712
  });
652
713
  }
653
714
  }
654
- async function getOAuthAccessTokenInternal(hostConfig) {
715
+ async function getOauthTokensWithCredentials(baseUrl, clientId, clientSecret, scope = "user_default") {
716
+ const result2 = await fetch(`${baseUrl}/oauth/token`, {
717
+ method: "POST",
718
+ mode: "cors",
719
+ headers: { "content-type": "application/json" },
720
+ body: JSON.stringify({
721
+ grant_type: "client_credentials",
722
+ client_id: clientId,
723
+ client_secret: clientSecret,
724
+ scope
725
+ })
726
+ });
727
+ const data = await result2.json();
728
+ return {
729
+ accessToken: data.access_token,
730
+ refreshToken: data.refresh_token,
731
+ errors: data.errors
732
+ };
733
+ }
734
+ async function getOauthTokensWithRefreshToken(baseUrl, refreshToken, clientSecret) {
735
+ const result2 = await fetch(`${baseUrl}/oauth/token`, {
736
+ method: "POST",
737
+ mode: "cors",
738
+ headers: { "content-type": "application/json" },
739
+ body: JSON.stringify({
740
+ grant_type: "refresh_token",
741
+ refresh_token: refreshToken,
742
+ client_secret: clientSecret
743
+ })
744
+ });
745
+ const data = await result2.json();
746
+ return {
747
+ accessToken: data.access_token,
748
+ refreshToken: data.refresh_token,
749
+ errors: data.errors
750
+ };
751
+ }
752
+ async function getOAuthTokensForNode(hostConfig) {
753
+ const { clientId, clientSecret } = hostConfig;
754
+ if (!clientId || !clientSecret) {
755
+ throw new InvalidHostConfigError(
756
+ 'A host config with authType set to "oauth2" has to provide a clientId and a clientSecret'
757
+ );
758
+ }
759
+ const oauthTokens = await loadOrAcquireAccessToken(
760
+ hostConfig,
761
+ async () => getOauthTokensWithCredentials(
762
+ toValidLocationUrl(hostConfig),
763
+ hostConfig.clientId,
764
+ // @ts-expect-error clientSecret is not yet in HostConfig type
765
+ hostConfig.clientSecret,
766
+ hostConfig.scope
767
+ )
768
+ );
769
+ return oauthTokens;
770
+ }
771
+ async function getOAuthTokensForBrowser(hostConfig) {
655
772
  const { clientId } = hostConfig;
656
773
  if (!clientId) {
657
774
  throw new InvalidHostConfigError('A host config with authType set to "oauth2" has to also provide a clientId');
658
775
  }
659
- const accessToken = await loadOrAcquireAccessToken(hostConfig, async () => {
776
+ const oauthTokens = await loadOrAcquireAccessToken(hostConfig, async () => {
660
777
  const code = loadAndDeleteFromSessionStorage(clientId, "code");
661
778
  const verifier = loadAndDeleteFromSessionStorage(clientId, "verifier");
662
779
  if (code && verifier) {
663
- const tokensResponse = await exchangeCodeAndVerifierForAccessTokenData(
780
+ const tokenResponse = await exchangeCodeAndVerifierForAccessTokenData(
664
781
  hostConfig,
665
782
  code,
666
783
  verifier,
667
784
  hostConfig.redirectUri
668
785
  );
669
- if (tokensResponse) {
670
- return tokensResponse.accessToken;
786
+ if (tokenResponse) {
787
+ return tokenResponse;
671
788
  }
672
789
  }
673
790
  return void 0;
674
791
  });
675
- if (accessToken) {
676
- return accessToken;
792
+ if (oauthTokens) {
793
+ return oauthTokens;
677
794
  }
678
795
  if (hostConfig.authRedirectUserConfirmation) {
679
796
  await hostConfig.authRedirectUserConfirmation();
@@ -682,10 +799,41 @@ async function getOAuthAccessTokenInternal(hostConfig) {
682
799
  return new Promise(() => {
683
800
  });
684
801
  }
685
- var lastOauthAccessTokenCall = Promise.resolve("");
802
+ var lastOauthTokensCall = Promise.resolve("");
686
803
  async function getOAuthAccessToken(hostConfig) {
687
- lastOauthAccessTokenCall = lastOauthAccessTokenCall.then(async () => getOAuthAccessTokenInternal(hostConfig));
688
- return lastOauthAccessTokenCall;
804
+ let getOauthTokensCall;
805
+ if (isNode()) {
806
+ getOauthTokensCall = getOAuthTokensForNode;
807
+ } else {
808
+ getOauthTokensCall = getOAuthTokensForBrowser;
809
+ }
810
+ lastOauthTokensCall = lastOauthTokensCall.then(async () => {
811
+ const tokens = await getOauthTokensCall(hostConfig);
812
+ if (tokens) {
813
+ handlePossibleErrors(tokens);
814
+ return tokens.accessToken || "";
815
+ }
816
+ return "";
817
+ });
818
+ return lastOauthTokensCall;
819
+ }
820
+ async function refreshAccessToken(hostConfig) {
821
+ const tokens = await loadCachedOauthTokens(hostConfig);
822
+ clearStoredOauthTokens(hostConfig);
823
+ if (tokens && tokens.refreshToken) {
824
+ const refreshedTokens = await loadOrAcquireAccessToken(
825
+ hostConfig,
826
+ async () => getOauthTokensWithRefreshToken(
827
+ toValidLocationUrl(hostConfig),
828
+ tokens.refreshToken,
829
+ // @ts-expect-error clientSecret is not yet in HostConfig type
830
+ hostConfig.clientSecret
831
+ )
832
+ );
833
+ if (refreshedTokens) {
834
+ handlePossibleErrors(refreshedTokens);
835
+ }
836
+ }
689
837
  }
690
838
 
691
839
  // src/auth/internal/default-auth-modules/oauth/temporary-token.ts
@@ -718,7 +866,7 @@ async function exchangeAccessTokenForTemporaryToken(hostConfig, accessToken, pur
718
866
  }
719
867
 
720
868
  // src/auth/internal/default-auth-modules/oauth.ts
721
- if (typeof window !== "undefined") {
869
+ if (isBrowser()) {
722
870
  handleOAuthCallback();
723
871
  }
724
872
  async function getRestCallAuthParams5({
@@ -757,12 +905,19 @@ async function getWebResourceAuthParams2({
757
905
  async function handleAuthenticationError5({
758
906
  hostConfig
759
907
  }) {
760
- if (hostConfig.authRedirectUserConfirmation) {
761
- await hostConfig.authRedirectUserConfirmation();
908
+ if (isBrowser()) {
909
+ if (hostConfig.authRedirectUserConfirmation) {
910
+ await hostConfig.authRedirectUserConfirmation();
911
+ }
912
+ startFullPageLoginFlow(hostConfig);
913
+ return {
914
+ preventDefault: true
915
+ };
762
916
  }
763
- startFullPageLoginFlow(hostConfig);
917
+ await refreshAccessToken(hostConfig);
764
918
  return {
765
- preventDefault: true
919
+ preventDefault: false,
920
+ retry: true
766
921
  };
767
922
  }
768
923
  var oauth_default = {
@@ -772,7 +927,7 @@ var oauth_default = {
772
927
  handleAuthenticationError: handleAuthenticationError5,
773
928
  validateHostConfig: (hostConfig) => internalValidateHostConfig(hostConfig, {
774
929
  requiredProps: ["clientId"],
775
- optionalProps: ["redirectUri", "accessTokenStorage"]
930
+ optionalProps: ["clientSecret", "redirectUri", "accessTokenStorage"]
776
931
  })
777
932
  };
778
933
 
@@ -1017,9 +1172,10 @@ async function fetchAndTransformExceptions(input, init) {
1017
1172
  return Promise.reject(new InvokeFetchError(getErrorMessage(e), 0, new Headers(), {}));
1018
1173
  }
1019
1174
  }
1020
- async function performActualHttpFetch(method, completeUrl, body, options, interceptors, authHeaders, credentials) {
1175
+ async function performActualHttpFetch(method, completeUrl, unencodedBody, contentType, options, interceptors, authHeaders, credentials) {
1176
+ const { body, contentTypeHeader, requestOptions } = encodeBody(unencodedBody, _nullishCoalesce(contentType, () => ( "")));
1021
1177
  const headers = {
1022
- "Content-Type": "application/json",
1178
+ ...contentTypeHeader,
1023
1179
  ...authHeaders,
1024
1180
  ..._optionalChain([options, 'optionalAccess', _22 => _22.headers])
1025
1181
  };
@@ -1030,8 +1186,10 @@ async function performActualHttpFetch(method, completeUrl, body, options, interc
1030
1186
  mode: isCrossOrigin ? "cors" : "same-origin",
1031
1187
  headers,
1032
1188
  redirect: await isWindows(_optionalChain([options, 'optionalAccess', _24 => _24.hostConfig])) ? "manual" : "follow",
1033
- body: body ? JSON.stringify(body) : null
1189
+ body,
1034
1190
  // body data type must match "Content-Type" header
1191
+ ...requestOptions
1192
+ // This adds 'duplex: "half"' if we're sending application/octet-stream, needed in node only.
1035
1193
  };
1036
1194
  let fetchTimeoutId;
1037
1195
  if (_optionalChain([options, 'optionalAccess', _25 => _25.timeoutMs]) && options.timeoutMs > 0) {
@@ -1054,6 +1212,98 @@ async function performActualHttpFetch(method, completeUrl, body, options, interc
1054
1212
  }
1055
1213
  return invokeFetchResponse;
1056
1214
  }
1215
+ function encodeBody(unencodedBody, contentType) {
1216
+ if (!unencodedBody) {
1217
+ return { body: null, contentTypeHeader: {}, requestOptions: {} };
1218
+ }
1219
+ const contentTypeHeader = {};
1220
+ const requestOptions = {};
1221
+ let body = null;
1222
+ switch (contentType) {
1223
+ case "":
1224
+ case "application/json":
1225
+ contentTypeHeader["Content-Type"] = "application/json";
1226
+ body = JSON.stringify(unencodedBody);
1227
+ break;
1228
+ case "multipart/form-data":
1229
+ body = encodeMultipartBody(unencodedBody);
1230
+ break;
1231
+ case "application/octet-stream":
1232
+ contentTypeHeader["Content-Type"] = contentType;
1233
+ requestOptions["duplex"] = "half";
1234
+ body = unencodedBody;
1235
+ break;
1236
+ case "text/plain":
1237
+ if (typeof unencodedBody === "string") {
1238
+ contentTypeHeader["Content-Type"] = contentType;
1239
+ body = unencodedBody;
1240
+ } else {
1241
+ throw new EncodingError(
1242
+ `Cannot send ${typeof unencodedBody} as ${contentType}, body should be a string.`,
1243
+ contentType,
1244
+ unencodedBody
1245
+ );
1246
+ }
1247
+ break;
1248
+ default:
1249
+ throw new EncodingError(
1250
+ `Unsupported content-type "${contentType}", supported are: application/json, multipart/form-data, application/octet-stream and text/plain`,
1251
+ contentType,
1252
+ unencodedBody
1253
+ );
1254
+ }
1255
+ return { body, contentTypeHeader, requestOptions };
1256
+ }
1257
+ function encodeMultipartBody(unencodedBody) {
1258
+ const contentType = "multipart/form-data";
1259
+ if (typeof unencodedBody !== "object") {
1260
+ throw new EncodingError(
1261
+ `Cannot encode ${typeof unencodedBody} as ${contentType}, body should be an object.`,
1262
+ contentType,
1263
+ unencodedBody
1264
+ );
1265
+ }
1266
+ if (Array.isArray(unencodedBody)) {
1267
+ throw new EncodingError(
1268
+ `Cannot encode ${typeof unencodedBody} as ${contentType}, body should be an object.`,
1269
+ contentType,
1270
+ unencodedBody
1271
+ );
1272
+ }
1273
+ if (unencodedBody instanceof FormData) {
1274
+ return unencodedBody;
1275
+ }
1276
+ const form = new FormData();
1277
+ Object.entries(unencodedBody).forEach((entry) => {
1278
+ const [key, value] = entry;
1279
+ switch (typeof value) {
1280
+ case "boolean":
1281
+ case "number":
1282
+ case "string":
1283
+ form.set(key, `${value}`);
1284
+ break;
1285
+ case "object":
1286
+ if (value instanceof Blob) {
1287
+ form.set(key, value);
1288
+ } else if (value instanceof Uint8Array) {
1289
+ const data = new Blob([value], { type: "application/octet-stream" });
1290
+ form.set(key, data);
1291
+ } else {
1292
+ const json = JSON.stringify(value);
1293
+ const data = new Blob([json], { type: "application/json" });
1294
+ form.set(key, data, "");
1295
+ }
1296
+ break;
1297
+ default:
1298
+ throw new EncodingError(
1299
+ `Cannot encode multipart-field "${key}" with value of type ${typeof value}, values must be objects, strings, numbers or boolean.`,
1300
+ contentType,
1301
+ unencodedBody
1302
+ );
1303
+ }
1304
+ });
1305
+ return form;
1306
+ }
1057
1307
  async function getInvokeFetchUrlParams({
1058
1308
  method,
1059
1309
  pathTemplate,
@@ -1093,7 +1343,7 @@ function invokeFetchWithUrl(api, props, interceptors) {
1093
1343
  interceptors
1094
1344
  );
1095
1345
  }
1096
- function invokeFetchWithUrlAndRetry(api, { method, completeUrl, cacheKey, body, options, authHeaders, credentials }, performRetry, interceptors) {
1346
+ function invokeFetchWithUrlAndRetry(api, { method, completeUrl, cacheKey, body, options, authHeaders, credentials, contentType }, performRetry, interceptors) {
1097
1347
  if (!cache[api]) {
1098
1348
  cache[api] = {};
1099
1349
  }
@@ -1111,6 +1361,7 @@ function invokeFetchWithUrlAndRetry(api, { method, completeUrl, cacheKey, body,
1111
1361
  method,
1112
1362
  completeUrl,
1113
1363
  body,
1364
+ contentType,
1114
1365
  options,
1115
1366
  interceptors,
1116
1367
  authHeaders,
@@ -1250,6 +1501,16 @@ var InvokeFetchError = class extends Error {
1250
1501
  this.stack = cleanStack(this.stack);
1251
1502
  }
1252
1503
  };
1504
+ var EncodingError = class extends Error {
1505
+
1506
+
1507
+ constructor(errorMessage, contentType, data) {
1508
+ super(errorMessage);
1509
+ this.contentType = contentType;
1510
+ this.data = data;
1511
+ this.stack = cleanStack(this.stack);
1512
+ }
1513
+ };
1253
1514
  var regex = /^.+\/qmfe-api(?:\.js)?:(\d+)(?::\d+)?$/gim;
1254
1515
  var isFromQmfeApi = (line) => {
1255
1516
  const matches = line.match(regex);
@@ -1339,4 +1600,6 @@ var invoke_fetch_default = invokeFetchExp;
1339
1600
 
1340
1601
 
1341
1602
 
1342
- exports.getPlatform = getPlatform; exports.InvalidHostConfigError = InvalidHostConfigError; exports.UnexpectedAuthTypeError = UnexpectedAuthTypeError; exports.InvalidAuthTypeError = InvalidAuthTypeError; exports.isHostCrossOrigin = isHostCrossOrigin; exports.isWindows = isWindows; exports.toValidLocationUrl = toValidLocationUrl; exports.toValidEnigmaLocationUrl = toValidEnigmaLocationUrl; exports.toValidWebsocketLocationUrl = toValidWebsocketLocationUrl; exports.getWebSocketAuthParams = getWebSocketAuthParams; exports.getWebResourceAuthParams = getWebResourceAuthParams; exports.handleAuthenticationError = handleAuthenticationError; exports.getRestCallAuthParams = getRestCallAuthParams; exports.registerAuthModule = registerAuthModule2; exports.setDefaultHostConfig = setDefaultHostConfig2; exports.checkForCrossDomainRequest = checkForCrossDomainRequest; exports.logout = logout; exports.InvokeFetchError = InvokeFetchError; exports.invokeFetch = invokeFetch; exports.clearApiCache = clearApiCache; exports.parseFetchResponse = parseFetchResponse; exports.invoke_fetch_default = invoke_fetch_default; exports.auth_default = auth_default;
1603
+
1604
+
1605
+ exports.getPlatform = getPlatform; exports.InvalidHostConfigError = InvalidHostConfigError; exports.UnexpectedAuthTypeError = UnexpectedAuthTypeError; exports.InvalidAuthTypeError = InvalidAuthTypeError; exports.AuthorizationError = AuthorizationError; exports.isHostCrossOrigin = isHostCrossOrigin; exports.isWindows = isWindows; exports.toValidLocationUrl = toValidLocationUrl; exports.toValidEnigmaLocationUrl = toValidEnigmaLocationUrl; exports.toValidWebsocketLocationUrl = toValidWebsocketLocationUrl; exports.getWebSocketAuthParams = getWebSocketAuthParams; exports.getWebResourceAuthParams = getWebResourceAuthParams; exports.handleAuthenticationError = handleAuthenticationError; exports.getRestCallAuthParams = getRestCallAuthParams; exports.registerAuthModule = registerAuthModule2; exports.setDefaultHostConfig = setDefaultHostConfig2; exports.checkForCrossDomainRequest = checkForCrossDomainRequest; exports.logout = logout; exports.InvokeFetchError = InvokeFetchError; exports.EncodingError = EncodingError; exports.invokeFetch = invokeFetch; exports.clearApiCache = clearApiCache; exports.parseFetchResponse = parseFetchResponse; exports.invoke_fetch_default = invoke_fetch_default; exports.auth_default = auth_default;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getAuthRuntimeModule
3
- } from "./chunk-WM7FQU2U.mjs";
3
+ } from "./chunk-3SVRHJII.mjs";
4
4
 
5
5
  // src/public/auth.ts
6
6
  function registerAuthModule(name, authModule) {
@@ -1,16 +1,16 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkH7SAZYEEjs = require('./chunk-H7SAZYEE.js');
3
+ var _chunk2STFUQKQjs = require('./chunk-2STFUQKQ.js');
4
4
 
5
5
  // src/public/auth.ts
6
6
  function registerAuthModule(name, authModule) {
7
- void _chunkH7SAZYEEjs.getAuthRuntimeModule.call(void 0, ).then((impl) => impl.registerAuthModule(name, authModule));
7
+ void _chunk2STFUQKQjs.getAuthRuntimeModule.call(void 0, ).then((impl) => impl.registerAuthModule(name, authModule));
8
8
  }
9
9
  function logout() {
10
- void _chunkH7SAZYEEjs.getAuthRuntimeModule.call(void 0, ).then((impl) => impl.logout());
10
+ void _chunk2STFUQKQjs.getAuthRuntimeModule.call(void 0, ).then((impl) => impl.logout());
11
11
  }
12
12
  function setDefaultHostConfig(hostConfig) {
13
- void _chunkH7SAZYEEjs.getAuthRuntimeModule.call(void 0, hostConfig).then((impl) => impl.setDefaultHostConfig(hostConfig));
13
+ void _chunk2STFUQKQjs.getAuthRuntimeModule.call(void 0, hostConfig).then((impl) => impl.setDefaultHostConfig(hostConfig));
14
14
  }
15
15
  var auth_default = {
16
16
  registerAuthModule,
@@ -1,14 +1,14 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkZT4C7KCQjs = require('./chunk-ZT4C7KCQ.js');
3
+ var _chunk2STFUQKQjs = require('./chunk-2STFUQKQ.js');
4
4
 
5
5
  // src/public/invoke-fetch.ts
6
6
  async function invokeFetch(api, props) {
7
7
  const hostConfig = _optionalChain([props, 'access', _ => _.options, 'optionalAccess', _2 => _2.hostConfig]);
8
- return (await _chunkZT4C7KCQjs.getInvokeFetchRuntimeModule.call(void 0, hostConfig)).invokeFetch(api, props);
8
+ return (await _chunk2STFUQKQjs.getInvokeFetchRuntimeModule.call(void 0, hostConfig)).invokeFetch(api, props);
9
9
  }
10
10
  function clearApiCache(api) {
11
- void _chunkZT4C7KCQjs.getInvokeFetchRuntimeModule.call(void 0, ).then((runtimeModule) => runtimeModule.clearApiCache(api));
11
+ void _chunk2STFUQKQjs.getInvokeFetchRuntimeModule.call(void 0, ).then((runtimeModule) => runtimeModule.clearApiCache(api));
12
12
  }
13
13
 
14
14
 
@@ -0,0 +1,11 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined")
5
+ return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+
9
+
10
+
11
+ exports.__require = __require;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getInvokeFetchRuntimeModule
3
- } from "./chunk-WM7FQU2U.mjs";
3
+ } from "./chunk-3SVRHJII.mjs";
4
4
 
5
5
  // src/public/invoke-fetch.ts
6
6
  async function invokeFetch(api, props) {
@@ -0,0 +1,11 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined")
5
+ return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+
9
+ export {
10
+ __require
11
+ };