adminforth 1.1.73 → 1.1.75

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 (122) hide show
  1. package/auth.ts +14 -0
  2. package/dataConnectors/baseConnector.ts +107 -0
  3. package/dataConnectors/mongo.ts +6 -12
  4. package/dataConnectors/postgres.ts +17 -37
  5. package/dataConnectors/sqlite.ts +44 -55
  6. package/dist/auth.js +7 -0
  7. package/dist/dataConnectors/baseConnector.js +90 -0
  8. package/dist/dataConnectors/mongo.js +6 -12
  9. package/dist/dataConnectors/postgres.js +12 -33
  10. package/dist/dataConnectors/sqlite.js +67 -83
  11. package/dist/index.js +125 -66
  12. package/dist/modules/codeInjector.js +29 -15
  13. package/dist/plugins/AuditLogPlugin/index.js +2 -17
  14. package/dist/plugins/S3UploadPlugin/custom/s3uploader.vue +120 -0
  15. package/dist/plugins/S3UploadPlugin/index.js +103 -0
  16. package/dist/plugins/S3UploadPlugin/package-lock.json +431 -0
  17. package/dist/plugins/S3UploadPlugin/package.json +15 -0
  18. package/dist/plugins/TwoFactorsAuthPlugin/custom/TwoFactorsConfirmation.vue +152 -0
  19. package/dist/plugins/TwoFactorsAuthPlugin/custom/TwoFactorsSetup.vue +188 -0
  20. package/dist/plugins/TwoFactorsAuthPlugin/index.js +150 -0
  21. package/dist/plugins/TwoFactorsAuthPlugin/types.js +1 -0
  22. package/dist/spa/index.html +1 -1
  23. package/dist/spa/package-lock.json +111 -0
  24. package/dist/spa/package.json +1 -0
  25. package/dist/spa/src/App.vue +178 -133
  26. package/dist/spa/src/components/MenuLink.vue +3 -3
  27. package/dist/spa/src/components/ResourceForm.vue +96 -96
  28. package/dist/spa/src/components/ResourceListTable.vue +69 -84
  29. package/dist/spa/src/components/ValueRenderer.vue +2 -3
  30. package/dist/spa/src/composables/useStores.ts +24 -11
  31. package/dist/spa/src/main.ts +1 -1
  32. package/dist/spa/src/router/index.ts +0 -1
  33. package/dist/spa/src/utils.ts +1 -1
  34. package/dist/spa/src/views/CreateView.vue +1 -9
  35. package/dist/spa/src/views/EditView.vue +1 -9
  36. package/dist/spa/src/views/ListView.vue +12 -3
  37. package/dist/spa/src/views/LoginView.vue +6 -1
  38. package/dist/spa/src/views/ResourceParent.vue +1 -2
  39. package/dist/spa/src/views/ShowView.vue +6 -14
  40. package/dist/spa/tailwind.config.js +3 -1
  41. package/index.ts +103 -36
  42. package/modules/codeInjector.ts +38 -27
  43. package/package.json +2 -1
  44. package/plugins/AuditLogPlugin/index.ts +4 -20
  45. package/plugins/S3UploadPlugin/custom/s3uploader.vue +120 -0
  46. package/plugins/S3UploadPlugin/index.ts +112 -0
  47. package/plugins/S3UploadPlugin/package-lock.json +431 -0
  48. package/plugins/S3UploadPlugin/package.json +15 -0
  49. package/plugins/S3UploadPlugin/types.ts +76 -0
  50. package/plugins/TwoFactorsAuthPlugin/custom/TwoFactorsConfirmation.vue +152 -0
  51. package/plugins/TwoFactorsAuthPlugin/custom/TwoFactorsOtp.vue +0 -0
  52. package/plugins/TwoFactorsAuthPlugin/custom/TwoFactorsSetup.vue +188 -0
  53. package/plugins/TwoFactorsAuthPlugin/index.ts +150 -0
  54. package/plugins/TwoFactorsAuthPlugin/types.ts +10 -0
  55. package/servers/express.ts +1 -0
  56. package/spa/src/App.vue +154 -121
  57. package/spa/src/components/ResourceForm.vue +91 -91
  58. package/spa/src/router/index.ts +0 -1
  59. package/spa/src/utils.ts +1 -1
  60. package/spa/src/views/CreateView.vue +0 -1
  61. package/spa/src/views/LoginView.vue +4 -1
  62. package/types/AdminForthConfig.ts +166 -5
  63. package/dist/plugins/AuditLog/index.js +0 -13
  64. package/dist/spa/spa/.eslintrc.cjs +0 -14
  65. package/dist/spa/spa/.vscode/extensions.json +0 -6
  66. package/dist/spa/spa/README.md +0 -39
  67. package/dist/spa/spa/env.d.ts +0 -1
  68. package/dist/spa/spa/index.html +0 -23
  69. package/dist/spa/spa/package-lock.json +0 -4470
  70. package/dist/spa/spa/package.json +0 -48
  71. package/dist/spa/spa/postcss.config.js +0 -6
  72. package/dist/spa/spa/public/assets/favicon.png +0 -0
  73. package/dist/spa/spa/src/App.vue +0 -283
  74. package/dist/spa/spa/src/assets/logo.svg +0 -19
  75. package/dist/spa/spa/src/components/AcceptModal.vue +0 -45
  76. package/dist/spa/spa/src/components/Breadcrumbs.vue +0 -40
  77. package/dist/spa/spa/src/components/BreadcrumbsWithButtons.vue +0 -26
  78. package/dist/spa/spa/src/components/CustomDatePicker.vue +0 -174
  79. package/dist/spa/spa/src/components/CustomDateRangePicker.vue +0 -218
  80. package/dist/spa/spa/src/components/CustomRangePicker.vue +0 -148
  81. package/dist/spa/spa/src/components/Dropdown.vue +0 -168
  82. package/dist/spa/spa/src/components/Filters.vue +0 -211
  83. package/dist/spa/spa/src/components/HelloWorld.vue +0 -17
  84. package/dist/spa/spa/src/components/MenuLink.vue +0 -24
  85. package/dist/spa/spa/src/components/ResourceForm.vue +0 -265
  86. package/dist/spa/spa/src/components/ResourceListTable.vue +0 -404
  87. package/dist/spa/spa/src/components/SingleSkeletLoader.vue +0 -13
  88. package/dist/spa/spa/src/components/Toast.vue +0 -66
  89. package/dist/spa/spa/src/components/ValueRenderer.vue +0 -59
  90. package/dist/spa/spa/src/components/icons/IconCalendar.vue +0 -5
  91. package/dist/spa/spa/src/components/icons/IconCommunity.vue +0 -7
  92. package/dist/spa/spa/src/components/icons/IconDocumentation.vue +0 -7
  93. package/dist/spa/spa/src/components/icons/IconEcosystem.vue +0 -7
  94. package/dist/spa/spa/src/components/icons/IconSupport.vue +0 -7
  95. package/dist/spa/spa/src/components/icons/IconTime.vue +0 -5
  96. package/dist/spa/spa/src/components/icons/IconTooling.vue +0 -19
  97. package/dist/spa/spa/src/composables/useFrontendApi.ts +0 -26
  98. package/dist/spa/spa/src/composables/useStores.ts +0 -126
  99. package/dist/spa/spa/src/index.scss +0 -26
  100. package/dist/spa/spa/src/main.ts +0 -18
  101. package/dist/spa/spa/src/router/index.ts +0 -64
  102. package/dist/spa/spa/src/spa_types/core.ts +0 -51
  103. package/dist/spa/spa/src/stores/core.ts +0 -144
  104. package/dist/spa/spa/src/stores/filters.ts +0 -22
  105. package/dist/spa/spa/src/stores/modal.ts +0 -48
  106. package/dist/spa/spa/src/stores/toast.ts +0 -15
  107. package/dist/spa/spa/src/stores/user.ts +0 -54
  108. package/dist/spa/spa/src/utils.ts +0 -101
  109. package/dist/spa/spa/src/views/CreateView.vue +0 -156
  110. package/dist/spa/spa/src/views/EditView.vue +0 -157
  111. package/dist/spa/spa/src/views/ListView.vue +0 -266
  112. package/dist/spa/spa/src/views/LoginView.vue +0 -136
  113. package/dist/spa/spa/src/views/ResourceParent.vue +0 -17
  114. package/dist/spa/spa/src/views/ShowView.vue +0 -180
  115. package/dist/spa/spa/tailwind.config.js +0 -17
  116. package/dist/spa/spa/tsconfig.app.json +0 -14
  117. package/dist/spa/spa/tsconfig.json +0 -11
  118. package/dist/spa/spa/tsconfig.node.json +0 -19
  119. package/dist/spa/spa/vite.config.ts +0 -49
  120. /package/dist/plugins/{AuditLog → S3UploadPlugin}/types.js +0 -0
  121. /package/dist/{spa/spa/src/assets/base.css → plugins/TwoFactorsAuthPlugin/custom/TwoFactorsOtp.vue} +0 -0
  122. /package/dist/spa/{spa/src → src}/components/SkeleteLoader.vue +0 -0
