@singi-labs/sifa-sdk 0.7.0 → 0.7.2

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.
@@ -95,6 +95,19 @@ function fetchProfile(config, handleOrDid, options = {}) {
95
95
  ...options
96
96
  });
97
97
  }
98
+ async function fetchAtFundLink(config, did, options = {}) {
99
+ const path = `/api/profiles/${encodeURIComponent(did)}/at-fund-link`;
100
+ try {
101
+ const data = await apiFetch(config, path, {
102
+ next: { revalidate: 3600 },
103
+ timeoutMs: 5e3,
104
+ ...options
105
+ });
106
+ return typeof data.url === "string" ? data.url : null;
107
+ } catch {
108
+ return null;
109
+ }
110
+ }
98
111
 
99
112
  // src/query/fetchers/positions.ts
100
113
  function createPosition(config, data, options = {}) {
@@ -106,6 +119,44 @@ function createPosition(config, data, options = {}) {
106
119
  });
107
120
  }
108
121
 
122
+ // src/query/fetchers/stats.ts
123
+ async function fetchStats(config, options = {}) {
124
+ try {
125
+ return await apiFetch(config, "/api/stats", {
126
+ next: { revalidate: 900 },
127
+ ...options
128
+ });
129
+ } catch {
130
+ return null;
131
+ }
132
+ }
133
+
134
+ // src/query/fetchers/apps.ts
135
+ async function fetchAppsRegistry(config, options = {}) {
136
+ try {
137
+ return await apiFetch(config, "/api/apps/registry", {
138
+ next: { revalidate: 86400 },
139
+ ...options
140
+ });
141
+ } catch {
142
+ return [];
143
+ }
144
+ }
145
+ async function fetchHiddenApps(config, options = {}) {
146
+ const headers = { ...options.headers ?? {} };
147
+ if (options.cookieHeader) headers.cookie = options.cookieHeader;
148
+ try {
149
+ const data = await apiFetch(config, "/api/profile/hidden-apps", {
150
+ credentials: "include",
151
+ ...options,
152
+ headers
153
+ });
154
+ return data.apps;
155
+ } catch {
156
+ return [];
157
+ }
158
+ }
159
+
109
160
  // src/query/fetchers/search.ts
110
161
  var EMPTY_SEARCH = { profiles: [], total: 0, limit: 20, offset: 0 };
111
162
  var EMPTY_FILTERS = { countries: [], industries: [], apps: [] };
@@ -223,12 +274,211 @@ async function fetchFollowing(config, opts = {}) {
223
274
  }
224
275
  }
225
276
 
