namirasoft-node 1.3.76 → 1.3.77
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/BaseTable.d.ts +2 -2
- package/dist/BaseTable.js.map +1 -1
- package/package.json +1 -1
- package/src/AnomalyDetector.ts +84 -84
- package/src/BaseApplication.ts +435 -435
- package/src/BaseApplicationLink.ts +6 -6
- package/src/BaseController.ts +193 -193
- package/src/BaseCron.ts +54 -54
- package/src/BaseDatabase.ts +192 -192
- package/src/BaseEmailService.ts +38 -38
- package/src/BaseTable.ts +104 -104
- package/src/CommandOperation.ts +32 -32
- package/src/EmptyDatabase.ts +7 -7
- package/src/EnvService.ts +22 -22
- package/src/GmailService.ts +22 -22
- package/src/IPOperation.ts +38 -38
- package/src/Meta.ts +40 -40
- package/src/OTPOperation.ts +64 -64
- package/src/RequestHeaderService.ts +27 -27
- package/src/SMTPService.ts +26 -26
- package/src/ServerToServerOperation.ts +23 -23
- package/src/index.ts +17 -17
- package/dist/CMDOperation.d.ts +0 -4
- package/dist/CMDOperation.js +0 -43
- package/dist/CMDOperation.js.map +0 -1
- package/dist/EmailService.d.ts +0 -16
- package/dist/EmailService.js +0 -81
- package/dist/EmailService.js.map +0 -1
package/src/OTPOperation.ts
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import { ErrorOperation, TimeOperation } from "namirasoft-core";
|
|
2
|
-
|
|
3
|
-
export class OTPOperation
|
|
4
|
-
{
|
|
5
|
-
static generate(length: number = 6, digit: number = 3)
|
|
6
|
-
{
|
|
7
|
-
if (!length)
|
|
8
|
-
length = 6;
|
|
9
|
-
if (!digit)
|
|
10
|
-
digit = 3;
|
|
11
|
-
let dig = [];
|
|
12
|
-
for (let i = 0; i < digit; i++)
|
|
13
|
-
dig[i] = parseInt((Math.random() * 9 + 1) + "");
|
|
14
|
-
let ans = '';
|
|
15
|
-
for (let i = 0; i < length; i++)
|
|
16
|
-
ans = ans + '' + dig[parseInt((Math.random() * dig.length) + "")];
|
|
17
|
-
return ans;
|
|
18
|
-
}
|
|
19
|
-
static getWaitTime(min_wait_time: number, max_wait_time: number, min_attempt: number, user_attemptted: number, increase_power_base: number = 2): number
|
|
20
|
-
{
|
|
21
|
-
let wait_time = min_wait_time;
|
|
22
|
-
let extra_attempt = user_attemptted - min_attempt;
|
|
23
|
-
if (extra_attempt > 0)
|
|
24
|
-
wait_time = Math.min(Math.pow(increase_power_base, extra_attempt) * 60, max_wait_time);
|
|
25
|
-
return parseInt(wait_time + "");
|
|
26
|
-
}
|
|
27
|
-
static async onSafeRequest(handler: () => Promise<void>, min_wait_time: number, max_wait_time: number, min_try_count: number, user_tried_time: Date, user_tried_count: number, increase_power_base: number = 2)
|
|
28
|
-
{
|
|
29
|
-
// check wait time
|
|
30
|
-
let wait_time = this.getWaitTime(min_wait_time, max_wait_time, min_try_count, user_tried_count, increase_power_base);
|
|
31
|
-
let wait_date = TimeOperation.minutesAgo(wait_time, new Date());
|
|
32
|
-
let next_time = TimeOperation.diffInSecond(user_tried_time, wait_date, false);
|
|
33
|
-
if (next_time > 0)
|
|
34
|
-
{
|
|
35
|
-
return {
|
|
36
|
-
error: 'Too many request, please try again in ' + next_time + ' seconds.',
|
|
37
|
-
next_time
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
await handler();
|
|
41
|
-
wait_time = this.getWaitTime(min_wait_time, max_wait_time, min_try_count, user_tried_count + 1, increase_power_base);
|
|
42
|
-
next_time = wait_time * 60;
|
|
43
|
-
return { next_time };
|
|
44
|
-
}
|
|
45
|
-
static async onSafeVerify(handler: () => Promise<void>, errorHandler: () => Promise<void>,
|
|
46
|
-
valid_otp: string, valid_otp_time: Date, otp_expire_time: number, max_try_count: number,
|
|
47
|
-
entered_otp: string, user_tried_count: number)
|
|
48
|
-
{
|
|
49
|
-
if (!entered_otp)
|
|
50
|
-
ErrorOperation.throwHTTP(403, "The OTP not generated yet.");
|
|
51
|
-
|
|
52
|
-
if (valid_otp_time < TimeOperation.minutesAgo(otp_expire_time, new Date()))
|
|
53
|
-
ErrorOperation.throwHTTP(403, "The OTP code expired. Please request again.");
|
|
54
|
-
|
|
55
|
-
if (user_tried_count > max_try_count)
|
|
56
|
-
ErrorOperation.throwHTTP(403, "The try limit attempt exceeded. Please request again.");
|
|
57
|
-
|
|
58
|
-
if (valid_otp !== entered_otp)
|
|
59
|
-
{
|
|
60
|
-
await errorHandler();
|
|
61
|
-
ErrorOperation.throwHTTP(403, "Wrong code.");
|
|
62
|
-
}
|
|
63
|
-
await handler();
|
|
64
|
-
}
|
|
1
|
+
import { ErrorOperation, TimeOperation } from "namirasoft-core";
|
|
2
|
+
|
|
3
|
+
export class OTPOperation
|
|
4
|
+
{
|
|
5
|
+
static generate(length: number = 6, digit: number = 3)
|
|
6
|
+
{
|
|
7
|
+
if (!length)
|
|
8
|
+
length = 6;
|
|
9
|
+
if (!digit)
|
|
10
|
+
digit = 3;
|
|
11
|
+
let dig = [];
|
|
12
|
+
for (let i = 0; i < digit; i++)
|
|
13
|
+
dig[i] = parseInt((Math.random() * 9 + 1) + "");
|
|
14
|
+
let ans = '';
|
|
15
|
+
for (let i = 0; i < length; i++)
|
|
16
|
+
ans = ans + '' + dig[parseInt((Math.random() * dig.length) + "")];
|
|
17
|
+
return ans;
|
|
18
|
+
}
|
|
19
|
+
static getWaitTime(min_wait_time: number, max_wait_time: number, min_attempt: number, user_attemptted: number, increase_power_base: number = 2): number
|
|
20
|
+
{
|
|
21
|
+
let wait_time = min_wait_time;
|
|
22
|
+
let extra_attempt = user_attemptted - min_attempt;
|
|
23
|
+
if (extra_attempt > 0)
|
|
24
|
+
wait_time = Math.min(Math.pow(increase_power_base, extra_attempt) * 60, max_wait_time);
|
|
25
|
+
return parseInt(wait_time + "");
|
|
26
|
+
}
|
|
27
|
+
static async onSafeRequest(handler: () => Promise<void>, min_wait_time: number, max_wait_time: number, min_try_count: number, user_tried_time: Date, user_tried_count: number, increase_power_base: number = 2)
|
|
28
|
+
{
|
|
29
|
+
// check wait time
|
|
30
|
+
let wait_time = this.getWaitTime(min_wait_time, max_wait_time, min_try_count, user_tried_count, increase_power_base);
|
|
31
|
+
let wait_date = TimeOperation.minutesAgo(wait_time, new Date());
|
|
32
|
+
let next_time = TimeOperation.diffInSecond(user_tried_time, wait_date, false);
|
|
33
|
+
if (next_time > 0)
|
|
34
|
+
{
|
|
35
|
+
return {
|
|
36
|
+
error: 'Too many request, please try again in ' + next_time + ' seconds.',
|
|
37
|
+
next_time
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
await handler();
|
|
41
|
+
wait_time = this.getWaitTime(min_wait_time, max_wait_time, min_try_count, user_tried_count + 1, increase_power_base);
|
|
42
|
+
next_time = wait_time * 60;
|
|
43
|
+
return { next_time };
|
|
44
|
+
}
|
|
45
|
+
static async onSafeVerify(handler: () => Promise<void>, errorHandler: () => Promise<void>,
|
|
46
|
+
valid_otp: string, valid_otp_time: Date, otp_expire_time: number, max_try_count: number,
|
|
47
|
+
entered_otp: string, user_tried_count: number)
|
|
48
|
+
{
|
|
49
|
+
if (!entered_otp)
|
|
50
|
+
ErrorOperation.throwHTTP(403, "The OTP not generated yet.");
|
|
51
|
+
|
|
52
|
+
if (valid_otp_time < TimeOperation.minutesAgo(otp_expire_time, new Date()))
|
|
53
|
+
ErrorOperation.throwHTTP(403, "The OTP code expired. Please request again.");
|
|
54
|
+
|
|
55
|
+
if (user_tried_count > max_try_count)
|
|
56
|
+
ErrorOperation.throwHTTP(403, "The try limit attempt exceeded. Please request again.");
|
|
57
|
+
|
|
58
|
+
if (valid_otp !== entered_otp)
|
|
59
|
+
{
|
|
60
|
+
await errorHandler();
|
|
61
|
+
ErrorOperation.throwHTTP(403, "Wrong code.");
|
|
62
|
+
}
|
|
63
|
+
await handler();
|
|
64
|
+
}
|
|
65
65
|
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import * as express from 'express';
|
|
2
|
-
import { ConvertService, ObjectService } from 'namirasoft-core';
|
|
3
|
-
|
|
4
|
-
export class RequestHeaderService extends ConvertService
|
|
5
|
-
{
|
|
6
|
-
private req: express.Request;
|
|
7
|
-
private name: string;
|
|
8
|
-
constructor(req: express.Request, name: string, mandatory: boolean = false)
|
|
9
|
-
{
|
|
10
|
-
super(mandatory);
|
|
11
|
-
this.req = req;
|
|
12
|
-
this.name = name;
|
|
13
|
-
}
|
|
14
|
-
override getNullString()
|
|
15
|
-
{
|
|
16
|
-
if (this.req)
|
|
17
|
-
if (this.req.headers)
|
|
18
|
-
{
|
|
19
|
-
let item = this.req.headers[this.name];
|
|
20
|
-
return new ObjectService(item).getNullString();
|
|
21
|
-
}
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
protected override onMandatoryError(): void
|
|
25
|
-
{
|
|
26
|
-
throw new Error(`Request Header value was not provided: ${this.name}`);
|
|
27
|
-
}
|
|
1
|
+
import * as express from 'express';
|
|
2
|
+
import { ConvertService, ObjectService } from 'namirasoft-core';
|
|
3
|
+
|
|
4
|
+
export class RequestHeaderService extends ConvertService
|
|
5
|
+
{
|
|
6
|
+
private req: express.Request;
|
|
7
|
+
private name: string;
|
|
8
|
+
constructor(req: express.Request, name: string, mandatory: boolean = false)
|
|
9
|
+
{
|
|
10
|
+
super(mandatory);
|
|
11
|
+
this.req = req;
|
|
12
|
+
this.name = name;
|
|
13
|
+
}
|
|
14
|
+
override getNullString()
|
|
15
|
+
{
|
|
16
|
+
if (this.req)
|
|
17
|
+
if (this.req.headers)
|
|
18
|
+
{
|
|
19
|
+
let item = this.req.headers[this.name];
|
|
20
|
+
return new ObjectService(item).getNullString();
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
protected override onMandatoryError(): void
|
|
25
|
+
{
|
|
26
|
+
throw new Error(`Request Header value was not provided: ${this.name}`);
|
|
27
|
+
}
|
|
28
28
|
}
|
package/src/SMTPService.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { BaseEmailService } from './BaseEmailService';
|
|
2
|
-
|
|
3
|
-
export class SMTPService extends BaseEmailService
|
|
4
|
-
{
|
|
5
|
-
host: string;
|
|
6
|
-
port: number;
|
|
7
|
-
password: string;
|
|
8
|
-
constructor(host: string, port: number, username: string, password: string)
|
|
9
|
-
{
|
|
10
|
-
super(username);
|
|
11
|
-
this.host = host;
|
|
12
|
-
this.port = port;
|
|
13
|
-
this.password = password;
|
|
14
|
-
}
|
|
15
|
-
protected override getTransform(): any
|
|
16
|
-
{
|
|
17
|
-
return {
|
|
18
|
-
host: this.host,
|
|
19
|
-
port: this.port,
|
|
20
|
-
secure: true,
|
|
21
|
-
auth: {
|
|
22
|
-
user: this.username,
|
|
23
|
-
pass: this.password
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
}
|
|
1
|
+
import { BaseEmailService } from './BaseEmailService';
|
|
2
|
+
|
|
3
|
+
export class SMTPService extends BaseEmailService
|
|
4
|
+
{
|
|
5
|
+
host: string;
|
|
6
|
+
port: number;
|
|
7
|
+
password: string;
|
|
8
|
+
constructor(host: string, port: number, username: string, password: string)
|
|
9
|
+
{
|
|
10
|
+
super(username);
|
|
11
|
+
this.host = host;
|
|
12
|
+
this.port = port;
|
|
13
|
+
this.password = password;
|
|
14
|
+
}
|
|
15
|
+
protected override getTransform(): any
|
|
16
|
+
{
|
|
17
|
+
return {
|
|
18
|
+
host: this.host,
|
|
19
|
+
port: this.port,
|
|
20
|
+
secure: true,
|
|
21
|
+
auth: {
|
|
22
|
+
user: this.username,
|
|
23
|
+
pass: this.password
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
27
|
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import * as express from 'express';
|
|
2
|
-
import { ErrorOperation, HashOperation } from "namirasoft-core";
|
|
3
|
-
import { RequestHeaderService } from './RequestHeaderService';
|
|
4
|
-
|
|
5
|
-
export class ServerToServerOperation
|
|
6
|
-
{
|
|
7
|
-
static isValid(sign_key: string, data: any, req: express.Request, sign_header: string): boolean
|
|
8
|
-
{
|
|
9
|
-
let signature = new RequestHeaderService(req, sign_header).getString();
|
|
10
|
-
return HashOperation.isValidSHA256Secret(sign_key, data, signature);
|
|
11
|
-
}
|
|
12
|
-
static check(sign_key: string, data: any, req: express.Request, sign_header: string): void
|
|
13
|
-
{
|
|
14
|
-
if (!sign_key)
|
|
15
|
-
ErrorOperation.throwHTTP(401, "Invlid signature - No sign key.");
|
|
16
|
-
if (!sign_header)
|
|
17
|
-
ErrorOperation.throwHTTP(401, "Invlid signature - No sign header name.");
|
|
18
|
-
let signature = new RequestHeaderService(req, sign_header).getString();
|
|
19
|
-
if (!signature)
|
|
20
|
-
ErrorOperation.throwHTTP(401, "Invlid signature - No signature.");
|
|
21
|
-
if (!this.isValid(sign_key, data, req, sign_header))
|
|
22
|
-
ErrorOperation.throwHTTP(401, "Invlid signature.");
|
|
23
|
-
}
|
|
1
|
+
import * as express from 'express';
|
|
2
|
+
import { ErrorOperation, HashOperation } from "namirasoft-core";
|
|
3
|
+
import { RequestHeaderService } from './RequestHeaderService';
|
|
4
|
+
|
|
5
|
+
export class ServerToServerOperation
|
|
6
|
+
{
|
|
7
|
+
static isValid(sign_key: string, data: any, req: express.Request, sign_header: string): boolean
|
|
8
|
+
{
|
|
9
|
+
let signature = new RequestHeaderService(req, sign_header).getString();
|
|
10
|
+
return HashOperation.isValidSHA256Secret(sign_key, data, signature);
|
|
11
|
+
}
|
|
12
|
+
static check(sign_key: string, data: any, req: express.Request, sign_header: string): void
|
|
13
|
+
{
|
|
14
|
+
if (!sign_key)
|
|
15
|
+
ErrorOperation.throwHTTP(401, "Invlid signature - No sign key.");
|
|
16
|
+
if (!sign_header)
|
|
17
|
+
ErrorOperation.throwHTTP(401, "Invlid signature - No sign header name.");
|
|
18
|
+
let signature = new RequestHeaderService(req, sign_header).getString();
|
|
19
|
+
if (!signature)
|
|
20
|
+
ErrorOperation.throwHTTP(401, "Invlid signature - No signature.");
|
|
21
|
+
if (!this.isValid(sign_key, data, req, sign_header))
|
|
22
|
+
ErrorOperation.throwHTTP(401, "Invlid signature.");
|
|
23
|
+
}
|
|
24
24
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export * from "./AnomalyDetector";
|
|
2
|
-
export * from "./BaseApplication";
|
|
3
|
-
export * from "./BaseApplicationLink";
|
|
4
|
-
export * from "./BaseController";
|
|
5
|
-
export * from "./BaseCron";
|
|
6
|
-
export * from "./BaseDatabase";
|
|
7
|
-
export * from "./BaseEmailService";
|
|
8
|
-
export * from "./BaseTable";
|
|
9
|
-
export * from "./CommandOperation";
|
|
10
|
-
export * from "./EmptyDatabase";
|
|
11
|
-
export * from "./EnvService";
|
|
12
|
-
export * from "./GmailService";
|
|
13
|
-
export * from "./IPOperation";
|
|
14
|
-
export * from "./Meta";
|
|
15
|
-
export * from "./OTPOperation";
|
|
16
|
-
export * from "./RequestHeaderService";
|
|
17
|
-
export * from "./ServerToServerOperation";
|
|
1
|
+
export * from "./AnomalyDetector";
|
|
2
|
+
export * from "./BaseApplication";
|
|
3
|
+
export * from "./BaseApplicationLink";
|
|
4
|
+
export * from "./BaseController";
|
|
5
|
+
export * from "./BaseCron";
|
|
6
|
+
export * from "./BaseDatabase";
|
|
7
|
+
export * from "./BaseEmailService";
|
|
8
|
+
export * from "./BaseTable";
|
|
9
|
+
export * from "./CommandOperation";
|
|
10
|
+
export * from "./EmptyDatabase";
|
|
11
|
+
export * from "./EnvService";
|
|
12
|
+
export * from "./GmailService";
|
|
13
|
+
export * from "./IPOperation";
|
|
14
|
+
export * from "./Meta";
|
|
15
|
+
export * from "./OTPOperation";
|
|
16
|
+
export * from "./RequestHeaderService";
|
|
17
|
+
export * from "./ServerToServerOperation";
|
|
18
18
|
export * from "./SMTPService";
|
package/dist/CMDOperation.d.ts
DELETED
package/dist/CMDOperation.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.OTPOperation = void 0;
|
|
13
|
-
const { exec, execSync } = require('child_process');
|
|
14
|
-
class OTPOperation {
|
|
15
|
-
static run(command, cwd) {
|
|
16
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
yield exec(command, { cwd }, (error, stdout, stderr) => {
|
|
18
|
-
if (error) {
|
|
19
|
-
console.error(`error: ${error.message}`);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (stderr) {
|
|
23
|
-
console.error(`stderr: ${stderr}`);
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
console.log(`stdout:\n${stdout}`);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
static runSync(command, cwd) {
|
|
31
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
try {
|
|
33
|
-
return yield execSync(command, { cwd, encoding: 'utf-8' });
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
console.error(error.stdout);
|
|
37
|
-
throw error;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.OTPOperation = OTPOperation;
|
|
43
|
-
//# sourceMappingURL=CMDOperation.js.map
|
package/dist/CMDOperation.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CMDOperation.js","sourceRoot":"","sources":["../src/CMDOperation.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;AACpD,MAAa,YAAY;IAErB,MAAM,CAAO,GAAG,CAAC,OAAe,EAAE,GAAuB;;YAErD,MAAM,IAAI,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;gBAEnD,IAAI,KAAK,EACT;oBACI,OAAO,CAAC,KAAK,CAAC,UAAU,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;oBACzC,OAAO;iBACV;gBACD,IAAI,MAAM,EACV;oBACI,OAAO,CAAC,KAAK,CAAC,WAAW,MAAM,EAAE,CAAC,CAAC;oBACnC,OAAO;iBACV;gBACD,OAAO,CAAC,GAAG,CAAC,YAAY,MAAM,EAAE,CAAC,CAAC;YACtC,CAAC,CAAC,CAAC;QACP,CAAC;KAAA;IACD,MAAM,CAAO,OAAO,CAAC,OAAe,EAAE,GAAuB;;YAEzD,IACA;gBACI,OAAO,MAAM,QAAQ,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;aAC9D;YAAC,OAAO,KAAU,EACnB;gBACI,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBAC5B,MAAM,KAAK,CAAC;aACf;QACL,CAAC;KAAA;CACJ;AA9BD,oCA8BC"}
|
package/dist/EmailService.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import { AttachmentLike } from "nodemailer/lib/mailer";
|
|
4
|
-
import { Readable } from "stream";
|
|
5
|
-
export declare class EmailService {
|
|
6
|
-
host: string;
|
|
7
|
-
username: string;
|
|
8
|
-
username_from: string;
|
|
9
|
-
password: string;
|
|
10
|
-
error_title: string;
|
|
11
|
-
error_recipients: string;
|
|
12
|
-
constructor(host: string, username: string, username_from: string, password: string, error_title: string, error_recipients: string);
|
|
13
|
-
sendExeption(error: Error, meta: any, callback?: (err: Error | null, info: any) => void): void;
|
|
14
|
-
sendError(title: string, message: string, callback?: (err: Error | null, info: any) => void): void;
|
|
15
|
-
send(to: string, subject: string, text: string, html?: string | Buffer | Readable | AttachmentLike | undefined, callback?: (err: Error | null, info: any) => void): void;
|
|
16
|
-
}
|
package/dist/EmailService.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.EmailService = void 0;
|
|
7
|
-
const nodemailer_1 = __importDefault(require("nodemailer"));
|
|
8
|
-
const nodemailer_smtp_transport_1 = __importDefault(require("nodemailer-smtp-transport"));
|
|
9
|
-
class EmailService {
|
|
10
|
-
constructor(host, username, username_from, password, error_title, error_recipients) {
|
|
11
|
-
this.host = host;
|
|
12
|
-
this.username = username;
|
|
13
|
-
this.username_from = username_from;
|
|
14
|
-
this.password = password;
|
|
15
|
-
this.error_title = error_title;
|
|
16
|
-
this.error_recipients = error_recipients;
|
|
17
|
-
}
|
|
18
|
-
sendExeption(error, meta, callback) {
|
|
19
|
-
let title = error.message;
|
|
20
|
-
let message = title;
|
|
21
|
-
if (meta)
|
|
22
|
-
message += "\r\n" + JSON.stringify(meta);
|
|
23
|
-
message += "\r\n" + error.stack;
|
|
24
|
-
this.sendError(title, message, callback);
|
|
25
|
-
}
|
|
26
|
-
sendError(title, message, callback) {
|
|
27
|
-
if (!title)
|
|
28
|
-
title = '';
|
|
29
|
-
let toks = this.error_recipients.split(',');
|
|
30
|
-
for (let i = 0; i < toks.length; i++) {
|
|
31
|
-
const email = toks[i];
|
|
32
|
-
this.send(email, this.error_title + " - " + title, message, undefined, callback);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
send(to, subject, text, html, callback) {
|
|
36
|
-
if (!this.username)
|
|
37
|
-
return;
|
|
38
|
-
if (!this.password)
|
|
39
|
-
return;
|
|
40
|
-
let transform = {};
|
|
41
|
-
if (this.host === 'gmail')
|
|
42
|
-
transform = (0, nodemailer_smtp_transport_1.default)({
|
|
43
|
-
service: 'gmail',
|
|
44
|
-
host: 'smtp.gmail.com',
|
|
45
|
-
auth: {
|
|
46
|
-
user: this.username,
|
|
47
|
-
pass: this.password
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
else
|
|
51
|
-
transform = {
|
|
52
|
-
host: this.host,
|
|
53
|
-
port: 465,
|
|
54
|
-
secure: true,
|
|
55
|
-
auth: {
|
|
56
|
-
user: this.username,
|
|
57
|
-
pass: this.password
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
let transporter = nodemailer_1.default.createTransport(transform);
|
|
61
|
-
let mailOptions = {
|
|
62
|
-
from: this.username_from,
|
|
63
|
-
to,
|
|
64
|
-
subject,
|
|
65
|
-
text,
|
|
66
|
-
html
|
|
67
|
-
};
|
|
68
|
-
if (html)
|
|
69
|
-
mailOptions.html = html;
|
|
70
|
-
transporter.sendMail(mailOptions, function (error, info) {
|
|
71
|
-
if (callback)
|
|
72
|
-
callback(error, info);
|
|
73
|
-
else {
|
|
74
|
-
if (error)
|
|
75
|
-
console.log(error);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
exports.EmailService = EmailService;
|
|
81
|
-
//# sourceMappingURL=EmailService.js.map
|
package/dist/EmailService.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EmailService.js","sourceRoot":"","sources":["../src/EmailService.ts"],"names":[],"mappings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