@@ -82,9 +82,113 @@ export interface AdminForthDataSourceConnector {
82
82
  /**
83
83
  * Function which will be called to fetch record from database.
84
84
  */
85
+ getRecordByPrimaryKeyWithOriginalTypes(resource: AdminForthResource, recordId: string): Promise<any>;
86
+
87
+
88
+ /**
89
+ * Function should go over all columns of table defined in resource.table and try to guess
90
+ * data and constraints for each columns.
91
+ * Type should be saved to:
92
+ * - {@link AdminForthResourceColumn.type}
93
+ * Constraints:
94
+ * - {@link AdminForthResourceColumn.required}
95
+ * - {@link AdminForthResourceColumn.primaryKey}
96
+ * For string fields:
97
+ * - {@link AdminForthResourceColumn.maxLength}
98
+ * For numbers:
99
+ * - {@link AdminForthResourceColumn.min}
100
+ * - {@link AdminForthResourceColumn.max}
101
+ * - {@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})
102
+ * Also you can additionally save original column type to {@link AdminForthResourceColumn._underlineType}. This might be later used
103
+ * in {@link AdminForthDataSourceConnector.getFieldValue} and {@link AdminForthDataSourceConnector.setFieldValue} methods.
104
+ *
105
+ *
106
+ * @param resource
107
+ */
108
+ discoverFields(resource: AdminForthResource): Promise<{[key: string]: AdminForthResourceColumn}>;
109
+
110
+
111
+ /**
112
+ * Used to transform record after fetching from database.
113
+ * According to AdminForth convention, if {@link AdminForthResourceColumn.type} is set to {@link AdminForthDataTypes.DATETIME} then it should be transformed to ISO string.
114
+ * @param field
115
+ * @param value
116
+ */
117
+ getFieldValue(field: AdminForthResourceColumn, value: any): any;
118
+
119
+ /**
120
+ * Used to transform record before saving to database. Should perform operation inverse to {@link AdminForthDataSourceConnector.getFieldValue}
121
+ * @param field
122
+ * @param value
123
+ */
124
+ setFieldValue(field: AdminForthResourceColumn, value: any): any;
125
+
126
+ /**
127
+ * Used to fetch data from database.
128
+ * This method is reused both to list records and show one record (by passing limit 1 and offset 0) .
129
+ *
130
+ * Fields are returned from db "as is" then {@link AdminForthBaseConnector.getData} will transform each field using {@link AdminForthDataSourceConnector.getFieldValue}
131
+ */
132
+ getDataWithOriginalTypes({ resource, limit, offset, sort, filters }: {
133
+ resource: AdminForthResource,
134
+ limit: number,
135
+ offset: number,
136
+ sort: { field: string, direction: AdminForthSortDirections }[],
137
+ filters: { field: string, operator: AdminForthFilterOperators, value: any }[]
138
+ }): Promise<{data: Array<any>, total: number}>;
139
+
140
+
141
+ /**
142
+ * Optional method which used to get min and max values for columns in resource.
143
+ * Called only for columns which have {@link AdminForthResourceColumn.allowMinMaxQuery} set to true.
144
+ *
145
+ * Internally should call {@link AdminForthDataSourceConnector.getFieldValue} for both min and max values.
146
+ */
147
+ getMinMaxForColumnsWithOriginalTypes({ resource, columns }: { resource: AdminForthResource, columns: AdminForthResourceColumn[] }): Promise<{ [key: string]: { min: any, max: any } }>;
148
+
149
+
150
+ /**
151
+ * Used to create record in database.
152
+ */
153
+ createRecord({ resource, record }: { resource: AdminForthResource, record: any }): Promise<void>;
154
+
155
+ /**
156
+ * Used to update record in database.
157
+ * recordId is value of field which is marked as {@link AdminForthResourceColumn.primaryKey}
158
+ * newValues is array of fields which should be updated (might be not all fields in record, but only changed fields).
159
+ */
160
+ updateRecord({ resource, recordId, newValues }:
161
+ { resource: AdminForthResource, recordId: string, newValues: any }
162
+ ): Promise<void>;
163
+
164
+ /**
165
+ * Used to delete record in database.
166
+ */
167
+ deleteRecord({ resource, recordId }: { resource: AdminForthResource, recordId: any }): Promise<void>;
168
+ }
169
+
170
+
171
+ /**
172
+ * Interface that exposes methods to interact with AdminForth in standard way
173
+ */
174
+ export interface AdminForthDataSourceConnectorBase extends AdminForthDataSourceConnector {
175
+
176
+ getPrimaryKey(resource: AdminForthResource): string;
177
+
178
+ getData({ resource, limit, offset, sort, filters }: {
179
+ resource: AdminForthResource,
180
+ limit: number,
181
+ offset: number,
182
+ sort: { field: string, direction: AdminForthSortDirections }[],
183
+ filters: { field: string, operator: AdminForthFilterOperators, value: any }[]
184
+ }): Promise<{ data: Array<any>, total: number }>;
185
+
85
186
  getRecordByPrimaryKey(resource: AdminForthResource, recordId: string): Promise<any>;
187
+
188
+ getMinMaxForColumns({ resource, columns }: { resource: AdminForthResource, columns: AdminForthResourceColumn[] }): Promise<{ [key: string]: { min: any, max: any } }>;
86
189
  }
