@contentstack/cli-cm-import 1.12.0 → 1.12.2
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 +3 -1
- package/lib/commands/cm/stacks/import.js +3 -2
- package/lib/import/modules/entries.d.ts +1 -1
- package/lib/import/modules/entries.js +10 -6
- package/lib/import/modules/index.js +24 -11
- package/lib/import/modules/marketplace-apps.d.ts +93 -21
- package/lib/import/modules/marketplace-apps.js +204 -120
- package/lib/import/modules/workflows.js +1 -0
- package/lib/import/modules-js/marketplace-apps.js +3 -2
- package/lib/import/modules-js/workflows.js +1 -0
- package/lib/types/entries.d.ts +11 -0
- package/lib/types/entries.js +2 -0
- package/lib/types/import-config.d.ts +1 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.js +3 -0
- package/lib/types/marketplace-app.d.ts +54 -0
- package/lib/types/marketplace-app.js +2 -0
- package/lib/utils/asset-helper.js +4 -2
- package/lib/utils/entries-helper.d.ts +1 -1
- package/lib/utils/entries-helper.js +126 -74
- package/lib/utils/import-config-handler.js +1 -0
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +1 -4
- package/lib/utils/marketplace-app-helper.d.ts +2 -9
- package/lib/utils/marketplace-app-helper.js +25 -48
- package/oclif.manifest.json +7 -1
- package/package.json +4 -4
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Entries lookup
|
|
4
4
|
*/
|
|
5
|
+
// FIXME refactor the complete file/code after discussed with the team
|
|
5
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
7
|
exports.restoreJsonRteEntryRefs = exports.removeEntryRefsFromJSONRTE = exports.removeUidsFromJsonRteFields = exports.lookupEntries = void 0;
|
|
7
8
|
const tslib_1 = require("tslib");
|
|
@@ -18,7 +19,9 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
|
|
|
18
19
|
let isNewRefFields = false;
|
|
19
20
|
let preserveStackVersion = config_1.default.preserveStackVersion;
|
|
20
21
|
function gatherJsonRteEntryIds(jsonRteData) {
|
|
21
|
-
|
|
22
|
+
var _a;
|
|
23
|
+
(_a = jsonRteData.children) === null || _a === void 0 ? void 0 : _a.forEach((element) => {
|
|
24
|
+
var _a, _b;
|
|
22
25
|
if (element.type) {
|
|
23
26
|
switch (element.type) {
|
|
24
27
|
default: {
|
|
@@ -28,7 +31,7 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
|
|
|
28
31
|
break;
|
|
29
32
|
}
|
|
30
33
|
case 'reference': {
|
|
31
|
-
if (Object.keys(element.attrs).length > 0 && element.attrs.type === 'entry') {
|
|
34
|
+
if (((_a = Object.keys(element.attrs)) === null || _a === void 0 ? void 0 : _a.length) > 0 && ((_b = element.attrs) === null || _b === void 0 ? void 0 : _b.type) === 'entry') {
|
|
32
35
|
if (uids.indexOf(element.attrs['entry-uid']) === -1) {
|
|
33
36
|
uids.push(element.attrs['entry-uid']);
|
|
34
37
|
}
|
|
@@ -43,13 +46,14 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
|
|
|
43
46
|
});
|
|
44
47
|
}
|
|
45
48
|
const update = function (_parent, form_id, updateEntry) {
|
|
49
|
+
var _a, _b, _c;
|
|
46
50
|
let _entry = updateEntry;
|
|
47
|
-
let len = _parent.length;
|
|
51
|
+
let len = _parent === null || _parent === void 0 ? void 0 : _parent.length;
|
|
48
52
|
for (let j = 0; j < len; j++) {
|
|
49
53
|
if (_entry && _parent[j]) {
|
|
50
54
|
if (j === len - 1 && _entry[_parent[j]]) {
|
|
51
55
|
if (form_id !== '_assets') {
|
|
52
|
-
if (_entry[_parent[j]].length) {
|
|
56
|
+
if ((_a = _entry[_parent[j]]) === null || _a === void 0 ? void 0 : _a.length) {
|
|
53
57
|
_entry[_parent[j]].forEach((item, idx) => {
|
|
54
58
|
if (typeof item.uid === 'string' && item._content_type_uid) {
|
|
55
59
|
uids.push(item.uid);
|
|
@@ -69,12 +73,12 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
|
|
|
69
73
|
}
|
|
70
74
|
else if (Array.isArray(_entry[_parent[j]])) {
|
|
71
75
|
for (const element of _entry[_parent[j]]) {
|
|
72
|
-
if (element.uid.length) {
|
|
76
|
+
if ((_b = element.uid) === null || _b === void 0 ? void 0 : _b.length) {
|
|
73
77
|
uids.push(element.uid);
|
|
74
78
|
}
|
|
75
79
|
}
|
|
76
80
|
}
|
|
77
|
-
else if (_entry[_parent[j]].uid.length) {
|
|
81
|
+
else if ((_c = _entry[_parent[j]].uid) === null || _c === void 0 ? void 0 : _c.length) {
|
|
78
82
|
uids.push(_entry[_parent[j]].uid);
|
|
79
83
|
}
|
|
80
84
|
}
|
|
@@ -82,7 +86,7 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
|
|
|
82
86
|
_entry = _entry[_parent[j]];
|
|
83
87
|
let _keys = _.clone(_parent).splice(j + 1, len);
|
|
84
88
|
if (Array.isArray(_entry)) {
|
|
85
|
-
for (let i = 0, _i = _entry.length; i < _i; i++) {
|
|
89
|
+
for (let i = 0, _i = _entry === null || _entry === void 0 ? void 0 : _entry.length; i < _i; i++) {
|
|
86
90
|
update(_keys, form_id, _entry[i]);
|
|
87
91
|
}
|
|
88
92
|
}
|
|
@@ -94,6 +98,7 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
|
|
|
94
98
|
}
|
|
95
99
|
};
|
|
96
100
|
const find = function (schema = [], _entry) {
|
|
101
|
+
var _a;
|
|
97
102
|
for (let i = 0, _i = schema === null || schema === void 0 ? void 0 : schema.length; i < _i; i++) {
|
|
98
103
|
switch (schema[i].data_type) {
|
|
99
104
|
case 'reference':
|
|
@@ -118,7 +123,7 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
|
|
|
118
123
|
parent.pop();
|
|
119
124
|
break;
|
|
120
125
|
case 'blocks':
|
|
121
|
-
for (let j = 0, _j = schema[i].blocks.length; j < _j; j++) {
|
|
126
|
+
for (let j = 0, _j = (_a = schema[i].blocks) === null || _a === void 0 ? void 0 : _a.length; j < _j; j++) {
|
|
122
127
|
parent.push(schema[i].uid);
|
|
123
128
|
parent.push(schema[i].blocks[j].uid);
|
|
124
129
|
find(schema[i].blocks[j].schema, _entry);
|
|
@@ -135,12 +140,13 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
|
|
|
135
140
|
}
|
|
136
141
|
};
|
|
137
142
|
function findEntryIdsFromJsonRte(entry, ctSchema = []) {
|
|
143
|
+
var _a, _b, _c;
|
|
138
144
|
for (const element of ctSchema) {
|
|
139
145
|
switch (element.data_type) {
|
|
140
146
|
case 'blocks': {
|
|
141
147
|
if (entry[element.uid]) {
|
|
142
148
|
if (element.multiple) {
|
|
143
|
-
entry[element.uid].forEach((e) => {
|
|
149
|
+
(_a = entry[element.uid]) === null || _a === void 0 ? void 0 : _a.forEach((e) => {
|
|
144
150
|
let key = Object.keys(e).pop();
|
|
145
151
|
let subBlock = element.blocks.filter((e) => e.uid === key).pop();
|
|
146
152
|
findEntryIdsFromJsonRte(e[key], subBlock.schema);
|
|
@@ -153,7 +159,7 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
|
|
|
153
159
|
case 'group': {
|
|
154
160
|
if (entry[element.uid]) {
|
|
155
161
|
if (element.multiple) {
|
|
156
|
-
entry[element.uid].forEach((e) => {
|
|
162
|
+
(_b = entry[element.uid]) === null || _b === void 0 ? void 0 : _b.forEach((e) => {
|
|
157
163
|
findEntryIdsFromJsonRte(e, element.schema);
|
|
158
164
|
});
|
|
159
165
|
}
|
|
@@ -166,7 +172,7 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
|
|
|
166
172
|
case 'json': {
|
|
167
173
|
if (entry[element.uid] && element.field_metadata.rich_text_type) {
|
|
168
174
|
if (element.multiple) {
|
|
169
|
-
entry[element.uid].forEach((jsonRteData) => {
|
|
175
|
+
(_c = entry[element.uid]) === null || _c === void 0 ? void 0 : _c.forEach((jsonRteData) => {
|
|
170
176
|
gatherJsonRteEntryIds(jsonRteData);
|
|
171
177
|
});
|
|
172
178
|
}
|
|
@@ -192,7 +198,8 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
|
|
|
192
198
|
let entry = JSON.stringify(data.entry);
|
|
193
199
|
uids.forEach(function (uid) {
|
|
194
200
|
if (mappedUids.hasOwnProperty(uid)) {
|
|
195
|
-
|
|
201
|
+
const escapedUid = uid.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
202
|
+
entry = entry.replace(new RegExp(escapedUid, 'img'), mappedUids[uid]);
|
|
196
203
|
mapped.push(uid);
|
|
197
204
|
}
|
|
198
205
|
else {
|
|
@@ -256,8 +263,9 @@ const removeUidsFromJsonRteFields = (entry, ctSchema = []) => {
|
|
|
256
263
|
if (entry[element.uid]) {
|
|
257
264
|
if (element.multiple) {
|
|
258
265
|
entry[element.uid] = entry[element.uid].map((e) => {
|
|
266
|
+
var _a;
|
|
259
267
|
let key = Object.keys(e).pop();
|
|
260
|
-
let subBlock = element.blocks.filter((block) => block.uid === key).pop();
|
|
268
|
+
let subBlock = (_a = element.blocks) === null || _a === void 0 ? void 0 : _a.filter((block) => block.uid === key).pop();
|
|
261
269
|
e[key] = (0, exports.removeUidsFromJsonRteFields)(e[key], subBlock.schema);
|
|
262
270
|
return e;
|
|
263
271
|
});
|
|
@@ -312,7 +320,7 @@ const removeUidsFromJsonRteFields = (entry, ctSchema = []) => {
|
|
|
312
320
|
};
|
|
313
321
|
exports.removeUidsFromJsonRteFields = removeUidsFromJsonRteFields;
|
|
314
322
|
function removeUidsFromChildren(children) {
|
|
315
|
-
if (children.length && children.length > 0) {
|
|
323
|
+
if ((children === null || children === void 0 ? void 0 : children.length) && children.length > 0) {
|
|
316
324
|
return children.map((child) => {
|
|
317
325
|
if (child.type && child.type.length > 0) {
|
|
318
326
|
delete child.uid; // remove uid
|
|
@@ -340,14 +348,16 @@ function removeUidsFromChildren(children) {
|
|
|
340
348
|
}
|
|
341
349
|
}
|
|
342
350
|
const removeEntryRefsFromJSONRTE = (entry, ctSchema = []) => {
|
|
351
|
+
var _a, _b;
|
|
343
352
|
for (const element of ctSchema) {
|
|
344
353
|
switch (element.data_type) {
|
|
345
354
|
case 'blocks': {
|
|
346
355
|
if (entry[element.uid]) {
|
|
347
356
|
if (element.multiple) {
|
|
348
357
|
entry[element.uid] = entry[element.uid].map((e) => {
|
|
358
|
+
var _a;
|
|
349
359
|
let key = Object.keys(e).pop();
|
|
350
|
-
let subBlock = element.blocks.filter((block) => block.uid === key).pop();
|
|
360
|
+
let subBlock = (_a = element.blocks) === null || _a === void 0 ? void 0 : _a.filter((block) => block.uid === key).pop();
|
|
351
361
|
e[key] = (0, exports.removeEntryRefsFromJSONRTE)(e[key], subBlock.schema);
|
|
352
362
|
return e;
|
|
353
363
|
});
|
|
@@ -374,10 +384,12 @@ const removeEntryRefsFromJSONRTE = (entry, ctSchema = []) => {
|
|
|
374
384
|
const structuredPTag = '{"type":"p","attrs":{},"children":[{"text":""}]}';
|
|
375
385
|
if (entry[element.uid] && element.field_metadata.rich_text_type) {
|
|
376
386
|
if (element.multiple) {
|
|
387
|
+
entry[element.uid] = entry[element.uid].map(removeReferenceInJsonRTE);
|
|
377
388
|
entry[element.uid] = entry[element.uid].map((jsonRteData) => {
|
|
389
|
+
var _a;
|
|
378
390
|
// repeated code from else block, will abstract later
|
|
379
|
-
let entryReferences = jsonRteData.children.filter((e) => doEntryReferencesExist(e));
|
|
380
|
-
if (entryReferences.length > 0) {
|
|
391
|
+
let entryReferences = (_a = jsonRteData.children) === null || _a === void 0 ? void 0 : _a.filter((e) => doEntryReferencesExist(e));
|
|
392
|
+
if ((entryReferences === null || entryReferences === void 0 ? void 0 : entryReferences.length) > 0) {
|
|
381
393
|
jsonRteData.children = jsonRteData.children.filter((e) => !doEntryReferencesExist(e));
|
|
382
394
|
if (jsonRteData.children.length === 0) {
|
|
383
395
|
// empty children array are no longer acceptable by the API, a default structure must be there
|
|
@@ -391,10 +403,12 @@ const removeEntryRefsFromJSONRTE = (entry, ctSchema = []) => {
|
|
|
391
403
|
});
|
|
392
404
|
}
|
|
393
405
|
else {
|
|
394
|
-
|
|
395
|
-
|
|
406
|
+
// NOTE Clean up all the reference
|
|
407
|
+
entry[element.uid] = removeReferenceInJsonRTE(entry[element.uid]);
|
|
408
|
+
let entryReferences = (_a = entry[element.uid].children) === null || _a === void 0 ? void 0 : _a.filter((e) => doEntryReferencesExist(e));
|
|
409
|
+
if ((entryReferences === null || entryReferences === void 0 ? void 0 : entryReferences.length) > 0) {
|
|
396
410
|
entry[element.uid].children = entry[element.uid].children.filter((e) => !doEntryReferencesExist(e));
|
|
397
|
-
if (entry[element.uid].children.length === 0) {
|
|
411
|
+
if (((_b = entry[element.uid].children) === null || _b === void 0 ? void 0 : _b.length) === 0) {
|
|
398
412
|
entry[element.uid].children.push(JSON.parse(structuredPTag));
|
|
399
413
|
}
|
|
400
414
|
}
|
|
@@ -410,9 +424,11 @@ exports.removeEntryRefsFromJSONRTE = removeEntryRefsFromJSONRTE;
|
|
|
410
424
|
function doEntryReferencesExist(element) {
|
|
411
425
|
// checks if the children of p element contain any references
|
|
412
426
|
// only checking one level deep, not recursive
|
|
413
|
-
if (element.length) {
|
|
427
|
+
if (element === null || element === void 0 ? void 0 : element.length) {
|
|
414
428
|
for (const item of element) {
|
|
415
|
-
if ((item.type === 'p' || item.type === 'a' || item.type === 'span') &&
|
|
429
|
+
if ((item.type === 'p' || item.type === 'a' || item.type === 'span') &&
|
|
430
|
+
item.children &&
|
|
431
|
+
item.children.length > 0) {
|
|
416
432
|
return doEntryReferencesExist(item.children);
|
|
417
433
|
}
|
|
418
434
|
else if (isEntryRef(item)) {
|
|
@@ -424,28 +440,31 @@ function doEntryReferencesExist(element) {
|
|
|
424
440
|
if (isEntryRef(element)) {
|
|
425
441
|
return true;
|
|
426
442
|
}
|
|
427
|
-
if ((element.type === 'p' || element.type === 'a' || element.type === 'span') &&
|
|
443
|
+
if ((element.type === 'p' || element.type === 'a' || element.type === 'span') &&
|
|
444
|
+
element.children &&
|
|
445
|
+
element.children.length > 0) {
|
|
428
446
|
return doEntryReferencesExist(element.children);
|
|
429
447
|
}
|
|
430
448
|
}
|
|
431
449
|
return false;
|
|
432
450
|
}
|
|
433
451
|
function isEntryRef(element) {
|
|
434
|
-
|
|
452
|
+
var _a;
|
|
453
|
+
return element.type === 'reference' && ((_a = element.attrs) === null || _a === void 0 ? void 0 : _a.type) === 'entry';
|
|
435
454
|
}
|
|
436
|
-
const restoreJsonRteEntryRefs = (entry, sourceStackEntry, ctSchema = [], { mappedAssetUids, mappedAssetUrls }) => {
|
|
437
|
-
// let mappedAssetUids = fileHelper.readFileSync(this.mappedAssetUidPath) || {};
|
|
438
|
-
// let mappedAssetUrls = fileHelper.readFileSync(this.mappedAssetUrlPath) || {};
|
|
455
|
+
const restoreJsonRteEntryRefs = (entry, sourceStackEntry, ctSchema = [], { uidMapper, mappedAssetUids, mappedAssetUrls }) => {
|
|
439
456
|
for (const element of ctSchema) {
|
|
440
457
|
switch (element.data_type) {
|
|
441
458
|
case 'blocks': {
|
|
442
459
|
if (entry[element.uid]) {
|
|
443
460
|
if (element.multiple && Array.isArray(entry[element.uid])) {
|
|
444
461
|
entry[element.uid] = entry[element.uid].map((e, eIndex) => {
|
|
462
|
+
var _a;
|
|
445
463
|
let key = Object.keys(e).pop();
|
|
446
|
-
let subBlock = element.blocks.filter((block) => block.uid === key).pop();
|
|
464
|
+
let subBlock = (_a = element.blocks) === null || _a === void 0 ? void 0 : _a.filter((block) => block.uid === key).pop();
|
|
447
465
|
let sourceStackElement = sourceStackEntry[element.uid][eIndex][key];
|
|
448
466
|
e[key] = (0, exports.restoreJsonRteEntryRefs)(e[key], sourceStackElement, subBlock.schema, {
|
|
467
|
+
uidMapper,
|
|
449
468
|
mappedAssetUids,
|
|
450
469
|
mappedAssetUrls,
|
|
451
470
|
});
|
|
@@ -461,13 +480,18 @@ const restoreJsonRteEntryRefs = (entry, sourceStackEntry, ctSchema = [], { mappe
|
|
|
461
480
|
if (element.multiple && Array.isArray(entry[element.uid])) {
|
|
462
481
|
entry[element.uid] = entry[element.uid].map((e, eIndex) => {
|
|
463
482
|
let sourceStackElement = sourceStackEntry[element.uid][eIndex];
|
|
464
|
-
e = (0, exports.restoreJsonRteEntryRefs)(e, sourceStackElement, element.schema, {
|
|
483
|
+
e = (0, exports.restoreJsonRteEntryRefs)(e, sourceStackElement, element.schema, {
|
|
484
|
+
uidMapper,
|
|
485
|
+
mappedAssetUids,
|
|
486
|
+
mappedAssetUrls,
|
|
487
|
+
});
|
|
465
488
|
return e;
|
|
466
489
|
});
|
|
467
490
|
}
|
|
468
491
|
else {
|
|
469
492
|
let sourceStackElement = sourceStackEntry[element.uid];
|
|
470
493
|
entry[element.uid] = (0, exports.restoreJsonRteEntryRefs)(entry[element.uid], sourceStackElement, element.schema, {
|
|
494
|
+
uidMapper,
|
|
471
495
|
mappedAssetUids,
|
|
472
496
|
mappedAssetUrls,
|
|
473
497
|
});
|
|
@@ -478,55 +502,23 @@ const restoreJsonRteEntryRefs = (entry, sourceStackEntry, ctSchema = [], { mappe
|
|
|
478
502
|
case 'json': {
|
|
479
503
|
if (entry[element.uid] && element.field_metadata.rich_text_type) {
|
|
480
504
|
if (element.multiple && Array.isArray(entry[element.uid])) {
|
|
481
|
-
entry[element.uid] =
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
return
|
|
487
|
-
})
|
|
488
|
-
.filter((e) => doEntryReferencesExist(e.value))
|
|
489
|
-
.map((e) => {
|
|
490
|
-
// commenting the line below resolved the maximum call stack exceeded issue
|
|
491
|
-
// e.value = this.setDirtyTrue(e.value)
|
|
492
|
-
setDirtyTrue(e.value);
|
|
493
|
-
return e;
|
|
494
|
-
})
|
|
495
|
-
.map((e) => {
|
|
496
|
-
// commenting the line below resolved the maximum call stack exceeded issue
|
|
497
|
-
// e.value = this.resolveAssetRefsInEntryRefsForJsonRte(e, mappedAssetUids, mappedAssetUrls)
|
|
498
|
-
resolveAssetRefsInEntryRefsForJsonRte(e.value, mappedAssetUids, mappedAssetUrls);
|
|
499
|
-
return e;
|
|
505
|
+
entry[element.uid] = sourceStackEntry[element.uid].map((jsonRTE) => {
|
|
506
|
+
jsonRTE = restoreReferenceInJsonRTE(jsonRTE, uidMapper);
|
|
507
|
+
jsonRTE.children = jsonRTE.children.map((child) => {
|
|
508
|
+
child = setDirtyTrue(child);
|
|
509
|
+
child = resolveAssetRefsInEntryRefsForJsonRte(child, mappedAssetUids, mappedAssetUrls);
|
|
510
|
+
return child;
|
|
500
511
|
});
|
|
501
|
-
|
|
502
|
-
entryRefs.forEach((entryRef) => {
|
|
503
|
-
field.children.splice(entryRef.index, 0, entryRef.value);
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
return field;
|
|
512
|
+
return jsonRTE;
|
|
507
513
|
});
|
|
508
514
|
}
|
|
509
515
|
else {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
.map((e) => {
|
|
516
|
-
setDirtyTrue(e.value);
|
|
517
|
-
return e;
|
|
518
|
-
})
|
|
519
|
-
.map((e) => {
|
|
520
|
-
resolveAssetRefsInEntryRefsForJsonRte(e.value, mappedAssetUids, mappedAssetUrls);
|
|
521
|
-
return e;
|
|
516
|
+
entry[element.uid] = restoreReferenceInJsonRTE(sourceStackEntry[element.uid], uidMapper);
|
|
517
|
+
entry[element.uid].children = entry[element.uid].children.map((child) => {
|
|
518
|
+
child = setDirtyTrue(child);
|
|
519
|
+
child = resolveAssetRefsInEntryRefsForJsonRte(child, mappedAssetUids, mappedAssetUrls);
|
|
520
|
+
return child;
|
|
522
521
|
});
|
|
523
|
-
if (entryRefs.length > 0) {
|
|
524
|
-
entryRefs.forEach((entryRef) => {
|
|
525
|
-
if (!_.isEmpty(entry[element.uid]) && entry[element.uid].children) {
|
|
526
|
-
entry[element.uid].children.splice(entryRef.index, 0, entryRef.value);
|
|
527
|
-
}
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
522
|
}
|
|
531
523
|
}
|
|
532
524
|
break;
|
|
@@ -550,8 +542,9 @@ function setDirtyTrue(jsonRteChild) {
|
|
|
550
542
|
return jsonRteChild;
|
|
551
543
|
}
|
|
552
544
|
function resolveAssetRefsInEntryRefsForJsonRte(jsonRteChild, mappedAssetUids, mappedAssetUrls) {
|
|
545
|
+
var _a;
|
|
553
546
|
if (jsonRteChild.type) {
|
|
554
|
-
if (jsonRteChild.attrs.type === 'asset') {
|
|
547
|
+
if (((_a = jsonRteChild.attrs) === null || _a === void 0 ? void 0 : _a.type) === 'asset') {
|
|
555
548
|
let assetUrl;
|
|
556
549
|
if (mappedAssetUids[jsonRteChild.attrs['asset-uid']]) {
|
|
557
550
|
jsonRteChild.attrs['asset-uid'] = mappedAssetUids[jsonRteChild.attrs['asset-uid']];
|
|
@@ -577,3 +570,62 @@ function resolveAssetRefsInEntryRefsForJsonRte(jsonRteChild, mappedAssetUids, ma
|
|
|
577
570
|
}
|
|
578
571
|
return jsonRteChild;
|
|
579
572
|
}
|
|
573
|
+
/**
|
|
574
|
+
* The function removes references from a JSON RTE (Rich Text Editor) object.
|
|
575
|
+
* @param {EntryJsonRTEFieldDataType} jsonRTE - The parameter `jsonRTE` is of type
|
|
576
|
+
* `EntryJsonRTEFieldDataType`. It represents a JSON object that contains rich text content. The
|
|
577
|
+
* function `removeReferenceInJsonRTE` takes this JSON object as input and removes any references
|
|
578
|
+
* present in the content. It recursively traverses the JSON
|
|
579
|
+
* @returns the modified `jsonRTE` object after removing any references in the JSON RTE.
|
|
580
|
+
*/
|
|
581
|
+
function removeReferenceInJsonRTE(jsonRTE) {
|
|
582
|
+
var _a;
|
|
583
|
+
// NOTE Other possible reference logic will be added related to JSON RTE (Ex missing assets, extensions etc.,)
|
|
584
|
+
if ((jsonRTE === null || jsonRTE === void 0 ? void 0 : jsonRTE.children) && Array.isArray(jsonRTE.children)) {
|
|
585
|
+
jsonRTE.children = (_a = jsonRTE === null || jsonRTE === void 0 ? void 0 : jsonRTE.children) === null || _a === void 0 ? void 0 : _a.map((child) => {
|
|
586
|
+
const { children, attrs, type } = child;
|
|
587
|
+
if (type === 'reference' && (attrs === null || attrs === void 0 ? void 0 : attrs['entry-uid'])) {
|
|
588
|
+
child = {
|
|
589
|
+
type: 'p',
|
|
590
|
+
attrs: {},
|
|
591
|
+
children: [{ text: '' }],
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
if (!_.isEmpty(children)) {
|
|
595
|
+
return removeReferenceInJsonRTE(child);
|
|
596
|
+
}
|
|
597
|
+
return child;
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
return jsonRTE;
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* The function `restoreReferenceInJsonRTE` takes a JSON object `jsonRTE` and a mapping object
|
|
604
|
+
* `uidMapper`, and recursively replaces the `entry-uid` attribute values in any `reference` type
|
|
605
|
+
* elements with their corresponding values from the `uidMapper` object.
|
|
606
|
+
* @param {EntryJsonRTEFieldDataType} jsonRTE - The `jsonRTE` parameter is an object that represents a
|
|
607
|
+
* JSON structure. It contains a `children` property which is an array of objects. Each object
|
|
608
|
+
* represents a child element in the JSON structure and can have properties like `children`, `attrs`,
|
|
609
|
+
* and `type`.
|
|
610
|
+
* @param uidMapper - The `uidMapper` parameter is an object that maps entry UIDs to their
|
|
611
|
+
* corresponding restored UIDs. It is used to replace the `entry-uid` attribute in the JSON RTE with
|
|
612
|
+
* the restored UID.
|
|
613
|
+
* @returns the updated `jsonRTE` object with the restored references.
|
|
614
|
+
*/
|
|
615
|
+
function restoreReferenceInJsonRTE(jsonRTE, uidMapper) {
|
|
616
|
+
var _a;
|
|
617
|
+
if ((jsonRTE === null || jsonRTE === void 0 ? void 0 : jsonRTE.children) && Array.isArray(jsonRTE.children)) {
|
|
618
|
+
jsonRTE.children = (_a = jsonRTE === null || jsonRTE === void 0 ? void 0 : jsonRTE.children) === null || _a === void 0 ? void 0 : _a.map((child, index) => {
|
|
619
|
+
const { children, attrs, type } = child;
|
|
620
|
+
if (type === 'reference' && (attrs === null || attrs === void 0 ? void 0 : attrs['entry-uid'])) {
|
|
621
|
+
jsonRTE.children[index] = child;
|
|
622
|
+
jsonRTE.children[index].attrs['entry-uid'] = uidMapper[child.attrs['entry-uid']];
|
|
623
|
+
}
|
|
624
|
+
if (!_.isEmpty(children)) {
|
|
625
|
+
return restoreReferenceInJsonRTE(child, uidMapper);
|
|
626
|
+
}
|
|
627
|
+
return child;
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
return jsonRTE;
|
|
631
|
+
}
|
|
@@ -62,6 +62,7 @@ const setupConfig = async (importCmdFlags) => {
|
|
|
62
62
|
config.source_stack = config.apiKey;
|
|
63
63
|
config.importWebhookStatus = importCmdFlags['import-webhook-status'];
|
|
64
64
|
config.forceStopMarketplaceAppsPrompt = importCmdFlags.yes;
|
|
65
|
+
config.skipPrivateAppRecreationIfExist = importCmdFlags['skip-app-recreation'];
|
|
65
66
|
if (importCmdFlags['branch']) {
|
|
66
67
|
config.branchName = importCmdFlags['branch'];
|
|
67
68
|
config.branchDir = path.join(config.contentDir, config.branchName);
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { fsUtil } from './file-helper';
|
|
|
5
5
|
export { default as backupHandler } from './backup-handler';
|
|
6
6
|
export { log, unlinkFileLogger } from './logger';
|
|
7
7
|
export { uploadAssetHelper, lookupAssets } from './asset-helper';
|
|
8
|
-
export { getDeveloperHubUrl, getOrgUid, getConfirmationToCreateApps,
|
|
8
|
+
export { getDeveloperHubUrl, getOrgUid, getConfirmationToCreateApps, handleNameConflict, makeRedirectUrlCall, confirmToCloseProcess, getAllStackSpecificApps, ifAppAlreadyExist, } from './marketplace-app-helper';
|
|
9
9
|
export { schemaTemplate, suppressSchemaReference, removeReferenceFields } from './content-type-helper';
|
|
10
10
|
export { lookupExtension } from './extension-helper';
|
|
11
11
|
export { lookupEntries, removeUidsFromJsonRteFields, removeEntryRefsFromJSONRTE, restoreJsonRteEntryRefs, } from './entries-helper';
|
package/lib/utils/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lookUpTerms = exports.lookUpTaxonomy = exports.restoreJsonRteEntryRefs = exports.removeEntryRefsFromJSONRTE = exports.removeUidsFromJsonRteFields = exports.lookupEntries = exports.lookupExtension = exports.removeReferenceFields = exports.suppressSchemaReference = exports.schemaTemplate = exports.
|
|
3
|
+
exports.lookUpTerms = exports.lookUpTaxonomy = exports.restoreJsonRteEntryRefs = exports.removeEntryRefsFromJSONRTE = exports.removeUidsFromJsonRteFields = exports.lookupEntries = exports.lookupExtension = exports.removeReferenceFields = exports.suppressSchemaReference = exports.schemaTemplate = exports.ifAppAlreadyExist = exports.getAllStackSpecificApps = exports.confirmToCloseProcess = exports.makeRedirectUrlCall = exports.handleNameConflict = exports.getConfirmationToCreateApps = exports.getOrgUid = exports.getDeveloperHubUrl = exports.lookupAssets = exports.uploadAssetHelper = exports.unlinkFileLogger = exports.log = exports.backupHandler = exports.fsUtil = exports.fileHelper = exports.setupImportConfig = exports.interactive = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
exports.interactive = tslib_1.__importStar(require("./interactive"));
|
|
6
6
|
var import_config_handler_1 = require("./import-config-handler");
|
|
@@ -20,14 +20,11 @@ var marketplace_app_helper_1 = require("./marketplace-app-helper");
|
|
|
20
20
|
Object.defineProperty(exports, "getDeveloperHubUrl", { enumerable: true, get: function () { return marketplace_app_helper_1.getDeveloperHubUrl; } });
|
|
21
21
|
Object.defineProperty(exports, "getOrgUid", { enumerable: true, get: function () { return marketplace_app_helper_1.getOrgUid; } });
|
|
22
22
|
Object.defineProperty(exports, "getConfirmationToCreateApps", { enumerable: true, get: function () { return marketplace_app_helper_1.getConfirmationToCreateApps; } });
|
|
23
|
-
Object.defineProperty(exports, "createPrivateApp", { enumerable: true, get: function () { return marketplace_app_helper_1.createPrivateApp; } });
|
|
24
23
|
Object.defineProperty(exports, "handleNameConflict", { enumerable: true, get: function () { return marketplace_app_helper_1.handleNameConflict; } });
|
|
25
|
-
Object.defineProperty(exports, "installApp", { enumerable: true, get: function () { return marketplace_app_helper_1.installApp; } });
|
|
26
24
|
Object.defineProperty(exports, "makeRedirectUrlCall", { enumerable: true, get: function () { return marketplace_app_helper_1.makeRedirectUrlCall; } });
|
|
27
25
|
Object.defineProperty(exports, "confirmToCloseProcess", { enumerable: true, get: function () { return marketplace_app_helper_1.confirmToCloseProcess; } });
|
|
28
26
|
Object.defineProperty(exports, "getAllStackSpecificApps", { enumerable: true, get: function () { return marketplace_app_helper_1.getAllStackSpecificApps; } });
|
|
29
27
|
Object.defineProperty(exports, "ifAppAlreadyExist", { enumerable: true, get: function () { return marketplace_app_helper_1.ifAppAlreadyExist; } });
|
|
30
|
-
Object.defineProperty(exports, "updateAppConfig", { enumerable: true, get: function () { return marketplace_app_helper_1.updateAppConfig; } });
|
|
31
28
|
var content_type_helper_1 = require("./content-type-helper");
|
|
32
29
|
Object.defineProperty(exports, "schemaTemplate", { enumerable: true, get: function () { return content_type_helper_1.schemaTemplate; } });
|
|
33
30
|
Object.defineProperty(exports, "suppressSchemaReference", { enumerable: true, get: function () { return content_type_helper_1.suppressSchemaReference; } });
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare const getAllStackSpecificApps: (developerHubBaseUrl: string, httpClient: HttpClient, config: ImportConfig) => Promise<any>;
|
|
1
|
+
import { ImportConfig, Installation } from '../types';
|
|
2
|
+
export declare const getAllStackSpecificApps: (config: ImportConfig, skip?: number, listOfApps?: Installation[]) => Promise<Installation[]>;
|
|
4
3
|
export declare const getDeveloperHubUrl: (config: ImportConfig) => Promise<string>;
|
|
5
4
|
export declare const getOrgUid: (config: ImportConfig) => Promise<string>;
|
|
6
5
|
export declare const getConfirmationToCreateApps: (privateApps: any, config: ImportConfig) => Promise<boolean>;
|
|
7
|
-
export declare const createPrivateApp: (client: ContentstackClient, config: ImportConfig, app: any) => Promise<any>;
|
|
8
|
-
export declare const installApp: (client: ContentstackClient, config: ImportConfig, appManifestUid?: string, mappedUid?: string) => Promise<any>;
|
|
9
6
|
export declare const handleNameConflict: (app: any, appSuffix: number, config: ImportConfig) => Promise<any>;
|
|
10
7
|
export declare const makeRedirectUrlCall: (response: any, appName: string, config: ImportConfig) => Promise<void>;
|
|
11
8
|
export declare const confirmToCloseProcess: (installation: any, config: ImportConfig) => Promise<void>;
|
|
12
9
|
export declare const ifAppAlreadyExist: (app: any, currentStackApp: any, config: ImportConfig) => Promise<{}>;
|
|
13
|
-
export declare const updateAppConfig: (client: ContentstackClient, config: ImportConfig, app: any, payload: {
|
|
14
|
-
configuration: Record<string, unknown>;
|
|
15
|
-
server_configuration: Record<string, unknown>;
|
|
16
|
-
}) => Promise<any>;
|
|
@@ -1,33 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ifAppAlreadyExist = exports.confirmToCloseProcess = exports.makeRedirectUrlCall = exports.handleNameConflict = exports.getConfirmationToCreateApps = exports.getOrgUid = exports.getDeveloperHubUrl = exports.getAllStackSpecificApps = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
6
6
|
const map_1 = tslib_1.__importDefault(require("lodash/map"));
|
|
7
|
-
const
|
|
7
|
+
const omitBy_1 = tslib_1.__importDefault(require("lodash/omitBy"));
|
|
8
|
+
const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
|
|
8
9
|
const includes_1 = tslib_1.__importDefault(require("lodash/includes"));
|
|
9
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
10
10
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
11
11
|
const logger_1 = require("./logger");
|
|
12
12
|
const log_1 = require("../utils/log");
|
|
13
13
|
const utils_1 = require("../utils");
|
|
14
14
|
const interactive_1 = require("./interactive");
|
|
15
15
|
const interactive_2 = require("../utils/interactive");
|
|
16
|
-
const getAllStackSpecificApps = async (
|
|
17
|
-
const
|
|
18
|
-
host: developerHubBaseUrl.split('://').pop(),
|
|
16
|
+
const getAllStackSpecificApps = async (config, skip = 0, listOfApps = []) => {
|
|
17
|
+
const appSdk = await (0, cli_utilities_1.marketplaceSDKClient)({
|
|
18
|
+
host: config.developerHubBaseUrl.split('://').pop(),
|
|
19
19
|
});
|
|
20
|
-
|
|
21
|
-
.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
},
|
|
25
|
-
})
|
|
26
|
-
.then(({ data }) => data.data)
|
|
20
|
+
const collection = await appSdk
|
|
21
|
+
.marketplace(config.org_uid)
|
|
22
|
+
.installation()
|
|
23
|
+
.fetchAll({ target_uids: config.target_stack, skip })
|
|
27
24
|
.catch((error) => {
|
|
28
25
|
(0, log_1.trace)(error, 'error', true);
|
|
29
26
|
(0, logger_1.log)(config, `Failed to export marketplace-apps ${(0, utils_1.formatError)(error)}`, 'error');
|
|
30
27
|
});
|
|
28
|
+
if (collection) {
|
|
29
|
+
const { items: apps, count } = collection;
|
|
30
|
+
// NOTE Remove all the chain functions
|
|
31
|
+
const installation = (0, map_1.default)(apps, (app) => (0, omitBy_1.default)(app, (val, _key) => {
|
|
32
|
+
if (val instanceof Function)
|
|
33
|
+
return true;
|
|
34
|
+
return false;
|
|
35
|
+
}));
|
|
36
|
+
listOfApps = listOfApps.concat(installation);
|
|
37
|
+
if (count - (skip + 50) > 0) {
|
|
38
|
+
return await (0, exports.getAllStackSpecificApps)(config, skip + 50, listOfApps);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return listOfApps;
|
|
31
42
|
};
|
|
32
43
|
exports.getAllStackSpecificApps = getAllStackSpecificApps;
|
|
33
44
|
const getDeveloperHubUrl = async (config) => {
|
|
@@ -64,24 +75,6 @@ const getConfirmationToCreateApps = async (privateApps, config) => {
|
|
|
64
75
|
}
|
|
65
76
|
};
|
|
66
77
|
exports.getConfirmationToCreateApps = getConfirmationToCreateApps;
|
|
67
|
-
const createPrivateApp = async (client, config, app) => {
|
|
68
|
-
const privateApp = (0, omit_1.default)(app, ['uid']);
|
|
69
|
-
return await client
|
|
70
|
-
.organization(config.org_uid)
|
|
71
|
-
.app()
|
|
72
|
-
.create(privateApp)
|
|
73
|
-
.catch((error) => error);
|
|
74
|
-
};
|
|
75
|
-
exports.createPrivateApp = createPrivateApp;
|
|
76
|
-
const installApp = async (client, config, appManifestUid, mappedUid) => {
|
|
77
|
-
const appUid = mappedUid || appManifestUid;
|
|
78
|
-
return await client
|
|
79
|
-
.organization(config.org_uid)
|
|
80
|
-
.app(appUid)
|
|
81
|
-
.install({ targetUid: config.target_stack, targetType: 'stack' })
|
|
82
|
-
.catch((error) => error);
|
|
83
|
-
};
|
|
84
|
-
exports.installApp = installApp;
|
|
85
78
|
const handleNameConflict = async (app, appSuffix, config) => {
|
|
86
79
|
const appName = config.forceStopMarketplaceAppsPrompt
|
|
87
80
|
? (0, interactive_2.getAppName)(app.name, appSuffix)
|
|
@@ -142,19 +135,3 @@ const ifAppAlreadyExist = async (app, currentStackApp, config) => {
|
|
|
142
135
|
return updateParam;
|
|
143
136
|
};
|
|
144
137
|
exports.ifAppAlreadyExist = ifAppAlreadyExist;
|
|
145
|
-
const updateAppConfig = async (client, config, app, payload) => {
|
|
146
|
-
var _a;
|
|
147
|
-
let installation = client.organization(config.org_uid).app((_a = app === null || app === void 0 ? void 0 : app.manifest) === null || _a === void 0 ? void 0 : _a.uid).installation(app === null || app === void 0 ? void 0 : app.uid);
|
|
148
|
-
installation = Object.assign(installation, payload);
|
|
149
|
-
return await installation
|
|
150
|
-
.update()
|
|
151
|
-
.then((data) => {
|
|
152
|
-
var _a;
|
|
153
|
-
(0, logger_1.log)(config, `${(_a = app === null || app === void 0 ? void 0 : app.manifest) === null || _a === void 0 ? void 0 : _a.name} app config updated successfully.!`, 'success');
|
|
154
|
-
})
|
|
155
|
-
.catch((error) => {
|
|
156
|
-
(0, log_1.trace)(error, 'error', true);
|
|
157
|
-
(0, logger_1.log)(config, `Failed to update app config.${(0, utils_1.formatError)(error)}`, 'error');
|
|
158
|
-
});
|
|
159
|
-
};
|
|
160
|
-
exports.updateAppConfig = updateAppConfig;
|
package/oclif.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.12.
|
|
2
|
+
"version": "1.12.2",
|
|
3
3
|
"commands": {
|
|
4
4
|
"cm:stacks:import": {
|
|
5
5
|
"id": "cm:stacks:import",
|
|
@@ -123,6 +123,12 @@
|
|
|
123
123
|
"required": false,
|
|
124
124
|
"allowNo": false
|
|
125
125
|
},
|
|
126
|
+
"skip-app-recreation": {
|
|
127
|
+
"name": "skip-app-recreation",
|
|
128
|
+
"type": "boolean",
|
|
129
|
+
"description": "[optional] Skip private apps recreation if already exist",
|
|
130
|
+
"allowNo": false
|
|
131
|
+
},
|
|
126
132
|
"replace-existing": {
|
|
127
133
|
"name": "replace-existing",
|
|
128
134
|
"type": "boolean",
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-import",
|
|
3
3
|
"description": "Contentstack CLI plugin to import content into stack",
|
|
4
|
-
"version": "1.12.
|
|
4
|
+
"version": "1.12.2",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@contentstack/cli-command": "~1.2.16",
|
|
9
|
-
"@contentstack/cli-utilities": "~1.5.
|
|
10
|
-
"@contentstack/management": "~1.
|
|
9
|
+
"@contentstack/cli-utilities": "~1.5.9",
|
|
10
|
+
"@contentstack/management": "~1.13.0",
|
|
11
11
|
"@oclif/core": "^2.9.3",
|
|
12
12
|
"axios": "^1.6.0",
|
|
13
13
|
"big-json": "^3.2.0",
|
|
@@ -99,4 +99,4 @@
|
|
|
99
99
|
}
|
|
100
100
|
},
|
|
101
101
|
"repository": "https://github.com/contentstack/cli"
|
|
102
|
-
}
|
|
102
|
+
}
|