@adaptivestone/framework 4.0.0 → 4.1.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,9 @@
1
- ### 4.0.0 - DEV
1
+ ### 4.1.0
2
+
3
+ [UPDATE] updated deps
4
+ [NEW] email - Ability to render templae to string for future usage
5
+
6
+ ### 4.0.0
2
7
 
3
8
  [BREAKING] change bcrypt encryption with scrypt
4
9
  [BREAKING] change internal express parser to formidable parser. Affect you if external formidable is used
@@ -266,9 +271,8 @@ const someTypeSequence = await SequenceModel.getSequence('someType');
266
271
  // will be 2
267
272
  const someTypeSequence2 = await SequenceModel.getSequence('someType');
268
273
  // will be 1 as type is another
269
- const someAnotherTypeSequence = await SequenceModel.getSequence(
270
- 'someAnotherType',
271
- );
274
+ const someAnotherTypeSequence =
275
+ await SequenceModel.getSequence('someAnotherType');
272
276
  ```
273
277
 
274
278
  #### 2.13.1
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 = await User.generateUserPasswordRecoveryToken(
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.0.0",
3
+ "version": "4.1.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": "^8.3.0",
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": "^13.0.0",
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",
@@ -59,7 +59,7 @@ class Mail extends Base {
59
59
  * @param {object} templateData
60
60
  * @returns string
61
61
  */
62
- static async #renderTemplate({ type, fullPath } = {}, templateData = {}) {
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
- * Send email
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 send(to, from = null, aditionalNodemailerOptions = {}) {
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.#renderTemplate(templates.html, templateDataToRender),
116
- this.constructor.#renderTemplate(
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.#renderTemplate(templates.text, templateDataToRender),
121
- this.constructor.#renderTemplate(templates.style),
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
- subjectRendered,
157
+ subject,
138
158
  inlinedHTML,
139
- textRendered,
159
+ text,
140
160
  from,
141
161
  aditionalNodemailerOptions,
142
162
  );