backend-manager 5.6.1 → 5.6.2

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 @@
1
+ {"sessionId":"c926cd91-919f-483f-bb49-db72f77f9e2e","pid":30061,"procStart":"Thu Jun 11 11:57:09 2026","acquiredAt":1781179809978}
package/CHANGELOG.md CHANGED
@@ -14,6 +14,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
14
14
  - `Fixed` for any bug fixes.
15
15
  - `Security` in case of vulnerabilities.
16
16
 
17
+ # [5.6.2] - 2026-06-11
18
+
19
+ ### Fixed
20
+ - **4 stale framework tests aligned with shipped v5.5.4–v5.5.6 validation behavior.** The default `npx mgr test` run failed 4 tests whose expectations predated intentional source changes: `test/email/validation.js` still expected all-numeric (`123456@`) and short letter+number (`a123@`) local parts to be blocked (both patterns were removed in v5.5.6 after NeverBounce confirmed real users — QQ emails, real Gmail accounts — were being blocked; tests renamed `localpart-all-numeric-allowed` / `localpart-letter-plus-numbers-allowed`) and expected the pre-v5.5.5 `DEFAULT_CHECKS`/`ALL_CHECKS` lists (now include `typo`, and `dns` in `ALL_CHECKS`); `test/routes/marketing/webhook.js`'s bounce test sent no `bounce_classification`, which v5.5.4 deliberately skips (renamed `sendgrid-hard-bounce-event-handled`, now sends `'Invalid Address'`).
21
+
22
+ ### Added
23
+ - **Suite coverage for the v5.5.5 `typo` + `dns` email validation checks** (previously only covered by the standalone `validation.test.js` script): typo-domain blocking (`gamil.com`, `gmail.con`) + correct-domain pass-through, dns-not-in-default-checks, an offline-safe dns positive (network errors skip, never block), and an extended-gated (`TEST_EXTENDED_MODE`) dns negative for nonexistent domains.
24
+ - **Suite coverage for the v5.5.4 bounce-classification filter**: `dropped` + `'Invalid Address'` revokes, technical bounce (`'Technical Failure'`) skipped, and unclassified bounce skipped — locking in that sender-side bounces never revoke recipient consent.
25
+
17
26
  # [5.6.1] - 2026-06-11
18
27
 
19
28
  ### Added
