@irisend/sdk 0.1.0 → 0.2.1

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 CHANGED
@@ -75,6 +75,39 @@ await irisend.batch.send([...]);
75
75
  Batch items can't schedule or attach files (`scheduledAt` / `attachments`), matching
76
76
  `POST /emails/batch`.
77
77
 
78
+ ### React Email
79
+
80
+ Pass a React element as `react` instead of `html` — on `emails.send`, `emails.sendBatch`,
81
+ `broadcasts.create`, and `broadcasts.update`. It's rendered to HTML with
82
+ [`@react-email/render`](https://www.npmjs.com/package/@react-email/render) right before the
83
+ request is sent; `react` takes precedence over a caller-supplied `html` if both are given, and is
84
+ never sent on the wire itself:
85
+
86
+ ```tsx
87
+ import { Html, Text } from "@react-email/components";
88
+
89
+ await irisend.emails.send({
90
+ from: "Acme <onboarding@acme.com>",
91
+ to: "customer@example.com",
92
+ subject: "Welcome!",
93
+ react: (
94
+ <Html>
95
+ <Text>Thanks for signing up.</Text>
96
+ </Html>
97
+ ),
98
+ });
99
+ ```
100
+
101
+ `@react-email/render` (plus `react`/`react-dom`) is an **optional peer dependency** — install it
102
+ yourself if you use `react`:
103
+
104
+ ```sh
105
+ npm install @react-email/render react react-dom
106
+ ```
107
+
108
+ Calling `send`/`sendBatch`/`broadcasts.create`/`broadcasts.update` with `react` set but
109
+ `@react-email/render` not installed throws a clear error instead of sending a broken request.
110
+
78
111
  ### Emails
79
112
 
80
113
  ```ts
@@ -84,6 +117,25 @@ await irisend.emails.update(id, { scheduledAt: "2026-08-05T11:52:01.858Z" });
84
117
  await irisend.emails.cancel(id);
85
118
  ```
86
119
 
120
+ ### Receiving (inbound emails)
121
+
122
+ Enable receiving on a domain, then read what came in:
123
+
124
+ ```ts
125
+ await irisend.domains.update(domain.id, { capabilities: { receiving: "enabled" } });
126
+
127
+ const { data } = await irisend.emails.receiving.list({ limit: 20 });
128
+ const email = await irisend.emails.receiving.get(data.data[0].id); // html_format: "data_uri" | "cid"
129
+
130
+ await irisend.emails.receiving.attachments.list({ emailId: email.data.id });
131
+ await irisend.emails.receiving.attachments.get({ emailId: email.data.id, id: "att_123" });
132
+ ```
133
+
134
+ `emails.receiving.get`'s `raw.downloadUrl` and `attachments.list`/`attachments.get`'s
135
+ `downloadUrl` are signed, expiring URLs — fetch them directly, don't proxy through the API again.
136
+ Subscribe a webhook to `"email.received"` to get notified as inbound mail arrives instead of
137
+ polling `emails.receiving.list`.
138
+
87
139
  ### Domains
88
140
 
89
141
  ```ts
@@ -94,6 +146,10 @@ await irisend.domains.update(domain.id, { openTracking: true, clickTracking: tru
94
146
  await irisend.domains.verify(domain.id);
95
147
  await irisend.domains.remove(domain.id);
96
148
 
149
+ // Inbound receiving — off by default; the response's `capabilities.receiving` reflects it:
150
+ await irisend.domains.create({ name: "acme.com", capabilities: { receiving: "enabled" } });
151
+ await irisend.domains.update(domain.id, { capabilities: { receiving: "disabled" } });
152
+
97
153
  // Irisend-specific (no Resend equivalent):
98
154
  await irisend.domains.unpause(domain.id); // reputation circuit breaker override
99
155
  await irisend.domains.mintEmbedToken(domain.id); // token for @irisend/connect-react's widget
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import * as React from 'react';
2
+
1
3
  /**
2
4
  * Mirrors the `{ statusCode, name, message }` shape `@irisend/core`'s `ApiError.toJSON()` puts on
3
5
  * the wire. A real `Error` subclass (not a plain object) so callers who prefer `try`/`catch` over
@@ -45,9 +47,12 @@ interface MutationResponse {
45
47
  id: string;
46
48
  }
47
49
 
50
+ /** `domain_access` is bound to one domain (`domainId` required): send from it, read its sent and received mail and its domain record. */
51
+ type ApiKeyPermission = "full_access" | "sending_access" | "contacts_access" | "domain_access";
48
52
  interface CreateApiKeyOptions {
49
53
  name: string;
50
- permission?: "full_access" | "sending_access";
54
+ permission?: ApiKeyPermission;
55
+ /** Restricts a `sending_access` key to one domain; required for `domain_access`. */
51
56
  domainId?: string;
52
57
  }
53
58
  interface CreateApiKeyResponse {
@@ -101,12 +106,229 @@ declare class AudiencesResource {
101
106
  }>>;
102
107
  }
103
108
 
109
+ type BroadcastStatus = "draft" | "scheduled" | "queued" | "sent" | "canceled";
110
+ /** Resend-compatible `GET /broadcasts/:id` shape. `audienceId`/`segmentId` are the same value —
111
+ * Resend renamed Audiences to Segments; both are kept since the response includes both. */
112
+ interface Broadcast {
113
+ object: "broadcast";
114
+ id: string;
115
+ name: string;
116
+ audienceId: string | null;
117
+ segmentId: string | null;
118
+ from: string;
119
+ subject: string;
120
+ replyTo: string[] | null;
121
+ previewText: string | null;
122
+ html: string | null;
123
+ text: string | null;
124
+ status: BroadcastStatus;
125
+ createdAt: string;
126
+ scheduledAt: string | null;
127
+ sentAt: string | null;
128
+ topicId: string | null;
129
+ }
130
+ /** `GET /broadcasts` item shape — a trimmed subset of `Broadcast`. */
131
+ interface BroadcastListItem {
132
+ id: string;
133
+ name: string;
134
+ audienceId: string | null;
135
+ segmentId: string | null;
136
+ status: BroadcastStatus;
137
+ createdAt: string;
138
+ scheduledAt: string | null;
139
+ sentAt: string | null;
140
+ }
141
+ interface CreateBroadcastOptions {
142
+ /** The segment (audience) to send to. Required unless `audienceId` is provided instead. */
143
+ segmentId?: string;
144
+ /** Legacy alias for `segmentId`. */
145
+ audienceId?: string;
146
+ from: string;
147
+ subject: string;
148
+ replyTo?: string | string[];
149
+ html?: string;
150
+ text?: string;
151
+ /** A React component to render as the `html` body. Takes precedence over `html` when both are
152
+ * given. Requires the optional peer dependency `@react-email/render` at call time. */
153
+ react?: React.ReactNode;
154
+ name?: string;
155
+ topicId?: string;
156
+ previewText?: string;
157
+ /** Send (or schedule, with `scheduledAt`) immediately after creation. Defaults to `false`. */
158
+ send?: boolean;
159
+ /** Requires `send: true`. ISO 8601, e.g. `2026-08-05T11:52:01.858Z`. */
160
+ scheduledAt?: string;
161
+ }
162
+ /** Every field optional — an omitted field keeps the broadcast's current value. Only allowed
163
+ * while the broadcast is `draft`. */
164
+ interface UpdateBroadcastOptions {
165
+ segmentId?: string;
166
+ audienceId?: string;
167
+ from?: string;
168
+ subject?: string;
169
+ replyTo?: string | string[];
170
+ html?: string;
171
+ text?: string;
172
+ /** A React component to render as the `html` body. Takes precedence over `html` when both are
173
+ * given. Requires the optional peer dependency `@react-email/render` at call time. */
174
+ react?: React.ReactNode;
175
+ name?: string;
176
+ topicId?: string;
177
+ previewText?: string;
178
+ }
179
+ interface SendBroadcastOptions {
180
+ /** ISO 8601, e.g. `2026-08-05T11:52:01.858Z`. Omit to send immediately. */
181
+ scheduledAt?: string;
182
+ }
183
+ /** `POST /broadcasts/:id/send` has no `object` field in its response, unlike every other
184
+ * broadcast mutation. */
185
+ interface SendBroadcastResponse {
186
+ id: string;
187
+ }
188
+ interface ListBroadcastsOptions {
189
+ limit?: number;
190
+ after?: string;
191
+ before?: string;
192
+ }
193
+ type BroadcastRecipientEventType = "sent" | "delivered" | "opened" | "clicked" | "bounced" | "complained" | "unsubscribed" | "suppressed";
194
+ type BounceType = "permanent" | "transient" | "undetermined";
195
+ interface ListBroadcastRecipientsOptions {
196
+ type: BroadcastRecipientEventType;
197
+ limit?: number;
198
+ after?: string;
199
+ before?: string;
200
+ email?: string;
201
+ /** Only valid with `type: "bounced"`. */
202
+ bounceType?: BounceType;
203
+ }
204
+ interface BroadcastRecipient {
205
+ /** Opaque cursor for this row; does not identify any entity. Use `contactId` for that. */
206
+ id: string;
207
+ contactId: string | null;
208
+ email: string;
209
+ /** Only present for `type: "opened"` / `type: "clicked"`. */
210
+ count?: number;
211
+ /** Only present for `type: "bounced"`. */
212
+ bounceType?: BounceType | null;
213
+ /** Only present for `type: "clicked"`. */
214
+ clickedLinks?: {
215
+ url: string;
216
+ clicks: number;
217
+ }[];
218
+ }
219
+ interface ListBroadcastClickedLinksOptions {
220
+ limit?: number;
221
+ after?: string;
222
+ before?: string;
223
+ }
224
+ interface BroadcastClickedLink {
225
+ id: string;
226
+ url: string;
227
+ clicks: number;
228
+ uniqueClicks: number;
229
+ }
230
+ declare class BroadcastsResource {
231
+ private readonly http;
232
+ constructor(http: HttpClient);
233
+ /** `POST /broadcasts` */
234
+ create(input: CreateBroadcastOptions): Promise<IrisendResponse<MutationResponse>>;
235
+ /** `GET /broadcasts` — cursor paginated. */
236
+ list(options?: ListBroadcastsOptions): Promise<IrisendResponse<ListResponse<BroadcastListItem>>>;
237
+ /** `GET /broadcasts/:id` */
238
+ get(id: string): Promise<IrisendResponse<Broadcast>>;
239
+ /** `PATCH /broadcasts/:id` — only while `draft`. */
240
+ update(id: string, input: UpdateBroadcastOptions): Promise<IrisendResponse<MutationResponse>>;
241
+ /** `DELETE /broadcasts/:id` — only while `draft` or `scheduled`. */
242
+ remove(id: string): Promise<IrisendResponse<MutationResponse & {
243
+ deleted: boolean;
244
+ }>>;
245
+ /** `POST /broadcasts/:id/send` — only while `draft`. You can send broadcasts created via the
246
+ * API only. */
247
+ send(id: string, input?: SendBroadcastOptions): Promise<IrisendResponse<SendBroadcastResponse>>;
248
+ /** `POST /broadcasts/:id/cancel` — only while `scheduled` or `queued`. */
249
+ cancel(id: string): Promise<IrisendResponse<MutationResponse>>;
250
+ /** `POST /broadcasts/:id/duplicate` — any broadcast can be duplicated, including sent ones. */
251
+ duplicate(id: string): Promise<IrisendResponse<MutationResponse>>;
252
+ /** `GET /broadcasts/:id/recipients` — cursor paginated. */
253
+ recipients(id: string, options: ListBroadcastRecipientsOptions): Promise<IrisendResponse<ListResponse<BroadcastRecipient>>>;
254
+ /** `GET /broadcasts/:id/clicked-links` — cursor paginated, ranked by total clicks descending. */
255
+ clickedLinks(id: string, options?: ListBroadcastClickedLinksOptions): Promise<IrisendResponse<ListResponse<BroadcastClickedLink>>>;
256
+ }
257
+
258
+ type ConsentBasis = "explicit_opt_in" | "soft_opt_in";
259
+ type ConsentStatus = "no_basis" | "explicit_opt_in" | "soft_opt_in" | "soft_opt_in_stale" | "withdrawn";
260
+ interface CreateConsentOptions {
261
+ email: string;
262
+ basis: ConsentBasis;
263
+ source: string;
264
+ /** The exact opt-in copy shown to the contact — required, this is the evidence the endpoint exists to capture. */
265
+ consentText: string;
266
+ /** ISO 8601, must not be in the future. @default now */
267
+ occurredAt?: string;
268
+ ipAddress?: string;
269
+ userAgent?: string;
270
+ metadata?: Record<string, unknown>;
271
+ }
272
+ interface CreateConsentResponse {
273
+ object: "consent";
274
+ id: string;
275
+ email: string;
276
+ status: ConsentStatus;
277
+ }
278
+ interface WithdrawConsentOptions {
279
+ source?: string;
280
+ }
281
+ interface WithdrawConsentResponse {
282
+ object: "consent";
283
+ email: string;
284
+ status: "withdrawn";
285
+ }
286
+ interface ConsentEvent {
287
+ object: "consent_event";
288
+ id: string;
289
+ action: "granted" | "withdrawn";
290
+ basis: ConsentBasis | null;
291
+ source: string;
292
+ consentText: string | null;
293
+ ipAddress: string | null;
294
+ userAgent: string | null;
295
+ metadata: Record<string, unknown>;
296
+ occurredAt: string;
297
+ recordedBy: string;
298
+ createdAt: string;
299
+ }
300
+ interface GetConsentResponse {
301
+ object: "consent";
302
+ email: string;
303
+ status: ConsentStatus;
304
+ /** Present only when `status` is `soft_opt_in`. */
305
+ validUntil?: string;
306
+ events: ConsentEvent[];
307
+ }
308
+ /** Telecommunicatiewet-style consent evidence register, keyed by email (not nested under an
309
+ * audience — one address's consent basis applies across every list it ends up on). */
310
+ declare class ConsentsResource {
311
+ private readonly http;
312
+ constructor(http: HttpClient);
313
+ /** `POST /consents` — records one consent grant with its evidence. */
314
+ create(input: CreateConsentOptions): Promise<IrisendResponse<CreateConsentResponse>>;
315
+ /** `POST /consents/:email/withdraw` */
316
+ withdraw(email: string, input?: WithdrawConsentOptions): Promise<IrisendResponse<WithdrawConsentResponse>>;
317
+ /** `GET /consents/:email` — 404s when no consent evidence has ever been recorded for the address. */
318
+ get(email: string): Promise<IrisendResponse<GetConsentResponse>>;
319
+ }
320
+
104
321
  interface CreateContactOptions {
105
322
  email: string;
106
323
  firstName?: string;
107
324
  lastName?: string;
108
325
  unsubscribed?: boolean;
109
326
  }
327
+ interface UpdateContactOptions {
328
+ firstName?: string | null;
329
+ lastName?: string | null;
330
+ unsubscribed?: boolean | null;
331
+ }
110
332
  interface CreateContactResponse {
111
333
  object: "contact";
112
334
  id: string;
@@ -126,6 +348,10 @@ declare class ContactsResource {
126
348
  constructor(http: HttpClient);
127
349
  /** `POST /audiences/:audienceId/contacts` — upserts by (audience, email). */
128
350
  create(audienceId: string, input: CreateContactOptions): Promise<IrisendResponse<CreateContactResponse>>;
351
+ /** `GET /audiences/:audienceId/contacts/:idOrEmail` */
352
+ get(audienceId: string, idOrEmail: string): Promise<IrisendResponse<Contact>>;
353
+ /** `PATCH /audiences/:audienceId/contacts/:idOrEmail` — an omitted field keeps its current value, matching the API's own contract. */
354
+ update(audienceId: string, idOrEmail: string, input: UpdateContactOptions): Promise<IrisendResponse<Contact>>;
129
355
  /** `GET /audiences/:audienceId/contacts` */
130
356
  list(audienceId: string): Promise<IrisendResponse<ListResponse<Contact>>>;
131
357
  /** `DELETE /audiences/:audienceId/contacts/:idOrEmail` */
@@ -160,11 +386,22 @@ interface Domain {
160
386
  reputationStatus: string;
161
387
  bimiLogoUrl: string | null;
162
388
  bimiVmcUrl: string | null;
389
+ capabilities: DomainCapabilities;
163
390
  }
164
391
  type DomainListItem = Omit<Domain, "records">;
392
+ /** Irisend domains always send, so `sending` is only ever `"enabled"` on the wire — `receiving`
393
+ * reflects whether the inbound MX record is published (`domains.receivingEnabled`). */
394
+ interface DomainCapabilities {
395
+ sending: "enabled";
396
+ receiving: "enabled" | "disabled";
397
+ }
165
398
  interface CreateDomainOptions {
166
399
  name: string;
167
400
  region?: DomainRegion;
401
+ /** Only `receiving` is settable on create — `sending` is always `"enabled"`. */
402
+ capabilities?: {
403
+ receiving?: "enabled" | "disabled";
404
+ };
168
405
  }
169
406
  interface UpdateDomainOptions {
170
407
  openTracking?: boolean;
@@ -172,6 +409,10 @@ interface UpdateDomainOptions {
172
409
  tls?: "opportunistic" | "enforced";
173
410
  bimiLogoUrl?: string | null;
174
411
  bimiVmcUrl?: string | null;
412
+ /** Only `receiving` is settable — toggles the inbound MX record and `receivingEnabled`. */
413
+ capabilities?: {
414
+ receiving?: "enabled" | "disabled";
415
+ };
175
416
  }
176
417
  interface ListDomainsOptions {
177
418
  limit?: number;
@@ -256,6 +497,98 @@ declare class DomainsResource {
256
497
  }): Promise<IrisendResponse<ListResponse<DmarcReport>>>;
257
498
  }
258
499
 
500
+ type InboundAuthResult = "pass" | "fail" | "gray" | "processing_failed" | "unknown";
501
+ interface InboundAuthentication {
502
+ spf: InboundAuthResult;
503
+ dkim: InboundAuthResult;
504
+ dmarc: InboundAuthResult;
505
+ }
506
+ interface ReceivedEmailAttachmentMeta {
507
+ id: string;
508
+ filename: string | null;
509
+ contentType: string;
510
+ contentDisposition: string | null;
511
+ contentId: string | null;
512
+ size: number;
513
+ }
514
+ interface ReceivedEmailListItem {
515
+ id: string;
516
+ to: string[];
517
+ from: string;
518
+ createdAt: string;
519
+ subject: string;
520
+ bcc: string[] | null;
521
+ cc: string[] | null;
522
+ replyTo: string[] | null;
523
+ messageId: string;
524
+ attachments: ReceivedEmailAttachmentMeta[];
525
+ }
526
+ type InboundHtmlFormat = "data_uri" | "cid";
527
+ interface ReceivedEmail extends ReceivedEmailListItem {
528
+ object: "email";
529
+ html: string | null;
530
+ /** Echoes the form actually served — may be `"cid"` even when `data_uri` was requested, for emails too large to inline. */
531
+ htmlFormat: InboundHtmlFormat;
532
+ text: string | null;
533
+ headers: Record<string, string> | null;
534
+ /** Recipient addresses taken from the `for` clause of the message's `Received` headers. */
535
+ receivedFor: string[];
536
+ /** `null` for emails received before this field was introduced. */
537
+ authentication: InboundAuthentication | null;
538
+ raw: {
539
+ downloadUrl: string;
540
+ expiresAt: string;
541
+ };
542
+ }
543
+ interface GetReceivedEmailOptions {
544
+ /** Controls how inline images are returned inside `html`; defaults to `"data_uri"`. */
545
+ htmlFormat?: InboundHtmlFormat;
546
+ }
547
+ interface ListReceivedEmailsOptions {
548
+ limit?: number;
549
+ after?: string;
550
+ before?: string;
551
+ }
552
+ interface ReceivedAttachment {
553
+ object: "attachment";
554
+ id: string;
555
+ filename: string | null;
556
+ size: number;
557
+ contentType: string;
558
+ contentDisposition: string | null;
559
+ contentId: string | null;
560
+ downloadUrl: string;
561
+ expiresAt: string;
562
+ }
563
+ type ReceivedAttachmentListItem = Omit<ReceivedAttachment, "object">;
564
+ interface ListReceivedAttachmentsOptions {
565
+ emailId: string;
566
+ limit?: number;
567
+ after?: string;
568
+ before?: string;
569
+ }
570
+ interface GetReceivedAttachmentOptions {
571
+ emailId: string;
572
+ id: string;
573
+ }
574
+ declare class ReceivingAttachmentsResource {
575
+ private readonly http;
576
+ constructor(http: HttpClient);
577
+ /** `GET /emails/receiving/:emailId/attachments` — cursor paginated. */
578
+ list(options: ListReceivedAttachmentsOptions): Promise<IrisendResponse<ListResponse<ReceivedAttachmentListItem>>>;
579
+ /** `GET /emails/receiving/:emailId/attachments/:id` */
580
+ get(options: GetReceivedAttachmentOptions): Promise<IrisendResponse<ReceivedAttachment>>;
581
+ }
582
+ declare class ReceivingResource {
583
+ private readonly http;
584
+ readonly attachments: ReceivingAttachmentsResource;
585
+ constructor(http: HttpClient);
586
+ /** `GET /emails/receiving` — cursor paginated; emails received by your team. */
587
+ list(options?: ListReceivedEmailsOptions): Promise<IrisendResponse<ListResponse<ReceivedEmailListItem>>>;
588
+ /** `GET /emails/receiving/:id` */
589
+ get(id: string, options?: GetReceivedEmailOptions): Promise<IrisendResponse<ReceivedEmail>>;
590
+ }
591
+
259
592
  interface Attachment {
260
593
  filename: string;
261
594
  /** base64-encoded content; provide exactly one of `content`/`path` */
@@ -277,6 +610,10 @@ interface CreateEmailOptions {
277
610
  replyTo?: string | string[];
278
611
  html?: string;
279
612
  text?: string;
613
+ /** A React component to render as the `html` body. Takes precedence over `html` when both are
614
+ * given, matching Resend's node SDK. Requires the optional peer dependency
615
+ * `@react-email/render` at call time (lazily imported — not needed unless you pass this). */
616
+ react?: React.ReactNode;
280
617
  /** opaque — never case-converted, since these are caller-chosen MIME header names */
281
618
  headers?: Record<string, string>;
282
619
  tags?: Tag[];
@@ -324,6 +661,7 @@ interface UpdateEmailOptions {
324
661
  }
325
662
  declare class EmailsResource {
326
663
  private readonly http;
664
+ readonly receiving: ReceivingResource;
327
665
  constructor(http: HttpClient);
328
666
  /** `POST /emails` */
329
667
  send(input: CreateEmailOptions, options?: Pick<ClientRequestOptions, "idempotencyKey">): Promise<IrisendResponse<CreateEmailResponse>>;
@@ -339,6 +677,94 @@ declare class EmailsResource {
339
677
  cancel(id: string): Promise<IrisendResponse<MutationResponse>>;
340
678
  }
341
679
 
680
+ /** `GET /logs` query parameters. `after`/`before` are mutually exclusive (Resend's pagination
681
+ * contract) — passing both is a 422 from the API, not validated client-side. */
682
+ interface ListLogsOptions {
683
+ limit?: number;
684
+ after?: string;
685
+ before?: string;
686
+ }
687
+ interface LogListItem {
688
+ id: string;
689
+ createdAt: string;
690
+ endpoint: string;
691
+ method: string;
692
+ responseStatus: number;
693
+ userAgent: string | null;
694
+ }
695
+ /** `GET /logs/:id` — adds the full request/response bodies. Shapes vary per logged endpoint, so
696
+ * both are `unknown`. Secrets (API key tokens, webhook signing secrets) are never present: the
697
+ * server redacts them before the row is ever written. */
698
+ interface Log extends LogListItem {
699
+ requestBody: unknown;
700
+ responseBody: unknown;
701
+ }
702
+ declare class LogsResource {
703
+ private readonly http;
704
+ constructor(http: HttpClient);
705
+ /** `GET /logs` — cursor paginated, newest first. */
706
+ list(options?: ListLogsOptions): Promise<IrisendResponse<ListResponse<LogListItem>>>;
707
+ /** `GET /logs/:id` */
708
+ get(id: string): Promise<IrisendResponse<Log>>;
709
+ }
710
+
711
+ /** Resend's `origin` enum has no `unsubscribe` value; Irisend surfaces a preference-center/
712
+ * one-click withdrawal as `manual` on the wire (see `packages/core/src/suppressions.ts`). */
713
+ type SuppressionOrigin = "bounce" | "complaint" | "manual";
714
+ interface AddSuppressionOptions {
715
+ email: string;
716
+ }
717
+ interface Suppression {
718
+ object: "suppression";
719
+ id: string;
720
+ email: string;
721
+ origin: SuppressionOrigin;
722
+ sourceId: string | null;
723
+ createdAt: string;
724
+ }
725
+ interface ListSuppressionsOptions {
726
+ limit?: number;
727
+ after?: string;
728
+ before?: string;
729
+ origin?: SuppressionOrigin;
730
+ }
731
+ interface BatchAddSuppressionsOptions {
732
+ emails: string[];
733
+ }
734
+ interface BatchRemoveSuppressionsOptions {
735
+ emails?: string[];
736
+ ids?: string[];
737
+ }
738
+ declare class SuppressionsBatchResource {
739
+ private readonly http;
740
+ constructor(http: HttpClient);
741
+ /** `POST /suppressions/batch/add` — up to 100 addresses at once. */
742
+ add(input: BatchAddSuppressionsOptions): Promise<IrisendResponse<{
743
+ data: MutationResponse[];
744
+ }>>;
745
+ /** `POST /suppressions/batch/remove` — provide exactly one of `emails`/`ids`, up to 100 entries. */
746
+ remove(input: BatchRemoveSuppressionsOptions): Promise<IrisendResponse<{
747
+ data: Array<MutationResponse & {
748
+ deleted: boolean;
749
+ }>;
750
+ }>>;
751
+ }
752
+ declare class SuppressionsResource {
753
+ private readonly http;
754
+ readonly batch: SuppressionsBatchResource;
755
+ constructor(http: HttpClient);
756
+ /** `POST /suppressions` */
757
+ add(input: AddSuppressionOptions): Promise<IrisendResponse<MutationResponse>>;
758
+ /** `GET /suppressions` */
759
+ list(options?: ListSuppressionsOptions): Promise<IrisendResponse<ListResponse<Suppression>>>;
760
+ /** `GET /suppressions/:suppression` — accepts either a suppression id or an email address. */
761
+ get(idOrEmail: string): Promise<IrisendResponse<Suppression>>;
762
+ /** `DELETE /suppressions/:suppression` — accepts either a suppression id or an email address. */
763
+ remove(idOrEmail: string): Promise<IrisendResponse<MutationResponse & {
764
+ deleted: boolean;
765
+ }>>;
766
+ }
767
+
342
768
  type TemplateVariableType = "string" | "number";
343
769
  interface TemplateVariable {
344
770
  key: string;
@@ -439,7 +865,7 @@ declare class TemplatesResource {
439
865
  rollback(id: string, versionId: string): Promise<IrisendResponse<MutationResponse>>;
440
866
  }
441
867
 
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";
868
+ 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" | "email.received" | "domain.reputation.warning" | "domain.reputation.paused" | "domain.health.degraded" | "domain.health.critical" | "account.created" | "account.suspended" | "account.resumed" | "domain.dmarc.unknown_source" | "domain.dmarc.ramp_ready" | "contact.created" | "contact.updated" | "contact.deleted";
443
869
  interface CreateWebhookOptions {
444
870
  endpoint: string;
445
871
  events: WebhookEventType[];
@@ -472,6 +898,15 @@ declare class WebhooksResource {
472
898
  remove(id: string): Promise<IrisendResponse<MutationResponse & {
473
899
  deleted: boolean;
474
900
  }>>;
901
+ /**
902
+ * Verifies a Standard Webhooks-signed delivery to this plugin's receiver (byte-compatible with
903
+ * Svix — ports `packages/core/src/webhooks.ts`'s `verifyWebhook` so a consumer never needs
904
+ * `@irisend/core`, just this SDK, to validate an inbound webhook). Accepts either `webhook-*`
905
+ * or `svix-*` header names; pass a plain lower-cased header map (e.g.
906
+ * `Object.fromEntries(req.headers)`). `toleranceSec` bounds how stale `webhook-timestamp` may
907
+ * be (default 300s, matching Standard Webhooks' recommendation).
908
+ */
909
+ verify(secret: string, headers: Record<string, string | undefined>, body: string, toleranceSec?: number): boolean;
475
910
  }
476
911
 
477
912
  interface IrisendOptions {
@@ -485,7 +920,11 @@ declare class Irisend {
485
920
  readonly webhooks: WebhooksResource;
486
921
  readonly audiences: AudiencesResource;
487
922
  readonly contacts: ContactsResource;
923
+ readonly consents: ConsentsResource;
488
924
  readonly templates: TemplatesResource;
925
+ readonly logs: LogsResource;
926
+ readonly broadcasts: BroadcastsResource;
927
+ readonly suppressions: SuppressionsResource;
489
928
  /** Resend-style alias: `batch.send` is the same call as `emails.sendBatch`. */
490
929
  readonly batch: {
491
930
  send: EmailsResource["sendBatch"];
@@ -493,4 +932,4 @@ declare class Irisend {
493
932
  constructor(apiKey: string, options?: IrisendOptions);
494
933
  }
495
934
 
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 };
935
+ export { type AddSuppressionOptions, type ApiKey, type ApiKeyPermission, type Attachment, type Audience, type BatchAddSuppressionsOptions, type BatchRemoveSuppressionsOptions, type BounceType, type Broadcast, type BroadcastClickedLink, type BroadcastListItem, type BroadcastRecipient, type BroadcastRecipientEventType, type BroadcastStatus, type ConsentBasis, type ConsentEvent, type ConsentStatus, type Contact, type CreateApiKeyOptions, type CreateApiKeyResponse, type CreateAudienceOptions, type CreateAudienceResponse, type CreateBatchEmailOptions, type CreateBatchEmailResponse, type CreateBroadcastOptions, type CreateConsentOptions, type CreateConsentResponse, 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 DomainCapabilities, type DomainListItem, type DomainRecord, type DomainRegion, type DuplicateTemplateOptions, type Email, type EmailListItem, type EmbedToken, type GetConsentResponse, type GetReceivedAttachmentOptions, type GetReceivedEmailOptions, type InboundAuthResult, type InboundAuthentication, type InboundHtmlFormat, Irisend, IrisendError, type IrisendOptions, type IrisendResponse, type ListBroadcastClickedLinksOptions, type ListBroadcastRecipientsOptions, type ListBroadcastsOptions, type ListDmarcSourcesOptions, type ListDomainsOptions, type ListEmailsOptions, type ListLogsOptions, type ListReceivedAttachmentsOptions, type ListReceivedEmailsOptions, type ListResponse, type ListSuppressionsOptions, type ListTemplateVersionsOptions, type ListTemplatesOptions, type Log, type LogListItem, type MutationResponse, type ReceivedAttachment, type ReceivedAttachmentListItem, type ReceivedEmail, type ReceivedEmailAttachmentMeta, type ReceivedEmailListItem, type SendBroadcastOptions, type SendBroadcastResponse, type Suppression, type SuppressionOrigin, type Tag, type Template, type TemplateVariable, type TemplateVariableType, type TemplateVersion, type UpdateBroadcastOptions, type UpdateContactOptions, type UpdateDomainOptions, type UpdateEmailOptions, type UpdateTemplateOptions, type Webhook, type WebhookEventType, type WithdrawConsentOptions, type WithdrawConsentResponse };
package/dist/index.js CHANGED
@@ -133,6 +133,213 @@ var AudiencesResource = class {
133
133
  }
134
134
  };
135
135
 
136
+ // src/react-render.ts
137
+ async function renderReactEmail(node) {
138
+ let render;
139
+ try {
140
+ ({ render } = await import("@react-email/render"));
141
+ } catch {
142
+ throw new Error(
143
+ "Sending a `react` email body requires the optional peer dependency `@react-email/render`. Install it with `npm install @react-email/render react react-dom`."
144
+ );
145
+ }
146
+ return render(node);
147
+ }
148
+
149
+ // src/resources/broadcasts.ts
150
+ function fromWireBroadcast(b) {
151
+ return {
152
+ object: "broadcast",
153
+ id: b.id,
154
+ name: b.name,
155
+ audienceId: b.audience_id,
156
+ segmentId: b.segment_id,
157
+ from: b.from,
158
+ subject: b.subject,
159
+ replyTo: b.reply_to,
160
+ previewText: b.preview_text,
161
+ html: b.html,
162
+ text: b.text,
163
+ status: b.status,
164
+ createdAt: b.created_at,
165
+ scheduledAt: b.scheduled_at,
166
+ sentAt: b.sent_at,
167
+ topicId: b.topic_id
168
+ };
169
+ }
170
+ function fromWireBroadcastListItem(b) {
171
+ return {
172
+ id: b.id,
173
+ name: b.name,
174
+ audienceId: b.audience_id,
175
+ segmentId: b.segment_id,
176
+ status: b.status,
177
+ createdAt: b.created_at,
178
+ scheduledAt: b.scheduled_at,
179
+ sentAt: b.sent_at
180
+ };
181
+ }
182
+ function fromWireRecipient(r) {
183
+ return {
184
+ id: r.id,
185
+ contactId: r.contact_id,
186
+ email: r.email,
187
+ ...r.count !== void 0 ? { count: r.count } : {},
188
+ ...r.bounce_type !== void 0 ? { bounceType: r.bounce_type } : {},
189
+ ...r.clicked_links !== void 0 ? { clickedLinks: r.clicked_links } : {}
190
+ };
191
+ }
192
+ function fromWireClickedLink(l) {
193
+ return { id: l.id, url: l.url, clicks: l.clicks, uniqueClicks: l.unique_clicks };
194
+ }
195
+ var BroadcastsResource = class {
196
+ constructor(http) {
197
+ this.http = http;
198
+ }
199
+ http;
200
+ /** `POST /broadcasts` */
201
+ async create(input) {
202
+ const html = input.react ? await renderReactEmail(input.react) : input.html;
203
+ return this.http.request("POST", "/broadcasts", {
204
+ body: {
205
+ segment_id: input.segmentId,
206
+ audience_id: input.audienceId,
207
+ from: input.from,
208
+ subject: input.subject,
209
+ reply_to: input.replyTo,
210
+ html,
211
+ text: input.text,
212
+ name: input.name,
213
+ topic_id: input.topicId,
214
+ preview_text: input.previewText,
215
+ send: input.send,
216
+ scheduled_at: input.scheduledAt
217
+ }
218
+ });
219
+ }
220
+ /** `GET /broadcasts` — cursor paginated. */
221
+ list(options) {
222
+ return mapResponse(
223
+ this.http.request("GET", "/broadcasts", {
224
+ query: { limit: options?.limit, after: options?.after, before: options?.before }
225
+ }),
226
+ (raw) => ({ object: "list", hasMore: raw.has_more, data: raw.data.map(fromWireBroadcastListItem) })
227
+ );
228
+ }
229
+ /** `GET /broadcasts/:id` */
230
+ get(id) {
231
+ return mapResponse(this.http.request("GET", `/broadcasts/${id}`), fromWireBroadcast);
232
+ }
233
+ /** `PATCH /broadcasts/:id` — only while `draft`. */
234
+ async update(id, input) {
235
+ const html = input.react ? await renderReactEmail(input.react) : input.html;
236
+ return this.http.request("PATCH", `/broadcasts/${id}`, {
237
+ body: {
238
+ segment_id: input.segmentId,
239
+ audience_id: input.audienceId,
240
+ from: input.from,
241
+ subject: input.subject,
242
+ reply_to: input.replyTo,
243
+ html,
244
+ text: input.text,
245
+ name: input.name,
246
+ topic_id: input.topicId,
247
+ preview_text: input.previewText
248
+ }
249
+ });
250
+ }
251
+ /** `DELETE /broadcasts/:id` — only while `draft` or `scheduled`. */
252
+ remove(id) {
253
+ return this.http.request("DELETE", `/broadcasts/${id}`);
254
+ }
255
+ /** `POST /broadcasts/:id/send` — only while `draft`. You can send broadcasts created via the
256
+ * API only. */
257
+ send(id, input = {}) {
258
+ return this.http.request("POST", `/broadcasts/${id}/send`, { body: { scheduled_at: input.scheduledAt } });
259
+ }
260
+ /** `POST /broadcasts/:id/cancel` — only while `scheduled` or `queued`. */
261
+ cancel(id) {
262
+ return this.http.request("POST", `/broadcasts/${id}/cancel`);
263
+ }
264
+ /** `POST /broadcasts/:id/duplicate` — any broadcast can be duplicated, including sent ones. */
265
+ duplicate(id) {
266
+ return this.http.request("POST", `/broadcasts/${id}/duplicate`);
267
+ }
268
+ /** `GET /broadcasts/:id/recipients` — cursor paginated. */
269
+ recipients(id, options) {
270
+ return mapResponse(
271
+ this.http.request("GET", `/broadcasts/${id}/recipients`, {
272
+ query: { type: options.type, limit: options.limit, after: options.after, before: options.before, email: options.email, bounce_type: options.bounceType }
273
+ }),
274
+ (raw) => ({ object: "list", hasMore: raw.has_more, data: raw.data.map(fromWireRecipient) })
275
+ );
276
+ }
277
+ /** `GET /broadcasts/:id/clicked-links` — cursor paginated, ranked by total clicks descending. */
278
+ clickedLinks(id, options = {}) {
279
+ return mapResponse(
280
+ this.http.request("GET", `/broadcasts/${id}/clicked-links`, {
281
+ query: { limit: options.limit, after: options.after, before: options.before }
282
+ }),
283
+ (raw) => ({ object: "list", hasMore: raw.has_more, data: raw.data.map(fromWireClickedLink) })
284
+ );
285
+ }
286
+ };
287
+
288
+ // src/resources/consents.ts
289
+ function fromWireConsentEvent(e) {
290
+ return {
291
+ object: "consent_event",
292
+ id: e.id,
293
+ action: e.action,
294
+ basis: e.basis,
295
+ source: e.source,
296
+ consentText: e.consent_text,
297
+ ipAddress: e.ip_address,
298
+ userAgent: e.user_agent,
299
+ metadata: e.metadata,
300
+ occurredAt: e.occurred_at,
301
+ recordedBy: e.recorded_by,
302
+ createdAt: e.created_at
303
+ };
304
+ }
305
+ var ConsentsResource = class {
306
+ constructor(http) {
307
+ this.http = http;
308
+ }
309
+ http;
310
+ /** `POST /consents` — records one consent grant with its evidence. */
311
+ create(input) {
312
+ return this.http.request("POST", "/consents", {
313
+ body: {
314
+ email: input.email,
315
+ basis: input.basis,
316
+ source: input.source,
317
+ consent_text: input.consentText,
318
+ occurred_at: input.occurredAt,
319
+ ip_address: input.ipAddress,
320
+ user_agent: input.userAgent,
321
+ metadata: input.metadata
322
+ }
323
+ });
324
+ }
325
+ /** `POST /consents/:email/withdraw` */
326
+ withdraw(email, input = {}) {
327
+ return this.http.request("POST", `/consents/${encodeURIComponent(email)}/withdraw`, {
328
+ body: { source: input.source }
329
+ });
330
+ }
331
+ /** `GET /consents/:email` — 404s when no consent evidence has ever been recorded for the address. */
332
+ get(email) {
333
+ return mapResponse(
334
+ this.http.request(
335
+ "GET",
336
+ `/consents/${encodeURIComponent(email)}`
337
+ ),
338
+ (raw) => ({ object: "consent", email: raw.email, status: raw.status, validUntil: raw.valid_until, events: raw.events.map(fromWireConsentEvent) })
339
+ );
340
+ }
341
+ };
342
+
136
343
  // src/resources/contacts.ts
137
344
  function fromWireContact(c) {
138
345
  return { object: "contact", id: c.id, email: c.email, firstName: c.first_name, lastName: c.last_name, unsubscribed: c.unsubscribed, createdAt: c.created_at };
@@ -148,6 +355,19 @@ var ContactsResource = class {
148
355
  body: { email: input.email, first_name: input.firstName, last_name: input.lastName, unsubscribed: input.unsubscribed }
149
356
  });
150
357
  }
358
+ /** `GET /audiences/:audienceId/contacts/:idOrEmail` */
359
+ get(audienceId, idOrEmail) {
360
+ return mapResponse(this.http.request("GET", `/audiences/${audienceId}/contacts/${encodeURIComponent(idOrEmail)}`), fromWireContact);
361
+ }
362
+ /** `PATCH /audiences/:audienceId/contacts/:idOrEmail` — an omitted field keeps its current value, matching the API's own contract. */
363
+ update(audienceId, idOrEmail, input) {
364
+ return mapResponse(
365
+ this.http.request("PATCH", `/audiences/${audienceId}/contacts/${encodeURIComponent(idOrEmail)}`, {
366
+ body: { first_name: input.firstName, last_name: input.lastName, unsubscribed: input.unsubscribed }
367
+ }),
368
+ fromWireContact
369
+ );
370
+ }
151
371
  /** `GET /audiences/:audienceId/contacts` */
152
372
  list(audienceId) {
153
373
  return mapResponse(
@@ -179,7 +399,8 @@ function fromWireDomain(d) {
179
399
  tls: d.tls,
180
400
  reputationStatus: d.reputation_status,
181
401
  bimiLogoUrl: d.bimi_logo_url,
182
- bimiVmcUrl: d.bimi_vmc_url
402
+ bimiVmcUrl: d.bimi_vmc_url,
403
+ capabilities: d.capabilities
183
404
  };
184
405
  }
185
406
  var DomainsResource = class {
@@ -189,7 +410,12 @@ var DomainsResource = class {
189
410
  http;
190
411
  /** `POST /domains` */
191
412
  create(input) {
192
- return mapResponse(this.http.request("POST", "/domains", { body: { name: input.name, region: input.region } }), fromWireDomain);
413
+ return mapResponse(
414
+ this.http.request("POST", "/domains", {
415
+ body: { name: input.name, region: input.region, capabilities: input.capabilities ? { receiving: input.capabilities.receiving } : void 0 }
416
+ }),
417
+ fromWireDomain
418
+ );
193
419
  }
194
420
  /** `GET /domains` — list items omit `records`. */
195
421
  list(options) {
@@ -212,7 +438,8 @@ var DomainsResource = class {
212
438
  click_tracking: input.clickTracking,
213
439
  tls: input.tls,
214
440
  bimi_logo_url: input.bimiLogoUrl,
215
- bimi_vmc_url: input.bimiVmcUrl
441
+ bimi_vmc_url: input.bimiVmcUrl,
442
+ capabilities: input.capabilities ? { receiving: input.capabilities.receiving } : void 0
216
443
  }
217
444
  });
218
445
  }
@@ -299,6 +526,106 @@ var DomainsResource = class {
299
526
  }
300
527
  };
301
528
 
529
+ // src/resources/receiving.ts
530
+ function fromWireAttachmentMeta(a) {
531
+ return { id: a.id, filename: a.filename, contentType: a.content_type, contentDisposition: a.content_disposition, contentId: a.content_id, size: a.size };
532
+ }
533
+ function fromWireReceivedEmailListItem(e) {
534
+ return {
535
+ id: e.id,
536
+ to: e.to,
537
+ from: e.from,
538
+ createdAt: e.created_at,
539
+ subject: e.subject,
540
+ bcc: e.bcc,
541
+ cc: e.cc,
542
+ replyTo: e.reply_to,
543
+ messageId: e.message_id,
544
+ attachments: e.attachments.map(fromWireAttachmentMeta)
545
+ };
546
+ }
547
+ function fromWireReceivedEmail(e) {
548
+ return {
549
+ ...fromWireReceivedEmailListItem(e),
550
+ object: "email",
551
+ html: e.html,
552
+ htmlFormat: e.html_format,
553
+ text: e.text,
554
+ headers: e.headers,
555
+ receivedFor: e.received_for,
556
+ authentication: e.authentication,
557
+ raw: { downloadUrl: e.raw.download_url, expiresAt: e.raw.expires_at }
558
+ };
559
+ }
560
+ function fromWireReceivedAttachment(a) {
561
+ return {
562
+ object: "attachment",
563
+ id: a.id,
564
+ filename: a.filename,
565
+ size: a.size,
566
+ contentType: a.content_type,
567
+ contentDisposition: a.content_disposition,
568
+ contentId: a.content_id,
569
+ downloadUrl: a.download_url,
570
+ expiresAt: a.expires_at
571
+ };
572
+ }
573
+ var ReceivingAttachmentsResource = class {
574
+ constructor(http) {
575
+ this.http = http;
576
+ }
577
+ http;
578
+ /** `GET /emails/receiving/:emailId/attachments` — cursor paginated. */
579
+ list(options) {
580
+ return mapResponse(
581
+ this.http.request(
582
+ "GET",
583
+ `/emails/receiving/${options.emailId}/attachments`,
584
+ { query: { limit: options.limit, after: options.after, before: options.before } }
585
+ ),
586
+ (raw) => ({
587
+ object: "list",
588
+ hasMore: raw.has_more,
589
+ data: raw.data.map((a) => {
590
+ const { object: _object, ...item } = fromWireReceivedAttachment({ ...a, object: "attachment" });
591
+ return item;
592
+ })
593
+ })
594
+ );
595
+ }
596
+ /** `GET /emails/receiving/:emailId/attachments/:id` */
597
+ get(options) {
598
+ return mapResponse(
599
+ this.http.request("GET", `/emails/receiving/${options.emailId}/attachments/${options.id}`),
600
+ fromWireReceivedAttachment
601
+ );
602
+ }
603
+ };
604
+ var ReceivingResource = class {
605
+ constructor(http) {
606
+ this.http = http;
607
+ this.attachments = new ReceivingAttachmentsResource(http);
608
+ }
609
+ http;
610
+ attachments;
611
+ /** `GET /emails/receiving` — cursor paginated; emails received by your team. */
612
+ list(options) {
613
+ return mapResponse(
614
+ this.http.request("GET", "/emails/receiving", {
615
+ query: { limit: options?.limit, after: options?.after, before: options?.before }
616
+ }),
617
+ (raw) => ({ object: "list", hasMore: raw.has_more, data: raw.data.map(fromWireReceivedEmailListItem) })
618
+ );
619
+ }
620
+ /** `GET /emails/receiving/:id` */
621
+ get(id, options) {
622
+ return mapResponse(
623
+ this.http.request("GET", `/emails/receiving/${id}`, { query: { html_format: options?.htmlFormat } }),
624
+ fromWireReceivedEmail
625
+ );
626
+ }
627
+ };
628
+
302
629
  // src/resources/emails.ts
303
630
  function toWireAttachment(a) {
304
631
  return { filename: a.filename, content: a.content, path: a.path, content_type: a.contentType, content_id: a.contentId };
@@ -343,15 +670,19 @@ function fromWireEmail(e) {
343
670
  var EmailsResource = class {
344
671
  constructor(http) {
345
672
  this.http = http;
673
+ this.receiving = new ReceivingResource(http);
346
674
  }
347
675
  http;
676
+ receiving;
348
677
  /** `POST /emails` */
349
- send(input, options) {
350
- return this.http.request("POST", "/emails", { body: toWireEmail(input), idempotencyKey: options?.idempotencyKey });
678
+ async send(input, options) {
679
+ const body = input.react ? { ...input, html: await renderReactEmail(input.react) } : input;
680
+ return this.http.request("POST", "/emails", { body: toWireEmail(body), idempotencyKey: options?.idempotencyKey });
351
681
  }
352
682
  /** `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 });
