@atproto/bsky 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/config.d.ts +2 -0
  3. package/dist/context.d.ts +3 -0
  4. package/dist/db/index.js.map +1 -1
  5. package/dist/index.js +592 -205
  6. package/dist/index.js.map +3 -3
  7. package/dist/lexicon/index.d.ts +8 -0
  8. package/dist/lexicon/lexicons.d.ts +99 -0
  9. package/dist/lexicon/types/com/atproto/server/confirmEmail.d.ts +27 -0
  10. package/dist/lexicon/types/com/atproto/server/createSession.d.ts +1 -0
  11. package/dist/lexicon/types/com/atproto/server/getSession.d.ts +1 -0
  12. package/dist/lexicon/types/com/atproto/server/requestEmailConfirmation.d.ts +19 -0
  13. package/dist/lexicon/types/com/atproto/server/requestEmailUpdate.d.ts +30 -0
  14. package/dist/lexicon/types/com/atproto/server/updateEmail.d.ts +27 -0
  15. package/dist/services/actor/index.d.ts +2 -2
  16. package/dist/services/util/search.d.ts +3 -3
  17. package/package.json +13 -13
  18. package/src/api/app/bsky/actor/searchActors.ts +36 -22
  19. package/src/api/app/bsky/actor/searchActorsTypeahead.ts +24 -17
  20. package/src/api/app/bsky/graph/getSuggestedFollowsByActor.ts +1 -0
  21. package/src/api/com/atproto/admin/searchRepos.ts +5 -8
  22. package/src/config.ts +7 -0
  23. package/src/context.ts +6 -0
  24. package/src/index.ts +5 -0
  25. package/src/lexicon/index.ts +48 -0
  26. package/src/lexicon/lexicons.ts +122 -0
  27. package/src/lexicon/types/com/atproto/server/confirmEmail.ts +40 -0
  28. package/src/lexicon/types/com/atproto/server/createSession.ts +1 -0
  29. package/src/lexicon/types/com/atproto/server/getSession.ts +1 -0
  30. package/src/lexicon/types/com/atproto/server/requestEmailConfirmation.ts +31 -0
  31. package/src/lexicon/types/com/atproto/server/requestEmailUpdate.ts +43 -0
  32. package/src/lexicon/types/com/atproto/server/updateEmail.ts +41 -0
  33. package/src/services/actor/index.ts +9 -9
  34. package/src/services/util/search.ts +24 -23
@@ -29,6 +29,7 @@ import * as ComAtprotoRepoGetRecord from './types/com/atproto/repo/getRecord';
29
29
  import * as ComAtprotoRepoListRecords from './types/com/atproto/repo/listRecords';
30
30
  import * as ComAtprotoRepoPutRecord from './types/com/atproto/repo/putRecord';
31
31
  import * as ComAtprotoRepoUploadBlob from './types/com/atproto/repo/uploadBlob';
32
+ import * as ComAtprotoServerConfirmEmail from './types/com/atproto/server/confirmEmail';
32
33
  import * as ComAtprotoServerCreateAccount from './types/com/atproto/server/createAccount';
33
34
  import * as ComAtprotoServerCreateAppPassword from './types/com/atproto/server/createAppPassword';
34
35
  import * as ComAtprotoServerCreateInviteCode from './types/com/atproto/server/createInviteCode';
@@ -42,9 +43,12 @@ import * as ComAtprotoServerGetSession from './types/com/atproto/server/getSessi
42
43
  import * as ComAtprotoServerListAppPasswords from './types/com/atproto/server/listAppPasswords';
43
44
  import * as ComAtprotoServerRefreshSession from './types/com/atproto/server/refreshSession';
44
45
  import * as ComAtprotoServerRequestAccountDelete from './types/com/atproto/server/requestAccountDelete';
46
+ import * as ComAtprotoServerRequestEmailConfirmation from './types/com/atproto/server/requestEmailConfirmation';
47
+ import * as ComAtprotoServerRequestEmailUpdate from './types/com/atproto/server/requestEmailUpdate';
45
48
  import * as ComAtprotoServerRequestPasswordReset from './types/com/atproto/server/requestPasswordReset';
46
49
  import * as ComAtprotoServerResetPassword from './types/com/atproto/server/resetPassword';
