@xylex-group/athena 3.1.0 → 3.3.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/README.md +1 -1
- package/dist/admin.cjs +55 -1
- package/dist/admin.cjs.map +1 -1
- package/dist/admin.d.cts +32 -8
- package/dist/admin.d.ts +32 -8
- package/dist/admin.js +54 -2
- package/dist/admin.js.map +1 -1
- package/dist/athena-auth-url-C1FbVmN6.d.cts +200 -0
- package/dist/athena-auth-url-C1FbVmN6.d.ts +200 -0
- package/dist/{athena-request-headers-C7Jy-c_D.d.ts → athena-request-headers-DzimbvOA.d.ts} +48 -200
- package/dist/{athena-request-headers-DujFFyMU.d.cts → athena-request-headers-Lr_m8xCV.d.cts} +48 -200
- package/dist/billing.cjs +1 -1
- package/dist/billing.cjs.map +1 -1
- package/dist/billing.js +1 -1
- package/dist/billing.js.map +1 -1
- package/dist/browser.cjs +602 -16
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +8 -7
- package/dist/browser.d.ts +8 -7
- package/dist/browser.js +593 -17
- package/dist/browser.js.map +1 -1
- package/dist/cli/index.cjs +141 -6
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +2 -2
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +141 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/env.cjs +130 -0
- package/dist/env.cjs.map +1 -0
- package/dist/env.d.cts +70 -0
- package/dist/env.d.ts +70 -0
- package/dist/env.js +122 -0
- package/dist/env.js.map +1 -0
- package/dist/index.cjs +624 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +615 -20
- package/dist/index.js.map +1 -1
- package/dist/{model-form-BhWWsA-7.d.cts → model-form-3Gr8rkdT.d.cts} +24 -2
- package/dist/{model-form-BbdzJ9Uh.d.ts → model-form-CotpEL7z.d.ts} +24 -2
- package/dist/{module-xFd7_Igv.d.cts → module-CQmOaDzP.d.cts} +4 -4
- package/dist/{module-DKkJKOuJ.d.ts → module-CWkUTcUc.d.ts} +4 -4
- package/dist/next/client.cjs +123 -7
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.d.cts +4 -3
- package/dist/next/client.d.ts +4 -3
- package/dist/next/client.js +123 -7
- package/dist/next/client.js.map +1 -1
- package/dist/next/server.cjs +1130 -364
- package/dist/next/server.cjs.map +1 -1
- package/dist/next/server.d.cts +121 -8
- package/dist/next/server.d.ts +121 -8
- package/dist/next/server.js +1120 -365
- package/dist/next/server.js.map +1 -1
- package/dist/{pipeline-DuKzYGia.d.cts → pipeline-BnRKO_Pd.d.cts} +1 -1
- package/dist/{pipeline-wer2G9xW.d.ts → pipeline-sWCmlFqu.d.ts} +1 -1
- package/dist/{proxy-request-headers-m4D2Tduy.d.ts → proxy-request-headers-CttlcuRb.d.ts} +1 -1
- package/dist/{proxy-request-headers-DGxdoyA0.d.cts → proxy-request-headers-pIBSn1Fw.d.cts} +1 -1
- package/dist/react.cjs +290 -31
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +59 -9
- package/dist/react.d.ts +59 -9
- package/dist/react.js +290 -32
- package/dist/react.js.map +1 -1
- package/dist/schema-handlers-BtT_IQFi.d.cts +138 -0
- package/dist/schema-handlers-VjFDhIMw.d.ts +138 -0
- package/dist/social-providers.d.cts +1 -1
- package/dist/social-providers.d.ts +1 -1
- package/dist/{types-CccOiXPo.d.ts → types-BDX8zS7w.d.ts} +12 -0
- package/dist/{types-AOY-GLu8.d.cts → types-BVKpQmfY.d.cts} +11 -0
- package/dist/{types-AOY-GLu8.d.ts → types-BVKpQmfY.d.ts} +11 -0
- package/dist/{types-1ztXDgPa.d.cts → types-D-Am7YSd.d.cts} +12 -0
- package/dist/utils.cjs +30 -0
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +3 -2
- package/dist/utils.d.ts +3 -2
- package/dist/utils.js +30 -1
- package/dist/utils.js.map +1 -1
- package/dist/{v3-client-CWfZHcKL.d.cts → v3-client-G1SLeHRa.d.cts} +23 -1
- package/dist/{v3-client-DZp2NEhK.d.ts → v3-client-ao8BWQ8v.d.ts} +23 -1
- package/package.json +16 -2
package/dist/react.d.cts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { u as AthenaGatewayHookConfig, v as AthenaGatewayHookResult } from './types-Bltx6iL6.cjs';
|
|
2
2
|
export { w as AthenaDeletePayload, x as AthenaFetchPayload, a as AthenaGatewayCallOptions, d as AthenaGatewayErrorCode, e as AthenaGatewayErrorDetails, s as AthenaGatewayResponse, y as AthenaInsertPayload, f as AthenaJsonArray, g as AthenaJsonObject, h as AthenaJsonPrimitive, i as AthenaJsonValue, j as AthenaRpcCallOptions, k as AthenaRpcFilter, l as AthenaRpcFilterOperator, m as AthenaRpcOrder, n as AthenaRpcPayload, z as AthenaUpdatePayload } from './types-Bltx6iL6.cjs';
|
|
3
|
-
import { a as AthenaReadQueryClient, c as AthenaReadQueryDefinition, e as AthenaReadQueryExecutionResult, i as AthenaReadQueryFlatRow } from './model-form-
|
|
4
|
-
export { A as AthenaGatewayError, M as ModelFormAdapter, D as ModelFormDefaults, E as ModelFormNullishMode, G as ModelFormValues, T as ToModelFormDefaultsOptions, H as ToModelPayloadOptions, _ as createModelFormAdapter, a3 as isAthenaGatewayError,
|
|
3
|
+
import { a as AthenaReadQueryClient, c as AthenaReadQueryDefinition, e as AthenaReadQueryExecutionResult, i as AthenaReadQueryFlatRow } from './model-form-3Gr8rkdT.cjs';
|
|
4
|
+
export { A as AthenaGatewayError, M as ModelFormAdapter, D as ModelFormDefaults, E as ModelFormNullishMode, G as ModelFormValues, T as ToModelFormDefaultsOptions, H as ToModelPayloadOptions, _ as createModelFormAdapter, a3 as isAthenaGatewayError, a7 as toModelFormDefaults, a8 as toModelPayload } from './model-form-3Gr8rkdT.cjs';
|
|
5
5
|
import * as react from 'react';
|
|
6
6
|
import { ReactNode } from 'react';
|
|
7
|
-
import { aE as AthenaAuthFetchCompatibleInput, E as AthenaAuthCallOptions, ad as AthenaAuthSessionResponse, R as AthenaAuthErrorDetails, aa as AthenaAuthResult } from './types-
|
|
8
|
-
export { D as AthenaAuthBindings, aC as AuthBindings } from './types-
|
|
9
|
-
import {
|
|
7
|
+
import { aE as AthenaAuthFetchCompatibleInput, E as AthenaAuthCallOptions, ad as AthenaAuthSessionResponse, R as AthenaAuthErrorDetails, aa as AthenaAuthResult, aD as AthenaAdminHasPermissionRequest } from './types-BVKpQmfY.cjs';
|
|
8
|
+
export { D as AthenaAuthBindings, aC as AuthBindings } from './types-BVKpQmfY.cjs';
|
|
9
|
+
import { AthenaAdminSessionLike, AthenaAdminPermissionCheckInput } from './admin.cjs';
|
|
10
|
+
import { ax as AthenaRequestContext, b5 as AthenaStorageFileUploadInput, bp as AthenaStorageUploadSource, bb as AthenaStorageModule, bo as AthenaStorageUploadProgressHandler, bn as AthenaStorageUploadProgress, b8 as AthenaStorageFileUploadResult, aP as AthenaStorageCallOptions, b2 as AthenaStorageFileListInput, ck as StorageListFilesResponse, cf as StorageFileMutationResponse } from './v3-client-G1SLeHRa.cjs';
|
|
10
11
|
import './types-CgCv5o6R.cjs';
|
|
11
12
|
import './module-C_ab-MM1.cjs';
|
|
12
13
|
|
|
@@ -230,9 +231,9 @@ declare function createAthenaQueryClient(config?: AthenaQueryClientConfig): Athe
|
|
|
230
231
|
declare function attachStateAdapter(client: AthenaQueryClient, adapter: AthenaStateAdapter): AthenaUnsubscribe;
|
|
231
232
|
|
|
232
233
|
interface AthenaQueryClientProviderProps {
|
|
234
|
+
children: ReactNode;
|
|
233
235
|
client?: AthenaQueryClient;
|
|
234
236
|
config?: AthenaQueryClientConfig;
|
|
235
|
-
children: ReactNode;
|
|
236
237
|
}
|
|
237
238
|
declare function AthenaQueryClientProvider(props: AthenaQueryClientProviderProps): react.FunctionComponentElement<react.ProviderProps<AthenaQueryClient | null>>;
|
|
238
239
|
declare function useAthenaQueryClient(): AthenaQueryClient;
|
|
@@ -354,6 +355,55 @@ type InferSessionData$1<TClient> = TClient extends {
|
|
|
354
355
|
*/
|
|
355
356
|
declare function useSession<TClient extends UseSessionAuthClient>(authClient: TClient, options?: UseSessionOptions): UseSessionResult<InferSessionData$1<TClient>>;
|
|
356
357
|
|
|
358
|
+
interface UseAdminPermissionOptions {
|
|
359
|
+
/**
|
|
360
|
+
* Permission set checked via `client.auth.admin.hasPermission`.
|
|
361
|
+
* Defaults to `["admin:read"]`.
|
|
362
|
+
*/
|
|
363
|
+
permissions?: AthenaAdminHasPermissionRequest['permissions'];
|
|
364
|
+
permission?: AthenaAdminHasPermissionRequest['permission'];
|
|
365
|
+
/**
|
|
366
|
+
* When provided, skips the internal session fetch.
|
|
367
|
+
* Pass `null` to force a denied result without calling getSession.
|
|
368
|
+
*/
|
|
369
|
+
session?: AthenaAdminSessionLike | null;
|
|
370
|
+
allowRoleBypass?: boolean;
|
|
371
|
+
enabled?: boolean;
|
|
372
|
+
fetchOptions?: AthenaAdminPermissionCheckInput['fetchOptions'];
|
|
373
|
+
requestOptions?: AthenaAdminPermissionCheckInput['requestOptions'];
|
|
374
|
+
/** Forwarded to the internal `useSession` when `session` is omitted. */
|
|
375
|
+
sessionOptions?: Omit<UseSessionOptions, 'enabled'>;
|
|
376
|
+
}
|
|
377
|
+
interface UseAdminPermissionResult {
|
|
378
|
+
allowed: boolean;
|
|
379
|
+
isPending: boolean;
|
|
380
|
+
error: Error | null;
|
|
381
|
+
session: AthenaAdminSessionLike | null;
|
|
382
|
+
refetch: () => Promise<boolean>;
|
|
383
|
+
}
|
|
384
|
+
type AdminPermissionAuthClient = UseSessionAuthClient & {
|
|
385
|
+
auth?: {
|
|
386
|
+
admin?: unknown;
|
|
387
|
+
};
|
|
388
|
+
admin?: unknown;
|
|
389
|
+
};
|
|
390
|
+
/**
|
|
391
|
+
* React gate for Athena admin permissions.
|
|
392
|
+
*
|
|
393
|
+
* Uses {@link hasAdminPermission} from `@xylex-group/athena/admin` with an
|
|
394
|
+
* optional local `admin` role short-circuit. When `session` is omitted, loads
|
|
395
|
+
* the current session through {@link useSession}.
|
|
396
|
+
*
|
|
397
|
+
* @example
|
|
398
|
+
* ```tsx
|
|
399
|
+
* const athena = createClient({ url, key, auth: { url: "/api/auth" } })
|
|
400
|
+
* const { allowed, isPending } = useAdminPermission(athena, {
|
|
401
|
+
* permissions: ["admin:read"],
|
|
402
|
+
* })
|
|
403
|
+
* ```
|
|
404
|
+
*/
|
|
405
|
+
declare function useAdminPermission(client: AdminPermissionAuthClient | null | undefined, options?: UseAdminPermissionOptions): UseAdminPermissionResult;
|
|
406
|
+
|
|
357
407
|
type SessionGetter<TSessionData extends AthenaAuthSessionResponse> = (input?: AthenaAuthFetchCompatibleInput, options?: AthenaAuthCallOptions) => Promise<AthenaAuthResult<TSessionData>>;
|
|
358
408
|
type AthenaContextScopedClient<TSessionData extends AthenaAuthSessionResponse = AthenaAuthSessionResponse> = {
|
|
359
409
|
auth: {
|
|
@@ -400,14 +450,14 @@ interface UseStorageUploadResult {
|
|
|
400
450
|
declare function useStorageUpload(options: UseStorageUploadOptions): UseStorageUploadResult;
|
|
401
451
|
|
|
402
452
|
interface UseStorageFilesOptions {
|
|
403
|
-
storage: Pick<AthenaStorageModule,
|
|
453
|
+
storage: Pick<AthenaStorageModule, "file">;
|
|
404
454
|
input: AthenaStorageFileListInput | null | undefined;
|
|
405
455
|
enabled?: boolean;
|
|
406
456
|
callOptions?: AthenaStorageCallOptions;
|
|
407
457
|
refreshIntervalMs?: number;
|
|
408
458
|
}
|
|
409
459
|
interface UseStorageFilesResult {
|
|
410
|
-
files: StorageListFilesResponse[
|
|
460
|
+
files: StorageListFilesResponse["files"];
|
|
411
461
|
count: number;
|
|
412
462
|
loading: boolean;
|
|
413
463
|
error: unknown;
|
|
@@ -429,4 +479,4 @@ interface UseStorageFileDeleteResult {
|
|
|
429
479
|
}
|
|
430
480
|
declare function useStorageFileDelete(options: UseStorageFileDeleteOptions): UseStorageFileDeleteResult;
|
|
431
481
|
|
|
432
|
-
export { type AthenaCacheMode, type AthenaCachePolicy, AthenaGatewayHookConfig, AthenaGatewayHookResult, type AthenaMutationDefaults, type AthenaMutationEvent, type AthenaMutationRequestLog, type AthenaMutationResultData, type AthenaMutationState, AthenaQueryClient, type AthenaQueryClientConfig, AthenaQueryClientProvider, type AthenaQueryDefaults, type AthenaQueryError, type AthenaQueryEvent, type AthenaQueryRequestLog, type AthenaQueryResult, type AthenaQueryState, type AthenaResponseLike, type AthenaRetryCount, type AthenaRetryDelay, type AthenaRuntimeBaseEvent, type AthenaRuntimeEvent, type AthenaRuntimeEventType, type AthenaStateAdapter, type AthenaUnsubscribe, type QueryKey, type QueryStatus, type UseAthenaReadQueryOptions, type UseAthenaReadQueryResult, type UseAthenaSessionClientOptions, type UseAthenaSessionClientResult, type UseMutationOptions, type UseMutationResult, type UseQueryOptions, type UseQueryResult, type UseSessionAuthClient, type UseSessionOptions, type UseSessionResult, type UseStorageFileDeleteOptions, type UseStorageFileDeleteResult, type UseStorageFilesOptions, type UseStorageFilesResult, type UseStorageUploadInput, type UseStorageUploadOptions, type UseStorageUploadResult, attachStateAdapter, createAthenaQueryClient, useAthenaGateway, useAthenaQueryClient, useAthenaReadQuery, useAthenaSessionClient, useMutation, useQuery, useSession, useStorageFileDelete, useStorageFiles, useStorageUpload };
|
|
482
|
+
export { type AthenaCacheMode, type AthenaCachePolicy, AthenaGatewayHookConfig, AthenaGatewayHookResult, type AthenaMutationDefaults, type AthenaMutationEvent, type AthenaMutationRequestLog, type AthenaMutationResultData, type AthenaMutationState, AthenaQueryClient, type AthenaQueryClientConfig, AthenaQueryClientProvider, type AthenaQueryDefaults, type AthenaQueryError, type AthenaQueryEvent, type AthenaQueryRequestLog, type AthenaQueryResult, type AthenaQueryState, type AthenaResponseLike, type AthenaRetryCount, type AthenaRetryDelay, type AthenaRuntimeBaseEvent, type AthenaRuntimeEvent, type AthenaRuntimeEventType, type AthenaStateAdapter, type AthenaUnsubscribe, type QueryKey, type QueryStatus, type UseAdminPermissionOptions, type UseAdminPermissionResult, type UseAthenaReadQueryOptions, type UseAthenaReadQueryResult, type UseAthenaSessionClientOptions, type UseAthenaSessionClientResult, type UseMutationOptions, type UseMutationResult, type UseQueryOptions, type UseQueryResult, type UseSessionAuthClient, type UseSessionOptions, type UseSessionResult, type UseStorageFileDeleteOptions, type UseStorageFileDeleteResult, type UseStorageFilesOptions, type UseStorageFilesResult, type UseStorageUploadInput, type UseStorageUploadOptions, type UseStorageUploadResult, attachStateAdapter, createAthenaQueryClient, useAdminPermission, useAthenaGateway, useAthenaQueryClient, useAthenaReadQuery, useAthenaSessionClient, useMutation, useQuery, useSession, useStorageFileDelete, useStorageFiles, useStorageUpload };
|
package/dist/react.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { u as AthenaGatewayHookConfig, v as AthenaGatewayHookResult } from './types-Bltx6iL6.js';
|
|
2
2
|
export { w as AthenaDeletePayload, x as AthenaFetchPayload, a as AthenaGatewayCallOptions, d as AthenaGatewayErrorCode, e as AthenaGatewayErrorDetails, s as AthenaGatewayResponse, y as AthenaInsertPayload, f as AthenaJsonArray, g as AthenaJsonObject, h as AthenaJsonPrimitive, i as AthenaJsonValue, j as AthenaRpcCallOptions, k as AthenaRpcFilter, l as AthenaRpcFilterOperator, m as AthenaRpcOrder, n as AthenaRpcPayload, z as AthenaUpdatePayload } from './types-Bltx6iL6.js';
|
|
3
|
-
import { a as AthenaReadQueryClient, c as AthenaReadQueryDefinition, e as AthenaReadQueryExecutionResult, i as AthenaReadQueryFlatRow } from './model-form-
|
|
4
|
-
export { A as AthenaGatewayError, M as ModelFormAdapter, D as ModelFormDefaults, E as ModelFormNullishMode, G as ModelFormValues, T as ToModelFormDefaultsOptions, H as ToModelPayloadOptions, _ as createModelFormAdapter, a3 as isAthenaGatewayError,
|
|
3
|
+
import { a as AthenaReadQueryClient, c as AthenaReadQueryDefinition, e as AthenaReadQueryExecutionResult, i as AthenaReadQueryFlatRow } from './model-form-CotpEL7z.js';
|
|
4
|
+
export { A as AthenaGatewayError, M as ModelFormAdapter, D as ModelFormDefaults, E as ModelFormNullishMode, G as ModelFormValues, T as ToModelFormDefaultsOptions, H as ToModelPayloadOptions, _ as createModelFormAdapter, a3 as isAthenaGatewayError, a7 as toModelFormDefaults, a8 as toModelPayload } from './model-form-CotpEL7z.js';
|
|
5
5
|
import * as react from 'react';
|
|
6
6
|
import { ReactNode } from 'react';
|
|
7
|
-
import { aE as AthenaAuthFetchCompatibleInput, E as AthenaAuthCallOptions, ad as AthenaAuthSessionResponse, R as AthenaAuthErrorDetails, aa as AthenaAuthResult } from './types-
|
|
8
|
-
export { D as AthenaAuthBindings, aC as AuthBindings } from './types-
|
|
9
|
-
import {
|
|
7
|
+
import { aE as AthenaAuthFetchCompatibleInput, E as AthenaAuthCallOptions, ad as AthenaAuthSessionResponse, R as AthenaAuthErrorDetails, aa as AthenaAuthResult, aD as AthenaAdminHasPermissionRequest } from './types-BVKpQmfY.js';
|
|
8
|
+
export { D as AthenaAuthBindings, aC as AuthBindings } from './types-BVKpQmfY.js';
|
|
9
|
+
import { AthenaAdminSessionLike, AthenaAdminPermissionCheckInput } from './admin.js';
|
|
10
|
+
import { ax as AthenaRequestContext, b5 as AthenaStorageFileUploadInput, bp as AthenaStorageUploadSource, bb as AthenaStorageModule, bo as AthenaStorageUploadProgressHandler, bn as AthenaStorageUploadProgress, b8 as AthenaStorageFileUploadResult, aP as AthenaStorageCallOptions, b2 as AthenaStorageFileListInput, ck as StorageListFilesResponse, cf as StorageFileMutationResponse } from './v3-client-ao8BWQ8v.js';
|
|
10
11
|
import './types-B75PdABb.js';
|
|
11
12
|
import './module-C_ab-MM1.js';
|
|
12
13
|
|
|
@@ -230,9 +231,9 @@ declare function createAthenaQueryClient(config?: AthenaQueryClientConfig): Athe
|
|
|
230
231
|
declare function attachStateAdapter(client: AthenaQueryClient, adapter: AthenaStateAdapter): AthenaUnsubscribe;
|
|
231
232
|
|
|
232
233
|
interface AthenaQueryClientProviderProps {
|
|
234
|
+
children: ReactNode;
|
|
233
235
|
client?: AthenaQueryClient;
|
|
234
236
|
config?: AthenaQueryClientConfig;
|
|
235
|
-
children: ReactNode;
|
|
236
237
|
}
|
|
237
238
|
declare function AthenaQueryClientProvider(props: AthenaQueryClientProviderProps): react.FunctionComponentElement<react.ProviderProps<AthenaQueryClient | null>>;
|
|
238
239
|
declare function useAthenaQueryClient(): AthenaQueryClient;
|
|
@@ -354,6 +355,55 @@ type InferSessionData$1<TClient> = TClient extends {
|
|
|
354
355
|
*/
|
|
355
356
|
declare function useSession<TClient extends UseSessionAuthClient>(authClient: TClient, options?: UseSessionOptions): UseSessionResult<InferSessionData$1<TClient>>;
|
|
356
357
|
|
|
358
|
+
interface UseAdminPermissionOptions {
|
|
359
|
+
/**
|
|
360
|
+
* Permission set checked via `client.auth.admin.hasPermission`.
|
|
361
|
+
* Defaults to `["admin:read"]`.
|
|
362
|
+
*/
|
|
363
|
+
permissions?: AthenaAdminHasPermissionRequest['permissions'];
|
|
364
|
+
permission?: AthenaAdminHasPermissionRequest['permission'];
|
|
365
|
+
/**
|
|
366
|
+
* When provided, skips the internal session fetch.
|
|
367
|
+
* Pass `null` to force a denied result without calling getSession.
|
|
368
|
+
*/
|
|
369
|
+
session?: AthenaAdminSessionLike | null;
|
|
370
|
+
allowRoleBypass?: boolean;
|
|
371
|
+
enabled?: boolean;
|
|
372
|
+
fetchOptions?: AthenaAdminPermissionCheckInput['fetchOptions'];
|
|
373
|
+
requestOptions?: AthenaAdminPermissionCheckInput['requestOptions'];
|
|
374
|
+
/** Forwarded to the internal `useSession` when `session` is omitted. */
|
|
375
|
+
sessionOptions?: Omit<UseSessionOptions, 'enabled'>;
|
|
376
|
+
}
|
|
377
|
+
interface UseAdminPermissionResult {
|
|
378
|
+
allowed: boolean;
|
|
379
|
+
isPending: boolean;
|
|
380
|
+
error: Error | null;
|
|
381
|
+
session: AthenaAdminSessionLike | null;
|
|
382
|
+
refetch: () => Promise<boolean>;
|
|
383
|
+
}
|
|
384
|
+
type AdminPermissionAuthClient = UseSessionAuthClient & {
|
|
385
|
+
auth?: {
|
|
386
|
+
admin?: unknown;
|
|
387
|
+
};
|
|
388
|
+
admin?: unknown;
|
|
389
|
+
};
|
|
390
|
+
/**
|
|
391
|
+
* React gate for Athena admin permissions.
|
|
392
|
+
*
|
|
393
|
+
* Uses {@link hasAdminPermission} from `@xylex-group/athena/admin` with an
|
|
394
|
+
* optional local `admin` role short-circuit. When `session` is omitted, loads
|
|
395
|
+
* the current session through {@link useSession}.
|
|
396
|
+
*
|
|
397
|
+
* @example
|
|
398
|
+
* ```tsx
|
|
399
|
+
* const athena = createClient({ url, key, auth: { url: "/api/auth" } })
|
|
400
|
+
* const { allowed, isPending } = useAdminPermission(athena, {
|
|
401
|
+
* permissions: ["admin:read"],
|
|
402
|
+
* })
|
|
403
|
+
* ```
|
|
404
|
+
*/
|
|
405
|
+
declare function useAdminPermission(client: AdminPermissionAuthClient | null | undefined, options?: UseAdminPermissionOptions): UseAdminPermissionResult;
|
|
406
|
+
|
|
357
407
|
type SessionGetter<TSessionData extends AthenaAuthSessionResponse> = (input?: AthenaAuthFetchCompatibleInput, options?: AthenaAuthCallOptions) => Promise<AthenaAuthResult<TSessionData>>;
|
|
358
408
|
type AthenaContextScopedClient<TSessionData extends AthenaAuthSessionResponse = AthenaAuthSessionResponse> = {
|
|
359
409
|
auth: {
|
|
@@ -400,14 +450,14 @@ interface UseStorageUploadResult {
|
|
|
400
450
|
declare function useStorageUpload(options: UseStorageUploadOptions): UseStorageUploadResult;
|
|
401
451
|
|
|
402
452
|
interface UseStorageFilesOptions {
|
|
403
|
-
storage: Pick<AthenaStorageModule,
|
|
453
|
+
storage: Pick<AthenaStorageModule, "file">;
|
|
404
454
|
input: AthenaStorageFileListInput | null | undefined;
|
|
405
455
|
enabled?: boolean;
|
|
406
456
|
callOptions?: AthenaStorageCallOptions;
|
|
407
457
|
refreshIntervalMs?: number;
|
|
408
458
|
}
|
|
409
459
|
interface UseStorageFilesResult {
|
|
410
|
-
files: StorageListFilesResponse[
|
|
460
|
+
files: StorageListFilesResponse["files"];
|
|
411
461
|
count: number;
|
|
412
462
|
loading: boolean;
|
|
413
463
|
error: unknown;
|
|
@@ -429,4 +479,4 @@ interface UseStorageFileDeleteResult {
|
|
|
429
479
|
}
|
|
430
480
|
declare function useStorageFileDelete(options: UseStorageFileDeleteOptions): UseStorageFileDeleteResult;
|
|
431
481
|
|
|
432
|
-
export { type AthenaCacheMode, type AthenaCachePolicy, AthenaGatewayHookConfig, AthenaGatewayHookResult, type AthenaMutationDefaults, type AthenaMutationEvent, type AthenaMutationRequestLog, type AthenaMutationResultData, type AthenaMutationState, AthenaQueryClient, type AthenaQueryClientConfig, AthenaQueryClientProvider, type AthenaQueryDefaults, type AthenaQueryError, type AthenaQueryEvent, type AthenaQueryRequestLog, type AthenaQueryResult, type AthenaQueryState, type AthenaResponseLike, type AthenaRetryCount, type AthenaRetryDelay, type AthenaRuntimeBaseEvent, type AthenaRuntimeEvent, type AthenaRuntimeEventType, type AthenaStateAdapter, type AthenaUnsubscribe, type QueryKey, type QueryStatus, type UseAthenaReadQueryOptions, type UseAthenaReadQueryResult, type UseAthenaSessionClientOptions, type UseAthenaSessionClientResult, type UseMutationOptions, type UseMutationResult, type UseQueryOptions, type UseQueryResult, type UseSessionAuthClient, type UseSessionOptions, type UseSessionResult, type UseStorageFileDeleteOptions, type UseStorageFileDeleteResult, type UseStorageFilesOptions, type UseStorageFilesResult, type UseStorageUploadInput, type UseStorageUploadOptions, type UseStorageUploadResult, attachStateAdapter, createAthenaQueryClient, useAthenaGateway, useAthenaQueryClient, useAthenaReadQuery, useAthenaSessionClient, useMutation, useQuery, useSession, useStorageFileDelete, useStorageFiles, useStorageUpload };
|
|
482
|
+
export { type AthenaCacheMode, type AthenaCachePolicy, AthenaGatewayHookConfig, AthenaGatewayHookResult, type AthenaMutationDefaults, type AthenaMutationEvent, type AthenaMutationRequestLog, type AthenaMutationResultData, type AthenaMutationState, AthenaQueryClient, type AthenaQueryClientConfig, AthenaQueryClientProvider, type AthenaQueryDefaults, type AthenaQueryError, type AthenaQueryEvent, type AthenaQueryRequestLog, type AthenaQueryResult, type AthenaQueryState, type AthenaResponseLike, type AthenaRetryCount, type AthenaRetryDelay, type AthenaRuntimeBaseEvent, type AthenaRuntimeEvent, type AthenaRuntimeEventType, type AthenaStateAdapter, type AthenaUnsubscribe, type QueryKey, type QueryStatus, type UseAdminPermissionOptions, type UseAdminPermissionResult, type UseAthenaReadQueryOptions, type UseAthenaReadQueryResult, type UseAthenaSessionClientOptions, type UseAthenaSessionClientResult, type UseMutationOptions, type UseMutationResult, type UseQueryOptions, type UseQueryResult, type UseSessionAuthClient, type UseSessionOptions, type UseSessionResult, type UseStorageFileDeleteOptions, type UseStorageFileDeleteResult, type UseStorageFilesOptions, type UseStorageFilesResult, type UseStorageUploadInput, type UseStorageUploadOptions, type UseStorageUploadResult, attachStateAdapter, createAthenaQueryClient, useAdminPermission, useAthenaGateway, useAthenaQueryClient, useAthenaReadQuery, useAthenaSessionClient, useMutation, useQuery, useSession, useStorageFileDelete, useStorageFiles, useStorageUpload };
|
package/dist/react.js
CHANGED
|
@@ -392,7 +392,7 @@ function buildAthenaRequestHeaders(input) {
|
|
|
392
392
|
|
|
393
393
|
// package.json
|
|
394
394
|
var package_default = {
|
|
395
|
-
version: "3.
|
|
395
|
+
version: "3.3.0"
|
|
396
396
|
};
|
|
397
397
|
|
|
398
398
|
// src/sdk-version.ts
|
|
@@ -1043,7 +1043,8 @@ function stableSerialize(value, seen) {
|
|
|
1043
1043
|
if (value === void 0) return "undefined";
|
|
1044
1044
|
const valueType = typeof value;
|
|
1045
1045
|
if (valueType === "string") return `"${value}"`;
|
|
1046
|
-
if (valueType === "number")
|
|
1046
|
+
if (valueType === "number")
|
|
1047
|
+
return Number.isFinite(value) ? String(value) : "null";
|
|
1047
1048
|
if (valueType === "boolean") return value ? "true" : "false";
|
|
1048
1049
|
if (valueType === "bigint") return `${String(value)}n`;
|
|
1049
1050
|
if (valueType === "symbol") return `symbol:${String(value)}`;
|
|
@@ -1124,7 +1125,8 @@ async function runWithRetry(execute, options) {
|
|
|
1124
1125
|
}
|
|
1125
1126
|
function errorMessageFromUnknown(error) {
|
|
1126
1127
|
if (typeof error === "string" && error.trim()) return error.trim();
|
|
1127
|
-
if (error instanceof Error && error.message.trim())
|
|
1128
|
+
if (error instanceof Error && error.message.trim())
|
|
1129
|
+
return error.message.trim();
|
|
1128
1130
|
if (isRecord2(error)) {
|
|
1129
1131
|
const messageCandidate = error.message ?? error.error;
|
|
1130
1132
|
if (typeof messageCandidate === "string" && messageCandidate.trim()) {
|
|
@@ -1343,7 +1345,11 @@ var AthenaQueryClient = class {
|
|
|
1343
1345
|
const key = this.getMutationKeyToken(mutationKey);
|
|
1344
1346
|
const entry = this.ensureMutationEntry(key);
|
|
1345
1347
|
entry.activeRequestId = ++this.requestCounter;
|
|
1346
|
-
this.setMutationState(
|
|
1348
|
+
this.setMutationState(
|
|
1349
|
+
entry,
|
|
1350
|
+
createInitialMutationState(),
|
|
1351
|
+
"mutation_reset"
|
|
1352
|
+
);
|
|
1347
1353
|
}
|
|
1348
1354
|
async executeQuery(input) {
|
|
1349
1355
|
const entry = this.ensureQueryEntry(input.queryKeyToken);
|
|
@@ -1405,7 +1411,10 @@ var AthenaQueryClient = class {
|
|
|
1405
1411
|
);
|
|
1406
1412
|
}
|
|
1407
1413
|
const rawResult = await input.queryFn();
|
|
1408
|
-
const normalized = normalizeAthenaResult(
|
|
1414
|
+
const normalized = normalizeAthenaResult(
|
|
1415
|
+
rawResult,
|
|
1416
|
+
input.select
|
|
1417
|
+
);
|
|
1409
1418
|
if (normalized.error) {
|
|
1410
1419
|
throw {
|
|
1411
1420
|
__athenaNormalizedError: normalized.error,
|
|
@@ -1493,7 +1502,10 @@ var AthenaQueryClient = class {
|
|
|
1493
1502
|
this.inflightQueries.delete(input.queryKeyToken);
|
|
1494
1503
|
}
|
|
1495
1504
|
});
|
|
1496
|
-
this.inflightQueries.set(
|
|
1505
|
+
this.inflightQueries.set(
|
|
1506
|
+
input.queryKeyToken,
|
|
1507
|
+
executionPromise
|
|
1508
|
+
);
|
|
1497
1509
|
return executionPromise;
|
|
1498
1510
|
}
|
|
1499
1511
|
async executeMutation(input) {
|
|
@@ -1539,7 +1551,10 @@ var AthenaQueryClient = class {
|
|
|
1539
1551
|
);
|
|
1540
1552
|
}
|
|
1541
1553
|
const rawResult = await input.mutationFn(input.variables);
|
|
1542
|
-
const normalized = normalizeAthenaResult(
|
|
1554
|
+
const normalized = normalizeAthenaResult(
|
|
1555
|
+
rawResult,
|
|
1556
|
+
input.select
|
|
1557
|
+
);
|
|
1543
1558
|
if (normalized.error) {
|
|
1544
1559
|
throw {
|
|
1545
1560
|
__athenaNormalizedError: normalized.error,
|
|
@@ -2164,12 +2179,6 @@ function applyAthenaReadQuerySelectOrder(queryBuilder, orderBy) {
|
|
|
2164
2179
|
queryBuilder
|
|
2165
2180
|
);
|
|
2166
2181
|
}
|
|
2167
|
-
function applyAthenaReadQuerySelectLimit(queryBuilder, limit) {
|
|
2168
|
-
if (!limit || limit < 1) {
|
|
2169
|
-
return queryBuilder;
|
|
2170
|
-
}
|
|
2171
|
-
return queryBuilder.limit(limit);
|
|
2172
|
-
}
|
|
2173
2182
|
function clampAthenaReadQueryTotalItems(totalItems, limit) {
|
|
2174
2183
|
if (!limit || limit < 1) {
|
|
2175
2184
|
return totalItems;
|
|
@@ -2202,6 +2211,27 @@ function resolveTotalItemsFromPage({
|
|
|
2202
2211
|
}
|
|
2203
2212
|
return clampAthenaReadQueryTotalItems(exactCount, limit);
|
|
2204
2213
|
}
|
|
2214
|
+
function resolveAthenaReadQueryPageFetch({
|
|
2215
|
+
page,
|
|
2216
|
+
pageSize,
|
|
2217
|
+
limit
|
|
2218
|
+
}) {
|
|
2219
|
+
const safePage = Math.max(1, Math.trunc(page) || 1);
|
|
2220
|
+
const safePageSize = Math.max(1, Math.trunc(pageSize) || 1);
|
|
2221
|
+
if (!limit || limit < 1) {
|
|
2222
|
+
return { page: safePage, pageSize: safePageSize, shouldFetch: true };
|
|
2223
|
+
}
|
|
2224
|
+
const totalCap = Math.trunc(limit);
|
|
2225
|
+
const offset = (safePage - 1) * safePageSize;
|
|
2226
|
+
if (offset >= totalCap) {
|
|
2227
|
+
return { page: safePage, pageSize: safePageSize, shouldFetch: false };
|
|
2228
|
+
}
|
|
2229
|
+
return {
|
|
2230
|
+
page: safePage,
|
|
2231
|
+
pageSize: Math.min(safePageSize, totalCap - offset),
|
|
2232
|
+
shouldFetch: true
|
|
2233
|
+
};
|
|
2234
|
+
}
|
|
2205
2235
|
async function executeAthenaReadQuery({
|
|
2206
2236
|
client,
|
|
2207
2237
|
page,
|
|
@@ -2220,15 +2250,29 @@ async function executeAthenaReadQuery({
|
|
|
2220
2250
|
count: "exact",
|
|
2221
2251
|
head: true
|
|
2222
2252
|
});
|
|
2253
|
+
const pageFetch = resolveAthenaReadQueryPageFetch({
|
|
2254
|
+
limit: query.limit,
|
|
2255
|
+
page,
|
|
2256
|
+
pageSize
|
|
2257
|
+
});
|
|
2258
|
+
if (!pageFetch.shouldFetch) {
|
|
2259
|
+
return {
|
|
2260
|
+
rows: [],
|
|
2261
|
+
totalItems: resolveTotalItemsFromPage({
|
|
2262
|
+
countCandidates: [countResult.count],
|
|
2263
|
+
limit: query.limit,
|
|
2264
|
+
page: pageFetch.page,
|
|
2265
|
+
pageSize,
|
|
2266
|
+
rowCount: 0
|
|
2267
|
+
})
|
|
2268
|
+
};
|
|
2269
|
+
}
|
|
2223
2270
|
if ((query.mode ?? "findMany") === "select") {
|
|
2224
|
-
const selectBuilder =
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
query.orderBy
|
|
2228
|
-
),
|
|
2229
|
-
query.limit
|
|
2271
|
+
const selectBuilder = applyAthenaReadQuerySelectOrder(
|
|
2272
|
+
applyAthenaReadQueryFilters(baseBuilder, query.filters),
|
|
2273
|
+
query.orderBy
|
|
2230
2274
|
);
|
|
2231
|
-
const result2 = await selectBuilder.currentPage(page).pageSize(pageSize).select(buildAthenaReadQuerySelectString(query.columns), {
|
|
2275
|
+
const result2 = await selectBuilder.currentPage(pageFetch.page).pageSize(pageFetch.pageSize).select(buildAthenaReadQuerySelectString(query.columns), {
|
|
2232
2276
|
count: "exact"
|
|
2233
2277
|
});
|
|
2234
2278
|
const rows2 = flattenAthenaReadQueryRows(
|
|
@@ -2242,7 +2286,7 @@ async function executeAthenaReadQuery({
|
|
|
2242
2286
|
totalItems: resolveTotalItemsFromPage({
|
|
2243
2287
|
countCandidates: [countResult.count, result2.count],
|
|
2244
2288
|
limit: query.limit,
|
|
2245
|
-
page,
|
|
2289
|
+
page: pageFetch.page,
|
|
2246
2290
|
pageSize,
|
|
2247
2291
|
rowCount: rows2.length
|
|
2248
2292
|
})
|
|
@@ -2250,12 +2294,11 @@ async function executeAthenaReadQuery({
|
|
|
2250
2294
|
}
|
|
2251
2295
|
const findManyOrderBy = buildAthenaReadQueryFindManyOrderBy(query.orderBy);
|
|
2252
2296
|
const findManyOptions = {
|
|
2253
|
-
...query.limit ? { limit: query.limit } : {},
|
|
2254
2297
|
...findManyOrderBy ? { orderBy: findManyOrderBy } : {},
|
|
2255
2298
|
select: buildAthenaReadQueryFindManySelect(query.columns),
|
|
2256
2299
|
...query.filters?.length ? { where: buildAthenaReadQueryFindManyWhere(query.filters) } : {}
|
|
2257
2300
|
};
|
|
2258
|
-
const result = await baseBuilder.currentPage(page).pageSize(pageSize).findMany(findManyOptions);
|
|
2301
|
+
const result = await baseBuilder.currentPage(pageFetch.page).pageSize(pageFetch.pageSize).findMany(findManyOptions);
|
|
2259
2302
|
const rows = flattenAthenaReadQueryRows(
|
|
2260
2303
|
Array.isArray(result.data) ? result.data : [],
|
|
2261
2304
|
query.columns,
|
|
@@ -2267,7 +2310,7 @@ async function executeAthenaReadQuery({
|
|
|
2267
2310
|
totalItems: resolveTotalItemsFromPage({
|
|
2268
2311
|
countCandidates: [countResult.count, result.count],
|
|
2269
2312
|
limit: query.limit,
|
|
2270
|
-
page,
|
|
2313
|
+
page: pageFetch.page,
|
|
2271
2314
|
pageSize,
|
|
2272
2315
|
rowCount: rows.length
|
|
2273
2316
|
})
|
|
@@ -2379,7 +2422,16 @@ function resolveGetSession(authClient) {
|
|
|
2379
2422
|
if ("auth" in authClient && authClient.auth && typeof authClient.auth.getSession === "function") {
|
|
2380
2423
|
return authClient.auth.getSession;
|
|
2381
2424
|
}
|
|
2382
|
-
throw new Error(
|
|
2425
|
+
throw new Error(
|
|
2426
|
+
"useSession requires an auth-capable client (createClient(...).auth)"
|
|
2427
|
+
);
|
|
2428
|
+
}
|
|
2429
|
+
function toFallbackErrorDetails(code, message, status) {
|
|
2430
|
+
return {
|
|
2431
|
+
code,
|
|
2432
|
+
message,
|
|
2433
|
+
status
|
|
2434
|
+
};
|
|
2383
2435
|
}
|
|
2384
2436
|
function useSession(authClient, options = {}) {
|
|
2385
2437
|
const enabled = options.enabled ?? true;
|
|
@@ -2397,11 +2449,6 @@ function useSession(authClient, options = {}) {
|
|
|
2397
2449
|
useEffect(() => {
|
|
2398
2450
|
dataRef.current = data;
|
|
2399
2451
|
}, [data]);
|
|
2400
|
-
const toFallbackErrorDetails = (code, message, status) => ({
|
|
2401
|
-
code,
|
|
2402
|
-
message,
|
|
2403
|
-
status
|
|
2404
|
-
});
|
|
2405
2452
|
const runFetch = useCallback(async () => {
|
|
2406
2453
|
const requestId = ++requestIdRef.current;
|
|
2407
2454
|
const hasData = dataRef.current !== null;
|
|
@@ -2464,6 +2511,211 @@ function useSession(authClient, options = {}) {
|
|
|
2464
2511
|
refetch
|
|
2465
2512
|
};
|
|
2466
2513
|
}
|
|
2514
|
+
|
|
2515
|
+
// src/admin/index.ts
|
|
2516
|
+
function resolveAdminPermissionClient(client) {
|
|
2517
|
+
if (!client || typeof client !== "object") {
|
|
2518
|
+
return null;
|
|
2519
|
+
}
|
|
2520
|
+
const record = client;
|
|
2521
|
+
const nestedAuth = record.auth;
|
|
2522
|
+
if (nestedAuth && typeof nestedAuth === "object" && nestedAuth !== null && "admin" in nestedAuth) {
|
|
2523
|
+
return client;
|
|
2524
|
+
}
|
|
2525
|
+
if ("admin" in record) {
|
|
2526
|
+
return { auth: client };
|
|
2527
|
+
}
|
|
2528
|
+
return null;
|
|
2529
|
+
}
|
|
2530
|
+
function buildAdminAuthFetchOptions(credentials = {}) {
|
|
2531
|
+
const cookie = credentials.cookie?.trim() || void 0;
|
|
2532
|
+
const bearerToken = credentials.bearerToken?.trim() || void 0;
|
|
2533
|
+
const headers = {};
|
|
2534
|
+
if (cookie) {
|
|
2535
|
+
headers.cookie = cookie;
|
|
2536
|
+
}
|
|
2537
|
+
if (bearerToken) {
|
|
2538
|
+
headers.authorization = `Bearer ${bearerToken}`;
|
|
2539
|
+
}
|
|
2540
|
+
return {
|
|
2541
|
+
credentials: "include",
|
|
2542
|
+
...bearerToken ? { bearerToken } : {},
|
|
2543
|
+
...Object.keys(headers).length > 0 ? { headers } : {}
|
|
2544
|
+
};
|
|
2545
|
+
}
|
|
2546
|
+
function hasAdminRole(session) {
|
|
2547
|
+
const role = session?.user?.role;
|
|
2548
|
+
if (!role) {
|
|
2549
|
+
return false;
|
|
2550
|
+
}
|
|
2551
|
+
return role.split(",").map((item) => item.trim().toLowerCase()).includes("admin");
|
|
2552
|
+
}
|
|
2553
|
+
function mergeAdminFetchOptions(input) {
|
|
2554
|
+
const fromCredentials = input.credentials ? buildAdminAuthFetchOptions(input.credentials) : void 0;
|
|
2555
|
+
const explicit = input.fetchOptions;
|
|
2556
|
+
if (!fromCredentials && !explicit) {
|
|
2557
|
+
return void 0;
|
|
2558
|
+
}
|
|
2559
|
+
if (!fromCredentials) {
|
|
2560
|
+
return explicit;
|
|
2561
|
+
}
|
|
2562
|
+
if (!explicit) {
|
|
2563
|
+
return fromCredentials;
|
|
2564
|
+
}
|
|
2565
|
+
return {
|
|
2566
|
+
...fromCredentials,
|
|
2567
|
+
...explicit,
|
|
2568
|
+
headers: {
|
|
2569
|
+
...fromCredentials.headers ?? {},
|
|
2570
|
+
...explicit.headers ?? {}
|
|
2571
|
+
}
|
|
2572
|
+
};
|
|
2573
|
+
}
|
|
2574
|
+
async function hasAdminPermission(client, input) {
|
|
2575
|
+
if (!input.session?.user?.id) {
|
|
2576
|
+
return false;
|
|
2577
|
+
}
|
|
2578
|
+
if (input.allowRoleBypass !== false && hasAdminRole(input.session)) {
|
|
2579
|
+
return true;
|
|
2580
|
+
}
|
|
2581
|
+
const fetchOptions = mergeAdminFetchOptions(input);
|
|
2582
|
+
const result = await client.auth.admin.hasPermission(
|
|
2583
|
+
{
|
|
2584
|
+
permission: input.permission,
|
|
2585
|
+
permissions: input.permissions,
|
|
2586
|
+
...fetchOptions ? { fetchOptions } : {}
|
|
2587
|
+
},
|
|
2588
|
+
input.requestOptions
|
|
2589
|
+
);
|
|
2590
|
+
return Boolean(result.ok && result.data?.success);
|
|
2591
|
+
}
|
|
2592
|
+
|
|
2593
|
+
// src/react/use-admin-permission.ts
|
|
2594
|
+
var DEFAULT_ADMIN_PERMISSIONS = [
|
|
2595
|
+
"admin:read"
|
|
2596
|
+
];
|
|
2597
|
+
function serializePermissions(permissions, permission) {
|
|
2598
|
+
return JSON.stringify({
|
|
2599
|
+
permission: permission ?? null,
|
|
2600
|
+
permissions: permissions ?? DEFAULT_ADMIN_PERMISSIONS
|
|
2601
|
+
});
|
|
2602
|
+
}
|
|
2603
|
+
function useAdminPermission(client, options = {}) {
|
|
2604
|
+
const enabled = options.enabled ?? true;
|
|
2605
|
+
const sessionProvided = "session" in options;
|
|
2606
|
+
const sessionFromOptions = sessionProvided ? options.session ?? null : void 0;
|
|
2607
|
+
const permissionsKey = serializePermissions(options.permissions, options.permission);
|
|
2608
|
+
const allowRoleBypass = options.allowRoleBypass;
|
|
2609
|
+
const fetchOptions = options.fetchOptions;
|
|
2610
|
+
const requestOptions = options.requestOptions;
|
|
2611
|
+
const optionsRef = useRef(options);
|
|
2612
|
+
optionsRef.current = options;
|
|
2613
|
+
const sessionState = useSession(client, {
|
|
2614
|
+
...options.sessionOptions,
|
|
2615
|
+
enabled: enabled && !sessionProvided && !!client
|
|
2616
|
+
});
|
|
2617
|
+
const session = sessionProvided ? sessionFromOptions ?? null : sessionState.data;
|
|
2618
|
+
const sessionPending = !sessionProvided && sessionState.isPending;
|
|
2619
|
+
const sessionUserId = session?.user?.id ?? null;
|
|
2620
|
+
const sessionRole = session?.user?.role ?? null;
|
|
2621
|
+
const [allowed, setAllowed] = useState(false);
|
|
2622
|
+
const [error, setError] = useState(null);
|
|
2623
|
+
const [isChecking, setIsChecking] = useState(enabled);
|
|
2624
|
+
const requestIdRef = useRef(0);
|
|
2625
|
+
const mountedRef = useRef(true);
|
|
2626
|
+
const runCheck = useCallback(async () => {
|
|
2627
|
+
const requestId = ++requestIdRef.current;
|
|
2628
|
+
const current = optionsRef.current;
|
|
2629
|
+
const permissions = current.permissions ?? DEFAULT_ADMIN_PERMISSIONS;
|
|
2630
|
+
if (!enabled || !client) {
|
|
2631
|
+
if (mountedRef.current && requestId === requestIdRef.current) {
|
|
2632
|
+
setAllowed(false);
|
|
2633
|
+
setError(null);
|
|
2634
|
+
setIsChecking(false);
|
|
2635
|
+
}
|
|
2636
|
+
return false;
|
|
2637
|
+
}
|
|
2638
|
+
setIsChecking(true);
|
|
2639
|
+
try {
|
|
2640
|
+
const permissionClient = resolveAdminPermissionClient(client);
|
|
2641
|
+
if (!permissionClient) {
|
|
2642
|
+
throw new Error(
|
|
2643
|
+
"useAdminPermission requires an Athena client with auth.admin (createClient(...) or auth bindings)"
|
|
2644
|
+
);
|
|
2645
|
+
}
|
|
2646
|
+
const resolvedSession = sessionProvided ? current.session ?? null : sessionState.data;
|
|
2647
|
+
const nextAllowed = await hasAdminPermission(permissionClient, {
|
|
2648
|
+
session: resolvedSession,
|
|
2649
|
+
permissions,
|
|
2650
|
+
permission: current.permission,
|
|
2651
|
+
allowRoleBypass: current.allowRoleBypass,
|
|
2652
|
+
fetchOptions: current.fetchOptions,
|
|
2653
|
+
requestOptions: current.requestOptions
|
|
2654
|
+
});
|
|
2655
|
+
if (!mountedRef.current || requestId !== requestIdRef.current) {
|
|
2656
|
+
return nextAllowed;
|
|
2657
|
+
}
|
|
2658
|
+
setAllowed(nextAllowed);
|
|
2659
|
+
setError(null);
|
|
2660
|
+
return nextAllowed;
|
|
2661
|
+
} catch (checkError) {
|
|
2662
|
+
if (!mountedRef.current || requestId !== requestIdRef.current) {
|
|
2663
|
+
return false;
|
|
2664
|
+
}
|
|
2665
|
+
const nextError = checkError instanceof Error ? checkError : new Error("Failed to resolve admin permission");
|
|
2666
|
+
setAllowed(false);
|
|
2667
|
+
setError(nextError);
|
|
2668
|
+
return false;
|
|
2669
|
+
} finally {
|
|
2670
|
+
if (mountedRef.current && requestId === requestIdRef.current) {
|
|
2671
|
+
setIsChecking(false);
|
|
2672
|
+
}
|
|
2673
|
+
}
|
|
2674
|
+
}, [client, enabled, sessionProvided, sessionState.data]);
|
|
2675
|
+
useEffect(() => {
|
|
2676
|
+
mountedRef.current = true;
|
|
2677
|
+
return () => {
|
|
2678
|
+
mountedRef.current = false;
|
|
2679
|
+
};
|
|
2680
|
+
}, []);
|
|
2681
|
+
useEffect(() => {
|
|
2682
|
+
if (!enabled) {
|
|
2683
|
+
setAllowed(false);
|
|
2684
|
+
setError(null);
|
|
2685
|
+
setIsChecking(false);
|
|
2686
|
+
return;
|
|
2687
|
+
}
|
|
2688
|
+
if (!sessionProvided && sessionState.isPending) {
|
|
2689
|
+
setIsChecking(true);
|
|
2690
|
+
return;
|
|
2691
|
+
}
|
|
2692
|
+
void runCheck();
|
|
2693
|
+
}, [
|
|
2694
|
+
allowRoleBypass,
|
|
2695
|
+
enabled,
|
|
2696
|
+
fetchOptions,
|
|
2697
|
+
permissionsKey,
|
|
2698
|
+
requestOptions,
|
|
2699
|
+
runCheck,
|
|
2700
|
+
sessionPending,
|
|
2701
|
+
sessionProvided,
|
|
2702
|
+
sessionRole,
|
|
2703
|
+
sessionUserId
|
|
2704
|
+
]);
|
|
2705
|
+
const refetch = useCallback(async () => {
|
|
2706
|
+
if (!sessionProvided) {
|
|
2707
|
+
await sessionState.refetch();
|
|
2708
|
+
}
|
|
2709
|
+
return await runCheck();
|
|
2710
|
+
}, [runCheck, sessionProvided, sessionState]);
|
|
2711
|
+
return {
|
|
2712
|
+
allowed,
|
|
2713
|
+
isPending: enabled && (sessionPending || isChecking),
|
|
2714
|
+
error,
|
|
2715
|
+
session,
|
|
2716
|
+
refetch
|
|
2717
|
+
};
|
|
2718
|
+
}
|
|
2467
2719
|
function useAthenaSessionClient(baseClient, options = {}) {
|
|
2468
2720
|
const sessionState = useSession(baseClient, options);
|
|
2469
2721
|
const scopedClient = useMemo(
|
|
@@ -2568,7 +2820,13 @@ function isStorageUploadInput(input) {
|
|
|
2568
2820
|
return Boolean(input) && typeof input === "object" && "files" in input && "s3_id" in input;
|
|
2569
2821
|
}
|
|
2570
2822
|
function useStorageFiles(options) {
|
|
2571
|
-
const {
|
|
2823
|
+
const {
|
|
2824
|
+
storage,
|
|
2825
|
+
input,
|
|
2826
|
+
enabled = true,
|
|
2827
|
+
callOptions,
|
|
2828
|
+
refreshIntervalMs
|
|
2829
|
+
} = options;
|
|
2572
2830
|
const [data, setData] = React.useState(null);
|
|
2573
2831
|
const [loading, setLoading] = React.useState(false);
|
|
2574
2832
|
const [error, setError] = React.useState(null);
|
|
@@ -2721,6 +2979,6 @@ function createModelFormAdapter(model) {
|
|
|
2721
2979
|
};
|
|
2722
2980
|
}
|
|
2723
2981
|
|
|
2724
|
-
export { AthenaGatewayError, AthenaQueryClient, AthenaQueryClientProvider, attachStateAdapter, createAthenaQueryClient, createModelFormAdapter, isAthenaGatewayError, toModelFormDefaults, toModelPayload, useAthenaGateway, useAthenaQueryClient, useAthenaReadQuery, useAthenaSessionClient, useMutation, useQuery, useSession, useStorageFileDelete, useStorageFiles, useStorageUpload };
|
|
2982
|
+
export { AthenaGatewayError, AthenaQueryClient, AthenaQueryClientProvider, attachStateAdapter, createAthenaQueryClient, createModelFormAdapter, isAthenaGatewayError, toModelFormDefaults, toModelPayload, useAdminPermission, useAthenaGateway, useAthenaQueryClient, useAthenaReadQuery, useAthenaSessionClient, useMutation, useQuery, useSession, useStorageFileDelete, useStorageFiles, useStorageUpload };
|
|
2725
2983
|
//# sourceMappingURL=react.js.map
|
|
2726
2984
|
//# sourceMappingURL=react.js.map
|