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