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,204 +1,115 @@
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
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
- if (ar || !(i in from)) {
41
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
- ar[i] = from[i];
43
- }
44
- }
45
- return to.concat(ar || Array.prototype.slice.call(from));
46
- };
47
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
48
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
49
4
  };
50
5
  Object.defineProperty(exports, "__esModule", { value: true });
51
6
  exports.checkForError = void 0;
52
- var lodash_1 = __importDefault(require("lodash"));
53
- var voca_1 = __importDefault(require("voca"));
54
- var checkForError = function (result, errors, mapping, status) { return __awaiter(void 0, void 0, void 0, function () {
55
- var finalErrors, errorMsgPath, errorValue, fError, finalFinalStatus_1, finalMessage, finalMessages_1;
56
- return __generator(this, function (_a) {
57
- console.log("\n ==result", result);
58
- finalErrors = [];
59
- console.log("errors", errors);
60
- if (errors && errors.length > 0) {
61
- console.log("I have multi error setting");
62
- errors.forEach(function (error, index) {
63
- console.log("Checking for error ", index);
64
- var fError = handleMultiErrorConfig(error, result, status);
65
- console.log("Error has been checked ", index);
66
- console.log("fError", fError);
67
- if (fError) {
68
- finalErrors.push(fError);
69
- }
70
- });
71
- }
72
- else {
73
- console.log("This is response data mapping error");
74
- errorMsgPath = mapping.errorMsgPath, errorValue = mapping.errorValue;
75
- fError = handleMultiErrorConfig({ message: errorMsgPath, value: errorValue, path: errorValue }, result, status);
76
- console.log("fError", fError);
7
+ const lodash_1 = __importDefault(require("lodash"));
8
+ const voca_1 = __importDefault(require("voca"));
9
+ // Constants
10
+ const DEFAULT_ERROR_STATUS = 400;
11
+ const ERROR_STATUS_PREFIXES = ["3", "4", "5"];
12
+ const ERROR_VALUES = ["false", "error", "fail", "failed"];
13
+ const checkForError = async (result, errors, mapping, status) => {
14
+ let finalErrors = [];
15
+ if (errors && errors.length > 0) {
16
+ errors.forEach((error) => {
17
+ const fError = handleMultiErrorConfig(error, result, status);
77
18
  if (fError) {
78
19
  finalErrors.push(fError);
79
20
  }
21
+ });
22
+ }
23
+ else {
24
+ const { errorMsgPath, errorValue } = mapping;
25
+ const fError = handleMultiErrorConfig({ message: errorMsgPath, value: errorValue, path: String(errorValue) }, result, status);
26
+ if (fError) {
27
+ finalErrors.push(fError);
80
28
  }
81
- console.log("finalErrors", finalErrors);
82
- if (finalErrors.length > 0) {
83
- finalErrors = removeDuplicateError(finalErrors);
84
- finalFinalStatus_1 = 400;
85
- finalMessage = "";
86
- console.log("finalMessage", finalMessage);
87
- console.log("finalFinalStatus", finalFinalStatus_1);
88
- finalMessages_1 = [];
89
- finalErrors.forEach(function (errObj) {
90
- var status = errObj.status, message = errObj.message;
91
- if (status !== 400) {
92
- finalFinalStatus_1 = +status;
93
- }
94
- finalMessages_1.push(message);
95
- });
96
- console.log("finalMessages", finalMessages_1);
97
- finalMessage = finalMessages_1.join("\n").toString();
98
- console.log("finalMessage", finalMessage);
99
- return [2 /*return*/, {
100
- status: finalFinalStatus_1,
101
- responseData: finalMessage || "Error from source",
102
- noError: false,
103
- }];
104
- }
105
- else {
106
- return [2 /*return*/, { noError: true }];
107
- }
108
- return [2 /*return*/];
109
- });
110
- }); };
29
+ }
30
+ if (finalErrors.length > 0) {
31
+ finalErrors = removeDuplicateError(finalErrors);
32
+ let finalStatus = DEFAULT_ERROR_STATUS;
33
+ const finalMessages = [];
34
+ finalErrors.forEach((errObj) => {
35
+ const { status, message } = errObj;
36
+ if (status !== DEFAULT_ERROR_STATUS) {
37
+ finalStatus = +status;
38
+ }
39
+ finalMessages.push(message);
40
+ });
41
+ const finalMessage = finalMessages.join("\n");
42
+ return {
43
+ status: finalStatus,
44
+ responseData: finalMessage || "Error from source",
45
+ noError: false,
46
+ };
47
+ }
48
+ return { noError: true };
49
+ };
111
50
  exports.checkForError = checkForError;
112
- var removeDuplicateError = function (finalErrors) {
113
- // Remove duplicates based only on the message
114
- var uniqueErrors = Array.from(new Map(finalErrors.map(function (err) { return [err.message.trim(), err]; })).values());
115
- return uniqueErrors;
51
+ const removeDuplicateError = (finalErrors) => {
52
+ return Array.from(new Map(finalErrors.map((err) => [err.message.trim(), err])).values());
116
53
  };
117
- var handleMultiErrorConfig = function (error, result, status) {
54
+ const handleMultiErrorConfig = (error, result, status) => {
118
55
  if (!error || Object.keys(error).length === 0) {
119
56
  return null;
120
57
  }
121
- var message = error.message, path = error.path, value = error.value;
122
- console.log("handleMultiErrorConfig message", message);
123
- console.log("handleMultiErrorConfig path", path);
124
- console.log("handleMultiErrorConfig value", value);
125
- var apiErrorMessage;
126
- var apiErrorValue;
127
- if (result && result !== "undefined" && result !== "null") {
128
- console.log("handleMultiErrorConfig result :>> ".concat(Object.keys(result)));
58
+ const { message, path, value } = error;
59
+ let apiErrorMessage;
60
+ let apiErrorValue;
61
+ if (result && typeof result === "object") {
129
62
  apiErrorMessage = lodash_1.default.get(result, message);
130
63
  if (apiErrorMessage) {
131
- console.log("*** utility 3 ***");
132
- if (typeof apiErrorMessage == "string") {
133
- console.log("It's string so leave");
64
+ if (typeof apiErrorMessage === "string") {
65
+ // Keep as is
134
66
  }
135
67
  else if (Array.isArray(apiErrorMessage)) {
136
- apiErrorMessage = apiErrorMessage.join("\n").toString();
68
+ apiErrorMessage = apiErrorMessage.join("\n");
137
69
  }
138
70
  else {
139
- var messages = nestedValue(apiErrorMessage);
71
+ const messages = nestedValue(apiErrorMessage);
140
72
  apiErrorMessage = messages.join("\n");
141
73
  }
142
74
  }
143
- if (path) {
144
- console.log("Since we already have errorPath");
145
- apiErrorValue = lodash_1.default.get(result, path);
146
- }
147
- else {
148
- console.log("*** utility 7 ***");
149
- apiErrorValue = status;
150
- }
151
- console.log("*** utility 8 ***");
75
+ apiErrorValue = path ? `${lodash_1.default.get(result, path)}` : `${status}`;
152
76
  }
153
77
  else {
154
- console.log("result", result);
155
- apiErrorValue = status;
78
+ apiErrorValue = `${status}`;
156
79
  }
157
- console.log("apiErrorValue", apiErrorValue);
158
- apiErrorValue = "".concat(apiErrorValue);
159
- console.log("apiErrorMessage", apiErrorMessage);
160
- console.log("apiErrorValue", apiErrorValue);
161
- if (value && apiErrorValue == value) {
80
+ if (value && apiErrorValue === `${value}`) {
162
81
  return {
163
- status: 400,
164
- message: apiErrorMessage,
82
+ status: DEFAULT_ERROR_STATUS,
83
+ message: apiErrorMessage || "",
165
84
  };
166
85
  }
167
- else if (["false", "error", "fail", "failed"].includes(apiErrorValue.toLowerCase())) {
168
- console.log("*** utility 9 ***");
86
+ if (ERROR_VALUES.includes(apiErrorValue.toLowerCase())) {
169
87
  return {
170
- status: 400,
171
- message: apiErrorMessage,
88
+ status: DEFAULT_ERROR_STATUS,
89
+ message: apiErrorMessage || "",
172
90
  };
173
91
  }
174
- else if (voca_1.default.startsWith(apiErrorValue, "3") ||
175
- voca_1.default.startsWith(apiErrorValue, "4") ||
176
- voca_1.default.startsWith(apiErrorValue, "5")) {
92
+ if (ERROR_STATUS_PREFIXES.some((prefix) => voca_1.default.startsWith(apiErrorValue, prefix))) {
177
93
  console.log("*** utility 10 ***");
178
94
  console.log("Compare 4");
179
95
  return {
180
- status: apiErrorValue,
181
- message: apiErrorMessage,
96
+ status: parseInt(apiErrorValue),
97
+ message: apiErrorMessage || "",
182
98
  };
183
99
  }
184
100
  return null;
185
101
  };
186
- var nestedValue = function (data, messages) {
187
- if (messages === void 0) { messages = []; }
188
- var keys = Object.keys(data);
189
- keys.forEach(function (key) {
190
- var value = data[key];
191
- if (typeof value == "string") {
192
- messages.push(value);
102
+ const nestedValue = (data, messages = []) => {
103
+ return Object.entries(data).reduce((acc, [_, value]) => {
104
+ if (typeof value === "string") {
105
+ return [...acc, value];
193
106
  }
194
- else if (Array.isArray(value)) {
195
- messages = __spreadArray(__spreadArray([], messages, true), value, true);
107
+ if (Array.isArray(value)) {
108
+ return [...acc, ...value];
196
109
  }
197
- else {
198
- if (Object.keys(value).length) {
199
- messages = nestedValue(value, messages);
200
- }
110
+ if (value && typeof value === "object") {
111
+ return nestedValue(value, acc);
201
112
  }
202
- });
203
- return messages;
113
+ return acc;
114
+ }, messages);
204
115
  };
@@ -1,78 +1,79 @@
1
+ import { PageContent, WebhookContent, ExternalApiContent, CustomComponentContent, CustomMappingContent, TaskContent, EventContent, SnippetContent, LocalizationContent, PluginContent, DevApiContent, TemplateContent, CollectionContent } from "./file-util";
1
2
  /**
2
3
  * Page Related
3
4
  */
4
- export declare const loadPages: (projectId: string) => any[];
5
- export declare const loadPage: (projectId: string, slug: string) => any;
6
- export declare const saveProjectPages: (projectId: string, pages: any[]) => void;
5
+ export declare const loadPages: (projectId: string) => PageContent[];
6
+ export declare const loadPage: (projectId: string, slug: string) => PageContent | null;
7
+ export declare const saveProjectPages: (projectId: string, pages: PageContent[]) => void;
7
8
  /**
8
9
  * Webhook Related
9
10
  */
10
- export declare const loadWebhooks: (projectId: string) => any[];
11
- export declare const loadWebhook: (projectId: string, uuid: string) => any;
12
- export declare const saveWebhooks: (projectId: string, webhooks: any[]) => void;
11
+ export declare const loadWebhooks: (projectId: string) => WebhookContent[];
12
+ export declare const loadWebhook: (projectId: string, uuid: string) => WebhookContent | null;
13
+ export declare const saveWebhooks: (projectId: string, webhooks: WebhookContent[]) => void;
13
14
  /**
14
15
  * External API Related
15
16
  */
16
- export declare const loadExternalApis: (projectId: string) => any[];
17
- export declare const loadExternalApi: (projectId: string, uuid: string) => any;
18
- export declare const saveExternalApis: (projectId: string, externalApis: any[]) => void;
17
+ export declare const loadExternalApis: (projectId: string) => ExternalApiContent[];
18
+ export declare const loadExternalApi: (projectId: string, uuid: string) => ExternalApiContent | null;
19
+ export declare const saveExternalApis: (projectId: string, externalApis: ExternalApiContent[]) => void;
19
20
  /**
20
21
  * Custom Component Related
21
22
  */
22
- export declare const loadCustomComponents: (projectId: string) => any[];
23
- export declare const loadCustomComponent: (projectId: string, uuid: string) => any;
24
- export declare const saveCustomComponents: (projectId: string, customComponents: any[]) => void;
23
+ export declare const loadCustomComponents: (projectId: string) => CustomComponentContent[];
24
+ export declare const loadCustomComponent: (projectId: string, uuid: string) => CustomComponentContent | null;
25
+ export declare const saveCustomComponents: (projectId: string, customComponents: CustomComponentContent[]) => void;
25
26
  /**
26
27
  * Custom Component Related
27
28
  */
28
- export declare const loadCustomMappings: (projectId: string) => any[];
29
- export declare const loadCustomMapping: (projectId: string, uuid: string) => any;
30
- export declare const saveCustomMappings: (projectId: string, customMappings: any[]) => void;
29
+ export declare const loadCustomMappings: (projectId: string) => CustomMappingContent[];
30
+ export declare const loadCustomMapping: (projectId: string, uuid: string) => CustomMappingContent | null;
31
+ export declare const saveCustomMappings: (projectId: string, customMappings: CustomMappingContent[]) => void;
31
32
  /**
32
33
  * Custom Component Related
33
34
  */
34
- export declare const loadTasks: (projectId: string) => any[];
35
- export declare const loadTask: (projectId: string, uuid: string) => any;
36
- export declare const saveTasks: (projectId: string, tasks: any[]) => void;
35
+ export declare const loadTasks: (projectId: string) => TaskContent[];
36
+ export declare const loadTask: (projectId: string, uuid: string) => TaskContent | null;
37
+ export declare const saveTasks: (projectId: string, tasks: TaskContent[]) => void;
37
38
  /**
38
39
  * Event Related
39
40
  */
40
- export declare const loadEvents: (projectId: string) => any[];
41
- export declare const loadEvent: (projectId: string, uuid: string) => any;
42
- export declare const saveEvents: (projectId: string, events: any[]) => void;
41
+ export declare const loadEvents: (projectId: string) => EventContent[];
42
+ export declare const loadEvent: (projectId: string, uuid: string) => EventContent | null;
43
+ export declare const saveEvents: (projectId: string, events: EventContent[]) => void;
43
44
  /**
44
45
  * Snippet Related
45
46
  */
46
- export declare const loadSnippets: (projectId: string) => any[];
47
- export declare const loadSnippet: (projectId: string, uuid: string) => any;
48
- export declare const saveSnippets: (projectId: string, snippets: any[]) => void;
47
+ export declare const loadSnippets: (projectId: string) => SnippetContent[];
48
+ export declare const loadSnippet: (projectId: string, uuid: string) => SnippetContent | null;
49
+ export declare const saveSnippets: (projectId: string, snippets: SnippetContent[]) => void;
49
50
  /**
50
51
  * Localization Related
51
52
  */
52
- export declare const loadLocalizations: (projectId: string) => any[];
53
- export declare const loadLocalization: (projectId: string, language: string) => any;
54
- export declare const saveLocalizations: (projectId: string, localizations: any[]) => void;
53
+ export declare const loadLocalizations: (projectId: string) => LocalizationContent[];
54
+ export declare const loadLocalization: (projectId: string, language: string) => LocalizationContent | null;
55
+ export declare const saveLocalizations: (projectId: string, localizations: LocalizationContent[]) => void;
55
56
  /**
56
57
  * Plugin Related
57
58
  */
58
- export declare const loadPlugins: (projectId: string) => any[];
59
- export declare const loadPlugin: (projectId: string, code: string) => any;
60
- export declare const savePlugins: (projectId: string, plugins: any[]) => void;
59
+ export declare const loadPlugins: (projectId: string) => PluginContent[];
60
+ export declare const loadPlugin: (projectId: string, code: string) => PluginContent | null;
61
+ export declare const savePlugins: (projectId: string, plugins: PluginContent[]) => void;
61
62
  /**
62
63
  * DEV APIs Related
63
64
  */
64
- export declare const loadDevAPIs: (projectId: string) => any[];
65
- export declare const loadDevAPI: (projectId: string, uuid: string) => any;
66
- export declare const saveDevAPIs: (projectId: string, devApis: any[]) => void;
65
+ export declare const loadDevAPIs: (projectId: string) => DevApiContent[];
66
+ export declare const loadDevAPI: (projectId: string, uuid: string) => DevApiContent | null;
67
+ export declare const saveDevAPIs: (projectId: string, devApis: DevApiContent[]) => void;
67
68
  /**
68
69
  * Template Related
69
70
  */
70
- export declare const loadTemplates: (projectId: string) => any[];
71
- export declare const loadTemplate: (projectId: string, uuid: string) => any;
72
- export declare const saveTemplates: (projectId: string, templates: any[]) => void;
71
+ export declare const loadTemplates: (projectId: string) => TemplateContent[];
72
+ export declare const loadTemplate: (projectId: string, uuid: string) => TemplateContent | null;
73
+ export declare const saveTemplates: (projectId: string, templates: TemplateContent[]) => void;
73
74
  /**
74
75
  * Collection Related
75
76
  */
76
- export declare const loadCollections: (projectId: string) => any[];
77
- export declare const loadCollection: (projectId: string, uuid: string) => any;
78
- export declare const saveCollections: (projectId: string, collections: any[]) => void;
77
+ export declare const loadCollections: (projectId: string) => CollectionContent[];
78
+ export declare const loadCollection: (projectId: string, uuid: string) => CollectionContent | null;
79
+ export declare const saveCollections: (projectId: string, collections: CollectionContent[]) => void;