@spinajs/email 2.0.38 → 2.0.45

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.
Files changed (38) hide show
  1. package/lib/{email/src/cli → cli}/SendEmail.d.ts +0 -0
  2. package/lib/{email/src/cli → cli}/SendEmail.js +3 -3
  3. package/lib/cli/SendEmail.js.map +1 -0
  4. package/lib/config/email.d.ts +28 -0
  5. package/lib/config/email.js +35 -0
  6. package/lib/config/email.js.map +1 -0
  7. package/lib/events/EmailSent.d.ts +23 -0
  8. package/lib/events/EmailSent.js +33 -0
  9. package/lib/events/EmailSent.js.map +1 -0
  10. package/lib/index.d.ts +23 -0
  11. package/lib/index.js +77 -0
  12. package/lib/index.js.map +1 -0
  13. package/lib/{email/src/interfaces.d.ts → interfaces.d.ts} +36 -10
  14. package/lib/interfaces.js +45 -0
  15. package/lib/interfaces.js.map +1 -0
  16. package/lib/jobs/EmailSend.d.ts +30 -0
  17. package/lib/jobs/EmailSend.js +37 -0
  18. package/lib/jobs/EmailSend.js.map +1 -0
  19. package/lib/schemas/email.smtp.configuration.d.ts +52 -0
  20. package/lib/schemas/email.smtp.configuration.js +39 -0
  21. package/lib/schemas/email.smtp.configuration.js.map +1 -0
  22. package/lib/transports.d.ts +9 -0
  23. package/lib/transports.js +25 -0
  24. package/lib/transports.js.map +1 -0
  25. package/package.json +15 -10
  26. package/lib/email/src/cli/SendEmail.js.map +0 -1
  27. package/lib/email/src/config/email.d.ts +0 -8
  28. package/lib/email/src/config/email.js +0 -15
  29. package/lib/email/src/config/email.js.map +0 -1
  30. package/lib/email/src/index.d.ts +0 -14
  31. package/lib/email/src/index.js +0 -66
  32. package/lib/email/src/index.js.map +0 -1
  33. package/lib/email/src/interfaces.js +0 -7
  34. package/lib/email/src/interfaces.js.map +0 -1
  35. package/lib/email.js +0 -7
  36. package/lib/exceptions/src/index.d.ts +0 -85
  37. package/lib/exceptions/src/index.js +0 -106
  38. package/lib/exceptions/src/index.js.map +0 -1