47
50
  import * as ComAtprotoServerRevokeAppPassword from './types/com/atproto/server/revokeAppPassword';
51
+ import * as ComAtprotoServerUpdateEmail from './types/com/atproto/server/updateEmail';
48
52
  import * as ComAtprotoSyncGetBlob from './types/com/atproto/sync/getBlob';
49
53
  import * as ComAtprotoSyncGetBlocks from './types/com/atproto/sync/getBlocks';
50
54
  import * as ComAtprotoSyncGetCheckout from './types/com/atproto/sync/getCheckout';
@@ -196,6 +200,7 @@ export declare class RepoNS {
196
200
  export declare class ServerNS {
197
201
  _server: Server;
198
202
  constructor(server: Server);
203
+ confirmEmail<AV extends AuthVerifier>(cfg: ConfigOf<AV, ComAtprotoServerConfirmEmail.Handler<ExtractAuth<AV>>, ComAtprotoServerConfirmEmail.HandlerReqCtx<ExtractAuth<AV>>>): void;
199
204
  createAccount<AV extends AuthVerifier>(cfg: ConfigOf<AV, ComAtprotoServerCreateAccount.Handler<ExtractAuth<AV>>, ComAtprotoServerCreateAccount.HandlerReqCtx<ExtractAuth<AV>>>): void;
200
205
  createAppPassword<AV extends AuthVerifier>(cfg: ConfigOf<AV, ComAtprotoServerCreateAppPassword.Handler<ExtractAuth<AV>>, ComAtprotoServerCreateAppPassword.HandlerReqCtx<ExtractAuth<AV>>>): void;
201
206
  createInviteCode<AV extends AuthVerifier>(cfg: ConfigOf<AV, ComAtprotoServerCreateInviteCode.Handler<ExtractAuth<AV>>, ComAtprotoServerCreateInviteCode.HandlerReqCtx<ExtractAuth<AV>>>): void;
@@ -209,9 +214,12 @@ export declare class ServerNS {
209
214
  listAppPasswords<AV extends AuthVerifier>(cfg: ConfigOf<AV, ComAtprotoServerListAppPasswords.Handler<ExtractAuth<AV>>, ComAtprotoServerListAppPasswords.HandlerReqCtx<ExtractAuth<AV>>>): void;
210
215
  refreshSession<AV extends AuthVerifier>(cfg: ConfigOf<AV, ComAtprotoServerRefreshSession.Handler<ExtractAuth<AV>>, ComAtprotoServerRefreshSession.HandlerReqCtx<ExtractAuth<AV>>>): void;
211
216
  requestAccountDelete<AV extends AuthVerifier>(cfg: ConfigOf<AV, ComAtprotoServerRequestAccountDelete.Handler<ExtractAuth<AV>>, ComAtprotoServerRequestAccountDelete.HandlerReqCtx<ExtractAuth<AV>>>): void;
217
+ requestEmailConfirmation<AV extends AuthVerifier>(cfg: ConfigOf<AV, ComAtprotoServerRequestEmailConfirmation.Handler<ExtractAuth<AV>>, ComAtprotoServerRequestEmailConfirmation.HandlerReqCtx<ExtractAuth<AV>>>): void;
218
+ requestEmailUpdate<AV extends AuthVerifier>(cfg: ConfigOf<AV, ComAtprotoServerRequestEmailUpdate.Handler<ExtractAuth<AV>>, ComAtprotoServerRequestEmailUpdate.HandlerReqCtx<ExtractAuth<AV>>>): void;
212
219
  requestPasswordReset<AV extends AuthVerifier>(cfg: ConfigOf<AV, ComAtprotoServerRequestPasswordReset.Handler<ExtractAuth<AV>>, ComAtprotoServerRequestPasswordReset.HandlerReqCtx<ExtractAuth<AV>>>): void;
213
220
  resetPassword<AV extends AuthVerifier>(cfg: ConfigOf<AV, ComAtprotoServerResetPassword.Handler<ExtractAuth<AV>>, ComAtprotoServerResetPassword.HandlerReqCtx<ExtractAuth<AV>>>): void;
214
221
  revokeAppPassword<AV extends AuthVerifier>(cfg: ConfigOf<AV, ComAtprotoServerRevokeAppPassword.Handler<ExtractAuth<AV>>, ComAtprotoServerRevokeAppPassword.HandlerReqCtx<ExtractAuth<AV>>>): void;
222
+ updateEmail<AV extends AuthVerifier>(cfg: ConfigOf<AV, ComAtprotoServerUpdateEmail.Handler<ExtractAuth<AV>>, ComAtprotoServerUpdateEmail.HandlerReqCtx<ExtractAuth<AV>>>): void;
215
223
  }
216
224
  export declare class SyncNS {
217
225
  _server: Server;
@@ -2060,6 +2060,34 @@ export declare const schemaDict: {
2060
2060
  };
2061
2061
  };
2062
2062
  };
2063
+ ComAtprotoServerConfirmEmail: {
2064
+ lexicon: number;
2065
+ id: string;
2066
+ defs: {
2067
+ main: {
2068
+ type: string;
2069
+ description: string;
2070
+ input: {
2071
+ encoding: string;
2072
+ schema: {
2073
+ type: string;
2074
+ required: string[];
2075
+ properties: {
2076
+ email: {
2077
+ type: string;
2078
+ };
2079
+ token: {
2080
+ type: string;
2081
+ };
2082
+ };
2083
+ };
2084
+ };
2085
+ errors: {
2086
+ name: string;
2087
+ }[];
2088
+ };
2089
+ };
2090
+ };
2063
2091
  ComAtprotoServerCreateAccount: {
2064
2092
  lexicon: number;
2065
2093
  id: string;
@@ -2321,6 +2349,9 @@ export declare const schemaDict: {
2321
2349
  email: {
2322
2350
  type: string;
2323
2351
  };
2352
+ emailConfirmed: {
2353
+ type: string;
2354
+ };
2324
2355
  };
2325
2356
  };
2326
2357
  };
