@nocobase/plugin-flow-engine 2.1.0-beta.14 → 2.1.0-beta.16

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.
Files changed (229) hide show
  1. package/dist/ai/ai-employees/nathan/index.d.ts +10 -0
  2. package/dist/ai/ai-employees/nathan/index.js +41 -0
  3. package/dist/ai/ai-employees/nathan/prompt.md +132 -0
  4. package/dist/ai/ai-employees/nathan/skills/frontend-developer/SKILLS.md +69 -0
  5. package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextApis.js +2 -2
  6. package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextEnvs.js +2 -2
  7. package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextVars.js +2 -2
  8. package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/lintAndTestJS.js +2 -2
  9. package/dist/ai/docs/runjs/context/block-model.md +35 -35
  10. package/dist/ai/docs/runjs/context/collection-field.md +53 -51
  11. package/dist/ai/docs/runjs/context/collection.md +39 -39
  12. package/dist/ai/docs/runjs/context/data-source-manager.md +40 -30
  13. package/dist/ai/docs/runjs/context/data-source.md +52 -44
  14. package/dist/ai/docs/runjs/context/element.md +44 -38
  15. package/dist/ai/docs/runjs/context/exit-all.md +37 -35
  16. package/dist/ai/docs/runjs/context/exit.md +38 -35
  17. package/dist/ai/docs/runjs/context/filter-manager.md +36 -30
  18. package/dist/ai/docs/runjs/context/form.md +57 -57
  19. package/dist/ai/docs/runjs/context/get-model.md +22 -21
  20. package/dist/ai/docs/runjs/context/get-value.md +20 -19
  21. package/dist/ai/docs/runjs/context/get-var.md +61 -55
  22. package/dist/ai/docs/runjs/context/i18n.md +17 -14
  23. package/dist/ai/docs/runjs/context/import-async.md +333 -45
  24. package/dist/ai/docs/runjs/context/init-resource.md +20 -20
  25. package/dist/ai/docs/runjs/context/libs.md +31 -31
  26. package/dist/ai/docs/runjs/context/location.md +34 -31
  27. package/dist/ai/docs/runjs/context/logger.md +41 -40
  28. package/dist/ai/docs/runjs/context/make-resource.md +27 -26
  29. package/dist/ai/docs/runjs/context/message.md +42 -41
  30. package/dist/ai/docs/runjs/context/modal.md +44 -44
  31. package/dist/ai/docs/runjs/context/model.md +36 -33
  32. package/dist/ai/docs/runjs/context/notification.md +41 -40
  33. package/dist/ai/docs/runjs/context/off.md +14 -14
  34. package/dist/ai/docs/runjs/context/on.md +30 -29
  35. package/dist/ai/docs/runjs/context/open-view.md +40 -40
  36. package/dist/ai/docs/runjs/context/render.md +37 -32
  37. package/dist/ai/docs/runjs/context/request.md +46 -45
  38. package/dist/ai/docs/runjs/context/require-async.md +28 -25
  39. package/dist/ai/docs/runjs/context/resource.md +34 -34
  40. package/dist/ai/docs/runjs/context/route.md +36 -34
  41. package/dist/ai/docs/runjs/context/router.md +43 -31
  42. package/dist/ai/docs/runjs/context/set-value.md +18 -17
  43. package/dist/ai/docs/runjs/context/t.md +20 -17
  44. package/dist/ai/docs/runjs/context/view.md +49 -46
  45. package/dist/ai/docs/runjs/document.md +1 -0
  46. package/dist/ai/docs/runjs/import-modules.md +32 -32
  47. package/dist/ai/docs/runjs/index.md +13 -13
  48. package/dist/ai/docs/runjs/jsx.md +19 -19
  49. package/dist/ai/docs/runjs/model/form-block-model.md +1 -3
  50. package/dist/ai/docs/runjs/render.md +15 -15
  51. package/dist/ai/docs/runjs/resource/api-resource.md +53 -53
  52. package/dist/ai/docs/runjs/resource/multi-record-resource.md +64 -64
  53. package/dist/ai/docs/runjs/resource/single-record-resource.md +55 -55
  54. package/dist/ai/docs/runjs/resource/sql-resource.md +57 -57
  55. package/dist/ai/docs/runjs/window.md +5 -5
  56. package/dist/client/index.js +1 -1
  57. package/dist/externalVersion.js +11 -10
  58. package/dist/node_modules/ses/dist/ses.cjs +1 -1
  59. package/dist/node_modules/ses/package.json +1 -1
  60. package/dist/node_modules/zod/index.cjs +1 -1
  61. package/dist/node_modules/zod/package.json +1 -1
  62. package/dist/server/flow-surfaces/action-scope.d.ts +38 -0
  63. package/dist/server/flow-surfaces/action-scope.js +152 -0
  64. package/dist/server/flow-surfaces/apply/compiler.d.ts +13 -0
  65. package/dist/server/flow-surfaces/apply/compiler.js +969 -0
  66. package/dist/server/flow-surfaces/apply/layout.d.ts +34 -0
  67. package/dist/server/flow-surfaces/apply/layout.js +175 -0
  68. package/dist/server/flow-surfaces/apply/matching.d.ts +16 -0
  69. package/dist/server/flow-surfaces/apply/matching.js +181 -0
  70. package/dist/server/flow-surfaces/approval/blueprint-service.d.ts +84 -0
  71. package/dist/server/flow-surfaces/approval/blueprint-service.js +589 -0
  72. package/dist/server/flow-surfaces/approval/blueprint.d.ts +21 -0
  73. package/dist/server/flow-surfaces/approval/blueprint.js +187 -0
  74. package/dist/server/flow-surfaces/approval/builder.d.ts +225 -0
  75. package/dist/server/flow-surfaces/approval/builder.js +384 -0
  76. package/dist/server/flow-surfaces/approval/catalog-specs.d.ts +33 -0
  77. package/dist/server/flow-surfaces/approval/catalog-specs.js +156 -0
  78. package/dist/server/flow-surfaces/approval/index.d.ts +14 -0
  79. package/dist/server/flow-surfaces/approval/index.js +40 -0
  80. package/dist/server/flow-surfaces/approval/runtime-config.d.ts +44 -0
  81. package/dist/server/flow-surfaces/approval/runtime-config.js +299 -0
  82. package/dist/server/flow-surfaces/approval/semantic-use.d.ts +23 -0
  83. package/dist/server/flow-surfaces/approval/semantic-use.js +155 -0
  84. package/dist/server/flow-surfaces/association-title-field.d.ts +20 -0
  85. package/dist/server/flow-surfaces/association-title-field.js +158 -0
  86. package/dist/server/flow-surfaces/blueprint/compile-blocks.d.ts +14 -0
  87. package/dist/server/flow-surfaces/blueprint/compile-blocks.js +1007 -0
  88. package/dist/server/flow-surfaces/blueprint/compile-plan.d.ts +13 -0
  89. package/dist/server/flow-surfaces/blueprint/compile-plan.js +308 -0
  90. package/dist/server/flow-surfaces/blueprint/compile-reaction.d.ts +11 -0
  91. package/dist/server/flow-surfaces/blueprint/compile-reaction.js +72 -0
  92. package/dist/server/flow-surfaces/blueprint/defaults.d.ts +26 -0
  93. package/dist/server/flow-surfaces/blueprint/defaults.js +133 -0
  94. package/dist/server/flow-surfaces/blueprint/index.d.ts +12 -0
  95. package/dist/server/flow-surfaces/blueprint/index.js +44 -0
  96. package/dist/server/flow-surfaces/blueprint/normalize-document.d.ts +10 -0
  97. package/dist/server/flow-surfaces/blueprint/normalize-document.js +416 -0
  98. package/dist/server/flow-surfaces/blueprint/private-utils.d.ts +26 -0
  99. package/dist/server/flow-surfaces/blueprint/private-utils.js +182 -0
  100. package/dist/server/flow-surfaces/blueprint/public-types.d.ts +193 -0
  101. package/dist/server/flow-surfaces/blueprint/public-types.js +24 -0
  102. package/dist/server/flow-surfaces/builder.d.ts +211 -0
  103. package/dist/server/flow-surfaces/builder.js +1029 -0
  104. package/dist/server/flow-surfaces/catalog-smart.d.ts +18 -0
  105. package/dist/server/flow-surfaces/catalog-smart.js +239 -0
  106. package/dist/server/flow-surfaces/catalog-smart.projector.d.ts +15 -0
  107. package/dist/server/flow-surfaces/catalog-smart.projector.js +157 -0
  108. package/dist/server/flow-surfaces/catalog-smart.types.d.ts +99 -0
  109. package/dist/server/flow-surfaces/catalog-smart.types.js +24 -0
  110. package/dist/server/flow-surfaces/catalog.d.ts +78 -0
  111. package/dist/server/flow-surfaces/catalog.js +3496 -0
  112. package/dist/server/flow-surfaces/chart-config.d.ts +121 -0
  113. package/dist/server/flow-surfaces/chart-config.js +1394 -0
  114. package/dist/server/flow-surfaces/compose-compiler.d.ts +108 -0
  115. package/dist/server/flow-surfaces/compose-compiler.js +167 -0
  116. package/dist/server/flow-surfaces/compose-runtime.d.ts +93 -0
  117. package/dist/server/flow-surfaces/compose-runtime.js +375 -0
  118. package/dist/server/flow-surfaces/configure-options.d.ts +23 -0
  119. package/dist/server/flow-surfaces/configure-options.js +827 -0
  120. package/dist/server/flow-surfaces/constants.d.ts +351 -0
  121. package/dist/server/flow-surfaces/constants.js +104 -0
  122. package/dist/server/flow-surfaces/context.d.ts +72 -0
  123. package/dist/server/flow-surfaces/context.js +556 -0
  124. package/dist/server/flow-surfaces/contract-guard.d.ts +19 -0
  125. package/dist/server/flow-surfaces/contract-guard.js +402 -0
  126. package/dist/server/flow-surfaces/default-action-popup.d.ts +63 -0
  127. package/dist/server/flow-surfaces/default-action-popup.js +322 -0
  128. package/dist/server/flow-surfaces/default-block-actions.d.ts +32 -0
  129. package/dist/server/flow-surfaces/default-block-actions.js +185 -0
  130. package/dist/server/flow-surfaces/errors.d.ts +47 -0
  131. package/dist/server/flow-surfaces/errors.js +145 -0
  132. package/dist/server/flow-surfaces/executor.d.ts +23 -0
  133. package/dist/server/flow-surfaces/executor.js +132 -0
  134. package/dist/server/flow-surfaces/field-binding-registry.d.ts +23 -0
  135. package/dist/server/flow-surfaces/field-binding-registry.js +391 -0
  136. package/dist/server/flow-surfaces/field-semantics.d.ts +15 -0
  137. package/dist/server/flow-surfaces/field-semantics.js +81 -0
  138. package/dist/server/flow-surfaces/filter-group.d.ts +15 -0
  139. package/dist/server/flow-surfaces/filter-group.js +94 -0
  140. package/dist/server/flow-surfaces/index.d.ts +11 -0
  141. package/dist/server/flow-surfaces/index.js +243 -0
  142. package/dist/server/flow-surfaces/locator.d.ts +28 -0
  143. package/dist/server/flow-surfaces/locator.js +240 -0
  144. package/dist/server/flow-surfaces/node-use-sets.d.ts +15 -0
  145. package/dist/server/flow-surfaces/node-use-sets.js +131 -0
  146. package/dist/server/flow-surfaces/payload-shape.d.ts +9 -0
  147. package/dist/server/flow-surfaces/payload-shape.js +61 -0
  148. package/dist/server/flow-surfaces/placement.d.ts +33 -0
  149. package/dist/server/flow-surfaces/placement.js +195 -0
  150. package/dist/server/flow-surfaces/planning/action-specs.d.ts +179 -0
  151. package/dist/server/flow-surfaces/planning/action-specs.js +190 -0
  152. package/dist/server/flow-surfaces/planning/compiler.d.ts +37 -0
  153. package/dist/server/flow-surfaces/planning/compiler.js +376 -0
  154. package/dist/server/flow-surfaces/planning/context.d.ts +30 -0
  155. package/dist/server/flow-surfaces/planning/context.js +139 -0
  156. package/dist/server/flow-surfaces/planning/created-keys.d.ts +34 -0
  157. package/dist/server/flow-surfaces/planning/created-keys.js +375 -0
  158. package/dist/server/flow-surfaces/planning/key-kind.d.ts +11 -0
  159. package/dist/server/flow-surfaces/planning/key-kind.js +88 -0
  160. package/dist/server/flow-surfaces/planning/key-persistence.d.ts +34 -0
  161. package/dist/server/flow-surfaces/planning/key-persistence.js +148 -0
  162. package/dist/server/flow-surfaces/planning/key-registry.d.ts +40 -0
  163. package/dist/server/flow-surfaces/planning/key-registry.js +206 -0
  164. package/dist/server/flow-surfaces/planning/runtime.d.ts +37 -0
  165. package/dist/server/flow-surfaces/planning/runtime.js +259 -0
  166. package/dist/server/flow-surfaces/planning/step-link.d.ts +14 -0
  167. package/dist/server/flow-surfaces/planning/step-link.js +104 -0
  168. package/dist/server/flow-surfaces/planning/types.d.ts +55 -0
  169. package/dist/server/flow-surfaces/planning/types.js +24 -0
  170. package/dist/server/flow-surfaces/public-data-surface-default-filter.d.ts +20 -0
  171. package/dist/server/flow-surfaces/public-data-surface-default-filter.js +111 -0
  172. package/dist/server/flow-surfaces/reaction/errors.d.ts +20 -0
  173. package/dist/server/flow-surfaces/reaction/errors.js +69 -0
  174. package/dist/server/flow-surfaces/reaction/field-value.d.ts +34 -0
  175. package/dist/server/flow-surfaces/reaction/field-value.js +181 -0
  176. package/dist/server/flow-surfaces/reaction/fingerprint.d.ts +16 -0
  177. package/dist/server/flow-surfaces/reaction/fingerprint.js +71 -0
  178. package/dist/server/flow-surfaces/reaction/linkage.d.ts +136 -0
  179. package/dist/server/flow-surfaces/reaction/linkage.js +882 -0
  180. package/dist/server/flow-surfaces/reaction/meta.d.ts +11 -0
  181. package/dist/server/flow-surfaces/reaction/meta.js +451 -0
  182. package/dist/server/flow-surfaces/reaction/registry.d.ts +156 -0
  183. package/dist/server/flow-surfaces/reaction/registry.js +206 -0
  184. package/dist/server/flow-surfaces/reaction/resolver.d.ts +22 -0
  185. package/dist/server/flow-surfaces/reaction/resolver.js +202 -0
  186. package/dist/server/flow-surfaces/reaction/types.d.ts +241 -0
  187. package/dist/server/flow-surfaces/reaction/types.js +24 -0
  188. package/dist/server/flow-surfaces/reaction/utils.d.ts +17 -0
  189. package/dist/server/flow-surfaces/reaction/utils.js +67 -0
  190. package/dist/server/flow-surfaces/reaction/value-expr.d.ts +15 -0
  191. package/dist/server/flow-surfaces/reaction/value-expr.js +209 -0
  192. package/dist/server/flow-surfaces/reference-guards.d.ts +19 -0
  193. package/dist/server/flow-surfaces/reference-guards.js +103 -0
  194. package/dist/server/flow-surfaces/route-sync.d.ts +47 -0
  195. package/dist/server/flow-surfaces/route-sync.js +392 -0
  196. package/dist/server/flow-surfaces/service-helpers.d.ts +42 -0
  197. package/dist/server/flow-surfaces/service-helpers.js +377 -0
  198. package/dist/server/flow-surfaces/service-utils.d.ts +108 -0
  199. package/dist/server/flow-surfaces/service-utils.js +811 -0
  200. package/dist/server/flow-surfaces/service.d.ts +773 -0
  201. package/dist/server/flow-surfaces/service.js +13008 -0
  202. package/dist/server/flow-surfaces/support-matrix.d.ts +31 -0
  203. package/dist/server/flow-surfaces/support-matrix.js +259 -0
  204. package/dist/server/flow-surfaces/surface-context.d.ts +52 -0
  205. package/dist/server/flow-surfaces/surface-context.js +437 -0
  206. package/dist/server/flow-surfaces/template-compatibility.d.ts +42 -0
  207. package/dist/server/flow-surfaces/template-compatibility.js +189 -0
  208. package/dist/server/flow-surfaces/template-display.d.ts +20 -0
  209. package/dist/server/flow-surfaces/template-display.js +289 -0
  210. package/dist/server/flow-surfaces/template-service-utils.d.ts +62 -0
  211. package/dist/server/flow-surfaces/template-service-utils.js +281 -0
  212. package/dist/server/flow-surfaces/types.d.ts +288 -0
  213. package/dist/server/flow-surfaces/types.js +24 -0
  214. package/dist/server/plugin.js +2 -0
  215. package/dist/swagger/flow-surfaces.d.ts +5964 -0
  216. package/dist/swagger/flow-surfaces.examples.d.ts +1533 -0
  217. package/dist/swagger/flow-surfaces.examples.js +1758 -0
  218. package/dist/swagger/flow-surfaces.js +5315 -0
  219. package/dist/swagger/flow-surfaces.template-action-docs.d.ts +62 -0
  220. package/dist/swagger/flow-surfaces.template-action-docs.js +121 -0
  221. package/dist/swagger/flow-surfaces.template-schemas.d.ts +239 -0
  222. package/dist/swagger/flow-surfaces.template-schemas.js +255 -0
  223. package/dist/swagger/index.d.ts +5969 -0
  224. package/dist/swagger/index.js +50 -0
  225. package/package.json +2 -2
  226. /package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextApis.d.ts +0 -0
  227. /package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextEnvs.d.ts +0 -0
  228. /package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextVars.d.ts +0 -0
  229. /package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/lintAndTestJS.d.ts +0 -0
