@singi-labs/sifa-sdk 0.19.54 → 0.19.55
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/dist/badge/index.cjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/{network-map-Bj-s4akz.d.cts → network-map-CdYpUy-t.d.cts} +2 -2
- package/dist/{network-map-v_4bPC5p.d.ts → network-map-CiWrQ1fF.d.ts} +2 -2
- package/dist/{org-mUwICoPr.d.cts → org-fmpG85L0.d.cts} +32 -27
- package/dist/{org-DTHVhan9.d.ts → org-hxHnoBfg.d.ts} +32 -27
- package/dist/{profile-summary-D-Z_C6ZC.d.cts → profile-summary-5T1hDw6Q.d.cts} +1 -1
- package/dist/{profile-summary-BXG--PFN.d.ts → profile-summary-Bj7ufSDK.d.ts} +1 -1
- package/dist/query/client.js.map +1 -1
- package/dist/query/fetchers/destructive.js.map +1 -1
- package/dist/query/fetchers/external-accounts.js.map +1 -1
- package/dist/query/fetchers/follow.js.map +1 -1
- package/dist/query/fetchers/index.cjs.map +1 -1
- package/dist/query/fetchers/index.d.cts +5 -5
- package/dist/query/fetchers/index.d.ts +5 -5
- package/dist/query/fetchers/org.js.map +1 -1
- package/dist/query/fetchers/profile-mutations.js.map +1 -1
- package/dist/query/fetchers/publications.js.map +1 -1
- package/dist/query/fetchers/repo-inventory.js.map +1 -1
- package/dist/query/fetchers/skills.js.map +1 -1
- package/dist/query/hooks/index.cjs.map +1 -1
- package/dist/query/hooks/index.d.cts +3 -3
- package/dist/query/hooks/index.d.ts +3 -3
- package/dist/query/hooks/use-org-claim.js.map +1 -1
- package/dist/query/hooks/use-org-domains.js.map +1 -1
- package/dist/query/hooks/use-org-notification-emails.js.map +1 -1
- package/dist/query/hooks/use-org-profile-settings.js.map +1 -1
- package/dist/query/hooks/use-skill-mutations.js.map +1 -1
- package/dist/query/index.cjs.map +1 -1
- package/dist/query/index.d.cts +8 -8
- package/dist/query/index.d.ts +8 -8
- package/dist/{types-BeEuVVBo.d.cts → types-DHT7jcZc.d.cts} +26 -8
- package/dist/{types-Dblq-u-n.d.ts → types-jB67EFpw.d.ts} +26 -8
- package/dist/{use-org-notification-emails-CgEZnFTp.d.ts → use-org-notification-emails-CWLCWkmb.d.ts} +15 -15
- package/dist/{use-org-notification-emails-C8Z0U5rH.d.cts → use-org-notification-emails-Cj8IDI_7.d.cts} +15 -15
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { W as WriteResult, K as SifaApiConfig, M as ApiFetchOptions, N as CreateResult, b as ActivityLabel, t as RepoDeleteResult, w as RepoInventory } from './types-
|
|
1
|
+
import { W as WriteResult, K as SifaApiConfig, M as ApiFetchOptions, N as CreateResult, b as ActivityLabel, t as RepoDeleteResult, w as RepoInventory } from './types-jB67EFpw.js';
|
|
2
2
|
import { p as ExternalAccount } from './index-D9GC0u__.js';
|
|
3
3
|
import { s as FollowProfileItem, p as FeatureAllowlistEntry, r as FeatureFlag } from './follow-profile-D1l6pulB.js';
|
|
4
4
|
import { z } from 'zod';
|
|
@@ -56,10 +56,10 @@ interface UpdateProfileOverrideInput {
|
|
|
56
56
|
*/
|
|
57
57
|
declare function updateProfileOverride(config: SifaApiConfig, data: UpdateProfileOverrideInput, options?: ApiFetchOptions): Promise<WriteResult>;
|
|
58
58
|
/** Extended result for {@link refreshPds}. */
|
|
59
|
-
|
|
59
|
+
type RefreshPdsResult = WriteResult<{
|
|
60
60
|
displayName?: string | null;
|
|
61
61
|
avatar?: string | null;
|
|
62
|
-
}
|
|
62
|
+
}>;
|
|
63
63
|
/**
|
|
64
64
|
* Re-pull the authenticated user's `app.bsky.actor.profile` from their
|
|
65
65
|
* PDS. Returns the freshly resolved `displayName` and `avatar` on
|
|
@@ -67,10 +67,10 @@ interface RefreshPdsResult extends WriteResult {
|
|
|
67
67
|
*/
|
|
68
68
|
declare function refreshPds(config: SifaApiConfig, options?: ApiFetchOptions): Promise<RefreshPdsResult>;
|
|
69
69
|
/** Extended result for {@link uploadAvatar}. */
|
|
70
|
-
|
|
70
|
+
type UploadAvatarResult = WriteResult<{
|
|
71
71
|
/** Publicly accessible URL of the newly uploaded avatar. */
|
|
72
72
|
url?: string;
|
|
73
|
-
}
|
|
73
|
+
}>;
|
|
74
74
|
/**
|
|
75
75
|
* Upload a new avatar via `multipart/form-data`. Pass either a `File`
|
|
76
76
|
* (browser) or any `Blob` (Expo, node). The SDK leaves `Content-Type`
|
|
@@ -82,10 +82,10 @@ declare function uploadAvatar(config: SifaApiConfig, file: Blob, options?: ApiFe
|
|
|
82
82
|
/** Delete the authenticated user's avatar override (revert to PDS avatar). */
|
|
83
83
|
declare function deleteAvatarOverride(config: SifaApiConfig, options?: ApiFetchOptions): Promise<WriteResult>;
|
|
84
84
|
/** Extended result for {@link uploadNamePronunciationAudio}. */
|
|
85
|
-
|
|
85
|
+
type UploadPronunciationAudioResult = WriteResult<{
|
|
86
86
|
/** Publicly accessible URL of the newly uploaded audio clip. */
|
|
87
87
|
url?: string;
|
|
88
|
-
}
|
|
88
|
+
}>;
|
|
89
89
|
/**
|
|
90
90
|
* Upload a name-pronunciation audio clip via `multipart/form-data`. Pass a
|
|
91
91
|
* `File` (browser) or any `Blob` (Expo, node). The SDK leaves `Content-Type`
|
|
@@ -137,7 +137,7 @@ interface SubCategoryBulkResult {
|
|
|
137
137
|
* per-IP rate limit on any sizeable profile (#324). An empty `subCategory`
|
|
138
138
|
* clears the field.
|
|
139
139
|
*/
|
|
140
|
-
declare function updateSkillSubCategories(config: SifaApiConfig, rkeys: string[], subCategory: string, options?: ApiFetchOptions): Promise<WriteResult
|
|
140
|
+
declare function updateSkillSubCategories(config: SifaApiConfig, rkeys: string[], subCategory: string, options?: ApiFetchOptions): Promise<WriteResult<SubCategoryBulkResult>>;
|
|
141
141
|
/** Delete a skill record by `rkey`. */
|
|
142
142
|
declare function deleteSkill(config: SifaApiConfig, rkey: string, options?: ApiFetchOptions): Promise<WriteResult>;
|
|
143
143
|
|
|
@@ -182,15 +182,15 @@ interface ExternalAccountInput {
|
|
|
182
182
|
feedUrl?: string;
|
|
183
183
|
}
|
|
184
184
|
/** Extended create result for {@link createExternalAccount}. */
|
|
185
|
-
|
|
185
|
+
type CreateExternalAccountResult = WriteResult<{
|
|
186
186
|
rkey?: string;
|
|
187
187
|
feedUrl?: string | null;
|
|
188
|
-
}
|
|
188
|
+
}>;
|
|
189
189
|
/** Extended write result for {@link verifyExternalAccount}. */
|
|
190
|
-
|
|
190
|
+
type VerifyExternalAccountResult = WriteResult<{
|
|
191
191
|
verified?: boolean;
|
|
192
192
|
verifiedVia?: string;
|
|
193
|
-
}
|
|
193
|
+
}>;
|
|
194
194
|
/** List external accounts attached to a profile. Returns `[]` on error. */
|
|
195
195
|
declare function fetchExternalAccounts(config: SifaApiConfig, handleOrDid: string, options?: ApiFetchOptions): Promise<ExternalAccount[]>;
|
|
196
196
|
/**
|
|
@@ -516,10 +516,10 @@ interface FetchProfileCompletenessOptions extends ApiFetchOptions {
|
|
|
516
516
|
declare function fetchProfileCompleteness(config: SifaApiConfig, options?: FetchProfileCompletenessOptions): Promise<ProfileCompleteness>;
|
|
517
517
|
|
|
518
518
|
/** Extended result for {@link refreshOrcidPublications}. */
|
|
519
|
-
|
|
519
|
+
type RefreshOrcidPublicationsResult = WriteResult<{
|
|
520
520
|
added?: number;
|
|
521
521
|
removed?: number;
|
|
522
|
-
}
|
|
522
|
+
}>;
|
|
523
523
|
/**
|
|
524
524
|
* Hide an ORCID-imported publication from the user's profile. The
|
|
525
525
|
* `putCode` is the ORCID-side identifier; the underlying record stays
|
|
@@ -1001,11 +1001,11 @@ declare function fetchFollowing(config: SifaApiConfig, opts?: {
|
|
|
1001
1001
|
* handle surface as `success: false` with the server-provided message;
|
|
1002
1002
|
* dup-follow is idempotent (sifa-api E7) and resolves as `success: true`.
|
|
1003
1003
|
*/
|
|
1004
|
-
|
|
1004
|
+
type FollowUserResult = WriteResult<{
|
|
1005
1005
|
rkey?: string;
|
|
1006
1006
|
/** DID of the followed subject (server-resolved from the handle). */
|
|
1007
1007
|
subjectDid?: string;
|
|
1008
|
-
}
|
|
1008
|
+
}>;
|
|
1009
1009
|
/**
|
|
1010
1010
|
* Create an `id.sifa.graph.follow` record on the caller's PDS via the
|
|
1011
1011
|
* AppView. Idempotent on duplicate (server catches the unique-violation
|
|
@@ -1442,17 +1442,17 @@ interface WipePreview {
|
|
|
1442
1442
|
*/
|
|
1443
1443
|
declare function fetchWipePreview(config: SifaApiConfig, options?: ApiFetchOptions): Promise<WipePreview>;
|
|
1444
1444
|
/** Extended write result for {@link resetProfile}. */
|
|
1445
|
-
|
|
1445
|
+
type ResetProfileResult = WriteResult<{
|
|
1446
1446
|
/** Present when `deletePdsData: true`. See {@link PdsWipeOutcome}. */
|
|
1447
1447
|
pds?: PdsWipeOutcome;
|
|
1448
|
-
}
|
|
1448
|
+
}>;
|
|
1449
1449
|
/** Extended write result for {@link deleteAccount}. */
|
|
1450
|
-
|
|
1450
|
+
type DeleteAccountResult = WriteResult<{
|
|
1451
1451
|
/** The deleted handle, returned by the server for confirmation UIs. */
|
|
1452
1452
|
handle?: string;
|
|
1453
1453
|
/** Present when `deletePdsData: true`. See {@link PdsWipeOutcome}. */
|
|
1454
1454
|
pds?: PdsWipeOutcome;
|
|
1455
|
-
}
|
|
1455
|
+
}>;
|
|
1456
1456
|
/**
|
|
1457
1457
|
* Reset the authenticated user's Sifa profile.
|
|
1458
1458
|
*
|
|
@@ -1698,7 +1698,12 @@ interface OrgDomainVerifyResult {
|
|
|
1698
1698
|
/** Response body of `POST /api/org/notification-emails`. */
|
|
1699
1699
|
interface OrgNotificationEmailAddResult {
|
|
1700
1700
|
ok: boolean;
|
|
1701
|
-
|
|
1701
|
+
/**
|
|
1702
|
+
* Outcome of the verification email: `verification_sent` (accepted by the
|
|
1703
|
+
* mail provider), `sends_paused` (sending is off, nothing went out) or
|
|
1704
|
+
* `send_failed` (rejected or unreachable).
|
|
1705
|
+
*/
|
|
1706
|
+
status: 'verification_sent' | 'sends_paused' | 'send_failed';
|
|
1702
1707
|
}
|
|
1703
1708
|
/** Response body of `DELETE /api/org/notification-emails`. */
|
|
1704
1709
|
interface OrgNotificationEmailRemoveResult {
|
|
@@ -1711,35 +1716,35 @@ interface OrgNotificationEmailRemoveResult {
|
|
|
1711
1716
|
* structured {@link OrgClaimResult} folded into a {@link WriteResult} on success,
|
|
1712
1717
|
* or `{ success: false, error, pdsHost? }` on failure.
|
|
1713
1718
|
*/
|
|
1714
|
-
declare function submitOrgClaim(config: SifaApiConfig, body: OrgClaimRequestInput, options?: Omit<ApiFetchOptions, 'method' | 'body'>): Promise<WriteResult
|
|
1719
|
+
declare function submitOrgClaim(config: SifaApiConfig, body: OrgClaimRequestInput, options?: Omit<ApiFetchOptions, 'method' | 'body'>): Promise<WriteResult<Partial<OrgClaimResult>>>;
|
|
1715
1720
|
/**
|
|
1716
1721
|
* Edit the org record (`PUT /api/org/profile`). Fresh-from-body server-side PUT
|
|
1717
1722
|
* (a cleared optional field is dropped, no spread-merge). Never throws.
|
|
1718
1723
|
*/
|
|
1719
|
-
declare function updateOrgProfile(config: SifaApiConfig, body: OrgProfileUpdateRequestInput, options?: Omit<ApiFetchOptions, 'method' | 'body'>): Promise<WriteResult
|
|
1724
|
+
declare function updateOrgProfile(config: SifaApiConfig, body: OrgProfileUpdateRequestInput, options?: Omit<ApiFetchOptions, 'method' | 'body'>): Promise<WriteResult<Partial<OrgProfileUpdateResult>>>;
|
|
1720
1725
|
/**
|
|
1721
1726
|
* Issue a one-time DNS TXT domain challenge (`POST /api/org/domains/challenge`).
|
|
1722
1727
|
* Returns the TXT record name + value the org must publish. Never throws.
|
|
1723
1728
|
*/
|
|
1724
|
-
declare function requestOrgDomainChallenge(config: SifaApiConfig, body: OrgDomainChallengeRequestInput, options?: Omit<ApiFetchOptions, 'method' | 'body'>): Promise<WriteResult
|
|
1729
|
+
declare function requestOrgDomainChallenge(config: SifaApiConfig, body: OrgDomainChallengeRequestInput, options?: Omit<ApiFetchOptions, 'method' | 'body'>): Promise<WriteResult<Partial<OrgDomainChallengeResult>>>;
|
|
1725
1730
|
/**
|
|
1726
1731
|
* Verify a DNS TXT domain challenge (`POST /api/org/domains/verify`). On success
|
|
1727
1732
|
* `status` is `verified` or `pending`. Expired / confusable / not-found map to
|
|
1728
1733
|
* non-2xx server responses and surface as `{ success: false, error }`. Never
|
|
1729
1734
|
* throws.
|
|
1730
1735
|
*/
|
|
1731
|
-
declare function verifyOrgDomain(config: SifaApiConfig, body: OrgDomainVerifyRequestInput, options?: Omit<ApiFetchOptions, 'method' | 'body'>): Promise<WriteResult
|
|
1736
|
+
declare function verifyOrgDomain(config: SifaApiConfig, body: OrgDomainVerifyRequestInput, options?: Omit<ApiFetchOptions, 'method' | 'body'>): Promise<WriteResult<Partial<OrgDomainVerifyResult>>>;
|
|
1732
1737
|
/**
|
|
1733
1738
|
* Add an org notification email (`POST /api/org/notification-emails`). The
|
|
1734
1739
|
* address must use a domain the org controls (checked server-side). An
|
|
1735
1740
|
* individual verification email is enqueued through the (dormant) sending
|
|
1736
1741
|
* pipeline. Never throws.
|
|
1737
1742
|
*/
|
|
1738
|
-
declare function addOrgNotificationEmail(config: SifaApiConfig, body: OrgNotificationEmailRequestInput, options?: Omit<ApiFetchOptions, 'method' | 'body'>): Promise<WriteResult
|
|
1743
|
+
declare function addOrgNotificationEmail(config: SifaApiConfig, body: OrgNotificationEmailRequestInput, options?: Omit<ApiFetchOptions, 'method' | 'body'>): Promise<WriteResult<Partial<OrgNotificationEmailAddResult>>>;
|
|
1739
1744
|
/**
|
|
1740
1745
|
* Remove an org notification email (`DELETE /api/org/notification-emails`).
|
|
1741
1746
|
* Never throws.
|
|
1742
1747
|
*/
|
|
1743
|
-
declare function removeOrgNotificationEmail(config: SifaApiConfig, body: OrgNotificationEmailRequestInput, options?: Omit<ApiFetchOptions, 'method' | 'body'>): Promise<WriteResult
|
|
1748
|
+
declare function removeOrgNotificationEmail(config: SifaApiConfig, body: OrgNotificationEmailRequestInput, options?: Omit<ApiFetchOptions, 'method' | 'body'>): Promise<WriteResult<Partial<OrgNotificationEmailRemoveResult>>>;
|
|
1744
1749
|
|
|
1745
1750
|
export { type HeatmapDay as $, type AccountCheckResult as A, type BulkHideProfileItemInput as B, type ConfirmEndorsementInput as C, type DeleteAccountResult as D, type EndorsementInput as E, type FeatureAllowlistResponse as F, type FetchInboxCountsOptions as G, type FetchMyGithubPullRequestsOptions as H, type FetchMyRoadmapVotesOptions as I, type FetchProfileCompletenessOptions as J, type FetchReactionStatusOptions as K, type FetchSuggestionsOptions as L, type FetchUnlinkedPositionsOptions as M, type FollowListPage as N, type FollowProfile as O, type FollowProfilePageResponse as P, type FollowUserResult as Q, type FollowingFeedApp as R, type FollowingFeedEmptyReason as S, type FollowingFeedResponse as T, type FollowingFeedVersion as U, type FollowingResponse as V, type GetAdminReviewQueuesOptions as W, type GithubPullRequest as X, type GivenConfirmation as Y, HIDDEN_ITEM_SOURCES as Z, HIDDEN_ITEM_TYPES as _, type ConfirmEndorsementResult as a, bulkHideProfileItems as a$, type HeatmapResponse as a0, type HiddenActivityItem as a1, type HiddenApp as a2, type HiddenItemSource as a3, type HiddenItemType as a4, type HideActivityItemInput as a5, type HideProfileItemInput as a6, type InboxCounts as a7, type ListFeatureAllowlistOptions as a8, type MyGithubPullRequestsResponse as a9, type ReactionStatus as aA, type RefreshOrcidPublicationsResult as aB, type RefreshPdsResult as aC, type RepoDeleteInput as aD, type ResetProfileResult as aE, type ResolveQuotedPostsOptions as aF, type RoadmapVoteError as aG, type RoadmapVoteResult as aH, type RoadmapVoter as aI, type RoadmapVotesResponse as aJ, type SifaQueryKey as aK, type SimilarProfile as aL, type StatsResponse as aM, type SubCategoryBulkResult as aN, type SuggestionProfile as aO, type SuggestionsResponse as aP, type UnhideActivityItemInput as aQ, type UnlinkedPosition as aR, type UnlinkedPositionsResult as aS, type UpdateProfileOverrideInput as aT, type UpdateProfileSelfInput as aU, type UploadAvatarResult as aV, type UploadPronunciationAudioResult as aW, type VerifyExternalAccountResult as aX, type WipePreview as aY, addFeatureAllowlist as aZ, addOrgNotificationEmail as a_, type OrgClaimBinding as aa, type OrgClaimResult as ab, type OrgDomainChallengeResult as ac, type OrgDomainVerifyResult as ad, type OrgNotificationEmailAddResult as ae, type OrgNotificationEmailRemoveResult as af, type OrgProfileEcho as ag, type OrgProfileUpdateResult as ah, PROFILE_COMPLETENESS_SIGNALS as ai, type PdsWipeOutcome as aj, type PendingConfirmation as ak, type PendingConfirmationsPage as al, type PrimarySection as am, type ProfileCompleteness as an, type ProfileCompletenessSignal as ao, type ProfileIndustryInput as ap, type ProfileLocationAddress as aq, type ProfileLocationInput as ar, type ProfileSelfLocation as as, QUOTED_POSTS_BATCH_MAX as at, type QuotedPostAuthor as au, type QuotedPostImage as av, type QuotedPostResult as aw, type QuotedPostView as ax, type ReactionError as ay, type ReactionResult as az, type AccountSummary as b, refreshPds as b$, bulkHideStandardPublications as b0, bulkUnhideProfileItems as b1, bulkUnhideStandardPublications as b2, castRoadmapVote as b3, checkAppAccount as b4, confirmEndorsement as b5, createConfirmation as b6, createEndorsement as b7, createExternalAccount as b8, createProfileLocation as b9, fetchMyGithubPullRequests as bA, fetchMyRoadmapVotes as bB, fetchPendingConfirmations as bC, fetchProfileCompleteness as bD, fetchReactionStatus as bE, fetchRepoInventory as bF, fetchRoadmapVotes as bG, fetchSimilarProfiles as bH, fetchStats as bI, fetchSuggestionCount as bJ, fetchSuggestions as bK, fetchUnlinkedPositions as bL, fetchWipePreview as bM, followUser as bN, getAdminReviewQueues as bO, getBlueskySuggestions as bP, getFollowers as bQ, getFollowing as bR, getMutuals as bS, hideActivityItem as bT, hideOrcidPublication as bU, hideProfileItem as bV, hideSifaPublication as bW, hideStandardPublication as bX, isNewerFollowingFeed as bY, listFeatureAllowlist as bZ, refreshOrcidPublications as b_, createReaction as ba, createSkill as bb, deleteAccount as bc, deleteAvatarOverride as bd, deleteExternalAccount as be, deleteNamePronunciationAudio as bf, deleteProfileLocation as bg, deleteReaction as bh, deleteRepoRecords as bi, deleteSkill as bj, dismissConfirmation as bk, dismissUnlinkedPosition as bl, fetchAccounts as bm, fetchActivityFeed as bn, fetchActivityTeaser as bo, fetchAppsRegistry as bp, fetchExternalAccounts as bq, fetchFeaturedProfile as br, fetchFollowing as bs, fetchFollowingFeed as bt, fetchFollowingFeedVersion as bu, fetchGivenConfirmations as bv, fetchHeatmapData as bw, fetchHiddenActivityItems as bx, fetchHiddenApps as by, fetchInboxCounts as bz, type ActivityFeedResponse as c, removeFeatureAllowlist as c0, removeOrgNotificationEmail as c1, repoExportUrl as c2, requestOrgDomainChallenge as c3, resetProfile as c4, resolveQuotedPosts as c5, retractRoadmapVote as c6, revokeConfirmation as c7, setExternalAccountPrimary as c8, setSectionPrimary as c9, submitOrgClaim as ca, switchAccount as cb, unfollowUser as cc, unhideActivityItem as cd, unhideOrcidPublication as ce, unhideProfileItem as cf, unhideSifaPublication as cg, unhideStandardPublication as ch, unsetExternalAccountPrimary as ci, unsetSectionPrimary as cj, updateExternalAccount as ck, updateOrgProfile as cl, updateProfileLocation as cm, updateProfileOverride as cn, updateProfileSelf as co, updateSkill as cp, updateSkillSubCategories as cq, uploadAvatar as cr, uploadNamePronunciationAudio as cs, verifyExternalAccount as ct, verifyOrgDomain as cu, type ActivityItem as d, type ActivityItemLinkHealth as e, type ActivityTeaserResponse as f, type AdminReviewQueues as g, type AppRegistryEntry as h, type CastRoadmapVoteResult as i, type CheckAppAccountOptions as j, type ConfirmationInput as k, type ConfirmationSubjectInput as l, type CreateExternalAccountResult as m, type DismissUnlinkedPositionInput as n, type ExternalAccountInput as o, type FeaturedProfile as p, type FetchAccountsOptions as q, type FetchActivityFeedOptions as r, sifaQueryKeys as s, type FetchActivityTeaserOptions as t, type FetchConfirmationsOptions as u, type FetchFollowListOptions as v, type FetchFollowProfilePageOptions as w, type FetchFollowingFeedOptions as x, type FetchHiddenActivityItemsOptions as y, type FetchHiddenAppsOptions as z };
|
package/dist/query/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/query/client.ts"],"sourcesContent":["/**\n * Foundation HTTP client for talking to the Sifa AppView.\n *\n * Stateless. Consumers supply a {@link SifaApiConfig} per call (the React\n * hooks read it from context; non-React consumers pass it explicitly). No\n * singletons, no module-level state.\n */\n\n/** Configuration passed to every fetcher. */\nexport interface SifaApiConfig {\n /** Base URL of the sifa-api AppView, e.g. `https://api.sifa.id`. No trailing slash. */\n baseUrl: string;\n /**\n * Optional fetch implementation. Defaults to {@link globalThis.fetch}.\n * Lets Next.js consumers pass their cache-enhanced fetch; node/Expo\n * consumers can leave this unset.\n */\n fetch?: typeof fetch;\n /**\n * Optional per-request auth-token minter for auth-required reads. The NATIVE\n * app supplies this (it has no sifa-api session cookie): given a method NSID\n * (`lxm`), it mints a short-lived AT Protocol service-auth JWT on the user's\n * PDS (see the SDK's `/atproto` `mintServiceAuthToken`) and returns it; the\n * fetcher attaches it as `Authorization: Bearer`. Web omits this and relies on\n * its session cookie (`credentials: 'include'`). Return `null` to send no\n * token. See `sifa-api` `createIdentityMiddleware`.\n */\n getAuthToken?: (lxm: string) => Promise<string | null>;\n}\n\n/** Options accepted by {@link apiFetch}. */\nexport interface ApiFetchOptions {\n method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n /** Request body. Serialized to JSON automatically. */\n body?: unknown;\n /** AbortSignal. Defaults to `AbortSignal.timeout(timeoutMs)` if `timeoutMs` is set. */\n signal?: AbortSignal;\n /** Per-call timeout in milliseconds. Default: 10_000. Ignored if `signal` is provided. */\n timeoutMs?: number;\n /** Retry on HTTP 429 up to 3 times with the server's `Retry-After` delay (capped at 3s). */\n retryOn429?: boolean;\n /** Additional headers. `Content-Type: application/json` is set automatically when `body` is present. */\n headers?: Record<string, string>;\n credentials?: RequestCredentials;\n cache?: RequestCache;\n /**\n * Next.js-specific cache hints. Ignored on non-Next runtimes. Passed\n * through transparently as part of {@link RequestInit}.\n */\n next?: { revalidate?: number | false; tags?: string[] };\n}\n\n/** Error thrown by {@link apiFetch} on non-2xx responses. */\nexport class ApiError extends Error {\n readonly status: number;\n readonly body: unknown;\n /** Seconds until a rate limit resets, read from the headers of a 429. */\n readonly retryAfterSeconds?: number;\n\n constructor(message: string, status: number, body?: unknown, retryAfterSeconds?: number) {\n super(message);\n this.name = 'ApiError';\n this.status = status;\n this.body = body;\n if (retryAfterSeconds !== undefined) this.retryAfterSeconds = retryAfterSeconds;\n }\n}\n\nconst DEFAULT_TIMEOUT_MS = 10_000;\nconst MAX_RATE_LIMIT_RETRIES = 3;\nconst RATE_LIMIT_RETRY_CAP_SECONDS = 3;\n\n/**\n * Headers sifa-api (`@fastify/rate-limit`) sets on a 429, in preference order.\n * Both carry an integer count of seconds until the limit resets.\n */\nconst RATE_LIMIT_RESET_HEADERS = ['retry-after', 'x-ratelimit-reset'] as const;\n\n/**\n * Seconds to wait before retrying a rate-limited response, or `undefined` when\n * no header carries a positive integer (`Retry-After` may also be an HTTP\n * date, which sifa-api never sends).\n */\nfunction parseRetryAfterSeconds(headers: Headers): number | undefined {\n for (const name of RATE_LIMIT_RESET_HEADERS) {\n const seconds = Number.parseInt(headers.get(name) ?? '', 10);\n if (Number.isFinite(seconds) && seconds > 0) return seconds;\n }\n return undefined;\n}\n\n/**\n * Encode a handle or DID for safe interpolation into a request path,\n * idempotently.\n *\n * Plain {@link encodeURIComponent} double-encodes an already-encoded\n * identifier: Next.js hands route params to RSC pages percent-encoded on a\n * hard navigation (`did%3Aplc%3A...`) but decoded on client-side navigation\n * (`did:plc:...`). Encoding the former again turns `%` into `%25`, so the\n * AppView reads `did%3A...` as a literal handle, finds no match, and 404s —\n * which is why DID profile links broke on direct visits but worked when\n * clicked within the app.\n *\n * AT identifiers (handles are domain names, DIDs are `did:method:...`) never\n * contain a literal `%`, so decoding a decoded value is a no-op. A malformed\n * percent sequence (lone `%`) makes {@link decodeURIComponent} throw; in that\n * case we keep the original value so behaviour matches the prior bare\n * `encodeURIComponent`.\n */\nexport function encodeIdentifier(value: string): string {\n let decoded = value;\n try {\n decoded = decodeURIComponent(value);\n } catch {\n // Malformed percent-encoding — fall back to the raw value.\n }\n return encodeURIComponent(decoded);\n}\n\n/**\n * Generic fetcher used by all SDK query and mutation functions.\n *\n * Returns parsed JSON typed as `T`. Throws {@link ApiError} on non-2xx\n * responses. Use {@link apiFetchOrNull} when 404 should resolve to `null`\n * instead.\n */\nexport async function apiFetch<T = unknown>(\n config: SifaApiConfig,\n path: string,\n options: ApiFetchOptions = {},\n): Promise<T> {\n const fetchFn = config.fetch ?? globalThis.fetch;\n const url = `${config.baseUrl}${path}`;\n const maxRetries = options.retryOn429 ? MAX_RATE_LIMIT_RETRIES : 0;\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n const signal = options.signal ?? AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS);\n\n const headers: Record<string, string> = { ...(options.headers ?? {}) };\n let body: BodyInit | undefined;\n if (options.body !== undefined) {\n headers['Content-Type'] ??= 'application/json';\n body = JSON.stringify(options.body);\n }\n\n // `next` is a Next.js extension to RequestInit; cast through.\n const init = {\n method: options.method ?? 'GET',\n headers,\n body,\n signal,\n credentials: options.credentials,\n cache: options.cache,\n ...(options.next ? { next: options.next } : {}),\n } as RequestInit;\n\n const res = await fetchFn(url, init);\n\n if (res.status === 429 && attempt < maxRetries) {\n const retryAfterRaw = res.headers.get('retry-after');\n const retryAfter = retryAfterRaw ? Number.parseInt(retryAfterRaw, 10) : 2;\n const waitSeconds = Math.min(\n Number.isFinite(retryAfter) ? retryAfter : 2,\n RATE_LIMIT_RETRY_CAP_SECONDS,\n );\n await new Promise((r) => setTimeout(r, waitSeconds * 1000));\n continue;\n }\n\n if (!res.ok) {\n let errBody: unknown;\n try {\n errBody = (await res.json()) as unknown;\n } catch {\n try {\n errBody = await res.text();\n } catch {\n errBody = undefined;\n }\n }\n throw new ApiError(\n `Sifa API ${res.status} on ${path}`,\n res.status,\n errBody,\n res.status === 429 ? parseRetryAfterSeconds(res.headers) : undefined,\n );\n }\n\n // 204 and 205 are defined to carry no body, so res.json() throws on them.\n // apiWrite treats that throw as a failed write, which turned every\n // successful no-content response (roadmap unvote, remove reaction,\n // dismiss endorsement) into a reported error.\n if (res.status === 204 || res.status === 205) {\n return undefined as T;\n }\n\n return (await res.json()) as T;\n }\n\n throw new ApiError(`Sifa API exhausted retries on ${path}`, 429);\n}\n\n/**\n * Variant of {@link apiFetch} that resolves to `null` on HTTP 404 instead\n * of throwing. Useful for \"fetch by handle\" reads where missing is\n * expected (e.g. unknown profile).\n */\nexport async function apiFetchOrNull<T>(\n config: SifaApiConfig,\n path: string,\n options: ApiFetchOptions = {},\n): Promise<T | null> {\n try {\n return await apiFetch<T>(config, path, options);\n } catch (e) {\n if (e instanceof ApiError && e.status === 404) return null;\n throw e;\n }\n}\n\n/**\n * Result returned by record-write mutations (create / update / delete).\n *\n * Never throws -- writes against the user's PDS can fail in many ways\n * (network, PDS unreachable, rate limit) and the UI needs structured\n * results to render appropriate messages.\n */\nexport interface WriteResult {\n success: boolean;\n error?: string;\n /**\n * PDS hostname returned by sifa-api when a write failed at the user's\n * Personal Data Server (issue #167). Lets the UI render\n * \"Your data server (eurosky.social) isn't responding\" instead of a\n * generic \"Request failed (500)\".\n */\n pdsHost?: string;\n /** HTTP status of a failed write. Absent on success and on network errors. */\n status?: number;\n /**\n * Seconds until the rate limit resets, when a write was rejected with 429\n * and the server said how long to wait (sifa-workspace#533). Lets the UI say\n * \"try again in N seconds\" instead of a generic failure.\n */\n retryAfterSeconds?: number;\n}\n\n/** Result returned by create mutations. Includes the newly created `rkey`. */\nexport interface CreateResult extends WriteResult {\n rkey?: string;\n}\n\ninterface ApiErrorBody {\n message?: string;\n error?: string;\n pdsHost?: string;\n}\n\nfunction extractWriteError(\n e: ApiError,\n): Pick<WriteResult, 'error' | 'pdsHost' | 'status' | 'retryAfterSeconds'> {\n const body = (e.body && typeof e.body === 'object' ? e.body : {}) as ApiErrorBody;\n return {\n // Fastify puts the detail in `message` and the status phrase in `error`;\n // sifa-api's own handlers (and the rate limiter) only set `error`.\n error: body.message ?? body.error ?? `Request failed (${e.status})`,\n status: e.status,\n ...(e.retryAfterSeconds !== undefined ? { retryAfterSeconds: e.retryAfterSeconds } : {}),\n ...(body.pdsHost ? { pdsHost: body.pdsHost } : {}),\n };\n}\n\n/**\n * Write mutation against the Sifa AppView. Wraps {@link apiFetch} with the\n * never-throws contract used by all sifa-web mutations: returns a\n * structured {@link WriteResult} on both success and failure, and\n * preserves the `pdsHost` field when the AppView reports a PDS-side\n * failure (issue #167).\n *\n * On success: returns `{ success: true, ...payload }` where `payload` is\n * whatever the server returned in JSON (or `{}` for 204).\n *\n * On failure: returns `{ success: false, error, pdsHost? }`. Never throws.\n *\n * Use {@link apiWriteCreate} when you specifically need the `rkey` from a\n * create response folded into the result shape.\n */\nexport async function apiWrite<TExtra extends object = Record<never, never>>(\n config: SifaApiConfig,\n path: string,\n method: 'POST' | 'PUT' | 'DELETE' | 'PATCH',\n options: Omit<ApiFetchOptions, 'method'> = {},\n): Promise<WriteResult & TExtra> {\n try {\n const data = await apiFetch<TExtra>(config, path, {\n method,\n credentials: 'include',\n ...options,\n });\n return { success: true, ...(data ?? ({} as TExtra)) };\n } catch (e) {\n if (e instanceof ApiError) {\n return { success: false, ...extractWriteError(e) } as WriteResult & TExtra;\n }\n return { success: false, error: 'Network error' } as WriteResult & TExtra;\n }\n}\n\n/**\n * Write mutation that expects the server to return a record key (`rkey`)\n * in its response body. Wraps {@link apiWrite} and folds the `rkey` into\n * the result shape so consumers get `{ success, rkey?, error?, pdsHost? }`.\n *\n * If the server returns additional fields (e.g. `feedUrl` from external\n * account creation), pass them via the `TExtra` generic to keep them\n * typed.\n */\nexport function apiWriteCreate<TExtra extends object = Record<never, never>>(\n config: SifaApiConfig,\n path: string,\n body: unknown,\n options: Omit<ApiFetchOptions, 'method' | 'body'> = {},\n): Promise<CreateResult & TExtra> {\n return apiWrite<{ rkey?: string } & TExtra>(config, path, 'POST', {\n body,\n ...options,\n });\n}\n"],"mappings":";AAqDO,IAAM,WAAN,cAAuB,MAAM;AAAA,EACzB;AAAA,EACA;AAAA;AAAA,EAEA;AAAA,EAET,YAAY,SAAiB,QAAgB,MAAgB,mBAA4B;AACvF,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AACZ,QAAI,sBAAsB,OAAW,MAAK,oBAAoB;AAAA,EAChE;AACF;AAEA,IAAM,qBAAqB;AAC3B,IAAM,yBAAyB;AAC/B,IAAM,+BAA+B;AAMrC,IAAM,2BAA2B,CAAC,eAAe,mBAAmB;AAOpE,SAAS,uBAAuB,SAAsC;AACpE,aAAW,QAAQ,0BAA0B;AAC3C,UAAM,UAAU,OAAO,SAAS,QAAQ,IAAI,IAAI,KAAK,IAAI,EAAE;AAC3D,QAAI,OAAO,SAAS,OAAO,KAAK,UAAU,EAAG,QAAO;AAAA,EACtD;AACA,SAAO;AACT;AAoBO,SAAS,iBAAiB,OAAuB;AACtD,MAAI,UAAU;AACd,MAAI;AACF,cAAU,mBAAmB,KAAK;AAAA,EACpC,QAAQ;AAAA,EAER;AACA,SAAO,mBAAmB,OAAO;AACnC;AASA,eAAsB,SACpB,QACA,MACA,UAA2B,CAAC,GAChB;AACZ,QAAM,UAAU,OAAO,SAAS,WAAW;AAC3C,QAAM,MAAM,GAAG,OAAO,OAAO,GAAG,IAAI;AACpC,QAAM,aAAa,QAAQ,aAAa,yBAAyB;AAEjE,WAAS,UAAU,GAAG,WAAW,YAAY,WAAW;AACtD,UAAM,SAAS,QAAQ,UAAU,YAAY,QAAQ,QAAQ,aAAa,kBAAkB;AAE5F,UAAM,UAAkC,EAAE,GAAI,QAAQ,WAAW,CAAC,EAAG;AACrE,QAAI;AACJ,QAAI,QAAQ,SAAS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AA2B,CAAC,GACT;AACnB,MAAI;AACF,WAAO,MAAM,SAAY,QAAQ,MAAM,OAAO;AAAA,EAChD,SAAS,GAAG;AACV,QAAI,aAAa,YAAY,EAAE,WAAW,IAAK,QAAO;AACtD,UAAM;AAAA,EACR;AACF;AAwCA,SAAS,kBACP,GACyE;AACzE,QAAM,OAAQ,EAAE,QAAQ,OAAO,EAAE,SAAS,WAAW,EAAE,OAAO,CAAC;AAC/D,SAAO;AAAA;AAAA;AAAA,IAGL,OAAO,KAAK,WAAW,KAAK,SAAS,mBAAmB,EAAE,MAAM;AAAA,IAChE,QAAQ,EAAE;AAAA,IACV,GAAI,EAAE,sBAAsB,SAAY,EAAE,mBAAmB,EAAE,kBAAkB,IAAI,CAAC;AAAA,IACtF,GAAI,KAAK,UAAU,EAAE,SAAS,KAAK,QAAQ,IAAI,CAAC;AAAA,EAClD;AACF;AAiBA,eAAsB,SACpB,QACA,MACA,QACA,UAA2C,CAAC,GACb;AAC/B,MAAI;AACF,UAAM,OAAO,MAAM,SAAiB,QAAQ,MAAM;AAAA,MAChD;AAAA,MACA,aAAa;AAAA,MACb,GAAG;AAAA,IACL,CAAC;AACD,WAAO,EAAE,SAAS,MAAM,GAAI,QAAS,CAAC,EAAc;AAAA,EACtD,SAAS,GAAG;AACV,QAAI,aAAa,UAAU;AACzB,aAAO,EAAE,SAAS,OAAO,GAAG,kBAAkB,CAAC,EAAE;AAAA,IACnD;AACA,WAAO,EAAE,SAAS,OAAO,OAAO,gBAAgB;AAAA,EAClD;AACF;AAWO,SAAS,eACd,QACA,MACA,MACA,UAAoD,CAAC,GACrB;AAChC,SAAO,SAAqC,QAAQ,MAAM,QAAQ;AAAA,IAChE;AAAA,IACA,GAAG;AAAA,EACL,CAAC;AACH;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/query/client.ts"],"sourcesContent":["/**\n * Foundation HTTP client for talking to the Sifa AppView.\n *\n * Stateless. Consumers supply a {@link SifaApiConfig} per call (the React\n * hooks read it from context; non-React consumers pass it explicitly). No\n * singletons, no module-level state.\n */\n\n/** Configuration passed to every fetcher. */\nexport interface SifaApiConfig {\n /** Base URL of the sifa-api AppView, e.g. `https://api.sifa.id`. No trailing slash. */\n baseUrl: string;\n /**\n * Optional fetch implementation. Defaults to {@link globalThis.fetch}.\n * Lets Next.js consumers pass their cache-enhanced fetch; node/Expo\n * consumers can leave this unset.\n */\n fetch?: typeof fetch;\n /**\n * Optional per-request auth-token minter for auth-required reads. The NATIVE\n * app supplies this (it has no sifa-api session cookie): given a method NSID\n * (`lxm`), it mints a short-lived AT Protocol service-auth JWT on the user's\n * PDS (see the SDK's `/atproto` `mintServiceAuthToken`) and returns it; the\n * fetcher attaches it as `Authorization: Bearer`. Web omits this and relies on\n * its session cookie (`credentials: 'include'`). Return `null` to send no\n * token. See `sifa-api` `createIdentityMiddleware`.\n */\n getAuthToken?: (lxm: string) => Promise<string | null>;\n}\n\n/** Options accepted by {@link apiFetch}. */\nexport interface ApiFetchOptions {\n method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n /** Request body. Serialized to JSON automatically. */\n body?: unknown;\n /** AbortSignal. Defaults to `AbortSignal.timeout(timeoutMs)` if `timeoutMs` is set. */\n signal?: AbortSignal;\n /** Per-call timeout in milliseconds. Default: 10_000. Ignored if `signal` is provided. */\n timeoutMs?: number;\n /** Retry on HTTP 429 up to 3 times with the server's `Retry-After` delay (capped at 3s). */\n retryOn429?: boolean;\n /** Additional headers. `Content-Type: application/json` is set automatically when `body` is present. */\n headers?: Record<string, string>;\n credentials?: RequestCredentials;\n cache?: RequestCache;\n /**\n * Next.js-specific cache hints. Ignored on non-Next runtimes. Passed\n * through transparently as part of {@link RequestInit}.\n */\n next?: { revalidate?: number | false; tags?: string[] };\n}\n\n/** Error thrown by {@link apiFetch} on non-2xx responses. */\nexport class ApiError extends Error {\n readonly status: number;\n readonly body: unknown;\n /** Seconds until a rate limit resets, read from the headers of a 429. */\n readonly retryAfterSeconds?: number;\n\n constructor(message: string, status: number, body?: unknown, retryAfterSeconds?: number) {\n super(message);\n this.name = 'ApiError';\n this.status = status;\n this.body = body;\n if (retryAfterSeconds !== undefined) this.retryAfterSeconds = retryAfterSeconds;\n }\n}\n\nconst DEFAULT_TIMEOUT_MS = 10_000;\nconst MAX_RATE_LIMIT_RETRIES = 3;\nconst RATE_LIMIT_RETRY_CAP_SECONDS = 3;\n\n/**\n * Headers sifa-api (`@fastify/rate-limit`) sets on a 429, in preference order.\n * Both carry an integer count of seconds until the limit resets.\n */\nconst RATE_LIMIT_RESET_HEADERS = ['retry-after', 'x-ratelimit-reset'] as const;\n\n/**\n * Seconds to wait before retrying a rate-limited response, or `undefined` when\n * no header carries a positive integer (`Retry-After` may also be an HTTP\n * date, which sifa-api never sends).\n */\nfunction parseRetryAfterSeconds(headers: Headers): number | undefined {\n for (const name of RATE_LIMIT_RESET_HEADERS) {\n const seconds = Number.parseInt(headers.get(name) ?? '', 10);\n if (Number.isFinite(seconds) && seconds > 0) return seconds;\n }\n return undefined;\n}\n\n/**\n * Encode a handle or DID for safe interpolation into a request path,\n * idempotently.\n *\n * Plain {@link encodeURIComponent} double-encodes an already-encoded\n * identifier: Next.js hands route params to RSC pages percent-encoded on a\n * hard navigation (`did%3Aplc%3A...`) but decoded on client-side navigation\n * (`did:plc:...`). Encoding the former again turns `%` into `%25`, so the\n * AppView reads `did%3A...` as a literal handle, finds no match, and 404s —\n * which is why DID profile links broke on direct visits but worked when\n * clicked within the app.\n *\n * AT identifiers (handles are domain names, DIDs are `did:method:...`) never\n * contain a literal `%`, so decoding a decoded value is a no-op. A malformed\n * percent sequence (lone `%`) makes {@link decodeURIComponent} throw; in that\n * case we keep the original value so behaviour matches the prior bare\n * `encodeURIComponent`.\n */\nexport function encodeIdentifier(value: string): string {\n let decoded = value;\n try {\n decoded = decodeURIComponent(value);\n } catch {\n // Malformed percent-encoding — fall back to the raw value.\n }\n return encodeURIComponent(decoded);\n}\n\n/**\n * Generic fetcher used by all SDK query and mutation functions.\n *\n * Returns parsed JSON typed as `T`. Throws {@link ApiError} on non-2xx\n * responses. Use {@link apiFetchOrNull} when 404 should resolve to `null`\n * instead.\n */\nexport async function apiFetch<T = unknown>(\n config: SifaApiConfig,\n path: string,\n options: ApiFetchOptions = {},\n): Promise<T> {\n const fetchFn = config.fetch ?? globalThis.fetch;\n const url = `${config.baseUrl}${path}`;\n const maxRetries = options.retryOn429 ? MAX_RATE_LIMIT_RETRIES : 0;\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n const signal = options.signal ?? AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS);\n\n const headers: Record<string, string> = { ...(options.headers ?? {}) };\n let body: BodyInit | undefined;\n if (options.body !== undefined) {\n headers['Content-Type'] ??= 'application/json';\n body = JSON.stringify(options.body);\n }\n\n // `next` is a Next.js extension to RequestInit; cast through.\n const init = {\n method: options.method ?? 'GET',\n headers,\n body,\n signal,\n credentials: options.credentials,\n cache: options.cache,\n ...(options.next ? { next: options.next } : {}),\n } as RequestInit;\n\n const res = await fetchFn(url, init);\n\n if (res.status === 429 && attempt < maxRetries) {\n const retryAfterRaw = res.headers.get('retry-after');\n const retryAfter = retryAfterRaw ? Number.parseInt(retryAfterRaw, 10) : 2;\n const waitSeconds = Math.min(\n Number.isFinite(retryAfter) ? retryAfter : 2,\n RATE_LIMIT_RETRY_CAP_SECONDS,\n );\n await new Promise((r) => setTimeout(r, waitSeconds * 1000));\n continue;\n }\n\n if (!res.ok) {\n let errBody: unknown;\n try {\n errBody = (await res.json()) as unknown;\n } catch {\n try {\n errBody = await res.text();\n } catch {\n errBody = undefined;\n }\n }\n throw new ApiError(\n `Sifa API ${res.status} on ${path}`,\n res.status,\n errBody,\n res.status === 429 ? parseRetryAfterSeconds(res.headers) : undefined,\n );\n }\n\n // 204 and 205 are defined to carry no body, so res.json() throws on them.\n // apiWrite treats that throw as a failed write, which turned every\n // successful no-content response (roadmap unvote, remove reaction,\n // dismiss endorsement) into a reported error.\n if (res.status === 204 || res.status === 205) {\n return undefined as T;\n }\n\n return (await res.json()) as T;\n }\n\n throw new ApiError(`Sifa API exhausted retries on ${path}`, 429);\n}\n\n/**\n * Variant of {@link apiFetch} that resolves to `null` on HTTP 404 instead\n * of throwing. Useful for \"fetch by handle\" reads where missing is\n * expected (e.g. unknown profile).\n */\nexport async function apiFetchOrNull<T>(\n config: SifaApiConfig,\n path: string,\n options: ApiFetchOptions = {},\n): Promise<T | null> {\n try {\n return await apiFetch<T>(config, path, options);\n } catch (e) {\n if (e instanceof ApiError && e.status === 404) return null;\n throw e;\n }\n}\n\n/**\n * Failed branch of a {@link WriteResult}.\n *\n * Never throws -- writes against the user's PDS can fail in many ways\n * (network, PDS unreachable, rate limit) and the UI needs structured\n * results to render appropriate messages.\n */\nexport interface WriteFailure {\n success: false;\n error?: string;\n /**\n * PDS hostname returned by sifa-api when a write failed at the user's\n * Personal Data Server (issue #167). Lets the UI render\n * \"Your data server (eurosky.social) isn't responding\" instead of a\n * generic \"Request failed (500)\".\n */\n pdsHost?: string;\n /** HTTP status of a failed write. Absent on network errors. */\n status?: number;\n /**\n * Seconds until the rate limit resets, when a write was rejected with 429\n * and the server said how long to wait (sifa-workspace#533). Lets the UI say\n * \"try again in N seconds\" instead of a generic failure.\n */\n retryAfterSeconds?: number;\n}\n\n/**\n * Successful branch of a {@link WriteResult}: the response body fields\n * (`TExtra`) plus the optional failure fields. A body field that shares a name\n * with a failure field (e.g. a body `status`) keeps its body type here, so it\n * never collides with the HTTP status on the failure branch.\n */\nexport type WriteSuccess<TExtra extends object = Record<never, never>> = { success: true } & Omit<\n WriteFailure,\n 'success' | keyof TExtra\n> &\n TExtra;\n\n/**\n * Result returned by record-write mutations (create / update / delete),\n * discriminated on `success`. Narrow on `success` to read a body `status`\n * (success) or the HTTP `status` (failure). Other fields stay readable without\n * narrowing.\n */\nexport type WriteResult<TExtra extends object = Record<never, never>> =\n WriteSuccess<TExtra> | (WriteFailure & Partial<Omit<TExtra, keyof WriteFailure>>);\n\n/** Result returned by create mutations. Includes the newly created `rkey`. */\nexport type CreateResult = WriteResult<{ rkey?: string }>;\n\ninterface ApiErrorBody {\n message?: string;\n error?: string;\n pdsHost?: string;\n}\n\nfunction extractWriteError(e: ApiError): Omit<WriteFailure, 'success'> {\n const body = (e.body && typeof e.body === 'object' ? e.body : {}) as ApiErrorBody;\n return {\n // Fastify puts the detail in `message` and the status phrase in `error`;\n // sifa-api's own handlers (and the rate limiter) only set `error`.\n error: body.message ?? body.error ?? `Request failed (${e.status})`,\n status: e.status,\n ...(e.retryAfterSeconds !== undefined ? { retryAfterSeconds: e.retryAfterSeconds } : {}),\n ...(body.pdsHost ? { pdsHost: body.pdsHost } : {}),\n };\n}\n\n/**\n * Write mutation against the Sifa AppView. Wraps {@link apiFetch} with the\n * never-throws contract used by all sifa-web mutations: returns a\n * structured {@link WriteResult} on both success and failure, and\n * preserves the `pdsHost` field when the AppView reports a PDS-side\n * failure (issue #167).\n *\n * On success: returns `{ success: true, ...payload }` where `payload` is\n * whatever the server returned in JSON (or `{}` for 204).\n *\n * On failure: returns `{ success: false, error, pdsHost? }`. Never throws.\n *\n * Use {@link apiWriteCreate} when you specifically need the `rkey` from a\n * create response folded into the result shape.\n */\nexport async function apiWrite<TExtra extends object = Record<never, never>>(\n config: SifaApiConfig,\n path: string,\n method: 'POST' | 'PUT' | 'DELETE' | 'PATCH',\n options: Omit<ApiFetchOptions, 'method'> = {},\n): Promise<WriteResult<TExtra>> {\n try {\n const data = await apiFetch<TExtra>(config, path, {\n method,\n credentials: 'include',\n ...options,\n });\n return { success: true, ...(data ?? ({} as TExtra)) };\n } catch (e) {\n if (e instanceof ApiError) {\n return { success: false, ...extractWriteError(e) };\n }\n return { success: false, error: 'Network error' };\n }\n}\n\n/**\n * Write mutation that expects the server to return a record key (`rkey`)\n * in its response body. Wraps {@link apiWrite} and folds the `rkey` into\n * the result shape so consumers get `{ success, rkey?, error?, pdsHost? }`.\n *\n * If the server returns additional fields (e.g. `feedUrl` from external\n * account creation), pass them via the `TExtra` generic to keep them\n * typed.\n */\nexport function apiWriteCreate<TExtra extends object = Record<never, never>>(\n config: SifaApiConfig,\n path: string,\n body: unknown,\n options: Omit<ApiFetchOptions, 'method' | 'body'> = {},\n): Promise<WriteResult<{ rkey?: string } & TExtra>> {\n return apiWrite<{ rkey?: string } & TExtra>(config, path, 'POST', {\n body,\n ...options,\n });\n}\n"],"mappings":";AAqDO,IAAM,WAAN,cAAuB,MAAM;AAAA,EACzB;AAAA,EACA;AAAA;AAAA,EAEA;AAAA,EAET,YAAY,SAAiB,QAAgB,MAAgB,mBAA4B;AACvF,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AACZ,QAAI,sBAAsB,OAAW,MAAK,oBAAoB;AAAA,EAChE;AACF;AAEA,IAAM,qBAAqB;AAC3B,IAAM,yBAAyB;AAC/B,IAAM,+BAA+B;AAMrC,IAAM,2BAA2B,CAAC,eAAe,mBAAmB;AAOpE,SAAS,uBAAuB,SAAsC;AACpE,aAAW,QAAQ,0BAA0B;AAC3C,UAAM,UAAU,OAAO,SAAS,QAAQ,IAAI,IAAI,KAAK,IAAI,EAAE;AAC3D,QAAI,OAAO,SAAS,OAAO,KAAK,UAAU,EAAG,QAAO;AAAA,EACtD;AACA,SAAO;AACT;AAoBO,SAAS,iBAAiB,OAAuB;AACtD,MAAI,UAAU;AACd,MAAI;AACF,cAAU,mBAAmB,KAAK;AAAA,EACpC,QAAQ;AAAA,EAER;AACA,SAAO,mBAAmB,OAAO;AACnC;AASA,eAAsB,SACpB,QACA,MACA,UAA2B,CAAC,GAChB;AACZ,QAAM,UAAU,OAAO,SAAS,WAAW;AAC3C,QAAM,MAAM,GAAG,OAAO,OAAO,GAAG,IAAI;AACpC,QAAM,aAAa,QAAQ,aAAa,yBAAyB;AAEjE,WAAS,UAAU,GAAG,WAAW,YAAY,WAAW;AACtD,UAAM,SAAS,QAAQ,UAAU,YAAY,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+1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/query/fetchers/destructive.ts"],"sourcesContent":["import {\n apiFetch,\n apiWrite,\n type ApiFetchOptions,\n type SifaApiConfig,\n type WriteResult,\n} from '../client.js';\n\n/**\n * What the server managed to remove from the user's PDS.\n *\n * The wipe runs per collection, so it can partly succeed: `success: true` means\n * the account action completed, NOT that the PDS is clean. A UI that ignores\n * this can tell someone their data is gone while it is still on their data\n * server, so treat a non-empty `remaining` as \"not deleted\".\n *\n * Absent when the PDS was not touched (`deletePdsData: false`).\n */\nexport interface PdsWipeOutcome {\n /** Collections whose records were removed. */\n deleted: string[];\n /** Collections whose records are still on the PDS. Non-empty means not done. */\n remaining: string[];\n /**\n * The server could not enumerate the repo, so it does not know what survived.\n * Without this, that case is indistinguishable from \"nothing to delete\".\n */\n unknown: boolean;\n}\n\n/**\n * What a PDS wipe could not remove with the grant the session holds today.\n *\n * Read this BEFORE the destructive step. Deleting an account destroys the\n * session, so a missing scope cannot be granted afterwards -- there is nobody\n * left to ask. A non-empty `needsScopeFor` means the wipe would strand those\n * records on the user's data server.\n */\nexport interface WipePreview {\n /** id.sifa.* collections the current grant cannot delete. */\n needsScopeFor: string[];\n /**\n * The server could not enumerate the repo, so the gap list is not\n * authoritative. Distinct from an empty list, which means \"nothing to ask for\".\n */\n unknown?: boolean;\n}\n\n/**\n * Ask which id.sifa.* collections the current grant cannot delete.\n *\n * Unlike most read fetchers in this file's neighbourhood, a failure is NOT\n * flattened into an empty result: an empty gap list reads as \"a wipe will be\n * clean\", and a caller must not promise that on the strength of a request that\n * never arrived. Let it throw and warn.\n */\nexport function fetchWipePreview(\n config: SifaApiConfig,\n options: ApiFetchOptions = {},\n): Promise<WipePreview> {\n return apiFetch<WipePreview>(config, '/api/profile/wipe-preview', {\n credentials: 'include',\n ...options,\n });\n}\n\n/** Extended write result for {@link resetProfile}. */\nexport
|
|
1
|
+
{"version":3,"sources":["../../../src/query/fetchers/destructive.ts"],"sourcesContent":["import {\n apiFetch,\n apiWrite,\n type ApiFetchOptions,\n type SifaApiConfig,\n type WriteResult,\n} from '../client.js';\n\n/**\n * What the server managed to remove from the user's PDS.\n *\n * The wipe runs per collection, so it can partly succeed: `success: true` means\n * the account action completed, NOT that the PDS is clean. A UI that ignores\n * this can tell someone their data is gone while it is still on their data\n * server, so treat a non-empty `remaining` as \"not deleted\".\n *\n * Absent when the PDS was not touched (`deletePdsData: false`).\n */\nexport interface PdsWipeOutcome {\n /** Collections whose records were removed. */\n deleted: string[];\n /** Collections whose records are still on the PDS. Non-empty means not done. */\n remaining: string[];\n /**\n * The server could not enumerate the repo, so it does not know what survived.\n * Without this, that case is indistinguishable from \"nothing to delete\".\n */\n unknown: boolean;\n}\n\n/**\n * What a PDS wipe could not remove with the grant the session holds today.\n *\n * Read this BEFORE the destructive step. Deleting an account destroys the\n * session, so a missing scope cannot be granted afterwards -- there is nobody\n * left to ask. A non-empty `needsScopeFor` means the wipe would strand those\n * records on the user's data server.\n */\nexport interface WipePreview {\n /** id.sifa.* collections the current grant cannot delete. */\n needsScopeFor: string[];\n /**\n * The server could not enumerate the repo, so the gap list is not\n * authoritative. Distinct from an empty list, which means \"nothing to ask for\".\n */\n unknown?: boolean;\n}\n\n/**\n * Ask which id.sifa.* collections the current grant cannot delete.\n *\n * Unlike most read fetchers in this file's neighbourhood, a failure is NOT\n * flattened into an empty result: an empty gap list reads as \"a wipe will be\n * clean\", and a caller must not promise that on the strength of a request that\n * never arrived. Let it throw and warn.\n */\nexport function fetchWipePreview(\n config: SifaApiConfig,\n options: ApiFetchOptions = {},\n): Promise<WipePreview> {\n return apiFetch<WipePreview>(config, '/api/profile/wipe-preview', {\n credentials: 'include',\n ...options,\n });\n}\n\n/** Extended write result for {@link resetProfile}. */\nexport type ResetProfileResult = WriteResult<{\n /** Present when `deletePdsData: true`. See {@link PdsWipeOutcome}. */\n pds?: PdsWipeOutcome;\n}>;\n\n/** Extended write result for {@link deleteAccount}. */\nexport type DeleteAccountResult = WriteResult<{\n /** The deleted handle, returned by the server for confirmation UIs. */\n handle?: string;\n /** Present when `deletePdsData: true`. See {@link PdsWipeOutcome}. */\n pds?: PdsWipeOutcome;\n}>;\n\n/**\n * Reset the authenticated user's Sifa profile.\n *\n * `deletePdsData: true` also deletes the corresponding records on the\n * user's PDS. `deletePdsData: false` only removes the AppView's\n * indexed state -- the records on the PDS are left intact and could be\n * re-indexed later.\n *\n * Destructive. Server enforces session check + attestation; the SDK\n * does not gate on additional confirmation. Wrap call sites in your\n * own modal if you want a UX confirmation step.\n */\nexport function resetProfile(\n config: SifaApiConfig,\n deletePdsData: boolean,\n options: ApiFetchOptions = {},\n): Promise<ResetProfileResult> {\n return apiWrite<{ ok?: boolean; pds?: PdsWipeOutcome }>(config, '/api/profile/reset', 'DELETE', {\n body: { deletePdsData },\n ...options,\n });\n}\n\n/**\n * Delete the authenticated user's account. Returns the deleted handle\n * on success (used by the post-delete confirmation screen).\n *\n * `deletePdsData: true` also deletes the corresponding records on the\n * user's PDS; `false` leaves the PDS records intact.\n *\n * Destructive. Same caveat as {@link resetProfile}.\n */\nexport function deleteAccount(\n config: SifaApiConfig,\n deletePdsData: boolean,\n options: ApiFetchOptions = {},\n): Promise<DeleteAccountResult> {\n return apiWrite<{ ok?: boolean; handle?: string; pds?: PdsWipeOutcome }>(\n config,\n '/api/profile/account',\n 'DELETE',\n {\n body: { deletePdsData },\n ...options,\n },\n );\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AAkDA,SAAS,iBACd,QACA,UAA2B,CAAC,GACN;AACtB,SAAO,SAAsB,QAAQ,6BAA6B;AAAA,IAChE,aAAa;AAAA,IACb,GAAG;AAAA,EACL,CAAC;AACH;AA4BO,SAAS,aACd,QACA,eACA,UAA2B,CAAC,GACC;AAC7B,SAAO,SAAiD,QAAQ,sBAAsB,UAAU;AAAA,IAC9F,MAAM,EAAE,cAAc;AAAA,IACtB,GAAG;AAAA,EACL,CAAC;AACH;AAWO,SAAS,cACd,QACA,eACA,UAA2B,CAAC,GACE;AAC9B,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,MACE,MAAM,EAAE,cAAc;AAAA,MACtB,GAAG;AAAA,IACL;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/query/fetchers/external-accounts.ts"],"sourcesContent":["import type { ExternalAccount } from '../../types/index.js';\nimport {\n apiFetch,\n encodeIdentifier,\n apiWrite,\n type ApiFetchOptions,\n type SifaApiConfig,\n type WriteResult,\n} from '../client.js';\n\n/** Body accepted by {@link createExternalAccount} / {@link updateExternalAccount}. */\nexport interface ExternalAccountInput {\n platform: string;\n url: string;\n label?: string;\n feedUrl?: string;\n}\n\n/** Extended create result for {@link createExternalAccount}. */\nexport
|
|
1
|
+
{"version":3,"sources":["../../../src/query/fetchers/external-accounts.ts"],"sourcesContent":["import type { ExternalAccount } from '../../types/index.js';\nimport {\n apiFetch,\n encodeIdentifier,\n apiWrite,\n type ApiFetchOptions,\n type SifaApiConfig,\n type WriteResult,\n} from '../client.js';\n\n/** Body accepted by {@link createExternalAccount} / {@link updateExternalAccount}. */\nexport interface ExternalAccountInput {\n platform: string;\n url: string;\n label?: string;\n feedUrl?: string;\n}\n\n/** Extended create result for {@link createExternalAccount}. */\nexport type CreateExternalAccountResult = WriteResult<{\n rkey?: string;\n feedUrl?: string | null;\n}>;\n\n/** Extended write result for {@link verifyExternalAccount}. */\nexport type VerifyExternalAccountResult = WriteResult<{\n verified?: boolean;\n verifiedVia?: string;\n}>;\n\n/** List external accounts attached to a profile. Returns `[]` on error. */\nexport async function fetchExternalAccounts(\n config: SifaApiConfig,\n handleOrDid: string,\n options: ApiFetchOptions = {},\n): Promise<ExternalAccount[]> {\n const path = `/api/profile/${encodeIdentifier(handleOrDid)}/external-accounts`;\n try {\n const data = await apiFetch<{ accounts?: ExternalAccount[] }>(config, path, {\n credentials: 'include',\n ...options,\n });\n return data.accounts ?? [];\n } catch {\n return [];\n }\n}\n\n/**\n * Create a new external account record. Returns the newly-created `rkey`\n * and the server-resolved `feedUrl` (sifa-api inspects the target for\n * RSS feeds on platforms that publish them).\n */\nexport function createExternalAccount(\n config: SifaApiConfig,\n data: ExternalAccountInput,\n options: ApiFetchOptions = {},\n): Promise<CreateExternalAccountResult> {\n return apiWrite<{ rkey?: string; feedUrl?: string | null }>(\n config,\n '/api/profile/external-accounts',\n 'POST',\n { body: data, ...options },\n );\n}\n\n/** Update an existing external account by `rkey`. */\nexport function updateExternalAccount(\n config: SifaApiConfig,\n rkey: string,\n data: ExternalAccountInput,\n options: ApiFetchOptions = {},\n): Promise<WriteResult> {\n return apiWrite(config, `/api/profile/external-accounts/${encodeURIComponent(rkey)}`, 'PUT', {\n body: data,\n ...options,\n });\n}\n\n/** Delete an external account by `rkey`. */\nexport function deleteExternalAccount(\n config: SifaApiConfig,\n rkey: string,\n options: ApiFetchOptions = {},\n): Promise<WriteResult> {\n return apiWrite(\n config,\n `/api/profile/external-accounts/${encodeURIComponent(rkey)}`,\n 'DELETE',\n options,\n );\n}\n\n/** Mark an external account as the user's primary. */\nexport function setExternalAccountPrimary(\n config: SifaApiConfig,\n rkey: string,\n options: ApiFetchOptions = {},\n): Promise<WriteResult> {\n return apiWrite(\n config,\n `/api/profile/external-accounts/${encodeURIComponent(rkey)}/primary`,\n 'PUT',\n options,\n );\n}\n\n/** Clear the \"primary\" flag on an external account. */\nexport function unsetExternalAccountPrimary(\n config: SifaApiConfig,\n rkey: string,\n options: ApiFetchOptions = {},\n): Promise<WriteResult> {\n return apiWrite(\n config,\n `/api/profile/external-accounts/${encodeURIComponent(rkey)}/primary`,\n 'DELETE',\n options,\n );\n}\n\n/**\n * Run server-side verification on an external account (e.g. inspect\n * the target for a keytrace claim). Returns `{ verified, verifiedVia }`\n * on success.\n */\nexport function verifyExternalAccount(\n config: SifaApiConfig,\n rkey: string,\n options: ApiFetchOptions = {},\n): Promise<VerifyExternalAccountResult> {\n return apiWrite<{ verified?: boolean; verifiedVia?: string }>(\n config,\n `/api/profile/external-accounts/${encodeURIComponent(rkey)}/verify`,\n 'POST',\n { body: {}, ...options },\n );\n}\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAuBP,eAAsB,sBACpB,QACA,aACA,UAA2B,CAAC,GACA;AAC5B,QAAM,OAAO,gBAAgB,iBAAiB,WAAW,CAAC;AAC1D,MAAI;AACF,UAAM,OAAO,MAAM,SAA2C,QAAQ,MAAM;AAAA,MAC1E,aAAa;AAAA,MACb,GAAG;AAAA,IACL,CAAC;AACD,WAAO,KAAK,YAAY,CAAC;AAAA,EAC3B,QAAQ;AACN,WAAO,CAAC;AAAA,EACV;AACF;AAOO,SAAS,sBACd,QACA,MACA,UAA2B,CAAC,GACU;AACtC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,EAAE,MAAM,MAAM,GAAG,QAAQ;AAAA,EAC3B;AACF;AAGO,SAAS,sBACd,QACA,MACA,MACA,UAA2B,CAAC,GACN;AACtB,SAAO,SAAS,QAAQ,kCAAkC,mBAAmB,IAAI,CAAC,IAAI,OAAO;AAAA,IAC3F,MAAM;AAAA,IACN,GAAG;AAAA,EACL,CAAC;AACH;AAGO,SAAS,sBACd,QACA,MACA,UAA2B,CAAC,GACN;AACtB,SAAO;AAAA,IACL;AAAA,IACA,kCAAkC,mBAAmB,IAAI,CAAC;AAAA,IAC1D;AAAA,IACA;AAAA,EACF;AACF;AAGO,SAAS,0BACd,QACA,MACA,UAA2B,CAAC,GACN;AACtB,SAAO;AAAA,IACL;AAAA,IACA,kCAAkC,mBAAmB,IAAI,CAAC;AAAA,IAC1D;AAAA,IACA;AAAA,EACF;AACF;AAGO,SAAS,4BACd,QACA,MACA,UAA2B,CAAC,GACN;AACtB,SAAO;AAAA,IACL;AAAA,IACA,kCAAkC,mBAAmB,IAAI,CAAC;AAAA,IAC1D;AAAA,IACA;AAAA,EACF;AACF;AAOO,SAAS,sBACd,QACA,MACA,UAA2B,CAAC,GACU;AACtC,SAAO;AAAA,IACL;AAAA,IACA,kCAAkC,mBAAmB,IAAI,CAAC;AAAA,IAC1D;AAAA,IACA,EAAE,MAAM,CAAC,GAAG,GAAG,QAAQ;AAAA,EACzB;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/query/fetchers/follow.ts"],"sourcesContent":["import {\n apiFetch,\n encodeIdentifier,\n apiWrite,\n type ApiFetchOptions,\n type SifaApiConfig,\n type WriteResult,\n} from '../client.js';\nimport type { ActivityFeedResponse } from './activity.js';\n\nexport interface FollowProfile {\n did: string;\n handle: string;\n displayName?: string;\n headline?: string;\n avatarUrl?: string;\n source: string;\n claimed: boolean;\n followedAt: string;\n blueskyVerified?: boolean;\n blueskyVerifiedAt?: string | null;\n}\n\nexport interface FollowingResponse {\n follows: FollowProfile[];\n cursor?: string;\n}\n\n/** People the authenticated user follows. Empty on error. */\nexport async function fetchFollowing(\n config: SifaApiConfig,\n opts: { source?: string; cursor?: string; limit?: number } & ApiFetchOptions = {},\n): Promise<FollowingResponse> {\n const params = new URLSearchParams();\n if (opts.source) params.set('source', opts.source);\n if (opts.cursor) params.set('cursor', opts.cursor);\n if (opts.limit) params.set('limit', String(opts.limit));\n const qs = params.toString();\n\n try {\n return await apiFetch<FollowingResponse>(config, `/api/following${qs ? `?${qs}` : ''}`, {\n credentials: 'include',\n cache: 'no-store',\n ...opts,\n });\n } catch {\n return { follows: [] };\n }\n}\n\n/**\n * Result of {@link followUser}. Extends {@link WriteResult} with the\n * follow `rkey` returned by sifa-api on success. Self-follow + invalid\n * handle surface as `success: false` with the server-provided message;\n * dup-follow is idempotent (sifa-api E7) and resolves as `success: true`.\n */\nexport interface FollowUserResult extends WriteResult {\n rkey?: string;\n /** DID of the followed subject (server-resolved from the handle). */\n subjectDid?: string;\n}\n\n/**\n * Create an `id.sifa.graph.follow` record on the caller's PDS via the\n * AppView. Idempotent on duplicate (server catches the unique-violation\n * and returns 200, per sifa-api#673 E7).\n */\nexport function followUser(\n config: SifaApiConfig,\n handle: string,\n opts: { note?: string } & Omit<ApiFetchOptions, 'method' | 'body'> = {},\n): Promise<FollowUserResult> {\n const { note, ...rest } = opts;\n return apiWrite<{ rkey?: string; subjectDid?: string }>(\n config,\n `/api/follow/${encodeIdentifier(handle)}`,\n 'POST',\n {\n body: note !== undefined ? { note } : undefined,\n ...rest,\n },\n );\n}\n\n/** Delete the authenticated viewer's `id.sifa.graph.follow` for `handle`. */\nexport function unfollowUser(\n config: SifaApiConfig,\n handle: string,\n opts: Omit<ApiFetchOptions, 'method' | 'body'> = {},\n): Promise<WriteResult> {\n return apiWrite(config, `/api/follow/${encodeIdentifier(handle)}`, 'DELETE', opts);\n}\n\nexport interface FollowListPage {\n follows: FollowProfile[];\n cursor: string | null;\n}\n\nexport interface FetchFollowListOptions extends ApiFetchOptions {\n cursor?: string;\n limit?: number;\n /**\n * Pass the caller's `Cookie` header on Next.js RSC server-side calls\n * (mirrors {@link FetchActivityFeedOptions}; required for authenticated\n * server fetches because `credentials: 'include'` does not propagate\n * cookies from RSC).\n */\n cookieHeader?: string;\n}\n\nfunction buildListPath(prefix: string, opts: FetchFollowListOptions): string {\n const params = new URLSearchParams();\n if (opts.cursor) params.set('cursor', opts.cursor);\n if (opts.limit) params.set('limit', String(opts.limit));\n const qs = params.toString();\n return `${prefix}${qs ? `?${qs}` : ''}`;\n}\n\n/**\n * Paginated list of `handle`'s followers. Returns an empty page on error\n * so the UI can render a graceful \"no followers yet\" state.\n */\nexport async function getFollowers(\n config: SifaApiConfig,\n handle: string,\n opts: FetchFollowListOptions = {},\n): Promise<FollowListPage> {\n const headers: Record<string, string> = { ...(opts.headers ?? {}) };\n if (opts.cookieHeader) headers.cookie = opts.cookieHeader;\n try {\n const res = await apiFetch<{ follows: FollowProfile[]; cursor?: string | null }>(\n config,\n buildListPath(`/api/profile/${encodeIdentifier(handle)}/followers`, opts),\n { credentials: 'include', cache: 'no-store', ...opts, headers },\n );\n return { follows: res.follows, cursor: res.cursor ?? null };\n } catch {\n return { follows: [], cursor: null };\n }\n}\n\n/** Paginated list of who `handle` follows. */\nexport async function getFollowing(\n config: SifaApiConfig,\n handle: string,\n opts: FetchFollowListOptions = {},\n): Promise<FollowListPage> {\n const headers: Record<string, string> = { ...(opts.headers ?? {}) };\n if (opts.cookieHeader) headers.cookie = opts.cookieHeader;\n try {\n const res = await apiFetch<{ follows: FollowProfile[]; cursor?: string | null }>(\n config,\n buildListPath(`/api/profile/${encodeIdentifier(handle)}/following`, opts),\n { credentials: 'include', cache: 'no-store', ...opts, headers },\n );\n return { follows: res.follows, cursor: res.cursor ?? null };\n } catch {\n return { follows: [], cursor: null };\n }\n}\n\n/** The method binding for the following-feed service-auth token; MUST match the\n * sifa-api endpoint's `lxm`. */\nexport const FOLLOWING_FEED_LXM = 'id.sifa.feed.getFollowingFeed';\n\n/** One app the viewer's network is active on, for the feed's source tabs. */\nexport interface FollowingFeedApp {\n /** Registry app id, e.g. `tangled`. Pass back as {@link FetchFollowingFeedOptions.app}. */\n id: string;\n name: string;\n /** Summed recent activity across the network; the tab ordering. */\n count: number;\n}\n\n/**\n * Why a following-feed page came back empty. Lets a client say something true\n * per case instead of one catch-all sentence, and point at the right next step.\n */\nexport type FollowingFeedEmptyReason =\n | 'no_follows'\n | 'no_visible_follows'\n | 'no_cross_app_activity'\n | 'no_recent_records'\n | 'all_hidden'\n | 'nothing_renderable'\n | 'hydration_failed'\n /** The feed is still being built. Nothing is wrong: ask again shortly. */\n | 'building';\n\n/** Options for {@link fetchFollowingFeed}. */\nexport interface FetchFollowingFeedOptions extends ApiFetchOptions {\n limit?: number;\n /**\n * Opt in to the viewer's Bluesky activity too. Off by default: the point of\n * the feed is what connections do on OTHER apps.\n *\n * Ignored when {@link app} is set, since a source tab selects one app.\n */\n includeBluesky?: boolean;\n /**\n * Restrict the page to one app (a registry id from the response's `apps`).\n * This is what a source tab selects. `app: 'bluesky'` selects Bluesky even\n * though it is excluded from the default mixed view.\n */\n app?: string;\n /** Forward a `Cookie` header on Next.js RSC server-side calls (web). */\n cookieHeader?: string;\n}\n\n/** The following feed's response: an activity feed plus its tab metadata. */\nexport interface FollowingFeedResponse extends ActivityFeedResponse {\n /**\n * Apps the viewer's network is actually active on, most active first.\n * Present on empty pages too, so a client's tabs survive a quiet tab.\n */\n apps?: FollowingFeedApp[];\n /** Set only when `items` is empty. */\n reason?: FollowingFeedEmptyReason;\n /** When this feed was built (ISO 8601). Absent on a `building` answer. */\n builtAt?: string;\n /**\n * True when this is an older build, served while a newer one is built in\n * the background. Poll {@link fetchFollowingFeedVersion} to learn when the\n * newer one is ready.\n */\n stale?: boolean;\n}\n\n/** Query string and auth headers shared by the feed and its version check. */\nasync function followingFeedRequest(config: SifaApiConfig, opts: FetchFollowingFeedOptions) {\n const params = new URLSearchParams();\n if (opts.limit) params.set('limit', String(opts.limit));\n // A selected tab decides Bluesky on its own, so the flag is not also sent.\n if (opts.app) params.set('app', opts.app);\n else if (opts.includeBluesky) params.set('includeBluesky', 'true');\n const qs = params.toString();\n\n const headers: Record<string, string> = { ...(opts.headers ?? {}) };\n if (opts.cookieHeader) headers.cookie = opts.cookieHeader;\n if (config.getAuthToken) {\n const token = await config.getAuthToken(FOLLOWING_FEED_LXM);\n if (token) headers.Authorization = `Bearer ${token}`;\n }\n return { query: qs ? `?${qs}` : '', headers };\n}\n\n/**\n * The viewer's cross-app following feed: what OTHER apps their connections use\n * (Tangled, WhiteWind, Smoke Signal, ...) — Bluesky is excluded server-side by\n * default, as it is the least interesting part and other apps already surface\n * it. Pass `includeBluesky: true` to bring it back in.\n *\n * Auth is identity-only server-side, so the NATIVE app supplies\n * `config.getAuthToken` to mint a service-auth Bearer, while WEB relies on its\n * session cookie (`credentials: 'include'`). Returns `null` on error. v1 is a\n * finite first page (no cursor yet).\n */\nexport async function fetchFollowingFeed(\n config: SifaApiConfig,\n opts: FetchFollowingFeedOptions = {},\n): Promise<FollowingFeedResponse | null> {\n const { query, headers } = await followingFeedRequest(config, opts);\n try {\n return await apiFetch<FollowingFeedResponse>(config, `/api/following/feed${query}`, {\n credentials: 'include',\n cache: 'no-store',\n ...opts,\n headers,\n });\n } catch {\n return null;\n }\n}\n\n/** When the cached following feed for a query was built. */\nexport interface FollowingFeedVersion {\n /** ISO 8601, or null when nothing is cached for this query. */\n builtAt: string | null;\n}\n\n/**\n * When the cached following feed for the same query was built. Cheap: it never\n * builds a feed. A client showing a `stale` feed polls this and offers the\n * newer one once {@link isNewerFollowingFeed} says so. Returns `null` on error.\n */\nexport async function fetchFollowingFeedVersion(\n config: SifaApiConfig,\n opts: FetchFollowingFeedOptions = {},\n): Promise<FollowingFeedVersion | null> {\n const { query, headers } = await followingFeedRequest(config, opts);\n try {\n return await apiFetch<FollowingFeedVersion>(config, `/api/following/feed/version${query}`, {\n credentials: 'include',\n cache: 'no-store',\n ...opts,\n headers,\n });\n } catch {\n return null;\n }\n}\n\n/** True when `latestBuiltAt` is a newer build than the one shown (`shownBuiltAt`). */\nexport function isNewerFollowingFeed(\n shownBuiltAt: string | null | undefined,\n latestBuiltAt: string | null | undefined,\n): boolean {\n if (!shownBuiltAt || !latestBuiltAt) return false;\n return Date.parse(latestBuiltAt) > Date.parse(shownBuiltAt);\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAsBP,eAAsB,eACpB,QACA,OAA+E,CAAC,GACpD;AAC5B,QAAM,SAAS,IAAI,gBAAgB;AACnC,MAAI,KAAK,OAAQ,QAAO,IAAI,UAAU,KAAK,MAAM;AACjD,MAAI,KAAK,OAAQ,QAAO,IAAI,UAAU,KAAK,MAAM;AACjD,MAAI,KAAK,MAAO,QAAO,IAAI,SAAS,OAAO,KAAK,KAAK,CAAC;AACtD,QAAM,KAAK,OAAO,SAAS;AAE3B,MAAI;AACF,WAAO,MAAM,SAA4B,QAAQ,iBAAiB,KAAK,IAAI,E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,QAAQ,IAAI;AAClE,MAAI;AACF,WAAO,MAAM,SAAgC,QAAQ,sBAAsB,KAAK,IAAI;AAAA,MAClF,aAAa;AAAA,MACb,OAAO;AAAA,MACP,GAAG;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAaA,eAAsB,0BACpB,QACA,OAAkC,CAAC,GACG;AACtC,QAAM,EAAE,OAAO,QAAQ,IAAI,MAAM,qBAAqB,QAAQ,IAAI;AAClE,MAAI;AACF,WAAO,MAAM,SAA+B,QAAQ,8BAA8B,KAAK,IAAI;AAAA,MACzF,aAAa;AAAA,MACb,OAAO;AAAA,MACP,GAAG;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAGO,SAAS,qBACd,cACA,eACS;AACT,MAAI,CAAC,gBAAgB,CAAC,cAAe,QAAO;AAC5C,SAAO,KAAK,MAAM,aAAa,IAAI,KAAK,MAAM,YAAY;AAC5D;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/query/fetchers/follow.ts"],"sourcesContent":["import {\n apiFetch,\n encodeIdentifier,\n apiWrite,\n type ApiFetchOptions,\n type SifaApiConfig,\n type WriteResult,\n} from '../client.js';\nimport type { ActivityFeedResponse } from './activity.js';\n\nexport interface FollowProfile {\n did: string;\n handle: string;\n displayName?: string;\n headline?: string;\n avatarUrl?: string;\n source: string;\n claimed: boolean;\n followedAt: string;\n blueskyVerified?: boolean;\n blueskyVerifiedAt?: string | null;\n}\n\nexport interface FollowingResponse {\n follows: FollowProfile[];\n cursor?: string;\n}\n\n/** People the authenticated user follows. Empty on error. */\nexport async function fetchFollowing(\n config: SifaApiConfig,\n opts: { source?: string; cursor?: string; limit?: number } & ApiFetchOptions = {},\n): Promise<FollowingResponse> {\n const params = new URLSearchParams();\n if (opts.source) params.set('source', opts.source);\n if (opts.cursor) params.set('cursor', opts.cursor);\n if (opts.limit) params.set('limit', String(opts.limit));\n const qs = params.toString();\n\n try {\n return await apiFetch<FollowingResponse>(config, `/api/following${qs ? `?${qs}` : ''}`, {\n credentials: 'include',\n cache: 'no-store',\n ...opts,\n });\n } catch {\n return { follows: [] };\n }\n}\n\n/**\n * Result of {@link followUser}. Extends {@link WriteResult} with the\n * follow `rkey` returned by sifa-api on success. Self-follow + invalid\n * handle surface as `success: false` with the server-provided message;\n * dup-follow is idempotent (sifa-api E7) and resolves as `success: true`.\n */\nexport type FollowUserResult = WriteResult<{\n rkey?: string;\n /** DID of the followed subject (server-resolved from the handle). */\n subjectDid?: string;\n}>;\n\n/**\n * Create an `id.sifa.graph.follow` record on the caller's PDS via the\n * AppView. Idempotent on duplicate (server catches the unique-violation\n * and returns 200, per sifa-api#673 E7).\n */\nexport function followUser(\n config: SifaApiConfig,\n handle: string,\n opts: { note?: string } & Omit<ApiFetchOptions, 'method' | 'body'> = {},\n): Promise<FollowUserResult> {\n const { note, ...rest } = opts;\n return apiWrite<{ rkey?: string; subjectDid?: string }>(\n config,\n `/api/follow/${encodeIdentifier(handle)}`,\n 'POST',\n {\n body: note !== undefined ? { note } : undefined,\n ...rest,\n },\n );\n}\n\n/** Delete the authenticated viewer's `id.sifa.graph.follow` for `handle`. */\nexport function unfollowUser(\n config: SifaApiConfig,\n handle: string,\n opts: Omit<ApiFetchOptions, 'method' | 'body'> = {},\n): Promise<WriteResult> {\n return apiWrite(config, `/api/follow/${encodeIdentifier(handle)}`, 'DELETE', opts);\n}\n\nexport interface FollowListPage {\n follows: FollowProfile[];\n cursor: string | null;\n}\n\nexport interface FetchFollowListOptions extends ApiFetchOptions {\n cursor?: string;\n limit?: number;\n /**\n * Pass the caller's `Cookie` header on Next.js RSC server-side calls\n * (mirrors {@link FetchActivityFeedOptions}; required for authenticated\n * server fetches because `credentials: 'include'` does not propagate\n * cookies from RSC).\n */\n cookieHeader?: string;\n}\n\nfunction buildListPath(prefix: string, opts: FetchFollowListOptions): string {\n const params = new URLSearchParams();\n if (opts.cursor) params.set('cursor', opts.cursor);\n if (opts.limit) params.set('limit', String(opts.limit));\n const qs = params.toString();\n return `${prefix}${qs ? `?${qs}` : ''}`;\n}\n\n/**\n * Paginated list of `handle`'s followers. Returns an empty page on error\n * so the UI can render a graceful \"no followers yet\" state.\n */\nexport async function getFollowers(\n config: SifaApiConfig,\n handle: string,\n opts: FetchFollowListOptions = {},\n): Promise<FollowListPage> {\n const headers: Record<string, string> = { ...(opts.headers ?? {}) };\n if (opts.cookieHeader) headers.cookie = opts.cookieHeader;\n try {\n const res = await apiFetch<{ follows: FollowProfile[]; cursor?: string | null }>(\n config,\n buildListPath(`/api/profile/${encodeIdentifier(handle)}/followers`, opts),\n { credentials: 'include', cache: 'no-store', ...opts, headers },\n );\n return { follows: res.follows, cursor: res.cursor ?? null };\n } catch {\n return { follows: [], cursor: null };\n }\n}\n\n/** Paginated list of who `handle` follows. */\nexport async function getFollowing(\n config: SifaApiConfig,\n handle: string,\n opts: FetchFollowListOptions = {},\n): Promise<FollowListPage> {\n const headers: Record<string, string> = { ...(opts.headers ?? {}) };\n if (opts.cookieHeader) headers.cookie = opts.cookieHeader;\n try {\n const res = await apiFetch<{ follows: FollowProfile[]; cursor?: string | null }>(\n config,\n buildListPath(`/api/profile/${encodeIdentifier(handle)}/following`, opts),\n { credentials: 'include', cache: 'no-store', ...opts, headers },\n );\n return { follows: res.follows, cursor: res.cursor ?? null };\n } catch {\n return { follows: [], cursor: null };\n }\n}\n\n/** The method binding for the following-feed service-auth token; MUST match the\n * sifa-api endpoint's `lxm`. */\nexport const FOLLOWING_FEED_LXM = 'id.sifa.feed.getFollowingFeed';\n\n/** One app the viewer's network is active on, for the feed's source tabs. */\nexport interface FollowingFeedApp {\n /** Registry app id, e.g. `tangled`. Pass back as {@link FetchFollowingFeedOptions.app}. */\n id: string;\n name: string;\n /** Summed recent activity across the network; the tab ordering. */\n count: number;\n}\n\n/**\n * Why a following-feed page came back empty. Lets a client say something true\n * per case instead of one catch-all sentence, and point at the right next step.\n */\nexport type FollowingFeedEmptyReason =\n | 'no_follows'\n | 'no_visible_follows'\n | 'no_cross_app_activity'\n | 'no_recent_records'\n | 'all_hidden'\n | 'nothing_renderable'\n | 'hydration_failed'\n /** The feed is still being built. Nothing is wrong: ask again shortly. */\n | 'building';\n\n/** Options for {@link fetchFollowingFeed}. */\nexport interface FetchFollowingFeedOptions extends ApiFetchOptions {\n limit?: number;\n /**\n * Opt in to the viewer's Bluesky activity too. Off by default: the point of\n * the feed is what connections do on OTHER apps.\n *\n * Ignored when {@link app} is set, since a source tab selects one app.\n */\n includeBluesky?: boolean;\n /**\n * Restrict the page to one app (a registry id from the response's `apps`).\n * This is what a source tab selects. `app: 'bluesky'` selects Bluesky even\n * though it is excluded from the default mixed view.\n */\n app?: string;\n /** Forward a `Cookie` header on Next.js RSC server-side calls (web). */\n cookieHeader?: string;\n}\n\n/** The following feed's response: an activity feed plus its tab metadata. */\nexport interface FollowingFeedResponse extends ActivityFeedResponse {\n /**\n * Apps the viewer's network is actually active on, most active first.\n * Present on empty pages too, so a client's tabs survive a quiet tab.\n */\n apps?: FollowingFeedApp[];\n /** Set only when `items` is empty. */\n reason?: FollowingFeedEmptyReason;\n /** When this feed was built (ISO 8601). Absent on a `building` answer. */\n builtAt?: string;\n /**\n * True when this is an older build, served while a newer one is built in\n * the background. Poll {@link fetchFollowingFeedVersion} to learn when the\n * newer one is ready.\n */\n stale?: boolean;\n}\n\n/** Query string and auth headers shared by the feed and its version check. */\nasync function followingFeedRequest(config: SifaApiConfig, opts: FetchFollowingFeedOptions) {\n const params = new URLSearchParams();\n if (opts.limit) params.set('limit', String(opts.limit));\n // A selected tab decides Bluesky on its own, so the flag is not also sent.\n if (opts.app) params.set('app', opts.app);\n else if (opts.includeBluesky) params.set('includeBluesky', 'true');\n const qs = params.toString();\n\n const headers: Record<string, string> = { ...(opts.headers ?? {}) };\n if (opts.cookieHeader) headers.cookie = opts.cookieHeader;\n if (config.getAuthToken) {\n const token = await config.getAuthToken(FOLLOWING_FEED_LXM);\n if (token) headers.Authorization = `Bearer ${token}`;\n }\n return { query: qs ? `?${qs}` : '', headers };\n}\n\n/**\n * The viewer's cross-app following feed: what OTHER apps their connections use\n * (Tangled, WhiteWind, Smoke Signal, ...) — Bluesky is excluded server-side by\n * default, as it is the least interesting part and other apps already surface\n * it. Pass `includeBluesky: true` to bring it back in.\n *\n * Auth is identity-only server-side, so the NATIVE app supplies\n * `config.getAuthToken` to mint a service-auth Bearer, while WEB relies on its\n * session cookie (`credentials: 'include'`). Returns `null` on error. v1 is a\n * finite first page (no cursor yet).\n */\nexport async function fetchFollowingFeed(\n config: SifaApiConfig,\n opts: FetchFollowingFeedOptions = {},\n): Promise<FollowingFeedResponse | null> {\n const { query, headers } = await followingFeedRequest(config, opts);\n try {\n return await apiFetch<FollowingFeedResponse>(config, `/api/following/feed${query}`, {\n credentials: 'include',\n cache: 'no-store',\n ...opts,\n headers,\n });\n } catch {\n return null;\n }\n}\n\n/** When the cached following feed for a query was built. */\nexport interface FollowingFeedVersion {\n /** ISO 8601, or null when nothing is cached for this query. */\n builtAt: string | null;\n}\n\n/**\n * When the cached following feed for the same query was built. Cheap: it never\n * builds a feed. A client showing a `stale` feed polls this and offers the\n * newer one once {@link isNewerFollowingFeed} says so. Returns `null` on error.\n */\nexport async function fetchFollowingFeedVersion(\n config: SifaApiConfig,\n opts: FetchFollowingFeedOptions = {},\n): Promise<FollowingFeedVersion | null> {\n const { query, headers } = await followingFeedRequest(config, opts);\n try {\n return await apiFetch<FollowingFeedVersion>(config, `/api/following/feed/version${query}`, {\n credentials: 'include',\n cache: 'no-store',\n ...opts,\n headers,\n });\n } catch {\n return null;\n }\n}\n\n/** True when `latestBuiltAt` is a newer build than the one shown (`shownBuiltAt`). */\nexport function isNewerFollowingFeed(\n shownBuiltAt: string | null | undefined,\n latestBuiltAt: string | null | undefined,\n): boolean {\n if (!shownBuiltAt || !latestBuiltAt) return false;\n return Date.parse(latestBuiltAt) > Date.parse(shownBuiltAt);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