@upyo/plunk 0.4.0 → 0.4.1-dev.257

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
@@ -14,7 +14,7 @@
14
14
  function createPlunkConfig(config) {
15
15
  return {
16
16
  apiKey: config.apiKey,
17
- baseUrl: config.baseUrl ?? "https://api.useplunk.com",
17
+ baseUrl: config.baseUrl ?? "https://next-api.useplunk.com",
18
18
  timeout: config.timeout ?? 3e4,
19
19
  retries: config.retries ?? 3,
20
20
  validateSsl: config.validateSsl ?? true,
@@ -117,7 +117,13 @@ var PlunkHttpClient = class {
117
117
  if (typeof data !== "object" || data === null) throw new Error("Invalid response format: expected object");
118
118
  if (typeof data.success !== "boolean") throw new Error("Invalid response format: missing success field");
119
119
  if (!data.success) throw new Error(data.message ?? "Send operation failed without error details");
120
- return data;
120
+ const responseData = "data" in data ? data.data : data;
121
+ if (typeof responseData !== "object" || responseData === null) throw new Error("Invalid response format: missing data field");
122
+ return {
123
+ success: true,
124
+ emails: responseData.emails,
125
+ timestamp: responseData.timestamp
126
+ };
121
127
  } catch (error) {
122
128
  if (error instanceof SyntaxError) throw new Error("Invalid JSON response from Plunk API");
123
129
  throw error;
@@ -191,8 +197,7 @@ async function convertMessage(message, _config) {
191
197
  const plunkEmail = {
192
198
  to,
193
199
  subject: message.subject,
194
- body,
195
- subscribed: false
200
+ body
196
201
  };
197
202
  if (senderName) plunkEmail.name = senderName;
198
203
  if (senderEmail) plunkEmail.from = senderEmail;
@@ -214,7 +219,7 @@ async function convertAttachment(attachment) {
214
219
  return {
215
220
  filename: attachment.filename,
216
221
  content: base64Content,
217
- type: attachment.contentType
222
+ contentType: attachment.contentType
218
223
  };
219
224
  } catch (error) {
220
225
  console.warn(`Failed to convert attachment ${attachment.filename}:`, error);
@@ -263,7 +268,7 @@ function arrayBufferToBase64(buffer) {
263
268
  *
264
269
  * const transport = new PlunkTransport({
265
270
  * apiKey: 'your-plunk-api-key',
266
- * baseUrl: 'https://api.useplunk.com', // or self-hosted URL
271
+ * baseUrl: 'https://next-api.useplunk.com', // or self-hosted URL
267
272
  * timeout: 30000,
268
273
  * retries: 3
269
274
  * });
@@ -410,19 +415,16 @@ var PlunkTransport = class {
410
415
  /**
411
416
  * Extracts or generates a message ID from the Plunk response.
412
417
  *
413
- * Plunk returns email details in the response, so we can use the contact ID
414
- * and timestamp to create a meaningful message ID.
418
+ * Plunk returns its email record ID in the response. This ID can be used to
419
+ * correlate the send operation with webhook events.
415
420
  *
416
421
  * @param response The Plunk API response.
417
422
  * @param message The original message for fallback ID generation.
418
423
  * @returns A message ID string.
419
424
  */
420
425
  extractMessageId(response, message) {
421
- if (response.emails && response.emails.length > 0) {
422
- const contactId = response.emails[0].contact?.id;
423
- const timestamp$1 = response.timestamp;
424
- if (contactId && timestamp$1) return `plunk-${contactId}-${new Date(timestamp$1).getTime()}`;
425
- }
426
+ const emailId = response.emails?.[0]?.email;
427
+ if (emailId) return emailId;
426
428
  const timestamp = Date.now();
427
429
  const recipientHash = message.recipients[0]?.address.split("@")[0].substring(0, 8) ?? "unknown";
428
430
  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
  * });
@@ -208,8 +208,8 @@ declare class PlunkTransport implements Transport {
208
208
  /**
209
209
  * Extracts or generates a message ID from the Plunk response.
210
210
  *
211
- * Plunk returns email details in the response, so we can use the contact ID
212
- * and timestamp to create a meaningful message ID.
211
+ * Plunk returns its email record ID in the response. This ID can be used to
212
+ * correlate the send operation with webhook events.
213
213
  *
214
214
  * @param response The Plunk API response.
215
215
  * @param message The original message for fallback ID generation.
@@ -235,6 +235,9 @@ interface PlunkResponse {
235
235
  readonly id: string;
236
236
  readonly email: string;
237
237
  };
238
+ /**
239
+ * Plunk email record ID used to correlate webhook events.
240
+ */
238
241
  readonly email: string;
239
242
  }[];
240
243
  /**
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
  * });
@@ -208,8 +208,8 @@ declare class PlunkTransport implements Transport {
208
208
  /**
209
209
  * Extracts or generates a message ID from the Plunk response.
210
210
  *
211
- * Plunk returns email details in the response, so we can use the contact ID
212
- * and timestamp to create a meaningful message ID.
211
+ * Plunk returns its email record ID in the response. This ID can be used to
212
+ * correlate the send operation with webhook events.
213
213
  *
214
214
  * @param response The Plunk API response.
215
215
  * @param message The original message for fallback ID generation.
@@ -235,6 +235,9 @@ interface PlunkResponse {
235
235
  readonly id: string;
236
236
  readonly email: string;
237
237
  };
238
+ /**
239
+ * Plunk email record ID used to correlate webhook events.
240
+ */
238
241
  readonly email: string;
239
242
  }[];
240
243
  /**
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@
13
13
  function createPlunkConfig(config) {
14
14
  return {
15
15
  apiKey: config.apiKey,
16
- baseUrl: config.baseUrl ?? "https://api.useplunk.com",
16
+ baseUrl: config.baseUrl ?? "https://next-api.useplunk.com",
17
17
  timeout: config.timeout ?? 3e4,
18
18
  retries: config.retries ?? 3,
19
19
  validateSsl: config.validateSsl ?? true,
@@ -116,7 +116,13 @@ var PlunkHttpClient = class {
116
116
  if (typeof data !== "object" || data === null) throw new Error("Invalid response format: expected object");
117
117
  if (typeof data.success !== "boolean") throw new Error("Invalid response format: missing success field");
118
118
  if (!data.success) throw new Error(data.message ?? "Send operation failed without error details");
119
- return data;
119
+ const responseData = "data" in data ? data.data : data;
120
+ if (typeof responseData !== "object" || responseData === null) throw new Error("Invalid response format: missing data field");
121
+ return {
122
+ success: true,
123
+ emails: responseData.emails,
124
+ timestamp: responseData.timestamp
125
+ };
120
126
  } catch (error) {
121
127
  if (error instanceof SyntaxError) throw new Error("Invalid JSON response from Plunk API");
122
128
  throw error;
@@ -190,8 +196,7 @@ async function convertMessage(message, _config) {
190
196
  const plunkEmail = {
191
197
  to,
192
198
  subject: message.subject,
193
- body,
194
- subscribed: false
199
+ body
195
200
  };
196
201
  if (senderName) plunkEmail.name = senderName;
197
202
  if (senderEmail) plunkEmail.from = senderEmail;
@@ -213,7 +218,7 @@ async function convertAttachment(attachment) {
213
218
  return {
214
219
  filename: attachment.filename,
215
220
  content: base64Content,
216
- type: attachment.contentType
221
+ contentType: attachment.contentType
217
222
  };
218
223
  } catch (error) {
219
224
  console.warn(`Failed to convert attachment ${attachment.filename}:`, error);
@@ -262,7 +267,7 @@ function arrayBufferToBase64(buffer) {
262
267
  *
263
268
  * const transport = new PlunkTransport({
264
269
  * apiKey: 'your-plunk-api-key',
265
- * baseUrl: 'https://api.useplunk.com', // or self-hosted URL
270
+ * baseUrl: 'https://next-api.useplunk.com', // or self-hosted URL
266
271
  * timeout: 30000,
267
272
  * retries: 3
268
273
  * });
@@ -409,19 +414,16 @@ var PlunkTransport = class {
409
414
  /**
410
415
  * Extracts or generates a message ID from the Plunk response.
411
416
  *
412
- * Plunk returns email details in the response, so we can use the contact ID
413
- * and timestamp to create a meaningful message ID.
417
+ * Plunk returns its email record ID in the response. This ID can be used to
418
+ * correlate the send operation with webhook events.
414
419
  *
415
420
  * @param response The Plunk API response.
416
421
  * @param message The original message for fallback ID generation.
417
422
  * @returns A message ID string.
418
423
  */
419
424
  extractMessageId(response, message) {
420
- if (response.emails && response.emails.length > 0) {
421
- const contactId = response.emails[0].contact?.id;
422
- const timestamp$1 = response.timestamp;
423
- if (contactId && timestamp$1) return `plunk-${contactId}-${new Date(timestamp$1).getTime()}`;
424
- }
425
+ const emailId = response.emails?.[0]?.email;
426
+ if (emailId) return emailId;
425
427
  const timestamp = Date.now();
426
428
  const recipientHash = message.recipients[0]?.address.split("@")[0].substring(0, 8) ?? "unknown";
427
429
  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.4.0",
3
+ "version": "0.4.1-dev.257",
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.4.0"
56
+ "@upyo/core": "0.4.1-dev.257+e25d7072"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@dotenvx/dotenvx": "^1.47.3",