@ripwords/myinvois-client 0.2.38 → 0.2.39

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.
Files changed (74) hide show
  1. package/dist/api/platformLogin.d.ts +1 -1
  2. package/dist/api/platformLogin.js +1 -1
  3. package/dist/index.cjs +2 -2
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.js +2 -2
  6. package/dist/index10.cjs +187 -16
  7. package/dist/index10.cjs.map +1 -1
  8. package/dist/index12.cjs +16 -25
  9. package/dist/index12.cjs.map +1 -1
  10. package/dist/index13.cjs +0 -24
  11. package/dist/index15.cjs +29 -0
  12. package/dist/index15.cjs.map +1 -0
  13. package/dist/index16.cjs +25 -0
  14. package/dist/index16.cjs.map +1 -0
  15. package/dist/index17.cjs +0 -5
  16. package/dist/index18.cjs +33 -6
  17. package/dist/index18.cjs.map +1 -0
  18. package/dist/index19.cjs +23 -4
  19. package/dist/{index13.cjs.map → index19.cjs.map} +1 -1
  20. package/dist/index2.cjs +4 -61
  21. package/dist/index20.cjs +0 -3
  22. package/dist/index21.cjs +0 -3
  23. package/dist/index22.cjs +0 -6
  24. package/dist/index23.cjs +3 -207
  25. package/dist/index24.cjs +9 -105
  26. package/dist/index24.cjs.map +1 -1
  27. package/dist/index25.cjs +4 -136
  28. package/dist/index26.cjs +21 -63
  29. package/dist/index27.cjs +2 -266
  30. package/dist/index28.cjs +2 -78
  31. package/dist/index29.cjs +326 -103
  32. package/dist/index29.cjs.map +1 -1
  33. package/dist/index3.cjs +6 -531
  34. package/dist/index30.cjs +189 -69
  35. package/dist/index30.cjs.map +1 -1
  36. package/dist/index31.cjs +203 -107
  37. package/dist/index31.cjs.map +1 -1
  38. package/dist/index32.cjs +104 -95
  39. package/dist/index32.cjs.map +1 -1
  40. package/dist/index33.cjs +136 -3
  41. package/dist/{index25.cjs.map → index33.cjs.map} +1 -1
  42. package/dist/index34.cjs +60 -9
  43. package/dist/index34.cjs.map +1 -1
  44. package/dist/index35.cjs +266 -4
  45. package/dist/{index27.cjs.map → index35.cjs.map} +1 -1
  46. package/dist/index36.cjs +78 -21
  47. package/dist/{index28.cjs.map → index36.cjs.map} +1 -1
  48. package/dist/index37.cjs +106 -2
  49. package/dist/index37.cjs.map +1 -0
  50. package/dist/index38.cjs +72 -2
  51. package/dist/index38.cjs.map +1 -0
  52. package/dist/index39.cjs +108 -326
  53. package/dist/index39.cjs.map +1 -1
  54. package/dist/index4.cjs +4 -195
  55. package/dist/index40.cjs +96 -189
  56. package/dist/index40.cjs.map +1 -1
  57. package/dist/index5.cjs +3 -0
  58. package/dist/index6.cjs +2 -24
  59. package/dist/index65.cts.map +1 -1
  60. package/dist/index7.cjs +6 -0
  61. package/dist/index8.cjs +62 -0
  62. package/dist/{index2.cjs.map → index8.cjs.map} +1 -1
  63. package/dist/index9.cjs +526 -23
  64. package/dist/index9.cjs.map +1 -1
  65. package/dist/{platformLogin-BVTUzLjd.cjs → platformLogin-Ch6hFKoU.cjs} +3 -3
  66. package/dist/platformLogin-Ch6hFKoU.cjs.map +1 -0
  67. package/dist/{platformLogin-B6f18bB7.js → platformLogin-CqI9OLYP.js} +2 -2
  68. package/package.json +1 -1
  69. package/dist/index23.cjs.map +0 -1
  70. package/dist/index26.cjs.map +0 -1
  71. package/dist/index3.cjs.map +0 -1
  72. package/dist/index4.cjs.map +0 -1
  73. package/dist/index6.cjs.map +0 -1
  74. package/dist/platformLogin-BVTUzLjd.cjs.map +0 -1
package/dist/index30.cjs CHANGED
@@ -1,73 +1,193 @@
1
1
 
