@ondc/automation-mock-runner 0.0.1
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/LICENSE +15 -0
- package/README.md +372 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +43 -0
- package/dist/lib/MockRunner.d.ts +18 -0
- package/dist/lib/MockRunner.js +335 -0
- package/dist/lib/configHelper.d.ts +2 -0
- package/dist/lib/configHelper.js +101 -0
- package/dist/lib/constants/function-registry.d.ts +26 -0
- package/dist/lib/constants/function-registry.js +132 -0
- package/dist/lib/runners/base-runner.d.ts +6 -0
- package/dist/lib/runners/base-runner.js +6 -0
- package/dist/lib/runners/browser-runner.d.ts +12 -0
- package/dist/lib/runners/browser-runner.js +91 -0
- package/dist/lib/runners/node-runner.d.ts +16 -0
- package/dist/lib/runners/node-runner.js +189 -0
- package/dist/lib/runners/runner-factory.d.ts +25 -0
- package/dist/lib/runners/runner-factory.js +113 -0
- package/dist/lib/types/execution-results.d.ts +30 -0
- package/dist/lib/types/execution-results.js +2 -0
- package/dist/lib/types/mock-config.d.ts +107 -0
- package/dist/lib/types/mock-config.js +52 -0
- package/dist/lib/utils/errors.d.ts +47 -0
- package/dist/lib/utils/errors.js +84 -0
- package/dist/lib/utils/input-validator.d.ts +18 -0
- package/dist/lib/utils/input-validator.js +146 -0
- package/dist/lib/utils/logger.d.ts +36 -0
- package/dist/lib/utils/logger.js +86 -0
- package/dist/lib/utils/performance-monitor.d.ts +34 -0
- package/dist/lib/utils/performance-monitor.js +98 -0
- package/dist/lib/utils/validateConfig.d.ts +6 -0
- package/dist/lib/utils/validateConfig.js +16 -0
- package/dist/lib/validators/code-validator.d.ts +30 -0
- package/dist/lib/validators/code-validator.js +327 -0
- package/dist/lib/worker/worker-factory.d.ts +3 -0
- package/dist/lib/worker/worker-factory.js +81 -0
- package/dist/test/MockRunner.test.d.ts +4 -0
- package/dist/test/MockRunner.test.js +144 -0
- package/dist/test/__mocks__/uuid.d.ts +5 -0
- package/dist/test/__mocks__/uuid.js +8 -0
- package/dist/test/setup.d.ts +3 -0
- package/dist/test/setup.js +43 -0
- package/package.json +84 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BrowserRunner = void 0;
|
|
4
|
+
const code_validator_1 = require("../validators/code-validator");
|
|
5
|
+
const worker_factory_1 = require("../worker/worker-factory");
|
|
6
|
+
class BrowserRunner {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.worker = null;
|
|
9
|
+
this.executionId = 0;
|
|
10
|
+
this.pendingExecutions = new Map();
|
|
11
|
+
this.initWorker();
|
|
12
|
+
}
|
|
13
|
+
initWorker() {
|
|
14
|
+
if (this.worker) {
|
|
15
|
+
this.worker.terminate();
|
|
16
|
+
}
|
|
17
|
+
this.worker = worker_factory_1.WorkerFactory.createCodeRunnerWorker();
|
|
18
|
+
this.worker.addEventListener("message", (event) => {
|
|
19
|
+
const { id, success, result, error, logs, executionTime } = event.data;
|
|
20
|
+
const pending = this.pendingExecutions.get(id);
|
|
21
|
+
if (pending) {
|
|
22
|
+
clearTimeout(pending.timeout);
|
|
23
|
+
this.pendingExecutions.delete(id);
|
|
24
|
+
pending.resolve({
|
|
25
|
+
timestamp: new Date().toISOString(),
|
|
26
|
+
success,
|
|
27
|
+
result,
|
|
28
|
+
error,
|
|
29
|
+
logs,
|
|
30
|
+
executionTime,
|
|
31
|
+
validation: { isValid: true, errors: [], warnings: [] },
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
this.worker.addEventListener("error", (error) => {
|
|
36
|
+
console.error("Worker error:", error);
|
|
37
|
+
this.initWorker();
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async execute(functionBody, schema, args) {
|
|
41
|
+
const validation = code_validator_1.CodeValidator.validate(functionBody, schema);
|
|
42
|
+
if (!validation.isValid || !validation.wrappedCode) {
|
|
43
|
+
return {
|
|
44
|
+
success: false,
|
|
45
|
+
timestamp: new Date().toISOString(),
|
|
46
|
+
error: {
|
|
47
|
+
message: validation.errors.join("\n"),
|
|
48
|
+
name: "ValidationError",
|
|
49
|
+
},
|
|
50
|
+
logs: [],
|
|
51
|
+
validation,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// Execute wrapped code in worker
|
|
55
|
+
return new Promise((resolve) => {
|
|
56
|
+
const id = ++this.executionId;
|
|
57
|
+
const timeout = schema.timeout || 5000;
|
|
58
|
+
const timeoutId = setTimeout(() => {
|
|
59
|
+
this.pendingExecutions.delete(id);
|
|
60
|
+
resolve({
|
|
61
|
+
success: false,
|
|
62
|
+
timestamp: new Date().toISOString(),
|
|
63
|
+
error: {
|
|
64
|
+
message: `Execution timeout after ${timeout}ms`,
|
|
65
|
+
name: "TimeoutError",
|
|
66
|
+
},
|
|
67
|
+
logs: [],
|
|
68
|
+
validation,
|
|
69
|
+
});
|
|
70
|
+
this.initWorker();
|
|
71
|
+
}, timeout); // Type assertion for compatibility
|
|
72
|
+
this.pendingExecutions.set(id, {
|
|
73
|
+
resolve: (result) => {
|
|
74
|
+
resolve({ ...result, validation });
|
|
75
|
+
},
|
|
76
|
+
timeout: timeoutId,
|
|
77
|
+
});
|
|
78
|
+
this.worker?.postMessage({
|
|
79
|
+
id,
|
|
80
|
+
code: validation.wrappedCode,
|
|
81
|
+
functionName: schema.name,
|
|
82
|
+
args,
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
terminate() {
|
|
87
|
+
this.worker?.terminate();
|
|
88
|
+
this.worker = null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.BrowserRunner = BrowserRunner;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FunctionSchema } from "../constants/function-registry";
|
|
2
|
+
import { ExecutionResult } from "../types/execution-results";
|
|
3
|
+
import { BaseCodeRunner } from "./base-runner";
|
|
4
|
+
export declare class NodeRunner implements BaseCodeRunner {
|
|
5
|
+
private worker;
|
|
6
|
+
private executionId;
|
|
7
|
+
private pendingExecutions;
|
|
8
|
+
private readonly workerPath;
|
|
9
|
+
private readonly maxMemoryMB;
|
|
10
|
+
constructor(options?: {
|
|
11
|
+
maxMemoryMB?: number;
|
|
12
|
+
});
|
|
13
|
+
private initWorker;
|
|
14
|
+
execute(functionBody: string, schema: FunctionSchema, args: any[]): Promise<ExecutionResult>;
|
|
15
|
+
terminate(): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.NodeRunner = void 0;
|
|
37
|
+
const worker_threads_1 = require("worker_threads");
|
|
38
|
+
const code_validator_1 = require("../validators/code-validator");
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
class NodeRunner {
|
|
41
|
+
constructor(options = {}) {
|
|
42
|
+
this.worker = null;
|
|
43
|
+
this.executionId = 0;
|
|
44
|
+
this.pendingExecutions = new Map();
|
|
45
|
+
this.workerPath = path.join(__dirname, "../../../public/node-worker.js");
|
|
46
|
+
this.maxMemoryMB = options.maxMemoryMB || 128;
|
|
47
|
+
this.initWorker();
|
|
48
|
+
}
|
|
49
|
+
initWorker() {
|
|
50
|
+
if (this.worker) {
|
|
51
|
+
this.worker.terminate();
|
|
52
|
+
}
|
|
53
|
+
// Create worker with resource limits
|
|
54
|
+
this.worker = new worker_threads_1.Worker(this.workerPath, {
|
|
55
|
+
resourceLimits: {
|
|
56
|
+
maxOldGenerationSizeMb: this.maxMemoryMB,
|
|
57
|
+
maxYoungGenerationSizeMb: this.maxMemoryMB / 2,
|
|
58
|
+
codeRangeSizeMb: 16,
|
|
59
|
+
},
|
|
60
|
+
// Prevent worker from accessing parent environment variables
|
|
61
|
+
env: {},
|
|
62
|
+
});
|
|
63
|
+
this.worker.on("message", (message) => {
|
|
64
|
+
const { id, success, result, error, logs, executionTime } = message;
|
|
65
|
+
const pending = this.pendingExecutions.get(id);
|
|
66
|
+
if (pending) {
|
|
67
|
+
clearTimeout(pending.timeout);
|
|
68
|
+
this.pendingExecutions.delete(id);
|
|
69
|
+
pending.resolve({
|
|
70
|
+
timestamp: new Date().toISOString(),
|
|
71
|
+
success,
|
|
72
|
+
result,
|
|
73
|
+
error,
|
|
74
|
+
logs,
|
|
75
|
+
executionTime,
|
|
76
|
+
validation: { isValid: true, errors: [], warnings: [] },
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
this.worker.on("error", (error) => {
|
|
81
|
+
console.error("Worker error:", error);
|
|
82
|
+
// Resolve all pending executions with error
|
|
83
|
+
this.pendingExecutions.forEach((pending, id) => {
|
|
84
|
+
clearTimeout(pending.timeout);
|
|
85
|
+
pending.resolve({
|
|
86
|
+
success: false,
|
|
87
|
+
timestamp: new Date().toISOString(),
|
|
88
|
+
error: {
|
|
89
|
+
message: error.message || "Worker crashed",
|
|
90
|
+
name: "WorkerError",
|
|
91
|
+
},
|
|
92
|
+
logs: [],
|
|
93
|
+
validation: { isValid: true, errors: [], warnings: [] },
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
this.pendingExecutions.clear();
|
|
97
|
+
this.initWorker();
|
|
98
|
+
});
|
|
99
|
+
this.worker.on("exit", (code) => {
|
|
100
|
+
if (code !== 0) {
|
|
101
|
+
console.error(`Worker stopped with exit code ${code}`);
|
|
102
|
+
// Handle any pending executions
|
|
103
|
+
this.pendingExecutions.forEach((pending, id) => {
|
|
104
|
+
clearTimeout(pending.timeout);
|
|
105
|
+
pending.resolve({
|
|
106
|
+
success: false,
|
|
107
|
+
timestamp: new Date().toISOString(),
|
|
108
|
+
error: {
|
|
109
|
+
message: `Worker exited with code ${code}`,
|
|
110
|
+
name: "WorkerExitError",
|
|
111
|
+
},
|
|
112
|
+
logs: [],
|
|
113
|
+
validation: { isValid: true, errors: [], warnings: [] },
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
this.pendingExecutions.clear();
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
async execute(functionBody, schema, args) {
|
|
121
|
+
const validation = code_validator_1.CodeValidator.validate(functionBody, schema);
|
|
122
|
+
if (!validation.isValid || !validation.wrappedCode) {
|
|
123
|
+
return {
|
|
124
|
+
success: false,
|
|
125
|
+
timestamp: new Date().toISOString(),
|
|
126
|
+
error: {
|
|
127
|
+
message: validation.errors.join("\n"),
|
|
128
|
+
name: "ValidationError",
|
|
129
|
+
},
|
|
130
|
+
logs: [],
|
|
131
|
+
validation,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return new Promise((resolve) => {
|
|
135
|
+
const id = ++this.executionId;
|
|
136
|
+
const timeout = schema.timeout || 5000;
|
|
137
|
+
const timeoutId = setTimeout(() => {
|
|
138
|
+
this.pendingExecutions.delete(id);
|
|
139
|
+
resolve({
|
|
140
|
+
success: false,
|
|
141
|
+
timestamp: new Date().toISOString(),
|
|
142
|
+
error: {
|
|
143
|
+
message: `Execution timeout after ${timeout}ms`,
|
|
144
|
+
name: "TimeoutError",
|
|
145
|
+
},
|
|
146
|
+
logs: [],
|
|
147
|
+
validation,
|
|
148
|
+
});
|
|
149
|
+
// Restart worker to kill the hanging execution
|
|
150
|
+
this.initWorker();
|
|
151
|
+
}, timeout);
|
|
152
|
+
this.pendingExecutions.set(id, {
|
|
153
|
+
resolve: (result) => {
|
|
154
|
+
resolve({ ...result, validation });
|
|
155
|
+
},
|
|
156
|
+
timeout: timeoutId,
|
|
157
|
+
});
|
|
158
|
+
// Send code to worker for execution
|
|
159
|
+
this.worker?.postMessage({
|
|
160
|
+
id,
|
|
161
|
+
code: validation.wrappedCode,
|
|
162
|
+
functionName: schema.name,
|
|
163
|
+
args,
|
|
164
|
+
timeout,
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
terminate() {
|
|
169
|
+
// Clear all pending executions
|
|
170
|
+
this.pendingExecutions.forEach((pending) => {
|
|
171
|
+
clearTimeout(pending.timeout);
|
|
172
|
+
pending.resolve({
|
|
173
|
+
success: false,
|
|
174
|
+
timestamp: new Date().toISOString(),
|
|
175
|
+
error: {
|
|
176
|
+
message: "Runner terminated",
|
|
177
|
+
name: "TerminationError",
|
|
178
|
+
},
|
|
179
|
+
logs: [],
|
|
180
|
+
validation: { isValid: true, errors: [], warnings: [] },
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
this.pendingExecutions.clear();
|
|
184
|
+
// Terminate worker
|
|
185
|
+
this.worker?.terminate();
|
|
186
|
+
this.worker = null;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
exports.NodeRunner = NodeRunner;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Worker } from "worker_threads";
|
|
2
|
+
import { BrowserRunner } from "./browser-runner";
|
|
3
|
+
import { NodeRunner } from "./node-runner";
|
|
4
|
+
/**
|
|
5
|
+
* Factory for creating workers in both browser and Node.js environments
|
|
6
|
+
*/
|
|
7
|
+
export declare class RunnerFactory {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a Web Worker for browser environment
|
|
10
|
+
*/
|
|
11
|
+
static createCodeRunnerWorker(): Worker;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a Worker Thread for Node.js environment
|
|
14
|
+
* Note: This is primarily for internal use by NodeRunner
|
|
15
|
+
*/
|
|
16
|
+
static createNodeWorker(workerPath: string, options?: any): Worker;
|
|
17
|
+
/**
|
|
18
|
+
* Detects the current environment
|
|
19
|
+
*/
|
|
20
|
+
static getEnvironment(): "browser" | "node" | "unknown";
|
|
21
|
+
/**
|
|
22
|
+
* Creates appropriate runner based on environment
|
|
23
|
+
*/
|
|
24
|
+
static createRunner(options?: any): BrowserRunner | NodeRunner;
|
|
25
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RunnerFactory = void 0;
|
|
4
|
+
const worker_threads_1 = require("worker_threads");
|
|
5
|
+
const browser_runner_1 = require("./browser-runner");
|
|
6
|
+
const node_runner_1 = require("./node-runner");
|
|
7
|
+
/**
|
|
8
|
+
* Factory for creating workers in both browser and Node.js environments
|
|
9
|
+
*/
|
|
10
|
+
class RunnerFactory {
|
|
11
|
+
/**
|
|
12
|
+
* Creates a Web Worker for browser environment
|
|
13
|
+
*/
|
|
14
|
+
static createCodeRunnerWorker() {
|
|
15
|
+
// Browser environment - returns Web Worker
|
|
16
|
+
if (typeof window !== "undefined" && typeof worker_threads_1.Worker !== "undefined") {
|
|
17
|
+
// Inline worker code for browser
|
|
18
|
+
const workerCode = `
|
|
19
|
+
self.addEventListener('message', (event) => {
|
|
20
|
+
const { id, code, functionName, args } = event.data;
|
|
21
|
+
const startTime = performance.now();
|
|
22
|
+
const logs = [];
|
|
23
|
+
|
|
24
|
+
// Override console to capture logs
|
|
25
|
+
const originalConsole = { ...console };
|
|
26
|
+
console.log = (...args) => {
|
|
27
|
+
logs.push(args.join(' '));
|
|
28
|
+
originalConsole.log(...args);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
// Execute code
|
|
33
|
+
eval(code);
|
|
34
|
+
const fn = self[functionName];
|
|
35
|
+
|
|
36
|
+
if (typeof fn !== 'function') {
|
|
37
|
+
throw new Error(\`\${functionName} is not a function\`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const result = fn(...args);
|
|
41
|
+
const executionTime = performance.now() - startTime;
|
|
42
|
+
|
|
43
|
+
self.postMessage({
|
|
44
|
+
id,
|
|
45
|
+
success: true,
|
|
46
|
+
result,
|
|
47
|
+
logs,
|
|
48
|
+
executionTime
|
|
49
|
+
});
|
|
50
|
+
} catch (error) {
|
|
51
|
+
const executionTime = performance.now() - startTime;
|
|
52
|
+
self.postMessage({
|
|
53
|
+
id,
|
|
54
|
+
success: false,
|
|
55
|
+
error: {
|
|
56
|
+
message: error.message,
|
|
57
|
+
name: error.name,
|
|
58
|
+
stack: error.stack
|
|
59
|
+
},
|
|
60
|
+
logs,
|
|
61
|
+
executionTime
|
|
62
|
+
});
|
|
63
|
+
} finally {
|
|
64
|
+
// Restore console
|
|
65
|
+
console.log = originalConsole.log;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
`;
|
|
69
|
+
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
70
|
+
const workerUrl = URL.createObjectURL(blob);
|
|
71
|
+
return new worker_threads_1.Worker(workerUrl);
|
|
72
|
+
}
|
|
73
|
+
// Node.js environment - returns Worker Thread
|
|
74
|
+
// This shouldn't be called for NodeRunner, but included for completeness
|
|
75
|
+
throw new Error("Use NodeRunner directly in Node.js environment instead of WorkerFactory");
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Creates a Worker Thread for Node.js environment
|
|
79
|
+
* Note: This is primarily for internal use by NodeRunner
|
|
80
|
+
*/
|
|
81
|
+
static createNodeWorker(workerPath, options) {
|
|
82
|
+
if (typeof worker_threads_1.Worker === "undefined") {
|
|
83
|
+
throw new Error("Worker threads not available in this environment");
|
|
84
|
+
}
|
|
85
|
+
return new worker_threads_1.Worker(workerPath, options);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Detects the current environment
|
|
89
|
+
*/
|
|
90
|
+
static getEnvironment() {
|
|
91
|
+
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
92
|
+
return "browser";
|
|
93
|
+
}
|
|
94
|
+
if (typeof process !== "undefined" && process.versions?.node) {
|
|
95
|
+
return "node";
|
|
96
|
+
}
|
|
97
|
+
return "unknown";
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Creates appropriate runner based on environment
|
|
101
|
+
*/
|
|
102
|
+
static createRunner(options) {
|
|
103
|
+
const env = RunnerFactory.getEnvironment();
|
|
104
|
+
if (env === "browser") {
|
|
105
|
+
return new browser_runner_1.BrowserRunner();
|
|
106
|
+
}
|
|
107
|
+
else if (env === "node") {
|
|
108
|
+
return new node_runner_1.NodeRunner(options);
|
|
109
|
+
}
|
|
110
|
+
throw new Error(`Unsupported environment: ${env}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.RunnerFactory = RunnerFactory;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface ExecutionResult {
|
|
2
|
+
timestamp: string;
|
|
3
|
+
success: boolean;
|
|
4
|
+
result?: any;
|
|
5
|
+
error?: {
|
|
6
|
+
message: string;
|
|
7
|
+
stack?: string;
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
10
|
+
logs: Array<{
|
|
11
|
+
type: "log" | "error" | "warn";
|
|
12
|
+
message: string;
|
|
13
|
+
timestamp: number;
|
|
14
|
+
}>;
|
|
15
|
+
executionTime?: number;
|
|
16
|
+
validation: ValidationResult;
|
|
17
|
+
}
|
|
18
|
+
export interface ValidationResult {
|
|
19
|
+
isValid: boolean;
|
|
20
|
+
errors: string[];
|
|
21
|
+
warnings: string[];
|
|
22
|
+
wrappedCode?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface CodeStatistics {
|
|
25
|
+
lines: number;
|
|
26
|
+
functions: number;
|
|
27
|
+
complexity: number;
|
|
28
|
+
loops: number;
|
|
29
|
+
conditionals: number;
|
|
30
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const OwnerSchema: z.ZodEnum<{
|
|
3
|
+
BAP: "BAP";
|
|
4
|
+
BPP: "BPP";
|
|
5
|
+
}>;
|
|
6
|
+
export declare const MetaSchema: z.ZodObject<{
|
|
7
|
+
domain: z.ZodString;
|
|
8
|
+
version: z.ZodString;
|
|
9
|
+
flowId: z.ZodString;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
export declare const TransactionDataSchema: z.ZodObject<{
|
|
12
|
+
transaction_id: z.ZodString;
|
|
13
|
+
latest_timestamp: z.ZodString;
|
|
14
|
+
bap_id: z.ZodOptional<z.ZodString>;
|
|
15
|
+
bap_uri: z.ZodOptional<z.ZodString>;
|
|
16
|
+
bpp_id: z.ZodOptional<z.ZodString>;
|
|
17
|
+
bpp_uri: z.ZodOptional<z.ZodString>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
export declare const MockConfigSchema: z.ZodObject<{
|
|
20
|
+
generate: z.ZodString;
|
|
21
|
+
validate: z.ZodString;
|
|
22
|
+
requirements: z.ZodString;
|
|
23
|
+
defaultPayload: z.ZodAny;
|
|
24
|
+
saveData: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
25
|
+
inputs: z.ZodObject<{
|
|
26
|
+
id: z.ZodOptional<z.ZodString>;
|
|
27
|
+
jsonSchema: z.ZodOptional<z.ZodAny>;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
export declare const PlaygroundActionStepSchema: z.ZodObject<{
|
|
31
|
+
api: z.ZodString;
|
|
32
|
+
action_id: z.ZodString;
|
|
33
|
+
owner: z.ZodEnum<{
|
|
34
|
+
BAP: "BAP";
|
|
35
|
+
BPP: "BPP";
|
|
36
|
+
}>;
|
|
37
|
+
responseFor: z.ZodNullable<z.ZodString>;
|
|
38
|
+
unsolicited: z.ZodBoolean;
|
|
39
|
+
description: z.ZodString;
|
|
40
|
+
mock: z.ZodObject<{
|
|
41
|
+
generate: z.ZodString;
|
|
42
|
+
validate: z.ZodString;
|
|
43
|
+
requirements: z.ZodString;
|
|
44
|
+
defaultPayload: z.ZodAny;
|
|
45
|
+
saveData: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
46
|
+
inputs: z.ZodObject<{
|
|
47
|
+
id: z.ZodOptional<z.ZodString>;
|
|
48
|
+
jsonSchema: z.ZodOptional<z.ZodAny>;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
}, z.core.$strip>;
|
|
51
|
+
}, z.core.$strip>;
|
|
52
|
+
export declare const TransactionHistoryItemSchema: z.ZodObject<{
|
|
53
|
+
action_id: z.ZodString;
|
|
54
|
+
payload: z.ZodAny;
|
|
55
|
+
saved_info: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
56
|
+
}, z.core.$strip>;
|
|
57
|
+
export declare const MockPlaygroundConfigSchema: z.ZodObject<{
|
|
58
|
+
meta: z.ZodObject<{
|
|
59
|
+
domain: z.ZodString;
|
|
60
|
+
version: z.ZodString;
|
|
61
|
+
flowId: z.ZodString;
|
|
62
|
+
}, z.core.$strip>;
|
|
63
|
+
transaction_data: z.ZodObject<{
|
|
64
|
+
transaction_id: z.ZodString;
|
|
65
|
+
latest_timestamp: z.ZodString;
|
|
66
|
+
bap_id: z.ZodOptional<z.ZodString>;
|
|
67
|
+
bap_uri: z.ZodOptional<z.ZodString>;
|
|
68
|
+
bpp_id: z.ZodOptional<z.ZodString>;
|
|
69
|
+
bpp_uri: z.ZodOptional<z.ZodString>;
|
|
70
|
+
}, z.core.$strip>;
|
|
71
|
+
steps: z.ZodArray<z.ZodObject<{
|
|
72
|
+
api: z.ZodString;
|
|
73
|
+
action_id: z.ZodString;
|
|
74
|
+
owner: z.ZodEnum<{
|
|
75
|
+
BAP: "BAP";
|
|
76
|
+
BPP: "BPP";
|
|
77
|
+
}>;
|
|
78
|
+
responseFor: z.ZodNullable<z.ZodString>;
|
|
79
|
+
unsolicited: z.ZodBoolean;
|
|
80
|
+
description: z.ZodString;
|
|
81
|
+
mock: z.ZodObject<{
|
|
82
|
+
generate: z.ZodString;
|
|
83
|
+
validate: z.ZodString;
|
|
84
|
+
requirements: z.ZodString;
|
|
85
|
+
defaultPayload: z.ZodAny;
|
|
86
|
+
saveData: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
87
|
+
inputs: z.ZodObject<{
|
|
88
|
+
id: z.ZodOptional<z.ZodString>;
|
|
89
|
+
jsonSchema: z.ZodOptional<z.ZodAny>;
|
|
90
|
+
}, z.core.$strip>;
|
|
91
|
+
}, z.core.$strip>;
|
|
92
|
+
}, z.core.$strip>>;
|
|
93
|
+
transaction_history: z.ZodArray<z.ZodObject<{
|
|
94
|
+
action_id: z.ZodString;
|
|
95
|
+
payload: z.ZodAny;
|
|
96
|
+
saved_info: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
97
|
+
}, z.core.$strip>>;
|
|
98
|
+
validationLib: z.ZodString;
|
|
99
|
+
helperLib: z.ZodString;
|
|
100
|
+
}, z.core.$strip>;
|
|
101
|
+
export type Owner = z.infer<typeof OwnerSchema>;
|
|
102
|
+
export type Meta = z.infer<typeof MetaSchema>;
|
|
103
|
+
export type TransactionData = z.infer<typeof TransactionDataSchema>;
|
|
104
|
+
export type MockConfig = z.infer<typeof MockConfigSchema>;
|
|
105
|
+
export type PlaygroundActionStep = z.infer<typeof PlaygroundActionStepSchema>;
|
|
106
|
+
export type TransactionHistoryItem = z.infer<typeof TransactionHistoryItemSchema>;
|
|
107
|
+
export type MockPlaygroundConfigType = z.infer<typeof MockPlaygroundConfigSchema>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MockPlaygroundConfigSchema = exports.TransactionHistoryItemSchema = exports.PlaygroundActionStepSchema = exports.MockConfigSchema = exports.TransactionDataSchema = exports.MetaSchema = exports.OwnerSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
// Zod schemas
|
|
6
|
+
exports.OwnerSchema = zod_1.z.enum(["BAP", "BPP"]);
|
|
7
|
+
exports.MetaSchema = zod_1.z.object({
|
|
8
|
+
domain: zod_1.z.string().min(1, "Domain is required"),
|
|
9
|
+
version: zod_1.z.string().min(1, "Version is required"),
|
|
10
|
+
flowId: zod_1.z.string().min(1, "Flow ID is required"),
|
|
11
|
+
});
|
|
12
|
+
exports.TransactionDataSchema = zod_1.z.object({
|
|
13
|
+
transaction_id: zod_1.z.string().min(1, "Transaction ID is required"),
|
|
14
|
+
latest_timestamp: zod_1.z.string().min(1, "Latest timestamp is required"),
|
|
15
|
+
bap_id: zod_1.z.string().optional(),
|
|
16
|
+
bap_uri: zod_1.z.string().min(1, "BAP URI is required").optional(),
|
|
17
|
+
bpp_id: zod_1.z.string().min(1, "BPP ID is required").optional(),
|
|
18
|
+
bpp_uri: zod_1.z.string().min(1, "BPP URI is required").optional(),
|
|
19
|
+
});
|
|
20
|
+
exports.MockConfigSchema = zod_1.z.object({
|
|
21
|
+
generate: zod_1.z.string(),
|
|
22
|
+
validate: zod_1.z.string(),
|
|
23
|
+
requirements: zod_1.z.string(),
|
|
24
|
+
defaultPayload: zod_1.z.any(),
|
|
25
|
+
saveData: zod_1.z.record(zod_1.z.string(), zod_1.z.string()),
|
|
26
|
+
inputs: zod_1.z.object({
|
|
27
|
+
id: zod_1.z.string().min(1, "Input ID is required").optional(),
|
|
28
|
+
jsonSchema: zod_1.z.any().optional(),
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
31
|
+
exports.PlaygroundActionStepSchema = zod_1.z.object({
|
|
32
|
+
api: zod_1.z.string().min(1, "API is required"),
|
|
33
|
+
action_id: zod_1.z.string().min(1, "Action ID is required"),
|
|
34
|
+
owner: exports.OwnerSchema,
|
|
35
|
+
responseFor: zod_1.z.string().nullable(),
|
|
36
|
+
unsolicited: zod_1.z.boolean(),
|
|
37
|
+
description: zod_1.z.string(),
|
|
38
|
+
mock: exports.MockConfigSchema,
|
|
39
|
+
});
|
|
40
|
+
exports.TransactionHistoryItemSchema = zod_1.z.object({
|
|
41
|
+
action_id: zod_1.z.string().min(1, "Action ID is required"),
|
|
42
|
+
payload: zod_1.z.any(),
|
|
43
|
+
saved_info: zod_1.z.record(zod_1.z.string(), zod_1.z.any()),
|
|
44
|
+
});
|
|
45
|
+
exports.MockPlaygroundConfigSchema = zod_1.z.object({
|
|
46
|
+
meta: exports.MetaSchema,
|
|
47
|
+
transaction_data: exports.TransactionDataSchema,
|
|
48
|
+
steps: zod_1.z.array(exports.PlaygroundActionStepSchema),
|
|
49
|
+
transaction_history: zod_1.z.array(exports.TransactionHistoryItemSchema),
|
|
50
|
+
validationLib: zod_1.z.string(),
|
|
51
|
+
helperLib: zod_1.z.string(),
|
|
52
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error classes for better error handling and debugging
|
|
3
|
+
*/
|
|
4
|
+
export declare class MockRunnerError extends Error {
|
|
5
|
+
readonly code: string;
|
|
6
|
+
readonly context: Record<string, any>;
|
|
7
|
+
readonly timestamp: string;
|
|
8
|
+
constructor(message: string, code: string, context?: Record<string, any>);
|
|
9
|
+
toJSON(): {
|
|
10
|
+
name: string;
|
|
11
|
+
message: string;
|
|
12
|
+
code: string;
|
|
13
|
+
context: Record<string, any>;
|
|
14
|
+
timestamp: string;
|
|
15
|
+
stack: string | undefined;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export declare class ConfigurationError extends MockRunnerError {
|
|
19
|
+
constructor(message: string, context?: Record<string, any>);
|
|
20
|
+
}
|
|
21
|
+
export declare class ValidationError extends MockRunnerError {
|
|
22
|
+
readonly validationErrors: string[];
|
|
23
|
+
constructor(message: string, validationErrors?: string[], context?: Record<string, any>);
|
|
24
|
+
}
|
|
25
|
+
export declare class ExecutionError extends MockRunnerError {
|
|
26
|
+
readonly executionTime: number;
|
|
27
|
+
readonly actionId: string;
|
|
28
|
+
constructor(message: string, actionId: string, executionTime?: number, context?: Record<string, any>);
|
|
29
|
+
}
|
|
30
|
+
export declare class SecurityError extends MockRunnerError {
|
|
31
|
+
readonly securityViolation: string;
|
|
32
|
+
constructor(message: string, violation: string, context?: Record<string, any>);
|
|
33
|
+
}
|
|
34
|
+
export declare class TimeoutError extends MockRunnerError {
|
|
35
|
+
readonly timeoutMs: number;
|
|
36
|
+
constructor(message: string, timeoutMs: number, context?: Record<string, any>);
|
|
37
|
+
}
|
|
38
|
+
export declare class ActionNotFoundError extends MockRunnerError {
|
|
39
|
+
readonly actionId: string;
|
|
40
|
+
readonly availableActions: string[];
|
|
41
|
+
constructor(actionId: string, availableActions?: string[]);
|
|
42
|
+
}
|
|
43
|
+
export declare class SessionDataError extends MockRunnerError {
|
|
44
|
+
readonly stepIndex: number;
|
|
45
|
+
readonly jsonPath: string;
|
|
46
|
+
constructor(message: string, stepIndex: number, jsonPath?: string, context?: Record<string, any>);
|
|
47
|
+
}
|