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

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.
@@ -17412,14 +17412,8 @@ const UploadFileDigiLocker = props => {
17412
17412
  showToast = _useState4[0],
17413
17413
  setShowToast = _useState4[1];
17414
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];
17415
+ digiLockerFilename = _useState5[0],
17416
+ setDigiLockerFilename = _useState5[1];
17423
17417
  const user_type = Digit.SessionStorage.get("userType");
17424
17418
  const _Digit$Hooks$createTo = Digit.Hooks.createTokenAPI("document");
17425
17419
  let extraStyles = {};
@@ -17434,12 +17428,11 @@ const UploadFileDigiLocker = props => {
17434
17428
  extraStyles = getCitizenStyles("OBPS");
17435
17429
  const handleDelete = () => {
17436
17430
  inpRef.current.value = "";
17437
- if (digiLockerPreviewUrl) {
17438
- URL.revokeObjectURL(digiLockerPreviewUrl);
17439
- setDigiLockerPreviewUrl(null);
17440
- }
17441
17431
  setDigiLockerFilename(null);
17442
17432
  setHasFile(false);
17433
+ if (props.onDocumentNumber) {
17434
+ props.onDocumentNumber("");
17435
+ }
17443
17436
  props.onDelete();
17444
17437
  };
17445
17438
  const handleEmpty = () => {
@@ -17509,7 +17502,7 @@ const UploadFileDigiLocker = props => {
17509
17502
  };
17510
17503
  const aliases = DOCTYPE_ALIASES[doctype] || [doctype];
17511
17504
  let uri = res1.IssuedDoc.filter(item => aliases.some(alias => item.doctype === alias));
17512
- const _temp7 = function () {
17505
+ const _temp1 = function () {
17513
17506
  if ((uri === null || uri === void 0 ? void 0 : uri.length) > 0) {
17514
17507
  const uriStr = uri[0].uri || "";
17515
17508
  const parts = uriStr.split("-");
@@ -17526,120 +17519,162 @@ const UploadFileDigiLocker = props => {
17526
17519
  TokenReq: TokenReqNew
17527
17520
  }, tenantId)).then(function (res2) {
17528
17521
  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({
17532
- error: true,
17533
- label: "Failed to read document from DigiLocker."
17534
- });
17535
- }
17536
17522
  console.log("[DigiLocker] uriFile response:", res2);
17537
17523
  let blobData = null;
17538
17524
  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
17525
  let isJsonString = contentType.includes("application/json");
17540
- const _temp5 = function () {
17526
+ const _temp0 = function () {
17541
17527
  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;
17528
+ function _temp9() {
17529
+ const filename = doctype + "_" + (uri[0].name || "document") + ".pdf";
17530
+ if (blobData && blobData.size > 0) convertToFile(e, blobData, filename);else setShowToast({
17531
+ error: true,
17532
+ label: "Failed to read document from DigiLocker."
17533
+ });
17553
17534
  }
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;
17585
- }
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);
17535
+ const _temp8 = function () {
17536
+ if (res2 !== null && res2 !== void 0 && res2.data) {
17537
+ const rawBytes = new Uint8Array(res2.data);
17538
+ const _temp7 = function () {
17539
+ if (rawBytes.length > 5 && rawBytes[0] === 0x22 && rawBytes[1] === 0x25 && rawBytes[2] === 0x50 && rawBytes[3] === 0x44 && rawBytes[4] === 0x46) {
17540
+ console.log("[DigiLocker] Response is a JSON-encoded binary PDF string. Unescaping bytes...");
17541
+ const unescaped = new Uint8Array(rawBytes.length);
17542
+ let outIdx = 0;
17543
+ for (let i = 1; i < rawBytes.length - 1; i++) {
17544
+ if (rawBytes[i] === 0x5c) {
17545
+ i++;
17546
+ const next = rawBytes[i];
17547
+ if (next === 0x6e) unescaped[outIdx++] = 0x0a;else if (next === 0x72) unescaped[outIdx++] = 0x0d;else if (next === 0x74) unescaped[outIdx++] = 0x09;else if (next === 0x22) unescaped[outIdx++] = 0x22;else if (next === 0x5c) unescaped[outIdx++] = 0x5c;else if (next === 0x62) unescaped[outIdx++] = 0x08;else if (next === 0x66) unescaped[outIdx++] = 0x0c;else unescaped[outIdx++] = next;
17548
+ } else {
17549
+ unescaped[outIdx++] = rawBytes[i];
17595
17550
  }
17596
17551
  }
17552
+ blobData = new Blob([unescaped.slice(0, outIdx)], {
17553
+ type: "application/pdf"
17554
+ });
17597
17555
  } else {
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
- });
17556
+ const _temp6 = function () {
17557
+ if (rawBytes.length > 4 && rawBytes[0] === 0x25 && rawBytes[1] === 0x50 && rawBytes[2] === 0x44 && rawBytes[3] === 0x46) {
17558
+ console.log("[DigiLocker] Response is a raw binary PDF.");
17559
+ blobData = new Blob([res2.data], {
17560
+ type: "application/pdf"
17607
17561
  });
17608
17562
  } 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
- }
17563
+ const decoder = new TextDecoder("utf-8");
17564
+ const textStr = decoder.decode(res2.data);
17565
+ let parsedJson = null;
17566
+ try {
17567
+ parsedJson = JSON.parse(textStr);
17568
+ } catch (e) {}
17569
+ const _temp5 = function () {
17570
+ if (parsedJson) {
17571
+ const _temp4 = function () {
17572
+ if (Array.isArray(parsedJson)) {
17573
+ console.log("[DigiLocker] Response is a JSON array of bytes.");
17574
+ const arr = new Uint8Array(parsedJson);
17575
+ blobData = new Blob([arr], {
17576
+ type: "application/pdf"
17577
+ });
17578
+ } else {
17579
+ const _temp3 = function () {
17580
+ if (typeof parsedJson === "string") {
17581
+ console.log("[DigiLocker] Response is a base64 string in JSON.");
17582
+ const dataUri = parsedJson.startsWith("data:") ? parsedJson : "data:application/pdf;base64," + parsedJson;
17583
+ try {
17584
+ blobData = dataURItoBlob(dataUri);
17585
+ } catch (e) {
17586
+ console.error("Failed to parse JSON string as base64", e);
17587
+ }
17588
+ } else {
17589
+ const _temp2 = function () {
17590
+ if (typeof parsedJson === "object") {
17591
+ const findFileStoreId = obj => {
17592
+ if (!obj || typeof obj !== "object") return null;
17593
+ for (let key in obj) {
17594
+ if (key.toLowerCase() === "filestoreid") return obj[key];
17595
+ const found = findFileStoreId(obj[key]);
17596
+ if (found) return found;
17597
+ }
17598
+ return null;
17599
+ };
17600
+ const findBase64 = obj => {
17601
+ if (!obj || typeof obj !== "object") return null;
17602
+ for (let key in obj) {
17603
+ if (["doccontent", "filecontent", "base64"].includes(key.toLowerCase())) return obj[key];
17604
+ const found = findBase64(obj[key]);
17605
+ if (found && typeof found === "string") return found;
17606
+ }
17607
+ return null;
17608
+ };
17609
+ const fsId = findFileStoreId(parsedJson);
17610
+ const _temp = function () {
17611
+ if (fsId) {
17612
+ console.log("[DigiLocker] Got fileStoreId from JSON:", fsId);
17613
+ return Promise.resolve(Digit.UploadServices.FileFetchbyid(fsId, Digit.ULBService.getStateId())).then(function (fileRes) {
17614
+ var _fileRes$headers;
17615
+ 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) || ""], {
17616
+ 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"
17617
+ });
17618
+ });
17619
+ } else {
17620
+ const b64 = findBase64(parsedJson);
17621
+ if (b64 && typeof b64 === "string") {
17622
+ console.log("[DigiLocker] Got base64 content from JSON field");
17623
+ const dataUri = b64.startsWith("data:") ? b64 : "data:application/pdf;base64," + b64;
17624
+ blobData = dataURItoBlob(dataUri);
17625
+ } else {
17626
+ console.log("[DigiLocker] JSON did not contain filestoreid or base64.");
17627
+ }
17628
+ }
17629
+ }();
17630
+ if (_temp && _temp.then) return _temp.then(function () {});
17631
+ }
17632
+ }();
17633
+ if (_temp2 && _temp2.then) return _temp2.then(function () {});
17634
+ }
17635
+ }();
17636
+ if (_temp3 && _temp3.then) return _temp3.then(function () {});
17637
+ }
17638
+ }();
17639
+ if (_temp4 && _temp4.then) return _temp4.then(function () {});
17640
+ } else {
17641
+ if (textStr.startsWith("JVBERi0x")) {
17642
+ console.log("[DigiLocker] Response is a raw base64 string.");
17643
+ try {
17644
+ blobData = dataURItoBlob("data:application/pdf;base64," + textStr);
17645
+ } catch (e) {
17646
+ console.error("Failed to parse raw text as base64", e);
17647
+ }
17648
+ } else {
17649
+ console.log("[DigiLocker] Response is unknown format, attempting binary PDF fallback.");
17650
+ blobData = new Blob([res2.data], {
17651
+ type: "application/pdf"
17652
+ });
17653
+ }
17654
+ }
17655
+ }();
17656
+ if (_temp5 && _temp5.then) return _temp5.then(function () {});
17617
17657
  }
17618
17658
  }();
17619
- if (_temp && _temp.then) return _temp.then(function () {});
17659
+ if (_temp6 && _temp6.then) return _temp6.then(function () {});
17620
17660
  }
