@bernierllc/email-webhook-events 1.4.0 → 1.6.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.
Files changed (52) hide show
  1. package/dist/EmailWebhookEventsService.js +4 -0
  2. package/dist/EmailWebhookEventsService.js.map +1 -1
  3. package/dist/analytics/AnalyticsEngine.js +2 -1
  4. package/dist/analytics/AnalyticsEngine.js.map +1 -1
  5. package/dist/errors.d.ts +12 -0
  6. package/dist/errors.d.ts.map +1 -0
  7. package/dist/errors.js +25 -0
  8. package/dist/errors.js.map +1 -0
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +3 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/persistence/InMemoryPersistenceAdapter.js +2 -4
  14. package/dist/persistence/InMemoryPersistenceAdapter.js.map +1 -1
  15. package/package.json +6 -2
  16. package/.eslintrc.cjs +0 -30
  17. package/CHANGELOG.md +0 -131
  18. package/__tests__/EmailWebhookEventsService.test.ts +0 -251
  19. package/__tests__/WebhookEventCallbacks.test.ts +0 -343
  20. package/__tests__/analytics/AnalyticsEngine.test.ts +0 -250
  21. package/__tests__/fixtures/sendgrid-webhooks/.gitkeep +0 -0
  22. package/__tests__/fixtures/sendgrid-webhooks/README.md +0 -63
  23. package/__tests__/fixtures/sendgrid-webhooks/deferred.json +0 -31
  24. package/__tests__/fixtures/sendgrid-webhooks/delivered.json +0 -83
  25. package/__tests__/fixtures/sendgrid-webhooks/open.json +0 -83
  26. package/__tests__/integration/ngrok-tunnel-manager.ts +0 -88
  27. package/__tests__/integration/sendgrid-webhook-integration.test.ts +0 -272
  28. package/__tests__/integration/webhook-server.ts +0 -188
  29. package/__tests__/mocks/README.md +0 -172
  30. package/__tests__/mocks/index.ts +0 -94
  31. package/__tests__/mocks/sendgrid-api-responses.ts +0 -391
  32. package/__tests__/mocks/sendgrid-webhook-payloads.ts +0 -463
  33. package/__tests__/normalizers/MailgunNormalizer.test.ts +0 -149
  34. package/__tests__/normalizers/PostmarkNormalizer.test.ts +0 -112
  35. package/__tests__/normalizers/SESNormalizer.test.ts +0 -168
  36. package/__tests__/normalizers/SMTP2GONormalizer.test.ts +0 -83
  37. package/__tests__/normalizers/SendGridNormalizer.test.ts +0 -181
  38. package/__tests__/persistence/PersistenceAdapter.test.ts +0 -103
  39. package/jest.config.cjs +0 -38
  40. package/src/EmailWebhookEventsService.ts +0 -290
  41. package/src/analytics/AnalyticsEngine.ts +0 -230
  42. package/src/index.ts +0 -40
  43. package/src/normalizers/EventNormalizer.ts +0 -13
  44. package/src/normalizers/MailgunNormalizer.ts +0 -72
  45. package/src/normalizers/PostmarkNormalizer.ts +0 -72
  46. package/src/normalizers/SESNormalizer.ts +0 -117
  47. package/src/normalizers/SMTP2GONormalizer.ts +0 -54
  48. package/src/normalizers/SendGridNormalizer.ts +0 -63
  49. package/src/persistence/InMemoryPersistenceAdapter.ts +0 -68
  50. package/src/persistence/PersistenceAdapter.ts +0 -15
  51. package/src/types.ts +0 -261
  52. package/tsconfig.json +0 -31
