@bernierllc/email-sender 3.0.5 → 5.0.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.
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Email sender error classes with ES2022 Error.cause support
3
+ *
4
+ * These errors follow the error propagation standard defined in:
5
+ * plans/standards/error-propagation-standard.md
6
+ */
7
+ /**
8
+ * Error codes for programmatic error handling
9
+ */
10
+ export declare const EmailSenderErrorCode: {
11
+ readonly PROVIDER_ERROR: "PROVIDER_ERROR";
12
+ readonly PROVIDER_AUTH_ERROR: "PROVIDER_AUTH_ERROR";
13
+ readonly PROVIDER_RATE_LIMITED: "PROVIDER_RATE_LIMITED";
14
+ readonly PROVIDER_UNAVAILABLE: "PROVIDER_UNAVAILABLE";
15
+ readonly VALIDATION_ERROR: "VALIDATION_ERROR";
16
+ readonly INVALID_EMAIL: "INVALID_EMAIL";
17
+ readonly INVALID_TEMPLATE: "INVALID_TEMPLATE";
18
+ readonly TEMPLATE_NOT_FOUND: "TEMPLATE_NOT_FOUND";
19
+ readonly TEMPLATE_UNAUTHORIZED: "TEMPLATE_UNAUTHORIZED";
20
+ readonly TEMPLATE_CONFLICT: "TEMPLATE_CONFLICT";
21
+ readonly NETWORK_ERROR: "NETWORK_ERROR";
22
+ readonly TIMEOUT_ERROR: "TIMEOUT_ERROR";
23
+ readonly SEND_ERROR: "SEND_ERROR";
24
+ readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
25
+ };
26
+ export type EmailSenderErrorCodeType = typeof EmailSenderErrorCode[keyof typeof EmailSenderErrorCode];
27
+ /**
28
+ * Options for creating an EmailSenderError
29
+ */
30
+ export interface EmailSenderErrorOptions {
31
+ /** The underlying error that caused this error */
32
+ cause?: Error;
33
+ /** Machine-readable error code for programmatic handling */
34
+ code?: EmailSenderErrorCodeType;
35
+ /** Additional context about the error */
36
+ context?: Record<string, unknown>;
37
+ /** Whether this error is retryable */
38
+ retryable?: boolean;
39
+ /** Suggested retry delay in milliseconds */
40
+ retryAfter?: number;
41
+ }
42
+ /**
43
+ * Base error class for all email sender errors
44
+ *
45
+ * Supports ES2022 Error.cause for error chaining.
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * try {
50
+ * await sendGridClient.send(email);
51
+ * } catch (error) {
52
+ * throw new EmailSenderError('Failed to send email via SendGrid', {
53
+ * cause: error,
54
+ * code: 'PROVIDER_ERROR',
55
+ * context: { provider: 'sendgrid', to: email.to }
56
+ * });
57
+ * }
58
+ * ```
59
+ */
60
+ export declare class EmailSenderError extends Error {
61
+ readonly code: EmailSenderErrorCodeType;
62
+ readonly context: Record<string, unknown> | undefined;
63
+ readonly retryable: boolean;
64
+ readonly retryAfter: number | undefined;
65
+ constructor(message: string, options?: EmailSenderErrorOptions);
66
+ /**
67
+ * Check if the error or any error in its cause chain is retryable
68
+ */
69
+ isRetryable(): boolean;
70
+ /**
71
+ * Get retry timing from this error or its cause chain
72
+ */
73
+ getRetryAfter(): number | undefined;
74
+ }
75
+ /**
76
+ * Error thrown when email validation fails
77
+ */
78
+ export declare class EmailValidationError extends EmailSenderError {
79
+ constructor(message: string, options?: Omit<EmailSenderErrorOptions, 'code'>);
80
+ }
81
+ /**
82
+ * Error thrown when a provider operation fails
83
+ */
84
+ export declare class ProviderError extends EmailSenderError {
85
+ readonly statusCode: number | undefined;
86
+ readonly providerResponse: unknown;
87
+ constructor(message: string, options?: EmailSenderErrorOptions & {
88
+ statusCode?: number;
89
+ providerResponse?: unknown;
90
+ });
91
+ }
92
+ /**
93
+ * Error thrown when rate limited by a provider
94
+ */
95
+ export declare class RateLimitError extends EmailSenderError {
96
+ constructor(message: string, options?: Omit<EmailSenderErrorOptions, 'code' | 'retryable'> & {
97
+ retryAfter?: number;
98
+ });
99
+ }
100
+ /**
101
+ * Error thrown when network communication fails
102
+ */
103
+ export declare class NetworkError extends EmailSenderError {
104
+ constructor(message: string, options?: Omit<EmailSenderErrorOptions, 'code'>);
105
+ }
106
+ /**
107
+ * Error thrown when a request times out
108
+ */
109
+ export declare class TimeoutError extends EmailSenderError {
110
+ constructor(message: string, options?: Omit<EmailSenderErrorOptions, 'code'>);
111
+ }
112
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AAEH;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;CAwBvB,CAAC;AAEX,MAAM,MAAM,wBAAwB,GAAG,OAAO,oBAAoB,CAAC,MAAM,OAAO,oBAAoB,CAAC,CAAC;AAEtG;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,kDAAkD;IAClD,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,4DAA4D;IAC5D,IAAI,CAAC,EAAE,wBAAwB,CAAC;IAChC,yCAAyC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,sCAAsC;IACtC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,4CAA4C;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,QAAQ,CAAC,IAAI,EAAE,wBAAwB,CAAC;IACxC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IACtD,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;gBAE5B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,uBAAuB;IAiB9D;;OAEG;IACH,WAAW,IAAI,OAAO;IAetB;;OAEG;IACH,aAAa,IAAI,MAAM,GAAG,SAAS;CAcpC;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,gBAAgB;gBAC5C,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,uBAAuB,EAAE,MAAM,CAAC;CAI7E;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,gBAAgB;IACjD,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;gBAGjC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,uBAAuB,GAAG;QAClC,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,gBAAgB,CAAC,EAAE,OAAO,CAAC;KAC5B;CAOJ;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,gBAAgB;gBAEhD,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,IAAI,CAAC,uBAAuB,EAAE,MAAM,GAAG,WAAW,CAAC,GAAG;QAC9D,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB;CAaJ;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,gBAAgB;gBACpC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,uBAAuB,EAAE,MAAM,CAAC;CAQ7E;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,gBAAgB;gBACpC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,uBAAuB,EAAE,MAAM,CAAC;CAQ7E"}
package/dist/errors.js ADDED
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (c) 2025 Bernier LLC
4
+
5
+ This file is licensed to the client under a limited-use license.
6
+ The client may use and modify this code *only within the scope of the project it was delivered for*.
7
+ Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.TimeoutError = exports.NetworkError = exports.RateLimitError = exports.ProviderError = exports.EmailValidationError = exports.EmailSenderError = exports.EmailSenderErrorCode = void 0;
11
+ /**
12
+ * Email sender error classes with ES2022 Error.cause support
13
+ *
14
+ * These errors follow the error propagation standard defined in:
15
+ * plans/standards/error-propagation-standard.md
16
+ */
17
+ /**
18
+ * Error codes for programmatic error handling
19
+ */
20
+ exports.EmailSenderErrorCode = {
21
+ // Provider errors
22
+ PROVIDER_ERROR: 'PROVIDER_ERROR',
23
+ PROVIDER_AUTH_ERROR: 'PROVIDER_AUTH_ERROR',
24
+ PROVIDER_RATE_LIMITED: 'PROVIDER_RATE_LIMITED',
25
+ PROVIDER_UNAVAILABLE: 'PROVIDER_UNAVAILABLE',
26
+ // Validation errors
27
+ VALIDATION_ERROR: 'VALIDATION_ERROR',
28
+ INVALID_EMAIL: 'INVALID_EMAIL',
29
+ INVALID_TEMPLATE: 'INVALID_TEMPLATE',
30
+ // Template errors
31
+ TEMPLATE_NOT_FOUND: 'TEMPLATE_NOT_FOUND',
32
+ TEMPLATE_UNAUTHORIZED: 'TEMPLATE_UNAUTHORIZED',
33
+ TEMPLATE_CONFLICT: 'TEMPLATE_CONFLICT',
34
+ // Network errors
35
+ NETWORK_ERROR: 'NETWORK_ERROR',
36
+ TIMEOUT_ERROR: 'TIMEOUT_ERROR',
37
+ // General errors
38
+ SEND_ERROR: 'SEND_ERROR',
39
+ UNKNOWN_ERROR: 'UNKNOWN_ERROR',
40
+ };
41
+ /**
42
+ * Base error class for all email sender errors
43
+ *
44
+ * Supports ES2022 Error.cause for error chaining.
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * try {
49
+ * await sendGridClient.send(email);
50
+ * } catch (error) {
51
+ * throw new EmailSenderError('Failed to send email via SendGrid', {
52
+ * cause: error,
53
+ * code: 'PROVIDER_ERROR',
54
+ * context: { provider: 'sendgrid', to: email.to }
55
+ * });
56
+ * }
57
+ * ```
58
+ */
59
+ class EmailSenderError extends Error {
60
+ constructor(message, options) {
61
+ super(message);
62
+ this.name = 'EmailSenderError';
63
+ this.code = options?.code ?? exports.EmailSenderErrorCode.UNKNOWN_ERROR;
64
+ this.context = options?.context;
65
+ this.retryable = options?.retryable ?? false;
66
+ this.retryAfter = options?.retryAfter;
67
+ // Set cause using ES2022 pattern (works at runtime in Node 16.9+)
68
+ if (options?.cause) {
69
+ this.cause = options.cause;
70
+ }
71
+ // Maintains proper stack trace in V8 engines
72
+ Error.captureStackTrace?.(this, this.constructor);
73
+ }
74
+ /**
75
+ * Check if the error or any error in its cause chain is retryable
76
+ */
77
+ isRetryable() {
78
+ if (this.retryable)
79
+ return true;
80
+ // Check cause chain
81
+ let current = this.cause;
82
+ while (current instanceof Error) {
83
+ if ('retryable' in current && current.retryable === true) {
84
+ return true;
85
+ }
86
+ current = current.cause;
87
+ }
88
+ return false;
89
+ }
90
+ /**
91
+ * Get retry timing from this error or its cause chain
92
+ */
93
+ getRetryAfter() {
94
+ if (this.retryAfter !== undefined)
95
+ return this.retryAfter;
96
+ // Check cause chain
97
+ let current = this.cause;
98
+ while (current instanceof Error) {
99
+ if ('retryAfter' in current && typeof current.retryAfter === 'number') {
100
+ return current.retryAfter;
101
+ }
102
+ current = current.cause;
103
+ }
104
+ return undefined;
105
+ }
106
+ }
107
+ exports.EmailSenderError = EmailSenderError;
108
+ /**
109
+ * Error thrown when email validation fails
110
+ */
111
+ class EmailValidationError extends EmailSenderError {
112
+ constructor(message, options) {
113
+ super(message, { ...options, code: exports.EmailSenderErrorCode.VALIDATION_ERROR });
114
+ this.name = 'EmailValidationError';
115
+ }
116
+ }
117
+ exports.EmailValidationError = EmailValidationError;
118
+ /**
119
+ * Error thrown when a provider operation fails
120
+ */
121
+ class ProviderError extends EmailSenderError {
122
+ constructor(message, options) {
123
+ super(message, { ...options, code: options?.code ?? exports.EmailSenderErrorCode.PROVIDER_ERROR });
124
+ this.name = 'ProviderError';
125
+ this.statusCode = options?.statusCode;
126
+ this.providerResponse = options?.providerResponse;
127
+ }
128
+ }
129
+ exports.ProviderError = ProviderError;
130
+ /**
131
+ * Error thrown when rate limited by a provider
132
+ */
133
+ class RateLimitError extends EmailSenderError {
134
+ constructor(message, options) {
135
+ const baseOptions = {
136
+ ...options,
137
+ code: exports.EmailSenderErrorCode.PROVIDER_RATE_LIMITED,
138
+ retryable: true,
139
+ };
140
+ if (options?.retryAfter !== undefined) {
141
+ baseOptions.retryAfter = options.retryAfter;
142
+ }
143
+ super(message, baseOptions);
144
+ this.name = 'RateLimitError';
145
+ }
146
+ }
147
+ exports.RateLimitError = RateLimitError;
148
+ /**
149
+ * Error thrown when network communication fails
150
+ */
151
+ class NetworkError extends EmailSenderError {
152
+ constructor(message, options) {
153
+ super(message, {
154
+ ...options,
155
+ code: exports.EmailSenderErrorCode.NETWORK_ERROR,
156
+ retryable: true, // Network errors are generally retryable
157
+ });
158
+ this.name = 'NetworkError';
159
+ }
160
+ }
161
+ exports.NetworkError = NetworkError;
162
+ /**
163
+ * Error thrown when a request times out
164
+ */
165
+ class TimeoutError extends EmailSenderError {
166
+ constructor(message, options) {
167
+ super(message, {
168
+ ...options,
169
+ code: exports.EmailSenderErrorCode.TIMEOUT_ERROR,
170
+ retryable: true,
171
+ });
172
+ this.name = 'TimeoutError';
173
+ }
174
+ }
175
+ exports.TimeoutError = TimeoutError;
176
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";AAAA;;;;;;EAME;;;AAEF;;;;;GAKG;AAEH;;GAEG;AACU,QAAA,oBAAoB,GAAG;IAClC,kBAAkB;IAClB,cAAc,EAAE,gBAAgB;IAChC,mBAAmB,EAAE,qBAAqB;IAC1C,qBAAqB,EAAE,uBAAuB;IAC9C,oBAAoB,EAAE,sBAAsB;IAE5C,oBAAoB;IACpB,gBAAgB,EAAE,kBAAkB;IACpC,aAAa,EAAE,eAAe;IAC9B,gBAAgB,EAAE,kBAAkB;IAEpC,kBAAkB;IAClB,kBAAkB,EAAE,oBAAoB;IACxC,qBAAqB,EAAE,uBAAuB;IAC9C,iBAAiB,EAAE,mBAAmB;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SAAS,EAAE,IAAI;SAChB,CAAC;QACF,IAAI,OAAO,EAAE,UAAU,KAAK,SAAS,EAAE,CAAC;YACtC,WAAW,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QAC9C,CAAC;QACD,KAAK,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAlBD,wCAkBC;AAED;;GAEG;AACH,MAAa,YAAa,SAAQ,gBAAgB;IAChD,YAAY,OAAe,EAAE,OAA+C;QAC1E,KAAK,CAAC,OAAO,EAAE;YACb,GAAG,OAAO;YACV,IAAI,EAAE,4BAAoB,CAAC,aAAa;YACxC,SAAS,EAAE,IAAI,EAAE,yCAAyC;SAC3D,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AATD,oCASC;AAED;;GAEG;AACH,MAAa,YAAa,SAAQ,gBAAgB;IAChD,YAAY,OAAe,EAAE,OAA+C;QAC1E,KAAK,CAAC,OAAO,EAAE;YACb,GAAG,OAAO;YACV,IAAI,EAAE,4BAAoB,CAAC,aAAa;YACxC,SAAS,EAAE,IAAI;SAChB,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AATD,oCASC"}
package/dist/index.d.ts CHANGED
@@ -12,6 +12,9 @@ export { SesProvider } from './providers/ses';
12
12
  export { MailgunProvider } from './providers/mailgun';
