@yaks/resend 0.0.0-stage → 0.2.36

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.
Files changed (59) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +96 -2
  3. package/_dist/api.d.ts +2 -0
  4. package/_dist/api.d.ts.map +1 -0
  5. package/_dist/box-queue.d.ts +30 -0
  6. package/_dist/box-queue.d.ts.map +1 -0
  7. package/_dist/box-wire.d.ts +35 -0
  8. package/_dist/box-wire.d.ts.map +1 -0
  9. package/_dist/domains.d.ts +55 -0
  10. package/_dist/domains.d.ts.map +1 -0
  11. package/_dist/graph.d.ts +8 -0
  12. package/_dist/graph.d.ts.map +1 -0
  13. package/_dist/mod.d.ts +5 -0
  14. package/_dist/mod.d.ts.map +1 -0
  15. package/_dist/options.d.ts +19 -0
  16. package/_dist/options.d.ts.map +1 -0
  17. package/_dist/receive.d.ts +45 -0
  18. package/_dist/receive.d.ts.map +1 -0
  19. package/_dist/routes.d.ts +8 -0
  20. package/_dist/routes.d.ts.map +1 -0
  21. package/_dist/sender.d.ts +19 -0
  22. package/_dist/sender.d.ts.map +1 -0
  23. package/_dist/service.d.ts +10 -0
  24. package/_dist/service.d.ts.map +1 -0
  25. package/api.js +19 -0
  26. package/api.js.map +1 -0
  27. package/api.ts +27 -0
  28. package/box-queue.js +161 -0
  29. package/box-queue.js.map +1 -0
  30. package/box-queue.ts +188 -0
  31. package/box-wire.js +18 -0
  32. package/box-wire.js.map +1 -0
  33. package/box-wire.ts +57 -0
  34. package/deno.json +1 -0
  35. package/domains.js +226 -0
  36. package/domains.js.map +1 -0
  37. package/domains.ts +300 -0
  38. package/graph.js +31 -0
  39. package/graph.js.map +1 -0
  40. package/graph.ts +54 -0
  41. package/mod.js +5 -0
  42. package/mod.js.map +1 -0
  43. package/mod.ts +5 -0
  44. package/options.js +19 -0
  45. package/options.js.map +1 -0
  46. package/options.ts +48 -0
  47. package/package.json +54 -4
  48. package/receive.js +206 -0
  49. package/receive.js.map +1 -0
  50. package/receive.ts +266 -0
  51. package/routes.js +43 -0
  52. package/routes.js.map +1 -0
  53. package/routes.ts +45 -0
  54. package/sender.js +101 -0
  55. package/sender.js.map +1 -0
  56. package/sender.ts +124 -0
  57. package/service.js +102 -0
  58. package/service.js.map +1 -0
  59. package/service.ts +107 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Jeff Peterson
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,97 @@
1
- # Temporary Holding Version
1
+ # @yaks/resend
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Resend sending, signed delivery receipts, and receiving through the portable
4
+ mail boundary from `@yaks/host`. Letters and their delivery outcomes belong to
5
+ `@yaks/mail`; provider email ids remain here.
6
+
7
+ `resend({token, base?, fetch?, tags?})` returns a `Sender`. Supply a separate
8
+ `sending_access` key per service. Resend restricts a key to one domain or to
9
+ none, so restrict it only for a service that sends from a single domain; the box
10
+ sends from bot.yak.sh and yaks.app, and its key is unrestricted. A refused key
11
+ (401, 403) rejects as `Unsent`, so its letters wait for a repaired key instead
12
+ of bouncing. A validation refusal (400, 422) that names a reader, as Resend
13
+ answers a letter to example.com, rejects as `Undeliverable`: the letter bounces
14
+ with Resend's message as its reason. Any other refusal rejects with the status
15
+ and Resend's error name, never its body. The envelope supplies the sender's
16
+ address, including a customer's verified custom domain. There is no fixed
17
+ platform domain.
18
+
19
+ `Message.id` is the caller's letter UUID. It travels as the `yak_letter` tag;
20
+ `event(request, webhookSecret)` verifies Resend's signed, fresh webhook, and
21
+ `receipt(event)` returns that UUID and the RFC Message-ID. The send response's
22
+ API email id is never returned as a thread id. A host can route the same
23
+ verified receipt into its own graph door. Receipt writes are idempotent and
24
+ retry when their letter has not yet committed.
25
+
26
+ ## As a plugin
27
+
28
+ Listed in a config, the package lends its host the sender named `resend`
29
+ (`./graph`), which `@yaks/mail` selects with `sender: {"via": "resend"}`. Its
30
+ options are the sender's: `token`, and `base`, `fetch` and `tags`. The sender
31
+ reads them at every letter, so a token set after start-up is used for the next
32
+ one, and until there is a token a letter waits. With `receipts`, it also answers
33
+ the webhook Resend posts delivery receipts to (`./routes`, default
34
+ `POST /mail/resend`), verifies the endpoint's signature, and fills
35
+ `mail.message_id` on the letter it names. A receipt counts only where it carries
36
+ every one of the sender's `tags`, so several hosts can share one Resend account.
37
+ A host that routes receipts itself, such as a Worker, asks the graph facet for
38
+ the notices named `resend` instead: they verify a request with the same
39
+ `receipts.secret` and answer the receipt and the letter's tags.
40
+
41
+ ```json
42
+ {
43
+ "use": "@yaks/resend",
44
+ "with": {
45
+ "token": { "secret": "RESEND_TOKEN" },
46
+ "tags": { "yak_host": "box" },
47
+ "receipts": { "secret": { "secret": "RESEND_WEBHOOK_SECRET" } },
48
+ "domains": { "token": { "secret": "RESEND_DOMAINS_TOKEN" } }
49
+ }
50
+ }
51
+ ```
52
+
53
+ ## Mail domains
54
+
55
+ `domains({token, base?, fetch?})` lends `@yaks/host`'s `MailDomains` over
56
+ Resend's Domains API: `setup(name)` adds a domain with sending and receiving
57
+ both on, or turns on whichever an existing one lacks; `read(name)` answers its
58
+ records, each fully qualified with whether Resend has `arrived` it, and starts
59
+ Resend's check when some record has not arrived and none is being checked;
60
+ `remove(name)` deletes it. A caller names a domain only by its name: Resend's id
61
+ is looked up at each call and never returned. Managing domains needs a
62
+ `full_access` key; a sending key is refused. As a plugin, the graph facet lends
63
+ these as the mail domains named `resend`, with the key from `domains.token` read
64
+ at each call, and `base` and `fetch` shared with the sender. `./testing` holds
65
+ `domainsApi()`, a stand-in for the API that names its records the way Resend
66
+ does.
67
+
68
+ `received({token, base?, fetch?}, emailId)` retrieves incoming message content
69
+ and attachments, and returns one neutral `Incoming` per recipient its To, Cc and
70
+ Bcc name or Resend received it for. Download URLs receive no API credential. A
71
+ sending-only key cannot retrieve mail; Resend offers no receiving-only API
72
+ permission, so a host limited to scoped keys keeps receiving elsewhere.
73
+ `verified` is the API's trusted DKIM verdict, which passes only for the From
74
+ domain's signature, and `vouched` its DMARC pass; supplied message headers
75
+ cannot establish authorship. With `receiving: {token}` among its options, the
76
+ `resend` notices answer a signed `email.received` with the `letters` it carried,
77
+ read with that key; without it, the event is acknowledged unread. See
78
+ [receiving authentication](https://resend.com/docs/api-reference/emails/retrieve-received-email)
79
+ and
80
+ [API key permissions](https://resend.com/docs/api-reference/api-keys/create-api-key).
81
+
82
+ ```ts
83
+ import { receipt } from '@yaks/resend'
84
+ import { equal } from '@yaks/testing'
85
+
86
+ equal(
87
+ receipt({
88
+ type: 'email.sent',
89
+ data: {
90
+ email_id: 'provider-only',
91
+ message_id: '<thread@example.com>',
92
+ tags: { yak_letter: '21491aa7-e2c1-4631-8465-0414f7195261' },
93
+ },
94
+ }),
95
+ { letter: '21491aa7-e2c1-4631-8465-0414f7195261', id: 'thread@example.com' },
96
+ )
97
+ ```
package/_dist/api.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ /** The HTTP boundary a host supplies in place of `fetch`. */ export type Fetch = (url: string, init: RequestInit) => Promise<Response>;
2
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sources":["../api.ts"],"names":[],"mappings":"AAIA,2DAA2D,GAC3D,YAAY,SAAS,KAAK,MAAM,EAAE,MAAM,gBAAgB,QAAQ"}
@@ -0,0 +1,30 @@
1
+ import { type Bucket } from "@yaks/blob/object";
2
+ import type { DomainRecord, MailDomains } from "@yaks/host/senders";
3
+ import type { Completion, Work } from "./box-wire.js";
4
+ import type { Retrieved } from "./receive.js";
5
+ type Source = {
6
+ body: string;
7
+ url: string;
8
+ headers: [string, string][];
9
+ };
10
+ type Arrival = Pick<Request, 'text' | 'headers' | 'url'>;
11
+ type Page = {
12
+ jobs: Work[];
13
+ cursor?: string;
14
+ };
15
+ type Deliver = (incoming: Retrieved, source: Source) => Promise<void>;
16
+ type Save = (name: string, records: DomainRecord[] | null, token?: string) => Promise<void>;
17
+ export type Queue = {
18
+ domains: MailDomains;
19
+ arrival: (email: string, request: Arrival) => Promise<void>;
20
+ work: (cursor?: string, needsSender?: (name: string) => Promise<boolean>) => Promise<Page>;
21
+ complete: (completion: Completion, deliver: Deliver, save: Save) => Promise<void>;
22
+ };
23
+ type Pause = (ms: number) => Promise<void>;
24
+ export declare class MailPending extends Error {
25
+ constructor();
26
+ }
27
+ /** Operations stay in the bucket until the provider and the platform have
28
+ * both accepted them. Domain operations are idempotent by name and delivery
29
+ * is idempotent by Message-ID and recipient in the existing inbox. */ export declare let queue: (raw: Bucket, now?: () => number, pause?: Pause) => Queue;
30
+ //# sourceMappingURL=box-queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"box-queue.d.ts","sources":["../box-queue.ts"],"names":[],"mappings":"AAAA,SAAS,KAAK,MAAM,iCAA+C;AAEnE,cAAc,YAAY,EAAE,WAAW,kCAAuC;AAC9E,cAAc,UAAU,EAAO,IAAI,wBAAuB;AAC1D,cAAc,SAAS,uBAAsB;KAOxC;EAAW,MAAM,MAAM;EAAE,KAAK,MAAM;EAAE,UAAU,MAAM,EAAE,MAAM;;KAG9D,UAAU,KAAK,SAAS,SAAS,YAAY;KAC7C;EAAS,MAAM;EAAQ,SAAS,MAAM;;KACtC,WAAW,UAAU,WAAW,QAAQ,WAAW,QAAQ,IAAI;KAC/D,QACH,MAAM,MAAM,EACZ,SAAS,iBAAiB,IAAI,EAC9B,QAAQ,MAAM,KACX,QAAQ,IAAI;AACjB,YAAY;EACV,SAAS;EACT,UAAU,OAAO,MAAM,EAAE,SAAS,YAAY,QAAQ,IAAI;EAC1D,OACE,SAAS,MAAM,EACf,eAAe,MAAM,MAAM,KAAK,QAAQ,OAAO,MAC5C,QAAQ;EACb,WACE,YAAY,YACZ,SAAS,SACT,MAAM,SACH,QAAQ,IAAI;;KAGd,SAAS,IAAI,MAAM,KAAK,QAAQ,IAAI;AA0BzC,OAAO,cAAM,oBAAoB;EAC/B;AAGF;AAEA;;oEAEoE,GACpE,OAAO,YAAI,QACT,KAAK,QACL,YAAW,MAAM,EACjB,QAAO,UACN,MAgHF"}
@@ -0,0 +1,35 @@
1
+ import type { MailDomain } from "@yaks/host/senders";
2
+ import type { Retrieved } from "./receive.js";
3
+ export declare let path: string;
4
+ type DomainOp = 'setup' | 'read' | 'remove';
5
+ export type Job = {
6
+ op: DomainOp;
7
+ name: string;
8
+ } | {
9
+ op: 'receive';
10
+ email: string;
11
+ };
12
+ export type Work = {
13
+ id: string;
14
+ job: Job;
15
+ sender?: boolean;
16
+ };
17
+ export type Result = {
18
+ domain: MailDomain | null;
19
+ token?: string;
20
+ } | {
21
+ incoming: Retrieved;
22
+ };
23
+ export type Completion = {
24
+ id: string;
25
+ result: Result;
26
+ };
27
+ export declare let digest: (body: string) => Promise<string>;
28
+ type Ticket = {
29
+ method: string;
30
+ digest: string;
31
+ expires: number;
32
+ };
33
+ export declare let ticket: (secret: string, method: string, body?: string) => Promise<string>;
34
+ export declare let authorized: (secret: string, request: Pick<Request, 'headers' | 'method'>) => Promise<Ticket | undefined>;
35
+ //# sourceMappingURL=box-wire.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"box-wire.d.ts","sources":["../box-wire.ts"],"names":[],"mappings":"AAEA,cAAc,UAAU,kCAAuC;AAC/D,cAAc,SAAS,uBAAsB;AAE7C,OAAO,YAAI,aAAyB;KAE/B,WAAW,UAAU,SAAS;AACnC,YAAY;EACN,IAAI;EAAU,MAAM,MAAM;;EAC1B,IAAI;EAAW,OAAO,MAAM;;AAElC,YAAY;EAAS,IAAI,MAAM;EAAE,KAAK;EAAK,SAAS,OAAO;;AAC3D,YAAY;EACN,QAAQ,aAAa,IAAI;EAAE,QAAQ,MAAM;;EACzC,UAAU;;AAEhB,YAAY;EAAe,IAAI,MAAM;EAAE,QAAQ;;AAG/C,OAAO,YAAI,SAAgB,MAAM,MAAM,KAAG,QAAQ,MAAM,EAQrD;KAEE;EAAW,QAAQ,MAAM;EAAE,QAAQ,MAAM;EAAE,SAAS,MAAM;;AAE/D,OAAO,YAAI,SACT,QAAQ,MAAM,EACd,QAAQ,MAAM,EACd,kBACC,QAAQ,MAAM,EASd;AAEH,OAAO,YAAI,aACT,QAAQ,MAAM,EACd,SAAS,KAAK,SAAS,YAAY,cAClC,QAAQ,SAAS,SAAS,EAM5B"}
@@ -0,0 +1,55 @@
1
+ import type { MailDomain, MailDomains } from "@yaks/host/senders";
2
+ import { type Vault } from "@yaks/secrets";
3
+ import { type Fetch } from "./api.js";
4
+ /** The key domains are set up with and the HTTP boundary, from the host. */ export type Domains = {
5
+ token: string;
6
+ base?: string;
7
+ fetch?: Fetch;
8
+ };
9
+ type Answered = {
10
+ id: string;
11
+ name: string;
12
+ capabilities?: {
13
+ sending?: string;
14
+ receiving?: string;
15
+ };
16
+ records?: {
17
+ type: string;
18
+ name: string;
19
+ value: string;
20
+ priority?: number | null;
21
+ status: string;
22
+ }[];
23
+ };
24
+ /** A domain's records as fully qualified names, each `arrived` once Resend
25
+ * has verified it.
26
+ *
27
+ * ```ts
28
+ * import { shaped } from '@yaks/resend/domains'
29
+ * import { equal } from '@yaks/testing'
30
+ *
31
+ * let record = (name: string, status = 'verified') =>
32
+ * ({ type: 'TXT', name, value: 'v', status })
33
+ * equal(
34
+ * shaped({
35
+ * id: 'r',
36
+ * name: 'bot.yak.sh',
37
+ * records: [record('resend._domainkey.bot'), record('bot', 'pending')],
38
+ * }).records.map(({ name, arrived }) => [name, arrived]),
39
+ * [['resend._domainkey.bot.yak.sh', true], ['bot.yak.sh', false]],
40
+ * )
41
+ * ```
42
+ */ export declare let shaped: (domain: Answered) => MailDomain;
43
+ export declare let domains: (options: Domains) => MailDomains;
44
+ export type SendingKeys = {
45
+ pending: (domain: string) => Promise<string>;
46
+ acknowledged: (domain: string) => Promise<void>;
47
+ remove: (domain: string) => Promise<void>;
48
+ };
49
+ /** A per-domain sending key minted with the local provisioning credential.
50
+ * Its token is kept in the vault only until the Worker acknowledges receipt.
51
+ * Its Resend id stays so removing the domain revokes its key as well. */ export declare let sendingKeys: (options: Domains, vault: Vault) => SendingKeys;
52
+ /** The domains of a key set at the call, or the same verbs rejecting with
53
+ * why they cannot be reached until it is: `options` are read at each call,
54
+ * so a key put after start-up is used by the next one. */ export declare let lent: (options: () => Partial<Domains>) => MailDomains;
55
+ //# sourceMappingURL=domains.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domains.d.ts","sources":["../domains.ts"],"names":[],"mappings":"AAIA,cAA4B,UAAU,EAAE,WAAW,kCAAuC;AAC1F,SAAoB,KAAK,KAAK,6BAAkC;AAChE,SAAS,KAAK,KAAK,mBAA8B;AAEjD,0EAA0E,GAC1E,YAAY;EAAY,OAAO,MAAM;EAAE,OAAO,MAAM;EAAE,QAAQ;;KAIzD;EACH,IAAI,MAAM;EACV,MAAM,MAAM;EACZ;IAAiB,UAAU,MAAM;IAAE,YAAY,MAAM;;EACrD;IACE,MAAM,MAAM;IACZ,MAAM,MAAM;IACZ,OAAO,MAAM;IACb,WAAW,MAAM,GAAG,IAAI;IACxB,QAAQ,MAAM;;;AAkBlB;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,YAAI,SAAU,QAAQ,aAAW,WAoBvC;AAiED,OAAO,YAAI,UAAW,SAAS,YAAU,YA8CxC;AAID,YAAY;EACV,UAAU,QAAQ,MAAM,KAAK,QAAQ,MAAM;EAC3C,eAAe,QAAQ,MAAM,KAAK,QAAQ,IAAI;EAC9C,SAAS,QAAQ,MAAM,KAAK,QAAQ,IAAI;;AAG1C;;uEAEuE,GACvE,OAAO,YAAI,cAAe,SAAS,SAAS,OAAO,UAAQ,YA6E1D;AAED;;wDAEwD,GACxD,OAAO,YAAI,OAAQ,eAAe,QAAQ,aAAW,YAcpD"}
@@ -0,0 +1,8 @@
1
+ import { type MailDomains, type Notices, type Sender } from "@yaks/host/senders";
2
+ import type { Options } from "./options.js";
3
+ /** The `resend` sender, built from these options at every letter. */ export declare let senders: (_host: unknown, options?: Options) => Record<string, Sender>;
4
+ /** The `resend` notices, verified with `receipts.secret` as it reads then,
5
+ * and a received letter read with `receiving.token` where options name one. */ export declare let notices: (_host: unknown, options?: Options) => Record<string, Notices>;
6
+ /** The `resend` mail domains, set up with `domains.token` as it reads at
7
+ * each call. */ export declare let mailDomains: (_host: unknown, options?: Options) => Record<string, MailDomains>;
8
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sources":["../graph.ts"],"names":[],"mappings":"AAMA,SAEE,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,MAAM,kCACyB;AAEtC,cAAc,OAAO,uBAAsB;AAI3C,mEAAmE,GACnE,OAAO,YAAI,UACT,OAAO,OAAO,EACd,UAAS,YACR,OAAO,MAAM,EAAE,QAA0D;AAE5E;6EAC6E,GAC7E,OAAO,YAAI,UACT,OAAO,OAAO,EACd,UAAS,YACR,OAAO,MAAM,EAAE,SAYhB;AAEF;cACc,GACd,OAAO,YAAI,cACT,OAAO,OAAO,EACd,UAAS,YACR,OAAO,MAAM,EAAE,aAMhB"}
package/_dist/mod.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from "./sender.js";
2
+ export * from "./receive.js";
3
+ export { type Domains, domains } from "./domains.js";
4
+ export type { Options, Receipts } from "./options.js";
5
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AACA,4BAA2B;AAC3B,6BAA4B;AAC5B,SAAS,KAAK,OAAO,EAAE,OAAO,uBAAsB;AACpD,cAAc,OAAO,EAAE,QAAQ,uBAAsB"}
@@ -0,0 +1,19 @@
1
+ import type { Resend } from "./sender.js";
2
+ /** What a config passes to @yaks/resend. */ export type Options = Partial<Resend> & {
3
+ /** Resend's signed delivery receipts for this graph. A receipt counts only
4
+ * where it carries every one of the sender's `tags`. */ receipts?: Receipts;
5
+ /** The mail domains it sets up, reads and removes, through `base` and
6
+ * `fetch` as the sender is. */ domains?: {
7
+ /** a `full_access` key: a sending key cannot manage domains */ token?: string;
8
+ };
9
+ /** Mail Resend receives, which the notices read in full for a host that
10
+ * takes mail in. Without it, a received letter is acknowledged unread. */ receiving?: {
11
+ /** a `full_access` key: a sending key cannot read received mail */ token?: string;
12
+ /** Defer retrieval to the host when a receiving key is unavailable here. */ defer?: boolean;
13
+ };
14
+ };
15
+ /** The webhook Resend posts delivery receipts to. */ export type Receipts = {
16
+ /** the endpoint's signing secret, `whsec_…` */ secret?: string;
17
+ /** the path it answers on (default `/mail/resend`) */ path?: string;
18
+ };
19
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sources":["../options.ts"],"names":[],"mappings":"AAkBA,cAAc,MAAM,sBAAqB;AAEzC,0CAA0C,GAC1C,YAAY,UAAU,QAAQ;EAC5B;wDACsD,GACtD,WAAW;EACX;+BAC6B,GAC7B;IACE,6DAA6D,GAAG,QAC9D,MAAM;;EAEV;0EACwE,GACxE;IACE,iEAAiE,GAAG,QAClE,MAAM;IACR,0EAA0E,GAC1E,QAAQ,OAAO;;;AAInB,mDAAmD,GACnD,YAAY;EACV,6CAA6C,GAC7C,SAAS,MAAM;EACf,oDAAoD,GACpD,OAAO,MAAM"}
@@ -0,0 +1,45 @@
1
+ import { type Incoming, type Notice, Unsigned } from "@yaks/host/senders";
2
+ import { type Fetch } from "./api.js";
3
+ export { Unsigned };
4
+ export type Event = {
5
+ type: string;
6
+ data: {
7
+ email_id?: string;
8
+ message_id?: string;
9
+ to?: string[];
10
+ cc?: string[];
11
+ bcc?: string[];
12
+ received_for?: string[];
13
+ tags?: Record<string, string>;
14
+ headers?: {
15
+ name: string;
16
+ value: string;
17
+ }[];
18
+ };
19
+ };
20
+ export type Receiving = {
21
+ /** a `full_access` key: a sending key cannot read received mail */ token?: string;
22
+ /** Hand authenticated arrivals off to the host for later retrieval. */ defer?: boolean;
23
+ base?: string;
24
+ fetch?: Fetch;
25
+ };
26
+ /** Verify the unparsed webhook body with its endpoint's signing key. */ export declare let event: (request: Request, secret: string, now?: number) => Promise<Event>;
27
+ /** A signed acceptance's RFC Message-ID, correlated to the caller's letter. */ export declare let receipt: (event: Event) => {
28
+ letter: string;
29
+ id: string;
30
+ } | undefined;
31
+ /** Receive full content and attachments, one letter for each recipient it
32
+ * names: its To, Cc and Bcc, and those Resend received it for. This
33
+ * explicitly needs a receiving credential: a sending-only key cannot retrieve
34
+ * bodies or attachments. */ export declare let received: (options: Receiving, email: string) => Promise<Incoming[]>;
35
+ /** The provider responses needed to relay a received letter. Attachment
36
+ * bytes travel separately from the provider's expiring download URLs. */ export type Retrieved = {
37
+ mail: string;
38
+ attachments?: string;
39
+ };
40
+ export declare let retrieved: (options: Receiving, email: string) => Promise<Retrieved>;
41
+ export declare let decoded: (raw: Retrieved, go?: Fetch) => Promise<Incoming[]>;
42
+ /** A signed provider event at the neutral receipt boundary, verified with
43
+ * the endpoint's signing secret. Where the host takes mail in (`receiving`),
44
+ * a received letter is read in full with its key. */ export declare let notification: (request: Request, secret: string | undefined, receiving?: Receiving) => Promise<Notice>;
45
+ //# sourceMappingURL=receive.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"receive.d.ts","sources":["../receive.ts"],"names":[],"mappings":"AAEA,SACE,KAAK,QAAQ,EAEb,KAAK,MAAM,EACX,QAAQ,kCAC4B;AACtC,SAAS,KAAK,KAAK,mBAAwB;AAE3C,SAAS,QAAQ,GAAE;AAEnB,YAAY;EACV,MAAM,MAAM;EACZ;IACE,WAAW,MAAM;IACjB,aAAa,MAAM;IACnB,KAAK,MAAM;IACX,KAAK,MAAM;IACX,MAAM,MAAM;IACZ,eAAe,MAAM;IACrB,OAAO,OAAO,MAAM,EAAE,MAAM;IAC5B;MAAY,MAAM,MAAM;MAAE,OAAO,MAAM;;;;AAkB3C,YAAY;EACV,iEAAiE,GACjE,QAAQ,MAAM;EACd,qEAAqE,GACrE,QAAQ,OAAO;EACf,OAAO,MAAM;EACb,QAAQ;;AAOV,sEAAsE,GACtE,OAAO,YAAI,QACT,SAAS,SACT,QAAQ,MAAM,EACd,MAAK,MAAM,KACV,QAAQ,OA0CV;AAED,6EAA6E,GAC7E,OAAO,YAAI,UACT,OAAO;EACJ,QAAQ,MAAM;EAAE,IAAI,MAAM;IAAK,SAAS,CAO5C;AAKD;;;0BAG0B,GAC1B,OAAO,YAAI,WACT,SAAS,WACT,OAAO,MAAM,KACZ,QAAQ,YAC8C;AAEzD;uEACuE,GACvE,YAAY;EAAc,MAAM,MAAM;EAAE,cAAc,MAAM;;AAE5D,OAAO,YAAI,YACT,SAAS,WACT,OAAO,MAAM,KACZ,QAAQ,WAoBV;AAED,OAAO,YAAI,UACT,KAAK,WACL,KAAI,UACH,QAAQ,YA+DV;AAED;;mDAEmD,GACnD,OAAO,YAAI,eACT,SAAS,SACT,QAAQ,MAAM,GAAG,SAAS,EAC1B,YAAY,cACX,QAAQ,QAkCV"}
@@ -0,0 +1,8 @@
1
+ import type { Route } from "@yaks/api";
2
+ import type { Graph } from "@yaks/graph";
3
+ import type { Options } from "./options.js";
4
+ /** The receipt route, where the options configure one. */ export declare let routes: (host: {
5
+ graph: Pick<Graph, 'get' | 'apply'>;
6
+ report?: (error: unknown) => unknown;
7
+ }, options?: Options) => Route[];
8
+ //# sourceMappingURL=routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.d.ts","sources":["../routes.ts"],"names":[],"mappings":"AAIA,cAAc,KAAK,yBAA8B;AACjD,cAAc,KAAK,2BAAgC;AAEnD,cAAc,OAAO,uBAAsB;AAG3C,wDAAwD,GACxD,OAAO,YAAI,SACT;EACE,OAAO,KAAK,OAAO,QAAQ;EAC3B,UAAU,OAAO,OAAO,KAAK,OAAO;GAEtC,UAAS,YACR,QA2BF"}
@@ -0,0 +1,19 @@
1
+ import type { Sender } from "@yaks/host/senders";
2
+ import { type Fetch } from "./api.js";
3
+ /** Credentials and the HTTP boundary, supplied by the host. */ export type Resend = {
4
+ token: string;
5
+ base?: string;
6
+ fetch?: Fetch;
7
+ tags?: Record<string, string>;
8
+ };
9
+ /** Resend's sending API. Only a refusal known to precede acceptance retries
10
+ * (a dropped connection, a 429, a refused key), and a refusal of the letter's
11
+ * recipient is {@link Undeliverable};
12
+ * an uncertain response never causes another send or another provider to send.
13
+ * Resend exposes the RFC Message-ID through webhooks and retrieval, rather
14
+ * than its send response. An accepted letter therefore has an empty receipt. */ export declare let resend: ({}: Resend) => Sender;
15
+ /** Build from host configuration, leaving missing credentials waiting. */ export declare let configured: (options: Partial<Resend>) => {
16
+ sender?: Sender;
17
+ waiting?: string;
18
+ };
19
+ //# sourceMappingURL=sender.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sender.d.ts","sources":["../sender.ts"],"names":[],"mappings":"AAIA,cAAuB,MAAM,kCAAuC;AACpE,SAAS,KAAK,KAAK,mBAAuC;AAE1D,6DAA6D,GAC7D,YAAY;EACV,OAAO,MAAM;EACb,OAAO,MAAM;EACb,QAAQ;EACR,OAAO,OAAO,MAAM,EAAE,MAAM;;AAgC9B;;;;;8EAK8E,GAC9E,OAAO,YAAI,SACT,IAAyC,MAAM,KAC9C,OA+DD;AAEF,wEAAwE,GACxE,OAAO,YAAI,aACT,SAAS,QAAQ;EACd,SAAS;EAAQ,UAAU,MAAM;EAGqC"}
@@ -0,0 +1,10 @@
1
+ import type { Host } from "@yaks/host";
2
+ type Options = {
3
+ box?: {
4
+ url?: string;
5
+ secret?: string;
6
+ token?: string;
7
+ };
8
+ };
9
+ export declare let service: (host: Host, options?: Options, signal?: AbortSignal) => Promise<void>;
10
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sources":["../service.ts"],"names":[],"mappings":"AACA,cAAc,IAAI,0BAA+B;KAK5C;EACH;IAAQ,MAAM,MAAM;IAAE,SAAS,MAAM;IAAE,QAAQ,MAAM;;;AAGvD,OAAO,YAAI,UACT,MAAM,MACN,UAAS,SACT,SAAQ,gBACP,QAAQ,IAAI,EAqFd"}
package/api.js ADDED
@@ -0,0 +1,19 @@
1
+ // What every call to Resend's API shares: its root, and the code and message
2
+ // of a refusal, which callers keep apart because a body can echo a private
3
+ // letter or credential.
4
+ /** The HTTP boundary a host supplies in place of `fetch`. */ /** The API root, `https://api.resend.com` unless `base` names another. */ export let root = (base)=>(base ?? 'https://api.resend.com').replace(/\/+$/, '');
5
+ /** Resend's error body, `{name, message}`, or empty strings where it has
6
+ * none. `name` is only ever Resend's snake_case code. */ export let said = (response)=>response.ok ? Promise.resolve({
7
+ name: '',
8
+ message: ''
9
+ }) : response.json().then((body)=>{
10
+ let { name, message } = body ?? {};
11
+ return {
12
+ name: typeof name == 'string' && /^[a-z_]+$/.test(name) ? name : '',
13
+ message: typeof message == 'string' ? message : ''
14
+ };
15
+ }, ()=>({
16
+ name: '',
17
+ message: ''
18
+ }));
19
+ //# sourceMappingURL=api.js.map
package/api.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sources":["./api.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,2EAA2E;AAC3E,wBAAwB;AAExB,2DAA2D,GAG3D,wEAAwE,GACxE,OAAO,IAAI,OAAO,CAAC,OACjB,CAAC,QAAQ,wBAAwB,EAAE,OAAO,CAAC,QAAQ,IAAG;AAExD;uDACuD,GACvD,OAAO,IAAI,OAAO,CAChB,WAEA,SAAS,EAAE,GAAG,QAAQ,OAAO,CAAC;IAAE,MAAM;IAAI,SAAS;EAAG,KAAK,SAAS,IAAI,GACrE,IAAI,CACH,CAAC;IACC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,GAAI,QAAQ,CAAC;IAClC,OAAO;MACL,MAAM,OAAO,QAAQ,YAAY,YAAY,IAAI,CAAC,QAAQ,OAAO;MACjE,SAAS,OAAO,WAAW,WAAW,UAAU;IAClD;EACF,GACA,IAAM,CAAC;MAAE,MAAM;MAAI,SAAS;IAAG,CAAC,GACjC"}