@positronic/cloudflare 0.0.77 → 0.0.78
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.
- package/dist/src/api/brains.js +90 -195
- package/dist/src/api/files.js +178 -0
- package/dist/src/api/index.js +9 -0
- package/dist/src/api/webhooks/coordination.js +0 -2
- package/dist/src/api/webhooks/index.js +43 -36
- package/dist/src/api/webhooks/system.js +23 -21
- package/dist/src/brain-runner-do.js +110 -170
- package/dist/src/content-type.js +6 -0
- package/dist/src/dev-server.js +128 -18
- package/dist/src/file-utils.js +7 -0
- package/dist/src/files-service.js +465 -0
- package/dist/src/manifest.js +13 -8
- package/dist/src/monitor-do.js +17 -0
- package/dist/src/schedule-do.js +5 -19
- package/dist/src/zip-builder.js +507 -0
- package/dist/types/api/brains.d.ts.map +1 -1
- package/dist/types/api/files.d.ts +7 -0
- package/dist/types/api/files.d.ts.map +1 -0
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/webhooks/coordination.d.ts +0 -1
- package/dist/types/api/webhooks/coordination.d.ts.map +1 -1
- package/dist/types/api/webhooks/index.d.ts.map +1 -1
- package/dist/types/api/webhooks/system.d.ts.map +1 -1
- package/dist/types/brain-runner-do.d.ts +13 -7
- package/dist/types/brain-runner-do.d.ts.map +1 -1
- package/dist/types/content-type.d.ts +2 -0
- package/dist/types/content-type.d.ts.map +1 -0
- package/dist/types/dev-server.d.ts +1 -0
- package/dist/types/dev-server.d.ts.map +1 -1
- package/dist/types/file-utils.d.ts +3 -0
- package/dist/types/file-utils.d.ts.map +1 -0
- package/dist/types/files-service.d.ts +4 -0
- package/dist/types/files-service.d.ts.map +1 -0
- package/dist/types/manifest.d.ts.map +1 -1
- package/dist/types/monitor-do.d.ts +6 -0
- package/dist/types/monitor-do.d.ts.map +1 -1
- package/dist/types/schedule-do.d.ts +0 -1
- package/dist/types/schedule-do.d.ts.map +1 -1
- package/dist/types/zip-builder.d.ts +4 -0
- package/dist/types/zip-builder.d.ts.map +1 -0
- package/package.json +5 -4
|
@@ -165,7 +165,7 @@ function _ts_generator(thisArg, body) {
|
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
import { Hono } from 'hono';
|
|
168
|
-
import { getWebhookManifest } from '../../brain-runner-do.js';
|
|
168
|
+
import { getWebhookManifest, startBrainRun } from '../../brain-runner-do.js';
|
|
169
169
|
import { queueWebhookAndWakeUp } from './coordination.js';
|
|
170
170
|
import system from './system.js';
|
|
171
171
|
var webhooks = new Hono();
|
|
@@ -197,7 +197,7 @@ webhooks.get('/', function(context) {
|
|
|
197
197
|
// Receive incoming webhook from external service (user-defined webhooks)
|
|
198
198
|
webhooks.post('/:slug', function(context) {
|
|
199
199
|
return _async_to_generator(function() {
|
|
200
|
-
var slug, webhookManifest, webhook,
|
|
200
|
+
var slug, webhookManifest, webhook, handlerResult, brainRunId, submittedToken, result, error;
|
|
201
201
|
return _ts_generator(this, function(_state) {
|
|
202
202
|
switch(_state.label){
|
|
203
203
|
case 0:
|
|
@@ -216,13 +216,10 @@ webhooks.post('/:slug', function(context) {
|
|
|
216
216
|
case 1:
|
|
217
217
|
_state.trys.push([
|
|
218
218
|
1,
|
|
219
|
-
|
|
219
|
+
6,
|
|
220
220
|
,
|
|
221
|
-
|
|
221
|
+
7
|
|
222
222
|
]);
|
|
223
|
-
// Clone the request so we can extract the CSRF token separately
|
|
224
|
-
// without consuming the body that the user's handler needs
|
|
225
|
-
clonedReq = context.req.raw.clone();
|
|
226
223
|
return [
|
|
227
224
|
4,
|
|
228
225
|
webhook.handler(context.req.raw)
|
|
@@ -238,44 +235,54 @@ webhooks.post('/:slug', function(context) {
|
|
|
238
235
|
})
|
|
239
236
|
];
|
|
240
237
|
}
|
|
241
|
-
//
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
238
|
+
// Handler determined this event should be ignored
|
|
239
|
+
if (handlerResult.type === 'ignore') {
|
|
240
|
+
return [
|
|
241
|
+
2,
|
|
242
|
+
context.json({
|
|
243
|
+
received: true,
|
|
244
|
+
action: 'ignored'
|
|
245
|
+
})
|
|
246
|
+
];
|
|
247
|
+
}
|
|
248
|
+
if (!(handlerResult.type === 'trigger')) return [
|
|
245
249
|
3,
|
|
246
|
-
|
|
250
|
+
4
|
|
247
251
|
];
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
252
|
+
if (!webhook.triggers) {
|
|
253
|
+
return [
|
|
254
|
+
2,
|
|
255
|
+
context.json({
|
|
256
|
+
error: "Webhook '".concat(slug, "' returned trigger result but has no triggers config")
|
|
257
|
+
}, 400)
|
|
258
|
+
];
|
|
259
|
+
}
|
|
256
260
|
return [
|
|
257
261
|
4,
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
return [
|
|
264
|
-
3,
|
|
265
|
-
6
|
|
262
|
+
startBrainRun(context.env.BRAIN_RUNNER_DO, webhook.triggers.brain, {
|
|
263
|
+
name: webhook.triggers.runAs
|
|
264
|
+
}, {
|
|
265
|
+
initialState: handlerResult.response
|
|
266
|
+
})
|
|
266
267
|
];
|
|
267
|
-
case
|
|
268
|
-
|
|
268
|
+
case 3:
|
|
269
|
+
brainRunId = _state.sent();
|
|
269
270
|
return [
|
|
270
|
-
|
|
271
|
-
|
|
271
|
+
2,
|
|
272
|
+
context.json({
|
|
273
|
+
received: true,
|
|
274
|
+
action: 'triggered',
|
|
275
|
+
brainRunId: brainRunId
|
|
276
|
+
}, 201)
|
|
272
277
|
];
|
|
273
|
-
case
|
|
278
|
+
case 4:
|
|
279
|
+
// CSRF token is passed as a query parameter (if present)
|
|
280
|
+
submittedToken = context.req.query('token') || null;
|
|
274
281
|
return [
|
|
275
282
|
4,
|
|
276
283
|
queueWebhookAndWakeUp(context, slug, handlerResult.identifier, handlerResult.response, submittedToken)
|
|
277
284
|
];
|
|
278
|
-
case
|
|
285
|
+
case 5:
|
|
279
286
|
result = _state.sent();
|
|
280
287
|
// For user webhooks, return 'queued' instead of 'not_found' when no brain is waiting
|
|
281
288
|
// This allows webhooks to be received even when no brain is actively waiting
|
|
@@ -293,7 +300,7 @@ webhooks.post('/:slug', function(context) {
|
|
|
293
300
|
2,
|
|
294
301
|
context.json(result)
|
|
295
302
|
];
|
|
296
|
-
case
|
|
303
|
+
case 6:
|
|
297
304
|
error = _state.sent();
|
|
298
305
|
console.error("Error receiving webhook ".concat(slug, ":"), error);
|
|
299
306
|
return [
|
|
@@ -302,7 +309,7 @@ webhooks.post('/:slug', function(context) {
|
|
|
302
309
|
error: 'Failed to process webhook'
|
|
303
310
|
}, 500)
|
|
304
311
|
];
|
|
305
|
-
case
|
|
312
|
+
case 7:
|
|
306
313
|
return [
|
|
307
314
|
2
|
|
308
315
|
];
|
|
@@ -171,21 +171,23 @@ function _ts_generator(thisArg, body) {
|
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
import { Hono } from 'hono';
|
|
174
|
-
import {
|
|
174
|
+
import { parseFormData } from '@positronic/core';
|
|
175
|
+
import { queueWebhookAndWakeUp } from './coordination.js';
|
|
175
176
|
var system = new Hono();
|
|
176
177
|
/**
|
|
177
|
-
* Built-in webhook for
|
|
178
|
-
* This handles form POSTs from pages generated by .
|
|
178
|
+
* Built-in webhook for page form submissions.
|
|
179
|
+
* This handles form POSTs from pages generated by .page() steps.
|
|
179
180
|
*
|
|
180
|
-
* POST /webhooks/system/
|
|
181
|
+
* POST /webhooks/system/page-form?identifier=<identifier>&token=<token>
|
|
181
182
|
* Content-Type: application/x-www-form-urlencoded or multipart/form-data
|
|
182
|
-
*/ system.post('/
|
|
183
|
+
*/ system.post('/page-form', function(context) {
|
|
183
184
|
return _async_to_generator(function() {
|
|
184
|
-
var identifier,
|
|
185
|
+
var identifier, token, formData, response, result, error;
|
|
185
186
|
return _ts_generator(this, function(_state) {
|
|
186
187
|
switch(_state.label){
|
|
187
188
|
case 0:
|
|
188
189
|
identifier = context.req.query('identifier');
|
|
190
|
+
token = context.req.query('token');
|
|
189
191
|
if (!identifier) {
|
|
190
192
|
return [
|
|
191
193
|
2,
|
|
@@ -194,6 +196,18 @@ var system = new Hono();
|
|
|
194
196
|
}, 400)
|
|
195
197
|
];
|
|
196
198
|
}
|
|
199
|
+
// System page-form endpoint always requires a CSRF token
|
|
200
|
+
if (!token) {
|
|
201
|
+
return [
|
|
202
|
+
2,
|
|
203
|
+
context.json({
|
|
204
|
+
received: false,
|
|
205
|
+
action: 'ignored',
|
|
206
|
+
identifier: identifier,
|
|
207
|
+
reason: 'Missing form token'
|
|
208
|
+
}, 403)
|
|
209
|
+
];
|
|
210
|
+
}
|
|
197
211
|
_state.label = 1;
|
|
198
212
|
case 1:
|
|
199
213
|
_state.trys.push([
|
|
@@ -208,22 +222,10 @@ var system = new Hono();
|
|
|
208
222
|
];
|
|
209
223
|
case 2:
|
|
210
224
|
formData = _state.sent();
|
|
211
|
-
|
|
212
|
-
// System ui-form endpoint always requires a CSRF token
|
|
213
|
-
if (!token) {
|
|
214
|
-
return [
|
|
215
|
-
2,
|
|
216
|
-
context.json({
|
|
217
|
-
received: false,
|
|
218
|
-
action: 'ignored',
|
|
219
|
-
identifier: identifier,
|
|
220
|
-
reason: 'Missing form token'
|
|
221
|
-
}, 403)
|
|
222
|
-
];
|
|
223
|
-
}
|
|
225
|
+
response = parseFormData(formData);
|
|
224
226
|
return [
|
|
225
227
|
4,
|
|
226
|
-
queueWebhookAndWakeUp(context, '
|
|
228
|
+
queueWebhookAndWakeUp(context, 'page-form', identifier, response, token)
|
|
227
229
|
];
|
|
228
230
|
case 3:
|
|
229
231
|
result = _state.sent();
|
|
@@ -249,7 +251,7 @@ var system = new Hono();
|
|
|
249
251
|
];
|
|
250
252
|
case 4:
|
|
251
253
|
error = _state.sent();
|
|
252
|
-
console.error('Error processing
|
|
254
|
+
console.error('Error processing page form submission:', error);
|
|
253
255
|
return [
|
|
254
256
|
2,
|
|
255
257
|
context.json({
|