Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
215 changes: 215 additions & 0 deletions src/components/ListingSpacesChip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
"use client";

import * as stylex from "@stylexjs/stylex";
import { Link as RouterLink } from "@tanstack/react-router";
import { ArrowRight, UsersRound } from "lucide-react";
import { Button } from "react-aria-components";

/**
* `<ListingSpacesChip/>` — accent pill beside Scopes that calls out ATProto Spaces
* (permissioned data) support, with a popover listing which spaces the app asks for.
*/
import type { DirectoryListingOAuthProbe } from "../integrations/tanstack-query/api-directory-listings.functions";
import type { ListingSpaceGrant } from "../lib/oauth-space-scopes";

import { Flex } from "../design-system/flex";
import { HoverCard } from "../design-system/hover-card";
import { animationDuration } from "../design-system/theme/animations.stylex";
import { uiColor } from "../design-system/theme/color.stylex";
import { blue } from "../design-system/theme/colors/blue.stylex";
import { radius } from "../design-system/theme/radius.stylex";
import {
gap,
horizontalSpace,
size,
verticalSpace,
} from "../design-system/theme/semantic-spacing.stylex";
import {
fontFamily,
fontSize,
fontWeight,
} from "../design-system/theme/typography.stylex";
import { SmallBody } from "../design-system/typography";
import { Text } from "../design-system/typography/text";
import {
describeSpaceAuthority,
describeSpaceGrantAccess,
summarizeListingSpaces,
} from "../lib/oauth-space-scopes";

const styles = stylex.create({
chip: {
borderColor: {
default: blue.border1,
":hover": blue.border2,
},
borderRadius: radius.full,
borderStyle: "solid",
borderWidth: 1,
paddingInline: 12,
alignItems: "center",
backgroundColor: {
default: blue.component1,
":hover": blue.component2,
},
boxSizing: "border-box",
color: blue.text2,
columnGap: gap.sm,
cursor: "pointer",
display: "inline-flex",
flexShrink: 0,
fontFamily: fontFamily.sans,
fontSize: 13,
fontWeight: 500,
outlineColor: blue.text2,
outlineOffset: 2,
outlineStyle: { default: "none", ":focus-visible": "solid" },
outlineWidth: 2,
transitionDuration: animationDuration.default,
transitionProperty: "border-color, background-color",
height: 30,
},
popoverSurface: {
maxHeight: "min(480px, 78vh)",
maxWidth: "min(432px, 94vw)",
overflowX: "hidden",
overflowY: "auto",
paddingBottom: 0,
paddingLeft: 0,
paddingRight: 0,
paddingTop: 0,
},
header: {
alignItems: "center",
columnGap: gap.xl,
display: "flex",
justifyContent: "space-between",
borderBottomColor: uiColor.border2,
borderBottomStyle: "solid",
borderBottomWidth: 1,
height: size["4xl"],
paddingLeft: horizontalSpace["2xl"],
paddingRight: horizontalSpace["2xl"],
},
moreLink: {
textDecoration: "none",
alignItems: "center",
color: {
default: uiColor.text1,
":hover": uiColor.text2,
},
columnGap: 4,
display: "inline-flex",
fontSize: fontSize.sm,
fontWeight: fontWeight.medium,
whiteSpace: "nowrap",
},
content: {
paddingBottom: verticalSpace["2xl"],
paddingLeft: horizontalSpace["2xl"],
paddingRight: horizontalSpace["2xl"],
paddingTop: verticalSpace["2xl"],
},
list: {
margin: 0,
padding: 0,
listStyle: "none",
display: "flex",
flexDirection: "column",
rowGap: verticalSpace["3xl"],
},
spaceType: {
color: uiColor.text2,
fontFamily: fontFamily.mono,
fontSize: fontSize.sm,
fontWeight: fontWeight.medium,
overflowWrap: "anywhere",
},
anyType: {
fontFamily: fontFamily.sans,
},
});

