@basaltkit/auth 1.8.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,12 +1,18 @@
1
1
  export { ScryptPasswordHasher, type PasswordHasher } from './hashing.js';
2
2
  export { signJwt, verifyJwt, TokenInvalidError, TokenExpiredError, type JwtClaims, } from './jwt.js';
3
3
  export { MemoryUserSource, MemorySessionStore, MemoryRefreshTokenStore, MemoryAuthTokenStore, MemoryApiKeyStore, MemoryMfaStore, MemoryTokenVersionStore, type TokenVersionStore, type AuthUser, type PublicUser, type UserSource, type UserPatch, type SessionStore, type SessionRecord, type RefreshTokenStore, type RefreshRecord, type AuthTokenStore, type AuthTokenRecord, type AuthTokenPurpose, type ApiKeyStore, type ApiKeyRecord, type ApiKeyInfo, type ApiKeyFilter, type MfaStore, type MfaRecord, } from './stores.js';
4
+ declare module '@basaltkit/http' {
5
+ interface RouteMeta {
6
+ /** `true` requires a session; `false` opts a route out. */
7
+ auth?: boolean;
8
+ }
9
+ }
4
10
  export { Auth, publicUser, InvalidCredentialsError, EmailTakenError, WeakJwtSecretError, RefreshInvalidError, RefreshReusedError, AuthRequiredError, AuthTokenInvalidError, UserUpdateUnsupportedError, MfaRequiredError, MfaInvalidCodeError, MfaNotEnrolledError, type AuthOptions, type TokenPair, } from './auth.js';
5
11
  export { base32Encode, base32Decode, generateTotpSecret, totp, verifyTotp, matchTotpStep, otpauthUri, type TotpOptions, type VerifyTotpOptions, type OtpauthUriInput, } from './totp.js';
6
12
  export { authPlugin, AUTH, type AuthPluginOptions } from './plugin.js';
7
13
  export { ApiKeys, ScopeRequiredError, scopesSatisfy, type ApiKeysOptions, type IssueApiKeyInput, type ApiKeyContext, } from './apikeys.js';
8
14
  export { apiKeysPlugin, API_KEYS, type ApiKeysPluginOptions } from './apikeys-plugin.js';
9
- export { authRoutes, apiKeyRoutes, mfaRoutes } from './routes.js';
15
+ export { authRoutes, apiKeyRoutes, mfaRoutes, type AuthRoutesOptions, type PasswordPolicy, } from './routes.js';
10
16
  export { OAuth, googleProvider, githubProvider, oidcProvider, discoverOidcProvider, stripTrailingSlashes, OAuthProviderUnknownError, OAuthStateInvalidError, OAuthExchangeError, type OAuthProvider, type OAuthProfile, type OAuthOptions, } from './oauth.js';
11
17
  export { oauthPlugin, oauthRoutes, OAUTH, type OAuthPluginOptions, type OAuthRoutesOptions, } from './oauth-plugin.js';
