@bymax-one/nest-notification 1.4.9 → 1.4.10
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.
- package/CHANGELOG.md +94 -1
- package/README.md +21 -11
- package/dist/server/index.cjs +216 -49
- package/dist/server/index.d.cts +27 -13
- package/dist/server/index.d.ts +27 -13
- package/dist/server/index.mjs +216 -49
- package/dist/shared/index.cjs +4 -2
- package/dist/shared/index.d.cts +4 -2
- package/dist/shared/index.d.ts +4 -2
- package/dist/shared/index.mjs +4 -2
- package/dist/testing/index.cjs +3 -2
- package/dist/testing/index.mjs +3 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -11,6 +11,98 @@ the entries that carry one, is the compatibility contract — read it, not the n
|
|
|
11
11
|
|
|
12
12
|
## [Unreleased]
|
|
13
13
|
|
|
14
|
+
## [1.4.10] - 2026-11-16
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- **A control character in a value no longer starts a second audit record.** An audit entry carries
|
|
19
|
+
values a caller chose: a recipient, a user id, an error text, an email template name. The
|
|
20
|
+
interceptor, `OtpService` and `EmailService` wrote them as they came, so a line feed in one of
|
|
21
|
+
them started a record nobody wrote in any log or store that writes lines, and a bidirectional
|
|
22
|
+
control could make a line read as another. The entry is now escaped once, where every writer's
|
|
23
|
+
entry passes: every string of it, and every key and string value of its `metadata`, reaches
|
|
24
|
+
`INotificationLogRepository.create` with the C0 and C1 controls, the Unicode line and paragraph
|
|
25
|
+
separators and the bidirectional controls written as visible sequences (`\n`, `\r`, `\t`,
|
|
26
|
+
`\uXXXX`); a key that escapes to the text of an earlier key takes a `#2`, `#3` suffix. Metadata that is nested too deep, a cycle and a value that is not a plain
|
|
27
|
+
object, an array or a primitive arrive as a fixed marker. The `BYMAX_NOTIFICATION_LOG_REPOSITORY`
|
|
28
|
+
token still resolves to the host's own repository.
|
|
29
|
+
|
|
30
|
+
- **A purpose is a short name, and anything else is refused.** `purpose` is part of every storage
|
|
31
|
+
key, of the audit entry and of the template data, and nothing checked it: it could be empty,
|
|
32
|
+
carry a newline that forges a log record, carry glob characters that make a key pattern
|
|
33
|
+
unreliable, or be as long as the caller liked. A purpose is now 1 to 64 characters from
|
|
34
|
+
`A-Z a-z 0-9 : _ -`, checked by every OTP operation and by both reference storages before a key
|
|
35
|
+
is built. The refusal is `notification.invalid_scope_identifier` (400), names the boundary and
|
|
36
|
+
the parameter and never the value. A `perPurpose` key outside that set stops the module at
|
|
37
|
+
startup. The audit interceptor, which sees the payload before the service refuses it, leaves a
|
|
38
|
+
purpose that is not a plain name out of the entry it writes. The README now says what the limits
|
|
39
|
+
are scoped on and that purposes are the host's own.
|
|
40
|
+
|
|
41
|
+
- **One recipient, one key, whatever the spelling of its domain.** Two spellings of one mailbox's
|
|
42
|
+
domain reached two keys, so each had its own resend cooldown and attempt counter. The domain of an
|
|
43
|
+
email is now given the spelling a resolver gives it (UTS #46 mapping, non-transitional): fullwidth
|
|
44
|
+
and ligature forms and the punycode form of an internationalized domain are one key, and a domain
|
|
45
|
+
the mapping would change in any other way (an address literal, a host read as an address, text
|
|
46
|
+
with URL syntax in it) keeps its own spelling, lower-cased. The local part
|
|
47
|
+
gets no Unicode normalization, because two local parts that differ in a compatibility character are
|
|
48
|
+
two mailboxes and one key for both would let a code mailed to one verify for the other; plus tags
|
|
49
|
+
stay separate keys, which the README now says, with the advice to limit per user id. A recipient
|
|
50
|
+
whose domain is not plain ASCII gets a different key, so a code issued before the upgrade is not
|
|
51
|
+
found after it.
|
|
52
|
+
|
|
53
|
+
- **A control character in a relay's reply no longer starts a second log line.** The warning an
|
|
54
|
+
SMTP or Resend send failure logs carries the reason the relay or the API gave, after the
|
|
55
|
+
credentials and declared secrets are removed from it; the startup warning for a template
|
|
56
|
+
renderer that throws carries the error's text. A line feed in that text started a record nobody
|
|
57
|
+
wrote, and a bidirectional control could make a line read as another. These lines now write the
|
|
58
|
+
same controls the audit entry does as visible sequences, after the removal, so a declared value
|
|
59
|
+
that holds a line feed is still matched as written.
|
|
60
|
+
|
|
61
|
+
- **`InMemoryOtpStorage.size()` counts the failure counters.** The helper reported the entries and
|
|
62
|
+
the cooldowns and not the failure counters, so a test asserting that nothing is left behind could
|
|
63
|
+
not see a counter that leaked; it now returns `failures` as well.
|
|
64
|
+
|
|
65
|
+
- **Resolving a template placeholder no longer reads the whole data object.** `DefaultTemplateRenderer`
|
|
66
|
+
copied every own enumerable property of the data into a new map to find one value, and a nested path
|
|
67
|
+
did it for each segment. The work grew with the size of the object,
|
|
68
|
+
and a getter on a property the template never names ran, so one that threw broke a render that did
|
|
69
|
+
not ask for it. The renderer now reads only the property that is named, and only when it is an own
|
|
70
|
+
enumerable one: the same keys resolve as before, and inherited and prototype keys stay out of reach.
|
|
71
|
+
A getter on a named key now runs each time the placeholder is read, not once per render for a flat
|
|
72
|
+
placeholder, so a getter whose value changes between reads can differ between occurrences.
|
|
73
|
+
|
|
74
|
+
#### Apply to a derived backend
|
|
75
|
+
|
|
76
|
+
A purpose is now 1 to 64 characters from `A-Z a-z 0-9 : _ -`. `OtpService.generate`, `resend`,
|
|
77
|
+
`verify`, `consume` and `getStatus`, and the keys of `RedisOtpStorage` and `InMemoryOtpStorage`,
|
|
78
|
+
refuse any other with `notification.invalid_scope_identifier` (HTTP 400), where a purpose with a
|
|
79
|
+
space, a dot, a slash, a non-ASCII character, an empty string or more than 64 characters used to
|
|
80
|
+
work. A host that used such a purpose renames it; a code issued under one before the upgrade
|
|
81
|
+
cannot be verified after it, which only matters for the minutes of its lifetime. The
|
|
82
|
+
`NOTIFICATION_PURPOSES` and any snake_case name are unaffected. A `perPurpose` key outside the
|
|
83
|
+
set now fails when the module starts. A custom `IOtpStorage` needs no change: the service checks
|
|
84
|
+
before it calls the store, and the purposes `./testing` generates for its cases now fit the
|
|
85
|
+
rule. The default message of `INVALID_SCOPE_IDENTIFIER` in
|
|
86
|
+
`NOTIFICATION_ERROR_DEFINITIONS` is a literal type in the declarations and now reads "A tenant,
|
|
87
|
+
recipient or purpose identifier is not valid" where it said "Tenant or recipient identifier does
|
|
88
|
+
not identify anybody", so a host that matched on the old text updates; matching on the `code`
|
|
89
|
+
is unaffected.
|
|
90
|
+
|
|
91
|
+
A custom `INotificationLogRepository` now receives entries in which a control character in any
|
|
92
|
+
string, or in a key or string value of `metadata`, arrives as a visible escape sequence, and a
|
|
93
|
+
subtree of `metadata` that is too deep, circular or not a plain value arrives as a marker; a host
|
|
94
|
+
whose values never contain one sees no difference. The module wraps the repository for the
|
|
95
|
+
interceptor, `OtpService` and `EmailService`; a host that builds one of them by hand with `new`
|
|
96
|
+
passes its own repository straight through and escapes in its `create`. No declaration changes.
|
|
97
|
+
|
|
98
|
+
`InMemoryOtpStorage.size()` returns a `failures` field, and the exported
|
|
99
|
+
`InMemoryStorageSize` type gains it as a required property: code that reads the result is
|
|
100
|
+
unaffected, code that builds a value of that type adds the field.
|
|
101
|
+
|
|
102
|
+
The log lines of the SMTP and Resend providers and of the template startup check now hold a
|
|
103
|
+
reason with control characters written as visible sequences; the error those providers throw
|
|
104
|
+
keeps its text as it came, so a host that logs it writes its own line and escapes it there.
|
|
105
|
+
|
|
14
106
|
## [1.4.9] - 2026-11-14
|
|
15
107
|
|
|
16
108
|
### Fixed
|
|
@@ -1176,7 +1268,8 @@ rejected at startup rather than failing on the first send.
|
|
|
1176
1268
|
|
|
1177
1269
|
[1.0.4]: https://github.com/bymaxone/nest-notification/compare/v1.0.3...v1.0.4
|
|
1178
1270
|
[1.0.3]: https://github.com/bymaxone/nest-notification/compare/v1.0.2...v1.0.3
|
|
1179
|
-
[Unreleased]: https://github.com/bymaxone/nest-notification/compare/v1.4.
|
|
1271
|
+
[Unreleased]: https://github.com/bymaxone/nest-notification/compare/v1.4.10...HEAD
|
|
1272
|
+
[1.4.10]: https://github.com/bymaxone/nest-notification/compare/v1.4.9...v1.4.10
|
|
1180
1273
|
[1.4.9]: https://github.com/bymaxone/nest-notification/compare/v1.4.8...v1.4.9
|
|
1181
1274
|
[1.4.8]: https://github.com/bymaxone/nest-notification/compare/v1.4.7...v1.4.8
|
|
1182
1275
|
[1.4.7]: https://github.com/bymaxone/nest-notification/compare/v1.4.6...v1.4.7
|
package/README.md
CHANGED
|
@@ -382,6 +382,8 @@ BymaxNotificationModule.forRoot({
|
|
|
382
382
|
|
|
383
383
|
To capture HTTP-level `sent` / `failed` entries automatically, apply `NotificationAuditInterceptor` with `@UseInterceptors(...)` on a controller or handler, or wire it globally.
|
|
384
384
|
|
|
385
|
+
**Control characters are escaped before your repository sees an entry.** An entry carries values a caller chose (a recipient, a user id, an error text, a template name), and a line feed in one of them starts a second record in a log or a store that writes lines. Every string of an entry, and every key and string value of its `metadata`, reaches `create` with the C0 and C1 controls, the Unicode line and paragraph separators and the bidirectional controls written as visible sequences (`\n`, `\r`, `\t`, `\uXXXX`); a backslash is left as it is, so a key that escapes to the text of an earlier key takes a `#2`, `#3` suffix instead of replacing it. Metadata nested too deep, a cycle, and a value that is not a plain object, an array or a primitive arrive as `[depth limit]`, `[circular]` or `[non-plain value]`. The module does this for every writer it wires, and the `BYMAX_NOTIFICATION_LOG_REPOSITORY` token still resolves to your own repository. A host that builds `OtpService`, `EmailService` or `NotificationAuditInterceptor` itself, with `new`, bypasses the wiring and has its own repository's `create` escape the strings of the entry the same way. The length of a value is not bounded here. The failure lines the library logs from text it did not write (the reason an SMTP relay or the Resend API gives, and the error a template renderer throws at startup) carry it with the same escape; the error those providers throw keeps the text as it came, and is yours to escape if you log it.
|
|
386
|
+
|
|
385
387
|
### 7. Frontend Integration (React)
|
|
386
388
|
|
|
387
389
|
The `./react` subpath is browser-only state and UX — it drives the OTP-input box and a countdown. **Verifying the code is your app's job**: the hooks carry no HTTP client and no Node builtins, so nothing about your API shape is assumed.
|
|
@@ -579,6 +581,14 @@ A code is short: a six-digit code has a million values, so a plain hash of it is
|
|
|
579
581
|
- **Changing or removing the secret** makes the digests already stored unverifiable (`invalid_code`); those codes must be requested again. Downgrading the library below the version that introduced the option does the same.
|
|
580
582
|
- A custom `IOtpStorage` is unaffected: `OtpEntry.code` is an opaque string to it.
|
|
581
583
|
|
|
584
|
+
### Which spellings share a key
|
|
585
|
+
|
|
586
|
+
The recipient is normalized before it is hashed. Surrounding whitespace is trimmed, and an email (an identifier with an ASCII `@`) is lower-cased and its domain is given the spelling the resolver gives it, so `Jane@Acme.com`, `jane@acme.com` and `jane@acme.com` (fullwidth letters) are one recipient, and so are `jane@bücher.de` and `jane@xn--bcher-kva.de`. A domain the mapping would change in any other way keeps the spelling it was written in, lower-cased: an address literal, a host a URL parser reads as an address (`0x7f.1`), and a domain with anything in it that is not part of a name. The local part gets no Unicode normalization: two local parts that differ in a compatibility character (`file` and `file`) are two mailboxes at a provider that accepts them, and one key for both would let a code mailed to one verify for the other. A plus tag is kept for the same reason of not guessing a provider's rules: `jane+1@acme.com` and `jane@acme.com` are two recipients, each with its own cooldown and attempt counter, although many providers deliver both to one mailbox. A host that must limit per mailbox limits per user id, not per recipient.
|
|
587
|
+
|
|
588
|
+
### Purposes are yours
|
|
589
|
+
|
|
590
|
+
A purpose names a flow (`email_verification`, `password_reset`): 1 to 64 characters from `A-Z a-z 0-9 : _ -`. Every OTP operation and both reference storages refuse anything else with `notification.invalid_scope_identifier` (HTTP 400), and a `perPurpose` key outside that set stops the module at startup. The refusal never carries the value. The limits of a recipient are kept per `(tenant, recipient, purpose)`, and a purpose with no `perPurpose` entry uses the defaults, so a caller who can choose the purpose can ask for a fresh cooldown and a fresh attempt counter each time. Purposes are yours: a literal from `NOTIFICATION_PURPOSES` or your own list, never taken from the request.
|
|
591
|
+
|
|
582
592
|
### Attempt ceilings and cooldowns are atomic
|
|
583
593
|
|
|
584
594
|
`consumeAttempt` is the only writer of the attempt counter, and `tryAcquireCooldown` (`SET NX EX`) is the only acquirer of the resend window — both inside the storage, in one indivisible step. A service-side `get` followed by an `update` looks equivalent and passes every sequential test, but two concurrent verifies read the same count and each writes back the same increment: five attempts become unbounded. The same shape lets two concurrent resends both pass the cooldown check.
|
|
@@ -593,7 +603,7 @@ With the default, `consumeOnVerify: false`, the entry is marked validated and st
|
|
|
593
603
|
|
|
594
604
|
A per-code counter alone lets a re-issue reset the failure count: guess wrongly up to the limit, wait out the resend cooldown, and guess again. So the failed verifications of a `(tenant, recipient, purpose)` are counted in the storage, and `verify()` refuses once that count passes the purpose's attempt ceiling, whichever code is live.
|
|
595
605
|
|
|
596
|
-
- Every verification attempt against a live code adds one to the count, before its code is compared, and restarts the counter's lifetime to the purpose's code lifetime (`ttlSeconds`); a counter that is not touched for that long lapses, which starts the count again from zero.
|
|
606
|
+
- Every verification attempt against a live code adds one to the count, before its code is compared, and restarts the counter's lifetime to the purpose's code lifetime (`ttlSeconds`); a counter that is not touched for that long lapses, which starts the count again from zero. Because every attempt restarts the lifetime, attempts spaced closer apart than `ttlSeconds` never let the counter lapse; only a success, `consume()` or `ttlSeconds` of silence resets it, which is the stricter behaviour against a slow attack.
|
|
597
607
|
- A successful verification and `consume()` clear it (the attempt that succeeded included), so the next flow starts with a full budget.
|
|
598
608
|
- Once the count passes the ceiling, `verify()` returns `{ valid: false, reason: 'max_attempts' }` for any code, a freshly issued one included, until the counter lapses. The stored count alone decides, so the lockout ends exactly when the counter lapses. Because the increment is atomic and happens first, guesses that arrive together each get their own number and only those within the ceiling are compared. `remainingAttempts` reports the nearer of the code's own budget and the count's. This also means that someone who keeps sending wrong guesses for a recipient keeps that recipient locked out, so rate-limit the OTP endpoints by IP in your controller.
|
|
599
609
|
- `RedisOtpStorage` keeps the counter under `{namespace}:otp_fail:{purpose}:{hash}`, incremented by one script; `InMemoryOtpStorage` does the same in memory.
|
|
@@ -657,7 +667,7 @@ A one-time password is a credential, so every behavior is pinned so that a regre
|
|
|
657
667
|
| Coverage | **100%** line/branch/function/statement per file (`pnpm test:cov:all`) |
|
|
658
668
|
| Mutation | Stryker score **100%** (`break: 100`), no survivors |
|
|
659
669
|
| Lint | ESLint flat config + `eslint-plugin-security`, zero warnings |
|
|
660
|
-
| Bundle budgets | server <
|
|
670
|
+
| Bundle budgets | server < 34.61 KB · shared < 4 KB · react < 8 KB · testing < 4.5 KB brotli (`pnpm size`) |
|
|
661
671
|
| Prisma-free | `pnpm check:no-prisma` — the library never imports `@prisma/client` |
|
|
662
672
|
| Export map | `pnpm check:exports` — `attw` against the packed tarball, ESM and CJS |
|
|
663
673
|
| Supply chain | published with npm provenance (OIDC), CodeQL + OpenSSF Scorecard |
|
|
@@ -732,15 +742,15 @@ pnpm mutation # Stryker mutation testing
|
|
|
732
742
|
|
|
733
743
|
### Reference adapters
|
|
734
744
|
|
|
735
|
-
| Export | Implements | Use for
|
|
736
|
-
| ------------------------------- | ---------------------------- |
|
|
737
|
-
| `ResendEmailProvider` | `IEmailProvider` | Production email via Resend
|
|
738
|
-
| `SmtpEmailProvider` | `IEmailProvider` | Any SMTP relay, and Mailpit/MailHog in tests
|
|
739
|
-
| `NoOpEmailProvider` | `IEmailProvider` | Dev/test — logs a masked recipient only
|
|
740
|
-
| `RedisOtpStorage` | `IOtpStorage` | Production OTP state (atomic via Lua)
|
|
741
|
-
| `InMemoryOtpStorage` | `IOtpStorage` | Dev/test — single-process only; `.size()`
|
|
742
|
-
| `DefaultTemplateRenderer` | `IEmailTemplateRenderer` | `{{var}}` interpolation with HTML escaping
|
|
743
|
-
| `NoOpNotificationLogRepository` | `INotificationLogRepository` | Audit configured but intentionally discarded
|
|
745
|
+
| Export | Implements | Use for |
|
|
746
|
+
| ------------------------------- | ---------------------------- | --------------------------------------------------------------- |
|
|
747
|
+
| `ResendEmailProvider` | `IEmailProvider` | Production email via Resend |
|
|
748
|
+
| `SmtpEmailProvider` | `IEmailProvider` | Any SMTP relay, and Mailpit/MailHog in tests |
|
|
749
|
+
| `NoOpEmailProvider` | `IEmailProvider` | Dev/test — logs a masked recipient only |
|
|
750
|
+
| `RedisOtpStorage` | `IOtpStorage` | Production OTP state (atomic via Lua) |
|
|
751
|
+
| `InMemoryOtpStorage` | `IOtpStorage` | Dev/test — single-process only; `.size()` reports what it holds |
|
|
752
|
+
| `DefaultTemplateRenderer` | `IEmailTemplateRenderer` | `{{var}}` interpolation with HTML escaping |
|
|
753
|
+
| `NoOpNotificationLogRepository` | `INotificationLogRepository` | Audit configured but intentionally discarded |
|
|
744
754
|
|
|
745
755
|
### Utilities
|
|
746
756
|
|
package/dist/server/index.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var common = require('@nestjs/common');
|
|
4
4
|
var crypto = require('crypto');
|
|
5
|
+
var url = require('url');
|
|
5
6
|
var rxjs = require('rxjs');
|
|
6
7
|
|
|
7
8
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -29,6 +30,7 @@ var BYMAX_NOTIFICATION_SMS_PROVIDER = /* @__PURE__ */ Symbol("BYMAX_NOTIFICATION
|
|
|
29
30
|
var BYMAX_NOTIFICATION_PUSH_PROVIDER = /* @__PURE__ */ Symbol("BYMAX_NOTIFICATION_PUSH_PROVIDER");
|
|
30
31
|
var BYMAX_NOTIFICATION_TEMPLATE_RENDERER = /* @__PURE__ */ Symbol("BYMAX_NOTIFICATION_TEMPLATE_RENDERER");
|
|
31
32
|
var BYMAX_NOTIFICATION_LOG_REPOSITORY = /* @__PURE__ */ Symbol("BYMAX_NOTIFICATION_LOG_REPOSITORY");
|
|
33
|
+
var BYMAX_NOTIFICATION_AUDIT_SINK = /* @__PURE__ */ Symbol("BYMAX_NOTIFICATION_AUDIT_SINK");
|
|
32
34
|
|
|
33
35
|
// src/server/constants/default-options.constants.ts
|
|
34
36
|
var DEFAULT_MAX_ATTACHMENT_BYTES = 10485760;
|
|
@@ -169,8 +171,10 @@ var NOTIFICATION_ERROR_CODES = {
|
|
|
169
171
|
AUDIT_LOG_FAILED: "notification.audit_log_failed",
|
|
170
172
|
CHANNEL_DISABLED: "notification.channel_disabled",
|
|
171
173
|
/**
|
|
172
|
-
* A `tenantId` or `
|
|
173
|
-
* boundary
|
|
174
|
+
* A `tenantId`, `recipient` or `purpose` that cannot scope an OTP reached a
|
|
175
|
+
* scoping boundary: empty, whitespace-only, not a string at all, carrying a
|
|
176
|
+
* control character, or, for a purpose, longer than 64 characters or made of
|
|
177
|
+
* anything but `A-Z a-z 0-9 : _ -`. Distinct from
|
|
174
178
|
* {@link EMAIL_INVALID_RECIPIENT}, which is about a malformed address rather
|
|
175
179
|
* than a value that cannot scope anything.
|
|
176
180
|
*/
|
|
@@ -313,7 +317,7 @@ var NOTIFICATION_ERROR_DEFINITIONS = {
|
|
|
313
317
|
INVALID_SCOPE_IDENTIFIER: {
|
|
314
318
|
code: NOTIFICATION_ERROR_CODES.INVALID_SCOPE_IDENTIFIER,
|
|
315
319
|
status: common.HttpStatus.BAD_REQUEST,
|
|
316
|
-
message: "
|
|
320
|
+
message: "A tenant, recipient or purpose identifier is not valid"
|
|
317
321
|
}
|
|
318
322
|
};
|
|
319
323
|
var NOTIFICATION_ERROR_DEFINITION_MAP = new Map(
|
|
@@ -378,6 +382,47 @@ var NotificationException = class extends common.HttpException {
|
|
|
378
382
|
}
|
|
379
383
|
};
|
|
380
384
|
|
|
385
|
+
// src/server/utils/tenant-scope.ts
|
|
386
|
+
var CONTROL_CHARACTER = new RegExp("\\p{Cc}", "u");
|
|
387
|
+
function refuse(owner, label, reason) {
|
|
388
|
+
return new NotificationException(
|
|
389
|
+
"INVALID_SCOPE_IDENTIFIER",
|
|
390
|
+
{ boundary: owner, parameter: label, reason },
|
|
391
|
+
{ message: `[${owner}] ${label} ${reason}` }
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
function assertIdentifies(owner, label, value) {
|
|
395
|
+
if (typeof value !== "string") {
|
|
396
|
+
throw refuse(owner, label, `expected a string, received ${typeof value}`);
|
|
397
|
+
}
|
|
398
|
+
if (value.trim() === "") {
|
|
399
|
+
throw refuse(owner, label, "empty or whitespace-only");
|
|
400
|
+
}
|
|
401
|
+
if (CONTROL_CHARACTER.test(value)) {
|
|
402
|
+
throw refuse(owner, label, "contains a control character");
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
var MAX_PURPOSE_LENGTH = 64;
|
|
406
|
+
var PURPOSE_CHARACTERS = /^[A-Za-z0-9:_-]+$/;
|
|
407
|
+
function purposeProblem(value) {
|
|
408
|
+
if (typeof value !== "string") {
|
|
409
|
+
return `expected a string, received ${typeof value}`;
|
|
410
|
+
}
|
|
411
|
+
if (value === "") {
|
|
412
|
+
return "empty";
|
|
413
|
+
}
|
|
414
|
+
if (value.length > MAX_PURPOSE_LENGTH) {
|
|
415
|
+
return `longer than ${String(MAX_PURPOSE_LENGTH)} characters`;
|
|
416
|
+
}
|
|
417
|
+
return PURPOSE_CHARACTERS.test(value) ? void 0 : "contains a character outside A-Z a-z 0-9 : _ -";
|
|
418
|
+
}
|
|
419
|
+
function assertPurpose(owner, value) {
|
|
420
|
+
const problem = purposeProblem(value);
|
|
421
|
+
if (problem !== void 0) {
|
|
422
|
+
throw refuse(owner, "purpose", problem);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
381
426
|
// src/server/config/default-options.ts
|
|
382
427
|
var VALID_CODE_TYPES = ["numeric", "alpha", "alphanumeric"];
|
|
383
428
|
var OTP_MIN_LENGTH = 1;
|
|
@@ -472,6 +517,14 @@ function validateOtpOptions(otp) {
|
|
|
472
517
|
if (otp.defaultMaxAttempts !== void 0 && otp.defaultMaxAttempts < 1) {
|
|
473
518
|
throw new Error("[BymaxNotificationModule] options.otp.defaultMaxAttempts must be at least 1");
|
|
474
519
|
}
|
|
520
|
+
for (const key of Object.keys(otp.perPurpose ?? {})) {
|
|
521
|
+
const problem = purposeProblem(key);
|
|
522
|
+
if (problem !== void 0) {
|
|
523
|
+
throw new Error(
|
|
524
|
+
`[BymaxNotificationModule] options.otp.perPurpose has the key ${JSON.stringify(key)}, which is not a valid purpose: ${problem}`
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
475
528
|
if (otp.resendCooldownSeconds !== void 0 && otp.resendCooldownSeconds < 0) {
|
|
476
529
|
throw new Error(
|
|
477
530
|
"[BymaxNotificationModule] options.otp.resendCooldownSeconds must be 0 or greater"
|
|
@@ -554,14 +607,13 @@ exports.DefaultTemplateRenderer = class DefaultTemplateRenderer {
|
|
|
554
607
|
});
|
|
555
608
|
}
|
|
556
609
|
/**
|
|
557
|
-
* Builds a variable resolver for one render call.
|
|
558
|
-
*
|
|
559
|
-
*
|
|
610
|
+
* Builds a variable resolver for one render call. A key resolves only when the object holds it as
|
|
611
|
+
* an own enumerable property, so neither flat nor nested resolution can reach inherited or
|
|
612
|
+
* prototype keys, and only the property that is named is read.
|
|
560
613
|
*/
|
|
561
614
|
buildResolver(data) {
|
|
562
615
|
if (!this.enableNestedPaths) {
|
|
563
|
-
|
|
564
|
-
return (path) => values.get(path);
|
|
616
|
+
return (path) => this.ownValue(data, path);
|
|
565
617
|
}
|
|
566
618
|
return (path) => this.resolveNested(data, path);
|
|
567
619
|
}
|
|
@@ -572,10 +624,17 @@ exports.DefaultTemplateRenderer = class DefaultTemplateRenderer {
|
|
|
572
624
|
if (current === null || current === void 0 || typeof current !== "object") {
|
|
573
625
|
return void 0;
|
|
574
626
|
}
|
|
575
|
-
current =
|
|
627
|
+
current = this.ownValue(current, key);
|
|
576
628
|
}
|
|
577
629
|
return current;
|
|
578
630
|
}
|
|
631
|
+
/**
|
|
632
|
+
* The value of `key` when `object` holds it as an own enumerable property, otherwise `undefined`.
|
|
633
|
+
* Called through `Object.prototype` so an object without a prototype works too.
|
|
634
|
+
*/
|
|
635
|
+
ownValue(object, key) {
|
|
636
|
+
return Object.prototype.propertyIsEnumerable.call(object, key) ? Reflect.get(object, key) : void 0;
|
|
637
|
+
}
|
|
579
638
|
/**
|
|
580
639
|
* Validates a registered template shape, throwing on the offending key. The
|
|
581
640
|
* optional `text` body, when present, must be a string — a non-string `text`
|
|
@@ -600,6 +659,87 @@ exports.DefaultTemplateRenderer = class DefaultTemplateRenderer {
|
|
|
600
659
|
exports.DefaultTemplateRenderer = __decorateClass([
|
|
601
660
|
common.Injectable()
|
|
602
661
|
], exports.DefaultTemplateRenderer);
|
|
662
|
+
|
|
663
|
+
// src/server/utils/audit-escape.ts
|
|
664
|
+
var MAX_METADATA_DEPTH = 4;
|
|
665
|
+
var DEPTH_LIMIT_MARKER = "[depth limit]";
|
|
666
|
+
var CIRCULAR_MARKER = "[circular]";
|
|
667
|
+
var NON_PLAIN_MARKER = "[non-plain value]";
|
|
668
|
+
var ESCAPED = /[\p{Cc}\p{Zl}\p{Zp}\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069]/gu;
|
|
669
|
+
var NAMED = /* @__PURE__ */ new Map([
|
|
670
|
+
["\n", "\\n"],
|
|
671
|
+
["\r", "\\r"],
|
|
672
|
+
[" ", "\\t"]
|
|
673
|
+
]);
|
|
674
|
+
function sequenceOf(character) {
|
|
675
|
+
return NAMED.get(character) ?? `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`;
|
|
676
|
+
}
|
|
677
|
+
function escapeAuditString(value) {
|
|
678
|
+
return value.replace(ESCAPED, sequenceOf);
|
|
679
|
+
}
|
|
680
|
+
function isPlainObject(value) {
|
|
681
|
+
const prototype = Object.getPrototypeOf(value);
|
|
682
|
+
return prototype === Object.prototype || prototype === null;
|
|
683
|
+
}
|
|
684
|
+
function escapeRecord(record, level, ancestors) {
|
|
685
|
+
const escaped = /* @__PURE__ */ new Map();
|
|
686
|
+
for (const [key, value] of Object.entries(record)) {
|
|
687
|
+
const base = escapeAuditString(key);
|
|
688
|
+
let name = base;
|
|
689
|
+
for (let attempt = 2; escaped.has(name); attempt++) {
|
|
690
|
+
name = `${base}#${attempt}`;
|
|
691
|
+
}
|
|
692
|
+
escaped.set(name, escapeValue(value, level + 1, ancestors));
|
|
693
|
+
}
|
|
694
|
+
return Object.fromEntries(escaped);
|
|
695
|
+
}
|
|
696
|
+
function escapeValue(value, level, ancestors) {
|
|
697
|
+
if (typeof value === "string") {
|
|
698
|
+
return escapeAuditString(value);
|
|
699
|
+
}
|
|
700
|
+
if (typeof value === "function" || typeof value === "symbol") {
|
|
701
|
+
return NON_PLAIN_MARKER;
|
|
702
|
+
}
|
|
703
|
+
if (typeof value !== "object" || value === null) {
|
|
704
|
+
return value;
|
|
705
|
+
}
|
|
706
|
+
if (level > MAX_METADATA_DEPTH) {
|
|
707
|
+
return DEPTH_LIMIT_MARKER;
|
|
708
|
+
}
|
|
709
|
+
if (ancestors.has(value)) {
|
|
710
|
+
return CIRCULAR_MARKER;
|
|
711
|
+
}
|
|
712
|
+
const isArray = Array.isArray(value);
|
|
713
|
+
if (!isArray && !isPlainObject(value)) {
|
|
714
|
+
return NON_PLAIN_MARKER;
|
|
715
|
+
}
|
|
716
|
+
ancestors.add(value);
|
|
717
|
+
try {
|
|
718
|
+
return isArray ? value.map((item) => escapeValue(item, level + 1, ancestors)) : escapeRecord(value, level, ancestors);
|
|
719
|
+
} finally {
|
|
720
|
+
ancestors.delete(value);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
function escapeAuditEntry(entry) {
|
|
724
|
+
return escapeRecord(
|
|
725
|
+
entry,
|
|
726
|
+
0,
|
|
727
|
+
/* @__PURE__ */ new WeakSet()
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
// src/server/providers/escaping-log-repository.ts
|
|
732
|
+
var EscapingLogRepository = class {
|
|
733
|
+
/** @param inner - The host's repository that receives the escaped entries. */
|
|
734
|
+
constructor(inner) {
|
|
735
|
+
this.inner = inner;
|
|
736
|
+
this.name = inner.name;
|
|
737
|
+
}
|
|
738
|
+
/** Writes `entry` to the wrapped repository with its strings escaped. */
|
|
739
|
+
async create(entry) {
|
|
740
|
+
await this.inner.create(escapeAuditEntry(entry));
|
|
741
|
+
}
|
|
742
|
+
};
|
|
603
743
|
exports.NoOpNotificationLogRepository = class NoOpNotificationLogRepository {
|
|
604
744
|
constructor() {
|
|
605
745
|
this.name = "noop";
|
|
@@ -1190,27 +1330,6 @@ function buildRedactedCopy(name, message, stack) {
|
|
|
1190
1330
|
return copy;
|
|
1191
1331
|
}
|
|
1192
1332
|
|
|
1193
|
-
// src/server/utils/tenant-scope.ts
|
|
1194
|
-
var CONTROL_CHARACTER = new RegExp("\\p{Cc}", "u");
|
|
1195
|
-
function refuse(owner, label, reason) {
|
|
1196
|
-
return new NotificationException(
|
|
1197
|
-
"INVALID_SCOPE_IDENTIFIER",
|
|
1198
|
-
{ boundary: owner, parameter: label, reason },
|
|
1199
|
-
{ message: `[${owner}] ${label} ${reason}` }
|
|
1200
|
-
);
|
|
1201
|
-
}
|
|
1202
|
-
function assertIdentifies(owner, label, value) {
|
|
1203
|
-
if (typeof value !== "string") {
|
|
1204
|
-
throw refuse(owner, label, `expected a string, received ${typeof value}`);
|
|
1205
|
-
}
|
|
1206
|
-
if (value.trim() === "") {
|
|
1207
|
-
throw refuse(owner, label, "empty or whitespace-only");
|
|
1208
|
-
}
|
|
1209
|
-
if (CONTROL_CHARACTER.test(value)) {
|
|
1210
|
-
throw refuse(owner, label, "contains a control character");
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
1333
|
// src/server/services/email.service.ts
|
|
1215
1334
|
var FALLBACK_LOCALE = "en";
|
|
1216
1335
|
var OTP_TEMPLATE_REMEDY = "register an 'otp_code' template (for example 'otp_code::en') in your template renderer, such as DefaultTemplateRenderer; the OTP email can use another template through the emailTemplate option of generate()";
|
|
@@ -1562,7 +1681,7 @@ exports.EmailService = __decorateClass([
|
|
|
1562
1681
|
__decorateParam(0, common.Inject(BYMAX_NOTIFICATION_OPTIONS)),
|
|
1563
1682
|
__decorateParam(1, common.Inject(BYMAX_NOTIFICATION_EMAIL_PROVIDER)),
|
|
1564
1683
|
__decorateParam(2, common.Inject(BYMAX_NOTIFICATION_TEMPLATE_RENDERER)),
|
|
1565
|
-
__decorateParam(3, common.Inject(
|
|
1684
|
+
__decorateParam(3, common.Inject(BYMAX_NOTIFICATION_AUDIT_SINK))
|
|
1566
1685
|
], exports.EmailService);
|
|
1567
1686
|
var NUMERIC = "0123456789";
|
|
1568
1687
|
var ALPHA = "ABCDEFGHJKLMNPQRSTUVWXYZ";
|
|
@@ -1626,11 +1745,31 @@ function formatCooldown(remainingSeconds) {
|
|
|
1626
1745
|
}
|
|
1627
1746
|
return parts.join(" ");
|
|
1628
1747
|
}
|
|
1629
|
-
|
|
1630
|
-
|
|
1748
|
+
var PLAIN_DOMAIN = /^[\p{L}\p{N}\p{M}_.-]+$/u;
|
|
1749
|
+
var ASCII_LABEL = new RegExp("^\\p{ASCII}*$", "u");
|
|
1750
|
+
function isLabelWiseMapping(folded, mapped) {
|
|
1751
|
+
const expected = folded.split(".").map((label) => ASCII_LABEL.test(label) ? label.toLowerCase() : null);
|
|
1752
|
+
const output = mapped.split(".");
|
|
1753
|
+
return expected.length === output.length && output.every((label, index) => {
|
|
1754
|
+
const want = expected.at(index);
|
|
1755
|
+
return want === null ? label.startsWith("xn--") : label === want;
|
|
1756
|
+
});
|
|
1757
|
+
}
|
|
1758
|
+
function normalizeDomain(domain) {
|
|
1759
|
+
const folded = domain.normalize("NFKC");
|
|
1760
|
+
if (!PLAIN_DOMAIN.test(folded)) {
|
|
1761
|
+
return domain.toLowerCase();
|
|
1762
|
+
}
|
|
1763
|
+
const mapped = url.domainToASCII(domain);
|
|
1764
|
+
return isLabelWiseMapping(folded, mapped) ? mapped : domain.toLowerCase();
|
|
1765
|
+
}
|
|
1631
1766
|
function normalizeRecipient(recipient) {
|
|
1632
1767
|
const trimmed = recipient.trim();
|
|
1633
|
-
|
|
1768
|
+
const at = trimmed.lastIndexOf("@");
|
|
1769
|
+
if (at === -1) {
|
|
1770
|
+
return trimmed;
|
|
1771
|
+
}
|
|
1772
|
+
return `${trimmed.slice(0, at).toLowerCase()}@${normalizeDomain(trimmed.slice(at + 1))}`;
|
|
1634
1773
|
}
|
|
1635
1774
|
|
|
1636
1775
|
// src/server/utils/storage-failures.ts
|
|
@@ -1971,7 +2110,7 @@ exports.OtpService = class OtpService {
|
|
|
1971
2110
|
);
|
|
1972
2111
|
} catch (error) {
|
|
1973
2112
|
this.logger.warn(
|
|
1974
|
-
`[${TEMPLATE_WARNING_CODE}] Could not check whether the email template '${DEFAULT_OTP_TEMPLATE}' resolves (${describeError(error)}); if it does not, the first generate() that delivers by email fails with TEMPLATE_NOT_FOUND.`
|
|
2113
|
+
`[${TEMPLATE_WARNING_CODE}] Could not check whether the email template '${DEFAULT_OTP_TEMPLATE}' resolves (${escapeAuditString(describeError(error))}); if it does not, the first generate() that delivers by email fails with TEMPLATE_NOT_FOUND.`
|
|
1975
2114
|
);
|
|
1976
2115
|
}
|
|
1977
2116
|
}
|
|
@@ -2106,11 +2245,12 @@ exports.OtpService = class OtpService {
|
|
|
2106
2245
|
* consumer-supplied {@link IOtpStorage} is not required to, and a blank scope would
|
|
2107
2246
|
* then be shared by every caller that sent one.
|
|
2108
2247
|
*
|
|
2109
|
-
* @throws NotificationException `INVALID_SCOPE_IDENTIFIER` when either is blank.
|
|
2248
|
+
* @throws NotificationException `INVALID_SCOPE_IDENTIFIER` when either is blank or the purpose is not a plain name.
|
|
2110
2249
|
*/
|
|
2111
2250
|
assertScope(ref) {
|
|
2112
2251
|
assertIdentifies("OtpService", "tenantId", ref.tenantId);
|
|
2113
2252
|
assertIdentifies("OtpService", "recipient", ref.recipient);
|
|
2253
|
+
assertPurpose("OtpService", ref.purpose);
|
|
2114
2254
|
}
|
|
2115
2255
|
/**
|
|
2116
2256
|
* Returns the input with its recipient replaced by the value the OTP state is keyed on.
|
|
@@ -2173,7 +2313,7 @@ exports.OtpService = __decorateClass([
|
|
|
2173
2313
|
common.Injectable(),
|
|
2174
2314
|
__decorateParam(0, common.Inject(BYMAX_NOTIFICATION_OPTIONS)),
|
|
2175
2315
|
__decorateParam(1, common.Inject(BYMAX_NOTIFICATION_OTP_STORAGE)),
|
|
2176
|
-
__decorateParam(2, common.Inject(
|
|
2316
|
+
__decorateParam(2, common.Inject(BYMAX_NOTIFICATION_AUDIT_SINK)),
|
|
2177
2317
|
__decorateParam(3, common.Optional()),
|
|
2178
2318
|
__decorateParam(3, common.Inject(exports.EmailService))
|
|
2179
2319
|
], exports.OtpService);
|
|
@@ -2432,6 +2572,7 @@ exports.BymaxNotificationModule = class BymaxNotificationModule {
|
|
|
2432
2572
|
exports: [
|
|
2433
2573
|
BYMAX_NOTIFICATION_OPTIONS,
|
|
2434
2574
|
BYMAX_NOTIFICATION_LOG_REPOSITORY,
|
|
2575
|
+
BYMAX_NOTIFICATION_AUDIT_SINK,
|
|
2435
2576
|
BYMAX_NOTIFICATION_EMAIL_PROVIDER,
|
|
2436
2577
|
BYMAX_NOTIFICATION_TEMPLATE_RENDERER,
|
|
2437
2578
|
BYMAX_NOTIFICATION_OTP_STORAGE,
|
|
@@ -2458,7 +2599,7 @@ exports.BymaxNotificationModule = class BymaxNotificationModule {
|
|
|
2458
2599
|
BYMAX_NOTIFICATION_OPTIONS,
|
|
2459
2600
|
BYMAX_NOTIFICATION_EMAIL_PROVIDER,
|
|
2460
2601
|
BYMAX_NOTIFICATION_TEMPLATE_RENDERER,
|
|
2461
|
-
|
|
2602
|
+
BYMAX_NOTIFICATION_AUDIT_SINK
|
|
2462
2603
|
]
|
|
2463
2604
|
},
|
|
2464
2605
|
{
|
|
@@ -2467,7 +2608,7 @@ exports.BymaxNotificationModule = class BymaxNotificationModule {
|
|
|
2467
2608
|
inject: [
|
|
2468
2609
|
BYMAX_NOTIFICATION_OPTIONS,
|
|
2469
2610
|
BYMAX_NOTIFICATION_OTP_STORAGE,
|
|
2470
|
-
|
|
2611
|
+
BYMAX_NOTIFICATION_AUDIT_SINK,
|
|
2471
2612
|
// Stryker disable next-line BooleanLiteral: the EmailService token is ALWAYS registered in async mode (as a factory that resolves to `undefined` when email is absent), so Nest resolves it whether optional is true or false — `optional: false` would still inject `undefined`, never throw, making the flag observationally inert here.
|
|
2472
2613
|
{ token: exports.EmailService, optional: true }
|
|
2473
2614
|
]
|
|
@@ -2498,6 +2639,7 @@ exports.BymaxNotificationModule = class BymaxNotificationModule {
|
|
|
2498
2639
|
useFactory: (raw) => raw.audit ? instantiate(raw.audit.repository) : new exports.NoOpNotificationLogRepository(),
|
|
2499
2640
|
inject: [RAW_NOTIFICATION_OPTIONS]
|
|
2500
2641
|
},
|
|
2642
|
+
auditSinkProvider(),
|
|
2501
2643
|
{
|
|
2502
2644
|
provide: BYMAX_NOTIFICATION_EMAIL_PROVIDER,
|
|
2503
2645
|
useFactory: (raw) => raw.email ? instantiate(raw.email.provider) : null,
|
|
@@ -2519,7 +2661,8 @@ exports.BymaxNotificationModule = class BymaxNotificationModule {
|
|
|
2519
2661
|
static buildProviders(options, resolved) {
|
|
2520
2662
|
const providers = [
|
|
2521
2663
|
{ provide: BYMAX_NOTIFICATION_OPTIONS, useValue: resolved },
|
|
2522
|
-
options.audit?.repository ? resolveAsProvider(BYMAX_NOTIFICATION_LOG_REPOSITORY, options.audit.repository) : { provide: BYMAX_NOTIFICATION_LOG_REPOSITORY, useClass: exports.NoOpNotificationLogRepository }
|
|
2664
|
+
options.audit?.repository ? resolveAsProvider(BYMAX_NOTIFICATION_LOG_REPOSITORY, options.audit.repository) : { provide: BYMAX_NOTIFICATION_LOG_REPOSITORY, useClass: exports.NoOpNotificationLogRepository },
|
|
2665
|
+
auditSinkProvider()
|
|
2523
2666
|
];
|
|
2524
2667
|
if (resolved.email && options.email) {
|
|
2525
2668
|
providers.push(resolveAsProvider(BYMAX_NOTIFICATION_EMAIL_PROVIDER, options.email.provider));
|
|
@@ -2561,6 +2704,13 @@ function activeChannels(resolved) {
|
|
|
2561
2704
|
}
|
|
2562
2705
|
return channels;
|
|
2563
2706
|
}
|
|
2707
|
+
function auditSinkProvider() {
|
|
2708
|
+
return {
|
|
2709
|
+
provide: BYMAX_NOTIFICATION_AUDIT_SINK,
|
|
2710
|
+
useFactory: (repository) => new EscapingLogRepository(repository),
|
|
2711
|
+
inject: [BYMAX_NOTIFICATION_LOG_REPOSITORY]
|
|
2712
|
+
};
|
|
2713
|
+
}
|
|
2564
2714
|
function resolveRenderer(renderer) {
|
|
2565
2715
|
if (renderer === void 0) {
|
|
2566
2716
|
return {
|
|
@@ -2745,15 +2895,23 @@ exports.NotificationAuditInterceptor = class NotificationAuditInterceptor {
|
|
|
2745
2895
|
}
|
|
2746
2896
|
return input.payload.recipient;
|
|
2747
2897
|
}
|
|
2748
|
-
/**
|
|
2898
|
+
/**
|
|
2899
|
+
* Extracts the audit `purpose`: the OTP purpose, or the email template name. The interceptor sees
|
|
2900
|
+
* the payload before the service refuses it and audits a refused call too, so an OTP purpose that
|
|
2901
|
+
* is not a plain name is left out of the entry: a control character in it would forge a log
|
|
2902
|
+
* record and its length is unbounded.
|
|
2903
|
+
*/
|
|
2749
2904
|
extractPurpose(input) {
|
|
2750
|
-
|
|
2905
|
+
if (input.channel !== "otp") {
|
|
2906
|
+
return input.payload.template;
|
|
2907
|
+
}
|
|
2908
|
+
return purposeProblem(input.payload.purpose) === void 0 ? input.payload.purpose : void 0;
|
|
2751
2909
|
}
|
|
2752
2910
|
};
|
|
2753
2911
|
exports.NotificationAuditInterceptor = __decorateClass([
|
|
2754
2912
|
common.Injectable(),
|
|
2755
2913
|
__decorateParam(0, common.Inject(BYMAX_NOTIFICATION_OPTIONS)),
|
|
2756
|
-
__decorateParam(1, common.Inject(
|
|
2914
|
+
__decorateParam(1, common.Inject(BYMAX_NOTIFICATION_AUDIT_SINK))
|
|
2757
2915
|
], exports.NotificationAuditInterceptor);
|
|
2758
2916
|
|
|
2759
2917
|
// src/server/constants/notification-purposes.ts
|
|
@@ -2964,7 +3122,7 @@ exports.ResendEmailProvider = class ResendEmailProvider {
|
|
|
2964
3122
|
return withCode(new Error("Resend send failed"), code);
|
|
2965
3123
|
}
|
|
2966
3124
|
const reason = this.scrubSendError(rawMessage, options);
|
|
2967
|
-
this.logger.warn(`[RESEND_SEND_FAILED] ${reason}`);
|
|
3125
|
+
this.logger.warn(`[RESEND_SEND_FAILED] ${escapeAuditString(reason)}`);
|
|
2968
3126
|
return withCode(new Error(`Resend send failed: ${reason}`), code);
|
|
2969
3127
|
}
|
|
2970
3128
|
/**
|
|
@@ -3203,7 +3361,7 @@ exports.SmtpEmailProvider = class SmtpEmailProvider {
|
|
|
3203
3361
|
return this.withheldFailure(raw, code, redactValuesList);
|
|
3204
3362
|
}
|
|
3205
3363
|
const reason = this.scrubTransportError(raw, payload, redactValuesList);
|
|
3206
|
-
this.logger.warn(`[SMTP_SEND_FAILED] ${reason}`);
|
|
3364
|
+
this.logger.warn(`[SMTP_SEND_FAILED] ${escapeAuditString(reason)}`);
|
|
3207
3365
|
return Object.assign(
|
|
3208
3366
|
new Error(`SMTP send failed: ${reason}`),
|
|
3209
3367
|
code === void 0 ? {} : { code }
|
|
@@ -3738,7 +3896,7 @@ exports.InMemoryOtpStorage = class InMemoryOtpStorage {
|
|
|
3738
3896
|
this.cooldowns.delete(this.key(tenantId, recipient, purpose));
|
|
3739
3897
|
}
|
|
3740
3898
|
/**
|
|
3741
|
-
* Test helper — wipes all entries and
|
|
3899
|
+
* Test helper — wipes all entries, cooldowns and failure counters. Not part of `IOtpStorage`.
|
|
3742
3900
|
*/
|
|
3743
3901
|
clear() {
|
|
3744
3902
|
this.store.clear();
|
|
@@ -3746,12 +3904,17 @@ exports.InMemoryOtpStorage = class InMemoryOtpStorage {
|
|
|
3746
3904
|
this.failures.clear();
|
|
3747
3905
|
}
|
|
3748
3906
|
/**
|
|
3749
|
-
* Test helper — current map sizes. Not part of `IOtpStorage`.
|
|
3907
|
+
* Test helper — current map sizes. Not part of `IOtpStorage`. Like the cooldowns, a failure
|
|
3908
|
+
* counter that has lapsed stays counted until it is read or cleared.
|
|
3750
3909
|
*
|
|
3751
|
-
* @returns The number of stored OTP entries and
|
|
3910
|
+
* @returns The number of stored OTP entries, cooldowns and failure counters.
|
|
3752
3911
|
*/
|
|
3753
3912
|
size() {
|
|
3754
|
-
return {
|
|
3913
|
+
return {
|
|
3914
|
+
otps: this.store.size,
|
|
3915
|
+
cooldowns: this.cooldowns.size,
|
|
3916
|
+
failures: this.failures.size
|
|
3917
|
+
};
|
|
3755
3918
|
}
|
|
3756
3919
|
/** The unexpired failure count for a key, dropping a lapsed counter. Synchronous. */
|
|
3757
3920
|
liveFailures(key) {
|
|
@@ -3775,6 +3938,7 @@ exports.InMemoryOtpStorage = class InMemoryOtpStorage {
|
|
|
3775
3938
|
* stays unambiguous too.
|
|
3776
3939
|
*/
|
|
3777
3940
|
key(tenantId, recipient, purpose) {
|
|
3941
|
+
assertPurpose("InMemoryOtpStorage", purpose);
|
|
3778
3942
|
return `${hashTenantRecipient(tenantId, recipient)}::${purpose}`;
|
|
3779
3943
|
}
|
|
3780
3944
|
};
|
|
@@ -3994,14 +4158,17 @@ exports.RedisOtpStorage = class RedisOtpStorage {
|
|
|
3994
4158
|
}
|
|
3995
4159
|
/** Builds the OTP entry key: `{namespace}:otp:{purpose}:{hashTenantRecipient(...)}`. */
|
|
3996
4160
|
otpKey(tenantId, recipient, purpose) {
|
|
4161
|
+
assertPurpose("RedisOtpStorage", purpose);
|
|
3997
4162
|
return `${this.namespace}:otp:${purpose}:${hashTenantRecipient(tenantId, recipient)}`;
|
|
3998
4163
|
}
|
|
3999
4164
|
/** Builds the failure-counter key: `{namespace}:otp_fail:{purpose}:{hashTenantRecipient(...)}`. */
|
|
4000
4165
|
failureKey(tenantId, recipient, purpose) {
|
|
4166
|
+
assertPurpose("RedisOtpStorage", purpose);
|
|
4001
4167
|
return `${this.namespace}:otp_fail:${purpose}:${hashTenantRecipient(tenantId, recipient)}`;
|
|
4002
4168
|
}
|
|
4003
4169
|
/** Builds the cooldown key: `{namespace}:otp_cd:{purpose}:{hashTenantRecipient(...)}`. */
|
|
4004
4170
|
cooldownKey(tenantId, recipient, purpose) {
|
|
4171
|
+
assertPurpose("RedisOtpStorage", purpose);
|
|
4005
4172
|
return `${this.namespace}:otp_cd:${purpose}:${hashTenantRecipient(tenantId, recipient)}`;
|
|
4006
4173
|
}
|
|
4007
4174
|
};
|