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
4 changes: 2 additions & 2 deletions lexicons/fyi/atstore/directory/searchListings.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@
"items": {
"type": "string",
"maxLength": 32,
"knownValues": ["open-source", "donations", "official"]
"knownValues": ["spaces", "open-source", "donations", "official"]
},
"description": "Required extras (all): open-source (has a source link), donations (has a donate link), official (has a product account)."
"description": "Required extras (all): spaces (OAuth client requests ATProto Spaces permissioned data), open-source (has a source link), donations (has a donate link), official (has a product account)."
},
"limit": {
"type": "integer",
Expand Down
4 changes: 4 additions & 0 deletions src/components/ListingOAuthScopesPopoverChip.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type ScopeBucket =
| "repo"
| "blob"
| "api"
| "space"
| "transitional"
| "other";

Expand All @@ -25,6 +26,7 @@ export const BUCKET_LABEL: Record<ScopeBucket, string> = {
repo: "Manage records",
blob: "Files & blobs",
api: "API",
space: "Permissioned spaces",
transitional: "Legacy broad access",
other: "Other",
};
Expand All @@ -35,6 +37,7 @@ const BUCKET_ORDER: Array<ScopeBucket> = [
"repo",
"blob",
"api",
"space",
"transitional",
"other",
];
Expand Down Expand Up @@ -89,6 +92,7 @@ function scopeTokenBucket(token: string): ScopeBucket {
if (res === "repo") return "repo";
if (res === "blob") return "blob";
if (res === "rpc") return "api";
if (res === "space") return "space";
return "other";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import {
computeOAuthLexiconHubData,
getOAuthLexiconHubSnapshot,
} from "#/lib/oauth-lexicon-hub-snapshot.server";
import { PERMISSION_GRANT_SPACES_HEADING } from "#/lib/oauth-permission-grant-ui";
import { oauthClientDistinctTokensFromPublishedScopeLine } from "#/lib/oauth-scope-include-parse";
import {
compareOAuthLexiconKeysForDisplayOrder,
Expand Down Expand Up @@ -185,6 +186,27 @@ function listingPublicWhere(table: typeof dbSchema.storeListings, extra?: SQL) {
return extra ? and(pub, extra) : pub;
}

/**
* The listing's own OAuth client asks for ATProto Spaces (permissioned data): a `space:…` token
* in its published client `scope` line, or an `include:` permission set with a
* `resource: "space"` entry. Deliberately ignores `oauth_scopes_distinct`, which also merges the
* authorization server's `scopes_supported` — a Spaces-capable PDS would flag every app.
*
* Bundle rows probed before the probe knew about spaces fell through to the generic
* "Technical permission" heading followed by a `resource: space.` line, so match that too.
*/
function sqlProbeRequestsSpaces(
probe: typeof dbSchema.storeListingOAuthProbes,
): SQL<boolean> {
const bundleLines =
"$.summary.scopeHumanReadable[*].includePermissionSet.structuredLines[*]";
const spaceBundlePath = `${bundleLines} ? (@ == ${JSON.stringify(PERMISSION_GRANT_SPACES_HEADING)} || @ == "resource: space.")`;
return sql<boolean>`(
coalesce(${probe.clientScopeRawLine} ~* '(^|\\s)space:', false)
or coalesce(${probe.reportJson} @? ${spaceBundlePath}::jsonpath, false)
)`;
}

/** Verified public listings exposed over directory XRPC — must have a published listing.detail AT URI. */
function listingXrpcPublicWhere(
table: typeof dbSchema.storeListings,
Expand Down Expand Up @@ -810,6 +832,11 @@ export interface DirectoryHomePageData {
};
/** Data producers whose records are used by the most apps. */
dataProducers: Array<DirectoryHomeDataProducer>;
/** Apps whose OAuth client asks for ATProto Spaces (permissioned data). */
spaces: {
total: number;
listings: Array<DirectoryListingCard>;
};
}

const CATEGORY_ACCENTS: Array<CategoryAccent> = [
Expand Down Expand Up @@ -1445,6 +1472,7 @@ const HOME_GAME_COUNT = 4;
const HOME_TAG_COUNT = 16;
const HOME_DATA_PRODUCER_COUNT = 8;
const HOME_ICON_STACK_COUNT = 4;
const HOME_SPACES_COUNT = 4;

function requireCards(
cards: Array<DirectoryListingCard>,
Expand Down Expand Up @@ -2118,6 +2146,7 @@ const getHomePageData = createServerFn({ method: "GET" })
browseListings,
configuredHomeHeroRows,
configuredHomePromoRow,
spacesRows,
] = await Promise.all([
context.db
.select(listingSelect)
Expand Down Expand Up @@ -2198,6 +2227,25 @@ const getHomePageData = createServerFn({ method: "GET" })

return row ?? null;
})(),
context.db
.select(listingSelect)
.from(table)
.innerJoin(
context.schema.storeListingOAuthProbes,
eq(context.schema.storeListingOAuthProbes.storeListingId, table.id),
)
.where(
listingPublicWhere(
table,
and(
sqlProbeRequestsSpaces(context.schema.storeListingOAuthProbes),
// `/apps` leaves protocol tooling out; match it so "See all" agrees.
sql`not ${sqlCategorySlugsMatchesLike(table.categorySlugs, "protocol/%")}`,
),
),
)
.orderBy(...orderByPopularListingSort(table))
.limit(HOME_SPACES_COUNT),
]);

if (recentRows.length === 0) {
Expand Down Expand Up @@ -2276,6 +2324,12 @@ const getHomePageData = createServerFn({ method: "GET" })
dataProducers: buildHomeDataProducers(
browseListings.filter((listing) => !isProtocolListing(listing)),
),
spaces: {
total: browseListings.filter(
(listing) => listing.supportsSpaces && !isProtocolListing(listing),
).length,
listings: spacesRows.map((row) => toListingCard(row)),
},
} satisfies DirectoryHomePageData;
});

