contentful-import 8.5.1 → 8.5.3

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,13 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.archiveEntities = archiveEntities;
7
7
  exports.publishEntities = publishEntities;
8
-
9
8
  var _getEntityName = _interopRequireDefault(require("contentful-batch-libs/dist/get-entity-name"));
10
-
11
9
  var _logging = require("contentful-batch-libs/dist/logging");
12
-
13
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
-
15
11
  /**
16
12
  * Publish a list of entities.
17
13
  * Does not return a rejected promise in the case of an error, pushing it
@@ -24,31 +20,21 @@ async function publishEntities({
24
20
  const entitiesToPublish = entities.filter(entity => {
25
21
  if (!entity || !entity.publish) {
26
22
  _logging.logEmitter.emit('warning', `Unable to publish ${(0, _getEntityName.default)(entity)}`);
27
-
28
23
  return false;
29
24
  }
30
-
31
25
  return true;
32
26
  });
33
-
34
27
  if (entitiesToPublish.length === 0) {
35
28
  _logging.logEmitter.emit('info', 'Skipping publishing since zero valid entities passed');
36
-
37
29
  return [];
38
30
  }
39
-
40
31
  const entity = entities[0].original || entities[0];
41
32
  const type = entity.sys.type || 'unknown type';
42
-
43
33
  _logging.logEmitter.emit('info', `Publishing ${entities.length} ${type}s`);
44
-
45
34
  const result = await runQueue(entitiesToPublish, [], requestQueue);
46
-
47
35
  _logging.logEmitter.emit('info', `Successfully published ${result.length} ${type}s`);
48
-
49
36
  return result;
50
37
  }
51
-
52
38
  async function archiveEntities({
53
39
  entities,
54
40
  requestQueue
@@ -56,24 +42,17 @@ async function archiveEntities({
56
42
  const entitiesToArchive = entities.filter(entity => {
57
43
  if (!entity || !entity.archive) {
58
44
  _logging.logEmitter.emit('warning', `Unable to archive ${(0, _getEntityName.default)(entity)}`);
59
-
60
45
  return false;
61
46
  }
62
-
63
47
  return true;
64
48
  });
65
-
66
49
  if (entitiesToArchive.length === 0) {
67
50
  _logging.logEmitter.emit('info', 'Skipping archiving since zero valid entities passed');
68
-
69
51
  return [];
70
52
  }
71
-
72
53
  const entity = entities[0].original || entities[0];
73
54
  const type = entity.sys.type || 'unknown type';
74
-
75
55
  _logging.logEmitter.emit('info', `Archiving ${entities.length} ${type}s`);
76
-
77
56
  const pendingArchivedEntities = entitiesToArchive.map(entity => {
78
57
  return requestQueue.add(async () => {
79
58
  try {
@@ -81,53 +60,41 @@ async function archiveEntities({
81
60
  return archivedEntity;
82
61
  } catch (err) {
83
62
  err.entity = entity;
84
-
85
63
  _logging.logEmitter.emit('error', err);
86
-
87
64
  return null;
88
65
  }
89
66
  });
90
67
  });
91
68
  const allPossiblyArchivedEntities = await Promise.all(pendingArchivedEntities);
92
69
  const allArchivedEntities = allPossiblyArchivedEntities.filter(entity => entity);
93
-
94
70
  _logging.logEmitter.emit('info', `Successfully archived ${allArchivedEntities.length} ${type}s`);
95
-
96
71
  return allArchivedEntities;
97
72
  }
98
-
99
73
  async function runQueue(queue, result = [], requestQueue) {
100
74
  const publishedEntities = [];
101
-
102
75
  for (const entity of queue) {
103
76
  _logging.logEmitter.emit('info', `Publishing ${entity.sys.type} ${(0, _getEntityName.default)(entity)}`);
104
-
105
77
  try {
106
78
  const publishedEntity = await requestQueue.add(() => entity.publish());
107
79
  publishedEntities.push(publishedEntity);
108
80
  } catch (err) {
109
81
  err.entity = entity;
110
-
111
82
  _logging.logEmitter.emit('error', err);
112
83
  }
113
84
  }
114
-
115
85
  result = [...result, ...publishedEntities];
116
86
  const publishedEntityIds = new Set(publishedEntities.map(entity => entity.sys.id));
117
87
  const unpublishedEntities = queue.filter(entity => !publishedEntityIds.has(entity.sys.id));
118
-
119
88
  if (unpublishedEntities.length > 0) {
120
89
  if (queue.length === unpublishedEntities.length) {
121
90
  // Fail when queue could not publish at least one item
122
91
  const unpublishedEntityNames = unpublishedEntities.map(_getEntityName.default).join(', ');
123
-
124
92
  _logging.logEmitter.emit('error', `Could not publish the following entities: ${unpublishedEntityNames}`);
125
93
  } else {
126
94
  // Rerun queue with unpublished entities
127
95
  return runQueue(unpublishedEntities, result, requestQueue);
128
96
  }
129
- } // Return only published entities + last result
130
-
131
-
97
+ }
98
+ // Return only published entities + last result
132
99
  return result;
133
100
  }
@@ -4,33 +4,19 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = pushToSpace;
7
-
8
7
  var _listr = _interopRequireDefault(require("listr"));
9
-
10
8
  var _listrVerboseRenderer = _interopRequireDefault(require("listr-verbose-renderer"));
11
-
12
9
  var _logging = require("contentful-batch-libs/dist/logging");
13
-
14
10
  var _listr2 = require("contentful-batch-libs/dist/listr");
15
-
16
11
  var assets = _interopRequireWildcard(require("./assets"));
17
-
18
12
  var creation = _interopRequireWildcard(require("./creation"));
19
-
20
13
  var publishing = _interopRequireWildcard(require("./publishing"));
21
-
22
14
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
-
24
15
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
-
26
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
-
28
17
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
29
-
30
18
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
31
-
32
19
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
33
-
34
20
  const DEFAULT_CONTENT_STRUCTURE = {
35
21
  entries: [],
36
22
  assets: [],
@@ -40,6 +26,7 @@ const DEFAULT_CONTENT_STRUCTURE = {
40
26
  webhooks: [],
41
27
  editorInterfaces: []
42
28
  };
29
+
43
30
  /**
44
31
  * Pushes all changes to a given space. Handles (un)publishing
45
32
  * as well as delays after creation and before publishing.
@@ -85,17 +72,13 @@ function pushToSpace({
85
72
  renderer: _listrVerboseRenderer.default
86
73
  };
87
74
  const destinationDataById = {};
88
-
89
75
  for (const [entityType, entities] of Object.entries(destinationData)) {
90
76
  const entitiesById = new Map();
91
-
92
77
  for (const entity of entities) {
93
78
  entitiesById.set(entity.sys.id, entity);
94
79
  }
95
-
96
80
  destinationDataById[entityType] = entitiesById;
97
81
  }
98
-
99
82
  return new _listr.default([{
100
83
  title: 'Connecting to space',
101
84
  task: (0, _listr2.wrapTask)(async (ctx, task) => {
@@ -169,16 +152,12 @@ function pushToSpace({
169
152
  const editorInterface = sourceData.editorInterfaces.find(editorInterface => {
170
153
  return editorInterface.sys.contentType.sys.id === contentType.sys.id;
171
154
  });
172
-
173
155
  if (!editorInterface) {
174
156
  return;
175
157
  }
176
-
177
158
  try {
178
159
  const ctEditorInterface = await requestQueue.add(() => ctx.environment.getEditorInterfaceForContentType(contentType.sys.id));
179
-
180
160
  _logging.logEmitter.emit('info', `Fetched editor interface for ${contentType.name}`);
181
-
182
161
  ctEditorInterface.controls = editorInterface.controls;
183
162
  ctEditorInterface.groupControls = editorInterface.groupControls;
184
163
  ctEditorInterface.editorLayout = editorInterface.editorLayout;
@@ -198,13 +177,11 @@ function pushToSpace({
198
177
  title: 'Uploading Assets',
199
178
  task: (0, _listr2.wrapTask)(async (ctx, task) => {
200
179
  const allPendingUploads = [];
201
-
202
180
  for (const asset of sourceData.assets) {
203
181
  for (const file of Object.values(asset.transformed.fields.file)) {
204
182
  allPendingUploads.push(requestQueue.add(async () => {
205
183
  try {
206
184
  _logging.logEmitter.emit('info', `Uploading Asset file ${file.upload}`);
207
-
208
185
  const assetStream = await assets.getAssetStreamForURL(file.upload, assetsDirectory);
209
186
  const upload = await ctx.environment.createUpload({
210
187
  fileName: asset.transformed.sys.id,
@@ -224,10 +201,10 @@ function pushToSpace({
224
201
  }
225
202
  }));
226
203
  }
227
- } // We call the pending uploads for the side effects
228
- // so we can just await all pending ones that are queued
229
-
204
+ }
230
205
 
206
+ // We call the pending uploads for the side effects
207
+ // so we can just await all pending ones that are queued
231
208
  const uploads = await Promise.all(allPendingUploads);
232
209
  ctx.data.uploadedAssetFiles = uploads;
233
210
  }),
@@ -329,7 +306,6 @@ function pushToSpace({
329
306
  skip: ctx => contentModelOnly || environmentId !== 'master' && 'Webhooks can only be imported in master environment'
330
307
  }], listrOptions);
331
308
  }
332
-
333
309
  function archiveEntities({
334
310
  entities,
335
311
  sourceEntities,
@@ -346,7 +322,6 @@ function archiveEntities({
346
322
  requestQueue
347
323
  });
348
324
  }
349
-
350
325
  function publishEntities({
351
326
  entities,
352
327
  sourceEntities,
@@ -357,13 +332,13 @@ function publishEntities({
357
332
  original
358
333
  }) => original.sys.publishedVersion).map(({
359
334
  original
360
- }) => original.sys.id); // Filter imported entities and publish only these who got published in the source
335
+ }) => original.sys.id);
361
336
 
337
+ // Filter imported entities and publish only these who got published in the source
362
338
  const entitiesToPublish = entities.filter(entity => entityIdsToPublish.indexOf(entity.sys.id) !== -1);
363
339
  return publishing.publishEntities({
364
340
  entities: entitiesToPublish,
365
341
  requestQueue
366
342
  });
367
343
  }
368
-
369
344
  module.exports = exports.default;
@@ -4,27 +4,19 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = _default;
7
-
8
7
  var _object = require("lodash/object");
9
-
10
8
  var defaultTransformers = _interopRequireWildcard(require("./transformers"));
11
-
12
9
  var _sortEntries = _interopRequireDefault(require("../utils/sort-entries"));
13
-
14
10
  var _sortLocales = _interopRequireDefault(require("../utils/sort-locales"));
15
-
16
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
12
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
-
20
13
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
-
22
14
  const spaceEntities = ['contentTypes', 'entries', 'assets', 'locales', 'webhooks', 'tags'];
15
+
23
16
  /**
24
17
  * Run transformer methods on each item for each kind of entity, in case there
25
18
  * is a need to transform data when copying it to the destination space
26
19
  */
