@solidstarters/solid-core 1.2.58 → 1.2.59

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 (48) hide show
  1. package/dist/config/iam.config.d.ts +2 -0
  2. package/dist/config/iam.config.d.ts.map +1 -1
  3. package/dist/config/iam.config.js +1 -0
  4. package/dist/config/iam.config.js.map +1 -1
  5. package/dist/controllers/setting.controller.d.ts +3 -0
  6. package/dist/controllers/setting.controller.d.ts.map +1 -1
  7. package/dist/controllers/setting.controller.js +23 -0
  8. package/dist/controllers/setting.controller.js.map +1 -1
  9. package/dist/dtos/create-setting.dto.d.ts +2 -15
  10. package/dist/dtos/create-setting.dto.d.ts.map +1 -1
  11. package/dist/dtos/create-setting.dto.js +6 -77
  12. package/dist/dtos/create-setting.dto.js.map +1 -1
  13. package/dist/dtos/update-setting.dto.d.ts +2 -15
  14. package/dist/dtos/update-setting.dto.d.ts.map +1 -1
  15. package/dist/dtos/update-setting.dto.js +6 -77
  16. package/dist/dtos/update-setting.dto.js.map +1 -1
  17. package/dist/dtos/update-settings.dto.d.ts +4 -0
  18. package/dist/dtos/update-settings.dto.d.ts.map +1 -0
  19. package/dist/dtos/update-settings.dto.js +26 -0
  20. package/dist/dtos/update-settings.dto.js.map +1 -0
  21. package/dist/entities/setting.entity.d.ts +2 -15
  22. package/dist/entities/setting.entity.d.ts.map +1 -1
  23. package/dist/entities/setting.entity.js +4 -65
  24. package/dist/entities/setting.entity.js.map +1 -1
  25. package/dist/seeders/module-metadata-seeder.service.d.ts.map +1 -1
  26. package/dist/seeders/module-metadata-seeder.service.js +1 -18
  27. package/dist/seeders/module-metadata-seeder.service.js.map +1 -1
  28. package/dist/seeders/seed-data/solid-core-metadata.json +7 -174
  29. package/dist/services/authentication.service.d.ts +3 -1
  30. package/dist/services/authentication.service.d.ts.map +1 -1
  31. package/dist/services/authentication.service.js +11 -8
  32. package/dist/services/authentication.service.js.map +1 -1
  33. package/dist/services/setting.service.d.ts +4 -0
  34. package/dist/services/setting.service.d.ts.map +1 -1
  35. package/dist/services/setting.service.js +139 -7
  36. package/dist/services/setting.service.js.map +1 -1
  37. package/dist/tsconfig.tsbuildinfo +1 -1
  38. package/package.json +1 -1
  39. package/src/config/iam.config.ts +1 -0
  40. package/src/controllers/setting.controller.ts +13 -1
  41. package/src/dtos/create-setting.dto.ts +10 -59
  42. package/src/dtos/update-setting.dto.ts +10 -60
  43. package/src/dtos/update-settings.dto.ts +7 -0
  44. package/src/entities/setting.entity.ts +8 -46
  45. package/src/seeders/module-metadata-seeder.service.ts +1 -19
  46. package/src/seeders/seed-data/solid-core-metadata.json +7 -174
  47. package/src/services/authentication.service.ts +8 -6
  48. package/src/services/setting.service.ts +163 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidstarters/solid-core",
3
- "version": "1.2.58",
3
+ "version": "1.2.59",
4
4
  "description": "This module is a NestJS module containing all the required core providers required by a Solid application",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -3,6 +3,7 @@ import { registerAs } from '@nestjs/config';
