adminforth 1.4.3-next.8 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/dist/basePlugin.d.ts.map +1 -1
  2. package/dist/basePlugin.js +2 -3
  3. package/dist/basePlugin.js.map +1 -1
  4. package/dist/dataConnectors/postgres.d.ts.map +1 -1
  5. package/dist/dataConnectors/postgres.js +29 -9
  6. package/dist/dataConnectors/postgres.js.map +1 -1
  7. package/dist/dataConnectors/sqlite.d.ts.map +1 -1
  8. package/dist/dataConnectors/sqlite.js +12 -5
  9. package/dist/dataConnectors/sqlite.js.map +1 -1
  10. package/dist/index.d.ts +4 -3
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +18 -5
  13. package/dist/index.js.map +1 -1
  14. package/dist/modules/codeInjector.d.ts +4 -2
  15. package/dist/modules/codeInjector.d.ts.map +1 -1
  16. package/dist/modules/codeInjector.js +98 -79
  17. package/dist/modules/codeInjector.js.map +1 -1
  18. package/dist/modules/configValidator.d.ts.map +1 -1
  19. package/dist/modules/configValidator.js +5 -4
  20. package/dist/modules/configValidator.js.map +1 -1
  21. package/dist/modules/operationalResource.d.ts.map +1 -1
  22. package/dist/modules/operationalResource.js.map +1 -1
  23. package/dist/modules/restApi.d.ts +8 -3
  24. package/dist/modules/restApi.d.ts.map +1 -1
  25. package/dist/modules/restApi.js +112 -39
  26. package/dist/modules/restApi.js.map +1 -1
  27. package/dist/modules/socketBroker.d.ts +16 -0
  28. package/dist/modules/socketBroker.d.ts.map +1 -0
  29. package/dist/modules/socketBroker.js +99 -0
  30. package/dist/modules/socketBroker.js.map +1 -0
  31. package/dist/modules/utils.d.ts +2 -1
  32. package/dist/modules/utils.d.ts.map +1 -1
  33. package/dist/modules/utils.js +5 -2
  34. package/dist/modules/utils.js.map +1 -1
  35. package/dist/servers/common.d.ts +21 -0
  36. package/dist/servers/common.d.ts.map +1 -0
  37. package/dist/servers/common.js +13 -0
  38. package/dist/servers/common.js.map +1 -0
  39. package/dist/servers/express.d.ts +5 -0
  40. package/dist/servers/express.d.ts.map +1 -1
  41. package/dist/servers/express.js +54 -7
  42. package/dist/servers/express.js.map +1 -1
  43. package/dist/spa/package-lock.json +59 -0
  44. package/dist/spa/package.json +1 -0
  45. package/dist/spa/src/App.vue +58 -36
  46. package/dist/spa/src/afcl/Button.vue +8 -1
  47. package/dist/spa/src/afcl/Input.vue +41 -0
  48. package/dist/spa/src/afcl/LinkButton.vue +23 -0
  49. package/dist/spa/src/afcl/Select.vue +8 -7
  50. package/dist/spa/src/afcl/index.ts +3 -0
  51. package/dist/spa/src/components/Filters.vue +0 -1
  52. package/dist/spa/src/components/GroupsTable.vue +4 -4
  53. package/dist/spa/src/components/ResourceListTable.vue +21 -21
  54. package/dist/spa/src/components/ValueRenderer.vue +3 -1
  55. package/dist/spa/src/composables/useStores.ts +4 -1
  56. package/dist/spa/src/renderers/CompactField.vue +4 -4
  57. package/dist/spa/src/renderers/CompactUUID.vue +4 -4
  58. package/dist/spa/src/renderers/CountryFlag.vue +3 -3
  59. package/dist/spa/src/renderers/HumanNumber.vue +5 -4
  60. package/dist/spa/src/renderers/RelativeTime.vue +5 -4
  61. package/dist/spa/src/router/index.ts +2 -0
  62. package/dist/spa/src/stores/core.ts +39 -6
  63. package/dist/spa/src/types/Back.ts +102 -9
  64. package/dist/spa/src/types/Common.ts +6 -1
  65. package/dist/spa/src/types/FrontendAPI.ts +7 -0
  66. package/dist/spa/src/views/EditView.vue +1 -0
  67. package/dist/spa/src/views/ListView.vue +2 -2
  68. package/dist/spa/src/views/LoginView.vue +7 -7
  69. package/dist/spa/src/views/PageNotFound.vue +20 -0
  70. package/dist/spa/src/views/ResourceParent.vue +0 -1
  71. package/dist/spa/src/views/ShowView.vue +1 -0
  72. package/dist/spa/src/websocket.ts +84 -0
  73. package/dist/spa/vite.config.ts +16 -34
  74. package/dist/types/Back.d.ts +70 -4
  75. package/dist/types/Back.d.ts.map +1 -1
  76. package/dist/types/Back.js.map +1 -1
  77. package/dist/types/Common.d.ts +4 -0
  78. package/dist/types/Common.d.ts.map +1 -1
  79. package/dist/types/FrontendAPI.d.ts +6 -0
  80. package/dist/types/FrontendAPI.d.ts.map +1 -1
  81. package/dist/types/FrontendAPI.js.map +1 -1
  82. package/package.json +5 -3
  83. package/dist/plugins/audit-log/types.d.ts +0 -35
  84. package/dist/plugins/audit-log/types.d.ts.map +0 -1
  85. package/dist/plugins/audit-log/types.js +0 -2
  86. package/dist/plugins/audit-log/types.js.map +0 -1
  87. package/dist/plugins/chat-gpt/types.d.ts +0 -82
  88. package/dist/plugins/chat-gpt/types.d.ts.map +0 -1
  89. package/dist/plugins/chat-gpt/types.js +0 -2
  90. package/dist/plugins/chat-gpt/types.js.map +0 -1
  91. package/dist/plugins/email-password-reset/types.d.ts +0 -28
  92. package/dist/plugins/email-password-reset/types.d.ts.map +0 -1
  93. package/dist/plugins/email-password-reset/types.js +0 -2
  94. package/dist/plugins/email-password-reset/types.js.map +0 -1
  95. package/dist/plugins/foreign-inline-list/types.d.ts +0 -19
  96. package/dist/plugins/foreign-inline-list/types.d.ts.map +0 -1
  97. package/dist/plugins/foreign-inline-list/types.js +0 -2
  98. package/dist/plugins/foreign-inline-list/types.js.map +0 -1
  99. package/dist/plugins/import-export/types.d.ts +0 -3
  100. package/dist/plugins/import-export/types.d.ts.map +0 -1
  101. package/dist/plugins/import-export/types.js +0 -2
  102. package/dist/plugins/import-export/types.js.map +0 -1
  103. package/dist/plugins/rich-editor/custom/async-queue.d.ts +0 -8
  104. package/dist/plugins/rich-editor/custom/async-queue.d.ts.map +0 -1
  105. package/dist/plugins/rich-editor/custom/async-queue.js +0 -29
  106. package/dist/plugins/rich-editor/custom/async-queue.js.map +0 -1
  107. package/dist/plugins/rich-editor/dist/custom/async-queue.d.ts +0 -8
  108. package/dist/plugins/rich-editor/dist/custom/async-queue.d.ts.map +0 -1
  109. package/dist/plugins/rich-editor/dist/custom/async-queue.js +0 -29
  110. package/dist/plugins/rich-editor/dist/custom/async-queue.js.map +0 -1
  111. package/dist/plugins/rich-editor/types.d.ts +0 -153
  112. package/dist/plugins/rich-editor/types.d.ts.map +0 -1
  113. package/dist/plugins/rich-editor/types.js +0 -16
  114. package/dist/plugins/rich-editor/types.js.map +0 -1
  115. package/dist/plugins/two-factors-auth/types.d.ts +0 -18
  116. package/dist/plugins/two-factors-auth/types.d.ts.map +0 -1
  117. package/dist/plugins/two-factors-auth/types.js +0 -2
  118. package/dist/plugins/two-factors-auth/types.js.map +0 -1
  119. package/dist/plugins/upload/types.d.ts +0 -132
  120. package/dist/plugins/upload/types.d.ts.map +0 -1
  121. package/dist/plugins/upload/types.js +0 -2
  122. package/dist/plugins/upload/types.js.map +0 -1
  123. package/dist/spa/src/acl/Button.vue +0 -21
  124. package/dist/spa/src/acl/Link.vue +0 -9
  125. package/dist/spa/src/components/Dropdown.vue +0 -167
  126. package/dist/spa/src/types/AdminForthConfig.js +0 -150
  127. package/dist/spa/src/types/AdminForthConfig.ts +0 -1816
  128. package/dist/spa/src/types/Commons.ts +0 -702
  129. package/dist/spa/src/types/FrontAndBack.ts +0 -698
  130. package/dist/types/AdminForthConfig.d.ts +0 -1665
  131. package/dist/types/AdminForthConfig.d.ts.map +0 -1
  132. package/dist/types/AdminForthConfig.js +0 -146
  133. package/dist/types/AdminForthConfig.js.map +0 -1
  134. package/dist/types/Commons.d.ts +0 -616
  135. package/dist/types/Commons.d.ts.map +0 -1
  136. package/dist/types/Commons.js +0 -65
  137. package/dist/types/Commons.js.map +0 -1
  138. package/dist/types/FrontAndBack.d.ts +0 -613
  139. package/dist/types/FrontAndBack.d.ts.map +0 -1
  140. package/dist/types/FrontAndBack.js +0 -62
  141. package/dist/types/FrontAndBack.js.map +0 -1
  142. /package/dist/spa/src/{components/AfTooltip.vue → afcl/Tooltip.vue} +0 -0
