push_notifications.proto 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. syntax = "proto3";
  2. package chatto.api.v1;
  3. import "buf/validate/validate.proto";
  4. // Browser Web Push subscription commands for the authenticated user.
  5. service PushNotificationService {
  6. // Stores or updates the caller's browser push subscription.
  7. //
  8. // The server must have Web Push configured. Clients normally call this after
  9. // the browser grants notification permission and returns a PushSubscription.
  10. // A stored subscription expires 180 days after its most recent save. The
  11. // client owns the refresh: call Subscribe again when the app starts and at
  12. // least once a day while it runs, and when the browser replaces the
  13. // PushSubscription. The server removes expired records itself. Call
  14. // Unsubscribe to stop delivery before the subscription expires.
  15. rpc Subscribe(SubscribeRequest) returns (SubscribeResponse);
  16. // Removes the caller's browser push subscription by endpoint.
  17. //
  18. // The call is idempotent: removing an unknown endpoint still succeeds.
  19. rpc Unsubscribe(UnsubscribeRequest) returns (UnsubscribeResponse) {
  20. option idempotency_level = IDEMPOTENT;
  21. }
  22. // Sends a test notification to the caller's registered browser subscriptions.
  23. // Calls are rate-limited per account. Delivery failures return a generic
  24. // unavailable error without exposing the push provider's response body.
  25. rpc SendTestNotification(SendTestNotificationRequest) returns (SendTestNotificationResponse);
  26. }
  27. // Request to store a PushSubscription returned by the browser Push API.
  28. message SubscribeRequest {
  29. // Absolute HTTPS push service endpoint URL. The server rejects redirects and
  30. // destinations that resolve to private or other special-use addresses.
  31. string endpoint = 1 [(buf.validate.field).string = {
  32. min_len: 1
  33. max_len: 4096
  34. }];
  35. // Client P-256 ECDH public key from PushSubscription.keys.p256dh.
  36. string p256dh = 2 [(buf.validate.field).string = {
  37. min_len: 1
  38. max_len: 256
  39. }];
  40. // Authentication secret from PushSubscription.keys.auth.
  41. string auth = 3 [(buf.validate.field).string = {
  42. min_len: 1
  43. max_len: 128
  44. }];
  45. // Optional browser user-agent string for device identification.
  46. optional string user_agent = 4 [(buf.validate.field).string.max_len = 512];
  47. // URL host of the Chatto server that supplied the installed web app. The
  48. // sending server combines this with its own hostname to reconstruct the
  49. // client route. A host can include a port but no scheme, path, or user info.
  50. string client_host = 5 [(buf.validate.field).string = {
  51. min_len: 1
  52. max_len: 255
  53. }];
  54. // Random per-save capability generated by the client. A cancelled save can
  55. // later remove only the record carrying this exact token, even when the same
  56. // browser PushSubscription has since moved to another account.
  57. string cleanup_token = 6 [(buf.validate.field).string = {
  58. min_len: 32
  59. max_len: 128
  60. }];
  61. }
  62. // Response from storing a browser push subscription.
  63. message SubscribeResponse {
  64. reserved 1;
  65. reserved "subscribed";
  66. }
  67. // Request to remove a browser push subscription.
  68. message UnsubscribeRequest {
  69. // Push service endpoint URL to remove.
  70. string endpoint = 1 [(buf.validate.field).string = {
  71. min_len: 1
  72. max_len: 4096
  73. }];
  74. }
  75. // Response from removing a browser push subscription.
  76. message UnsubscribeResponse {
  77. reserved 1;
  78. reserved "unsubscribed";
  79. }
  80. // Request to test the current user's registered browser push subscriptions.
  81. message SendTestNotificationRequest {}
  82. // Result of sending a test Web Push notification.
  83. message SendTestNotificationResponse {
  84. reserved 1;
  85. reserved "sent";
  86. }