app_bridge 4.1.1 → 6.0.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.
- checksums.yaml +4 -4
- data/.tool-versions +1 -1
- data/CHANGELOG.md +4 -0
- data/Cargo.lock +569 -801
- data/Cargo.toml +1 -1
- data/README.md +7 -1
- data/Rakefile +16 -13
- data/ext/app_bridge/Cargo.toml +6 -4
- data/ext/app_bridge/docs/connection-config-schema.json +500 -0
- data/ext/app_bridge/src/app_state.rs +14 -8
- data/ext/app_bridge/src/component.rs +177 -25
- data/ext/app_bridge/src/error_mapping.rs +5 -0
- data/ext/app_bridge/src/file_ops.rs +3 -1
- data/ext/app_bridge/src/lib.rs +5 -0
- data/ext/app_bridge/src/request_builder.rs +7 -1
- data/ext/app_bridge/src/wrappers/action_context.rs +9 -8
- data/ext/app_bridge/src/wrappers/app.rs +128 -37
- data/ext/app_bridge/src/wrappers/trigger_context.rs +5 -4
- data/ext/app_bridge/wit/v5/world.wit +363 -0
- data/ext/app_bridge/wit/v6/world.wit +385 -0
- data/lib/app_bridge/app.rb +49 -0
- data/lib/app_bridge/connection_config_validator.rb +101 -0
- data/lib/app_bridge/version.rb +1 -1
- data/lib/app_bridge.rb +2 -0
- data/sig/app_bridge.rbs +3 -0
- data/tasks/fixtures.rake +32 -4
- metadata +21 -3
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
use crate::component::v6::{self, standout::app::types::{ActionSchemaContext, TriggerSchemaContext, SchemaResponse}};
|
|
2
|
+
use super::connection::RConnection;
|
|
1
3
|
use magnus::{Error, TryConvert, Value};
|
|
2
4
|
use std::cell::RefCell;
|
|
3
5
|
use std::collections::HashMap;
|
|
@@ -5,6 +7,7 @@ use wasmtime::Store;
|
|
|
5
7
|
|
|
6
8
|
use crate::app_state::AppState;
|
|
7
9
|
use crate::component::{app, build_engine, build_linker, build_store, BridgeWrapper};
|
|
10
|
+
use crate::error_mapping::runtime_error;
|
|
8
11
|
use crate::types::{ActionContext, ActionResponse, AppError, ErrorCode, TriggerContext, TriggerResponse};
|
|
9
12
|
use super::{
|
|
10
13
|
action_context::RActionContext,
|
|
@@ -33,10 +36,45 @@ impl MutRApp {
|
|
|
33
36
|
if let Some(instance) = &*instance {
|
|
34
37
|
Ok(instance.wit_version().to_string())
|
|
35
38
|
} else {
|
|
36
|
-
Err(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
Err(runtime_error("App not initialized"))
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
pub fn connections_supported(&self) -> Result<bool, Error> {
|
|
44
|
+
let binding = self.0.borrow();
|
|
45
|
+
let instance = binding.instance.borrow();
|
|
46
|
+
|
|
47
|
+
if let Some(instance) = &*instance {
|
|
48
|
+
Ok(instance.connections_supported())
|
|
49
|
+
} else {
|
|
50
|
+
Err(runtime_error("App not initialized"))
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
pub fn connection_config(&self) -> Result<String, Error> {
|
|
55
|
+
let binding = self.0.borrow();
|
|
56
|
+
let mut instance = binding.instance.borrow_mut();
|
|
57
|
+
let mut store = binding.store.borrow_mut();
|
|
58
|
+
|
|
59
|
+
if let (Some(instance), Some(store)) = (&mut *instance, &mut *store) {
|
|
60
|
+
if !instance.connections_supported() {
|
|
61
|
+
return Err(AppError {
|
|
62
|
+
code: ErrorCode::Unsupported,
|
|
63
|
+
message: "connections interface not supported by this component version"
|
|
64
|
+
.to_string(),
|
|
65
|
+
}
|
|
66
|
+
.into());
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
instance.call_connection_config(store).map_err(|err| {
|
|
70
|
+
runtime_error(format!("Failed to read connection-config: {err}"))
|
|
71
|
+
})
|
|
72
|
+
} else {
|
|
73
|
+
Err(AppError {
|
|
74
|
+
code: ErrorCode::InternalError,
|
|
75
|
+
message: "App instance couldn't be initialized".to_string(),
|
|
76
|
+
}
|
|
77
|
+
.into())
|
|
40
78
|
}
|
|
41
79
|
}
|
|
42
80
|
|
|
@@ -44,10 +82,7 @@ impl MutRApp {
|
|
|
44
82
|
let mut this = self.0.borrow_mut();
|
|
45
83
|
let engine = build_engine();
|
|
46
84
|
let linker = build_linker(&engine).map_err(|e| {
|
|
47
|
-
|
|
48
|
-
magnus::exception::runtime_error(),
|
|
49
|
-
format!("Failed to build linker: {}", e),
|
|
50
|
-
)
|
|
85
|
+
runtime_error(format!("Failed to build linker: {}", e))
|
|
51
86
|
})?;
|
|
52
87
|
let mut store = if env_vars.is_empty() {
|
|
53
88
|
build_store(&engine, None)
|
|
@@ -57,12 +92,9 @@ impl MutRApp {
|
|
|
57
92
|
|
|
58
93
|
let app = app(component_path.clone(), engine, &mut store, linker).map_err(|e| {
|
|
59
94
|
if e.to_string().contains("Incompatible WASM file version") {
|
|
60
|
-
|
|
95
|
+
runtime_error(e.to_string())
|
|
61
96
|
} else {
|
|
62
|
-
|
|
63
|
-
magnus::exception::runtime_error(),
|
|
64
|
-
format!("Failed to initialize app: {}", e),
|
|
65
|
-
)
|
|
97
|
+
runtime_error(format!("Failed to initialize app: {}", e))
|
|
66
98
|
}
|
|
67
99
|
})?;
|
|
68
100
|
|
|
@@ -85,10 +117,7 @@ impl MutRApp {
|
|
|
85
117
|
if let Some(wit_err) = err.downcast_ref::<AppError>() {
|
|
86
118
|
Err(wit_err.clone().into())
|
|
87
119
|
} else {
|
|
88
|
-
Err(
|
|
89
|
-
magnus::exception::runtime_error(),
|
|
90
|
-
format!("Unexpected error: {:?}", err),
|
|
91
|
-
))
|
|
120
|
+
Err(runtime_error(format!("Unexpected error: {:?}", err)))
|
|
92
121
|
}
|
|
93
122
|
}
|
|
94
123
|
}
|
|
@@ -101,6 +130,83 @@ impl MutRApp {
|
|
|
101
130
|
}
|
|
102
131
|
}
|
|
103
132
|
|
|
133
|
+
fn read_v6_schema(
|
|
134
|
+
&self,
|
|
135
|
+
read: impl FnOnce(
|
|
136
|
+
&v6::Bridge,
|
|
137
|
+
&mut Store<AppState>,
|
|
138
|
+
) -> wasmtime::Result<
|
|
139
|
+
Result<SchemaResponse, v6::standout::app::types::AppError>,
|
|
140
|
+
>,
|
|
141
|
+
) -> Result<(String, Option<String>), Error> {
|
|
142
|
+
let binding = self.0.borrow();
|
|
143
|
+
let instance = binding.instance.borrow();
|
|
144
|
+
let mut store = binding.store.borrow_mut();
|
|
145
|
+
let (Some(BridgeWrapper::V6(app)), Some(store)) = (instance.as_ref(), store.as_mut())
|
|
146
|
+
else {
|
|
147
|
+
return Err(runtime_error("Expected a WIT v6 component"));
|
|
148
|
+
};
|
|
149
|
+
let response = read(app, store)
|
|
150
|
+
.map_err(|err| runtime_error(err.to_string()))?
|
|
151
|
+
.map_err(AppError::from)?;
|
|
152
|
+
Ok(match response {
|
|
153
|
+
SchemaResponse::Complete(json) => ("complete".into(), Some(json)),
|
|
154
|
+
SchemaResponse::Partial(json) => ("partial".into(), Some(json)),
|
|
155
|
+
SchemaResponse::ConnectionRequired => ("connection_required".into(), None),
|
|
156
|
+
})
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
pub fn action_schema_result(
|
|
160
|
+
&self,
|
|
161
|
+
output: bool,
|
|
162
|
+
action_id: String,
|
|
163
|
+
connection: Option<RConnection>,
|
|
164
|
+
serialized_input: String,
|
|
165
|
+
reference: Option<Value>,
|
|
166
|
+
) -> Result<(String, Option<String>), Error> {
|
|
167
|
+
let reference = reference
|
|
168
|
+
.map(RActionContext::parse_reference_object)
|
|
169
|
+
.transpose()?;
|
|
170
|
+
let ctx = ActionSchemaContext {
|
|
171
|
+
action_id,
|
|
172
|
+
connection: connection.map(|c| (&c.inner).into()),
|
|
173
|
+
serialized_input,
|
|
174
|
+
reference_object: reference.as_ref().map(Into::into),
|
|
175
|
+
};
|
|
176
|
+
self.read_v6_schema(|app, store| {
|
|
177
|
+
let actions = app.standout_app_actions();
|
|
178
|
+
if output {
|
|
179
|
+
actions.call_output_schema(store, &ctx)
|
|
180
|
+
} else {
|
|
181
|
+
actions.call_input_schema(store, &ctx)
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
pub fn trigger_schema_result(
|
|
187
|
+
&self,
|
|
188
|
+
output: bool,
|
|
189
|
+
trigger_id: String,
|
|
190
|
+
connection: Option<RConnection>,
|
|
191
|
+
serialized_input: String,
|
|
192
|
+
store: String,
|
|
193
|
+
) -> Result<(String, Option<String>), Error> {
|
|
194
|
+
let ctx = TriggerSchemaContext {
|
|
195
|
+
trigger_id,
|
|
196
|
+
connection: connection.map(|c| (&c.inner).into()),
|
|
197
|
+
serialized_input,
|
|
198
|
+
store,
|
|
199
|
+
};
|
|
200
|
+
self.read_v6_schema(|app, store| {
|
|
201
|
+
let triggers = app.standout_app_triggers();
|
|
202
|
+
if output {
|
|
203
|
+
triggers.call_output_schema(store, &ctx)
|
|
204
|
+
} else {
|
|
205
|
+
triggers.call_input_schema(store, &ctx)
|
|
206
|
+
}
|
|
207
|
+
})
|
|
208
|
+
}
|
|
209
|
+
|
|
104
210
|
pub fn trigger_input_schema(&self, context: RTriggerContext) -> Result<String, Error> {
|
|
105
211
|
let binding = self.0.borrow();
|
|
106
212
|
let mut instance = binding.instance.borrow_mut();
|
|
@@ -114,10 +220,7 @@ impl MutRApp {
|
|
|
114
220
|
if let Some(wit_err) = err.downcast_ref::<AppError>() {
|
|
115
221
|
Err(wit_err.clone().into())
|
|
116
222
|
} else {
|
|
117
|
-
Err(
|
|
118
|
-
magnus::exception::runtime_error(),
|
|
119
|
-
format!("Unexpected error: {:?}", err),
|
|
120
|
-
))
|
|
223
|
+
Err(runtime_error(format!("Unexpected error: {:?}", err)))
|
|
121
224
|
}
|
|
122
225
|
}
|
|
123
226
|
}
|
|
@@ -143,10 +246,7 @@ impl MutRApp {
|
|
|
143
246
|
if let Some(wit_err) = err.downcast_ref::<AppError>() {
|
|
144
247
|
Err(wit_err.clone().into())
|
|
145
248
|
} else {
|
|
146
|
-
Err(
|
|
147
|
-
magnus::exception::runtime_error(),
|
|
148
|
-
format!("Unexpected error: {:?}", err),
|
|
149
|
-
))
|
|
249
|
+
Err(runtime_error(format!("Unexpected error: {:?}", err)))
|
|
150
250
|
}
|
|
151
251
|
}
|
|
152
252
|
}
|
|
@@ -208,10 +308,7 @@ impl MutRApp {
|
|
|
208
308
|
if let Some(wit_err) = err.downcast_ref::<AppError>() {
|
|
209
309
|
Err(wit_err.clone().into())
|
|
210
310
|
} else {
|
|
211
|
-
Err(
|
|
212
|
-
magnus::exception::runtime_error(),
|
|
213
|
-
format!("Unexpected error: {:?}", err),
|
|
214
|
-
))
|
|
311
|
+
Err(runtime_error(format!("Unexpected error: {:?}", err)))
|
|
215
312
|
}
|
|
216
313
|
}
|
|
217
314
|
}
|
|
@@ -237,10 +334,7 @@ impl MutRApp {
|
|
|
237
334
|
if let Some(wit_err) = err.downcast_ref::<AppError>() {
|
|
238
335
|
Err(wit_err.clone().into())
|
|
239
336
|
} else {
|
|
240
|
-
Err(
|
|
241
|
-
magnus::exception::runtime_error(),
|
|
242
|
-
format!("Unexpected error: {:?}", err),
|
|
243
|
-
))
|
|
337
|
+
Err(runtime_error(format!("Unexpected error: {:?}", err)))
|
|
244
338
|
}
|
|
245
339
|
}
|
|
246
340
|
}
|
|
@@ -266,10 +360,7 @@ impl MutRApp {
|
|
|
266
360
|
if let Some(wit_err) = err.downcast_ref::<AppError>() {
|
|
267
361
|
Err(wit_err.clone().into())
|
|
268
362
|
} else {
|
|
269
|
-
Err(
|
|
270
|
-
magnus::exception::runtime_error(),
|
|
271
|
-
format!("Unexpected error: {:?}", err),
|
|
272
|
-
))
|
|
363
|
+
Err(runtime_error(format!("Unexpected error: {:?}", err)))
|
|
273
364
|
}
|
|
274
365
|
}
|
|
275
366
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
use magnus::{prelude::*, Error, TryConvert, Value};
|
|
2
|
+
use crate::error_mapping::runtime_error;
|
|
2
3
|
use crate::types::TriggerContext;
|
|
3
4
|
use super::connection::RConnection;
|
|
4
5
|
|
|
@@ -11,12 +12,12 @@ pub struct RTriggerContext {
|
|
|
11
12
|
impl RTriggerContext {
|
|
12
13
|
pub fn new(trigger_id: String, connection: Value, store: String, serialized_input: String) -> Result<Self, Error> {
|
|
13
14
|
if connection.is_nil() {
|
|
14
|
-
return Err(
|
|
15
|
+
return Err(runtime_error("Connection is required"));
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
let wrapped_connection: RConnection = match TryConvert::try_convert(connection) {
|
|
18
19
|
Ok(conn) => conn,
|
|
19
|
-
Err(_) => return Err(
|
|
20
|
+
Err(_) => return Err(runtime_error("Connection is required")),
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
let inner = TriggerContext {
|
|
@@ -56,12 +57,12 @@ impl TryConvert for RTriggerContext {
|
|
|
56
57
|
let serialized_input: String = val.funcall("serialized_input", ())?;
|
|
57
58
|
|
|
58
59
|
if connection_val.is_nil() {
|
|
59
|
-
return Err(
|
|
60
|
+
return Err(runtime_error("Connection is required"));
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
let wrapped_connection: RConnection = match TryConvert::try_convert(connection_val) {
|
|
63
64
|
Ok(conn) => conn,
|
|
64
|
-
Err(_) => return Err(
|
|
65
|
+
Err(_) => return Err(runtime_error("Connection is required")),
|
|
65
66
|
};
|
|
66
67
|
|
|
67
68
|
let inner = TriggerContext {
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
package standout:app@5.0.0;
|
|
2
|
+
|
|
3
|
+
interface types {
|
|
4
|
+
// The trigger-store is a string that is used to store data between trigger
|
|
5
|
+
// invocations. It is unique per trigger instance and is persisted between
|
|
6
|
+
// invocations.
|
|
7
|
+
//
|
|
8
|
+
// You can store any string here. We suggest that you use a serialized
|
|
9
|
+
// JSON object or similar since that will give you some flexibility if you
|
|
10
|
+
// need to add more data to the store.
|
|
11
|
+
type trigger-store = string;
|
|
12
|
+
|
|
13
|
+
record connection {
|
|
14
|
+
id: string,
|
|
15
|
+
name: string,
|
|
16
|
+
// The connection data is a JSON object serialized into a string. The JSON root
|
|
17
|
+
// will always be an object.
|
|
18
|
+
serialized-data: string,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
record trigger-context {
|
|
22
|
+
// Trigger ID is a unique identifier for the trigger that is requested to be
|
|
23
|
+
// invoked.
|
|
24
|
+
trigger-id: string,
|
|
25
|
+
|
|
26
|
+
// The connection that the trigger is invoked for.
|
|
27
|
+
// Connection is required for all trigger operations.
|
|
28
|
+
connection: connection,
|
|
29
|
+
|
|
30
|
+
// The store will contain the data that was stored in the trigger store the
|
|
31
|
+
// last time the trigger was invoked.
|
|
32
|
+
store: trigger-store,
|
|
33
|
+
|
|
34
|
+
// The input data for the trigger, serialized as a JSON object string.
|
|
35
|
+
// This contains the input data from the trigger configuration form.
|
|
36
|
+
serialized-input: string,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
record action-context {
|
|
40
|
+
// Action ID is a unique identifier for the action that is requested to be
|
|
41
|
+
// invoked.
|
|
42
|
+
action-id: string,
|
|
43
|
+
|
|
44
|
+
// The connection that the action is invoked for.
|
|
45
|
+
// Connection is required for all action operations.
|
|
46
|
+
connection: connection,
|
|
47
|
+
|
|
48
|
+
// The input data for the action, serialized as a JSON object string.
|
|
49
|
+
// This contains the data passed from the previous step in the workflow.
|
|
50
|
+
serialized-input: string,
|
|
51
|
+
|
|
52
|
+
// Optional reference information when the platform retries an action.
|
|
53
|
+
reference-object: option<reference-object>,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
record trigger-response {
|
|
57
|
+
// The trigger events, each event will be used to spawn a new workflow
|
|
58
|
+
// execution in Standouts integration platform.
|
|
59
|
+
events: list<trigger-event>,
|
|
60
|
+
|
|
61
|
+
// The updated store will be stored and used the next time the trigger is
|
|
62
|
+
// invoked.
|
|
63
|
+
store: trigger-store,
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
record action-response {
|
|
67
|
+
// The output data from the action, serialized as a JSON object string.
|
|
68
|
+
// This contains the data that will be passed to the next step in the workflow.
|
|
69
|
+
// The data must be a valid JSON object (not an array or primitive).
|
|
70
|
+
serialized-output: string
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
record trigger-event {
|
|
74
|
+
// The ID of the trigger event
|
|
75
|
+
//
|
|
76
|
+
// If the connection used for the given instance of the trigger is the same,
|
|
77
|
+
// as seen before. Then the event will be ignored.
|
|
78
|
+
//
|
|
79
|
+
// A scheduler could therefore use a timestamp as the ID, to ensure that
|
|
80
|
+
// the event is only triggered once per given time.
|
|
81
|
+
//
|
|
82
|
+
// A trigger that acts on created orders in a e-commerce system could use
|
|
83
|
+
// the order ID as the ID, to ensure that the event is only triggered once
|
|
84
|
+
// per order.
|
|
85
|
+
//
|
|
86
|
+
// A trigger that acts on updated orders in a e-commerce system could use
|
|
87
|
+
// the order ID in combination with an updated at timestamp as the ID, to
|
|
88
|
+
// ensure that the event is only triggered once per order update.
|
|
89
|
+
id: string,
|
|
90
|
+
|
|
91
|
+
// Serialized data must be a JSON object serialized into a string
|
|
92
|
+
// Note that it is important that the root is an object, not an array,
|
|
93
|
+
// or another primitive type.
|
|
94
|
+
serialized-data: string,
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/// Retry reference payload returned with error-code.retry-with-reference.
|
|
98
|
+
record reference-object {
|
|
99
|
+
/// Reference ID provided for retrying this request later.
|
|
100
|
+
reference: string,
|
|
101
|
+
|
|
102
|
+
/// Status describing the retry state.
|
|
103
|
+
status: string,
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
record app-error {
|
|
107
|
+
/// The error code identifying the type of failure.
|
|
108
|
+
code: error-code,
|
|
109
|
+
|
|
110
|
+
/// A human-readable message describing the error in more detail.
|
|
111
|
+
message: string,
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/// An enumeration of error codes that can be returned by a trigger implementation.
|
|
115
|
+
/// These codes help the platform and plugin developers distinguish between different types of failures.
|
|
116
|
+
variant error-code {
|
|
117
|
+
/// Authentication failed. Typically due to an invalid or expired API key or token.
|
|
118
|
+
unauthenticated,
|
|
119
|
+
|
|
120
|
+
/// Authorization failed. The connection is valid but does not have the necessary permissions.
|
|
121
|
+
forbidden,
|
|
122
|
+
|
|
123
|
+
/// The trigger is misconfigured. For example, a required setting is missing or invalid.
|
|
124
|
+
misconfigured,
|
|
125
|
+
|
|
126
|
+
/// The target system does not support a required feature or endpoint.
|
|
127
|
+
unsupported,
|
|
128
|
+
|
|
129
|
+
/// The target system is rate-limiting requests. Try again later.
|
|
130
|
+
rate-limit,
|
|
131
|
+
|
|
132
|
+
/// The request timed out. The target system did not respond in time.
|
|
133
|
+
timeout,
|
|
134
|
+
|
|
135
|
+
/// The target system is currently unavailable or unreachable.
|
|
136
|
+
unavailable,
|
|
137
|
+
|
|
138
|
+
/// An unexpected internal error occurred in the plugin.
|
|
139
|
+
internal-error,
|
|
140
|
+
|
|
141
|
+
/// The response from the external system could not be parsed or was in an invalid format.
|
|
142
|
+
malformed-response,
|
|
143
|
+
|
|
144
|
+
/// A catch-all for all other types of errors. Should include a descriptive message.
|
|
145
|
+
other,
|
|
146
|
+
|
|
147
|
+
/// Retry the request using a reference identifier.
|
|
148
|
+
retry-with-reference(reference-object),
|
|
149
|
+
|
|
150
|
+
/// Complete the current workflow execution.
|
|
151
|
+
complete-workflow,
|
|
152
|
+
|
|
153
|
+
/// Complete the parent step execution.
|
|
154
|
+
complete-parent,
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
interface triggers {
|
|
160
|
+
use types.{trigger-context, trigger-event, trigger-response, app-error};
|
|
161
|
+
|
|
162
|
+
trigger-ids: func() -> result<list<string>, app-error>;
|
|
163
|
+
|
|
164
|
+
// Get the input schema for a specific trigger
|
|
165
|
+
// Returns a JSON Schema Draft 2020-12 schema as a string
|
|
166
|
+
// The schema may vary based on the connection in the context
|
|
167
|
+
// The trigger-id is extracted from the context
|
|
168
|
+
input-schema: func(context: trigger-context) -> result<string, app-error>;
|
|
169
|
+
|
|
170
|
+
// Get the output schema for a specific trigger
|
|
171
|
+
// Returns a JSON Schema Draft 2020-12 schema as a string
|
|
172
|
+
// The schema may vary based on the connection in the context
|
|
173
|
+
// The trigger-id is extracted from the context
|
|
174
|
+
output-schema: func(context: trigger-context) -> result<string, app-error>;
|
|
175
|
+
|
|
176
|
+
// Fetch events
|
|
177
|
+
//
|
|
178
|
+
// There are some limitations to the function:
|
|
179
|
+
// - It must return a `trigger-response` within 30 seconds
|
|
180
|
+
// - It must return less than or equal to 100 `trigger-response.events`
|
|
181
|
+
// - It must not return more than 64 kB of data in the `trigger-response.store`
|
|
182
|
+
//
|
|
183
|
+
// If you need to fetch more events, you can return up to 100 events and then
|
|
184
|
+
// store the data needed for you to remember where you left off in the store.
|
|
185
|
+
// The next time the trigger is invoked, you can use the store to continue
|
|
186
|
+
// where you left off.
|
|
187
|
+
//
|
|
188
|
+
// If you do not pass the limitations the return value will be ignored. We
|
|
189
|
+
// will not handle any events and we persist the store that was returned in
|
|
190
|
+
// the response.
|
|
191
|
+
//
|
|
192
|
+
// That also means that you should implement your fetch event function in a
|
|
193
|
+
// way that it can be called multiple times using the same context and return
|
|
194
|
+
// the same events. That will ensure that the user that is building an
|
|
195
|
+
// integration with your trigger will not miss any events if your system is
|
|
196
|
+
// down for a short period of time.
|
|
197
|
+
fetch-events: func(context: trigger-context) -> result<trigger-response, app-error>;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
interface actions {
|
|
201
|
+
use types.{action-context, action-response, app-error};
|
|
202
|
+
|
|
203
|
+
action-ids: func() -> result<list<string>, app-error>;
|
|
204
|
+
|
|
205
|
+
// Get the input schema for a specific action
|
|
206
|
+
// Returns a JSON Schema Draft 2020-12 schema as a string
|
|
207
|
+
// The schema may vary based on the connection in the context
|
|
208
|
+
// The action-id is extracted from the context
|
|
209
|
+
input-schema: func(context: action-context) -> result<string, app-error>;
|
|
210
|
+
|
|
211
|
+
// Get the output schema for a specific action
|
|
212
|
+
// Returns a JSON Schema Draft 2020-12 schema as a string
|
|
213
|
+
// The schema may vary based on the connection in the context
|
|
214
|
+
// The action-id is extracted from the context
|
|
215
|
+
output-schema: func(context: action-context) -> result<string, app-error>;
|
|
216
|
+
|
|
217
|
+
// Execute an action
|
|
218
|
+
//
|
|
219
|
+
// There are some limitations to the function:
|
|
220
|
+
// - It must return an `action-response` within 30 seconds
|
|
221
|
+
// - The serialized-output must be a valid JSON object serialized as a string
|
|
222
|
+
//
|
|
223
|
+
// Actions can perform various operations such as:
|
|
224
|
+
// - Making HTTP requests to external APIs
|
|
225
|
+
// - Processing and transforming data
|
|
226
|
+
// - Storing data for future use
|
|
227
|
+
// - Triggering other systems or workflows
|
|
228
|
+
//
|
|
229
|
+
// The action receives input data from the previous step and can return
|
|
230
|
+
// serialized output data to be passed to the next step in the workflow.
|
|
231
|
+
execute: func(context: action-context) -> result<action-response, app-error>;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
interface environment {
|
|
235
|
+
// Get all environment variables
|
|
236
|
+
env-vars: func() -> list<tuple<string, string>>;
|
|
237
|
+
// Get a specific environment variable by name
|
|
238
|
+
env-var: func(name: string) -> option<string>;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
interface http {
|
|
242
|
+
record response {
|
|
243
|
+
status: u16,
|
|
244
|
+
headers: headers,
|
|
245
|
+
body: string,
|
|
246
|
+
/// Raw response payload for binary responses.
|
|
247
|
+
body-bytes: option<list<u8>>,
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
record request {
|
|
251
|
+
method: method,
|
|
252
|
+
url: string,
|
|
253
|
+
headers: headers,
|
|
254
|
+
body: string,
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
variant request-error {
|
|
258
|
+
other(string)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
type headers = list<tuple<string, string>>;
|
|
262
|
+
|
|
263
|
+
resource request-builder {
|
|
264
|
+
constructor();
|
|
265
|
+
|
|
266
|
+
method: func(method: method) -> request-builder;
|
|
267
|
+
url: func(url: string) -> request-builder;
|
|
268
|
+
|
|
269
|
+
// Add a header to the request
|
|
270
|
+
header: func(key: string, value: string) -> request-builder;
|
|
271
|
+
headers: func(headers: list<tuple<string, string>>) -> request-builder;
|
|
272
|
+
|
|
273
|
+
// Add a body to the request
|
|
274
|
+
body: func(body: string) -> request-builder;
|
|
275
|
+
// Add a binary body to the request
|
|
276
|
+
body-bytes: func(body: list<u8>) -> request-builder;
|
|
277
|
+
|
|
278
|
+
object: func() -> request;
|
|
279
|
+
|
|
280
|
+
// Send the request
|
|
281
|
+
send: func() -> result<response, request-error>;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
variant method {
|
|
285
|
+
get,
|
|
286
|
+
post,
|
|
287
|
+
put,
|
|
288
|
+
delete,
|
|
289
|
+
patch,
|
|
290
|
+
options,
|
|
291
|
+
head,
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
interface file {
|
|
296
|
+
// HTTP headers for file requests (same as http interface)
|
|
297
|
+
type headers = list<tuple<string, string>>;
|
|
298
|
+
|
|
299
|
+
// Normalized file data
|
|
300
|
+
record file-data {
|
|
301
|
+
// Base64-encoded file content
|
|
302
|
+
base64: string,
|
|
303
|
+
// MIME type (e.g., "application/pdf")
|
|
304
|
+
content-type: string,
|
|
305
|
+
// Filename
|
|
306
|
+
filename: string,
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
variant file-error {
|
|
310
|
+
// Failed to fetch file from URL
|
|
311
|
+
fetch-failed(string),
|
|
312
|
+
// Invalid input format (not a valid URL, data URI, or base64)
|
|
313
|
+
invalid-input(string),
|
|
314
|
+
// Request timed out
|
|
315
|
+
timeout(string),
|
|
316
|
+
// Any other error
|
|
317
|
+
other(string),
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// Normalize any file source to FileData
|
|
321
|
+
//
|
|
322
|
+
// The source is automatically detected:
|
|
323
|
+
// - URL: "https://example.com/file.pdf" - fetched with optional headers
|
|
324
|
+
// - Data URI: "data:application/pdf;base64,JVBERi0..." - parsed and extracted
|
|
325
|
+
// - Base64: Any other string is treated as raw base64 - decoded to detect type
|
|
326
|
+
//
|
|
327
|
+
// Parameters:
|
|
328
|
+
// - source: URL, data URI, or base64-encoded content
|
|
329
|
+
// - headers: Optional HTTP headers for URL requests (e.g., Authorization)
|
|
330
|
+
// - filename: Optional filename override (auto-detected if not provided)
|
|
331
|
+
//
|
|
332
|
+
// Returns file-data which will be processed by the platform:
|
|
333
|
+
// 1. Fields with format: "file-output" in the output schema are identified
|
|
334
|
+
// 2. File data is uploaded using the configured file_uploader
|
|
335
|
+
// 3. The file-data is replaced with the blob ID in the response
|
|
336
|
+
normalize: func(source: string, headers: option<headers>, filename: option<string>) -> result<file-data, file-error>;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Connection configuration for app-defined connectors.
|
|
340
|
+
//
|
|
341
|
+
// The connector is stateless. It declares how users connect and what runtime
|
|
342
|
+
// data actions/triggers receive. The platform stores credentials and handles
|
|
343
|
+
// OAuth flows, token refresh, and building serialized-data for execution.
|
|
344
|
+
//
|
|
345
|
+
// connection-config returns a JSON string.
|
|
346
|
+
// It is not validated in WASM. app_bridge validates exported JSON against
|
|
347
|
+
// connection-config-schema.json (see ext/app_bridge/docs/) using AppBridge::ConnectionConfigValidator.
|
|
348
|
+
// Connector authors can run the same validator on JSON in CI without loading WASM.
|
|
349
|
+
// integrationer persists connection_config_data,
|
|
350
|
+
// and reads stored JSON at runtime — not a live WASM call.
|
|
351
|
+
interface connections {
|
|
352
|
+
// Returns the embedded connection-config JSON document as a string.
|
|
353
|
+
connection-config: func() -> string;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
world bridge {
|
|
357
|
+
import http;
|
|
358
|
+
import environment;
|
|
359
|
+
import file;
|
|
360
|
+
export triggers;
|
|
361
|
+
export actions;
|
|
362
|
+
export connections;
|
|
363
|
+
}
|