@bymax-one/nest-notification 1.3.1 → 1.4.1

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.
@@ -24,7 +24,14 @@ var NOTIFICATION_ERROR_CODES = {
24
24
  PUSH_PROVIDER_NOT_CONFIGURED: "notification.push_provider_not_configured",
25
25
  PUSH_SEND_FAILED: "notification.push_send_failed",
26
26
  AUDIT_LOG_FAILED: "notification.audit_log_failed",
27
- CHANNEL_DISABLED: "notification.channel_disabled"
27
+ CHANNEL_DISABLED: "notification.channel_disabled",
28
+ /**
29
+ * A `tenantId` or `recipient` that identifies nobody reached a scoping
30
+ * boundary — empty, whitespace-only, or not a string at all. Distinct from
31
+ * {@link EMAIL_INVALID_RECIPIENT}, which is about a malformed address rather
32
+ * than a value that cannot scope anything.
33
+ */
34
+ INVALID_SCOPE_IDENTIFIER: "notification.invalid_scope_identifier"
28
35
  };
29
36
 
30
37
  // src/shared/constants/default-ttls.ts
@@ -74,8 +74,8 @@ interface NotificationErrorResponse {
74
74
  * Stable error-code identifiers, keyed by their symbolic name.
75
75
  *
76
76
  * Values are namespaced under `notification.*` and never change once published —
77
- * consumers branch on them to localize messages. The 22 entries cover the email,
78
- * template, OTP, SMS, push, audit, and channel-config failure surfaces.
77
+ * consumers branch on them to localize messages. The 23 entries cover the email,
78
+ * template, OTP, SMS, push, audit, channel-config and scoping failure surfaces.
79
79
  */
80
80
  declare const NOTIFICATION_ERROR_CODES: {
81
81
  readonly EMAIL_PROVIDER_NOT_CONFIGURED: "notification.email_provider_not_configured";
@@ -101,6 +101,13 @@ declare const NOTIFICATION_ERROR_CODES: {
101
101
  readonly PUSH_SEND_FAILED: "notification.push_send_failed";
102
102
  readonly AUDIT_LOG_FAILED: "notification.audit_log_failed";
103
103
  readonly CHANNEL_DISABLED: "notification.channel_disabled";
104
+ /**
105
+ * A `tenantId` or `recipient` that identifies nobody reached a scoping
106
+ * boundary — empty, whitespace-only, or not a string at all. Distinct from
107
+ * {@link EMAIL_INVALID_RECIPIENT}, which is about a malformed address rather
108
+ * than a value that cannot scope anything.
109
+ */
110
+ readonly INVALID_SCOPE_IDENTIFIER: "notification.invalid_scope_identifier";
104
111
  };
105
112
  /**
106
113
  * The literal-union type of every value in {@link NOTIFICATION_ERROR_CODES}.
@@ -135,4 +142,5 @@ declare const DEFAULT_TTLS: {
135
142
  readonly OTP_GENERIC_SECONDS: 600;
136
143
  };
137
144
 
138
- export { DEFAULT_TTLS, NOTIFICATION_ERROR_CODES, type NotificationChannel, type NotificationErrorCode, type NotificationErrorResponse, type OtpPurpose };
145
+ export { DEFAULT_TTLS, NOTIFICATION_ERROR_CODES };
146
+ export type { NotificationChannel, NotificationErrorCode, NotificationErrorResponse, OtpPurpose };
@@ -74,8 +74,8 @@ interface NotificationErrorResponse {
74
74
  * Stable error-code identifiers, keyed by their symbolic name.
75
75
  *
76
76
  * Values are namespaced under `notification.*` and never change once published —
77
- * consumers branch on them to localize messages. The 22 entries cover the email,
78
- * template, OTP, SMS, push, audit, and channel-config failure surfaces.
77
+ * consumers branch on them to localize messages. The 23 entries cover the email,
78
+ * template, OTP, SMS, push, audit, channel-config and scoping failure surfaces.
79
79
  */
80
80
  declare const NOTIFICATION_ERROR_CODES: {
81
81
  readonly EMAIL_PROVIDER_NOT_CONFIGURED: "notification.email_provider_not_configured";
@@ -101,6 +101,13 @@ declare const NOTIFICATION_ERROR_CODES: {
101
101
  readonly PUSH_SEND_FAILED: "notification.push_send_failed";
102
102
  readonly AUDIT_LOG_FAILED: "notification.audit_log_failed";
103
103
  readonly CHANNEL_DISABLED: "notification.channel_disabled";
104
+ /**
105
+ * A `tenantId` or `recipient` that identifies nobody reached a scoping
106
+ * boundary — empty, whitespace-only, or not a string at all. Distinct from
107
+ * {@link EMAIL_INVALID_RECIPIENT}, which is about a malformed address rather
108
+ * than a value that cannot scope anything.
109
+ */
110
+ readonly INVALID_SCOPE_IDENTIFIER: "notification.invalid_scope_identifier";
104
111
  };
105
112
  /**
106
113
  * The literal-union type of every value in {@link NOTIFICATION_ERROR_CODES}.
@@ -135,4 +142,5 @@ declare const DEFAULT_TTLS: {
135
142
  readonly OTP_GENERIC_SECONDS: 600;
136
143
  };
137
144
 
138
- export { DEFAULT_TTLS, NOTIFICATION_ERROR_CODES, type NotificationChannel, type NotificationErrorCode, type NotificationErrorResponse, type OtpPurpose };
145
+ export { DEFAULT_TTLS, NOTIFICATION_ERROR_CODES };
146
+ export type { NotificationChannel, NotificationErrorCode, NotificationErrorResponse, OtpPurpose };
@@ -22,7 +22,14 @@ var NOTIFICATION_ERROR_CODES = {
22
22
  PUSH_PROVIDER_NOT_CONFIGURED: "notification.push_provider_not_configured",
23
23
  PUSH_SEND_FAILED: "notification.push_send_failed",
24
24
  AUDIT_LOG_FAILED: "notification.audit_log_failed",
25
- CHANNEL_DISABLED: "notification.channel_disabled"
25
+ CHANNEL_DISABLED: "notification.channel_disabled",
26
+ /**
27
+ * A `tenantId` or `recipient` that identifies nobody reached a scoping
28
+ * boundary — empty, whitespace-only, or not a string at all. Distinct from
29
+ * {@link EMAIL_INVALID_RECIPIENT}, which is about a malformed address rather
30
+ * than a value that cannot scope anything.
31
+ */
32
+ INVALID_SCOPE_IDENTIFIER: "notification.invalid_scope_identifier"
26
33
  };
27
34
 
28
35
  // src/shared/constants/default-ttls.ts
@@ -20,7 +20,14 @@ function makeScope() {
20
20
  recipient: `${run}_${RECIPIENT_LOCAL}`,
21
21
  absentRecipient: `${run}_${ABSENT_LOCAL}`,
22
22
  purpose: `${KEY_PREFIX}_${run}_${PURPOSE_MAIN}`,
23
- otherPurpose: `${KEY_PREFIX}_${run}_${PURPOSE_OTHER}`
23
+ otherPurpose: `${KEY_PREFIX}_${run}_${PURPOSE_OTHER}`,
24
+ // Same characters, two different (tenant, recipient) splits. A key built by
25
+ // joining the raw values around `:` maps both onto one string, and so does one
26
+ // built around `::`, which the single-colon pair alone does not expose.
27
+ boundaryShifts: [
28
+ { left: [`${KEY_PREFIX}_${run}_x:y`, "z"], right: [`${KEY_PREFIX}_${run}_x`, "y:z"] },
29
+ { left: [`${KEY_PREFIX}_${run}_x::y`, "z"], right: [`${KEY_PREFIX}_${run}_x`, "y::z"] }
30
+ ]
24
31
  };
25
32
  }
26
33
  var DEFAULT_EXPIRY_WAIT_MS = 1500;
@@ -50,6 +57,10 @@ async function cleanUp(storage, scope) {
50
57
  await storage.delete(tenant, scope.absentRecipient, purpose);
51
58
  await storage.clearCooldown(tenant, scope.absentRecipient, purpose);
52
59
  }
60
+ for (const [tenant, recipient] of scope.boundaryShifts.flatMap((s) => [s.left, s.right])) {
61
+ await storage.delete(tenant, recipient, scope.purpose);
62
+ await storage.clearCooldown(tenant, recipient, scope.purpose);
63
+ }
53
64
  }
