@upyo/plunk 0.5.0 → 0.5.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
@@ -72,7 +72,7 @@ See the [Plunk docs] for more information about configuration options.
72
72
  ### Available Options
73
73
 
74
74
  - `apiKey`: Your Plunk API key
75
- - `baseUrl`: API base URL (default: `https://api.useplunk.com`)
75
+ - `baseUrl`: API base URL (default: `https://next-api.useplunk.com`)
76
76
  - `timeout`: Request timeout in milliseconds (default: `30000`)
77
77
  - `retries`: Number of retry attempts (default: `3`)
78
78
  - `validateSsl`: Whether to validate SSL certificates (default: `true`)
package/dist/index.cjs CHANGED
@@ -38,7 +38,7 @@ const __upyo_core = __toESM(require("@upyo/core"));
38
38
  function createPlunkConfig(config) {
39
39
  return {
40
40
  apiKey: config.apiKey,
41
- baseUrl: config.baseUrl ?? "https://api.useplunk.com",
41
+ baseUrl: config.baseUrl ?? "https://next-api.useplunk.com",
42
42
  timeout: config.timeout ?? 3e4,
43
43
  retries: config.retries ?? 3,
44
44
  validateSsl: config.validateSsl ?? true,
@@ -186,7 +186,13 @@ var PlunkHttpClient = class {
186
186
  if (typeof data !== "object" || data === null) throw new Error("Invalid response format: expected object");
187
187
  if (typeof data.success !== "boolean") throw new Error("Invalid response format: missing success field");
188
188
  if (!data.success) throw new Error(data.message ?? "Send operation failed without error details");
189
- return data;
189
+ const responseData = "data" in data ? data.data : data;
190
+ if (typeof responseData !== "object" || responseData === null) throw new Error("Invalid response format: missing data field");
191
+ return {
192
+ success: true,
193
+ emails: responseData.emails,
194
+ timestamp: responseData.timestamp
195
+ };
190
196
  } catch (error) {
191
197
  if (error instanceof SyntaxError) throw new Error("Invalid JSON response from Plunk API");
192
198
  throw error;
@@ -256,8 +262,7 @@ async function convertMessage(message, _config) {
256
262
  const plunkEmail = {
257
263
  to,
258
264
  subject: message.subject,
259
- body,
260
- subscribed: false
265
+ body
261
266
  };
262
267
  if (senderName) plunkEmail.name = senderName;
263
268
  if (senderEmail) plunkEmail.from = senderEmail;
@@ -279,7 +284,7 @@ async function convertAttachment(attachment) {
279
284
  return {
280
285
  filename: attachment.filename,
281
286
  content: base64Content,
282
- type: attachment.contentType
287
+ contentType: attachment.contentType
283
288
  };
284
289
  } catch (error) {
285
290
  console.warn(`Failed to convert attachment ${attachment.filename}:`, error);
@@ -328,7 +333,7 @@ function arrayBufferToBase64(buffer) {
328
333
  *
329
334
  * const transport = new PlunkTransport({
330
335
  * apiKey: 'your-plunk-api-key',
331
- * baseUrl: 'https://api.useplunk.com', // or self-hosted URL
336
+ * baseUrl: 'https://next-api.useplunk.com', // or self-hosted URL
332
337
  * timeout: 30000,
333
338
  * retries: 3
334
339
  * });
@@ -475,19 +480,16 @@ var PlunkTransport = class {
475
480
  /**
476
481
  * Extracts or generates a message ID from the Plunk response.
477
482
  *
478
- * Plunk returns email details in the response, so we can use the contact ID
479
- * and timestamp to create a meaningful message ID.
483
+ * Plunk returns its email record ID in the response. This ID can be used to
484
+ * correlate the send operation with webhook events.
480
485
  *
481
486
  * @param response The Plunk API response.
482
487
  * @param message The original message for fallback ID generation.
483
488
  * @returns A message ID string.
484
489
  */
485
490
  extractMessageId(response, message) {
486
- if (response.emails && response.emails.length > 0) {
487
- const contactId = response.emails[0].contact?.id;
488
- const timestamp$1 = response.timestamp;
489
- if (contactId && timestamp$1) return `plunk-${contactId}-${new Date(timestamp$1).getTime()}`;
490
- }
491
+ const emailId = response.emails?.[0]?.email;
492
+ if (emailId) return emailId;
491
493
  const timestamp = Date.now();
492
494
  const recipientHash = message.recipients[0]?.address.split("@")[0].substring(0, 8) ?? "unknown";
493
495
  const random = Math.random().toString(36).substring(2, 8);
package/dist/index.d.cts CHANGED
@@ -13,7 +13,7 @@ import { Message, Receipt, Transport, TransportOptions } from "@upyo/core";
13
13
  * ```typescript
14
14
  * const config: PlunkConfig = {
15
15
  * apiKey: 'your-api-key',
16
- * baseUrl: 'https://api.useplunk.com', // or self-hosted URL
16
+ * baseUrl: 'https://next-api.useplunk.com', // or self-hosted URL
17
17
  * timeout: 30000,
18
18
  * retries: 3
19
19
  * };
@@ -30,11 +30,11 @@ interface PlunkConfig {
30
30
  /**
31
31
  * Base URL for the Plunk API.
32
32
  *
33
- * For Plunk's hosted service, use "https://api.useplunk.com" (default).
33
+ * For Plunk's hosted service, use "https://next-api.useplunk.com" (default).
34
34
  * For self-hosted instances, use your domain with "/api" path
35
35
  * (e.g., "https://plunk.example.com/api").
36
36
  *
37
- * @default "https://api.useplunk.com"
37
+ * @default "https://next-api.useplunk.com"
38
38
  */
39
39
  readonly baseUrl?: string;
40
40
  /**
@@ -93,7 +93,7 @@ type ResolvedPlunkConfig = Required<PlunkConfig>;
93
93
  *
94
94
  * const transport = new PlunkTransport({
95
95
  * apiKey: 'your-plunk-api-key',
96
- * baseUrl: 'https://api.useplunk.com', // or self-hosted URL
96
+ * baseUrl: 'https://next-api.useplunk.com', // or self-hosted URL
97
97
  * timeout: 30000,
98
98
  * retries: 3
99
99
  * });
@@ -209,8 +209,8 @@ declare class PlunkTransport implements Transport<"plunk"> {
209
209
  /**
210
210
  * Extracts or generates a message ID from the Plunk response.
211
211
  *
212
- * Plunk returns email details in the response, so we can use the contact ID
213
- * and timestamp to create a meaningful message ID.
212
+ * Plunk returns its email record ID in the response. This ID can be used to
213
+ * correlate the send operation with webhook events.
214
214
  *
215
215
  * @param response The Plunk API response.
216
216
  * @param message The original message for fallback ID generation.
@@ -236,6 +236,9 @@ interface PlunkResponse {
236
236
  readonly id: string;
237
237
  readonly email: string;
238
238
  };
239
+ /**
240
+ * Plunk email record ID used to correlate webhook events.
241
+ */
239
242
  readonly email: string;
240
243
  }[];
241
244
  /**
package/dist/index.d.ts CHANGED
@@ -13,7 +13,7 @@ import { Message, Receipt, Transport, TransportOptions } from "@upyo/core";
13
13
  * ```typescript
14
14
  * const config: PlunkConfig = {
15
15
  * apiKey: 'your-api-key',
16
- * baseUrl: 'https://api.useplunk.com', // or self-hosted URL
16
+ * baseUrl: 'https://next-api.useplunk.com', // or self-hosted URL
17
17
  * timeout: 30000,
18
18
  * retries: 3
19
19
  * };
@@ -30,11 +30,11 @@ interface PlunkConfig {
30
30
  /**
31
31
  * Base URL for the Plunk API.
32
32
  *
33
- * For Plunk's hosted service, use "https://api.useplunk.com" (default).
33
+ * For Plunk's hosted service, use "https://next-api.useplunk.com" (default).
34
34
  * For self-hosted instances, use your domain with "/api" path
35
35
  * (e.g., "https://plunk.example.com/api").
36
36
  *
37
- * @default "https://api.useplunk.com"
37
+ * @default "https://next-api.useplunk.com"
38
38
  */
39
39
  readonly baseUrl?: string;
40
40
  /**
@@ -93,7 +93,7 @@ type ResolvedPlunkConfig = Required<PlunkConfig>;
93
93
  *
94
94
  * const transport = new PlunkTransport({
95
95
  * apiKey: 'your-plunk-api-key',
96
- * baseUrl: 'https://api.useplunk.com', // or self-hosted URL
96
+ * baseUrl: 'https://next-api.useplunk.com', // or self-hosted URL
97
97
  * timeout: 30000,
98
98
  * retries: 3
99
99
  * });
@@ -209,8 +209,8 @@ declare class PlunkTransport implements Transport<"plunk"> {
209
209
  /**
210
210
  * Extracts or generates a message ID from the Plunk response.
211
211
  *
212
- * Plunk returns email details in the response, so we can use the contact ID
213
- * and timestamp to create a meaningful message ID.
212
+ * Plunk returns its email record ID in the response. This ID can be used to
213
+ * correlate the send operation with webhook events.
214
214
  *
215
215
  * @param response The Plunk API response.
216
216
  * @param message The original message for fallback ID generation.
@@ -236,6 +236,9 @@ interface PlunkResponse {
236
236
  readonly id: string;
237
237
  readonly email: string;
238
238
  };
239
+ /**
240
+ * Plunk email record ID used to correlate webhook events.
241
+ */
239
242
  readonly email: string;
240
243
  }[];
241
244
  /**
package/dist/index.js CHANGED
@@ -15,7 +15,7 @@ import { combineSignals, createFailedReceipt, parseRetryAfter } from "@upyo/core
15
15
  function createPlunkConfig(config) {
16
16
  return {
17
17
  apiKey: config.apiKey,
18
- baseUrl: config.baseUrl ?? "https://api.useplunk.com",
18
+ baseUrl: config.baseUrl ?? "https://next-api.useplunk.com",
19
19
  timeout: config.timeout ?? 3e4,
20
20
  retries: config.retries ?? 3,
21
21
  validateSsl: config.validateSsl ?? true,
@@ -163,7 +163,13 @@ var PlunkHttpClient = class {
163
163
  if (typeof data !== "object" || data === null) throw new Error("Invalid response format: expected object");
164
164
  if (typeof data.success !== "boolean") throw new Error("Invalid response format: missing success field");
165
165
  if (!data.success) throw new Error(data.message ?? "Send operation failed without error details");
166
- return data;
166
+ const responseData = "data" in data ? data.data : data;
167
+ if (typeof responseData !== "object" || responseData === null) throw new Error("Invalid response format: missing data field");
168
+ return {
169
+ success: true,
170
+ emails: responseData.emails,
171
+ timestamp: responseData.timestamp
172
+ };
167
173
  } catch (error) {
168
174
  if (error instanceof SyntaxError) throw new Error("Invalid JSON response from Plunk API");
169
175
  throw error;
@@ -233,8 +239,7 @@ async function convertMessage(message, _config) {
233
239
  const plunkEmail = {
234
240
  to,
235
241
  subject: message.subject,
236
- body,
237
- subscribed: false
242
+ body
238
243
  };
239
244
  if (senderName) plunkEmail.name = senderName;
240
245
  if (senderEmail) plunkEmail.from = senderEmail;
@@ -256,7 +261,7 @@ async function convertAttachment(attachment) {
256
261
  return {
257
262
  filename: attachment.filename,
258
263
  content: base64Content,
259
- type: attachment.contentType
264
+ contentType: attachment.contentType
260
265
  };
261
266
  } catch (error) {
262
267
  console.warn(`Failed to convert attachment ${attachment.filename}:`, error);
@@ -305,7 +310,7 @@ function arrayBufferToBase64(buffer) {
305
310
  *
306
311
  * const transport = new PlunkTransport({
307
312
  * apiKey: 'your-plunk-api-key',
308
- * baseUrl: 'https://api.useplunk.com', // or self-hosted URL
313
+ * baseUrl: 'https://next-api.useplunk.com', // or self-hosted URL
309
314
  * timeout: 30000,
310
315
  * retries: 3
311
316
  * });
@@ -452,19 +457,16 @@ var PlunkTransport = class {
452
457
  /**
453
458
  * Extracts or generates a message ID from the Plunk response.
454
459
  *
455
- * Plunk returns email details in the response, so we can use the contact ID
456
- * and timestamp to create a meaningful message ID.
460
+ * Plunk returns its email record ID in the response. This ID can be used to
461
+ * correlate the send operation with webhook events.
457
462
  *
458
463
  * @param response The Plunk API response.
459
464
  * @param message The original message for fallback ID generation.
460
465
  * @returns A message ID string.
461
466
  */
462
467
  extractMessageId(response, message) {
463
- if (response.emails && response.emails.length > 0) {
464
- const contactId = response.emails[0].contact?.id;
465
- const timestamp$1 = response.timestamp;
466
- if (contactId && timestamp$1) return `plunk-${contactId}-${new Date(timestamp$1).getTime()}`;
467
- }
468
+ const emailId = response.emails?.[0]?.email;
469
+ if (emailId) return emailId;
468
470
  const timestamp = Date.now();
469
471
  const recipientHash = message.recipients[0]?.address.split("@")[0].substring(0, 8) ?? "unknown";
470
472
  const random = Math.random().toString(36).substring(2, 8);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@upyo/plunk",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Plunk 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.5.0"
56
+ "@upyo/core": "0.5.1"
57
57
  },
58
58
  "devDependencies": {
59
59
  "tsdown": "^0.12.7",