@contentstack/datasync-manager 1.2.4 → 2.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.
- package/LICENSE +1 -1
- package/dist/api.js +16 -10
- package/dist/config.js +1 -0
- package/dist/core/index.js +33 -26
- package/dist/core/inet.js +10 -7
- package/dist/core/plugins.js +6 -5
- package/dist/core/process.js +7 -6
- package/dist/core/q.js +22 -16
- package/dist/core/token-management.js +23 -20
- package/dist/index.js +48 -37
- package/dist/util/build-paths.js +15 -14
- package/dist/util/fs.js +19 -15
- package/dist/util/index.js +53 -43
- package/dist/util/logger.js +3 -2
- package/dist/util/promise.map.js +3 -2
- package/dist/util/series.js +3 -2
- package/dist/util/unprocessible.js +14 -12
- package/dist/util/validations.js +34 -24
- package/package.json +8 -2
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/workflows/codeql-analysis.yml +0 -68
- package/.github/workflows/jira.yml +0 -28
- package/.github/workflows/release.yml +0 -53
- package/.github/workflows/sast-scan.yml +0 -11
- package/.github/workflows/sca-scan.yml +0 -15
- package/.github/workflows/secrets-scan.yml +0 -11
- package/.releaserc +0 -9
- package/.talismanrc +0 -4
- package/CODEOWNERS +0 -1
- package/SECURITY.md +0 -27
- package/example/config.js +0 -60
- package/example/index.js +0 -30
- package/test/api.ts +0 -152
- package/test/core/filteredItems.ts +0 -58
- package/test/core/index.ts +0 -18
- package/test/core/inet.ts +0 -23
- package/test/core/q.ts +0 -42
- package/test/core/sync.ts +0 -19
- package/test/core/token-management.ts +0 -40
- package/test/dummy/api-responses/404.ts +0 -3
- package/test/dummy/api-responses/content-type.ts +0 -30
- package/test/dummy/api-responses/delete-asset.ts +0 -9
- package/test/dummy/api-responses/delete-content-type.ts +0 -6
- package/test/dummy/api-responses/delete-entry.ts +0 -9
- package/test/dummy/api-responses/delete.ts +0 -32
- package/test/dummy/api-responses/empty.ts +0 -7
- package/test/dummy/api-responses/entries.ts +0 -31
- package/test/dummy/api-responses/filter-items.ts +0 -32
- package/test/dummy/api-responses/global-field.ts +0 -175
- package/test/dummy/api-responses/markdown-content-type.ts +0 -202
- package/test/dummy/api-responses/markdown-entries.ts +0 -56
- package/test/dummy/api-responses/mixed.ts +0 -77
- package/test/dummy/api-responses/publish-asset.ts +0 -14
- package/test/dummy/api-responses/publish-entry.ts +0 -14
- package/test/dummy/api-responses/publish.ts +0 -35
- package/test/dummy/api-responses/references-content-type-2.ts +0 -240
- package/test/dummy/api-responses/references-content-type.ts +0 -272
- package/test/dummy/api-responses/references-entries.ts +0 -156
- package/test/dummy/api-responses/unpublish-asset.ts +0 -9
- package/test/dummy/api-responses/unpublish-entry.ts +0 -9
- package/test/dummy/api-responses/unpublish.ts +0 -26
- package/test/dummy/config.ts +0 -34
- package/test/dummy/connector-listener-instances.ts +0 -69
- package/test/dummy/filter-items.ts +0 -32
- package/test/dummy/plugins/myplugin1/index.js +0 -20
- package/test/dummy/plugins/myplugin2/index.js +0 -20
- package/test/dummy/references-content-type.ts +0 -340
- package/test/dummy/references-entry-expected.ts +0 -161
- package/test/dummy/references-entry.ts +0 -95
- package/test/index.ts +0 -330
- package/test/util/fs.ts +0 -92
- package/test/util/index.ts +0 -157
- package/test/util/log-save-filtered-items.ts +0 -42
- package/test/util/validations.ts +0 -158
- package/tslint.json +0 -53
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2023 Contentstack LLC <https://www.contentstack.com/>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/dist/api.js
CHANGED
|
@@ -13,32 +13,37 @@ const debug_1 = __importDefault(require("debug"));
|
|
|
13
13
|
const https_1 = require("https");
|
|
14
14
|
const path_1 = require("path");
|
|
15
15
|
const querystring_1 = require("querystring");
|
|
16
|
+
const sanitize_url_1 = require("@braintree/sanitize-url");
|
|
16
17
|
const fs_1 = require("./util/fs");
|
|
17
|
-
const debug = debug_1.default('api');
|
|
18
|
+
const debug = (0, debug_1.default)('api');
|
|
18
19
|
let MAX_RETRY_LIMIT;
|
|
19
20
|
let Contentstack;
|
|
20
21
|
/**
|
|
21
22
|
* @description Initialize sync utilities API requests
|
|
22
23
|
* @param {Object} contentstack - Contentstack configuration details
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
|
-
const packageInfo = JSON.parse(fs_1.readFileSync(path_1.join(__dirname, '..', 'package.json')));
|
|
25
|
+
const init = (contentstack) => {
|
|
26
|
+
const packageInfo = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '..', 'package.json')));
|
|
26
27
|
Contentstack = contentstack;
|
|
27
28
|
Contentstack.headers = {
|
|
28
29
|
'X-User-Agent': `datasync-manager/v${packageInfo.version}`,
|
|
29
30
|
'access_token': Contentstack.deliveryToken,
|
|
30
|
-
'api_key': Contentstack.apiKey
|
|
31
|
+
'api_key': Contentstack.apiKey
|
|
31
32
|
};
|
|
33
|
+
if (Contentstack.branch) {
|
|
34
|
+
Contentstack.headers['branch'] = Contentstack.branch;
|
|
35
|
+
}
|
|
32
36
|
if (Contentstack.MAX_RETRY_LIMIT) {
|
|
33
37
|
MAX_RETRY_LIMIT = Contentstack.MAX_RETRY_LIMIT;
|
|
34
38
|
}
|
|
35
39
|
};
|
|
40
|
+
exports.init = init;
|
|
36
41
|
/**
|
|
37
42
|
* @description Make API requests to Contentstack
|
|
38
43
|
* @param {Object} req - API request object
|
|
39
44
|
* @param {Number} RETRY - API request retry counter
|
|
40
45
|
*/
|
|
41
|
-
|
|
46
|
+
const get = (req, RETRY = 1) => {
|
|
42
47
|
return new Promise((resolve, reject) => {
|
|
43
48
|
if (RETRY > MAX_RETRY_LIMIT) {
|
|
44
49
|
return reject(new Error('Max retry limit exceeded!'));
|
|
@@ -46,13 +51,13 @@ exports.get = (req, RETRY = 1) => {
|
|
|
46
51
|
req.method = Contentstack.verbs.get;
|
|
47
52
|
req.path = req.path || Contentstack.apis.sync;
|
|
48
53
|
if (req.qs) {
|
|
49
|
-
req.path += `?${querystring_1.stringify(req.qs)}`;
|
|
54
|
+
req.path += `?${(0, querystring_1.stringify)(req.qs)}`;
|
|
50
55
|
}
|
|
51
56
|
const options = {
|
|
52
57
|
headers: Contentstack.headers,
|
|
53
58
|
hostname: Contentstack.host,
|
|
54
59
|
method: Contentstack.verbs.get,
|
|
55
|
-
path: req.path,
|
|
60
|
+
path: (0, sanitize_url_1.sanitizeUrl)(req.path),
|
|
56
61
|
port: Contentstack.port,
|
|
57
62
|
protocol: Contentstack.protocol,
|
|
58
63
|
};
|
|
@@ -60,7 +65,7 @@ exports.get = (req, RETRY = 1) => {
|
|
|
60
65
|
debug(`${options.method.toUpperCase()}: ${options.path}`);
|
|
61
66
|
let timeDelay;
|
|
62
67
|
let body = '';
|
|
63
|
-
https_1.request(options, (response) => {
|
|
68
|
+
(0, https_1.request)(options, (response) => {
|
|
64
69
|
response
|
|
65
70
|
.setEncoding('utf-8')
|
|
66
71
|
.on('data', (chunk) => body += chunk)
|
|
@@ -73,7 +78,7 @@ exports.get = (req, RETRY = 1) => {
|
|
|
73
78
|
timeDelay = Math.pow(Math.SQRT2, RETRY) * 200;
|
|
74
79
|
debug(`API rate limit exceeded. Retrying ${options.path} with ${timeDelay} sec delay`);
|
|
75
80
|
return setTimeout(() => {
|
|
76
|
-
return exports.get(req, RETRY)
|
|
81
|
+
return (0, exports.get)(req, RETRY)
|
|
77
82
|
.then(resolve)
|
|
78
83
|
.catch(reject);
|
|
79
84
|
}, timeDelay);
|
|
@@ -84,7 +89,7 @@ exports.get = (req, RETRY = 1) => {
|
|
|
84
89
|
debug(`Retrying ${options.path} with ${timeDelay} sec delay`);
|
|
85
90
|
RETRY++;
|
|
86
91
|
return setTimeout(() => {
|
|
87
|
-
return exports.get(req, RETRY)
|
|
92
|
+
return (0, exports.get)(req, RETRY)
|
|
88
93
|
.then(resolve)
|
|
89
94
|
.catch(reject);
|
|
90
95
|
}, timeDelay);
|
|
@@ -103,3 +108,4 @@ exports.get = (req, RETRY = 1) => {
|
|
|
103
108
|
}
|
|
104
109
|
});
|
|
105
110
|
};
|
|
111
|
+
exports.get = get;
|
package/dist/config.js
CHANGED
package/dist/core/index.js
CHANGED
|
@@ -30,7 +30,7 @@ const promise_map_1 = require("../util/promise.map");
|
|
|
30
30
|
const inet_1 = require("./inet");
|
|
31
31
|
const q_1 = require("./q");
|
|
32
32
|
const token_management_1 = require("./token-management");
|
|
33
|
-
const debug = debug_1.default('sync-core');
|
|
33
|
+
const debug = (0, debug_1.default)('sync-core');
|
|
34
34
|
const emitter = new events_1.EventEmitter();
|
|
35
35
|
const formattedAssetType = '_assets';
|
|
36
36
|
const formattedContentType = '_content_types';
|
|
@@ -47,10 +47,10 @@ let Q;
|
|
|
47
47
|
* @param {Object} connector - Content connector instance
|
|
48
48
|
* @param {Object} config - Application config
|
|
49
49
|
*/
|
|
50
|
-
|
|
51
|
-
config = __1.getConfig();
|
|
50
|
+
const init = (contentStore, assetStore) => {
|
|
51
|
+
config = (0, __1.getConfig)();
|
|
52
52
|
Q = new q_1.Q(contentStore, assetStore, config);
|
|
53
|
-
api_1.init(config.contentstack);
|
|
53
|
+
(0, api_1.init)(config.contentstack);
|
|
54
54
|
debug('Sync core:start invoked');
|
|
55
55
|
return new Promise((resolve, reject) => {
|
|
56
56
|
try {
|
|
@@ -70,8 +70,8 @@ exports.init = (contentStore, assetStore) => {
|
|
|
70
70
|
else if (typeof Contentstack.pagination_token === 'string' && Contentstack.pagination_token.length !== 0) {
|
|
71
71
|
request.qs.pagination_token = Contentstack.pagination_token;
|
|
72
72
|
}
|
|
73
|
-
else if (fs_1.existsSync(paths.token)) {
|
|
74
|
-
const token = JSON.parse(fs_1.readFileSync(paths.token));
|
|
73
|
+
else if ((0, fs_1.existsSync)(paths.token)) {
|
|
74
|
+
const token = JSON.parse((0, fs_1.readFileSync)(paths.token));
|
|
75
75
|
request.qs[token.name] = token.token;
|
|
76
76
|
}
|
|
77
77
|
else {
|
|
@@ -93,19 +93,23 @@ exports.init = (contentStore, assetStore) => {
|
|
|
93
93
|
}
|
|
94
94
|
});
|
|
95
95
|
};
|
|
96
|
-
exports.
|
|
96
|
+
exports.init = init;
|
|
97
|
+
const push = (data) => {
|
|
97
98
|
Q.emit('push', data);
|
|
98
99
|
};
|
|
99
|
-
exports.
|
|
100
|
+
exports.push = push;
|
|
101
|
+
const unshift = (data) => {
|
|
100
102
|
Q.emit('push', data);
|
|
101
103
|
};
|
|
102
|
-
exports.
|
|
104
|
+
exports.unshift = unshift;
|
|
105
|
+
const pop = () => {
|
|
103
106
|
Q.emit('pop');
|
|
104
107
|
};
|
|
108
|
+
exports.pop = pop;
|
|
105
109
|
/**
|
|
106
110
|
* @description Notifies the sync manager utility to wake up and start syncing..
|
|
107
111
|
*/
|
|
108
|
-
|
|
112
|
+
const poke = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
109
113
|
try {
|
|
110
114
|
debug('Invoked poke');
|
|
111
115
|
logger_1.logger.info('Received \'contentstack sync\' notification');
|
|
@@ -120,6 +124,7 @@ exports.poke = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
120
124
|
throw error;
|
|
121
125
|
}
|
|
122
126
|
});
|
|
127
|
+
exports.poke = poke;
|
|
123
128
|
/**
|
|
124
129
|
* @description Check's if the status of the app when a new incoming notification is fired
|
|
125
130
|
* @description Starts processing if the 'SQ: false'
|
|
@@ -155,7 +160,7 @@ const check = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
155
160
|
const sync = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
156
161
|
try {
|
|
157
162
|
debug('started [sync]');
|
|
158
|
-
const tokenObject = yield token_management_1.getToken();
|
|
163
|
+
const tokenObject = yield (0, token_management_1.getToken)();
|
|
159
164
|
debug('tokenObject [sync]', tokenObject);
|
|
160
165
|
const token = tokenObject;
|
|
161
166
|
const request = {
|
|
@@ -175,14 +180,15 @@ const sync = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
175
180
|
/**
|
|
176
181
|
* @description Used to lockdown the 'sync' process in case of exceptions
|
|
177
182
|
*/
|
|
178
|
-
|
|
183
|
+
const lock = () => {
|
|
179
184
|
debug('Contentstack sync locked..');
|
|
180
185
|
flag.lockdown = true;
|
|
181
186
|
};
|
|
187
|
+
exports.lock = lock;
|
|
182
188
|
/**
|
|
183
189
|
* @description Used to unlock the 'sync' process in case of errors/exceptions
|
|
184
190
|
*/
|
|
185
|
-
|
|
191
|
+
const unlock = (refire) => {
|
|
186
192
|
debug('Contentstack sync unlocked..', refire);
|
|
187
193
|
flag.lockdown = false;
|
|
188
194
|
if (typeof refire === 'boolean' && refire) {
|
|
@@ -195,6 +201,7 @@ exports.unlock = (refire) => {
|
|
|
195
201
|
}
|
|
196
202
|
check();
|
|
197
203
|
};
|
|
204
|
+
exports.unlock = unlock;
|
|
198
205
|
/**
|
|
199
206
|
* @description Description required
|
|
200
207
|
* @param {Object} req - Contentstack sync API request object
|
|
@@ -203,7 +210,7 @@ const fire = (req) => {
|
|
|
203
210
|
debug(`Fire called with: ${JSON.stringify(req)}`);
|
|
204
211
|
flag.SQ = true;
|
|
205
212
|
return new Promise((resolve, reject) => {
|
|
206
|
-
return api_1.get(req).then((response) => {
|
|
213
|
+
return (0, api_1.get)(req).then((response) => {
|
|
207
214
|
delete req.qs.init;
|
|
208
215
|
delete req.qs.pagination_token;
|
|
209
216
|
delete req.qs.sync_token;
|
|
@@ -211,15 +218,15 @@ const fire = (req) => {
|
|
|
211
218
|
const syncResponse = response;
|
|
212
219
|
debug('Response [fire]', syncResponse.items.length);
|
|
213
220
|
if (syncResponse.items.length) {
|
|
214
|
-
return index_1.filterItems(syncResponse, config).then(() => {
|
|
221
|
+
return (0, index_1.filterItems)(syncResponse, config).then(() => {
|
|
215
222
|
if (syncResponse.items.length === 0) {
|
|
216
223
|
return postProcess(req, syncResponse)
|
|
217
224
|
.then(resolve)
|
|
218
225
|
.catch(reject);
|
|
219
226
|
}
|
|
220
|
-
syncResponse.items = index_1.formatItems(syncResponse.items, config);
|
|
221
|
-
let groupedItems = index_1.groupItems(syncResponse.items);
|
|
222
|
-
groupedItems = index_1.markCheckpoint(groupedItems, syncResponse);
|
|
227
|
+
syncResponse.items = (0, index_1.formatItems)(syncResponse.items, config);
|
|
228
|
+
let groupedItems = (0, index_1.groupItems)(syncResponse.items);
|
|
229
|
+
groupedItems = (0, index_1.markCheckpoint)(groupedItems, syncResponse);
|
|
223
230
|
// send assets data for processing
|
|
224
231
|
if (groupedItems[formattedAssetType]) {
|
|
225
232
|
groupedItems[formattedAssetType].forEach((asset) => {
|
|
@@ -234,7 +241,7 @@ const fire = (req) => {
|
|
|
234
241
|
delete groupedItems[formattedContentType];
|
|
235
242
|
}
|
|
236
243
|
const contentTypeUids = Object.keys(groupedItems);
|
|
237
|
-
lodash_1.remove(contentTypeUids, (contentTypeUid) => {
|
|
244
|
+
(0, lodash_1.remove)(contentTypeUids, (contentTypeUid) => {
|
|
238
245
|
const contentType = groupedItems[contentTypeUid];
|
|
239
246
|
if (contentType.length === 1 && !contentType[0].publish_details) {
|
|
240
247
|
Q.push(contentType[0]);
|
|
@@ -242,9 +249,9 @@ const fire = (req) => {
|
|
|
242
249
|
}
|
|
243
250
|
return false;
|
|
244
251
|
});
|
|
245
|
-
return promise_map_1.map(contentTypeUids, (uid) => {
|
|
252
|
+
return (0, promise_map_1.map)(contentTypeUids, (uid) => {
|
|
246
253
|
return new Promise((mapResolve, mapReject) => {
|
|
247
|
-
return api_1.get({
|
|
254
|
+
return (0, api_1.get)({
|
|
248
255
|
path: `${Contentstack.apis.content_types}${uid}`,
|
|
249
256
|
qs: {
|
|
250
257
|
include_global_field_schema: config.contentstack.query.include_global_field_schema,
|
|
@@ -254,7 +261,7 @@ const fire = (req) => {
|
|
|
254
261
|
if (schemaResponse.content_type) {
|
|
255
262
|
const items = groupedItems[uid];
|
|
256
263
|
items.forEach((entry) => {
|
|
257
|
-
entry._content_type = lodash_1.cloneDeep(schemaResponse.content_type);
|
|
264
|
+
entry._content_type = (0, lodash_1.cloneDeep)(schemaResponse.content_type);
|
|
258
265
|
Q.push(entry);
|
|
259
266
|
});
|
|
260
267
|
return mapResolve('');
|
|
@@ -264,7 +271,7 @@ const fire = (req) => {
|
|
|
264
271
|
err.code = 'ICTC';
|
|
265
272
|
return mapReject(err);
|
|
266
273
|
}).catch((error) => {
|
|
267
|
-
if (inet_1.netConnectivityIssues(error)) {
|
|
274
|
+
if ((0, inet_1.netConnectivityIssues)(error)) {
|
|
268
275
|
flag.SQ = false;
|
|
269
276
|
}
|
|
270
277
|
return mapReject(error);
|
|
@@ -275,7 +282,7 @@ const fire = (req) => {
|
|
|
275
282
|
.then(resolve)
|
|
276
283
|
.catch(reject);
|
|
277
284
|
}).catch((error) => {
|
|
278
|
-
if (inet_1.netConnectivityIssues(error)) {
|
|
285
|
+
if ((0, inet_1.netConnectivityIssues)(error)) {
|
|
279
286
|
flag.SQ = false;
|
|
280
287
|
}
|
|
281
288
|
// Errorred while fetching content type schema
|
|
@@ -289,7 +296,7 @@ const fire = (req) => {
|
|
|
289
296
|
.then(resolve);
|
|
290
297
|
}).catch((error) => {
|
|
291
298
|
debug('Error [fire]', error);
|
|
292
|
-
if (inet_1.netConnectivityIssues(error)) {
|
|
299
|
+
if ((0, inet_1.netConnectivityIssues)(error)) {
|
|
293
300
|
flag.SQ = false;
|
|
294
301
|
}
|
|
295
302
|
// do something
|
|
@@ -311,7 +318,7 @@ const postProcess = (req, resp) => {
|
|
|
311
318
|
else {
|
|
312
319
|
name = 'sync_token';
|
|
313
320
|
}
|
|
314
|
-
return token_management_1.saveCheckpoint(name, resp[name])
|
|
321
|
+
return (0, token_management_1.saveCheckpoint)(name, resp[name])
|
|
315
322
|
.then(() => {
|
|
316
323
|
// re-fire!
|
|
317
324
|
req.qs[name] = resp[name];
|
package/dist/core/inet.js
CHANGED
|
@@ -16,15 +16,15 @@ const index_1 = require("../index");
|
|
|
16
16
|
const logger_1 = require("../util/logger");
|
|
17
17
|
const index_2 = require("./index");
|
|
18
18
|
const emitter = new events_1.EventEmitter();
|
|
19
|
-
const debug = debug_1.default('inet');
|
|
19
|
+
const debug = (0, debug_1.default)('inet');
|
|
20
20
|
let disconnected = false;
|
|
21
21
|
let sm;
|
|
22
22
|
let query;
|
|
23
23
|
let port;
|
|
24
24
|
let dns;
|
|
25
25
|
let currentTimeout;
|
|
26
|
-
|
|
27
|
-
sm = index_1.getConfig().syncManager;
|
|
26
|
+
const init = () => {
|
|
27
|
+
sm = (0, index_1.getConfig)().syncManager;
|
|
28
28
|
query = {
|
|
29
29
|
questions: [
|
|
30
30
|
{
|
|
@@ -40,8 +40,9 @@ exports.init = () => {
|
|
|
40
40
|
// start checking for net connectivity, 30 seconds after the app has started
|
|
41
41
|
setTimeout(exports.checkNetConnectivity, currentTimeout);
|
|
42
42
|
};
|
|
43
|
-
exports.
|
|
44
|
-
|
|
43
|
+
exports.init = init;
|
|
44
|
+
const checkNetConnectivity = () => {
|
|
45
|
+
const socket = (0, dns_socket_1.default)({
|
|
45
46
|
retries: sm.inet.retries,
|
|
46
47
|
timeout: sm.inet.timeout,
|
|
47
48
|
});
|
|
@@ -56,7 +57,7 @@ exports.checkNetConnectivity = () => {
|
|
|
56
57
|
});
|
|
57
58
|
}
|
|
58
59
|
else if (disconnected) {
|
|
59
|
-
index_2.poke();
|
|
60
|
+
(0, index_2.poke)();
|
|
60
61
|
}
|
|
61
62
|
disconnected = false;
|
|
62
63
|
return socket.destroy(() => {
|
|
@@ -65,12 +66,14 @@ exports.checkNetConnectivity = () => {
|
|
|
65
66
|
});
|
|
66
67
|
});
|
|
67
68
|
};
|
|
68
|
-
exports.
|
|
69
|
+
exports.checkNetConnectivity = checkNetConnectivity;
|
|
70
|
+
const netConnectivityIssues = (error) => {
|
|
69
71
|
if (error.code === 'ENOTFOUND' || error.code === 'ETIMEDOUT') {
|
|
70
72
|
return true;
|
|
71
73
|
}
|
|
72
74
|
return false;
|
|
73
75
|
};
|
|
76
|
+
exports.netConnectivityIssues = netConnectivityIssues;
|
|
74
77
|
emitter.on('ok', () => {
|
|
75
78
|
currentTimeout = sm.inet.retryTimeout;
|
|
76
79
|
debug(`pinging ${sm.inet.host} in ${sm.inet.timeout} ms`);
|
package/dist/core/plugins.js
CHANGED
|
@@ -13,14 +13,14 @@ const debug_1 = __importDefault(require("debug"));
|
|
|
13
13
|
const lodash_1 = require("lodash");
|
|
14
14
|
const index_1 = require("../util/index");
|
|
15
15
|
const validations_1 = require("../util/validations");
|
|
16
|
-
const debug = debug_1.default('plugins');
|
|
16
|
+
const debug = (0, debug_1.default)('plugins');
|
|
17
17
|
const pluginMethods = ['beforeSync', 'afterSync'];
|
|
18
18
|
/**
|
|
19
19
|
* @description Load registered plugins
|
|
20
20
|
* @param {Object} config - Application config
|
|
21
21
|
* @returns {Object} pluginInstance - An instance of plugins, with valid registered methods
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
const load = (config) => {
|
|
24
24
|
debug('Plugins load called');
|
|
25
25
|
const pluginInstances = {
|
|
26
26
|
external: {},
|
|
@@ -32,20 +32,20 @@ exports.load = (config) => {
|
|
|
32
32
|
pluginInstances.internal[pluginMethod] = pluginInstances[pluginMethod] || [];
|
|
33
33
|
});
|
|
34
34
|
plugins.forEach((plugin) => {
|
|
35
|
-
validations_1.validatePlugin(plugin);
|
|
35
|
+
(0, validations_1.validatePlugin)(plugin);
|
|
36
36
|
const pluginName = plugin.name;
|
|
37
37
|
const slicedName = pluginName.slice(0, 13);
|
|
38
38
|
let isInternal = false;
|
|
39
39
|
if (slicedName === '_cs_internal_') {
|
|
40
40
|
isInternal = true;
|
|
41
41
|
}
|
|
42
|
-
const pluginPath = index_1.normalizePluginPath(config, plugin, isInternal);
|
|
42
|
+
const pluginPath = (0, index_1.normalizePluginPath)(config, plugin, isInternal);
|
|
43
43
|
const Plugin = require(pluginPath);
|
|
44
44
|
Plugin.options = plugin.options || {};
|
|
45
45
|
// execute/initiate plugin
|
|
46
46
|
Plugin();
|
|
47
47
|
pluginMethods.forEach((pluginMethod) => {
|
|
48
|
-
if (lodash_1.hasIn(Plugin, pluginMethod)) {
|
|
48
|
+
if ((0, lodash_1.hasIn)(Plugin, pluginMethod)) {
|
|
49
49
|
if (plugin.disabled) {
|
|
50
50
|
// do nothing
|
|
51
51
|
}
|
|
@@ -65,3 +65,4 @@ exports.load = (config) => {
|
|
|
65
65
|
debug('Plugins loaded successfully!');
|
|
66
66
|
return pluginInstances;
|
|
67
67
|
};
|
|
68
|
+
exports.load = load;
|
package/dist/core/process.js
CHANGED
|
@@ -18,8 +18,8 @@ const index_2 = require("./index");
|
|
|
18
18
|
* @param {String} signal - Process signal
|
|
19
19
|
*/
|
|
20
20
|
const handleExit = (signal) => {
|
|
21
|
-
index_2.lock();
|
|
22
|
-
const { syncManager } = index_1.getConfig();
|
|
21
|
+
(0, index_2.lock)();
|
|
22
|
+
const { syncManager } = (0, index_1.getConfig)();
|
|
23
23
|
const killDuration = (process.env.KILLDURATION) ? calculateKillDuration() : syncManager.processTimeout;
|
|
24
24
|
logger_1.logger.info(`Received ${signal}. This will shut down the process in ${killDuration}ms..`);
|
|
25
25
|
setTimeout(abort, killDuration);
|
|
@@ -34,9 +34,9 @@ const handleExit = (signal) => {
|
|
|
34
34
|
const unhandledErrors = (error) => {
|
|
35
35
|
logger_1.logger.error('Unhandled exception caught. Locking down process for 10s to recover..');
|
|
36
36
|
logger_1.logger.error(error);
|
|
37
|
-
index_2.lock();
|
|
37
|
+
(0, index_2.lock)();
|
|
38
38
|
setTimeout(() => {
|
|
39
|
-
index_2.unlock();
|
|
39
|
+
(0, index_2.unlock)();
|
|
40
40
|
}, 10000);
|
|
41
41
|
};
|
|
42
42
|
/**
|
|
@@ -45,7 +45,7 @@ const unhandledErrors = (error) => {
|
|
|
45
45
|
const calculateKillDuration = () => {
|
|
46
46
|
const killDuration = parseInt(process.env.KILLDURATION, 10);
|
|
47
47
|
if (isNaN(killDuration)) {
|
|
48
|
-
const { syncManager } = index_1.getConfig();
|
|
48
|
+
const { syncManager } = (0, index_1.getConfig)();
|
|
49
49
|
return syncManager.processTimeout;
|
|
50
50
|
}
|
|
51
51
|
return killDuration;
|
|
@@ -56,9 +56,10 @@ const calculateKillDuration = () => {
|
|
|
56
56
|
const abort = () => {
|
|
57
57
|
process.abort();
|
|
58
58
|
};
|
|
59
|
-
|
|
59
|
+
const configure = () => {
|
|
60
60
|
process.on('SIGTERM', handleExit);
|
|
61
61
|
process.on('SIGINT', handleExit);
|
|
62
62
|
process.on('uncaughtException', unhandledErrors);
|
|
63
63
|
process.on('unhandledRejection', unhandledErrors);
|
|
64
64
|
};
|
|
65
|
+
exports.configure = configure;
|
package/dist/core/q.js
CHANGED
|
@@ -28,7 +28,8 @@ const series_1 = require("../util/series");
|
|
|
28
28
|
const unprocessible_1 = require("../util/unprocessible");
|
|
29
29
|
const plugins_1 = require("./plugins");
|
|
30
30
|
const token_management_1 = require("./token-management");
|
|
31
|
-
const
|
|
31
|
+
const index_2 = require("../index");
|
|
32
|
+
const debug = (0, debug_1.default)('q');
|
|
32
33
|
const notifications = new events_1.EventEmitter();
|
|
33
34
|
exports.notifications = notifications;
|
|
34
35
|
let instance = null;
|
|
@@ -47,7 +48,7 @@ class Q extends events_1.EventEmitter {
|
|
|
47
48
|
constructor(contentStore, assetStore, config) {
|
|
48
49
|
if (!instance && contentStore && assetStore && config) {
|
|
49
50
|
super();
|
|
50
|
-
this.pluginInstances = plugins_1.load(config);
|
|
51
|
+
this.pluginInstances = (0, plugins_1.load)(config);
|
|
51
52
|
this.contentStore = contentStore;
|
|
52
53
|
this.syncManager = config.syncManager;
|
|
53
54
|
this.iLock = false;
|
|
@@ -66,7 +67,7 @@ class Q extends events_1.EventEmitter {
|
|
|
66
67
|
this.q.unshift(data);
|
|
67
68
|
if (this.q.length > this.syncManager.queue.pause_threshold) {
|
|
68
69
|
this.iLock = true;
|
|
69
|
-
_1.lock();
|
|
70
|
+
(0, _1.lock)();
|
|
70
71
|
}
|
|
71
72
|
debug(`Content type '${data._content_type_uid}' received for '${data._type}'`);
|
|
72
73
|
this.emit('next');
|
|
@@ -79,7 +80,7 @@ class Q extends events_1.EventEmitter {
|
|
|
79
80
|
this.q.push(data);
|
|
80
81
|
if (this.q.length > this.syncManager.queue.pause_threshold) {
|
|
81
82
|
this.iLock = true;
|
|
82
|
-
_1.lock();
|
|
83
|
+
(0, _1.lock)();
|
|
83
84
|
}
|
|
84
85
|
debug(`Content type '${data._content_type_uid}' received for '${data._type}'`);
|
|
85
86
|
this.emit('next');
|
|
@@ -96,9 +97,9 @@ class Q extends events_1.EventEmitter {
|
|
|
96
97
|
logger_1.logger.error(obj);
|
|
97
98
|
debug(`Error handler called with ${JSON.stringify(obj)}`);
|
|
98
99
|
if (typeof obj.checkpoint !== 'undefined') {
|
|
99
|
-
yield token_management_1.saveToken(obj.checkpoint.name, obj.checkpoint.token);
|
|
100
|
+
yield (0, token_management_1.saveToken)(obj.checkpoint.name, obj.checkpoint.token);
|
|
100
101
|
}
|
|
101
|
-
yield unprocessible_1.saveFailedItems(obj);
|
|
102
|
+
yield (0, unprocessible_1.saveFailedItems)(obj);
|
|
102
103
|
this.inProgress = false;
|
|
103
104
|
this.emit('next');
|
|
104
105
|
}
|
|
@@ -121,7 +122,7 @@ class Q extends events_1.EventEmitter {
|
|
|
121
122
|
return __awaiter(this, void 0, void 0, function* () {
|
|
122
123
|
try {
|
|
123
124
|
if (this.iLock && this.q.length < this.syncManager.queue.resume_threshold) {
|
|
124
|
-
_1.unlock(true);
|
|
125
|
+
(0, _1.unlock)(true);
|
|
125
126
|
this.iLock = false;
|
|
126
127
|
}
|
|
127
128
|
debug(`Calling 'next'. In progress status is ${this.inProgress}, and Q length is ${this.q.length}`);
|
|
@@ -162,6 +163,9 @@ class Q extends events_1.EventEmitter {
|
|
|
162
163
|
const contentType = data._content_type_uid;
|
|
163
164
|
const locale = data.locale;
|
|
164
165
|
const uid = data.uid;
|
|
166
|
+
const branch = (0, index_2.getConfig)().contentstack.branch;
|
|
167
|
+
if (branch)
|
|
168
|
+
data.branch = branch;
|
|
165
169
|
if (data.hasOwnProperty('_checkpoint')) {
|
|
166
170
|
checkpoint = data._checkpoint;
|
|
167
171
|
delete data._checkpoint;
|
|
@@ -174,29 +178,29 @@ class Q extends events_1.EventEmitter {
|
|
|
174
178
|
const afterSyncPlugins = [];
|
|
175
179
|
let transformedData;
|
|
176
180
|
let transformedSchema;
|
|
177
|
-
let { schema } = index_1.getSchema(action, data);
|
|
178
|
-
data = index_1.filterUnwantedKeys(action, data);
|
|
181
|
+
let { schema } = (0, index_1.getSchema)(action, data);
|
|
182
|
+
data = (0, index_1.filterUnwantedKeys)(action, data);
|
|
179
183
|
if (typeof schema !== 'undefined') {
|
|
180
|
-
schema = index_1.filterUnwantedKeys(action, schema);
|
|
184
|
+
schema = (0, index_1.filterUnwantedKeys)(action, schema);
|
|
181
185
|
}
|
|
182
186
|
logger_1.logger.log(`${type}: { content_type: '${contentType}', ${(locale) ? `locale: '${locale}',` : ''} uid: '${uid}'} is in progress`);
|
|
183
187
|
this.pluginInstances.internal.beforeSync.forEach((method) => {
|
|
184
188
|
beforeSyncInternalPlugins.push(() => method(action, data, schema));
|
|
185
189
|
});
|
|
186
|
-
yield series_1.series(beforeSyncInternalPlugins);
|
|
190
|
+
yield (0, series_1.series)(beforeSyncInternalPlugins);
|
|
187
191
|
if (this.syncManager.pluginTransformations) {
|
|
188
192
|
transformedData = data;
|
|
189
193
|
transformedSchema = schema;
|
|
190
194
|
}
|
|
191
195
|
else {
|
|
192
|
-
transformedData = lodash_1.cloneDeep(data);
|
|
193
|
-
transformedSchema = lodash_1.cloneDeep(schema);
|
|
196
|
+
transformedData = (0, lodash_1.cloneDeep)(data);
|
|
197
|
+
transformedSchema = (0, lodash_1.cloneDeep)(schema);
|
|
194
198
|
}
|
|
195
199
|
if (this.syncManager.serializePlugins) {
|
|
196
200
|
this.pluginInstances.external.beforeSync.forEach((method) => {
|
|
197
201
|
beforeSyncPlugins.push(() => method(action, transformedData, transformedSchema));
|
|
198
202
|
});
|
|
199
|
-
yield series_1.series(beforeSyncPlugins);
|
|
203
|
+
yield (0, series_1.series)(beforeSyncPlugins);
|
|
200
204
|
}
|
|
201
205
|
else {
|
|
202
206
|
this.pluginInstances.external.beforeSync.forEach((method) => {
|
|
@@ -208,6 +212,8 @@ class Q extends events_1.EventEmitter {
|
|
|
208
212
|
yield this.contentStore[action](data);
|
|
209
213
|
debug(`Completed '${action}' on connector successfully!`);
|
|
210
214
|
if (typeof schema !== 'undefined') {
|
|
215
|
+
if (branch)
|
|
216
|
+
schema.branch = branch;
|
|
211
217
|
yield this.contentStore.updateContentType(schema);
|
|
212
218
|
}
|
|
213
219
|
debug('Connector instance called successfully!');
|
|
@@ -215,7 +221,7 @@ class Q extends events_1.EventEmitter {
|
|
|
215
221
|
this.pluginInstances.external.afterSync.forEach((method) => {
|
|
216
222
|
afterSyncPlugins.push(() => method(action, transformedData, transformedSchema));
|
|
217
223
|
});
|
|
218
|
-
yield series_1.series(afterSyncPlugins);
|
|
224
|
+
yield (0, series_1.series)(afterSyncPlugins);
|
|
219
225
|
}
|
|
220
226
|
else {
|
|
221
227
|
this.pluginInstances.external.afterSync.forEach((method) => {
|
|
@@ -224,7 +230,7 @@ class Q extends events_1.EventEmitter {
|
|
|
224
230
|
yield Promise.all(afterSyncPlugins);
|
|
225
231
|
}
|
|
226
232
|
if (typeof checkpoint !== 'undefined') {
|
|
227
|
-
yield token_management_1.saveToken(checkpoint.name, checkpoint.token);
|
|
233
|
+
yield (0, token_management_1.saveToken)(checkpoint.name, checkpoint.token);
|
|
228
234
|
}
|
|
229
235
|
debug('After action plugins executed successfully!');
|
|
230
236
|
logger_1.logger.log(`${type}: { content_type: '${contentType}', ${(locale) ? `locale: '${locale}',` : ''} uid: '${uid}'} was completed successfully!`);
|