277
+ // src/query/fetchers/activity.ts
278
+ async function fetchHeatmapData(config, handleOrDid, days, options = {}) {
279
+ const path = `/api/activity/${encodeURIComponent(handleOrDid)}/heatmap?days=${days}`;
280
+ try {
281
+ return await apiFetch(config, path, {
282
+ next: { revalidate: 900, tags: [`heatmap-${handleOrDid}`] },
283
+ ...options
284
+ });
285
+ } catch {
286
+ return null;
287
+ }
288
+ }
289
+ async function fetchActivityTeaser(config, handleOrDid, options = {}) {
290
+ const headers = { ...options.headers ?? {} };
291
+ if (options.cookieHeader) headers.cookie = options.cookieHeader;
292
+ try {
293
+ return await apiFetch(
294
+ config,
295
+ `/api/activity/${encodeURIComponent(handleOrDid)}/teaser`,
296
+ {
297
+ credentials: "include",
298
+ timeoutMs: 8e3,
299
+ next: { revalidate: 300, tags: [`activity-teaser-${handleOrDid}`] },
300
+ ...options,
301
+ headers
302
+ }
303
+ );
304
+ } catch {
305
+ return null;
306
+ }
307
+ }
308
+ async function fetchActivityFeed(config, handleOrDid, options = {}) {
309
+ const params = new URLSearchParams();
310
+ if (options.category) params.set("category", options.category);
311
+ if (options.limit) params.set("limit", String(options.limit));
312
+ if (options.cursor) params.set("cursor", options.cursor);
313
+ const qs = params.toString();
314
+ const headers = { ...options.headers ?? {} };
315
+ if (options.cookieHeader) headers.cookie = options.cookieHeader;
316
+ try {
317
+ return await apiFetch(
318
+ config,
319
+ `/api/activity/${encodeURIComponent(handleOrDid)}${qs ? `?${qs}` : ""}`,
320
+ {
321
+ credentials: "include",
322
+ cache: "no-store",
323
+ ...options,
324
+ headers
325
+ }
326
+ );
327
+ } catch {
328
+ return null;
329
+ }
330
+ }
331
+
332
+ // src/query/fetchers/endorsement.ts
333
+ async function fetchEndorsementCount(config, did, options = {}) {
334
+ const path = `/api/endorsement/${encodeURIComponent(did)}`;
335
+ try {
336
+ const data = await apiFetch(config, path, {
337
+ cache: "no-store",
338
+ timeoutMs: 5e3,
339
+ ...options
340
+ });
341
+ if (typeof data !== "object" || data === null || !("endorsements" in data)) {
342
+ return 0;
343
+ }
344
+ const endorsements = data.endorsements;
345
+ return Array.isArray(endorsements) ? endorsements.length : 0;
346
+ } catch {
347
+ return 0;
348
+ }
349
+ }
350
+
351
+ // src/query/fetchers/stream.ts
352
+ async function fetchNetworkStreamCount(config, did, options = {}) {
353
+ const headers = { ...options.headers ?? {} };
354
+ if (options.cookieHeader) headers.cookie = options.cookieHeader;
355
+ try {
356
+ const data = await apiFetch(
357
+ config,
358
+ `/api/stream/network?did=${encodeURIComponent(did)}`,
359
+ {
360
+ cache: "no-store",
361
+ timeoutMs: 5e3,
362
+ ...options.cookieHeader ? {} : { credentials: "include" },
363
+ ...options,
364
+ headers
365
+ }
366
+ );
367
+ if (typeof data !== "object" || data === null || !("items" in data)) {
368
+ return 0;
369
+ }
370
+ const items = data.items;
371
+ return Array.isArray(items) ? items.length : 0;
372
+ } catch {
373
+ return 0;
374
+ }
375
+ }
376
+
377
+ // src/query/fetchers/reactions.ts
378
+ async function fetchReactionStatus(config, uris, options = {}) {
379
+ if (uris.length === 0) return {};
380
+ const headers = { ...options.headers ?? {} };
381
+ if (options.cookieHeader) headers.cookie = options.cookieHeader;
382
+ try {
383
+ return await apiFetch(
384
+ config,
385
+ `/api/reactions/status?uris=${encodeURIComponent(uris.join(","))}`,
386
+ {
387
+ credentials: "include",
388
+ ...options,
389
+ headers
390
+ }
391
+ );
392
+ } catch {
393
+ return null;
394
+ }
395
+ }
396
+ async function checkAppAccount(config, appId, options = {}) {
397
+ const headers = { ...options.headers ?? {} };
398
+ if (options.cookieHeader) headers.cookie = options.cookieHeader;
399
+ try {
400
+ return await apiFetch(
401
+ config,
402
+ `/api/reactions/account-check/${encodeURIComponent(appId)}`,
403
+ {
404
+ credentials: "include",
405
+ ...options,
406
+ headers
407
+ }
408
+ );
409
+ } catch {
410
+ return null;
411
+ }
412
+ }
413
+
414
+ // src/query/fetchers/quoted-posts.ts
415
+ var QUOTED_POSTS_BATCH_MAX = 20;
416
+ async function resolveQuotedPosts(config, uris, options = {}) {
417
+ if (uris.length === 0) return {};
418
+ const unique = [...new Set(uris)];
419
+ const batches = [];
420
+ for (let i = 0; i < unique.length; i += QUOTED_POSTS_BATCH_MAX) {
421
+ batches.push(unique.slice(i, i + QUOTED_POSTS_BATCH_MAX));
422
+ }
423
+ const headers = { ...options.headers ?? {} };
424
+ if (options.cookieHeader) headers.cookie = options.cookieHeader;
425
+ const results = {};
426
+ await Promise.all(
427
+ batches.map(async (batch) => {
428
+ try {
429
+ const data = await apiFetch(
430
+ config,
431
+ "/api/quoted-posts/resolve",
432
+ {
433
+ method: "POST",
434
+ body: { uris: batch },
435
+ credentials: "include",
436
+ timeoutMs: 8e3,
437
+ ...options,
438
+ headers
439
+ }
440
+ );
441
+ Object.assign(results, data);
442
+ } catch {
443
+ }
444
+ })
445
+ );
446
+ return results;
447
+ }
448
+
449
+ // src/query/fetchers/roadmap.ts
450
+ async function fetchRoadmapVotes(config, options = {}) {
451
+ try {
452
+ return await apiFetch(config, "/api/roadmap/votes", {
453
+ cache: "no-store",
454
+ ...options
455
+ });
456
+ } catch {
457
+ return {};
458
+ }
459
+ }
460
+ async function fetchMyRoadmapVotes(config, options = {}) {
461
+ const headers = { ...options.headers ?? {} };
462
+ if (options.cookieHeader) headers.cookie = options.cookieHeader;
463
+ try {
464
+ const data = await apiFetch(config, "/api/roadmap/votes/me", {
465
+ credentials: "include",
466
+ ...options,
467
+ headers
468
+ });
469
+ return data.voted ?? [];
470
+ } catch {
471
+ return [];
472
+ }
473
+ }
474
+
226
475
  // src/query/keys.ts
