@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.
- package/CHANGELOG.md +4 -0
- package/LICENSE +21 -0
- package/README.md +21 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/dist/validator/common/common-types.d.ts +42 -0
- package/dist/validator/common/common-types.js +8 -0
- package/dist/validator/common/common-utils.d.ts +5 -0
- package/dist/validator/common/common-utils.js +24 -0
- package/dist/validator/common/connector-utils.d.ts +6 -0
- package/dist/validator/common/connector-utils.js +37 -0
- package/dist/validator/common/connector.d.ts +18 -0
- package/dist/validator/common/connector.js +27 -0
- package/dist/validator/common/index.d.ts +3 -0
- package/dist/validator/common/index.js +19 -0
- package/dist/validator/common/sonar-client.d.ts +12 -0
- package/dist/validator/common/sonar-client.js +55 -0
- package/dist/validator/index.d.ts +6 -0
- package/dist/validator/index.js +22 -0
- package/dist/validator/report/component-report.d.ts +22 -0
- package/dist/validator/report/component-report.js +29 -0
- package/dist/validator/report/index.d.ts +3 -0
- package/dist/validator/report/index.js +19 -0
- package/dist/validator/report/report.d.ts +30 -0
- package/dist/validator/report/report.js +42 -0
- package/dist/validator/report/step-report.d.ts +21 -0
- package/dist/validator/report/step-report.js +46 -0
- package/dist/validator/tasks/build-docker-image.d.ts +18 -0
- package/dist/validator/tasks/build-docker-image.js +31 -0
- package/dist/validator/tasks/create-workspace-volume.d.ts +11 -0
- package/dist/validator/tasks/create-workspace-volume.js +25 -0
- package/dist/validator/tasks/index.d.ts +7 -0
- package/dist/validator/tasks/index.js +23 -0
- package/dist/validator/tasks/run-sast-scan.d.ts +20 -0
- package/dist/validator/tasks/run-sast-scan.js +68 -0
- package/dist/validator/tasks/run-sca-scan.d.ts +19 -0
- package/dist/validator/tasks/run-sca-scan.js +60 -0
- package/dist/validator/tasks/run-unit-tests.d.ts +15 -0
- package/dist/validator/tasks/run-unit-tests.js +33 -0
- package/dist/validator/tasks/start-sast-server.d.ts +17 -0
- package/dist/validator/tasks/start-sast-server.js +39 -0
- package/dist/validator/tasks/stop-sast-server.d.ts +9 -0
- package/dist/validator/tasks/stop-sast-server.js +20 -0
- package/dist/validator/validator-events.d.ts +36 -0
- package/dist/validator/validator-events.js +2 -0
- package/dist/validator/validator-tasks.factory.d.ts +31 -0
- package/dist/validator/validator-tasks.factory.js +204 -0
- package/dist/validator/validator.d.ts +24 -0
- package/dist/validator/validator.js +127 -0
- package/dist/workflow/index.d.ts +5 -0
- package/dist/workflow/index.js +21 -0
- package/dist/workflow/interfaces/index.d.ts +1 -0
- package/dist/workflow/interfaces/index.js +17 -0
- package/dist/workflow/interfaces/task.interface.d.ts +24 -0
- package/dist/workflow/interfaces/task.interface.js +2 -0
- package/dist/workflow/workflow-engine.d.ts +21 -0
- package/dist/workflow/workflow-engine.js +69 -0
- package/dist/workflow/workflow-errors.d.ts +3 -0
- package/dist/workflow/workflow-errors.js +6 -0
- package/dist/workflow/workflow-task.d.ts +29 -0
- package/dist/workflow/workflow-task.js +73 -0
- package/dist/workflow/workflow.d.ts +7 -0
- package/dist/workflow/workflow.js +21 -0
- package/package.json +36 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import EventEmitter from "node:events";
|
|
2
|
+
import { Report as ValidationReport } from "./report/report";
|
|
3
|
+
import { Workflow } from "../workflow";
|
|
4
|
+
import { ConnectorValidatorEvents } from "./validator-events";
|
|
5
|
+
type ValidationOptions = Partial<{
|
|
6
|
+
skip?: "tests" | "analysis" | undefined;
|
|
7
|
+
}>;
|
|
8
|
+
declare class ConnectorValidator {
|
|
9
|
+
readonly validationId: string;
|
|
10
|
+
readonly projectRootDir: string;
|
|
11
|
+
readonly events: EventEmitter<ConnectorValidatorEvents>;
|
|
12
|
+
workflow: Workflow | undefined;
|
|
13
|
+
report: ValidationReport | undefined;
|
|
14
|
+
private constructor();
|
|
15
|
+
static create(projectRootDir: string): Promise<ConnectorValidator>;
|
|
16
|
+
private getComponents;
|
|
17
|
+
init(options?: ValidationOptions): Promise<void>;
|
|
18
|
+
private buildWorkflow;
|
|
19
|
+
private getEligibleApplicationsForAnalysis;
|
|
20
|
+
private generateWorkspaceVolumeName;
|
|
21
|
+
private sanitizeDirectoryName;
|
|
22
|
+
private static generateValidationId;
|
|
23
|
+
}
|
|
24
|
+
export { ConnectorValidator };
|
|
@@ -0,0 +1,127 @@
|
|
|
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.ConnectorValidator = void 0;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
10
|
+
const node_events_1 = __importDefault(require("node:events"));
|
|
11
|
+
const validator_tasks_factory_1 = require("./validator-tasks.factory");
|
|
12
|
+
const report_1 = require("./report/report");
|
|
13
|
+
const workflow_1 = require("../workflow");
|
|
14
|
+
const specification_1 = require("@commercetools-connect/specification");
|
|
15
|
+
const common_1 = require("./common");
|
|
16
|
+
class ConnectorValidator {
|
|
17
|
+
validationId;
|
|
18
|
+
projectRootDir;
|
|
19
|
+
events;
|
|
20
|
+
workflow;
|
|
21
|
+
report;
|
|
22
|
+
constructor(validationId, projectRootDir, events) {
|
|
23
|
+
this.validationId = validationId;
|
|
24
|
+
this.projectRootDir = projectRootDir;
|
|
25
|
+
this.events = events;
|
|
26
|
+
}
|
|
27
|
+
static async create(projectRootDir) {
|
|
28
|
+
const validationId = this.generateValidationId();
|
|
29
|
+
const events = new node_events_1.default();
|
|
30
|
+
return new ConnectorValidator(validationId, projectRootDir, events);
|
|
31
|
+
}
|
|
32
|
+
getComponents(projectRootDir, specification) {
|
|
33
|
+
const components = [];
|
|
34
|
+
for (const application of specification.getApplications()) {
|
|
35
|
+
components.push({
|
|
36
|
+
kind: "application",
|
|
37
|
+
name: application.getName(),
|
|
38
|
+
directory: application.getName(),
|
|
39
|
+
type: application.type,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
for (const moduleDir of common_1.ConnectorUtils.findCommonModules(projectRootDir, specification)) {
|
|
43
|
+
components.push({
|
|
44
|
+
kind: "module",
|
|
45
|
+
name: this.sanitizeDirectoryName(moduleDir),
|
|
46
|
+
directory: moduleDir,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return components;
|
|
50
|
+
}
|
|
51
|
+
async init(options) {
|
|
52
|
+
if (this.workflow) {
|
|
53
|
+
throw new Error("Validation has already been executed. Please check the report.");
|
|
54
|
+
}
|
|
55
|
+
const specification = await specification_1.ConnectSpecification.load(this.projectRootDir);
|
|
56
|
+
const components = this.getComponents(this.projectRootDir, specification);
|
|
57
|
+
const report = new report_1.Report(components);
|
|
58
|
+
this.workflow = this.buildWorkflow(report, options);
|
|
59
|
+
this.report = report;
|
|
60
|
+
const execution = new workflow_1.WorkflowEngine(this.workflow);
|
|
61
|
+
execution.on("workflowCompleted", () => this.events.emit("validationCompleted", report));
|
|
62
|
+
execution.on("workflowException", (errors) => this.events.emit("validationException", errors));
|
|
63
|
+
execution.execute();
|
|
64
|
+
}
|
|
65
|
+
buildWorkflow(report, options) {
|
|
66
|
+
const workflow = new workflow_1.Workflow();
|
|
67
|
+
const tasksFactory = new validator_tasks_factory_1.ValidatorTasksFactory(this.projectRootDir, this.validationId, report, this.events);
|
|
68
|
+
const logDirectory = node_path_1.default.join(this.projectRootDir, ".connect");
|
|
69
|
+
node_fs_1.default.rmSync(logDirectory, { recursive: true, force: true });
|
|
70
|
+
node_fs_1.default.mkdirSync(logDirectory);
|
|
71
|
+
const createVolumeTasks = [];
|
|
72
|
+
for (const { component } of report.componentAnalysis) {
|
|
73
|
+
const applicationName = component.name;
|
|
74
|
+
const buildTask = tasksFactory.createBuildTask(component, logDirectory);
|
|
75
|
+
const createWorkspaceVolumeTask = tasksFactory.createWorkspaceVolumeTask({ ...component, workspaceVolume: this.generateWorkspaceVolumeName(component.name) }, [buildTask]);
|
|
76
|
+
createVolumeTasks.push(createWorkspaceVolumeTask);
|
|
77
|
+
workflow.addTasks(buildTask, createWorkspaceVolumeTask);
|
|
78
|
+
if (options?.skip === "tests") {
|
|
79
|
+
report.getComponentOrThrow(applicationName).test.ignore();
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
const runTestsTask = tasksFactory.createTestTask({ ...component, workspaceVolume: this.generateWorkspaceVolumeName(component.name) }, logDirectory, [createWorkspaceVolumeTask]);
|
|
83
|
+
workflow.addTasks(runTestsTask);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (options?.skip === "analysis") {
|
|
87
|
+
report.scaAnalysis.ignore();
|
|
88
|
+
report.sastAnalysis.ignore();
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
const components = this.getEligibleApplicationsForAnalysis(report);
|
|
92
|
+
const scaAnalysisTask = tasksFactory.createScaScanTask(components, createVolumeTasks);
|
|
93
|
+
const startSastServerTask = tasksFactory.createStartSastServerTask(logDirectory);
|
|
94
|
+
const sastAnalysisTask = tasksFactory.createSastScanTask(components, [
|
|
95
|
+
startSastServerTask,
|
|
96
|
+
...createVolumeTasks,
|
|
97
|
+
]);
|
|
98
|
+
const stopSastServerTask = tasksFactory.createStopSastServerTask([sastAnalysisTask]);
|
|
99
|
+
workflow.addTasks(scaAnalysisTask, startSastServerTask, sastAnalysisTask, stopSastServerTask);
|
|
100
|
+
}
|
|
101
|
+
return workflow;
|
|
102
|
+
}
|
|
103
|
+
getEligibleApplicationsForAnalysis(report) {
|
|
104
|
+
return report.componentAnalysis
|
|
105
|
+
.filter(({ component }) => component.kind !== "application" ||
|
|
106
|
+
component.type !== "merchant-center-custom-application")
|
|
107
|
+
.map(({ component }) => ({
|
|
108
|
+
...component,
|
|
109
|
+
workspaceVolume: this.generateWorkspaceVolumeName(component.name),
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
generateWorkspaceVolumeName(componentName) {
|
|
113
|
+
return `workspace-${componentName}-volume-${this.validationId}`;
|
|
114
|
+
}
|
|
115
|
+
sanitizeDirectoryName(dirName) {
|
|
116
|
+
const unsafeChars = /[^a-zA-Z0-9-_]/g;
|
|
117
|
+
return dirName.replace(unsafeChars, "_").trim();
|
|
118
|
+
}
|
|
119
|
+
static generateValidationId() {
|
|
120
|
+
const bytes = node_crypto_1.default.randomBytes(Math.ceil((20 * 3) / 4));
|
|
121
|
+
return bytes
|
|
122
|
+
.toString("base64")
|
|
123
|
+
.replace(/[^a-zA-Z0-9]/g, "")
|
|
124
|
+
.substring(0, 20);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.ConnectorValidator = ConnectorValidator;
|
|
@@ -0,0 +1,21 @@
|
|
|
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("./interfaces"), exports);
|
|
18
|
+
__exportStar(require("./workflow-engine"), exports);
|
|
19
|
+
__exportStar(require("./workflow-errors"), exports);
|
|
20
|
+
__exportStar(require("./workflow-task"), exports);
|
|
21
|
+
__exportStar(require("./workflow"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./task.interface";
|
|
@@ -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("./task.interface"), exports);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type TaskStatus = "PENDING" | "SKIPPED" | "IN_PROGRESS" | "SUCCEEDED" | "FAILED";
|
|
2
|
+
export type TaskInputHandler<Input> = () => Input;
|
|
3
|
+
export type TaskEvents<Input, Output> = {
|
|
4
|
+
skipped: [];
|
|
5
|
+
started: [Input];
|
|
6
|
+
succeeded: [Input, Output];
|
|
7
|
+
failed: [Error];
|
|
8
|
+
};
|
|
9
|
+
export type ITask = {
|
|
10
|
+
id: string;
|
|
11
|
+
status: TaskStatus;
|
|
12
|
+
needs: Array<ITask>;
|
|
13
|
+
if: (() => boolean) | undefined;
|
|
14
|
+
areNeedsTerminated: () => boolean;
|
|
15
|
+
shouldSkip: () => boolean;
|
|
16
|
+
skip: () => void;
|
|
17
|
+
isPending(): boolean;
|
|
18
|
+
isInProgress(): boolean;
|
|
19
|
+
isSuccess(): boolean;
|
|
20
|
+
isSkipped(): boolean;
|
|
21
|
+
isFailure(): boolean;
|
|
22
|
+
isTerminated(): boolean;
|
|
23
|
+
execute: () => Promise<void>;
|
|
24
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import EventEmitter from "events";
|
|
2
|
+
import { Workflow } from "./workflow";
|
|
3
|
+
export type WorkflowStatus = "IDLE" | "RUNNING" | "COMPLETED" | "FAILED";
|
|
4
|
+
export type WorkflowEvents = {
|
|
5
|
+
workflowCompleted: [];
|
|
6
|
+
workflowException: [Error[]];
|
|
7
|
+
};
|
|
8
|
+
declare class WorkflowEngine extends EventEmitter<WorkflowEvents> {
|
|
9
|
+
readonly workflow: Workflow;
|
|
10
|
+
status: WorkflowStatus;
|
|
11
|
+
private errors;
|
|
12
|
+
constructor(workflow: Workflow);
|
|
13
|
+
execute(): WorkflowEngine;
|
|
14
|
+
private executeReadyTasks;
|
|
15
|
+
private handleTaskSuccess;
|
|
16
|
+
private handleTaskFailure;
|
|
17
|
+
private updateWorkflowStatus;
|
|
18
|
+
private allTasksSucceeded;
|
|
19
|
+
private allTasksTerminated;
|
|
20
|
+
}
|
|
21
|
+
export { WorkflowEngine };
|
|
@@ -0,0 +1,69 @@
|
|
|
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.WorkflowEngine = void 0;
|
|
7
|
+
const events_1 = __importDefault(require("events"));
|
|
8
|
+
class WorkflowEngine extends events_1.default {
|
|
9
|
+
workflow;
|
|
10
|
+
status = "IDLE";
|
|
11
|
+
errors = [];
|
|
12
|
+
constructor(workflow) {
|
|
13
|
+
super();
|
|
14
|
+
this.workflow = workflow;
|
|
15
|
+
}
|
|
16
|
+
execute() {
|
|
17
|
+
if (this.status === "RUNNING")
|
|
18
|
+
throw new Error("The workflow is already running.");
|
|
19
|
+
if (this.status !== "IDLE")
|
|
20
|
+
throw new Error("The workflow has already been executed.");
|
|
21
|
+
this.status = "RUNNING";
|
|
22
|
+
this.executeReadyTasks();
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
executeReadyTasks() {
|
|
26
|
+
for (const [, task] of this.workflow.tasks) {
|
|
27
|
+
if (task.isPending() === false)
|
|
28
|
+
continue;
|
|
29
|
+
if (task.areNeedsTerminated() === false)
|
|
30
|
+
continue;
|
|
31
|
+
if (task.shouldSkip()) {
|
|
32
|
+
task.skip();
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
task
|
|
36
|
+
.execute()
|
|
37
|
+
.then(this.handleTaskSuccess.bind(this))
|
|
38
|
+
.catch(this.handleTaskFailure.bind(this));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
handleTaskSuccess() {
|
|
42
|
+
this.executeReadyTasks();
|
|
43
|
+
this.updateWorkflowStatus();
|
|
44
|
+
}
|
|
45
|
+
handleTaskFailure(exception) {
|
|
46
|
+
this.errors.push(exception);
|
|
47
|
+
this.executeReadyTasks();
|
|
48
|
+
this.updateWorkflowStatus();
|
|
49
|
+
}
|
|
50
|
+
updateWorkflowStatus() {
|
|
51
|
+
if (this.allTasksSucceeded()) {
|
|
52
|
+
this.status = "COMPLETED";
|
|
53
|
+
this.emit("workflowCompleted");
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (this.allTasksTerminated()) {
|
|
57
|
+
this.status = "FAILED";
|
|
58
|
+
this.emit("workflowException", this.errors);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
allTasksSucceeded() {
|
|
63
|
+
return Array.from(this.workflow.tasks).every(([, task]) => task.isSkipped() || task.isSuccess());
|
|
64
|
+
}
|
|
65
|
+
allTasksTerminated() {
|
|
66
|
+
return Array.from(this.workflow.tasks).every(([, task]) => task.isTerminated());
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.WorkflowEngine = WorkflowEngine;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import EventEmitter from "node:events";
|
|
2
|
+
import { TaskEvents, ITask, TaskStatus, TaskInputHandler } from "./interfaces/task.interface";
|
|
3
|
+
declare abstract class Task<Input, Output> extends EventEmitter<TaskEvents<Input, Output>> implements ITask {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
status: TaskStatus;
|
|
6
|
+
output: Output | undefined;
|
|
7
|
+
readonly needs: Array<ITask>;
|
|
8
|
+
readonly if: (() => boolean) | undefined;
|
|
9
|
+
private readonly handleInput;
|
|
10
|
+
protected readonly abortController: AbortController;
|
|
11
|
+
constructor(props: {
|
|
12
|
+
id: string;
|
|
13
|
+
needs?: Array<ITask>;
|
|
14
|
+
if?: () => boolean;
|
|
15
|
+
handleInput: TaskInputHandler<Input>;
|
|
16
|
+
});
|
|
17
|
+
execute(): Promise<void>;
|
|
18
|
+
abstract run(input: Input): Promise<Output>;
|
|
19
|
+
isPending(): boolean;
|
|
20
|
+
isInProgress(): boolean;
|
|
21
|
+
isTerminated(): boolean;
|
|
22
|
+
isSuccess(): boolean;
|
|
23
|
+
isFailure(): boolean;
|
|
24
|
+
isSkipped(): boolean;
|
|
25
|
+
shouldSkip(): boolean;
|
|
26
|
+
skip(): void;
|
|
27
|
+
areNeedsTerminated(): boolean;
|
|
28
|
+
}
|
|
29
|
+
export { Task };
|
|
@@ -0,0 +1,73 @@
|
|
|
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.Task = void 0;
|
|
7
|
+
const node_events_1 = __importDefault(require("node:events"));
|
|
8
|
+
const workflow_errors_1 = require("./workflow-errors");
|
|
9
|
+
class Task extends node_events_1.default {
|
|
10
|
+
id;
|
|
11
|
+
status;
|
|
12
|
+
output;
|
|
13
|
+
needs;
|
|
14
|
+
if;
|
|
15
|
+
handleInput;
|
|
16
|
+
abortController = new AbortController();
|
|
17
|
+
constructor(props) {
|
|
18
|
+
super();
|
|
19
|
+
this.id = props.id;
|
|
20
|
+
this.status = "PENDING";
|
|
21
|
+
this.needs = props.needs ?? [];
|
|
22
|
+
this.if = props.if;
|
|
23
|
+
this.handleInput = props.handleInput;
|
|
24
|
+
}
|
|
25
|
+
async execute() {
|
|
26
|
+
try {
|
|
27
|
+
this.status = "IN_PROGRESS";
|
|
28
|
+
const input = this.handleInput();
|
|
29
|
+
this.emit("started", input);
|
|
30
|
+
this.output = await this.run(input);
|
|
31
|
+
this.status = "SUCCEEDED";
|
|
32
|
+
this.emit("succeeded", input, this.output);
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
this.status = "FAILED";
|
|
36
|
+
const error = err instanceof Error ? err : new workflow_errors_1.WorkflowUnexpectedException(String(err));
|
|
37
|
+
this.emit("failed", error);
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
isPending() {
|
|
42
|
+
return this.status === "PENDING";
|
|
43
|
+
}
|
|
44
|
+
isInProgress() {
|
|
45
|
+
return this.status === "IN_PROGRESS";
|
|
46
|
+
}
|
|
47
|
+
isTerminated() {
|
|
48
|
+
const terminatedStatus = ["SKIPPED", "SUCCEEDED", "FAILED"];
|
|
49
|
+
return terminatedStatus.includes(this.status);
|
|
50
|
+
}
|
|
51
|
+
isSuccess() {
|
|
52
|
+
return this.status === "SUCCEEDED";
|
|
53
|
+
}
|
|
54
|
+
isFailure() {
|
|
55
|
+
return this.status === "FAILED";
|
|
56
|
+
}
|
|
57
|
+
isSkipped() {
|
|
58
|
+
return this.status === "SKIPPED";
|
|
59
|
+
}
|
|
60
|
+
shouldSkip() {
|
|
61
|
+
if (this.if != null)
|
|
62
|
+
return !this.if();
|
|
63
|
+
return this.needs.some((task) => task.isSkipped() || task.isFailure());
|
|
64
|
+
}
|
|
65
|
+
skip() {
|
|
66
|
+
this.status = "SKIPPED";
|
|
67
|
+
this.emit("skipped");
|
|
68
|
+
}
|
|
69
|
+
areNeedsTerminated() {
|
|
70
|
+
return this.needs.every((task) => task.isTerminated());
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.Task = Task;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Workflow = void 0;
|
|
4
|
+
class Workflow {
|
|
5
|
+
tasks = new Map();
|
|
6
|
+
addTasks(...tasks) {
|
|
7
|
+
for (const task of tasks) {
|
|
8
|
+
for (const dependencyTask of task.needs) {
|
|
9
|
+
if (this.getTask(dependencyTask.id) === dependencyTask)
|
|
10
|
+
continue;
|
|
11
|
+
throw new Error(`Task ${task.id} dependency "${dependencyTask.id}" does not exist in the workflow.`);
|
|
12
|
+
}
|
|
13
|
+
this.tasks.set(task.id, task);
|
|
14
|
+
}
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
getTask(id) {
|
|
18
|
+
return this.tasks.get(id);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.Workflow = Workflow;
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@commercetools-connect/connector-validator",
|
|
3
|
+
"version": "0.0.1-rc.79af18b3",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"LICENSE"
|
|
9
|
+
],
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"clean": "rimraf dist",
|
|
15
|
+
"build": "yarn clean && tsc -p tsconfig.build.json",
|
|
16
|
+
"test": "jest --coverage"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/jest": "29.5.12",
|
|
20
|
+
"jest": "29.7.0",
|
|
21
|
+
"rimraf": "5.0.7",
|
|
22
|
+
"ts-jest": "29.1.5",
|
|
23
|
+
"tsx": "^4.15.7",
|
|
24
|
+
"typescript": "5.5.2"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@commercetools-connect/connector-buildtools": "0.0.1-rc.79af18b3",
|
|
28
|
+
"execa": "5.1.1",
|
|
29
|
+
"get-port": "5.1.1",
|
|
30
|
+
"node-fetch": "2.7.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@commercetools-connect/specification": "0.0.1-rc.79af18b3"
|
|
34
|
+
},
|
|
35
|
+
"stableVersion": "0.0.1"
|
|
36
|
+
}
|