@axcode/axcloud-sdk 0.4.0-dev.bf5c2c0 → 0.4.0-dev.f9603ab
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 +27 -1
- package/dist/index.d.mts +59 -7
- package/dist/index.d.ts +59 -7
- package/dist/index.js +42 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -77,6 +77,26 @@ async function submitForm(apiUrl, submission) {
|
|
|
77
77
|
throw primaryError;
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
+
async function getMembershipSections(apiUrl, options) {
|
|
81
|
+
const baseUrl = apiUrl.replace(/\/$/, "");
|
|
82
|
+
const response = await fetch(
|
|
83
|
+
`${baseUrl}/public/membership-sections?site=${encodeURIComponent(options.site)}`,
|
|
84
|
+
{
|
|
85
|
+
method: "GET",
|
|
86
|
+
headers: { "X-Api-Key": options.apiKey },
|
|
87
|
+
signal: options.signal
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
if (!response.ok) {
|
|
91
|
+
const error = await response.json().catch(() => ({}));
|
|
92
|
+
throw new Error(error.message || `Membership sections request failed (${response.status})`);
|
|
93
|
+
}
|
|
94
|
+
const result = await response.json().catch(() => ({}));
|
|
95
|
+
const sections = Array.isArray(result?.sections) ? result.sections : [];
|
|
96
|
+
return sections.filter(
|
|
97
|
+
(section) => !!section && typeof section.id === "string" && typeof section.name === "string"
|
|
98
|
+
).map(({ id, name }) => ({ id, name }));
|
|
99
|
+
}
|
|
80
100
|
function createFormHelper(config) {
|
|
81
101
|
return {
|
|
82
102
|
/**
|
|
@@ -109,6 +129,14 @@ function createFormHelper(config) {
|
|
|
109
129
|
email,
|
|
110
130
|
data
|
|
111
131
|
}),
|
|
132
|
+
/**
|
|
133
|
+
* List the sections offered in the membership application
|
|
134
|
+
*/
|
|
135
|
+
getMembershipSections: (options = {}) => getMembershipSections(config.apiUrl, {
|
|
136
|
+
apiKey: config.apiKey,
|
|
137
|
+
site: config.site,
|
|
138
|
+
signal: options.signal
|
|
139
|
+
}),
|
|
112
140
|
/**
|
|
113
141
|
* Generic submit function
|
|
114
142
|
*/
|
|
@@ -859,17 +887,18 @@ function useSections() {
|
|
|
859
887
|
refetch: query.refetch
|
|
860
888
|
};
|
|
861
889
|
}
|
|
890
|
+
var FORMS_ADMIN_PATH = "/forms/admin";
|
|
862
891
|
function useForms(options = {}) {
|
|
863
|
-
const { client,
|
|
892
|
+
const { client, orgId } = useAxCloudContext();
|
|
864
893
|
const { formType, status, limit = 50, cursor } = options;
|
|
865
894
|
const query = useQuery({
|
|
866
|
-
queryKey: ["axcloud", "forms", "submissions",
|
|
895
|
+
queryKey: ["axcloud", "forms", "submissions", orgId, formType, status, limit, cursor],
|
|
867
896
|
queryFn: async () => {
|
|
868
|
-
const params = { limit };
|
|
897
|
+
const params = { org_id: orgId, limit };
|
|
869
898
|
if (formType) params.form_type = formType;
|
|
870
899
|
if (status) params.status = status;
|
|
871
900
|
if (cursor) params.cursor = cursor;
|
|
872
|
-
return client.get(
|
|
901
|
+
return client.get(`${FORMS_ADMIN_PATH}/submissions`, params);
|
|
873
902
|
},
|
|
874
903
|
staleTime: 1e3 * 30
|
|
875
904
|
// 30 seconds
|
|
@@ -886,12 +915,12 @@ function useForms(options = {}) {
|
|
|
886
915
|
};
|
|
887
916
|
}
|
|
888
917
|
function useFormStats(options = {}) {
|
|
889
|
-
const { client,
|
|
918
|
+
const { client, orgId } = useAxCloudContext();
|
|
890
919
|
const { days = 30 } = options;
|
|
891
920
|
const query = useQuery({
|
|
892
|
-
queryKey: ["axcloud", "forms", "stats",
|
|
921
|
+
queryKey: ["axcloud", "forms", "stats", orgId, days],
|
|
893
922
|
queryFn: async () => {
|
|
894
|
-
return client.get(
|
|
923
|
+
return client.get(`${FORMS_ADMIN_PATH}/stats`, { org_id: orgId, days });
|
|
895
924
|
},
|
|
896
925
|
staleTime: 1e3 * 60 * 5
|
|
897
926
|
// 5 minutes
|
|
@@ -907,7 +936,7 @@ function useFormStats(options = {}) {
|
|
|
907
936
|
};
|
|
908
937
|
}
|
|
909
938
|
function useUpdateFormSubmission() {
|
|
910
|
-
const { client,
|
|
939
|
+
const { client, orgId } = useAxCloudContext();
|
|
911
940
|
const queryClient = useQueryClient();
|
|
912
941
|
return useMutation({
|
|
913
942
|
mutationFn: async ({
|
|
@@ -915,7 +944,10 @@ function useUpdateFormSubmission() {
|
|
|
915
944
|
status,
|
|
916
945
|
notes
|
|
917
946
|
}) => {
|
|
918
|
-
return client.patch(
|
|
947
|
+
return client.patch(
|
|
948
|
+
`${FORMS_ADMIN_PATH}/submissions/${encodeURIComponent(submissionId)}?org_id=${encodeURIComponent(orgId)}`,
|
|
949
|
+
{ status, notes }
|
|
950
|
+
);
|
|
919
951
|
},
|
|
920
952
|
onSuccess: () => {
|
|
921
953
|
queryClient.invalidateQueries({ queryKey: ["axcloud", "forms"] });
|
|
@@ -1533,6 +1565,6 @@ function LinkedAccountsList({
|
|
|
1533
1565
|
] });
|
|
1534
1566
|
}
|
|
1535
1567
|
|
|
1536
|
-
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 };
|
|
1568
|
+
export { AxCloudProvider, LinkedAccountsList, LoginButton, LogoutButton, ModuleGate, ProtectedRoute, castVote, castVoteWithCode, checkEligibility, checkVotingCode, createFormHelper, getBallot, getMembershipSections, 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 };
|
|
1537
1569
|
//# sourceMappingURL=index.mjs.map
|
|
1538
1570
|
//# sourceMappingURL=index.mjs.map
|