227
476
  var sifaQueryKeys = {
228
477
  all: () => ["sifa"],
229
478
  profile: {
230
479
  all: () => ["sifa", "profile"],
231
- byHandle: (handleOrDid) => ["sifa", "profile", handleOrDid]
480
+ byHandle: (handleOrDid) => ["sifa", "profile", handleOrDid],
481
+ atFundLink: (did) => ["sifa", "profile", "at-fund-link", did]
232
482
  },
233
483
  position: {
234
484
  all: () => ["sifa", "position"],
@@ -250,6 +500,39 @@ var sifaQueryKeys = {
250
500
  follow: {
251
501
  all: () => ["sifa", "follow"],
252
502
  following: (opts) => ["sifa", "follow", "following", opts]
503
+ },
504
+ stats: {
505
+ all: () => ["sifa", "stats"],
506
+ homepage: () => ["sifa", "stats", "homepage"]
507
+ },
508
+ apps: {
509
+ all: () => ["sifa", "apps"],
510
+ registry: () => ["sifa", "apps", "registry"],
511
+ hidden: () => ["sifa", "apps", "hidden"]
512
+ },
513
+ activity: {
514
+ all: () => ["sifa", "activity"],
515
+ heatmap: (handleOrDid, days) => ["sifa", "activity", "heatmap", handleOrDid, days],
516
+ teaser: (handleOrDid) => ["sifa", "activity", "teaser", handleOrDid],
517
+ feed: (handleOrDid, opts) => ["sifa", "activity", "feed", handleOrDid, opts]
518
+ },
519
+ endorsement: {
520
+ all: () => ["sifa", "endorsement"],
521
+ count: (did) => ["sifa", "endorsement", "count", did]
522
+ },
523
+ stream: {
524
+ all: () => ["sifa", "stream"],
525
+ networkCount: (did) => ["sifa", "stream", "network-count", did]
526
+ },
527
+ reactions: {
528
+ all: () => ["sifa", "reactions"],
529
+ status: (uris) => ["sifa", "reactions", "status", uris],
530
+ accountCheck: (appId) => ["sifa", "reactions", "account-check", appId]
531
+ },
532
+ roadmap: {
533
+ all: () => ["sifa", "roadmap"],
534
+ votes: () => ["sifa", "roadmap", "votes"],
535
+ myVotes: () => ["sifa", "roadmap", "my-votes"]
253
536
  }
254
537
  };
255
538
 
@@ -263,6 +546,15 @@ function useProfile(handleOrDid, options) {
263
546
  ...options
264
547
  });
265
548
  }
