identity-admin 1.25.16 → 1.25.18

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 (141) hide show
  1. package/README.md +126 -126
  2. package/lib/Dashboard.d.ts +14 -14
  3. package/lib/Dashboard.js +95 -95
  4. package/lib/container/helpers/HelperInversify.d.ts +6 -6
  5. package/lib/container/helpers/HelperInversify.js +10 -10
  6. package/lib/container/helpers/HelperTypes.d.ts +5 -5
  7. package/lib/container/helpers/HelperTypes.js +7 -7
  8. package/lib/container/index.d.ts +1 -1
  9. package/lib/container/index.js +14 -14
  10. package/lib/container/repositories/RepositoryInversify.d.ts +4 -4
  11. package/lib/container/repositories/RepositoryInversify.js +13 -13
  12. package/lib/container/repositories/RepositoryTypes.d.ts +4 -4
  13. package/lib/container/repositories/RepositoryTypes.js +6 -6
  14. package/lib/container/types.d.ts +8 -8
  15. package/lib/container/types.js +9 -9
  16. package/lib/controllers/ActionController.d.ts +8 -8
  17. package/lib/controllers/ActionController.js +79 -79
  18. package/lib/controllers/DashboardController.d.ts +41 -41
  19. package/lib/controllers/DashboardController.js +602 -595
  20. package/lib/controllers/ResourceController.d.ts +15 -15
  21. package/lib/controllers/ResourceController.js +134 -132
  22. package/lib/helpers/ActionsGenerator.d.ts +11 -11
  23. package/lib/helpers/ActionsGenerator.js +179 -175
  24. package/lib/helpers/FiltersHelper.d.ts +9 -9
  25. package/lib/helpers/FiltersHelper.js +105 -105
  26. package/lib/helpers/LocalesHelper.d.ts +4 -4
  27. package/lib/helpers/LocalesHelper.js +73 -73
  28. package/lib/helpers/LocalizedStringHelper.d.ts +9 -9
  29. package/lib/helpers/LocalizedStringHelper.js +57 -57
  30. package/lib/helpers/Permissions/PermissionFetcher.d.ts +7 -7
  31. package/lib/helpers/Permissions/PermissionFetcher.js +78 -78
  32. package/lib/helpers/Permissions/PermissionLabel.d.ts +2 -2
  33. package/lib/helpers/Permissions/PermissionLabel.js +42 -42
  34. package/lib/helpers/Permissions/PermissionMapper.d.ts +13 -13
  35. package/lib/helpers/Permissions/PermissionMapper.js +35 -35
  36. package/lib/helpers/Permissions/PermissionResource.d.ts +5 -5
  37. package/lib/helpers/Permissions/PermissionResource.js +31 -31
  38. package/lib/helpers/Permissions/PermissionSavingService.d.ts +13 -13
  39. package/lib/helpers/Permissions/PermissionSavingService.js +32 -32
  40. package/lib/helpers/Permissions/SavePermissionGroup.d.ts +6 -6
  41. package/lib/helpers/Permissions/SavePermissionGroup.js +32 -32
  42. package/lib/helpers/Permissions/UpdatePermissionGroup.d.ts +6 -6
  43. package/lib/helpers/Permissions/UpdatePermissionGroup.js +50 -50
  44. package/lib/helpers/Permissions/types.d.ts +17 -17
  45. package/lib/helpers/Permissions/types.js +2 -2
  46. package/lib/helpers/PopulationHelper.d.ts +12 -12
  47. package/lib/helpers/PopulationHelper.js +50 -50
  48. package/lib/helpers/ResourceGenerator.d.ts +9 -9
  49. package/lib/helpers/ResourceGenerator.js +172 -172
  50. package/lib/helpers/ResourceHelper.d.ts +28 -28
  51. package/lib/helpers/ResourceHelper.js +376 -376
  52. package/lib/helpers/SchemaGenerator.d.ts +5 -5
  53. package/lib/helpers/SchemaGenerator.js +97 -97
  54. package/lib/helpers/SchemaHelper.d.ts +5 -5
  55. package/lib/helpers/SchemaHelper.js +21 -21
  56. package/lib/locales/en.json +53 -53
  57. package/lib/middlewares/isAuth.d.ts +13 -13
  58. package/lib/middlewares/isAuth.js +43 -43
  59. package/lib/models/ModelNames.d.ts +7 -7
  60. package/lib/models/ModelNames.js +10 -10
  61. package/lib/models/adminpermission/AdminPermission.d.ts +6 -6
  62. package/lib/models/adminpermission/AdminPermission.js +23 -23
  63. package/lib/models/adminpermission/IAdminPermission.d.ts +13 -13
  64. package/lib/models/adminpermission/IAdminPermission.js +2 -2
  65. package/lib/models/customPage/CustomPage.d.ts +2 -2
  66. package/lib/models/customPage/CustomPage.js +38 -38
  67. package/lib/models/customPage/ICustomPage.d.ts +17 -17
  68. package/lib/models/customPage/ICustomPage.js +2 -2
  69. package/lib/models/file/File.d.ts +2 -2
  70. package/lib/models/file/File.js +23 -23
  71. package/lib/models/file/IFile.d.ts +15 -15
  72. package/lib/models/file/IFile.js +2 -2
  73. package/lib/models/location/ILocation.d.ts +14 -14
  74. package/lib/models/location/ILocation.js +2 -2
  75. package/lib/models/location/Location.d.ts +2 -2
  76. package/lib/models/location/Location.js +21 -21
  77. package/lib/models/modelConfiguration/IModelConfigurations.d.ts +29 -29
  78. package/lib/models/modelConfiguration/IModelConfigurations.js +2 -2
  79. package/lib/models/modelConfiguration/ModelConfiguration.d.ts +13 -13
  80. package/lib/models/modelConfiguration/ModelConfiguration.js +95 -95
  81. package/lib/models/permission/IPermission.d.ts +14 -14
  82. package/lib/models/permission/IPermission.js +2 -2
  83. package/lib/models/permission/Permission.d.ts +2 -2
  84. package/lib/models/permission/Permission.js +21 -21
  85. package/lib/models/request-log/IRequestLog.d.ts +22 -22
  86. package/lib/models/request-log/IRequestLog.js +2 -2
  87. package/lib/models/request-log/RequestLog.d.ts +3 -3
  88. package/lib/models/request-log/RequestLog.js +51 -51
  89. package/lib/repositories/DashboardRepository.d.ts +5 -5
  90. package/lib/repositories/DashboardRepository.js +12 -12
  91. package/lib/repositories/Repository.d.ts +68 -68
  92. package/lib/repositories/Repository.js +212 -212
  93. package/lib/repositories/RequestLogRepository.d.ts +10 -10
  94. package/lib/repositories/RequestLogRepository.js +54 -54
  95. package/lib/repositories/SaveResult.d.ts +14 -14
  96. package/lib/repositories/SaveResult.js +18 -18
  97. package/lib/router/index.d.ts +8 -8
  98. package/lib/router/index.js +104 -104
  99. package/lib/types/DashbordConfig.d.ts +21 -21
  100. package/lib/types/DashbordConfig.js +2 -2
  101. package/lib/types/IConfigurationFile.d.ts +9 -6
  102. package/lib/types/IConfigurationFile.js +2 -2
  103. package/lib/types/IResourceFile.d.ts +606 -584
  104. package/lib/types/IResourceFile.js +2 -2
  105. package/lib/types/IResourceResponse.d.ts +95 -95
  106. package/lib/types/IResourceResponse.js +2 -2
  107. package/lib/types/helpers.d.ts +61 -61
  108. package/lib/types/helpers.js +71 -71
  109. package/lib/utils/ResourceUtils.d.ts +2 -2
  110. package/lib/utils/ResourceUtils.js +7 -7
  111. package/lib/utils/ResponseUtils.d.ts +11 -11
  112. package/lib/utils/ResponseUtils.js +41 -41
  113. package/lib/utils/StringUtils.d.ts +9 -9
  114. package/lib/utils/StringUtils.js +46 -46
  115. package/lib/view/asset-manifest.json +18 -18
  116. package/lib/view/assets/icons/delete_icon.svg +3 -3
  117. package/lib/view/assets/icons/flags/ic_flag_cn.svg +9 -9
  118. package/lib/view/assets/icons/flags/ic_flag_sa.svg +9 -9
  119. package/lib/view/assets/icons/flags/ic_flag_vn.svg +9 -9
  120. package/lib/view/assets/icons/info_icon.svg +3 -3
  121. package/lib/view/assets/icons/navbar/ic_banking.svg +5 -5
  122. package/lib/view/assets/icons/navbar/ic_invoice.svg +4 -4
  123. package/lib/view/assets/icons/navbar/ic_kanban.svg +7 -7
  124. package/lib/view/assets/icons/navbar/ic_menu_item.svg +8 -8
  125. package/lib/view/assets/icons/small_info_icon.svg +3 -3
  126. package/lib/view/assets/illustrations/Group 16.svg +4 -4
  127. package/lib/view/assets/illustrations/logo.svg +5 -5
  128. package/lib/view/favicon/browserconfig.xml +9 -9
  129. package/lib/view/favicon/safari-pinned-tab.svg +182 -182
  130. package/lib/view/favicon/site.webmanifest +19 -19
  131. package/lib/view/fonts/index.css +18 -18
  132. package/lib/view/index.html +52 -52
  133. package/lib/view/manifest.json +20 -20
  134. package/lib/view/robots.txt +3 -3
  135. package/lib/view/static/css/main.54de06ef.css +1 -1
  136. package/lib/view/static/js/574.778b5963.chunk.js +1 -1
  137. package/lib/view/static/js/678.521704a3.chunk.js +1 -1
  138. package/lib/view/static/js/798.54856416.chunk.js +1 -1
  139. package/lib/view/static/js/main.4687f255.js +2 -2
  140. package/lib/view/static/js/main.4687f255.js.LICENSE.txt +214 -214
  141. package/package.json +51 -51
