contentful-import 9.1.0 → 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 +1315 -157
- package/dist/index.mjs +1308 -0
- package/package.json +24 -4
- package/dist/parseOptions.js +0 -97
- package/dist/tasks/get-destination-data.js +0 -122
- package/dist/tasks/init-client.js +0 -19
- package/dist/tasks/push-to-space/assets.js +0 -75
- package/dist/tasks/push-to-space/creation.js +0 -178
- package/dist/tasks/push-to-space/publishing.js +0 -100
- package/dist/tasks/push-to-space/push-to-space.js +0 -329
- package/dist/transform/transform-space.js +0 -56
- package/dist/transform/transformers.js +0 -70
- package/dist/usageParams.js +0 -115
- package/dist/utils/headers.js +0 -38
- package/dist/utils/schema.js +0 -87
- package/dist/utils/sort-entries.js +0 -116
- package/dist/utils/sort-locales.js +0 -37
- package/dist/utils/validations.js +0 -54
package/dist/utils/schema.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.payloadSchema = exports.assetSchema = exports.editorInterfaceSchema = exports.webhookSchema = exports.localeSchema = exports.tagSchema = exports.contentTypeSchema = exports.entrySchema = void 0;
|
|
7
|
-
const joi_1 = __importDefault(require("joi"));
|
|
8
|
-
const entrySchema = {
|
|
9
|
-
sys: joi_1.default.object(),
|
|
10
|
-
fields: joi_1.default.object()
|
|
11
|
-
};
|
|
12
|
-
exports.entrySchema = entrySchema;
|
|
13
|
-
const tagSchema = {
|
|
14
|
-
name: joi_1.default.string().required(),
|
|
15
|
-
sys: joi_1.default.object()
|
|
16
|
-
};
|
|
17
|
-
exports.tagSchema = tagSchema;
|
|
18
|
-
const contentTypeSchema = {
|
|
19
|
-
sys: joi_1.default.object(),
|
|
20
|
-
fields: joi_1.default.array().required().items(joi_1.default.object().keys({
|
|
21
|
-
id: joi_1.default.string().required(),
|
|
22
|
-
name: joi_1.default.string().required(),
|
|
23
|
-
type: joi_1.default.string().required().regex(/^Symbol|Text|Integer|Number|Date|Object|Boolean|Array|Link|Location$/),
|
|
24
|
-
validations: joi_1.default.array(),
|
|
25
|
-
disabled: joi_1.default.boolean(),
|
|
26
|
-
omitted: joi_1.default.boolean(),
|
|
27
|
-
required: joi_1.default.boolean(),
|
|
28
|
-
localized: joi_1.default.boolean(),
|
|
29
|
-
linkType: joi_1.default.string().when('type', { is: 'Link', then: joi_1.default.string().regex(/^Asset|Entry$/), otherwise: joi_1.default.forbidden() })
|
|
30
|
-
}))
|
|
31
|
-
};
|
|
32
|
-
exports.contentTypeSchema = contentTypeSchema;
|
|
33
|
-
const assetSchema = {
|
|
34
|
-
sys: joi_1.default.object(),
|
|
35
|
-
fields: joi_1.default.object({
|
|
36
|
-
file: joi_1.default.object().pattern(/.+/, joi_1.default.object({
|
|
37
|
-
url: joi_1.default.string().required(),
|
|
38
|
-
details: joi_1.default.object({
|
|
39
|
-
size: joi_1.default.number(),
|
|
40
|
-
image: joi_1.default.object({
|
|
41
|
-
width: joi_1.default.number(),
|
|
42
|
-
height: joi_1.default.number()
|
|
43
|
-
})
|
|
44
|
-
}),
|
|
45
|
-
fileName: joi_1.default.string().required(),
|
|
46
|
-
contentType: joi_1.default.string().required()
|
|
47
|
-
}))
|
|
48
|
-
}).required()
|
|
49
|
-
};
|
|
50
|
-
exports.assetSchema = assetSchema;
|
|
51
|
-
const editorInterfaceSchema = {
|
|
52
|
-
sys: joi_1.default.object(),
|
|
53
|
-
controls: joi_1.default.array().items({ fieldId: joi_1.default.string(), widgetId: joi_1.default.string() })
|
|
54
|
-
};
|
|
55
|
-
exports.editorInterfaceSchema = editorInterfaceSchema;
|
|
56
|
-
const localeSchema = {
|
|
57
|
-
name: joi_1.default.string().required(),
|
|
58
|
-
internal_code: joi_1.default.string(),
|
|
59
|
-
code: joi_1.default.string().required(),
|
|
60
|
-
fallbackCode: joi_1.default.string().allow(null),
|
|
61
|
-
default: joi_1.default.boolean(),
|
|
62
|
-
contentManagementApi: joi_1.default.boolean(),
|
|
63
|
-
contentDeliveryApi: joi_1.default.boolean(),
|
|
64
|
-
optional: joi_1.default.boolean(),
|
|
65
|
-
sys: joi_1.default.object()
|
|
66
|
-
};
|
|
67
|
-
exports.localeSchema = localeSchema;
|
|
68
|
-
const webhookSchema = {
|
|
69
|
-
name: joi_1.default.string(),
|
|
70
|
-
url: joi_1.default.string().replace(/{[^}{]+?}/g, 'x').regex(/^https?:\/\/[^ /}{][^ }{]*$/i).required(),
|
|
71
|
-
topics: joi_1.default.array().required(),
|
|
72
|
-
httpBasicUsername: joi_1.default.string().allow('', null)
|
|
73
|
-
};
|
|
74
|
-
exports.webhookSchema = webhookSchema;
|
|
75
|
-
/**
|
|
76
|
-
* @returns normalized validation object. Don't use normalized output as payload
|
|
77
|
-
*/
|
|
78
|
-
const payloadSchema = joi_1.default.object({
|
|
79
|
-
entries: joi_1.default.array().items(entrySchema),
|
|
80
|
-
contentTypes: joi_1.default.array().items(contentTypeSchema),
|
|
81
|
-
tags: joi_1.default.array().items(tagSchema),
|
|
82
|
-
assets: joi_1.default.array().items(assetSchema),
|
|
83
|
-
locales: joi_1.default.array().items(localeSchema),
|
|
84
|
-
editorInterfaces: joi_1.default.array().items(editorInterfaceSchema),
|
|
85
|
-
webhooks: joi_1.default.array().items(webhookSchema)
|
|
86
|
-
});
|
|
87
|
-
exports.payloadSchema = payloadSchema;
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const collection_1 = require("lodash/collection");
|
|
27
|
-
const _o = __importStar(require("lodash/object"));
|
|
28
|
-
const array_1 = require("lodash/array");
|
|
29
|
-
/**
|
|
30
|
-
* Given a list of entries, this function reorders them so that entries which
|
|
31
|
-
* are linked from other entries always come first in the order. This ensures
|
|
32
|
-
* that when we publish entries, we are not publishing entries which contain
|
|
33
|
-
* links to other entries which haven't been published yet.
|
|
34
|
-
*/
|
|
35
|
-
function sortEntries(entries) {
|
|
36
|
-
const linkedEntries = getLinkedEntries(entries);
|
|
37
|
-
const mergedLinkedEntries = mergeSort(linkedEntries, (a) => {
|
|
38
|
-
return hasLinkedIndexesInFront(a);
|
|
39
|
-
});
|
|
40
|
-
return (0, collection_1.map)(mergedLinkedEntries, (linkInfo) => entries[linkInfo.index]);
|
|
41
|
-
function hasLinkedIndexesInFront(item) {
|
|
42
|
-
if (hasLinkedIndexes(item)) {
|
|
43
|
-
return (0, collection_1.some)(item.linkIndexes, (index) => index > item.index) ? 1 : -1;
|
|
44
|
-
}
|
|
45
|
-
return 0;
|
|
46
|
-
}
|
|
47
|
-
function hasLinkedIndexes(item) {
|
|
48
|
-
return item.linkIndexes.length > 0;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.default = sortEntries;
|
|
52
|
-
function getLinkedEntries(entries) {
|
|
53
|
-
return (0, collection_1.map)(entries, function (entry) {
|
|
54
|
-
const entryIndex = entries.indexOf(entry);
|
|
55
|
-
const rawLinks = (0, collection_1.map)(entry.fields, (field) => {
|
|
56
|
-
field = _o.values(field)[0];
|
|
57
|
-
if (isEntryLink(field)) {
|
|
58
|
-
return getFieldEntriesIndex(field, entries);
|
|
59
|
-
}
|
|
60
|
-
else if (isEntityArray(field) && isEntryLink(field[0])) {
|
|
61
|
-
return (0, collection_1.map)(field, (item) => getFieldEntriesIndex(item, entries));
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
return {
|
|
65
|
-
index: entryIndex,
|
|
66
|
-
linkIndexes: (0, collection_1.filter)((0, array_1.flatten)(rawLinks), (index) => index >= 0)
|
|
67
|
-
};
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
function getFieldEntriesIndex(field, entries) {
|
|
71
|
-
const id = _o.get(field, 'sys.id');
|
|
72
|
-
return entries.findIndex((entry) => entry.sys.id === id);
|
|
73
|
-
}
|
|
74
|
-
function isEntryLink(item) {
|
|
75
|
-
return _o.get(item, 'sys.type') === 'Entry' ||
|
|
76
|
-
_o.get(item, 'sys.linkType') === 'Entry';
|
|
77
|
-
}
|
|
78
|
-
function isEntityArray(item) {
|
|
79
|
-
return Array.isArray(item) && item.length > 0 && _o.has(item[0], 'sys');
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* From https://github.com/millermedeiros/amd-utils/blob/master/src/array/sort.js
|
|
83
|
-
* MIT Licensed
|
|
84
|
-
* Merge sort (http://en.wikipedia.org/wiki/Merge_sort)
|
|
85
|
-
* @version 0.1.0 (2012/05/23)
|
|
86
|
-
*/
|
|
87
|
-
function mergeSort(arr, compareFn) {
|
|
88
|
-
if (arr.length < 2)
|
|
89
|
-
return arr;
|
|
90
|
-
if (compareFn == null)
|
|
91
|
-
compareFn = defaultCompare;
|
|
92
|
-
const mid = ~~(arr.length / 2);
|
|
93
|
-
const left = mergeSort(arr.slice(0, mid), compareFn);
|
|
94
|
-
const right = mergeSort(arr.slice(mid, arr.length), compareFn);
|
|
95
|
-
return merge(left, right, compareFn);
|
|
96
|
-
}
|
|
97
|
-
function defaultCompare(a, b) {
|
|
98
|
-
return a < b ? -1 : (a > b ? 1 : 0);
|
|
99
|
-
}
|
|
100
|
-
function merge(left, right, compareFn) {
|
|
101
|
-
const result = [];
|
|
102
|
-
while (left.length && right.length) {
|
|
103
|
-
if (compareFn(left[0], right[0]) <= 0) {
|
|
104
|
-
// if 0 it should preserve same order (stable)
|
|
105
|
-
result.push(left.shift());
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
result.push(right.shift());
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (left.length)
|
|
112
|
-
result.push.apply(result, left);
|
|
113
|
-
if (right.length)
|
|
114
|
-
result.push.apply(result, right);
|
|
115
|
-
return result;
|
|
116
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* Given a list of locales, this utility will sort them by `fallback` order, i.e. the locales without fallbacks first,
|
|
5
|
-
* then the locales having them as fallbacks, and then recursively.
|
|
6
|
-
*/
|
|
7
|
-
function sortLocales(locales) {
|
|
8
|
-
const localeByFallback = {};
|
|
9
|
-
locales.forEach(locale => {
|
|
10
|
-
if (locale.fallbackCode === null) {
|
|
11
|
-
locale.fallbackCode = undefined;
|
|
12
|
-
}
|
|
13
|
-
if (!localeByFallback[locale.fallbackCode]) {
|
|
14
|
-
localeByFallback[locale.fallbackCode] = [];
|
|
15
|
-
}
|
|
16
|
-
localeByFallback[locale.fallbackCode].push(locale);
|
|
17
|
-
});
|
|
18
|
-
return sortByFallbackKey(localeByFallback);
|
|
19
|
-
}
|
|
20
|
-
exports.default = sortLocales;
|
|
21
|
-
function sortByFallbackKey(localeByFallback, key) {
|
|
22
|
-
if (!localeByFallback[key]) {
|
|
23
|
-
return [];
|
|
24
|
-
}
|
|
25
|
-
const sortedLocales = localeByFallback[key];
|
|
26
|
-
sortedLocales.forEach((locale) => {
|
|
27
|
-
sortByFallbackKey(localeByFallback, locale.code).forEach((x) => sortedLocales.push(x));
|
|
28
|
-
});
|
|
29
|
-
// We have to reset the undefined fallback code to null so that the locales are properly created without fallback and
|
|
30
|
-
// not the default (en-US)
|
|
31
|
-
sortedLocales.forEach((locale) => {
|
|
32
|
-
if (!locale.fallbackCode) {
|
|
33
|
-
locale.fallbackCode = null;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
return sortedLocales;
|
|
37
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.assertDefaultLocale = exports.assertPayload = void 0;
|
|
7
|
-
const schema_1 = require("./schema");
|
|
8
|
-
const get_entity_name_1 = __importDefault(require("contentful-batch-libs/dist/get-entity-name"));
|
|
9
|
-
const attachEntityName = (details, payload) => {
|
|
10
|
-
details.map((detail) => {
|
|
11
|
-
if (detail.path.length >= 2) {
|
|
12
|
-
detail.entity = (0, get_entity_name_1.default)(payload[detail.path[0]][detail.path[1]]);
|
|
13
|
-
}
|
|
14
|
-
return detail;
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
const countInvalidEntities = (validationData) => {
|
|
18
|
-
const entityCount = validationData.reduce((entities, currentDetail) => {
|
|
19
|
-
if (!entities[currentDetail.path[0]]) {
|
|
20
|
-
entities[currentDetail.path[0]] = 1;
|
|
21
|
-
}
|
|
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_1.payloadSchema.validate(payload, { allowUnknown: true, abortEarly: false });
|
|
31
|
-
if (result.error) {
|
|
32
|
-
attachEntityName(result.error.details, payload);
|
|
33
|
-
const invalidEntityCount = countInvalidEntities(result.error.details).join(', ');
|
|
34
|
-
result.error.message = `${invalidEntityCount} - Get further details in the error log file`;
|
|
35
|
-
delete result.error._object;
|
|
36
|
-
throw result.error;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
exports.assertPayload = assertPayload;
|
|
40
|
-
const assertDefaultLocale = (source, destination) => {
|
|
41
|
-
const sourceDefaultLocale = source.locales.find((locale) => locale.default === true);
|
|
42
|
-
const destinationDefaultLocale = destination.locales.find((locale) => locale.default === true);
|
|
43
|
-
if (!sourceDefaultLocale || !destinationDefaultLocale) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
if (sourceDefaultLocale.code !== destinationDefaultLocale.code) {
|
|
47
|
-
throw new Error(`
|
|
48
|
-
Please make sure the destination space have the same default locale as the source\n
|
|
49
|
-
Default locale for source space : ${sourceDefaultLocale.code}\n
|
|
50
|
-
Default locale for destination space: ${destinationDefaultLocale.code}\n
|
|
51
|
-
`);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
exports.assertDefaultLocale = assertDefaultLocale;
|