@contentstack/cli-cm-export 1.6.1 → 1.8.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.
Files changed (43) hide show
  1. package/README.md +1 -1
  2. package/lib/config/index.js +16 -2
  3. package/lib/export/modules/base-class.d.ts +2 -1
  4. package/lib/export/modules/base-class.js +1 -0
  5. package/lib/export/modules/content-types.d.ts +15 -0
  6. package/lib/export/modules/content-types.js +72 -0
  7. package/lib/export/modules/custom-roles.d.ts +16 -0
  8. package/lib/export/modules/custom-roles.js +81 -0
  9. package/lib/export/modules/entries.d.ts +26 -0
  10. package/lib/export/modules/entries.js +167 -0
  11. package/lib/export/modules/environments.d.ts +12 -0
  12. package/lib/export/modules/environments.js +64 -0
  13. package/lib/export/modules/extensions.d.ts +12 -0
  14. package/lib/export/modules/extensions.js +64 -0
  15. package/lib/export/modules/global-fields.d.ts +14 -0
  16. package/lib/export/modules/global-fields.js +59 -0
  17. package/lib/export/modules/labels.d.ts +12 -0
  18. package/lib/export/modules/labels.js +64 -0
  19. package/lib/export/modules/locales.js +2 -1
  20. package/lib/export/modules/marketplace-apps.d.ts +18 -0
  21. package/lib/export/modules/marketplace-apps.js +119 -0
  22. package/lib/export/modules/stack.d.ts +12 -0
  23. package/lib/export/modules/stack.js +91 -0
  24. package/lib/export/modules/webhooks.d.ts +12 -0
  25. package/lib/export/modules/webhooks.js +63 -0
  26. package/lib/export/modules/workflows.d.ts +14 -0
  27. package/lib/export/modules/workflows.js +81 -0
  28. package/lib/export/modules-js/entries.js +2 -1
  29. package/lib/export/modules-js/index.d.ts +2 -1
  30. package/lib/export/modules-js/index.js +3 -5
  31. package/lib/export/modules-js/marketplace-apps.d.ts +0 -1
  32. package/lib/export/modules-js/marketplace-apps.js +3 -22
  33. package/lib/export/modules-js/stack.js +2 -2
  34. package/lib/types/default-config.d.ts +1 -0
  35. package/lib/types/export-config.d.ts +3 -0
  36. package/lib/types/index.d.ts +49 -0
  37. package/lib/utils/interactive.d.ts +1 -0
  38. package/lib/utils/interactive.js +15 -2
  39. package/lib/utils/marketplace-app-helper.d.ts +11 -1
  40. package/lib/utils/marketplace-app-helper.js +43 -11
  41. package/lib/utils/setup-branches.d.ts +1 -1
  42. package/oclif.manifest.json +1 -1
  43. package/package.json +9 -7
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const path = tslib_1.__importStar(require("path"));
5
+ const utils_1 = require("../../utils");
6
+ const base_class_1 = tslib_1.__importDefault(require("./base-class"));
7
+ class GlobalFieldsExport extends base_class_1.default {
8
+ constructor({ exportConfig, stackAPIClient }) {
9
+ super({ exportConfig, stackAPIClient });
10
+ this.stackAPIClient = stackAPIClient;
11
+ this.globalFieldsConfig = exportConfig.modules['global-fields'];
12
+ this.qs = {
13
+ skip: 0,
14
+ asc: 'updated_at',
15
+ include_count: true,
16
+ limit: this.globalFieldsConfig.limit,
17
+ };
18
+ this.globalFieldsDirPath = path.resolve(exportConfig.data, exportConfig.branchName || '', this.globalFieldsConfig.dirName);
19
+ this.globalFields = [];
20
+ }
21
+ async start() {
22
+ try {
23
+ (0, utils_1.log)(this.exportConfig, 'Starting global fields export', 'success');
24
+ await utils_1.fsUtil.makeDirectory(this.globalFieldsDirPath);
25
+ await this.getGlobalFields();
26
+ utils_1.fsUtil.writeFile(path.join(this.globalFieldsDirPath, this.globalFieldsConfig.fileName), this.globalFields);
27
+ (0, utils_1.log)(this.exportConfig, 'Completed global fields export', 'success');
28
+ }
29
+ catch (error) {
30
+ (0, utils_1.log)(this.exportConfig, `Failed to export global fields. ${(0, utils_1.formatError)(error)}`, 'error');
31
+ throw new Error('Failed to export global fields');
32
+ }
33
+ }
34
+ async getGlobalFields(skip = 0) {
35
+ if (skip) {
36
+ this.qs.skip = skip;
37
+ }
38
+ let globalFieldsFetchResponse = await this.stackAPIClient.globalField().query(this.qs).find();
39
+ if (Array.isArray(globalFieldsFetchResponse.items) && globalFieldsFetchResponse.items.length > 0) {
40
+ this.sanitizeAttribs(globalFieldsFetchResponse.items);
41
+ skip += this.globalFieldsConfig.limit || 100;
42
+ if (skip >= globalFieldsFetchResponse.count) {
43
+ return;
44
+ }
45
+ return await this.getGlobalFields(skip);
46
+ }
47
+ }
48
+ sanitizeAttribs(globalFields) {
49
+ globalFields.forEach((globalField) => {
50
+ for (let key in globalField) {
51
+ if (this.globalFieldsConfig.validKeys.indexOf(key) === -1) {
52
+ delete globalField[key];
53
+ }
54
+ }
55
+ this.globalFields.push(globalField);
56
+ });
57
+ }
58
+ }
59
+ exports.default = GlobalFieldsExport;
@@ -0,0 +1,12 @@
1
+ import BaseClass from './base-class';
2
+ import { ModuleClassParams } from '../../types';
3
+ export default class ExportLabels extends BaseClass {
4
+ private labels;
5
+ private labelConfig;
6
+ labelsFolderPath: string;
7
+ private qs;
8
+ constructor({ exportConfig, stackAPIClient }: ModuleClassParams);
9
+ start(): Promise<void>;
10
+ getLabels(skip?: number): Promise<void>;
11
+ sanitizeAttribs(labels: Record<string, string>[]): void;
12
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
5
+ const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
6
+ const node_path_1 = require("node:path");
7
+ const config_1 = tslib_1.__importDefault(require("../../config"));
8
+ const base_class_1 = tslib_1.__importDefault(require("./base-class"));
9
+ const utils_1 = require("../../utils");
10
+ class ExportLabels extends base_class_1.default {
11
+ constructor({ exportConfig, stackAPIClient }) {
12
+ super({ exportConfig, stackAPIClient });
13
+ this.labels = {};
14
+ this.labelConfig = config_1.default.modules.labels;
15
+ this.qs = { include_count: true };
16
+ }
17
+ async start() {
18
+ (0, utils_1.log)(this.exportConfig, 'Starting labels export', 'info');
19
+ this.labelsFolderPath = (0, node_path_1.resolve)(this.exportConfig.data, this.exportConfig.branchName || '', this.labelConfig.dirName);
20
+ await utils_1.fsUtil.makeDirectory(this.labelsFolderPath);
21
+ await this.getLabels();
22
+ if (this.labels === undefined || (0, isEmpty_1.default)(this.labels)) {
23
+ (0, utils_1.log)(this.exportConfig, 'No labels found', 'info');
24
+ }
25
+ else {
26
+ utils_1.fsUtil.writeFile((0, node_path_1.resolve)(this.labelsFolderPath, this.labelConfig.fileName), this.labels);
27
+ (0, utils_1.log)(this.exportConfig, 'All the labels have been exported successfully!', 'success');
28
+ }
29
+ }
30
+ async getLabels(skip = 0) {
31
+ if (skip) {
32
+ this.qs.skip = skip;
33
+ }
34
+ await this.stack
35
+ .label()
36
+ .query(this.qs)
37
+ .find()
38
+ .then(async (data) => {
39
+ const { items, count } = data;
40
+ if (items === null || items === void 0 ? void 0 : items.length) {
41
+ this.sanitizeAttribs(items);
42
+ skip += this.labelConfig.limit || 100;
43
+ if (skip >= count) {
44
+ return;
45
+ }
46
+ return await this.getLabels(skip);
47
+ }
48
+ })
49
+ .catch((error) => {
50
+ (0, utils_1.log)(this.exportConfig, `Failed to export labels. ${(0, utils_1.formatError)(error)}`, 'error');
51
+ (0, utils_1.log)(this.exportConfig, error, 'error');
52
+ });
53
+ }
54
+ sanitizeAttribs(labels) {
55
+ var _a;
56
+ for (let index = 0; index < (labels === null || labels === void 0 ? void 0 : labels.length); index++) {
57
+ const labelUid = labels[index].uid;
58
+ const labelName = (_a = labels[index]) === null || _a === void 0 ? void 0 : _a.name;
59
+ this.labels[labelUid] = (0, omit_1.default)(labels[index], this.labelConfig.invalidKeys);
60
+ (0, utils_1.log)(this.exportConfig, `'${labelName}' label was exported successfully`, 'success');
61
+ }
62
+ }
63
+ }
64
+ exports.default = ExportLabels;
@@ -51,12 +51,13 @@ class LocaleExport extends base_class_1.default {
51
51
  }
52
52
  sanitizeAttribs(locales) {
53
53
  locales.forEach((locale) => {
54
+ var _a, _b;
54
55
  for (let key in locale) {
55
56
  if (this.localeConfig.requiredKeys.indexOf(key) === -1) {
56
57
  delete locale[key];
57
58
  }
58
59
  }
59
- if (locale.code === this.exportConfig.master_locale.code) {
60
+ if ((locale === null || locale === void 0 ? void 0 : locale.code) === ((_b = (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.master_locale) === null || _b === void 0 ? void 0 : _b.code)) {
60
61
  this.masterLocale[locale.uid] = locale;
61
62
  }
62
63
  else {
@@ -0,0 +1,18 @@
1
+ import { NodeCrypto } from '@contentstack/cli-utilities';
2
+ import BaseClass from './base-class';
3
+ import { ModuleClassParams } from '../../types';
4
+ export default class ExportMarketplaceApps extends BaseClass {
5
+ private httpClient;
6
+ private marketplaceAppConfig;
7
+ private listOfApps;
8
+ private installedApps;
9
+ developerHubBaseUrl: string;
10
+ marketplaceAppPath: string;
11
+ nodeCrypto: NodeCrypto;
12
+ constructor({ exportConfig, stackAPIClient }: ModuleClassParams);
13
+ start(): Promise<void>;
14
+ setHttpClient(): Promise<void>;
15
+ getAllStackSpecificApps(skip?: number): Promise<any>;
16
+ exportInstalledExtensions(): Promise<void>;
17
+ getAppConfigurations(index: number, appInstallation: any): Promise<void>;
18
+ }
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const map_1 = tslib_1.__importDefault(require("lodash/map"));
5
+ const has_1 = tslib_1.__importDefault(require("lodash/has"));
6
+ const find_1 = tslib_1.__importDefault(require("lodash/find"));
7
+ const entries_1 = tslib_1.__importDefault(require("lodash/entries"));
8
+ const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
9
+ const node_path_1 = require("node:path");
10
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
11
+ const config_1 = tslib_1.__importDefault(require("../../config"));
12
+ const utils_1 = require("../../utils");
13
+ const base_class_1 = tslib_1.__importDefault(require("./base-class"));
14
+ class ExportMarketplaceApps extends base_class_1.default {
15
+ constructor({ exportConfig, stackAPIClient }) {
16
+ super({ exportConfig, stackAPIClient });
17
+ this.httpClient = new cli_utilities_1.HttpClient();
18
+ this.marketplaceAppConfig = config_1.default.modules.marketplace_apps;
19
+ this.listOfApps = [];
20
+ this.installedApps = [];
21
+ }
22
+ async start() {
23
+ if (!(0, cli_utilities_1.isAuthenticated)()) {
24
+ cli_utilities_1.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
+ (0, utils_1.log)(this.exportConfig, 'Starting marketplace app export', 'info');
28
+ this.marketplaceAppPath = (0, node_path_1.resolve)(this.exportConfig.data, this.exportConfig.branchName || '', this.marketplaceAppConfig.dirName);
29
+ await utils_1.fsUtil.makeDirectory(this.marketplaceAppPath);
30
+ this.developerHubBaseUrl = this.exportConfig.developerHubBaseUrl || (await (0, utils_1.getDeveloperHubUrl)(this.exportConfig));
31
+ this.exportConfig.org_uid = await (0, utils_1.getOrgUid)(this.exportConfig);
32
+ await this.setHttpClient();
33
+ await this.getAllStackSpecificApps();
34
+ this.installedApps = this.listOfApps;
35
+ await this.exportInstalledExtensions();
36
+ }
37
+ async setHttpClient() {
38
+ if (!this.exportConfig.auth_token) {
39
+ this.httpClient = new cli_utilities_1.OauthDecorator(this.httpClient);
40
+ const headers = await this.httpClient.preHeadersCheck(this.exportConfig);
41
+ this.httpClient = this.httpClient.headers(headers);
42
+ }
43
+ else {
44
+ this.httpClient = new cli_utilities_1.HttpClientDecorator(this.httpClient);
45
+ this.httpClient.headers(this.exportConfig);
46
+ }
47
+ }
48
+ async getAllStackSpecificApps(skip = 0) {
49
+ const data = await (0, utils_1.getStackSpecificApps)({
50
+ developerHubBaseUrl: this.developerHubBaseUrl,
51
+ httpClient: this.httpClient,
52
+ config: this.exportConfig,
53
+ skip,
54
+ });
55
+ const { data: apps, count } = data;
56
+ if (!this.nodeCrypto && (0, find_1.default)(apps, (app) => (0, isEmpty_1.default)(app.configuration))) {
57
+ this.nodeCrypto = await (0, utils_1.createNodeCryptoInstance)(this.exportConfig);
58
+ }
59
+ const stackApps = (0, map_1.default)(apps, (app) => {
60
+ if ((0, has_1.default)(app, 'configuration')) {
61
+ app['configuration'] = this.nodeCrypto.encrypt(app.configuration);
62
+ }
63
+ return app;
64
+ });
65
+ this.listOfApps = [...this.listOfApps, ...stackApps];
66
+ if (count - (skip + 50) > 0) {
67
+ return await this.getAllStackSpecificApps(skip + 50);
68
+ }
69
+ }
70
+ async exportInstalledExtensions() {
71
+ if ((0, isEmpty_1.default)(this.installedApps)) {
72
+ (0, utils_1.log)(this.exportConfig, 'No marketplace apps found', 'info');
73
+ }
74
+ else {
75
+ for (const [index, app] of (0, entries_1.default)(this.installedApps)) {
76
+ await this.getAppConfigurations(+index, app);
77
+ }
78
+ utils_1.fsUtil.writeFile((0, node_path_1.resolve)(this.marketplaceAppPath, this.marketplaceAppConfig.fileName), this.installedApps);
79
+ (0, utils_1.log)(this.exportConfig, 'All the marketplace apps have been exported successfully', 'info');
80
+ }
81
+ }
82
+ async getAppConfigurations(index, appInstallation) {
83
+ var _a, _b;
84
+ const sdkClient = await (0, cli_utilities_1.managementSDKClient)({
85
+ host: this.developerHubBaseUrl.split('://').pop(),
86
+ });
87
+ const appName = (_a = appInstallation === null || appInstallation === void 0 ? void 0 : appInstallation.manifest) === null || _a === void 0 ? void 0 : _a.name;
88
+ (0, utils_1.log)(this.exportConfig, `Exporting ${appName} app and it's config.`, 'info');
89
+ await sdkClient
90
+ .organization(this.exportConfig.org_uid)
91
+ .app((_b = appInstallation === null || appInstallation === void 0 ? void 0 : appInstallation.manifest) === null || _b === void 0 ? void 0 : _b.uid)
92
+ .installation(appInstallation === null || appInstallation === void 0 ? void 0 : appInstallation.uid)
93
+ .installationData()
94
+ .then(async (result) => {
95
+ const { data, error } = result;
96
+ if ((0, has_1.default)(data, 'server_configuration')) {
97
+ if (!this.nodeCrypto && (0, has_1.default)(data, 'server_configuration')) {
98
+ this.nodeCrypto = await (0, utils_1.createNodeCryptoInstance)(this.exportConfig);
99
+ }
100
+ if (!(0, isEmpty_1.default)(data === null || data === void 0 ? void 0 : data.server_configuration)) {
101
+ this.installedApps[index]['server_configuration'] = this.nodeCrypto.encrypt(data.server_configuration);
102
+ (0, utils_1.log)(this.exportConfig, `Exported ${appName} app and it's config.`, 'success');
103
+ }
104
+ else {
105
+ (0, utils_1.log)(this.exportConfig, `Exported ${appName} app`, 'success');
106
+ }
107
+ }
108
+ else if (error) {
109
+ (0, utils_1.log)(this.exportConfig, `Error on exporting ${appName} app and it's config.`, 'error');
110
+ (0, utils_1.log)(this.exportConfig, error, 'error');
111
+ }
112
+ })
113
+ .catch((error) => {
114
+ (0, utils_1.log)(this.exportConfig, `Failed to export ${appName} app config ${(0, utils_1.formatError)(error)}`, 'error');
115
+ (0, utils_1.log)(this.exportConfig, error, 'error');
116
+ });
117
+ }
118
+ }
119
+ exports.default = ExportMarketplaceApps;
@@ -0,0 +1,12 @@
1
+ import BaseClass from './base-class';
2
+ import { ModuleClassParams } from '../../types';
3
+ export default class ExportStack extends BaseClass {
4
+ private stackConfig;
5
+ private stackFolderPath;
6
+ private qs;
7
+ constructor({ exportConfig, stackAPIClient }: ModuleClassParams);
8
+ start(): Promise<void>;
9
+ getStack(): Promise<any>;
10
+ getLocales(skip?: number): Promise<any>;
11
+ exportStack(): Promise<any>;
12
+ }
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const find_1 = tslib_1.__importDefault(require("lodash/find"));
5
+ const node_path_1 = require("node:path");
6
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
7
+ const config_1 = tslib_1.__importDefault(require("../../config"));
8
+ const base_class_1 = tslib_1.__importDefault(require("./base-class"));
9
+ const utils_1 = require("../../utils");
10
+ class ExportStack extends base_class_1.default {
11
+ constructor({ exportConfig, stackAPIClient }) {
12
+ super({ exportConfig, stackAPIClient });
13
+ this.stackConfig = config_1.default.modules.stack;
14
+ this.qs = { include_count: true };
15
+ this.stackFolderPath = (0, node_path_1.resolve)(this.exportConfig.data, this.stackConfig.dirName);
16
+ }
17
+ async start() {
18
+ if ((0, cli_utilities_1.isAuthenticated)()) {
19
+ const stackData = await this.getStack();
20
+ if (stackData === null || stackData === void 0 ? void 0 : stackData.org_uid) {
21
+ this.exportConfig.org_uid = stackData.org_uid;
22
+ this.exportConfig.sourceStackName = stackData.name;
23
+ }
24
+ }
25
+ if (!this.exportConfig.preserveStackVersion && !this.exportConfig.hasOwnProperty('master_locale')) {
26
+ //fetch master locale details
27
+ return this.getLocales();
28
+ }
29
+ else if (this.exportConfig.preserveStackVersion) {
30
+ return this.exportStack();
31
+ }
32
+ }
33
+ async getStack() {
34
+ const tempAPIClient = await (0, cli_utilities_1.managementSDKClient)({ host: this.exportConfig.host });
35
+ return await tempAPIClient
36
+ .stack({ api_key: this.exportConfig.source_stack })
37
+ .fetch()
38
+ .catch((error) => {
39
+ (0, utils_1.log)(this.exportConfig, `Failed to export stack. ${(0, utils_1.formatError)(error)}`, 'error');
40
+ });
41
+ }
42
+ async getLocales(skip = 0) {
43
+ if (skip) {
44
+ this.qs.skip = skip;
45
+ }
46
+ return await this.stack
47
+ .locale()
48
+ .query(this.qs)
49
+ .find()
50
+ .then(async (data) => {
51
+ const { items, count } = data;
52
+ if (items === null || items === void 0 ? void 0 : items.length) {
53
+ skip += this.stackConfig.limit || 100;
54
+ const masterLocalObj = (0, find_1.default)(items, (locale) => {
55
+ if (locale.fallback_locale === null) {
56
+ return locale;
57
+ }
58
+ });
59
+ if (masterLocalObj) {
60
+ return masterLocalObj;
61
+ }
62
+ else if (skip >= count) {
63
+ (0, utils_1.log)(this.exportConfig, 'Master locale not found', 'error');
64
+ return;
65
+ }
66
+ else {
67
+ return await this.getLocales(skip);
68
+ }
69
+ }
70
+ })
71
+ .catch((error) => {
72
+ (0, utils_1.log)(this.exportConfig, `Failed to export locales. ${(0, utils_1.formatError)(error)}`, 'error');
73
+ (0, utils_1.log)(this.exportConfig, error, 'error');
74
+ });
75
+ }
76
+ async exportStack() {
77
+ (0, utils_1.log)(this.exportConfig, 'Exporting stack details', 'success');
78
+ await utils_1.fsUtil.makeDirectory(this.stackFolderPath);
79
+ return this.stack
80
+ .fetch()
81
+ .then((resp) => {
82
+ utils_1.fsUtil.writeFile((0, node_path_1.resolve)(this.stackFolderPath, this.stackConfig.fileName), resp);
83
+ (0, utils_1.log)(this.exportConfig, 'Exported stack details successfully!', 'success');
84
+ return resp;
85
+ })
86
+ .catch((error) => {
87
+ (0, utils_1.log)(this.exportConfig, `Failed to export stack. ${(0, utils_1.formatError)(error)}`, 'error');
88
+ });
89
+ }
90
+ }
91
+ exports.default = ExportStack;
@@ -0,0 +1,12 @@
1
+ import BaseClass from './base-class';
2
+ import { ModuleClassParams } from '../../types';
3
+ export default class ExportWebhooks extends BaseClass {
4
+ private webhooks;
5
+ private webhookConfig;
6
+ webhooksFolderPath: string;
7
+ private qs;
8
+ constructor({ exportConfig, stackAPIClient }: ModuleClassParams);
9
+ start(): Promise<void>;
10
+ getWebhooks(skip?: number): Promise<void>;
11
+ sanitizeAttribs(webhooks: Record<string, string>[]): void;
12
+ }
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
5
+ const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
6
+ const node_path_1 = require("node:path");
7
+ const config_1 = tslib_1.__importDefault(require("../../config"));
8
+ const base_class_1 = tslib_1.__importDefault(require("./base-class"));
9
+ const utils_1 = require("../../utils");
10
+ class ExportWebhooks extends base_class_1.default {
11
+ constructor({ exportConfig, stackAPIClient }) {
12
+ super({ exportConfig, stackAPIClient });
13
+ this.webhooks = {};
14
+ this.webhookConfig = config_1.default.modules.webhooks;
15
+ this.qs = { include_count: true, asc: 'updated_at' };
16
+ }
17
+ async start() {
18
+ (0, utils_1.log)(this.exportConfig, 'Starting webhooks export', 'info');
19
+ this.webhooksFolderPath = (0, node_path_1.resolve)(this.exportConfig.data, this.exportConfig.branchName || '', this.webhookConfig.dirName);
20
+ await utils_1.fsUtil.makeDirectory(this.webhooksFolderPath);
21
+ await this.getWebhooks();
22
+ if (this.webhooks === undefined || (0, isEmpty_1.default)(this.webhooks)) {
23
+ (0, utils_1.log)(this.exportConfig, 'No webhooks found', 'info');
24
+ }
25
+ else {
26
+ utils_1.fsUtil.writeFile((0, node_path_1.resolve)(this.webhooksFolderPath, this.webhookConfig.fileName), this.webhooks);
27
+ (0, utils_1.log)(this.exportConfig, 'All the webhooks have been exported successfully!', 'success');
28
+ }
29
+ }
30
+ async getWebhooks(skip = 0) {
31
+ if (skip) {
32
+ this.qs.skip = skip;
33
+ }
34
+ await this.stack
35
+ .webhook()
36
+ .fetchAll(this.qs)
37
+ .then(async (data) => {
38
+ const { items, count } = data;
39
+ if (items === null || items === void 0 ? void 0 : items.length) {
40
+ this.sanitizeAttribs(items);
41
+ skip += this.webhookConfig.limit || 100;
42
+ if (skip >= count) {
43
+ return;
44
+ }
45
+ return await this.getWebhooks(skip);
46
+ }
47
+ })
48
+ .catch((error) => {
49
+ (0, utils_1.log)(this.exportConfig, `Failed to export webhooks.${(0, utils_1.formatError)(error)}`, 'error');
50
+ (0, utils_1.log)(this.exportConfig, error, 'error');
51
+ });
52
+ }
53
+ sanitizeAttribs(webhooks) {
54
+ var _a;
55
+ for (let index = 0; index < (webhooks === null || webhooks === void 0 ? void 0 : webhooks.length); index++) {
56
+ const webhookUid = webhooks[index].uid;
57
+ const webhookName = (_a = webhooks[index]) === null || _a === void 0 ? void 0 : _a.name;
58
+ this.webhooks[webhookUid] = (0, omit_1.default)(webhooks[index], ['SYS_ACL']);
59
+ (0, utils_1.log)(this.exportConfig, `'${webhookName}' webhook was exported successfully`, 'success');
60
+ }
61
+ }
62
+ }
63
+ exports.default = ExportWebhooks;
@@ -0,0 +1,14 @@
1
+ import BaseClass from './base-class';
2
+ import { ModuleClassParams } from '../../types';
3
+ export default class ExportWorkFlows extends BaseClass {
4
+ private workflows;
5
+ private workflowConfig;
6
+ webhooksFolderPath: string;
7
+ private qs;
8
+ constructor({ exportConfig, stackAPIClient }: ModuleClassParams);
9
+ start(): Promise<void>;
10
+ getWorkflows(skip?: number): Promise<void>;
11
+ sanitizeAttribs(workflows: Record<string, string>[]): Promise<void>;
12
+ getWorkflowRoles(workflow: Record<string, any>): Promise<void>;
13
+ getRoles(roleUid: number): Promise<any>;
14
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
5
+ const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
6
+ const node_path_1 = require("node:path");
7
+ const config_1 = tslib_1.__importDefault(require("../../config"));
8
+ const base_class_1 = tslib_1.__importDefault(require("./base-class"));
9
+ const utils_1 = require("../../utils");
10
+ class ExportWorkFlows extends base_class_1.default {
11
+ constructor({ exportConfig, stackAPIClient }) {
12
+ super({ exportConfig, stackAPIClient });
13
+ this.workflows = {};
14
+ this.workflowConfig = config_1.default.modules.workflows;
15
+ this.qs = { include_count: true };
16
+ }
17
+ async start() {
18
+ (0, utils_1.log)(this.exportConfig, 'Starting workflows export', 'info');
19
+ this.webhooksFolderPath = (0, node_path_1.resolve)(this.exportConfig.data, this.exportConfig.branchName || '', this.workflowConfig.dirName);
20
+ await utils_1.fsUtil.makeDirectory(this.webhooksFolderPath);
21
+ await this.getWorkflows();
22
+ if (this.workflows === undefined || (0, isEmpty_1.default)(this.workflows)) {
23
+ (0, utils_1.log)(this.exportConfig, 'No workflows found', 'info');
24
+ }
25
+ else {
26
+ utils_1.fsUtil.writeFile((0, node_path_1.resolve)(this.webhooksFolderPath, this.workflowConfig.fileName), this.workflows);
27
+ (0, utils_1.log)(this.exportConfig, 'All the workflows have been exported successfully!', 'success');
28
+ }
29
+ }
30
+ async getWorkflows(skip = 0) {
31
+ if (skip) {
32
+ this.qs.skip = skip;
33
+ }
34
+ await this.stack
35
+ .workflow()
36
+ .fetchAll(this.qs)
37
+ .then(async (data) => {
38
+ const { items, count } = data;
39
+ if (items === null || items === void 0 ? void 0 : items.length) {
40
+ await this.sanitizeAttribs(items);
41
+ skip += this.workflowConfig.limit || 100;
42
+ if (skip >= count) {
43
+ return;
44
+ }
45
+ return await this.getWorkflows(skip);
46
+ }
47
+ })
48
+ .catch((error) => {
49
+ (0, utils_1.log)(this.exportConfig, `Failed to export workflows.${(0, utils_1.formatError)(error)}`, 'error');
50
+ (0, utils_1.log)(this.exportConfig, error, 'error');
51
+ });
52
+ }
53
+ async sanitizeAttribs(workflows) {
54
+ var _a;
55
+ for (let index = 0; index < (workflows === null || workflows === void 0 ? void 0 : workflows.length); index++) {
56
+ await this.getWorkflowRoles(workflows[index]);
57
+ const workflowUid = workflows[index].uid;
58
+ const workflowName = ((_a = workflows[index]) === null || _a === void 0 ? void 0 : _a.name) || '';
59
+ this.workflows[workflowUid] = (0, omit_1.default)(workflows[index], this.workflowConfig.invalidKeys);
60
+ (0, utils_1.log)(this.exportConfig, `'${workflowName}' workflow was exported successfully`, 'success');
61
+ }
62
+ }
63
+ async getWorkflowRoles(workflow) {
64
+ var _a, _b, _c;
65
+ for (const stage of workflow === null || workflow === void 0 ? void 0 : workflow.workflow_stages) {
66
+ for (let i = 0; i < ((_c = (_b = (_a = stage === null || stage === void 0 ? void 0 : stage.SYS_ACL) === null || _a === void 0 ? void 0 : _a.roles) === null || _b === void 0 ? void 0 : _b.uids) === null || _c === void 0 ? void 0 : _c.length); i++) {
67
+ const roleUid = stage.SYS_ACL.roles.uids[i];
68
+ const roleData = await this.getRoles(roleUid);
69
+ stage.SYS_ACL.roles.uids[i] = roleData;
70
+ }
71
+ }
72
+ }
73
+ async getRoles(roleUid) {
74
+ return await this.stack
75
+ .role(roleUid)
76
+ .fetch({ include_rules: true, include_permissions: true })
77
+ .then((data) => data)
78
+ .catch((err) => (0, utils_1.log)(this.exportConfig, `Failed to fetch roles.${(0, utils_1.formatError)(err)}`, 'error'));
79
+ }
80
+ }
81
+ exports.default = ExportWorkFlows;
@@ -1,5 +1,6 @@
1
1
  const path = require('path');
2
2
  const chalk = require('chalk');
3
+ const { values } = require('lodash');
3
4
  const { executeTask, formatError, fileHelper, log } = require('../../utils');
4
5
  class EntriesExport {
5
6
  constructor(exportConfig, stackAPIClient) {
@@ -31,7 +32,7 @@ class EntriesExport {
31
32
  log(this.exportConfig, `Exported entries of type '${requestOption.content_type}' locale '${requestOption.locale}'`, 'success');
32
33
  if (this.exportConfig.versioning) {
33
34
  log(this.exportConfig, `Started export versioned entries of type '${requestOption.content_type}' locale '${requestOption.locale}'`, 'info');
34
- for (let entry of entries) {
35
+ for (let entry of values(entries)) {
35
36
  const versionedEntries = await this.getEntryByVersion(Object.assign(Object.assign({}, requestOption), { uid: entry.uid }), entry._version);
36
37
  let versionedEntryPath = path.join(this.entriesRootPath, requestOption.locale, requestOption.content_type, entry.uid);
37
38
  await fileHelper.makeDirectory(versionedEntryPath);
@@ -1 +1,2 @@
1
- export default function startModuleExport(modulePayload: any): Promise<any>;
1
+ export = startModuleExport;
2
+ declare function startModuleExport(modulePayload: any): Promise<any>;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
2
  if (k2 === undefined) k2 = k;
4
3
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -22,12 +21,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
21
  __setModuleDefault(result, mod);
23
22
  return result;
24
23
  };
25
- var _a;
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
24
  async function startModuleExport(modulePayload) {
25
+ var _a;
28
26
  const { moduleName, exportConfig, stackAPIClient } = modulePayload;
29
- const { default: ModuleRunner } = await (_a = `./${moduleName}`, Promise.resolve().then(() => __importStar(require(_a))));
27
+ const { default: ModuleRunner } = await (_a = `./${moduleName}.js`, Promise.resolve().then(() => __importStar(require(_a))));
30
28
  const moduleRunner = new ModuleRunner(exportConfig, stackAPIClient);
31
29
  return moduleRunner.start();
32
30
  }
33
- exports.default = startModuleExport;
31
+ module.exports = startModuleExport;
@@ -14,7 +14,6 @@ declare class ExportMarketplaceApps {
14
14
  };
15
15
  start(): Promise<void>;
16
16
  getOrgUid(): Promise<void>;
17
- createNodeCryptoInstance(): Promise<void>;
18
17
  exportInstalledExtensions(): Promise<void>;
19
18
  getAllStackSpecificApps(listOfApps?: any[], skip?: number): any;
20
19
  getAppConfigurations(sdkClient: any, installedApps: any, [index, appInstallation]: [any, any]): Promise<void>;