elseware-nodejs 1.5.3 → 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;
@@ -1888,6 +1927,26 @@ declare class JWTService {
1888
1927
  private parseExpires;
1889
1928
  }
1890
1929
 
1930
+ type MulterFileHandlerOptions = {
1931
+ storage?: "memory" | "disk";
1932
+ allowedMimeTypes?: string[];
1933
+ allowedExtensions?: string[];
1934
+ fileSizeLimit?: number;
1935
+ };
1936
+ declare class MulterFileHandlerService {
1937
+ private storage;
1938
+ private options;
1939
+ constructor(options?: MulterFileHandlerOptions);
1940
+ private fileFilter;
1941
+ private buildUploader;
1942
+ single(fieldName: string): any;
1943
+ array(fieldName: string, maxCount: number): any;
1944
+ fields(fields: {
1945
+ name: string;
1946
+ maxCount?: number;
1947
+ }[]): any;
1948
+ }
1949
+
1891
1950
  declare function errorToString(error: unknown): string;
1892
1951
 
1893
1952
  declare function milliseconds(value: number): number;
@@ -1900,4 +1959,4 @@ declare function toMinutes(ms: number): number;
1900
1959
  declare function toHours(ms: number): number;
1901
1960
  declare function sleep(ms: number): Promise<void>;
1902
1961
 
1903
- 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, 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;
@@ -1888,6 +1927,26 @@ declare class JWTService {
1888
1927
  private parseExpires;
1889
1928
  }
1890
1929
 
1930
+ type MulterFileHandlerOptions = {
1931
+ storage?: "memory" | "disk";
1932
+ allowedMimeTypes?: string[];
1933
+ allowedExtensions?: string[];
1934
+ fileSizeLimit?: number;
1935
+ };
1936
+ declare class MulterFileHandlerService {
1937
+ private storage;
1938
+ private options;
1939
+ constructor(options?: MulterFileHandlerOptions);
1940
+ private fileFilter;
1941
+ private buildUploader;
1942
+ single(fieldName: string): any;
1943
+ array(fieldName: string, maxCount: number): any;
1944
+ fields(fields: {
1945
+ name: string;
1946
+ maxCount?: number;
1947
+ }[]): any;
1948
+ }
1949
+
1891
1950
  declare function errorToString(error: unknown): string;
1892
1951
 
1893
1952
  declare function milliseconds(value: number): number;
@@ -1900,4 +1959,4 @@ declare function toMinutes(ms: number): number;
1900
1959
  declare function toHours(ms: number): number;
1901
1960
  declare function sleep(ms: number): Promise<void>;
1902
1961
 
1903
- 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, 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,7 +3,11 @@ 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';
10
+ import multer from 'multer';
7
11
 
8
12
  // src/errors/appError.ts
9
13
  var AppError = class extends Error {
@@ -5287,6 +5291,65 @@ var CloudinaryService = class {
5287
5291
  return this.rootFolder || subFolder;
5288
5292
  }
5289
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
+ };
5290
5353
  var JWTService = class {
5291
5354
  accessSecret;
5292
5355
  refreshSecret;
@@ -5402,6 +5465,61 @@ var JWTService = class {
5402
5465
  return value;
5403
5466
  }
5404
5467
  };
5468
+ var MulterFileHandlerService = class {
5469
+ storage;
5470
+ options;
5471
+ constructor(options = {}) {
5472
+ this.options = options;
5473
+ this.storage = options.storage === "memory" ? multer.memoryStorage() : multer.diskStorage({});
5474
+ }
5475
+ // File Filter
5476
+ fileFilter = (req, file, cb) => {
5477
+ const { allowedMimeTypes, allowedExtensions } = this.options;
5478
+ const mimeType = file.mimetype;
5479
+ const extFromMime = mimeType.split("/")[1]?.toLowerCase();
5480
+ if (allowedMimeTypes?.length) {
5481
+ if (!allowedMimeTypes.includes(mimeType)) {
5482
+ return cb(
5483
+ new AppError(
5484
+ `Invalid file type! Allowed: ${allowedMimeTypes.join(", ")}`,
5485
+ 400
5486
+ ),
5487
+ false
5488
+ );
5489
+ }
5490
+ }
5491
+ if (allowedExtensions?.length) {
5492
+ if (!extFromMime || !allowedExtensions.includes(extFromMime)) {
5493
+ return cb(
5494
+ new AppError(
5495
+ `Invalid file extension! Allowed: ${allowedExtensions.join(", ")}`,
5496
+ 400
5497
+ ),
5498
+ false
5499
+ );
5500
+ }
5501
+ }
5502
+ cb(null, true);
5503
+ };
5504
+ // Build multer instance
5505
+ buildUploader() {
5506
+ return multer({
5507
+ storage: this.storage,
5508
+ fileFilter: this.fileFilter,
5509
+ limits: this.options.fileSizeLimit ? { fileSize: this.options.fileSizeLimit } : void 0
5510
+ });
5511
+ }
5512
+ // Public API
5513
+ single(fieldName) {
5514
+ return this.buildUploader().single(fieldName);
5515
+ }
5516
+ array(fieldName, maxCount) {
5517
+ return this.buildUploader().array(fieldName, maxCount);
5518
+ }
5519
+ fields(fields) {
5520
+ return this.buildUploader().fields(fields);
5521
+ }
5522
+ };
5405
5523
 
5406
5524
  // src/utils/time.ts
5407
5525
  function milliseconds(value) {
@@ -5432,6 +5550,6 @@ function sleep(ms) {
5432
5550
  return new Promise((resolve) => setTimeout(resolve, ms));
5433
5551
  }
5434
5552
 
5435
- 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, 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 };
5436
5554
  //# sourceMappingURL=index.js.map
5437
5555
  //# sourceMappingURL=index.js.map