@@ -1,112 +0,0 @@
1
- /*
2
- Copyright (c) 2025 Bernier LLC
3
-
4
- This file is licensed to the client under a limited-use license.
5
- The client may use and modify this code *only within the scope of the project it was delivered for*.
6
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
- */
8
-
9
- import { PostmarkNormalizer } from '../../src/normalizers/PostmarkNormalizer';
10
- import { EmailEventType, EmailProvider, WebhookPayload } from '../../src/types';
11
-
12
- describe('PostmarkNormalizer', () => {
13
- let normalizer: PostmarkNormalizer;
14
-
15
- beforeEach(() => {
16
- normalizer = new PostmarkNormalizer();
17
- });
18
-
19
- it('should normalize delivery event', () => {
20
- const webhook: WebhookPayload = {
21
- provider: EmailProvider.POSTMARK,
22
- signature: 'test-signature',
23
- payload: {
24
- RecordType: 'Delivery',
25
- MessageID: 'msg-123',
26
- Recipient: 'user@example.com',
27
- ReceivedAt: '2025-01-01T00:00:00.000Z'
28
- },
29
- headers: {}
30
- };
31
-
32
- const result = normalizer.normalize(webhook);
33
-
34
- expect(result.type).toBe(EmailEventType.DELIVERED);
35
- expect(result.recipient).toBe('user@example.com');
36
- expect(result.provider).toBe(EmailProvider.POSTMARK);
37
- expect(result.messageId).toBe('msg-123');
38
- });
39
-
40
- it('should normalize bounce event', () => {
41
- const webhook: WebhookPayload = {
42
- provider: EmailProvider.POSTMARK,
43
- signature: 'test-signature',
44
- payload: {
45
- RecordType: 'Bounce',
46
- MessageID: 'msg-123',
47
- Recipient: 'user@example.com',
48
- ReceivedAt: '2025-01-01T00:00:00.000Z',
49
- Type: 'HardBounce',
50
- TypeCode: 1,
51
- Description: 'User unknown'
52
- },
53
- headers: {}
54
- };
55
-
56
- const result = normalizer.normalize(webhook);
57
-
58
- expect(result.type).toBe(EmailEventType.BOUNCED);
59
- expect(result.metadata.bounceType).toBe('hard');
60
- expect(result.metadata.bounceReason).toBe('User unknown');
61
- });
62
-
63
- it('should normalize open event', () => {
64
- const webhook: WebhookPayload = {
65
- provider: EmailProvider.POSTMARK,
66
- signature: 'test-signature',
67
- payload: {
68
- RecordType: 'Open',
69
- MessageID: 'msg-123',
70
- Recipient: 'user@example.com',
71
- ReceivedAt: '2025-01-01T00:00:00.000Z',
72
- UserAgent: 'Mozilla/5.0',
73
- Geo: {
74
- Country: 'US',
75
- Region: 'CA',
76
- City: 'San Francisco'
77
- }
78
- },
79
- headers: {}
80
- };
81
-
82
- const result = normalizer.normalize(webhook);
83
-
84
- expect(result.type).toBe(EmailEventType.OPENED);
85
- expect(result.metadata.location).toEqual({
86
- country: 'US',
87
- region: 'CA',
88
- city: 'San Francisco'
89
- });
90
- });
91
-
92
- it('should normalize click event', () => {
93
- const webhook: WebhookPayload = {
94
- provider: EmailProvider.POSTMARK,
95
- signature: 'test-signature',
96
- payload: {
97
- RecordType: 'Click',
98
- MessageID: 'msg-123',
99
- Recipient: 'user@example.com',
100
- ReceivedAt: '2025-01-01T00:00:00.000Z',
101
- OriginalLink: 'https://example.com/link',
102
- UserAgent: 'Mozilla/5.0'
103
- },
104
- headers: {}
105
- };
106
-
107
- const result = normalizer.normalize(webhook);
108
-
109
- expect(result.type).toBe(EmailEventType.CLICKED);
110
- expect(result.metadata.url).toBe('https://example.com/link');
111
- });
112
- });
@@ -1,168 +0,0 @@
1
- /*
2
- Copyright (c) 2025 Bernier LLC
3
-
4
- This file is licensed to the client under a limited-use license.
5
- The client may use and modify this code *only within the scope of the project it was delivered for*.
6
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
- */
8
-
9
- import { SESNormalizer } from '../../src/normalizers/SESNormalizer';
10
- import { EmailEventType, EmailProvider, WebhookPayload } from '../../src/types';
11
-
12
- describe('SESNormalizer', () => {
13
- let normalizer: SESNormalizer;
14
-
15
- beforeEach(() => {
16
- normalizer = new SESNormalizer();
17
- });
18
-
19
- it('should normalize delivery event', () => {
20
- const webhook: WebhookPayload = {
21
- provider: EmailProvider.AWS_SES,
22
- signature: 'test-signature',
23
- payload: {
24
- Message: JSON.stringify({
25
- eventType: 'Delivery',
26
- mail: {
27
- messageId: 'msg-123',
28
- timestamp: '2025-01-01T00:00:00.000Z',
29
- destination: ['user@example.com']
30
- },
31
- delivery: {
32
- timestamp: '2025-01-01T00:00:00.000Z'
33
- }
34
- })
35
- },
36
- headers: {}
37
- };
38
-
39
- const result = normalizer.normalize(webhook);
40
-
41
- expect(result.type).toBe(EmailEventType.DELIVERED);
42
- expect(result.recipient).toBe('user@example.com');
43
- expect(result.provider).toBe(EmailProvider.AWS_SES);
44
- expect(result.messageId).toBe('msg-123');
45
- });
46
-
47
- it('should normalize bounce event', () => {
48
- const webhook: WebhookPayload = {
49
- provider: EmailProvider.AWS_SES,
50
- signature: 'test-signature',
51
- payload: {
52
- Message: JSON.stringify({
53
- eventType: 'Bounce',
54
- mail: {
55
- messageId: 'msg-123',
56
- timestamp: '2025-01-01T00:00:00.000Z',
57
- destination: ['user@example.com']
58
- },
59
- bounce: {
60
- bounceType: 'Permanent',
61
- bouncedRecipients: [
62
- {
63
- emailAddress: 'user@example.com',
64
- diagnosticCode: 'smtp; 550 5.1.1 user unknown'
65
- }
66
- ]
67
- }
68
- })
69
- },
70
- headers: {}
71
- };
72
-
73
- const result = normalizer.normalize(webhook);
74
-
75
- expect(result.type).toBe(EmailEventType.BOUNCED);
76
- expect(result.recipient).toBe('user@example.com');
77
- expect(result.metadata.bounceType).toBe('permanent');
78
- expect(result.metadata.bounceReason).toBe('smtp; 550 5.1.1 user unknown');
79
- });
80
-
81
- it('should normalize complaint event', () => {
82
- const webhook: WebhookPayload = {
83
- provider: EmailProvider.AWS_SES,
84
- signature: 'test-signature',
85
- payload: {
86
- Message: JSON.stringify({
87
- eventType: 'Complaint',
88
- mail: {
89
- messageId: 'msg-123',
90
- timestamp: '2025-01-01T00:00:00.000Z',
91
- destination: ['user@example.com']
92
- },
93
- complaint: {
94
- complainedRecipients: [
95
- {
96
- emailAddress: 'user@example.com'
97
- }
98
- ],
99
- complaintFeedbackType: 'abuse'
100
- }
101
- })
102
- },
103
- headers: {}
104
- };
105
-
106
- const result = normalizer.normalize(webhook);
107
-
108
- expect(result.type).toBe(EmailEventType.COMPLAINED);
109
- expect(result.recipient).toBe('user@example.com');
110
- expect(result.metadata.complaintFeedbackType).toBe('abuse');
111
- });
112
-
113
- it('should normalize open event', () => {
114
- const webhook: WebhookPayload = {
115
- provider: EmailProvider.AWS_SES,
116
- signature: 'test-signature',
117
- payload: {
118
- Message: JSON.stringify({
119
- eventType: 'Open',
120
- mail: {
121
- messageId: 'msg-123',
122
- timestamp: '2025-01-01T00:00:00.000Z',
123
- destination: ['user@example.com']
124
- },
125
- open: {
126
- ipAddress: '192.168.1.1',
127
- userAgent: 'Mozilla/5.0'
128
- }
129
- })
130
- },
131
- headers: {}
132
- };
133
-
134
- const result = normalizer.normalize(webhook);
135
-
136
- expect(result.type).toBe(EmailEventType.OPENED);
137
- expect(result.metadata.ipAddress).toBe('192.168.1.1');
138
- expect(result.metadata.userAgent).toBe('Mozilla/5.0');
139
- });
140
-
141
- it('should normalize click event', () => {
142
- const webhook: WebhookPayload = {
143
- provider: EmailProvider.AWS_SES,
144
- signature: 'test-signature',
145
- payload: {
146
- Message: JSON.stringify({
147
- eventType: 'Click',
148
- mail: {
149
- messageId: 'msg-123',
150
- timestamp: '2025-01-01T00:00:00.000Z',
151
- destination: ['user@example.com']
152
- },
153
- click: {
154
- link: 'https://example.com/link',
155
- ipAddress: '192.168.1.1',
156
- userAgent: 'Mozilla/5.0'
157
- }
158
- })
159
- },
160
- headers: {}
161
- };
162
-
163
- const result = normalizer.normalize(webhook);
164
-
165
- expect(result.type).toBe(EmailEventType.CLICKED);
166
- expect(result.metadata.url).toBe('https://example.com/link');
167
- });
168
- });
@@ -1,83 +0,0 @@
1
- /*
2
- Copyright (c) 2025 Bernier LLC
3
-
4
- This file is licensed to the client under a limited-use license.
5
- The client may use and modify this code *only within the scope of the project it was delivered for*.
6
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
- */
8
-
9
- import { SMTP2GONormalizer } from '../../src/normalizers/SMTP2GONormalizer';
10
- import { EmailEventType, EmailProvider, WebhookPayload } from '../../src/types';
11
-
12
- describe('SMTP2GONormalizer', () => {
13
- let normalizer: SMTP2GONormalizer;
14
-
15
- beforeEach(() => {
16
- normalizer = new SMTP2GONormalizer();
17
- });
18
-
19
- it('should normalize delivered event', () => {
20
- const webhook: WebhookPayload = {
21
- provider: EmailProvider.SMTP2GO,
22
- signature: 'test-signature',
23
- payload: {
24
- event: 'delivered',
25
- message_id: 'msg-123',
26
- email_id: 'email-456',
27
- rcpt_to: 'user@example.com',
28
- timestamp: '2025-01-01T00:00:00.000Z'
29
- },
30
- headers: {}
31
- };
32
-
33
- const result = normalizer.normalize(webhook);
34
-
35
- expect(result.type).toBe(EmailEventType.DELIVERED);
36
- expect(result.recipient).toBe('user@example.com');
37
- expect(result.provider).toBe(EmailProvider.SMTP2GO);
38
- expect(result.messageId).toBe('msg-123');
39
- expect(result.emailId).toBe('email-456');
40
- });
41
-
42
- it('should normalize bounce event with hard bounce', () => {
43
- const webhook: WebhookPayload = {
44
- provider: EmailProvider.SMTP2GO,
45
- signature: 'test-signature',
46
- payload: {
47
- event: 'bounce',
48
- message_id: 'msg-123',
49
- rcpt_to: 'user@example.com',
50
- timestamp: '2025-01-01T00:00:00.000Z',
51
- bounce_type: 'hard bounce',
52
- reason: 'User unknown'
53
- },
54
- headers: {}
55
- };
56
-
57
- const result = normalizer.normalize(webhook);
58
-
59
- expect(result.type).toBe(EmailEventType.BOUNCED);
60
- expect(result.metadata.bounceType).toBe('hard');
61
- expect(result.metadata.bounceReason).toBe('User unknown');
62
- });
63
-
64
- it('should normalize failed event', () => {
65
- const webhook: WebhookPayload = {
66
- provider: EmailProvider.SMTP2GO,
67
- signature: 'test-signature',
68
- payload: {
69
- event: 'failed',
70
- message_id: 'msg-123',
71
- rcpt_to: 'user@example.com',
72
- timestamp: '2025-01-01T00:00:00.000Z',
73
- reason: 'SMTP error'
74
- },
75
- headers: {}
76
- };
77
-
78
- const result = normalizer.normalize(webhook);
79
-
80
- expect(result.type).toBe(EmailEventType.FAILED);
81
- expect(result.metadata.failureReason).toBe('SMTP error');
82
- });
83
- });
@@ -1,181 +0,0 @@
1
- /*
2
- Copyright (c) 2025 Bernier LLC
3
-
4
- This file is licensed to the client under a limited-use license.
5
- The client may use and modify this code *only within the scope of the project it was delivered for*.
6
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
- */
8
-
9
- import { SendGridNormalizer } from '../../src/normalizers/SendGridNormalizer';
10
- import { EmailEventType, EmailProvider, WebhookPayload } from '../../src/types';
11
-
12
- describe('SendGridNormalizer', () => {
13
- let normalizer: SendGridNormalizer;
14
-
15
- beforeEach(() => {
16
- normalizer = new SendGridNormalizer();
17
- });
18
-
19
- it('should normalize delivered event', () => {
20
- const webhook: WebhookPayload = {
21
- provider: EmailProvider.SENDGRID,
22
- signature: 'test-signature',
23
- payload: {
24
- event: 'delivered',
25
- email: 'user@example.com',
26
- timestamp: 1234567890,
27
- sg_message_id: 'msg-123',
28
- email_id: 'email-456'
29
- },
30
- headers: {}
31
- };
32
-
33
- const result = normalizer.normalize(webhook);
34
-
35
- expect(result.type).toBe(EmailEventType.DELIVERED);
36
- expect(result.recipient).toBe('user@example.com');
37
- expect(result.provider).toBe(EmailProvider.SENDGRID);
38
- expect(result.messageId).toBe('msg-123');
39
- expect(result.emailId).toBe('email-456');
40
- expect(result.timestamp).toEqual(new Date(1234567890000));
41
- });
42
-
43
- it('should normalize open event', () => {
44
- const webhook: WebhookPayload = {
45
- provider: EmailProvider.SENDGRID,
46
- signature: 'test-signature',
47
- payload: {
48
- event: 'open',
49
- email: 'user@example.com',
50
- timestamp: 1234567890,
51
- sg_message_id: 'msg-123',
52
- useragent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) mobile'
53
- },
54
- headers: {}
55
- };
56
-
57
- const result = normalizer.normalize(webhook);
58
-
59
- expect(result.type).toBe(EmailEventType.OPENED);
60
- expect(result.metadata.deviceType).toBe('mobile');
61
- });
62
-
63
- it('should normalize click event with URL', () => {
64
- const webhook: WebhookPayload = {
65
- provider: EmailProvider.SENDGRID,
66
- signature: 'test-signature',
67
- payload: {
68
- event: 'click',
69
- email: 'user@example.com',
70
- timestamp: 1234567890,
71
- sg_message_id: 'msg-123',
72
- url: 'https://example.com/link'
73
- },
74
- headers: {}
75
- };
76
-
77
- const result = normalizer.normalize(webhook);
78
-
79
- expect(result.type).toBe(EmailEventType.CLICKED);
80
- expect(result.metadata.url).toBe('https://example.com/link');
81
- });
82
-
83
- it('should normalize bounce event with hard bounce', () => {
84
- const webhook: WebhookPayload = {
85
- provider: EmailProvider.SENDGRID,
86
- signature: 'test-signature',
87
- payload: {
88
- event: 'bounce',
89
- email: 'user@example.com',
90
- timestamp: 1234567890,
91
- sg_message_id: 'msg-123',
92
- status: '5.1.1',
93
- reason: 'User unknown'
94
- },
95
- headers: {}
96
- };
97
-
98
- const result = normalizer.normalize(webhook);
99
-
100
- expect(result.type).toBe(EmailEventType.BOUNCED);
101
- expect(result.metadata.bounceType).toBe('hard');
102
- expect(result.metadata.bounceReason).toBe('User unknown');
103
- });
104
-
105
- it('should normalize bounce event with soft bounce', () => {
106
- const webhook: WebhookPayload = {
107
- provider: EmailProvider.SENDGRID,
108
- signature: 'test-signature',
109
- payload: {
110
- event: 'bounce',
111
- email: 'user@example.com',
112
- timestamp: 1234567890,
113
- sg_message_id: 'msg-123',
114
- status: '4.2.2',
115
- reason: 'Mailbox full'
116
- },
117
- headers: {}
118
- };
119
-
120
- const result = normalizer.normalize(webhook);
121
-
122
- expect(result.type).toBe(EmailEventType.BOUNCED);
123
- expect(result.metadata.bounceType).toBe('soft');
124
- });
125
-
126
- it('should normalize spam complaint event', () => {
127
- const webhook: WebhookPayload = {
128
- provider: EmailProvider.SENDGRID,
129
- signature: 'test-signature',
130
- payload: {
131
- event: 'spamreport',
132
- email: 'user@example.com',
133
- timestamp: 1234567890,
134
- sg_message_id: 'msg-123'
135
- },
136
- headers: {}
137
- };
138
-
139
- const result = normalizer.normalize(webhook);
140
-
141
- expect(result.type).toBe(EmailEventType.COMPLAINED);
142
- });
143
-
144
- it('should detect tablet device type', () => {
145
- const webhook: WebhookPayload = {
146
- provider: EmailProvider.SENDGRID,
147
- signature: 'test-signature',
148
- payload: {
149
- event: 'open',
150
- email: 'user@example.com',
151
- timestamp: 1234567890,
152
- sg_message_id: 'msg-123',
153
- useragent: 'Mozilla/5.0 (iPad; CPU OS 14_0 like Mac OS X)'
154
- },
155
- headers: {}
156
- };
157
-
158
- const result = normalizer.normalize(webhook);
159
-
160
- expect(result.metadata.deviceType).toBe('tablet');
161
- });
162
-
163
- it('should detect desktop device type', () => {
164
- const webhook: WebhookPayload = {
165
- provider: EmailProvider.SENDGRID,
166
- signature: 'test-signature',
167
- payload: {
168
- event: 'open',
169
- email: 'user@example.com',
170
- timestamp: 1234567890,
171
- sg_message_id: 'msg-123',
172
- useragent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
173
- },
174
- headers: {}
175
- };
176
-
177
- const result = normalizer.normalize(webhook);
178
-
179
- expect(result.metadata.deviceType).toBe('desktop');
180
- });
181
- });
@@ -1,103 +0,0 @@
1
- /*
2
- Copyright (c) 2025 Bernier LLC
3
-
4
- This file is licensed to the client under a limited-use license.
5
- The client may use and modify this code *only within the scope of the project it was delivered for*.
6
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
- */
8
-
9
- import { InMemoryPersistenceAdapter } from '../../src/persistence/InMemoryPersistenceAdapter';
10
- import { EmailEvent, EmailEventType, EmailProvider } from '../../src/types';
11
-
12
- describe('InMemoryPersistenceAdapter', () => {
13
- let adapter: InMemoryPersistenceAdapter;
14
-
15
- beforeEach(() => {
16
- adapter = new InMemoryPersistenceAdapter();
17
- });
18
-
19
- const createEvent = (overrides: Partial<EmailEvent> = {}): EmailEvent => ({
20
- id: `event-${Math.random()}`,
21
- emailId: 'email-123',
22
- messageId: 'msg-123',
23
- type: EmailEventType.DELIVERED,
24
- recipient: 'user@example.com',
25
- timestamp: new Date(),
26
- provider: EmailProvider.SENDGRID,
27
- metadata: {},
28
- ...overrides
29
- });
30
-
31
- it('should save and retrieve events', async () => {
32
- const event = createEvent();
33
- await adapter.saveEvent(event);
34
-
35
- const results = await adapter.queryEvents({});
36
- expect(results).toHaveLength(1);
37
- expect(results[0].id).toBe(event.id);
38
- });
39
-
40
- it('should query events by email ID', async () => {
41
- await adapter.saveEvent(createEvent({ emailId: 'email-1' }));
42
- await adapter.saveEvent(createEvent({ emailId: 'email-2' }));
43
-
44
- const results = await adapter.queryEvents({ emailId: 'email-1' });
45
- expect(results).toHaveLength(1);
46
- expect(results[0].emailId).toBe('email-1');
47
- });
48
-
49
- it('should query events by recipient', async () => {
50
- await adapter.saveEvent(createEvent({ recipient: 'user1@example.com' }));
51
- await adapter.saveEvent(createEvent({ recipient: 'user2@example.com' }));
52
-
53
- const results = await adapter.queryEvents({ recipient: 'user1@example.com' });
54
- expect(results).toHaveLength(1);
55
- expect(results[0].recipient).toBe('user1@example.com');
56
- });
57
-
58
- it('should query events by event types', async () => {
59
- await adapter.saveEvent(createEvent({ type: EmailEventType.DELIVERED }));
60
- await adapter.saveEvent(createEvent({ type: EmailEventType.OPENED }));
61
-
62
- const results = await adapter.queryEvents({
63
- eventTypes: [EmailEventType.DELIVERED]
64
- });
65
-
66
- expect(results).toHaveLength(1);
67
- expect(results[0].type).toBe(EmailEventType.DELIVERED);
68
- });
69
-
70
- it('should query events by date range', async () => {
71
- await adapter.saveEvent(createEvent({ timestamp: new Date('2025-01-01') }));
72
- await adapter.saveEvent(createEvent({ timestamp: new Date('2025-06-01') }));
73
- await adapter.saveEvent(createEvent({ timestamp: new Date('2025-12-01') }));
74
-
75
- const results = await adapter.queryEvents({
76
- startDate: new Date('2025-05-01'),
77
- endDate: new Date('2025-07-01')
78
- });
79
-
80
- expect(results).toHaveLength(1);
81
- expect(results[0].timestamp).toEqual(new Date('2025-06-01'));
82
- });
83
-
84
- it('should apply limit and offset', async () => {
85
- await adapter.saveEvent(createEvent());
86
- await adapter.saveEvent(createEvent());
87
- await adapter.saveEvent(createEvent());
88
- await adapter.saveEvent(createEvent());
89
-
90
- const results = await adapter.queryEvents({ limit: 2, offset: 1 });
91
- expect(results).toHaveLength(2);
92
- });
93
-
94
- it('should clear all events', async () => {
95
- await adapter.saveEvent(createEvent());
96
- await adapter.saveEvent(createEvent());
97
-
98
- expect(adapter.getEventCount()).toBe(2);
99
-
100
- adapter.clearEvents();
101
- expect(adapter.getEventCount()).toBe(0);
102
- });
103
- });
package/jest.config.cjs DELETED
@@ -1,38 +0,0 @@
1
- /*
2
- Copyright (c) 2025 Bernier LLC
3
-
4
- This file is licensed to the client under a limited-use license.
5
- The client may use and modify this code *only within the scope of the project it was delivered for*.
6
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
- */
8
-
9
- module.exports = {
10
- displayName: 'email-webhook-events',
11
- preset: 'ts-jest',
12
- testEnvironment: 'node',
13
- roots: ['<rootDir>/__tests__'],
14
- testMatch: ['**/*.test.ts'],
15
- // Skip integration tests by default (require RUN_INTEGRATION_TESTS=true)
16
- testPathIgnorePatterns: ['/node_modules/', '/__tests__/integration/'],
17
- transform: {
18
- '^.+\\.tsx?$': ['ts-jest', {
19
- tsconfig: '<rootDir>/tsconfig.json',
20
- }],
21
- },
22
- moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
23
- collectCoverageFrom: [
24
- 'src/**/*.ts',
25
- '!src/**/*.d.ts',
26
- '!src/index.ts',
27
- ],
28
- coverageThreshold: {
29
- global: {
30
- branches: 68, // TODO: Increase to 85% - current: 68.35%
31
- functions: 85,
32
- lines: 85,
33
- statements: 85,
34
- },
35
- },
36
- coverageReporters: ['text', 'lcov', 'html'],
37
- };
38
-