Expand Down Expand Up @@ -2836,6 +2890,7 @@ async function loadBrowseListings(context: {
createdAt: table.createdAt,
updatedAt: table.updatedAt,
oauthLexiconKeys: probe.oauthLexiconKeys,
supportsSpaces: sqlProbeRequestsSpaces(probe),
})
.from(table)
.leftJoin(probe, eq(probe.storeListingId, table.id))
Expand Down Expand Up @@ -2869,6 +2924,7 @@ async function loadBrowseListings(context: {
hasAtUri: Boolean(row.atUri?.trim()),
hasSourceLink: linkTypes.has("source"),
acceptsDonations: linkTypes.has("donate"),
supportsSpaces: row.supportsSpaces === true,
};
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/lexicons/generated/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,10 @@ export const lexicons = [
items: {
type: "string",
maxLength: 32,
knownValues: ["open-source", "donations", "official"],
knownValues: ["spaces", "open-source", "donations", "official"],
},
description:
"Required extras (all): open-source (has a source link), donations (has a donate link), official (has a product account).",
"Required extras (all): spaces (OAuth client requests ATProto Spaces permissioned data), open-source (has a source link), donations (has a donate link), official (has a product account).",
},
limit: {
type: "integer",
Expand Down
11 changes: 11 additions & 0 deletions src/lib/browse-listings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function listing(overrides: Partial<BrowseListing>): BrowseListing {
hasAtUri: true,
hasSourceLink: false,
acceptsDonations: false,
supportsSpaces: false,
...overrides,
};
}
Expand Down Expand Up @@ -130,6 +131,16 @@ describe("listingMatchesFilters", () => {
]);
});

it("filters to apps that support Spaces", () => {
const forum = listing({ name: "Forum", supportsSpaces: true });
const filters = getBrowseFilters(validateBrowseSearch({ has: "spaces" }));
expect(
[...all, forum]
.filter((l) => listingMatchesFilters(l, filters))
.map((l) => l.name),
).toEqual(["Forum"]);
});

it("matches tags by slug", () => {
expect(match({ tag: "developer" })).toEqual(["Stratos"]);
});
Expand Down
13 changes: 12 additions & 1 deletion src/lib/browse-listings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface BrowseListing {
hasAtUri: boolean;
hasSourceLink: boolean;
acceptsDonations: boolean;
/** OAuth client asks for ATProto Spaces (permissioned data) — `space:` scopes or bundles. */
supportsSpaces: boolean;
}

/** What a result row renders — the server only sends these fields for the current page. */
Expand Down Expand Up @@ -67,10 +69,16 @@ export const BROWSE_SORT_LABELS: Record<BrowseSort, string> = {
alphabetical: "A–Z",
};

export const BROWSE_EXTRAS = ["open-source", "donations", "official"] as const;
export const BROWSE_EXTRAS = [
"spaces",
"open-source",
"donations",
"official",
] as const;
export type BrowseExtra = (typeof BROWSE_EXTRAS)[number];

