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