@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.
package/dist/index.js CHANGED
@@ -17415,14 +17415,8 @@ const UploadFileDigiLocker = props => {
17415
17415
  showToast = _useState4[0],
17416
17416
  setShowToast = _useState4[1];
17417
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];
17418
+ digiLockerFilename = _useState5[0],
17419
+ setDigiLockerFilename = _useState5[1];
17426
17420
  const user_type = Digit.SessionStorage.get("userType");
17427
17421
  const _Digit$Hooks$createTo = Digit.Hooks.createTokenAPI("document");
17428
17422
  let extraStyles = {};
@@ -17437,12 +17431,11 @@ const UploadFileDigiLocker = props => {
17437
17431
  extraStyles = getCitizenStyles("OBPS");
17438
17432
  const handleDelete = () => {
17439
17433
  inpRef.current.value = "";
17440
- if (digiLockerPreviewUrl) {
17441
- URL.revokeObjectURL(digiLockerPreviewUrl);
17442
- setDigiLockerPreviewUrl(null);
17443
- }
17444
17434
  setDigiLockerFilename(null);
17445
17435
  setHasFile(false);
17436
+ if (props.onDocumentNumber) {
17437
+ props.onDocumentNumber("");
17438
+ }
17446
17439
  props.onDelete();
17447
17440
  };
17448
17441
  const handleEmpty = () => {
@@ -17512,7 +17505,7 @@ const UploadFileDigiLocker = props => {
17512
17505
  };
17513
17506
  const aliases = DOCTYPE_ALIASES[doctype] || [doctype];
17514
17507
  let uri = res1.IssuedDoc.filter(item => aliases.some(alias => item.doctype === alias));
17515
- const _temp7 = function () {
17508
+ const _temp1 = function () {
17516
17509
  if ((uri === null || uri === void 0 ? void 0 : uri.length) > 0) {
17517
17510
  const uriStr = uri[0].uri || "";
17518
17511
  const parts = uriStr.split("-");
@@ -17529,120 +17522,162 @@ const UploadFileDigiLocker = props => {
17529
17522
  TokenReq: TokenReqNew
17530
17523
  }, tenantId)).then(function (res2) {
17531
17524
  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({
17535
- error: true,
17536
- label: "Failed to read document from DigiLocker."
17537
- });
17538
- }
17539
17525
  console.log("[DigiLocker] uriFile response:", res2);
17540
17526
  let blobData = null;
17541
17527
  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
17528
  let isJsonString = contentType.includes("application/json");
17543
- const _temp5 = function () {
17529
+ const _temp0 = function () {
17544
17530
  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;
17531
+ function _temp9() {
17532
+ const filename = doctype + "_" + (uri[0].name || "document") + ".pdf";
17533
+ if (blobData && blobData.size > 0) convertToFile(e, blobData, filename);else setShowToast({
17534
+ error: true,
17535
+ label: "Failed to read document from DigiLocker."
17536
+ });
17556
17537
  }
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;
17588
- }
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);
17538
+ const _temp8 = function () {
17539
+ if (res2 !== null && res2 !== void 0 && res2.data) {
17540
+ const rawBytes = new Uint8Array(res2.data);
17541
+ const _temp7 = function () {
17542
+ if (rawBytes.length > 5 && rawBytes[0] === 0x22 && rawBytes[1] === 0x25 && rawBytes[2] === 0x50 && rawBytes[3] === 0x44 && rawBytes[4] === 0x46) {
17543
+ console.log("[DigiLocker] Response is a JSON-encoded binary PDF string. Unescaping bytes...");
17544
+ const unescaped = new Uint8Array(rawBytes.length);
17545
+ let outIdx = 0;
17546
+ for (let i = 1; i < rawBytes.length - 1; i++) {
17547
+ if (rawBytes[i] === 0x5c) {
17548
+ i++;
17549
+ const next = rawBytes[i];
17550
+ 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;
17551
+ } else {
17552
+ unescaped[outIdx++] = rawBytes[i];
17598
17553
  }
17599
17554
  }
17555
+ blobData = new Blob([unescaped.slice(0, outIdx)], {
17556
+ type: "application/pdf"
17557
+ });
17600
17558
  } else {
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
- });
17559
+ const _temp6 = function () {
17560
+ if (rawBytes.length > 4 && rawBytes[0] === 0x25 && rawBytes[1] === 0x50 && rawBytes[2] === 0x44 && rawBytes[3] === 0x46) {
17561
+ console.log("[DigiLocker] Response is a raw binary PDF.");
17562
+ blobData = new Blob([res2.data], {
17563
+ type: "application/pdf"
17610
17564
  });
17611
17565
  } 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
- }
17566
+ const decoder = new TextDecoder("utf-8");
17567
+ const textStr = decoder.decode(res2.data);
17568
+ let parsedJson = null;
17569
+ try {
17570
+ parsedJson = JSON.parse(textStr);
17571
+ } catch (e) {}
17572
+ const _temp5 = function () {
17573
+ if (parsedJson) {
17574
+ const _temp4 = function () {
17575
+ if (Array.isArray(parsedJson)) {
17576
+ console.log("[DigiLocker] Response is a JSON array of bytes.");
17577
+ const arr = new Uint8Array(parsedJson);
17578
+ blobData = new Blob([arr], {
17579
+ type: "application/pdf"
17580
+ });
17581
+ } else {
17582
+ const _temp3 = function () {
17583
+ if (typeof parsedJson === "string") {
17584
+ console.log("[DigiLocker] Response is a base64 string in JSON.");
17585
+ const dataUri = parsedJson.startsWith("data:") ? parsedJson : "data:application/pdf;base64," + parsedJson;
17586
+ try {
17587
+ blobData = dataURItoBlob(dataUri);
17588
+ } catch (e) {
17589
+ console.error("Failed to parse JSON string as base64", e);
17590
+ }
17591
+ } else {
17592
+ const _temp2 = function () {
17593
+ if (typeof parsedJson === "object") {
17594
+ const findFileStoreId = obj => {
17595
+ if (!obj || typeof obj !== "object") return null;
17596
+ for (let key in obj) {
17597
+ if (key.toLowerCase() === "filestoreid") return obj[key];
17598
+ const found = findFileStoreId(obj[key]);
17599
+ if (found) return found;
17600
+ }
17601
+ return null;
17602
+ };
17603
+ const findBase64 = obj => {
17604
+ if (!obj || typeof obj !== "object") return null;
17605
+ for (let key in obj) {
17606
+ if (["doccontent", "filecontent", "base64"].includes(key.toLowerCase())) return obj[key];
17607
+ const found = findBase64(obj[key]);
17608
+ if (found && typeof found === "string") return found;
17609
+ }
17610
+ return null;
17611
+ };
17612
+ const fsId = findFileStoreId(parsedJson);
17613
+ const _temp = function () {
17614
+ if (fsId) {
17615
+ console.log("[DigiLocker] Got fileStoreId from JSON:", fsId);
17616
+ return Promise.resolve(Digit.UploadServices.FileFetchbyid(fsId, Digit.ULBService.getStateId())).then(function (fileRes) {
17617
+ var _fileRes$headers;
17618
+ 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) || ""], {
17619
+ 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"
17620
+ });
17621
+ });
17622
+ } else {
17623
+ const b64 = findBase64(parsedJson);
17624
+ if (b64 && typeof b64 === "string") {
17625
+ console.log("[DigiLocker] Got base64 content from JSON field");
17626
+ const dataUri = b64.startsWith("data:") ? b64 : "data:application/pdf;base64," + b64;
17627
+ blobData = dataURItoBlob(dataUri);
17628
+ } else {
17629
+ console.log("[DigiLocker] JSON did not contain filestoreid or base64.");
17630
+ }
17631
+ }
17632
+ }();
17633
+ if (_temp && _temp.then) return _temp.then(function () {});
17634
+ }
17635
+ }();
17636
+ if (_temp2 && _temp2.then) return _temp2.then(function () {});
17637
+ }
17638
+ }();
17639
+ if (_temp3 && _temp3.then) return _temp3.then(function () {});
17640
+ }
17641
+ }();
17642
+ if (_temp4 && _temp4.then) return _temp4.then(function () {});
17643
+ } else {
17644
+ if (textStr.startsWith("JVBERi0x")) {
17645
+ console.log("[DigiLocker] Response is a raw base64 string.");
17646
+ try {
17647
+ blobData = dataURItoBlob("data:application/pdf;base64," + textStr);
17648
+ } catch (e) {
17649
+ console.error("Failed to parse raw text as base64", e);
17650
+ }
17651
+ } else {
17652
+ console.log("[DigiLocker] Response is unknown format, attempting binary PDF fallback.");
17653
+ blobData = new Blob([res2.data], {
17654
+ type: "application/pdf"
17655
+ });
17656
+ }
17657
+ }
17658
+ }();
17659
+ if (_temp5 && _temp5.then) return _temp5.then(function () {});
17620
17660
  }
17621
17661
  }();
17622
- if (_temp && _temp.then) return _temp.then(function () {});
17662
+ if (_temp6 && _temp6.then) return _temp6.then(function () {});
17623
17663
  }
