@adaptivestone/framework 4.0.0 → 4.2.0
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/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
### 4.
|
|
1
|
+
### 4.2.0
|
|
2
|
+
|
|
3
|
+
[UPDATE] updated deps
|
|
4
|
+
[NEW] CreateUser cli command. Ability to update user by email or id.
|
|
5
|
+
|
|
6
|
+
### 4.1.0
|
|
7
|
+
|
|
8
|
+
[UPDATE] updated deps
|
|
9
|
+
[NEW] email - Ability to render templae to string for future usage
|
|
10
|
+
|
|
11
|
+
### 4.0.0
|
|
2
12
|
|
|
3
13
|
[BREAKING] change bcrypt encryption with scrypt
|
|
4
14
|
[BREAKING] change internal express parser to formidable parser. Affect you if external formidable is used
|
|
@@ -266,9 +276,8 @@ const someTypeSequence = await SequenceModel.getSequence('someType');
|
|
|
266
276
|
// will be 2
|
|
267
277
|
const someTypeSequence2 = await SequenceModel.getSequence('someType');
|
|
268
278
|
// will be 1 as type is another
|
|
269
|
-
const someAnotherTypeSequence =
|
|
270
|
-
'someAnotherType'
|
|
271
|
-
);
|
|
279
|
+
const someAnotherTypeSequence =
|
|
280
|
+
await SequenceModel.getSequence('someAnotherType');
|
|
272
281
|
```
|
|
273
282
|
|
|
274
283
|
#### 2.13.1
|
package/commands/CreateUser.js
CHANGED
|
@@ -4,21 +4,63 @@ const AbstractCommand = require('../modules/AbstractCommand');
|
|
|
4
4
|
class CreateUser extends AbstractCommand {
|
|
5
5
|
async run() {
|
|
6
6
|
const User = this.app.getModel('User');
|
|
7
|
-
const { email, password, roles } = this.args;
|
|
7
|
+
const { id, email, password, roles, update } = this.args;
|
|
8
8
|
|
|
9
|
-
if (!email
|
|
9
|
+
if (!email && !id) {
|
|
10
10
|
this.logger.error('Input validation failded');
|
|
11
|
-
this.logger.error('Please add "email"
|
|
11
|
+
this.logger.error('Please add "email" or "id" variables');
|
|
12
12
|
return false;
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
|
|
15
|
+
let user;
|
|
16
|
+
|
|
17
|
+
if (id) {
|
|
18
|
+
user = await User.findOne({ _id: id });
|
|
19
|
+
} else if (email) {
|
|
20
|
+
user = await User.findOne({ email });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (user && !update) {
|
|
24
|
+
this.logger.error(
|
|
25
|
+
'We are found a user in database. But "update" option is not providing. Exitin',
|
|
26
|
+
);
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!user && !password) {
|
|
31
|
+
this.logger.error(
|
|
32
|
+
'For a new user we alway asking for a password. Please provide it and rerun command',
|
|
33
|
+
);
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!user && !email) {
|
|
38
|
+
this.logger.error(
|
|
39
|
+
'For a new user we alway asking for a email. Please provide it and rerun command',
|
|
40
|
+
);
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!user) {
|
|
45
|
+
user = new User();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (password) {
|
|
49
|
+
user.password = password;
|
|
50
|
+
}
|
|
51
|
+
if (email) {
|
|
52
|
+
user.email = email;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (roles) {
|
|
56
|
+
user.roles = roles.split(',');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
await user.save();
|
|
60
|
+
|
|
19
61
|
await user.generateToken();
|
|
20
62
|
|
|
21
|
-
this.logger.info(`User was created ${JSON.stringify(user, 0, 4)}`);
|
|
63
|
+
this.logger.info(`User was created/updated ${JSON.stringify(user, 0, 4)}`);
|
|
22
64
|
|
|
23
65
|
return user;
|
|
24
66
|
}
|
package/models/User.js
CHANGED
|
@@ -174,9 +174,8 @@ class User extends AbstractModel {
|
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
async sendPasswordRecoveryEmail(i18n) {
|
|
177
|
-
const passwordRecoveryToken =
|
|
178
|
-
this
|
|
179
|
-
);
|
|
177
|
+
const passwordRecoveryToken =
|
|
178
|
+
await User.generateUserPasswordRecoveryToken(this);
|
|
180
179
|
const mail = new Mailer(
|
|
181
180
|
this.constructor.getSuper().app,
|
|
182
181
|
'recovery',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaptivestone/framework",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Adaptive stone node js framework",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"engines": {
|
|
@@ -64,11 +64,11 @@
|
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"eslint": "^8.0.0",
|
|
66
66
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
67
|
-
"eslint-config-prettier": "^
|
|
67
|
+
"eslint-config-prettier": "^9.0.0",
|
|
68
68
|
"eslint-plugin-jest": "^27.0.0",
|
|
69
69
|
"husky": "^8.0.0",
|
|
70
70
|
"jest": "^29.0.0",
|
|
71
|
-
"lint-staged": "^
|
|
71
|
+
"lint-staged": "^14.0.0",
|
|
72
72
|
"mongodb-memory-server": "^8.0.2",
|
|
73
73
|
"nodemon": "^3.0.1",
|
|
74
74
|
"prettier": "^3.0.0",
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
const RateLimiter = require('./RateLimiter');
|
|
2
2
|
|
|
3
3
|
describe('rate limiter methods', () => {
|
|
4
|
+
it('have description fields', async () => {
|
|
5
|
+
expect.assertions(1);
|
|
6
|
+
const middleware = new RateLimiter(global.server.app, {
|
|
7
|
+
driver: 'redis',
|
|
8
|
+
});
|
|
9
|
+
expect(middleware.constructor.description).toBeDefined();
|
|
10
|
+
});
|
|
11
|
+
|
|
4
12
|
it('can create redis rateLimiter', async () => {
|
|
5
13
|
expect.assertions(1);
|
|
6
14
|
|
|
@@ -59,7 +59,7 @@ class Mail extends Base {
|
|
|
59
59
|
* @param {object} templateData
|
|
60
60
|
* @returns string
|
|
61
61
|
*/
|
|
62
|
-
static async #
|
|
62
|
+
static async #renderTemplateFile({ type, fullPath } = {}, templateData = {}) {
|
|
63
63
|
if (!type) {
|
|
64
64
|
return null;
|
|
65
65
|
}
|
|
@@ -79,13 +79,10 @@ class Mail extends Base {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
|
-
*
|
|
83
|
-
* @param {string} to email send to
|
|
84
|
-
* @param {string} [from = mailConfig.from]
|
|
85
|
-
* @param {object} [aditionalNodemailerOptions = {}] additional option to nodemailer
|
|
82
|
+
* Render template
|
|
86
83
|
* @return {Promise}
|
|
87
84
|
*/
|
|
88
|
-
async
|
|
85
|
+
async renderTemplate() {
|
|
89
86
|
const files = await fs.promises.readdir(this.template);
|
|
90
87
|
const templates = {};
|
|
91
88
|
for (const file of files) {
|
|
@@ -112,13 +109,19 @@ class Mail extends Base {
|
|
|
112
109
|
|
|
113
110
|
const [htmlRendered, subjectRendered, textRendered, extraCss] =
|
|
114
111
|
await Promise.all([
|
|
115
|
-
this.constructor.#
|
|
116
|
-
|
|
112
|
+
this.constructor.#renderTemplateFile(
|
|
113
|
+
templates.html,
|
|
114
|
+
templateDataToRender,
|
|
115
|
+
),
|
|
116
|
+
this.constructor.#renderTemplateFile(
|
|
117
117
|
templates.subject,
|
|
118
118
|
templateDataToRender,
|
|
119
119
|
),
|
|
120
|
-
this.constructor.#
|
|
121
|
-
|
|
120
|
+
this.constructor.#renderTemplateFile(
|
|
121
|
+
templates.text,
|
|
122
|
+
templateDataToRender,
|
|
123
|
+
),
|
|
124
|
+
this.constructor.#renderTemplateFile(templates.style),
|
|
122
125
|
]);
|
|
123
126
|
|
|
124
127
|
juice.tableElements = ['TABLE'];
|
|
@@ -130,13 +133,30 @@ class Mail extends Base {
|
|
|
130
133
|
webResources: mailConfig.webResources,
|
|
131
134
|
extraCss,
|
|
132
135
|
});
|
|
136
|
+
return {
|
|
137
|
+
htmlRaw: htmlRendered,
|
|
138
|
+
subject: subjectRendered,
|
|
139
|
+
text: textRendered,
|
|
140
|
+
inlinedHTML,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Send email
|
|
146
|
+
* @param {string} to email send to
|
|
147
|
+
* @param {string} [from = mailConfig.from]
|
|
148
|
+
* @param {object} [aditionalNodemailerOptions = {}] additional option to nodemailer
|
|
149
|
+
* @return {Promise}
|
|
150
|
+
*/
|
|
151
|
+
async send(to, from = null, aditionalNodemailerOptions = {}) {
|
|
152
|
+
const { subject, text, inlinedHTML } = await this.renderTemplate();
|
|
133
153
|
|
|
134
154
|
return this.constructor.sendRaw(
|
|
135
155
|
this.app,
|
|
136
156
|
to,
|
|
137
|
-
|
|
157
|
+
subject,
|
|
138
158
|
inlinedHTML,
|
|
139
|
-
|
|
159
|
+
text,
|
|
140
160
|
from,
|
|
141
161
|
aditionalNodemailerOptions,
|
|
142
162
|
);
|