1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! Live-update models: the versions an editor names in `If-Match` so a save
//! never overwrites a newer change.
use serde::Deserialize;
use serde_json::Value;
/// The current version of each kind of record asked for.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct LiveVersionsResponse {
/// One entry per kind of record and scope.
#[serde(default)]
pub versions: Vec<LiveVersion>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One kind of record's version in one scope.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct LiveVersion {
/// The kind of record, e.g. `payment` or `subscription_settings`.
pub entity: String,
/// The shop, for a kind kept per shop.
#[serde(default)]
pub profile_id: Option<String>,
/// The one record, when the versions were read for one.
#[serde(default)]
pub record_id: Option<String>,
/// The version.
pub version: i64,
/// Who made it, when known.
#[serde(default)]
pub by: Option<LiveActor>,
/// The value to send in `If-Match` when saving. A save over a newer
/// version is refused with `IR_16` (400).
pub if_match: String,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// Who made a version.
///
/// `Debug` redacts [`name`](Self::name), a member's personal name.
#[derive(Clone, Deserialize)]
#[non_exhaustive]
pub struct LiveActor {
/// `user`, `support`, `api_key` or `system`; open to kinds added later.
pub kind: String,
/// The member, for `user`.
#[serde(default)]
pub user_id: Option<String>,
/// The member's name, for `user`, when they gave one.
#[serde(default)]
pub name: Option<String>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
impl std::fmt::Debug for LiveActor {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("LiveActor")
.field("kind", &self.kind)
.field("user_id", &self.user_id)
.field("name", &self.name.as_ref().map(|_| "[redacted]"))
.field("extra", &self.extra)
.finish()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn an_actor_debug_redacts_the_name() {
let actor: LiveActor =
serde_json::from_str(r#"{"kind":"user","user_id":"usr_1","name":"Ada Lovelace"}"#)
.unwrap();
let rendered = format!("{actor:?}");
assert!(!rendered.contains("Ada Lovelace"), "{rendered}");
assert!(rendered.contains("usr_1"));
}
}