@pixelplex/mail-service 0.1.21 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/.gitlab-ci.yml +1 -25
  2. package/LICENSE.md +1 -1
  3. package/README.md +76 -111
  4. package/dist/constants/index.d.ts +1 -0
  5. package/dist/constants/index.js +18 -0
  6. package/dist/constants/index.js.map +1 -0
  7. package/dist/constants/mail.constants.d.ts +10 -0
  8. package/dist/constants/mail.constants.js +16 -0
  9. package/dist/constants/mail.constants.js.map +1 -0
  10. package/dist/decorators/index.d.ts +2 -0
  11. package/dist/decorators/index.js +19 -0
  12. package/dist/decorators/index.js.map +1 -0
  13. package/dist/decorators/inject-gateways.decorator.d.ts +2 -0
  14. package/dist/decorators/inject-gateways.decorator.js +10 -0
  15. package/dist/decorators/inject-gateways.decorator.js.map +1 -0
  16. package/dist/decorators/inject-options.decorator.d.ts +3 -0
  17. package/dist/decorators/inject-options.decorator.js +14 -0
  18. package/dist/decorators/inject-options.decorator.js.map +1 -0
  19. package/dist/factories/gateway.factory.d.ts +4 -0
  20. package/dist/factories/gateway.factory.js +17 -0
  21. package/dist/factories/gateway.factory.js.map +1 -0
  22. package/dist/factories/index.d.ts +1 -0
  23. package/dist/factories/index.js +18 -0
  24. package/dist/factories/index.js.map +1 -0
  25. package/dist/gateways/console.gateway.d.ts +6 -0
  26. package/dist/{connect/app.module.js → gateways/console.gateway.js} +14 -13
  27. package/dist/gateways/console.gateway.js.map +1 -0
  28. package/dist/gateways/index.d.ts +3 -0
  29. package/dist/gateways/index.js +20 -0
  30. package/dist/gateways/index.js.map +1 -0
  31. package/dist/gateways/slack.gateway.d.ts +8 -0
  32. package/dist/gateways/slack.gateway.js +40 -0
  33. package/dist/gateways/slack.gateway.js.map +1 -0
  34. package/dist/gateways/smtp.gateway.d.ts +9 -0
  35. package/dist/gateways/smtp.gateway.js +43 -0
  36. package/dist/gateways/smtp.gateway.js.map +1 -0
  37. package/dist/index.d.ts +7 -3
  38. package/dist/index.js +21 -5
  39. package/dist/index.js.map +1 -1
  40. package/dist/interfaces/gateway.interface.d.ts +4 -0
  41. package/dist/interfaces/gateway.interface.js +3 -0
  42. package/dist/interfaces/gateway.interface.js.map +1 -0
  43. package/dist/interfaces/index.d.ts +1 -0
  44. package/dist/interfaces/index.js +18 -0
  45. package/dist/interfaces/index.js.map +1 -0
  46. package/dist/mail.module.d.ts +5 -0
  47. package/dist/mail.module.js +68 -0
  48. package/dist/mail.module.js.map +1 -0
  49. package/dist/services/index.d.ts +1 -0
  50. package/dist/services/index.js +18 -0
  51. package/dist/services/index.js.map +1 -0
  52. package/dist/services/mail-sender.service.d.ts +11 -0
  53. package/dist/services/mail-sender.service.js +84 -0
  54. package/dist/services/mail-sender.service.js.map +1 -0
  55. package/dist/tsconfig.build.tsbuildinfo +1 -8158
  56. package/dist/types/decorators.types.d.ts +2 -0
  57. package/dist/types/decorators.types.js +3 -0
  58. package/dist/types/decorators.types.js.map +1 -0
  59. package/dist/types/gateway.class.d.ts +4 -0
  60. package/dist/types/gateway.class.js +3 -0
  61. package/dist/types/gateway.class.js.map +1 -0
  62. package/dist/types/index.d.ts +6 -0
  63. package/dist/types/index.js +23 -0
  64. package/dist/types/index.js.map +1 -0
  65. package/dist/types/options.types.d.ts +13 -0
  66. package/dist/types/options.types.js +3 -0
  67. package/dist/types/options.types.js.map +1 -0
  68. package/dist/types/slack-options.types.d.ts +3 -0
  69. package/dist/types/slack-options.types.js +3 -0
  70. package/dist/types/slack-options.types.js.map +1 -0
  71. package/dist/types/smtp-options.types.d.ts +7 -0
  72. package/dist/types/smtp-options.types.js +3 -0
  73. package/dist/types/smtp-options.types.js.map +1 -0
  74. package/dist/types/templates.types.d.ts +10 -0
  75. package/dist/types/templates.types.js +3 -0
  76. package/dist/types/templates.types.js.map +1 -0
  77. package/dist/utils/connection.utils.d.ts +4 -0
  78. package/dist/utils/connection.utils.js +17 -0
  79. package/dist/utils/connection.utils.js.map +1 -0
  80. package/dist/utils/index.d.ts +2 -0
  81. package/dist/utils/index.js +19 -0
  82. package/dist/utils/index.js.map +1 -0
  83. package/dist/utils/types.utils.d.ts +1 -0
  84. package/dist/utils/types.utils.js +3 -0
  85. package/dist/utils/types.utils.js.map +1 -0
  86. package/package.json +29 -38
  87. package/tsconfig.json +4 -1
  88. package/.dockerignore +0 -5
  89. package/dist/connect/app.module.d.ts +0 -2
  90. package/dist/connect/app.module.js.map +0 -1
  91. package/dist/connect/app.service.d.ts +0 -20
  92. package/dist/connect/app.service.js +0 -61
  93. package/dist/connect/app.service.js.map +0 -1
  94. package/dist/connect/retry.d.ts +0 -2
  95. package/dist/connect/retry.js +0 -13
  96. package/dist/connect/retry.js.map +0 -1
  97. package/dist/connection.d.ts +0 -3
  98. package/dist/connection.js +0 -33
  99. package/dist/connection.js.map +0 -1
  100. package/dist/main.d.ts +0 -1
  101. package/dist/main.js +0 -23
  102. package/dist/main.js.map +0 -1
  103. package/dist/service/app.controller.d.ts +0 -9
  104. package/dist/service/app.controller.js +0 -59
  105. package/dist/service/app.controller.js.map +0 -1
  106. package/dist/service/app.module.d.ts +0 -2
  107. package/dist/service/app.module.js +0 -23
  108. package/dist/service/app.module.js.map +0 -1
  109. package/dist/service/sender.service.d.ts +0 -7
  110. package/dist/service/sender.service.js +0 -63
  111. package/dist/service/sender.service.js.map +0 -1
