drapcode-utility 1.9.6 → 1.9.78

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.
@@ -1,2 +1 @@
1
- export declare const getEncryptedReferenceFieldsQuery: (collectionFields: any, projectId: any) => any;
2
- export declare const prepareDBQuery: (projectId: string, collections: any) => any;
1
+ export declare const getEncryptedReferenceFields: (collectionFields: any) => any;
@@ -1,17 +1,8 @@
1
1
  "use strict";
2
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
- if (ar || !(i in from)) {
5
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
- ar[i] = from[i];
7
- }
8
- }
9
- return to.concat(ar || Array.prototype.slice.call(from));
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.prepareDBQuery = exports.getEncryptedReferenceFieldsQuery = void 0;
3
+ exports.getEncryptedReferenceFields = void 0;
13
4
  var drapcode_constant_1 = require("drapcode-constant");
14
- var getEncryptedReferenceFieldsQuery = function (collectionFields, projectId) {
5
+ var getEncryptedReferenceFields = function (collectionFields) {
15
6
  var collectionsNamesArr = [];
16
7
  collectionFields = collectionFields.filter(function (field) {
17
8
  return drapcode_constant_1.BelongsCreatedByRefField.includes(field.type);
@@ -26,32 +17,6 @@ var getEncryptedReferenceFieldsQuery = function (collectionFields, projectId) {
26
17
  collectionsNamesArr.push(collectionName);
27
18
  }
28
19
  });
29
- return (0, exports.prepareDBQuery)(projectId, collectionsNamesArr);
30
- };
31
- exports.getEncryptedReferenceFieldsQuery = getEncryptedReferenceFieldsQuery;
32
- var prepareDBQuery = function (projectId, collections) {
33
- var query = [
34
- {
35
- $match: {
36
- projectId: projectId,
37
- collectionName: { $in: __spreadArray([], collections, true) },
38
- fields: { $elemMatch: { encrypted: true } },
39
- },
40
- },
41
- {
42
- $project: {
43
- _id: 0,
44
- collectionName: 1,
45
- fields: {
46
- $filter: {
47
- input: "$fields",
48
- as: "item",
49
- cond: { $eq: ["$$item.encrypted", true] },
50
- },
51
- },
52
- },
53
- },
54
- ];
55
- return query;
20
+ return collectionsNamesArr;
56
21
  };
57
- exports.prepareDBQuery = prepareDBQuery;
22
+ exports.getEncryptedReferenceFields = getEncryptedReferenceFields;
@@ -47,7 +47,7 @@ var formatField = function (itemData, fields) {
47
47
  return newItemData;
48
48
  };
49
49
  var getFormatFieldData = function (fieldData, fieldType) {
50
- var createdAt = drapcode_constant_1.FieldTypes.createdAt, text = drapcode_constant_1.FieldTypes.text, large_text = drapcode_constant_1.FieldTypes.large_text, date = drapcode_constant_1.FieldTypes.date, password = drapcode_constant_1.FieldTypes.password, uuid = drapcode_constant_1.FieldTypes.uuid, custom_uuid = drapcode_constant_1.FieldTypes.custom_uuid, email = drapcode_constant_1.FieldTypes.email, url = drapcode_constant_1.FieldTypes.url, number = drapcode_constant_1.FieldTypes.number, unix_timestamp = drapcode_constant_1.FieldTypes.unix_timestamp, reference = drapcode_constant_1.FieldTypes.reference, belongsTo = drapcode_constant_1.FieldTypes.belongsTo, multi_reference = drapcode_constant_1.FieldTypes.multi_reference, dynamic_option = drapcode_constant_1.FieldTypes.dynamic_option, static_option = drapcode_constant_1.FieldTypes.static_option, boolean = drapcode_constant_1.FieldTypes.boolean, time_slot = drapcode_constant_1.FieldTypes.time_slot, slug = drapcode_constant_1.FieldTypes.slug, json = drapcode_constant_1.FieldTypes.json, markdown = drapcode_constant_1.FieldTypes.markdown;
50
+ var createdAt = drapcode_constant_1.FieldTypes.createdAt, text = drapcode_constant_1.FieldTypes.text, large_text = drapcode_constant_1.FieldTypes.large_text, date = drapcode_constant_1.FieldTypes.date, password = drapcode_constant_1.FieldTypes.password, uuid = drapcode_constant_1.FieldTypes.uuid, custom_uuid = drapcode_constant_1.FieldTypes.custom_uuid, email = drapcode_constant_1.FieldTypes.email, url = drapcode_constant_1.FieldTypes.url, number = drapcode_constant_1.FieldTypes.number, unix_timestamp = drapcode_constant_1.FieldTypes.unix_timestamp, belongsTo = drapcode_constant_1.FieldTypes.belongsTo, boolean = drapcode_constant_1.FieldTypes.boolean, time_slot = drapcode_constant_1.FieldTypes.time_slot, slug = drapcode_constant_1.FieldTypes.slug, json = drapcode_constant_1.FieldTypes.json, markdown = drapcode_constant_1.FieldTypes.markdown;
51
51
  var stringType = [
52
52
  createdAt.id,
53
53
  text.id,
package/build/index.d.ts CHANGED
@@ -8,13 +8,15 @@ export * from "./middlewares/interceptor-logger";
8
8
  export * from "./middlewares/interceptor-logger-new";
9
9
  export * from "./utils/date-util";
10
10
  export * from "./utils/query-parser";
11
- export * from "./utils/query-paser-new";
11
+ export * from "./utils/query-parser-new";
12
12
  export * from "./utils/util";
13
13
  export * from "./utils/uuid-generator";
14
14
  export * from "./utils/check-error";
15
15
  export * from "./utils/prepare-query";
16
16
  export * from "./utils/s3-util";
17
17
  export * from "./utils/project-util";
18
+ export * from "./utils/common-util";
19
+ export * from "./utils/rest-client";
18
20
  export * from "./encryption/index";
19
21
  export * from "./encryption/utility";
20
22
  export * from "./format-fields/index";
package/build/index.js CHANGED
@@ -24,13 +24,15 @@ __exportStar(require("./middlewares/interceptor-logger"), exports);
24
24
  __exportStar(require("./middlewares/interceptor-logger-new"), exports);
25
25
  __exportStar(require("./utils/date-util"), exports);
26
26
  __exportStar(require("./utils/query-parser"), exports);
27
- __exportStar(require("./utils/query-paser-new"), exports);
27
+ __exportStar(require("./utils/query-parser-new"), exports);
28
28
  __exportStar(require("./utils/util"), exports);
29
29
  __exportStar(require("./utils/uuid-generator"), exports);
30
30
  __exportStar(require("./utils/check-error"), exports);
31
31
  __exportStar(require("./utils/prepare-query"), exports);
32
32
  __exportStar(require("./utils/s3-util"), exports);
33
33
  __exportStar(require("./utils/project-util"), exports);
34
+ __exportStar(require("./utils/common-util"), exports);
35
+ __exportStar(require("./utils/rest-client"), exports);
34
36
  __exportStar(require("./encryption/index"), exports);
35
37
  __exportStar(require("./encryption/utility"), exports);
36
38
  __exportStar(require("./format-fields/index"), exports);
@@ -61,7 +61,7 @@ var checkForError = function (result, errors, mapping, status) { return __awaite
61
61
  console.log("I have multi error setting");
62
62
  errors.forEach(function (error, index) {
63
63
  console.log("Checking for error ", index);
64
- var fError = handleMultErrorConfig(error, result, status);
64
+ var fError = handleMultiErrorConfig(error, result, status);
65
65
  console.log("Error has been checked ", index);
66
66
  console.log("fError", fError);
67
67
  if (fError) {
@@ -72,7 +72,7 @@ var checkForError = function (result, errors, mapping, status) { return __awaite
72
72
  else {
73
73
  console.log("This is response data mapping error");
74
74
  errorMsgPath = mapping.errorMsgPath, errorValue = mapping.errorValue;
75
- fError = handleMultErrorConfig({ message: errorMsgPath, value: errorValue, path: errorValue }, result, status);
75
+ fError = handleMultiErrorConfig({ message: errorMsgPath, value: errorValue, path: errorValue }, result, status);
76
76
  console.log("fError", fError);
77
77
  if (fError) {
78
78
  finalErrors.push(fError);
@@ -114,18 +114,18 @@ var removeDuplicateError = function (finalErrors) {
114
114
  var uniqueErrors = Array.from(new Map(finalErrors.map(function (err) { return [err.message.trim(), err]; })).values());
115
115
  return uniqueErrors;
116
116
  };
117
- var handleMultErrorConfig = function (error, result, status) {
117
+ var handleMultiErrorConfig = function (error, result, status) {
118
118
  if (!error || Object.keys(error).length === 0) {
119
119
  return null;
120
120
  }
121
121
  var message = error.message, path = error.path, value = error.value;
122
- console.log("handleMultErrorConfig message", message);
123
- console.log("handleMultErrorConfig path", path);
124
- console.log("handleMultErrorConfig value", value);
122
+ console.log("handleMultiErrorConfig message", message);
123
+ console.log("handleMultiErrorConfig path", path);
124
+ console.log("handleMultiErrorConfig value", value);
125
125
  var apiErrorMessage;
126
126
  var apiErrorValue;
127
127
  if (result && result !== "undefined" && result !== "null") {
128
- console.log("handleMultErrorConfig result :>> ".concat(Object.keys(result)));
128
+ console.log("handleMultiErrorConfig result :>> ".concat(Object.keys(result)));
129
129
  apiErrorMessage = lodash_1.default.get(result, message);
130
130
  if (apiErrorMessage) {
131
131
  console.log("*** utility 3 ***");
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Page Related
3
+ */
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;
7
+ /**
8
+ * Webhook Related
9
+ */
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;
13
+ /**
14
+ * External API Related
15
+ */
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;
19
+ /**
20
+ * Custom Component Related
21
+ */
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;
25
+ /**
26
+ * Custom Component Related
27
+ */
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;
31
+ /**
32
+ * Custom Component Related
33
+ */
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;
37
+ /**
38
+ * Event Related
39
+ */
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;
43
+ /**
44
+ * Snippet Related
45
+ */
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;
49
+ /**
50
+ * Localization Related
51
+ */
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;
55
+ /**
56
+ * Plugin Related
57
+ */
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;
61
+ /**
62
+ * DEV APIs Related
63
+ */
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;
67
+ /**
68
+ * Template Related
69
+ */
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;
73
+ /**
74
+ * Collection Related
75
+ */
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;
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
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;
10
+ /**
11
+ * Page Related
12
+ */
13
+ var loadPages = function (projectId) {
14
+ return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "pages", ["default.json"]);
15
+ };
16
+ exports.loadPages = loadPages;
17
+ var loadPage = function (projectId, slug) {
18
+ return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "pages", slug);
19
+ };
20
+ 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) {
23
+ if (page.isDefaultPage) {
24
+ var defaultPath = path_1.default.join(folderPath, "default.json");
25
+ (0, file_util_1.createFile)(defaultPath, page);
26
+ }
27
+ });
28
+ };
29
+ exports.saveProjectPages = saveProjectPages;
30
+ /**
31
+ * Webhook Related
32
+ */
33
+ var loadWebhooks = function (projectId) {
34
+ return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "webhooks");
35
+ };
36
+ exports.loadWebhooks = loadWebhooks;
37
+ var loadWebhook = function (projectId, uuid) {
38
+ return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "webhooks", uuid);
39
+ };
40
+ exports.loadWebhook = loadWebhook;
41
+ var saveWebhooks = function (projectId, webhooks) {
42
+ (0, file_util_1.saveEntities)(projectId, "webhooks", webhooks, function (webhook) { return webhook.uuid; });
43
+ };
44
+ exports.saveWebhooks = saveWebhooks;
45
+ /**
46
+ * External API Related
47
+ */
48
+ var loadExternalApis = function (projectId) {
49
+ return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "external-apis");
50
+ };
51
+ exports.loadExternalApis = loadExternalApis;
52
+ var loadExternalApi = function (projectId, uuid) {
53
+ return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "external-apis", uuid);
54
+ };
55
+ exports.loadExternalApi = loadExternalApi;
56
+ var saveExternalApis = function (projectId, externalApis) {
57
+ (0, file_util_1.saveEntities)(projectId, "external-apis", externalApis, function (api) { return api.uuid; });
58
+ };
59
+ exports.saveExternalApis = saveExternalApis;
60
+ /**
61
+ * Custom Component Related
62
+ */
63
+ var loadCustomComponents = function (projectId) {
64
+ return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "custom-components");
65
+ };
66
+ exports.loadCustomComponents = loadCustomComponents;
67
+ var loadCustomComponent = function (projectId, uuid) {
68
+ return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "custom-components", uuid);
69
+ };
70
+ exports.loadCustomComponent = loadCustomComponent;
71
+ var saveCustomComponents = function (projectId, customComponents) {
72
+ (0, file_util_1.saveEntities)(projectId, "custom-components", customComponents, function (customComponent) { return customComponent.uuid; });
73
+ };
74
+ exports.saveCustomComponents = saveCustomComponents;
75
+ /**
76
+ * Custom Component Related
77
+ */
78
+ var loadCustomMappings = function (projectId) {
79
+ return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "custom-data-mappings");
80
+ };
81
+ exports.loadCustomMappings = loadCustomMappings;
82
+ var loadCustomMapping = function (projectId, uuid) {
83
+ return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "custom-data-mappings", uuid);
84
+ };
85
+ 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; });
88
+ };
89
+ exports.saveCustomMappings = saveCustomMappings;
90
+ /**
91
+ * Custom Component Related
92
+ */
93
+ var loadTasks = function (projectId) {
94
+ return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "tasks");
95
+ };
96
+ exports.loadTasks = loadTasks;
97
+ var loadTask = function (projectId, uuid) {
98
+ return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "tasks", uuid);
99
+ };
100
+ exports.loadTask = loadTask;
101
+ var saveTasks = function (projectId, tasks) {
102
+ (0, file_util_1.saveEntities)(projectId, "tasks", tasks, function (task) { return task.uuid; });
103
+ };
104
+ exports.saveTasks = saveTasks;
105
+ /**
106
+ * Event Related
107
+ */
108
+ var loadEvents = function (projectId) {
109
+ return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "events");
110
+ };
111
+ exports.loadEvents = loadEvents;
112
+ var loadEvent = function (projectId, uuid) {
113
+ return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "events", uuid);
114
+ };
115
+ exports.loadEvent = loadEvent;
116
+ var saveEvents = function (projectId, events) {
117
+ (0, file_util_1.saveEntities)(projectId, "events", events, function (event) { return event.uuid; });
118
+ };
119
+ exports.saveEvents = saveEvents;
120
+ /**
121
+ * Snippet Related
122
+ */
123
+ var loadSnippets = function (projectId) {
124
+ return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "snippets");
125
+ };
126
+ exports.loadSnippets = loadSnippets;
127
+ var loadSnippet = function (projectId, uuid) {
128
+ return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "snippets", uuid);
129
+ };
130
+ exports.loadSnippet = loadSnippet;
131
+ var saveSnippets = function (projectId, snippets) {
132
+ (0, file_util_1.saveEntities)(projectId, "snippets", snippets, function (snippet) { return snippet.uuid; });
133
+ };
134
+ exports.saveSnippets = saveSnippets;
135
+ /**
136
+ * Localization Related
137
+ */
138
+ var loadLocalizations = function (projectId) {
139
+ return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "localizations", [
140
+ "default.json",
141
+ ]);
142
+ };
143
+ exports.loadLocalizations = loadLocalizations;
144
+ var loadLocalization = function (projectId, language) {
145
+ return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "localizations", language);
146
+ };
147
+ 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) {
150
+ if (localization.isDefault) {
151
+ var defaultPath = path_1.default.join(folderPath, "default.json");
152
+ (0, file_util_1.createFile)(defaultPath, localization);
153
+ }
154
+ });
155
+ };
156
+ exports.saveLocalizations = saveLocalizations;
157
+ /**
158
+ * Plugin Related
159
+ */
160
+ var loadPlugins = function (projectId) {
161
+ return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "plugins");
162
+ };
163
+ exports.loadPlugins = loadPlugins;
164
+ var loadPlugin = function (projectId, code) {
165
+ return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "plugins", code);
166
+ };
167
+ exports.loadPlugin = loadPlugin;
168
+ var savePlugins = function (projectId, plugins) {
169
+ (0, file_util_1.saveEntities)(projectId, "plugins", plugins, function (plugin) { return plugin.code; });
170
+ };
171
+ exports.savePlugins = savePlugins;
172
+ /**
173
+ * DEV APIs Related
174
+ */
175
+ var loadDevAPIs = function (projectId) {
176
+ return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "dev-apis");
177
+ };
178
+ exports.loadDevAPIs = loadDevAPIs;
179
+ var loadDevAPI = function (projectId, uuid) {
180
+ return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "dev-apis", uuid);
181
+ };
182
+ exports.loadDevAPI = loadDevAPI;
183
+ var saveDevAPIs = function (projectId, devApis) {
184
+ (0, file_util_1.saveEntities)(projectId, "dev-apis", devApis, function (plugin) { return plugin.uuid; });
185
+ };
186
+ exports.saveDevAPIs = saveDevAPIs;
187
+ /**
188
+ * Template Related
189
+ */
190
+ var loadTemplates = function (projectId) {
191
+ return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "templates");
192
+ };
193
+ exports.loadTemplates = loadTemplates;
194
+ var loadTemplate = function (projectId, uuid) {
195
+ return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "templates", uuid);
196
+ };
197
+ exports.loadTemplate = loadTemplate;
198
+ var saveTemplates = function (projectId, templates) {
199
+ (0, file_util_1.saveEntities)(projectId, "templates", templates, function (template) { return template.uuid; });
200
+ };
201
+ exports.saveTemplates = saveTemplates;
202
+ /**
203
+ * Collection Related
204
+ */
205
+ var loadCollections = function (projectId) {
206
+ return (0, file_util_1.loadJsonFilesFromSubfolder)(projectId, "collections");
207
+ };
208
+ exports.loadCollections = loadCollections;
209
+ var loadCollection = function (projectId, uuid) {
210
+ return (0, file_util_1.loadSingleJsonFromSubfolder)(projectId, "collections", uuid);
211
+ };
212
+ 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"));
216
+ (0, file_util_1.createFile)(defaultPath, collection);
217
+ });
218
+ };
219
+ exports.saveCollections = saveCollections;
@@ -7,9 +7,7 @@ exports.DATE_REGEX = /^[12]\d{3}(-(0[1-9]|1[0-2])(-(0[1-9]|[12][0-9]|3[01]))?)(T
7
7
  var createLoggerDateFormat = function (timezone) {
8
8
  if (timezone === void 0) { timezone = ""; }
9
9
  var result = moment();
10
- console.log("\n result 1 :>> ", result);
11
10
  result = timezone ? result.utcOffset(timezone) : result;
12
- console.log("\n result 2 :>> ", result);
13
11
  return result.format("YYYY-MM-DD");
14
12
  };
15
13
  exports.createLoggerDateFormat = createLoggerDateFormat;
@@ -20,9 +18,7 @@ exports.createLoggerPreviouseDateFormat = createLoggerPreviouseDateFormat;
20
18
  var createLogsDateFormat = function (timezone) {
21
19
  if (timezone === void 0) { timezone = ""; }
22
20
  var result = moment();
23
- console.log("\n result 1 :>> ", result);
24
21
  result = timezone ? result.utcOffset(timezone) : result;
25
- console.log("\n result 2 :>> ", result);
26
22
  return result.format("YYYY-MM-DDTHH:mm:ss.SSS");
27
23
  };
28
24
  exports.createLogsDateFormat = createLogsDateFormat;
@@ -54,15 +50,11 @@ var getDateRangeValue = function (key, field, value) {
54
50
  var endValue = "";
55
51
  switch (value) {
56
52
  case drapcode_constant_1.CURRENT_MONTH:
57
- // Start of the current month
58
53
  startValue = moment().startOf("month");
59
- // End of the current month
60
54
  endValue = moment().endOf("month");
61
55
  break;
62
56
  case drapcode_constant_1.CURRENT_YEAR:
63
- // Start of the current year
64
57
  startValue = moment().startOf("year");
65
- // End of the current year
66
58
  endValue = moment().endOf("year");
67
59
  break;
68
60
  default:
@@ -124,19 +116,14 @@ exports.nextDayDate = nextDayDate;
124
116
  var timezoneDateParse = function (value, nextDay, prevDay) {
125
117
  if (nextDay === void 0) { nextDay = false; }
126
118
  if (prevDay === void 0) { prevDay = false; }
127
- console.log("value", value);
128
- console.log("");
129
119
  var timeZoneDate = moment(value);
130
- console.log("After Parse Date String into Date", timeZoneDate);
131
120
  if (nextDay && value.length <= 10) {
132
121
  timeZoneDate = timeZoneDate.add(1, "days");
133
122
  }
134
123
  if (prevDay && value.length <= 10) {
135
124
  timeZoneDate = timeZoneDate.subtract(1, "days");
136
125
  }
137
- console.log("If it was for end date ".concat(nextDay, " then"), timeZoneDate);
138
126
  timeZoneDate = timeZoneDate.format("YYYY-MM-DDTHH:mm:ss");
139
- console.log("Format Date into date string", timeZoneDate);
140
127
  return new Date(timeZoneDate);
141
128
  };
142
129
  exports.timezoneDateParse = timezoneDateParse;
@@ -0,0 +1,7 @@
1
+ export declare const checkFolder: (path: string | any) => void;
2
+ export declare const verifyProjectSettingFolder: (projectId: string) => boolean;
3
+ export declare const readFile: (filePath: string | any) => any;
4
+ export declare const createFile: (filePath: string | any, content: any) => void;
5
+ export declare const loadJsonFilesFromSubfolder: (projectId: string, subfolder: string, excludeFiles?: string[]) => any[];
6
+ export declare const loadSingleJsonFromSubfolder: (projectId: string, subfolder: string, fileName: string) => any;
7
+ export declare const saveEntities: (projectId: string, folderName: string, entities: any[], getFileName: (entity: any) => string, handleExtraSave?: ((folderPath: string, entity: any) => void) | undefined) => void;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.saveEntities = exports.loadSingleJsonFromSubfolder = exports.loadJsonFilesFromSubfolder = exports.createFile = exports.readFile = exports.verifyProjectSettingFolder = exports.checkFolder = void 0;
7
+ var fs_1 = require("fs");
8
+ var path_1 = __importDefault(require("path"));
9
+ var filePath = process.env.BUILD_FOLDER;
10
+ var checkFolder = function (path) {
11
+ if (!path) {
12
+ return;
13
+ }
14
+ if (!(0, fs_1.existsSync)(path)) {
15
+ try {
16
+ (0, fs_1.mkdirSync)(path);
17
+ }
18
+ catch (error) {
19
+ console.error(error);
20
+ }
21
+ }
22
+ };
23
+ exports.checkFolder = checkFolder;
24
+ var verifyProjectSettingFolder = function (projectId) {
25
+ var projectPath = path_1.default.join(filePath, "project_".concat(projectId));
26
+ return (0, fs_1.existsSync)(filePath) && (0, fs_1.existsSync)(projectPath);
27
+ };
28
+ exports.verifyProjectSettingFolder = verifyProjectSettingFolder;
29
+ var readFile = function (filePath) {
30
+ try {
31
+ if (!(0, fs_1.existsSync)(filePath)) {
32
+ return null;
33
+ }
34
+ var content = (0, fs_1.readFileSync)(filePath, "utf8");
35
+ if (!content)
36
+ return null;
37
+ return JSON.parse(content);
38
+ }
39
+ catch (error) {
40
+ console.log("error :>> ", error);
41
+ return null;
42
+ }
43
+ };
44
+ exports.readFile = readFile;
45
+ var createFile = function (filePath, content) {
46
+ try {
47
+ (0, fs_1.writeFileSync)(filePath, JSON.stringify(content));
48
+ }
49
+ catch (error) {
50
+ console.log("error :>> ", error);
51
+ }
52
+ };
53
+ exports.createFile = createFile;
54
+ var loadJsonFilesFromSubfolder = function (projectId, subfolder, excludeFiles) {
55
+ if (excludeFiles === void 0) { excludeFiles = []; }
56
+ if (!projectId)
57
+ return [];
58
+ var isMainExists = (0, exports.verifyProjectSettingFolder)(projectId);
59
+ if (!isMainExists)
60
+ return [];
61
+ var folderPath = path_1.default.join(filePath, "project_".concat(projectId), subfolder);
62
+ if (!(0, fs_1.existsSync)(folderPath))
63
+ return [];
64
+ var files = (0, fs_1.readdirSync)(folderPath);
65
+ var result = [];
66
+ for (var _i = 0, files_1 = files; _i < files_1.length; _i++) {
67
+ var file = files_1[_i];
68
+ if (!file.endsWith(".json") || excludeFiles.includes(file))
69
+ continue;
70
+ var json = (0, exports.readFile)(path_1.default.join(folderPath, file));
71
+ if (json) {
72
+ result.push(json);
73
+ }
74
+ }
75
+ return result;
76
+ };
77
+ exports.loadJsonFilesFromSubfolder = loadJsonFilesFromSubfolder;
78
+ var loadSingleJsonFromSubfolder = function (projectId, subfolder, fileName) {
79
+ if (!projectId || !fileName)
80
+ return null;
81
+ var isMainExists = (0, exports.verifyProjectSettingFolder)(projectId);
82
+ if (!isMainExists)
83
+ return null;
84
+ var folderPath = path_1.default.join(filePath, "project_".concat(projectId), subfolder);
85
+ if (!(0, fs_1.existsSync)(folderPath))
86
+ return null;
87
+ var iFilePath = path_1.default.join(folderPath, "".concat(fileName, ".json"));
88
+ return (0, exports.readFile)(iFilePath);
89
+ };
90
+ exports.loadSingleJsonFromSubfolder = loadSingleJsonFromSubfolder;
91
+ var saveEntities = function (projectId, folderName, entities, getFileName, handleExtraSave) {
92
+ if (!projectId || !Array.isArray(entities) || entities.length === 0) {
93
+ return;
94
+ }
95
+ (0, exports.checkFolder)(filePath);
96
+ var projectFolder = path_1.default.join(filePath, "project_".concat(projectId));
97
+ (0, exports.checkFolder)(projectFolder);
98
+ var targetFolder = path_1.default.join(projectFolder, folderName);
99
+ (0, exports.checkFolder)(targetFolder);
100
+ for (var _i = 0, entities_1 = entities; _i < entities_1.length; _i++) {
101
+ var entity = entities_1[_i];
102
+ var fileName = getFileName(entity);
103
+ if (!fileName || typeof fileName !== "string")
104
+ continue;
105
+ try {
106
+ var filePath_1 = path_1.default.join(targetFolder, "".concat(fileName, ".json"));
107
+ console.log("".concat(folderName, " filePath :>> "), filePath_1);
108
+ (0, exports.createFile)(filePath_1, entity);
109
+ if (handleExtraSave) {
110
+ handleExtraSave(targetFolder, entity);
111
+ }
112
+ }
113
+ catch (error) {
114
+ console.error("Failed to save ".concat(folderName, " \"").concat(fileName, "\":"), error);
115
+ }
116
+ }
117
+ };
118
+ exports.saveEntities = saveEntities;