identity-admin 1.25.12 → 1.25.13

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