@contentstack/datasync-manager 1.2.3 → 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.
@@ -25,3 +25,4 @@ jobs:
25
25
  description: |
26
26
  PR: ${{ github.event.pull_request.html_url }}
27
27
 
28
+ fields: "${{ secrets.JIRA_FIELDS }}"
package/dist/api.js CHANGED
@@ -8,36 +8,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
8
8
  return (mod && mod.__esModule) ? mod : { "default": mod };
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.get = exports.init = void 0;
11
12
  const debug_1 = __importDefault(require("debug"));
12
13
  const https_1 = require("https");
13
14
  const path_1 = require("path");
14
15
  const querystring_1 = require("querystring");
16
+ const sanitize_url_1 = require("@braintree/sanitize-url");
15
17
  const fs_1 = require("./util/fs");
16
- const debug = debug_1.default('api');
18
+ const debug = (0, debug_1.default)('api');
17
19
  let MAX_RETRY_LIMIT;
18
20
  let Contentstack;
19
21
  /**
20
22
  * @description Initialize sync utilities API requests
21
23
  * @param {Object} contentstack - Contentstack configuration details
22
24
  */
23
- exports.init = (contentstack) => {
24
- 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')));
25
27
  Contentstack = contentstack;
26
28
  Contentstack.headers = {
27
29
  'X-User-Agent': `datasync-manager/v${packageInfo.version}`,
28
30
  'access_token': Contentstack.deliveryToken,
29
31
  'api_key': Contentstack.apiKey,
32
+ branch: Contentstack.branch,
30
33
  };
31
34
  if (Contentstack.MAX_RETRY_LIMIT) {
32
35
  MAX_RETRY_LIMIT = Contentstack.MAX_RETRY_LIMIT;
33
36
  }
34
37
  };
38
+ exports.init = init;
35
39
  /**
36
40
  * @description Make API requests to Contentstack
37
41
  * @param {Object} req - API request object
38
42
  * @param {Number} RETRY - API request retry counter
39
43
  */
