@axcode/axcloud-sdk 0.1.5 → 0.1.7-dev.332678a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { createContext, useContext, useMemo, useCallback, useRef } from 'react';
1
+ import { createContext, useContext, useMemo, useCallback, useState, useRef } from 'react';
2
2
  import { Auth0Provider, useAuth0 } from '@auth0/auth0-react';
3
3
  import { QueryClient, QueryClientProvider, useQuery, useQueryClient, useMutation } from '@tanstack/react-query';
4
4
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
@@ -122,7 +122,7 @@ var AxCloudClient = class {
122
122
  */
123
123
  shouldAttachApiKey(path) {
124
124
  const normalized = path.startsWith("/") ? path : `/${path}`;
125
- return normalized.startsWith("/public/") || normalized.startsWith("/api/public/") || normalized.startsWith("/content/public/");
125
+ return normalized.startsWith("/public/") || normalized.startsWith("/api/public/") || normalized.startsWith("/content/public/") || normalized.startsWith("/media/public/") || normalized.startsWith("/documents/public/") || normalized.startsWith("/barnsport/public/") || normalized.startsWith("/api/barnsport/public/");
126
126
  }
127
127
  /**
128
128
  * Make an authenticated request
@@ -236,6 +236,88 @@ function getClient(key) {
236
236
  throw new Error("AxCloud client not found. Make sure AxCloudProvider is mounted and use useAxCloudContext() to get the client.");
237
237
  }
238
238
 
239
+ // src/core/contentSlots.ts
240
+ var SLOT_ATTRIBUTE_KEYS = ["slot", "field", "key", "name"];
241
+ function getContentSlotMap(content) {
242
+ const fields = isRecord(content?.fields) ? { ...content?.fields } : {};
243
+ for (const block of content?.blocks || []) {
244
+ const slot = getBlockSlot(block);
245
+ if (!slot) continue;
246
+ fields[slot] = blockToSlotValue(block);
247
+ }
248
+ return fields;
249
+ }
250
+ function createContentSlotReader(content) {
251
+ const fields = getContentSlotMap(content);
252
+ const value = (key, fallback) => {
253
+ return key in fields ? fields[key] : fallback;
254
+ };
255
+ return {
256
+ fields,
257
+ value,
258
+ text: (key, fallback = "") => stringifySlotValue(value(key, fallback)),
259
+ html: (key, fallback = "") => stringifySlotValue(value(key, fallback)),
260
+ list: (key, fallback = []) => slotValueToList(value(key, fallback)),
261
+ image: (key, fallback) => slotValueToImage(value(key, fallback))
262
+ };
263
+ }
264
+ function getBlockSlot(block) {
265
+ const attributes = block.attributes || {};
266
+ for (const key of SLOT_ATTRIBUTE_KEYS) {
267
+ const value = attributes[key];
268
+ if (typeof value === "string" && value.trim()) return value.trim();
269
+ }
270
+ return void 0;
271
+ }
272
+ function blockToSlotValue(block) {
273
+ if (block.attributes && "value" in block.attributes) {
274
+ return block.attributes.value;
275
+ }
276
+ if (block.type === "list") {
277
+ return Array.isArray(block.items) ? block.items : [];
278
+ }
279
+ if (block.type === "image" && block.url) {
280
+ return {
281
+ url: block.url,
282
+ alt: block.alt,
283
+ caption: block.caption
284
+ };
285
+ }
286
+ return block.content ?? "";
287
+ }
288
+ function stringifySlotValue(value) {
289
+ if (value === void 0 || value === null) return "";
290
+ if (typeof value === "string") return value;
291
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
292
+ if (Array.isArray(value)) return value.map((item) => stringifySlotValue(item)).filter(Boolean).join("\n");
293
+ return "";
294
+ }
295
+ function slotValueToList(value) {
296
+ if (Array.isArray(value)) {
297
+ return value.map((item) => stringifySlotValue(item)).filter(Boolean);
298
+ }
299
+ if (typeof value === "string") {
300
+ return value.split(/\r?\n/).map((item) => item.trim()).filter(Boolean);
301
+ }
302
+ return [];
303
+ }
304
+ function slotValueToImage(value) {
305
+ if (isRecord(value) && typeof value.url === "string") {
306
+ return {
307
+ url: value.url,
308
+ alt: typeof value.alt === "string" ? value.alt : void 0,
309
+ caption: typeof value.caption === "string" ? value.caption : void 0
310
+ };
311
+ }
312
+ if (typeof value === "string" && value) {
313
+ return { url: value };
314
+ }
315
+ return void 0;
316
+ }
317
+ function isRecord(value) {
318
+ return !!value && typeof value === "object" && !Array.isArray(value);
319
+ }
320
+
239
321
  // src/core/types.ts
240
322
  function userHasPermission(user, permission) {
241
323
  if (user.permissions && user.permissions.length > 0) {
@@ -349,6 +431,98 @@ function createFormHelper(config) {
349
431
  })
350
432
  };
351
433
  }
434
+
435
+ // src/core/voting.ts
436
+ function baseOf(votingApiUrl) {
437
+ return votingApiUrl.replace(/\/$/, "");
438
+ }
439
+ async function readJson(response) {
440
+ const json = await response.json().catch(() => ({}));
441
+ if (json && typeof json === "object" && "success" in json && "data" in json) {
442
+ return json.data;
443
+ }
444
+ return json;
445
+ }
446
+ async function ensureOk(response) {
447
+ if (!response.ok) {
448
+ const body = await response.json().catch(() => ({}));
449
+ const message = body && (body.error || body.message) || `Request failed with status ${response.status}`;
450
+ throw new Error(message);
451
+ }
452
+ }
453
+ async function checkVotingCode(votingApiUrl, params) {
454
+ const response = await fetch(
455
+ `${baseOf(votingApiUrl)}/public/organizations/${params.orgId}/polls/${params.pollId}/eligibility`,
456
+ {
457
+ method: "POST",
458
+ headers: { "Content-Type": "application/json" },
459
+ body: JSON.stringify({ code: params.code })
460
+ }
461
+ );
462
+ await ensureOk(response);
463
+ return readJson(response);
464
+ }
465
+ async function castVoteWithCode(votingApiUrl, params) {
466
+ const response = await fetch(
467
+ `${baseOf(votingApiUrl)}/public/organizations/${params.orgId}/polls/${params.pollId}/vote`,
468
+ {
469
+ method: "POST",
470
+ headers: { "Content-Type": "application/json" },
471
+ body: JSON.stringify({ code: params.code, selected_options: params.selectedOptions, rankings: params.rankings })
472
+ }
473
+ );
474
+ await ensureOk(response);
475
+ return readJson(response);
476
+ }
477
+ async function getVotingReceipt(votingApiUrl, params) {
478
+ const response = await fetch(
479
+ `${baseOf(votingApiUrl)}/public/organizations/${params.orgId}/polls/${params.pollId}/receipt`,
480
+ {
481
+ method: "POST",
482
+ headers: { "Content-Type": "application/json" },
483
+ body: JSON.stringify({ code: params.code })
484
+ }
485
+ );
486
+ await ensureOk(response);
487
+ return readJson(response);
488
+ }
489
+ function authHeaders(accessToken) {
490
+ return { "Content-Type": "application/json", Authorization: `Bearer ${accessToken}` };
491
+ }
492
+ async function getBallot(votingApiUrl, params) {
493
+ const base = `${baseOf(votingApiUrl)}/organizations/${params.orgId}/polls/${params.pollId}`;
494
+ const pollResp = await fetch(base, { headers: authHeaders(params.accessToken) });
495
+ await ensureOk(pollResp);
496
+ const poll = await readJson(pollResp);
497
+ let candidates = [];
498
+ if (poll.poll_type === "election") {
499
+ const candResp = await fetch(`${base}/candidates`, { headers: authHeaders(params.accessToken) });
500
+ await ensureOk(candResp);
501
+ const data = await readJson(candResp);
502
+ candidates = data.candidates || [];
503
+ }
504
+ return { ...poll, candidates };
505
+ }
506
+ async function checkEligibility(votingApiUrl, params) {
507
+ const response = await fetch(
508
+ `${baseOf(votingApiUrl)}/organizations/${params.orgId}/polls/${params.pollId}/eligibility`,
509
+ { headers: authHeaders(params.accessToken) }
510
+ );
511
+ await ensureOk(response);
512
+ return readJson(response);
513
+ }
514
+ async function castVote(votingApiUrl, params) {
515
+ const response = await fetch(
516
+ `${baseOf(votingApiUrl)}/organizations/${params.orgId}/polls/${params.pollId}/vote`,
517
+ {
518
+ method: "POST",
519
+ headers: authHeaders(params.accessToken),
520
+ body: JSON.stringify({ selected_options: params.selectedOptions, rankings: params.rankings })
521
+ }
522
+ );
523
+ await ensureOk(response);
524
+ return readJson(response);
525
+ }
352
526
  var AxCloudContext = createContext(null);
353
527
  function useAxCloudContext() {
354
528
  const context = useContext(AxCloudContext);
@@ -437,14 +611,15 @@ function AxCloudProvider({
437
611
  clientId: auth0.clientId,
438
612
  authorizationParams: {
439
613
  redirect_uri: auth0.redirectUri,
440
- audience: auth0.audience
614
+ audience: auth0.audience,
615
+ ...auth0.organization ? { organization: auth0.organization } : {}
441
616
  },
442
617
  children: /* @__PURE__ */ jsx(AxCloudInnerProvider, { config, timeout, children })
443
618
  }
