contentful-import 10.0.17 → 10.1.0-exo.1

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.d.mts CHANGED
@@ -19,6 +19,7 @@ type RunContentfulImportParams = {
19
19
  headers?: object;
20
20
  errorLogFile?: string;
21
21
  useVerboseRenderer?: boolean;
22
+ includeExperienceOrchestration?: boolean;
22
23
  timeout?: number;
23
24
  retryLimit?: number;
24
25
  config?: string;
package/dist/index.d.ts CHANGED
@@ -19,6 +19,7 @@ type RunContentfulImportParams = {
19
19
  headers?: object;
20
20
  errorLogFile?: string;
21
21
  useVerboseRenderer?: boolean;
22
+ includeExperienceOrchestration?: boolean;
22
23
  timeout?: number;
23
24
  retryLimit?: number;
24
25
  config?: string;
package/dist/index.js CHANGED
@@ -60,6 +60,13 @@ function initClient(opts) {
60
60
  };
61
61
  return (0, import_contentful_management.createClient)(config, { type: "legacy" });
62
62
  }
63
+ function initPlainClient(opts) {
64
+ return (0, import_contentful_management.createClient)({
65
+ accessToken: opts.managementToken,
66
+ host: opts.host,
67
+ logHandler
68
+ });
69
+ }
63
70
 
64
71
  // lib/tasks/get-destination-data.ts
65
72
  var import_bluebird = __toESM(require("bluebird"));
@@ -570,8 +577,10 @@ function pushToSpace({
570
577
  sourceData,
571
578
  destinationData = {},
572
579
  client,
580
+ plainClient,
573
581
  spaceId,
574
582
  environmentId,
583
+ includeExperienceOrchestration,
575
584
  contentModelOnly,
576
585
  skipContentModel,
577
586
  skipContentUpdates,
@@ -847,9 +856,108 @@ function pushToSpace({
847
856
  ctx.data.webhooks = webhooks2;
848
857
  }),
849
858
  skip: () => contentModelOnly || environmentId !== "master" && "Webhooks can only be imported in master environment"
859
+ },
860
+ {
861
+ title: "Importing Component Types",
862
+ task: (0, import_listr2.wrapTask)(async (ctx) => {
863
+ const results = await Promise.all((sourceData.componentTypes || []).map(async (entity) => {
864
+ try {
865
+ const result = await plainClient.componentType.upsert({ spaceId, environmentId, componentTypeId: entity.sys.id }, omitSys(entity));
866
+ import_logging6.logEmitter.emit("info", `UPSERT ComponentType ${entity.sys.id}`);
867
+ return result;
868
+ } catch (err) {
869
+ import_logging6.logEmitter.emit("error", err);
870
+ return null;
871
+ }
872
+ }));
873
+ ctx.data.componentTypes = results.filter(Boolean);
874
+ }),
875
+ skip: () => !includeExperienceOrchestration || !(sourceData.componentTypes || []).length
876
+ },
877
+ {
878
+ title: "Importing Templates",
879
+ task: (0, import_listr2.wrapTask)(async (ctx) => {
880
+ const results = await Promise.all((sourceData.templates || []).map(async (entity) => {
881
+ try {
882
+ const result = await plainClient.template.upsert({ spaceId, environmentId, templateId: entity.sys.id }, omitSys(entity));
883
+ import_logging6.logEmitter.emit("info", `UPSERT Template ${entity.sys.id}`);
884
+ return result;
885
+ } catch (err) {
886
+ import_logging6.logEmitter.emit("error", err);
887
+ return null;
888
+ }
889
+ }));
890
+ ctx.data.templates = results.filter(Boolean);
891
+ }),
892
+ skip: () => !includeExperienceOrchestration || !(sourceData.templates || []).length
893
+ },
894
+ {
895
+ title: "Importing Fragments",
896
+ task: (0, import_listr2.wrapTask)(async (ctx) => {
897
+ const results = await Promise.all((sourceData.fragments || []).map(async (entity) => {
898
+ try {
899
+ const result = await plainClient.fragment.upsert({ spaceId, environmentId, fragmentId: entity.sys.id }, omitSys(entity));
900
+ import_logging6.logEmitter.emit("info", `UPSERT Fragment ${entity.sys.id}`);
901
+ return result;
902
+ } catch (err) {
903
+ import_logging6.logEmitter.emit("error", err);
904
+ return null;
905
+ }
906
+ }));
907
+ ctx.data.fragments = results.filter(Boolean);
908
+ }),
909
+ skip: () => !includeExperienceOrchestration || !(sourceData.fragments || []).length
910
+ },
911
+ {
912
+ title: "Importing Data Assemblies",
913
+ task: (0, import_listr2.wrapTask)(async (ctx) => {
914
+ const results = await Promise.all((sourceData.dataAssemblies || []).map(async (entity) => {
915
+ try {
916
+ let result;
917
+ try {
918
+ const existing = await plainClient.dataAssembly.get({ spaceId, environmentId, dataAssemblyId: entity.sys.id });
919
+ result = await plainClient.dataAssembly.update({ spaceId, environmentId, dataAssemblyId: entity.sys.id }, { ...omitSys(entity), sys: { version: existing.sys.version } });
920
+ } catch (getErr) {
921
+ if (getErr.status === 404) {
922
+ result = await plainClient.dataAssembly.create({ spaceId, environmentId }, omitSys(entity));
923
+ } else {
924
+ throw getErr;
925
+ }
926
+ }
927
+ import_logging6.logEmitter.emit("info", `UPSERT DataAssembly ${entity.sys.id}`);
928
+ return result;
929
+ } catch (err) {
930
+ import_logging6.logEmitter.emit("error", err);
931
+ return null;
932
+ }
933
+ }));
934
+ ctx.data.dataAssemblies = results.filter(Boolean);
935
+ }),
936
+ skip: () => !includeExperienceOrchestration || !(sourceData.dataAssemblies || []).length
937
+ },
938
+ {
939
+ title: "Importing Experiences",
940
+ task: (0, import_listr2.wrapTask)(async (ctx) => {
941
+ const results = await Promise.all((sourceData.experiences || []).map(async (entity) => {
942
+ try {
943
+ const result = await plainClient.experience.upsert({ spaceId, environmentId, experienceId: entity.sys.id }, omitSys(entity));
944
+ import_logging6.logEmitter.emit("info", `UPSERT Experience ${entity.sys.id}`);
945
+ return result;
946
+ } catch (err) {
947
+ import_logging6.logEmitter.emit("error", err);
948
+ return null;
949
+ }
950
+ }));
951
+ ctx.data.experiences = results.filter(Boolean);
952
+ }),
953
+ skip: () => !includeExperienceOrchestration || !(sourceData.experiences || []).length
850
954
  }
851
955
  ], listrOptions);
