contentful-import 10.1.2 → 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 -183
  2. package/dist/index.mjs +280 -183
  3. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -31,13 +31,12 @@ function initClient(opts) {
31
31
  ...defaultOpts,
32
32
  ...opts
33
33
  };
34
- return createClient(config, { type: "legacy" });
35
- }
36
- function initPlainClient(opts) {
37
- return createClient({
38
- accessToken: opts.managementToken,
39
- host: opts.host,
40
- logHandler
34
+ return createClient(config, {
35
+ type: "plain",
36
+ defaults: {
37
+ spaceId: opts.spaceId,
38
+ environmentId: opts.environmentId
39
+ }
41
40
  });
42
41
  }
43
42
 
@@ -92,14 +91,14 @@ function isExoEntitlementError(err) {
92
91
  }
93
92
  }
94
93
  var EXO_M1_FEATURE = "exoM1";
95
- async function spaceHasExoM1Entitlement(plainClient, spaceId) {
94
+ async function spaceHasExoM1Entitlement(client, spaceId) {
96
95
  try {
97
- const space = await plainClient.space.get({ spaceId });
96
+ const space = await client.space.get({ spaceId });
98
97
  const organizationId = space.sys.organization?.sys?.id;
99
98
  if (!organizationId) {
100
99
  return null;
101
100
  }
102
- const entitlements = await plainClient.raw.get(
101
+ const entitlements = await client.raw.get(
103
102
  `/organizations/${organizationId}/organization_entitlement_set`
104
103
  );
105
104
  return entitlements.features?.[EXO_M1_FEATURE]?.value === true;
@@ -111,13 +110,6 @@ async function spaceHasExoM1Entitlement(plainClient, spaceId) {
111
110
  // lib/tasks/get-destination-data.ts
112
111
  var BATCH_CHAR_LIMIT = 1990;
113
112
  var BATCH_SIZE_LIMIT = 100;
114
- var OFFSET_QUERY_METHODS = {
115
- contentTypes: { name: "content types", method: "getContentTypes" },
116
- locales: { name: "locales", method: "getLocales" },
117
- entries: { name: "entries", method: "getEntries" },
118
- assets: { name: "assets", method: "getAssets" },
119
- tags: { name: "tags", method: "getTags" }
120
- };
121
113
  var CURSOR_QUERY_METHODS = {
122
114
  designTokens: { name: "design tokens", namespace: "designToken" },
123
115
  components: { name: "components", namespace: "component" },
@@ -126,47 +118,64 @@ var CURSOR_QUERY_METHODS = {
126
118
  dataAssemblies: { name: "data assemblies", namespace: "dataAssembly" },
127
119
  experiences: { name: "experiences", namespace: "experience" }
128
120
  };
129
- async function batchedIdQuery({ environment, type, ids, requestQueue }) {
130
- const method = OFFSET_QUERY_METHODS[type].method;
131
- const entityTypeName = OFFSET_QUERY_METHODS[type].name;
121
+ var ENTITY_METHODS = {
122
+ contentTypes: { name: "content types", ns: "contentType" },
123
+ entries: { name: "entries", ns: "entry" },
124
+ assets: { name: "assets", ns: "asset" },
125
+ locales: { name: "locales", ns: "locale" },
126
+ tags: { name: "tags", ns: "tag" }
127
+ };
128
+ async function batchedIdQuery({ client, spaceId, environmentId, type, ids, requestQueue }) {
129
+ const { name, ns } = ENTITY_METHODS[type];
132
130
  const batches = getIdBatches(ids);
133
131
  let totalFetched = 0;
134
132
  const allPendingResponses = batches.map((idBatch) => {
135
133
  return requestQueue.add(async () => {
136
- const response = await environment[method]({
137
- "sys.id[in]": idBatch,
138
- limit: idBatch.split(",").length
134
+ const response = await client[ns].getMany({
135
+ spaceId,
136
+ environmentId,
137
+ query: {
138
+ "sys.id[in]": idBatch,
139
+ limit: idBatch.split(",").length
140
+ }
139
141
  });
140
142
  totalFetched = totalFetched + response.items.length;
141
- logEmitter3.emit("info", `Fetched ${totalFetched} of ${response.total} ${entityTypeName}`);
143
+ logEmitter3.emit("info", `Fetched ${totalFetched} of ${response.total} ${name}`);
142
144
  return response.items;
143
145
  });
144
146
  });
145
147
  const responses = await Promise2.all(allPendingResponses);
146
148
  return responses.flat();
147
149
  }
148
- async function batchedPageQuery({ environment, type, requestQueue }) {
149
- const method = OFFSET_QUERY_METHODS[type].method;
150
- const entityTypeName = OFFSET_QUERY_METHODS[type].name;
150
+ async function batchedPageQuery({ client, spaceId, environmentId, type, requestQueue }) {
151
+ const { name, ns } = ENTITY_METHODS[type];
151
152
  let totalFetched = 0;
152
153
  const { items, total } = await requestQueue.add(async () => {
153
- const response = await environment[method]({
154
- skip: 0,
155
- limit: BATCH_SIZE_LIMIT
154
+ const response = await client[ns].getMany({
155
+ spaceId,
156
+ environmentId,
157
+ query: {
158
+ skip: 0,
159
+ limit: BATCH_SIZE_LIMIT
160
+ }
156
161
  });
157
162
  totalFetched += response.items.length;
158
- logEmitter3.emit("info", `Fetched ${totalFetched} of ${response.total} ${entityTypeName}`);
163
+ logEmitter3.emit("info", `Fetched ${totalFetched} of ${response.total} ${name}`);
159
164
  return { items: response.items, total: response.total };
160
165
  });
161
166
  const batches = getPagedBatches(totalFetched, total);
162
167
  const remainingTotalResponses = batches.map(({ skip }) => {
163
168
  return requestQueue.add(async () => {
164
- const response = await environment[method]({
165
- skip,
166
- limit: BATCH_SIZE_LIMIT
169
+ const response = await client[ns].getMany({
170
+ spaceId,
171
+ environmentId,
172
+ query: {
173
+ skip,
174
+ limit: BATCH_SIZE_LIMIT
175
+ }
167
176
  });
168
177
  totalFetched = totalFetched + response.items.length;
169
- logEmitter3.emit("info", `Fetched ${totalFetched} of ${response.total} ${entityTypeName}`);
178
+ logEmitter3.emit("info", `Fetched ${totalFetched} of ${response.total} ${name}`);
170
179
  return response.items;
171
180
  });
172
181
  });
@@ -203,14 +212,14 @@ function getPagedBatches(totalFetched, total) {
203
212
  }
204
213
  return batches;
205
214
  }
206
- async function cursorPaginatedQuery({ plainClient, spaceId, environmentId, type, requestQueue }) {
215
+ async function cursorPaginatedQuery({ client, spaceId, environmentId, type, requestQueue }) {
207
216
  const { name: entityTypeName, namespace } = CURSOR_QUERY_METHODS[type];
208
217
  let totalFetched = 0;
209
218
  let pageNext = void 0;
210
219
  const allItems = [];
211
220
  do {
212
221
  const items = await requestQueue.add(async () => {
213
- const response = await plainClient[namespace].getMany({
222
+ const response = await client[namespace].getMany({
214
223
  spaceId,
215
224
  environmentId,
216
225
  query: { limit: BATCH_SIZE_LIMIT, ...pageNext && { pageNext } }
@@ -239,7 +248,6 @@ async function cursorPaginatedQueryOrWarn(params) {
239
248
  }
240
249
  async function getDestinationData({
241
250
  client,
242
- plainClient,
243
251
  spaceId,
244
252
  environmentId,
245
253
  sourceData,
@@ -249,8 +257,6 @@ async function getDestinationData({
249
257
  includeExperienceOrchestration,
250
258
  requestQueue
251
259
  }) {
252
- const space = await client.getSpace(spaceId);
253
- const environment = await space.getEnvironment(environmentId);
254
260
  const result = {
255
261
  contentTypes: [],
256
262
  tags: [],
@@ -273,7 +279,9 @@ async function getDestinationData({
273
279
  const contentTypeIds = sourceData.contentTypes?.map((e) => e.sys.id);
274
280
  if (contentTypeIds) {
275
281
  result.contentTypes = batchedIdQuery({
276
- environment,
282
+ client,
283
+ spaceId,
284
+ environmentId,
277
285
  type: "contentTypes",
278
286
  ids: contentTypeIds,
279
287
  requestQueue
@@ -283,7 +291,9 @@ async function getDestinationData({
283
291
  const localeIds = sourceData.locales?.map((e) => e.sys.id);
284
292
  if (localeIds && localeIds.length) {
285
293
  result.locales = batchedPageQuery({
286
- environment,
294
+ client,
295
+ spaceId,
296
+ environmentId,
287
297
  type: "locales",
288
298
  requestQueue
289
299
  });
@@ -291,7 +301,7 @@ async function getDestinationData({
291
301
  }
292
302
  }
293
303
  try {
294
- result.tags = await batchedPageQuery({ environment, type: "tags", requestQueue });
304
+ result.tags = await batchedPageQuery({ client, spaceId, environmentId, type: "tags", requestQueue });
295
305
  } catch (_) {
296
306
  delete result.tags;
297
307
  }
@@ -302,7 +312,9 @@ async function getDestinationData({
302
312
  const assetIds = sourceData.assets?.map((e) => e.sys.id);
303
313
  if (entryIds && entryIds.length) {
304
314
  result.entries = batchedIdQuery({
305
- environment,
315
+ client,
316
+ spaceId,
317
+ environmentId,
306
318
  type: "entries",
307
319
  ids: entryIds,
308
320
  requestQueue
@@ -310,13 +322,15 @@ async function getDestinationData({
310
322
  }
311
323
  if (assetIds && assetIds.length) {
312
324
  result.assets = batchedIdQuery({
313
- environment,
325
+ client,
326
+ spaceId,
327
+ environmentId,
314
328
  type: "assets",
315
329
  ids: assetIds,
316
330
  requestQueue
317
331
  });
318
332
  }
319
- if (includeExperienceOrchestration && plainClient) {
333
+ if (includeExperienceOrchestration && client) {
320
334
  const sourceHasDesignTokens = Boolean(sourceData.designTokens?.length);
321
335
  const sourceHasComponents = Boolean(sourceData.components?.length);
322
336
  const sourceHasExperienceTemplates = Boolean(sourceData.experienceTemplates?.length);
@@ -324,29 +338,29 @@ async function getDestinationData({
324
338
  const sourceHasExperiences = Boolean(sourceData.experiences?.length);
325
339
  let entitled = true;
326
340
  if (sourceHasDesignTokens || sourceHasComponents || sourceHasExperienceTemplates || sourceHasExperienceFragments || sourceHasExperiences) {
327
- entitled = await spaceHasExoM1Entitlement(plainClient, spaceId);
341
+ entitled = await spaceHasExoM1Entitlement(client, spaceId);
328
342
  }
329
343
  if (entitled === false) {
330
344
  logEmitter3.emit("error", new Error("Skipping Experience Orchestration import: Experience Orchestration (ExO) is not enabled for this space"));
331
345
  } else {
332
346
  if (sourceHasDesignTokens) {
333
- result.designTokens = cursorPaginatedQueryOrWarn({ plainClient, spaceId, environmentId, type: "designTokens", requestQueue });
347
+ result.designTokens = cursorPaginatedQueryOrWarn({ client, spaceId, environmentId, type: "designTokens", requestQueue });
334
348
  }
335
349
  if (sourceHasComponents) {
336
- result.components = cursorPaginatedQueryOrWarn({ plainClient, spaceId, environmentId, type: "components", requestQueue });
350
+ result.components = cursorPaginatedQueryOrWarn({ client, spaceId, environmentId, type: "components", requestQueue });
337
351
  }
338
352
  if (sourceHasExperienceTemplates) {
339
- result.experienceTemplates = cursorPaginatedQueryOrWarn({ plainClient, spaceId, environmentId, type: "experienceTemplates", requestQueue });
353
+ result.experienceTemplates = cursorPaginatedQueryOrWarn({ client, spaceId, environmentId, type: "experienceTemplates", requestQueue });
340
354
  }
341
355
  if (sourceHasExperienceFragments) {
342
- result.experienceFragments = cursorPaginatedQueryOrWarn({ plainClient, spaceId, environmentId, type: "experienceFragments", requestQueue });
356
+ result.experienceFragments = cursorPaginatedQueryOrWarn({ client, spaceId, environmentId, type: "experienceFragments", requestQueue });
343
357
  }
344
358
  if (sourceHasExperiences) {
345
- result.experiences = cursorPaginatedQueryOrWarn({ plainClient, spaceId, environmentId, type: "experiences", requestQueue });
359
+ result.experiences = cursorPaginatedQueryOrWarn({ client, spaceId, environmentId, type: "experiences", requestQueue });
346
360
  }
347
361
  }
348
362
  if (sourceData.dataAssemblies?.length) {
349
- result.dataAssemblies = cursorPaginatedQueryOrWarn({ plainClient, spaceId, environmentId, type: "dataAssemblies", requestQueue });
363
+ result.dataAssemblies = cursorPaginatedQueryOrWarn({ client, spaceId, environmentId, type: "dataAssemblies", requestQueue });
350
364
  }
351
365
  }
352
366
  return Promise2.props(result);
@@ -393,9 +407,9 @@ async function getAssetStreamForURL(url, assetsDirectory) {
393
407
  throw error;
394
408
  }
395
409
  }
396
- async function processAssetForLocale(locale, asset, processingOptions) {
410
+ async function processAssetForLocale(client, spaceId, environmentId, locale, asset, processingOptions) {
397
411
  try {
398
- return await asset.processForLocale(locale, processingOptions);
412
+ return await client.asset.processForLocale({ spaceId, environmentId }, asset, locale, processingOptions);
399
413
  } catch (err) {
400
414
  if (err instanceof ContentfulEntityError) {
401
415
  err.entity = asset;
@@ -418,6 +432,9 @@ async function lastResult(promises) {
418
432
  }
419
433
  async function processAssets({
420
434
  assets: assets2,
435
+ client,
436
+ spaceId,
437
+ environmentId,
421
438
  timeout,
422
439
  retryLimit,
423
440
  requestQueue
@@ -435,7 +452,7 @@ async function processAssets({
435
452
  latestAssetVersion = await lastResult(
436
453
  locales2.map((locale) => {
437
454
  return requestQueue.add(
438
- () => processAssetForLocale(locale, asset, processingOptions)
455
+ () => processAssetForLocale(client, spaceId, environmentId, locale, asset, processingOptions)
439
456
  );
440
457
  })
441
458
  );
@@ -471,7 +488,7 @@ async function createEntitiesWithConcurrency({ context, entities, destinationEnt
471
488
  }
472
489
  return requestQueue.add(async () => {
473
490
  try {
474
- const createdEntity = await (destinationEntity ? updateDestinationWithSourceData(destinationEntity, entity.transformed) : createInDestination(context, entity.transformed));
491
+ const createdEntity = await (destinationEntity ? updateDestinationWithSourceData(context, destinationEntity, entity.transformed) : createInDestination(context, entity.transformed));
475
492
  creationSuccessNotifier(operation, createdEntity);
476
493
  return createdEntity;
477
494
  } catch (err) {
@@ -489,7 +506,7 @@ async function createEntitiesInSequence({ context, entities, destinationEntities
489
506
  const operation = destinationEntity ? "update" : "create";
490
507
  try {
491
508
  const createdEntity = await requestQueue.add(async () => {
492
- const createdOrUpdatedEntity = await (destinationEntity ? updateDestinationWithSourceData(destinationEntity, entity.transformed) : createInDestination(context, entity.transformed));
509
+ const createdOrUpdatedEntity = await (destinationEntity ? updateDestinationWithSourceData(context, destinationEntity, entity.transformed) : createInDestination(context, entity.transformed));
493
510
  return createdOrUpdatedEntity;
494
511
  });
495
512
  creationSuccessNotifier(operation, createdEntity);
@@ -505,11 +522,11 @@ async function createEntitiesInSequence({ context, entities, destinationEntities
505
522
  }
506
523
  async function createEntries({ context, entities, destinationEntitiesById, skipUpdates, requestQueue }) {
507
524
  const createdEntries = await Promise.all(entities.map((entry) => {
508
- return createEntry({ entry, target: context.target, skipContentModel: context.skipContentModel, destinationEntitiesById, skipUpdates, requestQueue });
525
+ return createEntry({ entry, context, destinationEntitiesById, skipUpdates, requestQueue });
509
526
  }));
510
527
  return createdEntries.filter((entry) => entry);
511
528
  }
512
- async function createEntry({ entry, target, skipContentModel, destinationEntitiesById, skipUpdates, requestQueue }) {
529
+ async function createEntry({ entry, context, destinationEntitiesById, skipUpdates, requestQueue }) {
513
530
  const contentTypeId = entry.original.sys.contentType.sys.id;
514
531
  const destinationEntry = getDestinationEntityForSourceEntity(
515
532
  destinationEntitiesById,
@@ -523,16 +540,16 @@ async function createEntry({ entry, target, skipContentModel, destinationEntitie
523
540
  }
524
541
  try {
525
542
  const createdOrUpdatedEntry = await requestQueue.add(() => {
526
- return destinationEntry ? updateDestinationWithSourceData(destinationEntry, entry.transformed) : createEntryInDestination(target, contentTypeId, entry.transformed);
543
+ return destinationEntry ? updateDestinationWithSourceData(context, destinationEntry, entry.transformed) : createEntryInDestination(context, contentTypeId, entry.transformed);
527
544
  });
528
545
  creationSuccessNotifier(operation, createdOrUpdatedEntry);
529
546
  return createdOrUpdatedEntry;
530
547
  } catch (err) {
531
548
  if (err instanceof Error) {
532
- if (skipContentModel && err.name === "UnknownField") {
549
+ if (context.skipContentModel && err.name === "UnknownField") {
533
550
  const errors = get(JSON.parse(err.message), "details.errors");
534
551
  entry.transformed.fields = cleanupUnknownFields(entry.transformed.fields, errors);
535
- return createEntry({ entry, target, skipContentModel, destinationEntitiesById, skipUpdates, requestQueue });
552
+ return createEntry({ entry, context, destinationEntitiesById, skipUpdates, requestQueue });
536
553
  }
537
554
  }
538
555
  if (err instanceof ContentfulEntityError) {
@@ -542,30 +559,78 @@ async function createEntry({ entry, target, skipContentModel, destinationEntitie
542
559
  return null;
543
560
  }
544
561
  }
545
- function updateDestinationWithSourceData(destinationEntity, sourceEntity) {
562
+ function updateDestinationWithSourceData(context, destinationEntity, sourceEntity) {
563
+ const { client, spaceId, environmentId, type } = context;
546
564
  const plainData = getPlainData(sourceEntity);
547
- assign(destinationEntity, plainData);
548
- return destinationEntity.update();
565
+ const updated = assign({}, plainData, { sys: destinationEntity.sys });
566
+ if (type === "Entry") {
567
+ return client.entry.update(
568
+ { spaceId, environmentId, entryId: destinationEntity.sys.id },
569
+ updated
570
+ );
571
+ }
572
+ if (type === "ContentType") {
573
+ return client.contentType.update(
574
+ { spaceId, environmentId, contentTypeId: destinationEntity.sys.id },
575
+ updated
576
+ );
577
+ }
578
+ if (type === "Asset") {
579
+ return client.asset.update(
580
+ { spaceId, environmentId, assetId: destinationEntity.sys.id },
581
+ updated
582
+ );
583
+ }
584
+ if (type === "Locale") {
585
+ return client.locale.update(
586
+ { spaceId, environmentId, localeId: destinationEntity.sys.id },
587
+ updated
588
+ );
589
+ }
590
+ if (type === "Webhook") {
591
+ return client.webhook.update(
592
+ { spaceId, webhookDefinitionId: destinationEntity.sys.id },
593
+ updated
594
+ );
595
+ }
596
+ throw new Error(`updateDestinationWithSourceData: unsupported type "${type}"`);
549
597
  }
550
598
  function createInDestination(context, sourceEntity) {
551
- const { type, target } = context;
599
+ const { type, client, spaceId, environmentId } = context;
552
600
  if (type === "Tag") {
553
601
  return createTagInDestination(context, sourceEntity);
554
602
  }
555
603
  const id = get(sourceEntity, "sys.id");
556
604
  const plainData = getPlainData(sourceEntity);
557
- return id ? target[`create${type}WithId`](id, plainData) : target[`create${type}`](plainData);
605
+ if (type === "ContentType") {
606
+ return id ? client.contentType.createWithId({ spaceId, environmentId, contentTypeId: id }, plainData) : client.contentType.create({ spaceId, environmentId }, plainData);
607
+ }
608
+ if (type === "Asset") {
609
+ return id ? client.asset.createWithId({ spaceId, environmentId, assetId: id }, plainData) : client.asset.create({ spaceId, environmentId }, plainData);
610
+ }
611
+ if (type === "Locale") {
612
+ return client.locale.create({ spaceId, environmentId }, plainData);
613
+ }
614
+ if (type === "Webhook") {
615
+ return id ? client.webhook.update({ spaceId, webhookDefinitionId: id }, { ...plainData, sys: { id } }) : client.webhook.create({ spaceId }, plainData);
616
+ }
617
+ throw new Error(`createInDestination: unsupported type "${type}"`);
558
618
  }
559
- function createEntryInDestination(space, contentTypeId, sourceEntity) {
619
+ function createEntryInDestination(context, contentTypeId, sourceEntity) {
620
+ const { client, spaceId, environmentId } = context;
560
621
  const id = sourceEntity.sys.id;
561
622
  const plainData = getPlainData(sourceEntity);
562
- return id ? space.createEntryWithId(contentTypeId, id, plainData) : space.createEntry(contentTypeId, plainData);
623
+ return id ? client.entry.createWithId({ spaceId, environmentId, contentTypeId, entryId: id }, plainData) : client.entry.create({ spaceId, environmentId, contentTypeId }, plainData);
563
624
  }
564
625
  function createTagInDestination(context, sourceEntity) {
626
+ const { client, spaceId, environmentId } = context;
565
627
  const id = sourceEntity.sys.id;
566
628
  const visibility = sourceEntity.sys.visibility || "private";
567
629
  const name = sourceEntity.name;
568
- return context.target.createTag(id, name, visibility);
630
+ return client.tag.createWithId(
631
+ { spaceId, environmentId, tagId: id },
632
+ { name, sys: { visibility } }
633
+ );
569
634
  }
570
635
  function handleCreationErrors(entity, err) {
571
636
  if (get(err, "error.sys.id") === "ValidationFailed") {
@@ -598,51 +663,61 @@ function creationSuccessNotifier(method, createdEntity) {
598
663
  return createdEntity;
599
664
  }
600
665
  function getPlainData(entity) {
601
- const data = entity.toPlainObject ? entity.toPlainObject() : entity;
602
- return omit(data, "sys");
666
+ return omit(entity, "sys");
603
667
  }
604
668
 
605
669
  // lib/tasks/push-to-space/publishing.ts
606
670
  import getEntityName3 from "contentful-batch-libs/dist/get-entity-name";
607
671
  import { logEmitter as logEmitter6 } from "contentful-batch-libs/dist/logging";
608
- async function publishEntities({ entities, requestQueue }) {
609
- const entitiesToPublish = entities.filter((entity2) => {
610
- if (!entity2 || !entity2.publish) {
611
- logEmitter6.emit("warning", `Unable to publish ${getEntityName3(entity2)}`);
612
- return false;
613
- }
614
- return true;
615
- });
616
- if (entitiesToPublish.length === 0) {
672
+ function publishEntity(client, spaceId, environmentId, entity) {
673
+ const id = entity.sys.id;
674
+ const type = entity.sys.type;
675
+ if (type === "Entry") {
676
+ return client.entry.publish({ spaceId, environmentId, entryId: id }, entity);
677
+ }
678
+ if (type === "Asset") {
679
+ return client.asset.publish({ spaceId, environmentId, assetId: id }, entity);
680
+ }
681
+ if (type === "ContentType") {
682
+ return client.contentType.publish({ spaceId, environmentId, contentTypeId: id }, entity);
683
+ }
684
+ throw new Error(`publishEntity: unsupported type "${type}"`);
685
+ }
686
+ function archiveEntity(client, spaceId, environmentId, entity) {
687
+ const id = entity.sys.id;
688
+ const type = entity.sys.type;
689
+ if (type === "Entry") {
690
+ return client.entry.archive({ spaceId, environmentId, entryId: id });
691
+ }
692
+ if (type === "Asset") {
693
+ return client.asset.archive({ spaceId, environmentId, assetId: id });
694
+ }
695
+ throw new Error(`archiveEntity: unsupported type "${type}"`);
696
+ }
697
+ async function publishEntities({ entities, client, spaceId, environmentId, requestQueue }) {
698
+ if (entities.length === 0) {
617
699
  logEmitter6.emit("info", "Skipping publishing since zero valid entities passed");
618
700
  return [];
619
701
  }
620
- const entity = entities[0].original || entities[0];
702
+ const entity = entities[0];
621
703
  const type = entity.sys.type || "unknown type";
622
704
  logEmitter6.emit("info", `Publishing ${entities.length} ${type}s`);
623
- const result = await runQueue(entitiesToPublish, [], requestQueue);
705
+ const result = await runQueue(entities, [], client, spaceId, environmentId, requestQueue);
624
706
  logEmitter6.emit("info", `Successfully published ${result.length} ${type}s`);
625
707
  return result;
626
708
  }
627
- async function archiveEntities({ entities, requestQueue }) {
628
- const entitiesToArchive = entities.filter((entity2) => {
629
- if (!entity2 || !entity2.archive) {
630
- logEmitter6.emit("warning", `Unable to archive ${getEntityName3(entity2)}`);
631
- return false;
632
- }
633
- return true;
634
- });
635
- if (entitiesToArchive.length === 0) {
709
+ async function archiveEntities({ entities, client, spaceId, environmentId, requestQueue }) {
710
+ if (entities.length === 0) {
636
711
  logEmitter6.emit("info", "Skipping archiving since zero valid entities passed");
637
712
  return [];
638
713
  }
639
- const entity = entities[0].original || entities[0];
714
+ const entity = entities[0];
640
715
  const type = entity.sys.type || "unknown type";
641
716
  logEmitter6.emit("info", `Archiving ${entities.length} ${type}s`);
642
- const pendingArchivedEntities = entitiesToArchive.map((entity2) => {
717
+ const pendingArchivedEntities = entities.map((entity2) => {
643
718
  return requestQueue.add(async () => {
644
719
  try {
645
- const archivedEntity = await entity2.archive();
720
+ const archivedEntity = await archiveEntity(client, spaceId, environmentId, entity2);
646
721
  return archivedEntity;
647
722
  } catch (err) {
648
723
  if (err instanceof ContentfulEntityError) {
@@ -658,12 +733,12 @@ async function archiveEntities({ entities, requestQueue }) {
658
733
  logEmitter6.emit("info", `Successfully archived ${allArchivedEntities.length} ${type}s`);
659
734
  return allArchivedEntities;
660
735
  }
661
- async function runQueue(queue, result = [], requestQueue) {
736
+ async function runQueue(queue, result = [], client, spaceId, environmentId, requestQueue) {
662
737
  const publishedEntities = [];
663
738
  for (const entity of queue) {
664
739
  logEmitter6.emit("info", `Publishing ${entity.sys.type} ${getEntityName3(entity)}`);
665
740
  try {
666
- const publishedEntity = await requestQueue.add(() => entity.publish());
741
+ const publishedEntity = await requestQueue.add(() => publishEntity(client, spaceId, environmentId, entity));
667
742
  publishedEntities.push(publishedEntity);
668
743
  } catch (err) {
669
744
  if (err instanceof ContentfulEntityError) {
@@ -683,7 +758,7 @@ async function runQueue(queue, result = [], requestQueue) {
683
758
  const unpublishedEntityNames = unpublishedEntities.map(getEntityName3).join(", ");
684
759
  logEmitter6.emit("error", `Could not publish the following entities: ${unpublishedEntityNames}`);
685
760
  } else {
686
- return runQueue(unpublishedEntities, result, requestQueue);
761
+ return runQueue(unpublishedEntities, result, client, spaceId, environmentId, requestQueue);
687
762
  }
688
763
  }
689
764
  return result;
@@ -851,8 +926,8 @@ function getSourceSpaceId(sourceEntities) {
851
926
  }
852
927
  return void 0;
853
928
  }
854
- async function ensureParentFolderGroupsExist(plainClient, organizationId) {
855
- const { items } = await plainClient.conceptScheme.getMany({
929
+ async function ensureParentFolderGroupsExist(client, organizationId) {
930
+ const { items } = await client.conceptScheme.getMany({
856
931
  organizationId,
857
932
  query: { purpose: "internal" }
858
933
  });
@@ -882,18 +957,18 @@ function deriveChildConceptMap(sourceEntities, destinationSpaceId) {
882
957
  }
883
958
  return childConceptMap;
884
959
  }
885
- async function createOrPatchChildConcepts(plainClient, organizationId, destinationSpaceId, childConceptMap) {
960
+ async function createOrPatchChildConcepts(client, organizationId, destinationSpaceId, childConceptMap) {
886
961
  const spaceLink = { sys: { type: "Link", linkType: "Space", id: destinationSpaceId } };
887
962
  for (const [sourceConceptId, { destConceptId }] of childConceptMap) {
888
963
  let prefLabel = { "en-US": destConceptId };
889
964
  try {
890
- const sourceConcept = await plainClient.concept.get({ organizationId, conceptId: sourceConceptId });
965
+ const sourceConcept = await client.concept.get({ organizationId, conceptId: sourceConceptId });
891
966
  if (sourceConcept?.prefLabel) prefLabel = sourceConcept.prefLabel;
892
967
  } catch {
893
968
  }
894
969
  let existing = null;
895
970
  try {
896
- existing = await plainClient.concept.get({ organizationId, conceptId: destConceptId });
971
+ existing = await client.concept.get({ organizationId, conceptId: destConceptId });
897
972
  } catch (err) {
898
973
  if (err?.name !== "NotFound") {
899
974
  logEmitter8.emit("warning", `Could not fetch destination child concept ${destConceptId}: ${err?.message ?? err}`);
@@ -901,8 +976,9 @@ async function createOrPatchChildConcepts(plainClient, organizationId, destinati
901
976
  }
902
977
  if (!existing) {
903
978
  try {
904
- await plainClient.concept.createWithId(
979
+ await client.concept.createWithId(
905
980
  { organizationId, conceptId: destConceptId },
981
+ // @ts-expect-error - CMA.js type needs to be updated to be aware of purpose: 'internal'
906
982
  { purpose: "internal", prefLabel, metadata: { spaces: [spaceLink] } }
907
983
  );
908
984
  logEmitter8.emit("info", `Created child folder concept ${destConceptId}`);
@@ -917,7 +993,7 @@ async function createOrPatchChildConcepts(plainClient, organizationId, destinati
917
993
  }
918
994
  if (patches.length > 0) {
919
995
  try {
920
- await plainClient.concept.patch(
996
+ await client.concept.patch(
921
997
  { organizationId, conceptId: destConceptId, version: existing.sys.version },
922
998
  patches
923
999
  );
@@ -929,14 +1005,14 @@ async function createOrPatchChildConcepts(plainClient, organizationId, destinati
929
1005
  }
930
1006
  }
931
1007
  }
932
- async function linkChildConceptsToParentGroups(plainClient, organizationId, childConceptMap, parentGroups) {
1008
+ async function linkChildConceptsToParentGroups(client, organizationId, childConceptMap, parentGroups) {
933
1009
  for (const [, { destConceptId, parentGroupId }] of childConceptMap) {
934
1010
  const parentGroup = parentGroups.get(parentGroupId);
935
1011
  if (!parentGroup) continue;
936
1012
  const alreadyLinked = (parentGroup.concepts ?? []).some((c) => c.sys.id === destConceptId);
937
1013
  if (alreadyLinked) continue;
938
1014
  try {
939
- const updated = await plainClient.conceptScheme.patch(
1015
+ const updated = await client.conceptScheme.patch(
940
1016
  { organizationId, conceptSchemeId: parentGroupId, version: parentGroup.sys.version },
941
1017
  [{ op: "add", path: "/concepts/-", value: { sys: { type: "Link", linkType: "TaxonomyConcept", id: destConceptId } } }]
942
1018
  );
@@ -958,7 +1034,7 @@ function rewriteEntityFolderConcepts(entities, childConceptMap) {
958
1034
  }
959
1035
  }
960
1036
  async function importExoFolders({
961
- plainClient,
1037
+ client,
962
1038
  organizationId,
963
1039
  destinationSpaceId,
964
1040
  sourceEntities
@@ -968,7 +1044,7 @@ async function importExoFolders({
968
1044
  logEmitter8.emit("info", "Source and destination space are the same \u2014 skipping ExO folder import");
969
1045
  return;
970
1046
  }
971
- const parentGroups = await ensureParentFolderGroupsExist(plainClient, organizationId);
1047
+ const parentGroups = await ensureParentFolderGroupsExist(client, organizationId);
972
1048
  if (parentGroups.size === 0) {
973
1049
  logEmitter8.emit("warn", "One or more Experience Orchestration folder group concept schemes are missing in the destination organization. Please create them before importing.");
974
1050
  return;
@@ -976,8 +1052,8 @@ async function importExoFolders({
976
1052
  const childConceptMap = deriveChildConceptMap(sourceEntities, destinationSpaceId);
977
1053
  if (childConceptMap.size === 0) return;
978
1054
  logEmitter8.emit("info", `Importing ${childConceptMap.size} ExO folder concept(s) into destination space ${destinationSpaceId}`);
979
- await createOrPatchChildConcepts(plainClient, organizationId, destinationSpaceId, childConceptMap);
980
- await linkChildConceptsToParentGroups(plainClient, organizationId, childConceptMap, parentGroups);
1055
+ await createOrPatchChildConcepts(client, organizationId, destinationSpaceId, childConceptMap);
1056
+ await linkChildConceptsToParentGroups(client, organizationId, childConceptMap, parentGroups);
981
1057
  const allEntities = [
982
1058
  ...sourceEntities.designTokens ?? [],
983
1059
  ...sourceEntities.components ?? [],
@@ -1019,7 +1095,6 @@ function pushToSpace({
1019
1095
  sourceData,
1020
1096
  destinationData = {},
1021
1097
  client,
1022
- plainClient,
1023
1098
  spaceId,
1024
1099
  environmentId,
1025
1100
  includeExperienceOrchestration,
@@ -1056,15 +1131,6 @@ function pushToSpace({
1056
1131
  destinationDataById[entityType] = entitiesById;
1057
1132
  }
1058
1133
  return new Listr([
1059
- {
1060
- title: "Connecting to space",
1061
- task: wrapTask(async (ctx) => {
1062
- const space = await client.getSpace(spaceId);
1063
- const environment = await space.getEnvironment(environmentId);
1064
- ctx.space = space;
1065
- ctx.environment = environment;
1066
- })
1067
- },
1068
1134
  {
1069
1135
  title: "Importing Locales",
1070
1136
  task: wrapTask(async (ctx) => {
@@ -1072,7 +1138,7 @@ function pushToSpace({
1072
1138
  return;
1073
1139
  }
1074
1140
  const locales2 = await createLocales({
1075
- context: { target: ctx.environment, type: "Locale" },
1141
+ context: { client, spaceId, environmentId, type: "Locale" },
1076
1142
  entities: sourceData.locales,
1077
1143
  destinationEntitiesById: destinationDataById.locales,
1078
1144
  requestQueue
@@ -1088,7 +1154,7 @@ function pushToSpace({
1088
1154
  return;
1089
1155
  }
1090
1156
  const contentTypes2 = await createEntities({
1091
- context: { target: ctx.environment, type: "ContentType" },
1157
+ context: { client, spaceId, environmentId, type: "ContentType" },
1092
1158
  entities: sourceData.contentTypes,
1093
1159
  destinationEntitiesById: destinationDataById.contentTypes,
1094
1160
  skipUpdates: false,
@@ -1104,6 +1170,9 @@ function pushToSpace({
1104
1170
  const publishedContentTypes = await publishEntities2({
1105
1171
  entities: ctx.data.contentTypes,
1106
1172
  sourceEntities: sourceData.contentTypes,
1173
+ client,
1174
+ spaceId,
1175
+ environmentId,
1107
1176
  requestQueue
1108
1177
  });
1109
1178
  ctx.data.contentTypes = publishedContentTypes;
@@ -1115,7 +1184,7 @@ function pushToSpace({
1115
1184
  task: wrapTask(async (ctx) => {
1116
1185
  if (sourceData.tags && destinationDataById.tags) {
1117
1186
  const tags2 = await createEntities({
1118
- context: { target: ctx.environment, type: "Tag" },
1187
+ context: { client, spaceId, environmentId, type: "Tag" },
1119
1188
  entities: sourceData.tags,
1120
1189
  destinationEntitiesById: destinationDataById.tags,
1121
1190
  skipUpdates: false,
@@ -1142,14 +1211,24 @@ function pushToSpace({
1142
1211
  return;
1143
1212
  }
1144
1213
  try {
1145
- const ctEditorInterface = await requestQueue.add(() => ctx.environment.getEditorInterfaceForContentType(contentType.sys.id));
1214
+ const ctEditorInterface = await requestQueue.add(
1215
+ () => client.editorInterface.get({ spaceId, environmentId, contentTypeId: contentType.sys.id })
1216
+ );
1146
1217
  logEmitter9.emit("info", `Fetched editor interface for ${contentType.name}`);
1147
- ctEditorInterface.controls = editorInterface.controls;
1148
- ctEditorInterface.groupControls = editorInterface.groupControls;
1149
- ctEditorInterface.editorLayout = editorInterface.editorLayout;
1150
- ctEditorInterface.sidebar = editorInterface.sidebar;
1151
- ctEditorInterface.editors = editorInterface.editors;
1152
- const updatedEditorInterface = await requestQueue.add(() => ctEditorInterface.update());
1218
+ const updatedData = {
1219
+ ...ctEditorInterface,
1220
+ controls: editorInterface.controls,
1221
+ groupControls: editorInterface.groupControls,
1222
+ editorLayout: editorInterface.editorLayout,
1223
+ sidebar: editorInterface.sidebar,
1224
+ editors: editorInterface.editors
1225
+ };
1226
+ const updatedEditorInterface = await requestQueue.add(
1227
+ () => client.editorInterface.update(
1228
+ { spaceId, environmentId, contentTypeId: contentType.sys.id },
1229
+ updatedData
1230
+ )
1231
+ );
1153
1232
  return updatedEditorInterface;
1154
1233
  } catch (err) {
1155
1234
  err.entity = editorInterface;
@@ -1173,10 +1252,10 @@ function pushToSpace({
1173
1252
  try {
1174
1253
  logEmitter9.emit("info", `Uploading Asset file ${file.upload}`);
1175
1254
  const assetStream = await getAssetStreamForURL(file.upload, assetsDirectory);
1176
- const upload = await ctx.environment.createUpload({
1177
- fileName: asset.transformed.sys.id,
1178
- file: assetStream
1179
- });
1255
+ const upload = await client.upload.create(
1256
+ { spaceId, environmentId },
1257
+ { file: assetStream }
1258
+ );
1180
1259
  delete file.upload;
1181
1260
  file.uploadFrom = {
1182
1261
  sys: {
@@ -1204,7 +1283,7 @@ function pushToSpace({
1204
1283
  return;
1205
1284
  }
1206
1285
  const assetsToProcess = await createEntities({
1207
- context: { target: ctx.environment, type: "Asset" },
1286
+ context: { client, spaceId, environmentId, type: "Asset" },
1208
1287
  entities: sourceData.assets,
1209
1288
  destinationEntitiesById: destinationDataById.assets,
1210
1289
  skipUpdates: skipAssetUpdates,
@@ -1212,6 +1291,9 @@ function pushToSpace({
1212
1291
  });
1213
1292
  const processedAssets = await processAssets({
1214
1293
  assets: assetsToProcess,
1294
+ client,
1295
+ spaceId,
1296
+ environmentId,
1215
1297
  timeout,
1216
1298
  retryLimit,
1217
1299
  requestQueue
@@ -1226,6 +1308,9 @@ function pushToSpace({
1226
1308
  const publishedAssets = await publishEntities2({
1227
1309
  entities: ctx.data.assets,
1228
1310
  sourceEntities: sourceData.assets,
1311
+ client,
1312
+ spaceId,
1313
+ environmentId,
1229
1314
  requestQueue
1230
1315
  });
1231
1316
  ctx.data.publishedAssets = publishedAssets;
@@ -1238,6 +1323,9 @@ function pushToSpace({
1238
1323
  const archivedAssets = await archiveEntities2({
1239
1324
  entities: ctx.data.assets,
1240
1325
  sourceEntities: sourceData.assets,
1326
+ client,
1327
+ spaceId,
1328
+ environmentId,
1241
1329
  requestQueue
1242
1330
  });
1243
1331
  ctx.data.archivedAssets = archivedAssets;
@@ -1248,7 +1336,7 @@ function pushToSpace({
1248
1336
  title: "Importing Content Entries",
1249
1337
  task: wrapTask(async (ctx) => {
1250
1338
  const entries2 = await createEntries({
1251
- context: { target: ctx.environment, skipContentModel },
1339
+ context: { client, spaceId, environmentId, skipContentModel, type: "Entry" },
1252
1340
  entities: sourceData.entries,
1253
1341
  destinationEntitiesById: destinationDataById.entries,
1254
1342
  skipUpdates: skipContentUpdates,
@@ -1264,6 +1352,9 @@ function pushToSpace({
1264
1352
  const publishedEntries = await publishEntities2({
1265
1353
  entities: ctx.data.entries,
1266
1354
  sourceEntities: sourceData.entries,
1355
+ client,
1356
+ spaceId,
1357
+ environmentId,
1267
1358
  requestQueue
1268
1359
  });
1269
1360
  ctx.data.publishedEntries = publishedEntries;
@@ -1276,6 +1367,9 @@ function pushToSpace({
1276
1367
  const archivedEntries = await archiveEntities2({
1277
1368
  entities: ctx.data.entries,
1278
1369
  sourceEntities: sourceData.entries,
1370
+ client,
1371
+ spaceId,
1372
+ environmentId,
1279
1373
  requestQueue
1280
1374
  });
1281
1375
  ctx.data.archivedEntries = archivedEntries;
@@ -1289,7 +1383,7 @@ function pushToSpace({
1289
1383
  return;
1290
1384
  }
1291
1385
  const webhooks2 = await createEntities({
1292
- context: { target: ctx.space, type: "Webhook" },
1386
+ context: { client, spaceId, environmentId, type: "Webhook" },
1293
1387
  entities: sourceData.webhooks,
1294
1388
  destinationEntitiesById: destinationDataById.webhooks,
1295
1389
  requestQueue
@@ -1300,19 +1394,24 @@ function pushToSpace({
1300
1394
  },
1301
1395
  {
1302
1396
  title: "Create ExO Folders",
1303
- task: wrapTask(async (ctx) => {
1304
- await importExoFolders({
1305
- plainClient,
1306
- organizationId: ctx.space.sys.organization.sys.id,
1307
- destinationSpaceId: spaceId,
1308
- sourceEntities: {
1309
- designTokens: sourceData.designTokens,
1310
- components: sourceData.components,
1311
- experienceTemplates: sourceData.experienceTemplates,
1312
- experienceFragments: sourceData.experienceFragments,
1313
- experiences: sourceData.experiences
1314
- }
1315
- });
1397
+ task: wrapTask(async () => {
1398
+ try {
1399
+ const space = await client.space.get({ spaceId });
1400
+ await importExoFolders({
1401
+ client,
1402
+ organizationId: space.sys.organization.sys.id,
1403
+ destinationSpaceId: spaceId,
1404
+ sourceEntities: {
1405
+ designTokens: sourceData.designTokens,
1406
+ components: sourceData.components,
1407
+ experienceTemplates: sourceData.experienceTemplates,
1408
+ experienceFragments: sourceData.experienceFragments,
1409
+ experiences: sourceData.experiences
1410
+ }
1411
+ });
1412
+ } catch (error) {
1413
+ logEmitter9.emit("warning", `Unable to create Experience Orchestration (ExO) folders, error: ${error}`);
1414
+ }
1316
1415
  }),
1317
1416
  skip: () => !includeExperienceOrchestration
1318
1417
  },
@@ -1325,14 +1424,14 @@ function pushToSpace({
1325
1424
  let result;
1326
1425
  if (existing) {
1327
1426
  const payload = { ...omitSys(entity), sys: buildDataAssemblySys(entity, existing.sys.version) };
1328
- result = await withGraphQLSchemaBackoff(() => plainClient.dataAssembly.update(
1427
+ result = await withGraphQLSchemaBackoff(() => client.dataAssembly.update(
1329
1428
  { spaceId, environmentId, dataAssemblyId: entity.sys.id },
1330
1429
  payload
1331
1430
  ));
1332
1431
  logEmitter9.emit("info", `UPDATE DataAssembly ${entity.sys.id}`);
1333
1432
  } else {
1334
1433
  const payload = { ...omitSys(entity), sys: buildDataAssemblySys(entity, 0) };
1335
- result = await withGraphQLSchemaBackoff(() => plainClient.dataAssembly.update(
1434
+ result = await withGraphQLSchemaBackoff(() => client.dataAssembly.update(
1336
1435
  { spaceId, environmentId, dataAssemblyId: entity.sys.id },
1337
1436
  payload
1338
1437
  ));
@@ -1354,7 +1453,7 @@ function pushToSpace({
1354
1453
  task: wrapTask(async (ctx) => {
1355
1454
  const entitiesToPublish = filterExoEntitiesToPublish(ctx.data.dataAssemblies, sourceData.dataAssemblies || []);
1356
1455
  const results = await Promise.all(entitiesToPublish.map(
1357
- (entity) => publishExoEntity("DataAssembly", entity, () => plainClient.dataAssembly.publish(
1456
+ (entity) => publishExoEntity("DataAssembly", entity, () => client.dataAssembly.publish(
1358
1457
  { spaceId, environmentId, dataAssemblyId: entity.sys.id, version: entity.sys.version }
1359
1458
  ))
1360
1459
  ));
@@ -1370,12 +1469,12 @@ function pushToSpace({
1370
1469
  const existing = destinationDataById.designTokens?.get(entity.sys.id);
1371
1470
  if (existing) {
1372
1471
  const payload = { ...entity, sys: { id: entity.sys.id, type: "DesignToken", version: existing.sys.version } };
1373
- const result = await plainClient.designToken.upsert({ spaceId, environmentId, designTokenId: entity.sys.id }, payload);
1472
+ const result = await client.designToken.upsert({ spaceId, environmentId, designTokenId: entity.sys.id }, payload);
1374
1473
  logEmitter9.emit("info", `UPDATE DesignToken ${entity.sys.id}`);
1375
1474
  return result;
1376
1475
  } else {
1377
1476
  const payload = { ...omitSys(entity), sys: { id: entity.sys.id, type: "DesignToken" } };
1378
- const result = await plainClient.designToken.upsert({ spaceId, environmentId, designTokenId: entity.sys.id }, payload);
1477
+ const result = await client.designToken.upsert({ spaceId, environmentId, designTokenId: entity.sys.id }, payload);
1379
1478
  logEmitter9.emit("info", `CREATE DesignToken ${entity.sys.id}`);
1380
1479
  return result;
1381
1480
  }
@@ -1399,12 +1498,12 @@ function pushToSpace({
1399
1498
  const existing = destinationDataById.components?.get(entity.sys.id);
1400
1499
  if (existing) {
1401
1500
  const payload = { ...entity, sys: { id: entity.sys.id, type: "Component", version: existing.sys.version } };
1402
- const result = await plainClient.component.upsert({ spaceId, environmentId, componentId: entity.sys.id }, payload);
1501
+ const result = await client.component.upsert({ spaceId, environmentId, componentId: entity.sys.id }, payload);
1403
1502
  logEmitter9.emit("info", `UPDATE Component ${entity.sys.id}`);
1404
1503
  results.push(result);
1405
1504
  } else {
1406
1505
  const payload = { ...omitSys(entity), sys: { id: entity.sys.id, type: "Component" } };
1407
- const result = await plainClient.component.upsert({ spaceId, environmentId, componentId: entity.sys.id }, payload);
1506
+ const result = await client.component.upsert({ spaceId, environmentId, componentId: entity.sys.id }, payload);
1408
1507
  logEmitter9.emit("info", `CREATE Component ${entity.sys.id}`);
1409
1508
  results.push(result);
1410
1509
  }
@@ -1424,7 +1523,7 @@ function pushToSpace({
1424
1523
  const sorted = sortOrReport(() => sortComponents(entitiesToPublish));
1425
1524
  const results = [];
1426
1525
  for (const entity of sorted) {
1427
- const published = await publishExoEntity("Component", entity, () => plainClient.component.publish(
1526
+ const published = await publishExoEntity("Component", entity, () => client.component.publish(
1428
1527
  { spaceId, environmentId, componentId: entity.sys.id, version: entity.sys.version }
1429
1528
  ));
1430
1529
  if (published) results.push(published);
@@ -1441,12 +1540,12 @@ function pushToSpace({
1441
1540
  const existing = destinationDataById.experienceTemplates?.get(entity.sys.id);
1442
1541
  if (existing) {
1443
1542
  const payload = { ...entity, sys: { id: entity.sys.id, type: "ExperienceTemplate", version: existing.sys.version } };
1444
- const result = await plainClient.experienceTemplate.upsert({ spaceId, environmentId, experienceTemplateId: entity.sys.id }, payload);
1543
+ const result = await client.experienceTemplate.upsert({ spaceId, environmentId, experienceTemplateId: entity.sys.id }, payload);
1445
1544
  logEmitter9.emit("info", `UPDATE ExperienceTemplate ${entity.sys.id}`);
1446
1545
  return result;
1447
1546
  } else {
1448
1547
  const payload = { ...omitSys(entity), sys: { id: entity.sys.id, type: "ExperienceTemplate" } };
1449
- const result = await plainClient.experienceTemplate.upsert({ spaceId, environmentId, experienceTemplateId: entity.sys.id }, payload);
1548
+ const result = await client.experienceTemplate.upsert({ spaceId, environmentId, experienceTemplateId: entity.sys.id }, payload);
1450
1549
  logEmitter9.emit("info", `CREATE ExperienceTemplate ${entity.sys.id}`);
1451
1550
  return result;
1452
1551
  }
@@ -1465,7 +1564,7 @@ function pushToSpace({
1465
1564
  task: wrapTask(async (ctx) => {
1466
1565
  const entitiesToPublish = filterExoEntitiesToPublish(ctx.data.experienceTemplates, sourceData.experienceTemplates || []);
1467
1566
  const results = await Promise.all(entitiesToPublish.map(
1468
- (entity) => publishExoEntity("ExperienceTemplate", entity, () => plainClient.experienceTemplate.publish(
1567
+ (entity) => publishExoEntity("ExperienceTemplate", entity, () => client.experienceTemplate.publish(
1469
1568
  { spaceId, environmentId, experienceTemplateId: entity.sys.id, version: entity.sys.version }
1470
1569
  ))
1471
1570
  ));
@@ -1483,12 +1582,12 @@ function pushToSpace({
1483
1582
  const existing = destinationDataById.experienceFragments?.get(entity.sys.id);
1484
1583
  if (existing) {
1485
1584
  const payload = { ...entity, sys: { id: entity.sys.id, type: "ExperienceFragment", version: existing.sys.version } };
1486
- const result = await plainClient.experienceFragment.upsert({ spaceId, environmentId, experienceFragmentId: entity.sys.id }, payload);
1585
+ const result = await client.experienceFragment.upsert({ spaceId, environmentId, experienceFragmentId: entity.sys.id }, payload);
1487
1586
  logEmitter9.emit("info", `UPDATE ExperienceFragment ${entity.sys.id}`);
1488
1587
  results.push(result);
1489
1588
  } else {
1490
1589
  const payload = { ...omitSys(entity), component: entity.sys.component, sys: { id: entity.sys.id, type: "ExperienceFragment" } };
1491
- const result = await plainClient.experienceFragment.upsert({ spaceId, environmentId, experienceFragmentId: entity.sys.id }, payload);
1590
+ const result = await client.experienceFragment.upsert({ spaceId, environmentId, experienceFragmentId: entity.sys.id }, payload);
1492
1591
  logEmitter9.emit("info", `CREATE ExperienceFragment ${entity.sys.id}`);
1493
1592
  results.push(result);
1494
1593
  }
@@ -1508,7 +1607,7 @@ function pushToSpace({
1508
1607
  const sorted = sortOrReport(() => sortExperienceFragments(entitiesToPublish));
1509
1608
  const results = [];
1510
1609
  for (const entity of sorted) {
1511
- const published = await publishExoEntity("ExperienceFragment", entity, () => plainClient.experienceFragment.publish(
1610
+ const published = await publishExoEntity("ExperienceFragment", entity, () => client.experienceFragment.publish(
1512
1611
  { spaceId, environmentId, experienceFragmentId: entity.sys.id, version: entity.sys.version }
1513
1612
  ));
1514
1613
  if (published) results.push(published);
@@ -1525,12 +1624,12 @@ function pushToSpace({
1525
1624
  const existing = destinationDataById.experiences?.get(entity.sys.id);
1526
1625
  if (existing) {
1527
1626
  const payload = { ...entity, sys: { id: entity.sys.id, type: "Experience", version: existing.sys.version } };
1528
- const result = await plainClient.experience.upsert({ spaceId, environmentId, experienceId: entity.sys.id }, payload);
1627
+ const result = await client.experience.upsert({ spaceId, environmentId, experienceId: entity.sys.id }, payload);
1529
1628
  logEmitter9.emit("info", `UPDATE Experience ${entity.sys.id}`);
1530
1629
  return result;
1531
1630
  } else {
1532
1631
  const payload = { ...omitSys(entity), experienceTemplate: entity.sys.experienceTemplate, sys: { id: entity.sys.id, type: "Experience" } };
1533
- const result = await plainClient.experience.upsert({ spaceId, environmentId, experienceId: entity.sys.id }, payload);
1632
+ const result = await client.experience.upsert({ spaceId, environmentId, experienceId: entity.sys.id }, payload);
1534
1633
  logEmitter9.emit("info", `CREATE Experience ${entity.sys.id}`);
1535
1634
  return result;
1536
1635
  }
@@ -1549,7 +1648,7 @@ function pushToSpace({
1549
1648
  task: wrapTask(async (ctx) => {
1550
1649
  const entitiesToPublish = filterExoEntitiesToPublish(ctx.data.experiences, sourceData.experiences || []);
1551
1650
  const results = await Promise.all(entitiesToPublish.map(
1552
- (entity) => publishExoEntity("Experience", entity, () => plainClient.experience.publish(
1651
+ (entity) => publishExoEntity("Experience", entity, () => client.experience.publish(
1553
1652
  { spaceId, environmentId, experienceId: entity.sys.id, version: entity.sys.version }
1554
1653
  ))
1555
1654
  ));
@@ -1565,7 +1664,7 @@ function pushToSpace({
1565
1664
  task: wrapTask(async (ctx) => {
1566
1665
  const entitiesToUnpublish = filterExoEntitiesToUnpublish(ctx.data.experiences, sourceData.experiences || []);
1567
1666
  await Promise.all(entitiesToUnpublish.map(
1568
- (entity) => unpublishExoEntity("Experience", entity, () => plainClient.experience.unpublish(
1667
+ (entity) => unpublishExoEntity("Experience", entity, () => client.experience.unpublish(
1569
1668
  { spaceId, environmentId, experienceId: entity.sys.id, version: entity.sys.version }
1570
1669
  ))
1571
1670
  ));
@@ -1578,7 +1677,7 @@ function pushToSpace({
1578
1677
  const entitiesToUnpublish = filterExoEntitiesToUnpublish(ctx.data.experienceFragments, sourceData.experienceFragments || []);
1579
1678
  const sorted = sortExperienceFragments(entitiesToUnpublish).reverse();
1580
1679
  for (const entity of sorted) {
1581
- await unpublishExoEntity("ExperienceFragment", entity, () => plainClient.experienceFragment.unpublish(
1680
+ await unpublishExoEntity("ExperienceFragment", entity, () => client.experienceFragment.unpublish(
1582
1681
  { spaceId, environmentId, experienceFragmentId: entity.sys.id, version: entity.sys.version }
1583
1682
  ));
1584
1683
  }
@@ -1590,7 +1689,7 @@ function pushToSpace({
1590
1689
  task: wrapTask(async (ctx) => {
1591
1690
  const entitiesToUnpublish = filterExoEntitiesToUnpublish(ctx.data.experienceTemplates, sourceData.experienceTemplates || []);
1592
1691
  await Promise.all(entitiesToUnpublish.map(
1593
- (entity) => unpublishExoEntity("ExperienceTemplate", entity, () => plainClient.experienceTemplate.unpublish(
1692
+ (entity) => unpublishExoEntity("ExperienceTemplate", entity, () => client.experienceTemplate.unpublish(
1594
1693
  { spaceId, environmentId, experienceTemplateId: entity.sys.id, version: entity.sys.version }
1595
1694
  ))
1596
1695
  ));
@@ -1603,7 +1702,7 @@ function pushToSpace({
1603
1702
  const entitiesToUnpublish = filterExoEntitiesToUnpublish(ctx.data.components, sourceData.components || []);
1604
1703
  const sorted = sortComponents(entitiesToUnpublish).reverse();
1605
1704
  for (const entity of sorted) {
1606
- await unpublishExoEntity("Component", entity, () => plainClient.component.unpublish(
1705
+ await unpublishExoEntity("Component", entity, () => client.component.unpublish(
1607
1706
  { spaceId, environmentId, componentId: entity.sys.id, version: entity.sys.version }
1608
1707
  ));
1609
1708
  }
@@ -1615,7 +1714,7 @@ function pushToSpace({
1615
1714
  task: wrapTask(async (ctx) => {
1616
1715
  const entitiesToUnpublish = filterExoEntitiesToUnpublish(ctx.data.dataAssemblies, sourceData.dataAssemblies || []);
1617
1716
  await Promise.all(entitiesToUnpublish.map(
1618
- (entity) => unpublishExoEntity("DataAssembly", entity, () => plainClient.dataAssembly.unpublish(
1717
+ (entity) => unpublishExoEntity("DataAssembly", entity, () => client.dataAssembly.unpublish(
1619
1718
  { spaceId, environmentId, dataAssemblyId: entity.sys.id, version: entity.sys.version }
1620
1719
  ))
1621
1720
  ));
@@ -1628,15 +1727,15 @@ function omitSys(entity) {
1628
1727
  const { sys: _sys, ...rest } = entity;
1629
1728
  return rest;
1630
1729
  }
1631
- function archiveEntities2({ entities, sourceEntities, requestQueue }) {
1730
+ function archiveEntities2({ entities, sourceEntities, client, spaceId, environmentId, requestQueue }) {
1632
1731
  const entityIdsToArchive = sourceEntities.filter(({ original }) => original.sys.archivedVersion).map(({ original }) => original.sys.id);
1633
1732
  const entitiesToArchive = entities.filter((entity) => entityIdsToArchive.indexOf(entity.sys.id) !== -1);
1634
- return archiveEntities({ entities: entitiesToArchive, requestQueue });
1733
+ return archiveEntities({ entities: entitiesToArchive, client, spaceId, environmentId, requestQueue });
1635
1734
  }
1636
- function publishEntities2({ entities, sourceEntities, requestQueue }) {
1735
+ function publishEntities2({ entities, sourceEntities, client, spaceId, environmentId, requestQueue }) {
1637
1736
  const entityIdsToPublish = sourceEntities.filter(({ original }) => original.sys.publishedVersion).map(({ original }) => original.sys.id);
1638
1737
  const entitiesToPublish = entities.filter((entity) => entityIdsToPublish.indexOf(entity.sys.id) !== -1);
1639
- return publishEntities({ entities: entitiesToPublish, requestQueue });
1738
+ return publishEntities({ entities: entitiesToPublish, client, spaceId, environmentId, requestQueue });
1640
1739
  }
1641
1740
 
1642
1741
  // lib/transform/transform-space.ts
@@ -2159,7 +2258,8 @@ async function parseOptions(params) {
2159
2258
  rawProxy: false,
2160
2259
  uploadAssets: false,
2161
2260
  rateLimit: 7,
2162
- includeExperienceOrchestration: true
2261
+ includeExperienceOrchestration: true,
2262
+ host: "api.contentful.com"
2163
2263
  };
2164
2264
  const configFile = params.config ? __require(resolve(process.cwd(), params.config)) : {};
2165
2265
  const options = {
@@ -2271,8 +2371,7 @@ async function runContentfulImport(params) {
2271
2371
  {
2272
2372
  title: "Initialize client",
2273
2373
  task: wrapTask2(async (ctx) => {
2274
- ctx.client = initClient({ ...options, content: void 0 });
2275
- ctx.plainClient = initPlainClient({ ...options, content: void 0 });
2374
+ ctx.client = initClient({ ...options });
2276
2375
  })
2277
2376
  },
2278
2377
  {
@@ -2280,7 +2379,6 @@ async function runContentfulImport(params) {
2280
2379
  task: wrapTask2(async (ctx) => {
2281
2380
  const destinationData = await getDestinationData({
2282
2381
  client: ctx.client,
2283
- plainClient: ctx.plainClient,
2284
2382
  spaceId: options.spaceId,
2285
2383
  environmentId: options.environmentId,
2286
2384
  sourceData: options.content,
@@ -2308,7 +2406,6 @@ async function runContentfulImport(params) {
2308
2406
  sourceData: ctx.sourceData,
2309
2407
  destinationData: ctx.destinationData,
2310
2408
  client: ctx.client,
2311
- plainClient: ctx.plainClient,
2312
2409
  spaceId: options.spaceId,
2313
2410
  includeExperienceOrchestration: options.includeExperienceOrchestration,
2314
2411
  environmentId: options.environmentId,