@singi-labs/sifa-sdk 0.10.5 → 0.10.6

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.
@@ -1124,6 +1124,10 @@ var sifaQueryKeys = {
1124
1124
  all: () => ["sifa", "roadmap"],
1125
1125
  votes: () => ["sifa", "roadmap", "votes"],
1126
1126
  myVotes: () => ["sifa", "roadmap", "my-votes"]
1127
+ },
1128
+ bskyPreferences: {
1129
+ all: () => ["sifa", "bsky-preferences"],
1130
+ contentLabels: () => ["sifa", "bsky-preferences", "content-labels"]
1127
1131
  }
1128
1132
  };
1129
1133
 
@@ -2202,6 +2206,83 @@ function useDeleteAccount(options) {
2202
2206
  });
2203
2207
  }
2204
2208
 
2209
+ // src/cards/adult-content.ts
2210
+ var ADULT_CONTENT_LABELS = ["porn", "sexual", "nudity", "graphic-media"];
2211
+
2212
+ // src/query/fetchers/bsky-preferences.ts
2213
+ async function fetchBskyContentLabelPrefs(config, options = {}) {
2214
+ const { onNeedsScope, ...fetchOptions } = options;
2215
+ try {
2216
+ const res = await apiFetch(
2217
+ config,
2218
+ "/api/bsky/preferences/content-labels",
2219
+ { credentials: "include", ...fetchOptions }
2220
+ );
2221
+ return res.contentLabels;
2222
+ } catch (err) {
2223
+ if (err && typeof err === "object" && "status" in err && err.status === 403) {
2224
+ onNeedsScope?.();
2225
+ }
2226
+ return null;
2227
+ }
2228
+ }
2229
+ async function updateBskyContentLabelPrefs(config, body) {
2230
+ const result = await apiWrite(config, "/api/bsky/preferences/content-labels", "PUT", {
2231
+ headers: { "Content-Type": "application/json" },
2232
+ body: JSON.stringify(body)
2233
+ });
2234
+ return result;
2235
+ }
2236
+ function effectiveContentVisibility(label, prefs, isAuthenticated) {
2237
+ if (!isAuthenticated) return "hide";
2238
+ const value = prefs?.[label] ?? null;
2239
+ return value ?? "hide";
2240
+ }
2241
+ function shouldGateAdultMedia(labels, prefs, isAuthenticated) {
2242
+ if (!labels || labels.length === 0) return false;
2243
+ for (const label of labels) {
2244
+ if (label.neg) continue;
2245
+ if (!ADULT_CONTENT_LABELS.includes(label.val)) continue;
2246
+ const visibility = effectiveContentVisibility(
2247
+ label.val,
2248
+ prefs,
2249
+ isAuthenticated
2250
+ );
2251
+ if (visibility !== "ignore") return true;
2252
+ }
2253
+ return false;
2254
+ }
2255
+ function useBskyContentLabelPrefs(options) {
2256
+ const config = useSifaConfig();
2257
+ return reactQuery.useQuery({
2258
+ queryKey: sifaQueryKeys.bskyPreferences.contentLabels(),
2259
+ queryFn: () => fetchBskyContentLabelPrefs(config),
2260
+ // Prefs change rarely; long stale time keeps the gate snappy on
2261
+ // navigation. Invalidation after a write is explicit.
2262
+ staleTime: 5 * 6e4,
2263
+ ...options
2264
+ });
2265
+ }
2266
+ function useUpdateBskyContentLabelPrefs() {
2267
+ const config = useSifaConfig();
2268
+ const queryClient = reactQuery.useQueryClient();
2269
+ return reactQuery.useMutation({
2270
+ mutationFn: (body) => updateBskyContentLabelPrefs(config, body),
2271
+ onSuccess: (result) => {
2272
+ if (result.success && result.contentLabels) {
2273
+ queryClient.setQueryData(
2274
+ sifaQueryKeys.bskyPreferences.contentLabels(),
2275
+ result.contentLabels
2276
+ );
2277
+ } else {
2278
+ void queryClient.invalidateQueries({
2279
+ queryKey: sifaQueryKeys.bskyPreferences.all()
2280
+ });
2281
+ }
2282
+ }
2283
+ });
2284
+ }
2285
+
2205
2286
  exports.ApiError = ApiError;
