@guren/server 0.2.0-alpha.7 → 1.0.0-rc.9
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/Application-DtWDHXr1.d.ts +2110 -0
- package/dist/BroadcastManager-AkIWUGJo.d.ts +466 -0
- package/dist/CacheManager-BkvHEOZX.d.ts +244 -0
- package/dist/ConsoleKernel-CqCVrdZs.d.ts +207 -0
- package/dist/EventManager-CmIoLt7r.d.ts +207 -0
- package/dist/Gate-CNkBYf8m.d.ts +268 -0
- package/dist/HealthManager-DUyMIzsZ.d.ts +141 -0
- package/dist/I18nManager-Dtgzsf5n.d.ts +270 -0
- package/dist/LogManager-7mxnkaPM.d.ts +256 -0
- package/dist/MailManager-DpMvYiP9.d.ts +292 -0
- package/dist/Scheduler-BstvSca7.d.ts +469 -0
- package/dist/StorageManager-oZTHqaza.d.ts +337 -0
- package/dist/api-token-JOif2CtG.d.ts +1792 -0
- package/dist/app-key-CsBfRC_Q.d.ts +214 -0
- package/dist/auth/index.d.ts +418 -0
- package/dist/auth/index.js +6742 -0
- package/dist/authorization/index.d.ts +129 -0
- package/dist/authorization/index.js +621 -0
- package/dist/broadcasting/index.d.ts +233 -0
- package/dist/broadcasting/index.js +907 -0
- package/dist/cache/index.d.ts +233 -0
- package/dist/cache/index.js +817 -0
- package/dist/encryption/index.d.ts +222 -0
- package/dist/encryption/index.js +602 -0
- package/dist/events/index.d.ts +155 -0
- package/dist/events/index.js +330 -0
- package/dist/health/index.d.ts +185 -0
- package/dist/health/index.js +379 -0
- package/dist/i18n/index.d.ts +101 -0
- package/dist/i18n/index.js +597 -0
- package/dist/index-9_Jzj5jo.d.ts +7 -0
- package/dist/index.d.ts +2628 -619
- package/dist/index.js +22229 -3116
- package/dist/lambda/index.d.ts +156 -0
- package/dist/lambda/index.js +91 -0
- package/dist/logging/index.d.ts +50 -0
- package/dist/logging/index.js +557 -0
- package/dist/mail/index.d.ts +288 -0
- package/dist/mail/index.js +695 -0
- package/dist/mcp/index.d.ts +139 -0
- package/dist/mcp/index.js +382 -0
- package/dist/notifications/index.d.ts +271 -0
- package/dist/notifications/index.js +741 -0
- package/dist/queue/index.d.ts +423 -0
- package/dist/queue/index.js +958 -0
- package/dist/runtime/index.d.ts +93 -0
- package/dist/runtime/index.js +834 -0
- package/dist/scheduling/index.d.ts +41 -0
- package/dist/scheduling/index.js +836 -0
- package/dist/storage/index.d.ts +196 -0
- package/dist/storage/index.js +832 -0
- package/dist/vite/index.js +203 -3
- package/package.json +93 -6
- package/dist/chunk-FK2XQSBF.js +0 -160
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { f as Policy$1, A as AuthUser, a as AuthorizationResponse, G as Gate, b as AuthorizeOptions } from '../Gate-CNkBYf8m.js';
|
|
2
|
+
export { c as GateCallback, d as GateDefinition, e as GateOptions, P as PolicyClass, g as PolicyMethod, h as PolicyRegistration, i as ResourceAction, R as Response, j as ResponseBuilder, k as authorize, l as can, m as cannot, n as createGate, o as defineGate, p as getGate, s as setGate } from '../Gate-CNkBYf8m.js';
|
|
3
|
+
import { Context } from 'hono';
|
|
4
|
+
import { M as Middleware } from '../index-9_Jzj5jo.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Base policy class for model authorization.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* class PostPolicy extends Policy {
|
|
12
|
+
* // Runs before all checks - return true/false to short-circuit
|
|
13
|
+
* before(user: AuthUser | null, ability: string) {
|
|
14
|
+
* if (user?.role === 'admin') {
|
|
15
|
+
* return true // Admins can do anything
|
|
16
|
+
* }
|
|
17
|
+
* return undefined // Continue to specific check
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* viewAny(user: AuthUser | null) {
|
|
21
|
+
* return true // Anyone can view posts list
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* view(user: AuthUser | null, post: Post) {
|
|
25
|
+
* return post.published || user?.id === post.authorId
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* create(user: AuthUser | null) {
|
|
29
|
+
* return user !== null
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* update(user: AuthUser | null, post: Post) {
|
|
33
|
+
* return user?.id === post.authorId
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* delete(user: AuthUser | null, post: Post) {
|
|
37
|
+
* return user?.id === post.authorId
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
declare abstract class Policy implements Policy$1 {
|
|
43
|
+
/**
|
|
44
|
+
* Perform pre-authorization checks.
|
|
45
|
+
* Return true to allow, false to deny, undefined to continue to specific check.
|
|
46
|
+
*/
|
|
47
|
+
before?(user: AuthUser | null, ability: string): boolean | undefined | Promise<boolean | undefined>;
|
|
48
|
+
/**
|
|
49
|
+
* Allow the action.
|
|
50
|
+
*/
|
|
51
|
+
protected allow(message?: string): AuthorizationResponse;
|
|
52
|
+
/**
|
|
53
|
+
* Deny the action.
|
|
54
|
+
*/
|
|
55
|
+
protected deny(message?: string, code?: string): AuthorizationResponse;
|
|
56
|
+
/**
|
|
57
|
+
* Deny with a specific HTTP status.
|
|
58
|
+
*/
|
|
59
|
+
protected denyWithStatus(status: number, message?: string): AuthorizationResponse & {
|
|
60
|
+
status: number;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Deny as not found (404).
|
|
64
|
+
*/
|
|
65
|
+
protected denyAsNotFound(message?: string): AuthorizationResponse & {
|
|
66
|
+
status: 404;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Create a simple policy from an object.
|
|
71
|
+
*/
|
|
72
|
+
declare function definePolicy<T>(definition: {
|
|
73
|
+
before?: (user: AuthUser | null, ability: string) => boolean | undefined | Promise<boolean | undefined>;
|
|
74
|
+
viewAny?: (user: AuthUser | null) => boolean | Promise<boolean>;
|
|
75
|
+
view?: (user: AuthUser | null, model: T) => boolean | Promise<boolean>;
|
|
76
|
+
create?: (user: AuthUser | null) => boolean | Promise<boolean>;
|
|
77
|
+
update?: (user: AuthUser | null, model: T) => boolean | Promise<boolean>;
|
|
78
|
+
delete?: (user: AuthUser | null, model: T) => boolean | Promise<boolean>;
|
|
79
|
+
restore?: (user: AuthUser | null, model: T) => boolean | Promise<boolean>;
|
|
80
|
+
forceDelete?: (user: AuthUser | null, model: T) => boolean | Promise<boolean>;
|
|
81
|
+
} & Record<string, ((user: AuthUser | null, ...args: any[]) => boolean | undefined | Promise<boolean | undefined>) | undefined>): new () => Policy;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Middleware to authorize an ability.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* // Authorize a simple ability
|
|
89
|
+
* app.get('/admin', authorizeMiddleware('admin'), adminHandler)
|
|
90
|
+
*
|
|
91
|
+
* // Authorize with model (from route param)
|
|
92
|
+
* app.put('/posts/:id', authorizeMiddleware('update', getPost), updateHandler)
|
|
93
|
+
*
|
|
94
|
+
* // Multiple abilities (any)
|
|
95
|
+
* app.get('/dashboard', authorizeMiddleware(['admin', 'moderator']), dashboardHandler)
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
declare function authorizeMiddleware(ability: string | string[], modelResolver?: (ctx: Context) => unknown | Promise<unknown>, options?: AuthorizeOptions): Middleware;
|
|
99
|
+
/**
|
|
100
|
+
* Middleware to authorize all given abilities.
|
|
101
|
+
*/
|
|
102
|
+
declare function authorizeAllMiddleware(abilities: string[], modelResolver?: (ctx: Context) => unknown | Promise<unknown>, options?: AuthorizeOptions): Middleware;
|
|
103
|
+
/**
|
|
104
|
+
* Middleware factory for resource authorization.
|
|
105
|
+
* Automatically maps HTTP methods to policy abilities.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* // Authorize resource actions based on HTTP method
|
|
110
|
+
* app.use('/posts/:id', authorizeResourceMiddleware(getPost))
|
|
111
|
+
* // GET -> view, POST -> create, PUT/PATCH -> update, DELETE -> delete
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
declare function authorizeResourceMiddleware(modelResolver: (ctx: Context) => unknown | Promise<unknown>, options?: AuthorizeOptions): Middleware;
|
|
115
|
+
/**
|
|
116
|
+
* Create a gate-aware context with authorization helpers.
|
|
117
|
+
*/
|
|
118
|
+
declare function withAuthorization(gate: Gate): Middleware;
|
|
119
|
+
/**
|
|
120
|
+
* Helper type for context with authorization.
|
|
121
|
+
*/
|
|
122
|
+
interface AuthorizedContext extends Context {
|
|
123
|
+
get(key: 'gate'): Gate;
|
|
124
|
+
get(key: 'can'): (ability: string, ...args: unknown[]) => Promise<boolean>;
|
|
125
|
+
get(key: 'cannot'): (ability: string, ...args: unknown[]) => Promise<boolean>;
|
|
126
|
+
get(key: 'authorize'): (ability: string, ...args: unknown[]) => Promise<void>;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export { AuthUser, AuthorizationResponse, AuthorizeOptions, type AuthorizedContext, Gate, Policy, Policy$1 as PolicyInterface, authorizeAllMiddleware, authorizeMiddleware, authorizeResourceMiddleware, definePolicy, withAuthorization };
|