852
956
  }
957
+ function omitSys(entity) {
958
+ const { sys: _sys, ...rest } = entity;
959
+ return rest;
960
+ }
853
961
  function archiveEntities2({ entities, sourceEntities, requestQueue }) {
854
962
  const entityIdsToArchive = sourceEntities.filter(({ original }) => original.sys.archivedVersion).map(({ original }) => original.sys.id);
855
963
  const entitiesToArchive = entities.filter((entity) => entityIdsToArchive.indexOf(entity.sys.id) !== -1);
@@ -1218,7 +1326,12 @@ var SUPPORTED_ENTITY_TYPES = [
1218
1326
  "assets",
1219
1327
  "locales",
1220
1328
  "webhooks",
1221
- "editorInterfaces"
1329
+ "editorInterfaces",
1330
+ "componentTypes",
1331
+ "templates",
1332
+ "dataAssemblies",
1333
+ "fragments",
1334
+ "experiences"
1222
1335
  ];
1223
1336
  async function parseOptions(params) {
1224
1337
  const defaultOptions = {
@@ -1231,7 +1344,8 @@ async function parseOptions(params) {
1231
1344
  environmentId: "master",
1232
1345
  rawProxy: false,
1233
1346
  uploadAssets: false,
1234
- rateLimit: 7
1347
+ rateLimit: 7,
1348
+ includeExperienceOrchestration: false
1235
1349
  };
1236
1350
  const configFile = params.config ? require((0, import_path2.resolve)(process.cwd(), params.config)) : {};
1237
1351
  const options = {
@@ -1344,6 +1458,7 @@ async function runContentfulImport(params) {
1344
1458
  title: "Initialize client",
1345
1459
  task: (0, import_listr4.wrapTask)(async (ctx) => {
1346
1460
  ctx.client = initClient({ ...options, content: void 0 });
1461
+ ctx.plainClient = initPlainClient({ ...options, content: void 0 });
1347
1462
  })
1348
1463
  },
1349
1464
  {
@@ -1377,7 +1492,9 @@ async function runContentfulImport(params) {
1377
1492
  sourceData: ctx.sourceData,
1378
1493
  destinationData: ctx.destinationData,
1379
1494
  client: ctx.client,
1495
+ plainClient: ctx.plainClient,
1380
1496
  spaceId: options.spaceId,
1497
+ includeExperienceOrchestration: options.includeExperienceOrchestration,
1381
1498
  environmentId: options.environmentId,
1382
1499
  contentModelOnly: options.contentModelOnly,
1383
1500
  skipLocales: options.skipLocales,
package/dist/index.mjs CHANGED
@@ -33,6 +33,13 @@ function initClient(opts) {
33
33
  };
34
34
  return createClient(config, { type: "legacy" });
35
35
  }
36
+ function initPlainClient(opts) {
37
+ return createClient({
38
+ accessToken: opts.managementToken,
39
+ host: opts.host,
40
+ logHandler
41
+ });
42
+ }
36
43
 
37
44
  // lib/tasks/get-destination-data.ts
38
45
  import Promise2 from "bluebird";
@@ -543,8 +550,10 @@ function pushToSpace({
543
550
  sourceData,
544
551
  destinationData = {},
545
552
  client,
553
+ plainClient,
546
554
  spaceId,
547
555
  environmentId,
556
+ includeExperienceOrchestration,
548
557
  contentModelOnly,
549
558
  skipContentModel,
550
559
  skipContentUpdates,
@@ -820,9 +829,108 @@ function pushToSpace({
820
829
  ctx.data.webhooks = webhooks2;
821
830
  }),
822
831
  skip: () => contentModelOnly || environmentId !== "master" && "Webhooks can only be imported in master environment"
832
+ },
833
+ {
834
+ title: "Importing Component Types",
835
+ task: wrapTask(async (ctx) => {
836
+ const results = await Promise.all((sourceData.componentTypes || []).map(async (entity) => {
837
+ try {
838
+ const result = await plainClient.componentType.upsert({ spaceId, environmentId, componentTypeId: entity.sys.id }, omitSys(entity));
839
+ logEmitter6.emit("info", `UPSERT ComponentType ${entity.sys.id}`);
840
+ return result;
841
+ } catch (err) {
842
+ logEmitter6.emit("error", err);
843
+ return null;
844
+ }
845
+ }));
846
+ ctx.data.componentTypes = results.filter(Boolean);
847
+ }),
848
+ skip: () => !includeExperienceOrchestration || !(sourceData.componentTypes || []).length
849
+ },
850
+ {
851
+ title: "Importing Templates",
852
+ task: wrapTask(async (ctx) => {
853
+ const results = await Promise.all((sourceData.templates || []).map(async (entity) => {
854
+ try {
855
+ const result = await plainClient.template.upsert({ spaceId, environmentId, templateId: entity.sys.id }, omitSys(entity));
856
+ logEmitter6.emit("info", `UPSERT Template ${entity.sys.id}`);
857
+ return result;
858
+ } catch (err) {
859
+ logEmitter6.emit("error", err);
860
+ return null;
861
+ }
862
+ }));
863
+ ctx.data.templates = results.filter(Boolean);
864
+ }),
865
+ skip: () => !includeExperienceOrchestration || !(sourceData.templates || []).length
866
+ },
867
+ {
868
+ title: "Importing Fragments",
869
+ task: wrapTask(async (ctx) => {
870
+ const results = await Promise.all((sourceData.fragments || []).map(async (entity) => {
871
+ try {
872
+ const result = await plainClient.fragment.upsert({ spaceId, environmentId, fragmentId: entity.sys.id }, omitSys(entity));
873
+ logEmitter6.emit("info", `UPSERT Fragment ${entity.sys.id}`);
874
+ return result;
875
+ } catch (err) {
876
+ logEmitter6.emit("error", err);
877
+ return null;
878
+ }
879
+ }));
880
+ ctx.data.fragments = results.filter(Boolean);
881
+ }),
882
+ skip: () => !includeExperienceOrchestration || !(sourceData.fragments || []).length
883
+ },
884
+ {
885
+ title: "Importing Data Assemblies",
886
+ task: wrapTask(async (ctx) => {
887
+ const results = await Promise.all((sourceData.dataAssemblies || []).map(async (entity) => {
888
+ try {
889
+ let result;
890
+ try {
891
+ const existing = await plainClient.dataAssembly.get({ spaceId, environmentId, dataAssemblyId: entity.sys.id });
892
+ result = await plainClient.dataAssembly.update({ spaceId, environmentId, dataAssemblyId: entity.sys.id }, { ...omitSys(entity), sys: { version: existing.sys.version } });
893
+ } catch (getErr) {
894
+ if (getErr.status === 404) {
895
+ result = await plainClient.dataAssembly.create({ spaceId, environmentId }, omitSys(entity));
896
+ } else {
897
+ throw getErr;
898
+ }
899
+ }
900
+ logEmitter6.emit("info", `UPSERT DataAssembly ${entity.sys.id}`);
901
+ return result;
902
+ } catch (err) {
903
+ logEmitter6.emit("error", err);
904
+ return null;
905
+ }
906
+ }));
907
+ ctx.data.dataAssemblies = results.filter(Boolean);
908
+ }),
909
+ skip: () => !includeExperienceOrchestration || !(sourceData.dataAssemblies || []).length
910
+ },
911
+ {
912
+ title: "Importing Experiences",
913
+ task: wrapTask(async (ctx) => {
914
+ const results = await Promise.all((sourceData.experiences || []).map(async (entity) => {
915
+ try {
916
+ const result = await plainClient.experience.upsert({ spaceId, environmentId, experienceId: entity.sys.id }, omitSys(entity));
917
+ logEmitter6.emit("info", `UPSERT Experience ${entity.sys.id}`);
918
+ return result;
919
+ } catch (err) {
920
+ logEmitter6.emit("error", err);
921
+ return null;
922
+ }
923
+ }));
924
+ ctx.data.experiences = results.filter(Boolean);
925
+ }),
926
+ skip: () => !includeExperienceOrchestration || !(sourceData.experiences || []).length
823
927
  }
824
928
  ], listrOptions);
825
929
  }
930
+ function omitSys(entity) {
931
+ const { sys: _sys, ...rest } = entity;
932
+ return rest;
933
+ }
826
934
  function archiveEntities2({ entities, sourceEntities, requestQueue }) {
827
935
  const entityIdsToArchive = sourceEntities.filter(({ original }) => original.sys.archivedVersion).map(({ original }) => original.sys.id);
828
936
  const entitiesToArchive = entities.filter((entity) => entityIdsToArchive.indexOf(entity.sys.id) !== -1);
@@ -1188,7 +1296,12 @@ var SUPPORTED_ENTITY_TYPES = [
1188
1296
  "assets",
1189
1297
  "locales",
1190
1298
  "webhooks",
1191
- "editorInterfaces"
1299
+ "editorInterfaces",
1300
+ "componentTypes",
1301
+ "templates",
1302
+ "dataAssemblies",
1303
+ "fragments",
1304
+ "experiences"
1192
1305
  ];
1193
1306
  async function parseOptions(params) {
1194
1307
  const defaultOptions = {
@@ -1201,7 +1314,8 @@ async function parseOptions(params) {
1201
1314
  environmentId: "master",
1202
1315
  rawProxy: false,
1203
1316
  uploadAssets: false,
1204
- rateLimit: 7
1317
+ rateLimit: 7,
1318
+ includeExperienceOrchestration: false
1205
1319
  };
1206
1320
  const configFile = params.config ? __require(resolve(process.cwd(), params.config)) : {};
1207
1321
  const options = {
@@ -1314,6 +1428,7 @@ async function runContentfulImport(params) {
1314
1428
  title: "Initialize client",
1315
1429
  task: wrapTask2(async (ctx) => {
1316
1430
  ctx.client = initClient({ ...options, content: void 0 });
1431
+ ctx.plainClient = initPlainClient({ ...options, content: void 0 });
1317
1432
  })
1318
1433
  },
1319
1434
  {
@@ -1347,7 +1462,9 @@ async function runContentfulImport(params) {
1347
1462
  sourceData: ctx.sourceData,
1348
1463
  destinationData: ctx.destinationData,
1349
1464
  client: ctx.client,
1465
+ plainClient: ctx.plainClient,
1350
1466
  spaceId: options.spaceId,
1467
+ includeExperienceOrchestration: options.includeExperienceOrchestration,
1351
1468
  environmentId: options.environmentId,
1352
1469
  contentModelOnly: options.contentModelOnly,
1353
1470
  skipLocales: options.skipLocales,
@@ -29,6 +29,8 @@ declare const _default: {
29
29
  "rate-limit": number;
30
30
  rateLimit: number;
31
31
  header: string | undefined;
32
+ "include-experience-orchestration": boolean;
33
+ includeExperienceOrchestration: boolean;
32
34
  _: (string | number)[];
33
35
  $0: string;
34
36
  } | Promise<{
@@ -62,6 +64,8 @@ declare const _default: {
62
64
  "rate-limit": number;
63
65
  rateLimit: number;
64
66
  header: string | undefined;
67
+ "include-experience-orchestration": boolean;
68
+ includeExperienceOrchestration: boolean;
65
69
  _: (string | number)[];
66
70
  $0: string;
67
71
  }>;
@@ -29,6 +29,8 @@ declare const _default: {
29
29
  "rate-limit": number;
30
30
  rateLimit: number;
31
31
  header: string | undefined;
32
+ "include-experience-orchestration": boolean;
33
+ includeExperienceOrchestration: boolean;
32
34
  _: (string | number)[];
33
35
  $0: string;
34
36
  } | Promise<{
@@ -62,6 +64,8 @@ declare const _default: {
62
64
  "rate-limit": number;
63
65
  rateLimit: number;
64
66
  header: string | undefined;
67
+ "include-experience-orchestration": boolean;
68
+ includeExperienceOrchestration: boolean;
65
69
  _: (string | number)[];
66
70
  $0: string;
67
71
  }>;
@@ -99,4 +99,8 @@ var usageParams_default = import_yargs.default.version(version || "Version only
99
99
  alias: "H",
100
100
  type: "string",
101
101
  describe: "Pass an additional HTTP Header"
102
+ }).option("include-experience-orchestration", {
103
+ describe: "Import Experience Orchestration entities (componentTypes, templates, fragments, dataAssemblies, experiences). Requires a space with ExO enabled.",
104
+ type: "boolean",
105
+ default: false
102
106
  }).config("config", "An optional configuration JSON file containing all the options for a single run").argv;
@@ -65,6 +65,10 @@ var usageParams_default = yargs.version(version || "Version only available on in
65
65
  alias: "H",
66
66
  type: "string",
67
67
  describe: "Pass an additional HTTP Header"
68
+ }).option("include-experience-orchestration", {
69
+ describe: "Import Experience Orchestration entities (componentTypes, templates, fragments, dataAssemblies, experiences). Requires a space with ExO enabled.",
70
+ type: "boolean",
71
+ default: false
68
72
  }).config("config", "An optional configuration JSON file containing all the options for a single run").argv;
69
73
  export {
70
74
  usageParams_default as default
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contentful-import",
3
- "version": "10.0.17",
3
+ "version": "10.1.0-exo.1",
4
4
  "description": "this tool allows you to import JSON dump exported by contentful-export",
5
5
  "main": "dist/index.mjs",
6
6
  "typings": "dist/index.d.ts",
@@ -64,7 +64,7 @@
64
64
  "bluebird": "^3.7.2",
65
65
  "cli-table3": "^0.6.5",
66
66
  "contentful-batch-libs": "^9.7.0",
67
- "contentful-management": "^12.8.0",
67
+ "contentful-management": "^12.6.0-dev.4",
68
68
  "date-fns": "^2.30.0",
69
69
  "joi": "^18.2.3",
70
70
  "listr": "^0.14.3",