drapcode-utility 1.2.9 → 1.3.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/build/encryption/KMS.js +1 -1
- package/build/encryption/crypt.js +2 -2
- package/build/encryption/file.js +4 -4
- package/build/encryption/index.js +14 -14
- package/build/encryption/model.d.ts +2 -2
- 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.d.ts +11 -0
- package/build/utils/prepare-query.js +124 -1
- package/build/utils/query-parser.d.ts +1 -1
- package/build/utils/query-parser.js +56 -130
- package/build/utils/query-paser-new.d.ts +1 -1
- package/build/utils/query-paser-new.js +51 -126
- package/build/utils/s3-util.js +52 -32
- package/build/utils/util.d.ts +3 -2
- package/build/utils/util.js +98 -55
- package/build/utils/uuid-generator.js +2 -2
- package/package.json +4 -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,21 +35,27 @@ 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;
|
|
45
49
|
var drapcode_constant_1 = require("drapcode-constant");
|
|
46
50
|
var date_util_1 = require("./date-util");
|
|
47
51
|
var util_1 = require("./util");
|
|
48
|
-
var
|
|
52
|
+
var prepare_query_1 = require("./prepare-query");
|
|
53
|
+
var queryParserNew = function (collectionName, query, constants, externalParams, currentUser, timezone, searchObj, refCollectionFieldsInItems, searchQueryTypeObj, lookupConfig) {
|
|
49
54
|
if (currentUser === void 0) { currentUser = {}; }
|
|
50
55
|
if (searchObj === void 0) { searchObj = null; }
|
|
51
56
|
if (refCollectionFieldsInItems === void 0) { refCollectionFieldsInItems = null; }
|
|
52
57
|
if (searchQueryTypeObj === void 0) { searchQueryTypeObj = {}; }
|
|
58
|
+
if (lookupConfig === void 0) { lookupConfig = []; }
|
|
53
59
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
54
60
|
var filterQuery, aggregateQuery, queryStr, searchQueryObj_1, finalQuery, likeQuery_1, projection, finder, sortBy, orderBy, aggregateFunctionField, offset, limit, direction, str;
|
|
55
61
|
var _a;
|
|
@@ -64,7 +70,7 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
64
70
|
filterQuery = mongoFilterQuery(query, externalParams, constants, currentUser);
|
|
65
71
|
console.log("**************************");
|
|
66
72
|
console.log("**************************");
|
|
67
|
-
console.log("filterQuery", filterQuery);
|
|
73
|
+
console.log("filterQuery", JSON.stringify(filterQuery));
|
|
68
74
|
console.log("==> searchQueryTypeObj :>>", searchQueryTypeObj);
|
|
69
75
|
aggregateQuery = [];
|
|
70
76
|
queryStr = ".aggregate([])";
|
|
@@ -81,11 +87,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
81
87
|
if (searchQueryTypeObj[key]) {
|
|
82
88
|
aggregateQuery.push({
|
|
83
89
|
$addFields: (_b = {},
|
|
84
|
-
_b["_"
|
|
90
|
+
_b["_".concat(key)] = { $toString: "$".concat(key) },
|
|
85
91
|
_b),
|
|
86
92
|
});
|
|
87
93
|
searchQueryObj_1.push((_c = {},
|
|
88
|
-
_c["_"
|
|
94
|
+
_c["_".concat(key)] = {
|
|
89
95
|
$regex: value,
|
|
90
96
|
$options: "i",
|
|
91
97
|
},
|
|
@@ -119,11 +125,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
119
125
|
// if input is string and db field type is boolean
|
|
120
126
|
aggregateQuery.push({
|
|
121
127
|
$addFields: (_b = {},
|
|
122
|
-
_b["_"
|
|
128
|
+
_b["_".concat(key)] = "$".concat(key),
|
|
123
129
|
_b),
|
|
124
130
|
});
|
|
125
131
|
likeQuery_1.push((_c = {},
|
|
126
|
-
_c["_"
|
|
132
|
+
_c["_".concat(key)] = toBoolean(value),
|
|
127
133
|
_c));
|
|
128
134
|
}
|
|
129
135
|
else if ([
|
|
@@ -135,22 +141,22 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
135
141
|
// if input is string and db field type is array
|
|
136
142
|
aggregateQuery.push({
|
|
137
143
|
$addFields: (_d = {},
|
|
138
|
-
_d["_"
|
|
144
|
+
_d["_".concat(key)] = "$".concat(key),
|
|
139
145
|
_d),
|
|
140
146
|
});
|
|
141
147
|
likeQuery_1.push((_e = {},
|
|
142
|
-
_e["_"
|
|
148
|
+
_e["_".concat(key)] = { $all: [value] },
|
|
143
149
|
_e));
|
|
144
150
|
}
|
|
145
151
|
else if (searchQueryTypeObj[key] === "tel") {
|
|
146
152
|
// handling value when db field type is tel
|
|
147
153
|
aggregateQuery.push({
|
|
148
154
|
$addFields: (_f = {},
|
|
149
|
-
_f["_"
|
|
155
|
+
_f["_".concat(key)] = { $toString: "$".concat(key) },
|
|
150
156
|
_f),
|
|
151
157
|
});
|
|
152
158
|
likeQuery_1.push((_g = {},
|
|
153
|
-
_g["_"
|
|
159
|
+
_g["_".concat(key)] = {
|
|
154
160
|
$regex: value.startsWith("+") ? value.replace("+", "") : value,
|
|
155
161
|
$options: "i",
|
|
156
162
|
},
|
|
@@ -160,11 +166,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
160
166
|
// handling value when db field type is Double/Int
|
|
161
167
|
aggregateQuery.push({
|
|
162
168
|
$addFields: (_h = {},
|
|
163
|
-
_h["_"
|
|
169
|
+
_h["_".concat(key)] = { $toString: { $toLong: "$".concat(key) } },
|
|
164
170
|
_h),
|
|
165
171
|
});
|
|
166
172
|
likeQuery_1.push((_j = {},
|
|
167
|
-
_j["_"
|
|
173
|
+
_j["_".concat(key)] = {
|
|
168
174
|
$regex: value,
|
|
169
175
|
$options: "i",
|
|
170
176
|
},
|
|
@@ -175,11 +181,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
175
181
|
// converting db field to string first
|
|
176
182
|
aggregateQuery.push({
|
|
177
183
|
$addFields: (_k = {},
|
|
178
|
-
_k["_"
|
|
184
|
+
_k["_".concat(key)] = { $toString: "$".concat(key) },
|
|
179
185
|
_k),
|
|
180
186
|
});
|
|
181
187
|
likeQuery_1.push((_l = {},
|
|
182
|
-
_l["_"
|
|
188
|
+
_l["_".concat(key)] = {
|
|
183
189
|
$regex: value,
|
|
184
190
|
$options: "i",
|
|
185
191
|
},
|
|
@@ -197,7 +203,6 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
197
203
|
}
|
|
198
204
|
});
|
|
199
205
|
if (likeQuery_1.length) {
|
|
200
|
-
// aggregateQuery.push({ $match: { $or: likeQuery } });
|
|
201
206
|
aggregateQuery.push({ $match: { $and: likeQuery_1 } });
|
|
202
207
|
}
|
|
203
208
|
}
|
|
@@ -205,94 +210,14 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
205
210
|
finder = query.finder, sortBy = query.sortBy, orderBy = query.orderBy, aggregateFunctionField = query.aggregateFunctionField;
|
|
206
211
|
if (!(finder != "COUNT" && refCollectionFieldsInItems)) return [3 /*break*/, 2];
|
|
207
212
|
return [4 /*yield*/, Promise.all(refCollectionFieldsInItems.map(function (field) {
|
|
208
|
-
|
|
209
|
-
if (["reference", "multi_reference", "belongsTo"].includes(field.type)) {
|
|
210
|
-
var collectionName_1 = field.refCollection
|
|
211
|
-
? field.refCollection["collectionName"]
|
|
212
|
-
: null;
|
|
213
|
-
if (collectionName_1) {
|
|
214
|
-
if (field.type === "belongsTo") {
|
|
215
|
-
aggregateQuery.push({
|
|
216
|
-
$lookup: {
|
|
217
|
-
from: "" + collectionName_1,
|
|
218
|
-
localField: field.fieldName,
|
|
219
|
-
foreignField: "uuid",
|
|
220
|
-
as: field.fieldName,
|
|
221
|
-
},
|
|
222
|
-
});
|
|
223
|
-
aggregateQuery.push({
|
|
224
|
-
$addFields: (_a = {},
|
|
225
|
-
_a["_$belongsToMetaData"] = field,
|
|
226
|
-
_a),
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
aggregateQuery.push({
|
|
231
|
-
$lookup: {
|
|
232
|
-
from: "" + collectionName_1,
|
|
233
|
-
let: (_b = {}, _b["" + field.fieldName] = "$" + field.fieldName, _b),
|
|
234
|
-
pipeline: [
|
|
235
|
-
{
|
|
236
|
-
$match: {
|
|
237
|
-
$expr: {
|
|
238
|
-
$in: [
|
|
239
|
-
"$uuid",
|
|
240
|
-
{
|
|
241
|
-
$cond: {
|
|
242
|
-
if: {
|
|
243
|
-
$in: ["$$" + field.fieldName, ["", null]],
|
|
244
|
-
},
|
|
245
|
-
then: [],
|
|
246
|
-
else: { $ifNull: ["$$" + field.fieldName, []] },
|
|
247
|
-
},
|
|
248
|
-
},
|
|
249
|
-
],
|
|
250
|
-
},
|
|
251
|
-
},
|
|
252
|
-
},
|
|
253
|
-
{
|
|
254
|
-
$lookup: {
|
|
255
|
-
from: "user",
|
|
256
|
-
let: { createdBy: "$createdBy" },
|
|
257
|
-
pipeline: [
|
|
258
|
-
{
|
|
259
|
-
$match: {
|
|
260
|
-
$expr: { $eq: ["$uuid", "$$createdBy"] },
|
|
261
|
-
},
|
|
262
|
-
},
|
|
263
|
-
{ $project: { _id: 0, password: 0 } },
|
|
264
|
-
],
|
|
265
|
-
as: "createdBy",
|
|
266
|
-
},
|
|
267
|
-
},
|
|
268
|
-
],
|
|
269
|
-
as: field.fieldName,
|
|
270
|
-
},
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
if (field.type === "createdBy")
|
|
276
|
-
aggregateQuery.push({
|
|
277
|
-
$lookup: {
|
|
278
|
-
from: "user",
|
|
279
|
-
let: (_c = {}, _c["" + field.fieldName] = "$" + field.fieldName, _c),
|
|
280
|
-
pipeline: [
|
|
281
|
-
{
|
|
282
|
-
$match: { $expr: { $eq: ["$uuid", "$$" + field.fieldName] } },
|
|
283
|
-
},
|
|
284
|
-
{ $project: { _id: 0, password: 0 } },
|
|
285
|
-
],
|
|
286
|
-
as: field.fieldName,
|
|
287
|
-
},
|
|
288
|
-
});
|
|
213
|
+
return (0, prepare_query_1.commonLookupSetting)(field, lookupConfig, aggregateQuery);
|
|
289
214
|
}))];
|
|
290
215
|
case 1:
|
|
291
216
|
_b.sent();
|
|
292
217
|
_b.label = 2;
|
|
293
218
|
case 2:
|
|
294
219
|
if (!["COUNT", "SUM", "AVG", "MIN", "MAX"].includes(finder) &&
|
|
295
|
-
!util_1.isEmpty(projection)) {
|
|
220
|
+
!(0, util_1.isEmpty)(projection)) {
|
|
296
221
|
aggregateQuery.push({ $project: projection });
|
|
297
222
|
}
|
|
298
223
|
if (finder === "COUNT") {
|
|
@@ -300,22 +225,22 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
300
225
|
}
|
|
301
226
|
else if (finder === "SUM") {
|
|
302
227
|
aggregateQuery.push({
|
|
303
|
-
$group: { _id: null, total: { $sum: "$"
|
|
228
|
+
$group: { _id: null, total: { $sum: "$".concat(aggregateFunctionField) } },
|
|
304
229
|
});
|
|
305
230
|
}
|
|
306
231
|
else if (finder === "AVG") {
|
|
307
232
|
aggregateQuery.push({
|
|
308
|
-
$group: { _id: null, average: { $avg: "$"
|
|
233
|
+
$group: { _id: null, average: { $avg: "$".concat(aggregateFunctionField) } },
|
|
309
234
|
});
|
|
310
235
|
}
|
|
311
236
|
else if (finder === "MIN") {
|
|
312
237
|
aggregateQuery.push({
|
|
313
|
-
$group: { _id: null, minimum: { $min: "$"
|
|
238
|
+
$group: { _id: null, minimum: { $min: "$".concat(aggregateFunctionField) } },
|
|
314
239
|
});
|
|
315
240
|
}
|
|
316
241
|
else if (finder === "MAX") {
|
|
317
242
|
aggregateQuery.push({
|
|
318
|
-
$group: { _id: null, maximum: { $max: "$"
|
|
243
|
+
$group: { _id: null, maximum: { $max: "$".concat(aggregateFunctionField) } },
|
|
319
244
|
});
|
|
320
245
|
}
|
|
321
246
|
offset = externalParams.offset || 0;
|
|
@@ -331,8 +256,8 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
331
256
|
if (finder != "COUNT" && limit) {
|
|
332
257
|
aggregateQuery.push({ $skip: +offset }, { $limit: +limit });
|
|
333
258
|
}
|
|
334
|
-
queryStr = ".aggregate("
|
|
335
|
-
str = "req.db.collection('"
|
|
259
|
+
queryStr = ".aggregate(".concat(JSON.stringify(aggregateQuery), ", { collation: { locale: \"en\" } })");
|
|
260
|
+
str = "req.db.collection('".concat(collectionName, "')").concat(queryStr);
|
|
336
261
|
str += ".toArray()";
|
|
337
262
|
return [2 /*return*/, str];
|
|
338
263
|
}
|
|
@@ -369,7 +294,7 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser)
|
|
|
369
294
|
filterQuery[lastKey].push(mongoQuery);
|
|
370
295
|
}
|
|
371
296
|
else {
|
|
372
|
-
filterQuery["$or"
|
|
297
|
+
filterQuery["$or".concat(index)] = [mongoQuery];
|
|
373
298
|
}
|
|
374
299
|
}
|
|
375
300
|
else if (queryObj.conjunctionType == "AND") {
|
|
@@ -378,11 +303,11 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser)
|
|
|
378
303
|
filterQuery[lastKey].push(mongoQuery);
|
|
379
304
|
}
|
|
380
305
|
else {
|
|
381
|
-
filterQuery["$and"
|
|
306
|
+
filterQuery["$and".concat(index)] = [mongoQuery];
|
|
382
307
|
}
|
|
383
308
|
}
|
|
384
309
|
else {
|
|
385
|
-
filterQuery["$or"
|
|
310
|
+
filterQuery["$or".concat(index)] = [mongoQuery];
|
|
386
311
|
}
|
|
387
312
|
});
|
|
388
313
|
console.log("==> *** filterQuery #2 :>> ", filterQuery);
|
|
@@ -398,15 +323,15 @@ var mongoSelectQuery = function (query) {
|
|
|
398
323
|
if (fieldsInclude[0] === "*") {
|
|
399
324
|
fieldsExclude.map(function (field) {
|
|
400
325
|
if (field)
|
|
401
|
-
return (projection[""
|
|
326
|
+
return (projection["".concat(field)] = 0);
|
|
402
327
|
});
|
|
403
328
|
}
|
|
404
329
|
else {
|
|
405
330
|
if (["FIND_ALL", "FIND"].includes(finder))
|
|
406
|
-
fieldsInclude = util_1.processFieldsInlcude(fieldsInclude);
|
|
331
|
+
fieldsInclude = (0, util_1.processFieldsInlcude)(fieldsInclude);
|
|
407
332
|
fieldsInclude.map(function (field) {
|
|
408
333
|
if (field)
|
|
409
|
-
return (projection[""
|
|
334
|
+
return (projection["".concat(field)] = 1);
|
|
410
335
|
});
|
|
411
336
|
}
|
|
412
337
|
return projection;
|
|
@@ -497,7 +422,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
497
422
|
return _r = {},
|
|
498
423
|
_r[field] = {
|
|
499
424
|
$gte: fieldValue,
|
|
500
|
-
$lt: new Date(date_util_1.nextDayDate(fieldValue)),
|
|
425
|
+
$lt: new Date((0, date_util_1.nextDayDate)(fieldValue)),
|
|
501
426
|
},
|
|
502
427
|
_r;
|
|
503
428
|
}
|
|
@@ -591,11 +516,11 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
591
516
|
if (key === drapcode_constant_1.BETWEEN) {
|
|
592
517
|
var _a = getMinMaxValue(value), startValue_1 = _a.startValue, endValue_1 = _a.endValue, isInteger = _a.isInteger;
|
|
593
518
|
if (requiredExternal) {
|
|
594
|
-
startValue_1 = ""
|
|
595
|
-
endValue_1 = ""
|
|
519
|
+
startValue_1 = "".concat(externalParams[startValue_1]);
|
|
520
|
+
endValue_1 = "".concat(externalParams[endValue_1]);
|
|
596
521
|
}
|
|
597
522
|
else {
|
|
598
|
-
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) {
|
|
523
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant, true).some(function (cnst) {
|
|
599
524
|
return startValue_1.includes(cnst);
|
|
600
525
|
})) {
|
|
601
526
|
startValue_1 = getValueOfProjectConstant(startValue_1, currentUser);
|
|
@@ -603,7 +528,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
603
528
|
else {
|
|
604
529
|
startValue_1 = constants.filter(function (constant) { return constant.name == startValue_1; });
|
|
605
530
|
}
|
|
606
|
-
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) { return endValue_1.includes(cnst); })) {
|
|
531
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant, true).some(function (cnst) { return endValue_1.includes(cnst); })) {
|
|
607
532
|
endValue_1 = getValueOfProjectConstant(endValue_1, currentUser);
|
|
608
533
|
}
|
|
609
534
|
else {
|
|
@@ -620,10 +545,10 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
620
545
|
//TODO: Need to figure out the params should be treated as number/string
|
|
621
546
|
if (!isNaN(startValue_1)) {
|
|
622
547
|
console.log("I am Number");
|
|
623
|
-
return startValue_1
|
|
548
|
+
return "".concat(startValue_1, "---").concat(endValue_1, "^");
|
|
624
549
|
}
|
|
625
550
|
else
|
|
626
|
-
return startValue_1
|
|
551
|
+
return "".concat(startValue_1, "---").concat(endValue_1);
|
|
627
552
|
}
|
|
628
553
|
if (value.includes(drapcode_constant_1.CURRENT_USER)) {
|
|
629
554
|
if (value === drapcode_constant_1.CURRENT_USER) {
|
|
@@ -661,11 +586,11 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
661
586
|
//TODO: This is just to confirm if external then it should be get from externalParams
|
|
662
587
|
if (requiredExternal) {
|
|
663
588
|
//TODO: Value returns from here undefined.
|
|
664
|
-
var externalParamValue = externalParams[""
|
|
589
|
+
var externalParamValue = externalParams["".concat(value)];
|
|
665
590
|
if (!isNaN(externalParamValue)) {
|
|
666
591
|
return +externalParamValue;
|
|
667
592
|
}
|
|
668
|
-
return externalParams[""
|
|
593
|
+
return externalParams["".concat(value)];
|
|
669
594
|
}
|
|
670
595
|
var constantArr = constants.filter(function (constant) { return constant.name == value; });
|
|
671
596
|
return constantArr.length ? "" + constantArr[0].value : "";
|
|
@@ -692,9 +617,9 @@ var getValueOfProjectConstant = function (value, currentUser) {
|
|
|
692
617
|
if (value === drapcode_constant_1.CURRENT_USER)
|
|
693
618
|
return currentUser["uuid"];
|
|
694
619
|
if (value === drapcode_constant_1.CURRENT_DATE)
|
|
695
|
-
return date_util_1.createLoggerDateFormat();
|
|
620
|
+
return (0, date_util_1.createLoggerDateFormat)();
|
|
696
621
|
if ([drapcode_constant_1.CURRENT_TIME, drapcode_constant_1.CURRENT_DATE_TIME].includes(value))
|
|
697
|
-
return date_util_1.createLogsDateFormat();
|
|
622
|
+
return (0, date_util_1.createLogsDateFormat)();
|
|
698
623
|
if (drapcode_constant_1.DateTimeUnit.some(function (cnst) { return value.includes(cnst); }))
|
|
699
|
-
return date_util_1.getDateValue(value);
|
|
624
|
+
return (0, date_util_1.getDateValue)(value);
|
|
700
625
|
};
|
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]) {
|
|
@@ -57,6 +57,7 @@ var mime_types_1 = __importDefault(require("mime-types"));
|
|
|
57
57
|
var lib_storage_1 = require("@aws-sdk/lib-storage");
|
|
58
58
|
var encryption_1 = require("../encryption");
|
|
59
59
|
var encryption_2 = require("../encryption");
|
|
60
|
+
var uuid_1 = require("uuid");
|
|
60
61
|
var createS3Client = function (awsConfig) {
|
|
61
62
|
if (!awsConfig) {
|
|
62
63
|
return null;
|
|
@@ -75,9 +76,9 @@ exports.createS3Client = createS3Client;
|
|
|
75
76
|
var fileUploadToS3 = function (files, s3Client, s3Config, encryption, options) {
|
|
76
77
|
if (options === void 0) { options = {}; }
|
|
77
78
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
78
|
-
var awsConfig, encryptionType, dataKey, accessKeyId, secretAccessKey, region, config, plainTextData, fileOptions, s3Key, _a, _b, _i, index, file, fileObj, fileObj;
|
|
79
|
-
return __generator(this, function (
|
|
80
|
-
switch (
|
|
79
|
+
var awsConfig, encryptionType, dataKey, accessKeyId, secretAccessKey, region, config, plainTextData, fileOptions, s3Key, _a, _b, _c, _i, index, file, fileObj, fileObj;
|
|
80
|
+
return __generator(this, function (_d) {
|
|
81
|
+
switch (_d.label) {
|
|
81
82
|
case 0:
|
|
82
83
|
if (!encryption) return [3 /*break*/, 2];
|
|
83
84
|
awsConfig = encryption.awsConfig, encryptionType = encryption.encryptionType, dataKey = encryption.dataKey;
|
|
@@ -88,38 +89,41 @@ var fileUploadToS3 = function (files, s3Client, s3Config, encryption, options) {
|
|
|
88
89
|
accessKeyId: accessKeyId,
|
|
89
90
|
secretAccessKey: secretAccessKey,
|
|
90
91
|
};
|
|
91
|
-
return [4 /*yield*/, encryption_2.processKMSDecryption(config, dataKey, {})];
|
|
92
|
+
return [4 /*yield*/, (0, encryption_2.processKMSDecryption)(config, dataKey, {})];
|
|
92
93
|
case 1:
|
|
93
|
-
plainTextData =
|
|
94
|
+
plainTextData = _d.sent();
|
|
94
95
|
if (plainTextData.status === "FAILED") {
|
|
95
96
|
return [2 /*return*/, plainTextData];
|
|
96
97
|
}
|
|
97
98
|
encryption.dataKey = plainTextData.data;
|
|
98
|
-
|
|
99
|
+
_d.label = 2;
|
|
99
100
|
case 2:
|
|
100
101
|
if (!Array.isArray(files)) return [3 /*break*/, 7];
|
|
101
102
|
console.log("I have multiple file");
|
|
102
103
|
fileOptions = [];
|
|
103
104
|
s3Key = s3Config.key;
|
|
104
|
-
_a =
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
_a = files;
|
|
106
|
+
_b = [];
|
|
107
|
+
for (_c in _a)
|
|
108
|
+
_b.push(_c);
|
|
107
109
|
_i = 0;
|
|
108
|
-
|
|
110
|
+
_d.label = 3;
|
|
109
111
|
case 3:
|
|
110
|
-
if (!(_i <
|
|
111
|
-
|
|
112
|
+
if (!(_i < _b.length)) return [3 /*break*/, 6];
|
|
113
|
+
_c = _b[_i];
|
|
114
|
+
if (!(_c in _a)) return [3 /*break*/, 5];
|
|
115
|
+
index = _c;
|
|
112
116
|
file = files[index];
|
|
113
117
|
if (s3Config.append) {
|
|
114
|
-
s3Config.key = s3Key
|
|
118
|
+
s3Config.key = "".concat(s3Key, "/").concat((0, uuid_1.v4)(), "/").concat(file.originalname);
|
|
115
119
|
}
|
|
116
120
|
return [4 /*yield*/, processFileUploadToS3(file, s3Client, s3Config, encryption, options, encryption ? true : false)];
|
|
117
121
|
case 4:
|
|
118
|
-
fileObj =
|
|
122
|
+
fileObj = _d.sent();
|
|
119
123
|
if (fileObj) {
|
|
120
124
|
fileOptions.push(fileObj);
|
|
121
125
|
}
|
|
122
|
-
|
|
126
|
+
_d.label = 5;
|
|
123
127
|
case 5:
|
|
124
128
|
_i++;
|
|
125
129
|
return [3 /*break*/, 3];
|
|
@@ -127,11 +131,11 @@ var fileUploadToS3 = function (files, s3Client, s3Config, encryption, options) {
|
|
|
127
131
|
case 7:
|
|
128
132
|
console.log("I have single file");
|
|
129
133
|
if (s3Config.append) {
|
|
130
|
-
s3Config.key = s3Config.key
|
|
134
|
+
s3Config.key = "".concat(s3Config.key, "/").concat((0, uuid_1.v4)(), "/").concat(files.originalname);
|
|
131
135
|
}
|
|
132
136
|
return [4 /*yield*/, processFileUploadToS3(files, s3Client, s3Config, encryption, options, encryption ? true : false)];
|
|
133
137
|
case 8:
|
|
134
|
-
fileObj =
|
|
138
|
+
fileObj = _d.sent();
|
|
135
139
|
return [2 /*return*/, fileObj];
|
|
136
140
|
}
|
|
137
141
|
});
|
|
@@ -142,33 +146,49 @@ var processFileUploadToS3 = function (file, s3Client, s3Config, encryption, opti
|
|
|
142
146
|
if (options === void 0) { options = {}; }
|
|
143
147
|
if (encrypt === void 0) { encrypt = false; }
|
|
144
148
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
145
|
-
var contentType, acl, key, bucket, params,
|
|
149
|
+
var contentType, acl, key, bucket, params, encryptedFilePath, parallelUploads3, data, originalname, mimetype, size, finalObject, error_1;
|
|
146
150
|
return __generator(this, function (_a) {
|
|
147
151
|
switch (_a.label) {
|
|
148
152
|
case 0:
|
|
149
|
-
|
|
153
|
+
console.log("encryption processFileUploadToS3", encryption);
|
|
154
|
+
_a.label = 1;
|
|
155
|
+
case 1:
|
|
156
|
+
_a.trys.push([1, 6, , 7]);
|
|
150
157
|
contentType = mime_types_1.default.lookup(file.originalname) || "";
|
|
151
158
|
acl = s3Config.acl, key = s3Config.key, bucket = s3Config.bucket;
|
|
152
159
|
params = null;
|
|
153
|
-
|
|
154
|
-
return [
|
|
155
|
-
|
|
156
|
-
|
|
160
|
+
encryptedFilePath = null;
|
|
161
|
+
if (!encrypt) return [3 /*break*/, 3];
|
|
162
|
+
return [4 /*yield*/, (0, encryption_1.cryptFile)(file.path, encryption, false)];
|
|
163
|
+
case 2:
|
|
164
|
+
encryptedFilePath = _a.sent();
|
|
165
|
+
console.log("encryptedFilePath", encryptedFilePath);
|
|
157
166
|
params = __assign({ Bucket: bucket, ACL: acl, Key: key,
|
|
158
167
|
//@ts-ignore
|
|
159
|
-
Body: fs_1.default.createReadStream(
|
|
160
|
-
return [3 /*break*/,
|
|
161
|
-
case 2:
|
|
162
|
-
params = __assign({ Bucket: bucket, ACL: acl, Key: key, Body: fs_1.default.createReadStream(file.path), ContentType: contentType }, options);
|
|
163
|
-
_a.label = 3;
|
|
168
|
+
Body: fs_1.default.createReadStream(encryptedFilePath), ContentType: contentType }, options);
|
|
169
|
+
return [3 /*break*/, 4];
|
|
164
170
|
case 3:
|
|
171
|
+
params = __assign({ Bucket: bucket, ACL: acl, Key: key, Body: fs_1.default.createReadStream(file.path), ContentType: contentType }, options);
|
|
172
|
+
_a.label = 4;
|
|
173
|
+
case 4:
|
|
165
174
|
parallelUploads3 = new lib_storage_1.Upload({
|
|
166
175
|
client: s3Client,
|
|
167
176
|
params: params,
|
|
168
177
|
});
|
|
169
178
|
return [4 /*yield*/, parallelUploads3.done()];
|
|
170
|
-
case
|
|
179
|
+
case 5:
|
|
171
180
|
data = _a.sent();
|
|
181
|
+
if (data) {
|
|
182
|
+
try {
|
|
183
|
+
fs_1.default.unlinkSync(file.path);
|
|
184
|
+
if (encryptedFilePath) {
|
|
185
|
+
fs_1.default.unlinkSync(encryptedFilePath);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
catch (unlinkError) {
|
|
189
|
+
console.error("Error deleting local file:", unlinkError);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
172
192
|
originalname = file.originalname, mimetype = file.mimetype, size = file.size;
|
|
173
193
|
finalObject = {
|
|
174
194
|
originalname: originalname,
|
|
@@ -178,11 +198,11 @@ var processFileUploadToS3 = function (file, s3Client, s3Config, encryption, opti
|
|
|
178
198
|
contentType: contentType,
|
|
179
199
|
};
|
|
180
200
|
return [2 /*return*/, finalObject];
|
|
181
|
-
case
|
|
201
|
+
case 6:
|
|
182
202
|
error_1 = _a.sent();
|
|
183
203
|
console.log("error", error_1);
|
|
184
204
|
return [2 /*return*/, null];
|
|
185
|
-
case
|
|
205
|
+
case 7: return [2 /*return*/];
|
|
186
206
|
}
|
|
187
207
|
});
|
|
188
208
|
});
|
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;
|
|
@@ -19,7 +19,7 @@ export declare const checkAndCompareValue: (input1: any, input2: any) => boolean
|
|
|
19
19
|
export declare const arraysEqual: (array1: any, array2: any) => boolean;
|
|
20
20
|
export declare const convertItemToArray: (itemValue: any) => any[];
|
|
21
21
|
export declare const validateAlphanumericString: (str: string) => false | "String should contain only numbers and letters";
|
|
22
|
-
export declare const formatCustomCSSClasses: (
|
|
22
|
+
export declare const formatCustomCSSClasses: (customClasses: any) => string;
|
|
23
23
|
export declare const replaceDataValueIntoExpression: (expression: string, data: any, user: any, tenant: any, sessionValue: any, envConstants: any, sessionFormValue: any) => string;
|
|
24
24
|
export declare const parseJsonString: (str: string) => any;
|
|
25
25
|
export declare const parseValueFromData: (data: any, fieldName: string) => any;
|
|
@@ -27,3 +27,4 @@ export declare const unflattenObject: (obj: any) => {};
|
|
|
27
27
|
export declare const replaceTransferObjectValueIntoExpression: (expression: string, transferObject: any) => string;
|
|
28
28
|
export declare const removeMongoDbId: (result: any[]) => any[];
|
|
29
29
|
export declare const processFieldsInlcude: (fieldsInclude: any) => any;
|
|
30
|
+
export declare const replaceValueFromSource: (variableName: any, environment: any, tenant: any) => any;
|