17624
17664
  }();
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
- });
17665
+ if (_temp7 && _temp7.then) return _temp7.then(function () {});
17631
17666
  }
17632
17667
  }();
17633
- return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
17668
+ return _temp8 && _temp8.then ? _temp8.then(_temp9) : _temp9(_temp8);
17669
+ } else {
17670
+ setShowToast({
17671
+ error: true,
17672
+ label: "Selected document (" + ((props === null || props === void 0 ? void 0 : props.documentType) || doctype) + ") is not available in your DigiLocker."
17673
+ });
17634
17674
  }
17635
17675
  }();
17636
- return _temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5);
17637
- });
17638
- } else {
17639
- setShowToast({
17640
- error: true,
17641
- label: "Selected document (" + ((props === null || props === void 0 ? void 0 : props.documentType) || doctype) + ") is not available in your DigiLocker."
17676
+ if (_temp0 && _temp0.then) return _temp0.then(function () {});
17642
17677
  });
17643
17678
  }
17644
17679
  }();
17645
- if (_temp7 && _temp7.then) return _temp7.then(function () {});
17680
+ if (_temp1 && _temp1.then) return _temp1.then(function () {});
17646
17681
  });
17647
17682
  }, function (error) {
17648
17683
  console.error("DigiLocker Fetch Error:", error);
@@ -17659,8 +17694,6 @@ const UploadFileDigiLocker = props => {
17659
17694
  if (filename === void 0) {
17660
17695
  filename = "document.pdf";
17661
17696
  }
17662
- const previewUrl = URL.createObjectURL(blob);
17663
- setDigiLockerPreviewUrl(previewUrl);
17664
17697
  var reader = new FileReader();
17665
17698
  reader.readAsDataURL(blob);
17666
17699
  reader.onloadend = function () {
@@ -17735,30 +17768,7 @@ const UploadFileDigiLocker = props => {
17735
17768
  style: {
17736
17769
  width: "20px"
17737
17770
  }
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) => {
17771
+ }), 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) => {
17762
17772
  var _extraStyles3;
17763
17773
  const fileDetailsData = file[1];
17764
17774
  return /*#__PURE__*/React__default.createElement("div", {
@@ -17817,72 +17827,7 @@ const UploadFileDigiLocker = props => {
17817
17827
  warning: showToast.warning,
17818
17828
  label: t(showToast.label),
17819
17829
  onClose: () => setShowToast(null)
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
- }))));
17830
+ }));
17886
17831
  };
