@singi-labs/sifa-sdk 0.7.0 → 0.7.1

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,176 @@ 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/roadmap.ts
415
+ async function fetchRoadmapVotes(config, options = {}) {
416
+ try {
417
+ return await apiFetch(config, "/api/roadmap/votes", {
418
+ cache: "no-store",
419
+ ...options
420
+ });
421
+ } catch {
422
+ return {};
423
+ }
424
+ }
425
+ async function fetchMyRoadmapVotes(config, options = {}) {
426
+ const headers = { ...options.headers ?? {} };
427
+ if (options.cookieHeader) headers.cookie = options.cookieHeader;
428
+ try {
429
+ const data = await apiFetch(config, "/api/roadmap/votes/me", {
430
+ credentials: "include",
431
+ ...options,
432
+ headers
433
+ });
434
+ return data.voted ?? [];
435
+ } catch {
436
+ return [];
437
+ }
438
+ }
439
+
226
440
  // src/query/keys.ts
227
441
  var sifaQueryKeys = {
228
442
  all: () => ["sifa"],
229
443
  profile: {
230
444
  all: () => ["sifa", "profile"],
231
- byHandle: (handleOrDid) => ["sifa", "profile", handleOrDid]
445
+ byHandle: (handleOrDid) => ["sifa", "profile", handleOrDid],
446
+ atFundLink: (did) => ["sifa", "profile", "at-fund-link", did]
232
447
  },
233
448
  position: {
234
449
  all: () => ["sifa", "position"],
@@ -250,6 +465,39 @@ var sifaQueryKeys = {
250
465
  follow: {
251
466
  all: () => ["sifa", "follow"],
252
467
  following: (opts) => ["sifa", "follow", "following", opts]
468
+ },
469
+ stats: {
470
+ all: () => ["sifa", "stats"],
471
+ homepage: () => ["sifa", "stats", "homepage"]
472
+ },
473
+ apps: {
474
+ all: () => ["sifa", "apps"],
475
+ registry: () => ["sifa", "apps", "registry"],
476
+ hidden: () => ["sifa", "apps", "hidden"]
477
+ },
478
+ activity: {
479
+ all: () => ["sifa", "activity"],
480
+ heatmap: (handleOrDid, days) => ["sifa", "activity", "heatmap", handleOrDid, days],
481
+ teaser: (handleOrDid) => ["sifa", "activity", "teaser", handleOrDid],
482
+ feed: (handleOrDid, opts) => ["sifa", "activity", "feed", handleOrDid, opts]
483
+ },
484
+ endorsement: {
485
+ all: () => ["sifa", "endorsement"],
486
+ count: (did) => ["sifa", "endorsement", "count", did]
487
+ },
488
+ stream: {
489
+ all: () => ["sifa", "stream"],
490
+ networkCount: (did) => ["sifa", "stream", "network-count", did]
491
+ },
492
+ reactions: {
493
+ all: () => ["sifa", "reactions"],
494
+ status: (uris) => ["sifa", "reactions", "status", uris],
495
+ accountCheck: (appId) => ["sifa", "reactions", "account-check", appId]
496
+ },
497
+ roadmap: {
498
+ all: () => ["sifa", "roadmap"],
499
+ votes: () => ["sifa", "roadmap", "votes"],
500
+ myVotes: () => ["sifa", "roadmap", "my-votes"]
253
501
  }
254
502
  };
255
503
 
@@ -263,6 +511,15 @@ function useProfile(handleOrDid, options) {
263
511
  ...options
264
512
  });
265
513
  }
514
+ function useAtFundLink(did, options) {
515
+ const config = useSifaConfig();
516
+ return useQuery({
517
+ queryKey: sifaQueryKeys.profile.atFundLink(did ?? ""),
518
+ queryFn: () => fetchAtFundLink(config, did ?? ""),
519
+ enabled: Boolean(did) && (options?.enabled ?? true),
520
+ ...options
521
+ });
522
+ }
266
523
  function useCreatePosition(ownerDid, options) {
267
524
  const config = useSifaConfig();
268
525
  const queryClient = useQueryClient();
@@ -278,6 +535,30 @@ function useCreatePosition(ownerDid, options) {
278
535
  ...options
279
536
  });
280
537
  }
