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