diff --git a/packages/objectql/package.json b/packages/objectql/package.json index 47125ebfa4..299e85f5b9 100644 --- a/packages/objectql/package.json +++ b/packages/objectql/package.json @@ -28,6 +28,7 @@ "@steedos/schemas": "2.7.11-beta.2", "@steedos/standard-objects": "2.7.11-beta.2", "amis-formula": "~6.3.0", + "axios": "^0.21.1", "app-root-path": "^2.2.1", "body-parser": "^1.18.1", "bunyan-sfdx-no-dtrace": "^1.8.2", diff --git a/packages/objectql/src/triggers/trigger.ts b/packages/objectql/src/triggers/trigger.ts index 908e9c25bb..dc7779f1e4 100644 --- a/packages/objectql/src/triggers/trigger.ts +++ b/packages/objectql/src/triggers/trigger.ts @@ -2,11 +2,13 @@ * @Author: baozhoutao@steedos.com * @Date: 2023-04-23 13:35:17 * @LastEditors: baozhoutao@steedos.com - * @LastEditTime: 2024-04-02 14:00:47 + * @LastEditTime: 2024-11-25 10:41:20 * @Description: */ const { NodeVM } = require('vm2'); +const _ = require('lodash'); import { ObjectId } from "mongodb"; +import axios from 'axios'; function str2function( contents, @@ -21,8 +23,68 @@ function str2function( } } +const sendPost = async (url, body, options)=>{ + try { + return await axios.post(url, body, options); + } catch (error) { + throw new Error(`请求失败(${error.message}): ${url}`) + } +} + + + +/** + * + * 请求参数(body): { + objectName, + userId, + spaceId, + doc + * } + * 接口返回参数结构: + { + "error": { + "code": "", + "message": "", + }, + "data": { + + } + } + */ +const runUrlTrigger = async (trigger, thisArg, args)=>{ + if(!trigger.url){ + throw new Error(`触发器「${trigger.name}」缺少URL`) + } + + const headers = { + 'Content-Type': 'application/json', + }; + + if(trigger.authentication_type == 'header'){ + headers[trigger.authentication_header_key] = trigger.authentication_header_value + } + + const { data: rsBody, status: httpStatus } = await sendPost(trigger.url, args && args.length > 0 ? args[0].params : {}, { headers }); + if(httpStatus !== 200){ + throw new Error(`请求失败: ${trigger.url}`) + } + let { error, data } = rsBody; + + if(error && error.message){ + throw new Error(error.message) + } + return data +} + export const runTriggerFunction = async (trigger, thisArg, ...args)=>{ + + if(trigger.type === 'url'){ + return await runUrlTrigger(trigger, thisArg, args) + } + + // ----- code trigger ----- const vm = new NodeVM({ sandbox: { str2function, diff --git a/services/service-plugin-amis/public/tailwind/tailwind-steedos.css b/services/service-plugin-amis/public/tailwind/tailwind-steedos.css index e9c0d0d18f..226a6217f4 100644 --- a/services/service-plugin-amis/public/tailwind/tailwind-steedos.css +++ b/services/service-plugin-amis/public/tailwind/tailwind-steedos.css @@ -64,6 +64,10 @@ position: absolute } +.relative { + position: relative +} + .sticky { position: sticky } @@ -75,6 +79,10 @@ left: 0px } +.isolate { + isolation: isolate +} + .z-20 { z-index: 20 } diff --git a/services/standard-object-database/main/default/objects/object_triggers/fields/authentication_header_key.field.yml b/services/standard-object-database/main/default/objects/object_triggers/fields/authentication_header_key.field.yml new file mode 100644 index 0000000000..39e35ac86b --- /dev/null +++ b/services/standard-object-database/main/default/objects/object_triggers/fields/authentication_header_key.field.yml @@ -0,0 +1,10 @@ +name: authentication_header_key +type: text +label: Header Name +group: 认证 +sort_no: 180 +visible_on: ${type === 'url' && authentication_type === 'header'} +amis: + - options: + - label: authorization + value: authorization \ No newline at end of file diff --git a/services/standard-object-database/main/default/objects/object_triggers/fields/authentication_header_value.field.yml b/services/standard-object-database/main/default/objects/object_triggers/fields/authentication_header_value.field.yml new file mode 100644 index 0000000000..2caf6aaf8a --- /dev/null +++ b/services/standard-object-database/main/default/objects/object_triggers/fields/authentication_header_value.field.yml @@ -0,0 +1,6 @@ +name: authentication_header_value +type: text +label: Header Value +group: 认证 +sort_no: 190 +visible_on: ${type === 'url' && authentication_type === 'header'} diff --git a/services/standard-object-database/main/default/objects/object_triggers/fields/authentication_type.field.yml b/services/standard-object-database/main/default/objects/object_triggers/fields/authentication_type.field.yml new file mode 100644 index 0000000000..7ae25f6632 --- /dev/null +++ b/services/standard-object-database/main/default/objects/object_triggers/fields/authentication_type.field.yml @@ -0,0 +1,12 @@ +name: authentication_type +label: 认证类型 +type: select +group: 认证 +options: + - label: 不认证 + value: none + - label: Header Auth + value: header +defaultValue: none +sort_no: 170 +visible_on: ${type === 'url'} \ No newline at end of file diff --git a/services/standard-object-database/main/default/objects/object_triggers/fields/handler.field.yml b/services/standard-object-database/main/default/objects/object_triggers/fields/handler.field.yml index 03285cbd98..d1dfb1fae8 100644 --- a/services/standard-object-database/main/default/objects/object_triggers/fields/handler.field.yml +++ b/services/standard-object-database/main/default/objects/object_triggers/fields/handler.field.yml @@ -23,3 +23,4 @@ editorDidMount: >- result ); sort_no: 150 +visible_on: ${type != 'url'} \ No newline at end of file diff --git a/services/standard-object-database/main/default/objects/object_triggers/fields/type.field.yml b/services/standard-object-database/main/default/objects/object_triggers/fields/type.field.yml new file mode 100644 index 0000000000..390bba332c --- /dev/null +++ b/services/standard-object-database/main/default/objects/object_triggers/fields/type.field.yml @@ -0,0 +1,10 @@ +name: type +label: 类型 +type: select +options: + - label: 代码 + value: code + - label: 接口 + value: url +defaultValue: code +sort_no: 132 \ No newline at end of file diff --git a/services/standard-object-database/main/default/objects/object_triggers/fields/url.field.yml b/services/standard-object-database/main/default/objects/object_triggers/fields/url.field.yml new file mode 100644 index 0000000000..cb8879b700 --- /dev/null +++ b/services/standard-object-database/main/default/objects/object_triggers/fields/url.field.yml @@ -0,0 +1,6 @@ +name: url +type: url +label: URL +sort_no: 160 +is_wide: true +visible_on: ${type === 'url'} \ No newline at end of file