app_bridge 3.0.0 → 4.1.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/.rubocop.yml +1 -0
- data/.tool-versions +1 -1
- data/Cargo.lock +292 -751
- data/Cargo.toml +1 -1
- data/README.md +274 -2
- data/ext/app_bridge/Cargo.toml +8 -4
- data/ext/app_bridge/src/app_state.rs +32 -13
- data/ext/app_bridge/src/component.rs +346 -45
- data/ext/app_bridge/src/error_mapping.rs +40 -24
- data/ext/app_bridge/src/file_ops.rs +326 -0
- data/ext/app_bridge/src/lib.rs +21 -3
- data/ext/app_bridge/src/request_builder.rs +343 -152
- data/ext/app_bridge/src/types.rs +95 -0
- data/ext/app_bridge/src/wrappers/action_context.rs +70 -9
- data/ext/app_bridge/src/wrappers/action_response.rs +7 -3
- data/ext/app_bridge/src/wrappers/app.rs +112 -148
- data/ext/app_bridge/src/wrappers/connection.rs +4 -4
- data/ext/app_bridge/src/wrappers/trigger_context.rs +7 -7
- data/ext/app_bridge/src/wrappers/trigger_event.rs +4 -4
- data/ext/app_bridge/src/wrappers/trigger_response.rs +29 -28
- data/ext/app_bridge/wit/{world.wit → v3/world.wit} +3 -0
- data/ext/app_bridge/wit/v4/world.wit +328 -0
- data/ext/app_bridge/wit/v4_1/world.wit +343 -0
- data/lib/app_bridge/app.rb +21 -2
- data/lib/app_bridge/file_processor.rb +131 -0
- data/lib/app_bridge/version.rb +1 -1
- data/lib/app_bridge.rb +25 -0
- data/tasks/fixtures.rake +16 -2
- metadata +9 -4
|
@@ -1,42 +1,43 @@
|
|
|
1
|
-
use magnus::{Error,
|
|
2
|
-
use crate::
|
|
1
|
+
use magnus::{Error, Ruby, TryConvert};
|
|
2
|
+
use crate::types::TriggerResponse;
|
|
3
3
|
use super::trigger_event::RTriggerEvent;
|
|
4
4
|
|
|
5
5
|
#[magnus::wrap(class = "AppBridge::TriggerResponse")]
|
|
6
6
|
pub struct RTriggerResponse {
|
|
7
|
-
|
|
7
|
+
inner: TriggerResponse,
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
impl RTriggerResponse {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
pub fn new(store: String, events: magnus::RArray) -> Self {
|
|
12
|
+
let iter = events.into_iter();
|
|
13
|
+
let res: Vec<RTriggerEvent> = iter
|
|
14
|
+
.map(&TryConvert::try_convert)
|
|
15
|
+
.collect::<Result<Vec<RTriggerEvent>, Error>>()
|
|
16
|
+
.unwrap();
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
let inner = TriggerResponse {
|
|
19
|
+
store,
|
|
20
|
+
events: res.iter().map(|e| e.into()).collect(),
|
|
21
|
+
};
|
|
22
|
+
Self { inner }
|
|
23
|
+
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
pub fn store(&self) -> String {
|
|
26
|
+
self.inner.store.clone()
|
|
27
|
+
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
pub fn events(&self) -> magnus::RArray {
|
|
30
|
+
let ruby = Ruby::get().unwrap();
|
|
31
|
+
let array = ruby.ary_new();
|
|
32
|
+
for e in &self.inner.events {
|
|
33
|
+
let _ = array.push(RTriggerEvent::from(e));
|
|
34
|
+
}
|
|
35
|
+
array
|
|
36
|
+
}
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
impl From<TriggerResponse> for RTriggerResponse {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
fn from(value: TriggerResponse) -> Self {
|
|
41
|
+
Self { inner: value }
|
|
42
|
+
}
|
|
42
43
|
}
|
|
@@ -275,9 +275,12 @@ interface http {
|
|
|
275
275
|
}
|
|
276
276
|
}
|
|
277
277
|
|
|
278
|
+
// Note: v3 does NOT include the file interface
|
|
279
|
+
|
|
278
280
|
world bridge {
|
|
279
281
|
import http;
|
|
280
282
|
import environment;
|
|
283
|
+
// Note: file interface is NOT available in v3
|
|
281
284
|
export triggers;
|
|
282
285
|
export actions;
|
|
283
286
|
}
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
package standout:app@4.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
|
+
|
|
53
|
+
record trigger-response {
|
|
54
|
+
// The trigger events, each event will be used to spawn a new workflow
|
|
55
|
+
// execution in Standouts integration plattform.
|
|
56
|
+
events: list<trigger-event>,
|
|
57
|
+
|
|
58
|
+
// The updated store will be stored and used the next time the trigger is
|
|
59
|
+
// invoked.
|
|
60
|
+
store: trigger-store,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
record action-response {
|
|
64
|
+
// The output data from the action, serialized as a JSON object string.
|
|
65
|
+
// This contains the data that will be passed to the next step in the workflow.
|
|
66
|
+
// The data must be a valid JSON object (not an array or primitive).
|
|
67
|
+
serialized-output: string
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
record trigger-event {
|
|
71
|
+
// The ID of the trigger event
|
|
72
|
+
//
|
|
73
|
+
// If the connection used for the given instance of the trigger is the same,
|
|
74
|
+
// as seen before. Then the event will be ignored.
|
|
75
|
+
//
|
|
76
|
+
// A scheduler could therefore use an timestamp as the ID, to ensure that
|
|
77
|
+
// the event is only triggered once per given time.
|
|
78
|
+
//
|
|
79
|
+
// A trigger that acts on created orders in a e-commerce system could use
|
|
80
|
+
// the order ID as the ID, to ensure that the event is only triggered once
|
|
81
|
+
// per order.
|
|
82
|
+
//
|
|
83
|
+
// A trigger that acts on updated orders in a e-commerce system could use
|
|
84
|
+
// the order ID in combination with an updated at timestamp as the ID, to
|
|
85
|
+
// ensure that the event is only triggered once per order update.
|
|
86
|
+
id: string,
|
|
87
|
+
|
|
88
|
+
// Serialized data must be a JSON object serialized into a string
|
|
89
|
+
// Note that it is important that the root is a object, not an array,
|
|
90
|
+
// or another primitive type.
|
|
91
|
+
serialized-data: string,
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/// A structured error that can be returned by for example a call to a trigger or action.
|
|
95
|
+
/// Contains a machine-readable code and a human-readable message.
|
|
96
|
+
record app-error {
|
|
97
|
+
/// The error code identifying the type of failure.
|
|
98
|
+
code: error-code,
|
|
99
|
+
|
|
100
|
+
/// A human-readable message describing the error in more detail.
|
|
101
|
+
message: string,
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/// An enumeration of error codes that can be returned by a trigger implementation.
|
|
105
|
+
/// These codes help the platform and plugin developers distinguish between different types of failures.
|
|
106
|
+
variant error-code {
|
|
107
|
+
/// Authentication failed. Typically due to an invalid or expired API key or token.
|
|
108
|
+
unauthenticated,
|
|
109
|
+
|
|
110
|
+
/// Authorization failed. The connection is valid but does not have the necessary permissions.
|
|
111
|
+
forbidden,
|
|
112
|
+
|
|
113
|
+
/// The trigger is misconfigured. For example, a required setting is missing or invalid.
|
|
114
|
+
misconfigured,
|
|
115
|
+
|
|
116
|
+
/// The target system does not support a required feature or endpoint.
|
|
117
|
+
unsupported,
|
|
118
|
+
|
|
119
|
+
/// The target system is rate-limiting requests. Try again later.
|
|
120
|
+
rate-limit,
|
|
121
|
+
|
|
122
|
+
/// The request timed out. The target system did not respond in time.
|
|
123
|
+
timeout,
|
|
124
|
+
|
|
125
|
+
/// The target system is currently unavailable or unreachable.
|
|
126
|
+
unavailable,
|
|
127
|
+
|
|
128
|
+
/// An unexpected internal error occurred in the plugin.
|
|
129
|
+
internal-error,
|
|
130
|
+
|
|
131
|
+
/// The response from the external system could not be parsed or was in an invalid format.
|
|
132
|
+
malformed-response,
|
|
133
|
+
|
|
134
|
+
/// A catch-all for all other types of errors. Should include a descriptive message.
|
|
135
|
+
other,
|
|
136
|
+
|
|
137
|
+
/// Complete the current workflow execution.
|
|
138
|
+
complete-workflow,
|
|
139
|
+
|
|
140
|
+
/// Complete the parent step execution.
|
|
141
|
+
complete-parent,
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
interface triggers {
|
|
147
|
+
use types.{trigger-context, trigger-event, trigger-response, app-error};
|
|
148
|
+
|
|
149
|
+
trigger-ids: func() -> result<list<string>, app-error>;
|
|
150
|
+
|
|
151
|
+
// Get the input schema for a specific trigger
|
|
152
|
+
// Returns a JSON Schema Draft 2020-12 schema as a string
|
|
153
|
+
// The schema may vary based on the connection in the context
|
|
154
|
+
// The trigger-id is extracted from the context
|
|
155
|
+
input-schema: func(context: trigger-context) -> result<string, app-error>;
|
|
156
|
+
|
|
157
|
+
// Get the output schema for a specific trigger
|
|
158
|
+
// Returns a JSON Schema Draft 2020-12 schema as a string
|
|
159
|
+
// The schema may vary based on the connection in the context
|
|
160
|
+
// The trigger-id is extracted from the context
|
|
161
|
+
output-schema: func(context: trigger-context) -> result<string, app-error>;
|
|
162
|
+
|
|
163
|
+
// Fetch events
|
|
164
|
+
//
|
|
165
|
+
// There are some limitations to the function:
|
|
166
|
+
// - It must a `trigger-response` within 30 seconds
|
|
167
|
+
// - It must return less than or equal to 100 `trigger-response.events`
|
|
168
|
+
// - It must not return more than 64 kB of data in the `trigger-response.store`
|
|
169
|
+
//
|
|
170
|
+
// If you need to fetch more events, you can return up to 100 events and then
|
|
171
|
+
// store the data needed for you to remember where you left off in the store.
|
|
172
|
+
// The next time the trigger is invoked, you can use the store to continue
|
|
173
|
+
// where you left off.
|
|
174
|
+
//
|
|
175
|
+
// If you do not pass the limitations the return value will be ignored. We
|
|
176
|
+
// will not handle any events and we persist the store that was returned in
|
|
177
|
+
// the response.
|
|
178
|
+
//
|
|
179
|
+
// That also means that you should implement your fetch event function in a
|
|
180
|
+
// way that it can be called multiple times using the same context and return
|
|
181
|
+
// the same events. That will ensure that the user that is building an
|
|
182
|
+
// integration with your trigger will not miss any events if your system is
|
|
183
|
+
// down for a short period of time.
|
|
184
|
+
fetch-events: func(context: trigger-context) -> result<trigger-response, app-error>;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
interface actions {
|
|
188
|
+
use types.{action-context, action-response, app-error};
|
|
189
|
+
|
|
190
|
+
action-ids: func() -> result<list<string>, app-error>;
|
|
191
|
+
|
|
192
|
+
// Get the input schema for a specific action
|
|
193
|
+
// Returns a JSON Schema Draft 2020-12 schema as a string
|
|
194
|
+
// The schema may vary based on the connection in the context
|
|
195
|
+
// The action-id is extracted from the context
|
|
196
|
+
input-schema: func(context: action-context) -> result<string, app-error>;
|
|
197
|
+
|
|
198
|
+
// Get the output schema for a specific action
|
|
199
|
+
// Returns a JSON Schema Draft 2020-12 schema as a string
|
|
200
|
+
// The schema may vary based on the connection in the context
|
|
201
|
+
// The action-id is extracted from the context
|
|
202
|
+
output-schema: func(context: action-context) -> result<string, app-error>;
|
|
203
|
+
|
|
204
|
+
// Execute an action
|
|
205
|
+
//
|
|
206
|
+
// There are some limitations to the function:
|
|
207
|
+
// - It must return an `action-response` within 30 seconds
|
|
208
|
+
// - The serialized-output must be a valid JSON object serialized as a string
|
|
209
|
+
//
|
|
210
|
+
// Actions can perform various operations such as:
|
|
211
|
+
// - Making HTTP requests to external APIs
|
|
212
|
+
// - Processing and transforming data
|
|
213
|
+
// - Storing data for future use
|
|
214
|
+
// - Triggering other systems or workflows
|
|
215
|
+
//
|
|
216
|
+
// The action receives input data from the previous step and can return
|
|
217
|
+
// serialized output data to be passed to the next step in the workflow.
|
|
218
|
+
execute: func(context: action-context) -> result<action-response, app-error>;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
interface environment {
|
|
222
|
+
// Get all environment variables
|
|
223
|
+
env-vars: func() -> list<tuple<string, string>>;
|
|
224
|
+
// Get a specific environment variable by name
|
|
225
|
+
env-var: func(name: string) -> option<string>;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
interface http {
|
|
229
|
+
record response {
|
|
230
|
+
status: u16,
|
|
231
|
+
headers: headers,
|
|
232
|
+
body: string,
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
record request {
|
|
236
|
+
method: method,
|
|
237
|
+
url: string,
|
|
238
|
+
headers: headers,
|
|
239
|
+
body: string,
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
variant request-error {
|
|
243
|
+
other(string)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
type headers = list<tuple<string, string>>;
|
|
247
|
+
|
|
248
|
+
resource request-builder {
|
|
249
|
+
constructor();
|
|
250
|
+
|
|
251
|
+
method: func(method: method) -> request-builder;
|
|
252
|
+
url: func(url: string) -> request-builder;
|
|
253
|
+
|
|
254
|
+
// Add a header to the request
|
|
255
|
+
header: func(key: string, value: string) -> request-builder;
|
|
256
|
+
headers: func(headers: list<tuple<string, string>>) -> request-builder;
|
|
257
|
+
|
|
258
|
+
// Add a body to the request
|
|
259
|
+
body: func(body: string) -> request-builder;
|
|
260
|
+
|
|
261
|
+
object: func() -> request;
|
|
262
|
+
|
|
263
|
+
// Send the request
|
|
264
|
+
send: func() -> result<response, request-error>;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
variant method {
|
|
268
|
+
get,
|
|
269
|
+
post,
|
|
270
|
+
put,
|
|
271
|
+
delete,
|
|
272
|
+
patch,
|
|
273
|
+
options,
|
|
274
|
+
head,
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
interface file {
|
|
279
|
+
// HTTP headers for file requests (same as http interface)
|
|
280
|
+
type headers = list<tuple<string, string>>;
|
|
281
|
+
|
|
282
|
+
// Normalized file data
|
|
283
|
+
record file-data {
|
|
284
|
+
// Base64-encoded file content
|
|
285
|
+
base64: string,
|
|
286
|
+
// MIME type (e.g., "application/pdf")
|
|
287
|
+
content-type: string,
|
|
288
|
+
// Filename
|
|
289
|
+
filename: string,
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
variant file-error {
|
|
293
|
+
// Failed to fetch file from URL
|
|
294
|
+
fetch-failed(string),
|
|
295
|
+
// Invalid input format (not a valid URL, data URI, or base64)
|
|
296
|
+
invalid-input(string),
|
|
297
|
+
// Request timed out
|
|
298
|
+
timeout(string),
|
|
299
|
+
// Any other error
|
|
300
|
+
other(string),
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// Normalize any file source to FileData
|
|
304
|
+
//
|
|
305
|
+
// The source is automatically detected:
|
|
306
|
+
// - URL: "https://example.com/file.pdf" - fetched with optional headers
|
|
307
|
+
// - Data URI: "data:application/pdf;base64,JVBERi0..." - parsed and extracted
|
|
308
|
+
// - Base64: Any other string is treated as raw base64 - decoded to detect type
|
|
309
|
+
//
|
|
310
|
+
// Parameters:
|
|
311
|
+
// - source: URL, data URI, or base64-encoded content
|
|
312
|
+
// - headers: Optional HTTP headers for URL requests (e.g., Authorization)
|
|
313
|
+
// - filename: Optional filename override (auto-detected if not provided)
|
|
314
|
+
//
|
|
315
|
+
// Returns file-data which will be processed by the platform:
|
|
316
|
+
// 1. Fields with format: "file-output" in the output schema are identified
|
|
317
|
+
// 2. File data is uploaded using the configured file_uploader
|
|
318
|
+
// 3. The file-data is replaced with the blob ID in the response
|
|
319
|
+
normalize: func(source: string, headers: option<headers>, filename: option<string>) -> result<file-data, file-error>;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
world bridge {
|
|
323
|
+
import http;
|
|
324
|
+
import environment;
|
|
325
|
+
import file;
|
|
326
|
+
export triggers;
|
|
327
|
+
export actions;
|
|
328
|
+
}
|