@lunora/mail 1.0.0-alpha.139 → 1.0.0-alpha.140
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/LICENSE.md +201 -104
- package/README.md +3 -3
- package/dist/inbound/index.mjs +1 -1
- package/dist/index.d.mts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/assertValidIdempotencyKey-CyJq0nZq.mjs +3 -0
- package/dist/packem_shared/authenticatesFrom-UBe_EgRT.mjs +1 -0
- package/dist/packem_shared/consumeQueuedSend-BwNGdlaG.mjs +1 -0
- package/dist/packem_shared/createCaptureSink-C489s13k.mjs +1 -0
- package/dist/packem_shared/{createCloudflareTransport-2pH3460e.mjs → createCloudflareTransport-Dxjf_b6q.mjs} +1 -1
- package/dist/packem_shared/createMailer-Cv1B9wYq.mjs +1 -0
- package/dist/packem_shared/{createResendTransport-DdsftR55.mjs → createResendTransport-CsJfCLAP.mjs} +1 -1
- package/dist/packem_shared/provider-transport-Ce2xVUuM.mjs +1 -0
- package/package.json +2 -2
- package/dist/packem_shared/address-BKzIBZxE.mjs +0 -3
- package/dist/packem_shared/authenticatesFrom-DCtlMHNq.mjs +0 -1
- package/dist/packem_shared/consumeQueuedSend-CDDDeoAz.mjs +0 -1
- package/dist/packem_shared/createCaptureSink-CEqX4_iD.mjs +0 -1
- package/dist/packem_shared/createMailer-DuQciU65.mjs +0 -1
- package/dist/packem_shared/provider-transport-C-ioZWVF.mjs +0 -1
package/LICENSE.md
CHANGED
|
@@ -1,108 +1,205 @@
|
|
|
1
|
-
# Functional Source License, Version 1.1, Apache 2.0 Future License
|
|
2
1
|
|
|
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
|
-
|
|
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 [yyyy] [name of copyright owner]
|
|
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.
|
|
106
203
|
|
|
107
204
|
<!-- DEPENDENCIES -->
|
|
108
205
|
<!-- /DEPENDENCIES -->
|
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
<div align="center">
|
|
16
16
|
|
|
17
17
|
[![typescript-image][typescript-badge]][typescript-url]
|
|
18
|
-
[![
|
|
18
|
+
[![Apache-2.0 licence][license-badge]][license]
|
|
19
19
|
[![npm version][npm-version-badge]][npm-version]
|
|
20
20
|
[![npm downloads][npm-downloads-badge]][npm-downloads]
|
|
21
21
|
[![PRs Welcome][prs-welcome-badge]][prs-welcome]
|
|
@@ -110,11 +110,11 @@ This is an open source project and will always remain free to use. If you think
|
|
|
110
110
|
|
|
111
111
|
## License
|
|
112
112
|
|
|
113
|
-
The Lunora mail package is open-sourced software licensed under the [
|
|
113
|
+
The Lunora mail package is open-sourced software licensed under the [Apache-2.0][license].
|
|
114
114
|
|
|
115
115
|
<!-- badges -->
|
|
116
116
|
|
|
117
|
-
[license-badge]: https://img.shields.io/badge/license-
|
|
117
|
+
[license-badge]: https://img.shields.io/badge/license-Apache--2.0-blue.svg?style=for-the-badge
|
|
118
118
|
[license]: https://github.com/anolilab/lunora/blob/alpha/LICENSE.md
|
|
119
119
|
[npm-version-badge]: https://img.shields.io/npm/v/@lunora/mail?style=for-the-badge
|
|
120
120
|
[npm-version]: https://www.npmjs.com/package/@lunora/mail
|
package/dist/inbound/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createInboundEmailHandler as n,dispatchToLunoraFunction as r}from"../packem_shared/createInboundEmailHandler-BeWkwqF2.mjs";import{authenticatesFrom as t,parseInboundEmail as i}from"../packem_shared/authenticatesFrom-
|
|
1
|
+
import{createInboundEmailHandler as n,dispatchToLunoraFunction as r}from"../packem_shared/createInboundEmailHandler-BeWkwqF2.mjs";import{authenticatesFrom as t,parseInboundEmail as i}from"../packem_shared/authenticatesFrom-UBe_EgRT.mjs";export{t as authenticatesFrom,n as createInboundEmailHandler,r as dispatchToLunoraFunction,i as parseInboundEmail};
|
package/dist/index.d.mts
CHANGED
|
@@ -3,6 +3,13 @@ export { type C as CapturedMail, type c as SendPayload, d as createCaptureTransp
|
|
|
3
3
|
import { D as DurableObjectJurisdiction } from "./packem_shared/shard.d-DVADjmEJ.mjs";
|
|
4
4
|
import { ReactElement } from 'react';
|
|
5
5
|
import { LunoraError } from '@lunora/errors';
|
|
6
|
+
/**
|
|
7
|
+
* Refuse a key the provider or a sent-mail store would reject. Run before the
|
|
8
|
+
* store is read: a KV read failing on an over-long key would otherwise surface as
|
|
9
|
+
* a retryable store error and redeliver the message into the dead-letter queue.
|
|
10
|
+
* The same key fails the same way on every attempt, so the refusal is final.
|
|
11
|
+
*/
|
|
12
|
+
declare const assertValidIdempotencyKey: (key: unknown) => void;
|
|
6
13
|
/**
|
|
7
14
|
* Sends a raw RFC 822 message through a Worker's Email send binding. The Workers
|
|
8
15
|
* runtime owns the binding, so the caller supplies this thin callback — keeping
|
|
@@ -322,4 +329,4 @@ declare const isRetryableMailError: (error: unknown) => boolean;
|
|
|
322
329
|
* One that is not must be reported (check the provider's logs), not resent.
|
|
323
330
|
*/
|
|
324
331
|
declare const isOutcomeUnknownMailError: (error: unknown) => boolean;
|
|
325
|
-
export { type CloudflareSend, type CloudflareTransportOptions, type ConsumeQueuedSendOptions, type FromEnvOptions, type LunoraMailOptions, type MailEnv, MailSendError, type MailSendErrorData, type MailTransport, type MailboxSink, type Mailer, type QueueLike, type QueuedSend, type SendOptions, type SentMailStore, consumeQueuedSend, createCaptureSink, createCloudflareTransport, createMailer, createMailerFromEnv, createResendTransport, isOutcomeUnknownMailError, isRetryableMailError, renderEmail, shouldCaptureMail, toQueuedPayload };
|
|
332
|
+
export { type CloudflareSend, type CloudflareTransportOptions, type ConsumeQueuedSendOptions, type FromEnvOptions, type LunoraMailOptions, type MailEnv, MailSendError, type MailSendErrorData, type MailTransport, type MailboxSink, type Mailer, type QueueLike, type QueuedSend, type SendOptions, type SentMailStore, assertValidIdempotencyKey, consumeQueuedSend, createCaptureSink, createCloudflareTransport, createMailer, createMailerFromEnv, createResendTransport, isOutcomeUnknownMailError, isRetryableMailError, renderEmail, shouldCaptureMail, toQueuedPayload };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,13 @@ export { type C as CapturedMail, type c as SendPayload, d as createCaptureTransp
|
|
|
3
3
|
import { D as DurableObjectJurisdiction } from "./packem_shared/shard.d-DVADjmEJ.js";
|
|
4
4
|
import { ReactElement } from 'react';
|
|
5
5
|
import { LunoraError } from '@lunora/errors';
|
|
6
|
+
/**
|
|
7
|
+
* Refuse a key the provider or a sent-mail store would reject. Run before the
|
|
8
|
+
* store is read: a KV read failing on an over-long key would otherwise surface as
|
|
9
|
+
* a retryable store error and redeliver the message into the dead-letter queue.
|
|
10
|
+
* The same key fails the same way on every attempt, so the refusal is final.
|
|
11
|
+
*/
|
|
12
|
+
declare const assertValidIdempotencyKey: (key: unknown) => void;
|
|
6
13
|
/**
|
|
7
14
|
* Sends a raw RFC 822 message through a Worker's Email send binding. The Workers
|
|
8
15
|
* runtime owns the binding, so the caller supplies this thin callback — keeping
|
|
@@ -322,4 +329,4 @@ declare const isRetryableMailError: (error: unknown) => boolean;
|
|
|
322
329
|
* One that is not must be reported (check the provider's logs), not resent.
|
|
323
330
|
*/
|
|
324
331
|
declare const isOutcomeUnknownMailError: (error: unknown) => boolean;
|
|
325
|
-
export { type CloudflareSend, type CloudflareTransportOptions, type ConsumeQueuedSendOptions, type FromEnvOptions, type LunoraMailOptions, type MailEnv, MailSendError, type MailSendErrorData, type MailTransport, type MailboxSink, type Mailer, type QueueLike, type QueuedSend, type SendOptions, type SentMailStore, consumeQueuedSend, createCaptureSink, createCloudflareTransport, createMailer, createMailerFromEnv, createResendTransport, isOutcomeUnknownMailError, isRetryableMailError, renderEmail, shouldCaptureMail, toQueuedPayload };
|
|
332
|
+
export { type CloudflareSend, type CloudflareTransportOptions, type ConsumeQueuedSendOptions, type FromEnvOptions, type LunoraMailOptions, type MailEnv, MailSendError, type MailSendErrorData, type MailTransport, type MailboxSink, type Mailer, type QueueLike, type QueuedSend, type SendOptions, type SentMailStore, assertValidIdempotencyKey, consumeQueuedSend, createCaptureSink, createCloudflareTransport, createMailer, createMailerFromEnv, createResendTransport, isOutcomeUnknownMailError, isRetryableMailError, renderEmail, shouldCaptureMail, toQueuedPayload };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{assertValidIdempotencyKey as o}from"./packem_shared/assertValidIdempotencyKey-CyJq0nZq.mjs";import{createCaptureTransport as t}from"./packem_shared/createCaptureTransport-DZhMUmaI.mjs";import{createCloudflareTransport as p}from"./packem_shared/createCloudflareTransport-Dxjf_b6q.mjs";import{default as m}from"./packem_shared/createMailer-Cv1B9wYq.mjs";import{createCaptureSink as u,createMailerFromEnv as f,shouldCaptureMail as s}from"./packem_shared/createCaptureSink-C489s13k.mjs";import{consumeQueuedSend as c,toQueuedPayload as x}from"./packem_shared/consumeQueuedSend-BwNGdlaG.mjs";import{default as E}from"./packem_shared/renderEmail-xypKDdux.mjs";import{default as C}from"./packem_shared/createResendTransport-CsJfCLAP.mjs";import{MailSendError as T,isOutcomeUnknownMailError as k,isRetryableMailError as Q}from"./packem_shared/MailSendError-BYih5mnM.mjs";export{T as MailSendError,o as assertValidIdempotencyKey,c as consumeQueuedSend,u as createCaptureSink,t as createCaptureTransport,p as createCloudflareTransport,m as createMailer,f as createMailerFromEnv,C as createResendTransport,k as isOutcomeUnknownMailError,Q as isRetryableMailError,E as renderEmail,s as shouldCaptureMail,x as toQueuedPayload};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{LunoraError as s}from"@lunora/errors";import{MailSendError as c}from"./MailSendError-BYih5mnM.mjs";const o=320,l=256,f=/^([^<]*)<([^>]*)>\s*$/,a=(t,r)=>{if(r.includes("\r")||r.includes(`
|
|
2
|
+
`)||r.includes(","))throw new s("INTERNAL",`@lunora/mail: address ${t} must not contain CR, LF, or comma`)},g=(t,r)=>{if(r.includes("\r")||r.includes(`
|
|
3
|
+
`))throw new s("INTERNAL",`@lunora/mail: ${t} must not contain CR or LF`)},d=(t,r)=>{if(t.length>l)throw new s("INTERNAL",`@lunora/mail: address name must be <= ${String(l)} characters`);if(r.length>o)throw new s("INTERNAL",`@lunora/mail: address email must be <= ${String(o)} characters`);return t&&a("name",t),a("email",r),t?{email:r,name:t}:{email:r}},u=t=>{const r=t.trim();if(r.length>o)throw new s("INTERNAL",`@lunora/mail: address email must be <= ${String(o)} characters`);return a("email",r),{email:r}},m=t=>{const r=f.exec(t),e=(r?.[2]??"").trim();return r&&e?d((r[1]??"").trim(),e):u(t)},i=t=>{if(t===void 0)return;const r=Array.isArray(t)?t:[t];if(r.length!==0)return r.map(e=>m(e))},w=t=>{if(i(t.to)===void 0)throw new s("INTERNAL","@lunora/mail: at least one recipient is required");i(t.cc),i(t.bcc),t.from!==void 0&&m(t.from),t.replyTo!==void 0&&m(t.replyTo)},h=/^[\u0021-\u007E]{1,256}$/u,N=t=>{if(t!==void 0&&(typeof t!="string"||!h.test(t)||t==="."||t===".."))throw new c({message:"@lunora/mail: `idempotencyKey` must be a string of 1-256 visible ASCII characters, other than `.` or `..`",retryable:!1})},T=t=>{for(const n of["html","text"])if(t[n]!==void 0&&typeof t[n]!="string")throw new c({message:`@lunora/mail: \`${n}\` must be a string, got ${typeof t[n]}`,retryable:!1});const r=typeof t.text=="string"&&t.text!=="",e=typeof t.html=="string"&&t.html!=="";if(!r&&!e)throw new c({message:"@lunora/mail: a message needs `text` or `html` content (or `react` to render them)",retryable:!1})};export{T as assertHasContent,w as assertSafeAddresses,g as assertSafeHeaderValue,N as assertValidIdempotencyKey,m as toAddress,i as toAddressList};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import l from"postal-mime";import{assertSafeHeaderValue as c}from"./assertValidIdempotencyKey-CyJq0nZq.mjs";const d=(s,e)=>{if(e!==void 0)return c(`inbound ${s}`,e),e},p=s=>s===null?s:s==="inline"?"inline":"attachment",f=s=>s.address!==void 0&&s.address!==""?s.name?`${s.name} <${s.address}>`:s.address:s.group?s.group.map(e=>e.address??"").filter(e=>e!=="").join(", "):s.name??"",g=/"(?:[^"\\]|\\.)*(?:"|$)|\((?:[^()\\]|\\.)*(?:\)|$)/g,v=s=>s.replaceAll(g,e=>e.startsWith('"')?e.replaceAll(/[;=]/gu," "):" "),m=(s,e,n)=>{const i=v(s).matchAll(new RegExp(String.raw`(?:^|;)\s*${e}\s*(?:/\s*\d+\s*)?=\s*([a-z]+)([^;]*)`,"gi")),a=new RegExp(String.raw`\b${n.split(".").join(String.raw`\s*\.\s*`)}\s*=\s*"?([^\s;"]+)`,"i");return[...i].map(o=>{const t=a.exec(o[2]??"")?.[1];return{domain:t===void 0?null:t.slice(t.lastIndexOf("@")+1).toLowerCase(),result:(o[1]??"").toLowerCase()}})},h=s=>s===void 0||s===""?{dkim:[],dmarc:[],spf:[]}:{dkim:m(s,"dkim","header.d"),dmarc:m(s,"dmarc","header.from"),spf:m(s,"spf","smtp.mailfrom")},$=async s=>{const e=await l.parse(s),n={};for(const r of e.headers)c(`inbound header \`${r.key}\``,r.value),n[r.key]=r.value;const i=e.headers.find(r=>r.key==="authentication-results")?.value,a=(e.to??[]).map(r=>{const u=f(r);return c("inbound to",u),u}),o=e.from?f(e.from):"";return c("inbound from",o),{attachments:e.attachments.map(r=>({content:r.content,disposition:p(r.disposition),...r.encoding===void 0?{}:{encoding:r.encoding},filename:r.filename,mimeType:r.mimeType})),authentication:h(i),from:o,headers:n,...e.html===void 0?{}:{html:e.html},...d("inReplyTo",e.inReplyTo)===void 0?{}:{inReplyTo:e.inReplyTo},...d("messageId",e.messageId)===void 0?{}:{messageId:e.messageId},...d("references",e.references)===void 0?{}:{references:e.references},...d("subject",e.subject)===void 0?{}:{subject:e.subject},...e.text===void 0?{}:{text:e.text},to:a}},x=/<([^<>]*)>$/,b=s=>{const e=x.exec(s)?.[1]??s,n=e.indexOf("@");if(!(n===-1||n!==e.lastIndexOf("@")))return e.slice(n+1).trim().toLowerCase()},T=s=>{const e=b(s.from);if(e===void 0)return!1;const n=t=>t.some(r=>r.result==="pass"&&r.domain===e),{dkim:i,dmarc:a,spf:o}=s.authentication;return n(a)||n(o)||n(i)};export{T as authenticatesFrom,$ as parseInboundEmail};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{assertValidIdempotencyKey as O}from"./assertValidIdempotencyKey-CyJq0nZq.mjs";import{MailSendError as y,isRetryableMailError as T,isOutcomeUnknownMailError as _}from"./MailSendError-BYih5mnM.mjs";const x=t=>{const e={...t};return delete e.react,e},N=86400,v=(t,e)=>`sending ${String(e)} ${t}`,E=(t,e)=>`failed ${String(e)} ${t}`,A=15*86400,k=t=>Math.max(t,A),w=1e4,D=1380*60*1e3,b=60,d=t=>new y({message:`@lunora/mail: ${t}`,retryable:!1}),$=t=>{if(!t||typeof t!="object"||Array.isArray(t))throw d("queue message body must be an object");const e=t;if(typeof e.subject!="string")throw d("queue message must have a string `subject`");const a=typeof e.to=="string",r=Array.isArray(e.to)&&e.to.every(c=>typeof c=="string");if(!a&&!r)throw d("queue message `to` must be a string or string[]");const n=(c,o)=>{if(o!==void 0){if(typeof o!="string")throw d(`queue message \`${c}\` must be a string`);return o}},s=(c,o)=>{if(o!==void 0){if(typeof o=="string")return[o];if(Array.isArray(o)&&o.every(u=>typeof u=="string"))return o;throw d(`queue message \`${c}\` must be a string or string[]`)}};let i;if(e.headers!==void 0){if(!e.headers||typeof e.headers!="object"||Array.isArray(e.headers))throw d("queue message `headers` must be an object of string values");const c=Object.entries(e.headers);for(const[o,u]of c)if(typeof u!="string")throw d(`queue message header "${o}" must be a string`);i=e.headers}const f=n("idempotencyKey",e.idempotencyKey);return O(f),{bcc:s("bcc",e.bcc),cc:s("cc",e.cc),from:n("from",e.from),headers:i,html:n("html",e.html),idempotencyKey:f,replyTo:n("replyTo",e.replyTo),subject:e.subject,text:n("text",e.text),to:e.to}},h=t=>{const e=t===void 0?0:Date.now()-t.getTime();return Number.isNaN(e)||e>=D},M=(t,e)=>{if(t&&h(e))throw new y({message:"@lunora/mail: an earlier delivery of this message may have been sent, and the provider no longer dedupes a key this old",outcomeUnknown:!0,retryable:!1})},S=async(t,e,a)=>{try{return await t.send(e)}catch(r){throw _(r)&&T(r)&&h(a)?new y({cause:r,message:"@lunora/mail: the send may have been delivered, and the provider no longer dedupes a key this old",outcomeUnknown:!0,retryable:!1}):r}},g=async t=>{let e;try{return await Promise.race([t,new Promise((a,r)=>{e=setTimeout(()=>{r(new Error(`the sent-mail store did not answer within ${String(w)}ms`))},w)})])}finally{clearTimeout(e)}},j=async(t,e,a)=>{const r=Array.from({length:a-1},(s,i)=>i+1);return(await g(Promise.all(r.map(async s=>await Promise.all([t.get(v(e,s)),t.get(E(e,s))]))))).some(([s,i])=>typeof s=="string"&&typeof i!="string")},I=async(t,e,a,r)=>{if(a<=1||!h(r))return;let n;try{n=await j(t,e,a)}catch(s){throw new y({cause:s,message:"@lunora/mail: could not read the sent-mail store",retryable:!0})}M(n,r)},p=(t,e,a,r)=>{const n=JSON.stringify({event:e,message:a,...r!==void 0&&{error:r instanceof Error?{message:r.message,name:r.name,stack:r.stack}:{message:typeof r=="string"?r:typeof r}}});console[t](n)},L=async(t,e,a,r)=>{try{await g(t.put(e,a,{expirationTtl:r}))}catch(n){p("error","lunora.mail.sent_record_failed","@lunora/mail: sent, but could not record the idempotency key; a redelivery may send again",n)}},q=async(t,e,a,r)=>{try{await g(t.put(E(e,a),"failed",{expirationTtl:k(r)}))}catch(n){p("warn","lunora.mail.attempt_mark_failed","@lunora/mail: could not mark a failed send; a late redelivery will be refused",n)}},R=async(t,e,a={})=>{const{attempts:r,enqueuedAt:n,sent:s,sentTtlSeconds:i=N}=a;if(!Number.isSafeInteger(i)||i<b)throw new y({message:`@lunora/mail: \`sentTtlSeconds\` must be a whole number of seconds, at least ${String(b)}`,retryable:!0});const f=$(e);if(!s)return"sent"in a&&p("warn","lunora.mail.sent_store_unbound","@lunora/mail: consumeQueuedSend got `sent: undefined` (is the KV namespace bound?), so redeliveries are not deduplicated"),M(r!==void 0&&r>1,n),{deduplicated:!1,...await S(t,f,n)};const l=f.idempotencyKey;if(l===void 0)throw d("queue message has no `idempotencyKey` to dedupe on");let c;try{c=await g(s.get(l))}catch(m){throw new y({cause:m,message:"@lunora/mail: could not read the sent-mail store",retryable:!0})}if(typeof c=="string")return{deduplicated:!0,id:c};const o=r??1;await I(s,l,o,n);try{await g(s.put(v(l,o),"sending",{expirationTtl:k(i)}))}catch(m){throw new y({cause:m,message:"@lunora/mail: could not mark the send in the sent-mail store",retryable:!0})}let u;try{({id:u}=await S(t,f,n))}catch(m){throw T(m)&&!_(m)&&await q(s,l,o,i),m}return await L(s,l,u,i),{deduplicated:!1,id:u}};export{R as consumeQueuedSend,x as toQueuedPayload};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./assertValidIdempotencyKey-CyJq0nZq.mjs";import{createCaptureTransport as c}from"./createCaptureTransport-DZhMUmaI.mjs";import"./createCloudflareTransport-Dxjf_b6q.mjs";import s from"./createMailer-Cv1B9wYq.mjs";import{LunoraError as l}from"@lunora/errors";import{D as m,a as p,p as E}from"./shard-C5t-b7FX.mjs";import"./consumeQueuedSend-BwNGdlaG.mjs";import"./renderEmail-xypKDdux.mjs";import"./createResendTransport-CsJfCLAP.mjs";import"./MailSendError-BYih5mnM.mjs";const _="__lunora_admin__:recordMail",N=/^(?:dev(?:elopment)?|local(?:host)?|test)$/iu,f=["CF_ENV","ENVIRONMENT","NODE_ENV","WORKER_ENV"],R=(e,r)=>{const o=e[r];if(typeof o!="string"||o==="")throw new l("INTERNAL",`@lunora/mail: missing env var \`${r}\` — set it in .dev.vars (and \`wrangler secret put ${r}\` for secrets).`);return o},A=e=>{const r=e.LUNORA_MAIL_CAPTURE;if(typeof r=="string"){const t=r.toLowerCase();if(t==="1"||t==="true")return!0;if(t==="0"||t==="false")return!1;console.warn(`@lunora/mail: unrecognized LUNORA_MAIL_CAPTURE value "${r}" — expected "1"/"true" or "0"/"false"; falling back to environment detection.`)}const o=f.map(t=>e[t]).filter(t=>typeof t=="string"&&t!=="");return o.length>0&&o.every(t=>N.test(t))};let u=!1;const T=(e,r=m,o)=>({record:async t=>{const i=e.SHARD,a=typeof e.LUNORA_ADMIN_TOKEN=="string"?e.LUNORA_ADMIN_TOKEN:void 0;if(i===void 0||a===void 0)return u||(u=!0,console.warn("@lunora/mail: capturing mail but there is nowhere to record it — the `SHARD` binding and/or `LUNORA_ADMIN_TOKEN` is missing, so every captured message is discarded. Set both to see mail in the studio inbox, or set LUNORA_MAIL_CAPTURE=0 to deliver for real.")),{id:"uncaptured"};const d=p(i,o);try{return{id:(await E(d,{adminToken:a,envelope:{args:t,functionPath:_},label:"@lunora/mail: recording captured mail",shardKey:r})).result?.id??"captured"}}catch(n){return console.error("@lunora/mail: failed to record captured mail into the studio inbox —",n),{id:"uncaptured"}}}}),v=(e,r={})=>{const o=R(e,"MAIL_FROM");if(A(e))return s({from:o,queue:r.queue,sendTimeoutMs:r.sendTimeoutMs,transport:c(T(e,r.rootShard,r.jurisdiction))});const{cloudflareSend:t}=r,i=typeof e.RESEND_API_KEY=="string"&&e.RESEND_API_KEY!==""?e.RESEND_API_KEY:void 0;return s({apiKey:i,cloudflareSend:t,from:o,queue:r.queue,sendTimeoutMs:r.sendTimeoutMs})};export{T as createCaptureSink,v as createMailerFromEnv,A as shouldCaptureMail};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cloudflareEmailProvider as l}from"@visulima/email/providers/cloudflare-email";import{r as d,t as m,i as f}from"./provider-transport-
|
|
1
|
+
import{cloudflareEmailProvider as l}from"@visulima/email/providers/cloudflare-email";import{r as d,t as m,i as f}from"./provider-transport-Ce2xVUuM.mjs";import{MailSendError as n}from"./MailSendError-BYih5mnM.mjs";const h=r=>{const t=l({send:r.send});return{send:async e=>{await t.initialize();const s=e.cc!==void 0&&e.cc.length>0,o=e.bcc!==void 0&&e.bcc.length>0;if(s||o)throw new n({message:"@lunora/mail: Cloudflare Email Workers does not support cc/bcc — fan out one send per recipient instead",retryable:!1});const{first:c,list:i}=d(e.to);if(i.length>1)throw new n({message:`@lunora/mail: Cloudflare Email Workers is single-recipient but received ${String(i.length)} \`to\` addresses — fan out one send per recipient instead`,retryable:!1});const a=await t.sendEmail(m(e,r.from,c));return f(a)}}};export{h as createCloudflareTransport};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as l}from"@lunora/errors";import{assertSafeHeaderValue as i,assertValidIdempotencyKey as b,assertSafeAddresses as h,assertHasContent as T}from"./assertValidIdempotencyKey-CyJq0nZq.mjs";import{isCaptureTransport as p}from"./createCaptureTransport-DZhMUmaI.mjs";import{createCloudflareTransport as S}from"./createCloudflareTransport-Dxjf_b6q.mjs";import{toQueuedPayload as E}from"./consumeQueuedSend-BwNGdlaG.mjs";import g from"./renderEmail-xypKDdux.mjs";import q from"./createResendTransport-CsJfCLAP.mjs";import{MailSendError as d}from"./MailSendError-BYih5mnM.mjs";const I=()=>{if(typeof crypto<"u"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"){const r=crypto.getRandomValues(new Uint8Array(16));return Array.from(r,t=>t.toString(16).padStart(2,"0")).join("")}}throw new Error("randomSessionId: no Web Crypto available — a session id needs crypto.randomUUID or crypto.getRandomValues")},U=6e4,y=2147483647,N=async(r,t)=>{let c;const s=new Promise((m,f)=>{c=setTimeout(()=>{f(new d({message:`@lunora/mail: send timed out after ${String(t)}ms, so it may have been delivered`,outcomeUnknown:!0,retryable:!1}))},t)});try{return await Promise.race([r,s])}finally{clearTimeout(c)}},v=r=>{if(r.cloudflareSend)return S({from:r.from,send:r.cloudflareSend});if(r.apiKey)return q(r.apiKey,r.from);if(r.queue)return{send:()=>Promise.reject(new d({message:"@lunora/mail: no transport configured — this mailer can only queue(); pass `transport`, `cloudflareSend` (a SEND_EMAIL binding) or `apiKey` (Resend) to send()",retryable:!0}))};throw new l("INTERNAL","@lunora/mail: a transport is required — pass `transport`, `cloudflareSend` (Cloudflare Email Workers, the default), or `apiKey` (Resend), or a `queue` for a producer-only mailer")},P=r=>{if(!r.from)throw new l("INTERNAL","@lunora/mail: `from` is required");const t=r.sendTimeoutMs??U;if(!Number.isFinite(t)||t<=0||t>y)throw new l("INTERNAL",`@lunora/mail: \`sendTimeoutMs\` must be a positive number of milliseconds, at most ${String(y)}`);const c=r.transport??v(r),s=async e=>{let{html:u}=e,{text:n}=e;if(e.react){const o=await g(e.react);u=u??o.html,n=n??o.text}if(i("subject",e.subject),b(e.idempotencyKey),e.headers)for(const[o,w]of Object.entries(e.headers))i(`header name "${o}"`,o),i(`header "${o}" value`,w);const a=e.from??r.from;return h({bcc:e.bcc,cc:e.cc,from:a,replyTo:e.replyTo,to:e.to}),T({html:u,text:n}),{bcc:e.bcc?.length?e.bcc:void 0,cc:e.cc?.length?e.cc:void 0,from:a,headers:e.headers,html:u,replyTo:e.replyTo,subject:e.subject,text:n,to:e.to}},m=async e=>{const u=await s(e),{idempotencyKey:n}=e;try{return await N(c.send(u,{idempotencyKey:n}),t)}catch(a){if(!(a instanceof d))throw new d({cause:a,retryable:!0});const o=n!==void 0&&c.dedupesOnIdempotencyKey===!0;throw a.outcomeUnknown&&a.retryable!==o?new d({cause:a.cause,message:a.message,outcomeUnknown:!0,retryable:o}):a}};return{queue:async e=>{if(!r.queue){if(p(c))return await m(e),{queued:!0};throw new l("INTERNAL","@lunora/mail: `queue` binding is required for mailer.queue()")}const u=await s(e),n=e.idempotencyKey??I();return await r.queue.send(E({...u,idempotencyKey:n})),{queued:!0}},send:m}};export{P as default};
|
package/dist/packem_shared/{createResendTransport-DdsftR55.mjs → createResendTransport-CsJfCLAP.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{resendProvider as c}from"@visulima/email/providers/resend";import{r as m,t as p,i as l}from"./provider-transport-
|
|
1
|
+
import{resendProvider as c}from"@visulima/email/providers/resend";import{r as m,t as p,i as l}from"./provider-transport-Ce2xVUuM.mjs";const f=(i,n)=>{const e=c({apiKey:i});return{dedupesOnIdempotencyKey:!0,send:async(t,s)=>{await e.initialize();const{first:o,list:r}=m(t.to),a=p(t,n,r.length===1?o:r),d=await e.sendEmail({...a,idempotencyKey:s?.idempotencyKey});return l(d)}}};export{f as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{toAddressList as s,assertHasContent as u,toAddress as o}from"./assertValidIdempotencyKey-CyJq0nZq.mjs";import{MailSendError as n}from"./MailSendError-BYih5mnM.mjs";const f=e=>e instanceof Error?e.message:e==null?"send failed":typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"||typeof e=="bigint"?e.toString():JSON.stringify(e)??"send failed",a=/^\d{3}$/,d=e=>typeof e=="number"?e:typeof e=="string"&&a.test(e)?Number(e):void 0,m="ETIMEDOUT",i=e=>{const t=[];for(let r=e;r instanceof Error&&t.length<5;r=r.cause)t.push(r);return t},l=e=>i(e).some(t=>"code"in t&&t.code===m),c=e=>{for(const t of i(e)){const r=d("code"in t?t.code:void 0);if(r!==void 0)return r}},h=409,b=e=>{if(!(e instanceof Error))return!0;const t=c(e);return t!==void 0&&t>=100&&t<=599?t===408||t===429||t>=500:!0},p=e=>{const t=s(e),[r]=t??[];if(!t||r===void 0)throw new n({message:"@lunora/mail: at least one recipient is required",retryable:!1});return{first:r,list:t}},g=(e,t,r)=>(u(e),{bcc:s(e.bcc),cc:s(e.cc),from:o(e.from??t),headers:e.headers,html:e.html,replyTo:e.replyTo?o(e.replyTo):void 0,subject:e.subject,text:e.text,to:r}),y=e=>{if(e.success&&!e.data)throw new n({message:"@lunora/mail: provider accepted the send but returned no message id",retryable:!1});if(!e.success||!e.data)throw console.error(`@lunora/mail: send failed: ${f(e.error)}`),l(e.error)?new n({cause:e.error,message:"@lunora/mail: the provider timed out, so the send may have been delivered",outcomeUnknown:!0,retryable:!1}):c(e.error)===h?new n({cause:e.error,message:"@lunora/mail: the provider is still processing a send with this idempotency key, so it may be delivered",outcomeUnknown:!0,retryable:!1}):new n({cause:e.error,retryable:b(e.error)});return{id:e.data.messageId}};export{y as i,p as r,g as t};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/mail",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.140",
|
|
4
4
|
"description": "Email for Lunora: Resend adapter, TSX templates, and queue-backed sends",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
],
|
|
15
15
|
"homepage": "https://lunora.sh",
|
|
16
16
|
"bugs": "https://github.com/anolilab/lunora/issues",
|
|
17
|
-
"license": "
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
18
|
"author": {
|
|
19
19
|
"name": "Daniel Bannert",
|
|
20
20
|
"email": "d.bannert@anolilab.de"
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{LunoraError as e}from"@lunora/errors";import{MailSendError as d}from"./MailSendError-BYih5mnM.mjs";const o=320,c=256,m=/^([^<]*)<([^>]*)>\s*$/,i=(r,t)=>{if(t.includes("\r")||t.includes(`
|
|
2
|
-
`)||t.includes(","))throw new e("INTERNAL",`@lunora/mail: address ${r} must not contain CR, LF, or comma`)},h=(r,t)=>{if(t.includes("\r")||t.includes(`
|
|
3
|
-
`))throw new e("INTERNAL",`@lunora/mail: ${r} must not contain CR or LF`)},l=(r,t)=>{if(r.length>c)throw new e("INTERNAL",`@lunora/mail: address name must be <= ${String(c)} characters`);if(t.length>o)throw new e("INTERNAL",`@lunora/mail: address email must be <= ${String(o)} characters`);return r&&i("name",r),i("email",t),r?{email:t,name:r}:{email:t}},u=r=>{const t=r.trim();if(t.length>o)throw new e("INTERNAL",`@lunora/mail: address email must be <= ${String(o)} characters`);return i("email",t),{email:t}},a=r=>{const t=m.exec(r),s=(t?.[2]??"").trim();return t&&s?l((t[1]??"").trim(),s):u(r)},n=r=>{if(r===void 0)return;const t=Array.isArray(r)?r:[r];if(t.length!==0)return t.map(s=>a(s))},N=r=>{if(n(r.to)===void 0)throw new e("INTERNAL","@lunora/mail: at least one recipient is required");n(r.cc),n(r.bcc),r.from!==void 0&&a(r.from),r.replyTo!==void 0&&a(r.replyTo)},f=/^[\u0021-\u007E]{1,256}$/u,T=r=>{if(r!==void 0&&(typeof r!="string"||!f.test(r)||r==="."||r===".."))throw new d({message:"@lunora/mail: `idempotencyKey` must be a string of 1-256 visible ASCII characters, other than `.` or `..`",retryable:!1})};export{h as a,T as b,a as c,N as d,n as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import l from"postal-mime";import{a as c}from"./address-BKzIBZxE.mjs";const d=(s,e)=>{if(e!==void 0)return c(`inbound ${s}`,e),e},p=s=>s===null?s:s==="inline"?"inline":"attachment",f=s=>s.address!==void 0&&s.address!==""?s.name?`${s.name} <${s.address}>`:s.address:s.group?s.group.map(e=>e.address??"").filter(e=>e!=="").join(", "):s.name??"",g=/"(?:[^"\\]|\\.)*(?:"|$)|\((?:[^()\\]|\\.)*(?:\)|$)/g,v=s=>s.replaceAll(g,e=>e.startsWith('"')?e.replaceAll(/[;=]/gu," "):" "),m=(s,e,n)=>{const i=v(s).matchAll(new RegExp(String.raw`(?:^|;)\s*${e}\s*(?:/\s*\d+\s*)?=\s*([a-z]+)([^;]*)`,"gi")),a=new RegExp(String.raw`\b${n.split(".").join(String.raw`\s*\.\s*`)}\s*=\s*"?([^\s;"]+)`,"i");return[...i].map(o=>{const t=a.exec(o[2]??"")?.[1];return{domain:t===void 0?null:t.slice(t.lastIndexOf("@")+1).toLowerCase(),result:(o[1]??"").toLowerCase()}})},h=s=>s===void 0||s===""?{dkim:[],dmarc:[],spf:[]}:{dkim:m(s,"dkim","header.d"),dmarc:m(s,"dmarc","header.from"),spf:m(s,"spf","smtp.mailfrom")},$=async s=>{const e=await l.parse(s),n={};for(const r of e.headers)c(`inbound header \`${r.key}\``,r.value),n[r.key]=r.value;const i=e.headers.find(r=>r.key==="authentication-results")?.value,a=(e.to??[]).map(r=>{const u=f(r);return c("inbound to",u),u}),o=e.from?f(e.from):"";return c("inbound from",o),{attachments:e.attachments.map(r=>({content:r.content,disposition:p(r.disposition),...r.encoding===void 0?{}:{encoding:r.encoding},filename:r.filename,mimeType:r.mimeType})),authentication:h(i),from:o,headers:n,...e.html===void 0?{}:{html:e.html},...d("inReplyTo",e.inReplyTo)===void 0?{}:{inReplyTo:e.inReplyTo},...d("messageId",e.messageId)===void 0?{}:{messageId:e.messageId},...d("references",e.references)===void 0?{}:{references:e.references},...d("subject",e.subject)===void 0?{}:{subject:e.subject},...e.text===void 0?{}:{text:e.text},to:a}},x=/<([^<>]*)>$/,b=s=>{const e=x.exec(s)?.[1]??s,n=e.indexOf("@");if(!(n===-1||n!==e.lastIndexOf("@")))return e.slice(n+1).trim().toLowerCase()},T=s=>{const e=b(s.from);if(e===void 0)return!1;const n=t=>t.some(r=>r.result==="pass"&&r.domain===e),{dkim:i,dmarc:a,spf:o}=s.authentication;return n(a)||n(o)||n(i)};export{T as authenticatesFrom,$ as parseInboundEmail};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b as O}from"./address-BKzIBZxE.mjs";import{MailSendError as y,isRetryableMailError as T,isOutcomeUnknownMailError as _}from"./MailSendError-BYih5mnM.mjs";const x=t=>{const e={...t};return delete e.react,e},N=86400,v=(t,e)=>`sending ${String(e)} ${t}`,E=(t,e)=>`failed ${String(e)} ${t}`,A=15*86400,k=t=>Math.max(t,A),w=1e4,D=1380*60*1e3,b=60,d=t=>new y({message:`@lunora/mail: ${t}`,retryable:!1}),$=t=>{if(!t||typeof t!="object"||Array.isArray(t))throw d("queue message body must be an object");const e=t;if(typeof e.subject!="string")throw d("queue message must have a string `subject`");const a=typeof e.to=="string",r=Array.isArray(e.to)&&e.to.every(c=>typeof c=="string");if(!a&&!r)throw d("queue message `to` must be a string or string[]");const n=(c,o)=>{if(o!==void 0){if(typeof o!="string")throw d(`queue message \`${c}\` must be a string`);return o}},s=(c,o)=>{if(o!==void 0){if(typeof o=="string")return[o];if(Array.isArray(o)&&o.every(u=>typeof u=="string"))return o;throw d(`queue message \`${c}\` must be a string or string[]`)}};let i;if(e.headers!==void 0){if(!e.headers||typeof e.headers!="object"||Array.isArray(e.headers))throw d("queue message `headers` must be an object of string values");const c=Object.entries(e.headers);for(const[o,u]of c)if(typeof u!="string")throw d(`queue message header "${o}" must be a string`);i=e.headers}const f=n("idempotencyKey",e.idempotencyKey);return O(f),{bcc:s("bcc",e.bcc),cc:s("cc",e.cc),from:n("from",e.from),headers:i,html:n("html",e.html),idempotencyKey:f,replyTo:n("replyTo",e.replyTo),subject:e.subject,text:n("text",e.text),to:e.to}},h=t=>{const e=t===void 0?0:Date.now()-t.getTime();return Number.isNaN(e)||e>=D},M=(t,e)=>{if(t&&h(e))throw new y({message:"@lunora/mail: an earlier delivery of this message may have been sent, and the provider no longer dedupes a key this old",outcomeUnknown:!0,retryable:!1})},S=async(t,e,a)=>{try{return await t.send(e)}catch(r){throw _(r)&&T(r)&&h(a)?new y({cause:r,message:"@lunora/mail: the send may have been delivered, and the provider no longer dedupes a key this old",outcomeUnknown:!0,retryable:!1}):r}},g=async t=>{let e;try{return await Promise.race([t,new Promise((a,r)=>{e=setTimeout(()=>{r(new Error(`the sent-mail store did not answer within ${String(w)}ms`))},w)})])}finally{clearTimeout(e)}},j=async(t,e,a)=>{const r=Array.from({length:a-1},(s,i)=>i+1);return(await g(Promise.all(r.map(async s=>await Promise.all([t.get(v(e,s)),t.get(E(e,s))]))))).some(([s,i])=>typeof s=="string"&&typeof i!="string")},I=async(t,e,a,r)=>{if(a<=1||!h(r))return;let n;try{n=await j(t,e,a)}catch(s){throw new y({cause:s,message:"@lunora/mail: could not read the sent-mail store",retryable:!0})}M(n,r)},p=(t,e,a,r)=>{const n=JSON.stringify({event:e,message:a,...r!==void 0&&{error:r instanceof Error?{message:r.message,name:r.name,stack:r.stack}:{message:typeof r=="string"?r:typeof r}}});console[t](n)},L=async(t,e,a,r)=>{try{await g(t.put(e,a,{expirationTtl:r}))}catch(n){p("error","lunora.mail.sent_record_failed","@lunora/mail: sent, but could not record the idempotency key; a redelivery may send again",n)}},q=async(t,e,a,r)=>{try{await g(t.put(E(e,a),"failed",{expirationTtl:k(r)}))}catch(n){p("warn","lunora.mail.attempt_mark_failed","@lunora/mail: could not mark a failed send; a late redelivery will be refused",n)}},R=async(t,e,a={})=>{const{attempts:r,enqueuedAt:n,sent:s,sentTtlSeconds:i=N}=a;if(!Number.isSafeInteger(i)||i<b)throw new y({message:`@lunora/mail: \`sentTtlSeconds\` must be a whole number of seconds, at least ${String(b)}`,retryable:!0});const f=$(e);if(!s)return"sent"in a&&p("warn","lunora.mail.sent_store_unbound","@lunora/mail: consumeQueuedSend got `sent: undefined` (is the KV namespace bound?), so redeliveries are not deduplicated"),M(r!==void 0&&r>1,n),{deduplicated:!1,...await S(t,f,n)};const l=f.idempotencyKey;if(l===void 0)throw d("queue message has no `idempotencyKey` to dedupe on");let c;try{c=await g(s.get(l))}catch(m){throw new y({cause:m,message:"@lunora/mail: could not read the sent-mail store",retryable:!0})}if(typeof c=="string")return{deduplicated:!0,id:c};const o=r??1;await I(s,l,o,n);try{await g(s.put(v(l,o),"sending",{expirationTtl:k(i)}))}catch(m){throw new y({cause:m,message:"@lunora/mail: could not mark the send in the sent-mail store",retryable:!0})}let u;try{({id:u}=await S(t,f,n))}catch(m){throw T(m)&&!_(m)&&await q(s,l,o,i),m}return await L(s,l,u,i),{deduplicated:!1,id:u}};export{R as consumeQueuedSend,x as toQueuedPayload};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createCaptureTransport as c}from"./createCaptureTransport-DZhMUmaI.mjs";import"./createCloudflareTransport-2pH3460e.mjs";import s from"./createMailer-DuQciU65.mjs";import{LunoraError as l}from"@lunora/errors";import{D as m,a as E,p as _}from"./shard-C5t-b7FX.mjs";import"./consumeQueuedSend-CDDDeoAz.mjs";import"./renderEmail-xypKDdux.mjs";import"./createResendTransport-DdsftR55.mjs";import"./MailSendError-BYih5mnM.mjs";const p="__lunora_admin__:recordMail",N=/^(?:dev(?:elopment)?|local(?:host)?|test)$/iu,f=["CF_ENV","ENVIRONMENT","NODE_ENV","WORKER_ENV"],R=(e,r)=>{const o=e[r];if(typeof o!="string"||o==="")throw new l("INTERNAL",`@lunora/mail: missing env var \`${r}\` — set it in .dev.vars (and \`wrangler secret put ${r}\` for secrets).`);return o},A=e=>{const r=e.LUNORA_MAIL_CAPTURE;if(typeof r=="string"){const t=r.toLowerCase();if(t==="1"||t==="true")return!0;if(t==="0"||t==="false")return!1;console.warn(`@lunora/mail: unrecognized LUNORA_MAIL_CAPTURE value "${r}" — expected "1"/"true" or "0"/"false"; falling back to environment detection.`)}const o=f.map(t=>e[t]).filter(t=>typeof t=="string"&&t!=="");return o.length>0&&o.every(t=>N.test(t))};let u=!1;const T=(e,r=m,o)=>({record:async t=>{const i=e.SHARD,a=typeof e.LUNORA_ADMIN_TOKEN=="string"?e.LUNORA_ADMIN_TOKEN:void 0;if(i===void 0||a===void 0)return u||(u=!0,console.warn("@lunora/mail: capturing mail but there is nowhere to record it — the `SHARD` binding and/or `LUNORA_ADMIN_TOKEN` is missing, so every captured message is discarded. Set both to see mail in the studio inbox, or set LUNORA_MAIL_CAPTURE=0 to deliver for real.")),{id:"uncaptured"};const d=E(i,o);try{return{id:(await _(d,{adminToken:a,envelope:{args:t,functionPath:p},label:"@lunora/mail: recording captured mail",shardKey:r})).result?.id??"captured"}}catch(n){return console.error("@lunora/mail: failed to record captured mail into the studio inbox —",n),{id:"uncaptured"}}}}),b=(e,r={})=>{const o=R(e,"MAIL_FROM");if(A(e))return s({from:o,queue:r.queue,sendTimeoutMs:r.sendTimeoutMs,transport:c(T(e,r.rootShard,r.jurisdiction))});const{cloudflareSend:t}=r,i=typeof e.RESEND_API_KEY=="string"&&e.RESEND_API_KEY!==""?e.RESEND_API_KEY:void 0;return s({apiKey:i,cloudflareSend:t,from:o,queue:r.queue,sendTimeoutMs:r.sendTimeoutMs})};export{T as createCaptureSink,b as createMailerFromEnv,A as shouldCaptureMail};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as l}from"@lunora/errors";import{a as i,b,d as h}from"./address-BKzIBZxE.mjs";import{isCaptureTransport as T}from"./createCaptureTransport-DZhMUmaI.mjs";import{createCloudflareTransport as p}from"./createCloudflareTransport-2pH3460e.mjs";import{toQueuedPayload as S}from"./consumeQueuedSend-CDDDeoAz.mjs";import E from"./renderEmail-xypKDdux.mjs";import g from"./createResendTransport-DdsftR55.mjs";import{MailSendError as c}from"./MailSendError-BYih5mnM.mjs";const q=()=>{if(typeof crypto<"u"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"){const r=crypto.getRandomValues(new Uint8Array(16));return Array.from(r,t=>t.toString(16).padStart(2,"0")).join("")}}throw new Error("randomSessionId: no Web Crypto available — a session id needs crypto.randomUUID or crypto.getRandomValues")},I=6e4,y=2147483647,U=async(r,t)=>{let d;const s=new Promise((m,f)=>{d=setTimeout(()=>{f(new c({message:`@lunora/mail: send timed out after ${String(t)}ms, so it may have been delivered`,outcomeUnknown:!0,retryable:!1}))},t)});try{return await Promise.race([r,s])}finally{clearTimeout(d)}},N=r=>{if(r.cloudflareSend)return p({from:r.from,send:r.cloudflareSend});if(r.apiKey)return g(r.apiKey,r.from);if(r.queue)return{send:()=>Promise.reject(new c({message:"@lunora/mail: no transport configured — this mailer can only queue(); pass `transport`, `cloudflareSend` (a SEND_EMAIL binding) or `apiKey` (Resend) to send()",retryable:!0}))};throw new l("INTERNAL","@lunora/mail: a transport is required — pass `transport`, `cloudflareSend` (Cloudflare Email Workers, the default), or `apiKey` (Resend), or a `queue` for a producer-only mailer")},P=r=>{if(!r.from)throw new l("INTERNAL","@lunora/mail: `from` is required");const t=r.sendTimeoutMs??I;if(!Number.isFinite(t)||t<=0||t>y)throw new l("INTERNAL",`@lunora/mail: \`sendTimeoutMs\` must be a positive number of milliseconds, at most ${String(y)}`);const d=r.transport??N(r),s=async e=>{let{html:u}=e,{text:o}=e;if(e.react){const n=await E(e.react);u=u??n.html,o=o??n.text}if(i("subject",e.subject),b(e.idempotencyKey),e.headers)for(const[n,w]of Object.entries(e.headers))i(`header name "${n}"`,n),i(`header "${n}" value`,w);const a=e.from??r.from;return h({bcc:e.bcc,cc:e.cc,from:a,replyTo:e.replyTo,to:e.to}),{bcc:e.bcc?.length?e.bcc:void 0,cc:e.cc?.length?e.cc:void 0,from:a,headers:e.headers,html:u,replyTo:e.replyTo,subject:e.subject,text:o,to:e.to}},m=async e=>{const u=await s(e),{idempotencyKey:o}=e;try{return await U(d.send(u,{idempotencyKey:o}),t)}catch(a){if(!(a instanceof c))throw new c({cause:a,retryable:!0});const n=o!==void 0&&d.dedupesOnIdempotencyKey===!0;throw a.outcomeUnknown&&a.retryable!==n?new c({cause:a.cause,message:a.message,outcomeUnknown:!0,retryable:n}):a}};return{queue:async e=>{if(!r.queue){if(T(d))return await m(e),{queued:!0};throw new l("INTERNAL","@lunora/mail: `queue` binding is required for mailer.queue()")}const u=await s(e),o=e.idempotencyKey??q();return await r.queue.send(S({...u,idempotencyKey:o})),{queued:!0}},send:m}};export{P as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as s,c as o}from"./address-BKzIBZxE.mjs";import{MailSendError as n}from"./MailSendError-BYih5mnM.mjs";const u=e=>e instanceof Error?e.message:e==null?"send failed":typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"||typeof e=="bigint"?e.toString():JSON.stringify(e)??"send failed",a=/^\d{3}$/,f=e=>typeof e=="number"?e:typeof e=="string"&&a.test(e)?Number(e):void 0,d="ETIMEDOUT",i=e=>{const t=[];for(let r=e;r instanceof Error&&t.length<5;r=r.cause)t.push(r);return t},m=e=>i(e).some(t=>"code"in t&&t.code===d),c=e=>{for(const t of i(e)){const r=f("code"in t?t.code:void 0);if(r!==void 0)return r}},l=409,h=e=>{if(!(e instanceof Error))return!0;const t=c(e);return t!==void 0&&t>=100&&t<=599?t===408||t===429||t>=500:!0},p=e=>{const t=s(e),[r]=t??[];if(!t||r===void 0)throw new n({message:"@lunora/mail: at least one recipient is required",retryable:!1});return{first:r,list:t}},T=(e,t,r)=>({bcc:s(e.bcc),cc:s(e.cc),from:o(e.from??t),headers:e.headers,html:e.html,replyTo:e.replyTo?o(e.replyTo):void 0,subject:e.subject,text:e.text,to:r}),g=e=>{if(e.success&&!e.data)throw new n({message:"@lunora/mail: provider accepted the send but returned no message id",retryable:!1});if(!e.success||!e.data)throw console.error(`@lunora/mail: send failed: ${u(e.error)}`),m(e.error)?new n({cause:e.error,message:"@lunora/mail: the provider timed out, so the send may have been delivered",outcomeUnknown:!0,retryable:!1}):c(e.error)===l?new n({cause:e.error,message:"@lunora/mail: the provider is still processing a send with this idempotency key, so it may be delivered",outcomeUnknown:!0,retryable:!1}):new n({cause:e.error,retryable:h(e.error)});return{id:e.data.messageId}};export{g as i,p as r,T as t};
|