@volcanicminds/typeorm 0.1.1 → 0.1.3
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/lib/entities/user.d.ts +1 -0
- package/dist/lib/entities/user.js.map +1 -1
- package/dist/lib/loader/userManager.d.ts +1 -1
- package/dist/lib/loader/userManager.js +17 -9
- package/dist/lib/loader/userManager.js.map +1 -1
- package/esm/lib/entities/user.d.ts +1 -0
- package/esm/lib/entities/user.js.map +1 -1
- package/esm/lib/loader/userManager.d.ts +1 -1
- package/esm/lib/loader/userManager.js +22 -8
- package/esm/lib/loader/userManager.js.map +1 -1
- package/package.json +1 -1
|
@@ -11,6 +11,7 @@ export declare abstract class User extends BaseEntity {
|
|
|
11
11
|
abstract blockedReason: string;
|
|
12
12
|
abstract blockedAt: Date;
|
|
13
13
|
abstract resetPasswordToken: string;
|
|
14
|
+
abstract confirmationToken: string;
|
|
14
15
|
abstract roles: string[];
|
|
15
16
|
abstract version: number;
|
|
16
17
|
abstract createdAt: Date;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../../lib/entities/user.ts"],"names":[],"mappings":";;;AAAA,qCAAoC;AAEpC,MAAsB,IAAK,SAAQ,oBAAU;
|
|
1
|
+
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../../lib/entities/user.ts"],"names":[],"mappings":";;;AAAA,qCAAoC;AAEpC,MAAsB,IAAK,SAAQ,oBAAU;CAkB5C;AAlBD,oBAkBC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export declare function demo(): Promise<never[]>;
|
|
2
1
|
export declare function isValidUser(data: typeof global.entity.User): Promise<boolean>;
|
|
3
2
|
export declare function createUser(data: typeof global.entity.User): Promise<any>;
|
|
4
3
|
export declare function resetExternalId(id: string): Promise<any>;
|
|
@@ -10,5 +9,6 @@ export declare function retrieveUserByPassword(email: string, password: string):
|
|
|
10
9
|
export declare function changePassword(email: string, password: string, oldPassword: string): Promise<any>;
|
|
11
10
|
export declare function forgotPassword(email: string): Promise<any>;
|
|
12
11
|
export declare function resetPassword(user: typeof global.entity.User, password: string): Promise<any>;
|
|
12
|
+
export declare function userConfirmation(user: typeof global.entity.User): Promise<any>;
|
|
13
13
|
export declare function blockUserById(id: string, reason: string): Promise<any>;
|
|
14
14
|
export declare function unblockUserById(id: string): Promise<any>;
|
|
@@ -43,15 +43,9 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
43
43
|
return t;
|
|
44
44
|
};
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.unblockUserById = exports.blockUserById = exports.resetPassword = exports.forgotPassword = exports.changePassword = exports.retrieveUserByPassword = exports.retrieveUserByExternalId = exports.retrieveUserByEmail = exports.retrieveUserById = exports.updateUserById = exports.resetExternalId = exports.createUser = exports.isValidUser =
|
|
46
|
+
exports.unblockUserById = exports.blockUserById = exports.userConfirmation = exports.resetPassword = exports.forgotPassword = exports.changePassword = exports.retrieveUserByPassword = exports.retrieveUserByExternalId = exports.retrieveUserByEmail = exports.retrieveUserById = exports.updateUserById = exports.resetExternalId = exports.createUser = exports.isValidUser = void 0;
|
|
47
47
|
const bcrypt = __importStar(require("bcrypt"));
|
|
48
48
|
const Crypto = require('crypto');
|
|
49
|
-
function demo() {
|
|
50
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
return [];
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
exports.demo = demo;
|
|
55
49
|
function isValidUser(data) {
|
|
56
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
51
|
return !!data && !!data.id && !!data.externalId && !!data.email && !!data.password;
|
|
@@ -72,7 +66,7 @@ function createUser(data) {
|
|
|
72
66
|
externalId = Crypto.randomUUID({ disableEntropyCache: true });
|
|
73
67
|
user = yield global.repository.users.findOneBy({ externalId: externalId });
|
|
74
68
|
} while (user != null);
|
|
75
|
-
user = yield global.entity.User.create(Object.assign(Object.assign({}, data), { confirmed:
|
|
69
|
+
user = yield global.entity.User.create(Object.assign(Object.assign({}, data), { confirmed: false, confirmationToken: Crypto.randomBytes(64).toString('hex'), blocked: false, blockedReason: null, externalId: externalId, email: email, username: username || email, password: hashedPassword }));
|
|
76
70
|
return yield global.entity.User.save(user);
|
|
77
71
|
}
|
|
78
72
|
catch (error) {
|
|
@@ -234,7 +228,7 @@ function resetPassword(user, password) {
|
|
|
234
228
|
try {
|
|
235
229
|
const salt = yield bcrypt.genSalt(12);
|
|
236
230
|
const hashedPassword = yield bcrypt.hash(password, salt);
|
|
237
|
-
return yield global.entity.User.save(Object.assign(Object.assign({}, user), { resetPasswordToken: null, password: hashedPassword }));
|
|
231
|
+
return yield global.entity.User.save(Object.assign(Object.assign({}, user), { confirmed: true, confirmedAt: new Date(), resetPasswordToken: null, password: hashedPassword }));
|
|
238
232
|
}
|
|
239
233
|
catch (error) {
|
|
240
234
|
throw error;
|
|
@@ -242,6 +236,20 @@ function resetPassword(user, password) {
|
|
|
242
236
|
});
|
|
243
237
|
}
|
|
244
238
|
exports.resetPassword = resetPassword;
|
|
239
|
+
function userConfirmation(user) {
|
|
240
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
+
if (!user) {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
try {
|
|
245
|
+
return yield global.entity.User.save(Object.assign(Object.assign({}, user), { confirmed: true, confirmedAt: new Date(), confirmationToken: null }));
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
throw error;
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
exports.userConfirmation = userConfirmation;
|
|
245
253
|
function blockUserById(id, reason) {
|
|
246
254
|
return __awaiter(this, void 0, void 0, function* () {
|
|
247
255
|
return updateUserById(id, { blocked: true, blockedAt: new Date(), blockedReason: reason });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userManager.js","sourceRoot":"","sources":["../../../lib/loader/userManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAgC;AAChC,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEhC,SAAsB,
|
|
1
|
+
{"version":3,"file":"userManager.js","sourceRoot":"","sources":["../../../lib/loader/userManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAgC;AAChC,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEhC,SAAsB,WAAW,CAAC,IAA+B;;QAE/D,OAAO,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAA;IACpF,CAAC;CAAA;AAHD,kCAGC;AAED,SAAsB,UAAU,CAAC,IAA+B;;QAC9D,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAA;QAE1C,IAAI,CAAC,KAAK,IAAI,CAAC,QAAQ,EAAE;YACvB,OAAO,IAAI,CAAA;SACZ;QAED,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;QACrC,MAAM,cAAc,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;QAExD,IAAI;YACF,IAAI,UAAU,EAAE,IAAI,CAAA;YACpB,GAAG;gBACD,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,EAAE,mBAAmB,EAAE,IAAI,EAAE,CAAC,CAAA;gBAE7D,IAAI,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAA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CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;IAC3F,CAAC;CAAA;AAFD,0CAEC"}
|
|
@@ -11,6 +11,7 @@ export declare abstract class User extends BaseEntity {
|
|
|
11
11
|
abstract blockedReason: string;
|
|
12
12
|
abstract blockedAt: Date;
|
|
13
13
|
abstract resetPasswordToken: string;
|
|
14
|
+
abstract confirmationToken: string;
|
|
14
15
|
abstract roles: string[];
|
|
15
16
|
abstract version: number;
|
|
16
17
|
abstract createdAt: Date;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../../lib/entities/user.ts"],"names":[],"mappings":";;;AAAA,qCAAoC;AAEpC,MAAsB,IAAK,SAAQ,oBAAU;
|
|
1
|
+
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../../lib/entities/user.ts"],"names":[],"mappings":";;;AAAA,qCAAoC;AAEpC,MAAsB,IAAK,SAAQ,oBAAU;CAkB5C;AAlBD,oBAkBC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export declare function demo(): Promise<never[]>;
|
|
2
1
|
export declare function isValidUser(data: typeof global.entity.User): Promise<boolean>;
|
|
3
2
|
export declare function createUser(data: typeof global.entity.User): Promise<any>;
|
|
4
3
|
export declare function resetExternalId(id: string): Promise<any>;
|
|
@@ -10,5 +9,6 @@ export declare function retrieveUserByPassword(email: string, password: string):
|
|
|
10
9
|
export declare function changePassword(email: string, password: string, oldPassword: string): Promise<any>;
|
|
11
10
|
export declare function forgotPassword(email: string): Promise<any>;
|
|
12
11
|
export declare function resetPassword(user: typeof global.entity.User, password: string): Promise<any>;
|
|
12
|
+
export declare function userConfirmation(user: typeof global.entity.User): Promise<any>;
|
|
13
13
|
export declare function blockUserById(id: string, reason: string): Promise<any>;
|
|
14
14
|
export declare function unblockUserById(id: string): Promise<any>;
|
|
@@ -23,13 +23,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.unblockUserById = exports.blockUserById = exports.resetPassword = exports.forgotPassword = exports.changePassword = exports.retrieveUserByPassword = exports.retrieveUserByExternalId = exports.retrieveUserByEmail = exports.retrieveUserById = exports.updateUserById = exports.resetExternalId = exports.createUser = exports.isValidUser =
|
|
26
|
+
exports.unblockUserById = exports.blockUserById = exports.userConfirmation = exports.resetPassword = exports.forgotPassword = exports.changePassword = exports.retrieveUserByPassword = exports.retrieveUserByExternalId = exports.retrieveUserByEmail = exports.retrieveUserById = exports.updateUserById = exports.resetExternalId = exports.createUser = exports.isValidUser = void 0;
|
|
27
27
|
const bcrypt = __importStar(require("bcrypt"));
|
|
28
28
|
const Crypto = require('crypto');
|
|
29
|
-
async function demo() {
|
|
30
|
-
return [];
|
|
31
|
-
}
|
|
32
|
-
exports.demo = demo;
|
|
33
29
|
async function isValidUser(data) {
|
|
34
30
|
return !!data && !!data.id && !!data.externalId && !!data.email && !!data.password;
|
|
35
31
|
}
|
|
@@ -49,8 +45,8 @@ async function createUser(data) {
|
|
|
49
45
|
} while (user != null);
|
|
50
46
|
user = await global.entity.User.create({
|
|
51
47
|
...data,
|
|
52
|
-
confirmed:
|
|
53
|
-
|
|
48
|
+
confirmed: false,
|
|
49
|
+
confirmationToken: Crypto.randomBytes(64).toString('hex'),
|
|
54
50
|
blocked: false,
|
|
55
51
|
blockedReason: null,
|
|
56
52
|
externalId: externalId,
|
|
@@ -201,13 +197,31 @@ async function resetPassword(user, password) {
|
|
|
201
197
|
try {
|
|
202
198
|
const salt = await bcrypt.genSalt(12);
|
|
203
199
|
const hashedPassword = await bcrypt.hash(password, salt);
|
|
204
|
-
return await global.entity.User.save({
|
|
200
|
+
return await global.entity.User.save({
|
|
201
|
+
...user,
|
|
202
|
+
confirmed: true,
|
|
203
|
+
confirmedAt: new Date(),
|
|
204
|
+
resetPasswordToken: null,
|
|
205
|
+
password: hashedPassword
|
|
206
|
+
});
|
|
205
207
|
}
|
|
206
208
|
catch (error) {
|
|
207
209
|
throw error;
|
|
208
210
|
}
|
|
209
211
|
}
|
|
210
212
|
exports.resetPassword = resetPassword;
|
|
213
|
+
async function userConfirmation(user) {
|
|
214
|
+
if (!user) {
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
return await global.entity.User.save({ ...user, confirmed: true, confirmedAt: new Date(), confirmationToken: null });
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
throw error;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
exports.userConfirmation = userConfirmation;
|
|
211
225
|
async function blockUserById(id, reason) {
|
|
212
226
|
return updateUserById(id, { blocked: true, blockedAt: new Date(), blockedReason: reason });
|
|
213
227
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userManager.js","sourceRoot":"","sources":["../../../lib/loader/userManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAgC;AAChC,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEzB,KAAK,UAAU,
|
|
1
|
+
{"version":3,"file":"userManager.js","sourceRoot":"","sources":["../../../lib/loader/userManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAgC;AAChC,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEzB,KAAK,UAAU,WAAW,CAAC,IAA+B;IAE/D,OAAO,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAA;AACpF,CAAC;AAHD,kCAGC;AAEM,KAAK,UAAU,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