worker 0.8.2

A Rust SDK for writing Cloudflare Workers.
Documentation
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
// Generated by ts-gen. Do not edit.

#[allow(dead_code)]
use ::web_sys::Event;
#[allow(dead_code)]
use ::web_sys::Headers;
#[allow(dead_code)]
use ::web_sys::ReadableStream;
#[allow(unused_imports)]
use js_sys::*;
#[allow(unused_imports)]
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
    # [wasm_bindgen (extends = Event , extends = Object)]
    #[derive(Debug, Clone, PartialEq, Eq)]
    pub type ExtendableEvent;
    #[doc = " The **`ExtendableEvent.waitUntil()`** method tells the event dispatcher that work is ongoing."]
    #[doc = ""]
    #[doc = " [MDN Reference](https://developer.mozilla.org/docs/Web/API/ExtendableEvent/waitUntil)"]
    #[wasm_bindgen(method, js_name = "waitUntil")]
    pub fn wait_until(this: &ExtendableEvent, promise: &Promise);
}
#[wasm_bindgen]
extern "C" {
    # [wasm_bindgen (extends = Object)]
    #[derive(Debug, Clone, PartialEq, Eq)]
    pub type EmailSendResult;
    #[doc = " The Email Message ID"]
    #[wasm_bindgen(method, getter, js_name = "messageId")]
    pub fn message_id(this: &EmailSendResult) -> String;
    #[wasm_bindgen(method, setter, js_name = "messageId")]
    pub fn set_message_id(this: &EmailSendResult, val: &str);
}
impl EmailSendResult {
    #[doc = " * `message_id` - The Email Message ID"]
    pub fn new(message_id: &str) -> EmailSendResult {
        let inner: Self = JsCast::unchecked_into(js_sys::Object::new());
        inner.set_message_id(message_id);
        inner
    }
}
#[wasm_bindgen]
extern "C" {
    # [wasm_bindgen (extends = email :: EmailMessage , extends = Object)]
    #[derive(Debug, Clone, PartialEq, Eq)]
    pub type ForwardableEmailMessage;
    #[doc = " Stream of the email message content."]
    #[wasm_bindgen(method, getter)]
    pub fn raw(this: &ForwardableEmailMessage) -> ReadableStream;
    #[doc = " An [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers)."]
    #[wasm_bindgen(method, getter)]
    pub fn headers(this: &ForwardableEmailMessage) -> Headers;
    #[doc = " Size of the email message content."]
    #[wasm_bindgen(method, getter, js_name = "rawSize")]
    pub fn raw_size(this: &ForwardableEmailMessage) -> f64;
    #[doc = " Reject this email message by returning a permanent SMTP error back to the connecting client including the given reason."]
    #[doc = ""]
    #[doc = " * `reason` - The reject reason."]
    #[doc = ""]
    #[doc = " Returns: void"]
    #[wasm_bindgen(method, js_name = "setReject")]
    pub fn set_reject(this: &ForwardableEmailMessage, reason: &str);
    #[doc = " Forward this email message to a verified destination address of the account."]
    #[doc = ""]
    #[doc = " * `rcptTo` - Verified destination address."]
    #[doc = " * `headers` - A [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers)."]
    #[doc = ""]
    #[doc = " Returns: A promise that resolves when the email message is forwarded."]
    #[wasm_bindgen(method, catch)]
    pub async fn forward(
        this: &ForwardableEmailMessage,
        rcpt_to: &str,
    ) -> Result<EmailSendResult, Error>;
    #[doc = " Forward this email message to a verified destination address of the account."]
    #[doc = ""]
    #[doc = " * `rcptTo` - Verified destination address."]
    #[doc = " * `headers` - A [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers)."]
    #[doc = ""]
    #[doc = " Returns: A promise that resolves when the email message is forwarded."]
    #[wasm_bindgen(method, catch, js_name = "forward")]
    pub async fn forward_with_headers(
        this: &ForwardableEmailMessage,
        rcpt_to: &str,
        headers: &Headers,
    ) -> Result<EmailSendResult, Error>;
    #[doc = " Reply to the sender of this email message with a new EmailMessage object."]
    #[doc = ""]
    #[doc = " * `message` - The reply message."]
    #[doc = ""]
    #[doc = " Returns: A promise that resolves when the email message is replied."]
    #[wasm_bindgen(method, catch)]
    pub async fn reply(
        this: &ForwardableEmailMessage,
        message: &email::EmailMessage,
    ) -> Result<EmailSendResult, Error>;
}
#[wasm_bindgen]
extern "C" {
    # [wasm_bindgen (extends = Object)]
    #[derive(Debug, Clone, PartialEq, Eq)]
    pub type EmailAttachment;
    #[wasm_bindgen(method, getter)]
    pub fn disposition(this: &EmailAttachment) -> DispositionKind;
    #[wasm_bindgen(method, setter)]
    pub fn set_disposition(this: &EmailAttachment, val: &str);
    #[wasm_bindgen(method, getter, js_name = "contentId")]
    pub fn content_id(this: &EmailAttachment) -> Option<String>;
    #[wasm_bindgen(method, setter, js_name = "contentId")]
    pub fn set_content_id(this: &EmailAttachment, val: &str);
    #[wasm_bindgen(method, getter)]
    pub fn filename(this: &EmailAttachment) -> String;
    #[wasm_bindgen(method, setter)]
    pub fn set_filename(this: &EmailAttachment, val: &str);
    #[wasm_bindgen(method, getter, js_name = "type")]
    pub fn type_(this: &EmailAttachment) -> String;
    #[wasm_bindgen(method, setter)]
    pub fn set_type(this: &EmailAttachment, val: &str);
    #[wasm_bindgen(method, getter)]
    pub fn content(this: &EmailAttachment) -> ContentKind;
    #[wasm_bindgen(method, setter)]
    pub fn set_content(this: &EmailAttachment, val: &str);
    #[wasm_bindgen(method, setter, js_name = "content")]
    pub fn set_content_with_array_buffer(this: &EmailAttachment, val: &ArrayBuffer);
    #[wasm_bindgen(method, setter, js_name = "content")]
    pub fn set_content_with_typed_array<T: ::js_sys::TypedArray>(this: &EmailAttachment, val: &T);
}
impl EmailAttachment {
    #[doc = " ## Inlined fields"]
    #[doc = ""]
    #[doc = " * `disposition: \"inline\"`"]
    pub fn new_inline(
        content_id: &str,
        filename: &str,
        r#type: &str,
        content: &str,
    ) -> EmailAttachment {
        let inner: Self = JsCast::unchecked_into(js_sys::Object::new());
        inner.set_disposition("inline");
        inner.set_content_id(content_id);
        inner.set_filename(filename);
        inner.set_type(r#type);
        inner.set_content(content);
        inner
    }
    #[doc = " ## Inlined fields"]
    #[doc = ""]
    #[doc = " * `disposition: \"inline\"`"]
    pub fn new_inline_with_array_buffer(
        content_id: &str,
        filename: &str,
        r#type: &str,
        content: &ArrayBuffer,
    ) -> EmailAttachment {
        let inner: Self = JsCast::unchecked_into(js_sys::Object::new());
        inner.set_disposition("inline");
        inner.set_content_id(content_id);
        inner.set_filename(filename);
        inner.set_type(r#type);
        inner.set_content_with_array_buffer(content);
        inner
    }
    #[doc = " ## Inlined fields"]
    #[doc = ""]
    #[doc = " * `disposition: \"inline\"`"]
    pub fn new_inline_with_typed_array<T: ::js_sys::TypedArray>(
        content_id: &str,
        filename: &str,
        r#type: &str,
        content: &T,
    ) -> EmailAttachment {
        let inner: Self = JsCast::unchecked_into(js_sys::Object::new());
        inner.set_disposition("inline");
        inner.set_content_id(content_id);
        inner.set_filename(filename);
        inner.set_type(r#type);
        inner.set_content_with_typed_array(content);
        inner
    }
    #[doc = " ## Inlined fields"]
    #[doc = ""]
    #[doc = " * `disposition: \"attachment\"`"]
    pub fn new_attachment(filename: &str, r#type: &str, content: &str) -> EmailAttachment {
        Self::builder_attachment(filename, r#type, content).build()
    }
    #[doc = " ## Inlined fields"]
    #[doc = ""]
    #[doc = " * `disposition: \"attachment\"`"]
    pub fn new_attachment_with_array_buffer(
        filename: &str,
        r#type: &str,
        content: &ArrayBuffer,
    ) -> EmailAttachment {
        Self::builder_attachment_with_array_buffer(filename, r#type, content).build()
    }
    #[doc = " ## Inlined fields"]
    #[doc = ""]
    #[doc = " * `disposition: \"attachment\"`"]
    pub fn new_attachment_with_typed_array<T: ::js_sys::TypedArray>(
        filename: &str,
        r#type: &str,
        content: &T,
    ) -> EmailAttachment {
        Self::builder_attachment_with_typed_array(filename, r#type, content).build()
    }
    #[doc = " ## Inlined fields"]
    #[doc = ""]
    #[doc = " * `disposition: \"attachment\"`"]
    pub fn builder_attachment(
        filename: &str,
        r#type: &str,
        content: &str,
    ) -> EmailAttachmentBuilder {
        let inner: Self = JsCast::unchecked_into(js_sys::Object::new());
        inner.set_disposition("attachment");
        inner.set_filename(filename);
        inner.set_type(r#type);
        inner.set_content(content);
        EmailAttachmentBuilder { inner }
    }
    #[doc = " ## Inlined fields"]
    #[doc = ""]
    #[doc = " * `disposition: \"attachment\"`"]
    pub fn builder_attachment_with_array_buffer(
        filename: &str,
        r#type: &str,
        content: &ArrayBuffer,
    ) -> EmailAttachmentBuilder {
        let inner: Self = JsCast::unchecked_into(js_sys::Object::new());
        inner.set_disposition("attachment");
        inner.set_filename(filename);
        inner.set_type(r#type);
        inner.set_content_with_array_buffer(content);
        EmailAttachmentBuilder { inner }
    }
    #[doc = " ## Inlined fields"]
    #[doc = ""]
    #[doc = " * `disposition: \"attachment\"`"]
    pub fn builder_attachment_with_typed_array<T: ::js_sys::TypedArray>(
        filename: &str,
        r#type: &str,
        content: &T,
    ) -> EmailAttachmentBuilder {
        let inner: Self = JsCast::unchecked_into(js_sys::Object::new());
        inner.set_disposition("attachment");
        inner.set_filename(filename);
        inner.set_type(r#type);
        inner.set_content_with_typed_array(content);
        EmailAttachmentBuilder { inner }
    }
}
pub struct EmailAttachmentBuilder {
    inner: EmailAttachment,
}
impl EmailAttachmentBuilder {
    pub fn content_id(self, val: &str) -> Self {
        self.inner.set_content_id(val);
        self
    }
    pub fn build(self) -> EmailAttachment {
        self.inner
    }
}
#[wasm_bindgen]
extern "C" {
    # [wasm_bindgen (extends = Object)]
    #[derive(Debug, Clone, PartialEq, Eq)]
    pub type EmailAddress;
    #[wasm_bindgen(method, getter)]
    pub fn name(this: &EmailAddress) -> String;
    #[wasm_bindgen(method, setter)]
    pub fn set_name(this: &EmailAddress, val: &str);
    #[wasm_bindgen(method, getter)]
    pub fn email(this: &EmailAddress) -> String;
    #[wasm_bindgen(method, setter)]
    pub fn set_email(this: &EmailAddress, val: &str);
}
impl EmailAddress {
    pub fn new(name: &str, email: &str) -> EmailAddress {
        let inner: Self = JsCast::unchecked_into(js_sys::Object::new());
        inner.set_name(name);
        inner.set_email(email);
        inner
    }
}
#[wasm_bindgen]
extern "C" {
    # [wasm_bindgen (extends = Object)]
    #[derive(Debug, Clone, PartialEq, Eq)]
    pub type SendEmail;
    #[wasm_bindgen(method, catch)]
    pub async fn send(
        this: &SendEmail,
        message: &email::EmailMessage,
    ) -> Result<EmailSendResult, Error>;
    #[wasm_bindgen(method, catch, js_name = "send")]
    pub async fn send_with_builder(
        this: &SendEmail,
        builder: &SendEmailBuilder,
    ) -> Result<EmailSendResult, Error>;
}
#[wasm_bindgen]
extern "C" {
    # [wasm_bindgen (extends = Object)]
    #[derive(Debug, Clone, PartialEq, Eq)]
    pub type SendEmailBuilder;
    #[wasm_bindgen(method, getter)]
    pub fn from(this: &SendEmailBuilder) -> FromKind;
    #[wasm_bindgen(method, setter)]
    pub fn set_from(this: &SendEmailBuilder, val: &str);
    #[wasm_bindgen(method, setter, js_name = "from")]
    pub fn set_from_with_email_address(this: &SendEmailBuilder, val: &EmailAddress);
    #[wasm_bindgen(method, getter)]
    pub fn to(this: &SendEmailBuilder) -> ToKind;
    #[wasm_bindgen(method, setter)]
    pub fn set_to(this: &SendEmailBuilder, val: &str);
    #[wasm_bindgen(method, setter, slice_to_array, js_name = "to")]
    pub fn set_to_with_slice(this: &SendEmailBuilder, val: &[String]);
    #[wasm_bindgen(method, getter)]
    pub fn subject(this: &SendEmailBuilder) -> String;
    #[wasm_bindgen(method, setter)]
    pub fn set_subject(this: &SendEmailBuilder, val: &str);
    #[wasm_bindgen(method, getter, js_name = "replyTo")]
    pub fn reply_to(this: &SendEmailBuilder) -> Option<FromKind>;
    #[wasm_bindgen(method, setter, js_name = "replyTo")]
    pub fn set_reply_to(this: &SendEmailBuilder, val: &str);
    #[wasm_bindgen(method, setter, js_name = "replyTo")]
    pub fn set_reply_to_with_email_address(this: &SendEmailBuilder, val: &EmailAddress);
    #[wasm_bindgen(method, getter)]
    pub fn cc(this: &SendEmailBuilder) -> Option<ToKind>;
    #[wasm_bindgen(method, setter)]
    pub fn set_cc(this: &SendEmailBuilder, val: &str);
    #[wasm_bindgen(method, setter, slice_to_array, js_name = "cc")]
    pub fn set_cc_with_slice(this: &SendEmailBuilder, val: &[String]);
    #[wasm_bindgen(method, getter)]
    pub fn bcc(this: &SendEmailBuilder) -> Option<ToKind>;
    #[wasm_bindgen(method, setter)]
    pub fn set_bcc(this: &SendEmailBuilder, val: &str);
    #[wasm_bindgen(method, setter, slice_to_array, js_name = "bcc")]
    pub fn set_bcc_with_slice(this: &SendEmailBuilder, val: &[String]);
    #[wasm_bindgen(method, getter)]
    pub fn headers(this: &SendEmailBuilder) -> Option<Object<JsString>>;
    #[wasm_bindgen(method, setter)]
    pub fn set_headers(this: &SendEmailBuilder, val: &Object<JsString>);
    #[wasm_bindgen(method, getter)]
    pub fn text(this: &SendEmailBuilder) -> Option<String>;
    #[wasm_bindgen(method, setter)]
    pub fn set_text(this: &SendEmailBuilder, val: &str);
    #[wasm_bindgen(method, getter)]
    pub fn html(this: &SendEmailBuilder) -> Option<String>;
    #[wasm_bindgen(method, setter)]
    pub fn set_html(this: &SendEmailBuilder, val: &str);
    #[wasm_bindgen(method, getter)]
    pub fn attachments(this: &SendEmailBuilder) -> Option<Vec<EmailAttachment>>;
    #[wasm_bindgen(method, setter, slice_to_array)]
    pub fn set_attachments(this: &SendEmailBuilder, val: &[EmailAttachment]);
}
impl SendEmailBuilder {
    pub fn new(from: &str, to: &str, subject: &str) -> SendEmailBuilder {
        Self::builder(from, to, subject).build()
    }
    pub fn new_with_str_and_slice(from: &str, to: &[String], subject: &str) -> SendEmailBuilder {
        Self::builder_with_str_and_slice(from, to, subject).build()
    }
    pub fn new_with_email_address_and_str(
        from: &EmailAddress,
        to: &str,
        subject: &str,
    ) -> SendEmailBuilder {
        Self::builder_with_email_address_and_str(from, to, subject).build()
    }
    pub fn new_with_email_address_and_slice(
        from: &EmailAddress,
        to: &[String],
        subject: &str,
    ) -> SendEmailBuilder {
        Self::builder_with_email_address_and_slice(from, to, subject).build()
    }
    pub fn builder(from: &str, to: &str, subject: &str) -> SendEmailBuilderBuilder {
        let inner: Self = JsCast::unchecked_into(js_sys::Object::new());
        inner.set_from(from);
        inner.set_to(to);
        inner.set_subject(subject);
        SendEmailBuilderBuilder { inner }
    }
    pub fn builder_with_str_and_slice(
        from: &str,
        to: &[String],
        subject: &str,
    ) -> SendEmailBuilderBuilder {
        let inner: Self = JsCast::unchecked_into(js_sys::Object::new());
        inner.set_from(from);
        inner.set_to_with_slice(to);
        inner.set_subject(subject);
        SendEmailBuilderBuilder { inner }
    }
    pub fn builder_with_email_address_and_str(
        from: &EmailAddress,
        to: &str,
        subject: &str,
    ) -> SendEmailBuilderBuilder {
        let inner: Self = JsCast::unchecked_into(js_sys::Object::new());
        inner.set_from_with_email_address(from);
        inner.set_to(to);
        inner.set_subject(subject);
        SendEmailBuilderBuilder { inner }
    }
    pub fn builder_with_email_address_and_slice(
        from: &EmailAddress,
        to: &[String],
        subject: &str,
    ) -> SendEmailBuilderBuilder {
        let inner: Self = JsCast::unchecked_into(js_sys::Object::new());
        inner.set_from_with_email_address(from);
        inner.set_to_with_slice(to);
        inner.set_subject(subject);
        SendEmailBuilderBuilder { inner }
    }
}
pub struct SendEmailBuilderBuilder {
    inner: SendEmailBuilder,
}
impl SendEmailBuilderBuilder {
    pub fn reply_to(self, val: &str) -> Self {
        self.inner.set_reply_to(val);
        self
    }
    pub fn reply_to_with_email_address(self, val: &EmailAddress) -> Self {
        self.inner.set_reply_to_with_email_address(val);
        self
    }
    pub fn cc(self, val: &str) -> Self {
        self.inner.set_cc(val);
        self
    }
    pub fn cc_with_slice(self, val: &[String]) -> Self {
        self.inner.set_cc_with_slice(val);
        self
    }
    pub fn bcc(self, val: &str) -> Self {
        self.inner.set_bcc(val);
        self
    }
    pub fn bcc_with_slice(self, val: &[String]) -> Self {
        self.inner.set_bcc_with_slice(val);
        self
    }
    pub fn headers(self, val: &Object<JsString>) -> Self {
        self.inner.set_headers(val);
        self
    }
    pub fn text(self, val: &str) -> Self {
        self.inner.set_text(val);
        self
    }
    pub fn html(self, val: &str) -> Self {
        self.inner.set_html(val);
        self
    }
    pub fn attachments(self, val: &[EmailAttachment]) -> Self {
        self.inner.set_attachments(val);
        self
    }
    pub fn build(self) -> SendEmailBuilder {
        self.inner
    }
}
#[wasm_bindgen]
extern "C" {
    # [wasm_bindgen (extends = ExtendableEvent , extends = Object)]
    #[derive(Debug, Clone, PartialEq, Eq)]
    pub type EmailEvent;
    #[wasm_bindgen(method, getter)]
    pub fn message(this: &EmailEvent) -> ForwardableEmailMessage;
}
pub mod email {
    use super::*;
    use js_sys::*;
    use wasm_bindgen::prelude::*;
    #[wasm_bindgen(module = "cloudflare:email")]
    extern "C" {
        # [wasm_bindgen (extends = Object)]
        #[derive(Debug, Clone, PartialEq, Eq)]
        pub type EmailMessage;
        #[wasm_bindgen(constructor, catch)]
        pub fn new(from: &str, to: &str, raw: &str) -> Result<EmailMessage, Error>;
        #[wasm_bindgen(constructor, catch, js_name = "EmailMessage")]
        pub fn new_with_readable_stream(
            from: &str,
            to: &str,
            raw: &ReadableStream,
        ) -> Result<EmailMessage, Error>;
        #[doc = " Envelope From attribute of the email message."]
        #[wasm_bindgen(method, getter)]
        pub fn from(this: &EmailMessage) -> String;
        #[doc = " Envelope To attribute of the email message."]
        #[wasm_bindgen(method, getter)]
        pub fn to(this: &EmailMessage) -> String;
    }
}
#[wasm_bindgen]
pub enum DispositionKind {
    Inline = "inline",
    Attachment = "attachment",
}
#[wasm_bindgen]
pub enum ContentKind {
    String(String),
    ArrayBuffer(ArrayBuffer),
    Uint8Array(Uint8Array),
}
#[wasm_bindgen]
pub enum FromKind {
    String(String),
    EmailAddress(EmailAddress),
}
#[wasm_bindgen]
pub enum ToKind {
    String(String),
    VecOfString(Array<String>),
}