storemw-core-api 1.0.92 → 1.0.93

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.
@@ -1,6 +1,6 @@
1
1
  export { FeatureResetPasswordProps, FeatureResetPasswordSuccessProps, FeatureResetPasswordRequestProps } from './reset_password/resetPasswordType';
2
2
  export { ResetPasswordHook } from "./reset_password/resetPasswordRegistry";
3
3
  export { registerResetPasswordHook } from "./reset_password/resetPasswordRegister";
4
- export { FeatureSmtpEmailProps, FeatureSmtpEmailOptions, FeatureSmtpEmailStartSendProps, FeatureSmtpEmailSuccessSendProps } from './smtp_email/smtpEmailType';
4
+ export { FeatureSmtpEmailProps, FeatureSmtpEmailOptions, FeatureSmtpEmailHbsOptions, FeatureSmtpEmailStartSendProps, FeatureSmtpEmailSuccessSendProps } from './smtp_email/smtpEmailType';
5
5
  export { SmtpEmailHook } from "./smtp_email/smtpEmailRegistry";
6
6
  export { registerSmtpEmailHook } from "./smtp_email/smtpEmailRegister";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/features/index.ts"],"names":[],"mappings":";;;AACA,gFAA0E;AAAjE,0HAAA,iBAAiB,OAAA;AAC1B,gFAAkF;AAAzE,kIAAA,yBAAyB,OAAA;AAGlC,oEAA8D;AAArD,kHAAA,aAAa,OAAA;AACtB,oEAAsE;AAA7D,0HAAA,qBAAqB,OAAA","sourcesContent":["export { FeatureResetPasswordProps, FeatureResetPasswordSuccessProps, FeatureResetPasswordRequestProps } from './reset_password/resetPasswordType'\nexport { ResetPasswordHook } from \"./reset_password/resetPasswordRegistry\"\nexport { registerResetPasswordHook } from \"./reset_password/resetPasswordRegister\"\n\nexport { FeatureSmtpEmailProps, FeatureSmtpEmailOptions, FeatureSmtpEmailStartSendProps, FeatureSmtpEmailSuccessSendProps } from './smtp_email/smtpEmailType'\nexport { SmtpEmailHook } from \"./smtp_email/smtpEmailRegistry\"\nexport { registerSmtpEmailHook } from \"./smtp_email/smtpEmailRegister\""]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/features/index.ts"],"names":[],"mappings":";;;AACA,gFAA0E;AAAjE,0HAAA,iBAAiB,OAAA;AAC1B,gFAAkF;AAAzE,kIAAA,yBAAyB,OAAA;AAGlC,oEAA8D;AAArD,kHAAA,aAAa,OAAA;AACtB,oEAAsE;AAA7D,0HAAA,qBAAqB,OAAA","sourcesContent":["export { FeatureResetPasswordProps, FeatureResetPasswordSuccessProps, FeatureResetPasswordRequestProps } from './reset_password/resetPasswordType'\nexport { ResetPasswordHook } from \"./reset_password/resetPasswordRegistry\"\nexport { registerResetPasswordHook } from \"./reset_password/resetPasswordRegister\"\n\nexport { FeatureSmtpEmailProps, FeatureSmtpEmailOptions, FeatureSmtpEmailHbsOptions, FeatureSmtpEmailStartSendProps, FeatureSmtpEmailSuccessSendProps } from './smtp_email/smtpEmailType'\nexport { SmtpEmailHook } from \"./smtp_email/smtpEmailRegistry\"\nexport { registerSmtpEmailHook } from \"./smtp_email/smtpEmailRegister\""]}
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.SmtpEmailHook = void 0;
4
7
  const utils_1 = require("../../utils");
8
+ const path_1 = __importDefault(require("path"));
5
9
  // import { OneTimeCodeType, ResetPasswordMethod } from "../../services";
6
10
  // Runtime storage for injected hook
7
11
  exports.SmtpEmailHook = {
@@ -18,6 +22,16 @@ exports.SmtpEmailHook = {
18
22
  password: ""
19
23
  },
20
24
  connectionTimeout: 500,
25
+ hbsOptions: {
26
+ extName: ".hbs",
27
+ viewPath: path_1.default.join(__dirname, "templates"),
28
+ viewEngine: {
29
+ layoutsDir: path_1.default.join(__dirname, "templates"),
30
+ partialsDir: path_1.default.join(__dirname, "templates"),
31
+ extname: ".hbs",
32
+ defaultLayout: false
33
+ },
34
+ }
21
35
  };
22
36
  },
