@contentstack/cli-cm-import 0.1.1-beta.9 → 1.0.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.
@@ -9,54 +9,91 @@ var path = require('path');
9
9
  var mkdirp = require('mkdirp');
10
10
  var slice = Array.prototype.slice;
11
11
 
12
- function returnString (args) {
12
+
13
+
14
+ const ansiRegexPattern = [
15
+ '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
16
+ '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'
17
+ ].join('|');
18
+
19
+ function returnString(args) {
13
20
  var returnStr = '';
14
21
  if (args && args.length) {
15
- returnStr = args.map(function (item) {
16
- if (item && typeof (item) === 'object') {
17
- return JSON.stringify(item);
18
- }
19
- return item;
20
- }).join(' ').trim();
22
+ returnStr = args
23
+ .map(function (item) {
24
+ if (item && typeof item === 'object') {
25
+ return JSON.stringify(item).replace(/authtoken\":\"blt................/g, 'authtoken":"blt....');
26
+ }
27
+ return item;
28
+ })
29
+ .join(' ')
30
+ .trim();
21
31
  }
32
+ returnStr = returnStr.replace(new RegExp(ansiRegexPattern, 'g'), "").trim();
22
33
  return returnStr;
23
34
  }
24
35
 
25
36
  var myCustomLevels = {
26
37
  levels: {
27
- error: 0,
28
38
  warn: 1,
29
39
  info: 2,
30
- debug: 3
40
+ debug: 3,
31
41
  },
32
42
  colors: {
33
43
  info: 'blue',
34
44
  debug: 'green',
35
45
  warn: 'yellow',
36
- error: 'red'
37
- }
46
+ error: 'red',
47
+ },
38
48
  };
39
49
 
40
- function init (_logPath, logfileName) {
41
- var logsDir = path.resolve(_logPath, 'logs', 'import')
42
- // Create dir if doesn't already exist
43
- mkdirp.sync(logsDir)
44
- var logPath = path.join(logsDir, logfileName + '.log');
50
+ let logger;
51
+ let errorLogger;
52
+
53
+ let successTransport;
54
+ let errorTransport;
45
55
 
46
- var transports = [new(winston.transports.File)({
47
- filename: logPath,
48
- maxFiles: 20,
49
- maxsize: 1000000,
50
- tailable: true,
51
- json: true
52
- })];
56
+ // removed logfileName from arguments
57
+ function init(_logPath) {
58
+ if (!logger || !errorLogger) {
59
+ var logsDir = path.resolve(_logPath, 'logs', 'import');
60
+ // Create dir if doesn't already exist
61
+ mkdirp.sync(logsDir);
53
62
 
54
- transports.push(new(winston.transports.Console)());
63
+ successTransport = {
64
+ filename: path.join(logsDir, 'success.log'),
65
+ maxFiles: 20,
66
+ maxsize: 1000000,
67
+ tailable: true,
68
+ json: true,
69
+ level: 'info',
70
+ };
55
71
 
56
- var logger = new(winston.Logger)({
57
- transports: transports,
58
- levels: myCustomLevels.levels
59
- });
72
+ errorTransport = {
73
+ filename: path.join(logsDir, 'error.log'),
74
+ maxFiles: 20,
75
+ maxsize: 1000000,
76
+ tailable: true,
77
+ json: true,
78
+ level: 'error',
79
+ };
80
+
81
+ logger = winston.createLogger({
82
+ transports: [
83
+ new winston.transports.File(successTransport),
84
+ new winston.transports.Console({ format: winston.format.simple() }),
85
+ ],
86
+ levels: myCustomLevels.levels,
87
+ });
88
+
89
+ errorLogger = winston.createLogger({
90
+ transports: [
91
+ new winston.transports.File(errorTransport),
92
+ new winston.transports.Console({ level: 'error', format: winston.format.simple() }),
93
+ ],
94
+ levels: { error: 0 },
95
+ });
96
+ }
60
97
 
61
98
  return {
62
99
  log: function () {
@@ -77,7 +114,7 @@ function init (_logPath, logfileName) {
77
114
  var args = slice.call(arguments);
78
115
  var logString = returnString(args);
79
116
  if (logString) {
80
- logger.log('error', logString);
117
+ errorLogger.log('error', logString);
81
118
  }
82
119
  },
83
120
  debug: function () {
@@ -86,16 +123,17 @@ function init (_logPath, logfileName) {
86
123
  if (logString) {
87
124
  logger.log('debug', logString);
88
125
  }
89
- }
126
+ },
90
127
  };
91
128
  }
92
129
 
93
130
  exports.addlogs = async (config, message, type) => {
94
- var configLogPath
95
- config.source_stack && config.target_stack ? configLogPath = config.data : configLogPath = config.oldPath
131
+ var configLogPath = config.source_stack && config.target_stack ? config.data : config.oldPath;
132
+ // ignoring the type argument, as we are not using it to create a logfile anymore
96
133
  if (type !== 'error') {
97
- init(configLogPath, type).log(message)
134
+ // removed type argument from init method
135
+ init(configLogPath).log(message);
98
136
  } else {
99
- init(configLogPath, type).error(message)
137
+ init(configLogPath).error(message);
100
138
  }
101
- }
139
+ };
@@ -7,48 +7,49 @@
7
7
 
8
8
  const chalk = require('chalk');
9
9
 
10
- const {addlogs} = require('../util/log')
11
- // var pkg = require('../../package');
12
- let stack = require('../util/contentstack-management-sdk')
13
- let client
14
-
10
+ const { addlogs } = require('../util/log');
11
+ let stack = require('../util/contentstack-management-sdk');
12
+ let client;
15
13
 
16
14
  module.exports = function (config) {
17
- client = stack.Client(config)
18
-
15
+ client = stack.Client(config);
16
+
19
17
  return new Promise(function (resolve, reject) {
20
18
  // eslint-disable-next-line no-console
21
19
  if (config.email && config.password) {
22
- console.log('Logging into Contentstack')
23
- return client.login({ email: config.email, password: config.password})
24
- .then(function (response) {
25
- // eslint-disable-next-line no-console
26
- console.log(chalk.green('Contentstack account authenticated successfully!'));
27
- config.authtoken = response.user.authtoken
28
- config.headers = {
29
- api_key: config.target_stack,
30
- authtoken: config.authtoken,
31
- 'X-User-Agent': 'contentstack-import/v'
32
- };
33
- return resolve(config);
34
- }).catch(reject);
20
+ console.log('Logging into Contentstack');
21
+ return client
22
+ .login({ email: config.email, password: config.password })
23
+ .then(function (response) {
24
+ // eslint-disable-next-line no-console
25
+ console.log(chalk.green('Contentstack account authenticated successfully!'));
26
+ config.authtoken = response.user.authtoken;
27
+ config.headers = {
28
+ api_key: config.target_stack,
29
+ authtoken: config.authtoken,
30
+ 'X-User-Agent': 'contentstack-import/v',
31
+ };
32
+ return resolve(config);
33
+ })
34
+ .catch(reject);
35
35
  } else if (config.management_token) {
36
- return resolve()
37
- } else if (config.auth_token) {
38
- // return resolve()
39
- client.stack({api_key: config.target_stack, management_token: config.management_token}).fetch()
40
- .then(function () {
41
- return resolve()
42
- })
43
- .catch(error => {
44
- let errorstack_key = error.errors.api_key
45
- if(error.errors.api_key) {
46
- addlogs(config, chalk.red("Stack Api key " + errorstack_key[0], "Please enter valid Key"), 'error')
47
- return reject()
48
- }
49
- addlogs(config, error.errorMessage, 'error')
50
- return reject()
51
- })
36
+ return resolve();
37
+ } else if (config.auth_token) {
38
+ client
39
+ .stack({ api_key: config.target_stack, management_token: config.management_token })
40
+ .fetch()
41
+ .then(function () {
42
+ return resolve();
43
+ })
44
+ .catch((error) => {
45
+ let errorstack_key = error.errors.api_key;
46
+ if (error.errors.api_key) {
47
+ addlogs(config, chalk.red('Stack Api key ' + errorstack_key[0], 'Please enter valid Key'), 'error');
48
+ return reject(error);
49
+ }
50
+ addlogs(config, error.errorMessage, 'error');
51
+ return reject(error);
52
+ });
52
53
  }
53
54
  });
54
55
  };
@@ -4,62 +4,173 @@
4
4
  * MIT Licensed
5
5
  */
6
6
 
7
- var url = require('url');
8
- var path = require('path');
9
- var _ = require('lodash');
10
- var marked = require('marked');
7
+ let url = require('url');
8
+ let path = require('path');
9
+ let _ = require('lodash');
10
+ let { marked } = require('marked');
11
11
 
12
- var helper = require('./fs');
12
+ let helper = require('./fs');
13
13
 
14
14
  // get assets object
15
15
  module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMapperPath) {
16
- if (!_.has(data, 'entry') || !_.has(data, 'content_type') || !_.isPlainObject(mappedAssetUids) || !_.isPlainObject(
17
- mappedAssetUrls) || typeof assetUidMapperPath !== 'string') {
16
+ if (
17
+ !_.has(data, 'entry') ||
18
+ !_.has(data, 'content_type') ||
19
+ !_.isPlainObject(mappedAssetUids) ||
20
+ !_.isPlainObject(mappedAssetUrls) ||
21
+ typeof assetUidMapperPath !== 'string'
22
+ ) {
18
23
  throw new Error('Invalid inputs for lookupAssets!');
19
24
  }
20
- var parent = [];
21
- var assetUids = [];
22
- var assetUrls = [];
23
- var unmatchedUids = [];
24
- var unmatchedUrls = [];
25
- var matchedUids = [];
26
- var matchedUrls = [];
27
-
28
- var find = function (schema, entry) {
29
- for (var i = 0, _i = schema.length; i < _i; i++) {
30
- if ((schema[i].data_type === 'text' && schema[i].field_metadata && (schema[i].field_metadata.markdown ||
31
- schema[i].field_metadata.rich_text_type))) {
25
+ let parent = [];
26
+ let assetUids = [];
27
+ let assetUrls = [];
28
+ let unmatchedUids = [];
29
+ let unmatchedUrls = [];
30
+ let matchedUids = [];
31
+ let matchedUrls = [];
32
+
33
+ let find = function (schema, entryToFind) {
34
+ for (let i = 0, _i = schema.length; i < _i; i++) {
35
+ if (
36
+ schema[i].data_type === 'text' &&
37
+ schema[i].field_metadata &&
38
+ (schema[i].field_metadata.markdown || schema[i].field_metadata.rich_text_type)
39
+ ) {
32
40
  parent.push(schema[i].uid);
33
- findFileUrls(parent, schema[i], entry, assetUrls);
41
+ findFileUrls(schema[i], entryToFind, assetUrls);
34
42
  parent.pop();
35
43
  }
36
44
  if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') {
37
45
  parent.push(schema[i].uid);
38
- find(schema[i].schema, entry);
46
+ find(schema[i].schema, entryToFind);
39
47
  parent.pop();
40
48
  }
41
49
  if (schema[i].data_type === 'blocks') {
42
- for (var j = 0, _j = schema[i].blocks.length; j < _j; j++) {
43
- if(schema[i].blocks[j].schema) {
50
+ for (let j = 0, _j = schema[i].blocks.length; j < _j; j++) {
51
+ if (schema[i].blocks[j].schema) {
44
52
  parent.push(schema[i].uid);
45
53
  parent.push(schema[i].blocks[j].uid);
46
- find(schema[i].blocks[j].schema, entry);
54
+ find(schema[i].blocks[j].schema, entryToFind);
47
55
  parent.pop();
48
56
  parent.pop();
49
57
  }
50
58
  }
51
59
  }
60
+ // added rich_text_type field check because some marketplace extensions also
61
+ // have data_type has json
62
+ if (schema[i].data_type === 'json' && schema[i].field_metadata.rich_text_type) {
63
+ parent.push(schema[i].uid);
64
+ // findFileUrls(schema[i], entry, assetUrls)
65
+ findAssetIdsFromJsonRte(data.entry, data.content_type.schema);
66
+ // maybe only one of these checks would be enough
67
+ parent.pop();
68
+ }
52
69
  }
53
70
  };
54
-
55
-
71
+
72
+ function findAssetIdsFromJsonRte(entryObj, ctSchema) {
73
+ for (const element of ctSchema) {
74
+ switch (element.data_type) {
75
+ case 'blocks': {
76
+ if (entryObj[element.uid]) {
77
+ if (element.multiple) {
78
+ entryObj[element.uid].forEach((e) => {
79
+ let key = Object.keys(e).pop();
80
+ let subBlock = element.blocks.filter((block) => block.uid === key).pop();
81
+ findAssetIdsFromJsonRte(e[key], subBlock.schema);
82
+ });
83
+ }
84
+ }
85
+ break;
86
+ }
87
+ case 'global_field':
88
+ case 'group': {
89
+ if (entryObj[element.uid]) {
90
+ if (element.multiple) {
91
+ entryObj[element.uid].forEach((e) => {
92
+ findAssetIdsFromJsonRte(e, element.schema);
93
+ });
94
+ } else {
95
+ findAssetIdsFromJsonRte(entryObj[element.uid], element.schema);
96
+ }
97
+ }
98
+ break;
99
+ }
100
+ case 'json': {
101
+ if (entryObj[element.uid] && element.field_metadata.rich_text_type) {
102
+ if (element.multiple) {
103
+ entryObj[element.uid].forEach((jsonRteData) => {
104
+ gatherJsonRteAssetIds(jsonRteData);
105
+ });
106
+ } else {
107
+ gatherJsonRteAssetIds(entryObj[element.uid]);
108
+ }
109
+ }
110
+ break;
111
+ }
112
+ }
113
+ }
114
+ }
115
+
116
+ function gatherJsonRteAssetIds(jsonRteData) {
117
+ jsonRteData.children.forEach((element) => {
118
+ if (element.type) {
119
+ switch (element.type) {
120
+ case 'a':
121
+ case 'p': {
122
+ if (element.children && element.children.length > 0) {
123
+ gatherJsonRteAssetIds(element);
124
+ }
125
+ break;
126
+ }
127
+ case 'reference': {
128
+ if (Object.keys(element.attrs).length > 0 && element.attrs.type === 'asset') {
129
+ if (assetUids.indexOf(element.attrs['asset-uid']) === -1) {
130
+ assetUids.push(element.attrs['asset-uid']);
131
+ }
132
+ // assets references inserted as link inside entry reference inserted as link did not have asset-link property
133
+ // instead it had an 'href' property. I haven't seen 'asset-link' and 'href' together yet
134
+ // writing this condition assuming that this never occurs, need to confirm
135
+ // (element.attrs['asset-link']) ? assetUrls.push(element.attrs['asset-link']) : assetUrls.push(element.attrs['asset-link'])
136
+ if (element.attrs['asset-link']) {
137
+ if (assetUrls.indexOf(element.attrs['asset-link']) === -1) {
138
+ assetUrls.push(element.attrs['asset-link']);
139
+ }
140
+ } else if (element.attrs['href']) {
141
+ if (assetUrls.indexOf(element.attrs['href']) === -1) {
142
+ assetUrls.push(element.attrs['href']);
143
+ }
144
+ }
145
+ }
146
+ if (element.children && element.children.length > 0) {
147
+ gatherJsonRteAssetIds(element);
148
+ }
149
+ break;
150
+ }
151
+ }
152
+ }
153
+ });
154
+ }
155
+
56
156
  find(data.content_type.schema, data.entry);
57
157
  updateFileFields(data.entry, data, null, mappedAssetUids, matchedUids, unmatchedUids);
58
158
  assetUids = _.uniq(assetUids);
59
159
  assetUrls = _.uniq(assetUrls);
60
- var entry = JSON.stringify(data.entry);
160
+ let entry = JSON.stringify(data.entry);
161
+
162
+ assetUrls.forEach(function (assetUrl) {
163
+ let mappedAssetUrl = mappedAssetUrls[assetUrl];
164
+ if (typeof mappedAssetUrl !== 'undefined') {
165
+ entry = entry.replace(new RegExp(assetUrl, 'img'), mappedAssetUrl);
166
+ matchedUrls.push(mappedAssetUrl);
167
+ } else {
168
+ unmatchedUrls.push(assetUrl);
169
+ }
170
+ });
171
+
61
172
  assetUids.forEach(function (assetUid) {
62
- var uid = mappedAssetUids[assetUid];
173
+ let uid = mappedAssetUids[assetUid];
63
174
  if (typeof uid !== 'undefined') {
64
175
  entry = entry.replace(new RegExp(assetUid, 'img'), uid);
65
176
  matchedUids.push(assetUid);
@@ -68,63 +179,53 @@ module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMappe
68
179
  }
69
180
  });
70
181
 
71
- assetUrls.forEach(function (assetUrl) {
72
- var url = mappedAssetUrls[assetUrl];
73
- if (typeof url !== 'undefined') {
74
- entry = entry.replace(new RegExp(assetUrl, 'img'), url);
75
- unmatchedUrls.push(url);
76
- } else {
77
- unmatchedUrls.push(assetUrl);
78
- }
79
- });
80
-
81
182
  if (matchedUids.length) {
82
- var matchedAssetUids = helper.readFile(path.join(assetUidMapperPath, 'matched-asset-uids.json'));
183
+ let matchedAssetUids = helper.readFile(path.join(assetUidMapperPath, 'matched-asset-uids.json'));
83
184
  matchedAssetUids = matchedAssetUids || {};
84
185
  if (matchedAssetUids.hasOwnProperty(data.content_type.uid)) {
85
186
  matchedAssetUids[data.content_type.uid][data.entry.uid] = matchedUids;
86
187
  } else {
87
188
  matchedAssetUids[data.content_type.uid] = {
88
- [data.entry.uid]: matchedUids
189
+ [data.entry.uid]: matchedUids,
89
190
  };
90
191
  }
91
192
  helper.writeFile(path.join(assetUidMapperPath, 'matched-asset-uids.json'));
92
193
  }
93
194
 
94
195
  if (unmatchedUids.length) {
95
- var unmatchedAssetUids = helper.readFile(path.join(assetUidMapperPath, 'unmatched-asset-uids.json'));
196
+ let unmatchedAssetUids = helper.readFile(path.join(assetUidMapperPath, 'unmatched-asset-uids.json'));
96
197
  unmatchedAssetUids = unmatchedAssetUids || {};
97
198
  if (unmatchedAssetUids.hasOwnProperty(data.content_type.uid)) {
98
199
  unmatchedAssetUids[data.content_type.uid][data.entry.uid] = unmatchedUids;
99
200
  } else {
100
201
  unmatchedAssetUids[data.content_type.uid] = {
101
- [data.entry.uid]: unmatchedUids
202
+ [data.entry.uid]: unmatchedUids,
102
203
  };
103
204
  }
104
205
  helper.writeFile(path.join(assetUidMapperPath, 'unmatched-asset-uids.json'));
105
206
  }
106
207
 
107
208
  if (unmatchedUrls.length) {
108
- var unmatchedAssetUrls = helper.readFile(path.join(assetUidMapperPath, 'unmatched-asset-urls.json'));
209
+ let unmatchedAssetUrls = helper.readFile(path.join(assetUidMapperPath, 'unmatched-asset-urls.json'));
109
210
  unmatchedAssetUrls = unmatchedAssetUrls || {};
110
211
  if (unmatchedAssetUrls.hasOwnProperty(data.content_type.uid)) {
111
212
  unmatchedAssetUrls[data.content_type.uid][data.entry.uid] = unmatchedUrls;
112
213
  } else {
113
214
  unmatchedAssetUrls[data.content_type.uid] = {
114
- [data.entry.uid]: unmatchedUrls
215
+ [data.entry.uid]: unmatchedUrls,
115
216
  };
116
217
  }
117
218
  helper.writeFile(path.join(assetUidMapperPath, 'unmatched-asset-urls.json'));
118
219
  }
119
220
 
120
221
  if (matchedUrls.length) {
121
- var matchedAssetUrls = helper.readFile(path.join(assetUidMapperPath, 'matched-asset-urls.json'));
222
+ let matchedAssetUrls = helper.readFile(path.join(assetUidMapperPath, 'matched-asset-urls.json'));
122
223
  matchedAssetUrls = matchedAssetUrls || {};
123
224
  if (matchedAssetUrls.hasOwnProperty(data.content_type.uid)) {
124
225
  matchedAssetUrls[data.content_type.uid][data.entry.uid] = matchedUrls;
125
226
  } else {
126
227
  matchedAssetUrls[data.content_type.uid] = {
127
- [data.entry.uid]: matchedUrls
228
+ [data.entry.uid]: matchedUrls,
128
229
  };
129
230
  }
130
231
  helper.writeFile(path.join(assetUidMapperPath, 'matched-asset-urls.json'));
@@ -133,20 +234,23 @@ module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMappe
133
234
  return JSON.parse(entry);
134
235
  };
135
236
 
136
- function findFileUrls (schema, _entry, assetUrls) {
137
- var markdownRegEx;
138
- var markdownMatch;
237
+ function findFileUrls(schema, _entry, assetUrls) {
238
+ let markdownRegEx;
239
+ let markdownMatch;
139
240
 
140
241
  // Regex to detect v2 asset uri patterns
141
- var _matches, regex;
242
+ let _matches, regex;
142
243
  if (schema && schema.field_metadata && schema.field_metadata.markdown) {
143
244
  regex = new RegExp(
144
245
  // eslint-disable-next-line no-control-regex
145
- 'https://(contentstack-|)api.(built|contentstack).io/(.*?)/download(.*?)uid=([a-z0-9]+[^\?&\s\n])((.*)[\n\s]?)',
146
- 'g');
246
+ 'https://(contentstack-|)api.(built|contentstack).io/(.*?)/download(.*?)uid=([a-z0-9]+[^?&s\n])((.*)[\ns]?)',
247
+ 'g',
248
+ );
147
249
  } else {
148
250
  regex = new RegExp(
149
- 'https://(contentstack-|)api.(built|contentstack).io/(.*?)/download(.*?)uid=([a-z0-9]+[^\?&\'"])(.*?)', 'g');
251
+ 'https://(contentstack-|)api.(built|contentstack).io/(.*?)/download(.*?)uid=([a-z0-9]+[^?&\'"])(.*?)',
252
+ 'g',
253
+ );
150
254
  }
151
255
  while ((_matches = regex.exec(_entry)) !== null) {
152
256
  if (_matches && _matches.length) {
@@ -155,14 +259,17 @@ function findFileUrls (schema, _entry, assetUrls) {
155
259
  }
156
260
  }
157
261
  }
158
- var text;
262
+ let text;
159
263
  // Regex to detect v3 asset uri patterns
160
264
  if (schema && schema.field_metadata && schema.field_metadata.markdown) {
161
- text = marked(_entry);
265
+ text = marked(JSON.stringify(_entry));
162
266
  } else {
163
- text = _entry;
267
+ text = JSON.stringify(_entry);
164
268
  }
165
- markdownRegEx = new RegExp('(https://(assets|images).contentstack.io/v3/assets/(.*?)/(.*?)/(.*?)/(.*)(?="))', 'g');
269
+ markdownRegEx = new RegExp(
270
+ '(https://(assets|(eu-|azure-na-)?images).contentstack.(io|com)/v3/assets/(.*?)/(.*?)/(.*?)/(.*?)(?="))',
271
+ 'g',
272
+ );
166
273
  while ((markdownMatch = markdownRegEx.exec(text)) !== null) {
167
274
  if (markdownMatch && typeof markdownMatch[0] === 'string') {
168
275
  assetUrls.push(markdownMatch[0]);
@@ -170,7 +277,7 @@ function findFileUrls (schema, _entry, assetUrls) {
170
277
  }
171
278
  }
172
279
 
173
- function updateFileFields (objekt, parent, pos, mappedAssetUids, matchedUids, unmatchedUids) {
280
+ function updateFileFields(objekt, parent, pos, mappedAssetUids, matchedUids, unmatchedUids) {
174
281
  if (_.isPlainObject(objekt) && _.has(objekt, 'filename') && _.has(objekt, 'uid')) {
175
282
  if (typeof pos !== 'undefined') {
176
283
  if (typeof pos === 'number' || typeof pos === 'string') {
@@ -184,10 +291,9 @@ function updateFileFields (objekt, parent, pos, mappedAssetUids, matchedUids, un
184
291
  }
185
292
  }
186
293
  } else if (_.isPlainObject(objekt)) {
187
- for (var key in objekt)
188
- updateFileFields(objekt[key], objekt, key, mappedAssetUids, matchedUids, unmatchedUids);
294
+ for (let key in objekt) updateFileFields(objekt[key], objekt, key, mappedAssetUids, matchedUids, unmatchedUids);
189
295
  } else if (_.isArray(objekt) && objekt.length) {
190
- for (var i = 0; i <= objekt.length; i++)
296
+ for (let i = 0; i <= objekt.length; i++)
191
297
  updateFileFields(objekt[i], objekt, i, mappedAssetUids, matchedUids, unmatchedUids);
192
298
 
193
299
  parent[pos] = _.compact(objekt);