2
- //#region src/types/msic/7X.d.ts
3
- let MSIC_7X = /* @__PURE__ */ function(MSIC_7X$1) {
4
- MSIC_7X$1["HEAD_OFFICES"] = "70100";
5
- MSIC_7X$1["BUSINESS_MANAGEMENT_CONSULTANCY"] = "70201";
6
- MSIC_7X$1["HR_CONSULTANCY"] = "70202";
7
- MSIC_7X$1["PR_COMMUNICATIONS_CONSULTANCY"] = "70203";
8
- MSIC_7X$1["OTHER_MANAGEMENT_CONSULTANCY"] = "70209";
9
- MSIC_7X$1["ARCHITECTURAL_SERVICES"] = "71101";
10
- MSIC_7X$1["ENGINEERING_SERVICES"] = "71102";
11
- MSIC_7X$1["LAND_SURVEYING"] = "71103";
12
- MSIC_7X$1["OTHER_ARCHITECTURAL_ENGINEERING"] = "71109";
13
- MSIC_7X$1["TECHNICAL_TESTING"] = "71200";
14
- MSIC_7X$1["NATURAL_SCIENCES_RESEARCH"] = "72101";
15
- MSIC_7X$1["ENGINEERING_RESEARCH"] = "72102";
16
- MSIC_7X$1["MEDICAL_SCIENCES_RESEARCH"] = "72103";
17
- MSIC_7X$1["BIOTECHNOLOGY_RESEARCH"] = "72104";
18
- MSIC_7X$1["AGRICULTURAL_SCIENCES_RESEARCH"] = "72105";
19
- MSIC_7X$1["ICT_RESEARCH"] = "72106";
20
- MSIC_7X$1["OTHER_NATURAL_SCIENCES_RESEARCH"] = "72109";
21
- MSIC_7X$1["SOCIAL_SCIENCES_RESEARCH"] = "72201";
22
- MSIC_7X$1["HUMANITIES_RESEARCH"] = "72202";
23
- MSIC_7X$1["OTHER_SOCIAL_SCIENCES_RESEARCH"] = "72209";
24
- MSIC_7X$1["ADVERTISING"] = "73100";
25
- MSIC_7X$1["MARKET_RESEARCH"] = "73200";
26
- MSIC_7X$1["INTERIOR_DECORATING"] = "74101";
27
- MSIC_7X$1["GRAPHIC_DESIGN"] = "74102";
28
- MSIC_7X$1["FASHION_DESIGN"] = "74103";
29
- MSIC_7X$1["OTHER_SPECIALIZED_DESIGN"] = "74109";
30
- MSIC_7X$1["PHOTOGRAPHY"] = "74200";
31
- MSIC_7X$1["TRANSLATION_SERVICES"] = "74901";
32
- MSIC_7X$1["BUSINESS_BROKERAGE"] = "74902";
33
- MSIC_7X$1["SECURITY_CONSULTING"] = "74903";
34
- MSIC_7X$1["QUANTITY_SURVEYING"] = "74904";
35
- MSIC_7X$1["OTHER_CONSULTANCY"] = "74905";
36
- MSIC_7X$1["OTHER_PROFESSIONAL_ACTIVITIES"] = "74909";
37
- MSIC_7X$1["VETERINARY_ACTIVITIES"] = "75000";
38
- MSIC_7X$1["CAR_RENTAL"] = "77101";
39
- MSIC_7X$1["TRUCK_RENTAL"] = "77102";
40
- MSIC_7X$1["BOAT_RENTAL"] = "77211";
41
- MSIC_7X$1["BICYCLE_RENTAL"] = "77212";
42
- MSIC_7X$1["BEACH_EQUIPMENT_RENTAL"] = "77213";
43
- MSIC_7X$1["OTHER_SPORTS_EQUIPMENT_RENTAL"] = "77219";
44
- MSIC_7X$1["VIDEO_RENTAL"] = "77220";
45
- MSIC_7X$1["CLOTHING_RENTAL"] = "77291";
46
- MSIC_7X$1["HOUSEHOLD_ITEMS_RENTAL"] = "77292";
47
- MSIC_7X$1["JEWELRY_RENTAL"] = "77293";
48
- MSIC_7X$1["BOOK_RENTAL"] = "77294";
49
- MSIC_7X$1["HOBBY_EQUIPMENT_RENTAL"] = "77295";
50
- MSIC_7X$1["PLANT_RENTAL"] = "77296";
51
- MSIC_7X$1["ELECTRONICS_RENTAL"] = "77297";
52
- MSIC_7X$1["OTHER_PERSONAL_GOODS_RENTAL"] = "77299";
53
- MSIC_7X$1["INDUSTRIAL_MACHINERY_RENTAL"] = "77301";
54
- MSIC_7X$1["LAND_TRANSPORT_RENTAL"] = "77302";
55
- MSIC_7X$1["WATER_TRANSPORT_RENTAL"] = "77303";
56
- MSIC_7X$1["AIR_TRANSPORT_RENTAL"] = "77304";
57
- MSIC_7X$1["AGRICULTURAL_MACHINERY_RENTAL"] = "77305";
58
- MSIC_7X$1["CONSTRUCTION_MACHINERY_RENTAL"] = "77306";
59
- MSIC_7X$1["OFFICE_MACHINERY_RENTAL"] = "77307";
60
- MSIC_7X$1["OTHER_MACHINERY_RENTAL"] = "77309";
61
- MSIC_7X$1["INTELLECTUAL_PROPERTY_LEASING"] = "77400";
62
- MSIC_7X$1["EMPLOYMENT_PLACEMENT"] = "78100";
63
- MSIC_7X$1["TEMPORARY_EMPLOYMENT"] = "78200";
64
- MSIC_7X$1["HR_PROVISION"] = "78300";
65
- MSIC_7X$1["TRAVEL_AGENCY"] = "79110";
66
- MSIC_7X$1["TOUR_OPERATOR"] = "79120";
67
- MSIC_7X$1["OTHER_RESERVATION_SERVICES"] = "79900";
68
- return MSIC_7X$1;
69
- }({});
2
+ //#region src/utils/validation.ts
3
+ /**
4
+ * Validates TIN format based on registration type
5
+ */
6
+ const validateTIN = (tin, registrationType) => {
7
+ const errors = [];
8
+ if (!tin) {
9
+ errors.push({
10
+ field: "tin",
11
+ code: "TIN_REQUIRED",
12
+ message: "TIN is required",
13
+ severity: "error"
14
+ });
15
+ return errors;
16
+ }
17
+ if (registrationType === "BRN" && !tin.startsWith("C")) errors.push({
18
+ field: "tin",
19
+ code: "TIN_FORMAT_INVALID",
20
+ message: "Company TIN should start with \"C\" for BRN registration",
21
+ severity: "warning"
22
+ });
23
+ if (registrationType === "NRIC" && !tin.startsWith("IG")) errors.push({
24
+ field: "tin",
25
+ code: "TIN_FORMAT_INVALID",
26
+ message: "Individual TIN should start with \"IG\" for NRIC registration",
27
+ severity: "warning"
28
+ });
29
+ if (tin.length > 14) errors.push({
30
+ field: "tin",
31
+ code: "TIN_LENGTH_INVALID",
32
+ message: "TIN cannot exceed 14 characters",
33
+ severity: "error"
34
+ });
35
+ return errors;
36
+ };
37
+ /**
38
+ * Validates contact number format (E.164 standard)
39
+ */
40
+ const validateContactNumber = (contactNumber) => {
41
+ const errors = [];
42
+ if (!contactNumber || contactNumber === "NA") return errors;
43
+ const e164Regex = /^\+[1-9]\d{1,14}$/;
44
+ if (!e164Regex.test(contactNumber)) errors.push({
45
+ field: "contactNumber",
46
+ code: "CONTACT_FORMAT_INVALID",
47
+ message: "Contact number must be in E.164 format (e.g., +60123456789)",
48
+ severity: "error"
49
+ });
50
+ if (contactNumber.length < 8) errors.push({
51
+ field: "contactNumber",
52
+ code: "CONTACT_LENGTH_INVALID",
53
+ message: "Contact number must be at least 8 characters",
54
+ severity: "error"
55
+ });
56
+ return errors;
57
+ };
58
+ /**
59
+ * Validates monetary amounts
60
+ */
61
+ const validateMonetaryAmount = (amount, fieldName, maxDigits = 18, maxDecimals = 2) => {
62
+ const errors = [];
63
+ if (amount < 0) errors.push({
64
+ field: fieldName,
65
+ code: "AMOUNT_NEGATIVE",
66
+ message: `${fieldName} cannot be negative`,
67
+ severity: "error"
68
+ });
69
+ const amountStr = amount.toString();
70
+ const [integerPart, decimalPart] = amountStr.split(".");
71
+ if (integerPart && integerPart.length > maxDigits - maxDecimals) errors.push({
72
+ field: fieldName,
73
+ code: "AMOUNT_DIGITS_EXCEEDED",
74
+ message: `${fieldName} exceeds maximum ${maxDigits} digits`,
75
+ severity: "error"
76
+ });
77
+ if (decimalPart && decimalPart.length > maxDecimals) errors.push({
78
+ field: fieldName,
79
+ code: "AMOUNT_DECIMALS_EXCEEDED",
80
+ message: `${fieldName} exceeds maximum ${maxDecimals} decimal places`,
81
+ severity: "error"
82
+ });
83
+ return errors;
84
+ };
85
+ /**
86
+ * Validates line item tax calculation consistency for both fixed rate and percentage taxation
87
+ */
88
+ const validateLineItemTax = (item, index) => {
89
+ const errors = [];
90
+ const tolerance = .01;
91
+ const hasFixedRate = item.taxPerUnitAmount !== void 0 && item.baseUnitMeasure !== void 0;
92
+ const hasPercentageRate = item.taxRate !== void 0;
93
+ if (!hasFixedRate && !hasPercentageRate) {
94
+ errors.push({
95
+ field: `lineItem[${index}]`,
96
+ code: "TAX_METHOD_MISSING",
97
+ message: `Line item ${index + 1} must specify either taxRate (for percentage) or taxPerUnitAmount + baseUnitMeasure (for fixed rate)`,
98
+ severity: "error"
99
+ });
100
+ return errors;
101
+ }
102
+ if (hasFixedRate && hasPercentageRate) errors.push({
103
+ field: `lineItem[${index}]`,
104
+ code: "TAX_METHOD_CONFLICT",
105
+ message: `Line item ${index + 1} cannot have both percentage and fixed rate tax methods`,
106
+ severity: "error"
107
+ });
108
+ if (hasFixedRate) {
109
+ if (item.baseUnitMeasureCode === void 0) errors.push({
110
+ field: `lineItem[${index}].baseUnitMeasureCode`,
111
+ code: "UNIT_CODE_MISSING",
112
+ message: `Line item ${index + 1} with fixed rate tax must specify baseUnitMeasureCode`,
113
+ severity: "error"
114
+ });
115
+ const expectedTaxAmount = item.taxPerUnitAmount * item.baseUnitMeasure;
116
+ if (Math.abs(item.taxAmount - expectedTaxAmount) > tolerance) errors.push({
117
+ field: `lineItem[${index}].taxAmount`,
118
+ code: "FIXED_TAX_CALCULATION_MISMATCH",
119
+ message: `Line item ${index + 1} tax amount (${item.taxAmount}) doesn't match fixed rate calculation (${item.taxPerUnitAmount} × ${item.baseUnitMeasure} = ${expectedTaxAmount})`,
120
+ severity: "error"
121
+ });
122
+ }
123
+ if (hasPercentageRate && !hasFixedRate) {
124
+ const expectedTaxAmount = item.totalTaxableAmountPerLine * item.taxRate / 100;
125
+ if (Math.abs(item.taxAmount - expectedTaxAmount) > tolerance) errors.push({
126
+ field: `lineItem[${index}].taxAmount`,
127
+ code: "PERCENTAGE_TAX_CALCULATION_MISMATCH",
128
+ message: `Line item ${index + 1} tax amount (${item.taxAmount}) doesn't match percentage calculation (${item.totalTaxableAmountPerLine} × ${item.taxRate}% = ${expectedTaxAmount})`,
129
+ severity: "error"
130
+ });
131
+ }
132
+ return errors;
133
+ };
134
+ /**
135
+ * Validates tax calculation consistency
136
+ */
137
+ const validateTaxCalculations = (invoice) => {
138
+ const errors = [];
139
+ invoice.invoiceLineItems.forEach((item, index) => {
140
+ errors.push(...validateLineItemTax(item, index));
141
+ });
142
+ const expectedTaxExclusive = invoice.invoiceLineItems.reduce((sum, item) => sum + item.totalTaxableAmountPerLine, 0);
143
+ const expectedTaxAmount = invoice.invoiceLineItems.reduce((sum, item) => sum + item.taxAmount, 0);
144
+ const tolerance = .01;
145
+ if (Math.abs(invoice.legalMonetaryTotal.taxExclusiveAmount - expectedTaxExclusive) > tolerance) errors.push({
146
+ field: "legalMonetaryTotal.taxExclusiveAmount",
147
+ code: "TAX_EXCLUSIVE_MISMATCH",
148
+ message: `Tax exclusive amount (${invoice.legalMonetaryTotal.taxExclusiveAmount}) doesn't match sum of line items (${expectedTaxExclusive})`,
149
+ severity: "error"
150
+ });
151
+ if (Math.abs(invoice.taxTotal.taxAmount - expectedTaxAmount) > tolerance) errors.push({
152
+ field: "taxTotal.taxAmount",
153
+ code: "TAX_AMOUNT_MISMATCH",
154
+ message: `Tax amount (${invoice.taxTotal.taxAmount}) doesn't match sum of line item taxes (${expectedTaxAmount})`,
155
+ severity: "error"
156
+ });
157
+ return errors;
158
+ };
159
+ /**
160
+ * Main validation function for complete invoice
161
+ */
162
+ const validateInvoice = (invoice) => {
163
+ const allErrors = [];
164
+ allErrors.push(...validateTIN(invoice.supplier.tin, invoice.supplier.registrationType));
165
+ allErrors.push(...validateTIN(invoice.buyer.tin, invoice.buyer.registrationType));
166
+ allErrors.push(...validateContactNumber(invoice.supplier.contactNumber));
167
+ allErrors.push(...validateContactNumber(invoice.buyer.contactNumber));
168
+ allErrors.push(...validateMonetaryAmount(invoice.legalMonetaryTotal.taxExclusiveAmount, "taxExclusiveAmount"));
169
+ allErrors.push(...validateMonetaryAmount(invoice.legalMonetaryTotal.payableAmount, "payableAmount"));
170
+ allErrors.push(...validateMonetaryAmount(invoice.taxTotal.taxAmount, "taxAmount"));
171
+ invoice.invoiceLineItems.forEach((item, index) => {
172
+ allErrors.push(...validateMonetaryAmount(item.unitPrice, `lineItem[${index}].unitPrice`));
173
+ allErrors.push(...validateMonetaryAmount(item.taxAmount, `lineItem[${index}].taxAmount`));
174
+ allErrors.push(...validateMonetaryAmount(item.totalTaxableAmountPerLine, `lineItem[${index}].totalTaxableAmountPerLine`));
175
+ });
176
+ allErrors.push(...validateTaxCalculations(invoice));
177
+ const errors = allErrors.filter((e) => e.severity === "error");
178
+ const warnings = allErrors.filter((e) => e.severity === "warning");
179
+ return {
180
+ isValid: errors.length === 0,
181
+ errors,
182
+ warnings
183
+ };
184
+ };
70
185
 
