ztechno_core 0.0.58 → 0.0.60
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/lib/express.d.ts +6 -0
- package/lib/express.js +18 -0
- package/lib/mail_service.d.ts +3 -2
- package/lib/mail_service.js +9 -2
- package/package.json +3 -1
package/lib/express.d.ts
ADDED
package/lib/express.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
exports.middleware = void 0;
|
|
4
|
+
function middleware() {
|
|
5
|
+
return async (req, res, next) => {
|
|
6
|
+
if (req.cookies === undefined) {
|
|
7
|
+
throw new Error(`Module 'cookie-parser' isn't initialized. Please use app.use(cookieParser())`);
|
|
8
|
+
}
|
|
9
|
+
if (req.cookies?.session === undefined) {
|
|
10
|
+
return next();
|
|
11
|
+
}
|
|
12
|
+
const auth = await userService.auth({ session: req.cookies?.session });
|
|
13
|
+
req.user = auth.user;
|
|
14
|
+
// TODO: Implement assertAdmin or something like that
|
|
15
|
+
next();
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
exports.middleware = middleware;
|
package/lib/mail_service.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { MailOptionsHtml, MailOptionsText, MailResponse, MailServiceOptions } from './typings/mail_types';
|
|
1
|
+
import { MailOptions, MailOptionsHtml, MailOptionsText, MailResponse, MailServiceOptions } from './typings/mail_types';
|
|
2
2
|
export declare class ZMailService {
|
|
3
3
|
private opt;
|
|
4
4
|
protected get sql(): import('./sql_service').ZSqlService;
|
|
5
5
|
constructor(opt: MailServiceOptions);
|
|
6
|
-
|
|
6
|
+
protected allowSend(mailOpts: MailOptions): Promise<boolean>;
|
|
7
|
+
send(mailOpts: MailOptionsText | MailOptionsHtml): Promise<MailResponse | undefined>;
|
|
7
8
|
}
|
package/lib/mail_service.js
CHANGED
|
@@ -14,7 +14,14 @@ class ZMailService {
|
|
|
14
14
|
constructor(opt) {
|
|
15
15
|
this.opt = opt;
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
async allowSend(mailOpts) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
async send(mailOpts) {
|
|
21
|
+
const allow = await this.allowSend(mailOpts);
|
|
22
|
+
if (!allow) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
18
25
|
const mailTransporter = nodemailer_1.default.createTransport({
|
|
19
26
|
service: 'gmail',
|
|
20
27
|
auth: this.opt.auth,
|
|
@@ -28,7 +35,7 @@ class ZMailService {
|
|
|
28
35
|
dkim: this.opt.dkim ?? mailOpts.dkim,
|
|
29
36
|
priority: mailOpts.priority,
|
|
30
37
|
};
|
|
31
|
-
return new Promise((resolve, reject) => {
|
|
38
|
+
return await new Promise((resolve, reject) => {
|
|
32
39
|
mailTransporter.sendMail(mailDetails, function (err, data) {
|
|
33
40
|
return err ? reject(err) : resolve(data);
|
|
34
41
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ztechno_core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.60",
|
|
4
4
|
"description": "Core files for ztechno framework",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -38,7 +38,9 @@
|
|
|
38
38
|
"typescript": "^4.9.3"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
+
"@types/express": "^5.0.0",
|
|
41
42
|
"dom-parser": "^0.1.6",
|
|
43
|
+
"express": "^4.21.2",
|
|
42
44
|
"mysql": "^2.18.1",
|
|
43
45
|
"nodemailer": "^6.8.0",
|
|
44
46
|
"translate": "^1.4.1"
|