forked from bluesky-social/atproto
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* change pkey on user table to did & rename to user_account * migration * tidy * fixes suggested by bryn * missed merge thing * some updating hanldes scheams * impl + passing test * more handle tests * tidy * update did doc + some new tests * one more test * test handle casing * Fix did pkey down migration --------- Co-authored-by: Devin Ivy <[email protected]>
- Loading branch information
Showing
13 changed files
with
396 additions
and
34 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,20 @@ | ||
{ | ||
"lexicon": 1, | ||
"id": "com.atproto.handle.update", | ||
"defs": { | ||
"main": { | ||
"type": "procedure", | ||
"description": "Updates the handle of the account", | ||
"input": { | ||
"encoding": "application/json", | ||
"schema": { | ||
"type": "object", | ||
"required": ["handle"], | ||
"properties": { | ||
"handle": {"type": "string"} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
packages/api/src/client/types/com/atproto/handle/update.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,31 @@ | ||
/** | ||
* GENERATED CODE - DO NOT MODIFY | ||
*/ | ||
import { Headers, XRPCError } from '@atproto/xrpc' | ||
import { ValidationResult } from '@atproto/lexicon' | ||
import { isObj, hasProp } from '../../../../util' | ||
import { lexicons } from '../../../../lexicons' | ||
|
||
export interface QueryParams {} | ||
|
||
export interface InputSchema { | ||
handle: string | ||
[k: string]: unknown | ||
} | ||
|
||
export interface CallOptions { | ||
headers?: Headers | ||
qp?: QueryParams | ||
encoding: 'application/json' | ||
} | ||
|
||
export interface Response { | ||
success: boolean | ||
headers: Headers | ||
} | ||
|
||
export function toKnownErr(e: any) { | ||
if (e instanceof XRPCError) { | ||
} | ||
return e | ||
} |
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,68 @@ | ||
import { InvalidRequestError } from '@atproto/xrpc-server' | ||
import * as handleLib from '@atproto/handle' | ||
import { Server } from '../../../lexicon' | ||
import AppContext from '../../../context' | ||
import { UserAlreadyExistsError } from '../../../services/actor' | ||
|
||
export default function (server: Server, ctx: AppContext) { | ||
server.com.atproto.handle.resolve(async ({ params }) => { | ||
const handle = params.handle | ||
|
||
let did = '' | ||
if (!handle || handle === ctx.cfg.publicHostname) { | ||
// self | ||
did = ctx.cfg.serverDid | ||
} else { | ||
const supportedHandle = ctx.cfg.availableUserDomains.some((host) => | ||
handle.endsWith(host), | ||
) | ||
if (!supportedHandle) { | ||
throw new InvalidRequestError('Not a supported handle domain') | ||
} | ||
const user = await ctx.services.actor(ctx.db).getUser(handle, true) | ||
if (!user) { | ||
throw new InvalidRequestError('Unable to resolve handle') | ||
} | ||
did = user.did | ||
} | ||
|
||
return { | ||
encoding: 'application/json', | ||
body: { did }, | ||
} | ||
}) | ||
|
||
server.com.atproto.handle.update({ | ||
auth: ctx.accessVerifierCheckTakedown, | ||
handler: async ({ auth, input }) => { | ||
const requester = auth.credentials.did | ||
let handle: string | ||
try { | ||
handle = handleLib.normalizeAndEnsureValid( | ||
input.body.handle, | ||
ctx.cfg.availableUserDomains, | ||
) | ||
} catch (err) { | ||
if (err instanceof handleLib.InvalidHandleError) { | ||
throw new InvalidRequestError(err.message, 'InvalidHandle') | ||
} else if (err instanceof handleLib.ReservedHandleError) { | ||
throw new InvalidRequestError(err.message, 'HandleNotAvailable') | ||
} | ||
throw err | ||
} | ||
|
||
await ctx.db.transaction(async (dbTxn) => { | ||
try { | ||
await ctx.services.actor(dbTxn).updateHandle(requester, handle) | ||
} catch (err) { | ||
if (err instanceof UserAlreadyExistsError) { | ||
throw new InvalidRequestError(`Handle already taken: ${handle}`) | ||
} | ||
throw err | ||
} | ||
|
||
await ctx.plcClient.updateHandle(requester, handle, ctx.keypair) | ||
}) | ||
}, | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
34 changes: 34 additions & 0 deletions
34
packages/pds/src/lexicon/types/com/atproto/handle/update.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,34 @@ | ||
/** | ||
* GENERATED CODE - DO NOT MODIFY | ||
*/ | ||
import express from 'express' | ||
import { ValidationResult } from '@atproto/lexicon' | ||
import { lexicons } from '../../../../lexicons' | ||
import { isObj, hasProp } from '../../../../util' | ||
import { HandlerAuth } from '@atproto/xrpc-server' | ||
|
||
export interface QueryParams {} | ||
|
||
export interface InputSchema { | ||
handle: string | ||
[k: string]: unknown | ||
} | ||
|
||
export interface HandlerInput { | ||
encoding: 'application/json' | ||
body: InputSchema | ||
} | ||
|
||
export interface HandlerError { | ||
status: number | ||
message?: string | ||
} | ||
|
||
export type HandlerOutput = HandlerError | void | ||
export type Handler<HA extends HandlerAuth = never> = (ctx: { | ||
auth: HA | ||
params: QueryParams | ||
input: HandlerInput | ||
req: express.Request | ||
res: express.Response | ||
}) => Promise<HandlerOutput> | HandlerOutput |
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.