gbflowengine 0.0.0-stage → 0.1.0
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 +21 -0
- package/README.md +271 -3
- package/dist/gbflowengine.css +1 -0
- package/dist/gbflowengine.js +18363 -0
- package/dist/gbflowengine.js.map +1 -0
- package/dist/gbflowengine.umd.cjs +5 -0
- package/dist/gbflowengine.umd.cjs.map +1 -0
- package/package.json +84 -6
- package/src/center/DefinitionInspect.vue +291 -0
- package/src/center/FlowCenter.vue +33 -0
- package/src/center/index.js +29 -0
- package/src/center/storage.js +748 -0
- package/src/core/flow/condition.js +160 -0
- package/src/core/flow/customNode.js +385 -0
- package/src/core/flow/defaults.js +124 -0
- package/src/core/flow/flowConstant.js +265 -0
- package/src/core/flow/flowNodeUtils.js +30 -0
- package/src/core/flow/index.js +47 -0
- package/src/core/flow/node.js +44 -0
- package/src/core/flow/nodeFactory.js +58 -0
- package/src/core/flow/prediction.js +325 -0
- package/src/core/flow/runtime/auto.js +83 -0
- package/src/core/flow/runtime/decide.js +329 -0
- package/src/core/flow/runtime/event.js +28 -0
- package/src/core/flow/runtime/execute.js +357 -0
- package/src/core/flow/runtime/helpers.js +52 -0
- package/src/core/flow/runtime/query.js +146 -0
- package/src/core/flow/runtime/reject.js +137 -0
- package/src/core/flow/runtime/token.js +269 -0
- package/src/core/flow/runtime.js +129 -0
- package/src/core/flow/schema.js +864 -0
- package/src/definition/FlowDefinitionDesigner.vue +338 -0
- package/src/definition/index.js +9 -0
- package/src/index.js +39 -0
- package/src/storage.js +200 -0
- package/src/testing/FlowTestPanel.vue +2502 -0
- package/src/testing/UserConfigDrawer.vue +376 -0
- package/src/testing/diagram/FlowProgressDiagram.vue +318 -0
- package/src/testing/diagramModel.js +517 -0
- package/src/testing/index.js +23 -0
- package/src/testing/mock.js +246 -0
- package/src/testing/oaExecutors.js +51 -0
- package/src/testing/oaSeed.js +467 -0
- package/src/testing/sample.js +412 -0
- package/src/testing/seed.js +122 -0
- package/src/utils/format.js +27 -0
- package/src/visual/FlowCanvas.vue +441 -0
- package/src/visual/NodeProgressDetail.vue +43 -0
- package/src/visual/NodeStatusBadge.vue +17 -0
- package/src/visual/NodeWrap.vue +47 -0
- package/src/visual/ScWorkflow.vue +50 -0
- package/src/visual/SelectDialog.vue +460 -0
- package/src/visual/conditionHelpers.js +117 -0
- package/src/visual/index.js +6 -0
- package/src/visual/nodes/AddNode.vue +223 -0
- package/src/visual/nodes/ApproverNode.vue +348 -0
- package/src/visual/nodes/BranchNode.vue +442 -0
- package/src/visual/nodes/CustomNode.vue +339 -0
- package/src/visual/nodes/EndNode.vue +22 -0
- package/src/visual/nodes/PassNode.vue +101 -0
- package/src/visual/nodes/PromoterNode.vue +135 -0
- package/src/visual/nodes/RejectNode.vue +101 -0
- package/src/visual/nodes/SendNode.vue +152 -0
- package/src/visual/styles.scss +879 -0
- package/src/visual/useScNodeStatus.js +18 -0
- package/src/workbench/OaWorkbench.vue +1341 -0
- package/src/workbench/components/ApprovalWorkspace.vue +2090 -0
- package/src/workbench/components/CategoryIcon.vue +74 -0
- package/src/workbench/components/NotificationIcon.vue +73 -0
- package/src/workbench/components/ProcessSteps.vue +557 -0
- package/src/workbench/components/ResubmitDialog.vue +227 -0
- package/src/workbench/components/SidebarNav.vue +138 -0
- package/src/workbench/components/StartFlowDialog.vue +1058 -0
- package/src/workbench/components/UserAvatar.vue +68 -0
- package/src/workbench/custom-tasks.js +130 -0
- package/src/workbench/model.js +1080 -0
- package/src/workbench/pages/DesignPage.vue +798 -0
- package/src/workbench/pages/HomePage.vue +1050 -0
- package/src/workbench/pages/MonitorPage.vue +1029 -0
- package/src/workbench/pages/NotificationsPage.vue +554 -0
- package/src/workbench/pages/RequestsPage.vue +644 -0
- package/src/workbench/pages/TaskCenterPage.vue +1155 -0
- package/src/workbench/pages/TemplatesPage.vue +680 -0
- package/src/workbench/persistence.js +89 -0
- package/src/workbench/shared.js +18 -0
- package/src/workbench/styles.scss +555 -0
- package/src/workbench/useWorkbench.js +955 -0
- package/types/center.d.ts +5 -0
- package/types/core.d.ts +479 -0
- package/types/definition.d.ts +4 -0
- package/types/index.d.ts +34 -0
- package/types/testing.d.ts +20 -0
- package/types/visual.d.ts +20 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { ConditionOperator } from 'gbformdesign/core'
|
|
2
|
+
|
|
3
|
+
const EMPTY_OPERATORS = [ConditionOperator.IS_EMPTY, ConditionOperator.IS_NOT_EMPTY]
|
|
4
|
+
|
|
5
|
+
export function isEmptyValue(value) {
|
|
6
|
+
if (value === null || value === undefined) return true
|
|
7
|
+
if (typeof value === 'string') return value.trim() === ''
|
|
8
|
+
if (Array.isArray(value)) return value.length === 0
|
|
9
|
+
return false
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function normalizeComparable(value) {
|
|
13
|
+
if (value === null || value === undefined) return ''
|
|
14
|
+
return String(value).trim()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function toNumber(value) {
|
|
18
|
+
if (isEmptyValue(value)) return null
|
|
19
|
+
const num = Number(value)
|
|
20
|
+
return Number.isNaN(num) ? null : num
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function toTimestamp(value) {
|
|
24
|
+
if (isEmptyValue(value)) return null
|
|
25
|
+
const time = new Date(value).getTime()
|
|
26
|
+
return Number.isNaN(time) ? null : time
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function getVariableValue(data, variable) {
|
|
30
|
+
if (!variable) return undefined
|
|
31
|
+
if (data && Object.prototype.hasOwnProperty.call(data, variable)) {
|
|
32
|
+
return data[variable]
|
|
33
|
+
}
|
|
34
|
+
return String(variable)
|
|
35
|
+
.split('.')
|
|
36
|
+
.reduce((current, key) => (current == null ? undefined : current[key]), data)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Evaluates a single condition. Numeric and date operands are compared
|
|
41
|
+
* semantically when both sides can be parsed, otherwise as strings.
|
|
42
|
+
*/
|
|
43
|
+
export function evaluateCondition(condition, data = {}) {
|
|
44
|
+
if (!condition || !condition.variable) return false
|
|
45
|
+
const actual = getVariableValue(data, condition.variable)
|
|
46
|
+
const expected = condition.value
|
|
47
|
+
const operator = condition.operator || ConditionOperator.EQUAL
|
|
48
|
+
|
|
49
|
+
if (operator === ConditionOperator.IS_EMPTY) return isEmptyValue(actual)
|
|
50
|
+
if (operator === ConditionOperator.IS_NOT_EMPTY) return !isEmptyValue(actual)
|
|
51
|
+
|
|
52
|
+
if (operator === ConditionOperator.CONTAINS) {
|
|
53
|
+
if (Array.isArray(actual)) return actual.map(normalizeComparable).includes(normalizeComparable(expected))
|
|
54
|
+
if (isEmptyValue(actual)) return false
|
|
55
|
+
return String(actual).includes(String(expected ?? ''))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (operator === ConditionOperator.NOT_CONTAINS) {
|
|
59
|
+
if (Array.isArray(actual)) return !actual.map(normalizeComparable).includes(normalizeComparable(expected))
|
|
60
|
+
if (isEmptyValue(actual)) return true
|
|
61
|
+
return !String(actual).includes(String(expected ?? ''))
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const actualNumber = toNumber(actual)
|
|
65
|
+
const expectedNumber = toNumber(expected)
|
|
66
|
+
const useNumeric =
|
|
67
|
+
actualNumber !== null && expectedNumber !== null && !Array.isArray(actual)
|
|
68
|
+
|
|
69
|
+
if (useNumeric) {
|
|
70
|
+
switch (operator) {
|
|
71
|
+
case ConditionOperator.EQUAL:
|
|
72
|
+
return actualNumber === expectedNumber
|
|
73
|
+
case ConditionOperator.NOT_EQUAL:
|
|
74
|
+
return actualNumber !== expectedNumber
|
|
75
|
+
case ConditionOperator.GREATER_THAN:
|
|
76
|
+
return actualNumber > expectedNumber
|
|
77
|
+
case ConditionOperator.LESS_THAN:
|
|
78
|
+
return actualNumber < expectedNumber
|
|
79
|
+
case ConditionOperator.GREATER_THAN_OR_EQUAL:
|
|
80
|
+
return actualNumber >= expectedNumber
|
|
81
|
+
case ConditionOperator.LESS_THAN_OR_EQUAL:
|
|
82
|
+
return actualNumber <= expectedNumber
|
|
83
|
+
default:
|
|
84
|
+
break
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const actualDate = toTimestamp(actual)
|
|
89
|
+
const expectedDate = toTimestamp(expected)
|
|
90
|
+
const useDate =
|
|
91
|
+
actualDate !== null &&
|
|
92
|
+
expectedDate !== null &&
|
|
93
|
+
typeof actual === 'string' &&
|
|
94
|
+
typeof expected === 'string' &&
|
|
95
|
+
/^\d{4}-\d{2}-\d{2}/.test(actual) &&
|
|
96
|
+
/^\d{4}-\d{2}-\d{2}/.test(expected)
|
|
97
|
+
|
|
98
|
+
const left = useDate ? actualDate : normalizeComparable(actual)
|
|
99
|
+
const right = useDate ? expectedDate : normalizeComparable(expected)
|
|
100
|
+
|
|
101
|
+
switch (operator) {
|
|
102
|
+
case ConditionOperator.EQUAL:
|
|
103
|
+
return left === right
|
|
104
|
+
case ConditionOperator.NOT_EQUAL:
|
|
105
|
+
return left !== right
|
|
106
|
+
case ConditionOperator.GREATER_THAN:
|
|
107
|
+
return left > right
|
|
108
|
+
case ConditionOperator.LESS_THAN:
|
|
109
|
+
return left < right
|
|
110
|
+
case ConditionOperator.GREATER_THAN_OR_EQUAL:
|
|
111
|
+
return left >= right
|
|
112
|
+
case ConditionOperator.LESS_THAN_OR_EQUAL:
|
|
113
|
+
return left <= right
|
|
114
|
+
default:
|
|
115
|
+
return false
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Conditions are linked by the `logic` field of the preceding condition,
|
|
121
|
+
* matching the designer UI where the connector appears after each row.
|
|
122
|
+
*/
|
|
123
|
+
export function evaluateConditionGroup(conditions, data = {}) {
|
|
124
|
+
if (!Array.isArray(conditions) || conditions.length === 0) return true
|
|
125
|
+
let result = evaluateCondition(conditions[0], data)
|
|
126
|
+
for (let i = 1; i < conditions.length; i += 1) {
|
|
127
|
+
const previous = conditions[i - 1]
|
|
128
|
+
const current = evaluateCondition(conditions[i], data)
|
|
129
|
+
result = previous.logic === 'OR' ? result || current : result && current
|
|
130
|
+
}
|
|
131
|
+
return result
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function selectBranchNode(branchNode, data = {}) {
|
|
135
|
+
if (!branchNode || !Array.isArray(branchNode.branchList)) return null
|
|
136
|
+
let fallback = null
|
|
137
|
+
for (const branch of branchNode.branchList) {
|
|
138
|
+
if (branch.isDefaultCondition) {
|
|
139
|
+
fallback = branch
|
|
140
|
+
continue
|
|
141
|
+
}
|
|
142
|
+
if (evaluateConditionGroup(branch.conditions, data)) return branch
|
|
143
|
+
}
|
|
144
|
+
return fallback
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function selectInclusiveBranches(branchNode, data = {}) {
|
|
148
|
+
if (!branchNode || !Array.isArray(branchNode.branchList)) return []
|
|
149
|
+
const selected = []
|
|
150
|
+
let fallback = null
|
|
151
|
+
for (const branch of branchNode.branchList) {
|
|
152
|
+
if (branch.isDefaultBranch) {
|
|
153
|
+
fallback = branch
|
|
154
|
+
continue
|
|
155
|
+
}
|
|
156
|
+
if (evaluateConditionGroup(branch.conditions, data)) selected.push(branch)
|
|
157
|
+
}
|
|
158
|
+
if (selected.length === 0 && fallback) selected.push(fallback)
|
|
159
|
+
return selected
|
|
160
|
+
}
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 自定义节点执行约定:节点配置标准化、模板变量解析,以及 HTTP / 已注册方法执行。
|
|
3
|
+
* 运行时只负责派发与收口,真正的异步执行由宿主(OA 工作台或导入方)调用。
|
|
4
|
+
*/
|
|
5
|
+
import { getVariableValue } from './condition.js'
|
|
6
|
+
|
|
7
|
+
export const CUSTOM_EXECUTOR_TYPE = Object.freeze({
|
|
8
|
+
HTTP: 'http',
|
|
9
|
+
METHOD: 'method'
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
export const CUSTOM_ERROR_POLICY = Object.freeze({
|
|
13
|
+
TERMINATE: 'terminate',
|
|
14
|
+
CONTINUE: 'continue'
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export const CUSTOM_HTTP_METHODS = Object.freeze([
|
|
18
|
+
'GET',
|
|
19
|
+
'POST',
|
|
20
|
+
'PUT',
|
|
21
|
+
'PATCH',
|
|
22
|
+
'DELETE',
|
|
23
|
+
'HEAD'
|
|
24
|
+
])
|
|
25
|
+
|
|
26
|
+
export const CUSTOM_TIMEOUT_DEFAULT = 10000
|
|
27
|
+
export const CUSTOM_TIMEOUT_MIN = 1000
|
|
28
|
+
export const CUSTOM_TIMEOUT_MAX = 120000
|
|
29
|
+
export const CUSTOM_RESULT_LIMIT = 200 * 1024
|
|
30
|
+
|
|
31
|
+
const DEFAULT_TIMEOUT = CUSTOM_TIMEOUT_DEFAULT
|
|
32
|
+
const DEFAULT_HEADERS = [{ key: 'Content-Type', value: 'application/json' }]
|
|
33
|
+
const VARIABLE_NAME = /^[A-Za-z_$][\w$]*$/
|
|
34
|
+
|
|
35
|
+
const clone = (value) =>
|
|
36
|
+
value === undefined ? undefined : JSON.parse(JSON.stringify(value))
|
|
37
|
+
|
|
38
|
+
function isPlainObject(value) {
|
|
39
|
+
return !!value && typeof value === 'object' && !Array.isArray(value)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function normalizeHeaders(headers) {
|
|
43
|
+
if (!Array.isArray(headers)) return clone(DEFAULT_HEADERS)
|
|
44
|
+
return headers
|
|
45
|
+
.filter((header) => isPlainObject(header) && String(header.key || '').trim())
|
|
46
|
+
.map((header) => ({
|
|
47
|
+
key: String(header.key).trim(),
|
|
48
|
+
value: String(header.value ?? '')
|
|
49
|
+
}))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function createCustomNodeConfig(overrides = {}) {
|
|
53
|
+
return normalizeCustomNodeConfig(overrides)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function normalizeCustomNodeConfig(input = {}) {
|
|
57
|
+
const source = isPlainObject(input) ? input : {}
|
|
58
|
+
const executorType =
|
|
59
|
+
source.executorType === CUSTOM_EXECUTOR_TYPE.METHOD
|
|
60
|
+
? CUSTOM_EXECUTOR_TYPE.METHOD
|
|
61
|
+
: CUSTOM_EXECUTOR_TYPE.HTTP
|
|
62
|
+
const method = String(source.method || 'POST').toUpperCase()
|
|
63
|
+
const timeout = Number(source.timeoutMs)
|
|
64
|
+
const headerSource = Array.isArray(source.headers)
|
|
65
|
+
? source.headers
|
|
66
|
+
: isPlainObject(source.headers)
|
|
67
|
+
? Object.entries(source.headers).map(([key, value]) => ({ key, value }))
|
|
68
|
+
: null
|
|
69
|
+
const headers = headerSource ? normalizeHeaders(headerSource) : clone(DEFAULT_HEADERS)
|
|
70
|
+
return {
|
|
71
|
+
executorType,
|
|
72
|
+
url: typeof source.url === 'string' ? source.url.trim() : '',
|
|
73
|
+
method: CUSTOM_HTTP_METHODS.includes(method) ? method : 'POST',
|
|
74
|
+
headers,
|
|
75
|
+
body:
|
|
76
|
+
typeof source.body === 'string'
|
|
77
|
+
? source.body
|
|
78
|
+
: source.body && typeof source.body === 'object'
|
|
79
|
+
? JSON.stringify(source.body)
|
|
80
|
+
: '',
|
|
81
|
+
timeoutMs:
|
|
82
|
+
Number.isFinite(timeout) && timeout > 0
|
|
83
|
+
? Math.min(CUSTOM_TIMEOUT_MAX, Math.max(CUSTOM_TIMEOUT_MIN, Math.round(timeout)))
|
|
84
|
+
: DEFAULT_TIMEOUT,
|
|
85
|
+
methodKey: typeof source.methodKey === 'string' ? source.methodKey.trim() : '',
|
|
86
|
+
resultVariable:
|
|
87
|
+
typeof source.resultVariable === 'string' ? source.resultVariable.trim() : '',
|
|
88
|
+
onError:
|
|
89
|
+
source.onError === CUSTOM_ERROR_POLICY.CONTINUE
|
|
90
|
+
? CUSTOM_ERROR_POLICY.CONTINUE
|
|
91
|
+
: CUSTOM_ERROR_POLICY.TERMINATE
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function isLiteralUrl(url) {
|
|
96
|
+
return Boolean(url) && !url.includes('{{')
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function isAllowedRequestUrl(url) {
|
|
100
|
+
if (url.startsWith('/') && !url.startsWith('//')) return true
|
|
101
|
+
try {
|
|
102
|
+
const parsed = new URL(url)
|
|
103
|
+
return (
|
|
104
|
+
['http:', 'https:'].includes(parsed.protocol) &&
|
|
105
|
+
!parsed.username &&
|
|
106
|
+
!parsed.password
|
|
107
|
+
)
|
|
108
|
+
} catch {
|
|
109
|
+
return false
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function validateCustomNodeConfig(input) {
|
|
114
|
+
const config = normalizeCustomNodeConfig(input)
|
|
115
|
+
const errors = []
|
|
116
|
+
const warnings = []
|
|
117
|
+
if (config.executorType === CUSTOM_EXECUTOR_TYPE.METHOD) {
|
|
118
|
+
if (!config.methodKey) {
|
|
119
|
+
errors.push({
|
|
120
|
+
code: 'CUSTOM_METHOD_EMPTY',
|
|
121
|
+
message: '自定义节点尚未填写已注册方法名'
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
if (!config.url) {
|
|
126
|
+
errors.push({
|
|
127
|
+
code: 'CUSTOM_URL_EMPTY',
|
|
128
|
+
message: 'HTTP 自定义节点尚未填写请求地址'
|
|
129
|
+
})
|
|
130
|
+
} else if (isLiteralUrl(config.url) && !isAllowedRequestUrl(config.url)) {
|
|
131
|
+
errors.push({
|
|
132
|
+
code: 'CUSTOM_URL_INVALID',
|
|
133
|
+
message: `自定义节点请求地址无效:${config.url}(仅支持 http(s) 或站内相对地址)`
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
if (
|
|
137
|
+
config.body.trim() &&
|
|
138
|
+
(config.method === 'GET' || config.method === 'HEAD')
|
|
139
|
+
) {
|
|
140
|
+
warnings.push({
|
|
141
|
+
code: 'CUSTOM_BODY_IGNORED',
|
|
142
|
+
message: `${config.method} 请求会忽略配置的请求体`
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
if (
|
|
146
|
+
config.headers.some((header) =>
|
|
147
|
+
/^(authorization|cookie)$/i.test(header.key)
|
|
148
|
+
)
|
|
149
|
+
) {
|
|
150
|
+
warnings.push({
|
|
151
|
+
code: 'CUSTOM_SECRET_HEADER',
|
|
152
|
+
message: '节点配置中包含认证请求头;生产环境建议通过网关或已注册方法注入敏感凭据'
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (config.resultVariable && !VARIABLE_NAME.test(config.resultVariable)) {
|
|
157
|
+
warnings.push({
|
|
158
|
+
code: 'CUSTOM_RESULT_VARIABLE_INVALID',
|
|
159
|
+
message: `结果变量「${config.resultVariable}」不符合变量命名规范,执行结果将只保存在节点轨迹中`
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
return { errors, warnings, config }
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function customNodeSummary(input) {
|
|
166
|
+
const config = normalizeCustomNodeConfig(input)
|
|
167
|
+
const target =
|
|
168
|
+
config.executorType === CUSTOM_EXECUTOR_TYPE.METHOD
|
|
169
|
+
? `方法 ${config.methodKey || '未配置方法'}`
|
|
170
|
+
: `${config.method} ${config.url || '未配置地址'}`
|
|
171
|
+
return config.resultVariable ? `${target} → ${config.resultVariable}` : target
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function isValidCustomResultVariable(value) {
|
|
175
|
+
return VARIABLE_NAME.test(String(value || ''))
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function interpolateCustomTemplate(template, variables = {}) {
|
|
179
|
+
if (template === null || template === undefined) return ''
|
|
180
|
+
if (typeof template !== 'string') return template
|
|
181
|
+
return template.replace(/{{\s*([^{}]+?)\s*}}/g, (_, rawKey) => {
|
|
182
|
+
const key = String(rawKey).trim()
|
|
183
|
+
if (!key) return ''
|
|
184
|
+
const value = getVariableValue(variables, key)
|
|
185
|
+
if (value === undefined || value === null) return ''
|
|
186
|
+
if (typeof value === 'object') {
|
|
187
|
+
try {
|
|
188
|
+
return JSON.stringify(value)
|
|
189
|
+
} catch {
|
|
190
|
+
return ''
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return String(value)
|
|
194
|
+
})
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
export function resolveCustomRequest(input, variables = {}) {
|
|
199
|
+
const config = normalizeCustomNodeConfig(input)
|
|
200
|
+
const body =
|
|
201
|
+
typeof config.body === 'string'
|
|
202
|
+
? interpolateCustomTemplate(config.body, variables)
|
|
203
|
+
: config.body
|
|
204
|
+
return {
|
|
205
|
+
url: interpolateCustomTemplate(config.url, variables),
|
|
206
|
+
method: config.method,
|
|
207
|
+
headers: config.headers.reduce((result, header) => {
|
|
208
|
+
result[interpolateCustomTemplate(header.key, variables)] =
|
|
209
|
+
interpolateCustomTemplate(header.value, variables)
|
|
210
|
+
return result
|
|
211
|
+
}, {}),
|
|
212
|
+
body:
|
|
213
|
+
config.method === 'GET' || config.method === 'HEAD' || !body
|
|
214
|
+
? undefined
|
|
215
|
+
: body,
|
|
216
|
+
timeoutMs: config.timeoutMs
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function serializeResult(value) {
|
|
221
|
+
if (value === undefined) return null
|
|
222
|
+
let text
|
|
223
|
+
try {
|
|
224
|
+
text = JSON.stringify(value)
|
|
225
|
+
} catch (error) {
|
|
226
|
+
throw new Error(`自定义节点执行结果无法序列化:${error.message}`)
|
|
227
|
+
}
|
|
228
|
+
if (text === undefined) return null
|
|
229
|
+
if (text.length > CUSTOM_RESULT_LIMIT) {
|
|
230
|
+
throw new Error(
|
|
231
|
+
`自定义节点执行结果超过 ${Math.round(CUSTOM_RESULT_LIMIT / 1024)}KB 限制`
|
|
232
|
+
)
|
|
233
|
+
}
|
|
234
|
+
return JSON.parse(text)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function responseHeaders(response) {
|
|
238
|
+
const result = {}
|
|
239
|
+
if (response?.headers?.forEach) {
|
|
240
|
+
response.headers.forEach((value, key) => {
|
|
241
|
+
result[String(key)] = String(value)
|
|
242
|
+
})
|
|
243
|
+
}
|
|
244
|
+
return result
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function previewResponse(data) {
|
|
248
|
+
const text = typeof data === 'string' ? data : JSON.stringify(data)
|
|
249
|
+
return String(text || '').slice(0, 200)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
async function executeHttp(config, { variables, fetchImpl, signal } = {}) {
|
|
253
|
+
const request = resolveCustomRequest(config, variables)
|
|
254
|
+
const impl =
|
|
255
|
+
fetchImpl ||
|
|
256
|
+
(typeof globalThis.fetch === 'function'
|
|
257
|
+
? globalThis.fetch.bind(globalThis)
|
|
258
|
+
: null)
|
|
259
|
+
if (typeof impl !== 'function') {
|
|
260
|
+
throw new Error('当前运行环境不支持 fetch,无法执行 HTTP 自定义节点')
|
|
261
|
+
}
|
|
262
|
+
if (!isAllowedRequestUrl(request.url)) {
|
|
263
|
+
throw new Error(`HTTP 自定义节点地址无效:${request.url || '空'}`)
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const controller = new AbortController()
|
|
267
|
+
let timedOut = false
|
|
268
|
+
const timeout = setTimeout(() => {
|
|
269
|
+
timedOut = true
|
|
270
|
+
controller.abort()
|
|
271
|
+
}, request.timeoutMs)
|
|
272
|
+
const abortExternal = () => controller.abort()
|
|
273
|
+
if (signal) {
|
|
274
|
+
if (signal.aborted) controller.abort()
|
|
275
|
+
else signal.addEventListener('abort', abortExternal, { once: true })
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
try {
|
|
279
|
+
const response = await impl(request.url, {
|
|
280
|
+
method: request.method,
|
|
281
|
+
headers: request.headers,
|
|
282
|
+
body: request.body,
|
|
283
|
+
signal: controller.signal,
|
|
284
|
+
credentials: 'same-origin'
|
|
285
|
+
})
|
|
286
|
+
const text = await response.text()
|
|
287
|
+
if (text.length > CUSTOM_RESULT_LIMIT) {
|
|
288
|
+
throw new Error(
|
|
289
|
+
`自定义节点响应超过 ${Math.round(CUSTOM_RESULT_LIMIT / 1024)}KB 限制`
|
|
290
|
+
)
|
|
291
|
+
}
|
|
292
|
+
let data = text
|
|
293
|
+
const contentType = String(response.headers?.get?.('content-type') || '')
|
|
294
|
+
if (text.trim() && (contentType.includes('json') || /^[\[{]/.test(text.trim()))) {
|
|
295
|
+
try {
|
|
296
|
+
data = JSON.parse(text)
|
|
297
|
+
} catch {
|
|
298
|
+
data = text
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
const result = serializeResult({
|
|
302
|
+
status: response.status,
|
|
303
|
+
ok: Boolean(response.ok),
|
|
304
|
+
headers: responseHeaders(response),
|
|
305
|
+
data
|
|
306
|
+
})
|
|
307
|
+
if (!response.ok) {
|
|
308
|
+
const error = new Error(
|
|
309
|
+
`HTTP ${response.status}${response.statusText ? ` ${response.statusText}` : ''}:${previewResponse(data)}`
|
|
310
|
+
)
|
|
311
|
+
error.result = result
|
|
312
|
+
throw error
|
|
313
|
+
}
|
|
314
|
+
return result
|
|
315
|
+
} catch (error) {
|
|
316
|
+
if (error.name === 'AbortError') {
|
|
317
|
+
throw new Error(
|
|
318
|
+
timedOut
|
|
319
|
+
? `自定义节点请求超时(${request.timeoutMs}ms)`
|
|
320
|
+
: '自定义节点请求已取消'
|
|
321
|
+
)
|
|
322
|
+
}
|
|
323
|
+
throw error
|
|
324
|
+
} finally {
|
|
325
|
+
clearTimeout(timeout)
|
|
326
|
+
signal?.removeEventListener?.('abort', abortExternal)
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function runWithTimeout(promise, timeoutMs, signal, label) {
|
|
331
|
+
return new Promise((resolve, reject) => {
|
|
332
|
+
let settled = false
|
|
333
|
+
const finish = (callback, value) => {
|
|
334
|
+
if (settled) return
|
|
335
|
+
settled = true
|
|
336
|
+
clearTimeout(timer)
|
|
337
|
+
signal?.removeEventListener?.('abort', onAbort)
|
|
338
|
+
callback(value)
|
|
339
|
+
}
|
|
340
|
+
const onAbort = () => finish(reject, new Error(`${label}已取消`))
|
|
341
|
+
const timer = setTimeout(
|
|
342
|
+
() => finish(reject, new Error(`${label}超时(${timeoutMs}ms)`)),
|
|
343
|
+
timeoutMs
|
|
344
|
+
)
|
|
345
|
+
if (signal?.aborted) onAbort()
|
|
346
|
+
else signal?.addEventListener('abort', onAbort, { once: true })
|
|
347
|
+
Promise.resolve(promise).then(
|
|
348
|
+
(value) => finish(resolve, value),
|
|
349
|
+
(error) => finish(reject, error)
|
|
350
|
+
)
|
|
351
|
+
})
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
async function executeMethod(config, { variables, executors, node, signal, instance } = {}) {
|
|
355
|
+
const executor = executors?.[config.methodKey]
|
|
356
|
+
if (typeof executor !== 'function') {
|
|
357
|
+
throw new Error(`未注册自定义执行方法:${config.methodKey || '未配置方法'}`)
|
|
358
|
+
}
|
|
359
|
+
const result = await runWithTimeout(
|
|
360
|
+
executor({
|
|
361
|
+
config,
|
|
362
|
+
variables: isPlainObject(variables) ? variables : {},
|
|
363
|
+
node: node || null,
|
|
364
|
+
instance: instance || null,
|
|
365
|
+
signal,
|
|
366
|
+
interpolate: (template) => interpolateCustomTemplate(template, variables)
|
|
367
|
+
}),
|
|
368
|
+
config.timeoutMs,
|
|
369
|
+
signal,
|
|
370
|
+
'自定义方法执行'
|
|
371
|
+
)
|
|
372
|
+
return serializeResult(result)
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export async function executeCustomNode(input, options = {}) {
|
|
376
|
+
const validated = validateCustomNodeConfig(input)
|
|
377
|
+
if (validated.errors.length) {
|
|
378
|
+
throw new Error(validated.errors[0].message)
|
|
379
|
+
}
|
|
380
|
+
const config = validated.config
|
|
381
|
+
if (config.executorType === CUSTOM_EXECUTOR_TYPE.METHOD) {
|
|
382
|
+
return executeMethod(config, options)
|
|
383
|
+
}
|
|
384
|
+
return executeHttp(config, options)
|
|
385
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FlowNodeType,
|
|
3
|
+
ApproverType,
|
|
4
|
+
SignMode,
|
|
5
|
+
RejectStrategy,
|
|
6
|
+
NodeTypeLabel
|
|
7
|
+
} from './flowConstant.js'
|
|
8
|
+
import { createCustomNodeConfig } from './customNode.js'
|
|
9
|
+
|
|
10
|
+
export const STRUCTURAL_NODE_TYPES = [
|
|
11
|
+
FlowNodeType.START,
|
|
12
|
+
FlowNodeType.BRANCH,
|
|
13
|
+
FlowNodeType.CONDITION,
|
|
14
|
+
FlowNodeType.PARALLEL,
|
|
15
|
+
FlowNodeType.PARALLEL_BRANCH,
|
|
16
|
+
FlowNodeType.INCLUSIVE,
|
|
17
|
+
FlowNodeType.INCLUSIVE_BRANCH
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
export const TERMINAL_NODE_TYPES = [
|
|
21
|
+
FlowNodeType.END,
|
|
22
|
+
FlowNodeType.PASS,
|
|
23
|
+
FlowNodeType.REJECT
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
export const BRANCH_NODE_TYPES = [
|
|
27
|
+
FlowNodeType.BRANCH,
|
|
28
|
+
FlowNodeType.PARALLEL,
|
|
29
|
+
FlowNodeType.INCLUSIVE
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
export function isStructuralNode(node) {
|
|
33
|
+
return !!node && STRUCTURAL_NODE_TYPES.includes(node.type)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function isTerminalNode(node) {
|
|
37
|
+
return !!node && TERMINAL_NODE_TYPES.includes(node.type)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function isBranchNode(node) {
|
|
41
|
+
return !!node && BRANCH_NODE_TYPES.includes(node.type)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function getNodeTypeLabel(type) {
|
|
45
|
+
return NodeTypeLabel[type] || type || '未知节点'
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Returns the complete default property set for a node type.
|
|
50
|
+
* Values follow the persisted shape used by yudi-flow-ruoyi so imported
|
|
51
|
+
* definitions stay wire-compatible with the original backend.
|
|
52
|
+
*/
|
|
53
|
+
export function createNodeDefaults(type) {
|
|
54
|
+
switch (type) {
|
|
55
|
+
case FlowNodeType.START:
|
|
56
|
+
return { nodeName: '发起人', childNode: null }
|
|
57
|
+
case FlowNodeType.APPROVE:
|
|
58
|
+
return {
|
|
59
|
+
nodeName: '审批人',
|
|
60
|
+
userList: [],
|
|
61
|
+
roleList: [],
|
|
62
|
+
userNickNames: {},
|
|
63
|
+
deptNameMap: {},
|
|
64
|
+
roleNameMap: {},
|
|
65
|
+
signMode: SignMode.AND,
|
|
66
|
+
approverType: ApproverType.USER,
|
|
67
|
+
superiorLevel: 1,
|
|
68
|
+
allowTransfer: true,
|
|
69
|
+
rejectStrategy: RejectStrategy.TERMINATE,
|
|
70
|
+
rejectTargetNodeId: null,
|
|
71
|
+
rejectRetryLimit: 0,
|
|
72
|
+
termAuto: false,
|
|
73
|
+
term: 0,
|
|
74
|
+
termMode: 0,
|
|
75
|
+
childNode: null
|
|
76
|
+
}
|
|
77
|
+
case FlowNodeType.CC:
|
|
78
|
+
return {
|
|
79
|
+
nodeName: '抄送人',
|
|
80
|
+
userList: [],
|
|
81
|
+
userNickNames: {},
|
|
82
|
+
deptNameMap: {},
|
|
83
|
+
allowInitiatorAddUsers: true,
|
|
84
|
+
childNode: null
|
|
85
|
+
}
|
|
86
|
+
case FlowNodeType.CUSTOM:
|
|
87
|
+
return {
|
|
88
|
+
nodeName: '自定义节点',
|
|
89
|
+
custom: createCustomNodeConfig(),
|
|
90
|
+
childNode: null
|
|
91
|
+
}
|
|
92
|
+
case FlowNodeType.BRANCH:
|
|
93
|
+
return { nodeName: '条件分支', branchList: [], childNode: null }
|
|
94
|
+
case FlowNodeType.CONDITION:
|
|
95
|
+
return {
|
|
96
|
+
nodeName: '条件',
|
|
97
|
+
conditions: [],
|
|
98
|
+
isDefaultCondition: false,
|
|
99
|
+
childNode: null
|
|
100
|
+
}
|
|
101
|
+
case FlowNodeType.PARALLEL:
|
|
102
|
+
return { nodeName: '并行分支', branchList: [], childNode: null }
|
|
103
|
+
case FlowNodeType.PARALLEL_BRANCH:
|
|
104
|
+
return { nodeName: '分支', branchIndex: 0, childNode: null }
|
|
105
|
+
case FlowNodeType.INCLUSIVE:
|
|
106
|
+
return { nodeName: '包容分支', branchList: [], childNode: null }
|
|
107
|
+
case FlowNodeType.INCLUSIVE_BRANCH:
|
|
108
|
+
return {
|
|
109
|
+
nodeName: '包容条件',
|
|
110
|
+
branchIndex: 0,
|
|
111
|
+
conditions: [],
|
|
112
|
+
isDefaultBranch: false,
|
|
113
|
+
childNode: null
|
|
114
|
+
}
|
|
115
|
+
case FlowNodeType.PASS:
|
|
116
|
+
return { nodeName: '直接通过', childNode: null }
|
|
117
|
+
case FlowNodeType.REJECT:
|
|
118
|
+
return { nodeName: '直接拒绝', childNode: null }
|
|
119
|
+
case FlowNodeType.END:
|
|
120
|
+
return { nodeName: '流程结束', childNode: null }
|
|
121
|
+
default:
|
|
122
|
+
return { nodeName: getNodeTypeLabel(type), childNode: null }
|
|
123
|
+
}
|
|
124
|
+
}
|