/** Accent chip shown only when the app's OAuth client asks for Spaces. */
export function ListingSpacesChip({
oauthProbe,
productName,
}: {
oauthProbe: DirectoryListingOAuthProbe | null;
productName: string;
}) {
const summary = oauthProbe ? summarizeListingSpaces(oauthProbe) : null;
if (!summary) return null;

return (
<HoverCard
placement="bottom start"
trigger={
<Button
slot="trigger"
aria-haspopup="dialog"
aria-label={`${productName} supports Spaces: see which spaces it uses`}
{...stylex.props(styles.chip)}
>
<UsersRound aria-hidden size={14} strokeWidth={2} />
<span>Spaces</span>
</Button>
}
style={styles.popoverSurface}
>
<Flex direction="column">
<div {...stylex.props(styles.header)}>
<Text size="base" weight="semibold">
Supports Spaces
</Text>
<RouterLink
to="/apps"
search={{ has: "spaces" }}
{...stylex.props(styles.moreLink)}
>
More apps
<ArrowRight size={14} aria-hidden />
</RouterLink>
</div>
<Flex direction="column" gap="2xl" style={styles.content}>
<SmallBody>
Spaces are the AT Protocol’s permissioned data: records shared with
just the people in a space instead of everyone.
</SmallBody>
{summary.grants.length > 0 ? (
<ul role="list" {...stylex.props(styles.list)}>
{summary.grants.map((grant) => (
<SpaceGrantItem key={JSON.stringify(grant)} grant={grant} />
))}
</ul>
) : null}
{summary.unspecifiedPermissionSets.length > 0 ? (
<SmallBody>
{`Through the ${summary.unspecifiedPermissionSets.join(", ")} permission ${
summary.unspecifiedPermissionSets.length === 1 ? "set" : "sets"
}.`}
</SmallBody>
) : null}
</Flex>
</Flex>
</HoverCard>
);
}

function SpaceGrantItem({ grant }: { grant: ListingSpaceGrant }) {
const isAnyType = grant.spaceType === "*";
return (
<li>
<div {...stylex.props(styles.spaceType, isAnyType && styles.anyType)}>
{isAnyType ? "Any kind of space" : grant.spaceType}
</div>
<SmallBody>
{`${capitalize(describeSpaceAuthority(grant.authority))} · ${describeSpaceGrantAccess(grant)}`}
</SmallBody>
</li>
);
}

