adminforth 1.3.54-next.8 → 1.3.55-next.0

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