@marktoflow/core 2.0.0-alpha.7 → 2.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/README.md +24 -220
- package/dist/built-in-operations.d.ts +150 -0
- package/dist/built-in-operations.d.ts.map +1 -0
- package/dist/built-in-operations.js +799 -0
- package/dist/built-in-operations.js.map +1 -0
- package/dist/core-tools.d.ts +39 -0
- package/dist/core-tools.d.ts.map +1 -0
- package/dist/core-tools.js +58 -0
- package/dist/core-tools.js.map +1 -0
- package/dist/credentials.d.ts +60 -1
- package/dist/credentials.d.ts.map +1 -1
- package/dist/credentials.js +229 -4
- package/dist/credentials.js.map +1 -1
- package/dist/engine.d.ts +144 -3
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +1385 -49
- package/dist/engine.js.map +1 -1
- package/dist/file-operations.d.ts +86 -0
- package/dist/file-operations.d.ts.map +1 -0
- package/dist/file-operations.js +363 -0
- package/dist/file-operations.js.map +1 -0
- package/dist/index.d.ts +16 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +46 -4
- package/dist/index.js.map +1 -1
- package/dist/logging.d.ts +40 -2
- package/dist/logging.d.ts.map +1 -1
- package/dist/logging.js +166 -13
- package/dist/logging.js.map +1 -1
- package/dist/models.d.ts +1931 -203
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +303 -13
- package/dist/models.js.map +1 -1
- package/dist/nunjucks-filters.d.ts +271 -0
- package/dist/nunjucks-filters.d.ts.map +1 -0
- package/dist/nunjucks-filters.js +648 -0
- package/dist/nunjucks-filters.js.map +1 -0
- package/dist/oauth-manager.d.ts +128 -0
- package/dist/oauth-manager.d.ts.map +1 -0
- package/dist/oauth-manager.js +291 -0
- package/dist/oauth-manager.js.map +1 -0
- package/dist/oauth-refresh.d.ts +37 -0
- package/dist/oauth-refresh.d.ts.map +1 -0
- package/dist/oauth-refresh.js +76 -0
- package/dist/oauth-refresh.js.map +1 -0
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +291 -10
- package/dist/parser.js.map +1 -1
- package/dist/permissions.d.ts +49 -0
- package/dist/permissions.d.ts.map +1 -0
- package/dist/permissions.js +286 -0
- package/dist/permissions.js.map +1 -0
- package/dist/prompt-loader.d.ts +53 -0
- package/dist/prompt-loader.d.ts.map +1 -0
- package/dist/prompt-loader.js +205 -0
- package/dist/prompt-loader.js.map +1 -0
- package/dist/scheduler.d.ts +22 -3
- package/dist/scheduler.d.ts.map +1 -1
- package/dist/scheduler.js +72 -73
- package/dist/scheduler.js.map +1 -1
- package/dist/script-executor.d.ts +65 -0
- package/dist/script-executor.d.ts.map +1 -0
- package/dist/script-executor.js +261 -0
- package/dist/script-executor.js.map +1 -0
- package/dist/sdk-registry.d.ts +20 -2
- package/dist/sdk-registry.d.ts.map +1 -1
- package/dist/sdk-registry.js +100 -15
- package/dist/sdk-registry.js.map +1 -1
- package/dist/secret-providers/index.d.ts +12 -0
- package/dist/secret-providers/index.d.ts.map +1 -0
- package/dist/secret-providers/index.js +11 -0
- package/dist/secret-providers/index.js.map +1 -0
- package/dist/secret-providers/providers/aws.d.ts +32 -0
- package/dist/secret-providers/providers/aws.d.ts.map +1 -0
- package/dist/secret-providers/providers/aws.js +118 -0
- package/dist/secret-providers/providers/aws.js.map +1 -0
- package/dist/secret-providers/providers/azure.d.ts +40 -0
- package/dist/secret-providers/providers/azure.d.ts.map +1 -0
- package/dist/secret-providers/providers/azure.js +170 -0
- package/dist/secret-providers/providers/azure.js.map +1 -0
- package/dist/secret-providers/providers/env.d.ts +26 -0
- package/dist/secret-providers/providers/env.d.ts.map +1 -0
- package/dist/secret-providers/providers/env.js +59 -0
- package/dist/secret-providers/providers/env.js.map +1 -0
- package/dist/secret-providers/providers/vault.d.ts +39 -0
- package/dist/secret-providers/providers/vault.d.ts.map +1 -0
- package/dist/secret-providers/providers/vault.js +180 -0
- package/dist/secret-providers/providers/vault.js.map +1 -0
- package/dist/secret-providers/secret-manager.d.ts +72 -0
- package/dist/secret-providers/secret-manager.d.ts.map +1 -0
- package/dist/secret-providers/secret-manager.js +226 -0
- package/dist/secret-providers/secret-manager.js.map +1 -0
- package/dist/secret-providers/types.d.ts +105 -0
- package/dist/secret-providers/types.d.ts.map +1 -0
- package/dist/secret-providers/types.js +8 -0
- package/dist/secret-providers/types.js.map +1 -0
- package/dist/security.d.ts +1 -0
- package/dist/security.d.ts.map +1 -1
- package/dist/security.js +4 -0
- package/dist/security.js.map +1 -1
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +16 -9
- package/dist/state.js.map +1 -1
- package/dist/template-engine.d.ts +51 -0
- package/dist/template-engine.d.ts.map +1 -0
- package/dist/template-engine.js +227 -0
- package/dist/template-engine.js.map +1 -0
- package/dist/templates.d.ts +10 -0
- package/dist/templates.d.ts.map +1 -1
- package/dist/templates.js +21 -17
- package/dist/templates.js.map +1 -1
- package/dist/tools/mcp-tool.js +9 -9
- package/dist/tools/mcp-tool.js.map +1 -1
- package/dist/trigger-manager.js +1 -1
- package/dist/trigger-manager.js.map +1 -1
- package/dist/workflow-tools.d.ts +102 -0
- package/dist/workflow-tools.d.ts.map +1 -0
- package/dist/workflow-tools.js +130 -0
- package/dist/workflow-tools.js.map +1 -0
- package/package.json +24 -6
package/dist/scheduler.js
CHANGED
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
* Scheduler for marktoflow v2.0
|
|
3
3
|
*
|
|
4
4
|
* Handles cron-based scheduling of workflow execution.
|
|
5
|
+
* Uses cron-parser for robust cron expression handling with proper
|
|
6
|
+
* DST handling, leap year support, and timezone awareness.
|
|
5
7
|
*/
|
|
8
|
+
import { CronExpressionParser } from 'cron-parser';
|
|
6
9
|
// ============================================================================
|
|
7
|
-
// Cron Parser
|
|
10
|
+
// Cron Parser (wrapper around cron-parser)
|
|
8
11
|
// ============================================================================
|
|
9
12
|
export class CronParser {
|
|
10
13
|
/**
|
|
@@ -17,57 +20,18 @@ export class CronParser {
|
|
|
17
20
|
if (parts.length !== 5) {
|
|
18
21
|
throw new Error(`Invalid cron expression: ${expression}. Expected 5 fields.`);
|
|
19
22
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
// Use cron-parser to validate and parse
|
|
24
|
+
const cronExpr = CronExpressionParser.parse(expression);
|
|
25
|
+
const fields = cronExpr.fields;
|
|
26
|
+
// Extract numeric values from cron fields
|
|
27
|
+
const extractNumbers = (values) => values.filter((v) => typeof v === 'number');
|
|
28
|
+
return {
|
|
29
|
+
minute: extractNumbers(fields.minute.values),
|
|
30
|
+
hour: extractNumbers(fields.hour.values),
|
|
31
|
+
day: extractNumbers(fields.dayOfMonth.values),
|
|
32
|
+
month: extractNumbers(fields.month.values),
|
|
33
|
+
weekday: extractNumbers(fields.dayOfWeek.values),
|
|
26
34
|
};
|
|
27
|
-
const fieldNames = ['minute', 'hour', 'day', 'month', 'weekday'];
|
|
28
|
-
const result = {
|
|
29
|
-
minute: [],
|
|
30
|
-
hour: [],
|
|
31
|
-
day: [],
|
|
32
|
-
month: [],
|
|
33
|
-
weekday: [],
|
|
34
|
-
};
|
|
35
|
-
for (let i = 0; i < fieldNames.length; i++) {
|
|
36
|
-
const name = fieldNames[i];
|
|
37
|
-
const [min, max] = ranges[name];
|
|
38
|
-
result[name] = this.parseField(parts[i], min, max);
|
|
39
|
-
}
|
|
40
|
-
return result;
|
|
41
|
-
}
|
|
42
|
-
static parseField(field, minVal, maxVal) {
|
|
43
|
-
const values = new Set();
|
|
44
|
-
for (const part of field.split(',')) {
|
|
45
|
-
if (part === '*') {
|
|
46
|
-
for (let i = minVal; i <= maxVal; i++) {
|
|
47
|
-
values.add(i);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
else if (part.includes('/')) {
|
|
51
|
-
const [base, stepStr] = part.split('/');
|
|
52
|
-
const step = parseInt(stepStr, 10);
|
|
53
|
-
const start = base === '*' ? minVal : parseInt(base, 10);
|
|
54
|
-
for (let i = start; i <= maxVal; i += step) {
|
|
55
|
-
values.add(i);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
else if (part.includes('-')) {
|
|
59
|
-
const [startStr, endStr] = part.split('-');
|
|
60
|
-
const start = parseInt(startStr, 10);
|
|
61
|
-
const end = parseInt(endStr, 10);
|
|
62
|
-
for (let i = start; i <= end; i++) {
|
|
63
|
-
values.add(i);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
values.add(parseInt(part, 10));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return Array.from(values).sort((a, b) => a - b);
|
|
71
35
|
}
|
|
72
36
|
/**
|
|
73
37
|
* Check if a date matches a cron expression.
|
|
@@ -87,28 +51,63 @@ export class CronParser {
|
|
|
87
51
|
}
|
|
88
52
|
/**
|
|
89
53
|
* Calculate the next run time for a cron expression.
|
|
54
|
+
* Supports timezone-aware scheduling.
|
|
90
55
|
*/
|
|
91
|
-
static nextRun(expression, after) {
|
|
92
|
-
const start = after || new Date();
|
|
56
|
+
static nextRun(expression, after, timezone) {
|
|
93
57
|
try {
|
|
94
|
-
|
|
58
|
+
const cronExpr = CronExpressionParser.parse(expression, {
|
|
59
|
+
currentDate: after ?? new Date(),
|
|
60
|
+
tz: timezone ?? 'UTC',
|
|
61
|
+
});
|
|
62
|
+
return cronExpr.next().toDate();
|
|
95
63
|
}
|
|
96
64
|
catch {
|
|
97
65
|
return null;
|
|
98
66
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Calculate the previous run time for a cron expression.
|
|
70
|
+
*/
|
|
71
|
+
static prevRun(expression, before, timezone) {
|
|
72
|
+
try {
|
|
73
|
+
const cronExpr = CronExpressionParser.parse(expression, {
|
|
74
|
+
currentDate: before ?? new Date(),
|
|
75
|
+
tz: timezone ?? 'UTC',
|
|
76
|
+
});
|
|
77
|
+
return cronExpr.prev().toDate();
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Validate a cron expression without throwing.
|
|
85
|
+
* Only accepts standard 5-field cron expressions.
|
|
86
|
+
*/
|
|
87
|
+
static isValid(expression) {
|
|
88
|
+
if (!expression || typeof expression !== 'string') {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
const parts = expression.trim().split(/\s+/);
|
|
92
|
+
if (parts.length !== 5) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
CronExpressionParser.parse(expression);
|
|
97
|
+
return true;
|
|
110
98
|
}
|
|
111
|
-
|
|
99
|
+
catch {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get the underlying cron-parser CronExpression for advanced usage.
|
|
105
|
+
*/
|
|
106
|
+
static getInterval(expression, options) {
|
|
107
|
+
return CronExpressionParser.parse(expression, {
|
|
108
|
+
currentDate: options?.currentDate ?? new Date(),
|
|
109
|
+
tz: options?.tz ?? 'UTC',
|
|
110
|
+
});
|
|
112
111
|
}
|
|
113
112
|
}
|
|
114
113
|
// ============================================================================
|
|
@@ -127,8 +126,8 @@ export class Scheduler {
|
|
|
127
126
|
* Add a scheduled job.
|
|
128
127
|
*/
|
|
129
128
|
addJob(job) {
|
|
130
|
-
// Calculate next run time
|
|
131
|
-
job.nextRun = CronParser.nextRun(job.schedule);
|
|
129
|
+
// Calculate next run time with timezone support
|
|
130
|
+
job.nextRun = CronParser.nextRun(job.schedule, undefined, job.timezone);
|
|
132
131
|
this.jobs.set(job.id, job);
|
|
133
132
|
}
|
|
134
133
|
/**
|
|
@@ -203,7 +202,7 @@ export class Scheduler {
|
|
|
203
202
|
// Update job state
|
|
204
203
|
job.lastRun = now;
|
|
205
204
|
job.runCount++;
|
|
206
|
-
job.nextRun = CronParser.nextRun(job.schedule, now);
|
|
205
|
+
job.nextRun = CronParser.nextRun(job.schedule, now, job.timezone);
|
|
207
206
|
}
|
|
208
207
|
}
|
|
209
208
|
/**
|
|
@@ -228,7 +227,7 @@ export class Scheduler {
|
|
|
228
227
|
}
|
|
229
228
|
job.lastRun = now;
|
|
230
229
|
job.runCount++;
|
|
231
|
-
job.nextRun = CronParser.nextRun(job.schedule, now);
|
|
230
|
+
job.nextRun = CronParser.nextRun(job.schedule, now, job.timezone);
|
|
232
231
|
results.set(job.id, now);
|
|
233
232
|
}
|
|
234
233
|
return results;
|
|
@@ -243,15 +242,15 @@ export class Scheduler {
|
|
|
243
242
|
// ============================================================================
|
|
244
243
|
// Helper Functions
|
|
245
244
|
// ============================================================================
|
|
246
|
-
export function createJob(id, workflowPath, schedule, inputs = {}) {
|
|
245
|
+
export function createJob(id, workflowPath, schedule, inputs = {}, timezone = 'UTC') {
|
|
247
246
|
return {
|
|
248
247
|
id,
|
|
249
248
|
workflowPath,
|
|
250
249
|
schedule,
|
|
251
|
-
timezone
|
|
250
|
+
timezone,
|
|
252
251
|
enabled: true,
|
|
253
252
|
lastRun: null,
|
|
254
|
-
nextRun: CronParser.nextRun(schedule),
|
|
253
|
+
nextRun: CronParser.nextRun(schedule, undefined, timezone),
|
|
255
254
|
runCount: 0,
|
|
256
255
|
inputs,
|
|
257
256
|
};
|
package/dist/scheduler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,oBAAoB,EAAuB,MAAM,aAAa,CAAC;AA4BxE,+EAA+E;AAC/E,2CAA2C;A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,SAAS,EAAE,CAAC;gBACtC,IAAI,CAAC;oBACH,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAC;gBACtB,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,KAAK,CAAC,uBAAuB,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;gBACzD,CAAC;YACH,CAAC;YAED,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC;YAClB,GAAG,CAAC,QAAQ,EAAE,CAAC;YACf,GAAG,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;YAClE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;QAC3B,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AAED,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E,MAAM,UAAU,SAAS,CACvB,EAAU,EACV,YAAoB,EACpB,QAAgB,EAChB,SAAkC,EAAE,EACpC,WAAmB,KAAK;IAExB,OAAO;QACL,EAAE;QACF,YAAY;QACZ,QAAQ;QACR,QAAQ;QACR,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC;QAC1D,QAAQ,EAAE,CAAC;QACX,MAAM;KACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Script Executor for marktoflow v2.0
|
|
3
|
+
*
|
|
4
|
+
* Provides secure inline JavaScript execution for `script` step types.
|
|
5
|
+
* Uses Node.js `vm` module with:
|
|
6
|
+
* - Frozen context (read-only access to variables/inputs)
|
|
7
|
+
* - Configurable timeout
|
|
8
|
+
* - Safe globals (JSON, Math, Date, Array, etc.)
|
|
9
|
+
*
|
|
10
|
+
* Example usage in workflow:
|
|
11
|
+
* ```yaml
|
|
12
|
+
* - type: script
|
|
13
|
+
* inputs:
|
|
14
|
+
* code: |
|
|
15
|
+
* const items = variables.api_response.items;
|
|
16
|
+
* const filtered = items.filter(i => i.status === 'active');
|
|
17
|
+
* return { filtered, count: filtered.length };
|
|
18
|
+
* timeout: 5000
|
|
19
|
+
* output_variable: result
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export interface ScriptExecutorOptions {
|
|
23
|
+
/** Maximum execution time in milliseconds (default: 5000) */
|
|
24
|
+
timeout?: number;
|
|
25
|
+
/** Additional globals to expose to the script */
|
|
26
|
+
extraGlobals?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
export interface ScriptContext {
|
|
29
|
+
/** Workflow variables (read-only) */
|
|
30
|
+
variables: Record<string, unknown>;
|
|
31
|
+
/** Workflow inputs (read-only) */
|
|
32
|
+
inputs: Record<string, unknown>;
|
|
33
|
+
/** Step results metadata (read-only) */
|
|
34
|
+
steps?: Record<string, unknown>;
|
|
35
|
+
}
|
|
36
|
+
export interface ScriptResult {
|
|
37
|
+
/** Whether the script executed successfully */
|
|
38
|
+
success: boolean;
|
|
39
|
+
/** The return value of the script */
|
|
40
|
+
value?: unknown;
|
|
41
|
+
/** Error message if execution failed */
|
|
42
|
+
error?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Execute a JavaScript code snippet in a sandboxed environment.
|
|
46
|
+
*
|
|
47
|
+
* @param code The JavaScript code to execute
|
|
48
|
+
* @param context Variables and inputs available to the script
|
|
49
|
+
* @param options Execution options (timeout, extra globals)
|
|
50
|
+
* @returns The result of script execution
|
|
51
|
+
*/
|
|
52
|
+
export declare function executeScript(code: string, context: ScriptContext, options?: ScriptExecutorOptions): ScriptResult;
|
|
53
|
+
/**
|
|
54
|
+
* Execute a script asynchronously, properly handling async code.
|
|
55
|
+
*/
|
|
56
|
+
export declare function executeScriptAsync(code: string, context: ScriptContext, options?: ScriptExecutorOptions): Promise<ScriptResult>;
|
|
57
|
+
/**
|
|
58
|
+
* Validate that a script doesn't contain dangerous patterns.
|
|
59
|
+
* This is a basic check; the VM sandbox provides the real security.
|
|
60
|
+
*/
|
|
61
|
+
export declare function validateScript(code: string): {
|
|
62
|
+
valid: boolean;
|
|
63
|
+
warnings: string[];
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=script-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script-executor.d.ts","sourceRoot":"","sources":["../src/script-executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAQH,MAAM,WAAW,qBAAqB;IACpC,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACxC;AAED,MAAM,WAAW,aAAa;IAC5B,qCAAqC;IACrC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,kCAAkC;IAClC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,wCAAwC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,YAAY;IAC3B,+CAA+C;IAC/C,OAAO,EAAE,OAAO,CAAC;IACjB,qCAAqC;IACrC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,wCAAwC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AA4ED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,aAAa,EACtB,OAAO,GAAE,qBAA0B,GAClC,YAAY,CAmEd;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,aAAa,EACtB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,YAAY,CAAC,CAgEvB;AA6BD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAwBnF"}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Script Executor for marktoflow v2.0
|
|
3
|
+
*
|
|
4
|
+
* Provides secure inline JavaScript execution for `script` step types.
|
|
5
|
+
* Uses Node.js `vm` module with:
|
|
6
|
+
* - Frozen context (read-only access to variables/inputs)
|
|
7
|
+
* - Configurable timeout
|
|
8
|
+
* - Safe globals (JSON, Math, Date, Array, etc.)
|
|
9
|
+
*
|
|
10
|
+
* Example usage in workflow:
|
|
11
|
+
* ```yaml
|
|
12
|
+
* - type: script
|
|
13
|
+
* inputs:
|
|
14
|
+
* code: |
|
|
15
|
+
* const items = variables.api_response.items;
|
|
16
|
+
* const filtered = items.filter(i => i.status === 'active');
|
|
17
|
+
* return { filtered, count: filtered.length };
|
|
18
|
+
* timeout: 5000
|
|
19
|
+
* output_variable: result
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import * as vm from 'node:vm';
|
|
23
|
+
// ============================================================================
|
|
24
|
+
// Safe Globals
|
|
25
|
+
// ============================================================================
|
|
26
|
+
/**
|
|
27
|
+
* Safe globals available to scripts.
|
|
28
|
+
* These are frozen copies that cannot modify the original objects.
|
|
29
|
+
*/
|
|
30
|
+
const SAFE_GLOBALS = {
|
|
31
|
+
// JSON operations
|
|
32
|
+
JSON,
|
|
33
|
+
// Math operations - use the real Math object (it's already effectively immutable)
|
|
34
|
+
Math,
|
|
35
|
+
// Date operations
|
|
36
|
+
Date,
|
|
37
|
+
// Array utilities
|
|
38
|
+
Array,
|
|
39
|
+
// Object utilities
|
|
40
|
+
Object,
|
|
41
|
+
// String utilities
|
|
42
|
+
String,
|
|
43
|
+
// Number utilities
|
|
44
|
+
Number: {
|
|
45
|
+
isFinite: Number.isFinite,
|
|
46
|
+
isInteger: Number.isInteger,
|
|
47
|
+
isNaN: Number.isNaN,
|
|
48
|
+
parseFloat: Number.parseFloat,
|
|
49
|
+
parseInt: Number.parseInt,
|
|
50
|
+
},
|
|
51
|
+
// Other safe utilities
|
|
52
|
+
parseInt,
|
|
53
|
+
parseFloat,
|
|
54
|
+
isFinite,
|
|
55
|
+
isNaN,
|
|
56
|
+
encodeURIComponent,
|
|
57
|
+
decodeURIComponent,
|
|
58
|
+
encodeURI,
|
|
59
|
+
decodeURI,
|
|
60
|
+
// Console for debugging (limited to log/warn/error)
|
|
61
|
+
console: {
|
|
62
|
+
log: (...args) => console.log('[script]', ...args),
|
|
63
|
+
warn: (...args) => console.warn('[script]', ...args),
|
|
64
|
+
error: (...args) => console.error('[script]', ...args),
|
|
65
|
+
},
|
|
66
|
+
// Promise is allowed for async operations
|
|
67
|
+
Promise,
|
|
68
|
+
// Timer functions for async operations
|
|
69
|
+
setTimeout,
|
|
70
|
+
clearTimeout,
|
|
71
|
+
setInterval,
|
|
72
|
+
clearInterval,
|
|
73
|
+
// Map and Set
|
|
74
|
+
Map,
|
|
75
|
+
Set,
|
|
76
|
+
// RegExp for pattern matching
|
|
77
|
+
RegExp,
|
|
78
|
+
};
|
|
79
|
+
// ============================================================================
|
|
80
|
+
// Script Execution
|
|
81
|
+
// ============================================================================
|
|
82
|
+
/**
|
|
83
|
+
* Execute a JavaScript code snippet in a sandboxed environment.
|
|
84
|
+
*
|
|
85
|
+
* @param code The JavaScript code to execute
|
|
86
|
+
* @param context Variables and inputs available to the script
|
|
87
|
+
* @param options Execution options (timeout, extra globals)
|
|
88
|
+
* @returns The result of script execution
|
|
89
|
+
*/
|
|
90
|
+
export function executeScript(code, context, options = {}) {
|
|
91
|
+
const timeout = options.timeout ?? 5000;
|
|
92
|
+
try {
|
|
93
|
+
// Create frozen copies of context to prevent modification
|
|
94
|
+
const frozenContext = {
|
|
95
|
+
variables: deepFreeze({ ...context.variables }),
|
|
96
|
+
inputs: deepFreeze({ ...context.inputs }),
|
|
97
|
+
steps: context.steps ? deepFreeze({ ...context.steps }) : undefined,
|
|
98
|
+
};
|
|
99
|
+
// Build the sandbox with safe globals and context
|
|
100
|
+
const sandbox = {
|
|
101
|
+
...SAFE_GLOBALS,
|
|
102
|
+
...frozenContext,
|
|
103
|
+
...(options.extraGlobals ?? {}),
|
|
104
|
+
};
|
|
105
|
+
// Wrap the code in an async IIFE that returns the result
|
|
106
|
+
// This allows `return` statements and async/await
|
|
107
|
+
const wrappedCode = `
|
|
108
|
+
(async () => {
|
|
109
|
+
${code}
|
|
110
|
+
})()
|
|
111
|
+
`;
|
|
112
|
+
// Create a VM context
|
|
113
|
+
const vmContext = vm.createContext(sandbox, {
|
|
114
|
+
name: 'script-executor',
|
|
115
|
+
codeGeneration: {
|
|
116
|
+
strings: false, // Disable eval() and Function()
|
|
117
|
+
wasm: false, // Disable WebAssembly
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
// Compile and run the script
|
|
121
|
+
const script = new vm.Script(wrappedCode, {
|
|
122
|
+
filename: 'inline-script.js',
|
|
123
|
+
});
|
|
124
|
+
// Run with timeout
|
|
125
|
+
const resultPromise = script.runInContext(vmContext, {
|
|
126
|
+
timeout,
|
|
127
|
+
displayErrors: true,
|
|
128
|
+
});
|
|
129
|
+
// Handle both sync and async results
|
|
130
|
+
if (resultPromise instanceof Promise) {
|
|
131
|
+
// For async code, we need to handle the promise
|
|
132
|
+
// Since this is a sync function, we'll need to handle this specially
|
|
133
|
+
// The caller should await the result if it's a promise
|
|
134
|
+
return {
|
|
135
|
+
success: true,
|
|
136
|
+
value: resultPromise,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
success: true,
|
|
141
|
+
value: resultPromise,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
return {
|
|
146
|
+
success: false,
|
|
147
|
+
error: error instanceof Error ? error.message : String(error),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Execute a script asynchronously, properly handling async code.
|
|
153
|
+
*/
|
|
154
|
+
export async function executeScriptAsync(code, context, options = {}) {
|
|
155
|
+
const timeout = options.timeout ?? 5000;
|
|
156
|
+
try {
|
|
157
|
+
// Create frozen copies of context to prevent modification
|
|
158
|
+
const frozenContext = {
|
|
159
|
+
variables: deepFreeze({ ...context.variables }),
|
|
160
|
+
inputs: deepFreeze({ ...context.inputs }),
|
|
161
|
+
steps: context.steps ? deepFreeze({ ...context.steps }) : undefined,
|
|
162
|
+
};
|
|
163
|
+
// Build the sandbox with safe globals and context
|
|
164
|
+
const sandbox = {
|
|
165
|
+
...SAFE_GLOBALS,
|
|
166
|
+
...frozenContext,
|
|
167
|
+
...(options.extraGlobals ?? {}),
|
|
168
|
+
};
|
|
169
|
+
// Wrap the code in an async IIFE
|
|
170
|
+
const wrappedCode = `
|
|
171
|
+
(async () => {
|
|
172
|
+
${code}
|
|
173
|
+
})()
|
|
174
|
+
`;
|
|
175
|
+
// Create a VM context
|
|
176
|
+
const vmContext = vm.createContext(sandbox, {
|
|
177
|
+
name: 'script-executor',
|
|
178
|
+
codeGeneration: {
|
|
179
|
+
strings: false,
|
|
180
|
+
wasm: false,
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
// Compile the script
|
|
184
|
+
const script = new vm.Script(wrappedCode, {
|
|
185
|
+
filename: 'inline-script.js',
|
|
186
|
+
});
|
|
187
|
+
// Run with timeout using a race
|
|
188
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
189
|
+
setTimeout(() => reject(new Error(`Script execution timed out after ${timeout}ms`)), timeout);
|
|
190
|
+
});
|
|
191
|
+
const resultPromise = script.runInContext(vmContext, {
|
|
192
|
+
displayErrors: true,
|
|
193
|
+
});
|
|
194
|
+
// Wait for result or timeout
|
|
195
|
+
const result = await Promise.race([
|
|
196
|
+
resultPromise instanceof Promise ? resultPromise : Promise.resolve(resultPromise),
|
|
197
|
+
timeoutPromise,
|
|
198
|
+
]);
|
|
199
|
+
return {
|
|
200
|
+
success: true,
|
|
201
|
+
value: result,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
return {
|
|
206
|
+
success: false,
|
|
207
|
+
error: error instanceof Error ? error.message : String(error),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// ============================================================================
|
|
212
|
+
// Utility Functions
|
|
213
|
+
// ============================================================================
|
|
214
|
+
/**
|
|
215
|
+
* Deep freeze an object to prevent any modifications.
|
|
216
|
+
*/
|
|
217
|
+
function deepFreeze(obj) {
|
|
218
|
+
if (obj === null || typeof obj !== 'object') {
|
|
219
|
+
return obj;
|
|
220
|
+
}
|
|
221
|
+
// Freeze arrays and objects recursively
|
|
222
|
+
if (Array.isArray(obj)) {
|
|
223
|
+
obj.forEach((item) => deepFreeze(item));
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
Object.keys(obj).forEach((key) => {
|
|
227
|
+
const value = obj[key];
|
|
228
|
+
if (typeof value === 'object' && value !== null) {
|
|
229
|
+
deepFreeze(value);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
return Object.freeze(obj);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Validate that a script doesn't contain dangerous patterns.
|
|
237
|
+
* This is a basic check; the VM sandbox provides the real security.
|
|
238
|
+
*/
|
|
239
|
+
export function validateScript(code) {
|
|
240
|
+
const warnings = [];
|
|
241
|
+
// Check for common dangerous patterns
|
|
242
|
+
const dangerousPatterns = [
|
|
243
|
+
{ pattern: /require\s*\(/, message: 'require() is not available in scripts' },
|
|
244
|
+
{ pattern: /import\s+/, message: 'import statements are not available in scripts' },
|
|
245
|
+
{ pattern: /process\./, message: 'process object is not available in scripts' },
|
|
246
|
+
{ pattern: /global\./, message: 'global object is not available in scripts' },
|
|
247
|
+
{ pattern: /globalThis\./, message: 'globalThis is not available in scripts' },
|
|
248
|
+
{ pattern: /eval\s*\(/, message: 'eval() is not available in scripts' },
|
|
249
|
+
{ pattern: /Function\s*\(/, message: 'Function constructor is not available in scripts' },
|
|
250
|
+
];
|
|
251
|
+
for (const { pattern, message } of dangerousPatterns) {
|
|
252
|
+
if (pattern.test(code)) {
|
|
253
|
+
warnings.push(message);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
valid: warnings.length === 0,
|
|
258
|
+
warnings,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
//# sourceMappingURL=script-executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script-executor.js","sourceRoot":"","sources":["../src/script-executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AA+B9B,+EAA+E;AAC/E,eAAe;AACf,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,YAAY,GAA4B;IAC5C,kBAAkB;IAClB,IAAI;IAEJ,kFAAkF;IAClF,IAAI;IAEJ,kBAAkB;IAClB,IAAI;IAEJ,kBAAkB;IAClB,KAAK;IAEL,mBAAmB;IACnB,MAAM;IAEN,mBAAmB;IACnB,MAAM;IAEN,mBAAmB;IACnB,MAAM,EAAE;QACN,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,QAAQ,EAAE,MAAM,CAAC,QAAQ;KAC1B;IAED,uBAAuB;IACvB,QAAQ;IACR,UAAU;IACV,QAAQ;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AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,sCAAsC;IACtC,MAAM,iBAAiB,GAAG;QACxB,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,uCAAuC,EAAE;QAC7E,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,gDAAgD,EAAE;QACnF,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,4CAA4C,EAAE;QAC/E,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,2CAA2C,EAAE;QAC7E,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,wCAAwC,EAAE;QAC9E,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,oCAAoC,EAAE;QACvE,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,kDAAkD,EAAE;KAC1F,CAAC;IAEF,KAAK,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,iBAAiB,EAAE,CAAC;QACrD,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAED,OAAO;QACL,KAAK,EAAE,QAAQ,CAAC,MAAM,KAAK,CAAC;QAC5B,QAAQ;KACT,CAAC;AACJ,CAAC"}
|
package/dist/sdk-registry.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { ToolConfig } from './models.js';
|
|
8
8
|
import { McpLoader } from './mcp-loader.js';
|
|
9
|
+
import { SecretManager } from './secret-providers/secret-manager.js';
|
|
9
10
|
export interface SDKInstance {
|
|
10
11
|
name: string;
|
|
11
12
|
sdk: unknown;
|
|
@@ -29,13 +30,19 @@ export interface SDKInitializer {
|
|
|
29
30
|
initialize(module: unknown, config: ToolConfig): Promise<unknown>;
|
|
30
31
|
}
|
|
31
32
|
export declare const defaultSDKLoader: SDKLoader;
|
|
33
|
+
/**
|
|
34
|
+
* Maps SDK names to actual npm package names.
|
|
35
|
+
* Used when the SDK name in workflows differs from the npm package name.
|
|
36
|
+
*/
|
|
37
|
+
export declare const packageNameMappings: Record<string, string>;
|
|
32
38
|
export declare const defaultInitializers: Record<string, SDKInitializer>;
|
|
33
39
|
export declare class SDKRegistry {
|
|
34
40
|
private sdks;
|
|
35
41
|
private loader;
|
|
36
42
|
private initializers;
|
|
37
43
|
private mcpLoader;
|
|
38
|
-
|
|
44
|
+
private secretManager?;
|
|
45
|
+
constructor(loader?: SDKLoader, initializers?: Record<string, SDKInitializer>, mcpLoader?: McpLoader, secretManager?: SecretManager);
|
|
39
46
|
/**
|
|
40
47
|
* Register tool configurations from a workflow.
|
|
41
48
|
*/
|
|
@@ -48,6 +55,10 @@ export declare class SDKRegistry {
|
|
|
48
55
|
* Load and initialize an SDK.
|
|
49
56
|
*/
|
|
50
57
|
load(name: string): Promise<unknown>;
|
|
58
|
+
/**
|
|
59
|
+
* Resolve secret references in tool configuration.
|
|
60
|
+
*/
|
|
61
|
+
private resolveConfigSecrets;
|
|
51
62
|
private isMcpModule;
|
|
52
63
|
private createMcpProxy;
|
|
53
64
|
/**
|
|
@@ -71,6 +82,13 @@ export interface SDKRegistryLike {
|
|
|
71
82
|
load(sdkName: string): Promise<unknown>;
|
|
72
83
|
has(sdkName: string): boolean;
|
|
73
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Execution context interface for step executor
|
|
87
|
+
*/
|
|
88
|
+
export interface ExecutionContextLike {
|
|
89
|
+
variables: Record<string, unknown>;
|
|
90
|
+
inputs: Record<string, unknown>;
|
|
91
|
+
}
|
|
74
92
|
/**
|
|
75
93
|
* Create a step executor that invokes SDK methods.
|
|
76
94
|
*/
|
|
@@ -78,5 +96,5 @@ export declare function createSDKStepExecutor(): (step: {
|
|
|
78
96
|
action?: string;
|
|
79
97
|
workflow?: string;
|
|
80
98
|
inputs: Record<string, unknown>;
|
|
81
|
-
},
|
|
99
|
+
}, executionContext: unknown, sdkRegistry: SDKRegistryLike) => Promise<unknown>;
|
|
82
100
|
//# sourceMappingURL=sdk-registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk-registry.d.ts","sourceRoot":"","sources":["../src/sdk-registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"sdk-registry.d.ts","sourceRoot":"","sources":["../src/sdk-registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAMrE,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,OAAO,CAAC;IACb,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,MAAM,WAAW,SAAS;IACxB;;;;OAIG;IACH,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACnE;AAMD,eAAO,MAAM,gBAAgB,EAAE,SAa9B,CAAC;AAMF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAMtD,CAAC;AAMF,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAmF9D,CAAC;AAMF,qBAAa,WAAW;IACtB,OAAO,CAAC,IAA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