drapcode-utility 2.0.0 → 2.0.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/build/encryption/KMS.js +54 -102
- package/build/encryption/crypt.d.ts +4 -2
- package/build/encryption/crypt.js +76 -91
- package/build/encryption/file.d.ts +0 -2
- package/build/encryption/file.js +14 -130
- package/build/encryption/index.js +162 -334
- package/build/encryption/utility.js +7 -10
- package/build/errors/app-error.js +9 -27
- package/build/errors/axios-error.js +3 -3
- package/build/errors/bad-request-error.js +10 -28
- package/build/errors/custom-error.js +5 -23
- package/build/errors/not-found.js +9 -27
- package/build/format-fields/index.d.ts +0 -1
- package/build/format-fields/index.js +32 -65
- package/build/index.d.ts +1 -4
- package/build/index.js +1 -4
- package/build/middlewares/error-logger.d.ts +1 -1
- package/build/middlewares/error-logger.js +29 -29
- package/build/middlewares/redis/request-log.js +24 -74
- package/build/query/queryBuilder.d.ts +9 -0
- package/build/query/queryBuilder.js +567 -0
- package/build/utils/check-error.d.ts +15 -8
- package/build/utils/check-error.js +71 -160
- package/build/utils/common-util.d.ts +40 -39
- package/build/utils/common-util.js +60 -59
- package/build/utils/date-util.d.ts +28 -7
- package/build/utils/date-util.js +180 -127
- package/build/utils/file-util.d.ts +51 -6
- package/build/utils/file-util.js +36 -40
- package/build/utils/prepare-query.js +70 -43
- package/build/utils/project-util.d.ts +43 -5
- package/build/utils/project-util.js +176 -121
- package/build/utils/query-parser.d.ts +1 -1
- package/build/utils/query-parser.js +289 -342
- package/build/utils/query-utils.d.ts +2 -2
- package/build/utils/query-utils.js +103 -116
- package/build/utils/rest-client.js +236 -328
- package/build/utils/s3-util.js +238 -469
- package/build/utils/token.js +34 -81
- package/build/utils/util.d.ts +58 -13
- package/build/utils/util.js +424 -494
- package/build/utils/uuid-generator.d.ts +20 -1
- package/build/utils/uuid-generator.js +111 -47
- package/package.json +7 -5
- package/build/middlewares/interceptor-logger-new.d.ts +0 -2
- package/build/middlewares/interceptor-logger-new.js +0 -53
- package/build/middlewares/interceptor-logger.d.ts +0 -2
- package/build/middlewares/interceptor-logger.js +0 -52
- package/build/utils/query-parser-new.d.ts +0 -1
- package/build/utils/query-parser-new.js +0 -541
|
@@ -1 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
declare const ALLOWED_CHARS: {
|
|
2
|
+
readonly alphanumeric: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
3
|
+
readonly numeric: "0123456789";
|
|
4
|
+
};
|
|
5
|
+
type Algorithm = keyof typeof ALLOWED_CHARS;
|
|
6
|
+
interface GenerationOptions {
|
|
7
|
+
prepend?: string;
|
|
8
|
+
minLength?: number;
|
|
9
|
+
append?: string;
|
|
10
|
+
algorithm: Algorithm;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Generates the next string in sequence based on the input string and options
|
|
14
|
+
* @param str - The input string to generate the next value from
|
|
15
|
+
* @param options - The generation options
|
|
16
|
+
* @returns The next generated string
|
|
17
|
+
* @throws {UUIDGenerationError} If the input string is invalid
|
|
18
|
+
*/
|
|
19
|
+
export declare const nextGeneratedString: (str: string, options: GenerationOptions) => string;
|
|
20
|
+
export {};
|
|
@@ -4,62 +4,126 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.nextGeneratedString = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
const voca_1 = __importDefault(require("voca"));
|
|
8
|
+
// Constants
|
|
9
|
+
const ALLOWED_CHARS = {
|
|
10
|
+
alphanumeric: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
|
11
|
+
numeric: "0123456789",
|
|
12
|
+
};
|
|
13
|
+
class UUIDGenerationError extends Error {
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = "UUIDGenerationError";
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
}
|
|
19
|
+
// Cache for character lookups
|
|
20
|
+
const charIndexCache = new Map();
|
|
21
|
+
/**
|
|
22
|
+
* Gets the allowed characters based on the algorithm
|
|
23
|
+
* @param algorithm - The algorithm to use
|
|
24
|
+
* @returns The string of allowed characters
|
|
25
|
+
* @throws {UUIDGenerationError} If the algorithm is invalid
|
|
26
|
+
*/
|
|
27
|
+
const getAllowedChars = (algorithm) => {
|
|
28
|
+
const chars = ALLOWED_CHARS[algorithm];
|
|
29
|
+
if (!chars) {
|
|
30
|
+
throw new UUIDGenerationError(`Invalid algorithm: ${algorithm}`);
|
|
22
31
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
return chars;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Gets the index of a character in the allowed characters string
|
|
36
|
+
* @param char - The character to look up
|
|
37
|
+
* @param allowedChars - The string of allowed characters
|
|
38
|
+
* @returns The index of the character
|
|
39
|
+
*/
|
|
40
|
+
const getCharIndex = (char, allowedChars) => {
|
|
41
|
+
const cacheKey = `${char}-${allowedChars}`;
|
|
42
|
+
if (!charIndexCache.has(cacheKey)) {
|
|
43
|
+
charIndexCache.set(cacheKey, allowedChars.indexOf(char));
|
|
28
44
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
45
|
+
return charIndexCache.get(cacheKey);
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Validates if the input string contains only allowed characters
|
|
49
|
+
* @param str - The input string to validate
|
|
50
|
+
* @param allowedChars - The string of allowed characters
|
|
51
|
+
* @returns True if the input string is valid
|
|
52
|
+
*/
|
|
53
|
+
const isValidInput = (str, allowedChars) => {
|
|
54
|
+
return str.split("").every((char) => allowedChars.includes(char));
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Handles leading zeros for numeric values
|
|
58
|
+
* @param value - The value to process
|
|
59
|
+
* @returns The processed value
|
|
60
|
+
*/
|
|
61
|
+
const handleLeadingZeros = (value) => {
|
|
62
|
+
if (voca_1.default.isDigit(value) && !+value) {
|
|
63
|
+
return "1" + value.slice(1);
|
|
35
64
|
}
|
|
36
|
-
|
|
65
|
+
return value;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Applies formatting to the generated value
|
|
69
|
+
* @param value - The value to format
|
|
70
|
+
* @param options - The formatting options
|
|
71
|
+
* @returns The formatted value
|
|
72
|
+
*/
|
|
73
|
+
const applyFormatting = (value, options) => {
|
|
74
|
+
const { minLength, prepend, append } = options;
|
|
75
|
+
let result = value;
|
|
37
76
|
if (minLength) {
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
if (prepend) {
|
|
41
|
-
finalValue = "".concat(prepend).concat(finalValue);
|
|
77
|
+
result = voca_1.default.padLeft(result, minLength, "0");
|
|
42
78
|
}
|
|
43
|
-
|
|
44
|
-
finalValue = "".concat(finalValue).concat(append);
|
|
45
|
-
}
|
|
46
|
-
return finalValue;
|
|
79
|
+
return `${prepend}${result}${append}`;
|
|
47
80
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Calculates the next sequence of indices
|
|
83
|
+
* @param str - The input string
|
|
84
|
+
* @param allowedChars - The string of allowed characters
|
|
85
|
+
* @returns The next sequence of indices
|
|
86
|
+
*/
|
|
87
|
+
const calculateNext = (str, allowedChars) => {
|
|
88
|
+
const nextSequence = str
|
|
89
|
+
.split("")
|
|
90
|
+
.map((char) => getCharIndex(char, allowedChars))
|
|
91
|
+
.reverse();
|
|
92
|
+
for (let i = 0; i < nextSequence.length; i++) {
|
|
93
|
+
const nextValue = nextSequence[i] + 1;
|
|
94
|
+
if (nextValue >= allowedChars.length) {
|
|
95
|
+
nextSequence[i] = 0;
|
|
57
96
|
}
|
|
58
97
|
else {
|
|
59
|
-
|
|
98
|
+
nextSequence[i] = nextValue;
|
|
99
|
+
return nextSequence;
|
|
60
100
|
}
|
|
61
101
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
102
|
+
nextSequence.push(0);
|
|
103
|
+
return nextSequence;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Generates the next string in sequence based on the input string and options
|
|
107
|
+
* @param str - The input string to generate the next value from
|
|
108
|
+
* @param options - The generation options
|
|
109
|
+
* @returns The next generated string
|
|
110
|
+
* @throws {UUIDGenerationError} If the input string is invalid
|
|
111
|
+
*/
|
|
112
|
+
const nextGeneratedString = (str, options) => {
|
|
113
|
+
const { prepend = "", minLength = 0, append = "", algorithm } = options;
|
|
114
|
+
if (!str) {
|
|
115
|
+
throw new UUIDGenerationError("Input string cannot be empty");
|
|
116
|
+
}
|
|
117
|
+
const allowedChars = getAllowedChars(algorithm);
|
|
118
|
+
if (!isValidInput(str, allowedChars)) {
|
|
119
|
+
throw new UUIDGenerationError(`Input string contains invalid characters for algorithm: ${algorithm}`);
|
|
120
|
+
}
|
|
121
|
+
const nextIds = calculateNext(str, allowedChars) || [0];
|
|
122
|
+
const result = nextIds
|
|
123
|
+
.reverse()
|
|
124
|
+
.map((index) => allowedChars[index])
|
|
125
|
+
.join("");
|
|
126
|
+
const finalValue = handleLeadingZeros(result);
|
|
127
|
+
return applyFormatting(finalValue, { minLength, prepend, append });
|
|
65
128
|
};
|
|
129
|
+
exports.nextGeneratedString = nextGeneratedString;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drapcode-utility",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"@types/mime-types": "^2.1.4",
|
|
27
27
|
"@types/uuid": "^9.0.8",
|
|
28
28
|
"del-cli": "^5.0.0",
|
|
29
|
-
"typescript": "^
|
|
29
|
+
"typescript": "^5.3.3",
|
|
30
|
+
"ts-loader": "^9.5.1"
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
32
33
|
"@aws-sdk/client-kms": "^3.540.0",
|
|
@@ -39,10 +40,11 @@
|
|
|
39
40
|
"@types/voca": "^1.4.2",
|
|
40
41
|
"aws4": "^1.13.2",
|
|
41
42
|
"axios": "^1.1.2",
|
|
43
|
+
"date-fns": "^4.1.0",
|
|
42
44
|
"dompurify": "^3.1.7",
|
|
43
|
-
"drapcode-constant": "^1.7.
|
|
44
|
-
"drapcode-logger": "^1.3.
|
|
45
|
-
"drapcode-redis": "^1.2.
|
|
45
|
+
"drapcode-constant": "^1.7.3",
|
|
46
|
+
"drapcode-logger": "^1.3.5",
|
|
47
|
+
"drapcode-redis": "^1.2.8",
|
|
46
48
|
"exiftool-vendored": "^28.2.1",
|
|
47
49
|
"express": "^4.17.1",
|
|
48
50
|
"gm": "^1.25.0",
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.interceptLoggerNew = void 0;
|
|
7
|
-
var drapcode_logger_1 = require("drapcode-logger");
|
|
8
|
-
var date_util_1 = require("../utils/date-util");
|
|
9
|
-
var fs_1 = __importDefault(require("fs"));
|
|
10
|
-
var interceptLoggerNew = function (req, res, next) {
|
|
11
|
-
var todayFilePath = "/tmp/log";
|
|
12
|
-
var loggerPath = process.env.LOG_FOLDER_PATH || todayFilePath;
|
|
13
|
-
var originalUrl = req.originalUrl, method = req.method, body = req.body, params = req.params, query = req.query, db = req.db, projectName = req.projectName, projectId = req.projectId, ip = req.ip;
|
|
14
|
-
var reqObject = {
|
|
15
|
-
uri: originalUrl,
|
|
16
|
-
method: method,
|
|
17
|
-
body: body,
|
|
18
|
-
params: params,
|
|
19
|
-
query: query,
|
|
20
|
-
dbName: "",
|
|
21
|
-
message: "",
|
|
22
|
-
line: "",
|
|
23
|
-
ip: ip,
|
|
24
|
-
};
|
|
25
|
-
if (db) {
|
|
26
|
-
reqObject["dbName"] = db.name;
|
|
27
|
-
}
|
|
28
|
-
var PreviouseFilePath;
|
|
29
|
-
if (projectName) {
|
|
30
|
-
loggerPath = "".concat(loggerPath, "/").concat(projectName, "/").concat((0, date_util_1.createLoggerDateFormat)(), "/output");
|
|
31
|
-
PreviouseFilePath = "".concat(loggerPath, "/").concat(projectName, "/").concat((0, date_util_1.createLoggerPreviouseDateFormat)(), "/");
|
|
32
|
-
}
|
|
33
|
-
else if (projectId) {
|
|
34
|
-
loggerPath = "".concat(loggerPath, "/").concat(projectId, "/").concat((0, date_util_1.createLoggerDateFormat)(), "/output");
|
|
35
|
-
PreviouseFilePath = "".concat(loggerPath, "/").concat(projectId, "/").concat((0, date_util_1.createLoggerPreviouseDateFormat)(), "/");
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
loggerPath = "".concat(loggerPath, "/").concat((0, date_util_1.createLoggerDateFormat)(), "/output");
|
|
39
|
-
PreviouseFilePath = "".concat(loggerPath, "/").concat((0, date_util_1.createLoggerPreviouseDateFormat)(), "/");
|
|
40
|
-
}
|
|
41
|
-
if (fs_1.default.existsSync(PreviouseFilePath)) {
|
|
42
|
-
fs_1.default.rmSync(PreviouseFilePath, { recursive: true, force: true });
|
|
43
|
-
}
|
|
44
|
-
var logger = new drapcode_logger_1.FileLogger(loggerPath).createLogger();
|
|
45
|
-
var oldSend = res.send;
|
|
46
|
-
res.send = function (data) {
|
|
47
|
-
logger.info(data);
|
|
48
|
-
oldSend.apply(res, arguments);
|
|
49
|
-
// saveRequest(req, data);
|
|
50
|
-
};
|
|
51
|
-
next();
|
|
52
|
-
};
|
|
53
|
-
exports.interceptLoggerNew = interceptLoggerNew;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.interceptLogger = void 0;
|
|
4
|
-
var interceptLogger = function (req, res, next) {
|
|
5
|
-
return next();
|
|
6
|
-
/**
|
|
7
|
-
let loggerPath = process.env.LOG_FOLDER_PATH || "/tmp/logs";
|
|
8
|
-
const {
|
|
9
|
-
originalUrl,
|
|
10
|
-
method,
|
|
11
|
-
body,
|
|
12
|
-
params,
|
|
13
|
-
query,
|
|
14
|
-
db,
|
|
15
|
-
projectName,
|
|
16
|
-
projectId,
|
|
17
|
-
ip,
|
|
18
|
-
} = req;
|
|
19
|
-
|
|
20
|
-
const reqObject = {
|
|
21
|
-
uri: originalUrl,
|
|
22
|
-
method,
|
|
23
|
-
body,
|
|
24
|
-
params,
|
|
25
|
-
query,
|
|
26
|
-
dbName: "",
|
|
27
|
-
message: "",
|
|
28
|
-
line: "",
|
|
29
|
-
ip,
|
|
30
|
-
};
|
|
31
|
-
if (db) {
|
|
32
|
-
reqObject["dbName"] = db.name;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (projectName) {
|
|
36
|
-
loggerPath = `${loggerPath}/${projectName}/${createLoggerDateFormat()}`;
|
|
37
|
-
} else if (projectId) {
|
|
38
|
-
loggerPath = `${loggerPath}/${projectId}/${createLoggerDateFormat()}`;
|
|
39
|
-
} else {
|
|
40
|
-
loggerPath = `${loggerPath}/${createLoggerDateFormat()}`;
|
|
41
|
-
}
|
|
42
|
-
const logger = new FileLogger(loggerPath).createLogger();
|
|
43
|
-
let oldSend = res.send;
|
|
44
|
-
res.send = function (data: any) {
|
|
45
|
-
logger.info(data);
|
|
46
|
-
oldSend.apply(res, arguments);
|
|
47
|
-
// saveRequest(req, data);
|
|
48
|
-
};
|
|
49
|
-
next();
|
|
50
|
-
*/
|
|
51
|
-
};
|
|
52
|
-
exports.interceptLogger = interceptLogger;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const queryParserNew: (collectionName: string, query: any, constants: any[], externalParams: any, currentUser: any, timezone: string, searchObj?: any, refCollectionFieldsInItems?: any, searchQueryTypeObj?: any, lookupConfig?: any) => Promise<any>;
|