@contentstack/cli-cm-import 0.1.1-beta.17 → 0.1.1-beta.18

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
@@ -34,7 +34,7 @@ $ npm install -g @contentstack/cli-cm-import
34
34
  $ csdx COMMAND
35
35
  running command...
36
36
  $ csdx (-v|--version|version)
37
- @contentstack/cli-cm-import/0.1.1-beta.17 linux-x64 node-v16.14.2
37
+ @contentstack/cli-cm-import/0.1.1-beta.18 linux-x64 node-v16.14.2
38
38
  $ csdx --help [COMMAND]
39
39
  USAGE
40
40
  $ csdx COMMAND
@@ -80,5 +80,5 @@ EXAMPLES
80
80
  csdx cm:import -A -B <branch name>
81
81
  ```
82
82
 
83
- _See code: [src/commands/cm/import.js](https://github.com/contentstack/cli/blob/v0.1.1-beta.17/packages/contentstack-import/src/commands/cm/import.js)_
83
+ _See code: [src/commands/cm/import.js](https://github.com/contentstack/cli/blob/v0.1.1-beta.18/packages/contentstack-import/src/commands/cm/import.js)_
84
84
  <!-- commandsstop -->
@@ -1 +1 @@
1
- {"version":"0.1.1-beta.17","commands":{"cm:import":{"id":"cm:import","description":"Import script for importing the content into new stack\n...\nOnce you export content from the source stack, import it to your destination stack by using the cm:import command.\n","pluginName":"@contentstack/cli-cm-import","pluginType":"core","aliases":[],"examples":["csdx cm:import -A","csdx cm:import -A -s <stack_ApiKey> -d <path/of/export/destination/dir>","csdx cm:import -A -c <path/of/config/dir>","csdx cm:import -A -m <single module name>","csdx cm:import -A -m <single module name> -b <backup dir>","csdx cm:import -a <management_token_alias>","csdx cm:import -a <management_token_alias> -d <path/of/export/destination/dir>","csdx cm:import -a <management_token_alias> -c <path/of/config/file>","csdx cm:import -A -m <single module name>","csdx cm:import -A -B <branch name>"],"flags":{"config":{"name":"config","type":"option","char":"c","description":"[optional] path of config file"},"stack-uid":{"name":"stack-uid","type":"option","char":"s","description":"API key of the target stack"},"data":{"name":"data","type":"option","char":"d","description":"path and location where data is stored"},"management-token-alias":{"name":"management-token-alias","type":"option","char":"a","description":"alias of the management token"},"auth-token":{"name":"auth-token","type":"boolean","char":"A","description":"to use auth token","allowNo":false},"module":{"name":"module","type":"option","char":"m","description":"[optional] specific module name"},"backup-dir":{"name":"backup-dir","type":"option","char":"b","description":"[optional] backup directory name when using specific module"},"branch":{"name":"branch","type":"option","char":"B","description":"[optional] branch name"}},"args":[]}}}
1
+ {"version":"0.1.1-beta.18","commands":{"cm:import":{"id":"cm:import","description":"Import script for importing the content into new stack\n...\nOnce you export content from the source stack, import it to your destination stack by using the cm:import command.\n","pluginName":"@contentstack/cli-cm-import","pluginType":"core","aliases":[],"examples":["csdx cm:import -A","csdx cm:import -A -s <stack_ApiKey> -d <path/of/export/destination/dir>","csdx cm:import -A -c <path/of/config/dir>","csdx cm:import -A -m <single module name>","csdx cm:import -A -m <single module name> -b <backup dir>","csdx cm:import -a <management_token_alias>","csdx cm:import -a <management_token_alias> -d <path/of/export/destination/dir>","csdx cm:import -a <management_token_alias> -c <path/of/config/file>","csdx cm:import -A -m <single module name>","csdx cm:import -A -B <branch name>"],"flags":{"config":{"name":"config","type":"option","char":"c","description":"[optional] path of config file"},"stack-uid":{"name":"stack-uid","type":"option","char":"s","description":"API key of the target stack"},"data":{"name":"data","type":"option","char":"d","description":"path and location where data is stored"},"management-token-alias":{"name":"management-token-alias","type":"option","char":"a","description":"alias of the management token"},"auth-token":{"name":"auth-token","type":"boolean","char":"A","description":"to use auth token","allowNo":false},"module":{"name":"module","type":"option","char":"m","description":"[optional] specific module name"},"backup-dir":{"name":"backup-dir","type":"option","char":"b","description":"[optional] backup directory name when using specific module"},"branch":{"name":"branch","type":"option","char":"B","description":"[optional] branch name"}},"args":[]}}}
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": "0.1.1-beta.17",
4
+ "version": "0.1.1-beta.18",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
@@ -38,8 +38,8 @@ class ImportCommand extends Command {
38
38
  moduleName,
39
39
  host,
40
40
  _authToken,
41
- branchName,
42
- backupdir
41
+ backupdir,
42
+ branchName
43
43
  )
44
44
  .then(() => {
45
45
  return resolve()
@@ -51,8 +51,8 @@ class ImportCommand extends Command {
51
51
  moduleName,
52
52
  host,
53
53
  _authToken,
54
- branchName,
55
- backupdir
54
+ backupdir,
55
+ branchName
56
56
  )
57
57
  .then(() => {
58
58
  return resolve()
@@ -63,8 +63,8 @@ class ImportCommand extends Command {
63
63
  moduleName,
64
64
  host,
65
65
  _authToken,
66
- branchName,
67
- backupdir
66
+ backupdir,
67
+ branchName
68
68
  )
69
69
  .then(() => {
70
70
  return resolve()
@@ -80,8 +80,8 @@ class ImportCommand extends Command {
80
80
  _authToken,
81
81
  moduleName,
82
82
  host,
83
- branchName,
84
- backupdir
83
+ backupdir,
84
+ branchName
85
85
  )
86
86
  .then(() => {
87
87
  return resolve()
@@ -376,6 +376,7 @@ importAssets.prototype = {
376
376
  branch[parent_uid][coll[j].uid] = {}
377
377
  coll.splice(j, 1);
378
378
  self.findBranches(branch[parent_uid], coll)
379
+ --j
379
380
  }
380
381
  }
381
382
  }
@@ -9,7 +9,6 @@ const path = require('path')
9
9
  const _ = require('lodash')
10
10
  const mkdirp = require('mkdirp')
11
11
  const chalk = require('chalk')
12
- const crypto = require('crypto')
13
12
 
14
13
  const helper = require('../util/fs')
15
14
  const {addlogs} = require('../util/log')
@@ -117,7 +116,7 @@ importEntries.prototype = {
117
116
  }
118
117
  }
119
118
 
120
- // Step 1: Removes filed rules from content type
119
+ // Step 1: Removes field rules from content type
121
120
  // This allows to handle cases like self references and circular reference
122
121
  // if mandatory reference fields are not filed in entries then avoids the error
123
122
  // Also remove field visibility rules
@@ -210,15 +209,10 @@ importEntries.prototype = {
210
209
  if (eUid) {
211
210
 
212
211
  // check ctUid in self.ctJsonRte array, if ct exists there... only then remove entry references for json rte
213
- // also with json rte, api creates the json-rte field with the same uid as passed in the payload. So use the node's inbuilt
214
- // crypto module to generate a random uid and populate the json rte data
215
- // https://www.kindacode.com/article/how-to-easily-generate-a-random-string-in-node-js/
212
+ // also with json rte, api creates the json-rte field with the same uid as passed in the payload.
216
213
 
217
- // while creating entries with json-rte field, the api does not create fresh uids for the json-rte field
218
- // and its subsequent children. If the data is passed without a uid, then the fields aren't created. So, I'll
219
- // generate the uids for now, and will come up with a better solution later
220
214
  if (self.ctJsonRte.indexOf(ctUid) > -1) {
221
- entries[eUid] = self.generateUidsForJsonRteFields(entries[eUid], self.ctSchemas[ctUid].schema)
215
+ entries[eUid] = self.removeUidsFromJsonRteFields(entries[eUid], self.ctSchemas[ctUid].schema)
222
216
  }
223
217
 
224
218
  // remove entry references from json-rte fields
@@ -251,7 +245,7 @@ importEntries.prototype = {
251
245
  }) + ' as it is already created'), 'success')
252
246
  self.success[ctUid] = createdEntries[eUid]
253
247
  // if its a non-master language, i.e. the entry isn't present in the master language
254
- if (lang !== masterLanguage) {
248
+ if (lang !== masterLanguage.code) {
255
249
  self.uniqueUids[eUid] = self.uniqueUids[eUid] || {}
256
250
  if (self.uniqueUids[eUid].locales) {
257
251
  self.uniqueUids[eUid].locales.push(lang)
@@ -280,7 +274,7 @@ importEntries.prototype = {
280
274
  self.mappedUids[eUid] = entryResponse.uid
281
275
  createdEntries = entryResponse
282
276
  // if its a non-master language, i.e. the entry isn't present in the master language
283
- if (lang !== masterLanguage) {
277
+ if (lang !== masterLanguage.code) {
284
278
  self.uniqueUids[eUid] = self.uniqueUids[eUid] || {}
285
279
  if (self.uniqueUids[eUid].locales) {
286
280
  self.uniqueUids[eUid].locales.push(lang)
@@ -303,7 +297,7 @@ importEntries.prototype = {
303
297
  })
304
298
  }
305
299
  delete requestObject.json.entry.publish_details
306
- return client.stack({api_key: config.target_stack, management_token: config.management_token}).contentType(ctUid).entry().create(requestObject.json)
300
+ return client.stack({api_key: config.target_stack, management_token: config.management_token}).contentType(ctUid).entry().create(requestObject.json, {locale: lang})
307
301
  .then(async entryResponse => {
308
302
  self.success[ctUid] = self.success[ctUid] || []
309
303
  self.success[ctUid].push(entries[eUid])
@@ -311,7 +305,7 @@ importEntries.prototype = {
311
305
  self.mappedUids[eUid] = entryResponse.uid
312
306
  createdEntries = entryResponse
313
307
  // if its a non-master language, i.e. the entry isn't present in the master language
314
- if (lang !== masterLanguage) {
308
+ if (lang !== masterLanguage.code) {
315
309
  self.uniqueUids[eUid] = self.uniqueUids[eUid] || {}
316
310
  if (self.uniqueUids[eUid].locales) {
317
311
  self.uniqueUids[eUid].locales.push(lang)
@@ -445,7 +439,6 @@ importEntries.prototype = {
445
439
  // map failed reference uids @mapper/language/unmapped-uids.json
446
440
  let refUidMapperPath = path.join(entryMapperPath, lang)
447
441
 
448
- // add entry references to JSON RTE fields
449
442
  entries = _.map(entries, function (entry) {
450
443
  try {
451
444
  let uid = entry.uid
@@ -453,7 +446,8 @@ importEntries.prototype = {
453
446
 
454
447
  // restores json rte entry refs if they exist
455
448
  if (self.ctJsonRte.indexOf(ctUid) > -1) {
456
- updatedEntry = self.restoreJsonRteEntryRefs(entry, sourceStackEntries[self.mappedUids[entry.uid]], schema)
449
+ // the entries stored in eSuccessFilePath, have the same uids as the entries from source data
450
+ updatedEntry = self.restoreJsonRteEntryRefs(entry, sourceStackEntries[entry.uid], schema.schema)
457
451
  } else {
458
452
  updatedEntry = entry
459
453
  }
@@ -902,7 +896,7 @@ importEntries.prototype = {
902
896
  })
903
897
  })
904
898
  },
905
- removeEntryRefsFromJSONRTE(entry, ctSchema) {
899
+ removeEntryRefsFromJSONRTE: function(entry, ctSchema) {
906
900
  for (let i = 0; i < ctSchema.length; i++) {
907
901
  switch(ctSchema[i].data_type) {
908
902
  case 'blocks': {
@@ -958,15 +952,13 @@ importEntries.prototype = {
958
952
  }
959
953
  return entry
960
954
  },
961
- doEntryReferencesExist(element) {
955
+ doEntryReferencesExist: function(element) {
962
956
  // checks if the children of p element contain any references
963
957
  // only checking one level deep, not recursive
964
958
 
965
959
  if (element.length) {
966
960
  for(let i=0; i < element.length; i++) {
967
- // although most data has only one level of nesting, and this case might never come up
968
- // I've handled multiple level of nesting for 'p' elements
969
- if(element[i].type === 'p' && element[i].children && element[i].children.length > 0) {
961
+ if((element[i].type === 'p' || element[i].type === 'a') && element[i].children && element[i].children.length > 0) {
970
962
  return this.doEntryReferencesExist(element[i].children)
971
963
  } else if(this.isEntryRef(element[i])) {
972
964
  return true
@@ -977,13 +969,15 @@ importEntries.prototype = {
977
969
  return true
978
970
  }
979
971
 
980
- if (element.type === "p" && element.children && element.children.length > 0) {
972
+ if ((element.type === 'p' || element.type === 'a') && element.children && element.children.length > 0) {
981
973
  return this.doEntryReferencesExist(element.children)
982
974
  }
983
975
  }
984
976
  return false
985
977
  },
986
- restoreJsonRteEntryRefs(entry, sourceStackEntry, ctSchema) {
978
+ restoreJsonRteEntryRefs: function(entry, sourceStackEntry, ctSchema) {
979
+ let mappedAssetUids = helper.readFile(mappedAssetUidPath) || {}
980
+ let mappedAssetUrls = helper.readFile(mappedAssetUrlPath) || {}
987
981
  for (let i = 0; i < ctSchema.length; i++) {
988
982
  switch (ctSchema[i].data_type) {
989
983
  case 'blocks': {
@@ -1020,17 +1014,56 @@ importEntries.prototype = {
1020
1014
  if (entry[ctSchema[i].uid] && ctSchema[i].field_metadata.rich_text_type) {
1021
1015
  if (ctSchema[i].multiple) {
1022
1016
  entry[ctSchema[i].uid] = entry[ctSchema[i].uid].map((field, index) => {
1023
- field.children = [
1024
- ...field.children,
1025
- ...sourceStackEntry[ctSchema[i].uid][index].children.filter(e => this.doEntryReferencesExist(e))
1026
- ]
1017
+
1018
+ // i am facing a Maximum call stack exceeded issue,
1019
+ // probably because of this loop operation
1020
+
1021
+ let entryRefs = sourceStackEntry[ctSchema[i].uid][index].children
1022
+ .map((e, index) => {
1023
+ return { index: index, value: e }
1024
+ })
1025
+ .filter(e => this.doEntryReferencesExist(e.value))
1026
+ .map(e => {
1027
+ // commenting the line below resolved the maximum call stack exceeded issue
1028
+ // e.value = this.setDirtyTrue(e.value)
1029
+ this.setDirtyTrue(e.value)
1030
+ return e
1031
+ })
1032
+ .map(e => {
1033
+ // commenting the line below resolved the maximum call stack exceeded issue
1034
+ // e.value = this.resolveAssetRefsInEntryRefsForJsonRte(e, mappedAssetUids, mappedAssetUrls)
1035
+ this.resolveAssetRefsInEntryRefsForJsonRte(e.value, mappedAssetUids, mappedAssetUrls)
1036
+ return e
1037
+ })
1038
+
1039
+ if(entryRefs.length > 0) {
1040
+ entryRefs.forEach(element => {
1041
+ field.children.splice(element.index, 0, element.value)
1042
+ })
1043
+ }
1027
1044
  return field
1028
1045
  })
1029
1046
  } else {
1030
- entry[ctSchema[i].uid].children = [
1031
- ...entry[ctSchema[i].uid].children,
1032
- ...sourceStackEntry[ctSchema[i].uid].children.filter(e => this.doEntryReferencesExist(e)),
1033
- ]
1047
+
1048
+ let entryRefs = sourceStackEntry[ctSchema[i].uid].children
1049
+ .map((e, index) => {
1050
+ return { index: index, value: e }
1051
+ })
1052
+ .filter(e => this.doEntryReferencesExist(e.value))
1053
+ .map(e => {
1054
+ this.setDirtyTrue(e.value)
1055
+ return e
1056
+ })
1057
+ .map(e => {
1058
+ this.resolveAssetRefsInEntryRefsForJsonRte(e.value, mappedAssetUids, mappedAssetUrls)
1059
+ return e
1060
+ })
1061
+
1062
+ if(entryRefs.length > 0) {
1063
+ entryRefs.forEach(element => {
1064
+ entry[ctSchema[i].uid].children.splice(element.index, 0, element.value)
1065
+ })
1066
+ }
1034
1067
  }
1035
1068
  }
1036
1069
  break;
@@ -1038,25 +1071,11 @@ importEntries.prototype = {
1038
1071
  }
1039
1072
  }
1040
1073
  return entry
1041
- //------------------------------------------------------------------------------------------------------------
1042
- // if (Object.keys(self.jsonRteEntryRefs).indexOf(entry.uid) > -1) {
1043
- // Object.keys(self.jsonRteEntryRefs[entry.uid]).forEach(jsonRteFieldUid => {
1044
- // if (self.jsonRteEntryRefs[entry.uid][jsonRteFieldUid].length) { // handles when json_rte is multiple
1045
- // entry[jsonRteFieldUid] = entry[jsonRteFieldUid].map((field, index) => {
1046
- // field.children = [...field.children, ...self.jsonRteEntryRefs[entry.uid][jsonRteFieldUid][index]]
1047
- // return field
1048
- // })
1049
- // } else {
1050
- // entry[jsonRteFieldUid].children = [...entry[jsonRteFieldUid].children, ...self.jsonRteEntryRefs[entry.uid][jsonRteFieldUid].children]
1051
- // }
1052
- // })
1053
- // }
1054
- // return entry
1055
1074
  },
1056
- isEntryRef(element) {
1075
+ isEntryRef: function(element) {
1057
1076
  return element.type === "reference" && element.attrs.type === "entry"
1058
1077
  },
1059
- generateUidsForJsonRteFields(entry, ctSchema) {
1078
+ removeUidsFromJsonRteFields: function(entry, ctSchema) {
1060
1079
  for (let i = 0; i < ctSchema.length; i++) {
1061
1080
  switch (ctSchema[i].data_type) {
1062
1081
  case 'blocks': {
@@ -1065,7 +1084,7 @@ importEntries.prototype = {
1065
1084
  entry[ctSchema[i].uid] = entry[ctSchema[i].uid].map(e => {
1066
1085
  let key = Object.keys(e).pop()
1067
1086
  let subBlock = ctSchema[i].blocks.filter(e => e.uid === key).pop()
1068
- e[key] = this.generateUidsForJsonRteFields(e[key], subBlock.schema)
1087
+ e[key] = this.removeUidsFromJsonRteFields(e[key], subBlock.schema)
1069
1088
  return e
1070
1089
  })
1071
1090
  }
@@ -1077,11 +1096,11 @@ importEntries.prototype = {
1077
1096
  if (entry[ctSchema[i].uid]) {
1078
1097
  if (ctSchema[i].multiple) {
1079
1098
  entry[ctSchema[i].uid] = entry[ctSchema[i].uid].map(e => {
1080
- e = this.generateUidsForJsonRteFields(e, ctSchema[i].schema)
1099
+ e = this.removeUidsFromJsonRteFields(e, ctSchema[i].schema)
1081
1100
  return e
1082
1101
  })
1083
1102
  } else {
1084
- entry[ctSchema[i].uid] = this.generateUidsForJsonRteFields(entry[ctSchema[i].uid], ctSchema[i].schema)
1103
+ entry[ctSchema[i].uid] = this.removeUidsFromJsonRteFields(entry[ctSchema[i].uid], ctSchema[i].schema)
1085
1104
  }
1086
1105
  }
1087
1106
  break;
@@ -1090,13 +1109,15 @@ importEntries.prototype = {
1090
1109
  if (entry[ctSchema[i].uid] && ctSchema[i].field_metadata.rich_text_type) {
1091
1110
  if (ctSchema[i].multiple) {
1092
1111
  entry[ctSchema[i].uid] = entry[ctSchema[i].uid].map(jsonRteData => {
1093
- jsonRteData.uid = this.generateUid()
1094
- jsonRteData.children = jsonRteData.children.map(child => this.populateChildrenWithUids(child))
1112
+ delete jsonRteData.uid // remove uid
1113
+ jsonRteData.attrs.dirty = true
1114
+ jsonRteData.children = jsonRteData.children.map(child => this.removeUidsFromChildren(child))
1095
1115
  return jsonRteData
1096
1116
  })
1097
1117
  } else {
1098
- entry[ctSchema[i].uid].uid = this.generateUid()
1099
- entry[ctSchema[i].uid].children = entry[ctSchema[i].uid].children.map(child => this.populateChildrenWithUids(child))
1118
+ delete entry[ctSchema[i].uid].uid // remove uid
1119
+ entry[ctSchema[i].uid].attrs.dirty = true
1120
+ entry[ctSchema[i].uid].children = entry[ctSchema[i].uid].children.map(child => this.removeUidsFromChildren(child))
1100
1121
  }
1101
1122
  }
1102
1123
  break;
@@ -1105,29 +1126,70 @@ importEntries.prototype = {
1105
1126
  }
1106
1127
  return entry
1107
1128
  },
1108
- populateChildrenWithUids(children) {
1129
+ removeUidsFromChildren: function(children) {
1109
1130
  if (children.length && children.length > 0) {
1110
1131
  return children.map(child => {
1111
1132
  if(child.type && child.type.length > 0) {
1112
- child.uid = this.generateUid()
1133
+ delete child.uid // remove uid
1134
+ child.attrs.dirty = true
1113
1135
  }
1114
1136
  if(child.children && child.children.length > 0) {
1115
- child.children = this.populateChildrenWithUids(child.children)
1137
+ child.children = this.removeUidsFromChildren(child.children)
1116
1138
  }
1117
1139
  return child
1118
1140
  })
1119
1141
  } else {
1120
1142
  if (children.type && children.type.length > 0) {
1121
- children.uid = this.generateUid()
1143
+ delete children.uid // remove uid
1144
+ children.attrs.dirty = true
1122
1145
  }
1123
1146
  if (children.children && children.children.length > 0) {
1124
- children.children = this.populateChildrenWithUids(children.children)
1147
+ children.children = this.removeUidsFromChildren(children.children)
1125
1148
  }
1126
1149
  return children
1127
1150
  }
1128
1151
  },
1129
- generateUid() {
1130
- return crypto.randomBytes(16).toString('hex')
1152
+ setDirtyTrue: function(jsonRteChild) { // also removing uids in this function
1153
+ if (jsonRteChild.type) {
1154
+ jsonRteChild.attrs['dirty'] = true
1155
+ delete jsonRteChild.uid
1156
+
1157
+ if (jsonRteChild.children && jsonRteChild.children.length > 0) {
1158
+ jsonRteChild.children = jsonRteChild.children.map(subElement => this.setDirtyTrue(subElement))
1159
+ }
1160
+ }
1161
+ return jsonRteChild
1162
+ },
1163
+ resolveAssetRefsInEntryRefsForJsonRte: function(jsonRteChild, mappedAssetUids, mappedAssetUrls) {
1164
+
1165
+ if (jsonRteChild.type) {
1166
+ if (jsonRteChild.attrs.type === 'asset') {
1167
+ let assetUrl
1168
+ if(mappedAssetUids[jsonRteChild.attrs['asset-uid']]) {
1169
+ jsonRteChild.attrs['asset-uid'] = mappedAssetUids[jsonRteChild.attrs['asset-uid']]
1170
+ }
1171
+
1172
+ if (jsonRteChild.attrs['display-type'] !== 'link') {
1173
+ assetUrl = jsonRteChild.attrs['asset-link']
1174
+ } else {
1175
+ assetUrl = jsonRteChild.attrs['href']
1176
+ }
1177
+
1178
+ if(mappedAssetUrls[assetUrl]) {
1179
+ if (jsonRteChild.attrs['display-type'] !== 'link') {
1180
+ jsonRteChild.attrs['asset-link'] = mappedAssetUrls[assetUrl]
1181
+ } else {
1182
+ jsonRteChild.attrs['href'] = mappedAssetUrls[assetUrl]
1183
+ }
1184
+ }
1185
+ }
1186
+
1187
+ if (jsonRteChild.children && jsonRteChild.children.length > 0) {
1188
+ jsonRteChild.children = jsonRteChild.children.map(subElement => this.resolveAssetRefsInEntryRefsForJsonRte(subElement, mappedAssetUids, mappedAssetUrls))
1189
+ }
1190
+ }
1191
+
1192
+ return jsonRteChild
1131
1193
  }
1132
1194
  }
1133
1195
 
@@ -54,9 +54,7 @@ module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMappe
54
54
  if (schema[i].data_type === "json" && schema[i].field_metadata.rich_text_type) {
55
55
  parent.push(schema[i].uid)
56
56
  // findFileUrls(schema[i], entry, assetUrls)
57
- if (assetUids.length === 0) {
58
- findAssetIdsFromJsonRte(data.entry, data.content_type.schema)
59
- }
57
+ findAssetIdsFromJsonRte(data.entry, data.content_type.schema)
60
58
  // maybe only one of these checks would be enough
61
59
  parent.pop()
62
60
  }
@@ -106,11 +104,12 @@ module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMappe
106
104
  }
107
105
  }
108
106
  }
109
-
107
+
110
108
  function gatherJsonRteAssetIds(jsonRteData) {
111
109
  jsonRteData.children.forEach(element => {
112
110
  if (element.type) {
113
111
  switch (element.type) {
112
+ case 'a':
114
113
  case 'p': {
115
114
  if (element.children && element.children.length > 0) {
116
115
  gatherJsonRteAssetIds(element)
@@ -119,8 +118,25 @@ module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMappe
119
118
  }
120
119
  case 'reference': {
121
120
  if (Object.keys(element.attrs).length > 0 && element.attrs.type === "asset") {
122
- assetUids.push(element.attrs['asset-uid'])
123
- assetUrls.push(element.attrs['asset-link'])
121
+ if (assetUids.indexOf(element.attrs['asset-uid']) === -1) {
122
+ assetUids.push(element.attrs['asset-uid'])
123
+ }
124
+ // assets references inserted as link inside entry reference inserted as link did not have asset-link property
125
+ // instead it had an 'href' property. I haven't seen 'asset-link' and 'href' together yet
126
+ // writing this condition assuming that this never occurs, need to confirm
127
+ // (element.attrs['asset-link']) ? assetUrls.push(element.attrs['asset-link']) : assetUrls.push(element.attrs['asset-link'])
128
+ if (element.attrs['asset-link']) {
129
+ if (assetUrls.indexOf(element.attrs['asset-link']) === -1) {
130
+ assetUrls.push(element.attrs['asset-link'])
131
+ }
132
+ } else if (element.attrs['href']) {
133
+ if (assetUrls.indexOf(element.attrs['href']) === -1) {
134
+ assetUrls.push(element.attrs['href'])
135
+ }
136
+ }
137
+ }
138
+ if (element.children && element.children.length > 0) {
139
+ gatherJsonRteAssetIds(element)
124
140
  }
125
141
  break;
126
142
  }
@@ -25,6 +25,7 @@ module.exports = function (data, mappedUids, uidMapperPath) {
25
25
  jsonRteData.children.forEach(element => {
26
26
  if (element.type) {
27
27
  switch (element.type) {
28
+ case 'a':
28
29
  case 'p': {
29
30
  if (element.children && element.children.length > 0) {
30
31
  gatherJsonRteEntryIds(element)
@@ -33,7 +34,12 @@ module.exports = function (data, mappedUids, uidMapperPath) {
33
34
  }
34
35
  case 'reference': {
35
36
  if (Object.keys(element.attrs).length > 0 && element.attrs.type === "entry") {
36
- uids.push(element.attrs['entry-uid'])
37
+ if (uids.indexOf(element.attrs['entry-uid']) === -1) {
38
+ uids.push(element.attrs['entry-uid'])
39
+ }
40
+ }
41
+ if (element.children && element.children.length > 0) {
42
+ gatherJsonRteEntryIds(element)
37
43
  }
38
44
  break;
39
45
  }
@@ -104,6 +110,7 @@ module.exports = function (data, mappedUids, uidMapperPath) {
104
110
  parent.pop()
105
111
  }
106
112
  break
113
+ case 'global_field':
107
114
  case 'group':
108
115
  parent.push(schema[i].uid)
109
116
  find(schema[i].schema, entry)
@@ -120,9 +127,7 @@ module.exports = function (data, mappedUids, uidMapperPath) {
120
127
  break
121
128
  case 'json':
122
129
  if (schema[i].field_metadata.rich_text_type) {
123
- if (uids.length === 0) {
124
- findEntryIdsFromJsonRte(data.entry, data.content_type.schema)
125
- }
130
+ findEntryIdsFromJsonRte(data.entry, data.content_type.schema)
126
131
  }
127
132
  break
128
133
  }
@@ -6,7 +6,7 @@
6
6
 
7
7
  var supress = module.exports = function (schema, flag) {
8
8
  for (var i in schema) {
9
- if (schema[i].data_type === 'group') {
9
+ if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') {
10
10
  supress(schema[i].schema, flag);
11
11
  } else if (schema[i].data_type === 'blocks') {
12
12
  for (var block in schema[i].blocks) {