drapcode-utility 1.9.8 → 1.9.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/index.js +5 -2
- package/build/utils/query-utils.js +29 -12
- package/build/utils/rest-client.js +25 -7
- package/build/utils/util.js +4 -4
- package/package.json +1 -1
|
@@ -90,7 +90,9 @@ var processItemEncryptDecrypt = function (item, fields, encryption, decrypt, enc
|
|
|
90
90
|
return __generator(this, function (_b) {
|
|
91
91
|
switch (_b.label) {
|
|
92
92
|
case 0:
|
|
93
|
-
if (!
|
|
93
|
+
if (!item && typeof item !== "object") {
|
|
94
|
+
return [2 /*return*/, item];
|
|
95
|
+
}
|
|
94
96
|
_loop_1 = function (fieldName) {
|
|
95
97
|
var field, promises, _c, _d, _e, _f, refField, _g, _h;
|
|
96
98
|
return __generator(this, function (_j) {
|
|
@@ -118,7 +120,7 @@ var processItemEncryptDecrypt = function (item, fields, encryption, decrypt, enc
|
|
|
118
120
|
_j.label = 4;
|
|
119
121
|
case 4:
|
|
120
122
|
if (!decrypt) return [3 /*break*/, 6];
|
|
121
|
-
if (!drapcode_constant_1.BelongsCreatedByRefField.includes(field === null || field === void 0 ? void 0 : field.type)) return [3 /*break*/, 6];
|
|
123
|
+
if (!(decrypt && drapcode_constant_1.BelongsCreatedByRefField.includes(field === null || field === void 0 ? void 0 : field.type))) return [3 /*break*/, 6];
|
|
122
124
|
refField = field;
|
|
123
125
|
if (!refField.refCollection &&
|
|
124
126
|
[drapcode_constant_1.FieldTypes.createdBy.id, drapcode_constant_1.FieldTypes.updatedBy.id].includes(field.type)) {
|
|
@@ -163,6 +165,7 @@ var processDataEncryptionDecryption = function (data, encryption, decrypt) { ret
|
|
|
163
165
|
encryptionType = encryption.encryptionType, dataKey = encryption.dataKey;
|
|
164
166
|
if (!data)
|
|
165
167
|
return [2 /*return*/, data];
|
|
168
|
+
console.log("data :>> ", data);
|
|
166
169
|
_a = encryptionType;
|
|
167
170
|
switch (_a) {
|
|
168
171
|
case "KMS": return [3 /*break*/, 1];
|
|
@@ -17,7 +17,7 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
17
17
|
var searchAggregateQuery = [];
|
|
18
18
|
var likeQuery = [];
|
|
19
19
|
Object.entries(searchObj).forEach(function (_a) {
|
|
20
|
-
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
20
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
21
21
|
var key = _a[0], value = _a[1];
|
|
22
22
|
if (value) {
|
|
23
23
|
var searchQueryTypeKey = searchQueryTypeObj[key];
|
|
@@ -101,42 +101,59 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
|
|
|
101
101
|
if (key.startsWith("start_")) {
|
|
102
102
|
likeQuery.push((_o = {},
|
|
103
103
|
_o["_".concat(key)] = {
|
|
104
|
-
$gte: (0, date_util_1.timezoneDateParse)(value,
|
|
104
|
+
$gte: (0, date_util_1.timezoneDateParse)(value, false, true),
|
|
105
105
|
},
|
|
106
106
|
_o));
|
|
107
107
|
}
|
|
108
108
|
else if (key.startsWith("end_")) {
|
|
109
109
|
likeQuery.push((_p = {},
|
|
110
110
|
_p["_".concat(key)] = {
|
|
111
|
-
$lt: (0, date_util_1.timezoneDateParse)(value
|
|
111
|
+
$lt: (0, date_util_1.timezoneDateParse)(value),
|
|
112
112
|
},
|
|
113
113
|
_p));
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
+
else {
|
|
117
|
+
searchAggregateQuery.push({
|
|
118
|
+
$addFields: (_q = {},
|
|
119
|
+
_q["_".concat(key)] = { $toString: "$".concat(key) },
|
|
120
|
+
_q),
|
|
121
|
+
});
|
|
122
|
+
likeQuery.push((_r = {},
|
|
123
|
+
_r["_".concat(key)] = {
|
|
124
|
+
$gte: (0, date_util_1.timezoneDateParse)(value, false, true),
|
|
125
|
+
},
|
|
126
|
+
_r));
|
|
127
|
+
likeQuery.push((_s = {},
|
|
128
|
+
_s["_".concat(key)] = {
|
|
129
|
+
$lt: (0, date_util_1.timezoneDateParse)(value, false),
|
|
130
|
+
},
|
|
131
|
+
_s));
|
|
132
|
+
}
|
|
116
133
|
}
|
|
117
134
|
else {
|
|
118
135
|
// if input is string and db field type is number
|
|
119
136
|
// converting db field to string first
|
|
120
137
|
searchAggregateQuery.push({
|
|
121
|
-
$addFields: (
|
|
122
|
-
|
|
123
|
-
|
|
138
|
+
$addFields: (_t = {},
|
|
139
|
+
_t["_".concat(key)] = { $toString: "$".concat(key) },
|
|
140
|
+
_t),
|
|
124
141
|
});
|
|
125
|
-
likeQuery.push((
|
|
126
|
-
|
|
142
|
+
likeQuery.push((_u = {},
|
|
143
|
+
_u["_".concat(key)] = {
|
|
127
144
|
$regex: value,
|
|
128
145
|
$options: "i",
|
|
129
146
|
},
|
|
130
|
-
|
|
147
|
+
_u));
|
|
131
148
|
}
|
|
132
149
|
}
|
|
133
150
|
else {
|
|
134
|
-
likeQuery.push((
|
|
135
|
-
|
|
151
|
+
likeQuery.push((_v = {},
|
|
152
|
+
_v[key] = {
|
|
136
153
|
$regex: value,
|
|
137
154
|
$options: "i",
|
|
138
155
|
},
|
|
139
|
-
|
|
156
|
+
_v));
|
|
140
157
|
}
|
|
141
158
|
}
|
|
142
159
|
});
|
|
@@ -286,7 +286,7 @@ var prepareReturnObject = function (data, status, success, headers) {
|
|
|
286
286
|
};
|
|
287
287
|
};
|
|
288
288
|
var makeAxiosCall = function (projectId, methodType, url, axiosConfig, data, timeout, wrapJsonDataInArray, awsSignPluginConfig) { return __awaiter(void 0, void 0, void 0, function () {
|
|
289
|
-
var result, instance, dataArray_1, awsRes;
|
|
289
|
+
var result, instance, dataArray_1, payload, urlObj_1, awsRes, error_2;
|
|
290
290
|
return __generator(this, function (_a) {
|
|
291
291
|
switch (_a.label) {
|
|
292
292
|
case 0:
|
|
@@ -323,20 +323,38 @@ var makeAxiosCall = function (projectId, methodType, url, axiosConfig, data, tim
|
|
|
323
323
|
default:
|
|
324
324
|
break;
|
|
325
325
|
}
|
|
326
|
-
|
|
327
|
-
return [4 /*yield*/, (0, util_1.getAwsSignature)(axiosConfig, awsSignPluginConfig)];
|
|
326
|
+
_a.label = 1;
|
|
328
327
|
case 1:
|
|
328
|
+
_a.trys.push([1, 5, , 6]);
|
|
329
|
+
if (!awsSignPluginConfig) return [3 /*break*/, 3];
|
|
330
|
+
payload = JSON.stringify(data);
|
|
331
|
+
axiosConfig = __assign(__assign({}, axiosConfig), { data: payload });
|
|
332
|
+
if (axiosConfig.params) {
|
|
333
|
+
urlObj_1 = new URL(axiosConfig.url);
|
|
334
|
+
Object.entries(axiosConfig.params).forEach(function (_a) {
|
|
335
|
+
var key = _a[0], value = _a[1];
|
|
336
|
+
urlObj_1.searchParams.append(key, value);
|
|
337
|
+
});
|
|
338
|
+
axiosConfig.url = urlObj_1.toString();
|
|
339
|
+
}
|
|
340
|
+
return [4 /*yield*/, (0, util_1.getAwsSignature)(axiosConfig, awsSignPluginConfig)];
|
|
341
|
+
case 2:
|
|
329
342
|
awsRes = _a.sent();
|
|
330
343
|
if (awsRes.error)
|
|
331
344
|
return [2 /*return*/, awsRes.error];
|
|
332
|
-
axiosConfig = __assign(__assign({}, awsRes.data), {
|
|
333
|
-
_a.label =
|
|
334
|
-
case
|
|
345
|
+
axiosConfig = __assign(__assign({}, awsRes.data), { data: payload });
|
|
346
|
+
_a.label = 3;
|
|
347
|
+
case 3:
|
|
335
348
|
console.log("\n ==> Final axiosConfig for projectID: ".concat(projectId, ":>> "), axiosConfig);
|
|
336
349
|
return [4 /*yield*/, (0, axios_1.default)(__assign({}, axiosConfig))];
|
|
337
|
-
case
|
|
350
|
+
case 4:
|
|
338
351
|
result = _a.sent();
|
|
339
352
|
return [2 /*return*/, result];
|
|
353
|
+
case 5:
|
|
354
|
+
error_2 = _a.sent();
|
|
355
|
+
console.log("\n ===error", error_2);
|
|
356
|
+
return [2 /*return*/, error_2];
|
|
357
|
+
case 6: return [2 /*return*/];
|
|
340
358
|
}
|
|
341
359
|
});
|
|
342
360
|
}); };
|
package/build/utils/util.js
CHANGED
|
@@ -1260,12 +1260,11 @@ var replaceValuesFromRequestMapping = function (dataArr, mappingArray) {
|
|
|
1260
1260
|
};
|
|
1261
1261
|
exports.replaceValuesFromRequestMapping = replaceValuesFromRequestMapping;
|
|
1262
1262
|
var getAwsSignature = function (axiosConfig, awsSignPluginConfig) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1263
|
-
var response, method, headers, url, data, parsedUrl,
|
|
1263
|
+
var response, method, headers, url, data, parsedUrl, accessKeyId, secretAccessKey, region, service, signedRequest;
|
|
1264
1264
|
return __generator(this, function (_a) {
|
|
1265
1265
|
response = { error: "", data: {} };
|
|
1266
1266
|
method = axiosConfig.method, headers = axiosConfig.headers, url = axiosConfig.url, data = axiosConfig.data;
|
|
1267
1267
|
parsedUrl = new URL(url);
|
|
1268
|
-
payload = JSON.stringify(data);
|
|
1269
1268
|
if (awsSignPluginConfig) {
|
|
1270
1269
|
accessKeyId = awsSignPluginConfig.accessKeyId, secretAccessKey = awsSignPluginConfig.secretAccessKey, region = awsSignPluginConfig.region, service = awsSignPluginConfig.service;
|
|
1271
1270
|
signedRequest = (0, aws4_1.sign)({
|
|
@@ -1274,9 +1273,10 @@ var getAwsSignature = function (axiosConfig, awsSignPluginConfig) { return __awa
|
|
|
1274
1273
|
region: region,
|
|
1275
1274
|
host: parsedUrl.host,
|
|
1276
1275
|
headers: headers,
|
|
1277
|
-
body:
|
|
1276
|
+
body: data,
|
|
1277
|
+
path: parsedUrl.pathname + parsedUrl.search,
|
|
1278
1278
|
}, { accessKeyId: accessKeyId, secretAccessKey: secretAccessKey });
|
|
1279
|
-
response.data = signedRequest;
|
|
1279
|
+
response.data = __assign(__assign({}, signedRequest), { url: url });
|
|
1280
1280
|
return [2 /*return*/, response];
|
|
1281
1281
|
}
|
|
1282
1282
|
else
|