export const BROWSE_EXTRA_LABELS: Record<BrowseExtra, string> = {
spaces: "Supports Spaces",
"open-source": "Open source",
donations: "Accepts donations",
official: "Has official account",
Expand Down Expand Up @@ -290,6 +298,9 @@ export function listingHasExtra(
extra: BrowseExtra,
): boolean {
switch (extra) {
case "spaces": {
return listing.supportsSpaces;
}
case "open-source": {
return listing.hasSourceLink;
}
Expand Down
51 changes: 51 additions & 0 deletions src/lib/oauth-listing-auth-probe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import {
PERMISSION_GRANT_RECORDS_LIST_LABEL,
PERMISSION_GRANT_REMOTE_ACTIONS_HEADING,
PERMISSION_GRANT_RPC_METHOD_EXPLAINER,
PERMISSION_GRANT_SPACES_HEADING,
PERMISSION_GRANT_SPACE_MANAGE_LIST_LABEL,
PERMISSION_GRANT_SPACE_RECORDS_LIST_LABEL,
PERMISSION_GRANT_UNRECOGNIZED_ENTRY_HEADING,
} from "./oauth-permission-grant-ui";
import {
Expand All @@ -37,6 +40,13 @@ import {
parseRpcScopeForStorefront,
scopeStringToTokens,
} from "./oauth-scope-include-parse";
import {
describeSpaceAuthority,
describeSpaceScope,
describeSpaceType,
parseSpacePermissionSetEntry,
parseSpaceScopeToken,
} from "./oauth-space-scopes";

export { oauthClientDistinctTokensFromPublishedScopeLine } from "./oauth-scope-include-parse";

Expand Down Expand Up @@ -672,6 +682,12 @@ function describeAtprotoScopeToken(token: string): string {
const attr = positional ?? sp.get("attr");
return attr ? `Reads identity · ${attr}` : "Reads identity-linked data.";
}
case "space": {
const parsed = parseSpaceScopeToken(t);
return parsed
? describeSpaceScope(parsed)
: "Access to permissioned spaces.";
}
default: {
return `Technical scope we didn’t summarize: ${token}`;
}
Expand Down Expand Up @@ -874,6 +890,41 @@ function linesForPermissionGrant(
const detail = raw.endsWith(".") ? raw : `${raw}.`;
return [PERMISSION_GRANT_IDENTITY_HEADING, detail];
}
case "space": {
const space = parseSpacePermissionSetEntry(p);
if (!space) {
return [
PERMISSION_GRANT_SPACES_HEADING,
"Details not spelled out here.",
];
}
const out: Array<PermissionGrantStructuredLine> = [
PERMISSION_GRANT_SPACES_HEADING,
`${describeSpaceType(space.spaceType)} · ${describeSpaceAuthority(space.authority)}.`,
];
if (space.collections.length > 0) {
out.push({
kind: "unorderedList",
label: PERMISSION_GRANT_SPACE_RECORDS_LIST_LABEL,
items: space.collections,
});
}
if (space.actions.length > 0) {
out.push({
kind: "unorderedList",
label: PERMISSION_GRANT_ALLOWED_VERBS_LIST_LABEL,
items: space.actions,
});
}
if (space.manage.length > 0) {
out.push({
kind: "unorderedList",
label: PERMISSION_GRANT_SPACE_MANAGE_LIST_LABEL,
items: space.manage,
});
}
return out;
}
default: {
return [
PERMISSION_GRANT_OTHER_TECHNICAL_HEADING,
Expand Down
11 changes: 11 additions & 0 deletions src/lib/oauth-permission-grant-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const PERMISSION_GRANT_RPC_METHOD_EXPLAINER =
"RPC means the app may call specific published API methods on the service below—not arbitrary code on your account.";
export const PERMISSION_GRANT_ACCOUNT_RELATED_HEADING = "Account-related data";
export const PERMISSION_GRANT_IDENTITY_HEADING = "Identity / profile";
/** ATProto Spaces (permissioned data, proposal 0016) — `resource: "space"` bundle rows. */
export const PERMISSION_GRANT_SPACES_HEADING = "Permissioned spaces";
/** Permission row with an unknown `resource` value. */
export const PERMISSION_GRANT_OTHER_TECHNICAL_HEADING = "Technical permission";
/** `type !== "permission"` rows in lexicon bundles. */
Expand All @@ -27,6 +29,14 @@ export const PERMISSION_GRANT_RECORDS_LIST_LABEL = "Records";
export const PERMISSION_GRANT_ALLOWED_VERBS_LIST_LABEL = "Allowed verbs";
/** Subheading for RPC `lxm` names. */
export const PERMISSION_GRANT_BACKEND_CALLS_LIST_LABEL = "API operations";
/**
* Subheading for record collections inside a space grant. Distinct from
* {@link PERMISSION_GRANT_RECORDS_LIST_LABEL} so private space collections never feed the
* public repo lexicon keys (`extractLexiconKeysFromSummaryScopeHumanReadable`).
*/
export const PERMISSION_GRANT_SPACE_RECORDS_LIST_LABEL = "Records in the space";
/** Subheading for space `manage` tokens (operations on the spaces themselves). */
export const PERMISSION_GRANT_SPACE_MANAGE_LIST_LABEL = "Manage spaces";

export interface PermissionGrantUnorderedList {
readonly kind: "unorderedList";
Expand Down Expand Up @@ -74,6 +84,7 @@ export const PERMISSION_GRANT_SECTION_HEADINGS: ReadonlySet<string> = new Set([
PERMISSION_GRANT_REMOTE_ACTIONS_HEADING,
PERMISSION_GRANT_ACCOUNT_RELATED_HEADING,
PERMISSION_GRANT_IDENTITY_HEADING,
PERMISSION_GRANT_SPACES_HEADING,
PERMISSION_GRANT_OTHER_TECHNICAL_HEADING,
PERMISSION_GRANT_UNRECOGNIZED_ENTRY_HEADING,
]);
Loading
Loading