@@ -284,7 +284,7 @@ All email tests live under `test/email/`, mirroring the source at `src/manager/l
284
284
  |---|---|---|
285
285
  | `templates.js` | MJML rendering for all 4 email templates (11 tests) | No |
286
286
  | `transactional.js` | Transactional email building (assertions on output shape) | No |
287
- | `validation.js` | Email format/disposable/corporate/local-part/typo/dns checks (60+ tests) | No |
287
+ | `validation.js` | Email format/disposable/corporate/local-part/typo/dns checks (52 tests) | No |
288
288
  | `transactional-send.js` | Single transactional email send via SendGrid | Yes |
289
289
  | `campaign-send.js` | Marketing campaign send with title + CTA + discount code | Yes |
290
290
  | `feedback-and-plain-send.js` | Feedback + plain template visual test sends | Yes |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "5.6.1",
3
+ "version": "5.6.2",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * Test: Email validation library (libraries/email/validation.js)
3
- * Unit tests for format, local part, disposable domain, and mailbox checks
3
+ * Unit tests for format, local part, disposable domain, corporate domain, typo domain, DNS, and mailbox checks
4
4
  *
5
- * Format, local part, and disposable tests always run (free, regex-based).
5
+ * Format, local part, disposable, corporate, and typo tests always run (free, sync, offline-safe).
6
+ * DNS negative tests require TEST_EXTENDED_MODE (live DNS resolution).
6
7
  * Mailbox verification tests require TEST_EXTENDED_MODE + NEVERBOUNCE_API_KEY or ZEROBOUNCE_API_KEY.
7
8
  */
8
9
  const { validate, isDisposable, isCorporate, DEFAULT_CHECKS, ALL_CHECKS } = require('../../src/manager/libraries/email/validation.js');
@@ -115,15 +116,17 @@ module.exports = {
115
116
  },
116
117
 
117
118
  {
118
- name: 'localpart-all-numeric-blocked',
119
+ name: 'localpart-all-numeric-allowed',
119
120
  timeout: 5000,
120
121
 
121
122
  async run({ assert }) {
123
+ // All-numeric local parts are legitimate (QQ emails like 1549482839@qq.com,
124
+ // student IDs) — the ^\d+$ pattern was removed in v5.5.6 after NeverBounce
125
+ // confirmed real users were being blocked.
122
126
  const result = await validate('123456@gmail.com');
123
127
 
124
- assert.equal(result.valid, false, 'All-numeric local part should be blocked');
125
- assert.propertyEquals(result, 'checks.localPart.blocked', true, 'Should be flagged as blocked');
126
- assert.propertyEquals(result, 'checks.localPart.reason', 'Matches junk pattern', 'Should match junk pattern');
128
+ assert.equal(result.valid, true, 'All-numeric local part should be allowed');
129
+ assert.propertyEquals(result, 'checks.localPart.valid', true, 'localPart check should pass');
127
130
  },
128
131
  },
129
132
 
@@ -164,14 +167,17 @@ module.exports = {
164
167
  },
165
168
 
166
169
  {
167
- name: 'localpart-letter-plus-numbers-blocked',
170
+ name: 'localpart-letter-plus-numbers-allowed',
168
171
  timeout: 5000,
169
172
 
170
173
  async run({ assert }) {
174
+ // Short letter + numbers local parts are legitimate (real Gmail users like
175
+ // mi1925973, hk9526802) — the ^[a-z]{1,2}\d+$ pattern was removed in v5.5.6
176
+ // after NeverBounce confirmed real users were being blocked.
171
177
  const result = await validate('a123@gmail.com');
172
178
 
173
- assert.equal(result.valid, false, 'Single letter + numbers should be blocked');
174
- assert.propertyEquals(result, 'checks.localPart.blocked', true, 'Should be flagged as blocked');
179
+ assert.equal(result.valid, true, 'Single letter + numbers should be allowed');
180
+ assert.propertyEquals(result, 'checks.localPart.valid', true, 'localPart check should pass');
175
181
  },
176
182
  },
177
183
 
@@ -370,6 +376,49 @@ module.exports = {
370
376
  },
371
377
  },
372
378
 
379
+ // --- Typo domain checks ---
380
+
381
+ {
382
+ name: 'typo-gamil-blocked',
383
+ timeout: 5000,
384
+
385
+ async run({ assert }) {
386
+ const result = await validate('rachel.greene@gamil.com');
387
+
388
+ assert.equal(result.valid, false, 'gamil.com should be blocked as a typo of gmail.com');
389
+ assert.propertyEquals(result, 'checks.typo.valid', false, 'Typo check should fail');
390
+ assert.propertyEquals(result, 'checks.typo.matchedPrefix', 'gamil.', 'Should report the matched prefix');
391
+ assert.propertyEquals(result, 'checks.typo.reason', 'Likely misspelled domain', 'Should have human-readable reason');
392
+ },
393
+ },
394
+
395
+ {
396
+ name: 'typo-gmail-con-blocked',
397
+ timeout: 5000,
398
+
399
+ async run({ assert }) {
400
+ const result = await validate('rachel.greene@gmail.con');
401
+
402
+ assert.equal(result.valid, false, 'gmail.con should be blocked as a typo TLD');
403
+ assert.propertyEquals(result, 'checks.typo.valid', false, 'Typo check should fail');
404
+ },
405
+ },
406
+
407
+ {
408
+ name: 'typo-correct-domains-pass',
409
+ timeout: 5000,
410
+
411
+ async run({ assert }) {
412
+ const gmail = await validate('rachel.greene@gmail.com');
413
+ const hotmail = await validate('rachel.greene@hotmail.com');
414
+
415
+ assert.equal(gmail.valid, true, 'gmail.com should pass');
416
+ assert.propertyEquals(gmail, 'checks.typo.valid', true, 'Typo check should pass for gmail.com');
417
+ assert.equal(hotmail.valid, true, 'hotmail.com should pass');
418
+ assert.propertyEquals(hotmail, 'checks.typo.valid', true, 'Typo check should pass for hotmail.com');
419
+ },
420
+ },
421
+
373
422
  // --- isCorporate helper ---
374
423
 
375
424
  {
@@ -529,8 +578,51 @@ module.exports = {
529
578
  timeout: 5000,
530
579
 
531
580
  async run({ assert }) {
532
- assert.deepEqual(DEFAULT_CHECKS, ['format', 'disposable', 'corporate', 'localPart'], 'DEFAULT_CHECKS should be format + disposable + corporate + localPart');
533
- assert.deepEqual(ALL_CHECKS, ['format', 'disposable', 'corporate', 'localPart', 'mailbox'], 'ALL_CHECKS should include mailbox');
581
+ assert.deepEqual(DEFAULT_CHECKS, ['format', 'disposable', 'corporate', 'localPart', 'typo'], 'DEFAULT_CHECKS should be all free sync checks (no dns/mailbox)');
582
+ assert.deepEqual(ALL_CHECKS, ['format', 'disposable', 'corporate', 'localPart', 'typo', 'dns', 'mailbox'], 'ALL_CHECKS should add dns + mailbox');
583
+ },
584
+ },
585
+
586
+ // --- DNS check behavior ---
587
+
588
+ {
589
+ name: 'dns-not-in-default-checks',
590
+ timeout: 5000,
591
+
592
+ async run({ assert }) {
593
+ const result = await validate('rachel.greene@gmail.com');
594
+
595
+ assert.equal(result.valid, true, 'Should be valid');
596
+ assert.equal(result.checks.dns, undefined, 'DNS should not run with default checks (async/slow — opt-in)');
597
+ },
598
+ },
599
+
600
+ {
601
+ name: 'dns-valid-domain-passes',
602
+ timeout: 15000,
603
+
604
+ async run({ assert }) {
605
+ // Offline-safe: on network errors the dns check is skipped (valid stays true);
606
+ // only definitive no-MX/NXDOMAIN answers block.
607
+ const result = await validate('rachel.greene@gmail.com', { checks: ['format', 'dns'] });
608
+
609
+ assert.equal(result.valid, true, 'gmail.com should pass the DNS check');
610
+ assert.hasProperty(result, 'checks.dns', 'Should have dns check result');
611
+ },
612
+ },
613
+
614
+ {
615
+ name: 'dns-nonexistent-domain-fails',
616
+ timeout: 15000,
617
+ skip: !process.env.TEST_EXTENDED_MODE
618
+ ? 'TEST_EXTENDED_MODE not set (requires live DNS resolution)'
619
+ : false,
620
+
621
+ async run({ assert }) {
622
+ const result = await validate('rachel.greene@thisdomaindoesnotexist99887766.com', { checks: ['format', 'dns'] });
623
+
624
+ assert.equal(result.valid, false, 'Nonexistent domain should fail the DNS check');
625
+ assert.propertyEquals(result, 'checks.dns.valid', false, 'DNS check should fail');
534
626
  },
535
627
  },
536
628
 
@@ -12,6 +12,8 @@
12
12
  *
13
13
  * SendGrid processor tests:
14
14
  * - Various event types (group_unsubscribe, unsubscribe, spamreport, bounce, dropped)
15
+ * - bounce/dropped only revoke on bounce_classification='Invalid Address' (hard bounce);
16
+ * technical bounces are sender-side issues and must NOT revoke consent
15
17
  * - Email lookup → user doc mutation with source='sendgrid'
16
18
  * - Silent skip when email doesn't map to a user (shared SendGrid account scenario)
17
19
  * - Batched events processed independently
@@ -25,13 +27,14 @@ function sgEventId(name) {
25
27
  }
26
28
 
27
29
  // Helper — build a SendGrid event payload
28
- function sgEvent({ id, type, email, timestamp, asmGroupId }) {
30
+ function sgEvent({ id, type, email, timestamp, asmGroupId, bounceClassification }) {
29
31
  return {
30
32
  sg_event_id: id,
31
33
  event: type,
32
34
  email,
33
35
  timestamp: timestamp || Math.floor(Date.now() / 1000),
34
36
  ...(asmGroupId !== undefined ? { asm_group_id: asmGroupId } : {}),
37
+ ...(bounceClassification !== undefined ? { bounce_classification: bounceClassification } : {}),
35
38
  };
36
39
  }
37
40
 
@@ -167,20 +170,43 @@ module.exports = {
167
170
  },
168
171
 
169
172
  {
170
- name: 'sendgrid-bounce-event-handled',
173
+ name: 'sendgrid-hard-bounce-event-handled',
171
174
  auth: 'none',
172
175
  async run({ http, firestore, assert, accounts }) {
173
176
  const uid = accounts.basic.uid;
174
177
  const email = accounts.basic.email;
175
- const eventId = sgEventId('bounce');
178
+ const eventId = sgEventId('hard-bounce');
176
179
 
180
+ // Only hard bounces (bounce_classification='Invalid Address') revoke consent.
177
181
  const response = await http.as('none').post(
178
182
  `backend-manager/marketing/webhook?provider=sendgrid&key=${process.env.BACKEND_MANAGER_WEBHOOK_KEY}`,
179
- [sgEvent({ id: eventId, type: 'bounce', email })]
183
+ [sgEvent({ id: eventId, type: 'bounce', email, bounceClassification: 'Invalid Address' })]
184
+ );
185
+
186
+ assert.isSuccess(response);
187
+ assert.propertyEquals(response, 'data.processed', 1, 'Hard bounce should be treated as a revoke');
188
+
189
+ const userDoc = await firestore.get(`users/${uid}`);
190
+ assert.equal(userDoc?.consent?.marketing?.status, 'revoked');
191
+ },
192
+ },
193
+
194
+ {
195
+ name: 'sendgrid-dropped-hard-bounce-handled',
196
+ auth: 'none',
197
+ async run({ http, firestore, assert, accounts }) {
198
+ const uid = accounts.basic.uid;
199
+ const email = accounts.basic.email;
200
+ const eventId = sgEventId('dropped');
201
+
202
+ // 'dropped' follows the same classification filter as 'bounce'.
203
+ const response = await http.as('none').post(
204
+ `backend-manager/marketing/webhook?provider=sendgrid&key=${process.env.BACKEND_MANAGER_WEBHOOK_KEY}`,
205
+ [sgEvent({ id: eventId, type: 'dropped', email, bounceClassification: 'Invalid Address' })]
180
206
  );
181
207
 
182
208
  assert.isSuccess(response);
183
- assert.propertyEquals(response, 'data.processed', 1, 'Bounce should be treated as a revoke');
209
+ assert.propertyEquals(response, 'data.processed', 1, 'Dropped with Invalid Address should be treated as a revoke');
184
210
 
185
211
  const userDoc = await firestore.get(`users/${uid}`);
186
212
  assert.equal(userDoc?.consent?.marketing?.status, 'revoked');
@@ -189,6 +215,45 @@ module.exports = {
189
215
 
190
216
  // ─── SendGrid processor — events we ignore ───
191
217
 
218
+ {
219
+ name: 'sendgrid-technical-bounce-ignored',
220
+ auth: 'none',
221
+ async run({ http, assert, accounts }) {
222
+ const email = accounts.basic.email;
223
+ const eventId = sgEventId('technical-bounce');
224
+
225
+ // Technical bounces (DMARC, TLS, DNS) are sender-side issues — the recipient's
226
+ // mailbox is still valid, so consent must NOT be revoked.
227
+ const response = await http.as('none').post(
228
+ `backend-manager/marketing/webhook?provider=sendgrid&key=${process.env.BACKEND_MANAGER_WEBHOOK_KEY}`,
229
+ [sgEvent({ id: eventId, type: 'bounce', email, bounceClassification: 'Technical Failure' })]
230
+ );
231
+
232
+ assert.isSuccess(response, 'Should accept the request (not error) but ignore the event');
233
+ assert.propertyEquals(response, 'data.processed', 0, 'Technical bounce should not be processed');
234
+ assert.propertyEquals(response, 'data.skipped', 1, '1 event should be skipped');
235
+ },
236
+ },
237
+
238
+ {
239
+ name: 'sendgrid-bounce-without-classification-ignored',
240
+ auth: 'none',
241
+ async run({ http, assert, accounts }) {
242
+ const email = accounts.basic.email;
243
+ const eventId = sgEventId('unclassified-bounce');
244
+
245
+ // No bounce_classification — can't confirm a hard bounce, so skip.
246
+ const response = await http.as('none').post(
247
+ `backend-manager/marketing/webhook?provider=sendgrid&key=${process.env.BACKEND_MANAGER_WEBHOOK_KEY}`,
248
+ [sgEvent({ id: eventId, type: 'bounce', email })]
249
+ );
250
+
251
+ assert.isSuccess(response, 'Should accept the request (not error) but ignore the event');
252
+ assert.propertyEquals(response, 'data.processed', 0, 'Unclassified bounce should not be processed');
253
+ assert.propertyEquals(response, 'data.skipped', 1, '1 event should be skipped');
254
+ },
255
+ },
256
+
192
257
  {
193
258
  name: 'sendgrid-delivered-event-ignored',
194
259
  auth: 'none',