@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
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export class SimpleEncryption {
|
|
2
|
+
private key: string
|
|
3
|
+
|
|
4
|
+
constructor(key: string) {
|
|
5
|
+
this.key = key
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async encrypt(text: string): Promise<string> {
|
|
9
|
+
if (!crypto?.subtle) {
|
|
10
|
+
console.warn('[auth2][storage] Crypto API not available, storing unencrypted')
|
|
11
|
+
return text
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const encoder = new TextEncoder()
|
|
16
|
+
const data = encoder.encode(text)
|
|
17
|
+
const keyData = encoder.encode(this.key.padEnd(32, '0').slice(0, 32))
|
|
18
|
+
|
|
19
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
20
|
+
'raw',
|
|
21
|
+
keyData,
|
|
22
|
+
{ name: 'AES-GCM', length: 256 },
|
|
23
|
+
false,
|
|
24
|
+
['encrypt'],
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
const iv = crypto.getRandomValues(new Uint8Array(12))
|
|
28
|
+
const encrypted = await crypto.subtle.encrypt(
|
|
29
|
+
{ name: 'AES-GCM', iv },
|
|
30
|
+
cryptoKey,
|
|
31
|
+
data,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
const result = new Uint8Array(iv.length + encrypted.byteLength)
|
|
35
|
+
result.set(iv, 0)
|
|
36
|
+
result.set(new Uint8Array(encrypted), iv.length)
|
|
37
|
+
|
|
38
|
+
return btoa(String.fromCharCode(...result))
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error('[auth2][storage] Encryption failed:', error)
|
|
41
|
+
return text
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async decrypt(encrypted: string): Promise<string> {
|
|
46
|
+
if (!crypto?.subtle) {
|
|
47
|
+
console.warn('[auth2][storage] Crypto API not available, reading unencrypted')
|
|
48
|
+
return encrypted
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const encoder = new TextEncoder()
|
|
53
|
+
const decoder = new TextDecoder()
|
|
54
|
+
const keyData = encoder.encode(this.key.padEnd(32, '0').slice(0, 32))
|
|
55
|
+
|
|
56
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
57
|
+
'raw',
|
|
58
|
+
keyData,
|
|
59
|
+
{ name: 'AES-GCM', length: 256 },
|
|
60
|
+
false,
|
|
61
|
+
['decrypt'],
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
const data = Uint8Array.from(atob(encrypted), (c) => c.charCodeAt(0))
|
|
65
|
+
const iv = data.slice(0, 12)
|
|
66
|
+
const encryptedData = data.slice(12)
|
|
67
|
+
|
|
68
|
+
const decrypted = await crypto.subtle.decrypt(
|
|
69
|
+
{ name: 'AES-GCM', iv },
|
|
70
|
+
cryptoKey,
|
|
71
|
+
encryptedData,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
return decoder.decode(decrypted)
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.error('[auth2][storage] Decryption failed:', error)
|
|
77
|
+
return encrypted
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { AuthStorage, StorageOptions } from '../../types'
|
|
2
|
+
import { isBrowser } from './env'
|
|
3
|
+
import { createMemoryStorage } from './memory'
|
|
4
|
+
import { createCookieStorage } from './cookie'
|
|
5
|
+
import { createBrowserStorage } from './browser'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Creates appropriate storage based on options
|
|
9
|
+
*/
|
|
10
|
+
export function createStorage<T>(options: StorageOptions = {}): AuthStorage<T> {
|
|
11
|
+
const storageType = options.storage ?? 'local'
|
|
12
|
+
const key = options.key ?? 'auth2_session'
|
|
13
|
+
|
|
14
|
+
switch (storageType) {
|
|
15
|
+
case 'cookie':
|
|
16
|
+
return createCookieStorage<T>(options)
|
|
17
|
+
|
|
18
|
+
case 'session':
|
|
19
|
+
return createBrowserStorage<T>({
|
|
20
|
+
key,
|
|
21
|
+
storage: isBrowser ? window.sessionStorage : undefined,
|
|
22
|
+
encrypt: options.encrypt,
|
|
23
|
+
encryptionKey: options.encryptionKey,
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
case 'local':
|
|
27
|
+
return createBrowserStorage<T>({
|
|
28
|
+
key,
|
|
29
|
+
storage: isBrowser ? window.localStorage : undefined,
|
|
30
|
+
encrypt: options.encrypt,
|
|
31
|
+
encryptionKey: options.encryptionKey,
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
default:
|
|
35
|
+
return createMemoryStorage<T>()
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AuthStorage } from '../../types'
|
|
2
|
+
|
|
3
|
+
export const createMemoryStorage = <T>(): AuthStorage<T> => {
|
|
4
|
+
let value: T | null = null
|
|
5
|
+
|
|
6
|
+
return {
|
|
7
|
+
get: () => value,
|
|
8
|
+
set: (next) => {
|
|
9
|
+
value = next
|
|
10
|
+
},
|
|
11
|
+
clear: () => {
|
|
12
|
+
value = null
|
|
13
|
+
},
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -16,6 +16,8 @@ export type LoginProps = {
|
|
|
16
16
|
// Right-side image URL and alt
|
|
17
17
|
rightImageSrc?: string;
|
|
18
18
|
rightImageAlt?: string;
|
|
19
|
+
// Explicit toggle to show/hide the right-side visual column
|
|
20
|
+
showRightImage?: boolean;
|
|
19
21
|
// Optional className for the outer container
|
|
20
22
|
className?: string;
|
|
21
23
|
// Optional continue-with slot (renders below the submit action area)
|
|
@@ -39,24 +41,33 @@ export function Login({
|
|
|
39
41
|
subtitle,
|
|
40
42
|
signupLabel = "Don't have an account?",
|
|
41
43
|
signupLinkLabel = 'Sign up',
|
|
42
|
-
signupHref
|
|
44
|
+
signupHref,
|
|
43
45
|
forgotPasswordLabel = 'Forgot your password?',
|
|
44
46
|
forgotPasswordLinkLabel = 'Reset Here',
|
|
45
47
|
forgotPasswordHref,
|
|
46
48
|
rightImageSrc,
|
|
47
49
|
rightImageAlt = 'Login image',
|
|
50
|
+
showRightImage = true,
|
|
48
51
|
className,
|
|
49
52
|
continueWith,
|
|
50
53
|
children,
|
|
51
54
|
}: LoginProps) {
|
|
55
|
+
const shouldRenderRightColumn = showRightImage;
|
|
56
|
+
|
|
52
57
|
return (
|
|
53
58
|
<div
|
|
54
|
-
className={[
|
|
59
|
+
className={[
|
|
60
|
+
'mx-auto grid min-h-dvh w-full max-w-[1920px] grid-cols-1 lg:min-h-[768px]',
|
|
61
|
+
shouldRenderRightColumn
|
|
62
|
+
? 'lg:grid-cols-[minmax(0,_1fr)_minmax(384px,_1fr)]'
|
|
63
|
+
: null,
|
|
64
|
+
className,
|
|
65
|
+
]
|
|
55
66
|
.filter(Boolean)
|
|
56
67
|
.join(' ')}
|
|
57
68
|
>
|
|
58
69
|
{/* Left column: form section */}
|
|
59
|
-
<div className="flex items-center justify-center p-6
|
|
70
|
+
<div className="flex min-h-0 items-center justify-center p-6 sm:p-8 lg:p-12">
|
|
60
71
|
<div className="w-full max-w-md">
|
|
61
72
|
{/* Title */}
|
|
62
73
|
<div className="mb-6 text-center">
|
|
@@ -99,28 +110,32 @@ export function Login({
|
|
|
99
110
|
</div>
|
|
100
111
|
|
|
101
112
|
{/* Signup footer */}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
{
|
|
106
|
-
|
|
107
|
-
|
|
113
|
+
{signupHref ? (
|
|
114
|
+
<div className="mt-6 text-center text-sm">
|
|
115
|
+
{signupLabel}{' '}
|
|
116
|
+
<a href={signupHref} className="underline underline-offset-4">
|
|
117
|
+
{signupLinkLabel}
|
|
118
|
+
</a>
|
|
119
|
+
</div>
|
|
120
|
+
) : null}
|
|
108
121
|
</div>
|
|
109
122
|
</div>
|
|
110
123
|
|
|
111
124
|
{/* Right column: image */}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
125
|
+
{shouldRenderRightColumn ? (
|
|
126
|
+
<div className="hidden max-h-[1280px] lg:block">
|
|
127
|
+
{rightImageSrc ? (
|
|
128
|
+
<img
|
|
129
|
+
src={rightImageSrc}
|
|
130
|
+
alt={rightImageAlt}
|
|
131
|
+
className="h-full w-full object-cover"
|
|
132
|
+
loading="lazy"
|
|
133
|
+
/>
|
|
134
|
+
) : (
|
|
135
|
+
<div className="h-full w-full bg-muted" />
|
|
136
|
+
)}
|
|
137
|
+
</div>
|
|
138
|
+
) : null}
|
|
124
139
|
</div>
|
|
125
140
|
);
|
|
126
141
|
}
|
|
@@ -41,6 +41,7 @@ type AdminLayoutProps = {
|
|
|
41
41
|
// Header bar customization
|
|
42
42
|
headerAfterTrigger?: React.ReactNode; // renders right after the collapsible icon trigger
|
|
43
43
|
headerAfterTheme?: React.ReactNode; // renders right after the ThemeToggle on the right
|
|
44
|
+
onLogout?: () => void | Promise<void>;
|
|
44
45
|
};
|
|
45
46
|
|
|
46
47
|
function AdminLayoutContent({
|
|
@@ -52,6 +53,7 @@ function AdminLayoutContent({
|
|
|
52
53
|
sidebarHeaderIcon,
|
|
53
54
|
headerAfterTrigger,
|
|
54
55
|
headerAfterTheme,
|
|
56
|
+
onLogout,
|
|
55
57
|
}: AdminLayoutProps) {
|
|
56
58
|
const { groups: sidebarGroups } = useAdminSidebarMenu();
|
|
57
59
|
const location = useLocation();
|
|
@@ -212,23 +214,26 @@ function AdminLayoutContent({
|
|
|
212
214
|
</Fragment>
|
|
213
215
|
))}
|
|
214
216
|
</SidebarContent>
|
|
215
|
-
|
|
216
|
-
<
|
|
217
|
-
<
|
|
218
|
-
<
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
<
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
217
|
+
{onLogout && (
|
|
218
|
+
<SidebarFooter className="bg-sidebar border-t border-sidebar-border px-2 py-3">
|
|
219
|
+
<SidebarMenu>
|
|
220
|
+
<SidebarMenuItem className="group-data-[collapsible=icon]:flex group-data-[collapsible=icon]:w-full group-data-[collapsible=icon]:justify-center">
|
|
221
|
+
<SidebarMenuButton
|
|
222
|
+
tooltip="Logout"
|
|
223
|
+
className="cursor-pointer group relative overflow-hidden rounded-lg mx-1 transition-all duration-200 hover:bg-sidebar-accent/70 hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:flex group-data-[collapsible=icon]:w-full group-data-[collapsible=icon]:items-center group-data-[collapsible=icon]:!justify-center group-data-[collapsible=icon]:!px-0 group-data-[collapsible=icon]:!gap-0"
|
|
224
|
+
onClick={() => { void onLogout(); }}
|
|
225
|
+
>
|
|
226
|
+
<div className="flex items-center gap-3 px-3 py-2.5 group-data-[collapsible=icon]:w-full group-data-[collapsible=icon]:items-center group-data-[collapsible=icon]:!justify-center group-data-[collapsible=icon]:!gap-0 group-data-[collapsible=icon]:!px-0">
|
|
227
|
+
<LogOut className="h-4 w-4 text-sidebar-foreground group-hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:mx-auto group-data-[collapsible=icon]:mr-0" />
|
|
228
|
+
<span className="font-medium text-sidebar-foreground group-hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:hidden">
|
|
229
|
+
Logout
|
|
230
|
+
</span>
|
|
231
|
+
</div>
|
|
232
|
+
</SidebarMenuButton>
|
|
233
|
+
</SidebarMenuItem>
|
|
234
|
+
</SidebarMenu>
|
|
235
|
+
</SidebarFooter>
|
|
236
|
+
)}
|
|
232
237
|
</Sidebar>
|
|
233
238
|
<SidebarInset>
|
|
234
239
|
<header className="flex h-16 shrink-0 items-center justify-between gap-4 border-b border-border/40 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 px-6">
|
|
@@ -258,6 +263,7 @@ export default function AdminLayout({
|
|
|
258
263
|
sidebarHeaderIcon,
|
|
259
264
|
headerAfterTrigger,
|
|
260
265
|
headerAfterTheme,
|
|
266
|
+
onLogout,
|
|
261
267
|
}: AdminLayoutProps) {
|
|
262
268
|
return (
|
|
263
269
|
<AdminMenuProvider>
|
|
@@ -270,6 +276,7 @@ export default function AdminLayout({
|
|
|
270
276
|
sidebarHeaderIcon={sidebarHeaderIcon}
|
|
271
277
|
headerAfterTrigger={headerAfterTrigger}
|
|
272
278
|
headerAfterTheme={headerAfterTheme}
|
|
279
|
+
onLogout={onLogout}
|
|
273
280
|
>
|
|
274
281
|
{children}
|
|
275
282
|
</AdminLayoutContent>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AuthProvider.d.ts","sourceRoot":"","sources":["../../../../src/kit/builder/auth/AuthProvider.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE1E,KAAK,mBAAmB,GAAG,gBAAgB,CACzC,OAAO,EACP,MAAM,EACN,MAAM,EACN,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EACpC,OAAO,CACR,CAAC;AAIF,KAAK,iBAAiB,CACpB,KAAK,GAAG,OAAO,EACf,KAAK,SAAS,MAAM,GAAG,MAAM,EAC7B,WAAW,SAAS,MAAM,GAAG,MAAM,EACnC,QAAQ,SAAS,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,CAAC,GAAG,WAAW,CACnE,KAAK,EACL,KAAK,EACL,W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AK,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,CAAC,GAC3E,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,CAAC,CAoYhE"}
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { AuthAdapterConfig, AuthSession, GraphQLAuthClient, RESTAuthClient } from './types';
|
|
2
|
-
export type GraphQLClientAdapterOptions<TUser = unknown, TRole extends string = string, TPermission extends string = string, TSession extends AuthSession<TUser, TRole, TPermission> = AuthSession<TUser, TRole, TPermission>, TCredentials = unknown> = {
|
|
3
|
-
client: GraphQLAuthClient<TSession, TCredentials>;
|
|
4
|
-
resolveUser?: (session: TSession | null) => TUser | null;
|
|
5
|
-
resolveRoles?: (session: TSession | null) => TRole[];
|
|
6
|
-
resolvePermissions?: (session: TSession | null) => TPermission[];
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Creates an auth adapter config for GraphQL clients
|
|
10
|
-
* Works with Apollo Client, urql, graphql-request, etc.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```tsx
|
|
14
|
-
* import { ApolloClient } from '@apollo/client';
|
|
15
|
-
* import { createGraphQLAuthAdapter } from '@k3mart/react-kit/auth2';
|
|
16
|
-
*
|
|
17
|
-
* const apolloClient = new ApolloClient({ ... });
|
|
18
|
-
*
|
|
19
|
-
* const authConfig = createGraphQLAuthAdapter({
|
|
20
|
-
* client: {
|
|
21
|
-
* login: async (credentials) => {
|
|
22
|
-
* const result = await apolloClient.mutate({
|
|
23
|
-
* mutation: LOGIN_MUTATION,
|
|
24
|
-
* variables: credentials,
|
|
25
|
-
* });
|
|
26
|
-
* return result.data.login;
|
|
27
|
-
* },
|
|
28
|
-
* logout: async () => {
|
|
29
|
-
* await apolloClient.mutate({ mutation: LOGOUT_MUTATION });
|
|
30
|
-
* },
|
|
31
|
-
* refresh: async (refreshToken) => {
|
|
32
|
-
* const result = await apolloClient.mutate({
|
|
33
|
-
* mutation: REFRESH_MUTATION,
|
|
34
|
-
* variables: { refreshToken },
|
|
35
|
-
* });
|
|
36
|
-
* return result.data.refresh;
|
|
37
|
-
* },
|
|
38
|
-
* getCurrentUser: async () => {
|
|
39
|
-
* const result = await apolloClient.query({
|
|
40
|
-
* query: GET_CURRENT_USER_QUERY,
|
|
41
|
-
* });
|
|
42
|
-
* return result.data.currentUser;
|
|
43
|
-
* },
|
|
44
|
-
* },
|
|
45
|
-
* });
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
export declare function createGraphQLAuthAdapter<TUser = unknown, TRole extends string = string, TPermission extends string = string, TSession extends AuthSession<TUser, TRole, TPermission> = AuthSession<TUser, TRole, TPermission>, TCredentials = unknown>(options: GraphQLClientAdapterOptions<TUser, TRole, TPermission, TSession, TCredentials>): Partial<AuthAdapterConfig<TUser, TRole, TPermission, TSession, TCredentials>>;
|
|
49
|
-
export type RESTClientAdapterOptions<TUser = unknown, TRole extends string = string, TPermission extends string = string, TSession extends AuthSession<TUser, TRole, TPermission> = AuthSession<TUser, TRole, TPermission>, TCredentials = unknown> = {
|
|
50
|
-
client: RESTAuthClient<TSession, TCredentials>;
|
|
51
|
-
resolveUser?: (session: TSession | null) => TUser | null;
|
|
52
|
-
resolveRoles?: (session: TSession | null) => TRole[];
|
|
53
|
-
resolvePermissions?: (session: TSession | null) => TPermission[];
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
* Creates an auth adapter config for REST API clients
|
|
57
|
-
* Works with fetch, axios, ky, etc.
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```tsx
|
|
61
|
-
* import axios from 'axios';
|
|
62
|
-
* import { createRESTAuthAdapter } from '@k3mart/react-kit/auth2';
|
|
63
|
-
*
|
|
64
|
-
* const api = axios.create({ baseURL: 'https://api.example.com' });
|
|
65
|
-
*
|
|
66
|
-
* const authConfig = createRESTAuthAdapter({
|
|
67
|
-
* client: {
|
|
68
|
-
* login: async (credentials) => {
|
|
69
|
-
* const response = await api.post('/auth/login', credentials);
|
|
70
|
-
* return response.data;
|
|
71
|
-
* },
|
|
72
|
-
* logout: async () => {
|
|
73
|
-
* await api.post('/auth/logout');
|
|
74
|
-
* },
|
|
75
|
-
* refresh: async (refreshToken) => {
|
|
76
|
-
* const response = await api.post('/auth/refresh', { refreshToken });
|
|
77
|
-
* return response.data;
|
|
78
|
-
* },
|
|
79
|
-
* getCurrentUser: async () => {
|
|
80
|
-
* const response = await api.get('/auth/me');
|
|
81
|
-
* return response.data;
|
|
82
|
-
* },
|
|
83
|
-
* },
|
|
84
|
-
* });
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
export declare function createRESTAuthAdapter<TUser = unknown, TRole extends string = string, TPermission extends string = string, TSession extends AuthSession<TUser, TRole, TPermission> = AuthSession<TUser, TRole, TPermission>, TCredentials = unknown>(options: RESTClientAdapterOptions<TUser, TRole, TPermission, TSession, TCredentials>): Partial<AuthAdapterConfig<TUser, TRole, TPermission, TSession, TCredentials>>;
|
|
88
|
-
/**
|
|
89
|
-
* Helper to create an axios interceptor that automatically adds auth token
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* ```tsx
|
|
93
|
-
* import axios from 'axios';
|
|
94
|
-
* import { createAxiosAuthInterceptor } from '@k3mart/react-kit/auth2';
|
|
95
|
-
*
|
|
96
|
-
* const api = axios.create({ baseURL: 'https://api.example.com' });
|
|
97
|
-
*
|
|
98
|
-
* createAxiosAuthInterceptor(api, authAdapter);
|
|
99
|
-
* ```
|
|
100
|
-
*/
|
|
101
|
-
export declare function createAxiosAuthInterceptor(axiosInstance: any, getToken: () => string | null, options?: {
|
|
102
|
-
tokenType?: string;
|
|
103
|
-
onTokenExpired?: () => void;
|
|
104
|
-
refreshToken?: () => Promise<void>;
|
|
105
|
-
}): void;
|
|
106
|
-
/**
|
|
107
|
-
* Helper to create a fetch wrapper with auth token injection
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* ```tsx
|
|
111
|
-
* import { createAuthFetch } from '@k3mart/react-kit/auth2';
|
|
112
|
-
*
|
|
113
|
-
* const authenticatedFetch = createAuthFetch(
|
|
114
|
-
* () => authAdapter.getToken(),
|
|
115
|
-
* {
|
|
116
|
-
* onTokenExpired: () => authAdapter.logout(),
|
|
117
|
-
* refreshToken: () => authAdapter.refresh(),
|
|
118
|
-
* }
|
|
119
|
-
* );
|
|
120
|
-
*
|
|
121
|
-
* // Use it like regular fetch
|
|
122
|
-
* const response = await authenticatedFetch('/api/users');
|
|
123
|
-
* ```
|
|
124
|
-
*/
|
|
125
|
-
export declare function createAuthFetch(getToken: () => string | null, options?: {
|
|
126
|
-
tokenType?: string;
|
|
127
|
-
onTokenExpired?: () => void;
|
|
128
|
-
refreshToken?: () => Promise<void>;
|
|
129
|
-
}): typeof fetch;
|
|
130
|
-
/**
|
|
131
|
-
* Helper to create Apollo Link with auth token injection
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* ```tsx
|
|
135
|
-
* import { ApolloClient, InMemoryCache, from } from '@apollo/client';
|
|
136
|
-
* import { createApolloAuthLink } from '@k3mart/react-kit/auth2';
|
|
137
|
-
*
|
|
138
|
-
* const authLink = createApolloAuthLink(() => authAdapter.getToken());
|
|
139
|
-
*
|
|
140
|
-
* const client = new ApolloClient({
|
|
141
|
-
* link: from([authLink, httpLink]),
|
|
142
|
-
* cache: new InMemoryCache(),
|
|
143
|
-
* });
|
|
144
|
-
* ```
|
|
145
|
-
*/
|
|
146
|
-
export declare function createApolloAuthLink(getToken: () => string | null, options?: {
|
|
147
|
-
tokenType?: string;
|
|
148
|
-
}): (ApolloLink: any) => any;
|
|
149
|
-
//# sourceMappingURL=client-adapters.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client-adapters.d.ts","sourceRoot":"","sources":["../../../../src/kit/builder/auth/client-adapters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB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C;IACnB,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC,QAoDF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,MAAM,GAAG,IAAI,EAC7B,OAAO,CAAC,EAAE;IACR,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC,GACA,OAAO,KAAK,CAwCd;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,MAAM,GAAG,IAAI,EAC7B,OAAO,CAAC,EAAE;IACR,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,IAOO,YAAY,GAAG,SAkBxB"}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { ComponentType } from 'react';
|
|
2
|
-
import { CanProps, RequireAuthProps, WithPermissionOptions } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Component that requires authentication
|
|
5
|
-
* Optionally checks for specific roles and permissions
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```tsx
|
|
9
|
-
* // Basic authentication check
|
|
10
|
-
* <RequireAuth fallback={<Login />}>
|
|
11
|
-
* <Dashboard />
|
|
12
|
-
* </RequireAuth>
|
|
13
|
-
*
|
|
14
|
-
* // With role check
|
|
15
|
-
* <RequireAuth
|
|
16
|
-
* roles="admin"
|
|
17
|
-
* fallback={<Forbidden />}
|
|
18
|
-
* loadingFallback={<Spinner />}
|
|
19
|
-
* >
|
|
20
|
-
* <AdminPanel />
|
|
21
|
-
* </RequireAuth>
|
|
22
|
-
*
|
|
23
|
-
* // With permission check
|
|
24
|
-
* <RequireAuth
|
|
25
|
-
* permissions={['post:edit', 'post:delete']}
|
|
26
|
-
* fallback={<Forbidden />}
|
|
27
|
-
* >
|
|
28
|
-
* <PostEditor />
|
|
29
|
-
* </RequireAuth>
|
|
30
|
-
*
|
|
31
|
-
* // Complex rule
|
|
32
|
-
* <RequireAuth
|
|
33
|
-
* roles={['admin', 'moderator']}
|
|
34
|
-
* permissions={{
|
|
35
|
-
* operator: 'OR',
|
|
36
|
-
* permissions: ['post:edit', 'post:delete']
|
|
37
|
-
* }}
|
|
38
|
-
* requireAll={false}
|
|
39
|
-
* fallback={<Forbidden />}
|
|
40
|
-
* >
|
|
41
|
-
* <ContentManager />
|
|
42
|
-
* </RequireAuth>
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
export declare function RequireAuth<TRole extends string = string, TPermission extends string = string>({ children, fallback, loadingFallback, roles, permissions, requireAll, }: RequireAuthProps<TRole, TPermission>): import('react').ReactNode;
|
|
46
|
-
/**
|
|
47
|
-
* Component for conditional rendering based on permissions
|
|
48
|
-
* More flexible than RequireAuth - doesn't check authentication status
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```tsx
|
|
52
|
-
* // Show button only if user can edit
|
|
53
|
-
* <Can permissions="post:edit" fallback={<ReadOnlyView />}>
|
|
54
|
-
* <EditButton />
|
|
55
|
-
* </Can>
|
|
56
|
-
*
|
|
57
|
-
* // Show admin panel if user is admin
|
|
58
|
-
* <Can roles="admin">
|
|
59
|
-
* <AdminPanel />
|
|
60
|
-
* </Can>
|
|
61
|
-
*
|
|
62
|
-
* // Complex permission check
|
|
63
|
-
* <Can
|
|
64
|
-
* roles={['admin', 'moderator']}
|
|
65
|
-
* permissions={{
|
|
66
|
-
* operator: 'OR',
|
|
67
|
-
* permissions: ['post:edit', 'post:delete']
|
|
68
|
-
* }}
|
|
69
|
-
* requireAll={false}
|
|
70
|
-
* >
|
|
71
|
-
* <ManageButton />
|
|
72
|
-
* </Can>
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
export declare function Can<TRole extends string = string, TPermission extends string = string>({ children, fallback, roles, permissions, requireAll, }: CanProps<TRole, TPermission>): import('react').ReactNode;
|
|
76
|
-
/**
|
|
77
|
-
* Higher-order component that wraps a component with permission checks
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```tsx
|
|
81
|
-
* const AdminButton = withPermission(Button, {
|
|
82
|
-
* roles: 'admin'
|
|
83
|
-
* });
|
|
84
|
-
*
|
|
85
|
-
* const EditButton = withPermission(Button, {
|
|
86
|
-
* permissions: 'post:edit'
|
|
87
|
-
* });
|
|
88
|
-
*
|
|
89
|
-
* // Use like regular component
|
|
90
|
-
* <AdminButton onClick={handleAdmin}>Admin Action</AdminButton>
|
|
91
|
-
* <EditButton onClick={handleEdit}>Edit Post</EditButton>
|
|
92
|
-
* ```
|
|
93
|
-
*/
|
|
94
|
-
export declare function withPermission<TRole extends string = string, TPermission extends string = string, TProps extends Record<string, unknown> = Record<string, unknown>>(Component: ComponentType<TProps>, options: WithPermissionOptions<TRole, TPermission>): ComponentType<TProps>;
|
|
95
|
-
/**
|
|
96
|
-
* Component that shows children only when authenticated
|
|
97
|
-
*/
|
|
98
|
-
export declare function ShowWhenAuthenticated({ children, }: {
|
|
99
|
-
children: React.ReactNode;
|
|
100
|
-
}): import('react').ReactNode;
|
|
101
|
-
/**
|
|
102
|
-
* Component that shows children only when NOT authenticated
|
|
103
|
-
*/
|
|
104
|
-
export declare function ShowWhenUnauthenticated({ children, }: {
|
|
105
|
-
children: React.ReactNode;
|
|
106
|
-
}): import('react').ReactNode;
|
|
107
|
-
/**
|
|
108
|
-
* Component that shows children only while loading
|
|
109
|
-
*/
|
|
110
|
-
export declare function ShowWhenLoading({ children }: {
|
|
111
|
-
children: React.ReactNode;
|
|
112
|
-
}): import('react').ReactNode;
|
|
113
|
-
/**
|
|
114
|
-
* Component that shows children only when there's an error
|
|
115
|
-
*/
|
|
116
|
-
export declare function ShowWhenError({ children }: {
|
|
117
|
-
children: React.ReactNode;
|
|
118
|
-
}): import('react').ReactNode;
|
|
119
|
-
//# sourceMappingURL=components.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../../../src/kit/builder/auth/components.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EACV,QAAQ,EACR,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,SAAS,CAAC;AAQjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,WAAW,CACzB,KAAK,SAAS,MAAM,GAAG,MAAM,EAC7B,WAAW,SAAS,MAAM,GAAG,MAAM,EACnC,EACA,QAAQ,EACR,QAAe,EACf,eAAsB,EACtB,KAAK,EACL,WAAW,EACX,UAAiB,GAClB,EAAE,gBAAgB,CAAC,KAAK,EAAE,WAAW,CAAC,6BAwBtC;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,GAAG,CACjB,KAAK,SAAS,MAAM,GAAG,MAAM,EAC7B,WAAW,SAAS,MAAM,GAAG,MAAM,EACnC,EACA,QAAQ,EACR,QAAe,EACf,KAAK,EACL,WAAW,EACX,UAAiB,GAClB,EAAE,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,6BAI9B;AAMD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,CAC5B,KAAK,SAAS,MAAM,GAAG,MAAM,EAC7B,WAAW,SAAS,MAAM,GAAG,MAAM,EACnC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAEhE,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,EAChC,OAAO,EAAE,qBAAqB,CAAC,KAAK,EAAE,WAAW,CAAC,GACjD,aAAa,CAAC,MAAM,CAAC,CAQvB;AAMD;;GAEG;AACH,wBAA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