@contentstack/cli-audit 1.17.0 → 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.
Files changed (38) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +19 -23
  3. package/lib/audit-base-command.d.ts +4 -1
  4. package/lib/audit-base-command.js +85 -54
  5. package/lib/config/index.d.ts +0 -5
  6. package/lib/config/index.js +9 -16
  7. package/lib/messages/index.d.ts +0 -1
  8. package/lib/messages/index.js +1 -2
  9. package/lib/modules/assets.d.ts +6 -4
  10. package/lib/modules/assets.js +51 -30
  11. package/lib/modules/base-class.d.ts +24 -0
  12. package/lib/modules/base-class.js +54 -0
  13. package/lib/modules/content-types.d.ts +6 -4
  14. package/lib/modules/content-types.js +62 -40
  15. package/lib/modules/custom-roles.d.ts +4 -4
  16. package/lib/modules/custom-roles.js +82 -61
  17. package/lib/modules/entries.d.ts +5 -4
  18. package/lib/modules/entries.js +190 -168
  19. package/lib/modules/extensions.d.ts +4 -4
  20. package/lib/modules/extensions.js +78 -58
  21. package/lib/modules/field_rules.d.ts +4 -4
  22. package/lib/modules/field_rules.js +69 -52
  23. package/lib/modules/global-fields.d.ts +3 -1
  24. package/lib/modules/global-fields.js +4 -2
  25. package/lib/modules/index.d.ts +2 -2
  26. package/lib/modules/index.js +3 -3
  27. package/lib/modules/modulesData.js +8 -17
  28. package/lib/modules/workflows.d.ts +4 -4
  29. package/lib/modules/workflows.js +85 -68
  30. package/lib/types/content-types.d.ts +1 -2
  31. package/lib/types/content-types.js +0 -1
  32. package/lib/types/context.d.ts +5 -0
  33. package/oclif.manifest.json +3 -5
  34. package/package.json +4 -4
  35. package/lib/modules/composable-studio.d.ts +0 -40
  36. package/lib/modules/composable-studio.js +0 -307
  37. package/lib/types/composable-studio.d.ts +0 -25
  38. package/lib/types/composable-studio.js +0 -2
