storemw-core-client 1.0.1

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 (112) hide show
  1. package/.env +1 -0
  2. package/.vscode/launch.json +24 -0
  3. package/dist/config/config.d.ts +6 -0
  4. package/dist/config/config.js +13 -0
  5. package/dist/config/env.d.ts +7 -0
  6. package/dist/config/env.js +16 -0
  7. package/dist/config/index.d.ts +2 -0
  8. package/dist/config/index.js +8 -0
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.js +32 -0
  11. package/dist/lib/ApiService.d.ts +41 -0
  12. package/dist/lib/ApiService.js +143 -0
  13. package/dist/lib/index.d.ts +4 -0
  14. package/dist/lib/index.js +9 -0
  15. package/dist/lib/queryParams.d.ts +43 -0
  16. package/dist/lib/queryParams.js +99 -0
  17. package/dist/services/account/AccountService.d.ts +52 -0
  18. package/dist/services/account/AccountService.js +119 -0
  19. package/dist/services/auth/AuthService.d.ts +44 -0
  20. package/dist/services/auth/AuthService.js +76 -0
  21. package/dist/services/branch/BranchService.d.ts +124 -0
  22. package/dist/services/branch/BranchService.js +162 -0
  23. package/dist/services/business/BusinessService.d.ts +91 -0
  24. package/dist/services/business/BusinessService.js +153 -0
  25. package/dist/services/document/DocumentService.d.ts +578 -0
  26. package/dist/services/document/DocumentService.js +615 -0
  27. package/dist/services/index.d.ts +36 -0
  28. package/dist/services/index.js +97 -0
  29. package/dist/services/injection_field/InjectionFieldService.d.ts +113 -0
  30. package/dist/services/injection_field/InjectionFieldService.js +220 -0
  31. package/dist/services/inventory/InventoryService.d.ts +27 -0
  32. package/dist/services/inventory/InventoryService.js +231 -0
  33. package/dist/services/item/ItemService.d.ts +227 -0
  34. package/dist/services/item/ItemService.js +411 -0
  35. package/dist/services/location/LocationService.d.ts +154 -0
  36. package/dist/services/location/LocationService.js +256 -0
  37. package/dist/services/logistic/LogisticService.d.ts +104 -0
  38. package/dist/services/logistic/LogisticService.js +150 -0
  39. package/dist/services/permission/PermissionService.d.ts +296 -0
  40. package/dist/services/permission/PermissionService.js +576 -0
  41. package/dist/services/permission/config/custom/adminPermission.d.ts +4 -0
  42. package/dist/services/permission/config/custom/adminPermission.js +18 -0
  43. package/dist/services/permission/config/custom/config.d.ts +40 -0
  44. package/dist/services/permission/config/custom/config.js +23 -0
  45. package/dist/services/permission/config/default/adminPermission.d.ts +2 -0
  46. package/dist/services/permission/config/default/adminPermission.js +129 -0
  47. package/dist/services/permission/config/default/agentPermission.d.ts +2 -0
  48. package/dist/services/permission/config/default/agentPermission.js +43 -0
  49. package/dist/services/permission/config/default/customerPermission.d.ts +2 -0
  50. package/dist/services/permission/config/default/customerPermission.js +10 -0
  51. package/dist/services/permission/config/default/driverPermission.d.ts +2 -0
  52. package/dist/services/permission/config/default/driverPermission.js +4 -0
  53. package/dist/services/permission/config/default/workerPermission.d.ts +2 -0
  54. package/dist/services/permission/config/default/workerPermission.js +25 -0
  55. package/dist/services/rate/RateService.d.ts +201 -0
  56. package/dist/services/rate/RateService.js +303 -0
  57. package/dist/services/region/RegionService.d.ts +111 -0
  58. package/dist/services/region/RegionService.js +193 -0
  59. package/dist/services/repository/RepositoryService.d.ts +153 -0
  60. package/dist/services/repository/RepositoryService.js +243 -0
  61. package/dist/services/transaction/TransactionService.d.ts +153 -0
  62. package/dist/services/transaction/TransactionService.js +173 -0
  63. package/dist/services/user/BranchUserService.d.ts +129 -0
  64. package/dist/services/user/BranchUserService.js +193 -0
  65. package/dist/services/user/UserRoleService.d.ts +105 -0
  66. package/dist/services/user/UserRoleService.js +193 -0
  67. package/dist/services/user/UserService.d.ts +269 -0
  68. package/dist/services/user/UserService.js +477 -0
  69. package/dist/services/wallet/WalletService.d.ts +104 -0
  70. package/dist/services/wallet/WalletService.js +163 -0
  71. package/dist/utils/dateUtils.d.ts +6 -0
  72. package/dist/utils/dateUtils.js +28 -0
  73. package/dist/utils/index.d.ts +2 -0
  74. package/dist/utils/index.js +13 -0
  75. package/package.json +27 -0
  76. package/src/config/config.ts +15 -0
  77. package/src/config/env.ts +18 -0
  78. package/src/config/index.ts +2 -0
  79. package/src/index.ts +41 -0
  80. package/src/lib/ApiService.ts +170 -0
  81. package/src/lib/index.ts +5 -0
  82. package/src/lib/queryParams.ts +162 -0
  83. package/src/services/account/AccountService.ts +232 -0
  84. package/src/services/auth/AuthService.ts +125 -0
  85. package/src/services/branch/BranchService.ts +330 -0
  86. package/src/services/business/BusinessService.ts +277 -0
  87. package/src/services/document/DocumentService.ts +1471 -0
  88. package/src/services/index.ts +73 -0
  89. package/src/services/injection_field/InjectionFieldService.ts +483 -0
  90. package/src/services/inventory/InventoryService.ts +314 -0
  91. package/src/services/item/ItemService.ts +707 -0
  92. package/src/services/location/LocationService.ts +505 -0
  93. package/src/services/logistic/LogisticService.ts +285 -0
  94. package/src/services/permission/PermissionService.ts +1069 -0
  95. package/src/services/permission/config/custom/adminPermission.ts +19 -0
  96. package/src/services/permission/config/custom/config.ts +39 -0
  97. package/src/services/permission/config/default/adminPermission.ts +129 -0
  98. package/src/services/permission/config/default/agentPermission.ts +42 -0
  99. package/src/services/permission/config/default/customerPermission.ts +9 -0
  100. package/src/services/permission/config/default/driverPermission.ts +4 -0
  101. package/src/services/permission/config/default/workerPermission.ts +25 -0
  102. package/src/services/rate/RateService.ts +570 -0
  103. package/src/services/region/RegionService.ts +353 -0
  104. package/src/services/repository/RepositoryService.ts +437 -0
  105. package/src/services/transaction/TransactionService.ts +404 -0
  106. package/src/services/user/BranchUserService.ts +381 -0
  107. package/src/services/user/UserRoleService.ts +342 -0
  108. package/src/services/user/UserService.ts +807 -0
  109. package/src/services/wallet/WalletService.ts +300 -0
  110. package/src/utils/dateUtils.ts +26 -0
  111. package/src/utils/index.ts +2 -0
  112. package/tsconfig.json +119 -0