17887
17832
 
17888
17833
  const DIGILOCKER_SUPPORTED_CODES = ["AADHAAR", "AADHAR", "DRIVING", "DRVLC", "PAN"];
@@ -18317,6 +18262,7 @@ function SelectDocument(_ref2) {
18317
18262
  setFile(null);
18318
18263
  setIsCameraFile(false);
18319
18264
  setIsDocumentUidLocked(false);
18265
+ setDocumentUid("");
18320
18266
  },
18321
18267
  id: id,
18322
18268
  message: uploadedFile ? "1 " + t("CS_ACTION_FILEUPLOADED") : t("CS_ACTION_NO_FILEUPLOADED"),
@@ -18334,6 +18280,7 @@ function SelectDocument(_ref2) {
18334
18280
  setFile(null);
18335
18281
  setIsCameraFile(false);
18336
18282
  setIsDocumentUidLocked(false);
18283
+ setDocumentUid("");
18337
18284
  },
18338
18285
  documentType: selectedDocument === null || selectedDocument === void 0 ? void 0 : selectedDocument.code,
18339
18286
  onDocumentNumber: num => {
@@ -18346,6 +18293,8 @@ function SelectDocument(_ref2) {
18346
18293
  setUploadedFile(null);
18347
18294
  setFile(null);
18348
18295
  setIsCameraFile(false);
18296
+ setIsDocumentUidLocked(false);
18297
+ setDocumentUid("");
18349
18298
  },
18350
18299
  id: id,
18351
18300
  message: uploadedFile ? "1 " + t("CS_ACTION_FILEUPLOADED") : t("CS_ACTION_NO_FILEUPLOADED"),
@@ -18362,6 +18311,8 @@ function SelectDocument(_ref2) {
18362
18311
  setUploadedFile(null);
18363
18312
  setFile(null);
18364
18313
  setIsCameraFile(false);
18314
+ setIsDocumentUidLocked(false);
18315
+ setDocumentUid("");
18365
18316
  }
18366
18317
  })), uploadedFile && /*#__PURE__*/React__default.createElement("div", {
18367
18318
  onClick: viewDocument,
@@ -18439,6 +18390,7 @@ function SelectDocument(_ref2) {
18439
18390
  center: true,
18440
18391
  actionCancelOnSubmit: () => setShowDocModal(false),
18441
18392
  actionCancelLabel: t("CS_COMMON_CLOSE") || "Close",
18393
+ hideSubmit: true,
18442
18394
  popupStyles: {
18443
18395
  width: "80%",
18444
18396
  maxWidth: "800px"