@djb25/digit-ui-module-ws 1.0.68 → 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
@@ -17414,18 +17414,28 @@ 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
+ digiLockerFilename = _useState5[0],
17419
+ setDigiLockerFilename = _useState5[1];
17417
17420
  const user_type = Digit.SessionStorage.get("userType");
17418
17421
  const _Digit$Hooks$createTo = Digit.Hooks.createTokenAPI("document");
17419
17422
  let extraStyles = {};
17420
17423
  const handleChange = () => {
17421
- if (inpRef.current.files[0]) {
17424
+ if (inpRef.current.files && inpRef.current.files[0]) {
17422
17425
  setHasFile(true);
17423
17426
  setprevSate(inpRef.current.files[0]);
17424
- } else setHasFile(false);
17427
+ } else if (!digiLockerFilename) {
17428
+ setHasFile(false);
17429
+ }
17425
17430
  };
17426
17431
  extraStyles = getCitizenStyles("OBPS");
17427
17432
  const handleDelete = () => {
17428
17433
  inpRef.current.value = "";
17434
+ setDigiLockerFilename(null);
17435
+ setHasFile(false);
17436
+ if (props.onDocumentNumber) {
17437
+ props.onDocumentNumber("");
17438
+ }
17429
17439
  props.onDelete();
17430
17440
  };
17431
17441
  const handleEmpty = () => {
@@ -17440,8 +17450,14 @@ const UploadFileDigiLocker = props => {
17440
17450
  }
17441
17451
  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
17452
  React.useEffect(() => handleChange(), [props.message]);
17453
+ React.useEffect(() => {
17454
+ return () => {
17455
+ if (digiLockerPreviewUrl) URL.revokeObjectURL(digiLockerPreviewUrl);
17456
+ };
17457
+ }, [digiLockerPreviewUrl]);
17443
17458
  const dataURItoBlob = dataURI => {
17444
- var binary = atob(dataURI.split(",")[1]);
17459
+ var b64Data = dataURI.split(",")[1].replace(/\s/g, "");
17460
+ var binary = atob(b64Data);
17445
17461
  var array = [];
17446
17462
  for (var i = 0; i < binary.length; i++) {
17447
17463
  array.push(binary.charCodeAt(i));
@@ -17489,7 +17505,7 @@ const UploadFileDigiLocker = props => {
17489
17505
  };
17490
17506
  const aliases = DOCTYPE_ALIASES[doctype] || [doctype];
17491
17507
  let uri = res1.IssuedDoc.filter(item => aliases.some(alias => item.doctype === alias));
17492
- const _temp5 = function () {
17508
+ const _temp1 = function () {
17493
17509
  if ((uri === null || uri === void 0 ? void 0 : uri.length) > 0) {
17494
17510
  const uriStr = uri[0].uri || "";
17495
17511
  const parts = uriStr.split("-");
@@ -17502,57 +17518,166 @@ const UploadFileDigiLocker = props => {
17502
17518
  id: uriStr
17503
17519
  };
17504
17520
  const tenantId = Digit.ULBService.getCurrentTenantId() || "dl.djb";
17505
- return Promise.resolve(Digit.DigiLockerService.uri({
17521
+ return Promise.resolve(Digit.DigiLockerService.uriFile({
17506
17522
  TokenReq: TokenReqNew
17507
17523
  }, 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({
17511
- error: true,
17512
- label: "Failed to read document from DigiLocker."
17513
- });
17514
- }
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
- });
17524
+ var _res2$headers;
17525
+ console.log("[DigiLocker] uriFile response:", res2);
17526
+ let blobData = null;
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"]) || "";
17528
+ let isJsonString = contentType.includes("application/json");
17529
+ const _temp0 = function () {
17530
+ if (res2 !== null && res2 !== void 0 && res2.data) {
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
+ });
17537
+ }
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];
17532
17553
  }
17533
- });
17534
- } else {
17535
- blobData = new Blob([JSON.stringify(res2)], {
17554
+ }
17555
+ blobData = new Blob([unescaped.slice(0, outIdx)], {
17536
17556
  type: "application/pdf"
17537
17557
  });
17558
+ } else {
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"
17564
+ });
17565
+ } else {
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 () {});
17660
+ }
17661
+ }();
17662
+ if (_temp6 && _temp6.then) return _temp6.then(function () {});
17538
17663
  }
17539
17664
  }();
17540
- if (_temp && _temp.then) return _temp.then(function () {});
17665
+ if (_temp7 && _temp7.then) return _temp7.then(function () {});
17541
17666
  }
17542
17667
  }();
17543
- if (_temp2 && _temp2.then) return _temp2.then(function () {});
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
+ });
17544
17674
  }
17545
17675
  }();
17546
- return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
17547
- });
17548
- } else {
17549
- setShowToast({
17550
- error: true,
17551
- 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 () {});
17552
17677
  });
