elseware-nodejs 1.7.0 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1895,7 +1895,9 @@ declare class EmailService {
1895
1895
  }
1896
1896
 
1897
1897
  declare class TemplateEngine {
1898
- static cache: Record<string, HandlebarsTemplateDelegate>;
1898
+ static templateCache: Record<string, HandlebarsTemplateDelegate>;
1899
+ static cssCache: Record<string, string>;
1900
+ static loadAllCSS(stylesDir: string): string;
1899
1901
  static render(templateName: string, data: any, templateDir: string): string;
1900
1902
  }
1901
1903
 
package/dist/index.d.ts CHANGED
@@ -1895,7 +1895,9 @@ declare class EmailService {
1895
1895
  }
1896
1896
 
1897
1897
  declare class TemplateEngine {
1898
- static cache: Record<string, HandlebarsTemplateDelegate>;
1898
+ static templateCache: Record<string, HandlebarsTemplateDelegate>;
1899
+ static cssCache: Record<string, string>;
1900
+ static loadAllCSS(stylesDir: string): string;
1899
1901
  static render(templateName: string, data: any, templateDir: string): string;
1900
1902
  }
1901
1903
 
package/dist/index.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import mongoose from 'mongoose';
2
2
  import dotenv from 'dotenv';
3
3
  import { BlobServiceClient, StorageSharedKeyCredential, generateBlobSASQueryParameters, BlobSASPermissions } from '@azure/storage-blob';
4
- import fs from 'fs';
4
+ import fs3 from 'fs';
5
5
  import cloudinaryModule from 'cloudinary';
6
6
  import nodemailer from 'nodemailer';
7
7
  import path from 'path';
8
8
  import Handlebars from 'handlebars';
9
+ import juice from 'juice';
9
10
  import jwt from 'jsonwebtoken';
10
11
  import multer from 'multer';
11
12
 
@@ -5155,8 +5156,8 @@ var AzureBlobStorageService = class {
5155
5156
  // Upload file
5156
5157
  async uploadFile(localPath, blobName, onProgress) {
5157
5158
  const blockBlobClient = this.containerClient.getBlockBlobClient(blobName);
5158
- const fileSize = fs.statSync(localPath).size;
5159
- const readStream = fs.createReadStream(localPath);
5159
+ const fileSize = fs3.statSync(localPath).size;
5160
+ const readStream = fs3.createReadStream(localPath);
5160
5161
  await blockBlobClient.uploadStream(
5161
5162
  readStream,
5162
5163
  4 * 1024 * 1024,
@@ -5181,7 +5182,7 @@ var AzureBlobStorageService = class {
5181
5182
  const fileSize = response.contentLength || 0;
5182
5183
  let downloaded = 0;
5183
5184
  return new Promise((resolve, reject) => {
5184
- const writable = fs.createWriteStream(downloadPath);
5185
+ const writable = fs3.createWriteStream(downloadPath);
5185
5186
  response.readableStreamBody?.on("data", (chunk) => {
5186
5187
  downloaded += chunk.length;
5187
5188
  if (onProgress && fileSize > 0) {
@@ -5244,7 +5245,7 @@ var CloudinaryService = class {
5244
5245
  }
5245
5246
  // Upload file to Cloudinary
5246
5247
  async uploadFile(filePath, options = {}) {
5247
- if (!fs.existsSync(filePath)) {
5248
+ if (!fs3.existsSync(filePath)) {
5248
5249
  throw new Error(`File not found: ${filePath}`);
5249
5250
  }
5250
5251
  const folderPath = this.buildFolderPath(options.folder);
@@ -5314,15 +5315,36 @@ var SMTPProvider = class {
5314
5315
  }
5315
5316
  };
5316
5317
  var TemplateEngine = class {
5317
- static cache = {};
5318
+ static templateCache = {};
5319
+ static cssCache = {};
5320
+ // Load ALL CSS files from styles folder
5321
+ static loadAllCSS(stylesDir) {
5322
+ if (!fs3.existsSync(stylesDir)) return "";
5323
+ const files = fs3.readdirSync(stylesDir).filter((f) => f.endsWith(".css"));
5324
+ let combinedCSS = "";
5325
+ for (const file of files) {
5326
+ const filePath = path.join(stylesDir, file);
5327
+ if (!this.cssCache[filePath]) {
5328
+ this.cssCache[filePath] = fs3.readFileSync(filePath, "utf-8");
5329
+ }
5330
+ combinedCSS += this.cssCache[filePath] + "\n";
5331
+ }
5332
+ return combinedCSS;
5333
+ }
5318
5334
  static render(templateName, data, templateDir) {
5319
- const cacheKey = `${templateDir}:${templateName}`;
5320
- if (!this.cache[cacheKey]) {
5335
+ const templateKey = `${templateDir}:${templateName}`;
5336
+ if (!this.templateCache[templateKey]) {
5321
5337
  const filePath = path.join(templateDir, `${templateName}.hbs`);
5322
- const source = fs.readFileSync(filePath, "utf-8");
5323
- this.cache[cacheKey] = Handlebars.compile(source);
5324
- }
5325
- return this.cache[cacheKey](data);
5338
+ const source = fs3.readFileSync(filePath, "utf-8");
5339
+ this.templateCache[templateKey] = Handlebars.compile(source);
5340
+ }
5341
+ const stylesDir = path.join(templateDir, "styles");
5342
+ const css = this.loadAllCSS(stylesDir);
5343
+ const rawHtml = this.templateCache[templateKey]({
5344
+ ...data,
5345
+ styles: css
5346
+ });
5347
+ return juice(rawHtml);
5326
5348
  }
5327
5349
  };
5328
5350