@ripwords/myinvois-client 0.2.24 → 0.2.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/documentSubmission.js +1 -1
- package/dist/{documentSubmission-Dz1RhbtK.cjs → documentSubmission-DQy30z4E.cjs} +3 -3
- package/dist/documentSubmission-DQy30z4E.cjs.map +1 -0
- package/dist/{documentSubmission-CJQJAa4z.js → documentSubmission-DRbswZAD.js} +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index10.cjs +24 -4
- package/dist/index10.cjs.map +1 -0
- package/dist/index11.cjs +0 -22
- package/dist/index12.cjs +33 -2
- package/dist/{index26.cjs.map → index12.cjs.map} +1 -1
- package/dist/index13.cjs +23 -2
- package/dist/{index27.cjs.map → index13.cjs.map} +1 -1
- package/dist/index14.cjs +0 -330
- package/dist/index15.cjs +0 -193
- package/dist/index16.cjs +0 -62
- package/dist/index17.cjs +4 -531
- package/dist/index18.cjs +6 -195
- package/dist/index19.cjs +5 -0
- package/dist/index2.cjs +61 -4
- package/dist/index2.cjs.map +1 -0
- package/dist/index20.cjs +2 -24
- package/dist/index21.cjs +3 -0
- package/dist/index22.cjs +6 -0
- package/dist/index23.cjs +3 -28
- package/dist/index24.cjs +9 -21
- package/dist/index24.cjs.map +1 -1
- package/dist/index25.cjs +5 -0
- package/dist/index26.cjs +21 -33
- package/dist/index27.cjs +2 -23
- package/dist/index28.cjs +3 -0
- package/dist/index29.cjs +330 -0
- package/dist/{index14.cjs.map → index29.cjs.map} +1 -1
- package/dist/index3.cjs +531 -6
- package/dist/index3.cjs.map +1 -0
- package/dist/index30.cjs +193 -0
- package/dist/{index15.cjs.map → index30.cjs.map} +1 -1
- package/dist/index4.cjs +195 -4
- package/dist/index4.cjs.map +1 -0
- package/dist/index5.cjs +0 -3
- package/dist/index6.cjs +24 -2
- package/dist/index6.cjs.map +1 -0
- package/dist/index7.cjs +0 -6
- package/dist/index8.cjs +0 -4
- package/dist/index9.cjs +25 -9
- package/dist/index9.cjs.map +1 -1
- package/package.json +1 -1
- package/dist/documentSubmission-Dz1RhbtK.cjs.map +0 -1
- package/dist/index16.cjs.map +0 -1
- package/dist/index17.cjs.map +0 -1
- package/dist/index18.cjs.map +0 -1
- package/dist/index20.cjs.map +0 -1
- package/dist/index23.cjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../formatIdValue-qTxJqj9o.js";
|
|
2
2
|
import "../document-BbggZ72T.js";
|
|
3
|
-
import { getSubmissionStatus, performDocumentAction, submitDocument } from "../documentSubmission-
|
|
3
|
+
import { getSubmissionStatus, performDocumentAction, submitDocument } from "../documentSubmission-DRbswZAD.js";
|
|
4
4
|
|
|
5
5
|
export { getSubmissionStatus, performDocumentAction, submitDocument };
|
|
@@ -89,9 +89,9 @@ async function getSubmissionStatus(context, submissionUid, pollInterval = 1e3, m
|
|
|
89
89
|
return await getSubmissionStatus(context, submissionUid, pollInterval, maxRetries - 1);
|
|
90
90
|
}
|
|
91
91
|
return {
|
|
92
|
-
status: "TimedOut",
|
|
92
|
+
status: data.overallStatus || "TimedOut",
|
|
93
93
|
documentSummary: data.documentSummary,
|
|
94
|
-
error: {
|
|
94
|
+
error: data.error ?? {
|
|
95
95
|
code: "Timeout",
|
|
96
96
|
message: "Submission timed out",
|
|
97
97
|
target: "submission",
|
|
@@ -147,4 +147,4 @@ Object.defineProperty(exports, 'submitDocument', {
|
|
|
147
147
|
return submitDocument;
|
|
148
148
|
}
|
|
149
149
|
});
|
|
150
|
-
//# sourceMappingURL=documentSubmission-
|
|
150
|
+
//# sourceMappingURL=documentSubmission-DQy30z4E.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documentSubmission-DQy30z4E.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":"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"}
|
|
@@ -89,9 +89,9 @@ async function getSubmissionStatus(context, submissionUid, pollInterval = 1e3, m
|
|
|
89
89
|
return await getSubmissionStatus(context, submissionUid, pollInterval, maxRetries - 1);
|
|
90
90
|
}
|
|
91
91
|
return {
|
|
92
|
-
status: "TimedOut",
|
|
92
|
+
status: data.overallStatus || "TimedOut",
|
|
93
93
|
documentSummary: data.documentSummary,
|
|
94
|
-
error: {
|
|
94
|
+
error: data.error ?? {
|
|
95
95
|
code: "Timeout",
|
|
96
96
|
message: "Submission timed out",
|
|
97
97
|
target: "submission",
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_documentManagement = require('./documentManagement-DQ7JEcBq.cjs');
|
|
2
2
|
require('./formatIdValue-i67o4kyD.cjs');
|
|
3
3
|
require('./document-BWReWH1w.cjs');
|
|
4
|
-
const require_documentSubmission = require('./documentSubmission-
|
|
4
|
+
const require_documentSubmission = require('./documentSubmission-DQy30z4E.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');
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getDocument, getDocumentDetails, searchDocuments } from "./documentManagement-CIQPkmyb.js";
|
|
2
2
|
import "./formatIdValue-qTxJqj9o.js";
|
|
3
3
|
import "./document-BbggZ72T.js";
|
|
4
|
-
import { getSubmissionStatus, performDocumentAction, submitDocument } from "./documentSubmission-
|
|
4
|
+
import { getSubmissionStatus, performDocumentAction, submitDocument } from "./documentSubmission-DRbswZAD.js";
|
|
5
5
|
import { getDocumentType, getDocumentTypeVersion, getDocumentTypes } from "./documentTypeManagement-cBtVCOY3.js";
|
|
6
6
|
import { getNotifications } from "./notificationManagement-n4Z5e-My.js";
|
|
7
7
|
import { platformLogin } from "./platformLogin-CqI9OLYP.js";
|
package/dist/index10.cjs
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
|
-
const require_certificate = require('./certificate-CWmfCPdt.cjs');
|
|
2
1
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
//#region src/types/payment-modes.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Enum representing the allowed payment mode codes with descriptive names.
|
|
5
|
+
* Provides a more readable way to reference payment modes.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const mode = PaymentModeCodeEnum.Cash;
|
|
9
|
+
* console.log(mode); // Output: "01"
|
|
10
|
+
*/
|
|
11
|
+
let PaymentModeCodeEnum = /* @__PURE__ */ function(PaymentModeCodeEnum$1) {
|
|
12
|
+
PaymentModeCodeEnum$1["Cash"] = "01";
|
|
13
|
+
PaymentModeCodeEnum$1["Cheque"] = "02";
|
|
14
|
+
PaymentModeCodeEnum$1["BankTransfer"] = "03";
|
|
15
|
+
PaymentModeCodeEnum$1["CreditCard"] = "04";
|
|
16
|
+
PaymentModeCodeEnum$1["DebitCard"] = "05";
|
|
17
|
+
PaymentModeCodeEnum$1["EWalletDigitalWallet"] = "06";
|
|
18
|
+
PaymentModeCodeEnum$1["DigitalBank"] = "07";
|
|
19
|
+
PaymentModeCodeEnum$1["Others"] = "08";
|
|
20
|
+
return PaymentModeCodeEnum$1;
|
|
21
|
+
}({});
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.PaymentModeCodeEnum = PaymentModeCodeEnum;
|
|
25
|
+
//# sourceMappingURL=index10.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index10.cjs","names":[],"sources":["../src/types/payment-modes.d.ts"],"sourcesContent":["/**\n * Represents the allowed codes for payment modes.\n * Based on the documentation: https://sdk.myinvois.hasil.gov.my/codes/payment-methods/\n */\nexport type PaymentModeCode =\n | '01' // Cash\n | '02' // Cheque\n | '03' // Bank Transfer\n | '04' // Credit Card\n | '05' // Debit Card\n | '06' // e-Wallet / Digital Wallet\n | '07' // Digital Bank\n | '08' // Others\n\n/**\n * Enum representing the allowed payment mode codes with descriptive names.\n * Provides a more readable way to reference payment modes.\n *\n * @example\n * const mode = PaymentModeCodeEnum.Cash;\n * console.log(mode); // Output: \"01\"\n */\nexport enum PaymentModeCodeEnum {\n Cash = '01',\n Cheque = '02',\n BankTransfer = '03',\n CreditCard = '04',\n DebitCard = '05',\n EWalletDigitalWallet = '06',\n DigitalBank = '07',\n Others = '08',\n}\n\n/**\n * Interface representing a payment mode entry.\n * Contains the code and its corresponding description.\n */\nexport interface PaymentMode {\n code: PaymentModeCode\n description: string\n}\n"],"mappings":";;;;;;;;;;AAsBA,IAAY,sEAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACD"}
|
package/dist/index11.cjs
CHANGED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
require('./formatIdValue-i67o4kyD.cjs');
|
|
2
|
-
const require_document = require('./document-BWReWH1w.cjs');
|
|
3
|
-
|
|
4
|
-
exports.calculateCertificateDigest = require_document.calculateCertificateDigest;
|
|
5
|
-
exports.calculateDocumentDigest = require_document.calculateDocumentDigest;
|
|
6
|
-
exports.calculateExpectedTaxAmount = require_document.calculateExpectedTaxAmount;
|
|
7
|
-
exports.calculateInvoiceTotals = require_document.calculateInvoiceTotals;
|
|
8
|
-
exports.calculateSignedPropertiesDigest = require_document.calculateSignedPropertiesDigest;
|
|
9
|
-
exports.canonicalizeJSON = require_document.canonicalizeJSON;
|
|
10
|
-
exports.createFixedRateTaxLineItem = require_document.createFixedRateTaxLineItem;
|
|
11
|
-
exports.createPercentageTaxLineItem = require_document.createPercentageTaxLineItem;
|
|
12
|
-
exports.createSignedInfoAndSign = require_document.createSignedInfoAndSign;
|
|
13
|
-
exports.createSignedProperties = require_document.createSignedProperties;
|
|
14
|
-
exports.extractCertificateInfo = require_document.extractCertificateInfo;
|
|
15
|
-
exports.generateCleanInvoiceObject = require_document.generateCleanInvoiceObject;
|
|
16
|
-
exports.generateCleanUBLDocument = require_document.generateCleanUBLDocument;
|
|
17
|
-
exports.generateCompleteDocument = require_document.generateCompleteDocument;
|
|
18
|
-
exports.isFixedRateTax = require_document.isFixedRateTax;
|
|
19
|
-
exports.isPercentageTax = require_document.isPercentageTax;
|
|
20
|
-
exports.signDocumentString = require_document.signDocumentString;
|
|
21
|
-
exports.sortObjectKeys = require_document.sortObjectKeys;
|
|
22
|
-
exports.transformDocumentForHashing = require_document.transformDocumentForHashing;
|
package/dist/index12.cjs
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
-
const require_formatIdValue = require('./formatIdValue-i67o4kyD.cjs');
|
|
2
1
|
|
|
3
|
-
|
|
2
|
+
//#region src/types/state-codes.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Enum representing the allowed state codes with descriptive names.
|
|
5
|
+
* Provides a more readable way to reference states.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const code = StateCodeEnum.Selangor;
|
|
9
|
+
* console.log(code); // Output: "10"
|
|
10
|
+
*/
|
|
11
|
+
let StateCodeEnum = /* @__PURE__ */ function(StateCodeEnum$1) {
|
|
12
|
+
StateCodeEnum$1["Johor"] = "01";
|
|
13
|
+
StateCodeEnum$1["Kedah"] = "02";
|
|
14
|
+
StateCodeEnum$1["Kelantan"] = "03";
|
|
15
|
+
StateCodeEnum$1["Melaka"] = "04";
|
|
16
|
+
StateCodeEnum$1["NegeriSembilan"] = "05";
|
|
17
|
+
StateCodeEnum$1["Pahang"] = "06";
|
|
18
|
+
StateCodeEnum$1["PulauPinang"] = "07";
|
|
19
|
+
StateCodeEnum$1["Perak"] = "08";
|
|
20
|
+
StateCodeEnum$1["Perlis"] = "09";
|
|
21
|
+
StateCodeEnum$1["Selangor"] = "10";
|
|
22
|
+
StateCodeEnum$1["Terengganu"] = "11";
|
|
23
|
+
StateCodeEnum$1["Sabah"] = "12";
|
|
24
|
+
StateCodeEnum$1["Sarawak"] = "13";
|
|
25
|
+
StateCodeEnum$1["WPKualaLumpur"] = "14";
|
|
26
|
+
StateCodeEnum$1["WPLabuan"] = "15";
|
|
27
|
+
StateCodeEnum$1["WPPutrajaya"] = "16";
|
|
28
|
+
StateCodeEnum$1["NotApplicable"] = "17";
|
|
29
|
+
return StateCodeEnum$1;
|
|
30
|
+
}({});
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
exports.StateCodeEnum = StateCodeEnum;
|
|
34
|
+
//# sourceMappingURL=index12.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"index12.cjs","names":[],"sources":["../src/types/state-codes.d.ts"],"sourcesContent":["/**\n * Represents the allowed codes for Malaysian states and federal territories.\n * Based on the documentation: https://sdk.myinvois.hasil.gov.my/codes/state-codes/\n */\nexport type StateCode =\n | '01' // Johor\n | '02' // Kedah\n | '03' // Kelantan\n | '04' // Melaka\n | '05' // Negeri Sembilan\n | '06' // Pahang\n | '07' // Pulau Pinang\n | '08' // Perak\n | '09' // Perlis\n | '10' // Selangor\n | '11' // Terengganu\n | '12' // Sabah\n | '13' // Sarawak\n | '14' // Wilayah Persekutuan Kuala Lumpur\n | '15' // Wilayah Persekutuan Labuan\n | '16' // Wilayah Persekutuan Putrajaya\n | '17' // Not Applicable\n\n/**\n * Enum representing the allowed state codes with descriptive names.\n * Provides a more readable way to reference states.\n *\n * @example\n * const code = StateCodeEnum.Selangor;\n * console.log(code); // Output: \"10\"\n */\nexport enum StateCodeEnum {\n Johor = '01',\n Kedah = '02',\n Kelantan = '03',\n Melaka = '04',\n NegeriSembilan = '05',\n Pahang = '06',\n PulauPinang = '07',\n Perak = '08',\n Perlis = '09',\n Selangor = '10',\n Terengganu = '11',\n Sabah = '12',\n Sarawak = '13',\n WPKualaLumpur = '14',\n WPLabuan = '15',\n WPPutrajaya = '16',\n NotApplicable = '17',\n}\n\n/**\n * Interface representing a state code entry.\n * Contains the code and its corresponding name.\n */\nexport interface State {\n code: StateCode\n name: string\n}\n"],"mappings":";;;;;;;;;;AA+BA,IAAY,0DAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACD"}
|
package/dist/index13.cjs
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
-
const require_getBaseUrl = require('./getBaseUrl-D0G4GZmp.cjs');
|
|
2
1
|
|
|
3
|
-
|
|
2
|
+
//#region src/types/tax-types.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Enum representing the allowed tax type codes with descriptive names.
|
|
5
|
+
* Provides a more readable way to reference tax types.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const code = TaxTypeCodeEnum.SalesTax;
|
|
9
|
+
* console.log(code); // Output: "01"
|
|
10
|
+
*/
|
|
11
|
+
let TaxTypeCodeEnum = /* @__PURE__ */ function(TaxTypeCodeEnum$1) {
|
|
12
|
+
TaxTypeCodeEnum$1["SalesTax"] = "01";
|
|
13
|
+
TaxTypeCodeEnum$1["ServiceTax"] = "02";
|
|
14
|
+
TaxTypeCodeEnum$1["TourismTax"] = "03";
|
|
15
|
+
TaxTypeCodeEnum$1["HighValueGoodsTax"] = "04";
|
|
16
|
+
TaxTypeCodeEnum$1["SalesTaxLowValueGoods"] = "05";
|
|
17
|
+
TaxTypeCodeEnum$1["NotApplicable"] = "06";
|
|
18
|
+
TaxTypeCodeEnum$1["TaxExemption"] = "E";
|
|
19
|
+
return TaxTypeCodeEnum$1;
|
|
20
|
+
}({});
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.TaxTypeCodeEnum = TaxTypeCodeEnum;
|
|
24
|
+
//# sourceMappingURL=index13.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"index13.cjs","names":[],"sources":["../src/types/tax-types.d.ts"],"sourcesContent":["/**\n * Represents the allowed codes for tax types.\n * Based on the documentation: https://sdk.myinvois.hasil.gov.my/codes/tax-types/\n */\nexport type TaxTypeCode =\n | '01' // Sales Tax\n | '02' // Service Tax\n | '03' // Tourism Tax\n | '04' // High-Value Goods Tax\n | '05' // Sales Tax on Low Value Goods\n | '06' // Not Applicable\n | 'E' // Tax exemption (where applicable)\n\n/**\n * Enum representing the allowed tax type codes with descriptive names.\n * Provides a more readable way to reference tax types.\n *\n * @example\n * const code = TaxTypeCodeEnum.SalesTax;\n * console.log(code); // Output: \"01\"\n */\nexport enum TaxTypeCodeEnum {\n SalesTax = '01',\n ServiceTax = '02',\n TourismTax = '03',\n HighValueGoodsTax = '04',\n SalesTaxLowValueGoods = '05',\n NotApplicable = '06',\n TaxExemption = 'E',\n}\n\n/**\n * Interface representing a tax type entry.\n * Contains the code and its corresponding description.\n */\nexport interface TaxType {\n code: TaxTypeCode\n description: string\n}\n"],"mappings":";;;;;;;;;;AAqBA,IAAY,8DAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;;AACD"}
|
package/dist/index14.cjs
CHANGED
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
require('./formatIdValue-i67o4kyD.cjs');
|
|
3
|
-
const require_document = require('./document-BWReWH1w.cjs');
|
|
4
|
-
const crypto = require_chunk.__toESM(require("crypto"));
|
|
5
|
-
|
|
6
|
-
//#region src/utils/signature-diagnostics.ts
|
|
7
|
-
/**
|
|
8
|
-
* Analyzes certificate for MyInvois compatibility issues
|
|
9
|
-
*/
|
|
10
|
-
function analyzeCertificateForDiagnostics(certificatePem) {
|
|
11
|
-
const issues = [];
|
|
12
|
-
const recommendations = [];
|
|
13
|
-
try {
|
|
14
|
-
const cert = new crypto.default.X509Certificate(certificatePem);
|
|
15
|
-
const certInfo = require_document.extractCertificateInfo(certificatePem);
|
|
16
|
-
const parseSubjectFields = (dn) => {
|
|
17
|
-
const fields = {};
|
|
18
|
-
dn.split("\n").forEach((line) => {
|
|
19
|
-
const trimmed = line.trim();
|
|
20
|
-
if (trimmed.includes("=")) {
|
|
21
|
-
const [key, ...valueParts] = trimmed.split("=");
|
|
22
|
-
if (key) fields[key.trim()] = valueParts.join("=").trim();
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
return fields;
|
|
26
|
-
};
|
|
27
|
-
const subjectFields = parseSubjectFields(cert.subject);
|
|
28
|
-
const organizationIdentifier = subjectFields["organizationIdentifier"] || subjectFields["2.5.4.97"];
|
|
29
|
-
const serialNumber = subjectFields["serialNumber"];
|
|
30
|
-
if (!organizationIdentifier) {
|
|
31
|
-
issues.push("DS311: Certificate missing organizationIdentifier field (TIN)");
|
|
32
|
-
recommendations.push("CRITICAL: Generate new certificate with organizationIdentifier matching your MyInvois TIN");
|
|
33
|
-
recommendations.push("Portal Error: \"Signer of invoice doesn't match the submitter of document. TIN doesn't match with the OI.\"");
|
|
34
|
-
} else if (organizationIdentifier.length < 10) {
|
|
35
|
-
issues.push("DS311: OrganizationIdentifier (TIN) appears too short - may cause submission rejection");
|
|
36
|
-
recommendations.push("Verify TIN format matches exactly what is registered in MyInvois");
|
|
37
|
-
}
|
|
38
|
-
if (!serialNumber) {
|
|
39
|
-
issues.push("DS312: Certificate missing serialNumber field (business registration)");
|
|
40
|
-
recommendations.push("CRITICAL: Generate new certificate with serialNumber matching your business registration");
|
|
41
|
-
recommendations.push("Portal Error: \"Submitter registration/identity number doesn't match with the certificate SERIALNUMBER.\"");
|
|
42
|
-
}
|
|
43
|
-
if (cert.issuer === cert.subject) {
|
|
44
|
-
issues.push("DS329: Self-signed certificate detected - will fail chain of trust validation");
|
|
45
|
-
recommendations.push("BLOCKING: Obtain certificate from MyInvois-approved CA:");
|
|
46
|
-
recommendations.push("• MSC Trustgate Sdn Bhd");
|
|
47
|
-
recommendations.push("• DigiCert Sdn Bhd");
|
|
48
|
-
recommendations.push("• Cybersign Asia Sdn Bhd");
|
|
49
|
-
recommendations.push("Portal Error: \"Certificate is not valid according to the chain of trust validation or has been issued by an untrusted certificate authority.\"");
|
|
50
|
-
} else {
|
|
51
|
-
const issuerName = cert.issuer.toLowerCase();
|
|
52
|
-
const approvedCAs = [
|
|
53
|
-
"msc trustgate",
|
|
54
|
-
"digicert",
|
|
55
|
-
"cybersign"
|
|
56
|
-
];
|
|
57
|
-
const isFromApprovedCA = approvedCAs.some((ca) => issuerName.includes(ca));
|
|
58
|
-
if (!isFromApprovedCA) {
|
|
59
|
-
issues.push("DS329: Certificate may not be from MyInvois-approved CA");
|
|
60
|
-
recommendations.push("Verify certificate was issued by an approved CA for MyInvois");
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
const rawIssuer = cert.issuer;
|
|
64
|
-
const normalizedIssuer = certInfo.issuerName;
|
|
65
|
-
const normalizedIssuerIssues = [
|
|
66
|
-
{
|
|
67
|
-
check: normalizedIssuer.includes("\n"),
|
|
68
|
-
issue: "Normalized issuer still contains newlines"
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
check: normalizedIssuer.includes(" "),
|
|
72
|
-
issue: "Normalized issuer contains double spaces"
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
check: /=\s+/.test(normalizedIssuer),
|
|
76
|
-
issue: "Normalized issuer has spaces after equals"
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
check: /\s+=/.test(normalizedIssuer),
|
|
80
|
-
issue: "Normalized issuer has spaces before equals"
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
check: normalizedIssuer.includes("\r"),
|
|
84
|
-
issue: "Normalized issuer contains carriage returns"
|
|
85
|
-
}
|
|
86
|
-
];
|
|
87
|
-
const hasActualFormatIssues = normalizedIssuerIssues.some(({ check, issue }) => {
|
|
88
|
-
if (check) {
|
|
89
|
-
issues.push(`DS326: ${issue} - will cause X509IssuerName mismatch`);
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
return false;
|
|
93
|
-
});
|
|
94
|
-
const hasRawIssuesButNormalizedOk = rawIssuer.includes("\n") && !normalizedIssuer.includes("\n");
|
|
95
|
-
if (hasActualFormatIssues) {
|
|
96
|
-
recommendations.push("CRITICAL: Fix issuer name normalization in signature generation");
|
|
97
|
-
recommendations.push("Portal Error: \"Certificate X509IssuerName doesn't match the X509IssuerName value provided in the signed properties section.\"");
|
|
98
|
-
recommendations.push("The normalization function is not properly formatting the issuer name");
|
|
99
|
-
recommendations.push("Debug: Check document.ts extractCertificateInfo() normalization logic");
|
|
100
|
-
} else if (hasRawIssuesButNormalizedOk) console.log("ℹ️ Note: Raw certificate issuer has newlines but normalization is handling them correctly");
|
|
101
|
-
const now = /* @__PURE__ */ new Date();
|
|
102
|
-
const validFrom = new Date(cert.validFrom);
|
|
103
|
-
const validTo = new Date(cert.validTo);
|
|
104
|
-
if (now < validFrom) {
|
|
105
|
-
issues.push("DS329: Certificate not yet valid (future start date)");
|
|
106
|
-
recommendations.push("Wait until certificate validity period begins");
|
|
107
|
-
}
|
|
108
|
-
if (now > validTo) {
|
|
109
|
-
issues.push("DS329: Certificate has expired");
|
|
110
|
-
recommendations.push("BLOCKING: Renew certificate - expired certificates are rejected");
|
|
111
|
-
}
|
|
112
|
-
try {
|
|
113
|
-
if (cert.keyUsage && !cert.keyUsage.includes("digital signature")) {
|
|
114
|
-
issues.push("DS333: Certificate lacks digitalSignature key usage");
|
|
115
|
-
recommendations.push("Generate new certificate with digitalSignature key usage enabled");
|
|
116
|
-
}
|
|
117
|
-
} catch {
|
|
118
|
-
console.log("Note: Could not check key usage extensions");
|
|
119
|
-
}
|
|
120
|
-
return {
|
|
121
|
-
organizationIdentifier,
|
|
122
|
-
serialNumber,
|
|
123
|
-
issuerName: certInfo.issuerName,
|
|
124
|
-
subjectName: certInfo.subjectName,
|
|
125
|
-
issues,
|
|
126
|
-
recommendations
|
|
127
|
-
};
|
|
128
|
-
} catch (error) {
|
|
129
|
-
issues.push(`Certificate parsing failed: ${error}`);
|
|
130
|
-
recommendations.push("Verify certificate format and validity");
|
|
131
|
-
return {
|
|
132
|
-
issuerName: "",
|
|
133
|
-
subjectName: "",
|
|
134
|
-
issues,
|
|
135
|
-
recommendations
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Analyzes signature generation for potential issues
|
|
141
|
-
*/
|
|
142
|
-
function analyzeSignatureForDiagnostics(invoices, certificatePem) {
|
|
143
|
-
const issues = [];
|
|
144
|
-
const recommendations = [];
|
|
145
|
-
try {
|
|
146
|
-
const documentDigest = require_document.calculateDocumentDigest(invoices);
|
|
147
|
-
const certificateDigest = require_document.calculateCertificateDigest(certificatePem);
|
|
148
|
-
const certInfo = require_document.extractCertificateInfo(certificatePem);
|
|
149
|
-
const signingTime = (/* @__PURE__ */ new Date()).toISOString();
|
|
150
|
-
const signedProperties = require_document.createSignedProperties(certificateDigest, signingTime, certInfo.issuerName, certInfo.serialNumber);
|
|
151
|
-
const signedPropertiesDigest = require_document.calculateSignedPropertiesDigest(signedProperties);
|
|
152
|
-
if (documentDigest.length === 0) {
|
|
153
|
-
issues.push("DS333: Document digest generation failed");
|
|
154
|
-
recommendations.push("CRITICAL: Verify document serialization excludes UBLExtensions/Signature");
|
|
155
|
-
recommendations.push("Portal Error: \"Document signature value is not a valid signature of the document digest using the public key of the certificate provided.\"");
|
|
156
|
-
}
|
|
157
|
-
if (certificateDigest.length === 0) {
|
|
158
|
-
issues.push("DS333: Certificate digest generation failed");
|
|
159
|
-
recommendations.push("CRITICAL: Verify certificate format and encoding");
|
|
160
|
-
recommendations.push("Certificate must be properly base64 encoded without headers/footers");
|
|
161
|
-
}
|
|
162
|
-
if (signedPropertiesDigest.length === 0) {
|
|
163
|
-
issues.push("DS333: Signed properties digest generation failed");
|
|
164
|
-
recommendations.push("CRITICAL: Verify signed properties structure and canonicalization");
|
|
165
|
-
recommendations.push("Check XML canonicalization (C14N) is applied correctly");
|
|
166
|
-
}
|
|
167
|
-
try {
|
|
168
|
-
const cert = new crypto.default.X509Certificate(certificatePem);
|
|
169
|
-
const publicKey = cert.publicKey;
|
|
170
|
-
const keyDetails = publicKey.asymmetricKeyDetails;
|
|
171
|
-
if (keyDetails) {
|
|
172
|
-
if (publicKey.asymmetricKeyType === "rsa" && keyDetails.modulusLength && keyDetails.modulusLength < 2048) {
|
|
173
|
-
issues.push("DS333: RSA key size too small (minimum 2048 bits required)");
|
|
174
|
-
recommendations.push("CRITICAL: Generate new certificate with RSA 2048+ bits");
|
|
175
|
-
}
|
|
176
|
-
const supportedKeyTypes = ["rsa", "ec"];
|
|
177
|
-
if (!supportedKeyTypes.includes(publicKey.asymmetricKeyType || "")) {
|
|
178
|
-
issues.push(`DS333: Unsupported key type: ${publicKey.asymmetricKeyType}`);
|
|
179
|
-
recommendations.push("CRITICAL: Use RSA or EC key types for MyInvois compatibility");
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
const certBuffer = Buffer.from(certificatePem.replace(/-----[^-]+-----/g, "").replace(/\s/g, ""), "base64");
|
|
183
|
-
if (certBuffer.length === 0) {
|
|
184
|
-
issues.push("DS333: Certificate encoding appears invalid");
|
|
185
|
-
recommendations.push("CRITICAL: Verify certificate is properly PEM encoded");
|
|
186
|
-
}
|
|
187
|
-
} catch (error) {
|
|
188
|
-
issues.push(`DS333: Certificate validation failed - ${error}`);
|
|
189
|
-
recommendations.push("CRITICAL: Verify certificate format and structure are valid");
|
|
190
|
-
}
|
|
191
|
-
const isValidBase64 = (str) => {
|
|
192
|
-
try {
|
|
193
|
-
return Buffer.from(str, "base64").toString("base64") === str;
|
|
194
|
-
} catch {
|
|
195
|
-
return false;
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
if (documentDigest && !isValidBase64(documentDigest)) {
|
|
199
|
-
issues.push("DS333: Document digest is not valid base64 format");
|
|
200
|
-
recommendations.push("Ensure digest is properly base64 encoded");
|
|
201
|
-
}
|
|
202
|
-
if (certificateDigest && !isValidBase64(certificateDigest)) {
|
|
203
|
-
issues.push("DS333: Certificate digest is not valid base64 format");
|
|
204
|
-
recommendations.push("Ensure certificate digest is properly base64 encoded");
|
|
205
|
-
}
|
|
206
|
-
if (signedPropertiesDigest && !isValidBase64(signedPropertiesDigest)) {
|
|
207
|
-
issues.push("DS333: Signed properties digest is not valid base64 format");
|
|
208
|
-
recommendations.push("Ensure signed properties digest is properly base64 encoded");
|
|
209
|
-
}
|
|
210
|
-
return {
|
|
211
|
-
documentDigest,
|
|
212
|
-
certificateDigest,
|
|
213
|
-
signedPropertiesDigest,
|
|
214
|
-
issues,
|
|
215
|
-
recommendations
|
|
216
|
-
};
|
|
217
|
-
} catch (error) {
|
|
218
|
-
issues.push(`Signature analysis failed: ${error}`);
|
|
219
|
-
recommendations.push("Review signature generation implementation");
|
|
220
|
-
return {
|
|
221
|
-
documentDigest: "",
|
|
222
|
-
certificateDigest: "",
|
|
223
|
-
signedPropertiesDigest: "",
|
|
224
|
-
issues,
|
|
225
|
-
recommendations
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Comprehensive signature diagnostics
|
|
231
|
-
*/
|
|
232
|
-
function diagnoseSignatureIssues(invoices, certificatePem) {
|
|
233
|
-
const certificateAnalysis = analyzeCertificateForDiagnostics(certificatePem);
|
|
234
|
-
const signatureAnalysis = analyzeSignatureForDiagnostics(invoices, certificatePem);
|
|
235
|
-
const certificateIssues = certificateAnalysis.issues.length;
|
|
236
|
-
const signatureIssues = signatureAnalysis.issues.length;
|
|
237
|
-
return {
|
|
238
|
-
certificateAnalysis,
|
|
239
|
-
signatureAnalysis,
|
|
240
|
-
summary: {
|
|
241
|
-
totalIssues: certificateIssues + signatureIssues,
|
|
242
|
-
certificateIssues,
|
|
243
|
-
signatureIssues
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Prints diagnostic results in a formatted way
|
|
249
|
-
*/
|
|
250
|
-
function printDiagnostics(result) {
|
|
251
|
-
console.log("\n🔍 MyInvois Signature Diagnostics Report");
|
|
252
|
-
console.log("=".repeat(60));
|
|
253
|
-
console.log("\n📜 CERTIFICATE ANALYSIS");
|
|
254
|
-
console.log("-".repeat(30));
|
|
255
|
-
console.log(` Issuer: ${result.certificateAnalysis.issuerName}`);
|
|
256
|
-
console.log(` Subject: ${result.certificateAnalysis.subjectName}`);
|
|
257
|
-
if (result.certificateAnalysis.organizationIdentifier) console.log(` Organization ID (TIN): ${result.certificateAnalysis.organizationIdentifier}`);
|
|
258
|
-
if (result.certificateAnalysis.serialNumber) console.log(` Serial Number: ${result.certificateAnalysis.serialNumber}`);
|
|
259
|
-
if (result.certificateAnalysis.issues.length > 0) {
|
|
260
|
-
console.log("\n 🚨 Certificate Issues:");
|
|
261
|
-
result.certificateAnalysis.issues.forEach((issue, index) => {
|
|
262
|
-
console.log(` ${index + 1}. ${issue}`);
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
if (result.certificateAnalysis.recommendations.length > 0) {
|
|
266
|
-
console.log("\n 💡 Certificate Recommendations:");
|
|
267
|
-
result.certificateAnalysis.recommendations.forEach((rec, index) => {
|
|
268
|
-
console.log(` ${index + 1}. ${rec}`);
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
console.log("\n🔐 SIGNATURE ANALYSIS");
|
|
272
|
-
console.log("-".repeat(30));
|
|
273
|
-
console.log(` Document Digest: ${result.signatureAnalysis.documentDigest.substring(0, 32)}...`);
|
|
274
|
-
console.log(` Certificate Digest: ${result.signatureAnalysis.certificateDigest.substring(0, 32)}...`);
|
|
275
|
-
console.log(` Signed Properties Digest: ${result.signatureAnalysis.signedPropertiesDigest.substring(0, 32)}...`);
|
|
276
|
-
if (result.signatureAnalysis.issues.length > 0) {
|
|
277
|
-
console.log("\n 🚨 Signature Issues:");
|
|
278
|
-
result.signatureAnalysis.issues.forEach((issue, index) => {
|
|
279
|
-
console.log(` ${index + 1}. ${issue}`);
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
if (result.signatureAnalysis.recommendations.length > 0) {
|
|
283
|
-
console.log("\n 💡 Signature Recommendations:");
|
|
284
|
-
result.signatureAnalysis.recommendations.forEach((rec, index) => {
|
|
285
|
-
console.log(` ${index + 1}. ${rec}`);
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
console.log("\n📊 SUMMARY");
|
|
289
|
-
console.log("-".repeat(30));
|
|
290
|
-
console.log(` Total Issues Found: ${result.summary.totalIssues}`);
|
|
291
|
-
console.log(` Certificate Issues: ${result.summary.certificateIssues}`);
|
|
292
|
-
console.log(` Signature Issues: ${result.summary.signatureIssues}`);
|
|
293
|
-
if (result.summary.totalIssues === 0) {
|
|
294
|
-
console.log("\n ✅ No issues detected in current analysis");
|
|
295
|
-
console.log(" 🎉 Certificate and signature implementation appear valid");
|
|
296
|
-
} else {
|
|
297
|
-
console.log("\n ⚠️ Issues detected - review recommendations above");
|
|
298
|
-
const hasDS311 = result.certificateAnalysis.issues.some((issue) => issue.includes("DS311"));
|
|
299
|
-
const hasDS312 = result.certificateAnalysis.issues.some((issue) => issue.includes("DS312"));
|
|
300
|
-
const hasDS326 = result.certificateAnalysis.issues.some((issue) => issue.includes("DS326"));
|
|
301
|
-
const hasDS329 = result.certificateAnalysis.issues.some((issue) => issue.includes("DS329"));
|
|
302
|
-
const hasDS333 = result.signatureAnalysis.issues.some((issue) => issue.includes("DS333"));
|
|
303
|
-
console.log("\n 🎯 MYINVOIS PORTAL ERROR ANALYSIS:");
|
|
304
|
-
if (hasDS311) console.log(" ❌ DS311 - TIN mismatch between certificate and submitter");
|
|
305
|
-
if (hasDS312) console.log(" ❌ DS312 - Registration number mismatch with certificate");
|
|
306
|
-
if (hasDS326) console.log(" ❌ DS326 - X509IssuerName format inconsistency");
|
|
307
|
-
if (hasDS329) console.log(" ❌ DS329 - Certificate trust chain validation failure");
|
|
308
|
-
if (hasDS333) console.log(" ❌ DS333 - Document signature validation failure");
|
|
309
|
-
if (result.summary.certificateIssues > 0) {
|
|
310
|
-
console.log("\n 🚨 PRIMARY ACTION REQUIRED:");
|
|
311
|
-
console.log(" Certificate issues must be resolved first");
|
|
312
|
-
console.log(" Self-generated certificates cannot pass MyInvois validation");
|
|
313
|
-
}
|
|
314
|
-
if (result.summary.signatureIssues > 0) {
|
|
315
|
-
console.log("\n ⚙️ SECONDARY ACTION:");
|
|
316
|
-
console.log(" Review and optimize signature implementation");
|
|
317
|
-
}
|
|
318
|
-
console.log("\n 📋 NEXT STEPS:");
|
|
319
|
-
console.log(" 1. Address BLOCKING/CRITICAL issues first");
|
|
320
|
-
console.log(" 2. Test with updated certificate/implementation");
|
|
321
|
-
console.log(" 3. Re-run diagnostics to verify fixes");
|
|
322
|
-
console.log(" 4. Submit test document to MyInvois portal");
|
|
323
|
-
}
|
|
324
|
-
console.log("\n" + "=".repeat(60));
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
//#endregion
|
|
328
|
-
exports.diagnoseSignatureIssues = diagnoseSignatureIssues;
|
|
329
|
-
exports.printDiagnostics = printDiagnostics;
|
|
330
|
-
//# sourceMappingURL=index14.cjs.map
|