27
-
28
20
  function _default(sourceData, destinationData, customTransformers, entities = spaceEntities) {
29
21
  const transformers = (0, _object.defaults)(customTransformers, defaultTransformers);
30
22
  const baseSpaceData = (0, _object.omit)(sourceData, ...entities);
@@ -41,5 +33,4 @@ function _default(sourceData, destinationData, customTransformers, entities = sp
41
33
  return transformedSpaceData;
42
34
  }, baseSpaceData);
43
35
  }
44
-
45
36
  module.exports = exports.default;
@@ -9,81 +9,67 @@ exports.entries = entries;
9
9
  exports.locales = locales;
10
10
  exports.tags = tags;
11
11
  exports.webhooks = webhooks;
12
-
13
12
  var _object = require("lodash/object");
14
-
15
13
  var _collection = require("lodash/collection");
16
-
17
14
  /**
18
15
  * Default transformer methods for each kind of entity.
19
16
  *
20
17
  * In the case of assets it also changes the asset url to the upload property
21
18
  * as the whole upload process needs to be followed again.
22
19
  */
20
+
23
21
  function contentTypes(contentType) {
24
22
  return contentType;
25
23
  }
26
-
27
24
  function tags(tag) {
28
25
  return tag;
29
26
  }
30
-
31
27
  function entries(entry, _, tagsEnabled = false) {
32
28
  return removeMetadataTags(entry, tagsEnabled);
33
29
  }
