@mesob/auth-hono 0.5.2 → 0.5.4
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-CDgzxZzO.d.ts → index-v_uxUd8A.d.ts} +45 -4
- package/dist/index.d.ts +10 -3
- package/dist/index.js +655 -250
- package/dist/index.js.map +1 -1
- package/dist/lib/auth-rate-limit.d.ts +21 -0
- package/dist/lib/auth-rate-limit.js +228 -0
- package/dist/lib/auth-rate-limit.js.map +1 -0
- package/dist/lib/cookie.d.ts +4 -2
- package/dist/lib/cookie.js +6 -1
- package/dist/lib/cookie.js.map +1 -1
- package/dist/lib/has-role-permission.d.ts +1 -1
- package/dist/lib/iam-seed.d.ts +1 -1
- package/dist/lib/load-session-pair.d.ts +16 -0
- package/dist/lib/load-session-pair.js +505 -0
- package/dist/lib/load-session-pair.js.map +1 -0
- package/dist/lib/normalize-auth-response.d.ts +5 -2
- package/dist/lib/normalize-auth-response.js +4 -1
- package/dist/lib/normalize-auth-response.js.map +1 -1
- package/dist/lib/normalize-rate-limit-ip.d.ts +5 -0
- package/dist/lib/normalize-rate-limit-ip.js +159 -0
- package/dist/lib/normalize-rate-limit-ip.js.map +1 -0
- package/dist/lib/normalize-user.d.ts +1 -1
- package/dist/lib/openapi-config.d.ts +1 -1
- package/dist/lib/phone-validation.d.ts +1 -1
- package/dist/lib/session-cache.d.ts +22 -0
- package/dist/lib/session-cache.js +396 -0
- package/dist/lib/session-cache.js.map +1 -0
- package/dist/lib/session.d.ts +1 -1
- package/dist/lib/tenant.d.ts +1 -1
- package/package.json +2 -2
|
@@ -137,17 +137,54 @@ type SeedRole = {
|
|
|
137
137
|
isEditable?: boolean;
|
|
138
138
|
isDeletable?: boolean;
|
|
139
139
|
};
|
|
140
|
-
|
|
141
|
-
|
|
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;
|
|
142
175
|
};
|
|
143
176
|
type AuthConfig = {
|
|
144
177
|
connectionString: string;
|
|
145
178
|
userType: string;
|
|
146
179
|
secret: string;
|
|
147
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;
|
|
148
186
|
tenant?: TenantConfig;
|
|
149
187
|
docs?: DocsConfig;
|
|
150
|
-
cookie?: CookieConfig;
|
|
151
188
|
permissions?: PermissionTree;
|
|
152
189
|
roles?: SeedRole[];
|
|
153
190
|
session: SessionConfig;
|
|
@@ -155,6 +192,10 @@ type AuthConfig = {
|
|
|
155
192
|
phone: PhoneConfig;
|
|
156
193
|
signUp?: SignUpConfig;
|
|
157
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;
|
|
158
199
|
};
|
|
159
200
|
|
|
160
201
|
type CreateAuthRoutesOptions = {
|
|
@@ -172,4 +213,4 @@ type MesobAuth = {
|
|
|
172
213
|
sessionMiddleware: hono.MiddlewareHandler;
|
|
173
214
|
};
|
|
174
215
|
|
|
175
|
-
export type { AuthConfig as A, MesobAuth as M, SessionStatus as S, Tenant as T, User as U,
|
|
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-
|
|
2
|
-
export {
|
|
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
3
|
import { D as Database } from './index-Dhe5obDc.js';
|
|
4
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 };
|