13
13
  export { PostmarkProvider } from './providers/postmark';
14
14
  export type { EmailMessage, SendResult, DeliveryStatus, WebhookEvent, EmailProviderConfig, EmailProviderCapabilities, EmailValidationResult, EmailAttachment, BatchEmailOptions, EmailTemplate, StagingSafetyConfig, EmailSafetyResult } from './types';
15
+ export { EmailSenderError, EmailSenderErrorCode, EmailValidationError, ProviderError, RateLimitError, NetworkError, TimeoutError, } from './errors';
16
+ export type { EmailSenderErrorOptions, EmailSenderErrorCodeType, } from './errors';
15
17
  export type { VerifiedSender, SenderValidationResult, Template, ProviderTemplate, TemplateVersion, SyncResult, TemplateAnalytics, SendGridAdvancedConfig } from './providers/sendgrid/types';
16
- export { SendGridApiError, TemplateNotFoundError, UnauthorizedTemplateAccessError, TemplateConflictError, RateLimitError } from './providers/sendgrid/errors';
18
+ export { SendGridApiError, TemplateNotFoundError, UnauthorizedTemplateAccessError, TemplateConflictError, SendGridRateLimitError, SendGridErrorCode, } from './providers/sendgrid/errors';
19
+ export type { SendGridErrorCodeType } from './providers/sendgrid/errors';
17
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA;;;GAGG;AAGH,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAGjE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAGxD,YAAY,EACV,YAAY,EACZ,UAAU,EACV,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,yBAAyB,EACzB,qBAAqB,EACrB,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAGjB,YAAY,EACV,cAAc,EACd,sBAAsB,EACtB,QAAQ,EACR,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,iBAAiB,EACjB,sBAAsB,EACvB,MA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+B,EAC/B,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,6BAA6B,CAAC;AACrC,YAAY,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC"}
package/dist/index.js CHANGED
@@ -21,7 +21,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
21
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
22
22
  };
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.RateLimitError = exports.TemplateConflictError = exports.UnauthorizedTemplateAccessError = exports.TemplateNotFoundError = exports.SendGridApiError = exports.PostmarkProvider = exports.MailgunProvider = exports.SesProvider = exports.SendGridProvider = exports.SmtpProvider = exports.EmailProvider = exports.EmailSafetyManager = exports.EmailSender = void 0;
24
+ exports.SendGridErrorCode = exports.SendGridRateLimitError = exports.TemplateConflictError = exports.UnauthorizedTemplateAccessError = exports.TemplateNotFoundError = exports.SendGridApiError = exports.TimeoutError = exports.NetworkError = exports.RateLimitError = exports.ProviderError = exports.EmailValidationError = exports.EmailSenderErrorCode = exports.EmailSenderError = exports.PostmarkProvider = exports.MailgunProvider = exports.SesProvider = exports.SendGridProvider = exports.SmtpProvider = exports.EmailProvider = exports.EmailSafetyManager = exports.EmailSender = void 0;
25
25
  /**
26
26
  * Email Sender - Core Library
27
27
  * Main entry point for the email sending system
@@ -46,10 +46,21 @@ var mailgun_1 = require("./providers/mailgun");
46
46
  Object.defineProperty(exports, "MailgunProvider", { enumerable: true, get: function () { return mailgun_1.MailgunProvider; } });
47
47
  var postmark_1 = require("./providers/postmark");
48
48
  Object.defineProperty(exports, "PostmarkProvider", { enumerable: true, get: function () { return postmark_1.PostmarkProvider; } });
49
- var errors_1 = require("./providers/sendgrid/errors");
50
- Object.defineProperty(exports, "SendGridApiError", { enumerable: true, get: function () { return errors_1.SendGridApiError; } });
51
- Object.defineProperty(exports, "TemplateNotFoundError", { enumerable: true, get: function () { return errors_1.TemplateNotFoundError; } });
52
- Object.defineProperty(exports, "UnauthorizedTemplateAccessError", { enumerable: true, get: function () { return errors_1.UnauthorizedTemplateAccessError; } });
53
- Object.defineProperty(exports, "TemplateConflictError", { enumerable: true, get: function () { return errors_1.TemplateConflictError; } });
49
+ // Error classes and types (v3.1.0 - Error propagation standard)
50
+ var errors_1 = require("./errors");
51
+ Object.defineProperty(exports, "EmailSenderError", { enumerable: true, get: function () { return errors_1.EmailSenderError; } });
52
+ Object.defineProperty(exports, "EmailSenderErrorCode", { enumerable: true, get: function () { return errors_1.EmailSenderErrorCode; } });
53
+ Object.defineProperty(exports, "EmailValidationError", { enumerable: true, get: function () { return errors_1.EmailValidationError; } });
54
+ Object.defineProperty(exports, "ProviderError", { enumerable: true, get: function () { return errors_1.ProviderError; } });
54
55
  Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_1.RateLimitError; } });
56
+ Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function () { return errors_1.NetworkError; } });
57
+ Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return errors_1.TimeoutError; } });
58
+ // SendGrid-specific errors
59
+ var errors_2 = require("./providers/sendgrid/errors");
60
+ Object.defineProperty(exports, "SendGridApiError", { enumerable: true, get: function () { return errors_2.SendGridApiError; } });
61
+ Object.defineProperty(exports, "TemplateNotFoundError", { enumerable: true, get: function () { return errors_2.TemplateNotFoundError; } });
62
+ Object.defineProperty(exports, "UnauthorizedTemplateAccessError", { enumerable: true, get: function () { return errors_2.UnauthorizedTemplateAccessError; } });
63
+ Object.defineProperty(exports, "TemplateConflictError", { enumerable: true, get: function () { return errors_2.TemplateConflictError; } });
64
+ Object.defineProperty(exports, "SendGridRateLimitError", { enumerable: true, get: function () { return errors_2.SendGridRateLimitError; } });
65
+ Object.defineProperty(exports, "SendGridErrorCode", { enumerable: true, get: function () { return errors_2.SendGridErrorCode; } });
55
66
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;EAME;;;;;;;;;;;;;;;;;AAEF;;;GAGG;AAEH,aAAa;AACb,0CAAwB;AAExB,eAAe;AACf,oDAAqE;AAA5D,2GAAA,WAAW,OAAA;AACpB,oEAAiE;AAAxD,0HAAA,kBAAkB,OAAA;AAE3B,mBAAmB;AACnB,yCAAiD;AAAxC,qGAAA,aAAa,OAAA;AACtB,yCAAgD;AAAvC,oGAAA,YAAY,OAAA;AACrB,iDAAwD;AAA/C,4GAAA,gBAAgB,OAAA;AACzB,uCAA8C;AAArC,kGAAA,WAAW,OAAA;AACpB,+CAAsD;AAA7C,0GAAA,eAAe,OAAA;AACxB,iDAAwD;AAA/C,4GAAA,gBAAgB,OAAA;AA8BzB,sDAMqC;AALnC,0GAAA,gBAAgB,OAAA;AAChB,+GAAA,qBAAqB,OAAA;AACrB,yHAAA,+BAA+B,OAAA;AAC/B,+GAAA,qBAAqB,OAAA;AACrB,wGAAA,cAAc,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;EAME;;;;;;;;;;;;;;;;;AAEF;;;GAGG;AAEH,aAAa;AACb,0CAAwB;AAExB,eAAe;AACf,oDAAqE;AAA5D,2GAAA,WAAW,OAAA;AACpB,oEAAiE;AAAxD,0HAAA,kBAAkB,OAAA;AAE3B,mBAAmB;AACnB,yCAAiD;AAAxC,qGAAA,aAAa,OAAA;AACtB,yCAAgD;AAAvC,oGAAA,YAAY,OAAA;AACrB,iDAAwD;AAA/C,4GAAA,gBAAgB,OAAA;AACzB,uCAA8C;AAArC,kGAAA,WAAW,OAAA;AACpB,+CAAsD;AAA7C,0GAAA,eAAe,OAAA;AACxB,iDAAwD;AAA/C,4GAAA,gBAAgB,OAAA;AAkBzB,gEAAgE;AAChE,mCAQkB;AAPhB,0GAAA,gBAAgB,OAAA;AAChB,8GAAA,oBAAoB,O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jF,iBAAiB,CAAC,QAAQ,EAAE,WAAW,GAAG,OAAO;IAIjD,iBAAiB,CAAC,CAAC,EAAE,QAAQ,EAAE,WAAW,GAAG,CAAC;CAO/C"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/providers/sendgrid/client.ts"],"names":[],"mappings":"AAQA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAC5C,MAAM,CAAC,EAAE;QACP,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;QACjC,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;QACjC,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;KACjC,GAAG,SAAS,CAAC;CACf;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAgC;IAC7D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAA6C;IACrE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiC;gBAE7C,MAAM,EAAE,oBAAoB;IAMlC,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC;IA+CjF,iBAAiB,CAAC,QAAQ,EAAE,WAAW,GAAG,OAAO;IAIjD,iBAAiB,CAAC,CAAC,EAAE,QAAQ,EAAE,WAAW,GAAG,CAAC;CAW/C"}
@@ -47,7 +47,9 @@ class SendGridClient {
47
47
  catch (error) {
48
48
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
49
49
  this.logger?.error(`SendGrid API error: ${errorMessage}`);
50
- throw new errors_1.SendGridApiError(`API request failed: ${errorMessage}`, undefined, error);
50
+ throw new errors_1.SendGridApiError(`API request failed: ${errorMessage}`, {
51
+ cause: error instanceof Error ? error : new Error(String(error)),
52
+ });
51
53
  }
52
54
  finally {
53
55
  if (this.rateLimiter) {
@@ -62,8 +64,12 @@ class SendGridClient {
62
64
  try {
63
65
  return JSON.parse(response.body);
64
66
  }
65
- catch (_error) {
66
- throw new errors_1.SendGridApiError('Failed to parse response body', response.statusCode, response.body);
67
+ catch (parseError) {
68
+ throw new errors_1.SendGridApiError('Failed to parse response body', {
69
+ statusCode: response.statusCode,
70
+ response: response.body,
71
+ cause: parseError instanceof Error ? parseError : new Error(String(parseError)),
72
+ });
67
73
  }
68
74
  }
69
75
  }
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/providers/sendgrid/client.ts"],"names":[],"mappings":";AAAA;;;;;;EAME;;;AAQF,qCAA4C;AAa5C,MAAa,cAAc;IAMzB,YAAY,MAA4B;QAFvB,YAAO,GAAG,6BAA6B,CAAC;QAGvD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,QAAgB,EAAE,OAA0B;QACxD,oCAAoC;QACpC,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;QACnC,CAAC;QAED,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,GAAG,QAAQ,EAAE,CAAC;YAEzC,MAAM,WAAW,GAAgB;gBAC/B,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,OAAO,EAAE;oBACP,eAAe,EAAE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AK,CAAC,QAAQ,CAAC,IAAI,CAAM,CAAC;QACxC,CAAC;QAAC,OAAO,UAAU,EAAE,CAAC;YACpB,MAAM,IAAI,yBAAgB,CAAC,+BAA+B,EAAE;gBAC1D,UAAU,EAAE,QAAQ,CAAC,UAAU;gBAC/B,QAAQ,EAAE,QAAQ,CAAC,IAAI;gBACvB,KAAK,EAAE,UAAU,YAAY,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;aAChF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF;AA1ED,wCA0EC"}
@@ -1,23 +1,66 @@
1
1
  /**
2
- * SendGrid-specific error classes
3
- * Merged from @bernierllc/email-sendgrid-plugin v1.0.1
2
+ * SendGrid-specific error classes with ES2022 Error.cause support
3
+ *
4
+ * These errors follow the error propagation standard defined in:
5
+ * plans/standards/error-propagation-standard.md
4
6
  */
