@irisend/sdk 0.1.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 +190 -0
- package/dist/index.d.ts +496 -0
- package/dist/index.js +565 -0
- package/package.json +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# @irisend/sdk
|
|
2
|
+
|
|
3
|
+
Official Node.js SDK for the [Irisend](https://irisend.com) API — a self-hosted, Resend-compatible
|
|
4
|
+
transactional + marketing email API. If you've used [`resend`](https://www.npmjs.com/package/resend),
|
|
5
|
+
this will feel almost identical: same `{ data, error }` return shape, same idempotency header, same
|
|
6
|
+
`batch.send` alias.
|
|
7
|
+
|
|
8
|
+
> **Why `@irisend/sdk`, not `@irisend/sdk-node`?** There's no separate browser/edge SDK planned —
|
|
9
|
+
> Irisend's public surface is a server-to-server REST API, so one Node-only package covers every
|
|
10
|
+
> consumer. The requirement is Node ≥ 22 (for global `fetch`), not a platform split that would need
|
|
11
|
+
> the `-node` qualifier to disambiguate from a sibling package.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install @irisend/sdk
|
|
17
|
+
# or
|
|
18
|
+
pnpm add @irisend/sdk
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Requires **Node.js ≥ 22**. Zero runtime dependencies — it only uses the global `fetch`.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { Irisend } from "@irisend/sdk";
|
|
27
|
+
|
|
28
|
+
const irisend = new Irisend(process.env.IRISEND_API_KEY!);
|
|
29
|
+
// Self-hosted at a different origin? Pass a baseUrl (defaults to https://api.irisend.com):
|
|
30
|
+
// const irisend = new Irisend(apiKey, { baseUrl: "https://api.your-irisend.example" });
|
|
31
|
+
|
|
32
|
+
const { data, error } = await irisend.emails.send({
|
|
33
|
+
from: "Acme <onboarding@acme.com>",
|
|
34
|
+
to: "customer@example.com",
|
|
35
|
+
subject: "Welcome!",
|
|
36
|
+
html: "<p>Thanks for signing up.</p>",
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
if (error) {
|
|
40
|
+
console.error(error.name, error.statusCode, error.message);
|
|
41
|
+
} else {
|
|
42
|
+
console.log("sent", data.id);
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Every call returns `Promise<{ data, error }>` — it never throws for API or network failures, so
|
|
47
|
+
you don't need a `try`/`catch` around a send. `error` is an `IrisendError` (`name`, `message`,
|
|
48
|
+
`statusCode`; `statusCode` is `undefined` for a failure that never reached the server, e.g. DNS or
|
|
49
|
+
connection errors).
|
|
50
|
+
|
|
51
|
+
### Idempotency
|
|
52
|
+
|
|
53
|
+
Pass `idempotencyKey` as a second argument to `emails.send` / `emails.sendBatch` to make retries
|
|
54
|
+
safe — it's sent as the `Idempotency-Key` header:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
await irisend.emails.send(
|
|
58
|
+
{ from: "a@acme.com", to: "b@example.com", subject: "hi", text: "hi" },
|
|
59
|
+
{ idempotencyKey: "order-42-confirmation" },
|
|
60
|
+
);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Batch sending
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
const { data, error } = await irisend.emails.sendBatch([
|
|
67
|
+
{ from: "a@acme.com", to: "one@example.com", subject: "hi", text: "hi" },
|
|
68
|
+
{ from: "a@acme.com", to: "two@example.com", subject: "hi", text: "hi" },
|
|
69
|
+
]);
|
|
70
|
+
|
|
71
|
+
// Resend-style alias — identical to emails.sendBatch:
|
|
72
|
+
await irisend.batch.send([...]);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Batch items can't schedule or attach files (`scheduledAt` / `attachments`), matching
|
|
76
|
+
`POST /emails/batch`.
|
|
77
|
+
|
|
78
|
+
### Emails
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
await irisend.emails.get(id);
|
|
82
|
+
await irisend.emails.list({ limit: 20, after: cursorId });
|
|
83
|
+
await irisend.emails.update(id, { scheduledAt: "2026-08-05T11:52:01.858Z" });
|
|
84
|
+
await irisend.emails.cancel(id);
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Domains
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
const { data: domain } = await irisend.domains.create({ name: "acme.com", region: "us-east-1" });
|
|
91
|
+
await irisend.domains.list();
|
|
92
|
+
await irisend.domains.get(domain.id);
|
|
93
|
+
await irisend.domains.update(domain.id, { openTracking: true, clickTracking: true });
|
|
94
|
+
await irisend.domains.verify(domain.id);
|
|
95
|
+
await irisend.domains.remove(domain.id);
|
|
96
|
+
|
|
97
|
+
// Irisend-specific (no Resend equivalent):
|
|
98
|
+
await irisend.domains.unpause(domain.id); // reputation circuit breaker override
|
|
99
|
+
await irisend.domains.mintEmbedToken(domain.id); // token for @irisend/connect-react's widget
|
|
100
|
+
await irisend.domains.dmarcSummary(domain.id);
|
|
101
|
+
await irisend.domains.dmarcSources(domain.id, { window: "30d" });
|
|
102
|
+
await irisend.domains.dmarcReports(domain.id);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### API keys
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
const { data } = await irisend.apiKeys.create({ name: "CI", permission: "sending_access" });
|
|
109
|
+
console.log(data.token); // shown once, store it now
|
|
110
|
+
await irisend.apiKeys.list();
|
|
111
|
+
await irisend.apiKeys.remove(data.id);
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Webhooks
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
const { data } = await irisend.webhooks.create({
|
|
118
|
+
endpoint: "https://example.com/hooks/irisend",
|
|
119
|
+
events: ["email.sent", "email.delivered", "email.bounced"],
|
|
120
|
+
});
|
|
121
|
+
console.log(data.signingSecret); // whsec_…
|
|
122
|
+
await irisend.webhooks.list();
|
|
123
|
+
await irisend.webhooks.get(data.id);
|
|
124
|
+
await irisend.webhooks.remove(data.id);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Templates
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
const { data: tpl } = await irisend.templates.create({
|
|
131
|
+
name: "Welcome",
|
|
132
|
+
subject: "Hi {{{FIRST}}}",
|
|
133
|
+
html: "<p>Hi {{{FIRST}}}, thanks for joining!</p>",
|
|
134
|
+
variables: [{ key: "FIRST", type: "string", fallbackValue: "there" }],
|
|
135
|
+
});
|
|
136
|
+
await irisend.templates.publish(tpl.id); // required before sending with it
|
|
137
|
+
|
|
138
|
+
await irisend.templates.get(tpl.id); // id or alias both work
|
|
139
|
+
await irisend.templates.list();
|
|
140
|
+
await irisend.templates.update(tpl.id, { html: "<p>new copy</p>" }); // appends a new version
|
|
141
|
+
await irisend.templates.duplicate(tpl.id, { name: "Welcome copy" });
|
|
142
|
+
await irisend.templates.remove(tpl.id);
|
|
143
|
+
|
|
144
|
+
// Irisend-specific versioning (no Resend equivalent): every create/update/rollback appends an
|
|
145
|
+
// immutable version; nothing is ever mutated in place.
|
|
146
|
+
const { data: versions } = await irisend.templates.versions(tpl.id);
|
|
147
|
+
await irisend.templates.rollback(tpl.id, versions.data[versions.data.length - 1].id);
|
|
148
|
+
|
|
149
|
+
// Send with a published template — variables fill in the template's placeholders:
|
|
150
|
+
await irisend.emails.send({
|
|
151
|
+
to: "jane@example.com",
|
|
152
|
+
template: { id: tpl.id, variables: { FIRST: "Jane" } },
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Audiences & contacts
|
|
157
|
+
|
|
158
|
+
Contacts are nested under an audience on the wire, so every contact call takes the owning
|
|
159
|
+
`audienceId`:
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
const { data: audience } = await irisend.audiences.create({ name: "Newsletter" });
|
|
163
|
+
await irisend.audiences.list();
|
|
164
|
+
await irisend.audiences.get(audience.id);
|
|
165
|
+
|
|
166
|
+
await irisend.contacts.create(audience.id, { email: "jane@example.com", firstName: "Jane" });
|
|
167
|
+
await irisend.contacts.list(audience.id);
|
|
168
|
+
await irisend.contacts.remove(audience.id, "jane@example.com"); // id or email both work
|
|
169
|
+
|
|
170
|
+
await irisend.audiences.remove(audience.id);
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Field naming
|
|
174
|
+
|
|
175
|
+
The SDK is camelCase end to end; the wire protocol (matching Resend's own API) is snake_case.
|
|
176
|
+
Conversion is explicit and shape-aware, not a blind deep-object transform — caller-supplied maps
|
|
177
|
+
like `headers` on an email keep their exact keys (`X-Entity-Ref-ID` stays `X-Entity-Ref-ID`, it is
|
|
178
|
+
never re-cased).
|
|
179
|
+
|
|
180
|
+
## Error handling
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
const { data, error } = await irisend.emails.send({ from: "a@acme.com", to: "b@x.com", subject: "hi" });
|
|
184
|
+
if (error) {
|
|
185
|
+
// error instanceof IrisendError
|
|
186
|
+
// error.name — e.g. "validation_error", "missing_api_key", "network_error"
|
|
187
|
+
// error.message — human-readable detail
|
|
188
|
+
// error.statusCode — HTTP status, or undefined for a network failure
|
|
189
|
+
}
|
|
190
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mirrors the `{ statusCode, name, message }` shape `@irisend/core`'s `ApiError.toJSON()` puts on
|
|
3
|
+
* the wire. A real `Error` subclass (not a plain object) so callers who prefer `try`/`catch` over
|
|
4
|
+
* checking `error` can still `throw result.error` and get a conventional stack + `instanceof` check.
|
|
5
|
+
*/
|
|
6
|
+
declare class IrisendError extends Error {
|
|
7
|
+
/** Absent for network-level failures (the request never reached the server). */
|
|
8
|
+
readonly statusCode: number | undefined;
|
|
9
|
+
constructor(name: string, message: string, statusCode?: number);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type IrisendResponse<T> = {
|
|
13
|
+
data: T;
|
|
14
|
+
error: null;
|
|
15
|
+
} | {
|
|
16
|
+
data: null;
|
|
17
|
+
error: IrisendError;
|
|
18
|
+
};
|
|
19
|
+
interface ClientRequestOptions {
|
|
20
|
+
body?: unknown;
|
|
21
|
+
query?: Record<string, string | number | undefined>;
|
|
22
|
+
idempotencyKey?: string;
|
|
23
|
+
}
|
|
24
|
+
/** Thin fetch wrapper: builds the URL, (de)serializes JSON, and turns non-2xx/network failures into `IrisendError`. Resource classes own all snake_case ↔ camelCase conversion. */
|
|
25
|
+
declare class HttpClient {
|
|
26
|
+
private readonly apiKey;
|
|
27
|
+
private readonly baseUrl;
|
|
28
|
+
constructor(apiKey: string, baseUrl: string);
|
|
29
|
+
request<T>(method: string, path: string, options?: ClientRequestOptions): Promise<IrisendResponse<T>>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface Tag {
|
|
33
|
+
name: string;
|
|
34
|
+
value: string;
|
|
35
|
+
}
|
|
36
|
+
/** `{object, has_more, data}` on the wire, camelCased. */
|
|
37
|
+
interface ListResponse<T> {
|
|
38
|
+
object: "list";
|
|
39
|
+
hasMore: boolean;
|
|
40
|
+
data: T[];
|
|
41
|
+
}
|
|
42
|
+
/** The minimal `{object, id}` shape most mutation endpoints return. */
|
|
43
|
+
interface MutationResponse {
|
|
44
|
+
object: string;
|
|
45
|
+
id: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface CreateApiKeyOptions {
|
|
49
|
+
name: string;
|
|
50
|
+
permission?: "full_access" | "sending_access";
|
|
51
|
+
domainId?: string;
|
|
52
|
+
}
|
|
53
|
+
interface CreateApiKeyResponse {
|
|
54
|
+
/** shown once — the API never returns it again */
|
|
55
|
+
id: string;
|
|
56
|
+
token: string;
|
|
57
|
+
}
|
|
58
|
+
interface ApiKey {
|
|
59
|
+
id: string;
|
|
60
|
+
name: string;
|
|
61
|
+
createdAt: string;
|
|
62
|
+
lastUsedAt: string | null;
|
|
63
|
+
}
|
|
64
|
+
declare class ApiKeysResource {
|
|
65
|
+
private readonly http;
|
|
66
|
+
constructor(http: HttpClient);
|
|
67
|
+
/** `POST /api-keys` */
|
|
68
|
+
create(input: CreateApiKeyOptions): Promise<IrisendResponse<CreateApiKeyResponse>>;
|
|
69
|
+
/** `GET /api-keys` */
|
|
70
|
+
list(): Promise<IrisendResponse<ListResponse<ApiKey>>>;
|
|
71
|
+
/** `DELETE /api-keys/:id` — responds with an empty body on success. */
|
|
72
|
+
remove(id: string): Promise<IrisendResponse<null>>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
interface CreateAudienceOptions {
|
|
76
|
+
name: string;
|
|
77
|
+
}
|
|
78
|
+
interface CreateAudienceResponse {
|
|
79
|
+
object: "audience";
|
|
80
|
+
id: string;
|
|
81
|
+
name: string;
|
|
82
|
+
}
|
|
83
|
+
interface Audience {
|
|
84
|
+
object: "audience";
|
|
85
|
+
id: string;
|
|
86
|
+
name: string;
|
|
87
|
+
createdAt: string;
|
|
88
|
+
}
|
|
89
|
+
declare class AudiencesResource {
|
|
90
|
+
private readonly http;
|
|
91
|
+
constructor(http: HttpClient);
|
|
92
|
+
/** `POST /audiences` */
|
|
93
|
+
create(input: CreateAudienceOptions): Promise<IrisendResponse<CreateAudienceResponse>>;
|
|
94
|
+
/** `GET /audiences` */
|
|
95
|
+
list(): Promise<IrisendResponse<ListResponse<Audience>>>;
|
|
96
|
+
/** `GET /audiences/:id` */
|
|
97
|
+
get(id: string): Promise<IrisendResponse<Audience>>;
|
|
98
|
+
/** `DELETE /audiences/:id` */
|
|
99
|
+
remove(id: string): Promise<IrisendResponse<MutationResponse & {
|
|
100
|
+
deleted: boolean;
|
|
101
|
+
}>>;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
interface CreateContactOptions {
|
|
105
|
+
email: string;
|
|
106
|
+
firstName?: string;
|
|
107
|
+
lastName?: string;
|
|
108
|
+
unsubscribed?: boolean;
|
|
109
|
+
}
|
|
110
|
+
interface CreateContactResponse {
|
|
111
|
+
object: "contact";
|
|
112
|
+
id: string;
|
|
113
|
+
}
|
|
114
|
+
interface Contact {
|
|
115
|
+
object: "contact";
|
|
116
|
+
id: string;
|
|
117
|
+
email: string;
|
|
118
|
+
firstName: string | null;
|
|
119
|
+
lastName: string | null;
|
|
120
|
+
unsubscribed: boolean;
|
|
121
|
+
createdAt: string;
|
|
122
|
+
}
|
|
123
|
+
/** Contacts are nested under an audience on the wire (`/audiences/:id/contacts`); every call takes the owning `audienceId`. */
|
|
124
|
+
declare class ContactsResource {
|
|
125
|
+
private readonly http;
|
|
126
|
+
constructor(http: HttpClient);
|
|
127
|
+
/** `POST /audiences/:audienceId/contacts` — upserts by (audience, email). */
|
|
128
|
+
create(audienceId: string, input: CreateContactOptions): Promise<IrisendResponse<CreateContactResponse>>;
|
|
129
|
+
/** `GET /audiences/:audienceId/contacts` */
|
|
130
|
+
list(audienceId: string): Promise<IrisendResponse<ListResponse<Contact>>>;
|
|
131
|
+
/** `DELETE /audiences/:audienceId/contacts/:idOrEmail` */
|
|
132
|
+
remove(audienceId: string, idOrEmail: string): Promise<IrisendResponse<{
|
|
133
|
+
object: "contact";
|
|
134
|
+
contact: string;
|
|
135
|
+
deleted: boolean;
|
|
136
|
+
}>>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
type DomainRegion = "us-east-1" | "eu-west-1" | "sa-east-1" | "ap-northeast-1";
|
|
140
|
+
interface DomainRecord {
|
|
141
|
+
record: string;
|
|
142
|
+
name: string;
|
|
143
|
+
type: string;
|
|
144
|
+
value: string;
|
|
145
|
+
status: string;
|
|
146
|
+
ttl: string;
|
|
147
|
+
priority?: number;
|
|
148
|
+
}
|
|
149
|
+
interface Domain {
|
|
150
|
+
object: "domain";
|
|
151
|
+
id: string;
|
|
152
|
+
name: string;
|
|
153
|
+
status: string;
|
|
154
|
+
createdAt: string;
|
|
155
|
+
region: string;
|
|
156
|
+
records: DomainRecord[];
|
|
157
|
+
openTracking: boolean;
|
|
158
|
+
clickTracking: boolean;
|
|
159
|
+
tls: string;
|
|
160
|
+
reputationStatus: string;
|
|
161
|
+
bimiLogoUrl: string | null;
|
|
162
|
+
bimiVmcUrl: string | null;
|
|
163
|
+
}
|
|
164
|
+
type DomainListItem = Omit<Domain, "records">;
|
|
165
|
+
interface CreateDomainOptions {
|
|
166
|
+
name: string;
|
|
167
|
+
region?: DomainRegion;
|
|
168
|
+
}
|
|
169
|
+
interface UpdateDomainOptions {
|
|
170
|
+
openTracking?: boolean;
|
|
171
|
+
clickTracking?: boolean;
|
|
172
|
+
tls?: "opportunistic" | "enforced";
|
|
173
|
+
bimiLogoUrl?: string | null;
|
|
174
|
+
bimiVmcUrl?: string | null;
|
|
175
|
+
}
|
|
176
|
+
interface ListDomainsOptions {
|
|
177
|
+
limit?: number;
|
|
178
|
+
after?: string;
|
|
179
|
+
}
|
|
180
|
+
interface DmarcSummary {
|
|
181
|
+
object: "dmarc_summary";
|
|
182
|
+
domainId: string;
|
|
183
|
+
publishedPolicy: string | null;
|
|
184
|
+
passRate7d: number | null;
|
|
185
|
+
passRate30d: number | null;
|
|
186
|
+
totalMessages7d: number;
|
|
187
|
+
unknownSourceCount7d: number;
|
|
188
|
+
recommendedPolicy: string | null;
|
|
189
|
+
recommendationReason: string | null;
|
|
190
|
+
lastReportAt: string | null;
|
|
191
|
+
reportsReceivedTotal: number;
|
|
192
|
+
}
|
|
193
|
+
interface DmarcSource {
|
|
194
|
+
object: "dmarc_source";
|
|
195
|
+
sourceIp: string;
|
|
196
|
+
reverseDns: string | null;
|
|
197
|
+
classification: string;
|
|
198
|
+
messages: number;
|
|
199
|
+
passRate: number;
|
|
200
|
+
firstSeen: string;
|
|
201
|
+
lastSeen: string;
|
|
202
|
+
}
|
|
203
|
+
interface DmarcReport {
|
|
204
|
+
object: "dmarc_report";
|
|
205
|
+
id: string;
|
|
206
|
+
orgName: string;
|
|
207
|
+
reportId: string;
|
|
208
|
+
dateRangeBegin: string;
|
|
209
|
+
dateRangeEnd: string;
|
|
210
|
+
policyP: string;
|
|
211
|
+
policyPct: number;
|
|
212
|
+
totalMessages: number;
|
|
213
|
+
alignedPassMessages: number;
|
|
214
|
+
createdAt: string;
|
|
215
|
+
}
|
|
216
|
+
interface ListDmarcSourcesOptions {
|
|
217
|
+
window?: "7d" | "30d" | "90d";
|
|
218
|
+
limit?: number;
|
|
219
|
+
after?: string;
|
|
220
|
+
}
|
|
221
|
+
interface EmbedToken {
|
|
222
|
+
object: "embed_token";
|
|
223
|
+
token: string;
|
|
224
|
+
domainId: string;
|
|
225
|
+
expiresAt: string;
|
|
226
|
+
}
|
|
227
|
+
declare class DomainsResource {
|
|
228
|
+
private readonly http;
|
|
229
|
+
constructor(http: HttpClient);
|
|
230
|
+
/** `POST /domains` */
|
|
231
|
+
create(input: CreateDomainOptions): Promise<IrisendResponse<Domain>>;
|
|
232
|
+
/** `GET /domains` — list items omit `records`. */
|
|
233
|
+
list(options?: ListDomainsOptions): Promise<IrisendResponse<ListResponse<DomainListItem>>>;
|
|
234
|
+
/** `GET /domains/:id` */
|
|
235
|
+
get(id: string): Promise<IrisendResponse<Domain>>;
|
|
236
|
+
/** `PATCH /domains/:id` */
|
|
237
|
+
update(id: string, input: UpdateDomainOptions): Promise<IrisendResponse<MutationResponse>>;
|
|
238
|
+
/** `POST /domains/:id/verify` — (re)triggers DNS verification. */
|
|
239
|
+
verify(id: string): Promise<IrisendResponse<MutationResponse>>;
|
|
240
|
+
/** `POST /domains/:id/unpause` — manual override for the reputation circuit breaker; no Resend equivalent. */
|
|
241
|
+
unpause(id: string): Promise<IrisendResponse<MutationResponse>>;
|
|
242
|
+
/** `DELETE /domains/:id` */
|
|
243
|
+
remove(id: string): Promise<IrisendResponse<MutationResponse & {
|
|
244
|
+
deleted: boolean;
|
|
245
|
+
}>>;
|
|
246
|
+
/** `POST /domains/:id/embed-token` — mints a 15-minute token for `@irisend/connect-react`'s embedded widget; no Resend equivalent. */
|
|
247
|
+
mintEmbedToken(id: string): Promise<IrisendResponse<EmbedToken>>;
|
|
248
|
+
/** `GET /domains/:id/dmarc/summary` — no Resend equivalent. */
|
|
249
|
+
dmarcSummary(id: string): Promise<IrisendResponse<DmarcSummary>>;
|
|
250
|
+
/** `GET /domains/:id/dmarc/sources` — no Resend equivalent. */
|
|
251
|
+
dmarcSources(id: string, options?: ListDmarcSourcesOptions): Promise<IrisendResponse<ListResponse<DmarcSource>>>;
|
|
252
|
+
/** `GET /domains/:id/dmarc/reports` — no Resend equivalent. */
|
|
253
|
+
dmarcReports(id: string, options?: {
|
|
254
|
+
limit?: number;
|
|
255
|
+
after?: string;
|
|
256
|
+
}): Promise<IrisendResponse<ListResponse<DmarcReport>>>;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
interface Attachment {
|
|
260
|
+
filename: string;
|
|
261
|
+
/** base64-encoded content; provide exactly one of `content`/`path` */
|
|
262
|
+
content?: string;
|
|
263
|
+
/** remote URL the API fetches the attachment from; provide exactly one of `content`/`path` */
|
|
264
|
+
path?: string;
|
|
265
|
+
contentType?: string;
|
|
266
|
+
/** inline reference used as `<img src="cid:...">` in `html` */
|
|
267
|
+
contentId?: string;
|
|
268
|
+
}
|
|
269
|
+
/** `from`/`subject` are required unless `template` supplies them; `html`/`text` are mutually
|
|
270
|
+
* exclusive with `template` (docs/research/resend.md §1.3). */
|
|
271
|
+
interface CreateEmailOptions {
|
|
272
|
+
from?: string;
|
|
273
|
+
to: string | string[];
|
|
274
|
+
subject?: string;
|
|
275
|
+
cc?: string | string[];
|
|
276
|
+
bcc?: string | string[];
|
|
277
|
+
replyTo?: string | string[];
|
|
278
|
+
html?: string;
|
|
279
|
+
text?: string;
|
|
280
|
+
/** opaque — never case-converted, since these are caller-chosen MIME header names */
|
|
281
|
+
headers?: Record<string, string>;
|
|
282
|
+
tags?: Tag[];
|
|
283
|
+
attachments?: Attachment[];
|
|
284
|
+
/** ISO 8601 timestamp, ≤ 30 days ahead */
|
|
285
|
+
scheduledAt?: string;
|
|
286
|
+
/** renders a published template; variable keys are not case-converted (caller-chosen). */
|
|
287
|
+
template?: {
|
|
288
|
+
id: string;
|
|
289
|
+
variables?: Record<string, string | number>;
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
/** Batch items may not schedule or attach files — `POST /emails/batch` rejects both. */
|
|
293
|
+
type CreateBatchEmailOptions = Omit<CreateEmailOptions, "attachments" | "scheduledAt">;
|
|
294
|
+
interface CreateEmailResponse {
|
|
295
|
+
id: string;
|
|
296
|
+
}
|
|
297
|
+
interface CreateBatchEmailResponse {
|
|
298
|
+
data: CreateEmailResponse[];
|
|
299
|
+
}
|
|
300
|
+
interface Email {
|
|
301
|
+
object: "email";
|
|
302
|
+
id: string;
|
|
303
|
+
to: string[];
|
|
304
|
+
from: string;
|
|
305
|
+
createdAt: string;
|
|
306
|
+
subject: string;
|
|
307
|
+
html: string | null;
|
|
308
|
+
text: string | null;
|
|
309
|
+
bcc: string[] | null;
|
|
310
|
+
cc: string[] | null;
|
|
311
|
+
replyTo: string[] | null;
|
|
312
|
+
lastEvent: string;
|
|
313
|
+
scheduledAt: string | null;
|
|
314
|
+
tags: Tag[];
|
|
315
|
+
}
|
|
316
|
+
type EmailListItem = Omit<Email, "html" | "text">;
|
|
317
|
+
interface ListEmailsOptions {
|
|
318
|
+
limit?: number;
|
|
319
|
+
after?: string;
|
|
320
|
+
}
|
|
321
|
+
interface UpdateEmailOptions {
|
|
322
|
+
/** the only mutable field — only scheduled emails can be updated */
|
|
323
|
+
scheduledAt: string;
|
|
324
|
+
}
|
|
325
|
+
declare class EmailsResource {
|
|
326
|
+
private readonly http;
|
|
327
|
+
constructor(http: HttpClient);
|
|
328
|
+
/** `POST /emails` */
|
|
329
|
+
send(input: CreateEmailOptions, options?: Pick<ClientRequestOptions, "idempotencyKey">): Promise<IrisendResponse<CreateEmailResponse>>;
|
|
330
|
+
/** `POST /emails/batch` — up to 100 emails, same order in the response. Also exposed as `batch.send` for drop-in Resend compatibility. */
|
|
331
|
+
sendBatch(inputs: CreateBatchEmailOptions[], options?: Pick<ClientRequestOptions, "idempotencyKey">): Promise<IrisendResponse<CreateBatchEmailResponse>>;
|
|
332
|
+
/** `GET /emails/:id` */
|
|
333
|
+
get(id: string): Promise<IrisendResponse<Email>>;
|
|
334
|
+
/** `GET /emails` — cursor paginated. */
|
|
335
|
+
list(options?: ListEmailsOptions): Promise<IrisendResponse<ListResponse<EmailListItem>>>;
|
|
336
|
+
/** `PATCH /emails/:id` — only scheduled emails can be updated. */
|
|
337
|
+
update(id: string, input: UpdateEmailOptions): Promise<IrisendResponse<MutationResponse>>;
|
|
338
|
+
/** `POST /emails/:id/cancel` — cancels a scheduled email. */
|
|
339
|
+
cancel(id: string): Promise<IrisendResponse<MutationResponse>>;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
type TemplateVariableType = "string" | "number";
|
|
343
|
+
interface TemplateVariable {
|
|
344
|
+
key: string;
|
|
345
|
+
type: TemplateVariableType;
|
|
346
|
+
fallbackValue?: string | number;
|
|
347
|
+
}
|
|
348
|
+
/** Resend-compatible `GET /templates/:id` shape (docs/research/resend.md §1.8) — template
|
|
349
|
+
* metadata plus the current draft version's content, flattened into one object. */
|
|
350
|
+
interface Template {
|
|
351
|
+
object: "template";
|
|
352
|
+
id: string;
|
|
353
|
+
alias: string | null;
|
|
354
|
+
status: "draft" | "published";
|
|
355
|
+
name: string;
|
|
356
|
+
subject: string | null;
|
|
357
|
+
from: string | null;
|
|
358
|
+
replyTo: string | null;
|
|
359
|
+
html: string | null;
|
|
360
|
+
text: string | null;
|
|
361
|
+
variables: TemplateVariable[];
|
|
362
|
+
version: number;
|
|
363
|
+
createdAt: string;
|
|
364
|
+
updatedAt: string;
|
|
365
|
+
}
|
|
366
|
+
/** Irisend versioning extension — `GET /templates/:id/versions` items. */
|
|
367
|
+
interface TemplateVersion {
|
|
368
|
+
object: "template_version";
|
|
369
|
+
id: string;
|
|
370
|
+
templateId: string;
|
|
371
|
+
version: number;
|
|
372
|
+
name: string;
|
|
373
|
+
subject: string | null;
|
|
374
|
+
from: string | null;
|
|
375
|
+
replyTo: string | null;
|
|
376
|
+
html: string | null;
|
|
377
|
+
text: string | null;
|
|
378
|
+
variables: TemplateVariable[];
|
|
379
|
+
createdAt: string;
|
|
380
|
+
}
|
|
381
|
+
interface CreateTemplateOptions {
|
|
382
|
+
name: string;
|
|
383
|
+
html: string;
|
|
384
|
+
alias?: string;
|
|
385
|
+
from?: string;
|
|
386
|
+
subject?: string;
|
|
387
|
+
replyTo?: string;
|
|
388
|
+
text?: string;
|
|
389
|
+
variables?: TemplateVariable[];
|
|
390
|
+
}
|
|
391
|
+
/** Every field optional — an omitted field keeps the current version's value; it is never reset. */
|
|
392
|
+
interface UpdateTemplateOptions {
|
|
393
|
+
name?: string;
|
|
394
|
+
html?: string;
|
|
395
|
+
alias?: string;
|
|
396
|
+
from?: string;
|
|
397
|
+
subject?: string;
|
|
398
|
+
replyTo?: string;
|
|
399
|
+
text?: string;
|
|
400
|
+
variables?: TemplateVariable[];
|
|
401
|
+
}
|
|
402
|
+
interface DuplicateTemplateOptions {
|
|
403
|
+
name?: string;
|
|
404
|
+
alias?: string;
|
|
405
|
+
}
|
|
406
|
+
interface ListTemplatesOptions {
|
|
407
|
+
limit?: number;
|
|
408
|
+
after?: string;
|
|
409
|
+
}
|
|
410
|
+
interface ListTemplateVersionsOptions {
|
|
411
|
+
limit?: number;
|
|
412
|
+
after?: string;
|
|
413
|
+
}
|
|
414
|
+
declare class TemplatesResource {
|
|
415
|
+
private readonly http;
|
|
416
|
+
constructor(http: HttpClient);
|
|
417
|
+
/** `POST /templates` */
|
|
418
|
+
create(input: CreateTemplateOptions): Promise<IrisendResponse<Template>>;
|
|
419
|
+
/** `GET /templates` — cursor paginated. */
|
|
420
|
+
list(options?: ListTemplatesOptions): Promise<IrisendResponse<ListResponse<Template>>>;
|
|
421
|
+
/** `GET /templates/:id` — `id` accepts either the template id or its alias. */
|
|
422
|
+
get(idOrAlias: string): Promise<IrisendResponse<Template>>;
|
|
423
|
+
/** `PATCH /templates/:id` — appends a new version. */
|
|
424
|
+
update(id: string, input: UpdateTemplateOptions): Promise<IrisendResponse<MutationResponse & {
|
|
425
|
+
version: number;
|
|
426
|
+
}>>;
|
|
427
|
+
/** `DELETE /templates/:id` */
|
|
428
|
+
remove(id: string): Promise<IrisendResponse<MutationResponse & {
|
|
429
|
+
deleted: boolean;
|
|
430
|
+
}>>;
|
|
431
|
+
/** `POST /templates/:id/publish` — makes the current draft version the one `emails.send`'s `template.id` renders. */
|
|
432
|
+
publish(id: string): Promise<IrisendResponse<MutationResponse>>;
|
|
433
|
+
/** `POST /templates/:id/duplicate` — a brand-new template seeded from this one's current draft. */
|
|
434
|
+
duplicate(id: string, input?: DuplicateTemplateOptions): Promise<IrisendResponse<Template>>;
|
|
435
|
+
/** `GET /templates/:id/versions` — cursor paginated, newest first. Irisend extension, no Resend equivalent. */
|
|
436
|
+
versions(id: string, options?: ListTemplateVersionsOptions): Promise<IrisendResponse<ListResponse<TemplateVersion>>>;
|
|
437
|
+
/** `POST /templates/:id/versions/:version_id/rollback` — appends a new version copied from
|
|
438
|
+
* `versionId` and makes it current. Irisend extension, no Resend equivalent. */
|
|
439
|
+
rollback(id: string, versionId: string): Promise<IrisendResponse<MutationResponse>>;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
type WebhookEventType = "email.sent" | "email.delivered" | "email.delivery_delayed" | "email.bounced" | "email.complained" | "email.opened" | "email.clicked" | "email.failed" | "email.scheduled" | "email.suppressed" | "email.canceled" | "domain.reputation.warning" | "domain.reputation.paused" | "account.created" | "account.suspended" | "account.resumed" | "domain.dmarc.unknown_source" | "domain.dmarc.ramp_ready";
|
|
443
|
+
interface CreateWebhookOptions {
|
|
444
|
+
endpoint: string;
|
|
445
|
+
events: WebhookEventType[];
|
|
446
|
+
}
|
|
447
|
+
interface CreateWebhookResponse {
|
|
448
|
+
object: "webhook";
|
|
449
|
+
id: string;
|
|
450
|
+
/** `whsec_…` — shown in full only here and on `get` */
|
|
451
|
+
signingSecret: string;
|
|
452
|
+
}
|
|
453
|
+
interface Webhook {
|
|
454
|
+
object: "webhook";
|
|
455
|
+
id: string;
|
|
456
|
+
endpoint: string;
|
|
457
|
+
events: WebhookEventType[];
|
|
458
|
+
status: "enabled" | "disabled";
|
|
459
|
+
createdAt: string;
|
|
460
|
+
signingSecret?: string;
|
|
461
|
+
}
|
|
462
|
+
declare class WebhooksResource {
|
|
463
|
+
private readonly http;
|
|
464
|
+
constructor(http: HttpClient);
|
|
465
|
+
/** `POST /webhooks` */
|
|
466
|
+
create(input: CreateWebhookOptions): Promise<IrisendResponse<CreateWebhookResponse>>;
|
|
467
|
+
/** `GET /webhooks` — list items omit `signingSecret`. */
|
|
468
|
+
list(): Promise<IrisendResponse<ListResponse<Webhook>>>;
|
|
469
|
+
/** `GET /webhooks/:id` */
|
|
470
|
+
get(id: string): Promise<IrisendResponse<Webhook>>;
|
|
471
|
+
/** `DELETE /webhooks/:id` */
|
|
472
|
+
remove(id: string): Promise<IrisendResponse<MutationResponse & {
|
|
473
|
+
deleted: boolean;
|
|
474
|
+
}>>;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
interface IrisendOptions {
|
|
478
|
+
/** override for self-hosted deployments; defaults to `https://api.irisend.com` */
|
|
479
|
+
baseUrl?: string;
|
|
480
|
+
}
|
|
481
|
+
declare class Irisend {
|
|
482
|
+
readonly emails: EmailsResource;
|
|
483
|
+
readonly domains: DomainsResource;
|
|
484
|
+
readonly apiKeys: ApiKeysResource;
|
|
485
|
+
readonly webhooks: WebhooksResource;
|
|
486
|
+
readonly audiences: AudiencesResource;
|
|
487
|
+
readonly contacts: ContactsResource;
|
|
488
|
+
readonly templates: TemplatesResource;
|
|
489
|
+
/** Resend-style alias: `batch.send` is the same call as `emails.sendBatch`. */
|
|
490
|
+
readonly batch: {
|
|
491
|
+
send: EmailsResource["sendBatch"];
|
|
492
|
+
};
|
|
493
|
+
constructor(apiKey: string, options?: IrisendOptions);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
export { type ApiKey, type Attachment, type Audience, type Contact, type CreateApiKeyOptions, type CreateApiKeyResponse, type CreateAudienceOptions, type CreateAudienceResponse, type CreateBatchEmailOptions, type CreateBatchEmailResponse, type CreateContactOptions, type CreateContactResponse, type CreateDomainOptions, type CreateEmailOptions, type CreateEmailResponse, type CreateTemplateOptions, type CreateWebhookOptions, type CreateWebhookResponse, type DmarcReport, type DmarcSource, type DmarcSummary, type Domain, type DomainListItem, type DomainRecord, type DomainRegion, type DuplicateTemplateOptions, type Email, type EmailListItem, type EmbedToken, Irisend, IrisendError, type IrisendOptions, type IrisendResponse, type ListDmarcSourcesOptions, type ListDomainsOptions, type ListEmailsOptions, type ListResponse, type ListTemplateVersionsOptions, type ListTemplatesOptions, type MutationResponse, type Tag, type Template, type TemplateVariable, type TemplateVariableType, type TemplateVersion, type UpdateDomainOptions, type UpdateEmailOptions, type UpdateTemplateOptions, type Webhook, type WebhookEventType };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var IrisendError = class extends Error {
|
|
3
|
+
/** Absent for network-level failures (the request never reached the server). */
|
|
4
|
+
statusCode;
|
|
5
|
+
constructor(name, message, statusCode) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = name;
|
|
8
|
+
this.statusCode = statusCode;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
function apiError(payload, status) {
|
|
12
|
+
if (payload && typeof payload === "object") {
|
|
13
|
+
const p = payload;
|
|
14
|
+
if (typeof p.name === "string" && typeof p.message === "string") {
|
|
15
|
+
return new IrisendError(p.name, p.message, typeof p.statusCode === "number" ? p.statusCode : status);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return new IrisendError("application_error", `Request failed with status code ${status}`, status);
|
|
19
|
+
}
|
|
20
|
+
function networkError(cause) {
|
|
21
|
+
const message = cause instanceof Error ? cause.message : "The request could not be sent";
|
|
22
|
+
return new IrisendError("network_error", message);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// src/client.ts
|
|
26
|
+
var HttpClient = class {
|
|
27
|
+
constructor(apiKey, baseUrl) {
|
|
28
|
+
this.apiKey = apiKey;
|
|
29
|
+
this.baseUrl = baseUrl;
|
|
30
|
+
}
|
|
31
|
+
apiKey;
|
|
32
|
+
baseUrl;
|
|
33
|
+
async request(method, path, options = {}) {
|
|
34
|
+
const base = this.baseUrl.endsWith("/") ? this.baseUrl.slice(0, -1) : this.baseUrl;
|
|
35
|
+
const qs = new URLSearchParams();
|
|
36
|
+
for (const [key, value] of Object.entries(options.query ?? {})) {
|
|
37
|
+
if (value !== void 0) qs.set(key, String(value));
|
|
38
|
+
}
|
|
39
|
+
const query = qs.toString();
|
|
40
|
+
const url = `${base}${path}${query ? `?${query}` : ""}`;
|
|
41
|
+
const headers = { authorization: `Bearer ${this.apiKey}` };
|
|
42
|
+
if (options.idempotencyKey) headers["idempotency-key"] = options.idempotencyKey;
|
|
43
|
+
let body;
|
|
44
|
+
if (options.body !== void 0) {
|
|
45
|
+
headers["content-type"] = "application/json";
|
|
46
|
+
body = JSON.stringify(options.body);
|
|
47
|
+
}
|
|
48
|
+
let res;
|
|
49
|
+
try {
|
|
50
|
+
res = await fetch(url, { method, headers, body });
|
|
51
|
+
} catch (cause) {
|
|
52
|
+
return { data: null, error: networkError(cause) };
|
|
53
|
+
}
|
|
54
|
+
const text = await res.text();
|
|
55
|
+
let payload = null;
|
|
56
|
+
if (text.length > 0) {
|
|
57
|
+
try {
|
|
58
|
+
payload = JSON.parse(text);
|
|
59
|
+
} catch (cause) {
|
|
60
|
+
if (!res.ok) return { data: null, error: apiError(null, res.status) };
|
|
61
|
+
return { data: null, error: networkError(cause) };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (!res.ok) return { data: null, error: apiError(payload, res.status) };
|
|
65
|
+
return { data: payload, error: null };
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
async function mapResponse(promise, transform) {
|
|
69
|
+
const res = await promise;
|
|
70
|
+
if (res.error) return { data: null, error: res.error };
|
|
71
|
+
return { data: transform(res.data), error: null };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/resources/api-keys.ts
|
|
75
|
+
var ApiKeysResource = class {
|
|
76
|
+
constructor(http) {
|
|
77
|
+
this.http = http;
|
|
78
|
+
}
|
|
79
|
+
http;
|
|
80
|
+
/** `POST /api-keys` */
|
|
81
|
+
create(input) {
|
|
82
|
+
return this.http.request("POST", "/api-keys", {
|
|
83
|
+
body: { name: input.name, permission: input.permission, domain_id: input.domainId }
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/** `GET /api-keys` */
|
|
87
|
+
list() {
|
|
88
|
+
return mapResponse(
|
|
89
|
+
this.http.request(
|
|
90
|
+
"GET",
|
|
91
|
+
"/api-keys"
|
|
92
|
+
),
|
|
93
|
+
(raw) => ({
|
|
94
|
+
object: "list",
|
|
95
|
+
hasMore: raw.has_more,
|
|
96
|
+
data: raw.data.map((k) => ({ id: k.id, name: k.name, createdAt: k.created_at, lastUsedAt: k.last_used_at }))
|
|
97
|
+
})
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
/** `DELETE /api-keys/:id` — responds with an empty body on success. */
|
|
101
|
+
remove(id) {
|
|
102
|
+
return this.http.request("DELETE", `/api-keys/${id}`);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// src/resources/audiences.ts
|
|
107
|
+
var AudiencesResource = class {
|
|
108
|
+
constructor(http) {
|
|
109
|
+
this.http = http;
|
|
110
|
+
}
|
|
111
|
+
http;
|
|
112
|
+
/** `POST /audiences` */
|
|
113
|
+
create(input) {
|
|
114
|
+
return this.http.request("POST", "/audiences", { body: { name: input.name } });
|
|
115
|
+
}
|
|
116
|
+
/** `GET /audiences` */
|
|
117
|
+
list() {
|
|
118
|
+
return mapResponse(
|
|
119
|
+
this.http.request("GET", "/audiences"),
|
|
120
|
+
(raw) => ({ object: "list", hasMore: raw.has_more, data: raw.data.map((a) => ({ object: "audience", id: a.id, name: a.name, createdAt: a.created_at })) })
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
/** `GET /audiences/:id` */
|
|
124
|
+
get(id) {
|
|
125
|
+
return mapResponse(
|
|
126
|
+
this.http.request("GET", `/audiences/${id}`),
|
|
127
|
+
(a) => ({ object: "audience", id: a.id, name: a.name, createdAt: a.created_at })
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
/** `DELETE /audiences/:id` */
|
|
131
|
+
remove(id) {
|
|
132
|
+
return this.http.request("DELETE", `/audiences/${id}`);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// src/resources/contacts.ts
|
|
137
|
+
function fromWireContact(c) {
|
|
138
|
+
return { object: "contact", id: c.id, email: c.email, firstName: c.first_name, lastName: c.last_name, unsubscribed: c.unsubscribed, createdAt: c.created_at };
|
|
139
|
+
}
|
|
140
|
+
var ContactsResource = class {
|
|
141
|
+
constructor(http) {
|
|
142
|
+
this.http = http;
|
|
143
|
+
}
|
|
144
|
+
http;
|
|
145
|
+
/** `POST /audiences/:audienceId/contacts` — upserts by (audience, email). */
|
|
146
|
+
create(audienceId, input) {
|
|
147
|
+
return this.http.request("POST", `/audiences/${audienceId}/contacts`, {
|
|
148
|
+
body: { email: input.email, first_name: input.firstName, last_name: input.lastName, unsubscribed: input.unsubscribed }
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/** `GET /audiences/:audienceId/contacts` */
|
|
152
|
+
list(audienceId) {
|
|
153
|
+
return mapResponse(
|
|
154
|
+
this.http.request("GET", `/audiences/${audienceId}/contacts`),
|
|
155
|
+
(raw) => ({ object: "list", hasMore: raw.has_more, data: raw.data.map(fromWireContact) })
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
/** `DELETE /audiences/:audienceId/contacts/:idOrEmail` */
|
|
159
|
+
remove(audienceId, idOrEmail) {
|
|
160
|
+
return this.http.request(
|
|
161
|
+
"DELETE",
|
|
162
|
+
`/audiences/${audienceId}/contacts/${encodeURIComponent(idOrEmail)}`
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// src/resources/domains.ts
|
|
168
|
+
function fromWireDomain(d) {
|
|
169
|
+
return {
|
|
170
|
+
object: "domain",
|
|
171
|
+
id: d.id,
|
|
172
|
+
name: d.name,
|
|
173
|
+
status: d.status,
|
|
174
|
+
createdAt: d.created_at,
|
|
175
|
+
region: d.region,
|
|
176
|
+
records: d.records ?? [],
|
|
177
|
+
openTracking: d.open_tracking,
|
|
178
|
+
clickTracking: d.click_tracking,
|
|
179
|
+
tls: d.tls,
|
|
180
|
+
reputationStatus: d.reputation_status,
|
|
181
|
+
bimiLogoUrl: d.bimi_logo_url,
|
|
182
|
+
bimiVmcUrl: d.bimi_vmc_url
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
var DomainsResource = class {
|
|
186
|
+
constructor(http) {
|
|
187
|
+
this.http = http;
|
|
188
|
+
}
|
|
189
|
+
http;
|
|
190
|
+
/** `POST /domains` */
|
|
191
|
+
create(input) {
|
|
192
|
+
return mapResponse(this.http.request("POST", "/domains", { body: { name: input.name, region: input.region } }), fromWireDomain);
|
|
193
|
+
}
|
|
194
|
+
/** `GET /domains` — list items omit `records`. */
|
|
195
|
+
list(options) {
|
|
196
|
+
return mapResponse(
|
|
197
|
+
this.http.request("GET", "/domains", {
|
|
198
|
+
query: { limit: options?.limit, after: options?.after }
|
|
199
|
+
}),
|
|
200
|
+
(raw) => ({ object: "list", hasMore: raw.has_more, data: raw.data.map(fromWireDomain) })
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
/** `GET /domains/:id` */
|
|
204
|
+
get(id) {
|
|
205
|
+
return mapResponse(this.http.request("GET", `/domains/${id}`), fromWireDomain);
|
|
206
|
+
}
|
|
207
|
+
/** `PATCH /domains/:id` */
|
|
208
|
+
update(id, input) {
|
|
209
|
+
return this.http.request("PATCH", `/domains/${id}`, {
|
|
210
|
+
body: {
|
|
211
|
+
open_tracking: input.openTracking,
|
|
212
|
+
click_tracking: input.clickTracking,
|
|
213
|
+
tls: input.tls,
|
|
214
|
+
bimi_logo_url: input.bimiLogoUrl,
|
|
215
|
+
bimi_vmc_url: input.bimiVmcUrl
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
/** `POST /domains/:id/verify` — (re)triggers DNS verification. */
|
|
220
|
+
verify(id) {
|
|
221
|
+
return this.http.request("POST", `/domains/${id}/verify`);
|
|
222
|
+
}
|
|
223
|
+
/** `POST /domains/:id/unpause` — manual override for the reputation circuit breaker; no Resend equivalent. */
|
|
224
|
+
unpause(id) {
|
|
225
|
+
return this.http.request("POST", `/domains/${id}/unpause`);
|
|
226
|
+
}
|
|
227
|
+
/** `DELETE /domains/:id` */
|
|
228
|
+
remove(id) {
|
|
229
|
+
return this.http.request("DELETE", `/domains/${id}`);
|
|
230
|
+
}
|
|
231
|
+
/** `POST /domains/:id/embed-token` — mints a 15-minute token for `@irisend/connect-react`'s embedded widget; no Resend equivalent. */
|
|
232
|
+
mintEmbedToken(id) {
|
|
233
|
+
return mapResponse(
|
|
234
|
+
this.http.request("POST", `/domains/${id}/embed-token`),
|
|
235
|
+
(raw) => ({ object: "embed_token", token: raw.token, domainId: raw.domain_id, expiresAt: raw.expires_at })
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
/** `GET /domains/:id/dmarc/summary` — no Resend equivalent. */
|
|
239
|
+
dmarcSummary(id) {
|
|
240
|
+
return mapResponse(
|
|
241
|
+
this.http.request("GET", `/domains/${id}/dmarc/summary`),
|
|
242
|
+
(raw) => ({
|
|
243
|
+
object: "dmarc_summary",
|
|
244
|
+
domainId: raw.domain_id,
|
|
245
|
+
publishedPolicy: raw.published_policy,
|
|
246
|
+
passRate7d: raw.pass_rate_7d,
|
|
247
|
+
passRate30d: raw.pass_rate_30d,
|
|
248
|
+
totalMessages7d: raw.total_messages_7d,
|
|
249
|
+
unknownSourceCount7d: raw.unknown_source_count_7d,
|
|
250
|
+
recommendedPolicy: raw.recommended_policy,
|
|
251
|
+
recommendationReason: raw.recommendation_reason,
|
|
252
|
+
lastReportAt: raw.last_report_at,
|
|
253
|
+
reportsReceivedTotal: raw.reports_received_total
|
|
254
|
+
})
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
/** `GET /domains/:id/dmarc/sources` — no Resend equivalent. */
|
|
258
|
+
dmarcSources(id, options) {
|
|
259
|
+
return mapResponse(
|
|
260
|
+
this.http.request("GET", `/domains/${id}/dmarc/sources`, { query: { window: options?.window, limit: options?.limit, after: options?.after } }),
|
|
261
|
+
(raw) => ({
|
|
262
|
+
object: "list",
|
|
263
|
+
hasMore: raw.has_more,
|
|
264
|
+
data: raw.data.map((r) => ({
|
|
265
|
+
object: "dmarc_source",
|
|
266
|
+
sourceIp: r.source_ip,
|
|
267
|
+
reverseDns: r.reverse_dns,
|
|
268
|
+
classification: r.classification,
|
|
269
|
+
messages: r.messages,
|
|
270
|
+
passRate: r.pass_rate,
|
|
271
|
+
firstSeen: r.first_seen,
|
|
272
|
+
lastSeen: r.last_seen
|
|
273
|
+
}))
|
|
274
|
+
})
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
/** `GET /domains/:id/dmarc/reports` — no Resend equivalent. */
|
|
278
|
+
dmarcReports(id, options) {
|
|
279
|
+
return mapResponse(
|
|
280
|
+
this.http.request("GET", `/domains/${id}/dmarc/reports`, { query: { limit: options?.limit, after: options?.after } }),
|
|
281
|
+
(raw) => ({
|
|
282
|
+
object: "list",
|
|
283
|
+
hasMore: raw.has_more,
|
|
284
|
+
data: raw.data.map((r) => ({
|
|
285
|
+
object: "dmarc_report",
|
|
286
|
+
id: r.id,
|
|
287
|
+
orgName: r.org_name,
|
|
288
|
+
reportId: r.report_id,
|
|
289
|
+
dateRangeBegin: r.date_range_begin,
|
|
290
|
+
dateRangeEnd: r.date_range_end,
|
|
291
|
+
policyP: r.policy_p,
|
|
292
|
+
policyPct: r.policy_pct,
|
|
293
|
+
totalMessages: r.total_messages,
|
|
294
|
+
alignedPassMessages: r.aligned_pass_messages,
|
|
295
|
+
createdAt: r.created_at
|
|
296
|
+
}))
|
|
297
|
+
})
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
// src/resources/emails.ts
|
|
303
|
+
function toWireAttachment(a) {
|
|
304
|
+
return { filename: a.filename, content: a.content, path: a.path, content_type: a.contentType, content_id: a.contentId };
|
|
305
|
+
}
|
|
306
|
+
function toWireEmail(input) {
|
|
307
|
+
const attachments = "attachments" in input ? input.attachments : void 0;
|
|
308
|
+
const scheduledAt = "scheduledAt" in input ? input.scheduledAt : void 0;
|
|
309
|
+
return {
|
|
310
|
+
from: input.from,
|
|
311
|
+
to: input.to,
|
|
312
|
+
subject: input.subject,
|
|
313
|
+
cc: input.cc,
|
|
314
|
+
bcc: input.bcc,
|
|
315
|
+
reply_to: input.replyTo,
|
|
316
|
+
html: input.html,
|
|
317
|
+
text: input.text,
|
|
318
|
+
headers: input.headers,
|
|
319
|
+
tags: input.tags,
|
|
320
|
+
attachments: attachments?.map(toWireAttachment),
|
|
321
|
+
scheduled_at: scheduledAt,
|
|
322
|
+
template: input.template
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
function fromWireEmail(e) {
|
|
326
|
+
return {
|
|
327
|
+
object: "email",
|
|
328
|
+
id: e.id,
|
|
329
|
+
to: e.to,
|
|
330
|
+
from: e.from,
|
|
331
|
+
createdAt: e.created_at,
|
|
332
|
+
subject: e.subject,
|
|
333
|
+
html: e.html,
|
|
334
|
+
text: e.text,
|
|
335
|
+
bcc: e.bcc,
|
|
336
|
+
cc: e.cc,
|
|
337
|
+
replyTo: e.reply_to,
|
|
338
|
+
lastEvent: e.last_event,
|
|
339
|
+
scheduledAt: e.scheduled_at,
|
|
340
|
+
tags: e.tags
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
var EmailsResource = class {
|
|
344
|
+
constructor(http) {
|
|
345
|
+
this.http = http;
|
|
346
|
+
}
|
|
347
|
+
http;
|
|
348
|
+
/** `POST /emails` */
|
|
349
|
+
send(input, options) {
|
|
350
|
+
return this.http.request("POST", "/emails", { body: toWireEmail(input), idempotencyKey: options?.idempotencyKey });
|
|
351
|
+
}
|
|
352
|
+
/** `POST /emails/batch` — up to 100 emails, same order in the response. Also exposed as `batch.send` for drop-in Resend compatibility. */
|
|
353
|
+
sendBatch(inputs, options) {
|
|
354
|
+
return this.http.request("POST", "/emails/batch", { body: inputs.map(toWireEmail), idempotencyKey: options?.idempotencyKey });
|
|
355
|
+
}
|
|
356
|
+
/** `GET /emails/:id` */
|
|
357
|
+
get(id) {
|
|
358
|
+
return mapResponse(this.http.request("GET", `/emails/${id}`), fromWireEmail);
|
|
359
|
+
}
|
|
360
|
+
/** `GET /emails` — cursor paginated. */
|
|
361
|
+
list(options) {
|
|
362
|
+
return mapResponse(
|
|
363
|
+
this.http.request("GET", "/emails", {
|
|
364
|
+
query: { limit: options?.limit, after: options?.after }
|
|
365
|
+
}),
|
|
366
|
+
(raw) => ({ object: "list", hasMore: raw.has_more, data: raw.data.map(fromWireEmail) })
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
/** `PATCH /emails/:id` — only scheduled emails can be updated. */
|
|
370
|
+
update(id, input) {
|
|
371
|
+
return this.http.request("PATCH", `/emails/${id}`, { body: { scheduled_at: input.scheduledAt } });
|
|
372
|
+
}
|
|
373
|
+
/** `POST /emails/:id/cancel` — cancels a scheduled email. */
|
|
374
|
+
cancel(id) {
|
|
375
|
+
return this.http.request("POST", `/emails/${id}/cancel`);
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
// src/resources/templates.ts
|
|
380
|
+
function toWireVariable(v) {
|
|
381
|
+
return { key: v.key, type: v.type, fallback_value: v.fallbackValue };
|
|
382
|
+
}
|
|
383
|
+
function fromWireVariable(v) {
|
|
384
|
+
return { key: v.key, type: v.type, fallbackValue: v.fallback_value };
|
|
385
|
+
}
|
|
386
|
+
function fromWireTemplate(t) {
|
|
387
|
+
return {
|
|
388
|
+
object: "template",
|
|
389
|
+
id: t.id,
|
|
390
|
+
alias: t.alias,
|
|
391
|
+
status: t.status,
|
|
392
|
+
name: t.name,
|
|
393
|
+
subject: t.subject,
|
|
394
|
+
from: t.from,
|
|
395
|
+
replyTo: t.reply_to,
|
|
396
|
+
html: t.html,
|
|
397
|
+
text: t.text,
|
|
398
|
+
variables: t.variables.map(fromWireVariable),
|
|
399
|
+
version: t.version,
|
|
400
|
+
createdAt: t.created_at,
|
|
401
|
+
updatedAt: t.updated_at
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
function fromWireTemplateVersion(v) {
|
|
405
|
+
return {
|
|
406
|
+
object: "template_version",
|
|
407
|
+
id: v.id,
|
|
408
|
+
templateId: v.template_id,
|
|
409
|
+
version: v.version,
|
|
410
|
+
name: v.name,
|
|
411
|
+
subject: v.subject,
|
|
412
|
+
from: v.from,
|
|
413
|
+
replyTo: v.reply_to,
|
|
414
|
+
html: v.html,
|
|
415
|
+
text: v.text,
|
|
416
|
+
variables: v.variables.map(fromWireVariable),
|
|
417
|
+
createdAt: v.created_at
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
var TemplatesResource = class {
|
|
421
|
+
constructor(http) {
|
|
422
|
+
this.http = http;
|
|
423
|
+
}
|
|
424
|
+
http;
|
|
425
|
+
/** `POST /templates` */
|
|
426
|
+
create(input) {
|
|
427
|
+
return mapResponse(
|
|
428
|
+
this.http.request("POST", "/templates", {
|
|
429
|
+
body: {
|
|
430
|
+
name: input.name,
|
|
431
|
+
html: input.html,
|
|
432
|
+
alias: input.alias,
|
|
433
|
+
from: input.from,
|
|
434
|
+
subject: input.subject,
|
|
435
|
+
reply_to: input.replyTo,
|
|
436
|
+
text: input.text,
|
|
437
|
+
variables: input.variables?.map(toWireVariable)
|
|
438
|
+
}
|
|
439
|
+
}),
|
|
440
|
+
fromWireTemplate
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
/** `GET /templates` — cursor paginated. */
|
|
444
|
+
list(options) {
|
|
445
|
+
return mapResponse(
|
|
446
|
+
this.http.request("GET", "/templates", {
|
|
447
|
+
query: { limit: options?.limit, after: options?.after }
|
|
448
|
+
}),
|
|
449
|
+
(raw) => ({ object: "list", hasMore: raw.has_more, data: raw.data.map(fromWireTemplate) })
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
/** `GET /templates/:id` — `id` accepts either the template id or its alias. */
|
|
453
|
+
get(idOrAlias) {
|
|
454
|
+
return mapResponse(this.http.request("GET", `/templates/${idOrAlias}`), fromWireTemplate);
|
|
455
|
+
}
|
|
456
|
+
/** `PATCH /templates/:id` — appends a new version. */
|
|
457
|
+
update(id, input) {
|
|
458
|
+
return this.http.request("PATCH", `/templates/${id}`, {
|
|
459
|
+
body: {
|
|
460
|
+
name: input.name,
|
|
461
|
+
html: input.html,
|
|
462
|
+
alias: input.alias,
|
|
463
|
+
from: input.from,
|
|
464
|
+
subject: input.subject,
|
|
465
|
+
reply_to: input.replyTo,
|
|
466
|
+
text: input.text,
|
|
467
|
+
variables: input.variables?.map(toWireVariable)
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
/** `DELETE /templates/:id` */
|
|
472
|
+
remove(id) {
|
|
473
|
+
return this.http.request("DELETE", `/templates/${id}`);
|
|
474
|
+
}
|
|
475
|
+
/** `POST /templates/:id/publish` — makes the current draft version the one `emails.send`'s `template.id` renders. */
|
|
476
|
+
publish(id) {
|
|
477
|
+
return this.http.request("POST", `/templates/${id}/publish`);
|
|
478
|
+
}
|
|
479
|
+
/** `POST /templates/:id/duplicate` — a brand-new template seeded from this one's current draft. */
|
|
480
|
+
duplicate(id, input = {}) {
|
|
481
|
+
return mapResponse(
|
|
482
|
+
this.http.request("POST", `/templates/${id}/duplicate`, { body: { name: input.name, alias: input.alias } }),
|
|
483
|
+
fromWireTemplate
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
/** `GET /templates/:id/versions` — cursor paginated, newest first. Irisend extension, no Resend equivalent. */
|
|
487
|
+
versions(id, options) {
|
|
488
|
+
return mapResponse(
|
|
489
|
+
this.http.request("GET", `/templates/${id}/versions`, {
|
|
490
|
+
query: { limit: options?.limit, after: options?.after }
|
|
491
|
+
}),
|
|
492
|
+
(raw) => ({ object: "list", hasMore: raw.has_more, data: raw.data.map(fromWireTemplateVersion) })
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
/** `POST /templates/:id/versions/:version_id/rollback` — appends a new version copied from
|
|
496
|
+
* `versionId` and makes it current. Irisend extension, no Resend equivalent. */
|
|
497
|
+
rollback(id, versionId) {
|
|
498
|
+
return this.http.request("POST", `/templates/${id}/versions/${versionId}/rollback`);
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
// src/resources/webhooks.ts
|
|
503
|
+
function fromWireWebhook(w) {
|
|
504
|
+
return { object: "webhook", id: w.id, endpoint: w.endpoint, events: w.events, status: w.status, createdAt: w.created_at, signingSecret: w.signing_secret };
|
|
505
|
+
}
|
|
506
|
+
var WebhooksResource = class {
|
|
507
|
+
constructor(http) {
|
|
508
|
+
this.http = http;
|
|
509
|
+
}
|
|
510
|
+
http;
|
|
511
|
+
/** `POST /webhooks` */
|
|
512
|
+
create(input) {
|
|
513
|
+
return mapResponse(
|
|
514
|
+
this.http.request("POST", "/webhooks", {
|
|
515
|
+
body: { endpoint: input.endpoint, events: input.events }
|
|
516
|
+
}),
|
|
517
|
+
(raw) => ({ object: "webhook", id: raw.id, signingSecret: raw.signing_secret })
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
/** `GET /webhooks` — list items omit `signingSecret`. */
|
|
521
|
+
list() {
|
|
522
|
+
return mapResponse(
|
|
523
|
+
this.http.request("GET", "/webhooks"),
|
|
524
|
+
(raw) => ({ object: "list", hasMore: raw.has_more, data: raw.data.map(fromWireWebhook) })
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
/** `GET /webhooks/:id` */
|
|
528
|
+
get(id) {
|
|
529
|
+
return mapResponse(this.http.request("GET", `/webhooks/${id}`), fromWireWebhook);
|
|
530
|
+
}
|
|
531
|
+
/** `DELETE /webhooks/:id` */
|
|
532
|
+
remove(id) {
|
|
533
|
+
return this.http.request("DELETE", `/webhooks/${id}`);
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
// src/irisend.ts
|
|
538
|
+
var DEFAULT_BASE_URL = "https://api.irisend.com";
|
|
539
|
+
var Irisend = class {
|
|
540
|
+
emails;
|
|
541
|
+
domains;
|
|
542
|
+
apiKeys;
|
|
543
|
+
webhooks;
|
|
544
|
+
audiences;
|
|
545
|
+
contacts;
|
|
546
|
+
templates;
|
|
547
|
+
/** Resend-style alias: `batch.send` is the same call as `emails.sendBatch`. */
|
|
548
|
+
batch;
|
|
549
|
+
constructor(apiKey, options = {}) {
|
|
550
|
+
if (!apiKey) throw new Error("Irisend requires an API key: `new Irisend(apiKey)`.");
|
|
551
|
+
const http = new HttpClient(apiKey, options.baseUrl ?? DEFAULT_BASE_URL);
|
|
552
|
+
this.emails = new EmailsResource(http);
|
|
553
|
+
this.domains = new DomainsResource(http);
|
|
554
|
+
this.apiKeys = new ApiKeysResource(http);
|
|
555
|
+
this.webhooks = new WebhooksResource(http);
|
|
556
|
+
this.audiences = new AudiencesResource(http);
|
|
557
|
+
this.contacts = new ContactsResource(http);
|
|
558
|
+
this.templates = new TemplatesResource(http);
|
|
559
|
+
this.batch = { send: this.emails.sendBatch.bind(this.emails) };
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
export {
|
|
563
|
+
Irisend,
|
|
564
|
+
IrisendError
|
|
565
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@irisend/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Official Node.js SDK for the Irisend API (Resend-compatible).",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=22"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"module": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^22.20.4",
|
|
25
|
+
"tsup": "^8.5.1",
|
|
26
|
+
"typescript": "^5.9.3",
|
|
27
|
+
"vitest": "^5.0.2"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsup",
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"test": "vitest run"
|
|
33
|
+
}
|
|
34
|
+
}
|