@mistriwork/cloudflare 1.0.0-rc.35 → 1.0.0-rc.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/mail.js +26 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,7 +33,8 @@ and `scheduled` (a once-a-minute `/readyz` that starts the instance if a host re
|
|
|
33
33
|
|
|
34
34
|
`forwardEmail(message, env, { binding, instance, secretEnv, parse })` signs an inbound message (HMAC-SHA-256 over
|
|
35
35
|
`<timestamp>.<body>`) and posts it to the App's `/api/mail/inbound` through the Durable Object. Hand it the parser:
|
|
36
|
-
`parse: (raw) => PostalMime.parse(raw
|
|
36
|
+
`parse: (raw) => PostalMime.parse(raw)`; this package carries none. An attachment's bytes are sent as base64
|
|
37
|
+
whichever way the parser hands them (an `ArrayBuffer`, a typed array, or base64 text already). A 2xx or a replayed delivery (409) is done; a 404, 413, 400 or 422 rejects the message with
|
|
37
38
|
a reason; anything else (401, 403, 429, 5xx) throws, so a signing or configuration fault is retried and logged rather
|
|
38
39
|
than finishing as if the mail were forwarded.
|
|
39
40
|
|
package/dist/mail.js
CHANGED
|
@@ -11,6 +11,27 @@ export async function signMail(secret, timestamp, body) {
|
|
|
11
11
|
const key = await crypto.subtle.importKey('raw', new TextEncoder().encode(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);
|
|
12
12
|
return `v1=${hex(await crypto.subtle.sign('HMAC', key, new TextEncoder().encode(`${timestamp}.${body}`)))}`;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* An attachment's bytes as the App takes them: base64. postal-mime hands an ArrayBuffer unless it is told
|
|
16
|
+
* `attachmentEncoding: 'base64'`, and an ArrayBuffer is `{}` in JSON, so every attachment arrived empty; bytes are
|
|
17
|
+
* encoded here, and a string is taken as base64 already.
|
|
18
|
+
*/
|
|
19
|
+
function attachmentContent(content) {
|
|
20
|
+
if (typeof content === 'string')
|
|
21
|
+
return content;
|
|
22
|
+
const bytes = content instanceof ArrayBuffer
|
|
23
|
+
? new Uint8Array(content)
|
|
24
|
+
: ArrayBuffer.isView(content)
|
|
25
|
+
? new Uint8Array(content.buffer, content.byteOffset, content.byteLength)
|
|
26
|
+
: undefined;
|
|
27
|
+
if (!bytes)
|
|
28
|
+
throw new Error('an attachment carried neither bytes nor base64 text');
|
|
29
|
+
/* A chunk at a time: String.fromCharCode over a whole large file overflows the argument list. */
|
|
30
|
+
let binary = '';
|
|
31
|
+
for (let at = 0; at < bytes.length; at += 0x8000)
|
|
32
|
+
binary += String.fromCharCode(...bytes.subarray(at, at + 0x8000));
|
|
33
|
+
return btoa(binary);
|
|
34
|
+
}
|
|
14
35
|
function mailBody(message, mail) {
|
|
15
36
|
return JSON.stringify({
|
|
16
37
|
recipient: message.to,
|
|
@@ -24,7 +45,11 @@ function mailBody(message, mail) {
|
|
|
24
45
|
text: mail.text,
|
|
25
46
|
html: mail.html,
|
|
26
47
|
headers: Object.fromEntries(mail.headers.map((h) => [h.key, h.value])),
|
|
27
|
-
attachments: mail.attachments.map((a) => ({
|
|
48
|
+
attachments: mail.attachments.map((a) => ({
|
|
49
|
+
name: a.filename ?? 'attachment',
|
|
50
|
+
type: a.mimeType,
|
|
51
|
+
content: attachmentContent(a.content),
|
|
52
|
+
})),
|
|
28
53
|
});
|
|
29
54
|
}
|
|
30
55
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mistriwork/cloudflare",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.37",
|
|
4
4
|
"description": "A mistri App on Cloudflare Containers: the Container class and Worker handlers `mistri deploy init cloudflare` writes against, so a fix to the glue is a package upgrade.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|