@ripwords/myinvois-client 0.2.4 → 0.2.5

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 (38) hide show
  1. package/dist/api/documentManagement.d.ts +2 -2
  2. package/dist/api/documentSubmission.d.ts +2 -2
  3. package/dist/api/documentSubmission.js +2 -2
  4. package/dist/api/documentTypeManagement.d.ts +2 -2
  5. package/dist/api/notificationManagement.d.ts +2 -2
  6. package/dist/api/platformLogin.d.ts +2 -2
  7. package/dist/api/taxpayerValidation.d.ts +2 -2
  8. package/dist/{document-BSuYbfXR.js → document-BvyYSCPx.js} +85 -1
  9. package/dist/{document-vDphtJTv.cjs → document-djvnrrZo.cjs} +121 -1
  10. package/dist/document-djvnrrZo.cjs.map +1 -0
  11. package/dist/{documentSubmission-BdJxIB_I.js → documentSubmission-695VhFA8.js} +1 -1
  12. package/dist/{documentSubmission-D5TC0MPC.cjs → documentSubmission-CK1zOsSV.cjs} +2 -2
  13. package/dist/{documentSubmission-D5TC0MPC.cjs.map → documentSubmission-CK1zOsSV.cjs.map} +1 -1
  14. package/dist/{documents-zzL50wnG.d.ts → documents-Br8I8SvT.d.ts} +37 -2
  15. package/dist/{documents-DCOYxz61.d.cts → documents-BuH9ULyn.d.cts} +38 -3
  16. package/dist/index.cjs +2 -2
  17. package/dist/index.d.ts +2 -2
  18. package/dist/index.js +2 -2
  19. package/dist/index18.cjs +2 -2
  20. package/dist/index25.cjs +7 -1
  21. package/dist/index27.cjs +1 -1
  22. package/dist/index28.cjs +53 -0
  23. package/dist/index28.cjs.map +1 -1
  24. package/dist/index70.cts.map +1 -1
  25. package/dist/index73.cts.map +1 -1
  26. package/dist/{taxpayer-CxAVm7lJ.d.ts → taxpayer-5MlboTnW.d.ts} +1 -1
  27. package/dist/{taxpayer-aaXyVf7B.d.cts → taxpayer-DVjaFzJw.d.cts} +2 -2
  28. package/dist/types/documents.d.ts +1 -1
  29. package/dist/types/index.d.ts +2 -2
  30. package/dist/types/taxpayer.d.ts +2 -2
  31. package/dist/utils/document.d.ts +54 -3
  32. package/dist/utils/document.js +2 -2
  33. package/dist/utils/signature-diagnostics.d.ts +2 -2
  34. package/dist/utils/signature-diagnostics.js +1 -1
  35. package/dist/utils/validation.d.ts +65 -3
  36. package/dist/utils/validation.js +53 -1
  37. package/package.json +1 -1
  38. package/dist/document-vDphtJTv.cjs.map +0 -1
