@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,192 +1,56 @@
|
|
|
1
1
|
import type { Context } from '../http/Application.js';
|
|
2
2
|
import type { AuthUser, GateCallback, GateBeforeCallback, GateDefinition, GateOptions, PolicyClass, Policy, AuthorizationResponse, ResponseBuilder } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Response builder for authorization checks.
|
|
5
|
-
*/
|
|
3
|
+
/** Response builder for authorization checks. */
|
|
6
4
|
export declare const Response: ResponseBuilder;
|
|
7
|
-
/**
|
|
8
|
-
* Narrow a policy/gate return value to an `AuthorizationResponse`.
|
|
9
|
-
*
|
|
10
|
-
* Policies may return either a boolean or one of the `Response` objects
|
|
11
|
-
* produced by `allow()`/`deny()`/`denyWithStatus()`/`denyAsNotFound()`.
|
|
12
|
-
*/
|
|
5
|
+
/** Narrow a policy/gate return value to an `AuthorizationResponse`. */
|
|
13
6
|
export declare function isAuthorizationResponse(value: unknown): value is AuthorizationResponse;
|
|
14
|
-
/**
|
|
15
|
-
* Build the exception for a denial, honouring `denyWithStatus()` /
|
|
16
|
-
* `denyAsNotFound()` so a policy can hide a record as a 404.
|
|
17
|
-
*/
|
|
7
|
+
/** Honours `denyWithStatus()` / `denyAsNotFound()` so a policy can hide a record as a 404. */
|
|
18
8
|
export declare function denialToException(response: AuthorizationResponse): Error;
|
|
19
|
-
/**
|
|
20
|
-
* Authorization gate for defining and checking abilities.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```typescript
|
|
24
|
-
* const gate = new Gate()
|
|
25
|
-
*
|
|
26
|
-
* // Define abilities
|
|
27
|
-
* gate.define('edit-post', (user, post) => user.id === post.authorId)
|
|
28
|
-
* gate.define('admin', (user) => user.role === 'admin')
|
|
29
|
-
*
|
|
30
|
-
* // Check abilities
|
|
31
|
-
* if (await gate.allows('edit-post', post)) {
|
|
32
|
-
* // User can edit
|
|
33
|
-
* }
|
|
34
|
-
*
|
|
35
|
-
* // Or throw on denial
|
|
36
|
-
* await gate.authorize('edit-post', post) // throws if not allowed
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
9
|
+
/** Authorization gate for defining and checking abilities. */
|
|
39
10
|
export declare class Gate {
|
|
40
|
-
/**
|
|
41
|
-
* Defined gates.
|
|
42
|
-
*/
|
|
43
11
|
protected gates: Map<string, GateDefinition>;
|
|
44
|
-
/**
|
|
45
|
-
* Registered policies.
|
|
46
|
-
*/
|
|
47
12
|
protected policies: Map<unknown, PolicyClass>;
|
|
48
|
-
/**
|
|
49
|
-
* Policy instances cache.
|
|
50
|
-
*/
|
|
51
13
|
protected policyInstances: Map<PolicyClass, Policy>;
|
|
52
|
-
/**
|
|
53
|
-
* Before callbacks.
|
|
54
|
-
*/
|
|
55
14
|
protected beforeCallbacks: GateBeforeCallback[];
|
|
56
|
-
/**
|
|
57
|
-
* After callbacks.
|
|
58
|
-
*/
|
|
59
15
|
protected afterCallbacks: Array<(user: AuthUser | null, ability: string, result: boolean, args: unknown[]) => void | Promise<void>>;
|
|
60
|
-
/**
|
|
61
|
-
* User resolver function.
|
|
62
|
-
*/
|
|
63
16
|
protected userResolver?: (ctx: Context) => AuthUser | null | Promise<AuthUser | null>;
|
|
64
|
-
/**
|
|
65
|
-
* Current user for checks.
|
|
66
|
-
*/
|
|
67
17
|
protected currentUser: AuthUser | null;
|
|
68
18
|
constructor(options?: GateOptions);
|
|
69
|
-
/**
|
|
70
|
-
* Define a new gate.
|
|
71
|
-
*/
|
|
72
19
|
define<Args extends unknown[]>(ability: string, callback: GateCallback<Args>): this;
|
|
73
|
-
/**
|
|
74
|
-
* Register a policy for a model class.
|
|
75
|
-
*/
|
|
76
20
|
policy(modelClass: unknown, policyClass: PolicyClass): this;
|
|
77
|
-
/**
|
|
78
|
-
* Register a before callback.
|
|
79
|
-
* Return true to allow, false to deny, undefined to continue.
|
|
80
|
-
*/
|
|
21
|
+
/** Return true to allow, false to deny, undefined to continue. */
|
|
81
22
|
before<Args extends unknown[]>(callback: GateBeforeCallback<Args>): this;
|
|
82
|
-
/**
|
|
83
|
-
* Register an after callback.
|
|
84
|
-
*/
|
|
85
23
|
after(callback: (user: AuthUser | null, ability: string, result: boolean, args: unknown[]) => void | Promise<void>): this;
|
|
86
|
-
/**
|
|
87
|
-
* Set the current user for authorization checks.
|
|
88
|
-
*/
|
|
89
24
|
forUser(user: AuthUser | null): this;
|
|
90
|
-
/**
|
|
91
|
-
* Resolve the user from context.
|
|
92
|
-
*/
|
|
93
25
|
resolveUser(ctx: Context): Promise<AuthUser | null>;
|
|
94
|
-
/**
|
|
95
|
-
* Check if the user has the given ability.
|
|
96
|
-
*/
|
|
97
26
|
allows(ability: string, ...args: unknown[]): Promise<boolean>;
|
|
98
|
-
/**
|
|
99
|
-
* Check if the user doesn't have the given ability.
|
|
100
|
-
*/
|
|
101
27
|
denies(ability: string, ...args: unknown[]): Promise<boolean>;
|
|
102
|
-
/**
|
|
103
|
-
* Check if the user has any of the given abilities.
|
|
104
|
-
*/
|
|
105
28
|
any(abilities: string[], ...args: unknown[]): Promise<boolean>;
|
|
106
|
-
/**
|
|
107
|
-
* Check if the user has all of the given abilities.
|
|
108
|
-
*/
|
|
109
29
|
all(abilities: string[], ...args: unknown[]): Promise<boolean>;
|
|
110
|
-
/**
|
|
111
|
-
* Check if the user has none of the given abilities.
|
|
112
|
-
*/
|
|
113
30
|
none(abilities: string[], ...args: unknown[]): Promise<boolean>;
|
|
114
|
-
/**
|
|
115
|
-
* Authorize the ability or throw an exception.
|
|
116
|
-
*/
|
|
117
31
|
authorize(ability: string, ...args: unknown[]): Promise<void>;
|
|
118
|
-
/**
|
|
119
|
-
* Get the authorization response.
|
|
120
|
-
*/
|
|
121
32
|
inspect(ability: string, ...args: unknown[]): Promise<AuthorizationResponse>;
|
|
122
|
-
/**
|
|
123
|
-
* Check the ability with a specific user.
|
|
124
|
-
*/
|
|
125
33
|
check(ability: string, user: AuthUser | null, ...args: unknown[]): Promise<boolean>;
|
|
126
|
-
/**
|
|
127
|
-
* Check the ability with a specific user and keep the full response.
|
|
128
|
-
*
|
|
129
|
-
* Policies may answer with a boolean or with a `Response` object. Both
|
|
130
|
-
* shapes are normalized here so no caller has to truthy-test a
|
|
131
|
-
* `{ allowed: false }` object.
|
|
132
|
-
*/
|
|
34
|
+
/** Like check(), but keeps the full response instead of just `allowed`. */
|
|
133
35
|
checkResponse(ability: string, user: AuthUser | null, ...args: unknown[]): Promise<AuthorizationResponse>;
|
|
134
36
|
protected settle(user: AuthUser | null, ability: string, response: AuthorizationResponse, args: unknown[]): Promise<AuthorizationResponse>;
|
|
135
37
|
/**
|
|
136
|
-
* Check a policy for the given ability.
|
|
137
|
-
*
|
|
138
38
|
* The subject may be a class instance (policy resolved via its constructor)
|
|
139
|
-
* or a `[ModelClass, record]` / `['key', record]` tuple
|
|
140
|
-
* required for plain records
|
|
141
|
-
* information.
|
|
39
|
+
* or a `[ModelClass, record]` / `['key', record]` tuple — the tuple form is
|
|
40
|
+
* required for plain ORM records, which carry no constructor information.
|
|
142
41
|
*/
|
|
143
42
|
protected checkPolicy(ability: string, user: AuthUser | null, model: unknown, additionalArgs: unknown[]): Promise<boolean | AuthorizationResponse | undefined>;
|
|
144
|
-
/**
|
|
145
|
-
* Get or create a policy instance.
|
|
146
|
-
*/
|
|
147
43
|
protected getPolicyInstance(policyClass: PolicyClass): Policy;
|
|
148
|
-
/**
|
|
149
|
-
* Run after callbacks.
|
|
150
|
-
*/
|
|
151
44
|
protected runAfterCallbacks(user: AuthUser | null, ability: string, result: boolean, args: unknown[]): Promise<void>;
|
|
152
|
-
/**
|
|
153
|
-
* Get all defined abilities.
|
|
154
|
-
*/
|
|
155
45
|
abilities(): string[];
|
|
156
|
-
/**
|
|
157
|
-
* Check if an ability is defined.
|
|
158
|
-
*/
|
|
159
46
|
has(ability: string): boolean;
|
|
160
|
-
/**
|
|
161
|
-
* Get the policy for a model.
|
|
162
|
-
*/
|
|
163
47
|
getPolicyFor(model: unknown): Policy | undefined;
|
|
164
48
|
}
|
|
165
|
-
/**
|
|
166
|
-
* Create a new gate instance.
|
|
167
|
-
*/
|
|
168
49
|
export declare function createGate(options?: GateOptions): Gate;
|
|
169
|
-
/**
|
|
170
|
-
* Set the global gate instance.
|
|
171
|
-
*/
|
|
172
50
|
export declare function setGate(gate: Gate): void;
|
|
173
|
-
/**
|
|
174
|
-
* Get the global gate instance.
|
|
175
|
-
*/
|
|
176
51
|
export declare function getGate(): Gate;
|
|
177
|
-
/**
|
|
178
|
-
* Define a gate on the global instance.
|
|
179
|
-
*/
|
|
52
|
+
/** Define a gate on the global instance. */
|
|
180
53
|
export declare function defineGate(ability: string, callback: GateCallback): void;
|
|
181
|
-
/**
|
|
182
|
-
* Check if the current user can perform an ability.
|
|
183
|
-
*/
|
|
184
54
|
export declare function can(ability: string, ...args: unknown[]): Promise<boolean>;
|
|
185
|
-
/**
|
|
186
|
-
* Check if the current user cannot perform an ability.
|
|
187
|
-
*/
|
|
188
55
|
export declare function cannot(ability: string, ...args: unknown[]): Promise<boolean>;
|
|
189
|
-
/**
|
|
190
|
-
* Authorize or throw.
|
|
191
|
-
*/
|
|
192
56
|
export declare function authorize(ability: string, ...args: unknown[]): Promise<void>;
|
|
@@ -1,70 +1,23 @@
|
|
|
1
1
|
import type { AuthUser, Policy as PolicyInterface, AuthorizationResponse, PolicyResult } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Base policy class for model authorization.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* class PostPolicy extends Policy {
|
|
8
|
-
* // Runs before all checks - return true/false to short-circuit
|
|
9
|
-
* before(user: AuthUser | null, ability: string) {
|
|
10
|
-
* if (user?.role === 'admin') {
|
|
11
|
-
* return true // Admins can do anything
|
|
12
|
-
* }
|
|
13
|
-
* return undefined // Continue to specific check
|
|
14
|
-
* }
|
|
15
|
-
*
|
|
16
|
-
* viewAny(user: AuthUser | null) {
|
|
17
|
-
* return true // Anyone can view posts list
|
|
18
|
-
* }
|
|
19
|
-
*
|
|
20
|
-
* view(user: AuthUser | null, post: Post) {
|
|
21
|
-
* return post.published || user?.id === post.authorId
|
|
22
|
-
* }
|
|
23
|
-
*
|
|
24
|
-
* create(user: AuthUser | null) {
|
|
25
|
-
* return user !== null
|
|
26
|
-
* }
|
|
27
|
-
*
|
|
28
|
-
* update(user: AuthUser | null, post: Post) {
|
|
29
|
-
* return user?.id === post.authorId
|
|
30
|
-
* }
|
|
31
|
-
*
|
|
32
|
-
* delete(user: AuthUser | null, post: Post) {
|
|
33
|
-
* return user?.id === post.authorId
|
|
34
|
-
* }
|
|
35
|
-
* }
|
|
36
|
-
* ```
|
|
3
|
+
* Base policy class for model authorization. Ability methods are looked up on
|
|
4
|
+
* the subclass by name (`viewAny`, `view`, `create`, `update`, `delete`,
|
|
5
|
+
* `restore`, `forceDelete`, or any custom ability), each taking
|
|
6
|
+
* `(user, model?, ...args)`.
|
|
37
7
|
*/
|
|
38
8
|
export declare abstract class Policy implements PolicyInterface {
|
|
39
|
-
/**
|
|
40
|
-
* Perform pre-authorization checks.
|
|
41
|
-
* Return true to allow, false to deny, undefined to continue to specific check.
|
|
42
|
-
*/
|
|
9
|
+
/** Return true to allow, false to deny, undefined to continue to the ability method. */
|
|
43
10
|
before?(user: AuthUser | null, ability: string): PolicyResult | undefined | Promise<PolicyResult | undefined>;
|
|
44
|
-
/**
|
|
45
|
-
* Allow the action.
|
|
46
|
-
*/
|
|
47
11
|
protected allow(message?: string): AuthorizationResponse;
|
|
48
|
-
/**
|
|
49
|
-
* Deny the action.
|
|
50
|
-
*/
|
|
51
12
|
protected deny(message?: string, code?: string): AuthorizationResponse;
|
|
52
|
-
/**
|
|
53
|
-
* Deny with a specific HTTP status.
|
|
54
|
-
*/
|
|
55
13
|
protected denyWithStatus(status: number, message?: string): AuthorizationResponse & {
|
|
56
14
|
status: number;
|
|
57
15
|
};
|
|
58
|
-
/**
|
|
59
|
-
* Deny as not found (404).
|
|
60
|
-
*/
|
|
61
16
|
protected denyAsNotFound(message?: string): AuthorizationResponse & {
|
|
62
17
|
status: 404;
|
|
63
18
|
};
|
|
64
19
|
}
|
|
65
|
-
/**
|
|
66
|
-
* Create a simple policy from an object.
|
|
67
|
-
*/
|
|
20
|
+
/** Create a policy class from an object of ability functions. */
|
|
68
21
|
export declare function definePolicy<T>(definition: {
|
|
69
22
|
before?: (user: AuthUser | null, ability: string) => PolicyResult | undefined | Promise<PolicyResult | undefined>;
|
|
70
23
|
viewAny?: (user: AuthUser | null) => PolicyResult | Promise<PolicyResult>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as setGate, a as withAuthorization, c as Gate, d as can, f as cannot, g as isAuthorizationResponse, h as getGate, l as Response, m as defineGate, n as authorizeMiddleware, o as Policy, p as createGate, r as authorizeResourceMiddleware, s as definePolicy, t as authorizeAllMiddleware, u as authorize } from "../authorization-
|
|
1
|
+
import { _ as setGate, a as withAuthorization, c as Gate, d as can, f as cannot, g as isAuthorizationResponse, h as getGate, l as Response, m as defineGate, n as authorizeMiddleware, o as Policy, p as createGate, r as authorizeResourceMiddleware, s as definePolicy, t as authorizeAllMiddleware, u as authorize } from "../authorization-CdEWZZw3.js";
|
|
2
2
|
export { Gate, Policy, Response, authorize, authorizeAllMiddleware, authorizeMiddleware, authorizeResourceMiddleware, can, cannot, createGate, defineGate, definePolicy, getGate, isAuthorizationResponse, setGate, withAuthorization };
|
|
@@ -3,82 +3,36 @@ import type { Middleware } from '../http/middleware/index.js';
|
|
|
3
3
|
import type { AuthorizeOptions, AuthorizeResourceOptions } from './types.js';
|
|
4
4
|
import { Gate } from './Gate.js';
|
|
5
5
|
/**
|
|
6
|
-
* Middleware to authorize an ability.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* // Authorize a simple ability
|
|
11
|
-
* app.get('/admin', authorizeMiddleware('admin'), adminHandler)
|
|
12
|
-
*
|
|
13
|
-
* // Authorize with model (from route param)
|
|
14
|
-
* app.put('/posts/:id', authorizeMiddleware('update', getPost), updateHandler)
|
|
15
|
-
*
|
|
16
|
-
* // Multiple abilities (any)
|
|
17
|
-
* app.get('/dashboard', authorizeMiddleware(['admin', 'moderator']), dashboardHandler)
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* An array argument is snapshotted at creation: mutating it afterwards
|
|
21
|
-
* changes neither what the middleware checks nor what it reports. A
|
|
22
|
-
* one-element array is treated exactly like the bare ability, denial message
|
|
23
|
-
* and status included. An empty array denies every request (`Gate.any([])` is
|
|
24
|
-
* false) and names no ability — fail-closed, so it is left to run rather than
|
|
25
|
-
* rejected.
|
|
6
|
+
* Middleware to authorize an ability. An array argument is snapshotted at
|
|
7
|
+
* creation, and a one-element array behaves exactly like the bare ability.
|
|
8
|
+
* An empty array denies every request (`Gate.any([])` is false) — fail-closed,
|
|
9
|
+
* so it is left to run rather than rejected.
|
|
26
10
|
*/
|
|
27
11
|
export declare function authorizeMiddleware(ability: string | string[], modelResolver?: (ctx: Context) => unknown | Promise<unknown>, options?: AuthorizeOptions): Middleware;
|
|
28
12
|
/**
|
|
29
|
-
* Middleware to authorize all given abilities.
|
|
13
|
+
* Middleware to authorize all given abilities. The array is snapshotted at creation.
|
|
30
14
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* @throws if no ability is given. `Gate.all([])` is vacuously true, so an
|
|
35
|
-
* empty list would mount a route that advertises authorization and enforces
|
|
36
|
-
* none — the fail-open shape RFC 0016's "authn is not authz" rule exists to
|
|
37
|
-
* catch. Refusing at creation surfaces it at boot rather than per request.
|
|
15
|
+
* @throws if no ability is given: `Gate.all([])` is vacuously true, so an empty
|
|
16
|
+
* list would advertise authorization and enforce none (RFC 0016).
|
|
38
17
|
*/
|
|
39
18
|
export declare function authorizeAllMiddleware(input: string[], modelResolver?: (ctx: Context) => unknown | Promise<unknown>, options?: AuthorizeOptions): Middleware;
|
|
40
19
|
/**
|
|
41
|
-
* The ability `
|
|
42
|
-
*
|
|
43
|
-
* denies). This is the single source of the verb → ability mapping: a
|
|
44
|
-
* consumer resolving a route's ability from its stamped
|
|
20
|
+
* The single source of the verb → ability mapping; `undefined` for a method it
|
|
21
|
+
* refuses to guess at. A consumer resolving a route's ability from its stamped
|
|
45
22
|
* `authorization.resource` capability calls this rather than restating the
|
|
46
|
-
* table, and may only do so when `resource.fromMethodMap` is true.
|
|
47
|
-
*
|
|
48
|
-
* Not re-exported from the package root — like the capability stamp itself
|
|
49
|
-
* (RFC 0007), this is an internal contract until a public consumer needs it.
|
|
23
|
+
* table, and may only do so when `resource.fromMethodMap` is true. Internal
|
|
24
|
+
* contract (RFC 0007): not re-exported from the package root.
|
|
50
25
|
*/
|
|
51
26
|
export declare function resourceAbilityForMethod(method: string): string | undefined;
|
|
52
27
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* `router.on()`) are denied with a 403 rather than downgraded to a `view`
|
|
58
|
-
* check — the middleware cannot know whether an unknown verb mutates, so
|
|
59
|
-
* guessing would let a view-only user reach a mutating handler. Map custom
|
|
60
|
-
* verbs explicitly with `options.abilityFor`.
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```typescript
|
|
64
|
-
* // Authorize resource actions based on HTTP method
|
|
65
|
-
* app.use('/posts/:id', authorizeResourceMiddleware(getPost))
|
|
66
|
-
* // GET/HEAD/QUERY -> view, POST -> create, PUT/PATCH -> update, DELETE -> delete
|
|
67
|
-
*
|
|
68
|
-
* // Custom verbs must be mapped explicitly, or they are denied
|
|
69
|
-
* authorizeResourceMiddleware(getPost, {
|
|
70
|
-
* abilityFor: (method) => (method === 'PURGE' ? 'delete' : undefined),
|
|
71
|
-
* })
|
|
72
|
-
* ```
|
|
28
|
+
* Maps HTTP methods to policy abilities. A method outside the built-in mapping
|
|
29
|
+
* (a custom verb via `router.on()`) is denied with a 403 rather than downgraded
|
|
30
|
+
* to `view`: guessing would let a view-only user reach a mutating handler. Map
|
|
31
|
+
* custom verbs explicitly with `options.abilityFor`.
|
|
73
32
|
*/
|
|
74
33
|
export declare function authorizeResourceMiddleware(modelResolver: (ctx: Context) => unknown | Promise<unknown>, options?: AuthorizeResourceOptions): Middleware;
|
|
75
|
-
/**
|
|
76
|
-
* Create a gate-aware context with authorization helpers.
|
|
77
|
-
*/
|
|
34
|
+
/** Create a gate-aware context with authorization helpers. */
|
|
78
35
|
export declare function withAuthorization(gate: Gate): Middleware;
|
|
79
|
-
/**
|
|
80
|
-
* Helper type for context with authorization.
|
|
81
|
-
*/
|
|
82
36
|
export interface AuthorizedContext extends Context {
|
|
83
37
|
get(key: 'gate'): Gate;
|
|
84
38
|
get(key: 'can'): (ability: string, ...args: unknown[]) => Promise<boolean>;
|
|
@@ -1,113 +1,57 @@
|
|
|
1
1
|
import type { Context } from '../http/Application.js';
|
|
2
|
-
/**
|
|
3
|
-
* User type for authorization.
|
|
4
|
-
*/
|
|
5
2
|
export interface AuthUser {
|
|
6
3
|
id: string | number;
|
|
7
4
|
}
|
|
8
|
-
/**
|
|
9
|
-
* Gate callback function.
|
|
10
|
-
*/
|
|
11
5
|
export type GateCallback<Args extends unknown[] = unknown[]> = {
|
|
12
6
|
bivarianceHack(user: AuthUser | null, ...args: Args): PolicyResult | Promise<PolicyResult>;
|
|
13
7
|
}['bivarianceHack'];
|
|
14
|
-
/**
|
|
15
|
-
* Gate before callbacks can short-circuit authorization.
|
|
16
|
-
* Return true to allow, false to deny, or undefined to continue.
|
|
17
|
-
*/
|
|
8
|
+
/** Return true to allow, false to deny, or undefined to continue. */
|
|
18
9
|
export type GateBeforeCallback<Args extends unknown[] = unknown[]> = {
|
|
19
10
|
bivarianceHack(user: AuthUser | null, ability: string, ...args: Args): PolicyResult | undefined | Promise<PolicyResult | undefined>;
|
|
20
11
|
}['bivarianceHack'];
|
|
21
|
-
/**
|
|
22
|
-
* Gate definition with optional callback.
|
|
23
|
-
*/
|
|
24
12
|
export interface GateDefinition {
|
|
25
13
|
callback: GateCallback;
|
|
26
14
|
}
|
|
27
15
|
/**
|
|
28
|
-
* What a policy ability or gate callback may answer.
|
|
29
|
-
*
|
|
30
16
|
* `Response.deny()` and friends return an object, so it must be part of the
|
|
31
|
-
* type — a
|
|
32
|
-
* as an approval.
|
|
17
|
+
* type — a `boolean`-only signature let a denial be read as an approval.
|
|
33
18
|
*/
|
|
34
19
|
export type PolicyResult = boolean | AuthorizationResponse;
|
|
35
|
-
/**
|
|
36
|
-
* Policy method type.
|
|
37
|
-
*/
|
|
38
20
|
export type PolicyMethod<T = unknown> = (user: AuthUser | null, model?: T, ...args: unknown[]) => PolicyResult | Promise<PolicyResult>;
|
|
39
|
-
/**
|
|
40
|
-
* Policy class interface.
|
|
41
|
-
*/
|
|
42
21
|
export interface Policy {
|
|
43
|
-
/**
|
|
44
|
-
* Run before all other authorization checks.
|
|
45
|
-
* Return true to allow, false to deny, undefined to continue to specific check.
|
|
46
|
-
*/
|
|
22
|
+
/** Return true to allow, false to deny, undefined to continue to the ability method. */
|
|
47
23
|
before?(user: AuthUser | null, ability: string): PolicyResult | undefined | Promise<PolicyResult | undefined>;
|
|
48
24
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Policy class constructor.
|
|
51
|
-
*/
|
|
52
25
|
export interface PolicyClass {
|
|
53
26
|
new (): Policy;
|
|
54
27
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Authorization response.
|
|
57
|
-
*/
|
|
58
28
|
export interface AuthorizationResponse {
|
|
59
29
|
allowed: boolean;
|
|
60
30
|
message?: string;
|
|
61
31
|
code?: string;
|
|
62
32
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Gate options.
|
|
65
|
-
*/
|
|
66
33
|
export interface GateOptions {
|
|
67
|
-
/**
|
|
68
|
-
* Default user resolver from context.
|
|
69
|
-
*/
|
|
70
34
|
userResolver?: (ctx: Context) => AuthUser | null | Promise<AuthUser | null>;
|
|
71
35
|
}
|
|
72
|
-
/**
|
|
73
|
-
* Authorization check options.
|
|
74
|
-
*/
|
|
75
36
|
export interface AuthorizeOptions {
|
|
76
|
-
/**
|
|
77
|
-
* Custom message for denial.
|
|
78
|
-
*/
|
|
37
|
+
/** Custom message for denial. */
|
|
79
38
|
message?: string;
|
|
80
|
-
/**
|
|
81
|
-
* HTTP status code for denial.
|
|
82
|
-
*/
|
|
39
|
+
/** HTTP status code for denial. */
|
|
83
40
|
status?: number;
|
|
84
41
|
}
|
|
85
|
-
/**
|
|
86
|
-
* Options for `authorizeResourceMiddleware`.
|
|
87
|
-
*/
|
|
88
42
|
export interface AuthorizeResourceOptions extends AuthorizeOptions {
|
|
89
43
|
/**
|
|
90
|
-
* Map an HTTP method (always uppercased) to a policy ability
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* denied with a 403.
|
|
44
|
+
* Map an HTTP method (always uppercased) to a policy ability. Return
|
|
45
|
+
* `undefined` to fall back to the built-in mapping; a method with no ability
|
|
46
|
+
* from either source is denied with a 403.
|
|
94
47
|
*/
|
|
95
48
|
abilityFor?: (method: string) => string | undefined;
|
|
96
49
|
}
|
|
97
|
-
/**
|
|
98
|
-
* Policy registration.
|
|
99
|
-
*/
|
|
100
50
|
export interface PolicyRegistration {
|
|
101
51
|
modelClass: unknown;
|
|
102
52
|
policyClass: PolicyClass;
|
|
103
53
|
}
|
|
104
|
-
/**
|
|
105
|
-
* Resource actions for policies.
|
|
106
|
-
*/
|
|
107
54
|
export type ResourceAction = 'viewAny' | 'view' | 'create' | 'update' | 'delete' | 'restore' | 'forceDelete';
|
|
108
|
-
/**
|
|
109
|
-
* Response builder for authorization.
|
|
110
|
-
*/
|
|
111
55
|
export interface ResponseBuilder {
|
|
112
56
|
allow(message?: string): AuthorizationResponse;
|
|
113
57
|
deny(message?: string, code?: string): AuthorizationResponse;
|