@upyo/sendgrid 0.1.0-dev.13 → 0.1.0-dev.17

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
@@ -54,7 +54,11 @@ const transport = new SendGridTransport({
54
54
  });
55
55
 
56
56
  const receipt = await transport.send(message);
57
- console.log("Email sent:", receipt.successful);
57
+ if (receipt.successful) {
58
+ console.log("Message sent with ID:", receipt.messageId);
59
+ } else {
60
+ console.error("Send failed:", receipt.errorMessages.join(", "));
61
+ }
58
62
  ~~~~
59
63
 
60
64
 
package/dist/index.cjs CHANGED
@@ -5,20 +5,11 @@
5
5
  *
6
6
  * This function takes a partial SendGrid configuration and returns a complete
7
7
  * configuration with all optional fields filled with sensible defaults.
8
+ * It is used internally by the SendGrid transport.
8
9
  *
9
10
  * @param config - The SendGrid configuration with optional fields
10
11
  * @returns A resolved configuration with all defaults applied
11
- *
12
- * @example
13
- * ```typescript
14
- * const resolved = createSendGridConfig({
15
- * apiKey: 'your-api-key'
16
- * });
17
- *
18
- * // resolved.baseUrl will be 'https://api.sendgrid.com/v3' (default)
19
- * // resolved.timeout will be 30000 (default)
20
- * // resolved.retries will be 3 (default)
21
- * ```
12
+ * @internal
22
13
  */