@@ -0,0 +1,2 @@
1
+ import { Inject } from '@nestjs/common';
2
+ export type InjectDecorator = ReturnType<typeof Inject>;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=decorators.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorators.types.js","sourceRoot":"","sources":["../../src/types/decorators.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { IGateway } from '../interfaces';
2
+ export type GatewayClass = {
3
+ new (...args: any[]): IGateway;
4
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=gateway.class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gateway.class.js","sourceRoot":"","sources":["../../src/types/gateway.class.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ export * from './templates.types';
2
+ export * from './decorators.types';
3
+ export * from './gateway.class';
4
+ export * from './options.types';
5
+ export * from './slack-options.types';
6
+ export * from './smtp-options.types';
@@ -0,0 +1,23 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./templates.types"), exports);
18
+ __exportStar(require("./decorators.types"), exports);
19
+ __exportStar(require("./gateway.class"), exports);
20
+ __exportStar(require("./options.types"), exports);
21
+ __exportStar(require("./slack-options.types"), exports);
22
+ __exportStar(require("./smtp-options.types"), exports);
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,qDAAmC;AACnC,kDAAgC;AAChC,kDAAgC;AAChC,wDAAsC;AACtC,uDAAqC"}
@@ -0,0 +1,13 @@
1
+ import { ExtendsOrEmpty } from '../utils';
2
+ import { GatewayClass } from './gateway.class';
3
+ import { SlackOptions } from './slack-options.types';
4
+ import { SmtpOptions } from './smtp-options.types';
5
+ export type Gateway = 'smtp' | 'console' | 'slack';
6
+ export type MailOptions<TGateway extends Gateway = Gateway> = {
7
+ readonly gateways: [TGateway, ...TGateway[]];
8
+ readonly customGateways?: [GatewayClass, ...GatewayClass[]];
9
+ } & ExtendsOrEmpty<'smtp', TGateway, {
10
+ smtp: SmtpOptions;
11
+ }> & ExtendsOrEmpty<'slack', TGateway, {
12
+ slack: SlackOptions;
13
+ }>;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=options.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.types.js","sourceRoot":"","sources":["../../src/types/options.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export type SlackOptions = {
2
+ url: string;
3
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=slack-options.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slack-options.types.js","sourceRoot":"","sources":["../../src/types/slack-options.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ export type SmtpOptions = {
2
+ readonly host: string;
3
+ readonly port: number;
4
+ readonly username: string;
5
+ readonly password: string;
6
+ readonly sender: string;
7
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=smtp-options.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smtp-options.types.js","sourceRoot":"","sources":["../../src/types/smtp-options.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ export type Content = {
2
+ subject?: string;
3
+ html?: string;
4
+ plain?: string;
5
+ };
6
+ export type TemplatePaths = {
7
+ html?: string;
8
+ plain?: string;
9
+ subject?: string;
10
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=templates.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.types.js","sourceRoot":"","sources":["../../src/types/templates.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { Gateway } from '../types';
2
+ export declare function getMailOptionsToken(connection?: string): string;
3
+ export declare function getGatewayOptionsToken(gateway: Gateway, connection?: string): string;
4
+ export declare function getGatewaysToken(connection?: string): string;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGatewaysToken = exports.getGatewayOptionsToken = exports.getMailOptionsToken = void 0;
4
+ const constants_1 = require("../constants");
5
+ function getMailOptionsToken(connection) {
6
+ return `${connection || constants_1.MAIL_MODULE_CONSTANTS.DEFAULT_CONNECTION}_${constants_1.MAIL_MODULE_CONSTANTS.OPTIONS_TOKEN}`;
7
+ }
8
+ exports.getMailOptionsToken = getMailOptionsToken;
9
+ function getGatewayOptionsToken(gateway, connection) {
10
+ return `${connection || constants_1.MAIL_MODULE_CONSTANTS.DEFAULT_CONNECTION}_${constants_1.MAIL_MODULE_CONSTANTS.OPTIONS_TOKEN}_${gateway}`;
11
+ }
12
+ exports.getGatewayOptionsToken = getGatewayOptionsToken;
13
+ function getGatewaysToken(connection) {
14
+ return `${connection || constants_1.MAIL_MODULE_CONSTANTS.DEFAULT_CONNECTION}_${constants_1.MAIL_MODULE_CONSTANTS.GATEWAYS_TOKEN}`;
15
+ }
16
+ exports.getGatewaysToken = getGatewaysToken;
17
+ //# sourceMappingURL=connection.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.utils.js","sourceRoot":"","sources":["../../src/utils/connection.utils.ts"],"names":[],"mappings":";;;AAAA,4CAAqD;AAGrD,SAAgB,mBAAmB,CAAC,UAAmB;IACrD,OAAO,GAAG,UAAU,IAAI,iCAAqB,CAAC,kBAAkB,IAAI,iCAAqB,CAAC,aAAa,EAAE,CAAC;AAC5G,CAAC;AAFD,kDAEC;AAED,SAAgB,sBAAsB,CAAC,OAAgB,EAAE,UAAmB;IAC1E,OAAO,GAAG,UAAU,IAAI,iCAAqB,CAAC,kBAAkB,IAAI,iCAAqB,CAAC,aAAa,IAAI,OAAO,EAAE,CAAC;AACvH,CAAC;AAFD,wDAEC;AAED,SAAgB,gBAAgB,CAAC,UAAmB;IAClD,OAAO,GAAG,UAAU,IAAI,iCAAqB,CAAC,kBAAkB,IAAI,iCAAqB,CAAC,cAAc,EAAE,CAAC;AAC7G,CAAC;AAFD,4CAEC"}
@@ -0,0 +1,2 @@
1
+ export * from './connection.utils';
2
+ export * from './types.utils';
@@ -0,0 +1,19 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./connection.utils"), exports);
18
+ __exportStar(require("./types.utils"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,gDAA8B"}
@@ -0,0 +1 @@
1
+ export type ExtendsOrEmpty<T, U, Res> = T extends U ? Res : {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.utils.js","sourceRoot":"","sources":["../../src/utils/types.utils.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixelplex/mail-service",
3
- "version": "0.1.21",
3
+ "version": "0.2.0",
4
4
  "description": "Mail service",
5
5
  "author": "dev@pixelplex.io",
6
6
  "private": false,
@@ -10,63 +10,54 @@
10
10
  "prebuild": "rimraf dist",
11
11
  "build": "nest build",
12
12
  "format": "prettier --write \"src/**/*.ts\"",
13
- "start": "nest start",
14
- "start:dev": "nest start --watch",
15
- "start:debug": "nest start --debug --watch",
16
- "start:prod": "node dist/main",
17
- "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
13
+ "lint": "eslint \"{src,apps,libs,test}/**/*.ts\"",
14
+ "lint:fix": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
18
15
  "test": "jest",
19
16
  "test:watch": "jest --watch",
20
17
  "test:cov": "jest --coverage",
21
18
  "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
22
19
  "test:e2e": "jest --config ./test/jest-e2e.json",
23
20
  "audit": "audit-ci --config audit-ci.json",
24
- "prepare": "husky install"
21
+ "prepare": "husky install",
22
+ "type-check": "tsc --pretty --noEmit"
25
23
  },
26
24
  "dependencies": {
27
- "@nestjs/common": "^7.5.1",
28
- "@nestjs/core": "^7.5.1",
29
- "@nestjs/microservices": "^7.5.2",
30
- "@nestjs/platform-express": "^7.5.1",
31
- "@sentry/node": "^5.27.4",
32
- "amqp-connection-manager": "^3.2.1",
33
- "amqplib": "^0.6.0",
34
- "config": "^3.3.2",
35
- "express-handlebars": "^5.2.0",
36
- "handlebars": "^4.7.6",
37
- "nodemailer": "^6.7.2",
38
- "nodemailer-express-handlebars": "^4.0.0",
25
+ "@nestjs/common": "^9.4.3",
26
+ "@nestjs/core": "^9.4.3",
27
+ "axios": "^1.4.0",
28
+ "handlebars": "^4.7.7",
29
+ "nodemailer": "^6.9.3",
39
30
  "reflect-metadata": "^0.1.13",
40
- "rimraf": "^3.0.2",
41
- "rxjs": "^6.6.3"
31
+ "rimraf": "^3.0.2"
42
32
  },
43
33
  "devDependencies": {
44
- "@nestjs/cli": "^7.5.1",
45
- "@nestjs/schematics": "^7.1.3",
46
- "@nestjs/testing": "^7.5.1",
47
- "@types/express": "^4.17.8",
34
+ "@nestjs/cli": "^9.5.0",
35
+ "@nestjs/schematics": "^9.2.0",
36
+ "@nestjs/testing": "^9.4.3",
37
+ "@types/express": "^4.17.17",
48
38
  "@types/jest": "^26.0.15",
49
- "@types/node": "^14.14.6",
50
- "@types/supertest": "^2.0.10",
51
- "@typescript-eslint/eslint-plugin": "^5.3.0",
52
- "@typescript-eslint/eslint-plugin-tslint": "^5.3.0",
53
- "@typescript-eslint/parser": "^5.3.0",
39
+ "@types/node": "^18.16.18",
40
+ "@types/nodemailer": "^6.4.8",
41
+ "@types/supertest": "^2.0.12",
42
+ "@typescript-eslint/eslint-plugin": "^5.60.1",
43
+ "@typescript-eslint/eslint-plugin-tslint": "^5.60.1",
44
+ "@typescript-eslint/parser": "^5.60.1",
54
45
  "audit-ci": "^5.1.2",
55
- "eslint": "^8.2.0",
56
- "eslint-config-prettier": "^8.3.0",
57
- "eslint-import-resolver-typescript": "^2.5.0",
58
- "eslint-plugin-import": "^2.25.2",
59
- "eslint-plugin-prettier": "^4.0.0",
46
+ "eslint": "^8.43.0",
47
+ "eslint-config-prettier": "^8.8.0",
48
+ "eslint-import-resolver-typescript": "^3.5.5",
49
+ "eslint-plugin-import": "^2.27.5",
50
+ "eslint-plugin-prettier": "^4.2.1",
60
51
  "husky": "^7.0.2",
61
52
  "jest": "^26.6.3",
62
53
  "prettier": "^2.5.1",
63
54
  "pretty-quick": "^3.1.3",
64
- "supertest": "^6.0.0",
55
+ "supertest": "^6.3.3",
65
56
  "ts-jest": "^26.4.3",
66
57
  "ts-loader": "^8.0.8",
67
58
  "ts-node": "^9.0.0",
68
- "tsconfig-paths": "^3.9.0",
69
- "typescript": "^4.0.5"
59
+ "tsconfig-paths": "^4.2.0",
60
+ "typescript": "^5.1.6"
70
61
  },
71
62
  "jest": {
72
63
  "moduleFileExtensions": [
package/tsconfig.json CHANGED
@@ -6,10 +6,13 @@
6
6
  "emitDecoratorMetadata": true,
7
7
  "experimentalDecorators": true,
8
8
  "allowSyntheticDefaultImports": true,
9
+ "esModuleInterop": true,
9
10
  "target": "es2017",
10
11
  "sourceMap": true,
11
12
  "outDir": "./dist",
12
13
  "baseUrl": "./",
13
- "incremental": true
14
+ "incremental": true,
15
+ "strict": true,
16
+ "typeRoots": ["node_modules/@types"]
14
17
  }
15
18
  }
package/.dockerignore DELETED
@@ -1,5 +0,0 @@
1
- node_modules
2
- config/local.json
3
- dist
4
- templates
5
- docker-compose.yml
@@ -1,2 +0,0 @@
1
- export declare class MailModule {
2
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"app.module.js","sourceRoot":"","sources":["../../src/connect/app.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,+CAA4C;AAQ5C,IAAa,UAAU,GAAvB,MAAa,UAAU;CAAG,CAAA;AAAb,UAAU;IANtB,eAAM,CAAC;QACN,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,CAAC,yBAAW,CAAC;QACtB,WAAW,EAAE,EAAE;QACf,SAAS,EAAE,CAAC,yBAAW,CAAC;KACzB,CAAC;GACW,UAAU,CAAG;AAAb,gCAAU"}
@@ -1,20 +0,0 @@
1
- import { OnApplicationBootstrap } from '@nestjs/common';
2
- import { ClientProxy } from '@nestjs/microservices';
3
- import { Observable } from 'rxjs';
4
- export declare class MailService implements OnApplicationBootstrap {
5
- private logger;
6
- client: ClientProxy;
7
- clientRecovery: ClientProxy;
8
- onApplicationBootstrap(): Promise<void>;
9
- /**
10
- * @param to - email to send the message to
11
- * @param type - the type of message to send. files `{type}.handlebars` and `{type}.subject.handlebars` will used
12
- * @param payload - object with payload to build you mail
13
- * @param ttl - the number of seconds after which the message will be rejected from the queue if,
14
- * but only if it was processed with an error. Set 0 if you think your message should live until
15
- * it is successfully sent.
16
- */
17
- sendMail<TResult = any>(to: string, type: string, payload?: {
18
- [key: string]: unknown;
19
- }, ttl?: number): Observable<TResult>;
20
- }
@@ -1,61 +0,0 @@
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.MailService = void 0;
13
- const common_1 = require("@nestjs/common");
14
- const microservices_1 = require("@nestjs/microservices");
15
- const rxjs_1 = require("rxjs");
16
- const connection_1 = require("../connection");
17
- const retry_1 = require("./retry");
18
- let MailService = class MailService {
19
- constructor() {
20
- this.logger = new common_1.Logger('Mail::MailService');
21
- }
22
- async onApplicationBootstrap() {
23
- await rxjs_1.defer(async () => {
24
- await this.client.connect();
25
- await this.clientRecovery.connect();
26
- })
27
- .pipe(retry_1.default(10, 5000))
28
- .toPromise();
29
- this.logger.log('RMQ Connected');
30
- }
31
- /**
32
- * @param to - email to send the message to
33
- * @param type - the type of message to send. files `{type}.handlebars` and `{type}.subject.handlebars` will used
34
- * @param payload - object with payload to build you mail
35
- * @param ttl - the number of seconds after which the message will be rejected from the queue if,
36
- * but only if it was processed with an error. Set 0 if you think your message should live until
37
- * it is successfully sent.
38
- */
39
- sendMail(to, type, payload, ttl = 0) {
40
- return this.client.emit('new_mail', {
41
- type,
42
- payload,
43
- to,
44
- timestamp: new Date().getTime(),
45
- ttl,
46
- });
47
- }
48
- };
49
- __decorate([
50
- microservices_1.Client(connection_1.generalClient),
51
- __metadata("design:type", microservices_1.ClientProxy)
52
- ], MailService.prototype, "client", void 0);
53
- __decorate([
54
- microservices_1.Client(connection_1.dlClient),
55
- __metadata("design:type", microservices_1.ClientProxy)
56
- ], MailService.prototype, "clientRecovery", void 0);
57
- MailService = __decorate([
58
- common_1.Injectable()
59
- ], MailService);
60
- exports.MailService = MailService;
61
- //# sourceMappingURL=app.service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"app.service.js","sourceRoot":"","sources":["../../src/connect/app.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4E;AAC5E,yDAA4D;AAC5D,+BAAyC;AACzC,8CAAwD;AAExD,mCAA4B;AAG5B,IAAa,WAAW,GAAxB,MAAa,WAAW;IAAxB;QACU,WAAM,GAAW,IAAI,eAAM,CAAC,mBAAmB,CAAC,CAAC;IAwC3D,CAAC;IAhCC,KAAK,CAAC,sBAAsB;QAC1B,MAAM,YAAK,CAAC,KAAK,IAAI,EAAE;YACrB,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAC5B,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;QACtC,CAAC,CAAC;aACC,IAAI,CAAC,eAAK,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;aACrB,SAAS,EAAE,CAAC;QACf,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC;IAED;;;;;;;OAOG;IACH,QAAQ,CACN,EAAU,EACV,IAAY,EACZ,OAAoC,EACpC,MAAc,CAAC;QAEf,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAuB,UAAU,EAAE;YACxD,IAAI;YACJ,OAAO;YACP,EAAE;YACF,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;YAC/B,GAAG;SACJ,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AArCC;IADC,sBAAM,CAAC,0BAAa,CAAC;8BACd,2BAAW;2CAAC;AAGpB;IADC,sBAAM,CAAC,qBAAQ,CAAC;8BACD,2BAAW;mDAAC;AAPjB,WAAW;IADvB,mBAAU,EAAE;GACA,WAAW,CAyCvB;AAzCY,kCAAW"}
@@ -1,2 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- export default function retry(retryAttempts?: number, retryDelay?: number): <T>(source: Observable<T>) => Observable<T>;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const operators_1 = require("rxjs/operators");
4
- function retry(retryAttempts = 10, retryDelay = 10000) {
5
- return (source) => source.pipe(operators_1.retryWhen((e) => e.pipe(operators_1.scan((acc, error) => {
6
- if (acc + 1 >= retryAttempts) {
7
- throw error;
8
- }
9
- return acc + 1;
10
- }, 0), operators_1.delay(retryDelay))));
11
- }
12
- exports.default = retry;
13
- //# sourceMappingURL=retry.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/connect/retry.ts"],"names":[],"mappings":";;AACA,8CAAwD;AAExD,SAAwB,KAAK,CAAC,aAAa,GAAG,EAAE,EAAE,UAAU,GAAG,KAAK;IAClE,OAAO,CAAI,MAAqB,EAAE,EAAE,CAClC,MAAM,CAAC,IAAI,CACT,qBAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CACd,CAAC,CAAC,IAAI,CACJ,gBAAI,CAAC,CAAC,GAAW,EAAE,KAAY,EAAE,EAAE;QACjC,IAAI,GAAG,GAAG,CAAC,IAAI,aAAa,EAAE;YAC5B,MAAM,KAAK,CAAC;SACb;QACD,OAAO,GAAG,GAAG,CAAC,CAAC;IACjB,CAAC,EAAE,CAAC,CAAC,EACL,iBAAK,CAAC,UAAU,CAAC,CAClB,CACF,CACF,CAAC;AACN,CAAC;AAfD,wBAeC"}
@@ -1,3 +0,0 @@
1
- import { RmqOptions } from '@nestjs/microservices';
2
- export declare const generalClient: RmqOptions;
3
- export declare const dlClient: RmqOptions;
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dlClient = exports.generalClient = void 0;
4
- const microservices_1 = require("@nestjs/microservices");
5
- const config_1 = require("config");
6
- exports.generalClient = {
7
- transport: microservices_1.Transport.RMQ,
8
- options: {
9
- urls: [config_1.MAIL_SERVICE.RMQ.URL],
10
- noAck: false,
11
- queueOptions: {
12
- durable: true,
13
- deadLetterExchange: '',
14
- deadLetterRoutingKey: `DL_${config_1.MAIL_SERVICE.RMQ.QUEUE}`,
15
- },
16
- queue: config_1.MAIL_SERVICE.RMQ.QUEUE,
17
- },
18
- };
19
- exports.dlClient = {
20
- transport: microservices_1.Transport.RMQ,
21
- options: {
22
- urls: [config_1.MAIL_SERVICE.RMQ.URL],
23
- noAck: false,
24
- queueOptions: {
25
- durable: true,
26
- deadLetterExchange: '',
27
- deadLetterRoutingKey: config_1.MAIL_SERVICE.RMQ.QUEUE,
28
- messageTtl: config_1.MAIL_SERVICE.RMQ.MESSAGE_TTL,
29
- },
30
- queue: `DL_${config_1.MAIL_SERVICE.RMQ.QUEUE}`,
31
- },
32
- };
33
- //# sourceMappingURL=connection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":";;;AAAA,yDAA8D;AAC9D,mCAAsC;AAEzB,QAAA,aAAa,GAAe;IACvC,SAAS,EAAE,yBAAS,CAAC,GAAG;IACxB,OAAO,EAAE;QACP,IAAI,EAAE,CAAC,qBAAY,CAAC,GAAG,CAAC,GAAG,CAAC;QAC5B,KAAK,EAAE,KAAK;QACZ,YAAY,EAAE;YACZ,OAAO,EAAE,IAAI;YACb,kBAAkB,EAAE,EAAE;YACtB,oBAAoB,EAAE,MAAM,qBAAY,CAAC,GAAG,CAAC,KAAK,EAAE;SACrD;QACD,KAAK,EAAE,qBAAY,CAAC,GAAG,CAAC,KAAK;KAC9B;CACF,CAAC;AAEW,QAAA,QAAQ,GAAe;IAClC,SAAS,EAAE,yBAAS,CAAC,GAAG;IACxB,OAAO,EAAE;QACP,IAAI,EAAE,CAAC,qBAAY,CAAC,GAAG,CAAC,GAAG,CAAC;QAC5B,KAAK,EAAE,KAAK;QACZ,YAAY,EAAE;YACZ,OAAO,EAAE,IAAI;YACb,kBAAkB,EAAE,EAAE;YACtB,oBAAoB,EAAE,qBAAY,CAAC,GAAG,CAAC,KAAK;YAC5C,UAAU,EAAE,qBAAY,CAAC,GAAG,CAAC,WAAW;SACzC;QACD,KAAK,EAAE,MAAM,qBAAY,CAAC,GAAG,CAAC,KAAK,EAAE;KACtC;CACF,CAAC"}
package/dist/main.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/main.js DELETED
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@nestjs/core");
4
- const common_1 = require("@nestjs/common");
5
- const Sentry = require("@sentry/node");
6
- const config_1 = require("config");
7
- const app_module_1 = require("./service/app.module");
8
- const connection_1 = require("./connection");
9
- const logger = new common_1.Logger('Mail::Application');
10
- if (config_1.SENTRY.ENABLED && config_1.SENTRY.DSN) {
11
- Sentry.init({
12
- dsn: config_1.SENTRY.DSN,
13
- });
14
- logger.log('Sentry is initialized');
15
- }
16
- async function bootstrap() {
17
- const app = await core_1.NestFactory.createMicroservice(app_module_1.AppModule, connection_1.generalClient);
18
- await app.listen(() => {
19
- logger.log('RMQ Connected. Service is started');
20
- });
21
- }
22
- bootstrap();
23
- //# sourceMappingURL=main.js.map
package/dist/main.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;AAAA,uCAA2C;AAE3C,2CAAwC;AACxC,uCAAuC;AACvC,mCAAgC;AAChC,qDAAiD;AACjD,6CAA6C;AAE7C,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,mBAAmB,CAAC,CAAC;AAE/C,IAAI,eAAM,CAAC,OAAO,IAAI,eAAM,CAAC,GAAG,EAAE;IAChC,MAAM,CAAC,IAAI,CAAC;QACV,GAAG,EAAE,eAAM,CAAC,GAAG;KAChB,CAAC,CAAC;IACH,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;CACrC;AAED,KAAK,UAAU,SAAS;IACtB,MAAM,GAAG,GAAG,MAAM,kBAAW,CAAC,kBAAkB,CAAsB,sBAAS,EAAE,0BAAa,CAAC,CAAC;IAChG,MAAM,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE;QACpB,MAAM,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC;AACD,SAAS,EAAE,CAAC"}
@@ -1,9 +0,0 @@
1
- import { RmqContext } from '@nestjs/microservices';
2
- import { MailMessage } from '../mail';
3
- import { SenderService } from './sender.service';
4
- export declare class AppController {
5
- private readonly senderService;
6
- private logger;
7
- constructor(senderService: SenderService);
8
- getHello(data: MailMessage, context: RmqContext): Promise<void>;
9
- }
@@ -1,59 +0,0 @@
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
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.AppController = void 0;
16
- const common_1 = require("@nestjs/common");
17
- const microservices_1 = require("@nestjs/microservices");
18
- const Sentry = require("@sentry/node");
19
- const sender_service_1 = require("./sender.service");
20
- let AppController = class AppController {
21
- constructor(senderService) {
22
- this.senderService = senderService;
23
- this.logger = new common_1.Logger('Mail::AppController');
24
- }
25
- async getHello(data, context) {
26
- const channel = context.getChannelRef();
27
- const originalMsg = context.getMessage();
28
- try {
29
- await this.senderService.sendMail(data.to, data.type, data.payload);
30
- channel.ack(originalMsg);
31
- }
32
- catch (e) {
33
- if (data.ttl > 0 && (new Date().getTime() - data.timestamp) / 1000 > data.ttl) {
34
- this.logger.warn(`message to "${data.to}" with template "${data.type}" was market as processed due to exceeding ttl`);
35
- channel.ack(originalMsg);
36
- return;
37
- }
38
- Sentry.captureException(e, {
39
- extra: data,
40
- });
41
- this.logger.error('send email error');
42
- this.logger.error(e);
43
- channel.nack(originalMsg, false, false);
44
- }
45
- }
46
- };
47
- __decorate([
48
- microservices_1.EventPattern('new_mail'),
49
- __param(0, microservices_1.Payload()), __param(1, microservices_1.Ctx()),
50
- __metadata("design:type", Function),
51
- __metadata("design:paramtypes", [Object, microservices_1.RmqContext]),
52
- __metadata("design:returntype", Promise)
53
- ], AppController.prototype, "getHello", null);
54
- AppController = __decorate([
55
- common_1.Controller(),
56
- __metadata("design:paramtypes", [sender_service_1.SenderService])
57
- ], AppController);
58
- exports.AppController = AppController;
59
- //# sourceMappingURL=app.controller.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"app.controller.js","sourceRoot":"","sources":["../../src/service/app.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,yDAA+E;AAC/E,uCAAuC;AAEvC,qDAAiD;AAGjD,IAAa,aAAa,GAA1B,MAAa,aAAa;IAExB,YAA6B,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;QADjD,WAAM,GAAG,IAAI,eAAM,CAAC,qBAAqB,CAAC,CAAC;IACS,CAAC;IAG7D,KAAK,CAAC,QAAQ,CAAY,IAAiB,EAAS,OAAmB;QACrE,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QACxC,MAAM,WAAW,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;QACzC,IAAI;YACF,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YACpE,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;SAC1B;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,IAAI,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE;gBAC7E,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,eAAe,IAAI,CAAC,EAAE,oBAAoB,IAAI,CAAC,IAAI,gDAAgD,CACpG,CAAC;gBACF,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;gBACzB,OAAO;aACR;YACD,MAAM,CAAC,gBAAgB,CAAC,CAAC,EAAE;gBACzB,KAAK,EAAE,IAAI;aACZ,CAAC,CAAC;YACH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;YACtC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACrB,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;SACzC;IACH,CAAC;CACF,CAAA;AAtBC;IADC,4BAAY,CAAC,UAAU,CAAC;IACT,WAAA,uBAAO,EAAE,CAAA,EAAqB,WAAA,mBAAG,EAAE,CAAA;;6CAAU,0BAAU;;6CAqBtE;AA1BU,aAAa;IADzB,mBAAU,EAAE;qCAGiC,8BAAa;GAF9C,aAAa,CA2BzB;AA3BY,sCAAa"}
@@ -1,2 +0,0 @@
1
- export declare class AppModule {
2
- }