@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.
Files changed (82) hide show
  1. package/README.md +1 -1
  2. package/dist/admin.cjs +55 -1
  3. package/dist/admin.cjs.map +1 -1
  4. package/dist/admin.d.cts +32 -8
  5. package/dist/admin.d.ts +32 -8
  6. package/dist/admin.js +54 -2
  7. package/dist/admin.js.map +1 -1
  8. package/dist/athena-auth-url-C1FbVmN6.d.cts +200 -0
  9. package/dist/athena-auth-url-C1FbVmN6.d.ts +200 -0
  10. package/dist/{athena-request-headers-C7Jy-c_D.d.ts → athena-request-headers-DzimbvOA.d.ts} +48 -200
  11. package/dist/{athena-request-headers-DujFFyMU.d.cts → athena-request-headers-Lr_m8xCV.d.cts} +48 -200
  12. package/dist/billing.cjs +1 -1
  13. package/dist/billing.cjs.map +1 -1
  14. package/dist/billing.js +1 -1
  15. package/dist/billing.js.map +1 -1
  16. package/dist/browser.cjs +602 -16
  17. package/dist/browser.cjs.map +1 -1
  18. package/dist/browser.d.cts +8 -7
  19. package/dist/browser.d.ts +8 -7
  20. package/dist/browser.js +593 -17
  21. package/dist/browser.js.map +1 -1
  22. package/dist/cli/index.cjs +141 -6
  23. package/dist/cli/index.cjs.map +1 -1
  24. package/dist/cli/index.d.cts +2 -2
  25. package/dist/cli/index.d.ts +2 -2
  26. package/dist/cli/index.js +141 -6
  27. package/dist/cli/index.js.map +1 -1
  28. package/dist/env.cjs +130 -0
  29. package/dist/env.cjs.map +1 -0
  30. package/dist/env.d.cts +70 -0
  31. package/dist/env.d.ts +70 -0
  32. package/dist/env.js +122 -0
  33. package/dist/env.js.map +1 -0
  34. package/dist/index.cjs +624 -19
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +8 -7
  37. package/dist/index.d.ts +8 -7
  38. package/dist/index.js +615 -20
  39. package/dist/index.js.map +1 -1
  40. package/dist/{model-form-BhWWsA-7.d.cts → model-form-3Gr8rkdT.d.cts} +24 -2
  41. package/dist/{model-form-BbdzJ9Uh.d.ts → model-form-CotpEL7z.d.ts} +24 -2
  42. package/dist/{module-xFd7_Igv.d.cts → module-CQmOaDzP.d.cts} +4 -4
  43. package/dist/{module-DKkJKOuJ.d.ts → module-CWkUTcUc.d.ts} +4 -4
  44. package/dist/next/client.cjs +123 -7
  45. package/dist/next/client.cjs.map +1 -1
  46. package/dist/next/client.d.cts +4 -3
  47. package/dist/next/client.d.ts +4 -3
  48. package/dist/next/client.js +123 -7
  49. package/dist/next/client.js.map +1 -1
  50. package/dist/next/server.cjs +1130 -364
  51. package/dist/next/server.cjs.map +1 -1
  52. package/dist/next/server.d.cts +121 -8
  53. package/dist/next/server.d.ts +121 -8
  54. package/dist/next/server.js +1120 -365
  55. package/dist/next/server.js.map +1 -1
  56. package/dist/{pipeline-DuKzYGia.d.cts → pipeline-BnRKO_Pd.d.cts} +1 -1
  57. package/dist/{pipeline-wer2G9xW.d.ts → pipeline-sWCmlFqu.d.ts} +1 -1
  58. package/dist/{proxy-request-headers-m4D2Tduy.d.ts → proxy-request-headers-CttlcuRb.d.ts} +1 -1
  59. package/dist/{proxy-request-headers-DGxdoyA0.d.cts → proxy-request-headers-pIBSn1Fw.d.cts} +1 -1
  60. package/dist/react.cjs +290 -31
  61. package/dist/react.cjs.map +1 -1
  62. package/dist/react.d.cts +59 -9
  63. package/dist/react.d.ts +59 -9
  64. package/dist/react.js +290 -32
  65. package/dist/react.js.map +1 -1
  66. package/dist/schema-handlers-BtT_IQFi.d.cts +138 -0
  67. package/dist/schema-handlers-VjFDhIMw.d.ts +138 -0
  68. package/dist/social-providers.d.cts +1 -1
  69. package/dist/social-providers.d.ts +1 -1
  70. package/dist/{types-CccOiXPo.d.ts → types-BDX8zS7w.d.ts} +12 -0
  71. package/dist/{types-AOY-GLu8.d.cts → types-BVKpQmfY.d.cts} +11 -0
  72. package/dist/{types-AOY-GLu8.d.ts → types-BVKpQmfY.d.ts} +11 -0
  73. package/dist/{types-1ztXDgPa.d.cts → types-D-Am7YSd.d.cts} +12 -0
  74. package/dist/utils.cjs +30 -0
  75. package/dist/utils.cjs.map +1 -1
  76. package/dist/utils.d.cts +3 -2
  77. package/dist/utils.d.ts +3 -2
  78. package/dist/utils.js +30 -1
  79. package/dist/utils.js.map +1 -1
  80. package/dist/{v3-client-CWfZHcKL.d.cts → v3-client-G1SLeHRa.d.cts} +23 -1
  81. package/dist/{v3-client-DZp2NEhK.d.ts → v3-client-ao8BWQ8v.d.ts} +23 -1
  82. package/package.json +16 -2