40
- exports.get = (req, RETRY = 1) => {
44
+ const get = (req, RETRY = 1) => {
41
45
  return new Promise((resolve, reject) => {
42
46
  if (RETRY > MAX_RETRY_LIMIT) {
43
47
  return reject(new Error('Max retry limit exceeded!'));
@@ -45,13 +49,13 @@ exports.get = (req, RETRY = 1) => {
45
49
  req.method = Contentstack.verbs.get;
46
50
  req.path = req.path || Contentstack.apis.sync;
47
51
  if (req.qs) {
48
- req.path += `?${querystring_1.stringify(req.qs)}`;
52
+ req.path += `?${(0, querystring_1.stringify)(req.qs)}`;
49
53
  }
50
54
  const options = {
51
55
  headers: Contentstack.headers,
52
56
  hostname: Contentstack.host,
53
57
  method: Contentstack.verbs.get,
54
- path: req.path,
58
+ path: (0, sanitize_url_1.sanitizeUrl)(req.path),
55
59
  port: Contentstack.port,
56
60
  protocol: Contentstack.protocol,
57
61
  };
@@ -59,7 +63,7 @@ exports.get = (req, RETRY = 1) => {
59
63
  debug(`${options.method.toUpperCase()}: ${options.path}`);
60
64
  let timeDelay;
61
65
  let body = '';
62
- https_1.request(options, (response) => {
66
+ (0, https_1.request)(options, (response) => {
63
67
  response
64
68
  .setEncoding('utf-8')
65
69
  .on('data', (chunk) => body += chunk)
@@ -72,7 +76,7 @@ exports.get = (req, RETRY = 1) => {
72
76
  timeDelay = Math.pow(Math.SQRT2, RETRY) * 200;
73
77
  debug(`API rate limit exceeded. Retrying ${options.path} with ${timeDelay} sec delay`);
74
78
  return setTimeout(() => {
75
- return exports.get(req, RETRY)
79
+ return (0, exports.get)(req, RETRY)
76
80
  .then(resolve)
77
81
  .catch(reject);
78
82
  }, timeDelay);
@@ -83,7 +87,7 @@ exports.get = (req, RETRY = 1) => {
83
87
  debug(`Retrying ${options.path} with ${timeDelay} sec delay`);
84
88
  RETRY++;
85
89
  return setTimeout(() => {
86
- return exports.get(req, RETRY)
90
+ return (0, exports.get)(req, RETRY)
87
91
  .then(resolve)
88
92
  .catch(reject);
89
93
  }, timeDelay);
@@ -102,3 +106,4 @@ exports.get = (req, RETRY = 1) => {
102
106
  }
103
107
  });
104
108
  };
109
+ exports.get = get;
package/dist/config.js CHANGED
@@ -5,6 +5,7 @@
5
5
  * MIT Licensed
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.config = void 0;
8
9
  /**
9
10
  * @description Default application's internal config
10
11
  */
@@ -85,6 +86,7 @@ exports.config = {
85
86
  options: {
86
87
  logAssetPaths: true,
87
88
  logReferencePaths: true,
89
+ // other overrides...
88
90
  },
89
91
  },
90
92
  {
@@ -4,10 +4,20 @@
4
4
  * Copyright (c) 2019 Contentstack LLC
5
5
  * MIT Licensed
6
6
  */
7
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
+ return new (P || (P = Promise))(function (resolve, reject) {
10
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
14
+ });
15
+ };
7
16
  var __importDefault = (this && this.__importDefault) || function (mod) {
8
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
9
18
  };
10
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.unlock = exports.lock = exports.poke = exports.pop = exports.unshift = exports.push = exports.init = void 0;
11
21
  const debug_1 = __importDefault(require("debug"));
12
22
  const events_1 = require("events");
13
23
  const lodash_1 = require("lodash");
@@ -20,7 +30,7 @@ const promise_map_1 = require("../util/promise.map");
20
30
  const inet_1 = require("./inet");
21
31
  const q_1 = require("./q");
22
32
  const token_management_1 = require("./token-management");
23
- const debug = debug_1.default('sync-core');
33
+ const debug = (0, debug_1.default)('sync-core');
24
34
  const emitter = new events_1.EventEmitter();
25
35
  const formattedAssetType = '_assets';
26
36
  const formattedContentType = '_content_types';
@@ -37,10 +47,10 @@ let Q;
37
47
  * @param {Object} connector - Content connector instance
38
48
  * @param {Object} config - Application config
39
49
  */
40
- exports.init = (contentStore, assetStore) => {
41
- config = __1.getConfig();
50
+ const init = (contentStore, assetStore) => {
51
+ config = (0, __1.getConfig)();
42
52
  Q = new q_1.Q(contentStore, assetStore, config);
43
- api_1.init(config.contentstack);
53
+ (0, api_1.init)(config.contentstack);
44
54
  debug('Sync core:start invoked');
45
55
  return new Promise((resolve, reject) => {
46
56
  try {
@@ -60,8 +70,8 @@ exports.init = (contentStore, assetStore) => {
60
70
  else if (typeof Contentstack.pagination_token === 'string' && Contentstack.pagination_token.length !== 0) {
61
71
  request.qs.pagination_token = Contentstack.pagination_token;
62
72
  }
63
- else if (fs_1.existsSync(paths.token)) {
64
- 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));
65
75
  request.qs[token.name] = token.token;
66
76
  }
67
77
  else {
@@ -83,78 +93,102 @@ exports.init = (contentStore, assetStore) => {
83
93
  }
84
94
  });
85
95
  };
86
- exports.push = (data) => {
96
+ exports.init = init;
97
+ const push = (data) => {
87
98
  Q.emit('push', data);
88
99
  };
89
- exports.unshift = (data) => {
100
+ exports.push = push;
101
+ const unshift = (data) => {
90
102
  Q.emit('push', data);
91
103
  };
92
- exports.pop = () => {
104
+ exports.unshift = unshift;
105
+ const pop = () => {
93
106
  Q.emit('pop');
94
107
  };
108
+ exports.pop = pop;
95
109
  /**
96
110
  * @description Notifies the sync manager utility to wake up and start syncing..
97
111
  */
98
- exports.poke = () => {
99
- logger_1.logger.info('Received \'contentstack sync\' notification');
100
- if (!flag.lockdown) {
101
- flag.WQ = true;
102
- check();
112
+ const poke = () => __awaiter(void 0, void 0, void 0, function* () {
113
+ try {
114
+ debug('Invoked poke');
115
+ logger_1.logger.info('Received \'contentstack sync\' notification');
116
+ if (!flag.lockdown) {
117
+ flag.WQ = true;
118
+ return yield check();
119
+ }
120
+ return null;
103
121
  }
104
- };
122
+ catch (error) {
123
+ debug('Error [poke]', error);
124
+ throw error;
125
+ }
126
+ });
127
+ exports.poke = poke;
105
128
  /**
106
129
  * @description Check's if the status of the app when a new incoming notification is fired
107
130
  * @description Starts processing if the 'SQ: false'
108
131
  */
109
- const check = () => {
110
- debug(`Check called. SQ status is ${flag.SQ} and WQ status is ${flag.WQ}`);
111
- if (!flag.SQ && flag.WQ) {
112
- flag.WQ = false;
113
- flag.SQ = true;
114
- sync().then(() => {
132
+ const check = () => __awaiter(void 0, void 0, void 0, function* () {
133
+ try {
134
+ debug(`Check called. SQ status is ${flag.SQ} and WQ status is ${flag.WQ}`);
135
+ if (!flag.SQ && flag.WQ) {
136
+ flag.WQ = false;
137
+ flag.SQ = true;
138
+ yield sync();
115
139
  debug(`Sync completed and SQ flag updated. Cooloff duration is ${config.syncManager.cooloff}`);
116
140
  setTimeout(() => {
117
141
  flag.SQ = false;
118
142
  emitter.emit('check');
119
143
  }, config.syncManager.cooloff);
144
+ }
145
+ }
146
+ catch (error) {
147
+ logger_1.logger.error(error);
148
+ debug('Error [check]', error);
149
+ check().then(() => {
150
+ debug('passed [check] error');
120
151
  }).catch((error) => {
121
- logger_1.logger.error(error);
122
- check();
152
+ debug('failed [check] error', error);
123
153
  });
154
+ throw error;
124
155
  }
125
- };
156
+ });
126
157
  /**
127
158
  * @description Gets saved token, builds request object and fires the sync process
128
159
  */
129
- const sync = () => {
130
- return new Promise((resolve, reject) => {
131
- return token_management_1.getToken().then((tokenObject) => {
132
- const token = tokenObject;
133
- const request = {
134
- qs: {
135
- environment: process.env.SYNC_ENV || Contentstack.environment || 'development',
136
- limit: config.syncManager.limit,
137
- [token.name]: token.token,
138
- },
139
- };
140
- return fire(request)
141
- .then(resolve);
142
- }).catch((error) => {
143
- return reject(error);
144
- });
145
- });
146
- };
160
+ const sync = () => __awaiter(void 0, void 0, void 0, function* () {
161
+ try {
162
+ debug('started [sync]');
163
+ const tokenObject = yield (0, token_management_1.getToken)();
164
+ debug('tokenObject [sync]', tokenObject);
165
+ const token = tokenObject;
166
+ const request = {
167
+ qs: {
168
+ environment: process.env.SYNC_ENV || Contentstack.environment || 'development',
169
+ limit: config.syncManager.limit,
170
+ [token.name]: token.token,
171
+ },
172
+ };
173
+ return yield fire(request);
174
+ }
175
+ catch (error) {
176
+ debug('Error [sync]', error);
177
+ throw error;
178
+ }
179
+ });
147
180
  /**
148
181
  * @description Used to lockdown the 'sync' process in case of exceptions
149
182
  */
150
- exports.lock = () => {
183
+ const lock = () => {
151
184
  debug('Contentstack sync locked..');
152
185
  flag.lockdown = true;
153
186
  };
187
+ exports.lock = lock;
154
188
  /**
155
189
  * @description Used to unlock the 'sync' process in case of errors/exceptions
156
190
  */
157
- exports.unlock = (refire) => {
191
+ const unlock = (refire) => {
158
192
  debug('Contentstack sync unlocked..', refire);
159
193
  flag.lockdown = false;
160
194
  if (typeof refire === 'boolean' && refire) {
@@ -167,6 +201,7 @@ exports.unlock = (refire) => {
167
201
  }
168
202
  check();
169
203
  };
204
+ exports.unlock = unlock;
170
205
  /**
171
206
  * @description Description required
172
207
  * @param {Object} req - Contentstack sync API request object
@@ -175,22 +210,23 @@ const fire = (req) => {
175
210
  debug(`Fire called with: ${JSON.stringify(req)}`);
176
211
  flag.SQ = true;
177
212
  return new Promise((resolve, reject) => {
178
- return api_1.get(req).then((response) => {
213
+ return (0, api_1.get)(req).then((response) => {
179
214
  delete req.qs.init;
180
215
  delete req.qs.pagination_token;
181
216
  delete req.qs.sync_token;
182
217
  delete req.path;
183
218
  const syncResponse = response;
219
+ debug('Response [fire]', syncResponse.items.length);
184
220
  if (syncResponse.items.length) {
185
- return index_1.filterItems(syncResponse, config).then(() => {
221
+ return (0, index_1.filterItems)(syncResponse, config).then(() => {
186
222
  if (syncResponse.items.length === 0) {
187
223
  return postProcess(req, syncResponse)
188
224
  .then(resolve)
189
225
  .catch(reject);
190
226
  }
191
- syncResponse.items = index_1.formatItems(syncResponse.items, config);
192
- let groupedItems = index_1.groupItems(syncResponse.items);
193
- 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);
194
230
  // send assets data for processing
195
231
  if (groupedItems[formattedAssetType]) {
196
232
  groupedItems[formattedAssetType].forEach((asset) => {
@@ -205,7 +241,7 @@ const fire = (req) => {
205
241
  delete groupedItems[formattedContentType];
206
242
  }
207
243
  const contentTypeUids = Object.keys(groupedItems);
208
- lodash_1.remove(contentTypeUids, (contentTypeUid) => {
244
+ (0, lodash_1.remove)(contentTypeUids, (contentTypeUid) => {
209
245
  const contentType = groupedItems[contentTypeUid];
210
246
  if (contentType.length === 1 && !contentType[0].publish_details) {
211
247
  Q.push(contentType[0]);
@@ -213,9 +249,9 @@ const fire = (req) => {
213
249
  }
214
250
  return false;
215
251
  });
216
- return promise_map_1.map(contentTypeUids, (uid) => {
252
+ return (0, promise_map_1.map)(contentTypeUids, (uid) => {
217
253
  return new Promise((mapResolve, mapReject) => {
218
- return api_1.get({
254
+ return (0, api_1.get)({
219
255
  path: `${Contentstack.apis.content_types}${uid}`,
220
256
  qs: {
221
257
  include_global_field_schema: config.contentstack.query.include_global_field_schema,
@@ -225,17 +261,17 @@ const fire = (req) => {
225
261
  if (schemaResponse.content_type) {
226
262
  const items = groupedItems[uid];
227
263
  items.forEach((entry) => {
228
- entry._content_type = lodash_1.cloneDeep(schemaResponse.content_type);
264
+ entry._content_type = (0, lodash_1.cloneDeep)(schemaResponse.content_type);
229
265
  Q.push(entry);
230
266
  });
231
- return mapResolve();
267
+ return mapResolve('');
232
268
  }
233
269
  const err = new Error('Content type ${uid} schema not found!');
234
270
  // Illegal content type call
235
271
  err.code = 'ICTC';
236
272
  return mapReject(err);
237
273
  }).catch((error) => {
238
- if (inet_1.netConnectivityIssues(error)) {
274
+ if ((0, inet_1.netConnectivityIssues)(error)) {
239
275
  flag.SQ = false;
240
276
  }
241
277
  return mapReject(error);
@@ -246,7 +282,7 @@ const fire = (req) => {
246
282
  .then(resolve)
247
283
  .catch(reject);
248
284
  }).catch((error) => {
249
- if (inet_1.netConnectivityIssues(error)) {
285
+ if ((0, inet_1.netConnectivityIssues)(error)) {
250
286
  flag.SQ = false;
251
287
  }
252
288
  // Errorred while fetching content type schema
@@ -259,7 +295,8 @@ const fire = (req) => {
259
295
  return postProcess(req, syncResponse)
260
296
  .then(resolve);
261
297
  }).catch((error) => {
262
- if (inet_1.netConnectivityIssues(error)) {
298
+ debug('Error [fire]', error);
299
+ if ((0, inet_1.netConnectivityIssues)(error)) {
263
300
  flag.SQ = false;
264
301
  }
265
302
  // do something
@@ -281,7 +318,7 @@ const postProcess = (req, resp) => {
281
318
  else {
282
319
  name = 'sync_token';
283
320
  }
284
- return token_management_1.saveCheckpoint(name, resp[name])
321
+ return (0, token_management_1.saveCheckpoint)(name, resp[name])
285
322
  .then(() => {
286
323
  // re-fire!
287
324
  req.qs[name] = resp[name];
@@ -296,7 +333,7 @@ const postProcess = (req, resp) => {
296
333
  else {
297
334
  if (name === 'sync_token') {
298
335
  flag.SQ = false;
299
- return resolve();
336
+ return resolve('');
300
337
  }
301
338
  return fire(req)
302
339
  .then(resolve)
package/dist/core/inet.js CHANGED
@@ -8,6 +8,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
8
8
  return (mod && mod.__esModule) ? mod : { "default": mod };
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.netConnectivityIssues = exports.checkNetConnectivity = exports.init = void 0;
11
12
  const debug_1 = __importDefault(require("debug"));
12
13
  const dns_socket_1 = __importDefault(require("dns-socket"));
13
14
  const events_1 = require("events");
@@ -15,15 +16,15 @@ const index_1 = require("../index");
15
16
  const logger_1 = require("../util/logger");
16
17
  const index_2 = require("./index");
17
18
  const emitter = new events_1.EventEmitter();
18
- const debug = debug_1.default('inet');
19
+ const debug = (0, debug_1.default)('inet');
19
20
  let disconnected = false;
20
21
  let sm;
21
22
  let query;
22
23
  let port;
23
24
  let dns;
24
25
  let currentTimeout;
25
- exports.init = () => {
26
- sm = index_1.getConfig().syncManager;
26
+ const init = () => {
27
+ sm = (0, index_1.getConfig)().syncManager;
27
28
  query = {
28
29
  questions: [
29
30
  {
@@ -39,8 +40,9 @@ exports.init = () => {
39
40
  // start checking for net connectivity, 30 seconds after the app has started
40
41
  setTimeout(exports.checkNetConnectivity, currentTimeout);
41
42
  };
42
- exports.checkNetConnectivity = () => {
43
- const socket = dns_socket_1.default({
43
+ exports.init = init;
44
+ const checkNetConnectivity = () => {
45
+ const socket = (0, dns_socket_1.default)({
44
46
  retries: sm.inet.retries,
45
47
  timeout: sm.inet.timeout,
46
48
  });
@@ -55,7 +57,7 @@ exports.checkNetConnectivity = () => {
55
57
  });
56
58
  }
57
59
  else if (disconnected) {
58
- index_2.poke();
60
+ (0, index_2.poke)();
59
61
  }
60
62
  disconnected = false;
61
63
  return socket.destroy(() => {
@@ -64,12 +66,14 @@ exports.checkNetConnectivity = () => {
64
66
  });
65
67
  });
66
68
  };
67
- exports.netConnectivityIssues = (error) => {
69
+ exports.checkNetConnectivity = checkNetConnectivity;
70
+ const netConnectivityIssues = (error) => {
68
71
  if (error.code === 'ENOTFOUND' || error.code === 'ETIMEDOUT') {
69
72
  return true;
70
73
  }
71
74
  return false;
72
75
  };
76
+ exports.netConnectivityIssues = netConnectivityIssues;
73
77
  emitter.on('ok', () => {
74
78
  currentTimeout = sm.inet.retryTimeout;
75
79
  debug(`pinging ${sm.inet.host} in ${sm.inet.timeout} ms`);
@@ -8,18 +8,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
8
8
  return (mod && mod.__esModule) ? mod : { "default": mod };
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.load = void 0;
11
12
  const debug_1 = __importDefault(require("debug"));
12
13
  const lodash_1 = require("lodash");
13
14
  const index_1 = require("../util/index");
14
15
  const validations_1 = require("../util/validations");
15
- const debug = debug_1.default('plugins');
16
+ const debug = (0, debug_1.default)('plugins');
16
17
  const pluginMethods = ['beforeSync', 'afterSync'];
17
18
  /**
18
19
  * @description Load registered plugins
19
20
  * @param {Object} config - Application config
20
21
  * @returns {Object} pluginInstance - An instance of plugins, with valid registered methods
21
22
  */
22
- exports.load = (config) => {
23
+ const load = (config) => {
23
24
  debug('Plugins load called');
24
25
  const pluginInstances = {
25
26
  external: {},
@@ -31,20 +32,20 @@ exports.load = (config) => {
31
32
  pluginInstances.internal[pluginMethod] = pluginInstances[pluginMethod] || [];
32
33
  });
33
34
  plugins.forEach((plugin) => {
34
- validations_1.validatePlugin(plugin);
35
+ (0, validations_1.validatePlugin)(plugin);
35
36
  const pluginName = plugin.name;
36
37
  const slicedName = pluginName.slice(0, 13);
37
38
  let isInternal = false;
38
39
  if (slicedName === '_cs_internal_') {
39
40
  isInternal = true;
40
41
  }
41
- const pluginPath = index_1.normalizePluginPath(config, plugin, isInternal);
42
+ const pluginPath = (0, index_1.normalizePluginPath)(config, plugin, isInternal);
42
43
  const Plugin = require(pluginPath);
43
44
  Plugin.options = plugin.options || {};
44
45
  // execute/initiate plugin
45
46
  Plugin();
46
47
  pluginMethods.forEach((pluginMethod) => {
47
- if (lodash_1.hasIn(Plugin, pluginMethod)) {
48
+ if ((0, lodash_1.hasIn)(Plugin, pluginMethod)) {
48
49
  if (plugin.disabled) {
49
50
  // do nothing
50
51
  }
@@ -64,3 +65,4 @@ exports.load = (config) => {
64
65
  debug('Plugins loaded successfully!');
65
66
  return pluginInstances;
66
67
  };
68
+ exports.load = load;
@@ -5,6 +5,7 @@
5
5
  * MIT Licensed
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.configure = void 0;
8
9
  /**
9
10
  * @note 'SIGKILL' cannot have a listener installed, it will unconditionally terminate Node.js on all platforms.
10
11
  * @note 'SIGSTOP' cannot have a listener installed.
@@ -17,8 +18,8 @@ const index_2 = require("./index");
17
18
  * @param {String} signal - Process signal
18
19
  */
19
20
  const handleExit = (signal) => {
20
- index_2.lock();
21
- const { syncManager } = index_1.getConfig();
21
+ (0, index_2.lock)();
22
+ const { syncManager } = (0, index_1.getConfig)();
22
23
  const killDuration = (process.env.KILLDURATION) ? calculateKillDuration() : syncManager.processTimeout;
23
24
  logger_1.logger.info(`Received ${signal}. This will shut down the process in ${killDuration}ms..`);
24
25
  setTimeout(abort, killDuration);
@@ -33,9 +34,9 @@ const handleExit = (signal) => {
33
34
  const unhandledErrors = (error) => {
34
35
  logger_1.logger.error('Unhandled exception caught. Locking down process for 10s to recover..');
35
36
  logger_1.logger.error(error);
36
- index_2.lock();
37
+ (0, index_2.lock)();
37
38
  setTimeout(() => {
38
- index_2.unlock();
39
+ (0, index_2.unlock)();
39
40
  }, 10000);
40
41
  };
41
42
  /**
@@ -44,7 +45,7 @@ const unhandledErrors = (error) => {
44
45
  const calculateKillDuration = () => {
45
46
  const killDuration = parseInt(process.env.KILLDURATION, 10);
46
47
  if (isNaN(killDuration)) {
47
- const { syncManager } = index_1.getConfig();
48
+ const { syncManager } = (0, index_1.getConfig)();
48
49
  return syncManager.processTimeout;
49
50
  }
50
51
  return killDuration;
@@ -55,9 +56,10 @@ const calculateKillDuration = () => {
55
56
  const abort = () => {
56
57
  process.abort();
57
58
  };
58
- exports.configure = () => {
59
+ const configure = () => {
59
60
  process.on('SIGTERM', handleExit);
60
61
  process.on('SIGINT', handleExit);
61
62
  process.on('uncaughtException', unhandledErrors);
62
63
  process.on('unhandledRejection', unhandledErrors);
63
64
  };
65
+ exports.configure = configure;