@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.
@@ -13,7 +13,7 @@ const lodash_1 = require("lodash");
13
13
  * @description Check's if the application's config is enough to start the app without errors
14
14
  * @param {Object} config - Application config
15
15
  */
16
- exports.validateConfig = (config) => {
16
+ const validateConfig = (config) => {
17
17
  const keys = ['listener', 'assetStore', 'contentStore', 'syncManager', 'contentstack',
18
18
  'locales',
19
19
  ];
@@ -22,8 +22,8 @@ exports.validateConfig = (config) => {
22
22
  throw new Error(`Config '${key}' key cannot be undefined`);
23
23
  }
24
24
  });
25
- if (typeof config.contentstack !== 'object' || !config.contentstack.apiKey || !config.contentstack.deliveryToken) {
26
- throw new Error('Config \'contentstack\' should be of type object and have \'apiKey\' and \'token\'');
25
+ if (typeof config.contentstack !== 'object' || !config.contentstack.apiKey || !config.contentstack.deliveryToken || !config.contentstack.branch) {
26
+ throw new Error('Config \'contentstack\' should be of type object and have \'apiKey\', \'token\' and \'branch\'');
27
27
  }
28
28
  if (config.queue) {
29
29
  if (config.queue.resume_threshold >= config.queue.pause_threshold) {
@@ -31,92 +31,98 @@ exports.validateConfig = (config) => {
31
31
  }
32
32
  }
33
33
  };
34
+ exports.validateConfig = validateConfig;
34
35
  /**
35
36
  * @public
36
37
  * @method validateAssetStore
37
38
  * @description Validates if provided asset store has required methods
38
39
  * @param {Object} assetStore - Asset store
39
40
  */
40
- exports.validateAssetStore = (assetStore) => {
41
+ const validateAssetStore = (assetStore) => {
41
42
  if (typeof assetStore !== 'object' && typeof assetStore !== 'function') {
42
43
  throw new Error('Invalid Type! Asset store is of neither \'object\' or \'function\'!');
43
44
  }
44
45
  const methods = ['getConfig', 'getAssetLocation', 'setConfig', 'start'];
45
46
  methods.forEach((method) => {
46
- if (!(lodash_1.hasIn(assetStore, method)) && typeof assetStore[method] === 'function') {
47
+ if (!((0, lodash_1.hasIn)(assetStore, method)) && typeof assetStore[method] === 'function') {
47
48
  throw new Error(`Missing required methods! Asset store is missing '${method}()'!`);
48
49
  }
49
50
  });
50
51
  };
52
+ exports.validateAssetStore = validateAssetStore;
51
53
  /**
52
54
  * @public
53
55
  * @method validateContentStore
54
56
  * @description Validates if provided content store has required methods
55
57
  * @param {Object} contentStore - Content store
56
58
  */
57
- exports.validateContentStore = (contentStore) => {
59
+ const validateContentStore = (contentStore) => {
58
60
  if (typeof contentStore !== 'object' && typeof contentStore !== 'function') {
59
61
  throw new Error('Invalid Type! Content store is of neither \'object\' or \'function\'!');
60
62
  }
61
63
  const methods = ['getConfig', 'setConfig', 'setAssetStore', 'start'];
62
64
  methods.forEach((method) => {
63
- if (!(lodash_1.hasIn(contentStore, method)) && typeof contentStore[method] === 'function') {
65
+ if (!((0, lodash_1.hasIn)(contentStore, method)) && typeof contentStore[method] === 'function') {
64
66
  throw new Error(`Missing required methods! Content store is missing '${method}()'!`);
65
67
  }
66
68
  });
67
69
  };
70
+ exports.validateContentStore = validateContentStore;
68
71
  /**
69
72
  * @public
70
73
  * @method validateListener
71
74
  * @description Validates if the provided listener supports required methods
72
75
  * @param {Object} listener - Listener instance
73
76
  */
74
- exports.validateListener = (listener) => {
77
+ const validateListener = (listener) => {
75
78
  if (typeof listener !== 'object' && typeof listener !== 'function') {
76
79
  throw new Error('Invalid Type! Listener is of neither \'object\' or \'function\'!');
77
80
  }
78
81
  const methods = ['getConfig', 'setConfig', 'start', 'register'];
79
82
  methods.forEach((method) => {
80
- if (!(lodash_1.hasIn(listener, method)) || typeof listener[method] !== 'function') {
83
+ if (!((0, lodash_1.hasIn)(listener, method)) || typeof listener[method] !== 'function') {
81
84
  throw new Error(`Missing required methods! Listener is missing '${method}()'!`);
82
85
  }
83
86
  });
84
87
  };
88
+ exports.validateListener = validateListener;
85
89
  /**
86
90
  * @public
87
91
  * @method validateContentStoreInstance
88
92
  * @description Validates if the registered content store supports required methods
89
93
  * @param {Object} instance - Content store instance
90
94
  */
91
- exports.validateContentStoreInstance = (instance) => {
95
+ const validateContentStoreInstance = (instance) => {
92
96
  const fns = ['publish', 'unpublish', 'delete', 'updateContentType'];
93
97
  fns.forEach((fn) => {
94
- if (!(lodash_1.hasIn(instance, fn)) && typeof instance[fn] === 'function') {
98
+ if (!((0, lodash_1.hasIn)(instance, fn)) && typeof instance[fn] === 'function') {
95
99
  throw new Error(`${instance} content store does not support '${fn}()'`);
96
100
  }
97
101
  });
98
102
  };
103
+ exports.validateContentStoreInstance = validateContentStoreInstance;
99
104
  /**
100
105
  * @public
101
106
  * @method validateAssetStoreInstance
102
107
  * @description Validates if the registered asset store supports required methods
103
108
  * @param {Object} instance - Asset store instance
104
109
  */
105
- exports.validateAssetStoreInstance = (instance) => {
110
+ const validateAssetStoreInstance = (instance) => {
106
111
  const fns = ['delete', 'download', 'unpublish'];
107
112
  fns.forEach((fn) => {
108
- if (!(lodash_1.hasIn(instance, fn)) && typeof instance[fn] === 'function') {
113
+ if (!((0, lodash_1.hasIn)(instance, fn)) && typeof instance[fn] === 'function') {
109
114
  throw new Error(`${instance} asset store does not support '${fn}()'`);
110
115
  }
111
116
  });
112
117
  };
118
+ exports.validateAssetStoreInstance = validateAssetStoreInstance;
113
119
  /**
114
120
  * @public
115
121
  * @method validateExternalInput
116
122
  * @description Validates if the input provided by external method into 'Q' conforms standards
117
123
  * @param {Object} data - Input data
118
124
  */
119
- exports.validateExternalInput = (data) => {
125
+ const validateExternalInput = (data) => {
120
126
  if (typeof data._content_type_uid !== 'string' || data._content_type_uid.length === 0) {
121
127
  throw new Error('data._content_type_uid should be of type string and not empty!');
122
128
  }
@@ -126,15 +132,16 @@ exports.validateExternalInput = (data) => {
126
132
  if (typeof data.locale !== 'string' || data.locale.length === 0) {
127
133
  throw new Error('data.locale should be of type string and not empty!');
128
134
  }
129
- if (!(lodash_1.isPlainObject(data)) || lodash_1.isEmpty(data)) {
135
+ if (!((0, lodash_1.isPlainObject)(data)) || (0, lodash_1.isEmpty)(data)) {
130
136
  throw new Error('data should be of type object and not empty!');
131
137
  }
132
138
  };
139
+ exports.validateExternalInput = validateExternalInput;
133
140
  /**
134
141
  * @description Validates if the custom logger set supports required methods
135
142
  * @param {Object} instance - Custom logger instance
136
143
  */
137
- exports.validateLogger = (instance) => {
144
+ const validateLogger = (instance) => {
138
145
  let flag = false;
139
146
  if (!instance) {
140
147
  return flag;
@@ -147,7 +154,8 @@ exports.validateLogger = (instance) => {
147
154
  });
148
155
  return !flag;
149
156
  };
150
- exports.validateItemStructure = (item) => {
157
+ exports.validateLogger = validateLogger;
158
+ const validateItemStructure = (item) => {
151
159
  try {
152
160
  if (!(item.type) || typeof item.type !== 'string' || !(item.type.length)) {
153
161
  item._error = '\'type\' key is missing!';
@@ -174,12 +182,13 @@ exports.validateItemStructure = (item) => {
174
182
  return false;
175
183
  }
176
184
  };
185
+ exports.validateItemStructure = validateItemStructure;
177
186
  const assetPublishedStructure = (asset) => {
178
187
  const requiredKeys = ['content_type_uid', 'data', 'data.uid', 'data.url', 'data.publish_details',
179
188
  'data.publish_details.locale', 'data.title',
180
189
  ];
181
190
  requiredKeys.forEach((key) => {
182
- if (!(lodash_1.hasIn(asset, key))) {
191
+ if (!((0, lodash_1.hasIn)(asset, key))) {
183
192
  asset._error = asset._error || '';
184
193
  asset._error += `${key} is missing!\t`;
185
194
  }
@@ -189,17 +198,18 @@ const assetPublishedStructure = (asset) => {
189
198
  }
190
199
  return true;
191
200
  };
192
- exports.validatePlugin = (plugin) => {
201
+ const validatePlugin = (plugin) => {
193
202
  if (!plugin.name || typeof plugin.name !== 'string' || plugin.name.length < 1) {
194
203
  throw new Error(`Invalid plugin config, 'plugin.name' is a required property!`);
195
204
  }
196
205
  };
206
+ exports.validatePlugin = validatePlugin;
197
207
  const entryPublishedStructure = (entry) => {
198
208
  const requiredKeys = ['content_type_uid', 'data', 'data.uid', 'data.publish_details',
199
209
  'data.publish_details.locale',
200
210
  ];
201
211
  requiredKeys.forEach((key) => {
202
- if (!(lodash_1.hasIn(entry, key))) {
212
+ if (!((0, lodash_1.hasIn)(entry, key))) {
203
213
  entry._error = entry._error || '';
204
214
  entry._error += `${key} is missing!`;
205
215
  }
@@ -212,7 +222,7 @@ const entryPublishedStructure = (entry) => {
212
222
  const assetDeletedStructure = (asset) => {
213
223
  const requiredKeys = ['content_type_uid', 'data', 'data.uid', 'data.locale'];
214
224
  requiredKeys.forEach((key) => {
215
- if (!(lodash_1.hasIn(asset, key))) {
225
+ if (!((0, lodash_1.hasIn)(asset, key))) {
216
226
  asset._error = asset._error || '';
217
227
  asset._error += `${key} is missing!`;
218
228
  }
@@ -225,7 +235,7 @@ const assetDeletedStructure = (asset) => {
225
235
  const entryDeletedStructure = (entry) => {
226
236
  const requiredKeys = ['content_type_uid', 'data', 'data.uid', 'data.locale'];
227
237
  requiredKeys.forEach((key) => {
228
- if (!(lodash_1.hasIn(entry, key))) {
238
+ if (!((0, lodash_1.hasIn)(entry, key))) {
229
239
  entry._error = entry._error || '';
230
240
  entry._error += `${key} is missing!`;
231
241
  }
@@ -238,7 +248,7 @@ const entryDeletedStructure = (entry) => {
238
248
  const assetUnpublishedStructure = (asset) => {
239
249
  const requiredKeys = ['content_type_uid', 'data', 'data.uid', 'data.locale'];
240
250
  requiredKeys.forEach((key) => {
241
- if (!(lodash_1.hasIn(asset, key))) {
251
+ if (!((0, lodash_1.hasIn)(asset, key))) {
242
252
  asset._error = asset._error || '';
243
253
  asset._error += `${key} is missing!`;
244
254
  }
@@ -251,7 +261,7 @@ const assetUnpublishedStructure = (asset) => {
251
261
  const entryUnpublishedStructure = (entry) => {
252
262
  const requiredKeys = ['content_type_uid', 'data', 'data.uid', 'data.locale'];
253
263
  requiredKeys.forEach((key) => {
254
- if (!(lodash_1.hasIn(entry, key))) {
264
+ if (!((0, lodash_1.hasIn)(entry, key))) {
255
265
  entry._error = entry._error || '';
256
266
  entry._error += `${key} is missing!`;
257
267
  }
@@ -264,7 +274,7 @@ const entryUnpublishedStructure = (entry) => {
264
274
  const contentTypeDeletedStructure = (contentType) => {
265
275
  const requiredKeys = ['content_type_uid'];
266
276
  requiredKeys.forEach((key) => {
267
- if (!(lodash_1.hasIn(contentType, key))) {
277
+ if (!((0, lodash_1.hasIn)(contentType, key))) {
268
278
  contentType._error = contentType._error || '';
269
279
  contentType._error += `${key} is missing!`;
270
280
  }
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@contentstack/datasync-manager",
3
3
  "author": "Contentstack LLC <support@contentstack.com>",
4
- "version": "1.2.4",
4
+ "version": "2.0.0",
5
5
  "description": "The primary module of Contentstack DataSync. Syncs Contentstack data with your server using Contentstack Sync API",
6
6
  "main": "dist/index.js",
7
7
  "dependencies": {
8
+ "@braintree/sanitize-url": "^6.0.2",
8
9
  "debug": "^4.3.4",
9
10
  "dns-socket": "^4.2.2",
10
11
  "lodash": "^4.17.21",
@@ -34,7 +35,7 @@
34
35
  "semantic-release": "^19.0.5",
35
36
  "ts-jest": "^29.0.1",
36
37
  "tslint": "^5.18.0",
37
- "typescript": "^3.9.2"
38
+ "typescript": "^4.9.4"
38
39
  },
39
40
  "scripts": {
40
41
  "clean": "rimraf dist typings coverage .tokens .ledger .checkpoint",