@k3-universe/react-kit 0.0.29 → 0.0.31
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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1023 -25
- package/dist/kit/builder/auth/components/Can.d.ts +13 -0
- package/dist/kit/builder/auth/components/Can.d.ts.map +1 -0
- package/dist/kit/builder/auth/components/RequireAuth.d.ts +45 -0
- package/dist/kit/builder/auth/components/RequireAuth.d.ts.map +1 -0
- package/dist/kit/builder/auth/components/ShowWhenAuthenticated.d.ts +8 -0
- package/dist/kit/builder/auth/components/ShowWhenAuthenticated.d.ts.map +1 -0
- package/dist/kit/builder/auth/components/ShowWhenError.d.ts +8 -0
- package/dist/kit/builder/auth/components/ShowWhenError.d.ts.map +1 -0
- package/dist/kit/builder/auth/components/ShowWhenLoading.d.ts +8 -0
- package/dist/kit/builder/auth/components/ShowWhenLoading.d.ts.map +1 -0
- package/dist/kit/builder/auth/components/ShowWhenUnauthenticated.d.ts +8 -0
- package/dist/kit/builder/auth/components/ShowWhenUnauthenticated.d.ts.map +1 -0
- package/dist/kit/builder/auth/components/withPermission.d.ts +7 -0
- package/dist/kit/builder/auth/components/withPermission.d.ts.map +1 -0
- package/dist/kit/builder/auth/hooks/action-hooks.d.ts +18 -0
- package/dist/kit/builder/auth/hooks/action-hooks.d.ts.map +1 -0
- package/dist/kit/builder/auth/hooks/core-hooks.d.ts +56 -0
- package/dist/kit/builder/auth/hooks/core-hooks.d.ts.map +1 -0
- package/dist/kit/builder/auth/hooks/index.d.ts +5 -0
- package/dist/kit/builder/auth/hooks/index.d.ts.map +1 -0
- package/dist/kit/builder/auth/hooks/permission-hooks.d.ts +18 -0
- package/dist/kit/builder/auth/hooks/permission-hooks.d.ts.map +1 -0
- package/dist/kit/builder/auth/hooks/token-hooks.d.ts +13 -0
- package/dist/kit/builder/auth/hooks/token-hooks.d.ts.map +1 -0
- package/dist/kit/builder/auth/index.d.ts +14 -8
- package/dist/kit/builder/auth/index.d.ts.map +1 -1
- package/dist/kit/builder/auth/{AuthProvider.d.ts → providers/AuthProvider.d.ts} +1 -1
- package/dist/kit/builder/auth/providers/AuthProvider.d.ts.map +1 -0
- package/dist/kit/builder/auth/types/adapter-config.d.ts +31 -0
- package/dist/kit/builder/auth/types/adapter-config.d.ts.map +1 -0
- package/dist/kit/builder/auth/types/adapter.d.ts +80 -0
- package/dist/kit/builder/auth/types/adapter.d.ts.map +1 -0
- package/dist/kit/builder/auth/types/core.d.ts +16 -0
- package/dist/kit/builder/auth/types/core.d.ts.map +1 -0
- package/dist/kit/builder/auth/types/index.d.ts +10 -0
- package/dist/kit/builder/auth/types/index.d.ts.map +1 -0
- package/dist/kit/builder/auth/types/middleware.d.ts +11 -0
- package/dist/kit/builder/auth/types/middleware.d.ts.map +1 -0
- package/dist/kit/builder/auth/types/permissions.d.ts +17 -0
- package/dist/kit/builder/auth/types/permissions.d.ts.map +1 -0
- package/dist/kit/builder/auth/types/state.d.ts +13 -0
- package/dist/kit/builder/auth/types/state.d.ts.map +1 -0
- package/dist/kit/builder/auth/types/storage.d.ts +20 -0
- package/dist/kit/builder/auth/types/storage.d.ts.map +1 -0
- package/dist/kit/builder/auth/types/token-manager.d.ts +7 -0
- package/dist/kit/builder/auth/types/token-manager.d.ts.map +1 -0
- package/dist/kit/builder/auth/types/utils.d.ts +7 -0
- package/dist/kit/builder/auth/types/utils.d.ts.map +1 -0
- package/dist/kit/builder/auth/{adapter.d.ts → utils/auth-adapter.d.ts} +2 -2
- package/dist/kit/builder/auth/utils/auth-adapter.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/client-adapters/apollo-link.d.ts +4 -0
- package/dist/kit/builder/auth/utils/client-adapters/apollo-link.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/client-adapters/axios.d.ts +6 -0
- package/dist/kit/builder/auth/utils/client-adapters/axios.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/client-adapters/fetch.d.ts +6 -0
- package/dist/kit/builder/auth/utils/client-adapters/fetch.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/client-adapters/graphql.d.ts +9 -0
- package/dist/kit/builder/auth/utils/client-adapters/graphql.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/client-adapters/index.d.ts +7 -0
- package/dist/kit/builder/auth/utils/client-adapters/index.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/client-adapters/rest.d.ts +9 -0
- package/dist/kit/builder/auth/utils/client-adapters/rest.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/client-adapters/urql-exchange.d.ts +14 -0
- package/dist/kit/builder/auth/utils/client-adapters/urql-exchange.d.ts.map +1 -0
- package/dist/kit/builder/auth/{permission-checker.d.ts → utils/permission-checker.d.ts} +1 -1
- package/dist/kit/builder/auth/utils/permission-checker.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/storage/browser.d.ts +11 -0
- package/dist/kit/builder/auth/utils/storage/browser.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/storage/cookie.d.ts +3 -0
- package/dist/kit/builder/auth/utils/storage/cookie.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/storage/encryption.d.ts +7 -0
- package/dist/kit/builder/auth/utils/storage/encryption.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/storage/env.d.ts +2 -0
- package/dist/kit/builder/auth/utils/storage/env.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/storage/factory.d.ts +6 -0
- package/dist/kit/builder/auth/utils/storage/factory.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/storage/index.d.ts +7 -0
- package/dist/kit/builder/auth/utils/storage/index.d.ts.map +1 -0
- package/dist/kit/builder/auth/utils/storage/memory.d.ts +3 -0
- package/dist/kit/builder/auth/utils/storage/memory.d.ts.map +1 -0
- package/dist/kit/builder/auth/{token-manager.d.ts → utils/token-manager.d.ts} +1 -1
- package/dist/kit/builder/auth/utils/token-manager.d.ts.map +1 -0
- package/dist/kit/components/login/Login.d.ts +2 -1
- package/dist/kit/components/login/Login.d.ts.map +1 -1
- package/dist/kit/layouts/admin/components/AdminLayout.d.ts +2 -1
- package/dist/kit/layouts/admin/components/AdminLayout.d.ts.map +1 -1
- package/dist/kit/themes/clean-slate.css +28 -4
- package/dist/kit/themes/default.css +28 -4
- package/dist/kit/themes/minimal-modern.css +28 -4
- package/dist/kit/themes/spotify.css +28 -4
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/kit/builder/auth/components/Can.tsx +27 -0
- package/src/kit/builder/auth/components/RequireAuth.tsx +78 -0
- package/src/kit/builder/auth/components/ShowWhenAuthenticated.tsx +10 -0
- package/src/kit/builder/auth/components/ShowWhenError.tsx +10 -0
- package/src/kit/builder/auth/components/ShowWhenLoading.tsx +10 -0
- package/src/kit/builder/auth/components/ShowWhenUnauthenticated.tsx +10 -0
- package/src/kit/builder/auth/components/withPermission.tsx +23 -0
- package/src/kit/builder/auth/hooks/action-hooks.ts +34 -0
- package/src/kit/builder/auth/hooks/core-hooks.ts +65 -0
- package/src/kit/builder/auth/hooks/index.ts +4 -0
- package/src/kit/builder/auth/hooks/permission-hooks.ts +43 -0
- package/src/kit/builder/auth/hooks/token-hooks.ts +25 -0
- package/src/kit/builder/auth/index.ts +16 -18
- package/src/kit/builder/auth/{AuthProvider.tsx → providers/AuthProvider.tsx} +1 -1
- package/src/kit/builder/auth/types/adapter-config.ts +44 -0
- package/src/kit/builder/auth/types/adapter.ts +132 -0
- package/src/kit/builder/auth/types/core.ts +27 -0
- package/src/kit/builder/auth/types/index.ts +9 -0
- package/src/kit/builder/auth/types/middleware.ts +20 -0
- package/src/kit/builder/auth/types/permissions.ts +23 -0
- package/src/kit/builder/auth/types/state.ts +16 -0
- package/src/kit/builder/auth/types/storage.ts +21 -0
- package/src/kit/builder/auth/types/token-manager.ts +9 -0
- package/src/kit/builder/auth/types/utils.ts +55 -0
- package/src/kit/builder/auth/{adapter.ts → utils/auth-adapter.ts} +3 -2
- package/src/kit/builder/auth/utils/client-adapters/apollo-link.ts +30 -0
- package/src/kit/builder/auth/utils/client-adapters/axios.ts +61 -0
- package/src/kit/builder/auth/utils/client-adapters/fetch.ts +48 -0
- package/src/kit/builder/auth/utils/client-adapters/graphql.ts +60 -0
- package/src/kit/builder/auth/utils/client-adapters/index.ts +6 -0
- package/src/kit/builder/auth/utils/client-adapters/rest.ts +60 -0
- package/src/kit/builder/auth/utils/client-adapters/urql-exchange.ts +76 -0
- package/src/kit/builder/auth/{permission-checker.ts → utils/permission-checker.ts} +1 -1
- package/src/kit/builder/auth/utils/storage/browser.ts +99 -0
- package/src/kit/builder/auth/utils/storage/cookie.ts +116 -0
- package/src/kit/builder/auth/utils/storage/encryption.ts +80 -0
- package/src/kit/builder/auth/utils/storage/env.ts +2 -0
- package/src/kit/builder/auth/utils/storage/factory.ts +37 -0
- package/src/kit/builder/auth/utils/storage/index.ts +6 -0
- package/src/kit/builder/auth/utils/storage/memory.ts +15 -0
- package/src/kit/builder/auth/{token-manager.ts → utils/token-manager.ts} +1 -1
- package/src/kit/components/login/Login.tsx +36 -21
- package/src/kit/layouts/admin/components/AdminLayout.tsx +24 -17
- package/dist/kit/builder/auth/AuthProvider.d.ts.map +0 -1
- package/dist/kit/builder/auth/adapter.d.ts.map +0 -1
- package/dist/kit/builder/auth/client-adapters.d.ts +0 -149
- package/dist/kit/builder/auth/client-adapters.d.ts.map +0 -1
- package/dist/kit/builder/auth/components.d.ts +0 -119
- package/dist/kit/builder/auth/components.d.ts.map +0 -1
- package/dist/kit/builder/auth/hooks.d.ts +0 -158
- package/dist/kit/builder/auth/hooks.d.ts.map +0 -1
- package/dist/kit/builder/auth/permission-checker.d.ts.map +0 -1
- package/dist/kit/builder/auth/storage.d.ts +0 -17
- package/dist/kit/builder/auth/storage.d.ts.map +0 -1
- package/dist/kit/builder/auth/token-manager.d.ts.map +0 -1
- package/dist/kit/builder/auth/types.d.ts +0 -183
- package/dist/kit/builder/auth/types.d.ts.map +0 -1
- package/src/kit/builder/auth/client-adapters.ts +0 -398
- package/src/kit/builder/auth/components.tsx +0 -221
- package/src/kit/builder/auth/hooks.ts +0 -237
- package/src/kit/builder/auth/storage.ts +0 -366
- package/src/kit/builder/auth/types.ts +0 -393
|
@@ -1,393 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
// ============================================================================
|
|
4
|
-
// Core Status & Session Types
|
|
5
|
-
// ============================================================================
|
|
6
|
-
|
|
7
|
-
export type AuthStatus =
|
|
8
|
-
| 'idle'
|
|
9
|
-
| 'loading'
|
|
10
|
-
| 'authenticated'
|
|
11
|
-
| 'unauthenticated'
|
|
12
|
-
| 'error';
|
|
13
|
-
|
|
14
|
-
export type TokenType = 'bearer' | 'jwt' | 'custom';
|
|
15
|
-
|
|
16
|
-
export type RefreshStrategy = 'auto' | 'manual' | 'sliding';
|
|
17
|
-
|
|
18
|
-
export type AuthSession<
|
|
19
|
-
TUser = unknown,
|
|
20
|
-
TRole = string,
|
|
21
|
-
TPermission = string,
|
|
22
|
-
> = {
|
|
23
|
-
user?: TUser | null;
|
|
24
|
-
accessToken?: string | null;
|
|
25
|
-
refreshToken?: string | null;
|
|
26
|
-
tokenType?: TokenType;
|
|
27
|
-
roles?: TRole[] | null;
|
|
28
|
-
permissions?: TPermission[] | null;
|
|
29
|
-
expiresAt?: number | null;
|
|
30
|
-
refreshExpiresAt?: number | null;
|
|
31
|
-
issuedAt?: number | null;
|
|
32
|
-
meta?: Record<string, unknown> | null;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// ============================================================================
|
|
36
|
-
// Permission System Types
|
|
37
|
-
// ============================================================================
|
|
38
|
-
|
|
39
|
-
export type PermissionOperator = 'AND' | 'OR';
|
|
40
|
-
|
|
41
|
-
export type PermissionPolicy<TPermission extends string = string> = {
|
|
42
|
-
operator?: PermissionOperator;
|
|
43
|
-
permissions: TPermission[];
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export type PermissionRule<
|
|
47
|
-
TRole extends string = string,
|
|
48
|
-
TPermission extends string = string,
|
|
49
|
-
> = {
|
|
50
|
-
roles?: TRole | TRole[];
|
|
51
|
-
permissions?: TPermission | TPermission[] | PermissionPolicy<TPermission>;
|
|
52
|
-
requireAll?: boolean;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export type PermissionHierarchy<TPermission extends string = string> = {
|
|
56
|
-
[key in TPermission]?: TPermission[];
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export type RoleHierarchy<TRole extends string = string> = {
|
|
60
|
-
[key in TRole]?: TRole[];
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// ============================================================================
|
|
64
|
-
// State Types
|
|
65
|
-
// ============================================================================
|
|
66
|
-
|
|
67
|
-
export type AuthAdapterState<TSession, TUser, TRole, TPermission> = {
|
|
68
|
-
status: AuthStatus;
|
|
69
|
-
session: TSession | null;
|
|
70
|
-
user: TUser | null;
|
|
71
|
-
roles: TRole[];
|
|
72
|
-
permissions: TPermission[];
|
|
73
|
-
error?: unknown;
|
|
74
|
-
lastRefresh?: number;
|
|
75
|
-
tokenExpiresIn?: number;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export type AuthAdapterSubscriber<TSession, TUser, TRole, TPermission> = (
|
|
79
|
-
state: AuthAdapterState<TSession, TUser, TRole, TPermission>,
|
|
80
|
-
) => void;
|
|
81
|
-
|
|
82
|
-
// ============================================================================
|
|
83
|
-
// Storage Types
|
|
84
|
-
// ============================================================================
|
|
85
|
-
|
|
86
|
-
export type AuthStorage<TSession> = {
|
|
87
|
-
get: () => Promise<TSession | null> | TSession | null;
|
|
88
|
-
set: (value: TSession | null) => Promise<void> | void;
|
|
89
|
-
clear: () => Promise<void> | void;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
export type StorageType = 'local' | 'session' | 'cookie' | 'memory';
|
|
93
|
-
|
|
94
|
-
export type StorageOptions = {
|
|
95
|
-
key?: string;
|
|
96
|
-
encrypt?: boolean;
|
|
97
|
-
encryptionKey?: string;
|
|
98
|
-
storage?: StorageType;
|
|
99
|
-
cookieOptions?: {
|
|
100
|
-
domain?: string;
|
|
101
|
-
path?: string;
|
|
102
|
-
secure?: boolean;
|
|
103
|
-
sameSite?: 'strict' | 'lax' | 'none';
|
|
104
|
-
maxAge?: number;
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
// ============================================================================
|
|
109
|
-
// Middleware Types
|
|
110
|
-
// ============================================================================
|
|
111
|
-
|
|
112
|
-
export type AuthMiddleware<
|
|
113
|
-
TSession = unknown,
|
|
114
|
-
TUser = unknown,
|
|
115
|
-
TRole extends string = string,
|
|
116
|
-
TPermission extends string = string,
|
|
117
|
-
> = {
|
|
118
|
-
onBeforeLogin?: (credentials: unknown) => Promise<void> | void;
|
|
119
|
-
onAfterLogin?: (
|
|
120
|
-
state: AuthAdapterState<TSession, TUser, TRole, TPermission>,
|
|
121
|
-
) => Promise<void> | void;
|
|
122
|
-
onBeforeLogout?: () => Promise<void> | void;
|
|
123
|
-
onAfterLogout?: () => Promise<void> | void;
|
|
124
|
-
onRefresh?: (
|
|
125
|
-
state: AuthAdapterState<TSession, TUser, TRole, TPermission>,
|
|
126
|
-
) => Promise<void> | void;
|
|
127
|
-
onError?: (error: unknown) => Promise<void> | void;
|
|
128
|
-
onSessionExpired?: () => Promise<void> | void;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
// ============================================================================
|
|
132
|
-
// Token Management Types
|
|
133
|
-
// ============================================================================
|
|
134
|
-
|
|
135
|
-
export type TokenManager = {
|
|
136
|
-
isExpired: (expiresAt?: number | null) => boolean;
|
|
137
|
-
shouldRefresh: (expiresAt?: number | null, threshold?: number) => boolean;
|
|
138
|
-
getTimeUntilExpiry: (expiresAt?: number | null) => number;
|
|
139
|
-
scheduleRefresh?: (
|
|
140
|
-
callback: () => void,
|
|
141
|
-
expiresAt?: number | null,
|
|
142
|
-
) => () => void;
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
// ============================================================================
|
|
146
|
-
// Adapter Configuration Types
|
|
147
|
-
// ============================================================================
|
|
148
|
-
|
|
149
|
-
export type AuthAdapterConfig<
|
|
150
|
-
TUser = unknown,
|
|
151
|
-
TRole extends string = string,
|
|
152
|
-
TPermission extends string = string,
|
|
153
|
-
TSession extends AuthSession<TUser, TRole, TPermission> = AuthSession<
|
|
154
|
-
TUser,
|
|
155
|
-
TRole,
|
|
156
|
-
TPermission
|
|
157
|
-
>,
|
|
158
|
-
TCredentials = unknown,
|
|
159
|
-
> = {
|
|
160
|
-
storage?: AuthStorage<TSession>;
|
|
161
|
-
loadSession?: () => Promise<TSession | null>;
|
|
162
|
-
login?: (credentials: TCredentials) => Promise<TSession>;
|
|
163
|
-
logout?: (session: TSession | null) => Promise<void> | void;
|
|
164
|
-
refresh?: (session: TSession) => Promise<TSession>;
|
|
165
|
-
resolveUser?: (session: TSession | null) => TUser | null;
|
|
166
|
-
resolveRoles?: (session: TSession | null) => TRole[];
|
|
167
|
-
resolvePermissions?: (session: TSession | null) => TPermission[];
|
|
168
|
-
shouldRefresh?: (session: TSession) => boolean;
|
|
169
|
-
onStateChange?: (
|
|
170
|
-
state: AuthAdapterState<TSession, TUser, TRole, TPermission>,
|
|
171
|
-
) => void;
|
|
172
|
-
|
|
173
|
-
// Enhanced features
|
|
174
|
-
refreshStrategy?: RefreshStrategy;
|
|
175
|
-
refreshThreshold?: number; // seconds before expiry to trigger refresh
|
|
176
|
-
autoRefresh?: boolean;
|
|
177
|
-
permissionHierarchy?: PermissionHierarchy<TPermission>;
|
|
178
|
-
roleHierarchy?: RoleHierarchy<TRole>;
|
|
179
|
-
middleware?: AuthMiddleware<TSession, TUser, TRole, TPermission>[];
|
|
180
|
-
tokenManager?: TokenManager;
|
|
181
|
-
retryConfig?: {
|
|
182
|
-
maxRetries?: number;
|
|
183
|
-
retryDelay?: number;
|
|
184
|
-
retryOn?: (error: unknown) => boolean;
|
|
185
|
-
};
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
// ============================================================================
|
|
189
|
-
// Adapter API Types
|
|
190
|
-
// ============================================================================
|
|
191
|
-
|
|
192
|
-
export type AuthAdapter<
|
|
193
|
-
TUser = unknown,
|
|
194
|
-
TRole extends string = string,
|
|
195
|
-
TPermission extends string = string,
|
|
196
|
-
TSession extends AuthSession<TUser, TRole, TPermission> = AuthSession<
|
|
197
|
-
TUser,
|
|
198
|
-
TRole,
|
|
199
|
-
TPermission
|
|
200
|
-
>,
|
|
201
|
-
TCredentials = unknown,
|
|
202
|
-
> = {
|
|
203
|
-
getState: () => AuthAdapterState<TSession, TUser, TRole, TPermission>;
|
|
204
|
-
subscribe: (
|
|
205
|
-
listener: AuthAdapterSubscriber<TSession, TUser, TRole, TPermission>,
|
|
206
|
-
) => () => void;
|
|
207
|
-
sync: () => Promise<AuthAdapterState<TSession, TUser, TRole, TPermission>>;
|
|
208
|
-
login?: (
|
|
209
|
-
credentials: TCredentials,
|
|
210
|
-
) => Promise<AuthAdapterState<TSession, TUser, TRole, TPermission>>;
|
|
211
|
-
logout: () => Promise<void>;
|
|
212
|
-
refresh: () => Promise<AuthAdapterState<TSession, TUser, TRole, TPermission>>;
|
|
213
|
-
setSession: (
|
|
214
|
-
session: TSession | null,
|
|
215
|
-
) => Promise<AuthAdapterState<TSession, TUser, TRole, TPermission>>;
|
|
216
|
-
hasRole: (
|
|
217
|
-
target: TRole | TRole[],
|
|
218
|
-
options?: { requireAll?: boolean },
|
|
219
|
-
) => boolean;
|
|
220
|
-
hasPermission: (
|
|
221
|
-
target: TPermission | TPermission[] | PermissionPolicy<TPermission>,
|
|
222
|
-
options?: { requireAll?: boolean },
|
|
223
|
-
) => boolean;
|
|
224
|
-
can: (rule: PermissionRule<TRole, TPermission>) => boolean;
|
|
225
|
-
|
|
226
|
-
// Token management
|
|
227
|
-
getToken: () => string | null;
|
|
228
|
-
isTokenExpired: () => boolean;
|
|
229
|
-
getTimeUntilExpiry: () => number;
|
|
230
|
-
scheduleAutoRefresh?: () => () => void;
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
// ============================================================================
|
|
234
|
-
// Context Types
|
|
235
|
-
// ============================================================================
|
|
236
|
-
|
|
237
|
-
export type AuthContextValue<
|
|
238
|
-
TUser = unknown,
|
|
239
|
-
TRole extends string = string,
|
|
240
|
-
TPermission extends string = string,
|
|
241
|
-
TSession extends AuthSession<TUser, TRole, TPermission> = AuthSession<
|
|
242
|
-
TUser,
|
|
243
|
-
TRole,
|
|
244
|
-
TPermission
|
|
245
|
-
>,
|
|
246
|
-
TCredentials = unknown,
|
|
247
|
-
> = {
|
|
248
|
-
state: AuthAdapterState<TSession, TUser, TRole, TPermission>;
|
|
249
|
-
status: AuthStatus;
|
|
250
|
-
session: TSession | null;
|
|
251
|
-
user: TUser | null;
|
|
252
|
-
roles: TRole[];
|
|
253
|
-
permissions: TPermission[];
|
|
254
|
-
error?: unknown;
|
|
255
|
-
|
|
256
|
-
// Actions
|
|
257
|
-
login?: (
|
|
258
|
-
credentials: TCredentials,
|
|
259
|
-
) => Promise<AuthAdapterState<TSession, TUser, TRole, TPermission>>;
|
|
260
|
-
logout: () => Promise<void>;
|
|
261
|
-
refresh: () => Promise<AuthAdapterState<TSession, TUser, TRole, TPermission>>;
|
|
262
|
-
setSession: (
|
|
263
|
-
session: TSession | null,
|
|
264
|
-
) => Promise<AuthAdapterState<TSession, TUser, TRole, TPermission>>;
|
|
265
|
-
|
|
266
|
-
// Permission checks
|
|
267
|
-
hasRole: (
|
|
268
|
-
target: TRole | TRole[],
|
|
269
|
-
options?: { requireAll?: boolean },
|
|
270
|
-
) => boolean;
|
|
271
|
-
hasPermission: (
|
|
272
|
-
target: TPermission | TPermission[] | PermissionPolicy<TPermission>,
|
|
273
|
-
options?: { requireAll?: boolean },
|
|
274
|
-
) => boolean;
|
|
275
|
-
can: (rule: PermissionRule<TRole, TPermission>) => boolean;
|
|
276
|
-
|
|
277
|
-
// Token management
|
|
278
|
-
getToken: () => string | null;
|
|
279
|
-
isTokenExpired: () => boolean;
|
|
280
|
-
getTimeUntilExpiry: () => number;
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
// ============================================================================
|
|
284
|
-
// Component Props Types
|
|
285
|
-
// ============================================================================
|
|
286
|
-
|
|
287
|
-
export type RequireAuthProps<
|
|
288
|
-
TRole extends string = string,
|
|
289
|
-
TPermission extends string = string,
|
|
290
|
-
> = {
|
|
291
|
-
children: ReactNode;
|
|
292
|
-
fallback?: ReactNode;
|
|
293
|
-
loadingFallback?: ReactNode;
|
|
294
|
-
roles?: TRole | TRole[];
|
|
295
|
-
permissions?: TPermission | TPermission[] | PermissionPolicy<TPermission>;
|
|
296
|
-
requireAll?: boolean;
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
export type CanProps<
|
|
300
|
-
TRole extends string = string,
|
|
301
|
-
TPermission extends string = string,
|
|
302
|
-
> = {
|
|
303
|
-
children: ReactNode;
|
|
304
|
-
fallback?: ReactNode;
|
|
305
|
-
roles?: TRole | TRole[];
|
|
306
|
-
permissions?: TPermission | TPermission[] | PermissionPolicy<TPermission>;
|
|
307
|
-
requireAll?: boolean;
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
export type WithPermissionOptions<
|
|
311
|
-
TRole extends string = string,
|
|
312
|
-
TPermission extends string = string,
|
|
313
|
-
> = {
|
|
314
|
-
roles?: TRole | TRole[];
|
|
315
|
-
permissions?: TPermission | TPermission[] | PermissionPolicy<TPermission>;
|
|
316
|
-
requireAll?: boolean;
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
// ============================================================================
|
|
320
|
-
// Client Adapter Types (GraphQL/REST)
|
|
321
|
-
// ============================================================================
|
|
322
|
-
|
|
323
|
-
export type GraphQLAuthClient<TSession = unknown, TCredentials = unknown> = {
|
|
324
|
-
login: (credentials: TCredentials) => Promise<TSession>;
|
|
325
|
-
logout?: () => Promise<void>;
|
|
326
|
-
refresh?: (refreshToken: string) => Promise<TSession>;
|
|
327
|
-
getCurrentUser?: () => Promise<TSession>;
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
export type RESTAuthClient<TSession = unknown, TCredentials = unknown> = {
|
|
331
|
-
login: (credentials: TCredentials) => Promise<TSession>;
|
|
332
|
-
logout?: () => Promise<void>;
|
|
333
|
-
refresh?: (refreshToken: string) => Promise<TSession>;
|
|
334
|
-
getCurrentUser?: () => Promise<TSession>;
|
|
335
|
-
};
|
|
336
|
-
|
|
337
|
-
export type ClientAdapter<TSession = unknown, TCredentials = unknown> =
|
|
338
|
-
| GraphQLAuthClient<TSession, TCredentials>
|
|
339
|
-
| RESTAuthClient<TSession, TCredentials>;
|
|
340
|
-
|
|
341
|
-
// ============================================================================
|
|
342
|
-
// Utility Types
|
|
343
|
-
// ============================================================================
|
|
344
|
-
|
|
345
|
-
export type InferSession<T> = T extends AuthAdapter<
|
|
346
|
-
infer _User,
|
|
347
|
-
infer _Role extends string,
|
|
348
|
-
infer _Permission extends string,
|
|
349
|
-
infer TSession,
|
|
350
|
-
infer _Credentials
|
|
351
|
-
>
|
|
352
|
-
? TSession
|
|
353
|
-
: never;
|
|
354
|
-
|
|
355
|
-
export type InferUser<T> = T extends AuthAdapter<
|
|
356
|
-
infer TUser,
|
|
357
|
-
infer _Role extends string,
|
|
358
|
-
infer _Permission extends string,
|
|
359
|
-
infer _Session,
|
|
360
|
-
infer _Credentials
|
|
361
|
-
>
|
|
362
|
-
? TUser
|
|
363
|
-
: never;
|
|
364
|
-
|
|
365
|
-
export type InferRole<T> = T extends AuthAdapter<
|
|
366
|
-
infer _User,
|
|
367
|
-
infer TRole extends string,
|
|
368
|
-
infer _Permission extends string,
|
|
369
|
-
infer _Session,
|
|
370
|
-
infer _Credentials
|
|
371
|
-
>
|
|
372
|
-
? TRole
|
|
373
|
-
: never;
|
|
374
|
-
|
|
375
|
-
export type InferPermission<T> = T extends AuthAdapter<
|
|
376
|
-
infer _User,
|
|
377
|
-
infer _Role extends string,
|
|
378
|
-
infer TPermission extends string,
|
|
379
|
-
infer _Session,
|
|
380
|
-
infer _Credentials
|
|
381
|
-
>
|
|
382
|
-
? TPermission
|
|
383
|
-
: never;
|
|
384
|
-
|
|
385
|
-
export type InferCredentials<T> = T extends AuthAdapter<
|
|
386
|
-
infer _User,
|
|
387
|
-
infer _Role extends string,
|
|
388
|
-
infer _Permission extends string,
|
|
389
|
-
infer _Session,
|
|
390
|
-
infer TCredentials
|
|
391
|
-
>
|
|
392
|
-
? TCredentials
|
|
393
|
-
: never;
|