683
+ async sendBatch(inputs, options) {
684
+ const bodies = await Promise.all(inputs.map(async (input) => input.react ? { ...input, html: await renderReactEmail(input.react) } : input));
685
+ return this.http.request("POST", "/emails/batch", { body: bodies.map(toWireEmail), idempotencyKey: options?.idempotencyKey });
355
686
  }
356
687
  /** `GET /emails/:id` */
357
688
  get(id) {
@@ -376,6 +707,83 @@ var EmailsResource = class {
376
707
  }
377
708
  };
378
709
 
710
+ // src/resources/logs.ts
711
+ function fromWireLogListItem(l) {
712
+ return { id: l.id, createdAt: l.created_at, endpoint: l.endpoint, method: l.method, responseStatus: l.response_status, userAgent: l.user_agent };
713
+ }
714
+ function fromWireLog(l) {
715
+ return { ...fromWireLogListItem(l), requestBody: l.request_body, responseBody: l.response_body };
716
+ }
717
+ var LogsResource = class {
718
+ constructor(http) {
719
+ this.http = http;
720
+ }
721
+ http;
722
+ /** `GET /logs` — cursor paginated, newest first. */
723
+ list(options) {
724
+ return mapResponse(
725
+ this.http.request("GET", "/logs", {
726
+ query: { limit: options?.limit, after: options?.after, before: options?.before }
727
+ }),
728
+ (raw) => ({ object: "list", hasMore: raw.has_more, data: raw.data.map(fromWireLogListItem) })
729
+ );
730
+ }
731
+ /** `GET /logs/:id` */
732
+ get(id) {
733
+ return mapResponse(this.http.request("GET", `/logs/${id}`), fromWireLog);
734
+ }
735
+ };
736
+
737
+ // src/resources/suppressions.ts
738
+ function fromWireSuppression(s) {
739
+ return { object: "suppression", id: s.id, email: s.email, origin: s.origin, sourceId: s.source_id, createdAt: s.created_at };
740
+ }
741
+ var SuppressionsBatchResource = class {
742
+ constructor(http) {
743
+ this.http = http;
744
+ }
745
+ http;
746
+ /** `POST /suppressions/batch/add` — up to 100 addresses at once. */
747
+ add(input) {
748
+ return this.http.request("POST", "/suppressions/batch/add", { body: { emails: input.emails } });
749
+ }
750
+ /** `POST /suppressions/batch/remove` — provide exactly one of `emails`/`ids`, up to 100 entries. */
751
+ remove(input) {
752
+ return this.http.request("POST", "/suppressions/batch/remove", {
753
+ body: { emails: input.emails, ids: input.ids }
754
+ });
755
+ }
756
+ };
757
+ var SuppressionsResource = class {
758
+ constructor(http) {
759
+ this.http = http;
760
+ this.batch = new SuppressionsBatchResource(http);
761
+ }
762
+ http;
763
+ batch;
764
+ /** `POST /suppressions` */
765
+ add(input) {
766
+ return this.http.request("POST", "/suppressions", { body: { email: input.email } });
767
+ }
768
+ /** `GET /suppressions` */
769
+ list(options) {
770
+ return mapResponse(
771
+ this.http.request("GET", "/suppressions", {
772
+ query: { limit: options?.limit, after: options?.after, before: options?.before, origin: options?.origin }
773
+ }),
774
+ (raw) => ({ object: "list", hasMore: raw.has_more, data: raw.data.map(fromWireSuppression) })
775
+ );
776
+ }
777
+ /** `GET /suppressions/:suppression` — accepts either a suppression id or an email address. */
778
+ get(idOrEmail) {
779
+ return mapResponse(this.http.request("GET", `/suppressions/${encodeURIComponent(idOrEmail)}`), fromWireSuppression);
780
+ }
781
+ /** `DELETE /suppressions/:suppression` — accepts either a suppression id or an email address. */
782
+ remove(idOrEmail) {
783
+ return this.http.request("DELETE", `/suppressions/${encodeURIComponent(idOrEmail)}`);
784
+ }
785
+ };
786
+
379
787
  // src/resources/templates.ts
