adminforth 1.3.40 → 1.3.42
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/dist/index.js +5 -0
- package/dist/modules/configValidator.js +38 -27
- package/index.ts +6 -0
- package/modules/configValidator.ts +42 -30
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -291,6 +291,7 @@ class AdminForth {
|
|
|
291
291
|
return { error: resp.error };
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
|
+
return { error: null };
|
|
294
295
|
});
|
|
295
296
|
}
|
|
296
297
|
resource(resourceId) {
|
|
@@ -329,6 +330,10 @@ AdminForth.Utils = {
|
|
|
329
330
|
regExp: '^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).+$',
|
|
330
331
|
message: 'Password must include at least one uppercase letter, one lowercase letter, and one number'
|
|
331
332
|
},
|
|
333
|
+
},
|
|
334
|
+
EMAIL_VALIDATOR: {
|
|
335
|
+
regExp: '^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,}$',
|
|
336
|
+
message: 'Email is not valid, must be in format example@test.com',
|
|
332
337
|
}
|
|
333
338
|
};
|
|
334
339
|
export default AdminForth;
|
|
@@ -63,32 +63,6 @@ export default class ConfigValidator {
|
|
|
63
63
|
catch (e) {
|
|
64
64
|
this.config.customization.customComponentsDir = undefined;
|
|
65
65
|
}
|
|
66
|
-
if (this.config.auth) {
|
|
67
|
-
// TODO: remove in future releases
|
|
68
|
-
if (!this.config.auth.usersResourceId && this.config.auth.resourceId) {
|
|
69
|
-
this.config.auth.usersResourceId = this.config.auth.resourceId;
|
|
70
|
-
}
|
|
71
|
-
if (!this.config.auth.usersResourceId) {
|
|
72
|
-
throw new Error('No config.auth.usersResourceId defined');
|
|
73
|
-
}
|
|
74
|
-
if (!this.config.auth.passwordHashField) {
|
|
75
|
-
throw new Error('No config.auth.passwordHashField defined');
|
|
76
|
-
}
|
|
77
|
-
if (!this.config.auth.usernameField) {
|
|
78
|
-
throw new Error('No config.auth.usernameField defined');
|
|
79
|
-
}
|
|
80
|
-
if (this.config.auth.loginBackgroundImage) {
|
|
81
|
-
errors.push(...this.checkCustomFileExists(this.config.auth.loginBackgroundImage));
|
|
82
|
-
}
|
|
83
|
-
const userResource = this.config.resources.find((res) => res.resourceId === this.config.auth.usersResourceId);
|
|
84
|
-
if (!userResource) {
|
|
85
|
-
const similar = suggestIfTypo(this.config.resources.map((res) => res.resourceId || res.table), this.config.auth.usersResourceId);
|
|
86
|
-
throw new Error(`Resource with id "${this.config.auth.usersResourceId}" not found. ${similar ? `Did you mean "${similar}"?` : ''}`);
|
|
87
|
-
}
|
|
88
|
-
if (!this.config.auth.beforeLoginConfirmation) {
|
|
89
|
-
this.config.auth.beforeLoginConfirmation = [];
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
66
|
if (!this.config.customization) {
|
|
93
67
|
this.config.customization = {};
|
|
94
68
|
}
|
|
@@ -202,6 +176,15 @@ export default class ConfigValidator {
|
|
|
202
176
|
}
|
|
203
177
|
col.showIn = col.showIn || Object.values(AdminForthResourcePages);
|
|
204
178
|
if (col.foreignResource) {
|
|
179
|
+
if (!col.foreignResource.resourceId) {
|
|
180
|
+
errors.push(`Resource "${res.resourceId}" column "${col.name}" has foreignResource without resourceId`);
|
|
181
|
+
}
|
|
182
|
+
const resource = this.config.resources.find((r) => r.resourceId === col.foreignResource.resourceId);
|
|
183
|
+
if (!resource) {
|
|
184
|
+
const similar = suggestIfTypo(this.config.resources.map((r) => r.resourceId), col.foreignResource.resourceId);
|
|
185
|
+
errors.push(`Resource "${res.resourceId}" column "${col.name}" has foreignResource resourceId which is not in resources: "${col.foreignResource.resourceId}".
|
|
186
|
+
${similar ? `Did you mean "${similar}" instead of "${col.foreignResource.resourceId}"?` : ''}`);
|
|
187
|
+
}
|
|
205
188
|
const befHook = (_b = (_a = col.foreignResource.hooks) === null || _a === void 0 ? void 0 : _a.dropdownList) === null || _b === void 0 ? void 0 : _b.beforeDatasourceRequest;
|
|
206
189
|
if (befHook) {
|
|
207
190
|
if (!Array.isArray(befHook)) {
|
|
@@ -382,7 +365,9 @@ export default class ConfigValidator {
|
|
|
382
365
|
errors.push(`Menu item with type 'resource' must have resourceId : ${JSON.stringify(item)}`);
|
|
383
366
|
}
|
|
384
367
|
if (item.resourceId && !this.config.resources.find((res) => res.resourceId === item.resourceId)) {
|
|
385
|
-
|
|
368
|
+
const similar = suggestIfTypo(this.config.resources.map((res) => res.resourceId), item.resourceId);
|
|
369
|
+
errors.push(`Menu item with type 'resourceId' has resourceId which is not in resources: "${JSON.stringify(item)}".
|
|
370
|
+
${similar ? `Did you mean "${similar}" instead of "${item.resourceId}"?` : ''}`);
|
|
386
371
|
}
|
|
387
372
|
if (item.type === 'component' && !item.component) {
|
|
388
373
|
errors.push(`Menu item with type 'component' must have component : ${JSON.stringify(item)}`);
|
|
@@ -410,6 +395,32 @@ export default class ConfigValidator {
|
|
|
410
395
|
};
|
|
411
396
|
browseMenu(this.config.menu);
|
|
412
397
|
}
|
|
398
|
+
if (this.config.auth) {
|
|
399
|
+
// TODO: remove in future releases
|
|
400
|
+
if (!this.config.auth.usersResourceId && this.config.auth.resourceId) {
|
|
401
|
+
this.config.auth.usersResourceId = this.config.auth.resourceId;
|
|
402
|
+
}
|
|
403
|
+
if (!this.config.auth.usersResourceId) {
|
|
404
|
+
throw new Error('No config.auth.usersResourceId defined');
|
|
405
|
+
}
|
|
406
|
+
if (!this.config.auth.passwordHashField) {
|
|
407
|
+
throw new Error('No config.auth.passwordHashField defined');
|
|
408
|
+
}
|
|
409
|
+
if (!this.config.auth.usernameField) {
|
|
410
|
+
throw new Error('No config.auth.usernameField defined');
|
|
411
|
+
}
|
|
412
|
+
if (this.config.auth.loginBackgroundImage) {
|
|
413
|
+
errors.push(...this.checkCustomFileExists(this.config.auth.loginBackgroundImage));
|
|
414
|
+
}
|
|
415
|
+
const userResource = this.config.resources.find((res) => res.resourceId === this.config.auth.usersResourceId);
|
|
416
|
+
if (!userResource) {
|
|
417
|
+
const similar = suggestIfTypo(this.config.resources.map((res) => res.resourceId), this.config.auth.usersResourceId);
|
|
418
|
+
throw new Error(`Resource with id "${this.config.auth.usersResourceId}" not found. ${similar ? `Did you mean "${similar}"?` : ''}`);
|
|
419
|
+
}
|
|
420
|
+
if (!this.config.auth.beforeLoginConfirmation) {
|
|
421
|
+
this.config.auth.beforeLoginConfirmation = [];
|
|
422
|
+
}
|
|
423
|
+
}
|
|
413
424
|
// check for duplicate resourceIds and show which ones are duplicated
|
|
414
425
|
const resourceIds = this.config.resources.map((res) => res.resourceId);
|
|
415
426
|
const uniqueResourceIds = new Set(resourceIds);
|
package/index.ts
CHANGED
|
@@ -50,6 +50,10 @@ class AdminForth implements IAdminForth {
|
|
|
50
50
|
regExp: '^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).+$',
|
|
51
51
|
message: 'Password must include at least one uppercase letter, one lowercase letter, and one number'
|
|
52
52
|
},
|
|
53
|
+
},
|
|
54
|
+
EMAIL_VALIDATOR: {
|
|
55
|
+
regExp: '^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,}$',
|
|
56
|
+
message: 'Email is not valid, must be in format example@test.com',
|
|
53
57
|
}
|
|
54
58
|
}
|
|
55
59
|
|
|
@@ -369,6 +373,8 @@ class AdminForth implements IAdminForth {
|
|
|
369
373
|
return { error: resp.error };
|
|
370
374
|
}
|
|
371
375
|
}
|
|
376
|
+
|
|
377
|
+
return { error: null };
|
|
372
378
|
}
|
|
373
379
|
|
|
374
380
|
resource(resourceId: string): IOperationalResource {
|
|
@@ -76,35 +76,6 @@ export default class ConfigValidator implements IConfigValidator {
|
|
|
76
76
|
this.config.customization.customComponentsDir = undefined;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
if (this.config.auth) {
|
|
80
|
-
// TODO: remove in future releases
|
|
81
|
-
if (!this.config.auth.usersResourceId && this.config.auth.resourceId) {
|
|
82
|
-
this.config.auth.usersResourceId = this.config.auth.resourceId;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (!this.config.auth.usersResourceId) {
|
|
86
|
-
throw new Error('No config.auth.usersResourceId defined');
|
|
87
|
-
}
|
|
88
|
-
if (!this.config.auth.passwordHashField) {
|
|
89
|
-
throw new Error('No config.auth.passwordHashField defined');
|
|
90
|
-
}
|
|
91
|
-
if (!this.config.auth.usernameField) {
|
|
92
|
-
throw new Error('No config.auth.usernameField defined');
|
|
93
|
-
}
|
|
94
|
-
if (this.config.auth.loginBackgroundImage) {
|
|
95
|
-
errors.push(...this.checkCustomFileExists(this.config.auth.loginBackgroundImage));
|
|
96
|
-
}
|
|
97
|
-
const userResource = this.config.resources.find((res) => res.resourceId === this.config.auth.usersResourceId);
|
|
98
|
-
if (!userResource) {
|
|
99
|
-
const similar = suggestIfTypo(this.config.resources.map((res) => res.resourceId || res.table), this.config.auth.usersResourceId);
|
|
100
|
-
throw new Error(`Resource with id "${this.config.auth.usersResourceId}" not found. ${similar ? `Did you mean "${similar}"?` : ''}`);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (!this.config.auth.beforeLoginConfirmation) {
|
|
104
|
-
this.config.auth.beforeLoginConfirmation = [];
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
79
|
if (!this.config.customization) {
|
|
109
80
|
this.config.customization = {};
|
|
110
81
|
}
|
|
@@ -224,6 +195,16 @@ export default class ConfigValidator implements IConfigValidator {
|
|
|
224
195
|
col.showIn = col.showIn || Object.values(AdminForthResourcePages);
|
|
225
196
|
|
|
226
197
|
if (col.foreignResource) {
|
|
198
|
+
|
|
199
|
+
if (!col.foreignResource.resourceId) {
|
|
200
|
+
errors.push(`Resource "${res.resourceId}" column "${col.name}" has foreignResource without resourceId`);
|
|
201
|
+
}
|
|
202
|
+
const resource = this.config.resources.find((r) => r.resourceId === col.foreignResource.resourceId);
|
|
203
|
+
if (!resource) {
|
|
204
|
+
const similar = suggestIfTypo(this.config.resources.map((r) => r.resourceId), col.foreignResource.resourceId);
|
|
205
|
+
errors.push(`Resource "${res.resourceId}" column "${col.name}" has foreignResource resourceId which is not in resources: "${col.foreignResource.resourceId}".
|
|
206
|
+
${similar ? `Did you mean "${similar}" instead of "${col.foreignResource.resourceId}"?` : ''}`);
|
|
207
|
+
}
|
|
227
208
|
const befHook = col.foreignResource.hooks?.dropdownList?.beforeDatasourceRequest;
|
|
228
209
|
if (befHook) {
|
|
229
210
|
if (!Array.isArray(befHook)) {
|
|
@@ -442,7 +423,9 @@ export default class ConfigValidator implements IConfigValidator {
|
|
|
442
423
|
}
|
|
443
424
|
|
|
444
425
|
if (item.resourceId && !this.config.resources.find((res) => res.resourceId === item.resourceId)) {
|
|
445
|
-
|
|
426
|
+
const similar = suggestIfTypo(this.config.resources.map((res) => res.resourceId), item.resourceId);
|
|
427
|
+
errors.push(`Menu item with type 'resourceId' has resourceId which is not in resources: "${JSON.stringify(item)}".
|
|
428
|
+
${similar ? `Did you mean "${similar}" instead of "${item.resourceId}"?` : ''}`);
|
|
446
429
|
}
|
|
447
430
|
|
|
448
431
|
if (item.type === 'component' && !item.component) {
|
|
@@ -476,6 +459,35 @@ export default class ConfigValidator implements IConfigValidator {
|
|
|
476
459
|
|
|
477
460
|
}
|
|
478
461
|
|
|
462
|
+
if (this.config.auth) {
|
|
463
|
+
// TODO: remove in future releases
|
|
464
|
+
if (!this.config.auth.usersResourceId && this.config.auth.resourceId) {
|
|
465
|
+
this.config.auth.usersResourceId = this.config.auth.resourceId;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
if (!this.config.auth.usersResourceId) {
|
|
469
|
+
throw new Error('No config.auth.usersResourceId defined');
|
|
470
|
+
}
|
|
471
|
+
if (!this.config.auth.passwordHashField) {
|
|
472
|
+
throw new Error('No config.auth.passwordHashField defined');
|
|
473
|
+
}
|
|
474
|
+
if (!this.config.auth.usernameField) {
|
|
475
|
+
throw new Error('No config.auth.usernameField defined');
|
|
476
|
+
}
|
|
477
|
+
if (this.config.auth.loginBackgroundImage) {
|
|
478
|
+
errors.push(...this.checkCustomFileExists(this.config.auth.loginBackgroundImage));
|
|
479
|
+
}
|
|
480
|
+
const userResource = this.config.resources.find((res) => res.resourceId === this.config.auth.usersResourceId);
|
|
481
|
+
if (!userResource) {
|
|
482
|
+
const similar = suggestIfTypo(this.config.resources.map((res) => res.resourceId ), this.config.auth.usersResourceId);
|
|
483
|
+
throw new Error(`Resource with id "${this.config.auth.usersResourceId}" not found. ${similar ? `Did you mean "${similar}"?` : ''}`);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
if (!this.config.auth.beforeLoginConfirmation) {
|
|
487
|
+
this.config.auth.beforeLoginConfirmation = [];
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
479
491
|
// check for duplicate resourceIds and show which ones are duplicated
|
|
480
492
|
const resourceIds = this.config.resources.map((res) => res.resourceId);
|
|
481
493
|
const uniqueResourceIds = new Set(resourceIds);
|