adminforth 1.3.57-next.9 → 1.4.2

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 (74) hide show
  1. package/commands/cli.js +18 -0
  2. package/dist/basePlugin.d.ts +1 -1
  3. package/dist/basePlugin.d.ts.map +1 -1
  4. package/dist/dataConnectors/baseConnector.d.ts +2 -1
  5. package/dist/dataConnectors/baseConnector.d.ts.map +1 -1
  6. package/dist/dataConnectors/baseConnector.js +1 -1
  7. package/dist/dataConnectors/baseConnector.js.map +1 -1
  8. package/dist/dataConnectors/clickhouse.d.ts +2 -1
  9. package/dist/dataConnectors/clickhouse.d.ts.map +1 -1
  10. package/dist/dataConnectors/clickhouse.js +1 -1
  11. package/dist/dataConnectors/clickhouse.js.map +1 -1
  12. package/dist/dataConnectors/mongo.d.ts +2 -1
  13. package/dist/dataConnectors/mongo.d.ts.map +1 -1
  14. package/dist/dataConnectors/mongo.js +1 -1
  15. package/dist/dataConnectors/mongo.js.map +1 -1
  16. package/dist/dataConnectors/postgres.d.ts +2 -1
  17. package/dist/dataConnectors/postgres.d.ts.map +1 -1
  18. package/dist/dataConnectors/postgres.js +1 -1
  19. package/dist/dataConnectors/postgres.js.map +1 -1
  20. package/dist/dataConnectors/sqlite.d.ts +1 -1
  21. package/dist/dataConnectors/sqlite.d.ts.map +1 -1
  22. package/dist/dataConnectors/sqlite.js +1 -1
  23. package/dist/dataConnectors/sqlite.js.map +1 -1
  24. package/dist/index.d.ts +4 -2
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +5 -2
  27. package/dist/index.js.map +1 -1
  28. package/dist/modules/codeInjector.d.ts +1 -1
  29. package/dist/modules/codeInjector.d.ts.map +1 -1
  30. package/dist/modules/codeInjector.js +1 -1
  31. package/dist/modules/codeInjector.js.map +1 -1
  32. package/dist/modules/configValidator.d.ts +2 -1
  33. package/dist/modules/configValidator.d.ts.map +1 -1
  34. package/dist/modules/configValidator.js +1 -2
  35. package/dist/modules/configValidator.js.map +1 -1
  36. package/dist/modules/operationalResource.d.ts +1 -1
  37. package/dist/modules/operationalResource.d.ts.map +1 -1
  38. package/dist/modules/restApi.d.ts +2 -1
  39. package/dist/modules/restApi.d.ts.map +1 -1
  40. package/dist/modules/restApi.js +1 -1
  41. package/dist/modules/restApi.js.map +1 -1
  42. package/dist/servers/express.d.ts +1 -1
  43. package/dist/servers/express.d.ts.map +1 -1
  44. package/dist/servers/express.js +12 -1
  45. package/dist/servers/express.js.map +1 -1
  46. package/dist/spa/src/components/Dropdown.vue +0 -1
  47. package/dist/spa/src/components/Filters.vue +4 -4
  48. package/dist/spa/src/components/GroupsTable.vue +3 -1
  49. package/dist/spa/src/components/ResourceForm.vue +3 -0
  50. package/dist/spa/src/components/ThreeDotsMenu.vue +1 -1
  51. package/dist/spa/src/composables/useStores.ts +2 -3
  52. package/dist/spa/src/stores/core.ts +4 -4
  53. package/dist/spa/src/types/Back.ts +1181 -0
  54. package/dist/spa/src/types/Common.ts +702 -0
  55. package/dist/spa/src/types/Commons.ts +702 -0
  56. package/dist/spa/src/types/FrontAndBack.ts +698 -0
  57. package/dist/spa/src/views/ListView.vue +2 -0
  58. package/dist/types/Back.d.ts +1083 -0
  59. package/dist/types/Back.d.ts.map +1 -0
  60. package/dist/types/Back.js +86 -0
  61. package/dist/types/Back.js.map +1 -0
  62. package/dist/types/Common.d.ts +616 -0
  63. package/dist/types/Common.d.ts.map +1 -0
  64. package/dist/types/Common.js +65 -0
  65. package/dist/types/Common.js.map +1 -0
  66. package/dist/types/Commons.d.ts +616 -0
  67. package/dist/types/Commons.d.ts.map +1 -0
  68. package/dist/types/Commons.js +65 -0
  69. package/dist/types/Commons.js.map +1 -0
  70. package/dist/types/FrontAndBack.d.ts +613 -0
  71. package/dist/types/FrontAndBack.d.ts.map +1 -0
  72. package/dist/types/FrontAndBack.js +62 -0
  73. package/dist/types/FrontAndBack.js.map +1 -0
  74. package/package.json +9 -3