380
788
  function toWireVariable(v) {
381
789
  return { key: v.key, type: v.type, fallback_value: v.fallbackValue };
@@ -500,6 +908,7 @@ var TemplatesResource = class {
500
908
  };
501
909
 
502
910
  // src/resources/webhooks.ts
911
+ import { createHmac, timingSafeEqual } from "crypto";
503
912
  function fromWireWebhook(w) {
504
913
  return { object: "webhook", id: w.id, endpoint: w.endpoint, events: w.events, status: w.status, createdAt: w.created_at, signingSecret: w.signing_secret };
505
914
  }
@@ -532,6 +941,27 @@ var WebhooksResource = class {
532
941
  remove(id) {
533
942
  return this.http.request("DELETE", `/webhooks/${id}`);
534
943
  }
944
+ /**
945
+ * Verifies a Standard Webhooks-signed delivery to this plugin's receiver (byte-compatible with
946
+ * Svix — ports `packages/core/src/webhooks.ts`'s `verifyWebhook` so a consumer never needs
947
+ * `@irisend/core`, just this SDK, to validate an inbound webhook). Accepts either `webhook-*`
948
+ * or `svix-*` header names; pass a plain lower-cased header map (e.g.
949
+ * `Object.fromEntries(req.headers)`). `toleranceSec` bounds how stale `webhook-timestamp` may
950
+ * be (default 300s, matching Standard Webhooks' recommendation).
951
+ */
952
+ verify(secret, headers, body, toleranceSec = 300) {
953
+ const id = headers["webhook-id"] ?? headers["svix-id"];
954
+ const ts = Number(headers["webhook-timestamp"] ?? headers["svix-timestamp"]);
955
+ const sigHeader = headers["webhook-signature"] ?? headers["svix-signature"];
956
+ if (!id || !ts || !sigHeader) return false;
957
+ if (Math.abs(Date.now() / 1e3 - ts) > toleranceSec) return false;
958
+ const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
959
+ const expected = Buffer.from(createHmac("sha256", key).update(`${id}.${ts}.${body}`).digest("base64"));
960
+ return sigHeader.split(" ").some((part) => {
961
+ const candidate = Buffer.from(part.replace(/^v1,/, ""));
962
+ return candidate.length === expected.length && timingSafeEqual(candidate, expected);
963
+ });
964
+ }
535
965
  };
536
966
 
537
967
  // src/irisend.ts
@@ -543,7 +973,11 @@ var Irisend = class {
543
973
  webhooks;
544
974
  audiences;
545
975
  contacts;
976
+ consents;
546
977
  templates;
978
+ logs;
979
+ broadcasts;
980
+ suppressions;
547
981
  /** Resend-style alias: `batch.send` is the same call as `emails.sendBatch`. */
548
982
  batch;
549
983
  constructor(apiKey, options = {}) {
@@ -555,7 +989,11 @@ var Irisend = class {
555
989
  this.webhooks = new WebhooksResource(http);
556
990
  this.audiences = new AudiencesResource(http);
557
991
  this.contacts = new ContactsResource(http);
992
+ this.consents = new ConsentsResource(http);
558
993
  this.templates = new TemplatesResource(http);
994
+ this.logs = new LogsResource(http);
995
+ this.broadcasts = new BroadcastsResource(http);
996
+ this.suppressions = new SuppressionsResource(http);
559
997
  this.batch = { send: this.emails.sendBatch.bind(this.emails) };
560
998
  }
561
999
  };
package/package.json CHANGED
@@ -1,7 +1,21 @@
1
1
  {
2
2
  "name": "@irisend/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Official Node.js SDK for the Irisend API (Resend-compatible).",
5
+ "keywords": [
6
+ "irisend",
7
+ "email",
8
+ "email-api",
9
+ "transactional-email",
10
+ "resend-alternative",
11
+ "sdk",
12
+ "ses"
13
+ ],
14
+ "homepage": "https://irisend.com/docs#sdk-node",
15
+ "bugs": {
16
+ "email": "legal@irisend.com"
17
+ },
18
+ "author": "Irisend <legal@irisend.com> (https://irisend.com)",
5
19
  "type": "module",
6
20
  "license": "MIT",
7
21
  "engines": {
@@ -20,11 +34,24 @@
20
34
  "dist",
21
35
  "README.md"
22
36
  ],
37
+ "peerDependencies": {
38
+ "@react-email/render": "^1.0.0 || ^2.0.0"
39
+ },
40
+ "peerDependenciesMeta": {
41
+ "@react-email/render": {
42
+ "optional": true
43
+ }
44
+ },
23
45
  "devDependencies": {
46
+ "@react-email/render": "^2.2.0",
24
47
  "@types/node": "^22.20.4",
48
+ "@types/react": "^19.3.0",
49
+ "react": "19.2.8",
50
+ "react-dom": "19.2.8",
25
51
  "tsup": "^8.5.1",
26
52
  "typescript": "^5.9.3",
27
- "vitest": "^5.0.2"
53
+ "vitest": "^5.0.2",
54
+ "@irisend/core": "0.0.0"
28
55
  },
29
56
  "scripts": {
30
57
  "build": "tsup",