@commercetools-connect/connector-validator 0.0.1-rc.79af18b3

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 (64) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/LICENSE +21 -0
  3. package/README.md +21 -0
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.js +17 -0
  6. package/dist/validator/common/common-types.d.ts +42 -0
  7. package/dist/validator/common/common-types.js +8 -0
  8. package/dist/validator/common/common-utils.d.ts +5 -0
  9. package/dist/validator/common/common-utils.js +24 -0
  10. package/dist/validator/common/connector-utils.d.ts +6 -0
  11. package/dist/validator/common/connector-utils.js +37 -0
  12. package/dist/validator/common/connector.d.ts +18 -0
  13. package/dist/validator/common/connector.js +27 -0
  14. package/dist/validator/common/index.d.ts +3 -0
  15. package/dist/validator/common/index.js +19 -0
  16. package/dist/validator/common/sonar-client.d.ts +12 -0
  17. package/dist/validator/common/sonar-client.js +55 -0
  18. package/dist/validator/index.d.ts +6 -0
  19. package/dist/validator/index.js +22 -0
  20. package/dist/validator/report/component-report.d.ts +22 -0
  21. package/dist/validator/report/component-report.js +29 -0
  22. package/dist/validator/report/index.d.ts +3 -0
  23. package/dist/validator/report/index.js +19 -0
  24. package/dist/validator/report/report.d.ts +30 -0
  25. package/dist/validator/report/report.js +42 -0
  26. package/dist/validator/report/step-report.d.ts +21 -0
  27. package/dist/validator/report/step-report.js +46 -0
  28. package/dist/validator/tasks/build-docker-image.d.ts +18 -0
  29. package/dist/validator/tasks/build-docker-image.js +31 -0
  30. package/dist/validator/tasks/create-workspace-volume.d.ts +11 -0
  31. package/dist/validator/tasks/create-workspace-volume.js +25 -0
  32. package/dist/validator/tasks/index.d.ts +7 -0
  33. package/dist/validator/tasks/index.js +23 -0
  34. package/dist/validator/tasks/run-sast-scan.d.ts +20 -0
  35. package/dist/validator/tasks/run-sast-scan.js +68 -0
  36. package/dist/validator/tasks/run-sca-scan.d.ts +19 -0
  37. package/dist/validator/tasks/run-sca-scan.js +60 -0
  38. package/dist/validator/tasks/run-unit-tests.d.ts +15 -0
  39. package/dist/validator/tasks/run-unit-tests.js +33 -0
  40. package/dist/validator/tasks/start-sast-server.d.ts +17 -0
  41. package/dist/validator/tasks/start-sast-server.js +39 -0
  42. package/dist/validator/tasks/stop-sast-server.d.ts +9 -0
  43. package/dist/validator/tasks/stop-sast-server.js +20 -0
  44. package/dist/validator/validator-events.d.ts +36 -0
  45. package/dist/validator/validator-events.js +2 -0
  46. package/dist/validator/validator-tasks.factory.d.ts +31 -0
  47. package/dist/validator/validator-tasks.factory.js +204 -0
  48. package/dist/validator/validator.d.ts +24 -0
  49. package/dist/validator/validator.js +127 -0
  50. package/dist/workflow/index.d.ts +5 -0
  51. package/dist/workflow/index.js +21 -0
  52. package/dist/workflow/interfaces/index.d.ts +1 -0
  53. package/dist/workflow/interfaces/index.js +17 -0
  54. package/dist/workflow/interfaces/task.interface.d.ts +24 -0
  55. package/dist/workflow/interfaces/task.interface.js +2 -0
  56. package/dist/workflow/workflow-engine.d.ts +21 -0
  57. package/dist/workflow/workflow-engine.js +69 -0
  58. package/dist/workflow/workflow-errors.d.ts +3 -0
  59. package/dist/workflow/workflow-errors.js +6 -0
  60. package/dist/workflow/workflow-task.d.ts +29 -0
  61. package/dist/workflow/workflow-task.js +73 -0
  62. package/dist/workflow/workflow.d.ts +7 -0
  63. package/dist/workflow/workflow.js +21 -0
  64. package/package.json +36 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ ## 0.0.1 (2024-07-01)