@@ -136,12 +136,33 @@ interface InvoiceLineItem {
136
136
  */
137
137
  taxType: TaxTypeCode;
138
138
  /**
139
- * Tax rate. Max 18 digits, 2 decimal places.
139
+ * Tax rate percentage. Max 18 digits, 2 decimal places.
140
+ * Used for percentage-based taxation.
140
141
  * @example 6.00
141
142
  */
142
- taxRate: number;
143
+ taxRate?: number;
144
+ /**
145
+ * Tax amount per unit for fixed rate taxation. Max 18 digits, 2 decimal places.
146
+ * Used when tax is calculated as a fixed amount per unit.
147
+ * @example 10.00
148
+ */
149
+ taxPerUnitAmount?: number;
150
+ /**
151
+ * Number of units for fixed rate taxation.
152
+ * Used when tax is calculated as a fixed amount per unit.
153
+ * @example 5
154
+ */
155
+ baseUnitMeasure?: number;
156
+ /**
157
+ * Unit code for BaseUnitMeasure (e.g., 'C62' for units, 'DAY' for days).
158
+ * Required when using fixed rate taxation.
159
+ * @example 'C62'
160
+ */
161
+ baseUnitMeasureCode?: string;
143
162
  /**
144
163
  * Tax amount. Max 18 digits, 2 decimal places.
164
+ * For percentage tax: calculated as taxableAmount * taxRate / 100
165
+ * For fixed rate: calculated as taxPerUnitAmount * baseUnitMeasure
145
166
  * @example 90.00
146
167
  */
147
168
  taxAmount: number;
@@ -529,6 +550,20 @@ interface InvoiceSubmission {
529
550
  _: number;
530
551
  currencyID: string;
531
552
  }[];
553
+ /** For percentage-based taxation */
554
+ Percent?: {
555
+ _: number;
556
+ }[];
557
+ /** For fixed rate taxation - Total Amount per Unit */
558
+ PerUnitAmount?: {
559
+ _: number;
560
+ currencyID: string;
561
+ }[];
562
+ /** For fixed rate taxation - Number of Units */
563
+ BaseUnitMeasure?: {
564
+ _: number;
565
+ unitCode: string;
566
+ }[];
532
567
  TaxCategory: {
533
568
  ID: {
534
569
  _: string;
@@ -891,4 +926,4 @@ interface DocumentTypeVersionResponse {
891
926
  }
892
927
  //#endregion
893
928
  export { Address, Buyer, CompleteInvoice, DocumentStatus, DocumentSummary, DocumentTypeResponse, DocumentTypeVersion, DocumentTypeVersionResponse, DocumentTypesResponse, DocumentValidationResult, DocumentValidationStepResult, FinalDocumentData, GetSubmissionResponse, InvoiceLineItem, InvoiceSubmission, InvoiceV1_1, LegalMonetaryTotal, RegistrationType, ResponseDocument, SignedInfoObject, SignedInvoiceSubmission, SignedPropertiesData, SignedPropertiesObject, SigningCredentials, StandardError, SubmissionResponse, SubmissionStatus, Supplier, TaxCategory, TaxSubtotal, TaxTotal, UBLDocument, WorkflowParameter };
894
- //# sourceMappingURL=documents-DCOYxz61.d.cts.map
929
+ //# sourceMappingURL=documents-BuH9ULyn.d.cts.map
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  const require_documentManagement = require('./documentManagement-DQ7JEcBq.cjs');
2
- require('./document-vDphtJTv.cjs');
3
- const require_documentSubmission = require('./documentSubmission-D5TC0MPC.cjs');
2
+ require('./document-djvnrrZo.cjs');
3
+ const require_documentSubmission = require('./documentSubmission-CK1zOsSV.cjs');
4
4
  const require_documentTypeManagement = require('./documentTypeManagement-DXRLfTsW.cjs');
5
5
  const require_notificationManagement = require('./notificationManagement-C_qrFwWL.cjs');
6
6
  const require_platformLogin = require('./platformLogin-CPiPiVUh.cjs');
package/dist/index.d.ts CHANGED
@@ -15,7 +15,7 @@ import "./9X-_XRgT2-_.js";
15
15
  import { MSICCode } from "./msic-codes-CiPeemFK.js";
16
16
  import { TaxType, TaxTypeCode, TaxTypeCodeEnum } from "./tax-types-BskcyNBv.js";
17
17
  import { State, StateCode, StateCodeEnum } from "./state-codes-BaGjZcA8.js";
18
- import { Address, Buyer, CompleteInvoice, DocumentStatus, DocumentSummary, DocumentTypeResponse, DocumentTypeVersion, DocumentTypeVersionResponse, DocumentTypesResponse, DocumentValidationResult, DocumentValidationStepResult, FinalDocumentData, GetSubmissionResponse, InvoiceLineItem, InvoiceSubmission, InvoiceV1_1, LegalMonetaryTotal, RegistrationType, ResponseDocument, SignedInfoObject, SignedInvoiceSubmission, SignedPropertiesData, SignedPropertiesObject, SigningCredentials, StandardError, SubmissionResponse, SubmissionStatus, Supplier, TaxCategory, TaxSubtotal, TaxTotal, UBLDocument, WorkflowParameter } from "./documents-zzL50wnG.js";
18
+ import { Address, Buyer, CompleteInvoice, DocumentStatus, DocumentSummary, DocumentTypeResponse, DocumentTypeVersion, DocumentTypeVersionResponse, DocumentTypesResponse, DocumentValidationResult, DocumentValidationStepResult, FinalDocumentData, GetSubmissionResponse, InvoiceLineItem, InvoiceSubmission, InvoiceV1_1, LegalMonetaryTotal, RegistrationType, ResponseDocument, SignedInfoObject, SignedInvoiceSubmission, SignedPropertiesData, SignedPropertiesObject, SigningCredentials, StandardError, SubmissionResponse, SubmissionStatus, Supplier, TaxCategory, TaxSubtotal, TaxTotal, UBLDocument, WorkflowParameter } from "./documents-Br8I8SvT.js";
19
19
  import { PaymentMode, PaymentModeCode, PaymentModeCodeEnum } from "./payment-modes-NpE3OcCV.js";
20
20
  import "./1X-C72Wa4pk.js";
21
21
  import "./2X-CH89y3Af.js";
@@ -55,7 +55,7 @@ import "./XX-DOA-10JW.js";
55
55
  import { UnitType, UnitTypeCode } from "./unit-types-VgYXIwTT.js";
56
56
  import { CanonicalizationMethod, Cert, CertDigest, DigestMethod, IssuerDigitalSignature, IssuerSerial, KeyInfo, QualifyingProperties, Reference, SignatureMethod, SignedInfo, SignedProperties, SignedSignatureProperties, SigningCertificate, Transform, X509Data } from "./signatures-C-nCPDqt.js";
57
57
  import { Notification, NotificationDeliveryAttempt, NotificationMetadata, NotificationResponse, NotificationSearchParams, NotificationStatus, NotificationStatusEnum, NotificationType, NotificationTypeEnum } from "./notifications-B4l_qRj7.js";
58
- import { TaxpayerQRCodeResponse, TinSearchParams, TinSearchResponse } from "./taxpayer-CxAVm7lJ.js";
58
+ import { TaxpayerQRCodeResponse, TinSearchParams, TinSearchResponse } from "./taxpayer-5MlboTnW.js";
59
59
  import { Fetch } from "./utils-B3mo51Zp.js";
60
60
  import { ClientCredentials, TokenResponse } from "./index-FTgB2nM6.js";
61
61
 
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { getDocument, getDocumentDetails, searchDocuments } from "./documentManagement-CIQPkmyb.js";
2
- import "./document-BSuYbfXR.js";
3
- import { getSubmissionStatus, performDocumentAction, submitDocument } from "./documentSubmission-BdJxIB_I.js";
2
+ import "./document-BvyYSCPx.js";
3
+ import { getSubmissionStatus, performDocumentAction, submitDocument } from "./documentSubmission-695VhFA8.js";
4
4
  import { getDocumentType, getDocumentTypeVersion, getDocumentTypes } from "./documentTypeManagement-tojgXfm9.js";
5
5
  import { getNotifications } from "./notificationManagement-CHDRVy8J.js";
6
6
  import { platformLogin } from "./platformLogin-Ck1Fge2n.js";
package/dist/index18.cjs CHANGED
@@ -1,5 +1,5 @@
1
- require('./document-vDphtJTv.cjs');
2
- const require_documentSubmission = require('./documentSubmission-D5TC0MPC.cjs');
1
+ require('./document-djvnrrZo.cjs');
2
+ const require_documentSubmission = require('./documentSubmission-CK1zOsSV.cjs');
3
3
 
4
4
  exports.getSubmissionStatus = require_documentSubmission.getSubmissionStatus;
5
5
  exports.performDocumentAction = require_documentSubmission.performDocumentAction;
package/dist/index25.cjs CHANGED
@@ -1,13 +1,19 @@
1
- const require_document = require('./document-vDphtJTv.cjs');
1
+ const require_document = require('./document-djvnrrZo.cjs');
2
2
 
3
3
  exports.calculateCertificateDigest = require_document.calculateCertificateDigest;
4
4
  exports.calculateDocumentDigest = require_document.calculateDocumentDigest;
5
+ exports.calculateExpectedTaxAmount = require_document.calculateExpectedTaxAmount;
6
+ exports.calculateInvoiceTotals = require_document.calculateInvoiceTotals;
5
7
  exports.calculateSignedPropertiesDigest = require_document.calculateSignedPropertiesDigest;
6
8
  exports.canonicalizeJSON = require_document.canonicalizeJSON;
9
+ exports.createFixedRateTaxLineItem = require_document.createFixedRateTaxLineItem;
10
+ exports.createPercentageTaxLineItem = require_document.createPercentageTaxLineItem;
7
11
  exports.createSignedInfoAndSign = require_document.createSignedInfoAndSign;
8
12
  exports.createSignedProperties = require_document.createSignedProperties;
9
13
  exports.extractCertificateInfo = require_document.extractCertificateInfo;
10
14
  exports.generateCleanInvoiceObject = require_document.generateCleanInvoiceObject;
11
15
  exports.generateCleanUBLDocument = require_document.generateCleanUBLDocument;
12
16
  exports.generateCompleteDocument = require_document.generateCompleteDocument;
17
+ exports.isFixedRateTax = require_document.isFixedRateTax;
18
+ exports.isPercentageTax = require_document.isPercentageTax;
13
19
  exports.sortObjectKeys = require_document.sortObjectKeys;
package/dist/index27.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const require_document = require('./document-vDphtJTv.cjs');
2
+ const require_document = require('./document-djvnrrZo.cjs');
3
3
  const crypto = require_chunk.__toESM(require("crypto"));
4
4
 
5
5
  //#region src/utils/signature-diagnostics.ts
package/dist/index28.cjs CHANGED
@@ -83,10 +83,62 @@ const validateMonetaryAmount = (amount, fieldName, maxDigits = 18, maxDecimals =
83
83
  return errors;
84
84
  };
85
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
+ /**
86
135
  * Validates tax calculation consistency
87
136
  */
88
137
  const validateTaxCalculations = (invoice) => {
89
138
  const errors = [];
139
+ invoice.invoiceLineItems.forEach((item, index) => {
140
+ errors.push(...validateLineItemTax(item, index));
141
+ });
90
142
  const expectedTaxExclusive = invoice.invoiceLineItems.reduce((sum, item) => sum + item.totalTaxableAmountPerLine, 0);
91
143
  const expectedTaxAmount = invoice.invoiceLineItems.reduce((sum, item) => sum + item.taxAmount, 0);
92
144
  const tolerance = .01;
@@ -134,6 +186,7 @@ const validateInvoice = (invoice) => {
134
186
  //#endregion
135
187
  exports.validateContactNumber = validateContactNumber;
136
188
  exports.validateInvoice = validateInvoice;
189
+ exports.validateLineItemTax = validateLineItemTax;
137
190
  exports.validateMonetaryAmount = validateMonetaryAmount;
138
191
  exports.validateTIN = validateTIN;
139
192
  exports.validateTaxCalculations = validateTaxCalculations;
@@ -1 +1 @@
1
- {"version":3,"file":"index28.cjs","names":["tin: string","registrationType?: string","errors: ValidationError[]","contactNumber: string","amount: number","fieldName: string","invoice: InvoiceV1_1","allErrors: ValidationError[]"],"sources":["../src/utils/validation.ts"],"sourcesContent":["import type { InvoiceV1_1 } from '../types/documents/index.js'\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 tax calculation consistency\n */\nexport const validateTaxCalculations = (\n invoice: InvoiceV1_1,\n): ValidationError[] => {\n const errors: ValidationError[] = []\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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"}
1
+ {"version":3,"file":"index28.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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"}
@@ -1 +1 @@
1
- {"version":3,"file":"index70.cts","names":[],"sources":["../src/utils/document.d.ts"],"sourcesContent":["import { InvoiceSubmission, InvoiceV1_1, SigningCredentials, SignedPropertiesObject, UBLDocument, CompleteInvoice, SignedInfoObject } from '../types';\n/**\n * MyInvois v1.1 Document Generation and Signing Utilities\n * Strictly follows: https://sdk.myinvois.hasil.gov.my/documents/invoice-v1-1\n * JSON Signature Guide: https://sdk.myinvois.hasil.gov.my/signature-creation-json/\n */\n/**\n * Helper function to recursively sort object keys for JSON canonicalization\n */\nexport declare function sortObjectKeys(obj: unknown): unknown;\n/**\n * Enhanced canonicalization following MyInvois specification exactly\n * Key changes: ensure consistent ordering and formatting\n */\nexport declare const canonicalizeJSON: (obj: unknown) => string;\n/**\n * Generates a clean invoice object following MyInvois v1.1 specification exactly\n * This is the base invoice structure WITHOUT signature elements (for hash calculation)\n *\n * Key requirements from working documents:\n * - All mandatory fields must be present\n * - Many optional fields must be present even if empty\n * - Specific field ordering and structure\n * - Correct listID values (e.g., \"3166-1\" not \"ISO3166-1\")\n */\nexport declare const generateCleanInvoiceObject: (invoice: InvoiceV1_1) => InvoiceSubmission;\n/**\n * Generates the complete UBL document structure with namespace declarations\n */\nexport declare const generateCleanUBLDocument: (invoices: InvoiceV1_1[]) => UBLDocument;\n/**\n * Step 2: Calculate Document Digest\n * FIXED: Remove UBLExtensions and Signature before hashing (DS322)\n * Based on working implementation pattern\n */\nexport declare const calculateDocumentDigest: (invoices: InvoiceV1_1[]) => string;\n/**\n * Step 4: Calculate Certificate Digest\n * Enhanced to handle certificate content properly\n */\nexport declare const calculateCertificateDigest: (certificatePem: string) => string;\n/**\n * Enhanced certificate info extraction with better error handling\n * FIXED: Normalize issuer name format to match MyInvois expectations (DS326)\n */\nexport declare const extractCertificateInfo: (certificatePem: string) => {\n issuerName: string;\n serialNumber: string;\n subjectName: string;\n};\n/**\n * Step 5: Create SignedProperties with enhanced structure\n * FIXED: Simplified structure to match MyInvois expectations (DS320)\n * Following MyInvois JSON signature specification exactly\n */\nexport declare const createSignedProperties: (certificateDigest: string, signingTime: string, issuerName: string, serialNumber: string) => SignedPropertiesObject;\n/**\n * Step 6: Calculate SignedProperties Digest\n * FIXED: Add Target wrapper and use direct JSON stringify (DS320)\n * Based on working implementation pattern\n */\nexport declare const calculateSignedPropertiesDigest: (signedProperties: SignedPropertiesObject) => string;\n/**\n * Step 3: Create SignedInfo and calculate signature\n * Enhanced with better structure and signature generation\n */\nexport declare const createSignedInfoAndSign: (docDigest: string, propsDigest: string, privateKeyPem: string) => {\n signedInfo: SignedInfoObject;\n signatureValue: string;\n};\n/**\n * Complete document generation with signatures\n * Follows the complete MyInvois JSON signature creation process (Steps 1-7)\n */\nexport declare const generateCompleteDocument: (invoices: InvoiceV1_1[], signingCredentials: SigningCredentials) => CompleteInvoice;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAE,iBAAA,CAAA,GAAA;AACF,IAAW,mBAAmB,CAAC,GAAI;AACnC,IAAW,6BAA6B;CAAC;CAAK,MAAM;CAAa,MAAM;AAAK;AAC5E,IAAW,2BAA2B;CAAC;CAAK,MAAM;CAAa,MAAM;AAAY;AACjF,IAAE,0BAAA,CAAA,KAAA,MAAA,WAAA;AACF,IAAE,6BAAA,CAAA,GAAA;AACF,IAAW,yBAAyB,CAAC,GAAI;AACzC,IAAE,yBAAA,CAAA,KAAA,MAAA,sBAAA;AACF,IAAW,kCAAkC,CAAC,KAAK,MAAM,sBAAI;AAC7D,IAAE,0BAAA,CAAA,KAAA,MAAA,gBAAA;AACF,IAAW,2BAA2B;CAAC;CAAK,MAAM;CAAa,MAAK;CAAA,MAAA;AAAA"}
1
+ {"version":3,"file":"index70.cts","names":[],"sources":["../src/utils/document.d.ts"],"sourcesContent":["import { InvoiceSubmission, InvoiceV1_1, SigningCredentials, SignedPropertiesObject, UBLDocument, CompleteInvoice, SignedInfoObject } from '../types';\n/**\n * MyInvois v1.1 Document Generation and Signing Utilities\n * Strictly follows: https://sdk.myinvois.hasil.gov.my/documents/invoice-v1-1\n * JSON Signature Guide: https://sdk.myinvois.hasil.gov.my/signature-creation-json/\n */\n/**\n * Determines if a line item uses fixed rate taxation\n */\nexport declare const isFixedRateTax: (item: InvoiceV1_1[\"invoiceLineItems\"][0]) => boolean;\n/**\n * Determines if a line item uses percentage taxation\n */\nexport declare const isPercentageTax: (item: InvoiceV1_1[\"invoiceLineItems\"][0]) => boolean;\n/**\n * Calculates expected tax amount for a line item based on its tax type\n */\nexport declare const calculateExpectedTaxAmount: (item: InvoiceV1_1[\"invoiceLineItems\"][0]) => number;\n/**\n * Helper function to recursively sort object keys for JSON canonicalization\n */\nexport declare function sortObjectKeys(obj: unknown): unknown;\n/**\n * Enhanced canonicalization following MyInvois specification exactly\n * Key changes: ensure consistent ordering and formatting\n */\nexport declare const canonicalizeJSON: (obj: unknown) => string;\n/**\n * Generates a clean invoice object following MyInvois v1.1 specification exactly\n * This is the base invoice structure WITHOUT signature elements (for hash calculation)\n *\n * Key requirements from working documents:\n * - All mandatory fields must be present\n * - Many optional fields must be present even if empty\n * - Specific field ordering and structure\n * - Correct listID values (e.g., \"3166-1\" not \"ISO3166-1\")\n */\nexport declare const generateCleanInvoiceObject: (invoice: InvoiceV1_1) => InvoiceSubmission;\n/**\n * Generates the complete UBL document structure with namespace declarations\n */\nexport declare const generateCleanUBLDocument: (invoices: InvoiceV1_1[]) => UBLDocument;\n/**\n * Step 2: Calculate Document Digest\n * FIXED: Remove UBLExtensions and Signature before hashing (DS322)\n * Based on working implementation pattern\n */\nexport declare const calculateDocumentDigest: (invoices: InvoiceV1_1[]) => string;\n/**\n * Step 4: Calculate Certificate Digest\n * Enhanced to handle certificate content properly\n */\nexport declare const calculateCertificateDigest: (certificatePem: string) => string;\n/**\n * Enhanced certificate info extraction with better error handling\n * FIXED: Normalize issuer name format to match MyInvois expectations (DS326)\n */\nexport declare const extractCertificateInfo: (certificatePem: string) => {\n issuerName: string;\n serialNumber: string;\n subjectName: string;\n};\n/**\n * Step 5: Create SignedProperties with enhanced structure\n * FIXED: Simplified structure to match MyInvois expectations (DS320)\n * Following MyInvois JSON signature specification exactly\n */\nexport declare const createSignedProperties: (certificateDigest: string, signingTime: string, issuerName: string, serialNumber: string) => SignedPropertiesObject;\n/**\n * Step 6: Calculate SignedProperties Digest\n * FIXED: Add Target wrapper and use direct JSON stringify (DS320)\n * Based on working implementation pattern\n */\nexport declare const calculateSignedPropertiesDigest: (signedProperties: SignedPropertiesObject) => string;\n/**\n * Step 3: Create SignedInfo and calculate signature\n * Enhanced with better structure and signature generation\n */\nexport declare const createSignedInfoAndSign: (docDigest: string, propsDigest: string, privateKeyPem: string) => {\n signedInfo: SignedInfoObject;\n signatureValue: string;\n};\n/**\n * Complete document generation with signatures\n * Follows the complete MyInvois JSON signature creation process (Steps 1-7)\n */\nexport declare const generateCompleteDocument: (invoices: InvoiceV1_1[], signingCredentials: SigningCredentials) => CompleteInvoice;\n/**\n * Creates a line item with percentage-based taxation (e.g., SST, GST)\n */\nexport declare const createPercentageTaxLineItem: (params: {\n itemClassificationCode: string;\n itemDescription: string;\n unitPrice: number;\n quantity?: number;\n taxType: string;\n taxRate: number;\n totalTaxableAmountPerLine?: number;\n}) => InvoiceV1_1[\"invoiceLineItems\"][0];\n/**\n * Creates a line item with fixed rate taxation (e.g., Tourism Tax)\n */\nexport declare const createFixedRateTaxLineItem: (params: {\n itemClassificationCode: string;\n itemDescription: string;\n unitPrice: number;\n quantity?: number;\n taxType: string;\n taxPerUnitAmount: number;\n baseUnitMeasure: number;\n baseUnitMeasureCode: string;\n totalTaxableAmountPerLine?: number;\n}) => InvoiceV1_1[\"invoiceLineItems\"][0];\n/**\n * Calculates invoice totals from line items\n */\nexport declare const calculateInvoiceTotals: (lineItems: InvoiceV1_1[\"invoiceLineItems\"]) => {\n legalMonetaryTotal: {\n taxExclusiveAmount: number;\n taxInclusiveAmount: number;\n payableAmount: number;\n };\n taxTotal: {\n taxAmount: number;\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAE,iBAAA,CAAA,KAAA,MAAA,WAAA;AACF,IAAW,kBAAkB,CAAC,KAAK,MAAM,WAAY;AACrD,IAAW,6BAA6B,CAAC,KAAK,MAAM,WAAY;AAChE,IAAW,iBAAiB,CAAC,GAAI;AACjC,IAAE,mBAAA,CAAA,GAAA;AACF,IAAE,6BAAA;CAAA;CAAA,MAAA;CAAA,MAAA;AAAA;AACF,IAAW,2BAA2B;CAAC;CAAK,MAAM;CAAE,MAAA;AAAA;AACpD,IAAE,0BAAA,CAAA,KAAA,MAAA,WAAA;AACF,IAAW,6BAA6B,CAAC,GAAI;AAC7C,IAAE,yBAAA,CAAA,GAAA;AACF,IAAW,yBAAyB,CAAC,KAAK,MAAM,sBAAI;AACpD,IAAE,kCAAA,CAAA,KAAA,MAAA,sBAAA;AACF,IAAW,0BAA0B,CAAC,KAAK,MAAM,gBAAiB;AAClE,IAAE,2BAAA;CAAA;CAAA,MAAA;CAAA,MAAA;CAAA,MAAA;AAAA;AACF,IAAW,8BAA8B,CAAC,KAAK,MAAM,WAAY;AACjE,IAAE,6BAAA,CAAA,KAAA,MAAA,WAAA;AACF,IAAW,yBAAyB,CAAC,KAAK,MAAM,WAAY"}
@@ -1 +1 @@
1
- {"version":3,"file":"index73.cts","names":[],"sources":["../src/utils/validation.d.ts"],"sourcesContent":["import type { InvoiceV1_1 } from '../types/documents/index.js';\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 */\nexport interface ValidationResult {\n isValid: boolean;\n errors: ValidationError[];\n warnings: ValidationWarning[];\n}\nexport interface ValidationError {\n field: string;\n code: string;\n message: string;\n severity: 'error' | 'warning';\n}\nexport interface ValidationWarning extends ValidationError {\n severity: 'warning';\n}\n/**\n * Validates TIN format based on registration type\n */\nexport declare const validateTIN: (tin: string, registrationType?: string) => ValidationError[];\n/**\n * Validates contact number format (E.164 standard)\n */\nexport declare const validateContactNumber: (contactNumber: string) => ValidationError[];\n/**\n * Validates monetary amounts\n */\nexport declare const validateMonetaryAmount: (amount: number, fieldName: string, maxDigits?: number, maxDecimals?: number) => ValidationError[];\n/**\n * Validates tax calculation consistency\n */\nexport declare const validateTaxCalculations: (invoice: InvoiceV1_1) => ValidationError[];\n/**\n * Main validation function for complete invoice\n */\nexport declare const validateInvoice: (invoice: InvoiceV1_1) => ValidationResult;\n"],"mappings":";;;AACA,IAAE,mBAAA;CAAA;CAAA,MAAA;CAAA,MAAA;AAAA;AACF,IAAW,kBAAkB,CAAC,GAAI;AAClC,IAAC,oBAAA,CAAA,KAAA,MAAA,eAAA;AACD,IAAW,cAAc,CAAC,KAAK,MAAM,eAAgB;AACrD,IAAW,wBAAwB,CAAC,KAAK,MAAM,eAAgB;AAC/D,IAAE,yBAAA,CAAA,KAAA,MAAA,eAAA;AACF,IAAW,0BAAuB;CAAA;CAAA,MAAA;CAAA,MAAA;AAAA;AAClC,IAAW,kBAAS;CAAA;CAAA,MAAA;CAAA,MAAA;AAAA"}
1
+ {"version":3,"file":"index73.cts","names":[],"sources":["../src/utils/validation.d.ts"],"sourcesContent":["import type { InvoiceV1_1, InvoiceLineItem } from '../types';\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 */\nexport interface ValidationResult {\n isValid: boolean;\n errors: ValidationError[];\n warnings: ValidationWarning[];\n}\nexport interface ValidationError {\n field: string;\n code: string;\n message: string;\n severity: 'error' | 'warning';\n}\nexport interface ValidationWarning extends ValidationError {\n severity: 'warning';\n}\n/**\n * Validates TIN format based on registration type\n */\nexport declare const validateTIN: (tin: string, registrationType?: string) => ValidationError[];\n/**\n * Validates contact number format (E.164 standard)\n */\nexport declare const validateContactNumber: (contactNumber: string) => ValidationError[];\n/**\n * Validates monetary amounts\n */\nexport declare const validateMonetaryAmount: (amount: number, fieldName: string, maxDigits?: number, maxDecimals?: number) => ValidationError[];\n/**\n * Validates line item tax calculation consistency for both fixed rate and percentage taxation\n */\nexport declare const validateLineItemTax: (item: InvoiceLineItem, index: number) => ValidationError[];\n/**\n * Validates tax calculation consistency\n */\nexport declare const validateTaxCalculations: (invoice: InvoiceV1_1) => ValidationError[];\n/**\n * Main validation function for complete invoice\n */\nexport declare const validateInvoice: (invoice: InvoiceV1_1) => ValidationResult;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAE,mBAAA;CAAA;CAAA,MAAA;CAAA,MAAA;AAAA;AACF,IAAW,kBAAkB,CAAC,GAAI;AAClC,IAAC,oBAAA,CAAA,KAAA,MAAA,eAAA;AACD,IAAW,cAAc,CAAC,KAAK,MAAM,eAAgB;AACrD,IAAW,wBAAwB,CAAC,KAAK,MAAM,eAAgB;AAC/D,IAAE,yBAAA,CAAA,KAAA,MAAA,eAAA;AACF,IAAW,sBAAsB;CAAC;CAAA,MAAA;CAAA,MAAA;AAAA;AAClC,IAAW,0BAAS;CAAA;CAAA,MAAA;CAAA,MAAA;AAAA;AACpB,IAAW,kBAAkB;CAAA;CAAA,MAAA;CAAA,MAAA;AAAA"}
@@ -1,5 +1,5 @@
1
1
  import { MSICCode } from "./msic-codes-CiPeemFK.js";
2
- import { RegistrationType } from "./documents-zzL50wnG.js";
2
+ import { RegistrationType } from "./documents-Br8I8SvT.js";
3
3
 
4
4
  //#region src/types/taxpayer.d.ts
5
5
  interface TaxpayerQRCodeResponse {
@@ -1,5 +1,5 @@
1
1
  import { MSICCode } from "./msic-codes-CIKdPqag.cjs";
2
- import { RegistrationType } from "./documents-DCOYxz61.cjs";
2
+ import { RegistrationType } from "./documents-BuH9ULyn.cjs";
3
3
 
4
4
  //#region src/types/taxpayer.d.ts
5
5
  interface TaxpayerQRCodeResponse {
@@ -32,4 +32,4 @@ interface TinSearchResponse {
32
32
  }
33
33
  //#endregion
34
34
  export { TaxpayerQRCodeResponse, TinSearchParams, TinSearchResponse };
35
- //# sourceMappingURL=taxpayer-aaXyVf7B.d.cts.map
35
+ //# sourceMappingURL=taxpayer-DVjaFzJw.d.cts.map
@@ -15,5 +15,5 @@ import "../9X-_XRgT2-_.js";
15
15
  import "../msic-codes-CiPeemFK.js";
16
16
  import "../tax-types-BskcyNBv.js";
17
17
  import "../state-codes-BaGjZcA8.js";
18
- import { Address, Buyer, CompleteInvoice, DocumentStatus, DocumentSummary, DocumentTypeResponse, DocumentTypeVersion, DocumentTypeVersionResponse, DocumentTypesResponse, DocumentValidationResult, DocumentValidationStepResult, FinalDocumentData, GetSubmissionResponse, InvoiceLineItem, InvoiceSubmission, InvoiceV1_1, LegalMonetaryTotal, RegistrationType, ResponseDocument, SignedInfoObject, SignedInvoiceSubmission, SignedPropertiesData, SignedPropertiesObject, SigningCredentials, StandardError, SubmissionResponse, SubmissionStatus, Supplier, TaxCategory, TaxSubtotal, TaxTotal, UBLDocument, WorkflowParameter } from "../documents-zzL50wnG.js";
18
+ import { Address, Buyer, CompleteInvoice, DocumentStatus, DocumentSummary, DocumentTypeResponse, DocumentTypeVersion, DocumentTypeVersionResponse, DocumentTypesResponse, DocumentValidationResult, DocumentValidationStepResult, FinalDocumentData, GetSubmissionResponse, InvoiceLineItem, InvoiceSubmission, InvoiceV1_1, LegalMonetaryTotal, RegistrationType, ResponseDocument, SignedInfoObject, SignedInvoiceSubmission, SignedPropertiesData, SignedPropertiesObject, SigningCredentials, StandardError, SubmissionResponse, SubmissionStatus, Supplier, TaxCategory, TaxSubtotal, TaxTotal, UBLDocument, WorkflowParameter } from "../documents-Br8I8SvT.js";
19
19
  export { Address, Buyer, CompleteInvoice, DocumentStatus, DocumentSummary, DocumentTypeResponse, DocumentTypeVersion, DocumentTypeVersionResponse, DocumentTypesResponse, DocumentValidationResult, DocumentValidationStepResult, FinalDocumentData, GetSubmissionResponse, InvoiceLineItem, InvoiceSubmission, InvoiceV1_1, LegalMonetaryTotal, RegistrationType, ResponseDocument, SignedInfoObject, SignedInvoiceSubmission, SignedPropertiesData, SignedPropertiesObject, SigningCredentials, StandardError, SubmissionResponse, SubmissionStatus, Supplier, TaxCategory, TaxSubtotal, TaxTotal, UBLDocument, WorkflowParameter };
@@ -15,7 +15,7 @@ import "../9X-_XRgT2-_.js";
15
15
  import { MSICCode } from "../msic-codes-CiPeemFK.js";
16
16
  import { TaxType, TaxTypeCode, TaxTypeCodeEnum } from "../tax-types-BskcyNBv.js";
17
17
  import { State, StateCode, StateCodeEnum } from "../state-codes-BaGjZcA8.js";
18
- import { Address, Buyer, CompleteInvoice, DocumentStatus, DocumentSummary, DocumentTypeResponse, DocumentTypeVersion, DocumentTypeVersionResponse, DocumentTypesResponse, DocumentValidationResult, DocumentValidationStepResult, FinalDocumentData, GetSubmissionResponse, InvoiceLineItem, InvoiceSubmission, InvoiceV1_1, LegalMonetaryTotal, RegistrationType, ResponseDocument, SignedInfoObject, SignedInvoiceSubmission, SignedPropertiesData, SignedPropertiesObject, SigningCredentials, StandardError, SubmissionResponse, SubmissionStatus, Supplier, TaxCategory, TaxSubtotal, TaxTotal, UBLDocument, WorkflowParameter } from "../documents-zzL50wnG.js";
18
+ import { Address, Buyer, CompleteInvoice, DocumentStatus, DocumentSummary, DocumentTypeResponse, DocumentTypeVersion, DocumentTypeVersionResponse, DocumentTypesResponse, DocumentValidationResult, DocumentValidationStepResult, FinalDocumentData, GetSubmissionResponse, InvoiceLineItem, InvoiceSubmission, InvoiceV1_1, LegalMonetaryTotal, RegistrationType, ResponseDocument, SignedInfoObject, SignedInvoiceSubmission, SignedPropertiesData, SignedPropertiesObject, SigningCredentials, StandardError, SubmissionResponse, SubmissionStatus, Supplier, TaxCategory, TaxSubtotal, TaxTotal, UBLDocument, WorkflowParameter } from "../documents-Br8I8SvT.js";
19
19
  import { PaymentMode, PaymentModeCode, PaymentModeCodeEnum } from "../payment-modes-NpE3OcCV.js";
20
20
  import "../1X-C72Wa4pk.js";
21
21
  import "../2X-CH89y3Af.js";
@@ -55,7 +55,7 @@ import "../XX-DOA-10JW.js";
55
55
  import { UnitType, UnitTypeCode } from "../unit-types-VgYXIwTT.js";
56
56
  import { CanonicalizationMethod, Cert, CertDigest, DigestMethod, IssuerDigitalSignature, IssuerSerial, KeyInfo, QualifyingProperties, Reference, SignatureMethod, SignedInfo, SignedProperties, SignedSignatureProperties, SigningCertificate, Transform, X509Data } from "../signatures-C-nCPDqt.js";
57
57
  import { Notification, NotificationDeliveryAttempt, NotificationMetadata, NotificationResponse, NotificationSearchParams, NotificationStatus, NotificationStatusEnum, NotificationType, NotificationTypeEnum } from "../notifications-B4l_qRj7.js";
58
- import { TaxpayerQRCodeResponse, TinSearchParams, TinSearchResponse } from "../taxpayer-CxAVm7lJ.js";
58
+ import { TaxpayerQRCodeResponse, TinSearchParams, TinSearchResponse } from "../taxpayer-5MlboTnW.js";
59
59
  import { Fetch } from "../utils-B3mo51Zp.js";
60
60
  import { ClientCredentials, TokenResponse } from "../index-FTgB2nM6.js";
61
61
  export { Address, Buyer, CanonicalizationMethod, Cert, CertDigest, Classification, ClassificationCode, ClassificationCodeEnum, ClientCredentials, CompleteInvoice, Country, CountryCode, CountryCodeEnum, CountryNameEnum, Currency, CurrencyCode, CurrencyCodeEnum, DigestMethod, DocumentStatus, DocumentSummary, DocumentTypeResponse, DocumentTypeVersion, DocumentTypeVersionResponse, DocumentTypesResponse, DocumentValidationResult, DocumentValidationStepResult, EInvoiceType, EInvoiceTypeCode, EInvoiceTypeCodeEnum, Fetch, FinalDocumentData, GetSubmissionResponse, InvoiceLineItem, InvoiceSubmission, InvoiceV1_1, IssuerDigitalSignature, IssuerSerial, KeyInfo, LegalMonetaryTotal, MSICCode, Notification, NotificationDeliveryAttempt, NotificationMetadata, NotificationResponse, NotificationSearchParams, NotificationStatus, NotificationStatusEnum, NotificationType, NotificationTypeEnum, PaymentMode, PaymentModeCode, PaymentModeCodeEnum, QualifyingProperties, Reference, RegistrationType, ResponseDocument, SignatureMethod, SignedInfo, SignedInfoObject, SignedInvoiceSubmission, SignedProperties, SignedPropertiesData, SignedPropertiesObject, SignedSignatureProperties, SigningCertificate, SigningCredentials, StandardError, State, StateCode, StateCodeEnum, SubmissionResponse, SubmissionStatus, Supplier, TaxCategory, TaxSubtotal, TaxTotal, TaxType, TaxTypeCode, TaxTypeCodeEnum, TaxpayerQRCodeResponse, TinSearchParams, TinSearchResponse, TokenResponse, Transform, UBLDocument, UnitType, UnitTypeCode, WorkflowParameter, X509Data };
@@ -15,6 +15,6 @@ import "../9X-_XRgT2-_.js";
15
15
  import "../msic-codes-CiPeemFK.js";
16
16
  import "../tax-types-BskcyNBv.js";
17
17
  import "../state-codes-BaGjZcA8.js";
18
- import "../documents-zzL50wnG.js";
19
- import { TaxpayerQRCodeResponse, TinSearchParams, TinSearchResponse } from "../taxpayer-CxAVm7lJ.js";
18
+ import "../documents-Br8I8SvT.js";
19
+ import { TaxpayerQRCodeResponse, TinSearchParams, TinSearchResponse } from "../taxpayer-5MlboTnW.js";
20
20
  export { TaxpayerQRCodeResponse, TinSearchParams, TinSearchResponse };
@@ -15,7 +15,7 @@ import "../9X-_XRgT2-_.js";
15
15
  import "../msic-codes-CiPeemFK.js";
16
16
  import "../tax-types-BskcyNBv.js";
17
17
  import "../state-codes-BaGjZcA8.js";
18
- import { CompleteInvoice, InvoiceSubmission, InvoiceV1_1, SignedInfoObject, SignedPropertiesObject, SigningCredentials, UBLDocument } from "../documents-zzL50wnG.js";
18
+ import { CompleteInvoice, InvoiceSubmission, InvoiceV1_1, SignedInfoObject, SignedPropertiesObject, SigningCredentials, UBLDocument } from "../documents-Br8I8SvT.js";
19
19
  import "../payment-modes-NpE3OcCV.js";
20
20
  import "../1X-C72Wa4pk.js";
21
21
  import "../2X-CH89y3Af.js";
@@ -55,7 +55,7 @@ import "../XX-DOA-10JW.js";
55
55
  import "../unit-types-VgYXIwTT.js";
56
56
  import "../signatures-C-nCPDqt.js";
57
57
  import "../notifications-B4l_qRj7.js";
58
- import "../taxpayer-CxAVm7lJ.js";
58
+ import "../taxpayer-5MlboTnW.js";
59
59
  import "../utils-B3mo51Zp.js";
60
60
  import "../index-FTgB2nM6.js";
61
61
 
@@ -66,6 +66,18 @@ import "../index-FTgB2nM6.js";
66
66
  * JSON Signature Guide: https://sdk.myinvois.hasil.gov.my/signature-creation-json/
67
67
  */
68
68
  /**
69
+ * Determines if a line item uses fixed rate taxation
70
+ */
71
+ declare const isFixedRateTax: (item: InvoiceV1_1["invoiceLineItems"][0]) => boolean;
72
+ /**
73
+ * Determines if a line item uses percentage taxation
74
+ */
75
+ declare const isPercentageTax: (item: InvoiceV1_1["invoiceLineItems"][0]) => boolean;
76
+ /**
77
+ * Calculates expected tax amount for a line item based on its tax type
78
+ */
79
+ declare const calculateExpectedTaxAmount: (item: InvoiceV1_1["invoiceLineItems"][0]) => number;
80
+ /**
69
81
  * Helper function to recursively sort object keys for JSON canonicalization
70
82
  */
71
83
  declare function sortObjectKeys(obj: unknown): unknown;
@@ -134,5 +146,44 @@ declare const createSignedInfoAndSign: (docDigest: string, propsDigest: string,
134
146
  * Follows the complete MyInvois JSON signature creation process (Steps 1-7)
135
147
  */
136
148
  declare const generateCompleteDocument: (invoices: InvoiceV1_1[], signingCredentials: SigningCredentials) => CompleteInvoice;
149
+ /**
150
+ * Creates a line item with percentage-based taxation (e.g., SST, GST)
151
+ */
152
+ declare const createPercentageTaxLineItem: (params: {
153
+ itemClassificationCode: string;
154
+ itemDescription: string;
155
+ unitPrice: number;
156
+ quantity?: number;
157
+ taxType: string;
158
+ taxRate: number;
159
+ totalTaxableAmountPerLine?: number;
160
+ }) => InvoiceV1_1["invoiceLineItems"][0];
161
+ /**
162
+ * Creates a line item with fixed rate taxation (e.g., Tourism Tax)
163
+ */
164
+ declare const createFixedRateTaxLineItem: (params: {
165
+ itemClassificationCode: string;
166
+ itemDescription: string;
167
+ unitPrice: number;
168
+ quantity?: number;
169
+ taxType: string;
170
+ taxPerUnitAmount: number;
171
+ baseUnitMeasure: number;
172
+ baseUnitMeasureCode: string;
173
+ totalTaxableAmountPerLine?: number;
174
+ }) => InvoiceV1_1["invoiceLineItems"][0];
175
+ /**
176
+ * Calculates invoice totals from line items
177
+ */
178
+ declare const calculateInvoiceTotals: (lineItems: InvoiceV1_1["invoiceLineItems"]) => {
179
+ legalMonetaryTotal: {
180
+ taxExclusiveAmount: number;
181
+ taxInclusiveAmount: number;
182
+ payableAmount: number;
183
+ };
184
+ taxTotal: {
185
+ taxAmount: number;
186
+ };
187
+ };
137
188
  //#endregion
138
- export { calculateCertificateDigest, calculateDocumentDigest, calculateSignedPropertiesDigest, canonicalizeJSON, createSignedInfoAndSign, createSignedProperties, extractCertificateInfo, generateCleanInvoiceObject, generateCleanUBLDocument, generateCompleteDocument, sortObjectKeys };
189
+ export { calculateCertificateDigest, calculateDocumentDigest, calculateExpectedTaxAmount, calculateInvoiceTotals, calculateSignedPropertiesDigest, canonicalizeJSON, createFixedRateTaxLineItem, createPercentageTaxLineItem, createSignedInfoAndSign, createSignedProperties, extractCertificateInfo, generateCleanInvoiceObject, generateCleanUBLDocument, generateCompleteDocument, isFixedRateTax, isPercentageTax, sortObjectKeys };
@@ -1,3 +1,3 @@
1
- import { calculateCertificateDigest, calculateDocumentDigest, calculateSignedPropertiesDigest, canonicalizeJSON, createSignedInfoAndSign, createSignedProperties, extractCertificateInfo, generateCleanInvoiceObject, generateCleanUBLDocument, generateCompleteDocument, sortObjectKeys } from "../document-BSuYbfXR.js";
1
+ import { calculateCertificateDigest, calculateDocumentDigest, calculateExpectedTaxAmount, calculateInvoiceTotals, calculateSignedPropertiesDigest, canonicalizeJSON, createFixedRateTaxLineItem, createPercentageTaxLineItem, createSignedInfoAndSign, createSignedProperties, extractCertificateInfo, generateCleanInvoiceObject, generateCleanUBLDocument, generateCompleteDocument, isFixedRateTax, isPercentageTax, sortObjectKeys } from "../document-BvyYSCPx.js";
2
2
 
3
- export { calculateCertificateDigest, calculateDocumentDigest, calculateSignedPropertiesDigest, canonicalizeJSON, createSignedInfoAndSign, createSignedProperties, extractCertificateInfo, generateCleanInvoiceObject, generateCleanUBLDocument, generateCompleteDocument, sortObjectKeys };
3
+ export { calculateCertificateDigest, calculateDocumentDigest, calculateExpectedTaxAmount, calculateInvoiceTotals, calculateSignedPropertiesDigest, canonicalizeJSON, createFixedRateTaxLineItem, createPercentageTaxLineItem, createSignedInfoAndSign, createSignedProperties, extractCertificateInfo, generateCleanInvoiceObject, generateCleanUBLDocument, generateCompleteDocument, isFixedRateTax, isPercentageTax, sortObjectKeys };
@@ -15,7 +15,7 @@ import "../9X-_XRgT2-_.js";
15
15
  import "../msic-codes-CiPeemFK.js";
16
16
  import "../tax-types-BskcyNBv.js";
17
17
  import "../state-codes-BaGjZcA8.js";
18
- import { InvoiceV1_1 } from "../documents-zzL50wnG.js";
18
+ import { InvoiceV1_1 } from "../documents-Br8I8SvT.js";
19
19
  import "../payment-modes-NpE3OcCV.js";
20
20
  import "../1X-C72Wa4pk.js";
21
21
  import "../2X-CH89y3Af.js";
@@ -55,7 +55,7 @@ import "../XX-DOA-10JW.js";
55
55
  import "../unit-types-VgYXIwTT.js";
56
56
  import "../signatures-C-nCPDqt.js";
57
57
  import "../notifications-B4l_qRj7.js";
58
- import "../taxpayer-CxAVm7lJ.js";
58
+ import "../taxpayer-5MlboTnW.js";
59
59
  import "../utils-B3mo51Zp.js";
60
60
  import "../index-FTgB2nM6.js";
61
61
 
@@ -1,4 +1,4 @@
1
- import { calculateCertificateDigest, calculateDocumentDigest, calculateSignedPropertiesDigest, createSignedProperties, extractCertificateInfo } from "../document-BSuYbfXR.js";
1
+ import { calculateCertificateDigest, calculateDocumentDigest, calculateSignedPropertiesDigest, createSignedProperties, extractCertificateInfo } from "../document-BvyYSCPx.js";
2
2
  import crypto from "crypto";
3
3
 
4
4
  //#region src/utils/signature-diagnostics.ts
@@ -1,7 +1,65 @@
1
- import { InvoiceV1_1 } from "../types/documents/index.js";
1
+ import "../classification-codes-B1D5xbq5.js";
2
+ import "../country-code-D42kAyNH.js";
3
+ import "../currencies-CDveO_yz.js";
4
+ import "../e-invoice-BxNC6V_j.js";
5
+ import "../0X-DZnB0al0.js";
6
+ import "../1X-Dg5J6Bfg.js";
7
+ import "../2X-D_qwTeDT.js";
8
+ import "../3X-BJHYxgxa.js";
9
+ import "../4X-BbZgoRHO.js";
10
+ import "../5X-oQRBnO0f.js";
11
+ import "../6X-B9I2XJa4.js";
12
+ import "../7X-Ckv9bbzG.js";
13
+ import "../8X-C37BJTl6.js";
14
+ import "../9X-_XRgT2-_.js";
15
+ import "../msic-codes-CiPeemFK.js";
16
+ import "../tax-types-BskcyNBv.js";
17
+ import "../state-codes-BaGjZcA8.js";
18
+ import { InvoiceLineItem, InvoiceV1_1 } from "../documents-Br8I8SvT.js";
19
+ import "../payment-modes-NpE3OcCV.js";
20
+ import "../1X-C72Wa4pk.js";
21
+ import "../2X-CH89y3Af.js";
22
+ import "../3X-DryrwYRf.js";
23
+ import "../4X-BPMLRoDv.js";
24
+ import "../5X-Bv7M6KyG.js";
25
+ import "../6X-ZeZ8OB57.js";
26
+ import "../7X-Dvw2Z2VN.js";
27
+ import "../8X-BkgoX8dg.js";
28
+ import "../9X-Du0e44cq.js";
29
+ import "../AX-BSPLpkVT.js";
30
+ import "../BX-u4yMaIkz.js";
31
+ import "../CX-BKZG0pVE.js";
32
+ import "../DX-CwA9WJAf.js";
33
+ import "../EX-BRNu1Ooi.js";
34
+ import "../FX-DBxjq6xY.js";
35
+ import "../GX-B3CvWNrP.js";
36
+ import "../HX-D7FABgTv.js";
37
+ import "../IX-D3ZknsAB.js";
38
+ import "../JX-BRaZM3Gc.js";
39
+ import "../KX-B1K0OWoi.js";
40
+ import "../LX-CKRefinL.js";
41
+ import "../MX-DKmaeO9r.js";
42
+ import "../NX-CJL2Gn1U.js";
43
+ import "../OX-Do2ap5v_.js";
44
+ import "../PX-_DOr_rm9.js";
45
+ import "../QX-HlXLkIki.js";
46
+ import "../RX-DVPGOVES.js";
47
+ import "../SX-OGT3qwlS.js";
48
+ import "../TX-cPDINmZ5.js";
49
+ import "../UX-Be3sqvPV.js";
50
+ import "../VX-CoEuBNDK.js";
51
+ import "../WX-DMvw__jH.js";
52
+ import "../YX-F34sJ7Ik.js";
53
+ import "../ZX-CDQOfsHh.js";
54
+ import "../XX-DOA-10JW.js";
55
+ import "../unit-types-VgYXIwTT.js";
56
+ import "../signatures-C-nCPDqt.js";
57
+ import "../notifications-B4l_qRj7.js";
58
+ import "../taxpayer-5MlboTnW.js";
59
+ import "../utils-B3mo51Zp.js";
60
+ import "../index-FTgB2nM6.js";
2
61
 
3
62
  //#region src/utils/validation.d.ts
4
-
5
63
  /**
6
64
  * MyInvois Invoice Validation Utilities
7
65
  *
@@ -35,6 +93,10 @@ declare const validateContactNumber: (contactNumber: string) => ValidationError[
35
93
  */
36
94
  declare const validateMonetaryAmount: (amount: number, fieldName: string, maxDigits?: number, maxDecimals?: number) => ValidationError[];
37
95
  /**
96
+ * Validates line item tax calculation consistency for both fixed rate and percentage taxation
97
+ */
98
+ declare const validateLineItemTax: (item: InvoiceLineItem, index: number) => ValidationError[];
99
+ /**
38
100
  * Validates tax calculation consistency
39
101
  */
40
102
  declare const validateTaxCalculations: (invoice: InvoiceV1_1) => ValidationError[];
@@ -43,4 +105,4 @@ declare const validateTaxCalculations: (invoice: InvoiceV1_1) => ValidationError
43
105
  */
44
106
  declare const validateInvoice: (invoice: InvoiceV1_1) => ValidationResult;
45
107
  //#endregion
46
- export { ValidationError, ValidationResult, ValidationWarning, validateContactNumber, validateInvoice, validateMonetaryAmount, validateTIN, validateTaxCalculations };
108
+ export { ValidationError, ValidationResult, ValidationWarning, validateContactNumber, validateInvoice, validateLineItemTax, validateMonetaryAmount, validateTIN, validateTaxCalculations };