444
619
  ) });
445
620
  }
446
621
  function useAuth() {
447
- const { config } = useAxCloudContext();
622
+ const { config, client } = useAxCloudContext();
448
623
  const {
449
624
  isAuthenticated,
450
625
  isLoading,
@@ -460,10 +635,15 @@ function useAuth() {
460
635
  return loginWithRedirect({
461
636
  appState: {
462
637
  returnTo: options?.returnTo || window.location.pathname
463
- }
638
+ },
639
+ ...config.auth0.organization ? {
640
+ authorizationParams: {
641
+ organization: config.auth0.organization
642
+ }
643
+ } : {}
464
644
  });
465
645
  },
466
- [loginWithRedirect]
646
+ [config.auth0.organization, loginWithRedirect]
467
647
  );
468
648
  const logout = useCallback(
469
649
  (options) => {
@@ -482,6 +662,60 @@ function useAuth() {
482
662
  return void 0;
483
663
  }
484
664
  }, [getAccessTokenSilently]);
665
+ const refreshUser = useCallback(async () => {
666
+ await getAccessTokenSilently({ cacheMode: "off" });
667
+ const claims = await getIdTokenClaims();
668
+ return claims?.email_verified === true;
669
+ }, [getAccessTokenSilently, getIdTokenClaims]);
670
+ const requestEmailVerification = useCallback(
671
+ async (options) => {
672
+ if (!isAuthenticated || !auth0User) {
673
+ return {
674
+ success: false,
675
+ status: "failed",
676
+ message: "You must be signed in to verify your email."
677
+ };
678
+ }
679
+ if (auth0User.email_verified === true) {
680
+ return {
681
+ success: true,
682
+ status: "already_verified",
683
+ message: "Your email address is already verified."
684
+ };
685
+ }
686
+ try {
687
+ const response = await client.post("/email/identity/verification-email", {
688
+ return_to: options?.returnTo || window.location.href
689
+ });
690
+ const data = response.data || {};
691
+ return {
692
+ success: true,
693
+ status: data.status || "sent",
694
+ message: data.message || "A verification email has been sent.",
695
+ ...data.retry_after_seconds !== void 0 ? { retryAfterSeconds: data.retry_after_seconds } : {}
696
+ };
697
+ } catch (requestError) {
698
+ if (isAxCloudError(requestError) && requestError.status === 429) {
699
+ const responseDetails = requestError.details?.details;
700
+ const retryAfterSeconds = Number(
701
+ responseDetails && typeof responseDetails === "object" ? responseDetails.retry_after_seconds : void 0
702
+ );
703
+ return {
704
+ success: false,
705
+ status: "rate_limited",
706
+ message: "Please wait before requesting another verification email.",
707
+ ...Number.isFinite(retryAfterSeconds) ? { retryAfterSeconds } : {}
708
+ };
709
+ }
710
+ return {
711
+ success: false,
712
+ status: "failed",
713
+ message: "Failed to send the verification email. Please try again."
714
+ };
715
+ }
716
+ },
717
+ [auth0User, client, isAuthenticated]
718
+ );
485
719
  const getAuth0Client = useCallback(() => {
486
720
  return {
487
721
  loginWithRedirect,
@@ -555,13 +789,17 @@ function useAuth() {
555
789
  id: auth0User.sub || "",
556
790
  email: auth0User.email || "",
557
791
  name: auth0User.name || "",
558
- avatar: auth0User.picture
792
+ avatar: auth0User.picture,
793
+ ...typeof auth0User.email_verified === "boolean" ? { emailVerified: auth0User.email_verified } : {}
559
794
  } : null,
795
+ needsEmailVerification: isAuthenticated && auth0User?.email_verified === false,
560
796
  login,
561
797
  logout,
562
798
  // Escape hatch for advanced use cases
563
799
  getAccessToken,
564
800
  getAuth0Client,
801
+ refreshUser,
802
+ requestEmailVerification,
565
803
  // Password management
566
804
  requestPasswordReset
567
805
  };
@@ -659,6 +897,7 @@ function useNews(options = {}) {
659
897
  search,
660
898
  sortBy = "publishedAt",
661
899
  sortOrder = "desc",
900
+ lang,
662
901
  publicOnly = false
663
902
  } = options;
664
903
  const usePublicEndpoint = isPublicMode || publicOnly;
@@ -675,7 +914,8 @@ function useNews(options = {}) {
675
914
  sectionId,
676
915
  search,
677
916
  sortBy,
678
- sortOrder
917
+ sortOrder,
918
+ lang
679
919
  ],
680
920
  queryFn: async () => {
681
921
  const endpoint = usePublicEndpoint ? `/content/public/${orgId}/news` : `/content/members/${orgId}/news`;
@@ -687,7 +927,8 @@ function useNews(options = {}) {
687
927
  sectionId,
688
928
  search,
689
929
  sortBy,
690
- sortOrder
930
+ sortOrder,
931
+ lang
691
932
  });
692
933
  },
693
934
  staleTime: 1e3 * 60 * 5
@@ -789,6 +1030,15 @@ function useContentItem(contentType, idOrSlug, options = {}) {
789
1030
  refetch: query.refetch
790
1031
  };
791
1032
  }
