@ripwords/myinvois-client 0.2.41 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/documentManagement.d.ts +2 -2
- package/dist/api/documentSubmission.d.ts +2 -2
- package/dist/api/documentSubmission.js +2 -2
- package/dist/api/documentTypeManagement.d.ts +2 -2
- package/dist/api/notificationManagement.d.ts +2 -2
- package/dist/api/platformLogin.d.ts +2 -2
- package/dist/api/taxpayerValidation.d.ts +2 -2
- package/dist/apiQueue-B6Q644Bz.js +201 -0
- package/dist/apiQueue-DgKWaQDS.cjs +220 -0
- package/dist/apiQueue-DgKWaQDS.cjs.map +1 -0
- package/dist/{document-DLFdGSK1.js → document-D4O7JY0G.js} +9 -3
- package/dist/{document-CCza2JPL.cjs → document-DoQEvmcK.cjs} +10 -4
- package/dist/document-DoQEvmcK.cjs.map +1 -0
- package/dist/{documentSubmission-M4UlirJ7.cjs → documentSubmission-DUsjqWhR.cjs} +2 -2
- package/dist/{documentSubmission-M4UlirJ7.cjs.map → documentSubmission-DUsjqWhR.cjs.map} +1 -1
- package/dist/{documentSubmission-ZAgXsd3X.js → documentSubmission-uJ7yPWub.js} +1 -1
- package/dist/{documents-DCZ3Ffya.d.cts → documents-BECak3KN.d.cts} +7 -1
- package/dist/{documents-DzZA3NHj.d.ts → documents-Dp19RgNX.d.ts} +6 -0
- package/dist/index.cjs +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/index10.cjs +24 -4
- package/dist/index10.cjs.map +1 -0
- package/dist/index11.cjs +0 -22
- package/dist/index12.cjs +33 -2
- package/dist/index12.cjs.map +1 -0
- package/dist/index13.cjs +23 -2
- package/dist/index13.cjs.map +1 -0
- package/dist/index14.cjs +0 -330
- package/dist/index15.cjs +0 -193
- package/dist/index16.cjs +0 -62
- package/dist/index17.cjs +4 -531
- package/dist/index18.cjs +6 -195
- package/dist/index19.cjs +5 -0
- package/dist/index2.cjs +61 -4
- package/dist/index2.cjs.map +1 -0
- package/dist/index20.cjs +2 -24
- package/dist/index21.cjs +3 -0
- package/dist/index22.cjs +6 -0
- package/dist/index23.cjs +203 -24
- package/dist/index23.cjs.map +1 -1
- package/dist/index24.cjs +104 -20
- package/dist/index24.cjs.map +1 -1
- package/dist/index25.cjs +137 -0
- package/dist/{index33.cjs.map → index25.cjs.map} +1 -1
- package/dist/index26.cjs +59 -29
- package/dist/index26.cjs.map +1 -1
- package/dist/index27.cjs +262 -19
- package/dist/index27.cjs.map +1 -1
- package/dist/index28.cjs +79 -0
- package/dist/{index36.cjs.map → index28.cjs.map} +1 -1
- package/dist/index29.cjs +107 -0
- package/dist/{index37.cjs.map → index29.cjs.map} +1 -1
- package/dist/index3.cjs +531 -6
- package/dist/index3.cjs.map +1 -0
- package/dist/index30.cjs +73 -0
- package/dist/{index38.cjs.map → index30.cjs.map} +1 -1
- package/dist/index31.cjs +107 -203
- package/dist/index31.cjs.map +1 -1
- package/dist/index32.cjs +95 -104
- package/dist/index32.cjs.map +1 -1
- package/dist/index33.cjs +4 -136
- package/dist/index34.cjs +9 -60
- package/dist/index34.cjs.map +1 -1
- package/dist/index35.cjs +4 -266
- package/dist/index36.cjs +21 -78
- package/dist/index37.cjs +2 -106
- package/dist/index38.cjs +2 -72
- package/dist/index39.cjs +326 -108
- package/dist/index39.cjs.map +1 -1
- package/dist/index4.cjs +195 -4
- package/dist/index4.cjs.map +1 -0
- package/dist/index40.cjs +189 -96
- package/dist/index40.cjs.map +1 -1
- package/dist/index5.cjs +0 -3
- package/dist/index6.cjs +24 -2
- package/dist/index6.cjs.map +1 -0
- package/dist/index68.cts.map +1 -1
- package/dist/index7.cjs +0 -6
- package/dist/index71.cts.map +1 -1
- package/dist/index8.cjs +0 -4
- package/dist/index9.cjs +25 -9
- package/dist/index9.cjs.map +1 -1
- package/dist/{taxpayer-DmHW0m7o.d.ts → taxpayer-BdvCGHHC.d.ts} +1 -1
- package/dist/{taxpayer-Pm90MrPj.d.cts → taxpayer-CaDfslWB.d.cts} +2 -2
- package/dist/types/documents.d.ts +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/taxpayer.d.ts +2 -2
- package/dist/utils/apiQueue.d.ts +11 -3
- package/dist/utils/apiQueue.js +2 -2
- package/dist/utils/document.d.ts +4 -3
- package/dist/utils/document.js +1 -1
- package/dist/utils/signature-diagnostics.d.ts +2 -2
- package/dist/utils/signature-diagnostics.js +1 -1
- package/dist/utils/validation.d.ts +2 -2
- package/package.json +1 -1
- package/dist/apiQueue-CCrZMnMu.js +0 -182
- package/dist/apiQueue-Djd7WlnV.cjs +0 -195
- package/dist/apiQueue-Djd7WlnV.cjs.map +0 -1
- package/dist/document-CCza2JPL.cjs.map +0 -1
- package/dist/index14.cjs.map +0 -1
- package/dist/index15.cjs.map +0 -1
- package/dist/index16.cjs.map +0 -1
- package/dist/index17.cjs.map +0 -1
- package/dist/index18.cjs.map +0 -1
- package/dist/index20.cjs.map +0 -1
- package/dist/index35.cjs.map +0 -1
package/dist/index71.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index71.cts","names":[],"sources":["../src/utils/document.d.ts"],"sourcesContent":["import { InvoiceSubmission, AllDocumentsV1_1, SigningCredentials, SignedPropertiesObject, UBLDocument, CompleteInvoice, SignedInfoObject, UnitTypeCode, InvoiceLineItem } from '../types';\nimport type { ClassificationCode } from '../types';\nimport type { TaxTypeCode } 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: InvoiceLineItem) => boolean;\n/**\n * Determines if a line item uses percentage taxation\n */\nexport declare const isPercentageTax: (item: InvoiceLineItem) => boolean;\n/**\n * Calculates expected tax amount for a line item based on its tax type\n */\nexport declare const calculateExpectedTaxAmount: (item: InvoiceLineItem) => 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: AllDocumentsV1_1) => InvoiceSubmission;\n/**\n * Generates the complete UBL document structure with namespace declarations\n */\nexport declare const generateCleanUBLDocument: (invoices: AllDocumentsV1_1[]) => UBLDocument;\n/**\n * Step 1: Transform the document for hashing or transmission\n * Removes UBLExtensions and Signature, and minifies the JSON\n * Returns the minified, cleaned JSON string\n *\n * FIXED: Use regex-based minification to match PowerShell script exactly\n */\nexport declare const transformDocumentForHashing: (invoices: AllDocumentsV1_1[]) => string;\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: AllDocumentsV1_1[]) => string;\n/**\n * Step 4: Calculate Certificate Digest\n * Enhanced to handle certificate content properly\n * FIXED: Match PowerShell script exactly - use raw certificate data like $cert.RawData\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 * Calculates the digest over the correct structure for validator compliance.\n * FIXED: Calculate digest from SignedProperties only (without Target wrapper)\n */\nexport declare const calculateSignedPropertiesDigest: (signedProperties: SignedPropertiesObject, useTargetWrapper?: boolean) => 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 * Signs the minified document string using the provided private key PEM\n * Returns the signature as a base64 string\n * FIXED: Match PowerShell script exactly - first compute hash, then sign the hash\n */\nexport declare const signDocumentString: (documentString: string, privateKeyPem: string) => string;\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: AllDocumentsV1_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: ClassificationCode;\n itemDescription: string;\n unitPrice: number;\n quantity?: number;\n taxType: TaxTypeCode;\n taxRate: number;\n totalTaxableAmountPerLine?: number;\n discountAmount?: number;\n discountRate?: number;\n}) => InvoiceLineItem;\n/**\n * Creates a line item with fixed rate taxation (e.g., Tourism Tax)\n */\nexport declare const createFixedRateTaxLineItem: (params: {\n itemClassificationCode: ClassificationCode;\n itemDescription: string;\n unitPrice: number;\n quantity?: number;\n taxType: TaxTypeCode;\n taxPerUnitAmount: number;\n baseUnitMeasure: number;\n baseUnitMeasureCode: UnitTypeCode;\n totalTaxableAmountPerLine?: number;\n discountAmount?: number;\n discountRate?: number;\n}) => InvoiceLineItem;\n/**\n * Calculates invoice totals from line items\n */\nexport declare const calculateInvoiceTotals: (lineItems: InvoiceLineItem[]) => {\n legalMonetaryTotal: {\n taxExclusiveAmount: number;\n taxInclusiveAmount: number;\n payableAmount: number;\n };\n taxTotal: {\n taxAmount: number;\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAE,iBAAA,CAAA,KAAA,MAAA,eAAA;AACF,IAAW,kBAAkB,CAAC,KAAK,MAAM,eAAgB;AACzD,IAAW,6BAA6B,CAAC,KAAK,MAAM,eAAgB;AACpE,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,8BAAA,CAAA,KAAA,MAAA,gBAAA;AACF,IAAW,0BAA0B,CAAC,KAAK,MAAM,gBAAiB;AAClE,IAAE,6BAAA,CAAA,GAAA;AACF,IAAW,yBAAyB,CAAC,GAAI;AACzC,IAAE,yBAAA,CAAA,KAAA,MAAA,sBAAA;AACF,IAAW,kCAAkC,CAAC,KAAK,MAAM,sBAAe;AACxE,IAAE,0BAAA,CAAA,KAAA,MAAA,gBAAA;AACF,IAAW,qBAAqB,CAAC,GAAI;AACrC,IAAE,2BAAA;CAAA;CAAA,MAAA;CAAA,MAAA;CAAA,MAAA;AAAA;AACF,IAAW,8BAA8B;CAAC;CAAK,MAAM;CAAoB,MAAM;CAAG,MAAA;AAAA;AAClF,IAAE,6BAAA;CAAA;CAAA,MAAA;CAAA,MAAA;CAAA,MAAA;CAAA,MAAA;AAAA;AACF,IAAW,yBAAyB,CAAC,KAAK,MAAM,eAAgB"}
|
|
1
|
+
{"version":3,"file":"index71.cts","names":[],"sources":["../src/utils/document.d.ts"],"sourcesContent":["import { InvoiceSubmission, AllDocumentsV1_1, SigningCredentials, SignedPropertiesObject, UBLDocument, CompleteInvoice, SignedInfoObject, UnitTypeCode, InvoiceLineItem } from '../types';\nimport type { ClassificationCode } from '../types';\nimport type { TaxTypeCode } 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: InvoiceLineItem) => boolean;\n/**\n * Determines if a line item uses percentage taxation\n */\nexport declare const isPercentageTax: (item: InvoiceLineItem) => boolean;\n/**\n * Calculates expected tax amount for a line item based on its tax type\n */\nexport declare const calculateExpectedTaxAmount: (item: InvoiceLineItem) => 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: AllDocumentsV1_1) => InvoiceSubmission;\n/**\n * Generates the complete UBL document structure with namespace declarations\n */\nexport declare const generateCleanUBLDocument: (invoices: AllDocumentsV1_1[]) => UBLDocument;\n/**\n * Step 1: Transform the document for hashing or transmission\n * Removes UBLExtensions and Signature, and minifies the JSON\n * Returns the minified, cleaned JSON string\n *\n * FIXED: Use regex-based minification to match PowerShell script exactly\n */\nexport declare const transformDocumentForHashing: (invoices: AllDocumentsV1_1[]) => string;\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: AllDocumentsV1_1[]) => string;\n/**\n * Step 4: Calculate Certificate Digest\n * Enhanced to handle certificate content properly\n * FIXED: Match PowerShell script exactly - use raw certificate data like $cert.RawData\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 * Calculates the digest over the correct structure for validator compliance.\n * FIXED: Calculate digest from SignedProperties only (without Target wrapper)\n */\nexport declare const calculateSignedPropertiesDigest: (signedProperties: SignedPropertiesObject, useTargetWrapper?: boolean) => 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 * Signs the minified document string using the provided private key PEM\n * Returns the signature as a base64 string\n * FIXED: Match PowerShell script exactly - first compute hash, then sign the hash\n */\nexport declare const signDocumentString: (documentString: string, privateKeyPem: string) => string;\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: AllDocumentsV1_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: ClassificationCode;\n itemDescription: string;\n unitPrice: number;\n quantity?: number;\n taxType: TaxTypeCode;\n taxRate: number;\n totalTaxableAmountPerLine?: number;\n discountAmount?: number;\n discountRate?: number;\n}) => InvoiceLineItem;\n/**\n * Creates a line item with fixed rate taxation (e.g., Tourism Tax)\n */\nexport declare const createFixedRateTaxLineItem: (params: {\n itemClassificationCode: ClassificationCode;\n itemDescription: string;\n unitPrice: number;\n quantity?: number;\n taxType: TaxTypeCode;\n taxPerUnitAmount: number;\n baseUnitMeasure: number;\n baseUnitMeasureCode: UnitTypeCode;\n totalTaxableAmountPerLine?: number;\n discountAmount?: number;\n discountRate?: number;\n}) => InvoiceLineItem;\n/**\n * Calculates invoice totals from line items\n */\nexport declare const calculateInvoiceTotals: (lineItems: InvoiceLineItem[], payableRoundingAmount?: number) => {\n legalMonetaryTotal: {\n taxExclusiveAmount: number;\n taxInclusiveAmount: number;\n payableRoundingAmount: number;\n payableAmount: number;\n };\n taxTotal: {\n taxAmount: number;\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAE,iBAAA,CAAA,KAAA,MAAA,eAAA;AACF,IAAW,kBAAkB,CAAC,KAAK,MAAM,eAAgB;AACzD,IAAW,6BAA6B,CAAC,KAAK,MAAM,eAAgB;AACpE,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,8BAAA,CAAA,KAAA,MAAA,gBAAA;AACF,IAAW,0BAA0B,CAAC,KAAK,MAAM,gBAAiB;AAClE,IAAE,6BAAA,CAAA,GAAA;AACF,IAAW,yBAAyB,CAAC,GAAI;AACzC,IAAE,yBAAA,CAAA,KAAA,MAAA,sBAAA;AACF,IAAW,kCAAkC,CAAC,KAAK,MAAM,sBAAe;AACxE,IAAE,0BAAA,CAAA,KAAA,MAAA,gBAAA;AACF,IAAW,qBAAqB,CAAC,GAAI;AACrC,IAAE,2BAAA;CAAA;CAAA,MAAA;CAAA,MAAA;CAAA,MAAA;AAAA;AACF,IAAW,8BAA8B;CAAC;CAAK,MAAM;CAAoB,MAAM;CAAG,MAAA;AAAA;AAClF,IAAE,6BAAA;CAAA;CAAA,MAAA;CAAA,MAAA;CAAA,MAAA;CAAA,MAAA;AAAA;AACF,IAAW,yBAAyB,CAAC,KAAK,MAAM,eAAgB"}
|
package/dist/index8.cjs
CHANGED
package/dist/index9.cjs
CHANGED
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
|
|
2
|
-
//#region src/
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
//#region src/types/notifications.d.ts
|
|
3
|
+
let NotificationTypeEnum = /* @__PURE__ */ function(NotificationTypeEnum$1) {
|
|
4
|
+
NotificationTypeEnum$1[NotificationTypeEnum$1["Profile data validation"] = 3] = "Profile data validation";
|
|
5
|
+
NotificationTypeEnum$1[NotificationTypeEnum$1["Document received"] = 6] = "Document received";
|
|
6
|
+
NotificationTypeEnum$1[NotificationTypeEnum$1["Document validated"] = 7] = "Document validated";
|
|
7
|
+
NotificationTypeEnum$1[NotificationTypeEnum$1["Document cancelled"] = 8] = "Document cancelled";
|
|
8
|
+
NotificationTypeEnum$1[NotificationTypeEnum$1["User profile changed"] = 10] = "User profile changed";
|
|
9
|
+
NotificationTypeEnum$1[NotificationTypeEnum$1["Taxpayer profile changed"] = 11] = "Taxpayer profile changed";
|
|
10
|
+
NotificationTypeEnum$1[NotificationTypeEnum$1["Document rejection initiated"] = 15] = "Document rejection initiated";
|
|
11
|
+
NotificationTypeEnum$1[NotificationTypeEnum$1["ERP data validation"] = 26] = "ERP data validation";
|
|
12
|
+
NotificationTypeEnum$1[NotificationTypeEnum$1["Documents processing summary"] = 33] = "Documents processing summary";
|
|
13
|
+
NotificationTypeEnum$1[NotificationTypeEnum$1["Document Template Published"] = 34] = "Document Template Published";
|
|
14
|
+
NotificationTypeEnum$1[NotificationTypeEnum$1["Document Template Deletion"] = 35] = "Document Template Deletion";
|
|
15
|
+
return NotificationTypeEnum$1;
|
|
16
|
+
}({});
|
|
17
|
+
let NotificationStatusEnum = /* @__PURE__ */ function(NotificationStatusEnum$1) {
|
|
18
|
+
NotificationStatusEnum$1[NotificationStatusEnum$1["New"] = 1] = "New";
|
|
19
|
+
NotificationStatusEnum$1[NotificationStatusEnum$1["Pending"] = 2] = "Pending";
|
|
20
|
+
NotificationStatusEnum$1[NotificationStatusEnum$1["Batched"] = 3] = "Batched";
|
|
21
|
+
NotificationStatusEnum$1[NotificationStatusEnum$1["Delivered"] = 4] = "Delivered";
|
|
22
|
+
NotificationStatusEnum$1[NotificationStatusEnum$1["Error"] = 5] = "Error";
|
|
23
|
+
return NotificationStatusEnum$1;
|
|
24
|
+
}({});
|
|
9
25
|
|
|
10
26
|
//#endregion
|
|
11
|
-
exports.
|
|
12
|
-
exports.
|
|
27
|
+
exports.NotificationStatusEnum = NotificationStatusEnum;
|
|
28
|
+
exports.NotificationTypeEnum = NotificationTypeEnum;
|
|
13
29
|
//# sourceMappingURL=index9.cjs.map
|
package/dist/index9.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index9.cjs","names":[
|
|
1
|
+
{"version":3,"file":"index9.cjs","names":[],"sources":["../src/types/notifications.d.ts"],"sourcesContent":["export type NotificationType = 3 | 6 | 7 | 8 | 10 | 11 | 15 | 26 | 33 | 34 | 35\n\nexport enum NotificationTypeEnum {\n 'Profile data validation' = 3,\n 'Document received' = 6,\n 'Document validated' = 7,\n 'Document cancelled' = 8,\n 'User profile changed' = 10,\n 'Taxpayer profile changed' = 11,\n 'Document rejection initiated' = 15,\n 'ERP data validation' = 26,\n 'Documents processing summary' = 33,\n 'Document Template Published' = 34,\n 'Document Template Deletion' = 35,\n}\n\nexport type NotificationStatus = 1 | 2 | 3 | 4 | 5\n\nexport enum NotificationStatusEnum {\n 'New' = 1,\n 'Pending' = 2,\n 'Batched' = 3,\n 'Delivered' = 4,\n 'Error' = 5,\n}\n\nexport type NotificationDeliveryAttempt = {\n attemptDateTime: string\n status: string\n statusDetails: string\n}\n\nexport type NotificationMetadata = {\n hasNext: boolean\n}\n\nexport type Notification = {\n notificationId: string\n receiverNName: string\n notificationDeliveryId: string\n creationDateTime: string\n receivedDateTime: string\n notificationSubject: string\n deliveredDateTime: string\n typeId: string\n typeName: string\n finalMessage: string\n address: string\n language: string\n status: string\n deliveryAttempts: NotificationDeliveryAttempt[]\n}\n\nexport type NotificationResponse = {\n notifications: Notification[]\n metadata: NotificationMetadata\n}\n\nexport type NotificationSearchParams = {\n dateFrom?: string\n dateTo?: string\n type?: NotificationType\n language?: string\n status?: NotificationStatus\n pageNo?: number\n pageSize?: number\n}\n"],"mappings":";;AAEA,IAAY,wEAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACD;AAID,IAAY,4EAAL;AACL;AACA;AACA;AACA;AACA;;AACD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MSICCode } from "./msic-codes-CIKdPqag.cjs";
|
|
2
|
-
import { RegistrationType } from "./documents-
|
|
2
|
+
import { RegistrationType } from "./documents-BECak3KN.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-
|
|
35
|
+
//# sourceMappingURL=taxpayer-CaDfslWB.d.cts.map
|
|
@@ -51,5 +51,5 @@ import "../YX-F34sJ7Ik.js";
|
|
|
51
51
|
import "../ZX-CDQOfsHh.js";
|
|
52
52
|
import "../XX-DOA-10JW.js";
|
|
53
53
|
import "../unit-types-VgYXIwTT.js";
|
|
54
|
-
import { Address, AllDocumentsV1_1, Buyer, CompleteInvoice, CreditNoteV1_1, DebitNoteV1_1, DocumentStatus, DocumentSummary, DocumentTypeResponse, DocumentTypeVersion, DocumentTypeVersionResponse, DocumentTypesResponse, DocumentValidationResult, DocumentValidationStepResult, FinalDocumentData, GetSubmissionResponse, InvoiceLineItem, InvoiceSubmission, InvoiceV1_1, LegalMonetaryTotal, RefundNoteV1_1, RegistrationType, ResponseDocument, SelfBilledCreditNoteV1_1, SelfBilledInvoiceV1_1, SelfBilledRefundNoteV1_1, SignedInfoObject, SignedInvoiceSubmission, SignedPropertiesData, SignedPropertiesObject, SigningCredentials, StandardError, SubmissionResponse, SubmissionStatus, Supplier, TaxCategory, TaxSubtotal, TaxTotal, UBLDocument, WorkflowParameter } from "../documents-
|
|
54
|
+
import { Address, AllDocumentsV1_1, Buyer, CompleteInvoice, CreditNoteV1_1, DebitNoteV1_1, DocumentStatus, DocumentSummary, DocumentTypeResponse, DocumentTypeVersion, DocumentTypeVersionResponse, DocumentTypesResponse, DocumentValidationResult, DocumentValidationStepResult, FinalDocumentData, GetSubmissionResponse, InvoiceLineItem, InvoiceSubmission, InvoiceV1_1, LegalMonetaryTotal, RefundNoteV1_1, RegistrationType, ResponseDocument, SelfBilledCreditNoteV1_1, SelfBilledInvoiceV1_1, SelfBilledRefundNoteV1_1, SignedInfoObject, SignedInvoiceSubmission, SignedPropertiesData, SignedPropertiesObject, SigningCredentials, StandardError, SubmissionResponse, SubmissionStatus, Supplier, TaxCategory, TaxSubtotal, TaxTotal, UBLDocument, WorkflowParameter } from "../documents-Dp19RgNX.js";
|
|
55
55
|
export { Address, AllDocumentsV1_1, Buyer, CompleteInvoice, CreditNoteV1_1, DebitNoteV1_1, DocumentStatus, DocumentSummary, DocumentTypeResponse, DocumentTypeVersion, DocumentTypeVersionResponse, DocumentTypesResponse, DocumentValidationResult, DocumentValidationStepResult, FinalDocumentData, GetSubmissionResponse, InvoiceLineItem, InvoiceSubmission, InvoiceV1_1, LegalMonetaryTotal, RefundNoteV1_1, RegistrationType, ResponseDocument, SelfBilledCreditNoteV1_1, SelfBilledInvoiceV1_1, SelfBilledRefundNoteV1_1, SignedInfoObject, SignedInvoiceSubmission, SignedPropertiesData, SignedPropertiesObject, SigningCredentials, StandardError, SubmissionResponse, SubmissionStatus, Supplier, TaxCategory, TaxSubtotal, TaxTotal, UBLDocument, WorkflowParameter };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -51,11 +51,11 @@ import "../YX-F34sJ7Ik.js";
|
|
|
51
51
|
import "../ZX-CDQOfsHh.js";
|
|
52
52
|
import "../XX-DOA-10JW.js";
|
|
53
53
|
import { UnitType, UnitTypeCode } from "../unit-types-VgYXIwTT.js";
|
|
54
|
-
import { Address, AllDocumentsV1_1, Buyer, CompleteInvoice, CreditNoteV1_1, DebitNoteV1_1, DocumentStatus, DocumentSummary, DocumentTypeResponse, DocumentTypeVersion, DocumentTypeVersionResponse, DocumentTypesResponse, DocumentValidationResult, DocumentValidationStepResult, FinalDocumentData, GetSubmissionResponse, InvoiceLineItem, InvoiceSubmission, InvoiceV1_1, LegalMonetaryTotal, RefundNoteV1_1, RegistrationType, ResponseDocument, SelfBilledCreditNoteV1_1, SelfBilledInvoiceV1_1, SelfBilledRefundNoteV1_1, SignedInfoObject, SignedInvoiceSubmission, SignedPropertiesData, SignedPropertiesObject, SigningCredentials, StandardError, SubmissionResponse, SubmissionStatus, Supplier, TaxCategory, TaxSubtotal, TaxTotal, UBLDocument, WorkflowParameter } from "../documents-
|
|
54
|
+
import { Address, AllDocumentsV1_1, Buyer, CompleteInvoice, CreditNoteV1_1, DebitNoteV1_1, DocumentStatus, DocumentSummary, DocumentTypeResponse, DocumentTypeVersion, DocumentTypeVersionResponse, DocumentTypesResponse, DocumentValidationResult, DocumentValidationStepResult, FinalDocumentData, GetSubmissionResponse, InvoiceLineItem, InvoiceSubmission, InvoiceV1_1, LegalMonetaryTotal, RefundNoteV1_1, RegistrationType, ResponseDocument, SelfBilledCreditNoteV1_1, SelfBilledInvoiceV1_1, SelfBilledRefundNoteV1_1, SignedInfoObject, SignedInvoiceSubmission, SignedPropertiesData, SignedPropertiesObject, SigningCredentials, StandardError, SubmissionResponse, SubmissionStatus, Supplier, TaxCategory, TaxSubtotal, TaxTotal, UBLDocument, WorkflowParameter } from "../documents-Dp19RgNX.js";
|
|
55
55
|
import { PaymentMode, PaymentModeCode, PaymentModeCodeEnum } from "../payment-modes-g3DzLmWb.js";
|
|
56
56
|
import { CanonicalizationMethod, Cert, CertDigest, DigestMethod, IssuerDigitalSignature, IssuerSerial, KeyInfo, QualifyingProperties, Reference, SignatureMethod, SignedInfo, SignedProperties, SignedSignatureProperties, SigningCertificate, Transform, X509Data } from "../signatures-CerHUrj3.js";
|
|
57
57
|
import { Notification, NotificationDeliveryAttempt, NotificationMetadata, NotificationResponse, NotificationSearchParams, NotificationStatus, NotificationStatusEnum, NotificationType, NotificationTypeEnum } from "../notifications-sFhgh3rJ.js";
|
|
58
|
-
import { TaxpayerQRCodeResponse, TinSearchParams, TinSearchResponse } from "../taxpayer-
|
|
58
|
+
import { TaxpayerQRCodeResponse, TinSearchParams, TinSearchResponse } from "../taxpayer-BdvCGHHC.js";
|
|
59
59
|
import { Fetch } from "../utils-C4FoVKLq.js";
|
|
60
60
|
import { ClientCredentials, TokenResponse } from "../index-CygwSf0x.js";
|
|
61
61
|
export { Address, AllDocumentsV1_1, Buyer, CanonicalizationMethod, Cert, CertDigest, Classification, ClassificationCode, ClassificationCodeEnum, ClientCredentials, CompleteInvoice, Country, CountryCode, CountryCodeEnum, CountryNameEnum, CreditNoteV1_1, Currency, CurrencyCode, CurrencyCodeEnum, DebitNoteV1_1, 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, RefundNoteV1_1, RegistrationType, ResponseDocument, SelfBilledCreditNoteV1_1, SelfBilledInvoiceV1_1, SelfBilledRefundNoteV1_1, 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 };
|
package/dist/types/taxpayer.d.ts
CHANGED
|
@@ -51,6 +51,6 @@ import "../YX-F34sJ7Ik.js";
|
|
|
51
51
|
import "../ZX-CDQOfsHh.js";
|
|
52
52
|
import "../XX-DOA-10JW.js";
|
|
53
53
|
import "../unit-types-VgYXIwTT.js";
|
|
54
|
-
import "../documents-
|
|
55
|
-
import { TaxpayerQRCodeResponse, TinSearchParams, TinSearchResponse } from "../taxpayer-
|
|
54
|
+
import "../documents-Dp19RgNX.js";
|
|
55
|
+
import { TaxpayerQRCodeResponse, TinSearchParams, TinSearchResponse } from "../taxpayer-BdvCGHHC.js";
|
|
56
56
|
export { TaxpayerQRCodeResponse, TinSearchParams, TinSearchResponse };
|
package/dist/utils/apiQueue.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/utils/apiQueue.d.ts
|
|
2
|
-
// A very small utility that provides per-endpoint request queuing with
|
|
2
|
+
// A very small utility that provides per-endpoint request queuing with rate-limits.
|
|
3
3
|
// The goal is to make sure that we never exceed the vendor-defined limits while also ensuring
|
|
4
4
|
// that every request is eventually executed.
|
|
5
5
|
//
|
|
@@ -22,16 +22,24 @@ Search Taxpayer's TIN : 60
|
|
|
22
22
|
Taxpayer's QR Code : 60
|
|
23
23
|
*/
|
|
24
24
|
type ApiCategory = "loginTaxpayer" | "loginIntermediary" | "submitDocuments" | "getSubmission" | "cancelDocument" | "rejectDocument" | "getDocument" | "getDocumentDetails" | "getRecentDocuments" | "searchDocuments" | "searchTin" | "taxpayerQr" | "default";
|
|
25
|
+
type Task<T> = () => Promise<T>;
|
|
25
26
|
/**
|
|
26
27
|
* Public helper to schedule a request according to the category's limits.
|
|
27
28
|
* Rate limits are enforced per clientId, so multiple instances with the same
|
|
28
29
|
* clientId will share rate limiters, while different clientIds get separate limiters.
|
|
30
|
+
*
|
|
31
|
+
* This implementation uses a sliding window to track all requests within the time window.
|
|
29
32
|
*/
|
|
30
|
-
declare function queueRequest<T>(clientId: string, category: ApiCategory,
|
|
33
|
+
declare function queueRequest<T>(clientId: string, category: ApiCategory, task: Task<T>, debug?: boolean): Promise<T>;
|
|
34
|
+
/**
|
|
35
|
+
* Cleanup function to clear all queues and timers for a specific client.
|
|
36
|
+
* Useful for testing or cleanup on application shutdown.
|
|
37
|
+
*/
|
|
38
|
+
declare function clearQueue(clientId: string, category?: ApiCategory): void;
|
|
31
39
|
/**
|
|
32
40
|
* Very naive path-based category detection. If no matcher fits, the `default` category
|
|
33
41
|
* (effectively unlimited) is returned. Adjust these heuristics as your API surface evolves.
|
|
34
42
|
*/
|
|
35
43
|
declare function categorizeRequest(path: string, method?: string): ApiCategory;
|
|
36
44
|
//#endregion
|
|
37
|
-
export { ApiCategory, categorizeRequest, queueRequest };
|
|
45
|
+
export { ApiCategory, categorizeRequest, clearQueue, queueRequest };
|
package/dist/utils/apiQueue.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { categorizeRequest, queueRequest } from "../apiQueue-
|
|
1
|
+
import { categorizeRequest, clearQueue, queueRequest } from "../apiQueue-B6Q644Bz.js";
|
|
2
2
|
|
|
3
|
-
export { categorizeRequest, queueRequest };
|
|
3
|
+
export { categorizeRequest, clearQueue, queueRequest };
|
package/dist/utils/document.d.ts
CHANGED
|
@@ -51,11 +51,11 @@ import "../YX-F34sJ7Ik.js";
|
|
|
51
51
|
import "../ZX-CDQOfsHh.js";
|
|
52
52
|
import "../XX-DOA-10JW.js";
|
|
53
53
|
import { UnitTypeCode } from "../unit-types-VgYXIwTT.js";
|
|
54
|
-
import { AllDocumentsV1_1, CompleteInvoice, InvoiceLineItem, InvoiceSubmission, SignedInfoObject, SignedPropertiesObject, SigningCredentials, UBLDocument } from "../documents-
|
|
54
|
+
import { AllDocumentsV1_1, CompleteInvoice, InvoiceLineItem, InvoiceSubmission, SignedInfoObject, SignedPropertiesObject, SigningCredentials, UBLDocument } from "../documents-Dp19RgNX.js";
|
|
55
55
|
import "../payment-modes-g3DzLmWb.js";
|
|
56
56
|
import "../signatures-CerHUrj3.js";
|
|
57
57
|
import "../notifications-sFhgh3rJ.js";
|
|
58
|
-
import "../taxpayer-
|
|
58
|
+
import "../taxpayer-BdvCGHHC.js";
|
|
59
59
|
import "../utils-C4FoVKLq.js";
|
|
60
60
|
import "../index-CygwSf0x.js";
|
|
61
61
|
|
|
@@ -194,10 +194,11 @@ declare const createFixedRateTaxLineItem: (params: {
|
|
|
194
194
|
/**
|
|
195
195
|
* Calculates invoice totals from line items
|
|
196
196
|
*/
|
|
197
|
-
declare const calculateInvoiceTotals: (lineItems: InvoiceLineItem[]) => {
|
|
197
|
+
declare const calculateInvoiceTotals: (lineItems: InvoiceLineItem[], payableRoundingAmount?: number) => {
|
|
198
198
|
legalMonetaryTotal: {
|
|
199
199
|
taxExclusiveAmount: number;
|
|
200
200
|
taxInclusiveAmount: number;
|
|
201
|
+
payableRoundingAmount: number;
|
|
201
202
|
payableAmount: number;
|
|
202
203
|
};
|
|
203
204
|
taxTotal: {
|
package/dist/utils/document.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import "../formatIdValue-qTxJqj9o.js";
|
|
2
|
-
import { calculateCertificateDigest, calculateDocumentDigest, calculateExpectedTaxAmount, calculateInvoiceTotals, calculateSignedPropertiesDigest, canonicalizeJSON, createFixedRateTaxLineItem, createPercentageTaxLineItem, createSignedInfoAndSign, createSignedProperties, extractCertificateInfo, generateCleanInvoiceObject, generateCleanUBLDocument, generateCompleteDocument, isFixedRateTax, isPercentageTax, signDocumentString, sortObjectKeys, transformDocumentForHashing } from "../document-
|
|
2
|
+
import { calculateCertificateDigest, calculateDocumentDigest, calculateExpectedTaxAmount, calculateInvoiceTotals, calculateSignedPropertiesDigest, canonicalizeJSON, createFixedRateTaxLineItem, createPercentageTaxLineItem, createSignedInfoAndSign, createSignedProperties, extractCertificateInfo, generateCleanInvoiceObject, generateCleanUBLDocument, generateCompleteDocument, isFixedRateTax, isPercentageTax, signDocumentString, sortObjectKeys, transformDocumentForHashing } from "../document-D4O7JY0G.js";
|
|
3
3
|
|
|
4
4
|
export { calculateCertificateDigest, calculateDocumentDigest, calculateExpectedTaxAmount, calculateInvoiceTotals, calculateSignedPropertiesDigest, canonicalizeJSON, createFixedRateTaxLineItem, createPercentageTaxLineItem, createSignedInfoAndSign, createSignedProperties, extractCertificateInfo, generateCleanInvoiceObject, generateCleanUBLDocument, generateCompleteDocument, isFixedRateTax, isPercentageTax, signDocumentString, sortObjectKeys, transformDocumentForHashing };
|
|
@@ -51,11 +51,11 @@ import "../YX-F34sJ7Ik.js";
|
|
|
51
51
|
import "../ZX-CDQOfsHh.js";
|
|
52
52
|
import "../XX-DOA-10JW.js";
|
|
53
53
|
import "../unit-types-VgYXIwTT.js";
|
|
54
|
-
import { InvoiceV1_1 } from "../documents-
|
|
54
|
+
import { InvoiceV1_1 } from "../documents-Dp19RgNX.js";
|
|
55
55
|
import "../payment-modes-g3DzLmWb.js";
|
|
56
56
|
import "../signatures-CerHUrj3.js";
|
|
57
57
|
import "../notifications-sFhgh3rJ.js";
|
|
58
|
-
import "../taxpayer-
|
|
58
|
+
import "../taxpayer-BdvCGHHC.js";
|
|
59
59
|
import "../utils-C4FoVKLq.js";
|
|
60
60
|
import "../index-CygwSf0x.js";
|
|
61
61
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../formatIdValue-qTxJqj9o.js";
|
|
2
|
-
import { calculateCertificateDigest, calculateDocumentDigest, calculateSignedPropertiesDigest, createSignedProperties, extractCertificateInfo } from "../document-
|
|
2
|
+
import { calculateCertificateDigest, calculateDocumentDigest, calculateSignedPropertiesDigest, createSignedProperties, extractCertificateInfo } from "../document-D4O7JY0G.js";
|
|
3
3
|
import crypto from "crypto";
|
|
4
4
|
|
|
5
5
|
//#region src/utils/signature-diagnostics.ts
|
|
@@ -51,11 +51,11 @@ import "../YX-F34sJ7Ik.js";
|
|
|
51
51
|
import "../ZX-CDQOfsHh.js";
|
|
52
52
|
import "../XX-DOA-10JW.js";
|
|
53
53
|
import "../unit-types-VgYXIwTT.js";
|
|
54
|
-
import { InvoiceLineItem, InvoiceV1_1 } from "../documents-
|
|
54
|
+
import { InvoiceLineItem, InvoiceV1_1 } from "../documents-Dp19RgNX.js";
|
|
55
55
|
import "../payment-modes-g3DzLmWb.js";
|
|
56
56
|
import "../signatures-CerHUrj3.js";
|
|
57
57
|
import "../notifications-sFhgh3rJ.js";
|
|
58
|
-
import "../taxpayer-
|
|
58
|
+
import "../taxpayer-BdvCGHHC.js";
|
|
59
59
|
import "../utils-C4FoVKLq.js";
|
|
60
60
|
import "../index-CygwSf0x.js";
|
|
61
61
|
|
package/package.json
CHANGED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
//#region src/utils/apiQueue.ts
|
|
2
|
-
const WINDOW = 6e4;
|
|
3
|
-
const RATE_LIMITS = {
|
|
4
|
-
loginTaxpayer: {
|
|
5
|
-
limit: 12,
|
|
6
|
-
windowMs: WINDOW
|
|
7
|
-
},
|
|
8
|
-
loginIntermediary: {
|
|
9
|
-
limit: 12,
|
|
10
|
-
windowMs: WINDOW
|
|
11
|
-
},
|
|
12
|
-
submitDocuments: {
|
|
13
|
-
limit: 100,
|
|
14
|
-
windowMs: WINDOW
|
|
15
|
-
},
|
|
16
|
-
getSubmission: {
|
|
17
|
-
limit: 300,
|
|
18
|
-
windowMs: WINDOW
|
|
19
|
-
},
|
|
20
|
-
cancelDocument: {
|
|
21
|
-
limit: 12,
|
|
22
|
-
windowMs: WINDOW
|
|
23
|
-
},
|
|
24
|
-
rejectDocument: {
|
|
25
|
-
limit: 12,
|
|
26
|
-
windowMs: WINDOW
|
|
27
|
-
},
|
|
28
|
-
getDocument: {
|
|
29
|
-
limit: 60,
|
|
30
|
-
windowMs: WINDOW
|
|
31
|
-
},
|
|
32
|
-
getDocumentDetails: {
|
|
33
|
-
limit: 125,
|
|
34
|
-
windowMs: WINDOW
|
|
35
|
-
},
|
|
36
|
-
getRecentDocuments: {
|
|
37
|
-
limit: 12,
|
|
38
|
-
windowMs: WINDOW
|
|
39
|
-
},
|
|
40
|
-
searchDocuments: {
|
|
41
|
-
limit: 12,
|
|
42
|
-
windowMs: WINDOW
|
|
43
|
-
},
|
|
44
|
-
searchTin: {
|
|
45
|
-
limit: 60,
|
|
46
|
-
windowMs: WINDOW
|
|
47
|
-
},
|
|
48
|
-
taxpayerQr: {
|
|
49
|
-
limit: 60,
|
|
50
|
-
windowMs: WINDOW
|
|
51
|
-
},
|
|
52
|
-
default: {
|
|
53
|
-
limit: 12,
|
|
54
|
-
windowMs: WINDOW
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* A token-bucket style rate-limiter with queuing.
|
|
59
|
-
* Uses a sliding window approach to allow bursts while respecting overall limits.
|
|
60
|
-
* Each category gets its own instance so limits remain isolated.
|
|
61
|
-
*/
|
|
62
|
-
var RateLimiter = class {
|
|
63
|
-
limit;
|
|
64
|
-
windowMs;
|
|
65
|
-
minInterval;
|
|
66
|
-
queue = [];
|
|
67
|
-
nextAvailable = 0;
|
|
68
|
-
timer = null;
|
|
69
|
-
requestTimes = [];
|
|
70
|
-
isProcessing = false;
|
|
71
|
-
constructor(config) {
|
|
72
|
-
this.limit = config.limit;
|
|
73
|
-
this.windowMs = config.windowMs;
|
|
74
|
-
this.minInterval = Math.ceil(this.windowMs / this.limit * .5);
|
|
75
|
-
}
|
|
76
|
-
drainQueue() {
|
|
77
|
-
if (this.isProcessing || this.queue.length === 0) return;
|
|
78
|
-
this.isProcessing = true;
|
|
79
|
-
try {
|
|
80
|
-
const now = Date.now();
|
|
81
|
-
this.requestTimes = this.requestTimes.filter((time) => now - time < this.windowMs);
|
|
82
|
-
if (this.requestTimes.length >= this.limit) {
|
|
83
|
-
const oldestRequest = Math.min(...this.requestTimes);
|
|
84
|
-
const nextAvailable = oldestRequest + this.windowMs;
|
|
85
|
-
this.scheduleNextDrain(nextAvailable - now);
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
if (now < this.nextAvailable) {
|
|
89
|
-
this.scheduleNextDrain(this.nextAvailable - now);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const next = this.queue.shift();
|
|
93
|
-
const requestStartTime = Date.now();
|
|
94
|
-
this.requestTimes.push(requestStartTime);
|
|
95
|
-
this.nextAvailable = requestStartTime + this.minInterval;
|
|
96
|
-
next();
|
|
97
|
-
} finally {
|
|
98
|
-
this.isProcessing = false;
|
|
99
|
-
}
|
|
100
|
-
if (this.queue.length > 0) {
|
|
101
|
-
const now = Date.now();
|
|
102
|
-
const delay = Math.max(1, this.nextAvailable - now);
|
|
103
|
-
this.scheduleNextDrain(delay);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
scheduleNextDrain(delay) {
|
|
107
|
-
if (this.timer) clearTimeout(this.timer);
|
|
108
|
-
this.timer = setTimeout(() => {
|
|
109
|
-
this.timer = null;
|
|
110
|
-
this.drainQueue();
|
|
111
|
-
}, Math.max(0, delay));
|
|
112
|
-
}
|
|
113
|
-
get queueSize() {
|
|
114
|
-
return this.queue.length;
|
|
115
|
-
}
|
|
116
|
-
cleanup() {
|
|
117
|
-
if (this.timer) {
|
|
118
|
-
clearTimeout(this.timer);
|
|
119
|
-
this.timer = null;
|
|
120
|
-
}
|
|
121
|
-
this.queue = [];
|
|
122
|
-
this.requestTimes = [];
|
|
123
|
-
this.isProcessing = false;
|
|
124
|
-
}
|
|
125
|
-
schedule(fn, debug = false, category) {
|
|
126
|
-
return new Promise((resolve, reject) => {
|
|
127
|
-
const execute = () => {
|
|
128
|
-
if (debug && category) console.log(`[apiQueue] ▶️ Executing request (${category}). Remaining queue: ${this.queue.length}`);
|
|
129
|
-
try {
|
|
130
|
-
const result = fn();
|
|
131
|
-
if (result && typeof result.then === "function") result.then(resolve).catch(reject);
|
|
132
|
-
else resolve(result);
|
|
133
|
-
} catch (err) {
|
|
134
|
-
reject(err);
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
if (debug && category) console.log(`[apiQueue] ⏳ Queued request (${category}). Queue length before push: ${this.queue.length}`);
|
|
138
|
-
this.queue.push(execute);
|
|
139
|
-
this.drainQueue();
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
const limiterRegistry = /* @__PURE__ */ new Map();
|
|
144
|
-
function getLimiter(clientId, category) {
|
|
145
|
-
if (!limiterRegistry.has(clientId)) limiterRegistry.set(clientId, /* @__PURE__ */ new Map());
|
|
146
|
-
const clientLimiters = limiterRegistry.get(clientId);
|
|
147
|
-
if (!clientLimiters.has(category)) clientLimiters.set(category, new RateLimiter(RATE_LIMITS[category]));
|
|
148
|
-
return clientLimiters.get(category);
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Public helper to schedule a request according to the category's limits.
|
|
152
|
-
* Rate limits are enforced per clientId, so multiple instances with the same
|
|
153
|
-
* clientId will share rate limiters, while different clientIds get separate limiters.
|
|
154
|
-
*/
|
|
155
|
-
function queueRequest(clientId, category, fn, debug = false) {
|
|
156
|
-
const limiter = getLimiter(clientId, category);
|
|
157
|
-
return limiter.schedule(fn, debug, category);
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Very naive path-based category detection. If no matcher fits, the `default` category
|
|
161
|
-
* (effectively unlimited) is returned. Adjust these heuristics as your API surface evolves.
|
|
162
|
-
*/
|
|
163
|
-
function categorizeRequest(path, method = "GET") {
|
|
164
|
-
const cleanPath = path.toLowerCase();
|
|
165
|
-
const isPost = method?.toUpperCase() === "POST";
|
|
166
|
-
if (cleanPath.includes("/documentsubmissions")) return isPost ? "submitDocuments" : "getSubmission";
|
|
167
|
-
if (cleanPath.includes("/documents/recent")) return "getRecentDocuments";
|
|
168
|
-
if (cleanPath.includes("/documents/search")) return "searchDocuments";
|
|
169
|
-
if (cleanPath.includes("/documents/state/") && cleanPath.endsWith("/state")) return "cancelDocument";
|
|
170
|
-
if (/\/documents\/[^/]+\/raw$/.test(cleanPath)) return "getDocument";
|
|
171
|
-
if (/\/documents\/[^/]+\/details$/.test(cleanPath)) return "getDocumentDetails";
|
|
172
|
-
if (cleanPath.includes("/taxpayer/search/tin")) return "searchTin";
|
|
173
|
-
if (cleanPath.includes("/taxpayer/validate/")) return "searchTin";
|
|
174
|
-
if (cleanPath.includes("/taxpayer/qrcode")) return "taxpayerQr";
|
|
175
|
-
if (cleanPath.includes("/searchtin")) return "searchTin";
|
|
176
|
-
if (cleanPath.includes("/qrcode")) return "taxpayerQr";
|
|
177
|
-
if (cleanPath.includes("/connect/token")) return "loginTaxpayer";
|
|
178
|
-
return "default";
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
//#endregion
|
|
182
|
-
export { categorizeRequest, queueRequest };
|