@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
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.6.1 linux-x64 node-v18.16.1
51
+ @contentstack/cli-cm-export/1.8.0 linux-x64 node-v18.17.1
52
52
  $ csdx --help [COMMAND]
53
53
  USAGE
54
54
  $ csdx COMMAND
@@ -60,7 +60,7 @@ const config = {
60
60
  labels: {
61
61
  dirName: 'labels',
62
62
  fileName: 'labels.json',
63
- invalidKeys: ['stackHeaders', 'uid', 'urlPath', 'created_at', 'updated_at', 'created_by', 'updated_by'],
63
+ invalidKeys: ['stackHeaders', 'urlPath', 'created_at', 'updated_at', 'created_by', 'updated_by'],
64
64
  },
65
65
  webhooks: {
66
66
  dirName: 'webhooks',
@@ -137,6 +137,7 @@ const config = {
137
137
  // total no of entries fetched in each content type in a single call
138
138
  limit: 100,
139
139
  dependencies: ['locales', 'content-types'],
140
+ exportVersions: false,
140
141
  },
141
142
  extensions: {
142
143
  dirName: 'extensions',
@@ -368,7 +369,20 @@ const config = {
368
369
  'xh',
369
370
  'zu',
370
371
  ],
371
- updatedModules: ['assets', 'locales'],
372
+ updatedModules: [
373
+ 'assets',
374
+ 'locales',
375
+ 'extensions',
376
+ 'marketplace-apps',
377
+ 'labels',
378
+ 'webhooks',
379
+ 'custom-roles',
380
+ 'global-fields',
381
+ 'content-types',
382
+ 'entries',
383
+ 'workflows',
384
+ 'stack',
385
+ ],
372
386
  apis: {
373
387
  userSession: '/user-session/',
374
388
  globalfields: '/global_fields/',
@@ -18,11 +18,12 @@ export type EnvType = {
18
18
  export type CustomPromiseHandlerInput = {
19
19
  index: number;
20
20
  batchIndex: number;
21
+ element?: Record<string, any>;
21
22
  apiParams?: ApiOptions;
22
23
  isLastRequest: boolean;
23
24
  };
24
25
  export type CustomPromiseHandler = (input: CustomPromiseHandlerInput) => Promise<any>;
25
- export type ApiModuleType = 'stack' | 'asset' | 'assets' | 'entry' | 'entries' | 'content-type' | 'content-types' | 'stacks' | 'download-asset';
26
+ export type ApiModuleType = 'stack' | 'asset' | 'assets' | 'entry' | 'entries' | 'content-type' | 'content-types' | 'stacks' | 'versioned-entries' | 'download-asset';
26
27
  export default abstract class BaseClass {
27
28
  readonly client: any;
28
29
  exportConfig: ExportConfig;
@@ -45,6 +45,7 @@ class BaseClass {
45
45
  if (promisifyHandler instanceof Function) {
46
46
  promise = promisifyHandler({
47
47
  apiParams,
48
+ element,
48
49
  isLastRequest,
49
50
  index: Number(index),
50
51
  batchIndex: Number(batchIndex),
@@ -0,0 +1,15 @@
1
+ import { ExportConfig, ModuleClassParams } from '../../types';
2
+ import BaseClass from './base-class';
3
+ export default class ContentTypesExport extends BaseClass {
4
+ private stackAPIClient;
5
+ exportConfig: ExportConfig;
6
+ private qs;
7
+ private contentTypesConfig;
8
+ private contentTypesDirPath;
9
+ private contentTypes;
10
+ constructor({ exportConfig, stackAPIClient }: ModuleClassParams);
11
+ start(): Promise<void>;
12
+ getContentTypes(skip?: number): Promise<any>;
13
+ sanitizeAttribs(contentTypes: Record<string, unknown>[]): Record<string, unknown>[];
14
+ writeContentTypes(contentTypes: Record<string, unknown>[]): Promise<void>;
15
+ }
@@ -0,0 +1,72 @@
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 ContentTypesExport extends base_class_1.default {
8
+ constructor({ exportConfig, stackAPIClient }) {
9
+ super({ exportConfig, stackAPIClient });
10
+ this.stackAPIClient = stackAPIClient;
11
+ this.contentTypesConfig = exportConfig.modules['content-types'];
12
+ this.qs = {
13
+ include_count: true,
14
+ asc: 'updated_at',
15
+ limit: this.contentTypesConfig.limit,
16
+ include_global_field_schema: true,
17
+ };
18
+ this.contentTypesDirPath = path.resolve(exportConfig.data, exportConfig.branchName || '', this.contentTypesConfig.dirName);
19
+ this.contentTypes = [];
20
+ }
21
+ async start() {
22
+ try {
23
+ (0, utils_1.log)(this.exportConfig, 'Starting content type export', 'success');
24
+ await utils_1.fsUtil.makeDirectory(this.contentTypesDirPath);
25
+ await this.getContentTypes();
26
+ await this.writeContentTypes(this.contentTypes);
27
+ (0, utils_1.log)(this.exportConfig, 'Content type(s) exported successfully', 'success');
28
+ }
29
+ catch (error) {
30
+ (0, utils_1.log)(this.exportConfig, `Failed to export content types ${(0, utils_1.formatError)(error)}`, 'error');
31
+ throw new Error('Failed to export content types');
32
+ }
33
+ }
34
+ async getContentTypes(skip = 0) {
35
+ if (skip) {
36
+ this.qs.skip = skip;
37
+ }
38
+ const contentTypeSearchResponse = await this.stackAPIClient.contentType().query(this.qs).find();
39
+ if (Array.isArray(contentTypeSearchResponse.items) && contentTypeSearchResponse.items.length > 0) {
40
+ let updatedContentTypes = this.sanitizeAttribs(contentTypeSearchResponse.items);
41
+ this.contentTypes.push(...updatedContentTypes);
42
+ skip += this.contentTypesConfig.limit || 100;
43
+ if (skip >= contentTypeSearchResponse.count) {
44
+ return;
45
+ }
46
+ return await this.getContentTypes(skip);
47
+ }
48
+ else {
49
+ (0, utils_1.log)(this.exportConfig, 'No content types returned for the given query', 'info');
50
+ }
51
+ }
52
+ sanitizeAttribs(contentTypes) {
53
+ let updatedContentTypes = [];
54
+ contentTypes.forEach((contentType) => {
55
+ for (let key in contentType) {
56
+ if (this.contentTypesConfig.validKeys.indexOf(key) === -1) {
57
+ delete contentType[key];
58
+ }
59
+ }
60
+ updatedContentTypes.push(contentType);
61
+ });
62
+ return updatedContentTypes;
63
+ }
64
+ async writeContentTypes(contentTypes) {
65
+ function write(contentType) {
66
+ return utils_1.fsUtil.writeFile(path.join(this.contentTypesDirPath, `${contentType.uid === 'schema' ? 'schema|1' : contentType.uid}.json`), contentType);
67
+ }
68
+ await (0, utils_1.executeTask)(contentTypes, write.bind(this), { concurrency: this.exportConfig.writeConcurrency });
69
+ return utils_1.fsUtil.writeFile(path.join(this.contentTypesDirPath, 'schema.json'), contentTypes);
70
+ }
71
+ }
72
+ exports.default = ContentTypesExport;
@@ -0,0 +1,16 @@
1
+ import BaseClass from './base-class';
2
+ import { ModuleClassParams } from '../../types';
3
+ export default class ExportCustomRoles extends BaseClass {
4
+ private customRoles;
5
+ private existingRoles;
6
+ private customRolesConfig;
7
+ private sourceLocalesMap;
8
+ private localesMap;
9
+ rolesFolderPath: string;
10
+ customRolesLocalesFilepath: string;
11
+ constructor({ exportConfig, stackAPIClient }: ModuleClassParams);
12
+ start(): Promise<void>;
13
+ getCustomRoles(): Promise<void>;
14
+ getLocales(): Promise<void>;
15
+ getCustomRolesLocales(): Promise<void>;
16
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const keys_1 = tslib_1.__importDefault(require("lodash/keys"));
5
+ const find_1 = tslib_1.__importDefault(require("lodash/find"));
6
+ const forEach_1 = tslib_1.__importDefault(require("lodash/forEach"));
7
+ const values_1 = tslib_1.__importDefault(require("lodash/values"));
8
+ const node_path_1 = require("node:path");
9
+ const config_1 = tslib_1.__importDefault(require("../../config"));
10
+ const base_class_1 = tslib_1.__importDefault(require("./base-class"));
11
+ const utils_1 = require("../../utils");
12
+ class ExportCustomRoles extends base_class_1.default {
13
+ constructor({ exportConfig, stackAPIClient }) {
14
+ super({ exportConfig, stackAPIClient });
15
+ this.customRoles = {};
16
+ this.customRolesConfig = config_1.default.modules.customRoles;
17
+ this.existingRoles = { Admin: 1, Developer: 1, 'Content Manager': 1 };
18
+ this.localesMap = {};
19
+ this.sourceLocalesMap = {};
20
+ }
21
+ async start() {
22
+ (0, utils_1.log)(this.exportConfig, 'Starting custom roles export', 'info');
23
+ this.rolesFolderPath = (0, node_path_1.resolve)(this.exportConfig.data, this.exportConfig.branchName || '', this.customRolesConfig.dirName);
24
+ await utils_1.fsUtil.makeDirectory(this.rolesFolderPath);
25
+ this.customRolesLocalesFilepath = (0, node_path_1.resolve)(this.rolesFolderPath, this.customRolesConfig.customRolesLocalesFileName);
26
+ await this.getCustomRoles();
27
+ await this.getLocales();
28
+ await this.getCustomRolesLocales();
29
+ }
30
+ async getCustomRoles() {
31
+ const roles = await this.stack
32
+ .role()
33
+ .fetchAll({ include_rules: true, include_permissions: true })
34
+ .then((data) => data)
35
+ .catch((err) => (0, utils_1.log)(this.exportConfig, `Failed to fetch roles. ${(0, utils_1.formatError)(err)}`, 'error'));
36
+ const customRoles = roles.items.filter((role) => !this.existingRoles[role.name]);
37
+ if (!customRoles.length) {
38
+ (0, utils_1.log)(this.exportConfig, 'No custom roles were found in the Stack', 'info');
39
+ return;
40
+ }
41
+ customRoles.forEach((role) => {
42
+ (0, utils_1.log)(this.exportConfig, `'${role === null || role === void 0 ? void 0 : role.name}' role was exported successfully`, 'info');
43
+ this.customRoles[role.uid] = role;
44
+ });
45
+ utils_1.fsUtil.writeFile((0, node_path_1.resolve)(this.rolesFolderPath, this.customRolesConfig.fileName), this.customRoles);
46
+ }
47
+ async getLocales() {
48
+ const locales = await this.stack
49
+ .locale()
50
+ .query({})
51
+ .find()
52
+ .then((data) => data)
53
+ .catch((err) => (0, utils_1.log)(this.exportConfig, `Failed to fetch locales. ${(0, utils_1.formatError)(err)}`, 'error'));
54
+ for (const locale of locales.items) {
55
+ this.sourceLocalesMap[locale.uid] = locale;
56
+ }
57
+ }
58
+ async getCustomRolesLocales() {
59
+ var _a, _b;
60
+ for (const role of (0, values_1.default)(this.customRoles)) {
61
+ const customRole = role;
62
+ const rulesLocales = (0, find_1.default)(customRole.rules, (rule) => rule.module === 'locale');
63
+ if ((_a = rulesLocales === null || rulesLocales === void 0 ? void 0 : rulesLocales.locales) === null || _a === void 0 ? void 0 : _a.length) {
64
+ (0, forEach_1.default)(rulesLocales.locales, (locale) => {
65
+ this.localesMap[locale] = 1;
66
+ });
67
+ }
68
+ }
69
+ if ((_b = (0, keys_1.default)(this.localesMap)) === null || _b === void 0 ? void 0 : _b.length) {
70
+ for (const locale in this.localesMap) {
71
+ if (this.sourceLocalesMap[locale] !== undefined) {
72
+ const sourceLocale = this.sourceLocalesMap[locale];
73
+ sourceLocale === null || sourceLocale === void 0 ? true : delete sourceLocale.stackHeaders;
74
+ }
75
+ this.localesMap[locale] = this.sourceLocalesMap[locale];
76
+ }
77
+ utils_1.fsUtil.writeFile(this.customRolesLocalesFilepath, this.localesMap);
78
+ }
79
+ }
80
+ }
81
+ exports.default = ExportCustomRoles;
@@ -0,0 +1,26 @@
1
+ import { ExportConfig, ModuleClassParams } from '../../types';
2
+ import BaseClass, { ApiOptions } from './base-class';
3
+ export default class EntriesExport extends BaseClass {
4
+ private stackAPIClient;
5
+ exportConfig: ExportConfig;
6
+ private entriesConfig;
7
+ private entriesDirPath;
8
+ private localesFilePath;
9
+ private schemaFilePath;
10
+ private entriesFileHelper;
11
+ constructor({ exportConfig, stackAPIClient }: ModuleClassParams);
12
+ start(): Promise<void>;
13
+ createRequestObjects(locales: Array<Record<string, unknown>>, contentTypes: Array<Record<string, unknown>>): Array<Record<string, any>>;
14
+ getEntries(options: Record<string, any>): Promise<any>;
15
+ fetchEntriesVersions(entries: any, options: {
16
+ locale: string;
17
+ contentType: string;
18
+ versionedEntryPath: string;
19
+ }): Promise<void>;
20
+ entryVersionHandler({ apiParams, element: entry, }: {
21
+ apiParams: ApiOptions;
22
+ element: Record<string, string>;
23
+ isLastRequest: boolean;
24
+ }): Promise<unknown>;
25
+ getEntryByVersion(options: any, entry: Record<string, any>, entries?: Array<Record<string, any>>): Promise<any[]>;
26
+ }
@@ -0,0 +1,167 @@
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 cli_utilities_1 = require("@contentstack/cli-utilities");
6
+ const utils_1 = require("../../utils");
7
+ const base_class_1 = tslib_1.__importDefault(require("./base-class"));
8
+ class EntriesExport extends base_class_1.default {
9
+ constructor({ exportConfig, stackAPIClient }) {
10
+ super({ exportConfig, stackAPIClient });
11
+ this.stackAPIClient = stackAPIClient;
12
+ this.exportConfig = exportConfig;
13
+ this.entriesConfig = exportConfig.modules.entries;
14
+ this.entriesDirPath = path.resolve(exportConfig.data, exportConfig.branchName || '', this.entriesConfig.dirName);
15
+ this.localesFilePath = path.resolve(exportConfig.data, exportConfig.branchName || '', exportConfig.modules.locales.dirName, exportConfig.modules.locales.fileName);
16
+ this.schemaFilePath = path.resolve(exportConfig.data, exportConfig.branchName || '', exportConfig.modules.content_types.dirName, 'schema.json');
17
+ }
18
+ async start() {
19
+ var _a;
20
+ try {
21
+ (0, utils_1.log)(this.exportConfig, 'Starting entries export', 'info');
22
+ const locales = utils_1.fsUtil.readFile(this.localesFilePath);
23
+ const contentTypes = utils_1.fsUtil.readFile(this.schemaFilePath);
24
+ if (contentTypes.length === 0) {
25
+ (0, utils_1.log)(this.exportConfig, 'No content types found to export entries', 'info');
26
+ return;
27
+ }
28
+ const entryRequestOptions = this.createRequestObjects(locales, contentTypes);
29
+ for (let entryRequestOption of entryRequestOptions) {
30
+ (0, utils_1.log)(this.exportConfig, `Starting export of entries of content type - ${entryRequestOption.contentType} locale - ${entryRequestOption.locale}`, 'info');
31
+ await this.getEntries(entryRequestOption);
32
+ (_a = this.entriesFileHelper) === null || _a === void 0 ? void 0 : _a.completeFile(true);
33
+ (0, utils_1.log)(this.exportConfig, `Exported entries of type '${entryRequestOption.contentType}' locale '${entryRequestOption.locale}'`, 'success');
34
+ }
35
+ (0, utils_1.log)(this.exportConfig, 'Entries exported successfully', 'success');
36
+ }
37
+ catch (error) {
38
+ (0, utils_1.log)(this.exportConfig, `Failed to export entries ${(0, utils_1.formatError)(error)}`, 'error');
39
+ throw new Error('Failed to export entries');
40
+ }
41
+ }
42
+ createRequestObjects(locales, contentTypes) {
43
+ let requestObjects = [];
44
+ contentTypes.forEach((contentType) => {
45
+ if (Object.keys(locales).length !== 0) {
46
+ for (let locale in locales) {
47
+ requestObjects.push({
48
+ contentType: contentType.uid,
49
+ locale: locales[locale].code,
50
+ });
51
+ }
52
+ }
53
+ requestObjects.push({
54
+ contentType: contentType.uid,
55
+ locale: this.exportConfig.master_locale.code,
56
+ });
57
+ });
58
+ return requestObjects;
59
+ }
60
+ async getEntries(options) {
61
+ options.skip = options.skip || 0;
62
+ let requestObject = {
63
+ locale: options.locale,
64
+ skip: options.skip,
65
+ limit: this.entriesConfig.limit,
66
+ include_count: true,
67
+ include_publish_details: true,
68
+ query: {
69
+ locale: options.locale,
70
+ },
71
+ };
72
+ const entriesSearchResponse = await this.stackAPIClient
73
+ .contentType(options.contentType)
74
+ .entry()
75
+ .query(requestObject)
76
+ .find();
77
+ if (Array.isArray(entriesSearchResponse.items) && entriesSearchResponse.items.length > 0) {
78
+ if (options.skip === 0) {
79
+ const entryBasePath = path.join(this.entriesDirPath, options.contentType, options.locale);
80
+ await utils_1.fsUtil.makeDirectory(entryBasePath);
81
+ this.entriesFileHelper = new cli_utilities_1.FsUtility({
82
+ moduleName: 'entries',
83
+ indexFileName: 'index.json',
84
+ basePath: entryBasePath,
85
+ chunkFileSize: this.entriesConfig.chunkFileSize,
86
+ keepMetadata: false,
87
+ omitKeys: this.entriesConfig.invalidKeys,
88
+ });
89
+ }
90
+ this.entriesFileHelper.writeIntoFile(entriesSearchResponse.items, { mapKeyVal: true });
91
+ if (this.entriesConfig.exportVersions) {
92
+ let versionedEntryPath = path.join(this.entriesDirPath, options.contentType, options.locale, 'versions');
93
+ utils_1.fsUtil.makeDirectory(versionedEntryPath);
94
+ await this.fetchEntriesVersions(entriesSearchResponse.items, {
95
+ locale: options.locale,
96
+ contentType: options.contentType,
97
+ versionedEntryPath,
98
+ });
99
+ }
100
+ options.skip += this.entriesConfig.limit || 100;
101
+ if (options.skip >= entriesSearchResponse.count) {
102
+ return Promise.resolve(true);
103
+ }
104
+ return await this.getEntries(options);
105
+ }
106
+ }
107
+ async fetchEntriesVersions(entries, options) {
108
+ const onSuccess = ({ response, apiData: entry }) => {
109
+ utils_1.fsUtil.writeFile(path.join(options.versionedEntryPath, `${entry.uid}.json`), response);
110
+ (0, utils_1.log)(this.exportConfig, `Exported versioned entries of type '${options.contentType}' locale '${options.locale}'`, 'success');
111
+ };
112
+ const onReject = ({ error, apiData: { uid } = undefined }) => {
113
+ (0, utils_1.log)(this.exportConfig, `failed to export versions of entry ${uid}`, 'error');
114
+ (0, utils_1.log)(this.exportConfig, (0, utils_1.formatError)(error), 'error');
115
+ };
116
+ return await this.makeConcurrentCall({
117
+ apiBatches: [entries],
118
+ module: 'versioned-entries',
119
+ totalCount: entries.length,
120
+ concurrencyLimit: this.entriesConfig.batchLimit,
121
+ apiParams: {
122
+ module: 'versioned-entries',
123
+ queryParam: options,
124
+ resolve: onSuccess,
125
+ reject: onReject,
126
+ },
127
+ }, this.entryVersionHandler.bind(this));
128
+ }
129
+ async entryVersionHandler({ apiParams, element: entry, }) {
130
+ return new Promise(async (resolve, reject) => {
131
+ return await this.getEntryByVersion(apiParams.queryParam, entry)
132
+ .then((response) => {
133
+ apiParams.resolve({
134
+ response,
135
+ apiData: entry,
136
+ });
137
+ resolve(true);
138
+ })
139
+ .catch((error) => {
140
+ apiParams.reject({
141
+ error,
142
+ apiData: entry,
143
+ });
144
+ reject(true);
145
+ });
146
+ });
147
+ }
148
+ async getEntryByVersion(options, entry, entries = []) {
149
+ const queryRequestObject = {
150
+ locale: options.locale,
151
+ except: {
152
+ BASE: this.entriesConfig.invalidKeys,
153
+ },
154
+ version: entry._version,
155
+ };
156
+ const entryResponse = await this.stackAPIClient
157
+ .contentType(options.contentType)
158
+ .entry(entry.uid)
159
+ .fetch(queryRequestObject);
160
+ entries.push(entryResponse);
161
+ if (--entry._version > 0) {
162
+ return await this.getEntryByVersion(options, entry, entries);
163
+ }
164
+ return entries;
165
+ }
166
+ }
167
+ exports.default = EntriesExport;
@@ -0,0 +1,12 @@
1
+ import BaseClass from './base-class';
2
+ import { ModuleClassParams } from '../../types';
3
+ export default class ExportEnvironments extends BaseClass {
4
+ private environments;
5
+ private environmentConfig;
6
+ environmentsFolderPath: string;
7
+ private qs;
8
+ constructor({ exportConfig, stackAPIClient }: ModuleClassParams);
9
+ start(): Promise<void>;
10
+ getEnvironments(skip?: number): Promise<void>;
11
+ sanitizeAttribs(environments: 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 node_path_1 = require("node:path");
5
+ const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
6
+ const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
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 ExportEnvironments extends base_class_1.default {
11
+ constructor({ exportConfig, stackAPIClient }) {
12
+ super({ exportConfig, stackAPIClient });
13
+ this.environments = {};
14
+ this.environmentConfig = config_1.default.modules.environments;
15
+ this.qs = { include_count: true };
16
+ }
17
+ async start() {
18
+ (0, utils_1.log)(this.exportConfig, 'Starting environment export', 'info');
19
+ this.environmentsFolderPath = (0, node_path_1.resolve)(this.exportConfig.data, this.exportConfig.branchName || '', this.environmentConfig.dirName);
20
+ await utils_1.fsUtil.makeDirectory(this.environmentsFolderPath);
21
+ await this.getEnvironments();
22
+ if (this.environments === undefined || (0, isEmpty_1.default)(this.environments)) {
23
+ (0, utils_1.log)(this.exportConfig, 'No environments found', 'info');
24
+ }
25
+ else {
26
+ utils_1.fsUtil.writeFile((0, node_path_1.resolve)(this.environmentsFolderPath, this.environmentConfig.fileName), this.environments);
27
+ (0, utils_1.log)(this.exportConfig, 'All the environments have been exported successfully!', 'success');
28
+ }
29
+ }
30
+ async getEnvironments(skip = 0) {
31
+ if (skip) {
32
+ this.qs.skip = skip;
33
+ }
34
+ await this.stack
35
+ .environment()
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.environmentConfig.limit || 100;
43
+ if (skip >= count) {
44
+ return;
45
+ }
46
+ return await this.getEnvironments(skip);
47
+ }
48
+ })
49
+ .catch((error) => {
50
+ (0, utils_1.log)(this.exportConfig, `Failed to export environments. ${(0, utils_1.formatError)(error)}`, 'error');
51
+ (0, utils_1.log)(this.exportConfig, error, 'error');
52
+ });
53
+ }
54
+ sanitizeAttribs(environments) {
55
+ var _a;
56
+ for (let index = 0; index < (environments === null || environments === void 0 ? void 0 : environments.length); index++) {
57
+ const extUid = environments[index].uid;
58
+ const envName = (_a = environments[index]) === null || _a === void 0 ? void 0 : _a.name;
59
+ this.environments[extUid] = (0, omit_1.default)(environments[index], ['ACL']);
60
+ (0, utils_1.log)(this.exportConfig, `'${envName}' environment was exported successfully`, 'success');
61
+ }
62
+ }
63
+ }
64
+ exports.default = ExportEnvironments;
@@ -0,0 +1,12 @@
1
+ import BaseClass from './base-class';
2
+ import { ExtensionsConfig, ModuleClassParams } from '../../types';
3
+ export default class ExportExtensions extends BaseClass {
4
+ private extensionsFolderPath;
5
+ private extensions;
6
+ extensionConfig: ExtensionsConfig;
7
+ private qs;
8
+ constructor({ exportConfig, stackAPIClient }: ModuleClassParams);
9
+ start(): Promise<void>;
10
+ getExtensions(skip?: number): Promise<void>;
11
+ sanitizeAttribs(extensions: 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 ExportExtensions extends base_class_1.default {
11
+ constructor({ exportConfig, stackAPIClient }) {
12
+ super({ exportConfig, stackAPIClient });
13
+ this.extensions = {};
14
+ this.extensionConfig = config_1.default.modules.extensions;
15
+ this.qs = { include_count: true };
16
+ }
17
+ async start() {
18
+ (0, utils_1.log)(this.exportConfig, 'Starting extension export', 'info');
19
+ this.extensionsFolderPath = (0, node_path_1.resolve)(this.exportConfig.data, this.exportConfig.branchName || '', this.extensionConfig.dirName);
20
+ await utils_1.fsUtil.makeDirectory(this.extensionsFolderPath);
21
+ await this.getExtensions();
22
+ if (this.extensions === undefined || (0, isEmpty_1.default)(this.extensions)) {
23
+ (0, utils_1.log)(this.exportConfig, 'No extensions found', 'info');
24
+ }
25
+ else {
26
+ utils_1.fsUtil.writeFile((0, node_path_1.resolve)(this.extensionsFolderPath, this.extensionConfig.fileName), this.extensions);
27
+ (0, utils_1.log)(this.exportConfig, 'All the extensions have been exported successfully!', 'success');
28
+ }
29
+ }
30
+ async getExtensions(skip = 0) {
31
+ if (skip) {
32
+ this.qs.skip = skip;
33
+ }
34
+ await this.stack
35
+ .extension()
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.extensionConfig.limit || 100;
43
+ if (skip >= count) {
44
+ return;
45
+ }
46
+ return await this.getExtensions(skip);
47
+ }
48
+ })
49
+ .catch((error) => {
50
+ (0, utils_1.log)(this.exportConfig, `Failed to export extensions. ${(0, utils_1.formatError)(error)}`, 'error');
51
+ (0, utils_1.log)(this.exportConfig, error, 'error');
52
+ });
53
+ }
54
+ sanitizeAttribs(extensions) {
55
+ var _a;
56
+ for (let index = 0; index < (extensions === null || extensions === void 0 ? void 0 : extensions.length); index++) {
57
+ const extUid = extensions[index].uid;
58
+ const extTitle = (_a = extensions[index]) === null || _a === void 0 ? void 0 : _a.title;
59
+ this.extensions[extUid] = (0, omit_1.default)(extensions[index], ['SYS_ACL']);
60
+ (0, utils_1.log)(this.exportConfig, `'${extTitle}' extension was exported successfully`, 'success');
61
+ }
62
+ }
63
+ }
64
+ exports.default = ExportExtensions;
@@ -0,0 +1,14 @@
1
+ import { ExportConfig, ModuleClassParams } from '../../types';
2
+ import BaseClass from './base-class';
3
+ export default class GlobalFieldsExport extends BaseClass {
4
+ private stackAPIClient;
5
+ exportConfig: ExportConfig;
6
+ private qs;
7
+ private globalFieldsConfig;
8
+ private globalFieldsDirPath;
9
+ private globalFields;
10
+ constructor({ exportConfig, stackAPIClient }: ModuleClassParams);
11
+ start(): Promise<void>;
12
+ getGlobalFields(skip?: number): Promise<any>;
13
+ sanitizeAttribs(globalFields: Record<string, string>[]): void;
14
+ }