@@ -1,40 +0,0 @@
1
- import { ConfigType, ContentTypeStruct, CtConstructorParam, ModuleConstructorParam } from '../types';
2
- import auditConfig from '../config';
3
- import { ComposableStudioProject } from '../types/composable-studio';
4
- export default class ComposableStudio {
5
- protected fix: boolean;
6
- fileName: string;
7
- config: ConfigType;
8
- folderPath: string;
9
- composableStudioProjects: ComposableStudioProject[];
10
- ctSchema: ContentTypeStruct[];
11
- moduleName: keyof typeof auditConfig.moduleConfig;
12
- ctUidSet: Set<string>;
13
- environmentUidSet: Set<string>;
14
- localeCodeSet: Set<string>;
15
- projectsWithIssues: any[];
16
- composableStudioPath: string;
17
- private projectsWithIssuesMap;
18
- constructor({ fix, config, moduleName, ctSchema }: ModuleConstructorParam & Pick<CtConstructorParam, 'ctSchema'>);
19
- validateModules(moduleName: keyof typeof auditConfig.moduleConfig, moduleConfig: Record<string, unknown>): keyof typeof auditConfig.moduleConfig;
20
- /**
21
- * Load environments from the environments.json file
22
- */
23
- loadEnvironments(): Promise<void>;
24
- /**
25
- * Load locales from the locales.json and master-locale.json files
26
- */
27
- loadLocales(): Promise<void>;
28
- /**
29
- * Main run method to audit composable studio projects
30
- */
31
- run(): Promise<{}>;
32
- /**
33
- * Fix composable studio projects by removing invalid references
34
- */
35
- fixComposableStudioProjects(): Promise<void>;
36
- /**
37
- * Write fixed composable studio projects back to file
38
- */
39
- writeFixContent(fixedProjects: any): Promise<void>;
40
- }
@@ -1,307 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const path_1 = require("path");
4
- const fs_1 = require("fs");
5
- const cli_utilities_1 = require("@contentstack/cli-utilities");
6
- const messages_1 = require("../messages");
7
- class ComposableStudio {
8
- constructor({ fix, config, moduleName, ctSchema }) {
9
- this.config = config;
10
- this.fix = fix !== null && fix !== void 0 ? fix : false;
11
- this.ctSchema = ctSchema;
12
- this.composableStudioProjects = [];
13
- cli_utilities_1.log.debug(`Initializing ComposableStudio module`, this.config.auditContext);
14
- cli_utilities_1.log.debug(`Fix mode: ${this.fix}`, this.config.auditContext);
15
- cli_utilities_1.log.debug(`Content types count: ${ctSchema.length}`, this.config.auditContext);
16
- cli_utilities_1.log.debug(`Module name: ${moduleName}`, this.config.auditContext);
17
- this.moduleName = this.validateModules(moduleName, this.config.moduleConfig);
18
- this.fileName = config.moduleConfig[this.moduleName].fileName;
19
- cli_utilities_1.log.debug(`File name: ${this.fileName}`, this.config.auditContext);
20
- this.folderPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(config.basePath), (0, cli_utilities_1.sanitizePath)(config.moduleConfig[this.moduleName].dirName));
21
- cli_utilities_1.log.debug(`Folder path: ${this.folderPath}`, this.config.auditContext);
22
- this.ctUidSet = new Set();
23
- this.environmentUidSet = new Set();
24
- this.localeCodeSet = new Set();
25
- this.projectsWithIssues = [];
26
- this.projectsWithIssuesMap = new Map();
27
- this.composableStudioPath = '';
28
- cli_utilities_1.log.debug(`ComposableStudio module initialization completed`, this.config.auditContext);
29
- }
30
- validateModules(moduleName, moduleConfig) {
31
- cli_utilities_1.log.debug(`Validating module: ${moduleName}`, this.config.auditContext);
32
- cli_utilities_1.log.debug(`Available modules: ${Object.keys(moduleConfig).join(', ')}`, this.config.auditContext);
33
- if (Object.keys(moduleConfig).includes(moduleName)) {
34
- cli_utilities_1.log.debug(`Module ${moduleName} is valid`, this.config.auditContext);
35
- return moduleName;
36
- }
37
- cli_utilities_1.log.debug(`Module ${moduleName} not found, defaulting to 'composable-studio'`, this.config.auditContext);
38
- return 'composable-studio';
39
- }
40
- /**
41
- * Load environments from the environments.json file
42
- */
43
- async loadEnvironments() {
44
- cli_utilities_1.log.debug(`Loading environments`, this.config.auditContext);
45
- const environmentsPath = (0, path_1.resolve)(this.config.basePath, 'environments', 'environments.json');
46
- if ((0, fs_1.existsSync)(environmentsPath)) {
47
- cli_utilities_1.log.debug(`Environments file path: ${environmentsPath}`, this.config.auditContext);
48
- try {
49
- const environments = JSON.parse((0, fs_1.readFileSync)(environmentsPath, 'utf-8'));
50
- const envArray = Array.isArray(environments) ? environments : Object.values(environments);
51
- envArray.forEach((env) => {
52
- if (env.uid) {
53
- this.environmentUidSet.add(env.uid);
54
- }
55
- });
56
- cli_utilities_1.log.debug(`Loaded ${this.environmentUidSet.size} environments: ${Array.from(this.environmentUidSet).join(', ')}`, this.config.auditContext);
57
- }
58
- catch (error) {
59
- (0, cli_utilities_1.handleAndLogError)(error, this.config.auditContext, 'Failed to load environments');
60
- }
61
- }
62
- else {
63
- cli_utilities_1.log.debug(`Environments file not found at: ${environmentsPath}`, this.config.auditContext);
64
- }
65
- }
66
- /**
67
- * Load locales from the locales.json and master-locale.json files
68
- */
69
- async loadLocales() {
70
- cli_utilities_1.log.debug(`Loading locales`, this.config.auditContext);
71
- const localesPath = (0, path_1.resolve)(this.config.basePath, 'locales', 'locales.json');
72
- const masterLocalePath = (0, path_1.resolve)(this.config.basePath, 'locales', 'master-locale.json');
73
- // Load master locale
74
- if ((0, fs_1.existsSync)(masterLocalePath)) {
75
- cli_utilities_1.log.debug(`Master locale file path: ${masterLocalePath}`, this.config.auditContext);
76
- try {
77
- const masterLocales = JSON.parse((0, fs_1.readFileSync)(masterLocalePath, 'utf-8'));
78
- const localeArray = Array.isArray(masterLocales) ? masterLocales : Object.values(masterLocales);
79
- localeArray.forEach((locale) => {
80
- if (locale.code) {
81
- this.localeCodeSet.add(locale.code);
82
- }
83
- });
84
- cli_utilities_1.log.debug(`Loaded ${this.localeCodeSet.size} master locales`, this.config.auditContext);
85
- }
86
- catch (error) {
87
- (0, cli_utilities_1.handleAndLogError)(error, this.config.auditContext, 'Failed to load master locales');
88
- }
89
- }
90
- else {
91
- cli_utilities_1.log.debug(`Master locale file not found at: ${masterLocalePath}`, this.config.auditContext);
92
- }
93
- // Load additional locales
94
- if ((0, fs_1.existsSync)(localesPath)) {
95
- cli_utilities_1.log.debug(`Locales file path: ${localesPath}`, this.config.auditContext);
96
- try {
97
- const locales = JSON.parse((0, fs_1.readFileSync)(localesPath, 'utf-8'));
98
- const localeArray = Array.isArray(locales) ? locales : Object.values(locales);
99
- localeArray.forEach((locale) => {
100
- if (locale.code) {
101
- this.localeCodeSet.add(locale.code);
102
- }
103
- });
104
- cli_utilities_1.log.debug(`Total locales after loading additional locales: ${this.localeCodeSet.size}`, this.config.auditContext);
105
- }
106
- catch (error) {
107
- (0, cli_utilities_1.handleAndLogError)(error, this.config.auditContext, 'Failed to load additional locales');
108
- }
109
- }
110
- else {
111
- cli_utilities_1.log.debug(`Locales file not found at: ${localesPath}`, this.config.auditContext);
112
- }
113
- cli_utilities_1.log.debug(`Locale codes loaded: ${Array.from(this.localeCodeSet).join(', ')}`, this.config.auditContext);
114
- }
115
- /**
116
- * Main run method to audit composable studio projects
117
- */
118
- async run() {
119
- var _a, _b, _c, _d;
120
- cli_utilities_1.log.debug(`Starting ${this.moduleName} audit process`, this.config.auditContext);
121
- cli_utilities_1.log.debug(`Composable Studio folder path: ${this.folderPath}`, this.config.auditContext);
122
- cli_utilities_1.log.debug(`Fix mode: ${this.fix}`, this.config.auditContext);
123
- if (!(0, fs_1.existsSync)(this.folderPath)) {
124
- cli_utilities_1.log.debug(`Skipping ${this.moduleName} audit - path does not exist`, this.config.auditContext);
125
- cli_utilities_1.log.warn(`Skipping ${this.moduleName} audit`, this.config.auditContext);
126
- cli_utilities_1.cliux.print((0, messages_1.$t)(messages_1.auditMsg.NOT_VALID_PATH, { path: this.folderPath }), { color: 'yellow' });
127
- return {};
128
- }
129
- this.composableStudioPath = (0, path_1.join)(this.folderPath, this.fileName);
130
- cli_utilities_1.log.debug(`Composable Studio file path: ${this.composableStudioPath}`, this.config.auditContext);
131
- // Load composable studio projects
132
- cli_utilities_1.log.debug(`Loading composable studio projects from file`, this.config.auditContext);
133
- if ((0, fs_1.existsSync)(this.composableStudioPath)) {
134
- try {
135
- const projectsData = JSON.parse((0, fs_1.readFileSync)(this.composableStudioPath, 'utf-8'));
136
- this.composableStudioProjects = Array.isArray(projectsData) ? projectsData : [projectsData];
137
- cli_utilities_1.log.debug(`Loaded ${this.composableStudioProjects.length} composable studio projects`, this.config.auditContext);
138
- }
139
- catch (error) {
140
- (0, cli_utilities_1.handleAndLogError)(error, this.config.auditContext, 'Failed to load composable studio projects');
141
- return {};
142
- }
143
- }
144
- else {
145
- cli_utilities_1.log.debug(`Composable studio file not found`, this.config.auditContext);
146
- return {};
147
- }
148
- // Build content type UID set
149
- cli_utilities_1.log.debug(`Building content type UID set from ${this.ctSchema.length} content types`, this.config.auditContext);
150
- this.ctSchema.forEach((ct) => this.ctUidSet.add(ct.uid));
151
- cli_utilities_1.log.debug(`Content type UID set contains: ${Array.from(this.ctUidSet).join(', ')}`, this.config.auditContext);
152
- // Load environments and locales
153
- await this.loadEnvironments();
154
- await this.loadLocales();
155
- // Process each project
156
- cli_utilities_1.log.debug(`Processing ${this.composableStudioProjects.length} composable studio projects`, this.config.auditContext);
157
- for (const project of this.composableStudioProjects) {
158
- const { name, uid, contentTypeUid, settings } = project;
159
- cli_utilities_1.log.debug(`Processing composable studio project: ${name} (${uid})`, this.config.auditContext);
160
- cli_utilities_1.log.debug(`Content type UID: ${contentTypeUid}`, this.config.auditContext);
161
- cli_utilities_1.log.debug(`Environment: ${(_a = settings === null || settings === void 0 ? void 0 : settings.configuration) === null || _a === void 0 ? void 0 : _a.environment}`, this.config.auditContext);
162
- cli_utilities_1.log.debug(`Locale: ${(_b = settings === null || settings === void 0 ? void 0 : settings.configuration) === null || _b === void 0 ? void 0 : _b.locale}`, this.config.auditContext);
163
- let hasIssues = false;
164
- const issuesList = [];
165
- const invalidContentTypes = [];
166
- const invalidEnvironments = [];
167
- const invalidLocales = [];
168
- // Check content type
169
- if (contentTypeUid && !this.ctUidSet.has(contentTypeUid)) {
170
- cli_utilities_1.log.debug(`Content type ${contentTypeUid} not found in project ${name}`, this.config.auditContext);
171
- invalidContentTypes.push(contentTypeUid);
172
- issuesList.push(`Invalid contentTypeUid: ${contentTypeUid}`);
173
- hasIssues = true;
174
- }
175
- // Check environment
176
- if (((_c = settings === null || settings === void 0 ? void 0 : settings.configuration) === null || _c === void 0 ? void 0 : _c.environment) && !this.environmentUidSet.has(settings.configuration.environment)) {
177
- cli_utilities_1.log.debug(`Environment ${settings.configuration.environment} not found in project ${name}`, this.config.auditContext);
178
- invalidEnvironments.push(settings.configuration.environment);
179
- issuesList.push(`Invalid environment: ${settings.configuration.environment}`);
180
- hasIssues = true;
181
- }
182
- // Check locale
183
- if (((_d = settings === null || settings === void 0 ? void 0 : settings.configuration) === null || _d === void 0 ? void 0 : _d.locale) && !this.localeCodeSet.has(settings.configuration.locale)) {
184
- cli_utilities_1.log.debug(`Locale ${settings.configuration.locale} not found in project ${name}`, this.config.auditContext);
185
- invalidLocales.push(settings.configuration.locale);
186
- issuesList.push(`Invalid locale: ${settings.configuration.locale}`);
187
- hasIssues = true;
188
- }
189
- if (hasIssues) {
190
- cli_utilities_1.log.debug(`Project ${name} has validation issues`, this.config.auditContext);
191
- // Store the original project for fixing
192
- this.projectsWithIssuesMap.set(uid, project);
193
- // Create a report-friendly object
194
- const reportEntry = {
195
- title: name,
196
- name: name,
197
- uid: uid,
198
- content_types: invalidContentTypes.length > 0 ? invalidContentTypes : undefined,
199
- environment: invalidEnvironments.length > 0 ? invalidEnvironments : undefined,
200
- locale: invalidLocales.length > 0 ? invalidLocales : undefined,
201
- issues: issuesList.join(', '),
202
- };
203
- this.projectsWithIssues.push(reportEntry);
204
- }
205
- else {
206
- cli_utilities_1.log.debug(`Project ${name} has no validation issues`, this.config.auditContext);
207
- }
208
- cli_utilities_1.log.info((0, messages_1.$t)(messages_1.auditMsg.SCAN_CS_SUCCESS_MSG, {
209
- name,
210
- uid,
211
- }), this.config.auditContext);
212
- }
213
- cli_utilities_1.log.debug(`Composable Studio audit completed. Found ${this.projectsWithIssues.length} projects with issues`, this.config.auditContext);
214
- if (this.fix && this.projectsWithIssues.length) {
215
- cli_utilities_1.log.debug(`Fix mode enabled, fixing ${this.projectsWithIssues.length} projects`, this.config.auditContext);
216
- await this.fixComposableStudioProjects();
217
- this.projectsWithIssues.forEach((project) => {
218
- cli_utilities_1.log.debug(`Marking project ${project.name} as fixed`, this.config.auditContext);
219
- project.fixStatus = 'Fixed';
220
- });
221
- cli_utilities_1.log.debug(`Composable Studio fix completed`, this.config.auditContext);
222
- return this.projectsWithIssues;
223
- }
224
- cli_utilities_1.log.debug(`Composable Studio audit completed without fixes`, this.config.auditContext);
225
- return this.projectsWithIssues;
226
- }
227
- /**
228
- * Fix composable studio projects by removing invalid references
229
- */
230
- async fixComposableStudioProjects() {
231
- var _a, _b, _c, _d;
232
- cli_utilities_1.log.debug(`Starting composable studio projects fix`, this.config.auditContext);
233
- cli_utilities_1.log.debug(`Loading current composable studio projects from: ${this.composableStudioPath}`, this.config.auditContext);
234
- let projectsData;
235
- try {
236
- projectsData = JSON.parse((0, fs_1.readFileSync)(this.composableStudioPath, 'utf-8'));
237
- }
238
- catch (error) {
239
- cli_utilities_1.log.debug(`Failed to load composable studio projects for fixing: ${error}`, this.config.auditContext);
240
- return;
241
- }
242
- const isArray = Array.isArray(projectsData);
243
- const projects = isArray ? projectsData : [projectsData];
244
- cli_utilities_1.log.debug(`Loaded ${projects.length} projects for fixing`, this.config.auditContext);
245
- for (let i = 0; i < projects.length; i++) {
246
- const project = projects[i];
247
- const { uid, name } = project;
248
- cli_utilities_1.log.debug(`Fixing project: ${name} (${uid})`, this.config.auditContext);
249
- let needsFix = false;
250
- // Check and fix content type
251
- if (project.contentTypeUid && !this.ctUidSet.has(project.contentTypeUid)) {
252
- cli_utilities_1.log.debug(`Removing invalid content type ${project.contentTypeUid} from project ${name}`, this.config.auditContext);
253
- cli_utilities_1.cliux.print(`Warning: Project "${name}" has invalid content type "${project.contentTypeUid}". It will be removed.`, { color: 'yellow' });
254
- project.contentTypeUid = undefined;
255
- needsFix = true;
256
- }
257
- // Check and fix environment
258
- if (((_b = (_a = project.settings) === null || _a === void 0 ? void 0 : _a.configuration) === null || _b === void 0 ? void 0 : _b.environment) &&
259
- !this.environmentUidSet.has(project.settings.configuration.environment)) {
260
- cli_utilities_1.log.debug(`Removing invalid environment ${project.settings.configuration.environment} from project ${name}`, this.config.auditContext);
261
- cli_utilities_1.cliux.print(`Warning: Project "${name}" has invalid environment "${project.settings.configuration.environment}". It will be removed.`, { color: 'yellow' });
262
- project.settings.configuration.environment = undefined;
263
- needsFix = true;
264
- }
265
- // Check and fix locale
266
- if (((_d = (_c = project.settings) === null || _c === void 0 ? void 0 : _c.configuration) === null || _d === void 0 ? void 0 : _d.locale) && !this.localeCodeSet.has(project.settings.configuration.locale)) {
267
- cli_utilities_1.log.debug(`Removing invalid locale ${project.settings.configuration.locale} from project ${name}`, this.config.auditContext);
268
- cli_utilities_1.cliux.print(`Warning: Project "${name}" has invalid locale "${project.settings.configuration.locale}". It will be removed.`, { color: 'yellow' });
269
- project.settings.configuration.locale = undefined;
270
- needsFix = true;
271
- }
272
- if (needsFix) {
273
- cli_utilities_1.log.debug(`Project ${name} was fixed`, this.config.auditContext);
274
- }
275
- else {
276
- cli_utilities_1.log.debug(`Project ${name} did not need fixing`, this.config.auditContext);
277
- }
278
- }
279
- cli_utilities_1.log.debug(`Composable studio projects fix completed, writing updated file`, this.config.auditContext);
280
- await this.writeFixContent(isArray ? projects : projects[0]);
281
- }
282
- /**
283
- * Write fixed composable studio projects back to file
284
- */
285
- async writeFixContent(fixedProjects) {
286
- var _a, _b;
287
- cli_utilities_1.log.debug(`Writing fix content`, this.config.auditContext);
288
- cli_utilities_1.log.debug(`Fix mode: ${this.fix}`, this.config.auditContext);
289
- cli_utilities_1.log.debug(`Copy directory flag: ${this.config.flags['copy-dir']}`, this.config.auditContext);
290
- cli_utilities_1.log.debug(`External config skip confirm: ${(_a = this.config.flags['external-config']) === null || _a === void 0 ? void 0 : _a.skipConfirm}`, this.config.auditContext);
291
- cli_utilities_1.log.debug(`Yes flag: ${this.config.flags.yes}`, this.config.auditContext);
292
- if (this.fix &&
293
- (this.config.flags['copy-dir'] ||
294
- ((_b = this.config.flags['external-config']) === null || _b === void 0 ? void 0 : _b.skipConfirm) ||
295
- this.config.flags.yes ||
296
- (await cli_utilities_1.cliux.confirm(messages_1.commonMsg.FIX_CONFIRMATION)))) {
297
- const outputPath = (0, path_1.join)(this.folderPath, this.config.moduleConfig[this.moduleName].fileName);
298
- cli_utilities_1.log.debug(`Writing fixed composable studio projects to: ${outputPath}`, this.config.auditContext);
299
- (0, fs_1.writeFileSync)(outputPath, JSON.stringify(fixedProjects, null, 2));
300
- cli_utilities_1.log.debug(`Successfully wrote fixed composable studio projects to file`, this.config.auditContext);
301
- }
302
- else {
303
- cli_utilities_1.log.debug(`Skipping file write - fix mode disabled or user declined confirmation`, this.config.auditContext);
304
- }
305
- }
306
- }
307
- exports.default = ComposableStudio;
@@ -1,25 +0,0 @@
1
- interface ComposableStudioProject {
2
- name: string;
3
- description?: string;
4
- canvasUrl?: string;
5
- connectedStackApiKey?: string;
6
- contentTypeUid: string;
7
- organizationUid?: string;
8
- settings: {
9
- configuration: {
10
- environment: string;
11
- locale: string;
12
- };
13
- };
14
- createdBy?: string;
15
- updatedBy?: string;
16
- deletedAt?: boolean;
17
- createdAt?: string;
18
- updatedAt?: string;
19
- uid: string;
20
- missingContentType?: boolean;
21
- missingEnvironment?: boolean;
22
- missingLocale?: boolean;
23
- fixStatus?: string;
24
- }
25
- export { ComposableStudioProject };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });