@bernierllc/sender-identity-verification 1.6.1 → 2.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.
@@ -6,7 +6,7 @@ The client may use and modify this code *only within the scope of the project it
6
6
  Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
7
  */
8
8
 
9
- import { SenderVerificationError, SenderErrorCode, handleSenderError } from '../src/errors';
9
+ import { SenderVerificationError, handleSenderError } from '../src/errors';
10
10
  import { SenderIdentityVerification } from '../src/SenderIdentityVerification';
11
11
  import { SenderIdentityConfig } from '../src/config';
12
12
  import { EmailProvider, SenderStatus } from '../src/types';
@@ -35,36 +35,51 @@ describe('Error Handling Tests', () => {
35
35
  it('should create error with code and message', () => {
36
36
  const error = new SenderVerificationError(
37
37
  'Sender not found',
38
- SenderErrorCode.SENDER_NOT_FOUND
38
+ { code: 'SENDER_NOT_FOUND' }
39
39
  );
40
40
 
41
41
  expect(error.name).toBe('SenderVerificationError');
42
42
  expect(error.message).toBe('Sender not found');
43
- expect(error.code).toBe(SenderErrorCode.SENDER_NOT_FOUND);
44
- expect(error.details).toBeUndefined();
43
+ expect(error.code).toBe('SENDER_NOT_FOUND');
44
+ expect(error.context).toBeUndefined();
45
45
  });
46
46
 
47
- it('should create error with details', () => {
47
+ it('should create error with context (details)', () => {
48
48
  const error = new SenderVerificationError(
49
49
  'Verification failed',
50
- SenderErrorCode.VERIFICATION_FAILED,
51
- { attempts: 3, senderId: '123' }
50
+ {
51
+ code: 'VERIFICATION_FAILED',
52
+ context: { details: { attempts: 3, senderId: '123' } }
53
+ }
52
54
  );
53
55
 
54
- expect(error.code).toBe(SenderErrorCode.VERIFICATION_FAILED);
55
- expect(error.details).toEqual({ attempts: 3, senderId: '123' });
56
+ expect(error.code).toBe('VERIFICATION_FAILED');
57
+ expect(error.context).toEqual({ details: { attempts: 3, senderId: '123' } });
58
+ });
59
+
60
+ it('should default code to SENDER_VERIFICATION_ERROR when omitted', () => {
61
+ const error = new SenderVerificationError('generic failure');
62
+ expect(error.code).toBe('SENDER_VERIFICATION_ERROR');
56
63
  });
57
64
 
58
- it('should include all error codes', () => {
59
- expect(SenderErrorCode.SENDER_NOT_FOUND).toBe('SENDER_NOT_FOUND');
60
- expect(SenderErrorCode.SENDER_ALREADY_EXISTS).toBe('SENDER_ALREADY_EXISTS');
61
- expect(SenderErrorCode.SENDER_LOCKED).toBe('SENDER_LOCKED');
62
- expect(SenderErrorCode.VERIFICATION_EXPIRED).toBe('VERIFICATION_EXPIRED');
63
- expect(SenderErrorCode.VERIFICATION_FAILED).toBe('VERIFICATION_FAILED');
64
- expect(SenderErrorCode.DOMAIN_NOT_VERIFIED).toBe('DOMAIN_NOT_VERIFIED');
65
- expect(SenderErrorCode.PROVIDER_ERROR).toBe('PROVIDER_ERROR');
66
- expect(SenderErrorCode.INVALID_EMAIL).toBe('INVALID_EMAIL');
67
- expect(SenderErrorCode.RATE_LIMIT_EXCEEDED).toBe('RATE_LIMIT_EXCEEDED');
65
+ it('should preserve native ES2022 cause chain', () => {
66
+ const root = new Error('socket hang up');
67
+ const error = new SenderVerificationError('Provider call failed', {
68
+ code: 'PROVIDER_ERROR',
69
+ cause: root
70
+ });
71
+
72
+ expect(error.cause).toBe(root);
73
+ });
74
+
75
+ it('should preserve context when provided', () => {
76
+ const ctx = { senderId: 'abc', attempts: 5 };
77
+ const error = new SenderVerificationError('locked', {
78
+ code: 'SENDER_LOCKED',
79
+ context: ctx
80
+ });
81
+
82
+ expect(error.context).toBe(ctx);
68
83
  });
69
84
  });
70
85
 
@@ -72,14 +87,14 @@ describe('Error Handling Tests', () => {
72
87
  it('should handle SenderVerificationError', () => {
73
88
  const error = new SenderVerificationError(
74
89
  'Sender locked',
75
- SenderErrorCode.SENDER_LOCKED
90
+ { code: 'SENDER_LOCKED' }
76
91
  );
77
92
 
78
93
  const result = handleSenderError(error);
79
94
 
80
95
  expect(result.success).toBe(false);
81
96
  expect(result.error).toBe('Sender locked');
82
- expect(result.errors).toContain(SenderErrorCode.SENDER_LOCKED);
97
+ expect(result.errors).toContain('SENDER_LOCKED');
83
98
  });
84
99
 
85
100
  it('should handle generic Error', () => {
@@ -55,12 +55,21 @@ const email_sender_manager_1 = require("@bernierllc/email-sender-manager");
55
55
  * service falls back to the legacy in-memory store.
56
56
  */
57
57
  class SenderIdentityVerification {
58
+ config;
59
+ // Legacy in-memory store — used only when no senderManager is configured
60
+ senders = new Map();
61
+ // Provider plugin registry (keyed by providerId)
62
+ providerPlugins = new Map();
63
+ // Core persistence layer (optional, new path)
64
+ senderManager;
65
+ emailSender;
66
+ domainVerification;
67
+ cryptoUtils;
68
+ logger;
69
+ emailValidator;
70
+ neverhub;
58
71
  constructor(config) {
59
72
  this.config = config;
60
- // Legacy in-memory store — used only when no senderManager is configured
61
- this.senders = new Map();
62
- // Provider plugin registry (keyed by providerId)
63
- this.providerPlugins = new Map();
64
73
  // Initialize domain verification from config if provided
65
74
  if (config.domainVerificationConfig?.instance) {
66
75
  this.domainVerification = config.domainVerificationConfig.instance;
package/dist/errors.d.ts CHANGED
@@ -1,27 +1,39 @@
1
1
  import { SenderIdentityResult } from './types.js';
2
2
  /**
3
- * Sender error codes
3
+ * Typed error code union for sender-identity-verification errors.
4
+ *
5
+ * Replaces the previous `SenderErrorCode` enum (removed in 2.0.0).
6
+ * Consumers should use the string literal directly, e.g. `'SENDER_NOT_FOUND'`.
4
7
  */
5
- export declare enum SenderErrorCode {
6
- SENDER_NOT_FOUND = "SENDER_NOT_FOUND",
7
- SENDER_ALREADY_EXISTS = "SENDER_ALREADY_EXISTS",
8
- SENDER_LOCKED = "SENDER_LOCKED",
9
- VERIFICATION_EXPIRED = "VERIFICATION_EXPIRED",
10
- VERIFICATION_FAILED = "VERIFICATION_FAILED",
11
- DOMAIN_NOT_VERIFIED = "DOMAIN_NOT_VERIFIED",
12
- PROVIDER_ERROR = "PROVIDER_ERROR",
13
- INVALID_EMAIL = "INVALID_EMAIL",
14
- RATE_LIMIT_EXCEEDED = "RATE_LIMIT_EXCEEDED"
8
+ export type SenderVerificationErrorCode = 'SENDER_VERIFICATION_ERROR' | 'SENDER_NOT_FOUND' | 'SENDER_ALREADY_EXISTS' | 'SENDER_LOCKED' | 'VERIFICATION_EXPIRED' | 'VERIFICATION_FAILED' | 'DOMAIN_NOT_VERIFIED' | 'PROVIDER_ERROR' | 'INVALID_EMAIL' | 'RATE_LIMIT_EXCEEDED';
9
+ /**
10
+ * Options bag accepted by `SenderVerificationError`.
11
+ *
12
+ * - `cause`: chained underlying error (ES2022 Error.cause).
13
+ * - `code`: a typed error code from {@link SenderVerificationErrorCode}.
14
+ * - `context`: arbitrary structured context — senderId/details/etc.
15
+ * The legacy `details` ctor argument is now stored under `context.details`.
16
+ */
17
+ export interface SenderVerificationErrorOptions {
18
+ cause?: Error;
19
+ code?: SenderVerificationErrorCode;
20
+ context?: Record<string, unknown>;
15
21
  }
16
22
  /**
17
- * Custom error class for sender verification errors
23
+ * Custom error class for sender verification errors.
24
+ *
25
+ * Uses native ES2022 `Error.cause` for error chaining — read the underlying
26
+ * error via `error.cause`. Structured fields (senderId, details, etc.) live
27
+ * on `error.context` since 2.0.0.
18
28
  */
19
29
  export declare class SenderVerificationError extends Error {
20
- code: SenderErrorCode;
21
- details?: unknown | undefined;
22
- constructor(message: string, code: SenderErrorCode, details?: unknown | undefined);
30
+ readonly code: SenderVerificationErrorCode;
31
+ readonly context?: Record<string, unknown>;
32
+ constructor(message: string, options?: SenderVerificationErrorOptions);
23
33
  }
24
34
  /**
25
- * Error handling wrapper
35
+ * Error handling wrapper — converts arbitrary errors to a
36
+ * `SenderIdentityResult<never>` envelope. Reads `error.code` (now a string
37
+ * literal under the new union) to populate `errors`.
26
38
  */
27
39
  export declare function handleSenderError(error: unknown): SenderIdentityResult<never>;
package/dist/errors.js CHANGED
@@ -7,38 +7,33 @@ The client may use and modify this code *only within the scope of the project it
7
7
  Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.SenderVerificationError = exports.SenderErrorCode = void 0;
10
+ exports.SenderVerificationError = void 0;
11
11
  exports.handleSenderError = handleSenderError;
12
12
  /**
13
- * Sender error codes
14
- */
15
- var SenderErrorCode;
16
- (function (SenderErrorCode) {
17
- SenderErrorCode["SENDER_NOT_FOUND"] = "SENDER_NOT_FOUND";
18
- SenderErrorCode["SENDER_ALREADY_EXISTS"] = "SENDER_ALREADY_EXISTS";
19
- SenderErrorCode["SENDER_LOCKED"] = "SENDER_LOCKED";
20
- SenderErrorCode["VERIFICATION_EXPIRED"] = "VERIFICATION_EXPIRED";
21
- SenderErrorCode["VERIFICATION_FAILED"] = "VERIFICATION_FAILED";
22
- SenderErrorCode["DOMAIN_NOT_VERIFIED"] = "DOMAIN_NOT_VERIFIED";
23
- SenderErrorCode["PROVIDER_ERROR"] = "PROVIDER_ERROR";
24
- SenderErrorCode["INVALID_EMAIL"] = "INVALID_EMAIL";
25
- SenderErrorCode["RATE_LIMIT_EXCEEDED"] = "RATE_LIMIT_EXCEEDED";
26
- })(SenderErrorCode || (exports.SenderErrorCode = SenderErrorCode = {}));
27
- /**
28
- * Custom error class for sender verification errors
13
+ * Custom error class for sender verification errors.
14
+ *
15
+ * Uses native ES2022 `Error.cause` for error chaining — read the underlying
16
+ * error via `error.cause`. Structured fields (senderId, details, etc.) live
17
+ * on `error.context` since 2.0.0.
29
18
  */
30
19
  class SenderVerificationError extends Error {
31
- constructor(message, code, details) {
32
- super(message);
33
- this.code = code;
34
- this.details = details;
20
+ code;
21
+ context;
22
+ constructor(message, options) {
23
+ super(message, options?.cause ? { cause: options.cause } : undefined);
35
24
  this.name = 'SenderVerificationError';
36
- Object.setPrototypeOf(this, SenderVerificationError.prototype);
25
+ this.code = options?.code ?? 'SENDER_VERIFICATION_ERROR';
26
+ if (options?.context !== undefined) {
27
+ this.context = options.context;
28
+ }
29
+ Error.captureStackTrace?.(this, this.constructor);
37
30
  }
38
31
  }
39
32
  exports.SenderVerificationError = SenderVerificationError;
40
33
  /**
41
- * Error handling wrapper
34
+ * Error handling wrapper — converts arbitrary errors to a
35
+ * `SenderIdentityResult<never>` envelope. Reads `error.code` (now a string
36
+ * literal under the new union) to populate `errors`.
42
37
  */
43
38
  function handleSenderError(error) {
44
39
  if (error instanceof SenderVerificationError) {
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { SenderIdentityVerification } from './SenderIdentityVerification.js';
2
2
  export { SenderIdentityConfig, loadConfigFromEnv } from './config.js';
3
- export { SenderVerificationError, SenderErrorCode, handleSenderError } from './errors.js';
3
+ export { SenderVerificationError, handleSenderError } from './errors.js';
4
+ export type { SenderVerificationErrorCode, SenderVerificationErrorOptions } from './errors.js';
4
5
  export { SenderIdentity, SenderStatus, EmailProvider, CreateSenderInput, UpdateSenderInput, VerificationResult, ComplianceCheckResult, ListSendersOptions, SenderIdentityResult, DomainVerificationStatus, IEmailDomainVerification } from './types.js';
5
6
  export { getManualInstructions, isManualVerificationProvider } from './manual-instructions.js';
6
7
  export type { ManualVerificationInstruction } from './manual-instructions.js';
package/dist/index.js CHANGED
@@ -7,14 +7,13 @@ The client may use and modify this code *only within the scope of the project it
7
7
  Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.isManualVerificationProvider = exports.getManualInstructions = exports.EmailProvider = exports.SenderStatus = exports.handleSenderError = exports.SenderErrorCode = exports.SenderVerificationError = exports.loadConfigFromEnv = exports.SenderIdentityVerification = void 0;
10
+ exports.isManualVerificationProvider = exports.getManualInstructions = exports.EmailProvider = exports.SenderStatus = exports.handleSenderError = exports.SenderVerificationError = exports.loadConfigFromEnv = exports.SenderIdentityVerification = void 0;
11
11
  var SenderIdentityVerification_js_1 = require("./SenderIdentityVerification.js");
12
12
  Object.defineProperty(exports, "SenderIdentityVerification", { enumerable: true, get: function () { return SenderIdentityVerification_js_1.SenderIdentityVerification; } });
13
13
  var config_js_1 = require("./config.js");
14
14
  Object.defineProperty(exports, "loadConfigFromEnv", { enumerable: true, get: function () { return config_js_1.loadConfigFromEnv; } });
15
15
  var errors_js_1 = require("./errors.js");
16
16
  Object.defineProperty(exports, "SenderVerificationError", { enumerable: true, get: function () { return errors_js_1.SenderVerificationError; } });
17
- Object.defineProperty(exports, "SenderErrorCode", { enumerable: true, get: function () { return errors_js_1.SenderErrorCode; } });
18
17
  Object.defineProperty(exports, "handleSenderError", { enumerable: true, get: function () { return errors_js_1.handleSenderError; } });
19
18
  var types_js_1 = require("./types.js");
20
19
  Object.defineProperty(exports, "SenderStatus", { enumerable: true, get: function () { return types_js_1.SenderStatus; } });
@@ -12,6 +12,7 @@ exports.SendGridProvider = void 0;
12
12
  * SendGrid provider for sender verification
13
13
  */
14
14
  class SendGridProvider {
15
+ apiKey;
15
16
  constructor(apiKey) {
16
17
  this.apiKey = apiKey;
17
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bernierllc/sender-identity-verification",
3
- "version": "1.6.1",
3
+ "version": "2.0.0",
4
4
  "description": "Individual sender email address verification service for email production compliance",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,9 +20,9 @@
20
20
  "license": "SEE LICENSE IN LICENSE",
21
21
  "dependencies": {
22
22
  "@bernierllc/email-sender": "5.7.0",
23
+ "@bernierllc/logger": "1.7.0",
23
24
  "@bernierllc/crypto-utils": "1.4.0",
24
25
  "@bernierllc/email-sender-manager": "1.6.0",
25
- "@bernierllc/logger": "1.7.0",
26
26
  "@bernierllc/neverhub-adapter": "0.4.0",
27
27
  "@bernierllc/retry-policy": "0.7.0",
28
28
  "@bernierllc/validators-email": "0.7.0"
package/src/errors.ts CHANGED
@@ -9,37 +9,63 @@ Redistribution or use in other products or commercial offerings is not permitted
9
9
  import { SenderIdentityResult } from './types.js';
10
10
 
11
11
  /**
12
- * Sender error codes
12
+ * Typed error code union for sender-identity-verification errors.
13
+ *
14
+ * Replaces the previous `SenderErrorCode` enum (removed in 2.0.0).
15
+ * Consumers should use the string literal directly, e.g. `'SENDER_NOT_FOUND'`.
13
16
  */
14
- export enum SenderErrorCode {
15
- SENDER_NOT_FOUND = 'SENDER_NOT_FOUND',
16
- SENDER_ALREADY_EXISTS = 'SENDER_ALREADY_EXISTS',
17
- SENDER_LOCKED = 'SENDER_LOCKED',
18
- VERIFICATION_EXPIRED = 'VERIFICATION_EXPIRED',
19
- VERIFICATION_FAILED = 'VERIFICATION_FAILED',
20
- DOMAIN_NOT_VERIFIED = 'DOMAIN_NOT_VERIFIED',
21
- PROVIDER_ERROR = 'PROVIDER_ERROR',
22
- INVALID_EMAIL = 'INVALID_EMAIL',
23
- RATE_LIMIT_EXCEEDED = 'RATE_LIMIT_EXCEEDED',
17
+ export type SenderVerificationErrorCode =
18
+ | 'SENDER_VERIFICATION_ERROR'
19
+ | 'SENDER_NOT_FOUND'
20
+ | 'SENDER_ALREADY_EXISTS'
21
+ | 'SENDER_LOCKED'
22
+ | 'VERIFICATION_EXPIRED'
23
+ | 'VERIFICATION_FAILED'
24
+ | 'DOMAIN_NOT_VERIFIED'
25
+ | 'PROVIDER_ERROR'
26
+ | 'INVALID_EMAIL'
27
+ | 'RATE_LIMIT_EXCEEDED';
28
+
29
+ /**
30
+ * Options bag accepted by `SenderVerificationError`.
31
+ *
32
+ * - `cause`: chained underlying error (ES2022 Error.cause).
33
+ * - `code`: a typed error code from {@link SenderVerificationErrorCode}.
34
+ * - `context`: arbitrary structured context — senderId/details/etc.
35
+ * The legacy `details` ctor argument is now stored under `context.details`.
36
+ */
37
+ export interface SenderVerificationErrorOptions {
38
+ cause?: Error;
39
+ code?: SenderVerificationErrorCode;
40
+ context?: Record<string, unknown>;
24
41
  }
25
42
 
26
43
  /**
27
- * Custom error class for sender verification errors
44
+ * Custom error class for sender verification errors.
45
+ *
46
+ * Uses native ES2022 `Error.cause` for error chaining — read the underlying
47
+ * error via `error.cause`. Structured fields (senderId, details, etc.) live
48
+ * on `error.context` since 2.0.0.
28
49
  */
29
50
  export class SenderVerificationError extends Error {
30
- constructor(
31
- message: string,
32
- public code: SenderErrorCode,
33
- public details?: unknown
34
- ) {
35
- super(message);
51
+ public readonly code: SenderVerificationErrorCode;
52
+ public readonly context?: Record<string, unknown>;
53
+
54
+ constructor(message: string, options?: SenderVerificationErrorOptions) {
55
+ super(message, options?.cause ? { cause: options.cause } : undefined);
36
56
  this.name = 'SenderVerificationError';
37
- Object.setPrototypeOf(this, SenderVerificationError.prototype);
57
+ this.code = options?.code ?? 'SENDER_VERIFICATION_ERROR';
58
+ if (options?.context !== undefined) {
59
+ this.context = options.context;
60
+ }
61
+ Error.captureStackTrace?.(this, this.constructor);
38
62
  }
39
63
  }
40
64
 
41
65
  /**
42
- * Error handling wrapper
66
+ * Error handling wrapper — converts arbitrary errors to a
67
+ * `SenderIdentityResult<never>` envelope. Reads `error.code` (now a string
68
+ * literal under the new union) to populate `errors`.
43
69
  */
44
70
  export function handleSenderError(error: unknown): SenderIdentityResult<never> {
45
71
  if (error instanceof SenderVerificationError) {
package/src/index.ts CHANGED
@@ -8,7 +8,14 @@ Redistribution or use in other products or commercial offerings is not permitted
8
8
 
9
9
  export { SenderIdentityVerification } from './SenderIdentityVerification.js';
10
10
  export { SenderIdentityConfig, loadConfigFromEnv } from './config.js';
11
- export { SenderVerificationError, SenderErrorCode, handleSenderError } from './errors.js';
11
+ export {
12
+ SenderVerificationError,
13
+ handleSenderError
14
+ } from './errors.js';
15
+ export type {
16
+ SenderVerificationErrorCode,
17
+ SenderVerificationErrorOptions
18
+ } from './errors.js';
12
19
  export {
13
20
  SenderIdentity,
14
21
  SenderStatus,
package/tsconfig.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "ES2020",
3
+ "target": "ES2022",
4
4
  "module": "commonjs",
5
- "lib": ["ES2020", "DOM"],
5
+ "lib": ["ES2022", "DOM"],
6
6
  "declaration": true,
7
7
  "outDir": "./dist",
8
8
  "rootDir": "./src",