io_jmap/rfc8620/push_subscription.rs
1//! JMAP PushSubscription (RFC 8620 §7.2): register a URL the JMAP server
2//! POSTs push messages to, verified via a pushed [`JmapPushVerification`]
3//! code.
4//!
5//! Unlike other JMAP objects, push subscriptions are tied to authentication
6//! credentials rather than accounts, so `PushSubscription/get` and
7//! `PushSubscription/set` take no `accountId` and track no state string.
8
9use alloc::{
10 string::{String, ToString},
11 vec::Vec,
12};
13
14use serde::{Deserialize, Serialize};
15
16pub mod get;
17pub mod set;
18
19/// A JMAP PushSubscription object (RFC 8620 §7.2), as returned by the server.
20///
21/// The `url` and `keys` properties are write-only (RFC 8620 §7.2.1: the
22/// server MUST NOT return them), so they live on
23/// [`set::JmapPushSubscriptionCreate`] only.
24#[derive(Clone, Debug, Serialize, Deserialize)]
25#[serde(rename_all = "camelCase")]
26pub struct JmapPushSubscription {
27 /// The server-assigned ID. Defaults to empty in `PushSubscription/set`
28 /// updated echoes, which carry only the server-changed properties.
29 #[serde(default)]
30 pub id: String,
31 /// An ID unique to the client + device that created the subscription,
32 /// letting clients recognize their own subscriptions after losing local
33 /// state (RFC 8620 §7.2).
34 #[serde(default)]
35 pub device_client_id: Option<String>,
36 /// The verification code proving the client controls the URL, copied by
37 /// the client from the pushed [`JmapPushVerification`].
38 #[serde(default)]
39 pub verification_code: Option<String>,
40 /// RFC 3339 time this subscription expires; the server may set or clamp
41 /// it.
42 #[serde(default)]
43 pub expires: Option<String>,
44 /// Type names pushes are restricted to; `None` pushes all types.
45 #[serde(default)]
46 pub types: Option<Vec<String>>,
47}
48
49/// The PushVerification object the server POSTs to the subscription URL
50/// right after create (RFC 8620 §7.2.2); the client MUST copy
51/// `verification_code` into a [`set::JmapPushSubscriptionUpdate`] before the
52/// server makes any further pushes.
53#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
54#[serde(rename_all = "camelCase")]
55pub struct JmapPushVerification {
56 /// The type tag: always the string `PushVerification`.
57 #[serde(rename = "@type", default = "default_type_tag")]
58 pub r#type: String,
59 /// The ID of the push subscription that was created.
60 pub push_subscription_id: String,
61 /// The code to copy back into the subscription.
62 pub verification_code: String,
63}
64
65fn default_type_tag() -> String {
66 "PushVerification".to_string()
67}