34
-
35
30
  function webhooks(webhook) {
36
31
  // Workaround for webhooks with credentials
37
32
  if (webhook.httpBasicUsername) {
38
33
  delete webhook.httpBasicUsername;
39
- } // Workaround for webhooks with secret headers
40
-
34
+ }
41
35
 
36
+ // Workaround for webhooks with secret headers
42
37
  if (webhook.headers) {
43
38
  webhook.headers = webhook.headers.filter(header => !header.secret);
44
39
  }
45
-
46
40
  return webhook;
47
41
  }
48
-
49
42
  function assets(asset, _, tagsEnabled = false) {
50
43
  const transformedAsset = (0, _object.omit)(asset, 'sys');
51
44
  transformedAsset.sys = (0, _object.pick)(asset.sys, 'id');
52
45
  transformedAsset.fields = (0, _object.pick)(asset.fields, 'title', 'description');
53
46
  transformedAsset.fields.file = (0, _collection.reduce)(asset.fields.file, (newFile, localizedFile, locale) => {
54
47
  newFile[locale] = (0, _object.pick)(localizedFile, 'contentType', 'fileName');
55
-
56
48
  if (!localizedFile.uploadFrom) {
57
49
  const assetUrl = localizedFile.url || localizedFile.upload;
58
50
  newFile[locale].upload = `${/^(http|https):\/\/i/.test(assetUrl) ? '' : 'https:'}${assetUrl}`;
59
51
  } else {
60
52
  newFile[locale].uploadFrom = localizedFile.uploadFrom;
61
53
  }
62
-
63
54
  return newFile;
64
55
  }, {});
65
56
  return removeMetadataTags(transformedAsset, tagsEnabled);
66
57
  }
