app_bridge 3.0.0 → 4.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/.rubocop.yml +1 -0
- data/.tool-versions +1 -1
- data/Cargo.lock +292 -751
- data/Cargo.toml +1 -1
- data/README.md +213 -2
- data/ext/app_bridge/Cargo.toml +8 -4
- data/ext/app_bridge/src/app_state.rs +29 -13
- data/ext/app_bridge/src/component.rs +256 -46
- data/ext/app_bridge/src/error_mapping.rs +24 -24
- data/ext/app_bridge/src/file_ops.rs +325 -0
- data/ext/app_bridge/src/lib.rs +5 -1
- data/ext/app_bridge/src/request_builder.rs +270 -152
- data/ext/app_bridge/src/types.rs +78 -0
- data/ext/app_bridge/src/wrappers/action_context.rs +3 -3
- 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/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 +26 -0
- data/tasks/fixtures.rake +16 -2
- metadata +8 -4
|
@@ -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
|
+
}
|
data/lib/app_bridge/app.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "json"
|
|
3
4
|
require "timeout"
|
|
4
5
|
|
|
5
6
|
module AppBridge
|
|
@@ -25,9 +26,13 @@ module AppBridge
|
|
|
25
26
|
def execute_action(context)
|
|
26
27
|
response = request_action_with_timeout(context)
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
# Process files: find file-output fields in schema and replace with blob IDs
|
|
30
|
+
processed_output = process_files(response.serialized_output, context)
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
validate_action_response_size!(processed_output)
|
|
33
|
+
|
|
34
|
+
# Return new response with processed output
|
|
35
|
+
response.with_output(processed_output)
|
|
31
36
|
end
|
|
32
37
|
|
|
33
38
|
def timeout_seconds
|
|
@@ -65,5 +70,19 @@ module AppBridge
|
|
|
65
70
|
_rust_fetch_events(context)
|
|
66
71
|
end
|
|
67
72
|
end
|
|
73
|
+
|
|
74
|
+
# Process files in the response based on output schema
|
|
75
|
+
def process_files(serialized_output, context)
|
|
76
|
+
data = JSON.parse(serialized_output)
|
|
77
|
+
schema = parse_output_schema(context)
|
|
78
|
+
JSON.generate(FileProcessor.call(data, schema))
|
|
79
|
+
rescue JSON::ParserError
|
|
80
|
+
# Schema parsing failed, return original output
|
|
81
|
+
serialized_output
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def parse_output_schema(context)
|
|
85
|
+
JSON.parse(action_output_schema(context))
|
|
86
|
+
end
|
|
68
87
|
end
|
|
69
88
|
end
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
5
|
+
module AppBridge
|
|
6
|
+
# Processes file data from WASM component responses.
|
|
7
|
+
#
|
|
8
|
+
# Uses the output schema to find fields with format: "file-output" and
|
|
9
|
+
# replaces the file data (base64, content_type, filename) with blob IDs
|
|
10
|
+
# via the configured file_uploader.
|
|
11
|
+
#
|
|
12
|
+
# The WASM component should use file.read to normalize any input format
|
|
13
|
+
# (URL, data URI, raw base64) into a consistent hash structure before output.
|
|
14
|
+
class FileProcessor
|
|
15
|
+
FILE_OUTPUT_FORMAT = "file-output"
|
|
16
|
+
|
|
17
|
+
# Process file data in a response hash.
|
|
18
|
+
#
|
|
19
|
+
# @param data [Hash] The response data from a WASM component
|
|
20
|
+
# @param schema [Hash] The JSON schema for the response data
|
|
21
|
+
# @return [Hash] The processed data with file IDs instead of file data
|
|
22
|
+
def self.call(data, schema)
|
|
23
|
+
new(data, schema).call
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# @param data [Hash] The response data from a WASM component
|
|
27
|
+
# @param schema [Hash] The JSON schema for the response data
|
|
28
|
+
def initialize(data, schema)
|
|
29
|
+
@data = deep_dup(data)
|
|
30
|
+
@schema = schema
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Processes the data, uploading files and replacing file data with IDs.
|
|
34
|
+
#
|
|
35
|
+
# @return [Hash] The processed data with file IDs
|
|
36
|
+
def call
|
|
37
|
+
process_node(@data, @schema)
|
|
38
|
+
@data
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def process_node(data_node, schema_node)
|
|
44
|
+
return unless data_node.is_a?(Hash) && schema_node.is_a?(Hash)
|
|
45
|
+
|
|
46
|
+
properties = schema_node["properties"]
|
|
47
|
+
return unless properties.is_a?(Hash)
|
|
48
|
+
|
|
49
|
+
properties.each do |key, sub_schema|
|
|
50
|
+
process_property(data_node, key, sub_schema)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def process_property(data_node, key, sub_schema)
|
|
55
|
+
data_value, actual_key = find_data_value(data_node, key)
|
|
56
|
+
return if data_value.nil?
|
|
57
|
+
|
|
58
|
+
if sub_schema["format"] == FILE_OUTPUT_FORMAT
|
|
59
|
+
process_file_field(data_node, actual_key, data_value)
|
|
60
|
+
elsif array_schema?(sub_schema)
|
|
61
|
+
process_array_field(data_value, sub_schema)
|
|
62
|
+
elsif data_value.is_a?(Hash)
|
|
63
|
+
process_node(data_value, sub_schema)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def find_data_value(data_node, key)
|
|
68
|
+
str_key = key.to_s
|
|
69
|
+
return [nil, nil] unless data_node.key?(str_key)
|
|
70
|
+
|
|
71
|
+
[data_node[str_key], str_key]
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def process_file_field(data_node, actual_key, data_value)
|
|
75
|
+
return unless file_data?(data_value)
|
|
76
|
+
|
|
77
|
+
blob_id = upload_file(data_value)
|
|
78
|
+
data_node[actual_key] = blob_id
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def array_schema?(sub_schema)
|
|
82
|
+
sub_schema["type"] == "array" && sub_schema["items"].is_a?(Hash)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def process_array_field(data_value, sub_schema)
|
|
86
|
+
return unless data_value.is_a?(Array)
|
|
87
|
+
|
|
88
|
+
items_schema = sub_schema["items"]
|
|
89
|
+
data_value.each_with_index do |item, index|
|
|
90
|
+
if items_schema["format"] == FILE_OUTPUT_FORMAT && file_data?(item)
|
|
91
|
+
data_value[index] = upload_file(item)
|
|
92
|
+
else
|
|
93
|
+
process_node(item, items_schema)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def file_data?(value)
|
|
99
|
+
return false unless value.is_a?(Hash)
|
|
100
|
+
|
|
101
|
+
present?(value["base64"]) && present?(value["filename"])
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def upload_file(file_data)
|
|
105
|
+
result = AppBridge.file_uploader.call(file_data)
|
|
106
|
+
# If uploader returns nil (no uploader configured), leave data unchanged
|
|
107
|
+
result.nil? ? file_data : result
|
|
108
|
+
rescue StandardError => e
|
|
109
|
+
raise AppBridge::InternalError, "Failed to upload '#{file_data["filename"]}': #{e.message}"
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def present?(value)
|
|
113
|
+
!value.nil? && !value.to_s.strip.empty?
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Deep duplicates the object and normalizes all hash keys to strings
|
|
117
|
+
def deep_dup(obj)
|
|
118
|
+
case obj
|
|
119
|
+
when Hash then obj.transform_keys(&:to_s).transform_values { |v| deep_dup(v) }
|
|
120
|
+
when Array then obj.map { |v| deep_dup(v) }
|
|
121
|
+
else safe_dup(obj)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def safe_dup(obj)
|
|
126
|
+
obj.dup
|
|
127
|
+
rescue TypeError
|
|
128
|
+
obj
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
data/lib/app_bridge/version.rb
CHANGED
data/lib/app_bridge.rb
CHANGED
|
@@ -2,13 +2,39 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "app_bridge/version"
|
|
4
4
|
require_relative "app_bridge/app"
|
|
5
|
+
require_relative "app_bridge/file_processor"
|
|
5
6
|
|
|
7
|
+
# Communication layer for Standout integration apps using WebAssembly components.
|
|
6
8
|
module AppBridge
|
|
7
9
|
class Error < StandardError; end
|
|
8
10
|
class TimeoutError < Error; end
|
|
9
11
|
class TooManyEventsError < Error; end
|
|
10
12
|
class StoreTooLargeError < Error; end
|
|
11
13
|
class ActionResponseTooLargeError < Error; end
|
|
14
|
+
class FileUploadError < Error; end
|
|
15
|
+
class InternalError < Error; end
|
|
16
|
+
|
|
17
|
+
class << self
|
|
18
|
+
# Configurable file uploader callback.
|
|
19
|
+
# The platform should set this to handle file uploads and return an ID.
|
|
20
|
+
#
|
|
21
|
+
# @example Configure with ActiveStorage
|
|
22
|
+
# AppBridge.file_uploader = ->(file_data) {
|
|
23
|
+
# content = Base64.decode64(file_data['base64'])
|
|
24
|
+
# blob = ActiveStorage::Blob.create_and_upload!(
|
|
25
|
+
# io: StringIO.new(content),
|
|
26
|
+
# filename: file_data['filename'],
|
|
27
|
+
# content_type: file_data['content_type'] || 'application/octet-stream'
|
|
28
|
+
# )
|
|
29
|
+
# blob.signed_id # Returns just the ID
|
|
30
|
+
# }
|
|
31
|
+
attr_accessor :file_uploader
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Default no-op uploader (returns nil - no file storage configured)
|
|
35
|
+
# rubocop:disable Style/NilLambda
|
|
36
|
+
self.file_uploader = ->(_file_data) { nil }
|
|
37
|
+
# rubocop:enable Style/NilLambda
|
|
12
38
|
|
|
13
39
|
# Represents a trigger event that is recieved from the app.
|
|
14
40
|
class TriggerEvent
|
data/tasks/fixtures.rake
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require "English"
|
|
4
4
|
|
|
5
|
-
namespace :fixtures do
|
|
5
|
+
namespace :fixtures do
|
|
6
6
|
namespace :apps do
|
|
7
7
|
desc "Clean up build artifacts"
|
|
8
8
|
task :clean do
|
|
@@ -37,8 +37,22 @@ namespace :fixtures do # rubocop:disable Metrics/BlockLength
|
|
|
37
37
|
Process.wait(pid)
|
|
38
38
|
raise "Failed to build artifacts" unless $CHILD_STATUS.success?
|
|
39
39
|
end
|
|
40
|
+
|
|
41
|
+
desc "Compile the v3 fixture app (for backward compatibility testing)"
|
|
42
|
+
task :compile_rust_v3 do
|
|
43
|
+
pwd = "spec/fixtures/components/rust_app_v3"
|
|
44
|
+
next unless File.exist?(pwd)
|
|
45
|
+
|
|
46
|
+
compile_pid = Process.spawn("cargo clean && cargo build --release --target wasm32-wasip2",
|
|
47
|
+
chdir: pwd)
|
|
48
|
+
Process.wait(compile_pid)
|
|
49
|
+
raise "Failed to build v3 artifacts" unless $CHILD_STATUS.success?
|
|
50
|
+
|
|
51
|
+
move_pid = Process.spawn("mv #{pwd}/target/wasm32-wasip2/release/rust_app_v3.wasm #{pwd}/../rust_app_v3.wasm")
|
|
52
|
+
Process.wait(move_pid)
|
|
53
|
+
end
|
|
40
54
|
end
|
|
41
55
|
end
|
|
42
56
|
|
|
43
57
|
desc "Build all fixtures"
|
|
44
|
-
task fixtures: %i[fixtures:apps:clean fixtures:apps:compile_rust fixtures:apps:compile_js]
|
|
58
|
+
task fixtures: %i[fixtures:apps:clean fixtures:apps:compile_rust fixtures:apps:compile_js fixtures:apps:compile_rust_v3]
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: app_bridge
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 4.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexander Ross
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: rb_sys
|
|
@@ -47,8 +47,10 @@ files:
|
|
|
47
47
|
- ext/app_bridge/src/app_state.rs
|
|
48
48
|
- ext/app_bridge/src/component.rs
|
|
49
49
|
- ext/app_bridge/src/error_mapping.rs
|
|
50
|
+
- ext/app_bridge/src/file_ops.rs
|
|
50
51
|
- ext/app_bridge/src/lib.rs
|
|
51
52
|
- ext/app_bridge/src/request_builder.rs
|
|
53
|
+
- ext/app_bridge/src/types.rs
|
|
52
54
|
- ext/app_bridge/src/wrappers/action_context.rs
|
|
53
55
|
- ext/app_bridge/src/wrappers/action_response.rs
|
|
54
56
|
- ext/app_bridge/src/wrappers/app.rs
|
|
@@ -57,9 +59,11 @@ files:
|
|
|
57
59
|
- ext/app_bridge/src/wrappers/trigger_context.rs
|
|
58
60
|
- ext/app_bridge/src/wrappers/trigger_event.rs
|
|
59
61
|
- ext/app_bridge/src/wrappers/trigger_response.rs
|
|
60
|
-
- ext/app_bridge/wit/world.wit
|
|
62
|
+
- ext/app_bridge/wit/v3/world.wit
|
|
63
|
+
- ext/app_bridge/wit/v4/world.wit
|
|
61
64
|
- lib/app_bridge.rb
|
|
62
65
|
- lib/app_bridge/app.rb
|
|
66
|
+
- lib/app_bridge/file_processor.rb
|
|
63
67
|
- lib/app_bridge/version.rb
|
|
64
68
|
- sig/app_bridge.rbs
|
|
65
69
|
- tasks/fixtures.rake
|
|
@@ -87,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
87
91
|
- !ruby/object:Gem::Version
|
|
88
92
|
version: 3.3.11
|
|
89
93
|
requirements: []
|
|
90
|
-
rubygems_version: 3.6.
|
|
94
|
+
rubygems_version: 3.6.9
|
|
91
95
|
specification_version: 4
|
|
92
96
|
summary: Communication layer for Standout integration apps
|
|
93
97
|
test_files: []
|