drapcode-utility 2.0.0 → 2.0.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.
Files changed (50) hide show
  1. package/build/encryption/KMS.js +54 -102
  2. package/build/encryption/crypt.d.ts +4 -2
  3. package/build/encryption/crypt.js +76 -91
  4. package/build/encryption/file.d.ts +0 -2
  5. package/build/encryption/file.js +14 -130
  6. package/build/encryption/index.js +162 -334
  7. package/build/encryption/utility.js +7 -10
  8. package/build/errors/app-error.js +9 -27
  9. package/build/errors/axios-error.js +3 -3
  10. package/build/errors/bad-request-error.js +10 -28
  11. package/build/errors/custom-error.js +5 -23
  12. package/build/errors/not-found.js +9 -27
  13. package/build/format-fields/index.d.ts +0 -1
  14. package/build/format-fields/index.js +32 -65
  15. package/build/index.d.ts +1 -4
  16. package/build/index.js +1 -4
  17. package/build/middlewares/error-logger.d.ts +1 -1
  18. package/build/middlewares/error-logger.js +29 -29
  19. package/build/middlewares/redis/request-log.js +24 -74
  20. package/build/query/queryBuilder.d.ts +9 -0
  21. package/build/query/queryBuilder.js +567 -0
  22. package/build/utils/check-error.d.ts +15 -8
  23. package/build/utils/check-error.js +71 -160
  24. package/build/utils/common-util.d.ts +40 -39
  25. package/build/utils/common-util.js +60 -59
  26. package/build/utils/date-util.d.ts +28 -7
  27. package/build/utils/date-util.js +180 -127
  28. package/build/utils/file-util.d.ts +51 -6
  29. package/build/utils/file-util.js +36 -40
  30. package/build/utils/prepare-query.js +70 -43
  31. package/build/utils/project-util.d.ts +43 -5
  32. package/build/utils/project-util.js +176 -121
  33. package/build/utils/query-parser.d.ts +1 -1
  34. package/build/utils/query-parser.js +289 -342
  35. package/build/utils/query-utils.d.ts +2 -2
  36. package/build/utils/query-utils.js +103 -116
  37. package/build/utils/rest-client.js +236 -328
  38. package/build/utils/s3-util.js +238 -469
  39. package/build/utils/token.js +34 -81
  40. package/build/utils/util.d.ts +58 -13
  41. package/build/utils/util.js +424 -494
  42. package/build/utils/uuid-generator.d.ts +20 -1
  43. package/build/utils/uuid-generator.js +111 -47
  44. package/package.json +7 -5
  45. package/build/middlewares/interceptor-logger-new.d.ts +0 -2
  46. package/build/middlewares/interceptor-logger-new.js +0 -53
  47. package/build/middlewares/interceptor-logger.d.ts +0 -2
  48. package/build/middlewares/interceptor-logger.js +0 -52
  49. package/build/utils/query-parser-new.d.ts +0 -1
  50. package/build/utils/query-parser-new.js +0 -541
