drapcode-utility 1.1.7 → 1.1.9
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.d.ts +4 -0
- package/build/encryption/file.js +134 -0
- package/build/encryption/index.d.ts +5 -0
- package/build/encryption/index.js +44 -14
- package/build/encryption/model.d.ts +2 -2
- package/build/index.d.ts +1 -0
- package/build/index.js +2 -5
- 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 +8 -12
- package/build/utils/date-util.js +3 -3
- package/build/utils/query-parser.js +53 -57
- package/build/utils/query-paser-new.js +48 -52
- package/build/utils/s3-util.d.ts +28 -0
- package/build/utils/s3-util.js +170 -0
- package/build/utils/util.d.ts +1 -1
- package/build/utils/util.js +13 -13
- package/build/utils/uuid-generator.js +2 -2
- package/package.json +5 -1
|
@@ -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 (
|
|
17
|
+
while (_) 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,14 +35,10 @@ 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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
ar[i] = from[i];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
39
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
40
|
+
to[j] = from[i];
|
|
41
|
+
return to;
|
|
46
42
|
};
|
|
47
43
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
44
|
exports.queryParserNew = void 0;
|
|
@@ -85,11 +81,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
85
81
|
if (searchQueryTypeObj[key]) {
|
|
86
82
|
aggregateQuery.push({
|
|
87
83
|
$addFields: (_b = {},
|
|
88
|
-
_b["_"
|
|
84
|
+
_b["_" + key] = { $toString: "$" + key },
|
|
89
85
|
_b),
|
|
90
86
|
});
|
|
91
87
|
searchQueryObj_1.push((_c = {},
|
|
92
|
-
_c["_"
|
|
88
|
+
_c["_" + key] = {
|
|
93
89
|
$regex: value,
|
|
94
90
|
$options: "i",
|
|
95
91
|
},
|
|
@@ -123,11 +119,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
123
119
|
// if input is string and db field type is boolean
|
|
124
120
|
aggregateQuery.push({
|
|
125
121
|
$addFields: (_b = {},
|
|
126
|
-
_b["_"
|
|
122
|
+
_b["_" + key] = "$" + key,
|
|
127
123
|
_b),
|
|
128
124
|
});
|
|
129
125
|
likeQuery_1.push((_c = {},
|
|
130
|
-
_c["_"
|
|
126
|
+
_c["_" + key] = toBoolean(value),
|
|
131
127
|
_c));
|
|
132
128
|
}
|
|
133
129
|
else if ([
|
|
@@ -139,22 +135,22 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
139
135
|
// if input is string and db field type is array
|
|
140
136
|
aggregateQuery.push({
|
|
141
137
|
$addFields: (_d = {},
|
|
142
|
-
_d["_"
|
|
138
|
+
_d["_" + key] = "$" + key,
|
|
143
139
|
_d),
|
|
144
140
|
});
|
|
145
141
|
likeQuery_1.push((_e = {},
|
|
146
|
-
_e["_"
|
|
142
|
+
_e["_" + key] = { $all: [value] },
|
|
147
143
|
_e));
|
|
148
144
|
}
|
|
149
145
|
else if (searchQueryTypeObj[key] === "tel") {
|
|
150
146
|
// handling value when db field type is tel
|
|
151
147
|
aggregateQuery.push({
|
|
152
148
|
$addFields: (_f = {},
|
|
153
|
-
_f["_"
|
|
149
|
+
_f["_" + key] = { $toString: "$" + key },
|
|
154
150
|
_f),
|
|
155
151
|
});
|
|
156
152
|
likeQuery_1.push((_g = {},
|
|
157
|
-
_g["_"
|
|
153
|
+
_g["_" + key] = {
|
|
158
154
|
$regex: value.startsWith("+") ? value.replace("+", "") : value,
|
|
159
155
|
$options: "i",
|
|
160
156
|
},
|
|
@@ -164,11 +160,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
164
160
|
// handling value when db field type is Double/Int
|
|
165
161
|
aggregateQuery.push({
|
|
166
162
|
$addFields: (_h = {},
|
|
167
|
-
_h["_"
|
|
163
|
+
_h["_" + key] = { $toString: { $toLong: "$" + key } },
|
|
168
164
|
_h),
|
|
169
165
|
});
|
|
170
166
|
likeQuery_1.push((_j = {},
|
|
171
|
-
_j["_"
|
|
167
|
+
_j["_" + key] = {
|
|
172
168
|
$regex: value,
|
|
173
169
|
$options: "i",
|
|
174
170
|
},
|
|
@@ -179,11 +175,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
179
175
|
// converting db field to string first
|
|
180
176
|
aggregateQuery.push({
|
|
181
177
|
$addFields: (_k = {},
|
|
182
|
-
_k["_"
|
|
178
|
+
_k["_" + key] = { $toString: "$" + key },
|
|
183
179
|
_k),
|
|
184
180
|
});
|
|
185
181
|
likeQuery_1.push((_l = {},
|
|
186
|
-
_l["_"
|
|
182
|
+
_l["_" + key] = {
|
|
187
183
|
$regex: value,
|
|
188
184
|
$options: "i",
|
|
189
185
|
},
|
|
@@ -218,7 +214,7 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
218
214
|
if (field.type === "belongsTo") {
|
|
219
215
|
aggregateQuery.push({
|
|
220
216
|
$lookup: {
|
|
221
|
-
from: ""
|
|
217
|
+
from: "" + collectionName_1,
|
|
222
218
|
localField: field.fieldName,
|
|
223
219
|
foreignField: "uuid",
|
|
224
220
|
as: field.fieldName,
|
|
@@ -233,8 +229,8 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
233
229
|
else {
|
|
234
230
|
aggregateQuery.push({
|
|
235
231
|
$lookup: {
|
|
236
|
-
from: ""
|
|
237
|
-
let: (_b = {}, _b[""
|
|
232
|
+
from: "" + collectionName_1,
|
|
233
|
+
let: (_b = {}, _b["" + field.fieldName] = "$" + field.fieldName, _b),
|
|
238
234
|
pipeline: [
|
|
239
235
|
{
|
|
240
236
|
$match: {
|
|
@@ -244,10 +240,10 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
244
240
|
{
|
|
245
241
|
$cond: {
|
|
246
242
|
if: {
|
|
247
|
-
$in: ["$$"
|
|
243
|
+
$in: ["$$" + field.fieldName, ["", null]],
|
|
248
244
|
},
|
|
249
245
|
then: [],
|
|
250
|
-
else: { $ifNull: ["$$"
|
|
246
|
+
else: { $ifNull: ["$$" + field.fieldName, []] },
|
|
251
247
|
},
|
|
252
248
|
},
|
|
253
249
|
],
|
|
@@ -280,10 +276,10 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
280
276
|
aggregateQuery.push({
|
|
281
277
|
$lookup: {
|
|
282
278
|
from: "user",
|
|
283
|
-
let: (_c = {}, _c[""
|
|
279
|
+
let: (_c = {}, _c["" + field.fieldName] = "$" + field.fieldName, _c),
|
|
284
280
|
pipeline: [
|
|
285
281
|
{
|
|
286
|
-
$match: { $expr: { $eq: ["$uuid", "$$"
|
|
282
|
+
$match: { $expr: { $eq: ["$uuid", "$$" + field.fieldName] } },
|
|
287
283
|
},
|
|
288
284
|
{ $project: { _id: 0, password: 0 } },
|
|
289
285
|
],
|
|
@@ -296,7 +292,7 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
296
292
|
_b.label = 2;
|
|
297
293
|
case 2:
|
|
298
294
|
if (!["COUNT", "SUM", "AVG", "MIN", "MAX"].includes(finder) &&
|
|
299
|
-
!
|
|
295
|
+
!util_1.isEmpty(projection)) {
|
|
300
296
|
aggregateQuery.push({ $project: projection });
|
|
301
297
|
}
|
|
302
298
|
if (finder === "COUNT") {
|
|
@@ -304,22 +300,22 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
304
300
|
}
|
|
305
301
|
else if (finder === "SUM") {
|
|
306
302
|
aggregateQuery.push({
|
|
307
|
-
$group: { _id: null, total: { $sum: "$"
|
|
303
|
+
$group: { _id: null, total: { $sum: "$" + aggregateFunctionField } },
|
|
308
304
|
});
|
|
309
305
|
}
|
|
310
306
|
else if (finder === "AVG") {
|
|
311
307
|
aggregateQuery.push({
|
|
312
|
-
$group: { _id: null, average: { $avg: "$"
|
|
308
|
+
$group: { _id: null, average: { $avg: "$" + aggregateFunctionField } },
|
|
313
309
|
});
|
|
314
310
|
}
|
|
315
311
|
else if (finder === "MIN") {
|
|
316
312
|
aggregateQuery.push({
|
|
317
|
-
$group: { _id: null, minimum: { $min: "$"
|
|
313
|
+
$group: { _id: null, minimum: { $min: "$" + aggregateFunctionField } },
|
|
318
314
|
});
|
|
319
315
|
}
|
|
320
316
|
else if (finder === "MAX") {
|
|
321
317
|
aggregateQuery.push({
|
|
322
|
-
$group: { _id: null, maximum: { $max: "$"
|
|
318
|
+
$group: { _id: null, maximum: { $max: "$" + aggregateFunctionField } },
|
|
323
319
|
});
|
|
324
320
|
}
|
|
325
321
|
offset = externalParams.offset || 0;
|
|
@@ -335,8 +331,8 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
335
331
|
if (finder != "COUNT" && limit) {
|
|
336
332
|
aggregateQuery.push({ $skip: +offset }, { $limit: +limit });
|
|
337
333
|
}
|
|
338
|
-
queryStr = ".aggregate("
|
|
339
|
-
str = "req.db.collection('"
|
|
334
|
+
queryStr = ".aggregate(" + JSON.stringify(aggregateQuery) + ", { collation: { locale: \"en\" } })";
|
|
335
|
+
str = "req.db.collection('" + collectionName + "')" + queryStr;
|
|
340
336
|
str += ".toArray()";
|
|
341
337
|
return [2 /*return*/, str];
|
|
342
338
|
}
|
|
@@ -373,7 +369,7 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser)
|
|
|
373
369
|
filterQuery[lastKey].push(mongoQuery);
|
|
374
370
|
}
|
|
375
371
|
else {
|
|
376
|
-
filterQuery["$or"
|
|
372
|
+
filterQuery["$or" + index] = [mongoQuery];
|
|
377
373
|
}
|
|
378
374
|
}
|
|
379
375
|
else if (queryObj.conjunctionType == "AND") {
|
|
@@ -382,11 +378,11 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser)
|
|
|
382
378
|
filterQuery[lastKey].push(mongoQuery);
|
|
383
379
|
}
|
|
384
380
|
else {
|
|
385
|
-
filterQuery["$and"
|
|
381
|
+
filterQuery["$and" + index] = [mongoQuery];
|
|
386
382
|
}
|
|
387
383
|
}
|
|
388
384
|
else {
|
|
389
|
-
filterQuery["$or"
|
|
385
|
+
filterQuery["$or" + index] = [mongoQuery];
|
|
390
386
|
}
|
|
391
387
|
});
|
|
392
388
|
console.log("==> *** filterQuery #2 :>> ", filterQuery);
|
|
@@ -402,13 +398,13 @@ var mongoSelectQuery = function (query) {
|
|
|
402
398
|
if (fieldsInclude[0] === "*") {
|
|
403
399
|
fieldsExclude.map(function (field) {
|
|
404
400
|
if (field)
|
|
405
|
-
return (projection[""
|
|
401
|
+
return (projection["" + field] = 0);
|
|
406
402
|
});
|
|
407
403
|
}
|
|
408
404
|
else {
|
|
409
405
|
fieldsInclude.map(function (field) {
|
|
410
406
|
if (field)
|
|
411
|
-
return (projection[""
|
|
407
|
+
return (projection["" + field] = 1);
|
|
412
408
|
});
|
|
413
409
|
}
|
|
414
410
|
return projection;
|
|
@@ -499,7 +495,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
499
495
|
return _r = {},
|
|
500
496
|
_r[field] = {
|
|
501
497
|
$gte: fieldValue,
|
|
502
|
-
$lt: new Date(
|
|
498
|
+
$lt: new Date(date_util_1.nextDayDate(fieldValue)),
|
|
503
499
|
},
|
|
504
500
|
_r;
|
|
505
501
|
}
|
|
@@ -577,11 +573,11 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
577
573
|
if (key === drapcode_constant_1.BETWEEN) {
|
|
578
574
|
var _a = getMinMaxValue(value), startValue_1 = _a.startValue, endValue_1 = _a.endValue, isInteger = _a.isInteger;
|
|
579
575
|
if (requiredExternal) {
|
|
580
|
-
startValue_1 = ""
|
|
581
|
-
endValue_1 = ""
|
|
576
|
+
startValue_1 = "" + externalParams[startValue_1];
|
|
577
|
+
endValue_1 = "" + externalParams[endValue_1];
|
|
582
578
|
}
|
|
583
579
|
else {
|
|
584
|
-
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant
|
|
580
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) {
|
|
585
581
|
return startValue_1.includes(cnst);
|
|
586
582
|
})) {
|
|
587
583
|
startValue_1 = getValueOfProjectConstant(startValue_1, currentUser);
|
|
@@ -589,7 +585,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
589
585
|
else {
|
|
590
586
|
startValue_1 = constants.filter(function (constant) { return constant.name == startValue_1; });
|
|
591
587
|
}
|
|
592
|
-
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant
|
|
588
|
+
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) { return endValue_1.includes(cnst); })) {
|
|
593
589
|
endValue_1 = getValueOfProjectConstant(endValue_1, currentUser);
|
|
594
590
|
}
|
|
595
591
|
else {
|
|
@@ -606,10 +602,10 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
606
602
|
//TODO: Need to figure out the params should be treated as number/string
|
|
607
603
|
if (!isNaN(startValue_1)) {
|
|
608
604
|
console.log("I am Number");
|
|
609
|
-
return
|
|
605
|
+
return startValue_1 + "---" + endValue_1 + "^";
|
|
610
606
|
}
|
|
611
607
|
else
|
|
612
|
-
return
|
|
608
|
+
return startValue_1 + "---" + endValue_1;
|
|
613
609
|
}
|
|
614
610
|
if (value.includes(drapcode_constant_1.CURRENT_USER)) {
|
|
615
611
|
if (value === drapcode_constant_1.CURRENT_USER) {
|
|
@@ -647,11 +643,11 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
647
643
|
//TODO: This is just to confirm if external then it should be get from externalParams
|
|
648
644
|
if (requiredExternal) {
|
|
649
645
|
//TODO: Value returns from here undefined.
|
|
650
|
-
var externalParamValue = externalParams[""
|
|
646
|
+
var externalParamValue = externalParams["" + value];
|
|
651
647
|
if (!isNaN(externalParamValue)) {
|
|
652
648
|
return +externalParamValue;
|
|
653
649
|
}
|
|
654
|
-
return externalParams[""
|
|
650
|
+
return externalParams["" + value];
|
|
655
651
|
}
|
|
656
652
|
var constantArr = constants.filter(function (constant) { return constant.name == value; });
|
|
657
653
|
return constantArr.length ? "" + constantArr[0].value : "";
|
|
@@ -678,9 +674,9 @@ var getValueOfProjectConstant = function (value, currentUser) {
|
|
|
678
674
|
if (value === drapcode_constant_1.CURRENT_USER)
|
|
679
675
|
return currentUser["uuid"];
|
|
680
676
|
if (value === drapcode_constant_1.CURRENT_DATE)
|
|
681
|
-
return
|
|
677
|
+
return date_util_1.createLoggerDateFormat();
|
|
682
678
|
if ([drapcode_constant_1.CURRENT_TIME, drapcode_constant_1.CURRENT_DATE_TIME].includes(value))
|
|
683
|
-
return
|
|
679
|
+
return date_util_1.createLogsDateFormat();
|
|
684
680
|
if (drapcode_constant_1.DateTimeUnit.some(function (cnst) { return value.includes(cnst); }))
|
|
685
|
-
return
|
|
681
|
+
return date_util_1.getDateValue(value);
|
|
686
682
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { S3Client, ObjectCannedACL } from "@aws-sdk/client-s3";
|
|
2
|
+
import { Encryption } from "../encryption/model";
|
|
3
|
+
interface AWSConfig {
|
|
4
|
+
region: string;
|
|
5
|
+
accessKey: string;
|
|
6
|
+
accessSecret: string;
|
|
7
|
+
}
|
|
8
|
+
interface S3Config {
|
|
9
|
+
acl: ObjectCannedACL;
|
|
10
|
+
key: string;
|
|
11
|
+
bucket: string;
|
|
12
|
+
append: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare const createS3Client: (awsConfig: AWSConfig) => S3Client | null;
|
|
15
|
+
export declare const fileUploadToS3: (files: any, s3Client: S3Client, s3Config: S3Config, encryption: Encryption, options?: {}) => Promise<{
|
|
16
|
+
originalname: any;
|
|
17
|
+
mimetype: any;
|
|
18
|
+
size: any;
|
|
19
|
+
key: string | undefined;
|
|
20
|
+
contentType: string;
|
|
21
|
+
} | {
|
|
22
|
+
originalname: any;
|
|
23
|
+
mimetype: any;
|
|
24
|
+
size: any;
|
|
25
|
+
key: string | undefined;
|
|
26
|
+
contentType: string;
|
|
27
|
+
}[] | null>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
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
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.fileUploadToS3 = exports.createS3Client = void 0;
|
|
54
|
+
var client_s3_1 = require("@aws-sdk/client-s3");
|
|
55
|
+
var fs_1 = __importDefault(require("fs"));
|
|
56
|
+
var mime_types_1 = __importDefault(require("mime-types"));
|
|
57
|
+
var lib_storage_1 = require("@aws-sdk/lib-storage");
|
|
58
|
+
var encryption_1 = require("../encryption");
|
|
59
|
+
var createS3Client = function (awsConfig) {
|
|
60
|
+
if (!awsConfig) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
var region = awsConfig.region, accessKey = awsConfig.accessKey, accessSecret = awsConfig.accessSecret;
|
|
64
|
+
var s3client = new client_s3_1.S3Client({
|
|
65
|
+
region: region,
|
|
66
|
+
credentials: {
|
|
67
|
+
accessKeyId: accessKey,
|
|
68
|
+
secretAccessKey: accessSecret,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
return s3client;
|
|
72
|
+
};
|
|
73
|
+
exports.createS3Client = createS3Client;
|
|
74
|
+
var fileUploadToS3 = function (files, s3Client, s3Config, encryption, options) {
|
|
75
|
+
if (options === void 0) { options = {}; }
|
|
76
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
77
|
+
var fileOptions, s3Key, _a, _b, _i, index, file, fileObj, fileObj;
|
|
78
|
+
return __generator(this, function (_c) {
|
|
79
|
+
switch (_c.label) {
|
|
80
|
+
case 0:
|
|
81
|
+
if (!Array.isArray(files)) return [3 /*break*/, 5];
|
|
82
|
+
console.log("I have multiple file");
|
|
83
|
+
fileOptions = [];
|
|
84
|
+
s3Key = s3Config.key;
|
|
85
|
+
_a = [];
|
|
86
|
+
for (_b in files)
|
|
87
|
+
_a.push(_b);
|
|
88
|
+
_i = 0;
|
|
89
|
+
_c.label = 1;
|
|
90
|
+
case 1:
|
|
91
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
92
|
+
index = _a[_i];
|
|
93
|
+
file = files[index];
|
|
94
|
+
if (s3Config.append) {
|
|
95
|
+
s3Config.key = s3Key + "/" + file.originalname;
|
|
96
|
+
}
|
|
97
|
+
return [4 /*yield*/, processFileUploadToS3(file, s3Client, s3Config, encryption, options, encryption ? true : false)];
|
|
98
|
+
case 2:
|
|
99
|
+
fileObj = _c.sent();
|
|
100
|
+
if (fileObj) {
|
|
101
|
+
fileOptions.push(fileObj);
|
|
102
|
+
}
|
|
103
|
+
_c.label = 3;
|
|
104
|
+
case 3:
|
|
105
|
+
_i++;
|
|
106
|
+
return [3 /*break*/, 1];
|
|
107
|
+
case 4: return [2 /*return*/, fileOptions];
|
|
108
|
+
case 5:
|
|
109
|
+
console.log("I have single file");
|
|
110
|
+
if (s3Config.append) {
|
|
111
|
+
s3Config.key = s3Config.key + "/" + files.originalname;
|
|
112
|
+
}
|
|
113
|
+
return [4 /*yield*/, processFileUploadToS3(files, s3Client, s3Config, encryption, options, encryption ? true : false)];
|
|
114
|
+
case 6:
|
|
115
|
+
fileObj = _c.sent();
|
|
116
|
+
return [2 /*return*/, fileObj];
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
exports.fileUploadToS3 = fileUploadToS3;
|
|
122
|
+
var processFileUploadToS3 = function (file, s3Client, s3Config, encryption, options, encrypt) {
|
|
123
|
+
if (options === void 0) { options = {}; }
|
|
124
|
+
if (encrypt === void 0) { encrypt = false; }
|
|
125
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
126
|
+
var contentType, acl, key, bucket, params, encryptedBody, parallelUploads3, data, originalname, mimetype, size, finalObject, error_1;
|
|
127
|
+
return __generator(this, function (_a) {
|
|
128
|
+
switch (_a.label) {
|
|
129
|
+
case 0:
|
|
130
|
+
_a.trys.push([0, 5, , 6]);
|
|
131
|
+
contentType = mime_types_1.default.lookup(file.originalname) || "";
|
|
132
|
+
acl = s3Config.acl, key = s3Config.key, bucket = s3Config.bucket;
|
|
133
|
+
params = null;
|
|
134
|
+
if (!encrypt) return [3 /*break*/, 2];
|
|
135
|
+
return [4 /*yield*/, encryption_1.cryptFile(file.path, encryption, false)];
|
|
136
|
+
case 1:
|
|
137
|
+
encryptedBody = _a.sent();
|
|
138
|
+
params = __assign({ Bucket: bucket, ACL: acl, Key: key,
|
|
139
|
+
//@ts-ignore
|
|
140
|
+
Body: fs_1.default.createReadStream(encryptedBody), ContentType: contentType }, options);
|
|
141
|
+
return [3 /*break*/, 3];
|
|
142
|
+
case 2:
|
|
143
|
+
params = __assign({ Bucket: bucket, ACL: acl, Key: key, Body: fs_1.default.createReadStream(file.path), ContentType: contentType }, options);
|
|
144
|
+
_a.label = 3;
|
|
145
|
+
case 3:
|
|
146
|
+
parallelUploads3 = new lib_storage_1.Upload({
|
|
147
|
+
client: s3Client,
|
|
148
|
+
params: params,
|
|
149
|
+
});
|
|
150
|
+
return [4 /*yield*/, parallelUploads3.done()];
|
|
151
|
+
case 4:
|
|
152
|
+
data = _a.sent();
|
|
153
|
+
originalname = file.originalname, mimetype = file.mimetype, size = file.size;
|
|
154
|
+
finalObject = {
|
|
155
|
+
originalname: originalname,
|
|
156
|
+
mimetype: mimetype,
|
|
157
|
+
size: size,
|
|
158
|
+
key: data.Key,
|
|
159
|
+
contentType: contentType,
|
|
160
|
+
};
|
|
161
|
+
return [2 /*return*/, finalObject];
|
|
162
|
+
case 5:
|
|
163
|
+
error_1 = _a.sent();
|
|
164
|
+
console.log("error", error_1);
|
|
165
|
+
return [2 /*return*/, null];
|
|
166
|
+
case 6: return [2 /*return*/];
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
};
|
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) => string;
|
|
3
|
+
export declare const clearSpaceAndReformat: (text: string, separator?: string | undefined) => 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;
|
package/build/utils/util.js
CHANGED
|
@@ -38,7 +38,7 @@ var validateString = function (str) {
|
|
|
38
38
|
};
|
|
39
39
|
exports.validateString = validateString;
|
|
40
40
|
var camelize = function (str) {
|
|
41
|
-
str =
|
|
41
|
+
str = exports.clearSpaceAndReformat(str);
|
|
42
42
|
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
|
|
43
43
|
return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
|
44
44
|
});
|
|
@@ -160,13 +160,13 @@ var stringToExpression = function (str) {
|
|
|
160
160
|
};
|
|
161
161
|
exports.stringToExpression = stringToExpression;
|
|
162
162
|
var cleanCollectionAndFieldName = function (str) {
|
|
163
|
-
str = str.replace(/[^
|
|
163
|
+
str = str.replace(/[^A-Za-z0-9\s_]/, "");
|
|
164
164
|
return str;
|
|
165
165
|
};
|
|
166
166
|
exports.cleanCollectionAndFieldName = cleanCollectionAndFieldName;
|
|
167
167
|
var formatCollectionAndFieldName = function (str) {
|
|
168
|
-
var updateString =
|
|
169
|
-
return
|
|
168
|
+
var updateString = exports.cleanCollectionAndFieldName(str);
|
|
169
|
+
return exports.clearSpaceAndReformat(updateString.trim(), "_");
|
|
170
170
|
};
|
|
171
171
|
exports.formatCollectionAndFieldName = formatCollectionAndFieldName;
|
|
172
172
|
var restructureData = function (data) {
|
|
@@ -197,7 +197,7 @@ var restructureData = function (data) {
|
|
|
197
197
|
exports.restructureData = restructureData;
|
|
198
198
|
var checkAndCompareValue = function (input1, input2) {
|
|
199
199
|
return Array.isArray(input2)
|
|
200
|
-
?
|
|
200
|
+
? exports.arraysEqual(input1, input2.map(function (key) { return key.value; }))
|
|
201
201
|
: input1 === input2.value;
|
|
202
202
|
};
|
|
203
203
|
exports.checkAndCompareValue = checkAndCompareValue;
|
|
@@ -207,7 +207,7 @@ var arraysEqual = function (array1, array2) {
|
|
|
207
207
|
return false;
|
|
208
208
|
for (var i = 0; i < array1.length; i++ // assert each element equal
|
|
209
209
|
)
|
|
210
|
-
if (!
|
|
210
|
+
if (!exports.arraysEqual(array1[i], array2[i]))
|
|
211
211
|
return false;
|
|
212
212
|
return true;
|
|
213
213
|
}
|
|
@@ -224,7 +224,7 @@ var convertItemToArray = function (itemValue) {
|
|
|
224
224
|
};
|
|
225
225
|
exports.convertItemToArray = convertItemToArray;
|
|
226
226
|
var validateAlphanumericString = function (str) {
|
|
227
|
-
if (/[^
|
|
227
|
+
if (/[^A-Za-z0-9\s_]/.test(str)) {
|
|
228
228
|
return "String should contain only numbers and letters";
|
|
229
229
|
}
|
|
230
230
|
return false;
|
|
@@ -242,7 +242,7 @@ var formatCustomCSSClasses = function (projectCustomCSSClasses) {
|
|
|
242
242
|
.replace(/"([^"]+)"/g, "$1")
|
|
243
243
|
.split(",")
|
|
244
244
|
.join(";");
|
|
245
|
-
projectCustomCSSClassesData += ""
|
|
245
|
+
projectCustomCSSClassesData += "" + (element.class.startsWith(".") ? element.class : "." + element.class) + (element.pseudoClass ? ":" + element.pseudoClass : "") + unquotedClassWithProp + " ";
|
|
246
246
|
}
|
|
247
247
|
});
|
|
248
248
|
return projectCustomCSSClassesData;
|
|
@@ -253,18 +253,18 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, s
|
|
|
253
253
|
var contentList = (_a = expression
|
|
254
254
|
.match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
|
|
255
255
|
contentList === null || contentList === void 0 ? void 0 : contentList.forEach(function (prop) {
|
|
256
|
-
var needle = "{{"
|
|
256
|
+
var needle = "{{" + prop + "}}";
|
|
257
257
|
var dataOfItem = "";
|
|
258
258
|
if (prop.includes("current_user")) {
|
|
259
259
|
prop = prop.replace("current_user.", "");
|
|
260
260
|
if (Object.keys(user).length > 0) {
|
|
261
|
-
dataOfItem =
|
|
261
|
+
dataOfItem = exports.parseValueFromData(user, prop);
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
264
|
else if (prop.includes("current_tenant")) {
|
|
265
265
|
prop = prop.replace("current_tenant.", "");
|
|
266
266
|
if (Object.keys(tenant).length > 0) {
|
|
267
|
-
dataOfItem =
|
|
267
|
+
dataOfItem = exports.parseValueFromData(tenant, prop);
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
270
|
else if (prop.includes("current_session")) {
|
|
@@ -290,7 +290,7 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, s
|
|
|
290
290
|
}
|
|
291
291
|
else {
|
|
292
292
|
if (Object.keys(data).length > 0) {
|
|
293
|
-
dataOfItem =
|
|
293
|
+
dataOfItem = exports.parseValueFromData(data, prop);
|
|
294
294
|
//TODO: Need better way
|
|
295
295
|
delete data[prop];
|
|
296
296
|
}
|
|
@@ -390,7 +390,7 @@ var replaceTransferObjectValueIntoExpression = function (expression, transferObj
|
|
|
390
390
|
var contentList = (_a = expression
|
|
391
391
|
.match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
|
|
392
392
|
contentList === null || contentList === void 0 ? void 0 : contentList.forEach(function (prop) {
|
|
393
|
-
var needle = "{{"
|
|
393
|
+
var needle = "{{" + prop + "}}";
|
|
394
394
|
var dataOfItem = "";
|
|
395
395
|
dataOfItem = transferObject[prop] ? transferObject[prop] : "";
|
|
396
396
|
expression = dataOfItem
|
|
@@ -38,10 +38,10 @@ var nextGeneratedString = function (str, prepend, minLength, append, algorithm)
|
|
|
38
38
|
finalValue = voca_1.default.padLeft(finalValue, minLength, "0");
|
|
39
39
|
}
|
|
40
40
|
if (prepend) {
|
|
41
|
-
finalValue = ""
|
|
41
|
+
finalValue = "" + prepend + finalValue;
|
|
42
42
|
}
|
|
43
43
|
if (append) {
|
|
44
|
-
finalValue = ""
|
|
44
|
+
finalValue = "" + finalValue + append;
|
|
45
45
|
}
|
|
46
46
|
return finalValue;
|
|
47
47
|
};
|