@djb25/digit-ui-module-ws 1.0.68 → 1.0.69

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.js CHANGED
@@ -17414,18 +17414,35 @@ const UploadFileDigiLocker = props => {
17414
17414
  const _useState4 = React.useState(null),
17415
17415
  showToast = _useState4[0],
17416
17416
  setShowToast = _useState4[1];
17417
+ const _useState5 = React.useState(null),
17418
+ digiLockerPreviewUrl = _useState5[0],
17419
+ setDigiLockerPreviewUrl = _useState5[1];
17420
+ const _useState6 = React.useState(false),
17421
+ showDigiLockerPreview = _useState6[0],
17422
+ setShowDigiLockerPreview = _useState6[1];
17423
+ const _useState7 = React.useState(null),
17424
+ digiLockerFilename = _useState7[0],
17425
+ setDigiLockerFilename = _useState7[1];
17417
17426
  const user_type = Digit.SessionStorage.get("userType");
17418
17427
  const _Digit$Hooks$createTo = Digit.Hooks.createTokenAPI("document");
17419
17428
  let extraStyles = {};
17420
17429
  const handleChange = () => {
17421
- if (inpRef.current.files[0]) {
17430
+ if (inpRef.current.files && inpRef.current.files[0]) {
17422
17431
  setHasFile(true);
17423
17432
  setprevSate(inpRef.current.files[0]);
17424
- } else setHasFile(false);
17433
+ } else if (!digiLockerFilename) {
17434
+ setHasFile(false);
17435
+ }
17425
17436
  };
17426
17437
  extraStyles = getCitizenStyles("OBPS");
17427
17438
  const handleDelete = () => {
17428
17439
  inpRef.current.value = "";
17440
+ if (digiLockerPreviewUrl) {
17441
+ URL.revokeObjectURL(digiLockerPreviewUrl);
17442
+ setDigiLockerPreviewUrl(null);
17443
+ }
17444
+ setDigiLockerFilename(null);
17445
+ setHasFile(false);
17429
17446
  props.onDelete();
17430
17447
  };
17431
17448
  const handleEmpty = () => {
@@ -17440,8 +17457,14 @@ const UploadFileDigiLocker = props => {
17440
17457
  }
17441
17458
  React.useEffect(() => handleEmpty(), [inpRef === null || inpRef === void 0 ? void 0 : (_inpRef$current = inpRef.current) === null || _inpRef$current === void 0 ? void 0 : _inpRef$current.files]);
17442
17459
  React.useEffect(() => handleChange(), [props.message]);
17460
+ React.useEffect(() => {
17461
+ return () => {
17462
+ if (digiLockerPreviewUrl) URL.revokeObjectURL(digiLockerPreviewUrl);
17463
+ };
17464
+ }, [digiLockerPreviewUrl]);
17443
17465
  const dataURItoBlob = dataURI => {
17444
- var binary = atob(dataURI.split(",")[1]);
17466
+ var b64Data = dataURI.split(",")[1].replace(/\s/g, "");
17467
+ var binary = atob(b64Data);
17445
17468
  var array = [];
17446
17469
  for (var i = 0; i < binary.length; i++) {
17447
17470
  array.push(binary.charCodeAt(i));
@@ -17489,7 +17512,7 @@ const UploadFileDigiLocker = props => {
17489
17512
  };
17490
17513
  const aliases = DOCTYPE_ALIASES[doctype] || [doctype];
17491
17514
  let uri = res1.IssuedDoc.filter(item => aliases.some(alias => item.doctype === alias));
17492
- const _temp5 = function () {
17515
+ const _temp7 = function () {
17493
17516
  if ((uri === null || uri === void 0 ? void 0 : uri.length) > 0) {
17494
17517
  const uriStr = uri[0].uri || "";
17495
17518
  const parts = uriStr.split("-");
@@ -17502,48 +17525,115 @@ const UploadFileDigiLocker = props => {
17502
17525
  id: uriStr
17503
17526
  };
17504
17527
  const tenantId = Digit.ULBService.getCurrentTenantId() || "dl.djb";
17505
- return Promise.resolve(Digit.DigiLockerService.uri({
17528
+ return Promise.resolve(Digit.DigiLockerService.uriFile({
17506
17529
  TokenReq: TokenReqNew
17507
17530
  }, tenantId)).then(function (res2) {
17508
- function _temp4() {
17509
- let filename = doctype + "_" + (uri[0].name || "document") + ".pdf";
17510
- if (blobData) convertToFile(e, blobData, filename);else setShowToast({
17531
+ var _res2$headers;
17532
+ function _temp6() {
17533
+ const filename = doctype + "_" + (uri[0].name || "document") + ".pdf";
17534
+ if (blobData && blobData.size > 0) convertToFile(e, blobData, filename);else setShowToast({
17511
17535
  error: true,
17512
17536
  label: "Failed to read document from DigiLocker."
17513
17537
  });
17514
17538
  }
17515
- let blobData;
17516
- const _temp3 = function () {
17517
- if (typeof res2 === "string" && res2.includes("base64")) {
17518
- blobData = dataURItoBlob(res2);
17519
- } else {
17520
- const _temp2 = function () {
17521
- if (res2 instanceof Blob) {
17522
- blobData = res2;
17523
- } else {
17524
- const _temp = function () {
17525
- if (res2 && typeof res2 === "object" && res2.fileStoreId) {
17526
- return Promise.resolve(Digit.UploadServices.FileFetchbyid(res2.fileStoreId, Digit.ULBService.getStateId())).then(function (fileRes) {
17527
- if (fileRes !== null && fileRes !== void 0 && fileRes.data) {
17528
- var _fileRes$headers;
17529
- blobData = fileRes.data instanceof Blob ? fileRes.data : new Blob([fileRes.data], {
17530
- type: ((_fileRes$headers = fileRes.headers) === null || _fileRes$headers === void 0 ? void 0 : _fileRes$headers["content-type"]) || "application/pdf"
17531
- });
17539
+ console.log("[DigiLocker] uriFile response:", res2);
17540
+ let blobData = null;
17541
+ let contentType = (res2 === null || res2 === void 0 ? void 0 : (_res2$headers = res2.headers) === null || _res2$headers === void 0 ? void 0 : _res2$headers["content-type"]) || "";
17542
+ let isJsonString = contentType.includes("application/json");
17543
+ const _temp5 = function () {
17544
+ if (res2 !== null && res2 !== void 0 && res2.data) {
17545
+ function _temp4() {
17546
+ if (!blobData) {
17547
+ console.log("[DigiLocker] Treating response as raw binary PDF fallback.");
17548
+ blobData = new Blob([(res2 === null || res2 === void 0 ? void 0 : res2.data) || res2], {
17549
+ type: "application/pdf"
17550
+ });
17551
+ }
17552
+ }
17553
+ const firstBytes = new Uint8Array(res2.data, 0, 3);
17554
+ if (firstBytes[0] === 34 && firstBytes[1] === 37 && firstBytes[2] === 80) {
17555
+ isJsonString = true;
17556
+ }
17557
+ const _temp3 = function () {
17558
+ if (isJsonString) {
17559
+ const decoder = new TextDecoder("utf-8");
17560
+ const jsonString = decoder.decode(res2.data);
17561
+ const jsonObj = JSON.parse(jsonString);
17562
+ const findFileStoreId = obj => {
17563
+ if (!obj || typeof obj !== "object") return null;
17564
+ for (let key in obj) {
17565
+ if (key.toLowerCase() === "filestoreid") return obj[key];
17566
+ const found = findFileStoreId(obj[key]);
17567
+ if (found) return found;
17568
+ }
17569
+ return null;
17570
+ };
17571
+ const findBase64 = obj => {
17572
+ if (!obj || typeof obj !== "object") return null;
17573
+ for (let key in obj) {
17574
+ if (["doccontent", "filecontent", "base64"].includes(key.toLowerCase())) return obj[key];
17575
+ const found = findBase64(obj[key]);
17576
+ if (found && typeof found === "string") return found;
17577
+ }
17578
+ return null;
17579
+ };
17580
+ const _temp2 = function () {
17581
+ if (typeof jsonObj === "string") {
17582
+ if (jsonObj.startsWith("%PDF")) {
17583
+ console.log("[DigiLocker] Response is a literal PDF string. Trying to salvage corrupted bytes...");
17584
+ const len = jsonObj.length;
17585
+ const arr = new Uint8Array(len);
17586
+ for (let i = 0; i < len; i++) {
17587
+ arr[i] = jsonObj.charCodeAt(i) & 0xFF;
17532
17588
  }
17533
- });
17589
+ blobData = new Blob([arr], {
17590
+ type: "application/pdf"
17591
+ });
17592
+ } else {
17593
+ const dataUri = jsonObj.startsWith("data:") ? jsonObj : "data:application/pdf;base64," + jsonObj;
17594
+ try {
17595
+ blobData = dataURItoBlob(dataUri);
17596
+ } catch (e) {
17597
+ console.error("Failed to parse string as base64", e);
17598
+ }
17599
+ }
17534
17600
  } else {
17535
- blobData = new Blob([JSON.stringify(res2)], {
17536
- type: "application/pdf"
17537
- });
17601
+ const fsId = findFileStoreId(jsonObj);
17602
+ const _temp = function () {
17603
+ if (fsId) {
17604
+ console.log("[DigiLocker] Got fileStoreId from JSON:", fsId);
17605
+ return Promise.resolve(Digit.UploadServices.FileFetchbyid(fsId, Digit.ULBService.getStateId())).then(function (fileRes) {
17606
+ var _fileRes$headers;
17607
+ blobData = (fileRes === null || fileRes === void 0 ? void 0 : fileRes.data) instanceof Blob ? fileRes.data : new Blob([(fileRes === null || fileRes === void 0 ? void 0 : fileRes.data) || ""], {
17608
+ type: (fileRes === null || fileRes === void 0 ? void 0 : (_fileRes$headers = fileRes.headers) === null || _fileRes$headers === void 0 ? void 0 : _fileRes$headers["content-type"]) || "application/pdf"
17609
+ });
17610
+ });
17611
+ } else {
17612
+ const b64 = findBase64(jsonObj);
17613
+ if (b64 && typeof b64 === "string") {
17614
+ console.log("[DigiLocker] Got base64 content from JSON field");
17615
+ const dataUri = b64.startsWith("data:") ? b64 : "data:application/pdf;base64," + b64;
17616
+ blobData = dataURItoBlob(dataUri);
17617
+ } else {
17618
+ console.log("[DigiLocker] JSON did not contain filestoreid or base64.");
17619
+ }
17620
+ }
17621
+ }();
17622
+ if (_temp && _temp.then) return _temp.then(function () {});
17538
17623
  }
17539
17624
  }();
17540
- if (_temp && _temp.then) return _temp.then(function () {});
17625
+ if (_temp2 && _temp2.then) return _temp2.then(function () {});
17626
+ } else {
17627
+ console.log("[DigiLocker] Treating response as raw binary PDF.", contentType);
17628
+ blobData = new Blob([res2.data], {
17629
+ type: "application/pdf"
17630
+ });
17541
17631
  }
17542
17632
  }();
17543
- if (_temp2 && _temp2.then) return _temp2.then(function () {});
17633
+ return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
17544
17634
  }
17545
17635
  }();
17546
- return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
17636
+ return _temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5);
17547
17637
  });
17548
17638
  } else {
17549
17639
  setShowToast({
@@ -17552,7 +17642,7 @@ const UploadFileDigiLocker = props => {
17552
17642
  });
17553
17643
  }
17554
17644
  }();
17555
- if (_temp5 && _temp5.then) return _temp5.then(function () {});
17645
+ if (_temp7 && _temp7.then) return _temp7.then(function () {});
17556
17646
  });
17557
17647
  }, function (error) {
17558
17648
  console.error("DigiLocker Fetch Error:", error);
@@ -17569,6 +17659,8 @@ const UploadFileDigiLocker = props => {
17569
17659
  if (filename === void 0) {
17570
17660
  filename = "document.pdf";
17571
17661
  }
17662
+ const previewUrl = URL.createObjectURL(blob);
17663
+ setDigiLockerPreviewUrl(previewUrl);
17572
17664
  var reader = new FileReader();
17573
17665
  reader.readAsDataURL(blob);
17574
17666
  reader.onloadend = function () {
@@ -17577,6 +17669,8 @@ const UploadFileDigiLocker = props => {
17577
17669
  let newFile = new File([blobData], filename, {
17578
17670
  type: "application/pdf"
17579
17671
  });
17672
+ setDigiLockerFilename(filename);
17673
+ setHasFile(true);
17580
17674
  props.onUpload(e, newFile);
17581
17675
  };
17582
17676
  };
@@ -17641,7 +17735,30 @@ const UploadFileDigiLocker = props => {
17641
17735
  style: {
17642
17736
  width: "20px"
17643
17737
  }
17644
- }), t("CS_COMMON_FETCH_FROM_DIGILOCKER")))), props === null || props === void 0 ? void 0 : (_props$uploadedFiles = props.uploadedFiles) === null || _props$uploadedFiles === void 0 ? void 0 : _props$uploadedFiles.map((file, index) => {
17738
+ }), t("CS_COMMON_FETCH_FROM_DIGILOCKER"))), digiLockerPreviewUrl && /*#__PURE__*/React__default.createElement("button", {
17739
+ type: "button",
17740
+ title: t("WS_VIEW_DOCUMENT") || "Preview document",
17741
+ onClick: () => setShowDigiLockerPreview(true),
17742
+ style: {
17743
+ background: "none",
17744
+ border: "none",
17745
+ cursor: "pointer",
17746
+ display: "flex",
17747
+ alignItems: "center",
17748
+ padding: "4px"
17749
+ }
17750
+ }, /*#__PURE__*/React__default.createElement("svg", {
17751
+ xmlns: "http://www.w3.org/2000/svg",
17752
+ height: "22",
17753
+ viewBox: "0 0 24 24",
17754
+ width: "22",
17755
+ fill: "#00497e"
17756
+ }, /*#__PURE__*/React__default.createElement("path", {
17757
+ d: "M0 0h24v24H0z",
17758
+ fill: "none"
17759
+ }), /*#__PURE__*/React__default.createElement("path", {
17760
+ d: "M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"
17761
+ })))), props === null || props === void 0 ? void 0 : (_props$uploadedFiles = props.uploadedFiles) === null || _props$uploadedFiles === void 0 ? void 0 : _props$uploadedFiles.map((file, index) => {
17645
17762
  var _extraStyles3;
17646
17763
  const fileDetailsData = file[1];
17647
17764
  return /*#__PURE__*/React__default.createElement("div", {
@@ -17653,7 +17770,7 @@ const UploadFileDigiLocker = props => {
17653
17770
  text: file[0],
17654
17771
  onClick: e => props === null || props === void 0 ? void 0 : props.removeTargetedFile(fileDetailsData, e)
17655
17772
  }));
17656
- }), !hasFile || props.error ? /*#__PURE__*/React__default.createElement("h2", {
17773
+ }), !hasFile && !props.file || props.error ? /*#__PURE__*/React__default.createElement("h2", {
17657
17774
  className: "file-upload-status"
17658
17775
  }, props.message) : /*#__PURE__*/React__default.createElement("div", {
17659
17776
  className: "tag-container",
@@ -17664,7 +17781,7 @@ const UploadFileDigiLocker = props => {
17664
17781
  }, /*#__PURE__*/React__default.createElement("span", {
17665
17782
  className: "text",
17666
17783
  style: extraStyles ? (_extraStyles6 = extraStyles) === null || _extraStyles6 === void 0 ? void 0 : _extraStyles6.textStyles : null
17667
- }, typeof ((_inpRef$current$files = inpRef.current.files[0]) === null || _inpRef$current$files === void 0 ? void 0 : _inpRef$current$files.name) !== "undefined" && !(props !== null && props !== void 0 && props.file) ? (_inpRef$current$files2 = inpRef.current.files[0]) === null || _inpRef$current$files2 === void 0 ? void 0 : _inpRef$current$files2.name : (_props$file = props.file) === null || _props$file === void 0 ? void 0 : _props$file.name), /*#__PURE__*/React__default.createElement("span", {
17784
+ }, digiLockerFilename ? digiLockerFilename : typeof ((_inpRef$current$files = inpRef.current.files[0]) === null || _inpRef$current$files === void 0 ? void 0 : _inpRef$current$files.name) !== "undefined" && !(props !== null && props !== void 0 && props.file) ? (_inpRef$current$files2 = inpRef.current.files[0]) === null || _inpRef$current$files2 === void 0 ? void 0 : _inpRef$current$files2.name : (_props$file = props.file) === null || _props$file === void 0 ? void 0 : _props$file.name), /*#__PURE__*/React__default.createElement("span", {
17668
17785
  onClick: () => handleDelete(),
17669
17786
  style: extraStyles ? (_extraStyles7 = extraStyles) === null || _extraStyles7 === void 0 ? void 0 : _extraStyles7.closeIconStyles : null
17670
17787
  }, /*#__PURE__*/React__default.createElement(Close, {
@@ -17700,7 +17817,72 @@ const UploadFileDigiLocker = props => {
17700
17817
  warning: showToast.warning,
17701
17818
  label: t(showToast.label),
17702
17819
  onClose: () => setShowToast(null)
17703
- }));
17820
+ }), showDigiLockerPreview && digiLockerPreviewUrl && /*#__PURE__*/React__default.createElement("div", {
17821
+ style: {
17822
+ position: "fixed",
17823
+ top: 0,
17824
+ left: 0,
17825
+ width: "100%",
17826
+ height: "100%",
17827
+ backgroundColor: "rgba(0,0,0,0.7)",
17828
+ zIndex: 9999,
17829
+ display: "flex",
17830
+ flexDirection: "column",
17831
+ alignItems: "center",
17832
+ justifyContent: "center"
17833
+ },
17834
+ onClick: () => setShowDigiLockerPreview(false)
17835
+ }, /*#__PURE__*/React__default.createElement("div", {
17836
+ style: {
17837
+ background: "#fff",
17838
+ borderRadius: "8px",
17839
+ width: "85%",
17840
+ maxWidth: "860px",
17841
+ overflow: "hidden",
17842
+ boxShadow: "0 8px 32px rgba(0,0,0,0.4)"
17843
+ },
17844
+ onClick: ev => ev.stopPropagation()
17845
+ }, /*#__PURE__*/React__default.createElement("div", {
17846
+ style: {
17847
+ display: "flex",
17848
+ justifyContent: "space-between",
17849
+ alignItems: "center",
17850
+ padding: "12px 16px",
17851
+ background: "#00497e"
17852
+ }
17853
+ }, /*#__PURE__*/React__default.createElement("span", {
17854
+ style: {
17855
+ color: "#fff",
17856
+ fontWeight: "bold",
17857
+ fontSize: "14px"
17858
+ }
17859
+ }, t("WS_VIEW_DOCUMENT") || "View Document"), /*#__PURE__*/React__default.createElement("button", {
17860
+ type: "button",
17861
+ onClick: () => setShowDigiLockerPreview(false),
17862
+ style: {
17863
+ background: "none",
17864
+ border: "none",
17865
+ cursor: "pointer",
17866
+ padding: "4px"
17867
+ }
17868
+ }, /*#__PURE__*/React__default.createElement("svg", {
17869
+ xmlns: "http://www.w3.org/2000/svg",
17870
+ viewBox: "0 0 24 24",
17871
+ fill: "#fff",
17872
+ width: "22",
17873
+ height: "22"
17874
+ }, /*#__PURE__*/React__default.createElement("path", {
17875
+ d: "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"
17876
+ })))), /*#__PURE__*/React__default.createElement("embed", {
17877
+ src: digiLockerPreviewUrl,
17878
+ type: "application/pdf",
17879
+ width: "100%",
17880
+ height: "520px",
17881
+ style: {
17882
+ border: "none",
17883
+ display: "block"
17884
+ }
17885
+ }))));
17704
17886
  };
17705
17887
 
17706
17888
  const DIGILOCKER_SUPPORTED_CODES = ["AADHAAR", "AADHAR", "DRIVING", "DRVLC", "PAN"];
@@ -48037,8 +48219,7 @@ const ApplicationDetails$1 = () => {
48037
48219
  })), /*#__PURE__*/React__default.createElement("div", {
48038
48220
  style: {
48039
48221
  flex: "2 1 500px",
48040
- minWidth: "300px",
48041
- overflowY: "auto"
48222
+ minWidth: "300px"
48042
48223
  }
48043
48224
  }, /*#__PURE__*/React__default.createElement(ApplicationDetails, {
48044
48225
  applicationDetails: applicationDetails,