@amaster.ai/client 1.1.0-beta.6 → 1.1.0-beta.61

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.
@@ -1,254 +0,0 @@
1
- /**
2
- * ============================================================================
3
- * Permission Checking - Type Definitions & Helpers
4
- * ============================================================================
5
- *
6
- * Permission and role checking utilities:
7
- * - Type-safe permission checking
8
- * - Role validation
9
- * - Permission helpers
10
- *
11
- * @module auth/permissions
12
- */
13
-
14
- import type { User } from './user';
15
-
16
- /**
17
- * Permission check result
18
- */
19
- export interface PermissionCheckResult {
20
- /** Whether the permission check passed */
21
- granted: boolean;
22
-
23
- /** Optional reason if denied */
24
- reason?: string;
25
- }
26
-
27
- /**
28
- * Permission checking helpers
29
- *
30
- * @example
31
- * Check single permission:
32
- * ```typescript
33
- * import { hasPermission } from '@amaster.ai/client/auth/permissions';
34
- *
35
- * const user = await client.auth.getMe().then(r => r.data);
36
- *
37
- * if (hasPermission(user, 'user:delete')) {
38
- * showDeleteButton();
39
- * }
40
- * ```
41
- *
42
- * @example
43
- * Check role:
44
- * ```typescript
45
- * import { hasRole } from '@amaster.ai/client/auth/permissions';
46
- *
47
- * if (hasRole(user, 'admin')) {
48
- * showAdminPanel();
49
- * }
50
- * ```
51
- *
52
- * @example
53
- * Check any of multiple permissions:
54
- * ```typescript
55
- * import { hasAnyPermission } from '@amaster.ai/client/auth/permissions';
56
- *
57
- * if (hasAnyPermission(user, ['user:read', 'user:write', 'user:delete'])) {
58
- * showUserManagement();
59
- * }
60
- * ```
61
- */
62
- export namespace PermissionHelpers {
63
- /**
64
- * Check if user has a specific permission
65
- *
66
- * @param user - User object with permissions
67
- * @param permission - Permission to check (format: "resource:action")
68
- * @returns True if user has the permission
69
- *
70
- * @example
71
- * ```typescript
72
- * const canDelete = hasPermission(user, 'user:delete');
73
- * const canRead = hasPermission(user, 'order:read');
74
- * ```
75
- */
76
- export function hasPermission(user: User | null | undefined, permission: string): boolean;
77
-
78
- /**
79
- * Check if user has a specific role
80
- *
81
- * @param user - User object with roles
82
- * @param role - Role code to check
83
- * @returns True if user has the role
84
- *
85
- * @example
86
- * ```typescript
87
- * const isAdmin = hasRole(user, 'admin');
88
- * const isManager = hasRole(user, 'manager');
89
- * ```
90
- */
91
- export function hasRole(user: User | null | undefined, role: string): boolean;
92
-
93
- /**
94
- * Check if user has ANY of the specified permissions
95
- *
96
- * @param user - User object with permissions
97
- * @param permissions - Array of permissions to check
98
- * @returns True if user has at least one permission
99
- *
100
- * @example
101
- * ```typescript
102
- * // User can access if they have ANY of these permissions
103
- * const canAccessUsers = hasAnyPermission(user, [
104
- * 'user:read',
105
- * 'user:write',
106
- * 'user:delete'
107
- * ]);
108
- * ```
109
- */
110
- export function hasAnyPermission(user: User | null | undefined, permissions: string[]): boolean;
111
-
112
- /**
113
- * Check if user has ALL of the specified permissions
114
- *
115
- * @param user - User object with permissions
116
- * @param permissions - Array of permissions to check
117
- * @returns True if user has all permissions
118
- *
119
- * @example
120
- * ```typescript
121
- * // User needs ALL of these permissions
122
- * const canManageUsers = hasAllPermissions(user, [
123
- * 'user:read',
124
- * 'user:write',
125
- * 'user:delete'
126
- * ]);
127
- * ```
128
- */
129
- export function hasAllPermissions(user: User | null | undefined, permissions: string[]): boolean;
130
-
131
- /**
132
- * Check if user has ANY of the specified roles
133
- *
134
- * @param user - User object with roles
135
- * @param roles - Array of role codes to check
136
- * @returns True if user has at least one role
137
- *
138
- * @example
139
- * ```typescript
140
- * const isStaff = hasAnyRole(user, ['admin', 'moderator', 'support']);
141
- * ```
142
- */
143
- export function hasAnyRole(user: User | null | undefined, roles: string[]): boolean;
144
-
145
- /**
146
- * Check if user has ALL of the specified roles
147
- *
148
- * @param user - User object with roles
149
- * @param roles - Array of role codes to check
150
- * @returns True if user has all roles
151
- *
152
- * @example
153
- * ```typescript
154
- * const isSuperAdmin = hasAllRoles(user, ['admin', 'superuser']);
155
- * ```
156
- */
157
- export function hasAllRoles(user: User | null | undefined, roles: string[]): boolean;
158
- }
159
-
160
- /**
161
- * Re-export helpers as individual functions for convenience
162
- *
163
- * @example
164
- * ```typescript
165
- * import { hasPermission, hasRole } from '@amaster.ai/client/auth/permissions';
166
- *
167
- * const canDelete = hasPermission(user, 'user:delete');
168
- * const isAdmin = hasRole(user, 'admin');
169
- * ```
170
- */
171
-
172
- /**
173
- * Check if user has a specific permission
174
- *
175
- * @param user - User object with permissions
176
- * @param permission - Permission to check (format: "resource:action")
177
- * @returns True if user has the permission
178
- *
179
- * @example
180
- * ```typescript
181
- * const canDelete = hasPermission(user, 'user:delete');
182
- * ```
183
- */
184
- export declare function hasPermission(user: User | null | undefined, permission: string): boolean;
185
-
186
- /**
187
- * Check if user has a specific role
188
- *
189
- * @param user - User object with roles
190
- * @param role - Role code to check
191
- * @returns True if user has the role
192
- *
193
- * @example
194
- * ```typescript
195
- * const isAdmin = hasRole(user, 'admin');
196
- * ```
197
- */
198
- export declare function hasRole(user: User | null | undefined, role: string): boolean;
199
-
200
- /**
201
- * Check if user has ANY of the specified permissions
202
- *
203
- * @param user - User object with permissions
204
- * @param permissions - Array of permissions to check
205
- * @returns True if user has at least one permission
206
- *
207
- * @example
208
- * ```typescript
209
- * const canAccessUsers = hasAnyPermission(user, ['user:read', 'user:write']);
210
- * ```
211
- */
212
- export declare function hasAnyPermission(user: User | null | undefined, permissions: string[]): boolean;
213
-
214
- /**
215
- * Check if user has ALL of the specified permissions
216
- *
217
- * @param user - User object with permissions
218
- * @param permissions - Array of permissions to check
219
- * @returns True if user has all permissions
220
- *
221
- * @example
222
- * ```typescript
223
- * const canManageUsers = hasAllPermissions(user, ['user:read', 'user:write', 'user:delete']);
224
- * ```
225
- */
226
- export declare function hasAllPermissions(user: User | null | undefined, permissions: string[]): boolean;
227
-
228
- /**
229
- * Check if user has ANY of the specified roles
230
- *
231
- * @param user - User object with roles
232
- * @param roles - Array of role codes to check
233
- * @returns True if user has at least one role
234
- *
235
- * @example
236
- * ```typescript
237
- * const isStaff = hasAnyRole(user, ['admin', 'moderator']);
238
- * ```
239
- */
240
- export declare function hasAnyRole(user: User | null | undefined, roles: string[]): boolean;
241
-
242
- /**
243
- * Check if user has ALL of the specified roles
244
- *
245
- * @param user - User object with roles
246
- * @param roles - Array of role codes to check
247
- * @returns True if user has all roles
248
- *
249
- * @example
250
- * ```typescript
251
- * const isSuperAdmin = hasAllRoles(user, ['admin', 'superuser']);
252
- * ```
253
- */
254
- export declare function hasAllRoles(user: User | null | undefined, roles: string[]): boolean;