@singi-labs/sifa-sdk 0.11.13 → 0.11.15

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 (38) hide show
  1. package/README.md +43 -0
  2. package/dist/{adult-content-BpZD_3ow.d.cts → adult-content-C0XGPU5A.d.cts} +6 -0
  3. package/dist/{adult-content-BpZD_3ow.d.ts → adult-content-C0XGPU5A.d.ts} +6 -0
  4. package/dist/{feed-DHTy7fUN.d.cts → feed-BaHtJXYR.d.cts} +98 -1
  5. package/dist/{feed-DHTy7fUN.d.ts → feed-BaHtJXYR.d.ts} +98 -1
  6. package/dist/index.cjs +105 -1
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.cts +28 -4
  9. package/dist/index.d.ts +28 -4
  10. package/dist/index.js +97 -2
  11. package/dist/index.js.map +1 -1
  12. package/dist/{keys-DuICaiIq.d.ts → keys-Cdu3x0cr.d.ts} +7 -3
  13. package/dist/{keys-K8kCuA5J.d.cts → keys-DdIxFB-C.d.cts} +7 -3
  14. package/dist/query/fetchers/index.cjs +83 -0
  15. package/dist/query/fetchers/index.cjs.map +1 -1
  16. package/dist/query/fetchers/index.d.cts +23 -5
  17. package/dist/query/fetchers/index.d.ts +23 -5
  18. package/dist/query/fetchers/index.js +81 -1
  19. package/dist/query/fetchers/index.js.map +1 -1
  20. package/dist/query/hooks/index.cjs +118 -0
  21. package/dist/query/hooks/index.cjs.map +1 -1
  22. package/dist/query/hooks/index.d.cts +74 -5
  23. package/dist/query/hooks/index.d.ts +74 -5
  24. package/dist/query/hooks/index.js +116 -2
  25. package/dist/query/hooks/index.js.map +1 -1
  26. package/dist/query/index.cjs +119 -0
  27. package/dist/query/index.cjs.map +1 -1
  28. package/dist/query/index.d.cts +6 -6
  29. package/dist/query/index.d.ts +6 -6
  30. package/dist/query/index.js +114 -2
  31. package/dist/query/index.js.map +1 -1
  32. package/dist/schemas/index.cjs +50 -0
  33. package/dist/schemas/index.cjs.map +1 -1
  34. package/dist/schemas/index.d.cts +2 -1
  35. package/dist/schemas/index.d.ts +2 -1
  36. package/dist/schemas/index.js +46 -1
  37. package/dist/schemas/index.js.map +1 -1
  38. package/package.json +1 -1
@@ -2,6 +2,7 @@
2
2
 
3
3
  var react = require('react');
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
+ var zod = require('zod');
5
6
  var reactQuery = require('@tanstack/react-query');
6
7
 
7
8
  // src/query/client.ts
@@ -594,6 +595,80 @@ async function searchSkills(config, query, limit = 10, options = {}) {
594
595
  return [];
595
596
  }
596
597
  }
