@finsys/core 2.2.0 → 2.3.0
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 +122 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -1
- package/dist/index.d.ts +45 -1
- package/dist/index.js +119 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -428,6 +428,8 @@ declare function getDisplayName(fieldName: string): string;
|
|
|
428
428
|
declare function extractTimePeriods(columnNames: string[]): string[];
|
|
429
429
|
declare function groupColumnsByTimePeriod(columnNames: string[]): Record<string, Record<string, string>>;
|
|
430
430
|
declare function groupFieldsByPattern(fields: FieldData[]): Record<string, FieldData[]>;
|
|
431
|
+
/** Returns human-friendly display names for field groups. */
|
|
432
|
+
declare function getGroupDisplayNames(): Record<string, string>;
|
|
431
433
|
declare function buildFileFieldTables(ihsData: Record<string, unknown>): Record<string, FileFieldTableData>;
|
|
432
434
|
declare function processIhsDetails(ihsData: Record<string, unknown>): IhsFieldDetail[];
|
|
433
435
|
declare function groupDetailsByCategory(details: IhsFieldDetail[]): IhsDetailCategory[];
|
|
@@ -467,4 +469,46 @@ declare enum ExtractionFileType {
|
|
|
467
469
|
Ic = "ic"
|
|
468
470
|
}
|
|
469
471
|
|
|
470
|
-
|
|
472
|
+
declare enum DocExtractionStatus {
|
|
473
|
+
NotUploaded = "not_uploaded",
|
|
474
|
+
Uploaded = "uploaded",
|
|
475
|
+
Queued = "queued",
|
|
476
|
+
Processing = "processing",
|
|
477
|
+
Extracted = "extracted",
|
|
478
|
+
Failed = "failed",
|
|
479
|
+
Unknown = "unknown"
|
|
480
|
+
}
|
|
481
|
+
interface ExtractionJobRecord {
|
|
482
|
+
fileType: string;
|
|
483
|
+
status: string;
|
|
484
|
+
errorMessage?: string | null;
|
|
485
|
+
}
|
|
486
|
+
interface DocExtractionResult {
|
|
487
|
+
fileType: ExtractionFileType;
|
|
488
|
+
status: DocExtractionStatus;
|
|
489
|
+
displayName: string;
|
|
490
|
+
populatedColumns: string[];
|
|
491
|
+
totalColumns: number;
|
|
492
|
+
errorMessage?: string | null;
|
|
493
|
+
}
|
|
494
|
+
interface ExtractionStatusResult {
|
|
495
|
+
documents: DocExtractionResult[];
|
|
496
|
+
summary: {
|
|
497
|
+
total: number;
|
|
498
|
+
extracted: number;
|
|
499
|
+
failed: number;
|
|
500
|
+
pending: number;
|
|
501
|
+
notUploaded: number;
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Determines per-document extraction status from IHS record data.
|
|
506
|
+
*
|
|
507
|
+
* @param ihsRecord - The IHS application record (any shape satisfying Record<string, unknown>)
|
|
508
|
+
* @param jobRecords - Extraction job records for this IHS. Pass the array (even if empty)
|
|
509
|
+
* when job records were fetched. Omit or pass undefined when job records are unavailable;
|
|
510
|
+
* this produces `Unknown` status for uploaded-but-unextracted documents rather than `Uploaded`.
|
|
511
|
+
*/
|
|
512
|
+
declare function resolveExtractionStatus(ihsRecord: Record<string, unknown>, jobRecords?: ExtractionJobRecord[]): ExtractionStatusResult;
|
|
513
|
+
|
|
514
|
+
export { BASE_FIELD_SPECS, BasicFormField, type Category, type Choice, DEFAULT_VALIDATOR_DEFINITIONS, type DocExtractionResult, DocExtractionStatus, type DropdownOption, type EditorValidator, ExtractionFileType, type ExtractionJobRecord, ExtractionJobStatus, type ExtractionStatusResult, FIELD_TYPE_DEFINITIONS, type FieldData, type FieldGroup, type FieldReference, FieldType, type FileFieldTableData, type FileFieldTableItem, FileFieldTableType, FileFormField, FormField, FormFieldCategory, type FormFieldInputType, type FormFieldType, type FormFieldTypeDefinitions, FormFieldValidator, FormSpec, type FormValidatorDefinitions, type IhsDetailCategory, type IhsFieldDetail, IhsValueFormat, type PageConfig, type RHFSchemaOutput, type RHFStep, type ResolvedField, Role, type SurveyElementJSON, type SurveyJSON, type SurveyPageJSON, type UnifiedFormConfig, type Validator, applyDynamicTitles, buildFileFieldTables, evaluateExpression, extractTimePeriods, generateRHFSchema, generateSurveyJson, getBaseCategories, getBaseFieldNames, getBaseFieldSpecMap, getBaseFieldSpecs, getCategoryName, getDisplayName, getDisplayNames, getGroupDisplayNames, getPastMonthLabel, getPastYearLabel, getStepDefaultValues, getStepSchema, groupColumnsByTimePeriod, groupDetailsByCategory, groupFieldsByCategory, groupFieldsByPattern, processIhsDetails, resolveExtractionStatus, resolvePageFields, validateFormConfig, validateFormSpec, validatePagesConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -428,6 +428,8 @@ declare function getDisplayName(fieldName: string): string;
|
|
|
428
428
|
declare function extractTimePeriods(columnNames: string[]): string[];
|
|
429
429
|
declare function groupColumnsByTimePeriod(columnNames: string[]): Record<string, Record<string, string>>;
|
|
430
430
|
declare function groupFieldsByPattern(fields: FieldData[]): Record<string, FieldData[]>;
|
|
431
|
+
/** Returns human-friendly display names for field groups. */
|
|
432
|
+
declare function getGroupDisplayNames(): Record<string, string>;
|
|
431
433
|
declare function buildFileFieldTables(ihsData: Record<string, unknown>): Record<string, FileFieldTableData>;
|
|
432
434
|
declare function processIhsDetails(ihsData: Record<string, unknown>): IhsFieldDetail[];
|
|
433
435
|
declare function groupDetailsByCategory(details: IhsFieldDetail[]): IhsDetailCategory[];
|
|
@@ -467,4 +469,46 @@ declare enum ExtractionFileType {
|
|
|
467
469
|
Ic = "ic"
|
|
468
470
|
}
|
|
469
471
|
|
|
470
|
-
|
|
472
|
+
declare enum DocExtractionStatus {
|
|
473
|
+
NotUploaded = "not_uploaded",
|
|
474
|
+
Uploaded = "uploaded",
|
|
475
|
+
Queued = "queued",
|
|
476
|
+
Processing = "processing",
|
|
477
|
+
Extracted = "extracted",
|
|
478
|
+
Failed = "failed",
|
|
479
|
+
Unknown = "unknown"
|
|
480
|
+
}
|
|
481
|
+
interface ExtractionJobRecord {
|
|
482
|
+
fileType: string;
|
|
483
|
+
status: string;
|
|
484
|
+
errorMessage?: string | null;
|
|
485
|
+
}
|
|
486
|
+
interface DocExtractionResult {
|
|
487
|
+
fileType: ExtractionFileType;
|
|
488
|
+
status: DocExtractionStatus;
|
|
489
|
+
displayName: string;
|
|
490
|
+
populatedColumns: string[];
|
|
491
|
+
totalColumns: number;
|
|
492
|
+
errorMessage?: string | null;
|
|
493
|
+
}
|
|
494
|
+
interface ExtractionStatusResult {
|
|
495
|
+
documents: DocExtractionResult[];
|
|
496
|
+
summary: {
|
|
497
|
+
total: number;
|
|
498
|
+
extracted: number;
|
|
499
|
+
failed: number;
|
|
500
|
+
pending: number;
|
|
501
|
+
notUploaded: number;
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Determines per-document extraction status from IHS record data.
|
|
506
|
+
*
|
|
507
|
+
* @param ihsRecord - The IHS application record (any shape satisfying Record<string, unknown>)
|
|
508
|
+
* @param jobRecords - Extraction job records for this IHS. Pass the array (even if empty)
|
|
509
|
+
* when job records were fetched. Omit or pass undefined when job records are unavailable;
|
|
510
|
+
* this produces `Unknown` status for uploaded-but-unextracted documents rather than `Uploaded`.
|
|
511
|
+
*/
|
|
512
|
+
declare function resolveExtractionStatus(ihsRecord: Record<string, unknown>, jobRecords?: ExtractionJobRecord[]): ExtractionStatusResult;
|
|
513
|
+
|
|
514
|
+
export { BASE_FIELD_SPECS, BasicFormField, type Category, type Choice, DEFAULT_VALIDATOR_DEFINITIONS, type DocExtractionResult, DocExtractionStatus, type DropdownOption, type EditorValidator, ExtractionFileType, type ExtractionJobRecord, ExtractionJobStatus, type ExtractionStatusResult, FIELD_TYPE_DEFINITIONS, type FieldData, type FieldGroup, type FieldReference, FieldType, type FileFieldTableData, type FileFieldTableItem, FileFieldTableType, FileFormField, FormField, FormFieldCategory, type FormFieldInputType, type FormFieldType, type FormFieldTypeDefinitions, FormFieldValidator, FormSpec, type FormValidatorDefinitions, type IhsDetailCategory, type IhsFieldDetail, IhsValueFormat, type PageConfig, type RHFSchemaOutput, type RHFStep, type ResolvedField, Role, type SurveyElementJSON, type SurveyJSON, type SurveyPageJSON, type UnifiedFormConfig, type Validator, applyDynamicTitles, buildFileFieldTables, evaluateExpression, extractTimePeriods, generateRHFSchema, generateSurveyJson, getBaseCategories, getBaseFieldNames, getBaseFieldSpecMap, getBaseFieldSpecs, getCategoryName, getDisplayName, getDisplayNames, getGroupDisplayNames, getPastMonthLabel, getPastYearLabel, getStepDefaultValues, getStepSchema, groupColumnsByTimePeriod, groupDetailsByCategory, groupFieldsByCategory, groupFieldsByPattern, processIhsDetails, resolveExtractionStatus, resolvePageFields, validateFormConfig, validateFormSpec, validatePagesConfig };
|
package/dist/index.js
CHANGED
|
@@ -9350,6 +9350,9 @@ var GROUP_DISPLAY_NAMES = {
|
|
|
9350
9350
|
ssm_documents: "SSM Company Information",
|
|
9351
9351
|
ic_documents: "Identification Card"
|
|
9352
9352
|
};
|
|
9353
|
+
function getGroupDisplayNames() {
|
|
9354
|
+
return GROUP_DISPLAY_NAMES;
|
|
9355
|
+
}
|
|
9353
9356
|
function isNumericField(fieldName) {
|
|
9354
9357
|
const patterns = [
|
|
9355
9358
|
"balance",
|
|
@@ -9566,10 +9569,124 @@ var ExtractionFileType = /* @__PURE__ */ ((ExtractionFileType2) => {
|
|
|
9566
9569
|
ExtractionFileType2["Ic"] = "ic";
|
|
9567
9570
|
return ExtractionFileType2;
|
|
9568
9571
|
})(ExtractionFileType || {});
|
|
9572
|
+
|
|
9573
|
+
// src/extraction-status.ts
|
|
9574
|
+
var DocExtractionStatus = /* @__PURE__ */ ((DocExtractionStatus2) => {
|
|
9575
|
+
DocExtractionStatus2["NotUploaded"] = "not_uploaded";
|
|
9576
|
+
DocExtractionStatus2["Uploaded"] = "uploaded";
|
|
9577
|
+
DocExtractionStatus2["Queued"] = "queued";
|
|
9578
|
+
DocExtractionStatus2["Processing"] = "processing";
|
|
9579
|
+
DocExtractionStatus2["Extracted"] = "extracted";
|
|
9580
|
+
DocExtractionStatus2["Failed"] = "failed";
|
|
9581
|
+
DocExtractionStatus2["Unknown"] = "unknown";
|
|
9582
|
+
return DocExtractionStatus2;
|
|
9583
|
+
})(DocExtractionStatus || {});
|
|
9584
|
+
var FILE_TYPE_TO_GROUP = {
|
|
9585
|
+
["bankStatements" /* BankStatement */]: "bank_statements",
|
|
9586
|
+
["financialStatements" /* FinancialStatement */]: "financials",
|
|
9587
|
+
["epfStatements" /* Epf */]: "epf_statements",
|
|
9588
|
+
["payslips" /* Payslip */]: "payslip_statements",
|
|
9589
|
+
["ssm" /* Ssm */]: "ssm_documents",
|
|
9590
|
+
["form9" /* Form9 */]: "form9",
|
|
9591
|
+
["ic" /* Ic */]: "ic_documents"
|
|
9592
|
+
};
|
|
9593
|
+
var _specs = getBaseFieldSpecs();
|
|
9594
|
+
var _fileFields = _specs.filter((f) => f.type === "file" && f.ihs_column_names?.length);
|
|
9595
|
+
var _grouped = groupFieldsByPattern(_fileFields);
|
|
9596
|
+
var _groupDisplayNames = getGroupDisplayNames();
|
|
9597
|
+
function isPopulated(value) {
|
|
9598
|
+
if (value === null || value === void 0 || value === "") return false;
|
|
9599
|
+
if (value === "Not Specified") return false;
|
|
9600
|
+
return true;
|
|
9601
|
+
}
|
|
9602
|
+
function hasUploadedFile(fields, ihsRecord) {
|
|
9603
|
+
return fields.some((field) => {
|
|
9604
|
+
if (!field.name) return false;
|
|
9605
|
+
return isPopulated(ihsRecord[field.name]);
|
|
9606
|
+
});
|
|
9607
|
+
}
|
|
9608
|
+
function getExtractionColumns(fields) {
|
|
9609
|
+
const columns = [];
|
|
9610
|
+
for (const field of fields) {
|
|
9611
|
+
if (field.ihs_column_names) {
|
|
9612
|
+
columns.push(...field.ihs_column_names);
|
|
9613
|
+
}
|
|
9614
|
+
}
|
|
9615
|
+
return columns;
|
|
9616
|
+
}
|
|
9617
|
+
function getPopulatedColumns(columns, ihsRecord) {
|
|
9618
|
+
return columns.filter((col) => isPopulated(ihsRecord[col]));
|
|
9619
|
+
}
|
|
9620
|
+
function resolveExtractionStatus(ihsRecord, jobRecords) {
|
|
9621
|
+
const documents = [];
|
|
9622
|
+
for (const fileType of Object.values(ExtractionFileType)) {
|
|
9623
|
+
const groupName = FILE_TYPE_TO_GROUP[fileType];
|
|
9624
|
+
const fields = _grouped[groupName] ?? [];
|
|
9625
|
+
const displayName = _groupDisplayNames[groupName] ?? fileType;
|
|
9626
|
+
const uploaded = fields.length > 0 && hasUploadedFile(fields, ihsRecord);
|
|
9627
|
+
const allColumns = getExtractionColumns(fields);
|
|
9628
|
+
const populated = getPopulatedColumns(allColumns, ihsRecord);
|
|
9629
|
+
const hasExtractedData = populated.length > 0;
|
|
9630
|
+
let status;
|
|
9631
|
+
let errorMessage;
|
|
9632
|
+
if (!uploaded) {
|
|
9633
|
+
status = "not_uploaded" /* NotUploaded */;
|
|
9634
|
+
} else if (jobRecords) {
|
|
9635
|
+
const job = jobRecords.find((j) => j.fileType === fileType);
|
|
9636
|
+
if (job) {
|
|
9637
|
+
if (job.status === "queued" /* Queued */) {
|
|
9638
|
+
status = "queued" /* Queued */;
|
|
9639
|
+
} else if (job.status === "processing" /* Processing */) {
|
|
9640
|
+
status = "processing" /* Processing */;
|
|
9641
|
+
} else if (job.status === "failed" /* Failed */) {
|
|
9642
|
+
if (hasExtractedData) {
|
|
9643
|
+
status = "extracted" /* Extracted */;
|
|
9644
|
+
errorMessage = job.errorMessage;
|
|
9645
|
+
} else {
|
|
9646
|
+
status = "failed" /* Failed */;
|
|
9647
|
+
errorMessage = job.errorMessage;
|
|
9648
|
+
}
|
|
9649
|
+
} else if (job.status === "succeeded" /* Succeeded */ || hasExtractedData) {
|
|
9650
|
+
status = "extracted" /* Extracted */;
|
|
9651
|
+
} else {
|
|
9652
|
+
status = "uploaded" /* Uploaded */;
|
|
9653
|
+
}
|
|
9654
|
+
} else if (hasExtractedData) {
|
|
9655
|
+
status = "extracted" /* Extracted */;
|
|
9656
|
+
} else {
|
|
9657
|
+
status = "uploaded" /* Uploaded */;
|
|
9658
|
+
}
|
|
9659
|
+
} else if (hasExtractedData) {
|
|
9660
|
+
status = "extracted" /* Extracted */;
|
|
9661
|
+
} else {
|
|
9662
|
+
status = "unknown" /* Unknown */;
|
|
9663
|
+
}
|
|
9664
|
+
documents.push({
|
|
9665
|
+
fileType,
|
|
9666
|
+
status,
|
|
9667
|
+
displayName,
|
|
9668
|
+
populatedColumns: populated,
|
|
9669
|
+
totalColumns: allColumns.length,
|
|
9670
|
+
errorMessage
|
|
9671
|
+
});
|
|
9672
|
+
}
|
|
9673
|
+
const summary = documents.reduce(
|
|
9674
|
+
(acc, d) => {
|
|
9675
|
+
if (d.status === "extracted" /* Extracted */) acc.extracted++;
|
|
9676
|
+
else if (d.status === "failed" /* Failed */) acc.failed++;
|
|
9677
|
+
else if (d.status === "not_uploaded" /* NotUploaded */) acc.notUploaded++;
|
|
9678
|
+
else acc.pending++;
|
|
9679
|
+
return acc;
|
|
9680
|
+
},
|
|
9681
|
+
{ total: documents.length, extracted: 0, failed: 0, pending: 0, notUploaded: 0 }
|
|
9682
|
+
);
|
|
9683
|
+
return { documents, summary };
|
|
9684
|
+
}
|
|
9569
9685
|
export {
|
|
9570
9686
|
BASE_FIELD_SPECS,
|
|
9571
9687
|
BasicFormField,
|
|
9572
9688
|
DEFAULT_VALIDATOR_DEFINITIONS,
|
|
9689
|
+
DocExtractionStatus,
|
|
9573
9690
|
ExtractionFileType,
|
|
9574
9691
|
ExtractionJobStatus,
|
|
9575
9692
|
FIELD_TYPE_DEFINITIONS,
|
|
@@ -9595,6 +9712,7 @@ export {
|
|
|
9595
9712
|
getCategoryName,
|
|
9596
9713
|
getDisplayName,
|
|
9597
9714
|
getDisplayNames,
|
|
9715
|
+
getGroupDisplayNames,
|
|
9598
9716
|
getPastMonthLabel,
|
|
9599
9717
|
getPastYearLabel,
|
|
9600
9718
|
getStepDefaultValues,
|
|
@@ -9604,6 +9722,7 @@ export {
|
|
|
9604
9722
|
groupFieldsByCategory,
|
|
9605
9723
|
groupFieldsByPattern,
|
|
9606
9724
|
processIhsDetails,
|
|
9725
|
+
resolveExtractionStatus,
|
|
9607
9726
|
resolvePageFields,
|
|
9608
9727
|
validateFormConfig,
|
|
9609
9728
|
validateFormSpec,
|