drapcode-utility 2.0.1 → 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
@@ -4,24 +4,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.saveCollections = exports.loadCollection = exports.loadCollections = exports.saveTemplates = exports.loadTemplate = exports.loadTemplates = exports.saveDevAPIs = exports.loadDevAPI = exports.loadDevAPIs = exports.savePlugins = exports.loadPlugin = exports.loadPlugins = exports.saveLocalizations = exports.loadLocalization = exports.loadLocalizations = exports.saveSnippets = exports.loadSnippet = exports.loadSnippets = exports.saveEvents = exports.loadEvent = exports.loadEvents = exports.saveTasks = exports.loadTask = exports.loadTasks = exports.saveCustomMappings = exports.loadCustomMapping = exports.loadCustomMappings = exports.saveCustomComponents = exports.loadCustomComponent = exports.loadCustomComponents = exports.saveExternalApis = exports.loadExternalApi = exports.loadExternalApis = exports.saveWebhooks = exports.loadWebhook = exports.loadWebhooks = exports.saveProjectPages = exports.loadPage = exports.loadPages = void 0;
7
- var path_1 = __importDefault(require("path"));
8
- var file_util_1 = require("./file-util");
9
- var filePath = process.env.BUILD_FOLDER;
7
+ const path_1 = __importDefault(require("path"));
8
+ const file_util_1 = require("./file-util");
10
9
  /**
11
10
  * Page Related
12
11
  */
13
- var loadPages = function (projectId) {
14
- return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "pages", ["default.json"]);
12
+ const loadPages = (projectId) => {
13
+ return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "pages", [
14
+ "default.json",
15
+ ]);
15
16
  };
16
17
  exports.loadPages = loadPages;
17
- var loadPage = function (projectId, slug) {
18
+ const loadPage = (projectId, slug) => {
18
19
  return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "pages", slug);
19
20
  };
20
21
  exports.loadPage = loadPage;
