@contentstack/datasync-manager 1.2.4 → 2.0.0
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/dist/api.js +13 -9
- 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 +20 -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 +52 -42
- 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 +35 -25
- package/package.json +3 -2
package/dist/api.js
CHANGED
|
@@ -13,32 +13,35 @@ 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
31
|
'api_key': Contentstack.apiKey,
|
|
32
|
+
branch: Contentstack.branch,
|
|
31
33
|
};
|
|
32
34
|
if (Contentstack.MAX_RETRY_LIMIT) {
|
|
33
35
|
MAX_RETRY_LIMIT = Contentstack.MAX_RETRY_LIMIT;
|
|
34
36
|
}
|
|
35
37
|
};
|
|
38
|
+
exports.init = init;
|
|
36
39
|
/**
|
|
37
40
|
* @description Make API requests to Contentstack
|
|
38
41
|
* @param {Object} req - API request object
|
|
39
42
|
* @param {Number} RETRY - API request retry counter
|
|
40
43
|
*/
|
|
41
|
-
|
|
44
|
+
const get = (req, RETRY = 1) => {
|
|
42
45
|
return new Promise((resolve, reject) => {
|
|
43
46
|
if (RETRY > MAX_RETRY_LIMIT) {
|
|
44
47
|
return reject(new Error('Max retry limit exceeded!'));
|
|
@@ -46,13 +49,13 @@ exports.get = (req, RETRY = 1) => {
|
|
|
46
49
|
req.method = Contentstack.verbs.get;
|
|
47
50
|
req.path = req.path || Contentstack.apis.sync;
|
|
48
51
|
if (req.qs) {
|
|
49
|
-
req.path += `?${querystring_1.stringify(req.qs)}`;
|
|
52
|
+
req.path += `?${(0, querystring_1.stringify)(req.qs)}`;
|
|
50
53
|
}
|
|
51
54
|
const options = {
|
|
52
55
|
headers: Contentstack.headers,
|
|
53
56
|
hostname: Contentstack.host,
|
|
54
57
|
method: Contentstack.verbs.get,
|
|
55
|
-
path: req.path,
|
|
58
|
+
path: (0, sanitize_url_1.sanitizeUrl)(req.path),
|
|
56
59
|
port: Contentstack.port,
|
|
57
60
|
protocol: Contentstack.protocol,
|
|
58
61
|
};
|
|
@@ -60,7 +63,7 @@ exports.get = (req, RETRY = 1) => {
|
|
|
60
63
|
debug(`${options.method.toUpperCase()}: ${options.path}`);
|
|
61
64
|
let timeDelay;
|
|
62
65
|
let body = '';
|
|
63
|
-
https_1.request(options, (response) => {
|
|
66
|
+
(0, https_1.request)(options, (response) => {
|
|
64
67
|
response
|
|
65
68
|
.setEncoding('utf-8')
|
|
66
69
|
.on('data', (chunk) => body += chunk)
|
|
@@ -73,7 +76,7 @@ exports.get = (req, RETRY = 1) => {
|
|
|
73
76
|
timeDelay = Math.pow(Math.SQRT2, RETRY) * 200;
|
|
74
77
|
debug(`API rate limit exceeded. Retrying ${options.path} with ${timeDelay} sec delay`);
|
|
75
78
|
return setTimeout(() => {
|
|
76
|
-
return exports.get(req, RETRY)
|
|
79
|
+
return (0, exports.get)(req, RETRY)
|
|
77
80
|
.then(resolve)
|
|
78
81
|
.catch(reject);
|
|
79
82
|
}, timeDelay);
|
|
@@ -84,7 +87,7 @@ exports.get = (req, RETRY = 1) => {
|
|
|
84
87
|
debug(`Retrying ${options.path} with ${timeDelay} sec delay`);
|
|
85
88
|
RETRY++;
|
|
86
89
|
return setTimeout(() => {
|
|
87
|
-
return exports.get(req, RETRY)
|
|
90
|
+
return (0, exports.get)(req, RETRY)
|
|
88
91
|
.then(resolve)
|
|
89
92
|
.catch(reject);
|
|
90
93
|
}, timeDelay);
|
|
@@ -103,3 +106,4 @@ exports.get = (req, RETRY = 1) => {
|
|
|
103
106
|
}
|
|
104
107
|
});
|
|
105
108
|
};
|
|
109
|
+
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,8 @@ 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
|
+
data.branch = branch;
|
|
165
168
|
if (data.hasOwnProperty('_checkpoint')) {
|
|
166
169
|
checkpoint = data._checkpoint;
|
|
167
170
|
delete data._checkpoint;
|
|
@@ -174,29 +177,29 @@ class Q extends events_1.EventEmitter {
|
|
|
174
177
|
const afterSyncPlugins = [];
|
|
175
178
|
let transformedData;
|
|
176
179
|
let transformedSchema;
|
|
177
|
-
let { schema } = index_1.getSchema(action, data);
|
|
178
|
-
data = index_1.filterUnwantedKeys(action, data);
|
|
180
|
+
let { schema } = (0, index_1.getSchema)(action, data);
|
|
181
|
+
data = (0, index_1.filterUnwantedKeys)(action, data);
|
|
179
182
|
if (typeof schema !== 'undefined') {
|
|
180
|
-
schema = index_1.filterUnwantedKeys(action, schema);
|
|
183
|
+
schema = (0, index_1.filterUnwantedKeys)(action, schema);
|
|
181
184
|
}
|
|
182
185
|
logger_1.logger.log(`${type}: { content_type: '${contentType}', ${(locale) ? `locale: '${locale}',` : ''} uid: '${uid}'} is in progress`);
|
|
183
186
|
this.pluginInstances.internal.beforeSync.forEach((method) => {
|
|
184
187
|
beforeSyncInternalPlugins.push(() => method(action, data, schema));
|
|
185
188
|
});
|
|
186
|
-
yield series_1.series(beforeSyncInternalPlugins);
|
|
189
|
+
yield (0, series_1.series)(beforeSyncInternalPlugins);
|
|
187
190
|
if (this.syncManager.pluginTransformations) {
|
|
188
191
|
transformedData = data;
|
|
189
192
|
transformedSchema = schema;
|
|
190
193
|
}
|
|
191
194
|
else {
|
|
192
|
-
transformedData = lodash_1.cloneDeep(data);
|
|
193
|
-
transformedSchema = lodash_1.cloneDeep(schema);
|
|
195
|
+
transformedData = (0, lodash_1.cloneDeep)(data);
|
|
196
|
+
transformedSchema = (0, lodash_1.cloneDeep)(schema);
|
|
194
197
|
}
|
|
195
198
|
if (this.syncManager.serializePlugins) {
|
|
196
199
|
this.pluginInstances.external.beforeSync.forEach((method) => {
|
|
197
200
|
beforeSyncPlugins.push(() => method(action, transformedData, transformedSchema));
|
|
198
201
|
});
|
|
199
|
-
yield series_1.series(beforeSyncPlugins);
|
|
202
|
+
yield (0, series_1.series)(beforeSyncPlugins);
|
|
200
203
|
}
|
|
201
204
|
else {
|
|
202
205
|
this.pluginInstances.external.beforeSync.forEach((method) => {
|
|
@@ -208,6 +211,7 @@ class Q extends events_1.EventEmitter {
|
|
|
208
211
|
yield this.contentStore[action](data);
|
|
209
212
|
debug(`Completed '${action}' on connector successfully!`);
|
|
210
213
|
if (typeof schema !== 'undefined') {
|
|
214
|
+
schema.branch = branch;
|
|
211
215
|
yield this.contentStore.updateContentType(schema);
|
|
212
216
|
}
|
|
213
217
|
debug('Connector instance called successfully!');
|
|
@@ -215,7 +219,7 @@ class Q extends events_1.EventEmitter {
|
|
|
215
219
|
this.pluginInstances.external.afterSync.forEach((method) => {
|
|
216
220
|
afterSyncPlugins.push(() => method(action, transformedData, transformedSchema));
|
|
217
221
|
});
|
|
218
|
-
yield series_1.series(afterSyncPlugins);
|
|
222
|
+
yield (0, series_1.series)(afterSyncPlugins);
|
|
219
223
|
}
|
|
220
224
|
else {
|
|
221
225
|
this.pluginInstances.external.afterSync.forEach((method) => {
|
|
@@ -224,7 +228,7 @@ class Q extends events_1.EventEmitter {
|
|
|
224
228
|
yield Promise.all(afterSyncPlugins);
|
|
225
229
|
}
|
|
226
230
|
if (typeof checkpoint !== 'undefined') {
|
|
227
|
-
yield token_management_1.saveToken(checkpoint.name, checkpoint.token);
|
|
231
|
+
yield (0, token_management_1.saveToken)(checkpoint.name, checkpoint.token);
|
|
228
232
|
}
|
|
229
233
|
debug('After action plugins executed successfully!');
|
|
230
234
|
logger_1.logger.log(`${type}: { content_type: '${contentType}', ${(locale) ? `locale: '${locale}',` : ''} uid: '${uid}'} was completed successfully!`);
|