71
186
  //#endregion
72
- exports.MSIC_7X = MSIC_7X;
187
+ exports.validateContactNumber = validateContactNumber;
188
+ exports.validateInvoice = validateInvoice;
189
+ exports.validateLineItemTax = validateLineItemTax;
190
+ exports.validateMonetaryAmount = validateMonetaryAmount;
191
+ exports.validateTIN = validateTIN;
192
+ exports.validateTaxCalculations = validateTaxCalculations;
73
193
  //# sourceMappingURL=index30.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index30.cjs","names":[],"sources":["../src/types/msic/7X.d.ts"],"sourcesContent":["export type MSIC_7X_CODE =\n | '70100'\n | '70201'\n | '70202'\n | '70203'\n | '70209'\n | '71101'\n | '71102'\n | '71103'\n | '71109'\n | '71200'\n | '72101'\n | '72102'\n | '72103'\n | '72104'\n | '72105'\n | '72106'\n | '72109'\n | '72201'\n | '72202'\n | '72209'\n | '73100'\n | '73200'\n | '74101'\n | '74102'\n | '74103'\n | '74109'\n | '74200'\n | '74901'\n | '74902'\n | '74903'\n | '74904'\n | '74905'\n | '74909'\n | '75000'\n | '77101'\n | '77102'\n | '77211'\n | '77212'\n | '77213'\n | '77219'\n | '77220'\n | '77291'\n | '77292'\n | '77293'\n | '77294'\n | '77295'\n | '77296'\n | '77297'\n | '77299'\n | '77301'\n | '77302'\n | '77303'\n | '77304'\n | '77305'\n | '77306'\n | '77307'\n | '77309'\n | '77400'\n | '78100'\n | '78200'\n | '78300'\n | '79110'\n | '79120'\n | '79900'\n\nexport enum MSIC_7X {\n HEAD_OFFICES = '70100',\n BUSINESS_MANAGEMENT_CONSULTANCY = '70201',\n HR_CONSULTANCY = '70202',\n PR_COMMUNICATIONS_CONSULTANCY = '70203',\n OTHER_MANAGEMENT_CONSULTANCY = '70209',\n ARCHITECTURAL_SERVICES = '71101',\n ENGINEERING_SERVICES = '71102',\n LAND_SURVEYING = '71103',\n OTHER_ARCHITECTURAL_ENGINEERING = '71109',\n TECHNICAL_TESTING = '71200',\n NATURAL_SCIENCES_RESEARCH = '72101',\n ENGINEERING_RESEARCH = '72102',\n MEDICAL_SCIENCES_RESEARCH = '72103',\n BIOTECHNOLOGY_RESEARCH = '72104',\n AGRICULTURAL_SCIENCES_RESEARCH = '72105',\n ICT_RESEARCH = '72106',\n OTHER_NATURAL_SCIENCES_RESEARCH = '72109',\n SOCIAL_SCIENCES_RESEARCH = '72201',\n HUMANITIES_RESEARCH = '72202',\n OTHER_SOCIAL_SCIENCES_RESEARCH = '72209',\n ADVERTISING = '73100',\n MARKET_RESEARCH = '73200',\n INTERIOR_DECORATING = '74101',\n GRAPHIC_DESIGN = '74102',\n FASHION_DESIGN = '74103',\n OTHER_SPECIALIZED_DESIGN = '74109',\n PHOTOGRAPHY = '74200',\n TRANSLATION_SERVICES = '74901',\n BUSINESS_BROKERAGE = '74902',\n SECURITY_CONSULTING = '74903',\n QUANTITY_SURVEYING = '74904',\n OTHER_CONSULTANCY = '74905',\n OTHER_PROFESSIONAL_ACTIVITIES = '74909',\n VETERINARY_ACTIVITIES = '75000',\n CAR_RENTAL = '77101',\n TRUCK_RENTAL = '77102',\n BOAT_RENTAL = '77211',\n BICYCLE_RENTAL = '77212',\n BEACH_EQUIPMENT_RENTAL = '77213',\n OTHER_SPORTS_EQUIPMENT_RENTAL = '77219',\n VIDEO_RENTAL = '77220',\n CLOTHING_RENTAL = '77291',\n HOUSEHOLD_ITEMS_RENTAL = '77292',\n JEWELRY_RENTAL = '77293',\n BOOK_RENTAL = '77294',\n HOBBY_EQUIPMENT_RENTAL = '77295',\n PLANT_RENTAL = '77296',\n ELECTRONICS_RENTAL = '77297',\n OTHER_PERSONAL_GOODS_RENTAL = '77299',\n INDUSTRIAL_MACHINERY_RENTAL = '77301',\n LAND_TRANSPORT_RENTAL = '77302',\n WATER_TRANSPORT_RENTAL = '77303',\n AIR_TRANSPORT_RENTAL = '77304',\n AGRICULTURAL_MACHINERY_RENTAL = '77305',\n CONSTRUCTION_MACHINERY_RENTAL = '77306',\n OFFICE_MACHINERY_RENTAL = '77307',\n OTHER_MACHINERY_RENTAL = '77309',\n INTELLECTUAL_PROPERTY_LEASING = '77400',\n EMPLOYMENT_PLACEMENT = '78100',\n TEMPORARY_EMPLOYMENT = '78200',\n HR_PROVISION = '78300',\n TRAVEL_AGENCY = '79110',\n TOUR_OPERATOR = '79120',\n OTHER_RESERVATION_SERVICES = '79900',\n}\n"],"mappings":";;AAkEA,IAAY,8CAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACD"}
