@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.
@@ -22,27 +22,27 @@ const debug_1 = __importDefault(require("debug"));
22
22
  const index_1 = require("../index");
23
23
  const fs_1 = require("../util/fs");
24
24
  const index_2 = require("../util/index");
25
- const debug = debug_1.default('token-management');
25
+ const debug = (0, debug_1.default)('token-management');
26
26
  let counter = 0;
27
27
  /**
28
28
  * @description Returns 'token details' based on 'token type'
29
29
  * @param {String} type - Token type (checkpoint | current)
30
30
  */
31
- exports.getToken = () => {
31
+ const getToken = () => {
32
32
  return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
33
33
  try {
34
- const config = index_1.getConfig();
34
+ const config = (0, index_1.getConfig)();
35
35
  const checkpoint = config.paths.checkpoint;
36
36
  const token = config.paths.token;
37
37
  let data = {};
38
- if (fs_1.existsSync(checkpoint)) {
38
+ if ((0, fs_1.existsSync)(checkpoint)) {
39
39
  debug(`Checkpoint read: ${checkpoint}`);
40
- const contents = yield fs_1.readFile(checkpoint);
40
+ const contents = yield (0, fs_1.readFile)(checkpoint);
41
41
  data = JSON.parse(contents);
42
42
  }
43
- else if (fs_1.existsSync(token)) {
43
+ else if ((0, fs_1.existsSync)(token)) {
44
44
  debug(`Token read: ${token}`);
45
- const contents = yield fs_1.readFile(token);
45
+ const contents = yield (0, fs_1.readFile)(token);
46
46
  data = JSON.parse(contents);
47
47
  }
48
48
  return resolve(data);
@@ -52,17 +52,18 @@ exports.getToken = () => {
52
52
  }
53
53
  }));
54
54
  };
55
+ exports.getToken = getToken;
55
56
  /**
56
57
  * @description Saves token details
57
58
  * @param {String} name - Name of the token
58
59
  * @param {String} token - Token value
59
60
  * @param {String} type - Token type
60
61
  */
61
- exports.saveToken = (name, token) => {
62
+ const saveToken = (name, token) => {
62
63
  debug(`Save token invoked with name: ${name}, token: ${token}`);
63
64
  return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
64
65
  try {
65
- const config = index_1.getConfig();
66
+ const config = (0, index_1.getConfig)();
66
67
  const path = config.paths.token;
67
68
  const data = {
68
69
  name,
@@ -70,7 +71,7 @@ exports.saveToken = (name, token) => {
70
71
  token,
71
72
  };
72
73
  // write token information @path
73
- yield fs_1.writeFile(path, JSON.stringify(data));
74
+ yield (0, fs_1.writeFile)(path, JSON.stringify(data));
74
75
  const obj = {
75
76
  name,
76
77
  timestamp: new Date().toISOString(),
@@ -83,42 +84,44 @@ exports.saveToken = (name, token) => {
83
84
  else {
84
85
  filename = `${config.paths.ledger}.${counter}`;
85
86
  }
86
- const file = yield index_2.getFile(filename, () => {
87
+ const file = yield (0, index_2.getFile)(filename, () => {
87
88
  counter++;
88
89
  return `${config.paths.ledger}-${counter}`;
89
90
  });
90
- debug(`ledger file: ${file} exists?(${fs_1.existsSync(file)})`);
91
- if (!fs_1.existsSync(file)) {
92
- yield fs_1.writeFile(file, JSON.stringify([obj]));
91
+ debug(`ledger file: ${file} exists?(${(0, fs_1.existsSync)(file)})`);
92
+ if (!(0, fs_1.existsSync)(file)) {
93
+ yield (0, fs_1.writeFile)(file, JSON.stringify([obj]));
93
94
  }
94
95
  else {
95
- const ledger = yield fs_1.readFile(file);
96
+ const ledger = yield (0, fs_1.readFile)(file);
96
97
  const ledgerDetails = JSON.parse(ledger);
97
98
  ledgerDetails.splice(0, 0, obj);
98
- yield fs_1.writeFile(file, JSON.stringify(ledgerDetails));
99
+ yield (0, fs_1.writeFile)(file, JSON.stringify(ledgerDetails));
99
100
  }
100
- return resolve();
101
+ return resolve('');
101
102
  }
102
103
  catch (error) {
103
104
  return reject(error);
104
105
  }
105
106
  }));
106
107
  };
108
+ exports.saveToken = saveToken;
107
109
  /**
108
110
  * @description Saves token details
109
111
  * @param {String} name - Name of the token
110
112
  * @param {String} token - Token value
111
113
  * @param {String} type - Token type
112
114
  */
113
- exports.saveCheckpoint = (name, token) => __awaiter(void 0, void 0, void 0, function* () {
115
+ const saveCheckpoint = (name, token) => __awaiter(void 0, void 0, void 0, function* () {
114
116
  debug(`Save token invoked with name: ${name}, token: ${token}`);
115
- const config = index_1.getConfig();
117
+ const config = (0, index_1.getConfig)();
116
118
  const path = config.paths.checkpoint;
117
119
  const data = {
118
120
  name,
119
121
  timestamp: new Date().toISOString(),
120
122
  token,
121
123
  };
122
- yield fs_1.writeFile(path, JSON.stringify(data));
124
+ yield (0, fs_1.writeFile)(path, JSON.stringify(data));
123
125
  return;
124
126
  });
127
+ exports.saveCheckpoint = saveCheckpoint;
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.debugNotifications = exports.start = exports.notifications = exports.getConfig = exports.setConfig = exports.setListener = exports.setAssetStore = exports.setContentStore = exports.getAssetLocation = exports.pop = exports.unshift = exports.push = void 0;
20
+ exports.debugNotifications = exports.start = exports.notifications = exports.setLogger = exports.getConfig = exports.setConfig = exports.setListener = exports.setAssetStore = exports.setContentStore = exports.getAssetLocation = exports.pop = exports.unshift = exports.push = void 0;
21
21
  const debug_1 = __importDefault(require("debug"));
22
22
  const lodash_1 = require("lodash");
23
23
  const config_1 = require("./config");
@@ -30,24 +30,27 @@ const build_paths_1 = require("./util/build-paths");
30
30
  const index_2 = require("./util/index");
31
31
  const logger_1 = require("./util/logger");
32
32
  const validations_1 = require("./util/validations");
33
- const debug = debug_1.default('sm:index');
33
+ const debug = (0, debug_1.default)('sm:index');
34
34
  let assetStoreInstance;
35
35
  let appConfig = {};
36
36
  let contentStore;
37
37
  let assetStore;
38
38
  let listener;
39
- exports.push = (data) => {
40
- validations_1.validateExternalInput(data);
41
- index_1.push(data);
39
+ const push = (data) => {
40
+ (0, validations_1.validateExternalInput)(data);
41
+ (0, index_1.push)(data);
42
42
  };
43
- exports.unshift = (data) => {
44
- validations_1.validateExternalInput(data);
45
- index_1.unshift(data);
43
+ exports.push = push;
44
+ const unshift = (data) => {
45
+ (0, validations_1.validateExternalInput)(data);
46
+ (0, index_1.unshift)(data);
46
47
  };
47
- exports.pop = () => {
48
- index_1.pop();
48
+ exports.unshift = unshift;
49
+ const pop = () => {
50
+ (0, index_1.pop)();
49
51
  };
50
- exports.getAssetLocation = (asset) => {
52
+ exports.pop = pop;
53
+ const getAssetLocation = (asset) => {
51
54
  return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
52
55
  try {
53
56
  const assetStoreConfig = assetStore.getConfig();
@@ -60,52 +63,58 @@ exports.getAssetLocation = (asset) => {
60
63
  }
61
64
  }));
62
65
  };
66
+ exports.getAssetLocation = getAssetLocation;
63
67
  /**
64
68
  * @public
65
69
  * @method setContentStore
66
70
  * @summary Register content store
67
71
  * @param {object} instance Content store instance
68
72
  */
69
- exports.setContentStore = (instance) => {
73
+ const setContentStore = (instance) => {
70
74
  contentStore = instance;
71
75
  };
76
+ exports.setContentStore = setContentStore;
72
77
  /**
73
78
  * @public
74
79
  * @method setAssetStore
75
80
  * @summary Register asset store
76
81
  * @param {object} instance Asset store instance
77
82
  */
78
- exports.setAssetStore = (instance) => {
83
+ const setAssetStore = (instance) => {
79
84
  assetStore = instance;
80
85
  };
86
+ exports.setAssetStore = setAssetStore;
81
87
  /**
82
88
  * @public
83
89
  * @method setListener
84
90
  * @summary Register listener
85
91
  * @param {object} instance Listener instance
86
92
  */
87
- exports.setListener = (instance) => {
88
- validations_1.validateListener(instance);
93
+ const setListener = (instance) => {
94
+ (0, validations_1.validateListener)(instance);
89
95
  listener = instance;
90
96
  };
97
+ exports.setListener = setListener;
91
98
  /**
92
99
  * @public
93
100
  * @method setConfig
94
101
  * @summary Sets the application's configuration
95
102
  * @param {object} config Application config
96
103
  */
97
- exports.setConfig = (config) => {
104
+ const setConfig = (config) => {
98
105
  appConfig = config;
99
106
  };
107
+ exports.setConfig = setConfig;
100
108
  /**
101
109
  * @public
102
110
  * @method getConfig
103
111
  * @summary Returns the application's configuration
104
112
  * @returns {object} Application config
105
113
  */
106
- exports.getConfig = () => {
114
+ const getConfig = () => {
107
115
  return appConfig;
108
116
  };
117
+ exports.getConfig = getConfig;
109
118
  /**
110
119
  * @public
111
120
  * @method setLogger
@@ -124,37 +133,37 @@ Object.defineProperty(exports, "setLogger", { enumerable: true, get: function ()
124
133
  * @param {object} config Optional application config overrides
125
134
  * @returns {Promise} Returns a promise
126
135
  */
127
- exports.start = (config = {}) => {
136
+ const start = (config = {}) => {
128
137
  return new Promise((resolve, reject) => {
129
138
  try {
130
- validations_1.validateAssetStore(assetStore);
131
- validations_1.validateContentStore(contentStore);
132
- validations_1.validateListener(listener);
133
- appConfig = lodash_1.merge({}, config_1.config, appConfig, config);
134
- validations_1.validateConfig(appConfig);
135
- appConfig.paths = build_paths_1.buildConfigPaths();
139
+ (0, validations_1.validateAssetStore)(assetStore);
140
+ (0, validations_1.validateContentStore)(contentStore);
141
+ (0, validations_1.validateListener)(listener);
142
+ appConfig = (0, lodash_1.merge)({}, config_1.config, appConfig, config);
143
+ (0, validations_1.validateConfig)(appConfig);
144
+ appConfig.paths = (0, build_paths_1.buildConfigPaths)();
136
145
  // since logger is singleton, if previously set, it'll return that isnstance!
137
- logger_1.setLogger();
138
- process_1.configure();
146
+ (0, logger_1.setLogger)();
147
+ (0, process_1.configure)();
139
148
  return assetStore.start(appConfig).then((assetInstance) => {
140
149
  debug('Asset store instance has returned successfully!');
141
- validations_1.validateAssetStoreInstance(assetInstance);
150
+ (0, validations_1.validateAssetStoreInstance)(assetInstance);
142
151
  assetStoreInstance = assetInstance;
143
152
  return contentStore.start(assetInstance, appConfig);
144
153
  }).then((contentStoreInstance) => {
145
154
  debug('Content store instance has returned successfully!');
146
- validations_1.validateContentStoreInstance(contentStoreInstance);
147
- appConfig = index_2.formatSyncFilters(appConfig);
148
- return index_1.init(contentStoreInstance, assetStoreInstance);
155
+ (0, validations_1.validateContentStoreInstance)(contentStoreInstance);
156
+ appConfig = (0, index_2.formatSyncFilters)(appConfig);
157
+ return (0, index_1.init)(contentStoreInstance, assetStoreInstance);
149
158
  }).then(() => {
150
159
  debug('Sync Manager initiated successfully!');
151
160
  listener.register(index_1.poke);
152
161
  // start checking for inet 10 secs after the app has started
153
- inet_1.init();
162
+ (0, inet_1.init)();
154
163
  return listener.start(appConfig);
155
164
  }).then(() => {
156
165
  logger_1.logger.info('Contentstack sync utility started successfully!');
157
- return resolve();
166
+ return resolve('');
158
167
  }).catch(reject);
159
168
  }
160
169
  catch (error) {
@@ -162,19 +171,21 @@ exports.start = (config = {}) => {
162
171
  }
163
172
  });
164
173
  };
174
+ exports.start = start;
165
175
  /**
166
176
  * @public
167
177
  * @method debugNotifications
168
178
  * @param {object} item Item being processed
169
179
  * @returns {void}
170
180
  */
171
- exports.debugNotifications = (action) => {
181
+ const debugNotifications = (action) => {
172
182
  return (item) => {
173
183
  debug(`Notifications: ${action} - ${JSON.stringify(item)}`);
174
184
  };
175
185
  };
186
+ exports.debugNotifications = debugNotifications;
176
187
  q_1.notifications
177
- .on('publish', exports.debugNotifications('publish'))
178
- .on('unpublish', exports.debugNotifications('unpublish'))
179
- .on('delete', exports.debugNotifications('delete'))
180
- .on('error', exports.debugNotifications('error'));
188
+ .on('publish', (0, exports.debugNotifications)('publish'))
189
+ .on('unpublish', (0, exports.debugNotifications)('unpublish'))
190
+ .on('delete', (0, exports.debugNotifications)('delete'))
191
+ .on('error', (0, exports.debugNotifications)('error'));
@@ -11,35 +11,36 @@ const path_1 = require("path");
11
11
  * @description Builds application's config paths where data is stored
12
12
  * @returns {Object} Returns config paths
13
13
  */
14
- exports.buildConfigPaths = () => {
15
- const baseDir = path_1.resolve(path_1.join(__dirname, '..', '..', '..', '..'));
14
+ const buildConfigPaths = () => {
15
+ const baseDir = (0, path_1.resolve)((0, path_1.join)(__dirname, '..', '..', '..', '..'));
16
16
  let pluginPath;
17
17
  let tokenPath;
18
18
  if (process.env.PLUGIN_PATH) {
19
- if (!path_1.isAbsolute(process.env.PLUGIN_PATH)) {
20
- pluginPath = path_1.join(baseDir, process.env.PLUGIN_PATH);
19
+ if (!(0, path_1.isAbsolute)(process.env.PLUGIN_PATH)) {
20
+ pluginPath = (0, path_1.join)(baseDir, process.env.PLUGIN_PATH);
21
21
  }
22
22
  else {
23
23
  pluginPath = process.env.PLUGIN_PATH;
24
24
  }
25
25
  }
26
26
  if (process.env.TOKEN_PATH) {
27
- if (!path_1.isAbsolute(process.env.TOKEN_PATH)) {
28
- tokenPath = path_1.join(baseDir, process.env.TOKEN_PATH);
27
+ if (!(0, path_1.isAbsolute)(process.env.TOKEN_PATH)) {
28
+ tokenPath = (0, path_1.join)(baseDir, process.env.TOKEN_PATH);
29
29
  }
30
30
  else {
31
31
  tokenPath = process.env.TOKEN_PATH;
32
32
  }
33
33
  }
34
34
  const paths = {
35
- baseDir: path_1.resolve(path_1.join(__dirname, '..', '..')),
36
- checkpoint: path_1.resolve(path_1.join(tokenPath || path_1.join(baseDir, '..'), '.checkpoint')),
37
- failed: path_1.resolve(path_1.join(tokenPath || path_1.join(baseDir, '..'), 'unprocessible', 'failed')),
38
- filtered: path_1.resolve(path_1.join(tokenPath || path_1.join(baseDir, '..'), 'unprocessible', 'filtered')),
39
- ledger: path_1.resolve(path_1.join(tokenPath || path_1.join(baseDir, '..'), '.ledger')),
40
- plugin: path_1.resolve(path_1.join(pluginPath || path_1.join(baseDir, '..'), 'plugins')),
41
- token: path_1.resolve(path_1.join(tokenPath || path_1.join(baseDir, '..'), '.token')),
42
- unprocessibleDir: path_1.resolve(path_1.join(tokenPath || baseDir, 'unprocessible')),
35
+ baseDir: (0, path_1.resolve)((0, path_1.join)(__dirname, '..', '..')),
36
+ checkpoint: (0, path_1.resolve)((0, path_1.join)(tokenPath || (0, path_1.join)(baseDir, '..'), '.checkpoint')),
37
+ failed: (0, path_1.resolve)((0, path_1.join)(tokenPath || (0, path_1.join)(baseDir, '..'), 'unprocessible', 'failed')),
38
+ filtered: (0, path_1.resolve)((0, path_1.join)(tokenPath || (0, path_1.join)(baseDir, '..'), 'unprocessible', 'filtered')),
39
+ ledger: (0, path_1.resolve)((0, path_1.join)(tokenPath || (0, path_1.join)(baseDir, '..'), '.ledger')),
40
+ plugin: (0, path_1.resolve)((0, path_1.join)(pluginPath || (0, path_1.join)(baseDir, '..'), 'plugins')),
41
+ token: (0, path_1.resolve)((0, path_1.join)(tokenPath || (0, path_1.join)(baseDir, '..'), '.token')),
42
+ unprocessibleDir: (0, path_1.resolve)((0, path_1.join)(tokenPath || baseDir, 'unprocessible')),
43
43
  };
44
44
  return paths;
45
45
  };
46
+ exports.buildConfigPaths = buildConfigPaths;
package/dist/util/fs.js CHANGED
@@ -9,7 +9,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
9
9
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.mkdir = exports.readFileSync = exports.readFile = exports.writeFile = exports.existsSync = void 0;
12
+ exports.mkdirpSync = exports.stat = exports.mkdir = exports.readFileSync = exports.readFile = exports.writeFile = exports.existsSync = void 0;
13
13
  const Debug = require("debug");
14
14
  const fs_1 = require("fs");
15
15
  Object.defineProperty(exports, "existsSync", { enumerable: true, get: function () { return fs_1.existsSync; } });
@@ -23,19 +23,19 @@ const debug = Debug('sm:util-fs');
23
23
  * @param {Object} data - Data that's to be written
24
24
  * @returns {Promise} Returns a promise
25
25
  */
26
- exports.writeFile = (filePath, data) => {
26
+ const writeFile = (filePath, data) => {
27
27
  debug(`Write file called on ${filePath}`);
28
28
  return new Promise((resolve, reject) => {
29
29
  try {
30
- const fileDirectory = path_1.dirname(filePath);
31
- if (!fs_1.existsSync(fileDirectory)) {
30
+ const fileDirectory = (0, path_1.dirname)(filePath);
31
+ if (!(0, fs_1.existsSync)(fileDirectory)) {
32
32
  mkdirp_1.default.sync(fileDirectory);
33
33
  }
34
- return write_file_atomic_1.default(filePath, (typeof data === 'object') ? JSON.stringify(data) : data, (wfError) => {
34
+ return (0, write_file_atomic_1.default)(filePath, (typeof data === 'object') ? JSON.stringify(data) : data, (wfError) => {
35
35
  if (wfError) {
36
36
  return reject(wfError);
37
37
  }
38
- return resolve();
38
+ return resolve('');
39
39
  });
40
40
  }
41
41
  catch (writeFileError) {
@@ -43,21 +43,22 @@ exports.writeFile = (filePath, data) => {
43
43
  }
44
44
  });
45
45
  };
46
+ exports.writeFile = writeFile;
46
47
  /**
47
48
  * @description A wrapper around nodejs fs module's 'readFile()'
48
49
  * @param {String} filePath - Path from where data is to be read
49
50
  * @returns {Promise} Returns a promise
50
51
  */
51
- exports.readFile = (filePath) => {
52
+ const readFile = (filePath) => {
52
53
  debug(`Read file called on ${filePath}`);
53
54
  return new Promise((resolve, reject) => {
54
55
  try {
55
- return fs_1.stat(filePath, (error, stats) => {
56
+ return (0, fs_1.stat)(filePath, (error, stats) => {
56
57
  if (error) {
57
58
  return reject(error);
58
59
  }
59
60
  else if (stats.isFile) {
60
- return fs_1.readFile(filePath, { encoding: 'utf-8' }, (rfError, data) => {
61
+ return (0, fs_1.readFile)(filePath, { encoding: 'utf-8' }, (rfError, data) => {
61
62
  if (rfError) {
62
63
  return reject(rfError);
63
64
  }
@@ -74,34 +75,36 @@ exports.readFile = (filePath) => {
74
75
  }
75
76
  });
76
77
  };
78
+ exports.readFile = readFile;
77
79
  /**
78
80
  * @description A wrapper around nodejs fs module's 'readFileSync()'
79
81
  * @param filePath - Path from where data is to be read
80
82
  * @returns {String} Returns the data that's been read
81
83
  */
82
- exports.readFileSync = (filePath) => {
84
+ const readFileSync = (filePath) => {
83
85
  debug(`Read file sync called on ${filePath}`);
84
- if (fs_1.existsSync(filePath)) {
85
- return fs_1.readFileSync(filePath, { encoding: 'utf-8' });
86
+ if ((0, fs_1.existsSync)(filePath)) {
87
+ return (0, fs_1.readFileSync)(filePath, { encoding: 'utf-8' });
86
88
  }
87
89
  const err = new Error(`Invalid 'read' operation on file. Expected ${filePath} to be of type 'file'!`);
88
90
  err.code = 'IOORFS';
89
91
  throw err;
90
92
  };
93
+ exports.readFileSync = readFileSync;
91
94
  /**
92
95
  * @description Safely creats a directory at the specified 'path'
93
96
  * @param filePath - Path from where directory is to be created
94
97
  * @returns {String} Returns a promise
95
98
  */
96
- exports.mkdir = (path) => {
99
+ const mkdir = (path) => {
97
100
  debug(`mkdir called on ${path}`);
98
101
  return new Promise((resolve, reject) => {
99
102
  try {
100
- return mkdirp_1.default(path, (error) => {
103
+ return (0, mkdirp_1.default)(path, (error) => {
101
104
  if (error) {
102
105
  return reject(error);
103
106
  }
104
- return resolve();
107
+ return resolve('');
105
108
  });
106
109
  }
107
110
  catch (error) {
@@ -109,6 +112,7 @@ exports.mkdir = (path) => {
109
112
  }
110
113
  });
111
114
  };
115
+ exports.mkdir = mkdir;
112
116
  /**
113
117
  * @description exports fs.stat
114
118
  */