@mesob/auth-hono 0.5.0 → 0.5.3

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.
@@ -1,7 +1,7 @@
1
1
  import * as hono from 'hono';
2
2
  import { OpenAPIHono } from '@hono/zod-openapi';
3
3
  import { PermissionTree } from '@mesob/common';
4
- import { D as Database } from './index-D8OE85f8.js';
4
+ import { D as Database } from './index-Dhe5obDc.js';
5
5
 
6
6
  type Tenant = {
7
7
  id: string;
@@ -89,6 +89,12 @@ type PhoneConfig = VerificationConfig & {
89
89
  phoneRegex?: RegExp | string;
90
90
  };
91
91
  type EmailConfig = VerificationConfig;
92
+ type SignUpConfig = {
93
+ enabled: boolean;
94
+ emailEnabled: boolean;
95
+ phoneEnabled: boolean;
96
+ allowedEmailDomains?: readonly string[];
97
+ };
92
98
  type SessionConfig = {
93
99
  /** Default session duration (e.g., '7d', '30d'). Default: '7d' */
94
100
  expiresIn: string;
@@ -131,23 +137,65 @@ type SeedRole = {
131
137
  isEditable?: boolean;
132
138
  isDeletable?: boolean;
133
139
  };
134
- type CookieConfig = {
135
- prefix?: string;
140
+ /** KV subset for session cache + rate limits (e.g. Cloudflare KVNamespace). */
141
+ type AuthKvStorage = {
142
+ get(key: string): Promise<string | null | undefined>;
143
+ put(key: string, value: string, options?: {
144
+ expirationTtl?: number;
145
+ }): Promise<void>;
146
+ delete(key: string): Promise<void>;
147
+ };
148
+ type SessionCacheConfig = {
149
+ enabled: false;
150
+ } | {
151
+ enabled: true;
152
+ kv: AuthKvStorage;
153
+ /** Cache entry TTL in seconds */
154
+ ttlSeconds?: number;
155
+ };
156
+ type AuthRateLimitConfig = {
157
+ enabled: false;
158
+ } | {
159
+ enabled: true;
160
+ kv: AuthKvStorage;
161
+ /** Window length in seconds */
162
+ window: number;
163
+ /** Max requests per window per IP (and per route bucket in impl) */
164
+ max: number;
165
+ /** Shown on 429 for auth-react */
166
+ message?: string;
167
+ /** Default cf-connecting-ip; impl may fall back to x-forwarded-for */
168
+ ipHeader?: string;
169
+ /**
170
+ * IPv6 rate-limit bucket: mask to this prefix length (1–128).
171
+ * 128 = full address; 64 = typical LAN; 48 / 32 = larger nets. Default 64.
172
+ * IPv4 always uses the full address. IPv4-mapped IPv6 → IPv4 key.
173
+ */
174
+ ipv6Subnet?: number;
136
175
  };
137
176
  type AuthConfig = {
138
177
  connectionString: string;
139
178
  userType: string;
140
179
  secret: string;
141
180
  basePath?: string;
181
+ /**
182
+ * Session cookie name + KV session cache key namespace (`{prefix}_session_token`, `{prefix}:sc:v1:…`).
183
+ * Default `msb`. Align with auth-react `prefix`.
184
+ */
185
+ prefix?: string;
142
186
  tenant?: TenantConfig;
143
187
  docs?: DocsConfig;
144
- cookie?: CookieConfig;
145
188
  permissions?: PermissionTree;
146
189
  roles?: SeedRole[];
147
190
  session: SessionConfig;
148
191
  email: EmailConfig;
149
192
  phone: PhoneConfig;
193
+ signUp?: SignUpConfig;
150
194
  security?: SecurityConfig;
195
+ /** Session+user cache in KV; DB remains source of truth when disabled */
196
+ sessionCache?: SessionCacheConfig;
197
+ /** Abuse guard on unauthenticated auth routes; separate KV from sessionCache */
198
+ rateLimit?: AuthRateLimitConfig;
151
199
  };
152
200
 
153
201
  type CreateAuthRoutesOptions = {
@@ -165,4 +213,4 @@ type MesobAuth = {
165
213
  sessionMiddleware: hono.MiddlewareHandler;
166
214
  };
167
215
 
168
- export type { AuthConfig as A, MesobAuth as M, SessionStatus as S, Tenant as T, User as U, SendInvitationParams as a, SendVerificationOTPParams as b, Session as c, SeedRole as d, SessionConfig as e };
216
+ export type { AuthConfig as A, MesobAuth as M, SessionStatus as S, Tenant as T, User as U, AuthEnv as a, AuthKvStorage as b, AuthRateLimitConfig as c, SendInvitationParams as d, SendVerificationOTPParams as e, Session as f, SessionCacheConfig as g, SeedRole as h, SessionConfig as i };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,15 @@
1
- import { A as AuthConfig, M as MesobAuth } from './index-DwIwuvVj.js';
2
- export { a as SendInvitationParams, b as SendVerificationOTPParams, c as Session, S as SessionStatus, T as Tenant, U as User } from './index-DwIwuvVj.js';
3
- import { D as Database } from './index-D8OE85f8.js';
4
- export { c as createDatabase } from './index-D8OE85f8.js';
1
+ import { A as AuthConfig, a as AuthEnv, M as MesobAuth } from './index-v_uxUd8A.js';
2
+ export { b as AuthKvStorage, c as AuthRateLimitConfig, d as SendInvitationParams, e as SendVerificationOTPParams, f as Session, g as SessionCacheConfig, S as SessionStatus, T as Tenant, U as User } from './index-v_uxUd8A.js';
3
+ import { D as Database } from './index-Dhe5obDc.js';
4
+ export { c as createDatabase } from './index-Dhe5obDc.js';
5
+ export { AUTH_RATE_LIMIT_POST_PATHS } from './lib/auth-rate-limit.js';
5
6
  export { cleanupExpiredData, cleanupExpiredSessions, cleanupExpiredVerifications } from './lib/cleanup.js';
7
+ export { getSessionCookieName, getSessionKeyNamespace } from './lib/cookie.js';
6
8
  export { hasPermission, hasPermissionThrow } from './lib/has-role-permission.js';
9
+ export { rateLimitClientKey } from './lib/normalize-rate-limit-ip.js';
10
+ export { deleteSessionCacheKeys, invalidateSessionCacheForHashedToken, invalidateSessionCacheForUser, sessionCacheKey } from './lib/session-cache.js';
7
11
  import * as hono from 'hono';
12
+ import { MiddlewareHandler } from 'hono';
8
13
  import '@hono/zod-openapi';
9
14
  import '@mesob/common';
10
15
  import 'drizzle-orm/node-postgres';
@@ -12,10 +17,12 @@ import 'drizzle-orm';
12
17
  import 'drizzle-orm/pg-core';
13
18
  import 'pg';
14
19
 
20
+ declare const createAuthRateLimitMiddleware: (config: AuthConfig) => MiddlewareHandler<AuthEnv>;
21
+
15
22
  declare const createSessionMiddleware: () => hono.MiddlewareHandler<any, string, {}, Response>;
16
23
 
17
24
  declare const createTenantMiddleware: (database: Database, config: AuthConfig) => hono.MiddlewareHandler<any, string, {}, Response>;
18
25
 
19
26
  declare const createMesobAuth: (authConfig: AuthConfig) => MesobAuth;
20
27
 
21
- export { AuthConfig, Database, MesobAuth, createMesobAuth, createSessionMiddleware, createTenantMiddleware };
28
+ export { AuthConfig, Database, MesobAuth, createAuthRateLimitMiddleware, createMesobAuth, createSessionMiddleware, createTenantMiddleware };