@singi-labs/sifa-sdk 0.10.18 → 0.11.0

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.
@@ -2145,8 +2145,36 @@ async function fetchMyRoadmapVotes(config, options = {}) {
2145
2145
  return [];
2146
2146
  }
2147
2147
  }
2148
- function castRoadmapVote(config, key, options = {}) {
2149
- return apiWrite(config, `/api/roadmap/votes/${encodeURIComponent(key)}`, "POST", options);
2148
+ async function castRoadmapVote(config, key, options = {}) {
2149
+ const fetchFn = config.fetch ?? globalThis.fetch;
2150
+ const url = `${config.baseUrl}/api/roadmap/votes/${encodeURIComponent(key)}`;
2151
+ try {
2152
+ const res = await fetchFn(url, {
2153
+ method: "POST",
2154
+ headers: { "Content-Type": "application/json", ...options.headers ?? {} },
2155
+ credentials: options.credentials ?? "include",
2156
+ signal: options.signal ?? AbortSignal.timeout(options.timeoutMs ?? 1e4)
2157
+ });
2158
+ if (!res.ok) {
2159
+ if (res.status === 403) {
2160
+ try {
2161
+ const body = await res.json();
2162
+ if (body.error === "ScopeInsufficient") {
2163
+ return {
2164
+ ok: false,
2165
+ error: { type: "scope_insufficient", requiredScope: body.requiredScope }
2166
+ };
2167
+ }
2168
+ } catch {
2169
+ }
2170
+ }
2171
+ return { ok: false, error: { type: "error" } };
2172
+ }
2173
+ const data = await res.json();
2174
+ return { ok: true, data };
2175
+ } catch {
2176
+ return { ok: false, error: { type: "error" } };
2177
+ }
2150
2178
  }
2151
2179
  function retractRoadmapVote(config, key, options = {}) {
2152
2180
  return apiWrite(config, `/api/roadmap/votes/${encodeURIComponent(key)}`, "DELETE", options);
@@ -2178,7 +2206,7 @@ function useCastRoadmapVote(options) {
2178
2206
  return reactQuery.useMutation({
2179
2207
  mutationFn: (key) => castRoadmapVote(config, key),
2180
2208
  onSuccess: async (result, variables, onMutateResult, context) => {
2181
- if (result.success) {
2209
+ if (result.ok) {
2182
2210
  await invalidateRoadmap(queryClient);
2183
2211
  }
2184
2212
  await options?.onSuccess?.(result, variables, onMutateResult, context);