2
+
3
+
4
+ - This bump does not introduce any new features or fixes. It is solely a result of updates to dependencies, tooling, or global settings.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 commercetools
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # @commercetools-connect/connector-validator
2
+
3
+ ## Overview
4
+
5
+ This package is part of the commercetools [Connect](https://commercetools.com/products/connect) product suite.
6
+
7
+ ## Usage
8
+
9
+ This package is a dependency of the commercetools [CLI](https://www.npmjs.com/package/@commercetools/cli) and is used internally to provide necessary functionalities.
10
+
11
+ ## Installation
12
+
13
+ You do not need to install this package directly. It will be installed automatically when you install the main CLI package.
14
+
15
+ ```sh
16
+ $ npm install -g @commercetools/cli
17
+ ```
18
+
19
+ ## License
20
+
21
+ This package is licensed under the [MIT](LICENSE) License.
@@ -0,0 +1 @@
1
+ export * from "./validator";
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./validator"), exports);
@@ -0,0 +1,42 @@
1
+ export type CompositionAnalysisIssue = {
2
+ kind: "dependency_vulnerability";
3
+ id: string;
4
+ file: string;
5
+ package: {
6
+ name: string;
7
+ installedVersion: string;
8
+ };
9
+ severity: "UNKNOWN" | "LOW" | "MEDIUM" | "HIGH" | "CRITICAL";
10
+ title?: string | undefined;
11
+ description?: string | undefined;
12
+ };
13
+ export type StaticCodeAnalysisIssue = {
14
+ kind: "bug" | "code_smell" | "code_vulnerability";
15
+ severity: "UNKNOWN" | "INFO" | "MINOR" | "MAJOR" | "CRITICAL" | "BLOCKER";
16
+ file: string;
17
+ line: number;
18
+ description?: string | undefined;
19
+ };
20
+ export type TrivyVulnerability = {
21
+ VulnerabilityID: string;
22
+ PkgName: string;
23
+ InstalledVersion: string;
24
+ Severity: "UNKNOWN" | "LOW" | "MEDIUM" | "HIGH" | "CRITICAL";
25
+ Title?: string;
26
+ Description?: string;
27
+ };
28
+ export type TrivyScanResult = {
29
+ Results?: Array<{
30
+ Target: string;
31
+ Vulnerabilities?: Array<TrivyVulnerability>;
32
+ }>;
33
+ };
34
+ export type SonarIssueType = "BUG" | "CODE_SMELL" | "VULNERABILITY";
35
+ export type SonarIssue = {
36
+ type: SonarIssueType;
37
+ severity?: "BLOCKER" | "CRITICAL" | "MAJOR" | "MINOR" | "INFO";
38
+ component: string;
39
+ line: number;
40
+ message: string;
41
+ };
42
+ export declare const SonarIssueTypeMapping: Map<SonarIssueType, "bug" | "code_smell" | "code_vulnerability">;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SonarIssueTypeMapping = void 0;
4
+ exports.SonarIssueTypeMapping = new Map([
5
+ ["BUG", "bug"],
6
+ ["CODE_SMELL", "code_smell"],
7
+ ["VULNERABILITY", "code_vulnerability"],
8
+ ]);
@@ -0,0 +1,5 @@
1
+ declare class CommonUtility {
2
+ static retry<T>(fn: () => Promise<T>, maxAttempts: number, delay: number): Promise<T>;
3
+ static sleep(ms: number): Promise<void>;
4
+ }
5
+ export { CommonUtility };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommonUtility = void 0;
4
+ class CommonUtility {
5
+ static async retry(fn, maxAttempts, delay) {
6
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
7
+ try {
8
+ return await fn();
9
+ }
10
+ catch (error) {
11
+ if (attempt < maxAttempts) {
12
+ await this.sleep(delay);
13
+ continue;
14
+ }
15
+ throw error;
16
+ }
17
+ }
18
+ throw new Error("retry: no attempts made");
19
+ }
20
+ static sleep(ms) {
21
+ return new Promise((resolve) => setTimeout(resolve, ms));
22
+ }
23
+ }
24
+ exports.CommonUtility = CommonUtility;
@@ -0,0 +1,6 @@
1
+ import { ConnectSpecification } from "@commercetools-connect/specification";
2
+ declare class ConnectorUtils {
3
+ private static findLocalDependencies;
4
+ static findCommonModules(projectDir: string, specification: ConnectSpecification): Array<string>;
5
+ }
6
+ export { ConnectorUtils };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ConnectorUtils = void 0;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ class ConnectorUtils {
10
+ static findLocalDependencies(projectDir, applicationDir) {
11
+ const dependencies = new Set();
12
+ const packageJsonPath = node_path_1.default.resolve(node_path_1.default.join(applicationDir, "package.json"));
13
+ if (node_fs_1.default.existsSync(packageJsonPath) === false)
14
+ return dependencies;
15
+ const packageJson = JSON.parse(node_fs_1.default.readFileSync(packageJsonPath).toString());
16
+ const dependenciesObject = Object.assign({}, packageJson.dependencies, packageJson.devDependencies);
17
+ for (const dependencyPath of Object.values(dependenciesObject)) {
18
+ if (dependencyPath.startsWith("file:") === false &&
19
+ dependencyPath.startsWith("link:") === false) {
20
+ continue;
21
+ }
22
+ const relativeDependencyPath = dependencyPath.substring(5);
23
+ const absoluteDependencyPath = node_path_1.default.resolve(applicationDir, relativeDependencyPath);
24
+ dependencies.add(node_path_1.default.relative(projectDir, absoluteDependencyPath));
25
+ }
26
+ return dependencies;
27
+ }
28
+ static findCommonModules(projectDir, specification) {
29
+ const commonModulesPaths = new Array();
30
+ for (const application of specification.getApplications()) {
31
+ const applicationDir = node_path_1.default.join(projectDir, application.getName());
32
+ commonModulesPaths.push(...this.findLocalDependencies(projectDir, applicationDir));
33
+ }
34
+ return Array.from(new Set(commonModulesPaths));
35
+ }
36
+ }
37
+ exports.ConnectorUtils = ConnectorUtils;
@@ -0,0 +1,18 @@
1
+ import { ApplicationType } from "@commercetools-connect/specification";
2
+ declare abstract class BaseComponent {
3
+ readonly name: string;
4
+ readonly directory: string;
5
+ abstract readonly kind: string;
6
+ constructor(name: string, directory: string);
7
+ }
8
+ declare class ConnectorCommonModule extends BaseComponent {
9
+ readonly kind = "module";
10
+ constructor(name: string, directory: string);
11
+ }
12
+ declare class ConnectorApplication extends BaseComponent {
13
+ readonly type: ApplicationType;
14
+ readonly kind = "application";
15
+ constructor(name: string, directory: string, type: ApplicationType);
16
+ }
17
+ export { ConnectorCommonModule, ConnectorApplication };
18
+ export type ConnectorComponent = ConnectorCommonModule | ConnectorApplication;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectorApplication = exports.ConnectorCommonModule = void 0;
4
+ class BaseComponent {
5
+ name;
6
+ directory;
7
+ constructor(name, directory) {
8
+ this.name = name;
9
+ this.directory = directory;
10
+ }
11
+ }
12
+ class ConnectorCommonModule extends BaseComponent {
13
+ kind = "module";
14
+ constructor(name, directory) {
15
+ super(name, directory);
16
+ }
17
+ }
18
+ exports.ConnectorCommonModule = ConnectorCommonModule;
19
+ class ConnectorApplication extends BaseComponent {
20
+ type;
21
+ kind = "application";
22
+ constructor(name, directory, type) {
23
+ super(name, directory);
24
+ this.type = type;
25
+ }
26
+ }
27
+ exports.ConnectorApplication = ConnectorApplication;
@@ -0,0 +1,3 @@
1
+ export * from "./common-types";
2
+ export * from "./connector-utils";
3
+ export * from "./connector";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./common-types"), exports);
18
+ __exportStar(require("./connector-utils"), exports);
19
+ __exportStar(require("./connector"), exports);
@@ -0,0 +1,12 @@
1
+ import { StaticCodeAnalysisIssue } from "./common-types";
2
+ declare class SonarClient {
3
+ private readonly sonarAuthHeader;
4
+ private readonly sonarApiUrl;
5
+ constructor(sonarApiProto: string, sonarApiHost: string, sonarApiPort: number, sonarAuthHeader: string);
6
+ hasServerStartedOrThrow(): Promise<void>;
7
+ isServerReadyOrThrow(): Promise<void>;
8
+ private fetchStatus;
9
+ hasTaskSucceeded(taskId: string): Promise<boolean>;
10
+ fetchIssues(taskId: string, severities: string): Promise<StaticCodeAnalysisIssue[]>;
11
+ }
12
+ export { SonarClient };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SonarClient = void 0;
7
+ const node_fetch_1 = __importDefault(require("node-fetch"));
8
+ const common_types_1 = require("./common-types");
9
+ class SonarClient {
10
+ sonarAuthHeader;
11
+ sonarApiUrl;
12
+ constructor(sonarApiProto, sonarApiHost, sonarApiPort, sonarAuthHeader) {
13
+ this.sonarAuthHeader = sonarAuthHeader;
14
+ this.sonarApiUrl = `${sonarApiProto}://${sonarApiHost}:${sonarApiPort}/api`;
15
+ }
16
+ async hasServerStartedOrThrow() {
17
+ await this.fetchStatus();
18
+ }
19
+ async isServerReadyOrThrow() {
20
+ const data = await this.fetchStatus();
21
+ if (data.status !== "UP") {
22
+ throw new Error("Service is not ready.");
23
+ }
24
+ }
25
+ async fetchStatus() {
26
+ const url = `${this.sonarApiUrl}/system/status`;
27
+ const response = await (0, node_fetch_1.default)(url);
28
+ if (!response.ok) {
29
+ throw new Error("Network response was not ok");
30
+ }
31
+ return response.json();
32
+ }
33
+ async hasTaskSucceeded(taskId) {
34
+ const url = `${this.sonarApiUrl}/ce/task?id=${taskId}`;
35
+ const response = await (0, node_fetch_1.default)(url, { headers: { Authorization: this.sonarAuthHeader } });
36
+ if (!response.ok) {
37
+ throw new Error(`Failed to fetch task status: ${response.statusText}`);
38
+ }
39
+ const data = await response.json();
40
+ return data.task.status === "SUCCESS";
41
+ }
42
+ async fetchIssues(taskId, severities) {
43
+ const url = `${this.sonarApiUrl}/issues/search?componentRoots=${taskId}&severities=${severities}`;
44
+ const response = await (0, node_fetch_1.default)(url, { headers: { Authorization: this.sonarAuthHeader } });
45
+ const data = await response.json();
46
+ return data.issues.map((issue) => ({
47
+ kind: common_types_1.SonarIssueTypeMapping.get(issue.type),
48
+ severity: issue.severity ?? "UNKNOWN",
49
+ description: issue.message,
50
+ file: String(issue.component.split(":")[1]),
51
+ line: issue.line,
52
+ }));
53
+ }
54
+ }
55
+ exports.SonarClient = SonarClient;
@@ -0,0 +1,6 @@
1
+ export * from "./common";
2
+ export * from "./report";
3
+ export * from "./tasks";
4
+ export * from "./validator-events";
5
+ export * from "./validator-tasks.factory";
6
+ export * from "./validator";
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./common"), exports);
18
+ __exportStar(require("./report"), exports);
19
+ __exportStar(require("./tasks"), exports);
20
+ __exportStar(require("./validator-events"), exports);
21
+ __exportStar(require("./validator-tasks.factory"), exports);
22
+ __exportStar(require("./validator"), exports);
@@ -0,0 +1,22 @@
1
+ import { ConnectorComponent } from "../common/connector";
2
+ import { StepReport, StepReportObject } from "./step-report";
3
+ type BuildAndTestLogDetails = {
4
+ logFilePath: string | undefined;
5
+ };
6
+ type ComponentReportObject = {
7
+ component: ConnectorComponent;
8
+ build: StepReportObject<BuildAndTestLogDetails>;
9
+ test: StepReportObject<BuildAndTestLogDetails>;
10
+ };
11
+ declare class ComponentReport {
12
+ readonly component: ConnectorComponent;
13
+ constructor(component: ConnectorComponent);
14
+ build: StepReport<BuildAndTestLogDetails>;
15
+ test: StepReport<BuildAndTestLogDetails>;
16
+ isTerminated(): boolean;
17
+ isSuccessful(): boolean;
18
+ isFailure(): boolean;
19
+ toObject(): ComponentReportObject;
20
+ }
21
+ export { ComponentReport };
22
+ export type { ComponentReportObject };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ComponentReport = void 0;
4
+ const step_report_1 = require("./step-report");
5
+ class ComponentReport {
6
+ component;
7
+ constructor(component) {
8
+ this.component = component;
9
+ }
10
+ build = new step_report_1.StepReport();
11
+ test = new step_report_1.StepReport();
12
+ isTerminated() {
13
+ return this.build.isTerminated() && this.test.isTerminated();
14
+ }
15
+ isSuccessful() {
16
+ return this.build.isSuccessful() && this.test.isSuccessful();
17
+ }
18
+ isFailure() {
19
+ return this.build.isFailure() || this.test.isFailure();
20
+ }
21
+ toObject() {
22
+ return {
23
+ component: this.component,
24
+ build: this.build.toObject(),
25
+ test: this.test.toObject(),
26
+ };
27
+ }
28
+ }
29
+ exports.ComponentReport = ComponentReport;
@@ -0,0 +1,3 @@
1
+ export * from "./component-report";
2
+ export * from "./report";
3
+ export * from "./step-report";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./component-report"), exports);
18
+ __exportStar(require("./report"), exports);
19
+ __exportStar(require("./step-report"), exports);
@@ -0,0 +1,30 @@
1
+ import { ConnectorComponent } from "../common/connector";
2
+ import { CompositionAnalysisIssue, StaticCodeAnalysisIssue } from "../common/common-types";
3
+ import { StepReport, StepReportObject } from "./step-report";
4
+ import { ComponentReport, ComponentReportObject } from "./component-report";
5
+ type ReportStatus = "IN_PROGRESS" | "FAILED" | "SUCCEEDED";
6
+ type ReportObject = {
7
+ status: ReportStatus;
8
+ componentAnalysis: ComponentReportObject[];
9
+ scaAnalysis: StepReportObject<{
10
+ issues: Array<CompositionAnalysisIssue>;
11
+ }>;
12
+ sastAnalysis: StepReportObject<{
13
+ issues: Array<StaticCodeAnalysisIssue>;
14
+ }>;
15
+ };
16
+ declare class Report {
17
+ readonly componentAnalysis: Array<ComponentReport>;
18
+ readonly scaAnalysis: StepReport<{
19
+ issues: Array<CompositionAnalysisIssue>;
20
+ }>;
21
+ readonly sastAnalysis: StepReport<{
22
+ issues: Array<StaticCodeAnalysisIssue>;
23
+ }>;
24
+ constructor(components: Array<ConnectorComponent>);
25
+ getComponentOrThrow(name: string): ComponentReport;
26
+ get status(): ReportStatus;
27
+ toObject(): ReportObject;
28
+ }
29
+ export { Report };
30
+ export type { ReportObject };
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Report = void 0;
4
+ const step_report_1 = require("./step-report");
5
+ const component_report_1 = require("./component-report");
6
+ class Report {
7
+ componentAnalysis = [];
8
+ scaAnalysis;
9
+ sastAnalysis;
10
+ constructor(components) {
11
+ this.componentAnalysis = components.map((comp) => new component_report_1.ComponentReport(comp));
12
+ this.scaAnalysis = new step_report_1.StepReport();
13
+ this.sastAnalysis = new step_report_1.StepReport();
14
+ }
15
+ getComponentOrThrow(name) {
16
+ const component = this.componentAnalysis.find(({ component }) => component.name === name);
17
+ if (component == null) {
18
+ throw new Error("The component report you are trying to access does not exist.");
19
+ }
20
+ return component;
21
+ }
22
+ get status() {
23
+ const haveAllStepsTerminated = this.componentAnalysis.every((component) => component.isTerminated()) &&
24
+ this.scaAnalysis.isTerminated() &&
25
+ this.sastAnalysis.isTerminated();
26
+ if (haveAllStepsTerminated === false)
27
+ return "IN_PROGRESS";
28
+ const haveAllStepsSucceeded = this.componentAnalysis.every((component) => component.isSuccessful()) &&
29
+ this.scaAnalysis.isSuccessful() &&
30
+ this.sastAnalysis.isSuccessful();
31
+ return haveAllStepsSucceeded ? "SUCCEEDED" : "FAILED";
32
+ }
33
+ toObject() {
34
+ return {
35
+ status: this.status,
36
+ componentAnalysis: this.componentAnalysis.map((component) => component.toObject()),
37
+ scaAnalysis: this.scaAnalysis.toObject(),
38
+ sastAnalysis: this.sastAnalysis.toObject(),
39
+ };
40
+ }
41
+ }
42
+ exports.Report = Report;
@@ -0,0 +1,21 @@
1
+ type StepReportStatus = "PENDING" | "IGNORED" | "IN_PROGRESS" | "SKIPPED" | "SUCCEEDED" | "FAILED";
2
+ type StepReportObject<Details> = {
3
+ status: StepReportStatus;
4
+ details: Details | undefined;
5
+ };
6
+ declare class StepReport<Details = unknown> {
7
+ status: StepReportStatus;
8
+ details: Details | undefined;
9
+ setDetails(details: Details): void;
10
+ inProgress(): void;
11
+ ignore(): void;
12
+ skip(): void;
13
+ success(details?: Details): void;
14
+ failure(details?: Details): void;
15
+ isTerminated(): boolean;
16
+ isSuccessful(): boolean;
17
+ isFailure(): boolean;
18
+ toObject(): StepReportObject<Details>;
19
+ }
20
+ export { StepReport };
21
+ export type { StepReportStatus, StepReportObject };
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StepReport = void 0;
4
+ class StepReport {
5
+ status = "PENDING";
6
+ details;
7
+ setDetails(details) {
8
+ this.details = details;
9
+ }
10
+ inProgress() {
11
+ this.status = "IN_PROGRESS";
12
+ }
13
+ ignore() {
14
+ this.status = "IGNORED";
15
+ }
16
+ skip() {
17
+ this.status = "SKIPPED";
18
+ }
19
+ success(details) {
20
+ if (details)
21
+ this.details = details;
22
+ this.status = "SUCCEEDED";
23
+ }
24
+ failure(details) {
25
+ if (details)
26
+ this.details = details;
27
+ this.status = "FAILED";
28
+ }
29
+ isTerminated() {
30
+ const terminatedStatus = ["SKIPPED", "SUCCEEDED", "FAILED", "IGNORED"];
31
+ return terminatedStatus.includes(this.status);
32
+ }
33
+ isSuccessful() {
34
+ return this.status === "IGNORED" || this.status === "SUCCEEDED";
35
+ }
36
+ isFailure() {
37
+ return this.status === "FAILED";
38
+ }
39
+ toObject() {
40
+ return {
41
+ status: this.status,
42
+ details: this.details,
43
+ };
44
+ }
45
+ }
46
+ exports.StepReport = StepReport;
@@ -0,0 +1,18 @@
1
+ import { Task } from "../../workflow";
2
+ type BuildDockerImageTaskInput = {
3
+ projectRootDir: string;
4
+ componentName: string;
5
+ componentDir: string;
6
+ imageName: string;
7
+ imageTag?: string;
8
+ logDir: string;
9
+ };
10
+ type BuildDockerImageTaskOutput = {
11
+ success: boolean;
12
+ logFilePath: string;
13
+ };
14
+ declare class BuildDockerImageTask extends Task<BuildDockerImageTaskInput, BuildDockerImageTaskOutput> {
15
+ run(input: BuildDockerImageTaskInput): Promise<BuildDockerImageTaskOutput>;
16
+ private writeLogFile;
17
+ }
18
+ export { BuildDockerImageTask };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.BuildDockerImageTask = void 0;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const workflow_1 = require("../../workflow");
10
+ const connector_buildtools_1 = require("@commercetools-connect/connector-buildtools");
11
+ class BuildDockerImageTask extends workflow_1.Task {
12
+ async run(input) {
13
+ const logFilePath = node_path_1.default.join(input.logDir, `build_${input.componentName}.log`);
14
+ try {
15
+ const buildResult = await connector_buildtools_1.ApplicationImageBuilder.build(input.projectRootDir, input.componentName, input.imageName, input.imageTag, "development");
16
+ this.writeLogFile(logFilePath, String(buildResult.all));
17
+ return { success: true, logFilePath };
18
+ }
19
+ catch (error) {
20
+ if (error instanceof Error && "all" in error) {
21
+ this.writeLogFile(logFilePath, String(error.all));
22
+ return { success: false, logFilePath };
23
+ }
24
+ throw error;
25
+ }
26
+ }
27
+ writeLogFile(logFilePath, logs) {
28
+ node_fs_1.default.writeFileSync(logFilePath, logs);
29
+ }
30
+ }
31
+ exports.BuildDockerImageTask = BuildDockerImageTask;