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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
//! A shop's own texts of the emails it sends its buyers.
//!
//! In each language the shop's text goes before the platform's, which goes
//! before the built-in one. Enumerated values arrive as strings, so a value
//! added later does not break decoding; each field lists the values known
//! today.
use std::fmt;
use serde::{Deserialize, Serialize};
use serde_json::Value;
/// A template's text in one language, in one of two modes: the branded
/// layout filled with the parts below, or a whole HTML document.
///
/// Sent as `{"mode": "layout", ...}` or `{"mode": "html", ...}`.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "mode", rename_all = "snake_case")]
#[non_exhaustive]
pub enum MessageTemplateContent {
/// The branded layout, filled with a subject, heading, body and button.
Layout(MessageTemplateLayout),
/// A whole HTML document.
Html(MessageTemplateHtml),
}
/// The parts of a text in the branded layout.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MessageTemplateLayout {
/// The subject line.
pub subject: String,
/// The preview text mail clients show after the subject.
#[serde(default)]
pub preheader: Option<String>,
/// The heading.
#[serde(default)]
pub heading: Option<String>,
/// The body.
pub body: String,
/// The label of the button, for a template with a link.
#[serde(default)]
pub action_label: Option<String>,
/// The footer.
#[serde(default)]
pub footer: Option<String>,
}
impl MessageTemplateLayout {
/// A layout text with a subject and a body; the other parts are left
/// empty.
pub fn new(subject: impl Into<String>, body: impl Into<String>) -> Self {
Self {
subject: subject.into(),
preheader: None,
heading: None,
body: body.into(),
action_label: None,
footer: None,
}
}
/// Set the preview text.
#[must_use]
pub fn preheader(mut self, preheader: impl Into<String>) -> Self {
self.preheader = Some(preheader.into());
self
}
/// Set the heading.
#[must_use]
pub fn heading(mut self, heading: impl Into<String>) -> Self {
self.heading = Some(heading.into());
self
}
/// Set the button's label.
#[must_use]
pub fn action_label(mut self, action_label: impl Into<String>) -> Self {
self.action_label = Some(action_label.into());
self
}
/// Set the footer.
#[must_use]
pub fn footer(mut self, footer: impl Into<String>) -> Self {
self.footer = Some(footer.into());
self
}
}
/// A text written as a whole HTML document.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MessageTemplateHtml {
/// The subject line.
pub subject: String,
/// The HTML document.
pub html: String,
}
impl MessageTemplateHtml {
/// An HTML text with a subject.
pub fn new(subject: impl Into<String>, html: impl Into<String>) -> Self {
Self {
subject: subject.into(),
html: html.into(),
}
}
}
/// Where one language of a template takes its text from.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MessageTemplateLanguageSummary {
/// The language: `en`, `de`, `fr`, `es`, `it`, `nl`, `pt` or `pl`.
pub language: String,
/// `shop`, `platform` or `built_in`.
pub source: String,
/// `layout` or `html`.
pub mode: String,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One template in a list.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MessageTemplateSummary {
/// The template's stable id, for example `reset_password`.
pub id: String,
/// `email`.
pub channel: String,
/// Who receives it: `dashboard_user`, `operator`, `buyer` or
/// `buyer_account`.
pub audience: String,
/// Where its text may be stored: `platform`, `merchant`, `shop`.
#[serde(default)]
pub editable_scopes: Vec<String>,
/// The variable the layout's button opens, if the template has a link.
#[serde(default)]
pub action_variable: Option<String>,
/// Whether that link can never be left out.
#[serde(default)]
pub action_required: bool,
/// Every language, in the order of the list's `languages`.
#[serde(default)]
pub languages: Vec<MessageTemplateLanguageSummary>,
/// The languages with a text stored at the requested scope.
#[serde(default)]
pub customised_languages: Vec<String>,
/// How many shops store a text of their own, in a platform list; `None`
/// otherwise.
#[serde(default)]
pub shops_customised: Option<i64>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// Every template that can be edited at one scope.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MessageTemplateList {
/// `platform`, `merchant` or `shop`.
pub scope: String,
/// The shop's profile id, or `platform`.
pub scope_id: String,
/// Every language a text can be written in.
#[serde(default)]
pub languages: Vec<String>,
/// The language a message is written in when nothing about its
/// recipient names one.
pub default_language: String,
/// The templates the caller may read.
#[serde(default)]
pub templates: Vec<MessageTemplateSummary>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// A variable a template's text can use.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MessageTemplateVariable {
/// The variable's name.
pub name: String,
/// Its alias in the text.
pub alias: String,
/// Whether every text must use it.
pub required: bool,
/// A sample value, used in previews.
pub sample: String,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// Who last stored a text.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MessageTemplateActor {
/// The user's id.
pub id: String,
/// The user's name.
#[serde(default)]
pub name: Option<String>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// A text stored at the requested scope.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MessageTemplateStored {
/// The text.
pub content: MessageTemplateContent,
/// Its revision; send it back as `expected_revision` to refuse a save
/// over someone else's change.
pub revision: i64,
/// When it was stored.
pub updated_at: String,
/// Who stored it.
#[serde(default)]
pub updated_by: Option<MessageTemplateActor>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// What applies without a text of the scope's own.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MessageTemplateInherited {
/// The text.
pub content: MessageTemplateContent,
/// `shop`, `platform` or `built_in`.
pub source: String,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One language of a template at one scope.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MessageTemplateLanguage {
/// The language: `en`, `de`, `fr`, `es`, `it`, `nl`, `pt` or `pl`.
pub language: String,
/// The scope's own text, when one is stored.
#[serde(default)]
pub own: Option<MessageTemplateStored>,
/// What applies without `own`.
pub inherited: MessageTemplateInherited,
/// The text the platform ships.
pub built_in: MessageTemplateContent,
/// Which layer the text in force comes from: `shop`, `platform` or
/// `built_in`.
pub effective_source: String,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One template, its variables and its text in every language.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MessageTemplateDetail {
/// The template's stable id.
pub id: String,
/// `email`.
pub channel: String,
/// Who receives it: `dashboard_user`, `operator`, `buyer` or
/// `buyer_account`.
pub audience: String,
/// Where its text may be stored: `platform`, `merchant`, `shop`.
#[serde(default)]
pub editable_scopes: Vec<String>,
/// The variable the layout's button opens, if the template has a link.
#[serde(default)]
pub action_variable: Option<String>,
/// Whether that link can never be left out.
#[serde(default)]
pub action_required: bool,
/// The variables a text can use.
#[serde(default)]
pub variables: Vec<MessageTemplateVariable>,
/// The text in every language.
#[serde(default)]
pub languages: Vec<MessageTemplateLanguage>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// A template rendered with sample values.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MessageTemplatePreview {
/// The language rendered.
pub language: String,
/// The rendered subject.
pub subject: String,
/// The rendered HTML.
pub html: String,
/// The rendered plain text.
pub text: String,
/// What the text may get wrong, such as a missing required variable.
#[serde(default)]
pub warnings: Vec<String>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// Where a test message was sent.
#[derive(Clone, Deserialize)]
#[non_exhaustive]
pub struct SendTestMessageResponse {
/// The address the test was sent to.
pub sent_to: String,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
impl fmt::Debug for SendTestMessageResponse {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("SendTestMessageResponse")
.field("sent_to", &"<redacted>")
.finish_non_exhaustive()
}
}