elseware-nodejs 1.6.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/README.md +1 -1
- package/dist/index.cjs +97 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -1
- package/dist/index.d.ts +42 -1
- package/dist/index.js +90 -6
- package/dist/index.js.map +1 -1
- package/package.json +75 -72
package/dist/index.d.cts
CHANGED
|
@@ -1860,6 +1860,47 @@ 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 templateCache: Record<string, HandlebarsTemplateDelegate>;
|
|
1899
|
+
static cssCache: Record<string, string>;
|
|
1900
|
+
static loadAllCSS(stylesDir: string): string;
|
|
1901
|
+
static render(templateName: string, data: any, templateDir: string): string;
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1863
1904
|
interface JWTServiceOptions {
|
|
1864
1905
|
accessSecret: string;
|
|
1865
1906
|
refreshSecret: string;
|
|
@@ -1920,4 +1961,4 @@ declare function toMinutes(ms: number): number;
|
|
|
1920
1961
|
declare function toHours(ms: number): number;
|
|
1921
1962
|
declare function sleep(ms: number): Promise<void>;
|
|
1922
1963
|
|
|
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 };
|
|
1964
|
+
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,47 @@ 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 templateCache: Record<string, HandlebarsTemplateDelegate>;
|
|
1899
|
+
static cssCache: Record<string, string>;
|
|
1900
|
+
static loadAllCSS(stylesDir: string): string;
|
|
1901
|
+
static render(templateName: string, data: any, templateDir: string): string;
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1863
1904
|
interface JWTServiceOptions {
|
|
1864
1905
|
accessSecret: string;
|
|
1865
1906
|
refreshSecret: string;
|
|
@@ -1920,4 +1961,4 @@ declare function toMinutes(ms: number): number;
|
|
|
1920
1961
|
declare function toHours(ms: number): number;
|
|
1921
1962
|
declare function sleep(ms: number): Promise<void>;
|
|
1922
1963
|
|
|
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 };
|
|
1964
|
+
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
|
@@ -1,8 +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
|
|
4
|
+
import fs3 from 'fs';
|
|
5
5
|
import cloudinaryModule from 'cloudinary';
|
|
6
|
+
import nodemailer from 'nodemailer';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import Handlebars from 'handlebars';
|
|
9
|
+
import juice from 'juice';
|
|
6
10
|
import jwt from 'jsonwebtoken';
|
|
7
11
|
import multer from 'multer';
|
|
8
12
|
|
|
@@ -5152,8 +5156,8 @@ var AzureBlobStorageService = class {
|
|
|
5152
5156
|
// Upload file
|
|
5153
5157
|
async uploadFile(localPath, blobName, onProgress) {
|
|
5154
5158
|
const blockBlobClient = this.containerClient.getBlockBlobClient(blobName);
|
|
5155
|
-
const fileSize =
|
|
5156
|
-
const readStream =
|
|
5159
|
+
const fileSize = fs3.statSync(localPath).size;
|
|
5160
|
+
const readStream = fs3.createReadStream(localPath);
|
|
5157
5161
|
await blockBlobClient.uploadStream(
|
|
5158
5162
|
readStream,
|
|
5159
5163
|
4 * 1024 * 1024,
|
|
@@ -5178,7 +5182,7 @@ var AzureBlobStorageService = class {
|
|
|
5178
5182
|
const fileSize = response.contentLength || 0;
|
|
5179
5183
|
let downloaded = 0;
|
|
5180
5184
|
return new Promise((resolve, reject) => {
|
|
5181
|
-
const writable =
|
|
5185
|
+
const writable = fs3.createWriteStream(downloadPath);
|
|
5182
5186
|
response.readableStreamBody?.on("data", (chunk) => {
|
|
5183
5187
|
downloaded += chunk.length;
|
|
5184
5188
|
if (onProgress && fileSize > 0) {
|
|
@@ -5241,7 +5245,7 @@ var CloudinaryService = class {
|
|
|
5241
5245
|
}
|
|
5242
5246
|
// Upload file to Cloudinary
|
|
5243
5247
|
async uploadFile(filePath, options = {}) {
|
|
5244
|
-
if (!
|
|
5248
|
+
if (!fs3.existsSync(filePath)) {
|
|
5245
5249
|
throw new Error(`File not found: ${filePath}`);
|
|
5246
5250
|
}
|
|
5247
5251
|
const folderPath = this.buildFolderPath(options.folder);
|
|
@@ -5288,6 +5292,86 @@ var CloudinaryService = class {
|
|
|
5288
5292
|
return this.rootFolder || subFolder;
|
|
5289
5293
|
}
|
|
5290
5294
|
};
|
|
5295
|
+
var SMTPProvider = class {
|
|
5296
|
+
transporter;
|
|
5297
|
+
constructor(config) {
|
|
5298
|
+
this.transporter = nodemailer.createTransport({
|
|
5299
|
+
host: config.host,
|
|
5300
|
+
port: config.port,
|
|
5301
|
+
secure: config.port === 465,
|
|
5302
|
+
auth: {
|
|
5303
|
+
user: config.user,
|
|
5304
|
+
pass: config.pass
|
|
5305
|
+
}
|
|
5306
|
+
});
|
|
5307
|
+
}
|
|
5308
|
+
async sendMail({ to, subject, html, from }) {
|
|
5309
|
+
await this.transporter.sendMail({
|
|
5310
|
+
from,
|
|
5311
|
+
to,
|
|
5312
|
+
subject,
|
|
5313
|
+
html
|
|
5314
|
+
});
|
|
5315
|
+
}
|
|
5316
|
+
};
|
|
5317
|
+
var TemplateEngine = class {
|
|
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
|
+
}
|
|
5334
|
+
static render(templateName, data, templateDir) {
|
|
5335
|
+
const templateKey = `${templateDir}:${templateName}`;
|
|
5336
|
+
if (!this.templateCache[templateKey]) {
|
|
5337
|
+
const filePath = path.join(templateDir, `${templateName}.hbs`);
|
|
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);
|
|
5348
|
+
}
|
|
5349
|
+
};
|
|
5350
|
+
|
|
5351
|
+
// src/services/email/email.service.ts
|
|
5352
|
+
var EmailService = class {
|
|
5353
|
+
provider;
|
|
5354
|
+
from;
|
|
5355
|
+
templateDir;
|
|
5356
|
+
constructor(provider, from, templateDir) {
|
|
5357
|
+
this.provider = provider;
|
|
5358
|
+
this.from = from;
|
|
5359
|
+
this.templateDir = templateDir;
|
|
5360
|
+
}
|
|
5361
|
+
async send(options) {
|
|
5362
|
+
const html = TemplateEngine.render(
|
|
5363
|
+
options.template,
|
|
5364
|
+
options.data,
|
|
5365
|
+
this.templateDir
|
|
5366
|
+
);
|
|
5367
|
+
await this.provider.sendMail({
|
|
5368
|
+
to: options.to,
|
|
5369
|
+
subject: options.subject,
|
|
5370
|
+
html,
|
|
5371
|
+
from: this.from
|
|
5372
|
+
});
|
|
5373
|
+
}
|
|
5374
|
+
};
|
|
5291
5375
|
var JWTService = class {
|
|
5292
5376
|
accessSecret;
|
|
5293
5377
|
refreshSecret;
|
|
@@ -5488,6 +5572,6 @@ function sleep(ms) {
|
|
|
5488
5572
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
5489
5573
|
}
|
|
5490
5574
|
|
|
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 };
|
|
5575
|
+
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
5576
|
//# sourceMappingURL=index.js.map
|
|
5493
5577
|
//# sourceMappingURL=index.js.map
|