contentful-import 8.2.24 → 8.2.28
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 +11 -11
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
@@ -7,14 +7,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = function (sourceData, destinationData, customTransformers, entities = spaceEntities) {
|
|
8
8
|
const transformers = (0, _object.defaults)(customTransformers, defaultTransformers);
|
|
9
9
|
const baseSpaceData = (0, _object.omit)(sourceData, ...entities);
|
|
10
|
-
|
|
11
10
|
sourceData.locales = (0, _sortLocales2.default)(sourceData.locales);
|
|
12
11
|
const tagsEnabled = !!destinationData.tags;
|
|
13
|
-
|
|
14
12
|
return entities.reduce((transformedSpaceData, type) => {
|
|
15
13
|
// tags don't contain links to other entities, don't need to be sorted
|
|
16
14
|
const sortedEntities = type === 'tags' ? sourceData[type] : (0, _sortEntries2.default)(sourceData[type]);
|
|
17
|
-
|
|
18
15
|
const transformedEntities = sortedEntities.map(entity => ({
|
|
19
16
|
original: entity,
|
|
20
17
|
transformed: transformers[type](entity, destinationData[type], tagsEnabled)
|
|
@@ -24,28 +21,30 @@ exports.default = function (sourceData, destinationData, customTransformers, ent
|
|
|
24
21
|
}, baseSpaceData);
|
|
25
22
|
};
|
|
26
23
|
|
|
27
|
-
var _object = require(
|
|
24
|
+
var _object = require("lodash/object");
|
|
28
25
|
|
|
29
|
-
var _transformers = require(
|
|
26
|
+
var _transformers = require("./transformers");
|
|
30
27
|
|
|
31
28
|
var defaultTransformers = _interopRequireWildcard(_transformers);
|
|
32
29
|
|
|
33
|
-
var _sortEntries = require(
|
|
30
|
+
var _sortEntries = require("../utils/sort-entries");
|
|
34
31
|
|
|
35
32
|
var _sortEntries2 = _interopRequireDefault(_sortEntries);
|
|
36
33
|
|
|
37
|
-
var _sortLocales = require(
|
|
34
|
+
var _sortLocales = require("../utils/sort-locales");
|
|
38
35
|
|
|
39
36
|
var _sortLocales2 = _interopRequireDefault(_sortLocales);
|
|
40
37
|
|
|
41
38
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
42
39
|
|
|
43
|
-
function
|
|
40
|
+
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); }
|
|
44
41
|
|
|
45
|
-
|
|
42
|
+
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; }
|
|
46
43
|
|
|
44
|
+
const spaceEntities = ['contentTypes', 'entries', 'assets', 'locales', 'webhooks', 'tags'];
|
|
47
45
|
/**
|
|
48
46
|
* Run transformer methods on each item for each kind of entity, in case there
|
|
49
47
|
* is a need to transform data when copying it to the destination space
|
|
50
48
|
*/
|
|
49
|
+
|
|
51
50
|
module.exports = exports.default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
@@ -10,9 +10,9 @@ exports.webhooks = webhooks;
|
|
|
10
10
|
exports.assets = assets;
|
|
11
11
|
exports.locales = locales;
|
|
12
12
|
|
|
13
|
-
var _object = require(
|
|
13
|
+
var _object = require("lodash/object");
|
|
14
14
|
|
|
15
|
-
var _collection = require(
|
|
15
|
+
var _collection = require("lodash/collection");
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Default transformer methods for each kind of entity.
|
|
@@ -20,7 +20,6 @@ var _collection = require('lodash/collection');
|
|
|
20
20
|
* In the case of assets it also changes the asset url to the upload property
|
|
21
21
|
* as the whole upload process needs to be followed again.
|
|
22
22
|
*/
|
|
23
|
-
|
|
24
23
|
function contentTypes(contentType) {
|
|
25
24
|
return contentType;
|
|
26
25
|
}
|
|
@@ -37,9 +36,9 @@ function webhooks(webhook) {
|
|
|
37
36
|
// Workaround for webhooks with credentials
|
|
38
37
|
if (webhook.httpBasicUsername) {
|
|
39
38
|
delete webhook.httpBasicUsername;
|
|
40
|
-
}
|
|
39
|
+
} // Workaround for webhooks with secret headers
|
|
40
|
+
|
|
41
41
|
|
|
42
|
-
// Workaround for webhooks with secret headers
|
|
43
42
|
if (webhook.headers) {
|
|
44
43
|
webhook.headers = webhook.headers.filter(header => !header.secret);
|
|
45
44
|
}
|
|
@@ -53,12 +52,14 @@ function assets(asset, _, tagsEnabled = false) {
|
|
|
53
52
|
transformedAsset.fields = (0, _object.pick)(asset.fields, 'title', 'description');
|
|
54
53
|
transformedAsset.fields.file = (0, _collection.reduce)(asset.fields.file, (newFile, localizedFile, locale) => {
|
|
55
54
|
newFile[locale] = (0, _object.pick)(localizedFile, 'contentType', 'fileName');
|
|
55
|
+
|
|
56
56
|
if (!localizedFile.uploadFrom) {
|
|
57
57
|
const assetUrl = localizedFile.url || localizedFile.upload;
|
|
58
58
|
newFile[locale].upload = `${/^(http|https):\/\/i/.test(assetUrl) ? '' : 'https:'}${assetUrl}`;
|
|
59
59
|
} else {
|
|
60
60
|
newFile[locale].uploadFrom = localizedFile.uploadFrom;
|
|
61
61
|
}
|
|
62
|
+
|
|
62
63
|
return newFile;
|
|
63
64
|
}, {});
|
|
64
65
|
return removeMetadataTags(transformedAsset, tagsEnabled);
|
|
@@ -66,7 +67,10 @@ function assets(asset, _, tagsEnabled = false) {
|
|
|
66
67
|
|
|
67
68
|
function locales(locale, destinationLocales) {
|
|
68
69
|
const transformedLocale = (0, _object.pick)(locale, 'code', 'name', 'contentManagementApi', 'contentDeliveryApi', 'fallbackCode', 'optional');
|
|
69
|
-
const destinationLocale = (0, _collection.find)(destinationLocales, {
|
|
70
|
+
const destinationLocale = (0, _collection.find)(destinationLocales, {
|
|
71
|
+
code: locale.code
|
|
72
|
+
});
|
|
73
|
+
|
|
70
74
|
if (destinationLocale) {
|
|
71
75
|
// This will implicitly remove the locale ID
|
|
72
76
|
// which then causes the create path to not pick `createLocaleWithId` but `createLocale` instead
|
|
@@ -80,5 +84,6 @@ function removeMetadataTags(entity, tagsEnabled = false) {
|
|
|
80
84
|
if (!tagsEnabled) {
|
|
81
85
|
delete entity.metadata;
|
|
82
86
|
}
|
|
87
|
+
|
|
83
88
|
return entity;
|
|
84
89
|
}
|
package/dist/usageParams.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
|
|
7
|
-
var _yargs = require(
|
|
7
|
+
var _yargs = require("yargs");
|
|
8
8
|
|
|
9
9
|
var _yargs2 = _interopRequireDefault(_yargs);
|
|
10
10
|
|
|
11
|
-
var _package = require(
|
|
11
|
+
var _package = require("../package");
|
|
12
12
|
|
|
13
13
|
var packageFile = _interopRequireWildcard(_package);
|
|
14
14
|
|
|
15
|
-
function
|
|
15
|
+
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); }
|
|
16
|
+
|
|
17
|
+
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; }
|
|
16
18
|
|
|
17
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
20
|
|
package/dist/utils/headers.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.getHeadersConfig = getHeadersConfig;
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
9
|
+
|
|
10
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
11
|
+
|
|
12
|
+
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; }
|
|
8
13
|
|
|
9
|
-
exports.getHeadersConfig = getHeadersConfig;
|
|
10
14
|
/**
|
|
11
15
|
* Turn header option into an object. Invalid header values
|
|
12
16
|
* are ignored.
|
|
@@ -27,21 +31,17 @@ function getHeadersConfig(value) {
|
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
const values = Array.isArray(value) ? value : [value];
|
|
30
|
-
|
|
31
34
|
return values.reduce((headers, value) => {
|
|
32
35
|
value = value.trim();
|
|
36
|
+
const separatorIndex = value.indexOf(':'); // Invalid header format
|
|
33
37
|
|
|
34
|
-
const separatorIndex = value.indexOf(':');
|
|
35
|
-
|
|
36
|
-
// Invalid header format
|
|
37
38
|
if (separatorIndex === -1) {
|
|
38
39
|
return headers;
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
const headerKey = value.slice(0, separatorIndex).trim();
|
|
42
43
|
const headerValue = value.slice(separatorIndex + 1).trim();
|
|
43
|
-
|
|
44
|
-
return _extends({}, headers, {
|
|
44
|
+
return _objectSpread(_objectSpread({}, headers), {}, {
|
|
45
45
|
[headerKey]: headerValue
|
|
46
46
|
});
|
|
47
47
|
}, {});
|
package/dist/utils/schema.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.payloadSchema = exports.assetSchema = exports.editorInterfaceSchema = exports.webhookSchema = exports.localeSchema = exports.tagSchema = exports.contentTypeSchema = exports.entrySchema = undefined;
|
|
7
7
|
|
|
8
|
-
var _joi = require(
|
|
8
|
+
var _joi = require("joi");
|
|
9
9
|
|
|
10
10
|
var _joi2 = _interopRequireDefault(_joi);
|
|
11
11
|
|
|
@@ -15,12 +15,10 @@ const entrySchema = {
|
|
|
15
15
|
sys: _joi2.default.object(),
|
|
16
16
|
fields: _joi2.default.object()
|
|
17
17
|
};
|
|
18
|
-
|
|
19
18
|
const tagSchema = {
|
|
20
19
|
name: _joi2.default.string().required(),
|
|
21
20
|
sys: _joi2.default.object()
|
|
22
21
|
};
|
|
23
|
-
|
|
24
22
|
const contentTypeSchema = {
|
|
25
23
|
sys: _joi2.default.object(),
|
|
26
24
|
fields: _joi2.default.array().required().items(_joi2.default.object().keys({
|
|
@@ -32,10 +30,13 @@ const contentTypeSchema = {
|
|
|
32
30
|
omitted: _joi2.default.boolean(),
|
|
33
31
|
required: _joi2.default.boolean(),
|
|
34
32
|
localized: _joi2.default.boolean(),
|
|
35
|
-
linkType: _joi2.default.string().when('type', {
|
|
33
|
+
linkType: _joi2.default.string().when('type', {
|
|
34
|
+
is: 'Link',
|
|
35
|
+
then: _joi2.default.string().regex(/^Asset|Entry$/),
|
|
36
|
+
otherwise: _joi2.default.forbidden()
|
|
37
|
+
})
|
|
36
38
|
}))
|
|
37
39
|
};
|
|
38
|
-
|
|
39
40
|
const assetSchema = {
|
|
40
41
|
sys: _joi2.default.object(),
|
|
41
42
|
fields: _joi2.default.object({
|
|
@@ -55,38 +56,42 @@ const assetSchema = {
|
|
|
55
56
|
};
|
|
56
57
|
const editorInterfaceSchema = {
|
|
57
58
|
sys: _joi2.default.object(),
|
|
58
|
-
controls: _joi2.default.array().items(
|
|
59
|
+
controls: _joi2.default.array().items({
|
|
60
|
+
fieldId: _joi2.default.string(),
|
|
61
|
+
widgetId: _joi2.default.string()
|
|
62
|
+
})
|
|
59
63
|
};
|
|
60
64
|
const localeSchema = {
|
|
61
65
|
name: _joi2.default.string().required(),
|
|
62
66
|
internal_code: _joi2.default.string(),
|
|
63
67
|
code: _joi2.default.string().required(),
|
|
64
|
-
fallbackCode: _joi2.default.string().allow(
|
|
68
|
+
fallbackCode: _joi2.default.string().allow(null),
|
|
65
69
|
default: _joi2.default.boolean(),
|
|
66
70
|
contentManagementApi: _joi2.default.boolean(),
|
|
67
71
|
contentDeliveryApi: _joi2.default.boolean(),
|
|
68
72
|
optional: _joi2.default.boolean(),
|
|
69
73
|
sys: _joi2.default.object()
|
|
70
74
|
};
|
|
71
|
-
|
|
72
75
|
const webhookSchema = {
|
|
73
76
|
name: _joi2.default.string(),
|
|
74
77
|
url: _joi2.default.string().replace(/{[^}{]+?}/g, 'x').regex(/^https?:\/\/[^ /}{][^ }{]*$/i).required(),
|
|
75
78
|
topics: _joi2.default.array().required(),
|
|
76
|
-
httpBasicUsername: _joi2.default.string().allow(
|
|
79
|
+
httpBasicUsername: _joi2.default.string().allow('', null)
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* @returns normalized validation object. Don't use normalized output as payload
|
|
83
|
+
*/
|
|
77
84
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
locales: _joi2.default.array().items([localeSchema]),
|
|
87
|
-
editorInterfaces: _joi2.default.array().items([editorInterfaceSchema]),
|
|
88
|
-
webhooks: _joi2.default.array().items([webhookSchema])
|
|
85
|
+
const payloadSchema = _joi2.default.object({
|
|
86
|
+
entries: _joi2.default.array().items(entrySchema),
|
|
87
|
+
contentTypes: _joi2.default.array().items(contentTypeSchema),
|
|
88
|
+
tags: _joi2.default.array().items(tagSchema),
|
|
89
|
+
assets: _joi2.default.array().items(assetSchema),
|
|
90
|
+
locales: _joi2.default.array().items(localeSchema),
|
|
91
|
+
editorInterfaces: _joi2.default.array().items(editorInterfaceSchema),
|
|
92
|
+
webhooks: _joi2.default.array().items(webhookSchema)
|
|
89
93
|
});
|
|
94
|
+
|
|
90
95
|
exports.entrySchema = entrySchema;
|
|
91
96
|
exports.contentTypeSchema = contentTypeSchema;
|
|
92
97
|
exports.tagSchema = tagSchema;
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = sortEntries;
|
|
7
7
|
|
|
8
|
-
var _collection = require(
|
|
8
|
+
var _collection = require("lodash/collection");
|
|
9
9
|
|
|
10
|
-
var _object = require(
|
|
10
|
+
var _object = require("lodash/object");
|
|
11
11
|
|
|
12
12
|
var _o = _interopRequireWildcard(_object);
|
|
13
13
|
|
|
14
|
-
var _array = require(
|
|
14
|
+
var _array = require("lodash/array");
|
|
15
15
|
|
|
16
|
-
function
|
|
16
|
+
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); }
|
|
17
|
+
|
|
18
|
+
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
19
|
|
|
18
20
|
/**
|
|
19
21
|
* Given a list of entries, this function reorders them so that entries which
|
|
@@ -23,17 +25,16 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
|
23
25
|
*/
|
|
24
26
|
function sortEntries(entries) {
|
|
25
27
|
const linkedEntries = getLinkedEntries(entries);
|
|
26
|
-
|
|
27
28
|
const mergedLinkedEntries = mergeSort(linkedEntries, a => {
|
|
28
29
|
return hasLinkedIndexesInFront(a);
|
|
29
30
|
});
|
|
30
|
-
|
|
31
31
|
return (0, _collection.map)(mergedLinkedEntries, linkInfo => entries[linkInfo.index]);
|
|
32
32
|
|
|
33
33
|
function hasLinkedIndexesInFront(item) {
|
|
34
34
|
if (hasLinkedIndexes(item)) {
|
|
35
35
|
return (0, _collection.some)(item.linkIndexes, index => index > item.index) ? 1 : -1;
|
|
36
36
|
}
|
|
37
|
+
|
|
37
38
|
return 0;
|
|
38
39
|
}
|
|
39
40
|
|
|
@@ -45,16 +46,15 @@ function sortEntries(entries) {
|
|
|
45
46
|
function getLinkedEntries(entries) {
|
|
46
47
|
return (0, _collection.map)(entries, function (entry) {
|
|
47
48
|
const entryIndex = entries.indexOf(entry);
|
|
48
|
-
|
|
49
49
|
const rawLinks = (0, _collection.map)(entry.fields, field => {
|
|
50
50
|
field = _o.values(field)[0];
|
|
51
|
+
|
|
51
52
|
if (isEntryLink(field)) {
|
|
52
53
|
return getFieldEntriesIndex(field, entries);
|
|
53
54
|
} else if (isEntityArray(field) && isEntryLink(field[0])) {
|
|
54
55
|
return (0, _collection.map)(field, item => getFieldEntriesIndex(item, entries));
|
|
55
56
|
}
|
|
56
57
|
});
|
|
57
|
-
|
|
58
58
|
return {
|
|
59
59
|
index: entryIndex,
|
|
60
60
|
linkIndexes: (0, _collection.filter)((0, _array.flatten)(rawLinks), index => index >= 0)
|
|
@@ -64,6 +64,7 @@ function getLinkedEntries(entries) {
|
|
|
64
64
|
|
|
65
65
|
function getFieldEntriesIndex(field, entries) {
|
|
66
66
|
const id = _o.get(field, 'sys.id');
|
|
67
|
+
|
|
67
68
|
return entries.findIndex(entry => entry.sys.id === id);
|
|
68
69
|
}
|
|
69
70
|
|
|
@@ -74,22 +75,20 @@ function isEntryLink(item) {
|
|
|
74
75
|
function isEntityArray(item) {
|
|
75
76
|
return Array.isArray(item) && item.length > 0 && _o.has(item[0], 'sys');
|
|
76
77
|
}
|
|
77
|
-
|
|
78
78
|
/**
|
|
79
79
|
* From https://github.com/millermedeiros/amd-utils/blob/master/src/array/sort.js
|
|
80
80
|
* MIT Licensed
|
|
81
81
|
* Merge sort (http://en.wikipedia.org/wiki/Merge_sort)
|
|
82
82
|
* @version 0.1.0 (2012/05/23)
|
|
83
83
|
*/
|
|
84
|
+
|
|
85
|
+
|
|
84
86
|
function mergeSort(arr, compareFn) {
|
|
85
87
|
if (arr.length < 2) return arr;
|
|
86
|
-
|
|
87
88
|
if (compareFn == null) compareFn = defaultCompare;
|
|
88
|
-
|
|
89
89
|
const mid = ~~(arr.length / 2);
|
|
90
90
|
const left = mergeSort(arr.slice(0, mid), compareFn);
|
|
91
91
|
const right = mergeSort(arr.slice(mid, arr.length), compareFn);
|
|
92
|
-
|
|
93
92
|
return merge(left, right, compareFn);
|
|
94
93
|
}
|
|
95
94
|
|
|
@@ -111,7 +110,7 @@ function merge(left, right, compareFn) {
|
|
|
111
110
|
|
|
112
111
|
if (left.length) result.push.apply(result, left);
|
|
113
112
|
if (right.length) result.push.apply(result, right);
|
|
114
|
-
|
|
115
113
|
return result;
|
|
116
114
|
}
|
|
115
|
+
|
|
117
116
|
module.exports = exports.default;
|
|
@@ -4,13 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = sortLocales;
|
|
7
|
+
|
|
7
8
|
/**
|
|
8
9
|
* Given a list of locales, this utility will sort them by `fallback` order, i.e. the locales without fallbacks first,
|
|
9
10
|
* then the locales having them as fallbacks, and then recursively.
|
|
10
11
|
*/
|
|
11
12
|
function sortLocales(locales) {
|
|
12
13
|
const localeByFallback = {};
|
|
13
|
-
|
|
14
14
|
locales.forEach(locale => {
|
|
15
15
|
if (locale.fallbackCode === null) {
|
|
16
16
|
locale.fallbackCode = undefined;
|
|
@@ -22,7 +22,6 @@ function sortLocales(locales) {
|
|
|
22
22
|
|
|
23
23
|
localeByFallback[locale.fallbackCode].push(locale);
|
|
24
24
|
});
|
|
25
|
-
|
|
26
25
|
return sortByFallbackKey(localeByFallback);
|
|
27
26
|
}
|
|
28
27
|
|
|
@@ -32,11 +31,10 @@ function sortByFallbackKey(localeByFallback, key) {
|
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
const sortedLocales = localeByFallback[key];
|
|
35
|
-
|
|
36
34
|
sortedLocales.forEach(locale => {
|
|
37
35
|
sortByFallbackKey(localeByFallback, locale.code).forEach(x => sortedLocales.push(x));
|
|
38
36
|
});
|
|
39
|
-
|
|
40
37
|
return sortedLocales;
|
|
41
38
|
}
|
|
39
|
+
|
|
42
40
|
module.exports = exports.default;
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.assertDefaultLocale = exports.assertPayload = undefined;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _schema = require("./schema");
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
var _schema = require('./schema');
|
|
13
|
-
|
|
14
|
-
var _getEntityName = require('contentful-batch-libs/dist/get-entity-name');
|
|
10
|
+
var _getEntityName = require("contentful-batch-libs/dist/get-entity-name");
|
|
15
11
|
|
|
16
12
|
var _getEntityName2 = _interopRequireDefault(_getEntityName);
|
|
17
13
|
|
|
@@ -22,9 +18,11 @@ const attachEntityName = (details, payload) => {
|
|
|
22
18
|
if (detail.path.length >= 2) {
|
|
23
19
|
detail.entity = (0, _getEntityName2.default)(payload[detail.path[0]][detail.path[1]]);
|
|
24
20
|
}
|
|
21
|
+
|
|
25
22
|
return detail;
|
|
26
23
|
});
|
|
27
24
|
};
|
|
25
|
+
|
|
28
26
|
const countInvalidEntities = validationData => {
|
|
29
27
|
const entityCount = validationData.reduce((entities, currentDetail) => {
|
|
30
28
|
if (!entities[currentDetail.path[0]]) {
|
|
@@ -32,13 +30,18 @@ const countInvalidEntities = validationData => {
|
|
|
32
30
|
} else {
|
|
33
31
|
entities[currentDetail.path[0]]++;
|
|
34
32
|
}
|
|
33
|
+
|
|
35
34
|
return entities;
|
|
36
35
|
}, {});
|
|
37
36
|
return Object.keys(entityCount).map(key => `${key}:${entityCount[key]}`);
|
|
38
37
|
};
|
|
39
38
|
|
|
40
39
|
const assertPayload = payload => {
|
|
41
|
-
const result =
|
|
40
|
+
const result = _schema.payloadSchema.validate(payload, {
|
|
41
|
+
allowUnknown: true,
|
|
42
|
+
abortEarly: false
|
|
43
|
+
});
|
|
44
|
+
|
|
42
45
|
if (result.error) {
|
|
43
46
|
attachEntityName(result.error.details, payload);
|
|
44
47
|
const invalidEntityCount = countInvalidEntities(result.error.details).join(', ');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "contentful-import",
|
|
3
|
-
"version": "8.2.
|
|
3
|
+
"version": "8.2.28",
|
|
4
4
|
"description": "this tool allows you to import JSON dump exported by contentful-export",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -52,24 +52,24 @@
|
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"bluebird": "^3.5.1",
|
|
54
54
|
"cli-table3": "^0.6.0",
|
|
55
|
-
"contentful-batch-libs": "^9.
|
|
56
|
-
"contentful-management": "^7.
|
|
57
|
-
"joi": "^
|
|
55
|
+
"contentful-batch-libs": "^9.2.1",
|
|
56
|
+
"contentful-management": "^7.45.5",
|
|
57
|
+
"joi": "^17.5.0",
|
|
58
58
|
"listr": "^0.14.1",
|
|
59
59
|
"listr-update-renderer": "^0.5.0",
|
|
60
60
|
"listr-verbose-renderer": "^0.6.0",
|
|
61
61
|
"lodash": "^4.17.10",
|
|
62
62
|
"moment": "^2.22.2",
|
|
63
63
|
"p-queue": "^6.6.2",
|
|
64
|
-
"yargs": "^17.0
|
|
64
|
+
"yargs": "^17.3.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"babel
|
|
68
|
-
"babel
|
|
67
|
+
"@babel/cli": "^7.16.0",
|
|
68
|
+
"@babel/core": "^7.16.0",
|
|
69
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
|
|
69
70
|
"babel-eslint": "^10.1.0",
|
|
70
71
|
"babel-jest": "^27.0.1",
|
|
71
72
|
"babel-plugin-add-module-exports": "^1.0.2",
|
|
72
|
-
"babel-plugin-transform-object-rest-spread": "^6.23.0",
|
|
73
73
|
"babel-preset-env": "^1.7.0",
|
|
74
74
|
"cz-conventional-changelog": "^3.1.0",
|
|
75
75
|
"eslint": "^7.2.0",
|
|
@@ -77,12 +77,12 @@
|
|
|
77
77
|
"eslint-plugin-import": "^2.13.0",
|
|
78
78
|
"eslint-plugin-jest": "^25.0.1",
|
|
79
79
|
"eslint-plugin-node": "^11.1.0",
|
|
80
|
-
"eslint-plugin-promise": "^5.
|
|
80
|
+
"eslint-plugin-promise": "^5.2.0",
|
|
81
81
|
"eslint-plugin-standard": "^5.0.0",
|
|
82
82
|
"husky": "^4.3.8",
|
|
83
|
-
"jest": "^
|
|
83
|
+
"jest": "^27.4.3",
|
|
84
84
|
"rimraf": "^3.0.2",
|
|
85
|
-
"semantic-release": "^
|
|
85
|
+
"semantic-release": "^18.0.0"
|
|
86
86
|
},
|
|
87
87
|
"files": [
|
|
88
88
|
"bin",
|