drapcode-utility 1.5.0 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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 (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ while (_) 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]) {
@@ -76,9 +76,9 @@ exports.createS3Client = createS3Client;
76
76
  var fileUploadToS3 = function (files, s3Client, s3Config, encryption, options) {
77
77
  if (options === void 0) { options = {}; }
78
78
  return __awaiter(void 0, void 0, void 0, function () {
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) {
79
+ var awsConfig, encryptionType, dataKey, accessKeyId, secretAccessKey, region, config, plainTextData, fileOptions, s3Key, _a, _b, _i, index, file, fileObj, fileObj;
80
+ return __generator(this, function (_c) {
81
+ switch (_c.label) {
82
82
  case 0:
83
83
  if (!encryption) return [3 /*break*/, 2];
84
84
  awsConfig = encryption.awsConfig, encryptionType = encryption.encryptionType, dataKey = encryption.dataKey;
@@ -89,41 +89,38 @@ var fileUploadToS3 = function (files, s3Client, s3Config, encryption, options) {
89
89
  accessKeyId: accessKeyId,
90
90
  secretAccessKey: secretAccessKey,
91
91
  };
92
- return [4 /*yield*/, (0, encryption_2.processKMSDecryption)(config, dataKey, {})];
92
+ return [4 /*yield*/, encryption_2.processKMSDecryption(config, dataKey, {})];
93
93
  case 1:
94
- plainTextData = _d.sent();
94
+ plainTextData = _c.sent();
95
95
  if (plainTextData.status === "FAILED") {
96
96
  return [2 /*return*/, plainTextData];
97
97
  }
98
98
  encryption.dataKey = plainTextData.data;
99
- _d.label = 2;
99
+ _c.label = 2;
100
100
  case 2:
101
101
  if (!Array.isArray(files)) return [3 /*break*/, 7];
102
102
  console.log("I have multiple file");
103
103
  fileOptions = [];
104
104
  s3Key = s3Config.key;
105
- _a = files;
106
- _b = [];
107
- for (_c in _a)
108
- _b.push(_c);
105
+ _a = [];
106
+ for (_b in files)
107
+ _a.push(_b);
109
108
  _i = 0;
110
- _d.label = 3;
109
+ _c.label = 3;
111
110
  case 3:
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;
111
+ if (!(_i < _a.length)) return [3 /*break*/, 6];
112
+ index = _a[_i];
116
113
  file = files[index];
117
114
  if (s3Config.append) {
118
- s3Config.key = "".concat(s3Key, "/").concat((0, uuid_1.v4)(), "/").concat(file.originalname);
115
+ s3Config.key = s3Key + "/" + uuid_1.v4() + "/" + file.originalname;
119
116
  }
120
117
  return [4 /*yield*/, processFileUploadToS3(file, s3Client, s3Config, encryption, options, encryption ? true : false)];
121
118
  case 4:
122
- fileObj = _d.sent();
119
+ fileObj = _c.sent();
123
120
  if (fileObj) {
124
121
  fileOptions.push(fileObj);
125
122
  }
126
- _d.label = 5;
123
+ _c.label = 5;
127
124
  case 5:
128
125
  _i++;
129
126
  return [3 /*break*/, 3];
@@ -131,11 +128,11 @@ var fileUploadToS3 = function (files, s3Client, s3Config, encryption, options) {
131
128
  case 7:
132
129
  console.log("I have single file");
133
130
  if (s3Config.append) {
134
- s3Config.key = "".concat(s3Config.key, "/").concat((0, uuid_1.v4)(), "/").concat(files.originalname);
131
+ s3Config.key = s3Config.key + "/" + uuid_1.v4() + "/" + files.originalname;
135
132
  }
136
133
  return [4 /*yield*/, processFileUploadToS3(files, s3Client, s3Config, encryption, options, encryption ? true : false)];
137
134
  case 8:
138
- fileObj = _d.sent();
135
+ fileObj = _c.sent();
139
136
  return [2 /*return*/, fileObj];
140
137
  }
141
138
  });
@@ -159,7 +156,7 @@ var processFileUploadToS3 = function (file, s3Client, s3Config, encryption, opti
159
156
  params = null;
160
157
  encryptedFilePath = null;
161
158
  if (!encrypt) return [3 /*break*/, 3];
162
- return [4 /*yield*/, (0, encryption_1.cryptFile)(file.path, encryption, false)];
159
+ return [4 /*yield*/, encryption_1.cryptFile(file.path, encryption, false)];
163
160
  case 2:
164
161
  encryptedFilePath = _a.sent();
165
162
  console.log("encryptedFilePath", encryptedFilePath);
@@ -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 (g && (g = 0, op[0] && (_ = 0)), _) try {
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]) {
@@ -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 = "".concat(token, ".").concat(timestamp);
60
- return [4 /*yield*/, (0, drapcode_redis_1.redis_get_method)(uniqueSessionId)];
59
+ token = token + "." + timestamp;
60
+ return [4 /*yield*/, 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) {
@@ -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;
@@ -21,14 +21,10 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  }
22
22
  return t;
23
23
  };
24
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
25
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
26
- if (ar || !(i in from)) {
27
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
28
- ar[i] = from[i];
29
- }
30
- }
31
- return to.concat(ar || Array.prototype.slice.call(from));
24
+ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
25
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
26
+ to[j] = from[i];
27
+ return to;
32
28
  };
33
29
  var __importDefault = (this && this.__importDefault) || function (mod) {
34
30
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -81,7 +77,7 @@ var validateString = function (str) {
81
77
  };
82
78
  exports.validateString = validateString;
83
79
  var camelize = function (str) {
84
- str = (0, exports.clearSpaceAndReformat)(str);
80
+ str = exports.clearSpaceAndReformat(str);
85
81
  return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
86
82
  return index === 0 ? word.toLowerCase() : word.toUpperCase();
87
83
  });
@@ -208,8 +204,8 @@ var cleanCollectionAndFieldName = function (str) {
208
204
  };
209
205
  exports.cleanCollectionAndFieldName = cleanCollectionAndFieldName;
210
206
  var formatCollectionAndFieldName = function (str) {
211
- var updateString = (0, exports.cleanCollectionAndFieldName)(str);
212
- return (0, exports.clearSpaceAndReformat)(updateString.trim(), "_");
207
+ var updateString = exports.cleanCollectionAndFieldName(str);
208
+ return exports.clearSpaceAndReformat(updateString.trim(), "_");
213
209
  };
214
210
  exports.formatCollectionAndFieldName = formatCollectionAndFieldName;
215
211
  var restructureData = function (data) {
@@ -240,7 +236,7 @@ var restructureData = function (data) {
240
236
  exports.restructureData = restructureData;
241
237
  var checkAndCompareValue = function (input1, input2) {
242
238
  return Array.isArray(input2)
243
- ? (0, exports.arraysEqual)(input1, input2.map(function (key) { return key.value; }))
239
+ ? exports.arraysEqual(input1, input2.map(function (key) { return key.value; }))
244
240
  : input1 === input2.value;
245
241
  };
246
242
  exports.checkAndCompareValue = checkAndCompareValue;
@@ -250,7 +246,7 @@ var arraysEqual = function (array1, array2) {
250
246
  return false;
251
247
  for (var i = 0; i < array1.length; i++ // assert each element equal
252
248
  )
253
- if (!(0, exports.arraysEqual)(array1[i], array2[i]))
249
+ if (!exports.arraysEqual(array1[i], array2[i]))
254
250
  return false;
255
251
  return true;
256
252
  }
@@ -285,7 +281,7 @@ var formatCustomCSSClasses = function (customClasses) {
285
281
  .replace(/"([^"]+)"/g, "$1")
286
282
  .split(",")
287
283
  .join(";");
288
- projectCustomCSSClassesData += "".concat(element.class.startsWith(".") ? element.class : "." + element.class).concat(element.pseudoClass ? ":" + element.pseudoClass : "").concat(unquotedClassWithProp, " ");
284
+ projectCustomCSSClassesData += "" + (element.class.startsWith(".") ? element.class : "." + element.class) + (element.pseudoClass ? ":" + element.pseudoClass : "") + unquotedClassWithProp + " ";
289
285
  }
290
286
  });
291
287
  return projectCustomCSSClassesData;
@@ -296,18 +292,18 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, s
296
292
  var contentList = (_a = expression
297
293
  .match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
298
294
  contentList === null || contentList === void 0 ? void 0 : contentList.forEach(function (prop) {
299
- var needle = "{{".concat(prop, "}}");
295
+ var needle = "{{" + prop + "}}";
300
296
  var dataOfItem = "";
301
297
  if (prop.includes("current_user")) {
302
298
  prop = prop.replace("current_user.", "");
303
299
  if (Object.keys(user).length > 0) {
304
- dataOfItem = (0, exports.parseValueFromData)(user, prop);
300
+ dataOfItem = exports.parseValueFromData(user, prop);
305
301
  }
306
302
  }
307
303
  else if (prop.includes("current_tenant")) {
308
304
  prop = prop.replace("current_tenant.", "");
309
305
  if (Object.keys(tenant).length > 0) {
310
- dataOfItem = (0, exports.parseValueFromData)(tenant, prop);
306
+ dataOfItem = exports.parseValueFromData(tenant, prop);
311
307
  }
312
308
  }
313
309
  else if (prop.includes("current_session")) {
@@ -333,7 +329,7 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, s
333
329
  }
334
330
  else {
335
331
  if (Object.keys(data).length > 0) {
336
- dataOfItem = (0, exports.parseValueFromData)(data, prop);
332
+ dataOfItem = exports.parseValueFromData(data, prop);
337
333
  //TODO: Need better way
338
334
  delete data[prop];
339
335
  }
@@ -433,7 +429,7 @@ var replaceTransferObjectValueIntoExpression = function (expression, transferObj
433
429
  var contentList = (_a = expression
434
430
  .match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
435
431
  contentList === null || contentList === void 0 ? void 0 : contentList.forEach(function (prop) {
436
- var needle = "{{".concat(prop, "}}");
432
+ var needle = "{{" + prop + "}}";
437
433
  var dataOfItem = "";
438
434
  dataOfItem = transferObject[prop] ? transferObject[prop] : "";
439
435
  expression = dataOfItem
@@ -479,8 +475,8 @@ var processFieldsInlcude = function (fieldsInclude) {
479
475
  fieldsInclude = fieldsInclude.filter(function (field) { return !(field.startsWith("RF::") || field.startsWith("DF::")); });
480
476
  var refFields = processReferenceFieldInclude(refFieldsInclude);
481
477
  var derivedFields = processDerivedFieldInclude(derivedFieldsInclude);
482
- var extraField = __spreadArray(__spreadArray([], refFields, true), derivedFields, true).filter(function (value, index, array) { return array.indexOf(value) === index; });
483
- result = __spreadArray(__spreadArray([], fieldsInclude, true), extraField, true);
478
+ var extraField = __spreadArray(__spreadArray([], refFields), derivedFields).filter(function (value, index, array) { return array.indexOf(value) === index; });
479
+ result = __spreadArray(__spreadArray([], fieldsInclude), extraField);
484
480
  return result;
485
481
  };
486
482
  exports.processFieldsInlcude = processFieldsInlcude;
@@ -505,16 +501,16 @@ var processDerivedFieldInclude = function (derivedFieldsInclude) {
505
501
  if (arg.name === "expression") {
506
502
  var needleList = (_a = arg.key
507
503
  .match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
508
- var tempFields = (0, exports.processFieldsInlcude)(needleList);
509
- fields = __spreadArray(__spreadArray([], fields, true), tempFields, true);
504
+ var tempFields = exports.processFieldsInlcude(needleList);
505
+ fields = __spreadArray(__spreadArray([], fields), tempFields);
510
506
  }
511
507
  else if (!derivedFieldExcludes.includes(arg.name)) {
512
508
  var tempFields = Array.isArray(arg.key) ? arg.key : [arg.key];
513
- tempFields = (0, exports.processFieldsInlcude)(tempFields);
514
- fields = __spreadArray(__spreadArray([], fields, true), tempFields, true);
509
+ tempFields = exports.processFieldsInlcude(tempFields);
510
+ fields = __spreadArray(__spreadArray([], fields), tempFields);
515
511
  }
516
512
  });
517
- derivedFields = __spreadArray(__spreadArray([], derivedFields, true), fields, true);
513
+ derivedFields = __spreadArray(__spreadArray([], derivedFields), fields);
518
514
  });
519
515
  return derivedFields;
520
516
  };
@@ -590,7 +586,7 @@ var assignFieldValue = function (formattedField, field, fieldName, filledItemdat
590
586
  value = formattedField.extraFieldSetting
591
587
  ? formattedField.extraFieldSetting.defaultValue
592
588
  : filledItemdata[fieldName];
593
- value = (0, format_fields_1.getFormatFieldData)(value, field.type);
589
+ value = format_fields_1.getFormatFieldData(value, field.type);
594
590
  return value;
595
591
  };
596
592
  var validateData = function (fields, data) {
@@ -611,7 +607,7 @@ var validateData = function (fields, data) {
611
607
  fieldValue = JSON.parse(fieldValue);
612
608
  }
613
609
  catch (error) {
614
- errors.push("Error parsing ".concat(fieldTitle, ": ").concat(error.message));
610
+ errors.push("Error parsing " + fieldTitle + ": " + error.message);
615
611
  return;
616
612
  }
617
613
  }
@@ -620,50 +616,50 @@ var validateData = function (fields, data) {
620
616
  if (typeof fieldValue !== "string" &&
621
617
  typeof fieldValue !== "number" &&
622
618
  Object.prototype.toString.call(fieldValue) !== "[object Date]") {
623
- errors.push("".concat(fieldTitle, " must be a string"));
619
+ errors.push(fieldTitle + " must be a string");
624
620
  }
625
621
  break;
626
622
  case "large_text":
627
623
  case "color":
628
624
  if (typeof fieldValue !== "string") {
629
- errors.push("".concat(fieldTitle, " must be a string"));
625
+ errors.push(fieldTitle + " must be a string");
630
626
  }
631
627
  break;
632
628
  case "uuid":
633
- if (typeof fieldValue !== "string" || !(0, uuid_1.validate)(fieldValue)) {
634
- errors.push("".concat(fieldTitle, " must be a valid UUID string"));
629
+ if (typeof fieldValue !== "string" || !uuid_1.validate(fieldValue)) {
630
+ errors.push(fieldTitle + " must be a valid UUID string");
635
631
  }
636
632
  break;
637
633
  case "reference":
638
634
  case "belongsTo":
639
635
  if (!Array.isArray(fieldValue) ||
640
636
  fieldValue.some(function (item) { return typeof item !== "string"; })) {
641
- errors.push("".concat(fieldTitle, " must be an array of valid UUID strings"));
637
+ errors.push(fieldTitle + " must be an array of valid UUID strings");
642
638
  }
643
639
  break;
644
640
  case "createdAt":
645
641
  case "updatedAt":
646
642
  case "date":
647
643
  if (fieldValue && isNaN(Date.parse(fieldValue))) {
648
- errors.push("".concat(fieldTitle, " must be a valid date"));
644
+ errors.push(fieldTitle + " must be a valid date");
649
645
  }
650
646
  break;
651
647
  case "boolean":
652
648
  if (typeof fieldValue !== "boolean") {
653
- errors.push("".concat(fieldTitle, " must be a boolean"));
649
+ errors.push(fieldTitle + " must be a boolean");
654
650
  }
655
651
  break;
656
652
  case "email":
657
653
  if (typeof fieldValue !== "string" ||
658
654
  !/\S+@\S+\.\S+/.test(fieldValue)) {
659
- errors.push("".concat(fieldTitle, " must be a valid email address"));
655
+ errors.push(fieldTitle + " must be a valid email address");
660
656
  break;
661
657
  }
662
658
  break;
663
659
  case "tel":
664
660
  var telPattern = /^\+?(\d{1,3})?[-\s]?(\(\d{1,4}\)|\d{1,4})[-\s]?(\d{1,4}[-\s]?\d{1,4}|\d{7,10})$/;
665
661
  if (typeof fieldValue !== "string" || !telPattern.test(fieldValue)) {
666
- errors.push("".concat(fieldTitle, " must be a valid phone number"));
662
+ errors.push(fieldTitle + " must be a valid phone number");
667
663
  }
668
664
  break;
669
665
  case "static_option":
@@ -673,16 +669,16 @@ var validateData = function (fields, data) {
673
669
  }
674
670
  else if (Array.isArray(fieldValue)) {
675
671
  if (fieldValue.some(function (item) { return typeof item !== "string"; })) {
676
- errors.push("".concat(fieldTitle, " must be an array of strings"));
672
+ errors.push(fieldTitle + " must be an array of strings");
677
673
  }
678
674
  }
679
675
  else {
680
- errors.push("".concat(fieldTitle, " must be a string or an array of strings"));
676
+ errors.push(fieldTitle + " must be a string or an array of strings");
681
677
  }
682
678
  break;
683
679
  case "url":
684
- if (typeof fieldValue !== "string" || !(0, exports.validateUrl)(fieldValue)) {
685
- errors.push("".concat(fieldTitle, " must be a valid URL"));
680
+ if (typeof fieldValue !== "string" || !exports.validateUrl(fieldValue)) {
681
+ errors.push(fieldTitle + " must be a valid URL");
686
682
  }
687
683
  break;
688
684
  case "file":
@@ -692,18 +688,18 @@ var validateData = function (fields, data) {
692
688
  !item.key ||
693
689
  typeof item.key !== "string";
694
690
  })) {
695
- errors.push("".concat(fieldTitle, " must be an array of objects with 'key' property as string"));
691
+ errors.push(fieldTitle + " must be an array of objects with 'key' property as string");
696
692
  }
697
693
  }
698
694
  else if (typeof fieldValue !== "object" ||
699
695
  !fieldValue.key ||
700
696
  typeof fieldValue.key !== "string") {
701
- errors.push("".concat(fieldTitle, " must be an object with 'key' property as string"));
697
+ errors.push(fieldTitle + " must be an object with 'key' property as string");
702
698
  }
703
699
  break;
704
700
  case "number":
705
701
  if (isNaN(Number(fieldValue))) {
706
- errors.push("".concat(fieldTitle, " must be a valid number."));
702
+ errors.push(fieldTitle + " must be a valid number.");
707
703
  }
708
704
  break;
709
705
  default:
@@ -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 = "".concat(prepend).concat(finalValue);
41
+ finalValue = "" + prepend + finalValue;
42
42
  }
43
43
  if (append) {
44
- finalValue = "".concat(finalValue).concat(append);
44
+ finalValue = "" + finalValue + append;
45
45
  }
46
46
  return finalValue;
47
47
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drapcode-utility",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -33,8 +33,8 @@
33
33
  "@types/express": "^4.17.7",
34
34
  "@types/voca": "^1.4.2",
35
35
  "axios": "^1.1.2",
36
- "drapcode-constant": "^1.4.2",
37
- "drapcode-logger": "^1.1.4",
36
+ "drapcode-constant": "^1.4.5",
37
+ "drapcode-logger": "^1.1.6",
38
38
  "drapcode-redis": "^1.0.5",
39
39
  "express": "^4.17.1",
40
40
  "lodash": "^4.17.21",