@singi-labs/sifa-sdk 0.10.17 → 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.
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode } from 'react';
3
- import { S as SifaApiConfig, s as sifaQueryKeys, W as WriteResult, a4 as RefreshPdsResult, ag as UpdateProfileOverrideInput, ah as UpdateProfileSelfInput, ai as UploadAvatarResult, i as CreateResult, T as ProfileLocationInput, j as ExternalAccountInput, h as CreateExternalAccountResult, aj as VerifyExternalAccountResult, E as EndorsementInput, a3 as RefreshOrcidPublicationsResult, B as BulkHideProfileItemInput, O as HideProfileItemInput, ad as StatsResponse, g as AppRegistryEntry, L as HiddenApp, v as FilterOptions, a8 as SearchFilters, a9 as SearchResponse, ac as SkillSearchResult, k as FeaturedProfile, ab as SimilarProfile, u as FetchSuggestionsOptions, af as SuggestionsResponse, z as FollowUserResult, n as FetchFollowListOptions, w as FollowListPage, G as FollowingResponse, p as FetchFollowingFeedOptions, o as FetchFollowProfilePageOptions, y as FollowProfilePageResponse, F as FeatureAllowlistResponse, l as FetchActivityFeedOptions, b as ActivityFeedResponse, e as ActivityTeaserResponse, K as HeatmapResponse, a as AccountCheckResult, a2 as ReactionStatus, a1 as ReactionResult, a0 as ReactionError, a7 as RoadmapVotesResponse, D as DeleteAccountResult } from '../../keys-CMaEcp0g.cjs';
4
- export { aa as SifaQueryKey } from '../../keys-CMaEcp0g.cjs';
3
+ import { S as SifaApiConfig, s as sifaQueryKeys, W as WriteResult, a5 as RefreshPdsResult, aj as UpdateProfileOverrideInput, ak as UpdateProfileSelfInput, al as UploadAvatarResult, j as CreateResult, U as ProfileLocationInput, k as ExternalAccountInput, i as CreateExternalAccountResult, am as VerifyExternalAccountResult, E as EndorsementInput, a4 as RefreshOrcidPublicationsResult, B as BulkHideProfileItemInput, P as HideProfileItemInput, ag as StatsResponse, g as AppRegistryEntry, M as HiddenApp, w as FilterOptions, ab as SearchFilters, ac as SearchResponse, af as SkillSearchResult, l as FeaturedProfile, ae as SimilarProfile, v as FetchSuggestionsOptions, ai as SuggestionsResponse, G as FollowUserResult, o as FetchFollowListOptions, x as FollowListPage, H as FollowingResponse, q as FetchFollowingFeedOptions, p as FetchFollowProfilePageOptions, z as FollowProfilePageResponse, F as FeatureAllowlistResponse, m as FetchActivityFeedOptions, b as ActivityFeedResponse, e as ActivityTeaserResponse, L as HeatmapResponse, a as AccountCheckResult, a3 as ReactionStatus, a2 as ReactionResult, a1 as ReactionError, aa as RoadmapVotesResponse, C as CastRoadmapVoteResult, D as DeleteAccountResult } from '../../keys-BDzlCEo1.cjs';
4
+ export { ad as SifaQueryKey } from '../../keys-BDzlCEo1.cjs';
5
5
  import * as _tanstack_react_query from '@tanstack/react-query';
6
6
  import { UseQueryOptions, UseMutationOptions, UseInfiniteQueryOptions, InfiniteData } from '@tanstack/react-query';
7
7
  import { c as Profile, r as ProfilePosition, w as SkillRef, E as ExternalAccount, S as SkillSuggestion } from '../../adult-content-o0BxhFzc.cjs';