17621
17661
  }();
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
- });
17662
+ if (_temp7 && _temp7.then) return _temp7.then(function () {});
17628
17663
  }
17629
17664
  }();
17630
- return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
17665
+ return _temp8 && _temp8.then ? _temp8.then(_temp9) : _temp9(_temp8);
17666
+ } else {
17667
+ setShowToast({
17668
+ error: true,
17669
+ label: "Selected document (" + ((props === null || props === void 0 ? void 0 : props.documentType) || doctype) + ") is not available in your DigiLocker."
17670
+ });
17631
17671
  }
17632
17672
  }();
17633
- return _temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5);
17634
- });
17635
- } else {
17636
- setShowToast({
17637
- error: true,
17638
- label: "Selected document (" + ((props === null || props === void 0 ? void 0 : props.documentType) || doctype) + ") is not available in your DigiLocker."
17673
+ if (_temp0 && _temp0.then) return _temp0.then(function () {});
17639
17674
  });
17640
17675
  }
17641
17676
  }();
17642
- if (_temp7 && _temp7.then) return _temp7.then(function () {});
17677
+ if (_temp1 && _temp1.then) return _temp1.then(function () {});
17643
17678
  });
17644
17679
  }, function (error) {
17645
17680
  console.error("DigiLocker Fetch Error:", error);
@@ -17656,8 +17691,6 @@ const UploadFileDigiLocker = props => {
17656
17691
  if (filename === void 0) {
17657
17692
  filename = "document.pdf";
17658
17693
  }
17659
- const previewUrl = URL.createObjectURL(blob);
17660
- setDigiLockerPreviewUrl(previewUrl);
17661
17694
  var reader = new FileReader();
17662
17695
  reader.readAsDataURL(blob);
17663
17696
  reader.onloadend = function () {
@@ -17732,30 +17765,7 @@ const UploadFileDigiLocker = props => {
17732
17765
  style: {
17733
17766
  width: "20px"
17734
17767
  }
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) => {
17768
+ }), 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) => {
17759
17769
  var _extraStyles3;
17760
17770
  const fileDetailsData = file[1];
17761
17771
  return /*#__PURE__*/React.createElement("div", {
@@ -17814,72 +17824,7 @@ const UploadFileDigiLocker = props => {
17814
17824
  warning: showToast.warning,
17815
17825
  label: t(showToast.label),
17816
17826
  onClose: () => setShowToast(null)
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
- }))));
17827
+ }));
17883
17828
  };
