elseware-nodejs 1.7.0 → 1.7.2

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.cjs CHANGED
@@ -3,11 +3,12 @@
3
3
  var mongoose = require('mongoose');
4
4
  var dotenv = require('dotenv');
5
5
  var storageBlob = require('@azure/storage-blob');
6
- var fs = require('fs');
6
+ var fs3 = require('fs');
7
7
  var cloudinaryModule = require('cloudinary');
8
8
  var nodemailer = require('nodemailer');
9
9
  var path = require('path');
10
10
  var Handlebars = require('handlebars');
11
+ var juice = require('juice');
11
12
  var jwt = require('jsonwebtoken');
12
13
  var multer = require('multer');
13
14
 
@@ -15,11 +16,12 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
15
16
 
16
17
  var mongoose__default = /*#__PURE__*/_interopDefault(mongoose);
17
18
  var dotenv__default = /*#__PURE__*/_interopDefault(dotenv);
18
- var fs__default = /*#__PURE__*/_interopDefault(fs);
19
+ var fs3__default = /*#__PURE__*/_interopDefault(fs3);
19
20
  var cloudinaryModule__default = /*#__PURE__*/_interopDefault(cloudinaryModule);
20
21
  var nodemailer__default = /*#__PURE__*/_interopDefault(nodemailer);
21
22
  var path__default = /*#__PURE__*/_interopDefault(path);
22
23
  var Handlebars__default = /*#__PURE__*/_interopDefault(Handlebars);
24
+ var juice__default = /*#__PURE__*/_interopDefault(juice);
23
25
  var jwt__default = /*#__PURE__*/_interopDefault(jwt);
24
26
  var multer__default = /*#__PURE__*/_interopDefault(multer);
25
27
 
@@ -5169,8 +5171,8 @@ var AzureBlobStorageService = class {
5169
5171
  // Upload file
5170
5172
  async uploadFile(localPath, blobName, onProgress) {
5171
5173
  const blockBlobClient = this.containerClient.getBlockBlobClient(blobName);
5172
- const fileSize = fs__default.default.statSync(localPath).size;
5173
- const readStream = fs__default.default.createReadStream(localPath);
5174
+ const fileSize = fs3__default.default.statSync(localPath).size;
5175
+ const readStream = fs3__default.default.createReadStream(localPath);
5174
5176
  await blockBlobClient.uploadStream(
5175
5177
  readStream,
5176
5178
  4 * 1024 * 1024,
@@ -5195,7 +5197,7 @@ var AzureBlobStorageService = class {
5195
5197
  const fileSize = response.contentLength || 0;
5196
5198
  let downloaded = 0;
5197
5199
  return new Promise((resolve, reject) => {
5198
- const writable = fs__default.default.createWriteStream(downloadPath);
5200
+ const writable = fs3__default.default.createWriteStream(downloadPath);
5199
5201
  response.readableStreamBody?.on("data", (chunk) => {
5200
5202
  downloaded += chunk.length;
5201
5203
  if (onProgress && fileSize > 0) {
@@ -5258,7 +5260,7 @@ var CloudinaryService = class {
5258
5260
  }
5259
5261
  // Upload file to Cloudinary
5260
5262
  async uploadFile(filePath, options = {}) {
5261
- if (!fs__default.default.existsSync(filePath)) {
5263
+ if (!fs3__default.default.existsSync(filePath)) {
5262
5264
  throw new Error(`File not found: ${filePath}`);
5263
5265
  }
5264
5266
  const folderPath = this.buildFolderPath(options.folder);
@@ -5328,15 +5330,36 @@ var SMTPProvider = class {
5328
5330
  }
5329
5331
  };
5330
5332
  var TemplateEngine = class {
5331
- static cache = {};
5333
+ static templateCache = {};
5334
+ static cssCache = {};
5335
+ // Load ALL CSS files from styles folder
5336
+ static loadAllCSS(stylesDir) {
5337
+ if (!fs3__default.default.existsSync(stylesDir)) return "";
5338
+ const files = fs3__default.default.readdirSync(stylesDir).filter((f) => f.endsWith(".css"));
5339
+ let combinedCSS = "";
5340
+ for (const file of files) {
5341
+ const filePath = path__default.default.join(stylesDir, file);
5342
+ if (!this.cssCache[filePath]) {
5343
+ this.cssCache[filePath] = fs3__default.default.readFileSync(filePath, "utf-8");
5344
+ }
5345
+ combinedCSS += this.cssCache[filePath] + "\n";
5346
+ }
5347
+ return combinedCSS;
5348
+ }
5332
5349
  static render(templateName, data, templateDir) {
5333
- const cacheKey = `${templateDir}:${templateName}`;
5334
- if (!this.cache[cacheKey]) {
5350
+ const templateKey = `${templateDir}:${templateName}`;
5351
+ if (!this.templateCache[templateKey]) {
5335
5352
  const filePath = path__default.default.join(templateDir, `${templateName}.hbs`);
5336
- const source = fs__default.default.readFileSync(filePath, "utf-8");
5337
- this.cache[cacheKey] = Handlebars__default.default.compile(source);
5338
- }
5339
- return this.cache[cacheKey](data);
5353
+ const source = fs3__default.default.readFileSync(filePath, "utf-8");
5354
+ this.templateCache[templateKey] = Handlebars__default.default.compile(source);
5355
+ }
5356
+ const stylesDir = path__default.default.join(templateDir, "styles");
5357
+ const css = this.loadAllCSS(stylesDir);
5358
+ const rawHtml = this.templateCache[templateKey]({
5359
+ ...data,
5360
+ styles: css
5361
+ });
5362
+ return juice__default.default(rawHtml);
5340
5363
  }
5341
5364
  };
5342
5365