@@ -459,8 +459,14 @@ declare function useRoadmapVotes(options?: Omit<UseQueryOptions<RoadmapVotesResp
459
459
  /** Roadmap items the authenticated viewer has voted on. Returns `[]` data on error. */
460
460
  declare function useMyRoadmapVotes(options?: Omit<UseQueryOptions<string[], Error, string[], ReturnType<typeof sifaQueryKeys.roadmap.myVotes>>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<NoInfer<string[]>, Error>;
461
461
 
462
- /** React hook for casting a roadmap vote. Variable: the item key. */
463
- declare function useCastRoadmapVote(options?: Omit<UseMutationOptions<WriteResult, Error, string>, 'mutationFn'>): _tanstack_react_query.UseMutationResult<WriteResult, Error, string, unknown>;
462
+ /**
463
+ * React hook for casting a roadmap vote. Variable: the item key.
464
+ *
465
+ * Returns the discriminated-union result so callers can detect
466
+ * `scope_insufficient` and trigger an OAuth scope-upgrade flow
467
+ * (see {@link castRoadmapVote}).
468
+ */
469
+ declare function useCastRoadmapVote(options?: Omit<UseMutationOptions<CastRoadmapVoteResult, Error, string>, 'mutationFn'>): _tanstack_react_query.UseMutationResult<CastRoadmapVoteResult, Error, string, unknown>;
464
470
  /** React hook for retracting a previously-cast roadmap vote. */
465
471
  declare function useRetractRoadmapVote(options?: Omit<UseMutationOptions<WriteResult, Error, string>, 'mutationFn'>): _tanstack_react_query.UseMutationResult<WriteResult, Error, string, unknown>;
466
472
 
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode } from 'react';
3
- import { S as SifaApiConfig, s as sifaQueryKeys, W as WriteResult, a4 as RefreshPdsResult, ag as UpdateProfileOverrideInput, ah as UpdateProfileSelfInput, ai as UploadAvatarResult, i as CreateResult, T as ProfileLocationInput, j as ExternalAccountInput, h as CreateExternalAccountResult, aj as VerifyExternalAccountResult, E as EndorsementInput, a3 as RefreshOrcidPublicationsResult, B as BulkHideProfileItemInput, O as HideProfileItemInput, ad as StatsResponse, g as AppRegistryEntry, L as HiddenApp, v as FilterOptions, a8 as SearchFilters, a9 as SearchResponse, ac as SkillSearchResult, k as FeaturedProfile, ab as SimilarProfile, u as FetchSuggestionsOptions, af as SuggestionsResponse, z as FollowUserResult, n as FetchFollowListOptions, w as FollowListPage, G as FollowingResponse, p as FetchFollowingFeedOptions, o as FetchFollowProfilePageOptions, y as FollowProfilePageResponse, F as FeatureAllowlistResponse, l as FetchActivityFeedOptions, b as ActivityFeedResponse, e as ActivityTeaserResponse, K as HeatmapResponse, a as AccountCheckResult, a2 as ReactionStatus, a1 as ReactionResult, a0 as ReactionError, a7 as RoadmapVotesResponse, D as DeleteAccountResult } from '../../keys-B_Z735bY.js';
4
- export { aa as SifaQueryKey } from '../../keys-B_Z735bY.js';
3
+ import { S as SifaApiConfig, s as sifaQueryKeys, W as WriteResult, a5 as RefreshPdsResult, aj as UpdateProfileOverrideInput, ak as UpdateProfileSelfInput, al as UploadAvatarResult, j as CreateResult, U as ProfileLocationInput, k as ExternalAccountInput, i as CreateExternalAccountResult, am as VerifyExternalAccountResult, E as EndorsementInput, a4 as RefreshOrcidPublicationsResult, B as BulkHideProfileItemInput, P as HideProfileItemInput, ag as StatsResponse, g as AppRegistryEntry, M as HiddenApp, w as FilterOptions, ab as SearchFilters, ac as SearchResponse, af as SkillSearchResult, l as FeaturedProfile, ae as SimilarProfile, v as FetchSuggestionsOptions, ai as SuggestionsResponse, G as FollowUserResult, o as FetchFollowListOptions, x as FollowListPage, H as FollowingResponse, q as FetchFollowingFeedOptions, p as FetchFollowProfilePageOptions, z as FollowProfilePageResponse, F as FeatureAllowlistResponse, m as FetchActivityFeedOptions, b as ActivityFeedResponse, e as ActivityTeaserResponse, L as HeatmapResponse, a as AccountCheckResult, a3 as ReactionStatus, a2 as ReactionResult, a1 as ReactionError, aa as RoadmapVotesResponse, C as CastRoadmapVoteResult, D as DeleteAccountResult } from '../../keys-D1qvOp5Q.js';
4
+ export { ad as SifaQueryKey } from '../../keys-D1qvOp5Q.js';
5
5
  import * as _tanstack_react_query from '@tanstack/react-query';
6
6
  import { UseQueryOptions, UseMutationOptions, UseInfiniteQueryOptions, InfiniteData } from '@tanstack/react-query';
7
7
  import { c as Profile, r as ProfilePosition, w as SkillRef, E as ExternalAccount, S as SkillSuggestion } from '../../adult-content-o0BxhFzc.js';
@@ -459,8 +459,14 @@ declare function useRoadmapVotes(options?: Omit<UseQueryOptions<RoadmapVotesResp
459
459
  /** Roadmap items the authenticated viewer has voted on. Returns `[]` data on error. */
460
460
  declare function useMyRoadmapVotes(options?: Omit<UseQueryOptions<string[], Error, string[], ReturnType<typeof sifaQueryKeys.roadmap.myVotes>>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<NoInfer<string[]>, Error>;
461
461
 
462
- /** React hook for casting a roadmap vote. Variable: the item key. */
463
- declare function useCastRoadmapVote(options?: Omit<UseMutationOptions<WriteResult, Error, string>, 'mutationFn'>): _tanstack_react_query.UseMutationResult<WriteResult, Error, string, unknown>;
462
+ /**
463
+ * React hook for casting a roadmap vote. Variable: the item key.
464
+ *
465
+ * Returns the discriminated-union result so callers can detect
466
+ * `scope_insufficient` and trigger an OAuth scope-upgrade flow
467
+ * (see {@link castRoadmapVote}).
468
+ */
469
+ declare function useCastRoadmapVote(options?: Omit<UseMutationOptions<CastRoadmapVoteResult, Error, string>, 'mutationFn'>): _tanstack_react_query.UseMutationResult<CastRoadmapVoteResult, Error, string, unknown>;
464
470
  /** React hook for retracting a previously-cast roadmap vote. */
465
471
  declare function useRetractRoadmapVote(options?: Omit<UseMutationOptions<WriteResult, Error, string>, 'mutationFn'>): _tanstack_react_query.UseMutationResult<WriteResult, Error, string, unknown>;
466
472
 
@@ -2143,8 +2143,36 @@ async function fetchMyRoadmapVotes(config, options = {}) {
2143
2143
  return [];
2144
2144
  }
2145
2145
  }
2146
- function castRoadmapVote(config, key, options = {}) {
2147
- return apiWrite(config, `/api/roadmap/votes/${encodeURIComponent(key)}`, "POST", options);
2146
+ async function castRoadmapVote(config, key, options = {}) {
2147
+ const fetchFn = config.fetch ?? globalThis.fetch;
2148
+ const url = `${config.baseUrl}/api/roadmap/votes/${encodeURIComponent(key)}`;
2149
+ try {
2150
+ const res = await fetchFn(url, {
2151
+ method: "POST",
2152
+ headers: { "Content-Type": "application/json", ...options.headers ?? {} },
2153
+ credentials: options.credentials ?? "include",
2154
+ signal: options.signal ?? AbortSignal.timeout(options.timeoutMs ?? 1e4)
2155
+ });
2156
+ if (!res.ok) {
2157
+ if (res.status === 403) {
2158
+ try {
2159
+ const body = await res.json();
2160
+ if (body.error === "ScopeInsufficient") {
2161
+ return {
2162
+ ok: false,
2163
+ error: { type: "scope_insufficient", requiredScope: body.requiredScope }
2164
+ };
2165
+ }
2166
+ } catch {
2167
+ }
2168
+ }
2169
+ return { ok: false, error: { type: "error" } };
2170
+ }
2171
+ const data = await res.json();
2172
+ return { ok: true, data };
2173
+ } catch {
2174
+ return { ok: false, error: { type: "error" } };
2175
+ }
2148
2176
  }
2149
2177
  function retractRoadmapVote(config, key, options = {}) {
2150
2178
  return apiWrite(config, `/api/roadmap/votes/${encodeURIComponent(key)}`, "DELETE", options);
@@ -2176,7 +2204,7 @@ function useCastRoadmapVote(options) {
2176
2204
  return useMutation({
2177
2205
  mutationFn: (key) => castRoadmapVote(config, key),
2178
2206
  onSuccess: async (result, variables, onMutateResult, context) => {
2179
- if (result.success) {
2207
+ if (result.ok) {
2180
2208
  await invalidateRoadmap(queryClient);
2181
2209
  }
2182
2210
  await options?.onSuccess?.(result, variables, onMutateResult, context);