87
190
 
191
+
88
192
  export interface AdminForthDataSourceConnectorConstructor {
89
193
  new ({ url }: { url: string }): AdminForthDataSourceConnector;
90
194
  }
@@ -95,14 +199,13 @@ export interface AdminForthClass {
95
199
  express: GenericHttpServer;
96
200
 
97
201
  connectors: {
98
- [key: string]: AdminForthDataSourceConnector,
202
+ [key: string]: AdminForthDataSourceConnectorBase;
99
203
  };
100
204
 
101
205
  createResourceRecord(params: { resource: AdminForthResource, record: any, adminUser: AdminUser }): Promise<any>;
102
206
 
103
207
  auth: {
104
208
  verify(jwt : string, mustHaveType: string): Promise<any>;
105
-
106
209
  issueJWT(payload: Object, type: string): string;
107
210
  }
108
211
 
@@ -425,21 +528,57 @@ export type AdminForthResourceColumn = {
425
528
  * Custom components which will be used to render this field in the admin panel.
426
529
  */
427
530
  components?: AdminForthFieldComponents
531
+
532
+ /**
533
+ * Maximum length of string that can be entered in this field.
534
+ */
428
535
  maxLength?: number,
536
+
537
+ /**
538
+ * Minimum length of string that can be entered in this field.
539
+ */
429
540
  minLength?: number,
541
+
430
542
  min?: number,
431
543
  max?: number,
544
+
545
+ /**
546
+ * Minimum value that can be entered in this field.
547
+ */
432
548
  minValue?: number,
549
+
550
+ /**
551
+ * Maximum value that can be entered in this field.
552
+ */
433
553
  maxValue?: number,
554
+
555
+ /**
556
+ * Enum of possible values for this field.
557
+ */
434
558
  enum?: Array<AdminForthColumnEnumItem>,
559
+
560
+ /**
561
+ * Foreign resource which has pk column with values same that written in this column.
562
+ */
435
563
  foreignResource?:AdminForthForeignResource,
564
+
436
565
  sortable?: boolean,
437
- backendOnly?: boolean, // if true field will not be passed to UI under no circumstances, but will be presented in hooks
566
+
567
+ /**
568
+ * if true field will !not be passed to UI under no circumstances, but will be presented in hooks
569
+ */
570
+ backendOnly?: boolean,
438
571
 
439
572
  /**
440
573
  * Masked fields will be displayed as `*****` on Edit and Create pages.
441
574
  */
442
575
  masked?: boolean,
576
+
577
+
578
+ /**
579
+ * Internal type which indicates original type of column in database.
580
+ */
581
+ _underlineType?: string,
443
582
  }
444
583
 
445
584
 
@@ -467,11 +606,17 @@ export type BeforeSaveFunction = (params:{resource: AdminForthResource, adminUse
467
606
  */
468
607
  export type AfterSaveFunction = (params: {resource: AdminForthResource, adminUser: AdminUser, record: any}) => Promise<{ok: boolean, error?: string}>;
469
608
 
609
+ /**
610
+ * Allow to get user data before login confirmation, will triger when user try to login.
611
+ */
612
+ export type BeforeLoginConfirmationFunction = (params?: { userRecord: AdminUser }) => Promise<{ok:boolean, error?:string, body:{setCookie?:[], redirectTo?: 'string', allowedLogin?: boolean }}>;
470
613
 
471
614
  /**
472
615
  * Resource describes one table or collection in database.
473
616
  * AdminForth generates set of pages for 'list', 'show', 'edit', 'create', 'filter' operations for each resource.
474
617
  */
618
+
619
+
475
620
  export type AdminForthResource = {
476
621
  /**
477
622
  * Unique identifier of resource. By default it equals to table name in database.
@@ -706,6 +851,13 @@ export type AdminForthConfig = {
706
851
  */
707
852
  loginBackgroundImage?: string,
708
853
 
854
+ /**
855
+ * Function or functions which will be called before user try to login.
856
+ * Each function will resive User object as an argument
857
+ */
858
+
859
+ beforeLoginConfirmation?: BeforeLoginConfirmationFunction | Array<BeforeLoginConfirmationFunction>,
860
+
709
861
  /**
710
862
  * Optionally if your users table has a field(column) with full name, you can set it here.
711
863
  * This field will be used to display user name in the top right corner of the admin panel.
@@ -845,7 +997,15 @@ export type AdminForthConfig = {
845
997
  * 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
846
998
  */
847
999
  styles?: Object,
848
- },
1000
+ /**
1001
+ * Description of custom pages which will let register custom pages for custom routes in AdminForth.
1002
+ */
1003
+
1004
+ customPages?: Array<{
1005
+ path: string,
1006
+ component: AdminForthComponentDeclaration,
1007
+ }>,
1008
+ }
849
1009
 
850
1010
  /**
851
1011
  * If you want to Serve AdminForth from a subdirectory, e.g. on example.com/backoffice, you can specify it like:
@@ -1095,4 +1255,5 @@ export type AdminForthForeignResource = {
1095
1255
  afterDatasourceResponse?: AfterDataSourceResponseFunction | Array<AfterDataSourceResponseFunction>,
1096
1256
  },
1097
1257
  },
1098
- }
1258
+ }
1259
+
@@ -1,13 +0,0 @@
1
- import AdminForthPlugin from "../base.js";
2
- class AuditLogPlugin extends AdminForthPlugin {
3
- constructor(options) {
4
- super(options, import.meta.url);
5
- this.options = options;
6
- }
7
- modifyResourceConfig(adminforth, resourceConfig) {
8
- super.modifyResourceConfig(adminforth, resourceConfig);
9
- this.adminforth = adminforth;
10
- }
11
- }
12
- AuditLogPlugin.defaultError = 'Sorry, you do not have access to this resource.';
13
- export default AuditLogPlugin;
@@ -1,14 +0,0 @@
1
- /* eslint-env node */
2
- require('@rushstack/eslint-patch/modern-module-resolution')
3
-
4
- module.exports = {
5
- root: true,
6
- 'extends': [
7
- 'plugin:vue/vue3-essential',
8
- 'eslint:recommended',
9
- '@vue/eslint-config-typescript'
10
- ],
11
- parserOptions: {
12
- ecmaVersion: 'latest'
13
- }
14
- }
@@ -1,6 +0,0 @@
1
- {
2
- "recommendations": [
3
- "Vue.volar",
4
- "dbaeumer.vscode-eslint"
5
- ]
6
- }
@@ -1,39 +0,0 @@
1
- # spa
2
-
3
- This template should help get you started developing with Vue 3 in Vite.
4
-
5
- ## Recommended IDE Setup
6
-
7
- [VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
8
-
9
- ## Type Support for `.vue` Imports in TS
10
-
11
- TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types.
12
-
13
- ## Customize configuration
14
-
15
- See [Vite Configuration Reference](https://vitejs.dev/config/).
16
-
17
- ## Project Setup
18
-
19
- ```sh
20
- npm install
21
- ```
22
-
23
- ### Compile and Hot-Reload for Development
24
-
25
- ```sh
26
- npm run dev
27
- ```
28
-
29
- ### Type-Check, Compile and Minify for Production
30
-
31
- ```sh
32
- npm run build
33
- ```
34
-
35
- ### Lint with [ESLint](https://eslint.org/)
36
-
37
- ```sh
38
- npm run lint
39
- ```
@@ -1 +0,0 @@
1
- /// <reference types="vite/client" />
@@ -1,23 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <link rel="icon" href="/* IMPORTANT:ADMINFORTH FAVICON */">
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
- <title>/* IMPORTANT:ADMINFORTH TITLE */</title>
8
- <!--
9
- <script>
10
- // On page load or when changing themes, best to add inline in `head` to avoid FOUC
11
- if (localStorage.getItem('color-theme') === 'dark' || (!('color-theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
12
- document.documentElement.classList.add('dark');
13
- } else {
14
- document.documentElement.classList.remove('dark')
15
- }
16
- </script> -->
17
-
18
- </head>
19
- <body class=" ">
20
- <div id="app" class="min-h-screen bg-lightHtml dark:bg-darkHtml"></div>
21
- <script type="module" src="/src/main.ts"></script>
22
- </body>
23
- </html>