23
37
  onStartSend: async (props) => {
@@ -1 +1 @@
1
- {"version":3,"file":"smtpEmailRegistry.js","sourceRoot":"","sources":["../../../src/features/smtp_email/smtpEmailRegistry.ts"],"names":[],"mappings":";;;AACA,mCAAoC;AACpC,qEAAqE;AAErE,oCAAoC;AACvB,QAAA,aAAa,GAA0B;IAChD,OAAO,EAAE,KAAK,IAAsC,EAAE;QAElD,UAAU;QACV,kDAAkD;QAClD,4DAA4D;QAE5D,OAAO;YACH,QAAQ,EAAE,EAAE;YACZ,QAAQ,EAAE,EAAE;YACZ,UAAU,EAAE,IAAI;YAChB,cAAc,EAAE;gBACZ,QAAQ,EAAE,EAAE;gBACZ,QAAQ,EAAE,EAAE;aACf;YACD,iBAAiB,EAAE,GAAG;SACzB,CAAA;IAEL,CAAC;IACD,WAAW,EAAE,KAAK,EAAE,KAAqC,EAAE,EAAE;QACzD,6BAA6B;QAC7B,uFAAuF;QACvF,IAAA,kBAAU,EAAC,mDAAmD,CAAC,CAAA;IACnE,CAAC;IACD,aAAa,EAAE,KAAK,EAAE,KAAuC,EAAE,EAAE;QAC7D,wBAAwB;QACxB,oFAAoF;QACpF,IAAA,kBAAU,EAAC,qDAAqD,CAAC,CAAA;IACrE,CAAC;CACJ,CAAA","sourcesContent":["import { FeatureSmtpEmailProps, FeatureSmtpEmailOptions, FeatureSmtpEmailSuccessSendProps, FeatureSmtpEmailStartSendProps } from '@/features'\nimport { throwError } from '@/utils'\n// import { OneTimeCodeType, ResetPasswordMethod } from \"@/services\";\n\n// Runtime storage for injected hook\nexport const SmtpEmailHook: FeatureSmtpEmailProps = {\n onSetup: async (): Promise<FeatureSmtpEmailOptions> => {\n\n // default\n // const oneTimeCodeType: OneTimeCodeType = \"otp\";\n // const resetPasswordMethod: ResetPasswordMethod = \"email\";\n\n return {\n smtpHost: \"\",\n smtpPort: 25,\n smtpSecure: true,\n smtpCredential: {\n username: \"\",\n password: \"\"\n },\n connectionTimeout: 500,\n }\n\n },\n onStartSend: async (props: FeatureSmtpEmailStartSendProps) => {\n // Default behavior: just log\n // console.log(`[ResetPasswordService] Default onRequest called for ${JSON.stringify}`)\n throwError(`Invalid settings for onStartSend in SmtpEmailHook`)\n },\n onSuccessSend: async (props: FeatureSmtpEmailSuccessSendProps) => {\n // Default behavior: log\n // console.log(`[ResetPasswordService] Default onSuccess called for user ${userId}`)\n throwError(`Invalid settings for onSuccessSend in SmtpEmailHook`)\n }\n}"]}
1
+ {"version":3,"file":"smtpEmailRegistry.js","sourceRoot":"","sources":["../../../src/features/smtp_email/smtpEmailRegistry.ts"],"names":[],"mappings":";;;;;;AACA,mCAAoC;AACpC,gDAAuB;AACvB,qEAAqE;AAErE,oCAAoC;AACvB,QAAA,aAAa,GAA0B;IAChD,OAAO,EAAE,KAAK,IAAsC,EAAE;QAElD,UAAU;QACV,kDAAkD;QAClD,4DAA4D;QAE5D,OAAO;YACH,QAAQ,EAAE,EAAE;YACZ,QAAQ,EAAE,EAAE;YACZ,UAAU,EAAE,IAAI;YAChB,cAAc,EAAE;gBACZ,QAAQ,EAAE,EAAE;gBACZ,QAAQ,EAAE,EAAE;aACf;YACD,iBAAiB,EAAE,GAAG;YACtB,UAAU,EAAE;gBACR,OAAO,EAAE,MAAM;gBACf,QAAQ,EAAE,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC;gBAC3C,UAAU,EAAE;oBACR,UAAU,EAAE,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC;oBAC7C,WAAW,EAAE,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC;oBAC9C,OAAO,EAAE,MAAM;oBACf,aAAa,EAAE,KAAK;iBACvB;aACJ;SACJ,CAAA;IAEL,CAAC;IACD,WAAW,EAAE,KAAK,EAAE,KAAqC,EAAE,EAAE;QACzD,6BAA6B;QAC7B,uFAAuF;QACvF,IAAA,kBAAU,EAAC,mDAAmD,CAAC,CAAA;IACnE,CAAC;IACD,aAAa,EAAE,KAAK,EAAE,KAAuC,EAAE,EAAE;QAC7D,wBAAwB;QACxB,oFAAoF;QACpF,IAAA,kBAAU,EAAC,qDAAqD,CAAC,CAAA;IACrE,CAAC;CACJ,CAAA","sourcesContent":["import { FeatureSmtpEmailProps, FeatureSmtpEmailOptions, FeatureSmtpEmailSuccessSendProps, FeatureSmtpEmailStartSendProps } from '@/features'\nimport { throwError } from '@/utils'\nimport path from 'path'\n// import { OneTimeCodeType, ResetPasswordMethod } from \"@/services\";\n\n// Runtime storage for injected hook\nexport const SmtpEmailHook: FeatureSmtpEmailProps = {\n onSetup: async (): Promise<FeatureSmtpEmailOptions> => {\n\n // default\n // const oneTimeCodeType: OneTimeCodeType = \"otp\";\n // const resetPasswordMethod: ResetPasswordMethod = \"email\";\n\n return {\n smtpHost: \"\",\n smtpPort: 25,\n smtpSecure: true,\n smtpCredential: {\n username: \"\",\n password: \"\"\n },\n connectionTimeout: 500,\n hbsOptions: {\n extName: \".hbs\",\n viewPath: path.join(__dirname, \"templates\"),\n viewEngine: {\n layoutsDir: path.join(__dirname, \"templates\"),\n partialsDir: path.join(__dirname, \"templates\"),\n extname: \".hbs\",\n defaultLayout: false\n },\n }\n }\n\n },\n onStartSend: async (props: FeatureSmtpEmailStartSendProps) => {\n // Default behavior: just log\n // console.log(`[ResetPasswordService] Default onRequest called for ${JSON.stringify}`)\n throwError(`Invalid settings for onStartSend in SmtpEmailHook`)\n },\n onSuccessSend: async (props: FeatureSmtpEmailSuccessSendProps) => {\n // Default behavior: log\n // console.log(`[ResetPasswordService] Default onSuccess called for user ${userId}`)\n throwError(`Invalid settings for onSuccessSend in SmtpEmailHook`)\n }\n}"]}
@@ -1,4 +1,14 @@
1
1
  import { SmtpEmailTransporterOptions } from "../../services";
2
+ export type FeatureSmtpEmailHbsOptions = {
3
+ viewPath: string;
4
+ extName: ".hbs";
5
+ viewEngine: {
6
+ extname: ".hbs";
7
+ layoutsDir: string;
8
+ partialsDir: string;
9
+ defaultLayout: string | false;
10
+ };
11
+ };
2
12
  export type FeatureSmtpEmailOptions = {
3
13
  smtpHost: string;
4
14
  smtpPort: number;
@@ -8,6 +18,7 @@ export type FeatureSmtpEmailOptions = {
8
18
  password: string;
9
19
  };
10
20
  connectionTimeout: number;
21
+ hbsOptions: FeatureSmtpEmailHbsOptions;
11
22
  };
12
23
  export type FeatureSmtpEmailStartSendProps = {
13
24
  smtpEmailOptions: FeatureSmtpEmailOptions;
@@ -16,6 +27,7 @@ export type FeatureSmtpEmailStartSendProps = {
16
27
  export type FeatureSmtpEmailSuccessSendProps = {
17
28
  smtpEmailOptions: FeatureSmtpEmailOptions;
18
29
  transporterOptions: SmtpEmailTransporterOptions;
30
+ previewMessageUrl: string | false;
19
31
  gatewayDetails: any;
20
32
  };
21
33
  export type FeatureSmtpEmailProps = {
@@ -1 +1 @@
1
- {"version":3,"file":"smtpEmailType.js","sourceRoot":"","sources":["../../../src/features/smtp_email/smtpEmailType.ts"],"names":[],"mappings":"","sourcesContent":["import { SmtpEmailTransporterOptions } from \"@/services\";\n\nexport type FeatureSmtpEmailOptions = {\n smtpHost: string\n smtpPort: number\n smtpSecure: boolean\n smtpCredential: {\n username: string\n password: string\n },\n connectionTimeout: number\n}\n\nexport type FeatureSmtpEmailStartSendProps = {\n smtpEmailOptions: FeatureSmtpEmailOptions\n transporterOptions: SmtpEmailTransporterOptions\n}\n\nexport type FeatureSmtpEmailSuccessSendProps = {\n smtpEmailOptions: FeatureSmtpEmailOptions\n transporterOptions: SmtpEmailTransporterOptions\n gatewayDetails: any\n}\n\nexport type FeatureSmtpEmailProps = {\n onSetup: () => Promise<FeatureSmtpEmailOptions>,\n onStartSend: (payload: FeatureSmtpEmailStartSendProps) => Promise<any>\n onSuccessSend: (payload: FeatureSmtpEmailSuccessSendProps) => Promise<any>\n}"]}
1
+ {"version":3,"file":"smtpEmailType.js","sourceRoot":"","sources":["../../../src/features/smtp_email/smtpEmailType.ts"],"names":[],"mappings":"","sourcesContent":["import { SmtpEmailTransporterOptions } from \"@/services\";\n\nexport type FeatureSmtpEmailHbsOptions = {\n viewPath: string // path to templates folder\n extName: \".hbs\" // extension for templates, e.g., \".hbs\"\n viewEngine: {\n extname: \".hbs\", // file extension of templates\n layoutsDir: string // folder for layout files\n partialsDir: string // folder for partial templates\n defaultLayout: string | false // default layout name or false\n // helpers?: Record<string, (...args: any[]) => any>\n }\n}\n\nexport type FeatureSmtpEmailOptions = {\n smtpHost: string\n smtpPort: number\n smtpSecure: boolean\n smtpCredential: {\n username: string\n password: string\n },\n connectionTimeout: number\n hbsOptions: FeatureSmtpEmailHbsOptions\n}\n\nexport type FeatureSmtpEmailStartSendProps = {\n smtpEmailOptions: FeatureSmtpEmailOptions\n transporterOptions: SmtpEmailTransporterOptions\n}\n\nexport type FeatureSmtpEmailSuccessSendProps = {\n smtpEmailOptions: FeatureSmtpEmailOptions\n transporterOptions: SmtpEmailTransporterOptions\n previewMessageUrl: string | false\n gatewayDetails: any\n}\n\nexport type FeatureSmtpEmailProps = {\n onSetup: () => Promise<FeatureSmtpEmailOptions>,\n onStartSend: (payload: FeatureSmtpEmailStartSendProps) => Promise<any>\n onSuccessSend: (payload: FeatureSmtpEmailSuccessSendProps) => Promise<any>\n}"]}
@@ -1,19 +1,17 @@
1
1
  import { DefaultServiceProps } from "../../utils";
2
+ import { SendMailOptions } from "nodemailer";
2
3
  export type SmtpEmailServiceProps = DefaultServiceProps & {};
3
- export type SmtpEmailTransporterOptions = {
4
- to: string | string[];
5
- from?: string;
6
- subject: string;
7
- text?: string;
8
- html?: string;
9
- cc?: string | string[];
10
- bcc?: string | string[];
4
+ export type SmtpEmailTransporterOptions = SendMailOptions & {
5
+ template?: string;
6
+ context?: Record<string, any>;
11
7
  };
12
8
  export type SmtpEmailSendProps = {
13
9
  transporterOptions: SmtpEmailTransporterOptions;
10
+ overrideTemplate?: string;
11
+ overrideContext?: Record<string, any>;
14
12
  };
15
13
  export declare const SmtpEmailService: (props: SmtpEmailServiceProps) => {
16
- sendEmail: ({ transporterOptions }: SmtpEmailSendProps) => Promise<{}>;
14
+ sendEmail: ({ transporterOptions, overrideTemplate, overrideContext }: SmtpEmailSendProps) => Promise<{}>;
17
15
  validateSmtpEmailOptions: () => Promise<{
18
16
  status: boolean;
19
17
  message: string;
@@ -8,15 +8,73 @@ exports.SmtpEmailService = void 0;
8
8
  // import { buildSqlRelation, buildSqlRawSelect, buildSqlWhere, buildSqlSelect, buildSqlLimitOffset, buildSqlOrderBy } from "../../lib";
9
9
  const features_1 = require("../../features");
10
10
  const nodemailer_1 = __importDefault(require("nodemailer"));
11
+ const nodemailer_express_handlebars_1 = __importDefault(require("nodemailer-express-handlebars"));
11
12
  const SmtpEmailService = (props) => {
12
13
  const { ...rest } = props;
13
14
  // Lazy init storage
14
15
  let nodeMailerTransporter = null;
15
16
  let hookSetup = null;
17
+ let hbsRegistered = false;
18
+ const validateHookSetup = (hookSetup) => {
19
+ if (!hookSetup) {
20
+ throw new Error("SmtpEmailHook.onSetup() returned null or undefined");
21
+ }
22
+ const { smtpHost, smtpPort, smtpSecure, smtpCredential, connectionTimeout, hbsOptions } = hookSetup;
23
+ if (!smtpHost || typeof smtpHost !== "string") {
24
+ throw new Error("smtpHost is required and must be a string");
25
+ }
26
+ if (!smtpPort || typeof smtpPort !== "number") {
27
+ throw new Error("smtpPort is required and must be a number");
28
+ }
29
+ if (typeof smtpSecure !== "boolean") {
30
+ throw new Error("smtpSecure is required and must be boolean");
31
+ }
32
+ if (!smtpCredential || !smtpCredential.username || !smtpCredential.password) {
33
+ throw new Error("smtpCredential with username and password is required");
34
+ }
35
+ if (!connectionTimeout || typeof connectionTimeout !== "number") {
36
+ throw new Error("connectionTimeout is required and must be a number");
37
+ }
38
+ if (!hbsOptions || typeof hbsOptions !== "object") {
39
+ throw new Error("hbsOptions is required and must be an object");
40
+ }
41
+ return true;
42
+ };
43
+ function validateHbsOptions(hbsOptions) {
44
+ if (!hbsOptions)
45
+ throw new Error("HBS options are required");
46
+ const { viewEngine, viewPath, extName } = hbsOptions;
47
+ if (!viewEngine || typeof viewEngine !== "object") {
48
+ throw new Error("hbsOptions.viewEngine is required");
49
+ }
50
+ if (!viewEngine.extname || typeof viewEngine.extname !== "string") {
51
+ throw new Error("hbsOptions.viewEngine.extname is required and must be a string");
52
+ }
53
+ if (!viewEngine.layoutsDir || typeof viewEngine.layoutsDir !== "string") {
54
+ throw new Error("hbsOptions.viewEngine.layoutsDir is required and must be a string");
55
+ }
56
+ if (viewEngine.defaultLayout !== undefined &&
57
+ viewEngine.defaultLayout !== false &&
58
+ typeof viewEngine.defaultLayout !== "string") {
59
+ throw new Error("hbsOptions.viewEngine.defaultLayout must be string or false");
60
+ }
61
+ if (!viewPath || typeof viewPath !== "string") {
62
+ throw new Error("hbsOptions.viewPath is required and must be a string");
63
+ }
64
+ if (!extName || typeof extName !== "string") {
65
+ throw new Error("hbsOptions.extName is required and must be a string");
66
+ }
67
+ }
16
68
  // Lazy getTransporter function
17
69
  const getTransporter = async () => {
18
70
  if (!nodeMailerTransporter) {
19
71
  hookSetup = await features_1.SmtpEmailHook.onSetup();
72
+ // validate the setup configurations
73
+ validateHookSetup(hookSetup); // validate smtp
74
+ validateHbsOptions(hookSetup?.hbsOptions); // validate hbs options
75
+ // if (!hookSetup) {
76
+ // throw new Error("SmtpEmailHook.onSetup() must return FeatureSmtpEmailOptions");
77
+ // }
20
78
  nodeMailerTransporter = nodemailer_1.default.createTransport({
21
79
  host: hookSetup.smtpHost,
22
80
  port: Number(hookSetup.smtpPort),
@@ -27,10 +85,14 @@ const SmtpEmailService = (props) => {
27
85
  },
28
86
  connectionTimeout: hookSetup.connectionTimeout,
29
87
  });
88
+ if (hookSetup?.hbsOptions && !hbsRegistered) {
89
+ nodeMailerTransporter.use("compile", (0, nodemailer_express_handlebars_1.default)(hookSetup.hbsOptions));
90
+ hbsRegistered = true;
91
+ }
30
92
  }
31
93
  return nodeMailerTransporter;
32
94
  };
33
- const sendEmail = async ({ transporterOptions }) => {
95
+ const sendEmail = async ({ transporterOptions, overrideTemplate = '', overrideContext = {} }) => {
34
96
  // get the onSetup from hook
35
97
  const transporter = await getTransporter(); // only initializes once
36
98
  let response = {};
@@ -42,12 +104,19 @@ const SmtpEmailService = (props) => {
42
104
  smtpEmailOptions: hookSetup
43
105
  });
44
106
  }
45
- const info = await transporter.sendMail(transporterOptions);
107
+ const info = await transporter.sendMail({
108
+ ...transporterOptions,
109
+ ...(overrideTemplate ? { template: overrideTemplate } : {}),
110
+ ...(overrideContext ? { context: overrideContext } : {})
111
+ });
112
+ // If using a test account
113
+ let previewMessageUrl = nodemailer_1.default.getTestMessageUrl(info);
46
114
  response = {
47
115
  ...response,
48
116
  success: true,
49
117
  messageId: info.messageId,
50
118
  accepted: info.accepted,
119
+ previewMessageUrl,
51
120
  gatewayDetails: info
52
121
  };
53
122
  // Call the consumer hook, if registered
@@ -55,6 +124,7 @@ const SmtpEmailService = (props) => {
55
124
  const responseCustomHook = await features_1.SmtpEmailHook.onSuccessSend({
56
125
  transporterOptions,
57
126
  smtpEmailOptions: hookSetup,
127
+ previewMessageUrl, // only if the test account smtp
58
128
  gatewayDetails: info
59
129
  });
60
130
  response = { ...response, custom: responseCustomHook };
@@ -1 +1 @@
1
- {"version":3,"file":"SmtpEmailService.js","sourceRoot":"","sources":["../../../src/services/gateway/SmtpEmailService.ts"],"names":[],"mappings":";;;;;;AAEA,yDAAyD;AAEzD,oIAAoI;AAEpI,yCAAmE;AAEnE,4DAAoD;AAmB7C,MAAM,gBAAgB,GAAG,CAAC,KAA4B,EAAE,EAAE;IAE7D,MAAM,EACF,GAAG,IAAI,EACV,GAAG,KAAK,CAAA;IAET,oBAAoB;IACpB,IAAI,qBAAqB,GAAuB,IAAI,CAAA;IACpD,IAAI,SAAS,GAAmC,IAAI,CAAA;IAEpD,+BAA+B;IAC/B,MAAM,cAAc,GAAG,KAAK,IAAI,EAAE;QAC9B,IAAI,CAAC,qBAAqB,EAAE,CAAC;YACzB,SA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BACzD,kBAAkB;oBAClB,gBAAgB,EAAE,SAAU;oBAC5B,cAAc,EAAE,IAAI;iBACvB,CAAC,CAAA;gBAEF,QAAQ,GAAG,EAAE,GAAG,QAAQ,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAA;YAE1D,CAAC;QAEL,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YAElB,QAAQ,GAAG;gBACP,GAAG,QAAQ;gBACX,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,KAAK,CAAC,IAAI,IAAI,eAAe;gBACpC,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,cAAc,EAAE,KAAK;aACxB,CAAA;QACL,CAAC;QAED,OAAO,QAAQ,CAAA;IACnB,CAAC,CAAA;IAED,MAAM,wBAAwB,GAAG,KAAK,IAAI,EAAE;QAExC,MAAM,WAAW,GAAG,MAAM,cAAc,EAAE,CAAA,CAAE,wBAAwB;QAEpE,IAAI,cAAc,GAAY,KAAK,CAAA;QACnC,IAAI,eAAe,GAAW,EAAE,CAAA;QAEhC,IAAI,CAAC;YACD,MAAM,WAAW,CAAC,MAAM,EAAE,CAAC;YAC3B,cAAc,GAAG,IAAI,CAAA;YACrB,eAAe,GAAG,0BAA0B,CAAA;QAEhD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,0DAA0D;YAC1D,cAAc,GAAG,IAAI,CAAA;YACrB,eAAe,GAAG,kCAAkC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAA;QAC/E,CAAC;QAED,OAAO;YACH,MAAM,EAAE,cAAc;YACtB,OAAO,EAAE,eAAe;SAC3B,CAAA;IAEL,CAAC,CAAC;IAEF,OAAO;QACH,SAAS;QACT,wBAAwB;KAC3B,CAAA;AAEL,CAAC,CAAA;AAhHY,QAAA,gBAAgB,oBAgH5B","sourcesContent":["import { DefaultServiceProps, throwError } from \"@/utils\";\n\n// import { QueryList, QueryGet } from \"@/schema/common\";\n\n// import { buildSqlRelation, buildSqlRawSelect, buildSqlWhere, buildSqlSelect, buildSqlLimitOffset, buildSqlOrderBy } from \"@/lib\";\n\nimport { SmtpEmailHook, FeatureSmtpEmailOptions } from \"@/features\"\n\nimport nodemailer, { Transporter } from \"nodemailer\"\n\nexport type SmtpEmailServiceProps = DefaultServiceProps & {\n};\n\nexport type SmtpEmailTransporterOptions = {\n to: string | string[];\n from?: string;\n subject: string;\n text?: string;\n html?: string;\n cc?: string | string[];\n bcc?: string | string[];\n}\n\nexport type SmtpEmailSendProps = {\n transporterOptions: SmtpEmailTransporterOptions\n}\n\nexport const SmtpEmailService = (props: SmtpEmailServiceProps) => {\n\n const {\n ...rest\n } = props\n\n // Lazy init storage\n let nodeMailerTransporter: Transporter | null = null\n let hookSetup: FeatureSmtpEmailOptions | null = null\n\n // Lazy getTransporter function\n const getTransporter = async () => {\n if (!nodeMailerTransporter) {\n hookSetup = await SmtpEmailHook.onSetup()\n nodeMailerTransporter = nodemailer.createTransport({\n host: hookSetup.smtpHost,\n port: Number(hookSetup.smtpPort),\n secure: Boolean(hookSetup.smtpSecure),\n auth: {\n user: hookSetup.smtpCredential.username,\n pass: hookSetup.smtpCredential.password\n },\n connectionTimeout: hookSetup.connectionTimeout,\n })\n }\n return nodeMailerTransporter\n }\n\n const sendEmail = async ({ transporterOptions }: SmtpEmailSendProps) => {\n\n // get the onSetup from hook\n const transporter = await getTransporter() // only initializes once\n\n let response = {}\n\n try {\n\n // Call the consumer hook, if registered\n if (SmtpEmailHook.onStartSend) {\n await SmtpEmailHook.onStartSend({\n transporterOptions,\n smtpEmailOptions: hookSetup!\n })\n }\n\n const info = await transporter.sendMail(transporterOptions);\n\n response = {\n ...response,\n success: true,\n messageId: info.messageId,\n accepted: info.accepted,\n gatewayDetails: info\n }\n\n // Call the consumer hook, if registered\n if (SmtpEmailHook.onSuccessSend) {\n\n const responseCustomHook = await SmtpEmailHook.onSuccessSend({\n transporterOptions,\n smtpEmailOptions: hookSetup!,\n gatewayDetails: info\n })\n\n response = { ...response, custom: responseCustomHook }\n\n }\n\n } catch (error: any) {\n\n response = {\n ...response,\n success: false,\n error: error.code || \"UNKNOWN_ERROR\",\n message: error.message,\n gatewayDetails: error\n }\n }\n\n return response\n }\n\n const validateSmtpEmailOptions = async () => {\n\n const transporter = await getTransporter() // only initializes once\n\n let responseStatus: boolean = false\n let responseMessage: string = ``\n\n try {\n await transporter.verify();\n responseStatus = true\n responseMessage = `Valid smtp email options`\n\n } catch (error) {\n // console.error(\"SMTP Connection verify failed:\", error);\n responseStatus = true\n responseMessage = `Smtp connection verify failed: ${JSON.stringify(error)}`\n }\n\n return {\n status: responseStatus,\n message: responseMessage\n }\n\n };\n\n return {\n sendEmail,\n validateSmtpEmailOptions\n }\n\n}\n\n"]}
1
+ {"version":3,"file":"SmtpEmailService.js","sourceRoot":"","sources":["../../../src/services/gateway/SmtpEmailService.ts"],"names":[],"mappings":";;;;;;AAEA,yDAAyD;AAEzD,oIAAoI;AAEpI,yCAA+F;AAE/F,4DAAqE;AACrE,kGAAgD;AA6BzC,MAAM,gBAAgB,GAAG,CAAC,KAA4B,EAAE,EAAE;IAE7D,MAAM,EACF,GAAG,IAAI,EACV,GAAG,KAAK,CAAA;IAET,oBAAoB;IACpB,IAAI,qBAAqB,GAAuB,IAAI,CAAA;IACpD,IAAI,SAAS,GAAmC,IAAI,CAAA;IACpD,IAAI,aAAa,GAAY,KAAK,CAAA;IAElC,MAAM,iBAAiB,GAAG,CAAC,SAAyC,EAAE,EAAE;QAEpE,IAAI,CAAC,SAAS,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;QAC1E,CAAC;QAED,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAE,iBAAiB,EAAE,UAAU,EAAE,GAAG,SAAS,CAAC;QAEpG,IAAI,CAAC,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAC5C,MAAM,IAAI,KAAK,CAAC,2CAA2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AAE,cAAc;YACtB,OAAO,EAAE,eAAe;SAC3B,CAAA;IAEL,CAAC,CAAC;IAEF,OAAO;QACH,SAAS;QACT,wBAAwB;KAC3B,CAAA;AAEL,CAAC,CAAA;AArNY,QAAA,gBAAgB,oBAqN5B","sourcesContent":["import { DefaultServiceProps, throwError } from \"@/utils\";\n\n// import { QueryList, QueryGet } from \"@/schema/common\";\n\n// import { buildSqlRelation, buildSqlRawSelect, buildSqlWhere, buildSqlSelect, buildSqlLimitOffset, buildSqlOrderBy } from \"@/lib\";\n\nimport { SmtpEmailHook, FeatureSmtpEmailOptions, FeatureSmtpEmailHbsOptions } from \"@/features\"\n\nimport nodemailer, { Transporter, SendMailOptions } from \"nodemailer\"\nimport hbs from \"nodemailer-express-handlebars\";\n\nexport type SmtpEmailServiceProps = DefaultServiceProps & {\n};\n\nexport type SmtpEmailTransporterOptions = SendMailOptions & {\n template?: string;\n context?: Record<string, any>;\n};\n\n// export type SmtpEmailTransporterOptions = {\n// to: string | string[];\n// from?: string;\n// subject: string;\n// text?: string;\n// html?: string;\n// cc?: string | string[];\n// bcc?: string | string[];\n// }\n\nexport type SmtpEmailSendProps = {\n transporterOptions: SmtpEmailTransporterOptions\n overrideTemplate?: string\n overrideContext?: Record<string, any>\n // hbsOptions: FeatureSmtpEmailHbsOptions\n // hbsTemplate?: string\n // hbsContext?: Record<string, any>\n}\n\nexport const SmtpEmailService = (props: SmtpEmailServiceProps) => {\n\n const {\n ...rest\n } = props\n\n // Lazy init storage\n let nodeMailerTransporter: Transporter | null = null\n let hookSetup: FeatureSmtpEmailOptions | null = null\n let hbsRegistered: boolean = false\n\n const validateHookSetup = (hookSetup: FeatureSmtpEmailOptions | null) => {\n\n if (!hookSetup) {\n throw new Error(\"SmtpEmailHook.onSetup() returned null or undefined\");\n }\n\n const { smtpHost, smtpPort, smtpSecure, smtpCredential, connectionTimeout, hbsOptions } = hookSetup;\n\n if (!smtpHost || typeof smtpHost !== \"string\") {\n throw new Error(\"smtpHost is required and must be a string\");\n }\n\n if (!smtpPort || typeof smtpPort !== \"number\") {\n throw new Error(\"smtpPort is required and must be a number\");\n }\n\n if (typeof smtpSecure !== \"boolean\") {\n throw new Error(\"smtpSecure is required and must be boolean\");\n }\n\n if (!smtpCredential || !smtpCredential.username || !smtpCredential.password) {\n throw new Error(\"smtpCredential with username and password is required\");\n }\n\n if (!connectionTimeout || typeof connectionTimeout !== \"number\") {\n throw new Error(\"connectionTimeout is required and must be a number\");\n }\n\n if (!hbsOptions || typeof hbsOptions !== \"object\") {\n throw new Error(\"hbsOptions is required and must be an object\");\n }\n\n return true;\n };\n\n function validateHbsOptions(hbsOptions: FeatureSmtpEmailHbsOptions) {\n\n if (!hbsOptions) throw new Error(\"HBS options are required\");\n\n const { viewEngine, viewPath, extName } = hbsOptions;\n\n if (!viewEngine || typeof viewEngine !== \"object\") {\n throw new Error(\"hbsOptions.viewEngine is required\");\n }\n\n if (!viewEngine.extname || typeof viewEngine.extname !== \"string\") {\n throw new Error(\"hbsOptions.viewEngine.extname is required and must be a string\");\n }\n\n if (!viewEngine.layoutsDir || typeof viewEngine.layoutsDir !== \"string\") {\n throw new Error(\"hbsOptions.viewEngine.layoutsDir is required and must be a string\");\n }\n\n if (viewEngine.defaultLayout !== undefined &&\n viewEngine.defaultLayout !== false &&\n typeof viewEngine.defaultLayout !== \"string\") {\n throw new Error(\"hbsOptions.viewEngine.defaultLayout must be string or false\");\n }\n\n if (!viewPath || typeof viewPath !== \"string\") {\n throw new Error(\"hbsOptions.viewPath is required and must be a string\");\n }\n\n if (!extName || typeof extName !== \"string\") {\n throw new Error(\"hbsOptions.extName is required and must be a string\");\n }\n }\n\n // Lazy getTransporter function\n const getTransporter = async () => {\n\n if (!nodeMailerTransporter) {\n\n hookSetup = await SmtpEmailHook.onSetup()\n\n // validate the setup configurations\n validateHookSetup(hookSetup); // validate smtp\n validateHbsOptions(hookSetup?.hbsOptions) // validate hbs options\n\n // if (!hookSetup) {\n // throw new Error(\"SmtpEmailHook.onSetup() must return FeatureSmtpEmailOptions\");\n // }\n\n nodeMailerTransporter = nodemailer.createTransport({\n host: hookSetup.smtpHost,\n port: Number(hookSetup.smtpPort),\n secure: Boolean(hookSetup.smtpSecure),\n auth: {\n user: hookSetup.smtpCredential.username,\n pass: hookSetup.smtpCredential.password\n },\n connectionTimeout: hookSetup.connectionTimeout,\n })\n\n if (hookSetup?.hbsOptions && !hbsRegistered) {\n nodeMailerTransporter.use(\"compile\", hbs(hookSetup.hbsOptions));\n hbsRegistered = true\n }\n\n }\n\n return nodeMailerTransporter\n\n }\n\n const sendEmail = async ({\n transporterOptions,\n overrideTemplate = '',\n overrideContext = {}\n }: SmtpEmailSendProps) => {\n\n // get the onSetup from hook\n const transporter = await getTransporter() // only initializes once\n\n let response = {}\n\n try {\n\n // Call the consumer hook, if registered\n if (SmtpEmailHook.onStartSend) {\n await SmtpEmailHook.onStartSend({\n transporterOptions,\n smtpEmailOptions: hookSetup!\n })\n }\n\n const info = await transporter.sendMail({\n ...transporterOptions,\n ...(overrideTemplate ? { template: overrideTemplate } : {}),\n ...(overrideContext ? { context: overrideContext } : {})\n });\n\n // If using a test account\n let previewMessageUrl = nodemailer.getTestMessageUrl(info);\n\n response = {\n ...response,\n success: true,\n messageId: info.messageId,\n accepted: info.accepted,\n previewMessageUrl,\n gatewayDetails: info\n }\n\n // Call the consumer hook, if registered\n if (SmtpEmailHook.onSuccessSend) {\n\n const responseCustomHook = await SmtpEmailHook.onSuccessSend({\n transporterOptions,\n smtpEmailOptions: hookSetup!,\n previewMessageUrl, // only if the test account smtp\n gatewayDetails: info\n })\n\n response = { ...response, custom: responseCustomHook }\n\n }\n\n } catch (error: any) {\n\n response = {\n ...response,\n success: false,\n error: error.code || \"UNKNOWN_ERROR\",\n message: error.message,\n gatewayDetails: error\n }\n }\n\n return response\n }\n\n const validateSmtpEmailOptions = async () => {\n\n const transporter = await getTransporter() // only initializes once\n\n let responseStatus: boolean = false\n let responseMessage: string = ``\n\n try {\n await transporter.verify();\n responseStatus = true\n responseMessage = `Valid smtp email options`\n\n } catch (error) {\n // console.error(\"SMTP Connection verify failed:\", error);\n responseStatus = true\n responseMessage = `Smtp connection verify failed: ${JSON.stringify(error)}`\n }\n\n return {\n status: responseStatus,\n message: responseMessage\n }\n\n };\n\n return {\n sendEmail,\n validateSmtpEmailOptions\n }\n\n}\n\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storemw-core-api",
3
- "version": "1.0.92",
3
+ "version": "1.0.93",
4
4
  "description": "STOREMW Core API",
5
5
  "main": "dist/app.js",
6
6
  "types": "dist/app.d.ts",
@@ -109,6 +109,7 @@
109
109
  "jsonwebtoken": "^9.0.2",
110
110
  "lodash": "^4.17.21",
111
111
  "multer": "^2.0.2",
112
+ "nodemailer-express-handlebars": "^7.0.0",
112
113
  "path-to-regexp": "^8.3.0",
113
114
  "pg": "^8.14.1",
114
115
  "pino": "^9.6.0",
@@ -137,6 +138,7 @@
137
138
  "@types/multer": "^2.0.0",
138
139
  "@types/node": "^22.17.2",
139
140
  "@types/nodemailer": "^7.0.9",
141
+ "@types/nodemailer-express-handlebars": "^4.0.6",
140
142
  "@types/pino": "^7.0.4",
141
143
  "@types/tmp": "^0.2.6",
142
144
  "nodemailer": "^6.9.4",