@upyo/resend 0.3.3 → 0.3.4

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
@@ -51,13 +51,16 @@ var ResendHttpClient = class {
51
51
  *
52
52
  * @param messageData The JSON data to send to Resend.
53
53
  * @param signal Optional AbortSignal for cancellation.
54
+ * @param idempotencyKey Optional idempotency key for request deduplication.
54
55
  * @returns Promise that resolves to the Resend response.
55
56
  */
56
- sendMessage(messageData, signal) {
57
+ sendMessage(messageData, signal, idempotencyKey) {
57
58
  const url = `${this.config.baseUrl}/emails`;
59
+ const headers = { "Content-Type": "application/json" };
60
+ if (idempotencyKey) headers["Idempotency-Key"] = idempotencyKey;
58
61
  return this.makeRequest(url, {
59
62
  method: "POST",
60
- headers: { "Content-Type": "application/json" },
63
+ headers,
61
64
  body: JSON.stringify(messageData),
62
65
  signal
63
66
  });
@@ -67,13 +70,16 @@ var ResendHttpClient = class {
67
70
  *
68
71
  * @param messagesData Array of message data objects to send.
69
72
  * @param signal Optional AbortSignal for cancellation.
73
+ * @param idempotencyKey Optional idempotency key for request deduplication.
70
74
  * @returns Promise that resolves to the Resend batch response.
71
75
  */
72
- sendBatch(messagesData, signal) {
76
+ sendBatch(messagesData, signal, idempotencyKey) {
73
77
  const url = `${this.config.baseUrl}/emails/batch`;
78
+ const headers = { "Content-Type": "application/json" };
79
+ if (idempotencyKey) headers["Idempotency-Key"] = idempotencyKey;
74
80
  return this.makeRequest(url, {
75
81
  method: "POST",
76
- headers: { "Content-Type": "application/json" },
82
+ headers,
77
83
  body: JSON.stringify(messagesData),
78
84
  signal
79
85
  });
@@ -198,7 +204,6 @@ async function convertMessage(message, _config, options = {}) {
198
204
  headers["X-Priority"] = priorityMap[message.priority];
199
205
  }
200
206
  for (const [key, value] of message.headers.entries()) if (!isStandardHeader(key)) headers[key] = value;
201
- if (options.idempotencyKey) headers["Idempotency-Key"] = options.idempotencyKey;
202
207
  if (Object.keys(headers).length > 0) emailData.headers = headers;
203
208
  if (options.scheduledAt) emailData.scheduled_at = options.scheduledAt.toISOString();
204
209
  return emailData;
@@ -211,19 +216,15 @@ async function convertMessage(message, _config, options = {}) {
211
216
  *
212
217
  * @param messages - Array of Upyo messages to convert
213
218
  * @param config - The resolved Resend configuration
214
- * @param options - Optional conversion options
215
219
  * @returns Array of JSON objects ready for Resend batch API
216
220
  */
217
- async function convertMessagesBatch(messages, _config, options = {}) {
221
+ async function convertMessagesBatch(messages, _config) {
218
222
  if (messages.length > 100) throw new Error("Resend batch API supports maximum 100 emails per request");
219
223
  for (const message of messages) {
220
224
  if (message.attachments.length > 0) throw new Error("Attachments are not supported in Resend batch API");
221
225
  if (message.tags.length > 0) throw new Error("Tags are not supported in Resend batch API");
222
226
  }
223
- const batchData = await Promise.all(messages.map((message, index) => convertMessage(message, _config, {
224
- ...options,
225
- idempotencyKey: options.idempotencyKey ? `${options.idempotencyKey}-${index}` : void 0
226
- })));
227
+ const batchData = await Promise.all(messages.map((message) => convertMessage(message, _config)));
227
228
  return batchData;
228
229
  }
229
230
  /**
@@ -390,9 +391,9 @@ var ResendTransport = class {
390
391
  try {
391
392
  options?.signal?.throwIfAborted();
392
393
  const idempotencyKey = generateIdempotencyKey();
393
- const emailData = await convertMessage(message, this.config, { idempotencyKey });
394
+ const emailData = await convertMessage(message, this.config);
394
395
  options?.signal?.throwIfAborted();
395
- const response = await this.httpClient.sendMessage(emailData, options?.signal);
396
+ const response = await this.httpClient.sendMessage(emailData, options?.signal, idempotencyKey);
396
397
  return {
397
398
  successful: true,
398
399
  messageId: response.id
@@ -506,9 +507,9 @@ var ResendTransport = class {
506
507
  options?.signal?.throwIfAborted();
507
508
  try {
508
509
  const idempotencyKey = generateIdempotencyKey();
509
- const batchData = await convertMessagesBatch(messages, this.config, { idempotencyKey });
510
+ const batchData = await convertMessagesBatch(messages, this.config);
510
511
  options?.signal?.throwIfAborted();
511
- const response = await this.httpClient.sendBatch(batchData, options?.signal);
512
+ const response = await this.httpClient.sendBatch(batchData, options?.signal, idempotencyKey);
512
513
  for (const result of response.data) yield {
513
514
  successful: true,
514
515
  messageId: result.id
package/dist/index.js CHANGED
@@ -50,13 +50,16 @@ var ResendHttpClient = class {
50
50
  *
51
51
  * @param messageData The JSON data to send to Resend.
52
52
  * @param signal Optional AbortSignal for cancellation.
53
+ * @param idempotencyKey Optional idempotency key for request deduplication.
53
54
  * @returns Promise that resolves to the Resend response.
54
55
  */
55
- sendMessage(messageData, signal) {
56
+ sendMessage(messageData, signal, idempotencyKey) {
56
57
  const url = `${this.config.baseUrl}/emails`;
58
+ const headers = { "Content-Type": "application/json" };
59
+ if (idempotencyKey) headers["Idempotency-Key"] = idempotencyKey;
57
60
  return this.makeRequest(url, {
58
61
  method: "POST",
59
- headers: { "Content-Type": "application/json" },
62
+ headers,
60
63
  body: JSON.stringify(messageData),
61
64
  signal
62
65
  });
@@ -66,13 +69,16 @@ var ResendHttpClient = class {
66
69
  *
67
70
  * @param messagesData Array of message data objects to send.
68
71
  * @param signal Optional AbortSignal for cancellation.
72
+ * @param idempotencyKey Optional idempotency key for request deduplication.
69
73
  * @returns Promise that resolves to the Resend batch response.
70
74
  */
71
- sendBatch(messagesData, signal) {
75
+ sendBatch(messagesData, signal, idempotencyKey) {
72
76
  const url = `${this.config.baseUrl}/emails/batch`;
77
+ const headers = { "Content-Type": "application/json" };
78
+ if (idempotencyKey) headers["Idempotency-Key"] = idempotencyKey;
73
79
  return this.makeRequest(url, {
74
80
  method: "POST",
75
- headers: { "Content-Type": "application/json" },
81
+ headers,
76
82
  body: JSON.stringify(messagesData),
77
83
  signal
78
84
  });
@@ -197,7 +203,6 @@ async function convertMessage(message, _config, options = {}) {
197
203
  headers["X-Priority"] = priorityMap[message.priority];
198
204
  }
199
205
  for (const [key, value] of message.headers.entries()) if (!isStandardHeader(key)) headers[key] = value;
200
- if (options.idempotencyKey) headers["Idempotency-Key"] = options.idempotencyKey;
201
206
  if (Object.keys(headers).length > 0) emailData.headers = headers;
202
207
  if (options.scheduledAt) emailData.scheduled_at = options.scheduledAt.toISOString();
203
208
  return emailData;
@@ -210,19 +215,15 @@ async function convertMessage(message, _config, options = {}) {
210
215
  *
211
216
  * @param messages - Array of Upyo messages to convert
212
217
  * @param config - The resolved Resend configuration
213
- * @param options - Optional conversion options
214
218
  * @returns Array of JSON objects ready for Resend batch API
215
219
  */
216
- async function convertMessagesBatch(messages, _config, options = {}) {
220
+ async function convertMessagesBatch(messages, _config) {
217
221
  if (messages.length > 100) throw new Error("Resend batch API supports maximum 100 emails per request");
218
222
  for (const message of messages) {
219
223
  if (message.attachments.length > 0) throw new Error("Attachments are not supported in Resend batch API");
220
224
  if (message.tags.length > 0) throw new Error("Tags are not supported in Resend batch API");
221
225
  }
222
- const batchData = await Promise.all(messages.map((message, index) => convertMessage(message, _config, {
223
- ...options,
224
- idempotencyKey: options.idempotencyKey ? `${options.idempotencyKey}-${index}` : void 0
225
- })));
226
+ const batchData = await Promise.all(messages.map((message) => convertMessage(message, _config)));
226
227
  return batchData;
227
228
  }
228
229
  /**
@@ -389,9 +390,9 @@ var ResendTransport = class {
389
390
  try {
390
391
  options?.signal?.throwIfAborted();
391
392
  const idempotencyKey = generateIdempotencyKey();
392
- const emailData = await convertMessage(message, this.config, { idempotencyKey });
393
+ const emailData = await convertMessage(message, this.config);
393
394
  options?.signal?.throwIfAborted();
394
- const response = await this.httpClient.sendMessage(emailData, options?.signal);
395
+ const response = await this.httpClient.sendMessage(emailData, options?.signal, idempotencyKey);
395
396
  return {
396
397
  successful: true,
397
398
  messageId: response.id
@@ -505,9 +506,9 @@ var ResendTransport = class {
505
506
  options?.signal?.throwIfAborted();
506
507
  try {
507
508
  const idempotencyKey = generateIdempotencyKey();
508
- const batchData = await convertMessagesBatch(messages, this.config, { idempotencyKey });
509
+ const batchData = await convertMessagesBatch(messages, this.config);
509
510
  options?.signal?.throwIfAborted();
510
- const response = await this.httpClient.sendBatch(batchData, options?.signal);
511
+ const response = await this.httpClient.sendBatch(batchData, options?.signal, idempotencyKey);
511
512
  for (const result of response.data) yield {
512
513
  successful: true,
513
514
  messageId: result.id
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@upyo/resend",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Resend transport for Upyo email library",
5
5
  "keywords": [
6
6
  "email",
@@ -53,7 +53,7 @@
53
53
  },
54
54
  "sideEffects": false,
55
55
  "peerDependencies": {
56
- "@upyo/core": "0.3.3"
56
+ "@upyo/core": "0.3.4"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@dotenvx/dotenvx": "^1.47.3",