-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add describeServer lexicon for ozone
- Loading branch information
Showing
17 changed files
with
621 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"lexicon": 1, | ||
"id": "tools.ozone.server.describeServer", | ||
"defs": { | ||
"main": { | ||
"type": "query", | ||
"description": "Describes the server's configuration.", | ||
"output": { | ||
"encoding": "application/json", | ||
"schema": { | ||
"type": "object", | ||
"required": ["did", "moderators"], | ||
"properties": { | ||
"moderators": { | ||
"type": "array", | ||
"items": { "type": "ref", "ref": "#moderator" }, | ||
"description": "Users that have access to the service and their levels of access." | ||
}, | ||
"did": { | ||
"type": "string", | ||
"format": "did" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"moderator": { | ||
"type": "object", | ||
"properties": { | ||
"did": { "type": "string", "format": "did" }, | ||
"handle": { "type": "string", "format": "handle" }, | ||
"role": { "type": "string", "enum": ["admin", "moderator", "triage"] } | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/api/src/client/types/tools/ozone/server/describeServer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* GENERATED CODE - DO NOT MODIFY | ||
*/ | ||
import { Headers, XRPCError } from '@atproto/xrpc' | ||
import { ValidationResult, BlobRef } from '@atproto/lexicon' | ||
import { isObj, hasProp } from '../../../../util' | ||
import { lexicons } from '../../../../lexicons' | ||
import { CID } from 'multiformats/cid' | ||
|
||
export interface QueryParams {} | ||
|
||
export type InputSchema = undefined | ||
|
||
export interface OutputSchema { | ||
/** Users that have access to the service and their levels of access. */ | ||
moderators: Moderator[] | ||
did: string | ||
/** The URL of the PLC server. */ | ||
plcUrl?: string | ||
/** Configuration used to split subjects in multiple queues. */ | ||
queueConfig?: {} | ||
[k: string]: unknown | ||
} | ||
|
||
export interface CallOptions { | ||
headers?: Headers | ||
} | ||
|
||
export interface Response { | ||
success: boolean | ||
headers: Headers | ||
data: OutputSchema | ||
} | ||
|
||
export function toKnownErr(e: any) { | ||
if (e instanceof XRPCError) { | ||
} | ||
return e | ||
} | ||
|
||
export interface Moderator { | ||
did?: string | ||
handle?: string | ||
role?: 'admin' | 'moderator' | 'triage' | ||
[k: string]: unknown | ||
} | ||
|
||
export function isModerator(v: unknown): v is Moderator { | ||
return ( | ||
isObj(v) && | ||
hasProp(v, '$type') && | ||
v.$type === 'tools.ozone.server.describeServer#moderator' | ||
) | ||
} | ||
|
||
export function validateModerator(v: unknown): ValidationResult { | ||
return lexicons.validate('tools.ozone.server.describeServer#moderator', v) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Server } from '../../lexicon' | ||
import AppContext from '../../context' | ||
import { ToolsOzoneServerDescribeServer } from '@atproto/api' | ||
import { getHandle } from '@atproto/identity' | ||
|
||
const moderatorsCache: Map<string, ToolsOzoneServerDescribeServer.Moderator> = | ||
new Map() | ||
|
||
export default function (server: Server, ctx: AppContext) { | ||
server.tools.ozone.server.describeServer({ | ||
auth: ctx.authVerifier.modOrAdminToken, | ||
handler: async () => { | ||
const getModeratorDetails = async ( | ||
did: string, | ||
role: ToolsOzoneServerDescribeServer.Moderator['role'], | ||
) => { | ||
const fromCache = moderatorsCache.get(did) | ||
if (fromCache) { | ||
return fromCache | ||
} | ||
|
||
const didDoc = await ctx.idResolver.did.resolve(did) | ||
|
||
const handle = didDoc ? getHandle(didDoc) : undefined | ||
const details = { handle, did, role } | ||
moderatorsCache.set(did, details) | ||
return details | ||
} | ||
const moderators: ToolsOzoneServerDescribeServer.Moderator[] = | ||
await Promise.all([ | ||
...ctx.cfg.access.admins.map((did) => | ||
getModeratorDetails(did, 'admin'), | ||
), | ||
...ctx.cfg.access.moderators.map((did) => | ||
getModeratorDetails(did, 'moderator'), | ||
), | ||
...ctx.cfg.access.triage.map((did) => | ||
getModeratorDetails(did, 'triage'), | ||
), | ||
]) | ||
|
||
return { | ||
encoding: 'application/json', | ||
body: { | ||
moderators, | ||
did: ctx.cfg.service.did, | ||
}, | ||
} | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.