@bymax-one/nest-auth 1.5.9 → 1.5.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 CHANGED
@@ -18,6 +18,48 @@ what moves, and that note is the compatibility contract until strict SemVer begi
18
18
 
19
19
  ## [Unreleased]
20
20
 
21
+ ## [1.5.10] - 2026-11-18
22
+
23
+ A patch release.
24
+
25
+ ### Fixed
26
+
27
+ - **A flag that is not `true` or `false`, and an option that is not one of its documented values, are refused at startup.**
28
+ A flag is read as `if (x)` in some places and `=== false` in others, so a value that is neither was decided by whichever
29
+ reader saw it: `rateLimit.enabled: ''` (an unset environment variable) switched the rate-limit guard off while the boot
30
+ check still read it as enabled, `emailVerification.required: ''` let login skip the verification, and `'false'` was
31
+ truthy. An option compared with `===` fell through to its default branch on a typo: `environment: 'prodution'` was read
32
+ as not production and dropped `Secure` from every cookie with no error, a misspelled `tokenDelivery` issued cookies, and a
33
+ misspelled `passwordReset.method` silently used the token flow. Every flag (a `controllers` flag passed to
34
+ `registerAsync` included; `workspaces.allowCreate` may also be a function) must be exactly `true` or `false`, and an
35
+ option with a documented set of values must be one of them, with no case folding. The refusal
36
+ names the type of a string and never prints it. A spec reads the option interfaces and fails when a new flag or
37
+ documented-set option is declared and not listed in the validator.
38
+ - `registerAsync` inspects the hooks and the email provider when they are ready-made `useValue` objects: a hook that is
39
+ present and not a function, and an email provider without a method the library calls unguarded, are refused when it is
40
+ called instead of at the first event that fires them. A class, a factory or an alias is not inspected.
41
+
42
+ - `oauth` and `roles` are read by property access too, so a typed configuration class whose `hierarchy`, `platformHierarchy`
43
+ or provider block is a getter on its prototype takes effect. 1.5.9 read the fixed-key groups that way and left these two
44
+ as given, so a class with such a getter reached the validators with no hierarchy or no provider block: startup failed
45
+ or OAuth stayed unconfigured, never a looser setting. A `null` in either is still refused by name.
46
+ - `jwt.accessExpiresIn`'s refusals no longer quote the value: the unreadable case names the type received and the
47
+ too-long case states the lifetime in seconds.
48
+
49
+ ### Apply to a derived backend
50
+
51
+ A configuration that booted before is refused at startup when it sets a flag or an option with a documented set of values to
52
+ anything else. `undefined` and `null` still mean the default. An environment variable must be converted before it is passed
53
+ (`process.env.X === 'true'`), and `environment` must be spelled exactly as documented. A
54
+ `BYMAX_AUTH_EMAIL_PROVIDER` registered as an object needs the email methods the library calls without a guard; the
55
+ other methods stay optional, and one that is present must be a function.
56
+
57
+ Also refused at `registerAsync`: a `BYMAX_AUTH_EMAIL_PROVIDER` `useValue`, or a `BYMAX_AUTH_HOOKS` one that is not nullish, that is not an object, and a
58
+ hook (any of the hooks the library calls by name) that is present and not a function. A `null` hook counts as absent.
59
+ A `controllers` flag passed to `registerAsync` is checked like every other flag, and a `null` flag is unset.
60
+ `workspaces.allowCreate` may be `true`, `false` or a function. A refusal of `jwt.accessExpiresIn` has new wording; a test
61
+ or a log filter that matches the old text must change.
62
+
21
63
  ## [1.5.9] - 2026-11-17
22
64
 
23
65
  A patch release.
@@ -5335,7 +5377,8 @@ ever installable.
5335
5377
  - Phase 4 password-reset tests cover: both `token` and `otp` flows, mutual exclusivity validation, `verifiedToken` exchange, resend cooldown, anti-enumeration (no error on unknown email), and session invalidation on reset
5336
5378
  - Phase 5 tests cover: platform login with MFA path and brute-force lockout, `JwtPlatformGuard` cross-context rejection, `PlatformRolesGuard` hierarchy enforcement, OAuth CSRF state lifecycle, `onOAuthLogin` hook resolution strategies, and invitation role-authorization + acceptance single-use enforcement
5337
5379
 
