@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.
Files changed (297) hide show
  1. package/dist/{DocsViewerServiceProvider-qFCaeiUv.js → DocsViewerServiceProvider-D2cuVgtN.js} +7 -12
  2. package/dist/{Hash-CzrwKeDp.js → Hash-D2DFd8xX.js} +12 -57
  3. package/dist/{HttpException-BkS3euNG.js → HttpException-BlQ2yEmT.js} +2 -79
  4. package/dist/{Job-BVT813DO.js → Job-DxQK8h3P.js} +24 -179
  5. package/dist/{McpServiceProvider-BawsYjgN.js → McpServiceProvider-nNcbCIQX.js} +11 -20
  6. package/dist/{Random-DbIJ22KQ.js → Random-S0OvCuR8.js} +9 -106
  7. package/dist/agent/AgentApprovalRequested.d.ts +31 -0
  8. package/dist/agent/approval.d.ts +184 -0
  9. package/dist/agent/audit-emitter.d.ts +36 -0
  10. package/dist/agent/audit.d.ts +67 -0
  11. package/dist/agent/derive.d.ts +32 -66
  12. package/dist/agent/dispatch.d.ts +53 -63
  13. package/dist/agent/events.d.ts +11 -19
  14. package/dist/agent/meta-tools.d.ts +34 -0
  15. package/dist/agent/public.d.ts +14 -0
  16. package/dist/agent/public.js +2 -0
  17. package/dist/agent/redact.d.ts +16 -38
  18. package/dist/agent/scopes.d.ts +23 -69
  19. package/dist/auth/AuthManager.d.ts +19 -40
  20. package/dist/auth/AuthenticatableModel.d.ts +2 -2
  21. package/dist/auth/SessionGuard.d.ts +0 -1
  22. package/dist/auth/TokenGuard.d.ts +6 -26
  23. package/dist/auth/api-token.d.ts +16 -148
  24. package/dist/auth/context.d.ts +5 -10
  25. package/dist/auth/email-verification.d.ts +29 -127
  26. package/dist/auth/index.js +1 -1
  27. package/dist/auth/oauth/index.d.ts +35 -57
  28. package/dist/auth/password/DefaultHasher.d.ts +9 -5
  29. package/dist/auth/password/PasswordHasher.d.ts +7 -0
  30. package/dist/auth/password/hash-format.d.ts +11 -0
  31. package/dist/auth/password-reset.d.ts +16 -42
  32. package/dist/auth/providers/ModelUserProvider.d.ts +3 -4
  33. package/dist/auth/providers/UserProvider.d.ts +4 -4
  34. package/dist/auth/signed-token.d.ts +18 -0
  35. package/dist/auth/types.d.ts +9 -32
  36. package/dist/auth/utils.d.ts +6 -27
  37. package/dist/{auth-BSUc14CD.js → auth-CbdPH4Cd.js} +252 -496
  38. package/dist/authorization/Gate.d.ts +9 -145
  39. package/dist/authorization/Policy.d.ts +6 -53
  40. package/dist/authorization/index.js +1 -1
  41. package/dist/authorization/middleware.d.ts +16 -62
  42. package/dist/authorization/types.d.ts +8 -64
  43. package/dist/{authorization-CdfbCj8J.js → authorization-CdEWZZw3.js} +44 -309
  44. package/dist/broadcasting/BroadcastManager.d.ts +29 -149
  45. package/dist/broadcasting/channels/Channel.d.ts +1 -19
  46. package/dist/broadcasting/channels/PresenceChannel.d.ts +1 -55
  47. package/dist/broadcasting/channels/PrivateChannel.d.ts +1 -23
  48. package/dist/broadcasting/drivers/MemoryDriver.d.ts +18 -70
  49. package/dist/broadcasting/drivers/RedisDriver.d.ts +3 -80
  50. package/dist/broadcasting/drivers/index.d.ts +1 -1
  51. package/dist/broadcasting/index.d.ts +1 -1
  52. package/dist/broadcasting/index.js +1 -1
  53. package/dist/broadcasting/types.d.ts +7 -88
  54. package/dist/{broadcasting-BxU-LIfF.js → broadcasting-B5RzB0A2.js} +87 -414
  55. package/dist/cache/CacheManager.d.ts +8 -62
  56. package/dist/cache/TaggedCache.d.ts +2 -35
  57. package/dist/cache/index.js +1 -1
  58. package/dist/cache/stores/FileStore.d.ts +2 -36
  59. package/dist/cache/stores/MemoryStore.d.ts +2 -26
  60. package/dist/cache/stores/RedisStore.d.ts +1 -29
  61. package/dist/cache/types.d.ts +21 -128
  62. package/dist/{cache-BYnZf2FR.js → cache-BOOIr324.js} +19 -198
  63. package/dist/client-C4TEr_Dd.js +9 -0
  64. package/dist/console/Command.d.ts +17 -126
  65. package/dist/console/ConsoleKernel.d.ts +2 -74
  66. package/dist/console/Input.d.ts +5 -113
  67. package/dist/console/Output.d.ts +3 -99
  68. package/dist/console/types.d.ts +3 -33
  69. package/dist/container/Container.d.ts +12 -103
  70. package/dist/container/ServiceProvider.d.ts +17 -61
  71. package/dist/container/bindings.d.ts +10 -12
  72. package/dist/container/defineModule.d.ts +16 -54
  73. package/dist/container/definePlugin.d.ts +12 -45
  74. package/dist/container/types.d.ts +2 -34
  75. package/dist/context-CXk_umpT.js +21 -0
  76. package/dist/database/Factory.d.ts +4 -57
  77. package/dist/database/Seeder.d.ts +8 -46
  78. package/dist/database/SeederRunner.d.ts +3 -33
  79. package/dist/database/types.d.ts +3 -24
  80. package/dist/discovery/AutoDiscovery.d.ts +10 -82
  81. package/dist/dispatch-BAwzftws.js +238 -0
  82. package/dist/docs-viewer/DocsViewerServiceProvider.d.ts +2 -5
  83. package/dist/docs-viewer/endpoint.d.ts +5 -11
  84. package/dist/encryption/Encrypter.d.ts +5 -71
  85. package/dist/encryption/Hash.d.ts +7 -57
  86. package/dist/encryption/Random.d.ts +6 -99
  87. package/dist/encryption/index.js +3 -3
  88. package/dist/encryption/types.d.ts +10 -72
  89. package/dist/{encryption-DJtkkhiw.js → encryption-uwP3Di4D.js} +13 -79
  90. package/dist/{endpoint-D6GIqOpe.js → endpoint-BXipU2Jj.js} +6 -12
  91. package/dist/endpoint-Dsw3Acvq.js +26 -0
  92. package/dist/errors/ExceptionHandler.d.ts +3 -90
  93. package/dist/errors/HttpException.d.ts +2 -79
  94. package/dist/errors/debug-page.d.ts +3 -17
  95. package/dist/errors/error-page.d.ts +1 -0
  96. package/dist/errors/exceptions/AuthenticationException.d.ts +2 -24
  97. package/dist/errors/exceptions/AuthorizationException.d.ts +1 -24
  98. package/dist/errors/exceptions/MethodNotAllowedException.d.ts +1 -23
  99. package/dist/errors/exceptions/NotFoundHttpException.d.ts +1 -27
  100. package/dist/errors/exceptions/ValidationException.d.ts +2 -43
  101. package/dist/errors/types.d.ts +1 -25
  102. package/dist/{errors-BgeOl_DC.js → errors-JpkcCjjn.js} +3 -41
  103. package/dist/events/Event.d.ts +1 -28
  104. package/dist/events/EventManager.d.ts +5 -107
  105. package/dist/events/Listener.d.ts +7 -55
  106. package/dist/events/builtin.d.ts +0 -24
  107. package/dist/events/index.js +1 -1
  108. package/dist/events/types.d.ts +4 -22
  109. package/dist/{events-aIH_bWRx.js → events-DOmAHDeP.js} +11 -191
  110. package/dist/facades/index.d.ts +2 -14
  111. package/dist/health/HealthCheck.d.ts +0 -24
  112. package/dist/health/HealthManager.d.ts +0 -36
  113. package/dist/health/checks/CacheCheck.d.ts +2 -17
  114. package/dist/health/checks/CustomCheck.d.ts +0 -9
  115. package/dist/health/checks/DatabaseCheck.d.ts +2 -17
  116. package/dist/health/checks/MemoryCheck.d.ts +3 -12
  117. package/dist/health/checks/RedisCheck.d.ts +1 -13
  118. package/dist/health/checks/StorageCheck.d.ts +2 -17
  119. package/dist/health/index.js +1 -1
  120. package/dist/health/types.d.ts +4 -24
  121. package/dist/{health-VWdWXRwh.js → health-DQSvUplL.js} +1 -76
  122. package/dist/hot-disposables-B5BXqaIH.js +167 -0
  123. package/dist/hot-reload/hot-disposables.d.ts +22 -74
  124. package/dist/hot-reload/testing.d.ts +4 -9
  125. package/dist/http/Application.d.ts +62 -208
  126. package/dist/http/FormRequest.d.ts +4 -55
  127. package/dist/http/dev-assets.d.ts +16 -18
  128. package/dist/http/dev-banner.d.ts +2 -5
  129. package/dist/http/inertia-assets.d.ts +3 -6
  130. package/dist/http/middleware/capabilities.d.ts +27 -50
  131. package/dist/http/middleware/cors.d.ts +4 -29
  132. package/dist/http/middleware/csp.d.ts +2 -25
  133. package/dist/http/middleware/csrf.d.ts +20 -95
  134. package/dist/http/middleware/detect-locale.d.ts +7 -27
  135. package/dist/http/middleware/force-https.d.ts +6 -24
  136. package/dist/http/middleware/host-authorization.d.ts +2 -12
  137. package/dist/http/middleware/loopback-guard.d.ts +15 -33
  138. package/dist/http/middleware/rate-limit.d.ts +29 -126
  139. package/dist/http/middleware/redirect-safety.d.ts +2 -20
  140. package/dist/http/middleware/request-id.d.ts +1 -14
  141. package/dist/http/middleware/request-logging.d.ts +2 -13
  142. package/dist/http/middleware/response-headers.d.ts +5 -13
  143. package/dist/http/middleware/security-headers.d.ts +2 -16
  144. package/dist/http/middleware/session.d.ts +15 -34
  145. package/dist/http/middleware/validation-errors-cookie.d.ts +7 -18
  146. package/dist/http/middleware/validation.d.ts +8 -63
  147. package/dist/http/public-assets.d.ts +14 -0
  148. package/dist/http/request.d.ts +49 -48
  149. package/dist/http/resources/CursorPaginator.d.ts +5 -64
  150. package/dist/http/resources/Paginator.d.ts +7 -84
  151. package/dist/http/resources/Resource.d.ts +9 -65
  152. package/dist/http/resources/ResourceCollection.d.ts +5 -39
  153. package/dist/http/resources/types.d.ts +10 -30
  154. package/dist/http/static-documents.d.ts +21 -0
  155. package/dist/http/validation/Validator.d.ts +25 -85
  156. package/dist/http/validation/rules.d.ts +48 -147
  157. package/dist/http/validation/types.d.ts +16 -61
  158. package/dist/http/vite-assets.d.ts +5 -28
  159. package/dist/http/vite-dev-server.d.ts +6 -9
  160. package/dist/http/vite-manifest.d.ts +19 -33
  161. package/dist/i18n/I18nManager.d.ts +12 -78
  162. package/dist/i18n/Translator.d.ts +3 -54
  163. package/dist/i18n/index.js +1 -1
  164. package/dist/i18n/loaders/JsonLoader.d.ts +4 -31
  165. package/dist/i18n/loaders/MemoryLoader.d.ts +1 -21
  166. package/dist/i18n/pluralization.d.ts +4 -13
  167. package/dist/i18n/types.d.ts +17 -69
  168. package/dist/{i18n-mcWi7LCd.js → i18n-Cg1aajRP.js} +31 -225
  169. package/dist/index.d.ts +13 -4
  170. package/dist/index.js +1036 -3080
  171. package/dist/internal/agent-preflight.d.ts +9 -21
  172. package/dist/internal/request.d.ts +10 -17
  173. package/dist/internal/request.js +2 -2
  174. package/dist/internal/route-path.d.ts +9 -21
  175. package/dist/internal/route-path.js +9 -21
  176. package/dist/internal/zod-compat.d.ts +55 -122
  177. package/dist/internal/zod-compat.js +39 -70
  178. package/dist/internal/zod-json-schema.d.ts +18 -54
  179. package/dist/internal/zod-json-schema.js +46 -123
  180. package/dist/jsx-runtime.d.ts +3 -8
  181. package/dist/lambda/index.d.ts +17 -79
  182. package/dist/lambda/index.js +11 -59
  183. package/dist/logging/LogManager.d.ts +1 -51
  184. package/dist/logging/Logger.d.ts +8 -47
  185. package/dist/logging/channels/ConsoleChannel.d.ts +1 -3
  186. package/dist/logging/channels/DailyFileChannel.d.ts +1 -5
  187. package/dist/logging/channels/FileChannel.d.ts +1 -3
  188. package/dist/logging/daily-file-path.d.ts +15 -0
  189. package/dist/logging/index.d.ts +1 -0
  190. package/dist/logging/index.js +2 -2
  191. package/dist/logging/types.d.ts +13 -45
  192. package/dist/{logging-CPaRMuPP.js → logging-zOY1XCtq.js} +83 -129
  193. package/dist/{loopback-guard-D0Kc7-xc.js → loopback-guard-DT9gHF0F.js} +41 -92
  194. package/dist/mail/Mail.d.ts +10 -106
  195. package/dist/mail/MailManager.d.ts +2 -60
  196. package/dist/mail/index.js +1 -1
  197. package/dist/mail/transports/LogTransport.d.ts +1 -4
  198. package/dist/mail/transports/MemoryTransport.d.ts +1 -63
  199. package/dist/mail/transports/ResendTransport.d.ts +1 -23
  200. package/dist/mail/transports/SmtpTransport.d.ts +1 -31
  201. package/dist/mail/types.d.ts +28 -150
  202. package/dist/{mail-DfEfSQEr.js → mail-76DWy9lj.js} +31 -289
  203. package/dist/mcp/McpServiceProvider.d.ts +4 -10
  204. package/dist/mcp/create-mcp-server.d.ts +25 -57
  205. package/dist/mcp/endpoint.d.ts +12 -36
  206. package/dist/mcp/index.js +1 -1
  207. package/dist/mvc/Controller.d.ts +46 -253
  208. package/dist/mvc/Router.d.ts +50 -129
  209. package/dist/mvc/inertia/InertiaEngine.d.ts +18 -48
  210. package/dist/mvc/inertia/shared.d.ts +6 -19
  211. package/dist/mvc/mount-route.d.ts +2 -6
  212. package/dist/mvc/view.d.ts +1 -2
  213. package/dist/notifications/Notification.d.ts +8 -75
  214. package/dist/notifications/NotificationManager.d.ts +15 -88
  215. package/dist/notifications/channels/DatabaseChannel.d.ts +1 -41
  216. package/dist/notifications/channels/MailChannel.d.ts +2 -31
  217. package/dist/notifications/channels/MemoryChannel.d.ts +2 -62
  218. package/dist/notifications/channels/SlackChannel.d.ts +3 -48
  219. package/dist/notifications/index.js +1 -1
  220. package/dist/notifications/notifiable-type.d.ts +3 -6
  221. package/dist/notifications/registry.d.ts +8 -27
  222. package/dist/notifications/types.d.ts +16 -53
  223. package/dist/{notifications-BGqmUNZ8.js → notifications-okWFs9ly.js} +37 -335
  224. package/dist/providers/AuthServiceProvider.d.ts +1 -3
  225. package/dist/providers/AuthorizationServiceProvider.d.ts +2 -3
  226. package/dist/providers/BroadcastServiceProvider.d.ts +1 -3
  227. package/dist/providers/CacheServiceProvider.d.ts +1 -3
  228. package/dist/providers/EncryptionServiceProvider.d.ts +1 -3
  229. package/dist/providers/ErrorServiceProvider.d.ts +1 -4
  230. package/dist/providers/EventServiceProvider.d.ts +1 -3
  231. package/dist/providers/HealthServiceProvider.d.ts +1 -3
  232. package/dist/providers/I18nServiceProvider.d.ts +6 -10
  233. package/dist/providers/InertiaServiceProvider.d.ts +1 -4
  234. package/dist/providers/LogServiceProvider.d.ts +1 -3
  235. package/dist/providers/MailServiceProvider.d.ts +1 -3
  236. package/dist/providers/NotificationServiceProvider.d.ts +1 -3
  237. package/dist/providers/OAuthServiceProvider.d.ts +1 -3
  238. package/dist/providers/QueueServiceProvider.d.ts +1 -3
  239. package/dist/providers/SchedulingServiceProvider.d.ts +1 -3
  240. package/dist/providers/StorageServiceProvider.d.ts +1 -3
  241. package/dist/queue/FailedJobReporter.d.ts +1 -24
  242. package/dist/queue/Job.d.ts +12 -99
  243. package/dist/queue/QueueManager.d.ts +6 -57
  244. package/dist/queue/Worker.d.ts +4 -65
  245. package/dist/queue/drivers/MemoryDriver.d.ts +3 -44
  246. package/dist/queue/drivers/RedisDriver.d.ts +7 -65
  247. package/dist/queue/drivers/SqsDriver.d.ts +6 -57
  248. package/dist/queue/drivers/SyncDriver.d.ts +10 -13
  249. package/dist/queue/index.js +2 -2
  250. package/dist/queue/types.d.ts +10 -92
  251. package/dist/{queue-CXrRK85G.js → queue-CcXCjuJI.js} +32 -260
  252. package/dist/redis/RedisApiTokenStore.d.ts +4 -56
  253. package/dist/redis/RedisEmailVerificationStore.d.ts +4 -37
  254. package/dist/redis/RedisOAuthStateStore.d.ts +2 -10
  255. package/dist/redis/RedisPasswordResetStore.d.ts +4 -37
  256. package/dist/redis/RedisRateLimitStore.d.ts +16 -49
  257. package/dist/redis/RedisSessionStore.d.ts +3 -44
  258. package/dist/redis/client.d.ts +2 -32
  259. package/dist/redis/index.js +47 -232
  260. package/dist/redis/redis-values.d.ts +6 -12
  261. package/dist/redis/scan-keys.d.ts +1 -4
  262. package/dist/request-CLOYytGP.js +68 -0
  263. package/dist/runtime/index.d.ts +2 -0
  264. package/dist/runtime/index.js +108 -74
  265. package/dist/scheduling/CronParser.d.ts +0 -29
  266. package/dist/scheduling/Schedule.d.ts +1 -153
  267. package/dist/scheduling/ScheduledTask.d.ts +0 -31
  268. package/dist/scheduling/Scheduler.d.ts +0 -70
  269. package/dist/scheduling/index.js +1 -1
  270. package/dist/scheduling/types.d.ts +4 -65
  271. package/dist/{scheduling-CPiEdtQd.js → scheduling-C6tcOtUl.js} +2 -287
  272. package/dist/storage/StorageManager.d.ts +0 -48
  273. package/dist/storage/drivers/LocalDriver.d.ts +1 -25
  274. package/dist/storage/drivers/MemoryDriver.d.ts +5 -35
  275. package/dist/storage/drivers/S3Driver.d.ts +6 -36
  276. package/dist/storage/drivers/s3-acl.d.ts +5 -10
  277. package/dist/storage/index.js +1 -1
  278. package/dist/storage/types.d.ts +27 -265
  279. package/dist/{storage-TLD9t0Q2.js → storage-BB59f07j.js} +17 -157
  280. package/dist/support/contained-path.d.ts +10 -20
  281. package/dist/support/error-polyfill.d.ts +4 -6
  282. package/dist/support/expiry.d.ts +17 -33
  283. package/dist/support/expiry.js +17 -33
  284. package/dist/support/import-map.d.ts +3 -7
  285. package/dist/support/inertia-defaults.d.ts +5 -10
  286. package/dist/support/redirect-target.d.ts +4 -6
  287. package/dist/support/stack-frames.d.ts +11 -50
  288. package/dist/support/trim-slashes.d.ts +4 -7
  289. package/dist/support/warn-once.d.ts +2 -6
  290. package/dist/{trim-slashes-ZJ_VsY5s.js → trim-slashes-BLY9hKAa.js} +4 -7
  291. package/dist/{vite-manifest-BGfWbPYp.js → vite-manifest-CTQp-SOo.js} +34 -58
  292. package/package.json +6 -2
  293. package/dist/client-Dd7vLcqp.js +0 -27
  294. package/dist/context-DoD0c7J_.js +0 -26
  295. package/dist/endpoint-D-20PiHY.js +0 -46
  296. package/dist/hot-disposables-WsTX2ySN.js +0 -281
  297. package/dist/request-CRVuIiQr.js +0 -78
@@ -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. The tuple form is
140
- * required for plain records returned by the ORM, which carry no constructor
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
- * @example
6
- * ```typescript
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-CdfbCj8J.js";
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
- * @example
9
- * ```typescript
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
- * The array is snapshotted at creation, so mutating it afterwards changes
32
- * neither what the middleware checks nor what it reports.
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 `authorizeResourceMiddleware` checks for an HTTP method, or
42
- * `undefined` for a method it refuses to guess at (which the middleware
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
- * Middleware factory for resource authorization.
54
- * Automatically maps HTTP methods to policy abilities.
55
- *
56
- * Methods outside the built-in mapping (custom verbs registered via
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 signature of just `boolean` is what let a denial object be read
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, overriding
91
- * or extending the built-in mapping. Return `undefined` to fall back to
92
- * the default mapping; a method with no ability from either source is
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;