598
+ var httpUrlNullable = zod.z.string().refine((s) => /^https?:\/\//i.test(s), { message: "must be an http(s) URL" }).nullable();
599
+ var searchResultCommon = {
600
+ kind: zod.z.string(),
601
+ name: zod.z.string(),
602
+ domain: zod.z.string().nullable(),
603
+ country: zod.z.string().nullable(),
604
+ logoUrl: httpUrlNullable,
605
+ parentName: zod.z.string().nullable()
606
+ };
607
+ var EntitySearchResultSchema = zod.z.discriminatedUnion("source", [
608
+ zod.z.object({
609
+ source: zod.z.literal("entity"),
610
+ entityId: zod.z.number().int().positive(),
611
+ ...searchResultCommon
612
+ }),
613
+ zod.z.object({
614
+ source: zod.z.literal("pdl"),
615
+ pdlId: zod.z.string().min(1),
616
+ ...searchResultCommon
617
+ })
618
+ ]);
619
+ var EntitySearchResponseSchema = zod.z.object({
620
+ results: zod.z.array(EntitySearchResultSchema),
621
+ hasMore: zod.z.boolean()
622
+ });
623
+ zod.z.object({
624
+ entityId: zod.z.number().int().positive().optional(),
625
+ pdlId: zod.z.string().min(1).optional()
626
+ }).refine((v) => v.entityId != null !== (v.pdlId != null), {
627
+ message: "exactly one of entityId or pdlId is required"
628
+ });
629
+ var EntitySelectResponseSchema = zod.z.object({
630
+ entityId: zod.z.number().int().positive(),
631
+ slug: zod.z.string(),
632
+ kind: zod.z.string(),
633
+ canonicalName: zod.z.string(),
634
+ domain: zod.z.string().nullable(),
635
+ entityRef: httpUrlNullable
636
+ });
637
+ var EntityImportSearchResponseSchema = zod.z.object({
638
+ results: zod.z.array(EntitySearchResultSchema)
639
+ });
640
+
641
+ // src/query/fetchers/entities.ts
642
+ var EMPTY_SEARCH2 = { results: [], hasMore: false };
643
+ async function fetchEntitySearch(config, query, limit, options = {}) {
644
+ if (!query.trim()) return EMPTY_SEARCH2;
645
+ const params = new URLSearchParams({ q: query });
646
+ if (limit !== void 0) params.set("limit", String(limit));
647
+ const data = await apiFetch(config, `/api/entities/search?${params.toString()}`, {
648
+ cache: "no-store",
649
+ ...options
650
+ });
651
+ return EntitySearchResponseSchema.parse(data);
652
+ }
653
+ async function selectEntity(config, body, options = {}) {
654
+ const data = await apiFetch(config, "/api/entities/select", {
655
+ method: "POST",
656
+ body,
657
+ credentials: "include",
658
+ ...options
659
+ });
660
+ return EntitySelectResponseSchema.parse(data);
661
+ }
662
+ async function importSearchEntities(config, query, options = {}) {
663
+ if (!query.trim()) return [];
664
+ const data = await apiFetch(config, "/api/entities/import-search", {
665
+ method: "POST",
666
+ body: { q: query },
667
+ credentials: "include",
668
+ ...options
669
+ });
670
+ return EntityImportSearchResponseSchema.parse(data).results;
671
+ }
597
672
 
598
673
  // src/query/fetchers/discovery.ts
599
674
  async function fetchSimilarProfiles(config, did, opts = {}) {
@@ -1141,6 +1216,10 @@ var sifaQueryKeys = {
1141
1216
  canonicalSkills: (query, limit) => ["sifa", "search", "canonical-skills", query, limit],
1142
1217
  filters: () => ["sifa", "search", "filters"]
1143
1218
  },
1219
+ entity: {
1220
+ all: () => ["sifa", "entity"],
1221
+ search: (query, limit) => ["sifa", "entity", "search", query, limit]
1222
+ },
1144
1223
  discovery: {
1145
1224
  all: () => ["sifa", "discovery"],
1146
1225
  similar: (did, limit) => ["sifa", "discovery", "similar", did, limit],
@@ -1925,6 +2004,39 @@ function useSearchFilters(options) {
1925
2004
  ...options
1926
2005
  });
1927
2006
  }
2007
+ function useDebouncedValue(value, delayMs = 250) {
2008
+ const [debounced, setDebounced] = react.useState(value);
2009
+ react.useEffect(() => {
2010
+ const timer = setTimeout(() => setDebounced(value), delayMs);
2011
+ return () => clearTimeout(timer);
2012
+ }, [value, delayMs]);
2013
+ return debounced;
2014
+ }
2015
+ function useEntitySearch(query, opts = {}, queryOptions) {
2016
+ const config = useSifaConfig();
2017
+ const { limit = 5, debounceMs = 250, enabled = true } = opts;
2018
+ const debounced = useDebouncedValue(query.trim(), debounceMs);
2019
+ return reactQuery.useQuery({
2020
+ queryKey: sifaQueryKeys.entity.search(debounced, limit),
2021
+ queryFn: () => fetchEntitySearch(config, debounced, limit),
2022
+ enabled: enabled && debounced.length > 0,
2023
+ ...queryOptions
2024
+ });
2025
+ }
2026
+ function useSelectEntity(options) {
2027
+ const config = useSifaConfig();
2028
+ return reactQuery.useMutation({
2029
+ mutationFn: (body) => selectEntity(config, body),
2030
+ ...options
2031
+ });
2032
+ }
2033
+ function useImportSearchEntities(options) {
2034
+ const config = useSifaConfig();
2035
+ return reactQuery.useMutation({
2036
+ mutationFn: (query) => importSearchEntities(config, query),
2037
+ ...options
2038
+ });
2039
+ }
1928
2040
  function useSimilarProfiles(did, opts = {}, options) {
1929
2041
  const config = useSifaConfig();
1930
2042
  const limit = opts.limit ?? 5;
@@ -2426,6 +2538,7 @@ exports.fetchAppsRegistry = fetchAppsRegistry;
2426
2538
  exports.fetchAtFundLink = fetchAtFundLink;
2427
2539
  exports.fetchBskyContentLabelPrefs = fetchBskyContentLabelPrefs;
2428
2540
  exports.fetchEndorsementCount = fetchEndorsementCount;
2541
+ exports.fetchEntitySearch = fetchEntitySearch;
2429
2542
  exports.fetchExternalAccounts = fetchExternalAccounts;
2430
2543
  exports.fetchFeaturedProfile = fetchFeaturedProfile;
2431
2544
  exports.fetchFollowing = fetchFollowing;
@@ -2456,6 +2569,7 @@ exports.hideOrcidPublication = hideOrcidPublication;
2456
2569
  exports.hideProfileItem = hideProfileItem;
2457
2570
  exports.hideSifaPublication = hideSifaPublication;
2458
2571
  exports.hideStandardPublication = hideStandardPublication;
2572
+ exports.importSearchEntities = importSearchEntities;
2459
2573
  exports.initiateNetworkMapGeneration = initiateNetworkMapGeneration;
2460
2574
  exports.isNetworkMapResponse = isNetworkMapResponse;
2461
2575
  exports.linkSkillToPosition = linkSkillToPosition;
@@ -2468,6 +2582,7 @@ exports.resolveQuotedPosts = resolveQuotedPosts;
2468
2582
  exports.retractRoadmapVote = retractRoadmapVote;
2469
2583
  exports.revealMarqueDomain = revealMarqueDomain;
2470
2584
  exports.searchSkills = searchSkills;
2585
+ exports.selectEntity = selectEntity;
2471
2586
  exports.setExternalAccountPrimary = setExternalAccountPrimary;
2472
2587
  exports.setPositionPrimary = setPositionPrimary;
2473
2588
  exports.shouldGateAdultMedia = shouldGateAdultMedia;
@@ -2514,6 +2629,7 @@ exports.useCreateProfileLocation = useCreateProfileLocation;
2514
2629
  exports.useCreateReaction = useCreateReaction;
2515
2630
  exports.useCreateRecord = useCreateRecord;
2516
2631
  exports.useCreateSkill = useCreateSkill;
2632
+ exports.useDebouncedValue = useDebouncedValue;
2517
2633
  exports.useDeleteAccount = useDeleteAccount;
2518
2634
  exports.useDeleteAvatarOverride = useDeleteAvatarOverride;
2519
2635
  exports.useDeleteEducation = useDeleteEducation;
@@ -2524,6 +2640,7 @@ exports.useDeleteReaction = useDeleteReaction;
2524
2640
  exports.useDeleteRecord = useDeleteRecord;
2525
2641
  exports.useDeleteSkill = useDeleteSkill;
2526
2642
  exports.useEndorsementCount = useEndorsementCount;
2643
+ exports.useEntitySearch = useEntitySearch;
2527
2644
  exports.useExternalAccounts = useExternalAccounts;
2528
2645
  exports.useFeatureAllowlist = useFeatureAllowlist;
2529
2646
  exports.useFeaturedProfile = useFeaturedProfile;
@@ -2539,6 +2656,7 @@ exports.useHideOrcidPublication = useHideOrcidPublication;
2539
2656
  exports.useHideProfileItem = useHideProfileItem;
2540
2657
  exports.useHideSifaPublication = useHideSifaPublication;
2541
2658
  exports.useHideStandardPublication = useHideStandardPublication;
2659
+ exports.useImportSearchEntities = useImportSearchEntities;
2542
2660
  exports.useLinkSkillToPosition = useLinkSkillToPosition;
2543
2661
  exports.useMutuals = useMutuals;
2544
2662
  exports.useMyRoadmapVotes = useMyRoadmapVotes;
@@ -2554,6 +2672,7 @@ exports.useRevealMarqueDomain = useRevealMarqueDomain;
2554
2672
  exports.useRoadmapVotes = useRoadmapVotes;
2555
2673
  exports.useSearchFilters = useSearchFilters;
2556
2674
  exports.useSearchProfiles = useSearchProfiles;
2675
+ exports.useSelectEntity = useSelectEntity;
2557
2676
  exports.useSetExternalAccountPrimary = useSetExternalAccountPrimary;
2558
2677
  exports.useSetPositionPrimary = useSetPositionPrimary;
2559
2678
  exports.useSifaConfig = useSifaConfig;