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.
- package/.env +1 -0
- package/.vscode/launch.json +24 -0
- package/dist/config/config.d.ts +6 -0
- package/dist/config/config.js +13 -0
- package/dist/config/env.d.ts +7 -0
- package/dist/config/env.js +16 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +8 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +32 -0
- package/dist/lib/ApiService.d.ts +41 -0
- package/dist/lib/ApiService.js +143 -0
- package/dist/lib/index.d.ts +4 -0
- package/dist/lib/index.js +9 -0
- package/dist/lib/queryParams.d.ts +43 -0
- package/dist/lib/queryParams.js +99 -0
- package/dist/services/account/AccountService.d.ts +52 -0
- package/dist/services/account/AccountService.js +119 -0
- package/dist/services/auth/AuthService.d.ts +44 -0
- package/dist/services/auth/AuthService.js +76 -0
- package/dist/services/branch/BranchService.d.ts +124 -0
- package/dist/services/branch/BranchService.js +162 -0
- package/dist/services/business/BusinessService.d.ts +91 -0
- package/dist/services/business/BusinessService.js +153 -0
- package/dist/services/document/DocumentService.d.ts +578 -0
- package/dist/services/document/DocumentService.js +615 -0
- package/dist/services/index.d.ts +36 -0
- package/dist/services/index.js +97 -0
- package/dist/services/injection_field/InjectionFieldService.d.ts +113 -0
- package/dist/services/injection_field/InjectionFieldService.js +220 -0
- package/dist/services/inventory/InventoryService.d.ts +27 -0
- package/dist/services/inventory/InventoryService.js +231 -0
- package/dist/services/item/ItemService.d.ts +227 -0
- package/dist/services/item/ItemService.js +411 -0
- package/dist/services/location/LocationService.d.ts +154 -0
- package/dist/services/location/LocationService.js +256 -0
- package/dist/services/logistic/LogisticService.d.ts +104 -0
- package/dist/services/logistic/LogisticService.js +150 -0
- package/dist/services/permission/PermissionService.d.ts +296 -0
- package/dist/services/permission/PermissionService.js +576 -0
- package/dist/services/permission/config/custom/adminPermission.d.ts +4 -0
- package/dist/services/permission/config/custom/adminPermission.js +18 -0
- package/dist/services/permission/config/custom/config.d.ts +40 -0
- package/dist/services/permission/config/custom/config.js +23 -0
- package/dist/services/permission/config/default/adminPermission.d.ts +2 -0
- package/dist/services/permission/config/default/adminPermission.js +129 -0
- package/dist/services/permission/config/default/agentPermission.d.ts +2 -0
- package/dist/services/permission/config/default/agentPermission.js +43 -0
- package/dist/services/permission/config/default/customerPermission.d.ts +2 -0
- package/dist/services/permission/config/default/customerPermission.js +10 -0
- package/dist/services/permission/config/default/driverPermission.d.ts +2 -0
- package/dist/services/permission/config/default/driverPermission.js +4 -0
- package/dist/services/permission/config/default/workerPermission.d.ts +2 -0
- package/dist/services/permission/config/default/workerPermission.js +25 -0
- package/dist/services/rate/RateService.d.ts +201 -0
- package/dist/services/rate/RateService.js +303 -0
- package/dist/services/region/RegionService.d.ts +111 -0
- package/dist/services/region/RegionService.js +193 -0
- package/dist/services/repository/RepositoryService.d.ts +153 -0
- package/dist/services/repository/RepositoryService.js +243 -0
- package/dist/services/transaction/TransactionService.d.ts +153 -0
- package/dist/services/transaction/TransactionService.js +173 -0
- package/dist/services/user/BranchUserService.d.ts +129 -0
- package/dist/services/user/BranchUserService.js +193 -0
- package/dist/services/user/UserRoleService.d.ts +105 -0
- package/dist/services/user/UserRoleService.js +193 -0
- package/dist/services/user/UserService.d.ts +269 -0
- package/dist/services/user/UserService.js +477 -0
- package/dist/services/wallet/WalletService.d.ts +104 -0
- package/dist/services/wallet/WalletService.js +163 -0
- package/dist/utils/dateUtils.d.ts +6 -0
- package/dist/utils/dateUtils.js +28 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +13 -0
- package/package.json +27 -0
- package/src/config/config.ts +15 -0
- package/src/config/env.ts +18 -0
- package/src/config/index.ts +2 -0
- package/src/index.ts +41 -0
- package/src/lib/ApiService.ts +170 -0
- package/src/lib/index.ts +5 -0
- package/src/lib/queryParams.ts +162 -0
- package/src/services/account/AccountService.ts +232 -0
- package/src/services/auth/AuthService.ts +125 -0
- package/src/services/branch/BranchService.ts +330 -0
- package/src/services/business/BusinessService.ts +277 -0
- package/src/services/document/DocumentService.ts +1471 -0
- package/src/services/index.ts +73 -0
- package/src/services/injection_field/InjectionFieldService.ts +483 -0
- package/src/services/inventory/InventoryService.ts +314 -0
- package/src/services/item/ItemService.ts +707 -0
- package/src/services/location/LocationService.ts +505 -0
- package/src/services/logistic/LogisticService.ts +285 -0
- package/src/services/permission/PermissionService.ts +1069 -0
- package/src/services/permission/config/custom/adminPermission.ts +19 -0
- package/src/services/permission/config/custom/config.ts +39 -0
- package/src/services/permission/config/default/adminPermission.ts +129 -0
- package/src/services/permission/config/default/agentPermission.ts +42 -0
- package/src/services/permission/config/default/customerPermission.ts +9 -0
- package/src/services/permission/config/default/driverPermission.ts +4 -0
- package/src/services/permission/config/default/workerPermission.ts +25 -0
- package/src/services/rate/RateService.ts +570 -0
- package/src/services/region/RegionService.ts +353 -0
- package/src/services/repository/RepositoryService.ts +437 -0
- package/src/services/transaction/TransactionService.ts +404 -0
- package/src/services/user/BranchUserService.ts +381 -0
- package/src/services/user/UserRoleService.ts +342 -0
- package/src/services/user/UserService.ts +807 -0
- package/src/services/wallet/WalletService.ts +300 -0
- package/src/utils/dateUtils.ts +26 -0
- package/src/utils/index.ts +2 -0
- package/tsconfig.json +119 -0
|
@@ -0,0 +1,1069 @@
|
|
|
1
|
+
import { ApiService, ApiServiceType } from '@/lib';
|
|
2
|
+
|
|
3
|
+
export type AppRouteId =
|
|
4
|
+
| "operator"
|
|
5
|
+
| "administrator"
|
|
6
|
+
| "retail"
|
|
7
|
+
| "workstation"
|
|
8
|
+
| "customer"
|
|
9
|
+
| "member"
|
|
10
|
+
| "public"
|
|
11
|
+
| "driver"
|
|
12
|
+
|
|
13
|
+
/** Load Custom Configs */
|
|
14
|
+
import {
|
|
15
|
+
_customPermissionScopeTypes,
|
|
16
|
+
customPermissionScopeTypes,
|
|
17
|
+
customPermissionModuleTypes,
|
|
18
|
+
CustomPermissionMap,
|
|
19
|
+
CustomModuleTypesMap
|
|
20
|
+
} from './config/custom/config';
|
|
21
|
+
|
|
22
|
+
import { customAdminPermissionsConfig } from './config/custom/adminPermission';
|
|
23
|
+
|
|
24
|
+
export const permissionTypes = {
|
|
25
|
+
role: "role",
|
|
26
|
+
} as const
|
|
27
|
+
|
|
28
|
+
export const targetPermissionTypes = {
|
|
29
|
+
role: "role",
|
|
30
|
+
} as const
|
|
31
|
+
|
|
32
|
+
import { adminPermissionsConfig } from './config/default/adminPermission';
|
|
33
|
+
import { workerPermissionsConfig } from './config/default/workerPermission';
|
|
34
|
+
import { agentPermissionsConfig } from './config/default/agentPermission';
|
|
35
|
+
import { driverPermissionsConfig } from './config/default/driverPermission';
|
|
36
|
+
import { customerPermissionsConfig } from './config/default/customerPermission';
|
|
37
|
+
|
|
38
|
+
export type PermissionType = keyof typeof permissionTypes
|
|
39
|
+
export type PermissionTargetType = typeof targetPermissionTypes[keyof typeof targetPermissionTypes]
|
|
40
|
+
export type PermissionTargetKey = keyof typeof targetPermissionTypes
|
|
41
|
+
|
|
42
|
+
export type PermissionFunctionType =
|
|
43
|
+
| 'pageList'
|
|
44
|
+
| 'pageNew'
|
|
45
|
+
| 'pageView'
|
|
46
|
+
| 'pageUpdate'
|
|
47
|
+
| 'pageStockPost'
|
|
48
|
+
| 'pageVerifyOut'
|
|
49
|
+
| 'pageVerifyIn'
|
|
50
|
+
| 'pageVerifyTransferIn'
|
|
51
|
+
| 'pageExecute'
|
|
52
|
+
| 'pagePack'
|
|
53
|
+
| 'pageImages'
|
|
54
|
+
| 'pageSettings'
|
|
55
|
+
| 'pageChildrenNew'
|
|
56
|
+
| 'pageChildrenUpdate'
|
|
57
|
+
| 'remove'
|
|
58
|
+
| 'removeChildren'
|
|
59
|
+
| 'cancel'
|
|
60
|
+
| 'verifyOutLogs'
|
|
61
|
+
| 'verifyOutUndo'
|
|
62
|
+
| 'verifyOutNew'
|
|
63
|
+
| 'verifyInLogs'
|
|
64
|
+
| 'verifyInUndo'
|
|
65
|
+
| 'verifyInNew'
|
|
66
|
+
| 'verifyTransferInLogs'
|
|
67
|
+
| 'verifyTransferInUndo'
|
|
68
|
+
| 'verifyTransferInNew';
|
|
69
|
+
|
|
70
|
+
export type FunctionTypeMeta = {
|
|
71
|
+
id: PermissionFunctionType
|
|
72
|
+
label: string
|
|
73
|
+
type: PermissionFunctionActionType
|
|
74
|
+
description?: string
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export type FunctionTypeMap = {
|
|
78
|
+
[key in PermissionFunctionType]: FunctionTypeMeta
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export type PermissionFunctionActionType = keyof typeof permissionFunctionActionTypes;
|
|
82
|
+
|
|
83
|
+
export const permissionFunctionActionTypes = {
|
|
84
|
+
pageAccess: "pageAccess",
|
|
85
|
+
callAction: "callAction",
|
|
86
|
+
} as const;
|
|
87
|
+
|
|
88
|
+
export const permissionFunctionTypes: FunctionTypeMap = {
|
|
89
|
+
pageList: { id: "pageList", label: "Browse", type: "pageAccess", description: "View Listing" },
|
|
90
|
+
pageNew: { id: "pageNew", label: "Create", type: "pageAccess", description: "Create New" },
|
|
91
|
+
pageView: { id: "pageView", label: "View", type: "pageAccess", description: "View Detail" },
|
|
92
|
+
pageUpdate: { id: "pageUpdate", label: "Update", type: "pageAccess", description: "Modify Detail" },
|
|
93
|
+
pageStockPost: { id: "pageStockPost", label: "Post to Stock", type: "pageAccess", description: "Update Stock" },
|
|
94
|
+
pageVerifyOut: { id: "pageVerifyOut", label: "Verify Out", type: "pageAccess", description: "Stock Deduction" },
|
|
95
|
+
pageVerifyIn: { id: "pageVerifyIn", label: "Verify In", type: "pageAccess", description: "Stock Increment" },
|
|
96
|
+
pageVerifyTransferIn: { id: "pageVerifyTransferIn", label: "Verify Transfer In", type: "pageAccess", description: "Transfer Increment" },
|
|
97
|
+
pageExecute: { id: "pageExecute", label: "Execute", type: "pageAccess", description: "Execution" },
|
|
98
|
+
pagePack: { id: "pagePack", label: "Pack", type: "pageAccess", description: "Perform Packing" },
|
|
99
|
+
pageImages: { id: "pageImages", label: "Images", type: "pageAccess", description: "Manage Images" },
|
|
100
|
+
pageSettings: { id: "pageSettings", label: "Settings", type: "pageAccess", description: "Manage Settings" },
|
|
101
|
+
pageChildrenNew: { id: "pageChildrenNew", label: "Create Children", type: "pageAccess", description: "Create Sub Assets" },
|
|
102
|
+
pageChildrenUpdate: { id: "pageChildrenUpdate", label: "Update Children", type: "pageAccess", description: "Modify Sub Assets" },
|
|
103
|
+
|
|
104
|
+
remove: { id: "remove", label: "Remove", type: "callAction", description: "Deletion" },
|
|
105
|
+
removeChildren: { id: "removeChildren", label: "Remove Children", type: "callAction", description: "Sub Assets Deletion" },
|
|
106
|
+
cancel: { id: "cancel", label: "Cancel", type: "callAction", description: "Cancellation" },
|
|
107
|
+
verifyOutLogs: { id: "verifyOutLogs", label: "Verify Out History", type: "callAction", description: "Browse History" },
|
|
108
|
+
verifyOutUndo: { id: "verifyOutUndo", label: "Undo Verify Out", type: "callAction", description: "Undo Action" },
|
|
109
|
+
verifyOutNew: { id: "verifyOutNew", label: "Create Verify Out", type: "callAction", description: "Perform Action" },
|
|
110
|
+
verifyInLogs: { id: "verifyInLogs", label: "Verify In History", type: "callAction", description: "Browse History" },
|
|
111
|
+
verifyInUndo: { id: "verifyInUndo", label: "Undo Verify In", type: "callAction", description: "Undo Action" },
|
|
112
|
+
verifyInNew: { id: "verifyInNew", label: "Create Verify In", type: "callAction", description: "Perform Action" },
|
|
113
|
+
verifyTransferInLogs: { id: "verifyTransferInLogs", label: "Verify Transfer In History", type: "callAction", description: "Browse History" },
|
|
114
|
+
verifyTransferInUndo: { id: "verifyTransferInUndo", label: "Undo Verify Transfer In", type: "callAction", description: "Undo Action" },
|
|
115
|
+
verifyTransferInNew: { id: "verifyTransferInNew", label: "Create Verify Transfer In", type: "callAction", description: "Perform Action" },
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// export type PermissionScopeType =
|
|
119
|
+
// | "product"
|
|
120
|
+
// | "document"
|
|
121
|
+
// | "repository"
|
|
122
|
+
// | "logistic"
|
|
123
|
+
// | "operation"
|
|
124
|
+
// | "user"
|
|
125
|
+
// | "userRole"
|
|
126
|
+
// | "userBranches"
|
|
127
|
+
// | "branchUsers"
|
|
128
|
+
// | "group"
|
|
129
|
+
// | "region"
|
|
130
|
+
// | "business"
|
|
131
|
+
// | "customField"
|
|
132
|
+
// // | "injectionProp"
|
|
133
|
+
// | "injectionField"
|
|
134
|
+
// | "report"
|
|
135
|
+
// | "scheduler"
|
|
136
|
+
// | "rate"
|
|
137
|
+
// | "audit"
|
|
138
|
+
// | "wallet"
|
|
139
|
+
// | "transaction"
|
|
140
|
+
// | "userApiKey";
|
|
141
|
+
|
|
142
|
+
// const _customPermissionScopeTypes = [
|
|
143
|
+
// "customSettings"
|
|
144
|
+
// ] as const
|
|
145
|
+
|
|
146
|
+
const _permissionScopeTypes = [
|
|
147
|
+
"product",
|
|
148
|
+
"document",
|
|
149
|
+
"repository",
|
|
150
|
+
"logistic",
|
|
151
|
+
"operation",
|
|
152
|
+
"user",
|
|
153
|
+
"userRole",
|
|
154
|
+
"userBranches",
|
|
155
|
+
"branchUsers",
|
|
156
|
+
"group",
|
|
157
|
+
"region",
|
|
158
|
+
"business",
|
|
159
|
+
"customField",
|
|
160
|
+
"injectionField",
|
|
161
|
+
"report",
|
|
162
|
+
"scheduler",
|
|
163
|
+
"rate",
|
|
164
|
+
"audit",
|
|
165
|
+
"wallet",
|
|
166
|
+
"transaction",
|
|
167
|
+
"userApiKey",
|
|
168
|
+
..._customPermissionScopeTypes
|
|
169
|
+
] as const;
|
|
170
|
+
|
|
171
|
+
export type PermissionScopeType = typeof _permissionScopeTypes[number];
|
|
172
|
+
|
|
173
|
+
export type ScopeTypeMeta = {
|
|
174
|
+
id: PermissionScopeType;
|
|
175
|
+
label: string;
|
|
176
|
+
postValue: string;
|
|
177
|
+
description: string;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
export type ScopeTypeMap = {
|
|
181
|
+
[key in PermissionScopeType]: ScopeTypeMeta
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// const customPermissionScopeTypes = {
|
|
185
|
+
// customSettings: { id: "customSettings", label: "Custom", description: "" },
|
|
186
|
+
// } as const
|
|
187
|
+
|
|
188
|
+
export const permissionScopeTypes: ScopeTypeMap = {
|
|
189
|
+
product: { id: "product", label: "Products", postValue: "product", description: "" },
|
|
190
|
+
document: { id: "document", label: "Documents", postValue: "document", description: "" },
|
|
191
|
+
repository: { id: "repository", label: "Repositories", postValue: "repository", description: "" },
|
|
192
|
+
logistic: { id: "logistic", label: "Logistics", postValue: "logistic", description: "" },
|
|
193
|
+
operation: { id: "operation", label: "Operations", postValue: "operation", description: "" },
|
|
194
|
+
user: { id: "user", label: "Users", postValue: "user", description: "" },
|
|
195
|
+
userRole: { id: "userRole", label: "Roles and Permissions", postValue: "user_role", description: "" },
|
|
196
|
+
userBranches: { id: "userBranches", label: "User Branches", postValue: "user_branch", description: "" },
|
|
197
|
+
branchUsers: { id: "branchUsers", label: "Branch Users", postValue: "branch_user", description: "" },
|
|
198
|
+
group: { id: "group", label: "User Groups", postValue: "group", description: "" },
|
|
199
|
+
region: { id: "region", label: "Regions", postValue: "region", description: "" },
|
|
200
|
+
business: { id: "business", label: "Business", postValue: "business", description: "" },
|
|
201
|
+
customField: { id: "customField", label: "Custom Fields", postValue: "custom_field", description: "" },
|
|
202
|
+
// injectionProp: { id: "injectionProp", label: "Injection Props", postValue: "", description: "" },
|
|
203
|
+
injectionField: { id: "injectionField", label: "Injection Fields", postValue: "injection_field", description: "" },
|
|
204
|
+
report: { id: "report", label: "Reports", postValue: "report", description: "" },
|
|
205
|
+
scheduler: { id: "scheduler", label: "Schedulers", postValue: "scheduler", description: "" },
|
|
206
|
+
rate: { id: "rate", label: "Rates", postValue: "rate", description: "" },
|
|
207
|
+
audit: { id: "audit", label: "Audit Trails", postValue: "audit_trail", description: "" },
|
|
208
|
+
wallet: { id: "wallet", label: "Wallets", postValue: "wallet", description: "" },
|
|
209
|
+
transaction: { id: "transaction", label: "Transactions", postValue: "transaction", description: "" },
|
|
210
|
+
userApiKey: { id: "userApiKey", label: "User API Keys", postValue: "userApiKey", description: "" },
|
|
211
|
+
...customPermissionScopeTypes
|
|
212
|
+
} as const;
|
|
213
|
+
|
|
214
|
+
type ModuleProduct =
|
|
215
|
+
| "product"
|
|
216
|
+
| "item"
|
|
217
|
+
| "brand"
|
|
218
|
+
| "category"
|
|
219
|
+
| "uom";
|
|
220
|
+
|
|
221
|
+
type ModuleDocument =
|
|
222
|
+
| "salesOrder"
|
|
223
|
+
| "proformaSales"
|
|
224
|
+
| "cashSales"
|
|
225
|
+
| "retailCashSales"
|
|
226
|
+
| "deliveryOrder"
|
|
227
|
+
| "replacementDelivery"
|
|
228
|
+
| "salesDebitNote"
|
|
229
|
+
| "salesCreditNote"
|
|
230
|
+
| "salesInvoice"
|
|
231
|
+
| "purchaseOrder"
|
|
232
|
+
| "purchaseReturn"
|
|
233
|
+
| "purchaseInvoice"
|
|
234
|
+
| "itemReceive"
|
|
235
|
+
| "itemTransfer"
|
|
236
|
+
| "itemRelocate"
|
|
237
|
+
| "itemTransform"
|
|
238
|
+
| "itemIssue"
|
|
239
|
+
| "itemAdjustment"
|
|
240
|
+
| "stockTake"
|
|
241
|
+
| "transferReturn"
|
|
242
|
+
| "transferRequisition"
|
|
243
|
+
| "tripOrder"
|
|
244
|
+
| "pickOrder"
|
|
245
|
+
| "retailPrescription";
|
|
246
|
+
|
|
247
|
+
type ModuleRepository =
|
|
248
|
+
| "container"
|
|
249
|
+
| "package";
|
|
250
|
+
|
|
251
|
+
type ModuleLogistic =
|
|
252
|
+
| "transporter";
|
|
253
|
+
|
|
254
|
+
type ModuleOperation =
|
|
255
|
+
| "examineInventory"
|
|
256
|
+
| "itemRelocateThreshold"
|
|
257
|
+
| "itemReorderThreshold";
|
|
258
|
+
|
|
259
|
+
type ModuleUser =
|
|
260
|
+
| "administrator"
|
|
261
|
+
| "customer"
|
|
262
|
+
| "driver"
|
|
263
|
+
| "member"
|
|
264
|
+
| "retail"
|
|
265
|
+
| "supplier"
|
|
266
|
+
| "worker";
|
|
267
|
+
|
|
268
|
+
type ModuleUserRole =
|
|
269
|
+
| "role"
|
|
270
|
+
| "permission";
|
|
271
|
+
|
|
272
|
+
type ModuleUserBranches =
|
|
273
|
+
| "customer"
|
|
274
|
+
| "retail";
|
|
275
|
+
|
|
276
|
+
type ModuleBranchUsers =
|
|
277
|
+
| "customer"
|
|
278
|
+
| "retail";
|
|
279
|
+
|
|
280
|
+
type ModuleGroup =
|
|
281
|
+
| "administrator"
|
|
282
|
+
| "customer"
|
|
283
|
+
| "supplier";
|
|
284
|
+
|
|
285
|
+
type ModuleRegion =
|
|
286
|
+
| "country"
|
|
287
|
+
| "area";
|
|
288
|
+
|
|
289
|
+
type ModuleBusiness =
|
|
290
|
+
| "business";
|
|
291
|
+
|
|
292
|
+
type ModuleCustomField =
|
|
293
|
+
| "customField";
|
|
294
|
+
|
|
295
|
+
// type ModuleInjectionProp =
|
|
296
|
+
// | "injectionProp";
|
|
297
|
+
|
|
298
|
+
type ModuleInjectionField =
|
|
299
|
+
| "injectionField";
|
|
300
|
+
|
|
301
|
+
type ModuleReport =
|
|
302
|
+
| "productItem"
|
|
303
|
+
| "salesOrder"
|
|
304
|
+
| "salesOrderItem"
|
|
305
|
+
| "deliveryOrder"
|
|
306
|
+
| "deliveryOrderItem"
|
|
307
|
+
| "itemReceive"
|
|
308
|
+
| "itemReceiveItem"
|
|
309
|
+
| "itemTransfer"
|
|
310
|
+
| "itemTransferItem";
|
|
311
|
+
|
|
312
|
+
type ModuleScheduler =
|
|
313
|
+
| "schedulerTask"
|
|
314
|
+
| "schedulerLog"
|
|
315
|
+
| "schedulerRequest"
|
|
316
|
+
| "schedulerConsole";
|
|
317
|
+
|
|
318
|
+
type ModuleRate =
|
|
319
|
+
| "shippingRate"
|
|
320
|
+
| "shippingRule"
|
|
321
|
+
| "taxRate";
|
|
322
|
+
|
|
323
|
+
type ModuleAudit =
|
|
324
|
+
| "auditTrail"
|
|
325
|
+
| "auditTrailTag";
|
|
326
|
+
|
|
327
|
+
type ModuleWallet =
|
|
328
|
+
| "wallet"
|
|
329
|
+
| "walletUser";
|
|
330
|
+
|
|
331
|
+
type ModuleTransaction =
|
|
332
|
+
| "request"
|
|
333
|
+
| "wallet";
|
|
334
|
+
|
|
335
|
+
type ModuleUserApiKey =
|
|
336
|
+
| "apiKey";
|
|
337
|
+
|
|
338
|
+
export type ModuleTypeMetaScoped<T extends string> = {
|
|
339
|
+
id: T;
|
|
340
|
+
label: string;
|
|
341
|
+
postValue: string;
|
|
342
|
+
description?: string;
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
export type ModuleTypesMap = {
|
|
346
|
+
product: { [key in ModuleProduct]: ModuleTypeMetaScoped<key> };
|
|
347
|
+
document: { [key in ModuleDocument]: ModuleTypeMetaScoped<key> };
|
|
348
|
+
repository: { [key in ModuleRepository]: ModuleTypeMetaScoped<key> };
|
|
349
|
+
logistic: { [key in ModuleLogistic]: ModuleTypeMetaScoped<key> };
|
|
350
|
+
operation: { [key in ModuleOperation]: ModuleTypeMetaScoped<key> };
|
|
351
|
+
user: { [key in ModuleUser]: ModuleTypeMetaScoped<key> };
|
|
352
|
+
userRole: { [key in ModuleUserRole]: ModuleTypeMetaScoped<key> };
|
|
353
|
+
userBranches: { [key in ModuleUserBranches]: ModuleTypeMetaScoped<key> };
|
|
354
|
+
branchUsers: { [key in ModuleBranchUsers]: ModuleTypeMetaScoped<key> };
|
|
355
|
+
group: { [key in ModuleGroup]: ModuleTypeMetaScoped<key> };
|
|
356
|
+
region: { [key in ModuleRegion]: ModuleTypeMetaScoped<key> };
|
|
357
|
+
business: { [key in ModuleBusiness]: ModuleTypeMetaScoped<key> };
|
|
358
|
+
customField: { [key in ModuleCustomField]: ModuleTypeMetaScoped<key> };
|
|
359
|
+
// injectionProp: { [key in ModuleInjectionProp]: ModuleTypeMetaScoped<key> };
|
|
360
|
+
injectionField: { [key in ModuleInjectionField]: ModuleTypeMetaScoped<key> };
|
|
361
|
+
report: { [key in ModuleReport]: ModuleTypeMetaScoped<key> };
|
|
362
|
+
scheduler: { [key in ModuleScheduler]: ModuleTypeMetaScoped<key> };
|
|
363
|
+
rate: { [key in ModuleRate]: ModuleTypeMetaScoped<key> };
|
|
364
|
+
audit: { [key in ModuleAudit]: ModuleTypeMetaScoped<key> };
|
|
365
|
+
wallet: { [key in ModuleWallet]: ModuleTypeMetaScoped<key> };
|
|
366
|
+
transaction: { [key in ModuleTransaction]: ModuleTypeMetaScoped<key> };
|
|
367
|
+
userApiKey: { [key in ModuleUserApiKey]: ModuleTypeMetaScoped<key> };
|
|
368
|
+
} & CustomModuleTypesMap
|
|
369
|
+
|
|
370
|
+
export const permissionModuleTypes: ModuleTypesMap = {
|
|
371
|
+
product: {
|
|
372
|
+
product: { id: "product", label: "Manage Items", postValue: "product", description: "Product Catalogue" },
|
|
373
|
+
item: { id: "item", label: "Manage Item Uoms", postValue: "item", description: "Sku Items Catalogue" },
|
|
374
|
+
brand: { id: "brand", label: "Manage Brands", postValue: "brand", description: "Product Brands" },
|
|
375
|
+
category: { id: "category", label: "Manage Categories", postValue: "category", description: "Organize Product Category" },
|
|
376
|
+
uom: { id: "uom", label: "Manage Uoms", postValue: "uom", description: "Unit Measures" },
|
|
377
|
+
},
|
|
378
|
+
document: {
|
|
379
|
+
salesOrder: { id: "salesOrder", label: "Sales Orders", postValue: "sales", description: "All Functions" },
|
|
380
|
+
proformaSales: { id: "proformaSales", label: "Proforma Sales", postValue: "proforma_sales", description: "All Functions" },
|
|
381
|
+
cashSales: { id: "cashSales", label: "Cash Sales", postValue: "cash_sales", description: "All Functions" },
|
|
382
|
+
retailCashSales: { id: "retailCashSales", label: "Retail Cash Sales", postValue: "retail_cash_sales", description: "All Functions" },
|
|
383
|
+
deliveryOrder: { id: "deliveryOrder", label: "Delivery Orders", postValue: "delivery", description: "All Functions" },
|
|
384
|
+
replacementDelivery: { id: "replacementDelivery", label: "Replacement Delivery", postValue: "replacement_delivery", description: "All Functions" },
|
|
385
|
+
salesDebitNote: { id: "salesDebitNote", label: "Sales Debit Notes", postValue: "sales_debit_note", description: "All Functions" },
|
|
386
|
+
salesCreditNote: { id: "salesCreditNote", label: "Sales Credit Notes", postValue: "sales_credit_note", description: "All Functions" },
|
|
387
|
+
salesInvoice: { id: "salesInvoice", label: "Sales Invoice", postValue: "sales_invoice", description: "All Functions" },
|
|
388
|
+
purchaseOrder: { id: "purchaseOrder", label: "Purchase Orders", postValue: "purchase", description: "All Functions" },
|
|
389
|
+
purchaseReturn: { id: "purchaseReturn", label: "Purchase Returns", postValue: "purchase_return", description: "All Functions" },
|
|
390
|
+
purchaseInvoice: { id: "purchaseInvoice", label: "Purchase Invoices", postValue: "purchase_invoice", description: "All Functions" },
|
|
391
|
+
itemReceive: { id: "itemReceive", label: "Item Receives", postValue: "item_receive", description: "All Functions" },
|
|
392
|
+
itemTransfer: { id: "itemTransfer", label: "Item Transfers", postValue: "item_transfer", description: "All Functions" },
|
|
393
|
+
itemRelocate: { id: "itemRelocate", label: "Item Relocates", postValue: "item_relocate", description: "All Functions" },
|
|
394
|
+
itemTransform: { id: "itemTransform", label: "Item Transforms", postValue: "item_transform", description: "All Functions" },
|
|
395
|
+
itemIssue: { id: "itemIssue", label: "Item Issues", postValue: "item_issue", description: "All Functions" },
|
|
396
|
+
itemAdjustment: { id: "itemAdjustment", label: "Item Adjustments", postValue: "item_adjustment", description: "All Functions" },
|
|
397
|
+
stockTake: { id: "stockTake", label: "Stock Takes", postValue: "stock_take", description: "All Functions" },
|
|
398
|
+
transferReturn: { id: "transferReturn", label: "Transfer Returns", postValue: "transfer_return", description: "All Functions" },
|
|
399
|
+
transferRequisition: { id: "transferRequisition", label: "Transfer Requisitions", postValue: "transfer_requisition", description: "All Functions" },
|
|
400
|
+
tripOrder: { id: "tripOrder", label: "Delivery Trips", postValue: "trip", description: "All Functions" },
|
|
401
|
+
pickOrder: { id: "pickOrder", label: "Pick Orders Trips", postValue: "pick_order", description: "All Functions" },
|
|
402
|
+
retailPrescription: { id: "retailPrescription", label: "Retail Prescriptions", postValue: "retail_prescription", description: "All Functions" },
|
|
403
|
+
},
|
|
404
|
+
repository: {
|
|
405
|
+
container: { id: "container", label: "Containers", postValue: "container", description: "Shipment Containers" },
|
|
406
|
+
package: { id: "package", label: "Packages", postValue: "pakage", description: "Item Packages" },
|
|
407
|
+
},
|
|
408
|
+
logistic: {
|
|
409
|
+
transporter: { id: "transporter", label: "Transporters", postValue: "transporter", description: "Fulfillment Parties" },
|
|
410
|
+
},
|
|
411
|
+
operation: {
|
|
412
|
+
examineInventory: { id: "examineInventory", label: "Examine Inventory", postValue: "examine_inventory", description: "View Item Inventory" },
|
|
413
|
+
itemRelocateThreshold: { id: "itemRelocateThreshold", label: "Relocate Threshold", postValue: "item_relocate_threshold", description: "Relocate Threshold Control" },
|
|
414
|
+
itemReorderThreshold: { id: "itemReorderThreshold", label: "Reorder Threshold", postValue: "item_reorder_threshold", description: "Reorder Threshold Control" },
|
|
415
|
+
},
|
|
416
|
+
user: {
|
|
417
|
+
administrator: { id: "administrator", label: "Manage Administrators", postValue: "administrator", description: "All Functions" },
|
|
418
|
+
customer: { id: "customer", label: "Manage Customers", postValue: "customer", description: "All Functions" },
|
|
419
|
+
driver: { id: "driver", label: "Manage Drivers", postValue: "driver", description: "All Functions" },
|
|
420
|
+
member: { id: "member", label: "Manage Members", postValue: "member", description: "All Functions" },
|
|
421
|
+
retail: { id: "retail", label: "Manage Retailers", postValue: "retail", description: "All Functions" },
|
|
422
|
+
supplier: { id: "supplier", label: "Manage Suppliers", postValue: "supplier", description: "All Functions" },
|
|
423
|
+
worker: { id: "worker", label: "Manage Workers", postValue: "worker", description: "All Functions" },
|
|
424
|
+
},
|
|
425
|
+
userRole: {
|
|
426
|
+
role: { id: "role", label: "Roles", postValue: "role", description: "User Roles" },
|
|
427
|
+
permission: { id: "permission", label: "Permissions", postValue: "permission", description: "Assign Permissions" },
|
|
428
|
+
},
|
|
429
|
+
userBranches: {
|
|
430
|
+
customer: { id: "customer", label: "For Customers", postValue: "customer", description: "Customer Branches" },
|
|
431
|
+
retail: { id: "retail", label: "For Retailers", postValue: "retail", description: "Retail Outlets" },
|
|
432
|
+
},
|
|
433
|
+
branchUsers: {
|
|
434
|
+
customer: { id: "customer", label: "For Customers", postValue: "customer", description: "Customer Branch Users" },
|
|
435
|
+
retail: { id: "retail", label: "For Retailers", postValue: "retail", description: "Retail Outlet Users" },
|
|
436
|
+
},
|
|
437
|
+
group: {
|
|
438
|
+
administrator: { id: "administrator", label: "For Administrators", postValue: "administrator", description: "All Functions" },
|
|
439
|
+
customer: { id: "customer", label: "For Customers", postValue: "customer", description: "All Functions" },
|
|
440
|
+
supplier: { id: "supplier", label: "For Suppliers", postValue: "supplier", description: "All Functions" },
|
|
441
|
+
},
|
|
442
|
+
region: {
|
|
443
|
+
country: { id: "country", label: "Country", postValue: "country", description: "All Functions" },
|
|
444
|
+
area: { id: "area", label: "Area", postValue: "area", description: "All Functions" },
|
|
445
|
+
},
|
|
446
|
+
business: {
|
|
447
|
+
business: { id: "business", label: "Manage Business", postValue: "business", description: "Multiple business entity" },
|
|
448
|
+
},
|
|
449
|
+
customField: {
|
|
450
|
+
customField: { id: "customField", label: "Manage Custom Fields", postValue: "custom_field", description: "Custom Fields For Certain Resources" },
|
|
451
|
+
},
|
|
452
|
+
// injectionProp: {
|
|
453
|
+
// injectionProp: { id: "injectionProp", label: "Manage Injection Props", postValue: "", description: "Injection Props For Certain Resources" },
|
|
454
|
+
// },
|
|
455
|
+
injectionField: {
|
|
456
|
+
injectionField: { id: "injectionField", label: "Manage Injection Fields", postValue: "injection_field", description: "Injection Fields For Certain Resources" },
|
|
457
|
+
},
|
|
458
|
+
report: {
|
|
459
|
+
productItem: { id: "productItem", label: "Product Items", postValue: "item_report", description: "All Functions" },
|
|
460
|
+
salesOrder: { id: "salesOrder", label: "Sales Orders", postValue: "sales_report", description: "All Functions" },
|
|
461
|
+
salesOrderItem: { id: "salesOrderItem", label: "Sales Order Items", postValue: "sales_item_report", description: "All Functions" },
|
|
462
|
+
deliveryOrder: { id: "deliveryOrder", label: "Delivery Orders", postValue: "delivery_report", description: "All Functions" },
|
|
463
|
+
deliveryOrderItem: { id: "deliveryOrderItem", label: "Delivery Order Items", postValue: "delivery_item_report", description: "All Functions" },
|
|
464
|
+
itemReceive: { id: "itemReceive", label: "Item Receives", postValue: "item_receive_report", description: "All Functions" },
|
|
465
|
+
itemReceiveItem: { id: "itemReceiveItem", label: "Item Receive Items", postValue: "item_receive_item_report", description: "All Functions" },
|
|
466
|
+
itemTransfer: { id: "itemTransfer", label: "Item Transfers", postValue: "item_transfer_report", description: "All Functions" },
|
|
467
|
+
itemTransferItem: { id: "itemTransferItem", label: "Item Transfer Items", postValue: "item_transfer_item_report", description: "All Functions" },
|
|
468
|
+
},
|
|
469
|
+
scheduler: {
|
|
470
|
+
schedulerTask: { id: "schedulerTask", label: "Manage Task Schedule", postValue: "scheduler_task", description: "" },
|
|
471
|
+
schedulerLog: { id: "schedulerLog", label: "Manage Log Schedule", postValue: "scheduler_log", description: "" },
|
|
472
|
+
schedulerRequest: { id: "schedulerRequest", label: "Manage Request Schedule", postValue: "scheduler_request", description: "" },
|
|
473
|
+
schedulerConsole: { id: "schedulerConsole", label: "Scheduler Console", postValue: "scheduler_console", description: "" },
|
|
474
|
+
},
|
|
475
|
+
rate: {
|
|
476
|
+
shippingRate: { id: "shippingRate", label: "Manage Shipping Rate", postValue: "shipping_rate", description: "" },
|
|
477
|
+
shippingRule: { id: "shippingRule", label: "Manage Shipping Rule", postValue: "shipping_rule", description: "" },
|
|
478
|
+
taxRate: { id: "taxRate", label: "Manage Tax Rate", postValue: "tax_rate", description: "" },
|
|
479
|
+
},
|
|
480
|
+
audit: {
|
|
481
|
+
auditTrail: { id: "auditTrail", label: "Manage Audit Trails", postValue: "audit_trail", description: "" },
|
|
482
|
+
auditTrailTag: { id: "auditTrailTag", label: "Manage Audit Trail Tags", postValue: "audit_trail_tag", description: "" },
|
|
483
|
+
},
|
|
484
|
+
wallet: {
|
|
485
|
+
wallet: { id: "wallet", label: "Manage Wallets", postValue: "wallet", description: "" },
|
|
486
|
+
walletUser: { id: "walletUser", label: "Manage Wallet Users", postValue: "wallet_user", description: "" },
|
|
487
|
+
},
|
|
488
|
+
transaction: {
|
|
489
|
+
request: { id: "request", label: "Manage Request Transactions", postValue: "request", description: "" },
|
|
490
|
+
wallet: { id: "wallet", label: "Manage Wallet Transactions", postValue: "wallet", description: "" },
|
|
491
|
+
},
|
|
492
|
+
userApiKey: {
|
|
493
|
+
apiKey: { id: "apiKey", label: "Manage User API Keys", postValue: "api_key", description: "" },
|
|
494
|
+
},
|
|
495
|
+
...customPermissionModuleTypes
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
export type Scope = "product" | "document" | "wallet";
|
|
499
|
+
|
|
500
|
+
export type Permission = {
|
|
501
|
+
[key in PermissionFunctionType]?: boolean;
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
export type PermissionProduct = { [module in ModuleProduct]?: Permission; };
|
|
505
|
+
export type PermissionDocument = { [module in ModuleDocument]?: Permission; };
|
|
506
|
+
export type PermissionRepository = { [module in ModuleRepository]?: Permission; };
|
|
507
|
+
export type PermissionLogistic = { [module in ModuleLogistic]?: Permission; };
|
|
508
|
+
export type PermissionOperation = { [module in ModuleOperation]?: Permission; };
|
|
509
|
+
export type PermissionUser = { [module in ModuleUser]?: Permission; };
|
|
510
|
+
export type PermissionUserRole = { [module in ModuleUserRole]?: Permission; };
|
|
511
|
+
export type PermissionUserBranches = { [module in ModuleUserBranches]?: Permission; };
|
|
512
|
+
export type PermissionBranchUsers = { [module in ModuleBranchUsers]?: Permission; };
|
|
513
|
+
export type PermissionGroup = { [module in ModuleGroup]?: Permission; };
|
|
514
|
+
export type PermissionRegion = { [module in ModuleRegion]?: Permission; };
|
|
515
|
+
export type PermissionBusiness = { [module in ModuleBusiness]?: Permission; };
|
|
516
|
+
export type PermissionCustomField = { [module in ModuleCustomField]?: Permission; };
|
|
517
|
+
// export type PermissionInjectionProp = { [module in ModuleInjectionProp]?: Permission; };
|
|
518
|
+
export type PermissionInjectionField = { [module in ModuleInjectionField]?: Permission; };
|
|
519
|
+
export type PermissionReport = { [module in ModuleReport]?: Permission; };
|
|
520
|
+
export type PermissionScheduler = { [module in ModuleScheduler]?: Permission; };
|
|
521
|
+
export type PermissionRate = { [module in ModuleRate]?: Permission; };
|
|
522
|
+
export type PermissionAudit = { [module in ModuleAudit]?: Permission; };
|
|
523
|
+
export type PermissionWallet = { [module in ModuleWallet]?: Permission; };
|
|
524
|
+
export type PermissionTransaction = { [module in ModuleTransaction]?: Permission; };
|
|
525
|
+
export type PermissionUserApiKey = { [module in ModuleUserApiKey]?: Permission; };
|
|
526
|
+
|
|
527
|
+
// type CustomModuleTransaction =
|
|
528
|
+
// | "transportType"
|
|
529
|
+
// | "transportService";
|
|
530
|
+
|
|
531
|
+
// type CustomPermissionMap = {
|
|
532
|
+
// customSettings: { [module in CustomModuleTransaction]?: Permission; };
|
|
533
|
+
// }
|
|
534
|
+
|
|
535
|
+
export type PermissionMap = {
|
|
536
|
+
product: PermissionProduct;
|
|
537
|
+
document: PermissionDocument;
|
|
538
|
+
repository: PermissionRepository;
|
|
539
|
+
logistic: PermissionLogistic;
|
|
540
|
+
operation: PermissionOperation;
|
|
541
|
+
user: PermissionUser;
|
|
542
|
+
userRole: PermissionUserRole;
|
|
543
|
+
userBranches: PermissionUserBranches;
|
|
544
|
+
branchUsers: PermissionBranchUsers;
|
|
545
|
+
group: PermissionGroup;
|
|
546
|
+
region: PermissionRegion;
|
|
547
|
+
business: PermissionBusiness;
|
|
548
|
+
customField: PermissionCustomField;
|
|
549
|
+
// injectionProp: PermissionInjectionProp;
|
|
550
|
+
injectionField: PermissionInjectionField;
|
|
551
|
+
report: PermissionReport;
|
|
552
|
+
scheduler: PermissionScheduler;
|
|
553
|
+
rate: PermissionRate;
|
|
554
|
+
audit: PermissionAudit;
|
|
555
|
+
wallet: PermissionWallet;
|
|
556
|
+
transaction: PermissionTransaction;
|
|
557
|
+
userApiKey: PermissionUserApiKey;
|
|
558
|
+
} & CustomPermissionMap
|
|
559
|
+
|
|
560
|
+
export type PermissionConfig = Partial<{
|
|
561
|
+
[K in PermissionScopeType]: PermissionMap[K];
|
|
562
|
+
}>;
|
|
563
|
+
|
|
564
|
+
const memberPermissionsConfig: PermissionConfig = {
|
|
565
|
+
} as const;
|
|
566
|
+
|
|
567
|
+
// const driverPermissionsConfig: PermissionConfig = {
|
|
568
|
+
// } as const;
|
|
569
|
+
|
|
570
|
+
export type PermissionServiceProps = ApiServiceType & {
|
|
571
|
+
isOwnerUser: boolean,
|
|
572
|
+
userPermissions: any,
|
|
573
|
+
permissionTargetType?: PermissionTargetType
|
|
574
|
+
permissionType?: PermissionType
|
|
575
|
+
routeType?: AppRouteId,
|
|
576
|
+
scopeType?: PermissionScopeType,
|
|
577
|
+
moduleType?: AllModuleKeys,
|
|
578
|
+
permissionRouteType?: string
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
export type ChangePermissionProps = {
|
|
582
|
+
id: number,
|
|
583
|
+
permissionTargetType?: PermissionTargetType
|
|
584
|
+
permissionType?: PermissionType
|
|
585
|
+
data:
|
|
586
|
+
// user roles
|
|
587
|
+
{
|
|
588
|
+
userRoles: {
|
|
589
|
+
scopeType: PermissionScopeType,
|
|
590
|
+
moduleType: ModuleBusiness,
|
|
591
|
+
functionType: PermissionFunctionType,
|
|
592
|
+
status: boolean,
|
|
593
|
+
isCustomScope: boolean
|
|
594
|
+
}[]
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
const getChangePayload = (permissionType: PermissionType, data: ChangePermissionProps["data"]) => {
|
|
599
|
+
|
|
600
|
+
if (permissionType === "role" && "userRoles" in data) {
|
|
601
|
+
|
|
602
|
+
// scope_type: scopeValue,
|
|
603
|
+
// scope_name: targetId,
|
|
604
|
+
// permission_type: permissionId,
|
|
605
|
+
// status: status ? 1 : 0,
|
|
606
|
+
// is_custom: isCustomScopeId
|
|
607
|
+
|
|
608
|
+
return {
|
|
609
|
+
permissions: data.userRoles.map(i => ({
|
|
610
|
+
scope_type: i.scopeType,
|
|
611
|
+
scope_name: i.moduleType,
|
|
612
|
+
permission_type: i.functionType,
|
|
613
|
+
status: (i.status === true) ? 1 : 0,
|
|
614
|
+
is_custom: (i.isCustomScope === true) ? 1 : 0,
|
|
615
|
+
})),
|
|
616
|
+
// location_name: data.location.locationName,
|
|
617
|
+
// location_type: data.location.locationType,
|
|
618
|
+
// person_name: data.location.personName,
|
|
619
|
+
// person_contact: data.location.personContact,
|
|
620
|
+
// person_email: data.location.personEmail,
|
|
621
|
+
// address_1: data.location.address1,
|
|
622
|
+
// address_2: data.location.address2,
|
|
623
|
+
// postcode: data.location.postcode,
|
|
624
|
+
// state_id: data.location.stateId,
|
|
625
|
+
// country_id: data.location.countryId,
|
|
626
|
+
// area: data.location.areaId,
|
|
627
|
+
// is_default: (data.location.isDefault === true) ? 1 : 0,
|
|
628
|
+
// status: (data.location.status === true) ? 1 : 0,
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
const checkValidScopeId = (id: string) => {
|
|
634
|
+
|
|
635
|
+
return Object.values(permissionScopeTypes).some(scope => scope.id === id);
|
|
636
|
+
|
|
637
|
+
// let checkStatus = false;
|
|
638
|
+
|
|
639
|
+
// Object.keys(permissionScopeTypes).forEach((i: any) => {
|
|
640
|
+
// if (permissionScopeTypes[i]?.id === id) {
|
|
641
|
+
// checkStatus = true
|
|
642
|
+
// }
|
|
643
|
+
// })
|
|
644
|
+
|
|
645
|
+
// return checkStatus
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
const checkObjectHasKey = <T extends object>(
|
|
649
|
+
obj: T,
|
|
650
|
+
key: PropertyKey
|
|
651
|
+
): key is keyof T => {
|
|
652
|
+
return key in obj;
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
type AllModuleKeys = {
|
|
656
|
+
[Scope in keyof ModuleTypesMap]: keyof ModuleTypesMap[Scope];
|
|
657
|
+
}[keyof ModuleTypesMap];
|
|
658
|
+
|
|
659
|
+
export type CheckPermissionAllowProps = {
|
|
660
|
+
routeType?: AppRouteId,
|
|
661
|
+
scopeType?: keyof typeof permissionScopeTypes,
|
|
662
|
+
moduleType?: AllModuleKeys,
|
|
663
|
+
functionType: PermissionFunctionType
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
export const PermissionService = (props?: PermissionServiceProps) => {
|
|
667
|
+
|
|
668
|
+
const {
|
|
669
|
+
isOwnerUser = false,
|
|
670
|
+
userPermissions = {},
|
|
671
|
+
permissionType = "role",
|
|
672
|
+
permissionTargetType = "role",
|
|
673
|
+
routeType = "administrator",
|
|
674
|
+
scopeType = "user",
|
|
675
|
+
moduleType = "administrator",
|
|
676
|
+
customToken = '',
|
|
677
|
+
} = props ?? {};
|
|
678
|
+
|
|
679
|
+
const { makeCall } = ApiService(customToken ? { customToken } : {})
|
|
680
|
+
|
|
681
|
+
const endpoint1 = "role";
|
|
682
|
+
// const endpoint2 = "locations"
|
|
683
|
+
|
|
684
|
+
const changePermission = async ({ id, data, permissionType: overridePermissionType, permissionTargetType: overridePermissionTargetType }: ChangePermissionProps) => {
|
|
685
|
+
|
|
686
|
+
let url = `${endpoint1}/change/${id}`
|
|
687
|
+
|
|
688
|
+
let _permissionType = overridePermissionType || permissionType
|
|
689
|
+
|
|
690
|
+
let payload: any = getChangePayload(_permissionType, data)
|
|
691
|
+
|
|
692
|
+
const postData = {
|
|
693
|
+
scope: {
|
|
694
|
+
target: overridePermissionTargetType || permissionTargetType,
|
|
695
|
+
action: "",
|
|
696
|
+
},
|
|
697
|
+
payload
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
const response = await makeCall({
|
|
701
|
+
url,
|
|
702
|
+
method: "put",
|
|
703
|
+
payload: postData,
|
|
704
|
+
// configuration
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
return response;
|
|
708
|
+
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
const validatePermission = ({
|
|
712
|
+
// routeType,
|
|
713
|
+
// parentScopeType,
|
|
714
|
+
scopeType,
|
|
715
|
+
moduleType,
|
|
716
|
+
// parentScopeValue,
|
|
717
|
+
// scopeType,
|
|
718
|
+
functionType
|
|
719
|
+
}: {
|
|
720
|
+
// routeType: AppRouteId,
|
|
721
|
+
// parentScopeType: string,
|
|
722
|
+
// parentScopeValue: string,
|
|
723
|
+
scopeType: string,
|
|
724
|
+
moduleType: AllModuleKeys,
|
|
725
|
+
functionType: PermissionFunctionType
|
|
726
|
+
}) => {
|
|
727
|
+
|
|
728
|
+
// let {
|
|
729
|
+
// assignedRoles,
|
|
730
|
+
// assignedPermissions
|
|
731
|
+
// } = getRolePermissions()
|
|
732
|
+
|
|
733
|
+
let assignedPermissions = userPermissions// loginPermissionConfigs
|
|
734
|
+
|
|
735
|
+
console.log('assignedPermissions', assignedPermissions)
|
|
736
|
+
|
|
737
|
+
const scope = assignedPermissions[scopeType as keyof typeof assignedPermissions];
|
|
738
|
+
|
|
739
|
+
if (!scope) throw `Invalid permission in scope ${scopeType}`
|
|
740
|
+
|
|
741
|
+
const module = scope[moduleType as keyof typeof scope] as string[];
|
|
742
|
+
|
|
743
|
+
if (!Array.isArray(module)) {
|
|
744
|
+
throw `Invalid permission in module ${moduleType}`
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// console.log('module', module, functionType)
|
|
748
|
+
|
|
749
|
+
return module.includes(functionType);
|
|
750
|
+
|
|
751
|
+
// check scopeType exist
|
|
752
|
+
// if (scopeType in assignedPermissions === false) return false
|
|
753
|
+
|
|
754
|
+
// // check moduleType exist
|
|
755
|
+
// if (moduleType in assignedPermissions[scopeType] === false) return false
|
|
756
|
+
|
|
757
|
+
// // let listPermissions = assignedPermissions[scopeType][moduleType]
|
|
758
|
+
// let allowFunctions = assignedPermissions[scopeType][moduleType]
|
|
759
|
+
|
|
760
|
+
// // console.log('listPermissions', listPermissions, assignedPermissions)
|
|
761
|
+
|
|
762
|
+
// // check permission is array format
|
|
763
|
+
// if (Array.isArray(allowFunctions) === false) return false;
|
|
764
|
+
|
|
765
|
+
// if (allowFunctions.includes(functionType)) { // permission is exists
|
|
766
|
+
// return true;
|
|
767
|
+
// }
|
|
768
|
+
|
|
769
|
+
// return false;
|
|
770
|
+
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
const getPermissionConfig = (routeType: AppRouteId) => {
|
|
774
|
+
|
|
775
|
+
console.log('routeType >>>', routeType)
|
|
776
|
+
|
|
777
|
+
if (routeType === "administrator") {
|
|
778
|
+
return (Object.keys(customAdminPermissionsConfig).length > 0) ? customAdminPermissionsConfig : adminPermissionsConfig
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
if (routeType === "customer") return customerPermissionsConfig
|
|
782
|
+
if (routeType === "workstation") return workerPermissionsConfig
|
|
783
|
+
if (routeType === "retail") return agentPermissionsConfig
|
|
784
|
+
if (routeType === "driver") return driverPermissionsConfig
|
|
785
|
+
|
|
786
|
+
return {}
|
|
787
|
+
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
const checkPermissionAllow = ({
|
|
791
|
+
routeType: overrideRouteType,
|
|
792
|
+
scopeType: overrideScopeType,
|
|
793
|
+
moduleType: overrideModuleType,
|
|
794
|
+
functionType
|
|
795
|
+
}: CheckPermissionAllowProps) => {
|
|
796
|
+
|
|
797
|
+
let permissionStatus = false;
|
|
798
|
+
|
|
799
|
+
try {
|
|
800
|
+
|
|
801
|
+
let _scopeType_ = overrideScopeType || scopeType
|
|
802
|
+
let _moduleType_ = overrideModuleType || moduleType
|
|
803
|
+
|
|
804
|
+
let _routeType = overrideRouteType || routeType;
|
|
805
|
+
|
|
806
|
+
if (!_routeType) throw new Error(`Invalid route type in permission`)
|
|
807
|
+
|
|
808
|
+
let permissionConfigs = getPermissionConfig(routeType)
|
|
809
|
+
|
|
810
|
+
// if (routeType === "administrator") permissionConfigs = adminPermissionsConfig
|
|
811
|
+
// if (routeType === "customer") permissionConfigs = customerPermissionsConfig
|
|
812
|
+
// if (routeType === "workstation") permissionConfigs = workerPermissionsConfig
|
|
813
|
+
// if (routeType === "retail") permissionConfigs = retailPermissionsConfig
|
|
814
|
+
// if (routeType === "driver") permissionConfigs = driverPermissionsConfig
|
|
815
|
+
|
|
816
|
+
let _scopeType = _scopeType_ as keyof typeof permissionConfigs;
|
|
817
|
+
let _moduleType = _moduleType_;
|
|
818
|
+
let _functionType = functionType;
|
|
819
|
+
|
|
820
|
+
// if (overrideRouteType) _routeType =
|
|
821
|
+
// if (overrideScopeId) _scopeType =
|
|
822
|
+
// if (overrideScopeType) _moduleType = overrideScopeType
|
|
823
|
+
// if (overrideFunctionType) _functionType = overrideFunctionType
|
|
824
|
+
|
|
825
|
+
// check the scope id valid
|
|
826
|
+
if (checkValidScopeId(_scopeType) === false)
|
|
827
|
+
throw new Error(`Unsupported scope id : ${_scopeType}`)
|
|
828
|
+
|
|
829
|
+
const scopeConfig = permissionConfigs[_scopeType];
|
|
830
|
+
|
|
831
|
+
if (!scopeConfig) {
|
|
832
|
+
throw new Error(`Scope config is missing for: ${_scopeType}`);
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
if (!checkObjectHasKey(scopeConfig, _moduleType)) {
|
|
836
|
+
throw new Error(`Unsupported scope type: ${_moduleType} (${_scopeType})`);
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
const moduleConfig = scopeConfig[_moduleType];
|
|
840
|
+
|
|
841
|
+
if (!moduleConfig) {
|
|
842
|
+
throw new Error(`Module config is missing: ${_moduleType} (${_scopeType})`);
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
if (!checkObjectHasKey(moduleConfig, _functionType)) {
|
|
846
|
+
console.log('_scopeType', _scopeType)
|
|
847
|
+
console.log('_moduleType', _moduleType)
|
|
848
|
+
console.log('moduleConfig', moduleConfig, scopeConfig, _functionType)
|
|
849
|
+
throw new Error(
|
|
850
|
+
`Unsupported function type: ${_moduleType} > ${_functionType} (${_scopeType})`
|
|
851
|
+
);
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
// let permissionName = _functionType;
|
|
855
|
+
// let permissionStatus = false;
|
|
856
|
+
|
|
857
|
+
// console.log('permissionConfigs[_scopeType][_moduleType]', routeType, permissionConfigs[_scopeType][_moduleType], _functionType)
|
|
858
|
+
|
|
859
|
+
// check routeType exists
|
|
860
|
+
// if (checkObjectHasKey({
|
|
861
|
+
// obj: permissionConfigs[_scopeType][_moduleType][_functionType],
|
|
862
|
+
// key: routeType
|
|
863
|
+
// })) {
|
|
864
|
+
|
|
865
|
+
// system configured has this option
|
|
866
|
+
// permissionStatus = permissionConfigs[_scopeType][_moduleType][_functionType][_routeType]
|
|
867
|
+
// let allowFunctions = permissionConfigs[_scopeType][_moduleType]
|
|
868
|
+
|
|
869
|
+
// console.log('permissionStatus', _scopeType, permissionConfigs[_scopeType][_moduleType][_functionType], _moduleType, _functionType, permissionStatus)
|
|
870
|
+
|
|
871
|
+
// need to check the auth access token for permissions for this logged in user
|
|
872
|
+
// if (permissionStatus) {
|
|
873
|
+
|
|
874
|
+
// console.log('checkIsOwnerUser()', checkIsOwnerUser())
|
|
875
|
+
|
|
876
|
+
// if (checkIsOwnerUser() === true) {
|
|
877
|
+
if (isOwnerUser === true) {
|
|
878
|
+
// is owner always all permission open
|
|
879
|
+
permissionStatus = true
|
|
880
|
+
} else {
|
|
881
|
+
|
|
882
|
+
// get the scope value
|
|
883
|
+
// let _selectedScopes = moduleConfig; // scopeIds[_scopeType]
|
|
884
|
+
|
|
885
|
+
// override the permission if the real auth token access allow
|
|
886
|
+
permissionStatus = validatePermission({
|
|
887
|
+
// routeType,
|
|
888
|
+
// parentScopeType: _scopeType,
|
|
889
|
+
scopeType: _scopeType,
|
|
890
|
+
// parentScopeValue: "", // _selectedScopes?.value,
|
|
891
|
+
// scopeType: _moduleType,
|
|
892
|
+
moduleType: _moduleType,
|
|
893
|
+
functionType: _functionType
|
|
894
|
+
})
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
// }
|
|
898
|
+
|
|
899
|
+
// } else {
|
|
900
|
+
// permissionStatus = false; // not exists mean no permission
|
|
901
|
+
// // throw new Error(`Unsupported permission configs`, permissionConfigs[selectScopeId][selectScopeType][_functionType])
|
|
902
|
+
// }
|
|
903
|
+
|
|
904
|
+
// return permissionStatus
|
|
905
|
+
|
|
906
|
+
} catch (error) {
|
|
907
|
+
permissionStatus = false
|
|
908
|
+
console.log('error', error)
|
|
909
|
+
} finally {
|
|
910
|
+
return permissionStatus
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
// const list = async (props: PermissionLocationProps) => {
|
|
916
|
+
|
|
917
|
+
// const { locationType: overrideLocationType } = props;
|
|
918
|
+
|
|
919
|
+
// let _locationType = overrideLocationType || locationType
|
|
920
|
+
|
|
921
|
+
// let url: string
|
|
922
|
+
|
|
923
|
+
// if (_locationType === "location") { // only for location
|
|
924
|
+
|
|
925
|
+
// url = buildApiListUrl(
|
|
926
|
+
// `${endpoint2}/${_locationType}`,
|
|
927
|
+
// props
|
|
928
|
+
// );
|
|
929
|
+
|
|
930
|
+
// } else { // for rack, slot, zone
|
|
931
|
+
|
|
932
|
+
// url = buildApiListUrl(
|
|
933
|
+
// `${endpoint2}/${_locationType}/${props?.locationId}`,
|
|
934
|
+
// props
|
|
935
|
+
// );
|
|
936
|
+
|
|
937
|
+
// }
|
|
938
|
+
|
|
939
|
+
// const response = await makeCall({
|
|
940
|
+
// url,
|
|
941
|
+
// method: "get",
|
|
942
|
+
// payload: {},
|
|
943
|
+
// // configuration
|
|
944
|
+
// });
|
|
945
|
+
|
|
946
|
+
// return response;
|
|
947
|
+
|
|
948
|
+
// }
|
|
949
|
+
|
|
950
|
+
// const get = async (props: GetPermissionProps) => {
|
|
951
|
+
|
|
952
|
+
// const { id, locationType: overrideLocationType } = props;
|
|
953
|
+
|
|
954
|
+
// const url = buildApiGetUrl(
|
|
955
|
+
// `${endpoint1}/${overrideLocationType || locationType}/${id}`,
|
|
956
|
+
// props
|
|
957
|
+
// );
|
|
958
|
+
|
|
959
|
+
// const response = await makeCall({
|
|
960
|
+
// url,
|
|
961
|
+
// method: "get",
|
|
962
|
+
// payload: {},
|
|
963
|
+
// // configuration
|
|
964
|
+
// });
|
|
965
|
+
|
|
966
|
+
// return response;
|
|
967
|
+
|
|
968
|
+
// }
|
|
969
|
+
|
|
970
|
+
// const create = async ({ data, locationType: overrideLocationType, locationTargetType: overrideLocationTargetType }: CreatePermissionProps) => {
|
|
971
|
+
|
|
972
|
+
// let _locationType = overrideLocationType || locationType
|
|
973
|
+
|
|
974
|
+
// let payload: any = getCreatePayload(_locationType, data)
|
|
975
|
+
|
|
976
|
+
// let url = `${endpoint1}`;
|
|
977
|
+
|
|
978
|
+
// let postData = {
|
|
979
|
+
// scope: {
|
|
980
|
+
// target: overrideLocationTargetType || locationTargetType,
|
|
981
|
+
// action: "",
|
|
982
|
+
// },
|
|
983
|
+
// payload
|
|
984
|
+
// }
|
|
985
|
+
|
|
986
|
+
// const response = await makeCall({
|
|
987
|
+
// url,
|
|
988
|
+
// method: "post",
|
|
989
|
+
// payload: postData
|
|
990
|
+
// });
|
|
991
|
+
|
|
992
|
+
// return response;
|
|
993
|
+
|
|
994
|
+
// }
|
|
995
|
+
|
|
996
|
+
// const update = async ({ id, data, locationType: overrideLocationType, locationTargetType: overrideLocationTargetType }: UpdatePermissionProps) => {
|
|
997
|
+
|
|
998
|
+
// let url = `${endpoint1}/${id}`
|
|
999
|
+
|
|
1000
|
+
// let _locationType = overrideLocationType || locationType
|
|
1001
|
+
|
|
1002
|
+
// let payload: any = getUpdatePayload(_locationType, data)
|
|
1003
|
+
|
|
1004
|
+
// const postData = {
|
|
1005
|
+
// scope: {
|
|
1006
|
+
// target: overrideLocationTargetType || locationTargetType,
|
|
1007
|
+
// action: "",
|
|
1008
|
+
// },
|
|
1009
|
+
// payload
|
|
1010
|
+
// }
|
|
1011
|
+
|
|
1012
|
+
// const response = await makeCall({
|
|
1013
|
+
// url,
|
|
1014
|
+
// method: "put",
|
|
1015
|
+
// payload: postData
|
|
1016
|
+
// });
|
|
1017
|
+
|
|
1018
|
+
// return response;
|
|
1019
|
+
|
|
1020
|
+
// }
|
|
1021
|
+
|
|
1022
|
+
// const remove = async ({ ids, locationTargetType: overrideLocationTargetType }: RemovePermissionProps) => {
|
|
1023
|
+
|
|
1024
|
+
// let url = `${endpoint2}/delete`
|
|
1025
|
+
|
|
1026
|
+
// const postData = {
|
|
1027
|
+
// scope: {
|
|
1028
|
+
// target: overrideLocationTargetType || locationTargetType,
|
|
1029
|
+
// },
|
|
1030
|
+
// payload: {
|
|
1031
|
+
// ids
|
|
1032
|
+
// }
|
|
1033
|
+
// }
|
|
1034
|
+
|
|
1035
|
+
// const response = await makeCall({
|
|
1036
|
+
// url,
|
|
1037
|
+
// method: "post",
|
|
1038
|
+
// payload: postData
|
|
1039
|
+
// });
|
|
1040
|
+
|
|
1041
|
+
// return response;
|
|
1042
|
+
|
|
1043
|
+
// }
|
|
1044
|
+
|
|
1045
|
+
// const getDataTypes = async ({ locationType: overrideLocationType }: GetDataTypePermissionProps) => {
|
|
1046
|
+
|
|
1047
|
+
// let url = `${endpoint2}/data_types/${overrideLocationType || locationType}`
|
|
1048
|
+
|
|
1049
|
+
// const response = await makeCall({
|
|
1050
|
+
// url,
|
|
1051
|
+
// method: "get",
|
|
1052
|
+
// });
|
|
1053
|
+
|
|
1054
|
+
// return response;
|
|
1055
|
+
|
|
1056
|
+
// }
|
|
1057
|
+
|
|
1058
|
+
return {
|
|
1059
|
+
getPermissionConfig,
|
|
1060
|
+
checkPermissionAllow,
|
|
1061
|
+
changePermission,
|
|
1062
|
+
// list,
|
|
1063
|
+
// get,
|
|
1064
|
+
// create,
|
|
1065
|
+
// update,
|
|
1066
|
+
// remove,
|
|
1067
|
+
// getDataTypes
|
|
1068
|
+
};
|
|
1069
|
+
}
|