5
- export declare class SendGridApiError extends Error {
6
- statusCode?: number | undefined;
7
- response?: unknown | undefined;
8
- constructor(message: string, statusCode?: number | undefined, response?: unknown | undefined);
7
+ import { ProviderError, EmailSenderError, EmailSenderErrorCode, type EmailSenderErrorOptions } from '../../errors';
8
+ export { EmailSenderError, EmailSenderErrorCode };
9
+ /**
10
+ * Error codes specific to SendGrid operations
11
+ */
12
+ export declare const SendGridErrorCode: {
13
+ readonly API_ERROR: "SENDGRID_API_ERROR";
14
+ readonly TEMPLATE_NOT_FOUND: "SENDGRID_TEMPLATE_NOT_FOUND";
15
+ readonly TEMPLATE_UNAUTHORIZED: "SENDGRID_TEMPLATE_UNAUTHORIZED";
16
+ readonly TEMPLATE_CONFLICT: "SENDGRID_TEMPLATE_CONFLICT";
17
+ readonly RATE_LIMITED: "SENDGRID_RATE_LIMITED";
18
+ readonly INVALID_SENDER: "SENDGRID_INVALID_SENDER";
19
+ };
20
+ export type SendGridErrorCodeType = typeof SendGridErrorCode[keyof typeof SendGridErrorCode];
21
+ /**
22
+ * SendGrid API error with status code and response details
23
+ */
24
+ export declare class SendGridApiError extends ProviderError {
25
+ readonly sendGridErrors: Array<{
26
+ message: string;
27
+ field?: string;
28
+ }>;
29
+ constructor(message: string, options?: EmailSenderErrorOptions & {
30
+ statusCode?: number;
31
+ response?: unknown;
32
+ });
33
+ private extractErrors;
9
34
  }
10
- export declare class TemplateNotFoundError extends Error {
11
- constructor(templateId: string);
35
+ /**
36
+ * Error thrown when a SendGrid template is not found
37
+ */
38
+ export declare class TemplateNotFoundError extends EmailSenderError {
39
+ readonly templateId: string;
40
+ constructor(templateId: string, options?: Omit<EmailSenderErrorOptions, 'code'>);
12
41
  }
13
- export declare class UnauthorizedTemplateAccessError extends Error {
14
- constructor(templateId: string);
42
+ /**
43
+ * Error thrown when access to a template is unauthorized
44
+ */
45
+ export declare class UnauthorizedTemplateAccessError extends EmailSenderError {
46
+ readonly templateId: string;
47
+ constructor(templateId: string, options?: Omit<EmailSenderErrorOptions, 'code'>);
15
48
  }
16
- export declare class TemplateConflictError extends Error {
17
- conflicts: string[];
18
- constructor(templateId: string, conflicts: string[]);
49
+ /**
50
+ * Error thrown when template operations conflict
51
+ */
52
+ export declare class TemplateConflictError extends EmailSenderError {
53
+ readonly templateId: string;
54
+ readonly conflicts: string[];
55
+ constructor(templateId: string, conflicts: string[], options?: Omit<EmailSenderErrorOptions, 'code'>);
19
56
  }
20
- export declare class RateLimitError extends Error {
21
- constructor(message: string);
57
+ /**
58
+ * Error thrown when SendGrid rate limits are exceeded
59
+ */
60
+ export declare class SendGridRateLimitError extends EmailSenderError {
61
+ constructor(message: string, options?: Omit<EmailSenderErrorOptions, 'code' | 'retryable'> & {
62
+ retryAfter?: number;
63
+ });
22
64
  }
65
+ export { SendGridRateLimitError as RateLimitError };
23
66
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/providers/sendgrid/errors.ts"],"names":[],"mappings":"AAQA;;;GA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