1033
+ function usePageContent(slug, options = {}) {
1034
+ const state = useContentItem("pages", slug, options);
1035
+ const reader = useMemo(() => createContentSlotReader(state.data), [state.data]);
1036
+ return {
1037
+ ...state,
1038
+ page: state.data,
1039
+ ...reader
1040
+ };
1041
+ }
792
1042
  function useMySection(options = {}) {
793
1043
  const { includeMembers = true } = options;
794
1044
  const { isAuthenticated } = useAuth0();
@@ -907,6 +1157,76 @@ function useUpdateFormSubmission() {
907
1157
  }
908
1158
  });
909
1159
  }
1160
+ function useCodeBallot({ pollId, votingApiUrl }) {
1161
+ const { orgId, config } = useAxCloudContext();
1162
+ const baseUrl = votingApiUrl || `${config.apiUrl.replace(/\/$/, "")}/voting`;
1163
+ const [stage, setStage] = useState("enter_code");
1164
+ const [code, setCode] = useState("");
1165
+ const [ballot, setBallot] = useState(null);
1166
+ const [receipt, setReceipt] = useState(null);
1167
+ const [reason, setReason] = useState(void 0);
1168
+ const [loading, setLoading] = useState(false);
1169
+ const [error, setError] = useState(null);
1170
+ const validateCode = useCallback(
1171
+ async (inputCode) => {
1172
+ setLoading(true);
1173
+ setError(null);
1174
+ try {
1175
+ const result = await checkVotingCode(baseUrl, { orgId, pollId, code: inputCode });
1176
+ setCode(inputCode);
1177
+ setReason(result.reason);
1178
+ if (result.has_voted) {
1179
+ const r = await getVotingReceipt(baseUrl, { orgId, pollId, code: inputCode }).catch(() => null);
1180
+ setReceipt(r);
1181
+ setStage("already_voted");
1182
+ } else if (result.eligible && result.ballot) {
1183
+ setBallot(result.ballot);
1184
+ setStage("ballot");
1185
+ } else {
1186
+ setError(result.reason || "This code cannot be used to vote right now.");
1187
+ }
1188
+ return result;
1189
+ } catch (e) {
1190
+ setError(e instanceof Error ? e.message : "Failed to validate code");
1191
+ return null;
1192
+ } finally {
1193
+ setLoading(false);
1194
+ }
1195
+ },
1196
+ [baseUrl, orgId, pollId]
1197
+ );
1198
+ const submitVote = useCallback(
1199
+ async (selectedOptions, rankings) => {
1200
+ setLoading(true);
1201
+ setError(null);
1202
+ try {
1203
+ await castVoteWithCode(baseUrl, { orgId, pollId, code, selectedOptions, rankings });
1204
+ const r = await getVotingReceipt(baseUrl, { orgId, pollId, code }).catch(() => null);
1205
+ setReceipt(r);
1206
+ setStage("submitted");
1207
+ return true;
1208
+ } catch (e) {
1209
+ setError(e instanceof Error ? e.message : "Failed to submit vote");
1210
+ return false;
1211
+ } finally {
1212
+ setLoading(false);
1213
+ }
1214
+ },
1215
+ [baseUrl, orgId, pollId, code]
1216
+ );
1217
+ const reset = useCallback(() => {
1218
+ setStage("enter_code");
1219
+ setCode("");
1220
+ setBallot(null);
1221
+ setReceipt(null);
1222
+ setReason(void 0);
1223
+ setError(null);
1224
+ }, []);
1225
+ return useMemo(
1226
+ () => ({ stage, code, ballot, receipt, reason, loading, error, validateCode, submitVote, reset }),
1227
+ [stage, code, ballot, receipt, reason, loading, error, validateCode, submitVote, reset]
1228
+ );
1229
+ }
910
1230
  var LINKED_ACCOUNTS_QUERY_KEY = ["axcloud", "linked-accounts"];