@@ -1,1665 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- import type { Express } from 'express';
3
- import type { Writable } from 'stream';
4
- export interface ICodeInjector {
5
- srcFoldersToSync: Object;
6
- allComponentNames: Object;
7
- getServeDir(): string;
8
- }
9
- export interface IConfigValidator {
10
- validateConfig(): any;
11
- postProcessAfterDiscover(resource: AdminForthResource): void;
12
- }
13
- export interface IAdminForthHttpResponse {
14
- setHeader: (key: string, value: string) => void;
15
- setStatus: (code: number, message: string) => void;
16
- blobStream: () => Writable;
17
- }
18
- /**
19
- * Implement this interface to create custom HTTP server adapter for AdminForth.
20
- */
21
- export interface IHttpServer {
22
- /**
23
- * Sets up HTTP server to serve AdminForth SPA.
24
- * if hotReload is true, it should proxy all requests and headers to Vite dev server at `http://localhost:5173$\{req.url\}`
25
- * otherwise it should serve AdminForth SPA from dist folder. See Express for example.
26
- */
27
- setupSpaServer(): void;
28
- /**
29
- * Method which should register endpoint in HTTP server.
30
- *
31
- * @param options : Object with method, path and handler properties.
32
- */
33
- endpoint(options: {
34
- method: string;
35
- noAuth?: boolean;
36
- path: string;
37
- handler: (body: any, adminUser: any, query: {
38
- [key: string]: string;
39
- }, headers: {
40
- [key: string]: string;
41
- }, cookies: {
42
- [key: string]: string;
43
- }, response: IAdminForthHttpResponse) => void;
44
- }): void;
45
- }
46
- export type AdminUser = {
47
- /**
48
- * primaryKey field value of user in table which is defined by {@link AdminForthConfig.auth.usersResourceId}
49
- */
50
- pk: string | null;
51
- /**
52
- * Username which taken from {@link AdminForthConfig.auth.usernameField} field in user resource {@link AdminForthConfig.auth.usersResourceId}
53
- */
54
- username: string;
55
- /**
56
- * User record fetched from database, from resource defined in {@link AdminForthConfig.auth.usersResourceId}
57
- */
58
- dbUser: any;
59
- };
60
- export interface IExpressHttpServer extends IHttpServer {
61
- /**
62
- * Call this method to serve AdminForth SPA from Express instance.
63
- * @param app : Express instance
64
- */
65
- serve(app: Express): void;
66
- /**
67
- * Method (middleware) to wrap express endpoints with authorization check.
68
- * Adds adminUser to request object if user is authorized. Drops request with 401 status if user is not authorized.
69
- * @param callable : Function which will be called if user is authorized.
70
- *
71
- * Example:
72
- *
73
- * ```ts
74
- * expressApp.get('/myApi', authorize((req, res) => \{
75
- * console.log('User is authorized', req.adminUser);
76
- * res.json(\{ message: 'Hello World' \});
77
- * \}));
78
- * ``
79
- *
80
- */
81
- authorize(callable: Function): void;
82
- }
83
- export interface IAdminForthFilter {
84
- field: string;
85
- operator: AdminForthFilterOperators;
86
- value: any;
87
- }
88
- export interface IAdminForthSort {
89
- field: string;
90
- direction: AdminForthSortDirections;
91
- }
92
- export interface IAdminForthDataSourceConnector {
93
- /**
94
- * Optional.
95
- * You an redefine this function to define how one record should be fetched from database.
96
- * You you will not redefine it, AdminForth will use {@link IAdminForthDataSourceConnector.getData} with limit 1 and offset 0 and
97
- * filter by primary key.
98
- */
99
- getRecordByPrimaryKeyWithOriginalTypes(resource: AdminForthResource, recordId: string): Promise<any>;
100
- /**
101
- * Function should go over all columns of table defined in resource.table and try to guess
102
- * data and constraints for each columns.
103
- * Type should be saved to:
104
- * - {@link AdminForthResourceColumn.type}
105
- * Constraints:
106
- * - {@link AdminForthResourceColumn.required}
107
- * - {@link AdminForthResourceColumn.primaryKey}
108
- * For string fields:
109
- * - {@link AdminForthResourceColumn.maxLength}
110
- * For numbers:
111
- * - {@link AdminForthResourceColumn.min}
112
- * - {@link AdminForthResourceColumn.max}
113
- * - {@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})
114
- * Also you can additionally save original column type to {@link AdminForthResourceColumn._underlineType}. This might be later used
115
- * in {@link IAdminForthDataSourceConnector.getFieldValue} and {@link IAdminForthDataSourceConnector.setFieldValue} methods.
116
- *
117
- *
118
- * @param resource
119
- */
120
- discoverFields(resource: AdminForthResource): Promise<{
121
- [key: string]: AdminForthResourceColumn;
122
- }>;
123
- /**
124
- * Used to transform record after fetching from database.
125
- * According to AdminForth convention, if {@link AdminForthResourceColumn.type} is set to {@link AdminForthDataTypes.DATETIME} then it should be transformed to ISO string.
126
- * @param field
127
- * @param value
128
- */
129
- getFieldValue(field: AdminForthResourceColumn, value: any): any;
130
- /**
131
- * Used to transform record before saving to database. Should perform operation inverse to {@link IAdminForthDataSourceConnector.getFieldValue}
132
- * @param field
133
- * @param value
134
- */
135
- setFieldValue(field: AdminForthResourceColumn, value: any): any;
136
- /**
137
- * Used to fetch data from database.
138
- * This method is reused both to list records and show one record (by passing limit 1 and offset 0) .
139
- *
140
- * Fields are returned from db "as is" then {@link AdminForthBaseConnector.getData} will transform each field using {@link IAdminForthDataSourceConnector.getFieldValue}
141
- */
142
- getDataWithOriginalTypes({ resource, limit, offset, sort, filters }: {
143
- resource: AdminForthResource;
144
- limit: number;
145
- offset: number;
146
- sort: IAdminForthSort[];
147
- filters: IAdminForthFilter[];
148
- }): Promise<Array<any>>;
149
- /**
150
- * Used to get count of records in database.
151
- */
152
- getCount({ resource, filters }: {
153
- resource: AdminForthResource;
154
- filters: IAdminForthFilter[];
155
- }): Promise<number>;
156
- /**
157
- * Optional method which used to get min and max values for columns in resource.
158
- * Called only for columns which have {@link AdminForthResourceColumn.allowMinMaxQuery} set to true.
159
- *
160
- * Internally should call {@link IAdminForthDataSourceConnector.getFieldValue} for both min and max values.
161
- */
162
- getMinMaxForColumnsWithOriginalTypes({ resource, columns }: {
163
- resource: AdminForthResource;
164
- columns: AdminForthResourceColumn[];
165
- }): Promise<{
166
- [key: string]: {
167
- min: any;
168
- max: any;
169
- };
170
- }>;
171
- /**
172
- * Used to create record in database.
173
- */
174
- createRecordOriginalValues({ resource, record }: {
175
- resource: AdminForthResource;
176
- record: any;
177
- }): Promise<void>;
178
- /**
179
- * Update record in database. newValues might have not all fields in record, but only changed ones.
180
- * recordId is value of field which is marked as {@link AdminForthResourceColumn.primaryKey}
181
- */
182
- updateRecordOriginalValues({ resource, recordId, newValues }: {
183
- resource: AdminForthResource;
184
- recordId: string;
185
- newValues: any;
186
- }): Promise<void>;
187
- /**
188
- * Used to delete record in database.
189
- */
190
- deleteRecord({ resource, recordId }: {
191
- resource: AdminForthResource;
192
- recordId: any;
193
- }): Promise<boolean>;
194
- }
195
- /**
196
- * Interface that exposes methods to interact with AdminForth in standard way
197
- */
198
- export interface IAdminForthDataSourceConnectorBase extends IAdminForthDataSourceConnector {
199
- getPrimaryKey(resource: AdminForthResource): string;
200
- getData({ resource, limit, offset, sort, filters }: {
201
- resource: AdminForthResource;
202
- limit: number;
203
- offset: number;
204
- sort: IAdminForthSort[];
205
- filters: IAdminForthFilter[];
206
- getTotals?: boolean;
207
- }): Promise<{
208
- data: Array<any>;
209
- total: number;
210
- }>;
211
- getRecordByPrimaryKey(resource: AdminForthResource, recordId: string): Promise<any>;
212
- createRecord({ resource, record, adminUser }: {
213
- resource: AdminForthResource;
214
- record: any;
215
- adminUser: AdminUser;
216
- }): Promise<{
217
- ok: boolean;
218
- error?: string;
219
- createdRecord?: any;
220
- }>;
221
- updateRecord({ resource, recordId, newValues }: {
222
- resource: AdminForthResource;
223
- recordId: string;
224
- newValues: any;
225
- }): Promise<{
226
- ok: boolean;
227
- error?: string;
228
- }>;
229
- getMinMaxForColumns({ resource, columns }: {
230
- resource: AdminForthResource;
231
- columns: AdminForthResourceColumn[];
232
- }): Promise<{
233
- [key: string]: {
234
- min: any;
235
- max: any;
236
- };
237
- }>;
238
- }
239
- export interface IAdminForthDataSourceConnectorConstructor {
240
- new ({ url }: {
241
- url: string;
242
- }): IAdminForthDataSourceConnectorBase;
243
- }
244
- export interface IAdminForthAuth {
245
- verify(jwt: string, mustHaveType: string, decodeUser?: boolean): Promise<any>;
246
- issueJWT(payload: Object, type: string, expiresIn?: string): string;
247
- removeCustomCookie({ response, name }: {
248
- response: any;
249
- name: string;
250
- }): void;
251
- setAuthCookie({ expireInDays, response, username, pk, }: {
252
- expireInDays?: number;
253
- response: any;
254
- username: string;
255
- pk: string;
256
- }): void;
257
- removeAuthCookie(response: any): void;
258
- }
259
- export interface IAdminForth {
260
- config: AdminForthConfig;
261
- codeInjector: ICodeInjector;
262
- express: IHttpServer;
263
- activatedPlugins: Array<IAdminForthPlugin>;
264
- baseUrlSlashed: string;
265
- statuses: {
266
- dbDiscover: 'running' | 'done';
267
- };
268
- connectors: {
269
- [key: string]: IAdminForthDataSourceConnectorBase;
270
- };
271
- createResourceRecord(params: {
272
- resource: AdminForthResource;
273
- record: any;
274
- adminUser: AdminUser;
275
- }): Promise<{
276
- error?: string;
277
- createdRecord?: any;
278
- }>;
279
- updateResourceRecord(params: {
280
- resource: AdminForthResource;
281
- recordId: any;
282
- record: any;
283
- oldRecord: any;
284
- adminUser: AdminUser;
285
- }): Promise<{
286
- error?: string;
287
- }>;
288
- deleteResourceRecord(params: {
289
- resource: AdminForthResource;
290
- recordId: string;
291
- adminUser: AdminUser;
292
- record: any;
293
- }): Promise<{
294
- error?: string;
295
- }>;
296
- auth: IAdminForthAuth;
297
- /**
298
- * Internal flag which indicates if AdminForth is running in hot reload mode.
299
- */
300
- runningHotReload: boolean;
301
- /**
302
- * Connects to databases defined in datasources and fetches described resource columns to find out data types and constraints.
303
- * You must call this method as soon as possible after AdminForth class is instantiated.
304
- */
305
- discoverDatabases(): Promise<void>;
306
- /**
307
- * Bundles AdminForth SPA by injecting custom components into internal pre-made SPA source code. It generates internally dist which then will be
308
- * served by AdminForth HTTP adapter.
309
- * Bundle is generated in /tmp folder so if you have ramfs or tmpfs this operation will be faster.
310
- *
311
- * 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.
312
- * 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.
313
- */
314
- bundleNow({ hotReload, verbose }: {
315
- hotReload: boolean;
316
- verbose: boolean;
317
- }): Promise<void>;
318
- /**
319
- * Resource to get access to operational resources for data api fetching and manipulation.
320
- */
321
- resource(resourceId: string): IOperationalResource;
322
- /**
323
- * This method will be automatically called from AdminForth HTTP adapter to serve AdminForth SPA.
324
- */
325
- setupEndpoints(server: IHttpServer): void;
326
- }
327
- export interface IAdminForthPlugin {
328
- adminforth: IAdminForth;
329
- pluginDir: string;
330
- customFolderName: string;
331
- pluginInstanceId: string;
332
- customFolderPath: string;
333
- pluginOptions: any;
334
- resourceConfig: AdminForthResource;
335
- className: string;
336
- /**
337
- * Before activating all plugins are sorted by this number and then activated in order.
338
- * If you want to make sure that your plugin is activated after some other plugin, set this number to higher value. (default is 0)
339
- */
340
- activationOrder: number;
341
- /**
342
- * AdminForth plugins concept is based on modification of full AdminForth configuration
343
- * to add some custom functionality. For example plugin might simply add custom field to resource by reusing
344
- * {@link AdminForthResourceColumn.components} object, then add some hook which will modify record before getting or saving it to database.
345
- *
346
- * So this method is core of AdminForth plugins. It allows to modify full resource configuration.
347
- * @param adminforth Instance of IAdminForth
348
- * @param resourceConfig Resource configuration object which will be modified by plugin
349
- */
350
- modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource): void;
351
- componentPath(componentFile: string): string;
352
- /**
353
- * If plugin should support multiple installations per one resource, this function that should return unique string for each instance of plugin.
354
- * For example if plugin is installed for one column and this column defined as
355
- * `targetColumn` in plugin options, then this method should return `${pluginOptions.targetColumn}`.
356
- *
357
- * If plugin should support only one installation per resource, option can return 'single'
358
- * @param pluginOptions - options of plugin
359
- */
360
- instanceUniqueRepresentation(pluginOptions: any): string;
361
- /**
362
- * Optional method which will be called after AdminForth discovers all resources and their columns.
363
- * Can be used to validate types of columns, check if some columns are missing, etc.
364
- */
365
- validateConfigAfterDiscover?(adminforth: IAdminForth, resourceConfig: AdminForthResource): void;
366
- /**
367
- * Here you can register custom endpoints for your plugin.
368
- *
369
- * @param server
370
- */
371
- setupEndpoints(server: IHttpServer): void;
372
- }
373
- export declare enum AdminForthMenuTypes {
374
- /**
375
- * HEADING is just a label in the menu.
376
- * Respect `label` and `icon` property in {@link AdminForthConfigMenuItem}
377
- */
378
- heading = "heading",
379
- /**
380
- * GROUP is a group of menu items.
381
- * Respects `label`, `icon` and `children` properties in {@link AdminForthConfigMenuItem}
382
- * use @AdminForthMenuTypes.open to set if group is open by default
383
- */
384
- group = "group",
385
- /**
386
- * RESOURCE is a link to a resource.
387
- * Respects `label`, `icon`, `resourceId`, `homepage`, `isStaticRoute` properties in {@link AdminForthConfigMenuItem}
388
- */
389
- resource = "resource",
390
- /**
391
- * PAGE is a link to a custom page.
392
- * Respects `label`, `icon`, `path`, `component`, `homepage`, `isStaticRoute`, properties in {@link AdminForthConfigMenuItem}
393
- *
394
- * Example:
395
- *
396
- * ```ts
397
- * \{
398
- * type: AdminForthMenuTypes.PAGE,
399
- * label: 'Custom Page',
400
- * icon: 'home',
401
- * path: '/dash',
402
- * component: '@@/Dashboard.vue',
403
- * homepage: true,
404
- * \}
405
- * ```
406
- *
407
- */
408
- page = "page",
409
- /**
410
- * GAP ads some space between menu items.
411
- */
412
- gap = "gap",
413
- /**
414
- * DIVIDER is a divider between menu items.
415
- */
416
- divider = "divider"
417
- }
418
- export declare enum AdminForthResourcePages {
419
- list = "list",
420
- show = "show",
421
- edit = "edit",
422
- create = "create",
423
- filter = "filter"
424
- }
425
- /**
426
- * Menu item which displayed in the left sidebar of the admin panel.
427
- */
428
- export type AdminForthConfigMenuItem = {
429
- type?: AdminForthMenuTypes | keyof typeof AdminForthMenuTypes;
430
- /**
431
- * Label for menu item which will be displayed in the admin panel.
432
- */
433
- label?: string;
434
- /**
435
- * Icon for menu item which will be displayed in the admin panel.
436
- * Supports iconify icons in format `<icon set name>:<icon name>`
437
- * Browse available icons here: https://icon-sets.iconify.design/
438
- *
439
- * Example:
440
- *
441
- * ```ts
442
- * icon: 'flowbite:brain-solid',
443
- * ```
444
- *
445
- */
446
- icon?: string;
447
- /**
448
- * Path to custom component which will be displayed in the admin panel.
449
- *
450
- */
451
- path?: string;
452
- /**
453
- * Component to be used for this menu item. Component should be placed in custom folder and referenced with `@@/` prefix.
454
- * Supported for AdminForthMenuTypes.PAGE only!
455
- * Example:
456
- *
457
- * ```ts
458
- * component: '@@/Dashboard.vue',
459
- * ```
460
- *
461
- */
462
- component?: string;
463
- /**
464
- * Resource ID which will be used to fetch data from.
465
- * Supported for AdminForthMenuTypes.RESOURCE only!
466
- *
467
- */
468
- resourceId?: string;
469
- /**
470
- * If true, group will be open by default after user login to the admin panel.
471
- * Also will be used to redirect from root path.
472
- */
473
- homepage?: boolean;
474
- /**
475
- * Where Group is open by default
476
- * Supported for AdminForthMenuTypes.GROUP only!
477
- *
478
- */
479
- open?: boolean;
480
- /**
481
- * Children menu items which will be displayed in this group.
482
- * Supported for AdminForthMenuTypes.GROUP only!
483
- */
484
- children?: Array<AdminForthConfigMenuItem>;
485
- /**
486
- * By default all pages are imported dynamically with lazy import().
487
- * If you wish to import page statically, set this option to true.
488
- * Homepage will be imported statically by default. but you can override it with this option.
489
- */
490
- isStaticRoute?: boolean;
491
- meta?: {
492
- title?: string;
493
- };
494
- /**
495
- * Optional callback which will be called before rendering the menu for each item.
496
- * You can use it to hide menu items depending on some user
497
- */
498
- visible?: (user: AdminUser) => boolean;
499
- /**
500
- * Optional callback which will be called before rendering the menu for each item.
501
- * Result of callback if not null will be used as a small badge near the menu item.
502
- */
503
- badge?: string | ((user: AdminUser) => Promise<string>);
504
- };
505
- /**
506
- * Column describes one field in the table or collection in database.
507
- */
508
- export type AdminForthResourceColumn = {
509
- /**
510
- * Column name in database.
511
- */
512
- name: string;
513
- /**
514
- * How column can be labled in the admin panel.
515
- * Use it for renaming columns. Defaulted to column name with Uppercased first letter.
516
- */
517
- label?: string;
518
- /**
519
- * Type of data in column.
520
- * AdminForth will use this information to render proper input fields in the admin panel.
521
- * AdminForth tries to guess type of data from database column type automatically for typed databases like SQL-based.
522
- * However you can explicitly set it to any value. E.g. set AdminForthDataTypes.DATETIME for your string column in SQLite, which stores ISO date strings.
523
- */
524
- type?: AdminForthDataTypes;
525
- /**
526
- * An optional configuration object for extra settings.
527
- */
528
- extra?: {
529
- /**
530
- * How many levels of JSON should be collapsed.
531
- * `0` means - root level will be already collapsed e.g. `{a:1}` will show `{...}` where `'...'` is clickable
532
- * `1` means - root level will be shown, but next sub-level will be collapsed e.g. `{a: {b: 1}}` will show `{a: ...}` where `'...'` is clickable
533
- *
534
- * Default is 1.
535
- */
536
- jsonCollapsedLevel?: number;
537
- };
538
- /**
539
- * Whether to use this column as record identifier.
540
- * Only one column can be primary key.
541
- * AdminForth tries to guess primary key automatically first.
542
- */
543
- primaryKey?: boolean;
544
- /**
545
- * Whether AdminForth will require this field to be filled in create and edit forms.
546
- * Can be set to boolean or object with create and edit properties.
547
- * If boolean, it will be used for both create and edit forms.
548
- */
549
- required?: boolean | {
550
- create?: boolean;
551
- edit?: boolean;
552
- };
553
- /**
554
- * Whether AdminForth will show editing note near the field in edit/create form.
555
- */
556
- editingNote?: string | {
557
- create?: string;
558
- edit?: string;
559
- };
560
- /**
561
- * On which AdminForth pages this field will be shown. By default all.
562
- * Example: if you want to show field only in create and edit pages, set it to
563
- *
564
- * ```ts
565
- * showIn: [AdminForthResourcePages.CREATE, AdminForthResourcePages.EDIT]
566
- * ```
567
- *
568
- */
569
- showIn?: Array<AdminForthResourcePages | keyof typeof AdminForthResourcePages>;
570
- /**
571
- * Whether AdminForth will show this field in show view.
572
- */
573
- fillOnCreate?: Function;
574
- /**
575
- * Whether AdminForth will request user to enter unique value during creating or editing record.
576
- * This option causes AdminForth to make a request to database to check if value is unique.
577
- * (Constraints are not used, so for large-tables performance make sure you have unique index in database if you set this option to true)
578
- */
579
- isUnique?: boolean;
580
- /**
581
- * Will automatically convert any capital letters to lowercase in input during editing
582
- */
583
- enforceLowerCase?: boolean;
584
- /**
585
- * Runtime validation Regexp rules for this field.
586
- */
587
- validation?: Array<ValidationObject>;
588
- /**
589
- * Allows to make the field which does not exist in database table.
590
- * Examples: add custom show field with user country flag:
591
- *
592
- * ```ts
593
- * {
594
- * label: 'Country Flag',
595
- * type: AdminForthDataTypes.STRING,
596
- * virtual: true,
597
- * showIn: [AdminForthResourcePages.SHOW, AdminForthResourcePages.LIST],
598
- * components: {
599
- * show: '@@/CountryFlag.vue',
600
- * list: '@@/CountryFlag.vue',
601
- * },
602
- * }
603
- * ```
604
- *
605
- * This field will be displayed in show and list views with custom component `CountryFlag.vue`. CountryFlag.vue should be placed in custom folder and can be next:
606
- *
607
- * ```html
608
- * <template>
609
- * {{ getFlagEmojiFromIso(record.ipCountry) }}
610
- * </template>
611
- *
612
- * <script setup>
613
- * const props = defineProps(['record']);
614
- *
615
- * function getFlagEmojiFromIso(iso) {
616
- * return iso.toUpperCase().replace(/./g, (char) => String.fromCodePoint(char.charCodeAt(0) + 127397));
617
- * }
618
- * </script>
619
- * ```
620
- *
621
- */
622
- virtual?: boolean;
623
- /**
624
- * Whether AdminForth will show this field in list view.
625
- */
626
- allowMinMaxQuery?: boolean;
627
- /**
628
- * Custom components which will be used to render this field in the admin panel.
629
- */
630
- components?: AdminForthFieldComponents;
631
- /**
632
- * Maximum length of string that can be entered in this field.
633
- */
634
- maxLength?: number;
635
- /**
636
- * Minimum length of string that can be entered in this field.
637
- */
638
- minLength?: number;
639
- min?: number;
640
- max?: number;
641
- /**
642
- * Minimum value that can be entered in this field.
643
- */
644
- minValue?: number;
645
- /**
646
- * Maximum value that can be entered in this field.
647
- */
648
- maxValue?: number;
649
- /**
650
- * Enum of possible values for this field.
651
- */
652
- enum?: Array<AdminForthColumnEnumItem>;
653
- /**
654
- * Foreign resource which has pk column with values same that written in this column.
655
- */
656
- foreignResource?: AdminForthForeignResource;
657
- sortable?: boolean;
658
- /**
659
- * if true field will !not be passed to UI under no circumstances, but will be presented in hooks
660
- */
661
- backendOnly?: boolean;
662
- /**
663
- * Masked fields will be displayed as `*****` on Edit and Create pages.
664
- */
665
- masked?: boolean;
666
- /**
667
- * Internal type which indicates original type of column in database.
668
- */
669
- _underlineType?: string;
670
- };
671
- /**
672
- * Modify query to change how data is fetched from database.
673
- * Return ok: false and error: string to stop execution and show error message to user. Return ok: true to continue execution.
674
- */
675
- export type BeforeDataSourceRequestFunction = (params: {
676
- resource: AdminForthResource;
677
- adminUser: AdminUser;
678
- query: any;
679
- extra: {
680
- body: any;
681
- query: Record<string, string>;
682
- headers: Record<string, string>;
683
- cookies: Record<string, string>;
684
- };
685
- }) => Promise<{
686
- ok: boolean;
687
- error?: string;
688
- }>;
689
- /**
690
- * Modify response to change how data is returned after fetching from database.
691
- * Return ok: false and error: string to stop execution and show error message to user. Return ok: true to continue execution.
692
- */
693
- export type AfterDataSourceResponseFunction = (params: {
694
- resource: AdminForthResource;
695
- adminUser: AdminUser;
696
- response: any;
697
- extra: {
698
- body: any;
699
- query: Record<string, string>;
700
- headers: Record<string, string>;
701
- cookies: {
702
- key: string;
703
- value: string;
704
- }[];
705
- };
706
- }) => Promise<{
707
- ok: boolean;
708
- error?: string;
709
- }>;
710
- /**
711
- * Modify record to change how data is saved to database.
712
- * Return ok: false and error: string to stop execution and show error message to user. Return ok: true to continue execution.
713
- */
714
- export type BeforeSaveFunction = (params: {
715
- resource: AdminForthResource;
716
- recordId: any;
717
- adminUser: AdminUser;
718
- record: any;
719
- oldRecord?: any;
720
- }) => Promise<{
721
- ok: boolean;
722
- error?: string;
723
- }>;
724
- /**
725
- * Modify record to change how data is saved to database.
726
- * Return ok: false and error: string to stop execution and show error message to user. Return ok: true to continue execution.
727
- */
728
- export type AfterSaveFunction = (params: {
729
- resource: AdminForthResource;
730
- recordId: any;
731
- adminUser: AdminUser;
732
- record: any;
733
- oldRecord?: any;
734
- }) => Promise<{
735
- ok: boolean;
736
- error?: string;
737
- }>;
738
- /**
739
- * Allow to get user data before login confirmation, will triger when user try to login.
740
- */
741
- export type BeforeLoginConfirmationFunction = (params?: {
742
- adminUser: AdminUser;
743
- response: IAdminForthHttpResponse;
744
- }) => Promise<{
745
- ok: boolean;
746
- error?: string;
747
- body: {
748
- redirectTo?: string;
749
- allowedLogin?: boolean;
750
- };
751
- }>;
752
- export type AdminForthBulkAction = {
753
- id?: string;
754
- /**
755
- * Label for action button which will be displayed in the list view
756
- */
757
- label: string;
758
- state: string;
759
- /**
760
- * Icon for action button which will be displayed in the list view
761
- */
762
- icon?: string;
763
- /**
764
- * Callback which will be called on backend when user clicks on action button.
765
- * It should return Promise which will be resolved when action is done.
766
- */
767
- action: ({ resource, selectedIds, adminUser }: {
768
- resource: AdminForthResource;
769
- selectedIds: Array<any>;
770
- adminUser: AdminUser;
771
- }) => Promise<{
772
- ok: boolean;
773
- error?: string;
774
- successMessage?: string;
775
- }>;
776
- /**
777
- * Confirmation message which will be displayed to user before action is executed.
778
- */
779
- confirm?: string;
780
- /**
781
- * Success message which will be displayed to user after action is executed.
782
- */
783
- successMessage?: string;
784
- /**
785
- * Allowed callback called to check whether action is allowed for user.
786
- * 1. It called first time when user goes to list view. If callback returns false, action button will be hidden on list view.
787
- * 2. This same callback called second time when user clicks an action button. If callback returns false, action will not be executed.
788
- * In second time selectedIds will be passed to callback (because checkbox for items are selected), so you can use this to make additional
789
- * checks ( for example to check if user has permission for certain records ).
790
- *
791
- * Example:
792
- *
793
- * ```ts
794
- * allowed: async ({ resource, adminUser, selectedIds }) => {
795
- * if (adminUser.dbUser.role !== 'superadmin') {
796
- * return false;
797
- * }
798
- * return true;
799
- * }
800
- * ```
801
- *
802
- */
803
- allowed?: ({ resource, adminUser, selectedIds, allowedActions }: {
804
- /**
805
- * recordIds will be passed only once user tries to perform bulk action by clicking on button
806
- */
807
- selectedIds?: Array<any>;
808
- resource: AdminForthResource;
809
- /**
810
- * Admin user object
811
- */
812
- adminUser: AdminUser;
813
- /**
814
- * Allowed standard actions for current user resolved by calling allowedActions callbacks if they are passed.
815
- * You can use this variable to rely on standard actions permissions. E.g. if you have custom actions "Mark as read", you
816
- * might want to allow it only for users who have "edit" action allowed:
817
- *
818
- * Example:
819
- *
820
- * ```ts
821
- *
822
- * options: \{
823
- * bulkActions: [
824
- * \{
825
- * label: 'Mark as read',
826
- * action: async (\{ resource, recordIds \}) => \{
827
- * await markAsRead(recordIds);
828
- * \},
829
- * allowed: (\{ allowedActions \}) => allowedActions.edit,
830
- * \}
831
- * ],
832
- * allowedActions: \{
833
- * edit: (\{ resource, adminUser, recordIds \}) => \{
834
- * return adminUser.dbUser.role === 'superadmin';
835
- * \}
836
- * \}
837
- * \}
838
- * ```
839
- *
840
- */
841
- allowedActions: AllowedActionsResolved;
842
- }) => Promise<boolean>;
843
- };
844
- /**
845
- * Resource describes one table or collection in database.
846
- * AdminForth generates set of pages for 'list', 'show', 'edit', 'create', 'filter' operations for each resource.
847
- */
848
- export type AdminForthResource = {
849
- /**
850
- * Unique identifier of resource. By default it equals to table name in database.
851
- * If you wish you can explicitly set it to any string.
852
- * We added to support cases when 2 datasources have tables with the same name.
853
- */
854
- resourceId?: string;
855
- /**
856
- * Label for resource which will be displayed in the admin panel.
857
- * By default it equals to table name in database.
858
- */
859
- label?: string;
860
- /**
861
- * Table name in database which will be used to fetch data from. Might be case sensitive.
862
- */
863
- table: string;
864
- /**
865
- * ID of datasource which will be used to fetch data from.
866
- */
867
- dataSource: string;
868
- /**
869
- * Array of columns which will be displayed in the admin panel.
870
- * Each column has its own configuration.
871
- */
872
- columns: Array<AdminForthResourceColumn>;
873
- /**
874
- * Internal array of columns which are not virtual. You should not edit it.
875
- */
876
- dataSourceColumns?: Array<AdminForthResourceColumn>;
877
- /**
878
- * Hook which allow you to modify record label
879
- *
880
- * Example:
881
- *
882
- * ```ts
883
- * recordLabel: (record) => `${record.name} - ${record.id}`,
884
- * ```
885
- *
886
- */
887
- recordLabel?: Function;
888
- /**
889
- * Array of plugins which will be used to modify resource configuration.
890
- *
891
- */
892
- plugins?: Array<IAdminForthPlugin>;
893
- /**
894
- * Hooks allow you to change the data on different stages of resource lifecycle.
895
- * Hooks are functions which will be called on backend side (only backend side).
896
- */
897
- hooks?: {
898
- show?: {
899
- /**
900
- * Typical use-cases:
901
- * - request additional data from database before returning to frontend for soft-join
902
- */
903
- beforeDatasourceRequest?: BeforeDataSourceRequestFunction | Array<BeforeDataSourceRequestFunction>;
904
- /**
905
- * Typical use-cases:
906
- * - Transform value for some field for record returned from database before returning to frontend (minimize, sanitize, etc)
907
- * - If some-why you can't use `backendOnly` you can cleanup sensitive fields here
908
- * - Attach additional data to record before returning to frontend
909
- */
910
- afterDatasourceResponse?: AfterDataSourceResponseFunction | Array<AfterDataSourceResponseFunction>;
911
- };
912
- list?: {
913
- /**
914
- * Typical use-cases:
915
- * - add additional filters in addition to what user selected before fetching data from database.
916
- * - same as hooks.show.beforeDatasourceRequest
917
- */
918
- beforeDatasourceRequest?: BeforeDataSourceRequestFunction | Array<BeforeDataSourceRequestFunction>;
919
- /**
920
- * Typical use-cases:
921
- * - Same as hooks.show.afterDatasourceResponse but applied for all records returned from database for
922
- * showing in list view, e.g. add new field to each record in list view
923
- */
924
- afterDatasourceResponse?: AfterDataSourceResponseFunction | Array<AfterDataSourceResponseFunction>;
925
- };
926
- create?: {
927
- /**
928
- * Typical use-cases:
929
- * - Validate record before saving to database and interrupt execution if validation failed (`allowedActions.create` should be preferred in most cases)
930
- * - fill-in adminUser as creator of record
931
- * - Attach additional data to record before saving to database (mostly fillOnCreate should be used instead)
932
- */
933
- beforeSave?: BeforeSaveFunction | Array<BeforeSaveFunction>;
934
- /**
935
- * Typical use-cases:
936
- * - Initiate some trigger after record saved to database (e.g sync to another datasource)
937
- */
938
- afterSave?: AfterSaveFunction | Array<AfterSaveFunction>;
939
- };
940
- edit?: {
941
- /**
942
- * Typical use-cases:
943
- * - Same as hooks.create.beforeSave but for edit page
944
- */
945
- beforeSave?: BeforeSaveFunction | Array<BeforeSaveFunction>;
946
- /**
947
- * Typical use-cases:
948
- * - Same as hooks.create.afterSave but for edit page
949
- */
950
- afterSave?: AfterSaveFunction | Array<AfterSaveFunction>;
951
- };
952
- delete?: {
953
- /**
954
- * Typical use-cases:
955
- * - Validate that record can be deleted and interrupt execution if validation failed (`allowedActions.delete` should be preferred in most cases)
956
- */
957
- beforeSave?: BeforeSaveFunction | Array<BeforeSaveFunction>;
958
- /**
959
- * Typical use-cases:
960
- * - Initiate some trigger after record deleted from database (e.g sync to another datasource)
961
- */
962
- afterSave?: BeforeSaveFunction | Array<BeforeSaveFunction>;
963
- };
964
- };
965
- /**
966
- * General options for resource.
967
- */
968
- options?: {
969
- /**
970
- * Default sort for list view.
971
- * Example:
972
- *
973
- * ```ts
974
- * import { AdminForthSortDirections } from 'adminforth';
975
- *
976
- * ...
977
- *
978
- * defaultSort: {
979
- * columnName: 'created_at',
980
- * direction: AdminForthSortDirections.ASC,
981
- * }
982
- * ```
983
- *
984
- */
985
- defaultSort?: {
986
- /**
987
- * Column name which will be used to sort records.
988
- */
989
- columnName: string;
990
- /**
991
- * Direction of sorting. Can be 'asc' or 'desc'.
992
- */
993
- direction: AdminForthSortDirections | string;
994
- };
995
- /**
996
- * Custom bulk actions list. Bulk actions available in list view when user selects multiple records by
997
- * using checkboxes.
998
- */
999
- bulkActions?: AdminForthBulkAction[];
1000
- /**
1001
- * Allowed actions for resource.
1002
- *
1003
- * Example:
1004
- *
1005
- * ```ts
1006
- * allowedActions: {
1007
- * create: ({ resource, adminUser }) => {
1008
- * // Allow only superadmin to create records
1009
- * return adminUser.dbUser.role === 'superadmin';
1010
- * },
1011
- * delete: false, // disable delete action for all users
1012
- * }
1013
- * ```
1014
- *
1015
- */
1016
- allowedActions?: AllowedActions;
1017
- /**
1018
- * Allows to make groups of columns in create/edit resource pages.
1019
- */
1020
- createEditGroups?: {
1021
- groupName: string;
1022
- columns: string[];
1023
- }[];
1024
- /**
1025
- * Page size for list view
1026
- */
1027
- listPageSize?: number;
1028
- /**
1029
- * Callback to define what happens when user clicks on record in list view.
1030
- * By default show view will be opened.
1031
- * If you wish to open custom page, return URL to the custom page (can start with https://, or relative adminforth path)
1032
- * If you wish to open page in new tab, add `target=_blank` get param to returned URL, example:
1033
- *
1034
- * ```ts
1035
- * listTableClickUrl: async (record, adminUser) => {
1036
- * return `https://google.com/search?q=${record.name}&target=_blank`;
1037
- * }
1038
- * ```
1039
- *
1040
- * If you wish to do nothing on click, return null.
1041
- *
1042
- * Example:
1043
- *
1044
- * ```ts
1045
- * listTableClickUrl: async (record, adminUser) => {
1046
- * return null;
1047
- * }
1048
- * ```
1049
- *
1050
- * @param record - record which was clicked
1051
- * @param adminUser - user who clicked
1052
- * @returns
1053
- */
1054
- listTableClickUrl?: (record: any, adminUser: AdminUser) => Promise<string | null>;
1055
- /**
1056
- * Whether to refresh existing list rows automatically every N seconds.
1057
- */
1058
- listRowsAutoRefreshSeconds?: number;
1059
- /**
1060
- * Custom components which can be injected into AdminForth CRUD pages.
1061
- * Each injection is a path to a custom component which will be displayed in the admin panel.
1062
- * Can be also array to render multiple injections one after another.
1063
- *
1064
- * Example:
1065
- *
1066
- * ```ts
1067
- * pageInjections: {
1068
- * list: {
1069
- * beforeBreadcrumbs: '@@/Announcement.vue',
1070
- * }
1071
- * }
1072
- * ```
1073
- *
1074
- *
1075
- */
1076
- pageInjections?: {
1077
- /**
1078
- * Custom components which can be injected into resource list page.
1079
- *
1080
- * Component accepts next props: [resource, adminUser, meta]
1081
- */
1082
- list?: {
1083
- beforeBreadcrumbs?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
1084
- afterBreadcrumbs?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
1085
- bottom?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
1086
- threeDotsDropdownItems?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
1087
- customActionIcons?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
1088
- };
1089
- /**
1090
- * Custom components which can be injected into resource show page.
1091
- *
1092
- * Component accepts next props: [record, resource, adminUser, meta]
1093
- */
1094
- show?: {
1095
- beforeBreadcrumbs?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
1096
- afterBreadcrumbs?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
1097
- bottom?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
1098
- threeDotsDropdownItems?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
1099
- };
1100
- /**
1101
- * Custom components which can be injected into resource edit page.
1102
- *
1103
- * Component accepts next props: [record, resource, adminUser, meta]
1104
- */
1105
- edit?: {
1106
- beforeBreadcrumbs?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
1107
- afterBreadcrumbs?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
1108
- bottom?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
1109
- threeDotsDropdownItems?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
1110
- };
1111
- /**
1112
- * Custom components which can be injected into resource create page.
1113
- *
1114
- * Component accepts next props: [resource, adminUser, meta]
1115
- */
1116
- create?: {
1117
- beforeBreadcrumbs?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
1118
- afterBreadcrumbs?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
1119
- bottom?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
1120
- threeDotsDropdownItems?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
1121
- };
1122
- };
1123
- };
1124
- };
1125
- /**
1126
- * Data source describes database connection which will be used to fetch data for resources.
1127
- * Each resource should use one data source.
1128
- */
1129
- export type AdminForthDataSource = {
1130
- /**
1131
- * ID of datasource which you will use in resources to specify from which database to fetch data from
1132
- */
1133
- id: string;
1134
- /**
1135
- * URL to database. Examples:
1136
- *
1137
- * - MongoDB: `mongodb://<user>:<password>@<host>:<port>/<database>`
1138
- * - PostgreSQL: `postgresql://<user>:<password>@<host>:<port>/<database>`
1139
- * - SQLite: `sqlite://<path>`
1140
- */
1141
- url: string;
1142
- };
1143
- /**
1144
- * Main configuration object for AdminForth
1145
- */
1146
- export type AdminForthConfig = {
1147
- /**
1148
- * Authorization module configuration
1149
- */
1150
- auth?: {
1151
- /**
1152
- * Resource ID for resource which stores user table.
1153
- * 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.
1154
- * In other words this setting is a reference to a table in database where users will be fetched from on login.
1155
- */
1156
- usersResourceId?: string;
1157
- /**
1158
- * Legacy field left for backward compatibility. Use usersResourceId instead.
1159
- */
1160
- resourceId?: string;
1161
- /**
1162
- * Field name (column name) in user resource which will be used as username for searching user in database during login.
1163
- * Can be e.g. 'email' or 'username'
1164
- */
1165
- usernameField: string;
1166
- /**
1167
- * Field name (column name) in user resource which will be used to get hash of password.
1168
- * Can be e.g. 'passwordHash'
1169
- */
1170
- passwordHashField: string;
1171
- /**
1172
- * File path to custom background image for login page
1173
- * Example:
1174
- * Place file `login-background.jpg` to `./custom` folder and set this option:
1175
- *
1176
- * ```ts
1177
- * loginBackgroundImage: '@@/login-background.jpg',
1178
- * ```
1179
- */
1180
- loginBackgroundImage?: string;
1181
- /**
1182
- * Position of background image on login page
1183
- * 'over' - image will be displayed over full login page under login form
1184
- * '1/2' - image will be displayed on left 1/2 of login page
1185
- *
1186
- * Default: '1/2'
1187
- */
1188
- loginBackgroundPosition?: 'over' | '1/2' | '1/3' | '2/3' | '3/4' | '2/5' | '3/5';
1189
- /**
1190
- * Function or functions which will be called before user try to login.
1191
- * Each function will resive User object as an argument
1192
- */
1193
- beforeLoginConfirmation?: BeforeLoginConfirmationFunction | Array<BeforeLoginConfirmationFunction>;
1194
- /**
1195
- * Optionally if your users table has a field(column) with full name, you can set it here.
1196
- * This field will be used to display user name in the top right corner of the admin panel.
1197
- */
1198
- userFullNameField?: string;
1199
- /**
1200
- * Pair of login and pass substitution for demo mode. Split by ':'
1201
- * ! This option is for demo purposes only, never use it for your projects
1202
- */
1203
- demoCredentials?: string;
1204
- /**
1205
- * Any prompt to show users on login. Supports HTML.
1206
- */
1207
- loginPromptHTML?: string;
1208
- /**
1209
- * Remember me days for "Remember Me" checkbox on login page.
1210
- * If not set or set to null/0/undefined, "Remember Me" checkbox will not be displayed.
1211
- * If rememberMeDays is set, then users who check "Remember Me" will be staying logged in for this amount of days.
1212
- */
1213
- rememberMeDays?: number;
1214
- };
1215
- /**
1216
- * Array of resources which will be displayed in the admin panel.
1217
- * Resource represents one table or collection in database.
1218
- * Each resource has its own configuration.
1219
- */
1220
- resources: Array<AdminForthResource>;
1221
- /**
1222
- * Array of left sidebar menu items which will be displayed in the admin panel.
1223
- * Menu items can be links to resources or custom pages.
1224
- * Menu items can be grouped.
1225
- *
1226
- */
1227
- menu: Array<AdminForthConfigMenuItem>;
1228
- /**
1229
- * If you want use custom DataSource which is not supported by AdminForth yet, you can define it's class here
1230
- *
1231
- */
1232
- databaseConnectors?: {
1233
- [key: string]: IAdminForthDataSourceConnectorConstructor;
1234
- };
1235
- /**
1236
- * List of data sources which will be used to fetch data for resources.
1237
- * Datasource is one database connection
1238
- *
1239
- */
1240
- dataSources: Array<AdminForthDataSource>;
1241
- /**
1242
- * Settings which allow you to customize AdminForth
1243
- *
1244
- */
1245
- customization?: {
1246
- /**
1247
- * Your app name
1248
- */
1249
- brandName?: string;
1250
- /**
1251
- * Slug which will be used on tech side e.g. to store cookies separately.
1252
- * Created automatically from brandName if not set.
1253
- */
1254
- _brandNameSlug?: string;
1255
- /**
1256
- * Whether to show brand name in sidebar
1257
- * default is true
1258
- */
1259
- showBrandNameInSidebar?: boolean;
1260
- /**
1261
- * Path to your app logo
1262
- *
1263
- * Example:
1264
- * Place file `logo.svg` to `./custom` folder and set this option:
1265
- *
1266
- * ```ts
1267
- * brandLogo: '@@/logo.svg',
1268
- * ```
1269
- *
1270
- */
1271
- brandLogo?: string;
1272
- /**
1273
- * Path to your app favicon
1274
- *
1275
- * Example:
1276
- * Place file `favicon.png` to `./custom` folder and set this option:
1277
- *
1278
- * ```ts
1279
- * favicon: '@@/favicon.png',
1280
- * ```
1281
- */
1282
- favicon?: string;
1283
- /**
1284
- * DayJS format string for all dates in the app.
1285
- * Defaulted to 'MMM D, YYYY'
1286
- */
1287
- datesFormat?: string;
1288
- /**
1289
- * DayJS format string for all datetimes in the app.
1290
- * Defaulted to 'HH:mm:ss'
1291
- */
1292
- timeFormat?: string;
1293
- /**
1294
- * HTML title tag value, defaults to brandName
1295
- */
1296
- title?: string;
1297
- /**
1298
- * Placeholder for empty fields in lists and show views, by default empty string ''
1299
- */
1300
- emptyFieldPlaceholder?: {
1301
- show?: string;
1302
- list?: string;
1303
- } | string;
1304
- /**
1305
- * Relative or absolute path to custom components directory
1306
- * By default equals `./custom`.
1307
- *
1308
- * Custom .vue files, images, and any other assets placed in this directory can be accessed in AdminForth components and configs with `@@/`.
1309
- *
1310
- * For example if file path is `./custom/comp/my.vue`, you can use it in AdminForth config like this:
1311
- *
1312
- * ```ts
1313
- * components: {
1314
- * show: '@@/comp/my.vue',
1315
- * }
1316
- * ```
1317
- *
1318
- */
1319
- customComponentsDir?: string;
1320
- /**
1321
- * Path to custom .ts file which allows to inject custom Vue uses in SPA or add custom imports.
1322
- *
1323
- * Example: Create file: `./custom/vue-uses.ts` with next content:
1324
- *
1325
- * ```ts
1326
- * import HighchartsVue from 'highcharts-vue';
1327
- * // import '@@/custom.scss'; // here is how you can import custom styles
1328
- *
1329
- * export default function (app) {
1330
- * app.use(HighchartsVue);
1331
- * }
1332
- * ```
1333
- *
1334
- * Install HighCharts into custom folder:
1335
- *
1336
- * ```bashcreating rec
1337
- * cd custom
1338
- * npm init -y
1339
- * npm install highcharts highcharts-vue
1340
- * ```
1341
- *
1342
- * And specify vueUsesFile in AdminForth config:
1343
- *
1344
- * ```ts
1345
- * vueUsesFile: '@@/vue-uses.ts',
1346
- * ```
1347
- *
1348
- */
1349
- vueUsesFile?: string;
1350
- /**
1351
- * 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
1352
- */
1353
- styles?: Object;
1354
- /**
1355
- * Description of custom pages which will let register custom pages for custom routes in AdminForth.
1356
- */
1357
- customPages?: Array<{
1358
- path: string;
1359
- component: AdminForthComponentDeclaration;
1360
- }>;
1361
- /**
1362
- * Function to return custom badge in side bar for users. Can return text or html
1363
- * If function is not passed or returns null, badge will not be shown.
1364
- * Execution is done on admin app load.
1365
- */
1366
- announcementBadge?: (user: AdminUser) => {
1367
- text?: string;
1368
- html?: string;
1369
- closable?: boolean;
1370
- title?: string;
1371
- } | null;
1372
- /**
1373
- * Custom panel components or array of components which will be displayed in the login form
1374
- * right after the inputs. Use it to add custom authorization methods like social login or other custom fields e.g. 'reset'
1375
- * password link.
1376
- */
1377
- loginPageInjections?: {
1378
- underInputs?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
1379
- };
1380
- /**
1381
- * Custom panel components or array of components which will be displayed in different parts of the admin panel.
1382
- */
1383
- globalInjections?: {
1384
- userMenu?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
1385
- header?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
1386
- sidebar?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>;
1387
- };
1388
- };
1389
- /**
1390
- * If you want to Serve AdminForth from a subdirectory, e.g. on example.com/backoffice, you can specify it like:
1391
- *
1392
- * ```ts
1393
- * baseUrl: '/backoffice',
1394
- * ```
1395
- *
1396
- */
1397
- baseUrl?: string;
1398
- /**
1399
- * Whether to show delete confirmation dialog before deleting record.
1400
- * By default it is true.
1401
- */
1402
- deleteConfirmation?: boolean;
1403
- };
1404
- export type FDataFilter = (field: string, value: any) => IAdminForthFilter;
1405
- export declare class Filters {
1406
- static EQ(field: string, value: any): IAdminForthFilter;
1407
- static NEQ(field: string, value: any): IAdminForthFilter;
1408
- static GT(field: string, value: any): IAdminForthFilter;
1409
- static GTE(field: string, value: any): IAdminForthFilter;
1410
- static LT(field: string, value: any): IAdminForthFilter;
1411
- static LTE(field: string, value: any): IAdminForthFilter;
1412
- static IN(field: string, value: any): IAdminForthFilter;
1413
- static NOT_IN(field: string, value: any): IAdminForthFilter;
1414
- static LIKE(field: string, value: any): IAdminForthFilter;
1415
- }
1416
- export type FDataSort = (field: string, direction: AdminForthSortDirections) => IAdminForthSort;
1417
- export declare class Sorts {
1418
- static ASC(field: string): IAdminForthSort;
1419
- static DESC(field: string): IAdminForthSort;
1420
- }
1421
- export interface IOperationalResource {
1422
- get: (filter: IAdminForthFilter | IAdminForthFilter[]) => Promise<any | null>;
1423
- list: (filter: IAdminForthFilter | IAdminForthFilter[], limit?: number, offset?: number, sort?: IAdminForthSort | IAdminForthSort[]) => Promise<any[]>;
1424
- count: (filter: IAdminForthFilter | IAdminForthFilter[] | undefined) => Promise<number>;
1425
- create: (record: any) => Promise<{
1426
- ok: boolean;
1427
- createdRecord: any;
1428
- error?: string;
1429
- }>;
1430
- update: (primaryKey: any, record: any) => Promise<any>;
1431
- delete: (primaryKey: any) => Promise<boolean>;
1432
- }
1433
- export declare enum AllowedActionsEnum {
1434
- show = "show",
1435
- list = "list",
1436
- edit = "edit",
1437
- create = "create",
1438
- delete = "delete",
1439
- filter = "filter"
1440
- }
1441
- /**
1442
- * Defines whether user has access to an action, can statically be Boolean
1443
- * or function which returns Boolean or string with error message
1444
- *
1445
- */
1446
- export type AllowedActionValue = boolean | (({ adminUser, resource, meta, source }: {
1447
- adminUser: AdminUser;
1448
- resource: AdminForthResource;
1449
- /**
1450
- * Meta object which will pass request information just in case
1451
- */
1452
- meta: any;
1453
- /**
1454
- * Source of the check
1455
- */
1456
- source: ActionCheckSource;
1457
- }) => Promise<boolean | string>);
1458
- export declare enum ActionCheckSource {
1459
- DisplayButtons = "displayButtons",
1460
- ListRequest = "listRequest",
1461
- ShowRequest = "showRequest",
1462
- EditRequest = "editRequest",
1463
- CreateRequest = "createRequest",
1464
- DeleteRequest = "deleteRequest",
1465
- BulkActionRequest = "bulkActionRequest"
1466
- }
1467
- /**
1468
- * Object which describes allowed actions for user.
1469
- */
1470
- export type AllowedActions = {
1471
- [key in AllowedActionsEnum]?: AllowedActionValue;
1472
- } & {
1473
- all?: AllowedActionValue;
1474
- };
1475
- export type AllowedActionsResolved = {
1476
- [key in AllowedActionsEnum]?: boolean;
1477
- };
1478
- export type ValidationObject = {
1479
- /**
1480
- * Should be pure string (not RegExp string)
1481
- *
1482
- * Example:
1483
- *
1484
- * ```ts
1485
- * // regex for email
1486
- * regExp: '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$',
1487
- * ```
1488
- *
1489
- */
1490
- regExp: string;
1491
- /**
1492
- * Error message shown to user if validation fails
1493
- *
1494
- * Example: "Invalid email format"
1495
- */
1496
- message: string;
1497
- /**
1498
- * Whether to check case sensitivity (i flag)
1499
- */
1500
- caseSensitive?: boolean;
1501
- /**
1502
- * Whether to check Multiline strings (m flag)
1503
- */
1504
- multiline?: boolean;
1505
- /**
1506
- * Whether to check global strings (g flag)
1507
- */
1508
- global?: boolean;
1509
- };
1510
- export type AdminForthComponentDeclarationFull = {
1511
- /**
1512
- * Path to custom component which will be used to render field in the admin panel.
1513
- * e.g. `@@/MyCustomComponent.vue`
1514
- */
1515
- file: string;
1516
- /**
1517
- * Optional Meta object which will be passed to custom component as props. For example used by plugins
1518
- * to pass plugin options to custom components.
1519
- *
1520
- * Example:
1521
- *
1522
- * ```ts
1523
- * {
1524
- * name: 'Country Flag',
1525
- * virtual: true,
1526
- * showIn: [AdminForthResourcePages.SHOW],
1527
- * components: {
1528
- * show: {
1529
- * file: '@@/Flag.vue',
1530
- * meta: {
1531
- * flagType: 'country',
1532
- * },
1533
- * },
1534
- * },
1535
- * },
1536
- * {
1537
- * name: 'Team Flag',
1538
- * virtual: true,
1539
- * showIn: [AdminForthResourcePages.SHOW],
1540
- * components: {
1541
- * show: {
1542
- * file: '@@/Flag.vue',
1543
- * meta: {
1544
- * flagType: 'team',
1545
- * },
1546
- * },
1547
- * },
1548
- * }
1549
- * ```
1550
- *
1551
- * In Flag.vue you can access this meta object like this:
1552
- *
1553
- * ```html
1554
- * <template>
1555
- * <img :src="loadFile(`@@/flags/${meta.flagType}/${meta.flagType === 'country' ? record.countryIso : record.teamCode}.png`)" />
1556
- * </template>
1557
- *
1558
- * <script setup>
1559
- * import { loadFile } from '@/utils';
1560
- * defineProps(['meta', 'record']);
1561
- * </script>
1562
- *
1563
- */
1564
- meta?: any;
1565
- };
1566
- export type AdminForthComponentDeclaration = AdminForthComponentDeclarationFull | string;
1567
- export type AdminForthFieldComponents = {
1568
- /**
1569
- * Show component is used to redefine cell which renders field value in show view.
1570
- * Component accepts next properties: [record, column, resource, adminUser, meta].
1571
- *
1572
- * Example: `FullName.vue`
1573
- *
1574
- * ```html
1575
- * <template>
1576
- * {{ record.firstName }} {{ record.lastName }}
1577
- * </template>
1578
- *
1579
- * <script setup>
1580
- * defineProps(['record']);
1581
- * </script>
1582
- *
1583
- * ```ts
1584
- * {
1585
- * label: 'Full Name',
1586
- * virtual: true,
1587
- * showIn: [AdminForthResourcePages.SHOW, AdminForthResourcePages.LIST],
1588
- * components: {
1589
- * show: '@@/FullName.vue',
1590
- * list: '@@/FullName.vue',
1591
- * },
1592
- * }
1593
- * ```
1594
- *
1595
- */
1596
- show?: AdminForthComponentDeclaration;
1597
- /**
1598
- * showRow component is similar to {@link AdminForthFieldComponent.show} but rewrites full table row (both \<td\> tags)
1599
- * Accepts next properties: [record, column, resource, adminUser]
1600
- */
1601
- showRow?: AdminForthComponentDeclaration;
1602
- /**
1603
- * Create component is used to redefine input field in create view.
1604
- * Component accepts next properties: [record, column, resource, adminUser].
1605
- */
1606
- create?: AdminForthComponentDeclaration;
1607
- /**
1608
- * Edit component is used to redefine input field in edit view.
1609
- * Component accepts next properties: [record, column, resource, adminUser].
1610
- */
1611
- edit?: AdminForthComponentDeclaration;
1612
- /**
1613
- * List component is used to redefine cell which renders field value in list view.
1614
- * Component accepts next properties: [record, column, resource, adminUser].
1615
- * Component can emit events:
1616
- * - `update:value` - to update record value.
1617
- * - `update:inValidity` - emit true once entered value became not valid (e.g. emit('update:inValidity', true) ). Emit false once entered value became valid. Emit default value in mounted hook.
1618
- * - `update:emptiness` - emit true once entered value became empty (e.g. emit('update:emptiness', true) ). Emit false once entered value became not empty. Emit default value in mounted hook.
1619
- * emptiness emit is optional and required for complex cases. For example for virtual columns where initial value is not set.
1620
- */
1621
- list?: AdminForthComponentDeclaration;
1622
- };
1623
- export declare enum AdminForthDataTypes {
1624
- STRING = "string",
1625
- INTEGER = "integer",
1626
- FLOAT = "float",
1627
- DECIMAL = "decimal",
1628
- BOOLEAN = "boolean",
1629
- DATE = "date",
1630
- DATETIME = "datetime",
1631
- TIME = "time",
1632
- TEXT = "text",
1633
- JSON = "json",
1634
- RICHTEXT = "richtext"
1635
- }
1636
- export declare enum AdminForthFilterOperators {
1637
- EQ = "eq",
1638
- NE = "ne",
1639
- GT = "gt",
1640
- LT = "lt",
1641
- GTE = "gte",
1642
- LTE = "lte",
1643
- LIKE = "like",
1644
- ILIKE = "ilike",
1645
- IN = "in",
1646
- NIN = "nin"
1647
- }
1648
- export declare enum AdminForthSortDirections {
1649
- asc = "asc",
1650
- desc = "desc"
1651
- }
1652
- export type AdminForthColumnEnumItem = {
1653
- value: any | null;
1654
- label: string;
1655
- };
1656
- export type AdminForthForeignResource = {
1657
- resourceId: string;
1658
- hooks?: {
1659
- dropdownList?: {
1660
- beforeDatasourceRequest?: BeforeDataSourceRequestFunction | Array<BeforeDataSourceRequestFunction>;
1661
- afterDatasourceResponse?: AfterDataSourceResponseFunction | Array<AfterDataSourceResponseFunction>;
1662
- };
1663
- };
1664
- };
1665
- //# sourceMappingURL=AdminForthConfig.d.ts.map