1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { html } from "https://esm.town/v/postpostscript/html";
import { importModule } from "https://esm.town/v/postpostscript/meta";
import { pathMatches } from "https://esm.town/v/postpostscript/pathAsScope";
export async function authDescribeScopes(scopes: string[]) {
return Promise.all(scopes.map(async (scope) => {
const [author, name, ..._scopeName] = scope.slice(1).split("/");
const scopeName = _scopeName.join("/");
try {
const module = await importModule(`@${author}/${name}`, true);
if (!module.SCOPES) {
return [scope, ""];
}
const { SCOPES } = module;
const value = scopeName in SCOPES
? SCOPES[scopeName]
: Object.entries(SCOPES).find(([key, _]) => {
return pathMatches(scopeName, key);
})?.[1];
if (value.toString() && value.toString().endsWith(".")) {
return [scope, html`${value}.`];
}
return [scope, html`${value}`];
} catch (e) {
console.log("could not fetch scope", scope, e);
}
})).then(res => Object.fromEntries(res.filter(Boolean)));
}