@ripwords/myinvois-client 0.2.27 → 0.2.29
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.js +1 -1
- package/dist/api/documentSubmission.js +2 -2
- package/dist/{document-nWFcUMsi.js → document-DI6hw1MO.js} +1 -1
- package/dist/{document-CNM7-o5x.cjs → document-DWsGewNs.cjs} +2 -2
- package/dist/document-DWsGewNs.cjs.map +1 -0
- package/dist/{documentManagement-CIQPkmyb.js → documentManagement-CeNbp3qm.js} +13 -3
- package/dist/{documentManagement-DQ7JEcBq.cjs → documentManagement-CyPwiyP4.cjs} +14 -4
- package/dist/documentManagement-CyPwiyP4.cjs.map +1 -0
- package/dist/{documentSubmission-BE1En5JO.cjs → documentSubmission-D96QqHJ-.cjs} +2 -2
- package/dist/{documentSubmission-BE1En5JO.cjs.map → documentSubmission-D96QqHJ-.cjs.map} +1 -1
- package/dist/{documentSubmission-CVwFwnDd.js → documentSubmission-Dr4R4sKD.js} +1 -1
- package/dist/index.cjs +35 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +26 -0
- package/dist/index.js +35 -3
- package/dist/index10.cjs +53 -16
- package/dist/index10.cjs.map +1 -1
- package/dist/index11.cjs +532 -0
- package/dist/index11.cjs.map +1 -0
- package/dist/index12.cjs +187 -25
- package/dist/index12.cjs.map +1 -1
- package/dist/index13.cjs +0 -24
- package/dist/index14.cjs +25 -0
- package/dist/index14.cjs.map +1 -0
- package/dist/index17.cjs +28 -4
- package/dist/index17.cjs.map +1 -0
- package/dist/index18.cjs +24 -6
- package/dist/index18.cjs.map +1 -0
- package/dist/index19.cjs +0 -5
- package/dist/index2.cjs +3 -61
- package/dist/index20.cjs +33 -2
- package/dist/index20.cjs.map +1 -0
- package/dist/index21.cjs +23 -2
- package/dist/{index13.cjs.map → index21.cjs.map} +1 -1
- package/dist/index22.cjs +0 -6
- package/dist/index23.cjs +0 -4
- package/dist/index24.cjs +0 -13
- package/dist/index25.cjs +4 -4
- package/dist/index26.cjs +5 -20
- package/dist/index27.cjs +4 -2
- package/dist/index28.cjs +2 -2
- package/dist/index29.cjs +2 -329
- package/dist/index3.cjs +9 -528
- package/dist/index3.cjs.map +1 -1
- package/dist/index30.cjs +5 -192
- package/dist/index4.cjs +4 -195
- package/dist/index5.cjs +22 -0
- package/dist/index6.cjs +2 -24
- package/dist/index67.cts.map +1 -1
- package/dist/index7.cjs +3 -0
- package/dist/index8.cjs +330 -0
- package/dist/index8.cjs.map +1 -0
- package/dist/index9.cjs +189 -25
- package/dist/index9.cjs.map +1 -1
- package/dist/utils/document.js +1 -1
- package/dist/utils/signature-diagnostics.js +1 -1
- package/package.json +3 -1
- package/dist/document-CNM7-o5x.cjs.map +0 -1
- package/dist/documentManagement-DQ7JEcBq.cjs.map +0 -1
- package/dist/index2.cjs.map +0 -1
- package/dist/index24.cjs.map +0 -1
- package/dist/index29.cjs.map +0 -1
- package/dist/index30.cjs.map +0 -1
- package/dist/index4.cjs.map +0 -1
- package/dist/index6.cjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../formatIdValue-qTxJqj9o.js";
|
|
2
|
-
import "../document-
|
|
3
|
-
import { getSubmissionStatus, performDocumentAction, submitDocument } from "../documentSubmission-
|
|
2
|
+
import "../document-DI6hw1MO.js";
|
|
3
|
+
import { getSubmissionStatus, performDocumentAction, submitDocument } from "../documentSubmission-Dr4R4sKD.js";
|
|
4
4
|
|
|
5
5
|
export { getSubmissionStatus, performDocumentAction, submitDocument };
|
|
@@ -296,7 +296,7 @@ const calculateCertificateDigest = (certificatePem) => {
|
|
|
296
296
|
const hash = crypto.createHash("sha256");
|
|
297
297
|
hash.update(rawCertificateData);
|
|
298
298
|
return hash.digest("base64");
|
|
299
|
-
} catch
|
|
299
|
+
} catch {
|
|
300
300
|
const certificateContent = certificatePem.replace(/-----BEGIN CERTIFICATE-----/g, "").replace(/-----END CERTIFICATE-----/g, "").replace(/\s+/g, "");
|
|
301
301
|
const certificateBinary = Buffer.from(certificateContent, "base64");
|
|
302
302
|
const hash = crypto.createHash("sha256");
|
|
@@ -297,7 +297,7 @@ const calculateCertificateDigest = (certificatePem) => {
|
|
|
297
297
|
const hash = crypto.default.createHash("sha256");
|
|
298
298
|
hash.update(rawCertificateData);
|
|
299
299
|
return hash.digest("base64");
|
|
300
|
-
} catch
|
|
300
|
+
} catch {
|
|
301
301
|
const certificateContent = certificatePem.replace(/-----BEGIN CERTIFICATE-----/g, "").replace(/-----END CERTIFICATE-----/g, "").replace(/\s+/g, "");
|
|
302
302
|
const certificateBinary = Buffer.from(certificateContent, "base64");
|
|
303
303
|
const hash = crypto.default.createHash("sha256");
|
|
@@ -698,4 +698,4 @@ Object.defineProperty(exports, 'transformDocumentForHashing', {
|
|
|
698
698
|
return transformDocumentForHashing;
|
|
699
699
|
}
|
|
700
700
|
});
|
|
701
|
-
//# sourceMappingURL=document-
|
|
701
|
+
//# sourceMappingURL=document-DWsGewNs.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-DWsGewNs.cjs","names":["item: InvoiceLineItem","doc: AllDocumentsV1_1","obj: unknown","sortedObj: Record<string, unknown>","invoice: AllDocumentsV1_1","invoices: AllDocumentsV1_1[]","invoice: InvoiceSubmission","certificatePem: string","X509Certificate","str: string","issuer: string","serialHex: string","error: unknown","certificateDigest: string","signingTime: string","issuerName: string","serialNumber: string","signedProperties: SignedPropertiesObject","useTargetWrapper: boolean","digestObj: unknown","docDigest: string","propsDigest: string","privateKeyPem: string","signedInfo: SignedInfoObject","documentString: string","signingCredentials: SigningCredentials","params: {\n itemClassificationCode: ClassificationCode\n itemDescription: string\n unitPrice: number\n quantity?: number\n taxType: TaxTypeCode\n taxRate: number\n totalTaxableAmountPerLine?: number\n}","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}","lineItems: InvoiceLineItem[]"],"sources":["../src/utils/document.ts"],"sourcesContent":["import crypto, { X509Certificate } from 'crypto'\nimport {\n InvoiceSubmission,\n AllDocumentsV1_1,\n SigningCredentials,\n SignedPropertiesObject,\n UBLDocument,\n CompleteInvoice,\n SignedInfoObject,\n UnitTypeCode,\n InvoiceLineItem,\n} from '../types'\nimport type { ClassificationCode } from '../types'\nimport type { TaxTypeCode } from '../types'\nimport { formatIdValue } from './formatIdValue'\n\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/**\n * Determines if a line item uses fixed rate taxation\n */\nexport const isFixedRateTax = (item: InvoiceLineItem): boolean => {\n return (\n item.taxPerUnitAmount !== undefined && item.baseUnitMeasure !== undefined\n )\n}\n\n/**\n * Determines if a line item uses percentage taxation\n */\nexport const isPercentageTax = (item: InvoiceLineItem): boolean => {\n return item.taxRate !== undefined && !isFixedRateTax(item)\n}\n\n/**\n * Calculates expected tax amount for a line item based on its tax type\n */\nexport const calculateExpectedTaxAmount = (item: InvoiceLineItem): number => {\n if (isFixedRateTax(item)) {\n return item.taxPerUnitAmount! * item.baseUnitMeasure!\n } else if (isPercentageTax(item)) {\n return (item.totalTaxableAmountPerLine * item.taxRate!) / 100\n }\n return 0\n}\n\n/**\n * Extracts the line-item array from any document variant\n */\nconst getLineItems = (doc: AllDocumentsV1_1): InvoiceLineItem[] => {\n if ('invoiceLineItems' in doc) return doc.invoiceLineItems\n if ('creditNoteLineItems' in doc) return doc.creditNoteLineItems\n if ('debitNoteLineItems' in doc) return doc.debitNoteLineItems\n if ('refundNoteLineItems' in doc) return doc.refundNoteLineItems\n if ('selfBilledCreditNoteLineItems' in doc)\n return doc.selfBilledCreditNoteLineItems\n if ('selfBilledRefundNoteLineItems' in doc)\n return doc.selfBilledRefundNoteLineItems\n // Fallback (should never happen with exhaustive types)\n return []\n}\n\n/**\n * Helper function to recursively sort object keys for JSON canonicalization\n */\nexport function sortObjectKeys(obj: unknown): unknown {\n if (obj === null || typeof obj !== 'object') {\n return obj\n }\n\n if (Array.isArray(obj)) {\n return obj.map(sortObjectKeys)\n }\n\n const sortedObj: Record<string, unknown> = {}\n const keys = Object.keys(obj as Record<string, unknown>).sort()\n\n for (const key of keys) {\n sortedObj[key] = sortObjectKeys((obj as Record<string, unknown>)[key])\n }\n\n return sortedObj\n}\n\n/**\n * Enhanced canonicalization following MyInvois specification exactly\n * Key changes: ensure consistent ordering and formatting\n */\nexport const canonicalizeJSON = (obj: unknown): string => {\n const sortedObj = sortObjectKeys(obj)\n // Use compact JSON with no extra whitespace\n return JSON.stringify(sortedObj, null, 0)\n}\n\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 const generateCleanInvoiceObject = (\n invoice: AllDocumentsV1_1,\n): InvoiceSubmission => {\n const lineItems = getLineItems(invoice)\n return {\n // === MANDATORY CORE FIELDS ===\n ID: [{ _: invoice.eInvoiceCodeOrNumber }],\n IssueDate: [{ _: invoice.eInvoiceDate }],\n IssueTime: [{ _: invoice.eInvoiceTime }],\n InvoiceTypeCode: [\n {\n _: invoice.eInvoiceTypeCode,\n listVersionID: invoice.eInvoiceVersion || '1.1',\n },\n ],\n DocumentCurrencyCode: [{ _: invoice.invoiceCurrencyCode }],\n\n // === BILLING REFERENCE (only for credit/debit/refund notes) ===\n ...('originalEInvoiceReferenceNumber' in invoice &&\n 'originalEInvoiceInternalId' in invoice &&\n invoice.originalEInvoiceReferenceNumber\n ? {\n BillingReference: [\n {\n InvoiceDocumentReference: [\n {\n UUID: [\n {\n _: invoice.originalEInvoiceReferenceNumber,\n },\n ],\n ID: [\n {\n _: invoice.originalEInvoiceInternalId,\n },\n ],\n },\n ],\n },\n ],\n }\n : {}),\n\n // === SUPPLIER PARTY (AccountingSupplierParty) ===\n AccountingSupplierParty: [\n {\n Party: [\n {\n // Industry Classification - required field\n IndustryClassificationCode: [\n {\n _: invoice.supplier.industryClassificationCode,\n name: invoice.supplier.industryClassificationDescription,\n },\n ],\n\n // Party Identifications\n PartyIdentification: [\n {\n ID: [\n {\n _: invoice.supplier.tin,\n schemeID: 'TIN',\n },\n ],\n },\n {\n ID: [\n {\n _: formatIdValue(invoice.supplier.registrationNumber),\n schemeID: invoice.supplier.registrationType || 'NRIC',\n },\n ],\n },\n ],\n\n // Postal Address - FIXED listID format\n PostalAddress: [\n {\n CityName: [{ _: invoice.supplier.address.cityName }],\n CountrySubentityCode: [{ _: invoice.supplier.address.state }],\n AddressLine: [\n {\n Line: [{ _: invoice.supplier.address.addressLine0 }],\n },\n ],\n Country: [\n {\n IdentificationCode: [\n {\n _: invoice.supplier.address.country || 'MYS',\n listID: '3166-1', // FIXED: was \"ISO3166-1\"\n listAgencyID: 'ISO',\n },\n ],\n },\n ],\n },\n ],\n\n // Party Legal Entity\n PartyLegalEntity: [\n {\n RegistrationName: [{ _: invoice.supplier.name }],\n },\n ],\n\n // Contact Information\n Contact: [\n {\n Telephone: [{ _: invoice.supplier.contactNumber || '' }],\n },\n ],\n },\n ],\n },\n ],\n\n // === BUYER PARTY (AccountingCustomerParty) ===\n AccountingCustomerParty: [\n {\n Party: [\n {\n // Party Identifications\n PartyIdentification: [\n {\n ID: [\n {\n _: invoice.buyer.tin,\n schemeID: 'TIN',\n },\n ],\n },\n {\n ID: [\n {\n _: formatIdValue(invoice.buyer.registrationNumber),\n schemeID: invoice.buyer.registrationType || 'NRIC',\n },\n ],\n },\n {\n ID: [\n {\n _: invoice.buyer.sstRegistrationNumber || 'NA',\n schemeID: 'SST',\n },\n ],\n },\n ],\n\n // Postal Address - FIXED listID format\n PostalAddress: [\n {\n CityName: [{ _: invoice.buyer.address.cityName }],\n CountrySubentityCode: [{ _: invoice.buyer.address.state }],\n AddressLine: [\n {\n Line: [{ _: invoice.buyer.address.addressLine0 }],\n },\n ],\n Country: [\n {\n IdentificationCode: [\n {\n _: invoice.buyer.address.country || 'MYS',\n listID: '3166-1', // FIXED: was \"ISO3166-1\"\n listAgencyID: 'ISO',\n },\n ],\n },\n ],\n },\n ],\n\n // Party Legal Entity\n PartyLegalEntity: [\n {\n RegistrationName: [{ _: invoice.buyer.name }],\n },\n ],\n\n // Contact Information\n Contact: [\n {\n Telephone: [{ _: invoice.buyer.contactNumber || '' }],\n },\n ],\n },\n ],\n },\n ],\n\n // === TAX TOTAL ===\n TaxTotal: [\n {\n TaxAmount: [\n {\n _: invoice.taxTotal.taxAmount,\n currencyID: invoice.invoiceCurrencyCode,\n },\n ],\n TaxSubtotal: [\n // Generate basic tax subtotal from invoice line items\n {\n TaxableAmount: [\n {\n _: invoice.legalMonetaryTotal.taxExclusiveAmount,\n currencyID: invoice.invoiceCurrencyCode,\n },\n ],\n TaxAmount: [\n {\n _: invoice.taxTotal.taxAmount,\n currencyID: invoice.invoiceCurrencyCode,\n },\n ],\n TaxCategory: [\n {\n ID: [{ _: lineItems[0]?.taxType || '01' }],\n TaxScheme: [\n {\n ID: [\n {\n _: 'OTH',\n schemeAgencyID: '6',\n schemeID: 'UN/ECE 5153',\n },\n ],\n },\n ],\n },\n ],\n },\n ],\n },\n ],\n\n // === LEGAL MONETARY TOTAL ===\n LegalMonetaryTotal: [\n {\n LineExtensionAmount: [\n {\n _: invoice.legalMonetaryTotal.taxExclusiveAmount,\n currencyID: invoice.invoiceCurrencyCode,\n },\n ],\n TaxExclusiveAmount: [\n {\n _: invoice.legalMonetaryTotal.taxExclusiveAmount,\n currencyID: invoice.invoiceCurrencyCode,\n },\n ],\n TaxInclusiveAmount: [\n {\n _: invoice.legalMonetaryTotal.taxInclusiveAmount,\n currencyID: invoice.invoiceCurrencyCode,\n },\n ],\n PayableAmount: [\n {\n _: invoice.legalMonetaryTotal.payableAmount,\n currencyID: invoice.invoiceCurrencyCode,\n },\n ],\n },\n ],\n\n // === INVOICE LINES ===\n InvoiceLine: lineItems.map((item, index) => ({\n ID: [{ _: (index + 1).toString() }],\n\n // Item Information\n Item: [\n {\n CommodityClassification: [\n {\n ItemClassificationCode: [\n {\n _: item.itemClassificationCode,\n listID: 'CLASS',\n },\n ],\n },\n ],\n Description: [{ _: item.itemDescription }],\n },\n ],\n\n ItemPriceExtension: [\n {\n Amount: [\n {\n _: item.totalTaxableAmountPerLine,\n currencyID: invoice.invoiceCurrencyCode,\n },\n ],\n },\n ],\n\n LineExtensionAmount: [\n {\n _: item.totalTaxableAmountPerLine,\n currencyID: invoice.invoiceCurrencyCode,\n },\n ],\n\n // Price Information\n Price: [\n {\n PriceAmount: [\n {\n _: item.unitPrice,\n currencyID: invoice.invoiceCurrencyCode,\n },\n ],\n },\n ],\n\n // Tax Information for line\n TaxTotal: [\n {\n TaxAmount: [\n {\n _: item.taxAmount,\n currencyID: invoice.invoiceCurrencyCode,\n },\n ],\n TaxSubtotal: [\n {\n TaxableAmount: [\n {\n _: item.totalTaxableAmountPerLine,\n currencyID: invoice.invoiceCurrencyCode,\n },\n ],\n TaxAmount: [\n {\n _: item.taxAmount,\n currencyID: invoice.invoiceCurrencyCode,\n },\n ],\n // Conditional tax fields based on taxation type\n ...(item.taxPerUnitAmount !== undefined &&\n item.baseUnitMeasure !== undefined\n ? {\n // Fixed Rate Taxation\n PerUnitAmount: [\n {\n _: item.taxPerUnitAmount,\n currencyID: invoice.invoiceCurrencyCode,\n },\n ],\n BaseUnitMeasure: [\n {\n _: item.baseUnitMeasure,\n unitCode: item.baseUnitMeasureCode || 'C62',\n },\n ],\n }\n : item.taxRate !== undefined\n ? {\n // Percentage Taxation\n Percent: [{ _: item.taxRate }],\n }\n : {}),\n TaxCategory: [\n {\n ID: [{ _: item.taxType }],\n TaxScheme: [\n {\n ID: [\n {\n _: 'OTH',\n schemeAgencyID: '6',\n schemeID: 'UN/ECE 5153',\n },\n ],\n },\n ],\n },\n ],\n },\n ],\n },\n ],\n })),\n\n // === TAX EXCHANGE RATE (mandatory where applicable) ===\n TaxExchangeRate: invoice.currencyExchangeRate\n ? [\n {\n SourceCurrencyCode: [\n {\n _: invoice.invoiceCurrencyCode,\n },\n ],\n TargetCurrencyCode: [\n {\n _: 'MYR',\n },\n ],\n CalculationRate: [\n {\n _: invoice.currencyExchangeRate,\n },\n ],\n },\n ]\n : undefined,\n }\n}\n\n/**\n * Generates the complete UBL document structure with namespace declarations\n */\nexport const generateCleanUBLDocument = (\n invoices: AllDocumentsV1_1[],\n): UBLDocument => {\n return {\n _D: 'urn:oasis:names:specification:ubl:schema:xsd:Invoice-2',\n _A: 'urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2',\n _B: 'urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2',\n Invoice: invoices.map(generateCleanInvoiceObject),\n }\n}\n\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 const transformDocumentForHashing = (\n invoices: AllDocumentsV1_1[],\n): string => {\n // Generate clean UBL document structure\n const cleanDocument = generateCleanUBLDocument(invoices)\n\n // Deep clone to avoid mutating input\n const documentForTransform = JSON.parse(JSON.stringify(cleanDocument))\n if (\n documentForTransform.Invoice &&\n Array.isArray(documentForTransform.Invoice)\n ) {\n documentForTransform.Invoice.forEach((invoice: InvoiceSubmission) => {\n delete invoice.UBLExtensions\n delete invoice.Signature\n })\n }\n\n // Convert to JSON string first\n const jsonString = JSON.stringify(documentForTransform)\n\n // Apply the exact same regex-based minification as PowerShell script\n // This regex preserves whitespace within quoted strings but removes all other whitespace\n const minifiedJson = jsonString.replace(\n /(\"(?:\\\\.|[^\"\\\\])*\")|\\s+/g,\n (match, quotedString) => {\n if (quotedString) {\n return quotedString // Keep string content exactly as-is\n } else {\n return '' // Remove all other whitespace\n }\n },\n )\n\n return minifiedJson\n}\n\n/**\n * Step 2: Calculate Document Digest\n * FIXED: Remove UBLExtensions and Signature before hashing (DS322)\n * Based on working implementation pattern\n */\nexport const calculateDocumentDigest = (\n invoices: AllDocumentsV1_1[],\n): string => {\n // Use the transformation function to get the minified, cleaned JSON string\n const documentString = transformDocumentForHashing(invoices)\n\n // Calculate SHA-256 hash\n const hash = crypto.createHash('sha256')\n hash.update(documentString, 'utf8')\n\n // Return as Base64 (DocDigest)\n return hash.digest('base64')\n}\n\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 const calculateCertificateDigest = (certificatePem: string): string => {\n try {\n // Create X509Certificate object to get raw data (like PowerShell $cert.RawData)\n const cert = new X509Certificate(certificatePem)\n\n // Get the raw certificate data (DER-encoded, like PowerShell $cert.RawData)\n const rawCertificateData = cert.raw\n\n // Calculate SHA-256 hash of raw certificate data (like PowerShell $sha256.ComputeHash($cert.RawData))\n const hash = crypto.createHash('sha256')\n hash.update(rawCertificateData)\n\n // Return as Base64 (like PowerShell [Convert]::ToBase64String($certHash))\n return hash.digest('base64')\n } catch {\n // Fallback to the previous method if X509Certificate fails\n const certificateContent = certificatePem\n .replace(/-----BEGIN CERTIFICATE-----/g, '')\n .replace(/-----END CERTIFICATE-----/g, '')\n .replace(/\\s+/g, '') // Remove all whitespace\n\n // Convert Base64 to binary\n const certificateBinary = Buffer.from(certificateContent, 'base64')\n\n // Calculate SHA-256 hash of binary content\n const hash = crypto.createHash('sha256')\n hash.update(certificateBinary)\n\n // Return as Base64\n return hash.digest('base64')\n }\n}\n\n/**\n * Enhanced certificate info extraction with better error handling\n * FIXED: Normalize issuer name format to match MyInvois expectations (DS326)\n */\nexport const extractCertificateInfo = (\n certificatePem: string,\n): {\n issuerName: string\n serialNumber: string\n subjectName: string\n} => {\n try {\n const cert = new X509Certificate(certificatePem)\n\n // Extract serial number and convert to decimal string\n const serialNumberHex = cert.serialNumber\n\n // FIXED: Use raw issuer name like PowerShell $cert.IssuerName.Name\n // Apply XML escaping to match PowerShell [System.Security.SecurityElement]::Escape()\n const escapeXmlSpecialChars = (str: string): string => {\n return str\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''')\n }\n\n // FIXED: Normalize issuer name to match MyInvois expectations\n // The issuer name should be in the format: \"CN=Trial LHDNM Sub CA V1, OU=Terms of use at http://www.testcertcomp.com.my, O=LHDNM, C=MY\"\n const normalizeIssuerName = (issuer: string): string => {\n // Node returns issuer DN in reverse RDN order (C, O, ... , CN).\n // The MyInvois validator expects forward order (CN first).\n // 1. Break DN into components separated by newline or commas.\n // 2. Reverse to get CN → ... → C ordering.\n // 3. Join with \", \" and ensure single '=' spacing.\n const parts = issuer\n .split(/\\r?\\n|,\\s*/)\n .map(part => part.trim())\n .filter(part => part.length > 0)\n .reverse()\n return parts.join(', ').replace(/\\s*=\\s*/g, '=')\n }\n\n // Enhanced serial number formatting\n const formatSerialNumber = (serialHex: string): string => {\n // Convert hex to decimal and ensure it's a string\n const decimal = BigInt('0x' + serialHex).toString()\n return decimal\n }\n\n // FIXED: Use raw subject name without normalization to match PowerShell $cert.SubjectName.Name\n // The subject name should be in the format shown in the specification\n const rawSubjectName = cert.subject\n\n return {\n issuerName: escapeXmlSpecialChars(normalizeIssuerName(cert.issuer)),\n serialNumber: formatSerialNumber(serialNumberHex),\n subjectName: rawSubjectName, // Use raw subject name like PowerShell\n }\n } catch (error: unknown) {\n throw new Error(\n `Failed to extract certificate info: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n}\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 const createSignedProperties = (\n certificateDigest: string,\n signingTime: string,\n issuerName: string,\n serialNumber: string,\n): SignedPropertiesObject => {\n return {\n SignedProperties: [\n {\n Id: 'id-xades-signed-props',\n SignedSignatureProperties: [\n {\n SigningTime: [{ _: signingTime }],\n SigningCertificate: [\n {\n Cert: [\n {\n CertDigest: [\n {\n DigestMethod: [\n {\n _: '',\n Algorithm:\n 'http://www.w3.org/2001/04/xmlenc#sha256',\n },\n ],\n DigestValue: [{ _: certificateDigest }],\n },\n ],\n IssuerSerial: [\n {\n X509IssuerName: [{ _: issuerName }],\n X509SerialNumber: [{ _: serialNumber }],\n },\n ],\n },\n ],\n },\n ],\n },\n ],\n },\n ],\n }\n}\n\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 const calculateSignedPropertiesDigest = (\n signedProperties: SignedPropertiesObject,\n useTargetWrapper: boolean = true, // Changed to true - validator calculates digest from embedded structure with Target wrapper\n): string => {\n let digestObj: unknown\n if (useTargetWrapper) {\n digestObj = {\n Target: 'signature',\n SignedProperties: signedProperties.SignedProperties,\n }\n } else {\n digestObj = signedProperties.SignedProperties\n }\n\n // FIXED: Don't sort object keys - use exact structure as embedded\n // The validator calculates digest from the exact embedded structure\n const signedPropertiesString = JSON.stringify(digestObj)\n\n // Apply the same regex-based minification as the document transformation\n const minifiedSignedProperties = signedPropertiesString.replace(\n /(\"(?:\\\\.|[^\"\\\\])*\")|\\s+/g,\n (match, quotedString) => {\n if (quotedString) {\n return quotedString // Keep string content exactly as-is\n } else {\n return '' // Remove all other whitespace\n }\n },\n )\n\n const hash = crypto.createHash('sha256')\n hash.update(minifiedSignedProperties, 'utf8')\n return hash.digest('base64')\n}\n\n/**\n * Step 3: Create SignedInfo and calculate signature\n * Enhanced with better structure and signature generation\n */\nexport const createSignedInfoAndSign = (\n docDigest: string,\n propsDigest: string,\n privateKeyPem: string,\n): { signedInfo: SignedInfoObject; signatureValue: string } => {\n // Create SignedInfo structure following specification exactly\n const signedInfo: SignedInfoObject = {\n CanonicalizationMethod: [\n {\n _: '',\n Algorithm: 'http://www.w3.org/2006/12/xml-c14n11',\n },\n ],\n SignatureMethod: [\n {\n _: '',\n Algorithm: 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256',\n },\n ],\n Reference: [\n {\n Id: 'id-doc-signed-data',\n Type: '',\n URI: '',\n DigestMethod: [\n {\n _: '',\n Algorithm: 'http://www.w3.org/2001/04/xmlenc#sha256',\n },\n ],\n DigestValue: [{ _: docDigest }],\n },\n {\n Id: 'id-xades-signed-props',\n Type: 'http://uri.etsi.org/01903/v1.3.2#SignedProperties',\n URI: '#id-xades-signed-props',\n DigestMethod: [\n {\n _: '',\n Algorithm: 'http://www.w3.org/2001/04/xmlenc#sha256',\n },\n ],\n DigestValue: [{ _: propsDigest }],\n },\n ],\n }\n\n // Serialize the SignedInfo exactly as it will be embedded (no reordering)\n const signedInfoRaw = JSON.stringify(signedInfo)\n\n try {\n const signer = crypto.createSign('RSA-SHA256')\n signer.update(signedInfoRaw, 'utf8')\n const signatureValue = signer.sign(privateKeyPem, 'base64')\n\n // Reuse the original object so ordering is preserved\n return { signedInfo, signatureValue }\n } catch (error) {\n throw new Error(\n `Signature generation failed: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n}\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 const signDocumentString = (\n documentString: string,\n privateKeyPem: string,\n): string => {\n // Create signer with RSA-SHA256 (matches PowerShell RSAPKCS1SignatureFormatter)\n const signer = crypto.createSign('RSA-SHA256')\n signer.update(documentString, 'utf8')\n return signer.sign(privateKeyPem, 'base64')\n}\n\n/**\n * Complete document generation with signatures\n * Follows the complete MyInvois JSON signature creation process (Steps 1-7)\n */\nexport const generateCompleteDocument = (\n invoices: AllDocumentsV1_1[],\n signingCredentials: SigningCredentials,\n): CompleteInvoice => {\n try {\n // Step 1: Generate clean document (done in calculateDocumentDigest)\n // Step 2: Calculate document digest\n const docDigest = calculateDocumentDigest(invoices)\n\n // Get the minified, cleaned JSON string for signing\n const documentString = transformDocumentForHashing(invoices)\n\n // Step 3: Sign the minified document string (not the digest)\n const docSignature = signDocumentString(\n documentString,\n signingCredentials.privateKeyPem,\n )\n\n // Generate signing time in proper ISO format matching PowerShell exactly\n // PowerShell: Get-Date -Format \"yyyy-MM-ddTHH:mm:ssZ\"\n const now = new Date()\n const signingTime =\n now.getFullYear() +\n '-' +\n String(now.getMonth() + 1).padStart(2, '0') +\n '-' +\n String(now.getDate()).padStart(2, '0') +\n 'T' +\n String(now.getHours()).padStart(2, '0') +\n ':' +\n String(now.getMinutes()).padStart(2, '0') +\n ':' +\n String(now.getSeconds()).padStart(2, '0') +\n 'Z'\n\n // Extract certificate information (enhanced)\n const certInfo = extractCertificateInfo(signingCredentials.certificatePem)\n\n // Step 4: Calculate certificate digest\n const certificateDigest = calculateCertificateDigest(\n signingCredentials.certificatePem,\n )\n\n // Step 5: Create SignedProperties using extracted cert info\n const signedProperties = createSignedProperties(\n certificateDigest,\n signingTime,\n certInfo.issuerName,\n certInfo.serialNumber,\n )\n\n // Step 6: Calculate SignedProperties digest using the dedicated function\n const propsDigest = calculateSignedPropertiesDigest(signedProperties)\n\n // Create simple SignedInfo structure (matching PowerShell approach)\n const signedInfo: SignedInfoObject = {\n CanonicalizationMethod: [\n {\n _: '',\n Algorithm: 'http://www.w3.org/2006/12/xml-c14n11',\n },\n ],\n SignatureMethod: [\n {\n _: '',\n Algorithm: 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256',\n },\n ],\n Reference: [\n {\n Id: 'id-doc-signed-data',\n Type: '',\n URI: '',\n DigestMethod: [\n {\n _: '',\n Algorithm: 'http://www.w3.org/2001/04/xmlenc#sha256',\n },\n ],\n DigestValue: [{ _: docDigest }],\n },\n {\n Id: 'id-xades-signed-props',\n Type: 'http://uri.etsi.org/01903/v1.3.2#SignedProperties',\n URI: '#id-xades-signed-props',\n DigestMethod: [\n {\n _: '',\n Algorithm: 'http://www.w3.org/2001/04/xmlenc#sha256',\n },\n ],\n DigestValue: [{ _: propsDigest }],\n },\n ],\n }\n\n // Extract certificate content using raw data (like PowerShell $cert.RawData)\n const cert = new X509Certificate(signingCredentials.certificatePem)\n const certificate = cert.raw.toString('base64')\n\n // Step 7: Create final signed document\n const signedInvoices = invoices.map(invoice => {\n const cleanInvoice = generateCleanInvoiceObject(invoice)\n\n return {\n ...cleanInvoice,\n\n // Add UBLExtensions with complete signature structure\n UBLExtensions: [\n {\n UBLExtension: [\n {\n ExtensionURI: [\n {\n _: 'urn:oasis:names:specification:ubl:dsig:enveloped:xades',\n },\n ],\n ExtensionContent: [\n {\n UBLDocumentSignatures: [\n {\n SignatureInformation: [\n {\n ID: [\n {\n _: 'urn:oasis:names:specification:ubl:signature:1',\n },\n ],\n ReferencedSignatureID: [\n {\n _: 'urn:oasis:names:specification:ubl:signature:Invoice',\n },\n ],\n Signature: [\n {\n Id: 'signature',\n Object: [\n {\n QualifyingProperties: [\n {\n Target: 'signature',\n SignedProperties:\n signedProperties.SignedProperties,\n },\n ],\n },\n ],\n KeyInfo: [\n {\n X509Data: [\n {\n X509Certificate: [{ _: certificate }],\n X509SubjectName: [\n { _: certInfo.subjectName },\n ],\n X509IssuerSerial: [\n {\n X509IssuerName: [\n {\n _: certInfo.issuerName,\n },\n ],\n X509SerialNumber: [\n {\n _: certInfo.serialNumber,\n },\n ],\n },\n ],\n },\n ],\n },\n ],\n SignatureValue: [{ _: docSignature }],\n SignedInfo: [signedInfo],\n },\n ],\n },\n ],\n },\n ],\n },\n ],\n },\n ],\n },\n ],\n\n // Add simple Signature reference\n Signature: [\n {\n ID: [\n {\n _: 'urn:oasis:names:specification:ubl:signature:Invoice',\n },\n ],\n SignatureMethod: [\n {\n _: 'urn:oasis:names:specification:ubl:dsig:enveloped:xades',\n },\n ],\n },\n ],\n }\n })\n\n return {\n _D: 'urn:oasis:names:specification:ubl:schema:xsd:Invoice-2',\n _A: 'urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2',\n _B: 'urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2',\n Invoice: signedInvoices,\n }\n } catch (error) {\n throw new Error(\n `Document generation failed: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n}\n\n/**\n * Creates a line item with percentage-based taxation (e.g., SST, GST)\n */\nexport 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}): InvoiceLineItem => {\n const quantity = params.quantity || 1\n const totalTaxableAmount =\n params.totalTaxableAmountPerLine || params.unitPrice * quantity\n const taxAmount = (totalTaxableAmount * params.taxRate) / 100\n\n return {\n itemClassificationCode: params.itemClassificationCode,\n itemDescription: params.itemDescription,\n unitPrice: params.unitPrice,\n taxType: params.taxType,\n taxRate: params.taxRate,\n taxAmount: Math.round(taxAmount * 100) / 100, // Round to 2 decimal places\n totalTaxableAmountPerLine: totalTaxableAmount,\n totalAmountPerLine: totalTaxableAmount + taxAmount,\n }\n}\n\n/**\n * Creates a line item with fixed rate taxation (e.g., Tourism Tax)\n */\nexport 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}): InvoiceLineItem => {\n const quantity = params.quantity || 1\n const totalTaxableAmount =\n params.totalTaxableAmountPerLine || params.unitPrice * quantity\n const taxAmount = params.taxPerUnitAmount * params.baseUnitMeasure\n\n return {\n itemClassificationCode: params.itemClassificationCode,\n itemDescription: params.itemDescription,\n unitPrice: params.unitPrice,\n taxType: params.taxType,\n taxPerUnitAmount: params.taxPerUnitAmount,\n baseUnitMeasure: params.baseUnitMeasure,\n baseUnitMeasureCode: params.baseUnitMeasureCode,\n taxAmount: Math.round(taxAmount * 100) / 100, // Round to 2 decimal places\n totalTaxableAmountPerLine: totalTaxableAmount,\n totalAmountPerLine: totalTaxableAmount + taxAmount,\n }\n}\n\n/**\n * Calculates invoice totals from line items\n */\nexport const calculateInvoiceTotals = (\n lineItems: InvoiceLineItem[],\n): {\n legalMonetaryTotal: {\n taxExclusiveAmount: number\n taxInclusiveAmount: number\n payableAmount: number\n }\n taxTotal: {\n taxAmount: number\n }\n} => {\n const taxExclusiveAmount = lineItems.reduce(\n (sum, item) => sum + item.totalTaxableAmountPerLine,\n 0,\n )\n const totalTaxAmount = lineItems.reduce(\n (sum, item) => sum + item.taxAmount,\n 0,\n )\n const taxInclusiveAmount = taxExclusiveAmount + totalTaxAmount\n\n return {\n legalMonetaryTotal: {\n taxExclusiveAmount: Math.round(taxExclusiveAmount * 100) / 100,\n taxInclusiveAmount: Math.round(taxInclusiveAmount * 100) / 100,\n payableAmount: Math.round(taxInclusiveAmount * 100) / 100,\n },\n taxTotal: {\n taxAmount: Math.round(totalTaxAmount * 100) / 100,\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAyBA,MAAa,iBAAiB,CAACA,SAAmC;AAChE,QACE,KAAK,+BAAkC,KAAK;AAE/C;;;;AAKD,MAAa,kBAAkB,CAACA,SAAmC;AACjE,QAAO,KAAK,uBAA0B,eAAe,KAAK;AAC3D;;;;AAKD,MAAa,6BAA6B,CAACA,SAAkC;AAC3E,KAAI,eAAe,KAAK,CACtB,QAAO,KAAK,mBAAoB,KAAK;UAC5B,gBAAgB,KAAK,CAC9B,QAAQ,KAAK,4BAA4B,KAAK,UAAY;AAE5D,QAAO;AACR;;;;AAKD,MAAM,eAAe,CAACC,QAA6C;AACjE,KAAI,sBAAsB,IAAK,QAAO,IAAI;AAC1C,KAAI,yBAAyB,IAAK,QAAO,IAAI;AAC7C,KAAI,wBAAwB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AAG;GAC3D,oBAAoB,KAAK,MAAM,qBAAqB,IAAI,GAAG;GAC3D,eAAe,KAAK,MAAM,qBAAqB,IAAI,GAAG;EACvD;EACD,UAAU,EACR,WAAW,KAAK,MAAM,iBAAiB,IAAI,GAAG,IAC/C;CACF;AACF"}
|
|
@@ -3,13 +3,20 @@ async function getDocument(context, documentUid) {
|
|
|
3
3
|
const { fetch } = context;
|
|
4
4
|
const response = await fetch(`/api/v1.0/documents/${documentUid}/raw`);
|
|
5
5
|
const data = await response.json();
|
|
6
|
-
return
|
|
6
|
+
return {
|
|
7
|
+
...data,
|
|
8
|
+
longId: data.longID ?? data.longId
|
|
9
|
+
};
|
|
7
10
|
}
|
|
8
11
|
async function getDocumentDetails(context, documentUid) {
|
|
9
12
|
const { fetch } = context;
|
|
10
13
|
const response = await fetch(`/api/v1.0/documents/${documentUid}/details`);
|
|
11
14
|
const data = await response.json();
|
|
12
|
-
|
|
15
|
+
const resp = {
|
|
16
|
+
...data,
|
|
17
|
+
longId: data.longID ?? data.longId
|
|
18
|
+
};
|
|
19
|
+
return resp;
|
|
13
20
|
}
|
|
14
21
|
async function searchDocuments(context, params) {
|
|
15
22
|
const { fetch } = context;
|
|
@@ -28,7 +35,10 @@ async function searchDocuments(context, params) {
|
|
|
28
35
|
if (searchQuery) queryParams.set("searchQuery", searchQuery);
|
|
29
36
|
const response = await fetch(`/api/v1.0/documents/search?${queryParams.toString()}`);
|
|
30
37
|
const data = await response.json();
|
|
31
|
-
return data
|
|
38
|
+
return data.map((doc) => ({
|
|
39
|
+
...doc,
|
|
40
|
+
longId: doc.longID ?? doc.longId
|
|
41
|
+
}));
|
|
32
42
|
}
|
|
33
43
|
|
|
34
44
|
//#endregion
|
|
@@ -4,13 +4,20 @@ async function getDocument(context, documentUid) {
|
|
|
4
4
|
const { fetch } = context;
|
|
5
5
|
const response = await fetch(`/api/v1.0/documents/${documentUid}/raw`);
|
|
6
6
|
const data = await response.json();
|
|
7
|
-
return
|
|
7
|
+
return {
|
|
8
|
+
...data,
|
|
9
|
+
longId: data.longID ?? data.longId
|
|
10
|
+
};
|
|
8
11
|
}
|
|
9
12
|
async function getDocumentDetails(context, documentUid) {
|
|
10
13
|
const { fetch } = context;
|
|
11
14
|
const response = await fetch(`/api/v1.0/documents/${documentUid}/details`);
|
|
12
15
|
const data = await response.json();
|
|
13
|
-
|
|
16
|
+
const resp = {
|
|
17
|
+
...data,
|
|
18
|
+
longId: data.longID ?? data.longId
|
|
19
|
+
};
|
|
20
|
+
return resp;
|
|
14
21
|
}
|
|
15
22
|
async function searchDocuments(context, params) {
|
|
16
23
|
const { fetch } = context;
|
|
@@ -29,7 +36,10 @@ async function searchDocuments(context, params) {
|
|
|
29
36
|
if (searchQuery) queryParams.set("searchQuery", searchQuery);
|
|
30
37
|
const response = await fetch(`/api/v1.0/documents/search?${queryParams.toString()}`);
|
|
31
38
|
const data = await response.json();
|
|
32
|
-
return data
|
|
39
|
+
return data.map((doc) => ({
|
|
40
|
+
...doc,
|
|
41
|
+
longId: doc.longID ?? doc.longId
|
|
42
|
+
}));
|
|
33
43
|
}
|
|
34
44
|
|
|
35
45
|
//#endregion
|
|
@@ -51,4 +61,4 @@ Object.defineProperty(exports, 'searchDocuments', {
|
|
|
51
61
|
return searchDocuments;
|
|
52
62
|
}
|
|
53
63
|
});
|
|
54
|
-
//# sourceMappingURL=documentManagement-
|
|
64
|
+
//# sourceMappingURL=documentManagement-CyPwiyP4.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documentManagement-CyPwiyP4.cjs","names":["context: DocumentContext","documentUid: string","params: {\n uuid?: string\n submissionDateFrom: string\n submissionDateTo?: string\n pageSize?: number\n pageNo?: number\n issueDateFrom?: string\n issueDateTo?: string\n invoiceDirection?: 'Sent' | 'Received'\n status?: DocumentStatus\n documentType?: EInvoiceTypeCode\n searchQuery?: string\n }","doc: DocumentSummary & { longID: string }"],"sources":["../src/api/documentManagement.ts"],"sourcesContent":["import type {\n DocumentSummary,\n DocumentStatus,\n EInvoiceTypeCode,\n DocumentValidationResult,\n DocumentValidationStepResult,\n Fetch,\n} from '../types'\n\ninterface DocumentContext {\n fetch: Fetch\n}\n\nexport async function getDocument(\n context: DocumentContext,\n documentUid: string,\n): Promise<DocumentSummary & { document: string }> {\n const { fetch } = context\n\n const response = await fetch(`/api/v1.0/documents/${documentUid}/raw`)\n const data = await response.json()\n\n return { ...data, longId: data.longID ?? data.longId } as DocumentSummary & {\n document: string\n }\n}\n\nexport async function getDocumentDetails(\n context: DocumentContext,\n documentUid: string,\n): Promise<\n DocumentSummary & {\n validationResults: {\n status: DocumentValidationResult\n validationSteps: DocumentValidationStepResult[]\n }\n }\n> {\n const { fetch } = context\n\n const response = await fetch(`/api/v1.0/documents/${documentUid}/details`)\n const data = await response.json()\n const resp = {\n ...data,\n longId: data.longID ?? data.longId,\n } as DocumentSummary & {\n validationResults: {\n status: DocumentValidationResult\n validationSteps: DocumentValidationStepResult[]\n }\n }\n\n return resp\n}\n\nexport async function searchDocuments(\n context: DocumentContext,\n params: {\n uuid?: string\n submissionDateFrom: string\n submissionDateTo?: string\n pageSize?: number\n pageNo?: number\n issueDateFrom?: string\n issueDateTo?: string\n invoiceDirection?: 'Sent' | 'Received'\n status?: DocumentStatus\n documentType?: EInvoiceTypeCode\n searchQuery?: string\n },\n): Promise<DocumentSummary[]> {\n const { fetch } = context\n const {\n uuid,\n submissionDateFrom,\n submissionDateTo,\n pageSize,\n pageNo,\n issueDateFrom,\n issueDateTo,\n invoiceDirection,\n status,\n documentType,\n searchQuery,\n } = params\n\n const queryParams = new URLSearchParams()\n\n if (uuid) queryParams.set('uuid', uuid)\n if (submissionDateFrom)\n queryParams.set('submissionDateFrom', submissionDateFrom)\n if (submissionDateTo) queryParams.set('submissionDateTo', submissionDateTo)\n if (pageSize) queryParams.set('pageSize', pageSize.toString())\n if (pageNo) queryParams.set('pageNo', pageNo.toString())\n if (issueDateFrom) queryParams.set('issueDateFrom', issueDateFrom)\n if (issueDateTo) queryParams.set('issueDateTo', issueDateTo)\n if (invoiceDirection) queryParams.set('invoiceDirection', invoiceDirection)\n if (status) queryParams.set('status', status)\n if (documentType) queryParams.set('documentType', documentType)\n if (searchQuery) queryParams.set('searchQuery', searchQuery)\n\n const response = await fetch(\n `/api/v1.0/documents/search?${queryParams.toString()}`,\n )\n\n const data = await response.json()\n\n return data.map((doc: DocumentSummary & { longID: string }) => ({\n ...doc,\n longId: doc.longID ?? doc.longId,\n })) as DocumentSummary[]\n}\n"],"mappings":";;AAaA,eAAsB,YACpBA,SACAC,aACiD;CACjD,MAAM,EAAE,OAAO,GAAG;CAElB,MAAM,WAAW,MAAM,OAAO,sBAAsB,YAAY,MAAM;CACtE,MAAM,OAAO,MAAM,SAAS,MAAM;AAElC,QAAO;EAAE,GAAG;EAAM,QAAQ,KAAK,UAAU,KAAK;CAAQ;AAGvD;AAED,eAAsB,mBACpBD,SACAC,aAQA;CACA,MAAM,EAAE,OAAO,GAAG;CAElB,MAAM,WAAW,MAAM,OAAO,sBAAsB,YAAY,UAAU;CAC1E,MAAM,OAAO,MAAM,SAAS,MAAM;CAClC,MAAM,OAAO;EACX,GAAG;EACH,QAAQ,KAAK,UAAU,KAAK;CAC7B;AAOD,QAAO;AACR;AAED,eAAsB,gBACpBD,SACAE,QAa4B;CAC5B,MAAM,EAAE,OAAO,GAAG;CAClB,MAAM,EACJ,MACA,oBACA,kBACA,UACA,QACA,eACA,aACA,kBACA,QACA,cACA,aACD,GAAG;CAEJ,MAAM,cAAc,IAAI;AAExB,KAAI,KAAM,aAAY,IAAI,QAAQ,KAAK;AACvC,KAAI,mBACF,aAAY,IAAI,sBAAsB,mBAAmB;AAC3D,KAAI,iBAAkB,aAAY,IAAI,oBAAoB,iBAAiB;AAC3E,KAAI,SAAU,aAAY,IAAI,YAAY,SAAS,UAAU,CAAC;AAC9D,KAAI,OAAQ,aAAY,IAAI,UAAU,OAAO,UAAU,CAAC;AACxD,KAAI,cAAe,aAAY,IAAI,iBAAiB,cAAc;AAClE,KAAI,YAAa,aAAY,IAAI,eAAe,YAAY;AAC5D,KAAI,iBAAkB,aAAY,IAAI,oBAAoB,iBAAiB;AAC3E,KAAI,OAAQ,aAAY,IAAI,UAAU,OAAO;AAC7C,KAAI,aAAc,aAAY,IAAI,gBAAgB,aAAa;AAC/D,KAAI,YAAa,aAAY,IAAI,eAAe,YAAY;CAE5D,MAAM,WAAW,MAAM,OACpB,6BAA6B,YAAY,UAAU,CAAC,EACtD;CAED,MAAM,OAAO,MAAM,SAAS,MAAM;AAElC,QAAO,KAAK,IAAI,CAACC,SAA+C;EAC9D,GAAG;EACH,QAAQ,IAAI,UAAU,IAAI;CAC3B,GAAE;AACJ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_document = require('./document-
|
|
1
|
+
const require_document = require('./document-DWsGewNs.cjs');
|
|
2
2
|
|
|
3
3
|
//#region src/api/documentSubmission.ts
|
|
4
4
|
async function submitDocument(context, documents) {
|
|
@@ -147,4 +147,4 @@ Object.defineProperty(exports, 'submitDocument', {
|
|
|
147
147
|
return submitDocument;
|
|
148
148
|
}
|
|
149
149
|
});
|
|
150
|
-
//# sourceMappingURL=documentSubmission-
|
|
150
|
+
//# sourceMappingURL=documentSubmission-D96QqHJ-.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentSubmission-BE1En5JO.cjs","names":["context: SubmissionContext","documents: AllDocumentsV1_1[]","context: Pick<SubmissionContext, 'fetch' | 'debug'>","submissionUid: string","pollInterval: number","maxRetries: number","documentUid: string","status: 'rejected' | 'cancelled'","reason: string"],"sources":["../src/api/documentSubmission.ts"],"sourcesContent":["import type {\n AllDocumentsV1_1,\n SubmissionResponse,\n SigningCredentials,\n SubmissionStatus,\n DocumentSummary,\n Fetch,\n StandardError,\n GetSubmissionResponse,\n} from '../types'\nimport { generateCompleteDocument } from '../utils/document'\n\ninterface SubmissionContext {\n fetch: Fetch\n debug: boolean\n signingCredentials: SigningCredentials\n}\n\nexport async function submitDocument(\n context: SubmissionContext,\n documents: AllDocumentsV1_1[],\n): Promise<{\n data: SubmissionResponse\n status: number\n}> {\n const { fetch, debug, signingCredentials } = context\n\n // 🔒 Hard enforcement of platform submission limits\n if (documents.length > 100) {\n throw new Error(\n 'Submission rejected: Cannot submit more than 100 documents at once',\n )\n }\n\n if (debug) {\n console.log(`📦 Preparing to submit ${documents.length} document(s)...`)\n }\n\n // For batch submission, each document must be signed and encoded separately\n // Build the submission payload according to MyInvois API format\n const crypto = await import('crypto')\n\n const submissionPayload = {\n documents: await Promise.all(\n documents.map(async doc => {\n // 1️⃣ Sign the single document (generateCompleteDocument expects an array)\n const signedDocument = generateCompleteDocument(\n [doc],\n signingCredentials,\n )\n\n // 2️⃣ Serialize\n const docJson = JSON.stringify(signedDocument)\n\n // 3️⃣ Hash\n const docHash = crypto\n .createHash('sha256')\n .update(docJson, 'utf8')\n .digest('hex')\n\n // 4️⃣ Base64 encode\n const docBase64 = Buffer.from(docJson, 'utf8').toString('base64')\n\n // 🚨 Enforce 300 KB per-document limit\n const rawSize = Buffer.byteLength(docBase64, 'base64')\n if (rawSize > 300 * 1024) {\n throw new Error(\n `Submission rejected: Document ${doc.eInvoiceCodeOrNumber} is ${rawSize} bytes – exceeds 300KB limit`,\n )\n }\n\n if (debug) {\n console.log('—'.repeat(60))\n console.log(`📄 Prepared document: ${doc.eInvoiceCodeOrNumber}`)\n console.log(` • JSON size : ${docJson.length} bytes`)\n console.log(` • Base64 size: ${docBase64.length} bytes`)\n }\n\n return {\n format: 'JSON',\n document: docBase64,\n documentHash: docHash,\n codeNumber: doc.eInvoiceCodeOrNumber,\n }\n }),\n ),\n }\n\n const payloadSize = Buffer.byteLength(JSON.stringify(submissionPayload))\n\n if (payloadSize > 5 * 1024 * 1024) {\n throw new Error(\n `Submission rejected: Payload is ${payloadSize} bytes – exceeds 5MB limit`,\n )\n }\n\n if (debug) {\n console.log('🚀 Submission payload structure:')\n console.log('- Format: JSON')\n console.log('- Documents count:', submissionPayload.documents.length)\n console.log('- Total payload size:', payloadSize, 'bytes')\n }\n\n // Submit to MyInvois API with proper headers\n const response = await fetch('/api/v1.0/documentsubmissions', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(submissionPayload),\n })\n\n const responseData = (await response.json()) as SubmissionResponse\n\n if (debug) {\n console.log(`📡 API Response status: ${response.status}`)\n\n if (responseData.rejectedDocuments?.length > 0) {\n responseData.rejectedDocuments.forEach((doc, index) => {\n console.log(` Document ${index + 1}:`, doc.invoiceCodeNumber)\n if (doc.error) {\n console.log(` Error:`, doc.error.message)\n if (doc.error.details) {\n doc.error.details.forEach((detail, detailIndex) => {\n console.log(` Detail ${detailIndex + 1}:`, detail.message)\n })\n }\n }\n })\n }\n }\n\n const data = responseData as SubmissionResponse\n\n if (debug) {\n if (response.status !== 202) {\n console.error('❌ Submission failed with status:', response.status)\n console.error('❌ Response data:', JSON.stringify(data, null, 2))\n } else {\n console.log('✅ Submission successful!')\n console.log(`📋 Submission UID: ${data.submissionUid}`)\n console.log(\n `✅ Accepted documents: ${data.acceptedDocuments?.length || 0}`,\n )\n console.log(\n `❌ Rejected documents: ${data.rejectedDocuments?.length || 0}`,\n )\n }\n }\n\n return {\n data,\n status: response.status,\n }\n}\n\nexport async function getSubmissionStatus(\n context: Pick<SubmissionContext, 'fetch' | 'debug'>,\n submissionUid: string,\n pollInterval: number = 1000,\n maxRetries: number = 10,\n): Promise<{\n status: SubmissionStatus\n documentSummary?: DocumentSummary[]\n error?: {\n code: string\n message: string | null\n target: string\n details: {\n code: string\n message: string\n target: string\n }[]\n }\n}> {\n const { fetch, debug } = context\n\n try {\n const response = await fetch(\n `/api/v1.0/documentsubmissions/${submissionUid}`,\n )\n\n const data = (await response.json()) as GetSubmissionResponse\n\n if (debug) {\n console.log('Submission:', data)\n if (data.error) {\n console.log('Submission error details:', data.error.details)\n }\n }\n\n // If we have a successful response and status is completed, return success\n if (data.overallStatus === 'Valid') {\n return {\n status: data.overallStatus,\n documentSummary: data.documentSummary,\n }\n }\n if (data.overallStatus === 'Invalid') {\n return {\n status: 'Invalid',\n documentSummary: data.documentSummary,\n }\n }\n\n // If we have retries left, continue polling for any non-completed status or errors\n if (maxRetries > 0) {\n await new Promise(resolve => setTimeout(resolve, pollInterval))\n return await getSubmissionStatus(\n context,\n submissionUid,\n pollInterval,\n maxRetries - 1,\n )\n }\n\n return {\n status: data.overallStatus || 'TimedOut',\n documentSummary: data.documentSummary,\n error:\n data.error ??\n ({\n code: 'Timeout',\n message: 'Submission timed out',\n target: 'submission',\n details: [],\n } satisfies StandardError),\n }\n } catch (error) {\n // Handle any request errors by retrying if we have retries left\n if (maxRetries > 0) {\n if (debug) {\n console.log('Request error, retrying...', error)\n }\n await new Promise(resolve => setTimeout(resolve, pollInterval))\n return await getSubmissionStatus(\n context,\n submissionUid,\n pollInterval,\n maxRetries - 1,\n )\n }\n\n // No retries left - return timeout\n return {\n status: 'TimedOut',\n documentSummary: [],\n error: {\n code: 'Timeout',\n message: 'Submission timed out after request errors',\n target: 'submission',\n details: [],\n },\n }\n }\n}\n\nexport async function performDocumentAction(\n documentUid: string,\n status: 'rejected' | 'cancelled',\n reason: string,\n): Promise<{\n uuid: string\n status: string\n error: StandardError\n}> {\n const response = await fetch(\n `/api/v1.0/documents/state/${documentUid}/state`,\n {\n method: 'POST',\n body: JSON.stringify({\n status,\n reason,\n }),\n },\n )\n\n const data = (await response.json()) as {\n uuid: string\n status: string\n error: StandardError\n }\n\n return data\n}\n"],"mappings":";;;AAkBA,eAAsB,eACpBA,SACAC,WAIC;CACD,MAAM,EAAE,gBAAO,OAAO,oBAAoB,GAAG;AAG7C,KAAI,UAAU,SAAS,IACrB,OAAM,IAAI,MACR;AAIJ,KAAI,MACF,SAAQ,KAAK,yBAAyB,UAAU,OAAO,iBAAiB;CAK1E,MAAM,SAAS,MAAM,OAAO;CAE5B,MAAM,oBAAoB,EACxB,WAAW,MAAM,QAAQ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B,KAAK;EACvB;AAIH,MAAI,aAAa,GAAG;AAClB,SAAM,IAAI,QAAQ,aAAW,WAAW,SAAS,aAAa;AAC9D,UAAO,MAAM,oBACX,SACA,eACA,cACA,aAAa,EACd;EACF;AAED,SAAO;GACL,QAAQ,KAAK,iBAAiB;GAC9B,iBAAiB,KAAK;GACtB,OACE,KAAK,SACJ;IACC,MAAM;IACN,SAAS;IACT,QAAQ;IACR,SAAS,CAAE;GACZ;EACJ;CACF,SAAQ,OAAO;AAEd,MAAI,aAAa,GAAG;AAClB,OAAI,MACF,SAAQ,IAAI,8BAA8B,MAAM;AAElD,SAAM,IAAI,QAAQ,aAAW,WAAW,SAAS,aAAa;AAC9D,UAAO,MAAM,oBACX,SACA,eACA,cACA,aAAa,EACd;EACF;AAGD,SAAO;GACL,QAAQ;GACR,iBAAiB,CAAE;GACnB,OAAO;IACL,MAAM;IACN,SAAS;IACT,QAAQ;IACR,SAAS,CAAE;GACZ;EACF;CACF;AACF;AAED,eAAsB,sBACpBC,aACAC,QACAC,QAKC;CACD,MAAM,WAAW,MAAM,OACpB,4BAA4B,YAAY,SACzC;EACE,QAAQ;EACR,MAAM,KAAK,UAAU;GACnB;GACA;EACD,EAAC;CACH,EACF;CAED,MAAM,OAAQ,MAAM,SAAS,MAAM;AAMnC,QAAO;AACR"}
|
|
1
|
+
{"version":3,"file":"documentSubmission-D96QqHJ-.cjs","names":["context: SubmissionContext","documents: AllDocumentsV1_1[]","context: Pick<SubmissionContext, 'fetch' | 'debug'>","submissionUid: string","pollInterval: number","maxRetries: number","documentUid: string","status: 'rejected' | 'cancelled'","reason: string"],"sources":["../src/api/documentSubmission.ts"],"sourcesContent":["import type {\n AllDocumentsV1_1,\n SubmissionResponse,\n SigningCredentials,\n SubmissionStatus,\n DocumentSummary,\n Fetch,\n StandardError,\n GetSubmissionResponse,\n} from '../types'\nimport { generateCompleteDocument } from '../utils/document'\n\ninterface SubmissionContext {\n fetch: Fetch\n debug: boolean\n signingCredentials: SigningCredentials\n}\n\nexport async function submitDocument(\n context: SubmissionContext,\n documents: AllDocumentsV1_1[],\n): Promise<{\n data: SubmissionResponse\n status: number\n}> {\n const { fetch, debug, signingCredentials } = context\n\n // 🔒 Hard enforcement of platform submission limits\n if (documents.length > 100) {\n throw new Error(\n 'Submission rejected: Cannot submit more than 100 documents at once',\n )\n }\n\n if (debug) {\n console.log(`📦 Preparing to submit ${documents.length} document(s)...`)\n }\n\n // For batch submission, each document must be signed and encoded separately\n // Build the submission payload according to MyInvois API format\n const crypto = await import('crypto')\n\n const submissionPayload = {\n documents: await Promise.all(\n documents.map(async doc => {\n // 1️⃣ Sign the single document (generateCompleteDocument expects an array)\n const signedDocument = generateCompleteDocument(\n [doc],\n signingCredentials,\n )\n\n // 2️⃣ Serialize\n const docJson = JSON.stringify(signedDocument)\n\n // 3️⃣ Hash\n const docHash = crypto\n .createHash('sha256')\n .update(docJson, 'utf8')\n .digest('hex')\n\n // 4️⃣ Base64 encode\n const docBase64 = Buffer.from(docJson, 'utf8').toString('base64')\n\n // 🚨 Enforce 300 KB per-document limit\n const rawSize = Buffer.byteLength(docBase64, 'base64')\n if (rawSize > 300 * 1024) {\n throw new Error(\n `Submission rejected: Document ${doc.eInvoiceCodeOrNumber} is ${rawSize} bytes – exceeds 300KB limit`,\n )\n }\n\n if (debug) {\n console.log('—'.repeat(60))\n console.log(`📄 Prepared document: ${doc.eInvoiceCodeOrNumber}`)\n console.log(` • JSON size : ${docJson.length} bytes`)\n console.log(` • Base64 size: ${docBase64.length} bytes`)\n }\n\n return {\n format: 'JSON',\n document: docBase64,\n documentHash: docHash,\n codeNumber: doc.eInvoiceCodeOrNumber,\n }\n }),\n ),\n }\n\n const payloadSize = Buffer.byteLength(JSON.stringify(submissionPayload))\n\n if (payloadSize > 5 * 1024 * 1024) {\n throw new Error(\n `Submission rejected: Payload is ${payloadSize} bytes – exceeds 5MB limit`,\n )\n }\n\n if (debug) {\n console.log('🚀 Submission payload structure:')\n console.log('- Format: JSON')\n console.log('- Documents count:', submissionPayload.documents.length)\n console.log('- Total payload size:', payloadSize, 'bytes')\n }\n\n // Submit to MyInvois API with proper headers\n const response = await fetch('/api/v1.0/documentsubmissions', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(submissionPayload),\n })\n\n const responseData = (await response.json()) as SubmissionResponse\n\n if (debug) {\n console.log(`📡 API Response status: ${response.status}`)\n\n if (responseData.rejectedDocuments?.length > 0) {\n responseData.rejectedDocuments.forEach((doc, index) => {\n console.log(` Document ${index + 1}:`, doc.invoiceCodeNumber)\n if (doc.error) {\n console.log(` Error:`, doc.error.message)\n if (doc.error.details) {\n doc.error.details.forEach((detail, detailIndex) => {\n console.log(` Detail ${detailIndex + 1}:`, detail.message)\n })\n }\n }\n })\n }\n }\n\n const data = responseData as SubmissionResponse\n\n if (debug) {\n if (response.status !== 202) {\n console.error('❌ Submission failed with status:', response.status)\n console.error('❌ Response data:', JSON.stringify(data, null, 2))\n } else {\n console.log('✅ Submission successful!')\n console.log(`📋 Submission UID: ${data.submissionUid}`)\n console.log(\n `✅ Accepted documents: ${data.acceptedDocuments?.length || 0}`,\n )\n console.log(\n `❌ Rejected documents: ${data.rejectedDocuments?.length || 0}`,\n )\n }\n }\n\n return {\n data,\n status: response.status,\n }\n}\n\nexport async function getSubmissionStatus(\n context: Pick<SubmissionContext, 'fetch' | 'debug'>,\n submissionUid: string,\n pollInterval: number = 1000,\n maxRetries: number = 10,\n): Promise<{\n status: SubmissionStatus\n documentSummary?: DocumentSummary[]\n error?: {\n code: string\n message: string | null\n target: string\n details: {\n code: string\n message: string\n target: string\n }[]\n }\n}> {\n const { fetch, debug } = context\n\n try {\n const response = await fetch(\n `/api/v1.0/documentsubmissions/${submissionUid}`,\n )\n\n const data = (await response.json()) as GetSubmissionResponse\n\n if (debug) {\n console.log('Submission:', data)\n if (data.error) {\n console.log('Submission error details:', data.error.details)\n }\n }\n\n // If we have a successful response and status is completed, return success\n if (data.overallStatus === 'Valid') {\n return {\n status: data.overallStatus,\n documentSummary: data.documentSummary,\n }\n }\n if (data.overallStatus === 'Invalid') {\n return {\n status: 'Invalid',\n documentSummary: data.documentSummary,\n }\n }\n\n // If we have retries left, continue polling for any non-completed status or errors\n if (maxRetries > 0) {\n await new Promise(resolve => setTimeout(resolve, pollInterval))\n return await getSubmissionStatus(\n context,\n submissionUid,\n pollInterval,\n maxRetries - 1,\n )\n }\n\n return {\n status: data.overallStatus || 'TimedOut',\n documentSummary: data.documentSummary,\n error:\n data.error ??\n ({\n code: 'Timeout',\n message: 'Submission timed out',\n target: 'submission',\n details: [],\n } satisfies StandardError),\n }\n } catch (error) {\n // Handle any request errors by retrying if we have retries left\n if (maxRetries > 0) {\n if (debug) {\n console.log('Request error, retrying...', error)\n }\n await new Promise(resolve => setTimeout(resolve, pollInterval))\n return await getSubmissionStatus(\n context,\n submissionUid,\n pollInterval,\n maxRetries - 1,\n )\n }\n\n // No retries left - return timeout\n return {\n status: 'TimedOut',\n documentSummary: [],\n error: {\n code: 'Timeout',\n message: 'Submission timed out after request errors',\n target: 'submission',\n details: [],\n },\n }\n }\n}\n\nexport async function performDocumentAction(\n documentUid: string,\n status: 'rejected' | 'cancelled',\n reason: string,\n): Promise<{\n uuid: string\n status: string\n error: StandardError\n}> {\n const response = await fetch(\n `/api/v1.0/documents/state/${documentUid}/state`,\n {\n method: 'POST',\n body: JSON.stringify({\n status,\n reason,\n }),\n },\n )\n\n const data = (await response.json()) as {\n uuid: string\n status: string\n error: StandardError\n }\n\n return data\n}\n"],"mappings":";;;AAkBA,eAAsB,eACpBA,SACAC,WAIC;CACD,MAAM,EAAE,gBAAO,OAAO,oBAAoB,GAAG;AAG7C,KAAI,UAAU,SAAS,IACrB,OAAM,IAAI,MACR;AAIJ,KAAI,MACF,SAAQ,KAAK,yBAAyB,UAAU,OAAO,iBAAiB;CAK1E,MAAM,SAAS,MAAM,OAAO;CAE5B,MAAM,oBAAoB,EACxB,WAAW,MAAM,QAAQ,IACv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AK;EACvB;AAIH,MAAI,aAAa,GAAG;AAClB,SAAM,IAAI,QAAQ,aAAW,WAAW,SAAS,aAAa;AAC9D,UAAO,MAAM,oBACX,SACA,eACA,cACA,aAAa,EACd;EACF;AAED,SAAO;GACL,QAAQ,KAAK,iBAAiB;GAC9B,iBAAiB,KAAK;GACtB,OACE,KAAK,SACJ;IACC,MAAM;IACN,SAAS;IACT,QAAQ;IACR,SAAS,CAAE;GACZ;EACJ;CACF,SAAQ,OAAO;AAEd,MAAI,aAAa,GAAG;AAClB,OAAI,MACF,SAAQ,IAAI,8BAA8B,MAAM;AAElD,SAAM,IAAI,QAAQ,aAAW,WAAW,SAAS,aAAa;AAC9D,UAAO,MAAM,oBACX,SACA,eACA,cACA,aAAa,EACd;EACF;AAGD,SAAO;GACL,QAAQ;GACR,iBAAiB,CAAE;GACnB,OAAO;IACL,MAAM;IACN,SAAS;IACT,QAAQ;IACR,SAAS,CAAE;GACZ;EACF;CACF;AACF;AAED,eAAsB,sBACpBC,aACAC,QACAC,QAKC;CACD,MAAM,WAAW,MAAM,OACpB,4BAA4B,YAAY,SACzC;EACE,QAAQ;EACR,MAAM,KAAK,UAAU;GACnB;GACA;EACD,EAAC;CACH,EACF;CAED,MAAM,OAAQ,MAAM,SAAS,MAAM;AAMnC,QAAO;AACR"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const require_documentManagement = require('./documentManagement-
|
|
1
|
+
const require_documentManagement = require('./documentManagement-CyPwiyP4.cjs');
|
|
2
2
|
require('./formatIdValue-i67o4kyD.cjs');
|
|
3
|
-
require('./document-
|
|
4
|
-
const require_documentSubmission = require('./documentSubmission-
|
|
3
|
+
require('./document-DWsGewNs.cjs');
|
|
4
|
+
const require_documentSubmission = require('./documentSubmission-D96QqHJ-.cjs');
|
|
5
5
|
const require_documentTypeManagement = require('./documentTypeManagement-D_-LiQVg.cjs');
|
|
6
6
|
const require_notificationManagement = require('./notificationManagement-DLBDn77E.cjs');
|
|
7
7
|
const require_platformLogin = require('./platformLogin-Ch6hFKoU.cjs');
|
|
@@ -15,6 +15,7 @@ var MyInvoisClient = class MyInvoisClient {
|
|
|
15
15
|
baseUrl;
|
|
16
16
|
clientId;
|
|
17
17
|
clientSecret;
|
|
18
|
+
environment;
|
|
18
19
|
onBehalfOf;
|
|
19
20
|
signingCredentials;
|
|
20
21
|
debug;
|
|
@@ -26,6 +27,7 @@ var MyInvoisClient = class MyInvoisClient {
|
|
|
26
27
|
this.clientId = clientId;
|
|
27
28
|
this.clientSecret = clientSecret;
|
|
28
29
|
this.baseUrl = require_getBaseUrl.getBaseUrl(environment);
|
|
30
|
+
this.environment = environment;
|
|
29
31
|
this.onBehalfOf = onBehalfOf;
|
|
30
32
|
this.debug = debug ?? process.env.MYINVOIS_DEBUG === "true" ? true : false;
|
|
31
33
|
const { issuerName, serialNumber } = require_certificate.extractCertificateInfo(certificatePem);
|
|
@@ -479,6 +481,36 @@ var MyInvoisClient = class MyInvoisClient {
|
|
|
479
481
|
return require_documentTypeManagement.getDocumentType({ fetch: this.fetch.bind(this) }, id);
|
|
480
482
|
}
|
|
481
483
|
/**
|
|
484
|
+
* Generates a shareable QR code URL for a specific document.
|
|
485
|
+
*
|
|
486
|
+
* This method retrieves the document details using its unique identifier,
|
|
487
|
+
* then constructs a URL that can be used to access or share the document
|
|
488
|
+
* via the MyInvois platform. The URL format differs between sandbox and
|
|
489
|
+
* production environments.
|
|
490
|
+
*
|
|
491
|
+
* @param documentUid - The unique identifier of the document
|
|
492
|
+
* @returns Promise resolving to a string containing the QR code URL
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* ```typescript
|
|
496
|
+
* const qrCodeUrl = await client.getDocumentQrCode('abc123');
|
|
497
|
+
* console.log('Shareable QR code URL:', qrCodeUrl);
|
|
498
|
+
* // Output (sandbox): https://preprod.myinvois.hasil.gov.my/abc123/share/longId
|
|
499
|
+
* // Output (production): https://myinvois.hasil.gov.my/abc123/share/longId
|
|
500
|
+
* ```
|
|
501
|
+
*
|
|
502
|
+
* @remarks
|
|
503
|
+
* - The returned URL can be embedded in a QR code for document sharing.
|
|
504
|
+
* - The method fetches the document to obtain its longId, which is required for the URL.
|
|
505
|
+
* - Ensure the documentUid is valid and accessible by the current client.
|
|
506
|
+
*/
|
|
507
|
+
async getDocumentQrCode(documentUid) {
|
|
508
|
+
const doc = await require_documentManagement.getDocument({ fetch: this.fetch.bind(this) }, documentUid);
|
|
509
|
+
console.log(doc);
|
|
510
|
+
const qrCodeBaseLink = `https://${this.environment === "sandbox" ? "preprod." : ""}myinvois.hasil.gov.my/`;
|
|
511
|
+
return qrCodeBaseLink + documentUid + "/share/" + doc.longId;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
482
514
|
* Retrieves detailed information about a specific version of a document type.
|
|
483
515
|
*
|
|
484
516
|
* This method fetches version-specific metadata, schema definitions, and validation rules
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["clientId: string","clientSecret: string","environment: 'sandbox' | 'production'","certificatePem: string","privateKeyPem: string","onBehalfOf?: string","debug?: boolean","onBehalfOf: string","path: string","options: Parameters<typeof fetch>[1]","tin: string","idType: RegistrationType","idValue: string","params: TinSearchParams","qrCodeText: string","documentUid: string","status: 'rejected' | 'cancelled'","reason: string","documents: AllDocumentsV1_1[]","submissionUid: string","pollInterval: number","maxRetries: number","id: number","versionId: number","p12Input: Buffer | string","passphrase: string"],"sources":["../src/index.ts"],"sourcesContent":["import {\n DocumentStatus,\n DocumentSummary,\n DocumentTypeResponse,\n DocumentTypesResponse,\n DocumentTypeVersionResponse,\n DocumentValidationResult,\n DocumentValidationStepResult,\n EInvoiceTypeCode,\n NotificationResponse,\n NotificationSearchParams,\n RegistrationType,\n SigningCredentials,\n StandardError,\n SubmissionResponse,\n SubmissionStatus,\n TaxpayerQRCodeResponse,\n TinSearchParams,\n TinSearchResponse,\n AllDocumentsV1_1,\n} from './types'\n\nimport * as DocumentManagementAPI from './api/documentManagement'\nimport * as DocumentSubmissionAPI from './api/documentSubmission'\nimport * as DocumentTypeManagementAPI from './api/documentTypeManagement'\nimport * as NotificationManagementAPI from './api/notificationManagement'\nimport { platformLogin } from './api/platformLogin'\nimport * as TaxpayerValidationAPI from './api/taxpayerValidation'\nimport {\n extractCertificateInfo,\n validateKeyPair,\n getPemFromP12,\n} from './utils/certificate'\nimport { getBaseUrl } from './utils/getBaseUrl'\nimport { queueRequest, categorizeRequest } from './utils/apiQueue'\n\nexport type * from './types/index.d.ts'\nexport class MyInvoisClient {\n private readonly baseUrl: string\n private readonly clientId: string\n private readonly clientSecret: string\n private onBehalfOf?: string\n private readonly signingCredentials: SigningCredentials\n private readonly debug: boolean\n private token = ''\n private tokenExpiration: Date | undefined = undefined\n\n constructor(\n clientId: string,\n clientSecret: string,\n environment: 'sandbox' | 'production',\n certificatePem: string,\n privateKeyPem: string,\n onBehalfOf?: string,\n debug?: boolean,\n ) {\n // Check if basic signing credentials are available\n if (!privateKeyPem || !certificatePem) {\n throw new Error(\n 'Missing required environment variables: PRIVATE_KEY and CERTIFICATE',\n )\n }\n\n // Validate that the key pair matches\n if (!validateKeyPair(certificatePem, privateKeyPem)) {\n throw new Error('Certificate and private key do not match')\n }\n\n this.clientId = clientId\n this.clientSecret = clientSecret\n this.baseUrl = getBaseUrl(environment)\n this.onBehalfOf = onBehalfOf\n this.debug = (debug ?? process.env.MYINVOIS_DEBUG === 'true') ? true : false\n\n // Extract certificate information\n const { issuerName, serialNumber } = extractCertificateInfo(certificatePem)\n\n this.signingCredentials = {\n privateKeyPem,\n certificatePem,\n issuerName,\n serialNumber,\n }\n }\n\n async updateOnBehalfOf(onBehalfOf: string): Promise<void> {\n this.onBehalfOf = onBehalfOf\n await this.refreshToken()\n return\n }\n\n private async refreshToken() {\n const tokenResponse = await platformLogin({\n clientId: this.clientId,\n clientSecret: this.clientSecret,\n baseUrl: this.baseUrl,\n onBehalfOf: this.onBehalfOf,\n debug: this.debug,\n })\n\n this.token = tokenResponse.token\n this.tokenExpiration = tokenResponse.tokenExpiration\n }\n\n private async getToken() {\n if (\n !this.tokenExpiration ||\n this.tokenExpiration < new Date() ||\n isNaN(this.tokenExpiration.getTime())\n ) {\n if (this.debug) {\n console.log('Token expired')\n console.log('Refreshing token')\n }\n await this.refreshToken()\n }\n\n return this.token\n }\n\n private async fetch(path: string, options: Parameters<typeof fetch>[1] = {}) {\n const token = await this.getToken()\n\n // Dynamically categorise the request and enqueue it so we never exceed the\n // vendor-specified rate-limits. If the path isn't recognised it will fall\n // back to the `default` category which has a very high allowance.\n\n const category = categorizeRequest(\n path,\n options?.method as string | undefined,\n )\n\n return queueRequest(\n category,\n () =>\n fetch(`${this.baseUrl}${path}`, {\n ...options,\n headers: { ...options.headers, Authorization: `Bearer ${token}` },\n }),\n this.debug,\n )\n }\n\n /**\n * Validates a TIN against a NRIC/ARMY/PASSPORT/BRN (Business Registration Number)\n *\n * This method verifies if a given Tax Identification Number (TIN) is valid by checking it against\n * the provided identification type and value through the MyInvois platform's validation service.\n *\n * @param tin - The TIN to validate\n * @param idType - The type of ID to validate against ('NRIC', 'ARMY', 'PASSPORT', or 'BRN')\n * @param idValue - The value of the ID to validate against\n * @returns Promise resolving to true if the TIN is valid, false otherwise\n *\n * @example\n * ```typescript\n * // Validate TIN against NRIC\n * const isValid = await client.verifyTin('C12345678901234', 'NRIC', '123456789012');\n * if (isValid) {\n * console.log('TIN is valid');\n * }\n *\n * // Validate TIN against Business Registration Number\n * const isValidBusiness = await client.verifyTin('C98765432109876', 'BRN', '123456-K');\n * ```\n *\n * @remarks\n * - Returns false if validation fails due to network errors or invalid credentials\n * - Debug mode provides error logging for troubleshooting validation failures\n * - This is a non-blocking validation that won't throw exceptions on failure\n */\n async verifyTin(\n tin: string,\n idType: RegistrationType,\n idValue: string,\n ): Promise<boolean> {\n return TaxpayerValidationAPI.verifyTin(\n { fetch: this.fetch.bind(this), debug: this.debug },\n tin,\n idType,\n idValue,\n )\n }\n\n /**\n * Searches for a Tax Identification Number (TIN) using taxpayer information.\n *\n * This method allows searching for a TIN using either a taxpayer name or a combination\n * of identification type and value. The search is flexible and supports multiple\n * identification types including NRIC, ARMY, PASSPORT, and BRN.\n *\n * @param params - Search parameters object\n * @param params.taxpayerName - Optional name of the taxpayer to search for\n * @param params.idType - Optional type of ID to search with (NRIC, ARMY, PASSPORT, BRN)\n * @param params.idValue - Optional value of the ID to search with\n * @returns Promise resolving to TIN search response or standard error\n *\n * @example\n * ```typescript\n * // Search by taxpayer name\n * const result = await client.searchTin({ taxpayerName: 'John Doe' });\n * if ('tin' in result) {\n * console.log('Found TIN:', result.tin);\n * }\n *\n * // Search by ID type and value\n * const result = await client.searchTin({\n * idType: 'NRIC',\n * idValue: '123456789012'\n * });\n * ```\n *\n * @remarks\n * - Either taxpayerName or both idType and idValue must be provided\n * - Returns StandardError object if search criteria are invalid or inconclusive\n * - Debug mode provides detailed error logging for troubleshooting\n * - Search results are not guaranteed to be unique\n */\n async searchTin(params: TinSearchParams): Promise<TinSearchResponse> {\n return TaxpayerValidationAPI.tinSearch(\n { fetch: this.fetch.bind(this), debug: this.debug },\n params,\n )\n }\n\n /**\n * Retrieves taxpayer information from a QR code.\n *\n * This method decodes a QR code containing taxpayer information and returns\n * detailed taxpayer data including TIN, name, contact details, and business information.\n *\n * @param qrCodeText - The QR code text to decode\n * @returns Promise resolving to taxpayer QR code response or standard error\n *\n * @example\n * ```typescript\n * // Get taxpayer info from QR code\n * const taxpayerInfo = await client.getTaxpayerQRCode('QR_CODE_TEXT');\n * if ('tin' in taxpayerInfo) {\n * console.log('Taxpayer TIN:', taxpayerInfo.tin);\n * console.log('Business Name:', taxpayerInfo.name);\n * console.log('Address:', taxpayerInfo.addressLine1);\n * }\n * ```\n *\n * @remarks\n * - QR code must be in the correct format specified by MyInvois\n * - Returns StandardError if QR code is invalid or cannot be decoded\n * - Debug mode provides detailed error logging\n */\n async getTaxpayerQRCode(qrCodeText: string): Promise<TaxpayerQRCodeResponse> {\n return TaxpayerValidationAPI.taxpayerQRCode(\n { fetch: this.fetch.bind(this), debug: this.debug },\n qrCodeText,\n )\n }\n\n /**\n * Performs an action on a document such as rejection or cancellation.\n *\n * This method allows updating the status of a document to either rejected or cancelled,\n * along with providing a reason for the action. Useful for managing document workflow\n * and maintaining audit trails.\n *\n * @param documentUid - The unique identifier of the document\n * @param status - The new status to set ('rejected' or 'cancelled')\n * @param reason - The reason for the status change\n * @returns Promise resolving to document action response containing UUID, status, and any errors\n *\n * @example\n * ```typescript\n * // Reject a document with reason\n * const result = await client.performDocumentAction(\n * 'doc-123',\n * 'rejected',\n * 'Invalid tax calculation'\n * );\n *\n * // Cancel a document\n * const result = await client.performDocumentAction(\n * 'doc-456',\n * 'cancelled',\n * 'Duplicate submission'\n * );\n * ```\n *\n * @remarks\n * - Only valid for documents in appropriate states\n * - Reason is required and should be descriptive\n * - Action is irreversible once completed\n * - Returns error if document cannot be found or action is invalid\n */\n async performDocumentAction(\n documentUid: string,\n status: 'rejected' | 'cancelled',\n reason: string,\n ): Promise<{\n uuid: string\n status: string\n error: StandardError\n }> {\n return DocumentSubmissionAPI.performDocumentAction(\n documentUid,\n status,\n reason,\n )\n }\n\n /**\n * Submits one or more e-invoice documents to the MyInvois platform for processing.\n *\n * This method digitally signs each document using the provided certificate and private key,\n * generates document hashes, encodes them for submission, and sends them to the platform.\n * The method includes comprehensive validation warnings for document size and count limits.\n *\n * @param documents - Array of InvoiceV1_1 documents to be submitted\n * @returns Promise resolving to submission response containing the submission data and HTTP status\n * @throws {Error} If PRIVATE_KEY or CERTIFICATE environment variables are missing\n * @throws {Error} If document signing, encoding, or API submission fails\n *\n * @example\n * ```typescript\n * // Submit a single invoice\n * const result = await client.submitDocument([invoiceData]);\n * console.log(result.data.submissionUid); // Track submission with this UID\n *\n * // Submit multiple invoices\n * const result = await client.submitDocument([invoice1, invoice2, invoice3]);\n * if (result.status === 202) {\n * console.log('Documents submitted successfully');\n * }\n * ```\n *\n * @remarks\n * - Requires PRIVATE_KEY and CERTIFICATE environment variables for document signing\n * - Each document is digitally signed with XML-DSIG before submission\n * - Documents are base64-encoded for transmission\n * - API limits: Max 100 documents per submission, 5MB total payload, 300KB per document\n * - Debug mode provides detailed logging of payload sizes and validation warnings\n * - Returns HTTP 202 for successful submissions that require processing\n */\n async submitDocument(documents: AllDocumentsV1_1[]): Promise<{\n data: SubmissionResponse\n status: number\n }> {\n return DocumentSubmissionAPI.submitDocument(\n {\n fetch: this.fetch.bind(this),\n debug: this.debug,\n signingCredentials: this.signingCredentials,\n },\n documents,\n )\n }\n\n /**\n * Polls the MyInvois platform to get the current status of a document submission.\n *\n * This method continuously checks the submission status until it receives a final result\n * (Valid or Invalid) or reaches the maximum retry limit. It's designed to handle the\n * asynchronous nature of document processing on the MyInvois platform.\n *\n * @param submissionUid - The unique identifier of the submission to check\n * @param pollInterval - Time in milliseconds between status checks (default: 1000ms)\n * @param maxRetries - Maximum number of retry attempts (default: 10)\n * @returns Promise resolving to submission status object with document summary and any errors\n *\n * @example\n * ```typescript\n * // Check submission status with default polling\n * const result = await client.getSubmissionStatus('submission-uid-123');\n * if (result.status === 'Valid') {\n * console.log('All documents processed successfully');\n * console.log('Document summaries:', result.documentSummary);\n * }\n *\n * // Custom polling interval and retry count\n * const result = await client.getSubmissionStatus(\n * 'submission-uid-123',\n * 2000, // Poll every 2 seconds\n * 20 // Try up to 20 times\n * );\n * ```\n *\n * @remarks\n * - Automatically retries on network errors until maxRetries is reached\n * - Returns 'Invalid' status with timeout error if submission processing takes too long\n * - Debug mode provides detailed logging of polling attempts and responses\n * - Use reasonable poll intervals to avoid overwhelming the API\n */\n async getSubmissionStatus(\n submissionUid: string,\n pollInterval: number = 1000,\n maxRetries: number = 10,\n ): Promise<{\n status: SubmissionStatus\n documentSummary?: DocumentSummary[]\n error?: {\n code: string\n message: string | null\n target: string\n details: {\n code: string\n message: string\n target: string\n }[]\n }\n }> {\n return DocumentSubmissionAPI.getSubmissionStatus(\n { fetch: this.fetch.bind(this), debug: this.debug },\n submissionUid,\n pollInterval,\n maxRetries,\n )\n }\n\n /**\n * Retrieves a document by its unique identifier with the raw document content.\n *\n * @param documentUid - The unique identifier of the document to retrieve\n * @returns Promise resolving to document summary with raw document content as a string\n * @throws {Error} If the document is not found or request fails\n *\n * @example\n * ```typescript\n * const document = await client.getDocument('doc-uuid-123');\n * console.log(document.document); // Raw XML/JSON content\n * console.log(document.uuid); // Document UUID\n * ```\n */\n async getDocument(\n documentUid: string,\n ): Promise<DocumentSummary & { document: string }> {\n return DocumentManagementAPI.getDocument(\n { fetch: this.fetch.bind(this) },\n documentUid,\n )\n }\n\n /**\n * Retrieves detailed information about a document including validation results.\n *\n * @param documentUid - The unique identifier of the document to get details for\n * @returns Promise resolving to document summary with detailed validation results\n * @throws {Error} If the document is not found or request fails\n *\n * @example\n * ```typescript\n * const details = await client.getDocumentDetails('doc-uuid-123');\n * console.log(details.validationResults.status); // 'Valid' | 'Invalid' | 'Processing'\n * console.log(details.validationResults.validationSteps); // Array of validation step results\n * ```\n */\n async getDocumentDetails(documentUid: string): Promise<\n DocumentSummary & {\n validationResults: {\n status: DocumentValidationResult\n validationSteps: DocumentValidationStepResult[]\n }\n }\n > {\n return DocumentManagementAPI.getDocumentDetails(\n { fetch: this.fetch.bind(this) },\n documentUid,\n )\n }\n\n /**\n * Searches for documents based on various filter criteria.\n *\n * @param params - Search parameters object\n * @param params.uuid - Optional specific document UUID to search for\n * @param params.submissionDateFrom - Required start date for submission date range (ISO date string)\n * @param params.submissionDateTo - Optional end date for submission date range (ISO date string)\n * @param params.pageSize - Optional number of results per page (default handled by API)\n * @param params.pageNo - Optional page number for pagination (0-based)\n * @param params.issueDateFrom - Optional start date for issue date range (ISO date string)\n * @param params.issueDateTo - Optional end date for issue date range (ISO date string)\n * @param params.invoiceDirection - Optional filter by invoice direction ('Sent' or 'Received')\n * @param params.status - Optional filter by document status\n * @param params.documentType - Optional filter by e-invoice type code\n * @param params.searchQuery - Optional text search across uuid, buyerTIN, supplierTIN, buyerName, supplierName, internalID, total\n * @returns Promise resolving to array of document summaries matching the search criteria\n * @throws {Error} If the search request fails\n *\n * @example\n * ```typescript\n * // Search for documents submitted in the last 30 days\n * const documents = await client.searchDocuments({\n * submissionDateFrom: '2024-01-01',\n * submissionDateTo: '2024-01-31',\n * status: 'Valid',\n * pageSize: 10\n * });\n *\n * // Search by supplier name\n * const supplierDocs = await client.searchDocuments({\n * submissionDateFrom: '2024-01-01',\n * searchQuery: 'ACME Corp',\n * invoiceDirection: 'Received'\n * });\n * ```\n */\n async searchDocuments({\n uuid,\n submissionDateFrom,\n submissionDateTo,\n pageSize,\n pageNo,\n issueDateFrom,\n issueDateTo,\n invoiceDirection,\n status,\n documentType,\n searchQuery,\n }: {\n uuid?: string\n submissionDateFrom: string\n submissionDateTo?: string\n pageSize?: number\n pageNo?: number\n issueDateFrom?: string\n issueDateTo?: string\n invoiceDirection?: 'Sent' | 'Received'\n status?: DocumentStatus\n documentType?: EInvoiceTypeCode\n searchQuery?: string // Search by uuid, buyerTIN, supplierTIN, buyerName, supplierName, internalID, total\n }): Promise<DocumentSummary[]> {\n return DocumentManagementAPI.searchDocuments(\n { fetch: this.fetch.bind(this) },\n {\n uuid,\n submissionDateFrom,\n submissionDateTo,\n pageSize,\n pageNo,\n issueDateFrom,\n issueDateTo,\n invoiceDirection,\n status,\n documentType,\n searchQuery,\n },\n )\n }\n\n /**\n * Retrieves notifications from the MyInvois platform based on specified search criteria.\n *\n * This method allows you to search for system notifications, alerts, and messages\n * sent by the MyInvois platform regarding document processing, system updates,\n * or account-related information.\n *\n * @param params - Search parameters object for filtering notifications\n * @param params.dateFrom - Optional start date for notification date range (ISO date string)\n * @param params.dateTo - Optional end date for notification date range (ISO date string)\n * @param params.type - Optional notification type filter\n * @param params.language - Optional language preference for notifications\n * @param params.status - Optional notification status filter\n * @param params.pageNo - Optional page number for pagination (0-based)\n * @param params.pageSize - Optional number of results per page\n * @returns Promise resolving to notification response object or standard error\n *\n * @example\n * ```typescript\n * // Get all notifications from the last 7 days\n * const notifications = await client.getNotifications({\n * dateFrom: '2024-01-01',\n * dateTo: '2024-01-07',\n * pageSize: 20\n * });\n *\n * // Get unread notifications only\n * const unreadNotifications = await client.getNotifications({\n * status: 0, // Assuming 0 = unread\n * language: 'en'\n * });\n *\n * // Paginated notification retrieval\n * const firstPage = await client.getNotifications({\n * dateFrom: '2024-01-01',\n * pageNo: 0,\n * pageSize: 10\n * });\n * ```\n *\n * @remarks\n * - All parameters are optional, allowing flexible filtering\n * - Returns paginated results when pageNo and pageSize are specified\n * - Date parameters should be in ISO format (YYYY-MM-DD)\n * - May return StandardError object if the request fails\n */\n async getNotifications({\n dateFrom,\n dateTo,\n type,\n language,\n status,\n pageNo,\n pageSize,\n }: NotificationSearchParams): Promise<NotificationResponse> {\n return NotificationManagementAPI.getNotifications(\n { fetch: this.fetch.bind(this) },\n {\n dateFrom,\n dateTo,\n type,\n language,\n status,\n pageNo,\n pageSize,\n },\n )\n }\n\n async getDocumentTypes(): Promise<DocumentTypesResponse> {\n return DocumentTypeManagementAPI.getDocumentTypes({\n fetch: this.fetch.bind(this),\n })\n }\n\n /**\n * Retrieves detailed information about a specific document type from the MyInvois platform.\n *\n * This method fetches metadata and configuration details for a specific document type,\n * including supported versions, validation rules, and structural requirements.\n * Useful for understanding document format requirements before submission.\n *\n * @param id - The unique identifier of the document type to retrieve\n * @returns Promise resolving to document type response object or standard error\n *\n * @example\n * ```typescript\n * // Get details for e-invoice document type\n * const invoiceType = await client.getDocumentType(1);\n * if ('id' in invoiceType) {\n * console.log('Document type name:', invoiceType.name);\n * console.log('Available versions:', invoiceType.versionNumber);\n * console.log('Description:', invoiceType.description);\n * }\n *\n * // Handle potential errors\n * const documentType = await client.getDocumentType(999);\n * if ('error' in documentType) {\n * console.error('Failed to retrieve document type:', documentType.error.message);\n * }\n * ```\n *\n * @remarks\n * - Returns StandardError object if the document type ID doesn't exist\n * - Document type information includes validation schemas and business rules\n * - Use this method to discover supported document formats and versions\n * - Essential for understanding submission requirements for different document types\n */\n async getDocumentType(id: number): Promise<DocumentTypeResponse> {\n return DocumentTypeManagementAPI.getDocumentType(\n { fetch: this.fetch.bind(this) },\n id,\n )\n }\n\n /**\n * Retrieves detailed information about a specific version of a document type.\n *\n * This method fetches version-specific metadata, schema definitions, and validation rules\n * for a particular document type version. Essential for understanding the exact format\n * and requirements for document submission in a specific version.\n *\n * @param id - The unique identifier of the document type\n * @param versionId - The unique identifier of the specific version to retrieve\n * @returns Promise resolving to document type version response object or standard error\n *\n * @example\n * ```typescript\n * // Get specific version details for e-invoice\n * const invoiceV1_1 = await client.getDocumentTypeVersion(1, 1);\n * if ('id' in invoiceV1_1) {\n * console.log('Version number:', invoiceV1_1.versionNumber);\n * console.log('Schema:', invoiceV1_1.jsonSchema);\n * console.log('Status:', invoiceV1_1.status);\n * }\n *\n * // Compare different versions\n * const [v1_0, v1_1] = await Promise.all([\n * client.getDocumentTypeVersion(1, 0),\n * client.getDocumentTypeVersion(1, 1)\n * ]);\n *\n * // Handle version not found\n * const result = await client.getDocumentTypeVersion(1, 999);\n * if ('error' in result) {\n * console.error('Version not found:', result.error.message);\n * }\n * ```\n *\n * @remarks\n * - Returns StandardError object if document type ID or version ID doesn't exist\n * - Version information includes JSON schema for validation\n * - Different versions may have different validation rules and field requirements\n * - Use this to ensure your documents conform to the specific version requirements\n * - Version status indicates if the version is active, deprecated, or under development\n */\n async getDocumentTypeVersion(\n id: number,\n versionId: number,\n ): Promise<DocumentTypeVersionResponse> {\n return DocumentTypeManagementAPI.getDocumentTypeVersion(\n { fetch: this.fetch.bind(this) },\n id,\n versionId,\n )\n }\n\n // Static helper: create a client directly from a PKCS#12 (.p12) bundle\n static fromP12(\n clientId: string,\n clientSecret: string,\n environment: 'sandbox' | 'production',\n p12Input: Buffer | string,\n passphrase: string,\n onBehalfOf?: string,\n debug?: boolean,\n ): MyInvoisClient {\n const { certificatePem, privateKeyPem } = getPemFromP12(\n p12Input,\n passphrase,\n )\n\n return new MyInvoisClient(\n clientId,\n clientSecret,\n environment,\n certificatePem,\n privateKeyPem,\n onBehalfOf,\n debug,\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAqCA,IAAa,iBAAb,MAAa,eAAe;CAC1B,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAQ;CACR,AAAiB;CACjB,AAAiB;CACjB,AAAQ,QAAQ;CAChB,AAAQ;CAER,YACEA,UACAC,cACAC,aACAC,gBACAC,eACAC,YACAC,OACA;AAEA,OAAK,kBAAkB,eACrB,OAAM,IAAI,MACR;AAKJ,OAAK,oCAAgB,gBAAgB,cAAc,CACjD,OAAM,IAAI,MAAM;AAGlB,OAAK,WAAW;AAChB,OAAK,eAAe;AACpB,OAAK,UAAU,8BAAW,YAAY;AACtC,OAAK,aAAa;AAClB,OAAK,QAAS,SAAS,QAAQ,IAAI,mBAAmB,SAAU,OAAO;EAGvE,MAAM,EAAE,YAAY,cAAc,GAAG,2CAAuB,eAAe;AAE3E,OAAK,qBAAqB;GACxB;GACA;GACA;GACA;EACD;CACF;CAED,MAAM,iBAAiBC,YAAmC;AACxD,OAAK,aAAa;AAClB,QAAM,KAAK,cAAc;AACzB;CACD;CAED,MAAc,eAAe;EAC3B,MAAM,gBAAgB,MAAM,oCAAc;GACxC,UAAU,KAAK;GACf,cAAc,KAAK;GACnB,SAAS,KAAK;GACd,YAAY,KAAK;GACjB,OAAO,KAAK;EACb,EAAC;AAEF,OAAK,QAAQ,cAAc;AAC3B,OAAK,kBAAkB,cAAc;CACtC;CAED,MAAc,WAAW;AACvB,OACG,KAAK,mBACN,KAAK,kCAAkB,IAAI,UAC3B,MAAM,KAAK,gBAAgB,SAAS,CAAC,EACrC;AACA,OAAI,KAAK,OAAO;AACd,YAAQ,IAAI,gBAAgB;AAC5B,YAAQ,IAAI,mBAAmB;GAChC;AACD,SAAM,KAAK,cAAc;EAC1B;AAED,SAAO,KAAK;CACb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B,UACAC,cACAC,aACAsB,UACAC,YACApB,YACAC,OACgB;EAChB,MAAM,EAAE,gBAAgB,eAAe,GAAG,kCACxC,UACA,WACD;AAED,SAAO,IAAI,eACT,UACA,cACA,aACA,gBACA,eACA,YACA;CAEH;AACF"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["clientId: string","clientSecret: string","environment: 'sandbox' | 'production'","certificatePem: string","privateKeyPem: string","onBehalfOf?: string","debug?: boolean","onBehalfOf: string","path: string","options: Parameters<typeof fetch>[1]","tin: string","idType: RegistrationType","idValue: string","params: TinSearchParams","qrCodeText: string","documentUid: string","status: 'rejected' | 'cancelled'","reason: string","documents: AllDocumentsV1_1[]","submissionUid: string","pollInterval: number","maxRetries: number","id: number","versionId: number","p12Input: Buffer | string","passphrase: string"],"sources":["../src/index.ts"],"sourcesContent":["import {\n DocumentStatus,\n DocumentSummary,\n DocumentTypeResponse,\n DocumentTypesResponse,\n DocumentTypeVersionResponse,\n DocumentValidationResult,\n DocumentValidationStepResult,\n EInvoiceTypeCode,\n NotificationResponse,\n NotificationSearchParams,\n RegistrationType,\n SigningCredentials,\n StandardError,\n SubmissionResponse,\n SubmissionStatus,\n TaxpayerQRCodeResponse,\n TinSearchParams,\n TinSearchResponse,\n AllDocumentsV1_1,\n} from './types'\n\nimport * as DocumentManagementAPI from './api/documentManagement'\nimport * as DocumentSubmissionAPI from './api/documentSubmission'\nimport * as DocumentTypeManagementAPI from './api/documentTypeManagement'\nimport * as NotificationManagementAPI from './api/notificationManagement'\nimport { platformLogin } from './api/platformLogin'\nimport * as TaxpayerValidationAPI from './api/taxpayerValidation'\nimport {\n extractCertificateInfo,\n validateKeyPair,\n getPemFromP12,\n} from './utils/certificate'\nimport { getBaseUrl } from './utils/getBaseUrl'\nimport { queueRequest, categorizeRequest } from './utils/apiQueue'\n\nexport type * from './types/index.d.ts'\nexport class MyInvoisClient {\n private readonly baseUrl: string\n private readonly clientId: string\n private readonly clientSecret: string\n private readonly environment: 'sandbox' | 'production'\n private onBehalfOf?: string\n private readonly signingCredentials: SigningCredentials\n private readonly debug: boolean\n private token = ''\n private tokenExpiration: Date | undefined = undefined\n\n constructor(\n clientId: string,\n clientSecret: string,\n environment: 'sandbox' | 'production',\n certificatePem: string,\n privateKeyPem: string,\n onBehalfOf?: string,\n debug?: boolean,\n ) {\n // Check if basic signing credentials are available\n if (!privateKeyPem || !certificatePem) {\n throw new Error(\n 'Missing required environment variables: PRIVATE_KEY and CERTIFICATE',\n )\n }\n\n // Validate that the key pair matches\n if (!validateKeyPair(certificatePem, privateKeyPem)) {\n throw new Error('Certificate and private key do not match')\n }\n\n this.clientId = clientId\n this.clientSecret = clientSecret\n this.baseUrl = getBaseUrl(environment)\n this.environment = environment\n this.onBehalfOf = onBehalfOf\n this.debug = (debug ?? process.env.MYINVOIS_DEBUG === 'true') ? true : false\n\n // Extract certificate information\n const { issuerName, serialNumber } = extractCertificateInfo(certificatePem)\n\n this.signingCredentials = {\n privateKeyPem,\n certificatePem,\n issuerName,\n serialNumber,\n }\n }\n\n async updateOnBehalfOf(onBehalfOf: string): Promise<void> {\n this.onBehalfOf = onBehalfOf\n await this.refreshToken()\n return\n }\n\n private async refreshToken() {\n const tokenResponse = await platformLogin({\n clientId: this.clientId,\n clientSecret: this.clientSecret,\n baseUrl: this.baseUrl,\n onBehalfOf: this.onBehalfOf,\n debug: this.debug,\n })\n\n this.token = tokenResponse.token\n this.tokenExpiration = tokenResponse.tokenExpiration\n }\n\n private async getToken() {\n if (\n !this.tokenExpiration ||\n this.tokenExpiration < new Date() ||\n isNaN(this.tokenExpiration.getTime())\n ) {\n if (this.debug) {\n console.log('Token expired')\n console.log('Refreshing token')\n }\n await this.refreshToken()\n }\n\n return this.token\n }\n\n private async fetch(path: string, options: Parameters<typeof fetch>[1] = {}) {\n const token = await this.getToken()\n\n // Dynamically categorise the request and enqueue it so we never exceed the\n // vendor-specified rate-limits. If the path isn't recognised it will fall\n // back to the `default` category which has a very high allowance.\n\n const category = categorizeRequest(\n path,\n options?.method as string | undefined,\n )\n\n return queueRequest(\n category,\n () =>\n fetch(`${this.baseUrl}${path}`, {\n ...options,\n headers: { ...options.headers, Authorization: `Bearer ${token}` },\n }),\n this.debug,\n )\n }\n\n /**\n * Validates a TIN against a NRIC/ARMY/PASSPORT/BRN (Business Registration Number)\n *\n * This method verifies if a given Tax Identification Number (TIN) is valid by checking it against\n * the provided identification type and value through the MyInvois platform's validation service.\n *\n * @param tin - The TIN to validate\n * @param idType - The type of ID to validate against ('NRIC', 'ARMY', 'PASSPORT', or 'BRN')\n * @param idValue - The value of the ID to validate against\n * @returns Promise resolving to true if the TIN is valid, false otherwise\n *\n * @example\n * ```typescript\n * // Validate TIN against NRIC\n * const isValid = await client.verifyTin('C12345678901234', 'NRIC', '123456789012');\n * if (isValid) {\n * console.log('TIN is valid');\n * }\n *\n * // Validate TIN against Business Registration Number\n * const isValidBusiness = await client.verifyTin('C98765432109876', 'BRN', '123456-K');\n * ```\n *\n * @remarks\n * - Returns false if validation fails due to network errors or invalid credentials\n * - Debug mode provides error logging for troubleshooting validation failures\n * - This is a non-blocking validation that won't throw exceptions on failure\n */\n async verifyTin(\n tin: string,\n idType: RegistrationType,\n idValue: string,\n ): Promise<boolean> {\n return TaxpayerValidationAPI.verifyTin(\n { fetch: this.fetch.bind(this), debug: this.debug },\n tin,\n idType,\n idValue,\n )\n }\n\n /**\n * Searches for a Tax Identification Number (TIN) using taxpayer information.\n *\n * This method allows searching for a TIN using either a taxpayer name or a combination\n * of identification type and value. The search is flexible and supports multiple\n * identification types including NRIC, ARMY, PASSPORT, and BRN.\n *\n * @param params - Search parameters object\n * @param params.taxpayerName - Optional name of the taxpayer to search for\n * @param params.idType - Optional type of ID to search with (NRIC, ARMY, PASSPORT, BRN)\n * @param params.idValue - Optional value of the ID to search with\n * @returns Promise resolving to TIN search response or standard error\n *\n * @example\n * ```typescript\n * // Search by taxpayer name\n * const result = await client.searchTin({ taxpayerName: 'John Doe' });\n * if ('tin' in result) {\n * console.log('Found TIN:', result.tin);\n * }\n *\n * // Search by ID type and value\n * const result = await client.searchTin({\n * idType: 'NRIC',\n * idValue: '123456789012'\n * });\n * ```\n *\n * @remarks\n * - Either taxpayerName or both idType and idValue must be provided\n * - Returns StandardError object if search criteria are invalid or inconclusive\n * - Debug mode provides detailed error logging for troubleshooting\n * - Search results are not guaranteed to be unique\n */\n async searchTin(params: TinSearchParams): Promise<TinSearchResponse> {\n return TaxpayerValidationAPI.tinSearch(\n { fetch: this.fetch.bind(this), debug: this.debug },\n params,\n )\n }\n\n /**\n * Retrieves taxpayer information from a QR code.\n *\n * This method decodes a QR code containing taxpayer information and returns\n * detailed taxpayer data including TIN, name, contact details, and business information.\n *\n * @param qrCodeText - The QR code text to decode\n * @returns Promise resolving to taxpayer QR code response or standard error\n *\n * @example\n * ```typescript\n * // Get taxpayer info from QR code\n * const taxpayerInfo = await client.getTaxpayerQRCode('QR_CODE_TEXT');\n * if ('tin' in taxpayerInfo) {\n * console.log('Taxpayer TIN:', taxpayerInfo.tin);\n * console.log('Business Name:', taxpayerInfo.name);\n * console.log('Address:', taxpayerInfo.addressLine1);\n * }\n * ```\n *\n * @remarks\n * - QR code must be in the correct format specified by MyInvois\n * - Returns StandardError if QR code is invalid or cannot be decoded\n * - Debug mode provides detailed error logging\n */\n async getTaxpayerQRCode(qrCodeText: string): Promise<TaxpayerQRCodeResponse> {\n return TaxpayerValidationAPI.taxpayerQRCode(\n { fetch: this.fetch.bind(this), debug: this.debug },\n qrCodeText,\n )\n }\n\n /**\n * Performs an action on a document such as rejection or cancellation.\n *\n * This method allows updating the status of a document to either rejected or cancelled,\n * along with providing a reason for the action. Useful for managing document workflow\n * and maintaining audit trails.\n *\n * @param documentUid - The unique identifier of the document\n * @param status - The new status to set ('rejected' or 'cancelled')\n * @param reason - The reason for the status change\n * @returns Promise resolving to document action response containing UUID, status, and any errors\n *\n * @example\n * ```typescript\n * // Reject a document with reason\n * const result = await client.performDocumentAction(\n * 'doc-123',\n * 'rejected',\n * 'Invalid tax calculation'\n * );\n *\n * // Cancel a document\n * const result = await client.performDocumentAction(\n * 'doc-456',\n * 'cancelled',\n * 'Duplicate submission'\n * );\n * ```\n *\n * @remarks\n * - Only valid for documents in appropriate states\n * - Reason is required and should be descriptive\n * - Action is irreversible once completed\n * - Returns error if document cannot be found or action is invalid\n */\n async performDocumentAction(\n documentUid: string,\n status: 'rejected' | 'cancelled',\n reason: string,\n ): Promise<{\n uuid: string\n status: string\n error: StandardError\n }> {\n return DocumentSubmissionAPI.performDocumentAction(\n documentUid,\n status,\n reason,\n )\n }\n\n /**\n * Submits one or more e-invoice documents to the MyInvois platform for processing.\n *\n * This method digitally signs each document using the provided certificate and private key,\n * generates document hashes, encodes them for submission, and sends them to the platform.\n * The method includes comprehensive validation warnings for document size and count limits.\n *\n * @param documents - Array of InvoiceV1_1 documents to be submitted\n * @returns Promise resolving to submission response containing the submission data and HTTP status\n * @throws {Error} If PRIVATE_KEY or CERTIFICATE environment variables are missing\n * @throws {Error} If document signing, encoding, or API submission fails\n *\n * @example\n * ```typescript\n * // Submit a single invoice\n * const result = await client.submitDocument([invoiceData]);\n * console.log(result.data.submissionUid); // Track submission with this UID\n *\n * // Submit multiple invoices\n * const result = await client.submitDocument([invoice1, invoice2, invoice3]);\n * if (result.status === 202) {\n * console.log('Documents submitted successfully');\n * }\n * ```\n *\n * @remarks\n * - Requires PRIVATE_KEY and CERTIFICATE environment variables for document signing\n * - Each document is digitally signed with XML-DSIG before submission\n * - Documents are base64-encoded for transmission\n * - API limits: Max 100 documents per submission, 5MB total payload, 300KB per document\n * - Debug mode provides detailed logging of payload sizes and validation warnings\n * - Returns HTTP 202 for successful submissions that require processing\n */\n async submitDocument(documents: AllDocumentsV1_1[]): Promise<{\n data: SubmissionResponse\n status: number\n }> {\n return DocumentSubmissionAPI.submitDocument(\n {\n fetch: this.fetch.bind(this),\n debug: this.debug,\n signingCredentials: this.signingCredentials,\n },\n documents,\n )\n }\n\n /**\n * Polls the MyInvois platform to get the current status of a document submission.\n *\n * This method continuously checks the submission status until it receives a final result\n * (Valid or Invalid) or reaches the maximum retry limit. It's designed to handle the\n * asynchronous nature of document processing on the MyInvois platform.\n *\n * @param submissionUid - The unique identifier of the submission to check\n * @param pollInterval - Time in milliseconds between status checks (default: 1000ms)\n * @param maxRetries - Maximum number of retry attempts (default: 10)\n * @returns Promise resolving to submission status object with document summary and any errors\n *\n * @example\n * ```typescript\n * // Check submission status with default polling\n * const result = await client.getSubmissionStatus('submission-uid-123');\n * if (result.status === 'Valid') {\n * console.log('All documents processed successfully');\n * console.log('Document summaries:', result.documentSummary);\n * }\n *\n * // Custom polling interval and retry count\n * const result = await client.getSubmissionStatus(\n * 'submission-uid-123',\n * 2000, // Poll every 2 seconds\n * 20 // Try up to 20 times\n * );\n * ```\n *\n * @remarks\n * - Automatically retries on network errors until maxRetries is reached\n * - Returns 'Invalid' status with timeout error if submission processing takes too long\n * - Debug mode provides detailed logging of polling attempts and responses\n * - Use reasonable poll intervals to avoid overwhelming the API\n */\n async getSubmissionStatus(\n submissionUid: string,\n pollInterval: number = 1000,\n maxRetries: number = 10,\n ): Promise<{\n status: SubmissionStatus\n documentSummary?: DocumentSummary[]\n error?: {\n code: string\n message: string | null\n target: string\n details: {\n code: string\n message: string\n target: string\n }[]\n }\n }> {\n return DocumentSubmissionAPI.getSubmissionStatus(\n { fetch: this.fetch.bind(this), debug: this.debug },\n submissionUid,\n pollInterval,\n maxRetries,\n )\n }\n\n /**\n * Retrieves a document by its unique identifier with the raw document content.\n *\n * @param documentUid - The unique identifier of the document to retrieve\n * @returns Promise resolving to document summary with raw document content as a string\n * @throws {Error} If the document is not found or request fails\n *\n * @example\n * ```typescript\n * const document = await client.getDocument('doc-uuid-123');\n * console.log(document.document); // Raw XML/JSON content\n * console.log(document.uuid); // Document UUID\n * ```\n */\n async getDocument(\n documentUid: string,\n ): Promise<DocumentSummary & { document: string }> {\n return DocumentManagementAPI.getDocument(\n { fetch: this.fetch.bind(this) },\n documentUid,\n )\n }\n\n /**\n * Retrieves detailed information about a document including validation results.\n *\n * @param documentUid - The unique identifier of the document to get details for\n * @returns Promise resolving to document summary with detailed validation results\n * @throws {Error} If the document is not found or request fails\n *\n * @example\n * ```typescript\n * const details = await client.getDocumentDetails('doc-uuid-123');\n * console.log(details.validationResults.status); // 'Valid' | 'Invalid' | 'Processing'\n * console.log(details.validationResults.validationSteps); // Array of validation step results\n * ```\n */\n async getDocumentDetails(documentUid: string): Promise<\n DocumentSummary & {\n validationResults: {\n status: DocumentValidationResult\n validationSteps: DocumentValidationStepResult[]\n }\n }\n > {\n return DocumentManagementAPI.getDocumentDetails(\n { fetch: this.fetch.bind(this) },\n documentUid,\n )\n }\n\n /**\n * Searches for documents based on various filter criteria.\n *\n * @param params - Search parameters object\n * @param params.uuid - Optional specific document UUID to search for\n * @param params.submissionDateFrom - Required start date for submission date range (ISO date string)\n * @param params.submissionDateTo - Optional end date for submission date range (ISO date string)\n * @param params.pageSize - Optional number of results per page (default handled by API)\n * @param params.pageNo - Optional page number for pagination (0-based)\n * @param params.issueDateFrom - Optional start date for issue date range (ISO date string)\n * @param params.issueDateTo - Optional end date for issue date range (ISO date string)\n * @param params.invoiceDirection - Optional filter by invoice direction ('Sent' or 'Received')\n * @param params.status - Optional filter by document status\n * @param params.documentType - Optional filter by e-invoice type code\n * @param params.searchQuery - Optional text search across uuid, buyerTIN, supplierTIN, buyerName, supplierName, internalID, total\n * @returns Promise resolving to array of document summaries matching the search criteria\n * @throws {Error} If the search request fails\n *\n * @example\n * ```typescript\n * // Search for documents submitted in the last 30 days\n * const documents = await client.searchDocuments({\n * submissionDateFrom: '2024-01-01',\n * submissionDateTo: '2024-01-31',\n * status: 'Valid',\n * pageSize: 10\n * });\n *\n * // Search by supplier name\n * const supplierDocs = await client.searchDocuments({\n * submissionDateFrom: '2024-01-01',\n * searchQuery: 'ACME Corp',\n * invoiceDirection: 'Received'\n * });\n * ```\n */\n async searchDocuments({\n uuid,\n submissionDateFrom,\n submissionDateTo,\n pageSize,\n pageNo,\n issueDateFrom,\n issueDateTo,\n invoiceDirection,\n status,\n documentType,\n searchQuery,\n }: {\n uuid?: string\n submissionDateFrom: string\n submissionDateTo?: string\n pageSize?: number\n pageNo?: number\n issueDateFrom?: string\n issueDateTo?: string\n invoiceDirection?: 'Sent' | 'Received'\n status?: DocumentStatus\n documentType?: EInvoiceTypeCode\n searchQuery?: string // Search by uuid, buyerTIN, supplierTIN, buyerName, supplierName, internalID, total\n }): Promise<DocumentSummary[]> {\n return DocumentManagementAPI.searchDocuments(\n { fetch: this.fetch.bind(this) },\n {\n uuid,\n submissionDateFrom,\n submissionDateTo,\n pageSize,\n pageNo,\n issueDateFrom,\n issueDateTo,\n invoiceDirection,\n status,\n documentType,\n searchQuery,\n },\n )\n }\n\n /**\n * Retrieves notifications from the MyInvois platform based on specified search criteria.\n *\n * This method allows you to search for system notifications, alerts, and messages\n * sent by the MyInvois platform regarding document processing, system updates,\n * or account-related information.\n *\n * @param params - Search parameters object for filtering notifications\n * @param params.dateFrom - Optional start date for notification date range (ISO date string)\n * @param params.dateTo - Optional end date for notification date range (ISO date string)\n * @param params.type - Optional notification type filter\n * @param params.language - Optional language preference for notifications\n * @param params.status - Optional notification status filter\n * @param params.pageNo - Optional page number for pagination (0-based)\n * @param params.pageSize - Optional number of results per page\n * @returns Promise resolving to notification response object or standard error\n *\n * @example\n * ```typescript\n * // Get all notifications from the last 7 days\n * const notifications = await client.getNotifications({\n * dateFrom: '2024-01-01',\n * dateTo: '2024-01-07',\n * pageSize: 20\n * });\n *\n * // Get unread notifications only\n * const unreadNotifications = await client.getNotifications({\n * status: 0, // Assuming 0 = unread\n * language: 'en'\n * });\n *\n * // Paginated notification retrieval\n * const firstPage = await client.getNotifications({\n * dateFrom: '2024-01-01',\n * pageNo: 0,\n * pageSize: 10\n * });\n * ```\n *\n * @remarks\n * - All parameters are optional, allowing flexible filtering\n * - Returns paginated results when pageNo and pageSize are specified\n * - Date parameters should be in ISO format (YYYY-MM-DD)\n * - May return StandardError object if the request fails\n */\n async getNotifications({\n dateFrom,\n dateTo,\n type,\n language,\n status,\n pageNo,\n pageSize,\n }: NotificationSearchParams): Promise<NotificationResponse> {\n return NotificationManagementAPI.getNotifications(\n { fetch: this.fetch.bind(this) },\n {\n dateFrom,\n dateTo,\n type,\n language,\n status,\n pageNo,\n pageSize,\n },\n )\n }\n\n async getDocumentTypes(): Promise<DocumentTypesResponse> {\n return DocumentTypeManagementAPI.getDocumentTypes({\n fetch: this.fetch.bind(this),\n })\n }\n\n /**\n * Retrieves detailed information about a specific document type from the MyInvois platform.\n *\n * This method fetches metadata and configuration details for a specific document type,\n * including supported versions, validation rules, and structural requirements.\n * Useful for understanding document format requirements before submission.\n *\n * @param id - The unique identifier of the document type to retrieve\n * @returns Promise resolving to document type response object or standard error\n *\n * @example\n * ```typescript\n * // Get details for e-invoice document type\n * const invoiceType = await client.getDocumentType(1);\n * if ('id' in invoiceType) {\n * console.log('Document type name:', invoiceType.name);\n * console.log('Available versions:', invoiceType.versionNumber);\n * console.log('Description:', invoiceType.description);\n * }\n *\n * // Handle potential errors\n * const documentType = await client.getDocumentType(999);\n * if ('error' in documentType) {\n * console.error('Failed to retrieve document type:', documentType.error.message);\n * }\n * ```\n *\n * @remarks\n * - Returns StandardError object if the document type ID doesn't exist\n * - Document type information includes validation schemas and business rules\n * - Use this method to discover supported document formats and versions\n * - Essential for understanding submission requirements for different document types\n */\n async getDocumentType(id: number): Promise<DocumentTypeResponse> {\n return DocumentTypeManagementAPI.getDocumentType(\n { fetch: this.fetch.bind(this) },\n id,\n )\n }\n\n /**\n * Generates a shareable QR code URL for a specific document.\n *\n * This method retrieves the document details using its unique identifier,\n * then constructs a URL that can be used to access or share the document\n * via the MyInvois platform. The URL format differs between sandbox and\n * production environments.\n *\n * @param documentUid - The unique identifier of the document\n * @returns Promise resolving to a string containing the QR code URL\n *\n * @example\n * ```typescript\n * const qrCodeUrl = await client.getDocumentQrCode('abc123');\n * console.log('Shareable QR code URL:', qrCodeUrl);\n * // Output (sandbox): https://preprod.myinvois.hasil.gov.my/abc123/share/longId\n * // Output (production): https://myinvois.hasil.gov.my/abc123/share/longId\n * ```\n *\n * @remarks\n * - The returned URL can be embedded in a QR code for document sharing.\n * - The method fetches the document to obtain its longId, which is required for the URL.\n * - Ensure the documentUid is valid and accessible by the current client.\n */\n async getDocumentQrCode(documentUid: string): Promise<string> {\n const doc = await DocumentManagementAPI.getDocument(\n { fetch: this.fetch.bind(this) },\n documentUid,\n )\n\n console.log(doc)\n\n const qrCodeBaseLink = `https://${this.environment === 'sandbox' ? 'preprod.' : ''}myinvois.hasil.gov.my/`\n return qrCodeBaseLink + documentUid + '/share/' + doc.longId\n }\n\n /**\n * Retrieves detailed information about a specific version of a document type.\n *\n * This method fetches version-specific metadata, schema definitions, and validation rules\n * for a particular document type version. Essential for understanding the exact format\n * and requirements for document submission in a specific version.\n *\n * @param id - The unique identifier of the document type\n * @param versionId - The unique identifier of the specific version to retrieve\n * @returns Promise resolving to document type version response object or standard error\n *\n * @example\n * ```typescript\n * // Get specific version details for e-invoice\n * const invoiceV1_1 = await client.getDocumentTypeVersion(1, 1);\n * if ('id' in invoiceV1_1) {\n * console.log('Version number:', invoiceV1_1.versionNumber);\n * console.log('Schema:', invoiceV1_1.jsonSchema);\n * console.log('Status:', invoiceV1_1.status);\n * }\n *\n * // Compare different versions\n * const [v1_0, v1_1] = await Promise.all([\n * client.getDocumentTypeVersion(1, 0),\n * client.getDocumentTypeVersion(1, 1)\n * ]);\n *\n * // Handle version not found\n * const result = await client.getDocumentTypeVersion(1, 999);\n * if ('error' in result) {\n * console.error('Version not found:', result.error.message);\n * }\n * ```\n *\n * @remarks\n * - Returns StandardError object if document type ID or version ID doesn't exist\n * - Version information includes JSON schema for validation\n * - Different versions may have different validation rules and field requirements\n * - Use this to ensure your documents conform to the specific version requirements\n * - Version status indicates if the version is active, deprecated, or under development\n */\n async getDocumentTypeVersion(\n id: number,\n versionId: number,\n ): Promise<DocumentTypeVersionResponse> {\n return DocumentTypeManagementAPI.getDocumentTypeVersion(\n { fetch: this.fetch.bind(this) },\n id,\n versionId,\n )\n }\n\n // Static helper: create a client directly from a PKCS#12 (.p12) bundle\n static fromP12(\n clientId: string,\n clientSecret: string,\n environment: 'sandbox' | 'production',\n p12Input: Buffer | string,\n passphrase: string,\n onBehalfOf?: string,\n debug?: boolean,\n ): MyInvoisClient {\n const { certificatePem, privateKeyPem } = getPemFromP12(\n p12Input,\n passphrase,\n )\n\n return new MyInvoisClient(\n clientId,\n clientSecret,\n environment,\n certificatePem,\n privateKeyPem,\n onBehalfOf,\n debug,\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAqCA,IAAa,iBAAb,MAAa,eAAe;CAC1B,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAQ;CACR,AAAiB;CACjB,AAAiB;CACjB,AAAQ,QAAQ;CAChB,AAAQ;CAER,YACEA,UACAC,cACAC,aACAC,gBACAC,eACAC,YACAC,OACA;AAEA,OAAK,kBAAkB,eACrB,OAAM,IAAI,MACR;AAKJ,OAAK,oCAAgB,gBAAgB,cAAc,CACjD,OAAM,IAAI,MAAM;AAGlB,OAAK,WAAW;AAChB,OAAK,eAAe;AACpB,OAAK,UAAU,8BAAW,YAAY;AACtC,OAAK,cAAc;AACnB,OAAK,aAAa;AAClB,OAAK,QAAS,SAAS,QAAQ,IAAI,mBAAmB,SAAU,OAAO;EAGvE,MAAM,EAAE,YAAY,cAAc,GAAG,2CAAuB,eAAe;AAE3E,OAAK,qBAAqB;GACxB;GACA;GACA;GACA;EACD;CACF;CAED,MAAM,iBAAiBC,YAAmC;AACxD,OAAK,aAAa;AAClB,QAAM,KAAK,cAAc;AACzB;CACD;CAED,MAAc,eAAe;EAC3B,MAAM,gBAAgB,MAAM,oCAAc;GACxC,UAAU,KAAK;GACf,cAAc,KAAK;GACnB,SAAS,KAAK;GACd,YAAY,KAAK;GACjB,OAAO,K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;;;;;;;;;;;;;;;;;;;;;;;;CAmCD,MAAM,gBAAgBO,IAA2C;AAC/D,SAAO,+CACL,EAAE,OAAO,KAAK,MAAM,KAAK,KAAK,CAAE,GAChC,GACD;CACF;;;;;;;;;;;;;;;;;;;;;;;;;CA0BD,MAAM,kBAAkBP,aAAsC;EAC5D,MAAM,MAAM,MAAM,uCAChB,EAAE,OAAO,KAAK,MAAM,KAAK,KAAK,CAAE,GAChC,YACD;AAED,UAAQ,IAAI,IAAI;EAEhB,MAAM,kBAAkB,UAAU,KAAK,gBAAgB,YAAY,aAAa,GAAG;AACnF,SAAO,iBAAiB,cAAc,YAAY,IAAI;CACvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2CD,MAAM,uBACJO,IACAC,WACsC;AACtC,SAAO,sDACL,EAAE,OAAO,KAAK,MAAM,KAAK,KAAK,CAAE,GAChC,IACA,UACD;CACF;CAGD,OAAO,QACLvB,UACAC,cACAC,aACAsB,UACAC,YACApB,YACAC,OACgB;EAChB,MAAM,EAAE,gBAAgB,eAAe,GAAG,kCACxC,UACA,WACD;AAED,SAAO,IAAI,eACT,UACA,cACA,aACA,gBACA,eACA,YACA;CAEH;AACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -64,6 +64,7 @@ declare class MyInvoisClient {
|
|
|
64
64
|
private readonly baseUrl;
|
|
65
65
|
private readonly clientId;
|
|
66
66
|
private readonly clientSecret;
|
|
67
|
+
private readonly environment;
|
|
67
68
|
private onBehalfOf?;
|
|
68
69
|
private readonly signingCredentials;
|
|
69
70
|
private readonly debug;
|
|
@@ -479,6 +480,31 @@ declare class MyInvoisClient {
|
|
|
479
480
|
*/
|
|
480
481
|
getDocumentType(id: number): Promise<DocumentTypeResponse>;
|
|
481
482
|
/**
|
|
483
|
+
* Generates a shareable QR code URL for a specific document.
|
|
484
|
+
*
|
|
485
|
+
* This method retrieves the document details using its unique identifier,
|
|
486
|
+
* then constructs a URL that can be used to access or share the document
|
|
487
|
+
* via the MyInvois platform. The URL format differs between sandbox and
|
|
488
|
+
* production environments.
|
|
489
|
+
*
|
|
490
|
+
* @param documentUid - The unique identifier of the document
|
|
491
|
+
* @returns Promise resolving to a string containing the QR code URL
|
|
492
|
+
*
|
|
493
|
+
* @example
|
|
494
|
+
* ```typescript
|
|
495
|
+
* const qrCodeUrl = await client.getDocumentQrCode('abc123');
|
|
496
|
+
* console.log('Shareable QR code URL:', qrCodeUrl);
|
|
497
|
+
* // Output (sandbox): https://preprod.myinvois.hasil.gov.my/abc123/share/longId
|
|
498
|
+
* // Output (production): https://myinvois.hasil.gov.my/abc123/share/longId
|
|
499
|
+
* ```
|
|
500
|
+
*
|
|
501
|
+
* @remarks
|
|
502
|
+
* - The returned URL can be embedded in a QR code for document sharing.
|
|
503
|
+
* - The method fetches the document to obtain its longId, which is required for the URL.
|
|
504
|
+
* - Ensure the documentUid is valid and accessible by the current client.
|
|
505
|
+
*/
|
|
506
|
+
getDocumentQrCode(documentUid: string): Promise<string>;
|
|
507
|
+
/**
|
|
482
508
|
* Retrieves detailed information about a specific version of a document type.
|
|
483
509
|
*
|
|
484
510
|
* This method fetches version-specific metadata, schema definitions, and validation rules
|