@@ -1,86 +1,39 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
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
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.generateToken = void 0;
40
- var drapcode_redis_1 = require("drapcode-redis");
41
- var generateToken = function (projectId) { return __awaiter(void 0, void 0, void 0, function () {
42
- var timestamp, uniqueSessionId, characters, token, tokenLength, i, randomIndex, data, tokens, error_1;
43
- var _a;
44
- return __generator(this, function (_b) {
45
- switch (_b.label) {
46
- case 0:
47
- timestamp = Date.now().toString();
48
- uniqueSessionId = "unique_sessionid";
49
- _b.label = 1;
50
- case 1:
51
- _b.trys.push([1, 3, , 4]);
52
- characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
53
- token = "";
54
- tokenLength = 32;
55
- for (i = 0; i < tokenLength; i++) {
56
- randomIndex = Math.floor(Math.random() * characters.length);
57
- token += characters.charAt(randomIndex);
58
- }
59
- token = "".concat(token, ".").concat(timestamp);
60
- return [4 /*yield*/, (0, drapcode_redis_1.redis_get_method)(uniqueSessionId)];
61
- case 2:
62
- data = _b.sent();
63
- if (!data || !data[projectId] || !data[projectId].length) {
64
- data = (_a = {}, _a[projectId] = [token], _a);
65
- }
66
- else {
67
- tokens = data[projectId];
68
- if (tokens.length < 50) {
69
- tokens.push(token);
70
- }
71
- else {
72
- tokens.shift();
73
- tokens.push(token);
74
- }
75
- data[projectId] = tokens;
76
- }
77
- drapcode_redis_1.redisClient.setex(uniqueSessionId, 60 * 60, JSON.stringify(data), function (err, data) { });
78
- return [2 /*return*/, token];
79
- case 3:
80
- error_1 = _b.sent();
81
- throw new Error("Failed to generate token");
82
- case 4: return [2 /*return*/];
4
+ const drapcode_redis_1 = require("drapcode-redis");
5
+ const generateToken = async (projectId) => {
6
+ const timestamp = Date.now().toString();
7
+ const uniqueSessionId = `unique_sessionid`;
8
+ try {
9
+ const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
10
+ let token = "";
11
+ const tokenLength = 32;
12
+ for (let i = 0; i < tokenLength; i++) {
13
+ const randomIndex = Math.floor(Math.random() * characters.length);
14
+ token += characters.charAt(randomIndex);
15
+ }
16
+ token = `${token}.${timestamp}`;
17
+ let data = await (0, drapcode_redis_1.redis_get_method)(uniqueSessionId);
18
+ if (!data || !data[projectId] || !data[projectId].length) {
19
+ data = { [projectId]: [token] };
83
20
  }
84
- });
85
- }); };
21
+ else {
22
+ const tokens = data[projectId];
23
+ if (tokens.length < 50) {
24
+ tokens.push(token);
25
+ }
26
+ else {
27
+ tokens.shift();
28
+ tokens.push(token);
29
+ }
30
+ data[projectId] = tokens;
31
+ }
32
+ drapcode_redis_1.redisClient.setex(uniqueSessionId, 60 * 60, JSON.stringify(data));
33
+ return token;
34
+ }
35
+ catch (error) {
36
+ throw new Error("Failed to generate token");
37
+ }
38
+ };
86
39
  exports.generateToken = generateToken;
@@ -1,15 +1,60 @@
1
- export declare const validateString: (str: string) => false | "String should not contain special characters" | "String should not contain any number";
1
+ export declare const nonFindQuery: string[];
2
+ /**
3
+ * Validates a string for special characters and numbers
4
+ * @param str - The string to validate
5
+ * @returns Error message if invalid, false if valid
6
+ */
7
+ export declare const validateString: (str: string) => string | false;
8
+ /**
9
+ * Converts a string to camelCase
10
+ * @param str - The string to convert
11
+ * @returns The camelCase string
12
+ */
2
13
  export declare const camelize: (str: string) => string;
14
+ /**
15
+ * Clears spaces and reformats a string
16
+ * @param text - The text to format
17
+ * @param separator - Optional separator to use
18
+ * @returns The formatted string
19
+ */
3
20
  export declare const clearSpaceAndReformat: (text: string, separator?: string) => string;
4
- export declare const isEmpty: (obj: any) => boolean;
5
- export declare const isEmptyObject: (object: any) => boolean;
6
- export declare const isObject: (item: any) => any;
7
- export declare const dynamicSort: (property: any) => (a: any, b: any) => number;
8
- export declare const validateEmail: (email: string) => false | RegExpMatchArray | null;
9
- export declare const validateUuidString: (uuid: string) => false | RegExpMatchArray | null;
21
+ /**
22
+ * Checks if an object is empty
23
+ * @param obj - The object to check
24
+ * @returns True if the object is empty
25
+ */
26
+ export declare const isEmpty: (obj: Record<string, unknown>) => boolean;
27
+ /**
28
+ * Checks if an object is empty and is a plain object
29
+ * @param object - The object to check
30
+ * @returns True if the object is empty and is a plain object
31
+ */
32
+ export declare const isEmptyObject: (object: Record<string, unknown>) => boolean;
33
+ /**
34
+ * Checks if a value is an object
35
+ * @param item - The value to check
36
+ * @returns True if the value is an object
37
+ */
38
+ export declare const isObject: (item: unknown) => item is Record<string, unknown>;
39
+ /**
40
+ * Creates a dynamic sort function for an array
41
+ * @param property - The property to sort by
42
+ * @returns A sort function
43
+ */
44
+ export declare const dynamicSort: (property: string) => (a: Record<string, unknown>, b: Record<string, unknown>) => number;
45
+ /**
46
+ * Validates an email address
47
+ * @param email - The email to validate
48
+ * @returns True if the email is valid
49
+ */
50
+ export declare const validateEmail: (email: string) => boolean;
51
+ /**
52
+ * Validates a UUID string
53
+ * @param uuid - The UUID to validate
54
+ * @returns True if the UUID is valid
55
+ */
56
+ export declare const validateUuidString: (uuid: string) => boolean;
10
57
  export declare const getSpecialCharectorReplacedExpression: (expression: string) => string;
11
- export declare const expressionToString: (ex: string) => string;
12
- export declare const stringToExpression: (str: string) => string;
13
58
  export declare const cleanCollectionAndFieldName: (str: string) => string;
14
59
  export declare const formatCollectionAndFieldName: (str: string) => string;
15
60
  export declare const restructureData: (data: any) => any[];
@@ -59,7 +104,7 @@ export declare const evaluateJSLogic: (expression: string, data: any, user: any,
59
104
  export declare const formatDate: (formatType: string, datentime: any, timezone: string, unixType: any, offset?: boolean) => string;
60
105
  export declare const dateDifference: (formatType: string, datentime1: any, datentime2: any, timezone: string) => string;
61
106
  export declare const mergeObjects: (arrayOfObjects: any, data?: any, user?: any, tenant?: any, userSetting?: any, subTenant?: any, sessionValue?: any, envConstants?: any, sessionFormValue?: any, dataTransferObject?: any, localStorageValue?: any, cookiesValue?: any) => any;
62
- export declare const getFindQuery: (dataSourceType: string, item: any, customKey?: string) => {
107
+ export declare const getFindQuery: (item: any, customKey?: string) => {
63
108
  [x: string]: any;
64
109
  _data_source_rest_api_primary_id?: undefined;
65
110
  } | {
@@ -67,8 +112,8 @@ export declare const getFindQuery: (dataSourceType: string, item: any, customKey
67
112
  };
68
113
  export declare const getFileObjectList: (fileUrls: any, projectId: string) => any;
69
114
  export declare const getItemDataForArrayFields: (item: any, dataSourceItemKey: string) => any[];
70
- export declare const getMappingObjKey: (collectionMapping: any, fieldName: any) => any;
71
- export declare const getFieldSchemaForDataSourcePrimaryId: (dataSourceType: string) => {
115
+ export declare const getMappingObjKey: (collectionMapping: any | undefined, fieldName: any) => any;
116
+ export declare const getFieldSchemaForDataSourcePrimaryId: () => {
72
117
  required: boolean;
73
118
  staticOptions: never[];
74
119
  unique: boolean;
@@ -101,7 +146,7 @@ export declare const getFieldSchemaForDataSourcePrimaryId: (dataSourceType: stri
101
146
  };
102
147
  fieldName: string;
103
148
  };
104
- export declare const getPrimaryFieldNameOfDataSource: (dataSourceType: string) => string;
149
+ export declare const getPrimaryFieldNameOfDataSource: () => string;
105
150
  export declare const checkFieldValueType: (val: string) => boolean;
106
151
  export declare const replaceValuesFromObjArr: (dataArr: any[], mappingArray: any[]) => any[];
107
152
  export declare const replaceValuesFromRequestMapping: (dataArr: any[], mappingArray: any[]) => any[];