@singi-labs/sifa-sdk 0.9.18 → 0.9.20
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/feed-DHTy7fUN.d.cts +254 -0
- package/dist/feed-DHTy7fUN.d.ts +254 -0
- package/dist/{index-DCpMh2Ny.d.cts → index-DYUYJxOs.d.cts} +1 -1
- package/dist/{index-DCpMh2Ny.d.ts → index-DYUYJxOs.d.ts} +1 -1
- package/dist/index.cjs +114 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +103 -4
- package/dist/index.js.map +1 -1
- package/dist/keys-D-vNPzXx.d.ts +1085 -0
- package/dist/keys-DRD79nDE.d.cts +1085 -0
- package/dist/query/fetchers/index.cjs +155 -1
- package/dist/query/fetchers/index.cjs.map +1 -1
- package/dist/query/fetchers/index.d.cts +6 -933
- package/dist/query/fetchers/index.d.ts +6 -933
- package/dist/query/fetchers/index.js +146 -2
- package/dist/query/fetchers/index.js.map +1 -1
- package/dist/query/hooks/index.cjs +2268 -0
- package/dist/query/hooks/index.cjs.map +1 -0
- package/dist/query/hooks/index.d.cts +479 -0
- package/dist/query/hooks/index.d.ts +479 -0
- package/dist/query/hooks/index.js +2178 -0
- package/dist/query/hooks/index.js.map +1 -0
- package/dist/query/index.cjs +340 -1
- package/dist/query/index.cjs.map +1 -1
- package/dist/query/index.d.cts +9 -352
- package/dist/query/index.d.ts +9 -352
- package/dist/query/index.js +322 -3
- package/dist/query/index.js.map +1 -1
- package/dist/schemas/index.cjs +102 -1
- package/dist/schemas/index.cjs.map +1 -1
- package/dist/schemas/index.d.cts +28 -2
- package/dist/schemas/index.d.ts +28 -2
- package/dist/schemas/index.js +91 -2
- package/dist/schemas/index.js.map +1 -1
- package/package.json +14 -4
|
@@ -0,0 +1,2268 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
var reactQuery = require('@tanstack/react-query');
|
|
6
|
+
|
|
7
|
+
// src/query/config.tsx
|
|
8
|
+
var SifaConfigContext = react.createContext(null);
|
|
9
|
+
function SifaProvider({ config, children }) {
|
|
10
|
+
return /* @__PURE__ */ jsxRuntime.jsx(SifaConfigContext.Provider, { value: config, children });
|
|
11
|
+
}
|
|
12
|
+
function useSifaConfig() {
|
|
13
|
+
const ctx = react.useContext(SifaConfigContext);
|
|
14
|
+
if (!ctx) {
|
|
15
|
+
throw new Error(
|
|
16
|
+
"useSifaConfig must be used inside <SifaProvider>. Wrap your app once with <SifaProvider config={...}>."
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
return ctx;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/query/client.ts
|
|
23
|
+
var ApiError = class extends Error {
|
|
24
|
+
status;
|
|
25
|
+
body;
|
|
26
|
+
constructor(message, status, body) {
|
|
27
|
+
super(message);
|
|
28
|
+
this.name = "ApiError";
|
|
29
|
+
this.status = status;
|
|
30
|
+
this.body = body;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
34
|
+
var MAX_RATE_LIMIT_RETRIES = 3;
|
|
35
|
+
var RATE_LIMIT_RETRY_CAP_SECONDS = 3;
|
|
36
|
+
async function apiFetch(config, path, options = {}) {
|
|
37
|
+
const fetchFn = config.fetch ?? globalThis.fetch;
|
|
38
|
+
const url = `${config.baseUrl}${path}`;
|
|
39
|
+
const maxRetries = options.retryOn429 ? MAX_RATE_LIMIT_RETRIES : 0;
|
|
40
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
41
|
+
const signal = options.signal ?? AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
42
|
+
const headers = { ...options.headers ?? {} };
|
|
43
|
+
let body;
|
|
44
|
+
if (options.body !== void 0) {
|
|
45
|
+
headers["Content-Type"] ??= "application/json";
|
|
46
|
+
body = JSON.stringify(options.body);
|
|
47
|
+
}
|
|
48
|
+
const init = {
|
|
49
|
+
method: options.method ?? "GET",
|
|
50
|
+
headers,
|
|
51
|
+
body,
|
|
52
|
+
signal,
|
|
53
|
+
credentials: options.credentials,
|
|
54
|
+
cache: options.cache,
|
|
55
|
+
...options.next ? { next: options.next } : {}
|
|
56
|
+
};
|
|
57
|
+
const res = await fetchFn(url, init);
|
|
58
|
+
if (res.status === 429 && attempt < maxRetries) {
|
|
59
|
+
const retryAfterRaw = res.headers.get("retry-after");
|
|
60
|
+
const retryAfter = retryAfterRaw ? Number.parseInt(retryAfterRaw, 10) : 2;
|
|
61
|
+
const waitSeconds = Math.min(
|
|
62
|
+
Number.isFinite(retryAfter) ? retryAfter : 2,
|
|
63
|
+
RATE_LIMIT_RETRY_CAP_SECONDS
|
|
64
|
+
);
|
|
65
|
+
await new Promise((r) => setTimeout(r, waitSeconds * 1e3));
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (!res.ok) {
|
|
69
|
+
let errBody;
|
|
70
|
+
try {
|
|
71
|
+
errBody = await res.json();
|
|
72
|
+
} catch {
|
|
73
|
+
try {
|
|
74
|
+
errBody = await res.text();
|
|
75
|
+
} catch {
|
|
76
|
+
errBody = void 0;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
throw new ApiError(`Sifa API ${res.status} on ${path}`, res.status, errBody);
|
|
80
|
+
}
|
|
81
|
+
return await res.json();
|
|
82
|
+
}
|
|
83
|
+
throw new ApiError(`Sifa API exhausted retries on ${path}`, 429);
|
|
84
|
+
}
|
|
85
|
+
async function apiFetchOrNull(config, path, options = {}) {
|
|
86
|
+
try {
|
|
87
|
+
return await apiFetch(config, path, options);
|
|
88
|
+
} catch (e) {
|
|
89
|
+
if (e instanceof ApiError && e.status === 404) return null;
|
|
90
|
+
throw e;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function extractWriteError(data, status) {
|
|
94
|
+
const body = data ?? {};
|
|
95
|
+
return {
|
|
96
|
+
error: body.message ?? `Request failed (${status})`,
|
|
97
|
+
...body.pdsHost ? { pdsHost: body.pdsHost } : {}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
async function apiWrite(config, path, method, options = {}) {
|
|
101
|
+
try {
|
|
102
|
+
const data = await apiFetch(config, path, {
|
|
103
|
+
method,
|
|
104
|
+
credentials: "include",
|
|
105
|
+
...options
|
|
106
|
+
});
|
|
107
|
+
return { success: true, ...data ?? {} };
|
|
108
|
+
} catch (e) {
|
|
109
|
+
if (e instanceof ApiError) {
|
|
110
|
+
return { success: false, ...extractWriteError(e.body, e.status) };
|
|
111
|
+
}
|
|
112
|
+
return { success: false, error: "Network error" };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function apiWriteCreate(config, path, body, options = {}) {
|
|
116
|
+
return apiWrite(config, path, "POST", {
|
|
117
|
+
body,
|
|
118
|
+
...options
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// src/query/fetchers/profile.ts
|
|
123
|
+
function fetchProfile(config, handleOrDid, options = {}) {
|
|
124
|
+
const path = `/api/profile/${encodeURIComponent(handleOrDid)}`;
|
|
125
|
+
return apiFetchOrNull(config, path, {
|
|
126
|
+
retryOn429: true,
|
|
127
|
+
...options
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
async function fetchAtFundLink(config, did, options = {}) {
|
|
131
|
+
const path = `/api/profiles/${encodeURIComponent(did)}/at-fund-link`;
|
|
132
|
+
try {
|
|
133
|
+
const data = await apiFetch(config, path, {
|
|
134
|
+
next: { revalidate: 3600 },
|
|
135
|
+
timeoutMs: 5e3,
|
|
136
|
+
...options
|
|
137
|
+
});
|
|
138
|
+
return typeof data.url === "string" ? data.url : null;
|
|
139
|
+
} catch {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/query/keys.ts
|
|
145
|
+
var sifaQueryKeys = {
|
|
146
|
+
all: () => ["sifa"],
|
|
147
|
+
profile: {
|
|
148
|
+
all: () => ["sifa", "profile"],
|
|
149
|
+
byHandle: (handleOrDid) => ["sifa", "profile", handleOrDid],
|
|
150
|
+
atFundLink: (did) => ["sifa", "profile", "at-fund-link", did],
|
|
151
|
+
externalAccounts: (handleOrDid) => ["sifa", "profile", "external-accounts", handleOrDid]
|
|
152
|
+
},
|
|
153
|
+
position: {
|
|
154
|
+
all: () => ["sifa", "position"],
|
|
155
|
+
byOwner: (did) => ["sifa", "position", "by-owner", did]
|
|
156
|
+
},
|
|
157
|
+
search: {
|
|
158
|
+
all: () => ["sifa", "search"],
|
|
159
|
+
profiles: (filters) => ["sifa", "search", "profiles", filters],
|
|
160
|
+
skills: (query) => ["sifa", "search", "skills", query],
|
|
161
|
+
canonicalSkills: (query, limit) => ["sifa", "search", "canonical-skills", query, limit],
|
|
162
|
+
filters: () => ["sifa", "search", "filters"]
|
|
163
|
+
},
|
|
164
|
+
discovery: {
|
|
165
|
+
all: () => ["sifa", "discovery"],
|
|
166
|
+
similar: (did, limit) => ["sifa", "discovery", "similar", did, limit],
|
|
167
|
+
suggestions: (opts) => ["sifa", "discovery", "suggestions", opts],
|
|
168
|
+
suggestionCount: (since) => ["sifa", "discovery", "suggestion-count", since ?? null],
|
|
169
|
+
featured: () => ["sifa", "discovery", "featured"]
|
|
170
|
+
},
|
|
171
|
+
follow: {
|
|
172
|
+
all: () => ["sifa", "follow"],
|
|
173
|
+
following: (opts) => ["sifa", "follow", "following", opts],
|
|
174
|
+
followers: (handle) => ["sifa", "follow", "followers", handle],
|
|
175
|
+
followingOf: (handle) => ["sifa", "follow", "following-of", handle],
|
|
176
|
+
feed: (opts) => ["sifa", "follow", "feed", opts],
|
|
177
|
+
mutuals: (handle) => ["sifa", "follow", "mutuals", handle],
|
|
178
|
+
blueskySuggestions: () => ["sifa", "follow", "bluesky-suggestions"]
|
|
179
|
+
},
|
|
180
|
+
admin: {
|
|
181
|
+
all: () => ["sifa", "admin"],
|
|
182
|
+
featureAllowlist: (flag) => ["sifa", "admin", "feature-allowlist", flag]
|
|
183
|
+
},
|
|
184
|
+
stats: {
|
|
185
|
+
all: () => ["sifa", "stats"],
|
|
186
|
+
homepage: () => ["sifa", "stats", "homepage"]
|
|
187
|
+
},
|
|
188
|
+
apps: {
|
|
189
|
+
all: () => ["sifa", "apps"],
|
|
190
|
+
registry: () => ["sifa", "apps", "registry"],
|
|
191
|
+
hidden: () => ["sifa", "apps", "hidden"]
|
|
192
|
+
},
|
|
193
|
+
activity: {
|
|
194
|
+
all: () => ["sifa", "activity"],
|
|
195
|
+
heatmap: (handleOrDid, days) => ["sifa", "activity", "heatmap", handleOrDid, days],
|
|
196
|
+
teaser: (handleOrDid) => ["sifa", "activity", "teaser", handleOrDid],
|
|
197
|
+
feed: (handleOrDid, opts) => ["sifa", "activity", "feed", handleOrDid, opts]
|
|
198
|
+
},
|
|
199
|
+
endorsement: {
|
|
200
|
+
all: () => ["sifa", "endorsement"],
|
|
201
|
+
count: (did) => ["sifa", "endorsement", "count", did]
|
|
202
|
+
},
|
|
203
|
+
stream: {
|
|
204
|
+
all: () => ["sifa", "stream"],
|
|
205
|
+
networkCount: (did) => ["sifa", "stream", "network-count", did]
|
|
206
|
+
},
|
|
207
|
+
reactions: {
|
|
208
|
+
all: () => ["sifa", "reactions"],
|
|
209
|
+
status: (uris) => ["sifa", "reactions", "status", uris],
|
|
210
|
+
accountCheck: (appId) => ["sifa", "reactions", "account-check", appId]
|
|
211
|
+
},
|
|
212
|
+
roadmap: {
|
|
213
|
+
all: () => ["sifa", "roadmap"],
|
|
214
|
+
votes: () => ["sifa", "roadmap", "votes"],
|
|
215
|
+
myVotes: () => ["sifa", "roadmap", "my-votes"]
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
// src/query/hooks/use-profile.ts
|
|
220
|
+
function useProfile(handleOrDid, options) {
|
|
221
|
+
const config = useSifaConfig();
|
|
222
|
+
return reactQuery.useQuery({
|
|
223
|
+
queryKey: sifaQueryKeys.profile.byHandle(handleOrDid ?? ""),
|
|
224
|
+
queryFn: () => fetchProfile(config, handleOrDid ?? ""),
|
|
225
|
+
enabled: Boolean(handleOrDid) && (options?.enabled ?? true),
|
|
226
|
+
...options
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
function useAtFundLink(did, options) {
|
|
230
|
+
const config = useSifaConfig();
|
|
231
|
+
return reactQuery.useQuery({
|
|
232
|
+
queryKey: sifaQueryKeys.profile.atFundLink(did ?? ""),
|
|
233
|
+
queryFn: () => fetchAtFundLink(config, did ?? ""),
|
|
234
|
+
enabled: Boolean(did) && (options?.enabled ?? true),
|
|
235
|
+
...options
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// src/query/fetchers/profile-mutations.ts
|
|
240
|
+
function updateProfileSelf(config, data, options = {}) {
|
|
241
|
+
return apiWrite(config, "/api/profile/self", "PUT", { body: data, ...options });
|
|
242
|
+
}
|
|
243
|
+
function updateProfileOverride(config, data, options = {}) {
|
|
244
|
+
return apiWrite(config, "/api/profile/override", "PUT", { body: data, ...options });
|
|
245
|
+
}
|
|
246
|
+
function refreshPds(config, options = {}) {
|
|
247
|
+
return apiWrite(
|
|
248
|
+
config,
|
|
249
|
+
"/api/profile/refresh-pds",
|
|
250
|
+
"POST",
|
|
251
|
+
options
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
async function uploadAvatar(config, file, options = {}) {
|
|
255
|
+
const fetchFn = config.fetch ?? globalThis.fetch;
|
|
256
|
+
const url = `${config.baseUrl}/api/profile/avatar`;
|
|
257
|
+
const formData = new FormData();
|
|
258
|
+
formData.append("file", file);
|
|
259
|
+
try {
|
|
260
|
+
const res = await fetchFn(url, {
|
|
261
|
+
method: "POST",
|
|
262
|
+
credentials: options.credentials ?? "include",
|
|
263
|
+
body: formData,
|
|
264
|
+
signal: options.signal ?? AbortSignal.timeout(options.timeoutMs ?? 3e4),
|
|
265
|
+
headers: options.headers
|
|
266
|
+
});
|
|
267
|
+
if (!res.ok) {
|
|
268
|
+
const errBody = await res.json().catch(() => ({}));
|
|
269
|
+
const msg = errBody.message ?? `Request failed (${res.status})`;
|
|
270
|
+
const pdsHost = errBody.pdsHost;
|
|
271
|
+
return { success: false, error: msg, ...pdsHost ? { pdsHost } : {} };
|
|
272
|
+
}
|
|
273
|
+
const data = await res.json();
|
|
274
|
+
return { success: true, url: data.url };
|
|
275
|
+
} catch {
|
|
276
|
+
return { success: false, error: "Network error" };
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function deleteAvatarOverride(config, options = {}) {
|
|
280
|
+
return apiWrite(config, "/api/profile/avatar", "DELETE", options);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// src/query/hooks/use-profile-mutations.ts
|
|
284
|
+
async function invalidateProfile(queryClient, ownerHandleOrDid) {
|
|
285
|
+
await queryClient.invalidateQueries({
|
|
286
|
+
queryKey: sifaQueryKeys.profile.byHandle(ownerHandleOrDid)
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
function useUpdateProfileSelf(ownerHandleOrDid, options) {
|
|
290
|
+
const config = useSifaConfig();
|
|
291
|
+
const queryClient = reactQuery.useQueryClient();
|
|
292
|
+
return reactQuery.useMutation({
|
|
293
|
+
mutationFn: (data) => updateProfileSelf(config, data),
|
|
294
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
295
|
+
if (result.success) {
|
|
296
|
+
await invalidateProfile(queryClient, ownerHandleOrDid);
|
|
297
|
+
}
|
|
298
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
299
|
+
},
|
|
300
|
+
...options
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
function useUpdateProfileOverride(ownerHandleOrDid, options) {
|
|
304
|
+
const config = useSifaConfig();
|
|
305
|
+
const queryClient = reactQuery.useQueryClient();
|
|
306
|
+
return reactQuery.useMutation({
|
|
307
|
+
mutationFn: (data) => updateProfileOverride(config, data),
|
|
308
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
309
|
+
if (result.success) {
|
|
310
|
+
await invalidateProfile(queryClient, ownerHandleOrDid);
|
|
311
|
+
}
|
|
312
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
313
|
+
},
|
|
314
|
+
...options
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
function useRefreshPds(ownerHandleOrDid, options) {
|
|
318
|
+
const config = useSifaConfig();
|
|
319
|
+
const queryClient = reactQuery.useQueryClient();
|
|
320
|
+
return reactQuery.useMutation({
|
|
321
|
+
mutationFn: () => refreshPds(config),
|
|
322
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
323
|
+
if (result.success) {
|
|
324
|
+
await invalidateProfile(queryClient, ownerHandleOrDid);
|
|
325
|
+
}
|
|
326
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
327
|
+
},
|
|
328
|
+
...options
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
function useUploadAvatar(ownerHandleOrDid, options) {
|
|
332
|
+
const config = useSifaConfig();
|
|
333
|
+
const queryClient = reactQuery.useQueryClient();
|
|
334
|
+
return reactQuery.useMutation({
|
|
335
|
+
mutationFn: (file) => uploadAvatar(config, file),
|
|
336
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
337
|
+
if (result.success) {
|
|
338
|
+
await invalidateProfile(queryClient, ownerHandleOrDid);
|
|
339
|
+
}
|
|
340
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
341
|
+
},
|
|
342
|
+
...options
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
function useDeleteAvatarOverride(ownerHandleOrDid, options) {
|
|
346
|
+
const config = useSifaConfig();
|
|
347
|
+
const queryClient = reactQuery.useQueryClient();
|
|
348
|
+
return reactQuery.useMutation({
|
|
349
|
+
mutationFn: () => deleteAvatarOverride(config),
|
|
350
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
351
|
+
if (result.success) {
|
|
352
|
+
await invalidateProfile(queryClient, ownerHandleOrDid);
|
|
353
|
+
}
|
|
354
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
355
|
+
},
|
|
356
|
+
...options
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// src/query/fetchers/positions.ts
|
|
361
|
+
function createPosition(config, data, options = {}) {
|
|
362
|
+
return apiWriteCreate(config, "/api/profile/position", data, options);
|
|
363
|
+
}
|
|
364
|
+
function updatePosition(config, rkey, data, options = {}) {
|
|
365
|
+
return apiWrite(config, `/api/profile/position/${encodeURIComponent(rkey)}`, "PUT", {
|
|
366
|
+
body: data,
|
|
367
|
+
...options
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
function deletePosition(config, rkey, options = {}) {
|
|
371
|
+
return apiWrite(config, `/api/profile/position/${encodeURIComponent(rkey)}`, "DELETE", options);
|
|
372
|
+
}
|
|
373
|
+
function setPositionPrimary(config, rkey, options = {}) {
|
|
374
|
+
return apiWrite(
|
|
375
|
+
config,
|
|
376
|
+
`/api/profile/position/${encodeURIComponent(rkey)}/primary`,
|
|
377
|
+
"PUT",
|
|
378
|
+
options
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
function unsetPositionPrimary(config, rkey, options = {}) {
|
|
382
|
+
return apiWrite(
|
|
383
|
+
config,
|
|
384
|
+
`/api/profile/position/${encodeURIComponent(rkey)}/primary`,
|
|
385
|
+
"DELETE",
|
|
386
|
+
options
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
function buildPositionPayload(position, skills) {
|
|
390
|
+
return {
|
|
391
|
+
company: position.company,
|
|
392
|
+
title: position.title,
|
|
393
|
+
description: position.description,
|
|
394
|
+
startedAt: position.startedAt,
|
|
395
|
+
endedAt: position.endedAt,
|
|
396
|
+
location: position.location ?? void 0,
|
|
397
|
+
skills
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
function linkSkillToPosition(config, position, skillRef, options = {}) {
|
|
401
|
+
const currentSkills = position.skills ?? [];
|
|
402
|
+
if (currentSkills.some((s) => s.uri === skillRef.uri)) {
|
|
403
|
+
return Promise.resolve({ success: true });
|
|
404
|
+
}
|
|
405
|
+
return updatePosition(
|
|
406
|
+
config,
|
|
407
|
+
position.rkey,
|
|
408
|
+
buildPositionPayload(position, [...currentSkills, skillRef]),
|
|
409
|
+
options
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
function unlinkSkillFromPosition(config, position, skillRef, options = {}) {
|
|
413
|
+
const remaining = (position.skills ?? []).filter((s) => s.uri !== skillRef.uri);
|
|
414
|
+
return updatePosition(config, position.rkey, buildPositionPayload(position, remaining), options);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// src/query/hooks/use-create-position.ts
|
|
418
|
+
function useCreatePosition(ownerDid, options) {
|
|
419
|
+
const config = useSifaConfig();
|
|
420
|
+
const queryClient = reactQuery.useQueryClient();
|
|
421
|
+
return reactQuery.useMutation({
|
|
422
|
+
mutationFn: (data) => createPosition(config, data),
|
|
423
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
424
|
+
if (result.success) {
|
|
425
|
+
await queryClient.invalidateQueries({ queryKey: sifaQueryKeys.profile.byHandle(ownerDid) });
|
|
426
|
+
await queryClient.invalidateQueries({ queryKey: sifaQueryKeys.position.byOwner(ownerDid) });
|
|
427
|
+
}
|
|
428
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
429
|
+
},
|
|
430
|
+
...options
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
async function invalidatePositionCaches(queryClient, ownerHandleOrDid) {
|
|
434
|
+
await queryClient.invalidateQueries({
|
|
435
|
+
queryKey: sifaQueryKeys.profile.byHandle(ownerHandleOrDid)
|
|
436
|
+
});
|
|
437
|
+
await queryClient.invalidateQueries({
|
|
438
|
+
queryKey: sifaQueryKeys.position.byOwner(ownerHandleOrDid)
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
function useUpdatePosition(ownerHandleOrDid, options) {
|
|
442
|
+
const config = useSifaConfig();
|
|
443
|
+
const queryClient = reactQuery.useQueryClient();
|
|
444
|
+
return reactQuery.useMutation({
|
|
445
|
+
mutationFn: ({ rkey, data }) => updatePosition(config, rkey, data),
|
|
446
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
447
|
+
if (result.success) {
|
|
448
|
+
await invalidatePositionCaches(queryClient, ownerHandleOrDid);
|
|
449
|
+
}
|
|
450
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
451
|
+
},
|
|
452
|
+
...options
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
function useDeletePosition(ownerHandleOrDid, options) {
|
|
456
|
+
const config = useSifaConfig();
|
|
457
|
+
const queryClient = reactQuery.useQueryClient();
|
|
458
|
+
return reactQuery.useMutation({
|
|
459
|
+
mutationFn: (rkey) => deletePosition(config, rkey),
|
|
460
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
461
|
+
if (result.success) {
|
|
462
|
+
await invalidatePositionCaches(queryClient, ownerHandleOrDid);
|
|
463
|
+
}
|
|
464
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
465
|
+
},
|
|
466
|
+
...options
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
function useSetPositionPrimary(ownerHandleOrDid, options) {
|
|
470
|
+
const config = useSifaConfig();
|
|
471
|
+
const queryClient = reactQuery.useQueryClient();
|
|
472
|
+
return reactQuery.useMutation({
|
|
473
|
+
mutationFn: (rkey) => setPositionPrimary(config, rkey),
|
|
474
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
475
|
+
if (result.success) {
|
|
476
|
+
await invalidatePositionCaches(queryClient, ownerHandleOrDid);
|
|
477
|
+
}
|
|
478
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
479
|
+
},
|
|
480
|
+
...options
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
function useUnsetPositionPrimary(ownerHandleOrDid, options) {
|
|
484
|
+
const config = useSifaConfig();
|
|
485
|
+
const queryClient = reactQuery.useQueryClient();
|
|
486
|
+
return reactQuery.useMutation({
|
|
487
|
+
mutationFn: (rkey) => unsetPositionPrimary(config, rkey),
|
|
488
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
489
|
+
if (result.success) {
|
|
490
|
+
await invalidatePositionCaches(queryClient, ownerHandleOrDid);
|
|
491
|
+
}
|
|
492
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
493
|
+
},
|
|
494
|
+
...options
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
function useLinkSkillToPosition(ownerHandleOrDid, options) {
|
|
498
|
+
const config = useSifaConfig();
|
|
499
|
+
const queryClient = reactQuery.useQueryClient();
|
|
500
|
+
return reactQuery.useMutation({
|
|
501
|
+
mutationFn: ({ position, skillRef }) => linkSkillToPosition(config, position, skillRef),
|
|
502
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
503
|
+
if (result.success) {
|
|
504
|
+
await invalidatePositionCaches(queryClient, ownerHandleOrDid);
|
|
505
|
+
}
|
|
506
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
507
|
+
},
|
|
508
|
+
...options
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
function useUnlinkSkillFromPosition(ownerHandleOrDid, options) {
|
|
512
|
+
const config = useSifaConfig();
|
|
513
|
+
const queryClient = reactQuery.useQueryClient();
|
|
514
|
+
return reactQuery.useMutation({
|
|
515
|
+
mutationFn: ({ position, skillRef }) => unlinkSkillFromPosition(config, position, skillRef),
|
|
516
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
517
|
+
if (result.success) {
|
|
518
|
+
await invalidatePositionCaches(queryClient, ownerHandleOrDid);
|
|
519
|
+
}
|
|
520
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
521
|
+
},
|
|
522
|
+
...options
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// src/query/fetchers/education.ts
|
|
527
|
+
function createEducation(config, data, options = {}) {
|
|
528
|
+
return apiWriteCreate(config, "/api/profile/education", data, options);
|
|
529
|
+
}
|
|
530
|
+
function updateEducation(config, rkey, data, options = {}) {
|
|
531
|
+
return apiWrite(config, `/api/profile/education/${encodeURIComponent(rkey)}`, "PUT", {
|
|
532
|
+
body: data,
|
|
533
|
+
...options
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
function deleteEducation(config, rkey, options = {}) {
|
|
537
|
+
return apiWrite(config, `/api/profile/education/${encodeURIComponent(rkey)}`, "DELETE", options);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// src/query/hooks/use-education-mutations.ts
|
|
541
|
+
async function invalidateProfile2(queryClient, ownerHandleOrDid) {
|
|
542
|
+
await queryClient.invalidateQueries({
|
|
543
|
+
queryKey: sifaQueryKeys.profile.byHandle(ownerHandleOrDid)
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
function useCreateEducation(ownerHandleOrDid, options) {
|
|
547
|
+
const config = useSifaConfig();
|
|
548
|
+
const queryClient = reactQuery.useQueryClient();
|
|
549
|
+
return reactQuery.useMutation({
|
|
550
|
+
mutationFn: (data) => createEducation(config, data),
|
|
551
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
552
|
+
if (result.success) {
|
|
553
|
+
await invalidateProfile2(queryClient, ownerHandleOrDid);
|
|
554
|
+
}
|
|
555
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
556
|
+
},
|
|
557
|
+
...options
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
function useUpdateEducation(ownerHandleOrDid, options) {
|
|
561
|
+
const config = useSifaConfig();
|
|
562
|
+
const queryClient = reactQuery.useQueryClient();
|
|
563
|
+
return reactQuery.useMutation({
|
|
564
|
+
mutationFn: ({ rkey, data }) => updateEducation(config, rkey, data),
|
|
565
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
566
|
+
if (result.success) {
|
|
567
|
+
await invalidateProfile2(queryClient, ownerHandleOrDid);
|
|
568
|
+
}
|
|
569
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
570
|
+
},
|
|
571
|
+
...options
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
function useDeleteEducation(ownerHandleOrDid, options) {
|
|
575
|
+
const config = useSifaConfig();
|
|
576
|
+
const queryClient = reactQuery.useQueryClient();
|
|
577
|
+
return reactQuery.useMutation({
|
|
578
|
+
mutationFn: (rkey) => deleteEducation(config, rkey),
|
|
579
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
580
|
+
if (result.success) {
|
|
581
|
+
await invalidateProfile2(queryClient, ownerHandleOrDid);
|
|
582
|
+
}
|
|
583
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
584
|
+
},
|
|
585
|
+
...options
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
// src/query/fetchers/skills.ts
|
|
590
|
+
function createSkill(config, data, options = {}) {
|
|
591
|
+
return apiWriteCreate(config, "/api/profile/skill", data, options);
|
|
592
|
+
}
|
|
593
|
+
function updateSkill(config, rkey, data, options = {}) {
|
|
594
|
+
return apiWrite(config, `/api/profile/skill/${encodeURIComponent(rkey)}`, "PUT", {
|
|
595
|
+
body: data,
|
|
596
|
+
...options
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
function deleteSkill(config, rkey, options = {}) {
|
|
600
|
+
return apiWrite(config, `/api/profile/skill/${encodeURIComponent(rkey)}`, "DELETE", options);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// src/query/hooks/use-skill-mutations.ts
|
|
604
|
+
async function invalidateProfile3(queryClient, ownerHandleOrDid) {
|
|
605
|
+
await queryClient.invalidateQueries({
|
|
606
|
+
queryKey: sifaQueryKeys.profile.byHandle(ownerHandleOrDid)
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
function useCreateSkill(ownerHandleOrDid, options) {
|
|
610
|
+
const config = useSifaConfig();
|
|
611
|
+
const queryClient = reactQuery.useQueryClient();
|
|
612
|
+
return reactQuery.useMutation({
|
|
613
|
+
mutationFn: (data) => createSkill(config, data),
|
|
614
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
615
|
+
if (result.success) {
|
|
616
|
+
await invalidateProfile3(queryClient, ownerHandleOrDid);
|
|
617
|
+
}
|
|
618
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
619
|
+
},
|
|
620
|
+
...options
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
function useUpdateSkill(ownerHandleOrDid, options) {
|
|
624
|
+
const config = useSifaConfig();
|
|
625
|
+
const queryClient = reactQuery.useQueryClient();
|
|
626
|
+
return reactQuery.useMutation({
|
|
627
|
+
mutationFn: ({ rkey, data }) => updateSkill(config, rkey, data),
|
|
628
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
629
|
+
if (result.success) {
|
|
630
|
+
await invalidateProfile3(queryClient, ownerHandleOrDid);
|
|
631
|
+
}
|
|
632
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
633
|
+
},
|
|
634
|
+
...options
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
function useDeleteSkill(ownerHandleOrDid, options) {
|
|
638
|
+
const config = useSifaConfig();
|
|
639
|
+
const queryClient = reactQuery.useQueryClient();
|
|
640
|
+
return reactQuery.useMutation({
|
|
641
|
+
mutationFn: (rkey) => deleteSkill(config, rkey),
|
|
642
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
643
|
+
if (result.success) {
|
|
644
|
+
await invalidateProfile3(queryClient, ownerHandleOrDid);
|
|
645
|
+
}
|
|
646
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
647
|
+
},
|
|
648
|
+
...options
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
// src/query/fetchers/records.ts
|
|
653
|
+
function createRecord(config, collection, data, options = {}) {
|
|
654
|
+
return apiWriteCreate(
|
|
655
|
+
config,
|
|
656
|
+
`/api/profile/records/${encodeURIComponent(collection)}`,
|
|
657
|
+
data,
|
|
658
|
+
options
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
function updateRecord(config, collection, rkey, data, options = {}) {
|
|
662
|
+
const path = `/api/profile/records/${encodeURIComponent(collection)}/${encodeURIComponent(rkey)}`;
|
|
663
|
+
return apiWrite(config, path, "PUT", { body: data, ...options });
|
|
664
|
+
}
|
|
665
|
+
function deleteRecord(config, collection, rkey, options = {}) {
|
|
666
|
+
const path = `/api/profile/records/${encodeURIComponent(collection)}/${encodeURIComponent(rkey)}`;
|
|
667
|
+
return apiWrite(config, path, "DELETE", options);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
// src/query/hooks/use-record-mutations.ts
|
|
671
|
+
async function invalidateProfile4(queryClient, ownerHandleOrDid) {
|
|
672
|
+
await queryClient.invalidateQueries({
|
|
673
|
+
queryKey: sifaQueryKeys.profile.byHandle(ownerHandleOrDid)
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
function useCreateRecord(ownerHandleOrDid, options) {
|
|
677
|
+
const config = useSifaConfig();
|
|
678
|
+
const queryClient = reactQuery.useQueryClient();
|
|
679
|
+
return reactQuery.useMutation({
|
|
680
|
+
mutationFn: ({ collection, data }) => createRecord(config, collection, data),
|
|
681
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
682
|
+
if (result.success) {
|
|
683
|
+
await invalidateProfile4(queryClient, ownerHandleOrDid);
|
|
684
|
+
}
|
|
685
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
686
|
+
},
|
|
687
|
+
...options
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
function useUpdateRecord(ownerHandleOrDid, options) {
|
|
691
|
+
const config = useSifaConfig();
|
|
692
|
+
const queryClient = reactQuery.useQueryClient();
|
|
693
|
+
return reactQuery.useMutation({
|
|
694
|
+
mutationFn: ({ collection, rkey, data }) => updateRecord(config, collection, rkey, data),
|
|
695
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
696
|
+
if (result.success) {
|
|
697
|
+
await invalidateProfile4(queryClient, ownerHandleOrDid);
|
|
698
|
+
}
|
|
699
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
700
|
+
},
|
|
701
|
+
...options
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
function useDeleteRecord(ownerHandleOrDid, options) {
|
|
705
|
+
const config = useSifaConfig();
|
|
706
|
+
const queryClient = reactQuery.useQueryClient();
|
|
707
|
+
return reactQuery.useMutation({
|
|
708
|
+
mutationFn: ({ collection, rkey }) => deleteRecord(config, collection, rkey),
|
|
709
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
710
|
+
if (result.success) {
|
|
711
|
+
await invalidateProfile4(queryClient, ownerHandleOrDid);
|
|
712
|
+
}
|
|
713
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
714
|
+
},
|
|
715
|
+
...options
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
// src/query/fetchers/profile-locations.ts
|
|
720
|
+
function createProfileLocation(config, data, options = {}) {
|
|
721
|
+
return apiWriteCreate(config, "/api/profile/location", data, options);
|
|
722
|
+
}
|
|
723
|
+
function updateProfileLocation(config, rkey, data, options = {}) {
|
|
724
|
+
return apiWrite(config, `/api/profile/location/${encodeURIComponent(rkey)}`, "PUT", {
|
|
725
|
+
body: data,
|
|
726
|
+
...options
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
function deleteProfileLocation(config, rkey, options = {}) {
|
|
730
|
+
return apiWrite(config, `/api/profile/location/${encodeURIComponent(rkey)}`, "DELETE", options);
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
// src/query/hooks/use-location-mutations.ts
|
|
734
|
+
async function invalidateProfile5(queryClient, ownerHandleOrDid) {
|
|
735
|
+
await queryClient.invalidateQueries({
|
|
736
|
+
queryKey: sifaQueryKeys.profile.byHandle(ownerHandleOrDid)
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
function useCreateProfileLocation(ownerHandleOrDid, options) {
|
|
740
|
+
const config = useSifaConfig();
|
|
741
|
+
const queryClient = reactQuery.useQueryClient();
|
|
742
|
+
return reactQuery.useMutation({
|
|
743
|
+
mutationFn: (data) => createProfileLocation(config, data),
|
|
744
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
745
|
+
if (result.success) {
|
|
746
|
+
await invalidateProfile5(queryClient, ownerHandleOrDid);
|
|
747
|
+
}
|
|
748
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
749
|
+
},
|
|
750
|
+
...options
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
function useUpdateProfileLocation(ownerHandleOrDid, options) {
|
|
754
|
+
const config = useSifaConfig();
|
|
755
|
+
const queryClient = reactQuery.useQueryClient();
|
|
756
|
+
return reactQuery.useMutation({
|
|
757
|
+
mutationFn: ({ rkey, data }) => updateProfileLocation(config, rkey, data),
|
|
758
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
759
|
+
if (result.success) {
|
|
760
|
+
await invalidateProfile5(queryClient, ownerHandleOrDid);
|
|
761
|
+
}
|
|
762
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
763
|
+
},
|
|
764
|
+
...options
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
function useDeleteProfileLocation(ownerHandleOrDid, options) {
|
|
768
|
+
const config = useSifaConfig();
|
|
769
|
+
const queryClient = reactQuery.useQueryClient();
|
|
770
|
+
return reactQuery.useMutation({
|
|
771
|
+
mutationFn: (rkey) => deleteProfileLocation(config, rkey),
|
|
772
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
773
|
+
if (result.success) {
|
|
774
|
+
await invalidateProfile5(queryClient, ownerHandleOrDid);
|
|
775
|
+
}
|
|
776
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
777
|
+
},
|
|
778
|
+
...options
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// src/query/fetchers/external-accounts.ts
|
|
783
|
+
async function fetchExternalAccounts(config, handleOrDid, options = {}) {
|
|
784
|
+
const path = `/api/profile/${encodeURIComponent(handleOrDid)}/external-accounts`;
|
|
785
|
+
try {
|
|
786
|
+
const data = await apiFetch(config, path, {
|
|
787
|
+
credentials: "include",
|
|
788
|
+
...options
|
|
789
|
+
});
|
|
790
|
+
return data.accounts ?? [];
|
|
791
|
+
} catch {
|
|
792
|
+
return [];
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
function createExternalAccount(config, data, options = {}) {
|
|
796
|
+
return apiWrite(
|
|
797
|
+
config,
|
|
798
|
+
"/api/profile/external-accounts",
|
|
799
|
+
"POST",
|
|
800
|
+
{ body: data, ...options }
|
|
801
|
+
);
|
|
802
|
+
}
|
|
803
|
+
function updateExternalAccount(config, rkey, data, options = {}) {
|
|
804
|
+
return apiWrite(config, `/api/profile/external-accounts/${encodeURIComponent(rkey)}`, "PUT", {
|
|
805
|
+
body: data,
|
|
806
|
+
...options
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
function deleteExternalAccount(config, rkey, options = {}) {
|
|
810
|
+
return apiWrite(
|
|
811
|
+
config,
|
|
812
|
+
`/api/profile/external-accounts/${encodeURIComponent(rkey)}`,
|
|
813
|
+
"DELETE",
|
|
814
|
+
options
|
|
815
|
+
);
|
|
816
|
+
}
|
|
817
|
+
function setExternalAccountPrimary(config, rkey, options = {}) {
|
|
818
|
+
return apiWrite(
|
|
819
|
+
config,
|
|
820
|
+
`/api/profile/external-accounts/${encodeURIComponent(rkey)}/primary`,
|
|
821
|
+
"PUT",
|
|
822
|
+
options
|
|
823
|
+
);
|
|
824
|
+
}
|
|
825
|
+
function unsetExternalAccountPrimary(config, rkey, options = {}) {
|
|
826
|
+
return apiWrite(
|
|
827
|
+
config,
|
|
828
|
+
`/api/profile/external-accounts/${encodeURIComponent(rkey)}/primary`,
|
|
829
|
+
"DELETE",
|
|
830
|
+
options
|
|
831
|
+
);
|
|
832
|
+
}
|
|
833
|
+
function verifyExternalAccount(config, rkey, options = {}) {
|
|
834
|
+
return apiWrite(
|
|
835
|
+
config,
|
|
836
|
+
`/api/profile/external-accounts/${encodeURIComponent(rkey)}/verify`,
|
|
837
|
+
"POST",
|
|
838
|
+
{ body: {}, ...options }
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
// src/query/hooks/use-external-accounts.ts
|
|
843
|
+
async function invalidateProfileAndExternalAccounts(queryClient, ownerHandleOrDid) {
|
|
844
|
+
await queryClient.invalidateQueries({
|
|
845
|
+
queryKey: sifaQueryKeys.profile.byHandle(ownerHandleOrDid)
|
|
846
|
+
});
|
|
847
|
+
await queryClient.invalidateQueries({
|
|
848
|
+
queryKey: sifaQueryKeys.profile.externalAccounts(ownerHandleOrDid)
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
function useExternalAccounts(handleOrDid, options) {
|
|
852
|
+
const config = useSifaConfig();
|
|
853
|
+
return reactQuery.useQuery({
|
|
854
|
+
queryKey: sifaQueryKeys.profile.externalAccounts(handleOrDid ?? ""),
|
|
855
|
+
queryFn: () => fetchExternalAccounts(config, handleOrDid ?? ""),
|
|
856
|
+
enabled: Boolean(handleOrDid) && (options?.enabled ?? true),
|
|
857
|
+
...options
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
function useCreateExternalAccount(ownerHandleOrDid, options) {
|
|
861
|
+
const config = useSifaConfig();
|
|
862
|
+
const queryClient = reactQuery.useQueryClient();
|
|
863
|
+
return reactQuery.useMutation({
|
|
864
|
+
mutationFn: (data) => createExternalAccount(config, data),
|
|
865
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
866
|
+
if (result.success) {
|
|
867
|
+
await invalidateProfileAndExternalAccounts(queryClient, ownerHandleOrDid);
|
|
868
|
+
}
|
|
869
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
870
|
+
},
|
|
871
|
+
...options
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
function useUpdateExternalAccount(ownerHandleOrDid, options) {
|
|
875
|
+
const config = useSifaConfig();
|
|
876
|
+
const queryClient = reactQuery.useQueryClient();
|
|
877
|
+
return reactQuery.useMutation({
|
|
878
|
+
mutationFn: ({ rkey, data }) => updateExternalAccount(config, rkey, data),
|
|
879
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
880
|
+
if (result.success) {
|
|
881
|
+
await invalidateProfileAndExternalAccounts(queryClient, ownerHandleOrDid);
|
|
882
|
+
}
|
|
883
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
884
|
+
},
|
|
885
|
+
...options
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
function useDeleteExternalAccount(ownerHandleOrDid, options) {
|
|
889
|
+
const config = useSifaConfig();
|
|
890
|
+
const queryClient = reactQuery.useQueryClient();
|
|
891
|
+
return reactQuery.useMutation({
|
|
892
|
+
mutationFn: (rkey) => deleteExternalAccount(config, rkey),
|
|
893
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
894
|
+
if (result.success) {
|
|
895
|
+
await invalidateProfileAndExternalAccounts(queryClient, ownerHandleOrDid);
|
|
896
|
+
}
|
|
897
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
898
|
+
},
|
|
899
|
+
...options
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
function useSetExternalAccountPrimary(ownerHandleOrDid, options) {
|
|
903
|
+
const config = useSifaConfig();
|
|
904
|
+
const queryClient = reactQuery.useQueryClient();
|
|
905
|
+
return reactQuery.useMutation({
|
|
906
|
+
mutationFn: (rkey) => setExternalAccountPrimary(config, rkey),
|
|
907
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
908
|
+
if (result.success) {
|
|
909
|
+
await invalidateProfileAndExternalAccounts(queryClient, ownerHandleOrDid);
|
|
910
|
+
}
|
|
911
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
912
|
+
},
|
|
913
|
+
...options
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
function useUnsetExternalAccountPrimary(ownerHandleOrDid, options) {
|
|
917
|
+
const config = useSifaConfig();
|
|
918
|
+
const queryClient = reactQuery.useQueryClient();
|
|
919
|
+
return reactQuery.useMutation({
|
|
920
|
+
mutationFn: (rkey) => unsetExternalAccountPrimary(config, rkey),
|
|
921
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
922
|
+
if (result.success) {
|
|
923
|
+
await invalidateProfileAndExternalAccounts(queryClient, ownerHandleOrDid);
|
|
924
|
+
}
|
|
925
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
926
|
+
},
|
|
927
|
+
...options
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
function useVerifyExternalAccount(ownerHandleOrDid, options) {
|
|
931
|
+
const config = useSifaConfig();
|
|
932
|
+
const queryClient = reactQuery.useQueryClient();
|
|
933
|
+
return reactQuery.useMutation({
|
|
934
|
+
mutationFn: (rkey) => verifyExternalAccount(config, rkey),
|
|
935
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
936
|
+
if (result.success) {
|
|
937
|
+
await invalidateProfileAndExternalAccounts(queryClient, ownerHandleOrDid);
|
|
938
|
+
}
|
|
939
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
940
|
+
},
|
|
941
|
+
...options
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
// src/query/fetchers/endorsements.ts
|
|
946
|
+
function createEndorsement(config, data, options = {}) {
|
|
947
|
+
return apiWriteCreate(config, "/api/endorsements", data, options);
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
// src/query/hooks/use-endorsement-mutations.ts
|
|
951
|
+
function useCreateEndorsement(endorsedHandleOrDid, options) {
|
|
952
|
+
const config = useSifaConfig();
|
|
953
|
+
const queryClient = reactQuery.useQueryClient();
|
|
954
|
+
return reactQuery.useMutation({
|
|
955
|
+
mutationFn: (data) => createEndorsement(config, data),
|
|
956
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
957
|
+
if (result.success && endorsedHandleOrDid) {
|
|
958
|
+
await queryClient.invalidateQueries({
|
|
959
|
+
queryKey: sifaQueryKeys.profile.byHandle(endorsedHandleOrDid)
|
|
960
|
+
});
|
|
961
|
+
await queryClient.invalidateQueries({
|
|
962
|
+
queryKey: sifaQueryKeys.endorsement.count(endorsedHandleOrDid)
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
966
|
+
},
|
|
967
|
+
...options
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
// src/query/fetchers/keytrace-claims.ts
|
|
972
|
+
function hideKeytraceClaim(config, rkey, options = {}) {
|
|
973
|
+
return apiWrite(
|
|
974
|
+
config,
|
|
975
|
+
`/api/profile/keytrace-claims/${encodeURIComponent(rkey)}/hide`,
|
|
976
|
+
"POST",
|
|
977
|
+
options
|
|
978
|
+
);
|
|
979
|
+
}
|
|
980
|
+
function unhideKeytraceClaim(config, rkey, options = {}) {
|
|
981
|
+
return apiWrite(
|
|
982
|
+
config,
|
|
983
|
+
`/api/profile/keytrace-claims/${encodeURIComponent(rkey)}/hide`,
|
|
984
|
+
"DELETE",
|
|
985
|
+
options
|
|
986
|
+
);
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
// src/query/hooks/use-keytrace-claims.ts
|
|
990
|
+
async function invalidateProfile6(queryClient, ownerHandleOrDid) {
|
|
991
|
+
await queryClient.invalidateQueries({
|
|
992
|
+
queryKey: sifaQueryKeys.profile.byHandle(ownerHandleOrDid)
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
function useHideKeytraceClaim(ownerHandleOrDid, options) {
|
|
996
|
+
const config = useSifaConfig();
|
|
997
|
+
const queryClient = reactQuery.useQueryClient();
|
|
998
|
+
return reactQuery.useMutation({
|
|
999
|
+
mutationFn: (rkey) => hideKeytraceClaim(config, rkey),
|
|
1000
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
1001
|
+
if (result.success) {
|
|
1002
|
+
await invalidateProfile6(queryClient, ownerHandleOrDid);
|
|
1003
|
+
}
|
|
1004
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
1005
|
+
},
|
|
1006
|
+
...options
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
function useUnhideKeytraceClaim(ownerHandleOrDid, options) {
|
|
1010
|
+
const config = useSifaConfig();
|
|
1011
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1012
|
+
return reactQuery.useMutation({
|
|
1013
|
+
mutationFn: (rkey) => unhideKeytraceClaim(config, rkey),
|
|
1014
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
1015
|
+
if (result.success) {
|
|
1016
|
+
await invalidateProfile6(queryClient, ownerHandleOrDid);
|
|
1017
|
+
}
|
|
1018
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
1019
|
+
},
|
|
1020
|
+
...options
|
|
1021
|
+
});
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
// src/query/fetchers/publications.ts
|
|
1025
|
+
function hideOrcidPublication(config, putCode, options = {}) {
|
|
1026
|
+
return apiWrite(config, `/api/profile/orcid-publications/${putCode}/hide`, "POST", options);
|
|
1027
|
+
}
|
|
1028
|
+
function unhideOrcidPublication(config, putCode, options = {}) {
|
|
1029
|
+
return apiWrite(config, `/api/profile/orcid-publications/${putCode}/hide`, "DELETE", options);
|
|
1030
|
+
}
|
|
1031
|
+
function hideStandardPublication(config, uri, options = {}) {
|
|
1032
|
+
return apiWrite(
|
|
1033
|
+
config,
|
|
1034
|
+
`/api/profile/standard-publications/${encodeURIComponent(uri)}/hide`,
|
|
1035
|
+
"POST",
|
|
1036
|
+
options
|
|
1037
|
+
);
|
|
1038
|
+
}
|
|
1039
|
+
function unhideStandardPublication(config, uri, options = {}) {
|
|
1040
|
+
return apiWrite(
|
|
1041
|
+
config,
|
|
1042
|
+
`/api/profile/standard-publications/${encodeURIComponent(uri)}/hide`,
|
|
1043
|
+
"DELETE",
|
|
1044
|
+
options
|
|
1045
|
+
);
|
|
1046
|
+
}
|
|
1047
|
+
function bulkHideStandardPublications(config, uris, options = {}) {
|
|
1048
|
+
return apiWrite(config, "/api/profile/standard-publications/bulk-hide", "POST", {
|
|
1049
|
+
body: { uris },
|
|
1050
|
+
...options
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
1053
|
+
function bulkUnhideStandardPublications(config, uris, options = {}) {
|
|
1054
|
+
return apiWrite(config, "/api/profile/standard-publications/bulk-hide", "DELETE", {
|
|
1055
|
+
body: { uris },
|
|
1056
|
+
...options
|
|
1057
|
+
});
|
|
1058
|
+
}
|
|
1059
|
+
function hideSifaPublication(config, rkey, options = {}) {
|
|
1060
|
+
return apiWrite(config, `/api/profile/publications/${rkey}/hide`, "POST", options);
|
|
1061
|
+
}
|
|
1062
|
+
function unhideSifaPublication(config, rkey, options = {}) {
|
|
1063
|
+
return apiWrite(config, `/api/profile/publications/${rkey}/hide`, "DELETE", options);
|
|
1064
|
+
}
|
|
1065
|
+
async function refreshOrcidPublications(config, options = {}) {
|
|
1066
|
+
const result = await apiWrite(
|
|
1067
|
+
config,
|
|
1068
|
+
"/api/profile/orcid-publications/refresh",
|
|
1069
|
+
"POST",
|
|
1070
|
+
{ body: {}, ...options }
|
|
1071
|
+
);
|
|
1072
|
+
if (result.success && result.error) {
|
|
1073
|
+
return { success: false, error: result.error };
|
|
1074
|
+
}
|
|
1075
|
+
return result;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
// src/query/hooks/use-publication-mutations.ts
|
|
1079
|
+
async function invalidateProfile7(queryClient, ownerHandleOrDid) {
|
|
1080
|
+
await queryClient.invalidateQueries({
|
|
1081
|
+
queryKey: sifaQueryKeys.profile.byHandle(ownerHandleOrDid)
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
function makeWriteHook(fetcher) {
|
|
1085
|
+
return function useHook(ownerHandleOrDid, options) {
|
|
1086
|
+
const config = useSifaConfig();
|
|
1087
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1088
|
+
return reactQuery.useMutation({
|
|
1089
|
+
mutationFn: (v) => fetcher(config, v),
|
|
1090
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
1091
|
+
if (result.success) {
|
|
1092
|
+
await invalidateProfile7(queryClient, ownerHandleOrDid);
|
|
1093
|
+
}
|
|
1094
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
1095
|
+
},
|
|
1096
|
+
...options
|
|
1097
|
+
});
|
|
1098
|
+
};
|
|
1099
|
+
}
|
|
1100
|
+
var useHideOrcidPublication = makeWriteHook(
|
|
1101
|
+
(config, putCode) => hideOrcidPublication(config, putCode)
|
|
1102
|
+
);
|
|
1103
|
+
var useUnhideOrcidPublication = makeWriteHook(
|
|
1104
|
+
(config, putCode) => unhideOrcidPublication(config, putCode)
|
|
1105
|
+
);
|
|
1106
|
+
var useHideStandardPublication = makeWriteHook(
|
|
1107
|
+
(config, uri) => hideStandardPublication(config, uri)
|
|
1108
|
+
);
|
|
1109
|
+
var useUnhideStandardPublication = makeWriteHook(
|
|
1110
|
+
(config, uri) => unhideStandardPublication(config, uri)
|
|
1111
|
+
);
|
|
1112
|
+
var useBulkHideStandardPublications = makeWriteHook(
|
|
1113
|
+
(config, uris) => bulkHideStandardPublications(config, uris)
|
|
1114
|
+
);
|
|
1115
|
+
var useBulkUnhideStandardPublications = makeWriteHook(
|
|
1116
|
+
(config, uris) => bulkUnhideStandardPublications(config, uris)
|
|
1117
|
+
);
|
|
1118
|
+
var useHideSifaPublication = makeWriteHook(
|
|
1119
|
+
(config, rkey) => hideSifaPublication(config, rkey)
|
|
1120
|
+
);
|
|
1121
|
+
var useUnhideSifaPublication = makeWriteHook(
|
|
1122
|
+
(config, rkey) => unhideSifaPublication(config, rkey)
|
|
1123
|
+
);
|
|
1124
|
+
function useRefreshOrcidPublications(ownerHandleOrDid, options) {
|
|
1125
|
+
const config = useSifaConfig();
|
|
1126
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1127
|
+
return reactQuery.useMutation({
|
|
1128
|
+
mutationFn: () => refreshOrcidPublications(config),
|
|
1129
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
1130
|
+
if (result.success) {
|
|
1131
|
+
await invalidateProfile7(queryClient, ownerHandleOrDid);
|
|
1132
|
+
}
|
|
1133
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
1134
|
+
},
|
|
1135
|
+
...options
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
// src/query/fetchers/profile-items-hide.ts
|
|
1140
|
+
function hideProfileItem(config, input, options = {}) {
|
|
1141
|
+
return apiWrite(config, "/api/profile/items/hide", "POST", { ...options, body: input });
|
|
1142
|
+
}
|
|
1143
|
+
function unhideProfileItem(config, input, options = {}) {
|
|
1144
|
+
return apiWrite(config, "/api/profile/items/hide", "DELETE", { ...options, body: input });
|
|
1145
|
+
}
|
|
1146
|
+
function bulkHideProfileItems(config, input, options = {}) {
|
|
1147
|
+
return apiWrite(config, "/api/profile/items/bulk-hide", "POST", { ...options, body: input });
|
|
1148
|
+
}
|
|
1149
|
+
function bulkUnhideProfileItems(config, input, options = {}) {
|
|
1150
|
+
return apiWrite(config, "/api/profile/items/bulk-hide", "DELETE", { ...options, body: input });
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
// src/query/hooks/use-profile-items-hide.ts
|
|
1154
|
+
async function invalidateProfile8(queryClient, ownerHandleOrDid) {
|
|
1155
|
+
await queryClient.invalidateQueries({
|
|
1156
|
+
queryKey: sifaQueryKeys.profile.byHandle(ownerHandleOrDid)
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
function makeWriteHook2(fetcher) {
|
|
1160
|
+
return function useHook(ownerHandleOrDid, options) {
|
|
1161
|
+
const config = useSifaConfig();
|
|
1162
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1163
|
+
return reactQuery.useMutation({
|
|
1164
|
+
mutationFn: (v) => fetcher(config, v),
|
|
1165
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
1166
|
+
if (result.success) {
|
|
1167
|
+
await invalidateProfile8(queryClient, ownerHandleOrDid);
|
|
1168
|
+
}
|
|
1169
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
1170
|
+
},
|
|
1171
|
+
...options
|
|
1172
|
+
});
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1175
|
+
var useHideProfileItem = makeWriteHook2(
|
|
1176
|
+
(config, input) => hideProfileItem(config, input)
|
|
1177
|
+
);
|
|
1178
|
+
var useUnhideProfileItem = makeWriteHook2(
|
|
1179
|
+
(config, input) => unhideProfileItem(config, input)
|
|
1180
|
+
);
|
|
1181
|
+
var useBulkHideProfileItems = makeWriteHook2(
|
|
1182
|
+
(config, input) => bulkHideProfileItems(config, input)
|
|
1183
|
+
);
|
|
1184
|
+
var useBulkUnhideProfileItems = makeWriteHook2(
|
|
1185
|
+
(config, input) => bulkUnhideProfileItems(config, input)
|
|
1186
|
+
);
|
|
1187
|
+
|
|
1188
|
+
// src/query/fetchers/stats.ts
|
|
1189
|
+
async function fetchStats(config, options = {}) {
|
|
1190
|
+
try {
|
|
1191
|
+
return await apiFetch(config, "/api/stats", {
|
|
1192
|
+
next: { revalidate: 900 },
|
|
1193
|
+
...options
|
|
1194
|
+
});
|
|
1195
|
+
} catch {
|
|
1196
|
+
return null;
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
// src/query/hooks/use-stats.ts
|
|
1201
|
+
function useStats(options) {
|
|
1202
|
+
const config = useSifaConfig();
|
|
1203
|
+
return reactQuery.useQuery({
|
|
1204
|
+
queryKey: sifaQueryKeys.stats.homepage(),
|
|
1205
|
+
queryFn: () => fetchStats(config),
|
|
1206
|
+
...options
|
|
1207
|
+
});
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
// src/query/fetchers/apps.ts
|
|
1211
|
+
async function fetchAppsRegistry(config, options = {}) {
|
|
1212
|
+
try {
|
|
1213
|
+
return await apiFetch(config, "/api/apps/registry", {
|
|
1214
|
+
next: { revalidate: 86400 },
|
|
1215
|
+
...options
|
|
1216
|
+
});
|
|
1217
|
+
} catch {
|
|
1218
|
+
return [];
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
async function fetchHiddenApps(config, options = {}) {
|
|
1222
|
+
const headers = { ...options.headers ?? {} };
|
|
1223
|
+
if (options.cookieHeader) headers.cookie = options.cookieHeader;
|
|
1224
|
+
try {
|
|
1225
|
+
const data = await apiFetch(config, "/api/profile/hidden-apps", {
|
|
1226
|
+
credentials: "include",
|
|
1227
|
+
...options,
|
|
1228
|
+
headers
|
|
1229
|
+
});
|
|
1230
|
+
return data.apps;
|
|
1231
|
+
} catch {
|
|
1232
|
+
return [];
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
// src/query/hooks/use-apps.ts
|
|
1237
|
+
function useAppsRegistry(options) {
|
|
1238
|
+
const config = useSifaConfig();
|
|
1239
|
+
return reactQuery.useQuery({
|
|
1240
|
+
queryKey: sifaQueryKeys.apps.registry(),
|
|
1241
|
+
queryFn: () => fetchAppsRegistry(config),
|
|
1242
|
+
...options
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
function useHiddenApps(options) {
|
|
1246
|
+
const config = useSifaConfig();
|
|
1247
|
+
return reactQuery.useQuery({
|
|
1248
|
+
queryKey: sifaQueryKeys.apps.hidden(),
|
|
1249
|
+
queryFn: () => fetchHiddenApps(config),
|
|
1250
|
+
...options
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
// src/query/fetchers/search.ts
|
|
1255
|
+
var EMPTY_SEARCH = { profiles: [], total: 0, limit: 20, offset: 0 };
|
|
1256
|
+
var EMPTY_FILTERS = { countries: [], industries: [], apps: [] };
|
|
1257
|
+
async function fetchSearchProfiles(config, filters, options = {}) {
|
|
1258
|
+
const params = new URLSearchParams();
|
|
1259
|
+
if (filters.q) params.set("q", filters.q);
|
|
1260
|
+
if (filters.skill) params.set("skill", filters.skill);
|
|
1261
|
+
if (filters.country) params.set("country", filters.country);
|
|
1262
|
+
if (filters.industry) params.set("industry", filters.industry);
|
|
1263
|
+
if (filters.domain) params.set("domain", filters.domain);
|
|
1264
|
+
if (filters.workplace) params.set("workplace", filters.workplace);
|
|
1265
|
+
if (filters.app) params.set("app", filters.app);
|
|
1266
|
+
if (filters.limit !== void 0) params.set("limit", String(filters.limit));
|
|
1267
|
+
if (params.size === 0) return EMPTY_SEARCH;
|
|
1268
|
+
return apiFetch(config, `/api/search/profiles?${params.toString()}`, {
|
|
1269
|
+
cache: "no-store",
|
|
1270
|
+
...options
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
async function fetchSkillSuggestions(config, query, options = {}) {
|
|
1274
|
+
if (!query.trim()) return [];
|
|
1275
|
+
const path = `/api/search/skills?q=${encodeURIComponent(query)}&limit=8`;
|
|
1276
|
+
const data = await apiFetch(config, path, {
|
|
1277
|
+
cache: "no-store",
|
|
1278
|
+
...options
|
|
1279
|
+
});
|
|
1280
|
+
return data.skills ?? [];
|
|
1281
|
+
}
|
|
1282
|
+
async function fetchSearchFilters(config, options = {}) {
|
|
1283
|
+
try {
|
|
1284
|
+
return await apiFetch(config, "/api/search/filters", {
|
|
1285
|
+
next: { revalidate: 300 },
|
|
1286
|
+
...options
|
|
1287
|
+
});
|
|
1288
|
+
} catch {
|
|
1289
|
+
return EMPTY_FILTERS;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
async function searchSkills(config, query, limit = 10, options = {}) {
|
|
1293
|
+
if (!query.trim()) return [];
|
|
1294
|
+
const path = `/api/skills/search?q=${encodeURIComponent(query)}&limit=${limit}`;
|
|
1295
|
+
try {
|
|
1296
|
+
const data = await apiFetch(config, path, {
|
|
1297
|
+
cache: "no-store",
|
|
1298
|
+
...options
|
|
1299
|
+
});
|
|
1300
|
+
return data.skills ?? [];
|
|
1301
|
+
} catch {
|
|
1302
|
+
return [];
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
// src/query/hooks/use-search.ts
|
|
1307
|
+
function useSearchProfiles(filters, options) {
|
|
1308
|
+
const config = useSifaConfig();
|
|
1309
|
+
return reactQuery.useQuery({
|
|
1310
|
+
queryKey: sifaQueryKeys.search.profiles(filters),
|
|
1311
|
+
queryFn: () => fetchSearchProfiles(config, filters),
|
|
1312
|
+
...options
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
function useSkillSuggestions(query, options) {
|
|
1316
|
+
const config = useSifaConfig();
|
|
1317
|
+
return reactQuery.useQuery({
|
|
1318
|
+
queryKey: sifaQueryKeys.search.skills(query),
|
|
1319
|
+
queryFn: () => fetchSkillSuggestions(config, query),
|
|
1320
|
+
enabled: query.trim().length > 0 && (options?.enabled ?? true),
|
|
1321
|
+
...options
|
|
1322
|
+
});
|
|
1323
|
+
}
|
|
1324
|
+
function useCanonicalSkillSearch(query, limit = 10, options) {
|
|
1325
|
+
const config = useSifaConfig();
|
|
1326
|
+
return reactQuery.useQuery({
|
|
1327
|
+
queryKey: sifaQueryKeys.search.canonicalSkills(query, limit),
|
|
1328
|
+
queryFn: () => searchSkills(config, query, limit),
|
|
1329
|
+
enabled: query.trim().length > 0 && (options?.enabled ?? true),
|
|
1330
|
+
...options
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
function useSearchFilters(options) {
|
|
1334
|
+
const config = useSifaConfig();
|
|
1335
|
+
return reactQuery.useQuery({
|
|
1336
|
+
queryKey: sifaQueryKeys.search.filters(),
|
|
1337
|
+
queryFn: () => fetchSearchFilters(config),
|
|
1338
|
+
...options
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
// src/query/fetchers/discovery.ts
|
|
1343
|
+
async function fetchSimilarProfiles(config, did, opts = {}) {
|
|
1344
|
+
const limit = opts.limit ?? 5;
|
|
1345
|
+
const path = `/api/discover/similar/${encodeURIComponent(did)}?limit=${limit}`;
|
|
1346
|
+
try {
|
|
1347
|
+
const data = await apiFetch(config, path, {
|
|
1348
|
+
next: { revalidate: 300 },
|
|
1349
|
+
timeoutMs: 5e3,
|
|
1350
|
+
...opts
|
|
1351
|
+
});
|
|
1352
|
+
return data.profiles ?? [];
|
|
1353
|
+
} catch {
|
|
1354
|
+
return [];
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
async function fetchSuggestions(config, opts = {}) {
|
|
1358
|
+
const params = new URLSearchParams();
|
|
1359
|
+
if (opts.source) params.set("source", opts.source);
|
|
1360
|
+
if (opts.includeDismissed) params.set("include_dismissed", "true");
|
|
1361
|
+
if (opts.cursor) params.set("cursor", opts.cursor);
|
|
1362
|
+
if (opts.limit) params.set("limit", String(opts.limit));
|
|
1363
|
+
const qs = params.toString();
|
|
1364
|
+
const headers = { ...opts.headers ?? {} };
|
|
1365
|
+
if (opts.cookieHeader) headers.cookie = opts.cookieHeader;
|
|
1366
|
+
try {
|
|
1367
|
+
return await apiFetch(config, `/api/suggestions${qs ? `?${qs}` : ""}`, {
|
|
1368
|
+
credentials: "include",
|
|
1369
|
+
cache: "no-store",
|
|
1370
|
+
timeoutMs: 8e3,
|
|
1371
|
+
...opts,
|
|
1372
|
+
headers
|
|
1373
|
+
});
|
|
1374
|
+
} catch {
|
|
1375
|
+
return { onSifa: [], notOnSifa: [] };
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
async function fetchSuggestionCount(config, since, options = {}) {
|
|
1379
|
+
const params = since ? `?since=${encodeURIComponent(since)}` : "";
|
|
1380
|
+
try {
|
|
1381
|
+
const data = await apiFetch(config, `/api/suggestions/count${params}`, {
|
|
1382
|
+
credentials: "include",
|
|
1383
|
+
cache: "no-store",
|
|
1384
|
+
...options
|
|
1385
|
+
});
|
|
1386
|
+
return data.count ?? 0;
|
|
1387
|
+
} catch {
|
|
1388
|
+
return 0;
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
async function fetchFeaturedProfile(config, options = {}) {
|
|
1392
|
+
try {
|
|
1393
|
+
return await apiFetch(config, "/api/featured-profile", {
|
|
1394
|
+
next: { revalidate: 900 },
|
|
1395
|
+
...options
|
|
1396
|
+
});
|
|
1397
|
+
} catch {
|
|
1398
|
+
return null;
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
// src/query/hooks/use-discovery.ts
|
|
1403
|
+
function useSimilarProfiles(did, opts = {}, options) {
|
|
1404
|
+
const config = useSifaConfig();
|
|
1405
|
+
const limit = opts.limit ?? 5;
|
|
1406
|
+
return reactQuery.useQuery({
|
|
1407
|
+
queryKey: sifaQueryKeys.discovery.similar(did ?? "", limit),
|
|
1408
|
+
queryFn: () => fetchSimilarProfiles(config, did ?? "", { limit }),
|
|
1409
|
+
enabled: Boolean(did) && (options?.enabled ?? true),
|
|
1410
|
+
...options
|
|
1411
|
+
});
|
|
1412
|
+
}
|
|
1413
|
+
function useSuggestions(opts = {}, options) {
|
|
1414
|
+
const config = useSifaConfig();
|
|
1415
|
+
return reactQuery.useQuery({
|
|
1416
|
+
queryKey: sifaQueryKeys.discovery.suggestions(opts),
|
|
1417
|
+
queryFn: () => fetchSuggestions(config, opts),
|
|
1418
|
+
...options
|
|
1419
|
+
});
|
|
1420
|
+
}
|
|
1421
|
+
function useSuggestionCount(since, options) {
|
|
1422
|
+
const config = useSifaConfig();
|
|
1423
|
+
return reactQuery.useQuery({
|
|
1424
|
+
queryKey: sifaQueryKeys.discovery.suggestionCount(since),
|
|
1425
|
+
queryFn: () => fetchSuggestionCount(config, since),
|
|
1426
|
+
...options
|
|
1427
|
+
});
|
|
1428
|
+
}
|
|
1429
|
+
function useFeaturedProfile(options) {
|
|
1430
|
+
const config = useSifaConfig();
|
|
1431
|
+
return reactQuery.useQuery({
|
|
1432
|
+
queryKey: sifaQueryKeys.discovery.featured(),
|
|
1433
|
+
queryFn: () => fetchFeaturedProfile(config),
|
|
1434
|
+
...options
|
|
1435
|
+
});
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
// src/query/fetchers/follow.ts
|
|
1439
|
+
async function fetchFollowing(config, opts = {}) {
|
|
1440
|
+
const params = new URLSearchParams();
|
|
1441
|
+
if (opts.source) params.set("source", opts.source);
|
|
1442
|
+
if (opts.cursor) params.set("cursor", opts.cursor);
|
|
1443
|
+
if (opts.limit) params.set("limit", String(opts.limit));
|
|
1444
|
+
const qs = params.toString();
|
|
1445
|
+
try {
|
|
1446
|
+
return await apiFetch(config, `/api/following${qs ? `?${qs}` : ""}`, {
|
|
1447
|
+
credentials: "include",
|
|
1448
|
+
cache: "no-store",
|
|
1449
|
+
...opts
|
|
1450
|
+
});
|
|
1451
|
+
} catch {
|
|
1452
|
+
return { follows: [] };
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
function followUser(config, handle, opts = {}) {
|
|
1456
|
+
const { note, ...rest } = opts;
|
|
1457
|
+
return apiWrite(
|
|
1458
|
+
config,
|
|
1459
|
+
`/api/follow/${encodeURIComponent(handle)}`,
|
|
1460
|
+
"POST",
|
|
1461
|
+
{
|
|
1462
|
+
body: note !== void 0 ? { note } : void 0,
|
|
1463
|
+
...rest
|
|
1464
|
+
}
|
|
1465
|
+
);
|
|
1466
|
+
}
|
|
1467
|
+
function unfollowUser(config, handle, opts = {}) {
|
|
1468
|
+
return apiWrite(config, `/api/follow/${encodeURIComponent(handle)}`, "DELETE", opts);
|
|
1469
|
+
}
|
|
1470
|
+
function buildListPath(prefix, opts) {
|
|
1471
|
+
const params = new URLSearchParams();
|
|
1472
|
+
if (opts.cursor) params.set("cursor", opts.cursor);
|
|
1473
|
+
if (opts.limit) params.set("limit", String(opts.limit));
|
|
1474
|
+
const qs = params.toString();
|
|
1475
|
+
return `${prefix}${qs ? `?${qs}` : ""}`;
|
|
1476
|
+
}
|
|
1477
|
+
async function getFollowers(config, handle, opts = {}) {
|
|
1478
|
+
const headers = { ...opts.headers ?? {} };
|
|
1479
|
+
if (opts.cookieHeader) headers.cookie = opts.cookieHeader;
|
|
1480
|
+
try {
|
|
1481
|
+
const res = await apiFetch(
|
|
1482
|
+
config,
|
|
1483
|
+
buildListPath(`/api/profile/${encodeURIComponent(handle)}/followers`, opts),
|
|
1484
|
+
{ credentials: "include", cache: "no-store", ...opts, headers }
|
|
1485
|
+
);
|
|
1486
|
+
return { follows: res.follows, cursor: res.cursor ?? null };
|
|
1487
|
+
} catch {
|
|
1488
|
+
return { follows: [], cursor: null };
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
async function getFollowing(config, handle, opts = {}) {
|
|
1492
|
+
const headers = { ...opts.headers ?? {} };
|
|
1493
|
+
if (opts.cookieHeader) headers.cookie = opts.cookieHeader;
|
|
1494
|
+
try {
|
|
1495
|
+
const res = await apiFetch(
|
|
1496
|
+
config,
|
|
1497
|
+
buildListPath(`/api/profile/${encodeURIComponent(handle)}/following`, opts),
|
|
1498
|
+
{ credentials: "include", cache: "no-store", ...opts, headers }
|
|
1499
|
+
);
|
|
1500
|
+
return { follows: res.follows, cursor: res.cursor ?? null };
|
|
1501
|
+
} catch {
|
|
1502
|
+
return { follows: [], cursor: null };
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
async function getFollowingFeed(config, opts = {}) {
|
|
1506
|
+
const params = new URLSearchParams();
|
|
1507
|
+
if (opts.cursor) params.set("cursor", opts.cursor);
|
|
1508
|
+
if (opts.limit) params.set("limit", String(opts.limit));
|
|
1509
|
+
if (opts.categories && opts.categories.length > 0) {
|
|
1510
|
+
params.set("categories", opts.categories.join(","));
|
|
1511
|
+
}
|
|
1512
|
+
const qs = params.toString();
|
|
1513
|
+
const headers = { ...opts.headers ?? {} };
|
|
1514
|
+
if (opts.cookieHeader) headers.cookie = opts.cookieHeader;
|
|
1515
|
+
try {
|
|
1516
|
+
const res = await apiFetch(
|
|
1517
|
+
config,
|
|
1518
|
+
`/api/following/feed${qs ? `?${qs}` : ""}`,
|
|
1519
|
+
{ credentials: "include", cache: "no-store", ...opts, headers }
|
|
1520
|
+
);
|
|
1521
|
+
return { items: res.items ?? [], cursor: res.cursor ?? null };
|
|
1522
|
+
} catch {
|
|
1523
|
+
return { items: [], cursor: null };
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
// src/query/hooks/use-follow.ts
|
|
1528
|
+
function useFollowing(opts = {}, options) {
|
|
1529
|
+
const config = useSifaConfig();
|
|
1530
|
+
return reactQuery.useQuery({
|
|
1531
|
+
queryKey: sifaQueryKeys.follow.following(opts),
|
|
1532
|
+
queryFn: () => fetchFollowing(config, opts),
|
|
1533
|
+
...options
|
|
1534
|
+
});
|
|
1535
|
+
}
|
|
1536
|
+
function useFollow(options) {
|
|
1537
|
+
const config = useSifaConfig();
|
|
1538
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1539
|
+
return reactQuery.useMutation({
|
|
1540
|
+
mutationFn: ({ handle, note }) => followUser(config, handle, { note }),
|
|
1541
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
1542
|
+
if (result.success) {
|
|
1543
|
+
await queryClient.invalidateQueries({ queryKey: sifaQueryKeys.follow.all() });
|
|
1544
|
+
}
|
|
1545
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
1546
|
+
},
|
|
1547
|
+
onError: async (error, variables, onMutateResult, context) => {
|
|
1548
|
+
await queryClient.invalidateQueries({ queryKey: sifaQueryKeys.follow.all() });
|
|
1549
|
+
await options?.onError?.(error, variables, onMutateResult, context);
|
|
1550
|
+
},
|
|
1551
|
+
...options
|
|
1552
|
+
});
|
|
1553
|
+
}
|
|
1554
|
+
function useUnfollow(options) {
|
|
1555
|
+
const config = useSifaConfig();
|
|
1556
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1557
|
+
return reactQuery.useMutation({
|
|
1558
|
+
mutationFn: ({ handle }) => unfollowUser(config, handle),
|
|
1559
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
1560
|
+
if (result.success) {
|
|
1561
|
+
await queryClient.invalidateQueries({ queryKey: sifaQueryKeys.follow.all() });
|
|
1562
|
+
}
|
|
1563
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
1564
|
+
},
|
|
1565
|
+
onError: async (error, variables, onMutateResult, context) => {
|
|
1566
|
+
await queryClient.invalidateQueries({ queryKey: sifaQueryKeys.follow.all() });
|
|
1567
|
+
await options?.onError?.(error, variables, onMutateResult, context);
|
|
1568
|
+
},
|
|
1569
|
+
...options
|
|
1570
|
+
});
|
|
1571
|
+
}
|
|
1572
|
+
function useFollowers(handle, opts = {}, options) {
|
|
1573
|
+
const config = useSifaConfig();
|
|
1574
|
+
return reactQuery.useInfiniteQuery({
|
|
1575
|
+
queryKey: sifaQueryKeys.follow.followers(handle),
|
|
1576
|
+
queryFn: ({ pageParam }) => getFollowers(config, handle, { ...opts, cursor: pageParam }),
|
|
1577
|
+
initialPageParam: void 0,
|
|
1578
|
+
getNextPageParam: (lastPage) => lastPage.cursor ?? void 0,
|
|
1579
|
+
enabled: handle.length > 0,
|
|
1580
|
+
...options
|
|
1581
|
+
});
|
|
1582
|
+
}
|
|
1583
|
+
function useFollowingList(handle, opts = {}, options) {
|
|
1584
|
+
const config = useSifaConfig();
|
|
1585
|
+
return reactQuery.useInfiniteQuery({
|
|
1586
|
+
queryKey: sifaQueryKeys.follow.followingOf(handle),
|
|
1587
|
+
queryFn: ({ pageParam }) => getFollowing(config, handle, { ...opts, cursor: pageParam }),
|
|
1588
|
+
initialPageParam: void 0,
|
|
1589
|
+
getNextPageParam: (lastPage) => lastPage.cursor ?? void 0,
|
|
1590
|
+
enabled: handle.length > 0,
|
|
1591
|
+
...options
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
function useFollowingFeed(opts = {}, options) {
|
|
1595
|
+
const config = useSifaConfig();
|
|
1596
|
+
const keyOpts = {
|
|
1597
|
+
limit: opts.limit,
|
|
1598
|
+
categories: opts.categories
|
|
1599
|
+
};
|
|
1600
|
+
return reactQuery.useInfiniteQuery({
|
|
1601
|
+
queryKey: sifaQueryKeys.follow.feed(keyOpts),
|
|
1602
|
+
queryFn: ({ pageParam }) => getFollowingFeed(config, { ...opts, cursor: pageParam }),
|
|
1603
|
+
initialPageParam: void 0,
|
|
1604
|
+
getNextPageParam: (lastPage) => lastPage.cursor ?? void 0,
|
|
1605
|
+
...options
|
|
1606
|
+
});
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
// src/query/fetchers/follow-extras.ts
|
|
1610
|
+
function buildListPath2(prefix, opts) {
|
|
1611
|
+
const params = new URLSearchParams();
|
|
1612
|
+
if (opts.cursor) params.set("cursor", opts.cursor);
|
|
1613
|
+
if (opts.limit) params.set("limit", String(opts.limit));
|
|
1614
|
+
const qs = params.toString();
|
|
1615
|
+
return `${prefix}${qs ? `?${qs}` : ""}`;
|
|
1616
|
+
}
|
|
1617
|
+
async function fetchFollowProfilePage(config, path, opts) {
|
|
1618
|
+
const headers = { ...opts.headers ?? {} };
|
|
1619
|
+
if (opts.cookieHeader) headers.cookie = opts.cookieHeader;
|
|
1620
|
+
try {
|
|
1621
|
+
const res = await apiFetch(
|
|
1622
|
+
config,
|
|
1623
|
+
path,
|
|
1624
|
+
{ credentials: "include", cache: "no-store", ...opts, headers }
|
|
1625
|
+
);
|
|
1626
|
+
return { items: res.items ?? [], cursor: res.cursor ?? null };
|
|
1627
|
+
} catch {
|
|
1628
|
+
return { items: [], cursor: null };
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
async function getMutuals(config, handleOrDid, opts = {}) {
|
|
1632
|
+
return fetchFollowProfilePage(
|
|
1633
|
+
config,
|
|
1634
|
+
buildListPath2(`/api/profile/${encodeURIComponent(handleOrDid)}/mutuals`, opts),
|
|
1635
|
+
opts
|
|
1636
|
+
);
|
|
1637
|
+
}
|
|
1638
|
+
async function getBlueskySuggestions(config, opts = {}) {
|
|
1639
|
+
return fetchFollowProfilePage(config, buildListPath2("/api/me/bluesky-suggestions", opts), opts);
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
// src/query/hooks/use-follow-extras.ts
|
|
1643
|
+
function useMutuals(handleOrDid, opts = {}, options) {
|
|
1644
|
+
const config = useSifaConfig();
|
|
1645
|
+
return reactQuery.useInfiniteQuery({
|
|
1646
|
+
queryKey: sifaQueryKeys.follow.mutuals(handleOrDid),
|
|
1647
|
+
queryFn: ({ pageParam }) => getMutuals(config, handleOrDid, { ...opts, cursor: pageParam }),
|
|
1648
|
+
initialPageParam: void 0,
|
|
1649
|
+
getNextPageParam: (lastPage) => lastPage.cursor ?? void 0,
|
|
1650
|
+
enabled: handleOrDid.length > 0,
|
|
1651
|
+
...options
|
|
1652
|
+
});
|
|
1653
|
+
}
|
|
1654
|
+
function useBlueskySuggestions(opts = {}, options) {
|
|
1655
|
+
const config = useSifaConfig();
|
|
1656
|
+
return reactQuery.useInfiniteQuery({
|
|
1657
|
+
queryKey: sifaQueryKeys.follow.blueskySuggestions(),
|
|
1658
|
+
queryFn: ({ pageParam }) => getBlueskySuggestions(config, { ...opts, cursor: pageParam }),
|
|
1659
|
+
initialPageParam: void 0,
|
|
1660
|
+
getNextPageParam: (lastPage) => lastPage.cursor ?? void 0,
|
|
1661
|
+
...options
|
|
1662
|
+
});
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
// src/query/fetchers/admin-feature-allowlists.ts
|
|
1666
|
+
async function listFeatureAllowlist(config, flag, opts = {}) {
|
|
1667
|
+
const headers = { ...opts.headers ?? {} };
|
|
1668
|
+
if (opts.cookieHeader) headers.cookie = opts.cookieHeader;
|
|
1669
|
+
try {
|
|
1670
|
+
const res = await apiFetch(
|
|
1671
|
+
config,
|
|
1672
|
+
`/api/admin/feature-allowlists/${encodeURIComponent(flag)}`,
|
|
1673
|
+
{ credentials: "include", cache: "no-store", ...opts, headers }
|
|
1674
|
+
);
|
|
1675
|
+
return { items: res.items ?? [] };
|
|
1676
|
+
} catch {
|
|
1677
|
+
return { items: [] };
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
function addFeatureAllowlist(config, flag, did, opts = {}) {
|
|
1681
|
+
const { note, ...rest } = opts;
|
|
1682
|
+
return apiWrite(config, `/api/admin/feature-allowlists/${encodeURIComponent(flag)}`, "POST", {
|
|
1683
|
+
body: note !== void 0 ? { did, note } : { did },
|
|
1684
|
+
...rest
|
|
1685
|
+
});
|
|
1686
|
+
}
|
|
1687
|
+
function removeFeatureAllowlist(config, flag, did, opts = {}) {
|
|
1688
|
+
return apiWrite(
|
|
1689
|
+
config,
|
|
1690
|
+
`/api/admin/feature-allowlists/${encodeURIComponent(flag)}/${encodeURIComponent(did)}`,
|
|
1691
|
+
"DELETE",
|
|
1692
|
+
opts
|
|
1693
|
+
);
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
// src/query/hooks/use-feature-allowlist.ts
|
|
1697
|
+
function useFeatureAllowlist(flag, options) {
|
|
1698
|
+
const config = useSifaConfig();
|
|
1699
|
+
return reactQuery.useQuery({
|
|
1700
|
+
queryKey: sifaQueryKeys.admin.featureAllowlist(flag),
|
|
1701
|
+
queryFn: () => listFeatureAllowlist(config, flag),
|
|
1702
|
+
...options
|
|
1703
|
+
});
|
|
1704
|
+
}
|
|
1705
|
+
function useAddFeatureAllowlist(flag, options) {
|
|
1706
|
+
const config = useSifaConfig();
|
|
1707
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1708
|
+
const key = sifaQueryKeys.admin.featureAllowlist(flag);
|
|
1709
|
+
return reactQuery.useMutation({
|
|
1710
|
+
mutationFn: ({ did, note }) => addFeatureAllowlist(config, flag, did, { note }),
|
|
1711
|
+
onMutate: async ({ did, note }) => {
|
|
1712
|
+
await queryClient.cancelQueries({ queryKey: key });
|
|
1713
|
+
const previous = queryClient.getQueryData(key);
|
|
1714
|
+
const optimisticEntry = {
|
|
1715
|
+
did,
|
|
1716
|
+
addedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1717
|
+
note: note ?? null
|
|
1718
|
+
};
|
|
1719
|
+
const next = previous ? { items: [optimisticEntry, ...previous.items.filter((e) => e.did !== did)] } : { items: [optimisticEntry] };
|
|
1720
|
+
queryClient.setQueryData(key, next);
|
|
1721
|
+
return { previous };
|
|
1722
|
+
},
|
|
1723
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
1724
|
+
if (!result.success && onMutateResult?.previous) {
|
|
1725
|
+
queryClient.setQueryData(key, onMutateResult.previous);
|
|
1726
|
+
}
|
|
1727
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
1728
|
+
},
|
|
1729
|
+
onError: async (error, variables, onMutateResult, context) => {
|
|
1730
|
+
if (onMutateResult?.previous) {
|
|
1731
|
+
queryClient.setQueryData(key, onMutateResult.previous);
|
|
1732
|
+
}
|
|
1733
|
+
await options?.onError?.(error, variables, onMutateResult, context);
|
|
1734
|
+
},
|
|
1735
|
+
onSettled: async (result, error, variables, onMutateResult, context) => {
|
|
1736
|
+
await queryClient.invalidateQueries({ queryKey: key });
|
|
1737
|
+
await options?.onSettled?.(result, error, variables, onMutateResult, context);
|
|
1738
|
+
},
|
|
1739
|
+
...options
|
|
1740
|
+
});
|
|
1741
|
+
}
|
|
1742
|
+
function useRemoveFeatureAllowlist(flag, options) {
|
|
1743
|
+
const config = useSifaConfig();
|
|
1744
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1745
|
+
const key = sifaQueryKeys.admin.featureAllowlist(flag);
|
|
1746
|
+
return reactQuery.useMutation(
|
|
1747
|
+
{
|
|
1748
|
+
mutationFn: ({ did }) => removeFeatureAllowlist(config, flag, did),
|
|
1749
|
+
onMutate: async ({ did }) => {
|
|
1750
|
+
await queryClient.cancelQueries({ queryKey: key });
|
|
1751
|
+
const previous = queryClient.getQueryData(key);
|
|
1752
|
+
if (previous) {
|
|
1753
|
+
queryClient.setQueryData(key, {
|
|
1754
|
+
items: previous.items.filter((e) => e.did !== did)
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1757
|
+
return { previous };
|
|
1758
|
+
},
|
|
1759
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
1760
|
+
if (!result.success && onMutateResult?.previous) {
|
|
1761
|
+
queryClient.setQueryData(key, onMutateResult.previous);
|
|
1762
|
+
}
|
|
1763
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
1764
|
+
},
|
|
1765
|
+
onError: async (error, variables, onMutateResult, context) => {
|
|
1766
|
+
if (onMutateResult?.previous) {
|
|
1767
|
+
queryClient.setQueryData(key, onMutateResult.previous);
|
|
1768
|
+
}
|
|
1769
|
+
await options?.onError?.(error, variables, onMutateResult, context);
|
|
1770
|
+
},
|
|
1771
|
+
onSettled: async (result, error, variables, onMutateResult, context) => {
|
|
1772
|
+
await queryClient.invalidateQueries({ queryKey: key });
|
|
1773
|
+
await options?.onSettled?.(result, error, variables, onMutateResult, context);
|
|
1774
|
+
},
|
|
1775
|
+
...options
|
|
1776
|
+
}
|
|
1777
|
+
);
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1780
|
+
// src/query/fetchers/activity.ts
|
|
1781
|
+
async function fetchHeatmapData(config, handleOrDid, days, options = {}) {
|
|
1782
|
+
const path = `/api/activity/${encodeURIComponent(handleOrDid)}/heatmap?days=${days}`;
|
|
1783
|
+
try {
|
|
1784
|
+
return await apiFetch(config, path, {
|
|
1785
|
+
next: { revalidate: 900, tags: [`heatmap-${handleOrDid}`] },
|
|
1786
|
+
...options
|
|
1787
|
+
});
|
|
1788
|
+
} catch {
|
|
1789
|
+
return null;
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
async function fetchActivityTeaser(config, handleOrDid, options = {}) {
|
|
1793
|
+
const headers = { ...options.headers ?? {} };
|
|
1794
|
+
if (options.cookieHeader) headers.cookie = options.cookieHeader;
|
|
1795
|
+
try {
|
|
1796
|
+
return await apiFetch(
|
|
1797
|
+
config,
|
|
1798
|
+
`/api/activity/${encodeURIComponent(handleOrDid)}/teaser`,
|
|
1799
|
+
{
|
|
1800
|
+
credentials: "include",
|
|
1801
|
+
timeoutMs: 8e3,
|
|
1802
|
+
next: { revalidate: 300, tags: [`activity-teaser-${handleOrDid}`] },
|
|
1803
|
+
...options,
|
|
1804
|
+
headers
|
|
1805
|
+
}
|
|
1806
|
+
);
|
|
1807
|
+
} catch {
|
|
1808
|
+
return null;
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
async function fetchActivityFeed(config, handleOrDid, options = {}) {
|
|
1812
|
+
const params = new URLSearchParams();
|
|
1813
|
+
if (options.category) params.set("category", options.category);
|
|
1814
|
+
if (options.limit) params.set("limit", String(options.limit));
|
|
1815
|
+
if (options.cursor) params.set("cursor", options.cursor);
|
|
1816
|
+
const qs = params.toString();
|
|
1817
|
+
const headers = { ...options.headers ?? {} };
|
|
1818
|
+
if (options.cookieHeader) headers.cookie = options.cookieHeader;
|
|
1819
|
+
try {
|
|
1820
|
+
return await apiFetch(
|
|
1821
|
+
config,
|
|
1822
|
+
`/api/activity/${encodeURIComponent(handleOrDid)}${qs ? `?${qs}` : ""}`,
|
|
1823
|
+
{
|
|
1824
|
+
credentials: "include",
|
|
1825
|
+
cache: "no-store",
|
|
1826
|
+
...options,
|
|
1827
|
+
headers
|
|
1828
|
+
}
|
|
1829
|
+
);
|
|
1830
|
+
} catch {
|
|
1831
|
+
return null;
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
// src/query/hooks/use-activity.ts
|
|
1836
|
+
function useHeatmapData(handleOrDid, days, options) {
|
|
1837
|
+
const config = useSifaConfig();
|
|
1838
|
+
return reactQuery.useQuery({
|
|
1839
|
+
queryKey: sifaQueryKeys.activity.heatmap(handleOrDid ?? "", days),
|
|
1840
|
+
queryFn: () => fetchHeatmapData(config, handleOrDid ?? "", days),
|
|
1841
|
+
enabled: Boolean(handleOrDid) && (options?.enabled ?? true),
|
|
1842
|
+
...options
|
|
1843
|
+
});
|
|
1844
|
+
}
|
|
1845
|
+
function useActivityTeaser(handleOrDid, options) {
|
|
1846
|
+
const config = useSifaConfig();
|
|
1847
|
+
return reactQuery.useQuery({
|
|
1848
|
+
queryKey: sifaQueryKeys.activity.teaser(handleOrDid ?? ""),
|
|
1849
|
+
queryFn: () => fetchActivityTeaser(config, handleOrDid ?? ""),
|
|
1850
|
+
enabled: Boolean(handleOrDid) && (options?.enabled ?? true),
|
|
1851
|
+
...options
|
|
1852
|
+
});
|
|
1853
|
+
}
|
|
1854
|
+
function useActivityFeed(handleOrDid, opts = {}, options) {
|
|
1855
|
+
const config = useSifaConfig();
|
|
1856
|
+
return reactQuery.useQuery({
|
|
1857
|
+
queryKey: sifaQueryKeys.activity.feed(handleOrDid ?? "", opts),
|
|
1858
|
+
queryFn: () => fetchActivityFeed(config, handleOrDid ?? "", opts),
|
|
1859
|
+
enabled: Boolean(handleOrDid) && (options?.enabled ?? true),
|
|
1860
|
+
...options
|
|
1861
|
+
});
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
// src/query/fetchers/endorsement.ts
|
|
1865
|
+
async function fetchEndorsementCount(config, did, options = {}) {
|
|
1866
|
+
const path = `/api/endorsement/${encodeURIComponent(did)}`;
|
|
1867
|
+
try {
|
|
1868
|
+
const data = await apiFetch(config, path, {
|
|
1869
|
+
cache: "no-store",
|
|
1870
|
+
timeoutMs: 5e3,
|
|
1871
|
+
...options
|
|
1872
|
+
});
|
|
1873
|
+
if (typeof data !== "object" || data === null || !("endorsements" in data)) {
|
|
1874
|
+
return 0;
|
|
1875
|
+
}
|
|
1876
|
+
const endorsements = data.endorsements;
|
|
1877
|
+
return Array.isArray(endorsements) ? endorsements.length : 0;
|
|
1878
|
+
} catch {
|
|
1879
|
+
return 0;
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1883
|
+
// src/query/hooks/use-endorsement.ts
|
|
1884
|
+
function useEndorsementCount(did, options) {
|
|
1885
|
+
const config = useSifaConfig();
|
|
1886
|
+
return reactQuery.useQuery({
|
|
1887
|
+
queryKey: sifaQueryKeys.endorsement.count(did ?? ""),
|
|
1888
|
+
queryFn: () => fetchEndorsementCount(config, did ?? ""),
|
|
1889
|
+
enabled: Boolean(did) && (options?.enabled ?? true),
|
|
1890
|
+
...options
|
|
1891
|
+
});
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1894
|
+
// src/query/fetchers/stream.ts
|
|
1895
|
+
async function fetchNetworkStreamCount(config, did, options = {}) {
|
|
1896
|
+
const headers = { ...options.headers ?? {} };
|
|
1897
|
+
if (options.cookieHeader) headers.cookie = options.cookieHeader;
|
|
1898
|
+
try {
|
|
1899
|
+
const data = await apiFetch(
|
|
1900
|
+
config,
|
|
1901
|
+
`/api/stream/network?did=${encodeURIComponent(did)}`,
|
|
1902
|
+
{
|
|
1903
|
+
cache: "no-store",
|
|
1904
|
+
timeoutMs: 5e3,
|
|
1905
|
+
...options.cookieHeader ? {} : { credentials: "include" },
|
|
1906
|
+
...options,
|
|
1907
|
+
headers
|
|
1908
|
+
}
|
|
1909
|
+
);
|
|
1910
|
+
if (typeof data !== "object" || data === null || !("items" in data)) {
|
|
1911
|
+
return 0;
|
|
1912
|
+
}
|
|
1913
|
+
const items = data.items;
|
|
1914
|
+
return Array.isArray(items) ? items.length : 0;
|
|
1915
|
+
} catch {
|
|
1916
|
+
return 0;
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
// src/query/hooks/use-stream.ts
|
|
1921
|
+
function useNetworkStreamCount(did, options) {
|
|
1922
|
+
const config = useSifaConfig();
|
|
1923
|
+
return reactQuery.useQuery({
|
|
1924
|
+
queryKey: sifaQueryKeys.stream.networkCount(did ?? ""),
|
|
1925
|
+
queryFn: () => fetchNetworkStreamCount(config, did ?? ""),
|
|
1926
|
+
enabled: Boolean(did) && (options?.enabled ?? true),
|
|
1927
|
+
...options
|
|
1928
|
+
});
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
// src/query/fetchers/reactions.ts
|
|
1932
|
+
async function fetchReactionStatus(config, uris, options = {}) {
|
|
1933
|
+
if (uris.length === 0) return {};
|
|
1934
|
+
const headers = { ...options.headers ?? {} };
|
|
1935
|
+
if (options.cookieHeader) headers.cookie = options.cookieHeader;
|
|
1936
|
+
try {
|
|
1937
|
+
return await apiFetch(
|
|
1938
|
+
config,
|
|
1939
|
+
`/api/reactions/status?uris=${encodeURIComponent(uris.join(","))}`,
|
|
1940
|
+
{
|
|
1941
|
+
credentials: "include",
|
|
1942
|
+
...options,
|
|
1943
|
+
headers
|
|
1944
|
+
}
|
|
1945
|
+
);
|
|
1946
|
+
} catch {
|
|
1947
|
+
return null;
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
async function checkAppAccount(config, appId, options = {}) {
|
|
1951
|
+
const headers = { ...options.headers ?? {} };
|
|
1952
|
+
if (options.cookieHeader) headers.cookie = options.cookieHeader;
|
|
1953
|
+
try {
|
|
1954
|
+
return await apiFetch(
|
|
1955
|
+
config,
|
|
1956
|
+
`/api/reactions/account-check/${encodeURIComponent(appId)}`,
|
|
1957
|
+
{
|
|
1958
|
+
credentials: "include",
|
|
1959
|
+
...options,
|
|
1960
|
+
headers
|
|
1961
|
+
}
|
|
1962
|
+
);
|
|
1963
|
+
} catch {
|
|
1964
|
+
return null;
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
async function createReaction(config, targetUri, appId, targetCid, options = {}) {
|
|
1968
|
+
const fetchFn = config.fetch ?? globalThis.fetch;
|
|
1969
|
+
const url = `${config.baseUrl}/api/reactions`;
|
|
1970
|
+
try {
|
|
1971
|
+
const res = await fetchFn(url, {
|
|
1972
|
+
method: "POST",
|
|
1973
|
+
headers: { "Content-Type": "application/json", ...options.headers ?? {} },
|
|
1974
|
+
credentials: options.credentials ?? "include",
|
|
1975
|
+
body: JSON.stringify({ targetUri, appId, targetCid }),
|
|
1976
|
+
signal: options.signal ?? AbortSignal.timeout(options.timeoutMs ?? 1e4)
|
|
1977
|
+
});
|
|
1978
|
+
if (!res.ok) {
|
|
1979
|
+
if (res.status === 403) {
|
|
1980
|
+
try {
|
|
1981
|
+
const body = await res.json();
|
|
1982
|
+
if (body.error === "ScopeInsufficient") {
|
|
1983
|
+
return {
|
|
1984
|
+
ok: false,
|
|
1985
|
+
error: { type: "scope_insufficient", requiredScope: body.requiredScope }
|
|
1986
|
+
};
|
|
1987
|
+
}
|
|
1988
|
+
} catch {
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
return { ok: false, error: { type: "error" } };
|
|
1992
|
+
}
|
|
1993
|
+
const data = await res.json();
|
|
1994
|
+
return { ok: true, data };
|
|
1995
|
+
} catch {
|
|
1996
|
+
return { ok: false, error: { type: "error" } };
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
function deleteReaction(config, targetUri, appId, options = {}) {
|
|
2000
|
+
return apiWrite(config, "/api/reactions", "DELETE", {
|
|
2001
|
+
body: { targetUri, appId },
|
|
2002
|
+
...options
|
|
2003
|
+
});
|
|
2004
|
+
}
|
|
2005
|
+
|
|
2006
|
+
// src/query/hooks/use-reactions.ts
|
|
2007
|
+
function useReactionStatus(uris, options) {
|
|
2008
|
+
const config = useSifaConfig();
|
|
2009
|
+
return reactQuery.useQuery({
|
|
2010
|
+
queryKey: sifaQueryKeys.reactions.status(uris),
|
|
2011
|
+
queryFn: () => fetchReactionStatus(config, uris),
|
|
2012
|
+
...options
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2015
|
+
function useAppAccountCheck(appId, options) {
|
|
2016
|
+
const config = useSifaConfig();
|
|
2017
|
+
return reactQuery.useQuery({
|
|
2018
|
+
queryKey: sifaQueryKeys.reactions.accountCheck(appId ?? ""),
|
|
2019
|
+
queryFn: () => checkAppAccount(config, appId ?? ""),
|
|
2020
|
+
enabled: Boolean(appId) && (options?.enabled ?? true),
|
|
2021
|
+
...options
|
|
2022
|
+
});
|
|
2023
|
+
}
|
|
2024
|
+
function useCreateReaction(options) {
|
|
2025
|
+
const config = useSifaConfig();
|
|
2026
|
+
const queryClient = reactQuery.useQueryClient();
|
|
2027
|
+
return reactQuery.useMutation({
|
|
2028
|
+
mutationFn: ({ targetUri, appId, targetCid }) => createReaction(config, targetUri, appId, targetCid),
|
|
2029
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
2030
|
+
if (result.ok) {
|
|
2031
|
+
await queryClient.invalidateQueries({ queryKey: sifaQueryKeys.reactions.all() });
|
|
2032
|
+
}
|
|
2033
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
2034
|
+
},
|
|
2035
|
+
...options
|
|
2036
|
+
});
|
|
2037
|
+
}
|
|
2038
|
+
function useDeleteReaction(options) {
|
|
2039
|
+
const config = useSifaConfig();
|
|
2040
|
+
const queryClient = reactQuery.useQueryClient();
|
|
2041
|
+
return reactQuery.useMutation({
|
|
2042
|
+
mutationFn: ({ targetUri, appId }) => deleteReaction(config, targetUri, appId),
|
|
2043
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
2044
|
+
if (result.success) {
|
|
2045
|
+
await queryClient.invalidateQueries({ queryKey: sifaQueryKeys.reactions.all() });
|
|
2046
|
+
}
|
|
2047
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
2048
|
+
},
|
|
2049
|
+
...options
|
|
2050
|
+
});
|
|
2051
|
+
}
|
|
2052
|
+
|
|
2053
|
+
// src/query/fetchers/roadmap.ts
|
|
2054
|
+
async function fetchRoadmapVotes(config, options = {}) {
|
|
2055
|
+
try {
|
|
2056
|
+
return await apiFetch(config, "/api/roadmap/votes", {
|
|
2057
|
+
cache: "no-store",
|
|
2058
|
+
...options
|
|
2059
|
+
});
|
|
2060
|
+
} catch {
|
|
2061
|
+
return {};
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
async function fetchMyRoadmapVotes(config, options = {}) {
|
|
2065
|
+
const headers = { ...options.headers ?? {} };
|
|
2066
|
+
if (options.cookieHeader) headers.cookie = options.cookieHeader;
|
|
2067
|
+
try {
|
|
2068
|
+
const data = await apiFetch(config, "/api/roadmap/votes/me", {
|
|
2069
|
+
credentials: "include",
|
|
2070
|
+
...options,
|
|
2071
|
+
headers
|
|
2072
|
+
});
|
|
2073
|
+
return data.voted ?? [];
|
|
2074
|
+
} catch {
|
|
2075
|
+
return [];
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
function castRoadmapVote(config, key, options = {}) {
|
|
2079
|
+
return apiWrite(config, `/api/roadmap/votes/${encodeURIComponent(key)}`, "POST", options);
|
|
2080
|
+
}
|
|
2081
|
+
function retractRoadmapVote(config, key, options = {}) {
|
|
2082
|
+
return apiWrite(config, `/api/roadmap/votes/${encodeURIComponent(key)}`, "DELETE", options);
|
|
2083
|
+
}
|
|
2084
|
+
|
|
2085
|
+
// src/query/hooks/use-roadmap.ts
|
|
2086
|
+
function useRoadmapVotes(options) {
|
|
2087
|
+
const config = useSifaConfig();
|
|
2088
|
+
return reactQuery.useQuery({
|
|
2089
|
+
queryKey: sifaQueryKeys.roadmap.votes(),
|
|
2090
|
+
queryFn: () => fetchRoadmapVotes(config),
|
|
2091
|
+
...options
|
|
2092
|
+
});
|
|
2093
|
+
}
|
|
2094
|
+
function useMyRoadmapVotes(options) {
|
|
2095
|
+
const config = useSifaConfig();
|
|
2096
|
+
return reactQuery.useQuery({
|
|
2097
|
+
queryKey: sifaQueryKeys.roadmap.myVotes(),
|
|
2098
|
+
queryFn: () => fetchMyRoadmapVotes(config),
|
|
2099
|
+
...options
|
|
2100
|
+
});
|
|
2101
|
+
}
|
|
2102
|
+
async function invalidateRoadmap(queryClient) {
|
|
2103
|
+
await queryClient.invalidateQueries({ queryKey: sifaQueryKeys.roadmap.all() });
|
|
2104
|
+
}
|
|
2105
|
+
function useCastRoadmapVote(options) {
|
|
2106
|
+
const config = useSifaConfig();
|
|
2107
|
+
const queryClient = reactQuery.useQueryClient();
|
|
2108
|
+
return reactQuery.useMutation({
|
|
2109
|
+
mutationFn: (key) => castRoadmapVote(config, key),
|
|
2110
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
2111
|
+
if (result.success) {
|
|
2112
|
+
await invalidateRoadmap(queryClient);
|
|
2113
|
+
}
|
|
2114
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
2115
|
+
},
|
|
2116
|
+
...options
|
|
2117
|
+
});
|
|
2118
|
+
}
|
|
2119
|
+
function useRetractRoadmapVote(options) {
|
|
2120
|
+
const config = useSifaConfig();
|
|
2121
|
+
const queryClient = reactQuery.useQueryClient();
|
|
2122
|
+
return reactQuery.useMutation({
|
|
2123
|
+
mutationFn: (key) => retractRoadmapVote(config, key),
|
|
2124
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
2125
|
+
if (result.success) {
|
|
2126
|
+
await invalidateRoadmap(queryClient);
|
|
2127
|
+
}
|
|
2128
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
2129
|
+
},
|
|
2130
|
+
...options
|
|
2131
|
+
});
|
|
2132
|
+
}
|
|
2133
|
+
|
|
2134
|
+
// src/query/fetchers/destructive.ts
|
|
2135
|
+
function resetProfile(config, deletePdsData, options = {}) {
|
|
2136
|
+
return apiWrite(config, "/api/profile/reset", "DELETE", {
|
|
2137
|
+
body: { deletePdsData },
|
|
2138
|
+
...options
|
|
2139
|
+
});
|
|
2140
|
+
}
|
|
2141
|
+
function deleteAccount(config, deletePdsData, options = {}) {
|
|
2142
|
+
return apiWrite(config, "/api/profile/account", "DELETE", {
|
|
2143
|
+
body: { deletePdsData },
|
|
2144
|
+
...options
|
|
2145
|
+
});
|
|
2146
|
+
}
|
|
2147
|
+
|
|
2148
|
+
// src/query/hooks/use-destructive.ts
|
|
2149
|
+
function useResetProfile(options) {
|
|
2150
|
+
const config = useSifaConfig();
|
|
2151
|
+
const queryClient = reactQuery.useQueryClient();
|
|
2152
|
+
return reactQuery.useMutation({
|
|
2153
|
+
mutationFn: (deletePdsData) => resetProfile(config, deletePdsData),
|
|
2154
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
2155
|
+
if (result.success) {
|
|
2156
|
+
await queryClient.invalidateQueries({ queryKey: sifaQueryKeys.all() });
|
|
2157
|
+
}
|
|
2158
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
2159
|
+
},
|
|
2160
|
+
...options
|
|
2161
|
+
});
|
|
2162
|
+
}
|
|
2163
|
+
function useDeleteAccount(options) {
|
|
2164
|
+
const config = useSifaConfig();
|
|
2165
|
+
const queryClient = reactQuery.useQueryClient();
|
|
2166
|
+
return reactQuery.useMutation({
|
|
2167
|
+
mutationFn: (deletePdsData) => deleteAccount(config, deletePdsData),
|
|
2168
|
+
onSuccess: async (result, variables, onMutateResult, context) => {
|
|
2169
|
+
if (result.success) {
|
|
2170
|
+
queryClient.clear();
|
|
2171
|
+
}
|
|
2172
|
+
await options?.onSuccess?.(result, variables, onMutateResult, context);
|
|
2173
|
+
},
|
|
2174
|
+
...options
|
|
2175
|
+
});
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2178
|
+
exports.SifaProvider = SifaProvider;
|
|
2179
|
+
exports.sifaQueryKeys = sifaQueryKeys;
|
|
2180
|
+
exports.useActivityFeed = useActivityFeed;
|
|
2181
|
+
exports.useActivityTeaser = useActivityTeaser;
|
|
2182
|
+
exports.useAddFeatureAllowlist = useAddFeatureAllowlist;
|
|
2183
|
+
exports.useAppAccountCheck = useAppAccountCheck;
|
|
2184
|
+
exports.useAppsRegistry = useAppsRegistry;
|
|
2185
|
+
exports.useAtFundLink = useAtFundLink;
|
|
2186
|
+
exports.useBlueskySuggestions = useBlueskySuggestions;
|
|
2187
|
+
exports.useBulkHideProfileItems = useBulkHideProfileItems;
|
|
2188
|
+
exports.useBulkHideStandardPublications = useBulkHideStandardPublications;
|
|
2189
|
+
exports.useBulkUnhideProfileItems = useBulkUnhideProfileItems;
|
|
2190
|
+
exports.useBulkUnhideStandardPublications = useBulkUnhideStandardPublications;
|
|
2191
|
+
exports.useCanonicalSkillSearch = useCanonicalSkillSearch;
|
|
2192
|
+
exports.useCastRoadmapVote = useCastRoadmapVote;
|
|
2193
|
+
exports.useCreateEducation = useCreateEducation;
|
|
2194
|
+
exports.useCreateEndorsement = useCreateEndorsement;
|
|
2195
|
+
exports.useCreateExternalAccount = useCreateExternalAccount;
|
|
2196
|
+
exports.useCreatePosition = useCreatePosition;
|
|
2197
|
+
exports.useCreateProfileLocation = useCreateProfileLocation;
|
|
2198
|
+
exports.useCreateReaction = useCreateReaction;
|
|
2199
|
+
exports.useCreateRecord = useCreateRecord;
|
|
2200
|
+
exports.useCreateSkill = useCreateSkill;
|
|
2201
|
+
exports.useDeleteAccount = useDeleteAccount;
|
|
2202
|
+
exports.useDeleteAvatarOverride = useDeleteAvatarOverride;
|
|
2203
|
+
exports.useDeleteEducation = useDeleteEducation;
|
|
2204
|
+
exports.useDeleteExternalAccount = useDeleteExternalAccount;
|
|
2205
|
+
exports.useDeletePosition = useDeletePosition;
|
|
2206
|
+
exports.useDeleteProfileLocation = useDeleteProfileLocation;
|
|
2207
|
+
exports.useDeleteReaction = useDeleteReaction;
|
|
2208
|
+
exports.useDeleteRecord = useDeleteRecord;
|
|
2209
|
+
exports.useDeleteSkill = useDeleteSkill;
|
|
2210
|
+
exports.useEndorsementCount = useEndorsementCount;
|
|
2211
|
+
exports.useExternalAccounts = useExternalAccounts;
|
|
2212
|
+
exports.useFeatureAllowlist = useFeatureAllowlist;
|
|
2213
|
+
exports.useFeaturedProfile = useFeaturedProfile;
|
|
2214
|
+
exports.useFollow = useFollow;
|
|
2215
|
+
exports.useFollowers = useFollowers;
|
|
2216
|
+
exports.useFollowing = useFollowing;
|
|
2217
|
+
exports.useFollowingFeed = useFollowingFeed;
|
|
2218
|
+
exports.useFollowingList = useFollowingList;
|
|
2219
|
+
exports.useHeatmapData = useHeatmapData;
|
|
2220
|
+
exports.useHiddenApps = useHiddenApps;
|
|
2221
|
+
exports.useHideKeytraceClaim = useHideKeytraceClaim;
|
|
2222
|
+
exports.useHideOrcidPublication = useHideOrcidPublication;
|
|
2223
|
+
exports.useHideProfileItem = useHideProfileItem;
|
|
2224
|
+
exports.useHideSifaPublication = useHideSifaPublication;
|
|
2225
|
+
exports.useHideStandardPublication = useHideStandardPublication;
|
|
2226
|
+
exports.useLinkSkillToPosition = useLinkSkillToPosition;
|
|
2227
|
+
exports.useMutuals = useMutuals;
|
|
2228
|
+
exports.useMyRoadmapVotes = useMyRoadmapVotes;
|
|
2229
|
+
exports.useNetworkStreamCount = useNetworkStreamCount;
|
|
2230
|
+
exports.useProfile = useProfile;
|
|
2231
|
+
exports.useReactionStatus = useReactionStatus;
|
|
2232
|
+
exports.useRefreshOrcidPublications = useRefreshOrcidPublications;
|
|
2233
|
+
exports.useRefreshPds = useRefreshPds;
|
|
2234
|
+
exports.useRemoveFeatureAllowlist = useRemoveFeatureAllowlist;
|
|
2235
|
+
exports.useResetProfile = useResetProfile;
|
|
2236
|
+
exports.useRetractRoadmapVote = useRetractRoadmapVote;
|
|
2237
|
+
exports.useRoadmapVotes = useRoadmapVotes;
|
|
2238
|
+
exports.useSearchFilters = useSearchFilters;
|
|
2239
|
+
exports.useSearchProfiles = useSearchProfiles;
|
|
2240
|
+
exports.useSetExternalAccountPrimary = useSetExternalAccountPrimary;
|
|
2241
|
+
exports.useSetPositionPrimary = useSetPositionPrimary;
|
|
2242
|
+
exports.useSifaConfig = useSifaConfig;
|
|
2243
|
+
exports.useSimilarProfiles = useSimilarProfiles;
|
|
2244
|
+
exports.useSkillSuggestions = useSkillSuggestions;
|
|
2245
|
+
exports.useStats = useStats;
|
|
2246
|
+
exports.useSuggestionCount = useSuggestionCount;
|
|
2247
|
+
exports.useSuggestions = useSuggestions;
|
|
2248
|
+
exports.useUnfollow = useUnfollow;
|
|
2249
|
+
exports.useUnhideKeytraceClaim = useUnhideKeytraceClaim;
|
|
2250
|
+
exports.useUnhideOrcidPublication = useUnhideOrcidPublication;
|
|
2251
|
+
exports.useUnhideProfileItem = useUnhideProfileItem;
|
|
2252
|
+
exports.useUnhideSifaPublication = useUnhideSifaPublication;
|
|
2253
|
+
exports.useUnhideStandardPublication = useUnhideStandardPublication;
|
|
2254
|
+
exports.useUnlinkSkillFromPosition = useUnlinkSkillFromPosition;
|
|
2255
|
+
exports.useUnsetExternalAccountPrimary = useUnsetExternalAccountPrimary;
|
|
2256
|
+
exports.useUnsetPositionPrimary = useUnsetPositionPrimary;
|
|
2257
|
+
exports.useUpdateEducation = useUpdateEducation;
|
|
2258
|
+
exports.useUpdateExternalAccount = useUpdateExternalAccount;
|
|
2259
|
+
exports.useUpdatePosition = useUpdatePosition;
|
|
2260
|
+
exports.useUpdateProfileLocation = useUpdateProfileLocation;
|
|
2261
|
+
exports.useUpdateProfileOverride = useUpdateProfileOverride;
|
|
2262
|
+
exports.useUpdateProfileSelf = useUpdateProfileSelf;
|
|
2263
|
+
exports.useUpdateRecord = useUpdateRecord;
|
|
2264
|
+
exports.useUpdateSkill = useUpdateSkill;
|
|
2265
|
+
exports.useUploadAvatar = useUploadAvatar;
|
|
2266
|
+
exports.useVerifyExternalAccount = useVerifyExternalAccount;
|
|
2267
|
+
//# sourceMappingURL=index.cjs.map
|
|
2268
|
+
//# sourceMappingURL=index.cjs.map
|