@ripwords/myinvois-client 0.0.7 → 0.0.8

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 (54) hide show
  1. package/bun.lock +25 -25
  2. package/dist/index.cjs +39 -19
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.ts +2316 -463
  5. package/dist/index.js +16 -19
  6. package/package.json +17 -17
  7. package/src/api/platform/taxpayerLogin.ts +28 -0
  8. package/src/types/index.d.ts +12 -0
  9. package/src/types/unit/1X.d.ts +16 -0
  10. package/src/types/unit/2X.d.ts +62 -0
  11. package/src/types/unit/3X.d.ts +17 -0
  12. package/src/types/unit/4X.d.ts +44 -0
  13. package/src/types/unit/5X.d.ts +26 -0
  14. package/src/types/unit/6X.d.ts +12 -0
  15. package/src/types/unit/7X.d.ts +12 -0
  16. package/src/types/unit/8X.d.ts +15 -0
  17. package/src/types/unit/9X.d.ts +11 -0
  18. package/src/types/unit/AX.d.ts +202 -0
  19. package/src/types/unit/BX.d.ts +212 -0
  20. package/src/types/unit/CX.d.ts +238 -0
  21. package/src/types/unit/DX.d.ts +212 -0
  22. package/src/types/unit/EX.d.ts +196 -0
  23. package/src/types/unit/FX.d.ts +236 -0
  24. package/src/types/unit/GX.d.ts +254 -0
  25. package/src/types/unit/HX.d.ts +234 -0
  26. package/src/types/unit/IX.d.ts +28 -0
  27. package/src/types/unit/JX.d.ts +190 -0
  28. package/src/types/unit/KX.d.ts +284 -0
  29. package/src/types/unit/LX.d.ts +228 -0
  30. package/src/types/unit/MX.d.ts +288 -0
  31. package/src/types/unit/NX.d.ts +226 -0
  32. package/src/types/unit/OX.d.ts +34 -0
  33. package/src/types/unit/PX.d.ts +224 -0
  34. package/src/types/unit/QX.d.ts +94 -0
  35. package/src/types/unit/RX.d.ts +28 -0
  36. package/src/types/unit/SX.d.ts +56 -0
  37. package/src/types/unit/TX.d.ts +44 -0
  38. package/src/types/unit/UX.d.ts +14 -0
  39. package/src/types/unit/VX.d.ts +13 -0
  40. package/src/types/unit/WX.d.ts +34 -0
  41. package/src/types/unit/XX.d.ts +825 -0
  42. package/src/types/unit/YX.d.ts +17 -0
  43. package/src/types/unit/ZX.d.ts +19 -0
  44. package/src/types/unit-types.d.ts +71 -575
  45. package/src/utils/MyInvoisClient.ts +11 -33
  46. package/src/utils/getBaseUrl.ts +5 -0
  47. package/test/{MyInvoiClientRealData.test.ts → MyInvoiClientWithRealData.test.ts} +13 -1
  48. package/test/MyInvoisClient.test.ts +4 -7
  49. package/dist/cjs/index.cjs +0 -75
  50. package/dist/cjs/index.cjs.map +0 -1
  51. package/dist/cjs/multipart-parser-Bu3ikqFQ.cjs +0 -182
  52. package/dist/cjs/multipart-parser-Bu3ikqFQ.cjs.map +0 -1
  53. package/dist/cjs/node-qs2pnN6F.cjs +0 -4124
  54. package/dist/cjs/node-qs2pnN6F.cjs.map +0 -1
package/dist/index.js CHANGED
@@ -1,4 +1,11 @@
1
+ import { taxpayerLogin } from "src/api/platform/taxpayerLogin";
1
2
 
3
+ //#region src/utils/getBaseUrl.ts
4
+ const getBaseUrl = (environment) => {
5
+ return environment === "sandbox" ? "https://preprod-api.myinvois.hasil.gov.my" : "https://api.myinvois.hasil.gov.my";
6
+ };
7
+
8
+ //#endregion
2
9
  //#region src/utils/MyInvoisClient.ts
