contentful-import 10.1.1 → 10.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.
Files changed (3) hide show
  1. package/dist/index.js +280 -186
  2. package/dist/index.mjs +280 -186
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -58,13 +58,12 @@ function initClient(opts) {
58
58
  ...defaultOpts,
59
59
  ...opts
60
60
  };
61
- return (0, import_contentful_management.createClient)(config, { type: "legacy" });
62
- }
63
- function initPlainClient(opts) {
64
- return (0, import_contentful_management.createClient)({
65
- accessToken: opts.managementToken,
66
- host: opts.host,
67
- logHandler
61
+ return (0, import_contentful_management.createClient)(config, {
62
+ type: "plain",
63
+ defaults: {
64
+ spaceId: opts.spaceId,
65
+ environmentId: opts.environmentId
66
+ }
68
67
  });
69
68
  }
70
69
 
@@ -119,14 +118,14 @@ function isExoEntitlementError(err) {
119
118
  }
120
119
  }
121
120
  var EXO_M1_FEATURE = "exoM1";
122
- async function spaceHasExoM1Entitlement(plainClient, spaceId) {
121
+ async function spaceHasExoM1Entitlement(client, spaceId) {
123
122
  try {
124
- const space = await plainClient.space.get({ spaceId });
123
+ const space = await client.space.get({ spaceId });
125
124
  const organizationId = space.sys.organization?.sys?.id;
126
125
  if (!organizationId) {
127
126
  return null;
128
127
  }
129
- const entitlements = await plainClient.raw.get(
128
+ const entitlements = await client.raw.get(
130
129
  `/organizations/${organizationId}/organization_entitlement_set`
131
130
  );
132
131
  return entitlements.features?.[EXO_M1_FEATURE]?.value === true;
@@ -138,13 +137,6 @@ async function spaceHasExoM1Entitlement(plainClient, spaceId) {
138
137
  // lib/tasks/get-destination-data.ts
139
138
  var BATCH_CHAR_LIMIT = 1990;
140
139
  var BATCH_SIZE_LIMIT = 100;
141
- var OFFSET_QUERY_METHODS = {
142
- contentTypes: { name: "content types", method: "getContentTypes" },
143
- locales: { name: "locales", method: "getLocales" },
144
- entries: { name: "entries", method: "getEntries" },
145
- assets: { name: "assets", method: "getAssets" },
146
- tags: { name: "tags", method: "getTags" }
147
- };
148
140
  var CURSOR_QUERY_METHODS = {
149
141
  designTokens: { name: "design tokens", namespace: "designToken" },
150
142
  components: { name: "components", namespace: "component" },
@@ -153,47 +145,64 @@ var CURSOR_QUERY_METHODS = {
153
145
  dataAssemblies: { name: "data assemblies", namespace: "dataAssembly" },
154
146
  experiences: { name: "experiences", namespace: "experience" }
155
147
  };
156
- async function batchedIdQuery({ environment, type, ids, requestQueue }) {
157
- const method = OFFSET_QUERY_METHODS[type].method;
158
- const entityTypeName = OFFSET_QUERY_METHODS[type].name;
148
+ var ENTITY_METHODS = {
149
+ contentTypes: { name: "content types", ns: "contentType" },
150
+ entries: { name: "entries", ns: "entry" },
151
+ assets: { name: "assets", ns: "asset" },
152
+ locales: { name: "locales", ns: "locale" },
153
+ tags: { name: "tags", ns: "tag" }
154
+ };
155
+ async function batchedIdQuery({ client, spaceId, environmentId, type, ids, requestQueue }) {
156
+ const { name, ns } = ENTITY_METHODS[type];
159
157
  const batches = getIdBatches(ids);
160
158
  let totalFetched = 0;
161
159
  const allPendingResponses = batches.map((idBatch) => {
162
160
  return requestQueue.add(async () => {
163
- const response = await environment[method]({
164
- "sys.id[in]": idBatch,
165
- limit: idBatch.split(",").length
161
+ const response = await client[ns].getMany({
162
+ spaceId,
163
+ environmentId,
164
+ query: {
165
+ "sys.id[in]": idBatch,
166
+ limit: idBatch.split(",").length
167
+ }
166
168
  });
167
169
  totalFetched = totalFetched + response.items.length;
168
- import_logging3.logEmitter.emit("info", `Fetched ${totalFetched} of ${response.total} ${entityTypeName}`);
170
+ import_logging3.logEmitter.emit("info", `Fetched ${totalFetched} of ${response.total} ${name}`);
169
171
  return response.items;
170
172
  });
171
173
  });
172
174
  const responses = await import_bluebird.default.all(allPendingResponses);
173
175
  return responses.flat();
174
176
  }
175
- async function batchedPageQuery({ environment, type, requestQueue }) {
176
- const method = OFFSET_QUERY_METHODS[type].method;
177
- const entityTypeName = OFFSET_QUERY_METHODS[type].name;
177
+ async function batchedPageQuery({ client, spaceId, environmentId, type, requestQueue }) {
178
+ const { name, ns } = ENTITY_METHODS[type];
178
179
  let totalFetched = 0;
179
180
  const { items, total } = await requestQueue.add(async () => {
180
- const response = await environment[method]({
181
- skip: 0,
182
- limit: BATCH_SIZE_LIMIT
181
+ const response = await client[ns].getMany({
182
+ spaceId,
183
+ environmentId,
184
+ query: {
185
+ skip: 0,
186
+ limit: BATCH_SIZE_LIMIT
187
+ }
183
188
  });
184
189
  totalFetched += response.items.length;
185
- import_logging3.logEmitter.emit("info", `Fetched ${totalFetched} of ${response.total} ${entityTypeName}`);
190
+ import_logging3.logEmitter.emit("info", `Fetched ${totalFetched} of ${response.total} ${name}`);
186
191
  return { items: response.items, total: response.total };
187
192
  });
188
193
  const batches = getPagedBatches(totalFetched, total);
189
194
  const remainingTotalResponses = batches.map(({ skip }) => {
190
195
  return requestQueue.add(async () => {
191
- const response = await environment[method]({
192
- skip,
193
- limit: BATCH_SIZE_LIMIT
196
+ const response = await client[ns].getMany({
197
+ spaceId,
198
+ environmentId,
199
+ query: {
200
+ skip,
201
+ limit: BATCH_SIZE_LIMIT
202
+ }
194
203
  });
195
204
  totalFetched = totalFetched + response.items.length;
196
- import_logging3.logEmitter.emit("info", `Fetched ${totalFetched} of ${response.total} ${entityTypeName}`);
205
+ import_logging3.logEmitter.emit("info", `Fetched ${totalFetched} of ${response.total} ${name}`);
197
206
  return response.items;
198
207
  });
199
208
  });
@@ -230,14 +239,14 @@ function getPagedBatches(totalFetched, total) {
230
239
  }
231
240
  return batches;
232
241
  }
233
- async function cursorPaginatedQuery({ plainClient, spaceId, environmentId, type, requestQueue }) {
242
+ async function cursorPaginatedQuery({ client, spaceId, environmentId, type, requestQueue }) {
234
243
  const { name: entityTypeName, namespace } = CURSOR_QUERY_METHODS[type];
235
244
  let totalFetched = 0;
236
245
  let pageNext = void 0;
237
246
  const allItems = [];
238
247
  do {
239
248
  const items = await requestQueue.add(async () => {
240
- const response = await plainClient[namespace].getMany({
249
+ const response = await client[namespace].getMany({
241
250
  spaceId,
242
251
  environmentId,
243
252
  query: { limit: BATCH_SIZE_LIMIT, ...pageNext && { pageNext } }
@@ -266,7 +275,6 @@ async function cursorPaginatedQueryOrWarn(params) {
266
275
  }
267
276
  async function getDestinationData({
268
277
  client,
269
- plainClient,
270
278
  spaceId,
271
279
  environmentId,
272
280
  sourceData,
@@ -276,8 +284,6 @@ async function getDestinationData({
276
284
  includeExperienceOrchestration,
277
285
  requestQueue
278
286
  }) {
279
- const space = await client.getSpace(spaceId);
280
- const environment = await space.getEnvironment(environmentId);
281
287
  const result = {
282
288
  contentTypes: [],
283
289
  tags: [],
@@ -300,7 +306,9 @@ async function getDestinationData({
300
306
  const contentTypeIds = sourceData.contentTypes?.map((e) => e.sys.id);
301
307
  if (contentTypeIds) {
302
308
  result.contentTypes = batchedIdQuery({
303
- environment,
309
+ client,
310
+ spaceId,
311
+ environmentId,
304
312
  type: "contentTypes",
305
313
  ids: contentTypeIds,
306
314
  requestQueue
@@ -310,7 +318,9 @@ async function getDestinationData({
310
318
  const localeIds = sourceData.locales?.map((e) => e.sys.id);
311
319
  if (localeIds && localeIds.length) {
312
320
  result.locales = batchedPageQuery({
313
- environment,
321
+ client,
322
+ spaceId,
323
+ environmentId,
314
324
  type: "locales",
315
325
  requestQueue
316
326
  });
@@ -318,7 +328,7 @@ async function getDestinationData({
318
328
  }
319
329
  }
320
330
  try {
321
- result.tags = await batchedPageQuery({ environment, type: "tags", requestQueue });
331
+ result.tags = await batchedPageQuery({ client, spaceId, environmentId, type: "tags", requestQueue });
322
332
  } catch (_) {
323
333
  delete result.tags;
324
334
  }
@@ -329,7 +339,9 @@ async function getDestinationData({
329
339
  const assetIds = sourceData.assets?.map((e) => e.sys.id);
330
340
  if (entryIds && entryIds.length) {
331
341
  result.entries = batchedIdQuery({
332
- environment,
342
+ client,
343
+ spaceId,
344
+ environmentId,
333
345
  type: "entries",
334
346
  ids: entryIds,
335
347
  requestQueue
@@ -337,13 +349,15 @@ async function getDestinationData({
337
349
  }
338
350
  if (assetIds && assetIds.length) {
339
351
  result.assets = batchedIdQuery({
340
- environment,
352
+ client,
353
+ spaceId,
354
+ environmentId,
341
355
  type: "assets",
342
356
  ids: assetIds,
343
357
  requestQueue
344
358
  });
345
359
  }
346
- if (includeExperienceOrchestration && plainClient) {
360
+ if (includeExperienceOrchestration && client) {
347
361
  const sourceHasDesignTokens = Boolean(sourceData.designTokens?.length);
348
362
  const sourceHasComponents = Boolean(sourceData.components?.length);
349
363
  const sourceHasExperienceTemplates = Boolean(sourceData.experienceTemplates?.length);
@@ -351,29 +365,29 @@ async function getDestinationData({
351
365
  const sourceHasExperiences = Boolean(sourceData.experiences?.length);
352
366
  let entitled = true;
353
367
  if (sourceHasDesignTokens || sourceHasComponents || sourceHasExperienceTemplates || sourceHasExperienceFragments || sourceHasExperiences) {
354
- entitled = await spaceHasExoM1Entitlement(plainClient, spaceId);
368
+ entitled = await spaceHasExoM1Entitlement(client, spaceId);
355
369
  }
356
370
  if (entitled === false) {
357
371
  import_logging3.logEmitter.emit("error", new Error("Skipping Experience Orchestration import: Experience Orchestration (ExO) is not enabled for this space"));
358
372
  } else {
359
373
  if (sourceHasDesignTokens) {
360
- result.designTokens = cursorPaginatedQueryOrWarn({ plainClient, spaceId, environmentId, type: "designTokens", requestQueue });
374
+ result.designTokens = cursorPaginatedQueryOrWarn({ client, spaceId, environmentId, type: "designTokens", requestQueue });
361
375
  }
362
376
  if (sourceHasComponents) {
363
- result.components = cursorPaginatedQueryOrWarn({ plainClient, spaceId, environmentId, type: "components", requestQueue });
377
+ result.components = cursorPaginatedQueryOrWarn({ client, spaceId, environmentId, type: "components", requestQueue });
364
378
  }
365
379
  if (sourceHasExperienceTemplates) {
366
- result.experienceTemplates = cursorPaginatedQueryOrWarn({ plainClient, spaceId, environmentId, type: "experienceTemplates", requestQueue });
380
+ result.experienceTemplates = cursorPaginatedQueryOrWarn({ client, spaceId, environmentId, type: "experienceTemplates", requestQueue });
367
381
  }
368
382
  if (sourceHasExperienceFragments) {
369
- result.experienceFragments = cursorPaginatedQueryOrWarn({ plainClient, spaceId, environmentId, type: "experienceFragments", requestQueue });
383
+ result.experienceFragments = cursorPaginatedQueryOrWarn({ client, spaceId, environmentId, type: "experienceFragments", requestQueue });
370
384
  }
371
385
  if (sourceHasExperiences) {
372
- result.experiences = cursorPaginatedQueryOrWarn({ plainClient, spaceId, environmentId, type: "experiences", requestQueue });
386
+ result.experiences = cursorPaginatedQueryOrWarn({ client, spaceId, environmentId, type: "experiences", requestQueue });
373
387
  }
374
388
  }
375
389
  if (sourceData.dataAssemblies?.length) {
376
- result.dataAssemblies = cursorPaginatedQueryOrWarn({ plainClient, spaceId, environmentId, type: "dataAssemblies", requestQueue });
390
+ result.dataAssemblies = cursorPaginatedQueryOrWarn({ client, spaceId, environmentId, type: "dataAssemblies", requestQueue });
377
391
  }
378
392
  }
379
393
  return import_bluebird.default.props(result);
@@ -420,9 +434,9 @@ async function getAssetStreamForURL(url, assetsDirectory) {
420
434
  throw error;
421
435
  }
422
436
  }
423
- async function processAssetForLocale(locale, asset, processingOptions) {
437
+ async function processAssetForLocale(client, spaceId, environmentId, locale, asset, processingOptions) {
424
438
  try {
425
- return await asset.processForLocale(locale, processingOptions);
439
+ return await client.asset.processForLocale({ spaceId, environmentId }, asset, locale, processingOptions);
426
440
  } catch (err) {
427
441
  if (err instanceof ContentfulEntityError) {
428
442
  err.entity = asset;
@@ -445,6 +459,9 @@ async function lastResult(promises) {
445
459
  }
446
460
  async function processAssets({
447
461
  assets: assets2,
462
+ client,
463
+ spaceId,
464
+ environmentId,
448
465
  timeout,
449
466
  retryLimit,
450
467
  requestQueue
@@ -462,7 +479,7 @@ async function processAssets({
462
479
  latestAssetVersion = await lastResult(
463
480
  locales2.map((locale) => {
464
481
  return requestQueue.add(
465
- () => processAssetForLocale(locale, asset, processingOptions)
482
+ () => processAssetForLocale(client, spaceId, environmentId, locale, asset, processingOptions)
466
483
  );
467
484
  })
468
485
  );
@@ -498,7 +515,7 @@ async function createEntitiesWithConcurrency({ context, entities, destinationEnt
498
515
  }
499
516
  return requestQueue.add(async () => {
500
517
  try {
501
- const createdEntity = await (destinationEntity ? updateDestinationWithSourceData(destinationEntity, entity.transformed) : createInDestination(context, entity.transformed));
518
+ const createdEntity = await (destinationEntity ? updateDestinationWithSourceData(context, destinationEntity, entity.transformed) : createInDestination(context, entity.transformed));
502
519
  creationSuccessNotifier(operation, createdEntity);
503
520
  return createdEntity;
504
521
  } catch (err) {
@@ -516,7 +533,7 @@ async function createEntitiesInSequence({ context, entities, destinationEntities
516
533
  const operation = destinationEntity ? "update" : "create";
517
534
  try {
518
535
  const createdEntity = await requestQueue.add(async () => {
519
- const createdOrUpdatedEntity = await (destinationEntity ? updateDestinationWithSourceData(destinationEntity, entity.transformed) : createInDestination(context, entity.transformed));
536
+ const createdOrUpdatedEntity = await (destinationEntity ? updateDestinationWithSourceData(context, destinationEntity, entity.transformed) : createInDestination(context, entity.transformed));
520
537
  return createdOrUpdatedEntity;
521
538
  });
522
539
  creationSuccessNotifier(operation, createdEntity);
@@ -532,11 +549,11 @@ async function createEntitiesInSequence({ context, entities, destinationEntities
532
549
  }
533
550
  async function createEntries({ context, entities, destinationEntitiesById, skipUpdates, requestQueue }) {
534
551
  const createdEntries = await Promise.all(entities.map((entry) => {
535
- return createEntry({ entry, target: context.target, skipContentModel: context.skipContentModel, destinationEntitiesById, skipUpdates, requestQueue });
552
+ return createEntry({ entry, context, destinationEntitiesById, skipUpdates, requestQueue });
536
553
  }));
537
554
  return createdEntries.filter((entry) => entry);
538
555
  }
539
- async function createEntry({ entry, target, skipContentModel, destinationEntitiesById, skipUpdates, requestQueue }) {
556
+ async function createEntry({ entry, context, destinationEntitiesById, skipUpdates, requestQueue }) {
540
557
  const contentTypeId = entry.original.sys.contentType.sys.id;
541
558
  const destinationEntry = getDestinationEntityForSourceEntity(
542
559
  destinationEntitiesById,
@@ -550,16 +567,16 @@ async function createEntry({ entry, target, skipContentModel, destinationEntitie
550
567
  }
551
568
  try {
552
569
  const createdOrUpdatedEntry = await requestQueue.add(() => {
553
- return destinationEntry ? updateDestinationWithSourceData(destinationEntry, entry.transformed) : createEntryInDestination(target, contentTypeId, entry.transformed);
570
+ return destinationEntry ? updateDestinationWithSourceData(context, destinationEntry, entry.transformed) : createEntryInDestination(context, contentTypeId, entry.transformed);
554
571
  });
555
572
  creationSuccessNotifier(operation, createdOrUpdatedEntry);
556
573
  return createdOrUpdatedEntry;
557
574
  } catch (err) {
558
575
  if (err instanceof Error) {
559
- if (skipContentModel && err.name === "UnknownField") {
576
+ if (context.skipContentModel && err.name === "UnknownField") {
560
577
  const errors = (0, import_object.get)(JSON.parse(err.message), "details.errors");
561
578
  entry.transformed.fields = cleanupUnknownFields(entry.transformed.fields, errors);
562
- return createEntry({ entry, target, skipContentModel, destinationEntitiesById, skipUpdates, requestQueue });
579
+ return createEntry({ entry, context, destinationEntitiesById, skipUpdates, requestQueue });
563
580
  }
564
581
  }
565
582
  if (err instanceof ContentfulEntityError) {
@@ -569,30 +586,78 @@ async function createEntry({ entry, target, skipContentModel, destinationEntitie
569
586
  return null;
570
587
  }
571
588
  }
572
- function updateDestinationWithSourceData(destinationEntity, sourceEntity) {
589
+ function updateDestinationWithSourceData(context, destinationEntity, sourceEntity) {
590
+ const { client, spaceId, environmentId, type } = context;
573
591
  const plainData = getPlainData(sourceEntity);
574
- (0, import_object.assign)(destinationEntity, plainData);
575
- return destinationEntity.update();
592
+ const updated = (0, import_object.assign)({}, plainData, { sys: destinationEntity.sys });
593
+ if (type === "Entry") {
594
+ return client.entry.update(
595
+ { spaceId, environmentId, entryId: destinationEntity.sys.id },
596
+ updated
597
+ );
598
+ }
599
+ if (type === "ContentType") {
600
+ return client.contentType.update(
601
+ { spaceId, environmentId, contentTypeId: destinationEntity.sys.id },
602
+ updated
603
+ );
604
+ }
605
+ if (type === "Asset") {
606
+ return client.asset.update(
607
+ { spaceId, environmentId, assetId: destinationEntity.sys.id },
608
+ updated
609
+ );
610
+ }
611
+ if (type === "Locale") {
612
+ return client.locale.update(
613
+ { spaceId, environmentId, localeId: destinationEntity.sys.id },
614
+ updated
615
+ );
616
+ }
617
+ if (type === "Webhook") {
618
+ return client.webhook.update(
619
+ { spaceId, webhookDefinitionId: destinationEntity.sys.id },
620
+ updated
621
+ );
622
+ }
623
+ throw new Error(`updateDestinationWithSourceData: unsupported type "${type}"`);
576
624
  }
577
625
  function createInDestination(context, sourceEntity) {
578
- const { type, target } = context;
626
+ const { type, client, spaceId, environmentId } = context;
579
627
  if (type === "Tag") {
580
628
  return createTagInDestination(context, sourceEntity);
581
629
  }
582
630
  const id = (0, import_object.get)(sourceEntity, "sys.id");
583
631
  const plainData = getPlainData(sourceEntity);
584
- return id ? target[`create${type}WithId`](id, plainData) : target[`create${type}`](plainData);
632
+ if (type === "ContentType") {
633
+ return id ? client.contentType.createWithId({ spaceId, environmentId, contentTypeId: id }, plainData) : client.contentType.create({ spaceId, environmentId }, plainData);
634
+ }
635
+ if (type === "Asset") {
636
+ return id ? client.asset.createWithId({ spaceId, environmentId, assetId: id }, plainData) : client.asset.create({ spaceId, environmentId }, plainData);
637
+ }
638
+ if (type === "Locale") {
639
+ return client.locale.create({ spaceId, environmentId }, plainData);
640
+ }
641
+ if (type === "Webhook") {
642
+ return id ? client.webhook.update({ spaceId, webhookDefinitionId: id }, { ...plainData, sys: { id } }) : client.webhook.create({ spaceId }, plainData);
643
+ }
644
+ throw new Error(`createInDestination: unsupported type "${type}"`);
585
645
  }
586
- function createEntryInDestination(space, contentTypeId, sourceEntity) {
646
+ function createEntryInDestination(context, contentTypeId, sourceEntity) {
647
+ const { client, spaceId, environmentId } = context;
587
648
  const id = sourceEntity.sys.id;
588
649
  const plainData = getPlainData(sourceEntity);
589
- return id ? space.createEntryWithId(contentTypeId, id, plainData) : space.createEntry(contentTypeId, plainData);
650
+ return id ? client.entry.createWithId({ spaceId, environmentId, contentTypeId, entryId: id }, plainData) : client.entry.create({ spaceId, environmentId, contentTypeId }, plainData);
590
651
  }
591
652
  function createTagInDestination(context, sourceEntity) {
653
+ const { client, spaceId, environmentId } = context;
592
654
  const id = sourceEntity.sys.id;
593
655
  const visibility = sourceEntity.sys.visibility || "private";
594
656
  const name = sourceEntity.name;
595
- return context.target.createTag(id, name, visibility);
657
+ return client.tag.createWithId(
658
+ { spaceId, environmentId, tagId: id },
659
+ { name, sys: { visibility } }
660
+ );
596
661
  }
597
662
  function handleCreationErrors(entity, err) {
598
663
  if ((0, import_object.get)(err, "error.sys.id") === "ValidationFailed") {
@@ -625,51 +690,61 @@ function creationSuccessNotifier(method, createdEntity) {
625
690
  return createdEntity;
626
691
  }
627
692
  function getPlainData(entity) {
628
- const data = entity.toPlainObject ? entity.toPlainObject() : entity;
629
- return (0, import_object.omit)(data, "sys");
693
+ return (0, import_object.omit)(entity, "sys");
630
694
  }
631
695
 
632
696
  // lib/tasks/push-to-space/publishing.ts
633
697
  var import_get_entity_name3 = __toESM(require("contentful-batch-libs/dist/get-entity-name"));
634
698
  var import_logging6 = require("contentful-batch-libs/dist/logging");
635
- async function publishEntities({ entities, requestQueue }) {
636
- const entitiesToPublish = entities.filter((entity2) => {
637
- if (!entity2 || !entity2.publish) {
638
- import_logging6.logEmitter.emit("warning", `Unable to publish ${(0, import_get_entity_name3.default)(entity2)}`);
639
- return false;
640
- }
641
- return true;
642
- });
643
- if (entitiesToPublish.length === 0) {
699
+ function publishEntity(client, spaceId, environmentId, entity) {
700
+ const id = entity.sys.id;
701
+ const type = entity.sys.type;
702
+ if (type === "Entry") {
703
+ return client.entry.publish({ spaceId, environmentId, entryId: id }, entity);
704
+ }
705
+ if (type === "Asset") {
706
+ return client.asset.publish({ spaceId, environmentId, assetId: id }, entity);
707
+ }
708
+ if (type === "ContentType") {
709
+ return client.contentType.publish({ spaceId, environmentId, contentTypeId: id }, entity);
710
+ }
711
+ throw new Error(`publishEntity: unsupported type "${type}"`);
712
+ }
713
+ function archiveEntity(client, spaceId, environmentId, entity) {
714
+ const id = entity.sys.id;
715
+ const type = entity.sys.type;
716
+ if (type === "Entry") {
717
+ return client.entry.archive({ spaceId, environmentId, entryId: id });
718
+ }
719
+ if (type === "Asset") {
720
+ return client.asset.archive({ spaceId, environmentId, assetId: id });
721
+ }
722
+ throw new Error(`archiveEntity: unsupported type "${type}"`);
723
+ }
724
+ async function publishEntities({ entities, client, spaceId, environmentId, requestQueue }) {
725
+ if (entities.length === 0) {
644
726
  import_logging6.logEmitter.emit("info", "Skipping publishing since zero valid entities passed");
645
727
  return [];
646
728
  }
647
- const entity = entities[0].original || entities[0];
729
+ const entity = entities[0];
648
730
  const type = entity.sys.type || "unknown type";
649
731
  import_logging6.logEmitter.emit("info", `Publishing ${entities.length} ${type}s`);
650
- const result = await runQueue(entitiesToPublish, [], requestQueue);
732
+ const result = await runQueue(entities, [], client, spaceId, environmentId, requestQueue);
651
733
  import_logging6.logEmitter.emit("info", `Successfully published ${result.length} ${type}s`);
652
734
  return result;
653
735
  }
654
- async function archiveEntities({ entities, requestQueue }) {
655
- const entitiesToArchive = entities.filter((entity2) => {
656
- if (!entity2 || !entity2.archive) {
657
- import_logging6.logEmitter.emit("warning", `Unable to archive ${(0, import_get_entity_name3.default)(entity2)}`);
658
- return false;
659
- }
660
- return true;
661
- });
662
- if (entitiesToArchive.length === 0) {
736
+ async function archiveEntities({ entities, client, spaceId, environmentId, requestQueue }) {
737
+ if (entities.length === 0) {
663
738
  import_logging6.logEmitter.emit("info", "Skipping archiving since zero valid entities passed");
664
739
  return [];
665
740
  }
666
- const entity = entities[0].original || entities[0];
741
+ const entity = entities[0];
667
742
  const type = entity.sys.type || "unknown type";
668
743
  import_logging6.logEmitter.emit("info", `Archiving ${entities.length} ${type}s`);
669
- const pendingArchivedEntities = entitiesToArchive.map((entity2) => {
744
+ const pendingArchivedEntities = entities.map((entity2) => {
670
745
  return requestQueue.add(async () => {
671
746
  try {
672
- const archivedEntity = await entity2.archive();
747
+ const archivedEntity = await archiveEntity(client, spaceId, environmentId, entity2);
673
748
  return archivedEntity;
674
749
  } catch (err) {
675
750
  if (err instanceof ContentfulEntityError) {
@@ -685,12 +760,12 @@ async function archiveEntities({ entities, requestQueue }) {
685
760
  import_logging6.logEmitter.emit("info", `Successfully archived ${allArchivedEntities.length} ${type}s`);
686
761
  return allArchivedEntities;
687
762
  }
688
- async function runQueue(queue, result = [], requestQueue) {
763
+ async function runQueue(queue, result = [], client, spaceId, environmentId, requestQueue) {
689
764
  const publishedEntities = [];
690
765
  for (const entity of queue) {
691
766
  import_logging6.logEmitter.emit("info", `Publishing ${entity.sys.type} ${(0, import_get_entity_name3.default)(entity)}`);
692
767
  try {
693
- const publishedEntity = await requestQueue.add(() => entity.publish());
768
+ const publishedEntity = await requestQueue.add(() => publishEntity(client, spaceId, environmentId, entity));
694
769
  publishedEntities.push(publishedEntity);
695
770
  } catch (err) {
696
771
  if (err instanceof ContentfulEntityError) {
@@ -710,7 +785,7 @@ async function runQueue(queue, result = [], requestQueue) {
710
785
  const unpublishedEntityNames = unpublishedEntities.map(import_get_entity_name3.default).join(", ");
711
786
  import_logging6.logEmitter.emit("error", `Could not publish the following entities: ${unpublishedEntityNames}`);
712
787
  } else {
713
- return runQueue(unpublishedEntities, result, requestQueue);
788
+ return runQueue(unpublishedEntities, result, client, spaceId, environmentId, requestQueue);
714
789
  }
715
790
  }
716
791
  return result;
@@ -878,8 +953,8 @@ function getSourceSpaceId(sourceEntities) {
878
953
  }
879
954
  return void 0;
880
955
  }
881
- async function ensureParentFolderGroupsExist(plainClient, organizationId) {
882
- const { items } = await plainClient.conceptScheme.getMany({
956
+ async function ensureParentFolderGroupsExist(client, organizationId) {
957
+ const { items } = await client.conceptScheme.getMany({
883
958
  organizationId,
884
959
  query: { purpose: "internal" }
885
960
  });
@@ -909,18 +984,18 @@ function deriveChildConceptMap(sourceEntities, destinationSpaceId) {
909
984
  }
910
985
  return childConceptMap;
911
986
  }
912
- async function createOrPatchChildConcepts(plainClient, organizationId, destinationSpaceId, childConceptMap) {
987
+ async function createOrPatchChildConcepts(client, organizationId, destinationSpaceId, childConceptMap) {
913
988
  const spaceLink = { sys: { type: "Link", linkType: "Space", id: destinationSpaceId } };
914
989
  for (const [sourceConceptId, { destConceptId }] of childConceptMap) {
915
990
  let prefLabel = { "en-US": destConceptId };
916
991
  try {
917
- const sourceConcept = await plainClient.concept.get({ organizationId, conceptId: sourceConceptId });
992
+ const sourceConcept = await client.concept.get({ organizationId, conceptId: sourceConceptId });
918
993
  if (sourceConcept?.prefLabel) prefLabel = sourceConcept.prefLabel;
919
994
  } catch {
920
995
  }
921
996
  let existing = null;
922
997
  try {
923
- existing = await plainClient.concept.get({ organizationId, conceptId: destConceptId });
998
+ existing = await client.concept.get({ organizationId, conceptId: destConceptId });
924
999
  } catch (err) {
925
1000
  if (err?.name !== "NotFound") {
926
1001
  import_logging8.logEmitter.emit("warning", `Could not fetch destination child concept ${destConceptId}: ${err?.message ?? err}`);
@@ -928,8 +1003,9 @@ async function createOrPatchChildConcepts(plainClient, organizationId, destinati
928
1003
  }
929
1004
  if (!existing) {
930
1005
  try {
931
- await plainClient.concept.createWithId(
1006
+ await client.concept.createWithId(
932
1007
  { organizationId, conceptId: destConceptId },
1008
+ // @ts-expect-error - CMA.js type needs to be updated to be aware of purpose: 'internal'
933
1009
  { purpose: "internal", prefLabel, metadata: { spaces: [spaceLink] } }
934
1010
  );
935
1011
  import_logging8.logEmitter.emit("info", `Created child folder concept ${destConceptId}`);
@@ -938,16 +1014,13 @@ async function createOrPatchChildConcepts(plainClient, organizationId, destinati
938
1014
  }
939
1015
  } else {
940
1016
  const patches = [];
941
- if (existing.purpose !== "internal") {
942
- patches.push({ op: "add", path: "/purpose", value: "internal" });
943
- }
944
1017
  const spaces = existing.metadata?.spaces ?? [];
945
1018
  if (!spaces.some((s) => s.sys.id === destinationSpaceId)) {
946
1019
  patches.push({ op: "add", path: "/metadata/spaces/-", value: spaceLink });
947
1020
  }
948
1021
  if (patches.length > 0) {
949
1022
  try {
950
- await plainClient.concept.patch(
1023
+ await client.concept.patch(
951
1024
  { organizationId, conceptId: destConceptId, version: existing.sys.version },
952
1025
  patches
953
1026
  );
@@ -959,14 +1032,14 @@ async function createOrPatchChildConcepts(plainClient, organizationId, destinati
959
1032
  }
960
1033
  }
961
1034
  }
962
- async function linkChildConceptsToParentGroups(plainClient, organizationId, childConceptMap, parentGroups) {
1035
+ async function linkChildConceptsToParentGroups(client, organizationId, childConceptMap, parentGroups) {
963
1036
  for (const [, { destConceptId, parentGroupId }] of childConceptMap) {
964
1037
  const parentGroup = parentGroups.get(parentGroupId);
965
1038
  if (!parentGroup) continue;
966
1039
  const alreadyLinked = (parentGroup.concepts ?? []).some((c) => c.sys.id === destConceptId);
967
1040
  if (alreadyLinked) continue;
968
1041
  try {
969
- const updated = await plainClient.conceptScheme.patch(
1042
+ const updated = await client.conceptScheme.patch(
970
1043
  { organizationId, conceptSchemeId: parentGroupId, version: parentGroup.sys.version },
971
1044
  [{ op: "add", path: "/concepts/-", value: { sys: { type: "Link", linkType: "TaxonomyConcept", id: destConceptId } } }]
972
1045
  );
@@ -988,7 +1061,7 @@ function rewriteEntityFolderConcepts(entities, childConceptMap) {
988
1061
  }
989
1062
  }
990
1063
  async function importExoFolders({
991
- plainClient,
1064
+ client,
992
1065
  organizationId,
993
1066
  destinationSpaceId,
994
1067
  sourceEntities
@@ -998,7 +1071,7 @@ async function importExoFolders({
998
1071
  import_logging8.logEmitter.emit("info", "Source and destination space are the same \u2014 skipping ExO folder import");
999
1072
  return;
1000
1073
  }
1001
- const parentGroups = await ensureParentFolderGroupsExist(plainClient, organizationId);
1074
+ const parentGroups = await ensureParentFolderGroupsExist(client, organizationId);
1002
1075
  if (parentGroups.size === 0) {
1003
1076
  import_logging8.logEmitter.emit("warn", "One or more Experience Orchestration folder group concept schemes are missing in the destination organization. Please create them before importing.");
1004
1077
  return;
@@ -1006,8 +1079,8 @@ async function importExoFolders({
1006
1079
  const childConceptMap = deriveChildConceptMap(sourceEntities, destinationSpaceId);
1007
1080
  if (childConceptMap.size === 0) return;
1008
1081
  import_logging8.logEmitter.emit("info", `Importing ${childConceptMap.size} ExO folder concept(s) into destination space ${destinationSpaceId}`);
1009
- await createOrPatchChildConcepts(plainClient, organizationId, destinationSpaceId, childConceptMap);
1010
- await linkChildConceptsToParentGroups(plainClient, organizationId, childConceptMap, parentGroups);
1082
+ await createOrPatchChildConcepts(client, organizationId, destinationSpaceId, childConceptMap);
1083
+ await linkChildConceptsToParentGroups(client, organizationId, childConceptMap, parentGroups);
1011
1084
  const allEntities = [
1012
1085
  ...sourceEntities.designTokens ?? [],
1013
1086
  ...sourceEntities.components ?? [],
@@ -1049,7 +1122,6 @@ function pushToSpace({
1049
1122
  sourceData,
1050
1123
  destinationData = {},
1051
1124
  client,
1052
- plainClient,
1053
1125
  spaceId,
1054
1126
  environmentId,
1055
1127
  includeExperienceOrchestration,
@@ -1086,15 +1158,6 @@ function pushToSpace({
1086
1158
  destinationDataById[entityType] = entitiesById;
1087
1159
  }
1088
1160
  return new import_listr.default([
1089
- {
1090
- title: "Connecting to space",
1091
- task: (0, import_listr2.wrapTask)(async (ctx) => {
1092
- const space = await client.getSpace(spaceId);
1093
- const environment = await space.getEnvironment(environmentId);
1094
- ctx.space = space;
1095
- ctx.environment = environment;
1096
- })
1097
- },
1098
1161
  {
1099
1162
  title: "Importing Locales",
1100
1163
  task: (0, import_listr2.wrapTask)(async (ctx) => {
@@ -1102,7 +1165,7 @@ function pushToSpace({
1102
1165
  return;
1103
1166
  }
1104
1167
  const locales2 = await createLocales({
1105
- context: { target: ctx.environment, type: "Locale" },
1168
+ context: { client, spaceId, environmentId, type: "Locale" },
1106
1169
  entities: sourceData.locales,
1107
1170
  destinationEntitiesById: destinationDataById.locales,
1108
1171
  requestQueue
@@ -1118,7 +1181,7 @@ function pushToSpace({
1118
1181
  return;
1119
1182
  }
1120
1183
  const contentTypes2 = await createEntities({
1121
- context: { target: ctx.environment, type: "ContentType" },
1184
+ context: { client, spaceId, environmentId, type: "ContentType" },
1122
1185
  entities: sourceData.contentTypes,
1123
1186
  destinationEntitiesById: destinationDataById.contentTypes,
1124
1187
  skipUpdates: false,
@@ -1134,6 +1197,9 @@ function pushToSpace({
1134
1197
  const publishedContentTypes = await publishEntities2({
1135
1198
  entities: ctx.data.contentTypes,
1136
1199
  sourceEntities: sourceData.contentTypes,
1200
+ client,
1201
+ spaceId,
1202
+ environmentId,
1137
1203
  requestQueue
1138
1204
  });
1139
1205
  ctx.data.contentTypes = publishedContentTypes;
@@ -1145,7 +1211,7 @@ function pushToSpace({
1145
1211
  task: (0, import_listr2.wrapTask)(async (ctx) => {
1146
1212
  if (sourceData.tags && destinationDataById.tags) {
1147
1213
  const tags2 = await createEntities({
1148
- context: { target: ctx.environment, type: "Tag" },
1214
+ context: { client, spaceId, environmentId, type: "Tag" },
1149
1215
  entities: sourceData.tags,
1150
1216
  destinationEntitiesById: destinationDataById.tags,
1151
1217
  skipUpdates: false,
@@ -1172,14 +1238,24 @@ function pushToSpace({
1172
1238
  return;
1173
1239
  }
1174
1240
  try {
1175
- const ctEditorInterface = await requestQueue.add(() => ctx.environment.getEditorInterfaceForContentType(contentType.sys.id));
1241
+ const ctEditorInterface = await requestQueue.add(
1242
+ () => client.editorInterface.get({ spaceId, environmentId, contentTypeId: contentType.sys.id })
1243
+ );
1176
1244
  import_logging9.logEmitter.emit("info", `Fetched editor interface for ${contentType.name}`);
1177
- ctEditorInterface.controls = editorInterface.controls;
1178
- ctEditorInterface.groupControls = editorInterface.groupControls;
1179
- ctEditorInterface.editorLayout = editorInterface.editorLayout;
1180
- ctEditorInterface.sidebar = editorInterface.sidebar;
1181
- ctEditorInterface.editors = editorInterface.editors;
1182
- const updatedEditorInterface = await requestQueue.add(() => ctEditorInterface.update());
1245
+ const updatedData = {
1246
+ ...ctEditorInterface,
1247
+ controls: editorInterface.controls,
1248
+ groupControls: editorInterface.groupControls,
1249
+ editorLayout: editorInterface.editorLayout,
1250
+ sidebar: editorInterface.sidebar,
1251
+ editors: editorInterface.editors
1252
+ };
1253
+ const updatedEditorInterface = await requestQueue.add(
1254
+ () => client.editorInterface.update(
1255
+ { spaceId, environmentId, contentTypeId: contentType.sys.id },
1256
+ updatedData
1257
+ )
1258
+ );
1183
1259
  return updatedEditorInterface;
1184
1260
  } catch (err) {
1185
1261
  err.entity = editorInterface;
@@ -1203,10 +1279,10 @@ function pushToSpace({
1203
1279
  try {
1204
1280
  import_logging9.logEmitter.emit("info", `Uploading Asset file ${file.upload}`);
1205
1281
  const assetStream = await getAssetStreamForURL(file.upload, assetsDirectory);
1206
- const upload = await ctx.environment.createUpload({
1207
- fileName: asset.transformed.sys.id,
1208
- file: assetStream
1209
- });
1282
+ const upload = await client.upload.create(
1283
+ { spaceId, environmentId },
1284
+ { file: assetStream }
1285
+ );
1210
1286
  delete file.upload;
1211
1287
  file.uploadFrom = {
1212
1288
  sys: {
@@ -1234,7 +1310,7 @@ function pushToSpace({
1234
1310
  return;
1235
1311
  }
1236
1312
  const assetsToProcess = await createEntities({
1237
- context: { target: ctx.environment, type: "Asset" },
1313
+ context: { client, spaceId, environmentId, type: "Asset" },
1238
1314
  entities: sourceData.assets,
1239
1315
  destinationEntitiesById: destinationDataById.assets,
1240
1316
  skipUpdates: skipAssetUpdates,
@@ -1242,6 +1318,9 @@ function pushToSpace({
1242
1318
  });
1243
1319
  const processedAssets = await processAssets({
1244
1320
  assets: assetsToProcess,
1321
+ client,
1322
+ spaceId,
1323
+ environmentId,
1245
1324
  timeout,
1246
1325
  retryLimit,
1247
1326
  requestQueue
@@ -1256,6 +1335,9 @@ function pushToSpace({
1256
1335
  const publishedAssets = await publishEntities2({
1257
1336
  entities: ctx.data.assets,
1258
1337
  sourceEntities: sourceData.assets,
1338
+ client,
1339
+ spaceId,
1340
+ environmentId,
1259
1341
  requestQueue
1260
1342
  });
1261
1343
  ctx.data.publishedAssets = publishedAssets;
@@ -1268,6 +1350,9 @@ function pushToSpace({
1268
1350
  const archivedAssets = await archiveEntities2({
1269
1351
  entities: ctx.data.assets,
1270
1352
  sourceEntities: sourceData.assets,
1353
+ client,
1354
+ spaceId,
1355
+ environmentId,
1271
1356
  requestQueue
1272
1357
  });
1273
1358
  ctx.data.archivedAssets = archivedAssets;
@@ -1278,7 +1363,7 @@ function pushToSpace({
1278
1363
  title: "Importing Content Entries",
1279
1364
  task: (0, import_listr2.wrapTask)(async (ctx) => {
1280
1365
  const entries2 = await createEntries({
1281
- context: { target: ctx.environment, skipContentModel },
1366
+ context: { client, spaceId, environmentId, skipContentModel, type: "Entry" },
1282
1367
  entities: sourceData.entries,
1283
1368
  destinationEntitiesById: destinationDataById.entries,
1284
1369
  skipUpdates: skipContentUpdates,
@@ -1294,6 +1379,9 @@ function pushToSpace({
1294
1379
  const publishedEntries = await publishEntities2({
1295
1380
  entities: ctx.data.entries,
1296
1381
  sourceEntities: sourceData.entries,
1382
+ client,
1383
+ spaceId,
1384
+ environmentId,
1297
1385
  requestQueue
1298
1386
  });
1299
1387
  ctx.data.publishedEntries = publishedEntries;
@@ -1306,6 +1394,9 @@ function pushToSpace({
1306
1394
  const archivedEntries = await archiveEntities2({
1307
1395
  entities: ctx.data.entries,
1308
1396
  sourceEntities: sourceData.entries,
1397
+ client,
1398
+ spaceId,
1399
+ environmentId,
1309
1400
  requestQueue
1310
1401
  });
1311
1402
  ctx.data.archivedEntries = archivedEntries;
@@ -1319,7 +1410,7 @@ function pushToSpace({
1319
1410
  return;
1320
1411
  }
1321
1412
  const webhooks2 = await createEntities({
1322
- context: { target: ctx.space, type: "Webhook" },
1413
+ context: { client, spaceId, environmentId, type: "Webhook" },
1323
1414
  entities: sourceData.webhooks,
1324
1415
  destinationEntitiesById: destinationDataById.webhooks,
1325
1416
  requestQueue
@@ -1330,19 +1421,24 @@ function pushToSpace({
1330
1421
  },
1331
1422
  {
1332
1423
  title: "Create ExO Folders",
1333
- task: (0, import_listr2.wrapTask)(async (ctx) => {
1334
- await importExoFolders({
1335
- plainClient,
1336
- organizationId: ctx.space.sys.organization.sys.id,
1337
- destinationSpaceId: spaceId,
1338
- sourceEntities: {
1339
- designTokens: sourceData.designTokens,
1340
- components: sourceData.components,
1341
- experienceTemplates: sourceData.experienceTemplates,
1342
- experienceFragments: sourceData.experienceFragments,
1343
- experiences: sourceData.experiences
1344
- }
1345
- });
1424
+ task: (0, import_listr2.wrapTask)(async () => {
1425
+ try {
1426
+ const space = await client.space.get({ spaceId });
1427
+ await importExoFolders({
1428
+ client,
1429
+ organizationId: space.sys.organization.sys.id,
1430
+ destinationSpaceId: spaceId,
1431
+ sourceEntities: {
1432
+ designTokens: sourceData.designTokens,
1433
+ components: sourceData.components,
1434
+ experienceTemplates: sourceData.experienceTemplates,
1435
+ experienceFragments: sourceData.experienceFragments,
1436
+ experiences: sourceData.experiences
1437
+ }
1438
+ });
1439
+ } catch (error) {
1440
+ import_logging9.logEmitter.emit("warning", `Unable to create Experience Orchestration (ExO) folders, error: ${error}`);
1441
+ }
1346
1442
  }),
1347
1443
  skip: () => !includeExperienceOrchestration
1348
1444
  },
@@ -1355,14 +1451,14 @@ function pushToSpace({
1355
1451
  let result;
1356
1452
  if (existing) {
1357
1453
  const payload = { ...omitSys(entity), sys: buildDataAssemblySys(entity, existing.sys.version) };
1358
- result = await withGraphQLSchemaBackoff(() => plainClient.dataAssembly.update(
1454
+ result = await withGraphQLSchemaBackoff(() => client.dataAssembly.update(
1359
1455
  { spaceId, environmentId, dataAssemblyId: entity.sys.id },
1360
1456
  payload
1361
1457
  ));
1362
1458
  import_logging9.logEmitter.emit("info", `UPDATE DataAssembly ${entity.sys.id}`);
1363
1459
  } else {
1364
1460
  const payload = { ...omitSys(entity), sys: buildDataAssemblySys(entity, 0) };
1365
- result = await withGraphQLSchemaBackoff(() => plainClient.dataAssembly.update(
1461
+ result = await withGraphQLSchemaBackoff(() => client.dataAssembly.update(
1366
1462
  { spaceId, environmentId, dataAssemblyId: entity.sys.id },
1367
1463
  payload
1368
1464
  ));
@@ -1384,7 +1480,7 @@ function pushToSpace({
1384
1480
  task: (0, import_listr2.wrapTask)(async (ctx) => {
1385
1481
  const entitiesToPublish = filterExoEntitiesToPublish(ctx.data.dataAssemblies, sourceData.dataAssemblies || []);
1386
1482
  const results = await Promise.all(entitiesToPublish.map(
1387
- (entity) => publishExoEntity("DataAssembly", entity, () => plainClient.dataAssembly.publish(
1483
+ (entity) => publishExoEntity("DataAssembly", entity, () => client.dataAssembly.publish(
1388
1484
  { spaceId, environmentId, dataAssemblyId: entity.sys.id, version: entity.sys.version }
1389
1485
  ))
1390
1486
  ));
@@ -1400,12 +1496,12 @@ function pushToSpace({
1400
1496
  const existing = destinationDataById.designTokens?.get(entity.sys.id);
1401
1497
  if (existing) {
1402
1498
  const payload = { ...entity, sys: { id: entity.sys.id, type: "DesignToken", version: existing.sys.version } };
1403
- const result = await plainClient.designToken.upsert({ spaceId, environmentId, designTokenId: entity.sys.id }, payload);
1499
+ const result = await client.designToken.upsert({ spaceId, environmentId, designTokenId: entity.sys.id }, payload);
1404
1500
  import_logging9.logEmitter.emit("info", `UPDATE DesignToken ${entity.sys.id}`);
1405
1501
  return result;
1406
1502
  } else {
1407
1503
  const payload = { ...omitSys(entity), sys: { id: entity.sys.id, type: "DesignToken" } };
1408
- const result = await plainClient.designToken.upsert({ spaceId, environmentId, designTokenId: entity.sys.id }, payload);
1504
+ const result = await client.designToken.upsert({ spaceId, environmentId, designTokenId: entity.sys.id }, payload);
1409
1505
  import_logging9.logEmitter.emit("info", `CREATE DesignToken ${entity.sys.id}`);
1410
1506
  return result;
1411
1507
  }
@@ -1429,12 +1525,12 @@ function pushToSpace({
1429
1525
  const existing = destinationDataById.components?.get(entity.sys.id);
1430
1526
  if (existing) {
1431
1527
  const payload = { ...entity, sys: { id: entity.sys.id, type: "Component", version: existing.sys.version } };
1432
- const result = await plainClient.component.upsert({ spaceId, environmentId, componentId: entity.sys.id }, payload);
1528
+ const result = await client.component.upsert({ spaceId, environmentId, componentId: entity.sys.id }, payload);
1433
1529
  import_logging9.logEmitter.emit("info", `UPDATE Component ${entity.sys.id}`);
1434
1530
  results.push(result);
1435
1531
  } else {
1436
1532
  const payload = { ...omitSys(entity), sys: { id: entity.sys.id, type: "Component" } };
1437
- const result = await plainClient.component.upsert({ spaceId, environmentId, componentId: entity.sys.id }, payload);
1533
+ const result = await client.component.upsert({ spaceId, environmentId, componentId: entity.sys.id }, payload);
1438
1534
  import_logging9.logEmitter.emit("info", `CREATE Component ${entity.sys.id}`);
1439
1535
  results.push(result);
1440
1536
  }
@@ -1454,7 +1550,7 @@ function pushToSpace({
1454
1550
  const sorted = sortOrReport(() => sortComponents(entitiesToPublish));
1455
1551
  const results = [];
1456
1552
  for (const entity of sorted) {
1457
- const published = await publishExoEntity("Component", entity, () => plainClient.component.publish(
1553
+ const published = await publishExoEntity("Component", entity, () => client.component.publish(
1458
1554
  { spaceId, environmentId, componentId: entity.sys.id, version: entity.sys.version }
1459
1555
  ));
1460
1556
  if (published) results.push(published);
@@ -1471,12 +1567,12 @@ function pushToSpace({
1471
1567
  const existing = destinationDataById.experienceTemplates?.get(entity.sys.id);
1472
1568
  if (existing) {
1473
1569
  const payload = { ...entity, sys: { id: entity.sys.id, type: "ExperienceTemplate", version: existing.sys.version } };
1474
- const result = await plainClient.experienceTemplate.upsert({ spaceId, environmentId, experienceTemplateId: entity.sys.id }, payload);
1570
+ const result = await client.experienceTemplate.upsert({ spaceId, environmentId, experienceTemplateId: entity.sys.id }, payload);
1475
1571
  import_logging9.logEmitter.emit("info", `UPDATE ExperienceTemplate ${entity.sys.id}`);
1476
1572
  return result;
1477
1573
  } else {
1478
1574
  const payload = { ...omitSys(entity), sys: { id: entity.sys.id, type: "ExperienceTemplate" } };
1479
- const result = await plainClient.experienceTemplate.upsert({ spaceId, environmentId, experienceTemplateId: entity.sys.id }, payload);
1575
+ const result = await client.experienceTemplate.upsert({ spaceId, environmentId, experienceTemplateId: entity.sys.id }, payload);
1480
1576
  import_logging9.logEmitter.emit("info", `CREATE ExperienceTemplate ${entity.sys.id}`);
1481
1577
  return result;
1482
1578
  }
@@ -1495,7 +1591,7 @@ function pushToSpace({
1495
1591
  task: (0, import_listr2.wrapTask)(async (ctx) => {
1496
1592
  const entitiesToPublish = filterExoEntitiesToPublish(ctx.data.experienceTemplates, sourceData.experienceTemplates || []);
1497
1593
  const results = await Promise.all(entitiesToPublish.map(
1498
- (entity) => publishExoEntity("ExperienceTemplate", entity, () => plainClient.experienceTemplate.publish(
1594
+ (entity) => publishExoEntity("ExperienceTemplate", entity, () => client.experienceTemplate.publish(
1499
1595
  { spaceId, environmentId, experienceTemplateId: entity.sys.id, version: entity.sys.version }
1500
1596
  ))
1501
1597
  ));
@@ -1513,12 +1609,12 @@ function pushToSpace({
1513
1609
  const existing = destinationDataById.experienceFragments?.get(entity.sys.id);
1514
1610
  if (existing) {
1515
1611
  const payload = { ...entity, sys: { id: entity.sys.id, type: "ExperienceFragment", version: existing.sys.version } };
1516
- const result = await plainClient.experienceFragment.upsert({ spaceId, environmentId, experienceFragmentId: entity.sys.id }, payload);
1612
+ const result = await client.experienceFragment.upsert({ spaceId, environmentId, experienceFragmentId: entity.sys.id }, payload);
1517
1613
  import_logging9.logEmitter.emit("info", `UPDATE ExperienceFragment ${entity.sys.id}`);
1518
1614
  results.push(result);
1519
1615
  } else {
1520
1616
  const payload = { ...omitSys(entity), component: entity.sys.component, sys: { id: entity.sys.id, type: "ExperienceFragment" } };
1521
- const result = await plainClient.experienceFragment.upsert({ spaceId, environmentId, experienceFragmentId: entity.sys.id }, payload);
1617
+ const result = await client.experienceFragment.upsert({ spaceId, environmentId, experienceFragmentId: entity.sys.id }, payload);
1522
1618
  import_logging9.logEmitter.emit("info", `CREATE ExperienceFragment ${entity.sys.id}`);
1523
1619
  results.push(result);
1524
1620
  }
@@ -1538,7 +1634,7 @@ function pushToSpace({
1538
1634
  const sorted = sortOrReport(() => sortExperienceFragments(entitiesToPublish));
1539
1635
  const results = [];
1540
1636
  for (const entity of sorted) {
1541
- const published = await publishExoEntity("ExperienceFragment", entity, () => plainClient.experienceFragment.publish(
1637
+ const published = await publishExoEntity("ExperienceFragment", entity, () => client.experienceFragment.publish(
1542
1638
  { spaceId, environmentId, experienceFragmentId: entity.sys.id, version: entity.sys.version }
1543
1639
  ));
1544
1640
  if (published) results.push(published);
@@ -1555,12 +1651,12 @@ function pushToSpace({
1555
1651
  const existing = destinationDataById.experiences?.get(entity.sys.id);
1556
1652
  if (existing) {
1557
1653
  const payload = { ...entity, sys: { id: entity.sys.id, type: "Experience", version: existing.sys.version } };
1558
- const result = await plainClient.experience.upsert({ spaceId, environmentId, experienceId: entity.sys.id }, payload);
1654
+ const result = await client.experience.upsert({ spaceId, environmentId, experienceId: entity.sys.id }, payload);
1559
1655
  import_logging9.logEmitter.emit("info", `UPDATE Experience ${entity.sys.id}`);
1560
1656
  return result;
1561
1657
  } else {
1562
1658
  const payload = { ...omitSys(entity), experienceTemplate: entity.sys.experienceTemplate, sys: { id: entity.sys.id, type: "Experience" } };
1563
- const result = await plainClient.experience.upsert({ spaceId, environmentId, experienceId: entity.sys.id }, payload);
1659
+ const result = await client.experience.upsert({ spaceId, environmentId, experienceId: entity.sys.id }, payload);
1564
1660
  import_logging9.logEmitter.emit("info", `CREATE Experience ${entity.sys.id}`);
1565
1661
  return result;
1566
1662
  }
@@ -1579,7 +1675,7 @@ function pushToSpace({
1579
1675
  task: (0, import_listr2.wrapTask)(async (ctx) => {
1580
1676
  const entitiesToPublish = filterExoEntitiesToPublish(ctx.data.experiences, sourceData.experiences || []);
1581
1677
  const results = await Promise.all(entitiesToPublish.map(
1582
- (entity) => publishExoEntity("Experience", entity, () => plainClient.experience.publish(
1678
+ (entity) => publishExoEntity("Experience", entity, () => client.experience.publish(
1583
1679
  { spaceId, environmentId, experienceId: entity.sys.id, version: entity.sys.version }
1584
1680
  ))
1585
1681
  ));
@@ -1595,7 +1691,7 @@ function pushToSpace({
1595
1691
  task: (0, import_listr2.wrapTask)(async (ctx) => {
1596
1692
  const entitiesToUnpublish = filterExoEntitiesToUnpublish(ctx.data.experiences, sourceData.experiences || []);
1597
1693
  await Promise.all(entitiesToUnpublish.map(
1598
- (entity) => unpublishExoEntity("Experience", entity, () => plainClient.experience.unpublish(
1694
+ (entity) => unpublishExoEntity("Experience", entity, () => client.experience.unpublish(
1599
1695
  { spaceId, environmentId, experienceId: entity.sys.id, version: entity.sys.version }
1600
1696
  ))
1601
1697
  ));
@@ -1608,7 +1704,7 @@ function pushToSpace({
1608
1704
  const entitiesToUnpublish = filterExoEntitiesToUnpublish(ctx.data.experienceFragments, sourceData.experienceFragments || []);
1609
1705
  const sorted = sortExperienceFragments(entitiesToUnpublish).reverse();
1610
1706
  for (const entity of sorted) {
1611
- await unpublishExoEntity("ExperienceFragment", entity, () => plainClient.experienceFragment.unpublish(
1707
+ await unpublishExoEntity("ExperienceFragment", entity, () => client.experienceFragment.unpublish(
1612
1708
  { spaceId, environmentId, experienceFragmentId: entity.sys.id, version: entity.sys.version }
1613
1709
  ));
1614
1710
  }
@@ -1620,7 +1716,7 @@ function pushToSpace({
1620
1716
  task: (0, import_listr2.wrapTask)(async (ctx) => {
1621
1717
  const entitiesToUnpublish = filterExoEntitiesToUnpublish(ctx.data.experienceTemplates, sourceData.experienceTemplates || []);
1622
1718
  await Promise.all(entitiesToUnpublish.map(
1623
- (entity) => unpublishExoEntity("ExperienceTemplate", entity, () => plainClient.experienceTemplate.unpublish(
1719
+ (entity) => unpublishExoEntity("ExperienceTemplate", entity, () => client.experienceTemplate.unpublish(
1624
1720
  { spaceId, environmentId, experienceTemplateId: entity.sys.id, version: entity.sys.version }
1625
1721
  ))
1626
1722
  ));
@@ -1633,7 +1729,7 @@ function pushToSpace({
1633
1729
  const entitiesToUnpublish = filterExoEntitiesToUnpublish(ctx.data.components, sourceData.components || []);
1634
1730
  const sorted = sortComponents(entitiesToUnpublish).reverse();
1635
1731
  for (const entity of sorted) {
1636
- await unpublishExoEntity("Component", entity, () => plainClient.component.unpublish(
1732
+ await unpublishExoEntity("Component", entity, () => client.component.unpublish(
1637
1733
  { spaceId, environmentId, componentId: entity.sys.id, version: entity.sys.version }
1638
1734
  ));
1639
1735
  }
@@ -1645,7 +1741,7 @@ function pushToSpace({
1645
1741
  task: (0, import_listr2.wrapTask)(async (ctx) => {
1646
1742
  const entitiesToUnpublish = filterExoEntitiesToUnpublish(ctx.data.dataAssemblies, sourceData.dataAssemblies || []);
1647
1743
  await Promise.all(entitiesToUnpublish.map(
1648
- (entity) => unpublishExoEntity("DataAssembly", entity, () => plainClient.dataAssembly.unpublish(
1744
+ (entity) => unpublishExoEntity("DataAssembly", entity, () => client.dataAssembly.unpublish(
1649
1745
  { spaceId, environmentId, dataAssemblyId: entity.sys.id, version: entity.sys.version }
1650
1746
  ))
1651
1747
  ));
@@ -1658,15 +1754,15 @@ function omitSys(entity) {
1658
1754
  const { sys: _sys, ...rest } = entity;
1659
1755
  return rest;
1660
1756
  }
1661
- function archiveEntities2({ entities, sourceEntities, requestQueue }) {
1757
+ function archiveEntities2({ entities, sourceEntities, client, spaceId, environmentId, requestQueue }) {
1662
1758
  const entityIdsToArchive = sourceEntities.filter(({ original }) => original.sys.archivedVersion).map(({ original }) => original.sys.id);
1663
1759
  const entitiesToArchive = entities.filter((entity) => entityIdsToArchive.indexOf(entity.sys.id) !== -1);
1664
- return archiveEntities({ entities: entitiesToArchive, requestQueue });
1760
+ return archiveEntities({ entities: entitiesToArchive, client, spaceId, environmentId, requestQueue });
1665
1761
  }
1666
- function publishEntities2({ entities, sourceEntities, requestQueue }) {
1762
+ function publishEntities2({ entities, sourceEntities, client, spaceId, environmentId, requestQueue }) {
1667
1763
  const entityIdsToPublish = sourceEntities.filter(({ original }) => original.sys.publishedVersion).map(({ original }) => original.sys.id);
1668
1764
  const entitiesToPublish = entities.filter((entity) => entityIdsToPublish.indexOf(entity.sys.id) !== -1);
1669
- return publishEntities({ entities: entitiesToPublish, requestQueue });
1765
+ return publishEntities({ entities: entitiesToPublish, client, spaceId, environmentId, requestQueue });
1670
1766
  }
1671
1767
 
1672
1768
  // lib/transform/transform-space.ts
@@ -2192,7 +2288,8 @@ async function parseOptions(params) {
2192
2288
  rawProxy: false,
2193
2289
  uploadAssets: false,
2194
2290
  rateLimit: 7,
2195
- includeExperienceOrchestration: true
2291
+ includeExperienceOrchestration: true,
2292
+ host: "api.contentful.com"
2196
2293
  };
2197
2294
  const configFile = params.config ? require((0, import_path2.resolve)(process.cwd(), params.config)) : {};
2198
2295
  const options = {
@@ -2304,8 +2401,7 @@ async function runContentfulImport(params) {
2304
2401
  {
2305
2402
  title: "Initialize client",
2306
2403
  task: (0, import_listr4.wrapTask)(async (ctx) => {
2307
- ctx.client = initClient({ ...options, content: void 0 });
2308
- ctx.plainClient = initPlainClient({ ...options, content: void 0 });
2404
+ ctx.client = initClient({ ...options });
2309
2405
  })
2310
2406
  },
2311
2407
  {
@@ -2313,7 +2409,6 @@ async function runContentfulImport(params) {
2313
2409
  task: (0, import_listr4.wrapTask)(async (ctx) => {
2314
2410
  const destinationData = await getDestinationData({
2315
2411
  client: ctx.client,
2316
- plainClient: ctx.plainClient,
2317
2412
  spaceId: options.spaceId,
2318
2413
  environmentId: options.environmentId,
2319
2414
  sourceData: options.content,
@@ -2341,7 +2436,6 @@ async function runContentfulImport(params) {
2341
2436
  sourceData: ctx.sourceData,
2342
2437
  destinationData: ctx.destinationData,
2343
2438
  client: ctx.client,
2344
- plainClient: ctx.plainClient,
2345
2439
  spaceId: options.spaceId,
2346
2440
  includeExperienceOrchestration: options.includeExperienceOrchestration,
2347
2441
  environmentId: options.environmentId,