@ripwords/myinvois-client 0.1.6 → 0.1.7
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/package.json +5 -8
- package/.prettierrc +0 -8
- package/CHANGELOG.md +0 -152
- package/bun.lock +0 -460
- package/myinvois-cert.conf.template +0 -23
- package/scripts/gen-cert.sh +0 -159
- package/src/api/platform/platformLogin.ts +0 -34
- package/src/index.ts +0 -530
- package/src/types/classification-codes.d.ts +0 -115
- package/src/types/country-code.d.ts +0 -790
- package/src/types/currencies.d.ts +0 -383
- package/src/types/documents.d.ts +0 -869
- package/src/types/e-invoice.d.ts +0 -41
- package/src/types/index.d.ts +0 -24
- package/src/types/msic/0X.d.ts +0 -408
- package/src/types/msic/1X.d.ts +0 -210
- package/src/types/msic/2X.d.ts +0 -266
- package/src/types/msic/3X.d.ts +0 -114
- package/src/types/msic/4X.d.ts +0 -520
- package/src/types/msic/5X.d.ts +0 -144
- package/src/types/msic/6X.d.ts +0 -200
- package/src/types/msic/7X.d.ts +0 -132
- package/src/types/msic/8X.d.ts +0 -210
- package/src/types/msic/9X.d.ts +0 -186
- package/src/types/msic-codes.d.ts +0 -31
- package/src/types/payment-modes.d.ts +0 -41
- package/src/types/signatures.d.ts +0 -169
- package/src/types/state-codes.d.ts +0 -59
- package/src/types/tax-types.d.ts +0 -39
- package/src/types/unit/1X.d.ts +0 -16
- package/src/types/unit/2X.d.ts +0 -62
- package/src/types/unit/3X.d.ts +0 -17
- package/src/types/unit/4X.d.ts +0 -44
- package/src/types/unit/5X.d.ts +0 -26
- package/src/types/unit/6X.d.ts +0 -12
- package/src/types/unit/7X.d.ts +0 -12
- package/src/types/unit/8X.d.ts +0 -15
- package/src/types/unit/9X.d.ts +0 -11
- package/src/types/unit/AX.d.ts +0 -202
- package/src/types/unit/BX.d.ts +0 -212
- package/src/types/unit/CX.d.ts +0 -238
- package/src/types/unit/DX.d.ts +0 -212
- package/src/types/unit/EX.d.ts +0 -196
- package/src/types/unit/FX.d.ts +0 -236
- package/src/types/unit/GX.d.ts +0 -254
- package/src/types/unit/HX.d.ts +0 -234
- package/src/types/unit/IX.d.ts +0 -28
- package/src/types/unit/JX.d.ts +0 -190
- package/src/types/unit/KX.d.ts +0 -284
- package/src/types/unit/LX.d.ts +0 -228
- package/src/types/unit/MX.d.ts +0 -288
- package/src/types/unit/NX.d.ts +0 -226
- package/src/types/unit/OX.d.ts +0 -34
- package/src/types/unit/PX.d.ts +0 -224
- package/src/types/unit/QX.d.ts +0 -94
- package/src/types/unit/RX.d.ts +0 -28
- package/src/types/unit/SX.d.ts +0 -56
- package/src/types/unit/TX.d.ts +0 -44
- package/src/types/unit/UX.d.ts +0 -14
- package/src/types/unit/VX.d.ts +0 -13
- package/src/types/unit/WX.d.ts +0 -34
- package/src/types/unit/XX.d.ts +0 -825
- package/src/types/unit/YX.d.ts +0 -17
- package/src/types/unit/ZX.d.ts +0 -19
- package/src/types/unit-types.d.ts +0 -86
- package/src/utils/base64.ts +0 -7
- package/src/utils/certificate.ts +0 -60
- package/src/utils/document.ts +0 -852
- package/src/utils/getBaseUrl.ts +0 -5
- package/src/utils/helpers.ts +0 -552
- package/src/utils/signature-diagnostics.ts +0 -583
- package/src/utils/validation.ts +0 -268
- package/test/MyInvoiClientWithRealData.test.ts +0 -40
- package/test/MyInvoisClient.test.ts +0 -204
- package/test/base64.test.ts +0 -43
- package/test/dynamicInvoiceFeatures.test.ts +0 -451
- package/test/signAndSubmitInvoice.test.ts +0 -452
- package/test/signature-diagnostics.test.ts +0 -130
- package/tsconfig.json +0 -39
- package/tsdown.config.ts +0 -31
- package/vitest.config.ts +0 -8
package/src/types/unit/YX.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit types starting with Y
|
|
3
|
-
* https://sdk.myinvois.hasil.gov.my/codes/unit-types/
|
|
4
|
-
*/
|
|
5
|
-
export type UnitTypeCode_YX =
|
|
6
|
-
| 'YDK' // square yard
|
|
7
|
-
| 'YDQ' // cubic yard
|
|
8
|
-
| 'YRD' // yard
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Enum representing unit type codes starting with 'Y'.
|
|
12
|
-
*/
|
|
13
|
-
export enum UnitTypeCodeEnum_YX {
|
|
14
|
-
SquareYard = 'YDK',
|
|
15
|
-
CubicYard = 'YDQ',
|
|
16
|
-
Yard = 'YRD',
|
|
17
|
-
}
|
package/src/types/unit/ZX.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit types starting with Z
|
|
3
|
-
* https://sdk.myinvois.hasil.gov.my/codes/unit-types/
|
|
4
|
-
*/
|
|
5
|
-
export type UnitTypeCode_ZX =
|
|
6
|
-
| 'Z11' // hanging container
|
|
7
|
-
| 'Z9' // nanomole
|
|
8
|
-
| 'ZP' // page
|
|
9
|
-
| 'ZZ' // mutually defined
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Enum representing unit type codes starting with 'Z'.
|
|
13
|
-
*/
|
|
14
|
-
export enum UnitTypeCodeEnum_ZX {
|
|
15
|
-
HangingContainer = 'Z11',
|
|
16
|
-
Nanomole = 'Z9',
|
|
17
|
-
Page = 'ZP',
|
|
18
|
-
MutuallyDefined = 'ZZ',
|
|
19
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import type { UnitTypeCode_1X } from './unit/1X.d.ts'
|
|
2
|
-
import type { UnitTypeCode_2X } from './unit/2X.d.ts'
|
|
3
|
-
import type { UnitTypeCode_3X } from './unit/3X.d.ts'
|
|
4
|
-
import type { UnitTypeCode_4X } from './unit/4X.d.ts'
|
|
5
|
-
import type { UnitTypeCode_5X } from './unit/5X.d.ts'
|
|
6
|
-
import type { UnitTypeCode_6X } from './unit/6X.d.ts'
|
|
7
|
-
import type { UnitTypeCode_7X } from './unit/7X.d.ts'
|
|
8
|
-
import type { UnitTypeCode_8X } from './unit/8X.d.ts'
|
|
9
|
-
import type { UnitTypeCode_9X } from './unit/9X.d.ts'
|
|
10
|
-
import type { UnitTypeCode_AX } from './unit/AX.d.ts'
|
|
11
|
-
import type { UnitTypeCode_BX } from './unit/BX.d.ts'
|
|
12
|
-
import type { UnitTypeCode_CX } from './unit/CX.d.ts'
|
|
13
|
-
import type { UnitTypeCode_DX } from './unit/DX.d.ts'
|
|
14
|
-
import type { UnitTypeCode_EX } from './unit/EX.d.ts'
|
|
15
|
-
import type { UnitTypeCode_FX } from './unit/FX.d.ts'
|
|
16
|
-
import type { UnitTypeCode_GX } from './unit/GX.d.ts'
|
|
17
|
-
import type { UnitTypeCode_HX } from './unit/HX.d.ts'
|
|
18
|
-
import type { UnitTypeCode_IX } from './unit/IX.d.ts'
|
|
19
|
-
import type { UnitTypeCode_JX } from './unit/JX.d.ts'
|
|
20
|
-
import type { UnitTypeCode_KX } from './unit/KX.d.ts'
|
|
21
|
-
import type { UnitTypeCode_LX } from './unit/LX.d.ts'
|
|
22
|
-
import type { UnitTypeCode_MX } from './unit/MX.d.ts'
|
|
23
|
-
import type { UnitTypeCode_NX } from './unit/NX.d.ts'
|
|
24
|
-
import type { UnitTypeCode_OX } from './unit/OX.d.ts'
|
|
25
|
-
import type { UnitTypeCode_PX } from './unit/PX.d.ts'
|
|
26
|
-
import type { UnitTypeCode_QX } from './unit/QX.d.ts'
|
|
27
|
-
import type { UnitTypeCode_RX } from './unit/RX.d.ts'
|
|
28
|
-
import type { UnitTypeCode_SX } from './unit/SX.d.ts'
|
|
29
|
-
import type { UnitTypeCode_TX } from './unit/TX.d.ts'
|
|
30
|
-
import type { UnitTypeCode_UX } from './unit/UX.d.ts'
|
|
31
|
-
import type { UnitTypeCode_VX } from './unit/VX.d.ts'
|
|
32
|
-
import type { UnitTypeCode_WX } from './unit/WX.d.ts'
|
|
33
|
-
import type { UnitTypeCode_YX } from './unit/YX.d.ts'
|
|
34
|
-
import type { UnitTypeCode_ZX } from './unit/ZX.d.ts'
|
|
35
|
-
import type { UnitTypeCode_XX } from './unit/XX.d.ts'
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Represents the allowed codes for Unit of Measurement types.
|
|
39
|
-
* Based on UN/ECE Recommendation 20, Revision 17 (2021) as per the documentation:
|
|
40
|
-
* https://sdk.myinvois.hasil.gov.my/codes/unit-types/
|
|
41
|
-
*/
|
|
42
|
-
export type UnitTypeCode =
|
|
43
|
-
| UnitTypeCode_1X
|
|
44
|
-
| UnitTypeCode_2X
|
|
45
|
-
| UnitTypeCode_3X
|
|
46
|
-
| UnitTypeCode_4X
|
|
47
|
-
| UnitTypeCode_5X
|
|
48
|
-
| UnitTypeCode_6X
|
|
49
|
-
| UnitTypeCode_7X
|
|
50
|
-
| UnitTypeCode_8X
|
|
51
|
-
| UnitTypeCode_9X
|
|
52
|
-
| UnitTypeCode_AX
|
|
53
|
-
| UnitTypeCode_BX
|
|
54
|
-
| UnitTypeCode_CX
|
|
55
|
-
| UnitTypeCode_DX
|
|
56
|
-
| UnitTypeCode_EX
|
|
57
|
-
| UnitTypeCode_FX
|
|
58
|
-
| UnitTypeCode_GX
|
|
59
|
-
| UnitTypeCode_HX
|
|
60
|
-
| UnitTypeCode_IX
|
|
61
|
-
| UnitTypeCode_JX
|
|
62
|
-
| UnitTypeCode_KX
|
|
63
|
-
| UnitTypeCode_LX
|
|
64
|
-
| UnitTypeCode_MX
|
|
65
|
-
| UnitTypeCode_NX
|
|
66
|
-
| UnitTypeCode_OX
|
|
67
|
-
| UnitTypeCode_PX
|
|
68
|
-
| UnitTypeCode_QX
|
|
69
|
-
| UnitTypeCode_RX
|
|
70
|
-
| UnitTypeCode_SX
|
|
71
|
-
| UnitTypeCode_TX
|
|
72
|
-
| UnitTypeCode_UX
|
|
73
|
-
| UnitTypeCode_VX
|
|
74
|
-
| UnitTypeCode_WX
|
|
75
|
-
| UnitTypeCode_YX
|
|
76
|
-
| UnitTypeCode_ZX
|
|
77
|
-
| UnitTypeCode_XX
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Interface representing a Unit of Measurement entry.
|
|
81
|
-
* Contains the code and its corresponding name.
|
|
82
|
-
*/
|
|
83
|
-
export interface UnitType {
|
|
84
|
-
code: UnitTypeCode
|
|
85
|
-
name: string
|
|
86
|
-
}
|
package/src/utils/base64.ts
DELETED
package/src/utils/certificate.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import crypto from 'crypto'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Extracts certificate information from PEM certificate
|
|
5
|
-
* Converts hex serial number to decimal as required by MyInvois
|
|
6
|
-
*
|
|
7
|
-
* @param certificatePem - Certificate in PEM format
|
|
8
|
-
* @returns Object with issuer name and decimal serial number
|
|
9
|
-
*/
|
|
10
|
-
export const extractCertificateInfo = (
|
|
11
|
-
certificatePem: string,
|
|
12
|
-
): {
|
|
13
|
-
issuerName: string
|
|
14
|
-
serialNumber: string
|
|
15
|
-
} => {
|
|
16
|
-
try {
|
|
17
|
-
const cert = new crypto.X509Certificate(certificatePem)
|
|
18
|
-
|
|
19
|
-
// Convert hex serial number to decimal (MyInvois requirement)
|
|
20
|
-
const serialNumberHex = cert.serialNumber
|
|
21
|
-
const serialNumberDecimal = BigInt('0x' + serialNumberHex).toString()
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
issuerName: cert.issuer,
|
|
25
|
-
serialNumber: serialNumberDecimal,
|
|
26
|
-
}
|
|
27
|
-
} catch (error) {
|
|
28
|
-
throw new Error(`Failed to extract certificate info: ${error}`)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Validates that certificate and private key form a valid pair
|
|
34
|
-
*
|
|
35
|
-
* @param certificatePem - Certificate in PEM format
|
|
36
|
-
* @param privateKeyPem - Private key in PEM format
|
|
37
|
-
* @returns Boolean indicating if key pair is valid
|
|
38
|
-
*/
|
|
39
|
-
export const validateKeyPair = (
|
|
40
|
-
certificatePem: string,
|
|
41
|
-
privateKeyPem: string,
|
|
42
|
-
): boolean => {
|
|
43
|
-
try {
|
|
44
|
-
const cert = new crypto.X509Certificate(certificatePem)
|
|
45
|
-
const publicKey = cert.publicKey
|
|
46
|
-
|
|
47
|
-
// Test signature/verification cycle
|
|
48
|
-
const testData = 'validation-test-data'
|
|
49
|
-
const signer = crypto.createSign('RSA-SHA256')
|
|
50
|
-
signer.update(testData)
|
|
51
|
-
const signature = signer.sign(privateKeyPem)
|
|
52
|
-
|
|
53
|
-
const verifier = crypto.createVerify('RSA-SHA256')
|
|
54
|
-
verifier.update(testData)
|
|
55
|
-
return verifier.verify(publicKey, signature)
|
|
56
|
-
} catch (error) {
|
|
57
|
-
console.error('Key pair validation failed:', error)
|
|
58
|
-
return false
|
|
59
|
-
}
|
|
60
|
-
}
|