@ripwords/myinvois-client 0.1.5 → 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.
Files changed (81) hide show
  1. package/package.json +8 -11
  2. package/.prettierrc +0 -8
  3. package/CHANGELOG.md +0 -140
  4. package/bun.lock +0 -460
  5. package/myinvois-cert.conf.template +0 -23
  6. package/scripts/gen-cert.sh +0 -159
  7. package/src/api/platform/platformLogin.ts +0 -34
  8. package/src/index.ts +0 -530
  9. package/src/types/classification-codes.d.ts +0 -115
  10. package/src/types/country-code.d.ts +0 -790
  11. package/src/types/currencies.d.ts +0 -383
  12. package/src/types/documents.d.ts +0 -869
  13. package/src/types/e-invoice.d.ts +0 -41
  14. package/src/types/index.d.ts +0 -24
  15. package/src/types/msic/0X.d.ts +0 -408
  16. package/src/types/msic/1X.d.ts +0 -210
  17. package/src/types/msic/2X.d.ts +0 -266
  18. package/src/types/msic/3X.d.ts +0 -114
  19. package/src/types/msic/4X.d.ts +0 -520
  20. package/src/types/msic/5X.d.ts +0 -144
  21. package/src/types/msic/6X.d.ts +0 -200
  22. package/src/types/msic/7X.d.ts +0 -132
  23. package/src/types/msic/8X.d.ts +0 -210
  24. package/src/types/msic/9X.d.ts +0 -186
  25. package/src/types/msic-codes.d.ts +0 -31
  26. package/src/types/payment-modes.d.ts +0 -41
  27. package/src/types/signatures.d.ts +0 -169
  28. package/src/types/state-codes.d.ts +0 -59
  29. package/src/types/tax-types.d.ts +0 -39
  30. package/src/types/unit/1X.d.ts +0 -16
  31. package/src/types/unit/2X.d.ts +0 -62
  32. package/src/types/unit/3X.d.ts +0 -17
  33. package/src/types/unit/4X.d.ts +0 -44
  34. package/src/types/unit/5X.d.ts +0 -26
  35. package/src/types/unit/6X.d.ts +0 -12
  36. package/src/types/unit/7X.d.ts +0 -12
  37. package/src/types/unit/8X.d.ts +0 -15
  38. package/src/types/unit/9X.d.ts +0 -11
  39. package/src/types/unit/AX.d.ts +0 -202
  40. package/src/types/unit/BX.d.ts +0 -212
  41. package/src/types/unit/CX.d.ts +0 -238
  42. package/src/types/unit/DX.d.ts +0 -212
  43. package/src/types/unit/EX.d.ts +0 -196
  44. package/src/types/unit/FX.d.ts +0 -236
  45. package/src/types/unit/GX.d.ts +0 -254
  46. package/src/types/unit/HX.d.ts +0 -234
  47. package/src/types/unit/IX.d.ts +0 -28
  48. package/src/types/unit/JX.d.ts +0 -190
  49. package/src/types/unit/KX.d.ts +0 -284
  50. package/src/types/unit/LX.d.ts +0 -228
  51. package/src/types/unit/MX.d.ts +0 -288
  52. package/src/types/unit/NX.d.ts +0 -226
  53. package/src/types/unit/OX.d.ts +0 -34
  54. package/src/types/unit/PX.d.ts +0 -224
  55. package/src/types/unit/QX.d.ts +0 -94
  56. package/src/types/unit/RX.d.ts +0 -28
  57. package/src/types/unit/SX.d.ts +0 -56
  58. package/src/types/unit/TX.d.ts +0 -44
  59. package/src/types/unit/UX.d.ts +0 -14
  60. package/src/types/unit/VX.d.ts +0 -13
  61. package/src/types/unit/WX.d.ts +0 -34
  62. package/src/types/unit/XX.d.ts +0 -825
  63. package/src/types/unit/YX.d.ts +0 -17
  64. package/src/types/unit/ZX.d.ts +0 -19
  65. package/src/types/unit-types.d.ts +0 -86
  66. package/src/utils/base64.ts +0 -7
  67. package/src/utils/certificate.ts +0 -60
  68. package/src/utils/document.ts +0 -852
  69. package/src/utils/getBaseUrl.ts +0 -5
  70. package/src/utils/helpers.ts +0 -552
  71. package/src/utils/signature-diagnostics.ts +0 -583
  72. package/src/utils/validation.ts +0 -268
  73. package/test/MyInvoiClientWithRealData.test.ts +0 -40
  74. package/test/MyInvoisClient.test.ts +0 -204
  75. package/test/base64.test.ts +0 -43
  76. package/test/dynamicInvoiceFeatures.test.ts +0 -451
  77. package/test/signAndSubmitInvoice.test.ts +0 -452
  78. package/test/signature-diagnostics.test.ts +0 -130
  79. package/tsconfig.json +0 -39
  80. package/tsdown.config.ts +0 -31
  81. package/vitest.config.ts +0 -8
@@ -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
- }
@@ -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
- }
@@ -1,7 +0,0 @@
1
- export function encodeToBase64(content: string): string {
2
- return Buffer.from(content).toString('base64')
3
- }
4
-
5
- export function decodeFromBase64(content: string): string {
6
- return Buffer.from(content, 'base64').toString('utf-8')
7
- }
@@ -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
- }