function capitalize(text: string) {
return text.charAt(0).toUpperCase() + text.slice(1);
}
27 changes: 20 additions & 7 deletions src/components/shelf/listing/ListingSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import {
getAppTagLinkOptions,
} from "../../../lib/app-tag-metadata";
import { isGameOnlyListing } from "../../../lib/game-listing";
import { summarizeListingSpaces } from "../../../lib/oauth-space-scopes";
import { FundingPopoverChip } from "../../funding-popover-chip";
import { GameFactRows } from "../../GameDetailsPanel";
import { GermNetworkBadge } from "../../GermNetworkBadge";
import { ListingOAuthScopesPopoverChip } from "../../ListingOAuthScopesPopoverChip";
import { listingOAuthScopesPopoverChipShouldRender } from "../../ListingOAuthScopesPopoverChip.logic";
import { ListingSpacesChip } from "../../ListingSpacesChip";
import {
formatListingDate,
getCategoryDisplayLabel,
Expand Down Expand Up @@ -118,6 +120,9 @@ export function ListingSidebar({
listingOAuthScopesPopoverChipShouldRender({
oauthProbe: listing.oauthProbe,
});
const supportsSpaces =
listing.oauthProbe != null &&
summarizeListingSpaces(listing.oauthProbe) != null;
const germHref = listing.germDmHref?.trim() || null;
const hasSource = listing.links.some((link) => link.type === "source");
const hasDonate = listing.links.some((link) => link.type === "donate");
Expand Down Expand Up @@ -210,14 +215,22 @@ export function ListingSidebar({
))}
</DetailRow>
) : null}
{showScopes && website ? (
{(showScopes && website) || supportsSpaces ? (
<DetailRow term="Permissions">
<ListingOAuthScopesPopoverChip
oauthProbe={listing.oauthProbe}
storefrontUrl={website}
devListingId={listing.id}
devListingSlug={productSlug}
/>
{supportsSpaces ? (
<ListingSpacesChip
oauthProbe={listing.oauthProbe}
productName={listing.name}
/>
) : null}
{showScopes && website ? (
<ListingOAuthScopesPopoverChip
oauthProbe={listing.oauthProbe}
storefrontUrl={website}
devListingId={listing.id}
devListingSlug={productSlug}
/>
) : null}
</DetailRow>
) : null}
{hasSource || hasDonate || showFunding || germHref ? (
Expand Down
10 changes: 10 additions & 0 deletions src/lib/oauth-listing-auth-probe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { resolve } from "node:path";
import process from "node:process";

import type { PermissionGrantStructuredLine } from "./oauth-permission-grant-ui";
import type { ParsedSpaceScope } from "./oauth-space-scopes";

import {
PERMISSION_GRANT_ACCOUNT_RELATED_HEADING,
Expand Down Expand Up @@ -963,6 +964,8 @@ export type PermissionLexiconLookup =
title?: string;
detail?: string;
structuredLines: Array<PermissionGrantStructuredLine>;
/** `resource: "space"` entries in the bundle (absent on probes before Spaces support). */
spaceGrants?: Array<ParsedSpaceScope>;
}
| {
resolved: false;
Expand Down Expand Up @@ -1150,6 +1153,13 @@ async function resolveIncludedPermissionLexicon(
title: bundleMain.title,
detail: bundleMain.detail,
structuredLines,
spaceGrants: Array.isArray(perms)
? perms.flatMap((row) =>
row && typeof row === "object" && !Array.isArray(row)
? (parseSpacePermissionSetEntry(row as JsonRecord) ?? [])
: [],
)
: [],
};
lookupCache.set(nsid, out);
return out;
Expand Down
75 changes: 75 additions & 0 deletions src/lib/oauth-space-scopes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
isSpaceScopeToken,
parseSpacePermissionSetEntry,
parseSpaceScopeToken,
summarizeListingSpaces,
} from "./oauth-space-scopes";

describe("isSpaceScopeToken", () => {
Expand Down Expand Up @@ -84,3 +85,77 @@ describe("describeSpaceScope", () => {
);
});
});

type ScopeRow = Parameters<
typeof summarizeListingSpaces
>[0]["scopeHumanReadable"][number];

function resolvedSet(nsid: string, extra: Record<string, unknown>): ScopeRow {
return {
token: `include:${nsid}`,
description: "",
includePermissionSet: {
resolved: true,
nsid,
sourceKind: "remote",
sourceUrl: "https://example.com",
structuredLines: [],
...extra,
},
};
}

describe("summarizeListingSpaces", () => {
it("returns null when the client asks for no spaces", () => {
expect(
summarizeListingSpaces({
oauthClientScopesDistinct: ["atproto", "repo:app.bsky.feed.post"],
clientScopeRawLine: null,
scopeHumanReadable: [],
}),
).toBeNull();
});

it("collects direct tokens and permission-set grants, concrete types first", () => {
const summary = summarizeListingSpaces({
oauthClientScopesDistinct: [],
clientScopeRawLine:
"atproto space:*?action=read_self include:at.secretsky.permissions",
scopeHumanReadable: [
resolvedSet("at.secretsky.permissions", {
spaceGrants: [
{
spaceType: "at.secretsky.feed",
authority: "*",
collections: ["at.secretsky.post"],
actions: ["read", "create"],
manage: [],
},
],
}),
],
});
expect(
summary?.grants.map((g) => [g.spaceType, g.viaPermissionSet]),
).toEqual([
["at.secretsky.feed", "at.secretsky.permissions"],
["*", null],
]);
});

it("flags legacy bundles that use spaces without recorded grants", () => {
const summary = summarizeListingSpaces({
oauthClientScopesDistinct: ["atproto", "include:com.example.perms"],
clientScopeRawLine: null,
scopeHumanReadable: [
resolvedSet("com.example.perms", {
structuredLines: ["Technical permission", "resource: space."],
}),
],
});
expect(summary).toEqual({
grants: [],
unspecifiedPermissionSets: ["com.example.perms"],
});
});
});
Loading
Loading