digitalsee-ai-flow-cli 0.9.24-beta → 0.9.29-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +146 -2
- package/dist/api/client.js +9 -0
- package/dist/api/flow.js +4 -1
- package/dist/api/node.js +78 -7
- package/dist/api/trigger.js +242 -0
- package/dist/commands/flow/account.js +439 -1
- package/dist/commands/flow/analyze.js +10 -2
- package/dist/commands/flow/export.js +29 -4
- package/dist/commands/flow/helpers.js +439 -53
- package/dist/commands/flow/node.js +290 -32
- package/dist/commands/flow/offline.js +3 -2
- package/dist/commands/flow/trigger.js +190 -0
- package/dist/commands/flow/validate.js +57 -0
- package/dist/commands/flow/variables.js +1 -0
- package/dist/commands/flow.js +2 -0
- package/dist/constants/node-type.js +23 -0
- package/dist/services/classicNodePorts.js +167 -368
- package/dist/services/fieldTypeRegistry.js +496 -0
- package/dist/services/flowAnalyzer.js +8 -1
- package/dist/services/flowValidator.js +145 -0
- package/dist/services/portValidator.js +76 -70
- package/dist/services/skillGenerator.js +236 -194
- package/dist/services/triggerConfig.js +252 -0
- package/dist/utils/conditionRules.js +128 -0
- package/dist/utils/format.js +268 -168
- package/dist/utils/nodeEnvelope.js +128 -0
- package/dist/utils/switchBranch.js +83 -0
- package/dist/utils/updateCheck.js +50 -6
- package/package.json +1 -1
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WEBHOOK_RESPONSE_MODES = exports.WEBHOOK_HTTP_METHODS = void 0;
|
|
4
|
+
exports.validateCronExpression = validateCronExpression;
|
|
5
|
+
exports.validateTimezone = validateTimezone;
|
|
6
|
+
exports.validateWebhookPath = validateWebhookPath;
|
|
7
|
+
exports.isValidHttpMethod = isValidHttpMethod;
|
|
8
|
+
exports.isValidResponseMode = isValidResponseMode;
|
|
9
|
+
exports.validateWebhookAuth = validateWebhookAuth;
|
|
10
|
+
exports.normalizeCronTriggerConfig = normalizeCronTriggerConfig;
|
|
11
|
+
exports.normalizeWebhookTriggerConfig = normalizeWebhookTriggerConfig;
|
|
12
|
+
exports.formatTriggerConfig = formatTriggerConfig;
|
|
13
|
+
/**
|
|
14
|
+
* 触发器配置校验与归一化(对齐 rcs/DIP 契约 DipTriggerConfig,dip.types.ts:203-270)。
|
|
15
|
+
*
|
|
16
|
+
* 三种模式:
|
|
17
|
+
* - manual: 手动触发
|
|
18
|
+
* - cron: { expression, timezone },Quartz 风格表达式(6-7 段,秒开头,`?` 支持)
|
|
19
|
+
* - webhook: { path, httpMethod: GET|POST, responseMode: IMMEDIATE|LAST_NODE|CUSTOM,
|
|
20
|
+
* responseData?, authRequired?, authHeaderName?, authHeaderValue? }
|
|
21
|
+
*/
|
|
22
|
+
const FIELD_NAME_PATTERN = /^[a-zA-Z][a-zA-Z0-9_-]*$/;
|
|
23
|
+
/** Quartz 周名称缩写(1=SUN ... 7=SAT),解析为数字后按 1-7 校验 */
|
|
24
|
+
const WEEKDAY_NAMES = {
|
|
25
|
+
SUN: 1,
|
|
26
|
+
MON: 2,
|
|
27
|
+
TUE: 3,
|
|
28
|
+
WED: 4,
|
|
29
|
+
THU: 5,
|
|
30
|
+
FRI: 6,
|
|
31
|
+
SAT: 7,
|
|
32
|
+
};
|
|
33
|
+
/** Quartz cron 段取值范围(秒 分 时 日 月 周 [年]) */
|
|
34
|
+
const CRON_FIELD_RANGES = [
|
|
35
|
+
[0, 59], // 秒
|
|
36
|
+
[0, 59], // 分
|
|
37
|
+
[0, 23], // 时
|
|
38
|
+
[1, 31], // 日
|
|
39
|
+
[1, 12], // 月
|
|
40
|
+
[1, 7], // 周(Quartz 1=SUN ... 7=SAT)
|
|
41
|
+
[1970, 2099], // 年(可选)
|
|
42
|
+
];
|
|
43
|
+
/** 每段是否支持周名称(仅第 6 段周字段) */
|
|
44
|
+
function fieldAllowsWeekdayNames(index) {
|
|
45
|
+
return index === 5;
|
|
46
|
+
}
|
|
47
|
+
function parseAtom(atom, min, max, allowWeekday) {
|
|
48
|
+
if (/^\d+$/.test(atom)) {
|
|
49
|
+
const n = Number(atom);
|
|
50
|
+
return n >= min && n <= max ? n : null;
|
|
51
|
+
}
|
|
52
|
+
if (allowWeekday) {
|
|
53
|
+
const weekday = WEEKDAY_NAMES[atom.toUpperCase()];
|
|
54
|
+
if (weekday !== undefined && weekday >= min && weekday <= max)
|
|
55
|
+
return weekday;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 校验 Quartz 风格 cron 表达式(如 `0 0/5 * * * ?`)。
|
|
61
|
+
*
|
|
62
|
+
* 支持 6 段(秒 分 时 日 月 周)或 7 段(+ 年);每段支持
|
|
63
|
+
* `*`、`?`、数字、区间 `a-b`、步长 `n/m`、列表 `a,b,c` 的任意组合。
|
|
64
|
+
* 周字段用 1-7(Quartz),年字段 1970-2099。
|
|
65
|
+
*/
|
|
66
|
+
function validateCronExpression(expression) {
|
|
67
|
+
const trimmed = (expression || '').trim();
|
|
68
|
+
if (!trimmed)
|
|
69
|
+
return 'cron 表达式不能为空';
|
|
70
|
+
if (/\s{2,}/.test(trimmed))
|
|
71
|
+
return 'cron 表达式包含多余空格';
|
|
72
|
+
if (trimmed !== expression)
|
|
73
|
+
return 'cron 表达式首尾包含空白字符';
|
|
74
|
+
const fields = trimmed.split(' ');
|
|
75
|
+
if (fields.length !== 6 && fields.length !== 7) {
|
|
76
|
+
return `cron 表达式应为 6 或 7 段(秒 分 时 日 月 周 [年]),实际为 ${fields.length} 段`;
|
|
77
|
+
}
|
|
78
|
+
for (let i = 0; i < fields.length; i++) {
|
|
79
|
+
const field = fields[i];
|
|
80
|
+
const [min, max] = CRON_FIELD_RANGES[i];
|
|
81
|
+
if (!field)
|
|
82
|
+
return `cron 表达式第 ${i + 1} 段为空`;
|
|
83
|
+
const allowWeekday = fieldAllowsWeekdayNames(i);
|
|
84
|
+
for (const part of field.split(',')) {
|
|
85
|
+
if (!part)
|
|
86
|
+
return `cron 表达式第 ${i + 1} 段(${field})包含空列表项`;
|
|
87
|
+
// 每个列表项:原子 或 原子-原子 或 原子/步长 或 原子-原子/步长
|
|
88
|
+
const stepMatch = part.match(/^(.+?)\/(\d+)$/);
|
|
89
|
+
const body = stepMatch ? stepMatch[1] : part;
|
|
90
|
+
const step = stepMatch ? Number(stepMatch[2]) : null;
|
|
91
|
+
if (step !== null && (step < 1 || step > max)) {
|
|
92
|
+
return `cron 表达式第 ${i + 1} 段(${field})步长 ${step} 超出范围 1-${max}`;
|
|
93
|
+
}
|
|
94
|
+
// * / ? 通配形式
|
|
95
|
+
if (body === '*' || body === '?')
|
|
96
|
+
continue;
|
|
97
|
+
const rangeMatch = body.match(/^([A-Za-z0-9]+)-([A-Za-z0-9]+)$/);
|
|
98
|
+
if (rangeMatch) {
|
|
99
|
+
const lo = parseAtom(rangeMatch[1], min, max, allowWeekday);
|
|
100
|
+
const hi = parseAtom(rangeMatch[2], min, max, allowWeekday);
|
|
101
|
+
if (lo === null || hi === null) {
|
|
102
|
+
return `cron 表达式第 ${i + 1} 段(${field})取值 "${body}" 超出范围 ${min}-${max}`;
|
|
103
|
+
}
|
|
104
|
+
if (lo > hi) {
|
|
105
|
+
return `cron 表达式第 ${i + 1} 段(${field})区间 ${body} 起点大于终点`;
|
|
106
|
+
}
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (parseAtom(body, min, max, allowWeekday) === null) {
|
|
110
|
+
return `cron 表达式第 ${i + 1} 段(${field})值 "${body}" 非法(范围 ${min}-${max})`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
/** 校验 IANA 时区标识(宽松校验:非空、不含空白、长度合理) */
|
|
117
|
+
function validateTimezone(timezone) {
|
|
118
|
+
const trimmed = (timezone || '').trim();
|
|
119
|
+
if (!trimmed)
|
|
120
|
+
return 'timezone 不能为空';
|
|
121
|
+
if (/\s/.test(trimmed))
|
|
122
|
+
return `timezone "${timezone}" 包含空白字符`;
|
|
123
|
+
if (trimmed.length > 64)
|
|
124
|
+
return 'timezone 过长(最大 64 字符)';
|
|
125
|
+
if (!/^[A-Za-z0-9/_+\-]+$/.test(trimmed)) {
|
|
126
|
+
return `timezone "${timezone}" 含非法字符(仅允许字母、数字、/、_、+、-)`;
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
/** 校验 webhook path:必须以 / 开头的合法 URL 路径 */
|
|
131
|
+
function validateWebhookPath(path) {
|
|
132
|
+
const trimmed = (path || '').trim();
|
|
133
|
+
if (!trimmed)
|
|
134
|
+
return 'path 不能为空';
|
|
135
|
+
if (trimmed !== path)
|
|
136
|
+
return 'path 首尾包含空白字符';
|
|
137
|
+
if (!trimmed.startsWith('/'))
|
|
138
|
+
return `path "${path}" 必须以 / 开头`;
|
|
139
|
+
if (trimmed.length > 256)
|
|
140
|
+
return 'path 过长(最大 256 字符)';
|
|
141
|
+
if (!/^[A-Za-z0-9\-._~!$&'()*+,;=:@/%?]+$/.test(trimmed)) {
|
|
142
|
+
return `path "${path}" 含非法字符`;
|
|
143
|
+
}
|
|
144
|
+
if (trimmed.includes('//'))
|
|
145
|
+
return `path "${path}" 包含连续的 /`;
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
exports.WEBHOOK_HTTP_METHODS = ['GET', 'POST'];
|
|
149
|
+
exports.WEBHOOK_RESPONSE_MODES = ['IMMEDIATE', 'LAST_NODE', 'CUSTOM'];
|
|
150
|
+
function isValidHttpMethod(method) {
|
|
151
|
+
return exports.WEBHOOK_HTTP_METHODS.includes(method);
|
|
152
|
+
}
|
|
153
|
+
function isValidResponseMode(mode) {
|
|
154
|
+
return exports.WEBHOOK_RESPONSE_MODES.includes(mode);
|
|
155
|
+
}
|
|
156
|
+
function validateWebhookAuth(authHeaderName, authHeaderValue) {
|
|
157
|
+
const hasName = authHeaderName !== undefined && authHeaderName !== '';
|
|
158
|
+
const hasValue = authHeaderValue !== undefined && authHeaderValue !== '';
|
|
159
|
+
if (hasName !== hasValue) {
|
|
160
|
+
return 'authHeaderName 与 authHeaderValue 必须成对提供';
|
|
161
|
+
}
|
|
162
|
+
if (hasName && !FIELD_NAME_PATTERN.test(authHeaderName)) {
|
|
163
|
+
return `authHeaderName "${authHeaderName}" 非法(以字母开头,仅允许字母、数字、-、_)`;
|
|
164
|
+
}
|
|
165
|
+
if (hasValue && authHeaderValue.length > 512) {
|
|
166
|
+
return 'authHeaderValue 过长(最大 512 字符)';
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
/** 校验并归一化 cron 触发器配置,返回错误信息或 null */
|
|
171
|
+
function normalizeCronTriggerConfig(input) {
|
|
172
|
+
const expression = (input.expression || '').trim();
|
|
173
|
+
const cronError = validateCronExpression(expression);
|
|
174
|
+
if (cronError)
|
|
175
|
+
return cronError;
|
|
176
|
+
const config = { mode: 'cron', expression };
|
|
177
|
+
if (input.timezone !== undefined && input.timezone !== '') {
|
|
178
|
+
const tz = input.timezone.trim();
|
|
179
|
+
const tzError = validateTimezone(tz);
|
|
180
|
+
if (tzError)
|
|
181
|
+
return tzError;
|
|
182
|
+
config.timezone = tz;
|
|
183
|
+
}
|
|
184
|
+
return config;
|
|
185
|
+
}
|
|
186
|
+
/** 校验并归一化 webhook 触发器配置,返回配置或错误信息 */
|
|
187
|
+
function normalizeWebhookTriggerConfig(input) {
|
|
188
|
+
const pathError = validateWebhookPath(input.path || '');
|
|
189
|
+
if (pathError)
|
|
190
|
+
return pathError;
|
|
191
|
+
const method = (input.httpMethod || '').toUpperCase();
|
|
192
|
+
if (!isValidHttpMethod(method)) {
|
|
193
|
+
return `httpMethod "${input.httpMethod}" 非法,可选值: ${exports.WEBHOOK_HTTP_METHODS.join(' | ')}`;
|
|
194
|
+
}
|
|
195
|
+
const responseMode = (input.responseMode || 'IMMEDIATE').toUpperCase();
|
|
196
|
+
if (!isValidResponseMode(responseMode)) {
|
|
197
|
+
return `responseMode "${input.responseMode}" 非法,可选值: ${exports.WEBHOOK_RESPONSE_MODES.join(' | ')}`;
|
|
198
|
+
}
|
|
199
|
+
const config = {
|
|
200
|
+
mode: 'webhook',
|
|
201
|
+
path: input.path.trim(),
|
|
202
|
+
httpMethod: method,
|
|
203
|
+
responseMode,
|
|
204
|
+
};
|
|
205
|
+
if (responseMode === 'CUSTOM') {
|
|
206
|
+
if (input.responseData === undefined || input.responseData === '') {
|
|
207
|
+
return 'responseMode=CUSTOM 时必须提供 responseData';
|
|
208
|
+
}
|
|
209
|
+
config.responseData = input.responseData;
|
|
210
|
+
}
|
|
211
|
+
else if (input.responseData !== undefined && input.responseData !== '') {
|
|
212
|
+
config.responseData = input.responseData;
|
|
213
|
+
}
|
|
214
|
+
if (input.authRequired !== undefined) {
|
|
215
|
+
config.authRequired = input.authRequired;
|
|
216
|
+
}
|
|
217
|
+
if (input.authHeaderName !== undefined || input.authHeaderValue !== undefined) {
|
|
218
|
+
const authError = validateWebhookAuth(input.authHeaderName, input.authHeaderValue);
|
|
219
|
+
if (authError)
|
|
220
|
+
return authError;
|
|
221
|
+
config.authRequired = input.authRequired ?? true;
|
|
222
|
+
config.authHeaderName = input.authHeaderName;
|
|
223
|
+
config.authHeaderValue = input.authHeaderValue;
|
|
224
|
+
}
|
|
225
|
+
return config;
|
|
226
|
+
}
|
|
227
|
+
/** 渲染 TriggerConfig 为人类可读键值对 */
|
|
228
|
+
function formatTriggerConfig(config) {
|
|
229
|
+
const pairs = [['类型', config.mode]];
|
|
230
|
+
if (config.mode === 'cron') {
|
|
231
|
+
pairs.push(['表达式', config.expression]);
|
|
232
|
+
pairs.push(['时区', config.timezone || '(默认)']);
|
|
233
|
+
}
|
|
234
|
+
else if (config.mode === 'webhook') {
|
|
235
|
+
pairs.push(['路径', config.path]);
|
|
236
|
+
pairs.push(['HTTP 方法', config.httpMethod]);
|
|
237
|
+
pairs.push(['响应模式', config.responseMode]);
|
|
238
|
+
if (config.responseMode === 'CUSTOM' && config.responseData) {
|
|
239
|
+
pairs.push(['响应数据', config.responseData]);
|
|
240
|
+
}
|
|
241
|
+
pairs.push(['鉴权', config.authRequired ? '启用' : '未启用']);
|
|
242
|
+
if (config.authRequired && config.authHeaderName) {
|
|
243
|
+
pairs.push(['鉴权 Header', config.authHeaderName]);
|
|
244
|
+
if (config.authHeaderValue) {
|
|
245
|
+
const v = config.authHeaderValue;
|
|
246
|
+
pairs.push(['鉴权值', v.length > 8 ? `${v.slice(0, 4)}****${v.slice(-4)}` : '****']);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return pairs;
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=triggerConfig.js.map
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CONDITION_OPERATORS = void 0;
|
|
4
|
+
exports.safeSample = safeSample;
|
|
5
|
+
exports.validateOrList = validateOrList;
|
|
6
|
+
const VALID_CONDITION_OPERATORS = new Set([
|
|
7
|
+
'eq',
|
|
8
|
+
'ne',
|
|
9
|
+
'sw',
|
|
10
|
+
'nsw',
|
|
11
|
+
'ew',
|
|
12
|
+
'ewn',
|
|
13
|
+
'gt',
|
|
14
|
+
'ge',
|
|
15
|
+
'lt',
|
|
16
|
+
'le',
|
|
17
|
+
'co',
|
|
18
|
+
'nco',
|
|
19
|
+
'in',
|
|
20
|
+
'nin',
|
|
21
|
+
'is_null',
|
|
22
|
+
'is_not_null',
|
|
23
|
+
]);
|
|
24
|
+
exports.CONDITION_OPERATORS = [...VALID_CONDITION_OPERATORS];
|
|
25
|
+
const NULL_OPERATORS = new Set(['is_null', 'is_not_null']);
|
|
26
|
+
function safeSample(val) {
|
|
27
|
+
return (JSON.stringify(val) ?? '').substring(0, 80);
|
|
28
|
+
}
|
|
29
|
+
function validateOrList(orList, path) {
|
|
30
|
+
const errors = [];
|
|
31
|
+
if (!Array.isArray(orList)) {
|
|
32
|
+
errors.push({
|
|
33
|
+
field: path,
|
|
34
|
+
rule: 'type',
|
|
35
|
+
message: `${path} 必须是 array 类型`,
|
|
36
|
+
sample: safeSample(orList),
|
|
37
|
+
});
|
|
38
|
+
return errors;
|
|
39
|
+
}
|
|
40
|
+
if (orList.length === 0) {
|
|
41
|
+
errors.push({
|
|
42
|
+
field: path,
|
|
43
|
+
rule: 'required',
|
|
44
|
+
message: `${path} 至少需要 1 个条件组`,
|
|
45
|
+
sample: '',
|
|
46
|
+
});
|
|
47
|
+
return errors;
|
|
48
|
+
}
|
|
49
|
+
orList.forEach((orItem, i) => {
|
|
50
|
+
const orPath = `${path}[${i}]`;
|
|
51
|
+
if (!orItem || typeof orItem !== 'object') {
|
|
52
|
+
errors.push({
|
|
53
|
+
field: orPath,
|
|
54
|
+
rule: 'type',
|
|
55
|
+
message: `${orPath} 必须是 object 类型`,
|
|
56
|
+
sample: safeSample(orItem),
|
|
57
|
+
});
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const andList = orItem.and_list;
|
|
61
|
+
if (!Array.isArray(andList)) {
|
|
62
|
+
errors.push({
|
|
63
|
+
field: `${orPath}.and_list`,
|
|
64
|
+
rule: 'type',
|
|
65
|
+
message: `${orPath}.and_list 必须是 array 类型`,
|
|
66
|
+
sample: safeSample(andList),
|
|
67
|
+
});
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (andList.length === 0) {
|
|
71
|
+
errors.push({
|
|
72
|
+
field: `${orPath}.and_list`,
|
|
73
|
+
rule: 'required',
|
|
74
|
+
message: `${orPath}.and_list 至少需要 1 个条件`,
|
|
75
|
+
sample: '',
|
|
76
|
+
});
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
andList.forEach((item, j) => {
|
|
80
|
+
const itemPath = `${orPath}.and_list[${j}]`;
|
|
81
|
+
if (!item || typeof item !== 'object') {
|
|
82
|
+
errors.push({
|
|
83
|
+
field: itemPath,
|
|
84
|
+
rule: 'type',
|
|
85
|
+
message: `${itemPath} 必须是 object 类型`,
|
|
86
|
+
sample: safeSample(item),
|
|
87
|
+
});
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (!item.query || typeof item.query !== 'string' || !item.query.trim()) {
|
|
91
|
+
errors.push({
|
|
92
|
+
field: `${itemPath}.query`,
|
|
93
|
+
rule: 'required',
|
|
94
|
+
message: `${itemPath}.query 是必填字段,须为变量引用`,
|
|
95
|
+
sample: '',
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (!item.operator || typeof item.operator !== 'string') {
|
|
99
|
+
errors.push({
|
|
100
|
+
field: `${itemPath}.operator`,
|
|
101
|
+
rule: 'required',
|
|
102
|
+
message: `${itemPath}.operator 是必填字段`,
|
|
103
|
+
sample: '',
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
else if (!VALID_CONDITION_OPERATORS.has(item.operator)) {
|
|
107
|
+
errors.push({
|
|
108
|
+
field: `${itemPath}.operator`,
|
|
109
|
+
rule: 'type',
|
|
110
|
+
message: `${itemPath}.operator 无效: "${item.operator}",有效值: ${[...VALID_CONDITION_OPERATORS].join(', ')}`,
|
|
111
|
+
sample: item.operator,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
if (item.operator &&
|
|
115
|
+
!NULL_OPERATORS.has(item.operator) &&
|
|
116
|
+
(item.value === undefined || item.value === null)) {
|
|
117
|
+
errors.push({
|
|
118
|
+
field: `${itemPath}.value`,
|
|
119
|
+
rule: 'required',
|
|
120
|
+
message: `${itemPath}.value 在运算符为 "${item.operator}" 时必须提供`,
|
|
121
|
+
sample: '',
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
return errors;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=conditionRules.js.map
|