@@ -1,584 +1,606 @@
1
- import { Document, Model } from "mongoose";
2
- import { IRequest } from "../middlewares/isAuth";
3
- import { IRepository } from "../repositories/Repository";
4
- import SaveResult from "../repositories/SaveResult";
5
- import { ActionNames, ActionTypes, FieldTypes, FileTypes, HandlerStrategy, Virtuals } from "./helpers";
6
- declare type orderTypes = "asc" | "desc";
7
- declare type VirtualFieldTypes = "password" | "ref" | "Array";
8
- declare type Severity = "success" | "info" | "warning" | "error";
9
- declare type ButtonColors = "inherit" | "primary" | "secondary" | "success" | "error" | "info" | "warning";
10
- declare type ButtonVariants = "text" | "outlined" | "contained";
11
- declare type ButtonSizes = "small" | "medium" | "large";
12
- declare type PopulateFunction = (populatedString: any) => Promise<any>;
13
- interface Parent {
14
- /**
15
- * Name of the parent
16
- */
17
- name: string;
18
- /**
19
- * Icon of the parent. You can get the icons from
20
- * {@link https://mui.com/material-ui/material-icons/}
21
- */
22
- icon: string;
23
- }
24
- interface IPopulate {
25
- /**
26
- * This function is called for all the endpoints to have an access over the populated string
27
- */
28
- all?: PopulateFunction;
29
- /**
30
- * This function is called for the list endpoint to have an access over the populated string
31
- */
32
- list?: PopulateFunction;
33
- /**
34
- * This function is called for the get one endpoint either in show or form an access over the populated string
35
- */
36
- show?: PopulateFunction;
37
- }
38
- interface Action {
39
- /**
40
- * Specify if this action is accessible or not.
41
- * @default True for show, edit, delete, and new.
42
- * @default false for bulk delete.
43
- * You can ovveride any of these values here.
44
- */
45
- isAccessible?: boolean;
46
- /**
47
- * Specify if the page requires to be reloaded after executing the action
48
- * @default Fale for show, edit, delete, and new.
49
- */
50
- reloadAfterAction?: boolean;
51
- /**
52
- * The property that manages which admin role can use this action.
53
- * This function's result alters the isAccessible value. So no need to use both properties.
54
- * If both are used then isAccessible has the higher priority.
55
- * @default 'Same as isAccessible'
56
- */
57
- isAllowed?: (currentUser: Document) => boolean;
58
- }
59
- interface ICrudOperations {
60
- index?: {
61
- /**
62
- * Before handler that gives you the access to the filter object.
63
- * You can add to the filter object any key and value that will be used in the filter query before getting the records for list.
64
- * @returns the filter object
65
- */
66
- before?: (req: IRequest, filter: {
67
- [key: string]: any;
68
- }, currentUser: Document) => Promise<{
69
- [key: string]: any;
70
- }>;
71
- /**
72
- * After handler that gives you the access to the array of documents.
73
- * @returns the array of documents
74
- */
75
- after?: (req: IRequest, documents: Document[], currentUser: Document) => Promise<Document[]>;
76
- };
77
- create?: {
78
- /**
79
- * Before handler that is called before creating a new record.
80
- * This function gives you the access to the record params before saving it, you can perform any update to the params before saving it.
81
- * @returns the params
82
- */
83
- before?: (req: IRequest, params: any, currentUser: Document) => Promise<any>;
84
- /**
85
- * After handler that gives you the access to the saved document.
86
- * @returns the saved document
87
- */
88
- after?: (req: IRequest, document: Document, currentUser: Document, params: any) => Promise<Document>;
89
- };
90
- update?: {
91
- /**
92
- * Before handler that is called before updating a record.
93
- * This function gives you the access to the record params before saving it, you can perform any update to the params before saving it.
94
- * @returns the params
95
- */
96
- before?: (req: IRequest, params: any, currentUser: Document) => Promise<any>;
97
- /**
98
- * After handler that gives you the access to the updated document.
99
- * @returns the updated document
100
- */
101
- after?: (req: IRequest, document: Document, params: any, currentUser: Document) => Promise<Document>;
102
- /**
103
- * update handler that gives you the access to the run custom update method with custom query.
104
- * @returns saved result with updated document
105
- */
106
- update?: (req: IRequest, record: Document, recordParams: any, currentUser: Document) => Promise<SaveResult<any>>;
107
- };
108
- show?: {
109
- after?: (req: IRequest, record: Document) => Promise<{
110
- record: Document;
111
- [key: string]: any;
112
- }>;
113
- };
114
- }
115
- export interface ActionData {
116
- /**
117
- * Record document
118
- */
119
- record: any;
120
- /**
121
- * Current user data
122
- */
123
- currentUser: Document;
124
- /**
125
- * Resource data to which this record belongs
126
- */
127
- resource: {
128
- /**
129
- * Model name of this table.
130
- */
131
- name: string;
132
- /**
133
- * Path of the resource to which you can redirect.
134
- */
135
- path: string;
136
- /**
137
- * Repository of this resource.
138
- */
139
- repository: IRepository<Document>;
140
- };
141
- }
142
- interface IFilters {
143
- /**
144
- * Scope filter props.
145
- * Can be either auto or manual. It cannot be both.
146
- * This filter is not accessible by default
147
- */
148
- scopes?: {
149
- /**
150
- * Specify if this filter is accessible or not
151
- * @default false
152
- */
153
- isAccessible: boolean;
154
- /**
155
- * Automatic scope that filters by the specified key with one of the given options
156
- * This filter works automatically by mentioning the key as saved in the database along with the values that this key can has.
157
- * It doesn't need a handler
158
- */
159
- auto?: IAutoScope;
160
- /**
161
- * Manual scope by using a handler.
162
- * In this case you can put the options you like with specifying in the handler what to do with each option.
163
- */
164
- manual?: IManualScope;
165
- };
166
- /**
167
- * Search bar filter props
168
- */
169
- searchBar?: {
170
- /**
171
- * Specify if this filter is accessible or not
172
- * @default true
173
- */
174
- isAccessible: boolean;
175
- };
176
- }
177
- interface IAutoScope {
178
- /**
179
- * Key of property as specified in the database
180
- */
181
- key: string;
182
- /**
183
- * Array of values that this key can have
184
- */
185
- options: string[];
186
- }
187
- interface IManualScope {
188
- /**
189
- * Array of values that will be appeared in the scope
190
- */
191
- options: string[];
192
- /**
193
- * A handler that will be called when scope filter is used.
194
- * This handler should perform a switch case on the specified options values, each case set the filter on its way.
195
- */
196
- handler: (filter: {
197
- [key: string]: any;
198
- }, scope: string, currentUser: Document) => Promise<{
199
- [key: string]: any;
200
- }>;
201
- }
202
- export interface IFieldValue {
203
- /**
204
- * If the field is required in the schema and you don't want it to be required in the form, you can override this here.
205
- * @default 'same as schema'
206
- */
207
- required?: boolean;
208
- /**
209
- * Specify either this field can be edited or not.
210
- * @default true
211
- */
212
- isEditable?: boolean;
213
- /**
214
- * Specify the type of the field. Can be used for specifying localized string, image,... etc.
215
- * @default 'Same as schema''
216
- */
217
- type?: FieldTypes;
218
- /**
219
- * Specify the enum values if the field type is an enum.
220
- * You can give custom labels with custom background color of the chib as color and label color as labelColor
221
- * @default 'Same as schema''
222
- */
223
- enumValues?: string[] | {
224
- [key: string]: {
225
- label: string;
226
- color: string;
227
- labelColor: string;
228
- };
229
- };
230
- /**
231
- * Specify the allowed country codes.
232
- * @required if the type is phone number
233
- * ex: ["sa", "eg", ...]
234
- */
235
- countryCodes?: string[];
236
- /**
237
- * Specify the array type if the field is of type array.
238
- * @default 'Same as schema''
239
- */
240
- arrayType?: FieldTypes;
241
- /**
242
- * Specify if the array is draggable. Only used when the field type is an array.
243
- * @default 'true''
244
- */
245
- isDraggable?: boolean;
246
- /**
247
- * Can be used only if this field is a reference to the Image collection
248
- */
249
- mediaUploader?: boolean;
250
- /**
251
- * Specify the type of the file to be uploaded. Only required if the media uploader is true.
252
- * @default image
253
- */
254
- fileType?: FileTypes;
255
- /**
256
- * Specify if the date is shown with time or not. Only used if the field type is Date
257
- * @default false
258
- */
259
- withTime?: boolean;
260
- /**
261
- * Specify the api route that to be called for getting the referenced values
262
- * @default undefined
263
- */
264
- apiRoute?: string;
265
- /**
266
- * Path of the value inside the model schema
267
- * @default undefined
268
- */
269
- valuePath?: string;
270
- /**
271
- * Specify if this property is clickable or not in the list view.
272
- * @default undefined
273
- */
274
- isClickable?: boolean;
275
- /**
276
- * Specify the keys that will be shown in the nested schema. Only used when the type is nested schema
277
- * @default undefined
278
- */
279
- keys?: string[];
280
- /**
281
- * Specify the nested schema. Only used if the type is nested schema.
282
- * @default undefined
283
- */
284
- schema?: IModel | {
285
- [key: string]: IFieldValue;
286
- };
287
- }
288
- export interface IVirtualValue {
289
- /**
290
- * For now we have some virtual fields that can be added
291
- * 1) Password: If you want to add password field in the creation form for example
292
- * 2) ref: If it is a one to many realtion. For example, if you want to get all subCatogeries that belong to a category when you show the category record
293
- * 3) array: If this field is an array
294
- */
295
- type: VirtualFieldTypes;
296
- /**
297
- * Array type exists only if the type is array
298
- */
299
- arrayType?: string;
300
- /**
301
- * Defines where this virtaul field need to be appeared
302
- */
303
- showIn: Virtuals;
304
- required: boolean;
305
- /**
306
- * Define Virtual field's resource in case of ref type or array of ref type
307
- */
308
- resource?: Model<any, any>;
309
- /**
310
- * Define Filter query creator required in case of showIn Filter
311
- */
312
- handler?: (filterQuery: {
313
- [key: string]: any;
314
- }, value: any | any[]) => Promise<{
315
- [key: string]: any;
316
- }>;
317
- }
318
- export interface IModel {
319
- /**
320
- * virtual data props
321
- */
322
- virtuals?: {
323
- [key: string]: IVirtualValue;
324
- };
325
- }
326
- interface ActionOptions {
327
- show?: Action;
328
- new?: Action;
329
- edit?: Action;
330
- delete?: Action;
331
- bulkDelete?: Action;
332
- /**
333
- * Any extra action to be added.
334
- */
335
- extras?: ExtraAction[];
336
- }
337
- export interface ExtraAction {
338
- /**
339
- * Key of this action.
340
- * Should be unique in the same resource file
341
- */
342
- key: string;
343
- /**
344
- * Name of this action
345
- */
346
- name: string;
347
- /**
348
- * Icon of this action.
349
- * {@link https://mui.com/material-ui/material-icons/}
350
- */
351
- icon: string;
352
- /**
353
- * Color of the action button
354
- * In case of bulk actions it is one of the button colors. @default inherit
355
- * In case of record actions it is any color like red, green, ... @default black
356
- */
357
- color?: string | ButtonColors;
358
- /**
359
- * Size of the action button. Only used in case of bulk actions
360
- * @default small
361
- */
362
- size?: ButtonSizes;
363
- /**
364
- * Variant of the action button. Only used in case of bulk actions
365
- * @default contained
366
- */
367
- variant?: ButtonVariants;
368
- /**
369
- * Action type if it is record action or resource action.
370
- */
371
- actionType: ActionTypes;
372
- /**
373
- * Guard message title that appears before executing the action to confirm execution.
374
- * @default 'No guard message'
375
- */
376
- guardTitle?: string;
377
- /**
378
- * Guard message body that appears before executing the action to confirm execution.
379
- * @default 'No guard message'
380
- */
381
- guard?: string;
382
- /**
383
- * Alert message appear after executing this action.
384
- * @default 'Action was executed successfully'
385
- */
386
- message?: string;
387
- /**
388
- * The severity of the alert. This defines the color and icon used.
389
- * @default 'success'
390
- */
391
- severity?: Severity;
392
- /**
393
- * Specify if you need the dialog to be in full screen or not. Used only in case of custom component strategy
394
- * @default 'false'
395
- */
396
- fullScreen?: boolean;
397
- /**
398
- * @returns boolean value.
399
- * This value Specifies to which records should this action appears.
400
- * @default 'Action is shown to all records'
401
- */
402
- isVisible?: (data: ActionData) => Promise<boolean>;
403
- /**
404
- * Handler function that is executed after clicking the action.
405
- */
406
- handler: (req: IRequest, res: any, data: ActionData) => Promise<IActionHandlerResponse>;
407
- /**
408
- * Icon of this action.
409
- * {@link https://mui.com/material-ui/material-icons/}
410
- */
411
- handlerStrategy?: HandlerStrategy;
412
- }
413
- export interface IActionHandlerResponse {
414
- /**
415
- * The action taken after executing the action.
416
- * For example, if you would like to go to list after executing the action, just set this value by list
417
- */
418
- action: ActionNames;
419
- /**
420
- * Path of the resource that is intended to redirect.
421
- * Is set to resource.path if you would like to be in the same table
422
- */
423
- path: string;
424
- /**
425
- * Id of the record that is used in actions that needs record id like show or edit
426
- */
427
- recordId?: string;
428
- /**
429
- * Path of the uploaded file in case of file download handling strategy
430
- */
431
- filePath?: string;
432
- }
433
- export interface IResourceFile {
434
- properties: {
435
- /**
436
- * The model
437
- */
438
- resource: Model<any, any>;
439
- /**
440
- * Model name as saved in the data base.
441
- */
442
- modelName: string;
443
- /**
444
- * Name of this model appeared on the nav bar.
445
- * @default 'Model name'
446
- */
447
- name?: string;
448
- /**
449
- * Property of this table that is shown as the link for the record.
450
- * Used to be searched by in the search bar.
451
- * If not mentioned explicitly, a search is done on the schema to check for property title, name, or email.
452
- * If these properties are not found, _id is taken.
453
- */
454
- title?: string;
455
- /**
456
- * The property to be sorted by the documents.
457
- * @default 'The schema title'
458
- */
459
- defaultOrderBy?: string;
460
- /**
461
- * The property that controls the permission of this model according to the current user role.
462
- * Specify either this user is allowed to see this model or not.
463
- * @default true
464
- */
465
- isAllowed?: (currentUser: Document) => Promise<boolean>;
466
- /**
467
- * The property that controls the visibility of this resource in the nav bar
468
- * @default true
469
- */
470
- isVisible?: (currentUser: Document) => Promise<boolean>;
471
- /**
472
- * The default order
473
- * @default asc
474
- */
475
- defaultOrder?: orderTypes;
476
- /**
477
- * Number of rows per page
478
- * @default 10
479
- */
480
- defaultrowsPerPage?: number;
481
- /**
482
- * The parent that this model is belong to in the nav bar.
483
- * @default 'Set up parent'
484
- */
485
- parent?: Parent;
486
- /**
487
- * Array of fields that are completely hidden from all pages
488
- */
489
- hiddenProperties?: string[];
490
- /**
491
- * Action options for overriding existing actions accessibility or adding custom actions
492
- */
493
- actions?: ActionOptions;
494
- /**
495
- * Filters options
496
- */
497
- filters?: IFilters;
498
- /**
499
- * Using before or after handlers of any crud operation
500
- */
501
- crudOperations?: ICrudOperations;
502
- /**
503
- * Translation object of the fields' names.
504
- */
505
- keysTranslations?: {
506
- [key: string]: any;
507
- };
508
- /**
509
- * Translation object of the actions' names.
510
- */
511
- actionsTranslations?: {
512
- [key: string]: any;
513
- };
514
- /**
515
- * Override some props of a field's schema structure
516
- * Add a new virtual property
517
- */
518
- model?: {
519
- [key: string]: IFieldValue;
520
- } | IModel;
521
- /**
522
- * Override the populated object
523
- */
524
- populate?: IPopulate;
525
- /**
526
- * Disable the display of next and previous buttons in the show page
527
- * @default false
528
- */
529
- disableNextPreviousButtonsInShowPage?: boolean;
530
- /**
531
- * Disable the display of next and previous buttons in the edit page
532
- * @default false
533
- */
534
- disableNextPreviousButtonsInEditPage?: boolean;
535
- /**
536
- * The option to display the edit page instead of the show page
537
- * @default false
538
- */
539
- displayEditPageInShowPage?: boolean;
540
- /**
541
- * Specify the path of image to be shown beside the name in the reference options
542
- * @default undefined
543
- */
544
- imageOnReferencePath?: string;
545
- /**
546
- * The option to disable displaying the image beside the name in the reference options
547
- * @default false
548
- */
549
- disableImageOnReference?: boolean;
550
- /**
551
- * An object for any extra data need to be sent with the resource file
552
- * @default undefined
553
- */
554
- extras?: {
555
- [key: string]: any;
556
- };
557
- };
558
- /**
559
- * Array of properties that should be appeared in the list action.
560
- * @default 'The whole fields'
561
- */
562
- listProperties?: string[];
563
- /**
564
- * Arrays of properties that should be appeared in the show action.
565
- * @default 'The whole fields'
566
- */
567
- showProperties?: string[];
568
- /**
569
- * Array of properties that should be appeared in the create/edit form.
570
- * @default 'The whole fields'
571
- */
572
- formProperties?: string[];
573
- /**
574
- * Array of properties that should be appeared in the filter.
575
- * @default 'The whole fields'
576
- */
577
- filterProperties?: string[];
578
- /**
579
- * Array of properties that should be appeared in the quick filters.
580
- * @default 'Empty array'
581
- */
582
- quickFilterProperties?: string[];
583
- }
584
- export {};
1
+ import { Document, Model } from "mongoose";
2
+ import { IRequest } from "../middlewares/isAuth";
3
+ import { IRepository, PageInfo, PaginateParams } from "../repositories/Repository";
4
+ import SaveResult from "../repositories/SaveResult";
5
+ import { ActionNames, ActionTypes, FieldTypes, FileTypes, HandlerStrategy, Virtuals } from "./helpers";
6
+ declare type orderTypes = "asc" | "desc";
7
+ declare type VirtualFieldTypes = "password" | "ref" | "Array";
8
+ declare type Severity = "success" | "info" | "warning" | "error";
9
+ declare type ButtonColors = "inherit" | "primary" | "secondary" | "success" | "error" | "info" | "warning";
10
+ declare type ButtonVariants = "text" | "outlined" | "contained";
11
+ declare type ButtonSizes = "small" | "medium" | "large";
12
+ declare type PopulateFunction = (populatedString: any) => Promise<any>;
13
+ interface Parent {
14
+ /**
15
+ * Name of the parent
16
+ */
17
+ name: string;
18
+ /**
19
+ * Icon of the parent. You can get the icons from
20
+ * {@link https://mui.com/material-ui/material-icons/}
21
+ */
22
+ icon: string;
23
+ }
24
+ interface IPopulate {
25
+ /**
26
+ * This function is called for all the endpoints to have an access over the populated string
27
+ */
28
+ all?: PopulateFunction;
29
+ /**
30
+ * This function is called for the list endpoint to have an access over the populated string
31
+ */
32
+ list?: PopulateFunction;
33
+ /**
34
+ * This function is called for the get one endpoint either in show or form an access over the populated string
35
+ */
36
+ show?: PopulateFunction;
37
+ }
38
+ interface Action {
39
+ /**
40
+ * Specify if this action is accessible or not.
41
+ * @default True for show, edit, delete, and new.
42
+ * @default false for bulk delete.
43
+ * You can ovveride any of these values here.
44
+ */
45
+ isAccessible?: boolean;
46
+ /**
47
+ * Specify if the page requires to be reloaded after executing the action
48
+ * @default Fale for show, edit, delete, and new.
49
+ */
50
+ reloadAfterAction?: boolean;
51
+ /**
52
+ * The property that manages which admin role can use this action.
53
+ * This function's result alters the isAccessible value. So no need to use both properties.
54
+ * If both are used then isAccessible has the higher priority.
55
+ * @default 'Same as isAccessible'
56
+ */
57
+ isAllowed?: (currentUser: Document) => boolean;
58
+ /**
59
+ * The property that manages which action will be extracted from action menu in list.
60
+ * @default true for edit and show false for others
61
+ */
62
+ isMainAction?: boolean;
63
+ }
64
+ interface ICrudOperations {
65
+ index?: {
66
+ /**
67
+ * Before handler that gives you the access to the filter object.
68
+ * You can add to the filter object any key and value that will be used in the filter query before getting the records for list.
69
+ * @returns the filter object
70
+ */
71
+ before?: (req: IRequest, filter: {
72
+ [key: string]: any;
73
+ }, currentUser: Document) => Promise<{
74
+ [key: string]: any;
75
+ }>;
76
+ /**
77
+ * After handler that gives you the access to the array of documents.
78
+ * @returns the array of documents
79
+ */
80
+ after?: (req: IRequest, documents: Document[], currentUser: Document) => Promise<Document[]>;
81
+ /**
82
+ * index handler that gives you the access to the run custom index method with custom query.
83
+ * @returns result list of records
84
+ */
85
+ index?: (req: IRequest, filter: {
86
+ [key: string]: any;
87
+ }, sortQuery: {
88
+ [key: string]: any;
89
+ }, paginateParams: PaginateParams | undefined, populate: any, currentUser: Document) => Promise<{
90
+ records: Document[];
91
+ pageInfo?: PageInfo;
92
+ }>;
93
+ };
94
+ create?: {
95
+ /**
96
+ * Before handler that is called before creating a new record.
97
+ * This function gives you the access to the record params before saving it, you can perform any update to the params before saving it.
98
+ * @returns the params
99
+ */
100
+ before?: (req: IRequest, params: any, currentUser: Document) => Promise<any>;
101
+ /**
102
+ * After handler that gives you the access to the saved document.
103
+ * @returns the saved document
104
+ */
105
+ after?: (req: IRequest, document: Document, currentUser: Document, params: any) => Promise<Document>;
106
+ };
107
+ update?: {
108
+ /**
109
+ * Before handler that is called before updating a record.
110
+ * This function gives you the access to the record params before saving it, you can perform any update to the params before saving it.
111
+ * @returns the params
112
+ */
113
+ before?: (req: IRequest, params: any, currentUser: Document) => Promise<any>;
114
+ /**
115
+ * After handler that gives you the access to the updated document.
116
+ * @returns the updated document
117
+ */
118
+ after?: (req: IRequest, document: Document, params: any, currentUser: Document) => Promise<Document>;
119
+ /**
120
+ * update handler that gives you the access to the run custom update method with custom query.
121
+ * @returns saved result with updated document
122
+ */
123
+ update?: (req: IRequest, record: Document, recordParams: any, currentUser: Document) => Promise<SaveResult<any>>;
124
+ };
125
+ show?: {
126
+ after?: (req: IRequest, record: Document) => Promise<{
127
+ record: Document;
128
+ [key: string]: any;
129
+ }>;
130
+ };
131
+ }
132
+ export interface ActionData {
133
+ /**
134
+ * Record document
135
+ */
136
+ record: any;
137
+ /**
138
+ * Current user data
139
+ */
140
+ currentUser: Document;
141
+ /**
142
+ * Resource data to which this record belongs
143
+ */
144
+ resource: {
145
+ /**
146
+ * Model name of this table.
147
+ */
148
+ name: string;
149
+ /**
150
+ * Path of the resource to which you can redirect.
151
+ */
152
+ path: string;
153
+ /**
154
+ * Repository of this resource.
155
+ */
156
+ repository: IRepository<Document>;
157
+ };
158
+ }
159
+ interface IFilters {
160
+ /**
161
+ * Scope filter props.
162
+ * Can be either auto or manual. It cannot be both.
163
+ * This filter is not accessible by default
164
+ */
165
+ scopes?: {
166
+ /**
167
+ * Specify if this filter is accessible or not
168
+ * @default false
169
+ */
170
+ isAccessible: boolean;
171
+ /**
172
+ * Automatic scope that filters by the specified key with one of the given options
173
+ * This filter works automatically by mentioning the key as saved in the database along with the values that this key can has.
174
+ * It doesn't need a handler
175
+ */
176
+ auto?: IAutoScope;
177
+ /**
178
+ * Manual scope by using a handler.
179
+ * In this case you can put the options you like with specifying in the handler what to do with each option.
180
+ */
181
+ manual?: IManualScope;
182
+ };
183
+ /**
184
+ * Search bar filter props
185
+ */
186
+ searchBar?: {
187
+ /**
188
+ * Specify if this filter is accessible or not
189
+ * @default true
190
+ */
191
+ isAccessible: boolean;
192
+ };
193
+ }
194
+ interface IAutoScope {
195
+ /**
196
+ * Key of property as specified in the database
197
+ */
198
+ key: string;
199
+ /**
200
+ * Array of values that this key can have
201
+ */
202
+ options: string[];
203
+ }
204
+ interface IManualScope {
205
+ /**
206
+ * Array of values that will be appeared in the scope
207
+ */
208
+ options: string[];
209
+ /**
210
+ * A handler that will be called when scope filter is used.
211
+ * This handler should perform a switch case on the specified options values, each case set the filter on its way.
212
+ */
213
+ handler: (filter: {
214
+ [key: string]: any;
215
+ }, scope: string, currentUser: Document) => Promise<{
216
+ [key: string]: any;
217
+ }>;
218
+ }
219
+ export interface IFieldValue {
220
+ /**
221
+ * If the field is required in the schema and you don't want it to be required in the form, you can override this here.
222
+ * @default 'same as schema'
223
+ */
224
+ required?: boolean;
225
+ /**
226
+ * Specify either this field can be edited or not.
227
+ * @default true
228
+ */
229
+ isEditable?: boolean;
230
+ /**
231
+ * Specify the type of the field. Can be used for specifying localized string, image,... etc.
232
+ * @default 'Same as schema''
233
+ */
234
+ type?: FieldTypes;
235
+ /**
236
+ * Specify the enum values if the field type is an enum.
237
+ * You can give custom labels with custom background color of the chib as color and label color as labelColor
238
+ * @default 'Same as schema''
239
+ */
240
+ enumValues?: string[] | {
241
+ [key: string]: {
242
+ label: string;
243
+ color: string;
244
+ labelColor: string;
245
+ };
246
+ };
247
+ /**
248
+ * Specify the allowed country codes.
249
+ * @required if the type is phone number
250
+ * ex: ["sa", "eg", ...]
251
+ */
252
+ countryCodes?: string[];
253
+ /**
254
+ * Specify the array type if the field is of type array.
255
+ * @default 'Same as schema''
256
+ */
257
+ arrayType?: FieldTypes;
258
+ /**
259
+ * Specify if the array is draggable. Only used when the field type is an array.
260
+ * @default 'true''
261
+ */
262
+ isDraggable?: boolean;
263
+ /**
264
+ * Can be used only if this field is a reference to the Image collection
265
+ */
266
+ mediaUploader?: boolean;
267
+ /**
268
+ * Specify the type of the file to be uploaded. Only required if the media uploader is true.
269
+ * @default image
270
+ */
271
+ fileType?: FileTypes;
272
+ /**
273
+ * Specify if the date is shown with time or not. Only used if the field type is Date
274
+ * @default false
275
+ */
276
+ withTime?: boolean;
277
+ /**
278
+ * Specify the api route that to be called for getting the referenced values
279
+ * @default undefined
280
+ */
281
+ apiRoute?: string;
282
+ /**
283
+ * Path of the value inside the model schema
284
+ * @default undefined
285
+ */
286
+ valuePath?: string;
287
+ /**
288
+ * Specify if this property is clickable or not in the list view.
289
+ * @default undefined
290
+ */
291
+ isClickable?: boolean;
292
+ /**
293
+ * Specify the keys that will be shown in the nested schema. Only used when the type is nested schema
294
+ * @default undefined
295
+ */
296
+ keys?: string[];
297
+ /**
298
+ * Specify the nested schema. Only used if the type is nested schema.
299
+ * @default undefined
300
+ */
301
+ schema?: IModel | {
302
+ [key: string]: IFieldValue;
303
+ };
304
+ }
305
+ export interface IVirtualValue {
306
+ /**
307
+ * For now we have some virtual fields that can be added
308
+ * 1) Password: If you want to add password field in the creation form for example
309
+ * 2) ref: If it is a one to many realtion. For example, if you want to get all subCatogeries that belong to a category when you show the category record
310
+ * 3) array: If this field is an array
311
+ */
312
+ type: VirtualFieldTypes;
313
+ /**
314
+ * Array type exists only if the type is array
315
+ */
316
+ arrayType?: string;
317
+ /**
318
+ * Defines where this virtaul field need to be appeared
319
+ */
320
+ showIn: Virtuals;
321
+ required: boolean;
322
+ /**
323
+ * Define Virtual field's resource in case of ref type or array of ref type
324
+ */
325
+ resource?: Model<any, any>;
326
+ /**
327
+ * Define Filter query creator required in case of showIn Filter
328
+ */
329
+ handler?: (filterQuery: {
330
+ [key: string]: any;
331
+ }, value: any | any[]) => Promise<{
332
+ [key: string]: any;
333
+ }>;
334
+ }
335
+ export interface IModel {
336
+ /**
337
+ * virtual data props
338
+ */
339
+ virtuals?: {
340
+ [key: string]: IVirtualValue;
341
+ };
342
+ }
343
+ interface ActionOptions {
344
+ show?: Action;
345
+ new?: Action;
346
+ edit?: Action;
347
+ delete?: Action;
348
+ bulkDelete?: Action;
349
+ /**
350
+ * Any extra action to be added.
351
+ */
352
+ extras?: ExtraAction[];
353
+ }
354
+ export interface ExtraAction {
355
+ /**
356
+ * Key of this action.
357
+ * Should be unique in the same resource file
358
+ */
359
+ key: string;
360
+ /**
361
+ * Name of this action
362
+ */
363
+ name: string;
364
+ /**
365
+ * Icon of this action.
366
+ * {@link https://mui.com/material-ui/material-icons/}
367
+ */
368
+ icon: string;
369
+ /**
370
+ * Color of the action button
371
+ * In case of bulk actions it is one of the button colors. @default inherit
372
+ * In case of record actions it is any color like red, green, ... @default black
373
+ */
374
+ color?: string | ButtonColors;
375
+ /**
376
+ * Size of the action button. Only used in case of bulk actions
377
+ * @default small
378
+ */
379
+ size?: ButtonSizes;
380
+ /**
381
+ * Variant of the action button. Only used in case of bulk actions
382
+ * @default contained
383
+ */
384
+ variant?: ButtonVariants;
385
+ /**
386
+ * Action type if it is record action or resource action.
387
+ */
388
+ actionType: ActionTypes;
389
+ /**
390
+ * Guard message title that appears before executing the action to confirm execution.
391
+ * @default 'No guard message'
392
+ */
393
+ guardTitle?: string;
394
+ /**
395
+ * Guard message body that appears before executing the action to confirm execution.
396
+ * @default 'No guard message'
397
+ */
398
+ guard?: string;
399
+ /**
400
+ * Alert message appear after executing this action.
401
+ * @default 'Action was executed successfully'
402
+ */
403
+ message?: string;
404
+ /**
405
+ * The severity of the alert. This defines the color and icon used.
406
+ * @default 'success'
407
+ */
408
+ severity?: Severity;
409
+ /**
410
+ * Specify if you need the dialog to be in full screen or not. Used only in case of custom component strategy
411
+ * @default 'false'
412
+ */
413
+ fullScreen?: boolean;
414
+ /**
415
+ * @returns boolean value.
416
+ * This value Specifies to which records should this action appears.
417
+ * @default 'Action is shown to all records'
418
+ */
419
+ isVisible?: (data: ActionData) => Promise<boolean>;
420
+ /**
421
+ * Handler function that is executed after clicking the action.
422
+ */
423
+ handler: (req: IRequest, res: any, data: ActionData) => Promise<IActionHandlerResponse>;
424
+ /**
425
+ * Icon of this action.
426
+ * {@link https://mui.com/material-ui/material-icons/}
427
+ */
428
+ handlerStrategy?: HandlerStrategy;
429
+ /**
430
+ * The property that manages which action will be extracted from action menu in list.
431
+ * @default true for edit and show false for others
432
+ */
433
+ isMainAction?: boolean;
434
+ }
435
+ export interface IActionHandlerResponse {
436
+ /**
437
+ * The action taken after executing the action.
438
+ * For example, if you would like to go to list after executing the action, just set this value by list
439
+ */
440
+ action: ActionNames;
441
+ /**
442
+ * Path of the resource that is intended to redirect.
443
+ * Is set to resource.path if you would like to be in the same table
444
+ */
445
+ path: string;
446
+ /**
447
+ * Id of the record that is used in actions that needs record id like show or edit
448
+ */
449
+ recordId?: string;
450
+ /**
451
+ * Path of the uploaded file in case of file download handling strategy
452
+ */
453
+ filePath?: string;
454
+ }
455
+ export interface IResourceFile {
456
+ properties: {
457
+ /**
458
+ * The model
459
+ */
460
+ resource: Model<any, any>;
461
+ /**
462
+ * Model name as saved in the data base.
463
+ */
464
+ modelName: string;
465
+ /**
466
+ * Name of this model appeared on the nav bar.
467
+ * @default 'Model name'
468
+ */
469
+ name?: string;
470
+ /**
471
+ * Property of this table that is shown as the link for the record.
472
+ * Used to be searched by in the search bar.
473
+ * If not mentioned explicitly, a search is done on the schema to check for property title, name, or email.
474
+ * If these properties are not found, _id is taken.
475
+ */
476
+ title?: string;
477
+ /**
478
+ * The property to be sorted by the documents.
479
+ * @default 'The schema title'
480
+ */
481
+ defaultOrderBy?: string;
482
+ /**
483
+ * The property that controls the permission of this model according to the current user role.
484
+ * Specify either this user is allowed to see this model or not.
485
+ * @default true
486
+ */
487
+ isAllowed?: (currentUser: Document) => Promise<boolean>;
488
+ /**
489
+ * The property that controls the visibility of this resource in the nav bar
490
+ * @default true
491
+ */
492
+ isVisible?: (currentUser: Document) => Promise<boolean>;
493
+ /**
494
+ * The default order
495
+ * @default asc
496
+ */
497
+ defaultOrder?: orderTypes;
498
+ /**
499
+ * Number of rows per page
500
+ * @default 10
501
+ */
502
+ defaultrowsPerPage?: number;
503
+ /**
504
+ * The parent that this model is belong to in the nav bar.
505
+ * @default 'Set up parent'
506
+ */
507
+ parent?: Parent;
508
+ /**
509
+ * Array of fields that are completely hidden from all pages
510
+ */
511
+ hiddenProperties?: string[];
512
+ /**
513
+ * Action options for overriding existing actions accessibility or adding custom actions
514
+ */
515
+ actions?: ActionOptions;
516
+ /**
517
+ * Filters options
518
+ */
519
+ filters?: IFilters;
520
+ /**
521
+ * Using before or after handlers of any crud operation
522
+ */
523
+ crudOperations?: ICrudOperations;
524
+ /**
525
+ * Translation object of the fields' names.
526
+ */
527
+ keysTranslations?: {
528
+ [key: string]: any;
529
+ };
530
+ /**
531
+ * Translation object of the actions' names.
532
+ */
533
+ actionsTranslations?: {
534
+ [key: string]: any;
535
+ };
536
+ /**
537
+ * Override some props of a field's schema structure
538
+ * Add a new virtual property
539
+ */
540
+ model?: {
541
+ [key: string]: IFieldValue;
542
+ } | IModel;
543
+ /**
544
+ * Override the populated object
545
+ */
546
+ populate?: IPopulate;
547
+ /**
548
+ * Disable the display of next and previous buttons in the show page
549
+ * @default false
550
+ */
551
+ disableNextPreviousButtonsInShowPage?: boolean;
552
+ /**
553
+ * Disable the display of next and previous buttons in the edit page
554
+ * @default false
555
+ */
556
+ disableNextPreviousButtonsInEditPage?: boolean;
557
+ /**
558
+ * The option to display the edit page instead of the show page
559
+ * @default false
560
+ */
561
+ displayEditPageInShowPage?: boolean;
562
+ /**
563
+ * Specify the path of image to be shown beside the name in the reference options
564
+ * @default undefined
565
+ */
566
+ imageOnReferencePath?: string;
567
+ /**
568
+ * The option to disable displaying the image beside the name in the reference options
569
+ * @default false
570
+ */
571
+ disableImageOnReference?: boolean;
572
+ /**
573
+ * An object for any extra data need to be sent with the resource file
574
+ * @default undefined
575
+ */
576
+ extras?: {
577
+ [key: string]: any;
578
+ };
579
+ };
580
+ /**
581
+ * Array of properties that should be appeared in the list action.
582
+ * @default 'The whole fields'
583
+ */
584
+ listProperties?: string[];
585
+ /**
586
+ * Arrays of properties that should be appeared in the show action.
587
+ * @default 'The whole fields'
588
+ */
589
+ showProperties?: string[];
590
+ /**
591
+ * Array of properties that should be appeared in the create/edit form.
592
+ * @default 'The whole fields'
593
+ */
594
+ formProperties?: string[];
595
+ /**
596
+ * Array of properties that should be appeared in the filter.
597
+ * @default 'The whole fields'
598
+ */
599
+ filterProperties?: string[];
600
+ /**
601
+ * Array of properties that should be appeared in the quick filters.
602
+ * @default 'Empty array'
603
+ */
604
+ quickFilterProperties?: string[];
605
+ }
606
+ export {};