@@ -2533,6 +2564,9 @@ export declare const schemaDict: {
2533
2564
  email: {
2534
2565
  type: string;
2535
2566
  };
2567
+ emailConfirmed: {
2568
+ type: string;
2569
+ };
2536
2570
  };
2537
2571
  };
2538
2572
  };
@@ -2627,6 +2661,38 @@ export declare const schemaDict: {
2627
2661
  };
2628
2662
  };
2629
2663
  };
2664
+ ComAtprotoServerRequestEmailConfirmation: {
2665
+ lexicon: number;
2666
+ id: string;
2667
+ defs: {
2668
+ main: {
2669
+ type: string;
2670
+ description: string;
2671
+ };
2672
+ };
2673
+ };
2674
+ ComAtprotoServerRequestEmailUpdate: {
2675
+ lexicon: number;
2676
+ id: string;
2677
+ defs: {
2678
+ main: {
2679
+ type: string;
2680
+ description: string;
2681
+ output: {
2682
+ encoding: string;
2683
+ schema: {
2684
+ type: string;
2685
+ required: string[];
2686
+ properties: {
2687
+ tokenRequired: {
2688
+ type: string;
2689
+ };
2690
+ };
2691
+ };
2692
+ };
2693
+ };
2694
+ };
2695
+ };
2630
2696
  ComAtprotoServerRequestPasswordReset: {
2631
2697
  lexicon: number;
2632
2698
  id: string;
@@ -2699,6 +2765,35 @@ export declare const schemaDict: {
2699
2765
  };
2700
2766
  };
2701
2767
  };