5338
- [Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.5.9...HEAD
5380
+ [Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.5.10...HEAD
5381
+ [1.5.10]: https://github.com/bymaxone/nest-auth/compare/v1.5.9...v1.5.10
5339
5382
  [1.5.9]: https://github.com/bymaxone/nest-auth/compare/v1.5.8...v1.5.9
5340
5383
  [1.5.8]: https://github.com/bymaxone/nest-auth/compare/v1.5.7...v1.5.8
5341
5384
  [1.5.7]: https://github.com/bymaxone/nest-auth/compare/v1.5.6...v1.5.7
package/README.md CHANGED
@@ -307,6 +307,8 @@ export class PrismaUserRepository implements IUserRepository {
307
307
 
308
308
  Email delivery is fully delegated to the consumer — the library never imports a mailer SDK. Implement `IEmailProvider` with your transport of choice (Resend, SendGrid, SES, Nodemailer) and bind it to the `BYMAX_AUTH_EMAIL_PROVIDER` token.
309
309
 
310
+ When the provider (or the `BYMAX_AUTH_HOOKS` object) is registered as a ready-made `useValue` object, `registerAsync` checks it when it is called: each member the library calls by name that is present must be a function (any other member of the object is yours and is not looked at), and the provider must carry the methods the library calls without a guard: `sendPasswordResetToken`, `sendPasswordResetOtp`, `sendEmailVerificationOtp`, `sendMfaEnabledNotification`, `sendMfaDisabledNotification` and `sendInvitation`. A class, a factory or an alias is not inspected.
311
+
310
312
  > [!WARNING]
311
313
  > Any user-supplied value (display name, tenant name, inviter name) interpolated into HTML email bodies MUST be escaped to prevent stored XSS in notification content. Tokens and OTPs are library-generated and safe, but `inviterName`, `tenantName`, device strings, and any consumer-supplied placeholder are attacker-controllable.
312
314
 
@@ -807,6 +809,8 @@ All options are configurable via `registerAsync()`. Here are the key configurati
807
809
 
808
810
  An option that is omitted, or that holds `undefined` or `null`, is unset and takes its default; it never means "no limit". To switch
809
811
  a cap off, use the documented value (`0` for `jwt.absoluteSessionLifetimeDays`), not an absent one. A host-defined map or a required value (`oauth.<provider>`, the `oauth` redirect URLs, `roles.hierarchy.<role>`, `workspaces.permissions.<action>`) refuses `null` by name.
812
+ A flag must be exactly `true` or `false` (`workspaces.allowCreate` may also be a function), and an option with a documented set of values exactly one of them: anything else, an empty string and `'false'` included, is
813
+ refused at startup naming the option, never read as off or as a default.
810
814
 
811
815
  > [!NOTE]
812
816
  > When a feature is not enabled (e.g., `mfa`, `sessions`, `platform`), its controllers and services are **not registered** in the NestJS container — zero overhead. A feature is enabled by `controllers.<name>: true` on the `registerAsync()` call together with its configuration group (`mfa.encryptionKey` and `mfa.issuer`, `sessions.enabled`, `platform.enabled`); either half alone leaves it unregistered or fails at startup.
@@ -27,6 +27,193 @@ var BYMAX_AUTH_API_KEY_CLOCK = /* @__PURE__ */ Symbol("BYMAX_AUTH_API_KEY_CLOCK"
27
27
  var BYMAX_AUTH_WORKSPACE_REPOSITORY = /* @__PURE__ */ Symbol("BYMAX_AUTH_WORKSPACE_REPOSITORY");
28
28
  var BYMAX_AUTH_MEMBERSHIP_REPOSITORY = /* @__PURE__ */ Symbol("BYMAX_AUTH_MEMBERSHIP_REPOSITORY");
29
29
 
30
+ // src/server/config/describe-received.ts
31
+ function describeReceived(value) {
32
+ if (typeof value === "number") return String(value);
33
+ if (value === null || value === void 0) return String(value);
34
+ if (Array.isArray(value)) return "an array";
35
+ const kind = typeof value;
36
+ return `${kind === "object" ? "an" : "a"} ${kind}`;
37
+ }
38
+ __name(describeReceived, "describeReceived");
39
+
40
+ // src/server/config/enum-boolean-options.ts
41
+ var BOOLEAN_OPTIONS = [
42
+ "secureCookies",
43
+ "enforceTenantBinding",
44
+ "sessions.enabled",
45
+ "emailVerification.required",
46
+ "platform.enabled",
47
+ "invitations.enabled",
48
+ "rateLimit.enabled",
49
+ "workspaces.enabled",
50
+ "apiKeys.enabled"
51
+ ];
52
+ var BOOLEAN_OR_FUNCTION_OPTIONS = [
53
+ "workspaces.allowCreate"
54
+ ];
55
+ var CONTROLLER_FLAGS = [
56
+ "auth",
57
+ "mfa",
58
+ "passwordReset",
59
+ "sessions",
60
+ "platform",
61
+ "oauth",
62
+ "invitations",
63
+ "emailChange",
64
+ "workspaces",
65
+ "workspaceInvitations"
66
+ ];
67
+ var ENUM_OPTIONS = {
68
+ tokenDelivery: [
69
+ "cookie",
70
+ "bearer",
71
+ "both"
72
+ ],
73
+ environment: [
74
+ "production",
75
+ "development",
76
+ "test"
77
+ ],
78
+ "cookies.sameSite": [
79
+ "lax",
80
+ "strict",
81
+ "none"
82
+ ],
83
+ "passwordReset.method": [
84
+ "token",
85
+ "otp"
86
+ ]
87
+ };
88
+ function readPath(root, path) {
89
+ let node = root;
90
+ for (const step of path.split(".")) {
91
+ if (typeof node !== "object" || node === null) return void 0;
92
+ node = Reflect.get(node, step);
93
+ }
94
+ return node;
95
+ }
96
+ __name(readPath, "readPath");
97
+ function assertBoolean(path, value) {
98
+ if (value === void 0 || typeof value === "boolean") return;
99
+ throw new Error(`[BymaxAuthModule] ${path} must be true or false (received ${describeReceived(value)}).`);
100
+ }
101
+ __name(assertBoolean, "assertBoolean");
102
+ function assertOneOf(path, value, allowed) {
103
+ if (value === void 0 || typeof value === "string" && allowed.includes(value)) return;
104
+ throw new Error(`[BymaxAuthModule] ${path} must be one of ${allowed.map((entry) => `'${entry}'`).join(", ")} (received ${describeReceived(value)}).`);
105
+ }
106
+ __name(assertOneOf, "assertOneOf");
107
+ function validateControllerFlags(flags) {
108
+ for (const name of CONTROLLER_FLAGS) {
109
+ const flag = readPath(flags, name);
110
+ if (flag !== null) assertBoolean(`controllers.${name}`, flag);
111
+ }
112
+ }
113
+ __name(validateControllerFlags, "validateControllerFlags");
114
+ function validateEnumAndBooleanOptions(userOptions) {
115
+ for (const path of BOOLEAN_OPTIONS) assertBoolean(path, readPath(userOptions, path));
116
+ for (const path of BOOLEAN_OR_FUNCTION_OPTIONS) {
117
+ const value = readPath(userOptions, path);
118
+ if (typeof value !== "function") assertBoolean(path, value);
119
+ }
120
+ for (const [path, allowed] of Object.entries(ENUM_OPTIONS)) {
121
+ assertOneOf(path, readPath(userOptions, path), allowed);
122
+ }
123
+ validateControllerFlags(userOptions.controllers);
124
+ }
125
+ __name(validateEnumAndBooleanOptions, "validateEnumAndBooleanOptions");
126
+
127
+ // src/server/config/provider-shape.ts
128
+ var REQUIRED_EMAIL_METHODS = [
129
+ "sendPasswordResetToken",
130
+ "sendPasswordResetOtp",
131
+ "sendEmailVerificationOtp",
132
+ "sendMfaEnabledNotification",
133
+ "sendMfaDisabledNotification",
134
+ "sendInvitation"
135
+ ];
136
+ function readyMadeValue(providers, token) {
137
+ const entry = providers.find((p) => typeof p !== "function" && "provide" in p && p.provide === token);
138
+ if (entry === void 0 || !("useValue" in entry)) return {
139
+ found: false,
140
+ value: void 0
141
+ };
142
+ return {
143
+ found: true,
144
+ value: entry.useValue
145
+ };
146
+ }
147
+ __name(readyMadeValue, "readyMadeValue");
148
+ var HOOK_NAMES = Object.keys({
149
+ beforeRegister: true,
150
+ afterRegister: true,
151
+ beforeLogin: true,
152
+ afterLogin: true,
153
+ afterLogout: true,
154
+ afterPlatformLogout: true,
155
+ onLoginFailed: true,
156
+ onLockout: true,
157
+ onRefreshTokenReuseDetected: true,
158
+ afterMfaEnabled: true,
159
+ afterMfaDisabled: true,
160
+ afterMfaRecoveryCodesRegenerated: true,
161
+ onNewSession: true,
162
+ afterEmailVerified: true,
163
+ afterPasswordReset: true,
164
+ onOAuthLogin: true,
165
+ afterInvitationAccepted: true,
166
+ onSessionEvicted: true,
167
+ onApiKeyRequest: true,
168
+ beforeWorkspaceCreate: true,
169
+ onWorkspaceEvent: true
170
+ });
171
+ var EMAIL_METHOD_NAMES = Object.keys({
172
+ sendPasswordResetToken: true,
173
+ sendPasswordResetOtp: true,
174
+ sendEmailVerificationOtp: true,
175
+ sendPasswordChangedNotification: true,
176
+ sendEmailChangeVerification: true,
177
+ sendEmailChangedNotification: true,
178
+ sendMfaEnabledNotification: true,
179
+ sendMfaDisabledNotification: true,
180
+ sendNewSessionAlert: true,
181
+ sendInvitation: true,
182
+ sendWorkspaceInvitation: true
183
+ });
184
+ function assertNamedFunctions(label, value, names) {
185
+ if (typeof value !== "object" || value === null) {
186
+ throw new Error(`[BymaxAuthModule] ${label} must be an object (received ${describeReceived(value)}).`);
187
+ }
188
+ for (const name of names) {
189
+ const member = Reflect.get(value, name);
190
+ if (member !== void 0 && member !== null && typeof member !== "function") {
191
+ throw new Error(`[BymaxAuthModule] ${label}.${name} must be a function (received ${describeReceived(member)}).`);
192
+ }
193
+ }
194
+ }
195
+ __name(assertNamedFunctions, "assertNamedFunctions");
196
+ function assertProviderShapes(providers) {
197
+ const hooks = readyMadeValue(providers, BYMAX_AUTH_HOOKS);
198
+ if (hooks.found && hooks.value !== null && hooks.value !== void 0) {
199
+ assertNamedFunctions("BYMAX_AUTH_HOOKS", hooks.value, HOOK_NAMES);
200
+ }
201
+ const email = readyMadeValue(providers, BYMAX_AUTH_EMAIL_PROVIDER);
202
+ if (!email.found) return;
203
+ assertNamedFunctions("BYMAX_AUTH_EMAIL_PROVIDER", email.value, EMAIL_METHOD_NAMES);
204
+ for (const name of REQUIRED_EMAIL_METHODS) {
205
+ if (typeof Reflect.get(email.value, name) !== "function") {
206
+ throw new Error(`[BymaxAuthModule] BYMAX_AUTH_EMAIL_PROVIDER.${name} is required and must be a function.`);
207
+ }
208
+ }
209
+ }
210
+ __name(assertProviderShapes, "assertProviderShapes");
211
+ function validateRegistrationShapes(controllers, providers) {
212
+ validateControllerFlags(controllers);
213
+ assertProviderShapes(providers);
214
+ }
215
+ __name(validateRegistrationShapes, "validateRegistrationShapes");
216
+
30
217
  // src/server/config/default-options.ts
31
218
  var DEFAULT_OPTIONS = {
32
219
  jwt: {
@@ -320,16 +507,6 @@ function validateApiKeyTuning(group) {
320
507
  }
321
508
  __name(validateApiKeyTuning, "validateApiKeyTuning");
322
509
 
323
- // src/server/config/describe-received.ts
324
- function describeReceived(value) {
325
- if (typeof value === "number") return String(value);
326
- if (value === null || value === void 0) return String(value);
327
- if (Array.isArray(value)) return "an array";
328
- const kind = typeof value;
329
- return `${kind === "object" ? "an" : "a"} ${kind}`;
330
- }
331
- __name(describeReceived, "describeReceived");
332
-
333
510
  // src/server/config/duration.ts
334
511
  var DURATION_UNIT_SECONDS = {
335
512
  ms: 1e-3,
@@ -595,6 +772,13 @@ function validateNumericOptions(userOptions) {
595
772
  }
596
773
  __name(validateNumericOptions, "validateNumericOptions");
597
774
 
775
+ // src/server/config/option-values.ts
776
+ function validateOptionValues(userOptions) {
777
+ validateNumericOptions(userOptions);
778
+ validateEnumAndBooleanOptions(userOptions);
779
+ }
780
+ __name(validateOptionValues, "validateOptionValues");
781
+
598
782
  // src/server/config/shape-checks.ts
599
783
  function assertObject(label, value) {
600
784
  if (Object(value) === value) return;
@@ -745,6 +929,18 @@ var GROUP_KEYS = {
745
929
  resolveWsWorkspace: true
746
930
  }
747
931
  };
932
+ var KEPT_GROUP_KEYS = {
933
+ oauth: {
934
+ successRedirectUrl: true,
935
+ mfaRedirectUrl: true,
936
+ errorRedirectUrl: true,
937
+ google: true
938
+ },
939
+ roles: {
940
+ hierarchy: true,
941
+ platformHierarchy: true
942
+ }
943
+ };
748
944
  var WORKSPACE_SUBGROUP_KEYS = {
749
945
  accessDeniedEvents: [
750
946
  "max",
@@ -767,6 +963,18 @@ function readSetKeys(group, keys) {
767
963
  return out;
768
964
  }
769
965
  __name(readSetKeys, "readSetKeys");
966
+ function readKeptKeys(group, keys) {
967
+ const out = {};
968
+ for (const key of /* @__PURE__ */ new Set([
969
+ ...keys,
970
+ ...Object.keys(group)
971
+ ])) {
972
+ const entry = Reflect.get(group, key);
973
+ if (entry !== void 0 || Object.hasOwn(group, key)) out[key] = entry;
974
+ }
975
+ return out;
976
+ }
977
+ __name(readKeptKeys, "readKeptKeys");
770
978
  function dropUnsetKeys(value) {
771
979
  const copy = {
772
980
  ...value
@@ -791,6 +999,10 @@ function dropUnset(options) {
791
999
  }
792
1000
  copy[name] = group;
793
1001
  }
1002
+ for (const [name, keys] of Object.entries(KEPT_GROUP_KEYS)) {
1003
+ const entry = copy[name];
1004
+ if (isObjectGroup(entry)) copy[name] = readKeptKeys(entry, Object.keys(keys));
1005
+ }
794
1006
  return Object.assign({}, copy);
795
1007
  }
796
1008
  __name(dropUnset, "dropUnset");
@@ -1117,7 +1329,7 @@ function resolveOptions(given) {
1117
1329
  validateMfaEncryptionKey(userOptions.mfa);
1118
1330
  validateRolesHierarchy(userOptions.roles);
1119
1331
  validatePlatformAdmin(userOptions.platform, userOptions.roles);
1120
- validateNumericOptions(userOptions);
1332
+ validateOptionValues(userOptions);
1121
1333
  validatePasswordMinLength(userOptions.password);
1122
1334
  validatePasswordCostFactor(userOptions.password);
1123
1335
  validatePasswordMemoryParameters(userOptions.password);
@@ -1607,10 +1819,10 @@ function validateAccessLifetimeAgainstEpochRetention(jwt) {
1607
1819
  const configured = jwt.accessExpiresIn ?? DEFAULT_OPTIONS.jwt.accessExpiresIn;
1608
1820
  const seconds = durationToSeconds(configured);
1609
1821
  if (seconds === void 0) {
1610
- throw new Error(`[BymaxAuthModule] jwt.accessExpiresIn must be a time span such as '15m', '1h' or '900s'. Got: '${configured}'. A value the signer cannot read would fail at the first token issued, and leaves the token-epoch retention bound unverifiable at startup.`);
1822
+ throw new Error(`[BymaxAuthModule] jwt.accessExpiresIn must be a time span such as '15m', '1h' or '900s'. Received ${describeReceived(configured)}. A value the signer cannot read would fail at the first token issued, and leaves the token-epoch retention bound unverifiable at startup.`);
1611
1823
  }
1612
1824
  if (seconds > TOKEN_EPOCH_RETENTION_SECONDS) {
1613
- throw new Error(`[BymaxAuthModule] jwt.accessExpiresIn ('${configured}' = ${seconds} s) must not exceed the token-epoch retention window (${TOKEN_EPOCH_RETENTION_SECONDS} s). An access token that outlives the stored epoch would survive the password reset that revoked it: the epoch lookup falls back to 0 once the record expires, and the staleness check stops firing.`);
1825
+ throw new Error(`[BymaxAuthModule] jwt.accessExpiresIn (${seconds} s) must not exceed the token-epoch retention window (${TOKEN_EPOCH_RETENTION_SECONDS} s). An access token that outlives the stored epoch would survive the password reset that revoked it: the epoch lookup falls back to 0 once the record expires, and the staleness check stops firing.`);
1614
1826
  }
1615
1827
  }
1616
1828
  __name(validateAccessLifetimeAgainstEpochRetention, "validateAccessLifetimeAgainstEpochRetention");
@@ -24556,6 +24768,7 @@ exports.BymaxAuthModule = class _BymaxAuthModule {
24556
24768
  */
24557
24769
  static registerAsync(options) {
24558
24770
  const extraProviders = options.extraProviders ?? [];
24771
+ validateRegistrationShapes(options.controllers, extraProviders);
24559
24772
  if (!hasProviderToken(extraProviders, BYMAX_AUTH_USER_REPOSITORY)) {
24560
24773
  throw new Error("[BymaxAuthModule] BYMAX_AUTH_USER_REPOSITORY is required in extraProviders. Provide your IUserRepository implementation: { provide: BYMAX_AUTH_USER_REPOSITORY, useClass: YourUserRepository }.");
24561
24774
  }
@@ -25,6 +25,193 @@ var BYMAX_AUTH_API_KEY_CLOCK = /* @__PURE__ */ Symbol("BYMAX_AUTH_API_KEY_CLOCK"
25
25
  var BYMAX_AUTH_WORKSPACE_REPOSITORY = /* @__PURE__ */ Symbol("BYMAX_AUTH_WORKSPACE_REPOSITORY");
26
26
  var BYMAX_AUTH_MEMBERSHIP_REPOSITORY = /* @__PURE__ */ Symbol("BYMAX_AUTH_MEMBERSHIP_REPOSITORY");
27
27
 
28
+ // src/server/config/describe-received.ts
29
+ function describeReceived(value) {
30
+ if (typeof value === "number") return String(value);
31
+ if (value === null || value === void 0) return String(value);
32
+ if (Array.isArray(value)) return "an array";
33
+ const kind = typeof value;
34
+ return `${kind === "object" ? "an" : "a"} ${kind}`;
35
+ }
36
+ __name(describeReceived, "describeReceived");
37
+
38
+ // src/server/config/enum-boolean-options.ts
39
+ var BOOLEAN_OPTIONS = [
40
+ "secureCookies",
41
+ "enforceTenantBinding",
42
+ "sessions.enabled",
43
+ "emailVerification.required",
44
+ "platform.enabled",
45
+ "invitations.enabled",
46
+ "rateLimit.enabled",
47
+ "workspaces.enabled",
48
+ "apiKeys.enabled"
49
+ ];
50
+ var BOOLEAN_OR_FUNCTION_OPTIONS = [
51
+ "workspaces.allowCreate"
52
+ ];
53
+ var CONTROLLER_FLAGS = [
54
+ "auth",
55
+ "mfa",
56
+ "passwordReset",
57
+ "sessions",
58
+ "platform",
59
+ "oauth",
60
+ "invitations",
61
+ "emailChange",
62
+ "workspaces",
63
+ "workspaceInvitations"
64
+ ];
65
+ var ENUM_OPTIONS = {
66
+ tokenDelivery: [
67
+ "cookie",
68
+ "bearer",
69
+ "both"
70
+ ],
71
+ environment: [
72
+ "production",
73
+ "development",
74
+ "test"
75
+ ],
76
+ "cookies.sameSite": [
77
+ "lax",
78
+ "strict",
79
+ "none"
80
+ ],
81
+ "passwordReset.method": [
82
+ "token",
83
+ "otp"
84
+ ]
85
+ };
86
+ function readPath(root, path) {
87
+ let node = root;
88
+ for (const step of path.split(".")) {
89
+ if (typeof node !== "object" || node === null) return void 0;
90
+ node = Reflect.get(node, step);
91
+ }
92
+ return node;
93
+ }
94
+ __name(readPath, "readPath");
95
+ function assertBoolean(path, value) {
96
+ if (value === void 0 || typeof value === "boolean") return;
97
+ throw new Error(`[BymaxAuthModule] ${path} must be true or false (received ${describeReceived(value)}).`);
98
+ }
99
+ __name(assertBoolean, "assertBoolean");
100
+ function assertOneOf(path, value, allowed) {
101
+ if (value === void 0 || typeof value === "string" && allowed.includes(value)) return;
102
+ throw new Error(`[BymaxAuthModule] ${path} must be one of ${allowed.map((entry) => `'${entry}'`).join(", ")} (received ${describeReceived(value)}).`);
103
+ }
104
+ __name(assertOneOf, "assertOneOf");
105
+ function validateControllerFlags(flags) {
106
+ for (const name of CONTROLLER_FLAGS) {
107
+ const flag = readPath(flags, name);
108
+ if (flag !== null) assertBoolean(`controllers.${name}`, flag);
109
+ }
110
+ }
111
+ __name(validateControllerFlags, "validateControllerFlags");
112
+ function validateEnumAndBooleanOptions(userOptions) {
113
+ for (const path of BOOLEAN_OPTIONS) assertBoolean(path, readPath(userOptions, path));
114
+ for (const path of BOOLEAN_OR_FUNCTION_OPTIONS) {
115
+ const value = readPath(userOptions, path);
116
+ if (typeof value !== "function") assertBoolean(path, value);
117
+ }
118
+ for (const [path, allowed] of Object.entries(ENUM_OPTIONS)) {
119
+ assertOneOf(path, readPath(userOptions, path), allowed);
120
+ }
121
+ validateControllerFlags(userOptions.controllers);
122
+ }
123
+ __name(validateEnumAndBooleanOptions, "validateEnumAndBooleanOptions");
124
+
125
+ // src/server/config/provider-shape.ts
126
+ var REQUIRED_EMAIL_METHODS = [
127
+ "sendPasswordResetToken",
128
+ "sendPasswordResetOtp",
129
+ "sendEmailVerificationOtp",
130
+ "sendMfaEnabledNotification",
131
+ "sendMfaDisabledNotification",
132
+ "sendInvitation"
133
+ ];
134
+ function readyMadeValue(providers, token) {
135
+ const entry = providers.find((p) => typeof p !== "function" && "provide" in p && p.provide === token);
136
+ if (entry === void 0 || !("useValue" in entry)) return {
137
+ found: false,
138
+ value: void 0
139
+ };
140
+ return {
141
+ found: true,
142
+ value: entry.useValue
143
+ };
144
+ }
145
+ __name(readyMadeValue, "readyMadeValue");
146
+ var HOOK_NAMES = Object.keys({
147
+ beforeRegister: true,
148
+ afterRegister: true,
149
+ beforeLogin: true,
150
+ afterLogin: true,
151
+ afterLogout: true,
152
+ afterPlatformLogout: true,
153
+ onLoginFailed: true,
154
+ onLockout: true,
155
+ onRefreshTokenReuseDetected: true,
156
+ afterMfaEnabled: true,
157
+ afterMfaDisabled: true,
158
+ afterMfaRecoveryCodesRegenerated: true,
159
+ onNewSession: true,
160
+ afterEmailVerified: true,
161
+ afterPasswordReset: true,
162
+ onOAuthLogin: true,
163
+ afterInvitationAccepted: true,
164
+ onSessionEvicted: true,
165
+ onApiKeyRequest: true,
166
+ beforeWorkspaceCreate: true,
167
+ onWorkspaceEvent: true
168
+ });
169
+ var EMAIL_METHOD_NAMES = Object.keys({
170
+ sendPasswordResetToken: true,
171
+ sendPasswordResetOtp: true,
172
+ sendEmailVerificationOtp: true,
173
+ sendPasswordChangedNotification: true,
174
+ sendEmailChangeVerification: true,
175
+ sendEmailChangedNotification: true,
176
+ sendMfaEnabledNotification: true,
177
+ sendMfaDisabledNotification: true,
178
+ sendNewSessionAlert: true,
179
+ sendInvitation: true,
180
+ sendWorkspaceInvitation: true
181
+ });
182
+ function assertNamedFunctions(label, value, names) {
183
+ if (typeof value !== "object" || value === null) {
184
+ throw new Error(`[BymaxAuthModule] ${label} must be an object (received ${describeReceived(value)}).`);
185
+ }
186
+ for (const name of names) {
187
+ const member = Reflect.get(value, name);
188
+ if (member !== void 0 && member !== null && typeof member !== "function") {
189
+ throw new Error(`[BymaxAuthModule] ${label}.${name} must be a function (received ${describeReceived(member)}).`);
190
+ }
191
+ }
192
+ }
193
+ __name(assertNamedFunctions, "assertNamedFunctions");
194
+ function assertProviderShapes(providers) {
195
+ const hooks = readyMadeValue(providers, BYMAX_AUTH_HOOKS);
196
+ if (hooks.found && hooks.value !== null && hooks.value !== void 0) {
197
+ assertNamedFunctions("BYMAX_AUTH_HOOKS", hooks.value, HOOK_NAMES);
198
+ }
199
+ const email = readyMadeValue(providers, BYMAX_AUTH_EMAIL_PROVIDER);
200
+ if (!email.found) return;
201
+ assertNamedFunctions("BYMAX_AUTH_EMAIL_PROVIDER", email.value, EMAIL_METHOD_NAMES);
202
+ for (const name of REQUIRED_EMAIL_METHODS) {
203
+ if (typeof Reflect.get(email.value, name) !== "function") {
204
+ throw new Error(`[BymaxAuthModule] BYMAX_AUTH_EMAIL_PROVIDER.${name} is required and must be a function.`);
205
+ }
206
+ }
207
+ }
208
+ __name(assertProviderShapes, "assertProviderShapes");
209
+ function validateRegistrationShapes(controllers, providers) {
210
+ validateControllerFlags(controllers);
211
+ assertProviderShapes(providers);
212
+ }
213
+ __name(validateRegistrationShapes, "validateRegistrationShapes");
214
+
28
215
  // src/server/config/default-options.ts
29
216
  var DEFAULT_OPTIONS = {
30
217
  jwt: {
@@ -318,16 +505,6 @@ function validateApiKeyTuning(group) {
318
505
  }
319
506
  __name(validateApiKeyTuning, "validateApiKeyTuning");
320
507
 
321
- // src/server/config/describe-received.ts
322
- function describeReceived(value) {
323
- if (typeof value === "number") return String(value);
324
- if (value === null || value === void 0) return String(value);
325
- if (Array.isArray(value)) return "an array";
326
- const kind = typeof value;
327
- return `${kind === "object" ? "an" : "a"} ${kind}`;
328
- }
329
- __name(describeReceived, "describeReceived");
330
-
331
508
  // src/server/config/duration.ts
332
509
  var DURATION_UNIT_SECONDS = {
333
510
  ms: 1e-3,
@@ -593,6 +770,13 @@ function validateNumericOptions(userOptions) {
593
770
  }
594
771
  __name(validateNumericOptions, "validateNumericOptions");
595
772
 
773
+ // src/server/config/option-values.ts
774
+ function validateOptionValues(userOptions) {
775
+ validateNumericOptions(userOptions);
776
+ validateEnumAndBooleanOptions(userOptions);
777
+ }
778
+ __name(validateOptionValues, "validateOptionValues");
779
+
596
780
  // src/server/config/shape-checks.ts
597
781
  function assertObject(label, value) {
598
782
  if (Object(value) === value) return;
@@ -743,6 +927,18 @@ var GROUP_KEYS = {
743
927
  resolveWsWorkspace: true
744
928
  }
745
929
  };
930
+ var KEPT_GROUP_KEYS = {
931
+ oauth: {
932
+ successRedirectUrl: true,
933
+ mfaRedirectUrl: true,
934
+ errorRedirectUrl: true,
935
+ google: true
936
+ },
937
+ roles: {
938
+ hierarchy: true,
939
+ platformHierarchy: true
940
+ }
941
+ };
746
942
  var WORKSPACE_SUBGROUP_KEYS = {
747
943
  accessDeniedEvents: [
748
944
  "max",
@@ -765,6 +961,18 @@ function readSetKeys(group, keys) {
765
961
  return out;
766
962
  }
767
963
  __name(readSetKeys, "readSetKeys");
964
+ function readKeptKeys(group, keys) {
965
+ const out = {};
966
+ for (const key of /* @__PURE__ */ new Set([
967
+ ...keys,
968
+ ...Object.keys(group)
969
+ ])) {
970
+ const entry = Reflect.get(group, key);
971
+ if (entry !== void 0 || Object.hasOwn(group, key)) out[key] = entry;
972
+ }
973
+ return out;
974
+ }
975
+ __name(readKeptKeys, "readKeptKeys");
768
976
  function dropUnsetKeys(value) {
769
977
  const copy = {
770
978
  ...value
@@ -789,6 +997,10 @@ function dropUnset(options) {
789
997
  }
790
998
  copy[name] = group;
791
999
  }
1000
+ for (const [name, keys] of Object.entries(KEPT_GROUP_KEYS)) {
1001
+ const entry = copy[name];
1002
+ if (isObjectGroup(entry)) copy[name] = readKeptKeys(entry, Object.keys(keys));
1003
+ }
792
1004
  return Object.assign({}, copy);
793
1005
  }
794
1006
  __name(dropUnset, "dropUnset");
@@ -1115,7 +1327,7 @@ function resolveOptions(given) {
1115
1327
  validateMfaEncryptionKey(userOptions.mfa);
1116
1328
  validateRolesHierarchy(userOptions.roles);
1117
1329
  validatePlatformAdmin(userOptions.platform, userOptions.roles);
1118
- validateNumericOptions(userOptions);
1330
+ validateOptionValues(userOptions);
1119
1331
  validatePasswordMinLength(userOptions.password);
1120
1332
  validatePasswordCostFactor(userOptions.password);
1121
1333
  validatePasswordMemoryParameters(userOptions.password);
@@ -1605,10 +1817,10 @@ function validateAccessLifetimeAgainstEpochRetention(jwt) {
1605
1817
  const configured = jwt.accessExpiresIn ?? DEFAULT_OPTIONS.jwt.accessExpiresIn;
1606
1818
  const seconds = durationToSeconds(configured);
1607
1819
  if (seconds === void 0) {
1608
- throw new Error(`[BymaxAuthModule] jwt.accessExpiresIn must be a time span such as '15m', '1h' or '900s'. Got: '${configured}'. A value the signer cannot read would fail at the first token issued, and leaves the token-epoch retention bound unverifiable at startup.`);
1820
+ throw new Error(`[BymaxAuthModule] jwt.accessExpiresIn must be a time span such as '15m', '1h' or '900s'. Received ${describeReceived(configured)}. A value the signer cannot read would fail at the first token issued, and leaves the token-epoch retention bound unverifiable at startup.`);
1609
1821
  }
1610
1822
  if (seconds > TOKEN_EPOCH_RETENTION_SECONDS) {
1611
- throw new Error(`[BymaxAuthModule] jwt.accessExpiresIn ('${configured}' = ${seconds} s) must not exceed the token-epoch retention window (${TOKEN_EPOCH_RETENTION_SECONDS} s). An access token that outlives the stored epoch would survive the password reset that revoked it: the epoch lookup falls back to 0 once the record expires, and the staleness check stops firing.`);
1823
+ throw new Error(`[BymaxAuthModule] jwt.accessExpiresIn (${seconds} s) must not exceed the token-epoch retention window (${TOKEN_EPOCH_RETENTION_SECONDS} s). An access token that outlives the stored epoch would survive the password reset that revoked it: the epoch lookup falls back to 0 once the record expires, and the staleness check stops firing.`);
1612
1824
  }
1613
1825
  }
1614
1826
  __name(validateAccessLifetimeAgainstEpochRetention, "validateAccessLifetimeAgainstEpochRetention");
@@ -24554,6 +24766,7 @@ var BymaxAuthModule = class _BymaxAuthModule {
24554
24766
  */
24555
24767
  static registerAsync(options) {
24556
24768
  const extraProviders = options.extraProviders ?? [];
24769
+ validateRegistrationShapes(options.controllers, extraProviders);
24557
24770
  if (!hasProviderToken(extraProviders, BYMAX_AUTH_USER_REPOSITORY)) {
24558
24771
  throw new Error("[BymaxAuthModule] BYMAX_AUTH_USER_REPOSITORY is required in extraProviders. Provide your IUserRepository implementation: { provide: BYMAX_AUTH_USER_REPOSITORY, useClass: YourUserRepository }.");
24559
24772
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bymax-one/nest-auth",
3
- "version": "1.5.9",
3
+ "version": "1.5.10",
4
4
  "description": "Full-stack authentication and authorization package for NestJS, React and Next.js — JWT, MFA, OAuth, sessions, multi-tenant SaaS ready",
5
5
  "author": "Bymax One <support@bymax.one>",
6
6
  "license": "MIT",