@guren/server 2.14.0 → 2.16.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-CzrwKeDp.js → Hash-D2DFd8xX.js} +12 -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-nNcbCIQX.js} +11 -20
- package/dist/{Random-DbIJ22KQ.js → Random-S0OvCuR8.js} +9 -106
- package/dist/agent/AgentApprovalRequested.d.ts +31 -0
- package/dist/agent/approval.d.ts +184 -0
- package/dist/agent/audit-emitter.d.ts +36 -0
- package/dist/agent/audit.d.ts +67 -0
- package/dist/agent/derive.d.ts +32 -66
- package/dist/agent/dispatch.d.ts +53 -63
- package/dist/agent/events.d.ts +11 -19
- package/dist/agent/meta-tools.d.ts +34 -0
- package/dist/agent/public.d.ts +14 -0
- package/dist/agent/public.js +2 -0
- package/dist/agent/redact.d.ts +16 -38
- package/dist/agent/scopes.d.ts +23 -69
- package/dist/auth/AuthManager.d.ts +19 -40
- 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 +9 -5
- package/dist/auth/password/PasswordHasher.d.ts +7 -0
- package/dist/auth/password/hash-format.d.ts +11 -0
- 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-BSUc14CD.js → auth-CbdPH4Cd.js} +252 -496
- 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-BxU-LIfF.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 +10 -12
- 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-BAwzftws.js +238 -0
- 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-DJtkkhiw.js → encryption-uwP3Di4D.js} +13 -79
- 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 +62 -208
- package/dist/http/FormRequest.d.ts +4 -55
- package/dist/http/dev-assets.d.ts +16 -18
- 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 +20 -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/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 +14 -0
- package/dist/http/request.d.ts +49 -48
- 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 +21 -0
- 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 +13 -4
- package/dist/index.js +1036 -3080
- package/dist/internal/agent-preflight.d.ts +9 -21
- package/dist/internal/request.d.ts +10 -17
- package/dist/internal/request.js +2 -2
- 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 -5
- package/dist/logging/channels/FileChannel.d.ts +1 -3
- package/dist/logging/daily-file-path.d.ts +15 -0
- package/dist/logging/index.d.ts +1 -0
- package/dist/logging/index.js +2 -2
- package/dist/logging/types.d.ts +13 -45
- package/dist/{logging-CPaRMuPP.js → logging-zOY1XCtq.js} +83 -129
- 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 +25 -57
- package/dist/mcp/endpoint.d.ts +12 -36
- package/dist/mcp/index.js +1 -1
- package/dist/mvc/Controller.d.ts +46 -253
- 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 +108 -74
- 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-BGfWbPYp.js → vite-manifest-CTQp-SOo.js} +34 -58
- package/package.json +6 -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-CRVuIiQr.js +0 -78
|
@@ -1,35 +1,19 @@
|
|
|
1
|
-
import { t as HttpException } from "./HttpException-
|
|
2
|
-
import { n as getAuthContext } from "./context-
|
|
1
|
+
import { t as HttpException } from "./HttpException-BlQ2yEmT.js";
|
|
2
|
+
import { n as getAuthContext } from "./context-CXk_umpT.js";
|
|
3
3
|
//#region src/http/middleware/capabilities.ts
|
|
4
4
|
/**
|
|
5
|
-
* Internal security-capability marker (RFC 0007)
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* heuristics. `Symbol.for()` keeps the key identical across duplicated
|
|
11
|
-
* `@guren/server` copies in one process.
|
|
12
|
-
*
|
|
13
|
-
* Deliberately not part of the public API: nothing here is exported from
|
|
14
|
-
* the package root, and the shape may change in any release. A public
|
|
15
|
-
* `defineMiddleware` integration is future work in RFC 0007.
|
|
5
|
+
* Internal security-capability marker (RFC 0007): built-in middleware
|
|
6
|
+
* factories stamp their handlers so tooling can read what a chain enforces
|
|
7
|
+
* without name heuristics. `Symbol.for()` keeps the key identical across
|
|
8
|
+
* duplicated `@guren/server` copies in one process. Not public API — the
|
|
9
|
+
* shape may change in any release.
|
|
16
10
|
*/
|
|
17
11
|
const CAPABILITIES = Symbol.for("guren.capabilities");
|
|
18
12
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* non-authoritative check makes the verb map unusable for the whole chain.
|
|
24
|
-
*
|
|
25
|
-
* Mutates `into` and never `stamp` — nested objects and arrays are copied
|
|
26
|
-
* the first time they are taken, so a later merge cannot write back through
|
|
27
|
-
* the aggregate into a handler's stamp.
|
|
28
|
-
*
|
|
29
|
-
* Every call counts as an independent check. Folding the *same* stamp twice
|
|
30
|
-
* would read as two of them and degrade an `'any'` to `'mixed'`, so
|
|
31
|
-
* de-duplicating handlers that appear more than once in a chain is the
|
|
32
|
-
* caller's job.
|
|
13
|
+
* Folds one middleware's stamp into an accumulating aggregate. Mutates `into`
|
|
14
|
+
* and never `stamp`. Every call counts as an independent check, so folding the
|
|
15
|
+
* *same* stamp twice degrades an `'any'` to `'mixed'` — de-duplicating handlers
|
|
16
|
+
* that appear more than once in a chain is the caller's job.
|
|
33
17
|
*/
|
|
34
18
|
function mergeCapabilities(into, stamp) {
|
|
35
19
|
const auth = stamp.authentication;
|
|
@@ -62,26 +46,9 @@ function capabilitiesOf(handler) {
|
|
|
62
46
|
}
|
|
63
47
|
//#endregion
|
|
64
48
|
//#region src/errors/exceptions/AuthorizationException.ts
|
|
65
|
-
/**
|
|
66
|
-
* Authorization exception.
|
|
67
|
-
*
|
|
68
|
-
* Thrown when a user is authenticated but not authorized to perform an action.
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* throw new AuthorizationException()
|
|
73
|
-
* throw new AuthorizationException('You cannot edit this post')
|
|
74
|
-
* throw new AuthorizationException('Access denied', 'edit', 'Post')
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
49
|
+
/** 403: the user is authenticated but not allowed to perform the action. */
|
|
77
50
|
var AuthorizationException = class AuthorizationException extends HttpException {
|
|
78
|
-
/**
|
|
79
|
-
* The action that was attempted.
|
|
80
|
-
*/
|
|
81
51
|
action;
|
|
82
|
-
/**
|
|
83
|
-
* The resource that was being accessed.
|
|
84
|
-
*/
|
|
85
52
|
resource;
|
|
86
53
|
constructor(message = "This action is unauthorized.", action, resource) {
|
|
87
54
|
super(403, message);
|
|
@@ -89,16 +56,10 @@ var AuthorizationException = class AuthorizationException extends HttpException
|
|
|
89
56
|
this.action = action;
|
|
90
57
|
this.resource = resource;
|
|
91
58
|
}
|
|
92
|
-
/**
|
|
93
|
-
* Create exception for a specific action and resource.
|
|
94
|
-
*/
|
|
95
59
|
static forAction(action, resource) {
|
|
96
60
|
const message = resource ? `You are not authorized to ${action} this ${resource}.` : `You are not authorized to ${action}.`;
|
|
97
61
|
return new AuthorizationException(message, action, resource);
|
|
98
62
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Deny access to a resource.
|
|
101
|
-
*/
|
|
102
63
|
static deny(resource) {
|
|
103
64
|
const message = resource ? `Access to ${resource} denied.` : "Access denied.";
|
|
104
65
|
return new AuthorizationException(message, "access", resource);
|
|
@@ -106,9 +67,7 @@ var AuthorizationException = class AuthorizationException extends HttpException
|
|
|
106
67
|
};
|
|
107
68
|
//#endregion
|
|
108
69
|
//#region src/authorization/Gate.ts
|
|
109
|
-
/**
|
|
110
|
-
* Response builder for authorization checks.
|
|
111
|
-
*/
|
|
70
|
+
/** Response builder for authorization checks. */
|
|
112
71
|
const Response = {
|
|
113
72
|
allow(message) {
|
|
114
73
|
return {
|
|
@@ -138,128 +97,59 @@ const Response = {
|
|
|
138
97
|
};
|
|
139
98
|
}
|
|
140
99
|
};
|
|
141
|
-
/**
|
|
142
|
-
* Narrow a policy/gate return value to an `AuthorizationResponse`.
|
|
143
|
-
*
|
|
144
|
-
* Policies may return either a boolean or one of the `Response` objects
|
|
145
|
-
* produced by `allow()`/`deny()`/`denyWithStatus()`/`denyAsNotFound()`.
|
|
146
|
-
*/
|
|
100
|
+
/** Narrow a policy/gate return value to an `AuthorizationResponse`. */
|
|
147
101
|
function isAuthorizationResponse(value) {
|
|
148
102
|
return typeof value === "object" && value !== null && typeof value.allowed === "boolean";
|
|
149
103
|
}
|
|
150
104
|
/**
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* A `{ allowed: false }` object is truthy, so anything that decides access
|
|
154
|
-
* from the raw return value fails open. Every path in this class routes
|
|
155
|
-
* through here, and unknown shapes deny.
|
|
105
|
+
* A `{ allowed: false }` object is truthy, so deciding access from a raw return
|
|
106
|
+
* value fails open. Every path routes through here, and unknown shapes deny.
|
|
156
107
|
*/
|
|
157
108
|
function toAuthorizationResponse(value) {
|
|
158
109
|
if (isAuthorizationResponse(value)) return value;
|
|
159
110
|
return value === true ? Response.allow() : Response.deny();
|
|
160
111
|
}
|
|
161
|
-
/**
|
|
162
|
-
* Build the exception for a denial, honouring `denyWithStatus()` /
|
|
163
|
-
* `denyAsNotFound()` so a policy can hide a record as a 404.
|
|
164
|
-
*/
|
|
112
|
+
/** Honours `denyWithStatus()` / `denyAsNotFound()` so a policy can hide a record as a 404. */
|
|
165
113
|
function denialToException(response) {
|
|
166
114
|
const message = response.message ?? "This action is unauthorized.";
|
|
167
115
|
const status = response.status;
|
|
168
116
|
if (typeof status === "number" && status !== 403) return new HttpException(status, message);
|
|
169
117
|
return new AuthorizationException(message);
|
|
170
118
|
}
|
|
171
|
-
/**
|
|
172
|
-
* Authorization gate for defining and checking abilities.
|
|
173
|
-
*
|
|
174
|
-
* @example
|
|
175
|
-
* ```typescript
|
|
176
|
-
* const gate = new Gate()
|
|
177
|
-
*
|
|
178
|
-
* // Define abilities
|
|
179
|
-
* gate.define('edit-post', (user, post) => user.id === post.authorId)
|
|
180
|
-
* gate.define('admin', (user) => user.role === 'admin')
|
|
181
|
-
*
|
|
182
|
-
* // Check abilities
|
|
183
|
-
* if (await gate.allows('edit-post', post)) {
|
|
184
|
-
* // User can edit
|
|
185
|
-
* }
|
|
186
|
-
*
|
|
187
|
-
* // Or throw on denial
|
|
188
|
-
* await gate.authorize('edit-post', post) // throws if not allowed
|
|
189
|
-
* ```
|
|
190
|
-
*/
|
|
119
|
+
/** Authorization gate for defining and checking abilities. */
|
|
191
120
|
var Gate = class {
|
|
192
|
-
/**
|
|
193
|
-
* Defined gates.
|
|
194
|
-
*/
|
|
195
121
|
gates = /* @__PURE__ */ new Map();
|
|
196
|
-
/**
|
|
197
|
-
* Registered policies.
|
|
198
|
-
*/
|
|
199
122
|
policies = /* @__PURE__ */ new Map();
|
|
200
|
-
/**
|
|
201
|
-
* Policy instances cache.
|
|
202
|
-
*/
|
|
203
123
|
policyInstances = /* @__PURE__ */ new Map();
|
|
204
|
-
/**
|
|
205
|
-
* Before callbacks.
|
|
206
|
-
*/
|
|
207
124
|
beforeCallbacks = [];
|
|
208
|
-
/**
|
|
209
|
-
* After callbacks.
|
|
210
|
-
*/
|
|
211
125
|
afterCallbacks = [];
|
|
212
|
-
/**
|
|
213
|
-
* User resolver function.
|
|
214
|
-
*/
|
|
215
126
|
userResolver;
|
|
216
|
-
/**
|
|
217
|
-
* Current user for checks.
|
|
218
|
-
*/
|
|
219
127
|
currentUser = null;
|
|
220
128
|
constructor(options = {}) {
|
|
221
129
|
this.userResolver = options.userResolver;
|
|
222
130
|
}
|
|
223
|
-
/**
|
|
224
|
-
* Define a new gate.
|
|
225
|
-
*/
|
|
226
131
|
define(ability, callback) {
|
|
227
132
|
this.gates.set(ability, { callback });
|
|
228
133
|
return this;
|
|
229
134
|
}
|
|
230
|
-
/**
|
|
231
|
-
* Register a policy for a model class.
|
|
232
|
-
*/
|
|
233
135
|
policy(modelClass, policyClass) {
|
|
234
136
|
this.policies.set(modelClass, policyClass);
|
|
235
137
|
return this;
|
|
236
138
|
}
|
|
237
|
-
/**
|
|
238
|
-
* Register a before callback.
|
|
239
|
-
* Return true to allow, false to deny, undefined to continue.
|
|
240
|
-
*/
|
|
139
|
+
/** Return true to allow, false to deny, undefined to continue. */
|
|
241
140
|
before(callback) {
|
|
242
141
|
this.beforeCallbacks.push(callback);
|
|
243
142
|
return this;
|
|
244
143
|
}
|
|
245
|
-
/**
|
|
246
|
-
* Register an after callback.
|
|
247
|
-
*/
|
|
248
144
|
after(callback) {
|
|
249
145
|
this.afterCallbacks.push(callback);
|
|
250
146
|
return this;
|
|
251
147
|
}
|
|
252
|
-
/**
|
|
253
|
-
* Set the current user for authorization checks.
|
|
254
|
-
*/
|
|
255
148
|
forUser(user) {
|
|
256
149
|
const clone = Object.assign(Object.create(Object.getPrototypeOf(this)), this);
|
|
257
150
|
clone.currentUser = user;
|
|
258
151
|
return clone;
|
|
259
152
|
}
|
|
260
|
-
/**
|
|
261
|
-
* Resolve the user from context.
|
|
262
|
-
*/
|
|
263
153
|
async resolveUser(ctx) {
|
|
264
154
|
if (this.currentUser !== null) return this.currentUser;
|
|
265
155
|
if (this.userResolver) return this.userResolver(ctx);
|
|
@@ -267,64 +157,34 @@ var Gate = class {
|
|
|
267
157
|
if (auth && typeof auth.user === "function") return await auth.user() ?? null;
|
|
268
158
|
return ctx.get("user") ?? null;
|
|
269
159
|
}
|
|
270
|
-
/**
|
|
271
|
-
* Check if the user has the given ability.
|
|
272
|
-
*/
|
|
273
160
|
async allows(ability, ...args) {
|
|
274
161
|
return this.check(ability, this.currentUser, ...args);
|
|
275
162
|
}
|
|
276
|
-
/**
|
|
277
|
-
* Check if the user doesn't have the given ability.
|
|
278
|
-
*/
|
|
279
163
|
async denies(ability, ...args) {
|
|
280
164
|
return !await this.allows(ability, ...args);
|
|
281
165
|
}
|
|
282
|
-
/**
|
|
283
|
-
* Check if the user has any of the given abilities.
|
|
284
|
-
*/
|
|
285
166
|
async any(abilities, ...args) {
|
|
286
167
|
for (const ability of abilities) if (await this.allows(ability, ...args)) return true;
|
|
287
168
|
return false;
|
|
288
169
|
}
|
|
289
|
-
/**
|
|
290
|
-
* Check if the user has all of the given abilities.
|
|
291
|
-
*/
|
|
292
170
|
async all(abilities, ...args) {
|
|
293
171
|
for (const ability of abilities) if (!await this.allows(ability, ...args)) return false;
|
|
294
172
|
return true;
|
|
295
173
|
}
|
|
296
|
-
/**
|
|
297
|
-
* Check if the user has none of the given abilities.
|
|
298
|
-
*/
|
|
299
174
|
async none(abilities, ...args) {
|
|
300
175
|
return !await this.any(abilities, ...args);
|
|
301
176
|
}
|
|
302
|
-
/**
|
|
303
|
-
* Authorize the ability or throw an exception.
|
|
304
|
-
*/
|
|
305
177
|
async authorize(ability, ...args) {
|
|
306
178
|
const response = await this.checkResponse(ability, this.currentUser, ...args);
|
|
307
179
|
if (!response.allowed) throw denialToException(response);
|
|
308
180
|
}
|
|
309
|
-
/**
|
|
310
|
-
* Get the authorization response.
|
|
311
|
-
*/
|
|
312
181
|
async inspect(ability, ...args) {
|
|
313
182
|
return this.checkResponse(ability, this.currentUser, ...args);
|
|
314
183
|
}
|
|
315
|
-
/**
|
|
316
|
-
* Check the ability with a specific user.
|
|
317
|
-
*/
|
|
318
184
|
async check(ability, user, ...args) {
|
|
319
185
|
return (await this.checkResponse(ability, user, ...args)).allowed;
|
|
320
186
|
}
|
|
321
|
-
/**
|
|
322
|
-
* Check the ability with a specific user and keep the full response.
|
|
323
|
-
*
|
|
324
|
-
* Policies may answer with a boolean or with a `Response` object. Both
|
|
325
|
-
* shapes are normalized here so no caller has to truthy-test a
|
|
326
|
-
* `{ allowed: false }` object.
|
|
327
|
-
*/
|
|
187
|
+
/** Like check(), but keeps the full response instead of just `allowed`. */
|
|
328
188
|
async checkResponse(ability, user, ...args) {
|
|
329
189
|
for (const beforeCallback of this.beforeCallbacks) {
|
|
330
190
|
const result = await beforeCallback(user, ability, ...args);
|
|
@@ -347,12 +207,9 @@ var Gate = class {
|
|
|
347
207
|
return response;
|
|
348
208
|
}
|
|
349
209
|
/**
|
|
350
|
-
* Check a policy for the given ability.
|
|
351
|
-
*
|
|
352
210
|
* The subject may be a class instance (policy resolved via its constructor)
|
|
353
|
-
* or a `[ModelClass, record]` / `['key', record]` tuple
|
|
354
|
-
* required for plain records
|
|
355
|
-
* information.
|
|
211
|
+
* or a `[ModelClass, record]` / `['key', record]` tuple — the tuple form is
|
|
212
|
+
* required for plain ORM records, which carry no constructor information.
|
|
356
213
|
*/
|
|
357
214
|
async checkPolicy(ability, user, model, additionalArgs) {
|
|
358
215
|
let policyKey;
|
|
@@ -376,9 +233,6 @@ var Gate = class {
|
|
|
376
233
|
const method = policy[ability];
|
|
377
234
|
if (typeof method === "function") return hasSubject ? method.call(policy, user, subject, ...additionalArgs) : method.call(policy, user, ...additionalArgs);
|
|
378
235
|
}
|
|
379
|
-
/**
|
|
380
|
-
* Get or create a policy instance.
|
|
381
|
-
*/
|
|
382
236
|
getPolicyInstance(policyClass) {
|
|
383
237
|
let instance = this.policyInstances.get(policyClass);
|
|
384
238
|
if (!instance) {
|
|
@@ -387,27 +241,15 @@ var Gate = class {
|
|
|
387
241
|
}
|
|
388
242
|
return instance;
|
|
389
243
|
}
|
|
390
|
-
/**
|
|
391
|
-
* Run after callbacks.
|
|
392
|
-
*/
|
|
393
244
|
async runAfterCallbacks(user, ability, result, args) {
|
|
394
245
|
for (const afterCallback of this.afterCallbacks) await afterCallback(user, ability, result, args);
|
|
395
246
|
}
|
|
396
|
-
/**
|
|
397
|
-
* Get all defined abilities.
|
|
398
|
-
*/
|
|
399
247
|
abilities() {
|
|
400
248
|
return Array.from(this.gates.keys());
|
|
401
249
|
}
|
|
402
|
-
/**
|
|
403
|
-
* Check if an ability is defined.
|
|
404
|
-
*/
|
|
405
250
|
has(ability) {
|
|
406
251
|
return this.gates.has(ability);
|
|
407
252
|
}
|
|
408
|
-
/**
|
|
409
|
-
* Get the policy for a model.
|
|
410
|
-
*/
|
|
411
253
|
getPolicyFor(model) {
|
|
412
254
|
const modelConstructor = model?.constructor;
|
|
413
255
|
if (!modelConstructor) return;
|
|
@@ -417,116 +259,52 @@ var Gate = class {
|
|
|
417
259
|
}
|
|
418
260
|
};
|
|
419
261
|
let globalGate = null;
|
|
420
|
-
/**
|
|
421
|
-
* Create a new gate instance.
|
|
422
|
-
*/
|
|
423
262
|
function createGate(options) {
|
|
424
263
|
return new Gate(options);
|
|
425
264
|
}
|
|
426
|
-
/**
|
|
427
|
-
* Set the global gate instance.
|
|
428
|
-
*/
|
|
429
265
|
function setGate(gate) {
|
|
430
266
|
globalGate = gate;
|
|
431
267
|
}
|
|
432
|
-
/**
|
|
433
|
-
* Get the global gate instance.
|
|
434
|
-
*/
|
|
435
268
|
function getGate() {
|
|
436
269
|
if (!globalGate) throw new Error("Gate not initialized. Call setGate() first.");
|
|
437
270
|
return globalGate;
|
|
438
271
|
}
|
|
439
|
-
/**
|
|
440
|
-
* Define a gate on the global instance.
|
|
441
|
-
*/
|
|
272
|
+
/** Define a gate on the global instance. */
|
|
442
273
|
function defineGate(ability, callback) {
|
|
443
274
|
getGate().define(ability, callback);
|
|
444
275
|
}
|
|
445
|
-
/**
|
|
446
|
-
* Check if the current user can perform an ability.
|
|
447
|
-
*/
|
|
448
276
|
async function can(ability, ...args) {
|
|
449
277
|
return getGate().allows(ability, ...args);
|
|
450
278
|
}
|
|
451
|
-
/**
|
|
452
|
-
* Check if the current user cannot perform an ability.
|
|
453
|
-
*/
|
|
454
279
|
async function cannot(ability, ...args) {
|
|
455
280
|
return getGate().denies(ability, ...args);
|
|
456
281
|
}
|
|
457
|
-
/**
|
|
458
|
-
* Authorize or throw.
|
|
459
|
-
*/
|
|
460
282
|
async function authorize(ability, ...args) {
|
|
461
283
|
return getGate().authorize(ability, ...args);
|
|
462
284
|
}
|
|
463
285
|
//#endregion
|
|
464
286
|
//#region src/authorization/Policy.ts
|
|
465
287
|
/**
|
|
466
|
-
* Base policy class for model authorization.
|
|
467
|
-
*
|
|
468
|
-
*
|
|
469
|
-
*
|
|
470
|
-
* class PostPolicy extends Policy {
|
|
471
|
-
* // Runs before all checks - return true/false to short-circuit
|
|
472
|
-
* before(user: AuthUser | null, ability: string) {
|
|
473
|
-
* if (user?.role === 'admin') {
|
|
474
|
-
* return true // Admins can do anything
|
|
475
|
-
* }
|
|
476
|
-
* return undefined // Continue to specific check
|
|
477
|
-
* }
|
|
478
|
-
*
|
|
479
|
-
* viewAny(user: AuthUser | null) {
|
|
480
|
-
* return true // Anyone can view posts list
|
|
481
|
-
* }
|
|
482
|
-
*
|
|
483
|
-
* view(user: AuthUser | null, post: Post) {
|
|
484
|
-
* return post.published || user?.id === post.authorId
|
|
485
|
-
* }
|
|
486
|
-
*
|
|
487
|
-
* create(user: AuthUser | null) {
|
|
488
|
-
* return user !== null
|
|
489
|
-
* }
|
|
490
|
-
*
|
|
491
|
-
* update(user: AuthUser | null, post: Post) {
|
|
492
|
-
* return user?.id === post.authorId
|
|
493
|
-
* }
|
|
494
|
-
*
|
|
495
|
-
* delete(user: AuthUser | null, post: Post) {
|
|
496
|
-
* return user?.id === post.authorId
|
|
497
|
-
* }
|
|
498
|
-
* }
|
|
499
|
-
* ```
|
|
288
|
+
* Base policy class for model authorization. Ability methods are looked up on
|
|
289
|
+
* the subclass by name (`viewAny`, `view`, `create`, `update`, `delete`,
|
|
290
|
+
* `restore`, `forceDelete`, or any custom ability), each taking
|
|
291
|
+
* `(user, model?, ...args)`.
|
|
500
292
|
*/
|
|
501
293
|
var Policy = class {
|
|
502
|
-
/**
|
|
503
|
-
* Allow the action.
|
|
504
|
-
*/
|
|
505
294
|
allow(message) {
|
|
506
295
|
return Response.allow(message);
|
|
507
296
|
}
|
|
508
|
-
/**
|
|
509
|
-
* Deny the action.
|
|
510
|
-
*/
|
|
511
297
|
deny(message, code) {
|
|
512
298
|
return Response.deny(message, code);
|
|
513
299
|
}
|
|
514
|
-
/**
|
|
515
|
-
* Deny with a specific HTTP status.
|
|
516
|
-
*/
|
|
517
300
|
denyWithStatus(status, message) {
|
|
518
301
|
return Response.denyWithStatus(status, message);
|
|
519
302
|
}
|
|
520
|
-
/**
|
|
521
|
-
* Deny as not found (404).
|
|
522
|
-
*/
|
|
523
303
|
denyAsNotFound(message) {
|
|
524
304
|
return Response.denyAsNotFound(message);
|
|
525
305
|
}
|
|
526
306
|
};
|
|
527
|
-
/**
|
|
528
|
-
* Create a simple policy from an object.
|
|
529
|
-
*/
|
|
307
|
+
/** Create a policy class from an object of ability functions. */
|
|
530
308
|
function definePolicy(definition) {
|
|
531
309
|
return class extends Policy {
|
|
532
310
|
before = definition.before;
|
|
@@ -556,26 +334,10 @@ function definePolicy(definition) {
|
|
|
556
334
|
//#endregion
|
|
557
335
|
//#region src/authorization/middleware.ts
|
|
558
336
|
/**
|
|
559
|
-
* Middleware to authorize an ability.
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
* // Authorize a simple ability
|
|
564
|
-
* app.get('/admin', authorizeMiddleware('admin'), adminHandler)
|
|
565
|
-
*
|
|
566
|
-
* // Authorize with model (from route param)
|
|
567
|
-
* app.put('/posts/:id', authorizeMiddleware('update', getPost), updateHandler)
|
|
568
|
-
*
|
|
569
|
-
* // Multiple abilities (any)
|
|
570
|
-
* app.get('/dashboard', authorizeMiddleware(['admin', 'moderator']), dashboardHandler)
|
|
571
|
-
* ```
|
|
572
|
-
*
|
|
573
|
-
* An array argument is snapshotted at creation: mutating it afterwards
|
|
574
|
-
* changes neither what the middleware checks nor what it reports. A
|
|
575
|
-
* one-element array is treated exactly like the bare ability, denial message
|
|
576
|
-
* and status included. An empty array denies every request (`Gate.any([])` is
|
|
577
|
-
* false) and names no ability — fail-closed, so it is left to run rather than
|
|
578
|
-
* rejected.
|
|
337
|
+
* Middleware to authorize an ability. An array argument is snapshotted at
|
|
338
|
+
* creation, and a one-element array behaves exactly like the bare ability.
|
|
339
|
+
* An empty array denies every request (`Gate.any([])` is false) — fail-closed,
|
|
340
|
+
* so it is left to run rather than rejected.
|
|
579
341
|
*/
|
|
580
342
|
function authorizeMiddleware(ability, modelResolver, options = {}) {
|
|
581
343
|
const abilities = Array.isArray(ability) ? [...ability] : [ability];
|
|
@@ -601,15 +363,10 @@ function authorizeMiddleware(ability, modelResolver, options = {}) {
|
|
|
601
363
|
} });
|
|
602
364
|
}
|
|
603
365
|
/**
|
|
604
|
-
* Middleware to authorize all given abilities.
|
|
366
|
+
* Middleware to authorize all given abilities. The array is snapshotted at creation.
|
|
605
367
|
*
|
|
606
|
-
*
|
|
607
|
-
*
|
|
608
|
-
*
|
|
609
|
-
* @throws if no ability is given. `Gate.all([])` is vacuously true, so an
|
|
610
|
-
* empty list would mount a route that advertises authorization and enforces
|
|
611
|
-
* none — the fail-open shape RFC 0016's "authn is not authz" rule exists to
|
|
612
|
-
* catch. Refusing at creation surfaces it at boot rather than per request.
|
|
368
|
+
* @throws if no ability is given: `Gate.all([])` is vacuously true, so an empty
|
|
369
|
+
* list would advertise authorization and enforce none (RFC 0016).
|
|
613
370
|
*/
|
|
614
371
|
function authorizeAllMiddleware(input, modelResolver, options = {}) {
|
|
615
372
|
const abilities = [...input];
|
|
@@ -636,40 +393,20 @@ const RESOURCE_ABILITY_BY_METHOD = {
|
|
|
636
393
|
DELETE: "delete"
|
|
637
394
|
};
|
|
638
395
|
/**
|
|
639
|
-
* The ability `
|
|
640
|
-
*
|
|
641
|
-
* denies). This is the single source of the verb → ability mapping: a
|
|
642
|
-
* consumer resolving a route's ability from its stamped
|
|
396
|
+
* The single source of the verb → ability mapping; `undefined` for a method it
|
|
397
|
+
* refuses to guess at. A consumer resolving a route's ability from its stamped
|
|
643
398
|
* `authorization.resource` capability calls this rather than restating the
|
|
644
|
-
* table, and may only do so when `resource.fromMethodMap` is true.
|
|
645
|
-
*
|
|
646
|
-
* Not re-exported from the package root — like the capability stamp itself
|
|
647
|
-
* (RFC 0007), this is an internal contract until a public consumer needs it.
|
|
399
|
+
* table, and may only do so when `resource.fromMethodMap` is true. Internal
|
|
400
|
+
* contract (RFC 0007): not re-exported from the package root.
|
|
648
401
|
*/
|
|
649
402
|
function resourceAbilityForMethod(method) {
|
|
650
403
|
return RESOURCE_ABILITY_BY_METHOD[method.toUpperCase()];
|
|
651
404
|
}
|
|
652
405
|
/**
|
|
653
|
-
*
|
|
654
|
-
*
|
|
655
|
-
*
|
|
656
|
-
*
|
|
657
|
-
* `router.on()`) are denied with a 403 rather than downgraded to a `view`
|
|
658
|
-
* check — the middleware cannot know whether an unknown verb mutates, so
|
|
659
|
-
* guessing would let a view-only user reach a mutating handler. Map custom
|
|
660
|
-
* verbs explicitly with `options.abilityFor`.
|
|
661
|
-
*
|
|
662
|
-
* @example
|
|
663
|
-
* ```typescript
|
|
664
|
-
* // Authorize resource actions based on HTTP method
|
|
665
|
-
* app.use('/posts/:id', authorizeResourceMiddleware(getPost))
|
|
666
|
-
* // GET/HEAD/QUERY -> view, POST -> create, PUT/PATCH -> update, DELETE -> delete
|
|
667
|
-
*
|
|
668
|
-
* // Custom verbs must be mapped explicitly, or they are denied
|
|
669
|
-
* authorizeResourceMiddleware(getPost, {
|
|
670
|
-
* abilityFor: (method) => (method === 'PURGE' ? 'delete' : undefined),
|
|
671
|
-
* })
|
|
672
|
-
* ```
|
|
406
|
+
* Maps HTTP methods to policy abilities. A method outside the built-in mapping
|
|
407
|
+
* (a custom verb via `router.on()`) is denied with a 403 rather than downgraded
|
|
408
|
+
* to `view`: guessing would let a view-only user reach a mutating handler. Map
|
|
409
|
+
* custom verbs explicitly with `options.abilityFor`.
|
|
673
410
|
*/
|
|
674
411
|
function authorizeResourceMiddleware(modelResolver, options = {}) {
|
|
675
412
|
const abilityFor = options.abilityFor;
|
|
@@ -693,9 +430,7 @@ function authorizeResourceMiddleware(modelResolver, options = {}) {
|
|
|
693
430
|
resource: { fromMethodMap: abilityFor === void 0 }
|
|
694
431
|
} });
|
|
695
432
|
}
|
|
696
|
-
/**
|
|
697
|
-
* Create a gate-aware context with authorization helpers.
|
|
698
|
-
*/
|
|
433
|
+
/** Create a gate-aware context with authorization helpers. */
|
|
699
434
|
function withAuthorization(gate) {
|
|
700
435
|
return async (ctx, next) => {
|
|
701
436
|
const user = await gate.resolveUser(ctx);
|