@noxickon/onyx 3.0.0 → 4.0.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.
- package/AI-README.md +166 -74
- package/dist/contexts/AuthContext/index.d.ts +1 -4
- package/dist/contexts/AuthContext/src/AuthContext.types.d.ts +27 -21
- package/dist/contexts/AuthContext/src/createOxAuth.d.ts +5 -0
- package/dist/contexts/contexts.cjs.js +2 -11
- package/dist/contexts/contexts.es.js +162 -155
- package/dist/routes/GuestRoute/index.d.ts +2 -2
- package/dist/routes/GuestRoute/src/createOxGuestRoute.d.ts +4 -0
- package/dist/routes/ProtectedRoute/index.d.ts +2 -2
- package/dist/routes/ProtectedRoute/src/createOxProtectedRoute.d.ts +4 -0
- package/dist/routes/RoleRoute/index.d.ts +2 -2
- package/dist/routes/RoleRoute/src/RoleRoute.types.d.ts +6 -1
- package/dist/routes/RoleRoute/src/createOxRoleRoute.d.ts +8 -0
- package/dist/routes/routes.cjs.js +1 -1
- package/dist/routes/routes.es.js +46 -38
- package/package.json +1 -1
- package/dist/chunks/useAuth-BFgXzu6Q.js +0 -12
- package/dist/chunks/useAuth-DxoDe3YA.js +0 -1
- package/dist/contexts/AuthContext/src/AuthContext.d.ts +0 -2
- package/dist/contexts/AuthContext/src/AuthProvider.d.ts +0 -2
- package/dist/contexts/AuthContext/src/query.d.ts +0 -1
- package/dist/contexts/AuthContext/src/useAuth.d.ts +0 -1
- package/dist/routes/GuestRoute/src/GuestRoute.d.ts +0 -2
- package/dist/routes/ProtectedRoute/src/ProtectedRoute.d.ts +0 -2
- package/dist/routes/RoleRoute/src/RoleRoute.d.ts +0 -2
package/AI-README.md
CHANGED
|
@@ -69,8 +69,12 @@ import { useForm, useFilterQuery, useFormState } from '@noxickon/onyx/hooks';
|
|
|
69
69
|
// Layouts
|
|
70
70
|
import { OxAppLayout, OxSidebar, OxMainContent } from '@noxickon/onyx/layouts';
|
|
71
71
|
|
|
72
|
-
// Route
|
|
73
|
-
import {
|
|
72
|
+
// Route Guard Factories
|
|
73
|
+
import {
|
|
74
|
+
createOxProtectedRoute,
|
|
75
|
+
createOxGuestRoute,
|
|
76
|
+
createOxRoleRoute,
|
|
77
|
+
} from '@noxickon/onyx/routes';
|
|
74
78
|
|
|
75
79
|
// Utilities
|
|
76
80
|
import { cn, buildUrl, validateEmail } from '@noxickon/onyx/utils';
|
|
@@ -638,9 +642,7 @@ interface OxDroppableProps extends Omit<ComponentPropsWithRef<'div'>, 'id'> {
|
|
|
638
642
|
}}
|
|
639
643
|
>
|
|
640
644
|
<OxDndContext.Droppable id="drop-zone">
|
|
641
|
-
<OxDndContext.Draggable id="item-1">
|
|
642
|
-
Drag me
|
|
643
|
-
</OxDndContext.Draggable>
|
|
645
|
+
<OxDndContext.Draggable id="item-1">Drag me</OxDndContext.Draggable>
|
|
644
646
|
</OxDndContext.Droppable>
|
|
645
647
|
</OxDndContext>
|
|
646
648
|
```
|
|
@@ -856,9 +858,7 @@ interface OxEndlessListErrorProps extends Omit<HTMLAttributes<HTMLDivElement>, '
|
|
|
856
858
|
onLoadMore={fetchMore}
|
|
857
859
|
>
|
|
858
860
|
<OxEndlessList.Items>
|
|
859
|
-
<OxEndlessList.Item>
|
|
860
|
-
{(item, index) => <div>{item.name}</div>}
|
|
861
|
-
</OxEndlessList.Item>
|
|
861
|
+
<OxEndlessList.Item>{(item, index) => <div>{item.name}</div>}</OxEndlessList.Item>
|
|
862
862
|
</OxEndlessList.Items>
|
|
863
863
|
<OxEndlessList.Loader>Loading more...</OxEndlessList.Loader>
|
|
864
864
|
<OxEndlessList.Empty>No items found</OxEndlessList.Empty>
|
|
@@ -1327,11 +1327,21 @@ interface OxPageOutlineItemProps extends ComponentPropsWithRef<'a'> {
|
|
|
1327
1327
|
<OxPageOutline scrollOffset={80}>
|
|
1328
1328
|
<OxPageOutline.Header>On this page</OxPageOutline.Header>
|
|
1329
1329
|
<OxPageOutline.Content>
|
|
1330
|
-
<OxPageOutline.Item href="#introduction" level={1}>
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
<OxPageOutline.Item href="#
|
|
1334
|
-
|
|
1330
|
+
<OxPageOutline.Item href="#introduction" level={1}>
|
|
1331
|
+
Introduction
|
|
1332
|
+
</OxPageOutline.Item>
|
|
1333
|
+
<OxPageOutline.Item href="#getting-started" level={1}>
|
|
1334
|
+
Getting Started
|
|
1335
|
+
</OxPageOutline.Item>
|
|
1336
|
+
<OxPageOutline.Item href="#installation" level={2}>
|
|
1337
|
+
Installation
|
|
1338
|
+
</OxPageOutline.Item>
|
|
1339
|
+
<OxPageOutline.Item href="#configuration" level={2}>
|
|
1340
|
+
Configuration
|
|
1341
|
+
</OxPageOutline.Item>
|
|
1342
|
+
<OxPageOutline.Item href="#api" level={1}>
|
|
1343
|
+
API Reference
|
|
1344
|
+
</OxPageOutline.Item>
|
|
1335
1345
|
</OxPageOutline.Content>
|
|
1336
1346
|
</OxPageOutline>
|
|
1337
1347
|
```
|
|
@@ -3154,61 +3164,106 @@ interface OxLegendProps extends ComponentPropsWithRef<'legend'> {
|
|
|
3154
3164
|
|
|
3155
3165
|
## OxAuthContext
|
|
3156
3166
|
|
|
3157
|
-
|
|
3167
|
+
Factory-based authentication context with custom fetcher pattern (backend-agnostic).
|
|
3158
3168
|
|
|
3159
|
-
**Exports**: `
|
|
3169
|
+
**Exports**: `createOxAuth`
|
|
3160
3170
|
|
|
3161
|
-
###
|
|
3171
|
+
### Factory Pattern
|
|
3162
3172
|
|
|
3163
3173
|
```tsx
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
pollInterval?: number; // Default: 300000 (5 minutes)
|
|
3174
|
+
type OxCheckFunction<T> = (user: T | null) => boolean;
|
|
3175
|
+
type OxChecks<T> = Record<string, OxCheckFunction<T>>;
|
|
3176
|
+
|
|
3177
|
+
interface CreateOxAuthConfig<T, C extends OxChecks<T>> {
|
|
3178
|
+
checks?: C; // Custom check functions defined at factory level
|
|
3170
3179
|
}
|
|
3171
3180
|
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
} | null;
|
|
3181
|
+
interface OxAuthProviderProps<T> {
|
|
3182
|
+
children: ReactNode;
|
|
3183
|
+
fetcher: () => Promise<T | null>; // Custom fetcher (REST, GraphQL, etc.)
|
|
3184
|
+
pollInterval?: number; // Default: 300000 (5 minutes), 0 to disable
|
|
3185
|
+
}
|
|
3178
3186
|
|
|
3179
|
-
type
|
|
3180
|
-
|
|
3181
|
-
|
|
3187
|
+
type OxAuthContextValue<T, C extends OxChecks<T>> = {
|
|
3188
|
+
checks: { [K in keyof C]: boolean }; // Evaluated check results
|
|
3189
|
+
error: Error | null;
|
|
3182
3190
|
isLoggedIn: boolean; // Computed from !!user
|
|
3183
3191
|
loading: boolean;
|
|
3184
|
-
refreshUser:
|
|
3185
|
-
user:
|
|
3192
|
+
refreshUser: () => Promise<void>;
|
|
3193
|
+
user: T | null;
|
|
3194
|
+
};
|
|
3195
|
+
|
|
3196
|
+
// Factory returns typed Provider and Hook
|
|
3197
|
+
function createOxAuth<T, C extends OxChecks<T>>(
|
|
3198
|
+
config: CreateOxAuthConfig<T, C>
|
|
3199
|
+
): {
|
|
3200
|
+
OxAuthProvider: (props: OxAuthProviderProps<T>) => ReactNode;
|
|
3201
|
+
useOxAuth: () => OxAuthContextValue<T, C>;
|
|
3186
3202
|
};
|
|
3187
3203
|
```
|
|
3188
3204
|
|
|
3189
3205
|
### Example
|
|
3190
3206
|
|
|
3191
3207
|
```tsx
|
|
3192
|
-
//
|
|
3193
|
-
|
|
3208
|
+
// 1. Define user type and create auth context (src/lib/auth.ts)
|
|
3209
|
+
interface MyUser {
|
|
3210
|
+
id: string;
|
|
3211
|
+
email: string;
|
|
3212
|
+
role: 'admin' | 'user';
|
|
3213
|
+
emailVerified: boolean;
|
|
3214
|
+
}
|
|
3215
|
+
|
|
3216
|
+
export const { OxAuthProvider, useOxAuth } = createOxAuth<MyUser>({
|
|
3217
|
+
checks: {
|
|
3218
|
+
isAdmin: (user) => user?.role === 'admin',
|
|
3219
|
+
isVerified: (user) => user?.emailVerified === true,
|
|
3220
|
+
},
|
|
3221
|
+
});
|
|
3222
|
+
|
|
3223
|
+
// 2. Wrap app with provider (REST example)
|
|
3224
|
+
import { OxAuthProvider } from '@/lib/auth';
|
|
3225
|
+
|
|
3226
|
+
<OxAuthProvider
|
|
3227
|
+
fetcher={async () => {
|
|
3228
|
+
const res = await fetch('/api/auth/me', { credentials: 'include' });
|
|
3229
|
+
if (!res.ok) return null;
|
|
3230
|
+
return res.json();
|
|
3231
|
+
}}
|
|
3232
|
+
pollInterval={300000}
|
|
3233
|
+
>
|
|
3194
3234
|
<App />
|
|
3195
|
-
</OxAuthProvider
|
|
3235
|
+
</OxAuthProvider>
|
|
3236
|
+
|
|
3237
|
+
// 2. Wrap app with provider (GraphQL example)
|
|
3238
|
+
<OxAuthProvider
|
|
3239
|
+
fetcher={async () => {
|
|
3240
|
+
const { data } = await apolloClient.query({ query: GET_ME });
|
|
3241
|
+
return data.me;
|
|
3242
|
+
}}
|
|
3243
|
+
>
|
|
3244
|
+
<App />
|
|
3245
|
+
</OxAuthProvider>
|
|
3246
|
+
|
|
3247
|
+
// 3. Use hook in components (no generics needed - already typed!)
|
|
3248
|
+
import { useOxAuth } from '@/lib/auth';
|
|
3196
3249
|
|
|
3197
|
-
// Use in component
|
|
3198
3250
|
function MyComponent() {
|
|
3199
|
-
const { user, isLoggedIn,
|
|
3251
|
+
const { user, isLoggedIn, checks, loading, refreshUser } = useOxAuth();
|
|
3200
3252
|
|
|
3201
3253
|
if (loading) return <Spinner />;
|
|
3202
3254
|
if (!isLoggedIn) return <Login />;
|
|
3255
|
+
if (!checks.isVerified) return <VerifyEmail />;
|
|
3203
3256
|
|
|
3204
|
-
return <Dashboard user={user} />;
|
|
3257
|
+
return <Dashboard user={user} isAdmin={checks.isAdmin} />;
|
|
3205
3258
|
}
|
|
3206
3259
|
```
|
|
3207
3260
|
|
|
3208
3261
|
**Notes**:
|
|
3209
3262
|
|
|
3210
|
-
-
|
|
3211
|
-
-
|
|
3263
|
+
- Factory pattern: checks defined once, full TypeScript inference
|
|
3264
|
+
- Backend-agnostic: works with REST, GraphQL, or any async fetcher
|
|
3265
|
+
- No generics at call site: hook is pre-typed from factory
|
|
3266
|
+
- No external dependencies (no Apollo required)
|
|
3212
3267
|
- Throws error if hook used outside provider
|
|
3213
3268
|
|
|
3214
3269
|
---
|
|
@@ -3529,7 +3584,11 @@ function ProductList() {
|
|
|
3529
3584
|
<option value="">All</option>
|
|
3530
3585
|
<option value="electronics">Electronics</option>
|
|
3531
3586
|
</select>
|
|
3532
|
-
{isLoading ?
|
|
3587
|
+
{isLoading ? (
|
|
3588
|
+
<Spinner />
|
|
3589
|
+
) : (
|
|
3590
|
+
data?.map((product) => <ProductCard key={product.id} {...product} />)
|
|
3591
|
+
)}
|
|
3533
3592
|
</div>
|
|
3534
3593
|
);
|
|
3535
3594
|
}
|
|
@@ -4019,12 +4078,8 @@ function TableOfContents() {
|
|
|
4019
4078
|
|
|
4020
4079
|
return (
|
|
4021
4080
|
<nav>
|
|
4022
|
-
{sectionIds.map(id => (
|
|
4023
|
-
<a
|
|
4024
|
-
key={id}
|
|
4025
|
-
href={`#${id}`}
|
|
4026
|
-
className={activeId === id ? 'active' : ''}
|
|
4027
|
-
>
|
|
4081
|
+
{sectionIds.map((id) => (
|
|
4082
|
+
<a key={id} href={`#${id}`} className={activeId === id ? 'active' : ''}>
|
|
4028
4083
|
{id}
|
|
4029
4084
|
</a>
|
|
4030
4085
|
))}
|
|
@@ -4066,7 +4121,9 @@ function ResponsiveComponent() {
|
|
|
4066
4121
|
return (
|
|
4067
4122
|
<div ref={setRef}>
|
|
4068
4123
|
{size && (
|
|
4069
|
-
<p>
|
|
4124
|
+
<p>
|
|
4125
|
+
Width: {size.width}px, Height: {size.height}px
|
|
4126
|
+
</p>
|
|
4070
4127
|
)}
|
|
4071
4128
|
{size && size.width < 400 ? <CompactView /> : <FullView />}
|
|
4072
4129
|
</div>
|
|
@@ -4113,11 +4170,7 @@ interface UseThemeReturn {
|
|
|
4113
4170
|
function ThemeToggle() {
|
|
4114
4171
|
const { theme, toggleTheme } = useTheme();
|
|
4115
4172
|
|
|
4116
|
-
return
|
|
4117
|
-
<button onClick={toggleTheme}>
|
|
4118
|
-
{theme === 'light' ? '🌙' : '☀️'}
|
|
4119
|
-
</button>
|
|
4120
|
-
);
|
|
4173
|
+
return <button onClick={toggleTheme}>{theme === 'light' ? '🌙' : '☀️'}</button>;
|
|
4121
4174
|
}
|
|
4122
4175
|
|
|
4123
4176
|
// With custom storage key
|
|
@@ -4137,9 +4190,40 @@ const { theme, setTheme } = useTheme({
|
|
|
4137
4190
|
|
|
4138
4191
|
# Route Guards (3)
|
|
4139
4192
|
|
|
4140
|
-
|
|
4193
|
+
Factory functions that create typed route components bound to your auth hook.
|
|
4141
4194
|
|
|
4142
|
-
|
|
4195
|
+
## Setup
|
|
4196
|
+
|
|
4197
|
+
```tsx
|
|
4198
|
+
// src/lib/auth.ts - Create routes once with your auth hook
|
|
4199
|
+
import { createOxAuth } from '@noxickon/onyx/contexts';
|
|
4200
|
+
import {
|
|
4201
|
+
createOxProtectedRoute,
|
|
4202
|
+
createOxGuestRoute,
|
|
4203
|
+
createOxRoleRoute,
|
|
4204
|
+
} from '@noxickon/onyx/routes';
|
|
4205
|
+
|
|
4206
|
+
interface User {
|
|
4207
|
+
id: string;
|
|
4208
|
+
role: 'admin' | 'user' | 'moderator';
|
|
4209
|
+
}
|
|
4210
|
+
|
|
4211
|
+
const { OxAuthProvider, useOxAuth } = createOxAuth<User>({
|
|
4212
|
+
checks: { isAdmin: (u) => u?.role === 'admin' },
|
|
4213
|
+
});
|
|
4214
|
+
|
|
4215
|
+
// Create typed route components
|
|
4216
|
+
export const OxProtectedRoute = createOxProtectedRoute(useOxAuth);
|
|
4217
|
+
export const OxGuestRoute = createOxGuestRoute(useOxAuth);
|
|
4218
|
+
export const OxRoleRoute = createOxRoleRoute(useOxAuth);
|
|
4219
|
+
export { OxAuthProvider, useOxAuth };
|
|
4220
|
+
```
|
|
4221
|
+
|
|
4222
|
+
---
|
|
4223
|
+
|
|
4224
|
+
## createOxGuestRoute
|
|
4225
|
+
|
|
4226
|
+
Factory for routes accessible only to unauthenticated users (e.g., login, signup).
|
|
4143
4227
|
|
|
4144
4228
|
### Props
|
|
4145
4229
|
|
|
@@ -4154,16 +4238,18 @@ interface OxGuestRouteProps {
|
|
|
4154
4238
|
### Example
|
|
4155
4239
|
|
|
4156
4240
|
```tsx
|
|
4241
|
+
import { OxGuestRoute } from '@/lib/auth';
|
|
4242
|
+
|
|
4157
4243
|
<OxGuestRoute onLoading={<Spinner />} onAuthenticated={<Navigate to="/dashboard" />}>
|
|
4158
4244
|
<LoginPage />
|
|
4159
|
-
</OxGuestRoute
|
|
4245
|
+
</OxGuestRoute>;
|
|
4160
4246
|
```
|
|
4161
4247
|
|
|
4162
4248
|
---
|
|
4163
4249
|
|
|
4164
|
-
##
|
|
4250
|
+
## createOxProtectedRoute
|
|
4165
4251
|
|
|
4166
|
-
|
|
4252
|
+
Factory for routes requiring authentication.
|
|
4167
4253
|
|
|
4168
4254
|
### Props
|
|
4169
4255
|
|
|
@@ -4178,24 +4264,27 @@ interface OxProtectedRouteProps {
|
|
|
4178
4264
|
### Example
|
|
4179
4265
|
|
|
4180
4266
|
```tsx
|
|
4267
|
+
import { OxProtectedRoute } from '@/lib/auth';
|
|
4268
|
+
|
|
4181
4269
|
<OxProtectedRoute onLoading={<Spinner />} onUnauthenticated={<Navigate to="/login" />}>
|
|
4182
4270
|
<Dashboard />
|
|
4183
|
-
</OxProtectedRoute
|
|
4271
|
+
</OxProtectedRoute>;
|
|
4184
4272
|
```
|
|
4185
4273
|
|
|
4186
4274
|
---
|
|
4187
4275
|
|
|
4188
|
-
##
|
|
4276
|
+
## createOxRoleRoute
|
|
4189
4277
|
|
|
4190
|
-
|
|
4278
|
+
Factory for routes requiring specific user roles.
|
|
4191
4279
|
|
|
4192
4280
|
### Props
|
|
4193
4281
|
|
|
4194
4282
|
```tsx
|
|
4195
|
-
interface OxRoleRouteProps {
|
|
4283
|
+
interface OxRoleRouteProps<T extends { role: string }> {
|
|
4196
4284
|
children: ReactNode; // Required - Shown when user has role
|
|
4197
4285
|
onLoading?: ReactNode; // Fallback during auth check
|
|
4198
|
-
onUnauthorized?: ReactNode; // Fallback when unauthorized
|
|
4286
|
+
onUnauthorized?: ReactNode; // Fallback when unauthorized
|
|
4287
|
+
roleExtractor?: (user: T) => string; // Default: (u) => u.role
|
|
4199
4288
|
roles?: string[]; // Default: ['admin'] - Allowed roles (OR logic)
|
|
4200
4289
|
}
|
|
4201
4290
|
```
|
|
@@ -4203,10 +4292,12 @@ interface OxRoleRouteProps {
|
|
|
4203
4292
|
### Example
|
|
4204
4293
|
|
|
4205
4294
|
```tsx
|
|
4295
|
+
import { OxRoleRoute } from '@/lib/auth';
|
|
4296
|
+
|
|
4206
4297
|
{
|
|
4207
|
-
/* Admin only */
|
|
4298
|
+
/* Admin only (default) */
|
|
4208
4299
|
}
|
|
4209
|
-
<OxRoleRoute>
|
|
4300
|
+
<OxRoleRoute onUnauthorized={<AccessDenied />}>
|
|
4210
4301
|
<AdminPanel />
|
|
4211
4302
|
</OxRoleRoute>;
|
|
4212
4303
|
|
|
@@ -4220,9 +4311,12 @@ interface OxRoleRouteProps {
|
|
|
4220
4311
|
|
|
4221
4312
|
**Notes**:
|
|
4222
4313
|
|
|
4314
|
+
- Factory pattern: no prop drilling, hook called internally
|
|
4315
|
+
- User type must have a `role` property (TypeScript enforced)
|
|
4223
4316
|
- User must have at least ONE of the specified roles
|
|
4224
4317
|
- Empty roles array always shows `onUnauthorized`
|
|
4225
4318
|
- Default role: `'admin'`
|
|
4319
|
+
- Custom `roleExtractor` for nested role properties
|
|
4226
4320
|
|
|
4227
4321
|
---
|
|
4228
4322
|
|
|
@@ -4766,9 +4860,12 @@ const { data, validate } = useFormState({
|
|
|
4766
4860
|
|
|
4767
4861
|
## Route Protection
|
|
4768
4862
|
|
|
4769
|
-
Layer route guards for complex authorization:
|
|
4863
|
+
Layer route guards for complex authorization (routes created via factory pattern):
|
|
4770
4864
|
|
|
4771
4865
|
```tsx
|
|
4866
|
+
// Import from your auth setup file
|
|
4867
|
+
import { OxProtectedRoute, OxGuestRoute, OxRoleRoute } from '@/lib/auth';
|
|
4868
|
+
|
|
4772
4869
|
{
|
|
4773
4870
|
/* Guest route wrapping protected content */
|
|
4774
4871
|
}
|
|
@@ -4843,13 +4940,8 @@ interface OxFormState {
|
|
|
4843
4940
|
setError: (field: string, error: string | string[]) => void;
|
|
4844
4941
|
}
|
|
4845
4942
|
|
|
4846
|
-
//
|
|
4847
|
-
|
|
4848
|
-
id: string;
|
|
4849
|
-
role: string;
|
|
4850
|
-
email?: string;
|
|
4851
|
-
username?: string;
|
|
4852
|
-
} | null;
|
|
4943
|
+
// AuthContext uses generics - define your own user type
|
|
4944
|
+
// See OxAuthContext section for examples
|
|
4853
4945
|
```
|
|
4854
4946
|
|
|
4855
4947
|
---
|
|
@@ -1,5 +1,2 @@
|
|
|
1
1
|
export type * from './src/AuthContext.types';
|
|
2
|
-
export {
|
|
3
|
-
export { OxAuthProvider } from './src/AuthProvider';
|
|
4
|
-
export { OxAuthContext } from './src/AuthContext';
|
|
5
|
-
export { useOxAuth } from './src/useAuth';
|
|
2
|
+
export { createOxAuth } from './src/createOxAuth';
|
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
export type OxCheckFunction<T> = (user: T | null) => boolean;
|
|
3
|
+
export type OxChecks<T> = Record<string, OxCheckFunction<T>>;
|
|
4
|
+
export interface OxAuthContextValue<T, C extends OxChecks<T> = OxChecks<T>> {
|
|
5
|
+
checks: {
|
|
6
|
+
[K in keyof C]: boolean;
|
|
7
|
+
};
|
|
8
|
+
error: Error | null;
|
|
9
|
+
isLoggedIn: boolean;
|
|
10
|
+
loading: boolean;
|
|
11
|
+
refreshUser: () => Promise<void>;
|
|
12
|
+
user: T | null;
|
|
13
|
+
}
|
|
14
|
+
export interface OxAuthProviderProps<T> {
|
|
15
15
|
children: ReactNode;
|
|
16
|
-
|
|
17
|
-
options?: Omit<Parameters<typeof useQuery>[1], 'pollInterval'>;
|
|
16
|
+
fetcher: () => Promise<T | null>;
|
|
18
17
|
pollInterval?: number;
|
|
19
18
|
}
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
export interface CreateOxAuthConfig<T, C extends OxChecks<T>> {
|
|
20
|
+
checks?: C;
|
|
21
|
+
}
|
|
22
|
+
export interface CreateOxAuthReturn<T, C extends OxChecks<T>> {
|
|
23
|
+
OxAuthProvider: (props: OxAuthProviderProps<T>) => ReactNode;
|
|
24
|
+
useOxAuth: () => OxAuthContextValue<T, C>;
|
|
25
|
+
}
|
|
26
|
+
export interface OxAuthState<T = unknown> {
|
|
27
|
+
error: Error | null;
|
|
23
28
|
isLoggedIn: boolean;
|
|
24
29
|
loading: boolean;
|
|
25
|
-
refreshUser:
|
|
26
|
-
user:
|
|
27
|
-
}
|
|
30
|
+
refreshUser: () => Promise<void>;
|
|
31
|
+
user: T | null;
|
|
32
|
+
}
|
|
33
|
+
export type UseAuthHook<T = unknown> = () => OxAuthState<T>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CreateOxAuthConfig, OxAuthContextValue, OxAuthProviderProps, OxChecks } from './AuthContext.types';
|
|
2
|
+
export declare function createOxAuth<T, C extends OxChecks<T> = OxChecks<T>>(config?: CreateOxAuthConfig<T, C>): {
|
|
3
|
+
OxAuthProvider: ({ children, fetcher, pollInterval, }: OxAuthProviderProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
useOxAuth: () => OxAuthContextValue<T, C>;
|
|
5
|
+
};
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
query getCurrentUser {
|
|
3
|
-
me {
|
|
4
|
-
id
|
|
5
|
-
username
|
|
6
|
-
email
|
|
7
|
-
role
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
`;function L({adminRole:t="ADMIN",children:e,getCurrentUserQuery:a=w,options:l={},pollInterval:f=300*1e3}){const{data:u,error:r,loading:d,refetch:o}=m.useQuery(a,{fetchPolicy:"cache-and-network",nextFetchPolicy:"cache-first",errorPolicy:"all",pollInterval:f,...l}),s=!!u?.me,c=u?.me?.role===t;return g.jsx(T.OxAuthContext.Provider,{value:{user:u?.me||null,loading:d,error:r??null,isLoggedIn:s,isAdmin:c,refreshUser:o},children:e})}const R=C.gql`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("../chunks/ui-B0Ma5GdK.js"),y=require("react/jsx-runtime"),s=require("react"),j=require("@apollo/client"),w=require("../chunks/hooks-CNgb50x1.js");function T(r={}){const{checks:e={}}=r,d=s.createContext(void 0);function l({children:a,fetcher:o,pollInterval:f=300*1e3}){const[n,i]=s.useState(null),[u,_]=s.useState(!0),[v,p]=s.useState(null),O=s.useRef(null),D=s.useRef(!0),E=s.useRef(o);E.current=o;const m=s.useCallback(async()=>{try{const t=await E.current();D.current&&(i(t),p(null))}catch(t){D.current&&(p(t instanceof Error?t:new Error("Unknown error")),i(null))}finally{D.current&&_(!1)}},[]);s.useEffect(()=>(D.current=!0,m(),f>0&&(O.current=setInterval(m,f)),()=>{D.current=!1,O.current&&clearInterval(O.current)}),[m,f]);const h=s.useMemo(()=>{const t={};for(const[g,b]of Object.entries(e))t[g]=b(n);return t},[n]),F=!!n,c=s.useMemo(()=>({checks:h,error:v,isLoggedIn:F,loading:u,refreshUser:m,user:n}),[h,v,F,u,m,n]);return y.jsx(d.Provider,{value:c,children:a})}function x(){const a=s.useContext(d);if(!a)throw new Error("useOxAuth must be used within an OxAuthProvider");return a}return{OxAuthProvider:l,useOxAuth:x}}const k=j.gql`
|
|
11
2
|
query getFeatures {
|
|
12
3
|
features
|
|
13
4
|
}
|
|
14
|
-
`,
|
|
5
|
+
`,C=s.createContext(void 0);function q({children:r,enableDevMode:e=!1,getFeaturesQuery:d=k,options:l={},pollInterval:x=300*1e3}){const{data:a,error:o,loading:f,refetch:n}=w.useQuery(d,{fetchPolicy:"cache-and-network",nextFetchPolicy:"cache-first",errorPolicy:"all",pollInterval:x,skip:e,...l}),i=a?.features||{},u=_=>e?!0:i[_]??!1;return y.jsx(C.Provider,{value:{features:i,isEnabled:u,loading:f,error:o??null,refreshFeatures:n,enableDevMode:e},children:r})}function R(){const r=s.useContext(C);if(!r)throw new Error("useOxFeature must be used within an OxFeatureProvider");return r}const U=r=>{const e=w.compilerRuntimeExports.c(8),{children:d,className:l,fallback:x,name:a}=r,o=x===void 0?null:x,{isEnabled:f}=R();if(!f(a)){let u;return e[0]!==l||e[1]!==o?(u=o?y.jsx("div",{className:A.cn("contents",l),children:o}):null,e[0]=l,e[1]=o,e[2]=u):u=e[2],u}let n;e[3]!==l?(n=A.cn("contents",l),e[3]=l,e[4]=n):n=e[4];let i;return e[5]!==d||e[6]!==n?(i=y.jsx("div",{className:n,children:d}),e[5]=d,e[6]=n,e[7]=i):i=e[7],i},S=s.createContext(null),L=r=>{const e=w.compilerRuntimeExports.c(17),{children:d,maxDialogs:l}=r,x=l===void 0?3:l;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=[],e[0]=a):a=e[0];const[o,f]=s.useState(a);let n,i;e[1]!==o?(n=()=>{const c=o.some(M);return document.body.classList.toggle("overflow-hidden",c),I},i=[o],e[1]=o,e[2]=n,e[3]=i):(n=e[2],i=e[3]),s.useEffect(n,i);let u;e[4]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{let c=null;f(t=>{const g=t.filter(N),b=w.head(g);return b?(c=b.id,t.map(P=>P.id===b.id?{...P,isOpen:!1}:P)):t}),c&&setTimeout(()=>{f(t=>w.reject(t,g=>g.id===c))},200)},e[4]=u):u=e[4];const _=u;let v;e[5]!==x?(v=(c,t)=>{const g=w.uniqueId(),b={id:g,content:c,isOpen:!0,options:t};return f(P=>[b,...P].slice(0,x)),g},e[5]=x,e[6]=v):v=e[6];const p=v;let O;e[7]===Symbol.for("react.memo_cache_sentinel")?(O=()=>{f($),setTimeout(()=>{f([])},200)},e[7]=O):O=e[7];const D=O;let E;e[8]!==p?(E=Object.assign((c,t)=>p(c,t),{open:p,dismiss:_,dismissAll:D}),e[8]=p,e[9]=E):E=e[9];const m=E;let h;if(e[10]!==o){let c;e[12]===Symbol.for("react.memo_cache_sentinel")?(c=t=>y.jsx(A.OxDialog,{isOpen:t.isOpen,onClose:_,...t.options,children:t.content},t.id),e[12]=c):c=e[12],h=o.map(c),e[10]=o,e[11]=h}else h=e[11];let F;return e[13]!==d||e[14]!==m||e[15]!==h?(F=y.jsxs(S.Provider,{value:m,children:[d,h]}),e[13]=d,e[14]=m,e[15]=h,e[16]=F):F=e[16],F};function M(r){return r.isOpen}function I(){document.body.classList.remove("overflow-hidden")}function N(r){return r.isOpen}function G(r){return{...r,isOpen:!1}}function $(r){return r.map(G)}const Q=()=>{const r=s.useContext(S);if(!r)throw new Error("useOxDialog must be used within a DialogProvider");return r};exports.DEFAULT_GET_FEATURES=k;exports.OxDialogProvider=L;exports.OxFeatureFlag=U;exports.OxFeatureProvider=q;exports.createOxAuth=T;exports.useOxDialog=Q;exports.useOxFeature=R;
|
|
@@ -1,202 +1,209 @@
|
|
|
1
|
-
import { af as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import { createContext as C, useContext as T, useState as G, useEffect as $ } from "react";
|
|
8
|
-
const B = b`
|
|
9
|
-
query getCurrentUser {
|
|
10
|
-
me {
|
|
11
|
-
id
|
|
12
|
-
username
|
|
13
|
-
email
|
|
14
|
-
role
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
`;
|
|
18
|
-
function se({
|
|
19
|
-
adminRole: t = "ADMIN",
|
|
20
|
-
children: e,
|
|
21
|
-
getCurrentUserQuery: u = B,
|
|
22
|
-
options: l = {},
|
|
23
|
-
pollInterval: m = 300 * 1e3
|
|
24
|
-
}) {
|
|
1
|
+
import { af as C, y as T } from "../chunks/ui-DrKTwQ0M.js";
|
|
2
|
+
import { jsx as E, jsxs as q } from "react/jsx-runtime";
|
|
3
|
+
import { createContext as k, useContext as A, useState as F, useRef as P, useCallback as I, useEffect as S, useMemo as R } from "react";
|
|
4
|
+
import { gql as N } from "@apollo/client";
|
|
5
|
+
import { B as M, d as U, C as $, w as B, y as G } from "../chunks/hooks-6tQOArBm.js";
|
|
6
|
+
function ne(r = {}) {
|
|
25
7
|
const {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
8
|
+
checks: e = {}
|
|
9
|
+
} = r, f = k(void 0);
|
|
10
|
+
function l({
|
|
11
|
+
children: u,
|
|
12
|
+
fetcher: s,
|
|
13
|
+
pollInterval: a = 300 * 1e3
|
|
14
|
+
}) {
|
|
15
|
+
const [n, i] = F(null), [c, b] = F(!0), [O, p] = F(null), x = P(null), v = P(!0), w = P(s);
|
|
16
|
+
w.current = s;
|
|
17
|
+
const m = I(async () => {
|
|
18
|
+
try {
|
|
19
|
+
const t = await w.current();
|
|
20
|
+
v.current && (i(t), p(null));
|
|
21
|
+
} catch (t) {
|
|
22
|
+
v.current && (p(t instanceof Error ? t : new Error("Unknown error")), i(null));
|
|
23
|
+
} finally {
|
|
24
|
+
v.current && b(!1);
|
|
25
|
+
}
|
|
26
|
+
}, []);
|
|
27
|
+
S(() => (v.current = !0, m(), a > 0 && (x.current = setInterval(m, a)), () => {
|
|
28
|
+
v.current = !1, x.current && clearInterval(x.current);
|
|
29
|
+
}), [m, a]);
|
|
30
|
+
const h = R(() => {
|
|
31
|
+
const t = {};
|
|
32
|
+
for (const [g, D] of Object.entries(e))
|
|
33
|
+
t[g] = D(n);
|
|
34
|
+
return t;
|
|
35
|
+
}, [n]), y = !!n, o = R(() => ({
|
|
36
|
+
checks: h,
|
|
37
|
+
error: O,
|
|
38
|
+
isLoggedIn: y,
|
|
39
|
+
loading: c,
|
|
40
|
+
refreshUser: m,
|
|
41
|
+
user: n
|
|
42
|
+
}), [h, O, y, c, m, n]);
|
|
43
|
+
return /* @__PURE__ */ E(f.Provider, { value: o, children: u });
|
|
44
|
+
}
|
|
45
|
+
function d() {
|
|
46
|
+
const u = A(f);
|
|
47
|
+
if (!u)
|
|
48
|
+
throw new Error("useOxAuth must be used within an OxAuthProvider");
|
|
49
|
+
return u;
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
OxAuthProvider: l,
|
|
53
|
+
useOxAuth: d
|
|
54
|
+
};
|
|
45
55
|
}
|
|
46
|
-
const
|
|
56
|
+
const Q = N`
|
|
47
57
|
query getFeatures {
|
|
48
58
|
features
|
|
49
59
|
}
|
|
50
|
-
`,
|
|
51
|
-
function
|
|
52
|
-
children:
|
|
60
|
+
`, j = k(void 0);
|
|
61
|
+
function se({
|
|
62
|
+
children: r,
|
|
53
63
|
enableDevMode: e = !1,
|
|
54
|
-
getFeaturesQuery:
|
|
64
|
+
getFeaturesQuery: f = Q,
|
|
55
65
|
options: l = {},
|
|
56
|
-
pollInterval:
|
|
66
|
+
pollInterval: d = 300 * 1e3
|
|
57
67
|
}) {
|
|
58
68
|
const {
|
|
59
|
-
data:
|
|
60
|
-
error:
|
|
61
|
-
loading:
|
|
62
|
-
refetch:
|
|
63
|
-
} =
|
|
69
|
+
data: u,
|
|
70
|
+
error: s,
|
|
71
|
+
loading: a,
|
|
72
|
+
refetch: n
|
|
73
|
+
} = M(f, {
|
|
64
74
|
fetchPolicy: "cache-and-network",
|
|
65
75
|
nextFetchPolicy: "cache-first",
|
|
66
76
|
errorPolicy: "all",
|
|
67
|
-
pollInterval:
|
|
77
|
+
pollInterval: d,
|
|
68
78
|
skip: e,
|
|
69
79
|
...l
|
|
70
|
-
}),
|
|
71
|
-
return /* @__PURE__ */
|
|
72
|
-
features:
|
|
80
|
+
}), i = u?.features || {}, c = (b) => e ? !0 : i[b] ?? !1;
|
|
81
|
+
return /* @__PURE__ */ E(j.Provider, { value: {
|
|
82
|
+
features: i,
|
|
73
83
|
isEnabled: c,
|
|
74
|
-
loading:
|
|
75
|
-
error:
|
|
76
|
-
refreshFeatures:
|
|
84
|
+
loading: a,
|
|
85
|
+
error: s ?? null,
|
|
86
|
+
refreshFeatures: n,
|
|
77
87
|
enableDevMode: e
|
|
78
|
-
}, children:
|
|
88
|
+
}, children: r });
|
|
79
89
|
}
|
|
80
|
-
function
|
|
81
|
-
const
|
|
82
|
-
if (!
|
|
90
|
+
function z() {
|
|
91
|
+
const r = A(j);
|
|
92
|
+
if (!r)
|
|
83
93
|
throw new Error("useOxFeature must be used within an OxFeatureProvider");
|
|
84
|
-
return
|
|
94
|
+
return r;
|
|
85
95
|
}
|
|
86
|
-
const
|
|
87
|
-
const e =
|
|
88
|
-
children:
|
|
96
|
+
const oe = (r) => {
|
|
97
|
+
const e = U.c(8), {
|
|
98
|
+
children: f,
|
|
89
99
|
className: l,
|
|
90
|
-
fallback:
|
|
91
|
-
name:
|
|
92
|
-
} =
|
|
93
|
-
isEnabled:
|
|
94
|
-
} =
|
|
95
|
-
if (!
|
|
100
|
+
fallback: d,
|
|
101
|
+
name: u
|
|
102
|
+
} = r, s = d === void 0 ? null : d, {
|
|
103
|
+
isEnabled: a
|
|
104
|
+
} = z();
|
|
105
|
+
if (!a(u)) {
|
|
96
106
|
let c;
|
|
97
|
-
return e[0] !== l || e[1] !==
|
|
107
|
+
return e[0] !== l || e[1] !== s ? (c = s ? /* @__PURE__ */ E("div", { className: C("contents", l), children: s }) : null, e[0] = l, e[1] = s, e[2] = c) : c = e[2], c;
|
|
98
108
|
}
|
|
99
|
-
let
|
|
100
|
-
e[3] !== l ? (
|
|
101
|
-
let
|
|
102
|
-
return e[5] !==
|
|
103
|
-
},
|
|
104
|
-
const e =
|
|
105
|
-
children:
|
|
109
|
+
let n;
|
|
110
|
+
e[3] !== l ? (n = C("contents", l), e[3] = l, e[4] = n) : n = e[4];
|
|
111
|
+
let i;
|
|
112
|
+
return e[5] !== f || e[6] !== n ? (i = /* @__PURE__ */ E("div", { className: n, children: f }), e[5] = f, e[6] = n, e[7] = i) : i = e[7], i;
|
|
113
|
+
}, L = k(null), ie = (r) => {
|
|
114
|
+
const e = U.c(17), {
|
|
115
|
+
children: f,
|
|
106
116
|
maxDialogs: l
|
|
107
|
-
} =
|
|
108
|
-
let
|
|
109
|
-
e[0] === Symbol.for("react.memo_cache_sentinel") ? (
|
|
110
|
-
const [
|
|
111
|
-
let
|
|
112
|
-
e[1] !==
|
|
113
|
-
const
|
|
114
|
-
return document.body.classList.toggle("overflow-hidden",
|
|
115
|
-
},
|
|
117
|
+
} = r, d = l === void 0 ? 3 : l;
|
|
118
|
+
let u;
|
|
119
|
+
e[0] === Symbol.for("react.memo_cache_sentinel") ? (u = [], e[0] = u) : u = e[0];
|
|
120
|
+
const [s, a] = F(u);
|
|
121
|
+
let n, i;
|
|
122
|
+
e[1] !== s ? (n = () => {
|
|
123
|
+
const o = s.some(H);
|
|
124
|
+
return document.body.classList.toggle("overflow-hidden", o), J;
|
|
125
|
+
}, i = [s], e[1] = s, e[2] = n, e[3] = i) : (n = e[2], i = e[3]), S(n, i);
|
|
116
126
|
let c;
|
|
117
127
|
e[4] === Symbol.for("react.memo_cache_sentinel") ? (c = () => {
|
|
118
|
-
let
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
return
|
|
122
|
-
...
|
|
128
|
+
let o = null;
|
|
129
|
+
a((t) => {
|
|
130
|
+
const g = t.filter(K), D = $(g);
|
|
131
|
+
return D ? (o = D.id, t.map((_) => _.id === D.id ? {
|
|
132
|
+
..._,
|
|
123
133
|
isOpen: !1
|
|
124
|
-
} :
|
|
125
|
-
}),
|
|
126
|
-
|
|
134
|
+
} : _)) : t;
|
|
135
|
+
}), o && setTimeout(() => {
|
|
136
|
+
a((t) => B(t, (g) => g.id === o));
|
|
127
137
|
}, 200);
|
|
128
138
|
}, e[4] = c) : c = e[4];
|
|
129
|
-
const
|
|
130
|
-
let
|
|
131
|
-
e[5] !==
|
|
132
|
-
const
|
|
133
|
-
id:
|
|
134
|
-
content:
|
|
139
|
+
const b = c;
|
|
140
|
+
let O;
|
|
141
|
+
e[5] !== d ? (O = (o, t) => {
|
|
142
|
+
const g = G(), D = {
|
|
143
|
+
id: g,
|
|
144
|
+
content: o,
|
|
135
145
|
isOpen: !0,
|
|
136
|
-
options:
|
|
146
|
+
options: t
|
|
137
147
|
};
|
|
138
|
-
return
|
|
139
|
-
}, e[5] =
|
|
140
|
-
const
|
|
141
|
-
let
|
|
142
|
-
e[7] === Symbol.for("react.memo_cache_sentinel") ? (
|
|
143
|
-
|
|
144
|
-
|
|
148
|
+
return a((_) => [D, ..._].slice(0, d)), g;
|
|
149
|
+
}, e[5] = d, e[6] = O) : O = e[6];
|
|
150
|
+
const p = O;
|
|
151
|
+
let x;
|
|
152
|
+
e[7] === Symbol.for("react.memo_cache_sentinel") ? (x = () => {
|
|
153
|
+
a(W), setTimeout(() => {
|
|
154
|
+
a([]);
|
|
145
155
|
}, 200);
|
|
146
|
-
}, e[7] =
|
|
147
|
-
const
|
|
148
|
-
let
|
|
149
|
-
e[8] !==
|
|
150
|
-
open:
|
|
151
|
-
dismiss:
|
|
152
|
-
dismissAll:
|
|
153
|
-
}), e[8] =
|
|
154
|
-
const
|
|
155
|
-
let
|
|
156
|
-
if (e[10] !==
|
|
157
|
-
let
|
|
158
|
-
e[12] === Symbol.for("react.memo_cache_sentinel") ? (
|
|
156
|
+
}, e[7] = x) : x = e[7];
|
|
157
|
+
const v = x;
|
|
158
|
+
let w;
|
|
159
|
+
e[8] !== p ? (w = Object.assign((o, t) => p(o, t), {
|
|
160
|
+
open: p,
|
|
161
|
+
dismiss: b,
|
|
162
|
+
dismissAll: v
|
|
163
|
+
}), e[8] = p, e[9] = w) : w = e[9];
|
|
164
|
+
const m = w;
|
|
165
|
+
let h;
|
|
166
|
+
if (e[10] !== s) {
|
|
167
|
+
let o;
|
|
168
|
+
e[12] === Symbol.for("react.memo_cache_sentinel") ? (o = (t) => /* @__PURE__ */ E(T, { isOpen: t.isOpen, onClose: b, ...t.options, children: t.content }, t.id), e[12] = o) : o = e[12], h = s.map(o), e[10] = s, e[11] = h;
|
|
159
169
|
} else
|
|
160
|
-
|
|
161
|
-
let
|
|
162
|
-
return e[13] !==
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
] }), e[13] =
|
|
170
|
+
h = e[11];
|
|
171
|
+
let y;
|
|
172
|
+
return e[13] !== f || e[14] !== m || e[15] !== h ? (y = /* @__PURE__ */ q(L.Provider, { value: m, children: [
|
|
173
|
+
f,
|
|
174
|
+
h
|
|
175
|
+
] }), e[13] = f, e[14] = m, e[15] = h, e[16] = y) : y = e[16], y;
|
|
166
176
|
};
|
|
167
|
-
function
|
|
168
|
-
return
|
|
177
|
+
function H(r) {
|
|
178
|
+
return r.isOpen;
|
|
169
179
|
}
|
|
170
|
-
function
|
|
180
|
+
function J() {
|
|
171
181
|
document.body.classList.remove("overflow-hidden");
|
|
172
182
|
}
|
|
173
|
-
function
|
|
174
|
-
return
|
|
183
|
+
function K(r) {
|
|
184
|
+
return r.isOpen;
|
|
175
185
|
}
|
|
176
|
-
function
|
|
186
|
+
function V(r) {
|
|
177
187
|
return {
|
|
178
|
-
...
|
|
188
|
+
...r,
|
|
179
189
|
isOpen: !1
|
|
180
190
|
};
|
|
181
191
|
}
|
|
182
|
-
function
|
|
183
|
-
return
|
|
192
|
+
function W(r) {
|
|
193
|
+
return r.map(V);
|
|
184
194
|
}
|
|
185
|
-
const
|
|
186
|
-
const
|
|
187
|
-
if (!
|
|
195
|
+
const ce = () => {
|
|
196
|
+
const r = A(L);
|
|
197
|
+
if (!r)
|
|
188
198
|
throw new Error("useOxDialog must be used within a DialogProvider");
|
|
189
|
-
return
|
|
199
|
+
return r;
|
|
190
200
|
};
|
|
191
201
|
export {
|
|
192
|
-
|
|
193
|
-
M as DEFAULT_GET_FEATURES,
|
|
194
|
-
R as OxAuthContext,
|
|
195
|
-
se as OxAuthProvider,
|
|
202
|
+
Q as DEFAULT_GET_FEATURES,
|
|
196
203
|
ie as OxDialogProvider,
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
204
|
+
oe as OxFeatureFlag,
|
|
205
|
+
se as OxFeatureProvider,
|
|
206
|
+
ne as createOxAuth,
|
|
207
|
+
ce as useOxDialog,
|
|
208
|
+
z as useOxFeature
|
|
202
209
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { createOxGuestRoute } from './src/createOxGuestRoute';
|
|
2
|
+
export * from './src/GuestRoute.types';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { OxAuthState } from '../../../contexts';
|
|
3
|
+
import { OxGuestRouteProps } from './GuestRoute.types';
|
|
4
|
+
export declare function createOxGuestRoute<T>(useAuth: () => OxAuthState<T>): ({ children, onAuthenticated, onLoading, }: OxGuestRouteProps) => ReactNode;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { createOxProtectedRoute } from './src/createOxProtectedRoute';
|
|
2
|
+
export * from './src/ProtectedRoute.types';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { OxAuthState } from '../../../contexts';
|
|
3
|
+
import { OxProtectedRouteProps } from './ProtectedRoute.types';
|
|
4
|
+
export declare function createOxProtectedRoute<T>(useAuth: () => OxAuthState<T>): ({ children, onLoading, onUnauthenticated, }: OxProtectedRouteProps) => ReactNode;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { createOxRoleRoute } from './src/createOxRoleRoute';
|
|
2
|
+
export * from './src/RoleRoute.types';
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
export interface OxRoleRouteProps {
|
|
2
|
+
export interface OxRoleRouteProps<T extends {
|
|
3
|
+
role: string;
|
|
4
|
+
} = {
|
|
5
|
+
role: string;
|
|
6
|
+
}> {
|
|
3
7
|
children: ReactNode;
|
|
4
8
|
onLoading?: ReactNode;
|
|
5
9
|
onUnauthorized?: ReactNode;
|
|
10
|
+
roleExtractor?: (user: T) => string;
|
|
6
11
|
roles?: string[];
|
|
7
12
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { OxAuthState } from '../../../contexts';
|
|
3
|
+
import { OxRoleRouteProps } from './RoleRoute.types';
|
|
4
|
+
export declare function createOxRoleRoute<T extends {
|
|
5
|
+
role: string;
|
|
6
|
+
} = {
|
|
7
|
+
role: string;
|
|
8
|
+
}>(useAuth: () => OxAuthState<T>): ({ children, onLoading, onUnauthorized, roleExtractor, roles, }: OxRoleRouteProps<T>) => ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../chunks/hooks-CNgb50x1.js");function a(e){return function({children:n,onAuthenticated:u=null,onLoading:r=null}){const{isLoggedIn:o,loading:t}=e();return t?r:o?u:n}}function f(e){return function({children:n,onLoading:u=null,onUnauthenticated:r=null}){const{isLoggedIn:o,loading:t}=e();return t?u:o?n:r}}const d=e=>e.role;function R(e){return function({children:n,onLoading:u=null,onUnauthorized:r=null,roleExtractor:o=d,roles:t=["admin"]}){const{loading:l,user:i}=e();return l?u:!i||s.isEmpty(t)||!t.includes(o(i))?r:n}}exports.createOxGuestRoute=a;exports.createOxProtectedRoute=f;exports.createOxRoleRoute=R;
|
package/dist/routes/routes.es.js
CHANGED
|
@@ -1,40 +1,48 @@
|
|
|
1
|
-
import "../chunks/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
import { A as f } from "../chunks/hooks-6tQOArBm.js";
|
|
2
|
+
function d(t) {
|
|
3
|
+
return function({
|
|
4
|
+
children: e,
|
|
5
|
+
onAuthenticated: r = null,
|
|
6
|
+
onLoading: u = null
|
|
7
|
+
}) {
|
|
8
|
+
const {
|
|
9
|
+
isLoggedIn: o,
|
|
10
|
+
loading: n
|
|
11
|
+
} = t();
|
|
12
|
+
return n ? u : o ? r : e;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function R(t) {
|
|
16
|
+
return function({
|
|
17
|
+
children: e,
|
|
18
|
+
onLoading: r = null,
|
|
19
|
+
onUnauthenticated: u = null
|
|
20
|
+
}) {
|
|
21
|
+
const {
|
|
22
|
+
isLoggedIn: o,
|
|
23
|
+
loading: n
|
|
24
|
+
} = t();
|
|
25
|
+
return n ? r : o ? e : u;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const s = (t) => t.role;
|
|
29
|
+
function x(t) {
|
|
30
|
+
return function({
|
|
31
|
+
children: e,
|
|
32
|
+
onLoading: r = null,
|
|
33
|
+
onUnauthorized: u = null,
|
|
34
|
+
roleExtractor: o = s,
|
|
35
|
+
roles: n = ["admin"]
|
|
36
|
+
}) {
|
|
37
|
+
const {
|
|
38
|
+
loading: c,
|
|
39
|
+
user: l
|
|
40
|
+
} = t();
|
|
41
|
+
return c ? r : !l || f(n) || !n.includes(o(l)) ? u : e;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
36
44
|
export {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
45
|
+
d as createOxGuestRoute,
|
|
46
|
+
R as createOxProtectedRoute,
|
|
47
|
+
x as createOxRoleRoute
|
|
40
48
|
};
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const e=require("react"),u=e.createContext(void 0);function n(){const t=e.useContext(u);if(!t)throw new Error("useOxAuth must be used within an AuthProvider");return t}exports.OxAuthContext=u;exports.useOxAuth=n;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const DEFAULT_GET_CURRENT_USER: import('graphql').DocumentNode;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useOxAuth(): import('./AuthContext.types').OxAuthContextType;
|