@nocobase/plugin-flow-engine 2.3.0-alpha.1 → 2.3.0-beta.10
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/dist/ai/ai-employees/nathan/prompt.md +2 -0
- package/dist/ai/ai-employees/nathan/skills/frontend-developer/SKILLS.md +1 -0
- package/dist/ai/ai-employees/nathan/skills/frontend-developer/tools/patchJSCode.js +2 -2
- package/dist/ai/docs/runjs/context/ai.md +194 -4
- package/dist/externalVersion.js +9 -9
- package/dist/locale/en-US.json +2 -0
- package/dist/locale/index.d.ts +4 -0
- package/dist/locale/zh-CN.json +2 -0
- package/dist/node_modules/@ant-design/icons-svg/package.json +1 -1
- package/dist/node_modules/acorn/package.json +1 -1
- package/dist/node_modules/acorn-jsx/package.json +1 -1
- package/dist/node_modules/acorn-walk/package.json +1 -1
- package/dist/node_modules/ses/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/flow-surfaces/builder.js +5 -0
- package/dist/server/flow-surfaces/catalog.js +27 -8
- package/dist/server/flow-surfaces/configure-options.js +17 -1
- package/dist/server/flow-surfaces/field-binding-registry.js +9 -8
- package/dist/server/flow-surfaces/runjs-authoring/ast/parser.d.ts +10 -3
- package/dist/server/flow-surfaces/runjs-authoring/ast/parser.js +90 -8
- package/dist/server/flow-surfaces/runjs-authoring/ast/source.d.ts +2 -2
- package/dist/server/flow-surfaces/runjs-authoring/ast/source.js +7 -69
- package/dist/server/flow-surfaces/runjs-authoring/ast/static-bindings.d.ts +5 -5
- package/dist/server/flow-surfaces/runjs-authoring/ast/static-bindings.js +56 -23
- package/dist/server/flow-surfaces/runjs-authoring/ast/static-values.d.ts +1 -1
- package/dist/server/flow-surfaces/runjs-authoring/ast/static-values.js +4 -2
- package/dist/server/flow-surfaces/service-utils.d.ts +1 -0
- package/dist/server/flow-surfaces/service-utils.js +17 -0
- package/dist/server/flow-surfaces/service.js +9 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +7 -0
- package/dist/server/plugin.d.ts +13 -0
- package/dist/server/plugin.js +90 -3
- package/dist/server/repository.d.ts +12 -0
- package/dist/server/repository.js +39 -2
- package/dist/server/template/context-keys.d.ts +14 -0
- package/dist/server/template/context-keys.js +86 -0
- package/dist/server/template/contexts.d.ts +5 -8
- package/dist/server/template/contexts.js +43 -51
- package/dist/server/template/resolver.d.ts +5 -13
- package/dist/server/template/resolver.js +188 -257
- package/dist/server/template/variable-expression.d.ts +72 -0
- package/dist/server/template/variable-expression.js +597 -0
- package/dist/server/variables/allow-list.d.ts +49 -0
- package/dist/server/variables/allow-list.js +546 -0
- package/dist/server/variables/form-item-record-slot-resolvers.d.ts +10 -0
- package/dist/server/variables/form-item-record-slot-resolvers.js +297 -0
- package/dist/server/variables/record-bindings.d.ts +42 -0
- package/dist/server/variables/record-bindings.js +196 -0
- package/dist/server/variables/record-projection.d.ts +10 -0
- package/dist/server/variables/record-projection.js +140 -0
- package/dist/server/variables/record-slot-policy.d.ts +23 -0
- package/dist/server/variables/record-slot-policy.js +100 -0
- package/dist/server/variables/record-slot-resolvers.d.ts +46 -0
- package/dist/server/variables/record-slot-resolvers.js +115 -0
- package/dist/server/variables/records.d.ts +49 -2
- package/dist/server/variables/records.js +309 -18
- package/dist/server/variables/registry.d.ts +33 -10
- package/dist/server/variables/registry.js +197 -362
- package/dist/server/variables/resolve.d.ts +20 -2
- package/dist/server/variables/resolve.js +85 -13
- package/dist/server/variables/runjs-variable-dependencies.d.ts +23 -0
- package/dist/server/variables/runjs-variable-dependencies.js +542 -0
- package/dist/server/variables/selects.js +6 -3
- package/dist/server/variables/utils.d.ts +3 -6
- package/dist/server/variables/utils.js +50 -111
- package/package.json +2 -2
|
@@ -7,15 +7,33 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import type { ResourcerContext } from '@nocobase/resourcer';
|
|
10
|
+
import { type AnalyzedTemplate, type ResolvePathPolicy } from '../template/variable-expression';
|
|
10
11
|
import { JSONValue } from '../template/resolver';
|
|
11
|
-
type
|
|
12
|
+
import { type RecordBindingPlan } from './record-bindings';
|
|
13
|
+
export type ResolveBatchItem = {
|
|
12
14
|
id?: string | number;
|
|
13
15
|
template: JSONValue;
|
|
14
16
|
contextParams?: Record<string, unknown>;
|
|
15
17
|
};
|
|
18
|
+
export type AnalyzedResolveBatchItem = ResolveBatchItem & {
|
|
19
|
+
analysis: AnalyzedTemplate;
|
|
20
|
+
bindingPlan: RecordBindingPlan;
|
|
21
|
+
policy: ResolvePathPolicy;
|
|
22
|
+
};
|
|
16
23
|
export declare function resolveVariablesTemplate(ctx: ResourcerContext, template: JSONValue, contextParams?: Record<string, unknown>): Promise<any>;
|
|
24
|
+
export declare function isLegacyVariableTemplateSafe(template: JSONValue): boolean;
|
|
25
|
+
export declare function resolveFlowModelVariablesTemplate(ctx: ResourcerContext, options: {
|
|
26
|
+
contractRd?: string | number;
|
|
27
|
+
contextParams?: Record<string, unknown>;
|
|
28
|
+
rd?: string | number;
|
|
29
|
+
template: JSONValue;
|
|
30
|
+
}): Promise<any>;
|
|
31
|
+
export declare function resolveAnalyzedVariablesTemplate(ctx: ResourcerContext, analysis: AnalyzedTemplate, policy: ResolvePathPolicy, bindingPlan: RecordBindingPlan): Promise<any>;
|
|
17
32
|
export declare function resolveVariablesBatch(ctx: ResourcerContext, items: ResolveBatchItem[]): Promise<{
|
|
18
33
|
id?: string | number;
|
|
19
34
|
data: unknown;
|
|
20
35
|
}[]>;
|
|
21
|
-
export {
|
|
36
|
+
export declare function resolveAnalyzedVariablesBatch(ctx: ResourcerContext, items: AnalyzedResolveBatchItem[]): Promise<{
|
|
37
|
+
id?: string | number;
|
|
38
|
+
data: unknown;
|
|
39
|
+
}[]>;
|
|
@@ -26,15 +26,27 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
26
26
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
27
|
var resolve_exports = {};
|
|
28
28
|
__export(resolve_exports, {
|
|
29
|
+
isLegacyVariableTemplateSafe: () => isLegacyVariableTemplateSafe,
|
|
30
|
+
resolveAnalyzedVariablesBatch: () => resolveAnalyzedVariablesBatch,
|
|
31
|
+
resolveAnalyzedVariablesTemplate: () => resolveAnalyzedVariablesTemplate,
|
|
32
|
+
resolveFlowModelVariablesTemplate: () => resolveFlowModelVariablesTemplate,
|
|
29
33
|
resolveVariablesBatch: () => resolveVariablesBatch,
|
|
30
34
|
resolveVariablesTemplate: () => resolveVariablesTemplate
|
|
31
35
|
});
|
|
32
36
|
module.exports = __toCommonJS(resolve_exports);
|
|
33
37
|
var import_contexts = require("../template/contexts");
|
|
34
38
|
var import_resolver = require("../template/resolver");
|
|
39
|
+
var import_allow_list = require("./allow-list");
|
|
40
|
+
var import_record_bindings = require("./record-bindings");
|
|
35
41
|
var import_registry = require("./registry");
|
|
42
|
+
var import_record_slot_policy = require("./record-slot-policy");
|
|
36
43
|
var import_utils = require("./utils");
|
|
37
44
|
const GLOBAL_CONTEXT_KEY = Symbol.for("nocobase.flow-engine.variables.global-context");
|
|
45
|
+
const REQUEST_BOUND_RESOLVE_POLICY = {
|
|
46
|
+
allowAll: true,
|
|
47
|
+
allowedPaths: /* @__PURE__ */ new Set(),
|
|
48
|
+
unrestrictedVariables: /* @__PURE__ */ new Set()
|
|
49
|
+
};
|
|
38
50
|
function getGlobalContext(ctx) {
|
|
39
51
|
var _a, _b;
|
|
40
52
|
const app = ctx.app;
|
|
@@ -44,36 +56,96 @@ function getGlobalContext(ctx) {
|
|
|
44
56
|
return app[GLOBAL_CONTEXT_KEY];
|
|
45
57
|
}
|
|
46
58
|
async function resolveVariablesTemplate(ctx, template, contextParams = {}) {
|
|
47
|
-
|
|
48
|
-
|
|
59
|
+
const result = (0, import_allow_list.analyzeVariableTemplateSafely)(template, { mode: "untrusted-request" });
|
|
60
|
+
if (!result.ok) return template;
|
|
61
|
+
const bindingPlan = await createRequestBoundRecordBindingPlan(ctx, result.analysis, contextParams);
|
|
62
|
+
return resolveAnalyzedVariablesTemplate(ctx, result.analysis, REQUEST_BOUND_RESOLVE_POLICY, bindingPlan);
|
|
63
|
+
}
|
|
64
|
+
function isLegacyVariableTemplateSafe(template) {
|
|
65
|
+
const result = (0, import_allow_list.analyzeVariableTemplateSafely)(template, { mode: "untrusted-request" });
|
|
66
|
+
return result.ok && result.analysis.supported && result.analysis.paths.length === 0;
|
|
67
|
+
}
|
|
68
|
+
async function resolveFlowModelVariablesTemplate(ctx, options) {
|
|
69
|
+
if (!await (0, import_allow_list.resolveFlowModelNodeFromRequestRd)(ctx, options.rd)) return;
|
|
70
|
+
const authorization = await (0, import_allow_list.authorizeVariablesResolve)(ctx, options);
|
|
71
|
+
if (!authorization.allowed || !authorization.flowModelUid) return;
|
|
72
|
+
const resolved = await resolveAnalyzedVariablesTemplate(
|
|
73
|
+
ctx,
|
|
74
|
+
authorization.analysis,
|
|
75
|
+
authorization.policy,
|
|
76
|
+
authorization.bindingPlan
|
|
77
|
+
);
|
|
78
|
+
const remaining = (0, import_allow_list.analyzeVariableTemplateSafely)(resolved, { mode: "untrusted-request" });
|
|
79
|
+
if (!remaining.ok || !remaining.analysis.supported || remaining.analysis.paths.length) return;
|
|
80
|
+
return resolved;
|
|
81
|
+
}
|
|
82
|
+
async function createRequestBoundRecordBindingPlan(ctx, analysis, contextParams) {
|
|
83
|
+
const policies = await (0, import_record_slot_policy.compileRecordSlotPolicies)(analysis, { app: ctx.app, ctx });
|
|
84
|
+
return (0, import_record_bindings.planRecordBindings)({
|
|
85
|
+
contextParams,
|
|
86
|
+
koaCtx: ctx,
|
|
87
|
+
policies,
|
|
88
|
+
usage: analysis.usage
|
|
89
|
+
});
|
|
49
90
|
}
|
|
50
|
-
async function
|
|
91
|
+
async function resolveAnalyzedVariablesTemplate(ctx, analysis, policy, bindingPlan) {
|
|
92
|
+
await (0, import_utils.prefetchRecordsForResolve)(ctx, bindingPlan.bindings);
|
|
93
|
+
return resolveAnalyzedVariablesTemplateWithPrefetchedRecords(ctx, analysis, policy, bindingPlan);
|
|
94
|
+
}
|
|
95
|
+
async function resolveAnalyzedVariablesTemplateWithPrefetchedRecords(ctx, analysis, policy, bindingPlan) {
|
|
51
96
|
const requestCtx = new import_contexts.HttpRequestContext(ctx);
|
|
52
97
|
requestCtx.delegate(getGlobalContext(ctx));
|
|
53
|
-
await import_registry.variables.
|
|
54
|
-
return (0, import_resolver.
|
|
98
|
+
await import_registry.variables.attachUsedVariablesFromPlan(requestCtx, ctx, analysis.usage, bindingPlan);
|
|
99
|
+
return (0, import_resolver.resolveAnalyzedJsonTemplate)(analysis, requestCtx, policy);
|
|
55
100
|
}
|
|
56
101
|
async function resolveVariablesBatch(ctx, items) {
|
|
102
|
+
var _a;
|
|
103
|
+
const analyzedItems = [];
|
|
104
|
+
const results = [];
|
|
105
|
+
for (const [index, item] of items.entries()) {
|
|
106
|
+
const result = (0, import_allow_list.analyzeVariableTemplateSafely)((item == null ? void 0 : item.template) ?? {}, { mode: "untrusted-request" });
|
|
107
|
+
if (!result.ok) {
|
|
108
|
+
results[index] = { id: item == null ? void 0 : item.id, data: (item == null ? void 0 : item.template) ?? {} };
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
analyzedItems.push({
|
|
112
|
+
...item,
|
|
113
|
+
id: index,
|
|
114
|
+
analysis: result.analysis,
|
|
115
|
+
bindingPlan: await createRequestBoundRecordBindingPlan(ctx, result.analysis, item.contextParams || {}),
|
|
116
|
+
policy: REQUEST_BOUND_RESOLVE_POLICY
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
const resolvedItems = await resolveAnalyzedVariablesBatch(ctx, analyzedItems);
|
|
120
|
+
for (const item of resolvedItems) {
|
|
121
|
+
const index = Number(item.id);
|
|
122
|
+
results[index] = { id: (_a = items[index]) == null ? void 0 : _a.id, data: item.data };
|
|
123
|
+
}
|
|
124
|
+
return results.filter((item) => !!item);
|
|
125
|
+
}
|
|
126
|
+
async function resolveAnalyzedVariablesBatch(ctx, items) {
|
|
57
127
|
await (0, import_utils.prefetchRecordsForResolve)(
|
|
58
128
|
ctx,
|
|
59
|
-
items.
|
|
60
|
-
template: (item == null ? void 0 : item.template) ?? {},
|
|
61
|
-
contextParams: (item == null ? void 0 : item.contextParams) || {}
|
|
62
|
-
}))
|
|
129
|
+
items.flatMap((item) => item.bindingPlan.bindings)
|
|
63
130
|
);
|
|
64
131
|
const results = [];
|
|
65
132
|
for (const item of items) {
|
|
66
|
-
const data = await
|
|
133
|
+
const data = await resolveAnalyzedVariablesTemplateWithPrefetchedRecords(
|
|
67
134
|
ctx,
|
|
68
|
-
|
|
69
|
-
|
|
135
|
+
item.analysis,
|
|
136
|
+
item.policy,
|
|
137
|
+
item.bindingPlan
|
|
70
138
|
);
|
|
71
|
-
results.push({ id: item
|
|
139
|
+
results.push({ id: item.id, data });
|
|
72
140
|
}
|
|
73
141
|
return results;
|
|
74
142
|
}
|
|
75
143
|
// Annotate the CommonJS export names for ESM import in node:
|
|
76
144
|
0 && (module.exports = {
|
|
145
|
+
isLegacyVariableTemplateSafe,
|
|
146
|
+
resolveAnalyzedVariablesBatch,
|
|
147
|
+
resolveAnalyzedVariablesTemplate,
|
|
148
|
+
resolveFlowModelVariablesTemplate,
|
|
77
149
|
resolveVariablesBatch,
|
|
78
150
|
resolveVariablesTemplate
|
|
79
151
|
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
export type PreparedFlowModelVariableSource = Readonly<{
|
|
10
|
+
ok: true;
|
|
11
|
+
runJsTemplates: readonly string[];
|
|
12
|
+
templateSource: unknown;
|
|
13
|
+
}> | Readonly<{
|
|
14
|
+
ok: false;
|
|
15
|
+
}>;
|
|
16
|
+
export declare const MAX_FLOW_MODEL_VARIABLE_SOURCE_DEPTH = 128;
|
|
17
|
+
export declare const MAX_FLOW_MODEL_VARIABLE_SOURCE_NODES = 10000;
|
|
18
|
+
export declare const MAX_FLOW_MODEL_VARIABLE_STRING_LENGTH: number;
|
|
19
|
+
export declare const MAX_FLOW_MODEL_VARIABLE_TOTAL_STRING_LENGTH: number;
|
|
20
|
+
export declare function prepareFlowModelVariableSource(value: unknown, options?: Readonly<{
|
|
21
|
+
isRunJsValuePath?: (pathTail: readonly string[]) => boolean;
|
|
22
|
+
}>): PreparedFlowModelVariableSource;
|
|
23
|
+
export declare function collectPersistedRunJsVariableTemplates(value: unknown): string[];
|