@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.
Files changed (81) hide show
  1. package/package.json +5 -8
  2. package/.prettierrc +0 -8
  3. package/CHANGELOG.md +0 -152
  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,5 +0,0 @@
1
- export const getBaseUrl = (environment: 'sandbox' | 'production'): string => {
2
- return environment === 'sandbox'
3
- ? 'https://preprod-api.myinvois.hasil.gov.my'
4
- : 'https://api.myinvois.hasil.gov.my'
5
- }
@@ -1,552 +0,0 @@
1
- import type {
2
- InvoiceV1_1,
3
- PaymentMeans,
4
- AllowanceCharge,
5
- CurrencyExchangeRate,
6
- Delivery,
7
- AdditionalDocumentReference,
8
- } from '../types/documents/index.js'
9
-
10
- /**
11
- * MyInvois Invoice Helper Functions
12
- *
13
- * Provides convenient utilities for common invoice scenarios and business patterns.
14
- * These helpers simplify the creation of compliant MyInvois documents.
15
- */
16
-
17
- /**
18
- * Payment Method Helpers
19
- */
20
- export const PaymentHelpers = {
21
- /**
22
- * Creates cash payment means
23
- */
24
- cash(): PaymentMeans {
25
- return {
26
- paymentMeansCode: '01',
27
- paymentTerms: 'Cash payment',
28
- }
29
- },
30
-
31
- /**
32
- * Creates cheque payment means
33
- */
34
- cheque(accountId?: string): PaymentMeans {
35
- return {
36
- paymentMeansCode: '02',
37
- payeeFinancialAccountID: accountId,
38
- paymentTerms: 'Cheque payment',
39
- }
40
- },
41
-
42
- /**
43
- * Creates bank transfer payment means
44
- */
45
- bankTransfer(accountId: string, dueDate?: string): PaymentMeans {
46
- return {
47
- paymentMeansCode: '03',
48
- payeeFinancialAccountID: accountId,
49
- paymentDueDate: dueDate,
50
- paymentTerms: 'Bank transfer',
51
- }
52
- },
53
-
54
- /**
55
- * Creates credit card payment means
56
- */
57
- creditCard(): PaymentMeans {
58
- return {
59
- paymentMeansCode: '04',
60
- paymentTerms: 'Credit card payment',
61
- }
62
- },
63
-
64
- /**
65
- * Creates e-wallet payment means
66
- */
67
- eWallet(accountId?: string): PaymentMeans {
68
- return {
69
- paymentMeansCode: '05',
70
- payeeFinancialAccountID: accountId,
71
- paymentTerms: 'E-wallet payment',
72
- }
73
- },
74
-
75
- /**
76
- * Creates custom payment terms with specific due date
77
- */
78
- net(days: number, accountId?: string): PaymentMeans {
79
- const dueDate = new Date()
80
- dueDate.setDate(dueDate.getDate() + days)
81
-
82
- return {
83
- paymentMeansCode: '03', // Bank transfer is most common for net terms
84
- payeeFinancialAccountID: accountId,
85
- paymentDueDate: dueDate.toISOString().split('T')[0],
86
- paymentTerms: `Net ${days} days`,
87
- }
88
- },
89
- }
90
-
91
- /**
92
- * Currency and Exchange Rate Helpers
93
- */
94
- export const CurrencyHelpers = {
95
- /**
96
- * Creates domestic MYR transaction (no exchange rate needed)
97
- */
98
- domestic(): CurrencyExchangeRate {
99
- return {
100
- sourceCurrencyCode: 'MYR',
101
- targetCurrencyCode: 'MYR',
102
- calculationRate: 1.0,
103
- }
104
- },
105
-
106
- /**
107
- * Creates international transaction with exchange rate
108
- */
109
- international(
110
- fromCurrency: string,
111
- toCurrency: string = 'MYR',
112
- exchangeRate: number,
113
- rateDate?: string,
114
- ): CurrencyExchangeRate {
115
- return {
116
- sourceCurrencyCode: fromCurrency as any,
117
- targetCurrencyCode: toCurrency as any,
118
- calculationRate: exchangeRate,
119
- exchangeRateDate: rateDate || new Date().toISOString().split('T')[0],
120
- }
121
- },
122
-
123
- /**
124
- * Common exchange rates (these should be updated with real-time rates)
125
- */
126
- commonRates: {
127
- USD_MYR: 4.75,
128
- SGD_MYR: 3.45,
129
- EUR_MYR: 5.1,
130
- GBP_MYR: 5.85,
131
- JPY_MYR: 0.032,
132
- AUD_MYR: 3.12,
133
- },
134
- }
135
-
136
- /**
137
- * Tax Calculation Helpers
138
- */
139
- export const TaxHelpers = {
140
- /**
141
- * Calculates SST (6%) for goods
142
- */
143
- calculateSST(
144
- amount: number,
145
- rate: number = 6.0,
146
- ): { taxAmount: number; totalWithTax: number } {
147
- const taxAmount = (amount * rate) / 100
148
- return {
149
- taxAmount: Math.round(taxAmount * 100) / 100,
150
- totalWithTax: Math.round((amount + taxAmount) * 100) / 100,
151
- }
152
- },
153
-
154
- /**
155
- * Calculates Service Tax for services
156
- */
157
- calculateServiceTax(
158
- amount: number,
159
- rate: number = 6.0,
160
- ): { taxAmount: number; totalWithTax: number } {
161
- return TaxHelpers.calculateSST(amount, rate)
162
- },
163
-
164
- /**
165
- * Zero-rated calculation (0% tax)
166
- */
167
- zeroRated(amount: number): { taxAmount: number; totalWithTax: number } {
168
- return {
169
- taxAmount: 0,
170
- totalWithTax: amount,
171
- }
172
- },
173
-
174
- /**
175
- * Exempt calculation (no tax)
176
- */
177
- exempt(amount: number): { taxAmount: number; totalWithTax: number } {
178
- return {
179
- taxAmount: 0,
180
- totalWithTax: amount,
181
- }
182
- },
183
- }
184
-
185
- /**
186
- * Allowance and Charge Helpers
187
- */
188
- export const AllowanceChargeHelpers = {
189
- /**
190
- * Creates a discount allowance
191
- */
192
- discount(
193
- reason: string,
194
- amount: number,
195
- percentage?: number,
196
- ): AllowanceCharge {
197
- return {
198
- chargeIndicator: false,
199
- reason,
200
- amount,
201
- multiplierFactorNumeric: percentage ? percentage / 100 : undefined,
202
- }
203
- },
204
-
205
- /**
206
- * Creates a shipping charge
207
- */
208
- shipping(
209
- amount: number,
210
- description: string = 'Shipping and handling',
211
- ): AllowanceCharge {
212
- return {
213
- chargeIndicator: true,
214
- reason: description,
215
- amount,
216
- }
217
- },
218
-
219
- /**
220
- * Creates an early payment discount
221
- */
222
- earlyPaymentDiscount(
223
- percentage: number,
224
- baseAmount: number,
225
- ): AllowanceCharge {
226
- const discountAmount = (baseAmount * percentage) / 100
227
- return {
228
- chargeIndicator: false,
229
- reason: `Early payment discount ${percentage}%`,
230
- amount: Math.round(discountAmount * 100) / 100,
231
- multiplierFactorNumeric: percentage / 100,
232
- baseAmount,
233
- }
234
- },
235
-
236
- /**
237
- * Creates a handling fee charge
238
- */
239
- handlingFee(amount: number): AllowanceCharge {
240
- return {
241
- chargeIndicator: true,
242
- reason: 'Handling fee',
243
- amount,
244
- }
245
- },
246
- }
247
-
248
- /**
249
- * Delivery Helpers
250
- */
251
- export const DeliveryHelpers = {
252
- /**
253
- * Creates standard delivery information
254
- */
255
- standard(
256
- deliveryDate: string,
257
- address: {
258
- addressLine0: string
259
- cityName: string
260
- postalZone?: string
261
- state: string
262
- country?: string
263
- },
264
- ): Delivery {
265
- return {
266
- actualDeliveryDate: deliveryDate,
267
- deliveryLocation: {
268
- ...address,
269
- country: address.country || 'MYS',
270
- },
271
- }
272
- },
273
-
274
- /**
275
- * Creates pickup delivery (customer pickup)
276
- */
277
- pickup(pickupDate: string): Delivery {
278
- return {
279
- actualDeliveryDate: pickupDate,
280
- deliveryLocation: {
281
- addressLine0: 'Customer pickup',
282
- cityName: 'N/A',
283
- state: 'N/A',
284
- country: 'MYS',
285
- },
286
- }
287
- },
288
-
289
- /**
290
- * Creates delivery with freight charges
291
- */
292
- withFreight(
293
- deliveryDate: string,
294
- address: any,
295
- freightAmount: number,
296
- freightDescription: string = 'Freight charges',
297
- ): Delivery {
298
- return {
299
- actualDeliveryDate: deliveryDate,
300
- deliveryLocation: address,
301
- shipment: {
302
- id: `SHIP-${Date.now()}`,
303
- freightAllowanceCharge: {
304
- chargeIndicator: true,
305
- reason: freightDescription,
306
- amount: freightAmount,
307
- },
308
- },
309
- }
310
- },
311
- }
312
-
313
- /**
314
- * Document Reference Helpers
315
- */
316
- export const DocumentReferenceHelpers = {
317
- /**
318
- * Creates purchase order reference
319
- */
320
- purchaseOrder(poNumber: string): { purchaseOrderReference: string } {
321
- return { purchaseOrderReference: poNumber }
322
- },
323
-
324
- /**
325
- * Creates contract reference
326
- */
327
- contract(contractNumber: string): { contractReference: string } {
328
- return { contractReference: contractNumber }
329
- },
330
-
331
- /**
332
- * Creates project reference
333
- */
334
- project(projectNumber: string): { projectReference: string } {
335
- return { projectReference: projectNumber }
336
- },
337
-
338
- /**
339
- * Creates billing reference
340
- */
341
- billing(billingNumber: string): { billingReference: string } {
342
- return { billingReference: billingNumber }
343
- },
344
-
345
- /**
346
- * Creates customs reference
347
- */
348
- customs(customsFormNumber: string): AdditionalDocumentReference {
349
- return {
350
- id: customsFormNumber,
351
- documentType: 'CustomsImportForm',
352
- documentDescription: 'Customs import declaration',
353
- }
354
- },
355
-
356
- /**
357
- * Creates free trade agreement reference
358
- */
359
- freeTradeAgreement(
360
- ftaNumber: string,
361
- country: string,
362
- ): AdditionalDocumentReference {
363
- return {
364
- id: ftaNumber,
365
- documentType: 'FreeTradeAgreement',
366
- documentDescription: `Free trade agreement with ${country}`,
367
- }
368
- },
369
- }
370
-
371
- /**
372
- * Industry Classification Helpers
373
- */
374
- export const IndustryHelpers = {
375
- /**
376
- * Common industry classifications with proper codes and descriptions
377
- */
378
- trading: {
379
- industryClassificationCode: '47900',
380
- industryClassificationDescription:
381
- 'Retail sale via mail order houses or via Internet',
382
- },
383
-
384
- manufacturing: {
385
- industryClassificationCode: '10131',
386
- industryClassificationDescription: 'Processing and preserving of meat',
387
- },
388
-
389
- software: {
390
- industryClassificationCode: '62012',
391
- industryClassificationDescription:
392
- 'Business and domestic software development',
393
- },
394
-
395
- consulting: {
396
- industryClassificationCode: '70200',
397
- industryClassificationDescription: 'Management consultancy activities',
398
- },
399
-
400
- restaurant: {
401
- industryClassificationCode: '56101',
402
- industryClassificationDescription: 'Restaurants',
403
- },
404
-
405
- construction: {
406
- industryClassificationCode: '41000',
407
- industryClassificationDescription: 'Development of building projects',
408
- },
409
-
410
- logistics: {
411
- industryClassificationCode: '49301',
412
- industryClassificationDescription: 'Land freight transport',
413
- },
414
-
415
- /**
416
- * Creates custom industry classification
417
- */
418
- custom(
419
- code: string,
420
- description: string,
421
- ): {
422
- industryClassificationCode: string
423
- industryClassificationDescription: string
424
- } {
425
- return {
426
- industryClassificationCode: code,
427
- industryClassificationDescription: description,
428
- }
429
- },
430
- }
431
-
432
- /**
433
- * Date and Time Helpers
434
- */
435
- export const DateTimeHelpers = {
436
- /**
437
- * Gets current date in MyInvois format (YYYY-MM-DD)
438
- */
439
- currentDate(): string {
440
- return new Date().toISOString().split('T')[0] || ''
441
- },
442
-
443
- /**
444
- * Gets current time in MyInvois format (HH:mm:ssZ)
445
- */
446
- currentTime(): string {
447
- return new Date().toISOString().split('T')[1]?.split('.')[0] + 'Z' || ''
448
- },
449
-
450
- /**
451
- * Formats date to MyInvois format
452
- */
453
- formatDate(date: Date): string {
454
- return date.toISOString().split('T')[0] || ''
455
- },
456
-
457
- /**
458
- * Formats time to MyInvois format
459
- */
460
- formatTime(date: Date): string {
461
- return date.toISOString().split('T')[1]?.split('.')[0] + 'Z' || ''
462
- },
463
-
464
- /**
465
- * Adds days to a date
466
- */
467
- addDays(date: Date, days: number): Date {
468
- const result = new Date(date)
469
- result.setDate(result.getDate() + days)
470
- return result
471
- },
472
-
473
- /**
474
- * Gets billing period for monthly billing
475
- */
476
- monthlyPeriod(year: number, month: number): { start: string; end: string } {
477
- // Use UTC to avoid timezone issues
478
- // JavaScript Date uses 0-based months, so subtract 1 for the month
479
- const start = new Date(Date.UTC(year, month - 1, 1))
480
- // To get last day of the month, use day 0 of the NEXT month
481
- const end = new Date(Date.UTC(year, month, 0))
482
-
483
- return {
484
- start: DateTimeHelpers.formatDate(start),
485
- end: DateTimeHelpers.formatDate(end),
486
- }
487
- },
488
- }
489
-
490
- /**
491
- * Complete Invoice Builder Helper
492
- */
493
- export const InvoiceBuilder = {
494
- /**
495
- * Creates a basic cash invoice template
496
- */
497
- basicCash(invoiceNumber: string): Partial<InvoiceV1_1> {
498
- return {
499
- eInvoiceCodeOrNumber: invoiceNumber,
500
- eInvoiceDate: DateTimeHelpers.currentDate(),
501
- eInvoiceTime: DateTimeHelpers.currentTime(),
502
- eInvoiceTypeCode: '01',
503
- eInvoiceVersion: '1.1',
504
- invoiceCurrencyCode: 'MYR',
505
- paymentMeans: [PaymentHelpers.cash()],
506
- }
507
- },
508
-
509
- /**
510
- * Creates a business invoice template with bank transfer
511
- */
512
- businessInvoice(
513
- invoiceNumber: string,
514
- accountId: string,
515
- netDays: number = 30,
516
- ): Partial<InvoiceV1_1> {
517
- return {
518
- eInvoiceCodeOrNumber: invoiceNumber,
519
- eInvoiceDate: DateTimeHelpers.currentDate(),
520
- eInvoiceTime: DateTimeHelpers.currentTime(),
521
- eInvoiceTypeCode: '01',
522
- eInvoiceVersion: '1.1',
523
- invoiceCurrencyCode: 'MYR',
524
- paymentMeans: [PaymentHelpers.net(netDays, accountId)],
525
- }
526
- },
527
-
528
- /**
529
- * Creates an international invoice template
530
- */
531
- international(
532
- invoiceNumber: string,
533
- currency: string,
534
- exchangeRate: number,
535
- ): Partial<InvoiceV1_1> {
536
- return {
537
- eInvoiceCodeOrNumber: invoiceNumber,
538
- eInvoiceDate: DateTimeHelpers.currentDate(),
539
- eInvoiceTime: DateTimeHelpers.currentTime(),
540
- eInvoiceTypeCode: '01',
541
- eInvoiceVersion: '1.1',
542
- invoiceCurrencyCode: currency as any,
543
- currencyExchangeRate: exchangeRate,
544
- taxExchangeRate: CurrencyHelpers.international(
545
- currency,
546
- 'MYR',
547
- exchangeRate,
548
- ),
549
- paymentMeans: [PaymentHelpers.bankTransfer('')],
550
- }
551
- },
552
- }