File without changes
@@ -42,7 +42,7 @@ let SendEmailCommand = class SendEmailCommand extends cli_1.CliCommand {
42
42
  async execute(options) {
43
43
  this.Log.trace(`Sending email with options options: ${JSON.stringify(options)}`);
44
44
  try {
45
- const emails = await di_1.DI.resolve(index_1.Emails);
45
+ const emails = await di_1.DI.resolve(index_1.DefaultEmailService);
46
46
  let model = {};
47
47
  if (options.model && fs.existsSync(options.model)) {
48
48
  this.Log.trace(`Found model file at ${options.model}, trying to load model data ... `);
@@ -51,7 +51,7 @@ let SendEmailCommand = class SendEmailCommand extends cli_1.CliCommand {
51
51
  }
52
52
  await emails.send({
53
53
  from: options.from,
54
- to: [options.to],
54
+ to: options.to.split(','),
55
55
  connection: options.connection,
56
56
  template: options.template,
57
57
  model: model,
@@ -66,7 +66,7 @@ let SendEmailCommand = class SendEmailCommand extends cli_1.CliCommand {
66
66
  }
67
67
  };
68
68
  __decorate([
69
- (0, log_1.Logger)('templates'),
69
+ (0, log_1.Logger)('email'),
70
70
  __metadata("design:type", Object)
71
71
  ], SendEmailCommand.prototype, "Log", void 0);
72
72
  SendEmailCommand = __decorate([
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SendEmail.js","sourceRoot":"","sources":["../../src/cli/SendEmail.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAA2D;AAC3D,oCAAiC;AACjC,uCAAyB;AACzB,sCAA4C;AAC5C,sCAAiD;AAoBjD,IAAa,gBAAgB,GAA7B,MAAa,gBAAiB,SAAQ,gBAAU;IAIvC,KAAK,CAAC,OAAO,CAAC,OAAqB;QACxC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,uCAAuC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAEjF,IAAI;YACF,MAAM,MAAM,GAAG,MAAM,OAAE,CAAC,OAAO,CAAC,2BAAmB,CAAC,CAAC;YACrD,IAAI,KAAK,GAAG,EAAE,CAAC;YA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AE,YAAY,CAAC;IAC/C,IAAA,YAAM,EAAC,eAAe,EAAE,IAAI,EAAE,8CAA8C,CAAC;IAC7E,IAAA,YAAM,EAAC,2BAA2B,EAAE,KAAK,EAAE,eAAe,CAAC;IAC3D,IAAA,YAAM,EAAC,qBAAqB,EAAE,KAAK,EAAE,iDAAiD,CAAC;IACvF,IAAA,YAAM,EAAC,uBAAuB,EAAE,IAAI,EAAE,SAAS,CAAC;IAChD,IAAA,YAAM,EAAC,yBAAyB,EAAE,KAAK,EAAE,0CAA0C,CAAC;GACxE,gBAAgB,CAiC5B;AAjCY,4CAAgB"}
@@ -0,0 +1,28 @@
1
+ declare const email: {
2
+ system: {
3
+ dirs: {
4
+ cli: string[];
5
+ jobs: string[];
6
+ };
7
+ };
8
+ email: {
9
+ queue: string;
10
+ };
11
+ queue: {
12
+ routing: {
13
+ EmailSendJob: {
14
+ connection: string;
15
+ };
16
+ EmailSent: {
17
+ connection: string;
18
+ };
19
+ };
20
+ connections: {
21
+ name: string;
22
+ service: string;
23
+ defaultQueueChannel: string;
24
+ defaultTopicChannel: string;
25
+ }[];
26
+ };
27
+ };
28
+ export default email;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const path_1 = require("path");
4
+ function dir(path) {
5
+ return (0, path_1.resolve)((0, path_1.normalize)((0, path_1.join)(__dirname, path)));
6
+ }
7
+ const email = {
8
+ system: {
9
+ dirs: {
10
+ cli: [dir('./../cli')],
11
+ jobs: [dir('./../jobs')],
12
+ },
13
+ },
14
+ email: {
15
+ // default email queue / transport
16
+ queue: 'email-queue-black-hole',
17
+ },
18
+ queue: {
19
+ routing: {
20
+ EmailSendJob: { connection: 'email-queue-black-hole' },
21
+ EmailSent: { connection: 'email-queue-black-hole' },
22
+ },
23
+ // by default we dont have queue server for sending emails
24
+ connections: [
25
+ {
26
+ name: 'email-queue-black-hole',
27
+ service: 'BlackHoleQueueClient',
28
+ defaultQueueChannel: 'email-jobs',
29
+ defaultTopicChannel: 'email-events',
30
+ },
31
+ ],
32
+ },
33
+ };
34
+ exports.default = email;
35
+ //# sourceMappingURL=email.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email.js","sourceRoot":"","sources":["../../src/config/email.ts"],"names":[],"mappings":";;AAAA,+BAAgD;AAEhD,SAAS,GAAG,CAAC,IAAY;IACvB,OAAO,IAAA,cAAO,EAAC,IAAA,gBAAS,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,KAAK,GAAG;IACZ,MAAM,EAAE;QACN,IAAI,EAAE;YACJ,GAAG,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YACtB,IAAI,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;SACzB;KACF;IACD,KAAK,EAAE;QACL,kCAAkC;QAClC,KAAK,EAAE,wBAAwB;KAChC;IACD,KAAK,EAAE;QACL,OAAO,EAAE;YACP,YAAY,EAAE,EAAE,UAAU,EAAE,wBAAwB,EAAE;YACtD,SAAS,EAAE,EAAE,UAAU,EAAE,wBAAwB,EAAE;SACpD;QAED,0DAA0D;QAC1D,WAAW,EAAE;YACX;gBACE,IAAI,EAAE,wBAAwB;gBAC9B,OAAO,EAAE,sBAAsB;gBAC/B,mBAAmB,EAAE,YAAY;gBACjC,mBAAmB,EAAE,cAAc;aACpC;SACF;KACF;CACF,CAAC;AAEF,kBAAe,KAAK,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { QueueEvent } from '@spinajs/queue';
2
+ import { DateTime } from 'luxon';
3
+ import { IEmail } from '../interfaces';
4
+ export declare class EmailSent extends QueueEvent {
5
+ Connection?: string;
6
+ From: string;
7
+ To: string[];
8
+ /**
9
+ * Email template eg. pug file or mustashe
10
+ */
11
+ Template?: string;
12
+ /**
13
+ * Data model used in template
14
+ */
15
+ Model?: any;
16
+ Subject: string;
17
+ /**
18
+ * text content if template is not provided
19
+ */
20
+ Content?: string;
21
+ SentAt: DateTime;
22
+ constructor(email: IEmail);
23
+ }
@@ -0,0 +1,33 @@
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.EmailSent = void 0;
13
+ const queue_1 = require("@spinajs/queue");
14
+ const luxon_1 = require("luxon");
15
+ let EmailSent = class EmailSent extends queue_1.QueueEvent {
16
+ constructor(email) {
17
+ super();
18
+ this.Connection = email.connection;
19
+ this.From = email.from;
20
+ this.To = email.to;
21
+ this.Template = email.template;
22
+ this.Model = email.model;
23
+ this.Subject = email.subject;
24
+ this.Content = email.text;
25
+ this.SentAt = luxon_1.DateTime.now();
26
+ }
27
+ };
28
+ EmailSent = __decorate([
29
+ (0, queue_1.Event)(),
30
+ __metadata("design:paramtypes", [Object])
31
+ ], EmailSent);
32
+ exports.EmailSent = EmailSent;
33
+ //# sourceMappingURL=EmailSent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EmailSent.js","sourceRoot":"","sources":["../../src/events/EmailSent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAmD;AACnD,iCAAiC;AAIjC,IAAa,SAAS,GAAtB,MAAa,SAAU,SAAQ,kBAAU;IA0BvC,YAAY,KAAa;QACvB,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC/B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC;QAE1B,IAAI,CAAC,MAAM,GAAG,gBAAQ,CAAC,GAAG,EAAE,CAAC;IAC/B,CAAC;CACF,CAAA;AAvCY,SAAS;IADrB,IAAA,aAAK,GAAE;;GACK,SAAS,CAuCrB;AAvCY,8BAAS"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { Bootstrapper } from '@spinajs/di';
2
+ import { IEmail, EmailService } from './interfaces';
3
+ import { EmailSend } from './jobs/EmailSend';
4
+ export * from './interfaces';
5
+ export * from './transports';
6
+ export * from './jobs/EmailSend';
7
+ export declare class LogBotstrapper extends Bootstrapper {
8
+ bootstrap(): void;
9
+ }
10
+ /**
11
+ * Email sending service.
12
+ */
13
+ export declare class DefaultEmailService extends EmailService {
14
+ /**
15
+ *
16
+ * Tries to sends email immediately
17
+ *
18
+ * @param email - email struct
19
+ */
20
+ send(email: IEmail): Promise<void>;
21
+ sendDeferred(email: IEmail): Promise<EmailSend>;
22
+ processDefferedEmails(): Promise<void>;
23
+ }
package/lib/index.js ADDED
@@ -0,0 +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_1 = require("./interfaces");
30
+ const email_smtp_configuration_1 = __importDefault(require("./schemas/email.smtp.configuration"));
31
+ const EmailSent_1 = require("./events/EmailSent");
32
+ const EmailSend_1 = require("./jobs/EmailSend");
33
+ __exportStar(require("./interfaces"), exports);
34
+ __exportStar(require("./transports"), exports);
35
+ __exportStar(require("./jobs/EmailSend"), exports);
36
+ let LogBotstrapper = class LogBotstrapper extends di_1.Bootstrapper {
37
+ bootstrap() {
38
+ di_1.DI.register(email_smtp_configuration_1.default).asValue('__configurationSchema__');
39
+ }
40
+ };
41
+ LogBotstrapper = __decorate([
42
+ (0, di_1.Injectable)(di_1.Bootstrapper)
43
+ ], LogBotstrapper);
44
+ exports.LogBotstrapper = LogBotstrapper;
45
+ /**
46
+ * Email sending service.
47
+ */
48
+ let DefaultEmailService = class DefaultEmailService extends interfaces_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_1.EmailSent(email));
62
+ }
63
+ async sendDeferred(email) {
64
+ const dEmail = new EmailSend_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_1.EmailSend);
71
+ }
72
+ };
73
+ DefaultEmailService = __decorate([
74
+ (0, di_1.Injectable)(interfaces_1.EmailService)
75
+ ], DefaultEmailService);
76
+ exports.DefaultEmailService = DefaultEmailService;
77
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAuD;AACvD,oCAA2D;AAC3D,6CAAoD;AACpD,kGAAsE;AACtE,kDAA+C;AAC/C,gDAA6C;AAE7C,+CAA6B;AAC7B,+CAA6B;AAC7B,mDAAiC;AAGjC,IAAa,cAAc,GAA3B,MAAa,cAAe,SAAQ,iBAAY;IACvC,SAAS;QACd,OAAE,CAAC,QAAQ,CAAC,kCAAoB,CAAC,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;IACvE,CAAC;CACF,CAAA;AAJY,cAAc;IAD1B,IAAA,eAAU,EAAC,iBAAY,CAAC;GACZ,cAAc,CAI1B;AAJY,wCAAc;AAM3B;;GAEG;AAEH,IAAa,mBAAmB,GAAhC,MAAa,mBAAoB,SAAQ,yBAAY;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,qBAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IAC9C,CAAC;IAEM,KAAK,CAAC,YAAY,CAAC,KAAa;QACrC,MAAM,MAAM,GAAG,IAAI,qBAAS,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,qBAAS,CAAC,CAAC;IACtC,CAAC;CACF,CAAA;AA7BY,mBAAmB;IAD/B,IAAA,eAAU,EAAC,yBAAY,CAAC;GACZ,mBAAmB,CA6B/B;AA7BY,kDAAmB"}
@@ -1,6 +1,12 @@
1
- export declare abstract class EmailSender {
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';
5
+ export declare abstract class EmailSender extends AsyncService implements IInstanceCheck, IMappableService {
2
6
  Options: EmailConnectionOptions;
3
- abstract send(email: Email): Promise<void>;
7
+ get ServiceName(): string;
8
+ abstract send(email: IEmail): Promise<void>;
9
+ __checkInstance__(creationOptions: any): boolean;
4
10
  }
5
11
  export interface IEmailAttachement {
6
12
  /**
@@ -16,7 +22,7 @@ export interface IEmailAttachement {
16
22
  */
17
23
  provider?: string;
18
24
  }
19
- export interface Email {
25
+ export interface IEmail {
20
26
  to: string[];
21
27
  cc?: string[];
22
28
  bcc?: string[];
@@ -63,8 +69,8 @@ export interface EmailConnectionOptions {
63
69
  name: string;
64
70
  host?: string;
65
71
  port?: number;
66
- login?: string;
67
- password?: string;
72
+ user?: string;
73
+ pass?: string;
68
74
  ssl?: boolean;
69
75
  /**
70
76
  * defaults for messages
@@ -80,9 +86,29 @@ export interface EmailConnectionOptions {
80
86
  * lib specific
81
87
  */
82
88
  options?: unknown;
83
- attachements: {
84
- maxSingleSize: number;
85
- maxTotalSize: number;
86
- maxCount: number;
87
- };
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>;
88
114
  }
@@ -0,0 +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
+ __decorate([
29
+ (0, log_1.Logger)('email'),
30
+ __metadata("design:type", log_1.Log)
31
+ ], EmailService.prototype, "Log", void 0);
32
+ __decorate([
33
+ (0, configuration_1.AutoinjectService)('email.connections', EmailSender),
34
+ __metadata("design:type", Map)
35
+ ], EmailService.prototype, "Senders", void 0);
36
+ __decorate([
37
+ (0, configuration_1.Config)('email'),
38
+ __metadata("design:type", Object)
39
+ ], EmailService.prototype, "Configuration", void 0);
40
+ __decorate([
41
+ (0, di_1.Autoinject)(queue_1.QueueService),
42
+ __metadata("design:type", queue_1.QueueService)
43
+ ], EmailService.prototype, "Queue", void 0);
44
+ exports.EmailService = EmailService;
45
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +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;AAhCC;IADC,IAAA,YAAM,EAAC,OAAO,CAAC;8BACD,SAAG;yCAAC;AAGnB;IADC,IAAA,iCAAiB,EAAC,mBAAmB,EAAE,WAAW,CAAC;8BACjC,GAAG;6CAAsB;AAG5C;IADC,IAAA,sBAAM,EAAC,OAAO,CAAC;;mDAC4B;AAG5C;IADC,IAAA,eAAU,EAAC,oBAAY,CAAC;8BACR,oBAAY;2CAAC;AAXhC,oCAkCC"}
@@ -0,0 +1,30 @@
1
+ import { QueueJob } from '@spinajs/queue';
2
+ import { IEmail, IEmailAttachement } from '../interfaces';
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
+ }
@@ -0,0 +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_1 = require("../interfaces");
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_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 = __decorate([
34
+ (0, queue_1.Job)()
35
+ ], EmailSend);
36
+ exports.EmailSend = EmailSend;
37
+ //# sourceMappingURL=EmailSend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EmailSend.js","sourceRoot":"","sources":["../../src/jobs/EmailSend.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oCAAiC;AACjC,0CAA+C;AAC/C,8CAAwE;AAExE;;GAEG;AAEH,IAAa,SAAS,GAAtB,MAAa,SAAU,SAAQ,gBAAQ;IAkB9B,KAAK,CAAC,OAAO;QAClB,IAAI;YACF,MAAM,MAAM,GAAG,MAAM,OAAE,CAAC,OAAO,CAAC,yBAAY,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;AAjCY,8BAAS"}
@@ -0,0 +1,52 @@
1
+ declare const CONFIGURATION_SCHEMA: {
2
+ $id: string;
3
+ $configurationModule: string;
4
+ description: string;
5
+ type: string;
6
+ properties: {
7
+ queue: string;
8
+ connections: {
9
+ type: string;
10
+ uniqueItems: boolean;
11
+ items: {
12
+ type: string;
13
+ properties: {
14
+ ssl: {
15
+ type: string;
16
+ };
17
+ host: {
18
+ type: string;
19
+ };
20
+ port: {
21
+ type: string;
22
+ };
23
+ user: {
24
+ type: string;
25
+ };
26
+ password: {
27
+ type: string;
28
+ };
29
+ name: {
30
+ type: string;
31
+ };
32
+ sender: {
33
+ type: string;
34
+ };
35
+ options: {
36
+ type: string;
37
+ };
38
+ defaults: {
39
+ type: string;
40
+ properties: {
41
+ mailFrom: {
42
+ type: string;
43
+ };
44
+ };
45
+ };
46
+ };
47
+ };
48
+ };
49
+ };
50
+ required: string[];
51
+ };
52
+ export default CONFIGURATION_SCHEMA;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const CONFIGURATION_SCHEMA = {
4
+ $id: 'spinajs/email.configuration.schema.json',
5
+ $configurationModule: 'email',
6
+ description: 'Email smtp transport configuration option validation',
7
+ type: 'object',
8
+ properties: {
9
+ queue: 'string',
10
+ connections: {
11
+ type: 'array',
12
+ uniqueItems: true,
13
+ items: {
14
+ type: 'object',
15
+ properties: {
16
+ ssl: { type: 'boolean' },
17
+ host: { type: 'string' },
18
+ port: { type: 'number' },
19
+ user: { type: 'string' },
20
+ password: { type: 'string' },
21
+ name: { type: 'string' },
22
+ sender: { type: 'string' },
23
+ options: {
24
+ type: 'object',
25
+ },
26
+ defaults: {
27
+ type: 'object',
28
+ properties: {
29
+ mailFrom: { type: 'string' },
30
+ },
31
+ },
32
+ },
33
+ },
34
+ },
35
+ },
36
+ required: ['name', 'sender'],
37
+ };
38
+ exports.default = CONFIGURATION_SCHEMA;
39
+ //# sourceMappingURL=email.smtp.configuration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email.smtp.configuration.js","sourceRoot":"","sources":["../../src/schemas/email.smtp.configuration.ts"],"names":[],"mappings":";;AAAA,MAAM,oBAAoB,GAAG;IAC3B,GAAG,EAAE,yCAAyC;IAC9C,oBAAoB,EAAE,OAAO;IAC7B,WAAW,EAAE,sDAAsD;IACnE,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,KAAK,EAAE,QAAQ;QACf,WAAW,EAAE;YACX,IAAI,EAAE,OAAO;YACb,WAAW,EAAE,IAAI;YACjB,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,GAAG,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;oBACxB,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;oBACxB,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;oBACxB,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;oBACxB,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;oBAC5B,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;oBACxB,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;oBAC1B,OAAO,EAAE;wBACP,IAAI,EAAE,QAAQ;qBACf;oBACD,QAAQ,EAAE;wBACR,IAAI,EAAE,QAAQ;wBACd,UAAU,EAAE;4BACV,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;yBAC7B;qBACF;iBACF;aACF;SACF;KACF;IACD,QAAQ,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC;CAC7B,CAAC;AAEF,kBAAe,oBAAoB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { EmailSender } from './interfaces';
2
+ /**
3
+ * Transport that does nothing.
4
+ *
5
+ * Used for testing, or when we want temporarly disable siding emails
6
+ */
7
+ export declare class BlackHoleEmailTransport extends EmailSender {
8
+ send(): Promise<void>;
9
+ }
@@ -0,0 +1,25 @@
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.BlackHoleEmailTransport = void 0;
10
+ const di_1 = require("@spinajs/di");
11
+ const interfaces_1 = require("./interfaces");
12
+ /**
13
+ * Transport that does nothing.
14
+ *
15
+ * Used for testing, or when we want temporarly disable siding emails
16
+ */
17
+ let BlackHoleEmailTransport = class BlackHoleEmailTransport extends interfaces_1.EmailSender {
18
+ async send() { }
19
+ };
20
+ BlackHoleEmailTransport = __decorate([
21
+ (0, di_1.Injectable)(),
22
+ (0, di_1.NewInstance)()
23
+ ], BlackHoleEmailTransport);
24
+ exports.BlackHoleEmailTransport = BlackHoleEmailTransport;
25
+ //# sourceMappingURL=transports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transports.js","sourceRoot":"","sources":["../src/transports.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oCAAsD;AACtD,6CAA2C;AAE3C;;;;GAIG;AAGH,IAAa,uBAAuB,GAApC,MAAa,uBAAwB,SAAQ,wBAAW;IAC/C,KAAK,CAAC,IAAI,KAAmB,CAAC;CACtC,CAAA;AAFY,uBAAuB;IAFnC,IAAA,eAAU,GAAE;IACZ,IAAA,gBAAW,GAAE;GACD,uBAAuB,CAEnC;AAFY,0DAAuB"}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@spinajs/email",
3
- "version": "2.0.38",
3
+ "version": "2.0.45",
4
4
  "description": "sending emails easy & reliable way",
5
5
  "main": "lib/index.js",
6
6
  "private": false,
7
7
  "scripts": {
8
- "build": "npm run clean && npm run compile && cpx src/views/**/* lib/views && cpx src/static/**/* lib/static",
8
+ "build": "npm run clean && npm run compile",
9
9
  "compile": "tsc -p tsconfig.build.json",
10
10
  "clean": "",
11
11
  "test": "ts-mocha -p tsconfig.json test/**/*.test.ts",
@@ -38,18 +38,23 @@
38
38
  },
39
39
  "homepage": "https://github.com/spinajs/main#readme",
40
40
  "devDependencies": {
41
+ "@spinajs/queue-stomp-transport": "^2.0.45",
42
+ "@spinajs/templates-handlebars": "^2.0.45",
43
+ "@spinajs/templates-pug": "^2.0.45",
41
44
  "@types/luxon": "^2.3.1",
42
45
  "@types/node": "^16.11.11",
43
46
  "@types/nodemailer": "^6.4.4"
44
47
  },
45
48
  "dependencies": {
46
- "@spinajs/configuration": "^2.0.38",
47
- "@spinajs/di": "^2.0.38",
48
- "@spinajs/exceptions": "^2.0.12",
49
- "@spinajs/internal-logger": "^2.0.38",
50
- "@spinajs/intl": "^2.0.38",
51
- "@spinajs/log": "^2.0.38",
52
- "luxon": "^2.3.0"
49
+ "@spinajs/cli": "^2.0.45",
50
+ "@spinajs/configuration": "^2.0.45",
51
+ "@spinajs/di": "^2.0.45",
52
+ "@spinajs/exceptions": "^2.0.39",
53
+ "@spinajs/internal-logger": "^2.0.45",
54
+ "@spinajs/intl": "^2.0.45",
55
+ "@spinajs/log": "^2.0.45",
56
+ "@spinajs/queue": "^2.0.45",
57
+ "luxon": "^3.2.1"
53
58
  },
54
- "gitHead": "5ea5440ee9db49595f531592ebdbc6d69f457082"
59
+ "gitHead": "3aa423c570eae952dc79fe6a4704c3d2ccc178be"
55
60
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"SendEmail.js","sourceRoot":"","sources":["../../../../src/cli/SendEmail.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAA2D;AAC3D,oCAAiC;AACjC,uCAAyB;AACzB,sCAA4C;AAC5C,sCAAoC;AAoBpC,IAAa,gBAAgB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CAAC,KAAK,EAAE,CAAC,CAAC;SAClF;IACH,CAAC;CACF,CAAA;AA/BC;IADC,IAAA,YAAM,EAAC,WAAW,CAAC;;6CACA;AAFT,gBAAgB;IAR5B,IAAA,aAAO,EAAC,YAAY,EAAE,4DAA4D,CAAC;IACnF,IAAA,YAAM,EAAC,+BAA+B,EAAE,IAAI,EAAE,oBAAoB,CAAC;IACnE,IAAA,YAAM,EAAC,mBAAmB,EAAE,IAAI,EAAE,YAAY,CAAC;IAC/C,IAAA,YAAM,EAAC,eAAe,EAAE,IAAI,EAAE,8CAA8C,CAAC;IAC7E,IAAA,YAAM,EAAC,2BAA2B,EAAE,KAAK,EAAE,eAAe,CAAC;IAC3D,IAAA,YAAM,EAAC,qBAAqB,EAAE,KAAK,EAAE,iDAAiD,CAAC;IACvF,IAAA,YAAM,EAAC,uBAAuB,EAAE,IAAI,EAAE,SAAS,CAAC;IAChD,IAAA,YAAM,EAAC,yBAAyB,EAAE,KAAK,EAAE,0CAA0C,CAAC;GACxE,gBAAgB,CAiC5B;AAjCY,4CAAgB"}
@@ -1,8 +0,0 @@
1
- declare const email: {
2
- system: {
3
- dirs: {
4
- cli: string[];
5
- };
6
- };
7
- };
8
- export default email;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const path_1 = require("path");
4
- function dir(path) {
5
- return (0, path_1.resolve)((0, path_1.normalize)((0, path_1.join)(__dirname, path)));
6
- }
7
- const email = {
8
- system: {
9
- dirs: {
10
- cli: [dir('./../cli')],
11
- },
12
- },
13
- };
14
- exports.default = email;
15
- //# sourceMappingURL=email.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"email.js","sourceRoot":"","sources":["../../../../src/config/email.ts"],"names":[],"mappings":";;AAAA,+BAAgD;AAEhD,SAAS,GAAG,CAAC,IAAY;IACvB,OAAO,IAAA,cAAO,EAAC,IAAA,gBAAS,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,KAAK,GAAG;IACZ,MAAM,EAAE;QACN,IAAI,EAAE;YACJ,GAAG,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;SACvB;KACF;CACF,CAAC;AAEF,kBAAe,KAAK,CAAC"}
@@ -1,14 +0,0 @@
1
- import { AsyncModule } from '@spinajs/di';
2
- import { Log } from '@spinajs/log';
3
- import { Email, EmailSender, EmailConfiguration } from './interfaces';
4
- export * from './interfaces';
5
- /**
6
- * Inject INTL module for language support. We does nothing but to initialize module for use in templates.
7
- */
8
- export declare class Emails extends AsyncModule {
9
- protected Log: Log;
10
- protected Senders: Map<string, EmailSender>;
11
- protected Configuration: EmailConfiguration;
12
- resolveAsync(): Promise<void>;
13
- send(email: Email): Promise<void>;
14
- }
@@ -1,66 +0,0 @@
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 __metadata = (this && this.__metadata) || function (k, v) {
23
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.Emails = void 0;
27
- const index_1 = require("./../../exceptions/src/index");
28
- const di_1 = require("@spinajs/di");
29
- const log_1 = require("@spinajs/log");
30
- const configuration_1 = require("@spinajs/configuration");
31
- __exportStar(require("./interfaces"), exports);
32
- /**
33
- * Inject INTL module for language support. We does nothing but to initialize module for use in templates.
34
- */
35
- class Emails extends di_1.AsyncModule {
36
- constructor() {
37
- super(...arguments);
38
- this.Senders = new Map();
39
- }
40
- async resolveAsync() {
41
- for (const c of this.Configuration.connections) {
42
- this.Log.trace(`Found connection ${c.name} ${c.login}@${c.host}`);
43
- const connection = (await di_1.DI.resolve)(c.sender, [c]);
44
- this.Senders.set(c.name, connection);
45
- this.Log.trace(`Connection initialized - ${c.name} ${c.login}@${c.host}`);
46
- }
47
- await super.resolveAsync();
48
- }
49
- async send(email) {
50
- if (!this.Senders.has(email.connection)) {
51
- throw new index_1.InvalidOperation(`Email sender ${email.connection} not exists. Please check your configuration files.`);
52
- }
53
- const connection = this.Senders.get(email.connection);
54
- await connection.send(email);
55
- }
56
- }
57
- __decorate([
58
- (0, log_1.Logger)('email'),
59
- __metadata("design:type", log_1.Log)
60
- ], Emails.prototype, "Log", void 0);
61
- __decorate([
62
- (0, configuration_1.Config)('email'),
63
- __metadata("design:type", Object)
64
- ], Emails.prototype, "Configuration", void 0);
65
- exports.Emails = Emails;
66
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAAgE;AAChE,oCAA8C;AAC9C,sCAA2C;AAE3C,0DAAgD;AAChD,+CAA6B;AAE7B;;GAEG;AACH,MAAa,M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@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EmailSender = void 0;
4
- class EmailSender {
5
- }
6
- exports.EmailSender = EmailSender;
7
- //# sourceMappingURL=interfaces.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces.ts"],"names":[],"mappings":";;;AAAA,MAAsB,WAAW;CAIhC;AAJD,kCAIC"}
package/lib/email.js DELETED
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = email;
4
-
5
- function email() {
6
- // TODO
7
- }
@@ -1,85 +0,0 @@
1
- /**
2
- * Base class of all exceptions in framework
3
- */
4
- export declare class Exception extends Error {
5
- inner?: Error;
6
- /**
7
- * Constructs new exception with message
8
- *
9
- * @param message - error message
10
- * @param inner - inner exception ( eg. original couse of error )
11
- */
12
- constructor(message?: string, inner?: Error);
13
- }
14
- /**
15
- * Exception thrown when functionality is not supported
16
- */
17
- export declare class NotSupported extends Exception {
18
- }
19
- /**
20
- * Exception thrown when argument passed to function is invalid eg. out of range
21
- */
22
- export declare class InvalidArgument extends Exception {
23
- }
24
- /**
25
- * Exception thrown when config option is invalidl eg. missing or in invalid format
26
- */
27
- export declare class InvalidOption extends Exception {
28
- }
29
- /**
30
- * The exception that is thrown when a method call is invalid for the object's current state.
31
- */
32
- export declare class InvalidOperation extends Exception {
33
- }
34
- /**
35
- * Exception is thrown when authentication fails eg. user credentials are invalid
36
- */
37
- export declare class AuthenticationFailed extends Exception {
38
- }
39
- /**
40
- * Exception is thrown when request data are invalid
41
- */
42
- export declare class BadRequest extends Exception {
43
- }
44
- /**
45
- * Exception indicating that an access to resource by a client has been forbidden by the server
46
- * HTTP 403 - Forbidden
47
- */
48
- export declare class Forbidden extends Exception {
49
- }
50
- /**
51
- * Exception thrown when there was error with IO operations ie. not accessible file
52
- */
53
- export declare class IOFail extends Exception {
54
- }
55
- /**
56
- * The exception that is thrown when resource is not found eg. model in database or missing file
57
- */
58
- export declare class ResourceNotFound extends Exception {
59
- }
60
- /**
61
- * The exception that is thrown when method is not implemented
62
- */
63
- export declare class MethodNotImplemented extends Exception {
64
- }
65
- /**
66
- * The exception that is thrown when strange things happends in server eg. generic server error
67
- */
68
- export declare class UnexpectedServerError extends Exception {
69
- }
70
- /**
71
- * Exception occurs when resource is duplicated eg. unique constraint failed in db
72
- */
73
- export declare class ResourceDuplicated extends Exception {
74
- }
75
- /**
76
- * The exception that is thrown when JSON entity is checked against schema and is invalid
77
- */
78
- export declare class JsonValidationFailed extends Exception {
79
- }
80
- /**
81
- * The exception that is thrown if app not supports requestes `Accept` header eg. if client wants
82
- * html response but server can send only json.
83
- */
84
- export declare class ExpectedResponseUnacceptable extends Exception {
85
- }
@@ -1,106 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExpectedResponseUnacceptable = exports.JsonValidationFailed = exports.ResourceDuplicated = exports.UnexpectedServerError = exports.MethodNotImplemented = exports.ResourceNotFound = exports.IOFail = exports.Forbidden = exports.BadRequest = exports.AuthenticationFailed = exports.InvalidOperation = exports.InvalidOption = exports.InvalidArgument = exports.NotSupported = exports.Exception = void 0;
4
- /**
5
- * Base class of all exceptions in framework
6
- */
7
- class Exception extends Error {
8
- /**
9
- * Constructs new exception with message
10
- *
11
- * @param message - error message
12
- * @param inner - inner exception ( eg. original couse of error )
13
- */
14
- constructor(message, inner) {
15
- super(message);
16
- this.inner = inner;
17
- }
18
- }
19
- exports.Exception = Exception;
20
- /**
21
- * Exception thrown when functionality is not supported
22
- */
23
- class NotSupported extends Exception {
24
- }
25
- exports.NotSupported = NotSupported;
26
- /**
27
- * Exception thrown when argument passed to function is invalid eg. out of range
28
- */
29
- class InvalidArgument extends Exception {
30
- }
31
- exports.InvalidArgument = InvalidArgument;
32
- /**
33
- * Exception thrown when config option is invalidl eg. missing or in invalid format
34
- */
35
- class InvalidOption extends Exception {
36
- }
37
- exports.InvalidOption = InvalidOption;
38
- /**
39
- * The exception that is thrown when a method call is invalid for the object's current state.
40
- */
41
- class InvalidOperation extends Exception {
42
- }
43
- exports.InvalidOperation = InvalidOperation;
44
- /**
45
- * Exception is thrown when authentication fails eg. user credentials are invalid
46
- */
47
- class AuthenticationFailed extends Exception {
48
- }
49
- exports.AuthenticationFailed = AuthenticationFailed;
50
- /**
51
- * Exception is thrown when request data are invalid
52
- */
53
- class BadRequest extends Exception {
54
- }
55
- exports.BadRequest = BadRequest;
56
- /**
57
- * Exception indicating that an access to resource by a client has been forbidden by the server
58
- * HTTP 403 - Forbidden
59
- */
60
- class Forbidden extends Exception {
61
- }
62
- exports.Forbidden = Forbidden;
63
- /**
64
- * Exception thrown when there was error with IO operations ie. not accessible file
65
- */
66
- class IOFail extends Exception {
67
- }
68
- exports.IOFail = IOFail;
69
- /**
70
- * The exception that is thrown when resource is not found eg. model in database or missing file
71
- */
72
- class ResourceNotFound extends Exception {
73
- }
74
- exports.ResourceNotFound = ResourceNotFound;
75
- /**
76
- * The exception that is thrown when method is not implemented
77
- */
78
- class MethodNotImplemented extends Exception {
79
- }
80
- exports.MethodNotImplemented = MethodNotImplemented;
81
- /**
82
- * The exception that is thrown when strange things happends in server eg. generic server error
83
- */
84
- class UnexpectedServerError extends Exception {
85
- }
86
- exports.UnexpectedServerError = UnexpectedServerError;
87
- /**
88
- * Exception occurs when resource is duplicated eg. unique constraint failed in db
89
- */
90
- class ResourceDuplicated extends Exception {
91
- }
92
- exports.ResourceDuplicated = ResourceDuplicated;
93
- /**
94
- * The exception that is thrown when JSON entity is checked against schema and is invalid
95
- */
96
- class JsonValidationFailed extends Exception {
97
- }
98
- exports.JsonValidationFailed = JsonValidationFailed;
99
- /**
100
- * The exception that is thrown if app not supports requestes `Accept` header eg. if client wants
101
- * html response but server can send only json.
102
- */
103
- class ExpectedResponseUnacceptable extends Exception {
104
- }
105
- exports.ExpectedResponseUnacceptable = ExpectedResponseUnacceptable;
106
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {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