@@ -1,4 +1,4 @@
1
- import { b as GeneratorProviderConfig, a as LoadedGeneratorConfig, R as RunGeneratorOptions, d as RunGeneratorResult } from './types-1ztXDgPa.cjs';
1
+ import { b as GeneratorProviderConfig, a as LoadedGeneratorConfig, R as RunGeneratorOptions, d as RunGeneratorResult } from './types-D-Am7YSd.cjs';
2
2
 
3
3
  type GeneratorConfigFileAction = 'created' | 'updated' | 'unchanged' | 'skipped';
4
4
  type GeneratorConfigProviderMode = 'direct' | 'gateway' | 'auto';
@@ -1,4 +1,4 @@
1
- import { b as GeneratorProviderConfig, a as LoadedGeneratorConfig, R as RunGeneratorOptions, d as RunGeneratorResult } from './types-CccOiXPo.js';
1
+ import { b as GeneratorProviderConfig, a as LoadedGeneratorConfig, R as RunGeneratorOptions, d as RunGeneratorResult } from './types-BDX8zS7w.js';
2
2
 
3
3
  type GeneratorConfigFileAction = 'created' | 'updated' | 'unchanged' | 'skipped';
4
4
  type GeneratorConfigProviderMode = 'direct' | 'gateway' | 'auto';
@@ -1,4 +1,4 @@
1
- import { I as EnvLike } from './athena-request-headers-C7Jy-c_D.js';
1
+ import { E as EnvLike } from './athena-auth-url-C1FbVmN6.js';
2
2
 