@@ -0,0 +1,1083 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import type { Express } from 'express';
3
+ import type { Writable } from 'stream';
4
+ import { ActionCheckSource, AdminForthFilterOperators, AdminForthSortDirections, AllowedActionsEnum, type AdminForthComponentDeclaration, type AdminForthResourceCommon, type AdminUser, type AllowedActionsResolved, type AdminForthBulkActionCommon, type AdminForthForeignResourceCommon, type AdminForthResourceColumnCommon } from './Common.js';
5
+ export interface ICodeInjector {
6
+ srcFoldersToSync: Object;
7
+ allComponentNames: Object;
8
+ getServeDir(): string;
9
+ }
10
+ export interface IConfigValidator {
11
+ validateConfig(): void;
12
+ postProcessAfterDiscover(resource: AdminForthResource): void;
13
+ }
14
+ export interface IAdminForthHttpResponse {
15
+ setHeader: (key: string, value: string) => void;
16
+ setStatus: (code: number, message: string) => void;
17
+ blobStream: () => Writable;
18
+ }
19
+ /**
20
+ * Implement this interface to create custom HTTP server adapter for AdminForth.
21
+ */
22
+ export interface IHttpServer {
23
+ /**
24
+ * Sets up HTTP server to serve AdminForth SPA.
25
+ * if hotReload is true, it should proxy all requests and headers to Vite dev server at `http://localhost:5173$\{req.url\}`
26
+ * otherwise it should serve AdminForth SPA from dist folder. See Express for example.
27
+ */
28
+ setupSpaServer(): void;
29
+ /**
30
+ * Method which should register endpoint in HTTP server.
31
+ *
32
+ * @param options : Object with method, path and handler properties.
33
+ */
34
+ endpoint(options: {
35
+ method: string;
36
+ noAuth?: boolean;
37
+ path: string;
38
+ handler: (body: any, adminUser: any, query: {
39
+ [key: string]: string;
40
+ }, headers: {
41
+ [key: string]: string;
42
+ }, cookies: {
43
+ [key: string]: string;
44
+ }, response: IAdminForthHttpResponse) => void;
45
+ }): void;
46
+ }
47
+ export interface IExpressHttpServer extends IHttpServer {
48
+ /**
49
+ * Call this method to serve AdminForth SPA from Express instance.
50
+ * @param app : Express instance
51
+ */
52
+ serve(app: Express): void;
53
+ /**
54
+ * Method (middleware) to wrap express endpoints with authorization check.
55
+ * Adds adminUser to request object if user is authorized. Drops request with 401 status if user is not authorized.
56
+ * @param callable : Function which will be called if user is authorized.
57
+ *
58
+ * Example:
59
+ *
60
+ * ```ts
61
+ * expressApp.get('/myApi', authorize((req, res) => \{
62
+ * console.log('User is authorized', req.adminUser);
63
+ * res.json(\{ message: 'Hello World' \});
64
+ * \}));
65
+ * ``
66
+ *
67
+ */
68
+ authorize(callable: Function): void;
69
+ }
70
+ export interface IAdminForthFilter {
71
+ field: string;
72
+ operator: AdminForthFilterOperators;
73
+ value: any;
74
+ }
75
+ export interface IAdminForthSort {
76
+ field: string;
77
+ direction: AdminForthSortDirections;
78
+ }
79
+ export interface IAdminForthDataSourceConnector {
80
+ /**
81
+ * Optional.
82
+ * You an redefine this function to define how one record should be fetched from database.
83
+ * You you will not redefine it, AdminForth will use {@link IAdminForthDataSourceConnector.getData} with limit 1 and offset 0 and
84
+ * filter by primary key.
85
+ */
86
+ getRecordByPrimaryKeyWithOriginalTypes(resource: AdminForthResource, recordId: string): Promise<any>;
87
+ /**
88
+ * Function should go over all columns of table defined in resource.table and try to guess
89
+ * data and constraints for each columns.
90
+ * Type should be saved to:
91
+ * - {@link AdminForthResourceColumn.type}
92
+ * Constraints:
93
+ * - {@link AdminForthResourceColumn.required}
94
+ * - {@link AdminForthResourceColumn.primaryKey}
95
+ * For string fields:
96
+ * - {@link AdminForthResourceColumn.maxLength}
97
+ * For numbers:
98
+ * - {@link AdminForthResourceColumn.min}
99
+ * - {@link AdminForthResourceColumn.max}
100
+ * - {@link AdminForthResourceColumn.minValue}, {@link AdminForthResourceColumn.maxValue}, {@link AdminForthResourceColumn.enum}, {@link AdminForthResourceColumn.foreignResource}, {@link AdminForthResourceColumn.sortable}, {@link AdminForthResourceColumn.backendOnly}, {@link AdminForthResourceColumn.masked}, {@link AdminForthResourceColumn.virtual}, {@link AdminForthResourceColumn.components}, {@link AdminForthResourceColumn.allowMinMaxQuery}, {@link AdminForthResourceColumn.editingNote}, {@link AdminForthResourceColumn.showIn}, {@link AdminForthResourceColumn.isUnique}, {@link AdminForthResourceColumn.validation})
101
+ * Also you can additionally save original column type to {@link AdminForthResourceColumn._underlineType}. This might be later used
102
+ * in {@link IAdminForthDataSourceConnector.getFieldValue} and {@link IAdminForthDataSourceConnector.setFieldValue} methods.
103
+ *
104
+ *
105
+ * @param resource
106
+ */
107
+ discoverFields(resource: AdminForthResource): Promise<{
108
+ [key: string]: AdminForthResourceColumn;
109
+ }>;
110
+ /**
111
+ * Used to transform record after fetching from database.
112
+ * According to AdminForth convention, if {@link AdminForthResourceColumn.type} is set to {@link AdminForthDataTypes.DATETIME} then it should be transformed to ISO string.
113
+ * @param field
114
+ * @param value
115
+ */
116
+ getFieldValue(field: AdminForthResourceColumn, value: any): any;
117
+ /**
118
+ * Used to transform record before saving to database. Should perform operation inverse to {@link IAdminForthDataSourceConnector.getFieldValue}
119
+ * @param field
120
+ * @param value
121
+ */
122
+ setFieldValue(field: AdminForthResourceColumn, value: any): any;
123
+ /**
124
+ * Used to fetch data from database.
125
+ * This method is reused both to list records and show one record (by passing limit 1 and offset 0) .
126
+ *
127
+ * Fields are returned from db "as is" then {@link AdminForthBaseConnector.getData} will transform each field using {@link IAdminForthDataSourceConnector.getFieldValue}
128
+ */
129
+ getDataWithOriginalTypes({ resource, limit, offset, sort, filters }: {
130
+ resource: AdminForthResource;
131
+ limit: number;
132
+ offset: number;
133
+ sort: IAdminForthSort[];
134
+ filters: IAdminForthFilter[];
135
+ }): Promise<Array<any>>;
136
+ /**
137
+ * Used to get count of records in database.
138
+ */
139
+ getCount({ resource, filters }: {
140
+ resource: AdminForthResource;
141
+ filters: IAdminForthFilter[];
142
+ }): Promise<number>;
143
+ /**
144
+ * Optional method which used to get min and max values for columns in resource.
145
+ * Called only for columns which have {@link AdminForthResourceColumn.allowMinMaxQuery} set to true.
146
+ *
147
+ * Internally should call {@link IAdminForthDataSourceConnector.getFieldValue} for both min and max values.
148
+ */
149
+ getMinMaxForColumnsWithOriginalTypes({ resource, columns }: {
150
+ resource: AdminForthResource;
151
+ columns: AdminForthResourceColumn[];
152
+ }): Promise<{
153
+ [key: string]: {
154
+ min: any;
155
+ max: any;
156
+ };
157
+ }>;
158
+ /**
159
+ * Used to create record in database.
160
+ */
161
+ createRecordOriginalValues({ resource, record }: {
162
+ resource: AdminForthResource;
163
+ record: any;
164
+ }): Promise<void>;
165
+ /**
166
+ * Update record in database. newValues might have not all fields in record, but only changed ones.
167
+ * recordId is value of field which is marked as {@link AdminForthResourceColumn.primaryKey}
168
+ */
169
+ updateRecordOriginalValues({ resource, recordId, newValues }: {
170
+ resource: AdminForthResource;
171
+ recordId: string;
172
+ newValues: any;
173
+ }): Promise<void>;
174
+ /**
175
+ * Used to delete record in database.
176
+ */
177
+ deleteRecord({ resource, recordId }: {
178
+ resource: AdminForthResource;
179
+ recordId: any;
180
+ }): Promise<boolean>;
181
+ }
182
+ /**
183
+ * Interface that exposes methods to interact with AdminForth in standard way
184
+ */
185
+ export interface IAdminForthDataSourceConnectorBase extends IAdminForthDataSourceConnector {
186
+ getPrimaryKey(resource: AdminForthResource): string;
187
+ getData({ resource, limit, offset, sort, filters }: {
188
+ resource: AdminForthResource;
189
+ limit: number;
190
+ offset: number;
191
+ sort: IAdminForthSort[];
192
+ filters: IAdminForthFilter[];
193
+ getTotals?: boolean;
194
+ }): Promise<{
195
+ data: Array<any>;
196
+ total: number;
197
+ }>;
198
+ getRecordByPrimaryKey(resource: AdminForthResource, recordId: string): Promise<any>;
199
+ createRecord({ resource, record, adminUser }: {
200
+ resource: AdminForthResource;
201
+ record: any;
202
+ adminUser: AdminUser;
203
+ }): Promise<{
204
+ ok: boolean;
205
+ error?: string;
206
+ createdRecord?: any;
207
+ }>;
208
+ updateRecord({ resource, recordId, newValues }: {
209
+ resource: AdminForthResource;
210
+ recordId: string;
211
+ newValues: any;
212
+ }): Promise<{
213
+ ok: boolean;
214
+ error?: string;
215
+ }>;
216
+ getMinMaxForColumns({ resource, columns }: {
217
+ resource: AdminForthResource;
218
+ columns: AdminForthResourceColumn[];
219
+ }): Promise<{
220
+ [key: string]: {
221
+ min: any;
222
+ max: any;
223
+ };
224
+ }>;
225
+ }
226
+ export interface IAdminForthDataSourceConnectorConstructor {
227
+ new ({ url }: {
228
+ url: string;
229
+ }): IAdminForthDataSourceConnectorBase;
230
+ }
231
+ export interface IAdminForthAuth {
232
+ verify(jwt: string, mustHaveType: string, decodeUser?: boolean): Promise<any>;
233
+ issueJWT(payload: Object, type: string, expiresIn?: string): string;
234
+ removeCustomCookie({ response, name }: {
235
+ response: any;
236
+ name: string;
237
+ }): void;
238
+ setAuthCookie({ expireInDays, response, username, pk, }: {
239
+ expireInDays?: number;
240
+ response: any;
241
+ username: string;
242
+ pk: string;
243
+ }): void;
244
+ removeAuthCookie(response: any): void;
245
+ }
246
+ export interface IAdminForth {
247
+ config: AdminForthConfig;
248
+ codeInjector: ICodeInjector;
249
+ express: IHttpServer;
250
+ activatedPlugins: Array<IAdminForthPlugin>;
251
+ baseUrlSlashed: string;
252
+ statuses: {
253
+ dbDiscover: 'running' | 'done';
254
+ };
255
+ connectors: {
256
+ [key: string]: IAdminForthDataSourceConnectorBase;
257
+ };
258
+ createResourceRecord(params: {
259
+ resource: AdminForthResource;
260
+ record: any;
261
+ adminUser: AdminUser;
262
+ }): Promise<{
263
+ error?: string;
264
+ createdRecord?: any;
265
+ }>;
266
+ updateResourceRecord(params: {
267
+ resource: AdminForthResource;
268
+ recordId: any;
269
+ record: any;
270
+ oldRecord: any;
271
+ adminUser: AdminUser;
272
+ }): Promise<{
273
+ error?: string;
274
+ }>;
275
+ deleteResourceRecord(params: {
276
+ resource: AdminForthResource;
277
+ recordId: string;
278
+ adminUser: AdminUser;
279
+ record: any;
280
+ }): Promise<{
281
+ error?: string;
282
+ }>;
283
+ auth: IAdminForthAuth;
284
+ /**
285
+ * Internal flag which indicates if AdminForth is running in hot reload mode.
286
+ */
287
+ runningHotReload: boolean;
288
+ /**
289
+ * Connects to databases defined in datasources and fetches described resource columns to find out data types and constraints.
290
+ * You must call this method as soon as possible after AdminForth class is instantiated.
291
+ */
292
+ discoverDatabases(): Promise<void>;
293
+ /**
294
+ * Bundles AdminForth SPA by injecting custom components into internal pre-made SPA source code. It generates internally dist which then will be
295
+ * served by AdminForth HTTP adapter.
296
+ * Bundle is generated in /tmp folder so if you have ramfs or tmpfs this operation will be faster.
297
+ *
298
+ * We recommend calling this method from dedicated script which will be run by CI/CD pipeline in build time. This ensures lowest downtime for your users.
299
+ * However for simple setup you can call it from your main script, and users will see some "AdminForth is bundling" message in the admin panel while app is bundling.
300
+ */
301
+ bundleNow({ hotReload, verbose }: {
302
+ hotReload: boolean;
303
+ verbose: boolean;
304
+ }): Promise<void>;
305
+ /**
306
+ * Resource to get access to operational resources for data api fetching and manipulation.
307
+ */
308
+ resource(resourceId: string): IOperationalResource;
309
+ /**
310
+ * This method will be automatically called from AdminForth HTTP adapter to serve AdminForth SPA.
311
+ */
312
+ setupEndpoints(server: IHttpServer): void;
313
+ }
314
+ export interface IAdminForthPlugin {
315
+ adminforth: IAdminForth;
316
+ pluginDir: string;
317
+ customFolderName: string;
318
+ pluginInstanceId: string;
319
+ customFolderPath: string;
320
+ pluginOptions: any;
321
+ resourceConfig: AdminForthResource;
322
+ className: string;
323
+ /**
324
+ * Before activating all plugins are sorted by this number and then activated in order.
325
+ * If you want to make sure that your plugin is activated after some other plugin, set this number to higher value. (default is 0)
326
+ */
327
+ activationOrder: number;
328
+ /**
329
+ * AdminForth plugins concept is based on modification of full AdminForth configuration
330
+ * to add some custom functionality. For example plugin might simply add custom field to resource by reusing
331
+ * {@link AdminForthResourceColumn.components} object, then add some hook which will modify record before getting or saving it to database.
332
+ *
333
+ * So this method is core of AdminForth plugins. It allows to modify full resource configuration.
334
+ * @param adminforth Instance of IAdminForth
335
+ * @param resourceConfig Resource configuration object which will be modified by plugin
336
+ */
337
+ modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource): void;
338
+ componentPath(componentFile: string): string;
339
+ /**
340
+ * If plugin should support multiple installations per one resource, this function that should return unique string for each instance of plugin.
341
+ * For example if plugin is installed for one column and this column defined as
342
+ * `targetColumn` in plugin options, then this method should return `${pluginOptions.targetColumn}`.
343
+ *
344
+ * If plugin should support only one installation per resource, option can return 'single'
345
+ * @param pluginOptions - options of plugin
346
+ */
347
+ instanceUniqueRepresentation(pluginOptions: any): string;
348
+ /**
349
+ * Optional method which will be called after AdminForth discovers all resources and their columns.
350
+ * Can be used to validate types of columns, check if some columns are missing, etc.
351
+ */
352
+ validateConfigAfterDiscover?(adminforth: IAdminForth, resourceConfig: AdminForthResource): void;
353
+ /**
354
+ * Here you can register custom endpoints for your plugin.
355
+ *
356
+ * @param server
357
+ */
358
+ setupEndpoints(server: IHttpServer): void;
359
+ }
360
+ export declare enum AdminForthMenuTypes {
361
+ /**
362
+ * HEADING is just a label in the menu.
363
+ * Respect `label` and `icon` property in {@link AdminForthConfigMenuItem}
364
+ */
365
+ heading = "heading",
366
+ /**
367
+ * GROUP is a group of menu items.
368
+ * Respects `label`, `icon` and `children` properties in {@link AdminForthConfigMenuItem}
369
+ * use @AdminForthMenuTypes.open to set if group is open by default
370
+ */
371
+ group = "group",
372
+ /**
373
+ * RESOURCE is a link to a resource.
374
+ * Respects `label`, `icon`, `resourceId`, `homepage`, `isStaticRoute` properties in {@link AdminForthConfigMenuItem}
375
+ */
376
+ resource = "resource",
377
+ /**
378
+ * PAGE is a link to a custom page.
379
+ * Respects `label`, `icon`, `path`, `component`, `homepage`, `isStaticRoute`, properties in {@link AdminForthConfigMenuItem}
380
+ *
381
+ * Example:
382
+ *
383
+ * ```ts
384
+ * \{
385
+ * type: AdminForthMenuTypes.PAGE,
386
+ * label: 'Custom Page',
387
+ * icon: 'home',
388
+ * path: '/dash',
389
+ * component: '@@/Dashboard.vue',
390
+ * homepage: true,
391
+ * \}
392
+ * ```
393
+ *
394
+ */
395
+ page = "page",
396
+ /**
397
+ * GAP ads some space between menu items.
398
+ */
399
+ gap = "gap",
400
+ /**
401
+ * DIVIDER is a divider between menu items.
402
+ */
403
+ divider = "divider"
404
+ }
405
+ /**
406
+ * Menu item which displayed in the left sidebar of the admin panel.
407
+ */
408
+ export type AdminForthConfigMenuItem = {
409
+ type?: AdminForthMenuTypes | keyof typeof AdminForthMenuTypes;
410
+ /**
411
+ * Label for menu item which will be displayed in the admin panel.
412
+ */
413
+ label?: string;
414
+ /**
415
+ * Icon for menu item which will be displayed in the admin panel.
416
+ * Supports iconify icons in format `<icon set name>:<icon name>`
417
+ * Browse available icons here: https://icon-sets.iconify.design/
418
+ *
419
+ * Example:
420
+ *
421
+ * ```ts
422
+ * icon: 'flowbite:brain-solid',
423
+ * ```
424
+ *
425
+ */
426
+ icon?: string;
427
+ /**
428
+ * Path to custom component which will be displayed in the admin panel.
429
+ *
430
+ */
431
+ path?: string;
432
+ /**
433
+ * Component to be used for this menu item. Component should be placed in custom folder and referenced with `@@/` prefix.
434
+ * Supported for AdminForthMenuTypes.PAGE only!
435
+ * Example:
436
+ *
437
+ * ```ts
438
+ * component: '@@/Dashboard.vue',
439
+ * ```
440
+ *
441
+ */
442
+ component?: string;
443
+ /**
444
+ * Resource ID which will be used to fetch data from.
445
+ * Supported for AdminForthMenuTypes.RESOURCE only!
446
+ *
447
+ */
448
+ resourceId?: string;
449
+ /**
450
+ * If true, group will be open by default after user login to the admin panel.
451
+ * Also will be used to redirect from root path.
452
+ */
453
+ homepage?: boolean;
454
+ /**
455
+ * Where Group is open by default
456
+ * Supported for AdminForthMenuTypes.GROUP only!
457
+ *
458
+ */
459
+ open?: boolean;
460
+ /**
461
+ * Children menu items which will be displayed in this group.
462
+ * Supported for AdminForthMenuTypes.GROUP only!
463
+ */
464
+ children?: Array<AdminForthConfigMenuItem>;
465
+ /**
466
+ * By default all pages are imported dynamically with lazy import().
467
+ * If you wish to import page statically, set this option to true.
468
+ * Homepage will be imported statically by default. but you can override it with this option.
469
+ */
470
+ isStaticRoute?: boolean;
471
+ meta?: {
472
+ title?: string;
473
+ };
474
+ /**
475
+ * Optional callback which will be called before rendering the menu for each item.
476
+ * You can use it to hide menu items depending on some user
477
+ */
478
+ visible?: (user: AdminUser) => boolean;
479
+ /**
480
+ * Optional callback which will be called before rendering the menu for each item.
481
+ * Result of callback if not null will be used as a small badge near the menu item.
482
+ */
483
+ badge?: string | ((user: AdminUser) => Promise<string>);
484
+ };
485
+ /**
486
+ * Modify query to change how data is fetched from database.
487
+ * Return ok: false and error: string to stop execution and show error message to user. Return ok: true to continue execution.
488
+ */
489
+ export type BeforeDataSourceRequestFunction = (params: {
490
+ resource: AdminForthResource;
491
+ adminUser: AdminUser;
492
+ query: any;
493
+ extra: {
494
+ body: any;
495
+ query: Record<string, string>;
496
+ headers: Record<string, string>;
497
+ cookies: Record<string, string>;
498
+ };
499
+ }) => Promise<{
500
+ ok: boolean;
501
+ error?: string;
502
+ }>;
503
+ /**
504
+ * Modify response to change how data is returned after fetching from database.
505
+ * Return ok: false and error: string to stop execution and show error message to user. Return ok: true to continue execution.
506
+ */
507
+ export type AfterDataSourceResponseFunction = (params: {
508
+ resource: AdminForthResource;
509
+ adminUser: AdminUser;
510
+ response: any;
511
+ extra: {
512
+ body: any;
513
+ query: Record<string, string>;
514
+ headers: Record<string, string>;
515
+ cookies: {
516
+ key: string;
517
+ value: string;
518
+ }[];
519
+ };
520
+ }) => Promise<{
521
+ ok: boolean;
522
+ error?: string;
523
+ }>;
524
+ /**
525
+ * Modify record to change how data is saved to database.
526
+ * Return ok: false and error: string to stop execution and show error message to user. Return ok: true to continue execution.
527
+ */
528
+ export type BeforeSaveFunction = (params: {
529
+ resource: AdminForthResource;
530
+ recordId: any;
531
+ adminUser: AdminUser;
532
+ record: any;
533
+ oldRecord?: any;
534
+ }) => Promise<{
535
+ ok: boolean;
536
+ error?: string;
537
+ }>;
538
+ /**
539
+ * Modify record to change how data is saved to database.
540
+ * Return ok: false and error: string to stop execution and show error message to user. Return ok: true to continue execution.
541
+ */
542
+ export type AfterSaveFunction = (params: {
543
+ resource: AdminForthResource;
544
+ recordId: any;
545
+ adminUser: AdminUser;
546
+ record: any;
547
+ oldRecord?: any;
548
+ }) => Promise<{
549
+ ok: boolean;
550
+ error?: string;
551
+ }>;
552
+ /**
553
+ * Allow to get user data before login confirmation, will triger when user try to login.
554
+ */
555
+ export type BeforeLoginConfirmationFunction = (params?: {
556
+ adminUser: AdminUser;
557
+ response: IAdminForthHttpResponse;
558
+ }) => Promise<{
559
+ ok: boolean;
560
+ error?: string;
561
+ body: {
562
+ redirectTo?: string;
563
+ allowedLogin?: boolean;
564
+ };
565
+ }>;
566
+ /**
567
+ * Data source describes database connection which will be used to fetch data for resources.
568
+ * Each resource should use one data source.
569
+ */
570
+ export type AdminForthDataSource = {
571
+ /**
572
+ * ID of datasource which you will use in resources to specify from which database to fetch data from
573
+ */
574
+ id: string;
575
+ /**
576
+ * URL to database. Examples:
577
+ *
578
+ * - MongoDB: `mongodb://<user>:<password>@<host>:<port>/<database>`
579
+ * - PostgreSQL: `postgresql://<user>:<password>@<host>:<port>/<database>`
580
+ * - SQLite: `sqlite://<path>`
581
+ */
582
+ url: string;
583
+ };
584
+ /**
585
+ * Main configuration object for AdminForth
586
+ */
587
+ export interface AdminForthConfig {
588
+ /**
589
+ * Authorization module configuration
590
+ */
591
+ auth?: {
592
+ /**
593
+ * Resource ID for resource which stores user table.
594
+ * Resource is a table in database where users will be stored and fetched from. Resources and their ids are defined in resources section of the config.
595
+ * In other words this setting is a reference to a table in database where users will be fetched from on login.
596
+ */
597
+ usersResourceId?: string;
598
+ /**
599
+ * Legacy field left for backward compatibility. Use usersResourceId instead.
600
+ */
601
+ resourceId?: string;
602
+ /**
603
+ * Field name (column name) in user resource which will be used as username for searching user in database during login.
604
+ * Can be e.g. 'email' or 'username'
605
+ */
606
+ usernameField: string;
607
+ /**
608
+ * Field name (column name) in user resource which will be used to get hash of password.
609
+ * Can be e.g. 'passwordHash'
610
+ */
611
+ passwordHashField: string;
612
+ /**
613
+ * File path to custom background image for login page
614
+ * Example:
615
+ * Place file `login-background.jpg` to `./custom` folder and set this option:
616
+ *
617
+ * ```ts
618
+ * loginBackgroundImage: '@@/login-background.jpg',
619
+ * ```
620
+ */
621
+ loginBackgroundImage?: string;
622
+ /**
623
+ * Position of background image on login page
624
+ * 'over' - image will be displayed over full login page under login form
625
+ * '1/2' - image will be displayed on left 1/2 of login page
626
+ *
627
+ * Default: '1/2'
628
+ */
629
+ loginBackgroundPosition?: 'over' | '1/2' | '1/3' | '2/3' | '3/4' | '2/5' | '3/5';
630
+ /**
631
+ * Function or functions which will be called before user try to login.
632
+ * Each function will resive User object as an argument
633
+ */
634
+ beforeLoginConfirmation?: BeforeLoginConfirmationFunction | Array<BeforeLoginConfirmationFunction>;
635
+ /**
636
+ * Optionally if your users table has a field(column) with full name, you can set it here.
637
+ * This field will be used to display user name in the top right corner of the admin panel.
638
+ */
639
+ userFullNameField?: string;
640
+ /**
641
+ * Pair of login and pass substitution for demo mode. Split by ':'
642
+ * ! This option is for demo purposes only, never use it for your projects
643
+ */
644
+ demoCredentials?: string;
645
+ /**
646
+ * Any prompt to show users on login. Supports HTML.
647
+ */
648
+ loginPromptHTML?: string;
649
+ /**
650
+ * Remember me days for "Remember Me" checkbox on login page.
651
+ * If not set or set to null/0/undefined, "Remember Me" checkbox will not be displayed.
652
+ * If rememberMeDays is set, then users who check "Remember Me" will be staying logged in for this amount of days.
653
+ */
654
+ rememberMeDays?: number;
655
+ };
656
+ /**
657
+ * Array of resources which will be displayed in the admin panel.
658
+ * Resource represents one table or collection in database.
659
+ * Each resource has its own configuration.
660
+ */
661
+ resources: Array<AdminForthResource>;
662
+ /**
663
+ * Array of left sidebar menu items which will be displayed in the admin panel.
664
+ * Menu items can be links to resources or custom pages.
665
+ * Menu items can be grouped.
666
+ *
667
+ */
668
+ menu: Array<AdminForthConfigMenuItem>;
669
+ /**
670
+ * If you want use custom DataSource which is not supported by AdminForth yet, you can define it's class here
671
+ *
672
+ */
673
+ databaseConnectors?: {
674
+ [key: string]: IAdminForthDataSourceConnectorConstructor;
675
+ };
676
+ /**
677
+ * List of data sources which will be used to fetch data for resources.
678
+ * Datasource is one database connection
679
+ *
680
+ */
681
+ dataSources: Array<AdminForthDataSource>;
682
+ /**
683
+ * Settings which allow you to customize AdminForth
684
+ *
685
+ */
686
+ customization?: {
687
+ /**
688
+ * Your app name
689
+ */
690
+ brandName?: string;
691
+ /**
692
+ * Slug which will be used on tech side e.g. to store cookies separately.
693
+ * Created automatically from brandName if not set.
694
+ */
695
+ _brandNameSlug?: string;
696
+ /**
697
+ * Whether to show brand name in sidebar
698
+ * default is true
699
+ */
700
+ showBrandNameInSidebar?: boolean;
701
+ /**
702
+ * Path to your app logo
703
+ *
704
+ * Example:
705
+ * Place file `logo.svg` to `./custom` folder and set this option:
706
+ *
707
+ * ```ts
708
+ * brandLogo: '@@/logo.svg',
709
+ * ```
710
+ *
711
+ */
712
+ brandLogo?: string;
713
+ /**
714
+ * Path to your app favicon
715
+ *
716
+ * Example:
717
+ * Place file `favicon.png` to `./custom` folder and set this option:
718
+ *
719
+ * ```ts
720
+ * favicon: '@@/favicon.png',
721
+ * ```
722
+ */
723
+ favicon?: string;
724
+ /**
725
+ * DayJS format string for all dates in the app.
726
+ * Defaulted to 'MMM D, YYYY'
727
+ */
728
+ datesFormat?: string;
729
+ /**
730
+ * DayJS format string for all datetimes in the app.
731
+ * Defaulted to 'HH:mm:ss'
732
+ */
733
+ timeFormat?: string;
734
+ /**
735
+ * HTML title tag value, defaults to brandName
736
+ */
737
+ title?: string;
738
+ /**
739
+ * Placeholder for empty fields in lists and show views, by default empty string ''
740
+ */
741
+ emptyFieldPlaceholder?: {
742
+ show?: string;
743
+ list?: string;
744
+ } | string;
745
+ /**
746
+ * Relative or absolute path to custom components directory
747
+ * By default equals `./custom`.
748
+ *
749
+ * Custom .vue files, images, and any other assets placed in this directory can be accessed in AdminForth components and configs with `@@/`.
750
+ *
751
+ * For example if file path is `./custom/comp/my.vue`, you can use it in AdminForth config like this:
752
+ *
753
+ * ```ts
754
+ * components: {
755
+ * show: '@@/comp/my.vue',
756
+ * }
757
+ * ```
758
+ *
759
+ */
760
+ customComponentsDir?: string;
761
+ /**
762
+ * Path to custom .ts file which allows to inject custom Vue uses in SPA or add custom imports.
763
+ *
764
+ * Example: Create file: `./custom/vue-uses.ts` with next content:
765
+ *
766
+ * ```ts
767
+ * import HighchartsVue from 'highcharts-vue';
768
+ * // import '@@/custom.scss'; // here is how you can import custom styles
769
+ *
770
+ * export default function (app) {
771
+ * app.use(HighchartsVue);
772
+ * }
773
+ * ```
774
+ *
775
+ * Install HighCharts into custom folder:
776
+ *
777
+ * ```bashcreating rec
778
+ * cd custom
779
+ * npm init -y
780
+ * npm install highcharts highcharts-vue
781
+ * ```
782
+ *
783
+ * And specify vueUsesFile in AdminForth config:
784
+ *
785
+ * ```ts
786
+ * vueUsesFile: '@@/vue-uses.ts',
787
+ * ```
788
+ *
789
+ */
790
+ vueUsesFile?: string;
791
+ /**
792
+ * Object to redefine default styles for AdminForth components. Use this file as reference for all possible adjustments https://github.com/devforth/adminforth/blob/main/adminforth/modules/styles.ts
793
+ */
794
+ styles?: Object;
795
+ /**
796
+ * Description of custom pages which will let register custom pages for custom routes in AdminForth.
797
+ */
798
+ customPages?: Array<{
799
+ path: string;
800
+ component: AdminForthComponentDeclaration;
801
+ }>;
802
+ /**
803
+ * Function to return custom badge in side bar for users. Can return text or html
804
+ * If function is not passed or returns null, badge will not be shown.
805
+ * Execution is done on admin app load.
806
+ */
807
+ announcementBadge?: (user: AdminUser) => {
808
+ text?: string;
809
+ html?: string;
810
+ closable?: boolean;
811
+ title?: string;
812
+ } | null;
813
+ /**
814
+ * Custom panel components or array of components which will be displayed in the login form
815
+ * right after the inputs. Use it to add custom authorization methods like social login or other custom fields e.g. 'reset'
816
+ * password link.
817
+ */
818
+ loginPageInjections?: {
819
+ underInputs?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
820
+ };
821
+ /**
822
+ * Custom panel components or array of components which will be displayed in different parts of the admin panel.
823
+ */
824
+ globalInjections?: {
825
+ userMenu?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
826
+ header?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
827
+ sidebar?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
828
+ };
829
+ };
830
+ /**
831
+ * If you want to Serve AdminForth from a subdirectory, e.g. on example.com/backoffice, you can specify it like:
832
+ *
833
+ * ```ts
834
+ * baseUrl: '/backoffice',
835
+ * ```
836
+ *
837
+ */
838
+ baseUrl?: string;
839
+ /**
840
+ * Whether to show delete confirmation dialog before deleting record.
841
+ * By default it is true.
842
+ */
843
+ deleteConfirmation?: boolean;
844
+ }
845
+ export type FDataFilter = (field: string, value: any) => IAdminForthFilter;
846
+ export declare class Filters {
847
+ static EQ(field: string, value: any): IAdminForthFilter;
848
+ static NEQ(field: string, value: any): IAdminForthFilter;
849
+ static GT(field: string, value: any): IAdminForthFilter;
850
+ static GTE(field: string, value: any): IAdminForthFilter;
851
+ static LT(field: string, value: any): IAdminForthFilter;
852
+ static LTE(field: string, value: any): IAdminForthFilter;
853
+ static IN(field: string, value: any): IAdminForthFilter;
854
+ static NOT_IN(field: string, value: any): IAdminForthFilter;
855
+ static LIKE(field: string, value: any): IAdminForthFilter;
856
+ }
857
+ export type FDataSort = (field: string, direction: AdminForthSortDirections) => IAdminForthSort;
858
+ export declare class Sorts {
859
+ static ASC(field: string): IAdminForthSort;
860
+ static DESC(field: string): IAdminForthSort;
861
+ }
862
+ export interface IOperationalResource {
863
+ get: (filter: IAdminForthFilter | IAdminForthFilter[]) => Promise<any | null>;
864
+ list: (filter: IAdminForthFilter | IAdminForthFilter[], limit?: number, offset?: number, sort?: IAdminForthSort | IAdminForthSort[]) => Promise<any[]>;
865
+ count: (filter: IAdminForthFilter | IAdminForthFilter[] | undefined) => Promise<number>;
866
+ create: (record: any) => Promise<{
867
+ ok: boolean;
868
+ createdRecord: any;
869
+ error?: string;
870
+ }>;
871
+ update: (primaryKey: any, record: any) => Promise<any>;
872
+ delete: (primaryKey: any) => Promise<boolean>;
873
+ }
874
+ /**
875
+ * Defines whether user has access to an action, can statically be Boolean
876
+ * or function which returns Boolean or string with error message
877
+ *
878
+ */
879
+ export type AllowedActionValue = boolean | (({ adminUser, resource, meta, source }: {
880
+ adminUser: AdminUser;
881
+ resource: AdminForthResource;
882
+ /**
883
+ * Meta object which will pass request information just in case
884
+ */
885
+ meta: any;
886
+ /**
887
+ * Source of the check
888
+ */
889
+ source: ActionCheckSource;
890
+ }) => Promise<boolean | string>);
891
+ /**
892
+ * Object which describes allowed actions for user.
893
+ */
894
+ export type AllowedActions = {
895
+ [key in AllowedActionsEnum]?: AllowedActionValue;
896
+ } & {
897
+ all?: AllowedActionValue;
898
+ };
899
+ type ResourceOptions = Omit<AdminForthResourceCommon['options'], 'allowedActions' | 'bulkActions'> & {
900
+ /**
901
+ * Array of bulk actions which will be displayed in the list view.
902
+ * Bulk actions allow user to perform actions on multiple records at once.
903
+ *
904
+ */
905
+ bulkActions?: Array<AdminForthBulkAction>;
906
+ /**
907
+ * Object which describes allowed actions for user.
908
+ */
909
+ allowedActions?: AllowedActions;
910
+ };
911
+ /**
912
+ * Resource describes one table or collection in database.
913
+ * AdminForth generates set of pages for 'list', 'show', 'edit', 'create', 'filter' operations for each resource.
914
+ */
915
+ export interface AdminForthResource extends Omit<AdminForthResourceCommon, 'options'> {
916
+ /**
917
+ * Array of plugins which will be used to modify resource configuration.
918
+ *
919
+ */
920
+ plugins?: Array<IAdminForthPlugin>;
921
+ /**
922
+ * Hooks allow you to change the data on different stages of resource lifecycle.
923
+ * Hooks are functions which will be called on backend side (only backend side).
924
+ */
925
+ hooks?: {
926
+ show?: {
927
+ /**
928
+ * Typical use-cases:
929
+ * - request additional data from database before returning to frontend for soft-join
930
+ */
931
+ beforeDatasourceRequest?: BeforeDataSourceRequestFunction | Array<BeforeDataSourceRequestFunction>;
932
+ /**
933
+ * Typical use-cases:
934
+ * - Transform value for some field for record returned from database before returning to frontend (minimize, sanitize, etc)
935
+ * - If some-why you can't use `backendOnly` you can cleanup sensitive fields here
936
+ * - Attach additional data to record before returning to frontend
937
+ */
938
+ afterDatasourceResponse?: AfterDataSourceResponseFunction | Array<AfterDataSourceResponseFunction>;
939
+ };
940
+ list?: {
941
+ /**
942
+ * Typical use-cases:
943
+ * - add additional filters in addition to what user selected before fetching data from database.
944
+ * - same as hooks.show.beforeDatasourceRequest
945
+ */
946
+ beforeDatasourceRequest?: BeforeDataSourceRequestFunction | Array<BeforeDataSourceRequestFunction>;
947
+ /**
948
+ * Typical use-cases:
949
+ * - Same as hooks.show.afterDatasourceResponse but applied for all records returned from database for
950
+ * showing in list view, e.g. add new field to each record in list view
951
+ */
952
+ afterDatasourceResponse?: AfterDataSourceResponseFunction | Array<AfterDataSourceResponseFunction>;
953
+ };
954
+ create?: {
955
+ /**
956
+ * Typical use-cases:
957
+ * - Validate record before saving to database and interrupt execution if validation failed (`allowedActions.create` should be preferred in most cases)
958
+ * - fill-in adminUser as creator of record
959
+ * - Attach additional data to record before saving to database (mostly fillOnCreate should be used instead)
960
+ */
961
+ beforeSave?: BeforeSaveFunction | Array<BeforeSaveFunction>;
962
+ /**
963
+ * Typical use-cases:
964
+ * - Initiate some trigger after record saved to database (e.g sync to another datasource)
965
+ */
966
+ afterSave?: AfterSaveFunction | Array<AfterSaveFunction>;
967
+ };
968
+ edit?: {
969
+ /**
970
+ * Typical use-cases:
971
+ * - Same as hooks.create.beforeSave but for edit page
972
+ */
973
+ beforeSave?: BeforeSaveFunction | Array<BeforeSaveFunction>;
974
+ /**
975
+ * Typical use-cases:
976
+ * - Same as hooks.create.afterSave but for edit page
977
+ */
978
+ afterSave?: AfterSaveFunction | Array<AfterSaveFunction>;
979
+ };
980
+ delete?: {
981
+ /**
982
+ * Typical use-cases:
983
+ * - Validate that record can be deleted and interrupt execution if validation failed (`allowedActions.delete` should be preferred in most cases)
984
+ */
985
+ beforeSave?: BeforeSaveFunction | Array<BeforeSaveFunction>;
986
+ /**
987
+ * Typical use-cases:
988
+ * - Initiate some trigger after record deleted from database (e.g sync to another datasource)
989
+ */
990
+ afterSave?: BeforeSaveFunction | Array<BeforeSaveFunction>;
991
+ };
992
+ };
993
+ options?: ResourceOptions;
994
+ columns: Array<AdminForthResourceColumn>;
995
+ dataSourceColumns?: Array<AdminForthResourceColumn>;
996
+ }
997
+ export interface AdminForthBulkAction extends AdminForthBulkActionCommon {
998
+ /**
999
+ * Callback which will be called on backend when user clicks on action button.
1000
+ * It should return Promise which will be resolved when action is done.
1001
+ */
1002
+ action: ({ resource, selectedIds, adminUser }: {
1003
+ resource: AdminForthResource;
1004
+ selectedIds: Array<any>;
1005
+ adminUser: AdminUser;
1006
+ }) => Promise<{
1007
+ ok: boolean;
1008
+ error?: string;
1009
+ successMessage?: string;
1010
+ }>;
1011
+ /**
1012
+ * Allowed callback called to check whether action is allowed for user.
1013
+ * 1. It called first time when user goes to list view. If callback returns false, action button will be hidden on list view.
1014
+ * 2. This same callback called second time when user clicks an action button. If callback returns false, action will not be executed.
1015
+ * In second time selectedIds will be passed to callback (because checkbox for items are selected), so you can use this to make additional
1016
+ * checks ( for example to check if user has permission for certain records ).
1017
+ *
1018
+ * Example:
1019
+ *
1020
+ * ```ts
1021
+ * allowed: async ({ resource, adminUser, selectedIds }) => {
1022
+ * if (adminUser.dbUser.role !== 'superadmin') {
1023
+ * return false;
1024
+ * }
1025
+ * return true;
1026
+ * }
1027
+ * ```
1028
+ *
1029
+ */
1030
+ allowed?: ({ resource, adminUser, selectedIds, allowedActions }: {
1031
+ /**
1032
+ * recordIds will be passed only once user tries to perform bulk action by clicking on button
1033
+ */
1034
+ selectedIds?: Array<any>;
1035
+ resource: AdminForthResource;
1036
+ /**
1037
+ * Admin user object
1038
+ */
1039
+ adminUser: AdminUser;
1040
+ /**
1041
+ * Allowed standard actions for current user resolved by calling allowedActions callbacks if they are passed.
1042
+ * You can use this variable to rely on standard actions permissions. E.g. if you have custom actions "Mark as read", you
1043
+ * might want to allow it only for users who have "edit" action allowed:
1044
+ *
1045
+ * Example:
1046
+ *
1047
+ * ```ts
1048
+ *
1049
+ * options: \{
1050
+ * bulkActions: [
1051
+ * \{
1052
+ * label: 'Mark as read',
1053
+ * action: async (\{ resource, recordIds \}) => \{
1054
+ * await markAsRead(recordIds);
1055
+ * \},
1056
+ * allowed: (\{ allowedActions \}) => allowedActions.edit,
1057
+ * \}
1058
+ * ],
1059
+ * allowedActions: \{
1060
+ * edit: (\{ resource, adminUser, recordIds \}) => \{
1061
+ * return adminUser.dbUser.role === 'superadmin';
1062
+ * \}
1063
+ * \}
1064
+ * \}
1065
+ * ```
1066
+ *
1067
+ */
1068
+ allowedActions: AllowedActionsResolved;
1069
+ }) => Promise<boolean>;
1070
+ }
1071
+ export interface AdminForthForeignResource extends AdminForthForeignResourceCommon {
1072
+ hooks?: {
1073
+ dropdownList?: {
1074
+ beforeDatasourceRequest?: BeforeDataSourceRequestFunction | Array<BeforeDataSourceRequestFunction>;
1075
+ afterDatasourceResponse?: AfterDataSourceResponseFunction | Array<AfterDataSourceResponseFunction>;
1076
+ };
1077
+ };
1078
+ }
1079
+ export interface AdminForthResourceColumn extends AdminForthResourceColumnCommon {
1080
+ foreignResource?: AdminForthForeignResource;
1081
+ }
1082
+ export {};
1083
+ //# sourceMappingURL=Back.d.ts.map