adminforth 1.2.99 → 1.2.100
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.
- package/auth.ts +6 -5
- package/dataConnectors/baseConnector.ts +65 -7
- package/dataConnectors/clickhouse.ts +1 -0
- package/dataConnectors/mongo.ts +3 -4
- package/dataConnectors/sqlite.ts +7 -0
- package/dist/auth.js +6 -6
- package/dist/dataConnectors/baseConnector.js +59 -10
- package/dist/dataConnectors/clickhouse.js +1 -0
- package/dist/dataConnectors/mongo.js +3 -4
- package/dist/dataConnectors/sqlite.js +10 -0
- package/dist/index.js +50 -34
- package/dist/modules/configValidator.js +25 -16
- package/dist/modules/operationalResource.js +25 -25
- package/dist/modules/restApi.js +106 -96
- package/dist/modules/utils.js +16 -0
- package/index.ts +68 -43
- package/modules/configValidator.ts +26 -21
- package/modules/operationalResource.ts +39 -45
- package/modules/restApi.ts +91 -80
- package/modules/utils.ts +20 -0
- package/package.json +3 -2
- package/spa/src/App.vue +12 -9
- package/spa/src/components/Filters.vue +1 -1
- package/spa/src/components/ResourceForm.vue +7 -4
- package/spa/src/components/ResourceListTable.vue +124 -112
- package/spa/src/components/SkeleteLoader.vue +4 -4
- package/spa/src/components/ValueRenderer.vue +1 -1
- package/spa/src/router/index.ts +0 -8
- package/spa/src/spa_types/core.ts +1 -0
- package/spa/src/stores/filters.ts +3 -2
- package/spa/src/views/ListView.vue +16 -25
- package/spa/src/views/LoginView.vue +26 -9
- package/types/AdminForthConfig.ts +54 -33
|
@@ -51,16 +51,18 @@ export interface IHttpServer {
|
|
|
51
51
|
|
|
52
52
|
export type AdminUser = {
|
|
53
53
|
/**
|
|
54
|
-
* primaryKey field value of user in table which is defined by {@link AdminForthConfig.auth.
|
|
55
|
-
* or null if it is user logged in as {@link AdminForthConfig.rootUser}
|
|
54
|
+
* primaryKey field value of user in table which is defined by {@link AdminForthConfig.auth.usersResourceId}
|
|
56
55
|
*/
|
|
57
56
|
pk: string | null,
|
|
58
57
|
|
|
59
58
|
/**
|
|
60
|
-
* Username which
|
|
59
|
+
* Username which taken from {@link AdminForthConfig.auth.usernameField} field in user resource {@link AdminForthConfig.auth.usersResourceId}
|
|
61
60
|
*/
|
|
62
61
|
username: string,
|
|
63
|
-
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* User record fetched from database, from resource defined in {@link AdminForthConfig.auth.usersResourceId}
|
|
65
|
+
*/
|
|
64
66
|
dbUser: any,
|
|
65
67
|
}
|
|
66
68
|
|
|
@@ -220,7 +222,11 @@ export interface IAdminForthDataSourceConnectorBase extends IAdminForthDataSourc
|
|
|
220
222
|
|
|
221
223
|
getRecordByPrimaryKey(resource: AdminForthResource, recordId: string): Promise<any>;
|
|
222
224
|
|
|
223
|
-
createRecord({ resource, record }: {
|
|
225
|
+
createRecord({ resource, record, adminUser }: {
|
|
226
|
+
resource: AdminForthResource,
|
|
227
|
+
record: any
|
|
228
|
+
adminUser: AdminUser
|
|
229
|
+
}): Promise<{ok: boolean, error?: string, createdRecord?: any}>;
|
|
224
230
|
|
|
225
231
|
getMinMaxForColumns({ resource, columns }: { resource: AdminForthResource, columns: AdminForthResourceColumn[] }): Promise<{ [key: string]: { min: any, max: any } }>;
|
|
226
232
|
}
|
|
@@ -258,7 +264,9 @@ export interface IAdminForth {
|
|
|
258
264
|
[key: string]: IAdminForthDataSourceConnectorBase;
|
|
259
265
|
};
|
|
260
266
|
|
|
261
|
-
createResourceRecord(
|
|
267
|
+
createResourceRecord(
|
|
268
|
+
params: { resource: AdminForthResource, record: any, adminUser: AdminUser }
|
|
269
|
+
): Promise<{ ok: boolean, error?: string, createdRecord?: any }>;
|
|
262
270
|
|
|
263
271
|
auth: IAdminForthAuth;
|
|
264
272
|
|
|
@@ -563,6 +571,10 @@ export type AdminForthResourceColumn = {
|
|
|
563
571
|
*/
|
|
564
572
|
isUnique?: boolean,
|
|
565
573
|
|
|
574
|
+
/**
|
|
575
|
+
* Will automatically convert any capital letters to lowercase in input during editing
|
|
576
|
+
*/
|
|
577
|
+
enforceLowerCase?: boolean,
|
|
566
578
|
|
|
567
579
|
/**
|
|
568
580
|
* Runtime validation Regexp rules for this field.
|
|
@@ -684,13 +696,13 @@ export type AfterDataSourceResponseFunction = (params: {resource: AdminForthReso
|
|
|
684
696
|
* Modify record to change how data is saved to database.
|
|
685
697
|
* Return ok: false and error: string to stop execution and show error message to user. Return ok: true to continue execution.
|
|
686
698
|
*/
|
|
687
|
-
export type BeforeSaveFunction = (params:{resource: AdminForthResource, adminUser: AdminUser, record: any}) => Promise<{ok: boolean, error?: string}>;
|
|
699
|
+
export type BeforeSaveFunction = (params: {resource: AdminForthResource, recordId: any, adminUser: AdminUser, record: any}) => Promise<{ok: boolean, error?: string}>;
|
|
688
700
|
|
|
689
701
|
/**
|
|
690
702
|
* Modify record to change how data is saved to database.
|
|
691
703
|
* Return ok: false and error: string to stop execution and show error message to user. Return ok: true to continue execution.
|
|
692
704
|
*/
|
|
693
|
-
export type AfterSaveFunction = (params: {resource: AdminForthResource, adminUser: AdminUser, record: any}) => Promise<{ok: boolean, error?: string}>;
|
|
705
|
+
export type AfterSaveFunction = (params: {resource: AdminForthResource, recordId: any, adminUser: AdminUser, record: any}) => Promise<{ok: boolean, error?: string}>;
|
|
694
706
|
|
|
695
707
|
/**
|
|
696
708
|
* Allow to get user data before login confirmation, will triger when user try to login.
|
|
@@ -744,7 +756,7 @@ export type AdminForthBulkAction = {
|
|
|
744
756
|
*
|
|
745
757
|
* ```ts
|
|
746
758
|
* allowed: async ({ resource, adminUser, selectedIds }) => {
|
|
747
|
-
* if (adminUser.
|
|
759
|
+
* if (adminUser.dbUser.role !== 'superadmin') {
|
|
748
760
|
* return false;
|
|
749
761
|
* }
|
|
750
762
|
* return true;
|
|
@@ -786,7 +798,7 @@ export type AdminForthBulkAction = {
|
|
|
786
798
|
* ],
|
|
787
799
|
* allowedActions: \{
|
|
788
800
|
* edit: (\{ resource, adminUser, recordIds \}) => \{
|
|
789
|
-
* return adminUser.
|
|
801
|
+
* return adminUser.dbUser.role === 'superadmin';
|
|
790
802
|
* \}
|
|
791
803
|
* \}
|
|
792
804
|
* \}
|
|
@@ -979,8 +991,8 @@ export type AdminForthResource = {
|
|
|
979
991
|
* ```ts
|
|
980
992
|
* allowedActions: {
|
|
981
993
|
* create: ({ resource, adminUser }) => {
|
|
982
|
-
* // Allow only superadmin
|
|
983
|
-
* return adminUser.
|
|
994
|
+
* // Allow only superadmin to create records
|
|
995
|
+
* return adminUser.dbUser.role === 'superadmin';
|
|
984
996
|
* },
|
|
985
997
|
* delete: false, // disable delete action for all users
|
|
986
998
|
* }
|
|
@@ -1085,33 +1097,21 @@ export type AdminForthDataSource = {
|
|
|
1085
1097
|
*/
|
|
1086
1098
|
export type AdminForthConfig = {
|
|
1087
1099
|
|
|
1088
|
-
/**
|
|
1089
|
-
* Root user should be used to login to the admin panel first time.
|
|
1090
|
-
* Then you should create User for yourself using AdminForth (so it will be persisted in DB),
|
|
1091
|
-
* and then disable this option as it is less secure
|
|
1092
|
-
*/
|
|
1093
|
-
rootUser?: {
|
|
1094
|
-
/**
|
|
1095
|
-
* Username for root user
|
|
1096
|
-
*/
|
|
1097
|
-
username: string,
|
|
1098
|
-
|
|
1099
|
-
/**
|
|
1100
|
-
* Password for root user
|
|
1101
|
-
*/
|
|
1102
|
-
password: string,
|
|
1103
|
-
},
|
|
1104
|
-
|
|
1105
1100
|
/**
|
|
1106
1101
|
* Authorization module configuration
|
|
1107
1102
|
*/
|
|
1108
1103
|
auth?: {
|
|
1109
1104
|
/**
|
|
1110
|
-
* Resource ID for user
|
|
1105
|
+
* Resource ID for resource which stores user table.
|
|
1111
1106
|
* 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.
|
|
1112
1107
|
* In other words this setting is a reference to a table in database where users will be fetched from on login.
|
|
1113
1108
|
*/
|
|
1114
|
-
|
|
1109
|
+
usersResourceId?: string,
|
|
1110
|
+
|
|
1111
|
+
/**
|
|
1112
|
+
* Legacy field left for backward compatibility. Use usersResourceId instead.
|
|
1113
|
+
*/
|
|
1114
|
+
resourceId?: string,
|
|
1115
1115
|
|
|
1116
1116
|
/**
|
|
1117
1117
|
* Field name (column name) in user resource which will be used as username for searching user in database during login.
|
|
@@ -1136,6 +1136,16 @@ export type AdminForthConfig = {
|
|
|
1136
1136
|
*/
|
|
1137
1137
|
loginBackgroundImage?: string,
|
|
1138
1138
|
|
|
1139
|
+
|
|
1140
|
+
/**
|
|
1141
|
+
* Position of background image on login page
|
|
1142
|
+
* 'over' - image will be displayed over full login page under login form
|
|
1143
|
+
* '1/2' - image will be displayed on left 1/2 of login page
|
|
1144
|
+
*
|
|
1145
|
+
* Default: '1/2'
|
|
1146
|
+
*/
|
|
1147
|
+
loginBackgroundPosition?: 'over' | '1/2' | '1/3' | '2/3' | '3/4' | '2/5' | '3/5',
|
|
1148
|
+
|
|
1139
1149
|
/**
|
|
1140
1150
|
* Function or functions which will be called before user try to login.
|
|
1141
1151
|
* Each function will resive User object as an argument
|
|
@@ -1199,6 +1209,13 @@ export type AdminForthConfig = {
|
|
|
1199
1209
|
*/
|
|
1200
1210
|
brandName?: string,
|
|
1201
1211
|
|
|
1212
|
+
|
|
1213
|
+
/**
|
|
1214
|
+
* Whether to show brand name in sidebar
|
|
1215
|
+
* default is true
|
|
1216
|
+
*/
|
|
1217
|
+
showBrandNameInSidebar?: boolean,
|
|
1218
|
+
|
|
1202
1219
|
/**
|
|
1203
1220
|
* Path to your app logo
|
|
1204
1221
|
*
|
|
@@ -1322,6 +1339,10 @@ export type AdminForthConfig = {
|
|
|
1322
1339
|
baseUrl?: string,
|
|
1323
1340
|
|
|
1324
1341
|
|
|
1342
|
+
/**
|
|
1343
|
+
* Whether to show delete confirmation dialog before deleting record.
|
|
1344
|
+
* By default it is true.
|
|
1345
|
+
*/
|
|
1325
1346
|
deleteConfirmation?: boolean,
|
|
1326
1347
|
|
|
1327
1348
|
|
|
@@ -1375,13 +1396,13 @@ export class Sorts {
|
|
|
1375
1396
|
}
|
|
1376
1397
|
|
|
1377
1398
|
export interface IOperationalResource {
|
|
1378
|
-
get: (filter: IAdminForthFilter | IAdminForthFilter[]) => Promise<any
|
|
1399
|
+
get: (filter: IAdminForthFilter | IAdminForthFilter[]) => Promise<any | null>;
|
|
1379
1400
|
|
|
1380
1401
|
list: (filter: IAdminForthFilter | IAdminForthFilter[], limit: number, offset: number, sort: IAdminForthSort | IAdminForthSort[]) => Promise<any[]>;
|
|
1381
1402
|
|
|
1382
1403
|
count: (filter: IAdminForthFilter | IAdminForthFilter[]) => Promise<number>;
|
|
1383
1404
|
|
|
1384
|
-
create: (record: any) => Promise<any>;
|
|
1405
|
+
create: (record: any) => Promise<{ ok: boolean; createdRecord: any; error?: string; }>;
|
|
1385
1406
|
|
|
1386
1407
|
update: (primaryKey: any, record: any) => Promise<any>;
|
|
1387
1408
|
|