538
+ function useStats(options) {
539
+ const config = useSifaConfig();
540
+ return useQuery({
541
+ queryKey: sifaQueryKeys.stats.homepage(),
542
+ queryFn: () => fetchStats(config),
543
+ ...options
544
+ });
545
+ }
546
+ function useAppsRegistry(options) {
547
+ const config = useSifaConfig();
548
+ return useQuery({
549
+ queryKey: sifaQueryKeys.apps.registry(),
550
+ queryFn: () => fetchAppsRegistry(config),
551
+ ...options
552
+ });
553
+ }
554
+ function useHiddenApps(options) {
555
+ const config = useSifaConfig();
556
+ return useQuery({
557
+ queryKey: sifaQueryKeys.apps.hidden(),
558
+ queryFn: () => fetchHiddenApps(config),
559
+ ...options
560
+ });
561
+ }
281
562
  function useSearchProfiles(filters, options) {
282
563
  const config = useSifaConfig();
283
564
  return useQuery({
@@ -345,7 +626,85 @@ function useFollowing(opts = {}, options) {
345
626
  ...options
346
627
  });
347
628
  }
629
+ function useHeatmapData(handleOrDid, days, options) {
630
+ const config = useSifaConfig();
631
+ return useQuery({
632
+ queryKey: sifaQueryKeys.activity.heatmap(handleOrDid ?? "", days),
633
+ queryFn: () => fetchHeatmapData(config, handleOrDid ?? "", days),
634
+ enabled: Boolean(handleOrDid) && (options?.enabled ?? true),
635
+ ...options
636
+ });
637
+ }
638
+ function useActivityTeaser(handleOrDid, options) {
639
+ const config = useSifaConfig();
640
+ return useQuery({
641
+ queryKey: sifaQueryKeys.activity.teaser(handleOrDid ?? ""),
642
+ queryFn: () => fetchActivityTeaser(config, handleOrDid ?? ""),
643
+ enabled: Boolean(handleOrDid) && (options?.enabled ?? true),
644
+ ...options
645
+ });
646
+ }
647
+ function useActivityFeed(handleOrDid, opts = {}, options) {
648
+ const config = useSifaConfig();
649
+ return useQuery({
650
+ queryKey: sifaQueryKeys.activity.feed(handleOrDid ?? "", opts),
651
+ queryFn: () => fetchActivityFeed(config, handleOrDid ?? "", opts),
652
+ enabled: Boolean(handleOrDid) && (options?.enabled ?? true),
653
+ ...options
654
+ });
655
+ }
656
+ function useEndorsementCount(did, options) {
657
+ const config = useSifaConfig();
658
+ return useQuery({
659
+ queryKey: sifaQueryKeys.endorsement.count(did ?? ""),
660
+ queryFn: () => fetchEndorsementCount(config, did ?? ""),
661
+ enabled: Boolean(did) && (options?.enabled ?? true),
662
+ ...options
663
+ });
664
+ }
665
+ function useNetworkStreamCount(did, options) {
666
+ const config = useSifaConfig();
667
+ return useQuery({
668
+ queryKey: sifaQueryKeys.stream.networkCount(did ?? ""),
669
+ queryFn: () => fetchNetworkStreamCount(config, did ?? ""),
670
+ enabled: Boolean(did) && (options?.enabled ?? true),
671
+ ...options
672
+ });
673
+ }
674
+ function useReactionStatus(uris, options) {
675
+ const config = useSifaConfig();
676
+ return useQuery({
677
+ queryKey: sifaQueryKeys.reactions.status(uris),
678
+ queryFn: () => fetchReactionStatus(config, uris),
679
+ ...options
680
+ });
681
+ }
682
+ function useAppAccountCheck(appId, options) {
683
+ const config = useSifaConfig();
684
+ return useQuery({
685
+ queryKey: sifaQueryKeys.reactions.accountCheck(appId ?? ""),
686
+ queryFn: () => checkAppAccount(config, appId ?? ""),
687
+ enabled: Boolean(appId) && (options?.enabled ?? true),
688
+ ...options
689
+ });
690
+ }
691
+ function useRoadmapVotes(options) {
692
+ const config = useSifaConfig();
693
+ return useQuery({
694
+ queryKey: sifaQueryKeys.roadmap.votes(),
695
+ queryFn: () => fetchRoadmapVotes(config),
696
+ ...options
697
+ });
698
+ }
699
+ function useMyRoadmapVotes(options) {
700
+ const config = useSifaConfig();
701
+ return useQuery({
702
+ queryKey: sifaQueryKeys.roadmap.myVotes(),
703
+ queryFn: () => fetchMyRoadmapVotes(config),
704
+ ...options
705
+ });
706
+ }
348
707
 
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 };
708
+ export { ApiError, 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, 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
709
  //# sourceMappingURL=index.js.map
351
710
  //# sourceMappingURL=index.js.map