@insforge/sdk 1.4.1 → 1.4.2

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/index.mjs CHANGED
@@ -833,19 +833,32 @@ var HttpClient = class {
833
833
 
834
834
  // src/modules/auth/helpers.ts
835
835
  var PKCE_VERIFIER_KEY = "insforge_pkce_verifier";
836
+ async function getWebCrypto() {
837
+ const webCrypto = globalThis.crypto;
838
+ if (typeof webCrypto?.getRandomValues === "function" && webCrypto.subtle) {
839
+ return webCrypto;
840
+ }
841
+ if (typeof process !== "undefined" && process.versions?.node) {
842
+ const { webcrypto } = await import("crypto");
843
+ return webcrypto;
844
+ }
845
+ throw new Error("Web Crypto API is not available in this environment");
846
+ }
836
847
  function base64UrlEncode(buffer) {
837
848
  const base64 = btoa(String.fromCharCode(...buffer));
838
849
  return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
839
850
  }
840
- function generateCodeVerifier() {
851
+ async function generateCodeVerifier() {
852
+ const webCrypto = await getWebCrypto();
841
853
  const array = new Uint8Array(32);
842
- crypto.getRandomValues(array);
854
+ webCrypto.getRandomValues(array);
843
855
  return base64UrlEncode(array);
844
856
  }
845
857
  async function generateCodeChallenge(verifier) {
858
+ const webCrypto = await getWebCrypto();
846
859
  const encoder = new TextEncoder();
847
860
  const data = encoder.encode(verifier);
848
- const hash = await crypto.subtle.digest("SHA-256", data);
861
+ const hash = await webCrypto.subtle.digest("SHA-256", data);
849
862
  return base64UrlEncode(new Uint8Array(hash));
850
863
  }
851
864
  function storePkceVerifier(verifier) {
@@ -892,7 +905,7 @@ var Auth = class {
892
905
  this.http = http;
893
906
  this.tokenManager = tokenManager;
894
907
  this.options = options;
895
- this.authCallbackHandled = this.detectAuthCallback();
908
+ this.authCallbackHandled = options.detectOAuthCallback === false ? Promise.resolve() : this.detectAuthCallback();
896
909
  }
897
910
  isServerMode() {
898
911
  return !!this.options.isServerMode;
@@ -1038,7 +1051,7 @@ var Auth = class {
1038
1051
  }
1039
1052
  const { provider } = signInOptions;
1040
1053
  const providerKey = encodeURIComponent(provider.toLowerCase());
1041
- const codeVerifier = generateCodeVerifier();
1054
+ const codeVerifier = await generateCodeVerifier();
1042
1055
  const codeChallenge = await generateCodeChallenge(codeVerifier);
1043
1056
  storePkceVerifier(codeVerifier);
1044
1057
  const params = {
@@ -2760,7 +2773,8 @@ var InsForgeClient = class {
2760
2773
  this.tokenManager.setAccessToken(accessToken);
2761
2774
  }
2762
2775
  this.auth = new Auth(this.http, this.tokenManager, {
2763
- isServerMode: config.isServerMode ?? !!accessToken
2776
+ isServerMode: config.isServerMode ?? !!accessToken,
2777
+ detectOAuthCallback: config.auth?.detectOAuthCallback
2764
2778
  });
2765
2779
  this.database = new Database(this.http);
2766
2780
  this.storage = new Storage(this.http);