2768
+ ComAtprotoServerUpdateEmail: {
2769
+ lexicon: number;
2770
+ id: string;
2771
+ defs: {
2772
+ main: {
2773
+ type: string;
2774
+ description: string;
2775
+ input: {
2776
+ encoding: string;
2777
+ schema: {
2778
+ type: string;
2779
+ required: string[];
2780
+ properties: {
2781
+ email: {
2782
+ type: string;
2783
+ };
2784
+ token: {
2785
+ type: string;
2786
+ description: string;
2787
+ };
2788
+ };
2789
+ };
2790
+ };
2791
+ errors: {
2792
+ name: string;
2793
+ }[];
2794
+ };
2795
+ };
2796
+ };
2702
2797
  ComAtprotoSyncGetBlob: {
2703
2798
  lexicon: number;
2704
2799
  id: string;
@@ -6836,6 +6931,7 @@ export declare const ids: {
6836
6931
  ComAtprotoRepoPutRecord: string;
6837
6932
  ComAtprotoRepoStrongRef: string;
6838
6933
  ComAtprotoRepoUploadBlob: string;
6934
+ ComAtprotoServerConfirmEmail: string;
6839
6935
  ComAtprotoServerCreateAccount: string;
6840
6936
  ComAtprotoServerCreateAppPassword: string;
6841
6937
  ComAtprotoServerCreateInviteCode: string;
@@ -6850,9 +6946,12 @@ export declare const ids: {
6850
6946
  ComAtprotoServerListAppPasswords: string;
6851
6947
  ComAtprotoServerRefreshSession: string;
6852
6948
  ComAtprotoServerRequestAccountDelete: string;
6949
+ ComAtprotoServerRequestEmailConfirmation: string;
6950
+ ComAtprotoServerRequestEmailUpdate: string;
6853
6951
  ComAtprotoServerRequestPasswordReset: string;
6854
6952
  ComAtprotoServerResetPassword: string;
6855
6953
  ComAtprotoServerRevokeAppPassword: string;
6954
+ ComAtprotoServerUpdateEmail: string;
6856
6955
  ComAtprotoSyncGetBlob: string;
6857
6956
  ComAtprotoSyncGetBlocks: string;
6858
6957
  ComAtprotoSyncGetCheckout: string;
@@ -0,0 +1,27 @@
1
+ import express from 'express';
2
+ import { HandlerAuth } from '@atproto/xrpc-server';
3
+ export interface QueryParams {
4
+ }
5
+ export interface InputSchema {
6
+ email: string;
7
+ token: string;
8
+ [k: string]: unknown;
9
+ }
10
+ export interface HandlerInput {
11
+ encoding: 'application/json';
12
+ body: InputSchema;
13
+ }
14
+ export interface HandlerError {
15
+ status: number;
16
+ message?: string;
17
+ error?: 'AccountNotFound' | 'ExpiredToken' | 'InvalidToken' | 'InvalidEmail';
18
+ }
19
+ export declare type HandlerOutput = HandlerError | void;
20
+ export declare type HandlerReqCtx<HA extends HandlerAuth = never> = {
21
+ auth: HA;
22
+ params: QueryParams;
23
+ input: HandlerInput;
24
+ req: express.Request;
25
+ res: express.Response;
26
+ };
27
+ export declare type Handler<HA extends HandlerAuth = never> = (ctx: HandlerReqCtx<HA>) => Promise<HandlerOutput> | HandlerOutput;
@@ -13,6 +13,7 @@ export interface OutputSchema {
13
13
  handle: string;
14
14
  did: string;
15
15
  email?: string;
16
+ emailConfirmed?: boolean;
16
17
  [k: string]: unknown;
17
18
  }
18
19
  export interface HandlerInput {
@@ -7,6 +7,7 @@ export interface OutputSchema {
7
7
  handle: string;
8
8
  did: string;
9
9
  email?: string;
10
+ emailConfirmed?: boolean;
10
11
  [k: string]: unknown;
11
12
  }
12
13
  export declare type HandlerInput = undefined;
@@ -0,0 +1,19 @@
1
+ import express from 'express';
2
+ import { HandlerAuth } from '@atproto/xrpc-server';
3
+ export interface QueryParams {
4
+ }
5
+ export declare type InputSchema = undefined;
6
+ export declare type HandlerInput = undefined;
7
+ export interface HandlerError {
8
+ status: number;
9
+ message?: string;
10
+ }
11
+ export declare type HandlerOutput = HandlerError | void;
12
+ export declare type HandlerReqCtx<HA extends HandlerAuth = never> = {
13
+ auth: HA;
14
+ params: QueryParams;
15
+ input: HandlerInput;
16
+ req: express.Request;
17
+ res: express.Response;
18
+ };
19
+ export declare type Handler<HA extends HandlerAuth = never> = (ctx: HandlerReqCtx<HA>) => Promise<HandlerOutput> | HandlerOutput;
@@ -0,0 +1,30 @@
1
+ import express from 'express';
2
+ import { HandlerAuth } from '@atproto/xrpc-server';
3
+ export interface QueryParams {
4
+ }
5
+ export declare type InputSchema = undefined;
6
+ export interface OutputSchema {
7
+ tokenRequired: boolean;
8
+ [k: string]: unknown;
9
+ }
10
+ export declare type HandlerInput = undefined;
11
+ export interface HandlerSuccess {
12
+ encoding: 'application/json';
13
+ body: OutputSchema;
14
+ headers?: {
15
+ [key: string]: string;
16
+ };
17
+ }
18
+ export interface HandlerError {
19
+ status: number;
20
+ message?: string;
21
+ }
22
+ export declare type HandlerOutput = HandlerError | HandlerSuccess;
23
+ export declare type HandlerReqCtx<HA extends HandlerAuth = never> = {
24
+ auth: HA;
25
+ params: QueryParams;
26
+ input: HandlerInput;
27
+ req: express.Request;
28
+ res: express.Response;
29
+ };
30
+ export declare type Handler<HA extends HandlerAuth = never> = (ctx: HandlerReqCtx<HA>) => Promise<HandlerOutput> | HandlerOutput;
@@ -0,0 +1,27 @@
1
+ import express from 'express';
2
+ import { HandlerAuth } from '@atproto/xrpc-server';
3
+ export interface QueryParams {
4
+ }
5
+ export interface InputSchema {
6
+ email: string;
7
+ token?: string;
8
+ [k: string]: unknown;
9
+ }
10
+ export interface HandlerInput {
11
+ encoding: 'application/json';
12
+ body: InputSchema;
13
+ }
14
+ export interface HandlerError {
15
+ status: number;
16
+ message?: string;
17
+ error?: 'ExpiredToken' | 'InvalidToken' | 'TokenRequired';
18
+ }
19
+ export declare type HandlerOutput = HandlerError | void;
20
+ export declare type HandlerReqCtx<HA extends HandlerAuth = never> = {
21
+ auth: HA;
22
+ params: QueryParams;
23
+ input: HandlerInput;
24
+ req: express.Request;
25
+ res: express.Response;
26
+ };
27
+ export declare type Handler<HA extends HandlerAuth = never> = (ctx: HandlerReqCtx<HA>) => Promise<HandlerOutput> | HandlerOutput;
@@ -15,10 +15,10 @@ export declare class ActorService {
15
15
  getActorDid(handleOrDid: string): Promise<string | null>;
16
16
  getActor(handleOrDid: string, includeSoftDeleted?: boolean): Promise<ActorResult | null>;
17
17
  getActors(handleOrDids: string[], includeSoftDeleted?: boolean): Promise<ActorResult[]>;
18
- getSearchResults({ cursor, limit, term, includeSoftDeleted, }: {
18
+ getSearchResults({ cursor, limit, query, includeSoftDeleted, }: {
19
19
  cursor?: string;
20
20
  limit?: number;
21
- term?: string;
21
+ query?: string;
22
22
  includeSoftDeleted?: boolean;
23
23
  }): Promise<{
24
24
  results: Actor[];
@@ -1,7 +1,7 @@
1
1
  import { Database } from '../../db';
2
2
  import { GenericKeyset } from '../../db/pagination';
3
3
  export declare const getUserSearchQuery: (db: Database, opts: {
4
- term: string;
4
+ query: string;
5
5
  limit: number;
6
6
  cursor?: string;
7
7
  includeSoftDeleted?: boolean;
@@ -10,13 +10,13 @@ export declare const getUserSearchQuery: (db: Database, opts: {
10
10
  distance: number;
11
11
  }, "results">>, "actor" | "results", {}>;
12
12
  export declare const getUserSearchQuerySimple: (db: Database, opts: {
13
- term: string;
13
+ query: string;
14
14
  limit: number;
15
15
  }) => import("kysely").SelectQueryBuilder<import("kysely/dist/cjs/parser/table-parser").From<import("../../db/database-schema").DatabaseSchemaType, import("kysely").AliasedQueryBuilder<import("kysely/dist/cjs/parser/table-parser").From<import("../../db/database-schema").DatabaseSchemaType, import("kysely").AliasedQueryBuilder<import("kysely/dist/cjs/parser/table-parser").From<import("../../db/database-schema").DatabaseSchemaType, "actor">, "actor", import("kysely").Selection<import("kysely/dist/cjs/parser/table-parser").From<import("../../db/database-schema").DatabaseSchemaType, "actor">, "actor", import("kysely").AliasedRawBuilder<number, "distance"> | import("kysely").AliasedRawBuilder<unknown, "did">>, "accounts_and_profiles">>, "accounts_and_profiles", {
16
16
  did: unknown;
17
17
  distance: number;
18
18
  }, "results">>, "actor" | "results", {}>;
19
- export declare const cleanTerm: (term: string) => string;
19
+ export declare const cleanQuery: (query: string) => string;
20
20
  declare type Result = {
21
21
  distance: number;
22
22
  did: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/bsky",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "license": "MIT",
5
5
  "description": "Reference implementation of app.bsky App View (Bluesky API)",
6
6
  "keywords": [
@@ -36,14 +36,14 @@
36
36
  "sharp": "^0.31.2",
37
37
  "typed-emitter": "^2.1.0",
38
38
  "uint8arrays": "3.0.0",
39
- "@atproto/api": "^0.6.19",
40
- "@atproto/common": "^0.3.0",
39
+ "@atproto/api": "^0.6.20",
40
+ "@atproto/common": "^0.3.1",
41
41
  "@atproto/crypto": "^0.2.2",
42
- "@atproto/syntax": "^0.1.1",
43
- "@atproto/identity": "^0.2.0",
44
- "@atproto/lexicon": "^0.2.1",
45
- "@atproto/repo": "^0.3.1",
46
- "@atproto/xrpc-server": "^0.3.1"
42
+ "@atproto/syntax": "^0.1.2",
43
+ "@atproto/identity": "^0.2.1",
44
+ "@atproto/lexicon": "^0.2.2",
45
+ "@atproto/repo": "^0.3.2",
46
+ "@atproto/xrpc-server": "^0.3.2"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@did-plc/server": "^0.0.1",
@@ -54,11 +54,11 @@
54
54
  "@types/qs": "^6.9.7",
55
55
  "@types/sharp": "^0.31.0",
56
56
  "axios": "^0.27.2",
57
- "@atproto/api": "^0.6.19",
58
- "@atproto/dev-env": "^0.2.10",
59
- "@atproto/lex-cli": "^0.2.1",
60
- "@atproto/pds": "^0.1.19",
61
- "@atproto/xrpc": "^0.3.1"
57
+ "@atproto/api": "^0.6.20",
58
+ "@atproto/dev-env": "^0.2.11",
59
+ "@atproto/lex-cli": "^0.2.2",
60
+ "@atproto/pds": "^0.1.20",
61
+ "@atproto/xrpc": "^0.3.2"
62
62
  },
63
63
  "scripts": {
64
64
  "codegen": "lex gen-server ./src/lexicon ../../lexicons/com/atproto/*/* ../../lexicons/app/bsky/*/*",
@@ -2,7 +2,7 @@ import { sql } from 'kysely'
2
2
  import AppContext from '../../../../context'
3
3
  import { Server } from '../../../../lexicon'
4
4
  import {
5
- cleanTerm,
5
+ cleanQuery,
6
6
  getUserSearchQuery,
7
7
  SearchKeyset,
8
8
  } from '../../../../services/util/search'
@@ -11,37 +11,51 @@ export default function (server: Server, ctx: AppContext) {
11
11
  server.app.bsky.actor.searchActors({
12
12
  auth: ctx.authOptionalVerifier,
13
13
  handler: async ({ auth, params }) => {
14
- let { cursor, limit, term: rawTerm, q: rawQ } = params
14
+ const { cursor, limit } = params
15
15
  const requester = auth.credentials.did
16
-
17
- // prefer new 'q' query param over deprecated 'term'
18
- if (rawQ) {
19
- rawTerm = rawQ
20
- }
21
-
22
- const term = cleanTerm(rawTerm || '')
23
-
16
+ const rawQuery = params.q ?? params.term
17
+ const query = cleanQuery(rawQuery || '')
24
18
  const db = ctx.db.getReplica('search')
25
19
 
26
- const results = term
27
- ? await getUserSearchQuery(db, { term, limit, cursor })
28
- .select('distance')
29
- .selectAll('actor')
30
- .execute()
31
- : []
32
- const keyset = new SearchKeyset(sql``, sql``)
20
+ let results: string[]
21
+ let resCursor: string | undefined
22
+ if (ctx.searchAgent) {
23
+ const res =
24
+ await ctx.searchAgent.api.app.bsky.unspecced.searchActorsSkeleton({
25
+ q: query,
26
+ cursor,
27
+ limit,
28
+ })
29
+ results = res.data.actors.map((a) => a.did)
30
+ resCursor = res.data.cursor
31
+ } else {
32
+ const res = query
33
+ ? await getUserSearchQuery(db, { query, limit, cursor })
34
+ .select('distance')
35
+ .selectAll('actor')
36
+ .execute()
37
+ : []
38
+ results = res.map((a) => a.did)
39
+ const keyset = new SearchKeyset(sql``, sql``)
40
+ resCursor = keyset.packFromResult(res)
41
+ }
33
42
 
34
43
  const actors = await ctx.services
35
44
  .actor(db)
36
- .views.profilesList(results, requester)
37
- const filtered = actors.filter(
38
- (actor) => !actor.viewer?.blocking && !actor.viewer?.blockedBy,
39
- )
45
+ .views.profiles(results, requester)
46
+
47
+ const SKIP = []
48
+ const filtered = results.flatMap((did) => {
49
+ const actor = actors[did]
50
+ if (!actor) return SKIP
51
+ if (actor.viewer?.blocking || actor.viewer?.blockedBy) return SKIP
52
+ return actor
53
+ })
40
54
 
41
55
  return {
42
56
  encoding: 'application/json',
43
57
  body: {
44
- cursor: keyset.packFromResult(results),
58
+ cursor: resCursor,
45
59
  actors: filtered,
46
60
  },
47
61
  }
@@ -1,7 +1,7 @@
1
1
  import AppContext from '../../../../context'
2
2
  import { Server } from '../../../../lexicon'
3
3
  import {
4
- cleanTerm,
4
+ cleanQuery,
5
5
  getUserSearchQuerySimple,
6
6
  } from '../../../../services/util/search'
7
7
 
@@ -9,31 +9,38 @@ export default function (server: Server, ctx: AppContext) {
9
9
  server.app.bsky.actor.searchActorsTypeahead({
10
10
  auth: ctx.authOptionalVerifier,
11
11
  handler: async ({ params, auth }) => {
12
- let { limit, term: rawTerm, q: rawQ } = params
12
+ const { limit } = params
13
13
  const requester = auth.credentials.did
14
-
15
- // prefer new 'q' query param over deprecated 'term'
16
- if (rawQ) {
17
- rawTerm = rawQ
18
- }
19
-
20
- const term = cleanTerm(rawTerm || '')
21
-
14
+ const rawQuery = params.q ?? params.term
15
+ const query = cleanQuery(rawQuery || '')
22
16
  const db = ctx.db.getReplica('search')
23
17
 
24
- const results = term
25
- ? await getUserSearchQuerySimple(db, { term, limit })
26
- .selectAll('actor')
27
- .execute()
28
- : []
18
+ let results: string[]
19
+ if (ctx.searchAgent) {
20
+ const res =
21
+ await ctx.searchAgent.api.app.bsky.unspecced.searchActorsSkeleton({
22
+ q: query,
23
+ typeahead: true,
24
+ limit,
25
+ })
26
+ results = res.data.actors.map((a) => a.did)
27
+ } else {
28
+ const res = query
29
+ ? await getUserSearchQuerySimple(db, { query, limit })
30
+ .selectAll('actor')
31
+ .execute()
32
+ : []
33
+ results = res.map((a) => a.did)
34
+ }
29
35
 
30
36
  const actors = await ctx.services
31
37
  .actor(db)
32
38
  .views.profilesBasic(results, requester, { omitLabels: true })
33
39
 
34
40
  const SKIP = []
35
- const filtered = results.flatMap((res) => {
36
- const actor = actors[res.did]
41
+ const filtered = results.flatMap((did) => {
42
+ const actor = actors[did]
43
+ if (!actor) return SKIP
37
44
  if (actor.viewer?.blocking || actor.viewer?.blockedBy) return SKIP
38
45
  return actor
39
46
  })
@@ -78,6 +78,7 @@ async function getSkeleton(
78
78
  .selectFrom('like')
79
79
  .where('creator', '=', params.actor)
80
80
  .select(sql`split_part(subject, '/', 3)`.as('subjectDid'))
81
+ .orderBy('sortAt', 'desc')
81
82
  .limit(1000) // limit to 1000
82
83
  .as('likes'),
83
84
  )
@@ -8,23 +8,20 @@ export default function (server: Server, ctx: AppContext) {
8
8
  handler: async ({ params }) => {
9
9
  const db = ctx.db.getPrimary()
10
10
  const moderationService = ctx.services.moderation(db)
11
- const { invitedBy } = params
11
+ const { invitedBy, limit, cursor } = params
12
12
  if (invitedBy) {
13
13
  throw new InvalidRequestError('The invitedBy parameter is unsupported')
14
14
  }
15
15
  // prefer new 'q' query param over deprecated 'term'
16
- const { q } = params
17
- if (q) {
18
- params.term = q
19
- }
16
+ const query = params.q ?? params.term
20
17
 
21
- const { results, cursor } = await ctx.services
18
+ const { results, cursor: resCursor } = await ctx.services
22
19
  .actor(db)
23
- .getSearchResults({ ...params, includeSoftDeleted: true })
20
+ .getSearchResults({ query, limit, cursor, includeSoftDeleted: true })
24
21
  return {
25
22
  encoding: 'application/json',
26
23
  body: {
27
- cursor,
24
+ cursor: resCursor,
28
25
  repos: await moderationService.views.repo(results),
29
26
  },
30
27
  }
package/src/config.ts CHANGED
@@ -18,6 +18,7 @@ export interface ServerConfigValues {
18
18
  handleResolveNameservers?: string[]
19
19
  imgUriEndpoint?: string
20
20
  blobCacheLocation?: string
21
+ searchEndpoint?: string
21
22
  labelerDid: string
22
23
  adminPassword: string
23
24
  moderatorPassword?: string
@@ -51,6 +52,7 @@ export class ServerConfig {
51
52
  : []
52
53
  const imgUriEndpoint = process.env.IMG_URI_ENDPOINT
53
54
  const blobCacheLocation = process.env.BLOB_CACHE_LOC
55
+ const searchEndpoint = process.env.SEARCH_ENDPOINT
54
56
  const dbPrimaryPostgresUrl =
55
57
  overrides?.dbPrimaryPostgresUrl || process.env.DB_PRIMARY_POSTGRES_URL
56
58
  let dbReplicaPostgresUrls = overrides?.dbReplicaPostgresUrls
@@ -97,6 +99,7 @@ export class ServerConfig {
97
99
  handleResolveNameservers,
98
100
  imgUriEndpoint,
99
101
  blobCacheLocation,
102
+ searchEndpoint,
100
103
  labelerDid,
101
104
  adminPassword,
102
105
  moderatorPassword,
@@ -183,6 +186,10 @@ export class ServerConfig {
183
186
  return this.cfg.blobCacheLocation
184
187
  }
185
188
 
189
+ get searchEndpoint() {
190
+ return this.cfg.searchEndpoint
191
+ }
192
+
186
193
  get labelerDid() {
187
194
  return this.cfg.labelerDid
188
195
  }
package/src/context.ts CHANGED
@@ -10,6 +10,7 @@ import { BackgroundQueue } from './background'
10
10
  import { MountedAlgos } from './feed-gen/types'
11
11
  import { LabelCache } from './label-cache'
12
12
  import { NotificationServer } from './notifications'
13
+ import { AtpAgent } from '@atproto/api'
13
14
 
14
15
  export class AppContext {
15
16
  constructor(
@@ -22,6 +23,7 @@ export class AppContext {
22
23
  didCache: DidSqlCache
23
24
  labelCache: LabelCache
24
25
  backgroundQueue: BackgroundQueue
26
+ searchAgent?: AtpAgent
25
27
  algos: MountedAlgos
26
28
  notifServer: NotificationServer
27
29
  },
@@ -63,6 +65,10 @@ export class AppContext {
63
65
  return this.opts.notifServer
64
66
  }
65
67
 
68
+ get searchAgent(): AtpAgent | undefined {
69
+ return this.opts.searchAgent
70
+ }
71
+
66
72
  get authVerifier() {
67
73
  return auth.authVerifier(this.idResolver, { aud: this.cfg.serverDid })
68
74
  }