@sanoma-ai/connector-resend 0.4.8 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -19
- package/dist/connector.d.ts +120 -4
- package/dist/connector.js +104 -5
- package/dist/connector.js.map +1 -1
- package/dist/domains.d.ts +191 -0
- package/dist/domains.js +210 -0
- package/dist/domains.js.map +1 -0
- package/dist/driver.d.ts +3 -3
- package/dist/driver.js +74 -21
- package/dist/driver.js.map +1 -1
- package/dist/fake.d.ts +56 -7
- package/dist/fake.js +86 -7
- package/dist/fake.js.map +1 -1
- package/dist/generated/index.d.ts +2 -2
- package/dist/generated/index.js +1 -1
- package/dist/generated/index.js.map +1 -1
- package/dist/generated/sdk.gen.d.ts +23 -1
- package/dist/generated/sdk.gen.js +46 -0
- package/dist/generated/sdk.gen.js.map +1 -1
- package/dist/generated/types.gen.d.ts +321 -0
- package/dist/index.d.ts +46 -4
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/resources.d.ts +47 -0
- package/dist/resources.js +7 -0
- package/dist/resources.js.map +1 -0
- package/dist/steps.d.ts +4 -3
- package/dist/steps.js +6 -3
- package/dist/steps.js.map +1 -1
- package/features/domain.feature +82 -0
- package/features/emails.feature +1 -1
- package/package.json +9 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @sanoma-ai/connector-resend
|
|
2
2
|
|
|
3
|
-
[Resend Broadcasts API](https://resend.com/docs/api-reference/broadcasts) and [one-email send](https://resend.com/docs/api-reference/emails/send-email) operations for [`@sanoma-ai/workflows`](https://www.npmjs.com/package/@sanoma-ai/workflows).
|
|
3
|
+
[Resend Broadcasts API](https://resend.com/docs/api-reference/broadcasts) and [one-email send](https://resend.com/docs/api-reference/emails/send-email) operations for [`@sanoma-ai/workflows`](https://www.npmjs.com/package/@sanoma-ai/workflows), and the [sending domain](#sending-domain) they send from, as a resource a data file declares.
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
@@ -22,23 +22,68 @@ defineWorkflow({
|
|
|
22
22
|
// ...
|
|
23
23
|
uses: [resend.broadcast.create, resend.broadcast.send],
|
|
24
24
|
run: async (ctx, input) => {
|
|
25
|
-
const email = await ctx.resend.broadcast.create({
|
|
25
|
+
const email = await ctx.resend.broadcast.create({
|
|
26
|
+
audience: "newsletter",
|
|
27
|
+
from: "Acme <news@acme.example>",
|
|
28
|
+
subject: input.title,
|
|
29
|
+
html: input.body,
|
|
30
|
+
});
|
|
26
31
|
return ctx.resend.broadcast.send({ id: email.id });
|
|
27
32
|
},
|
|
28
33
|
});
|
|
29
34
|
```
|
|
30
35
|
|
|
31
|
-
`emails.send` takes `to` (an address, or a list of 1 to 50), `subject`, `html`, `text` or both (Resend makes the text from the HTML when there is none), and
|
|
36
|
+
`emails.send` takes `to` (an address, or a list of 1 to 50), `from` (required, see below), `subject`, and `html`, `text` or both (Resend makes the text from the HTML when there is none), and returns the email's `{ id }`:
|
|
32
37
|
|
|
33
38
|
```ts
|
|
34
39
|
defineWorkflow({
|
|
35
40
|
// ...
|
|
36
41
|
uses: [resend.emails.send],
|
|
37
42
|
run: async (ctx, input) =>
|
|
38
|
-
ctx.resend.emails.send({
|
|
43
|
+
ctx.resend.emails.send({
|
|
44
|
+
to: input.email,
|
|
45
|
+
from: "Acme <hello@acme.example>",
|
|
46
|
+
subject: "Following up",
|
|
47
|
+
text: `Hi ${input.name},…`,
|
|
48
|
+
}),
|
|
39
49
|
});
|
|
40
50
|
```
|
|
41
51
|
|
|
52
|
+
## Sending domain
|
|
53
|
+
|
|
54
|
+
`resend.domain`, from `@sanoma-ai/connector-resend/resources`, is a domain Resend sends from, which a data file declares. Its `dns_records` are the records the domain's zone must hold, in the shape `dnsRecord` (from `@sanoma-ai/workflows`) gives them, so a zone's record set can take them whole, as `cloudflare.records` (in `@sanoma-ai/connector-cloudflare`) does through `from: "dns_records"`:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
// resources/mail.ts
|
|
58
|
+
import { cloudflare } from "@sanoma-ai/connector-cloudflare/resources";
|
|
59
|
+
import { resend } from "@sanoma-ai/connector-resend/resources";
|
|
60
|
+
|
|
61
|
+
export const mail = resend.domain({ name: "sanoma.work" });
|
|
62
|
+
export const mailDns = cloudflare.records({ zone: "sanoma.work", name: "resend", records: mail });
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
| Field | Who sets it | What it is |
|
|
66
|
+
| -------------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
67
|
+
| `name` | declared (identity) | The domain, in lower case: `example.com`, or a subdomain such as `mail.example.com` (Resend recommends one). Apply finds a domain of that name in the account and binds it. |
|
|
68
|
+
| `region` | declared, optional | Where Resend sends from: `us-east-1` (Resend's default), `eu-west-1`, `sa-east-1` or `ap-northeast-1`. |
|
|
69
|
+
| `custom_return_path` | declared, optional | The Return-Path subdomain, `send` by default (`send.example.com`). A read takes it from the name of the domain's SPF record; one none shows is not drift. |
|
|
70
|
+
| `id` | Resend | The domain's id, which the binding keeps. |
|
|
71
|
+
| `status` | Resend | `not_started`, `pending`, `verified`, `failed`, `temporary_failure`, `partially_verified` or `partially_failed`. |
|
|
72
|
+
| `records` | Resend | The DNS records Resend asks for, as Resend gives them (`record`, `name`, `type`, `value`, `ttl`, `status`, `priority`). |
|
|
73
|
+
| `dns_records` | Resend | The same records as a zone holds them: `{ type, name, content, priority?, ttl }`, each `name` in full and in lower case with no trailing dot, a TXT record's text without quotes, `ttl` 1 for Resend's `Auto`. |
|
|
74
|
+
|
|
75
|
+
`name`, `region` and `custom_return_path` cannot change: a declaration that changes one plans a replace, which deletes the domain (Resend holds one domain of a name) and makes it again, with a new DKIM key, so new records; apply asks first.
|
|
76
|
+
|
|
77
|
+
Apply creates the domain, asks Resend to verify it at once, and reads it. Resend keeps checking for up to 72 hours, so the records the same apply writes a few seconds later verify it.
|
|
78
|
+
|
|
79
|
+
A domain is declared `verified`: any other status (`partially_verified` too) is drift (`status: verified → pending`), and apply plans an `update`, which asks Resend to verify it again.
|
|
80
|
+
|
|
81
|
+
A create tried again after its reply was lost finds the name registered already, and takes the domain of that name in the account, unless its region or Return-Path is not the one declared (refused, `conflict`). When another account holds it, the create is refused (`registered`): [claim it](https://resend.com/docs/dashboard/domains/claim) in Resend's dashboard.
|
|
82
|
+
|
|
83
|
+
An update approved while the domain was pending, which finds Resend has verified it since, is done. A replace that deleted the domain and then failed (`replace_incomplete` when its create failed, naming the deleted domain) finishes when tried again: the domain is gone, so it makes it, taking the one the failed try made.
|
|
84
|
+
|
|
85
|
+
Domains need a full-access API key: Resend answers a sending-only key's domain calls 401 `restricted_api_key`, which the driver refuses, saying so. Resend's free plan has 3 domains. Later: TLS (`tls`), open and click tracking and their subdomain, and receiving, which the type does not declare yet (Resend's defaults hold; a domain with any of them on has their records among `records` and `dns_records` too).
|
|
86
|
+
|
|
42
87
|
The logo the app shows beside these operations is Resend's lettermark from its [brand kit](https://resend.com/brand), black or white. It is there only to identify the service an operation calls.
|
|
43
88
|
|
|
44
89
|
## Driver
|
|
@@ -53,7 +98,7 @@ export default defineConfig({ workflows, connectors: [resend], policy });
|
|
|
53
98
|
|
|
54
99
|
`./driver` (`resendDriver`; `resendDriver({ timeoutMs })`, 15 s by default) and `./fake` (`fakeResend`) are internal entries, for tests.
|
|
55
100
|
|
|
56
|
-
`audience` is Resend's `segment_id` (Resend renamed audiences to segments). `from`, for a broadcast or an email,
|
|
101
|
+
`audience` is Resend's `segment_id` (Resend renamed audiences to segments). `from`, for a broadcast or an email, is the input's, a sender on a domain verified in Resend; Resend requires one, and the input refuses none (or an empty one), as do the driver and the fake, before calling Resend. The environment gives no sender: sign-in codes are sent from the config's `login.from` (`login: { sender: resend.emails.send, from: "Acme <login@acme.example>" }`). `broadcast.send` returns `status: "queued"` when it sends: Resend replies with the id only and sends in the background.
|
|
57
102
|
|
|
58
103
|
The client is generated by [Hey API](https://heyapi.dev) from Resend's [OpenAPI spec](https://github.com/resend/resend-openapi), pinned to a commit and cut to the operations it calls in `openapi-ts.config.ts`: `pnpm run generate` rewrites `src/generated/`, which is never edited by hand.
|
|
59
104
|
|
|
@@ -61,12 +106,11 @@ The client is generated by [Hey API](https://heyapi.dev) from Resend's [OpenAPI
|
|
|
61
106
|
|
|
62
107
|
It reads this on every call, never when the config loads:
|
|
63
108
|
|
|
64
|
-
| Variable | What it is
|
|
65
|
-
| ---------------- |
|
|
66
|
-
| `RESEND_API_KEY` | A Resend API key.
|
|
67
|
-
| `RESEND_FROM` | Optional: the sender of a broadcast or email whose input has no `from`, such as `Acme <news@acme.example>`, on a domain verified in Resend. |
|
|
109
|
+
| Variable | What it is |
|
|
110
|
+
| ---------------- | ------------------------------------------------------------------------------------------------ |
|
|
111
|
+
| `RESEND_API_KEY` | A Resend API key: a full-access one for [sending domains](#sending-domain), else sending access. |
|
|
68
112
|
|
|
69
|
-
When the key is unset, a call fails, not retryable, naming it; so does a `broadcast.create` or `emails.send` with no
|
|
113
|
+
When the key is unset, a call fails, not retryable, naming it; so does a `broadcast.create` or `emails.send` with no `from`. The driver declares the key in its `env` ([Credentials](https://www.npmjs.com/package/@sanoma-ai/workflows#credentials)): the worker starts without the key, warning, and the app's connector page shows its status and lets you set it.
|
|
70
114
|
|
|
71
115
|
### Idempotency
|
|
72
116
|
|
|
@@ -74,7 +118,7 @@ Resend documents `Idempotency-Key` for emails only, not broadcasts. `emails.send
|
|
|
74
118
|
|
|
75
119
|
### Errors and retries
|
|
76
120
|
|
|
77
|
-
A 408, a 429 (except `daily_quota_exceeded` and `monthly_quota_exceeded`), a 409 `concurrent_idempotent_requests` (a request with the same key still in flight), a 5xx, a timeout (15 s; `timeoutMs` changes it) or no reply is retryable; any other 4xx is not. `status` and `vendorCode` (Resend's error `name`) are kept. Resend allows 10 requests per second per team.
|
|
121
|
+
A 408, a 429 (except `daily_quota_exceeded` and `monthly_quota_exceeded`), a 409 `concurrent_idempotent_requests` (a request with the same key still in flight) or `resource_locked` (another request on the same resource), a 5xx, a timeout (15 s; `timeoutMs` changes it) or no reply is retryable; any other 4xx is not. `status` and `vendorCode` (Resend's error `name`) are kept. Resend allows 10 requests per second per team.
|
|
78
122
|
|
|
79
123
|
### Plan
|
|
80
124
|
|
|
@@ -90,22 +134,31 @@ SANOMA_LIVE=1 RESEND_API_KEY=re_... RESEND_TEST_AUDIENCE=<segment id> RESEND_TES
|
|
|
90
134
|
|
|
91
135
|
A recording loses ids, addresses, the sender's domain and keys. The error cases, and the broadcasts that are no longer drafts, only replay.
|
|
92
136
|
|
|
137
|
+
The sending domain's replies (`features/domain.feature`'s fixtures and `domain-restricted-key.json`) are **written from Resend's API reference, not recorded**: no account was at hand when the type was written, so a reply the reference gets wrong is wrong here too, and the first live run re-records them. That run needs a full-access key and a throwaway domain you own, which it creates and deletes (one of the free plan's 3): put the domain in place of `example.com` in `features/domain.feature` for the run, and in `RESEND_TEST_DOMAIN`, which the scrub turns back into `example.com` (with each DKIM key's `p=…` as `p=redacted`), then put the feature back:
|
|
138
|
+
|
|
139
|
+
```sh
|
|
140
|
+
SANOMA_LIVE=1 SANOMA_RECORD=1 RESEND_API_KEY=re_... RESEND_TEST_AUDIENCE=<segment id> RESEND_TEST_DOMAIN=<domain> pnpm vitest run connectors/resend/test/features.test.ts
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
It checks what the reference leaves open: whether Resend names a subdomain's records relative to the zone (`send.mail`) or to the domain (`send`), the read's TXT quoting, and the 403 a name registered already gets. The driver's domain tests only replay.
|
|
144
|
+
|
|
93
145
|
## Steps and features
|
|
94
146
|
|
|
95
147
|
The connector carries steps for [scenarios](https://github.com/Sanoma-AI/sanoma/blob/main/packages/workflows/README.md#steps-a-connector-ships) (`resendSteps`, attached with `withSetup`), which a company's scenario can use beside the generic steps and other connectors' ones:
|
|
96
148
|
|
|
97
|
-
| Keyword | Step | What it does
|
|
98
|
-
| ------- | --------------------------------------- |
|
|
99
|
-
| Given | `a Resend broadcast {string}` | Seeds a draft broadcast with that subject through `resend.broadcast.create`, named `broadcast` (`$broadcast.id`)
|
|
100
|
-
| Given | `Resend
|
|
101
|
-
|
|
|
102
|
-
| Then | `
|
|
149
|
+
| Keyword | Step | What it does |
|
|
150
|
+
| ------- | --------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
151
|
+
| Given | `a Resend broadcast {string}` | Seeds a draft broadcast with that subject through `resend.broadcast.create`, named `broadcast` (`$broadcast.id`) |
|
|
152
|
+
| Given | `a Resend domain {string}` | Seeds a sending domain of that name through `resend.domain.create`, asked to verify, named `domain` (`$domain.id`) |
|
|
153
|
+
| Given | `Resend fails to send once` | The next `resend.broadcast.send` fails (`failNext`) |
|
|
154
|
+
| Then | `the Resend broadcast {string} is sent` | The broadcast with that subject, seeded or created by the run, was sent |
|
|
155
|
+
| Then | `a Resend email to {string} is sent` | The run sent an email to that address, alone or in its list |
|
|
103
156
|
|
|
104
|
-
`features/broadcast.feature` creates and sends a broadcast,
|
|
157
|
+
`features/broadcast.feature` creates and sends a broadcast, `features/emails.feature` sends an email, and `features/domain.feature` creates, reads, imports, plans and deletes a sending domain, with these steps and the generic ones for an operation's own test, on the fake and on Resend's replies (`create-and-send.json`, `send-an-email.json`, and the domain's, written from the reference): `test/features.test.ts` runs them with [`describeFeatures`](https://github.com/Sanoma-AI/sanoma/blob/main/packages/testing/README.md#a-connectors-own-features). A scenario tagged `@fake-only` has no recording. The package ships `features/`.
|
|
105
158
|
|
|
106
159
|
## Testing
|
|
107
160
|
|
|
108
|
-
`@sanoma-ai/connector-resend/fake` is an in-memory Resend that emails nobody, the fake the connector carries: each sandbox run makes one of its own. A test that reads or seeds one attaches it to the connector itself, then checks `state.broadcasts`, `state.emails` (the emails sent, by id) and `calls`.
|
|
161
|
+
`@sanoma-ai/connector-resend/fake` is an in-memory Resend that emails nobody, the fake the connector carries: each sandbox run makes one of its own. A test that reads or seeds one attaches it to the connector itself, then checks `state.broadcasts`, `state.emails` (the emails sent, by id), `state.domains` (the sending domains, by id, as Resend gives them) and `calls`.
|
|
109
162
|
|
|
110
163
|
```ts
|
|
111
164
|
import { withSetup } from "@sanoma-ai/workflows";
|
|
@@ -130,8 +183,15 @@ Like Resend, the fake refuses to send a broadcast twice, unless the second call
|
|
|
130
183
|
- `fake.rateLimit("resend.broadcast.send")` throws a `DriverError` with status 429.
|
|
131
184
|
- `const release = fake.hold("resend.broadcast.send")` makes the call wait until `release()`.
|
|
132
185
|
|
|
186
|
+
A domain it makes has a DKIM key made from its id, an MX record `feedback-smtp.<region>.amazonses.com` (priority 10) and an SPF TXT record, named relative to the zone as Resend names them (the fake takes the zone to be the last two labels). Asked to verify, it stays `pending`, as at Resend until the zone holds the records: `fake.verifyDomain(id)` makes it and its records `verified`, `fake.failDomain(id)` `failed`. Like Resend, it holds one domain of a name. Like the driver, it refuses a send with no `from`.
|
|
187
|
+
|
|
133
188
|
`fake.reset()` empties it between tests. Pass `{ calls }` with one array to several fakes to see their calls in one order.
|
|
134
189
|
|
|
135
190
|
[`@sanoma-ai/testing`](https://github.com/Sanoma-AI/sanoma/blob/main/packages/testing/README.md) (in the sanoma repository, not published) has `startTestWorker` and `testDatabaseUrl` to run a test's worker with the fake on a database of its own.
|
|
136
191
|
|
|
192
|
+
## Changes
|
|
193
|
+
|
|
194
|
+
- 0.6.0: `RESEND_FROM` is retired: `from` is required in `broadcast.create` and `emails.send`, a send with none is refused (by the driver and the fake alike) whatever the environment holds, and the driver declares only `RESEND_API_KEY`. Sign-in codes are sent from the config's `login.from` (`@sanoma-ai/workflows` 0.11.0).
|
|
195
|
+
- 0.5.0: the resource type `resend.domain`. `RESEND_FROM` is deprecated: it still stands in for a missing `from`, warning once, and retires once `login.from` exists (sanoma#531), so pass `from`. It needs `@sanoma-ai/workflows` 0.10.5 or later, for `from` references.
|
|
196
|
+
|
|
137
197
|
License: FSL-1.1-ALv2.
|
package/dist/connector.d.ts
CHANGED
|
@@ -1,16 +1,131 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
/** The regions Resend sends from (https://resend.com/docs/api-reference/domains/create-domain). */
|
|
3
|
+
declare const REGIONS: readonly ["us-east-1", "eu-west-1", "sa-east-1", "ap-northeast-1"];
|
|
4
|
+
export type Region = (typeof REGIONS)[number];
|
|
5
|
+
/** The region a domain sends from when its declaration names none: Resend's default. */
|
|
6
|
+
export declare const DEFAULT_REGION = "us-east-1";
|
|
7
|
+
/** The Return-Path subdomain when a declaration names none: Resend's default (`send.example.com`). */
|
|
8
|
+
export declare const DEFAULT_RETURN_PATH = "send";
|
|
9
|
+
/** A domain's status at Resend: `verified` once its DNS records are found, the rest until then or when they are lost. */
|
|
10
|
+
declare const STATUSES: readonly ["not_started", "pending", "verified", "failed", "temporary_failure", "partially_verified", "partially_failed"];
|
|
11
|
+
export type DomainStatus = (typeof STATUSES)[number];
|
|
12
|
+
/** A DNS record as Resend gives it: its own fields, its name as Resend writes it. */
|
|
13
|
+
export declare const resendRecord: z.ZodObject<{
|
|
14
|
+
record: z.ZodString;
|
|
15
|
+
name: z.ZodString;
|
|
16
|
+
type: z.ZodString;
|
|
17
|
+
value: z.ZodString;
|
|
18
|
+
ttl: z.ZodOptional<z.ZodString>;
|
|
19
|
+
status: z.ZodOptional<z.ZodString>;
|
|
20
|
+
priority: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
}, z.core.$strip>;
|
|
2
22
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
23
|
+
* `resend.domain({ name, region?, custom_return_path? })`: a domain Resend sends from. Apply
|
|
24
|
+
* creates it and asks Resend to verify it, which Resend keeps checking for 72 hours; its
|
|
25
|
+
* `dns_records` are what the zone must hold, which `cloudflare.records` takes (`from:
|
|
26
|
+
* "dns_records"`). A domain is declared verified, so one Resend has not verified is drift, and
|
|
27
|
+
* apply asks Resend to verify it again.
|
|
28
|
+
*/
|
|
29
|
+
export declare const domain: import("@sanoma-ai/workflows").Resource<z.ZodObject<{
|
|
30
|
+
name: z.ZodString;
|
|
31
|
+
region: z.ZodOptional<z.ZodEnum<{
|
|
32
|
+
"ap-northeast-1": "ap-northeast-1";
|
|
33
|
+
"eu-west-1": "eu-west-1";
|
|
34
|
+
"sa-east-1": "sa-east-1";
|
|
35
|
+
"us-east-1": "us-east-1";
|
|
36
|
+
}>>;
|
|
37
|
+
custom_return_path: z.ZodOptional<z.ZodString>;
|
|
38
|
+
id: z.ZodOptional<z.ZodString>;
|
|
39
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
40
|
+
failed: "failed";
|
|
41
|
+
not_started: "not_started";
|
|
42
|
+
partially_failed: "partially_failed";
|
|
43
|
+
partially_verified: "partially_verified";
|
|
44
|
+
pending: "pending";
|
|
45
|
+
temporary_failure: "temporary_failure";
|
|
46
|
+
verified: "verified";
|
|
47
|
+
}>>;
|
|
48
|
+
records: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
49
|
+
record: z.ZodString;
|
|
50
|
+
name: z.ZodString;
|
|
51
|
+
type: z.ZodString;
|
|
52
|
+
value: z.ZodString;
|
|
53
|
+
ttl: z.ZodOptional<z.ZodString>;
|
|
54
|
+
status: z.ZodOptional<z.ZodString>;
|
|
55
|
+
priority: z.ZodOptional<z.ZodNumber>;
|
|
56
|
+
}, z.core.$strip>>>;
|
|
57
|
+
dns_records: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
58
|
+
type: z.ZodEnum<{
|
|
59
|
+
CAA: "CAA";
|
|
60
|
+
CNAME: "CNAME";
|
|
61
|
+
MX: "MX";
|
|
62
|
+
TXT: "TXT";
|
|
63
|
+
}>;
|
|
64
|
+
name: z.ZodString;
|
|
65
|
+
content: z.ZodString;
|
|
66
|
+
priority: z.ZodOptional<z.ZodNumber>;
|
|
67
|
+
ttl: z.ZodOptional<z.ZodNumber>;
|
|
68
|
+
}, z.core.$strip>>>;
|
|
69
|
+
}, z.core.$strip>, "resend.domain", {}, true>;
|
|
70
|
+
/**
|
|
71
|
+
* The sender, the input's `from` (unless empty): the driver and the fake refuse a send with none,
|
|
72
|
+
* as the schema does, for a call that skipped it.
|
|
73
|
+
*/
|
|
74
|
+
export declare function senderOf(op: string, from: string | undefined): string;
|
|
75
|
+
/**
|
|
76
|
+
* Resend's Broadcasts API (https://resend.com/docs/api-reference/broadcasts), its one-email send
|
|
77
|
+
* (https://resend.com/docs/api-reference/emails/send-email) and its sending domains, the resource
|
|
78
|
+
* type `resend.domain` (https://resend.com/docs/api-reference/domains).
|
|
5
79
|
*/
|
|
6
80
|
export declare const resendOps: import("@sanoma-ai/workflows").Connector<"resend", {
|
|
81
|
+
readonly domain: import("@sanoma-ai/workflows").Resource<z.ZodObject<{
|
|
82
|
+
name: z.ZodString;
|
|
83
|
+
region: z.ZodOptional<z.ZodEnum<{
|
|
84
|
+
"ap-northeast-1": "ap-northeast-1";
|
|
85
|
+
"eu-west-1": "eu-west-1";
|
|
86
|
+
"sa-east-1": "sa-east-1";
|
|
87
|
+
"us-east-1": "us-east-1";
|
|
88
|
+
}>>;
|
|
89
|
+
custom_return_path: z.ZodOptional<z.ZodString>;
|
|
90
|
+
id: z.ZodOptional<z.ZodString>;
|
|
91
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
92
|
+
failed: "failed";
|
|
93
|
+
not_started: "not_started";
|
|
94
|
+
partially_failed: "partially_failed";
|
|
95
|
+
partially_verified: "partially_verified";
|
|
96
|
+
pending: "pending";
|
|
97
|
+
temporary_failure: "temporary_failure";
|
|
98
|
+
verified: "verified";
|
|
99
|
+
}>>;
|
|
100
|
+
records: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
101
|
+
record: z.ZodString;
|
|
102
|
+
name: z.ZodString;
|
|
103
|
+
type: z.ZodString;
|
|
104
|
+
value: z.ZodString;
|
|
105
|
+
ttl: z.ZodOptional<z.ZodString>;
|
|
106
|
+
status: z.ZodOptional<z.ZodString>;
|
|
107
|
+
priority: z.ZodOptional<z.ZodNumber>;
|
|
108
|
+
}, z.core.$strip>>>;
|
|
109
|
+
dns_records: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
110
|
+
type: z.ZodEnum<{
|
|
111
|
+
CAA: "CAA";
|
|
112
|
+
CNAME: "CNAME";
|
|
113
|
+
MX: "MX";
|
|
114
|
+
TXT: "TXT";
|
|
115
|
+
}>;
|
|
116
|
+
name: z.ZodString;
|
|
117
|
+
content: z.ZodString;
|
|
118
|
+
priority: z.ZodOptional<z.ZodNumber>;
|
|
119
|
+
ttl: z.ZodOptional<z.ZodNumber>;
|
|
120
|
+
}, z.core.$strip>>>;
|
|
121
|
+
}, z.core.$strip>, "resend.domain", {}, true>;
|
|
7
122
|
readonly broadcast: {
|
|
8
123
|
readonly create: {
|
|
9
124
|
readonly effect: "write";
|
|
10
125
|
readonly description: "Create a broadcast to an audience. Nothing is sent.";
|
|
11
126
|
readonly input: z.ZodObject<{
|
|
12
127
|
audience: z.ZodString;
|
|
13
|
-
from: z.
|
|
128
|
+
from: z.ZodString;
|
|
14
129
|
subject: z.ZodString;
|
|
15
130
|
html: z.ZodString;
|
|
16
131
|
}, z.core.$strip>;
|
|
@@ -42,7 +157,7 @@ export declare const resendOps: import("@sanoma-ai/workflows").Connector<"resend
|
|
|
42
157
|
readonly description: "Send one email to an address, or to a list of up to 50. Cannot be undone.";
|
|
43
158
|
readonly input: z.ZodObject<{
|
|
44
159
|
to: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
45
|
-
from: z.
|
|
160
|
+
from: z.ZodString;
|
|
46
161
|
subject: z.ZodString;
|
|
47
162
|
html: z.ZodOptional<z.ZodString>;
|
|
48
163
|
text: z.ZodOptional<z.ZodString>;
|
|
@@ -53,3 +168,4 @@ export declare const resendOps: import("@sanoma-ai/workflows").Connector<"resend
|
|
|
53
168
|
};
|
|
54
169
|
};
|
|
55
170
|
}>;
|
|
171
|
+
export {};
|
package/dist/connector.js
CHANGED
|
@@ -1,17 +1,116 @@
|
|
|
1
|
-
import { defineConnector, vendorInfo } from "@sanoma-ai/workflows";
|
|
1
|
+
import { compareDeclared, defineConnector, defineResource, dnsRecord, DriverError, vendorInfo, } from "@sanoma-ai/workflows";
|
|
2
|
+
import { DOMAIN_NAME } from "@sanoma-ai/workflows/shared";
|
|
2
3
|
import { z } from "zod";
|
|
4
|
+
/** The regions Resend sends from (https://resend.com/docs/api-reference/domains/create-domain). */
|
|
5
|
+
const REGIONS = ["us-east-1", "eu-west-1", "sa-east-1", "ap-northeast-1"];
|
|
6
|
+
/** The region a domain sends from when its declaration names none: Resend's default. */
|
|
7
|
+
export const DEFAULT_REGION = "us-east-1";
|
|
8
|
+
/** The Return-Path subdomain when a declaration names none: Resend's default (`send.example.com`). */
|
|
9
|
+
export const DEFAULT_RETURN_PATH = "send";
|
|
10
|
+
/** A domain's status at Resend: `verified` once its DNS records are found, the rest until then or when they are lost. */
|
|
11
|
+
const STATUSES = [
|
|
12
|
+
"not_started",
|
|
13
|
+
"pending",
|
|
14
|
+
"verified",
|
|
15
|
+
"failed",
|
|
16
|
+
"temporary_failure",
|
|
17
|
+
"partially_verified",
|
|
18
|
+
"partially_failed",
|
|
19
|
+
];
|
|
20
|
+
/** A DNS record as Resend gives it: its own fields, its name as Resend writes it. */
|
|
21
|
+
export const resendRecord = z.object({
|
|
22
|
+
record: z.string().describe("What it is for: `SPF` and `DKIM` for sending, `Receiving`, `Tracking`, `TrackingCAA`"),
|
|
23
|
+
name: z.string(),
|
|
24
|
+
type: z.string(),
|
|
25
|
+
value: z.string(),
|
|
26
|
+
ttl: z.string().optional(),
|
|
27
|
+
status: z.string().optional(),
|
|
28
|
+
priority: z.number().int().optional(),
|
|
29
|
+
});
|
|
30
|
+
/** A sending domain as the operations read it: what a data file declares, and what Resend sets. */
|
|
31
|
+
const domainSchema = z.object({
|
|
32
|
+
name: z
|
|
33
|
+
.string()
|
|
34
|
+
.regex(DOMAIN_NAME, "a domain name in lower case, such as `example.com` or `mail.example.com`")
|
|
35
|
+
.describe("The domain to send from, such as `example.com`, or a subdomain such as `mail.example.com`"),
|
|
36
|
+
region: z
|
|
37
|
+
.enum(REGIONS)
|
|
38
|
+
.optional()
|
|
39
|
+
.describe("Where Resend sends from: `us-east-1` (the default), `eu-west-1`, `sa-east-1` or `ap-northeast-1`"),
|
|
40
|
+
custom_return_path: z
|
|
41
|
+
.string()
|
|
42
|
+
.regex(/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/, "one DNS label in lower case, such as `send`")
|
|
43
|
+
.optional()
|
|
44
|
+
.describe("The Return-Path subdomain, `send` by default (`send.example.com`)"),
|
|
45
|
+
id: z.string().optional().describe("The domain's id at Resend"),
|
|
46
|
+
status: z.enum(STATUSES).optional().describe("Whether Resend found its DNS records: `verified` once it has"),
|
|
47
|
+
records: z.array(resendRecord).optional().describe("The DNS records Resend asks for, as Resend gives them"),
|
|
48
|
+
dns_records: z
|
|
49
|
+
.array(dnsRecord)
|
|
50
|
+
.optional()
|
|
51
|
+
.describe("The same records as a zone holds them: full lower-case names, TXT text unquoted, ttl 1 for automatic"),
|
|
52
|
+
});
|
|
53
|
+
/** A domain's fields: what Resend sets, and what it cannot change in place. */
|
|
54
|
+
const fields = {
|
|
55
|
+
immutable: ["name", "region", "custom_return_path"],
|
|
56
|
+
vendorOwned: ["id", "status", "records", "dns_records"],
|
|
57
|
+
writeOnly: [],
|
|
58
|
+
};
|
|
3
59
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
60
|
+
* `resend.domain({ name, region?, custom_return_path? })`: a domain Resend sends from. Apply
|
|
61
|
+
* creates it and asks Resend to verify it, which Resend keeps checking for 72 hours; its
|
|
62
|
+
* `dns_records` are what the zone must hold, which `cloudflare.records` takes (`from:
|
|
63
|
+
* "dns_records"`). A domain is declared verified, so one Resend has not verified is drift, and
|
|
64
|
+
* apply asks Resend to verify it again.
|
|
65
|
+
*/
|
|
66
|
+
export const domain = defineResource({
|
|
67
|
+
vendor: "resend",
|
|
68
|
+
type: "domain",
|
|
69
|
+
title: "Domain",
|
|
70
|
+
identity: "name",
|
|
71
|
+
schema: domainSchema,
|
|
72
|
+
fields,
|
|
73
|
+
find: ({ name }) => name,
|
|
74
|
+
bindingId: (state) => String(state.id),
|
|
75
|
+
// The status is compared too, declared `verified` (a declaration never holds one). A Return-Path
|
|
76
|
+
// the records do not show (no SPF record read) is not drift: the read cannot tell it.
|
|
77
|
+
normalize: (state, desired) => ({
|
|
78
|
+
...compareDeclared(fields, state, desired),
|
|
79
|
+
...(state.custom_return_path === undefined && { custom_return_path: desired.custom_return_path }),
|
|
80
|
+
status: state.status ?? "verified",
|
|
81
|
+
}),
|
|
82
|
+
writable: true,
|
|
83
|
+
// Its DKIM key is Resend's: one made again needs new DNS records, so apply asks first.
|
|
84
|
+
stateless: false,
|
|
85
|
+
});
|
|
86
|
+
/** A broadcast's or an email's sender: Resend requires one, and the environment gives none. */
|
|
87
|
+
const sender = z
|
|
88
|
+
.string()
|
|
89
|
+
.min(1)
|
|
90
|
+
.describe("The sender, such as `Acme <news@acme.example>`, on a domain verified in Resend");
|
|
91
|
+
/**
|
|
92
|
+
* The sender, the input's `from` (unless empty): the driver and the fake refuse a send with none,
|
|
93
|
+
* as the schema does, for a call that skipped it.
|
|
94
|
+
*/
|
|
95
|
+
export function senderOf(op, from) {
|
|
96
|
+
if (from)
|
|
97
|
+
return from;
|
|
98
|
+
throw new DriverError(`resend: ${op} needs \`from\` in its input, a sender on a domain verified in Resend (for sign-in codes, the config's \`login.from\`)`, { retryable: false });
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Resend's Broadcasts API (https://resend.com/docs/api-reference/broadcasts), its one-email send
|
|
102
|
+
* (https://resend.com/docs/api-reference/emails/send-email) and its sending domains, the resource
|
|
103
|
+
* type `resend.domain` (https://resend.com/docs/api-reference/domains).
|
|
6
104
|
*/
|
|
7
105
|
export const resendOps = defineConnector("resend", {
|
|
106
|
+
domain,
|
|
8
107
|
broadcast: {
|
|
9
108
|
create: {
|
|
10
109
|
effect: "write",
|
|
11
110
|
description: "Create a broadcast to an audience. Nothing is sent.",
|
|
12
111
|
input: z.object({
|
|
13
112
|
audience: z.string().min(1),
|
|
14
|
-
from:
|
|
113
|
+
from: sender,
|
|
15
114
|
subject: z.string().min(1),
|
|
16
115
|
html: z.string(),
|
|
17
116
|
}),
|
|
@@ -32,7 +131,7 @@ export const resendOps = defineConnector("resend", {
|
|
|
32
131
|
input: z
|
|
33
132
|
.object({
|
|
34
133
|
to: z.union([z.string().min(1), z.array(z.string().min(1)).min(1).max(50)]),
|
|
35
|
-
from:
|
|
134
|
+
from: sender,
|
|
36
135
|
subject: z.string().min(1),
|
|
37
136
|
html: z.string().optional(),
|
|
38
137
|
text: z.string().optional(),
|
package/dist/connector.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connector.js","sourceRoot":"","sources":["../src/connector.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"connector.js","sourceRoot":"","sources":["../src/connector.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EACf,cAAc,EACd,SAAS,EACT,WAAW,EACX,UAAU,GACX,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,mGAAmG;AACnG,MAAM,OAAO,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,gBAAgB,CAAU,CAAC;AAEnF,wFAAwF;AACxF,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;AAC1C,sGAAsG;AACtG,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC;AAE1C,yHAAyH;AACzH,MAAM,QAAQ,GAAG;IACf,aAAa;IACb,SAAS;IACT,UAAU;IACV,QAAQ;IACR,mBAAmB;IACnB,oBAAoB;IACpB,kBAAkB;CACV,CAAC;AAGX,qFAAqF;AACrF,MAAM,CAAC,MAAM,YAA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