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.
@@ -1,329 +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
- 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 listr_1 = __importDefault(require("listr"));
30
- const listr_verbose_renderer_1 = __importDefault(require("listr-verbose-renderer"));
31
- const logging_1 = require("contentful-batch-libs/dist/logging");
32
- const listr_2 = require("contentful-batch-libs/dist/listr");
33
- const assets = __importStar(require("./assets"));
34
- const creation = __importStar(require("./creation"));
35
- const publishing = __importStar(require("./publishing"));
36
- const DEFAULT_CONTENT_STRUCTURE = {
37
- entries: [],
38
- assets: [],
39
- contentTypes: [],
40
- tags: [],
41
- locales: [],
42
- webhooks: [],
43
- editorInterfaces: []
44
- };
45
- /**
46
- * Pushes all changes to a given space. Handles (un)publishing
47
- * as well as delays after creation and before publishing.
48
- *
49
- * Creates everything in the right order so that a content type for a given entry
50
- * is there when entry creation for that content type is attempted.
51
- *
52
- * Allows only content model or only content pushing.
53
- *
54
- * Options:
55
- * - sourceData: see DEFAULT_CONTENT_STRUCTURE
56
- * - destinationData: see DEFAULT_CONTENT_STRUCTURE
57
- * - client: preconfigured management API client
58
- * - spaceId: ID of space content is being copied to
59
- * - contentModelOnly: synchronizes only content types and locales
60
- * - skipLocales: skips locales when synchronizing the content model
61
- * - skipContentModel: synchronizes only entries and assets
62
- * - skipContentPublishing: create content but don't publish it
63
- * - uploadAssets: upload exported files instead of pointing to an existing URL
64
- * - assetsDirectory: path to exported asset files to be uploaded instead of pointing to an existing URL
65
- */
66
- function pushToSpace({ sourceData, destinationData = {}, client, spaceId, environmentId, contentModelOnly, skipContentModel, skipLocales, skipContentPublishing, timeout, retryLimit, listrOptions, uploadAssets, assetsDirectory, requestQueue }) {
67
- sourceData = {
68
- ...DEFAULT_CONTENT_STRUCTURE,
69
- ...sourceData
70
- };
71
- destinationData = {
72
- ...DEFAULT_CONTENT_STRUCTURE,
73
- ...destinationData
74
- };
75
- listrOptions = listrOptions || {
76
- renderer: listr_verbose_renderer_1.default
77
- };
78
- const destinationDataById = {};
79
- for (const [entityType, entities] of Object.entries(destinationData)) {
80
- const entitiesById = new Map();
81
- for (const entity of entities) {
82
- entitiesById.set(entity.sys.id, entity);
83
- }
84
- destinationDataById[entityType] = entitiesById;
85
- }
86
- return new listr_1.default([
87
- {
88
- title: 'Connecting to space',
89
- task: (0, listr_2.wrapTask)(async (ctx, task) => {
90
- const space = await client.getSpace(spaceId);
91
- const environment = await space.getEnvironment(environmentId);
92
- ctx.space = space;
93
- ctx.environment = environment;
94
- })
95
- },
96
- {
97
- title: 'Importing Locales',
98
- task: (0, listr_2.wrapTask)(async (ctx, task) => {
99
- const locales = await creation.createLocales({
100
- context: { target: ctx.environment, type: 'Locale' },
101
- entities: sourceData.locales,
102
- destinationEntitiesById: destinationDataById.locales,
103
- requestQueue
104
- });
105
- ctx.data.locales = locales;
106
- }),
107
- skip: () => skipContentModel || skipLocales
108
- },
109
- {
110
- title: 'Importing Content Types',
111
- task: (0, listr_2.wrapTask)(async (ctx, task) => {
112
- const contentTypes = await creation.createEntities({
113
- context: { target: ctx.environment, type: 'ContentType' },
114
- entities: sourceData.contentTypes,
115
- destinationEntitiesById: destinationDataById.contentTypes,
116
- requestQueue
117
- });
118
- ctx.data.contentTypes = contentTypes;
119
- }),
120
- skip: () => skipContentModel
121
- },
122
- {
123
- title: 'Publishing Content Types',
124
- task: (0, listr_2.wrapTask)(async (ctx, task) => {
125
- const publishedContentTypes = await publishEntities({
126
- entities: ctx.data.contentTypes,
127
- sourceEntities: sourceData.contentTypes,
128
- requestQueue
129
- });
130
- ctx.data.contentTypes = publishedContentTypes;
131
- }),
132
- skip: (ctx) => skipContentModel
133
- },
134
- {
135
- title: 'Importing Tags',
136
- task: (0, listr_2.wrapTask)(async (ctx, task) => {
137
- const tags = await creation.createEntities({
138
- context: { target: ctx.environment, type: 'Tag' },
139
- entities: sourceData.tags,
140
- destinationEntitiesById: destinationDataById.tags,
141
- requestQueue
142
- });
143
- ctx.data.tags = tags;
144
- }),
145
- // we remove `tags` from destination data if an error was thrown trying to access them
146
- // this means the user doesn't have access to this feature, skip importing tags
147
- skip: () => !destinationDataById.tags
148
- },
149
- {
150
- title: 'Importing Editor Interfaces',
151
- task: (0, listr_2.wrapTask)(async (ctx, task) => {
152
- const allEditorInterfacesBeingFetched = ctx.data.contentTypes.map(async (contentType) => {
153
- const editorInterface = sourceData.editorInterfaces.find((editorInterface) => {
154
- return editorInterface.sys.contentType.sys.id === contentType.sys.id;
155
- });
156
- if (!editorInterface) {
157
- return;
158
- }
159
- try {
160
- const ctEditorInterface = await requestQueue.add(() => ctx.environment.getEditorInterfaceForContentType(contentType.sys.id));
161
- logging_1.logEmitter.emit('info', `Fetched editor interface for ${contentType.name}`);
162
- ctEditorInterface.controls = editorInterface.controls;
163
- ctEditorInterface.groupControls = editorInterface.groupControls;
164
- ctEditorInterface.editorLayout = editorInterface.editorLayout;
165
- const updatedEditorInterface = await requestQueue.add(() => ctEditorInterface.update());
166
- return updatedEditorInterface;
167
- }
168
- catch (err) {
169
- err.entity = editorInterface;
170
- throw err;
171
- }
172
- });
173
- const allEditorInterfaces = await Promise.all(allEditorInterfacesBeingFetched);
174
- const editorInterfaces = allEditorInterfaces.filter((editorInterface) => editorInterface);
175
- ctx.data.editorInterfaces = editorInterfaces;
176
- }),
177
- skip: (ctx) => skipContentModel || ctx.data.contentTypes.length === 0
178
- },
179
- {
180
- title: 'Uploading Assets',
181
- task: (0, listr_2.wrapTask)(async (ctx, task) => {
182
- const allPendingUploads = [];
183
- for (const asset of sourceData.assets) {
184
- for (const file of Object.values(asset.transformed.fields.file)) {
185
- allPendingUploads.push(requestQueue.add(async () => {
186
- try {
187
- logging_1.logEmitter.emit('info', `Uploading Asset file ${file.upload}`);
188
- const assetStream = await assets.getAssetStreamForURL(file.upload, assetsDirectory);
189
- const upload = await ctx.environment.createUpload({
190
- fileName: asset.transformed.sys.id,
191
- file: assetStream
192
- });
193
- delete file.upload;
194
- file.uploadFrom = {
195
- sys: {
196
- type: 'Link',
197
- linkType: 'Upload',
198
- id: upload.sys.id
199
- }
200
- };
201
- return upload;
202
- }
203
- catch (err) {
204
- logging_1.logEmitter.emit('error', err);
205
- }
206
- }));
207
- }
208
- }
209
- // We call the pending uploads for the side effects
210
- // so we can just await all pending ones that are queued
211
- const uploads = await Promise.all(allPendingUploads);
212
- ctx.data.uploadedAssetFiles = uploads;
213
- }),
214
- skip: (ctx) => !uploadAssets || !sourceData.assets.length
215
- },
216
- {
217
- title: 'Importing Assets',
218
- task: (0, listr_2.wrapTask)(async (ctx, task) => {
219
- const assetsToProcess = await creation.createEntities({
220
- context: { target: ctx.environment, type: 'Asset' },
221
- entities: sourceData.assets,
222
- destinationEntitiesById: destinationDataById.assets,
223
- requestQueue
224
- });
225
- const processedAssets = await assets.processAssets({
226
- assets: assetsToProcess,
227
- timeout,
228
- retryLimit,
229
- requestQueue
230
- });
231
- ctx.data.assets = processedAssets;
232
- }),
233
- skip: (ctx) => contentModelOnly
234
- },
235
- {
236
- title: 'Publishing Assets',
237
- task: (0, listr_2.wrapTask)(async (ctx, task) => {
238
- const publishedAssets = await publishEntities({
239
- entities: ctx.data.assets,
240
- sourceEntities: sourceData.assets,
241
- requestQueue
242
- });
243
- ctx.data.publishedAssets = publishedAssets;
244
- }),
245
- skip: (ctx) => contentModelOnly || skipContentPublishing
246
- },
247
- {
248
- title: 'Archiving Assets',
249
- task: (0, listr_2.wrapTask)(async (ctx, task) => {
250
- const archivedAssets = await archiveEntities({
251
- entities: ctx.data.assets,
252
- sourceEntities: sourceData.assets,
253
- requestQueue
254
- });
255
- ctx.data.archivedAssets = archivedAssets;
256
- }),
257
- skip: (ctx) => contentModelOnly || skipContentPublishing
258
- },
259
- {
260
- title: 'Importing Content Entries',
261
- task: (0, listr_2.wrapTask)(async (ctx, task) => {
262
- const entries = await creation.createEntries({
263
- context: { target: ctx.environment, skipContentModel },
264
- entities: sourceData.entries,
265
- destinationEntitiesById: destinationDataById.entries,
266
- requestQueue
267
- });
268
- ctx.data.entries = entries;
269
- }),
270
- skip: (ctx) => contentModelOnly
271
- },
272
- {
273
- title: 'Publishing Content Entries',
274
- task: (0, listr_2.wrapTask)(async (ctx, task) => {
275
- const publishedEntries = await publishEntities({
276
- entities: ctx.data.entries,
277
- sourceEntities: sourceData.entries,
278
- requestQueue
279
- });
280
- ctx.data.publishedEntries = publishedEntries;
281
- }),
282
- skip: (ctx) => contentModelOnly || skipContentPublishing
283
- },
284
- {
285
- title: 'Archiving Entries',
286
- task: (0, listr_2.wrapTask)(async (ctx, task) => {
287
- const archivedEntries = await archiveEntities({
288
- entities: ctx.data.entries,
289
- sourceEntities: sourceData.entries,
290
- requestQueue
291
- });
292
- ctx.data.archivedEntries = archivedEntries;
293
- }),
294
- skip: (ctx) => contentModelOnly || skipContentPublishing
295
- },
296
- {
297
- title: 'Creating Web Hooks',
298
- task: (0, listr_2.wrapTask)(async (ctx, task) => {
299
- const webhooks = await creation.createEntities({
300
- context: { target: ctx.space, type: 'Webhook' },
301
- entities: sourceData.webhooks,
302
- destinationEntitiesById: destinationDataById.webhooks,
303
- requestQueue
304
- });
305
- ctx.data.webhooks = webhooks;
306
- }),
307
- skip: (ctx) => contentModelOnly || (environmentId !== 'master' && 'Webhooks can only be imported in master environment')
308
- }
309
- ], listrOptions);
310
- }
311
- exports.default = pushToSpace;
312
- function archiveEntities({ entities, sourceEntities, requestQueue }) {
313
- const entityIdsToArchive = sourceEntities
314
- .filter(({ original }) => original.sys.archivedVersion)
315
- .map(({ original }) => original.sys.id);
316
- const entitiesToArchive = entities
317
- .filter((entity) => entityIdsToArchive.indexOf(entity.sys.id) !== -1);
318
- return publishing.archiveEntities({ entities: entitiesToArchive, requestQueue });
319
- }
320
- function publishEntities({ entities, sourceEntities, requestQueue }) {
321
- // Find all entities in source content which are published
322
- const entityIdsToPublish = sourceEntities
323
- .filter(({ original }) => original.sys.publishedVersion)
324
- .map(({ original }) => original.sys.id);
325
- // Filter imported entities and publish only these who got published in the source
326
- const entitiesToPublish = entities
327
- .filter((entity) => entityIdsToPublish.indexOf(entity.sys.id) !== -1);
328
- return publishing.publishEntities({ entities: entitiesToPublish, requestQueue });
329
- }
@@ -1,56 +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
- 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
- ];
36
- /**
37
- * Run transformer methods on each item for each kind of entity, in case there
38
- * is a need to transform data when copying it to the destination space
39
- */
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);
55
- }
56
- exports.default = default_1;
@@ -1,70 +0,0 @@
1
- "use strict";
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");
6
- /**
7
- * Default transformer methods for each kind of entity.
8
- *
9
- * In the case of assets it also changes the asset url to the upload property
10
- * as the whole upload process needs to be followed again.
11
- */
12
- function contentTypes(contentType) {
13
- return contentType;
14
- }
15
- exports.contentTypes = contentTypes;
16
- function tags(tag) {
17
- return tag;
18
- }
19
- exports.tags = tags;
20
- function entries(entry, _, tagsEnabled = false) {
21
- return removeMetadataTags(entry, tagsEnabled);
22
- }
23
- exports.entries = entries;
24
- function webhooks(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;
34
- }
35
- exports.webhooks = webhooks;
36
- function assets(asset, _, tagsEnabled = false) {
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);
52
- }
53
- exports.assets = assets;
54
- function locales(locale, destinationLocales) {
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;
63
- }
64
- exports.locales = locales;
65
- function removeMetadataTags(entity, tagsEnabled = false) {
66
- if (!tagsEnabled) {
67
- delete entity.metadata;
68
- }
69
- return entity;
70
- }
@@ -1,115 +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
- 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,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getHeadersConfig = void 0;
4
- /**
5
- * Turn header option into an object. Invalid header values
6
- * are ignored.
7
- *
8
- * @example
9
- * getHeadersConfig('Accept: Any')
10
- * // -> {Accept: 'Any'}
11
- *
12
- * @example
13
- * getHeadersConfig(['Accept: Any', 'X-Version: 1'])
14
- * // -> {Accept: 'Any', 'X-Version': '1'}
15
- *
16
- * @param value {string|string[]}
17
- */
18
- function getHeadersConfig(value) {
19
- if (!value) {
20
- return {};
21
- }
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;