3
10
  var MyInvoisClient = class {
4
11
  baseUrl;
@@ -10,28 +17,18 @@ var MyInvoisClient = class {
10
17
  constructor(clientId, clientSecret, environment, debug = false) {
11
18
  this.clientId = clientId;
12
19
  this.clientSecret = clientSecret;
20
+ this.baseUrl = getBaseUrl(environment);
13
21
  this.debug = debug;
14
- if (environment === "sandbox") this.baseUrl = "https://preprod-api.myinvois.hasil.gov.my";
15
- else this.baseUrl = "https://api.myinvois.hasil.gov.my";
16
22
  }
17
23
  async refreshToken() {
18
- try {
19
- const response = await fetch(`${this.baseUrl}/connect/token`, {
20
- method: "POST",
21
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
22
- body: new URLSearchParams({
23
- grant_type: "client_credentials",
24
- client_id: this.clientId,
25
- client_secret: this.clientSecret,
26
- scope: "InvoicingAPI"
27
- })
28
- });
29
- const tokenResponse = await response.json();
30
- this.token = tokenResponse.access_token;
31
- this.tokenExpiration = new Date(Date.now() + tokenResponse.expires_in * 1e3);
32
- } catch (error) {
33
- if (this.debug) console.error(error);
34
- }
24
+ const tokenResponse = await taxpayerLogin({
25
+ clientId: this.clientId,
26
+ clientSecret: this.clientSecret,
27
+ baseUrl: this.baseUrl,
28
+ debug: this.debug
29
+ });
30
+ this.token = tokenResponse.token;
31
+ this.tokenExpiration = tokenResponse.tokenExpiration;
35
32
  }
36
33
  async getToken() {
37
34
  if (!this.tokenExpiration || this.tokenExpiration < new Date()) {
package/package.json CHANGED
@@ -1,31 +1,31 @@
1
1
  {
2
2
  "name": "@ripwords/myinvois-client",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
+ "description": "MyInvois client",
5
+ "scripts": {
6
+ "build": "rolldown -c rolldown.config.ts",
7
+ "release": "bun run build && npm publish --access public",
8
+ "lint": "oxlint",
9
+ "test": "vitest"
10
+ },
4
11
  "main": "dist/index.js",
5
12
  "module": "src/index.ts",
13
+ "type": "module",
14
+ "types": "dist/index.d.ts",
15
+ "exports": {
16
+ "import": "./dist/index.js",
17
+ "require": "./dist/index.cjs"
18
+ },
6
19
  "devDependencies": {
7
20
  "@types/bun": "latest",
8
21
  "dotenv": "^16.5.0",
9
22
  "oxlint": "^0.16.6",
10
23
  "prettier": "^3.5.3",
11
24
  "rolldown": "^1.0.0-beta.7",
12
- "rolldown-plugin-dts": "^0.7.0",
25
+ "rolldown-plugin-dts": "^0.7.13",
13
26
  "vitest": "^3.1.1"
14
27
  },
15
- "exports": {
16
- "import": "./dist/index.js",
17
- "require": "./dist/index.cjs"
18
- },
19
28
  "peerDependencies": {
20
- "typescript": "^5"
21
- },
22
- "description": "MyInvois client",
23
- "scripts": {
24
- "build": "rolldown -c rolldown.config.ts",
25
- "release": "bun run build && npm publish --access public && git push --follow-tags",
26
- "lint": "oxlint",
27
- "test": "vitest"
28
- },
29
- "type": "module",
30
- "types": "dist/index.d.ts"
29
+ "typescript": "^5.8.3"
30
+ }
31
31
  }
@@ -0,0 +1,28 @@
1
+ import type { ClientCredentials, TokenResponse } from 'src/types'
2
+
3
+ export const taxpayerLogin = async (client: ClientCredentials) => {
4
+ const { clientId, clientSecret, baseUrl, debug } = client
5
+ try {
6
+ const response = await fetch(`${baseUrl}/connect/token`, {
7
+ method: 'POST',
8
+ headers: {
9
+ 'Content-Type': 'application/x-www-form-urlencoded',
10
+ },
11
+ body: new URLSearchParams({
12
+ grant_type: 'client_credentials',
13
+ client_id: clientId,
14
+ client_secret: clientSecret,
15
+ scope: 'InvoicingAPI',
16
+ }),
17
+ })
18
+
19
+ const tokenResponse: TokenResponse = await response.json()
20
+ return {
21
+ token: tokenResponse.access_token,
22
+ tokenExpiration: new Date(Date.now() + tokenResponse.expires_in * 1000),
23
+ }
24
+ } catch (error) {
25
+ if (debug) console.error(error)
26
+ throw error
27
+ }
28
+ }
@@ -9,3 +9,15 @@ export type * from './currencies.d.ts'
9
9
  export type * from './state-codes.d.ts'
10
10
  export type * from './e-invoice.d.ts'
11
11
  export type * from './msic-codes.d.ts'
12
+
13
+ export interface TokenResponse {
14
+ access_token: string
15
+ expires_in: number
16
+ }
17
+
18
+ export interface ClientCredentials {
19
+ clientId: string
20
+ clientSecret: string
21
+ baseUrl: string
22
+ debug?: boolean
23
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Unit type codes starting with '1'.
3
+ */
4
+ export type UnitTypeCode_1X = '10' | '11' | '13' | '14' | '15' | '1I'
5
+
6
+ /**
7
+ * Enum representing unit type codes starting with '1'.
8
+ */
9
+ export enum UnitTypeCodeEnum_1X {
10
+ Group = '10',
11
+ Outfit = '11',
12
+ Ration = '13',
13
+ Shot = '14',
14
+ StickMilitary = '15',
15
+ FixedRate = '1I',
16
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Unit type codes starting with '2'.
3
+ */
4
+ export type UnitTypeCode_2X =
5
+ | '20'
6
+ | '21'
7
+ | '22'
8
+ | '23'
9
+ | '24'
10
+ | '25'
11
+ | '27'
12
+ | '28'
13
+ | '2A'
14
+ | '2B'
15
+ | '2C'
16
+ | '2G'
17
+ | '2H'
18
+ | '2I'
19
+ | '2J'
20
+ | '2K'
21
+ | '2L'
22
+ | '2M'
23
+ | '2N'
24
+ | '2P'
25
+ | '2Q'
26
+ | '2R'
27
+ | '2U'
28
+ | '2X'
29
+ | '2Y'
30
+ | '2Z'
31
+
32
+ /**
33
+ * Enum representing unit type codes starting with '2'.
34
+ */
35
+ export enum UnitTypeCodeEnum_2X {
36
+ TwentyFootContainer = '20',
37
+ FortyFootContainer = '21',
38
+ DecilitrePerGram = '22',
39
+ GramPerCubicCentimetre = '23',
40
+ TheoreticalPound = '24',
41
+ GramPerSquareCentimetre = '25',
42
+ TheoreticalTon = '27',
43
+ KilogramPerSquareMetre = '28',
44
+ RadianPerSecond = '2A',
45
+ RadianPerSecondSquared = '2B',
46
+ Roentgen = '2C',
47
+ VoltAC = '2G',
48
+ VoltDC = '2H',
49
+ BritishThermalUnitInternationalTablePerHour = '2I',
50
+ CubicCentimetrePerSecond = '2J',
51
+ CubicFootPerHour = '2K',
52
+ CubicFootPerMinute = '2L',
53
+ CentimetrePerSecond = '2M',
54
+ Decibel = '2N',
55
+ Kilobyte = '2P',
56
+ Kilobecquerel = '2Q',
57
+ Kilocurie = '2R',
58
+ Megagram = '2U',
59
+ MetrePerMinute = '2X',
60
+ Milliroentgen = '2Y',
61
+ Millivolt = '2Z',
62
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Unit type codes starting with '3'.
3
+ */
4
+ export type UnitTypeCode_3X = '33' | '34' | '35' | '37' | '38' | '3B' | '3C'
5
+
6
+ /**
7
+ * Enum representing unit type codes starting with '3'.
8
+ */
9
+ export enum UnitTypeCodeEnum_3X {
10
+ KilopascalSquareMetrePerGram = '33',
11
+ KilopascalPerMillimetre = '34',
12
+ MillilitrePerSquareCentimetreSecond = '35',
13
+ OuncePerSquareFoot = '37',
14
+ OuncePerSquareFootPer0_01inch = '38',
15
+ Megajoule = '3B',
16
+ Manmonth = '3C',
17
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Unit type codes starting with '4'.
3
+ */
4
+ export type UnitTypeCode_4X =
5
+ | '40'
6
+ | '41'
7
+ | '4C'
8
+ | '4G'
9
+ | '4H'
10
+ | '4K'
11
+ | '4L'
12
+ | '4M'
13
+ | '4N'
14
+ | '4O'
15
+ | '4P'
16
+ | '4Q'
17
+ | '4R'
18
+ | '4T'
19
+ | '4U'
20
+ | '4W'
21
+ | '4X'
22
+
23
+ /**
24
+ * Enum representing unit type codes starting with '4'.
25
+ */
26
+ export enum UnitTypeCodeEnum_4X {
27
+ MillilitrePerSecond = '40',
28
+ MillilitrePerMinute = '41',
29
+ Centistokes = '4C',
30
+ Microlitre = '4G',
31
+ MicrometreMicron = '4H',
32
+ Milliampere = '4K',
33
+ Megabyte = '4L',
34
+ MilligramPerHour = '4M',
35
+ Megabecquerel = '4N',
36
+ Microfarad = '4O',
37
+ NewtonPerMetre = '4P',
38
+ OunceInch = '4Q',
39
+ OunceFoot = '4R',
40
+ Picofarad = '4T',
41
+ PoundPerHour = '4U',
42
+ TonUSPerHour = '4W',
43
+ KilolitrePerHour = '4X',
44
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Unit type codes starting with '5'.
3
+ */
4
+ export type UnitTypeCode_5X =
5
+ | '56'
6
+ | '57'
7
+ | '58'
8
+ | '59'
9
+ | '5A'
10
+ | '5B'
11
+ | '5E'
12
+ | '5J'
13
+
14
+ /**
15
+ * Enum representing unit type codes starting with '5'.
16
+ */
17
+ export enum UnitTypeCodeEnum_5X {
18
+ Sitas = '56',
19
+ Mesh = '57',
20
+ NetKilogram = '58',
21
+ PartPerMillion = '59',
22
+ BarrelUSPerMinute = '5A',
23
+ Batch = '5B',
24
+ MMSCFDay = '5E',
25
+ HydraulicHorsePower = '5J',
26
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Unit type codes starting with '6'.
3
+ */
4
+ export type UnitTypeCode_6X = '60' | '61'
5
+
6
+ /**
7
+ * Enum representing unit type codes starting with '6'.
8
+ */
9
+ export enum UnitTypeCodeEnum_6X {
10
+ PercentWeight = '60',
11
+ PartPerBillionUS = '61',
12
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Unit type codes starting with '7'.
3
+ */
4
+ export type UnitTypeCode_7X = '74' | '77'
5
+
6
+ /**
7
+ * Enum representing unit type codes starting with '7'.
8
+ */
9
+ export enum UnitTypeCodeEnum_7X {
10
+ Millipascal = '74',
11
+ MilliInch = '77',
12
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Unit type codes starting with '8'.
3
+ */
4
+ export type UnitTypeCode_8X = '80' | '81' | '85' | '87' | '89'
5
+
6
+ /**
7
+ * Enum representing unit type codes starting with '8'.
8
+ */
9
+ export enum UnitTypeCodeEnum_8X {
10
+ PoundPerSquareInchAbsolute = '80',
11
+ Henry = '81',
12
+ FootPoundForce = '85',
13
+ PoundPerCubicFoot = '87',
14
+ Poise = '89',
15
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Unit type codes starting with '9'.
3
+ */
4
+ export type UnitTypeCode_9X = '91'
5
+
6
+ /**
7
+ * Enum representing unit type codes starting with '9'.
8
+ */
9
+ export enum UnitTypeCodeEnum_9X {
10
+ Stokes = '91',
11
+ }
@@ -0,0 +1,202 @@
1
+ /**
2
+ * Unit type codes starting with 'A'.
3
+ */
4
+ export type UnitTypeCode_AX =
5
+ | 'A10'
6
+ | 'A11'
7
+ | 'A12'
8
+ | 'A13'
9
+ | 'A14'
10
+ | 'A15'
11
+ | 'A16'
12
+ | 'A17'
13
+ | 'A18'
14
+ | 'A19'
15
+ | 'A2'
16
+ | 'A20'
17
+ | 'A21'
18
+ | 'A22'
19
+ | 'A23'
20
+ | 'A24'
21
+ | 'A26'
22
+ | 'A27'
23
+ | 'A28'
24
+ | 'A29'
25
+ | 'A3'
26
+ | 'A30'
27
+ | 'A31'
28
+ | 'A32'
29
+ | 'A33'
30
+ | 'A34'
31
+ | 'A35'
32
+ | 'A36'
33
+ | 'A37'
34
+ | 'A38'
35
+ | 'A39'
36
+ | 'A4'
37
+ | 'A40'
38
+ | 'A41'
39
+ | 'A42'
40
+ | 'A43'
41
+ | 'A44'
42
+ | 'A45'
43
+ | 'A47'
44
+ | 'A48'
45
+ | 'A49'
46
+ | 'A5'
47
+ | 'A53'
48
+ | 'A54'
49
+ | 'A55'
50
+ | 'A56'
51
+ | 'A59'
52
+ | 'A6'
53
+ | 'A68'
54
+ | 'A69'
55
+ | 'A7'
56
+ | 'A70'
57
+ | 'A71'
58
+ | 'A73'
59
+ | 'A74'
60
+ | 'A75'
61
+ | 'A76'
62
+ | 'A8'
63
+ | 'A84'
64
+ | 'A85'
65
+ | 'A86'
66
+ | 'A87'
67
+ | 'A88'
68
+ | 'A89'
69
+ | 'A9'
70
+ | 'A90'
71
+ | 'A91'
72
+ | 'A93'
73
+ | 'A94'
74
+ | 'A95'
75
+ | 'A96'
76
+ | 'A97'
77
+ | 'A98'
78
+ | 'A99'
79
+ | 'AA'
80
+ | 'AB'
81
+ | 'ACR'
82
+ | 'ACT'
83
+ | 'AD'
84
+ | 'AE'
85
+ | 'AH'
86
+ | 'AI'
87
+ | 'AK'
88
+ | 'AL'
89
+ | 'AMH'
90
+ | 'AMP'
91
+ | 'ANN'
92
+ | 'APZ'
93
+ | 'AQ'
94
+ | 'AS'
95
+ | 'ASM'
96
+ | 'ASU'
97
+ | 'ATM'
98
+ | 'AWG'
99
+ | 'AY'
100
+ | 'AZ'
101
+
102
+ /**
103
+ * Enum representing unit type codes starting with 'A'.
104
+ */
105
+ export enum UnitTypeCodeEnum_AX {
106
+ AmpereSquareMetrePerJouleSecond = 'A10',
107
+ Angstrom = 'A11',
108
+ AstronomicalUnit = 'A12',
109
+ Attojoule = 'A13',
110
+ Barn = 'A14',
111
+ BarnPerElectronvolt = 'A15',
112
+ BarnPerSteradianElectronvolt = 'A16',
113
+ BarnPerSteradian = 'A17',
114
+ BecquerelPerKilogram = 'A18',
115
+ BecquerelPerCubicMetre = 'A19',
116
+ AmperePerCentimetre = 'A2',
117
+ BritishThermalUnitInternationalTablePerSecondSquareFootDegreeRankine = 'A20',
118
+ BritishThermalUnitInternationalTablePerPoundDegreeRankine = 'A21',
119
+ BritishThermalUnitInternationalTablePerSecondFootDegreeRankine = 'A22',
120
+ BritishThermalUnitInternationalTablePerHourSquareFootDegreeRankine = 'A23',
121
+ CandelaPerSquareMetre = 'A24',
122
+ CoulombMetre = 'A26',
123
+ CoulombMetreSquaredPerVolt = 'A27',
124
+ CoulombPerCubicCentimetre = 'A28',
125
+ CoulombPerCubicMetre = 'A29',
126
+ AmperePerMillimetre = 'A3',
127
+ CoulombPerCubicMillimetre = 'A30',
128
+ CoulombPerKilogramSecond = 'A31',
129
+ CoulombPerMole = 'A32',
130
+ CoulombPerSquareCentimetre = 'A33',
131
+ CoulombPerSquareMetre = 'A34',
132
+ CoulombPerSquareMillimetre = 'A35',
133
+ CubicCentimetrePerMole = 'A36',
134
+ CubicDecimetrePerMole = 'A37',
135
+ CubicMetrePerCoulomb = 'A38',
136
+ CubicMetrePerKilogram = 'A39',
137
+ AmperePerSquareCentimetre = 'A4',
138
+ CubicMetrePerMole = 'A40',
139
+ AmperePerSquareMetre = 'A41',
140
+ CuriePerKilogram = 'A42',
141
+ DeadweightTonnage = 'A43',
142
+ Decalitre = 'A44',
143
+ Decametre = 'A45',
144
+ Decitex = 'A47',
145
+ DegreeRankine = 'A48',
146
+ Denier = 'A49',
147
+ AmpereSquareMetre = 'A5',
148
+ Electronvolt = 'A53',
149
+ ElectronvoltPerMetre = 'A54',
150
+ ElectronvoltSquareMetre = 'A55',
151
+ ElectronvoltSquareMetrePerKilogram = 'A56',
152
+ _8PartCloudCover = 'A59', // Enum member names cannot start with a number
153
+ AmperePerSquareMetreKelvinSquared = 'A6',
154
+ Exajoule = 'A68',
155
+ FaradPerMetre = 'A69',
156
+ AmperePerSquareMillimetre = 'A7',
157
+ Femtojoule = 'A70',
158
+ Femtometre = 'A71',
159
+ FootPerSecondSquared = 'A73',
160
+ FootPoundForcePerSecond = 'A74',
161
+ FreightTon = 'A75',
162
+ Gal = 'A76',
163
+ AmpereSecond = 'A8',
164
+ GigacoulombPerCubicMetre = 'A84',
165
+ Gigaelectronvolt = 'A85',
166
+ Gigahertz = 'A86',
167
+ Gigaohm = 'A87',
168
+ GigaohmMetre = 'A88',
169
+ Gigapascal = 'A89',
170
+ Rate = 'A9',
171
+ Gigawatt = 'A90',
172
+ Gon = 'A91',
173
+ GramPerCubicMetre = 'A93',
174
+ GramPerMole = 'A94',
175
+ Gray = 'A95',
176
+ GrayPerSecond = 'A96',
177
+ Hectopascal = 'A97',
178
+ HenryPerMetre = 'A98',
179
+ Bit = 'A99',
180
+ Ball = 'AA',
181
+ BulkPack = 'AB',
182
+ Acre = 'ACR',
183
+ Activity = 'ACT',
184
+ Byte = 'AD',
185
+ AmperePerMetre = 'AE',
186
+ AdditionalMinute = 'AH',
187
+ AverageMinutePerCall = 'AI',
188
+ Fathom = 'AK',
189
+ AccessLine = 'AL',
190
+ AmpereHour = 'AMH',
191
+ Ampere = 'AMP',
192
+ Year = 'ANN',
193
+ TroyOunceOrApothecaryOunce = 'APZ',
194
+ AntiHemophilicFactorAHFUnit = 'AQ',
195
+ Assortment = 'AS',
196
+ AlcoholicStrengthByMass = 'ASM',
197
+ AlcoholicStrengthByVolume = 'ASU',
198
+ StandardAtmosphere = 'ATM',
199
+ AmericanWireGauge = 'AWG',
200
+ Assembly = 'AY',
201
+ BritishThermalUnitInternationalTablePerPound = 'AZ',
202
+ }