@axcode/axcloud-sdk 0.2.0-dev.85285e0 → 0.2.0-dev.f9f97e8
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 +23 -0
- package/dist/barnsport.d.mts +12 -3
- package/dist/barnsport.d.ts +12 -3
- package/dist/barnsport.js +21 -17
- package/dist/barnsport.mjs +2 -2
- package/dist/{chunk-DI4M6A7K.js → chunk-2IVJTMRB.js} +264 -219
- package/dist/chunk-2IVJTMRB.js.map +1 -0
- package/dist/{chunk-HRNRGCCT.mjs → chunk-7IPCZJ5Q.mjs} +16 -5
- package/dist/chunk-7IPCZJ5Q.mjs.map +1 -0
- package/dist/chunk-7K5N3DQ4.js +231 -0
- package/dist/chunk-7K5N3DQ4.js.map +1 -0
- package/dist/{chunk-F3JPEND3.mjs → chunk-CACQMQCJ.mjs} +259 -214
- package/dist/chunk-CACQMQCJ.mjs.map +1 -0
- package/dist/chunk-PMMCOWL3.mjs +223 -0
- package/dist/chunk-PMMCOWL3.mjs.map +1 -0
- package/dist/{chunk-EX66R5IA.js → chunk-ZOQAXLCZ.js} +29 -17
- package/dist/chunk-ZOQAXLCZ.js.map +1 -0
- package/dist/index.d.mts +4 -79
- package/dist/index.d.ts +4 -79
- package/dist/index.js +81 -320
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -260
- package/dist/index.mjs.map +1 -1
- package/dist/public.d.mts +2 -2
- package/dist/public.d.ts +2 -2
- package/dist/public.js +29 -9
- package/dist/public.mjs +4 -4
- package/dist/{useBarnsport-1DObGZDl.d.mts → useBarnsport-wM5BNfke.d.mts} +35 -4
- package/dist/{useBarnsport-1DObGZDl.d.ts → useBarnsport-wM5BNfke.d.ts} +35 -4
- package/dist/{analytics-LYZxP7PC.d.mts → useContent-1WbKvPY4.d.mts} +77 -1
- package/dist/{analytics-BOxmSWNt.d.ts → useContent-Cl7dvERE.d.ts} +77 -1
- package/package.json +1 -1
- package/dist/chunk-2A5NJAFA.mjs +0 -15
- package/dist/chunk-2A5NJAFA.mjs.map +0 -1
- package/dist/chunk-DI4M6A7K.js.map +0 -1
- package/dist/chunk-DSWRJZWR.js +0 -18
- package/dist/chunk-DSWRJZWR.js.map +0 -1
- package/dist/chunk-EX66R5IA.js.map +0 -1
- package/dist/chunk-F3JPEND3.mjs.map +0 -1
- package/dist/chunk-HRNRGCCT.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,97 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
export { useBarnsportActivities, useBarnsportActivity, useBarnsportMunicipalities, useBarnsportSitemap, useBarnsportSport, useBarnsportSports, useSubmitBarnsportInterest } from './chunk-
|
|
4
|
-
import { useAxCloudContext, AxCloudContext } from './chunk-
|
|
5
|
-
export { useAxCloudContext } from './chunk-
|
|
1
|
+
import { useContent, useAnalyticsRuntime } from './chunk-CACQMQCJ.mjs';
|
|
2
|
+
export { createContentSlotReader, fetchAnalyticsPublicConfig, getContentSlotMap, isAllowedAnalyticsEvent, isLocalAnalyticsHostname, sanitizeAnalyticsEventData, sanitizeAnalyticsPath, useAnalytics, useAnalyticsRuntime, useContent, useContentItem, usePageContent } from './chunk-CACQMQCJ.mjs';
|
|
3
|
+
export { useBarnsportActivities, useBarnsportActivity, useBarnsportMunicipalities, useBarnsportSitemap, useBarnsportSport, useBarnsportSports, useSubmitBarnsportInterest } from './chunk-7IPCZJ5Q.mjs';
|
|
4
|
+
import { useAxCloudContext, isAxCloudError, AxCloudClient, AxCloudContext } from './chunk-PMMCOWL3.mjs';
|
|
5
|
+
export { AxCloudClient, AxCloudError, createClient, getClient, isAxCloudError, useAxCloudContext } from './chunk-PMMCOWL3.mjs';
|
|
6
6
|
import { useState, useMemo, useCallback, useLayoutEffect, useRef } from 'react';
|
|
7
7
|
import { Auth0Provider, useAuth0 } from '@auth0/auth0-react';
|
|
8
8
|
import { QueryClientProvider, useQuery, useQueryClient, useMutation, QueryClient } from '@tanstack/react-query';
|
|
9
9
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
10
10
|
|
|
11
|
-
// src/core/contentSlots.ts
|
|
12
|
-
var SLOT_ATTRIBUTE_KEYS = ["slot", "field", "key", "name"];
|
|
13
|
-
function getContentSlotMap(content) {
|
|
14
|
-
const fields = isRecord(content?.fields) ? { ...content?.fields } : {};
|
|
15
|
-
for (const block of content?.blocks || []) {
|
|
16
|
-
const slot = getBlockSlot(block);
|
|
17
|
-
if (!slot) continue;
|
|
18
|
-
if (!(slot in fields)) fields[slot] = blockToSlotValue(block);
|
|
19
|
-
}
|
|
20
|
-
return fields;
|
|
21
|
-
}
|
|
22
|
-
function createContentSlotReader(content) {
|
|
23
|
-
const fields = getContentSlotMap(content);
|
|
24
|
-
const value = (key, fallback) => {
|
|
25
|
-
return key in fields ? fields[key] : fallback;
|
|
26
|
-
};
|
|
27
|
-
const unsafeHtml = (key, fallback = "") => stringifySlotValue(value(key, fallback));
|
|
28
|
-
return {
|
|
29
|
-
fields,
|
|
30
|
-
value,
|
|
31
|
-
text: (key, fallback = "") => stringifySlotValue(value(key, fallback)),
|
|
32
|
-
html: unsafeHtml,
|
|
33
|
-
unsafeHtml,
|
|
34
|
-
list: (key, fallback = []) => slotValueToList(value(key, fallback)),
|
|
35
|
-
image: (key, fallback) => slotValueToImage(value(key, fallback))
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function getBlockSlot(block) {
|
|
39
|
-
const attributes = block.attributes || {};
|
|
40
|
-
for (const key of SLOT_ATTRIBUTE_KEYS) {
|
|
41
|
-
const value = attributes[key];
|
|
42
|
-
if (typeof value === "string" && value.trim()) return value.trim();
|
|
43
|
-
}
|
|
44
|
-
return void 0;
|
|
45
|
-
}
|
|
46
|
-
function blockToSlotValue(block) {
|
|
47
|
-
if (block.attributes && "value" in block.attributes) {
|
|
48
|
-
return block.attributes.value;
|
|
49
|
-
}
|
|
50
|
-
if (block.type === "list") {
|
|
51
|
-
return Array.isArray(block.items) ? block.items : [];
|
|
52
|
-
}
|
|
53
|
-
if (block.type === "image" && block.url) {
|
|
54
|
-
return {
|
|
55
|
-
url: block.url,
|
|
56
|
-
alt: block.alt,
|
|
57
|
-
caption: block.caption
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
return block.content ?? "";
|
|
61
|
-
}
|
|
62
|
-
function stringifySlotValue(value) {
|
|
63
|
-
if (value === void 0 || value === null) return "";
|
|
64
|
-
if (typeof value === "string") return value;
|
|
65
|
-
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
66
|
-
if (Array.isArray(value)) return value.map((item) => stringifySlotValue(item)).filter(Boolean).join("\n");
|
|
67
|
-
return "";
|
|
68
|
-
}
|
|
69
|
-
function slotValueToList(value) {
|
|
70
|
-
if (Array.isArray(value)) {
|
|
71
|
-
return value.map((item) => stringifySlotValue(item)).filter(Boolean);
|
|
72
|
-
}
|
|
73
|
-
if (typeof value === "string") {
|
|
74
|
-
return value.split(/\r?\n/).map((item) => item.trim()).filter(Boolean);
|
|
75
|
-
}
|
|
76
|
-
return [];
|
|
77
|
-
}
|
|
78
|
-
function slotValueToImage(value) {
|
|
79
|
-
if (isRecord(value) && typeof value.url === "string") {
|
|
80
|
-
return {
|
|
81
|
-
url: value.url,
|
|
82
|
-
alt: typeof value.alt === "string" ? value.alt : void 0,
|
|
83
|
-
caption: typeof value.caption === "string" ? value.caption : void 0
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
if (typeof value === "string" && value) {
|
|
87
|
-
return { url: value };
|
|
88
|
-
}
|
|
89
|
-
return void 0;
|
|
90
|
-
}
|
|
91
|
-
function isRecord(value) {
|
|
92
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
11
|
// src/core/types.ts
|
|
96
12
|
function userHasPermission(user, permission) {
|
|
97
13
|
if (user.permissions && user.permissions.length > 0) {
|
|
@@ -883,176 +799,6 @@ function useOrg() {
|
|
|
883
799
|
};
|
|
884
800
|
}
|
|
885
801
|
|
|
886
|
-
// src/react/contentQueryPolicy.ts
|
|
887
|
-
var CONTENT_STALE_TIME_MS = 6e4;
|
|
888
|
-
function shouldRetryContentRequest(failureCount, error) {
|
|
889
|
-
if (isAxCloudError(error) && error.status >= 400 && error.status < 500) {
|
|
890
|
-
return false;
|
|
891
|
-
}
|
|
892
|
-
return failureCount < 2;
|
|
893
|
-
}
|
|
894
|
-
function normalizeContentCollectionType(contentType) {
|
|
895
|
-
switch (contentType.toLowerCase()) {
|
|
896
|
-
case "news":
|
|
897
|
-
return "news";
|
|
898
|
-
case "page":
|
|
899
|
-
case "pages":
|
|
900
|
-
return "pages";
|
|
901
|
-
case "event":
|
|
902
|
-
case "events":
|
|
903
|
-
return "events";
|
|
904
|
-
default:
|
|
905
|
-
throw new Error(`Unsupported AxCloud content collection type: ${contentType}`);
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
function normalizeContentDetailType(contentType) {
|
|
909
|
-
switch (contentType.toLowerCase()) {
|
|
910
|
-
case "news":
|
|
911
|
-
return "news";
|
|
912
|
-
case "page":
|
|
913
|
-
case "pages":
|
|
914
|
-
return "page";
|
|
915
|
-
case "event":
|
|
916
|
-
case "events":
|
|
917
|
-
return "event";
|
|
918
|
-
default:
|
|
919
|
-
throw new Error(`Unsupported AxCloud content detail type: ${contentType}`);
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
function getContentAccessState(context, publicOnly) {
|
|
923
|
-
if (publicOnly) {
|
|
924
|
-
return { mode: "public", enabled: true, subject: "anonymous" };
|
|
925
|
-
}
|
|
926
|
-
const isLoading = context.isAuthLoading ?? false;
|
|
927
|
-
if (isLoading) {
|
|
928
|
-
return { mode: "pending", enabled: false, subject: "auth-loading" };
|
|
929
|
-
}
|
|
930
|
-
const hasExplicitAuthState = typeof context.isAuthenticated === "boolean";
|
|
931
|
-
const isAuthenticated = context.isAuthenticated ?? !context.isPublicMode;
|
|
932
|
-
if (!isAuthenticated) {
|
|
933
|
-
return { mode: "public", enabled: true, subject: "anonymous" };
|
|
934
|
-
}
|
|
935
|
-
if (hasExplicitAuthState && !context.authSubject) {
|
|
936
|
-
return { mode: "pending", enabled: false, subject: "auth-subject-pending" };
|
|
937
|
-
}
|
|
938
|
-
const subject = context.authSubject || "legacy-authenticated-session";
|
|
939
|
-
return { mode: "member", enabled: Boolean(subject), subject };
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
// src/react/hooks/useContent.ts
|
|
943
|
-
function useContent(contentType, options = {}) {
|
|
944
|
-
const context = useAxCloudContext();
|
|
945
|
-
const { client, config, orgId, stage } = context;
|
|
946
|
-
const collectionType = normalizeContentCollectionType(contentType);
|
|
947
|
-
const {
|
|
948
|
-
publicOnly = false,
|
|
949
|
-
page = 1,
|
|
950
|
-
pageSize = 20,
|
|
951
|
-
search,
|
|
952
|
-
sortBy = collectionType === "news" ? "publishedAt" : "createdAt",
|
|
953
|
-
sortOrder = "desc",
|
|
954
|
-
tags,
|
|
955
|
-
lang
|
|
956
|
-
} = options;
|
|
957
|
-
const access = getContentAccessState(context, publicOnly);
|
|
958
|
-
const deliveryScope = access.mode === "member" ? "members" : "public";
|
|
959
|
-
const params = {
|
|
960
|
-
page,
|
|
961
|
-
pageSize,
|
|
962
|
-
search,
|
|
963
|
-
sort: sortBy,
|
|
964
|
-
order: sortOrder,
|
|
965
|
-
tags: tags?.length ? tags.join(",") : void 0,
|
|
966
|
-
lang
|
|
967
|
-
};
|
|
968
|
-
const query = useQuery({
|
|
969
|
-
queryKey: [
|
|
970
|
-
"axcloud",
|
|
971
|
-
"content",
|
|
972
|
-
"collection",
|
|
973
|
-
stage,
|
|
974
|
-
config.apiUrl,
|
|
975
|
-
orgId,
|
|
976
|
-
access.mode,
|
|
977
|
-
access.subject,
|
|
978
|
-
collectionType,
|
|
979
|
-
params
|
|
980
|
-
],
|
|
981
|
-
queryFn: () => client.get(
|
|
982
|
-
`/content/${deliveryScope}/${orgId}/${collectionType}`,
|
|
983
|
-
params
|
|
984
|
-
),
|
|
985
|
-
enabled: access.enabled,
|
|
986
|
-
staleTime: CONTENT_STALE_TIME_MS,
|
|
987
|
-
refetchOnWindowFocus: true,
|
|
988
|
-
retry: shouldRetryContentRequest
|
|
989
|
-
});
|
|
990
|
-
const items = query.data?.items ?? [];
|
|
991
|
-
return {
|
|
992
|
-
data: items,
|
|
993
|
-
count: query.data?.count ?? items.length,
|
|
994
|
-
total: query.data?.total ?? items.length,
|
|
995
|
-
page: query.data?.page ?? page,
|
|
996
|
-
pageSize: query.data?.pageSize ?? pageSize,
|
|
997
|
-
hasMore: query.data?.hasMore ?? false,
|
|
998
|
-
nextCursor: query.data?.nextCursor,
|
|
999
|
-
isLoading: access.mode === "pending" || query.isLoading,
|
|
1000
|
-
isFetching: query.isFetching,
|
|
1001
|
-
isError: query.isError,
|
|
1002
|
-
error: query.error,
|
|
1003
|
-
refetch: query.refetch
|
|
1004
|
-
};
|
|
1005
|
-
}
|
|
1006
|
-
function useContentItem(contentType, idOrSlug, options = {}) {
|
|
1007
|
-
const context = useAxCloudContext();
|
|
1008
|
-
const { client, config, orgId, stage } = context;
|
|
1009
|
-
const detailType = normalizeContentDetailType(contentType);
|
|
1010
|
-
const { publicOnly = false, lang } = options;
|
|
1011
|
-
const access = getContentAccessState(context, publicOnly);
|
|
1012
|
-
const deliveryScope = access.mode === "member" ? "members" : "public";
|
|
1013
|
-
const query = useQuery({
|
|
1014
|
-
queryKey: [
|
|
1015
|
-
"axcloud",
|
|
1016
|
-
"content",
|
|
1017
|
-
"item",
|
|
1018
|
-
stage,
|
|
1019
|
-
config.apiUrl,
|
|
1020
|
-
orgId,
|
|
1021
|
-
access.mode,
|
|
1022
|
-
access.subject,
|
|
1023
|
-
detailType,
|
|
1024
|
-
idOrSlug,
|
|
1025
|
-
lang
|
|
1026
|
-
],
|
|
1027
|
-
queryFn: () => {
|
|
1028
|
-
const encodedIdOrSlug = encodeURIComponent(idOrSlug);
|
|
1029
|
-
const endpoint = `/content/${deliveryScope}/${orgId}/items/${detailType}/${encodedIdOrSlug}`;
|
|
1030
|
-
return lang ? client.get(endpoint, { lang }) : client.get(endpoint);
|
|
1031
|
-
},
|
|
1032
|
-
enabled: access.enabled && Boolean(idOrSlug),
|
|
1033
|
-
staleTime: CONTENT_STALE_TIME_MS,
|
|
1034
|
-
refetchOnWindowFocus: true,
|
|
1035
|
-
retry: shouldRetryContentRequest
|
|
1036
|
-
});
|
|
1037
|
-
return {
|
|
1038
|
-
data: query.data ?? null,
|
|
1039
|
-
isLoading: access.mode === "pending" || query.isLoading,
|
|
1040
|
-
isFetching: query.isFetching,
|
|
1041
|
-
isError: query.isError,
|
|
1042
|
-
error: query.error,
|
|
1043
|
-
refetch: query.refetch
|
|
1044
|
-
};
|
|
1045
|
-
}
|
|
1046
|
-
function usePageContent(slug, options = {}) {
|
|
1047
|
-
const state = useContentItem("page", slug, options);
|
|
1048
|
-
const reader = useMemo(() => createContentSlotReader(state.data), [state.data]);
|
|
1049
|
-
return {
|
|
1050
|
-
...state,
|
|
1051
|
-
page: state.data,
|
|
1052
|
-
...reader
|
|
1053
|
-
};
|
|
1054
|
-
}
|
|
1055
|
-
|
|
1056
802
|
// src/react/hooks/useNews.ts
|
|
1057
803
|
function useNews(options = {}) {
|
|
1058
804
|
return useContent("news", options);
|
|
@@ -1765,6 +1511,6 @@ function LinkedAccountsList({
|
|
|
1765
1511
|
] });
|
|
1766
1512
|
}
|
|
1767
1513
|
|
|
1768
|
-
export { AxCloudProvider, LinkedAccountsList, LoginButton, LogoutButton, ModuleGate, ProtectedRoute, castVote, castVoteWithCode, checkEligibility, checkVotingCode,
|
|
1514
|
+
export { AxCloudProvider, LinkedAccountsList, LoginButton, LogoutButton, ModuleGate, ProtectedRoute, castVote, castVoteWithCode, checkEligibility, checkVotingCode, createFormHelper, getBallot, getVotingReceipt, submitForm, useAuth, useAvatar, useBranding, useCodeBallot, useDocumentDownload, useDocuments, useFormStats, useForms, useLinkedAccounts, useLogo, useMedia, useMediaList, useMemberDocumentDownload, useMemberDocumentFolders, useMemberDocuments, useModuleAccess, useMySection, useNews, useOrg, useSections, useUpdateFormSubmission, useUpdateMyProfile, useUser, userHasAllPermissions, userHasAnyPermission, userHasPermission };
|
|
1769
1515
|
//# sourceMappingURL=index.mjs.map
|
|
1770
1516
|
//# sourceMappingURL=index.mjs.map
|