@solidstarters/solid-core 1.2.53 → 1.2.56
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/controllers/authentication.controller.d.ts +7 -35
- package/dist/controllers/authentication.controller.d.ts.map +1 -1
- package/dist/controllers/field-metadata.controller.js +1 -1
- package/dist/controllers/media-storage-provider-metadata.controller.d.ts +1 -1
- package/dist/controllers/media-storage-provider-metadata.controller.js +3 -3
- package/dist/controllers/module-metadata.controller.d.ts +1 -1
- package/dist/controllers/module-metadata.controller.js +2 -2
- package/dist/helpers/schematic.service.d.ts +1 -0
- package/dist/helpers/schematic.service.d.ts.map +1 -1
- package/dist/helpers/schematic.service.js +3 -0
- package/dist/helpers/schematic.service.js.map +1 -1
- package/dist/seeders/seed-data/solid-core-metadata.json +6 -6
- package/dist/services/authentication.service.d.ts +11 -35
- package/dist/services/authentication.service.d.ts.map +1 -1
- package/dist/services/authentication.service.js +65 -36
- package/dist/services/authentication.service.js.map +1 -1
- package/dist/services/field-metadata.service.d.ts +1 -1
- package/dist/services/field-metadata.service.d.ts.map +1 -1
- package/dist/services/field-metadata.service.js +2 -3
- package/dist/services/field-metadata.service.js.map +1 -1
- package/dist/services/media-storage-provider-metadata.service.d.ts +1 -1
- package/dist/services/media-storage-provider-metadata.service.js +1 -1
- package/dist/services/model-metadata.service.d.ts.map +1 -1
- package/dist/services/model-metadata.service.js +6 -5
- package/dist/services/model-metadata.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/controllers/field-metadata.controller.ts +1 -1
- package/src/controllers/media-storage-provider-metadata.controller.ts +2 -2
- package/src/controllers/module-metadata.controller.ts +1 -1
- package/src/helpers/schematic.service.ts +12 -8
- package/src/seeders/seed-data/solid-core-metadata.json +6 -6
- package/src/services/authentication.service.ts +86 -45
- package/src/services/field-metadata.service.ts +2 -4
- package/src/services/media-storage-provider-metadata.service.ts +1 -1
- package/src/services/model-metadata.service.ts +7 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidstarters/solid-core",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.56",
|
|
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",
|
|
@@ -57,8 +57,8 @@ export class MediaStorageProviderMetadataController {
|
|
|
57
57
|
|
|
58
58
|
@ApiBearerAuth("jwt")
|
|
59
59
|
@Delete(':id')
|
|
60
|
-
|
|
61
|
-
return this.mediaStorageProviderService.
|
|
60
|
+
delete(@Param('id') id: number) {
|
|
61
|
+
return this.mediaStorageProviderService.delete(id);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
}
|
|
@@ -15,6 +15,7 @@ type FieldOptions = {
|
|
|
15
15
|
fields: any[]; //FIXME This type can be improved
|
|
16
16
|
modelEnableSoftDelete?: boolean;
|
|
17
17
|
parentModel?: string;
|
|
18
|
+
parentModule?: string;
|
|
18
19
|
};
|
|
19
20
|
export const REMOVE_FIELDS_COMMAND = 'remove-fields';
|
|
20
21
|
export const REFRESH_MODEL_COMMAND = 'refresh-model';
|
|
@@ -31,7 +32,7 @@ enum SYSTEM_FIELDS_TO_IGNORE_FOR_CODE_GENERATION {
|
|
|
31
32
|
export class SchematicService {
|
|
32
33
|
private readonly logger = new Logger(SchematicService.name);
|
|
33
34
|
private readonly SCHEMATIC_PROJECT = '@solidstarters/solid-code-builder';
|
|
34
|
-
constructor(private readonly commandService: CommandService) {}
|
|
35
|
+
constructor(private readonly commandService: CommandService) { }
|
|
35
36
|
|
|
36
37
|
async executeSchematicCommand(
|
|
37
38
|
command: string,
|
|
@@ -62,7 +63,7 @@ export class SchematicService {
|
|
|
62
63
|
if (fieldOptions.table) {
|
|
63
64
|
modelCommand += ` --table=${fieldOptions.table}`;
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
+
|
|
66
67
|
if (fieldOptions.dataSource) {
|
|
67
68
|
modelCommand += ` --data-source=${fieldOptions.dataSource}`;
|
|
68
69
|
}
|
|
@@ -70,26 +71,29 @@ export class SchematicService {
|
|
|
70
71
|
if (fieldOptions.modelEnableSoftDelete) {
|
|
71
72
|
modelCommand += ` --model-enable-soft-delete=${fieldOptions.modelEnableSoftDelete}`;
|
|
72
73
|
}
|
|
73
|
-
|
|
74
|
+
|
|
74
75
|
if (fieldOptions.parentModel) {
|
|
75
76
|
modelCommand += ` --parent-model=${fieldOptions.parentModel}`;
|
|
76
77
|
}
|
|
77
|
-
|
|
78
|
+
if (fieldOptions.parentModule) {
|
|
79
|
+
modelCommand += ` --parent-module=${fieldOptions.parentModule}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
78
82
|
let fieldCommand = fieldOptions.fields
|
|
79
83
|
.filter((field) => {
|
|
80
84
|
return !Object.values(SYSTEM_FIELDS_TO_IGNORE_FOR_CODE_GENERATION).includes(field.name);
|
|
81
|
-
})
|
|
85
|
+
})
|
|
82
86
|
.map((field) => {
|
|
83
87
|
return `--fields='${JSON.stringify(field)}'`;
|
|
84
88
|
})
|
|
85
89
|
.join(' ');
|
|
86
|
-
const schematicCommand =
|
|
90
|
+
const schematicCommand = modelCommand + ' ' + fieldCommand;
|
|
87
91
|
// console.log('schematicCommand', schematicCommand);
|
|
88
92
|
return schematicCommand;
|
|
89
93
|
} else if (command === ADD_MODULE_COMMAND) {
|
|
90
94
|
const moduleOptions = options as GenerateModuleOptions;
|
|
91
95
|
// console.log('moduleOptions', moduleOptions);
|
|
92
|
-
const schematicCommand =
|
|
96
|
+
const schematicCommand = ` ${baseCommand} --module=${moduleOptions.module}`;
|
|
93
97
|
// console.log('schematicCommand', schematicCommand);
|
|
94
98
|
this.logger.debug('schematicCommand', schematicCommand);
|
|
95
99
|
return schematicCommand;
|
|
@@ -97,5 +101,5 @@ export class SchematicService {
|
|
|
97
101
|
throw new Error('Schematic command not supported.');
|
|
98
102
|
}
|
|
99
103
|
}
|
|
100
|
-
|
|
104
|
+
|
|
101
105
|
}
|
|
@@ -5355,7 +5355,7 @@
|
|
|
5355
5355
|
{
|
|
5356
5356
|
"type": "field",
|
|
5357
5357
|
"attrs": {
|
|
5358
|
-
"name": "
|
|
5358
|
+
"name": "viewMetadata"
|
|
5359
5359
|
}
|
|
5360
5360
|
}
|
|
5361
5361
|
]
|
|
@@ -5813,7 +5813,7 @@
|
|
|
5813
5813
|
"type": "field",
|
|
5814
5814
|
"attrs": {
|
|
5815
5815
|
"name": "roles",
|
|
5816
|
-
"
|
|
5816
|
+
"widget": "checkbox",
|
|
5817
5817
|
"inlineCreateAutoSave": "true",
|
|
5818
5818
|
"renderModeCheckboxPreprocessor": "MenuItemMetadataRolesFormFieldPreprocessor",
|
|
5819
5819
|
"inlineCreate": "true",
|
|
@@ -5899,7 +5899,7 @@
|
|
|
5899
5899
|
"type": "field",
|
|
5900
5900
|
"attrs": {
|
|
5901
5901
|
"name": "relativeUri",
|
|
5902
|
-
"
|
|
5902
|
+
"widget": "image",
|
|
5903
5903
|
"isSearchable": true
|
|
5904
5904
|
}
|
|
5905
5905
|
},
|
|
@@ -5986,7 +5986,7 @@
|
|
|
5986
5986
|
"attrs": {
|
|
5987
5987
|
"name": "relativeUri",
|
|
5988
5988
|
"label": "relativeUri",
|
|
5989
|
-
"
|
|
5989
|
+
"widget": "image"
|
|
5990
5990
|
}
|
|
5991
5991
|
},
|
|
5992
5992
|
{
|
|
@@ -7029,7 +7029,7 @@
|
|
|
7029
7029
|
"attrs": {
|
|
7030
7030
|
"name": "permissions",
|
|
7031
7031
|
"isSearchable": true,
|
|
7032
|
-
"
|
|
7032
|
+
"widget": "checkbox",
|
|
7033
7033
|
"inlineCreate": "true"
|
|
7034
7034
|
}
|
|
7035
7035
|
},
|
|
@@ -7122,7 +7122,7 @@
|
|
|
7122
7122
|
"type": "field",
|
|
7123
7123
|
"attrs": {
|
|
7124
7124
|
"name": "permissions",
|
|
7125
|
-
"
|
|
7125
|
+
"widget": "inputSwitch",
|
|
7126
7126
|
"showLabel": false
|
|
7127
7127
|
}
|
|
7128
7128
|
}
|
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
RegistrationValidationSource,
|
|
40
40
|
TransactionalRegistrationValidationSource
|
|
41
41
|
} from "../constants";
|
|
42
|
+
import { CreateUserDto } from 'src/dtos/create-user.dto';
|
|
42
43
|
|
|
43
44
|
enum LoginProvider {
|
|
44
45
|
LOCAL = 'local',
|
|
@@ -112,55 +113,15 @@ export class AuthenticationService {
|
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
try {
|
|
115
|
-
|
|
116
|
-
user.username = signUpDto.username;
|
|
117
|
-
user.email = signUpDto.email;
|
|
118
|
-
user.fullName = signUpDto.fullName;
|
|
119
|
-
if (signUpDto.mobile) {
|
|
120
|
-
user.mobile = signUpDto.mobile;
|
|
121
|
-
}
|
|
122
|
-
// If password has been specified by the user, then we simply create & activate the user based on the configuration parameter "activateUserOnRegistration".
|
|
123
|
-
let pwd = '';
|
|
124
|
-
let autoGeneratedPwd = '';
|
|
125
|
-
if (signUpDto.password) {
|
|
126
|
-
pwd = await this.hashingService.hash(signUpDto.password);
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
// TODO: If password is not specified then auto-generate a random password, trigger this password over an email to the user.
|
|
130
|
-
// TODO: Also track if the user has to force reset / change their password, and then activate the user.
|
|
131
|
-
autoGeneratedPwd = this.generatePassword();
|
|
132
|
-
pwd = await this.hashingService.hash(autoGeneratedPwd);
|
|
133
|
-
user.forcePasswordChange = true;
|
|
134
|
-
}
|
|
135
|
-
user.password = pwd;
|
|
136
|
-
user.active = this.iamConfiguration.activateUserOnRegistration;
|
|
116
|
+
var { user, pwd, autoGeneratedPwd } = await this.populateForSignup(new User(), signUpDto, this.iamConfiguration.activateUserOnRegistration);
|
|
137
117
|
const savedUser = await this.userRepository.save(user);
|
|
138
118
|
|
|
139
119
|
// Also assign a default role to the newly created user.
|
|
140
|
-
|
|
120
|
+
const userRoles = signUpDto.roles ?? [];
|
|
141
121
|
if (this.iamConfiguration.defaultRole) {
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
// Default Internal user role assigned
|
|
145
|
-
roles.push("Internal User");
|
|
146
|
-
if (signUpDto.roles) {
|
|
147
|
-
roles = [...roles, ...signUpDto.roles];
|
|
148
|
-
}
|
|
149
|
-
roles = Array.from(new Set([...roles]));
|
|
150
|
-
if (roles.length > 0) {
|
|
151
|
-
this.userService.addRolesToUser(user.username, roles);
|
|
152
|
-
}
|
|
153
|
-
// Tanay: Adding user password to history table
|
|
154
|
-
const userPasswordHistory = new UserPasswordHistory();
|
|
155
|
-
userPasswordHistory.passwordHash = pwd;
|
|
156
|
-
userPasswordHistory.user = savedUser;
|
|
157
|
-
await this.userPasswordHistoryRepository.save(userPasswordHistory);
|
|
158
|
-
|
|
159
|
-
// if forcePasswordChange is true, then we trigger an email to the user to change the password, this needs to be done using a queue.
|
|
160
|
-
// Create a new method like notifyUserOnForcePasswordChange, create a new email template we can call it on-force-password-change this template to include the random password
|
|
161
|
-
if (user.forcePasswordChange && autoGeneratedPwd) {
|
|
162
|
-
this.notifyUserOnForcePasswordChange(user, autoGeneratedPwd);
|
|
122
|
+
userRoles.push(this.iamConfiguration.defaultRole);
|
|
163
123
|
}
|
|
124
|
+
await this.handlePostSignup(savedUser, userRoles, pwd, autoGeneratedPwd);
|
|
164
125
|
|
|
165
126
|
// TODO: make provision to trigger a welcome email also.
|
|
166
127
|
|
|
@@ -174,6 +135,79 @@ export class AuthenticationService {
|
|
|
174
135
|
}
|
|
175
136
|
}
|
|
176
137
|
|
|
138
|
+
async signupForExtensionUser<T extends User, U extends CreateUserDto>(signUpDto: SignUpDto, extensionUserDto: U, extensionUserRepo: Repository<T>): Promise<T> {
|
|
139
|
+
try {
|
|
140
|
+
// Merge the extended signUpDto attributes into the user entity
|
|
141
|
+
//@ts-ignore
|
|
142
|
+
const extensionUser = extensionUserRepo.merge(extensionUserRepo.create() as T, extensionUserDto);
|
|
143
|
+
var { user, pwd, autoGeneratedPwd } = await this.populateForSignup<T>(extensionUser, signUpDto);
|
|
144
|
+
const savedUser = await extensionUserRepo.save(user);
|
|
145
|
+
|
|
146
|
+
await this.handlePostSignup(savedUser, signUpDto.roles, pwd, autoGeneratedPwd);
|
|
147
|
+
|
|
148
|
+
return savedUser;
|
|
149
|
+
}
|
|
150
|
+
catch (err) {
|
|
151
|
+
const pgUniqueViolationErrorCode = '23505';
|
|
152
|
+
if (err.code === pgUniqueViolationErrorCode) {
|
|
153
|
+
throw new ConflictException();
|
|
154
|
+
}
|
|
155
|
+
throw err;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
private async populateForSignup<T extends User>(user: T, signUpDto: SignUpDto, isUserActive: boolean = true) {
|
|
161
|
+
// const user = new User();
|
|
162
|
+
user.username = signUpDto.username;
|
|
163
|
+
user.email = signUpDto.email;
|
|
164
|
+
user.fullName = signUpDto.fullName;
|
|
165
|
+
if (signUpDto.mobile) {
|
|
166
|
+
user.mobile = signUpDto.mobile;
|
|
167
|
+
}
|
|
168
|
+
// If password has been specified by the user, then we simply create & activate the user based on the configuration parameter "activateUserOnRegistration".
|
|
169
|
+
let pwd = '';
|
|
170
|
+
let autoGeneratedPwd = '';
|
|
171
|
+
if (signUpDto.password) {
|
|
172
|
+
pwd = await this.hashingService.hash(signUpDto.password);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
// TODO: If password is not specified then auto-generate a random password, trigger this password over an email to the user.
|
|
176
|
+
// TODO: Also track if the user has to force reset / change their password, and then activate the user.
|
|
177
|
+
autoGeneratedPwd = this.generatePassword();
|
|
178
|
+
pwd = await this.hashingService.hash(autoGeneratedPwd);
|
|
179
|
+
user.forcePasswordChange = true;
|
|
180
|
+
}
|
|
181
|
+
user.password = pwd;
|
|
182
|
+
// user.active = this.iamConfiguration.activateUserOnRegistration;
|
|
183
|
+
user.active = isUserActive;
|
|
184
|
+
return { user, pwd, autoGeneratedPwd };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private async handlePostSignup(user: User, roles: string[]=[], pwd: string, autoGeneratedPwd: string) {
|
|
188
|
+
let userRoles = [];
|
|
189
|
+
// Default Internal user role assigned
|
|
190
|
+
userRoles.push("Internal User");
|
|
191
|
+
if (roles) {
|
|
192
|
+
userRoles = [...userRoles, ...roles];
|
|
193
|
+
}
|
|
194
|
+
userRoles = Array.from(new Set([...userRoles]));
|
|
195
|
+
if (userRoles.length > 0) {
|
|
196
|
+
this.userService.addRolesToUser(user.username, userRoles);
|
|
197
|
+
}
|
|
198
|
+
// Tanay: Adding user password to history table
|
|
199
|
+
const userPasswordHistory = new UserPasswordHistory();
|
|
200
|
+
userPasswordHistory.passwordHash = pwd;
|
|
201
|
+
userPasswordHistory.user = user;
|
|
202
|
+
await this.userPasswordHistoryRepository.save(userPasswordHistory);
|
|
203
|
+
|
|
204
|
+
// if forcePasswordChange is true, then we trigger an email to the user to change the password, this needs to be done using a queue.
|
|
205
|
+
// Create a new method like notifyUserOnForcePasswordChange, create a new email template we can call it on-force-password-change this template to include the random password
|
|
206
|
+
if (user.forcePasswordChange && autoGeneratedPwd) {
|
|
207
|
+
this.notifyUserOnForcePasswordChange(user, autoGeneratedPwd);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
177
211
|
generatePassword(length: number = 8): string {
|
|
178
212
|
const upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
179
213
|
const lowerCase = "abcdefghijklmnopqrstuvwxyz";
|
|
@@ -975,7 +1009,14 @@ export class AuthenticationService {
|
|
|
975
1009
|
const tokens = await this.generateTokens(user);
|
|
976
1010
|
|
|
977
1011
|
const response = {
|
|
978
|
-
|
|
1012
|
+
user: {
|
|
1013
|
+
email: user.email,
|
|
1014
|
+
mobile: user.mobile,
|
|
1015
|
+
username: user.username,
|
|
1016
|
+
// forcePasswordChange: user.forcePasswordChange,
|
|
1017
|
+
id: user.id,
|
|
1018
|
+
roles: user.roles.map((role, idx, roles) => role.name)
|
|
1019
|
+
},
|
|
979
1020
|
...tokens
|
|
980
1021
|
}
|
|
981
1022
|
return response;
|
|
@@ -308,7 +308,7 @@ export class FieldMetadataService {
|
|
|
308
308
|
// return this.moduleMetadataRepo.save(country);
|
|
309
309
|
// }
|
|
310
310
|
|
|
311
|
-
async
|
|
311
|
+
async delete(id: number) {
|
|
312
312
|
const entity = await this.findOne(id);
|
|
313
313
|
return this.fieldMetadataRepo.remove(entity);
|
|
314
314
|
}
|
|
@@ -855,9 +855,7 @@ export class FieldMetadataService {
|
|
|
855
855
|
"encrypt",
|
|
856
856
|
"encryptionType",
|
|
857
857
|
"decryptWhen",
|
|
858
|
-
"columnName"
|
|
859
|
-
"isUserKey"
|
|
860
|
-
|
|
858
|
+
"columnName"
|
|
861
859
|
];
|
|
862
860
|
|
|
863
861
|
case SolidFieldType.selectionDynamic:
|
|
@@ -622,8 +622,8 @@ export class ModelMetadataService {
|
|
|
622
622
|
dataSourceType: model.dataSourceType,
|
|
623
623
|
tableName: model.tableName,
|
|
624
624
|
userKeyFieldUserKey: model.fields.find(field => field.isUserKey)?.name,
|
|
625
|
-
isChild: model
|
|
626
|
-
parentModelUserKey: model
|
|
625
|
+
isChild: model?.isChild,
|
|
626
|
+
parentModelUserKey: model?.parentModel?.singularName,
|
|
627
627
|
fields: []
|
|
628
628
|
}
|
|
629
629
|
|
|
@@ -897,7 +897,7 @@ export class ModelMetadataService {
|
|
|
897
897
|
// Remove the fields from the database as well. This also checks, if the field is marked for removal
|
|
898
898
|
fieldsForRemoval.forEach((field: FieldMetadata) => {
|
|
899
899
|
if (field.isMarkedForRemoval) {
|
|
900
|
-
this.fieldMetadataService.
|
|
900
|
+
this.fieldMetadataService.delete(field.id);
|
|
901
901
|
}
|
|
902
902
|
});
|
|
903
903
|
return removeOutput;
|
|
@@ -909,7 +909,7 @@ export class ModelMetadataService {
|
|
|
909
909
|
}
|
|
910
910
|
|
|
911
911
|
const query = {
|
|
912
|
-
populate: ["module", "fields", "parentModel"]
|
|
912
|
+
populate: ["module", "fields", "parentModel", "parentModel.module"]
|
|
913
913
|
};
|
|
914
914
|
const model = options.modelId ? await this.findOne(options.modelId, query) : await this.findOneByUserKey(options.modelUserKey, query.populate);
|
|
915
915
|
|
|
@@ -932,7 +932,9 @@ export class ModelMetadataService {
|
|
|
932
932
|
table: model.tableName,
|
|
933
933
|
fields: fieldsForRefresh,
|
|
934
934
|
modelEnableSoftDelete: model.enableSoftDelete,
|
|
935
|
-
parentModel: model.parentModel?.singularName
|
|
935
|
+
parentModel: model.parentModel?.singularName,
|
|
936
|
+
parentModule: model.parentModel?.module?.name,
|
|
937
|
+
|
|
936
938
|
},
|
|
937
939
|
dryRun
|
|
938
940
|
);
|