@finsys/core 2.2.0 → 2.3.1

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.cjs CHANGED
@@ -33,6 +33,7 @@ __export(index_exports, {
33
33
  BASE_FIELD_SPECS: () => BASE_FIELD_SPECS,
34
34
  BasicFormField: () => BasicFormField,
35
35
  DEFAULT_VALIDATOR_DEFINITIONS: () => DEFAULT_VALIDATOR_DEFINITIONS,
36
+ DocExtractionStatus: () => DocExtractionStatus,
36
37
  ExtractionFileType: () => ExtractionFileType,
37
38
  ExtractionJobStatus: () => ExtractionJobStatus,
38
39
  FIELD_TYPE_DEFINITIONS: () => FIELD_TYPE_DEFINITIONS,
@@ -58,6 +59,7 @@ __export(index_exports, {
58
59
  getCategoryName: () => getCategoryName,
59
60
  getDisplayName: () => getDisplayName,
60
61
  getDisplayNames: () => getDisplayNames,
62
+ getGroupDisplayNames: () => getGroupDisplayNames,
61
63
  getPastMonthLabel: () => getPastMonthLabel,
62
64
  getPastYearLabel: () => getPastYearLabel,
63
65
  getStepDefaultValues: () => getStepDefaultValues,
@@ -67,6 +69,7 @@ __export(index_exports, {
67
69
  groupFieldsByCategory: () => groupFieldsByCategory,
68
70
  groupFieldsByPattern: () => groupFieldsByPattern,
69
71
  processIhsDetails: () => processIhsDetails,
72
+ resolveExtractionStatus: () => resolveExtractionStatus,
70
73
  resolvePageFields: () => resolvePageFields,
71
74
  validateFormConfig: () => validateFormConfig,
72
75
  validateFormSpec: () => validateFormSpec,
@@ -9426,6 +9429,9 @@ var GROUP_DISPLAY_NAMES = {
9426
9429
  ssm_documents: "SSM Company Information",
9427
9430
  ic_documents: "Identification Card"
9428
9431
  };
9432
+ function getGroupDisplayNames() {
9433
+ return GROUP_DISPLAY_NAMES;
9434
+ }
9429
9435
  function isNumericField(fieldName) {
9430
9436
  const patterns = [
9431
9437
  "balance",
@@ -9568,9 +9574,12 @@ function processIhsDetails(ihsData) {
9568
9574
  const specs = getBaseFieldSpecs();
9569
9575
  const fileColumnSet = /* @__PURE__ */ new Set();
9570
9576
  for (const field of specs) {
9571
- if (field.type === "file" && field.ihs_column_names) {
9572
- for (const col of field.ihs_column_names) {
9573
- fileColumnSet.add(col);
9577
+ if (field.type === "file") {
9578
+ if (field.name) fileColumnSet.add(field.name);
9579
+ if (field.ihs_column_names) {
9580
+ for (const col of field.ihs_column_names) {
9581
+ fileColumnSet.add(col);
9582
+ }
9574
9583
  }
9575
9584
  }
9576
9585
  }
@@ -9642,11 +9651,163 @@ var ExtractionFileType = /* @__PURE__ */ ((ExtractionFileType2) => {
9642
9651
  ExtractionFileType2["Ic"] = "ic";
9643
9652
  return ExtractionFileType2;
9644
9653
  })(ExtractionFileType || {});
9654
+
9655
+ // src/extraction-status.ts
9656
+ var DocExtractionStatus = /* @__PURE__ */ ((DocExtractionStatus2) => {
9657
+ DocExtractionStatus2["NotUploaded"] = "not_uploaded";
9658
+ DocExtractionStatus2["Uploaded"] = "uploaded";
9659
+ DocExtractionStatus2["Queued"] = "queued";
9660
+ DocExtractionStatus2["Processing"] = "processing";
9661
+ DocExtractionStatus2["Extracted"] = "extracted";
9662
+ DocExtractionStatus2["Failed"] = "failed";
9663
+ DocExtractionStatus2["Unknown"] = "unknown";
9664
+ return DocExtractionStatus2;
9665
+ })(DocExtractionStatus || {});
9666
+ var FILE_TYPE_TO_GROUP = {
9667
+ ["bankStatements" /* BankStatement */]: "bank_statements",
9668
+ ["financialStatements" /* FinancialStatement */]: "financials",
9669
+ ["epfStatements" /* Epf */]: "epf_statements",
9670
+ ["payslips" /* Payslip */]: "payslip_statements",
9671
+ ["ssm" /* Ssm */]: "ssm_documents",
9672
+ ["form9" /* Form9 */]: "form9",
9673
+ ["ic" /* Ic */]: "ic_documents"
9674
+ };
9675
+ var _specs = getBaseFieldSpecs();
9676
+ var _fileFields = _specs.filter((f) => f.type === "file" && f.ihs_column_names?.length);
9677
+ var _grouped = groupFieldsByPattern(_fileFields);
9678
+ var _groupDisplayNames = getGroupDisplayNames();
9679
+ function isPopulated(value) {
9680
+ if (value === null || value === void 0 || value === "") return false;
9681
+ if (value === "Not Specified") return false;
9682
+ return true;
9683
+ }
9684
+ function countUploadedFiles(ihsRecord, aggregateKey) {
9685
+ const raw = ihsRecord[aggregateKey];
9686
+ if (!raw) return 0;
9687
+ if (typeof raw === "string") {
9688
+ try {
9689
+ const parsed = JSON.parse(raw);
9690
+ if (Array.isArray(parsed)) return parsed.length;
9691
+ } catch {
9692
+ return 1;
9693
+ }
9694
+ }
9695
+ if (Array.isArray(raw)) return raw.length;
9696
+ return 1;
9697
+ }
9698
+ function getPopulatedColumns(columns, ihsRecord) {
9699
+ return columns.filter((col) => isPopulated(ihsRecord[col]));
9700
+ }
9701
+ function resolveDocStatus(columns, ihsRecord, uploaded, jobRecord, hasJobRecords) {
9702
+ const populated = getPopulatedColumns(columns, ihsRecord);
9703
+ const hasExtractedData = populated.length > 0;
9704
+ let status;
9705
+ let errorMessage;
9706
+ if (!uploaded) {
9707
+ status = "not_uploaded" /* NotUploaded */;
9708
+ } else if (hasJobRecords) {
9709
+ if (jobRecord) {
9710
+ if (jobRecord.status === "queued" /* Queued */) {
9711
+ status = "queued" /* Queued */;
9712
+ } else if (jobRecord.status === "processing" /* Processing */) {
9713
+ status = "processing" /* Processing */;
9714
+ } else if (jobRecord.status === "failed" /* Failed */) {
9715
+ if (hasExtractedData) {
9716
+ status = "extracted" /* Extracted */;
9717
+ errorMessage = jobRecord.errorMessage;
9718
+ } else {
9719
+ status = "failed" /* Failed */;
9720
+ errorMessage = jobRecord.errorMessage;
9721
+ }
9722
+ } else if (jobRecord.status === "succeeded" /* Succeeded */ || hasExtractedData) {
9723
+ status = "extracted" /* Extracted */;
9724
+ } else {
9725
+ status = "uploaded" /* Uploaded */;
9726
+ }
9727
+ } else if (hasExtractedData) {
9728
+ status = "extracted" /* Extracted */;
9729
+ } else {
9730
+ status = "uploaded" /* Uploaded */;
9731
+ }
9732
+ } else if (hasExtractedData) {
9733
+ status = "extracted" /* Extracted */;
9734
+ } else {
9735
+ status = "unknown" /* Unknown */;
9736
+ }
9737
+ return { status, errorMessage };
9738
+ }
9739
+ function resolveExtractionStatus(ihsRecord, jobRecords) {
9740
+ const documents = [];
9741
+ const hasJobRecords = jobRecords !== void 0;
9742
+ for (const fileType of Object.values(ExtractionFileType)) {
9743
+ const groupName = FILE_TYPE_TO_GROUP[fileType];
9744
+ const fields = _grouped[groupName] ?? [];
9745
+ const displayName = _groupDisplayNames[groupName] ?? fileType;
9746
+ const uploadedCount = countUploadedFiles(ihsRecord, fileType);
9747
+ const isUploaded = uploadedCount > 0 || fields.some((f) => f.name && isPopulated(ihsRecord[f.name]));
9748
+ const matchingJobs = jobRecords?.filter((j) => j.fileType === fileType) ?? [];
9749
+ if (fields.length <= 1) {
9750
+ const field = fields[0];
9751
+ const columns = field?.ihs_column_names ?? [];
9752
+ const populated = getPopulatedColumns(columns, ihsRecord);
9753
+ const { status, errorMessage } = resolveDocStatus(
9754
+ columns,
9755
+ ihsRecord,
9756
+ isUploaded,
9757
+ matchingJobs[0],
9758
+ hasJobRecords
9759
+ );
9760
+ documents.push({
9761
+ fileType,
9762
+ status,
9763
+ displayName,
9764
+ populatedColumns: populated,
9765
+ totalColumns: columns.length,
9766
+ errorMessage
9767
+ });
9768
+ } else {
9769
+ const count = Math.max(uploadedCount, 1);
9770
+ for (let idx = 0; idx < count; idx++) {
9771
+ const field = fields[idx];
9772
+ const columns = field?.ihs_column_names ?? [];
9773
+ const populated = getPopulatedColumns(columns, ihsRecord);
9774
+ const fileUploaded = idx < uploadedCount;
9775
+ const { status, errorMessage } = resolveDocStatus(
9776
+ columns,
9777
+ ihsRecord,
9778
+ fileUploaded,
9779
+ matchingJobs[idx],
9780
+ hasJobRecords
9781
+ );
9782
+ documents.push({
9783
+ fileType,
9784
+ status,
9785
+ displayName,
9786
+ populatedColumns: populated,
9787
+ totalColumns: columns.length,
9788
+ errorMessage
9789
+ });
9790
+ }
9791
+ }
9792
+ }
9793
+ const summary = documents.reduce(
9794
+ (acc, d) => {
9795
+ if (d.status === "extracted" /* Extracted */) acc.extracted++;
9796
+ else if (d.status === "failed" /* Failed */) acc.failed++;
9797
+ else if (d.status === "not_uploaded" /* NotUploaded */) acc.notUploaded++;
9798
+ else acc.pending++;
9799
+ return acc;
9800
+ },
9801
+ { total: documents.length, extracted: 0, failed: 0, pending: 0, notUploaded: 0 }
9802
+ );
9803
+ return { documents, summary };
9804
+ }
9645
9805
  // Annotate the CommonJS export names for ESM import in node:
9646
9806
  0 && (module.exports = {
9647
9807
  BASE_FIELD_SPECS,
9648
9808
  BasicFormField,
9649
9809
  DEFAULT_VALIDATOR_DEFINITIONS,
9810
+ DocExtractionStatus,
9650
9811
  ExtractionFileType,
9651
9812
  ExtractionJobStatus,
9652
9813
  FIELD_TYPE_DEFINITIONS,
@@ -9672,6 +9833,7 @@ var ExtractionFileType = /* @__PURE__ */ ((ExtractionFileType2) => {
9672
9833
  getCategoryName,
9673
9834
  getDisplayName,
9674
9835
  getDisplayNames,
9836
+ getGroupDisplayNames,
9675
9837
  getPastMonthLabel,
9676
9838
  getPastYearLabel,
9677
9839
  getStepDefaultValues,
@@ -9681,6 +9843,7 @@ var ExtractionFileType = /* @__PURE__ */ ((ExtractionFileType2) => {
9681
9843
  groupFieldsByCategory,
9682
9844
  groupFieldsByPattern,
9683
9845
  processIhsDetails,
9846
+ resolveExtractionStatus,
9684
9847
  resolvePageFields,
9685
9848
  validateFormConfig,
9686
9849
  validateFormSpec,