@axcode/axcloud-sdk 0.1.6 → 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/README.md +67 -5
- package/dist/index.d.mts +537 -2
- package/dist/index.d.ts +537 -2
- package/dist/index.js +495 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +478 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
|
@@ -431,6 +431,98 @@ function createFormHelper(config) {
|
|
|
431
431
|
})
|
|
432
432
|
};
|
|
433
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
|
+
}
|
|
434
526
|
var AxCloudContext = createContext(null);
|
|
435
527
|
function useAxCloudContext() {
|
|
436
528
|
const context = useContext(AxCloudContext);
|
|
@@ -519,14 +611,15 @@ function AxCloudProvider({
|
|
|
519
611
|
clientId: auth0.clientId,
|
|
520
612
|
authorizationParams: {
|
|
521
613
|
redirect_uri: auth0.redirectUri,
|
|
522
|
-
audience: auth0.audience
|
|
614
|
+
audience: auth0.audience,
|
|
615
|
+
...auth0.organization ? { organization: auth0.organization } : {}
|
|
523
616
|
},
|
|
524
617
|
children: /* @__PURE__ */ jsx(AxCloudInnerProvider, { config, timeout, children })
|
|
525
618
|
}
|
|
526
619
|
) });
|
|
527
620
|
}
|
|
528
621
|
function useAuth() {
|
|
529
|
-
const { config } = useAxCloudContext();
|
|
622
|
+
const { config, client } = useAxCloudContext();
|
|
530
623
|
const {
|
|
531
624
|
isAuthenticated,
|
|
532
625
|
isLoading,
|
|
@@ -542,10 +635,15 @@ function useAuth() {
|
|
|
542
635
|
return loginWithRedirect({
|
|
543
636
|
appState: {
|
|
544
637
|
returnTo: options?.returnTo || window.location.pathname
|
|
545
|
-
}
|
|
638
|
+
},
|
|
639
|
+
...config.auth0.organization ? {
|
|
640
|
+
authorizationParams: {
|
|
641
|
+
organization: config.auth0.organization
|
|
642
|
+
}
|
|
643
|
+
} : {}
|
|
546
644
|
});
|
|
547
645
|
},
|
|
548
|
-
[loginWithRedirect]
|
|
646
|
+
[config.auth0.organization, loginWithRedirect]
|
|
549
647
|
);
|
|
550
648
|
const logout = useCallback(
|
|
551
649
|
(options) => {
|
|
@@ -564,6 +662,60 @@ function useAuth() {
|
|
|
564
662
|
return void 0;
|
|
565
663
|
}
|
|
566
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
|
+
);
|
|
567
719
|
const getAuth0Client = useCallback(() => {
|
|
568
720
|
return {
|
|
569
721
|
loginWithRedirect,
|
|
@@ -637,13 +789,17 @@ function useAuth() {
|
|
|
637
789
|
id: auth0User.sub || "",
|
|
638
790
|
email: auth0User.email || "",
|
|
639
791
|
name: auth0User.name || "",
|
|
640
|
-
avatar: auth0User.picture
|
|
792
|
+
avatar: auth0User.picture,
|
|
793
|
+
...typeof auth0User.email_verified === "boolean" ? { emailVerified: auth0User.email_verified } : {}
|
|
641
794
|
} : null,
|
|
795
|
+
needsEmailVerification: isAuthenticated && auth0User?.email_verified === false,
|
|
642
796
|
login,
|
|
643
797
|
logout,
|
|
644
798
|
// Escape hatch for advanced use cases
|
|
645
799
|
getAccessToken,
|
|
646
800
|
getAuth0Client,
|
|
801
|
+
refreshUser,
|
|
802
|
+
requestEmailVerification,
|
|
647
803
|
// Password management
|
|
648
804
|
requestPasswordReset
|
|
649
805
|
};
|
|
@@ -741,6 +897,7 @@ function useNews(options = {}) {
|
|
|
741
897
|
search,
|
|
742
898
|
sortBy = "publishedAt",
|
|
743
899
|
sortOrder = "desc",
|
|
900
|
+
lang,
|
|
744
901
|
publicOnly = false
|
|
745
902
|
} = options;
|
|
746
903
|
const usePublicEndpoint = isPublicMode || publicOnly;
|
|
@@ -757,7 +914,8 @@ function useNews(options = {}) {
|
|
|
757
914
|
sectionId,
|
|
758
915
|
search,
|
|
759
916
|
sortBy,
|
|
760
|
-
sortOrder
|
|
917
|
+
sortOrder,
|
|
918
|
+
lang
|
|
761
919
|
],
|
|
762
920
|
queryFn: async () => {
|
|
763
921
|
const endpoint = usePublicEndpoint ? `/content/public/${orgId}/news` : `/content/members/${orgId}/news`;
|
|
@@ -769,7 +927,8 @@ function useNews(options = {}) {
|
|
|
769
927
|
sectionId,
|
|
770
928
|
search,
|
|
771
929
|
sortBy,
|
|
772
|
-
sortOrder
|
|
930
|
+
sortOrder,
|
|
931
|
+
lang
|
|
773
932
|
});
|
|
774
933
|
},
|
|
775
934
|
staleTime: 1e3 * 60 * 5
|
|
@@ -998,6 +1157,76 @@ function useUpdateFormSubmission() {
|
|
|
998
1157
|
}
|
|
999
1158
|
});
|
|
1000
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
|
+
}
|
|
1001
1230
|
var LINKED_ACCOUNTS_QUERY_KEY = ["axcloud", "linked-accounts"];
|
|
1002
1231
|
function useLinkedAccounts() {
|
|
1003
1232
|
const { client, stage } = useAxCloudContext();
|
|
@@ -1156,6 +1385,245 @@ function useMedia(mediaId) {
|
|
|
1156
1385
|
refetch: query.refetch
|
|
1157
1386
|
};
|
|
1158
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
|
+
}
|
|
1159
1627
|
function LoginButton({
|
|
1160
1628
|
children = "Log in",
|
|
1161
1629
|
returnTo,
|
|
@@ -1399,6 +1867,6 @@ function LinkedAccountsList({
|
|
|
1399
1867
|
] });
|
|
1400
1868
|
}
|
|
1401
1869
|
|
|
1402
|
-
export { AxCloudClient, AxCloudError, AxCloudProvider, LinkedAccountsList, LoginButton, LogoutButton, ModuleGate, ProtectedRoute, createClient, createContentSlotReader, createFormHelper, getClient, getContentSlotMap, isAxCloudError, submitForm, useAuth, useAvatar, useAxCloudContext, useBranding, useContent, useContentItem, useFormStats, useForms, useLinkedAccounts, useLogo, useMedia, useMediaList, useModuleAccess, useMySection, useNews, useOrg, usePageContent, 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 };
|
|
1403
1871
|
//# sourceMappingURL=index.mjs.map
|
|
1404
1872
|
//# sourceMappingURL=index.mjs.map
|