elseware-nodejs 1.5.3 → 1.6.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.cjs +58 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.js +57 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.d.cts
CHANGED
|
@@ -1888,6 +1888,26 @@ declare class JWTService {
|
|
|
1888
1888
|
private parseExpires;
|
|
1889
1889
|
}
|
|
1890
1890
|
|
|
1891
|
+
type MulterFileHandlerOptions = {
|
|
1892
|
+
storage?: "memory" | "disk";
|
|
1893
|
+
allowedMimeTypes?: string[];
|
|
1894
|
+
allowedExtensions?: string[];
|
|
1895
|
+
fileSizeLimit?: number;
|
|
1896
|
+
};
|
|
1897
|
+
declare class MulterFileHandlerService {
|
|
1898
|
+
private storage;
|
|
1899
|
+
private options;
|
|
1900
|
+
constructor(options?: MulterFileHandlerOptions);
|
|
1901
|
+
private fileFilter;
|
|
1902
|
+
private buildUploader;
|
|
1903
|
+
single(fieldName: string): any;
|
|
1904
|
+
array(fieldName: string, maxCount: number): any;
|
|
1905
|
+
fields(fields: {
|
|
1906
|
+
name: string;
|
|
1907
|
+
maxCount?: number;
|
|
1908
|
+
}[]): any;
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1891
1911
|
declare function errorToString(error: unknown): string;
|
|
1892
1912
|
|
|
1893
1913
|
declare function milliseconds(value: number): number;
|
|
@@ -1900,4 +1920,4 @@ declare function toMinutes(ms: number): number;
|
|
|
1900
1920
|
declare function toHours(ms: number): number;
|
|
1901
1921
|
declare function sleep(ms: number): Promise<void>;
|
|
1902
1922
|
|
|
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 };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1888,6 +1888,26 @@ declare class JWTService {
|
|
|
1888
1888
|
private parseExpires;
|
|
1889
1889
|
}
|
|
1890
1890
|
|
|
1891
|
+
type MulterFileHandlerOptions = {
|
|
1892
|
+
storage?: "memory" | "disk";
|
|
1893
|
+
allowedMimeTypes?: string[];
|
|
1894
|
+
allowedExtensions?: string[];
|
|
1895
|
+
fileSizeLimit?: number;
|
|
1896
|
+
};
|
|
1897
|
+
declare class MulterFileHandlerService {
|
|
1898
|
+
private storage;
|
|
1899
|
+
private options;
|
|
1900
|
+
constructor(options?: MulterFileHandlerOptions);
|
|
1901
|
+
private fileFilter;
|
|
1902
|
+
private buildUploader;
|
|
1903
|
+
single(fieldName: string): any;
|
|
1904
|
+
array(fieldName: string, maxCount: number): any;
|
|
1905
|
+
fields(fields: {
|
|
1906
|
+
name: string;
|
|
1907
|
+
maxCount?: number;
|
|
1908
|
+
}[]): any;
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1891
1911
|
declare function errorToString(error: unknown): string;
|
|
1892
1912
|
|
|
1893
1913
|
declare function milliseconds(value: number): number;
|
|
@@ -1900,4 +1920,4 @@ declare function toMinutes(ms: number): number;
|
|
|
1900
1920
|
declare function toHours(ms: number): number;
|
|
1901
1921
|
declare function sleep(ms: number): Promise<void>;
|
|
1902
1922
|
|
|
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 };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { BlobServiceClient, StorageSharedKeyCredential, generateBlobSASQueryPara
|
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import cloudinaryModule from 'cloudinary';
|
|
6
6
|
import jwt from 'jsonwebtoken';
|
|
7
|
+
import multer from 'multer';
|
|
7
8
|
|
|
8
9
|
// src/errors/appError.ts
|
|
9
10
|
var AppError = class extends Error {
|
|
@@ -5402,6 +5403,61 @@ var JWTService = class {
|
|
|
5402
5403
|
return value;
|
|
5403
5404
|
}
|
|
5404
5405
|
};
|
|
5406
|
+
var MulterFileHandlerService = class {
|
|
5407
|
+
storage;
|
|
5408
|
+
options;
|
|
5409
|
+
constructor(options = {}) {
|
|
5410
|
+
this.options = options;
|
|
5411
|
+
this.storage = options.storage === "memory" ? multer.memoryStorage() : multer.diskStorage({});
|
|
5412
|
+
}
|
|
5413
|
+
// File Filter
|
|
5414
|
+
fileFilter = (req, file, cb) => {
|
|
5415
|
+
const { allowedMimeTypes, allowedExtensions } = this.options;
|
|
5416
|
+
const mimeType = file.mimetype;
|
|
5417
|
+
const extFromMime = mimeType.split("/")[1]?.toLowerCase();
|
|
5418
|
+
if (allowedMimeTypes?.length) {
|
|
5419
|
+
if (!allowedMimeTypes.includes(mimeType)) {
|
|
5420
|
+
return cb(
|
|
5421
|
+
new AppError(
|
|
5422
|
+
`Invalid file type! Allowed: ${allowedMimeTypes.join(", ")}`,
|
|
5423
|
+
400
|
|
5424
|
+
),
|
|
5425
|
+
false
|
|
5426
|
+
);
|
|
5427
|
+
}
|
|
5428
|
+
}
|
|
5429
|
+
if (allowedExtensions?.length) {
|
|
5430
|
+
if (!extFromMime || !allowedExtensions.includes(extFromMime)) {
|
|
5431
|
+
return cb(
|
|
5432
|
+
new AppError(
|
|
5433
|
+
`Invalid file extension! Allowed: ${allowedExtensions.join(", ")}`,
|
|
5434
|
+
400
|
|
5435
|
+
),
|
|
5436
|
+
false
|
|
5437
|
+
);
|
|
5438
|
+
}
|
|
5439
|
+
}
|
|
5440
|
+
cb(null, true);
|
|
5441
|
+
};
|
|
5442
|
+
// Build multer instance
|
|
5443
|
+
buildUploader() {
|
|
5444
|
+
return multer({
|
|
5445
|
+
storage: this.storage,
|
|
5446
|
+
fileFilter: this.fileFilter,
|
|
5447
|
+
limits: this.options.fileSizeLimit ? { fileSize: this.options.fileSizeLimit } : void 0
|
|
5448
|
+
});
|
|
5449
|
+
}
|
|
5450
|
+
// Public API
|
|
5451
|
+
single(fieldName) {
|
|
5452
|
+
return this.buildUploader().single(fieldName);
|
|
5453
|
+
}
|
|
5454
|
+
array(fieldName, maxCount) {
|
|
5455
|
+
return this.buildUploader().array(fieldName, maxCount);
|
|
5456
|
+
}
|
|
5457
|
+
fields(fields) {
|
|
5458
|
+
return this.buildUploader().fields(fields);
|
|
5459
|
+
}
|
|
5460
|
+
};
|
|
5405
5461
|
|
|
5406
5462
|
// src/utils/time.ts
|
|
5407
5463
|
function milliseconds(value) {
|
|
@@ -5432,6 +5488,6 @@ function sleep(ms) {
|
|
|
5432
5488
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
5433
5489
|
}
|
|
5434
5490
|
|
|
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 };
|
|
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 };
|
|
5436
5492
|
//# sourceMappingURL=index.js.map
|
|
5437
5493
|
//# sourceMappingURL=index.js.map
|