12
18
  export { LoginThrottle, AccountLockedError, type LoginThrottleOptions } from './throttle.js';
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ export { base32Encode, base32Decode, generateTotpSecret, totp, verifyTotp, match
6
6
  export { authPlugin, AUTH } from './plugin.js';
7
7
  export { ApiKeys, ScopeRequiredError, scopesSatisfy, } from './apikeys.js';
8
8
  export { apiKeysPlugin, API_KEYS } from './apikeys-plugin.js';
9
- export { authRoutes, apiKeyRoutes, mfaRoutes } from './routes.js';
9
+ export { authRoutes, apiKeyRoutes, mfaRoutes, } from './routes.js';
10
10
  export { OAuth, googleProvider, githubProvider, oidcProvider, discoverOidcProvider, stripTrailingSlashes, OAuthProviderUnknownError, OAuthStateInvalidError, OAuthExchangeError, } from './oauth.js';
11
11
  export { oauthPlugin, oauthRoutes, OAUTH, } from './oauth-plugin.js';
12
12
  export { LoginThrottle, AccountLockedError } from './throttle.js';
package/dist/routes.d.ts CHANGED
@@ -1,4 +1,25 @@
1
1
  import { type BasaltRoute } from '@basaltkit/http';
2
+ import { z } from 'zod';
3
+ /**
4
+ * How strong a password has to be.
5
+ *
6
+ * The rule was `min(8)`, fixed, with no way to change it — the 2012 minimum, in
7
+ * routes an application either uses as they are or replaces wholesale. One that
8
+ * needed more reached into the route's Zod object and swapped the field,
9
+ * depending on the internal shape of a body it does not own.
10
+ *
11
+ * A whole schema and not just a number, because the interesting rules are not
12
+ * lengths: "at least one symbol", "not the email address", "not in a breach
13
+ * list". An option taking only a number would send those applications straight
14
+ * back to patching.
15
+ */
16
+ export interface PasswordPolicy {
17
+ minLength?: number;
18
+ }
19
+ export interface AuthRoutesOptions {
20
+ /** A minimum length, or the schema itself. Default: `min(8)`. */
21
+ password?: PasswordPolicy | z.ZodType<string>;
22
+ }
2
23
  /**
3
24
  * Ready-made auth routes — register them in fastifyPlugin({ routes }):
4
25
  * register · login · refresh · logout · me, plus email verification
@@ -6,7 +27,7 @@ import { type BasaltRoute } from '@basaltkit/http';
6
27
  * (`/auth/password/forgot`, `/auth/password/reset`).
7
28
  * Every one is a plain BasaltRoute: replace or omit any of them freely.
8
29
  */
9
- export declare function authRoutes(): BasaltRoute[];
30
+ export declare function authRoutes(options?: AuthRoutesOptions): BasaltRoute[];
10
31
  /**
11
32
  * CRUD routes for API keys, all requiring a logged-in user (`meta.auth`). Keys
12
33
  * are scoped to the caller's tenant (`ctx().tenant`) and user; a caller only
package/dist/routes.js CHANGED
@@ -3,7 +3,15 @@ import { route } from '@basaltkit/http';
3
3
  import { z } from 'zod';
4
4
  import { AUTH } from './plugin.js';
5
5
  import { API_KEYS } from './apikeys-plugin.js';
6
- const credentials = z.object({ email: z.string().email(), password: z.string().min(8) });
6
+ const DEFAULT_PASSWORD = z.string().min(8);
7
+ const passwordSchema = (policy) => {
8
+ if (!policy)
9
+ return DEFAULT_PASSWORD;
10
+ if (typeof policy.safeParse === 'function')
11
+ return policy;
12
+ const { minLength } = policy;
13
+ return minLength === undefined ? DEFAULT_PASSWORD : z.string().min(minLength);
14
+ };
7
15
  const auth = () => ctx().container.get(AUTH);
8
16
  const apiKeys = () => ctx().container.get(API_KEYS);
9
17
  /**
@@ -13,7 +21,9 @@ const apiKeys = () => ctx().container.get(API_KEYS);
13
21
  * (`/auth/password/forgot`, `/auth/password/reset`).
14
22
  * Every one is a plain BasaltRoute: replace or omit any of them freely.
15
23
  */
16
- export function authRoutes() {
24
+ export function authRoutes(options = {}) {
25
+ const password = passwordSchema(options.password);
26
+ const credentials = z.object({ email: z.string().email(), password });
17
27
  return [
18
28
  route({
19
29
  method: 'POST',
@@ -93,7 +103,10 @@ export function authRoutes() {
93
103
  route({
94
104
  method: 'POST',
95
105
  url: '/auth/password/reset',
96
- body: z.object({ token: z.string(), password: z.string().min(8) }),
106
+ // The same policy as register. Covering register and leaving reset behind
107
+ // would let anyone walk a strong password back down to eight characters
108
+ // through "forgot password" — a loophole worse than having no option.
109
+ body: z.object({ token: z.string(), password }),
97
110
  async handler({ body }) {
98
111
  await auth().resetPassword(body.token, body.password);
99
112
  return { ok: true };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basaltkit/auth",
3
- "version": "1.8.0",
3
+ "version": "2.0.0",
4
4
  "engines": {
5
5
  "node": ">=22.5.0"
6
6
  },
@@ -19,17 +19,17 @@
19
19
  ],
20
20
  "dependencies": {
21
21
  "@basaltkit/core": "^1.3.1",
22
- "@basaltkit/http": "^1.14.0"
22
+ "@basaltkit/http": "^2.0.0"
23
23
  },
24
24
  "peerDependencies": {
25
- "zod": "^3.24.0 || ^4.0.0"
25
+ "zod": "^4.0.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@types/node": "^26.3.0",
28
+ "@types/node": "^26.4.0",
29
29
  "typescript": "^7.0.2",
30
30
  "vitest": "^4.1.11",
31
- "zod": "^3.24.0 || ^4.0.0",
32
- "@basaltkit/fastify": "^1.8.1",
31
+ "zod": "^4.5.4",
32
+ "@basaltkit/fastify": "^2.0.0",
33
33
  "@basaltkit/tsconfig": "^0.24.0"
34
34
  },
35
35
  "publishConfig": {