@positronic/spec 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.
@@ -429,16 +429,174 @@ export var webhooks = {
429
429
  });
430
430
  })();
431
431
  },
432
- uiForm: /**
433
- * Test POST /webhooks/system/ui-form - Built-in webhook for UI form submissions.
434
- * This is used by pages generated via .ui() steps to submit form data.
432
+ trigger: /**
433
+ * Test POST /webhooks/:slug - Webhook triggers a new brain run.
434
+ * The webhook handler returns { type: 'trigger', response } and the webhook
435
+ * has a triggers config specifying which brain to start.
436
+ * Expects 201 with { received: true, action: 'triggered', brainRunId }.
437
+ */ function trigger(fetch, slug, payload) {
438
+ return _async_to_generator(function() {
439
+ var request, response, data, error;
440
+ return _ts_generator(this, function(_state) {
441
+ switch(_state.label){
442
+ case 0:
443
+ _state.trys.push([
444
+ 0,
445
+ 3,
446
+ ,
447
+ 4
448
+ ]);
449
+ request = new Request("http://example.com/webhooks/".concat(encodeURIComponent(slug)), {
450
+ method: 'POST',
451
+ headers: {
452
+ 'Content-Type': 'application/json'
453
+ },
454
+ body: JSON.stringify(payload)
455
+ });
456
+ return [
457
+ 4,
458
+ fetch(request)
459
+ ];
460
+ case 1:
461
+ response = _state.sent();
462
+ if (response.status !== 201) {
463
+ console.error("POST /webhooks/".concat(slug, " (trigger) returned ").concat(response.status, ", expected 201"));
464
+ return [
465
+ 2,
466
+ false
467
+ ];
468
+ }
469
+ return [
470
+ 4,
471
+ response.json()
472
+ ];
473
+ case 2:
474
+ data = _state.sent();
475
+ if (typeof data.received !== 'boolean' || !data.received) {
476
+ console.error("Expected received to be true, got ".concat(data.received));
477
+ return [
478
+ 2,
479
+ false
480
+ ];
481
+ }
482
+ if (data.action !== 'triggered') {
483
+ console.error("Expected action to be 'triggered', got '".concat(data.action, "'"));
484
+ return [
485
+ 2,
486
+ false
487
+ ];
488
+ }
489
+ if (!data.brainRunId || typeof data.brainRunId !== 'string') {
490
+ console.error("Expected brainRunId to be a string, got ".concat(_type_of(data.brainRunId)));
491
+ return [
492
+ 2,
493
+ false
494
+ ];
495
+ }
496
+ return [
497
+ 2,
498
+ true
499
+ ];
500
+ case 3:
501
+ error = _state.sent();
502
+ console.error("Failed to test POST /webhooks/".concat(slug, " (trigger):"), error);
503
+ return [
504
+ 2,
505
+ false
506
+ ];
507
+ case 4:
508
+ return [
509
+ 2
510
+ ];
511
+ }
512
+ });
513
+ })();
514
+ },
515
+ ignore: /**
516
+ * Test POST /webhooks/:slug - Webhook handler returns ignore.
517
+ * The webhook handler returns { type: 'ignore' } to acknowledge
518
+ * receipt but take no action.
519
+ * Expects 200 with { received: true, action: 'ignored' }.
520
+ */ function ignore(fetch, slug, payload) {
521
+ return _async_to_generator(function() {
522
+ var request, response, data, error;
523
+ return _ts_generator(this, function(_state) {
524
+ switch(_state.label){
525
+ case 0:
526
+ _state.trys.push([
527
+ 0,
528
+ 3,
529
+ ,
530
+ 4
531
+ ]);
532
+ request = new Request("http://example.com/webhooks/".concat(encodeURIComponent(slug)), {
533
+ method: 'POST',
534
+ headers: {
535
+ 'Content-Type': 'application/json'
536
+ },
537
+ body: JSON.stringify(payload)
538
+ });
539
+ return [
540
+ 4,
541
+ fetch(request)
542
+ ];
543
+ case 1:
544
+ response = _state.sent();
545
+ if (response.status !== 200) {
546
+ console.error("POST /webhooks/".concat(slug, " (ignore) returned ").concat(response.status, ", expected 200"));
547
+ return [
548
+ 2,
549
+ false
550
+ ];
551
+ }
552
+ return [
553
+ 4,
554
+ response.json()
555
+ ];
556
+ case 2:
557
+ data = _state.sent();
558
+ if (typeof data.received !== 'boolean' || !data.received) {
559
+ console.error("Expected received to be true, got ".concat(data.received));
560
+ return [
561
+ 2,
562
+ false
563
+ ];
564
+ }
565
+ if (data.action !== 'ignored') {
566
+ console.error("Expected action to be 'ignored', got '".concat(data.action, "'"));
567
+ return [
568
+ 2,
569
+ false
570
+ ];
571
+ }
572
+ return [
573
+ 2,
574
+ true
575
+ ];
576
+ case 3:
577
+ error = _state.sent();
578
+ console.error("Failed to test POST /webhooks/".concat(slug, " (ignore):"), error);
579
+ return [
580
+ 2,
581
+ false
582
+ ];
583
+ case 4:
584
+ return [
585
+ 2
586
+ ];
587
+ }
588
+ });
589
+ })();
590
+ },
591
+ pageForm: /**
592
+ * Test POST /webhooks/system/page-form - Built-in webhook for page form submissions.
593
+ * This is used by pages generated via .page() steps to submit form data.
435
594
  *
436
595
  * The endpoint:
437
596
  * - Accepts form data (application/x-www-form-urlencoded or multipart/form-data)
438
- * - Requires an `identifier` query parameter to match the waiting brain
439
- * - Requires a `__positronic_token` field for CSRF validation
597
+ * - Requires `identifier` and `token` query parameters
440
598
  * - Returns { received: true, action: 'resumed' | 'not_found', ... }
441
- */ function uiForm(fetch, identifier, formData, token) {
599
+ */ function pageForm(fetch, identifier, formData, token) {
442
600
  return _async_to_generator(function() {
443
601
  var params, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, key, value, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, v, request, response, data, error;
444
602
  return _ts_generator(this, function(_state) {
@@ -452,7 +610,6 @@ export var webhooks = {
452
610
  ]);
453
611
  // Build URLSearchParams from form data
454
612
  params = new URLSearchParams();
455
- params.append('__positronic_token', token);
456
613
  _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
457
614
  try {
458
615
  for(_iterator = Object.entries(formData)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
@@ -496,7 +653,7 @@ export var webhooks = {
496
653
  }
497
654
  }
498
655
  }
499
- request = new Request("http://example.com/webhooks/system/ui-form?identifier=".concat(encodeURIComponent(identifier)), {
656
+ request = new Request("http://example.com/webhooks/system/page-form?identifier=".concat(encodeURIComponent(identifier), "&token=").concat(encodeURIComponent(token)), {
500
657
  method: 'POST',
501
658
  headers: {
502
659
  'Content-Type': 'application/x-www-form-urlencoded'
@@ -511,7 +668,7 @@ export var webhooks = {
511
668
  response = _state.sent();
512
669
  // Accept 200 (found and processed) or 404 (no brain waiting)
513
670
  if (response.status !== 200 && response.status !== 404) {
514
- console.error("POST /webhooks/system/ui-form returned ".concat(response.status, ", expected 200 or 404"));
671
+ console.error("POST /webhooks/system/page-form returned ".concat(response.status, ", expected 200 or 404"));
515
672
  return [
516
673
  2,
517
674
  false
@@ -552,7 +709,7 @@ export var webhooks = {
552
709
  ];
553
710
  case 3:
554
711
  error = _state.sent();
555
- console.error('Failed to test POST /webhooks/system/ui-form:', error);
712
+ console.error('Failed to test POST /webhooks/system/page-form:', error);
556
713
  return [
557
714
  2,
558
715
  false
@@ -565,9 +722,9 @@ export var webhooks = {
565
722
  });
566
723
  })();
567
724
  },
568
- uiFormMissingIdentifier: /**
569
- * Test POST /webhooks/system/ui-form with missing identifier - Should return 400
570
- */ function uiFormMissingIdentifier(fetch) {
725
+ pageFormMissingIdentifier: /**
726
+ * Test POST /webhooks/system/page-form with missing identifier - Should return 400
727
+ */ function pageFormMissingIdentifier(fetch) {
571
728
  return _async_to_generator(function() {
572
729
  var request, response, data, error;
573
730
  return _ts_generator(this, function(_state) {
@@ -579,7 +736,7 @@ export var webhooks = {
579
736
  ,
580
737
  4
581
738
  ]);
582
- request = new Request('http://example.com/webhooks/system/ui-form', {
739
+ request = new Request('http://example.com/webhooks/system/page-form', {
583
740
  method: 'POST',
584
741
  headers: {
585
742
  'Content-Type': 'application/x-www-form-urlencoded'
@@ -593,7 +750,7 @@ export var webhooks = {
593
750
  case 1:
594
751
  response = _state.sent();
595
752
  if (response.status !== 400) {
596
- console.error("POST /webhooks/system/ui-form without identifier returned ".concat(response.status, ", expected 400"));
753
+ console.error("POST /webhooks/system/page-form without identifier returned ".concat(response.status, ", expected 400"));
597
754
  return [
598
755
  2,
599
756
  false
@@ -625,7 +782,7 @@ export var webhooks = {
625
782
  ];
626
783
  case 3:
627
784
  error = _state.sent();
628
- console.error('Failed to test POST /webhooks/system/ui-form without identifier:', error);
785
+ console.error('Failed to test POST /webhooks/system/page-form without identifier:', error);
629
786
  return [
630
787
  2,
631
788
  false
@@ -638,10 +795,10 @@ export var webhooks = {
638
795
  });
639
796
  })();
640
797
  },
641
- uiFormMissingToken: /**
642
- * Test POST /webhooks/system/ui-form without a CSRF token - Should return 403.
643
- * The endpoint checks for missing token before looking up a waiting brain.
644
- */ function uiFormMissingToken(fetch, identifier) {
798
+ pageFormMissingToken: /**
799
+ * Test POST /webhooks/system/page-form without a CSRF token - Should return 403.
800
+ * The endpoint checks for missing token query param before looking up a waiting brain.
801
+ */ function pageFormMissingToken(fetch, identifier) {
645
802
  return _async_to_generator(function() {
646
803
  var params, request, response, data, error;
647
804
  return _ts_generator(this, function(_state) {
@@ -653,10 +810,10 @@ export var webhooks = {
653
810
  ,
654
811
  4
655
812
  ]);
656
- // Send form data without __positronic_token
813
+ // Send form data without token query param
657
814
  params = new URLSearchParams();
658
815
  params.append('name', 'Test User');
659
- request = new Request("http://example.com/webhooks/system/ui-form?identifier=".concat(encodeURIComponent(identifier)), {
816
+ request = new Request("http://example.com/webhooks/system/page-form?identifier=".concat(encodeURIComponent(identifier)), {
660
817
  method: 'POST',
661
818
  headers: {
662
819
  'Content-Type': 'application/x-www-form-urlencoded'
@@ -670,7 +827,7 @@ export var webhooks = {
670
827
  case 1:
671
828
  response = _state.sent();
672
829
  if (response.status !== 403) {
673
- console.error("POST /webhooks/system/ui-form without token returned ".concat(response.status, ", expected 403"));
830
+ console.error("POST /webhooks/system/page-form without token returned ".concat(response.status, ", expected 403"));
674
831
  return [
675
832
  2,
676
833
  false
@@ -702,7 +859,7 @@ export var webhooks = {
702
859
  ];
703
860
  case 3:
704
861
  error = _state.sent();
705
- console.error('Failed to test POST /webhooks/system/ui-form without token:', error);
862
+ console.error('Failed to test POST /webhooks/system/page-form without token:', error);
706
863
  return [
707
864
  2,
708
865
  false
@@ -715,12 +872,12 @@ export var webhooks = {
715
872
  });
716
873
  })();
717
874
  },
718
- uiFormWrongToken: /**
719
- * Test POST /webhooks/system/ui-form with a wrong CSRF token.
875
+ pageFormWrongToken: /**
876
+ * Test POST /webhooks/system/page-form with a wrong CSRF token.
720
877
  * Without a brain waiting, the endpoint returns 404 (not_found) since
721
878
  * token comparison only runs after a brain is found. The key assertion
722
879
  * is that a wrong token never produces a successful 200 "resumed" response.
723
- */ function uiFormWrongToken(fetch, identifier, formData, wrongToken) {
880
+ */ function pageFormWrongToken(fetch, identifier, formData, wrongToken) {
724
881
  return _async_to_generator(function() {
725
882
  var params, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, key, value, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, v, request, response, data, error;
726
883
  return _ts_generator(this, function(_state) {
@@ -733,7 +890,6 @@ export var webhooks = {
733
890
  5
734
891
  ]);
735
892
  params = new URLSearchParams();
736
- params.append('__positronic_token', wrongToken);
737
893
  _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
738
894
  try {
739
895
  for(_iterator = Object.entries(formData)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
@@ -777,7 +933,7 @@ export var webhooks = {
777
933
  }
778
934
  }
779
935
  }
780
- request = new Request("http://example.com/webhooks/system/ui-form?identifier=".concat(encodeURIComponent(identifier)), {
936
+ request = new Request("http://example.com/webhooks/system/page-form?identifier=".concat(encodeURIComponent(identifier), "&token=").concat(encodeURIComponent(wrongToken)), {
781
937
  method: 'POST',
782
938
  headers: {
783
939
  'Content-Type': 'application/x-www-form-urlencoded'
@@ -801,7 +957,7 @@ export var webhooks = {
801
957
  case 2:
802
958
  data = _state.sent();
803
959
  if (data.action === 'resumed') {
804
- console.error('POST /webhooks/system/ui-form with wrong token returned 200 with action "resumed" — token validation failed');
960
+ console.error('POST /webhooks/system/page-form with wrong token returned 200 with action "resumed" — token validation failed');
805
961
  return [
806
962
  2,
807
963
  false
@@ -811,7 +967,7 @@ export var webhooks = {
811
967
  case 3:
812
968
  // Accept 403 (token mismatch) or 404 (no brain waiting — token check happens after brain lookup)
813
969
  if (response.status !== 403 && response.status !== 404) {
814
- console.error("POST /webhooks/system/ui-form with wrong token returned ".concat(response.status, ", expected 403 or 404"));
970
+ console.error("POST /webhooks/system/page-form with wrong token returned ".concat(response.status, ", expected 403 or 404"));
815
971
  return [
816
972
  2,
817
973
  false
@@ -823,7 +979,7 @@ export var webhooks = {
823
979
  ];
824
980
  case 4:
825
981
  error = _state.sent();
826
- console.error('Failed to test POST /webhooks/system/ui-form with wrong token:', error);
982
+ console.error('Failed to test POST /webhooks/system/page-form with wrong token:', error);
827
983
  return [
828
984
  2,
829
985
  false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@positronic/spec",
3
- "version": "0.0.77",
3
+ "version": "0.0.78",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },