@spinajs/email 2.0.180 → 2.0.182
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/cjs/cli/SendEmail.d.ts +16 -16
- package/lib/cjs/cli/SendEmail.js +82 -82
- package/lib/cjs/cli/SendEmail.js.map +1 -1
- package/lib/cjs/config/email.d.ts +28 -28
- package/lib/cjs/config/email.js +35 -35
- package/lib/cjs/events/EmailSent.d.ts +23 -23
- package/lib/cjs/events/EmailSent.js +32 -32
- package/lib/cjs/events/EmailSent.js.map +1 -1
- package/lib/cjs/index.d.ts +23 -23
- package/lib/cjs/index.js +76 -76
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces.d.ts +114 -114
- package/lib/cjs/interfaces.js +44 -44
- package/lib/cjs/interfaces.js.map +1 -1
- package/lib/cjs/jobs/EmailSend.d.ts +30 -30
- package/lib/cjs/jobs/EmailSend.js +36 -36
- package/lib/cjs/jobs/EmailSend.js.map +1 -1
- package/lib/cjs/schemas/email.smtp.configuration.d.ts +52 -52
- package/lib/cjs/schemas/email.smtp.configuration.js +38 -38
- package/lib/cjs/transports.d.ts +9 -9
- package/lib/cjs/transports.js +24 -24
- package/lib/cjs/transports.js.map +1 -1
- package/lib/mjs/cli/SendEmail.d.ts +16 -16
- package/lib/mjs/cli/SendEmail.js +56 -56
- package/lib/mjs/cli/SendEmail.js.map +1 -1
- package/lib/mjs/config/email.d.ts +28 -28
- package/lib/mjs/config/email.js +33 -33
- package/lib/mjs/events/EmailSent.d.ts +23 -23
- package/lib/mjs/events/EmailSent.js +29 -29
- package/lib/mjs/events/EmailSent.js.map +1 -1
- package/lib/mjs/index.d.ts +23 -23
- package/lib/mjs/index.js +56 -56
- package/lib/mjs/index.js.map +1 -1
- package/lib/mjs/interfaces.d.ts +114 -114
- package/lib/mjs/interfaces.js +39 -39
- package/lib/mjs/interfaces.js.map +1 -1
- package/lib/mjs/jobs/EmailSend.d.ts +30 -30
- package/lib/mjs/jobs/EmailSend.js +33 -33
- package/lib/mjs/jobs/EmailSend.js.map +1 -1
- package/lib/mjs/schemas/email.smtp.configuration.d.ts +52 -52
- package/lib/mjs/schemas/email.smtp.configuration.js +36 -36
- package/lib/mjs/transports.d.ts +9 -9
- package/lib/mjs/transports.js +21 -21
- package/lib/mjs/transports.js.map +1 -1
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +8 -8
package/lib/cjs/index.js
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
14
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
15
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
16
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
17
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
18
|
-
};
|
|
19
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
-
};
|
|
22
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.DefaultEmailService = exports.LogBotstrapper = void 0;
|
|
27
|
-
const exceptions_1 = require("@spinajs/exceptions");
|
|
28
|
-
const di_1 = require("@spinajs/di");
|
|
29
|
-
const interfaces_js_1 = require("./interfaces.js");
|
|
30
|
-
const email_smtp_configuration_js_1 = __importDefault(require("./schemas/email.smtp.configuration.js"));
|
|
31
|
-
const EmailSent_js_1 = require("./events/EmailSent.js");
|
|
32
|
-
const EmailSend_js_1 = require("./jobs/EmailSend.js");
|
|
33
|
-
__exportStar(require("./interfaces.js"), exports);
|
|
34
|
-
__exportStar(require("./transports.js"), exports);
|
|
35
|
-
__exportStar(require("./jobs/EmailSend.js"), exports);
|
|
36
|
-
let LogBotstrapper = class LogBotstrapper extends di_1.Bootstrapper {
|
|
37
|
-
bootstrap() {
|
|
38
|
-
di_1.DI.register(email_smtp_configuration_js_1.default).asValue('__configurationSchema__');
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
LogBotstrapper =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Email sending service.
|
|
47
|
-
*/
|
|
48
|
-
let DefaultEmailService = class DefaultEmailService extends interfaces_js_1.EmailService {
|
|
49
|
-
/**
|
|
50
|
-
*
|
|
51
|
-
* Tries to sends email immediately
|
|
52
|
-
*
|
|
53
|
-
* @param email - email struct
|
|
54
|
-
*/
|
|
55
|
-
async send(email) {
|
|
56
|
-
if (!this.Senders.has(email.connection)) {
|
|
57
|
-
throw new exceptions_1.InvalidOperation(`Email sender ${email.connection} not exists. Please check your configuration files.`);
|
|
58
|
-
}
|
|
59
|
-
await this.Senders.get(email.connection).send(email);
|
|
60
|
-
// inform others of email event
|
|
61
|
-
await this.Queue.emit(new EmailSent_js_1.EmailSent(email));
|
|
62
|
-
}
|
|
63
|
-
async sendDeferred(email) {
|
|
64
|
-
const dEmail = new EmailSend_js_1.EmailSend();
|
|
65
|
-
dEmail.hydrate(email);
|
|
66
|
-
await this.Queue.emit(dEmail);
|
|
67
|
-
return dEmail;
|
|
68
|
-
}
|
|
69
|
-
async processDefferedEmails() {
|
|
70
|
-
await this.Queue.consume(EmailSend_js_1.EmailSend);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
DefaultEmailService =
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
14
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
15
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
16
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
17
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
18
|
+
};
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.DefaultEmailService = exports.LogBotstrapper = void 0;
|
|
27
|
+
const exceptions_1 = require("@spinajs/exceptions");
|
|
28
|
+
const di_1 = require("@spinajs/di");
|
|
29
|
+
const interfaces_js_1 = require("./interfaces.js");
|
|
30
|
+
const email_smtp_configuration_js_1 = __importDefault(require("./schemas/email.smtp.configuration.js"));
|
|
31
|
+
const EmailSent_js_1 = require("./events/EmailSent.js");
|
|
32
|
+
const EmailSend_js_1 = require("./jobs/EmailSend.js");
|
|
33
|
+
__exportStar(require("./interfaces.js"), exports);
|
|
34
|
+
__exportStar(require("./transports.js"), exports);
|
|
35
|
+
__exportStar(require("./jobs/EmailSend.js"), exports);
|
|
36
|
+
let LogBotstrapper = class LogBotstrapper extends di_1.Bootstrapper {
|
|
37
|
+
bootstrap() {
|
|
38
|
+
di_1.DI.register(email_smtp_configuration_js_1.default).asValue('__configurationSchema__');
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.LogBotstrapper = LogBotstrapper;
|
|
42
|
+
exports.LogBotstrapper = LogBotstrapper = __decorate([
|
|
43
|
+
(0, di_1.Injectable)(di_1.Bootstrapper)
|
|
44
|
+
], LogBotstrapper);
|
|
45
|
+
/**
|
|
46
|
+
* Email sending service.
|
|
47
|
+
*/
|
|
48
|
+
let DefaultEmailService = class DefaultEmailService extends interfaces_js_1.EmailService {
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* Tries to sends email immediately
|
|
52
|
+
*
|
|
53
|
+
* @param email - email struct
|
|
54
|
+
*/
|
|
55
|
+
async send(email) {
|
|
56
|
+
if (!this.Senders.has(email.connection)) {
|
|
57
|
+
throw new exceptions_1.InvalidOperation(`Email sender ${email.connection} not exists. Please check your configuration files.`);
|
|
58
|
+
}
|
|
59
|
+
await this.Senders.get(email.connection).send(email);
|
|
60
|
+
// inform others of email event
|
|
61
|
+
await this.Queue.emit(new EmailSent_js_1.EmailSent(email));
|
|
62
|
+
}
|
|
63
|
+
async sendDeferred(email) {
|
|
64
|
+
const dEmail = new EmailSend_js_1.EmailSend();
|
|
65
|
+
dEmail.hydrate(email);
|
|
66
|
+
await this.Queue.emit(dEmail);
|
|
67
|
+
return dEmail;
|
|
68
|
+
}
|
|
69
|
+
async processDefferedEmails() {
|
|
70
|
+
await this.Queue.consume(EmailSend_js_1.EmailSend);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
exports.DefaultEmailService = DefaultEmailService;
|
|
74
|
+
exports.DefaultEmailService = DefaultEmailService = __decorate([
|
|
75
|
+
(0, di_1.Injectable)(interfaces_js_1.EmailService)
|
|
76
|
+
], DefaultEmailService);
|
|
77
77
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAuD;AACvD,oCAA2D;AAC3D,mDAAuD;AACvD,wGAAyE;AACzE,wDAAkD;AAClD,sDAAgD;AAEhD,kDAAgC;AAChC,kDAAgC;AAChC,sDAAoC;AAG7B,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,iBAAY;IACvC,SAAS;QACd,OAAE,CAAC,QAAQ,CAAC,qCAAoB,CAAC,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;IACvE,CAAC;CACF,CAAA;AAJY,cAAc;IAD1B,IAAA,eAAU,EAAC,iBAAY,CAAC;GACZ,cAAc,CAI1B;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAuD;AACvD,oCAA2D;AAC3D,mDAAuD;AACvD,wGAAyE;AACzE,wDAAkD;AAClD,sDAAgD;AAEhD,kDAAgC;AAChC,kDAAgC;AAChC,sDAAoC;AAG7B,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,iBAAY;IACvC,SAAS;QACd,OAAE,CAAC,QAAQ,CAAC,qCAAoB,CAAC,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;IACvE,CAAC;CACF,CAAA;AAJY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,eAAU,EAAC,iBAAY,CAAC;GACZ,cAAc,CAI1B;AAED;;GAEG;AAEI,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,4BAAY;IACnD;;;;;OAKG;IACI,KAAK,CAAC,IAAI,CAAC,KAAa;QAC7B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE;YACvC,MAAM,IAAI,6BAAgB,CAAC,gBAAgB,KAAK,CAAC,UAAU,qDAAqD,CAAC,CAAC;SACnH;QAED,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAErD,+BAA+B;QAC/B,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,wBAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IAC9C,CAAC;IAEM,KAAK,CAAC,YAAY,CAAC,KAAa;QACrC,MAAM,MAAM,GAAG,IAAI,wBAAS,EAAE,CAAC;QAC/B,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACtB,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAE9B,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,KAAK,CAAC,qBAAqB;QAChC,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,wBAAS,CAAC,CAAC;IACtC,CAAC;CACF,CAAA;AA7BY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,eAAU,EAAC,4BAAY,CAAC;GACZ,mBAAmB,CA6B/B"}
|
package/lib/cjs/interfaces.d.ts
CHANGED
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
import { AsyncService, IInstanceCheck, IMappableService } from '@spinajs/di';
|
|
2
|
-
import { Log } from '@spinajs/log';
|
|
3
|
-
import { QueueService } from '@spinajs/queue';
|
|
4
|
-
import { EmailSend } from './jobs/EmailSend.js';
|
|
5
|
-
export declare abstract class EmailSender extends AsyncService implements IInstanceCheck, IMappableService {
|
|
6
|
-
Options: EmailConnectionOptions;
|
|
7
|
-
get ServiceName(): string;
|
|
8
|
-
abstract send(email: IEmail): Promise<void>;
|
|
9
|
-
__checkInstance__(creationOptions: any): boolean;
|
|
10
|
-
}
|
|
11
|
-
export interface IEmailAttachement {
|
|
12
|
-
/**
|
|
13
|
-
* - filename to be reported as the name of the attached file. Use of unicode is allowed.
|
|
14
|
-
*/
|
|
15
|
-
name: string;
|
|
16
|
-
/**
|
|
17
|
-
* Path to file
|
|
18
|
-
*/
|
|
19
|
-
path: string;
|
|
20
|
-
/**
|
|
21
|
-
* File provider could be local fs, aws s3 etc. Default is always fs-local
|
|
22
|
-
*/
|
|
23
|
-
provider?: string;
|
|
24
|
-
}
|
|
25
|
-
export interface IEmail {
|
|
26
|
-
to: string[];
|
|
27
|
-
cc?: string[];
|
|
28
|
-
bcc?: string[];
|
|
29
|
-
from: string;
|
|
30
|
-
connection: string;
|
|
31
|
-
attachements?: IEmailAttachement[];
|
|
32
|
-
/**
|
|
33
|
-
* Local template name. Must be avaible in one of dirs set in template config
|
|
34
|
-
*/
|
|
35
|
-
template?: string;
|
|
36
|
-
/**
|
|
37
|
-
* Some implementations have predefined templates. It can be accessed by this Id
|
|
38
|
-
* eg. mailersend
|
|
39
|
-
*/
|
|
40
|
-
templateId?: string;
|
|
41
|
-
/**
|
|
42
|
-
* Data passed to template
|
|
43
|
-
*/
|
|
44
|
-
model?: unknown;
|
|
45
|
-
/**
|
|
46
|
-
* Text representation of email
|
|
47
|
-
*/
|
|
48
|
-
text?: string;
|
|
49
|
-
subject: string;
|
|
50
|
-
lang?: string;
|
|
51
|
-
priority?: string;
|
|
52
|
-
replyTo?: string;
|
|
53
|
-
/**
|
|
54
|
-
* Additional tag for email,
|
|
55
|
-
* usefull for identyfying emails by category or module that sends it
|
|
56
|
-
*/
|
|
57
|
-
tag?: string;
|
|
58
|
-
/**
|
|
59
|
-
* Unique email id, for identification eg. in case of delivery failure
|
|
60
|
-
*/
|
|
61
|
-
emailId?: string;
|
|
62
|
-
}
|
|
63
|
-
export interface EmailConfiguration {
|
|
64
|
-
connections: EmailConnectionOptions[];
|
|
65
|
-
defaultConnection: string;
|
|
66
|
-
}
|
|
67
|
-
export interface EmailConnectionOptions {
|
|
68
|
-
sender: string;
|
|
69
|
-
name: string;
|
|
70
|
-
host?: string;
|
|
71
|
-
port?: number;
|
|
72
|
-
user?: string;
|
|
73
|
-
pass?: string;
|
|
74
|
-
ssl?: boolean;
|
|
75
|
-
/**
|
|
76
|
-
* defaults for messages
|
|
77
|
-
*/
|
|
78
|
-
defaults?: {
|
|
79
|
-
/**
|
|
80
|
-
* defalt `from` adress, can be override when sending
|
|
81
|
-
*/
|
|
82
|
-
mailFrom?: string;
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* Additional options passed
|
|
86
|
-
* lib specific
|
|
87
|
-
*/
|
|
88
|
-
options?: unknown;
|
|
89
|
-
}
|
|
90
|
-
export declare abstract class EmailService extends AsyncService {
|
|
91
|
-
protected Log: Log;
|
|
92
|
-
protected Senders: Map<string, EmailSender>;
|
|
93
|
-
protected Configuration: EmailConfiguration;
|
|
94
|
-
protected Queue: QueueService;
|
|
95
|
-
/**
|
|
96
|
-
*
|
|
97
|
-
* Sends email immediatelly ( in current process )
|
|
98
|
-
*
|
|
99
|
-
* @param email - email to send
|
|
100
|
-
*/
|
|
101
|
-
abstract send(email: IEmail): Promise<void>;
|
|
102
|
-
/**
|
|
103
|
-
*
|
|
104
|
-
* Schedules email to send ( adds to queue ). Email is sent by separate process
|
|
105
|
-
* that subscribe for specific events
|
|
106
|
-
*
|
|
107
|
-
* @param email - email to send
|
|
108
|
-
*/
|
|
109
|
-
abstract sendDeferred(email: IEmail): Promise<EmailSend>;
|
|
110
|
-
/**
|
|
111
|
-
* Subscribte to queue for emails to send
|
|
112
|
-
*/
|
|
113
|
-
abstract processDefferedEmails(): Promise<void>;
|
|
114
|
-
}
|
|
1
|
+
import { AsyncService, IInstanceCheck, IMappableService } from '@spinajs/di';
|
|
2
|
+
import { Log } from '@spinajs/log';
|
|
3
|
+
import { QueueService } from '@spinajs/queue';
|
|
4
|
+
import { EmailSend } from './jobs/EmailSend.js';
|
|
5
|
+
export declare abstract class EmailSender extends AsyncService implements IInstanceCheck, IMappableService {
|
|
6
|
+
Options: EmailConnectionOptions;
|
|
7
|
+
get ServiceName(): string;
|
|
8
|
+
abstract send(email: IEmail): Promise<void>;
|
|
9
|
+
__checkInstance__(creationOptions: any): boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface IEmailAttachement {
|
|
12
|
+
/**
|
|
13
|
+
* - filename to be reported as the name of the attached file. Use of unicode is allowed.
|
|
14
|
+
*/
|
|
15
|
+
name: string;
|
|
16
|
+
/**
|
|
17
|
+
* Path to file
|
|
18
|
+
*/
|
|
19
|
+
path: string;
|
|
20
|
+
/**
|
|
21
|
+
* File provider could be local fs, aws s3 etc. Default is always fs-local
|
|
22
|
+
*/
|
|
23
|
+
provider?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface IEmail {
|
|
26
|
+
to: string[];
|
|
27
|
+
cc?: string[];
|
|
28
|
+
bcc?: string[];
|
|
29
|
+
from: string;
|
|
30
|
+
connection: string;
|
|
31
|
+
attachements?: IEmailAttachement[];
|
|
32
|
+
/**
|
|
33
|
+
* Local template name. Must be avaible in one of dirs set in template config
|
|
34
|
+
*/
|
|
35
|
+
template?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Some implementations have predefined templates. It can be accessed by this Id
|
|
38
|
+
* eg. mailersend
|
|
39
|
+
*/
|
|
40
|
+
templateId?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Data passed to template
|
|
43
|
+
*/
|
|
44
|
+
model?: unknown;
|
|
45
|
+
/**
|
|
46
|
+
* Text representation of email
|
|
47
|
+
*/
|
|
48
|
+
text?: string;
|
|
49
|
+
subject: string;
|
|
50
|
+
lang?: string;
|
|
51
|
+
priority?: string;
|
|
52
|
+
replyTo?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Additional tag for email,
|
|
55
|
+
* usefull for identyfying emails by category or module that sends it
|
|
56
|
+
*/
|
|
57
|
+
tag?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Unique email id, for identification eg. in case of delivery failure
|
|
60
|
+
*/
|
|
61
|
+
emailId?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface EmailConfiguration {
|
|
64
|
+
connections: EmailConnectionOptions[];
|
|
65
|
+
defaultConnection: string;
|
|
66
|
+
}
|
|
67
|
+
export interface EmailConnectionOptions {
|
|
68
|
+
sender: string;
|
|
69
|
+
name: string;
|
|
70
|
+
host?: string;
|
|
71
|
+
port?: number;
|
|
72
|
+
user?: string;
|
|
73
|
+
pass?: string;
|
|
74
|
+
ssl?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* defaults for messages
|
|
77
|
+
*/
|
|
78
|
+
defaults?: {
|
|
79
|
+
/**
|
|
80
|
+
* defalt `from` adress, can be override when sending
|
|
81
|
+
*/
|
|
82
|
+
mailFrom?: string;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Additional options passed
|
|
86
|
+
* lib specific
|
|
87
|
+
*/
|
|
88
|
+
options?: unknown;
|
|
89
|
+
}
|
|
90
|
+
export declare abstract class EmailService extends AsyncService {
|
|
91
|
+
protected Log: Log;
|
|
92
|
+
protected Senders: Map<string, EmailSender>;
|
|
93
|
+
protected Configuration: EmailConfiguration;
|
|
94
|
+
protected Queue: QueueService;
|
|
95
|
+
/**
|
|
96
|
+
*
|
|
97
|
+
* Sends email immediatelly ( in current process )
|
|
98
|
+
*
|
|
99
|
+
* @param email - email to send
|
|
100
|
+
*/
|
|
101
|
+
abstract send(email: IEmail): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
*
|
|
104
|
+
* Schedules email to send ( adds to queue ). Email is sent by separate process
|
|
105
|
+
* that subscribe for specific events
|
|
106
|
+
*
|
|
107
|
+
* @param email - email to send
|
|
108
|
+
*/
|
|
109
|
+
abstract sendDeferred(email: IEmail): Promise<EmailSend>;
|
|
110
|
+
/**
|
|
111
|
+
* Subscribte to queue for emails to send
|
|
112
|
+
*/
|
|
113
|
+
abstract processDefferedEmails(): Promise<void>;
|
|
114
|
+
}
|
|
115
115
|
//# sourceMappingURL=interfaces.d.ts.map
|
package/lib/cjs/interfaces.js
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.EmailService = exports.EmailSender = void 0;
|
|
13
|
-
const di_1 = require("@spinajs/di");
|
|
14
|
-
const log_1 = require("@spinajs/log");
|
|
15
|
-
const configuration_1 = require("@spinajs/configuration");
|
|
16
|
-
const queue_1 = require("@spinajs/queue");
|
|
17
|
-
class EmailSender extends di_1.AsyncService {
|
|
18
|
-
get ServiceName() {
|
|
19
|
-
return this.Options.name;
|
|
20
|
-
}
|
|
21
|
-
__checkInstance__(creationOptions) {
|
|
22
|
-
return this.Options.name === creationOptions[0].name;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.EmailSender = EmailSender;
|
|
26
|
-
class EmailService extends di_1.AsyncService {
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.EmailService = exports.EmailSender = void 0;
|
|
13
|
+
const di_1 = require("@spinajs/di");
|
|
14
|
+
const log_1 = require("@spinajs/log");
|
|
15
|
+
const configuration_1 = require("@spinajs/configuration");
|
|
16
|
+
const queue_1 = require("@spinajs/queue");
|
|
17
|
+
class EmailSender extends di_1.AsyncService {
|
|
18
|
+
get ServiceName() {
|
|
19
|
+
return this.Options.name;
|
|
20
|
+
}
|
|
21
|
+
__checkInstance__(creationOptions) {
|
|
22
|
+
return this.Options.name === creationOptions[0].name;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.EmailSender = EmailSender;
|
|
26
|
+
class EmailService extends di_1.AsyncService {
|
|
27
|
+
}
|
|
28
|
+
exports.EmailService = EmailService;
|
|
29
|
+
__decorate([
|
|
30
|
+
(0, log_1.Logger)('email'),
|
|
31
|
+
__metadata("design:type", log_1.Log)
|
|
32
|
+
], EmailService.prototype, "Log", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, configuration_1.AutoinjectService)('email.connections', EmailSender),
|
|
35
|
+
__metadata("design:type", Map)
|
|
36
|
+
], EmailService.prototype, "Senders", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, configuration_1.Config)('email'),
|
|
39
|
+
__metadata("design:type", Object)
|
|
40
|
+
], EmailService.prototype, "Configuration", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, di_1.Autoinject)(queue_1.QueueService),
|
|
43
|
+
__metadata("design:type", queue_1.QueueService)
|
|
44
|
+
], EmailService.prototype, "Queue", void 0);
|
|
45
45
|
//# sourceMappingURL=interfaces.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAyF;AACzF,sCAA2C;AAC3C,0DAAmE;AACnE,0CAA8C;AAE9C,MAAsB,WAAY,SAAQ,iBAAY;IAGpD,IAAW,WAAW;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;IAIM,iBAAiB,CAAC,eAAoB;QAC3C,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACvD,CAAC;CACF;AAZD,kCAYC;AAwGD,MAAsB,YAAa,SAAQ,iBAAY;CAkCtD;
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAyF;AACzF,sCAA2C;AAC3C,0DAAmE;AACnE,0CAA8C;AAE9C,MAAsB,WAAY,SAAQ,iBAAY;IAGpD,IAAW,WAAW;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;IAIM,iBAAiB,CAAC,eAAoB;QAC3C,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACvD,CAAC;CACF;AAZD,kCAYC;AAwGD,MAAsB,YAAa,SAAQ,iBAAY;CAkCtD;AAlCD,oCAkCC;AAhCW;IADT,IAAA,YAAM,EAAC,OAAO,CAAC;8BACD,SAAG;yCAAC;AAGT;IADT,IAAA,iCAAiB,EAAC,mBAAmB,EAAE,WAAW,CAAC;8BACjC,GAAG;6CAAsB;AAGlC;IADT,IAAA,sBAAM,EAAC,OAAO,CAAC;;mDAC4B;AAGlC;IADT,IAAA,eAAU,EAAC,oBAAY,CAAC;8BACR,oBAAY;2CAAC"}
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { QueueJob } from '@spinajs/queue';
|
|
2
|
-
import { IEmail, IEmailAttachement } from '../interfaces.js';
|
|
3
|
-
/**
|
|
4
|
-
* Job for sending emails in background
|
|
5
|
-
*/
|
|
6
|
-
export declare class EmailSend extends QueueJob implements IEmail {
|
|
7
|
-
to: string[];
|
|
8
|
-
cc?: string[];
|
|
9
|
-
bcc?: string[];
|
|
10
|
-
from: string;
|
|
11
|
-
connection: string;
|
|
12
|
-
attachements?: IEmailAttachement[];
|
|
13
|
-
template?: string;
|
|
14
|
-
templateId?: string;
|
|
15
|
-
model?: unknown;
|
|
16
|
-
text?: string;
|
|
17
|
-
subject: string;
|
|
18
|
-
lang?: string;
|
|
19
|
-
priority?: string;
|
|
20
|
-
replyTo?: string;
|
|
21
|
-
tag?: string;
|
|
22
|
-
emailId?: string;
|
|
23
|
-
execute(): Promise<{
|
|
24
|
-
result: boolean;
|
|
25
|
-
error: any;
|
|
26
|
-
} | {
|
|
27
|
-
result: boolean;
|
|
28
|
-
error?: undefined;
|
|
29
|
-
}>;
|
|
30
|
-
}
|
|
1
|
+
import { QueueJob } from '@spinajs/queue';
|
|
2
|
+
import { IEmail, IEmailAttachement } from '../interfaces.js';
|
|
3
|
+
/**
|
|
4
|
+
* Job for sending emails in background
|
|
5
|
+
*/
|
|
6
|
+
export declare class EmailSend extends QueueJob implements IEmail {
|
|
7
|
+
to: string[];
|
|
8
|
+
cc?: string[];
|
|
9
|
+
bcc?: string[];
|
|
10
|
+
from: string;
|
|
11
|
+
connection: string;
|
|
12
|
+
attachements?: IEmailAttachement[];
|
|
13
|
+
template?: string;
|
|
14
|
+
templateId?: string;
|
|
15
|
+
model?: unknown;
|
|
16
|
+
text?: string;
|
|
17
|
+
subject: string;
|
|
18
|
+
lang?: string;
|
|
19
|
+
priority?: string;
|
|
20
|
+
replyTo?: string;
|
|
21
|
+
tag?: string;
|
|
22
|
+
emailId?: string;
|
|
23
|
+
execute(): Promise<{
|
|
24
|
+
result: boolean;
|
|
25
|
+
error: any;
|
|
26
|
+
} | {
|
|
27
|
+
result: boolean;
|
|
28
|
+
error?: undefined;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
31
31
|
//# sourceMappingURL=EmailSend.d.ts.map
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.EmailSend = void 0;
|
|
10
|
-
const di_1 = require("@spinajs/di");
|
|
11
|
-
const queue_1 = require("@spinajs/queue");
|
|
12
|
-
const interfaces_js_1 = require("../interfaces.js");
|
|
13
|
-
/**
|
|
14
|
-
* Job for sending emails in background
|
|
15
|
-
*/
|
|
16
|
-
let EmailSend = class EmailSend extends queue_1.QueueJob {
|
|
17
|
-
async execute() {
|
|
18
|
-
try {
|
|
19
|
-
const emails = await di_1.DI.resolve(interfaces_js_1.EmailService);
|
|
20
|
-
await emails.send(this);
|
|
21
|
-
}
|
|
22
|
-
catch (err) {
|
|
23
|
-
return {
|
|
24
|
-
result: false,
|
|
25
|
-
error: err,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
return {
|
|
29
|
-
result: true,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
EmailSend =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.EmailSend = void 0;
|
|
10
|
+
const di_1 = require("@spinajs/di");
|
|
11
|
+
const queue_1 = require("@spinajs/queue");
|
|
12
|
+
const interfaces_js_1 = require("../interfaces.js");
|
|
13
|
+
/**
|
|
14
|
+
* Job for sending emails in background
|
|
15
|
+
*/
|
|
16
|
+
let EmailSend = class EmailSend extends queue_1.QueueJob {
|
|
17
|
+
async execute() {
|
|
18
|
+
try {
|
|
19
|
+
const emails = await di_1.DI.resolve(interfaces_js_1.EmailService);
|
|
20
|
+
await emails.send(this);
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
return {
|
|
24
|
+
result: false,
|
|
25
|
+
error: err,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
result: true,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.EmailSend = EmailSend;
|
|
34
|
+
exports.EmailSend = EmailSend = __decorate([
|
|
35
|
+
(0, queue_1.Job)()
|
|
36
|
+
], EmailSend);
|
|
37
37
|
//# sourceMappingURL=EmailSend.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmailSend.js","sourceRoot":"","sources":["../../../src/jobs/EmailSend.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oCAAiC;AACjC,0CAA+C;AAC/C,oDAA2E;AAE3E;;GAEG;AAEI,IAAM,SAAS,GAAf,MAAM,SAAU,SAAQ,gBAAQ;IAkB9B,KAAK,CAAC,OAAO;QAClB,IAAI;YACF,MAAM,MAAM,GAAG,MAAM,OAAE,CAAC,OAAO,CAAC,4BAAY,CAAC,CAAC;YAC9C,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACzB;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO;gBACL,MAAM,EAAE,KAAK;gBACb,KAAK,EAAE,GAAG;aACX,CAAC;SACH;QAED,OAAO;YACL,MAAM,EAAE,IAAI;SACb,CAAC;IACJ,CAAC;CACF,CAAA;AAjCY,SAAS;IADrB,IAAA,WAAG,GAAE;GACO,SAAS,CAiCrB
|
|
1
|
+
{"version":3,"file":"EmailSend.js","sourceRoot":"","sources":["../../../src/jobs/EmailSend.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oCAAiC;AACjC,0CAA+C;AAC/C,oDAA2E;AAE3E;;GAEG;AAEI,IAAM,SAAS,GAAf,MAAM,SAAU,SAAQ,gBAAQ;IAkB9B,KAAK,CAAC,OAAO;QAClB,IAAI;YACF,MAAM,MAAM,GAAG,MAAM,OAAE,CAAC,OAAO,CAAC,4BAAY,CAAC,CAAC;YAC9C,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACzB;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO;gBACL,MAAM,EAAE,KAAK;gBACb,KAAK,EAAE,GAAG;aACX,CAAC;SACH;QAED,OAAO;YACL,MAAM,EAAE,IAAI;SACb,CAAC;IACJ,CAAC;CACF,CAAA;AAjCY,8BAAS;oBAAT,SAAS;IADrB,IAAA,WAAG,GAAE;GACO,SAAS,CAiCrB"}
|