911
1231
  function useLinkedAccounts() {
912
1232
  const { client, stage } = useAxCloudContext();
@@ -1065,6 +1385,245 @@ function useMedia(mediaId) {
1065
1385
  refetch: query.refetch
1066
1386
  };
1067
1387
  }
1388
+ function buildDocumentParams(options) {
1389
+ return {
1390
+ search: options?.search,
1391
+ tags: options?.tags?.join(","),
1392
+ limit: options?.limit
1393
+ };
1394
+ }
1395
+ function useDocuments(options) {
1396
+ const { client, orgId } = useAxCloudContext();
1397
+ const params = buildDocumentParams(options);
1398
+ const query = useQuery({
1399
+ queryKey: ["axcloud", "documents", "list", orgId, options],
1400
+ queryFn: async () => {
1401
+ return client.get(`/documents/public/${orgId}/documents`, params);
1402
+ },
1403
+ staleTime: 1e3 * 60 * 5
1404
+ });
1405
+ return {
1406
+ documents: query.data?.items ?? [],
1407
+ items: query.data?.items ?? [],
1408
+ count: query.data?.count ?? 0,
1409
+ isLoading: query.isLoading,
1410
+ isError: query.isError,
1411
+ error: query.error,
1412
+ refetch: query.refetch
1413
+ };
1414
+ }
1415
+ function useDocumentDownload(documentId) {
1416
+ const { client, orgId } = useAxCloudContext();
1417
+ const query = useQuery({
1418
+ queryKey: ["axcloud", "documents", "download", orgId, documentId],
1419
+ queryFn: async () => {
1420
+ return client.get(
1421
+ `/documents/public/${orgId}/documents/${encodeURIComponent(documentId || "")}/download`
1422
+ );
1423
+ },
1424
+ enabled: !!documentId,
1425
+ staleTime: 1e3 * 60 * 10,
1426
+ gcTime: 1e3 * 60 * 14
1427
+ });
1428
+ return {
1429
+ url: query.data?.url ?? null,
1430
+ documentUrl: query.data?.url ?? null,
1431
+ filename: query.data?.filename ?? null,
1432
+ mimeType: query.data?.mimeType ?? null,
1433
+ expiresIn: query.data?.expiresIn ?? null,
1434
+ isLoading: query.isLoading,
1435
+ isError: query.isError,
1436
+ error: query.error,
1437
+ refetch: query.refetch
1438
+ };
1439
+ }
1440
+ function useMemberDocuments(options) {
1441
+ const { client, orgId } = useAxCloudContext();
1442
+ const params = buildDocumentParams(options);
1443
+ const folderId = options?.folderId;
1444
+ const query = useQuery({
1445
+ queryKey: ["axcloud", "documents", "member", "list", orgId, options],
1446
+ queryFn: async () => {
1447
+ return client.get(`/documents/members/${orgId}/documents`, params);
1448
+ },
1449
+ staleTime: 1e3 * 60 * 5
1450
+ });
1451
+ const allItems = query.data?.items ?? [];
1452
+ const items = folderId ? allItems.filter((doc) => doc.folder_ids?.includes(folderId)) : allItems;
1453
+ return {
1454
+ documents: items,
1455
+ items,
1456
+ count: folderId ? items.length : query.data?.count ?? 0,
1457
+ isLoading: query.isLoading,
1458
+ isError: query.isError,
1459
+ error: query.error,
1460
+ refetch: query.refetch
1461
+ };
1462
+ }
1463
+ function useMemberDocumentFolders() {
1464
+ const { client, orgId } = useAxCloudContext();
1465
+ const query = useQuery({
1466
+ queryKey: ["axcloud", "documents", "member", "folders", orgId],
1467
+ queryFn: async () => {
1468
+ return client.get(
1469
+ `/documents/members/${orgId}/document-folders`
1470
+ );
1471
+ },
1472
+ staleTime: 1e3 * 60 * 5
1473
+ });
1474
+ return {
1475
+ folders: query.data?.folders ?? [],
1476
+ isLoading: query.isLoading,
1477
+ isError: query.isError,
1478
+ error: query.error,
1479
+ refetch: query.refetch
1480
+ };
1481
+ }
1482
+ function useMemberDocumentDownload(documentId) {
1483
+ const { client, orgId } = useAxCloudContext();
1484
+ const query = useQuery({
1485
+ queryKey: ["axcloud", "documents", "member", "download", orgId, documentId],
1486
+ queryFn: async () => {
1487
+ return client.get(
1488
+ `/documents/members/${orgId}/documents/${encodeURIComponent(documentId || "")}/download`
1489
+ );
1490
+ },
1491
+ enabled: !!documentId,
1492
+ staleTime: 1e3 * 60 * 10,
1493
+ gcTime: 1e3 * 60 * 14
1494
+ });
1495
+ return {
1496
+ url: query.data?.url ?? null,
1497
+ documentUrl: query.data?.url ?? null,
1498
+ filename: query.data?.filename ?? null,
1499
+ mimeType: query.data?.mimeType ?? null,
1500
+ expiresIn: query.data?.expiresIn ?? null,
1501
+ isLoading: query.isLoading,
1502
+ isError: query.isError,
1503
+ error: query.error,
1504
+ refetch: query.refetch
1505
+ };
1506
+ }
1507
+ function useBarnsportMunicipalities() {
1508
+ const { client, orgId } = useAxCloudContext();
1509
+ const query = useQuery({
1510
+ queryKey: ["axcloud", "barnsport", "municipalities", orgId],
1511
+ queryFn: () => client.get(
1512
+ `/barnsport/public/${orgId}/municipalities`
1513
+ ),
1514
+ staleTime: 1e3 * 60 * 30
1515
+ });
1516
+ return {
1517
+ municipalities: query.data?.items ?? [],
1518
+ count: query.data?.count ?? 0,
1519
+ isLoading: query.isLoading,
1520
+ isError: query.isError,
1521
+ error: query.error,
1522
+ refetch: query.refetch
1523
+ };
1524
+ }
1525
+ function useBarnsportSports() {
1526
+ const { client, orgId } = useAxCloudContext();
1527
+ const query = useQuery({
1528
+ queryKey: ["axcloud", "barnsport", "sports", orgId],
1529
+ queryFn: () => client.get(
1530
+ `/barnsport/public/${orgId}/sports`
1531
+ ),
1532
+ staleTime: 1e3 * 60 * 30
1533
+ });
1534
+ return {
1535
+ sports: query.data?.items ?? [],
1536
+ count: query.data?.count ?? 0,
1537
+ isLoading: query.isLoading,
1538
+ isError: query.isError,
1539
+ error: query.error,
1540
+ refetch: query.refetch
1541
+ };
1542
+ }
1543
+ function useBarnsportSport(slug) {
1544
+ const { client, orgId } = useAxCloudContext();
1545
+ const query = useQuery({
1546
+ queryKey: ["axcloud", "barnsport", "sport", orgId, slug],
1547
+ queryFn: () => client.get(
1548
+ `/barnsport/public/${orgId}/sports/${slug || ""}`
1549
+ ),
1550
+ enabled: Boolean(slug),
1551
+ staleTime: 1e3 * 60 * 15
1552
+ });
1553
+ return {
1554
+ sport: query.data?.sport ?? null,
1555
+ isLoading: query.isLoading,
1556
+ isError: query.isError,
1557
+ error: query.error,
1558
+ refetch: query.refetch
1559
+ };
1560
+ }
1561
+ function useBarnsportActivities(filters = {}) {
1562
+ const { client, orgId } = useAxCloudContext();
1563
+ const params = { ...filters };
1564
+ const query = useQuery({
1565
+ queryKey: ["axcloud", "barnsport", "activities", orgId, filters],
1566
+ queryFn: () => client.get(
1567
+ `/barnsport/public/${orgId}/activities`,
1568
+ params
1569
+ ),
1570
+ staleTime: 1e3 * 60 * 5
1571
+ });
1572
+ return {
1573
+ activities: query.data?.items ?? [],
1574
+ count: query.data?.count ?? 0,
1575
+ nextCursor: query.data?.nextCursor ?? null,
1576
+ isLoading: query.isLoading,
1577
+ isError: query.isError,
1578
+ error: query.error,
1579
+ refetch: query.refetch
1580
+ };
1581
+ }
1582
+ function useBarnsportActivity(slug) {
1583
+ const { client, orgId } = useAxCloudContext();
1584
+ const query = useQuery({
1585
+ queryKey: ["axcloud", "barnsport", "activity", orgId, slug],
1586
+ queryFn: () => client.get(
1587
+ `/barnsport/public/${orgId}/activities/${slug || ""}`
1588
+ ),
1589
+ enabled: Boolean(slug),
1590
+ staleTime: 1e3 * 60 * 5
1591
+ });
1592
+ return {
1593
+ activity: query.data?.activity ?? null,
1594
+ isLoading: query.isLoading,
1595
+ isError: query.isError,
1596
+ error: query.error,
1597
+ refetch: query.refetch
1598
+ };
1599
+ }
1600
+ function useBarnsportSitemap(baseUrl) {
1601
+ const { client, orgId } = useAxCloudContext();
1602
+ const query = useQuery({
1603
+ queryKey: ["axcloud", "barnsport", "sitemap", orgId, baseUrl],
1604
+ queryFn: () => client.get(`/barnsport/public/${orgId}/sitemap`, {
1605
+ baseUrl
1606
+ }),
1607
+ staleTime: 1e3 * 60 * 15
1608
+ });
1609
+ return {
1610
+ sitemap: query.data ?? null,
1611
+ urls: query.data?.urls ?? [],
1612
+ isLoading: query.isLoading,
1613
+ isError: query.isError,
1614
+ error: query.error,
1615
+ refetch: query.refetch
1616
+ };
1617
+ }
1618
+ function useSubmitBarnsportInterest() {
1619
+ const { client, orgId } = useAxCloudContext();
1620
+ return useMutation({
1621
+ mutationFn: (submission) => client.post(
1622
+ `/barnsport/public/${orgId}/interest`,
1623
+ submission
1624
+ )
1625
+ });
1626
+ }
1068
1627
  function LoginButton({
1069
1628
  children = "Log in",
1070
1629
  returnTo,
@@ -1308,6 +1867,6 @@ function LinkedAccountsList({
1308
1867
  ] });
1309
1868
  }
