contentful-import 8.2.24 → 8.2.25
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.
- package/dist/index.js +49 -75
- package/dist/parseOptions.js +27 -20
- package/dist/tasks/get-destination-data.js +116 -122
- package/dist/tasks/init-client.js +12 -6
- package/dist/tasks/push-to-space/assets.js +55 -65
- package/dist/tasks/push-to-space/creation.js +154 -157
- package/dist/tasks/push-to-space/publishing.js +100 -128
- package/dist/tasks/push-to-space/push-to-space.js +242 -399
- package/dist/transform/transform-space.js +9 -10
- package/dist/transform/transformers.js +12 -7
- package/dist/usageParams.js +6 -4
- package/dist/utils/headers.js +9 -9
- package/dist/utils/schema.js +26 -21
- package/dist/utils/sort-entries.js +13 -14
- package/dist/utils/sort-locales.js +2 -4
- package/dist/utils/validations.js +11 -8
- package/package.json +8 -8
|
@@ -1,81 +1,71 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
|
9
|
-
|
|
10
|
-
let getAssetStreamForURL = exports.getAssetStreamForURL = (() => {
|
|
11
|
-
var _ref = _asyncToGenerator(function* (url, assetsDirectory) {
|
|
12
|
-
var _url$split = url.split('//'),
|
|
13
|
-
_url$split2 = _slicedToArray(_url$split, 2);
|
|
14
|
-
|
|
15
|
-
const assetPath = _url$split2[1];
|
|
16
|
-
|
|
17
|
-
const filePath = (0, _path.join)(assetsDirectory, assetPath);
|
|
18
|
-
try {
|
|
19
|
-
yield stat(filePath);
|
|
20
|
-
return _fs2.default.createReadStream(filePath);
|
|
21
|
-
} catch (err) {
|
|
22
|
-
const error = new Error('Cannot open asset from filesystem');
|
|
23
|
-
error.filePath = filePath;
|
|
24
|
-
throw error;
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
return function getAssetStreamForURL(_x, _x2) {
|
|
29
|
-
return _ref.apply(this, arguments);
|
|
30
|
-
};
|
|
31
|
-
})();
|
|
32
|
-
|
|
33
|
-
let processAssets = exports.processAssets = (() => {
|
|
34
|
-
var _ref2 = _asyncToGenerator(function* ({ assets, timeout, retryLimit, requestQueue }) {
|
|
35
|
-
const pendingProcessingAssets = assets.map(function (asset) {
|
|
36
|
-
return requestQueue.add(_asyncToGenerator(function* () {
|
|
37
|
-
_logging.logEmitter.emit('info', `Processing Asset ${(0, _getEntityName2.default)(asset)}`);
|
|
38
|
-
const processingOptions = Object.assign({}, timeout && { processingCheckWait: timeout }, retryLimit && { processingCheckRetry: retryLimit });
|
|
39
|
-
|
|
40
|
-
try {
|
|
41
|
-
const processedAsset = yield asset.processForAllLocales(processingOptions);
|
|
42
|
-
return processedAsset;
|
|
43
|
-
} catch (err) {
|
|
44
|
-
err.entity = asset;
|
|
45
|
-
_logging.logEmitter.emit('error', err);
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
}));
|
|
49
|
-
});
|
|
6
|
+
exports.getAssetStreamForURL = getAssetStreamForURL;
|
|
7
|
+
exports.processAssets = processAssets;
|
|
50
8
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return potentiallyProcessedAssets.filter(function (asset) {
|
|
54
|
-
return asset;
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
return function processAssets(_x3) {
|
|
59
|
-
return _ref2.apply(this, arguments);
|
|
60
|
-
};
|
|
61
|
-
})();
|
|
62
|
-
|
|
63
|
-
var _fs = require('fs');
|
|
9
|
+
var _fs = require("fs");
|
|
64
10
|
|
|
65
11
|
var _fs2 = _interopRequireDefault(_fs);
|
|
66
12
|
|
|
67
|
-
var _path = require(
|
|
13
|
+
var _path = require("path");
|
|
68
14
|
|
|
69
|
-
var _util = require(
|
|
15
|
+
var _util = require("util");
|
|
70
16
|
|
|
71
|
-
var _getEntityName = require(
|
|
17
|
+
var _getEntityName = require("contentful-batch-libs/dist/get-entity-name");
|
|
72
18
|
|
|
73
19
|
var _getEntityName2 = _interopRequireDefault(_getEntityName);
|
|
74
20
|
|
|
75
|
-
var _logging = require(
|
|
21
|
+
var _logging = require("contentful-batch-libs/dist/logging");
|
|
76
22
|
|
|
77
23
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
78
24
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
25
|
+
const stat = (0, _util.promisify)(_fs2.default.stat);
|
|
26
|
+
|
|
27
|
+
async function getAssetStreamForURL(url, assetsDirectory) {
|
|
28
|
+
const [, assetPath] = url.split('//');
|
|
29
|
+
const filePath = (0, _path.join)(assetsDirectory, assetPath);
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
await stat(filePath);
|
|
33
|
+
return _fs2.default.createReadStream(filePath);
|
|
34
|
+
} catch (err) {
|
|
35
|
+
const error = new Error('Cannot open asset from filesystem');
|
|
36
|
+
error.filePath = filePath;
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function processAssets({
|
|
42
|
+
assets,
|
|
43
|
+
timeout,
|
|
44
|
+
retryLimit,
|
|
45
|
+
requestQueue
|
|
46
|
+
}) {
|
|
47
|
+
const pendingProcessingAssets = assets.map(asset => {
|
|
48
|
+
return requestQueue.add(async () => {
|
|
49
|
+
_logging.logEmitter.emit('info', `Processing Asset ${(0, _getEntityName2.default)(asset)}`);
|
|
50
|
+
|
|
51
|
+
const processingOptions = Object.assign({}, timeout && {
|
|
52
|
+
processingCheckWait: timeout
|
|
53
|
+
}, retryLimit && {
|
|
54
|
+
processingCheckRetry: retryLimit
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
const processedAsset = await asset.processForAllLocales(processingOptions);
|
|
59
|
+
return processedAsset;
|
|
60
|
+
} catch (err) {
|
|
61
|
+
err.entity = asset;
|
|
62
|
+
|
|
63
|
+
_logging.logEmitter.emit('error', err);
|
|
64
|
+
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
const potentiallyProcessedAssets = await Promise.all(pendingProcessingAssets);
|
|
70
|
+
return potentiallyProcessedAssets.filter(asset => asset);
|
|
71
|
+
}
|
|
@@ -1,185 +1,178 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.createEntities = createEntities;
|
|
7
|
+
exports.createLocales = createLocales;
|
|
8
|
+
exports.createEntries = createEntries;
|
|
7
9
|
|
|
8
|
-
var
|
|
10
|
+
var _collection = require("lodash/collection");
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
var _ref = _asyncToGenerator(function* ({ context, entities, destinationEntitiesById, requestQueue }) {
|
|
12
|
-
const pendingCreatedEntities = entities.map(function (entity) {
|
|
13
|
-
const destinationEntity = getDestinationEntityForSourceEntity(destinationEntitiesById, entity.transformed);
|
|
14
|
-
const operation = destinationEntity ? 'update' : 'create';
|
|
12
|
+
var _object = require("lodash/object");
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
try {
|
|
18
|
-
const createdEntity = yield destinationEntity ? updateDestinationWithSourceData(destinationEntity, entity.transformed) : createInDestination(context, entity.transformed);
|
|
14
|
+
var _getEntityName = require("contentful-batch-libs/dist/get-entity-name");
|
|
19
15
|
|
|
20
|
-
|
|
16
|
+
var _getEntityName2 = _interopRequireDefault(_getEntityName);
|
|
21
17
|
|
|
22
|
-
|
|
23
|
-
} catch (err) {
|
|
24
|
-
return handleCreationErrors(entity, err);
|
|
25
|
-
}
|
|
26
|
-
}));
|
|
27
|
-
});
|
|
18
|
+
var _logging = require("contentful-batch-libs/dist/logging");
|
|
28
19
|
|
|
29
|
-
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
30
21
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Creates a list of entities
|
|
24
|
+
* Applies to all entities except Entries, as the CMA API for those is slightly different
|
|
25
|
+
* See handleCreationErrors for details on what errors reject the promise or not.
|
|
26
|
+
*/
|
|
27
|
+
function createEntities({
|
|
28
|
+
context,
|
|
29
|
+
entities,
|
|
30
|
+
destinationEntitiesById,
|
|
31
|
+
requestQueue
|
|
32
|
+
}) {
|
|
33
|
+
return createEntitiesWithConcurrency({
|
|
34
|
+
context,
|
|
35
|
+
entities,
|
|
36
|
+
destinationEntitiesById,
|
|
37
|
+
requestQueue
|
|
35
38
|
});
|
|
39
|
+
} // TODO
|
|
40
|
+
// Locales need to be created in series
|
|
36
41
|
|
|
37
|
-
return function createEntitiesWithConcurrency(_x) {
|
|
38
|
-
return _ref.apply(this, arguments);
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
function createLocales({
|
|
44
|
+
context,
|
|
45
|
+
entities,
|
|
46
|
+
destinationEntitiesById,
|
|
47
|
+
requestQueue
|
|
48
|
+
}) {
|
|
49
|
+
return createEntitiesInSequence({
|
|
50
|
+
context,
|
|
51
|
+
entities,
|
|
52
|
+
destinationEntitiesById,
|
|
53
|
+
requestQueue
|
|
54
|
+
});
|
|
55
|
+
}
|
|
48
56
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const createdEntity = yield requestQueue.add(_asyncToGenerator(function* () {
|
|
60
|
-
const createdOrUpdatedEntity = yield destinationEntity ? updateDestinationWithSourceData(destinationEntity, entity.transformed) : createInDestination(context, entity.transformed);
|
|
61
|
-
return createdOrUpdatedEntity;
|
|
62
|
-
}));
|
|
63
|
-
|
|
64
|
-
creationSuccessNotifier(operation, createdEntity);
|
|
65
|
-
|
|
66
|
-
createdEntities.push(createdEntity);
|
|
67
|
-
} catch (err) {
|
|
68
|
-
const maybeSubstituteEntity = handleCreationErrors(entity, err);
|
|
69
|
-
if (maybeSubstituteEntity) {
|
|
70
|
-
createdEntities.push(maybeSubstituteEntity);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
} catch (err) {
|
|
75
|
-
_didIteratorError = true;
|
|
76
|
-
_iteratorError = err;
|
|
77
|
-
} finally {
|
|
57
|
+
async function createEntitiesWithConcurrency({
|
|
58
|
+
context,
|
|
59
|
+
entities,
|
|
60
|
+
destinationEntitiesById,
|
|
61
|
+
requestQueue
|
|
62
|
+
}) {
|
|
63
|
+
const pendingCreatedEntities = entities.map(entity => {
|
|
64
|
+
const destinationEntity = getDestinationEntityForSourceEntity(destinationEntitiesById, entity.transformed);
|
|
65
|
+
const operation = destinationEntity ? 'update' : 'create';
|
|
66
|
+
return requestQueue.add(async () => {
|
|
78
67
|
try {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
throw _iteratorError;
|
|
85
|
-
}
|
|
68
|
+
const createdEntity = await (destinationEntity ? updateDestinationWithSourceData(destinationEntity, entity.transformed) : createInDestination(context, entity.transformed));
|
|
69
|
+
creationSuccessNotifier(operation, createdEntity);
|
|
70
|
+
return createdEntity;
|
|
71
|
+
} catch (err) {
|
|
72
|
+
return handleCreationErrors(entity, err);
|
|
86
73
|
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return createdEntities;
|
|
74
|
+
});
|
|
90
75
|
});
|
|
76
|
+
const createdEntities = await Promise.all(pendingCreatedEntities); // Filter null values in case of errors
|
|
91
77
|
|
|
92
|
-
return
|
|
93
|
-
|
|
94
|
-
};
|
|
95
|
-
})();
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Creates a list of entries
|
|
99
|
-
*/
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
let createEntries = exports.createEntries = (() => {
|
|
103
|
-
var _ref5 = _asyncToGenerator(function* ({ context, entities, destinationEntitiesById, requestQueue }) {
|
|
104
|
-
const createdEntries = yield Promise.all(entities.map(function (entry) {
|
|
105
|
-
return createEntry({ entry, target: context.target, skipContentModel: context.skipContentModel, destinationEntitiesById, requestQueue });
|
|
106
|
-
}));
|
|
78
|
+
return createdEntities.filter(entity => entity);
|
|
79
|
+
}
|
|
107
80
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
81
|
+
async function createEntitiesInSequence({
|
|
82
|
+
context,
|
|
83
|
+
entities,
|
|
84
|
+
destinationEntitiesById,
|
|
85
|
+
requestQueue
|
|
86
|
+
}) {
|
|
87
|
+
const createdEntities = [];
|
|
112
88
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
})();
|
|
89
|
+
for (const entity of entities) {
|
|
90
|
+
const destinationEntity = getDestinationEntityForSourceEntity(destinationEntitiesById, entity.transformed);
|
|
91
|
+
const operation = destinationEntity ? 'update' : 'create';
|
|
117
92
|
|
|
118
|
-
let createEntry = (() => {
|
|
119
|
-
var _ref6 = _asyncToGenerator(function* ({ entry, target, skipContentModel, destinationEntitiesById, requestQueue }) {
|
|
120
|
-
const contentTypeId = entry.original.sys.contentType.sys.id;
|
|
121
|
-
const destinationEntry = getDestinationEntityForSourceEntity(destinationEntitiesById, entry.transformed);
|
|
122
|
-
const operation = destinationEntry ? 'update' : 'create';
|
|
123
93
|
try {
|
|
124
|
-
|
|
125
|
-
|
|
94
|
+
// Even though we run things in sequence here,
|
|
95
|
+
// we still want to go through the normal rate limiting queue
|
|
96
|
+
const createdEntity = await requestQueue.add(async () => {
|
|
97
|
+
const createdOrUpdatedEntity = await (destinationEntity ? updateDestinationWithSourceData(destinationEntity, entity.transformed) : createInDestination(context, entity.transformed));
|
|
98
|
+
return createdOrUpdatedEntity;
|
|
126
99
|
});
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return createdOrUpdatedEntry;
|
|
100
|
+
creationSuccessNotifier(operation, createdEntity);
|
|
101
|
+
createdEntities.push(createdEntity);
|
|
131
102
|
} catch (err) {
|
|
132
|
-
|
|
133
|
-
* In that case, the field is removed from the entry, and creation is attempted again.
|
|
134
|
-
*/
|
|
135
|
-
if (skipContentModel && err.name === 'UnknownField') {
|
|
136
|
-
const errors = (0, _object.get)(JSON.parse(err.message), 'details.errors');
|
|
137
|
-
entry.transformed.fields = cleanupUnknownFields(entry.transformed.fields, errors);
|
|
138
|
-
return createEntry({ entry, target, skipContentModel, destinationEntitiesById, requestQueue });
|
|
139
|
-
}
|
|
140
|
-
err.entity = entry;
|
|
141
|
-
_logging.logEmitter.emit('error', err);
|
|
103
|
+
const maybeSubstituteEntity = handleCreationErrors(entity, err);
|
|
142
104
|
|
|
143
|
-
|
|
144
|
-
|
|
105
|
+
if (maybeSubstituteEntity) {
|
|
106
|
+
createdEntities.push(maybeSubstituteEntity);
|
|
107
|
+
}
|
|
145
108
|
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return function createEntry(_x4) {
|
|
149
|
-
return _ref6.apply(this, arguments);
|
|
150
|
-
};
|
|
151
|
-
})();
|
|
152
|
-
|
|
153
|
-
exports.createEntities = createEntities;
|
|
154
|
-
exports.createLocales = createLocales;
|
|
155
|
-
|
|
156
|
-
var _collection = require('lodash/collection');
|
|
109
|
+
}
|
|
157
110
|
|
|
158
|
-
|
|
111
|
+
return createdEntities;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Creates a list of entries
|
|
115
|
+
*/
|
|
159
116
|
|
|
160
|
-
var _getEntityName = require('contentful-batch-libs/dist/get-entity-name');
|
|
161
117
|
|
|
162
|
-
|
|
118
|
+
async function createEntries({
|
|
119
|
+
context,
|
|
120
|
+
entities,
|
|
121
|
+
destinationEntitiesById,
|
|
122
|
+
requestQueue
|
|
123
|
+
}) {
|
|
124
|
+
const createdEntries = await Promise.all(entities.map(entry => {
|
|
125
|
+
return createEntry({
|
|
126
|
+
entry,
|
|
127
|
+
target: context.target,
|
|
128
|
+
skipContentModel: context.skipContentModel,
|
|
129
|
+
destinationEntitiesById,
|
|
130
|
+
requestQueue
|
|
131
|
+
});
|
|
132
|
+
}));
|
|
133
|
+
return createdEntries.filter(entry => entry);
|
|
134
|
+
}
|
|
163
135
|
|
|
164
|
-
|
|
136
|
+
async function createEntry({
|
|
137
|
+
entry,
|
|
138
|
+
target,
|
|
139
|
+
skipContentModel,
|
|
140
|
+
destinationEntitiesById,
|
|
141
|
+
requestQueue
|
|
142
|
+
}) {
|
|
143
|
+
const contentTypeId = entry.original.sys.contentType.sys.id;
|
|
144
|
+
const destinationEntry = getDestinationEntityForSourceEntity(destinationEntitiesById, entry.transformed);
|
|
145
|
+
const operation = destinationEntry ? 'update' : 'create';
|
|
146
|
+
|
|
147
|
+
try {
|
|
148
|
+
const createdOrUpdatedEntry = await requestQueue.add(() => {
|
|
149
|
+
return destinationEntry ? updateDestinationWithSourceData(destinationEntry, entry.transformed) : createEntryInDestination(target, contentTypeId, entry.transformed);
|
|
150
|
+
});
|
|
151
|
+
creationSuccessNotifier(operation, createdOrUpdatedEntry);
|
|
152
|
+
return createdOrUpdatedEntry;
|
|
153
|
+
} catch (err) {
|
|
154
|
+
/* If a field doesn't exist, it means it has been removed from the content types
|
|
155
|
+
* In that case, the field is removed from the entry, and creation is attempted again.
|
|
156
|
+
*/
|
|
157
|
+
if (skipContentModel && err.name === 'UnknownField') {
|
|
158
|
+
const errors = (0, _object.get)(JSON.parse(err.message), 'details.errors');
|
|
159
|
+
entry.transformed.fields = cleanupUnknownFields(entry.transformed.fields, errors);
|
|
160
|
+
return createEntry({
|
|
161
|
+
entry,
|
|
162
|
+
target,
|
|
163
|
+
skipContentModel,
|
|
164
|
+
destinationEntitiesById,
|
|
165
|
+
requestQueue
|
|
166
|
+
});
|
|
167
|
+
}
|
|
165
168
|
|
|
166
|
-
|
|
169
|
+
err.entity = entry;
|
|
167
170
|
|
|
168
|
-
|
|
171
|
+
_logging.logEmitter.emit('error', err); // No need to pass this entry down to publishing if it wasn't created
|
|
169
172
|
|
|
170
|
-
/**
|
|
171
|
-
* Creates a list of entities
|
|
172
|
-
* Applies to all entities except Entries, as the CMA API for those is slightly different
|
|
173
|
-
* See handleCreationErrors for details on what errors reject the promise or not.
|
|
174
|
-
*/
|
|
175
|
-
function createEntities({ context, entities, destinationEntitiesById, requestQueue }) {
|
|
176
|
-
return createEntitiesWithConcurrency({ context, entities, destinationEntitiesById, requestQueue });
|
|
177
|
-
}
|
|
178
173
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
function createLocales({ context, entities, destinationEntitiesById, requestQueue }) {
|
|
182
|
-
return createEntitiesInSequence({ context, entities, destinationEntitiesById, requestQueue });
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
183
176
|
}
|
|
184
177
|
|
|
185
178
|
function updateDestinationWithSourceData(destinationEntity, sourceEntity) {
|
|
@@ -189,8 +182,10 @@ function updateDestinationWithSourceData(destinationEntity, sourceEntity) {
|
|
|
189
182
|
}
|
|
190
183
|
|
|
191
184
|
function createInDestination(context, sourceEntity) {
|
|
192
|
-
const
|
|
193
|
-
|
|
185
|
+
const {
|
|
186
|
+
type,
|
|
187
|
+
target
|
|
188
|
+
} = context;
|
|
194
189
|
|
|
195
190
|
if (type === 'Tag') {
|
|
196
191
|
// tags are created with a different signature
|
|
@@ -199,7 +194,6 @@ function createInDestination(context, sourceEntity) {
|
|
|
199
194
|
|
|
200
195
|
const id = (0, _object.get)(sourceEntity, 'sys.id');
|
|
201
196
|
const plainData = getPlainData(sourceEntity);
|
|
202
|
-
|
|
203
197
|
return id ? target[`create${type}WithId`](id, plainData) : target[`create${type}`](plainData);
|
|
204
198
|
}
|
|
205
199
|
|
|
@@ -215,34 +209,35 @@ function createTagInDestination(context, sourceEntity) {
|
|
|
215
209
|
const name = sourceEntity.name;
|
|
216
210
|
return context.target.createTag(id, name, visibility);
|
|
217
211
|
}
|
|
218
|
-
|
|
219
212
|
/**
|
|
220
213
|
* Handles entity creation errors.
|
|
221
214
|
* If the error is a VersionMismatch the error is thrown and a message is returned
|
|
222
215
|
* instructing the user on what this situation probably means.
|
|
223
216
|
*/
|
|
217
|
+
|
|
218
|
+
|
|
224
219
|
function handleCreationErrors(entity, err) {
|
|
225
220
|
// Handle the case where a locale already exists and skip it
|
|
226
221
|
if ((0, _object.get)(err, 'error.sys.id') === 'ValidationFailed') {
|
|
227
222
|
const errors = (0, _object.get)(err, 'error.details.errors');
|
|
223
|
+
|
|
228
224
|
if (errors && errors.length > 0 && errors[0].name === 'taken') {
|
|
229
225
|
return entity;
|
|
230
226
|
}
|
|
231
227
|
}
|
|
228
|
+
|
|
232
229
|
err.entity = entity.original;
|
|
233
|
-
_logging.logEmitter.emit('error', err);
|
|
234
230
|
|
|
235
|
-
// No need to pass this entity down to publishing if it wasn't created
|
|
231
|
+
_logging.logEmitter.emit('error', err); // No need to pass this entity down to publishing if it wasn't created
|
|
232
|
+
|
|
233
|
+
|
|
236
234
|
return null;
|
|
237
235
|
}
|
|
238
236
|
|
|
239
237
|
function cleanupUnknownFields(fields, errors) {
|
|
240
238
|
return (0, _object.omitBy)(fields, (field, fieldId) => {
|
|
241
239
|
return (0, _collection.find)(errors, error => {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const errorFieldId = _error$path[1];
|
|
245
|
-
|
|
240
|
+
const [, errorFieldId] = error.path;
|
|
246
241
|
return error.name === 'unknown' && errorFieldId === fieldId;
|
|
247
242
|
});
|
|
248
243
|
});
|
|
@@ -254,7 +249,9 @@ function getDestinationEntityForSourceEntity(destinationEntitiesById, sourceEnti
|
|
|
254
249
|
|
|
255
250
|
function creationSuccessNotifier(method, createdEntity) {
|
|
256
251
|
const verb = method[0].toUpperCase() + method.substr(1, method.length) + 'd';
|
|
252
|
+
|
|
257
253
|
_logging.logEmitter.emit('info', `${verb} ${createdEntity.sys.type} ${(0, _getEntityName2.default)(createdEntity)}`);
|
|
254
|
+
|
|
258
255
|
return createdEntity;
|
|
259
256
|
}
|
|
260
257
|
|