@ripwords/myinvois-client 0.2.15 → 0.2.16
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/api/documentSubmission.js +2 -2
- package/dist/{document--5QdyrG2.cjs → document-CiBQaJ0c.cjs} +2 -6
- package/dist/{document--5QdyrG2.cjs.map → document-CiBQaJ0c.cjs.map} +1 -1
- package/dist/{document-B-ecipiP.js → document-SQQDNoI-.js} +1 -5
- package/dist/{documentSubmission-Ddn9kfXN.js → documentSubmission-B45EflkR.js} +1 -1
- package/dist/{documentSubmission-D3aRs6Es.cjs → documentSubmission-DG5pfaBQ.cjs} +2 -2
- package/dist/{documentSubmission-D3aRs6Es.cjs.map → documentSubmission-DG5pfaBQ.cjs.map} +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +2 -2
- package/dist/index10.cjs +16 -187
- package/dist/index10.cjs.map +1 -1
- package/dist/index12.cjs +25 -16
- package/dist/index12.cjs.map +1 -1
- package/dist/index13.cjs +24 -0
- package/dist/{index19.cjs.map → index13.cjs.map} +1 -1
- package/dist/index15.cjs +0 -29
- package/dist/index16.cjs +0 -25
- package/dist/index17.cjs +4 -0
- package/dist/index18.cjs +9 -30
- package/dist/index18.cjs.map +1 -1
- package/dist/index19.cjs +4 -23
- package/dist/index2.cjs +61 -4
- package/dist/{index8.cjs.map → index2.cjs.map} +1 -1
- package/dist/index20.cjs +20 -0
- package/dist/index21.cjs +3 -0
- package/dist/index22.cjs +3 -0
- package/dist/index23.cjs +329 -3
- package/dist/{index29.cjs.map → index23.cjs.map} +1 -1
- package/dist/index24.cjs +189 -9
- package/dist/index24.cjs.map +1 -1
- package/dist/index25.cjs +4 -4
- package/dist/index26.cjs +5 -18
- package/dist/index27.cjs +4 -2
- package/dist/index28.cjs +2 -2
- package/dist/index29.cjs +2 -329
- package/dist/index3.cjs +531 -6
- package/dist/index3.cjs.map +1 -0
- package/dist/index30.cjs +5 -192
- package/dist/index4.cjs +195 -4
- package/dist/index4.cjs.map +1 -0
- package/dist/index5.cjs +0 -3
- package/dist/index6.cjs +24 -2
- package/dist/index6.cjs.map +1 -0
- package/dist/index7.cjs +0 -6
- package/dist/index8.cjs +0 -62
- package/dist/index9.cjs +23 -526
- package/dist/index9.cjs.map +1 -1
- package/dist/utils/document.js +1 -1
- package/dist/utils/signature-diagnostics.js +1 -1
- package/package.json +1 -1
- package/dist/index15.cjs.map +0 -1
- package/dist/index16.cjs.map +0 -1
- package/dist/index30.cjs.map +0 -1
package/dist/index24.cjs
CHANGED
|
@@ -1,13 +1,193 @@
|
|
|
1
1
|
|
|
2
|
-
//#region src/utils/
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
};
|
|
9
185
|
|
|
10
186
|
//#endregion
|
|
11
|
-
exports.
|
|
12
|
-
exports.
|
|
187
|
+
exports.validateContactNumber = validateContactNumber;
|
|
188
|
+
exports.validateInvoice = validateInvoice;
|
|
189
|
+
exports.validateLineItemTax = validateLineItemTax;
|
|
190
|
+
exports.validateMonetaryAmount = validateMonetaryAmount;
|
|
191
|
+
exports.validateTIN = validateTIN;
|
|
192
|
+
exports.validateTaxCalculations = validateTaxCalculations;
|
|
13
193
|
//# sourceMappingURL=index24.cjs.map
|
package/dist/index24.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index24.cjs","names":["content: string"],"sources":["../src/utils/base64.ts"],"sourcesContent":["export function encodeToBase64(content: string): string {\n return Buffer.from(content).toString('base64')\n}\n\nexport function decodeFromBase64(content: string): string {\n return Buffer.from(content, 'base64').toString('utf-8')\n}\n"],"mappings":";;AAAA,SAAgB,eAAeA,SAAyB;AACtD,QAAO,OAAO,KAAK,QAAQ,CAAC,SAAS,SAAS;AAC/C;AAED,SAAgB,iBAAiBA,SAAyB;AACxD,QAAO,OAAO,KAAK,SAAS,SAAS,CAAC,SAAS,QAAQ;AACxD"}
|
|
1
|
+
{"version":3,"file":"index24.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":"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"}
|
package/dist/index25.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_documentManagement = require('./documentManagement-DQ7JEcBq.cjs');
|
|
2
2
|
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
exports.
|
|
3
|
+
exports.getDocument = require_documentManagement.getDocument;
|
|
4
|
+
exports.getDocumentDetails = require_documentManagement.getDocumentDetails;
|
|
5
|
+
exports.searchDocuments = require_documentManagement.searchDocuments;
|
package/dist/index26.cjs
CHANGED
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
require('./formatIdValue-i67o4kyD.cjs');
|
|
2
|
-
|
|
2
|
+
require('./document-CiBQaJ0c.cjs');
|
|
3
|
+
const require_documentSubmission = require('./documentSubmission-DG5pfaBQ.cjs');
|
|
3
4
|
|
|
4
|
-
exports.
|
|
5
|
-
exports.
|
|
6
|
-
exports.
|
|
7
|
-
exports.calculateInvoiceTotals = require_document.calculateInvoiceTotals;
|
|
8
|
-
exports.calculateSignedPropertiesDigest = require_document.calculateSignedPropertiesDigest;
|
|
9
|
-
exports.canonicalizeJSON = require_document.canonicalizeJSON;
|
|
10
|
-
exports.createFixedRateTaxLineItem = require_document.createFixedRateTaxLineItem;
|
|
11
|
-
exports.createPercentageTaxLineItem = require_document.createPercentageTaxLineItem;
|
|
12
|
-
exports.createSignedInfoAndSign = require_document.createSignedInfoAndSign;
|
|
13
|
-
exports.createSignedProperties = require_document.createSignedProperties;
|
|
14
|
-
exports.extractCertificateInfo = require_document.extractCertificateInfo;
|
|
15
|
-
exports.generateCleanInvoiceObject = require_document.generateCleanInvoiceObject;
|
|
16
|
-
exports.generateCleanUBLDocument = require_document.generateCleanUBLDocument;
|
|
17
|
-
exports.generateCompleteDocument = require_document.generateCompleteDocument;
|
|
18
|
-
exports.isFixedRateTax = require_document.isFixedRateTax;
|
|
19
|
-
exports.isPercentageTax = require_document.isPercentageTax;
|
|
20
|
-
exports.sortObjectKeys = require_document.sortObjectKeys;
|
|
5
|
+
exports.getSubmissionStatus = require_documentSubmission.getSubmissionStatus;
|
|
6
|
+
exports.performDocumentAction = require_documentSubmission.performDocumentAction;
|
|
7
|
+
exports.submitDocument = require_documentSubmission.submitDocument;
|
package/dist/index27.cjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_documentTypeManagement = require('./documentTypeManagement-D_-LiQVg.cjs');
|
|
2
2
|
|
|
3
|
-
exports.
|
|
3
|
+
exports.getDocumentType = require_documentTypeManagement.getDocumentType;
|
|
4
|
+
exports.getDocumentTypeVersion = require_documentTypeManagement.getDocumentTypeVersion;
|
|
5
|
+
exports.getDocumentTypes = require_documentTypeManagement.getDocumentTypes;
|
package/dist/index28.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_notificationManagement = require('./notificationManagement-DLBDn77E.cjs');
|
|
2
2
|
|
|
3
|
-
exports.
|
|
3
|
+
exports.getNotifications = require_notificationManagement.getNotifications;
|
package/dist/index29.cjs
CHANGED
|
@@ -1,330 +1,3 @@
|
|
|
1
|
-
const
|
|
2
|
-
require('./formatIdValue-i67o4kyD.cjs');
|
|
3
|
-
const require_document = require('./document--5QdyrG2.cjs');
|
|
4
|
-
const crypto = require_chunk.__toESM(require("crypto"));
|
|
1
|
+
const require_platformLogin = require('./platformLogin-Ch6hFKoU.cjs');
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Analyzes certificate for MyInvois compatibility issues
|
|
9
|
-
*/
|
|
10
|
-
function analyzeCertificateForDiagnostics(certificatePem) {
|
|
11
|
-
const issues = [];
|
|
12
|
-
const recommendations = [];
|
|
13
|
-
try {
|
|
14
|
-
const cert = new crypto.default.X509Certificate(certificatePem);
|
|
15
|
-
const certInfo = require_document.extractCertificateInfo(certificatePem);
|
|
16
|
-
const parseSubjectFields = (dn) => {
|
|
17
|
-
const fields = {};
|
|
18
|
-
dn.split("\n").forEach((line) => {
|
|
19
|
-
const trimmed = line.trim();
|
|
20
|
-
if (trimmed.includes("=")) {
|
|
21
|
-
const [key, ...valueParts] = trimmed.split("=");
|
|
22
|
-
if (key) fields[key.trim()] = valueParts.join("=").trim();
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
return fields;
|
|
26
|
-
};
|
|
27
|
-
const subjectFields = parseSubjectFields(cert.subject);
|
|
28
|
-
const organizationIdentifier = subjectFields["organizationIdentifier"] || subjectFields["2.5.4.97"];
|
|
29
|
-
const serialNumber = subjectFields["serialNumber"];
|
|
30
|
-
if (!organizationIdentifier) {
|
|
31
|
-
issues.push("DS311: Certificate missing organizationIdentifier field (TIN)");
|
|
32
|
-
recommendations.push("CRITICAL: Generate new certificate with organizationIdentifier matching your MyInvois TIN");
|
|
33
|
-
recommendations.push("Portal Error: \"Signer of invoice doesn't match the submitter of document. TIN doesn't match with the OI.\"");
|
|
34
|
-
} else if (organizationIdentifier.length < 10) {
|
|
35
|
-
issues.push("DS311: OrganizationIdentifier (TIN) appears too short - may cause submission rejection");
|
|
36
|
-
recommendations.push("Verify TIN format matches exactly what is registered in MyInvois");
|
|
37
|
-
}
|
|
38
|
-
if (!serialNumber) {
|
|
39
|
-
issues.push("DS312: Certificate missing serialNumber field (business registration)");
|
|
40
|
-
recommendations.push("CRITICAL: Generate new certificate with serialNumber matching your business registration");
|
|
41
|
-
recommendations.push("Portal Error: \"Submitter registration/identity number doesn't match with the certificate SERIALNUMBER.\"");
|
|
42
|
-
}
|
|
43
|
-
if (cert.issuer === cert.subject) {
|
|
44
|
-
issues.push("DS329: Self-signed certificate detected - will fail chain of trust validation");
|
|
45
|
-
recommendations.push("BLOCKING: Obtain certificate from MyInvois-approved CA:");
|
|
46
|
-
recommendations.push("• MSC Trustgate Sdn Bhd");
|
|
47
|
-
recommendations.push("• DigiCert Sdn Bhd");
|
|
48
|
-
recommendations.push("• Cybersign Asia Sdn Bhd");
|
|
49
|
-
recommendations.push("Portal Error: \"Certificate is not valid according to the chain of trust validation or has been issued by an untrusted certificate authority.\"");
|
|
50
|
-
} else {
|
|
51
|
-
const issuerName = cert.issuer.toLowerCase();
|
|
52
|
-
const approvedCAs = [
|
|
53
|
-
"msc trustgate",
|
|
54
|
-
"digicert",
|
|
55
|
-
"cybersign"
|
|
56
|
-
];
|
|
57
|
-
const isFromApprovedCA = approvedCAs.some((ca) => issuerName.includes(ca));
|
|
58
|
-
if (!isFromApprovedCA) {
|
|
59
|
-
issues.push("DS329: Certificate may not be from MyInvois-approved CA");
|
|
60
|
-
recommendations.push("Verify certificate was issued by an approved CA for MyInvois");
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
const rawIssuer = cert.issuer;
|
|
64
|
-
const normalizedIssuer = certInfo.issuerName;
|
|
65
|
-
const normalizedIssuerIssues = [
|
|
66
|
-
{
|
|
67
|
-
check: normalizedIssuer.includes("\n"),
|
|
68
|
-
issue: "Normalized issuer still contains newlines"
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
check: normalizedIssuer.includes(" "),
|
|
72
|
-
issue: "Normalized issuer contains double spaces"
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
check: /=\s+/.test(normalizedIssuer),
|
|
76
|
-
issue: "Normalized issuer has spaces after equals"
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
check: /\s+=/.test(normalizedIssuer),
|
|
80
|
-
issue: "Normalized issuer has spaces before equals"
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
check: normalizedIssuer.includes("\r"),
|
|
84
|
-
issue: "Normalized issuer contains carriage returns"
|
|
85
|
-
}
|
|
86
|
-
];
|
|
87
|
-
const hasActualFormatIssues = normalizedIssuerIssues.some(({ check, issue }) => {
|
|
88
|
-
if (check) {
|
|
89
|
-
issues.push(`DS326: ${issue} - will cause X509IssuerName mismatch`);
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
return false;
|
|
93
|
-
});
|
|
94
|
-
const hasRawIssuesButNormalizedOk = rawIssuer.includes("\n") && !normalizedIssuer.includes("\n");
|
|
95
|
-
if (hasActualFormatIssues) {
|
|
96
|
-
recommendations.push("CRITICAL: Fix issuer name normalization in signature generation");
|
|
97
|
-
recommendations.push("Portal Error: \"Certificate X509IssuerName doesn't match the X509IssuerName value provided in the signed properties section.\"");
|
|
98
|
-
recommendations.push("The normalization function is not properly formatting the issuer name");
|
|
99
|
-
recommendations.push("Debug: Check document.ts extractCertificateInfo() normalization logic");
|
|
100
|
-
} else if (hasRawIssuesButNormalizedOk) console.log("ℹ️ Note: Raw certificate issuer has newlines but normalization is handling them correctly");
|
|
101
|
-
const now = /* @__PURE__ */ new Date();
|
|
102
|
-
const validFrom = new Date(cert.validFrom);
|
|
103
|
-
const validTo = new Date(cert.validTo);
|
|
104
|
-
if (now < validFrom) {
|
|
105
|
-
issues.push("DS329: Certificate not yet valid (future start date)");
|
|
106
|
-
recommendations.push("Wait until certificate validity period begins");
|
|
107
|
-
}
|
|
108
|
-
if (now > validTo) {
|
|
109
|
-
issues.push("DS329: Certificate has expired");
|
|
110
|
-
recommendations.push("BLOCKING: Renew certificate - expired certificates are rejected");
|
|
111
|
-
}
|
|
112
|
-
try {
|
|
113
|
-
if (cert.keyUsage && !cert.keyUsage.includes("digital signature")) {
|
|
114
|
-
issues.push("DS333: Certificate lacks digitalSignature key usage");
|
|
115
|
-
recommendations.push("Generate new certificate with digitalSignature key usage enabled");
|
|
116
|
-
}
|
|
117
|
-
} catch {
|
|
118
|
-
console.log("Note: Could not check key usage extensions");
|
|
119
|
-
}
|
|
120
|
-
return {
|
|
121
|
-
organizationIdentifier,
|
|
122
|
-
serialNumber,
|
|
123
|
-
issuerName: certInfo.issuerName,
|
|
124
|
-
subjectName: certInfo.subjectName,
|
|
125
|
-
issues,
|
|
126
|
-
recommendations
|
|
127
|
-
};
|
|
128
|
-
} catch (error) {
|
|
129
|
-
issues.push(`Certificate parsing failed: ${error}`);
|
|
130
|
-
recommendations.push("Verify certificate format and validity");
|
|
131
|
-
return {
|
|
132
|
-
issuerName: "",
|
|
133
|
-
subjectName: "",
|
|
134
|
-
issues,
|
|
135
|
-
recommendations
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Analyzes signature generation for potential issues
|
|
141
|
-
*/
|
|
142
|
-
function analyzeSignatureForDiagnostics(invoices, certificatePem) {
|
|
143
|
-
const issues = [];
|
|
144
|
-
const recommendations = [];
|
|
145
|
-
try {
|
|
146
|
-
const documentDigest = require_document.calculateDocumentDigest(invoices);
|
|
147
|
-
const certificateDigest = require_document.calculateCertificateDigest(certificatePem);
|
|
148
|
-
const certInfo = require_document.extractCertificateInfo(certificatePem);
|
|
149
|
-
const signingTime = (/* @__PURE__ */ new Date()).toISOString();
|
|
150
|
-
const signedProperties = require_document.createSignedProperties(certificateDigest, signingTime, certInfo.issuerName, certInfo.serialNumber);
|
|
151
|
-
const signedPropertiesDigest = require_document.calculateSignedPropertiesDigest(signedProperties);
|
|
152
|
-
if (documentDigest.length === 0) {
|
|
153
|
-
issues.push("DS333: Document digest generation failed");
|
|
154
|
-
recommendations.push("CRITICAL: Verify document serialization excludes UBLExtensions/Signature");
|
|
155
|
-
recommendations.push("Portal Error: \"Document signature value is not a valid signature of the document digest using the public key of the certificate provided.\"");
|
|
156
|
-
}
|
|
157
|
-
if (certificateDigest.length === 0) {
|
|
158
|
-
issues.push("DS333: Certificate digest generation failed");
|
|
159
|
-
recommendations.push("CRITICAL: Verify certificate format and encoding");
|
|
160
|
-
recommendations.push("Certificate must be properly base64 encoded without headers/footers");
|
|
161
|
-
}
|
|
162
|
-
if (signedPropertiesDigest.length === 0) {
|
|
163
|
-
issues.push("DS333: Signed properties digest generation failed");
|
|
164
|
-
recommendations.push("CRITICAL: Verify signed properties structure and canonicalization");
|
|
165
|
-
recommendations.push("Check XML canonicalization (C14N) is applied correctly");
|
|
166
|
-
}
|
|
167
|
-
try {
|
|
168
|
-
const cert = new crypto.default.X509Certificate(certificatePem);
|
|
169
|
-
const publicKey = cert.publicKey;
|
|
170
|
-
const keyDetails = publicKey.asymmetricKeyDetails;
|
|
171
|
-
if (keyDetails) {
|
|
172
|
-
if (publicKey.asymmetricKeyType === "rsa" && keyDetails.modulusLength && keyDetails.modulusLength < 2048) {
|
|
173
|
-
issues.push("DS333: RSA key size too small (minimum 2048 bits required)");
|
|
174
|
-
recommendations.push("CRITICAL: Generate new certificate with RSA 2048+ bits");
|
|
175
|
-
}
|
|
176
|
-
const supportedKeyTypes = ["rsa", "ec"];
|
|
177
|
-
if (!supportedKeyTypes.includes(publicKey.asymmetricKeyType || "")) {
|
|
178
|
-
issues.push(`DS333: Unsupported key type: ${publicKey.asymmetricKeyType}`);
|
|
179
|
-
recommendations.push("CRITICAL: Use RSA or EC key types for MyInvois compatibility");
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
const certBuffer = Buffer.from(certificatePem.replace(/-----[^-]+-----/g, "").replace(/\s/g, ""), "base64");
|
|
183
|
-
if (certBuffer.length === 0) {
|
|
184
|
-
issues.push("DS333: Certificate encoding appears invalid");
|
|
185
|
-
recommendations.push("CRITICAL: Verify certificate is properly PEM encoded");
|
|
186
|
-
}
|
|
187
|
-
} catch (error) {
|
|
188
|
-
issues.push(`DS333: Certificate validation failed - ${error}`);
|
|
189
|
-
recommendations.push("CRITICAL: Verify certificate format and structure are valid");
|
|
190
|
-
}
|
|
191
|
-
const isValidBase64 = (str) => {
|
|
192
|
-
try {
|
|
193
|
-
return Buffer.from(str, "base64").toString("base64") === str;
|
|
194
|
-
} catch {
|
|
195
|
-
return false;
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
if (documentDigest && !isValidBase64(documentDigest)) {
|
|
199
|
-
issues.push("DS333: Document digest is not valid base64 format");
|
|
200
|
-
recommendations.push("Ensure digest is properly base64 encoded");
|
|
201
|
-
}
|
|
202
|
-
if (certificateDigest && !isValidBase64(certificateDigest)) {
|
|
203
|
-
issues.push("DS333: Certificate digest is not valid base64 format");
|
|
204
|
-
recommendations.push("Ensure certificate digest is properly base64 encoded");
|
|
205
|
-
}
|
|
206
|
-
if (signedPropertiesDigest && !isValidBase64(signedPropertiesDigest)) {
|
|
207
|
-
issues.push("DS333: Signed properties digest is not valid base64 format");
|
|
208
|
-
recommendations.push("Ensure signed properties digest is properly base64 encoded");
|
|
209
|
-
}
|
|
210
|
-
return {
|
|
211
|
-
documentDigest,
|
|
212
|
-
certificateDigest,
|
|
213
|
-
signedPropertiesDigest,
|
|
214
|
-
issues,
|
|
215
|
-
recommendations
|
|
216
|
-
};
|
|
217
|
-
} catch (error) {
|
|
218
|
-
issues.push(`Signature analysis failed: ${error}`);
|
|
219
|
-
recommendations.push("Review signature generation implementation");
|
|
220
|
-
return {
|
|
221
|
-
documentDigest: "",
|
|
222
|
-
certificateDigest: "",
|
|
223
|
-
signedPropertiesDigest: "",
|
|
224
|
-
issues,
|
|
225
|
-
recommendations
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Comprehensive signature diagnostics
|
|
231
|
-
*/
|
|
232
|
-
function diagnoseSignatureIssues(invoices, certificatePem) {
|
|
233
|
-
const certificateAnalysis = analyzeCertificateForDiagnostics(certificatePem);
|
|
234
|
-
const signatureAnalysis = analyzeSignatureForDiagnostics(invoices, certificatePem);
|
|
235
|
-
const certificateIssues = certificateAnalysis.issues.length;
|
|
236
|
-
const signatureIssues = signatureAnalysis.issues.length;
|
|
237
|
-
return {
|
|
238
|
-
certificateAnalysis,
|
|
239
|
-
signatureAnalysis,
|
|
240
|
-
summary: {
|
|
241
|
-
totalIssues: certificateIssues + signatureIssues,
|
|
242
|
-
certificateIssues,
|
|
243
|
-
signatureIssues
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Prints diagnostic results in a formatted way
|
|
249
|
-
*/
|
|
250
|
-
function printDiagnostics(result) {
|
|
251
|
-
console.log("\n🔍 MyInvois Signature Diagnostics Report");
|
|
252
|
-
console.log("=".repeat(60));
|
|
253
|
-
console.log("\n📜 CERTIFICATE ANALYSIS");
|
|
254
|
-
console.log("-".repeat(30));
|
|
255
|
-
console.log(` Issuer: ${result.certificateAnalysis.issuerName}`);
|
|
256
|
-
console.log(` Subject: ${result.certificateAnalysis.subjectName}`);
|
|
257
|
-
if (result.certificateAnalysis.organizationIdentifier) console.log(` Organization ID (TIN): ${result.certificateAnalysis.organizationIdentifier}`);
|
|
258
|
-
if (result.certificateAnalysis.serialNumber) console.log(` Serial Number: ${result.certificateAnalysis.serialNumber}`);
|
|
259
|
-
if (result.certificateAnalysis.issues.length > 0) {
|
|
260
|
-
console.log("\n 🚨 Certificate Issues:");
|
|
261
|
-
result.certificateAnalysis.issues.forEach((issue, index) => {
|
|
262
|
-
console.log(` ${index + 1}. ${issue}`);
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
if (result.certificateAnalysis.recommendations.length > 0) {
|
|
266
|
-
console.log("\n 💡 Certificate Recommendations:");
|
|
267
|
-
result.certificateAnalysis.recommendations.forEach((rec, index) => {
|
|
268
|
-
console.log(` ${index + 1}. ${rec}`);
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
console.log("\n🔐 SIGNATURE ANALYSIS");
|
|
272
|
-
console.log("-".repeat(30));
|
|
273
|
-
console.log(` Document Digest: ${result.signatureAnalysis.documentDigest.substring(0, 32)}...`);
|
|
274
|
-
console.log(` Certificate Digest: ${result.signatureAnalysis.certificateDigest.substring(0, 32)}...`);
|
|
275
|
-
console.log(` Signed Properties Digest: ${result.signatureAnalysis.signedPropertiesDigest.substring(0, 32)}...`);
|
|
276
|
-
if (result.signatureAnalysis.issues.length > 0) {
|
|
277
|
-
console.log("\n 🚨 Signature Issues:");
|
|
278
|
-
result.signatureAnalysis.issues.forEach((issue, index) => {
|
|
279
|
-
console.log(` ${index + 1}. ${issue}`);
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
if (result.signatureAnalysis.recommendations.length > 0) {
|
|
283
|
-
console.log("\n 💡 Signature Recommendations:");
|
|
284
|
-
result.signatureAnalysis.recommendations.forEach((rec, index) => {
|
|
285
|
-
console.log(` ${index + 1}. ${rec}`);
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
console.log("\n📊 SUMMARY");
|
|
289
|
-
console.log("-".repeat(30));
|
|
290
|
-
console.log(` Total Issues Found: ${result.summary.totalIssues}`);
|
|
291
|
-
console.log(` Certificate Issues: ${result.summary.certificateIssues}`);
|
|
292
|
-
console.log(` Signature Issues: ${result.summary.signatureIssues}`);
|
|
293
|
-
if (result.summary.totalIssues === 0) {
|
|
294
|
-
console.log("\n ✅ No issues detected in current analysis");
|
|
295
|
-
console.log(" 🎉 Certificate and signature implementation appear valid");
|
|
296
|
-
} else {
|
|
297
|
-
console.log("\n ⚠️ Issues detected - review recommendations above");
|
|
298
|
-
const hasDS311 = result.certificateAnalysis.issues.some((issue) => issue.includes("DS311"));
|
|
299
|
-
const hasDS312 = result.certificateAnalysis.issues.some((issue) => issue.includes("DS312"));
|
|
300
|
-
const hasDS326 = result.certificateAnalysis.issues.some((issue) => issue.includes("DS326"));
|
|
301
|
-
const hasDS329 = result.certificateAnalysis.issues.some((issue) => issue.includes("DS329"));
|
|
302
|
-
const hasDS333 = result.signatureAnalysis.issues.some((issue) => issue.includes("DS333"));
|
|
303
|
-
console.log("\n 🎯 MYINVOIS PORTAL ERROR ANALYSIS:");
|
|
304
|
-
if (hasDS311) console.log(" ❌ DS311 - TIN mismatch between certificate and submitter");
|
|
305
|
-
if (hasDS312) console.log(" ❌ DS312 - Registration number mismatch with certificate");
|
|
306
|
-
if (hasDS326) console.log(" ❌ DS326 - X509IssuerName format inconsistency");
|
|
307
|
-
if (hasDS329) console.log(" ❌ DS329 - Certificate trust chain validation failure");
|
|
308
|
-
if (hasDS333) console.log(" ❌ DS333 - Document signature validation failure");
|
|
309
|
-
if (result.summary.certificateIssues > 0) {
|
|
310
|
-
console.log("\n 🚨 PRIMARY ACTION REQUIRED:");
|
|
311
|
-
console.log(" Certificate issues must be resolved first");
|
|
312
|
-
console.log(" Self-generated certificates cannot pass MyInvois validation");
|
|
313
|
-
}
|
|
314
|
-
if (result.summary.signatureIssues > 0) {
|
|
315
|
-
console.log("\n ⚙️ SECONDARY ACTION:");
|
|
316
|
-
console.log(" Review and optimize signature implementation");
|
|
317
|
-
}
|
|
318
|
-
console.log("\n 📋 NEXT STEPS:");
|
|
319
|
-
console.log(" 1. Address BLOCKING/CRITICAL issues first");
|
|
320
|
-
console.log(" 2. Test with updated certificate/implementation");
|
|
321
|
-
console.log(" 3. Re-run diagnostics to verify fixes");
|
|
322
|
-
console.log(" 4. Submit test document to MyInvois portal");
|
|
323
|
-
}
|
|
324
|
-
console.log("\n" + "=".repeat(60));
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
//#endregion
|
|
328
|
-
exports.diagnoseSignatureIssues = diagnoseSignatureIssues;
|
|
329
|
-
exports.printDiagnostics = printDiagnostics;
|
|
330
|
-
//# sourceMappingURL=index29.cjs.map
|
|
3
|
+
exports.platformLogin = require_platformLogin.platformLogin;
|