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.
- package/dist/index.js +280 -183
- package/dist/index.mjs +280 -183
- 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, {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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(
|
|
121
|
+
async function spaceHasExoM1Entitlement(client, spaceId) {
|
|
123
122
|
try {
|
|
124
|
-
const space = await
|
|
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
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
|
164
|
-
|
|
165
|
-
|
|
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} ${
|
|
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({
|
|
176
|
-
const
|
|
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
|
|
181
|
-
|
|
182
|
-
|
|
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} ${
|
|
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
|
|
192
|
-
|
|
193
|
-
|
|
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} ${
|
|
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({
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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({
|
|
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
|
-
|
|
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
|
-
|
|
352
|
+
client,
|
|
353
|
+
spaceId,
|
|
354
|
+
environmentId,
|
|
341
355
|
type: "assets",
|
|
342
356
|
ids: assetIds,
|
|
343
357
|
requestQueue
|
|
344
358
|
});
|
|
345
359
|
}
|
|
346
|
-
if (includeExperienceOrchestration &&
|
|
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(
|
|
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({
|
|
374
|
+
result.designTokens = cursorPaginatedQueryOrWarn({ client, spaceId, environmentId, type: "designTokens", requestQueue });
|
|
361
375
|
}
|
|
362
376
|
if (sourceHasComponents) {
|
|
363
|
-
result.components = cursorPaginatedQueryOrWarn({
|
|
377
|
+
result.components = cursorPaginatedQueryOrWarn({ client, spaceId, environmentId, type: "components", requestQueue });
|
|
364
378
|
}
|
|
365
379
|
if (sourceHasExperienceTemplates) {
|
|
366
|
-
result.experienceTemplates = cursorPaginatedQueryOrWarn({
|
|
380
|
+
result.experienceTemplates = cursorPaginatedQueryOrWarn({ client, spaceId, environmentId, type: "experienceTemplates", requestQueue });
|
|
367
381
|
}
|
|
368
382
|
if (sourceHasExperienceFragments) {
|
|
369
|
-
result.experienceFragments = cursorPaginatedQueryOrWarn({
|
|
383
|
+
result.experienceFragments = cursorPaginatedQueryOrWarn({ client, spaceId, environmentId, type: "experienceFragments", requestQueue });
|
|
370
384
|
}
|
|
371
385
|
if (sourceHasExperiences) {
|
|
372
|
-
result.experiences = cursorPaginatedQueryOrWarn({
|
|
386
|
+
result.experiences = cursorPaginatedQueryOrWarn({ client, spaceId, environmentId, type: "experiences", requestQueue });
|
|
373
387
|
}
|
|
374
388
|
}
|
|
375
389
|
if (sourceData.dataAssemblies?.length) {
|
|
376
|
-
result.dataAssemblies = cursorPaginatedQueryOrWarn({
|
|
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,
|
|
552
|
+
return createEntry({ entry, context, destinationEntitiesById, skipUpdates, requestQueue });
|
|
536
553
|
}));
|
|
537
554
|
return createdEntries.filter((entry) => entry);
|
|
538
555
|
}
|
|
539
|
-
async function createEntry({ entry,
|
|
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(
|
|
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,
|
|
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)(
|
|
575
|
-
|
|
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,
|
|
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
|
-
|
|
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(
|
|
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 ?
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
636
|
-
const
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
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]
|
|
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(
|
|
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
|
-
|
|
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]
|
|
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 =
|
|
744
|
+
const pendingArchivedEntities = entities.map((entity2) => {
|
|
670
745
|
return requestQueue.add(async () => {
|
|
671
746
|
try {
|
|
672
|
-
const archivedEntity = await entity2
|
|
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
|
|
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(
|
|
882
|
-
const { items } = await
|
|
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(
|
|
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
|
|
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
|
|
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
|
|
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}`);
|
|
@@ -944,7 +1020,7 @@ async function createOrPatchChildConcepts(plainClient, organizationId, destinati
|
|
|
944
1020
|
}
|
|
945
1021
|
if (patches.length > 0) {
|
|
946
1022
|
try {
|
|
947
|
-
await
|
|
1023
|
+
await client.concept.patch(
|
|
948
1024
|
{ organizationId, conceptId: destConceptId, version: existing.sys.version },
|
|
949
1025
|
patches
|
|
950
1026
|
);
|
|
@@ -956,14 +1032,14 @@ async function createOrPatchChildConcepts(plainClient, organizationId, destinati
|
|
|
956
1032
|
}
|
|
957
1033
|
}
|
|
958
1034
|
}
|
|
959
|
-
async function linkChildConceptsToParentGroups(
|
|
1035
|
+
async function linkChildConceptsToParentGroups(client, organizationId, childConceptMap, parentGroups) {
|
|
960
1036
|
for (const [, { destConceptId, parentGroupId }] of childConceptMap) {
|
|
961
1037
|
const parentGroup = parentGroups.get(parentGroupId);
|
|
962
1038
|
if (!parentGroup) continue;
|
|
963
1039
|
const alreadyLinked = (parentGroup.concepts ?? []).some((c) => c.sys.id === destConceptId);
|
|
964
1040
|
if (alreadyLinked) continue;
|
|
965
1041
|
try {
|
|
966
|
-
const updated = await
|
|
1042
|
+
const updated = await client.conceptScheme.patch(
|
|
967
1043
|
{ organizationId, conceptSchemeId: parentGroupId, version: parentGroup.sys.version },
|
|
968
1044
|
[{ op: "add", path: "/concepts/-", value: { sys: { type: "Link", linkType: "TaxonomyConcept", id: destConceptId } } }]
|
|
969
1045
|
);
|
|
@@ -985,7 +1061,7 @@ function rewriteEntityFolderConcepts(entities, childConceptMap) {
|
|
|
985
1061
|
}
|
|
986
1062
|
}
|
|
987
1063
|
async function importExoFolders({
|
|
988
|
-
|
|
1064
|
+
client,
|
|
989
1065
|
organizationId,
|
|
990
1066
|
destinationSpaceId,
|
|
991
1067
|
sourceEntities
|
|
@@ -995,7 +1071,7 @@ async function importExoFolders({
|
|
|
995
1071
|
import_logging8.logEmitter.emit("info", "Source and destination space are the same \u2014 skipping ExO folder import");
|
|
996
1072
|
return;
|
|
997
1073
|
}
|
|
998
|
-
const parentGroups = await ensureParentFolderGroupsExist(
|
|
1074
|
+
const parentGroups = await ensureParentFolderGroupsExist(client, organizationId);
|
|
999
1075
|
if (parentGroups.size === 0) {
|
|
1000
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.");
|
|
1001
1077
|
return;
|
|
@@ -1003,8 +1079,8 @@ async function importExoFolders({
|
|
|
1003
1079
|
const childConceptMap = deriveChildConceptMap(sourceEntities, destinationSpaceId);
|
|
1004
1080
|
if (childConceptMap.size === 0) return;
|
|
1005
1081
|
import_logging8.logEmitter.emit("info", `Importing ${childConceptMap.size} ExO folder concept(s) into destination space ${destinationSpaceId}`);
|
|
1006
|
-
await createOrPatchChildConcepts(
|
|
1007
|
-
await linkChildConceptsToParentGroups(
|
|
1082
|
+
await createOrPatchChildConcepts(client, organizationId, destinationSpaceId, childConceptMap);
|
|
1083
|
+
await linkChildConceptsToParentGroups(client, organizationId, childConceptMap, parentGroups);
|
|
1008
1084
|
const allEntities = [
|
|
1009
1085
|
...sourceEntities.designTokens ?? [],
|
|
1010
1086
|
...sourceEntities.components ?? [],
|
|
@@ -1046,7 +1122,6 @@ function pushToSpace({
|
|
|
1046
1122
|
sourceData,
|
|
1047
1123
|
destinationData = {},
|
|
1048
1124
|
client,
|
|
1049
|
-
plainClient,
|
|
1050
1125
|
spaceId,
|
|
1051
1126
|
environmentId,
|
|
1052
1127
|
includeExperienceOrchestration,
|
|
@@ -1083,15 +1158,6 @@ function pushToSpace({
|
|
|
1083
1158
|
destinationDataById[entityType] = entitiesById;
|
|
1084
1159
|
}
|
|
1085
1160
|
return new import_listr.default([
|
|
1086
|
-
{
|
|
1087
|
-
title: "Connecting to space",
|
|
1088
|
-
task: (0, import_listr2.wrapTask)(async (ctx) => {
|
|
1089
|
-
const space = await client.getSpace(spaceId);
|
|
1090
|
-
const environment = await space.getEnvironment(environmentId);
|
|
1091
|
-
ctx.space = space;
|
|
1092
|
-
ctx.environment = environment;
|
|
1093
|
-
})
|
|
1094
|
-
},
|
|
1095
1161
|
{
|
|
1096
1162
|
title: "Importing Locales",
|
|
1097
1163
|
task: (0, import_listr2.wrapTask)(async (ctx) => {
|
|
@@ -1099,7 +1165,7 @@ function pushToSpace({
|
|
|
1099
1165
|
return;
|
|
1100
1166
|
}
|
|
1101
1167
|
const locales2 = await createLocales({
|
|
1102
|
-
context: {
|
|
1168
|
+
context: { client, spaceId, environmentId, type: "Locale" },
|
|
1103
1169
|
entities: sourceData.locales,
|
|
1104
1170
|
destinationEntitiesById: destinationDataById.locales,
|
|
1105
1171
|
requestQueue
|
|
@@ -1115,7 +1181,7 @@ function pushToSpace({
|
|
|
1115
1181
|
return;
|
|
1116
1182
|
}
|
|
1117
1183
|
const contentTypes2 = await createEntities({
|
|
1118
|
-
context: {
|
|
1184
|
+
context: { client, spaceId, environmentId, type: "ContentType" },
|
|
1119
1185
|
entities: sourceData.contentTypes,
|
|
1120
1186
|
destinationEntitiesById: destinationDataById.contentTypes,
|
|
1121
1187
|
skipUpdates: false,
|
|
@@ -1131,6 +1197,9 @@ function pushToSpace({
|
|
|
1131
1197
|
const publishedContentTypes = await publishEntities2({
|
|
1132
1198
|
entities: ctx.data.contentTypes,
|
|
1133
1199
|
sourceEntities: sourceData.contentTypes,
|
|
1200
|
+
client,
|
|
1201
|
+
spaceId,
|
|
1202
|
+
environmentId,
|
|
1134
1203
|
requestQueue
|
|
1135
1204
|
});
|
|
1136
1205
|
ctx.data.contentTypes = publishedContentTypes;
|
|
@@ -1142,7 +1211,7 @@ function pushToSpace({
|
|
|
1142
1211
|
task: (0, import_listr2.wrapTask)(async (ctx) => {
|
|
1143
1212
|
if (sourceData.tags && destinationDataById.tags) {
|
|
1144
1213
|
const tags2 = await createEntities({
|
|
1145
|
-
context: {
|
|
1214
|
+
context: { client, spaceId, environmentId, type: "Tag" },
|
|
1146
1215
|
entities: sourceData.tags,
|
|
1147
1216
|
destinationEntitiesById: destinationDataById.tags,
|
|
1148
1217
|
skipUpdates: false,
|
|
@@ -1169,14 +1238,24 @@ function pushToSpace({
|
|
|
1169
1238
|
return;
|
|
1170
1239
|
}
|
|
1171
1240
|
try {
|
|
1172
|
-
const ctEditorInterface = await requestQueue.add(
|
|
1241
|
+
const ctEditorInterface = await requestQueue.add(
|
|
1242
|
+
() => client.editorInterface.get({ spaceId, environmentId, contentTypeId: contentType.sys.id })
|
|
1243
|
+
);
|
|
1173
1244
|
import_logging9.logEmitter.emit("info", `Fetched editor interface for ${contentType.name}`);
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
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
|
+
);
|
|
1180
1259
|
return updatedEditorInterface;
|
|
1181
1260
|
} catch (err) {
|
|
1182
1261
|
err.entity = editorInterface;
|
|
@@ -1200,10 +1279,10 @@ function pushToSpace({
|
|
|
1200
1279
|
try {
|
|
1201
1280
|
import_logging9.logEmitter.emit("info", `Uploading Asset file ${file.upload}`);
|
|
1202
1281
|
const assetStream = await getAssetStreamForURL(file.upload, assetsDirectory);
|
|
1203
|
-
const upload = await
|
|
1204
|
-
|
|
1205
|
-
file: assetStream
|
|
1206
|
-
|
|
1282
|
+
const upload = await client.upload.create(
|
|
1283
|
+
{ spaceId, environmentId },
|
|
1284
|
+
{ file: assetStream }
|
|
1285
|
+
);
|
|
1207
1286
|
delete file.upload;
|
|
1208
1287
|
file.uploadFrom = {
|
|
1209
1288
|
sys: {
|
|
@@ -1231,7 +1310,7 @@ function pushToSpace({
|
|
|
1231
1310
|
return;
|
|
1232
1311
|
}
|
|
1233
1312
|
const assetsToProcess = await createEntities({
|
|
1234
|
-
context: {
|
|
1313
|
+
context: { client, spaceId, environmentId, type: "Asset" },
|
|
1235
1314
|
entities: sourceData.assets,
|
|
1236
1315
|
destinationEntitiesById: destinationDataById.assets,
|
|
1237
1316
|
skipUpdates: skipAssetUpdates,
|
|
@@ -1239,6 +1318,9 @@ function pushToSpace({
|
|
|
1239
1318
|
});
|
|
1240
1319
|
const processedAssets = await processAssets({
|
|
1241
1320
|
assets: assetsToProcess,
|
|
1321
|
+
client,
|
|
1322
|
+
spaceId,
|
|
1323
|
+
environmentId,
|
|
1242
1324
|
timeout,
|
|
1243
1325
|
retryLimit,
|
|
1244
1326
|
requestQueue
|
|
@@ -1253,6 +1335,9 @@ function pushToSpace({
|
|
|
1253
1335
|
const publishedAssets = await publishEntities2({
|
|
1254
1336
|
entities: ctx.data.assets,
|
|
1255
1337
|
sourceEntities: sourceData.assets,
|
|
1338
|
+
client,
|
|
1339
|
+
spaceId,
|
|
1340
|
+
environmentId,
|
|
1256
1341
|
requestQueue
|
|
1257
1342
|
});
|
|
1258
1343
|
ctx.data.publishedAssets = publishedAssets;
|
|
@@ -1265,6 +1350,9 @@ function pushToSpace({
|
|
|
1265
1350
|
const archivedAssets = await archiveEntities2({
|
|
1266
1351
|
entities: ctx.data.assets,
|
|
1267
1352
|
sourceEntities: sourceData.assets,
|
|
1353
|
+
client,
|
|
1354
|
+
spaceId,
|
|
1355
|
+
environmentId,
|
|
1268
1356
|
requestQueue
|
|
1269
1357
|
});
|
|
1270
1358
|
ctx.data.archivedAssets = archivedAssets;
|
|
@@ -1275,7 +1363,7 @@ function pushToSpace({
|
|
|
1275
1363
|
title: "Importing Content Entries",
|
|
1276
1364
|
task: (0, import_listr2.wrapTask)(async (ctx) => {
|
|
1277
1365
|
const entries2 = await createEntries({
|
|
1278
|
-
context: {
|
|
1366
|
+
context: { client, spaceId, environmentId, skipContentModel, type: "Entry" },
|
|
1279
1367
|
entities: sourceData.entries,
|
|
1280
1368
|
destinationEntitiesById: destinationDataById.entries,
|
|
1281
1369
|
skipUpdates: skipContentUpdates,
|
|
@@ -1291,6 +1379,9 @@ function pushToSpace({
|
|
|
1291
1379
|
const publishedEntries = await publishEntities2({
|
|
1292
1380
|
entities: ctx.data.entries,
|
|
1293
1381
|
sourceEntities: sourceData.entries,
|
|
1382
|
+
client,
|
|
1383
|
+
spaceId,
|
|
1384
|
+
environmentId,
|
|
1294
1385
|
requestQueue
|
|
1295
1386
|
});
|
|
1296
1387
|
ctx.data.publishedEntries = publishedEntries;
|
|
@@ -1303,6 +1394,9 @@ function pushToSpace({
|
|
|
1303
1394
|
const archivedEntries = await archiveEntities2({
|
|
1304
1395
|
entities: ctx.data.entries,
|
|
1305
1396
|
sourceEntities: sourceData.entries,
|
|
1397
|
+
client,
|
|
1398
|
+
spaceId,
|
|
1399
|
+
environmentId,
|
|
1306
1400
|
requestQueue
|
|
1307
1401
|
});
|
|
1308
1402
|
ctx.data.archivedEntries = archivedEntries;
|
|
@@ -1316,7 +1410,7 @@ function pushToSpace({
|
|
|
1316
1410
|
return;
|
|
1317
1411
|
}
|
|
1318
1412
|
const webhooks2 = await createEntities({
|
|
1319
|
-
context: {
|
|
1413
|
+
context: { client, spaceId, environmentId, type: "Webhook" },
|
|
1320
1414
|
entities: sourceData.webhooks,
|
|
1321
1415
|
destinationEntitiesById: destinationDataById.webhooks,
|
|
1322
1416
|
requestQueue
|
|
@@ -1327,19 +1421,24 @@ function pushToSpace({
|
|
|
1327
1421
|
},
|
|
1328
1422
|
{
|
|
1329
1423
|
title: "Create ExO Folders",
|
|
1330
|
-
task: (0, import_listr2.wrapTask)(async (
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
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
|
+
}
|
|
1343
1442
|
}),
|
|
1344
1443
|
skip: () => !includeExperienceOrchestration
|
|
1345
1444
|
},
|
|
@@ -1352,14 +1451,14 @@ function pushToSpace({
|
|
|
1352
1451
|
let result;
|
|
1353
1452
|
if (existing) {
|
|
1354
1453
|
const payload = { ...omitSys(entity), sys: buildDataAssemblySys(entity, existing.sys.version) };
|
|
1355
|
-
result = await withGraphQLSchemaBackoff(() =>
|
|
1454
|
+
result = await withGraphQLSchemaBackoff(() => client.dataAssembly.update(
|
|
1356
1455
|
{ spaceId, environmentId, dataAssemblyId: entity.sys.id },
|
|
1357
1456
|
payload
|
|
1358
1457
|
));
|
|
1359
1458
|
import_logging9.logEmitter.emit("info", `UPDATE DataAssembly ${entity.sys.id}`);
|
|
1360
1459
|
} else {
|
|
1361
1460
|
const payload = { ...omitSys(entity), sys: buildDataAssemblySys(entity, 0) };
|
|
1362
|
-
result = await withGraphQLSchemaBackoff(() =>
|
|
1461
|
+
result = await withGraphQLSchemaBackoff(() => client.dataAssembly.update(
|
|
1363
1462
|
{ spaceId, environmentId, dataAssemblyId: entity.sys.id },
|
|
1364
1463
|
payload
|
|
1365
1464
|
));
|
|
@@ -1381,7 +1480,7 @@ function pushToSpace({
|
|
|
1381
1480
|
task: (0, import_listr2.wrapTask)(async (ctx) => {
|
|
1382
1481
|
const entitiesToPublish = filterExoEntitiesToPublish(ctx.data.dataAssemblies, sourceData.dataAssemblies || []);
|
|
1383
1482
|
const results = await Promise.all(entitiesToPublish.map(
|
|
1384
|
-
(entity) => publishExoEntity("DataAssembly", entity, () =>
|
|
1483
|
+
(entity) => publishExoEntity("DataAssembly", entity, () => client.dataAssembly.publish(
|
|
1385
1484
|
{ spaceId, environmentId, dataAssemblyId: entity.sys.id, version: entity.sys.version }
|
|
1386
1485
|
))
|
|
1387
1486
|
));
|
|
@@ -1397,12 +1496,12 @@ function pushToSpace({
|
|
|
1397
1496
|
const existing = destinationDataById.designTokens?.get(entity.sys.id);
|
|
1398
1497
|
if (existing) {
|
|
1399
1498
|
const payload = { ...entity, sys: { id: entity.sys.id, type: "DesignToken", version: existing.sys.version } };
|
|
1400
|
-
const result = await
|
|
1499
|
+
const result = await client.designToken.upsert({ spaceId, environmentId, designTokenId: entity.sys.id }, payload);
|
|
1401
1500
|
import_logging9.logEmitter.emit("info", `UPDATE DesignToken ${entity.sys.id}`);
|
|
1402
1501
|
return result;
|
|
1403
1502
|
} else {
|
|
1404
1503
|
const payload = { ...omitSys(entity), sys: { id: entity.sys.id, type: "DesignToken" } };
|
|
1405
|
-
const result = await
|
|
1504
|
+
const result = await client.designToken.upsert({ spaceId, environmentId, designTokenId: entity.sys.id }, payload);
|
|
1406
1505
|
import_logging9.logEmitter.emit("info", `CREATE DesignToken ${entity.sys.id}`);
|
|
1407
1506
|
return result;
|
|
1408
1507
|
}
|
|
@@ -1426,12 +1525,12 @@ function pushToSpace({
|
|
|
1426
1525
|
const existing = destinationDataById.components?.get(entity.sys.id);
|
|
1427
1526
|
if (existing) {
|
|
1428
1527
|
const payload = { ...entity, sys: { id: entity.sys.id, type: "Component", version: existing.sys.version } };
|
|
1429
|
-
const result = await
|
|
1528
|
+
const result = await client.component.upsert({ spaceId, environmentId, componentId: entity.sys.id }, payload);
|
|
1430
1529
|
import_logging9.logEmitter.emit("info", `UPDATE Component ${entity.sys.id}`);
|
|
1431
1530
|
results.push(result);
|
|
1432
1531
|
} else {
|
|
1433
1532
|
const payload = { ...omitSys(entity), sys: { id: entity.sys.id, type: "Component" } };
|
|
1434
|
-
const result = await
|
|
1533
|
+
const result = await client.component.upsert({ spaceId, environmentId, componentId: entity.sys.id }, payload);
|
|
1435
1534
|
import_logging9.logEmitter.emit("info", `CREATE Component ${entity.sys.id}`);
|
|
1436
1535
|
results.push(result);
|
|
1437
1536
|
}
|
|
@@ -1451,7 +1550,7 @@ function pushToSpace({
|
|
|
1451
1550
|
const sorted = sortOrReport(() => sortComponents(entitiesToPublish));
|
|
1452
1551
|
const results = [];
|
|
1453
1552
|
for (const entity of sorted) {
|
|
1454
|
-
const published = await publishExoEntity("Component", entity, () =>
|
|
1553
|
+
const published = await publishExoEntity("Component", entity, () => client.component.publish(
|
|
1455
1554
|
{ spaceId, environmentId, componentId: entity.sys.id, version: entity.sys.version }
|
|
1456
1555
|
));
|
|
1457
1556
|
if (published) results.push(published);
|
|
@@ -1468,12 +1567,12 @@ function pushToSpace({
|
|
|
1468
1567
|
const existing = destinationDataById.experienceTemplates?.get(entity.sys.id);
|
|
1469
1568
|
if (existing) {
|
|
1470
1569
|
const payload = { ...entity, sys: { id: entity.sys.id, type: "ExperienceTemplate", version: existing.sys.version } };
|
|
1471
|
-
const result = await
|
|
1570
|
+
const result = await client.experienceTemplate.upsert({ spaceId, environmentId, experienceTemplateId: entity.sys.id }, payload);
|
|
1472
1571
|
import_logging9.logEmitter.emit("info", `UPDATE ExperienceTemplate ${entity.sys.id}`);
|
|
1473
1572
|
return result;
|
|
1474
1573
|
} else {
|
|
1475
1574
|
const payload = { ...omitSys(entity), sys: { id: entity.sys.id, type: "ExperienceTemplate" } };
|
|
1476
|
-
const result = await
|
|
1575
|
+
const result = await client.experienceTemplate.upsert({ spaceId, environmentId, experienceTemplateId: entity.sys.id }, payload);
|
|
1477
1576
|
import_logging9.logEmitter.emit("info", `CREATE ExperienceTemplate ${entity.sys.id}`);
|
|
1478
1577
|
return result;
|
|
1479
1578
|
}
|
|
@@ -1492,7 +1591,7 @@ function pushToSpace({
|
|
|
1492
1591
|
task: (0, import_listr2.wrapTask)(async (ctx) => {
|
|
1493
1592
|
const entitiesToPublish = filterExoEntitiesToPublish(ctx.data.experienceTemplates, sourceData.experienceTemplates || []);
|
|
1494
1593
|
const results = await Promise.all(entitiesToPublish.map(
|
|
1495
|
-
(entity) => publishExoEntity("ExperienceTemplate", entity, () =>
|
|
1594
|
+
(entity) => publishExoEntity("ExperienceTemplate", entity, () => client.experienceTemplate.publish(
|
|
1496
1595
|
{ spaceId, environmentId, experienceTemplateId: entity.sys.id, version: entity.sys.version }
|
|
1497
1596
|
))
|
|
1498
1597
|
));
|
|
@@ -1510,12 +1609,12 @@ function pushToSpace({
|
|
|
1510
1609
|
const existing = destinationDataById.experienceFragments?.get(entity.sys.id);
|
|
1511
1610
|
if (existing) {
|
|
1512
1611
|
const payload = { ...entity, sys: { id: entity.sys.id, type: "ExperienceFragment", version: existing.sys.version } };
|
|
1513
|
-
const result = await
|
|
1612
|
+
const result = await client.experienceFragment.upsert({ spaceId, environmentId, experienceFragmentId: entity.sys.id }, payload);
|
|
1514
1613
|
import_logging9.logEmitter.emit("info", `UPDATE ExperienceFragment ${entity.sys.id}`);
|
|
1515
1614
|
results.push(result);
|
|
1516
1615
|
} else {
|
|
1517
1616
|
const payload = { ...omitSys(entity), component: entity.sys.component, sys: { id: entity.sys.id, type: "ExperienceFragment" } };
|
|
1518
|
-
const result = await
|
|
1617
|
+
const result = await client.experienceFragment.upsert({ spaceId, environmentId, experienceFragmentId: entity.sys.id }, payload);
|
|
1519
1618
|
import_logging9.logEmitter.emit("info", `CREATE ExperienceFragment ${entity.sys.id}`);
|
|
1520
1619
|
results.push(result);
|
|
1521
1620
|
}
|
|
@@ -1535,7 +1634,7 @@ function pushToSpace({
|
|
|
1535
1634
|
const sorted = sortOrReport(() => sortExperienceFragments(entitiesToPublish));
|
|
1536
1635
|
const results = [];
|
|
1537
1636
|
for (const entity of sorted) {
|
|
1538
|
-
const published = await publishExoEntity("ExperienceFragment", entity, () =>
|
|
1637
|
+
const published = await publishExoEntity("ExperienceFragment", entity, () => client.experienceFragment.publish(
|
|
1539
1638
|
{ spaceId, environmentId, experienceFragmentId: entity.sys.id, version: entity.sys.version }
|
|
1540
1639
|
));
|
|
1541
1640
|
if (published) results.push(published);
|
|
@@ -1552,12 +1651,12 @@ function pushToSpace({
|
|
|
1552
1651
|
const existing = destinationDataById.experiences?.get(entity.sys.id);
|
|
1553
1652
|
if (existing) {
|
|
1554
1653
|
const payload = { ...entity, sys: { id: entity.sys.id, type: "Experience", version: existing.sys.version } };
|
|
1555
|
-
const result = await
|
|
1654
|
+
const result = await client.experience.upsert({ spaceId, environmentId, experienceId: entity.sys.id }, payload);
|
|
1556
1655
|
import_logging9.logEmitter.emit("info", `UPDATE Experience ${entity.sys.id}`);
|
|
1557
1656
|
return result;
|
|
1558
1657
|
} else {
|
|
1559
1658
|
const payload = { ...omitSys(entity), experienceTemplate: entity.sys.experienceTemplate, sys: { id: entity.sys.id, type: "Experience" } };
|
|
1560
|
-
const result = await
|
|
1659
|
+
const result = await client.experience.upsert({ spaceId, environmentId, experienceId: entity.sys.id }, payload);
|
|
1561
1660
|
import_logging9.logEmitter.emit("info", `CREATE Experience ${entity.sys.id}`);
|
|
1562
1661
|
return result;
|
|
1563
1662
|
}
|
|
@@ -1576,7 +1675,7 @@ function pushToSpace({
|
|
|
1576
1675
|
task: (0, import_listr2.wrapTask)(async (ctx) => {
|
|
1577
1676
|
const entitiesToPublish = filterExoEntitiesToPublish(ctx.data.experiences, sourceData.experiences || []);
|
|
1578
1677
|
const results = await Promise.all(entitiesToPublish.map(
|
|
1579
|
-
(entity) => publishExoEntity("Experience", entity, () =>
|
|
1678
|
+
(entity) => publishExoEntity("Experience", entity, () => client.experience.publish(
|
|
1580
1679
|
{ spaceId, environmentId, experienceId: entity.sys.id, version: entity.sys.version }
|
|
1581
1680
|
))
|
|
1582
1681
|
));
|
|
@@ -1592,7 +1691,7 @@ function pushToSpace({
|
|
|
1592
1691
|
task: (0, import_listr2.wrapTask)(async (ctx) => {
|
|
1593
1692
|
const entitiesToUnpublish = filterExoEntitiesToUnpublish(ctx.data.experiences, sourceData.experiences || []);
|
|
1594
1693
|
await Promise.all(entitiesToUnpublish.map(
|
|
1595
|
-
(entity) => unpublishExoEntity("Experience", entity, () =>
|
|
1694
|
+
(entity) => unpublishExoEntity("Experience", entity, () => client.experience.unpublish(
|
|
1596
1695
|
{ spaceId, environmentId, experienceId: entity.sys.id, version: entity.sys.version }
|
|
1597
1696
|
))
|
|
1598
1697
|
));
|
|
@@ -1605,7 +1704,7 @@ function pushToSpace({
|
|
|
1605
1704
|
const entitiesToUnpublish = filterExoEntitiesToUnpublish(ctx.data.experienceFragments, sourceData.experienceFragments || []);
|
|
1606
1705
|
const sorted = sortExperienceFragments(entitiesToUnpublish).reverse();
|
|
1607
1706
|
for (const entity of sorted) {
|
|
1608
|
-
await unpublishExoEntity("ExperienceFragment", entity, () =>
|
|
1707
|
+
await unpublishExoEntity("ExperienceFragment", entity, () => client.experienceFragment.unpublish(
|
|
1609
1708
|
{ spaceId, environmentId, experienceFragmentId: entity.sys.id, version: entity.sys.version }
|
|
1610
1709
|
));
|
|
1611
1710
|
}
|
|
@@ -1617,7 +1716,7 @@ function pushToSpace({
|
|
|
1617
1716
|
task: (0, import_listr2.wrapTask)(async (ctx) => {
|
|
1618
1717
|
const entitiesToUnpublish = filterExoEntitiesToUnpublish(ctx.data.experienceTemplates, sourceData.experienceTemplates || []);
|
|
1619
1718
|
await Promise.all(entitiesToUnpublish.map(
|
|
1620
|
-
(entity) => unpublishExoEntity("ExperienceTemplate", entity, () =>
|
|
1719
|
+
(entity) => unpublishExoEntity("ExperienceTemplate", entity, () => client.experienceTemplate.unpublish(
|
|
1621
1720
|
{ spaceId, environmentId, experienceTemplateId: entity.sys.id, version: entity.sys.version }
|
|
1622
1721
|
))
|
|
1623
1722
|
));
|
|
@@ -1630,7 +1729,7 @@ function pushToSpace({
|
|
|
1630
1729
|
const entitiesToUnpublish = filterExoEntitiesToUnpublish(ctx.data.components, sourceData.components || []);
|
|
1631
1730
|
const sorted = sortComponents(entitiesToUnpublish).reverse();
|
|
1632
1731
|
for (const entity of sorted) {
|
|
1633
|
-
await unpublishExoEntity("Component", entity, () =>
|
|
1732
|
+
await unpublishExoEntity("Component", entity, () => client.component.unpublish(
|
|
1634
1733
|
{ spaceId, environmentId, componentId: entity.sys.id, version: entity.sys.version }
|
|
1635
1734
|
));
|
|
1636
1735
|
}
|
|
@@ -1642,7 +1741,7 @@ function pushToSpace({
|
|
|
1642
1741
|
task: (0, import_listr2.wrapTask)(async (ctx) => {
|
|
1643
1742
|
const entitiesToUnpublish = filterExoEntitiesToUnpublish(ctx.data.dataAssemblies, sourceData.dataAssemblies || []);
|
|
1644
1743
|
await Promise.all(entitiesToUnpublish.map(
|
|
1645
|
-
(entity) => unpublishExoEntity("DataAssembly", entity, () =>
|
|
1744
|
+
(entity) => unpublishExoEntity("DataAssembly", entity, () => client.dataAssembly.unpublish(
|
|
1646
1745
|
{ spaceId, environmentId, dataAssemblyId: entity.sys.id, version: entity.sys.version }
|
|
1647
1746
|
))
|
|
1648
1747
|
));
|
|
@@ -1655,15 +1754,15 @@ function omitSys(entity) {
|
|
|
1655
1754
|
const { sys: _sys, ...rest } = entity;
|
|
1656
1755
|
return rest;
|
|
1657
1756
|
}
|
|
1658
|
-
function archiveEntities2({ entities, sourceEntities, requestQueue }) {
|
|
1757
|
+
function archiveEntities2({ entities, sourceEntities, client, spaceId, environmentId, requestQueue }) {
|
|
1659
1758
|
const entityIdsToArchive = sourceEntities.filter(({ original }) => original.sys.archivedVersion).map(({ original }) => original.sys.id);
|
|
1660
1759
|
const entitiesToArchive = entities.filter((entity) => entityIdsToArchive.indexOf(entity.sys.id) !== -1);
|
|
1661
|
-
return archiveEntities({ entities: entitiesToArchive, requestQueue });
|
|
1760
|
+
return archiveEntities({ entities: entitiesToArchive, client, spaceId, environmentId, requestQueue });
|
|
1662
1761
|
}
|
|
1663
|
-
function publishEntities2({ entities, sourceEntities, requestQueue }) {
|
|
1762
|
+
function publishEntities2({ entities, sourceEntities, client, spaceId, environmentId, requestQueue }) {
|
|
1664
1763
|
const entityIdsToPublish = sourceEntities.filter(({ original }) => original.sys.publishedVersion).map(({ original }) => original.sys.id);
|
|
1665
1764
|
const entitiesToPublish = entities.filter((entity) => entityIdsToPublish.indexOf(entity.sys.id) !== -1);
|
|
1666
|
-
return publishEntities({ entities: entitiesToPublish, requestQueue });
|
|
1765
|
+
return publishEntities({ entities: entitiesToPublish, client, spaceId, environmentId, requestQueue });
|
|
1667
1766
|
}
|
|
1668
1767
|
|
|
1669
1768
|
// lib/transform/transform-space.ts
|
|
@@ -2189,7 +2288,8 @@ async function parseOptions(params) {
|
|
|
2189
2288
|
rawProxy: false,
|
|
2190
2289
|
uploadAssets: false,
|
|
2191
2290
|
rateLimit: 7,
|
|
2192
|
-
includeExperienceOrchestration: true
|
|
2291
|
+
includeExperienceOrchestration: true,
|
|
2292
|
+
host: "api.contentful.com"
|
|
2193
2293
|
};
|
|
2194
2294
|
const configFile = params.config ? require((0, import_path2.resolve)(process.cwd(), params.config)) : {};
|
|
2195
2295
|
const options = {
|
|
@@ -2301,8 +2401,7 @@ async function runContentfulImport(params) {
|
|
|
2301
2401
|
{
|
|
2302
2402
|
title: "Initialize client",
|
|
2303
2403
|
task: (0, import_listr4.wrapTask)(async (ctx) => {
|
|
2304
|
-
ctx.client = initClient({ ...options
|
|
2305
|
-
ctx.plainClient = initPlainClient({ ...options, content: void 0 });
|
|
2404
|
+
ctx.client = initClient({ ...options });
|
|
2306
2405
|
})
|
|
2307
2406
|
},
|
|
2308
2407
|
{
|
|
@@ -2310,7 +2409,6 @@ async function runContentfulImport(params) {
|
|
|
2310
2409
|
task: (0, import_listr4.wrapTask)(async (ctx) => {
|
|
2311
2410
|
const destinationData = await getDestinationData({
|
|
2312
2411
|
client: ctx.client,
|
|
2313
|
-
plainClient: ctx.plainClient,
|
|
2314
2412
|
spaceId: options.spaceId,
|
|
2315
2413
|
environmentId: options.environmentId,
|
|
2316
2414
|
sourceData: options.content,
|
|
@@ -2338,7 +2436,6 @@ async function runContentfulImport(params) {
|
|
|
2338
2436
|
sourceData: ctx.sourceData,
|
|
2339
2437
|
destinationData: ctx.destinationData,
|
|
2340
2438
|
client: ctx.client,
|
|
2341
|
-
plainClient: ctx.plainClient,
|
|
2342
2439
|
spaceId: options.spaceId,
|
|
2343
2440
|
includeExperienceOrchestration: options.includeExperienceOrchestration,
|
|
2344
2441
|
environmentId: options.environmentId,
|