my-typescript-library-rahul52us 1.4.2 → 1.4.4

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.
@@ -16,11 +16,20 @@ const handlebars_1 = __importDefault(require("handlebars"));
16
16
  const mjml_1 = __importDefault(require("mjml"));
17
17
  const fs_1 = __importDefault(require("fs"));
18
18
  const path_1 = __importDefault(require("path"));
19
+ // Ensure __dirname works (CommonJS)
20
+ const templatesDir = path_1.default.join(__dirname, '../email-templates');
19
21
  function compileEmailTemplate({ fileName, data }) {
20
22
  return __awaiter(this, void 0, void 0, function* () {
21
- const mjMail = yield fs_1.default.promises.readFile(path_1.default.join('src/email-templates', fileName), 'utf8');
22
- const template = handlebars_1.default.compile(mjMail)(data);
23
- return (0, mjml_1.default)(template).html.toString();
23
+ try {
24
+ const templatePath = path_1.default.join(templatesDir, fileName);
25
+ const mjMail = yield fs_1.default.promises.readFile(templatePath, 'utf8');
26
+ const template = handlebars_1.default.compile(mjMail)(data);
27
+ return (0, mjml_1.default)(template).html.toString();
28
+ }
29
+ catch (error) {
30
+ console.error(`Error reading template: ${error.message}`);
31
+ throw new Error(`Template file "${fileName}" not found in ${templatesDir}`);
32
+ }
24
33
  });
25
34
  }
26
35
  exports.default = compileEmailTemplate;
@@ -1 +1 @@
1
- {"version":3,"file":"compile-email-template.js","sourceRoot":"","sources":["../../src/helpers/compile-email-template.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,4DAAoC;AACpC,gDAA6B;AAC7B,4CAAoB;AACpB,gDAAwB;AAoBxB,SAA8B,oBAAoB,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAS;;QAC1E,MAAM,MAAM,GAAG,MAAM,YAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,cAAI,CAAC,IAAI,CAAC,qBAAqB,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;QAC9F,MAAM,QAAQ,GAAG,oBAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC;QAClD,OAAO,IAAA,cAAS,EAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC7C,CAAC;CAAA;AAJD,uCAIC"}
1
+ {"version":3,"file":"compile-email-template.js","sourceRoot":"","sources":["../../src/helpers/compile-email-template.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,4DAAoC;AACpC,gDAA6B;AAC7B,4CAAoB;AACpB,gDAAwB;AAExB,oCAAoC;AACpC,MAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;AAoBhE,SAA8B,oBAAoB,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAS;;QAC1E,IAAI;YACF,MAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;YACvD,MAAM,MAAM,GAAG,MAAM,YAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;YAChE,MAAM,QAAQ,GAAG,oBAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC;YAClD,OAAO,IAAA,cAAS,EAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;SAC5C;QAAC,OAAO,KAAU,EAAE;YACnB,OAAO,CAAC,KAAK,CAAC,2BAA2B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YAC1D,MAAM,IAAI,KAAK,CAAC,kBAAkB,QAAQ,kBAAkB,YAAY,EAAE,CAAC,CAAC;SAC7E;IACH,CAAC;CAAA;AAVD,uCAUC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "my-typescript-library-rahul52us",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "description": "A reusable TypeScript utility library.",
5
5
  "main": "dist/server.js",
6
6
  "types": "dist/types/server.d.ts",
@@ -3,6 +3,9 @@ import mjml2html from 'mjml';
3
3
  import fs from 'fs';
4
4
  import path from 'path';
5
5
 
6
+ // Ensure __dirname works (CommonJS)
7
+ const templatesDir = path.join(__dirname, '../email-templates');
8
+
6
9
  type Props = {
7
10
  fileName: string;
8
11
  data: {
@@ -11,18 +14,24 @@ type Props = {
11
14
  url?: string;
12
15
  teamName?: string;
13
16
  link?: string;
14
- workflow_name?:string;
15
- password?:string;
16
- username?:string;
17
- level?:string;
18
- role?:string;
19
- designation?:string;
20
- verifyTokenUrl?:string
21
- }
17
+ workflow_name?: string;
18
+ password?: string;
19
+ username?: string;
20
+ level?: string;
21
+ role?: string;
22
+ designation?: string;
23
+ verifyTokenUrl?: string;
24
+ };
22
25
  };
23
26
 
24
27
  export default async function compileEmailTemplate({ fileName, data }: Props): Promise<string> {
25
- const mjMail = await fs.promises.readFile(path.join('src/email-templates', fileName), 'utf8');
26
- const template = handlebars.compile(mjMail)(data);
27
- return mjml2html(template).html.toString();
28
+ try {
29
+ const templatePath = path.join(templatesDir, fileName);
30
+ const mjMail = await fs.promises.readFile(templatePath, 'utf8');
31
+ const template = handlebars.compile(mjMail)(data);
32
+ return mjml2html(template).html.toString();
33
+ } catch (error: any) {
34
+ console.error(`Error reading template: ${error.message}`);
35
+ throw new Error(`Template file "${fileName}" not found in ${templatesDir}`);
36
+ }
28
37
  }