drapcode-utility 1.0.0 → 1.0.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.
@@ -7,6 +7,8 @@ var __extends = (this && this.__extends) || (function () {
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
10
12
  extendStatics(d, b);
11
13
  function __() { this.constructor = d; }
12
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -8,6 +8,3 @@ export declare const parseAxiosError: (error: AxiosError) => {
8
8
  error: any;
9
9
  status: number;
10
10
  };
11
- export declare const parseXanoConfigError: (error: any) => string;
12
- export declare const parseAirtableConfigError: (error: any) => string;
13
- export declare const parseSupabaseConfigError: (error: any) => string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseSupabaseConfigError = exports.parseAirtableConfigError = exports.parseXanoConfigError = exports.parseAxiosError = void 0;
3
+ exports.parseAxiosError = void 0;
4
4
  var parseAxiosError = function (error) {
5
5
  if (!error) {
6
6
  return {};
@@ -29,50 +29,3 @@ var parseAxiosError = function (error) {
29
29
  return { success: false, error: errData, status: errStatus };
30
30
  };
31
31
  exports.parseAxiosError = parseAxiosError;
32
- var parseXanoConfigError = function (error) {
33
- if (!error || !error.code) {
34
- return "Failed from Xano";
35
- }
36
- var errorMessage = "";
37
- switch (error.code) {
38
- case "ERROR_CODE_UNAUTHORIZED":
39
- errorMessage = "Developer API Key is wrong";
40
- break;
41
- default:
42
- errorMessage = "Failed from Xano";
43
- break;
44
- }
45
- return errorMessage;
46
- };
47
- exports.parseXanoConfigError = parseXanoConfigError;
48
- var parseAirtableConfigError = function (error) {
49
- if (!error || !error.error || !error.error.type) {
50
- return "Failed from Airtable";
51
- }
52
- var errorMessage = "";
53
- switch (error.error.type) {
54
- case "AUTHENTICATION_REQUIRED":
55
- errorMessage = "Authorization is missing/wrong.";
56
- break;
57
- default:
58
- errorMessage = "Failed from Airtable";
59
- break;
60
- }
61
- return errorMessage;
62
- };
63
- exports.parseAirtableConfigError = parseAirtableConfigError;
64
- var parseSupabaseConfigError = function (error) {
65
- if (!error) {
66
- return "Failed from Supabase";
67
- }
68
- var errorMessage = "";
69
- switch (error) {
70
- case "ENOTFOUND":
71
- errorMessage = "Given Supabase URL does not exists/API Key is wrong";
72
- break;
73
- default:
74
- break;
75
- }
76
- return errorMessage;
77
- };
78
- exports.parseSupabaseConfigError = parseSupabaseConfigError;
@@ -7,6 +7,8 @@ var __extends = (this && this.__extends) || (function () {
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
10
12
  extendStatics(d, b);
11
13
  function __() { this.constructor = d; }
12
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -7,6 +7,8 @@ var __extends = (this && this.__extends) || (function () {
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
10
12
  extendStatics(d, b);
11
13
  function __() { this.constructor = d; }
12
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -7,6 +7,8 @@ var __extends = (this && this.__extends) || (function () {
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
10
12
  extendStatics(d, b);
11
13
  function __() { this.constructor = d; }
12
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -35,12 +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 __spreadArrays = (this && this.__spreadArrays) || function () {
39
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
40
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
41
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
42
- r[k] = a[j];
43
- return r;
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;
44
42
  };
45
43
  var __importDefault = (this && this.__importDefault) || function (mod) {
46
44
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -176,7 +174,7 @@ var nestedValue = function (data, messages) {
176
174
  messages.push(value);
177
175
  }
178
176
  else if (Array.isArray(value)) {
179
- messages = __spreadArrays(messages, value);
177
+ messages = __spreadArray(__spreadArray([], messages), value);
180
178
  }
181
179
  else {
182
180
  if (Object.keys(value).length) {
@@ -1,8 +1,8 @@
1
1
  export declare const DATE_REGEX: RegExp;
2
- export declare const createLoggerDateFormat: () => any;
2
+ export declare const createLoggerDateFormat: (timezone?: string) => any;
3
3
  export declare const createLoggerPreviouseDateFormat: () => any;
4
- export declare const createLogsDateFormat: () => any;
5
- export declare const getDateValue: (value: string) => any;
4
+ export declare const createLogsDateFormat: (timezone?: string) => any;
5
+ export declare const getDateValue: (value: string, timezone?: string) => any;
6
6
  export declare const nextDayDate: (date: any) => any;
7
7
  export declare const timezoneDateParse: (value: string, nextDay?: boolean, prevDay?: boolean) => Date;
8
8
  export declare const formatProjectDates: (item: any, dateFormat: string, fields: Array<object>, reverse: boolean) => any;
@@ -4,32 +4,46 @@ exports.formatProjectDates = exports.timezoneDateParse = exports.nextDayDate = e
4
4
  var drapcode_constant_1 = require("drapcode-constant");
5
5
  var moment = require("moment");
6
6
  exports.DATE_REGEX = /^[12]\d{3}(-(0[1-9]|1[0-2])(-(0[1-9]|[12][0-9]|3[01]))?)(T| )?(([01][0-9]|2[0-3]):[0-5]\d(:[0-5]\d(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?)?$/;
7
- var createLoggerDateFormat = function () {
8
- return moment().format("YYYY-MM-DD");
7
+ var createLoggerDateFormat = function (timezone) {
8
+ if (timezone === void 0) { timezone = ""; }
9
+ var result = moment();
10
+ console.log("\n result 1 :>> ", result);
11
+ result = timezone ? result.utcOffset(timezone) : result;
12
+ console.log("\n result 2 :>> ", result);
13
+ return result.format("YYYY-MM-DD");
9
14
  };
10
15
  exports.createLoggerDateFormat = createLoggerDateFormat;
11
16
  var createLoggerPreviouseDateFormat = function () {
12
17
  return moment().subtract(10, "days").format("YYYY-MM-DD");
13
18
  };
14
19
  exports.createLoggerPreviouseDateFormat = createLoggerPreviouseDateFormat;
15
- var createLogsDateFormat = function () {
16
- return moment().format("YYYY-MM-DDTHH:mm:ss.SSS");
20
+ var createLogsDateFormat = function (timezone) {
21
+ if (timezone === void 0) { timezone = ""; }
22
+ var result = moment();
23
+ console.log("\n result 1 :>> ", result);
24
+ result = timezone ? result.utcOffset(timezone) : result;
25
+ console.log("\n result 2 :>> ", result);
26
+ return result.format("YYYY-MM-DDTHH:mm:ss.SSS");
17
27
  };
18
28
  exports.createLogsDateFormat = createLogsDateFormat;
19
- var getDateValue = function (value) {
29
+ var getDateValue = function (value, timezone) {
30
+ if (timezone === void 0) { timezone = ""; }
20
31
  if (!value)
21
- return exports.createLogsDateFormat();
32
+ return exports.createLogsDateFormat(timezone);
22
33
  var dateFormat = "YYYY-MM-DDTHH:mm:ss.SSS";
23
34
  var _a = value.split(":"), type = _a[0], number = _a[1], unit = _a[2];
35
+ if (!["ADD", "SUB"].includes(type))
36
+ return exports.createLogsDateFormat(timezone);
24
37
  var dateUnit = getDateUnit(unit);
38
+ var result;
25
39
  if (type === "ADD") {
26
- return moment().add(number, dateUnit).format(dateFormat);
40
+ result = moment().add(number, dateUnit);
27
41
  }
28
42
  else if (type === "SUB") {
29
- return moment().subtract(number, dateUnit).format(dateFormat);
43
+ result = moment().subtract(number, dateUnit);
30
44
  }
31
- else
32
- return exports.createLogsDateFormat();
45
+ result = timezone ? result.utcOffset(timezone) : result;
46
+ return result.format(dateFormat);
33
47
  };
34
48
  exports.getDateValue = getDateValue;
35
49
  var getDateUnit = function (unit) {
@@ -35,12 +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 __spreadArrays = (this && this.__spreadArrays) || function () {
39
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
40
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
41
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
42
- r[k] = a[j];
43
- return r;
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;
44
42
  };
45
43
  var __importDefault = (this && this.__importDefault) || function (mod) {
46
44
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -68,7 +66,7 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
68
66
  if (!query)
69
67
  return [2 /*return*/, ""];
70
68
  console.log("***1*** queryParser ***");
71
- filterQuery = mongoFilterQuery(query, externalParams, constants, currentUser, currentTenant);
69
+ filterQuery = mongoFilterQuery(query, externalParams, constants, currentUser, currentTenant, timezone);
72
70
  console.log("**************************");
73
71
  console.log("filterQuery", JSON.stringify(filterQuery));
74
72
  console.log("==> searchQueryTypeObj :>>", searchQueryTypeObj);
@@ -80,7 +78,7 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
80
78
  searchQueryObj = null;
81
79
  if (searchObj) {
82
80
  _a = getSearchObjQuery(searchObj, searchQueryTypeObj, timezone), searchAggregateQuery = _a.searchAggregateQuery, likeQuery = _a.likeQuery;
83
- aggregateQuery = __spreadArrays(aggregateQuery, searchAggregateQuery);
81
+ aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery), searchAggregateQuery);
84
82
  if (likeQuery && likeQuery.length > 0) {
85
83
  searchQueryObj = likeQuery;
86
84
  }
@@ -93,7 +91,7 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
93
91
  }
94
92
  else if (searchObj) {
95
93
  _b = getSearchObjQuery(searchObj, searchQueryTypeObj, timezone), searchAggregateQuery = _b.searchAggregateQuery, likeQuery = _b.likeQuery;
96
- aggregateQuery = __spreadArrays(aggregateQuery, searchAggregateQuery);
94
+ aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery), searchAggregateQuery);
97
95
  if (likeQuery.length) {
98
96
  // aggregateQuery.push({ $match: { $or: likeQuery } });
99
97
  aggregateQuery.push({ $match: { $and: likeQuery } });
@@ -233,7 +231,7 @@ var toBoolean = function (value) {
233
231
  return false;
234
232
  }
235
233
  };
236
- var mongoFilterQuery = function (query, externalParams, constants, currentUser, currentTenant) {
234
+ var mongoFilterQuery = function (query, externalParams, constants, currentUser, currentTenant, timezone) {
237
235
  if (currentUser === void 0) { currentUser = {}; }
238
236
  if (currentTenant === void 0) { currentTenant = {}; }
239
237
  var filterQuery = { $or0: [] };
@@ -242,7 +240,7 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser,
242
240
  conditions.forEach(function (queryObj, index) {
243
241
  var query = queryObj.query, requiredExternal = queryObj.requiredExternal;
244
242
  console.log("query :>> ", JSON.stringify(query));
245
- var mongoQuery = queryToMongo(query, requiredExternal, externalParams, constants, currentUser, currentTenant);
243
+ var mongoQuery = queryToMongo(query, requiredExternal, externalParams, constants, currentUser, currentTenant, timezone);
246
244
  console.log(":::::::::mongoQuery::::", JSON.stringify(mongoQuery));
247
245
  queryConjunctions.push(queryObj.conjunctionType);
248
246
  if (queryObj.conjunctionType == "OR") {
@@ -311,11 +309,11 @@ var modifyQuery = function (obj, hasAndQueryConjunction) {
311
309
  console.log("🚀 ~ file: query-parser.ts:303 ~ Object.entries ~ arr:", arr);
312
310
  return arr;
313
311
  };
314
- var queryToMongo = function (query, requiredExternal, externalParams, constants, currentUser, currentTenant) {
312
+ var queryToMongo = function (query, requiredExternal, externalParams, constants, currentUser, currentTenant, timezone) {
315
313
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
316
314
  if (currentUser === void 0) { currentUser = {}; }
317
315
  if (currentTenant === void 0) { currentTenant = {}; }
318
- var fieldValue = replaceExternalParams(query, requiredExternal, externalParams, constants, currentUser, currentTenant);
316
+ var fieldValue = replaceExternalParams(query, requiredExternal, externalParams, constants, currentUser, currentTenant, timezone);
319
317
  if (["undefined", "null", null, undefined, ""].includes(fieldValue)) {
320
318
  //TODO: In case field is not present in old record then fieldValue is undefined
321
319
  //TODO: In case of this, we assign some random string to avoid resulting all values
@@ -327,8 +325,8 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
327
325
  var isDate = checkDate(fieldValue);
328
326
  console.log("isDate queryToMongo 2", isDate);
329
327
  var key = query.key, field = query.field, value = query.value, fieldType = query.fieldType;
330
- if (isDate)
331
- fieldValue = new Date(fieldValue);
328
+ // Todo: Remove if it's working properly
329
+ // if (isDate) fieldValue = new Date(fieldValue);
332
330
  console.log("fieldValue queryToMongo 1", fieldValue);
333
331
  var condition = [
334
332
  "dynamic_option",
@@ -458,7 +456,7 @@ var isEntityInCondition = function (value) {
458
456
  return isEntity;
459
457
  };
460
458
  exports.isEntityInCondition = isEntityInCondition;
461
- var replaceExternalParams = function (query, requiredExternal, externalParams, constants, currentUser, currentTenant) {
459
+ var replaceExternalParams = function (query, requiredExternal, externalParams, constants, currentUser, currentTenant, timezone) {
462
460
  var key = query.key, value = query.value, fieldType = query.fieldType;
463
461
  if (fieldType &&
464
462
  !requiredExternal &&
@@ -490,16 +488,16 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
490
488
  endValue_1 = "" + externalParams[endValue_1];
491
489
  }
492
490
  else {
493
- if (__spreadArrays([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) {
491
+ if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) {
494
492
  return startValue_1.includes(cnst);
495
493
  })) {
496
- startValue_1 = getValueOfProjectConstant(startValue_1, currentUser);
494
+ startValue_1 = getValueOfProjectConstant(startValue_1, currentUser, timezone);
497
495
  }
498
496
  else {
499
497
  startValue_1 = constants.filter(function (constant) { return constant.name == startValue_1; });
500
498
  }
501
- if (__spreadArrays([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) { return endValue_1.includes(cnst); })) {
502
- endValue_1 = getValueOfProjectConstant(endValue_1, currentUser);
499
+ if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) { return endValue_1.includes(cnst); })) {
500
+ endValue_1 = getValueOfProjectConstant(endValue_1, currentUser, timezone);
503
501
  }
504
502
  else {
505
503
  endValue_1 = constants.filter(function (constant) { return constant.name == endValue_1; });
@@ -611,7 +609,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
611
609
  return currentTenant["uuid"];
612
610
  }
613
611
  if (drapcode_constant_1.DateConstant.some(function (cnst) { return value.includes(cnst); })) {
614
- return getValueOfProjectConstant(value, {});
612
+ return getValueOfProjectConstant(value, {}, timezone);
615
613
  }
616
614
  if (exports.isEntityInCondition(value)) {
617
615
  var key_1 = value.replace("ENTITY::", "");
@@ -647,15 +645,20 @@ var getMinMaxValue = function (value) {
647
645
  }
648
646
  };
649
647
  exports.getMinMaxValue = getMinMaxValue;
650
- var getValueOfProjectConstant = function (value, currentUser) {
648
+ var getValueOfProjectConstant = function (value, currentUser, timezone) {
649
+ if (!timezone)
650
+ timezone = "(GMT+5:30)";
651
+ timezone = timezone.substring(4, 10);
652
+ var result;
651
653
  if (value === drapcode_constant_1.CURRENT_USER)
652
654
  return currentUser["uuid"];
653
655
  if (value === drapcode_constant_1.CURRENT_DATE)
654
- return date_util_1.createLoggerDateFormat();
656
+ result = date_util_1.createLoggerDateFormat(timezone);
655
657
  if ([drapcode_constant_1.CURRENT_TIME, drapcode_constant_1.CURRENT_DATE_TIME].includes(value))
656
- return date_util_1.createLogsDateFormat();
658
+ result = date_util_1.createLogsDateFormat(timezone);
657
659
  if (drapcode_constant_1.DateTimeUnit.some(function (cnst) { return value.includes(cnst); }))
658
- return date_util_1.getDateValue(value);
660
+ result = date_util_1.getDateValue(value, timezone);
661
+ return result;
659
662
  };
660
663
  var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
661
664
  var searchAggregateQuery = [];
@@ -35,12 +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 __spreadArrays = (this && this.__spreadArrays) || function () {
39
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
40
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
41
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
42
- r[k] = a[j];
43
- return r;
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;
44
42
  };
45
43
  Object.defineProperty(exports, "__esModule", { value: true });
46
44
  exports.queryParserNew = void 0;
@@ -573,7 +571,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
573
571
  endValue_1 = "" + externalParams[endValue_1];
574
572
  }
575
573
  else {
576
- if (__spreadArrays([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) {
574
+ if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) {
577
575
  return startValue_1.includes(cnst);
578
576
  })) {
579
577
  startValue_1 = getValueOfProjectConstant(startValue_1, currentUser);
@@ -581,7 +579,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
581
579
  else {
582
580
  startValue_1 = constants.filter(function (constant) { return constant.name == startValue_1; });
583
581
  }
584
- if (__spreadArrays([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) { return endValue_1.includes(cnst); })) {
582
+ if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) { return endValue_1.includes(cnst); })) {
585
583
  endValue_1 = getValueOfProjectConstant(endValue_1, currentUser);
586
584
  }
587
585
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drapcode-utility",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",