1- import { Client } from '@atproto/lex'
2- import { ensureValidAtIdentifier } from '@atproto/syntax'
1+ import { Client , isAtIdentifierString } from '@atproto/lex'
32import * as blue from '#shared/types/lexicons/blue'
43
54const HEADERS = { 'User-Agent' : 'npmx' }
65
7- // Aggersive cache on identity since that doesn't change a ton
6+ // Aggressive cache on identity since that doesn't change a ton
87const CACHE_MAX_AGE_IDENTITY = CACHE_MAX_AGE_ONE_HOUR * 6
98
109const CACHE_KEY_IDENTITY = ( identity : string ) => `identity:${ identity } `
@@ -24,15 +23,20 @@ export class IdentityUtils {
2423 * @param identifier - A users did or handle
2524 * @returns
2625 */
27- async getMiniDoc ( identifier : string ) : Promise < blue . microcosm . identity . resolveMiniDoc . OutputBody > {
28- ensureValidAtIdentifier ( identifier )
26+ async getMiniDoc (
27+ identifier : string ,
28+ ) : Promise < blue . microcosm . identity . resolveMiniDoc . $OutputBody > {
29+ if ( ! isAtIdentifierString ( identifier ) ) {
30+ throw createError ( { status : 400 , message : 'Invalid AT Protocol identifier' } )
31+ }
2932 const cacheKey = CACHE_KEY_IDENTITY ( identifier )
30- const cached = await this . cache . get < blue . microcosm . identity . resolveMiniDoc . OutputBody > ( cacheKey )
33+ const cached =
34+ await this . cache . get < blue . microcosm . identity . resolveMiniDoc . $OutputBody > ( cacheKey )
3135 if ( cached ) {
3236 return cached
3337 }
3438 const result = await this . slingShotClient . call ( blue . microcosm . identity . resolveMiniDoc , {
35- identifier : identifier ,
39+ identifier,
3640 } )
3741 await this . cache . set ( cacheKey , result , CACHE_MAX_AGE_IDENTITY )
3842 return result
0 commit comments