@positronic/cloudflare 0.0.71 → 0.0.72

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.
@@ -126,6 +126,7 @@ import pages from './pages.js';
126
126
  import secrets from './secrets.js';
127
127
  import bundle from './bundle.js';
128
128
  import users from './users.js';
129
+ import store from './store.js';
129
130
  import { authMiddleware } from './auth-middleware.js';
130
131
  var app = new Hono();
131
132
  // Health check endpoint (no auth required)
@@ -212,4 +213,5 @@ app.route('/pages', pages);
212
213
  app.route('/secrets', secrets);
213
214
  app.route('/bundle', bundle);
214
215
  app.route('/users', users);
216
+ app.route('/store', store);
215
217
  export default app;
@@ -178,16 +178,7 @@ function _ts_generator(thisArg, body) {
178
178
  }
179
179
  }
180
180
  import { Hono } from 'hono';
181
- /**
182
- * Get the origin URL for constructing page URLs.
183
- * Uses WORKER_URL env var if set, otherwise falls back to request URL.
184
- */ function getOrigin(context) {
185
- if (context.env.WORKER_URL) {
186
- return context.env.WORKER_URL;
187
- }
188
- var url = new URL(context.req.url);
189
- return "".concat(url.protocol, "//").concat(url.host);
190
- }
181
+ import { getOrigin } from '../origin.js';
191
182
  /**
192
183
  * Generates a unique slug for pages that don't provide one.
193
184
  * Uses brainRunId prefix + random suffix for uniqueness.
@@ -200,15 +191,15 @@ var pages = new Hono();
200
191
  // Create a new page
201
192
  pages.post('/', function(context) {
202
193
  return _async_to_generator(function() {
203
- var body, slug, html, brainRunId, _body_persist, persist, ttl, bucket, key, createdAt, monitorId, monitorStub, pageUrl, error;
194
+ var body, slug, html, brainRunId, _body_persist, persist, ttl, bucket, key, createdAt, monitorId, monitorStub, origin, pageUrl, error;
204
195
  return _ts_generator(this, function(_state) {
205
196
  switch(_state.label){
206
197
  case 0:
207
198
  _state.trys.push([
208
199
  0,
209
- 4,
200
+ 5,
210
201
  ,
211
- 5
202
+ 6
212
203
  ]);
213
204
  return [
214
205
  4,
@@ -277,8 +268,13 @@ pages.post('/', function(context) {
277
268
  ];
278
269
  case 3:
279
270
  _state.sent();
280
- // Build the public URL for this page
281
- pageUrl = "".concat(getOrigin(context), "/pages/").concat(slug);
271
+ return [
272
+ 4,
273
+ getOrigin(context.env.RESOURCES_BUCKET)
274
+ ];
275
+ case 4:
276
+ origin = _state.sent();
277
+ pageUrl = "".concat(origin, "/pages/").concat(slug);
282
278
  return [
283
279
  2,
284
280
  context.json(_object_spread_props(_object_spread({
@@ -292,7 +288,7 @@ pages.post('/', function(context) {
292
288
  createdAt: createdAt
293
289
  }), 201)
294
290
  ];
295
- case 4:
291
+ case 5:
296
292
  error = _state.sent();
297
293
  console.error('Error creating page:', error);
298
294
  return [
@@ -301,7 +297,7 @@ pages.post('/', function(context) {
301
297
  error: "Failed to create page: ".concat(_instanceof(error, Error) ? error.message : 'Unknown error')
302
298
  }, 500)
303
299
  ];
304
- case 5:
300
+ case 6:
305
301
  return [
306
302
  2
307
303
  ];
@@ -312,7 +308,7 @@ pages.post('/', function(context) {
312
308
  // List all pages
313
309
  pages.get('/', function(context) {
314
310
  return _async_to_generator(function() {
315
- var bucket, listed, pageList, validPages, error;
311
+ var bucket, listed, origin, pageList, validPages, error;
316
312
  return _ts_generator(this, function(_state) {
317
313
  switch(_state.label){
318
314
  case 0:
@@ -321,9 +317,9 @@ pages.get('/', function(context) {
321
317
  case 1:
322
318
  _state.trys.push([
323
319
  1,
324
- 4,
320
+ 5,
325
321
  ,
326
- 5
322
+ 6
327
323
  ]);
328
324
  return [
329
325
  4,
@@ -333,6 +329,12 @@ pages.get('/', function(context) {
333
329
  ];
334
330
  case 2:
335
331
  listed = _state.sent();
332
+ return [
333
+ 4,
334
+ getOrigin(bucket)
335
+ ];
336
+ case 3:
337
+ origin = _state.sent();
336
338
  return [
337
339
  4,
338
340
  Promise.all(listed.objects.map(function(object) {
@@ -356,7 +358,7 @@ pages.get('/', function(context) {
356
358
  metadata = r2Object.customMetadata || {};
357
359
  slug = metadata.slug || object.key.replace('pages/', '').replace('.html', '');
358
360
  // Build the public URL
359
- pageUrl = "".concat(getOrigin(context), "/pages/").concat(slug);
361
+ pageUrl = "".concat(origin, "/pages/").concat(slug);
360
362
  return [
361
363
  2,
362
364
  _object_spread_props(_object_spread({
@@ -376,7 +378,7 @@ pages.get('/', function(context) {
376
378
  })();
377
379
  }))
378
380
  ];
379
- case 3:
381
+ case 4:
380
382
  pageList = _state.sent();
381
383
  // Filter out any null entries
382
384
  validPages = pageList.filter(function(page) {
@@ -389,7 +391,7 @@ pages.get('/', function(context) {
389
391
  count: validPages.length
390
392
  })
391
393
  ];
392
- case 4:
394
+ case 5:
393
395
  error = _state.sent();
394
396
  console.error('Error listing pages:', error);
395
397
  return [
@@ -398,7 +400,7 @@ pages.get('/', function(context) {
398
400
  error: "Failed to list pages: ".concat(_instanceof(error, Error) ? error.message : 'Unknown error')
399
401
  }, 500)
400
402
  ];
401
- case 5:
403
+ case 6:
402
404
  return [
403
405
  2
404
406
  ];
@@ -536,7 +538,7 @@ pages.get('/:slug', function(context) {
536
538
  // Update page HTML content
537
539
  pages.put('/:slug', function(context) {
538
540
  return _async_to_generator(function() {
539
- var slug, bucket, key, existingObject, body, html, existingMetadata, pageUrl, error;
541
+ var slug, bucket, key, existingObject, body, html, existingMetadata, origin, pageUrl, error;
540
542
  return _ts_generator(this, function(_state) {
541
543
  switch(_state.label){
542
544
  case 0:
@@ -547,9 +549,9 @@ pages.put('/:slug', function(context) {
547
549
  case 1:
548
550
  _state.trys.push([
549
551
  1,
550
- 5,
552
+ 6,
551
553
  ,
552
- 6
554
+ 7
553
555
  ]);
554
556
  return [
555
557
  4,
@@ -594,8 +596,13 @@ pages.put('/:slug', function(context) {
594
596
  ];
595
597
  case 4:
596
598
  _state.sent();
597
- // Build the public URL
598
- pageUrl = "".concat(getOrigin(context), "/pages/").concat(slug);
599
+ return [
600
+ 4,
601
+ getOrigin(bucket)
602
+ ];
603
+ case 5:
604
+ origin = _state.sent();
605
+ pageUrl = "".concat(origin, "/pages/").concat(slug);
599
606
  return [
600
607
  2,
601
608
  context.json({
@@ -604,7 +611,7 @@ pages.put('/:slug', function(context) {
604
611
  updatedAt: new Date().toISOString()
605
612
  })
606
613
  ];
607
- case 5:
614
+ case 6:
608
615
  error = _state.sent();
609
616
  console.error("Error updating page ".concat(slug, ":"), error);
610
617
  return [
@@ -613,7 +620,7 @@ pages.put('/:slug', function(context) {
613
620
  error: "Failed to update page: ".concat(_instanceof(error, Error) ? error.message : 'Unknown error')
614
621
  }, 500)
615
622
  ];
616
- case 6:
623
+ case 7:
617
624
  return [
618
625
  2
619
626
  ];