elseware-nodejs 1.6.0 → 1.7.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.
package/dist/index.d.cts CHANGED
@@ -1860,6 +1860,45 @@ declare class CloudinaryService {
1860
1860
  private buildFolderPath;
1861
1861
  }
1862
1862
 
1863
+ interface EmailProvider {
1864
+ sendMail(options: {
1865
+ to: string;
1866
+ subject: string;
1867
+ html: string;
1868
+ from: string;
1869
+ }): Promise<void>;
1870
+ }
1871
+
1872
+ declare class SMTPProvider implements EmailProvider {
1873
+ private transporter;
1874
+ constructor(config: {
1875
+ host: string;
1876
+ port: number;
1877
+ user: string;
1878
+ pass: string;
1879
+ });
1880
+ sendMail({ to, subject, html, from }: any): Promise<void>;
1881
+ }
1882
+
1883
+ interface SendEmailOptions {
1884
+ to: string;
1885
+ subject: string;
1886
+ template: string;
1887
+ data?: Record<string, any>;
1888
+ }
1889
+ declare class EmailService {
1890
+ private provider;
1891
+ private from;
1892
+ private templateDir;
1893
+ constructor(provider: EmailProvider, from: string, templateDir: string);
1894
+ send(options: SendEmailOptions): Promise<void>;
1895
+ }
1896
+
1897
+ declare class TemplateEngine {
1898
+ static cache: Record<string, HandlebarsTemplateDelegate>;
1899
+ static render(templateName: string, data: any, templateDir: string): string;
1900
+ }
1901
+
1863
1902
  interface JWTServiceOptions {
1864
1903
  accessSecret: string;
1865
1904
  refreshSecret: string;
@@ -1920,4 +1959,4 @@ declare function toMinutes(ms: number): number;
1920
1959
  declare function toHours(ms: number): number;
1921
1960
  declare function sleep(ms: number): Promise<void>;
1922
1961
 
1923
- export { APIFactory, APIFeatures, APIResponse, AVLTree, AdjacencyList, AdjacencyMatrix, type AdjacentEdge, type AllowedOriginsOptions, AppError, type AzureBlobStorageConfig, AzureBlobStorageService, BPlusTree, BTree, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, type CloudinaryConfig, CloudinaryService, ConsistentHash, CountMinSketch, type DatabaseConfig, Deque, type DirectedEdge, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, type Edge, FenwickTree, FibNode, FibonacciHeap, GlobalErrorHandler, Graph, HashMap, HashSet, HyperLogLog, type Interval, IntervalTree, JWTService, type JWTServiceOptions, KDTree, LFUCache, LRUCache, type LoggerOptions, MaxHeap, MaxStack, MinHeap, MinStack, MulterFileHandlerService, MultiSet, Node, OrderedSet, PairingHeap, PairingNode, type Point, type Point2D, PriorityQueue, type ProgressCallback, QuadTree, Queue, RadixTree, type Rect, RedBlackTree, SegmentTree, Set, SinglyLinkedList, SparseTable, SplayTree, Stack, StaticArray, SuffixArray, SuffixTree, TernarySearchTree, TreeNode, Trie, type UploadOptions, asyncHandler, authMiddleware, connectMongoDB, createAllowedOrigins, createCorsOptions, days, errorToString, hours, loadEnv, logger, milliseconds, minutes, pickFields, seconds, sleep, toHours, toMinutes, toSeconds, validate };
1962
+ export { APIFactory, APIFeatures, APIResponse, AVLTree, AdjacencyList, AdjacencyMatrix, type AdjacentEdge, type AllowedOriginsOptions, AppError, type AzureBlobStorageConfig, AzureBlobStorageService, BPlusTree, BTree, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, type CloudinaryConfig, CloudinaryService, ConsistentHash, CountMinSketch, type DatabaseConfig, Deque, type DirectedEdge, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, type Edge, type EmailProvider, EmailService, FenwickTree, FibNode, FibonacciHeap, GlobalErrorHandler, Graph, HashMap, HashSet, HyperLogLog, type Interval, IntervalTree, JWTService, type JWTServiceOptions, KDTree, LFUCache, LRUCache, type LoggerOptions, MaxHeap, MaxStack, MinHeap, MinStack, MulterFileHandlerService, MultiSet, Node, OrderedSet, PairingHeap, PairingNode, type Point, type Point2D, PriorityQueue, type ProgressCallback, QuadTree, Queue, RadixTree, type Rect, RedBlackTree, SMTPProvider, SegmentTree, type SendEmailOptions, Set, SinglyLinkedList, SparseTable, SplayTree, Stack, StaticArray, SuffixArray, SuffixTree, TemplateEngine, TernarySearchTree, TreeNode, Trie, type UploadOptions, asyncHandler, authMiddleware, connectMongoDB, createAllowedOrigins, createCorsOptions, days, errorToString, hours, loadEnv, logger, milliseconds, minutes, pickFields, seconds, sleep, toHours, toMinutes, toSeconds, validate };
package/dist/index.d.ts CHANGED
@@ -1860,6 +1860,45 @@ declare class CloudinaryService {
1860
1860
  private buildFolderPath;
1861
1861
  }
1862
1862
 
1863
+ interface EmailProvider {
1864
+ sendMail(options: {
1865
+ to: string;
1866
+ subject: string;
1867
+ html: string;
1868
+ from: string;
1869
+ }): Promise<void>;
1870
+ }
1871
+
1872
+ declare class SMTPProvider implements EmailProvider {
1873
+ private transporter;
1874
+ constructor(config: {
1875
+ host: string;
1876
+ port: number;
1877
+ user: string;
1878
+ pass: string;
1879
+ });
1880
+ sendMail({ to, subject, html, from }: any): Promise<void>;
1881
+ }
1882
+
1883
+ interface SendEmailOptions {
1884
+ to: string;
1885
+ subject: string;
1886
+ template: string;
1887
+ data?: Record<string, any>;
1888
+ }
1889
+ declare class EmailService {
1890
+ private provider;
1891
+ private from;
1892
+ private templateDir;
1893
+ constructor(provider: EmailProvider, from: string, templateDir: string);
1894
+ send(options: SendEmailOptions): Promise<void>;
1895
+ }
1896
+
1897
+ declare class TemplateEngine {
1898
+ static cache: Record<string, HandlebarsTemplateDelegate>;
1899
+ static render(templateName: string, data: any, templateDir: string): string;
1900
+ }
1901
+
1863
1902
  interface JWTServiceOptions {
1864
1903
  accessSecret: string;
1865
1904
  refreshSecret: string;
@@ -1920,4 +1959,4 @@ declare function toMinutes(ms: number): number;
1920
1959
  declare function toHours(ms: number): number;
1921
1960
  declare function sleep(ms: number): Promise<void>;
1922
1961
 
1923
- export { APIFactory, APIFeatures, APIResponse, AVLTree, AdjacencyList, AdjacencyMatrix, type AdjacentEdge, type AllowedOriginsOptions, AppError, type AzureBlobStorageConfig, AzureBlobStorageService, BPlusTree, BTree, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, type CloudinaryConfig, CloudinaryService, ConsistentHash, CountMinSketch, type DatabaseConfig, Deque, type DirectedEdge, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, type Edge, FenwickTree, FibNode, FibonacciHeap, GlobalErrorHandler, Graph, HashMap, HashSet, HyperLogLog, type Interval, IntervalTree, JWTService, type JWTServiceOptions, KDTree, LFUCache, LRUCache, type LoggerOptions, MaxHeap, MaxStack, MinHeap, MinStack, MulterFileHandlerService, MultiSet, Node, OrderedSet, PairingHeap, PairingNode, type Point, type Point2D, PriorityQueue, type ProgressCallback, QuadTree, Queue, RadixTree, type Rect, RedBlackTree, SegmentTree, Set, SinglyLinkedList, SparseTable, SplayTree, Stack, StaticArray, SuffixArray, SuffixTree, TernarySearchTree, TreeNode, Trie, type UploadOptions, asyncHandler, authMiddleware, connectMongoDB, createAllowedOrigins, createCorsOptions, days, errorToString, hours, loadEnv, logger, milliseconds, minutes, pickFields, seconds, sleep, toHours, toMinutes, toSeconds, validate };
1962
+ export { APIFactory, APIFeatures, APIResponse, AVLTree, AdjacencyList, AdjacencyMatrix, type AdjacentEdge, type AllowedOriginsOptions, AppError, type AzureBlobStorageConfig, AzureBlobStorageService, BPlusTree, BTree, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, type CloudinaryConfig, CloudinaryService, ConsistentHash, CountMinSketch, type DatabaseConfig, Deque, type DirectedEdge, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, type Edge, type EmailProvider, EmailService, FenwickTree, FibNode, FibonacciHeap, GlobalErrorHandler, Graph, HashMap, HashSet, HyperLogLog, type Interval, IntervalTree, JWTService, type JWTServiceOptions, KDTree, LFUCache, LRUCache, type LoggerOptions, MaxHeap, MaxStack, MinHeap, MinStack, MulterFileHandlerService, MultiSet, Node, OrderedSet, PairingHeap, PairingNode, type Point, type Point2D, PriorityQueue, type ProgressCallback, QuadTree, Queue, RadixTree, type Rect, RedBlackTree, SMTPProvider, SegmentTree, type SendEmailOptions, Set, SinglyLinkedList, SparseTable, SplayTree, Stack, StaticArray, SuffixArray, SuffixTree, TemplateEngine, TernarySearchTree, TreeNode, Trie, type UploadOptions, asyncHandler, authMiddleware, connectMongoDB, createAllowedOrigins, createCorsOptions, days, errorToString, hours, loadEnv, logger, milliseconds, minutes, pickFields, seconds, sleep, toHours, toMinutes, toSeconds, validate };
package/dist/index.js CHANGED
@@ -3,6 +3,9 @@ import dotenv from 'dotenv';
3
3
  import { BlobServiceClient, StorageSharedKeyCredential, generateBlobSASQueryParameters, BlobSASPermissions } from '@azure/storage-blob';
4
4
  import fs from 'fs';
5
5
  import cloudinaryModule from 'cloudinary';
6
+ import nodemailer from 'nodemailer';
7
+ import path from 'path';
8
+ import Handlebars from 'handlebars';
6
9
  import jwt from 'jsonwebtoken';
7
10
  import multer from 'multer';
8
11
 
@@ -5288,6 +5291,65 @@ var CloudinaryService = class {
5288
5291
  return this.rootFolder || subFolder;
5289
5292
  }
5290
5293
  };
5294
+ var SMTPProvider = class {
5295
+ transporter;
5296
+ constructor(config) {
5297
+ this.transporter = nodemailer.createTransport({
5298
+ host: config.host,
5299
+ port: config.port,
5300
+ secure: config.port === 465,
5301
+ auth: {
5302
+ user: config.user,
5303
+ pass: config.pass
5304
+ }
5305
+ });
5306
+ }
5307
+ async sendMail({ to, subject, html, from }) {
5308
+ await this.transporter.sendMail({
5309
+ from,
5310
+ to,
5311
+ subject,
5312
+ html
5313
+ });
5314
+ }
5315
+ };
5316
+ var TemplateEngine = class {
5317
+ static cache = {};
5318
+ static render(templateName, data, templateDir) {
5319
+ const cacheKey = `${templateDir}:${templateName}`;
5320
+ if (!this.cache[cacheKey]) {
5321
+ 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);
5326
+ }
5327
+ };
5328
+
5329
+ // src/services/email/email.service.ts
5330
+ var EmailService = class {
5331
+ provider;
5332
+ from;
5333
+ templateDir;
5334
+ constructor(provider, from, templateDir) {
5335
+ this.provider = provider;
5336
+ this.from = from;
5337
+ this.templateDir = templateDir;
5338
+ }
5339
+ async send(options) {
5340
+ const html = TemplateEngine.render(
5341
+ options.template,
5342
+ options.data,
5343
+ this.templateDir
5344
+ );
5345
+ await this.provider.sendMail({
5346
+ to: options.to,
5347
+ subject: options.subject,
5348
+ html,
5349
+ from: this.from
5350
+ });
5351
+ }
5352
+ };
5291
5353
  var JWTService = class {
5292
5354
  accessSecret;
5293
5355
  refreshSecret;
@@ -5488,6 +5550,6 @@ function sleep(ms) {
5488
5550
  return new Promise((resolve) => setTimeout(resolve, ms));
5489
5551
  }
5490
5552
 
5491
- export { APIFactory, apiFeatures_default as APIFeatures, APIResponse, AVLTree, AdjacencyList, AdjacencyMatrix, AppError, AzureBlobStorageService, BPlusTree, BTree, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, CloudinaryService, ConsistentHash, CountMinSketch, Deque, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, FenwickTree, FibNode, FibonacciHeap, GlobalErrorHandler, Graph, HashMap, HashSet, HyperLogLog, IntervalTree, JWTService, KDTree, LFUCache, LRUCache, MaxHeap, MaxStack, MinHeap, MinStack, MulterFileHandlerService, MultiSet, Node, OrderedSet, PairingHeap, PairingNode, PriorityQueue, QuadTree, Queue, RadixTree, RedBlackTree, SegmentTree, Set2 as Set, SinglyLinkedList, SparseTable, SplayTree, Stack, StaticArray, SuffixArray, SuffixTree, TernarySearchTree, TreeNode, Trie, asyncHandler, authMiddleware, connectMongoDB, createAllowedOrigins, createCorsOptions, days, errorToString, hours, loadEnv, logger, milliseconds, minutes, pickFields, seconds, sleep, toHours, toMinutes, toSeconds, validate };
5553
+ export { APIFactory, apiFeatures_default as APIFeatures, APIResponse, AVLTree, AdjacencyList, AdjacencyMatrix, AppError, AzureBlobStorageService, BPlusTree, BTree, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, CloudinaryService, ConsistentHash, CountMinSketch, Deque, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, EmailService, FenwickTree, FibNode, FibonacciHeap, GlobalErrorHandler, Graph, HashMap, HashSet, HyperLogLog, IntervalTree, JWTService, KDTree, LFUCache, LRUCache, MaxHeap, MaxStack, MinHeap, MinStack, MulterFileHandlerService, MultiSet, Node, OrderedSet, PairingHeap, PairingNode, PriorityQueue, QuadTree, Queue, RadixTree, RedBlackTree, SMTPProvider, SegmentTree, Set2 as Set, SinglyLinkedList, SparseTable, SplayTree, Stack, StaticArray, SuffixArray, SuffixTree, TemplateEngine, TernarySearchTree, TreeNode, Trie, asyncHandler, authMiddleware, connectMongoDB, createAllowedOrigins, createCorsOptions, days, errorToString, hours, loadEnv, logger, milliseconds, minutes, pickFields, seconds, sleep, toHours, toMinutes, toSeconds, validate };
5492
5554
  //# sourceMappingURL=index.js.map
5493
5555
  //# sourceMappingURL=index.js.map