identity-admin 1.25.16 → 1.25.17

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