resend 6.10.0 → 6.11.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.cjs CHANGED
@@ -1,4 +1,4 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  //#region \0rolldown/runtime.js
3
3
  var __create = Object.create;
4
4
  var __defProp = Object.defineProperty;
@@ -7,16 +7,12 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
- key = keys[i];
13
- if (!__hasOwnProp.call(to, key) && key !== except) {
14
- __defProp(to, key, {
15
- get: ((k) => from[k]).bind(null, key),
16
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
- });
18
- }
19
- }
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
20
16
  }
21
17
  return to;
22
18
  };
@@ -24,15 +20,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
20
  value: mod,
25
21
  enumerable: true
26
22
  }) : target, mod));
27
-
28
23
  //#endregion
29
24
  let postal_mime = require("postal-mime");
30
25
  postal_mime = __toESM(postal_mime);
31
26
  let svix = require("svix");
32
-
33
27
  //#region package.json
34
- var version = "6.10.0";
35
-
28
+ var version = "6.11.0-canary.0";
36
29
  //#endregion
37
30
  //#region src/common/utils/build-pagination-query.ts
38
31
  /**
@@ -47,7 +40,6 @@ function buildPaginationQuery(options) {
47
40
  if ("before" in options && options.before !== void 0) searchParams.set("before", options.before);
48
41
  return searchParams.toString();
49
42
  }
50
-
51
43
  //#endregion
52
44
  //#region src/api-keys/api-keys.ts
53
45
  var ApiKeys = class {
@@ -66,7 +58,140 @@ var ApiKeys = class {
66
58
  return await this.resend.delete(`/api-keys/${id}`);
67
59
  }
68
60
  };
69
-
61
+ //#endregion
62
+ //#region src/automation-runs/automation-runs.ts
63
+ var AutomationRuns = class {
64
+ constructor(resend) {
65
+ this.resend = resend;
66
+ }
67
+ async get(options) {
68
+ return await this.resend.get(`/automations/${options.automationId}/runs/${options.runId}`);
69
+ }
70
+ async list(options) {
71
+ const queryString = buildPaginationQuery(options);
72
+ const searchParams = new URLSearchParams(queryString);
73
+ if (options.status) {
74
+ const statusValue = Array.isArray(options.status) ? options.status.join(",") : options.status;
75
+ searchParams.set("status", statusValue);
76
+ }
77
+ const qs = searchParams.toString();
78
+ const url = qs ? `/automations/${options.automationId}/runs?${qs}` : `/automations/${options.automationId}/runs`;
79
+ return await this.resend.get(url);
80
+ }
81
+ };
82
+ //#endregion
83
+ //#region src/common/utils/parse-automation-to-api-options.ts
84
+ function parseStepConfig(step) {
85
+ switch (step.type) {
86
+ case "trigger": return {
87
+ key: step.key,
88
+ type: step.type,
89
+ config: { event_name: step.config.eventName }
90
+ };
91
+ case "delay": return {
92
+ key: step.key,
93
+ type: step.type,
94
+ config: step.config
95
+ };
96
+ case "send_email": return {
97
+ key: step.key,
98
+ type: step.type,
99
+ config: {
100
+ template: step.config.template,
101
+ subject: step.config.subject,
102
+ from: step.config.from,
103
+ reply_to: step.config.replyTo
104
+ }
105
+ };
106
+ case "wait_for_event": return {
107
+ key: step.key,
108
+ type: step.type,
109
+ config: {
110
+ event_name: step.config.eventName,
111
+ timeout: step.config.timeout,
112
+ filter_rule: step.config.filterRule
113
+ }
114
+ };
115
+ case "condition": return {
116
+ key: step.key,
117
+ type: step.type,
118
+ config: step.config
119
+ };
120
+ case "contact_update": return {
121
+ key: step.key,
122
+ type: step.type,
123
+ config: step.config
124
+ };
125
+ case "contact_delete": return {
126
+ key: step.key,
127
+ type: step.type,
128
+ config: step.config
129
+ };
130
+ case "add_to_segment": return {
131
+ key: step.key,
132
+ type: step.type,
133
+ config: step.config
134
+ };
135
+ }
136
+ }
137
+ function parseConnection(connection) {
138
+ return {
139
+ from: connection.from,
140
+ to: connection.to,
141
+ type: connection.type
142
+ };
143
+ }
144
+ function parseAutomationToApiOptions(automation) {
145
+ return {
146
+ name: automation.name,
147
+ status: automation.status,
148
+ steps: automation.steps.map(parseStepConfig),
149
+ connections: automation.connections.map(parseConnection)
150
+ };
151
+ }
152
+ function parseEventToApiOptions(event) {
153
+ return {
154
+ event: event.event,
155
+ contact_id: event.contactId,
156
+ email: event.email,
157
+ payload: event.payload
158
+ };
159
+ }
160
+ //#endregion
161
+ //#region src/automations/automations.ts
162
+ var Automations = class {
163
+ constructor(resend) {
164
+ this.resend = resend;
165
+ this.runs = new AutomationRuns(this.resend);
166
+ }
167
+ async create(payload) {
168
+ return await this.resend.post("/automations", parseAutomationToApiOptions(payload));
169
+ }
170
+ async list(options = {}) {
171
+ const params = [buildPaginationQuery(options)];
172
+ if (options.status) params.push(`status=${encodeURIComponent(options.status)}`);
173
+ const qs = params.filter(Boolean).join("&");
174
+ const url = qs ? `/automations?${qs}` : "/automations";
175
+ return await this.resend.get(url);
176
+ }
177
+ async get(id) {
178
+ return await this.resend.get(`/automations/${id}`);
179
+ }
180
+ async remove(id) {
181
+ return await this.resend.delete(`/automations/${id}`);
182
+ }
183
+ async update(id, payload) {
184
+ const apiPayload = {};
185
+ if (payload.name !== void 0) apiPayload.name = payload.name;
186
+ if (payload.status !== void 0) apiPayload.status = payload.status;
187
+ if (payload.steps !== void 0) apiPayload.steps = payload.steps.map(parseStepConfig);
188
+ if (payload.connections !== void 0) apiPayload.connections = payload.connections.map(parseConnection);
189
+ return await this.resend.patch(`/automations/${id}`, apiPayload);
190
+ }
191
+ async stop(id) {
192
+ return await this.resend.post(`/automations/${id}/stop`);
193
+ }
194
+ };
70
195
  //#endregion
71
196
  //#region src/common/utils/parse-email-to-api-options.ts
72
197
  function parseAttachments(attachments) {
@@ -99,7 +224,6 @@ function parseEmailToApiOptions(email) {
99
224
  topic_id: email.topicId
100
225
  };
101
226
  }
102
-
103
227
  //#endregion
104
228
  //#region src/render.ts
105
229
  async function render(node) {
@@ -111,7 +235,6 @@ async function render(node) {
111
235
  }
112
236
  return render(node);
113
237
  }
114
-
115
238
  //#endregion
116
239
  //#region src/batch/batch.ts
117
240
  var Batch = class {
@@ -139,7 +262,6 @@ var Batch = class {
139
262
  });
140
263
  }
141
264
  };
142
-
143
265
  //#endregion
144
266
  //#region src/broadcasts/broadcasts.ts
145
267
  var Broadcasts = class {
@@ -193,7 +315,6 @@ var Broadcasts = class {
193
315
  });
194
316
  }
195
317
  };
196
-
197
318
  //#endregion
198
319
  //#region src/common/utils/parse-contact-properties-to-api-options.ts
199
320
  function parseContactPropertyFromApi(contactProperty) {
@@ -213,7 +334,6 @@ function parseContactPropertyToApiOptions(contactProperty) {
213
334
  };
214
335
  return { fallback_value: contactProperty.fallbackValue };
215
336
  }
216
-
217
337
  //#endregion
218
338
  //#region src/contact-properties/contact-properties.ts
219
339
  var ContactProperties = class {
@@ -285,7 +405,6 @@ var ContactProperties = class {
285
405
  return await this.resend.delete(`/contact-properties/${id}`);
286
406
  }
287
407
  };
288
-
289
408
  //#endregion
290
409
  //#region src/contacts/segments/contact-segments.ts
291
410
  var ContactSegments = class {
@@ -334,7 +453,6 @@ var ContactSegments = class {
334
453
  return this.resend.delete(`/contacts/${identifier}/segments/${options.segmentId}`);
335
454
  }
336
455
  };
337
-
338
456
  //#endregion
339
457
  //#region src/contacts/topics/contact-topics.ts
340
458
  var ContactTopics = class {
@@ -370,7 +488,6 @@ var ContactTopics = class {
370
488
  return this.resend.get(url);
371
489
  }
372
490
  };
373
-
374
491
  //#endregion
375
492
  //#region src/contacts/contacts.ts
376
493
  var Contacts = class {
@@ -471,7 +588,6 @@ var Contacts = class {
471
588
  return this.resend.delete(`/audiences/${payload.audienceId}/contacts/${payload?.email ? payload?.email : payload?.id}`);
472
589
  }
473
590
  };
474
-
475
591
  //#endregion
476
592
  //#region src/common/utils/parse-domain-to-api-options.ts
477
593
  function parseDomainToApiOptions(domain) {
@@ -485,7 +601,6 @@ function parseDomainToApiOptions(domain) {
485
601
  tls: domain.tls
486
602
  };
487
603
  }
488
-
489
604
  //#endregion
490
605
  //#region src/domains/domains.ts
491
606
  var Domains = class {
@@ -518,7 +633,6 @@ var Domains = class {
518
633
  return await this.resend.post(`/domains/${id}/verify`);
519
634
  }
520
635
  };
521
-
522
636
  //#endregion
523
637
  //#region src/emails/attachments/attachments.ts
524
638
  var Attachments$1 = class {
@@ -536,7 +650,6 @@ var Attachments$1 = class {
536
650
  return await this.resend.get(url);
537
651
  }
538
652
  };
539
-
540
653
  //#endregion
541
654
  //#region src/emails/receiving/attachments/attachments.ts
542
655
  var Attachments = class {
@@ -554,7 +667,6 @@ var Attachments = class {
554
667
  return await this.resend.get(url);
555
668
  }
556
669
  };
557
-
558
670
  //#endregion
559
671
  //#region src/emails/receiving/receiving.ts
560
672
  var Receiving = class {
@@ -672,7 +784,6 @@ var Receiving = class {
672
784
  });
673
785
  }
674
786
  };
675
-
676
787
  //#endregion
677
788
  //#region src/emails/emails.ts
678
789
  var Emails = class {
@@ -703,7 +814,33 @@ var Emails = class {
703
814
  return await this.resend.post(`/emails/${id}/cancel`);
704
815
  }
705
816
  };
706
-
817
+ //#endregion
818
+ //#region src/events/events.ts
819
+ var Events = class {
820
+ constructor(resend) {
821
+ this.resend = resend;
822
+ }
823
+ async send(payload) {
824
+ return await this.resend.post("/events/send", parseEventToApiOptions(payload));
825
+ }
826
+ async create(payload) {
827
+ return await this.resend.post("/events", payload);
828
+ }
829
+ async get(identifier) {
830
+ return await this.resend.get(`/events/${encodeURIComponent(identifier)}`);
831
+ }
832
+ async list(options = {}) {
833
+ const queryString = buildPaginationQuery(options);
834
+ const url = queryString ? `/events?${queryString}` : "/events";
835
+ return await this.resend.get(url);
836
+ }
837
+ async update(identifier, payload) {
838
+ return await this.resend.patch(`/events/${encodeURIComponent(identifier)}`, payload);
839
+ }
840
+ async remove(identifier) {
841
+ return await this.resend.delete(`/events/${encodeURIComponent(identifier)}`);
842
+ }
843
+ };
707
844
  //#endregion
708
845
  //#region src/logs/logs.ts
709
846
  var Logs = class {
@@ -719,7 +856,6 @@ var Logs = class {
719
856
  return await this.resend.get(`/logs/${id}`);
720
857
  }
721
858
  };
722
-
723
859
  //#endregion
724
860
  //#region src/segments/segments.ts
725
861
  var Segments = class {
@@ -741,7 +877,6 @@ var Segments = class {
741
877
  return await this.resend.delete(`/segments/${id}`);
742
878
  }
743
879
  };
744
-
745
880
  //#endregion
746
881
  //#region src/common/utils/get-pagination-query-properties.ts
747
882
  function getPaginationQueryProperties(options = {}) {
@@ -751,7 +886,6 @@ function getPaginationQueryProperties(options = {}) {
751
886
  if (options.limit) query.set("limit", options.limit.toString());
752
887
  return query.size > 0 ? `?${query.toString()}` : "";
753
888
  }
754
-
755
889
  //#endregion
756
890
  //#region src/common/utils/parse-template-to-api-options.ts
757
891
  function parseVariables(variables) {
@@ -773,7 +907,6 @@ function parseTemplateToApiOptions(template) {
773
907
  variables: parseVariables(template.variables)
774
908
  };
775
909
  }
776
-
777
910
  //#endregion
778
911
  //#region src/templates/chainable-template-result.ts
779
912
  var ChainableTemplateResult = class {
@@ -794,7 +927,6 @@ var ChainableTemplateResult = class {
794
927
  return this.publishFn(data.id);
795
928
  }
796
929
  };
797
-
798
930
  //#endregion
799
931
  //#region src/templates/templates.ts
800
932
  var Templates = class {
@@ -835,7 +967,6 @@ var Templates = class {
835
967
  return await this.resend.patch(`/templates/${identifier}`, parseTemplateToApiOptions(payload));
836
968
  }
837
969
  };
838
-
839
970
  //#endregion
840
971
  //#region src/topics/topics.ts
841
972
  var Topics = class {
@@ -889,7 +1020,6 @@ var Topics = class {
889
1020
  return await this.resend.delete(`/topics/${id}`);
890
1021
  }
891
1022
  };
892
-
893
1023
  //#endregion
894
1024
  //#region src/webhooks/webhooks.ts
895
1025
  var Webhooks = class {
@@ -921,7 +1051,6 @@ var Webhooks = class {
921
1051
  });
922
1052
  }
923
1053
  };
924
-
925
1054
  //#endregion
926
1055
  //#region src/resend.ts
927
1056
  const defaultBaseUrl = "https://api.resend.com";
@@ -931,19 +1060,21 @@ const userAgent = typeof process !== "undefined" && process.env ? process.env.RE
931
1060
  var Resend = class {
932
1061
  constructor(key) {
933
1062
  this.key = key;
934
- this.apiKeys = new ApiKeys(this);
935
1063
  this.segments = new Segments(this);
1064
+ this.apiKeys = new ApiKeys(this);
936
1065
  this.audiences = this.segments;
1066
+ this.automations = new Automations(this);
937
1067
  this.batch = new Batch(this);
938
1068
  this.broadcasts = new Broadcasts(this);
939
- this.contacts = new Contacts(this);
940
1069
  this.contactProperties = new ContactProperties(this);
1070
+ this.contacts = new Contacts(this);
941
1071
  this.domains = new Domains(this);
942
1072
  this.emails = new Emails(this);
1073
+ this.events = new Events(this);
943
1074
  this.logs = new Logs(this);
944
- this.webhooks = new Webhooks(this);
945
1075
  this.templates = new Templates(this);
946
1076
  this.topics = new Topics(this);
1077
+ this.webhooks = new Webhooks(this);
947
1078
  if (!key) {
948
1079
  if (typeof process !== "undefined" && process.env) this.key = process.env.RESEND_API_KEY;
949
1080
  if (!this.key) throw new Error("Missing API key. Pass it to the constructor `new Resend(\"re_123\")`");
@@ -1063,6 +1194,5 @@ var Resend = class {
1063
1194
  return this.fetchRequest(path, requestOptions);
1064
1195
  }
1065
1196
  };
1066
-
1067
1197
  //#endregion
1068
- exports.Resend = Resend;
1198
+ exports.Resend = Resend;