@contentstack/cli-cm-export 1.20.1 → 2.0.0-beta
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 +15 -6
- package/lib/config/index.js +0 -2
- package/lib/export/module-exporter.js +37 -38
- package/lib/export/modules/assets.js +71 -14
- package/lib/export/modules/base-class.d.ts +17 -0
- package/lib/export/modules/base-class.js +45 -0
- package/lib/export/modules/content-types.js +30 -8
- package/lib/export/modules/custom-roles.js +61 -21
- package/lib/export/modules/entries.d.ts +2 -0
- package/lib/export/modules/entries.js +137 -37
- package/lib/export/modules/environments.js +45 -20
- package/lib/export/modules/extensions.js +42 -17
- package/lib/export/modules/global-fields.d.ts +1 -1
- package/lib/export/modules/global-fields.js +24 -6
- package/lib/export/modules/index.d.ts +1 -0
- package/lib/export/modules/index.js +1 -0
- package/lib/export/modules/labels.js +43 -16
- package/lib/export/modules/locales.js +31 -12
- package/lib/export/modules/marketplace-apps.d.ts +5 -2
- package/lib/export/modules/marketplace-apps.js +95 -25
- package/lib/export/modules/personalize.d.ts +12 -2
- package/lib/export/modules/personalize.js +181 -46
- package/lib/export/modules/stack.js +83 -28
- package/lib/export/modules/taxonomies.d.ts +4 -9
- package/lib/export/modules/taxonomies.js +123 -75
- package/lib/export/modules/webhooks.js +40 -17
- package/lib/export/modules/workflows.js +57 -20
- package/lib/types/default-config.d.ts +0 -2
- package/lib/types/index.d.ts +1 -1
- package/lib/utils/common-helper.d.ts +1 -2
- package/lib/utils/common-helper.js +1 -12
- package/lib/utils/constants.d.ts +147 -0
- package/lib/utils/constants.js +160 -0
- package/lib/utils/export-config-handler.js +2 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +6 -1
- package/lib/utils/marketplace-app-helper.d.ts +1 -0
- package/lib/utils/marketplace-app-helper.js +21 -12
- package/lib/utils/progress-strategy-registry.d.ts +7 -0
- package/lib/utils/progress-strategy-registry.js +92 -0
- package/messages/index.json +4 -2
- package/oclif.manifest.json +1 -1
- package/package.json +3 -3
- package/lib/export/modules-js/assets.d.ts +0 -43
- package/lib/export/modules-js/assets.js +0 -396
- package/lib/export/modules-js/content-types.d.ts +0 -21
- package/lib/export/modules-js/content-types.js +0 -76
- package/lib/export/modules-js/custom-roles.d.ts +0 -21
- package/lib/export/modules-js/custom-roles.js +0 -76
- package/lib/export/modules-js/entries.d.ts +0 -18
- package/lib/export/modules-js/entries.js +0 -143
- package/lib/export/modules-js/environments.d.ts +0 -16
- package/lib/export/modules-js/environments.js +0 -62
- package/lib/export/modules-js/extensions.d.ts +0 -18
- package/lib/export/modules-js/extensions.js +0 -57
- package/lib/export/modules-js/global-fields.d.ts +0 -22
- package/lib/export/modules-js/global-fields.js +0 -108
- package/lib/export/modules-js/index.d.ts +0 -2
- package/lib/export/modules-js/index.js +0 -31
- package/lib/export/modules-js/labels.d.ts +0 -14
- package/lib/export/modules-js/labels.js +0 -56
- package/lib/export/modules-js/locales.d.ts +0 -23
- package/lib/export/modules-js/locales.js +0 -68
- package/lib/export/modules-js/marketplace-apps.d.ts +0 -21
- package/lib/export/modules-js/marketplace-apps.js +0 -132
- package/lib/export/modules-js/stack.d.ts +0 -18
- package/lib/export/modules-js/stack.js +0 -91
- package/lib/export/modules-js/webhooks.d.ts +0 -18
- package/lib/export/modules-js/webhooks.js +0 -60
- package/lib/export/modules-js/workflows.d.ts +0 -16
- package/lib/export/modules-js/workflows.js +0 -89
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export = LocaleExport;
|
|
2
|
-
declare class LocaleExport {
|
|
3
|
-
constructor(exportConfig: any, stackAPIClient: any);
|
|
4
|
-
stackAPIClient: any;
|
|
5
|
-
exportConfig: any;
|
|
6
|
-
localeConfig: any;
|
|
7
|
-
masterLocaleConfig: any;
|
|
8
|
-
qs: {
|
|
9
|
-
include_count: boolean;
|
|
10
|
-
asc: string;
|
|
11
|
-
only: {
|
|
12
|
-
BASE: any;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
localesPath: string;
|
|
16
|
-
locales: {};
|
|
17
|
-
masterLocale: {};
|
|
18
|
-
fetchConcurrency: any;
|
|
19
|
-
writeConcurrency: any;
|
|
20
|
-
start(): Promise<void>;
|
|
21
|
-
getLocales(skip?: number): any;
|
|
22
|
-
sanitizeAttribs(locales: any): void;
|
|
23
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const chalk = require('chalk');
|
|
3
|
-
const { formatError, log, fileHelper } = require('../../utils');
|
|
4
|
-
const { sanitizePath } = require('@contentstack/cli-utilities');
|
|
5
|
-
class LocaleExport {
|
|
6
|
-
constructor(exportConfig, stackAPIClient) {
|
|
7
|
-
this.stackAPIClient = stackAPIClient;
|
|
8
|
-
this.exportConfig = exportConfig;
|
|
9
|
-
this.localeConfig = exportConfig.modules.locales;
|
|
10
|
-
this.masterLocaleConfig = exportConfig.modules.masterLocale;
|
|
11
|
-
this.qs = {
|
|
12
|
-
include_count: true,
|
|
13
|
-
asc: 'updated_at',
|
|
14
|
-
only: {
|
|
15
|
-
BASE: this.localeConfig.requiredKeys,
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
this.localesPath = path.resolve(sanitizePath(exportConfig.data), sanitizePath(exportConfig.branchName || ''), sanitizePath(this.localeConfig.dirName));
|
|
19
|
-
this.locales = {};
|
|
20
|
-
this.masterLocale = {};
|
|
21
|
-
this.fetchConcurrency = this.localeConfig.fetchConcurrency || this.exportConfig.fetchConcurrency;
|
|
22
|
-
this.writeConcurrency = this.localeConfig.writeConcurrency || this.exportConfig.writeConcurrency;
|
|
23
|
-
}
|
|
24
|
-
async start() {
|
|
25
|
-
try {
|
|
26
|
-
log(this.exportConfig, 'Starting locale export', 'success');
|
|
27
|
-
fileHelper.makeDirectory(this.localesPath);
|
|
28
|
-
await this.getLocales();
|
|
29
|
-
await fileHelper.writeFile(path.join(this.localesPath, this.localeConfig.fileName), this.locales);
|
|
30
|
-
await fileHelper.writeFile(path.join(this.localesPath, this.masterLocaleConfig.fileName), this.masterLocale);
|
|
31
|
-
log(this.exportConfig, 'Completed locale export', 'success');
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
log(this.exportConfig, `Failed to export locales. ${formatError(error)}`, 'error');
|
|
35
|
-
throw new Error('Failed to export locales');
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
async getLocales(skip = 0) {
|
|
39
|
-
if (skip) {
|
|
40
|
-
this.qs.skip = skip;
|
|
41
|
-
}
|
|
42
|
-
let localesFetchResponse = await this.stackAPIClient.locale().query(this.qs).find();
|
|
43
|
-
if (Array.isArray(localesFetchResponse.items) && localesFetchResponse.items.length > 0) {
|
|
44
|
-
this.sanitizeAttribs(localesFetchResponse.items);
|
|
45
|
-
skip += this.localeConfig.limit || 100;
|
|
46
|
-
if (skip > localesFetchResponse.count) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
return await this.getLocales(skip);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
sanitizeAttribs(locales) {
|
|
53
|
-
locales.forEach((locale) => {
|
|
54
|
-
for (let key in locale) {
|
|
55
|
-
if (this.localeConfig.requiredKeys.indexOf(key) === -1) {
|
|
56
|
-
delete locale[key];
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
if (locale.code === this.exportConfig.master_locale.code) {
|
|
60
|
-
this.masterLocale[locale.uid] = locale;
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
this.locales[locale.uid] = locale;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
module.exports = LocaleExport;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export = ExportMarketplaceApps;
|
|
2
|
-
declare class ExportMarketplaceApps {
|
|
3
|
-
constructor(credentialConfig: any);
|
|
4
|
-
client: any;
|
|
5
|
-
config: any;
|
|
6
|
-
httpClient: any;
|
|
7
|
-
nodeCrypto: any;
|
|
8
|
-
marketplaceAppPath: any;
|
|
9
|
-
developerHubBaseUrl: any;
|
|
10
|
-
marketplaceAppConfig: {
|
|
11
|
-
dirName: string;
|
|
12
|
-
fileName: string;
|
|
13
|
-
dependencies?: import("../../types").Modules[];
|
|
14
|
-
};
|
|
15
|
-
start(): Promise<void>;
|
|
16
|
-
appSdkAxiosInstance: any;
|
|
17
|
-
getOrgUid(): Promise<void>;
|
|
18
|
-
exportInstalledExtensions(): Promise<void>;
|
|
19
|
-
getAllStackSpecificApps(listOfApps?: any[], skip?: number): any;
|
|
20
|
-
getAppConfigurations(sdkClient: any, installedApps: any, [index, appInstallation]: [any, any]): Promise<void>;
|
|
21
|
-
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Contentstack Export
|
|
3
|
-
* Copyright (c) 2024 Contentstack LLC
|
|
4
|
-
* MIT Licensed
|
|
5
|
-
*/
|
|
6
|
-
const _ = require('lodash');
|
|
7
|
-
const path = require('path');
|
|
8
|
-
const chalk = require('chalk');
|
|
9
|
-
const mkdirp = require('mkdirp');
|
|
10
|
-
const eachOf = require('async/eachOf');
|
|
11
|
-
const { cliux, HttpClient, NodeCrypto, managementSDKClient, HttpClientDecorator, OauthDecorator, isAuthenticated, } = require('@contentstack/cli-utilities');
|
|
12
|
-
const { default: config } = require('../../config');
|
|
13
|
-
const { formatError, log, fileHelper } = require('../../utils');
|
|
14
|
-
const { createNodeCryptoInstance } = require('../../utils');
|
|
15
|
-
module.exports = class ExportMarketplaceApps {
|
|
16
|
-
constructor(credentialConfig) {
|
|
17
|
-
this.marketplaceAppPath = null;
|
|
18
|
-
this.developerHubBaseUrl = null;
|
|
19
|
-
this.marketplaceAppConfig = config.modules.marketplace_apps;
|
|
20
|
-
this.config = _.merge(config, credentialConfig);
|
|
21
|
-
}
|
|
22
|
-
async start() {
|
|
23
|
-
if (!isAuthenticated()) {
|
|
24
|
-
cliux.print('WARNING!!! To export Marketplace apps, you must be logged in. Please check csdx auth:login --help to log in', { color: 'yellow' });
|
|
25
|
-
return Promise.resolve();
|
|
26
|
-
}
|
|
27
|
-
this.developerHubBaseUrl = this.config.developerHubBaseUrl || (await getDeveloperHubUrl(this.config));
|
|
28
|
-
this.appSdkAxiosInstance = await managementSDKClient({
|
|
29
|
-
endpoint: this.developerHubBaseUrl,
|
|
30
|
-
});
|
|
31
|
-
await this.getOrgUid();
|
|
32
|
-
const httpClient = new HttpClient();
|
|
33
|
-
if (!this.config.auth_token) {
|
|
34
|
-
this.httpClient = new OauthDecorator(httpClient);
|
|
35
|
-
const headers = await this.httpClient.preHeadersCheck(this.config);
|
|
36
|
-
this.httpClient = this.httpClient.headers(headers);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
this.httpClient = new HttpClientDecorator(httpClient);
|
|
40
|
-
this.httpClient.headers(this.config);
|
|
41
|
-
}
|
|
42
|
-
log(this.config, 'Starting marketplace app export', 'success');
|
|
43
|
-
this.marketplaceAppPath = path.resolve(this.config.data, this.config.branchName || '', this.marketplaceAppConfig.dirName);
|
|
44
|
-
mkdirp.sync(this.marketplaceAppPath);
|
|
45
|
-
this.nodeCrypto = await createNodeCryptoInstance(config);
|
|
46
|
-
return this.exportInstalledExtensions();
|
|
47
|
-
}
|
|
48
|
-
async getOrgUid() {
|
|
49
|
-
const tempAPIClient = await managementSDKClient({ host: this.config.host });
|
|
50
|
-
const tempStackData = await tempAPIClient
|
|
51
|
-
.stack({ api_key: this.config.source_stack })
|
|
52
|
-
.fetch()
|
|
53
|
-
.catch((error) => {
|
|
54
|
-
log(this.config, formatError(error), 'error');
|
|
55
|
-
console.log(error);
|
|
56
|
-
});
|
|
57
|
-
if (tempStackData === null || tempStackData === void 0 ? void 0 : tempStackData.org_uid) {
|
|
58
|
-
this.config.org_uid = tempStackData.org_uid;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
async exportInstalledExtensions() {
|
|
62
|
-
const client = await managementSDKClient({ host: this.developerHubBaseUrl.split('://').pop() });
|
|
63
|
-
const installedApps = (await this.getAllStackSpecificApps()) || [];
|
|
64
|
-
if (!_.isEmpty(installedApps)) {
|
|
65
|
-
for (const [index, app] of _.entries(installedApps)) {
|
|
66
|
-
await this.getAppConfigurations(client, installedApps, [+index, app]);
|
|
67
|
-
}
|
|
68
|
-
fileHelper.writeFileSync(path.join(this.marketplaceAppPath, this.marketplaceAppConfig.fileName), installedApps);
|
|
69
|
-
log(this.config, chalk.green('All the marketplace apps have been exported successfully'), 'success');
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
log(this.config, 'No marketplace apps found', 'success');
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
getAllStackSpecificApps(listOfApps = [], skip = 0) {
|
|
76
|
-
return this.appSdkAxiosInstance.axiosInstance
|
|
77
|
-
.get(`/installations?target_uids=${this.config.source_stack}&skip=${skip}`, {
|
|
78
|
-
headers: {
|
|
79
|
-
organization_uid: this.config.org_uid
|
|
80
|
-
},
|
|
81
|
-
})
|
|
82
|
-
.then(async ({ data }) => {
|
|
83
|
-
const { data: apps, count } = data;
|
|
84
|
-
if (!this.nodeCrypto && _.find(apps, (app) => !_.isEmpty(app.configuration))) {
|
|
85
|
-
await this.createNodeCryptoInstance();
|
|
86
|
-
}
|
|
87
|
-
listOfApps.push(..._.map(apps, (app) => {
|
|
88
|
-
if (_.has(app, 'configuration')) {
|
|
89
|
-
app['configuration'] = this.nodeCrypto.encrypt(app.configuration || configuration);
|
|
90
|
-
}
|
|
91
|
-
return app;
|
|
92
|
-
}));
|
|
93
|
-
if (count - (skip + 50) > 0) {
|
|
94
|
-
return await this.getAllStackSpecificApps(listOfApps, skip + 50);
|
|
95
|
-
}
|
|
96
|
-
return listOfApps;
|
|
97
|
-
})
|
|
98
|
-
.catch((error) => {
|
|
99
|
-
log(this.config, `Failed to export marketplace-apps. ${formatError(error)}`, 'error');
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
async getAppConfigurations(sdkClient, installedApps, [index, appInstallation]) {
|
|
103
|
-
const appName = appInstallation.manifest.name;
|
|
104
|
-
log(this.config, `Exporting ${appName} app and it's config.`, 'success');
|
|
105
|
-
await sdkClient
|
|
106
|
-
.organization(this.config.org_uid)
|
|
107
|
-
.app(appInstallation.manifest.uid)
|
|
108
|
-
.installation(appInstallation.uid)
|
|
109
|
-
.installationData()
|
|
110
|
-
.then(async (result) => {
|
|
111
|
-
const { data, error } = result;
|
|
112
|
-
if (_.has(data, 'server_configuration')) {
|
|
113
|
-
if (!this.nodeCrypto && _.has(data, 'server_configuration')) {
|
|
114
|
-
await this.createNodeCryptoInstance();
|
|
115
|
-
}
|
|
116
|
-
if (!_.isEmpty(data.server_configuration)) {
|
|
117
|
-
installedApps[index]['server_configuration'] = this.nodeCrypto.encrypt(data.server_configuration);
|
|
118
|
-
log(this.config, `Exported ${appName} app and it's config.`, 'success');
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
log(this.config, `Exported ${appName} app`, 'success');
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
else if (error) {
|
|
125
|
-
log(this.config, `Error on exporting ${appName} app and it's config.`, 'error');
|
|
126
|
-
}
|
|
127
|
-
})
|
|
128
|
-
.catch((err) => {
|
|
129
|
-
log(this.config, `Failed to export ${appName} app config ${formatError(err)}`, 'error');
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export = ExportStack;
|
|
2
|
-
declare class ExportStack {
|
|
3
|
-
constructor(exportConfig: any, stackAPIClient: any);
|
|
4
|
-
stackConfig: {
|
|
5
|
-
dirName: string;
|
|
6
|
-
fileName: string;
|
|
7
|
-
dependencies?: import("../../types").Modules[];
|
|
8
|
-
};
|
|
9
|
-
config: any;
|
|
10
|
-
stackAPIClient: any;
|
|
11
|
-
requestOption: {
|
|
12
|
-
uri: any;
|
|
13
|
-
headers: any;
|
|
14
|
-
json: boolean;
|
|
15
|
-
};
|
|
16
|
-
start(): Promise<any>;
|
|
17
|
-
getLocales(apiDetails: any): Promise<any>;
|
|
18
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Contentstack Export
|
|
3
|
-
* Copyright (c) 2024 Contentstack LLC
|
|
4
|
-
* MIT Licensed
|
|
5
|
-
*/
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const mkdirp = require('mkdirp');
|
|
8
|
-
const merge = require('lodash/merge');
|
|
9
|
-
const { default: config } = require('../../config');
|
|
10
|
-
const { managementSDKClient, isAuthenticated } = require('@contentstack/cli-utilities');
|
|
11
|
-
const { log, fileHelper, formatError } = require('../../utils');
|
|
12
|
-
class ExportStack {
|
|
13
|
-
constructor(exportConfig, stackAPIClient) {
|
|
14
|
-
this.stackConfig = config.modules.stack;
|
|
15
|
-
this.config = merge(config, exportConfig);
|
|
16
|
-
this.stackAPIClient = stackAPIClient;
|
|
17
|
-
this.requestOption = {
|
|
18
|
-
uri: this.config.host + this.config.apis.stacks,
|
|
19
|
-
headers: this.config.headers,
|
|
20
|
-
json: true,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
async start() {
|
|
24
|
-
const self = this;
|
|
25
|
-
if (isAuthenticated()) {
|
|
26
|
-
const tempAPIClient = await managementSDKClient({ host: config.host });
|
|
27
|
-
const tempStackData = await tempAPIClient
|
|
28
|
-
.stack({ api_key: self.config.source_stack })
|
|
29
|
-
.fetch()
|
|
30
|
-
.catch((error) => {
|
|
31
|
-
});
|
|
32
|
-
if (tempStackData && tempStackData.org_uid) {
|
|
33
|
-
self.config.org_uid = tempStackData.org_uid;
|
|
34
|
-
self.config.sourceStackName = tempStackData.name;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if (!self.config.preserveStackVersion && !self.config.hasOwnProperty('master_locale')) {
|
|
38
|
-
const apiDetails = {
|
|
39
|
-
limit: 100,
|
|
40
|
-
skip: 0,
|
|
41
|
-
include_count: true,
|
|
42
|
-
};
|
|
43
|
-
return self.getLocales(apiDetails);
|
|
44
|
-
}
|
|
45
|
-
else if (self.config.preserveStackVersion) {
|
|
46
|
-
log(self.config, 'Exporting stack details', 'success');
|
|
47
|
-
let stackFolderPath = path.resolve(self.config.data, this.stackConfig.dirName);
|
|
48
|
-
let stackContentsFile = path.resolve(stackFolderPath, this.stackConfig.fileName);
|
|
49
|
-
mkdirp.sync(stackFolderPath);
|
|
50
|
-
return new Promise((resolve, reject) => {
|
|
51
|
-
return self.stackAPIClient
|
|
52
|
-
.fetch()
|
|
53
|
-
.then((response) => {
|
|
54
|
-
fileHelper.writeFile(stackContentsFile, response);
|
|
55
|
-
log(self.config, 'Exported stack details successfully!', 'success');
|
|
56
|
-
return resolve(response);
|
|
57
|
-
})
|
|
58
|
-
.catch(reject);
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
getLocales(apiDetails) {
|
|
63
|
-
const self = this;
|
|
64
|
-
return new Promise((resolve, reject) => {
|
|
65
|
-
const result = self.stackAPIClient.locale().query(apiDetails);
|
|
66
|
-
result
|
|
67
|
-
.find()
|
|
68
|
-
.then((response) => {
|
|
69
|
-
const masterLocalObj = response.items.find((obj) => {
|
|
70
|
-
if (obj.fallback_locale === null) {
|
|
71
|
-
return obj;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
apiDetails.skip += apiDetails.limit;
|
|
75
|
-
if (masterLocalObj) {
|
|
76
|
-
return resolve(masterLocalObj);
|
|
77
|
-
}
|
|
78
|
-
else if (apiDetails.skip <= response.count) {
|
|
79
|
-
return resolve(self.getLocales(apiDetails));
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
return reject('Master locale not found');
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
.catch((error) => {
|
|
86
|
-
return reject(error);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
module.exports = ExportStack;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export = ExportWebhooks;
|
|
2
|
-
declare class ExportWebhooks {
|
|
3
|
-
constructor(exportConfig: any, stackAPIClient: any);
|
|
4
|
-
config: any;
|
|
5
|
-
master: {};
|
|
6
|
-
webhooks: {};
|
|
7
|
-
requestOptions: {
|
|
8
|
-
include_count: boolean;
|
|
9
|
-
asc: string;
|
|
10
|
-
};
|
|
11
|
-
webhooksConfig: {
|
|
12
|
-
dirName: string;
|
|
13
|
-
fileName: string;
|
|
14
|
-
dependencies?: import("../../types").Modules[];
|
|
15
|
-
};
|
|
16
|
-
stackAPIClient: any;
|
|
17
|
-
start(): Promise<any>;
|
|
18
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Contentstack Export
|
|
3
|
-
* Copyright (c) 2024 Contentstack LLC
|
|
4
|
-
* MIT Licensed
|
|
5
|
-
*/
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const chalk = require('chalk');
|
|
8
|
-
const mkdirp = require('mkdirp');
|
|
9
|
-
const { merge } = require('lodash');
|
|
10
|
-
const { default: config } = require('../../config');
|
|
11
|
-
const { formatError, log, fileHelper } = require('../../utils');
|
|
12
|
-
// Create folder for environments
|
|
13
|
-
module.exports = class ExportWebhooks {
|
|
14
|
-
constructor(exportConfig, stackAPIClient) {
|
|
15
|
-
this.master = {};
|
|
16
|
-
this.webhooks = {};
|
|
17
|
-
this.requestOptions = {
|
|
18
|
-
include_count: true,
|
|
19
|
-
asc: 'updated_at',
|
|
20
|
-
};
|
|
21
|
-
this.webhooksConfig = config.modules.webhooks;
|
|
22
|
-
this.config = merge(config, exportConfig);
|
|
23
|
-
this.stackAPIClient = stackAPIClient;
|
|
24
|
-
}
|
|
25
|
-
start() {
|
|
26
|
-
log(this.config, 'Starting webhooks export', 'success');
|
|
27
|
-
const self = this;
|
|
28
|
-
const webhooksFolderPath = path.resolve(this.config.data, this.config.branchName || '', self.webhooksConfig.dirName);
|
|
29
|
-
mkdirp.sync(webhooksFolderPath);
|
|
30
|
-
return new Promise((resolve, reject) => {
|
|
31
|
-
self.stackAPIClient
|
|
32
|
-
.webhook()
|
|
33
|
-
.fetchAll(self.requestOptions)
|
|
34
|
-
.then((webhooks) => {
|
|
35
|
-
if (webhooks.items.length !== 0) {
|
|
36
|
-
for (let i = 0, total = webhooks.count; i < total; i++) {
|
|
37
|
-
const webUid = webhooks.items[i].uid;
|
|
38
|
-
self.master[webUid] = '';
|
|
39
|
-
self.webhooks[webUid] = webhooks.items[i];
|
|
40
|
-
delete self.webhooks[webUid].uid;
|
|
41
|
-
delete self.webhooks[webUid].SYS_ACL;
|
|
42
|
-
}
|
|
43
|
-
fileHelper.writeFileSync(path.join(webhooksFolderPath, self.webhooksConfig.fileName), self.webhooks);
|
|
44
|
-
log(self.config, chalk.green('All the webhooks have been exported successfully'), 'success');
|
|
45
|
-
return resolve();
|
|
46
|
-
}
|
|
47
|
-
log(self.config, 'No webhooks found', 'success');
|
|
48
|
-
resolve();
|
|
49
|
-
})
|
|
50
|
-
.catch(function (error) {
|
|
51
|
-
if (error.statusCode === 401) {
|
|
52
|
-
log(self.config, 'You are not allowed to export webhooks, Unless you provide email and password in config', 'error');
|
|
53
|
-
return resolve();
|
|
54
|
-
}
|
|
55
|
-
log(self.config, `Failed to export webhooks. ${formatError(error)}`, 'error');
|
|
56
|
-
reject('Failed to export webhooks');
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export = ExportWorkFlows;
|
|
2
|
-
declare class ExportWorkFlows {
|
|
3
|
-
constructor(exportConfig: any, stackAPIClient: any);
|
|
4
|
-
config: any;
|
|
5
|
-
workflows: {};
|
|
6
|
-
workFlowConfig: {
|
|
7
|
-
dirName: string;
|
|
8
|
-
fileName: string;
|
|
9
|
-
invalidKeys: string[];
|
|
10
|
-
dependencies?: import("../../types").Modules[];
|
|
11
|
-
};
|
|
12
|
-
stackAPIClient: any;
|
|
13
|
-
start(): Promise<any>;
|
|
14
|
-
getWorkflowRoles(self: any, workflow: any): Promise<void>;
|
|
15
|
-
getWorkflowsData(self: any, workflows: any): Promise<void>;
|
|
16
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Contentstack Export
|
|
3
|
-
* Copyright (c) 2024 Contentstack LLC
|
|
4
|
-
* MIT Licensed
|
|
5
|
-
*/
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const chalk = require('chalk');
|
|
8
|
-
const mkdirp = require('mkdirp');
|
|
9
|
-
const { merge } = require('lodash');
|
|
10
|
-
const { formatError, log, fileHelper } = require('../../utils');
|
|
11
|
-
const { default: config } = require('../../config');
|
|
12
|
-
module.exports = class ExportWorkFlows {
|
|
13
|
-
constructor(exportConfig, stackAPIClient) {
|
|
14
|
-
this.workflows = {};
|
|
15
|
-
this.workFlowConfig = config.modules.workflows;
|
|
16
|
-
this.config = merge(config, exportConfig);
|
|
17
|
-
this.stackAPIClient = stackAPIClient;
|
|
18
|
-
}
|
|
19
|
-
start() {
|
|
20
|
-
log(this.config, 'Starting workflow export', 'success');
|
|
21
|
-
const self = this;
|
|
22
|
-
const workflowsFolderPath = path.resolve(this.config.data, this.config.branchName || '', this.workFlowConfig.dirName);
|
|
23
|
-
mkdirp.sync(workflowsFolderPath);
|
|
24
|
-
return new Promise(function (resolve, reject) {
|
|
25
|
-
return self.stackAPIClient
|
|
26
|
-
.workflow()
|
|
27
|
-
.fetchAll()
|
|
28
|
-
.then(async (response) => {
|
|
29
|
-
try {
|
|
30
|
-
if (response.items.length) {
|
|
31
|
-
await self.getWorkflowsData(self, response.items);
|
|
32
|
-
log(self.config, chalk.green('All the workflow have been exported successfully'), 'success');
|
|
33
|
-
}
|
|
34
|
-
if (!response.items.length) {
|
|
35
|
-
log(self.config, 'No workflow were found in the Stack', 'success');
|
|
36
|
-
}
|
|
37
|
-
fileHelper.writeFileSync(path.join(workflowsFolderPath, self.workFlowConfig.fileName), self.workflows);
|
|
38
|
-
resolve();
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
log(self.config, formatError(error), 'error');
|
|
42
|
-
reject(error);
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
.catch(function (error) {
|
|
46
|
-
if (error.statusCode === 401) {
|
|
47
|
-
log(self.config, 'You are not allowed to export workflow, Unless you provide email and password in config', 'error');
|
|
48
|
-
return resolve();
|
|
49
|
-
}
|
|
50
|
-
log(self.config, formatError(error), 'error');
|
|
51
|
-
resolve();
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
async getWorkflowRoles(self, workflow) {
|
|
56
|
-
try {
|
|
57
|
-
for (const stage of workflow.workflow_stages) {
|
|
58
|
-
if (stage.SYS_ACL.roles.uids.length) {
|
|
59
|
-
for (let i = 0; i < stage.SYS_ACL.roles.uids.length; i++) {
|
|
60
|
-
const roleUid = stage.SYS_ACL.roles.uids[i];
|
|
61
|
-
const roleData = await self.stackAPIClient
|
|
62
|
-
.role(roleUid)
|
|
63
|
-
.fetch({ include_rules: true, include_permissions: true });
|
|
64
|
-
stage.SYS_ACL.roles.uids[i] = roleData;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
log(self.config, `Error fetching roles in export workflows task. ${formatError(error)}`, 'error');
|
|
71
|
-
throw new Error({ message: 'Error fetching roles in export workflows task.' });
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
async getWorkflowsData(self, workflows) {
|
|
75
|
-
try {
|
|
76
|
-
for (const workflow of workflows) {
|
|
77
|
-
log(self.config, workflow.name + ' workflow was exported successfully', 'success');
|
|
78
|
-
await self.getWorkflowRoles(self, workflow);
|
|
79
|
-
self.workflows[workflow.uid] = workflow;
|
|
80
|
-
const deleteItems = config.modules.workflows.invalidKeys;
|
|
81
|
-
deleteItems.forEach((e) => delete workflow[e]);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
catch (error) {
|
|
85
|
-
log(self.config, `Error fetching workflow data in export workflows task. ${formatError(error)}`, 'error');
|
|
86
|
-
throw error;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
};
|