drapcode-utility 1.5.6 → 1.5.7
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 +1 -1
- package/build/encryption/crypt.js +3 -3
- package/build/encryption/file.js +4 -4
- package/build/encryption/index.js +26 -22
- package/build/encryption/model.d.ts +2 -2
- package/build/encryption/utility.js +11 -7
- package/build/format-fields/index.d.ts +2 -0
- package/build/format-fields/index.js +72 -3
- package/build/index.js +5 -1
- package/build/middlewares/error-logger.js +6 -6
- package/build/middlewares/interceptor-logger-new.js +6 -6
- package/build/middlewares/interceptor-logger.js +3 -3
- package/build/middlewares/redis/request-log.js +4 -4
- package/build/utils/check-error.js +12 -8
- package/build/utils/date-util.js +3 -3
- package/build/utils/prepare-query.js +9 -9
- package/build/utils/query-parser.js +54 -50
- package/build/utils/query-paser-new.js +48 -44
- package/build/utils/s3-util.d.ts +2 -0
- package/build/utils/s3-util.js +138 -26
- package/build/utils/token.js +3 -3
- package/build/utils/util.d.ts +1 -1
- package/build/utils/util.js +44 -40
- package/build/utils/uuid-generator.js +2 -2
- package/package.json +8 -2
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -35,10 +35,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
39
|
-
for (var i = 0,
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
+
if (ar || !(i in from)) {
|
|
41
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
+
ar[i] = from[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
42
46
|
};
|
|
43
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
48
|
exports.queryParserNew = void 0;
|
|
@@ -83,11 +87,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
83
87
|
if (searchQueryTypeObj[key]) {
|
|
84
88
|
aggregateQuery.push({
|
|
85
89
|
$addFields: (_b = {},
|
|
86
|
-
_b["_"
|
|
90
|
+
_b["_".concat(key)] = { $toString: "$".concat(key) },
|
|
87
91
|
_b),
|
|
88
92
|
});
|
|
89
93
|
searchQueryObj_1.push((_c = {},
|
|
90
|
-
_c["_"
|
|
94
|
+
_c["_".concat(key)] = {
|
|
91
95
|
$regex: value,
|
|
92
96
|
$options: "i",
|
|
93
97
|
},
|
|
@@ -121,11 +125,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
121
125
|
// if input is string and db field type is boolean
|
|
122
126
|
aggregateQuery.push({
|
|
123
127
|
$addFields: (_b = {},
|
|
124
|
-
_b["_"
|
|
128
|
+
_b["_".concat(key)] = "$".concat(key),
|
|
125
129
|
_b),
|
|
126
130
|
});
|
|
127
131
|
likeQuery_1.push((_c = {},
|
|
128
|
-
_c["_"
|
|
132
|
+
_c["_".concat(key)] = toBoolean(value),
|
|
129
133
|
_c));
|
|
130
134
|
}
|
|
131
135
|
else if ([
|
|
@@ -137,22 +141,22 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
137
141
|
// if input is string and db field type is array
|
|
138
142
|
aggregateQuery.push({
|
|
139
143
|
$addFields: (_d = {},
|
|
140
|
-
_d["_"
|
|
144
|
+
_d["_".concat(key)] = "$".concat(key),
|
|
141
145
|
_d),
|
|
142
146
|
});
|
|
143
147
|
likeQuery_1.push((_e = {},
|
|
144
|
-
_e["_"
|
|
148
|
+
_e["_".concat(key)] = { $all: [value] },
|
|
145
149
|
_e));
|
|
146
150
|
}
|
|
147
151
|
else if (searchQueryTypeObj[key] === "tel") {
|
|
148
152
|
// handling value when db field type is tel
|
|
149
153
|
aggregateQuery.push({
|
|
150
154
|
$addFields: (_f = {},
|
|
151
|
-
_f["_"
|
|
155
|
+
_f["_".concat(key)] = { $toString: "$".concat(key) },
|
|
152
156
|
_f),
|
|
153
157
|
});
|
|
154
158
|
likeQuery_1.push((_g = {},
|
|
155
|
-
_g["_"
|
|
159
|
+
_g["_".concat(key)] = {
|
|
156
160
|
$regex: value.startsWith("+") ? value.replace("+", "") : value,
|
|
157
161
|
$options: "i",
|
|
158
162
|
},
|
|
@@ -162,11 +166,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
162
166
|
// handling value when db field type is Double/Int
|
|
163
167
|
aggregateQuery.push({
|
|
164
168
|
$addFields: (_h = {},
|
|
165
|
-
_h["_"
|
|
169
|
+
_h["_".concat(key)] = { $toString: { $toLong: "$".concat(key) } },
|
|
166
170
|
_h),
|
|
167
171
|
});
|
|
168
172
|
likeQuery_1.push((_j = {},
|
|
169
|
-
_j["_"
|
|
173
|
+
_j["_".concat(key)] = {
|
|
170
174
|
$regex: value,
|
|
171
175
|
$options: "i",
|
|
172
176
|
},
|
|
@@ -177,11 +181,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
177
181
|
// converting db field to string first
|
|
178
182
|
aggregateQuery.push({
|
|
179
183
|
$addFields: (_k = {},
|
|
180
|
-
_k["_"
|
|
184
|
+
_k["_".concat(key)] = { $toString: "$".concat(key) },
|
|
181
185
|
_k),
|
|
182
186
|
});
|
|
183
187
|
likeQuery_1.push((_l = {},
|
|
184
|
-
_l["_"
|
|
188
|
+
_l["_".concat(key)] = {
|
|
185
189
|
$regex: value,
|
|
186
190
|
$options: "i",
|
|
187
191
|
},
|
|
@@ -206,14 +210,14 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
206
210
|
finder = query.finder, sortBy = query.sortBy, orderBy = query.orderBy, aggregateFunctionField = query.aggregateFunctionField;
|
|
207
211
|
if (!(finder != "COUNT" && refCollectionFieldsInItems)) return [3 /*break*/, 2];
|
|
208
212
|
return [4 /*yield*/, Promise.all(refCollectionFieldsInItems.map(function (field) {
|
|
209
|
-
return prepare_query_1.commonLookupSetting(field, lookupConfig, aggregateQuery);
|
|
213
|
+
return (0, prepare_query_1.commonLookupSetting)(field, lookupConfig, aggregateQuery);
|
|
210
214
|
}))];
|
|
211
215
|
case 1:
|
|
212
216
|
_b.sent();
|
|
213
217
|
_b.label = 2;
|
|
214
218
|
case 2:
|
|
215
219
|
if (!["COUNT", "SUM", "AVG", "MIN", "MAX"].includes(finder) &&
|
|
216
|
-
!util_1.isEmpty(projection)) {
|
|
220
|
+
!(0, util_1.isEmpty)(projection)) {
|
|
217
221
|
aggregateQuery.push({ $project: projection });
|
|
218
222
|
}
|
|
219
223
|
if (finder === "COUNT") {
|
|
@@ -221,22 +225,22 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
221
225
|
}
|
|
222
226
|
else if (finder === "SUM") {
|
|
223
227
|
aggregateQuery.push({
|
|
224
|
-
$group: { _id: null, total: { $sum: "$"
|
|
228
|
+
$group: { _id: null, total: { $sum: "$".concat(aggregateFunctionField) } },
|
|
225
229
|
});
|
|
226
230
|
}
|
|
227
231
|
else if (finder === "AVG") {
|
|
228
232
|
aggregateQuery.push({
|
|
229
|
-
$group: { _id: null, average: { $avg: "$"
|
|
233
|
+
$group: { _id: null, average: { $avg: "$".concat(aggregateFunctionField) } },
|
|
230
234
|
});
|
|
231
235
|
}
|
|
232
236
|
else if (finder === "MIN") {
|
|
233
237
|
aggregateQuery.push({
|
|
234
|
-
$group: { _id: null, minimum: { $min: "$"
|
|
238
|
+
$group: { _id: null, minimum: { $min: "$".concat(aggregateFunctionField) } },
|
|
235
239
|
});
|
|
236
240
|
}
|
|
237
241
|
else if (finder === "MAX") {
|
|
238
242
|
aggregateQuery.push({
|
|
239
|
-
$group: { _id: null, maximum: { $max: "$"
|
|
243
|
+
$group: { _id: null, maximum: { $max: "$".concat(aggregateFunctionField) } },
|
|
240
244
|
});
|
|
241
245
|
}
|
|
242
246
|
offset = externalParams.offset || 0;
|
|
@@ -252,8 +256,8 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
252
256
|
if (finder != "COUNT" && limit) {
|
|
253
257
|
aggregateQuery.push({ $skip: +offset }, { $limit: +limit });
|
|
254
258
|
}
|
|
255
|
-
queryStr = ".aggregate("
|
|
256
|
-
str = "req.db.collection('"
|
|
259
|
+
queryStr = ".aggregate(".concat(JSON.stringify(aggregateQuery), ", { collation: { locale: \"en\" } })");
|
|
260
|
+
str = "req.db.collection('".concat(collectionName, "')").concat(queryStr);
|
|
257
261
|
str += ".toArray()";
|
|
258
262
|
return [2 /*return*/, str];
|
|
259
263
|
}
|
|
@@ -290,7 +294,7 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser)
|
|
|
290
294
|
filterQuery[lastKey].push(mongoQuery);
|
|
291
295
|
}
|
|
292
296
|
else {
|
|
293
|
-
filterQuery["$or"
|
|
297
|
+
filterQuery["$or".concat(index)] = [mongoQuery];
|
|
294
298
|
}
|
|
295
299
|
}
|
|
296
300
|
else if (queryObj.conjunctionType == "AND") {
|
|
@@ -299,11 +303,11 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser)
|
|
|
299
303
|
filterQuery[lastKey].push(mongoQuery);
|
|
300
304
|
}
|
|
301
305
|
else {
|
|
302
|
-
filterQuery["$and"
|
|
306
|
+
filterQuery["$and".concat(index)] = [mongoQuery];
|
|
303
307
|
}
|
|
304
308
|
}
|
|
305
309
|
else {
|
|
306
|
-
filterQuery["$or"
|
|
310
|
+
filterQuery["$or".concat(index)] = [mongoQuery];
|
|
307
311
|
}
|
|
308
312
|
});
|
|
309
313
|
console.log("==> *** filterQuery #2 :>> ", filterQuery);
|
|
@@ -319,15 +323,15 @@ var mongoSelectQuery = function (query) {
|
|
|
319
323
|
if (fieldsInclude[0] === "*") {
|
|
320
324
|
fieldsExclude.map(function (field) {
|
|
321
325
|
if (field)
|
|
322
|
-
return (projection[""
|
|
326
|
+
return (projection["".concat(field)] = 0);
|
|
323
327
|
});
|
|
324
328
|
}
|
|
325
329
|
else {
|
|
326
330
|
if (["FIND_ALL", "FIND"].includes(finder))
|
|
327
|
-
fieldsInclude = util_1.processFieldsInlcude(fieldsInclude);
|
|
331
|
+
fieldsInclude = (0, util_1.processFieldsInlcude)(fieldsInclude);
|
|
328
332
|
fieldsInclude.map(function (field) {
|
|
329
333
|
if (field)
|
|
330
|
-
return (projection[""
|
|
334
|
+
return (projection["".concat(field)] = 1);
|
|
331
335
|
});
|
|
332
336
|
}
|
|
333
337
|
return projection;
|
|
@@ -418,7 +422,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
418
422
|
return _r = {},
|
|
419
423
|
_r[field] = {
|
|
420
424
|
$gte: fieldValue,
|
|
421
|
-
$lt: new Date(date_util_1.nextDayDate(fieldValue)),
|
|
425
|
+
$lt: new Date((0, date_util_1.nextDayDate)(fieldValue)),
|
|
422
426
|
},
|
|
423
427
|
_r;
|
|
424
428
|
}
|
|
@@ -449,7 +453,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
449
453
|
return _z = {}, _z[field] = +fieldValue, _z;
|
|
450
454
|
}
|
|
451
455
|
console.log("Nothing match");
|
|
452
|
-
return _0 = {}, _0[field] = ""
|
|
456
|
+
return _0 = {}, _0[field] = "".concat(fieldValue), _0;
|
|
453
457
|
}
|
|
454
458
|
if (key == drapcode_constant_1.NOT_EQUAL)
|
|
455
459
|
return _1 = {},
|
|
@@ -515,11 +519,11 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
515
519
|
if (key === drapcode_constant_1.BETWEEN) {
|
|
516
520
|
var _a = getMinMaxValue(value), startValue_1 = _a.startValue, endValue_1 = _a.endValue, isInteger = _a.isInteger;
|
|
517
521
|
if (requiredExternal) {
|
|
518
|
-
startValue_1 = ""
|
|
519
|
-
endValue_1 = ""
|
|
522
|
+
startValue_1 = "".concat(externalParams[startValue_1]);
|
|
523
|
+
endValue_1 = "".concat(externalParams[endValue_1]);
|
|
520
524
|
}
|
|
521
525
|
else {
|
|
522
|
-
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) {
|
|
526
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant, true).some(function (cnst) {
|
|
523
527
|
return startValue_1.includes(cnst);
|
|
524
528
|
})) {
|
|
525
529
|
startValue_1 = getValueOfProjectConstant(startValue_1, currentUser);
|
|
@@ -527,7 +531,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
527
531
|
else {
|
|
528
532
|
startValue_1 = constants.filter(function (constant) { return constant.name == startValue_1; });
|
|
529
533
|
}
|
|
530
|
-
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) { return endValue_1.includes(cnst); })) {
|
|
534
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant, true).some(function (cnst) { return endValue_1.includes(cnst); })) {
|
|
531
535
|
endValue_1 = getValueOfProjectConstant(endValue_1, currentUser);
|
|
532
536
|
}
|
|
533
537
|
else {
|
|
@@ -544,10 +548,10 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
544
548
|
//TODO: Need to figure out the params should be treated as number/string
|
|
545
549
|
if (!isNaN(startValue_1)) {
|
|
546
550
|
console.log("I am Number");
|
|
547
|
-
return startValue_1
|
|
551
|
+
return "".concat(startValue_1, "---").concat(endValue_1, "^");
|
|
548
552
|
}
|
|
549
553
|
else
|
|
550
|
-
return startValue_1
|
|
554
|
+
return "".concat(startValue_1, "---").concat(endValue_1);
|
|
551
555
|
}
|
|
552
556
|
if (value.includes(drapcode_constant_1.CURRENT_USER)) {
|
|
553
557
|
if (value === drapcode_constant_1.CURRENT_USER) {
|
|
@@ -585,11 +589,11 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
585
589
|
//TODO: This is just to confirm if external then it should be get from externalParams
|
|
586
590
|
if (requiredExternal) {
|
|
587
591
|
//TODO: Value returns from here undefined.
|
|
588
|
-
var externalParamValue = externalParams[""
|
|
592
|
+
var externalParamValue = externalParams["".concat(value)];
|
|
589
593
|
if (!isNaN(externalParamValue)) {
|
|
590
594
|
return +externalParamValue;
|
|
591
595
|
}
|
|
592
|
-
return externalParams[""
|
|
596
|
+
return externalParams["".concat(value)];
|
|
593
597
|
}
|
|
594
598
|
var constantArr = constants.filter(function (constant) { return constant.name == value; });
|
|
595
599
|
return constantArr.length ? "" + constantArr[0].value : "";
|
|
@@ -616,9 +620,9 @@ var getValueOfProjectConstant = function (value, currentUser) {
|
|
|
616
620
|
if (value === drapcode_constant_1.CURRENT_USER)
|
|
617
621
|
return currentUser["uuid"];
|
|
618
622
|
if (value === drapcode_constant_1.CURRENT_DATE)
|
|
619
|
-
return date_util_1.createLoggerDateFormat();
|
|
623
|
+
return (0, date_util_1.createLoggerDateFormat)();
|
|
620
624
|
if ([drapcode_constant_1.CURRENT_TIME, drapcode_constant_1.CURRENT_DATE_TIME].includes(value))
|
|
621
|
-
return date_util_1.createLogsDateFormat();
|
|
625
|
+
return (0, date_util_1.createLogsDateFormat)();
|
|
622
626
|
if (drapcode_constant_1.DateTimeUnit.some(function (cnst) { return value.includes(cnst); }))
|
|
623
|
-
return date_util_1.getDateValue(value);
|
|
627
|
+
return (0, date_util_1.getDateValue)(value);
|
|
624
628
|
};
|
package/build/utils/s3-util.d.ts
CHANGED
|
@@ -35,4 +35,6 @@ export declare const fileUploadToS3: (files: any, s3Client: S3Client, s3Config:
|
|
|
35
35
|
mediumIcon: string | null;
|
|
36
36
|
largeIcon: string | null;
|
|
37
37
|
}[] | null>;
|
|
38
|
+
export declare const processAndRemoveExifDataFromImg: (files: any) => Promise<any>;
|
|
39
|
+
export declare const processAndRemoveScriptFromSVG: (files: any) => Promise<void>;
|
|
38
40
|
export {};
|
package/build/utils/s3-util.js
CHANGED
|
@@ -25,7 +25,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
25
25
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
26
|
function step(op) {
|
|
27
27
|
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
29
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
30
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
31
|
switch (op[0]) {
|
|
@@ -50,7 +50,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
50
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.fileUploadToS3 = exports.createS3Client = void 0;
|
|
53
|
+
exports.processAndRemoveScriptFromSVG = exports.processAndRemoveExifDataFromImg = exports.fileUploadToS3 = exports.createS3Client = void 0;
|
|
54
54
|
var client_s3_1 = require("@aws-sdk/client-s3");
|
|
55
55
|
var fs_1 = __importDefault(require("fs"));
|
|
56
56
|
var mime_types_1 = __importDefault(require("mime-types"));
|
|
@@ -59,6 +59,10 @@ var encryption_1 = require("../encryption");
|
|
|
59
59
|
var encryption_2 = require("../encryption");
|
|
60
60
|
var uuid_1 = require("uuid");
|
|
61
61
|
var gm_1 = __importDefault(require("gm"));
|
|
62
|
+
var svgo_1 = require("svgo");
|
|
63
|
+
var promises_1 = __importDefault(require("fs/promises"));
|
|
64
|
+
var exiftool_vendored_1 = require("exiftool-vendored");
|
|
65
|
+
var exiftool = new exiftool_vendored_1.ExifTool({});
|
|
62
66
|
var createS3Client = function (awsConfig) {
|
|
63
67
|
if (!awsConfig) {
|
|
64
68
|
return null;
|
|
@@ -77,9 +81,9 @@ exports.createS3Client = createS3Client;
|
|
|
77
81
|
var fileUploadToS3 = function (files, s3Client, s3Config, publicS3Client, publicS3Config, isGenerateIcons, encryption, options) {
|
|
78
82
|
if (options === void 0) { options = {}; }
|
|
79
83
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
80
|
-
var awsConfig, encryptionType, dataKey, accessKeyId, secretAccessKey, region, config, plainTextData, fileOptions, s3Key, _a, _b, _i, index, file, fileSlug, fileObj, fileSlug, fileObj;
|
|
81
|
-
return __generator(this, function (
|
|
82
|
-
switch (
|
|
84
|
+
var awsConfig, encryptionType, dataKey, accessKeyId, secretAccessKey, region, config, plainTextData, fileOptions, s3Key, _a, _b, _c, _i, index, file, fileSlug, fileObj, fileSlug, fileObj;
|
|
85
|
+
return __generator(this, function (_d) {
|
|
86
|
+
switch (_d.label) {
|
|
83
87
|
case 0:
|
|
84
88
|
if (!encryption) return [3 /*break*/, 2];
|
|
85
89
|
awsConfig = encryption.awsConfig, encryptionType = encryption.encryptionType, dataKey = encryption.dataKey;
|
|
@@ -90,27 +94,30 @@ var fileUploadToS3 = function (files, s3Client, s3Config, publicS3Client, public
|
|
|
90
94
|
accessKeyId: accessKeyId,
|
|
91
95
|
secretAccessKey: secretAccessKey,
|
|
92
96
|
};
|
|
93
|
-
return [4 /*yield*/, encryption_2.processKMSDecryption(config, dataKey, {})];
|
|
97
|
+
return [4 /*yield*/, (0, encryption_2.processKMSDecryption)(config, dataKey, {})];
|
|
94
98
|
case 1:
|
|
95
|
-
plainTextData =
|
|
99
|
+
plainTextData = _d.sent();
|
|
96
100
|
if (plainTextData.status === "FAILED") {
|
|
97
101
|
return [2 /*return*/, plainTextData];
|
|
98
102
|
}
|
|
99
103
|
encryption.dataKey = plainTextData.data;
|
|
100
|
-
|
|
104
|
+
_d.label = 2;
|
|
101
105
|
case 2:
|
|
102
106
|
if (!Array.isArray(files)) return [3 /*break*/, 7];
|
|
103
107
|
console.log("I have multiple file");
|
|
104
108
|
fileOptions = [];
|
|
105
109
|
s3Key = s3Config.key;
|
|
106
|
-
_a =
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
_a = files;
|
|
111
|
+
_b = [];
|
|
112
|
+
for (_c in _a)
|
|
113
|
+
_b.push(_c);
|
|
109
114
|
_i = 0;
|
|
110
|
-
|
|
115
|
+
_d.label = 3;
|
|
111
116
|
case 3:
|
|
112
|
-
if (!(_i <
|
|
113
|
-
|
|
117
|
+
if (!(_i < _b.length)) return [3 /*break*/, 6];
|
|
118
|
+
_c = _b[_i];
|
|
119
|
+
if (!(_c in _a)) return [3 /*break*/, 5];
|
|
120
|
+
index = _c;
|
|
114
121
|
file = files[index];
|
|
115
122
|
fileSlug = file.originalname
|
|
116
123
|
.replace(/\.[^/.]+$/, "")
|
|
@@ -118,15 +125,15 @@ var fileUploadToS3 = function (files, s3Client, s3Config, publicS3Client, public
|
|
|
118
125
|
.replace(/[^a-zA-Z0-9_]/g, "")
|
|
119
126
|
.toLowerCase();
|
|
120
127
|
if (s3Config.append) {
|
|
121
|
-
s3Config.key = s3Key
|
|
128
|
+
s3Config.key = "".concat(s3Key, "/").concat((0, uuid_1.v4)(), "/").concat(fileSlug);
|
|
122
129
|
}
|
|
123
130
|
return [4 /*yield*/, processFileUploadToS3(file, s3Client, s3Config, publicS3Client, publicS3Config, isGenerateIcons, encryption, options, encryption ? true : false)];
|
|
124
131
|
case 4:
|
|
125
|
-
fileObj =
|
|
132
|
+
fileObj = _d.sent();
|
|
126
133
|
if (fileObj) {
|
|
127
134
|
fileOptions.push(fileObj);
|
|
128
135
|
}
|
|
129
|
-
|
|
136
|
+
_d.label = 5;
|
|
130
137
|
case 5:
|
|
131
138
|
_i++;
|
|
132
139
|
return [3 /*break*/, 3];
|
|
@@ -139,11 +146,11 @@ var fileUploadToS3 = function (files, s3Client, s3Config, publicS3Client, public
|
|
|
139
146
|
.replace(/[^a-zA-Z0-9_]/g, "")
|
|
140
147
|
.toLowerCase();
|
|
141
148
|
if (s3Config.append) {
|
|
142
|
-
s3Config.key = s3Config.key
|
|
149
|
+
s3Config.key = "".concat(s3Config.key, "/").concat((0, uuid_1.v4)(), "/").concat(fileSlug);
|
|
143
150
|
}
|
|
144
151
|
return [4 /*yield*/, processFileUploadToS3(files, s3Client, s3Config, publicS3Client, publicS3Config, isGenerateIcons, encryption, options, encryption ? true : false)];
|
|
145
152
|
case 8:
|
|
146
|
-
fileObj =
|
|
153
|
+
fileObj = _d.sent();
|
|
147
154
|
return [2 /*return*/, fileObj];
|
|
148
155
|
}
|
|
149
156
|
});
|
|
@@ -164,7 +171,7 @@ var processFileUploadToS3 = function (file, s3Client, s3Config, publicS3Client,
|
|
|
164
171
|
params = null;
|
|
165
172
|
encryptedFilePath = null;
|
|
166
173
|
if (!encrypt) return [3 /*break*/, 2];
|
|
167
|
-
return [4 /*yield*/, encryption_1.cryptFile(file.path, encryption, false)];
|
|
174
|
+
return [4 /*yield*/, (0, encryption_1.cryptFile)(file.path, encryption, false)];
|
|
168
175
|
case 1:
|
|
169
176
|
encryptedFilePath = _b.sent();
|
|
170
177
|
params = __assign({ Bucket: bucket, ACL: acl, Key: key, Body: fs_1.default.createReadStream(encryptedFilePath), ContentType: contentType }, options);
|
|
@@ -206,6 +213,111 @@ var processFileUploadToS3 = function (file, s3Client, s3Config, publicS3Client,
|
|
|
206
213
|
});
|
|
207
214
|
});
|
|
208
215
|
};
|
|
216
|
+
var imageTypeFiles = ["image/png", "image/jpeg", "image/jpg"];
|
|
217
|
+
var processAndRemoveExifDataFromImg = function (files) { return __awaiter(void 0, void 0, void 0, function () {
|
|
218
|
+
var promises, error_2;
|
|
219
|
+
return __generator(this, function (_a) {
|
|
220
|
+
switch (_a.label) {
|
|
221
|
+
case 0:
|
|
222
|
+
_a.trys.push([0, 3, , 4]);
|
|
223
|
+
files = Array.isArray(files) ? files : [files];
|
|
224
|
+
files = files.filter(function (file) { return imageTypeFiles.includes(file.mimetype); });
|
|
225
|
+
promises = [];
|
|
226
|
+
if (!files.length) return [3 /*break*/, 2];
|
|
227
|
+
promises = files.map(function (file) { return __awaiter(void 0, void 0, void 0, function () {
|
|
228
|
+
return __generator(this, function (_a) {
|
|
229
|
+
switch (_a.label) {
|
|
230
|
+
case 0: return [4 /*yield*/, exiftool
|
|
231
|
+
.write(file.path, {}, { writeArgs: ["-all=", "-overwrite_original"] })
|
|
232
|
+
.catch(function (err) {
|
|
233
|
+
console.error("Error processing image:", err);
|
|
234
|
+
throw err;
|
|
235
|
+
})];
|
|
236
|
+
case 1:
|
|
237
|
+
// Remove EXIF data using exiftool
|
|
238
|
+
return [2 /*return*/, _a.sent()];
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}); });
|
|
242
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
243
|
+
case 1:
|
|
244
|
+
_a.sent();
|
|
245
|
+
_a.label = 2;
|
|
246
|
+
case 2: return [2 /*return*/, promises];
|
|
247
|
+
case 3:
|
|
248
|
+
error_2 = _a.sent();
|
|
249
|
+
console.log("\n error :>> ", error_2);
|
|
250
|
+
return [3 /*break*/, 4];
|
|
251
|
+
case 4: return [2 /*return*/];
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}); };
|
|
255
|
+
exports.processAndRemoveExifDataFromImg = processAndRemoveExifDataFromImg;
|
|
256
|
+
var processAndRemoveScriptFromSVG = function (files) { return __awaiter(void 0, void 0, void 0, function () {
|
|
257
|
+
var promises, error_3;
|
|
258
|
+
return __generator(this, function (_a) {
|
|
259
|
+
switch (_a.label) {
|
|
260
|
+
case 0:
|
|
261
|
+
_a.trys.push([0, 3, , 4]);
|
|
262
|
+
files = Array.isArray(files) ? files : [files];
|
|
263
|
+
files = files.filter(function (file) { return file.mimetype === "image/svg+xml"; });
|
|
264
|
+
if (!files.length) return [3 /*break*/, 2];
|
|
265
|
+
promises = files.map(function (file) { return __awaiter(void 0, void 0, void 0, function () {
|
|
266
|
+
var fileContent, sanitizedContent;
|
|
267
|
+
return __generator(this, function (_a) {
|
|
268
|
+
switch (_a.label) {
|
|
269
|
+
case 0: return [4 /*yield*/, promises_1.default.readFile(file.path, "utf-8")];
|
|
270
|
+
case 1:
|
|
271
|
+
fileContent = _a.sent();
|
|
272
|
+
sanitizedContent = (0, svgo_1.optimize)(fileContent, {
|
|
273
|
+
plugins: [
|
|
274
|
+
"removeScriptElement",
|
|
275
|
+
"removeDesc",
|
|
276
|
+
"removeTitle",
|
|
277
|
+
"removeMetadata",
|
|
278
|
+
"removeComments",
|
|
279
|
+
"removeXMLProcInst",
|
|
280
|
+
"removeDoctype",
|
|
281
|
+
"cleanupAttrs",
|
|
282
|
+
{
|
|
283
|
+
name: "removeAttrs",
|
|
284
|
+
params: {
|
|
285
|
+
attrs: "(on.*)", // Matches attributes starting with "on" (e.g., onclick, onmouseover)
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
name: "removeForeignObject",
|
|
290
|
+
fn: function (item) {
|
|
291
|
+
if (item.name === "foreignObject") {
|
|
292
|
+
return null; // Remove this element
|
|
293
|
+
}
|
|
294
|
+
else
|
|
295
|
+
return item;
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
],
|
|
299
|
+
});
|
|
300
|
+
return [4 /*yield*/, promises_1.default.writeFile(file.path, sanitizedContent.data, "utf-8")];
|
|
301
|
+
case 2:
|
|
302
|
+
_a.sent();
|
|
303
|
+
return [2 /*return*/];
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}); });
|
|
307
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
308
|
+
case 1:
|
|
309
|
+
_a.sent();
|
|
310
|
+
_a.label = 2;
|
|
311
|
+
case 2: return [3 /*break*/, 4];
|
|
312
|
+
case 3:
|
|
313
|
+
error_3 = _a.sent();
|
|
314
|
+
console.log("\n error :>> ", error_3);
|
|
315
|
+
return [3 /*break*/, 4];
|
|
316
|
+
case 4: return [2 /*return*/];
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
}); };
|
|
320
|
+
exports.processAndRemoveScriptFromSVG = processAndRemoveScriptFromSVG;
|
|
209
321
|
var handleIconUpload = function (file, contentType, publicS3Client, publicS3Config, isGenerateIcons, key, options) {
|
|
210
322
|
if (options === void 0) { options = {}; }
|
|
211
323
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -232,7 +344,7 @@ var handleIconUpload = function (file, contentType, publicS3Client, publicS3Conf
|
|
|
232
344
|
switch (_a.label) {
|
|
233
345
|
case 0:
|
|
234
346
|
iconLabel = iconLabels[index];
|
|
235
|
-
iconKey = key
|
|
347
|
+
iconKey = "".concat(key, "/icons/").concat((0, uuid_1.v4)(), "_").concat(iconLabel, ".png");
|
|
236
348
|
iconParams = __assign({ Bucket: bucket_1, ACL: acl_1, Key: iconKey, Body: fs_1.default.createReadStream(iconFilePath), ContentType: "image/png" }, options);
|
|
237
349
|
iconUpload = new lib_storage_1.Upload({
|
|
238
350
|
client: publicS3Client,
|
|
@@ -251,13 +363,13 @@ var handleIconUpload = function (file, contentType, publicS3Client, publicS3Conf
|
|
|
251
363
|
_a = _b.sent(), smallKey = _a[0], mediumKey = _a[1], largeKey = _a[2];
|
|
252
364
|
return [2 /*return*/, {
|
|
253
365
|
smallIcon: smallKey
|
|
254
|
-
? "https://"
|
|
366
|
+
? "https://".concat(bucket_1, ".s3.amazonaws.com/").concat(smallKey)
|
|
255
367
|
: null,
|
|
256
368
|
mediumIcon: mediumKey
|
|
257
|
-
? "https://"
|
|
369
|
+
? "https://".concat(bucket_1, ".s3.amazonaws.com/").concat(mediumKey)
|
|
258
370
|
: null,
|
|
259
371
|
largeIcon: largeKey
|
|
260
|
-
? "https://"
|
|
372
|
+
? "https://".concat(bucket_1, ".s3.amazonaws.com/").concat(largeKey)
|
|
261
373
|
: null,
|
|
262
374
|
}];
|
|
263
375
|
case 4: return [2 /*return*/, generateStaticIcons(contentType)];
|
|
@@ -273,9 +385,9 @@ var handleIconUpload = function (file, contentType, publicS3Client, publicS3Conf
|
|
|
273
385
|
};
|
|
274
386
|
var generateDynamicIcons = function (filePath, sizes, contentType) {
|
|
275
387
|
return Promise.all(sizes.map(function (size) {
|
|
276
|
-
var outputFilePath = filePath
|
|
388
|
+
var outputFilePath = "".concat(filePath, "_").concat(size, ".png");
|
|
277
389
|
return new Promise(function (resolve, reject) {
|
|
278
|
-
var gmInstance = gm_1.default(filePath);
|
|
390
|
+
var gmInstance = (0, gm_1.default)(filePath);
|
|
279
391
|
if (contentType === "application/pdf") {
|
|
280
392
|
gmInstance = gmInstance.selectFrame(0);
|
|
281
393
|
}
|
package/build/utils/token.js
CHANGED
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -56,8 +56,8 @@ var generateToken = function (projectId) { return __awaiter(void 0, void 0, void
|
|
|
56
56
|
randomIndex = Math.floor(Math.random() * characters.length);
|
|
57
57
|
token += characters.charAt(randomIndex);
|
|
58
58
|
}
|
|
59
|
-
token = token
|
|
60
|
-
return [4 /*yield*/, drapcode_redis_1.redis_get_method(uniqueSessionId)];
|
|
59
|
+
token = "".concat(token, ".").concat(timestamp);
|
|
60
|
+
return [4 /*yield*/, (0, drapcode_redis_1.redis_get_method)(uniqueSessionId)];
|
|
61
61
|
case 2:
|
|
62
62
|
data = _b.sent();
|
|
63
63
|
if (!data || !data[projectId] || !data[projectId].length) {
|
package/build/utils/util.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const validateString: (str: string) => false | "String should not contain special characters" | "String should not contain any number";
|
|
2
2
|
export declare const camelize: (str: string) => string;
|
|
3
|
-
export declare const clearSpaceAndReformat: (text: string, separator?: string
|
|
3
|
+
export declare const clearSpaceAndReformat: (text: string, separator?: string) => string;
|
|
4
4
|
export declare const isEmpty: (obj: any) => boolean;
|
|
5
5
|
export declare const isEmptyObject: (object: any) => boolean;
|
|
6
6
|
export declare const isObject: (item: any) => any;
|