3
3
  export const iamConfig = registerAs('iam', () => {
4
4
  return {
5
5
  passwordlessRegistration: (process.env.IAM_PASSWORD_LESS_REGISTRATION ?? 'false') === 'true',
6
+ iamPasswordRegistrationEnabled: (process.env.IAM_PASSWORD_REGISTRATION_ENABLED ?? 'true') === 'true',
6
7
  passwordlessRegistrationValidateWhat: (process.env.IAM_PASSWORD_LESS_REGISTRATION_VALIDATE_WHAT ?? 'email').split(',').map((item) => item.trim()),
7
8
  allowPublicRegistration: (process.env.IAM_ALLOW_PUBLIC_REGISTRATION ?? 'true') === 'true',
8
9
  activateUserOnRegistration: (process.env.IAM_ACTIVATE_USER_ON_REGISTRATION ?? 'true') === 'true',
@@ -6,6 +6,7 @@ import { CreateSettingDto } from '../dtos/create-setting.dto';
6
6
  import { UpdateSettingDto } from '../dtos/update-setting.dto';
7
7
  import { SolidRequestContextDecorator } from 'src/decorators/solid-request-context.decorator';
8
8
  import { SolidRequestContextDto } from 'src/dtos/solid-request-context.dto';
9
+ import { UpdateSettingsDto } from 'src/dtos/update-settings.dto';
9
10
 
10
11
  @ApiTags('Solid')
11
12
  @Controller('setting') //FIXME: Change this to the model plural name
@@ -45,7 +46,12 @@ export class SettingController {
45
46
  @Get('/wrapped')
46
47
  async wrapSettings() {
47
48
  return this.service.wrapSettings();
48
- }
49
+ }
50
+
51
+ @Get()
52
+ async getAllSettings() {
53
+ return this.service.getAllSettings();
54
+ }
49
55
 
50
56
  @ApiBearerAuth("jwt")
51
57
  @ApiQuery({ name: 'showSoftDeleted', required: false, type: Boolean })
@@ -79,4 +85,10 @@ export class SettingController {
79
85
  async delete(@Param('id') id: number,@SolidRequestContextDecorator() solidRequestContext:SolidRequestContextDto) {
80
86
  return this.service.delete(id,solidRequestContext);
81
87
  }
88
+
89
+ @ApiBearerAuth("jwt")
90
+ @Post('/bulk-update')
91
+ async updateSettings(@Body() updateSettingsDto: UpdateSettingsDto) {
92
+ return this.service.updateSettings(updateSettingsDto.settings);
93
+ }
82
94
  }
@@ -1,63 +1,14 @@
1
1
  import { IsString } from 'class-validator';
2
2
  import { IsOptional, IsBoolean } from 'class-validator';
3
- export class CreateSettingDto {
4
- @IsOptional()
5
- @IsString()
6
- authPagesLayout: string;
7
-
8
- @IsOptional()
9
- @IsString()
10
- authPagesTheme: string;
11
-
12
- @IsOptional()
13
- @IsString()
14
- appTitle: string;
15
-
16
- @IsOptional()
17
- @IsString()
18
- appLogo: string;
19
-
20
- @IsOptional()
21
- @IsString()
22
- appDescription: string;
23
-
24
- @IsOptional()
25
- @IsString()
26
- appTnc: string;
27
-
28
- @IsOptional()
29
- @IsString()
30
- appPrivacyPolicy: string;
31
-
32
- @IsOptional()
33
- @IsBoolean()
34
- iamAllowPublicRegistration: boolean = false;
3
+ import { ApiProperty } from '@nestjs/swagger';
35
4
 
36
- @IsOptional()
37
- @IsBoolean()
38
- iamPasswordRegistrationEnabled: boolean = false;
39
-
40
- @IsOptional()
41
- @IsBoolean()
42
- iamPasswordLessRegistrationEnabled: boolean = false;
43
-
44
- @IsOptional()
45
- @IsBoolean()
46
- iamActivateUserOnRegistration: boolean = false;
47
-
48
- @IsOptional()
49
- @IsString()
50
- iamDefaultRole: string;
51
-
52
- @IsOptional()
53
- @IsBoolean()
54
- iamGoogleOAuthEnabled: boolean = false;
55
-
56
- @IsOptional()
57
- @IsBoolean()
58
- shouldQueueEmails: boolean = false;
59
-
60
- @IsOptional()
61
- @IsBoolean()
62
- shouldQueueSms: boolean = false;
5
+ export class CreateSettingDto {
6
+ @IsOptional()
7
+ @IsString()
8
+ @ApiProperty()
9
+ key: string;
10
+ @IsOptional()
11
+ @IsString()
12
+ @ApiProperty()
13
+ value: string;
63
14
  }
@@ -1,66 +1,16 @@
1
1
  import { IsInt,IsOptional, IsString, IsBoolean } from 'class-validator';
2
+ import { ApiProperty } from '@nestjs/swagger';
3
+
2
4
  export class UpdateSettingDto {
3
5
  @IsOptional()
4
6
  @IsInt()
5
7
  id: number;
6
-
7
- @IsOptional()
8
- @IsString()
9
- authPagesLayout: string;
10
-
11
- @IsOptional()
12
- @IsString()
13
- authPagesTheme: string;
14
-
15
- @IsOptional()
16
- @IsString()
17
- appTitle: string;
18
-
19
- @IsOptional()
20
- @IsString()
21
- appLogo: string;
22
-
23
- @IsOptional()
24
- @IsString()
25
- appDescription: string;
26
-
27
- @IsOptional()
28
- @IsString()
29
- appTnc: string;
30
-
31
- @IsOptional()
32
- @IsString()
33
- appPrivacyPolicy: string;
34
-
35
- @IsOptional()
36
- @IsBoolean()
37
- iamAllowPublicRegistration: boolean = false;
38
-
39
- @IsOptional()
40
- @IsBoolean()
41
- iamPasswordRegistrationEnabled: boolean = false;
42
-
43
- @IsOptional()
44
- @IsBoolean()
45
- iamPasswordLessRegistrationEnabled: boolean = false;
46
-
47
- @IsOptional()
48
- @IsBoolean()
49
- iamActivateUserOnRegistration: boolean = false;
50
-
51
- @IsOptional()
52
- @IsString()
53
- iamDefaultRole: string;
54
-
55
- @IsOptional()
56
- @IsBoolean()
57
- iamGoogleOAuthEnabled: boolean = false;
58
-
59
- @IsOptional()
60
- @IsBoolean()
61
- shouldQueueEmails: boolean = false;
62
-
63
- @IsOptional()
64
- @IsBoolean()
65
- shouldQueueSms: boolean = false;
8
+ @IsOptional()
9
+ @IsString()
10
+ @ApiProperty()
11
+ key: string;
12
+ @IsOptional()
13
+ @IsString()
14
+ @ApiProperty()
15
+ value: string;
66
16
  }
@@ -0,0 +1,7 @@
1
+ import { IsNotEmpty, IsObject } from 'class-validator';
2
+
3
+ export class UpdateSettingsDto {
4
+ @IsObject()
5
+ @IsNotEmpty()
6
+ settings: Record<string, any>;
7
+ }
@@ -1,49 +1,11 @@
1
1
  import { CommonEntity } from 'src/entities/common.entity'
2
- import {Entity, Column} from 'typeorm'
3
- @Entity("ss_setting")
4
- export class Setting extends CommonEntity{
5
- @Column({ type: "varchar", nullable: true })
6
- authPagesLayout: string;
7
-
8
- @Column({ type: "varchar", nullable: true })
9
- authPagesTheme: string;
10
-
11
- @Column({ type: "varchar", nullable: true })
12
- appTitle: string;
13
-
14
- @Column({ type: "varchar", nullable: true })
15
- appLogo: string;
16
-
17
- @Column({ type: "varchar", nullable: true })
18
- appDescription: string;
19
-
20
- @Column({ type: "varchar", nullable: true })
21
- appTnc: string;
22
-
23
- @Column({ type: "varchar", nullable: true })
24
- appPrivacyPolicy: string;
25
-
26
- @Column({ type: "boolean", nullable: true, default: false })
27
- iamAllowPublicRegistration: boolean = false;
2
+ import {Entity, Column, Index} from 'typeorm'
28
3
 
29
- @Column({ type: "boolean", nullable: true, default: false })
30
- iamPasswordRegistrationEnabled: boolean = false;
31
-
32
- @Column({ type: "boolean", nullable: true, default: false })
33
- iamPasswordLessRegistrationEnabled: boolean = false;
34
-
35
- @Column({ type: "boolean", nullable: true, default: false })
36
- iamActivateUserOnRegistration: boolean = false;
37
-
38
- @Column({ type: "varchar", nullable: true })
39
- iamDefaultRole: string;
40
-
41
- @Column({ type: "boolean", nullable: true, default: false })
42
- iamGoogleOAuthEnabled: boolean = false;
43
-
44
- @Column({ type: "boolean", nullable: true, default: false })
45
- shouldQueueEmails: boolean = false;
46
-
47
- @Column({ type: "boolean", nullable: true, default: false })
48
- shouldQueueSms: boolean = false;
4
+ @Entity("ss_setting")
5
+ export class Setting extends CommonEntity {
6
+ @Index({ unique: true })
7
+ @Column({ type: "varchar", nullable: true })
8
+ key: string;
9
+ @Column({ type: "varchar", nullable: true })
10
+ value: string;
49
11
  }
@@ -74,24 +74,6 @@ export class ModuleMetadataSeederService {
74
74
 
75
75
  const typedSolidCoreMetadata: any = solidCoreMetadata;
76
76
 
77
- const settingsSeederData: any = {
78
- iamAllowPublicRegistration: this.iamConfiguration.allowPublicRegistration,
79
- iamPasswordRegistrationEnabled: true,
80
- iamPasswordLessRegistrationEnabled: this.iamConfiguration.passwordlessRegistration,
81
- iamActivateUserOnRegistration: this.iamConfiguration.activateUserOnRegistration,
82
- iamGoogleOAuthEnabled: false,
83
- authPagesLayout: "center",
84
- authPagesTheme: "light",
85
- appTitle: process.env.SOLID_APP_NAME || "Solid App",
86
- appLogo: "",
87
- appDescription: "",
88
- appTnc: "",
89
- appPrivacyPolicy: "",
90
- iamDefaultRole: this.iamConfiguration.defaultRole,
91
- shouldQueueEmails: this.commonConfiguration.shouldQueueEmails,
92
- shouldQueueSms: this.commonConfiguration.shouldQueueSms
93
- }
94
-
95
77
  // Run the permissions seeder.
96
78
  // await this.permissionsSeederService.seed();
97
79
  this.logger.log(`Seeding permissions`);
@@ -198,7 +180,7 @@ export class ModuleMetadataSeederService {
198
180
 
199
181
  // Settings
200
182
  this.logger.debug(`[Start] Processing settings for ${moduleMetadata.name}`);
201
- await this.seedSettings(settingsSeederData);
183
+ await this.seetingService.seedDefaultSettings();
202
184
  this.logger.debug(`[End] Processing settings for ${moduleMetadata.name}`);
203
185
 
204
186
  // Security rules
@@ -2380,191 +2380,24 @@
2380
2380
  "userKeyFieldUserKey": "username",
2381
2381
  "fields": [
2382
2382
  {
2383
- "name": "authPagesLayout",
2384
- "displayName": "Auth Pages Layout",
2385
- "type": "selectionStatic",
2386
- "ormType": "varchar",
2387
- "length": 128,
2388
- "required": false,
2389
- "unique": false,
2390
- "index": false,
2391
- "private": false,
2392
- "encrypt": false,
2393
- "isSystem": true,
2394
- "selectionStaticValues": [
2395
- "left:Left",
2396
- "center:Center",
2397
- "right:Right"
2398
- ]
2399
- },
2400
- {
2401
- "name": "authPagesTheme",
2402
- "displayName": "Auth Pages Theme",
2403
- "type": "selectionStatic",
2404
- "ormType": "varchar",
2405
- "length": 128,
2406
- "required": false,
2407
- "unique": false,
2408
- "index": false,
2409
- "private": false,
2410
- "encrypt": false,
2411
- "isSystem": true,
2412
- "selectionStaticValues": [
2413
- "dark:Dark",
2414
- "light:Light"
2415
- ]
2416
- },
2417
- {
2418
- "name": "appTitle",
2419
- "displayName": "App Title",
2383
+ "name": "key",
2384
+ "displayName": "Key",
2420
2385
  "type": "shortText",
2421
2386
  "ormType": "varchar",
2422
- "length": 512,
2423
- "required": false,
2424
- "unique": false,
2425
- "index": false,
2426
- "private": false,
2427
- "encrypt": false,
2428
- "isSystem": true
2429
- },
2430
- {
2431
- "name": "appLogo",
2432
- "displayName": "App Logo",
2433
- "type": "mediaSingle",
2434
- "mediaStorageProviderUserKey": "default-filesystem",
2387
+ "length": 128,
2435
2388
  "required": false,
2436
- "unique": false,
2389
+ "unique": true,
2437
2390
  "index": false,
2438
2391
  "private": false,
2439
2392
  "encrypt": false,
2440
2393
  "isSystem": true
2441
2394
  },
2442
2395
  {
2443
- "name": "appDescription",
2444
- "displayName": "App Description",
2396
+ "name": "value",
2397
+ "displayName": "Value",
2445
2398
  "type": "longText",
2446
2399
  "ormType": "varchar",
2447
- "required": false,
2448
- "unique": false,
2449
- "index": false,
2450
- "private": false,
2451
- "encrypt": false,
2452
- "isSystem": true
2453
- },
2454
- {
2455
- "name": "appTnc",
2456
- "displayName": "App TNC",
2457
- "type": "richText",
2458
- "ormType": "varchar",
2459
- "required": false,
2460
- "unique": false,
2461
- "index": false,
2462
- "private": false,
2463
- "encrypt": false,
2464
- "isSystem": true
2465
- },
2466
- {
2467
- "name": "appPrivacyPolicy",
2468
- "displayName": "App Privacy Policy",
2469
- "type": "richText",
2470
- "ormType": "varchar",
2471
- "required": false,
2472
- "unique": false,
2473
- "index": false,
2474
- "private": false,
2475
- "encrypt": false,
2476
- "isSystem": true
2477
- },
2478
- {
2479
- "name": "iamAllowPublicRegistration",
2480
- "displayName": "Iam Allow Public Registration",
2481
- "type": "boolean",
2482
- "ormType": "boolean",
2483
- "required": false,
2484
- "unique": false,
2485
- "index": false,
2486
- "private": false,
2487
- "encrypt": false,
2488
- "isSystem": true
2489
- },
2490
- {
2491
- "name": "iamPasswordRegistrationEnabled",
2492
- "displayName": "Iam Password Registration Enabled",
2493
- "type": "boolean",
2494
- "ormType": "boolean",
2495
- "required": false,
2496
- "unique": false,
2497
- "index": false,
2498
- "private": false,
2499
- "encrypt": false,
2500
- "isSystem": true
2501
- },
2502
- {
2503
- "name": "iamPasswordLessRegistrationEnabled",
2504
- "displayName": "Iam Password Less Registration enabled",
2505
- "type": "boolean",
2506
- "ormType": "boolean",
2507
- "required": false,
2508
- "unique": false,
2509
- "index": false,
2510
- "private": false,
2511
- "encrypt": false,
2512
- "isSystem": true
2513
- },
2514
- {
2515
- "name": "iamActivateUserOnRegistration",
2516
- "displayName": "Iam Activate User On Registration",
2517
- "type": "boolean",
2518
- "ormType": "boolean",
2519
- "required": false,
2520
- "unique": false,
2521
- "index": false,
2522
- "private": false,
2523
- "encrypt": false,
2524
- "isSystem": true
2525
- },
2526
- {
2527
- "name": "iamDefaultRole",
2528
- "displayName": "Iam Default Role",
2529
- "type": "shortText",
2530
- "ormType": "varchar",
2531
- "length": 512,
2532
- "required": false,
2533
- "unique": false,
2534
- "index": false,
2535
- "private": false,
2536
- "encrypt": false,
2537
- "isSystem": true
2538
- },
2539
- {
2540
- "name": "iamGoogleOAuthEnabled",
2541
- "displayName": "Iam Google OAuth Enabled",
2542
- "type": "boolean",
2543
- "ormType": "boolean",
2544
- "required": false,
2545
- "unique": false,
2546
- "index": false,
2547
- "private": false,
2548
- "encrypt": false,
2549
- "isSystem": true
2550
- },
2551
- {
2552
- "name": "shouldQueueEmails",
2553
- "displayName": "Should Queue Emails",
2554
- "type": "boolean",
2555
- "ormType": "boolean",
2556
- "required": false,
2557
- "unique": false,
2558
- "index": false,
2559
- "private": false,
2560
- "encrypt": false,
2561
- "isSystem": true
2562
- },
2563
- {
2564
- "name": "shouldQueueSms",
2565
- "displayName": "Should Queue SMS",
2566
- "type": "boolean",
2567
- "ormType": "boolean",
2400
+ "length": 128,
2568
2401
  "required": false,
2569
2402
  "unique": false,
2570
2403
  "index": false,
@@ -39,6 +39,7 @@ import {
39
39
  RegistrationValidationSource,
40
40
  TransactionalRegistrationValidationSource
41
41
  } from "../constants";
42
+ import { SettingService } from './setting.service';
42
43
  import { CreateUserDto } from 'src/dtos/create-user.dto';
43
44
 
44
45
  enum LoginProvider {
@@ -71,6 +72,7 @@ export class AuthenticationService {
71
72
  private readonly mailService: SMTPEMailService,
72
73
  private readonly smsService: Msg91OTPService,
73
74
  private readonly eventEmitter: EventEmitter2,
75
+ private readonly settingService: SettingService,
74
76
  ) { }
75
77
 
76
78
  async resolveUser(username: string, email: string) {
@@ -108,7 +110,7 @@ export class AuthenticationService {
108
110
 
109
111
  async signUp(signUpDto: SignUpDto, activeUser: ActiveUserData = null): Promise<User> {
110
112
  // If public registrations are disabled and no activeUser is present when invoking signUp then we throw an exception.
111
- if (!this.iamConfiguration.allowPublicRegistration && !activeUser) {
113
+ if (!(await this.settingService.getConfigValue('allowPublicRegistration')) && !activeUser) {
112
114
  throw new BadRequestException('Public registrations are disabled.');
113
115
  }
114
116
 
@@ -278,7 +280,7 @@ export class AuthenticationService {
278
280
  user = this.createUser(signUpDto);
279
281
  this.populateVerificationTokens(finalRegistrationVerificationSources, user);
280
282
  await this.userRepository.save(user);
281
- await this.userService.addRoleToUser(user.username, this.iamConfiguration.defaultRole);
283
+ await this.userService.addRoleToUser(user.username, await this.settingService.getConfigValue('defaultRole'));
282
284
  }
283
285
  else {
284
286
  this.populateVerificationTokens(finalRegistrationVerificationSources, user);
@@ -397,7 +399,7 @@ export class AuthenticationService {
397
399
  user.emailVerifiedOnRegistrationAt = new Date();
398
400
  user.emailVerificationTokenOnRegistration = null;
399
401
  user.emailVerificationTokenOnRegistrationExpiresAt = null;
400
- user.active = this.iamConfiguration.activateUserOnRegistration && this.areRegistrationValidationSourcesVerified(user);
402
+ user.active = await this.settingService.getConfigValue('activateUserOnRegistration') && this.areRegistrationValidationSourcesVerified(user);
401
403
  const savedUser: User = await this.userRepository.save(user);
402
404
  this.triggerRegistrationEvent(savedUser);
403
405
  return { active: savedUser.active, message: `User registration verified for ${confirmSignUpDto.type}` }
@@ -419,7 +421,7 @@ export class AuthenticationService {
419
421
  user.mobileVerifiedOnRegistrationAt = new Date();
420
422
  user.mobileVerificationTokenOnRegistration = null;
421
423
  user.mobileVerificationTokenOnRegistrationExpiresAt = null;
422
- user.active = this.iamConfiguration.activateUserOnRegistration && this.areRegistrationValidationSourcesVerified(user);
424
+ user.active = await this.settingService.getConfigValue('activateUserOnRegistration') && this.areRegistrationValidationSourcesVerified(user);
423
425
  const savedUser: User = await this.userRepository.save(user);
424
426
  this.triggerRegistrationEvent(savedUser);
425
427
  return { active: savedUser.active, message: `User registration verified for ${confirmSignUpDto.type}` }
@@ -976,8 +978,8 @@ export class AuthenticationService {
976
978
 
977
979
  }
978
980
 
979
- private isPasswordlessRegistrationEnabled() {
980
- return this.iamConfiguration.passwordlessRegistration;
981
+ private async isPasswordlessRegistrationEnabled() {
982
+ return this.settingService.getConfigValue('passwordlessRegistration');
981
983
  }
982
984
 
983
985
  //FIXME - Pending implementation