1
+ {"version":3,"file":"index30.cjs","names":["tin: string","registrationType?: string","errors: ValidationError[]","contactNumber: string","amount: number","fieldName: string","item: InvoiceLineItem","index: number","invoice: InvoiceV1_1","allErrors: ValidationError[]"],"sources":["../src/utils/validation.ts"],"sourcesContent":["import type { InvoiceV1_1, InvoiceLineItem } from '../types'\n\n/**\n * MyInvois Invoice Validation Utilities\n *\n * Provides comprehensive validation for invoice data before document generation\n * and submission to ensure compliance with MyInvois business rules and format requirements.\n */\n\nexport interface ValidationResult {\n isValid: boolean\n errors: ValidationError[]\n warnings: ValidationWarning[]\n}\n\nexport interface ValidationError {\n field: string\n code: string\n message: string\n severity: 'error' | 'warning'\n}\n\nexport interface ValidationWarning extends ValidationError {\n severity: 'warning'\n}\n\n/**\n * Validates TIN format based on registration type\n */\nexport const validateTIN = (\n tin: string,\n registrationType?: string,\n): ValidationError[] => {\n const errors: ValidationError[] = []\n\n if (!tin) {\n errors.push({\n field: 'tin',\n code: 'TIN_REQUIRED',\n message: 'TIN is required',\n severity: 'error',\n })\n return errors\n }\n\n // TIN format validation based on type\n if (registrationType === 'BRN' && !tin.startsWith('C')) {\n errors.push({\n field: 'tin',\n code: 'TIN_FORMAT_INVALID',\n message: 'Company TIN should start with \"C\" for BRN registration',\n severity: 'warning',\n })\n }\n\n if (registrationType === 'NRIC' && !tin.startsWith('IG')) {\n errors.push({\n field: 'tin',\n code: 'TIN_FORMAT_INVALID',\n message: 'Individual TIN should start with \"IG\" for NRIC registration',\n severity: 'warning',\n })\n }\n\n // Length validation\n if (tin.length > 14) {\n errors.push({\n field: 'tin',\n code: 'TIN_LENGTH_INVALID',\n message: 'TIN cannot exceed 14 characters',\n severity: 'error',\n })\n }\n\n return errors\n}\n\n/**\n * Validates contact number format (E.164 standard)\n */\nexport const validateContactNumber = (\n contactNumber: string,\n): ValidationError[] => {\n const errors: ValidationError[] = []\n\n if (!contactNumber || contactNumber === 'NA') {\n return errors // Allow NA for consolidated e-invoices\n }\n\n // E.164 format validation\n const e164Regex = /^\\+[1-9]\\d{1,14}$/\n if (!e164Regex.test(contactNumber)) {\n errors.push({\n field: 'contactNumber',\n code: 'CONTACT_FORMAT_INVALID',\n message: 'Contact number must be in E.164 format (e.g., +60123456789)',\n severity: 'error',\n })\n }\n\n if (contactNumber.length < 8) {\n errors.push({\n field: 'contactNumber',\n code: 'CONTACT_LENGTH_INVALID',\n message: 'Contact number must be at least 8 characters',\n severity: 'error',\n })\n }\n\n return errors\n}\n\n/**\n * Validates monetary amounts\n */\nexport const validateMonetaryAmount = (\n amount: number,\n fieldName: string,\n maxDigits = 18,\n maxDecimals = 2,\n): ValidationError[] => {\n const errors: ValidationError[] = []\n\n if (amount < 0) {\n errors.push({\n field: fieldName,\n code: 'AMOUNT_NEGATIVE',\n message: `${fieldName} cannot be negative`,\n severity: 'error',\n })\n }\n\n // Check total digits\n const amountStr = amount.toString()\n const [integerPart, decimalPart] = amountStr.split('.')\n\n if (integerPart && integerPart.length > maxDigits - maxDecimals) {\n errors.push({\n field: fieldName,\n code: 'AMOUNT_DIGITS_EXCEEDED',\n message: `${fieldName} exceeds maximum ${maxDigits} digits`,\n severity: 'error',\n })\n }\n\n if (decimalPart && decimalPart.length > maxDecimals) {\n errors.push({\n field: fieldName,\n code: 'AMOUNT_DECIMALS_EXCEEDED',\n message: `${fieldName} exceeds maximum ${maxDecimals} decimal places`,\n severity: 'error',\n })\n }\n\n return errors\n}\n\n/**\n * Validates line item tax calculation consistency for both fixed rate and percentage taxation\n */\nexport const validateLineItemTax = (\n item: InvoiceLineItem,\n index: number,\n): ValidationError[] => {\n const errors: ValidationError[] = []\n const tolerance = 0.01\n\n // Check if tax calculation method is specified\n const hasFixedRate =\n item.taxPerUnitAmount !== undefined && item.baseUnitMeasure !== undefined\n const hasPercentageRate = item.taxRate !== undefined\n\n if (!hasFixedRate && !hasPercentageRate) {\n errors.push({\n field: `lineItem[${index}]`,\n code: 'TAX_METHOD_MISSING',\n message: `Line item ${index + 1} must specify either taxRate (for percentage) or taxPerUnitAmount + baseUnitMeasure (for fixed rate)`,\n severity: 'error',\n })\n return errors\n }\n\n if (hasFixedRate && hasPercentageRate) {\n errors.push({\n field: `lineItem[${index}]`,\n code: 'TAX_METHOD_CONFLICT',\n message: `Line item ${index + 1} cannot have both percentage and fixed rate tax methods`,\n severity: 'error',\n })\n }\n\n // Validate fixed rate tax calculation\n if (hasFixedRate) {\n if (item.baseUnitMeasureCode === undefined) {\n errors.push({\n field: `lineItem[${index}].baseUnitMeasureCode`,\n code: 'UNIT_CODE_MISSING',\n message: `Line item ${index + 1} with fixed rate tax must specify baseUnitMeasureCode`,\n severity: 'error',\n })\n }\n\n const expectedTaxAmount = item.taxPerUnitAmount! * item.baseUnitMeasure!\n if (Math.abs(item.taxAmount - expectedTaxAmount) > tolerance) {\n errors.push({\n field: `lineItem[${index}].taxAmount`,\n code: 'FIXED_TAX_CALCULATION_MISMATCH',\n message: `Line item ${index + 1} tax amount (${item.taxAmount}) doesn't match fixed rate calculation (${item.taxPerUnitAmount} × ${item.baseUnitMeasure} = ${expectedTaxAmount})`,\n severity: 'error',\n })\n }\n }\n\n // Validate percentage tax calculation\n if (hasPercentageRate && !hasFixedRate) {\n const expectedTaxAmount =\n (item.totalTaxableAmountPerLine * item.taxRate!) / 100\n if (Math.abs(item.taxAmount - expectedTaxAmount) > tolerance) {\n errors.push({\n field: `lineItem[${index}].taxAmount`,\n code: 'PERCENTAGE_TAX_CALCULATION_MISMATCH',\n message: `Line item ${index + 1} tax amount (${item.taxAmount}) doesn't match percentage calculation (${item.totalTaxableAmountPerLine} × ${item.taxRate}% = ${expectedTaxAmount})`,\n severity: 'error',\n })\n }\n }\n\n return errors\n}\n\n/**\n * Validates tax calculation consistency\n */\nexport const validateTaxCalculations = (\n invoice: InvoiceV1_1,\n): ValidationError[] => {\n const errors: ValidationError[] = []\n\n // Validate individual line item tax calculations\n invoice.invoiceLineItems.forEach((item, index) => {\n errors.push(...validateLineItemTax(item, index))\n })\n\n // Calculate expected totals from line items\n const expectedTaxExclusive = invoice.invoiceLineItems.reduce(\n (sum, item) => sum + item.totalTaxableAmountPerLine,\n 0,\n )\n const expectedTaxAmount = invoice.invoiceLineItems.reduce(\n (sum, item) => sum + item.taxAmount,\n 0,\n )\n\n // Allow small rounding differences (0.01)\n const tolerance = 0.01\n\n if (\n Math.abs(\n invoice.legalMonetaryTotal.taxExclusiveAmount - expectedTaxExclusive,\n ) > tolerance\n ) {\n errors.push({\n field: 'legalMonetaryTotal.taxExclusiveAmount',\n code: 'TAX_EXCLUSIVE_MISMATCH',\n message: `Tax exclusive amount (${invoice.legalMonetaryTotal.taxExclusiveAmount}) doesn't match sum of line items (${expectedTaxExclusive})`,\n severity: 'error',\n })\n }\n\n if (Math.abs(invoice.taxTotal.taxAmount - expectedTaxAmount) > tolerance) {\n errors.push({\n field: 'taxTotal.taxAmount',\n code: 'TAX_AMOUNT_MISMATCH',\n message: `Tax amount (${invoice.taxTotal.taxAmount}) doesn't match sum of line item taxes (${expectedTaxAmount})`,\n severity: 'error',\n })\n }\n\n return errors\n}\n\n/**\n * Main validation function for complete invoice\n */\nexport const validateInvoice = (invoice: InvoiceV1_1): ValidationResult => {\n const allErrors: ValidationError[] = []\n\n // Core field validations\n allErrors.push(\n ...validateTIN(invoice.supplier.tin, invoice.supplier.registrationType),\n )\n allErrors.push(\n ...validateTIN(invoice.buyer.tin, invoice.buyer.registrationType),\n )\n\n allErrors.push(...validateContactNumber(invoice.supplier.contactNumber))\n allErrors.push(...validateContactNumber(invoice.buyer.contactNumber))\n\n // Monetary validations\n allErrors.push(\n ...validateMonetaryAmount(\n invoice.legalMonetaryTotal.taxExclusiveAmount,\n 'taxExclusiveAmount',\n ),\n )\n allErrors.push(\n ...validateMonetaryAmount(\n invoice.legalMonetaryTotal.payableAmount,\n 'payableAmount',\n ),\n )\n allErrors.push(\n ...validateMonetaryAmount(invoice.taxTotal.taxAmount, 'taxAmount'),\n )\n\n // Line item validations\n invoice.invoiceLineItems.forEach((item, index) => {\n allErrors.push(\n ...validateMonetaryAmount(item.unitPrice, `lineItem[${index}].unitPrice`),\n )\n allErrors.push(\n ...validateMonetaryAmount(item.taxAmount, `lineItem[${index}].taxAmount`),\n )\n allErrors.push(\n ...validateMonetaryAmount(\n item.totalTaxableAmountPerLine,\n `lineItem[${index}].totalTaxableAmountPerLine`,\n ),\n )\n })\n\n // Business rule validations\n allErrors.push(...validateTaxCalculations(invoice))\n\n // Separate errors and warnings\n const errors = allErrors.filter(e => e.severity === 'error')\n const warnings = allErrors.filter(\n e => e.severity === 'warning',\n ) as ValidationWarning[]\n\n return {\n isValid: errors.length === 0,\n errors,\n warnings,\n }\n}\n"],"mappings":";;;;;AA6BA,MAAa,cAAc,CACzBA,KACAC,qBACsB;CACtB,MAAMC,SAA4B,CAAE;AAEpC,MAAK,KAAK;AACR,SAAO,KAAK;GACV,OAAO;GACP,MAAM;GACN,SAAS;GACT,UAAU;EACX,EAAC;AACF,SAAO;CACR;AAGD,KAAI,qBAAqB,UAAU,IAAI,WAAW,IAAI,CACpD,QAAO,KAAK;EACV,OAAO;EACP,MAAM;EACN,SAAS;EACT,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