@@ -0,0 +1,589 @@
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
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var blueprint_service_exports = {};
38
+ __export(blueprint_service_exports, {
39
+ FlowSurfaceApprovalBlueprintService: () => FlowSurfaceApprovalBlueprintService
40
+ });
41
+ module.exports = __toCommonJS(blueprint_service_exports);
42
+ var import_data_source_manager = require("@nocobase/data-source-manager");
43
+ var import_utils = require("@nocobase/utils");
44
+ var import_lodash = __toESM(require("lodash"));
45
+ var import_service_utils = require("../service-utils");
46
+ var import_errors = require("../errors");
47
+ var import_blueprint = require("./blueprint");
48
+ var import_builder = require("./builder");
49
+ class FlowSurfaceApprovalBlueprintService {
50
+ constructor(deps) {
51
+ this.deps = deps;
52
+ }
53
+ parseApprovalBlueprintCollection(collectionValue) {
54
+ const normalizedCollection = String(collectionValue || "").trim();
55
+ if (!normalizedCollection) {
56
+ (0, import_errors.throwBadRequest)(`flowSurfaces applyApprovalBlueprint requires an approval workflow collection binding`);
57
+ }
58
+ let [dataSourceKey, collectionName] = (0, import_data_source_manager.parseCollectionName)(normalizedCollection);
59
+ if (!normalizedCollection.includes(":") && normalizedCollection.includes(".") && collectionName === normalizedCollection) {
60
+ const [candidateDataSourceKey, ...candidateCollectionParts] = normalizedCollection.split(".");
61
+ const candidateCollectionName = candidateCollectionParts.join(".");
62
+ if (candidateDataSourceKey && candidateCollectionName && this.deps.hasDataSource(candidateDataSourceKey)) {
63
+ dataSourceKey = candidateDataSourceKey;
64
+ collectionName = candidateCollectionName;
65
+ }
66
+ }
67
+ if (!collectionName) {
68
+ (0, import_errors.throwBadRequest)(`flowSurfaces applyApprovalBlueprint collection '${normalizedCollection}' is invalid`);
69
+ }
70
+ return {
71
+ dataSourceKey: dataSourceKey || "main",
72
+ collectionName
73
+ };
74
+ }
75
+ async resolveApprovalBlueprintBindingContext(document, transaction) {
76
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
77
+ if (!import_lodash.default.isUndefined(document.workflowId)) {
78
+ const workflow2 = await this.deps.db.getRepository("workflows").findOne({
79
+ filterByTk: document.workflowId,
80
+ transaction
81
+ });
82
+ if (!workflow2) {
83
+ (0, import_errors.throwBadRequest)(`flowSurfaces applyApprovalBlueprint workflow '${document.workflowId}' not found`);
84
+ }
85
+ if ((((_a = workflow2.get) == null ? void 0 : _a.call(workflow2, "type")) || workflow2.type) !== "approval") {
86
+ (0, import_errors.throwBadRequest)(
87
+ `flowSurfaces applyApprovalBlueprint workflow '${document.workflowId}' must be an approval workflow`
88
+ );
89
+ }
90
+ const workflowConfig2 = import_lodash.default.cloneDeep(((_b = workflow2.get) == null ? void 0 : _b.call(workflow2, "config")) || workflow2.config || {});
91
+ const collection2 = this.parseApprovalBlueprintCollection(workflowConfig2.collection);
92
+ return {
93
+ surface: document.surface,
94
+ ...collection2,
95
+ bindingResource: "workflows",
96
+ filterByTk: ((_c = workflow2.get) == null ? void 0 : _c.call(workflow2, "id")) || workflow2.id || document.workflowId,
97
+ rootUse: document.surface === "initiator" ? "TriggerChildPageModel" : "ApplyTaskCardDetailsModel",
98
+ rootUidKey: document.surface === "initiator" ? "approvalUid" : "taskCardUid",
99
+ existingUid: String(
100
+ document.surface === "initiator" ? workflowConfig2.approvalUid || "" : workflowConfig2.taskCardUid || ""
101
+ ).trim() || void 0,
102
+ workflowId: ((_d = workflow2.get) == null ? void 0 : _d.call(workflow2, "id")) || workflow2.id || document.workflowId,
103
+ workflow: workflow2
104
+ };
105
+ }
106
+ const node = await this.deps.db.getRepository("flow_nodes").findOne({
107
+ filterByTk: document.nodeId,
108
+ appends: ["workflow"],
109
+ transaction
110
+ });
111
+ if (!node) {
112
+ (0, import_errors.throwBadRequest)(`flowSurfaces applyApprovalBlueprint node '${document.nodeId}' not found`);
113
+ }
114
+ if ((((_e = node.get) == null ? void 0 : _e.call(node, "type")) || node.type) !== "approval") {
115
+ (0, import_errors.throwBadRequest)(`flowSurfaces applyApprovalBlueprint node '${document.nodeId}' must be an approval node`);
116
+ }
117
+ const workflow = ((_f = node.get) == null ? void 0 : _f.call(node, "workflow")) || node.workflow;
118
+ if (!workflow) {
119
+ (0, import_errors.throwBadRequest)(`flowSurfaces applyApprovalBlueprint node '${document.nodeId}' is missing its workflow relation`);
120
+ }
121
+ const resolvedNodeId = ((_g = node.get) == null ? void 0 : _g.call(node, "id")) || node.id || document.nodeId;
122
+ if (import_lodash.default.isNil(resolvedNodeId)) {
123
+ (0, import_errors.throwInternalError)(`flowSurfaces applyApprovalBlueprint node id could not be resolved`);
124
+ }
125
+ const workflowConfig = import_lodash.default.cloneDeep(((_h = workflow.get) == null ? void 0 : _h.call(workflow, "config")) || workflow.config || {});
126
+ const nodeConfig = import_lodash.default.cloneDeep(((_i = node.get) == null ? void 0 : _i.call(node, "config")) || node.config || {});
127
+ const collection = this.parseApprovalBlueprintCollection(workflowConfig.collection);
128
+ return {
129
+ surface: document.surface,
130
+ ...collection,
131
+ bindingResource: "flow_nodes",
132
+ filterByTk: resolvedNodeId,
133
+ rootUse: document.surface === "approver" ? "ApprovalChildPageModel" : "ApprovalTaskCardDetailsModel",
134
+ rootUidKey: document.surface === "approver" ? "approvalUid" : "taskCardUid",
135
+ existingUid: String(document.surface === "approver" ? nodeConfig.approvalUid || "" : nodeConfig.taskCardUid || "").trim() || void 0,
136
+ workflowId: ((_j = workflow.get) == null ? void 0 : _j.call(workflow, "id")) || workflow.id,
137
+ nodeId: resolvedNodeId,
138
+ workflow,
139
+ node
140
+ };
141
+ }
142
+ buildApprovalBlueprintSurfaceRootTree(context) {
143
+ switch (context.rootUse) {
144
+ case "TriggerChildPageModel":
145
+ return (0, import_builder.buildApprovalInitiatorSurfaceTree)({
146
+ dataSourceKey: context.dataSourceKey,
147
+ collectionName: context.collectionName
148
+ });
149
+ case "ApprovalChildPageModel":
150
+ return (0, import_builder.buildApprovalApproverSurfaceTree)({
151
+ dataSourceKey: context.dataSourceKey,
152
+ collectionName: context.collectionName
153
+ });
154
+ case "ApplyTaskCardDetailsModel":
155
+ return (0, import_builder.buildApprovalTaskCardSurfaceTree)({
156
+ detailsUse: "ApplyTaskCardDetailsModel",
157
+ gridUse: "ApplyTaskCardGridModel",
158
+ dataSourceKey: context.dataSourceKey,
159
+ collectionName: context.collectionName
160
+ });
161
+ case "ApprovalTaskCardDetailsModel":
162
+ return (0, import_builder.buildApprovalTaskCardSurfaceTree)({
163
+ detailsUse: "ApprovalTaskCardDetailsModel",
164
+ gridUse: "ApprovalTaskCardGridModel",
165
+ dataSourceKey: context.dataSourceKey,
166
+ collectionName: context.collectionName
167
+ });
168
+ default: {
169
+ const unsupportedUse = context.rootUse;
170
+ (0, import_errors.throwInternalError)(`flowSurfaces applyApprovalBlueprint unsupported root use '${unsupportedUse}'`);
171
+ }
172
+ }
173
+ }
174
+ buildApprovalBlueprintPageSurfaceRootTree(context) {
175
+ if (context.rootUse === "TriggerChildPageModel") {
176
+ return (0, import_builder.buildApprovalInitiatorSurfaceTree)({
177
+ dataSourceKey: context.dataSourceKey,
178
+ collectionName: context.collectionName
179
+ });
180
+ }
181
+ if (context.rootUse === "ApprovalChildPageModel") {
182
+ return (0, import_builder.buildApprovalApproverSurfaceTree)({
183
+ dataSourceKey: context.dataSourceKey,
184
+ collectionName: context.collectionName
185
+ });
186
+ }
187
+ (0, import_errors.throwInternalError)(`flowSurfaces applyApprovalBlueprint root use '${context.rootUse}' does not support tabs`);
188
+ }
189
+ getApprovalBlueprintExpectedTabUse(context) {
190
+ return context.rootUse === "TriggerChildPageModel" ? "TriggerChildPageTabModel" : "ApprovalChildPageTabModel";
191
+ }
192
+ getApprovalBlueprintExpectedGridUse(context) {
193
+ switch (context.rootUse) {
194
+ case "TriggerChildPageModel":
195
+ return "TriggerBlockGridModel";
196
+ case "ApprovalChildPageModel":
197
+ return "ApprovalBlockGridModel";
198
+ case "ApplyTaskCardDetailsModel":
199
+ return "ApplyTaskCardGridModel";
200
+ case "ApprovalTaskCardDetailsModel":
201
+ return "ApprovalTaskCardGridModel";
202
+ default: {
203
+ const unsupportedUse = context.rootUse;
204
+ (0, import_errors.throwInternalError)(`flowSurfaces applyApprovalBlueprint unsupported root use '${unsupportedUse}'`);
205
+ }
206
+ }
207
+ }
208
+ async findApprovalBlueprintSurfaceRoot(context, transaction) {
209
+ if (!context.existingUid) {
210
+ return null;
211
+ }
212
+ const root = await this.deps.repository.findModelById(context.existingUid, {
213
+ transaction,
214
+ includeAsyncNode: true
215
+ });
216
+ if (!(root == null ? void 0 : root.uid) || root.use !== context.rootUse) {
217
+ return null;
218
+ }
219
+ return root;
220
+ }
221
+ async createApprovalBlueprintSurfaceRoot(context, transaction) {
222
+ const tree = this.buildApprovalBlueprintSurfaceRootTree(context);
223
+ this.deps.contractGuard.validateNodeTreeAgainstContract(tree);
224
+ const root = await this.deps.repository.insertModel(tree, {
225
+ transaction
226
+ });
227
+ const grid = await this.deps.surfaceContext.resolveGridNode(root.uid, transaction);
228
+ return {
229
+ root,
230
+ rootUid: root.uid,
231
+ gridUid: grid.uid
232
+ };
233
+ }
234
+ async ensureApprovalBlueprintPageSurfaceStructure(root, context, transaction) {
235
+ var _a, _b, _c, _d, _e;
236
+ const expectedTabUse = this.getApprovalBlueprintExpectedTabUse(context);
237
+ let tab = import_lodash.default.castArray(((_a = root == null ? void 0 : root.subModels) == null ? void 0 : _a.tabs) || []).find((item) => (item == null ? void 0 : item.uid) && (item == null ? void 0 : item.use) === expectedTabUse) || import_lodash.default.castArray(((_b = root == null ? void 0 : root.subModels) == null ? void 0 : _b.tabs) || [])[0];
238
+ if (!(tab == null ? void 0 : tab.uid)) {
239
+ const defaultTree = this.buildApprovalBlueprintPageSurfaceRootTree(context);
240
+ const defaultTab = import_lodash.default.castArray(((_c = defaultTree == null ? void 0 : defaultTree.subModels) == null ? void 0 : _c.tabs) || [])[0];
241
+ await this.deps.repository.upsertModel(
242
+ {
243
+ parentId: root.uid,
244
+ subKey: "tabs",
245
+ subType: "array",
246
+ ...defaultTab
247
+ },
248
+ { transaction }
249
+ );
250
+ tab = await this.deps.repository.findModelById(defaultTab.uid, {
251
+ transaction,
252
+ includeAsyncNode: true
253
+ });
254
+ } else if (tab.use !== expectedTabUse) {
255
+ await this.deps.repository.patch(
256
+ {
257
+ uid: tab.uid,
258
+ use: expectedTabUse
259
+ },
260
+ { transaction }
261
+ );
262
+ tab = await this.deps.repository.findModelById(tab.uid, {
263
+ transaction,
264
+ includeAsyncNode: true
265
+ });
266
+ }
267
+ for (const extraTab of import_lodash.default.castArray(((_d = root == null ? void 0 : root.subModels) == null ? void 0 : _d.tabs) || []).filter(
268
+ (item) => (item == null ? void 0 : item.uid) && item.uid !== tab.uid
269
+ )) {
270
+ await this.deps.removeNodeTreeWithBindings(extraTab.uid, transaction);
271
+ }
272
+ const expectedGridUse = this.getApprovalBlueprintExpectedGridUse(context);
273
+ const grid = ((_e = tab == null ? void 0 : tab.subModels) == null ? void 0 : _e.grid) || ((tab == null ? void 0 : tab.uid) ? await this.deps.repository.findModelByParentId(tab.uid, {
274
+ transaction,
275
+ subKey: "grid",
276
+ includeAsyncNode: true
277
+ }) : null);
278
+ if (!(grid == null ? void 0 : grid.uid)) {
279
+ const gridUid = (0, import_utils.uid)();
280
+ await this.deps.repository.upsertModel(
281
+ {
282
+ uid: gridUid,
283
+ parentId: tab.uid,
284
+ subKey: "grid",
285
+ subType: "object",
286
+ async: true,
287
+ use: expectedGridUse
288
+ },
289
+ { transaction }
290
+ );
291
+ return gridUid;
292
+ }
293
+ if (grid.use !== expectedGridUse) {
294
+ await this.deps.repository.patch(
295
+ {
296
+ uid: grid.uid,
297
+ use: expectedGridUse
298
+ },
299
+ { transaction }
300
+ );
301
+ }
302
+ return grid.uid;
303
+ }
304
+ async ensureApprovalBlueprintTaskCardSurfaceStructure(root, context, transaction) {
305
+ var _a;
306
+ const expectedGridUse = this.getApprovalBlueprintExpectedGridUse(context);
307
+ const grid = ((_a = root == null ? void 0 : root.subModels) == null ? void 0 : _a.grid) || await this.deps.repository.findModelByParentId(root.uid, {
308
+ transaction,
309
+ subKey: "grid",
310
+ includeAsyncNode: true
311
+ });
312
+ if (!(grid == null ? void 0 : grid.uid)) {
313
+ const gridUid = (0, import_utils.uid)();
314
+ await this.deps.repository.upsertModel(
315
+ {
316
+ uid: gridUid,
317
+ parentId: root.uid,
318
+ subKey: "grid",
319
+ subType: "object",
320
+ use: expectedGridUse
321
+ },
322
+ { transaction }
323
+ );
324
+ return gridUid;
325
+ }
326
+ if (grid.use !== expectedGridUse) {
327
+ await this.deps.repository.patch(
328
+ {
329
+ uid: grid.uid,
330
+ use: expectedGridUse
331
+ },
332
+ { transaction }
333
+ );
334
+ }
335
+ return grid.uid;
336
+ }
337
+ async syncApprovalBlueprintSurfaceAsyncShape(surfaceRoot, context, transaction) {
338
+ await this.deps.setNodeAsyncFlag(surfaceRoot.rootUid, true, transaction);
339
+ if (context.surface === "taskCard") {
340
+ return;
341
+ }
342
+ await this.deps.setNodeAsyncFlag(surfaceRoot.gridUid, true, transaction);
343
+ }
344
+ async syncApprovalBlueprintSurfaceRoot(rootUid, context, transaction) {
345
+ const root = await this.deps.repository.findModelById(rootUid, {
346
+ transaction,
347
+ includeAsyncNode: true
348
+ });
349
+ if (!(root == null ? void 0 : root.uid)) {
350
+ return;
351
+ }
352
+ const stepParams = import_lodash.default.cloneDeep(root.stepParams || {});
353
+ const nextInit = {
354
+ dataSourceKey: context.dataSourceKey,
355
+ collectionName: context.collectionName
356
+ };
357
+ if (context.rootUse === "TriggerChildPageModel") {
358
+ const currentInit2 = import_lodash.default.get(stepParams, ["TriggerChildPageSettings", "init"]) || {};
359
+ if (import_lodash.default.isEqual(currentInit2, nextInit)) {
360
+ return;
361
+ }
362
+ import_lodash.default.set(stepParams, ["TriggerChildPageSettings", "init"], nextInit);
363
+ await this.deps.repository.patch(
364
+ {
365
+ uid: rootUid,
366
+ stepParams
367
+ },
368
+ { transaction }
369
+ );
370
+ return;
371
+ }
372
+ if (context.rootUse === "ApprovalChildPageModel") {
373
+ const currentInit2 = import_lodash.default.get(stepParams, ["ApprovalChildPageSettings", "init"]) || {};
374
+ const currentResourceInit = import_lodash.default.get(stepParams, ["resourceSettings", "init"]) || {};
375
+ if (import_lodash.default.isEqual(currentInit2, nextInit) && import_lodash.default.isEqual(currentResourceInit, nextInit)) {
376
+ return;
377
+ }
378
+ import_lodash.default.set(stepParams, ["ApprovalChildPageSettings", "init"], nextInit);
379
+ import_lodash.default.set(stepParams, ["resourceSettings", "init"], nextInit);
380
+ await this.deps.repository.patch(
381
+ {
382
+ uid: rootUid,
383
+ stepParams
384
+ },
385
+ { transaction }
386
+ );
387
+ return;
388
+ }
389
+ const currentInit = import_lodash.default.get(stepParams, ["resourceSettings", "init"]) || {};
390
+ if (!import_lodash.default.isEqual(currentInit, nextInit)) {
391
+ import_lodash.default.set(stepParams, ["resourceSettings", "init"], nextInit);
392
+ }
393
+ if (!import_lodash.default.get(stepParams, ["detailsSettings", "layout", "layout"])) {
394
+ import_lodash.default.set(stepParams, ["detailsSettings", "layout", "layout"], "horizontal");
395
+ }
396
+ if (import_lodash.default.isEqual(stepParams, root.stepParams || {})) {
397
+ return;
398
+ }
399
+ await this.deps.repository.patch(
400
+ {
401
+ uid: rootUid,
402
+ stepParams
403
+ },
404
+ { transaction }
405
+ );
406
+ }
407
+ async ensureApprovalBlueprintSurfaceRoot(context, transaction) {
408
+ const existingRoot = await this.findApprovalBlueprintSurfaceRoot(context, transaction);
409
+ if (!(existingRoot == null ? void 0 : existingRoot.uid)) {
410
+ return this.createApprovalBlueprintSurfaceRoot(context, transaction);
411
+ }
412
+ const gridUid = context.surface === "taskCard" ? await this.ensureApprovalBlueprintTaskCardSurfaceStructure(existingRoot, context, transaction) : await this.ensureApprovalBlueprintPageSurfaceStructure(existingRoot, context, transaction);
413
+ await this.syncApprovalBlueprintSurfaceAsyncShape(
414
+ {
415
+ root: existingRoot,
416
+ rootUid: existingRoot.uid,
417
+ gridUid
418
+ },
419
+ context,
420
+ transaction
421
+ );
422
+ await this.syncApprovalBlueprintSurfaceRoot(existingRoot.uid, context, transaction);
423
+ const root = await this.deps.repository.findModelById(existingRoot.uid, {
424
+ transaction,
425
+ includeAsyncNode: true
426
+ });
427
+ return {
428
+ root,
429
+ rootUid: root.uid,
430
+ gridUid
431
+ };
432
+ }
433
+ async persistApprovalBlueprintBinding(context, rootUid, transaction) {
434
+ var _a;
435
+ const configSource = context.bindingResource === "workflows" ? context.workflow : context.node;
436
+ const currentConfig = import_lodash.default.cloneDeep(((_a = configSource == null ? void 0 : configSource.get) == null ? void 0 : _a.call(configSource, "config")) || (configSource == null ? void 0 : configSource.config) || {});
437
+ if ((currentConfig == null ? void 0 : currentConfig[context.rootUidKey]) === rootUid) {
438
+ return;
439
+ }
440
+ await this.deps.db.getRepository(context.bindingResource).update({
441
+ filterByTk: context.filterByTk,
442
+ values: {
443
+ config: {
444
+ ...currentConfig,
445
+ [context.rootUidKey]: rootUid
446
+ }
447
+ },
448
+ transaction
449
+ });
450
+ }
451
+ async applyApprovalBlueprintPageSurface(document, surfaceRoot, options) {
452
+ await this.deps.compose(
453
+ {
454
+ target: {
455
+ uid: surfaceRoot.gridUid
456
+ },
457
+ mode: "replace",
458
+ blocks: document.blocks || [],
459
+ layout: document.layout
460
+ },
461
+ options
462
+ );
463
+ }
464
+ async applyApprovalBlueprintTaskCardSurface(document, surfaceRoot, context, options) {
465
+ var _a, _b;
466
+ const normalizedFields = import_lodash.default.castArray(document.fields || []).map(
467
+ (item, index) => (0, import_service_utils.normalizeComposeFieldSpec)(item, index)
468
+ );
469
+ normalizedFields.forEach((field) => {
470
+ if (field.target) {
471
+ (0, import_errors.throwBadRequest)(`flowSurfaces applyApprovalBlueprint taskCard fields do not support target`);
472
+ }
473
+ });
474
+ (0, import_service_utils.assertFlowSurfaceComposeUniqueKeys)(normalizedFields, "flowSurfaces applyApprovalBlueprint taskCard fields");
475
+ const initialGrid = await this.deps.repository.findModelById(surfaceRoot.gridUid, {
476
+ transaction: options.transaction,
477
+ includeAsyncNode: true
478
+ });
479
+ for (const item of import_lodash.default.castArray(((_a = initialGrid == null ? void 0 : initialGrid.subModels) == null ? void 0 : _a.items) || []).filter((candidate) => candidate == null ? void 0 : candidate.uid)) {
480
+ await this.deps.removeNodeTreeWithBindings(item.uid, options.transaction);
481
+ }
482
+ const createdByKey = {};
483
+ for (const fieldSpec of normalizedFields) {
484
+ let result;
485
+ try {
486
+ result = await this.deps.addField(
487
+ {
488
+ target: {
489
+ uid: surfaceRoot.rootUid
490
+ },
491
+ ...fieldSpec.key ? { key: fieldSpec.key } : {},
492
+ dataSourceKey: context.dataSourceKey,
493
+ collectionName: context.collectionName,
494
+ ...fieldSpec.fieldPath ? { fieldPath: fieldSpec.fieldPath } : {},
495
+ ...fieldSpec.associationPathName ? { associationPathName: fieldSpec.associationPathName } : {},
496
+ ...fieldSpec.renderer ? { renderer: fieldSpec.renderer } : {},
497
+ ...fieldSpec.type ? { type: fieldSpec.type } : {},
498
+ ...fieldSpec.popup ? { popup: fieldSpec.popup } : {},
499
+ ...Object.keys(fieldSpec.settings || {}).length ? { settings: fieldSpec.settings } : {}
500
+ },
501
+ options
502
+ );
503
+ } catch (error) {
504
+ if ((0, import_errors.isFlowSurfaceError)(error)) {
505
+ throw error;
506
+ }
507
+ const message = error instanceof Error ? error.message : String(error);
508
+ (0, import_errors.throwInternalError)(
509
+ `flowSurfaces applyApprovalBlueprint taskCard addField '${fieldSpec.key}' failed: ${message}`
510
+ );
511
+ }
512
+ createdByKey[fieldSpec.key] = {
513
+ uid: result.wrapperUid || result.uid
514
+ };
515
+ }
516
+ const finalGrid = await this.deps.repository.findModelById(surfaceRoot.gridUid, {
517
+ transaction: options.transaction,
518
+ includeAsyncNode: true
519
+ });
520
+ const layoutPayload = this.deps.buildComposeLayoutPayload({
521
+ layout: document.layout,
522
+ createdByKey,
523
+ finalItems: import_lodash.default.castArray(((_b = finalGrid == null ? void 0 : finalGrid.subModels) == null ? void 0 : _b.items) || []).filter((item) => item == null ? void 0 : item.uid)
524
+ });
525
+ try {
526
+ await this.deps.setLayout(
527
+ {
528
+ target: {
529
+ uid: surfaceRoot.gridUid
530
+ },
531
+ ...layoutPayload
532
+ },
533
+ options
534
+ );
535
+ } catch (error) {
536
+ if ((0, import_errors.isFlowSurfaceError)(error)) {
537
+ throw error;
538
+ }
539
+ const message = error instanceof Error ? error.message : String(error);
540
+ (0, import_errors.throwInternalError)(`flowSurfaces applyApprovalBlueprint taskCard setLayout failed: ${message}`);
541
+ }
542
+ }
543
+ async applyApprovalBlueprint(values, options = {}) {
544
+ const document = (0, import_blueprint.prepareFlowSurfaceApplyApprovalBlueprintDocument)(values);
545
+ const bindingContext = await this.resolveApprovalBlueprintBindingContext(document, options.transaction);
546
+ const surfaceRoot = await this.ensureApprovalBlueprintSurfaceRoot(bindingContext, options.transaction);
547
+ await this.persistApprovalBlueprintBinding(bindingContext, surfaceRoot.rootUid, options.transaction);
548
+ if (document.surface === "taskCard") {
549
+ await this.applyApprovalBlueprintTaskCardSurface(document, surfaceRoot, bindingContext, options);
550
+ } else {
551
+ await this.applyApprovalBlueprintPageSurface(document, surfaceRoot, options);
552
+ }
553
+ await this.deps.syncApprovalRuntimeConfigForSurfaceRoot({ uid: surfaceRoot.rootUid }, options.transaction);
554
+ let surface;
555
+ try {
556
+ surface = await this.deps.get(
557
+ {
558
+ uid: surfaceRoot.rootUid
559
+ },
560
+ options
561
+ );
562
+ } catch (error) {
563
+ const message = error instanceof Error ? error.message : String(error);
564
+ (0, import_errors.throwInternalError)(
565
+ `flowSurfaces applyApprovalBlueprint readback failed for '${surfaceRoot.rootUid}': ${message}`
566
+ );
567
+ }
568
+ return {
569
+ version: "1",
570
+ mode: document.mode,
571
+ surfaceType: document.surface,
572
+ target: (0, import_service_utils.buildDefinedPayload)({
573
+ uid: surfaceRoot.rootUid,
574
+ workflowId: bindingContext.workflowId,
575
+ nodeId: bindingContext.nodeId
576
+ }),
577
+ binding: {
578
+ resourceName: bindingContext.bindingResource,
579
+ filterByTk: bindingContext.filterByTk,
580
+ configPath: `config.${bindingContext.rootUidKey}`
581
+ },
582
+ surface
583
+ };
584
+ }
585
+ }
586
+ // Annotate the CommonJS export names for ESM import in node:
587
+ 0 && (module.exports = {
588
+ FlowSurfaceApprovalBlueprintService
589
+ });
@@ -0,0 +1,21 @@
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 declare const FLOW_SURFACE_APPROVAL_BLUEPRINT_SURFACES: readonly ["initiator", "approver", "taskCard"];
10
+ export type FlowSurfaceApprovalBlueprintSurface = (typeof FLOW_SURFACE_APPROVAL_BLUEPRINT_SURFACES)[number];
11
+ export type FlowSurfaceApplyApprovalBlueprintDocument = {
12
+ version: '1';
13
+ mode: 'replace';
14
+ surface: FlowSurfaceApprovalBlueprintSurface;
15
+ workflowId?: string | number;
16
+ nodeId?: string | number;
17
+ blocks?: Record<string, any>[];
18
+ fields?: Array<string | Record<string, any>>;
19
+ layout?: Record<string, any>;
20
+ };
21
+ export declare function prepareFlowSurfaceApplyApprovalBlueprintDocument(values: Record<string, any>): FlowSurfaceApplyApprovalBlueprintDocument;