54
65
  function roundTripCase({ scope, withStorage }) {
55
66
  return {
@@ -370,6 +381,40 @@ function cooldownAtomicCase({ scope, withStorage }) {
370
381
  })
371
382
  };
372
383
  }
384
+ function keyBoundaryCase({ scope, withStorage }) {
385
+ return {
386
+ name: "keeps the tenant and recipient boundary when composing a key",
387
+ run: () => withStorage(async (storage) => {
388
+ for (const { left, right } of scope.boundaryShifts) {
389
+ await storage.set(left[0], left[1], scope.purpose, makeEntry(6e4));
390
+ const bled = await storage.get(right[0], right[1], scope.purpose);
391
+ check(
392
+ bled === null,
393
+ "an entry written for one tenant was readable by another whose id and recipient differ only in where the boundary falls \u2014 the key concatenates the two fields without encoding the split, so one tenant can read and consume another OTP. Hash or length-prefix each field before joining; no digest strength repairs it"
394
+ );
395
+ }
396
+ })
397
+ };
398
+ }
399
+ function cooldownKeyBoundaryCase({ scope, withStorage }) {
400
+ return {
401
+ name: "keeps the tenant and recipient boundary when composing a cooldown key",
402
+ run: () => withStorage(async (storage) => {
403
+ for (const { left, right } of scope.boundaryShifts) {
404
+ const held = await storage.tryAcquireCooldown(left[0], left[1], scope.purpose, 60);
405
+ check(
406
+ held,
407
+ "the first cooldown could not be acquired, so this case proves nothing about boundary encoding \u2014 a case that cannot fail is decoration"
408
+ );
409
+ const other = await storage.tryAcquireCooldown(right[0], right[1], scope.purpose, 60);
410
+ check(
411
+ other,
412
+ "a cooldown held for one tenant blocked another whose id and recipient differ only in where the boundary falls \u2014 the cooldown key concatenates the two fields without encoding the split, so one tenant can suppress another resends. The entry key and the cooldown key are composed separately and both need this"
413
+ );
414
+ }
415
+ })
416
+ };
417
+ }
373
418
  var CASE_BUILDERS = [
374
419
  roundTripCase,
375
420
  absentCase,
@@ -389,7 +434,9 @@ var CASE_BUILDERS = [
389
434
  cooldownTenantScopeCase,
390
435
  cooldownRecipientScopeCase,
391
436
  cooldownPurposeScopeCase,
392
- cooldownAtomicCase
437
+ cooldownAtomicCase,
438
+ keyBoundaryCase,
439
+ cooldownKeyBoundaryCase
393
440
  ];
394
441
  function otpStorageContract(factory, options = {}) {
395
442
  const scope = makeScope();
@@ -171,4 +171,5 @@ interface OtpStorageContractOptions {
171
171
  */
172
172
  declare function otpStorageContract(factory: OtpStorageFactory, options?: OtpStorageContractOptions): OtpStorageContractCase[];
173
173
 
174
- export { type OtpStorageContractCase, type OtpStorageContractOptions, type OtpStorageFactory, otpStorageContract };
174
+ export { otpStorageContract };
175
+ export type { OtpStorageContractCase, OtpStorageContractOptions, OtpStorageFactory };
@@ -171,4 +171,5 @@ interface OtpStorageContractOptions {
171
171
  */
172
172
  declare function otpStorageContract(factory: OtpStorageFactory, options?: OtpStorageContractOptions): OtpStorageContractCase[];
173
173
 
174
- export { type OtpStorageContractCase, type OtpStorageContractOptions, type OtpStorageFactory, otpStorageContract };
174
+ export { otpStorageContract };
175
+ export type { OtpStorageContractCase, OtpStorageContractOptions, OtpStorageFactory };
@@ -18,7 +18,14 @@ function makeScope() {
18
18
  recipient: `${run}_${RECIPIENT_LOCAL}`,
19
19
  absentRecipient: `${run}_${ABSENT_LOCAL}`,
20
20
  purpose: `${KEY_PREFIX}_${run}_${PURPOSE_MAIN}`,
21
- otherPurpose: `${KEY_PREFIX}_${run}_${PURPOSE_OTHER}`
21
+ otherPurpose: `${KEY_PREFIX}_${run}_${PURPOSE_OTHER}`,
22
+ // Same characters, two different (tenant, recipient) splits. A key built by
23
+ // joining the raw values around `:` maps both onto one string, and so does one
24
+ // built around `::`, which the single-colon pair alone does not expose.
25
+ boundaryShifts: [
26
+ { left: [`${KEY_PREFIX}_${run}_x:y`, "z"], right: [`${KEY_PREFIX}_${run}_x`, "y:z"] },
27
+ { left: [`${KEY_PREFIX}_${run}_x::y`, "z"], right: [`${KEY_PREFIX}_${run}_x`, "y::z"] }
28
+ ]
22
29
  };
23
30
  }
24
31
  var DEFAULT_EXPIRY_WAIT_MS = 1500;
@@ -48,6 +55,10 @@ async function cleanUp(storage, scope) {
48
55
  await storage.delete(tenant, scope.absentRecipient, purpose);
49
56
  await storage.clearCooldown(tenant, scope.absentRecipient, purpose);
50
57
  }
58
+ for (const [tenant, recipient] of scope.boundaryShifts.flatMap((s) => [s.left, s.right])) {
59
+ await storage.delete(tenant, recipient, scope.purpose);
60
+ await storage.clearCooldown(tenant, recipient, scope.purpose);
61
+ }
51
62
  }
52
63
  function roundTripCase({ scope, withStorage }) {
53
64
  return {
@@ -368,6 +379,40 @@ function cooldownAtomicCase({ scope, withStorage }) {
368
379
  })
369
380
  };
370
381
  }
382
+ function keyBoundaryCase({ scope, withStorage }) {
383
+ return {
384
+ name: "keeps the tenant and recipient boundary when composing a key",
385
+ run: () => withStorage(async (storage) => {
386
+ for (const { left, right } of scope.boundaryShifts) {
387
+ await storage.set(left[0], left[1], scope.purpose, makeEntry(6e4));
388
+ const bled = await storage.get(right[0], right[1], scope.purpose);
389
+ check(
390
+ bled === null,
391
+ "an entry written for one tenant was readable by another whose id and recipient differ only in where the boundary falls \u2014 the key concatenates the two fields without encoding the split, so one tenant can read and consume another OTP. Hash or length-prefix each field before joining; no digest strength repairs it"
392
+ );
393
+ }
394
+ })
395
+ };
396
+ }
397
+ function cooldownKeyBoundaryCase({ scope, withStorage }) {
398
+ return {
399
+ name: "keeps the tenant and recipient boundary when composing a cooldown key",
400
+ run: () => withStorage(async (storage) => {
401
+ for (const { left, right } of scope.boundaryShifts) {
402
+ const held = await storage.tryAcquireCooldown(left[0], left[1], scope.purpose, 60);
403
+ check(
404
+ held,
405
+ "the first cooldown could not be acquired, so this case proves nothing about boundary encoding \u2014 a case that cannot fail is decoration"
406
+ );
407
+ const other = await storage.tryAcquireCooldown(right[0], right[1], scope.purpose, 60);
408
+ check(
409
+ other,
410
+ "a cooldown held for one tenant blocked another whose id and recipient differ only in where the boundary falls \u2014 the cooldown key concatenates the two fields without encoding the split, so one tenant can suppress another resends. The entry key and the cooldown key are composed separately and both need this"
411
+ );
412
+ }
413
+ })
414
+ };
415
+ }
371
416
  var CASE_BUILDERS = [
372
417
  roundTripCase,
373
418
  absentCase,
@@ -387,7 +432,9 @@ var CASE_BUILDERS = [
387
432
  cooldownTenantScopeCase,
388
433
  cooldownRecipientScopeCase,
389
434
  cooldownPurposeScopeCase,
390
- cooldownAtomicCase
435
+ cooldownAtomicCase,
436
+ keyBoundaryCase,
437
+ cooldownKeyBoundaryCase
391
438
  ];
392
439
  function otpStorageContract(factory, options = {}) {
393
440
  const scope = makeScope();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bymax-one/nest-notification",
3
- "version": "1.3.1",
3
+ "version": "1.4.1",
4
4
  "description": "Multi-channel notification library for NestJS — email, OTP, SMS, push — with pluggable providers and storage, multi-tenant by design, zero runtime dependencies.",
5
5
  "author": "Bymax One <support@bymax.one>",
6
6
  "license": "MIT",
@@ -86,8 +86,8 @@
86
86
  "check:no-prisma": "grep -rq '@prisma/client' src; s=$?; [ $s -eq 1 ] && exit 0; [ $s -eq 0 ] && { echo check:no-prisma: found @prisma/client import in src/; exit 1; }; echo check:no-prisma: grep failed with exit $s; exit $s",
87
87
  "check:published": "node scripts/check-published-surface.mjs",
88
88
  "clean": "rm -rf dist coverage",
89
- "lint": "eslint src scripts test",
90
- "lint:fix": "eslint src scripts test --fix",
89
+ "lint": "eslint src scripts test --max-warnings 0",
90
+ "lint:fix": "eslint src scripts test --fix --max-warnings 0",
91
91
  "mutation": "stryker run",
92
92
  "mutation:full": "node -e \"require('node:fs').rmSync('reports/stryker-incremental.json',{force:true,recursive:true})\" && stryker run",
93
93
  "mutation:dry-run": "stryker run --dryRunOnly",
@@ -117,11 +117,11 @@
117
117
  "@aws-sdk/client-ses": "^3.0.0",
118
118
  "@aws-sdk/client-sns": "^3.0.0",
119
119
  "mailgun.js": "^11.0.0 || ^12.0.0 || ^13.0.0",
120
- "nodemailer": "^9.0.1",
120
+ "nodemailer": "^10.1.4",
121
121
  "twilio": "^5.0.0 || ^6.0.0",
122
122
  "firebase-admin": "^13.0.0 || ^14.0.0",
123
123
  "@aws-sdk/client-dynamodb": "^3.0.0",
124
- "handlebars": "^4.7.9",
124
+ "handlebars": "^4.7.10",
125
125
  "@react-email/render": "^1.0.0 || ^2.0.0",
126
126
  "mjml": "^5.0.0",
127
127
  "class-validator": "^0.14.0 || ^0.15.0",
@@ -190,7 +190,7 @@
190
190
  "@arethetypeswrong/cli": "^0.18.5",
191
191
  "@commitlint/cli": "^21.2.1",
192
192
  "@commitlint/config-conventional": "^21.2.0",
193
- "@eslint/js": "^9.39.4",
193
+ "@eslint/js": "^10.0.1",
194
194
  "@nestjs/common": "^11.1.20",
195
195
  "@nestjs/core": "^11.1.20",
196
196
  "@nestjs/testing": "^11.1.20",
@@ -204,10 +204,10 @@
204
204
  "@types/react": "^19",
205
205
  "@typescript-eslint/eslint-plugin": "^8.59.3",
206
206
  "@typescript-eslint/parser": "^8.59.3",
207
- "eslint": "^9.39.4",
207
+ "eslint": "^10.9.1",
208
208
  "eslint-config-prettier": "^10.1.8",
209
209
  "eslint-import-resolver-typescript": "^4.4.4",
210
- "eslint-plugin-import": "^2.32.0",
210
+ "eslint-plugin-import-x": "^4.17.1",
211
211
  "eslint-plugin-prettier": "^5.5.5",
212
212
  "eslint-plugin-security": "^4.0.0",
213
213
  "globals": "^17.6.0",
@@ -222,7 +222,7 @@
222
222
  "rxjs": "^7.8.0",
223
223
  "ts-jest": "^29.4.11",
224
224
  "ts-node": "^10.9.2",
225
- "tsup": "^8.5.1",
225
+ "tsup": "^9.0.0",
226
226
  "typescript": "^5.9.3"
227
227
  },
228
228
  "keywords": [