contentful-import 9.0.21 → 9.1.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.
@@ -1,36 +1,56 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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;
5
17
  });
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
-
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const object_1 = require("lodash/object");
30
+ const defaultTransformers = __importStar(require("./transformers"));
31
+ const sort_entries_1 = __importDefault(require("../utils/sort-entries"));
32
+ const sort_locales_1 = __importDefault(require("../utils/sort-locales"));
33
+ const spaceEntities = [
34
+ 'contentTypes', 'entries', 'assets', 'locales', 'webhooks', 'tags'
35
+ ];
16
36
  /**
17
37
  * Run transformer methods on each item for each kind of entity, in case there
18
38
  * is a need to transform data when copying it to the destination space
19
39
  */
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);
40
+ function default_1(sourceData, destinationData, customTransformers, entities = spaceEntities) {
41
+ const transformers = (0, object_1.defaults)(customTransformers, defaultTransformers);
42
+ const baseSpaceData = (0, object_1.omit)(sourceData, ...entities);
43
+ sourceData.locales = (0, sort_locales_1.default)(sourceData.locales);
44
+ const tagsEnabled = !!destinationData.tags;
45
+ return entities.reduce((transformedSpaceData, type) => {
46
+ // tags don't contain links to other entities, don't need to be sorted
47
+ const sortedEntities = (type === 'tags') ? sourceData[type] : (0, sort_entries_1.default)(sourceData[type]);
48
+ const transformedEntities = sortedEntities.map((entity) => ({
49
+ original: entity,
50
+ transformed: transformers[type](entity, destinationData[type], tagsEnabled)
51
+ }));
52
+ transformedSpaceData[type] = transformedEntities;
53
+ return transformedSpaceData;
54
+ }, baseSpaceData);
35
55
  }
36
- module.exports = exports.default;
56
+ exports.default = default_1;
@@ -1,75 +1,70 @@
1
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");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.locales = exports.assets = exports.webhooks = exports.entries = exports.tags = exports.contentTypes = void 0;
4
+ const object_1 = require("lodash/object");
5
+ const collection_1 = require("lodash/collection");
14
6
  /**
15
7
  * Default transformer methods for each kind of entity.
16
8
  *
17
9
  * In the case of assets it also changes the asset url to the upload property
18
10
  * as the whole upload process needs to be followed again.
19
11
  */
20
-
21
12
  function contentTypes(contentType) {
22
- return contentType;
13
+ return contentType;
23
14
  }
15
+ exports.contentTypes = contentTypes;
24
16
  function tags(tag) {
25
- return tag;
17
+ return tag;
26
18
  }
19
+ exports.tags = tags;
27
20
  function entries(entry, _, tagsEnabled = false) {
28
- return removeMetadataTags(entry, tagsEnabled);
21
+ return removeMetadataTags(entry, tagsEnabled);
29
22
  }
23
+ exports.entries = entries;
30
24
  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;
25
+ // Workaround for webhooks with credentials
26
+ if (webhook.httpBasicUsername) {
27
+ delete webhook.httpBasicUsername;
28
+ }
29
+ // Workaround for webhooks with secret headers
30
+ if (webhook.headers) {
31
+ webhook.headers = webhook.headers.filter(header => !header.secret);
32
+ }
33
+ return webhook;
41
34
  }
35
+ exports.webhooks = webhooks;
42
36
  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);
37
+ const transformedAsset = (0, object_1.omit)(asset, 'sys');
38
+ transformedAsset.sys = (0, object_1.pick)(asset.sys, 'id');
39
+ transformedAsset.fields = (0, object_1.pick)(asset.fields, 'title', 'description');
40
+ transformedAsset.fields.file = (0, collection_1.reduce)(asset.fields.file, (newFile, localizedFile, locale) => {
41
+ newFile[locale] = (0, object_1.pick)(localizedFile, 'contentType', 'fileName');
42
+ if (!localizedFile.uploadFrom) {
43
+ const assetUrl = localizedFile.url || localizedFile.upload;
44
+ newFile[locale].upload = `${/^(http|https):\/\//i.test(assetUrl) ? '' : 'https:'}${assetUrl}`;
45
+ }
46
+ else {
47
+ newFile[locale].uploadFrom = localizedFile.uploadFrom;
48
+ }
49
+ return newFile;
50
+ }, {});
51
+ return removeMetadataTags(transformedAsset, tagsEnabled);
57
52
  }
53
+ exports.assets = assets;
58
54
  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;
55
+ const transformedLocale = (0, object_1.pick)(locale, 'code', 'name', 'contentManagementApi', 'contentDeliveryApi', 'fallbackCode', 'optional');
56
+ const destinationLocale = (0, collection_1.find)(destinationLocales, { code: locale.code });
57
+ if (destinationLocale) {
58
+ // This will implicitly remove the locale ID
59
+ // which then causes the create path to not pick `createLocaleWithId` but `createLocale` instead
60
+ transformedLocale.sys = (0, object_1.pick)(destinationLocale.sys, 'id');
61
+ }
62
+ return transformedLocale;
69
63
  }
