@nibssplc/cams-sdk-react 0.0.1-beta.97 → 0.0.1-beta.99

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.cjs.js CHANGED
@@ -576,22 +576,35 @@ function arrayBufferToBase64url(buffer) {
576
576
  function register(options) {
577
577
  return __awaiter(this, void 0, void 0, function () {
578
578
  var createOptions, credential, publicKeyCredential, attestationResponse, transports, err_1;
579
- var _a, _b, _c;
580
- return __generator(this, function (_d) {
581
- switch (_d.label) {
579
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
580
+ return __generator(this, function (_k) {
581
+ switch (_k.label) {
582
582
  case 0:
583
- _d.trys.push([0, 2, , 3]);
583
+ _k.trys.push([0, 2, , 3]);
584
584
  createOptions = __assign(__assign({}, options), { challenge: base64urlToArrayBuffer(options.challenge), user: __assign(__assign({}, options.user), { id: base64urlToArrayBuffer(options.user.id) }) });
585
+ console.log("Creating credential with options:", createOptions, "...\n\n\n", options);
585
586
  return [4 /*yield*/, navigator.credentials.create({
586
- publicKey: createOptions,
587
+ publicKey: __assign(__assign({}, options), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
588
+ type: "public-key",
589
+ alg: param.alg,
590
+ }); }), attestation: (((_b = options.attestation) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "none"), authenticatorSelection: __assign(__assign({}, options.authenticatorSelection), {
591
+ // authenticatorAttachment:
592
+ // (options.authenticatorSelection?.authenticatorAttachment?.toLowerCase() ||
593
+ // "platform") as AuthenticatorAttachment,
594
+ // requireResidentKey:
595
+ // (options.authenticatorSelection?.requireResidentKey?.toLowerCase() ||
596
+ // "false") === "true",
597
+ residentKey: (((_d = (_c = options.authenticatorSelection) === null || _c === void 0 ? void 0 : _c.residentKey) === null || _d === void 0 ? void 0 : _d.toLowerCase()) ||
598
+ "discouraged"), userVerification: (((_f = (_e = options.authenticatorSelection) === null || _e === void 0 ? void 0 : _e.userVerification) === null || _f === void 0 ? void 0 : _f.toLowerCase()) ||
599
+ "preferred") }) }),
587
600
  })];
588
601
  case 1:
589
- credential = _d.sent();
602
+ credential = _k.sent();
590
603
  if (!credential)
591
604
  throw new Error("No credential created.");
592
605
  publicKeyCredential = credential;
593
606
  attestationResponse = publicKeyCredential.response;
594
- transports = (_c = (_b = (_a = publicKeyCredential.response).getTransports) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : [];
607
+ transports = (_j = (_h = (_g = publicKeyCredential.response).getTransports) === null || _h === void 0 ? void 0 : _h.call(_g)) !== null && _j !== void 0 ? _j : [];
595
608
  return [2 /*return*/, {
596
609
  id: publicKeyCredential.id,
597
610
  rawId: arrayBufferToBase64url(publicKeyCredential.rawId),
@@ -603,7 +616,7 @@ function register(options) {
603
616
  },
604
617
  }];
605
618
  case 2:
606
- err_1 = _d.sent();
619
+ err_1 = _k.sent();
607
620
  if (err_1.name === "NotAllowedError") {
608
621
  throw new Error("Registration cancelled by user.");
609
622
  }
@@ -1878,11 +1891,11 @@ var MFAOptions = function (_a) {
1878
1891
  var authenticate = useWebAuthn().authenticate;
1879
1892
  var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
1880
1893
  var options, assertionResponse, error_1;
1881
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1882
- return __generator(this, function (_o) {
1883
- switch (_o.label) {
1894
+ var _a, _b, _c, _d, _e, _f;
1895
+ return __generator(this, function (_g) {
1896
+ switch (_g.label) {
1884
1897
  case 0:
1885
- _o.trys.push([0, 4, , 5]);
1898
+ _g.trys.push([0, 4, , 5]);
1886
1899
  // 1. Fetch authentication challenge from your server
1887
1900
  console.log("Requesting authentication challenge from server...");
1888
1901
  return [4 /*yield*/, axios.post(MFAEndpoints.RetrieveAuthChallenge, {}, {
@@ -1892,20 +1905,16 @@ var MFAOptions = function (_a) {
1892
1905
  },
1893
1906
  })];
1894
1907
  case 1:
1895
- options = (_o.sent()).data;
1908
+ options = (_g.sent()).data;
1896
1909
  console.log("Received challenge:", options);
1897
- __assign(__assign({}, options), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
1898
- type: "public-key",
1899
- alg: param.alg
1900
- }); }), attestation: ((_b = options.attestation) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "none", authenticatorSelection: __assign(__assign({}, options.authenticatorSelection), { residentKey: ((_d = (_c = options.authenticatorSelection) === null || _c === void 0 ? void 0 : _c.residentKey) === null || _d === void 0 ? void 0 : _d.toLowerCase()) || "discouraged", userVerification: ((_f = (_e = options.authenticatorSelection) === null || _e === void 0 ? void 0 : _e.userVerification) === null || _f === void 0 ? void 0 : _f.toLowerCase()) || "preferred" }) });
1901
1910
  // 2. Call the SDK to trigger the browser's passkey authentication UI
1902
1911
  console.log("Calling SDK authenticate function...");
1903
- return [4 /*yield*/, authenticate(__assign(__assign({}, options), { pubKeyCredParams: (_g = options.pubKeyCredParams) === null || _g === void 0 ? void 0 : _g.map(function (param) { return ({
1912
+ return [4 /*yield*/, authenticate(__assign(__assign({}, options), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
1904
1913
  type: "public-key",
1905
1914
  alg: param.alg
1906
- }); }), attestation: ((_h = options.attestation) === null || _h === void 0 ? void 0 : _h.toLowerCase()) || "none", authenticatorSelection: __assign(__assign({}, options.authenticatorSelection), { residentKey: ((_k = (_j = options.authenticatorSelection) === null || _j === void 0 ? void 0 : _j.residentKey) === null || _k === void 0 ? void 0 : _k.toLowerCase()) || "discouraged", userVerification: ((_m = (_l = options.authenticatorSelection) === null || _l === void 0 ? void 0 : _l.userVerification) === null || _m === void 0 ? void 0 : _m.toLowerCase()) || "preferred" }) }))];
1915
+ }); }), attestation: ((_b = options.attestation) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "none", authenticatorSelection: __assign(__assign({}, options.authenticatorSelection), { residentKey: ((_d = (_c = options.authenticatorSelection) === null || _c === void 0 ? void 0 : _c.residentKey) === null || _d === void 0 ? void 0 : _d.toLowerCase()) || "discouraged", userVerification: ((_f = (_e = options.authenticatorSelection) === null || _e === void 0 ? void 0 : _e.userVerification) === null || _f === void 0 ? void 0 : _f.toLowerCase()) || "preferred" }) }))];
1907
1916
  case 2:
1908
- assertionResponse = _o.sent();
1917
+ assertionResponse = _g.sent();
1909
1918
  console.log("Authentication assertion received from client:", assertionResponse);
1910
1919
  // 3. Send the assertion back to the server for verification
1911
1920
  console.log("Sending assertion to server for verification...");
@@ -1917,11 +1926,11 @@ var MFAOptions = function (_a) {
1917
1926
  withCredentials: true, // credentials: 'include'
1918
1927
  })];
1919
1928
  case 3:
1920
- _o.sent();
1929
+ _g.sent();
1921
1930
  sonner.toast.success("🔑 Sign-in successful!");
1922
1931
  return [3 /*break*/, 5];
1923
1932
  case 4:
1924
- error_1 = _o.sent();
1933
+ error_1 = _g.sent();
1925
1934
  console.error("Authentication failed:", error_1);
1926
1935
  sonner.toast.error("❌ Could not sign in.");
1927
1936
  return [3 /*break*/, 5];