23
14
  function createSendGridConfig(config) {
24
15
  return {
@@ -313,10 +304,17 @@ function isStandardHeader(headerName) {
313
304
  * });
314
305
  *
315
306
  * const receipt = await transport.send(message);
316
- * console.log('Message sent:', receipt.messageId);
307
+ * if (receipt.successful) {
308
+ * console.log('Message sent with ID:', receipt.messageId);
309
+ * } else {
310
+ * console.error('Send failed:', receipt.errorMessages.join(', '));
311
+ * }
317
312
  * ```
318
313
  */
319
314
  var SendGridTransport = class {
315
+ /**
316
+ * The resolved SendGrid configuration used by this transport.
317
+ */
320
318
  config;
321
319
  httpClient;
322
320
  /**
@@ -369,16 +367,14 @@ var SendGridTransport = class {
369
367
  const response = await this.httpClient.sendMessage(mailData, options?.signal);
370
368
  const messageId = this.extractMessageId(response);
371
369
  return {
372
- messageId,
373
- errorMessages: [],
374
- successful: true
370
+ successful: true,
371
+ messageId
375
372
  };
376
373
  } catch (error) {
377
374
  const errorMessage = error instanceof Error ? error.message : String(error);
378
375
  return {
379
- messageId: "",
380
- errorMessages: [errorMessage],
381
- successful: false
376
+ successful: false,
377
+ errorMessages: [errorMessage]
382
378
  };
383
379
  }
384
380
  }
@@ -466,5 +462,4 @@ var SendGridTransport = class {
466
462
 
467
463
  //#endregion
468
464
  exports.SendGridApiError = SendGridApiError;
469
- exports.SendGridTransport = SendGridTransport;
470
- exports.createSendGridConfig = createSendGridConfig;
465
+ exports.SendGridTransport = SendGridTransport;
package/dist/index.d.cts CHANGED
@@ -91,102 +91,12 @@ type ResolvedSendGridConfig = Required<SendGridConfig>;
91
91
  *
92
92
  * This function takes a partial SendGrid configuration and returns a complete
93
93
  * configuration with all optional fields filled with sensible defaults.
94
+ * It is used internally by the SendGrid transport.
94
95
  *
95
96
  * @param config - The SendGrid configuration with optional fields
96
97
  * @returns A resolved configuration with all defaults applied
97
- *
98
- * @example
99
- * ```typescript
100
- * const resolved = createSendGridConfig({
101
- * apiKey: 'your-api-key'
102
- * });
103
- *
104
- * // resolved.baseUrl will be 'https://api.sendgrid.com/v3' (default)
105
- * // resolved.timeout will be 30000 (default)
106
- * // resolved.retries will be 3 (default)
107
- * ```
98
+ * @internal
108
99
  */
109
- declare function createSendGridConfig(config: SendGridConfig): ResolvedSendGridConfig;
110
- //#endregion
111
- //#region src/http-client.d.ts
112
- /**
113
- * Response from SendGrid API for sending messages.
114
- */
115
- interface SendGridResponse {
116
- /**
117
- * HTTP status code returned by SendGrid.
118
- */
119
- readonly statusCode?: number;
120
- /**
121
- * Response body from SendGrid (usually empty on success).
122
- */
123
- readonly body?: string;
124
- /**
125
- * Response headers from SendGrid.
126
- */
127
- readonly headers?: Record<string, string>;
128
- }
129
- /**
130
- * Error response from SendGrid API.
131
- */
132
-
133
- /**
134
- * HTTP client wrapper for SendGrid API requests.
135
- *
136
- * This class handles authentication, request formatting, error handling,
137
- * and retry logic for SendGrid API calls.
138
- */
139
- declare class SendGridHttpClient {
140
- config: ResolvedSendGridConfig;
141
- constructor(config: ResolvedSendGridConfig);
142
- /**
143
- * Sends a message via SendGrid API.
144
- *
145
- * @param messageData The JSON data to send to SendGrid.
146
- * @param signal Optional AbortSignal for cancellation.
147
- * @returns Promise that resolves to the SendGrid response.
148
- */
149
- sendMessage(messageData: Record<string, unknown>, signal?: AbortSignal): Promise<SendGridResponse>;
150
- /**
151
- * Makes an HTTP request to SendGrid API with retry logic.
152
- *
153
- * @param url The URL to make the request to.
154
- * @param options Fetch options.
155
- * @returns Promise that resolves to the parsed response.
156
- */
157
- makeRequest(url: string, options: RequestInit): Promise<SendGridResponse>;
158
- /**
159
- * Makes a fetch request with SendGrid authentication.
160
- *
161
- * @param url The URL to make the request to.
162
- * @param options Fetch options.
163
- * @returns Promise that resolves to the fetch response.
164
- */
165
- fetchWithAuth(url: string, options: RequestInit): Promise<Response>;
166
- /**
167
- * Converts Headers object to a plain Record.
168
- *
169
- * @param headers The Headers object to convert.
170
- * @returns A plain object with header key-value pairs.
171
- */
172
- headersToRecord(headers: Headers): Record<string, string>;
173
- }
174
- /**
175
- * Custom error class for SendGrid API errors.
176
- */
177
- declare class SendGridApiError extends Error {
178
- readonly statusCode?: number;
179
- readonly errors?: {
180
- readonly message: string;
181
- readonly field?: string;
182
- readonly help?: string;
183
- }[];
184
- constructor(message: string, statusCode?: number, errors?: Array<{
185
- message: string;
186
- field?: string;
187
- help?: string;
188
- }>);
189
- }
190
100
  //#endregion
191
101
  //#region src/sendgrid-transport.d.ts
192
102
  /**
@@ -206,12 +116,19 @@ declare class SendGridApiError extends Error {
206
116
  * });
207
117
  *
208
118
  * const receipt = await transport.send(message);
209
- * console.log('Message sent:', receipt.messageId);
119
+ * if (receipt.successful) {
120
+ * console.log('Message sent with ID:', receipt.messageId);
121
+ * } else {
122
+ * console.error('Send failed:', receipt.errorMessages.join(', '));
123
+ * }
210
124
  * ```
211
125
  */
212
126
  declare class SendGridTransport implements Transport {
213
- config: ReturnType<typeof createSendGridConfig>;
214
- httpClient: SendGridHttpClient;
127
+ /**
128
+ * The resolved SendGrid configuration used by this transport.
129
+ */
130
+ config: ResolvedSendGridConfig;
131
+ private httpClient;
215
132
  /**
216
133
  * Creates a new SendGrid transport instance.
217
134
  *
@@ -317,4 +234,23 @@ declare class SendGridTransport implements Transport {
317
234
  private extractMessageId;
318
235
  }
319
236
  //#endregion
320
- export { SendGridApiError, SendGridConfig, SendGridTransport, createSendGridConfig };
237
+ //#region src/http-client.d.ts
238
+
239
+ /**
240
+ * Custom error class for SendGrid API errors.
241
+ */
242
+ declare class SendGridApiError extends Error {
243
+ readonly statusCode?: number;
244
+ readonly errors?: {
245
+ readonly message: string;
246
+ readonly field?: string;
247
+ readonly help?: string;
248
+ }[];
249
+ constructor(message: string, statusCode?: number, errors?: Array<{
250
+ message: string;
251
+ field?: string;
252
+ help?: string;
253
+ }>);
254
+ }
255
+ //#endregion
256
+ export { SendGridApiError, SendGridConfig, SendGridTransport };
package/dist/index.d.ts CHANGED
@@ -91,102 +91,12 @@ type ResolvedSendGridConfig = Required<SendGridConfig>;
91
91
  *
92
92
  * This function takes a partial SendGrid configuration and returns a complete
93
93
  * configuration with all optional fields filled with sensible defaults.
94
+ * It is used internally by the SendGrid transport.
94
95
  *
95
96
  * @param config - The SendGrid configuration with optional fields
96
97
  * @returns A resolved configuration with all defaults applied
97
- *
98
- * @example
99
- * ```typescript
100
- * const resolved = createSendGridConfig({
101
- * apiKey: 'your-api-key'
102
- * });
103
- *
104
- * // resolved.baseUrl will be 'https://api.sendgrid.com/v3' (default)
105
- * // resolved.timeout will be 30000 (default)
106
- * // resolved.retries will be 3 (default)
107
- * ```
98
+ * @internal
108
99
  */
109
- declare function createSendGridConfig(config: SendGridConfig): ResolvedSendGridConfig;
110
- //#endregion
111
- //#region src/http-client.d.ts
112
- /**
113
- * Response from SendGrid API for sending messages.
114
- */
115
- interface SendGridResponse {
116
- /**
117
- * HTTP status code returned by SendGrid.
118
- */
119
- readonly statusCode?: number;
120
- /**
121
- * Response body from SendGrid (usually empty on success).
122
- */
123
- readonly body?: string;
124
- /**
125
- * Response headers from SendGrid.
126
- */
127
- readonly headers?: Record<string, string>;
128
- }
129
- /**
130
- * Error response from SendGrid API.
131
- */
132
-
133
- /**
134
- * HTTP client wrapper for SendGrid API requests.
135
- *
136
- * This class handles authentication, request formatting, error handling,
137
- * and retry logic for SendGrid API calls.
138
- */
139
- declare class SendGridHttpClient {
140
- config: ResolvedSendGridConfig;
141
- constructor(config: ResolvedSendGridConfig);
142
- /**
143
- * Sends a message via SendGrid API.
144
- *
145
- * @param messageData The JSON data to send to SendGrid.
146
- * @param signal Optional AbortSignal for cancellation.
147
- * @returns Promise that resolves to the SendGrid response.
148
- */
149
- sendMessage(messageData: Record<string, unknown>, signal?: AbortSignal): Promise<SendGridResponse>;
150
- /**
151
- * Makes an HTTP request to SendGrid API with retry logic.
152
- *
153
- * @param url The URL to make the request to.
154
- * @param options Fetch options.
155
- * @returns Promise that resolves to the parsed response.
156
- */
157
- makeRequest(url: string, options: RequestInit): Promise<SendGridResponse>;
158
- /**
159
- * Makes a fetch request with SendGrid authentication.
160
- *
161
- * @param url The URL to make the request to.
162
- * @param options Fetch options.
163
- * @returns Promise that resolves to the fetch response.
164
- */
165
- fetchWithAuth(url: string, options: RequestInit): Promise<Response>;
166
- /**
167
- * Converts Headers object to a plain Record.
168
- *
169
- * @param headers The Headers object to convert.
170
- * @returns A plain object with header key-value pairs.
171
- */
172
- headersToRecord(headers: Headers): Record<string, string>;
173
- }
174
- /**
175
- * Custom error class for SendGrid API errors.
176
- */
177
- declare class SendGridApiError extends Error {
178
- readonly statusCode?: number;
179
- readonly errors?: {
180
- readonly message: string;
181
- readonly field?: string;
182
- readonly help?: string;
183
- }[];
184
- constructor(message: string, statusCode?: number, errors?: Array<{
185
- message: string;
186
- field?: string;
187
- help?: string;
188
- }>);
189
- }
190
100
  //#endregion
191
101
  //#region src/sendgrid-transport.d.ts
192
102
  /**
@@ -206,12 +116,19 @@ declare class SendGridApiError extends Error {
206
116
  * });
207
117
  *
208
118
  * const receipt = await transport.send(message);
209
- * console.log('Message sent:', receipt.messageId);
119
+ * if (receipt.successful) {
120
+ * console.log('Message sent with ID:', receipt.messageId);
121
+ * } else {
122
+ * console.error('Send failed:', receipt.errorMessages.join(', '));
123
+ * }
210
124
  * ```
211
125
  */
212
126
  declare class SendGridTransport implements Transport {
213
- config: ReturnType<typeof createSendGridConfig>;
214
- httpClient: SendGridHttpClient;
127
+ /**
128
+ * The resolved SendGrid configuration used by this transport.
129
+ */
130
+ config: ResolvedSendGridConfig;
131
+ private httpClient;
215
132
  /**
216
133
  * Creates a new SendGrid transport instance.
217
134
  *
@@ -317,4 +234,23 @@ declare class SendGridTransport implements Transport {
317
234
  private extractMessageId;
318
235
  }
319
236
  //#endregion
320
- export { SendGridApiError, SendGridConfig, SendGridTransport, createSendGridConfig };
237
+ //#region src/http-client.d.ts
238
+
239
+ /**
240
+ * Custom error class for SendGrid API errors.
241
+ */
242
+ declare class SendGridApiError extends Error {
243
+ readonly statusCode?: number;
244
+ readonly errors?: {
245
+ readonly message: string;
246
+ readonly field?: string;
247
+ readonly help?: string;
248
+ }[];
249
+ constructor(message: string, statusCode?: number, errors?: Array<{
250
+ message: string;
251
+ field?: string;
252
+ help?: string;
253
+ }>);
254
+ }
255
+ //#endregion
256
+ export { SendGridApiError, SendGridConfig, SendGridTransport };
package/dist/index.js CHANGED
@@ -4,20 +4,11 @@
4
4
  *
5
5
  * This function takes a partial SendGrid configuration and returns a complete
6
6
  * configuration with all optional fields filled with sensible defaults.
7
+ * It is used internally by the SendGrid transport.
7
8
  *
8
9
  * @param config - The SendGrid configuration with optional fields
9
10
  * @returns A resolved configuration with all defaults applied
10
- *
11
- * @example
12
- * ```typescript
13
- * const resolved = createSendGridConfig({
14
- * apiKey: 'your-api-key'
15
- * });
16
- *
17
- * // resolved.baseUrl will be 'https://api.sendgrid.com/v3' (default)
18
- * // resolved.timeout will be 30000 (default)
19
- * // resolved.retries will be 3 (default)
20
- * ```
11
+ * @internal
21
12
  */
22
13
  function createSendGridConfig(config) {
23
14
  return {
@@ -312,10 +303,17 @@ function isStandardHeader(headerName) {
312
303
  * });
313
304
  *
314
305
  * const receipt = await transport.send(message);
315
- * console.log('Message sent:', receipt.messageId);
306
+ * if (receipt.successful) {
307
+ * console.log('Message sent with ID:', receipt.messageId);
308
+ * } else {
309
+ * console.error('Send failed:', receipt.errorMessages.join(', '));
310
+ * }
316
311
  * ```
317
312
  */
318
313
  var SendGridTransport = class {
314
+ /**
315
+ * The resolved SendGrid configuration used by this transport.
316
+ */
319
317
  config;
320
318
  httpClient;
321
319
  /**
@@ -368,16 +366,14 @@ var SendGridTransport = class {
368
366
  const response = await this.httpClient.sendMessage(mailData, options?.signal);
369
367
  const messageId = this.extractMessageId(response);
370
368
  return {
371
- messageId,
372
- errorMessages: [],
373
- successful: true
369
+ successful: true,
370
+ messageId
374
371
  };
375
372
  } catch (error) {
376
373
  const errorMessage = error instanceof Error ? error.message : String(error);
377
374
  return {
378
- messageId: "",
379
- errorMessages: [errorMessage],
380
- successful: false
375
+ successful: false,
376
+ errorMessages: [errorMessage]
381
377
  };
382
378
  }
383
379
  }
@@ -464,4 +460,4 @@ var SendGridTransport = class {
464
460
  };
465
461
 
466
462
  //#endregion
467
- export { SendGridApiError, SendGridTransport, createSendGridConfig };
463
+ export { SendGridApiError, SendGridTransport };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@upyo/sendgrid",
3
- "version": "0.1.0-dev.13+aad44636",
3
+ "version": "0.1.0-dev.17+3ffd074a",
4
4
  "description": "SendGrid 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.1.0-dev.13+aad44636"
56
+ "@upyo/core": "0.1.0-dev.17+3ffd074a"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@dotenvx/dotenvx": "^1.47.3",