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