contentful-import 10.1.1 → 10.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +280 -186
- package/dist/index.mjs +280 -186
- 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, {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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(
|
|
94
|
+
async function spaceHasExoM1Entitlement(client, spaceId) {
|
|
96
95
|
try {
|
|
97
|
-
const space = await
|
|
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
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
|
137
|
-
|
|
138
|
-
|
|
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} ${
|
|
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({
|
|
149
|
-
const
|
|
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
|
|
154
|
-
|
|
155
|
-
|
|
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} ${
|
|
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
|
|
165
|
-
|
|
166
|
-
|
|
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} ${
|
|
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({
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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({
|
|
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
|
-
|
|
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
|
-
|
|
325
|
+
client,
|
|
326
|
+
spaceId,
|
|
327
|
+
environmentId,
|
|
314
328
|
type: "assets",
|
|
315
329
|
ids: assetIds,
|
|
316
330
|
requestQueue
|
|
317
331
|
});
|
|
318
332
|
}
|
|
319
|
-
if (includeExperienceOrchestration &&
|
|
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(
|
|
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({
|
|
347
|
+
result.designTokens = cursorPaginatedQueryOrWarn({ client, spaceId, environmentId, type: "designTokens", requestQueue });
|
|
334
348
|
}
|
|
335
349
|
if (sourceHasComponents) {
|
|
336
|
-
result.components = cursorPaginatedQueryOrWarn({
|
|
350
|
+
result.components = cursorPaginatedQueryOrWarn({ client, spaceId, environmentId, type: "components", requestQueue });
|
|
337
351
|
}
|
|
338
352
|
if (sourceHasExperienceTemplates) {
|
|
339
|
-
result.experienceTemplates = cursorPaginatedQueryOrWarn({
|
|
353
|
+
result.experienceTemplates = cursorPaginatedQueryOrWarn({ client, spaceId, environmentId, type: "experienceTemplates", requestQueue });
|
|
340
354
|
}
|
|
341
355
|
if (sourceHasExperienceFragments) {
|
|
342
|
-
result.experienceFragments = cursorPaginatedQueryOrWarn({
|
|
356
|
+
result.experienceFragments = cursorPaginatedQueryOrWarn({ client, spaceId, environmentId, type: "experienceFragments", requestQueue });
|
|
343
357
|
}
|
|
344
358
|
if (sourceHasExperiences) {
|
|
345
|
-
result.experiences = cursorPaginatedQueryOrWarn({
|
|
359
|
+
result.experiences = cursorPaginatedQueryOrWarn({ client, spaceId, environmentId, type: "experiences", requestQueue });
|
|
346
360
|
}
|
|
347
361
|
}
|
|
348
362
|
if (sourceData.dataAssemblies?.length) {
|
|
349
|
-
result.dataAssemblies = cursorPaginatedQueryOrWarn({
|
|
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,
|
|
525
|
+
return createEntry({ entry, context, destinationEntitiesById, skipUpdates, requestQueue });
|
|
509
526
|
}));
|
|
510
527
|
return createdEntries.filter((entry) => entry);
|
|
511
528
|
}
|
|
512
|
-
async function createEntry({ entry,
|
|
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(
|
|
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,
|
|
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(
|
|
548
|
-
|
|
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,
|
|
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
|
-
|
|
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(
|
|
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 ?
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
609
|
-
const
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
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]
|
|
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(
|
|
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
|
-
|
|
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]
|
|
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 =
|
|
717
|
+
const pendingArchivedEntities = entities.map((entity2) => {
|
|
643
718
|
return requestQueue.add(async () => {
|
|
644
719
|
try {
|
|
645
|
-
const archivedEntity = await entity2
|
|
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
|
|
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(
|
|
855
|
-
const { items } = await
|
|
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(
|
|
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
|
|
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
|
|
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
|
|
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}`);
|
|
@@ -911,16 +987,13 @@ async function createOrPatchChildConcepts(plainClient, organizationId, destinati
|
|
|
911
987
|
}
|
|
912
988
|
} else {
|
|
913
989
|
const patches = [];
|
|
914
|
-
if (existing.purpose !== "internal") {
|
|
915
|
-
patches.push({ op: "add", path: "/purpose", value: "internal" });
|
|
916
|
-
}
|
|
917
990
|
const spaces = existing.metadata?.spaces ?? [];
|
|
918
991
|
if (!spaces.some((s) => s.sys.id === destinationSpaceId)) {
|
|
919
992
|
patches.push({ op: "add", path: "/metadata/spaces/-", value: spaceLink });
|
|
920
993
|
}
|
|
921
994
|
if (patches.length > 0) {
|
|
922
995
|
try {
|
|
923
|
-
await
|
|
996
|
+
await client.concept.patch(
|
|
924
997
|
{ organizationId, conceptId: destConceptId, version: existing.sys.version },
|
|
925
998
|
patches
|
|
926
999
|
);
|
|
@@ -932,14 +1005,14 @@ async function createOrPatchChildConcepts(plainClient, organizationId, destinati
|
|
|
932
1005
|
}
|
|
933
1006
|
}
|
|
934
1007
|
}
|
|
935
|
-
async function linkChildConceptsToParentGroups(
|
|
1008
|
+
async function linkChildConceptsToParentGroups(client, organizationId, childConceptMap, parentGroups) {
|
|
936
1009
|
for (const [, { destConceptId, parentGroupId }] of childConceptMap) {
|
|
937
1010
|
const parentGroup = parentGroups.get(parentGroupId);
|
|
938
1011
|
if (!parentGroup) continue;
|
|
939
1012
|
const alreadyLinked = (parentGroup.concepts ?? []).some((c) => c.sys.id === destConceptId);
|
|
940
1013
|
if (alreadyLinked) continue;
|
|
941
1014
|
try {
|
|
942
|
-
const updated = await
|
|
1015
|
+
const updated = await client.conceptScheme.patch(
|
|
943
1016
|
{ organizationId, conceptSchemeId: parentGroupId, version: parentGroup.sys.version },
|
|
944
1017
|
[{ op: "add", path: "/concepts/-", value: { sys: { type: "Link", linkType: "TaxonomyConcept", id: destConceptId } } }]
|
|
945
1018
|
);
|
|
@@ -961,7 +1034,7 @@ function rewriteEntityFolderConcepts(entities, childConceptMap) {
|
|
|
961
1034
|
}
|
|
962
1035
|
}
|
|
963
1036
|
async function importExoFolders({
|
|
964
|
-
|
|
1037
|
+
client,
|
|
965
1038
|
organizationId,
|
|
966
1039
|
destinationSpaceId,
|
|
967
1040
|
sourceEntities
|
|
@@ -971,7 +1044,7 @@ async function importExoFolders({
|
|
|
971
1044
|
logEmitter8.emit("info", "Source and destination space are the same \u2014 skipping ExO folder import");
|
|
972
1045
|
return;
|
|
973
1046
|
}
|
|
974
|
-
const parentGroups = await ensureParentFolderGroupsExist(
|
|
1047
|
+
const parentGroups = await ensureParentFolderGroupsExist(client, organizationId);
|
|
975
1048
|
if (parentGroups.size === 0) {
|
|
976
1049
|
logEmitter8.emit("warn", "One or more Experience Orchestration folder group concept schemes are missing in the destination organization. Please create them before importing.");
|
|
977
1050
|
return;
|
|
@@ -979,8 +1052,8 @@ async function importExoFolders({
|
|
|
979
1052
|
const childConceptMap = deriveChildConceptMap(sourceEntities, destinationSpaceId);
|
|
980
1053
|
if (childConceptMap.size === 0) return;
|
|
981
1054
|
logEmitter8.emit("info", `Importing ${childConceptMap.size} ExO folder concept(s) into destination space ${destinationSpaceId}`);
|
|
982
|
-
await createOrPatchChildConcepts(
|
|
983
|
-
await linkChildConceptsToParentGroups(
|
|
1055
|
+
await createOrPatchChildConcepts(client, organizationId, destinationSpaceId, childConceptMap);
|
|
1056
|
+
await linkChildConceptsToParentGroups(client, organizationId, childConceptMap, parentGroups);
|
|
984
1057
|
const allEntities = [
|
|
985
1058
|
...sourceEntities.designTokens ?? [],
|
|
986
1059
|
...sourceEntities.components ?? [],
|
|
@@ -1022,7 +1095,6 @@ function pushToSpace({
|
|
|
1022
1095
|
sourceData,
|
|
1023
1096
|
destinationData = {},
|
|
1024
1097
|
client,
|
|
1025
|
-
plainClient,
|
|
1026
1098
|
spaceId,
|
|
1027
1099
|
environmentId,
|
|
1028
1100
|
includeExperienceOrchestration,
|
|
@@ -1059,15 +1131,6 @@ function pushToSpace({
|
|
|
1059
1131
|
destinationDataById[entityType] = entitiesById;
|
|
1060
1132
|
}
|
|
1061
1133
|
return new Listr([
|
|
1062
|
-
{
|
|
1063
|
-
title: "Connecting to space",
|
|
1064
|
-
task: wrapTask(async (ctx) => {
|
|
1065
|
-
const space = await client.getSpace(spaceId);
|
|
1066
|
-
const environment = await space.getEnvironment(environmentId);
|
|
1067
|
-
ctx.space = space;
|
|
1068
|
-
ctx.environment = environment;
|
|
1069
|
-
})
|
|
1070
|
-
},
|
|
1071
1134
|
{
|
|
1072
1135
|
title: "Importing Locales",
|
|
1073
1136
|
task: wrapTask(async (ctx) => {
|
|
@@ -1075,7 +1138,7 @@ function pushToSpace({
|
|
|
1075
1138
|
return;
|
|
1076
1139
|
}
|
|
1077
1140
|
const locales2 = await createLocales({
|
|
1078
|
-
context: {
|
|
1141
|
+
context: { client, spaceId, environmentId, type: "Locale" },
|
|
1079
1142
|
entities: sourceData.locales,
|
|
1080
1143
|
destinationEntitiesById: destinationDataById.locales,
|
|
1081
1144
|
requestQueue
|
|
@@ -1091,7 +1154,7 @@ function pushToSpace({
|
|
|
1091
1154
|
return;
|
|
1092
1155
|
}
|
|
1093
1156
|
const contentTypes2 = await createEntities({
|
|
1094
|
-
context: {
|
|
1157
|
+
context: { client, spaceId, environmentId, type: "ContentType" },
|
|
1095
1158
|
entities: sourceData.contentTypes,
|
|
1096
1159
|
destinationEntitiesById: destinationDataById.contentTypes,
|
|
1097
1160
|
skipUpdates: false,
|
|
@@ -1107,6 +1170,9 @@ function pushToSpace({
|
|
|
1107
1170
|
const publishedContentTypes = await publishEntities2({
|
|
1108
1171
|
entities: ctx.data.contentTypes,
|
|
1109
1172
|
sourceEntities: sourceData.contentTypes,
|
|
1173
|
+
client,
|
|
1174
|
+
spaceId,
|
|
1175
|
+
environmentId,
|
|
1110
1176
|
requestQueue
|
|
1111
1177
|
});
|
|
1112
1178
|
ctx.data.contentTypes = publishedContentTypes;
|
|
@@ -1118,7 +1184,7 @@ function pushToSpace({
|
|
|
1118
1184
|
task: wrapTask(async (ctx) => {
|
|
1119
1185
|
if (sourceData.tags && destinationDataById.tags) {
|
|
1120
1186
|
const tags2 = await createEntities({
|
|
1121
|
-
context: {
|
|
1187
|
+
context: { client, spaceId, environmentId, type: "Tag" },
|
|
1122
1188
|
entities: sourceData.tags,
|
|
1123
1189
|
destinationEntitiesById: destinationDataById.tags,
|
|
1124
1190
|
skipUpdates: false,
|
|
@@ -1145,14 +1211,24 @@ function pushToSpace({
|
|
|
1145
1211
|
return;
|
|
1146
1212
|
}
|
|
1147
1213
|
try {
|
|
1148
|
-
const ctEditorInterface = await requestQueue.add(
|
|
1214
|
+
const ctEditorInterface = await requestQueue.add(
|
|
1215
|
+
() => client.editorInterface.get({ spaceId, environmentId, contentTypeId: contentType.sys.id })
|
|
1216
|
+
);
|
|
1149
1217
|
logEmitter9.emit("info", `Fetched editor interface for ${contentType.name}`);
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
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
|
+
);
|
|
1156
1232
|
return updatedEditorInterface;
|
|
1157
1233
|
} catch (err) {
|
|
1158
1234
|
err.entity = editorInterface;
|
|
@@ -1176,10 +1252,10 @@ function pushToSpace({
|
|
|
1176
1252
|
try {
|
|
1177
1253
|
logEmitter9.emit("info", `Uploading Asset file ${file.upload}`);
|
|
1178
1254
|
const assetStream = await getAssetStreamForURL(file.upload, assetsDirectory);
|
|
1179
|
-
const upload = await
|
|
1180
|
-
|
|
1181
|
-
file: assetStream
|
|
1182
|
-
|
|
1255
|
+
const upload = await client.upload.create(
|
|
1256
|
+
{ spaceId, environmentId },
|
|
1257
|
+
{ file: assetStream }
|
|
1258
|
+
);
|
|
1183
1259
|
delete file.upload;
|
|
1184
1260
|
file.uploadFrom = {
|
|
1185
1261
|
sys: {
|
|
@@ -1207,7 +1283,7 @@ function pushToSpace({
|
|
|
1207
1283
|
return;
|
|
1208
1284
|
}
|
|
1209
1285
|
const assetsToProcess = await createEntities({
|
|
1210
|
-
context: {
|
|
1286
|
+
context: { client, spaceId, environmentId, type: "Asset" },
|
|
1211
1287
|
entities: sourceData.assets,
|
|
1212
1288
|
destinationEntitiesById: destinationDataById.assets,
|
|
1213
1289
|
skipUpdates: skipAssetUpdates,
|
|
@@ -1215,6 +1291,9 @@ function pushToSpace({
|
|
|
1215
1291
|
});
|
|
1216
1292
|
const processedAssets = await processAssets({
|
|
1217
1293
|
assets: assetsToProcess,
|
|
1294
|
+
client,
|
|
1295
|
+
spaceId,
|
|
1296
|
+
environmentId,
|
|
1218
1297
|
timeout,
|
|
1219
1298
|
retryLimit,
|
|
1220
1299
|
requestQueue
|
|
@@ -1229,6 +1308,9 @@ function pushToSpace({
|
|
|
1229
1308
|
const publishedAssets = await publishEntities2({
|
|
1230
1309
|
entities: ctx.data.assets,
|
|
1231
1310
|
sourceEntities: sourceData.assets,
|
|
1311
|
+
client,
|
|
1312
|
+
spaceId,
|
|
1313
|
+
environmentId,
|
|
1232
1314
|
requestQueue
|
|
1233
1315
|
});
|
|
1234
1316
|
ctx.data.publishedAssets = publishedAssets;
|
|
@@ -1241,6 +1323,9 @@ function pushToSpace({
|
|
|
1241
1323
|
const archivedAssets = await archiveEntities2({
|
|
1242
1324
|
entities: ctx.data.assets,
|
|
1243
1325
|
sourceEntities: sourceData.assets,
|
|
1326
|
+
client,
|
|
1327
|
+
spaceId,
|
|
1328
|
+
environmentId,
|
|
1244
1329
|
requestQueue
|
|
1245
1330
|
});
|
|
1246
1331
|
ctx.data.archivedAssets = archivedAssets;
|
|
@@ -1251,7 +1336,7 @@ function pushToSpace({
|
|
|
1251
1336
|
title: "Importing Content Entries",
|
|
1252
1337
|
task: wrapTask(async (ctx) => {
|
|
1253
1338
|
const entries2 = await createEntries({
|
|
1254
|
-
context: {
|
|
1339
|
+
context: { client, spaceId, environmentId, skipContentModel, type: "Entry" },
|
|
1255
1340
|
entities: sourceData.entries,
|
|
1256
1341
|
destinationEntitiesById: destinationDataById.entries,
|
|
1257
1342
|
skipUpdates: skipContentUpdates,
|
|
@@ -1267,6 +1352,9 @@ function pushToSpace({
|
|
|
1267
1352
|
const publishedEntries = await publishEntities2({
|
|
1268
1353
|
entities: ctx.data.entries,
|
|
1269
1354
|
sourceEntities: sourceData.entries,
|
|
1355
|
+
client,
|
|
1356
|
+
spaceId,
|
|
1357
|
+
environmentId,
|
|
1270
1358
|
requestQueue
|
|
1271
1359
|
});
|
|
1272
1360
|
ctx.data.publishedEntries = publishedEntries;
|
|
@@ -1279,6 +1367,9 @@ function pushToSpace({
|
|
|
1279
1367
|
const archivedEntries = await archiveEntities2({
|
|
1280
1368
|
entities: ctx.data.entries,
|
|
1281
1369
|
sourceEntities: sourceData.entries,
|
|
1370
|
+
client,
|
|
1371
|
+
spaceId,
|
|
1372
|
+
environmentId,
|
|
1282
1373
|
requestQueue
|
|
1283
1374
|
});
|
|
1284
1375
|
ctx.data.archivedEntries = archivedEntries;
|
|
@@ -1292,7 +1383,7 @@ function pushToSpace({
|
|
|
1292
1383
|
return;
|
|
1293
1384
|
}
|
|
1294
1385
|
const webhooks2 = await createEntities({
|
|
1295
|
-
context: {
|
|
1386
|
+
context: { client, spaceId, environmentId, type: "Webhook" },
|
|
1296
1387
|
entities: sourceData.webhooks,
|
|
1297
1388
|
destinationEntitiesById: destinationDataById.webhooks,
|
|
1298
1389
|
requestQueue
|
|
@@ -1303,19 +1394,24 @@ function pushToSpace({
|
|
|
1303
1394
|
},
|
|
1304
1395
|
{
|
|
1305
1396
|
title: "Create ExO Folders",
|
|
1306
|
-
task: wrapTask(async (
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
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
|
+
}
|
|
1319
1415
|
}),
|
|
1320
1416
|
skip: () => !includeExperienceOrchestration
|
|
1321
1417
|
},
|
|
@@ -1328,14 +1424,14 @@ function pushToSpace({
|
|
|
1328
1424
|
let result;
|
|
1329
1425
|
if (existing) {
|
|
1330
1426
|
const payload = { ...omitSys(entity), sys: buildDataAssemblySys(entity, existing.sys.version) };
|
|
1331
|
-
result = await withGraphQLSchemaBackoff(() =>
|
|
1427
|
+
result = await withGraphQLSchemaBackoff(() => client.dataAssembly.update(
|
|
1332
1428
|
{ spaceId, environmentId, dataAssemblyId: entity.sys.id },
|
|
1333
1429
|
payload
|
|
1334
1430
|
));
|
|
1335
1431
|
logEmitter9.emit("info", `UPDATE DataAssembly ${entity.sys.id}`);
|
|
1336
1432
|
} else {
|
|
1337
1433
|
const payload = { ...omitSys(entity), sys: buildDataAssemblySys(entity, 0) };
|
|
1338
|
-
result = await withGraphQLSchemaBackoff(() =>
|
|
1434
|
+
result = await withGraphQLSchemaBackoff(() => client.dataAssembly.update(
|
|
1339
1435
|
{ spaceId, environmentId, dataAssemblyId: entity.sys.id },
|
|
1340
1436
|
payload
|
|
1341
1437
|
));
|
|
@@ -1357,7 +1453,7 @@ function pushToSpace({
|
|
|
1357
1453
|
task: wrapTask(async (ctx) => {
|
|
1358
1454
|
const entitiesToPublish = filterExoEntitiesToPublish(ctx.data.dataAssemblies, sourceData.dataAssemblies || []);
|
|
1359
1455
|
const results = await Promise.all(entitiesToPublish.map(
|
|
1360
|
-
(entity) => publishExoEntity("DataAssembly", entity, () =>
|
|
1456
|
+
(entity) => publishExoEntity("DataAssembly", entity, () => client.dataAssembly.publish(
|
|
1361
1457
|
{ spaceId, environmentId, dataAssemblyId: entity.sys.id, version: entity.sys.version }
|
|
1362
1458
|
))
|
|
1363
1459
|
));
|
|
@@ -1373,12 +1469,12 @@ function pushToSpace({
|
|
|
1373
1469
|
const existing = destinationDataById.designTokens?.get(entity.sys.id);
|
|
1374
1470
|
if (existing) {
|
|
1375
1471
|
const payload = { ...entity, sys: { id: entity.sys.id, type: "DesignToken", version: existing.sys.version } };
|
|
1376
|
-
const result = await
|
|
1472
|
+
const result = await client.designToken.upsert({ spaceId, environmentId, designTokenId: entity.sys.id }, payload);
|
|
1377
1473
|
logEmitter9.emit("info", `UPDATE DesignToken ${entity.sys.id}`);
|
|
1378
1474
|
return result;
|
|
1379
1475
|
} else {
|
|
1380
1476
|
const payload = { ...omitSys(entity), sys: { id: entity.sys.id, type: "DesignToken" } };
|
|
1381
|
-
const result = await
|
|
1477
|
+
const result = await client.designToken.upsert({ spaceId, environmentId, designTokenId: entity.sys.id }, payload);
|
|
1382
1478
|
logEmitter9.emit("info", `CREATE DesignToken ${entity.sys.id}`);
|
|
1383
1479
|
return result;
|
|
1384
1480
|
}
|
|
@@ -1402,12 +1498,12 @@ function pushToSpace({
|
|
|
1402
1498
|
const existing = destinationDataById.components?.get(entity.sys.id);
|
|
1403
1499
|
if (existing) {
|
|
1404
1500
|
const payload = { ...entity, sys: { id: entity.sys.id, type: "Component", version: existing.sys.version } };
|
|
1405
|
-
const result = await
|
|
1501
|
+
const result = await client.component.upsert({ spaceId, environmentId, componentId: entity.sys.id }, payload);
|
|
1406
1502
|
logEmitter9.emit("info", `UPDATE Component ${entity.sys.id}`);
|
|
1407
1503
|
results.push(result);
|
|
1408
1504
|
} else {
|
|
1409
1505
|
const payload = { ...omitSys(entity), sys: { id: entity.sys.id, type: "Component" } };
|
|
1410
|
-
const result = await
|
|
1506
|
+
const result = await client.component.upsert({ spaceId, environmentId, componentId: entity.sys.id }, payload);
|
|
1411
1507
|
logEmitter9.emit("info", `CREATE Component ${entity.sys.id}`);
|
|
1412
1508
|
results.push(result);
|
|
1413
1509
|
}
|
|
@@ -1427,7 +1523,7 @@ function pushToSpace({
|
|
|
1427
1523
|
const sorted = sortOrReport(() => sortComponents(entitiesToPublish));
|
|
1428
1524
|
const results = [];
|
|
1429
1525
|
for (const entity of sorted) {
|
|
1430
|
-
const published = await publishExoEntity("Component", entity, () =>
|
|
1526
|
+
const published = await publishExoEntity("Component", entity, () => client.component.publish(
|
|
1431
1527
|
{ spaceId, environmentId, componentId: entity.sys.id, version: entity.sys.version }
|
|
1432
1528
|
));
|
|
1433
1529
|
if (published) results.push(published);
|
|
@@ -1444,12 +1540,12 @@ function pushToSpace({
|
|
|
1444
1540
|
const existing = destinationDataById.experienceTemplates?.get(entity.sys.id);
|
|
1445
1541
|
if (existing) {
|
|
1446
1542
|
const payload = { ...entity, sys: { id: entity.sys.id, type: "ExperienceTemplate", version: existing.sys.version } };
|
|
1447
|
-
const result = await
|
|
1543
|
+
const result = await client.experienceTemplate.upsert({ spaceId, environmentId, experienceTemplateId: entity.sys.id }, payload);
|
|
1448
1544
|
logEmitter9.emit("info", `UPDATE ExperienceTemplate ${entity.sys.id}`);
|
|
1449
1545
|
return result;
|
|
1450
1546
|
} else {
|
|
1451
1547
|
const payload = { ...omitSys(entity), sys: { id: entity.sys.id, type: "ExperienceTemplate" } };
|
|
1452
|
-
const result = await
|
|
1548
|
+
const result = await client.experienceTemplate.upsert({ spaceId, environmentId, experienceTemplateId: entity.sys.id }, payload);
|
|
1453
1549
|
logEmitter9.emit("info", `CREATE ExperienceTemplate ${entity.sys.id}`);
|
|
1454
1550
|
return result;
|
|
1455
1551
|
}
|
|
@@ -1468,7 +1564,7 @@ function pushToSpace({
|
|
|
1468
1564
|
task: wrapTask(async (ctx) => {
|
|
1469
1565
|
const entitiesToPublish = filterExoEntitiesToPublish(ctx.data.experienceTemplates, sourceData.experienceTemplates || []);
|
|
1470
1566
|
const results = await Promise.all(entitiesToPublish.map(
|
|
1471
|
-
(entity) => publishExoEntity("ExperienceTemplate", entity, () =>
|
|
1567
|
+
(entity) => publishExoEntity("ExperienceTemplate", entity, () => client.experienceTemplate.publish(
|
|
1472
1568
|
{ spaceId, environmentId, experienceTemplateId: entity.sys.id, version: entity.sys.version }
|
|
1473
1569
|
))
|
|
1474
1570
|
));
|
|
@@ -1486,12 +1582,12 @@ function pushToSpace({
|
|
|
1486
1582
|
const existing = destinationDataById.experienceFragments?.get(entity.sys.id);
|
|
1487
1583
|
if (existing) {
|
|
1488
1584
|
const payload = { ...entity, sys: { id: entity.sys.id, type: "ExperienceFragment", version: existing.sys.version } };
|
|
1489
|
-
const result = await
|
|
1585
|
+
const result = await client.experienceFragment.upsert({ spaceId, environmentId, experienceFragmentId: entity.sys.id }, payload);
|
|
1490
1586
|
logEmitter9.emit("info", `UPDATE ExperienceFragment ${entity.sys.id}`);
|
|
1491
1587
|
results.push(result);
|
|
1492
1588
|
} else {
|
|
1493
1589
|
const payload = { ...omitSys(entity), component: entity.sys.component, sys: { id: entity.sys.id, type: "ExperienceFragment" } };
|
|
1494
|
-
const result = await
|
|
1590
|
+
const result = await client.experienceFragment.upsert({ spaceId, environmentId, experienceFragmentId: entity.sys.id }, payload);
|
|
1495
1591
|
logEmitter9.emit("info", `CREATE ExperienceFragment ${entity.sys.id}`);
|
|
1496
1592
|
results.push(result);
|
|
1497
1593
|
}
|
|
@@ -1511,7 +1607,7 @@ function pushToSpace({
|
|
|
1511
1607
|
const sorted = sortOrReport(() => sortExperienceFragments(entitiesToPublish));
|
|
1512
1608
|
const results = [];
|
|
1513
1609
|
for (const entity of sorted) {
|
|
1514
|
-
const published = await publishExoEntity("ExperienceFragment", entity, () =>
|
|
1610
|
+
const published = await publishExoEntity("ExperienceFragment", entity, () => client.experienceFragment.publish(
|
|
1515
1611
|
{ spaceId, environmentId, experienceFragmentId: entity.sys.id, version: entity.sys.version }
|
|
1516
1612
|
));
|
|
1517
1613
|
if (published) results.push(published);
|
|
@@ -1528,12 +1624,12 @@ function pushToSpace({
|
|
|
1528
1624
|
const existing = destinationDataById.experiences?.get(entity.sys.id);
|
|
1529
1625
|
if (existing) {
|
|
1530
1626
|
const payload = { ...entity, sys: { id: entity.sys.id, type: "Experience", version: existing.sys.version } };
|
|
1531
|
-
const result = await
|
|
1627
|
+
const result = await client.experience.upsert({ spaceId, environmentId, experienceId: entity.sys.id }, payload);
|
|
1532
1628
|
logEmitter9.emit("info", `UPDATE Experience ${entity.sys.id}`);
|
|
1533
1629
|
return result;
|
|
1534
1630
|
} else {
|
|
1535
1631
|
const payload = { ...omitSys(entity), experienceTemplate: entity.sys.experienceTemplate, sys: { id: entity.sys.id, type: "Experience" } };
|
|
1536
|
-
const result = await
|
|
1632
|
+
const result = await client.experience.upsert({ spaceId, environmentId, experienceId: entity.sys.id }, payload);
|
|
1537
1633
|
logEmitter9.emit("info", `CREATE Experience ${entity.sys.id}`);
|
|
1538
1634
|
return result;
|
|
1539
1635
|
}
|
|
@@ -1552,7 +1648,7 @@ function pushToSpace({
|
|
|
1552
1648
|
task: wrapTask(async (ctx) => {
|
|
1553
1649
|
const entitiesToPublish = filterExoEntitiesToPublish(ctx.data.experiences, sourceData.experiences || []);
|
|
1554
1650
|
const results = await Promise.all(entitiesToPublish.map(
|
|
1555
|
-
(entity) => publishExoEntity("Experience", entity, () =>
|
|
1651
|
+
(entity) => publishExoEntity("Experience", entity, () => client.experience.publish(
|
|
1556
1652
|
{ spaceId, environmentId, experienceId: entity.sys.id, version: entity.sys.version }
|
|
1557
1653
|
))
|
|
1558
1654
|
));
|
|
@@ -1568,7 +1664,7 @@ function pushToSpace({
|
|
|
1568
1664
|
task: wrapTask(async (ctx) => {
|
|
1569
1665
|
const entitiesToUnpublish = filterExoEntitiesToUnpublish(ctx.data.experiences, sourceData.experiences || []);
|
|
1570
1666
|
await Promise.all(entitiesToUnpublish.map(
|
|
1571
|
-
(entity) => unpublishExoEntity("Experience", entity, () =>
|
|
1667
|
+
(entity) => unpublishExoEntity("Experience", entity, () => client.experience.unpublish(
|
|
1572
1668
|
{ spaceId, environmentId, experienceId: entity.sys.id, version: entity.sys.version }
|
|
1573
1669
|
))
|
|
1574
1670
|
));
|
|
@@ -1581,7 +1677,7 @@ function pushToSpace({
|
|
|
1581
1677
|
const entitiesToUnpublish = filterExoEntitiesToUnpublish(ctx.data.experienceFragments, sourceData.experienceFragments || []);
|
|
1582
1678
|
const sorted = sortExperienceFragments(entitiesToUnpublish).reverse();
|
|
1583
1679
|
for (const entity of sorted) {
|
|
1584
|
-
await unpublishExoEntity("ExperienceFragment", entity, () =>
|
|
1680
|
+
await unpublishExoEntity("ExperienceFragment", entity, () => client.experienceFragment.unpublish(
|
|
1585
1681
|
{ spaceId, environmentId, experienceFragmentId: entity.sys.id, version: entity.sys.version }
|
|
1586
1682
|
));
|
|
1587
1683
|
}
|
|
@@ -1593,7 +1689,7 @@ function pushToSpace({
|
|
|
1593
1689
|
task: wrapTask(async (ctx) => {
|
|
1594
1690
|
const entitiesToUnpublish = filterExoEntitiesToUnpublish(ctx.data.experienceTemplates, sourceData.experienceTemplates || []);
|
|
1595
1691
|
await Promise.all(entitiesToUnpublish.map(
|
|
1596
|
-
(entity) => unpublishExoEntity("ExperienceTemplate", entity, () =>
|
|
1692
|
+
(entity) => unpublishExoEntity("ExperienceTemplate", entity, () => client.experienceTemplate.unpublish(
|
|
1597
1693
|
{ spaceId, environmentId, experienceTemplateId: entity.sys.id, version: entity.sys.version }
|
|
1598
1694
|
))
|
|
1599
1695
|
));
|
|
@@ -1606,7 +1702,7 @@ function pushToSpace({
|
|
|
1606
1702
|
const entitiesToUnpublish = filterExoEntitiesToUnpublish(ctx.data.components, sourceData.components || []);
|
|
1607
1703
|
const sorted = sortComponents(entitiesToUnpublish).reverse();
|
|
1608
1704
|
for (const entity of sorted) {
|
|
1609
|
-
await unpublishExoEntity("Component", entity, () =>
|
|
1705
|
+
await unpublishExoEntity("Component", entity, () => client.component.unpublish(
|
|
1610
1706
|
{ spaceId, environmentId, componentId: entity.sys.id, version: entity.sys.version }
|
|
1611
1707
|
));
|
|
1612
1708
|
}
|
|
@@ -1618,7 +1714,7 @@ function pushToSpace({
|
|
|
1618
1714
|
task: wrapTask(async (ctx) => {
|
|
1619
1715
|
const entitiesToUnpublish = filterExoEntitiesToUnpublish(ctx.data.dataAssemblies, sourceData.dataAssemblies || []);
|
|
1620
1716
|
await Promise.all(entitiesToUnpublish.map(
|
|
1621
|
-
(entity) => unpublishExoEntity("DataAssembly", entity, () =>
|
|
1717
|
+
(entity) => unpublishExoEntity("DataAssembly", entity, () => client.dataAssembly.unpublish(
|
|
1622
1718
|
{ spaceId, environmentId, dataAssemblyId: entity.sys.id, version: entity.sys.version }
|
|
1623
1719
|
))
|
|
1624
1720
|
));
|
|
@@ -1631,15 +1727,15 @@ function omitSys(entity) {
|
|
|
1631
1727
|
const { sys: _sys, ...rest } = entity;
|
|
1632
1728
|
return rest;
|
|
1633
1729
|
}
|
|
1634
|
-
function archiveEntities2({ entities, sourceEntities, requestQueue }) {
|
|
1730
|
+
function archiveEntities2({ entities, sourceEntities, client, spaceId, environmentId, requestQueue }) {
|
|
1635
1731
|
const entityIdsToArchive = sourceEntities.filter(({ original }) => original.sys.archivedVersion).map(({ original }) => original.sys.id);
|
|
1636
1732
|
const entitiesToArchive = entities.filter((entity) => entityIdsToArchive.indexOf(entity.sys.id) !== -1);
|
|
1637
|
-
return archiveEntities({ entities: entitiesToArchive, requestQueue });
|
|
1733
|
+
return archiveEntities({ entities: entitiesToArchive, client, spaceId, environmentId, requestQueue });
|
|
1638
1734
|
}
|
|
1639
|
-
function publishEntities2({ entities, sourceEntities, requestQueue }) {
|
|
1735
|
+
function publishEntities2({ entities, sourceEntities, client, spaceId, environmentId, requestQueue }) {
|
|
1640
1736
|
const entityIdsToPublish = sourceEntities.filter(({ original }) => original.sys.publishedVersion).map(({ original }) => original.sys.id);
|
|
1641
1737
|
const entitiesToPublish = entities.filter((entity) => entityIdsToPublish.indexOf(entity.sys.id) !== -1);
|
|
1642
|
-
return publishEntities({ entities: entitiesToPublish, requestQueue });
|
|
1738
|
+
return publishEntities({ entities: entitiesToPublish, client, spaceId, environmentId, requestQueue });
|
|
1643
1739
|
}
|
|
1644
1740
|
|
|
1645
1741
|
// lib/transform/transform-space.ts
|
|
@@ -2162,7 +2258,8 @@ async function parseOptions(params) {
|
|
|
2162
2258
|
rawProxy: false,
|
|
2163
2259
|
uploadAssets: false,
|
|
2164
2260
|
rateLimit: 7,
|
|
2165
|
-
includeExperienceOrchestration: true
|
|
2261
|
+
includeExperienceOrchestration: true,
|
|
2262
|
+
host: "api.contentful.com"
|
|
2166
2263
|
};
|
|
2167
2264
|
const configFile = params.config ? __require(resolve(process.cwd(), params.config)) : {};
|
|
2168
2265
|
const options = {
|
|
@@ -2274,8 +2371,7 @@ async function runContentfulImport(params) {
|
|
|
2274
2371
|
{
|
|
2275
2372
|
title: "Initialize client",
|
|
2276
2373
|
task: wrapTask2(async (ctx) => {
|
|
2277
|
-
ctx.client = initClient({ ...options
|
|
2278
|
-
ctx.plainClient = initPlainClient({ ...options, content: void 0 });
|
|
2374
|
+
ctx.client = initClient({ ...options });
|
|
2279
2375
|
})
|
|
2280
2376
|
},
|
|
2281
2377
|
{
|
|
@@ -2283,7 +2379,6 @@ async function runContentfulImport(params) {
|
|
|
2283
2379
|
task: wrapTask2(async (ctx) => {
|
|
2284
2380
|
const destinationData = await getDestinationData({
|
|
2285
2381
|
client: ctx.client,
|
|
2286
|
-
plainClient: ctx.plainClient,
|
|
2287
2382
|
spaceId: options.spaceId,
|
|
2288
2383
|
environmentId: options.environmentId,
|
|
2289
2384
|
sourceData: options.content,
|
|
@@ -2311,7 +2406,6 @@ async function runContentfulImport(params) {
|
|
|
2311
2406
|
sourceData: ctx.sourceData,
|
|
2312
2407
|
destinationData: ctx.destinationData,
|
|
2313
2408
|
client: ctx.client,
|
|
2314
|
-
plainClient: ctx.plainClient,
|
|
2315
2409
|
spaceId: options.spaceId,
|
|
2316
2410
|
includeExperienceOrchestration: options.includeExperienceOrchestration,
|
|
2317
2411
|
environmentId: options.environmentId,
|