@tachybase/module-workflow 0.23.58 → 1.0.18

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.
@@ -0,0 +1,232 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var UpdateOrCreateInstruction_exports = {};
29
+ __export(UpdateOrCreateInstruction_exports, {
30
+ UpdateOrCreateInstruction: () => UpdateOrCreateInstruction,
31
+ default: () => UpdateOrCreateInstruction_default
32
+ });
33
+ module.exports = __toCommonJS(UpdateOrCreateInstruction_exports);
34
+ var import_data_source = require("@tachybase/data-source");
35
+ var import_server = require("@tachybase/server");
36
+ var import_utils = require("@tachybase/utils");
37
+ var import_axios = __toESM(require("axios"));
38
+ var import_form_data = __toESM(require("form-data"));
39
+ var import_lodash = __toESM(require("lodash"));
40
+ var import_mime_types = __toESM(require("mime-types"));
41
+ var import__ = require(".");
42
+ var import_constants = require("../constants");
43
+ var import_utils2 = require("../utils");
44
+ class UpdateOrCreateInstruction extends import__.Instruction {
45
+ async run(node, input, processor) {
46
+ var _a, _b, _c, _d;
47
+ const { collection, params: { appends = [], ...params } = {} } = node.config;
48
+ const [dataSourceName, collectionName] = (0, import_data_source.parseCollectionName)(collection);
49
+ const { repository, filterTargetKey } = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName).collectionManager.getCollection(collectionName);
50
+ const options = processor.getParsedValue(params, node.id);
51
+ const transaction = this.workflow.useDataSourceTransaction(dataSourceName, processor.transaction);
52
+ const c = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName).collectionManager.getCollection(collectionName);
53
+ const fields = c.getFields();
54
+ const fieldNames = Object.keys(params.values);
55
+ const includesFields = fields.filter((field) => fieldNames.includes(field.options.name));
56
+ const userId = import_lodash.default.get(processor.getScope(node.id), "$context.user.id", "");
57
+ const token = this.workflow.app.authManager.jwt.sign({ userId });
58
+ const isJSON = (str) => {
59
+ try {
60
+ return JSON.parse(str);
61
+ } catch (e) {
62
+ return false;
63
+ }
64
+ };
65
+ const handleResource = async (resource) => {
66
+ if (typeof resource === "object" && (resource == null ? void 0 : resource.url) && (resource == null ? void 0 : resource.filename)) {
67
+ const {
68
+ id,
69
+ createdAt,
70
+ updatedAt,
71
+ title,
72
+ filename,
73
+ extname,
74
+ size,
75
+ mimetype,
76
+ path,
77
+ meta,
78
+ url,
79
+ createById,
80
+ updatedById,
81
+ storageId
82
+ } = resource;
83
+ return {
84
+ id,
85
+ createdAt,
86
+ updatedAt,
87
+ title,
88
+ filename,
89
+ extname,
90
+ size,
91
+ mimetype,
92
+ path,
93
+ meta,
94
+ url,
95
+ createById,
96
+ updatedById,
97
+ storageId
98
+ };
99
+ }
100
+ const parseRes = isJSON(resource);
101
+ const config = {
102
+ method: "get",
103
+ url: resource,
104
+ responseType: "stream"
105
+ };
106
+ const form = new import_form_data.default();
107
+ if (resource.startsWith("data:")) {
108
+ const matches = resource.match(/^data:(.+);base64,(.+)$/);
109
+ if (matches) {
110
+ const contentType = matches[1];
111
+ const base64Data = matches[2];
112
+ const buffer = Buffer.from(base64Data, "base64");
113
+ const ext = import_mime_types.default.extension(contentType);
114
+ const filename = `${(0, import_utils.uid)()}.${ext}`;
115
+ form.append("file", buffer, {
116
+ filename,
117
+ contentType
118
+ });
119
+ } else {
120
+ throw new Error("Invalid data URL format");
121
+ }
122
+ } else if (parseRes) {
123
+ const {
124
+ url: resourceUrl,
125
+ params: resourceParams,
126
+ headers: resourceHeaders,
127
+ body: resourceBody,
128
+ filename
129
+ } = parseRes;
130
+ config.url = resourceUrl;
131
+ config.params = resourceParams;
132
+ config.headers = resourceHeaders;
133
+ if (resourceHeaders["content-type"] === "multipart/form-data") {
134
+ const formData = new import_form_data.default();
135
+ Object.entries(resourceBody).forEach(([key, value]) => {
136
+ formData.append(key, value);
137
+ });
138
+ config.data = formData;
139
+ } else {
140
+ config.data = resourceBody;
141
+ }
142
+ const response = await (0, import_axios.default)(config);
143
+ const contentType = response.headers["content-type"];
144
+ const ext = import_mime_types.default.extension(contentType);
145
+ const fullFilename = `${filename || (0, import_utils.uid)()}.${ext}`;
146
+ form.append("file", response.data, {
147
+ filename: fullFilename,
148
+ contentType: response.headers["content-type"]
149
+ });
150
+ } else {
151
+ const response = await (0, import_axios.default)(config);
152
+ const contentType = response.headers["content-type"];
153
+ const ext = import_mime_types.default.extension(contentType);
154
+ const filename = `${(0, import_utils.uid)()}.${ext}`;
155
+ form.append("file", response.data, {
156
+ filename,
157
+ contentType: response.headers["content-type"]
158
+ });
159
+ }
160
+ const origin = import_server.Gateway.getInstance().runAtLoop;
161
+ const uploadResponse = await (0, import_axios.default)({
162
+ method: "post",
163
+ url: origin + "/api/attachments:create",
164
+ data: form,
165
+ headers: {
166
+ ...form.getHeaders(),
167
+ Authorization: "Bearer " + token
168
+ }
169
+ });
170
+ return uploadResponse.data.data;
171
+ };
172
+ for (const attachmentField of includesFields) {
173
+ if (attachmentField.options.interface === "attachment") {
174
+ let targetField = options.values[attachmentField.options.name];
175
+ if (Array.isArray(targetField)) {
176
+ for (const i in targetField) {
177
+ targetField[i] = await handleResource(targetField[i]);
178
+ }
179
+ } else {
180
+ options.values[attachmentField.options.name] = [await handleResource(targetField)];
181
+ }
182
+ }
183
+ }
184
+ const instance = await repository.findOne({ filter: options.filter, transaction });
185
+ if (instance) {
186
+ const result = await repository.update({
187
+ ...options,
188
+ context: {
189
+ stack: Array.from(new Set((processor.execution.context.stack ?? []).concat(processor.execution.id))),
190
+ state: (_b = (_a = processor.options) == null ? void 0 : _a.httpContext) == null ? void 0 : _b.state
191
+ },
192
+ transaction
193
+ });
194
+ return {
195
+ result: result.length ?? result,
196
+ status: import_constants.JOB_STATUS.RESOLVED
197
+ };
198
+ } else {
199
+ const created = await repository.create({
200
+ ...options,
201
+ context: {
202
+ stack: Array.from(new Set((processor.execution.context.stack ?? []).concat(processor.execution.id))),
203
+ state: (_d = (_c = processor.options) == null ? void 0 : _c.httpContext) == null ? void 0 : _d.state
204
+ },
205
+ transaction
206
+ });
207
+ let result = created;
208
+ if (created && appends.length) {
209
+ const includeFields = appends.reduce((set, field) => {
210
+ set.add(field.split(".")[0]);
211
+ set.add(field);
212
+ return set;
213
+ }, /* @__PURE__ */ new Set());
214
+ result = await repository.findOne({
215
+ filterByTk: created[filterTargetKey],
216
+ appends: Array.from(includeFields),
217
+ transaction
218
+ });
219
+ }
220
+ return {
221
+ // NOTE: get() for non-proxied instance (#380)
222
+ result: (0, import_utils2.toJSON)(result),
223
+ status: import_constants.JOB_STATUS.RESOLVED
224
+ };
225
+ }
226
+ }
227
+ }
228
+ var UpdateOrCreateInstruction_default = UpdateOrCreateInstruction;
229
+ // Annotate the CommonJS export names for ESM import in node:
230
+ 0 && (module.exports = {
231
+ UpdateOrCreateInstruction
232
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tachybase/module-workflow",
3
3
  "displayName": "Workflow",
4
- "version": "0.23.58",
4
+ "version": "1.0.18",
5
5
  "description": "A powerful BPM tool that provides foundational support for business automation, with the capability to extend unlimited triggers and nodes.",
6
6
  "keywords": [
7
7
  "Workflow"
@@ -35,24 +35,25 @@
35
35
  "react-js-cron": "^3.2.0",
36
36
  "react-router-dom": "6.28.1",
37
37
  "sequelize": "^6.37.5",
38
- "@tachybase/components": "0.23.58",
39
- "@tachybase/plugin-workflow-test": "0.23.58"
38
+ "@tachybase/components": "1.0.18",
39
+ "@tachybase/plugin-workflow-test": "1.0.18"
40
40
  },
41
41
  "peerDependencies": {
42
- "@tachybase/actions": "0.23.58",
43
- "@tachybase/data-source": "0.23.58",
44
- "@tachybase/client": "0.23.58",
45
- "@tachybase/database": "0.23.58",
46
- "@tachybase/evaluators": "0.23.58",
47
- "@tachybase/logger": "0.23.58",
48
- "@tachybase/module-collection": "0.23.58",
49
- "@tachybase/module-error-handler": "0.23.58",
50
- "@tachybase/module-user": "0.23.58",
51
- "@tachybase/resourcer": "0.23.58",
52
- "@tachybase/server": "0.23.58",
53
- "@tachybase/utils": "0.23.58",
54
- "@tachybase/test": "0.23.58",
55
- "@tachybase/schema": "0.23.58"
42
+ "@tachybase/actions": "1.0.18",
43
+ "@tachybase/client": "1.0.18",
44
+ "@tachybase/data-source": "1.0.18",
45
+ "@tachybase/database": "1.0.18",
46
+ "@tachybase/evaluators": "1.0.18",
47
+ "@tachybase/logger": "1.0.18",
48
+ "@tachybase/module-collection": "1.0.18",
49
+ "@tachybase/module-error-handler": "1.0.18",
50
+ "@tachybase/module-ui-schema": "1.0.18",
51
+ "@tachybase/module-user": "1.0.18",
52
+ "@tachybase/schema": "1.0.18",
53
+ "@tachybase/server": "1.0.18",
54
+ "@tachybase/resourcer": "1.0.18",
55
+ "@tachybase/test": "1.0.18",
56
+ "@tachybase/utils": "1.0.18"
56
57
  },
57
58
  "description.zh-CN": "一个强大的 BPM 工具,为业务自动化提供基础支持,并且可任意扩展更多的触发器和节点。",
58
59
  "displayName.zh-CN": "工作流",