Skip to content

Commit

Permalink
✨ Search accounts by normalized email (bluesky-social#2426)
Browse files Browse the repository at this point in the history
* ✨ Search accounts by email domain works

* ✨ Add Search against normalized email column

* 🐛 Fix pagination

* ✨ Make email field optional in the response

* 🧹 Cleanup implementation

* 🧹 More cleanup

* 🧹 Cleanup and reuse accountView for searchAccounts response

* 📝 Add changeset

* ✨ Add min max and default to limit
  • Loading branch information
foysalit authored Jun 5, 2024
1 parent 8d2d3ac commit 2b21b5b
Show file tree
Hide file tree
Showing 15 changed files with 475 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .changeset/chilled-squids-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@atproto/ozone": patch
"@atproto/bsky": patch
"@atproto/api": patch
"@atproto/pds": patch
---

Add com.atproto.admin.searchAccounts lexicon to allow searching for accounts using email address
40 changes: 40 additions & 0 deletions lexicons/com/atproto/admin/searchAccounts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"lexicon": 1,
"id": "com.atproto.admin.searchAccounts",
"defs": {
"main": {
"type": "query",
"description": "Get list of accounts that matches your search query.",
"parameters": {
"type": "params",
"properties": {
"email": { "type": "string" },
"cursor": { "type": "string" },
"limit": {
"type": "integer",
"minimum": 1,
"maximum": 100,
"default": 50
}
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["accounts"],
"properties": {
"cursor": { "type": "string" },
"accounts": {
"type": "array",
"items": {
"type": "ref",
"ref": "com.atproto.admin.defs#accountView"
}
}
}
}
}
}
}
}
13 changes: 13 additions & 0 deletions packages/api/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as ComAtprotoAdminGetAccountInfo from './types/com/atproto/admin/getAcc
import * as ComAtprotoAdminGetAccountInfos from './types/com/atproto/admin/getAccountInfos'
import * as ComAtprotoAdminGetInviteCodes from './types/com/atproto/admin/getInviteCodes'
import * as ComAtprotoAdminGetSubjectStatus from './types/com/atproto/admin/getSubjectStatus'
import * as ComAtprotoAdminSearchAccounts from './types/com/atproto/admin/searchAccounts'
import * as ComAtprotoAdminSendEmail from './types/com/atproto/admin/sendEmail'
import * as ComAtprotoAdminUpdateAccountEmail from './types/com/atproto/admin/updateAccountEmail'
import * as ComAtprotoAdminUpdateAccountHandle from './types/com/atproto/admin/updateAccountHandle'
Expand Down Expand Up @@ -199,6 +200,7 @@ export * as ComAtprotoAdminGetAccountInfo from './types/com/atproto/admin/getAcc
export * as ComAtprotoAdminGetAccountInfos from './types/com/atproto/admin/getAccountInfos'
export * as ComAtprotoAdminGetInviteCodes from './types/com/atproto/admin/getInviteCodes'
export * as ComAtprotoAdminGetSubjectStatus from './types/com/atproto/admin/getSubjectStatus'
export * as ComAtprotoAdminSearchAccounts from './types/com/atproto/admin/searchAccounts'
export * as ComAtprotoAdminSendEmail from './types/com/atproto/admin/sendEmail'
export * as ComAtprotoAdminUpdateAccountEmail from './types/com/atproto/admin/updateAccountEmail'
export * as ComAtprotoAdminUpdateAccountHandle from './types/com/atproto/admin/updateAccountHandle'
Expand Down Expand Up @@ -570,6 +572,17 @@ export class ComAtprotoAdminNS {
})
}

searchAccounts(
params?: ComAtprotoAdminSearchAccounts.QueryParams,
opts?: ComAtprotoAdminSearchAccounts.CallOptions,
): Promise<ComAtprotoAdminSearchAccounts.Response> {
return this._service.xrpc
.call('com.atproto.admin.searchAccounts', params, undefined, opts)
.catch((e) => {
throw ComAtprotoAdminSearchAccounts.toKnownErr(e)
})
}

