@guren/server 2.15.0 → 2.17.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/{DocsViewerServiceProvider-qFCaeiUv.js → DocsViewerServiceProvider-D2cuVgtN.js} +7 -12
- package/dist/{Hash-C8aejmi8.js → Hash-D2DFd8xX.js} +7 -57
- package/dist/{HttpException-BkS3euNG.js → HttpException-BlQ2yEmT.js} +2 -79
- package/dist/{Job-BVT813DO.js → Job-DxQK8h3P.js} +24 -179
- package/dist/{McpServiceProvider-BawsYjgN.js → McpServiceProvider-Zihx3Bjq.js} +35 -20
- package/dist/{Random-DbIJ22KQ.js → Random-S0OvCuR8.js} +9 -106
- package/dist/agent/AgentApprovalRequested.d.ts +11 -39
- package/dist/agent/approval-status.d.ts +56 -0
- package/dist/agent/approval.d.ts +76 -187
- package/dist/agent/audit-emitter.d.ts +16 -44
- package/dist/agent/audit.d.ts +20 -56
- package/dist/agent/derive.d.ts +32 -66
- package/dist/agent/dispatch.d.ts +38 -90
- package/dist/agent/events.d.ts +17 -23
- package/dist/agent/gate.d.ts +118 -0
- package/dist/agent/meta-tools.d.ts +18 -46
- package/dist/agent/pipeline.d.ts +234 -0
- package/dist/agent/public.d.ts +6 -25
- package/dist/agent/public.js +1 -1
- package/dist/agent/redact.d.ts +16 -38
- package/dist/agent/scopes.d.ts +55 -69
- package/dist/auth/AgentPrincipalGuard.d.ts +49 -0
- package/dist/auth/AuthManager.d.ts +22 -43
- package/dist/auth/AuthenticatableModel.d.ts +2 -2
- package/dist/auth/SessionGuard.d.ts +0 -1
- package/dist/auth/TokenGuard.d.ts +6 -26
- package/dist/auth/api-token.d.ts +16 -148
- package/dist/auth/context.d.ts +5 -10
- package/dist/auth/email-verification.d.ts +29 -127
- package/dist/auth/index.js +1 -1
- package/dist/auth/oauth/index.d.ts +35 -57
- package/dist/auth/password/DefaultHasher.d.ts +5 -14
- package/dist/auth/password/PasswordHasher.d.ts +5 -13
- package/dist/auth/password/hash-format.d.ts +5 -13
- package/dist/auth/password-reset.d.ts +16 -42
- package/dist/auth/providers/ModelUserProvider.d.ts +3 -4
- package/dist/auth/providers/UserProvider.d.ts +4 -4
- package/dist/auth/signed-token.d.ts +18 -0
- package/dist/auth/types.d.ts +9 -32
- package/dist/auth/utils.d.ts +6 -27
- package/dist/{auth-DkYoAPVn.js → auth-Gg54ppQi.js} +279 -519
- package/dist/authorization/Gate.d.ts +9 -145
- package/dist/authorization/Policy.d.ts +6 -53
- package/dist/authorization/index.js +1 -1
- package/dist/authorization/middleware.d.ts +16 -62
- package/dist/authorization/types.d.ts +8 -64
- package/dist/{authorization-CdfbCj8J.js → authorization-CdEWZZw3.js} +44 -309
- package/dist/broadcasting/BroadcastManager.d.ts +29 -149
- package/dist/broadcasting/channels/Channel.d.ts +1 -19
- package/dist/broadcasting/channels/PresenceChannel.d.ts +1 -55
- package/dist/broadcasting/channels/PrivateChannel.d.ts +1 -23
- package/dist/broadcasting/drivers/MemoryDriver.d.ts +18 -70
- package/dist/broadcasting/drivers/RedisDriver.d.ts +3 -80
- package/dist/broadcasting/drivers/index.d.ts +1 -1
- package/dist/broadcasting/index.d.ts +1 -1
- package/dist/broadcasting/index.js +1 -1
- package/dist/broadcasting/types.d.ts +7 -88
- package/dist/{broadcasting-BwodCA4q.js → broadcasting-B5RzB0A2.js} +87 -414
- package/dist/cache/CacheManager.d.ts +8 -62
- package/dist/cache/TaggedCache.d.ts +2 -35
- package/dist/cache/index.js +1 -1
- package/dist/cache/stores/FileStore.d.ts +2 -36
- package/dist/cache/stores/MemoryStore.d.ts +2 -26
- package/dist/cache/stores/RedisStore.d.ts +1 -29
- package/dist/cache/types.d.ts +21 -128
- package/dist/{cache-BYnZf2FR.js → cache-BOOIr324.js} +19 -198
- package/dist/client-C4TEr_Dd.js +9 -0
- package/dist/console/Command.d.ts +17 -126
- package/dist/console/ConsoleKernel.d.ts +2 -74
- package/dist/console/Input.d.ts +5 -113
- package/dist/console/Output.d.ts +3 -99
- package/dist/console/types.d.ts +3 -33
- package/dist/container/Container.d.ts +12 -103
- package/dist/container/ServiceProvider.d.ts +17 -61
- package/dist/container/bindings.d.ts +5 -26
- package/dist/container/defineModule.d.ts +16 -54
- package/dist/container/definePlugin.d.ts +12 -45
- package/dist/container/types.d.ts +2 -34
- package/dist/context-CXk_umpT.js +21 -0
- package/dist/database/Factory.d.ts +4 -57
- package/dist/database/Seeder.d.ts +8 -46
- package/dist/database/SeederRunner.d.ts +3 -33
- package/dist/database/types.d.ts +3 -24
- package/dist/discovery/AutoDiscovery.d.ts +10 -82
- package/dist/{dispatch-erOS9epZ.js → dispatch-BAwzftws.js} +32 -79
- package/dist/docs-viewer/DocsViewerServiceProvider.d.ts +2 -5
- package/dist/docs-viewer/endpoint.d.ts +5 -11
- package/dist/encryption/Encrypter.d.ts +5 -71
- package/dist/encryption/Hash.d.ts +7 -57
- package/dist/encryption/Random.d.ts +6 -99
- package/dist/encryption/index.js +3 -3
- package/dist/encryption/types.d.ts +10 -72
- package/dist/{encryption-D99Vmls3.js → encryption-uwP3Di4D.js} +9 -78
- package/dist/{endpoint-D6GIqOpe.js → endpoint-BXipU2Jj.js} +6 -12
- package/dist/endpoint-Dsw3Acvq.js +26 -0
- package/dist/errors/ExceptionHandler.d.ts +3 -90
- package/dist/errors/HttpException.d.ts +2 -79
- package/dist/errors/debug-page.d.ts +3 -17
- package/dist/errors/error-page.d.ts +1 -0
- package/dist/errors/exceptions/AuthenticationException.d.ts +2 -24
- package/dist/errors/exceptions/AuthorizationException.d.ts +1 -24
- package/dist/errors/exceptions/MethodNotAllowedException.d.ts +1 -23
- package/dist/errors/exceptions/NotFoundHttpException.d.ts +1 -27
- package/dist/errors/exceptions/ValidationException.d.ts +2 -43
- package/dist/errors/types.d.ts +1 -25
- package/dist/{errors-BgeOl_DC.js → errors-JpkcCjjn.js} +3 -41
- package/dist/events/Event.d.ts +1 -28
- package/dist/events/EventManager.d.ts +5 -107
- package/dist/events/Listener.d.ts +7 -55
- package/dist/events/builtin.d.ts +0 -24
- package/dist/events/index.js +1 -1
- package/dist/events/types.d.ts +4 -22
- package/dist/{events-aIH_bWRx.js → events-DOmAHDeP.js} +11 -191
- package/dist/facades/index.d.ts +2 -14
- package/dist/health/HealthCheck.d.ts +0 -24
- package/dist/health/HealthManager.d.ts +0 -36
- package/dist/health/checks/CacheCheck.d.ts +2 -17
- package/dist/health/checks/CustomCheck.d.ts +0 -9
- package/dist/health/checks/DatabaseCheck.d.ts +2 -17
- package/dist/health/checks/MemoryCheck.d.ts +3 -12
- package/dist/health/checks/RedisCheck.d.ts +1 -13
- package/dist/health/checks/StorageCheck.d.ts +2 -17
- package/dist/health/index.js +1 -1
- package/dist/health/types.d.ts +4 -24
- package/dist/{health-VWdWXRwh.js → health-DQSvUplL.js} +1 -76
- package/dist/hot-disposables-B5BXqaIH.js +167 -0
- package/dist/hot-reload/hot-disposables.d.ts +22 -74
- package/dist/hot-reload/testing.d.ts +4 -9
- package/dist/http/Application.d.ts +77 -205
- package/dist/http/FormRequest.d.ts +4 -55
- package/dist/http/dev-assets.d.ts +13 -31
- package/dist/http/dev-banner.d.ts +2 -5
- package/dist/http/inertia-assets.d.ts +3 -6
- package/dist/http/middleware/capabilities.d.ts +27 -50
- package/dist/http/middleware/cors.d.ts +4 -29
- package/dist/http/middleware/csp.d.ts +2 -25
- package/dist/http/middleware/csrf.d.ts +28 -95
- package/dist/http/middleware/detect-locale.d.ts +7 -27
- package/dist/http/middleware/force-https.d.ts +6 -24
- package/dist/http/middleware/host-authorization.d.ts +2 -12
- package/dist/http/middleware/index.d.ts +1 -1
- package/dist/http/middleware/loopback-guard.d.ts +15 -33
- package/dist/http/middleware/rate-limit.d.ts +29 -126
- package/dist/http/middleware/redirect-safety.d.ts +2 -20
- package/dist/http/middleware/request-id.d.ts +1 -14
- package/dist/http/middleware/request-logging.d.ts +2 -13
- package/dist/http/middleware/response-headers.d.ts +5 -13
- package/dist/http/middleware/security-headers.d.ts +2 -16
- package/dist/http/middleware/session.d.ts +15 -34
- package/dist/http/middleware/validation-errors-cookie.d.ts +7 -18
- package/dist/http/middleware/validation.d.ts +8 -63
- package/dist/http/public-assets.d.ts +11 -7
- package/dist/http/request.d.ts +32 -118
- package/dist/http/resources/CursorPaginator.d.ts +5 -64
- package/dist/http/resources/Paginator.d.ts +7 -84
- package/dist/http/resources/Resource.d.ts +9 -65
- package/dist/http/resources/ResourceCollection.d.ts +5 -39
- package/dist/http/resources/types.d.ts +10 -30
- package/dist/http/static-documents.d.ts +10 -20
- package/dist/http/validation/Validator.d.ts +25 -85
- package/dist/http/validation/rules.d.ts +48 -147
- package/dist/http/validation/types.d.ts +16 -61
- package/dist/http/vite-assets.d.ts +5 -28
- package/dist/http/vite-dev-server.d.ts +6 -9
- package/dist/http/vite-manifest.d.ts +19 -33
- package/dist/i18n/I18nManager.d.ts +12 -78
- package/dist/i18n/Translator.d.ts +3 -54
- package/dist/i18n/index.js +1 -1
- package/dist/i18n/loaders/JsonLoader.d.ts +4 -31
- package/dist/i18n/loaders/MemoryLoader.d.ts +1 -21
- package/dist/i18n/pluralization.d.ts +4 -13
- package/dist/i18n/types.d.ts +17 -69
- package/dist/{i18n-mcWi7LCd.js → i18n-Cg1aajRP.js} +31 -225
- package/dist/index.d.ts +11 -4
- package/dist/index.js +1186 -3040
- package/dist/internal/agent-preflight.d.ts +9 -21
- package/dist/internal/agent-principal.d.ts +32 -0
- package/dist/internal/request.d.ts +6 -19
- package/dist/internal/request.js +1 -1
- package/dist/internal/route-path.d.ts +9 -21
- package/dist/internal/route-path.js +9 -21
- package/dist/internal/zod-compat.d.ts +55 -122
- package/dist/internal/zod-compat.js +39 -70
- package/dist/internal/zod-json-schema.d.ts +18 -54
- package/dist/internal/zod-json-schema.js +46 -123
- package/dist/jsx-runtime.d.ts +3 -8
- package/dist/lambda/index.d.ts +17 -79
- package/dist/lambda/index.js +11 -59
- package/dist/logging/LogManager.d.ts +1 -51
- package/dist/logging/Logger.d.ts +8 -47
- package/dist/logging/channels/ConsoleChannel.d.ts +1 -3
- package/dist/logging/channels/DailyFileChannel.d.ts +1 -3
- package/dist/logging/channels/FileChannel.d.ts +1 -3
- package/dist/logging/daily-file-path.d.ts +7 -16
- package/dist/logging/index.js +1 -1
- package/dist/logging/types.d.ts +13 -45
- package/dist/{logging-B-kngi3q.js → logging-zOY1XCtq.js} +52 -141
- package/dist/{loopback-guard-D0Kc7-xc.js → loopback-guard-DT9gHF0F.js} +41 -92
- package/dist/mail/Mail.d.ts +10 -106
- package/dist/mail/MailManager.d.ts +2 -60
- package/dist/mail/index.js +1 -1
- package/dist/mail/transports/LogTransport.d.ts +1 -4
- package/dist/mail/transports/MemoryTransport.d.ts +1 -63
- package/dist/mail/transports/ResendTransport.d.ts +1 -23
- package/dist/mail/transports/SmtpTransport.d.ts +1 -31
- package/dist/mail/types.d.ts +28 -150
- package/dist/{mail-DfEfSQEr.js → mail-76DWy9lj.js} +31 -289
- package/dist/mcp/McpServiceProvider.d.ts +4 -10
- package/dist/mcp/create-mcp-server.d.ts +42 -57
- package/dist/mcp/endpoint.d.ts +12 -36
- package/dist/mcp/index.js +1 -1
- package/dist/mvc/Controller.d.ts +46 -227
- package/dist/mvc/Router.d.ts +50 -129
- package/dist/mvc/inertia/InertiaEngine.d.ts +18 -48
- package/dist/mvc/inertia/shared.d.ts +6 -19
- package/dist/mvc/mount-route.d.ts +2 -6
- package/dist/mvc/view.d.ts +1 -2
- package/dist/notifications/Notification.d.ts +8 -75
- package/dist/notifications/NotificationManager.d.ts +15 -88
- package/dist/notifications/channels/DatabaseChannel.d.ts +1 -41
- package/dist/notifications/channels/MailChannel.d.ts +2 -31
- package/dist/notifications/channels/MemoryChannel.d.ts +2 -62
- package/dist/notifications/channels/SlackChannel.d.ts +3 -48
- package/dist/notifications/index.js +1 -1
- package/dist/notifications/notifiable-type.d.ts +3 -6
- package/dist/notifications/registry.d.ts +8 -27
- package/dist/notifications/types.d.ts +16 -53
- package/dist/{notifications-BGqmUNZ8.js → notifications-okWFs9ly.js} +37 -335
- package/dist/providers/AuthServiceProvider.d.ts +1 -3
- package/dist/providers/AuthorizationServiceProvider.d.ts +2 -3
- package/dist/providers/BroadcastServiceProvider.d.ts +1 -3
- package/dist/providers/CacheServiceProvider.d.ts +1 -3
- package/dist/providers/EncryptionServiceProvider.d.ts +1 -3
- package/dist/providers/ErrorServiceProvider.d.ts +1 -4
- package/dist/providers/EventServiceProvider.d.ts +1 -3
- package/dist/providers/HealthServiceProvider.d.ts +1 -3
- package/dist/providers/I18nServiceProvider.d.ts +6 -10
- package/dist/providers/InertiaServiceProvider.d.ts +1 -4
- package/dist/providers/LogServiceProvider.d.ts +1 -3
- package/dist/providers/MailServiceProvider.d.ts +1 -3
- package/dist/providers/NotificationServiceProvider.d.ts +1 -3
- package/dist/providers/OAuthServiceProvider.d.ts +1 -3
- package/dist/providers/QueueServiceProvider.d.ts +1 -3
- package/dist/providers/SchedulingServiceProvider.d.ts +1 -3
- package/dist/providers/StorageServiceProvider.d.ts +1 -3
- package/dist/queue/FailedJobReporter.d.ts +1 -24
- package/dist/queue/Job.d.ts +12 -99
- package/dist/queue/QueueManager.d.ts +6 -57
- package/dist/queue/Worker.d.ts +4 -65
- package/dist/queue/drivers/MemoryDriver.d.ts +3 -44
- package/dist/queue/drivers/RedisDriver.d.ts +7 -65
- package/dist/queue/drivers/SqsDriver.d.ts +6 -57
- package/dist/queue/drivers/SyncDriver.d.ts +10 -13
- package/dist/queue/index.js +2 -2
- package/dist/queue/types.d.ts +10 -92
- package/dist/{queue-CXrRK85G.js → queue-CcXCjuJI.js} +32 -260
- package/dist/redis/RedisApiTokenStore.d.ts +4 -56
- package/dist/redis/RedisEmailVerificationStore.d.ts +4 -37
- package/dist/redis/RedisOAuthStateStore.d.ts +2 -10
- package/dist/redis/RedisPasswordResetStore.d.ts +4 -37
- package/dist/redis/RedisRateLimitStore.d.ts +16 -49
- package/dist/redis/RedisSessionStore.d.ts +3 -44
- package/dist/redis/client.d.ts +2 -32
- package/dist/redis/index.js +47 -232
- package/dist/redis/redis-values.d.ts +6 -12
- package/dist/redis/scan-keys.d.ts +1 -4
- package/dist/request-CLOYytGP.js +68 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.js +50 -92
- package/dist/scheduling/CronParser.d.ts +0 -29
- package/dist/scheduling/Schedule.d.ts +1 -153
- package/dist/scheduling/ScheduledTask.d.ts +0 -31
- package/dist/scheduling/Scheduler.d.ts +0 -70
- package/dist/scheduling/index.js +1 -1
- package/dist/scheduling/types.d.ts +4 -65
- package/dist/{scheduling-CPiEdtQd.js → scheduling-C6tcOtUl.js} +2 -287
- package/dist/storage/StorageManager.d.ts +0 -48
- package/dist/storage/drivers/LocalDriver.d.ts +1 -25
- package/dist/storage/drivers/MemoryDriver.d.ts +5 -35
- package/dist/storage/drivers/S3Driver.d.ts +6 -36
- package/dist/storage/drivers/s3-acl.d.ts +5 -10
- package/dist/storage/index.js +1 -1
- package/dist/storage/types.d.ts +27 -265
- package/dist/{storage-TLD9t0Q2.js → storage-BB59f07j.js} +17 -157
- package/dist/support/contained-path.d.ts +10 -20
- package/dist/support/error-polyfill.d.ts +4 -6
- package/dist/support/expiry.d.ts +17 -33
- package/dist/support/expiry.js +17 -33
- package/dist/support/import-map.d.ts +3 -7
- package/dist/support/inertia-defaults.d.ts +5 -10
- package/dist/support/redirect-target.d.ts +4 -6
- package/dist/support/stack-frames.d.ts +11 -50
- package/dist/support/trim-slashes.d.ts +4 -7
- package/dist/support/warn-once.d.ts +2 -6
- package/dist/{trim-slashes-ZJ_VsY5s.js → trim-slashes-BLY9hKAa.js} +4 -7
- package/dist/{vite-manifest-w_RSOvQW.js → vite-manifest-B_Iy5183.js} +34 -58
- package/package.json +2 -2
- package/dist/client-Dd7vLcqp.js +0 -27
- package/dist/context-DoD0c7J_.js +0 -26
- package/dist/endpoint-D-20PiHY.js +0 -46
- package/dist/hot-disposables-WsTX2ySN.js +0 -281
- package/dist/request-CVQwpu2J.js +0 -129
|
@@ -1,39 +1,21 @@
|
|
|
1
1
|
import type { MiddlewareHandler, Context } from 'hono';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*/
|
|
2
|
+
import type { ContentfulStatusCode } from 'hono/utils/http-status';
|
|
3
|
+
/** Rate limit entry stored in the backing store. */
|
|
5
4
|
export interface RateLimitEntry {
|
|
6
5
|
count: number;
|
|
7
6
|
resetAt: number;
|
|
8
7
|
}
|
|
9
|
-
/**
|
|
10
|
-
* Store interface for rate limit data.
|
|
11
|
-
* Implement this for Redis or database-backed storage.
|
|
12
|
-
*/
|
|
8
|
+
/** Store interface for rate limit data; implement for Redis or database-backed storage. */
|
|
13
9
|
export interface RateLimitStore {
|
|
14
|
-
/**
|
|
15
|
-
* Get the current rate limit entry for a key.
|
|
16
|
-
*/
|
|
17
10
|
get(key: string): Promise<RateLimitEntry | null>;
|
|
18
|
-
/**
|
|
19
|
-
* Increment the count for a key and return the new entry.
|
|
20
|
-
* If the key doesn't exist, create it with count=1.
|
|
21
|
-
*/
|
|
11
|
+
/** Increments the count for a key, creating it with count=1 when absent. */
|
|
22
12
|
increment(key: string, windowMs: number): Promise<RateLimitEntry>;
|
|
23
|
-
/**
|
|
24
|
-
* Reset the count for a key.
|
|
25
|
-
*/
|
|
26
13
|
reset(key: string): Promise<void>;
|
|
27
14
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Base class for in-memory rate limit stores with automatic cleanup.
|
|
30
|
-
*/
|
|
31
15
|
declare abstract class BaseMemoryStore implements RateLimitStore {
|
|
32
16
|
protected readonly now: () => number;
|
|
33
17
|
protected cleanupInterval?: ReturnType<typeof setInterval>;
|
|
34
18
|
/**
|
|
35
|
-
* This store's claim on its hot-reload slot, if it holds one.
|
|
36
|
-
*
|
|
37
19
|
* Unlike the cache sweep, this interval is not `unref()`ed, so a leaked one
|
|
38
20
|
* both duplicates work and keeps the process alive on its own.
|
|
39
21
|
*/
|
|
@@ -47,10 +29,7 @@ declare abstract class BaseMemoryStore implements RateLimitStore {
|
|
|
47
29
|
abstract get size(): number;
|
|
48
30
|
destroy(): void;
|
|
49
31
|
}
|
|
50
|
-
/**
|
|
51
|
-
* In-memory rate limit store.
|
|
52
|
-
* Suitable for single-process development, not for production clusters.
|
|
53
|
-
*/
|
|
32
|
+
/** In-memory store: single-process development only, not production clusters. */
|
|
54
33
|
export declare class MemoryRateLimitStore extends BaseMemoryStore {
|
|
55
34
|
private entries;
|
|
56
35
|
get(key: string): Promise<RateLimitEntry | null>;
|
|
@@ -60,145 +39,69 @@ export declare class MemoryRateLimitStore extends BaseMemoryStore {
|
|
|
60
39
|
clear(): void;
|
|
61
40
|
get size(): number;
|
|
62
41
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Configuration options for rate limiting.
|
|
65
|
-
*/
|
|
42
|
+
/** Configuration options for rate limiting. */
|
|
66
43
|
export interface RateLimitOptions {
|
|
67
|
-
/**
|
|
68
|
-
* Maximum number of requests allowed in the time window.
|
|
69
|
-
* @default 100
|
|
70
|
-
*/
|
|
44
|
+
/** Maximum requests allowed in the window. @default 100 */
|
|
71
45
|
limit?: number;
|
|
72
|
-
/**
|
|
73
|
-
* Time window in milliseconds.
|
|
74
|
-
* @default 60000 (1 minute)
|
|
75
|
-
*/
|
|
46
|
+
/** Time window in milliseconds. @default 60000 (1 minute) */
|
|
76
47
|
windowMs?: number;
|
|
77
|
-
/**
|
|
78
|
-
* Function to extract the rate limit key from the request.
|
|
79
|
-
* Defaults to using the client IP address.
|
|
80
|
-
*/
|
|
48
|
+
/** Defaults to the client IP address. */
|
|
81
49
|
keyGenerator?: (ctx: Context) => string | Promise<string>;
|
|
82
|
-
/**
|
|
83
|
-
* Rate limit store implementation.
|
|
84
|
-
* Defaults to in-memory store.
|
|
85
|
-
*/
|
|
50
|
+
/** Defaults to an in-memory store. */
|
|
86
51
|
store?: RateLimitStore;
|
|
87
|
-
/**
|
|
88
|
-
* Whether to skip rate limiting for certain requests.
|
|
89
|
-
*/
|
|
52
|
+
/** Skip rate limiting for certain requests. */
|
|
90
53
|
skip?: (ctx: Context) => boolean | Promise<boolean>;
|
|
91
|
-
/**
|
|
92
|
-
* Custom handler when rate limit is exceeded.
|
|
93
|
-
*/
|
|
54
|
+
/** Custom handler when the rate limit is exceeded. */
|
|
94
55
|
onRateLimited?: (ctx: Context, retryAfter: number) => Response | Promise<Response>;
|
|
95
|
-
/**
|
|
96
|
-
* Whether to add rate limit headers to all responses.
|
|
97
|
-
* @default true
|
|
98
|
-
*/
|
|
56
|
+
/** Add rate limit headers to all responses. @default true */
|
|
99
57
|
headers?: boolean;
|
|
100
|
-
/**
|
|
101
|
-
* Custom message when rate limit is exceeded.
|
|
102
|
-
* @default 'Too many requests, please try again later.'
|
|
103
|
-
*/
|
|
58
|
+
/** @default 'Too many requests, please try again later.' */
|
|
104
59
|
message?: string;
|
|
105
|
-
/**
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
*/
|
|
109
|
-
statusCode?: number;
|
|
110
|
-
/**
|
|
111
|
-
* Prefix for rate limit keys.
|
|
112
|
-
* @default 'rl:'
|
|
113
|
-
*/
|
|
60
|
+
/** @default 429 */
|
|
61
|
+
statusCode?: ContentfulStatusCode;
|
|
62
|
+
/** @default 'rl:' */
|
|
114
63
|
keyPrefix?: string;
|
|
115
64
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* supplied, the store created for this middleware. A custom store keeps
|
|
120
|
-
* its own clock — construct it with the same `now` to stay coherent.
|
|
65
|
+
* Epoch-millisecond clock, injectable so tests advance time without sleeping.
|
|
66
|
+
* Drives Retry-After and, when no `store` is supplied, the store created here;
|
|
67
|
+
* a custom store keeps its own clock, so construct it with the same `now`.
|
|
121
68
|
* @default () => Date.now()
|
|
122
69
|
*/
|
|
123
70
|
now?: () => number;
|
|
124
71
|
/**
|
|
125
|
-
* Trust reverse-proxy headers for client IP
|
|
126
|
-
* `
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* Enable ONLY when every request passes through a proxy that sets or strips
|
|
130
|
-
* these headers — on direct deployments clients can spoof them to bypass
|
|
131
|
-
* per-client limits. Ignored when a custom `keyGenerator` is supplied.
|
|
72
|
+
* Trust reverse-proxy headers for client IP, in order: `CF-Connecting-IP`,
|
|
73
|
+
* `True-Client-IP`, `X-Real-IP`, first entry of `X-Forwarded-For`; falls back
|
|
74
|
+
* to `server.requestIP()`. Enable ONLY behind a proxy that sets or strips
|
|
75
|
+
* them, or clients spoof them to bypass limits. Ignored with a custom `keyGenerator`.
|
|
132
76
|
* @default false
|
|
133
77
|
*/
|
|
134
78
|
trustProxy?: boolean;
|
|
135
79
|
}
|
|
136
80
|
/**
|
|
137
81
|
* Create a rate limiting middleware.
|
|
138
|
-
*
|
|
139
82
|
* @example
|
|
140
83
|
* ```ts
|
|
141
|
-
*
|
|
142
|
-
* app.use('*', createRateLimitMiddleware())
|
|
143
|
-
*
|
|
144
|
-
* // Stricter limit for login endpoint
|
|
145
|
-
* router.post('/login', [AuthController, 'login'],
|
|
146
|
-
* createRateLimitMiddleware({
|
|
147
|
-
* limit: 5,
|
|
148
|
-
* windowMs: 15 * 60 * 1000, // 15 minutes
|
|
149
|
-
* })
|
|
150
|
-
* )
|
|
151
|
-
*
|
|
152
|
-
* // Custom key based on authenticated user
|
|
153
|
-
* app.use('/api/*', createRateLimitMiddleware({
|
|
154
|
-
* limit: 1000,
|
|
155
|
-
* windowMs: 60 * 60 * 1000, // 1 hour
|
|
156
|
-
* keyGenerator: async (ctx) => {
|
|
157
|
-
* const user = await ctx.get('user')
|
|
158
|
-
* return user?.id?.toString() ?? defaultKeyGenerator(ctx)
|
|
159
|
-
* },
|
|
160
|
-
* }))
|
|
84
|
+
* app.use('*', createRateLimitMiddleware({ limit: 100, windowMs: 60000 }))
|
|
161
85
|
* ```
|
|
162
86
|
*/
|
|
163
87
|
export declare function createRateLimitMiddleware(options?: RateLimitOptions): MiddlewareHandler;
|
|
164
|
-
/**
|
|
165
|
-
* Rate limit result information.
|
|
166
|
-
*/
|
|
88
|
+
/** Rate limit result information. */
|
|
167
89
|
export interface RateLimitInfo {
|
|
168
90
|
limit: number;
|
|
169
91
|
remaining: number;
|
|
170
92
|
resetAt: Date;
|
|
171
93
|
isLimited: boolean;
|
|
172
94
|
}
|
|
173
|
-
/**
|
|
174
|
-
* Get rate limit information for a key without incrementing.
|
|
175
|
-
*
|
|
176
|
-
* @example
|
|
177
|
-
* ```ts
|
|
178
|
-
* const info = await getRateLimitInfo('user:123', store, { limit: 100 })
|
|
179
|
-
* console.log(`${info.remaining} requests remaining`)
|
|
180
|
-
* ```
|
|
181
|
-
*/
|
|
95
|
+
/** Get rate limit information for a key without incrementing. */
|
|
182
96
|
export declare function getRateLimitInfo(key: string, store: RateLimitStore, options?: {
|
|
183
97
|
limit: number;
|
|
184
98
|
keyPrefix?: string;
|
|
185
99
|
}): Promise<RateLimitInfo>;
|
|
186
|
-
/**
|
|
187
|
-
* Reset rate limit for a specific key.
|
|
188
|
-
*
|
|
189
|
-
* @example
|
|
190
|
-
* ```ts
|
|
191
|
-
* // Reset rate limit after successful captcha
|
|
192
|
-
* await resetRateLimit(clientIp, store)
|
|
193
|
-
* ```
|
|
194
|
-
*/
|
|
100
|
+
/** Reset the rate limit for a specific key. */
|
|
195
101
|
export declare function resetRateLimit(key: string, store: RateLimitStore, options?: {
|
|
196
102
|
keyPrefix?: string;
|
|
197
103
|
}): Promise<void>;
|
|
198
|
-
/**
|
|
199
|
-
* Sliding window rate limit store.
|
|
200
|
-
* More accurate than fixed window but uses more memory.
|
|
201
|
-
*/
|
|
104
|
+
/** More accurate than the fixed window store, at more memory. */
|
|
202
105
|
export declare class SlidingWindowRateLimitStore extends BaseMemoryStore {
|
|
203
106
|
private requests;
|
|
204
107
|
get(key: string): Promise<RateLimitEntry | null>;
|
|
@@ -5,25 +5,7 @@ export interface RedirectSafetyOptions {
|
|
|
5
5
|
/** Fallback URL when an unsafe redirect is blocked. Default: '/' */
|
|
6
6
|
fallbackUrl?: string;
|
|
7
7
|
}
|
|
8
|
-
/**
|
|
9
|
-
* Middleware that prevents open redirect attacks by validating
|
|
10
|
-
* redirect destinations in 3xx responses.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { createRedirectSafetyMiddleware } from '@guren/core'
|
|
15
|
-
*
|
|
16
|
-
* app.use('*', createRedirectSafetyMiddleware({
|
|
17
|
-
* allowedHosts: ['accounts.google.com'],
|
|
18
|
-
* }))
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
8
|
+
/** Prevents open redirects by validating the `Location` of every 3xx response. */
|
|
21
9
|
export declare function createRedirectSafetyMiddleware(options?: RedirectSafetyOptions): MiddlewareHandler;
|
|
22
|
-
/**
|
|
23
|
-
* Check whether a redirect URL is safe (same-origin or in the allowed list).
|
|
24
|
-
*
|
|
25
|
-
* @param url - The redirect target URL
|
|
26
|
-
* @param requestUrl - The current request URL (used to determine the origin)
|
|
27
|
-
* @param allowedHosts - Additional allowed external hosts
|
|
28
|
-
*/
|
|
10
|
+
/** Safe means same-origin as `requestUrl`, or a host in `allowedHosts`. */
|
|
29
11
|
export declare function isSafeRedirectUrl(url: string, requestUrl: string, allowedHosts?: string[]): boolean;
|
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Middleware that generates a unique request ID for each request.
|
|
3
|
-
* Reads from the `X-Request-ID` header if present, otherwise generates one
|
|
4
|
-
* using `crypto.randomUUID()`.
|
|
5
|
-
* Attaches the ID to the Hono context (`c.get('requestId')`) and sets it
|
|
6
|
-
* on the response header.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* import { requestIdMiddleware } from '@guren/core'
|
|
11
|
-
*
|
|
12
|
-
* app.use('*', requestIdMiddleware())
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
1
|
+
/** Exposes the incoming or generated request ID as `c.get('requestId')`. */
|
|
15
2
|
export declare function requestIdMiddleware(): import("hono").MiddlewareHandler<{
|
|
16
3
|
Variables: {
|
|
17
4
|
requestId: string;
|
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* Pairs well with {@link requestIdMiddleware} — if a `requestId` is set on the
|
|
6
|
-
* context, it will be included in the log entry.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* import { requestIdMiddleware, requestLoggingMiddleware } from '@guren/core'
|
|
11
|
-
*
|
|
12
|
-
* app.use('*', requestIdMiddleware())
|
|
13
|
-
* app.use('*', requestLoggingMiddleware())
|
|
14
|
-
* ```
|
|
2
|
+
* Logs one structured JSON line per request. Pairs with {@link requestIdMiddleware}:
|
|
3
|
+
* a `requestId` on the context is included in the entry.
|
|
15
4
|
*/
|
|
16
5
|
export declare function requestLoggingMiddleware(): import("hono").MiddlewareHandler<any, string, {}, Response>;
|
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
import type { Context } from 'hono';
|
|
2
2
|
export type ResponseHeader = readonly [string, string];
|
|
3
3
|
/**
|
|
4
|
-
* Sets each header
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* response
|
|
8
|
-
*
|
|
9
|
-
* a handler returning a raw `new Response(...)` replaces `ctx.res` outright and
|
|
10
|
-
* drops them. That is every asset response the framework itself serves, so a
|
|
11
|
-
* header written the other way is simply absent from them.
|
|
12
|
-
*
|
|
13
|
-
* First writer wins, which preserves the precedence the prepared-header form
|
|
14
|
-
* had: anything registered closer to the handler — a route deliberately
|
|
15
|
-
* relaxing `X-Frame-Options` so it can be embedded, or an inner middleware's
|
|
16
|
-
* stronger `Strict-Transport-Security` — overwrote these before and still does.
|
|
4
|
+
* Sets each header unless the response already carries it. Use this rather than
|
|
5
|
+
* `ctx.header()` for headers that must reach *every* response: prepared headers
|
|
6
|
+
* are dropped by a handler returning a raw `new Response(...)`, which is every
|
|
7
|
+
* asset response the framework serves. First writer wins, so anything registered
|
|
8
|
+
* closer to the handler still overrides these.
|
|
17
9
|
*/
|
|
18
10
|
export declare function applyResponseHeaders(ctx: Context, headers: readonly ResponseHeader[]): void;
|
|
@@ -26,24 +26,10 @@ export interface SecurityHeadersOptions {
|
|
|
26
26
|
hsts?: HstsOptions | false;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
29
|
+
* Sets common HTTP security headers on every response.
|
|
31
30
|
* @example
|
|
32
31
|
* ```ts
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* app.use('*', createSecurityHeaders())
|
|
36
|
-
*
|
|
37
|
-
* // With HSTS enabled
|
|
38
|
-
* app.use('*', createSecurityHeaders({
|
|
39
|
-
* hsts: { maxAge: 31536000, includeSubDomains: true },
|
|
40
|
-
* }))
|
|
41
|
-
*
|
|
42
|
-
* // Disable specific headers
|
|
43
|
-
* app.use('*', createSecurityHeaders({
|
|
44
|
-
* frameOptions: false,
|
|
45
|
-
* xssProtection: false,
|
|
46
|
-
* }))
|
|
32
|
+
* app.use('*', createSecurityHeaders({ hsts: { maxAge: 31536000 } }))
|
|
47
33
|
* ```
|
|
48
34
|
*/
|
|
49
35
|
export declare function createSecurityHeaders(options?: SecurityHeadersOptions): MiddlewareHandler;
|
|
@@ -1,25 +1,16 @@
|
|
|
1
1
|
import type { MiddlewareHandler } from 'hono';
|
|
2
2
|
export type SessionData = Record<string, unknown>;
|
|
3
3
|
export interface SessionStore {
|
|
4
|
-
/**
|
|
5
|
-
* Read a session by its opaque identifier.
|
|
6
|
-
* Returns undefined when the session does not exist or has expired.
|
|
7
|
-
*/
|
|
4
|
+
/** Returns undefined when the session does not exist or has expired. */
|
|
8
5
|
read(id: string): Promise<SessionData | undefined>;
|
|
9
|
-
/**
|
|
10
|
-
* Persist a session using upsert semantics for the given opaque identifier.
|
|
11
|
-
*/
|
|
6
|
+
/** Persist a session using upsert semantics. */
|
|
12
7
|
write(id: string, data: SessionData, ttlSeconds: number): Promise<void>;
|
|
13
|
-
/**
|
|
14
|
-
* Destroy a session. Implementations must treat repeated calls as safe.
|
|
15
|
-
*/
|
|
8
|
+
/** Implementations must treat repeated calls as safe. */
|
|
16
9
|
destroy(id: string): Promise<void>;
|
|
17
10
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* that
|
|
21
|
-
* longer exists — including one that has expired but not yet been swept
|
|
22
|
-
* from storage — must be a no-op, not a resurrection.
|
|
11
|
+
* Refresh an existing session's TTL without rewriting its data (rolling
|
|
12
|
+
* expiry); stores omitting it fall back to a full `write`. Refreshing a
|
|
13
|
+
* session that does not exist must be a no-op, not a resurrection.
|
|
23
14
|
*/
|
|
24
15
|
touch?(id: string, ttlSeconds: number): Promise<void>;
|
|
25
16
|
}
|
|
@@ -54,29 +45,19 @@ export interface Session {
|
|
|
54
45
|
flush(): void;
|
|
55
46
|
all(): SessionData;
|
|
56
47
|
/**
|
|
57
|
-
* Rotate the session id (call after login to mitigate session fixation)
|
|
58
|
-
*
|
|
59
|
-
* limitation
|
|
60
|
-
*
|
|
61
|
-
* resurrected row holds only pre-rotation data (no auth state), so
|
|
62
|
-
* fixation does not escalate, but the row can linger until it expires.
|
|
48
|
+
* Rotate the session id (call after login to mitigate session fixation); the
|
|
49
|
+
* old one is destroyed at request end. Every multi-process store shares one
|
|
50
|
+
* limitation: a concurrent request on the old cookie can re-persist the old
|
|
51
|
+
* id, whose row holds only pre-rotation data and lingers until it expires.
|
|
63
52
|
*/
|
|
64
53
|
regenerate(): void;
|
|
65
54
|
invalidate(): void;
|
|
66
55
|
/**
|
|
67
|
-
* Whether this session survives the current response under `id`.
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* later request finds it. Anything anchoring a value to the session id —
|
|
73
|
-
* CSRF token binding — has to ask this rather than `!isNew`, or it
|
|
74
|
-
* anchors to nothing across the login response.
|
|
75
|
-
*
|
|
76
|
-
* Optional only so a custom `Session` predating it still type-checks.
|
|
77
|
-
* Callers fall back to `!isNew`, which for that implementation reproduces
|
|
78
|
-
* the bug this method exists to prevent — a login response anchors to
|
|
79
|
-
* nothing, and the next mutation is rejected. Implement it.
|
|
56
|
+
* Whether this session survives the current response under `id`. A session
|
|
57
|
+
* created *during* the request stays `isNew` for its lifetime yet is
|
|
58
|
+
* persisted once a handler writes to it, so anything anchoring a value to the
|
|
59
|
+
* session id (CSRF token binding) must ask this, not `!isNew`. Optional only
|
|
60
|
+
* so a custom `Session` predating it type-checks; the `!isNew` fallback has that bug, so implement it.
|
|
80
61
|
*/
|
|
81
62
|
willPersist?(): boolean;
|
|
82
63
|
flash(key: string, value: unknown): void;
|
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
import type { Context, MiddlewareHandler } from 'hono';
|
|
2
2
|
/**
|
|
3
|
-
* Cookie flash for Inertia validation errors on apps with no session
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* but sessions are only mounted when `createApp({ auth })` is configured — a
|
|
7
|
-
* fresh scaffold has none yet. Dropping the errors silently turns every
|
|
8
|
-
* validation failure into "the form did nothing", so without a session the
|
|
9
|
-
* flattened errors ride across the one redirect in a short-lived HttpOnly
|
|
10
|
-
* cookie instead: display-only data, no store required, working on every
|
|
11
|
-
* runtime (Bun, Workers, Lambda).
|
|
3
|
+
* Cookie flash for Inertia validation errors on apps with no session (sessions
|
|
4
|
+
* are only mounted by `createApp({ auth })`, so a fresh scaffold has none).
|
|
5
|
+
* Display-only data riding one redirect: no store, every runtime.
|
|
12
6
|
*/
|
|
13
7
|
export declare const VALIDATION_ERRORS_COOKIE = "guren_validation_errors";
|
|
14
|
-
/**
|
|
15
|
-
* The `Set-Cookie` value that flashes `errors` across the next redirect.
|
|
16
|
-
*/
|
|
8
|
+
/** The `Set-Cookie` value that flashes `errors` across the next redirect. */
|
|
17
9
|
export declare function validationErrorsSetCookie(errors: Record<string, string>): string;
|
|
18
10
|
/**
|
|
19
11
|
* The flashed errors carried by the current request, if any. Reading consumes
|
|
@@ -21,11 +13,8 @@ export declare function validationErrorsSetCookie(errors: Record<string, string>
|
|
|
21
13
|
*/
|
|
22
14
|
export declare function readValidationErrorsCookie(ctx: Context): Record<string, string> | undefined;
|
|
23
15
|
/**
|
|
24
|
-
* Expires the flash cookie on the response whose render consumed it,
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* cookie on its 303) never reaches the deletion — and the `getSetCookie`
|
|
28
|
-
* guard covers any other path that just wrote the cookie on this same
|
|
29
|
-
* response.
|
|
16
|
+
* Expires the flash cookie on the response whose render consumed it, restoring
|
|
17
|
+
* show-once semantics. The `getSetCookie` guard keeps it from deleting a fresh
|
|
18
|
+
* cookie another path wrote on this same response.
|
|
30
19
|
*/
|
|
31
20
|
export declare function createValidationErrorsCookieCleanup(): MiddlewareHandler;
|
|
@@ -12,79 +12,24 @@ export interface ValidationSchema<T = unknown> {
|
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
export interface ValidateRequestOptions {
|
|
15
|
-
/**
|
|
16
|
-
* Custom error handler when validation fails.
|
|
17
|
-
* Defaults to returning a 422 JSON response with formatted errors.
|
|
18
|
-
*/
|
|
15
|
+
/** Defaults to a 422 JSON response with formatted errors. */
|
|
19
16
|
onError?: (ctx: Context, errors: Record<string, string>) => Response | Promise<Response>;
|
|
20
|
-
/**
|
|
21
|
-
* HTTP status code for validation errors.
|
|
22
|
-
* Defaults to 422 (Unprocessable Entity).
|
|
23
|
-
*/
|
|
17
|
+
/** @default 422 */
|
|
24
18
|
status?: number;
|
|
25
|
-
/**
|
|
26
|
-
* Fallback message when no field-specific errors are available.
|
|
27
|
-
*/
|
|
19
|
+
/** Used when no field-specific errors are available. */
|
|
28
20
|
fallbackMessage?: string;
|
|
29
21
|
}
|
|
30
|
-
/**
|
|
31
|
-
* Get validated data from the request context.
|
|
32
|
-
* Returns undefined if validation middleware hasn't run or validation failed.
|
|
33
|
-
*/
|
|
22
|
+
/** Undefined when the validation middleware has not run, or validation failed. */
|
|
34
23
|
export declare function getValidatedData<T = Record<string, unknown>>(ctx: Context): T | undefined;
|
|
35
24
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```ts
|
|
40
|
-
* import { z } from 'zod'
|
|
41
|
-
* import { validateRequest, getValidatedData } from '@guren/server'
|
|
42
|
-
*
|
|
43
|
-
* const CreateUserSchema = z.object({
|
|
44
|
-
* name: z.string().min(1),
|
|
45
|
-
* email: z.email(),
|
|
46
|
-
* })
|
|
47
|
-
*
|
|
48
|
-
* app.post('/users', validateRequest(CreateUserSchema), (c) => {
|
|
49
|
-
* const data = getValidatedData<z.infer<typeof CreateUserSchema>>(c)
|
|
50
|
-
* // data is typed and validated
|
|
51
|
-
* return c.json({ user: data })
|
|
52
|
-
* })
|
|
53
|
-
* ```
|
|
25
|
+
* Validates the request body against a schema; read it with {@link getValidatedData}.
|
|
54
26
|
*/
|
|
55
27
|
export declare function validateRequest<T>(schema: ValidationSchema<T>, options?: ValidateRequestOptions): MiddlewareHandler;
|
|
56
|
-
/**
|
|
57
|
-
* Creates a validation middleware from a schema factory function.
|
|
58
|
-
* Useful when the schema depends on request context.
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* ```ts
|
|
62
|
-
* app.post('/users/:role', validateRequestWith((ctx) => {
|
|
63
|
-
* const role = ctx.req.param('role')
|
|
64
|
-
* return role === 'admin' ? AdminSchema : UserSchema
|
|
65
|
-
* }), handler)
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
28
|
+
/** Like {@link validateRequest}, for a schema that depends on request context. */
|
|
68
29
|
export declare function validateRequestWith<T>(schemaFactory: (ctx: Context) => ValidationSchema<T>, options?: ValidateRequestOptions): MiddlewareHandler;
|
|
69
|
-
/**
|
|
70
|
-
* Validates data against a schema and throws if invalid.
|
|
71
|
-
* Useful for manual validation in handlers.
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* ```ts
|
|
75
|
-
* app.post('/data', async (c) => {
|
|
76
|
-
* const payload = await parseRequestPayload(c)
|
|
77
|
-
* const data = validate(MySchema, payload)
|
|
78
|
-
* // throws ValidationError if invalid
|
|
79
|
-
* return c.json(data)
|
|
80
|
-
* })
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
30
|
+
/** Manual validation for handlers; throws when the data is invalid. */
|
|
83
31
|
export declare function validate<T>(schema: ValidationSchema<T>, data: unknown): T;
|
|
84
|
-
/**
|
|
85
|
-
* Validates data against a schema and returns a result object.
|
|
86
|
-
* Does not throw on validation failure.
|
|
87
|
-
*/
|
|
32
|
+
/** Like {@link validate}, but reports failure in the result instead of throwing. */
|
|
88
33
|
export declare function validateSafe<T>(schema: ValidationSchema<T>, data: unknown): {
|
|
89
34
|
success: true;
|
|
90
35
|
data: T;
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import type { Application } from './Application.js';
|
|
2
|
+
/**
|
|
3
|
+
* The root-asset extensions served when `rootPublicAssets.extensions` is
|
|
4
|
+
* omitted. Exported because the option *replaces* this list rather than
|
|
5
|
+
* extending it — an app that wants one more extension spreads this rather
|
|
6
|
+
* than restating it, so additions here reach it.
|
|
7
|
+
*/
|
|
8
|
+
export declare const DEFAULT_ROOT_PUBLIC_ASSET_EXTENSIONS: readonly ['.svg', '.png', '.jpg', '.jpeg', '.gif', '.ico', '.webp', '.avif', '.webmanifest', '.txt'];
|
|
2
9
|
export type RootPublicAssetsConfig = boolean | RootPublicAssetsOptions;
|
|
3
10
|
export interface RootPublicAssetsOptions {
|
|
4
11
|
/** Enable or disable root-level public asset serving. Defaults to true. */
|
|
@@ -12,13 +19,10 @@ export interface RootPublicAssetsOptions {
|
|
|
12
19
|
/** Override content types per extension. */
|
|
13
20
|
contentTypeMap?: Record<string, string>;
|
|
14
21
|
/**
|
|
15
|
-
* Serve document types (`.svg`, `.html`, XML) inline
|
|
16
|
-
* to
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* land — `.svg` is in the default extension list, and an SVG navigated to
|
|
20
|
-
* directly is script in the app's own origin. Turn it on only for a
|
|
21
|
-
* directory holding nothing user-supplied.
|
|
22
|
+
* Serve document types (`.svg`, `.html`, XML) inline rather than as downloads.
|
|
23
|
+
* Defaults to false because uploads land in this directory too, and an SVG
|
|
24
|
+
* navigated to directly is script in the app's own origin. Turn it on only
|
|
25
|
+
* for a directory holding nothing user-supplied.
|
|
22
26
|
*/
|
|
23
27
|
inlineDocuments?: boolean;
|
|
24
28
|
}
|