@contentstack/cli-cm-export 1.11.7 → 1.12.0
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 +1 -1
- package/lib/commands/cm/stacks/export.js +1 -0
- package/lib/config/index.js +83 -1
- package/lib/export/modules/entries.d.ts +3 -0
- package/lib/export/modules/entries.js +28 -7
- package/lib/export/modules/personalization.d.ts +11 -0
- package/lib/export/modules/personalization.js +48 -0
- package/lib/types/default-config.d.ts +39 -0
- package/lib/types/export-config.d.ts +3 -1
- package/lib/types/index.d.ts +7 -1
- package/lib/utils/export-config-handler.js +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ $ npm install -g @contentstack/cli-cm-export
|
|
|
48
48
|
$ csdx COMMAND
|
|
49
49
|
running command...
|
|
50
50
|
$ csdx (--version)
|
|
51
|
-
@contentstack/cli-cm-export/1.
|
|
51
|
+
@contentstack/cli-cm-export/1.12.0 linux-x64 node-v18.20.4
|
|
52
52
|
$ csdx --help [COMMAND]
|
|
53
53
|
USAGE
|
|
54
54
|
$ csdx COMMAND
|
|
@@ -15,6 +15,7 @@ class ExportCommand extends cli_command_1.Command {
|
|
|
15
15
|
let exportConfig = await (0, utils_1.setupExportConfig)(flags);
|
|
16
16
|
// Note setting host to create cma client
|
|
17
17
|
exportConfig.host = this.cmaHost;
|
|
18
|
+
exportConfig.region = this.region;
|
|
18
19
|
exportConfig.developerHubBaseUrl = this.developerHubUrl;
|
|
19
20
|
exportDir = exportConfig.cliLogsPath || exportConfig.data || exportConfig.exportDir;
|
|
20
21
|
const managementAPIClient = await (0, cli_utilities_1.managementSDKClient)(exportConfig);
|
package/lib/config/index.js
CHANGED
|
@@ -33,6 +33,7 @@ const config = {
|
|
|
33
33
|
'content-types',
|
|
34
34
|
'custom-roles',
|
|
35
35
|
'workflows',
|
|
36
|
+
'personalization',
|
|
36
37
|
'entries',
|
|
37
38
|
'labels',
|
|
38
39
|
'marketplace-apps',
|
|
@@ -143,6 +144,47 @@ const config = {
|
|
|
143
144
|
dependencies: ['locales', 'content-types'],
|
|
144
145
|
exportVersions: false,
|
|
145
146
|
},
|
|
147
|
+
personalization: {
|
|
148
|
+
baseURL: {
|
|
149
|
+
NA: 'https://personalization-api.contentstack.com',
|
|
150
|
+
},
|
|
151
|
+
dirName: 'personalization',
|
|
152
|
+
exportOrder: ['attributes', 'audiences', 'events', 'experiences'],
|
|
153
|
+
projects: {
|
|
154
|
+
dirName: 'projects',
|
|
155
|
+
fileName: 'projects.json',
|
|
156
|
+
},
|
|
157
|
+
attributes: {
|
|
158
|
+
dirName: 'attributes',
|
|
159
|
+
fileName: 'attributes.json',
|
|
160
|
+
},
|
|
161
|
+
audiences: {
|
|
162
|
+
dirName: 'audiences',
|
|
163
|
+
fileName: 'audiences.json',
|
|
164
|
+
},
|
|
165
|
+
events: {
|
|
166
|
+
dirName: 'events',
|
|
167
|
+
fileName: 'events.json',
|
|
168
|
+
},
|
|
169
|
+
experiences: {
|
|
170
|
+
dirName: 'experiences',
|
|
171
|
+
fileName: 'experiences.json',
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
variantEntry: {
|
|
175
|
+
serveMockData: false,
|
|
176
|
+
dirName: 'variants',
|
|
177
|
+
fileName: 'index.json',
|
|
178
|
+
chunkFileSize: 1,
|
|
179
|
+
query: {
|
|
180
|
+
skip: 0,
|
|
181
|
+
limit: 100,
|
|
182
|
+
include_variant: false,
|
|
183
|
+
include_count: true,
|
|
184
|
+
include_publish_details: true,
|
|
185
|
+
},
|
|
186
|
+
mockDataPath: './variant-mock-data.json',
|
|
187
|
+
},
|
|
146
188
|
extensions: {
|
|
147
189
|
dirName: 'extensions',
|
|
148
190
|
fileName: 'extensions.json',
|
|
@@ -166,7 +208,46 @@ const config = {
|
|
|
166
208
|
dirName: 'taxonomies',
|
|
167
209
|
fileName: 'taxonomies.json',
|
|
168
210
|
invalidKeys: ['updated_at', 'created_by', 'updated_by', 'stackHeaders', 'urlPath', 'created_at'],
|
|
169
|
-
}
|
|
211
|
+
},
|
|
212
|
+
events: {
|
|
213
|
+
dirName: 'events',
|
|
214
|
+
fileName: 'events.json',
|
|
215
|
+
invalidKeys: [
|
|
216
|
+
'updatedAt',
|
|
217
|
+
'createdBy',
|
|
218
|
+
'updatedBy',
|
|
219
|
+
'_id',
|
|
220
|
+
'createdAt',
|
|
221
|
+
'createdByUserName',
|
|
222
|
+
'updatedByUserName',
|
|
223
|
+
],
|
|
224
|
+
},
|
|
225
|
+
audiences: {
|
|
226
|
+
dirName: 'audiences',
|
|
227
|
+
fileName: 'audiences.json',
|
|
228
|
+
invalidKeys: [
|
|
229
|
+
'updatedAt',
|
|
230
|
+
'createdBy',
|
|
231
|
+
'updatedBy',
|
|
232
|
+
'_id',
|
|
233
|
+
'createdAt',
|
|
234
|
+
'createdByUserName',
|
|
235
|
+
'updatedByUserName',
|
|
236
|
+
],
|
|
237
|
+
},
|
|
238
|
+
attributes: {
|
|
239
|
+
dirName: 'attributes',
|
|
240
|
+
fileName: 'attributes.json',
|
|
241
|
+
invalidKeys: [
|
|
242
|
+
'updatedAt',
|
|
243
|
+
'createdBy',
|
|
244
|
+
'updatedBy',
|
|
245
|
+
'_id',
|
|
246
|
+
'createdAt',
|
|
247
|
+
'createdByUserName',
|
|
248
|
+
'updatedByUserName',
|
|
249
|
+
],
|
|
250
|
+
},
|
|
170
251
|
},
|
|
171
252
|
languagesCode: [
|
|
172
253
|
'af-za',
|
|
@@ -393,6 +474,7 @@ const config = {
|
|
|
393
474
|
stacks: '/stacks/',
|
|
394
475
|
},
|
|
395
476
|
preserveStackVersion: false,
|
|
477
|
+
personalizationEnabled: false,
|
|
396
478
|
fetchConcurrency: 5,
|
|
397
479
|
writeConcurrency: 5,
|
|
398
480
|
developerHubBaseUrl: '',
|
|
@@ -4,10 +4,13 @@ export default class EntriesExport extends BaseClass {
|
|
|
4
4
|
private stackAPIClient;
|
|
5
5
|
exportConfig: ExportConfig;
|
|
6
6
|
private entriesConfig;
|
|
7
|
+
private variantEntries;
|
|
7
8
|
private entriesDirPath;
|
|
8
9
|
private localesFilePath;
|
|
9
10
|
private schemaFilePath;
|
|
10
11
|
private entriesFileHelper;
|
|
12
|
+
private projectInstance;
|
|
13
|
+
exportVariantEntry: boolean;
|
|
11
14
|
constructor({ exportConfig, stackAPIClient }: ModuleClassParams);
|
|
12
15
|
start(): Promise<void>;
|
|
13
16
|
createRequestObjects(locales: Array<Record<string, unknown>>, contentTypes: Array<Record<string, unknown>>): Array<Record<string, any>>;
|
|
@@ -3,21 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const path = tslib_1.__importStar(require("path"));
|
|
5
5
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
6
|
+
const cli_variants_1 = require("@contentstack/cli-variants");
|
|
6
7
|
const utils_1 = require("../../utils");
|
|
7
8
|
const base_class_1 = tslib_1.__importDefault(require("./base-class"));
|
|
8
9
|
const cli_utilities_2 = require("@contentstack/cli-utilities");
|
|
9
10
|
class EntriesExport extends base_class_1.default {
|
|
10
11
|
constructor({ exportConfig, stackAPIClient }) {
|
|
11
12
|
super({ exportConfig, stackAPIClient });
|
|
13
|
+
this.exportVariantEntry = false;
|
|
12
14
|
this.stackAPIClient = stackAPIClient;
|
|
13
15
|
this.exportConfig = exportConfig;
|
|
14
16
|
this.entriesConfig = exportConfig.modules.entries;
|
|
15
17
|
this.entriesDirPath = path.resolve((0, cli_utilities_2.sanitizePath)(exportConfig.data), (0, cli_utilities_2.sanitizePath)(exportConfig.branchName || ''), (0, cli_utilities_2.sanitizePath)(this.entriesConfig.dirName));
|
|
16
18
|
this.localesFilePath = path.resolve((0, cli_utilities_2.sanitizePath)(exportConfig.data), (0, cli_utilities_2.sanitizePath)(exportConfig.branchName || ''), (0, cli_utilities_2.sanitizePath)(exportConfig.modules.locales.dirName), (0, cli_utilities_2.sanitizePath)(exportConfig.modules.locales.fileName));
|
|
17
19
|
this.schemaFilePath = path.resolve((0, cli_utilities_2.sanitizePath)(exportConfig.data), (0, cli_utilities_2.sanitizePath)(exportConfig.branchName || ''), (0, cli_utilities_2.sanitizePath)(exportConfig.modules.content_types.dirName), 'schema.json');
|
|
20
|
+
this.projectInstance = new cli_variants_1.ExportProjects(this.exportConfig);
|
|
18
21
|
}
|
|
19
22
|
async start() {
|
|
20
|
-
var _a;
|
|
23
|
+
var _a, _b;
|
|
21
24
|
try {
|
|
22
25
|
(0, utils_1.log)(this.exportConfig, 'Starting entries export', 'info');
|
|
23
26
|
const locales = utils_1.fsUtil.readFile(this.localesFilePath);
|
|
@@ -26,15 +29,25 @@ class EntriesExport extends base_class_1.default {
|
|
|
26
29
|
(0, utils_1.log)(this.exportConfig, 'No content types found to export entries', 'info');
|
|
27
30
|
return;
|
|
28
31
|
}
|
|
32
|
+
// NOTE Check if variant is enabled in specific stack
|
|
33
|
+
if (this.exportConfig.personalizationEnabled) {
|
|
34
|
+
let project_id;
|
|
35
|
+
try {
|
|
36
|
+
const project = await this.projectInstance.projects({ connectedStackApiKey: this.exportConfig.apiKey });
|
|
37
|
+
if (project && ((_a = project[0]) === null || _a === void 0 ? void 0 : _a.uid)) {
|
|
38
|
+
project_id = project[0].uid;
|
|
39
|
+
this.exportVariantEntry = true;
|
|
40
|
+
}
|
|
41
|
+
this.variantEntries = new cli_variants_1.Export.VariantEntries(Object.assign(this.exportConfig, { project_id }));
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
(0, utils_1.log)(this.exportConfig, `Failed to export variant entries ${error}`, 'error');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
29
47
|
const entryRequestOptions = this.createRequestObjects(locales, contentTypes);
|
|
30
48
|
for (let entryRequestOption of entryRequestOptions) {
|
|
31
|
-
// log(
|
|
32
|
-
// this.exportConfig,
|
|
33
|
-
// `Starting export of entries of content type - ${entryRequestOption.contentType} locale - ${entryRequestOption.locale}`,
|
|
34
|
-
// 'info',
|
|
35
|
-
// );
|
|
36
49
|
await this.getEntries(entryRequestOption);
|
|
37
|
-
(
|
|
50
|
+
(_b = this.entriesFileHelper) === null || _b === void 0 ? void 0 : _b.completeFile(true);
|
|
38
51
|
(0, utils_1.log)(this.exportConfig, `Exported entries of type '${entryRequestOption.contentType}' locale '${entryRequestOption.locale}'`, 'success');
|
|
39
52
|
}
|
|
40
53
|
(0, utils_1.log)(this.exportConfig, 'Entries exported successfully', 'success');
|
|
@@ -102,6 +115,14 @@ class EntriesExport extends base_class_1.default {
|
|
|
102
115
|
versionedEntryPath,
|
|
103
116
|
});
|
|
104
117
|
}
|
|
118
|
+
// NOTE Export all base entry specific 'variant entries'
|
|
119
|
+
if (this.exportVariantEntry) {
|
|
120
|
+
await this.variantEntries.exportVariantEntry({
|
|
121
|
+
locale: options.locale,
|
|
122
|
+
contentTypeUid: options.contentType,
|
|
123
|
+
entries: entriesSearchResponse.items,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
105
126
|
options.skip += this.entriesConfig.limit || 100;
|
|
106
127
|
if (options.skip >= entriesSearchResponse.count) {
|
|
107
128
|
return Promise.resolve(true);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AnyProperty } from '@contentstack/cli-variants';
|
|
2
|
+
import { ModuleClassParams, ExportConfig } from '../../types';
|
|
3
|
+
export default class ExportPersonalization {
|
|
4
|
+
exportConfig: ExportConfig;
|
|
5
|
+
personalizeConfig: {
|
|
6
|
+
dirName: string;
|
|
7
|
+
baseURL: Record<string, string>;
|
|
8
|
+
} & AnyProperty;
|
|
9
|
+
constructor({ exportConfig }: ModuleClassParams);
|
|
10
|
+
start(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const cli_variants_1 = require("@contentstack/cli-variants");
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
class ExportPersonalization {
|
|
6
|
+
constructor({ exportConfig }) {
|
|
7
|
+
this.exportConfig = exportConfig;
|
|
8
|
+
this.personalizeConfig = exportConfig.modules.personalization;
|
|
9
|
+
}
|
|
10
|
+
async start() {
|
|
11
|
+
try {
|
|
12
|
+
if (!this.personalizeConfig.baseURL[this.exportConfig.region.name]) {
|
|
13
|
+
(0, utils_1.log)(this.exportConfig, 'Skipping Personalize project export, personalize url is not set', 'info');
|
|
14
|
+
this.exportConfig.personalizationEnabled = false;
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (this.exportConfig.management_token) {
|
|
18
|
+
(0, utils_1.log)(this.exportConfig, 'Skipping Personalize project export when using management token', 'info');
|
|
19
|
+
this.exportConfig.personalizationEnabled = false;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
await new cli_variants_1.ExportProjects(this.exportConfig).start();
|
|
23
|
+
if (this.exportConfig.personalizationEnabled) {
|
|
24
|
+
const moduleMapper = {
|
|
25
|
+
events: new cli_variants_1.ExportEvents(this.exportConfig),
|
|
26
|
+
attributes: new cli_variants_1.ExportAttributes(this.exportConfig),
|
|
27
|
+
audiences: new cli_variants_1.ExportAudiences(this.exportConfig),
|
|
28
|
+
experiences: new cli_variants_1.ExportExperiences(this.exportConfig),
|
|
29
|
+
};
|
|
30
|
+
const order = this.exportConfig.modules.personalization
|
|
31
|
+
.exportOrder;
|
|
32
|
+
for (const module of order) {
|
|
33
|
+
if (moduleMapper[module]) {
|
|
34
|
+
await moduleMapper[module].start();
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
(0, utils_1.log)(this.exportConfig, `No implementation found for the module ${module}`, 'info');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
this.exportConfig.personalizationEnabled = false;
|
|
44
|
+
(0, utils_1.log)(this.exportConfig, error, 'error');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.default = ExportPersonalization;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Modules } from '.';
|
|
2
|
+
interface AnyProperty {
|
|
3
|
+
[propName: string]: any;
|
|
4
|
+
}
|
|
2
5
|
export default interface DefaultConfig {
|
|
3
6
|
contentVersion: number;
|
|
4
7
|
versioning: boolean;
|
|
@@ -106,6 +109,22 @@ export default interface DefaultConfig {
|
|
|
106
109
|
dependencies?: Modules[];
|
|
107
110
|
exportVersions: boolean;
|
|
108
111
|
};
|
|
112
|
+
personalization: {
|
|
113
|
+
dirName: string;
|
|
114
|
+
baseURL: Record<string, string>;
|
|
115
|
+
} & AnyProperty;
|
|
116
|
+
variantEntry: {
|
|
117
|
+
dirName: string;
|
|
118
|
+
fileName: string;
|
|
119
|
+
chunkFileSize: number;
|
|
120
|
+
query: {
|
|
121
|
+
skip: number;
|
|
122
|
+
limit: number;
|
|
123
|
+
include_variant: boolean;
|
|
124
|
+
include_count: boolean;
|
|
125
|
+
include_publish_details: boolean;
|
|
126
|
+
} & AnyProperty;
|
|
127
|
+
} & AnyProperty;
|
|
109
128
|
extensions: {
|
|
110
129
|
dirName: string;
|
|
111
130
|
fileName: string;
|
|
@@ -140,6 +159,24 @@ export default interface DefaultConfig {
|
|
|
140
159
|
invalidKeys: string[];
|
|
141
160
|
dependencies?: Modules[];
|
|
142
161
|
};
|
|
162
|
+
events: {
|
|
163
|
+
dirName: string;
|
|
164
|
+
fileName: string;
|
|
165
|
+
invalidKeys: string[];
|
|
166
|
+
dependencies?: Modules[];
|
|
167
|
+
};
|
|
168
|
+
audiences: {
|
|
169
|
+
dirName: string;
|
|
170
|
+
fileName: string;
|
|
171
|
+
invalidKeys: string[];
|
|
172
|
+
dependencies?: Modules[];
|
|
173
|
+
};
|
|
174
|
+
attributes: {
|
|
175
|
+
dirName: string;
|
|
176
|
+
fileName: string;
|
|
177
|
+
invalidKeys: string[];
|
|
178
|
+
dependencies?: Modules[];
|
|
179
|
+
};
|
|
143
180
|
};
|
|
144
181
|
languagesCode: string[];
|
|
145
182
|
apis: {
|
|
@@ -157,9 +194,11 @@ export default interface DefaultConfig {
|
|
|
157
194
|
stacks: string;
|
|
158
195
|
};
|
|
159
196
|
preserveStackVersion: boolean;
|
|
197
|
+
personalizationEnabled: boolean;
|
|
160
198
|
fetchConcurrency: number;
|
|
161
199
|
writeConcurrency: number;
|
|
162
200
|
developerHubBaseUrl: string;
|
|
163
201
|
marketplaceAppEncryptionKey: string;
|
|
164
202
|
onlyTSModules: string[];
|
|
165
203
|
}
|
|
204
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Modules } from '.';
|
|
1
|
+
import { Modules, Region } from '.';
|
|
2
2
|
import DefaultConfig from './default-config';
|
|
3
3
|
export default interface ExportConfig extends DefaultConfig {
|
|
4
4
|
cliLogsPath: string;
|
|
@@ -22,11 +22,13 @@ export default interface ExportConfig extends DefaultConfig {
|
|
|
22
22
|
access_token?: string;
|
|
23
23
|
authtoken?: string;
|
|
24
24
|
'X-User-Agent': string;
|
|
25
|
+
organization_uid?: string;
|
|
25
26
|
};
|
|
26
27
|
access_token?: string;
|
|
27
28
|
org_uid?: string;
|
|
28
29
|
source_stack?: string;
|
|
29
30
|
sourceStackName?: string;
|
|
31
|
+
region: Region;
|
|
30
32
|
}
|
|
31
33
|
type branch = {
|
|
32
34
|
uid: string;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -20,7 +20,13 @@ export interface User {
|
|
|
20
20
|
email: string;
|
|
21
21
|
authtoken: string;
|
|
22
22
|
}
|
|
23
|
-
export
|
|
23
|
+
export interface Region {
|
|
24
|
+
name: string;
|
|
25
|
+
cma: string;
|
|
26
|
+
cda: string;
|
|
27
|
+
uiHost: string;
|
|
28
|
+
}
|
|
29
|
+
export type Modules = 'stack' | 'assets' | 'locales' | 'environments' | 'extensions' | 'webhooks' | 'global-fields' | 'entries' | 'content-types' | 'custom-roles' | 'workflows' | 'labels' | 'marketplace-apps' | 'taxonomies' | 'personalization';
|
|
24
30
|
export type ModuleClassParams = {
|
|
25
31
|
stackAPIClient: ReturnType<ContentstackClient['stack']>;
|
|
26
32
|
exportConfig: ExportConfig;
|
|
@@ -57,7 +57,7 @@ const setupConfig = async (exportCmdFlags) => {
|
|
|
57
57
|
// Note support old config
|
|
58
58
|
config.source_stack = config.apiKey;
|
|
59
59
|
config.forceStopMarketplaceAppsPrompt = exportCmdFlags.yes;
|
|
60
|
-
config.auth_token = cli_utilities_1.configHandler.get('authtoken'); // TBD
|
|
60
|
+
config.auth_token = cli_utilities_1.configHandler.get('authtoken'); // TBD handle auth token in httpClient & sdk
|
|
61
61
|
config.isAuthenticated = (0, cli_utilities_1.isAuthenticated)();
|
|
62
62
|
if (exportCmdFlags['branch']) {
|
|
63
63
|
config.branchName = exportCmdFlags['branch'];
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-export",
|
|
3
3
|
"description": "Contentstack CLI plugin to export content from stack",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.12.0",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@contentstack/cli-command": "~1.3.0",
|
|
9
|
-
"@contentstack/cli-
|
|
9
|
+
"@contentstack/cli-variants": "~0.0.1-alpha",
|
|
10
|
+
"@contentstack/cli-utilities": "~1.7.2",
|
|
10
11
|
"@oclif/core": "^3.26.5",
|
|
11
12
|
"async": "^3.2.4",
|
|
12
13
|
"big-json": "^3.2.0",
|
|
@@ -98,4 +99,4 @@
|
|
|
98
99
|
}
|
|
99
100
|
},
|
|
100
101
|
"repository": "https://github.com/contentstack/cli"
|
|
101
|
-
}
|
|
102
|
+
}
|