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