@singi-labs/sifa-sdk 0.10.18 → 0.11.1

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.
@@ -1033,8 +1033,36 @@ async function fetchMyRoadmapVotes(config, options = {}) {
1033
1033
  return [];
1034
1034
  }
1035
1035
  }
1036
- function castRoadmapVote(config, key, options = {}) {
1037
- return apiWrite(config, `/api/roadmap/votes/${encodeURIComponent(key)}`, "POST", options);
1036
+ async function castRoadmapVote(config, key, options = {}) {
1037
+ const fetchFn = config.fetch ?? globalThis.fetch;
1038
+ const url = `${config.baseUrl}/api/roadmap/votes/${encodeURIComponent(key)}`;
1039
+ try {
1040
+ const res = await fetchFn(url, {
1041
+ method: "POST",
1042
+ headers: { "Content-Type": "application/json", ...options.headers ?? {} },
1043
+ credentials: options.credentials ?? "include",
1044
+ signal: options.signal ?? AbortSignal.timeout(options.timeoutMs ?? 1e4)
1045
+ });
1046
+ if (!res.ok) {
1047
+ if (res.status === 403) {
1048
+ try {
1049
+ const body = await res.json();
1050
+ if (body.error === "ScopeInsufficient") {
1051
+ return {
1052
+ ok: false,
1053
+ error: { type: "scope_insufficient", requiredScope: body.requiredScope }
1054
+ };
1055
+ }
1056
+ } catch {
1057
+ }
1058
+ }
1059
+ return { ok: false, error: { type: "error" } };
1060
+ }
1061
+ const data = await res.json();
1062
+ return { ok: true, data };
1063
+ } catch {
1064
+ return { ok: false, error: { type: "error" } };
1065
+ }
1038
1066
  }
1039
1067
  function retractRoadmapVote(config, key, options = {}) {
1040
1068
  return apiWrite(config, `/api/roadmap/votes/${encodeURIComponent(key)}`, "DELETE", options);
@@ -2219,7 +2247,7 @@ function useCastRoadmapVote(options) {
2219
2247
  return reactQuery.useMutation({
2220
2248
  mutationFn: (key) => castRoadmapVote(config, key),
2221
2249
  onSuccess: async (result, variables, onMutateResult, context) => {
2222
- if (result.success) {
2250
+ if (result.ok) {
2223
2251
  await invalidateRoadmap(queryClient);
2224
2252
  }
2225
2253
  await options?.onSuccess?.(result, variables, onMutateResult, context);