contentful-import 9.2.1 → 9.3.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/README.md CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/contentful-import.svg)](https://www.npmjs.com/package/contentful-import)
4
4
  [![CircleCI](https://circleci.com/gh/contentful/contentful-import.svg?style=shield)](https://circleci.com/gh/contentful/contentful-import/?branch=master)
5
- [![Dependency Status](https://img.shields.io/david/contentful/contentful-import.svg)](https://david-dm.org/contentful/contentful-import)
6
- [![devDependency Status](https://img.shields.io/david/dev/contentful/contentful-import.svg)](https://david-dm.org/contentful/contentful-import#info=devDependencies)
7
5
 
8
6
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
9
7
 
@@ -146,6 +144,14 @@ Upload local asset files downloaded via the [downloadAssets](https://github.com/
146
144
 
147
145
  Path to a directory with an asset export made using the [downloadAssets](https://github.com/contentful/contentful-export#downloadassets-boolean) option of the export. Requires `uploadAssets`
148
146
 
147
+ #### `timeout` [number] [default: 3000]
148
+
149
+ Time between retries on asset processing
150
+
151
+ #### `retryLimit` [number] [default: 10]
152
+
153
+ Maximum number of retries for asset processing
154
+
149
155
  ### Connection
150
156
 
151
157
  #### `host` [string] [default: 'api.contentful.com']
@@ -178,6 +184,10 @@ Full path to the error log file
178
184
 
179
185
  Display progress in new lines instead of displaying a busy spinner and the status in the same line. Useful for CI.
180
186
 
187
+ ### `config` [string]
188
+
189
+ Path to a JSON file with the configuration options. This file will be merged with the options passed to the function. The options passed to the function will take precedence over the ones in the config file.
190
+
181
191
  ## :rescue_worker_helmet: Troubleshooting
182
192
 
183
193
  Unable to connect to Contentful through your Proxy? Try to set the `rawProxy` option to `true`.
@@ -3,7 +3,7 @@ const runContentfulImport = require('../dist/index')
3
3
  const usageParams = require('../dist/usageParams')
4
4
  console.log('We moved the CLI version of this tool into our Contentful CLI.\nThis allows our users to use and install only one single CLI tool to get the full Contentful experience.\nFor more info please visit https://github.com/contentful/contentful-cli/tree/master/docs/space/import')
5
5
  runContentfulImport(usageParams)
6
- .then((result) => {
6
+ .then(() => {
7
7
  process.exit(0)
8
8
  })
9
9
  .catch(function (err) {
package/dist/index.d.mts CHANGED
@@ -1,3 +1,26 @@
1
- declare function runContentfulImport(params: any): Promise<any>;
1
+ type RunContentfulImportParams = {
2
+ spaceId: string;
3
+ environmentId?: string;
4
+ managementToken: string;
5
+ contentFile?: string;
6
+ content?: object;
7
+ contentModelOnly?: boolean;
8
+ skipContentModel?: boolean;
9
+ skipLocales?: boolean;
10
+ skipContentPublishing?: boolean;
11
+ uploadAssets?: boolean;
12
+ assetsDirectory?: string;
13
+ host?: string;
14
+ proxy?: string;
15
+ rawProxy?: string;
16
+ rateLimit?: number;
17
+ headers?: object;
18
+ errorLogFile?: string;
19
+ useVerboseRenderer?: boolean;
20
+ timeout?: number;
21
+ retryLimit?: number;
22
+ config?: string;
23
+ };
24
+ declare function runContentfulImport(params: RunContentfulImportParams): Promise<any>;
2
25
 
3
26
  export { runContentfulImport as default };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,26 @@
1
- declare function runContentfulImport(params: any): Promise<any>;
1
+ type RunContentfulImportParams = {
2
+ spaceId: string;
3
+ environmentId?: string;
4
+ managementToken: string;
5
+ contentFile?: string;
6
+ content?: object;
7
+ contentModelOnly?: boolean;
8
+ skipContentModel?: boolean;
9
+ skipLocales?: boolean;
10
+ skipContentPublishing?: boolean;
11
+ uploadAssets?: boolean;
12
+ assetsDirectory?: string;
13
+ host?: string;
14
+ proxy?: string;
15
+ rawProxy?: string;
16
+ rateLimit?: number;
17
+ headers?: object;
18
+ errorLogFile?: string;
19
+ useVerboseRenderer?: boolean;
20
+ timeout?: number;
21
+ retryLimit?: number;
22
+ config?: string;
23
+ };
24
+ declare function runContentfulImport(params: RunContentfulImportParams): Promise<any>;
2
25
 
3
26
  export { runContentfulImport as default };
package/dist/index.js CHANGED
@@ -43,7 +43,7 @@ var import_p_queue = __toESM(require("p-queue"));
43
43
  var import_logging7 = require("contentful-batch-libs/dist/logging");
44
44
  var import_listr4 = require("contentful-batch-libs/dist/listr");
45
45
 
46
- // lib/tasks/init-client.js
46
+ // lib/tasks/init-client.ts
47
47
  var import_contentful_management = require("contentful-management");
48
48
  var import_logging = require("contentful-batch-libs/dist/logging");
49
49
  function logHandler(level, data) {
@@ -61,7 +61,7 @@ function initClient(opts) {
61
61
  return (0, import_contentful_management.createClient)(config);
62
62
  }
63
63
 
64
- // lib/tasks/get-destination-data.js
64
+ // lib/tasks/get-destination-data.ts
65
65
  var import_bluebird = __toESM(require("bluebird"));
66
66
  var import_logging2 = require("contentful-batch-libs/dist/logging");
67
67
  var BATCH_CHAR_LIMIT = 1990;
@@ -133,59 +133,81 @@ async function getDestinationData({
133
133
  ...sourceData
134
134
  };
135
135
  if (!skipContentModel) {
136
- const contentTypeIds = sourceData.contentTypes.map((e) => e.sys.id);
137
- result.contentTypes = batchedIdQuery({
138
- environment,
139
- type: "contentTypes",
140
- ids: contentTypeIds,
141
- requestQueue
142
- });
143
- if (!skipLocales) {
144
- const localeIds = sourceData.locales.map((e) => e.sys.id);
145
- result.locales = batchedIdQuery({
136
+ const contentTypeIds = sourceData.contentTypes?.map((e) => e.sys.id);
137
+ if (contentTypeIds) {
138
+ result.contentTypes = batchedIdQuery({
146
139
  environment,
147
- type: "locales",
148
- ids: localeIds,
140
+ type: "contentTypes",
141
+ ids: contentTypeIds,
149
142
  requestQueue
150
143
  });
151
144
  }
145
+ if (!skipLocales) {
146
+ const localeIds = sourceData.locales?.map((e) => e.sys.id);
147
+ if (localeIds) {
148
+ result.locales = batchedIdQuery({
149
+ environment,
150
+ type: "locales",
151
+ ids: localeIds,
152
+ requestQueue
153
+ });
154
+ }
155
+ }
152
156
  }
153
- result.tags = environment.getTags().then((response) => response.items).catch((e) => {
157
+ result.tags = environment.getTags().then((response) => response.items).catch(() => {
154
158
  delete result.tags;
155
159
  });
156
160
  if (contentModelOnly) {
157
161
  return import_bluebird.default.props(result);
158
162
  }
159
- const entryIds = sourceData.entries.map((e) => e.sys.id);
160
- const assetIds = sourceData.assets.map((e) => e.sys.id);
161
- result.entries = batchedIdQuery({
162
- environment,
163
- type: "entries",
164
- ids: entryIds,
165
- requestQueue
166
- });
167
- result.assets = batchedIdQuery({
168
- environment,
169
- type: "assets",
170
- ids: assetIds,
171
- requestQueue
172
- });
163
+ const entryIds = sourceData.entries?.map((e) => e.sys.id);
164
+ const assetIds = sourceData.assets?.map((e) => e.sys.id);
165
+ if (entryIds) {
166
+ result.entries = batchedIdQuery({
167
+ environment,
168
+ type: "entries",
169
+ ids: entryIds,
170
+ requestQueue
171
+ });
172
+ }
173
+ if (assetIds) {
174
+ result.assets = batchedIdQuery({
175
+ environment,
176
+ type: "assets",
177
+ ids: assetIds,
178
+ requestQueue
179
+ });
180
+ }
173
181
  result.webhooks = [];
174
182
  return import_bluebird.default.props(result);
175
183
  }
176
184
 
177
- // lib/tasks/push-to-space/push-to-space.js
185
+ // lib/tasks/push-to-space/push-to-space.ts
178
186
  var import_listr = __toESM(require("listr"));
179
187
  var import_listr_verbose_renderer = __toESM(require("listr-verbose-renderer"));
180
188
  var import_logging6 = require("contentful-batch-libs/dist/logging");
181
189
  var import_listr2 = require("contentful-batch-libs/dist/listr");
182
190
 
183
- // lib/tasks/push-to-space/assets.js
191
+ // lib/tasks/push-to-space/assets.ts
184
192
  var import_fs = __toESM(require("fs"));
185
193
  var import_path = require("path");
186
194
  var import_util = require("util");
187
195
  var import_get_entity_name = __toESM(require("contentful-batch-libs/dist/get-entity-name"));
188
196
  var import_logging3 = require("contentful-batch-libs/dist/logging");
197
+
198
+ // lib/utils/errors.ts
199
+ var ContentfulAssetError = class extends Error {
200
+ constructor(message, filePath) {
201
+ super(message);
202
+ this.filePath = filePath;
203
+ }
204
+ };
205
+ var ContentfulEntityError = class extends Error {
206
+ };
207
+ var ContentfulMultiError = class extends Error {
208
+ };
209
+
210
+ // lib/tasks/push-to-space/assets.ts
189
211
  var stat = (0, import_util.promisify)(import_fs.default.stat);
190
212
  async function getAssetStreamForURL(url, assetsDirectory) {
191
213
  const [, assetPath] = url.split("//");
@@ -194,8 +216,10 @@ async function getAssetStreamForURL(url, assetsDirectory) {
194
216
  await stat(filePath);
195
217
  return import_fs.default.createReadStream(filePath);
196
218
  } catch (err) {
197
- const error = new Error("Cannot open asset from filesystem");
198
- error.filePath = filePath;
219
+ const error = new ContentfulAssetError(
220
+ "Cannot open asset from filesystem",
221
+ filePath
222
+ );
199
223
  throw error;
200
224
  }
201
225
  }
@@ -203,7 +227,9 @@ async function processAssetForLocale(locale, asset, processingOptions) {
203
227
  try {
204
228
  return await asset.processForLocale(locale, processingOptions);
205
229
  } catch (err) {
206
- err.entity = asset;
230
+ if (err instanceof ContentfulEntityError) {
231
+ err.entity = asset;
232
+ }
207
233
  import_logging3.logEmitter.emit("error", err);
208
234
  throw err;
209
235
  }
@@ -253,7 +279,7 @@ async function processAssets({
253
279
  return potentiallyProcessedAssets.filter((asset) => asset);
254
280
  }
255
281
 
256
- // lib/tasks/push-to-space/creation.js
282
+ // lib/tasks/push-to-space/creation.ts
257
283
  var import_collection = require("lodash/collection");
258
284
  var import_object = require("lodash/object");
259
285
  var import_get_entity_name2 = __toESM(require("contentful-batch-libs/dist/get-entity-name"));
@@ -322,12 +348,16 @@ async function createEntry({ entry, target, skipContentModel, destinationEntitie
322
348
  creationSuccessNotifier(operation, createdOrUpdatedEntry);
323
349
  return createdOrUpdatedEntry;
324
350
  } catch (err) {
325
- if (skipContentModel && err.name === "UnknownField") {
326
- const errors = (0, import_object.get)(JSON.parse(err.message), "details.errors");
327
- entry.transformed.fields = cleanupUnknownFields(entry.transformed.fields, errors);
328
- return createEntry({ entry, target, skipContentModel, destinationEntitiesById, requestQueue });
351
+ if (err instanceof Error) {
352
+ if (skipContentModel && err.name === "UnknownField") {
353
+ const errors = (0, import_object.get)(JSON.parse(err.message), "details.errors");
354
+ entry.transformed.fields = cleanupUnknownFields(entry.transformed.fields, errors);
355
+ return createEntry({ entry, target, skipContentModel, destinationEntitiesById, requestQueue });
356
+ }
357
+ }
358
+ if (err instanceof ContentfulEntityError) {
359
+ err.entity = entry;
329
360
  }
330
- err.entity = entry;
331
361
  import_logging4.logEmitter.emit("error", err);
332
362
  return null;
333
363
  }
@@ -389,7 +419,7 @@ function getPlainData(entity) {
389
419
  return (0, import_object.omit)(data, "sys");
390
420
  }
391
421
 
392
- // lib/tasks/push-to-space/publishing.js
422
+ // lib/tasks/push-to-space/publishing.ts
393
423
  var import_get_entity_name3 = __toESM(require("contentful-batch-libs/dist/get-entity-name"));
394
424
  var import_logging5 = require("contentful-batch-libs/dist/logging");
395
425
  async function publishEntities({ entities, requestQueue }) {
@@ -432,7 +462,9 @@ async function archiveEntities({ entities, requestQueue }) {
432
462
  const archivedEntity = await entity2.archive();
433
463
  return archivedEntity;
434
464
  } catch (err) {
435
- err.entity = entity2;
465
+ if (err instanceof ContentfulEntityError) {
466
+ err.entity = entity2;
467
+ }
436
468
  import_logging5.logEmitter.emit("error", err);
437
469
  return null;
438
470
  }
@@ -451,7 +483,9 @@ async function runQueue(queue, result = [], requestQueue) {
451
483
  const publishedEntity = await requestQueue.add(() => entity.publish());
452
484
  publishedEntities.push(publishedEntity);
453
485
  } catch (err) {
454
- err.entity = entity;
486
+ if (err instanceof ContentfulEntityError) {
487
+ err.entity = entity;
488
+ }
455
489
  import_logging5.logEmitter.emit("error", err);
456
490
  }
457
491
  }
@@ -472,7 +506,7 @@ async function runQueue(queue, result = [], requestQueue) {
472
506
  return result;
473
507
  }
474
508
 
475
- // lib/tasks/push-to-space/push-to-space.js
509
+ // lib/tasks/push-to-space/push-to-space.ts
476
510
  var DEFAULT_CONTENT_STRUCTURE = {
477
511
  entries: [],
478
512
  assets: [],
@@ -521,7 +555,7 @@ function pushToSpace({
521
555
  return new import_listr.default([
522
556
  {
523
557
  title: "Connecting to space",
524
- task: (0, import_listr2.wrapTask)(async (ctx, task) => {
558
+ task: (0, import_listr2.wrapTask)(async (ctx) => {
525
559
  const space = await client.getSpace(spaceId);
526
560
  const environment = await space.getEnvironment(environmentId);
527
561
  ctx.space = space;
@@ -530,7 +564,10 @@ function pushToSpace({
530
564
  },
531
565
  {
532
566
  title: "Importing Locales",
533
- task: (0, import_listr2.wrapTask)(async (ctx, task) => {
567
+ task: (0, import_listr2.wrapTask)(async (ctx) => {
568
+ if (!destinationDataById.locales) {
569
+ return;
570
+ }
534
571
  const locales2 = await createLocales({
535
572
  context: { target: ctx.environment, type: "Locale" },
536
573
  entities: sourceData.locales,
@@ -543,7 +580,10 @@ function pushToSpace({
543
580
  },
544
581
  {
545
582
  title: "Importing Content Types",
546
- task: (0, import_listr2.wrapTask)(async (ctx, task) => {
583
+ task: (0, import_listr2.wrapTask)(async (ctx) => {
584
+ if (!destinationDataById.contentTypes) {
585
+ return;
586
+ }
547
587
  const contentTypes2 = await createEntities({
548
588
  context: { target: ctx.environment, type: "ContentType" },
549
589
  entities: sourceData.contentTypes,
@@ -556,7 +596,7 @@ function pushToSpace({
556
596
  },
557
597
  {
558
598
  title: "Publishing Content Types",
559
- task: (0, import_listr2.wrapTask)(async (ctx, task) => {
599
+ task: (0, import_listr2.wrapTask)(async (ctx) => {
560
600
  const publishedContentTypes = await publishEntities2({
561
601
  entities: ctx.data.contentTypes,
562
602
  sourceEntities: sourceData.contentTypes,
@@ -564,18 +604,20 @@ function pushToSpace({
564
604
  });
565
605
  ctx.data.contentTypes = publishedContentTypes;
566
606
  }),
567
- skip: (ctx) => skipContentModel
607
+ skip: () => skipContentModel
568
608
  },
569
609
  {
570
610
  title: "Importing Tags",
571
- task: (0, import_listr2.wrapTask)(async (ctx, task) => {
572
- const tags2 = await createEntities({
573
- context: { target: ctx.environment, type: "Tag" },
574
- entities: sourceData.tags,
575
- destinationEntitiesById: destinationDataById.tags,
576
- requestQueue
577
- });
578
- ctx.data.tags = tags2;
611
+ task: (0, import_listr2.wrapTask)(async (ctx) => {
612
+ if (sourceData.tags && destinationDataById.tags) {
613
+ const tags2 = await createEntities({
614
+ context: { target: ctx.environment, type: "Tag" },
615
+ entities: sourceData.tags,
616
+ destinationEntitiesById: destinationDataById.tags,
617
+ requestQueue
618
+ });
619
+ ctx.data.tags = tags2;
620
+ }
579
621
  }),
580
622
  // we remove `tags` from destination data if an error was thrown trying to access them
581
623
  // this means the user doesn't have access to this feature, skip importing tags
@@ -583,8 +625,11 @@ function pushToSpace({
583
625
  },
584
626
  {
585
627
  title: "Importing Editor Interfaces",
586
- task: (0, import_listr2.wrapTask)(async (ctx, task) => {
628
+ task: (0, import_listr2.wrapTask)(async (ctx) => {
587
629
  const allEditorInterfacesBeingFetched = ctx.data.contentTypes.map(async (contentType) => {
630
+ if (!sourceData.editorInterfaces) {
631
+ return;
632
+ }
588
633
  const editorInterface = sourceData.editorInterfaces.find((editorInterface2) => {
589
634
  return editorInterface2.sys.contentType.sys.id === contentType.sys.id;
590
635
  });
@@ -600,7 +645,9 @@ function pushToSpace({
600
645
  const updatedEditorInterface = await requestQueue.add(() => ctEditorInterface.update());
601
646
  return updatedEditorInterface;
602
647
  } catch (err) {
603
- err.entity = editorInterface;
648
+ if (err instanceof ContentfulEntityError) {
649
+ err.entity = editorInterface;
650
+ }
604
651
  throw err;
605
652
  }
606
653
  });
@@ -612,7 +659,7 @@ function pushToSpace({
612
659
  },
613
660
  {
614
661
  title: "Uploading Assets",
615
- task: (0, import_listr2.wrapTask)(async (ctx, task) => {
662
+ task: (0, import_listr2.wrapTask)(async (ctx) => {
616
663
  const allPendingUploads = [];
617
664
  for (const asset of sourceData.assets) {
618
665
  for (const file of Object.values(asset.transformed.fields.file)) {
@@ -642,11 +689,14 @@ function pushToSpace({
642
689
  const uploads = await Promise.all(allPendingUploads);
643
690
  ctx.data.uploadedAssetFiles = uploads;
644
691
  }),
645
- skip: (ctx) => !uploadAssets || !sourceData.assets.length
692
+ skip: () => !uploadAssets || !sourceData.assets.length
646
693
  },
647
694
  {
648
695
  title: "Importing Assets",
649
- task: (0, import_listr2.wrapTask)(async (ctx, task) => {
696
+ task: (0, import_listr2.wrapTask)(async (ctx) => {
697
+ if (!destinationDataById.assets) {
698
+ return;
699
+ }
650
700
  const assetsToProcess = await createEntities({
651
701
  context: { target: ctx.environment, type: "Asset" },
652
702
  entities: sourceData.assets,
@@ -661,11 +711,11 @@ function pushToSpace({
661
711
  });
662
712
  ctx.data.assets = processedAssets;
663
713
  }),
664
- skip: (ctx) => contentModelOnly
714
+ skip: () => contentModelOnly
665
715
  },
666
716
  {
667
717
  title: "Publishing Assets",
668
- task: (0, import_listr2.wrapTask)(async (ctx, task) => {
718
+ task: (0, import_listr2.wrapTask)(async (ctx) => {
669
719
  const publishedAssets = await publishEntities2({
670
720
  entities: ctx.data.assets,
671
721
  sourceEntities: sourceData.assets,
@@ -673,11 +723,11 @@ function pushToSpace({
673
723
  });
674
724
  ctx.data.publishedAssets = publishedAssets;
675
725
  }),
676
- skip: (ctx) => contentModelOnly || skipContentPublishing
726
+ skip: () => contentModelOnly || skipContentPublishing
677
727
  },
678
728
  {
679
729
  title: "Archiving Assets",
680
- task: (0, import_listr2.wrapTask)(async (ctx, task) => {
730
+ task: (0, import_listr2.wrapTask)(async (ctx) => {
681
731
  const archivedAssets = await archiveEntities2({
682
732
  entities: ctx.data.assets,
683
733
  sourceEntities: sourceData.assets,
@@ -685,11 +735,11 @@ function pushToSpace({
685
735
  });
686
736
  ctx.data.archivedAssets = archivedAssets;
687
737
  }),
688
- skip: (ctx) => contentModelOnly || skipContentPublishing
738
+ skip: () => contentModelOnly || skipContentPublishing
689
739
  },
690
740
  {
691
741
  title: "Importing Content Entries",
692
- task: (0, import_listr2.wrapTask)(async (ctx, task) => {
742
+ task: (0, import_listr2.wrapTask)(async (ctx) => {
693
743
  const entries2 = await createEntries({
694
744
  context: { target: ctx.environment, skipContentModel },
695
745
  entities: sourceData.entries,
@@ -698,11 +748,11 @@ function pushToSpace({
698
748
  });
699
749
  ctx.data.entries = entries2;
700
750
  }),
701
- skip: (ctx) => contentModelOnly
751
+ skip: () => contentModelOnly
702
752
  },
703
753
  {
704
754
  title: "Publishing Content Entries",
705
- task: (0, import_listr2.wrapTask)(async (ctx, task) => {
755
+ task: (0, import_listr2.wrapTask)(async (ctx) => {
706
756
  const publishedEntries = await publishEntities2({
707
757
  entities: ctx.data.entries,
708
758
  sourceEntities: sourceData.entries,
@@ -710,11 +760,11 @@ function pushToSpace({
710
760
  });
711
761
  ctx.data.publishedEntries = publishedEntries;
712
762
  }),
713
- skip: (ctx) => contentModelOnly || skipContentPublishing
763
+ skip: () => contentModelOnly || skipContentPublishing
714
764
  },
715
765
  {
716
766
  title: "Archiving Entries",
717
- task: (0, import_listr2.wrapTask)(async (ctx, task) => {
767
+ task: (0, import_listr2.wrapTask)(async (ctx) => {
718
768
  const archivedEntries = await archiveEntities2({
719
769
  entities: ctx.data.entries,
720
770
  sourceEntities: sourceData.entries,
@@ -722,11 +772,14 @@ function pushToSpace({
722
772
  });
723
773
  ctx.data.archivedEntries = archivedEntries;
724
774
  }),
725
- skip: (ctx) => contentModelOnly || skipContentPublishing
775
+ skip: () => contentModelOnly || skipContentPublishing
726
776
  },
727
777
  {
728
778
  title: "Creating Web Hooks",
729
- task: (0, import_listr2.wrapTask)(async (ctx, task) => {
779
+ task: (0, import_listr2.wrapTask)(async (ctx) => {
780
+ if (!sourceData.webhooks || !destinationDataById.webhooks) {
781
+ return;
782
+ }
730
783
  const webhooks2 = await createEntities({
731
784
  context: { target: ctx.space, type: "Webhook" },
732
785
  entities: sourceData.webhooks,
@@ -735,7 +788,7 @@ function pushToSpace({
735
788
  });
736
789
  ctx.data.webhooks = webhooks2;
737
790
  }),
738
- skip: (ctx) => contentModelOnly || environmentId !== "master" && "Webhooks can only be imported in master environment"
791
+ skip: () => contentModelOnly || environmentId !== "master" && "Webhooks can only be imported in master environment"
739
792
  }
740
793
  ], listrOptions);
741
794
  }
@@ -750,10 +803,10 @@ function publishEntities2({ entities, sourceEntities, requestQueue }) {
750
803
  return publishEntities({ entities: entitiesToPublish, requestQueue });
751
804
  }
752
805
 
753
- // lib/transform/transform-space.js
806
+ // lib/transform/transform-space.ts
754
807
  var import_object3 = require("lodash/object");
755
808
 
756
- // lib/transform/transformers.js
809
+ // lib/transform/transformers.ts
757
810
  var transformers_exports = {};
758
811
  __export(transformers_exports, {
759
812
  assets: () => assets,
@@ -818,7 +871,7 @@ function removeMetadataTags(entity, tagsEnabled = false) {
818
871
  return entity;
819
872
  }
820
873
 
821
- // lib/utils/sort-entries.js
874
+ // lib/utils/sort-entries.ts
822
875
  var import_collection3 = require("lodash/collection");
823
876
  var _o = __toESM(require("lodash/object"));
824
877
  var import_array = require("lodash/array");
@@ -888,13 +941,13 @@ function merge(left, right, compareFn) {
888
941
  }
889
942
  }
890
943
  if (left.length)
891
- result.push.apply(result, left);
944
+ result.push(...left);
892
945
  if (right.length)
893
- result.push.apply(result, right);
946
+ result.push(...right);
894
947
  return result;
895
948
  }
896
949
 
897
- // lib/utils/sort-locales.js
950
+ // lib/utils/sort-locales.ts
898
951
  function sortLocales(locales2) {
899
952
  const localeByFallback = {};
900
953
  locales2.forEach((locale) => {
@@ -909,12 +962,14 @@ function sortLocales(locales2) {
909
962
  return sortByFallbackKey(localeByFallback);
910
963
  }
911
964
  function sortByFallbackKey(localeByFallback, key) {
912
- if (!localeByFallback[key]) {
965
+ if (!localeByFallback[`${key}`]) {
913
966
  return [];
914
967
  }
915
- const sortedLocales = localeByFallback[key];
968
+ const sortedLocales = localeByFallback[`${key}`];
916
969
  sortedLocales.forEach((locale) => {
917
- sortByFallbackKey(localeByFallback, locale.code).forEach((x) => sortedLocales.push(x));
970
+ sortByFallbackKey(localeByFallback, locale.code).forEach(
971
+ (x) => sortedLocales.push(x)
972
+ );
918
973
  });
919
974
  sortedLocales.forEach((locale) => {
920
975
  if (!locale.fallbackCode) {
@@ -924,7 +979,7 @@ function sortByFallbackKey(localeByFallback, key) {
924
979
  return sortedLocales;
925
980
  }
926
981
 
927
- // lib/transform/transform-space.js
982
+ // lib/transform/transform-space.ts
928
983
  var spaceEntities = [
929
984
  "contentTypes",
930
985
  "entries",
@@ -949,7 +1004,7 @@ function transform_space_default(sourceData, destinationData, customTransformers
949
1004
  }, baseSpaceData);
950
1005
  }
951
1006
 
952
- // lib/utils/schema.js
1007
+ // lib/utils/schema.ts
953
1008
  var import_joi = __toESM(require("joi"));
954
1009
  var entrySchema = {
955
1010
  sys: import_joi.default.object(),
@@ -1021,7 +1076,7 @@ var payloadSchema = import_joi.default.object({
1021
1076
  webhooks: import_joi.default.array().items(webhookSchema)
1022
1077
  });
1023
1078
 
1024
- // lib/utils/validations.js
1079
+ // lib/utils/validations.ts
1025
1080
  var import_get_entity_name4 = __toESM(require("contentful-batch-libs/dist/get-entity-name"));
1026
1081
  var attachEntityName = (details, payload) => {
1027
1082
  details.map((detail) => {
@@ -1048,7 +1103,7 @@ var assertPayload = (payload) => {
1048
1103
  attachEntityName(result.error.details, payload);
1049
1104
  const invalidEntityCount = countInvalidEntities(result.error.details).join(", ");
1050
1105
  result.error.message = `${invalidEntityCount} - Get further details in the error log file`;
1051
- delete result.error._object;
1106
+ delete result.error._original;
1052
1107
  throw result.error;
1053
1108
  }
1054
1109
  };
@@ -1070,7 +1125,7 @@ var assertDefaultLocale = (source, destination) => {
1070
1125
  }
1071
1126
  };
1072
1127
 
1073
- // lib/parseOptions.js
1128
+ // lib/parseOptions.ts
1074
1129
  var import_fs2 = __toESM(require("fs"));
1075
1130
  var import_path2 = require("path");
1076
1131
  var import_format = __toESM(require("date-fns/format"));
@@ -1078,7 +1133,7 @@ var import_format = __toESM(require("date-fns/format"));
1078
1133
  // package.json
1079
1134
  var version = "0.0.0-determined-by-semantic-release";
1080
1135
 
1081
- // lib/utils/headers.js
1136
+ // lib/utils/headers.ts
1082
1137
  function getHeadersConfig(value) {
1083
1138
  if (!value) {
1084
1139
  return {};
@@ -1099,7 +1154,7 @@ function getHeadersConfig(value) {
1099
1154
  }, {});
1100
1155
  }
1101
1156
 
1102
- // lib/parseOptions.js
1157
+ // lib/parseOptions.ts
1103
1158
  var import_proxy = require("contentful-batch-libs/dist/proxy");
1104
1159
  var import_add_sequence_header = __toESM(require("contentful-batch-libs/dist/add-sequence-header"));
1105
1160
  var import_json_ext = require("@discoveryjs/json-ext");
@@ -1222,7 +1277,7 @@ async function runContentfulImport(params) {
1222
1277
  const tasks = new import_listr3.default([
1223
1278
  {
1224
1279
  title: "Validating content-file",
1225
- task: (ctx) => {
1280
+ task: () => {
1226
1281
  assertPayload(options.content);
1227
1282
  }
1228
1283
  },
@@ -1234,7 +1289,7 @@ async function runContentfulImport(params) {
1234
1289
  },
1235
1290
  {
1236
1291
  title: "Checking if destination space already has any content and retrieving it",
1237
- task: (0, import_listr4.wrapTask)(async (ctx, task) => {
1292
+ task: (0, import_listr4.wrapTask)(async (ctx) => {
1238
1293
  const destinationData = await getDestinationData({
1239
1294
  client: ctx.client,
1240
1295
  spaceId: options.spaceId,
@@ -1258,7 +1313,7 @@ async function runContentfulImport(params) {
1258
1313
  },
1259
1314
  {
1260
1315
  title: "Push content to destination space",
1261
- task: (ctx, task) => {
1316
+ task: (ctx) => {
1262
1317
  return pushToSpace({
1263
1318
  sourceData: ctx.sourceData,
1264
1319
  destinationData: ctx.destinationData,
@@ -1311,7 +1366,7 @@ async function runContentfulImport(params) {
1311
1366
  (0, import_logging7.displayErrorLog)(displayLog);
1312
1367
  if (errorLog.length) {
1313
1368
  return (0, import_logging7.writeErrorLogFile)(options.errorLogFile, errorLog).then(() => {
1314
- const multiError = new Error("Errors occurred");
1369
+ const multiError = new ContentfulMultiError("Errors occurred");
1315
1370
  multiError.name = "ContentfulMultiError";
1316
1371
  multiError.errors = errorLog;
1317
1372
  throw multiError;
package/dist/index.mjs CHANGED
@@ -23,7 +23,7 @@ import PQueue from "p-queue";
23
23
  import { displayErrorLog, setupLogging, writeErrorLogFile } from "contentful-batch-libs/dist/logging";
24
24
  import { wrapTask as wrapTask2 } from "contentful-batch-libs/dist/listr";
25
25
 
26
- // lib/tasks/init-client.js
26
+ // lib/tasks/init-client.ts
27
27
  import { createClient } from "contentful-management";
28
28
  import { logEmitter } from "contentful-batch-libs/dist/logging";
29
29
  function logHandler(level, data) {
@@ -41,7 +41,7 @@ function initClient(opts) {
41
41
  return createClient(config);
42
42
  }
43
43
 
44
- // lib/tasks/get-destination-data.js
44
+ // lib/tasks/get-destination-data.ts
45
45
  import Promise2 from "bluebird";
46
46
  import { logEmitter as logEmitter2 } from "contentful-batch-libs/dist/logging";
47
47
  var BATCH_CHAR_LIMIT = 1990;
@@ -113,59 +113,81 @@ async function getDestinationData({
113
113
  ...sourceData
114
114
  };
115
115
  if (!skipContentModel) {
116
- const contentTypeIds = sourceData.contentTypes.map((e) => e.sys.id);
117
- result.contentTypes = batchedIdQuery({
118
- environment,
119
- type: "contentTypes",
120
- ids: contentTypeIds,
121
- requestQueue
122
- });
123
- if (!skipLocales) {
124
- const localeIds = sourceData.locales.map((e) => e.sys.id);
125
- result.locales = batchedIdQuery({
116
+ const contentTypeIds = sourceData.contentTypes?.map((e) => e.sys.id);
117
+ if (contentTypeIds) {
118
+ result.contentTypes = batchedIdQuery({
126
119
  environment,
127
- type: "locales",
128
- ids: localeIds,
120
+ type: "contentTypes",
121
+ ids: contentTypeIds,
129
122
  requestQueue
130
123
  });
131
124
  }
125
+ if (!skipLocales) {
126
+ const localeIds = sourceData.locales?.map((e) => e.sys.id);
127
+ if (localeIds) {
128
+ result.locales = batchedIdQuery({
129
+ environment,
130
+ type: "locales",
131
+ ids: localeIds,
132
+ requestQueue
133
+ });
134
+ }
135
+ }
132
136
  }
133
- result.tags = environment.getTags().then((response) => response.items).catch((e) => {
137
+ result.tags = environment.getTags().then((response) => response.items).catch(() => {
134
138
  delete result.tags;
135
139
  });
136
140
  if (contentModelOnly) {
137
141
  return Promise2.props(result);
138
142
  }
139
- const entryIds = sourceData.entries.map((e) => e.sys.id);
140
- const assetIds = sourceData.assets.map((e) => e.sys.id);
141
- result.entries = batchedIdQuery({
142
- environment,
143
- type: "entries",
144
- ids: entryIds,
145
- requestQueue
146
- });
147
- result.assets = batchedIdQuery({
148
- environment,
149
- type: "assets",
150
- ids: assetIds,
151
- requestQueue
152
- });
143
+ const entryIds = sourceData.entries?.map((e) => e.sys.id);
144
+ const assetIds = sourceData.assets?.map((e) => e.sys.id);
145
+ if (entryIds) {
146
+ result.entries = batchedIdQuery({
147
+ environment,
148
+ type: "entries",
149
+ ids: entryIds,
150
+ requestQueue
151
+ });
152
+ }
153
+ if (assetIds) {
154
+ result.assets = batchedIdQuery({
155
+ environment,
156
+ type: "assets",
157
+ ids: assetIds,
158
+ requestQueue
159
+ });
160
+ }
153
161
  result.webhooks = [];
154
162
  return Promise2.props(result);
155
163
  }
156
164
 
157
- // lib/tasks/push-to-space/push-to-space.js
165
+ // lib/tasks/push-to-space/push-to-space.ts
158
166
  import Listr from "listr";
159
167
  import verboseRenderer from "listr-verbose-renderer";
160
168
  import { logEmitter as logEmitter6 } from "contentful-batch-libs/dist/logging";
161
169
  import { wrapTask } from "contentful-batch-libs/dist/listr";
162
170
 
163
- // lib/tasks/push-to-space/assets.js
171
+ // lib/tasks/push-to-space/assets.ts
164
172
  import fs from "fs";
165
173
  import { join } from "path";
166
174
  import { promisify } from "util";
167
175
  import getEntityName from "contentful-batch-libs/dist/get-entity-name";
168
176
  import { logEmitter as logEmitter3 } from "contentful-batch-libs/dist/logging";
177
+
178
+ // lib/utils/errors.ts
179
+ var ContentfulAssetError = class extends Error {
180
+ constructor(message, filePath) {
181
+ super(message);
182
+ this.filePath = filePath;
183
+ }
184
+ };
185
+ var ContentfulEntityError = class extends Error {
186
+ };
187
+ var ContentfulMultiError = class extends Error {
188
+ };
189
+
190
+ // lib/tasks/push-to-space/assets.ts
169
191
  var stat = promisify(fs.stat);
170
192
  async function getAssetStreamForURL(url, assetsDirectory) {
171
193
  const [, assetPath] = url.split("//");
@@ -174,8 +196,10 @@ async function getAssetStreamForURL(url, assetsDirectory) {
174
196
  await stat(filePath);
175
197
  return fs.createReadStream(filePath);
176
198
  } catch (err) {
177
- const error = new Error("Cannot open asset from filesystem");
178
- error.filePath = filePath;
199
+ const error = new ContentfulAssetError(
200
+ "Cannot open asset from filesystem",
201
+ filePath
202
+ );
179
203
  throw error;
180
204
  }
181
205
  }
@@ -183,7 +207,9 @@ async function processAssetForLocale(locale, asset, processingOptions) {
183
207
  try {
184
208
  return await asset.processForLocale(locale, processingOptions);
185
209
  } catch (err) {
186
- err.entity = asset;
210
+ if (err instanceof ContentfulEntityError) {
211
+ err.entity = asset;
212
+ }
187
213
  logEmitter3.emit("error", err);
188
214
  throw err;
189
215
  }
@@ -233,7 +259,7 @@ async function processAssets({
233
259
  return potentiallyProcessedAssets.filter((asset) => asset);
234
260
  }
235
261
 
236
- // lib/tasks/push-to-space/creation.js
262
+ // lib/tasks/push-to-space/creation.ts
237
263
  import { find } from "lodash/collection";
238
264
  import { assign, get, omitBy, omit } from "lodash/object";
239
265
  import getEntityName2 from "contentful-batch-libs/dist/get-entity-name";
@@ -302,12 +328,16 @@ async function createEntry({ entry, target, skipContentModel, destinationEntitie
302
328
  creationSuccessNotifier(operation, createdOrUpdatedEntry);
303
329
  return createdOrUpdatedEntry;
304
330
  } catch (err) {
305
- if (skipContentModel && err.name === "UnknownField") {
306
- const errors = get(JSON.parse(err.message), "details.errors");
307
- entry.transformed.fields = cleanupUnknownFields(entry.transformed.fields, errors);
308
- return createEntry({ entry, target, skipContentModel, destinationEntitiesById, requestQueue });
331
+ if (err instanceof Error) {
332
+ if (skipContentModel && err.name === "UnknownField") {
333
+ const errors = get(JSON.parse(err.message), "details.errors");
334
+ entry.transformed.fields = cleanupUnknownFields(entry.transformed.fields, errors);
335
+ return createEntry({ entry, target, skipContentModel, destinationEntitiesById, requestQueue });
336
+ }
337
+ }
338
+ if (err instanceof ContentfulEntityError) {
339
+ err.entity = entry;
309
340
  }
310
- err.entity = entry;
311
341
  logEmitter4.emit("error", err);
312
342
  return null;
313
343
  }
@@ -369,7 +399,7 @@ function getPlainData(entity) {
369
399
  return omit(data, "sys");
370
400
  }
371
401
 
372
- // lib/tasks/push-to-space/publishing.js
402
+ // lib/tasks/push-to-space/publishing.ts
373
403
  import getEntityName3 from "contentful-batch-libs/dist/get-entity-name";
374
404
  import { logEmitter as logEmitter5 } from "contentful-batch-libs/dist/logging";
375
405
  async function publishEntities({ entities, requestQueue }) {
@@ -412,7 +442,9 @@ async function archiveEntities({ entities, requestQueue }) {
412
442
  const archivedEntity = await entity2.archive();
413
443
  return archivedEntity;
414
444
  } catch (err) {
415
- err.entity = entity2;
445
+ if (err instanceof ContentfulEntityError) {
446
+ err.entity = entity2;
447
+ }
416
448
  logEmitter5.emit("error", err);
417
449
  return null;
418
450
  }
@@ -431,7 +463,9 @@ async function runQueue(queue, result = [], requestQueue) {
431
463
  const publishedEntity = await requestQueue.add(() => entity.publish());
432
464
  publishedEntities.push(publishedEntity);
433
465
  } catch (err) {
434
- err.entity = entity;
466
+ if (err instanceof ContentfulEntityError) {
467
+ err.entity = entity;
468
+ }
435
469
  logEmitter5.emit("error", err);
436
470
  }
437
471
  }
@@ -452,7 +486,7 @@ async function runQueue(queue, result = [], requestQueue) {
452
486
  return result;
453
487
  }
454
488
 
455
- // lib/tasks/push-to-space/push-to-space.js
489
+ // lib/tasks/push-to-space/push-to-space.ts
456
490
  var DEFAULT_CONTENT_STRUCTURE = {
457
491
  entries: [],
458
492
  assets: [],
@@ -501,7 +535,7 @@ function pushToSpace({
501
535
  return new Listr([
502
536
  {
503
537
  title: "Connecting to space",
504
- task: wrapTask(async (ctx, task) => {
538
+ task: wrapTask(async (ctx) => {
505
539
  const space = await client.getSpace(spaceId);
506
540
  const environment = await space.getEnvironment(environmentId);
507
541
  ctx.space = space;
@@ -510,7 +544,10 @@ function pushToSpace({
510
544
  },
511
545
  {
512
546
  title: "Importing Locales",
513
- task: wrapTask(async (ctx, task) => {
547
+ task: wrapTask(async (ctx) => {
548
+ if (!destinationDataById.locales) {
549
+ return;
550
+ }
514
551
  const locales2 = await createLocales({
515
552
  context: { target: ctx.environment, type: "Locale" },
516
553
  entities: sourceData.locales,
@@ -523,7 +560,10 @@ function pushToSpace({
523
560
  },
524
561
  {
525
562
  title: "Importing Content Types",
526
- task: wrapTask(async (ctx, task) => {
563
+ task: wrapTask(async (ctx) => {
564
+ if (!destinationDataById.contentTypes) {
565
+ return;
566
+ }
527
567
  const contentTypes2 = await createEntities({
528
568
  context: { target: ctx.environment, type: "ContentType" },
529
569
  entities: sourceData.contentTypes,
@@ -536,7 +576,7 @@ function pushToSpace({
536
576
  },
537
577
  {
538
578
  title: "Publishing Content Types",
539
- task: wrapTask(async (ctx, task) => {
579
+ task: wrapTask(async (ctx) => {
540
580
  const publishedContentTypes = await publishEntities2({
541
581
  entities: ctx.data.contentTypes,
542
582
  sourceEntities: sourceData.contentTypes,
@@ -544,18 +584,20 @@ function pushToSpace({
544
584
  });
545
585
  ctx.data.contentTypes = publishedContentTypes;
546
586
  }),
547
- skip: (ctx) => skipContentModel
587
+ skip: () => skipContentModel
548
588
  },
549
589
  {
550
590
  title: "Importing Tags",
551
- task: wrapTask(async (ctx, task) => {
552
- const tags2 = await createEntities({
553
- context: { target: ctx.environment, type: "Tag" },
554
- entities: sourceData.tags,
555
- destinationEntitiesById: destinationDataById.tags,
556
- requestQueue
557
- });
558
- ctx.data.tags = tags2;
591
+ task: wrapTask(async (ctx) => {
592
+ if (sourceData.tags && destinationDataById.tags) {
593
+ const tags2 = await createEntities({
594
+ context: { target: ctx.environment, type: "Tag" },
595
+ entities: sourceData.tags,
596
+ destinationEntitiesById: destinationDataById.tags,
597
+ requestQueue
598
+ });
599
+ ctx.data.tags = tags2;
600
+ }
559
601
  }),
560
602
  // we remove `tags` from destination data if an error was thrown trying to access them
561
603
  // this means the user doesn't have access to this feature, skip importing tags
@@ -563,8 +605,11 @@ function pushToSpace({
563
605
  },
564
606
  {
565
607
  title: "Importing Editor Interfaces",
566
- task: wrapTask(async (ctx, task) => {
608
+ task: wrapTask(async (ctx) => {
567
609
  const allEditorInterfacesBeingFetched = ctx.data.contentTypes.map(async (contentType) => {
610
+ if (!sourceData.editorInterfaces) {
611
+ return;
612
+ }
568
613
  const editorInterface = sourceData.editorInterfaces.find((editorInterface2) => {
569
614
  return editorInterface2.sys.contentType.sys.id === contentType.sys.id;
570
615
  });
@@ -580,7 +625,9 @@ function pushToSpace({
580
625
  const updatedEditorInterface = await requestQueue.add(() => ctEditorInterface.update());
581
626
  return updatedEditorInterface;
582
627
  } catch (err) {
583
- err.entity = editorInterface;
628
+ if (err instanceof ContentfulEntityError) {
629
+ err.entity = editorInterface;
630
+ }
584
631
  throw err;
585
632
  }
586
633
  });
@@ -592,7 +639,7 @@ function pushToSpace({
592
639
  },
593
640
  {
594
641
  title: "Uploading Assets",
595
- task: wrapTask(async (ctx, task) => {
642
+ task: wrapTask(async (ctx) => {
596
643
  const allPendingUploads = [];
597
644
  for (const asset of sourceData.assets) {
598
645
  for (const file of Object.values(asset.transformed.fields.file)) {
@@ -622,11 +669,14 @@ function pushToSpace({
622
669
  const uploads = await Promise.all(allPendingUploads);
623
670
  ctx.data.uploadedAssetFiles = uploads;
624
671
  }),
625
- skip: (ctx) => !uploadAssets || !sourceData.assets.length
672
+ skip: () => !uploadAssets || !sourceData.assets.length
626
673
  },
627
674
  {
628
675
  title: "Importing Assets",
629
- task: wrapTask(async (ctx, task) => {
676
+ task: wrapTask(async (ctx) => {
677
+ if (!destinationDataById.assets) {
678
+ return;
679
+ }
630
680
  const assetsToProcess = await createEntities({
631
681
  context: { target: ctx.environment, type: "Asset" },
632
682
  entities: sourceData.assets,
@@ -641,11 +691,11 @@ function pushToSpace({
641
691
  });
642
692
  ctx.data.assets = processedAssets;
643
693
  }),
644
- skip: (ctx) => contentModelOnly
694
+ skip: () => contentModelOnly
645
695
  },
646
696
  {
647
697
  title: "Publishing Assets",
648
- task: wrapTask(async (ctx, task) => {
698
+ task: wrapTask(async (ctx) => {
649
699
  const publishedAssets = await publishEntities2({
650
700
  entities: ctx.data.assets,
651
701
  sourceEntities: sourceData.assets,
@@ -653,11 +703,11 @@ function pushToSpace({
653
703
  });
654
704
  ctx.data.publishedAssets = publishedAssets;
655
705
  }),
656
- skip: (ctx) => contentModelOnly || skipContentPublishing
706
+ skip: () => contentModelOnly || skipContentPublishing
657
707
  },
658
708
  {
659
709
  title: "Archiving Assets",
660
- task: wrapTask(async (ctx, task) => {
710
+ task: wrapTask(async (ctx) => {
661
711
  const archivedAssets = await archiveEntities2({
662
712
  entities: ctx.data.assets,
663
713
  sourceEntities: sourceData.assets,
@@ -665,11 +715,11 @@ function pushToSpace({
665
715
  });
666
716
  ctx.data.archivedAssets = archivedAssets;
667
717
  }),
668
- skip: (ctx) => contentModelOnly || skipContentPublishing
718
+ skip: () => contentModelOnly || skipContentPublishing
669
719
  },
670
720
  {
671
721
  title: "Importing Content Entries",
672
- task: wrapTask(async (ctx, task) => {
722
+ task: wrapTask(async (ctx) => {
673
723
  const entries2 = await createEntries({
674
724
  context: { target: ctx.environment, skipContentModel },
675
725
  entities: sourceData.entries,
@@ -678,11 +728,11 @@ function pushToSpace({
678
728
  });
679
729
  ctx.data.entries = entries2;
680
730
  }),
681
- skip: (ctx) => contentModelOnly
731
+ skip: () => contentModelOnly
682
732
  },
683
733
  {
684
734
  title: "Publishing Content Entries",
685
- task: wrapTask(async (ctx, task) => {
735
+ task: wrapTask(async (ctx) => {
686
736
  const publishedEntries = await publishEntities2({
687
737
  entities: ctx.data.entries,
688
738
  sourceEntities: sourceData.entries,
@@ -690,11 +740,11 @@ function pushToSpace({
690
740
  });
691
741
  ctx.data.publishedEntries = publishedEntries;
692
742
  }),
693
- skip: (ctx) => contentModelOnly || skipContentPublishing
743
+ skip: () => contentModelOnly || skipContentPublishing
694
744
  },
695
745
  {
696
746
  title: "Archiving Entries",
697
- task: wrapTask(async (ctx, task) => {
747
+ task: wrapTask(async (ctx) => {
698
748
  const archivedEntries = await archiveEntities2({
699
749
  entities: ctx.data.entries,
700
750
  sourceEntities: sourceData.entries,
@@ -702,11 +752,14 @@ function pushToSpace({
702
752
  });
703
753
  ctx.data.archivedEntries = archivedEntries;
704
754
  }),
705
- skip: (ctx) => contentModelOnly || skipContentPublishing
755
+ skip: () => contentModelOnly || skipContentPublishing
706
756
  },
707
757
  {
708
758
  title: "Creating Web Hooks",
709
- task: wrapTask(async (ctx, task) => {
759
+ task: wrapTask(async (ctx) => {
760
+ if (!sourceData.webhooks || !destinationDataById.webhooks) {
761
+ return;
762
+ }
710
763
  const webhooks2 = await createEntities({
711
764
  context: { target: ctx.space, type: "Webhook" },
712
765
  entities: sourceData.webhooks,
@@ -715,7 +768,7 @@ function pushToSpace({
715
768
  });
716
769
  ctx.data.webhooks = webhooks2;
717
770
  }),
718
- skip: (ctx) => contentModelOnly || environmentId !== "master" && "Webhooks can only be imported in master environment"
771
+ skip: () => contentModelOnly || environmentId !== "master" && "Webhooks can only be imported in master environment"
719
772
  }
720
773
  ], listrOptions);
721
774
  }
@@ -730,10 +783,10 @@ function publishEntities2({ entities, sourceEntities, requestQueue }) {
730
783
  return publishEntities({ entities: entitiesToPublish, requestQueue });
731
784
  }
732
785
 
733
- // lib/transform/transform-space.js
786
+ // lib/transform/transform-space.ts
734
787
  import { omit as omit3, defaults } from "lodash/object";
735
788
 
736
- // lib/transform/transformers.js
789
+ // lib/transform/transformers.ts
737
790
  var transformers_exports = {};
738
791
  __export(transformers_exports, {
739
792
  assets: () => assets,
@@ -798,7 +851,7 @@ function removeMetadataTags(entity, tagsEnabled = false) {
798
851
  return entity;
799
852
  }
800
853
 
801
- // lib/utils/sort-entries.js
854
+ // lib/utils/sort-entries.ts
802
855
  import { some, filter, map } from "lodash/collection";
803
856
  import * as _o from "lodash/object";
804
857
  import { flatten } from "lodash/array";
@@ -868,13 +921,13 @@ function merge(left, right, compareFn) {
868
921
  }
869
922
  }
870
923
  if (left.length)
871
- result.push.apply(result, left);
924
+ result.push(...left);
872
925
  if (right.length)
873
- result.push.apply(result, right);
926
+ result.push(...right);
874
927
  return result;
875
928
  }
876
929
 
877
- // lib/utils/sort-locales.js
930
+ // lib/utils/sort-locales.ts
878
931
  function sortLocales(locales2) {
879
932
  const localeByFallback = {};
880
933
  locales2.forEach((locale) => {
@@ -889,12 +942,14 @@ function sortLocales(locales2) {
889
942
  return sortByFallbackKey(localeByFallback);
890
943
  }
891
944
  function sortByFallbackKey(localeByFallback, key) {
892
- if (!localeByFallback[key]) {
945
+ if (!localeByFallback[`${key}`]) {
893
946
  return [];
894
947
  }
895
- const sortedLocales = localeByFallback[key];
948
+ const sortedLocales = localeByFallback[`${key}`];
896
949
  sortedLocales.forEach((locale) => {
897
- sortByFallbackKey(localeByFallback, locale.code).forEach((x) => sortedLocales.push(x));
950
+ sortByFallbackKey(localeByFallback, locale.code).forEach(
951
+ (x) => sortedLocales.push(x)
952
+ );
898
953
  });
899
954
  sortedLocales.forEach((locale) => {
900
955
  if (!locale.fallbackCode) {
@@ -904,7 +959,7 @@ function sortByFallbackKey(localeByFallback, key) {
904
959
  return sortedLocales;
905
960
  }
906
961
 
907
- // lib/transform/transform-space.js
962
+ // lib/transform/transform-space.ts
908
963
  var spaceEntities = [
909
964
  "contentTypes",
910
965
  "entries",
@@ -929,7 +984,7 @@ function transform_space_default(sourceData, destinationData, customTransformers
929
984
  }, baseSpaceData);
930
985
  }
931
986
 
932
- // lib/utils/schema.js
987
+ // lib/utils/schema.ts
933
988
  import Joi from "joi";
934
989
  var entrySchema = {
935
990
  sys: Joi.object(),
@@ -1001,7 +1056,7 @@ var payloadSchema = Joi.object({
1001
1056
  webhooks: Joi.array().items(webhookSchema)
1002
1057
  });
1003
1058
 
1004
- // lib/utils/validations.js
1059
+ // lib/utils/validations.ts
1005
1060
  import getEntityName4 from "contentful-batch-libs/dist/get-entity-name";
1006
1061
  var attachEntityName = (details, payload) => {
1007
1062
  details.map((detail) => {
@@ -1028,7 +1083,7 @@ var assertPayload = (payload) => {
1028
1083
  attachEntityName(result.error.details, payload);
1029
1084
  const invalidEntityCount = countInvalidEntities(result.error.details).join(", ");
1030
1085
  result.error.message = `${invalidEntityCount} - Get further details in the error log file`;
1031
- delete result.error._object;
1086
+ delete result.error._original;
1032
1087
  throw result.error;
1033
1088
  }
1034
1089
  };
@@ -1050,7 +1105,7 @@ var assertDefaultLocale = (source, destination) => {
1050
1105
  }
1051
1106
  };
1052
1107
 
1053
- // lib/parseOptions.js
1108
+ // lib/parseOptions.ts
1054
1109
  import fs2 from "fs";
1055
1110
  import { resolve } from "path";
1056
1111
  import format from "date-fns/format";
@@ -1058,7 +1113,7 @@ import format from "date-fns/format";
1058
1113
  // package.json
1059
1114
  var version = "0.0.0-determined-by-semantic-release";
1060
1115
 
1061
- // lib/utils/headers.js
1116
+ // lib/utils/headers.ts
1062
1117
  function getHeadersConfig(value) {
1063
1118
  if (!value) {
1064
1119
  return {};
@@ -1079,7 +1134,7 @@ function getHeadersConfig(value) {
1079
1134
  }, {});
1080
1135
  }
1081
1136
 
1082
- // lib/parseOptions.js
1137
+ // lib/parseOptions.ts
1083
1138
  import { proxyStringToObject, agentFromProxy } from "contentful-batch-libs/dist/proxy";
1084
1139
  import addSequenceHeader from "contentful-batch-libs/dist/add-sequence-header";
1085
1140
  import { parseChunked } from "@discoveryjs/json-ext";
@@ -1202,7 +1257,7 @@ async function runContentfulImport(params) {
1202
1257
  const tasks = new Listr2([
1203
1258
  {
1204
1259
  title: "Validating content-file",
1205
- task: (ctx) => {
1260
+ task: () => {
1206
1261
  assertPayload(options.content);
1207
1262
  }
1208
1263
  },
@@ -1214,7 +1269,7 @@ async function runContentfulImport(params) {
1214
1269
  },
1215
1270
  {
1216
1271
  title: "Checking if destination space already has any content and retrieving it",
1217
- task: wrapTask2(async (ctx, task) => {
1272
+ task: wrapTask2(async (ctx) => {
1218
1273
  const destinationData = await getDestinationData({
1219
1274
  client: ctx.client,
1220
1275
  spaceId: options.spaceId,
@@ -1238,7 +1293,7 @@ async function runContentfulImport(params) {
1238
1293
  },
1239
1294
  {
1240
1295
  title: "Push content to destination space",
1241
- task: (ctx, task) => {
1296
+ task: (ctx) => {
1242
1297
  return pushToSpace({
1243
1298
  sourceData: ctx.sourceData,
1244
1299
  destinationData: ctx.destinationData,
@@ -1291,7 +1346,7 @@ async function runContentfulImport(params) {
1291
1346
  displayErrorLog(displayLog);
1292
1347
  if (errorLog.length) {
1293
1348
  return writeErrorLogFile(options.errorLogFile, errorLog).then(() => {
1294
- const multiError = new Error("Errors occurred");
1349
+ const multiError = new ContentfulMultiError("Errors occurred");
1295
1350
  multiError.name = "ContentfulMultiError";
1296
1351
  multiError.errors = errorLog;
1297
1352
  throw multiError;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contentful-import",
3
- "version": "9.2.1",
3
+ "version": "9.3.0",
4
4
  "description": "this tool allows you to import JSON dump exported by contentful-export",
5
5
  "main": "dist/index.mjs",
6
6
  "typings": "dist/index.d.ts",
@@ -19,9 +19,10 @@
19
19
  },
20
20
  "scripts": {
21
21
  "build": "tsup",
22
- "build:watch": "babel lib --out-dir dist --watch",
23
22
  "clean": "rimraf dist && rimraf coverage",
24
- "lint": "eslint lib bin/contentful-import test",
23
+ "lint": "npm run lint:main && npm run lint:tests",
24
+ "lint:main": "eslint lib bin/contentful-import && tsc --project tsconfig.json",
25
+ "lint:tests": "eslint test && tsc --project tsconfig.test.json",
25
26
  "pretest": "npm run lint && npm run build",
26
27
  "test": "npm run test:unit && npm run test:integration",
27
28
  "test:unit": "jest --testPathPattern=test/unit --runInBand --coverage",
@@ -30,18 +31,7 @@
30
31
  "test:integration": "jest --testPathPattern=test/integration",
31
32
  "test:integration:debug": "node --inspect-brk ./node_modules/.bin/jest --runInBand --watch --testPathPattern=test/integration",
32
33
  "test:integration:watch": "npm run test:integration -- --watch",
33
- "test:simulate-ci": "trevor",
34
- "browser-coverage": "npm run test:cover && opener coverage/lcov-report/index.html",
35
34
  "semantic-release": "semantic-release",
36
- "devmanage:build": "pushd ../contentful-management.js && npm run build && popd",
37
- "devmanage:clean": "pushd ../contentful-management.js && npm run clean && popd",
38
- "devmanage:install": "npm run devmanage:build && rm -rf node_modules/contentful-management.js && npm install ../contentful-management.js && npm run devmanage:clean",
39
- "devmanage:uninstall": "npm run devmanage:clean && rimraf node_modules/contentful-management.js",
40
- "devdep:build": "pushd ../contentful-batch-libs && npm run build && popd",
41
- "devdep:clean": "pushd ../contentful-batch-libs && npm run clean && popd",
42
- "devdep:install": "npm run devdep:build && rm -rf node_modules/contentful-batch-libs && npm install ../contentful-batch-libs && npm run devdep:clean",
43
- "devdep:uninstall": "npm run devdep:clean && rimraf node_modules/contentful-batch-libs",
44
- "precommit": "npm run lint",
45
35
  "prepush": "npm run test:unit"
46
36
  },
47
37
  "repository": {
@@ -77,7 +67,7 @@
77
67
  "date-fns": "^2.30.0",
78
68
  "eslint": "^8.50.0",
79
69
  "eslint-config-standard": "^17.1.0",
80
- "joi": "^17.10.2",
70
+ "joi": "^17.11.0",
81
71
  "listr": "^0.14.1",
82
72
  "listr-update-renderer": "^0.5.0",
83
73
  "listr-verbose-renderer": "^0.6.0",
@@ -86,26 +76,21 @@
86
76
  "yargs": "^17.7.2"
87
77
  },
88
78
  "devDependencies": {
89
- "@babel/cli": "^7.23.0",
90
- "@babel/core": "^7.23.0",
91
- "@babel/plugin-proposal-object-rest-spread": "^7.20.7",
92
- "@babel/preset-env": "^7.22.20",
93
79
  "@types/jest": "^29.5.5",
94
80
  "@types/node": "^20.6.3",
95
- "@typescript-eslint/eslint-plugin": "^6.7.3",
96
- "@typescript-eslint/parser": "^6.7.2",
81
+ "@typescript-eslint/eslint-plugin": "^6.7.4",
82
+ "@typescript-eslint/parser": "^6.7.4",
97
83
  "babel-jest": "^29.7.0",
98
84
  "babel-plugin-add-module-exports": "^1.0.2",
99
85
  "babel-preset-env": "^1.7.0",
100
86
  "cz-conventional-changelog": "^3.1.0",
101
87
  "eslint-plugin-import": "^2.28.1",
102
- "eslint-plugin-jest": "^27.4.0",
88
+ "eslint-plugin-jest": "^27.4.2",
103
89
  "eslint-plugin-node": "^11.1.0",
104
90
  "eslint-plugin-promise": "^6.1.1",
105
91
  "eslint-plugin-standard": "^5.0.0",
106
- "husky": "^8.0.3",
107
92
  "jest": "^29.7.0",
108
- "rimraf": "^5.0.0",
93
+ "rimraf": "^5.0.5",
109
94
  "semantic-release": "^19.0.5",
110
95
  "ts-jest": "^29.1.1",
111
96
  "tsup": "^7.2.0",