1310
1869
 
1311
- export { AxCloudClient, AxCloudError, AxCloudProvider, LinkedAccountsList, LoginButton, LogoutButton, ModuleGate, ProtectedRoute, createClient, createFormHelper, getClient, isAxCloudError, submitForm, useAuth, useAvatar, useAxCloudContext, useBranding, useContent, useContentItem, useFormStats, useForms, useLinkedAccounts, useLogo, useMedia, useMediaList, useModuleAccess, useMySection, useNews, useOrg, useSections, useUpdateFormSubmission, useUser, userHasAllPermissions, userHasAnyPermission, userHasPermission };
1870
+ export { AxCloudClient, AxCloudError, AxCloudProvider, LinkedAccountsList, LoginButton, LogoutButton, ModuleGate, ProtectedRoute, castVote, castVoteWithCode, checkEligibility, checkVotingCode, createClient, createContentSlotReader, createFormHelper, getBallot, getClient, getContentSlotMap, getVotingReceipt, isAxCloudError, submitForm, useAuth, useAvatar, useAxCloudContext, useBarnsportActivities, useBarnsportActivity, useBarnsportMunicipalities, useBarnsportSitemap, useBarnsportSport, useBarnsportSports, useBranding, useCodeBallot, useContent, useContentItem, useDocumentDownload, useDocuments, useFormStats, useForms, useLinkedAccounts, useLogo, useMedia, useMediaList, useMemberDocumentDownload, useMemberDocumentFolders, useMemberDocuments, useModuleAccess, useMySection, useNews, useOrg, usePageContent, useSections, useSubmitBarnsportInterest, useUpdateFormSubmission, useUser, userHasAllPermissions, userHasAnyPermission, userHasPermission };
1312
1871
  //# sourceMappingURL=index.mjs.map
1313
1872
  //# sourceMappingURL=index.mjs.map