549
+ function useAtFundLink(did, options) {
550
+ const config = useSifaConfig();
551
+ return useQuery({
552
+ queryKey: sifaQueryKeys.profile.atFundLink(did ?? ""),
553
+ queryFn: () => fetchAtFundLink(config, did ?? ""),
554
+ enabled: Boolean(did) && (options?.enabled ?? true),
555
+ ...options
556
+ });
557
+ }
266
558
  function useCreatePosition(ownerDid, options) {
267
559
  const config = useSifaConfig();
268
560
  const queryClient = useQueryClient();
@@ -278,6 +570,30 @@ function useCreatePosition(ownerDid, options) {
278
570
  ...options
279
571
  });
280
572
  }
573
+ function useStats(options) {
574
+ const config = useSifaConfig();
575
+ return useQuery({
576
+ queryKey: sifaQueryKeys.stats.homepage(),
577
+ queryFn: () => fetchStats(config),
578
+ ...options
579
+ });
580
+ }
581
+ function useAppsRegistry(options) {
582
+ const config = useSifaConfig();
583
+ return useQuery({
584
+ queryKey: sifaQueryKeys.apps.registry(),
585
+ queryFn: () => fetchAppsRegistry(config),
586
+ ...options
587
+ });
588
+ }
589
+ function useHiddenApps(options) {
590
+ const config = useSifaConfig();
591
+ return useQuery({
592
+ queryKey: sifaQueryKeys.apps.hidden(),
593
+ queryFn: () => fetchHiddenApps(config),
594
+ ...options
595
+ });
596
+ }
281
597
  function useSearchProfiles(filters, options) {
282
598
  const config = useSifaConfig();
283
599
  return useQuery({
@@ -345,7 +661,85 @@ function useFollowing(opts = {}, options) {
345
661
  ...options
346
662
  });
347
663
  }
664
+ function useHeatmapData(handleOrDid, days, options) {
665
+ const config = useSifaConfig();
666
+ return useQuery({
667
+ queryKey: sifaQueryKeys.activity.heatmap(handleOrDid ?? "", days),
668
+ queryFn: () => fetchHeatmapData(config, handleOrDid ?? "", days),
669
+ enabled: Boolean(handleOrDid) && (options?.enabled ?? true),
670
+ ...options
671
+ });
672
+ }
673
+ function useActivityTeaser(handleOrDid, options) {
674
+ const config = useSifaConfig();
675
+ return useQuery({
676
+ queryKey: sifaQueryKeys.activity.teaser(handleOrDid ?? ""),
677
+ queryFn: () => fetchActivityTeaser(config, handleOrDid ?? ""),
678
+ enabled: Boolean(handleOrDid) && (options?.enabled ?? true),
679
+ ...options
680
+ });
681
+ }
682
+ function useActivityFeed(handleOrDid, opts = {}, options) {
683
+ const config = useSifaConfig();
684
+ return useQuery({
685
+ queryKey: sifaQueryKeys.activity.feed(handleOrDid ?? "", opts),
686
+ queryFn: () => fetchActivityFeed(config, handleOrDid ?? "", opts),
687
+ enabled: Boolean(handleOrDid) && (options?.enabled ?? true),
688
+ ...options
689
+ });
690
+ }
691
+ function useEndorsementCount(did, options) {
692
+ const config = useSifaConfig();
693
+ return useQuery({
694
+ queryKey: sifaQueryKeys.endorsement.count(did ?? ""),
695
+ queryFn: () => fetchEndorsementCount(config, did ?? ""),
696
+ enabled: Boolean(did) && (options?.enabled ?? true),
697
+ ...options
698
+ });
699
+ }
700
+ function useNetworkStreamCount(did, options) {
701
+ const config = useSifaConfig();
702
+ return useQuery({
703
+ queryKey: sifaQueryKeys.stream.networkCount(did ?? ""),
704
+ queryFn: () => fetchNetworkStreamCount(config, did ?? ""),
705
+ enabled: Boolean(did) && (options?.enabled ?? true),
706
+ ...options
707
+ });
708
+ }
709
+ function useReactionStatus(uris, options) {
710
+ const config = useSifaConfig();
711
+ return useQuery({
712
+ queryKey: sifaQueryKeys.reactions.status(uris),
713
+ queryFn: () => fetchReactionStatus(config, uris),
714
+ ...options
715
+ });
716
+ }
717
+ function useAppAccountCheck(appId, options) {
718
+ const config = useSifaConfig();
719
+ return useQuery({
720
+ queryKey: sifaQueryKeys.reactions.accountCheck(appId ?? ""),
721
+ queryFn: () => checkAppAccount(config, appId ?? ""),
722
+ enabled: Boolean(appId) && (options?.enabled ?? true),
723
+ ...options
724
+ });
725
+ }
726
+ function useRoadmapVotes(options) {
727
+ const config = useSifaConfig();
728
+ return useQuery({
729
+ queryKey: sifaQueryKeys.roadmap.votes(),
730
+ queryFn: () => fetchRoadmapVotes(config),
731
+ ...options
732
+ });
733
+ }
734
+ function useMyRoadmapVotes(options) {
735
+ const config = useSifaConfig();
736
+ return useQuery({
737
+ queryKey: sifaQueryKeys.roadmap.myVotes(),
738
+ queryFn: () => fetchMyRoadmapVotes(config),
739
+ ...options
740
+ });
741
+ }
348
742
 
349
- export { ApiError, SifaProvider, apiFetch, apiFetchOrNull, createPosition, fetchFeaturedProfile, fetchFollowing, fetchProfile, fetchSearchFilters, fetchSearchProfiles, fetchSimilarProfiles, fetchSkillSuggestions, fetchSuggestionCount, fetchSuggestions, sifaQueryKeys, useCreatePosition, useFeaturedProfile, useFollowing, useProfile, useSearchFilters, useSearchProfiles, useSifaConfig, useSimilarProfiles, useSkillSuggestions, useSuggestionCount, useSuggestions };
743
+ export { ApiError, QUOTED_POSTS_BATCH_MAX, SifaProvider, apiFetch, apiFetchOrNull, checkAppAccount, createPosition, fetchActivityFeed, fetchActivityTeaser, fetchAppsRegistry, fetchAtFundLink, fetchEndorsementCount, fetchFeaturedProfile, fetchFollowing, fetchHeatmapData, fetchHiddenApps, fetchMyRoadmapVotes, fetchNetworkStreamCount, fetchProfile, fetchReactionStatus, fetchRoadmapVotes, fetchSearchFilters, fetchSearchProfiles, fetchSimilarProfiles, fetchSkillSuggestions, fetchStats, fetchSuggestionCount, fetchSuggestions, resolveQuotedPosts, sifaQueryKeys, useActivityFeed, useActivityTeaser, useAppAccountCheck, useAppsRegistry, useAtFundLink, useCreatePosition, useEndorsementCount, useFeaturedProfile, useFollowing, useHeatmapData, useHiddenApps, useMyRoadmapVotes, useNetworkStreamCount, useProfile, useReactionStatus, useRoadmapVotes, useSearchFilters, useSearchProfiles, useSifaConfig, useSimilarProfiles, useSkillSuggestions, useStats, useSuggestionCount, useSuggestions };
350
744
  //# sourceMappingURL=index.js.map
351
745
  //# sourceMappingURL=index.js.map