sendEmail(
data?: ComAtprotoAdminSendEmail.InputSchema,
opts?: ComAtprotoAdminSendEmail.CallOptions,
Expand Down
47 changes: 47 additions & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,52 @@ export const schemaDict = {
},
},
},
ComAtprotoAdminSearchAccounts: {
lexicon: 1,
id: 'com.atproto.admin.searchAccounts',
defs: {
main: {
type: 'query',
description: 'Get list of accounts that matches your search query.',
parameters: {
type: 'params',
properties: {
email: {
type: 'string',
},
cursor: {
type: 'string',
},
limit: {
type: 'integer',
minimum: 1,
maximum: 100,
default: 50,
},
},
},
output: {
encoding: 'application/json',
schema: {
type: 'object',
required: ['accounts'],
properties: {
cursor: {
type: 'string',
},
accounts: {
type: 'array',
items: {
type: 'ref',
ref: 'lex:com.atproto.admin.defs#accountView',
},
},
},
},
},
},
},
},
ComAtprotoAdminSendEmail: {
lexicon: 1,
id: 'com.atproto.admin.sendEmail',
Expand Down Expand Up @@ -10848,6 +10894,7 @@ export const ids = {
ComAtprotoAdminGetAccountInfos: 'com.atproto.admin.getAccountInfos',
ComAtprotoAdminGetInviteCodes: 'com.atproto.admin.getInviteCodes',
ComAtprotoAdminGetSubjectStatus: 'com.atproto.admin.getSubjectStatus',
ComAtprotoAdminSearchAccounts: 'com.atproto.admin.searchAccounts',
ComAtprotoAdminSendEmail: 'com.atproto.admin.sendEmail',
ComAtprotoAdminUpdateAccountEmail: 'com.atproto.admin.updateAccountEmail',
ComAtprotoAdminUpdateAccountHandle: 'com.atproto.admin.updateAccountHandle',
Expand Down
39 changes: 39 additions & 0 deletions packages/api/src/client/types/com/atproto/admin/searchAccounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* 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'
import * as ComAtprotoAdminDefs from './defs'

export interface QueryParams {
email?: string
cursor?: string
limit?: number
}

export type InputSchema = undefined

export interface OutputSchema {
cursor?: string
accounts: ComAtprotoAdminDefs.AccountView[]
[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
}
12 changes: 12 additions & 0 deletions packages/bsky/src/lexicon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as ComAtprotoAdminGetAccountInfo from './types/com/atproto/admin/getAcc
import * as ComAtprotoAdminGetAccountInfos from './types/com/atproto/admin/getAccountInfos'
import * as ComAtprotoAdminGetInviteCodes from './types/com/atproto/admin/getInviteCodes'
import * as ComAtprotoAdminGetSubjectStatus from './types/com/atproto/admin/getSubjectStatus'
import * as ComAtprotoAdminSearchAccounts from './types/com/atproto/admin/searchAccounts'
import * as ComAtprotoAdminSendEmail from './types/com/atproto/admin/sendEmail'
import * as ComAtprotoAdminUpdateAccountEmail from './types/com/atproto/admin/updateAccountEmail'
import * as ComAtprotoAdminUpdateAccountHandle from './types/com/atproto/admin/updateAccountHandle'
Expand Down Expand Up @@ -323,6 +324,17 @@ export class ComAtprotoAdminNS {
return this._server.xrpc.method(nsid, cfg)
}

searchAccounts<AV extends AuthVerifier>(
cfg: ConfigOf<
AV,
ComAtprotoAdminSearchAccounts.Handler<ExtractAuth<AV>>,
ComAtprotoAdminSearchAccounts.HandlerReqCtx<ExtractAuth<AV>>
>,
) {
const nsid = 'com.atproto.admin.searchAccounts' // @ts-ignore
return this._server.xrpc.method(nsid, cfg)
}

sendEmail<AV extends AuthVerifier>(
cfg: ConfigOf<
AV,
Expand Down
47 changes: 47 additions & 0 deletions packages/bsky/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,52 @@ export const schemaDict = {
},
},
},
ComAtprotoAdminSearchAccounts: {
lexicon: 1,
id: 'com.atproto.admin.searchAccounts',
defs: {
main: {
type: 'query',
description: 'Get list of accounts that matches your search query.',
parameters: {
type: 'params',
properties: {
email: {
type: 'string',
},
cursor: {
type: 'string',
},
limit: {
type: 'integer',
minimum: 1,
maximum: 100,
default: 50,
},
},
},
output: {
encoding: 'application/json',
schema: {
type: 'object',
required: ['accounts'],
properties: {
cursor: {
type: 'string',
},
accounts: {
type: 'array',
items: {
type: 'ref',
ref: 'lex:com.atproto.admin.defs#accountView',
},
},
},
},
},
},
},
},
ComAtprotoAdminSendEmail: {
lexicon: 1,
id: 'com.atproto.admin.sendEmail',
Expand Down Expand Up @@ -9356,6 +9402,7 @@ export const ids = {
ComAtprotoAdminGetAccountInfos: 'com.atproto.admin.getAccountInfos',
ComAtprotoAdminGetInviteCodes: 'com.atproto.admin.getInviteCodes',
ComAtprotoAdminGetSubjectStatus: 'com.atproto.admin.getSubjectStatus',
ComAtprotoAdminSearchAccounts: 'com.atproto.admin.searchAccounts',
ComAtprotoAdminSendEmail: 'com.atproto.admin.sendEmail',
ComAtprotoAdminUpdateAccountEmail: 'com.atproto.admin.updateAccountEmail',
ComAtprotoAdminUpdateAccountHandle: 'com.atproto.admin.updateAccountHandle',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import express from 'express'
import { ValidationResult, BlobRef } from '@atproto/lexicon'
import { lexicons } from '../../../../lexicons'
import { isObj, hasProp } from '../../../../util'
import { CID } from 'multiformats/cid'
import { HandlerAuth, HandlerPipeThrough } from '@atproto/xrpc-server'
import * as ComAtprotoAdminDefs from './defs'

export interface QueryParams {
email?: string
cursor?: string
limit: number
}

export type InputSchema = undefined

export interface OutputSchema {
cursor?: string
accounts: ComAtprotoAdminDefs.AccountView[]
[k: string]: unknown
}

export type HandlerInput = undefined

export interface HandlerSuccess {
encoding: 'application/json'
body: OutputSchema
headers?: { [key: string]: string }
}

export interface HandlerError {
status: number
message?: string
}

export type HandlerOutput = HandlerError | HandlerSuccess | HandlerPipeThrough
export type HandlerReqCtx<HA extends HandlerAuth = never> = {
auth: HA
params: QueryParams
input: HandlerInput
req: express.Request
res: express.Response
}
export type Handler<HA extends HandlerAuth = never> = (
ctx: HandlerReqCtx<HA>,
) => Promise<HandlerOutput> | HandlerOutput
12 changes: 12 additions & 0 deletions packages/ozone/src/lexicon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as ComAtprotoAdminGetAccountInfo from './types/com/atproto/admin/getAcc
import * as ComAtprotoAdminGetAccountInfos from './types/com/atproto/admin/getAccountInfos'
import * as ComAtprotoAdminGetInviteCodes from './types/com/atproto/admin/getInviteCodes'
import * as ComAtprotoAdminGetSubjectStatus from './types/com/atproto/admin/getSubjectStatus'
import * as ComAtprotoAdminSearchAccounts from './types/com/atproto/admin/searchAccounts'
import * as ComAtprotoAdminSendEmail from './types/com/atproto/admin/sendEmail'
import * as ComAtprotoAdminUpdateAccountEmail from './types/com/atproto/admin/updateAccountEmail'
import * as ComAtprotoAdminUpdateAccountHandle from './types/com/atproto/admin/updateAccountHandle'
Expand Down Expand Up @@ -343,6 +344,17 @@ export class ComAtprotoAdminNS {
return this._server.xrpc.method(nsid, cfg)
}

searchAccounts<AV extends AuthVerifier>(
cfg: ConfigOf<
AV,
ComAtprotoAdminSearchAccounts.Handler<ExtractAuth<AV>>,
ComAtprotoAdminSearchAccounts.HandlerReqCtx<ExtractAuth<AV>>
>,
) {
const nsid = 'com.atproto.admin.searchAccounts' // @ts-ignore
return this._server.xrpc.method(nsid, cfg)
}

sendEmail<AV extends AuthVerifier>(
cfg: ConfigOf<
AV,
Expand Down
Loading

0 comments on commit 2b21b5b

Please sign in to comment.