17884
17829
 
17885
17830
  const DIGILOCKER_SUPPORTED_CODES = ["AADHAAR", "AADHAR", "DRIVING", "DRVLC", "PAN"];
@@ -18314,6 +18259,7 @@ function SelectDocument(_ref2) {
18314
18259
  setFile(null);
18315
18260
  setIsCameraFile(false);
18316
18261
  setIsDocumentUidLocked(false);
18262
+ setDocumentUid("");
18317
18263
  },
18318
18264
  id: id,
18319
18265
  message: uploadedFile ? "1 " + t("CS_ACTION_FILEUPLOADED") : t("CS_ACTION_NO_FILEUPLOADED"),
@@ -18331,6 +18277,7 @@ function SelectDocument(_ref2) {
18331
18277
  setFile(null);
18332
18278
  setIsCameraFile(false);
18333
18279
  setIsDocumentUidLocked(false);
18280
+ setDocumentUid("");
18334
18281
  },
18335
18282
  documentType: selectedDocument === null || selectedDocument === void 0 ? void 0 : selectedDocument.code,
18336
18283
  onDocumentNumber: num => {
@@ -18343,6 +18290,8 @@ function SelectDocument(_ref2) {
18343
18290
  setUploadedFile(null);
18344
18291
  setFile(null);
18345
18292
  setIsCameraFile(false);
18293
+ setIsDocumentUidLocked(false);
18294
+ setDocumentUid("");
18346
18295
  },
18347
18296
  id: id,
18348
18297
  message: uploadedFile ? "1 " + t("CS_ACTION_FILEUPLOADED") : t("CS_ACTION_NO_FILEUPLOADED"),
@@ -18359,6 +18308,8 @@ function SelectDocument(_ref2) {
18359
18308
  setUploadedFile(null);
18360
18309
  setFile(null);
18361
18310
  setIsCameraFile(false);
18311
+ setIsDocumentUidLocked(false);
18312
+ setDocumentUid("");
18362
18313
  }
18363
18314
  })), uploadedFile && /*#__PURE__*/React.createElement("div", {
18364
18315
  onClick: viewDocument,
@@ -18436,6 +18387,7 @@ function SelectDocument(_ref2) {
18436
18387
  center: true,
18437
18388
  actionCancelOnSubmit: () => setShowDocModal(false),
18438
18389
  actionCancelLabel: t("CS_COMMON_CLOSE") || "Close",
18390
+ hideSubmit: true,
18439
18391
  popupStyles: {
18440
18392
  width: "80%",
18441
18393
  maxWidth: "800px"