64
+ exports.locales = locales;
70
65
  function removeMetadataTags(entity, tagsEnabled = false) {
71
- if (!tagsEnabled) {
72
- delete entity.metadata;
73
- }
74
- return entity;
75
- }
66
+ if (!tagsEnabled) {
67
+ delete entity.metadata;
68
+ }
69
+ return entity;
70
+ }
@@ -1,76 +1,115 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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;
5
17
  });
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;
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const yargs_1 = __importDefault(require("yargs"));
30
+ const packageFile = __importStar(require("../package"));
31
+ exports.default = yargs_1.default
32
+ .version(packageFile.version || 'Version only available on installed package')
33
+ .usage('Usage: $0 [options]')
34
+ .option('space-id', {
35
+ describe: 'ID of the destination space',
36
+ type: 'string',
37
+ demand: true
38
+ })
39
+ .option('environment-id', {
40
+ describe: 'ID the environment in the destination space',
41
+ type: 'string',
42
+ default: 'master',
43
+ demand: false
44
+ })
45
+ .option('management-token', {
46
+ describe: 'Contentful management API token for the destination space',
47
+ type: 'string',
48
+ demand: true
49
+ })
50
+ .option('content-file', {
51
+ describe: 'JSON file that contains data to be import to your space',
52
+ type: 'string',
53
+ demand: true
54
+ })
55
+ .option('content-model-only', {
56
+ describe: 'Import only content types',
57
+ type: 'boolean',
58
+ default: false
59
+ })
60
+ .option('skip-content-model', {
61
+ describe: 'Skip importing content types and locales',
62
+ type: 'boolean',
63
+ default: false
64
+ })
65
+ .option('skip-locales', {
66
+ describe: 'Skip importing locales',
67
+ type: 'boolean',
68
+ default: false
69
+ })
70
+ .option('skip-content-publishing', {
71
+ describe: 'Skips content publishing. Creates content but does not publish it',
72
+ type: 'boolean',
73
+ default: false
74
+ })
75
+ .option('upload-assets', {
76
+ describe: 'Uses local asset files and uploads them instead of pointing to the URLs of previously uploaded assets. Requires assets-directory',
77
+ type: 'boolean',
78
+ default: false
79
+ })
80
+ .implies('upload-assets', 'assets-directory')
81
+ .option('assets-directory', {
82
+ 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',
83
+ type: 'string'
84
+ })
85
+ .implies('assets-directory', 'upload-assets')
86
+ .option('error-log-file', {
87
+ describe: 'Full path to the error log file',
88
+ type: 'string'
89
+ })
90
+ .option('host', {
91
+ describe: 'Management API host',
92
+ type: 'string',
93
+ default: 'api.contentful.com'
94
+ })
95
+ .option('proxy', {
96
+ describe: 'Proxy configuration in HTTP auth format: [http|https]://host:port or [http|https]://user:password@host:port',
97
+ type: 'string'
98
+ })
99
+ .option('raw-proxy', {
100
+ describe: 'Pass proxy config to Axios instead of creating a custom httpsAgent',
101
+ type: 'boolean',
102
+ default: false
103
+ })
104
+ .option('rate-limit', {
105
+ describe: 'Maximum requests per second used for API requests',
106
+ type: 'number',
107
+ default: 7
108
+ })
109
+ .option('header', {
110
+ alias: 'H',
111
+ type: 'string',
112
+ describe: 'Pass an additional HTTP Header'
113
+ })
114
+ .config('config', 'An optional configuration JSON file containing all the options for a single run')
115
+ .argv;
@@ -1,14 +1,6 @@
1
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); }
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getHeadersConfig = void 0;
12
4
  /**
13
5
  * Turn header option into an object. Invalid header values
14
6
  * are ignored.
@@ -24,22 +16,23 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
24
16
  * @param value {string|string[]}
25
17
  */
26
18
  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;
19
+ if (!value) {
20
+ return {};
38
21
  }
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
- }
22
+ const values = Array.isArray(value) ? value : [value];
23
+ return values.reduce((headers, value) => {
24
+ value = value.trim();
25
+ const separatorIndex = value.indexOf(':');
26
+ // Invalid header format
27
+ if (separatorIndex === -1) {
28
+ return headers;
29
+ }
30
+ const headerKey = value.slice(0, separatorIndex).trim();
31
+ const headerValue = value.slice(separatorIndex + 1).trim();
32
+ return {
33
+ ...headers,
34
+ [headerKey]: headerValue
35
+ };
36
+ }, {});
37
+ }
38
+ exports.getHeadersConfig = getHeadersConfig;
@@ -1,96 +1,87 @@
1
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 }; }
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"));
9
8
  const entrySchema = {
10
- sys: _joi.default.object(),
11
- fields: _joi.default.object()
9
+ sys: joi_1.default.object(),
10
+ fields: joi_1.default.object()
12
11
  };
13
12
  exports.entrySchema = entrySchema;
14
13
  const tagSchema = {
15
- name: _joi.default.string().required(),
16
- sys: _joi.default.object()
14
+ name: joi_1.default.string().required(),
15
+ sys: joi_1.default.object()
17
16
  };
18
17
  exports.tagSchema = tagSchema;
19
18
  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
- }))
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
+ }))
36
31
  };
37
32
  exports.contentTypeSchema = contentTypeSchema;
38
33
  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()
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()
54
49
  };
55
50
  exports.assetSchema = assetSchema;
56
51
  const editorInterfaceSchema = {
57
- sys: _joi.default.object(),
58
- controls: _joi.default.array().items({
59
- fieldId: _joi.default.string(),
60
- widgetId: _joi.default.string()
61
- })
52
+ sys: joi_1.default.object(),
53
+ controls: joi_1.default.array().items({ fieldId: joi_1.default.string(), widgetId: joi_1.default.string() })
62
54
  };
63
55
  exports.editorInterfaceSchema = editorInterfaceSchema;
64
56
  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()
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()
74
66
  };
75
67
  exports.localeSchema = localeSchema;
76
68
  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)
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)
81
73
  };
82
-
74
+ exports.webhookSchema = webhookSchema;
83
75
  /**
84
76
  * @returns normalized validation object. Don't use normalized output as payload
85
77
  */
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)
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)
95
86
  });
96
- exports.payloadSchema = payloadSchema;
87
+ exports.payloadSchema = payloadSchema;