@nibssplc/cams-sdk-react 1.0.0-rc.40 → 1.0.0-rc.42

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.esm.js CHANGED
@@ -21,10 +21,8 @@ import axios from 'axios';
21
21
  import https from 'https';
22
22
 
23
23
  // Crypto polyfill for MSAL browser compatibility
24
- (function () {
25
- var _this = this;
26
- if (typeof window === "undefined")
27
- return;
24
+ if (typeof window !== "undefined") {
25
+ // Run immediately and synchronously
28
26
  // Ensure crypto object exists
29
27
  if (!window.crypto) {
30
28
  window.crypto = {};
@@ -39,7 +37,7 @@ import https from 'https';
39
37
  return array;
40
38
  };
41
39
  }
42
- var sha256 = function (data) { return __awaiter(_this, void 0, void 0, function () {
40
+ var sha256_1 = function (data) { return __awaiter(void 0, void 0, void 0, function () {
43
41
  var toUint8, bytes, hash, k, ml, msg, dv, high, low, i, w, j, j, s0, s1, a, b, c, d, e, f, g, h, j, S1, ch, temp1, S0, maj, temp2, result, i;
44
42
  return __generator(this, function (_a) {
45
43
  toUint8 = function (src) {
@@ -133,19 +131,19 @@ import https from 'https';
133
131
  });
134
132
  }); };
135
133
  // Store reference to original subtle if it exists
136
- var originalSubtle = window.crypto.subtle;
134
+ var originalSubtle_1 = window.crypto.subtle;
137
135
  // Create the polyfilled subtle object
138
136
  var polyfillSubtle = {
139
- digest: function (algorithm, data) { return __awaiter(_this, void 0, void 0, function () {
137
+ digest: function (algorithm, data) { return __awaiter(void 0, void 0, void 0, function () {
140
138
  var alg;
141
139
  return __generator(this, function (_a) {
142
140
  alg = typeof algorithm === "string"
143
141
  ? algorithm
144
142
  : algorithm.name;
145
143
  if (alg === "SHA-256")
146
- return [2 /*return*/, sha256(data)];
147
- if (originalSubtle === null || originalSubtle === void 0 ? void 0 : originalSubtle.digest)
148
- return [2 /*return*/, originalSubtle.digest(algorithm, data)];
144
+ return [2 /*return*/, sha256_1(data)];
145
+ if (originalSubtle_1 === null || originalSubtle_1 === void 0 ? void 0 : originalSubtle_1.digest)
146
+ return [2 /*return*/, originalSubtle_1.digest(algorithm, data)];
149
147
  throw new Error("Unsupported algorithm: ".concat(alg));
150
148
  });
151
149
  }); },
@@ -176,7 +174,7 @@ import https from 'https';
176
174
  }
177
175
  // Log success for debugging
178
176
  console.log("Crypto polyfill loaded successfully");
179
- })();
177
+ }
180
178
 
181
179
  /******************************************************************************
182
180
  Copyright (c) Microsoft Corporation.
@@ -1356,7 +1354,12 @@ function CAMSMSALProviderInner(_a) {
1356
1354
  return (jsxRuntimeExports.jsx(CAMSMSALContext.Provider, { value: value, children: children }));
1357
1355
  }
1358
1356
  function CAMSMSALProvider(props) {
1357
+ var _a;
1359
1358
  var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
1359
+ // Ensure crypto is available before creating MSAL instance
1360
+ if (typeof window !== "undefined" && !((_a = window.crypto) === null || _a === void 0 ? void 0 : _a.subtle)) {
1361
+ throw new Error("Crypto API not available. Polyfill failed to load.");
1362
+ }
1360
1363
  var instance = msalInstance || new PublicClientApplication(msalConfig);
1361
1364
  return (jsxRuntimeExports.jsx(MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSMSALProviderInner, __assign({}, props)) }));
1362
1365
  }
@@ -1449,26 +1452,20 @@ function CAMSProviderCore(props) {
1449
1452
  }
1450
1453
  });
1451
1454
  }); };
1452
- // Handle MFA completion for MSAL mode
1453
1455
  useEffect(function () {
1454
1456
  if (mode === "MSAL" &&
1455
1457
  "requiresMFA" in auth &&
1456
1458
  !auth.requiresMFA &&
1457
1459
  auth.isAuthenticated) {
1458
- // MFA completed, extract profile from localStorage
1459
1460
  var storedData = localStorage.getItem(auth.storageKey);
1460
1461
  if (storedData) {
1461
1462
  try {
1462
1463
  var parsed = JSON.parse(storedData);
1463
- console.log("Parsed storage data:", parsed);
1464
1464
  if (parsed.userProfile) {
1465
- console.log("Setting user profile:", parsed.userProfile);
1466
1465
  setUserProfile(parsed.userProfile);
1467
1466
  }
1468
1467
  }
1469
- catch (e) {
1470
- console.error("Error parsing stored data:", e);
1471
- }
1468
+ catch (_a) { }
1472
1469
  }
1473
1470
  }
1474
1471
  }, [
@@ -1485,6 +1482,7 @@ function CAMSProviderCore(props) {
1485
1482
  return jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children });
1486
1483
  }
1487
1484
  function UnifiedCAMSProvider(props) {
1485
+ var _a;
1488
1486
  // Validate appCode is a valid GUID
1489
1487
  var appCodeValidation = GuidSchema.safeParse(props.appCode);
1490
1488
  if (!appCodeValidation.success) {
@@ -1492,6 +1490,9 @@ function UnifiedCAMSProvider(props) {
1492
1490
  }
1493
1491
  if (props.mode === "MSAL") {
1494
1492
  var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
1493
+ if (typeof window !== "undefined" && !((_a = window.crypto) === null || _a === void 0 ? void 0 : _a.subtle)) {
1494
+ throw new Error("Crypto API not available. Polyfill failed to load.");
1495
+ }
1495
1496
  var instance = msalInstance || new PublicClientApplication(msalConfig);
1496
1497
  return (jsxRuntimeExports.jsx(MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSProviderCore, __assign({}, props)) }));
1497
1498
  }