@contentstack/cli-cm-import 1.15.6 → 1.15.7

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/README.md CHANGED
@@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
47
47
  $ csdx COMMAND
48
48
  running command...
49
49
  $ csdx (--version)
50
- @contentstack/cli-cm-import/1.15.6 linux-x64 node-v18.20.3
50
+ @contentstack/cli-cm-import/1.15.7 linux-x64 node-v18.20.3
51
51
  $ csdx --help [COMMAND]
52
52
  USAGE
53
53
  $ csdx COMMAND
@@ -70,13 +70,14 @@ const lookupAssets = function (data, mappedAssetUids, mappedAssetUrls, assetUidM
70
70
  let matchedUids = [];
71
71
  let matchedUrls = [];
72
72
  let find = function (schema, entryToFind) {
73
+ var _a, _b, _c, _d, _e, _f, _g, _h;
73
74
  for (let i = 0, _i = schema.length; i < _i; i++) {
74
75
  if (schema[i].data_type === 'text' &&
75
76
  schema[i].field_metadata &&
76
- (schema[i].field_metadata.markdown || schema[i].field_metadata.rich_text_type)) {
77
+ (((_b = (_a = schema[i]) === null || _a === void 0 ? void 0 : _a.field_metadata) === null || _b === void 0 ? void 0 : _b.markdown) || ((_d = (_c = schema[i]) === null || _c === void 0 ? void 0 : _c.field_metadata) === null || _d === void 0 ? void 0 : _d.rich_text_type))) {
77
78
  parent.push(schema[i].uid);
78
79
  findFileUrls(schema[i], entryToFind, assetUrls);
79
- if (schema[i].field_metadata.rich_text_type) {
80
+ if ((_f = (_e = schema[i]) === null || _e === void 0 ? void 0 : _e.field_metadata) === null || _f === void 0 ? void 0 : _f.rich_text_type) {
80
81
  findAssetIdsFromHtmlRte(entryToFind, schema[i]);
81
82
  }
82
83
  parent.pop();
@@ -99,7 +100,7 @@ const lookupAssets = function (data, mappedAssetUids, mappedAssetUrls, assetUidM
99
100
  }
100
101
  // added rich_text_type field check because some marketplace extensions also
101
102
  // have data_type has json
102
- if (schema[i].data_type === 'json' && schema[i].field_metadata.rich_text_type) {
103
+ if (schema[i].data_type === 'json' && ((_h = (_g = schema[i]) === null || _g === void 0 ? void 0 : _g.field_metadata) === null || _h === void 0 ? void 0 : _h.rich_text_type)) {
103
104
  parent.push(schema[i].uid);
104
105
  // findFileUrls(schema[i], entry, assetUrls)
105
106
  findAssetIdsFromJsonRte(data.entry, data.content_type.schema);
@@ -144,6 +145,7 @@ const lookupAssets = function (data, mappedAssetUids, mappedAssetUrls, assetUidM
144
145
  }
145
146
  }
146
147
  function findAssetIdsFromJsonRte(entryObj, ctSchema) {
148
+ var _a;
147
149
  for (const element of ctSchema) {
148
150
  switch (element.data_type) {
149
151
  case 'blocks': {
@@ -173,7 +175,7 @@ const lookupAssets = function (data, mappedAssetUids, mappedAssetUrls, assetUidM
173
175
  break;
174
176
  }
175
177
  case 'json': {
176
- if (entryObj[element.uid] && element.field_metadata.rich_text_type) {
178
+ if (entryObj[element.uid] && ((_a = element === null || element === void 0 ? void 0 : element.field_metadata) === null || _a === void 0 ? void 0 : _a.rich_text_type)) {
177
179
  if (element.multiple) {
178
180
  entryObj[element.uid].forEach((jsonRteData) => {
179
181
  gatherJsonRteAssetIds(jsonRteData);
@@ -51,6 +51,7 @@ exports.schemaTemplate = {
51
51
  * MIT Licensed
52
52
  */
53
53
  const suppressSchemaReference = function (schema, flag) {
54
+ var _a, _b, _c, _d;
54
55
  for (var i in schema) {
55
56
  if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') {
56
57
  (0, exports.suppressSchemaReference)(schema[i].schema, flag);
@@ -63,12 +64,12 @@ const suppressSchemaReference = function (schema, flag) {
63
64
  else if (schema[i].data_type === 'reference') {
64
65
  flag.references = true;
65
66
  }
66
- else if (schema[i].data_type === 'json' && schema[i].field_metadata.rich_text_type) {
67
+ else if (schema[i].data_type === 'json' && ((_b = (_a = schema[i]) === null || _a === void 0 ? void 0 : _a.field_metadata) === null || _b === void 0 ? void 0 : _b.rich_text_type)) {
67
68
  flag.jsonRte = true;
68
69
  if (schema[i].field_metadata.embed_entry === true)
69
70
  flag.jsonRteEmbeddedEntries = true;
70
71
  }
71
- else if (schema[i].data_type === 'text' && schema[i].field_metadata.rich_text_type) {
72
+ else if (schema[i].data_type === 'text' && ((_d = (_c = schema[i]) === null || _c === void 0 ? void 0 : _c.field_metadata) === null || _d === void 0 ? void 0 : _d.rich_text_type)) {
72
73
  flag.rte = true;
73
74
  if (schema[i].field_metadata.embed_entry === true)
74
75
  flag.rteEmbeddedEntries = true;
@@ -85,6 +86,7 @@ const suppressSchemaReference = function (schema, flag) {
85
86
  };
86
87
  exports.suppressSchemaReference = suppressSchemaReference;
87
88
  const removeReferenceFields = async function (schema, flag = { supressed: false }, stackAPIClient) {
89
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
88
90
  for (let i = 0; i < schema.length; i++) {
89
91
  if (schema[i].data_type === 'group') {
90
92
  await (0, exports.removeReferenceFields)(schema[i].schema, flag, stackAPIClient);
@@ -146,18 +148,18 @@ const removeReferenceFields = async function (schema, flag = { supressed: false
146
148
  else if (
147
149
  // handling entry references in json rte
148
150
  schema[i].data_type === 'json' &&
149
- schema[i].field_metadata.rich_text_type &&
150
- schema[i].field_metadata.embed_entry &&
151
- schema[i].reference_to.length > 1) {
151
+ ((_b = (_a = schema[i]) === null || _a === void 0 ? void 0 : _a.field_metadata) === null || _b === void 0 ? void 0 : _b.rich_text_type) &&
152
+ ((_d = (_c = schema[i]) === null || _c === void 0 ? void 0 : _c.field_metadata) === null || _d === void 0 ? void 0 : _d.embed_entry) &&
153
+ ((_f = (_e = schema[i]) === null || _e === void 0 ? void 0 : _e.reference_to) === null || _f === void 0 ? void 0 : _f.length) > 1) {
152
154
  flag.supressed = true;
153
155
  schema[i].reference_to = ['sys_assets'];
154
156
  }
155
157
  else if (
156
158
  // handling entry references in rte
157
159
  schema[i].data_type === 'text' &&
158
- schema[i].field_metadata.rich_text_type &&
159
- schema[i].field_metadata.embed_entry &&
160
- schema[i].reference_to.length >= 1) {
160
+ ((_h = (_g = schema[i]) === null || _g === void 0 ? void 0 : _g.field_metadata) === null || _h === void 0 ? void 0 : _h.rich_text_type) &&
161
+ ((_k = (_j = schema[i]) === null || _j === void 0 ? void 0 : _j.field_metadata) === null || _k === void 0 ? void 0 : _k.embed_entry) &&
162
+ ((_m = (_l = schema[i]) === null || _l === void 0 ? void 0 : _l.reference_to) === null || _m === void 0 ? void 0 : _m.length) >= 1) {
161
163
  flag.supressed = true;
162
164
  schema[i].reference_to = ['sys_assets'];
163
165
  }
@@ -47,15 +47,15 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
47
47
  });
48
48
  }
49
49
  const update = function (_parent, form_id, updateEntry) {
50
- var _a, _b, _c;
50
+ var _a, _b, _c, _d;
51
51
  let _entry = updateEntry;
52
52
  let len = _parent === null || _parent === void 0 ? void 0 : _parent.length;
53
53
  for (let j = 0; j < len; j++) {
54
54
  if (_entry && _parent[j]) {
55
55
  if (j === len - 1 && _entry[_parent[j]]) {
56
56
  if (form_id !== '_assets') {
57
- if ((_a = _entry[_parent[j]]) === null || _a === void 0 ? void 0 : _a.length) {
58
- _entry[_parent[j]].forEach((item, idx) => {
57
+ if (((_a = _entry[_parent[j]]) === null || _a === void 0 ? void 0 : _a.length) && Object.keys(_entry).includes(_parent[j])) {
58
+ (_b = _entry[_parent[j]]) === null || _b === void 0 ? void 0 : _b.forEach((item, idx) => {
59
59
  if (typeof item.uid === 'string' && item._content_type_uid) {
60
60
  uids.push(item.uid);
61
61
  }
@@ -74,12 +74,12 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
74
74
  }
75
75
  else if (Array.isArray(_entry[_parent[j]])) {
76
76
  for (const element of _entry[_parent[j]]) {
77
- if ((_b = element.uid) === null || _b === void 0 ? void 0 : _b.length) {
77
+ if ((_c = element.uid) === null || _c === void 0 ? void 0 : _c.length) {
78
78
  uids.push(element.uid);
79
79
  }
80
80
  }
81
81
  }
82
- else if ((_c = _entry[_parent[j]].uid) === null || _c === void 0 ? void 0 : _c.length) {
82
+ else if ((_d = _entry[_parent[j]].uid) === null || _d === void 0 ? void 0 : _d.length) {
83
83
  uids.push(_entry[_parent[j]].uid);
84
84
  }
85
85
  }
@@ -102,13 +102,13 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
102
102
  }
103
103
  };
104
104
  const find = function (schema = [], _entry) {
105
- var _a;
105
+ var _a, _b, _c, _d, _e;
106
106
  for (let i = 0, _i = schema === null || schema === void 0 ? void 0 : schema.length; i < _i; i++) {
107
107
  switch (schema[i].data_type) {
108
108
  case 'reference':
109
109
  if (Array.isArray(schema[i].reference_to)) {
110
110
  isNewRefFields = true;
111
- schema[i].reference_to.forEach((reference) => {
111
+ (_b = (_a = schema[i]) === null || _a === void 0 ? void 0 : _a.reference_to) === null || _b === void 0 ? void 0 : _b.forEach((reference) => {
112
112
  parent.push(schema[i].uid);
113
113
  update(parent, reference, _entry);
114
114
  parent.pop();
@@ -127,7 +127,7 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
127
127
  parent.pop();
128
128
  break;
129
129
  case 'blocks':
130
- for (let j = 0, _j = (_a = schema[i].blocks) === null || _a === void 0 ? void 0 : _a.length; j < _j; j++) {
130
+ for (let j = 0, _j = (_c = schema[i].blocks) === null || _c === void 0 ? void 0 : _c.length; j < _j; j++) {
131
131
  parent.push(schema[i].uid);
132
132
  parent.push(schema[i].blocks[j].uid);
133
133
  find(schema[i].blocks[j].schema, _entry);
@@ -136,7 +136,7 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
136
136
  }
137
137
  break;
138
138
  case 'json':
139
- if (schema[i].field_metadata.rich_text_type) {
139
+ if ((_e = (_d = schema[i]) === null || _d === void 0 ? void 0 : _d.field_metadata) === null || _e === void 0 ? void 0 : _e.rich_text_type) {
140
140
  findEntryIdsFromJsonRte(data.entry, data.content_type.schema);
141
141
  }
142
142
  break;
@@ -144,7 +144,7 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
144
144
  }
145
145
  };
146
146
  function findEntryIdsFromJsonRte(entry, ctSchema = []) {
147
- var _a, _b, _c;
147
+ var _a, _b, _c, _d;
148
148
  for (const element of ctSchema) {
149
149
  switch (element.data_type) {
150
150
  case 'blocks': {
@@ -174,9 +174,9 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
174
174
  break;
175
175
  }
176
176
  case 'json': {
177
- if (entry[element.uid] && element.field_metadata.rich_text_type) {
177
+ if (entry[element.uid] && ((_c = element === null || element === void 0 ? void 0 : element.field_metadata) === null || _c === void 0 ? void 0 : _c.rich_text_type)) {
178
178
  if (element.multiple) {
179
- (_c = entry[element.uid]) === null || _c === void 0 ? void 0 : _c.forEach((jsonRteData) => {
179
+ (_d = entry[element.uid]) === null || _d === void 0 ? void 0 : _d.forEach((jsonRteData) => {
180
180
  gatherJsonRteEntryIds(jsonRteData);
181
181
  });
182
182
  }
@@ -200,7 +200,7 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
200
200
  }
201
201
  uids = _.uniq(uids);
202
202
  let entry = JSON.stringify(data.entry);
203
- uids.forEach(function (uid) {
203
+ uids === null || uids === void 0 ? void 0 : uids.forEach(function (uid) {
204
204
  if (mappedUids.hasOwnProperty(uid)) {
205
205
  const sanitizedUid = (0, cli_utilities_1.escapeRegExp)(uid);
206
206
  const escapedMappedUid = (0, cli_utilities_1.escapeRegExp)(mappedUids[uid]);
@@ -252,7 +252,7 @@ function findUidsInNewRefFields(entry, uids) {
252
252
  uids.push(entry.uid);
253
253
  }
254
254
  else if (Array.isArray(entry) && entry.length) {
255
- entry.forEach(function (elem) {
255
+ entry === null || entry === void 0 ? void 0 : entry.forEach(function (elem) {
256
256
  findUidsInNewRefFields(elem, uids);
257
257
  });
258
258
  }
@@ -266,6 +266,7 @@ function findUidsInNewRefFields(entry, uids) {
266
266
  }
267
267
  }
268
268
  const removeUidsFromJsonRteFields = (entry, ctSchema = []) => {
269
+ var _a;
269
270
  for (const element of ctSchema) {
270
271
  switch (element.data_type) {
271
272
  case 'blocks': {
@@ -298,7 +299,7 @@ const removeUidsFromJsonRteFields = (entry, ctSchema = []) => {
298
299
  break;
299
300
  }
300
301
  case 'json': {
301
- if (entry[element.uid] && element.field_metadata.rich_text_type) {
302
+ if (entry[element.uid] && ((_a = element === null || element === void 0 ? void 0 : element.field_metadata) === null || _a === void 0 ? void 0 : _a.rich_text_type)) {
302
303
  if (element.multiple) {
303
304
  entry[element.uid] = entry[element.uid].map((jsonRteData) => {
304
305
  delete jsonRteData.uid; // remove uid
@@ -357,7 +358,7 @@ function removeUidsFromChildren(children) {
357
358
  }
358
359
  }
359
360
  const removeEntryRefsFromJSONRTE = (entry, ctSchema = []) => {
360
- var _a, _b;
361
+ var _a, _b, _c, _d;
361
362
  for (const element of ctSchema) {
362
363
  switch (element.data_type) {
363
364
  case 'blocks': {
@@ -391,7 +392,7 @@ const removeEntryRefsFromJSONRTE = (entry, ctSchema = []) => {
391
392
  }
392
393
  case 'json': {
393
394
  const structuredPTag = '{"type":"p","attrs":{},"children":[{"text":""}]}';
394
- if (entry[element.uid] && element.field_metadata.rich_text_type) {
395
+ if (entry[element.uid] && ((_a = element === null || element === void 0 ? void 0 : element.field_metadata) === null || _a === void 0 ? void 0 : _a.rich_text_type)) {
395
396
  if (element.multiple) {
396
397
  entry[element.uid] = entry[element.uid].map(removeReferenceInJsonRTE);
397
398
  entry[element.uid] = entry[element.uid].map((jsonRteData) => {
@@ -414,10 +415,10 @@ const removeEntryRefsFromJSONRTE = (entry, ctSchema = []) => {
414
415
  else {
415
416
  // NOTE Clean up all the reference
416
417
  entry[element.uid] = removeReferenceInJsonRTE(entry[element.uid]);
417
- let entryReferences = (_a = entry[element.uid].children) === null || _a === void 0 ? void 0 : _a.filter((e) => doEntryReferencesExist(e));
418
+ let entryReferences = (_b = entry[element.uid].children) === null || _b === void 0 ? void 0 : _b.filter((e) => doEntryReferencesExist(e));
418
419
  if ((entryReferences === null || entryReferences === void 0 ? void 0 : entryReferences.length) > 0) {
419
420
  entry[element.uid].children = entry[element.uid].children.filter((e) => !doEntryReferencesExist(e));
420
- if (((_b = entry[element.uid].children) === null || _b === void 0 ? void 0 : _b.length) === 0) {
421
+ if (((_c = entry[element.uid].children) === null || _c === void 0 ? void 0 : _c.length) === 0) {
421
422
  entry[element.uid].children.push(JSON.parse(structuredPTag));
422
423
  }
423
424
  }
@@ -426,7 +427,7 @@ const removeEntryRefsFromJSONRTE = (entry, ctSchema = []) => {
426
427
  break;
427
428
  }
428
429
  case 'text': {
429
- if (entry[element.uid] && element.field_metadata.rich_text_type) {
430
+ if (entry[element.uid] && ((_d = element === null || element === void 0 ? void 0 : element.field_metadata) === null || _d === void 0 ? void 0 : _d.rich_text_type)) {
430
431
  if (element.multiple) {
431
432
  let rteContent = [];
432
433
  for (let i = 0; i < entry[element.uid].length; i++) {
@@ -477,6 +478,7 @@ function isEntryRef(element) {
477
478
  return element.type === 'reference' && ((_a = element.attrs) === null || _a === void 0 ? void 0 : _a.type) === 'entry';
478
479
  }
479
480
  const restoreJsonRteEntryRefs = (entry, sourceStackEntry, ctSchema = [], { uidMapper, mappedAssetUids, mappedAssetUrls }) => {
481
+ var _a, _b;
480
482
  for (const element of ctSchema) {
481
483
  switch (element.data_type) {
482
484
  case 'blocks': {
@@ -524,7 +526,7 @@ const restoreJsonRteEntryRefs = (entry, sourceStackEntry, ctSchema = [], { uidMa
524
526
  break;
525
527
  }
526
528
  case 'json': {
527
- if (entry[element.uid] && element.field_metadata.rich_text_type) {
529
+ if (entry[element.uid] && ((_a = element === null || element === void 0 ? void 0 : element.field_metadata) === null || _a === void 0 ? void 0 : _a.rich_text_type)) {
528
530
  if (element.multiple && Array.isArray(entry[element.uid])) {
529
531
  entry[element.uid] = sourceStackEntry[element.uid].map((jsonRTE) => {
530
532
  jsonRTE = restoreReferenceInJsonRTE(jsonRTE, uidMapper);
@@ -548,7 +550,7 @@ const restoreJsonRteEntryRefs = (entry, sourceStackEntry, ctSchema = [], { uidMa
548
550
  break;
549
551
  }
550
552
  case 'text': {
551
- if (entry[element.uid] && element.field_metadata.rich_text_type) {
553
+ if (entry[element.uid] && ((_b = element === null || element === void 0 ? void 0 : element.field_metadata) === null || _b === void 0 ? void 0 : _b.rich_text_type)) {
552
554
  entry[element.uid] = sourceStackEntry[element.uid];
553
555
  const matches = Object.keys(uidMapper).filter((uid) => {
554
556
  if (sourceStackEntry[element.uid].indexOf(uid) !== -1)
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.15.6",
2
+ "version": "1.15.7",
3
3
  "commands": {
4
4
  "cm:stacks:import": {
5
5
  "id": "cm:stacks:import",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-import",
3
3
  "description": "Contentstack CLI plugin to import content into stack",
4
- "version": "1.15.6",
4
+ "version": "1.15.7",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
@@ -99,4 +99,4 @@
99
99
  }
100
100
  },
101
101
  "repository": "https://github.com/contentstack/cli"
102
- }
102
+ }