17553
17678
  }
17554
17679
  }();
17555
- if (_temp5 && _temp5.then) return _temp5.then(function () {});
17680
+ if (_temp1 && _temp1.then) return _temp1.then(function () {});
17556
17681
  });
17557
17682
  }, function (error) {
17558
17683
  console.error("DigiLocker Fetch Error:", error);
@@ -17577,6 +17702,8 @@ const UploadFileDigiLocker = props => {
17577
17702
  let newFile = new File([blobData], filename, {
17578
17703
  type: "application/pdf"
17579
17704
  });
17705
+ setDigiLockerFilename(filename);
17706
+ setHasFile(true);
17580
17707
  props.onUpload(e, newFile);
17581
17708
  };
17582
17709
  };
@@ -17653,7 +17780,7 @@ const UploadFileDigiLocker = props => {
17653
17780
  text: file[0],
17654
17781
  onClick: e => props === null || props === void 0 ? void 0 : props.removeTargetedFile(fileDetailsData, e)
17655
17782
  }));
17656
- }), !hasFile || props.error ? /*#__PURE__*/React__default.createElement("h2", {
17783
+ }), !hasFile && !props.file || props.error ? /*#__PURE__*/React__default.createElement("h2", {
17657
17784
  className: "file-upload-status"
17658
17785
  }, props.message) : /*#__PURE__*/React__default.createElement("div", {
17659
17786
  className: "tag-container",
@@ -17664,7 +17791,7 @@ const UploadFileDigiLocker = props => {
17664
17791
  }, /*#__PURE__*/React__default.createElement("span", {
17665
17792
  className: "text",
17666
17793
  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", {
17794
+ }, 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
17795
  onClick: () => handleDelete(),
17669
17796
  style: extraStyles ? (_extraStyles7 = extraStyles) === null || _extraStyles7 === void 0 ? void 0 : _extraStyles7.closeIconStyles : null
17670
17797
  }, /*#__PURE__*/React__default.createElement(Close, {
@@ -18135,6 +18262,7 @@ function SelectDocument(_ref2) {
18135
18262
  setFile(null);
18136
18263
  setIsCameraFile(false);
18137
18264
  setIsDocumentUidLocked(false);
18265
+ setDocumentUid("");
18138
18266
  },
18139
18267
  id: id,
18140
18268
  message: uploadedFile ? "1 " + t("CS_ACTION_FILEUPLOADED") : t("CS_ACTION_NO_FILEUPLOADED"),
@@ -18152,6 +18280,7 @@ function SelectDocument(_ref2) {
18152
18280
  setFile(null);
18153
18281
  setIsCameraFile(false);
18154
18282
  setIsDocumentUidLocked(false);
18283
+ setDocumentUid("");
18155
18284
  },
18156
18285
  documentType: selectedDocument === null || selectedDocument === void 0 ? void 0 : selectedDocument.code,
18157
18286
  onDocumentNumber: num => {
@@ -18164,6 +18293,8 @@ function SelectDocument(_ref2) {
18164
18293
  setUploadedFile(null);
18165
18294
  setFile(null);
18166
18295
  setIsCameraFile(false);
18296
+ setIsDocumentUidLocked(false);
18297
+ setDocumentUid("");
18167
18298
  },
18168
18299
  id: id,
18169
18300
  message: uploadedFile ? "1 " + t("CS_ACTION_FILEUPLOADED") : t("CS_ACTION_NO_FILEUPLOADED"),
@@ -18180,6 +18311,8 @@ function SelectDocument(_ref2) {
18180
18311
  setUploadedFile(null);
18181
18312
  setFile(null);
18182
18313
  setIsCameraFile(false);
18314
+ setIsDocumentUidLocked(false);
18315
+ setDocumentUid("");
18183
18316
  }
18184
18317
  })), uploadedFile && /*#__PURE__*/React__default.createElement("div", {
18185
18318
  onClick: viewDocument,
@@ -18257,6 +18390,7 @@ function SelectDocument(_ref2) {
18257
18390
  center: true,
18258
18391
  actionCancelOnSubmit: () => setShowDocModal(false),
18259
18392
  actionCancelLabel: t("CS_COMMON_CLOSE") || "Close",
18393
+ hideSubmit: true,
18260
18394
  popupStyles: {
18261
18395
  width: "80%",
18262
18396
  maxWidth: "800px"
@@ -48037,8 +48171,7 @@ const ApplicationDetails$1 = () => {
48037
48171
  })), /*#__PURE__*/React__default.createElement("div", {
48038
48172
  style: {
48039
48173
  flex: "2 1 500px",
48040
- minWidth: "300px",
48041
- overflowY: "auto"
48174
+ minWidth: "300px"
48042
48175
  }
48043
48176
  }, /*#__PURE__*/React__default.createElement(ApplicationDetails, {
48044
48177
  applicationDetails: applicationDetails,