2206
2287
  exports.HIDDEN_ITEM_SOURCES = HIDDEN_ITEM_SOURCES;
2207
2288
  exports.HIDDEN_ITEM_TYPES = HIDDEN_ITEM_TYPES;
@@ -2236,10 +2317,12 @@ exports.deleteProfileLocation = deleteProfileLocation;
2236
2317
  exports.deleteReaction = deleteReaction;
2237
2318
  exports.deleteRecord = deleteRecord;
2238
2319
  exports.deleteSkill = deleteSkill;
2320
+ exports.effectiveContentVisibility = effectiveContentVisibility;
2239
2321
  exports.fetchActivityFeed = fetchActivityFeed;
2240
2322
  exports.fetchActivityTeaser = fetchActivityTeaser;
2241
2323
  exports.fetchAppsRegistry = fetchAppsRegistry;
2242
2324
  exports.fetchAtFundLink = fetchAtFundLink;
2325
+ exports.fetchBskyContentLabelPrefs = fetchBskyContentLabelPrefs;
2243
2326
  exports.fetchEndorsementCount = fetchEndorsementCount;
2244
2327
  exports.fetchExternalAccounts = fetchExternalAccounts;
2245
2328
  exports.fetchFeaturedProfile = fetchFeaturedProfile;
@@ -2283,6 +2366,7 @@ exports.retractRoadmapVote = retractRoadmapVote;
2283
2366
  exports.searchSkills = searchSkills;
2284
2367
  exports.setExternalAccountPrimary = setExternalAccountPrimary;
2285
2368
  exports.setPositionPrimary = setPositionPrimary;
2369
+ exports.shouldGateAdultMedia = shouldGateAdultMedia;
2286
2370
  exports.sifaQueryKeys = sifaQueryKeys;
2287
2371
  exports.unfollowUser = unfollowUser;
2288
2372
  exports.unhideKeytraceClaim = unhideKeytraceClaim;
@@ -2293,6 +2377,7 @@ exports.unhideStandardPublication = unhideStandardPublication;
2293
2377
  exports.unlinkSkillFromPosition = unlinkSkillFromPosition;
2294
2378
  exports.unsetExternalAccountPrimary = unsetExternalAccountPrimary;
2295
2379
  exports.unsetPositionPrimary = unsetPositionPrimary;
2380
+ exports.updateBskyContentLabelPrefs = updateBskyContentLabelPrefs;
2296
2381
  exports.updateEducation = updateEducation;
2297
2382
  exports.updateExternalAccount = updateExternalAccount;
2298
2383
  exports.updatePosition = updatePosition;
@@ -2309,6 +2394,7 @@ exports.useAppAccountCheck = useAppAccountCheck;
2309
2394
  exports.useAppsRegistry = useAppsRegistry;
2310
2395
  exports.useAtFundLink = useAtFundLink;
2311
2396
  exports.useBlueskySuggestions = useBlueskySuggestions;
2397
+ exports.useBskyContentLabelPrefs = useBskyContentLabelPrefs;
2312
2398
  exports.useBulkHideProfileItems = useBulkHideProfileItems;
2313
2399
  exports.useBulkHideStandardPublications = useBulkHideStandardPublications;
2314
2400
  exports.useBulkUnhideProfileItems = useBulkUnhideProfileItems;
@@ -2379,6 +2465,7 @@ exports.useUnhideStandardPublication = useUnhideStandardPublication;
2379
2465
  exports.useUnlinkSkillFromPosition = useUnlinkSkillFromPosition;
2380
2466
  exports.useUnsetExternalAccountPrimary = useUnsetExternalAccountPrimary;
2381
2467
  exports.useUnsetPositionPrimary = useUnsetPositionPrimary;
2468
+ exports.useUpdateBskyContentLabelPrefs = useUpdateBskyContentLabelPrefs;
2382
2469
  exports.useUpdateEducation = useUpdateEducation;
2383
2470
  exports.useUpdateExternalAccount = useUpdateExternalAccount;
2384
2471
  exports.useUpdatePosition = useUpdatePosition;