21
- var saveProjectPages = function (projectId, pages) {
22
- (0, file_util_1.saveEntities)(projectId, "pages", pages, function (page) { return page.slug; }, function (folderPath, page) {
22
+ const saveProjectPages = (projectId, pages) => {
23
+ (0, file_util_1.saveEntities)(projectId, "pages", pages, (page) => page.slug, (folderPath, page) => {
23
24
  if (page.isDefaultPage) {
24
- var defaultPath = path_1.default.join(folderPath, "default.json");
25
+ const defaultPath = path_1.default.join(folderPath, "default.json");
25
26
  (0, file_util_1.createFile)(defaultPath, page);
26
27
  }
27
28
  });
@@ -30,125 +31,125 @@ exports.saveProjectPages = saveProjectPages;
30
31
  /**
31
32
  * Webhook Related
32
33
  */
33
- var loadWebhooks = function (projectId) {
34
+ const loadWebhooks = (projectId) => {
34
35
  return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "webhooks");
35
36
  };
36
37
  exports.loadWebhooks = loadWebhooks;
37
- var loadWebhook = function (projectId, uuid) {
38
+ const loadWebhook = (projectId, uuid) => {
38
39
  return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "webhooks", uuid);
39
40
  };
40
41
  exports.loadWebhook = loadWebhook;
41
- var saveWebhooks = function (projectId, webhooks) {
42
- (0, file_util_1.saveEntities)(projectId, "webhooks", webhooks, function (webhook) { return webhook.uuid; });
42
+ const saveWebhooks = (projectId, webhooks) => {
43
+ (0, file_util_1.saveEntities)(projectId, "webhooks", webhooks, (webhook) => webhook.uuid);
43
44
  };
44
45
  exports.saveWebhooks = saveWebhooks;
45
46
  /**
46
47
  * External API Related
47
48
  */
48
- var loadExternalApis = function (projectId) {
49
+ const loadExternalApis = (projectId) => {
49
50
  return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "external-apis");
50
51
  };
51
52
  exports.loadExternalApis = loadExternalApis;
52
- var loadExternalApi = function (projectId, uuid) {
53
+ const loadExternalApi = (projectId, uuid) => {
53
54
  return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "external-apis", uuid);
54
55
  };
55
56
  exports.loadExternalApi = loadExternalApi;
56
- var saveExternalApis = function (projectId, externalApis) {
57
- (0, file_util_1.saveEntities)(projectId, "external-apis", externalApis, function (api) { return api.uuid; });
57
+ const saveExternalApis = (projectId, externalApis) => {
58
+ (0, file_util_1.saveEntities)(projectId, "external-apis", externalApis, (api) => api.uuid);
58
59
  };
59
60
  exports.saveExternalApis = saveExternalApis;
60
61
  /**
61
62
  * Custom Component Related
62
63
  */
63
- var loadCustomComponents = function (projectId) {
64
+ const loadCustomComponents = (projectId) => {
64
65
  return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "custom-components");
65
66
  };
66
67
  exports.loadCustomComponents = loadCustomComponents;
67
- var loadCustomComponent = function (projectId, uuid) {
68
+ const loadCustomComponent = (projectId, uuid) => {
68
69
  return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "custom-components", uuid);
69
70
  };
70
71
  exports.loadCustomComponent = loadCustomComponent;
71
- var saveCustomComponents = function (projectId, customComponents) {
72
- (0, file_util_1.saveEntities)(projectId, "custom-components", customComponents, function (customComponent) { return customComponent.uuid; });
72
+ const saveCustomComponents = (projectId, customComponents) => {
73
+ (0, file_util_1.saveEntities)(projectId, "custom-components", customComponents, (customComponent) => customComponent.uuid);
73
74
  };
74
75
  exports.saveCustomComponents = saveCustomComponents;
75
76
  /**
76
77
  * Custom Component Related
77
78
  */
78
- var loadCustomMappings = function (projectId) {
79
+ const loadCustomMappings = (projectId) => {
79
80
  return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "custom-data-mappings");
80
81
  };
81
82
  exports.loadCustomMappings = loadCustomMappings;
82
- var loadCustomMapping = function (projectId, uuid) {
83
+ const loadCustomMapping = (projectId, uuid) => {
83
84
  return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "custom-data-mappings", uuid);
84
85
  };
85
86
  exports.loadCustomMapping = loadCustomMapping;
86
- var saveCustomMappings = function (projectId, customMappings) {
87
- (0, file_util_1.saveEntities)(projectId, "custom-data-mappings", customMappings, function (customMapping) { return customMapping.uuid; });
87
+ const saveCustomMappings = (projectId, customMappings) => {
88
+ (0, file_util_1.saveEntities)(projectId, "custom-data-mappings", customMappings, (customMapping) => customMapping.uuid);
88
89
  };
89
90
  exports.saveCustomMappings = saveCustomMappings;
90
91
  /**
91
92
  * Custom Component Related
92
93
  */
93
- var loadTasks = function (projectId) {
94
+ const loadTasks = (projectId) => {
94
95
  return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "tasks");
95
96
  };
96
97
  exports.loadTasks = loadTasks;
97
- var loadTask = function (projectId, uuid) {
98
+ const loadTask = (projectId, uuid) => {
98
99
  return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "tasks", uuid);
99
100
  };
100
101
  exports.loadTask = loadTask;
101
- var saveTasks = function (projectId, tasks) {
102
- (0, file_util_1.saveEntities)(projectId, "tasks", tasks, function (task) { return task.uuid; });
102
+ const saveTasks = (projectId, tasks) => {
103
+ (0, file_util_1.saveEntities)(projectId, "tasks", tasks, (task) => task.uuid);
103
104
  };
104
105
  exports.saveTasks = saveTasks;
105
106
  /**
106
107
  * Event Related
107
108
  */
108
- var loadEvents = function (projectId) {
109
+ const loadEvents = (projectId) => {
109
110
  return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "events");
110
111
  };
111
112
  exports.loadEvents = loadEvents;
112
- var loadEvent = function (projectId, uuid) {
113
+ const loadEvent = (projectId, uuid) => {
113
114
  return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "events", uuid);
114
115
  };
115
116
  exports.loadEvent = loadEvent;
116
- var saveEvents = function (projectId, events) {
117
- (0, file_util_1.saveEntities)(projectId, "events", events, function (event) { return event.uuid; });
117
+ const saveEvents = (projectId, events) => {
118
+ (0, file_util_1.saveEntities)(projectId, "events", events, (event) => event.uuid);
118
119
  };
119
120
  exports.saveEvents = saveEvents;
120
121
  /**
121
122
  * Snippet Related
122
123
  */
123
- var loadSnippets = function (projectId) {
124
+ const loadSnippets = (projectId) => {
124
125
  return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "snippets");
125
126
  };
126
127
  exports.loadSnippets = loadSnippets;
127
- var loadSnippet = function (projectId, uuid) {
128
+ const loadSnippet = (projectId, uuid) => {
128
129
  return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "snippets", uuid);
129
130
  };
130
131
  exports.loadSnippet = loadSnippet;
131
- var saveSnippets = function (projectId, snippets) {
132
- (0, file_util_1.saveEntities)(projectId, "snippets", snippets, function (snippet) { return snippet.uuid; });
132
+ const saveSnippets = (projectId, snippets) => {
133
+ (0, file_util_1.saveEntities)(projectId, "snippets", snippets, (snippet) => snippet.uuid);
133
134
  };
134
135
  exports.saveSnippets = saveSnippets;
135
136
  /**
136
137
  * Localization Related
137
138
  */
138
- var loadLocalizations = function (projectId) {
139
+ const loadLocalizations = (projectId) => {
139
140
  return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "localizations", [
140
141
  "default.json",
141
142
  ]);
142
143
  };
143
144
  exports.loadLocalizations = loadLocalizations;
144
- var loadLocalization = function (projectId, language) {
145
+ const loadLocalization = (projectId, language) => {
145
146
  return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "localizations", language);
146
147
  };
147
148
  exports.loadLocalization = loadLocalization;
148
- var saveLocalizations = function (projectId, localizations) {
149
- (0, file_util_1.saveEntities)(projectId, "localizations", localizations, function (localization) { return localization.language; }, function (folderPath, localization) {
149
+ const saveLocalizations = (projectId, localizations) => {
150
+ (0, file_util_1.saveEntities)(projectId, "localizations", localizations, (localization) => localization.language, (folderPath, localization) => {
150
151
  if (localization.isDefault) {
151
- var defaultPath = path_1.default.join(folderPath, "default.json");
152
+ const defaultPath = path_1.default.join(folderPath, "default.json");
152
153
  (0, file_util_1.createFile)(defaultPath, localization);
153
154
  }
154
155
  });
@@ -157,62 +158,62 @@ exports.saveLocalizations = saveLocalizations;
157
158
  /**
158
159
  * Plugin Related
159
160
  */
160
- var loadPlugins = function (projectId) {
161
+ const loadPlugins = (projectId) => {
161
162
  return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "plugins");
162
163
  };
163
164
  exports.loadPlugins = loadPlugins;
164
- var loadPlugin = function (projectId, code) {
165
+ const loadPlugin = (projectId, code) => {
165
166
  return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "plugins", code);
166
167
  };
167
168
  exports.loadPlugin = loadPlugin;
168
- var savePlugins = function (projectId, plugins) {
169
- (0, file_util_1.saveEntities)(projectId, "plugins", plugins, function (plugin) { return plugin.code; });
169
+ const savePlugins = (projectId, plugins) => {
170
+ (0, file_util_1.saveEntities)(projectId, "plugins", plugins, (plugin) => plugin.code);
170
171
  };
171
172
  exports.savePlugins = savePlugins;
172
173
  /**
173
174
  * DEV APIs Related
174
175
  */
175
- var loadDevAPIs = function (projectId) {
176
+ const loadDevAPIs = (projectId) => {
176
177
  return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "dev-apis");
177
178
  };
178
179
  exports.loadDevAPIs = loadDevAPIs;
179
- var loadDevAPI = function (projectId, uuid) {
180
+ const loadDevAPI = (projectId, uuid) => {
180
181
  return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "dev-apis", uuid);
181
182
  };
182
183
  exports.loadDevAPI = loadDevAPI;
183
- var saveDevAPIs = function (projectId, devApis) {
184
- (0, file_util_1.saveEntities)(projectId, "dev-apis", devApis, function (plugin) { return plugin.uuid; });
184
+ const saveDevAPIs = (projectId, devApis) => {
185
+ (0, file_util_1.saveEntities)(projectId, "dev-apis", devApis, (plugin) => plugin.uuid);
185
186
  };
186
187
  exports.saveDevAPIs = saveDevAPIs;
187
188
  /**
188
189
  * Template Related
189
190
  */
190
- var loadTemplates = function (projectId) {
191
+ const loadTemplates = (projectId) => {
191
192
  return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "templates");
192
193
  };
193
194
  exports.loadTemplates = loadTemplates;
194
- var loadTemplate = function (projectId, uuid) {
195
+ const loadTemplate = (projectId, uuid) => {
195
196
  return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "templates", uuid);
196
197
  };
197
198
  exports.loadTemplate = loadTemplate;
198
- var saveTemplates = function (projectId, templates) {
199
- (0, file_util_1.saveEntities)(projectId, "templates", templates, function (template) { return template.uuid; });
199
+ const saveTemplates = (projectId, templates) => {
200
+ (0, file_util_1.saveEntities)(projectId, "templates", templates, (template) => template.uuid);
200
201
  };
201
202
  exports.saveTemplates = saveTemplates;
202
203
  /**
203
204
  * Collection Related
204
205
  */
205
- var loadCollections = function (projectId) {
206
+ const loadCollections = (projectId) => {
206
207
  return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "collections");
207
208
  };
208
209
  exports.loadCollections = loadCollections;
209
- var loadCollection = function (projectId, uuid) {
210
+ const loadCollection = (projectId, uuid) => {
210
211
  return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "collections", uuid);
211
212
  };
212
213
  exports.loadCollection = loadCollection;
213
- var saveCollections = function (projectId, collections) {
214
- (0, file_util_1.saveEntities)(projectId, "collections", collections, function (collection) { return collection.uuid; }, function (folderPath, collection) {
215
- var defaultPath = path_1.default.join(folderPath, "".concat(collection.collectionName, ".json"));
214
+ const saveCollections = (projectId, collections) => {
215
+ (0, file_util_1.saveEntities)(projectId, "collections", collections, (collection) => collection.uuid, (folderPath, collection) => {
216
+ const defaultPath = path_1.default.join(folderPath, `${collection.collectionName}.json`);
216
217
  (0, file_util_1.createFile)(defaultPath, collection);
217
218
  });
218
219
  };
@@ -1,9 +1,30 @@
1
+ interface DateField {
2
+ fieldName: string;
3
+ type: string;
4
+ extraFieldSetting?: {
5
+ dateDisplayType?: string;
6
+ };
7
+ }
8
+ interface DateRangeValue {
9
+ [key: string]: {
10
+ $gte?: string;
11
+ $lte?: string;
12
+ } | {
13
+ $or?: Array<{
14
+ [key: string]: {
15
+ $gte?: string;
16
+ $lte?: string;
17
+ };
18
+ }>;
19
+ };
20
+ }
1
21
  export declare const DATE_REGEX: RegExp;
2
- export declare const createLoggerDateFormat: (timezone?: string) => any;
3
- export declare const createLoggerPreviouseDateFormat: () => any;
4
- export declare const createLogsDateFormat: (timezone?: string) => any;
5
- export declare const getDateValue: (value: string, timezone?: string) => any;
6
- export declare const getDateRangeValue: (key: string, field: string, value: string) => any;
7
- export declare const nextDayDate: (date: any) => any;
22
+ export declare const createLoggerDateFormat: (timezone?: string) => string;
23
+ export declare const createLoggerPreviousDateFormat: () => string;
24
+ export declare const createLogsDateFormat: (timezone?: string) => string;
25
+ export declare const getDateValue: (value: string, timezone?: string) => string;
26
+ export declare const getDateRangeValue: (key: string, field: string, value: string) => DateRangeValue;
27
+ export declare const nextDayDate: (date: string | Date) => string;
8
28
  export declare const timezoneDateParse: (value: string, nextDay?: boolean, prevDay?: boolean) => Date;
9
- export declare const formatProjectDates: (item: any, dateFormat: string, fields: Array<object>, reverse: boolean) => any;
29
+ export declare const formatProjectDates: (item: Record<string, any> | Record<string, any>[], dateFormat: string, fields: DateField[], reverse: boolean) => Record<string, any> | Record<string, any>[];
30
+ export {};