contentful-import 9.0.21 → 9.2.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.
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1277 -124
- package/dist/index.mjs +1308 -0
- package/package.json +34 -20
- package/dist/parseOptions.js +0 -94
- package/dist/tasks/get-destination-data.js +0 -155
- package/dist/tasks/init-client.js +0 -25
- package/dist/tasks/push-to-space/assets.js +0 -83
- package/dist/tasks/push-to-space/creation.js +0 -227
- package/dist/tasks/push-to-space/publishing.js +0 -100
- package/dist/tasks/push-to-space/push-to-space.js +0 -346
- package/dist/transform/transform-space.js +0 -36
- package/dist/transform/transformers.js +0 -75
- package/dist/usageParams.js +0 -76
- package/dist/utils/headers.js +0 -45
- package/dist/utils/schema.js +0 -96
- package/dist/utils/sort-entries.js +0 -93
- package/dist/utils/sort-locales.js +0 -42
- package/dist/utils/validations.js +0 -57
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = _default;
|
|
7
|
-
var _object = require("lodash/object");
|
|
8
|
-
var defaultTransformers = _interopRequireWildcard(require("./transformers"));
|
|
9
|
-
var _sortEntries = _interopRequireDefault(require("../utils/sort-entries"));
|
|
10
|
-
var _sortLocales = _interopRequireDefault(require("../utils/sort-locales"));
|
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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); }
|
|
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; }
|
|
14
|
-
const spaceEntities = ['contentTypes', 'entries', 'assets', 'locales', 'webhooks', 'tags'];
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Run transformer methods on each item for each kind of entity, in case there
|
|
18
|
-
* is a need to transform data when copying it to the destination space
|
|
19
|
-
*/
|
|
20
|
-
function _default(sourceData, destinationData, customTransformers, entities = spaceEntities) {
|
|
21
|
-
const transformers = (0, _object.defaults)(customTransformers, defaultTransformers);
|
|
22
|
-
const baseSpaceData = (0, _object.omit)(sourceData, ...entities);
|
|
23
|
-
sourceData.locales = (0, _sortLocales.default)(sourceData.locales);
|
|
24
|
-
const tagsEnabled = !!destinationData.tags;
|
|
25
|
-
return entities.reduce((transformedSpaceData, type) => {
|
|
26
|
-
// tags don't contain links to other entities, don't need to be sorted
|
|
27
|
-
const sortedEntities = type === 'tags' ? sourceData[type] : (0, _sortEntries.default)(sourceData[type]);
|
|
28
|
-
const transformedEntities = sortedEntities.map(entity => ({
|
|
29
|
-
original: entity,
|
|
30
|
-
transformed: transformers[type](entity, destinationData[type], tagsEnabled)
|
|
31
|
-
}));
|
|
32
|
-
transformedSpaceData[type] = transformedEntities;
|
|
33
|
-
return transformedSpaceData;
|
|
34
|
-
}, baseSpaceData);
|
|
35
|
-
}
|
|
36
|
-
module.exports = exports.default;
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.assets = assets;
|
|
7
|
-
exports.contentTypes = contentTypes;
|
|
8
|
-
exports.entries = entries;
|
|
9
|
-
exports.locales = locales;
|
|
10
|
-
exports.tags = tags;
|
|
11
|
-
exports.webhooks = webhooks;
|
|
12
|
-
var _object = require("lodash/object");
|
|
13
|
-
var _collection = require("lodash/collection");
|
|
14
|
-
/**
|
|
15
|
-
* Default transformer methods for each kind of entity.
|
|
16
|
-
*
|
|
17
|
-
* In the case of assets it also changes the asset url to the upload property
|
|
18
|
-
* as the whole upload process needs to be followed again.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
function contentTypes(contentType) {
|
|
22
|
-
return contentType;
|
|
23
|
-
}
|
|
24
|
-
function tags(tag) {
|
|
25
|
-
return tag;
|
|
26
|
-
}
|
|
27
|
-
function entries(entry, _, tagsEnabled = false) {
|
|
28
|
-
return removeMetadataTags(entry, tagsEnabled);
|
|
29
|
-
}
|
|
30
|
-
function webhooks(webhook) {
|
|
31
|
-
// Workaround for webhooks with credentials
|
|
32
|
-
if (webhook.httpBasicUsername) {
|
|
33
|
-
delete webhook.httpBasicUsername;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Workaround for webhooks with secret headers
|
|
37
|
-
if (webhook.headers) {
|
|
38
|
-
webhook.headers = webhook.headers.filter(header => !header.secret);
|
|
39
|
-
}
|
|
40
|
-
return webhook;
|
|
41
|
-
}
|
|
42
|
-
function assets(asset, _, tagsEnabled = false) {
|
|
43
|
-
const transformedAsset = (0, _object.omit)(asset, 'sys');
|
|
44
|
-
transformedAsset.sys = (0, _object.pick)(asset.sys, 'id');
|
|
45
|
-
transformedAsset.fields = (0, _object.pick)(asset.fields, 'title', 'description');
|
|
46
|
-
transformedAsset.fields.file = (0, _collection.reduce)(asset.fields.file, (newFile, localizedFile, locale) => {
|
|
47
|
-
newFile[locale] = (0, _object.pick)(localizedFile, 'contentType', 'fileName');
|
|
48
|
-
if (!localizedFile.uploadFrom) {
|
|
49
|
-
const assetUrl = localizedFile.url || localizedFile.upload;
|
|
50
|
-
newFile[locale].upload = `${/^(http|https):\/\//i.test(assetUrl) ? '' : 'https:'}${assetUrl}`;
|
|
51
|
-
} else {
|
|
52
|
-
newFile[locale].uploadFrom = localizedFile.uploadFrom;
|
|
53
|
-
}
|
|
54
|
-
return newFile;
|
|
55
|
-
}, {});
|
|
56
|
-
return removeMetadataTags(transformedAsset, tagsEnabled);
|
|
57
|
-
}
|
|
58
|
-
function locales(locale, destinationLocales) {
|
|
59
|
-
const transformedLocale = (0, _object.pick)(locale, 'code', 'name', 'contentManagementApi', 'contentDeliveryApi', 'fallbackCode', 'optional');
|
|
60
|
-
const destinationLocale = (0, _collection.find)(destinationLocales, {
|
|
61
|
-
code: locale.code
|
|
62
|
-
});
|
|
63
|
-
if (destinationLocale) {
|
|
64
|
-
// This will implicitly remove the locale ID
|
|
65
|
-
// which then causes the create path to not pick `createLocaleWithId` but `createLocale` instead
|
|
66
|
-
transformedLocale.sys = (0, _object.pick)(destinationLocale.sys, 'id');
|
|
67
|
-
}
|
|
68
|
-
return transformedLocale;
|
|
69
|
-
}
|
|
70
|
-
function removeMetadataTags(entity, tagsEnabled = false) {
|
|
71
|
-
if (!tagsEnabled) {
|
|
72
|
-
delete entity.metadata;
|
|
73
|
-
}
|
|
74
|
-
return entity;
|
|
75
|
-
}
|
package/dist/usageParams.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _yargs = _interopRequireDefault(require("yargs"));
|
|
8
|
-
var packageFile = _interopRequireWildcard(require("../package"));
|
|
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); }
|
|
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; }
|
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
-
var _default = _yargs.default.version(packageFile.version || 'Version only available on installed package').usage('Usage: $0 [options]').option('space-id', {
|
|
13
|
-
describe: 'ID of the destination space',
|
|
14
|
-
type: 'string',
|
|
15
|
-
demand: true
|
|
16
|
-
}).option('environment-id', {
|
|
17
|
-
describe: 'ID the environment in the destination space',
|
|
18
|
-
type: 'string',
|
|
19
|
-
default: 'master',
|
|
20
|
-
demand: false
|
|
21
|
-
}).option('management-token', {
|
|
22
|
-
describe: 'Contentful management API token for the destination space',
|
|
23
|
-
type: 'string',
|
|
24
|
-
demand: true
|
|
25
|
-
}).option('content-file', {
|
|
26
|
-
describe: 'JSON file that contains data to be import to your space',
|
|
27
|
-
type: 'string',
|
|
28
|
-
demand: true
|
|
29
|
-
}).option('content-model-only', {
|
|
30
|
-
describe: 'Import only content types',
|
|
31
|
-
type: 'boolean',
|
|
32
|
-
default: false
|
|
33
|
-
}).option('skip-content-model', {
|
|
34
|
-
describe: 'Skip importing content types and locales',
|
|
35
|
-
type: 'boolean',
|
|
36
|
-
default: false
|
|
37
|
-
}).option('skip-locales', {
|
|
38
|
-
describe: 'Skip importing locales',
|
|
39
|
-
type: 'boolean',
|
|
40
|
-
default: false
|
|
41
|
-
}).option('skip-content-publishing', {
|
|
42
|
-
describe: 'Skips content publishing. Creates content but does not publish it',
|
|
43
|
-
type: 'boolean',
|
|
44
|
-
default: false
|
|
45
|
-
}).option('upload-assets', {
|
|
46
|
-
describe: 'Uses local asset files and uploads them instead of pointing to the URLs of previously uploaded assets. Requires assets-directory',
|
|
47
|
-
type: 'boolean',
|
|
48
|
-
default: false
|
|
49
|
-
}).implies('upload-assets', 'assets-directory').option('assets-directory', {
|
|
50
|
-
describe: 'Path to a directory with an asset export made using the downloadAssets option to upload those files instead of pointing to the URLs of previously uploaded assets. Requires upload-assets',
|
|
51
|
-
type: 'string'
|
|
52
|
-
}).implies('assets-directory', 'upload-assets').option('error-log-file', {
|
|
53
|
-
describe: 'Full path to the error log file',
|
|
54
|
-
type: 'string'
|
|
55
|
-
}).option('host', {
|
|
56
|
-
describe: 'Management API host',
|
|
57
|
-
type: 'string',
|
|
58
|
-
default: 'api.contentful.com'
|
|
59
|
-
}).option('proxy', {
|
|
60
|
-
describe: 'Proxy configuration in HTTP auth format: [http|https]://host:port or [http|https]://user:password@host:port',
|
|
61
|
-
type: 'string'
|
|
62
|
-
}).option('raw-proxy', {
|
|
63
|
-
describe: 'Pass proxy config to Axios instead of creating a custom httpsAgent',
|
|
64
|
-
type: 'boolean',
|
|
65
|
-
default: false
|
|
66
|
-
}).option('rate-limit', {
|
|
67
|
-
describe: 'Maximum requests per second used for API requests',
|
|
68
|
-
type: 'number',
|
|
69
|
-
default: 7
|
|
70
|
-
}).option('header', {
|
|
71
|
-
alias: 'H',
|
|
72
|
-
type: 'string',
|
|
73
|
-
describe: 'Pass an additional HTTP Header'
|
|
74
|
-
}).config('config', 'An optional configuration JSON file containing all the options for a single run').argv;
|
|
75
|
-
exports.default = _default;
|
|
76
|
-
module.exports = exports.default;
|
package/dist/utils/headers.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getHeadersConfig = getHeadersConfig;
|
|
7
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
8
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
9
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
10
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
11
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
12
|
-
/**
|
|
13
|
-
* Turn header option into an object. Invalid header values
|
|
14
|
-
* are ignored.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* getHeadersConfig('Accept: Any')
|
|
18
|
-
* // -> {Accept: 'Any'}
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* getHeadersConfig(['Accept: Any', 'X-Version: 1'])
|
|
22
|
-
* // -> {Accept: 'Any', 'X-Version': '1'}
|
|
23
|
-
*
|
|
24
|
-
* @param value {string|string[]}
|
|
25
|
-
*/
|
|
26
|
-
function getHeadersConfig(value) {
|
|
27
|
-
if (!value) {
|
|
28
|
-
return {};
|
|
29
|
-
}
|
|
30
|
-
const values = Array.isArray(value) ? value : [value];
|
|
31
|
-
return values.reduce((headers, value) => {
|
|
32
|
-
value = value.trim();
|
|
33
|
-
const separatorIndex = value.indexOf(':');
|
|
34
|
-
|
|
35
|
-
// Invalid header format
|
|
36
|
-
if (separatorIndex === -1) {
|
|
37
|
-
return headers;
|
|
38
|
-
}
|
|
39
|
-
const headerKey = value.slice(0, separatorIndex).trim();
|
|
40
|
-
const headerValue = value.slice(separatorIndex + 1).trim();
|
|
41
|
-
return _objectSpread(_objectSpread({}, headers), {}, {
|
|
42
|
-
[headerKey]: headerValue
|
|
43
|
-
});
|
|
44
|
-
}, {});
|
|
45
|
-
}
|
package/dist/utils/schema.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.webhookSchema = exports.tagSchema = exports.payloadSchema = exports.localeSchema = exports.entrySchema = exports.editorInterfaceSchema = exports.contentTypeSchema = exports.assetSchema = void 0;
|
|
7
|
-
var _joi = _interopRequireDefault(require("joi"));
|
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
-
const entrySchema = {
|
|
10
|
-
sys: _joi.default.object(),
|
|
11
|
-
fields: _joi.default.object()
|
|
12
|
-
};
|
|
13
|
-
exports.entrySchema = entrySchema;
|
|
14
|
-
const tagSchema = {
|
|
15
|
-
name: _joi.default.string().required(),
|
|
16
|
-
sys: _joi.default.object()
|
|
17
|
-
};
|
|
18
|
-
exports.tagSchema = tagSchema;
|
|
19
|
-
const contentTypeSchema = {
|
|
20
|
-
sys: _joi.default.object(),
|
|
21
|
-
fields: _joi.default.array().required().items(_joi.default.object().keys({
|
|
22
|
-
id: _joi.default.string().required(),
|
|
23
|
-
name: _joi.default.string().required(),
|
|
24
|
-
type: _joi.default.string().required().regex(/^Symbol|Text|Integer|Number|Date|Object|Boolean|Array|Link|Location$/),
|
|
25
|
-
validations: _joi.default.array(),
|
|
26
|
-
disabled: _joi.default.boolean(),
|
|
27
|
-
omitted: _joi.default.boolean(),
|
|
28
|
-
required: _joi.default.boolean(),
|
|
29
|
-
localized: _joi.default.boolean(),
|
|
30
|
-
linkType: _joi.default.string().when('type', {
|
|
31
|
-
is: 'Link',
|
|
32
|
-
then: _joi.default.string().regex(/^Asset|Entry$/),
|
|
33
|
-
otherwise: _joi.default.forbidden()
|
|
34
|
-
})
|
|
35
|
-
}))
|
|
36
|
-
};
|
|
37
|
-
exports.contentTypeSchema = contentTypeSchema;
|
|
38
|
-
const assetSchema = {
|
|
39
|
-
sys: _joi.default.object(),
|
|
40
|
-
fields: _joi.default.object({
|
|
41
|
-
file: _joi.default.object().pattern(/.+/, _joi.default.object({
|
|
42
|
-
url: _joi.default.string().required(),
|
|
43
|
-
details: _joi.default.object({
|
|
44
|
-
size: _joi.default.number(),
|
|
45
|
-
image: _joi.default.object({
|
|
46
|
-
width: _joi.default.number(),
|
|
47
|
-
height: _joi.default.number()
|
|
48
|
-
})
|
|
49
|
-
}),
|
|
50
|
-
fileName: _joi.default.string().required(),
|
|
51
|
-
contentType: _joi.default.string().required()
|
|
52
|
-
}))
|
|
53
|
-
}).required()
|
|
54
|
-
};
|
|
55
|
-
exports.assetSchema = assetSchema;
|
|
56
|
-
const editorInterfaceSchema = {
|
|
57
|
-
sys: _joi.default.object(),
|
|
58
|
-
controls: _joi.default.array().items({
|
|
59
|
-
fieldId: _joi.default.string(),
|
|
60
|
-
widgetId: _joi.default.string()
|
|
61
|
-
})
|
|
62
|
-
};
|
|
63
|
-
exports.editorInterfaceSchema = editorInterfaceSchema;
|
|
64
|
-
const localeSchema = {
|
|
65
|
-
name: _joi.default.string().required(),
|
|
66
|
-
internal_code: _joi.default.string(),
|
|
67
|
-
code: _joi.default.string().required(),
|
|
68
|
-
fallbackCode: _joi.default.string().allow(null),
|
|
69
|
-
default: _joi.default.boolean(),
|
|
70
|
-
contentManagementApi: _joi.default.boolean(),
|
|
71
|
-
contentDeliveryApi: _joi.default.boolean(),
|
|
72
|
-
optional: _joi.default.boolean(),
|
|
73
|
-
sys: _joi.default.object()
|
|
74
|
-
};
|
|
75
|
-
exports.localeSchema = localeSchema;
|
|
76
|
-
const webhookSchema = {
|
|
77
|
-
name: _joi.default.string(),
|
|
78
|
-
url: _joi.default.string().replace(/{[^}{]+?}/g, 'x').regex(/^https?:\/\/[^ /}{][^ }{]*$/i).required(),
|
|
79
|
-
topics: _joi.default.array().required(),
|
|
80
|
-
httpBasicUsername: _joi.default.string().allow('', null)
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @returns normalized validation object. Don't use normalized output as payload
|
|
85
|
-
*/
|
|
86
|
-
exports.webhookSchema = webhookSchema;
|
|
87
|
-
const payloadSchema = _joi.default.object({
|
|
88
|
-
entries: _joi.default.array().items(entrySchema),
|
|
89
|
-
contentTypes: _joi.default.array().items(contentTypeSchema),
|
|
90
|
-
tags: _joi.default.array().items(tagSchema),
|
|
91
|
-
assets: _joi.default.array().items(assetSchema),
|
|
92
|
-
locales: _joi.default.array().items(localeSchema),
|
|
93
|
-
editorInterfaces: _joi.default.array().items(editorInterfaceSchema),
|
|
94
|
-
webhooks: _joi.default.array().items(webhookSchema)
|
|
95
|
-
});
|
|
96
|
-
exports.payloadSchema = payloadSchema;
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = sortEntries;
|
|
7
|
-
var _collection = require("lodash/collection");
|
|
8
|
-
var _o = _interopRequireWildcard(require("lodash/object"));
|
|
9
|
-
var _array = require("lodash/array");
|
|
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); }
|
|
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; }
|
|
12
|
-
/**
|
|
13
|
-
* Given a list of entries, this function reorders them so that entries which
|
|
14
|
-
* are linked from other entries always come first in the order. This ensures
|
|
15
|
-
* that when we publish entries, we are not publishing entries which contain
|
|
16
|
-
* links to other entries which haven't been published yet.
|
|
17
|
-
*/
|
|
18
|
-
function sortEntries(entries) {
|
|
19
|
-
const linkedEntries = getLinkedEntries(entries);
|
|
20
|
-
const mergedLinkedEntries = mergeSort(linkedEntries, a => {
|
|
21
|
-
return hasLinkedIndexesInFront(a);
|
|
22
|
-
});
|
|
23
|
-
return (0, _collection.map)(mergedLinkedEntries, linkInfo => entries[linkInfo.index]);
|
|
24
|
-
function hasLinkedIndexesInFront(item) {
|
|
25
|
-
if (hasLinkedIndexes(item)) {
|
|
26
|
-
return (0, _collection.some)(item.linkIndexes, index => index > item.index) ? 1 : -1;
|
|
27
|
-
}
|
|
28
|
-
return 0;
|
|
29
|
-
}
|
|
30
|
-
function hasLinkedIndexes(item) {
|
|
31
|
-
return item.linkIndexes.length > 0;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function getLinkedEntries(entries) {
|
|
35
|
-
return (0, _collection.map)(entries, function (entry) {
|
|
36
|
-
const entryIndex = entries.indexOf(entry);
|
|
37
|
-
const rawLinks = (0, _collection.map)(entry.fields, field => {
|
|
38
|
-
field = _o.values(field)[0];
|
|
39
|
-
if (isEntryLink(field)) {
|
|
40
|
-
return getFieldEntriesIndex(field, entries);
|
|
41
|
-
} else if (isEntityArray(field) && isEntryLink(field[0])) {
|
|
42
|
-
return (0, _collection.map)(field, item => getFieldEntriesIndex(item, entries));
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
return {
|
|
46
|
-
index: entryIndex,
|
|
47
|
-
linkIndexes: (0, _collection.filter)((0, _array.flatten)(rawLinks), index => index >= 0)
|
|
48
|
-
};
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
function getFieldEntriesIndex(field, entries) {
|
|
52
|
-
const id = _o.get(field, 'sys.id');
|
|
53
|
-
return entries.findIndex(entry => entry.sys.id === id);
|
|
54
|
-
}
|
|
55
|
-
function isEntryLink(item) {
|
|
56
|
-
return _o.get(item, 'sys.type') === 'Entry' || _o.get(item, 'sys.linkType') === 'Entry';
|
|
57
|
-
}
|
|
58
|
-
function isEntityArray(item) {
|
|
59
|
-
return Array.isArray(item) && item.length > 0 && _o.has(item[0], 'sys');
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* From https://github.com/millermedeiros/amd-utils/blob/master/src/array/sort.js
|
|
64
|
-
* MIT Licensed
|
|
65
|
-
* Merge sort (http://en.wikipedia.org/wiki/Merge_sort)
|
|
66
|
-
* @version 0.1.0 (2012/05/23)
|
|
67
|
-
*/
|
|
68
|
-
function mergeSort(arr, compareFn) {
|
|
69
|
-
if (arr.length < 2) return arr;
|
|
70
|
-
if (compareFn == null) compareFn = defaultCompare;
|
|
71
|
-
const mid = ~~(arr.length / 2);
|
|
72
|
-
const left = mergeSort(arr.slice(0, mid), compareFn);
|
|
73
|
-
const right = mergeSort(arr.slice(mid, arr.length), compareFn);
|
|
74
|
-
return merge(left, right, compareFn);
|
|
75
|
-
}
|
|
76
|
-
function defaultCompare(a, b) {
|
|
77
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
|
78
|
-
}
|
|
79
|
-
function merge(left, right, compareFn) {
|
|
80
|
-
const result = [];
|
|
81
|
-
while (left.length && right.length) {
|
|
82
|
-
if (compareFn(left[0], right[0]) <= 0) {
|
|
83
|
-
// if 0 it should preserve same order (stable)
|
|
84
|
-
result.push(left.shift());
|
|
85
|
-
} else {
|
|
86
|
-
result.push(right.shift());
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (left.length) result.push.apply(result, left);
|
|
90
|
-
if (right.length) result.push.apply(result, right);
|
|
91
|
-
return result;
|
|
92
|
-
}
|
|
93
|
-
module.exports = exports.default;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = sortLocales;
|
|
7
|
-
/**
|
|
8
|
-
* Given a list of locales, this utility will sort them by `fallback` order, i.e. the locales without fallbacks first,
|
|
9
|
-
* then the locales having them as fallbacks, and then recursively.
|
|
10
|
-
*/
|
|
11
|
-
function sortLocales(locales) {
|
|
12
|
-
const localeByFallback = {};
|
|
13
|
-
locales.forEach(locale => {
|
|
14
|
-
if (locale.fallbackCode === null) {
|
|
15
|
-
locale.fallbackCode = undefined;
|
|
16
|
-
}
|
|
17
|
-
if (!localeByFallback[locale.fallbackCode]) {
|
|
18
|
-
localeByFallback[locale.fallbackCode] = [];
|
|
19
|
-
}
|
|
20
|
-
localeByFallback[locale.fallbackCode].push(locale);
|
|
21
|
-
});
|
|
22
|
-
return sortByFallbackKey(localeByFallback);
|
|
23
|
-
}
|
|
24
|
-
function sortByFallbackKey(localeByFallback, key) {
|
|
25
|
-
if (!localeByFallback[key]) {
|
|
26
|
-
return [];
|
|
27
|
-
}
|
|
28
|
-
const sortedLocales = localeByFallback[key];
|
|
29
|
-
sortedLocales.forEach(locale => {
|
|
30
|
-
sortByFallbackKey(localeByFallback, locale.code).forEach(x => sortedLocales.push(x));
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
// We have to reset the undefined fallback code to null so that the locales are properly created without fallback and
|
|
34
|
-
// not the default (en-US)
|
|
35
|
-
sortedLocales.forEach(locale => {
|
|
36
|
-
if (!locale.fallbackCode) {
|
|
37
|
-
locale.fallbackCode = null;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
return sortedLocales;
|
|
41
|
-
}
|
|
42
|
-
module.exports = exports.default;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.assertPayload = exports.assertDefaultLocale = void 0;
|
|
7
|
-
var _schema = require("./schema");
|
|
8
|
-
var _getEntityName = _interopRequireDefault(require("contentful-batch-libs/dist/get-entity-name"));
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
const attachEntityName = (details, payload) => {
|
|
11
|
-
details.map(detail => {
|
|
12
|
-
if (detail.path.length >= 2) {
|
|
13
|
-
detail.entity = (0, _getEntityName.default)(payload[detail.path[0]][detail.path[1]]);
|
|
14
|
-
}
|
|
15
|
-
return detail;
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
const countInvalidEntities = validationData => {
|
|
19
|
-
const entityCount = validationData.reduce((entities, currentDetail) => {
|
|
20
|
-
if (!entities[currentDetail.path[0]]) {
|
|
21
|
-
entities[currentDetail.path[0]] = 1;
|
|
22
|
-
} else {
|
|
23
|
-
entities[currentDetail.path[0]]++;
|
|
24
|
-
}
|
|
25
|
-
return entities;
|
|
26
|
-
}, {});
|
|
27
|
-
return Object.keys(entityCount).map(key => `${key}:${entityCount[key]}`);
|
|
28
|
-
};
|
|
29
|
-
const assertPayload = payload => {
|
|
30
|
-
const result = _schema.payloadSchema.validate(payload, {
|
|
31
|
-
allowUnknown: true,
|
|
32
|
-
abortEarly: false
|
|
33
|
-
});
|
|
34
|
-
if (result.error) {
|
|
35
|
-
attachEntityName(result.error.details, payload);
|
|
36
|
-
const invalidEntityCount = countInvalidEntities(result.error.details).join(', ');
|
|
37
|
-
result.error.message = `${invalidEntityCount} - Get further details in the error log file`;
|
|
38
|
-
delete result.error._object;
|
|
39
|
-
throw result.error;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
exports.assertPayload = assertPayload;
|
|
43
|
-
const assertDefaultLocale = (source, destination) => {
|
|
44
|
-
const sourceDefaultLocale = source.locales.find(locale => locale.default === true);
|
|
45
|
-
const destinationDefaultLocale = destination.locales.find(locale => locale.default === true);
|
|
46
|
-
if (!sourceDefaultLocale || !destinationDefaultLocale) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
if (sourceDefaultLocale.code !== destinationDefaultLocale.code) {
|
|
50
|
-
throw new Error(`
|
|
51
|
-
Please make sure the destination space have the same default locale as the source\n
|
|
52
|
-
Default locale for source space : ${sourceDefaultLocale.code}\n
|
|
53
|
-
Default locale for destination space: ${destinationDefaultLocale.code}\n
|
|
54
|
-
`);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
exports.assertDefaultLocale = assertDefaultLocale;
|