@@ -0,0 +1,404 @@
1
+ import { ApiService, ApiServiceType } from '@/lib';
2
+
3
+ import {
4
+ buildApiListUrl,
5
+ BuildApiListParamsProps,
6
+ buildApiGetUrl,
7
+ BuildApiGetParamsProps,
8
+ filterOperatorTypes
9
+ } from '@/lib';
10
+
11
+ export const transactionTypes = {
12
+ request: "request",
13
+ wallet: "wallet"
14
+ } as const
15
+
16
+ export const transactionActionTypes = {
17
+ requestTransfer: "wallet_transfer",
18
+ requestTopup: "wallet_topup",
19
+ requestWithdraw: "wallet_withdraw",
20
+ walletTransfer: "transfer",
21
+ walletTopup: "topup",
22
+ walletWithdraw: "withdraw",
23
+ walletPayment: "payment"
24
+ } as const
25
+
26
+ export const transactionTargetTypes = {
27
+ request: "request",
28
+ wallet: "wallet"
29
+ } as const
30
+
31
+ export type TransactionType = typeof transactionTypes[keyof typeof transactionTypes] // keyof typeof transactionTypes
32
+ export type TransactionTargetType = typeof transactionTargetTypes[keyof typeof transactionTargetTypes]
33
+ export type TransactionTargetKey = keyof typeof transactionTargetTypes
34
+ export type TransactionActionType = typeof transactionActionTypes[keyof typeof transactionActionTypes]
35
+
36
+ // export const walletCurrencyTypes = {
37
+ // myr: "MYR",
38
+ // sgd: "SGD",
39
+ // usd: "USD",
40
+ // cny: "CNY"
41
+ // } as const
42
+
43
+ // type Currency = typeof walletCurrencyTypes[keyof typeof walletCurrencyTypes]
44
+
45
+ export type TransactionServiceProps = ApiServiceType & {
46
+ transactionTargetType?: TransactionTargetType
47
+ transactionType?: TransactionType
48
+ };
49
+
50
+ export type ListTransactionProps = BuildApiListParamsProps & {
51
+ transactionType?: TransactionType
52
+ }
53
+
54
+ export type GetTransactionProps = BuildApiGetParamsProps & {
55
+ id: number | string
56
+ transactionType?: TransactionType
57
+ }
58
+
59
+ // type Transaction = {
60
+ // id: string;
61
+ // transactionNo: string | null;
62
+ // sourceTarget: string;
63
+ // sourceModule: string;
64
+ // sourceRef: string;
65
+ // sourceReferId: string;
66
+ // destinationTarget: string;
67
+ // destinationModule: string;
68
+ // destinationRef: string;
69
+ // destinationReferId: string;
70
+ // action: string;
71
+ // type: "WALLET" | "REQUEST";
72
+ // referenceNo: string | null;
73
+ // transactionAmount: string; // keeping string since it has decimal precision
74
+ // transactionStatus: "pending" | "completed" | "cancelled";
75
+ // description: string | null;
76
+ // remark: string | null;
77
+ // transactionDate: string | null; // could change to Date if API always returns ISO
78
+ // internalReferenceNo: string | null;
79
+ // internalRemark: string | null;
80
+ // }
81
+
82
+ type TransactionSource = {
83
+ sourceTarget: "wallet",
84
+ sourceModule: "wallet_user",
85
+ transactionRef: "wallet_user",
86
+ sourceRefFieldName: "wallet_user_id",
87
+ }
88
+
89
+ export type CreateTransactionProps = {
90
+ transactionTargetType?: TransactionTargetType
91
+ transactionActionType?: TransactionActionType
92
+ data:
93
+ // for Request Transfer - requestTransfer
94
+ {
95
+ requestTransfer: {
96
+ source: {
97
+ action: "wallet_transfer",
98
+ refId: number
99
+ } & TransactionSource,
100
+ destination: {
101
+ action: "wallet_transfer",
102
+ refId: number
103
+ } & TransactionSource
104
+ }
105
+ } |
106
+ // for Request Topup - requestTopup
107
+ {
108
+ requestTopup: {
109
+ source: {
110
+ action: "wallet_topup",
111
+ refId: number
112
+ } & TransactionSource,
113
+ // destination: {
114
+ // action: "wallet_topup",
115
+ // } & TransactionSource
116
+ }
117
+ } |
118
+ // for Request Withdraw - requestWithdraw
119
+ {
120
+ requestWithdraw: {
121
+ source: {
122
+ action: "wallet_withdraw",
123
+ refId: number
124
+ } & TransactionSource,
125
+ // destination: {
126
+ // action: "wallet_withdraw",
127
+ // } & TransactionSource
128
+ }
129
+ } |
130
+ // for Wallet Transfer - walletTransfer
131
+ {
132
+ walletTransfer: {
133
+ source: {
134
+ action: "transfer",
135
+ refId: number
136
+ } & TransactionSource
137
+ destination: {
138
+ action: "transfer",
139
+ refId: number
140
+ } & TransactionSource
141
+ }
142
+ } |
143
+ // for Wallet Topup - walletTopup
144
+ {
145
+ walletTopup: {
146
+ source: {
147
+ action: "topup",
148
+ refId: number
149
+ } & TransactionSource,
150
+ // destination: {
151
+ // action: "topup",
152
+ // } & TransactionSource
153
+ }
154
+ } |
155
+ // for Wallet Withdraw - walletWithdraw
156
+ {
157
+ walletWithdraw: {
158
+ source: {
159
+ action: "withdraw",
160
+ refId: number
161
+ } & TransactionSource
162
+ destination: {
163
+ action: "withdraw",
164
+ } & TransactionSource
165
+ }
166
+ } |
167
+ // for Wallet Payment - walletPayment
168
+ {
169
+ walletPayment: {
170
+ source: {
171
+ action: "payment",
172
+ refId: number
173
+ } & TransactionSource
174
+ destination: {
175
+ action: "payment",
176
+ } & TransactionSource
177
+ }
178
+ }
179
+ }
180
+
181
+ export type UpdateStatusTransactionProps = {
182
+ id: number
183
+ transactionTargetType?: TransactionTargetType
184
+ data:
185
+ // for all
186
+ {
187
+ status: "approved" | "cancelled", /** approved, cancelled */
188
+ transactionDate: string,
189
+ internalReferenceNo: string,
190
+ internalRemark: string
191
+ }
192
+ }
193
+
194
+ export type RemoveTransactionProps = {
195
+ transactionTargetType?: TransactionTargetType
196
+ ids: number[]
197
+ }
198
+
199
+ export type GetDataTypeTransactionProps = {
200
+ transactionType?: TransactionTargetType
201
+ }
202
+
203
+ const getCreatePayload = (transactionActionType: TransactionActionType, data: CreateTransactionProps["data"]) => {
204
+
205
+ if (transactionActionType === "wallet_transfer" && "requestTransfer" in data) {
206
+ return {
207
+ source: {
208
+ target: data.requestTransfer.source.sourceTarget,
209
+ module: data.requestTransfer.source.sourceModule,
210
+ transaction_ref: data.requestTransfer.source.transactionRef,
211
+ ref_id: {
212
+ [data.requestTransfer.source.sourceRefFieldName]: data.requestTransfer.source.refId
213
+ }
214
+ },
215
+ destination: {
216
+ target: data.requestTransfer.destination.sourceTarget,
217
+ module: data.requestTransfer.destination.sourceModule,
218
+ transaction_ref: data.requestTransfer.destination.transactionRef,
219
+ ref_id: {
220
+ [data.requestTransfer.destination.sourceRefFieldName]: data.requestTransfer.destination.refId
221
+ }
222
+ }
223
+ }
224
+ }
225
+
226
+ if (transactionActionType === "wallet_withdraw" && "requestWithdraw" in data) {
227
+ return {
228
+ source: {
229
+ target: data.requestWithdraw.source.sourceTarget,
230
+ module: data.requestWithdraw.source.sourceModule,
231
+ transaction_ref: data.requestWithdraw.source.transactionRef,
232
+ ref_id: {
233
+ [data.requestWithdraw.source.sourceRefFieldName]: data.requestWithdraw.source.refId
234
+ }
235
+ },
236
+ // destination: {
237
+ // target: data.requestWithdraw.destination.sourceTarget,
238
+ // module: data.requestWithdraw.destination.sourceModule,
239
+ // transaction_ref: data.requestWithdraw.destination.transactionRef,
240
+ // ref_id: {
241
+ // [data.requestWithdraw.destination.sourceRefFieldName]: data.requestWithdraw.destination.refId
242
+ // }
243
+ // }
244
+ }
245
+ }
246
+
247
+ if (transactionActionType === "wallet_topup" && "requestTopup" in data) {
248
+ return {
249
+ source: {
250
+ target: data.requestTopup.source.sourceTarget,
251
+ module: data.requestTopup.source.sourceModule,
252
+ transaction_ref: data.requestTopup.source.transactionRef,
253
+ ref_id: {
254
+ [data.requestTopup.source.sourceRefFieldName]: data.requestTopup.source.refId
255
+ }
256
+ },
257
+ // destination: {
258
+ // target: data.requestWithdraw.destination.sourceTarget,
259
+ // module: data.requestWithdraw.destination.sourceModule,
260
+ // transaction_ref: data.requestWithdraw.destination.transactionRef,
261
+ // ref_id: {
262
+ // [data.requestWithdraw.destination.sourceRefFieldName]: data.requestWithdraw.destination.refId
263
+ // }
264
+ // }
265
+ }
266
+ }
267
+
268
+ }
269
+
270
+
271
+ const getUpdatePayload = (data: UpdateStatusTransactionProps["data"]) => {
272
+
273
+ return {
274
+ transaction: {
275
+ status: data.status,
276
+ transaction_date: data.transactionDate,
277
+ internal_reference_no: data.internalReferenceNo,
278
+ internal_remark: data.internalRemark
279
+ }
280
+ }
281
+
282
+ }
283
+
284
+
285
+ export const TransactionService = (props?: TransactionServiceProps) => {
286
+
287
+ const { transactionType = "wallet", transactionTargetType, ...rest } = props ?? {};
288
+
289
+ const { makeCall } = ApiService(rest?.customToken ? { customToken: rest.customToken } : {})
290
+
291
+ const endpoint1 = "transaction";
292
+ const endpoint2 = "transactions"
293
+
294
+ const list = async (props: ListTransactionProps) => {
295
+
296
+ const { transactionType: overrideTransactionType } = props;
297
+
298
+ const url = buildApiListUrl(
299
+ `${endpoint2}/${overrideTransactionType || transactionType}`,
300
+ props
301
+ );
302
+
303
+ const response = await makeCall({
304
+ url,
305
+ method: "get",
306
+ payload: {},
307
+ // configuration
308
+ });
309
+
310
+ return response;
311
+
312
+ }
313
+
314
+ const get = async (props: GetTransactionProps) => {
315
+
316
+ const { id, transactionType: overrideTransactionType } = props;
317
+
318
+ const url = buildApiGetUrl(
319
+ `${endpoint1}/${overrideTransactionType || transactionType}/${id}`,
320
+ props
321
+ );
322
+
323
+ const response = await makeCall({
324
+ url,
325
+ method: "get",
326
+ payload: {},
327
+ // configuration
328
+ });
329
+
330
+ return response;
331
+
332
+ }
333
+
334
+ const create = async ({ data, transactionActionType = "wallet_topup", transactionTargetType: overrideTransactionTargetType }: CreateTransactionProps) => {
335
+
336
+ let _transactionType = transactionActionType
337
+
338
+ let payload: any = getCreatePayload(_transactionType, data)
339
+
340
+ let url = `${endpoint1}`;
341
+
342
+ let postData = {
343
+ scope: {
344
+ target: overrideTransactionTargetType || transactionTargetType,
345
+ action: "",
346
+ },
347
+ payload
348
+ }
349
+
350
+ const response = await makeCall({
351
+ url,
352
+ method: "post",
353
+ payload: postData
354
+ });
355
+
356
+ return response;
357
+
358
+ }
359
+
360
+ const updateStatus = async ({ id, data, transactionTargetType: overrideTransactionTargetType }: UpdateStatusTransactionProps) => {
361
+
362
+ let url = `${endpoint1}/status/${id}`
363
+
364
+ let payload: any = getUpdatePayload(data)
365
+
366
+ const postData = {
367
+ scope: {
368
+ target: overrideTransactionTargetType || transactionTargetType,
369
+ action: "",
370
+ },
371
+ payload
372
+ }
373
+
374
+ const response = await makeCall({
375
+ url,
376
+ method: "put",
377
+ payload: postData
378
+ });
379
+
380
+ return response;
381
+
382
+ }
383
+
384
+ const getDataTypes = async ({ transactionType: overrideTransactionType }: GetDataTypeTransactionProps) => {
385
+
386
+ let url = `${endpoint1}/data_types/${overrideTransactionType || transactionType}`
387
+
388
+ const response = await makeCall({
389
+ url,
390
+ method: "get",
391
+ });
392
+
393
+ return response;
394
+
395
+ }
396
+
397
+ return {
398
+ list,
399
+ get,
400
+ create,
401
+ updateStatus,
402
+ getDataTypes,
403
+ };
404
+ }