67
-
68
58
  function locales(locale, destinationLocales) {
69
59
  const transformedLocale = (0, _object.pick)(locale, 'code', 'name', 'contentManagementApi', 'contentDeliveryApi', 'fallbackCode', 'optional');
70
60
  const destinationLocale = (0, _collection.find)(destinationLocales, {
71
61
  code: locale.code
72
62
  });
73
-
74
63
  if (destinationLocale) {
75
64
  // This will implicitly remove the locale ID
76
65
  // which then causes the create path to not pick `createLocaleWithId` but `createLocale` instead
77
66
  transformedLocale.sys = (0, _object.pick)(destinationLocale.sys, 'id');
78
67
  }
79
-
80
68
  return transformedLocale;
81
69
  }
82
-
83
70
  function removeMetadataTags(entity, tagsEnabled = false) {
84
71
  if (!tagsEnabled) {
85
72
  delete entity.metadata;
86
73
  }
87
-
88
74
  return entity;
89
75
  }
@@ -4,17 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _yargs = _interopRequireDefault(require("yargs"));
9
-
10
8
  var packageFile = _interopRequireWildcard(require("../package"));
11
-
12
9
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
-
14
10
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
-
16
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
12
  var _default = _yargs.default.version(packageFile.version || 'Version only available on installed package').usage('Usage: $0 [options]').option('space-id', {
19
13
  describe: 'ID of the destination space',
20
14
  type: 'string',
@@ -78,6 +72,5 @@ var _default = _yargs.default.version(packageFile.version || 'Version only avail
78
72
  type: 'string',
79
73
  describe: 'Pass an additional HTTP Header'
80
74
  }).config('config', 'An optional configuration JSON file containing all the options for a single run').argv;
81
-
82
75
  exports.default = _default;
83
76
  module.exports = exports.default;
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getHeadersConfig = getHeadersConfig;
7
-
8
7
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
9
-
10
8
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
11
-
12
9
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
-
14
10
  /**
15
11
  * Turn header option into an object. Invalid header values
16
12
  * are ignored.
@@ -29,16 +25,15 @@ function getHeadersConfig(value) {
29
25
  if (!value) {
30
26
  return {};
31
27
  }
32
-
33
28
  const values = Array.isArray(value) ? value : [value];
34
29
  return values.reduce((headers, value) => {
35
30
  value = value.trim();
36
- const separatorIndex = value.indexOf(':'); // Invalid header format
31
+ const separatorIndex = value.indexOf(':');
37
32
 
33
+ // Invalid header format
38
34
  if (separatorIndex === -1) {
39
35
  return headers;
40
36
  }
41
-
42
37
  const headerKey = value.slice(0, separatorIndex).trim();
43
38
  const headerValue = value.slice(separatorIndex + 1).trim();
44
39
  return _objectSpread(_objectSpread({}, headers), {}, {
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.webhookSchema = exports.tagSchema = exports.payloadSchema = exports.localeSchema = exports.entrySchema = exports.editorInterfaceSchema = exports.contentTypeSchema = exports.assetSchema = void 0;
7
-
8
7
  var _joi = _interopRequireDefault(require("joi"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
9
  const entrySchema = {
13
10
  sys: _joi.default.object(),
14
11
  fields: _joi.default.object()
@@ -82,12 +79,11 @@ const webhookSchema = {
82
79
  topics: _joi.default.array().required(),
83
80
  httpBasicUsername: _joi.default.string().allow('', null)
84
81
  };
82
+
85
83
  /**
86
84
  * @returns normalized validation object. Don't use normalized output as payload
87
85
  */
88
-
89
86
  exports.webhookSchema = webhookSchema;
90
-
91
87
  const payloadSchema = _joi.default.object({
92
88
  entries: _joi.default.array().items(entrySchema),
93
89
  contentTypes: _joi.default.array().items(contentTypeSchema),
@@ -97,5 +93,4 @@ const payloadSchema = _joi.default.object({
97
93
  editorInterfaces: _joi.default.array().items(editorInterfaceSchema),
98
94
  webhooks: _joi.default.array().items(webhookSchema)
99
95
  });
100
-
101
96
  exports.payloadSchema = payloadSchema;
@@ -4,17 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = sortEntries;
7
-
8
7
  var _collection = require("lodash/collection");
9
-
10
8
  var _o = _interopRequireWildcard(require("lodash/object"));
11
-
12
9
  var _array = require("lodash/array");
13
-
14
10
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
-
16
11
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
-
18
12
  /**
19
13
  * Given a list of entries, this function reorders them so that entries which
20
14
  * are linked from other entries always come first in the order. This ensures
@@ -27,26 +21,21 @@ function sortEntries(entries) {
27
21
  return hasLinkedIndexesInFront(a);
28
22
  });
29
23
  return (0, _collection.map)(mergedLinkedEntries, linkInfo => entries[linkInfo.index]);
30
-
31
24
  function hasLinkedIndexesInFront(item) {
32
25
  if (hasLinkedIndexes(item)) {
33
26
  return (0, _collection.some)(item.linkIndexes, index => index > item.index) ? 1 : -1;
34
27
  }
35
-
36
28
  return 0;
37
29
  }
38
-
39
30
  function hasLinkedIndexes(item) {
40
31
  return item.linkIndexes.length > 0;
41
32
  }
42
33
  }
43
-
44
34
  function getLinkedEntries(entries) {
45
35
  return (0, _collection.map)(entries, function (entry) {
46
36
  const entryIndex = entries.indexOf(entry);
47
37
  const rawLinks = (0, _collection.map)(entry.fields, field => {
48
38
  field = _o.values(field)[0];
49
-
50
39
  if (isEntryLink(field)) {
51
40
  return getFieldEntriesIndex(field, entries);
52
41
  } else if (isEntityArray(field) && isEntryLink(field[0])) {
@@ -59,28 +48,23 @@ function getLinkedEntries(entries) {
59
48
  };
60
49
  });
61
50
  }
62
-
63
51
  function getFieldEntriesIndex(field, entries) {
64
52
  const id = _o.get(field, 'sys.id');
65
-
66
53
  return entries.findIndex(entry => entry.sys.id === id);
67
54
  }
68
-
69
55
  function isEntryLink(item) {
70
56
  return _o.get(item, 'sys.type') === 'Entry' || _o.get(item, 'sys.linkType') === 'Entry';
71
57
  }
72
-
73
58
  function isEntityArray(item) {
74
59
  return Array.isArray(item) && item.length > 0 && _o.has(item[0], 'sys');
75
60
  }
61
+
76
62
  /**
77
63
  * From https://github.com/millermedeiros/amd-utils/blob/master/src/array/sort.js
78
64
  * MIT Licensed
79
65
  * Merge sort (http://en.wikipedia.org/wiki/Merge_sort)
80
66
  * @version 0.1.0 (2012/05/23)
81
67
  */
82
-
83
-
84
68
  function mergeSort(arr, compareFn) {
85
69
  if (arr.length < 2) return arr;
86
70
  if (compareFn == null) compareFn = defaultCompare;
@@ -89,14 +73,11 @@ function mergeSort(arr, compareFn) {
89
73
  const right = mergeSort(arr.slice(mid, arr.length), compareFn);
90
74
  return merge(left, right, compareFn);
91
75
  }
92
-
93
76
  function defaultCompare(a, b) {
94
77
  return a < b ? -1 : a > b ? 1 : 0;
95
78
  }
96
-
97
79
  function merge(left, right, compareFn) {
98
80
  const result = [];
99
-
100
81
  while (left.length && right.length) {
101
82
  if (compareFn(left[0], right[0]) <= 0) {
102
83
  // if 0 it should preserve same order (stable)
@@ -105,10 +86,8 @@ function merge(left, right, compareFn) {
105
86
  result.push(right.shift());
106
87
  }
107
88
  }
108
-
109
89
  if (left.length) result.push.apply(result, left);
110
90
  if (right.length) result.push.apply(result, right);
111
91
  return result;
112
92
  }
113
-
114
93
  module.exports = exports.default;
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = sortLocales;
7
-
8
7
  /**
9
8
  * Given a list of locales, this utility will sort them by `fallback` order, i.e. the locales without fallbacks first,
10
9
  * then the locales having them as fallbacks, and then recursively.
@@ -15,26 +14,21 @@ function sortLocales(locales) {
15
14
  if (locale.fallbackCode === null) {
16
15
  locale.fallbackCode = undefined;
17
16
  }
18
-
19
17
  if (!localeByFallback[locale.fallbackCode]) {
20
18
  localeByFallback[locale.fallbackCode] = [];
21
19
  }
22
-
23
20
  localeByFallback[locale.fallbackCode].push(locale);
24
21
  });
25
22
  return sortByFallbackKey(localeByFallback);
26
23
  }
27
-
28
24
  function sortByFallbackKey(localeByFallback, key) {
29
25
  if (!localeByFallback[key]) {
30
26
  return [];
31
27
  }
32
-
33
28
  const sortedLocales = localeByFallback[key];
34
29
  sortedLocales.forEach(locale => {
35
30
  sortByFallbackKey(localeByFallback, locale.code).forEach(x => sortedLocales.push(x));
36
31
  });
37
32
  return sortedLocales;
38
33
  }
39
-
40
34
  module.exports = exports.default;
@@ -4,23 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.assertPayload = exports.assertDefaultLocale = void 0;
7
-
8
7
  var _schema = require("./schema");
9
-
10
8
  var _getEntityName = _interopRequireDefault(require("contentful-batch-libs/dist/get-entity-name"));
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
10
  const attachEntityName = (details, payload) => {
15
11
  details.map(detail => {
16
12
  if (detail.path.length >= 2) {
17
13
  detail.entity = (0, _getEntityName.default)(payload[detail.path[0]][detail.path[1]]);
18
14
  }
19
-
20
15
  return detail;
21
16
  });
22
17
  };
23
-
24
18
  const countInvalidEntities = validationData => {
25
19
  const entityCount = validationData.reduce((entities, currentDetail) => {
26
20
  if (!entities[currentDetail.path[0]]) {
@@ -28,18 +22,15 @@ const countInvalidEntities = validationData => {
28
22
  } else {
29
23
  entities[currentDetail.path[0]]++;
30
24
  }
31
-
32
25
  return entities;
33
26
  }, {});
34
27
  return Object.keys(entityCount).map(key => `${key}:${entityCount[key]}`);
35
28
  };
36
-
37
29
  const assertPayload = payload => {
38
30
  const result = _schema.payloadSchema.validate(payload, {
39
31
  allowUnknown: true,
40
32
  abortEarly: false
41
33
  });
42
-
43
34
  if (result.error) {
44
35
  attachEntityName(result.error.details, payload);
45
36
  const invalidEntityCount = countInvalidEntities(result.error.details).join(', ');
@@ -48,17 +39,13 @@ const assertPayload = payload => {
48
39
  throw result.error;
49
40
  }
50
41
  };
51
-
52
42
  exports.assertPayload = assertPayload;
53
-
54
43
  const assertDefaultLocale = (source, destination) => {
55
44
  const sourceDefaultLocale = source.locales.find(locale => locale.default === true);
56
45
  const destinationDefaultLocale = destination.locales.find(locale => locale.default === true);
57
-
58
46
  if (!sourceDefaultLocale || !destinationDefaultLocale) {
59
47
  return;
60
48
  }
61
-
62
49
  if (sourceDefaultLocale.code !== destinationDefaultLocale.code) {
63
50
  throw new Error(`
64
51
  Please make sure the destination space have the same default locale as the source\n
@@ -67,5 +54,4 @@ const assertDefaultLocale = (source, destination) => {
67
54
  `);
68
55
  }
69
56
  };
70
-
71
57
  exports.assertDefaultLocale = assertDefaultLocale;