3
3
  /**
4
4
  * Request header / Next.js helpers used by middleware and RSC session loaders.
@@ -1,4 +1,4 @@
1
- import { I as EnvLike } from './athena-request-headers-DujFFyMU.cjs';
1
+ import { E as EnvLike } from './athena-auth-url-C1FbVmN6.cjs';
2
2
 
3
3
  /**
4
4
  * Request header / Next.js helpers used by middleware and RSC session loaders.
package/dist/react.cjs CHANGED
@@ -413,7 +413,7 @@ function buildAthenaRequestHeaders(input) {
413
413
 
414
414
  // package.json
415
415
  var package_default = {
416
- version: "3.1.0"
416
+ version: "3.3.0"
417
417
  };
418
418
 
419
419
  // src/sdk-version.ts
@@ -1064,7 +1064,8 @@ function stableSerialize(value, seen) {
1064
1064
  if (value === void 0) return "undefined";
1065
1065
  const valueType = typeof value;
1066
1066
  if (valueType === "string") return `"${value}"`;
1067
- if (valueType === "number") return Number.isFinite(value) ? String(value) : "null";
1067
+ if (valueType === "number")
1068
+ return Number.isFinite(value) ? String(value) : "null";
1068
1069
  if (valueType === "boolean") return value ? "true" : "false";
1069
1070
  if (valueType === "bigint") return `${String(value)}n`;
1070
1071
  if (valueType === "symbol") return `symbol:${String(value)}`;
@@ -1145,7 +1146,8 @@ async function runWithRetry(execute, options) {
1145
1146
  }
1146
1147
  function errorMessageFromUnknown(error) {
1147
1148
  if (typeof error === "string" && error.trim()) return error.trim();
1148
- if (error instanceof Error && error.message.trim()) return error.message.trim();
1149
+ if (error instanceof Error && error.message.trim())
1150
+ return error.message.trim();
1149
1151
  if (isRecord2(error)) {
1150
1152
  const messageCandidate = error.message ?? error.error;
1151
1153
  if (typeof messageCandidate === "string" && messageCandidate.trim()) {
@@ -1364,7 +1366,11 @@ var AthenaQueryClient = class {
1364
1366
  const key = this.getMutationKeyToken(mutationKey);
1365
1367
  const entry = this.ensureMutationEntry(key);
1366
1368
  entry.activeRequestId = ++this.requestCounter;
1367
- this.setMutationState(entry, createInitialMutationState(), "mutation_reset");
1369
+ this.setMutationState(
1370
+ entry,
1371
+ createInitialMutationState(),
1372
+ "mutation_reset"
1373
+ );
1368
1374
  }
1369
1375
  async executeQuery(input) {
1370
1376
  const entry = this.ensureQueryEntry(input.queryKeyToken);
@@ -1426,7 +1432,10 @@ var AthenaQueryClient = class {
1426
1432
  );
1427
1433
  }
1428
1434
  const rawResult = await input.queryFn();
1429
- const normalized = normalizeAthenaResult(rawResult, input.select);
1435
+ const normalized = normalizeAthenaResult(
1436
+ rawResult,
1437
+ input.select
1438
+ );
1430
1439
  if (normalized.error) {
1431
1440
  throw {
1432
1441
  __athenaNormalizedError: normalized.error,
@@ -1514,7 +1523,10 @@ var AthenaQueryClient = class {
1514
1523
  this.inflightQueries.delete(input.queryKeyToken);
1515
1524
  }
1516
1525
  });
1517
- this.inflightQueries.set(input.queryKeyToken, executionPromise);
1526
+ this.inflightQueries.set(
1527
+ input.queryKeyToken,
1528
+ executionPromise
1529
+ );
1518
1530
  return executionPromise;
1519
1531
  }
1520
1532
  async executeMutation(input) {
@@ -1560,7 +1572,10 @@ var AthenaQueryClient = class {
1560
1572
  );
1561
1573
  }
1562
1574
  const rawResult = await input.mutationFn(input.variables);
1563
- const normalized = normalizeAthenaResult(rawResult, input.select);
1575
+ const normalized = normalizeAthenaResult(
1576
+ rawResult,
1577
+ input.select
1578
+ );
1564
1579
  if (normalized.error) {
1565
1580
  throw {
1566
1581
  __athenaNormalizedError: normalized.error,
@@ -2185,12 +2200,6 @@ function applyAthenaReadQuerySelectOrder(queryBuilder, orderBy) {
2185
2200
  queryBuilder
2186
2201
  );
2187
2202
  }
2188
- function applyAthenaReadQuerySelectLimit(queryBuilder, limit) {
2189
- if (!limit || limit < 1) {
2190
- return queryBuilder;
2191
- }
2192
- return queryBuilder.limit(limit);
2193
- }
2194
2203
  function clampAthenaReadQueryTotalItems(totalItems, limit) {
2195
2204
  if (!limit || limit < 1) {
2196
2205
  return totalItems;
@@ -2223,6 +2232,27 @@ function resolveTotalItemsFromPage({
2223
2232
  }
2224
2233
  return clampAthenaReadQueryTotalItems(exactCount, limit);
2225
2234
  }
2235
+ function resolveAthenaReadQueryPageFetch({
2236
+ page,
2237
+ pageSize,
2238
+ limit
2239
+ }) {
2240
+ const safePage = Math.max(1, Math.trunc(page) || 1);
2241
+ const safePageSize = Math.max(1, Math.trunc(pageSize) || 1);
2242
+ if (!limit || limit < 1) {
2243
+ return { page: safePage, pageSize: safePageSize, shouldFetch: true };
2244
+ }
2245
+ const totalCap = Math.trunc(limit);
2246
+ const offset = (safePage - 1) * safePageSize;
2247
+ if (offset >= totalCap) {
2248
+ return { page: safePage, pageSize: safePageSize, shouldFetch: false };
2249
+ }
2250
+ return {
2251
+ page: safePage,
2252
+ pageSize: Math.min(safePageSize, totalCap - offset),
2253
+ shouldFetch: true
2254
+ };
2255
+ }
2226
2256
  async function executeAthenaReadQuery({
2227
2257
  client,
2228
2258
  page,
@@ -2241,15 +2271,29 @@ async function executeAthenaReadQuery({
2241
2271
  count: "exact",
2242
2272
  head: true
2243
2273
  });
2274
+ const pageFetch = resolveAthenaReadQueryPageFetch({
2275
+ limit: query.limit,
2276
+ page,
2277
+ pageSize
2278
+ });
2279
+ if (!pageFetch.shouldFetch) {
2280
+ return {
2281
+ rows: [],
2282
+ totalItems: resolveTotalItemsFromPage({
2283
+ countCandidates: [countResult.count],
2284
+ limit: query.limit,
2285
+ page: pageFetch.page,
2286
+ pageSize,
2287
+ rowCount: 0
2288
+ })
2289
+ };
2290
+ }
2244
2291
  if ((query.mode ?? "findMany") === "select") {
2245
- const selectBuilder = applyAthenaReadQuerySelectLimit(
2246
- applyAthenaReadQuerySelectOrder(
2247
- applyAthenaReadQueryFilters(baseBuilder, query.filters),
2248
- query.orderBy
2249
- ),
2250
- query.limit
2292
+ const selectBuilder = applyAthenaReadQuerySelectOrder(
2293
+ applyAthenaReadQueryFilters(baseBuilder, query.filters),
2294
+ query.orderBy
2251
2295
  );
2252
- const result2 = await selectBuilder.currentPage(page).pageSize(pageSize).select(buildAthenaReadQuerySelectString(query.columns), {
2296
+ const result2 = await selectBuilder.currentPage(pageFetch.page).pageSize(pageFetch.pageSize).select(buildAthenaReadQuerySelectString(query.columns), {
2253
2297
  count: "exact"
2254
2298
  });
2255
2299
  const rows2 = flattenAthenaReadQueryRows(
@@ -2263,7 +2307,7 @@ async function executeAthenaReadQuery({
2263
2307
  totalItems: resolveTotalItemsFromPage({
2264
2308
  countCandidates: [countResult.count, result2.count],
2265
2309
  limit: query.limit,
2266
- page,
2310
+ page: pageFetch.page,
2267
2311
  pageSize,
2268
2312
  rowCount: rows2.length
2269
2313
  })
@@ -2271,12 +2315,11 @@ async function executeAthenaReadQuery({
2271
2315
  }
2272
2316
  const findManyOrderBy = buildAthenaReadQueryFindManyOrderBy(query.orderBy);
2273
2317
  const findManyOptions = {
2274
- ...query.limit ? { limit: query.limit } : {},
2275
2318
  ...findManyOrderBy ? { orderBy: findManyOrderBy } : {},
2276
2319
  select: buildAthenaReadQueryFindManySelect(query.columns),
2277
2320
  ...query.filters?.length ? { where: buildAthenaReadQueryFindManyWhere(query.filters) } : {}
2278
2321
  };
2279
- const result = await baseBuilder.currentPage(page).pageSize(pageSize).findMany(findManyOptions);
2322
+ const result = await baseBuilder.currentPage(pageFetch.page).pageSize(pageFetch.pageSize).findMany(findManyOptions);
2280
2323
  const rows = flattenAthenaReadQueryRows(
2281
2324
  Array.isArray(result.data) ? result.data : [],
2282
2325
  query.columns,
@@ -2288,7 +2331,7 @@ async function executeAthenaReadQuery({
2288
2331
  totalItems: resolveTotalItemsFromPage({
2289
2332
  countCandidates: [countResult.count, result.count],
2290
2333
  limit: query.limit,
2291
- page,
2334
+ page: pageFetch.page,
2292
2335
  pageSize,
2293
2336
  rowCount: rows.length
2294
2337
  })
@@ -2400,7 +2443,16 @@ function resolveGetSession(authClient) {
2400
2443
  if ("auth" in authClient && authClient.auth && typeof authClient.auth.getSession === "function") {
2401
2444
  return authClient.auth.getSession;
2402
2445
  }
2403
- throw new Error("useSession requires an auth-capable client (createClient(...).auth)");
2446
+ throw new Error(
2447
+ "useSession requires an auth-capable client (createClient(...).auth)"
2448
+ );
2449
+ }
2450
+ function toFallbackErrorDetails(code, message, status) {
2451
+ return {
2452
+ code,
2453
+ message,
2454
+ status
2455
+ };
2404
2456
  }
2405
2457
  function useSession(authClient, options = {}) {
2406
2458
  const enabled = options.enabled ?? true;
@@ -2418,11 +2470,6 @@ function useSession(authClient, options = {}) {
2418
2470
  React.useEffect(() => {
2419
2471
  dataRef.current = data;
2420
2472
  }, [data]);
2421
- const toFallbackErrorDetails = (code, message, status) => ({
2422
- code,
2423
- message,
2424
- status
2425
- });
2426
2473
  const runFetch = React.useCallback(async () => {
2427
2474
  const requestId = ++requestIdRef.current;
2428
2475
  const hasData = dataRef.current !== null;
@@ -2485,6 +2532,211 @@ function useSession(authClient, options = {}) {
2485
2532
  refetch
2486
2533
  };
2487
2534
  }
2535
+
2536
+ // src/admin/index.ts
2537
+ function resolveAdminPermissionClient(client) {
2538
+ if (!client || typeof client !== "object") {
2539
+ return null;
2540
+ }
2541
+ const record = client;
2542
+ const nestedAuth = record.auth;
2543
+ if (nestedAuth && typeof nestedAuth === "object" && nestedAuth !== null && "admin" in nestedAuth) {
2544
+ return client;
2545
+ }
2546
+ if ("admin" in record) {
2547
+ return { auth: client };
2548
+ }
2549
+ return null;
2550
+ }
2551
+ function buildAdminAuthFetchOptions(credentials = {}) {
2552
+ const cookie = credentials.cookie?.trim() || void 0;
2553
+ const bearerToken = credentials.bearerToken?.trim() || void 0;
2554
+ const headers = {};
2555
+ if (cookie) {
2556
+ headers.cookie = cookie;
2557
+ }
2558
+ if (bearerToken) {
2559
+ headers.authorization = `Bearer ${bearerToken}`;
2560
+ }
2561
+ return {
2562
+ credentials: "include",
2563
+ ...bearerToken ? { bearerToken } : {},
2564
+ ...Object.keys(headers).length > 0 ? { headers } : {}
2565
+ };
2566
+ }
2567
+ function hasAdminRole(session) {
2568
+ const role = session?.user?.role;
2569
+ if (!role) {
2570
+ return false;
2571
+ }
2572
+ return role.split(",").map((item) => item.trim().toLowerCase()).includes("admin");
2573
+ }
2574
+ function mergeAdminFetchOptions(input) {
2575
+ const fromCredentials = input.credentials ? buildAdminAuthFetchOptions(input.credentials) : void 0;
2576
+ const explicit = input.fetchOptions;
2577
+ if (!fromCredentials && !explicit) {
2578
+ return void 0;
2579
+ }
2580
+ if (!fromCredentials) {
2581
+ return explicit;
2582
+ }
2583
+ if (!explicit) {
2584
+ return fromCredentials;
2585
+ }
2586
+ return {
2587
+ ...fromCredentials,
2588
+ ...explicit,
2589
+ headers: {
2590
+ ...fromCredentials.headers ?? {},
2591
+ ...explicit.headers ?? {}
2592
+ }
2593
+ };
2594
+ }
2595
+ async function hasAdminPermission(client, input) {
2596
+ if (!input.session?.user?.id) {
2597
+ return false;
2598
+ }
2599
+ if (input.allowRoleBypass !== false && hasAdminRole(input.session)) {
2600
+ return true;
2601
+ }
2602
+ const fetchOptions = mergeAdminFetchOptions(input);
2603
+ const result = await client.auth.admin.hasPermission(
2604
+ {
2605
+ permission: input.permission,
2606
+ permissions: input.permissions,
2607
+ ...fetchOptions ? { fetchOptions } : {}
2608
+ },
2609
+ input.requestOptions
2610
+ );
2611
+ return Boolean(result.ok && result.data?.success);
2612
+ }
2613
+
2614
+ // src/react/use-admin-permission.ts
2615
+ var DEFAULT_ADMIN_PERMISSIONS = [
2616
+ "admin:read"
2617
+ ];
2618
+ function serializePermissions(permissions, permission) {
2619
+ return JSON.stringify({
2620
+ permission: permission ?? null,
2621
+ permissions: permissions ?? DEFAULT_ADMIN_PERMISSIONS
2622
+ });
2623
+ }
2624
+ function useAdminPermission(client, options = {}) {
2625
+ const enabled = options.enabled ?? true;
2626
+ const sessionProvided = "session" in options;
2627
+ const sessionFromOptions = sessionProvided ? options.session ?? null : void 0;
2628
+ const permissionsKey = serializePermissions(options.permissions, options.permission);
2629
+ const allowRoleBypass = options.allowRoleBypass;
2630
+ const fetchOptions = options.fetchOptions;
2631
+ const requestOptions = options.requestOptions;
2632
+ const optionsRef = React.useRef(options);
2633
+ optionsRef.current = options;
2634
+ const sessionState = useSession(client, {
2635
+ ...options.sessionOptions,
2636
+ enabled: enabled && !sessionProvided && !!client
2637
+ });
2638
+ const session = sessionProvided ? sessionFromOptions ?? null : sessionState.data;
2639
+ const sessionPending = !sessionProvided && sessionState.isPending;
2640
+ const sessionUserId = session?.user?.id ?? null;
2641
+ const sessionRole = session?.user?.role ?? null;
2642
+ const [allowed, setAllowed] = React.useState(false);
2643
+ const [error, setError] = React.useState(null);
2644
+ const [isChecking, setIsChecking] = React.useState(enabled);
2645
+ const requestIdRef = React.useRef(0);
2646
+ const mountedRef = React.useRef(true);
2647
+ const runCheck = React.useCallback(async () => {
2648
+ const requestId = ++requestIdRef.current;
2649
+ const current = optionsRef.current;
2650
+ const permissions = current.permissions ?? DEFAULT_ADMIN_PERMISSIONS;
2651
+ if (!enabled || !client) {
2652
+ if (mountedRef.current && requestId === requestIdRef.current) {
2653
+ setAllowed(false);
2654
+ setError(null);
2655
+ setIsChecking(false);
2656
+ }
2657
+ return false;
2658
+ }
2659
+ setIsChecking(true);
2660
+ try {
2661
+ const permissionClient = resolveAdminPermissionClient(client);
2662
+ if (!permissionClient) {
2663
+ throw new Error(
2664
+ "useAdminPermission requires an Athena client with auth.admin (createClient(...) or auth bindings)"
2665
+ );
2666
+ }
2667
+ const resolvedSession = sessionProvided ? current.session ?? null : sessionState.data;
2668
+ const nextAllowed = await hasAdminPermission(permissionClient, {
2669
+ session: resolvedSession,
2670
+ permissions,
2671
+ permission: current.permission,
2672
+ allowRoleBypass: current.allowRoleBypass,
2673
+ fetchOptions: current.fetchOptions,
2674
+ requestOptions: current.requestOptions
2675
+ });
2676
+ if (!mountedRef.current || requestId !== requestIdRef.current) {
2677
+ return nextAllowed;
2678
+ }
2679
+ setAllowed(nextAllowed);
2680
+ setError(null);
2681
+ return nextAllowed;
2682
+ } catch (checkError) {
2683
+ if (!mountedRef.current || requestId !== requestIdRef.current) {
2684
+ return false;
2685
+ }
2686
+ const nextError = checkError instanceof Error ? checkError : new Error("Failed to resolve admin permission");
2687
+ setAllowed(false);
2688
+ setError(nextError);
2689
+ return false;
2690
+ } finally {
2691
+ if (mountedRef.current && requestId === requestIdRef.current) {
2692
+ setIsChecking(false);
2693
+ }
2694
+ }
2695
+ }, [client, enabled, sessionProvided, sessionState.data]);
2696
+ React.useEffect(() => {
2697
+ mountedRef.current = true;
2698
+ return () => {
2699
+ mountedRef.current = false;
2700
+ };
2701
+ }, []);
2702
+ React.useEffect(() => {
2703
+ if (!enabled) {
2704
+ setAllowed(false);
2705
+ setError(null);
2706
+ setIsChecking(false);
2707
+ return;
2708
+ }
2709
+ if (!sessionProvided && sessionState.isPending) {
2710
+ setIsChecking(true);
2711
+ return;
2712
+ }
2713
+ void runCheck();
2714
+ }, [
2715
+ allowRoleBypass,
2716
+ enabled,
2717
+ fetchOptions,
2718
+ permissionsKey,
2719
+ requestOptions,
2720
+ runCheck,
2721
+ sessionPending,
2722
+ sessionProvided,
2723
+ sessionRole,
2724
+ sessionUserId
2725
+ ]);
2726
+ const refetch = React.useCallback(async () => {
2727
+ if (!sessionProvided) {
2728
+ await sessionState.refetch();
2729
+ }
2730
+ return await runCheck();
2731
+ }, [runCheck, sessionProvided, sessionState]);
2732
+ return {
2733
+ allowed,
2734
+ isPending: enabled && (sessionPending || isChecking),
2735
+ error,
2736
+ session,
2737
+ refetch
2738
+ };
2739
+ }
2488
2740
  function useAthenaSessionClient(baseClient, options = {}) {
2489
2741
  const sessionState = useSession(baseClient, options);
2490
2742
  const scopedClient = React.useMemo(
@@ -2589,7 +2841,13 @@ function isStorageUploadInput(input) {
2589
2841
  return Boolean(input) && typeof input === "object" && "files" in input && "s3_id" in input;
2590
2842
  }
2591
2843
  function useStorageFiles(options) {
2592
- const { storage, input, enabled = true, callOptions, refreshIntervalMs } = options;
2844
+ const {
2845
+ storage,
2846
+ input,
2847
+ enabled = true,
2848
+ callOptions,
2849
+ refreshIntervalMs
2850
+ } = options;
2593
2851
  const [data, setData] = React__namespace.useState(null);
2594
2852
  const [loading, setLoading] = React__namespace.useState(false);
2595
2853
  const [error, setError] = React__namespace.useState(null);
@@ -2751,6 +3009,7 @@ exports.createModelFormAdapter = createModelFormAdapter;
2751
3009
  exports.isAthenaGatewayError = isAthenaGatewayError;
2752
3010
  exports.toModelFormDefaults = toModelFormDefaults;
2753
3011
  exports.toModelPayload = toModelPayload;
3012
+ exports.useAdminPermission = useAdminPermission;
2754
3013
  exports.useAthenaGateway = useAthenaGateway;
2755
3014
  exports.useAthenaQueryClient = useAthenaQueryClient;
2756
3015
  exports.useAthenaReadQuery = useAthenaReadQuery;