resend 6.0.0 → 6.1.0-canary.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/dist/index.d.mts CHANGED
@@ -16,6 +16,27 @@ interface PutOptions {
16
16
  };
17
17
  }
18
18
 
19
+ type RateLimit = {
20
+ /**
21
+ * The maximum amount of requests that can be made in the time window of {@link shouldResetAfter}.
22
+ */
23
+ limit: number;
24
+ /**
25
+ * The amount of requests that can still be made before hitting {@link RateLimit.limit}.
26
+ *
27
+ * Resets after the seconds in {@link RateLimit.shouldResetAfter} go by.
28
+ */
29
+ remainingRequests: number;
30
+ /**
31
+ * The number of seconds after which the rate limiting will reset,
32
+ * and {@link RateLimit.remainingRequests} goes back to the value of
33
+ * {@link RateLimit.limit}.
34
+ *
35
+ * @see {@link import('./interfaces').Response.retryAfter}
36
+ */
37
+ shouldResetAfter: number;
38
+ };
39
+
19
40
  declare const RESEND_ERROR_CODES_BY_KEY: {
20
41
  readonly missing_required_field: 422;
21
42
  readonly invalid_idempotency_key: 400;
@@ -35,10 +56,26 @@ declare const RESEND_ERROR_CODES_BY_KEY: {
35
56
  readonly internal_server_error: 500;
36
57
  };
37
58
  type RESEND_ERROR_CODE_KEY = keyof typeof RESEND_ERROR_CODES_BY_KEY;
38
- interface ErrorResponse {
59
+ type ErrorResponse = {
39
60
  message: string;
40
- name: RESEND_ERROR_CODE_KEY;
41
- }
61
+ name: Exclude<RESEND_ERROR_CODE_KEY, 'rate_limit_exceeded'>;
62
+ } | {
63
+ message: string;
64
+ name: Extract<RESEND_ERROR_CODE_KEY, 'rate_limit_exceeded'>;
65
+ /**
66
+ * Time in seconds.
67
+ */
68
+ retryAfter: number;
69
+ };
70
+ type Response<Data> = {
71
+ data: Data;
72
+ rateLimiting: RateLimit;
73
+ error: null;
74
+ } | {
75
+ data: null;
76
+ rateLimiting: RateLimit | null;
77
+ error: ErrorResponse;
78
+ };
42
79
 
43
80
  interface CreateApiKeyOptions {
44
81
  name: string;
@@ -51,13 +88,7 @@ interface CreateApiKeyResponseSuccess {
51
88
  token: string;
52
89
  id: string;
53
90
  }
54
- type CreateApiKeyResponse = {
55
- data: CreateApiKeyResponseSuccess;
56
- error: null;
57
- } | {
58
- data: null;
59
- error: ErrorResponse;
60
- };
91
+ type CreateApiKeyResponse = Response<CreateApiKeyResponseSuccess>;
61
92
 
62
93
  interface ApiKey {
63
94
  created_at: string;
@@ -66,22 +97,10 @@ interface ApiKey {
66
97
  }
67
98
 
68
99
  type ListApiKeysResponseSuccess = Pick<ApiKey, 'name' | 'id' | 'created_at'>[];
69
- type ListApiKeysResponse = {
70
- data: ListApiKeysResponseSuccess;
71
- error: null;
72
- } | {
73
- data: null;
74
- error: ErrorResponse;
75
- };
100
+ type ListApiKeysResponse = Response<ListApiKeysResponseSuccess>;
76
101
 
77
102
  type RemoveApiKeyResponseSuccess = {};
78
- type RemoveApiKeyResponse = {
79
- data: RemoveApiKeyResponseSuccess;
80
- error: null;
81
- } | {
82
- data: null;
83
- error: ErrorResponse;
84
- };
103
+ type RemoveApiKeyResponse = Response<RemoveApiKeyResponseSuccess>;
85
104
 
86
105
  declare class ApiKeys {
87
106
  private readonly resend;
@@ -105,48 +124,24 @@ interface CreateAudienceRequestOptions extends PostOptions {
105
124
  interface CreateAudienceResponseSuccess extends Pick<Audience, 'name' | 'id'> {
106
125
  object: 'audience';
107
126
  }
108
- type CreateAudienceResponse = {
109
- data: CreateAudienceResponseSuccess;
110
- error: null;
111
- } | {
112
- data: null;
113
- error: ErrorResponse;
114
- };
127
+ type CreateAudienceResponse = Response<CreateAudienceResponseSuccess>;
115
128
 
116
129
  interface GetAudienceResponseSuccess extends Pick<Audience, 'id' | 'name' | 'created_at'> {
117
130
  object: 'audience';
118
131
  }
119
- type GetAudienceResponse = {
120
- data: GetAudienceResponseSuccess;
121
- error: null;
122
- } | {
123
- data: null;
124
- error: ErrorResponse;
125
- };
132
+ type GetAudienceResponse = Response<GetAudienceResponseSuccess>;
126
133
 
127
134
  type ListAudiencesResponseSuccess = {
128
135
  object: 'list';
129
136
  data: Audience[];
130
137
  };
131
- type ListAudiencesResponse = {
132
- data: ListAudiencesResponseSuccess;
133
- error: null;
134
- } | {
135
- data: null;
136
- error: ErrorResponse;
137
- };
138
+ type ListAudiencesResponse = Response<ListAudiencesResponseSuccess>;
138
139
 
139
140
  interface RemoveAudiencesResponseSuccess extends Pick<Audience, 'id'> {
140
141
  object: 'audience';
141
142
  deleted: boolean;
142
143
  }
143
- type RemoveAudiencesResponse = {
144
- data: RemoveAudiencesResponseSuccess;
145
- error: null;
146
- } | {
147
- data: null;
148
- error: ErrorResponse;
149
- };
144
+ type RemoveAudiencesResponse = Response<RemoveAudiencesResponseSuccess>;
150
145
 
151
146
  declare class Audiences {
152
147
  private readonly resend;
@@ -260,13 +255,7 @@ interface CreateEmailResponseSuccess {
260
255
  /** The ID of the newly created email. */
261
256
  id: string;
262
257
  }
263
- type CreateEmailResponse = {
264
- data: CreateEmailResponseSuccess;
265
- error: null;
266
- } | {
267
- data: null;
268
- error: ErrorResponse;
269
- };
258
+ type CreateEmailResponse = Response<CreateEmailResponseSuccess>;
270
259
  interface Attachment {
271
260
  /** Content of an attached file. */
272
261
  content?: string | Buffer;
@@ -302,13 +291,7 @@ interface CreateBatchSuccessResponse {
302
291
  id: string;
303
292
  }[];
304
293
  }
305
- type CreateBatchResponse = {
306
- data: CreateBatchSuccessResponse;
307
- error: null;
308
- } | {
309
- data: null;
310
- error: ErrorResponse;
311
- };
294
+ type CreateBatchResponse = Response<CreateBatchSuccessResponse>;
312
295
 
313
296
  declare class Batch {
314
297
  private readonly resend;
@@ -383,13 +366,7 @@ interface CreateBroadcastResponseSuccess {
383
366
  /** The ID of the newly sent broadcasts. */
384
367
  id: string;
385
368
  }
386
- type CreateBroadcastResponse = {
387
- data: CreateBroadcastResponseSuccess;
388
- error: null;
389
- } | {
390
- data: null;
391
- error: ErrorResponse;
392
- };
369
+ type CreateBroadcastResponse = Response<CreateBroadcastResponseSuccess>;
393
370
 
394
371
  interface Broadcast {
395
372
  id: string;
@@ -408,37 +385,19 @@ interface Broadcast {
408
385
  interface GetBroadcastResponseSuccess extends Broadcast {
409
386
  object: 'broadcast';
410
387
  }
411
- type GetBroadcastResponse = {
412
- data: GetBroadcastResponseSuccess;
413
- error: null;
414
- } | {
415
- data: null;
416
- error: ErrorResponse;
417
- };
388
+ type GetBroadcastResponse = Response<GetBroadcastResponseSuccess>;
418
389
 
419
390
  type ListBroadcastsResponseSuccess = {
420
391
  object: 'list';
421
392
  data: Pick<Broadcast, 'id' | 'name' | 'audience_id' | 'status' | 'created_at' | 'scheduled_at' | 'sent_at'>[];
422
393
  };
423
- type ListBroadcastsResponse = {
424
- data: ListBroadcastsResponseSuccess;
425
- error: null;
426
- } | {
427
- data: null;
428
- error: ErrorResponse;
429
- };
394
+ type ListBroadcastsResponse = Response<ListBroadcastsResponseSuccess>;
430
395
 
431
396
  interface RemoveBroadcastResponseSuccess extends Pick<Broadcast, 'id'> {
432
397
  object: 'broadcast';
433
398
  deleted: boolean;
434
399
  }
435
- type RemoveBroadcastResponse = {
436
- data: RemoveBroadcastResponseSuccess;
437
- error: null;
438
- } | {
439
- data: null;
440
- error: ErrorResponse;
441
- };
400
+ type RemoveBroadcastResponse = Response<RemoveBroadcastResponseSuccess>;
442
401
 
443
402
  interface SendBroadcastBaseOptions {
444
403
  /**
@@ -457,13 +416,7 @@ interface SendBroadcastResponseSuccess {
457
416
  /** The ID of the sent broadcast. */
458
417
  id: string;
459
418
  }
460
- type SendBroadcastResponse = {
461
- data: SendBroadcastResponseSuccess;
462
- error: null;
463
- } | {
464
- data: null;
465
- error: ErrorResponse;
466
- };
419
+ type SendBroadcastResponse = Response<SendBroadcastResponseSuccess>;
467
420
 
468
421
  interface UpdateBroadcastResponseSuccess {
469
422
  id: string;
@@ -478,13 +431,7 @@ interface UpdateBroadcastOptions {
478
431
  replyTo?: string[];
479
432
  previewText?: string;
480
433
  }
481
- type UpdateBroadcastResponse = {
482
- data: UpdateBroadcastResponseSuccess;
483
- error: null;
484
- } | {
485
- data: null;
486
- error: ErrorResponse;
487
- };
434
+ type UpdateBroadcastResponse = Response<UpdateBroadcastResponseSuccess>;
488
435
 
489
436
  declare class Broadcasts {
490
437
  private readonly resend;
@@ -512,6 +459,33 @@ interface Contact {
512
459
  last_name?: string;
513
460
  unsubscribed: boolean;
514
461
  }
462
+ type SelectingField = {
463
+ /**
464
+ * The contact id.
465
+ *
466
+ * @link https://resend.com/docs/api-reference/contacts/delete-contact#body-parameters
467
+ */
468
+ id: string;
469
+ /**
470
+ * The contact email.
471
+ *
472
+ * @link https://resend.com/docs/api-reference/contacts/delete-contact#body-parameters
473
+ */
474
+ email?: undefined | null;
475
+ } | {
476
+ /**
477
+ * The contact id.
478
+ *
479
+ * @link https://resend.com/docs/api-reference/contacts/delete-contact#body-parameters
480
+ */
481
+ id?: undefined | null;
482
+ /**
483
+ * The contact email.
484
+ *
485
+ * @link https://resend.com/docs/api-reference/contacts/delete-contact#body-parameters
486
+ */
487
+ email: string;
488
+ };
515
489
 
516
490
  interface CreateContactOptions {
517
491
  audienceId: string;
@@ -525,29 +499,15 @@ interface CreateContactRequestOptions extends PostOptions {
525
499
  interface CreateContactResponseSuccess extends Pick<Contact, 'id'> {
526
500
  object: 'contact';
527
501
  }
528
- type CreateContactResponse = {
529
- data: CreateContactResponseSuccess;
530
- error: null;
531
- } | {
532
- data: null;
533
- error: ErrorResponse;
534
- };
502
+ type CreateContactResponse = Response<CreateContactResponseSuccess>;
535
503
 
536
- interface GetContactOptions {
504
+ type GetContactOptions = {
537
505
  audienceId: string;
538
- id?: string;
539
- email?: string;
540
- }
506
+ } & SelectingField;
541
507
  interface GetContactResponseSuccess extends Pick<Contact, 'id' | 'email' | 'created_at' | 'first_name' | 'last_name' | 'unsubscribed'> {
542
508
  object: 'contact';
543
509
  }
544
- type GetContactResponse = {
545
- data: GetContactResponseSuccess;
546
- error: null;
547
- } | {
548
- data: null;
549
- error: ErrorResponse;
550
- };
510
+ type GetContactResponse = Response<GetContactResponseSuccess>;
551
511
 
552
512
  interface ListContactsOptions {
553
513
  audienceId: string;
@@ -556,64 +516,28 @@ interface ListContactsResponseSuccess {
556
516
  object: 'list';
557
517
  data: Contact[];
558
518
  }
559
- type ListContactsResponse = {
560
- data: ListContactsResponseSuccess;
561
- error: null;
562
- } | {
563
- data: null;
564
- error: ErrorResponse;
565
- };
519
+ type ListContactsResponse = Response<ListContactsResponseSuccess>;
566
520
 
567
521
  type RemoveContactsResponseSuccess = {
568
522
  object: 'contact';
569
523
  deleted: boolean;
570
524
  contact: string;
571
525
  };
572
- interface RemoveByOptions {
573
- /**
574
- * The contact id.
575
- *
576
- * @link https://resend.com/docs/api-reference/contacts/delete-contact#body-parameters
577
- */
578
- id?: string;
579
- /**
580
- * The contact email.
581
- *
582
- * @link https://resend.com/docs/api-reference/contacts/delete-contact#body-parameters
583
- */
584
- email?: string;
585
- }
586
- interface RemoveContactOptions extends RemoveByOptions {
526
+ type RemoveContactOptions = SelectingField & {
587
527
  audienceId: string;
588
- }
589
- type RemoveContactsResponse = {
590
- data: RemoveContactsResponseSuccess;
591
- error: null;
592
- } | {
593
- data: null;
594
- error: ErrorResponse;
595
528
  };
529
+ type RemoveContactsResponse = Response<RemoveContactsResponseSuccess>;
596
530
 
597
- interface UpdateContactBaseOptions {
598
- id?: string;
599
- email?: string;
600
- }
601
- interface UpdateContactOptions extends UpdateContactBaseOptions {
531
+ type UpdateContactOptions = {
602
532
  audienceId: string;
603
533
  unsubscribed?: boolean;
604
534
  firstName?: string;
605
535
  lastName?: string;
606
- }
536
+ } & SelectingField;
607
537
  type UpdateContactResponseSuccess = Pick<Contact, 'id'> & {
608
538
  object: 'contact';
609
539
  };
610
- type UpdateContactResponse = {
611
- data: UpdateContactResponseSuccess;
612
- error: null;
613
- } | {
614
- data: null;
615
- error: ErrorResponse;
616
- };
540
+ type UpdateContactResponse = Response<UpdateContactResponseSuccess>;
617
541
 
618
542
  declare class Contacts {
619
543
  private readonly resend;
@@ -621,7 +545,7 @@ declare class Contacts {
621
545
  create(payload: CreateContactOptions, options?: CreateContactRequestOptions): Promise<CreateContactResponse>;
622
546
  list(options: ListContactsOptions): Promise<ListContactsResponse>;
623
547
  get(options: GetContactOptions): Promise<GetContactResponse>;
624
- update(payload: UpdateContactOptions): Promise<UpdateContactResponse>;
548
+ update(options: UpdateContactOptions): Promise<UpdateContactResponse>;
625
549
  remove(payload: RemoveContactOptions): Promise<RemoveContactsResponse>;
626
550
  }
627
551
 
@@ -668,48 +592,24 @@ interface CreateDomainRequestOptions extends PostOptions {
668
592
  interface CreateDomainResponseSuccess extends Pick<Domain, 'name' | 'id' | 'status' | 'created_at' | 'region'> {
669
593
  records: DomainRecords[];
670
594
  }
671
- type CreateDomainResponse = {
672
- data: CreateDomainResponseSuccess;
673
- error: null;
674
- } | {
675
- data: null;
676
- error: ErrorResponse;
677
- };
595
+ type CreateDomainResponse = Response<CreateDomainResponseSuccess>;
678
596
 
679
597
  interface GetDomainResponseSuccess extends Pick<Domain, 'id' | 'name' | 'created_at' | 'region' | 'status'> {
680
598
  object: 'domain';
681
599
  records: DomainRecords[];
682
600
  }
683
- type GetDomainResponse = {
684
- data: GetDomainResponseSuccess;
685
- error: null;
686
- } | {
687
- data: null;
688
- error: ErrorResponse;
689
- };
601
+ type GetDomainResponse = Response<GetDomainResponseSuccess>;
690
602
 
691
603
  type ListDomainsResponseSuccess = {
692
604
  data: Domain[];
693
605
  };
694
- type ListDomainsResponse = {
695
- data: ListDomainsResponseSuccess;
696
- error: null;
697
- } | {
698
- data: null;
699
- error: ErrorResponse;
700
- };
606
+ type ListDomainsResponse = Response<ListDomainsResponseSuccess>;
701
607
 
702
608
  type RemoveDomainsResponseSuccess = Pick<Domain, 'id'> & {
703
609
  object: 'domain';
704
610
  deleted: boolean;
705
611
  };
706
- type RemoveDomainsResponse = {
707
- data: RemoveDomainsResponseSuccess;
708
- error: null;
709
- } | {
710
- data: null;
711
- error: ErrorResponse;
712
- };
612
+ type RemoveDomainsResponse = Response<RemoveDomainsResponseSuccess>;
713
613
 
714
614
  interface UpdateDomainsOptions {
715
615
  id: string;
@@ -720,24 +620,12 @@ interface UpdateDomainsOptions {
720
620
  type UpdateDomainsResponseSuccess = Pick<Domain, 'id'> & {
721
621
  object: 'domain';
722
622
  };
723
- type UpdateDomainsResponse = {
724
- data: UpdateDomainsResponseSuccess;
725
- error: null;
726
- } | {
727
- data: null;
728
- error: ErrorResponse;
729
- };
623
+ type UpdateDomainsResponse = Response<UpdateDomainsResponseSuccess>;
730
624
 
731
625
  type VerifyDomainsResponseSuccess = Pick<Domain, 'id'> & {
732
626
  object: 'domain';
733
627
  };
734
- type VerifyDomainsResponse = {
735
- data: VerifyDomainsResponseSuccess;
736
- error: null;
737
- } | {
738
- data: null;
739
- error: ErrorResponse;
740
- };
628
+ type VerifyDomainsResponse = Response<VerifyDomainsResponseSuccess>;
741
629
 
742
630
  declare class Domains {
743
631
  private readonly resend;
@@ -754,13 +642,7 @@ interface CancelEmailResponseSuccess {
754
642
  object: 'email';
755
643
  id: string;
756
644
  }
757
- type CancelEmailResponse = {
758
- data: CancelEmailResponseSuccess;
759
- error: null;
760
- } | {
761
- data: null;
762
- error: ErrorResponse;
763
- };
645
+ type CancelEmailResponse = Response<CancelEmailResponseSuccess>;
764
646
 
765
647
  interface GetEmailResponseSuccess {
766
648
  bcc: string[] | null;
@@ -773,17 +655,15 @@ interface GetEmailResponseSuccess {
773
655
  reply_to: string[] | null;
774
656
  subject: string;
775
657
  text: string | null;
658
+ tags?: {
659
+ name: string;
660
+ value: string;
661
+ }[];
776
662
  to: string[];
777
663
  scheduled_at: string | null;
778
664
  object: 'email';
779
665
  }
780
- type GetEmailResponse = {
781
- data: GetEmailResponseSuccess;
782
- error: null;
783
- } | {
784
- data: null;
785
- error: ErrorResponse;
786
- };
666
+ type GetEmailResponse = Response<GetEmailResponseSuccess>;
787
667
 
788
668
  interface UpdateEmailOptions {
789
669
  id: string;
@@ -793,13 +673,7 @@ interface UpdateEmailResponseSuccess {
793
673
  id: string;
794
674
  object: 'email';
795
675
  }
796
- type UpdateEmailResponse = {
797
- data: UpdateEmailResponseSuccess;
798
- error: null;
799
- } | {
800
- data: null;
801
- error: ErrorResponse;
802
- };
676
+ type UpdateEmailResponse = Response<UpdateEmailResponseSuccess>;
803
677
 
804
678
  declare class Emails {
805
679
  private readonly resend;
@@ -823,48 +697,12 @@ declare class Resend {
823
697
  readonly domains: Domains;
824
698
  readonly emails: Emails;
825
699
  constructor(key?: string | undefined);
826
- fetchRequest<T>(path: string, options?: {}): Promise<{
827
- data: T;
828
- error: null;
829
- } | {
830
- data: null;
831
- error: ErrorResponse;
832
- }>;
833
- post<T>(path: string, entity?: unknown, options?: PostOptions & IdempotentRequest): Promise<{
834
- data: null;
835
- error: ErrorResponse;
836
- } | {
837
- data: T;
838
- error: null;
839
- }>;
840
- get<T>(path: string, options?: GetOptions): Promise<{
841
- data: null;
842
- error: ErrorResponse;
843
- } | {
844
- data: T;
845
- error: null;
846
- }>;
847
- put<T>(path: string, entity: unknown, options?: PutOptions): Promise<{
848
- data: null;
849
- error: ErrorResponse;
850
- } | {
851
- data: T;
852
- error: null;
853
- }>;
854
- patch<T>(path: string, entity: unknown, options?: PatchOptions): Promise<{
855
- data: null;
856
- error: ErrorResponse;
857
- } | {
858
- data: T;
859
- error: null;
860
- }>;
861
- delete<T>(path: string, query?: unknown): Promise<{
862
- data: null;
863
- error: ErrorResponse;
864
- } | {
865
- data: T;
866
- error: null;
867
- }>;
700
+ fetchRequest<T>(path: string, options?: {}): Promise<Response<T>>;
701
+ post<T>(path: string, entity?: unknown, options?: PostOptions & IdempotentRequest): Promise<Response<T>>;
702
+ get<T>(path: string, options?: GetOptions): Promise<Response<T>>;
703
+ put<T>(path: string, entity: unknown, options?: PutOptions): Promise<Response<T>>;
704
+ patch<T>(path: string, entity: unknown, options?: PatchOptions): Promise<Response<T>>;
705
+ delete<T>(path: string, query?: unknown): Promise<Response<T>>;
868
706
  }
869
707
 
870
708
  export { Attachment, CreateApiKeyOptions, CreateApiKeyRequestOptions, CreateApiKeyResponse, CreateApiKeyResponseSuccess, CreateAudienceOptions, CreateAudienceRequestOptions, CreateAudienceResponse, CreateAudienceResponseSuccess, CreateBatchOptions, CreateBatchRequestOptions, CreateBatchResponse, CreateBatchSuccessResponse, CreateBroadcastOptions, CreateBroadcastRequestOptions, CreateBroadcastResponse, CreateBroadcastResponseSuccess, CreateContactOptions, CreateContactRequestOptions, CreateContactResponse, CreateContactResponseSuccess, CreateDomainOptions, CreateDomainRequestOptions, CreateDomainResponse, CreateDomainResponseSuccess, CreateEmailOptions, CreateEmailRequestOptions, CreateEmailResponse, CreateEmailResponseSuccess, ErrorResponse, GetAudienceResponse, GetAudienceResponseSuccess, GetContactOptions, GetContactResponse, GetContactResponseSuccess, GetDomainResponse, GetDomainResponseSuccess, GetEmailResponse, GetEmailResponseSuccess, ListApiKeysResponse, ListApiKeysResponseSuccess, ListAudiencesResponse, ListAudiencesResponseSuccess, ListContactsOptions, ListContactsResponse, ListContactsResponseSuccess, ListDomainsResponse, ListDomainsResponseSuccess, RemoveApiKeyResponse, RemoveApiKeyResponseSuccess, RemoveAudiencesResponse, RemoveAudiencesResponseSuccess, RemoveContactOptions, RemoveContactsResponse, RemoveContactsResponseSuccess, RemoveDomainsResponse, RemoveDomainsResponseSuccess, Resend, SendBroadcastOptions, SendBroadcastRequestOptions, SendBroadcastResponse, SendBroadcastResponseSuccess, Tag, UpdateContactOptions, UpdateContactResponse, UpdateContactResponseSuccess, UpdateDomainsOptions, UpdateDomainsResponse, UpdateDomainsResponseSuccess, VerifyDomainsResponse, VerifyDomainsResponseSuccess };