desearch-mcp-server 0.6.0 → 0.8.0
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.
- package/CHANGELOG.md +28 -0
- package/README.md +73 -5
- package/build/companies.d.ts +6 -3
- package/build/companies.d.ts.map +1 -1
- package/build/companies.js +8 -4
- package/build/desearch-api.d.ts +36 -0
- package/build/desearch-api.d.ts.map +1 -0
- package/build/desearch-api.js +72 -0
- package/build/people.d.ts +65 -16
- package/build/people.d.ts.map +1 -1
- package/build/people.js +152 -68
- package/build/server.d.ts +4 -1
- package/build/server.d.ts.map +1 -1
- package/build/server.js +281 -6
- package/build/social.d.ts +309 -0
- package/build/social.d.ts.map +1 -0
- package/build/social.js +364 -0
- package/package.json +7 -3
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import type { DesearchApi } from "./desearch-api.js";
|
|
2
|
+
/**
|
|
3
|
+
* TikTok, Facebook, Instagram, YouTube, Reddit, and Threads on the Desearch API
|
|
4
|
+
* (`/desearch/{platform}/*`).
|
|
5
|
+
*
|
|
6
|
+
* desearch-js 1.5 has no social methods, so the `tiktok`, `facebook`, `instagram`,
|
|
7
|
+
* `youtube`, `reddit`, and `threads` tools call these routes through `desearch-api.ts`.
|
|
8
|
+
* Each tool takes an `action` that picks one route; the table below says which
|
|
9
|
+
* arguments each route needs and accepts, and the request is refused before it is
|
|
10
|
+
* sent when they do not match.
|
|
11
|
+
*
|
|
12
|
+
* Paging (desearch-public-api docs/social-pagination.md): a list route answers with a
|
|
13
|
+
* JSON array and, when there is another page, an `x-desearch-next-cursor` header.
|
|
14
|
+
* The caller sends that value back unchanged as `cursor`, on the same route with the
|
|
15
|
+
* same target. The header is absent on the last page. A cursor is opaque and lasts
|
|
16
|
+
* 24 hours; this module never builds or changes one.
|
|
17
|
+
*/
|
|
18
|
+
export declare const SOCIAL_PLATFORMS: readonly ["tiktok", "facebook", "instagram", "youtube", "reddit", "threads"];
|
|
19
|
+
export type SocialPlatform = (typeof SOCIAL_PLATFORMS)[number];
|
|
20
|
+
export declare const NEXT_CURSOR_HEADER = "x-desearch-next-cursor";
|
|
21
|
+
export interface SocialActionSpec {
|
|
22
|
+
method: "GET" | "POST";
|
|
23
|
+
/** Route, with `{name}` for each path argument. */
|
|
24
|
+
path: string;
|
|
25
|
+
/** Arguments the route needs. */
|
|
26
|
+
required: readonly string[];
|
|
27
|
+
/** Other arguments the route accepts. `cursor` here means the route pages. */
|
|
28
|
+
optional: readonly string[];
|
|
29
|
+
/** The route answers with a list of items. */
|
|
30
|
+
list?: true;
|
|
31
|
+
/** Values an argument may take on this action, when the tool's schema allows more. */
|
|
32
|
+
choices?: Readonly<Record<string, readonly string[]>>;
|
|
33
|
+
}
|
|
34
|
+
export declare const SOCIAL_ACTIONS: {
|
|
35
|
+
readonly tiktok: {
|
|
36
|
+
readonly search: {
|
|
37
|
+
readonly method: "POST";
|
|
38
|
+
readonly path: "/desearch/tiktok/search";
|
|
39
|
+
readonly required: readonly ["query"];
|
|
40
|
+
readonly optional: readonly ["count", "sort", "cursor"];
|
|
41
|
+
readonly list: true;
|
|
42
|
+
};
|
|
43
|
+
readonly post: {
|
|
44
|
+
readonly method: "GET";
|
|
45
|
+
readonly path: "/desearch/tiktok/post/{id}";
|
|
46
|
+
readonly required: readonly ["id"];
|
|
47
|
+
readonly optional: readonly [];
|
|
48
|
+
};
|
|
49
|
+
readonly profile: {
|
|
50
|
+
readonly method: "GET";
|
|
51
|
+
readonly path: "/desearch/tiktok/profile/{username}";
|
|
52
|
+
readonly required: readonly ["username"];
|
|
53
|
+
readonly optional: readonly [];
|
|
54
|
+
};
|
|
55
|
+
readonly profile_posts: {
|
|
56
|
+
readonly method: "GET";
|
|
57
|
+
readonly path: "/desearch/tiktok/profile/{username}/posts";
|
|
58
|
+
readonly required: readonly ["username"];
|
|
59
|
+
readonly optional: readonly ["count", "cursor"];
|
|
60
|
+
readonly list: true;
|
|
61
|
+
};
|
|
62
|
+
readonly comments: {
|
|
63
|
+
readonly method: "GET";
|
|
64
|
+
readonly path: "/desearch/tiktok/comments/{video_id}";
|
|
65
|
+
readonly required: readonly ["video_id"];
|
|
66
|
+
readonly optional: readonly ["count", "cursor"];
|
|
67
|
+
readonly list: true;
|
|
68
|
+
};
|
|
69
|
+
readonly hashtag: {
|
|
70
|
+
readonly method: "GET";
|
|
71
|
+
readonly path: "/desearch/tiktok/hashtag/{tag}";
|
|
72
|
+
readonly required: readonly ["tag"];
|
|
73
|
+
readonly optional: readonly ["count", "cursor"];
|
|
74
|
+
readonly list: true;
|
|
75
|
+
};
|
|
76
|
+
readonly trending: {
|
|
77
|
+
readonly method: "GET";
|
|
78
|
+
readonly path: "/desearch/tiktok/trending";
|
|
79
|
+
readonly required: readonly [];
|
|
80
|
+
readonly optional: readonly ["region", "count"];
|
|
81
|
+
readonly list: true;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
readonly facebook: {
|
|
85
|
+
readonly search: {
|
|
86
|
+
readonly method: "POST";
|
|
87
|
+
readonly path: "/desearch/facebook/search";
|
|
88
|
+
readonly required: readonly ["query"];
|
|
89
|
+
readonly optional: readonly ["count", "cursor"];
|
|
90
|
+
readonly list: true;
|
|
91
|
+
};
|
|
92
|
+
readonly post: {
|
|
93
|
+
readonly method: "GET";
|
|
94
|
+
readonly path: "/desearch/facebook/post/{id}";
|
|
95
|
+
readonly required: readonly ["id"];
|
|
96
|
+
readonly optional: readonly [];
|
|
97
|
+
};
|
|
98
|
+
readonly profile: {
|
|
99
|
+
readonly method: "GET";
|
|
100
|
+
readonly path: "/desearch/facebook/profile/{profile_id}";
|
|
101
|
+
readonly required: readonly ["profile_id"];
|
|
102
|
+
readonly optional: readonly [];
|
|
103
|
+
};
|
|
104
|
+
readonly profile_posts: {
|
|
105
|
+
readonly method: "GET";
|
|
106
|
+
readonly path: "/desearch/facebook/profile/{profile_id}/posts";
|
|
107
|
+
readonly required: readonly ["profile_id"];
|
|
108
|
+
readonly optional: readonly ["count", "cursor"];
|
|
109
|
+
readonly list: true;
|
|
110
|
+
};
|
|
111
|
+
readonly comments: {
|
|
112
|
+
readonly method: "GET";
|
|
113
|
+
readonly path: "/desearch/facebook/comments/{post_id}";
|
|
114
|
+
readonly required: readonly ["post_id"];
|
|
115
|
+
readonly optional: readonly ["count", "cursor"];
|
|
116
|
+
readonly list: true;
|
|
117
|
+
};
|
|
118
|
+
readonly hashtag: {
|
|
119
|
+
readonly method: "GET";
|
|
120
|
+
readonly path: "/desearch/facebook/hashtag/{tag}";
|
|
121
|
+
readonly required: readonly ["tag"];
|
|
122
|
+
readonly optional: readonly ["count", "cursor"];
|
|
123
|
+
readonly list: true;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
readonly instagram: {
|
|
127
|
+
readonly search: {
|
|
128
|
+
readonly method: "POST";
|
|
129
|
+
readonly path: "/desearch/instagram/search";
|
|
130
|
+
readonly required: readonly ["query"];
|
|
131
|
+
readonly optional: readonly ["count"];
|
|
132
|
+
readonly list: true;
|
|
133
|
+
};
|
|
134
|
+
readonly media: {
|
|
135
|
+
readonly method: "GET";
|
|
136
|
+
readonly path: "/desearch/instagram/media/{id}";
|
|
137
|
+
readonly required: readonly ["id"];
|
|
138
|
+
readonly optional: readonly [];
|
|
139
|
+
};
|
|
140
|
+
readonly profile: {
|
|
141
|
+
readonly method: "GET";
|
|
142
|
+
readonly path: "/desearch/instagram/profile/{username}";
|
|
143
|
+
readonly required: readonly ["username"];
|
|
144
|
+
readonly optional: readonly [];
|
|
145
|
+
};
|
|
146
|
+
readonly profile_posts: {
|
|
147
|
+
readonly method: "GET";
|
|
148
|
+
readonly path: "/desearch/instagram/profile/{username}/posts";
|
|
149
|
+
readonly required: readonly ["username"];
|
|
150
|
+
readonly optional: readonly ["count", "cursor"];
|
|
151
|
+
readonly list: true;
|
|
152
|
+
};
|
|
153
|
+
readonly comments: {
|
|
154
|
+
readonly method: "GET";
|
|
155
|
+
readonly path: "/desearch/instagram/comments/{shortcode}";
|
|
156
|
+
readonly required: readonly ["shortcode"];
|
|
157
|
+
readonly optional: readonly ["count", "cursor"];
|
|
158
|
+
readonly list: true;
|
|
159
|
+
};
|
|
160
|
+
readonly hashtag: {
|
|
161
|
+
readonly method: "GET";
|
|
162
|
+
readonly path: "/desearch/instagram/hashtag/{tag}";
|
|
163
|
+
readonly required: readonly ["tag"];
|
|
164
|
+
readonly optional: readonly ["count", "cursor"];
|
|
165
|
+
readonly list: true;
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
readonly youtube: {
|
|
169
|
+
readonly search: {
|
|
170
|
+
readonly method: "POST";
|
|
171
|
+
readonly path: "/desearch/youtube/search";
|
|
172
|
+
readonly required: readonly ["query"];
|
|
173
|
+
readonly optional: readonly ["type", "upload_date", "sort_by", "duration", "cursor"];
|
|
174
|
+
readonly list: true;
|
|
175
|
+
};
|
|
176
|
+
readonly video: {
|
|
177
|
+
readonly method: "GET";
|
|
178
|
+
readonly path: "/desearch/youtube/video/{id}";
|
|
179
|
+
readonly required: readonly ["id"];
|
|
180
|
+
readonly optional: readonly [];
|
|
181
|
+
};
|
|
182
|
+
readonly transcript: {
|
|
183
|
+
readonly method: "GET";
|
|
184
|
+
readonly path: "/desearch/youtube/transcript/{video_id}";
|
|
185
|
+
readonly required: readonly ["video_id"];
|
|
186
|
+
readonly optional: readonly ["language"];
|
|
187
|
+
};
|
|
188
|
+
readonly comments: {
|
|
189
|
+
readonly method: "GET";
|
|
190
|
+
readonly path: "/desearch/youtube/comments/{video_id}";
|
|
191
|
+
readonly required: readonly ["video_id"];
|
|
192
|
+
readonly optional: readonly ["order", "cursor"];
|
|
193
|
+
readonly list: true;
|
|
194
|
+
};
|
|
195
|
+
readonly channel: {
|
|
196
|
+
readonly method: "GET";
|
|
197
|
+
readonly path: "/desearch/youtube/channel/{handle}";
|
|
198
|
+
readonly required: readonly ["handle"];
|
|
199
|
+
readonly optional: readonly [];
|
|
200
|
+
};
|
|
201
|
+
readonly channel_videos: {
|
|
202
|
+
readonly method: "GET";
|
|
203
|
+
readonly path: "/desearch/youtube/channel/{handle}/videos";
|
|
204
|
+
readonly required: readonly ["handle"];
|
|
205
|
+
readonly optional: readonly ["sort", "cursor"];
|
|
206
|
+
readonly list: true;
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
readonly reddit: {
|
|
210
|
+
readonly search: {
|
|
211
|
+
readonly method: "POST";
|
|
212
|
+
readonly path: "/desearch/reddit/search";
|
|
213
|
+
readonly required: readonly ["query"];
|
|
214
|
+
readonly optional: readonly ["sort", "timeframe", "cursor"];
|
|
215
|
+
readonly list: true;
|
|
216
|
+
readonly choices: {
|
|
217
|
+
readonly sort: readonly ["relevance", "new", "top", "comment_count"];
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
readonly subreddit: {
|
|
221
|
+
readonly method: "GET";
|
|
222
|
+
readonly path: "/desearch/reddit/subreddit/{name}";
|
|
223
|
+
readonly required: readonly ["name"];
|
|
224
|
+
readonly optional: readonly [];
|
|
225
|
+
};
|
|
226
|
+
readonly subreddit_posts: {
|
|
227
|
+
readonly method: "GET";
|
|
228
|
+
readonly path: "/desearch/reddit/subreddit/{name}/posts";
|
|
229
|
+
readonly required: readonly ["name"];
|
|
230
|
+
readonly optional: readonly ["sort", "timeframe", "cursor"];
|
|
231
|
+
readonly list: true;
|
|
232
|
+
readonly choices: {
|
|
233
|
+
readonly sort: readonly ["best", "hot", "new", "top", "rising"];
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
readonly post: {
|
|
237
|
+
readonly method: "GET";
|
|
238
|
+
readonly path: "/desearch/reddit/post/{id}";
|
|
239
|
+
readonly required: readonly ["id"];
|
|
240
|
+
readonly optional: readonly [];
|
|
241
|
+
};
|
|
242
|
+
readonly comments: {
|
|
243
|
+
readonly method: "GET";
|
|
244
|
+
readonly path: "/desearch/reddit/comments/{post_id}";
|
|
245
|
+
readonly required: readonly ["post_id"];
|
|
246
|
+
readonly optional: readonly ["cursor"];
|
|
247
|
+
readonly list: true;
|
|
248
|
+
};
|
|
249
|
+
};
|
|
250
|
+
readonly threads: {
|
|
251
|
+
readonly search: {
|
|
252
|
+
readonly method: "POST";
|
|
253
|
+
readonly path: "/desearch/threads/search";
|
|
254
|
+
readonly required: readonly ["query"];
|
|
255
|
+
readonly optional: readonly ["start_date", "end_date"];
|
|
256
|
+
readonly list: true;
|
|
257
|
+
};
|
|
258
|
+
readonly search_users: {
|
|
259
|
+
readonly method: "POST";
|
|
260
|
+
readonly path: "/desearch/threads/search/users";
|
|
261
|
+
readonly required: readonly ["query"];
|
|
262
|
+
readonly optional: readonly [];
|
|
263
|
+
readonly list: true;
|
|
264
|
+
};
|
|
265
|
+
readonly profile: {
|
|
266
|
+
readonly method: "GET";
|
|
267
|
+
readonly path: "/desearch/threads/profile/{username}";
|
|
268
|
+
readonly required: readonly ["username"];
|
|
269
|
+
readonly optional: readonly [];
|
|
270
|
+
};
|
|
271
|
+
readonly profile_posts: {
|
|
272
|
+
readonly method: "GET";
|
|
273
|
+
readonly path: "/desearch/threads/profile/{username}/posts";
|
|
274
|
+
readonly required: readonly ["username"];
|
|
275
|
+
readonly optional: readonly [];
|
|
276
|
+
readonly list: true;
|
|
277
|
+
};
|
|
278
|
+
readonly post: {
|
|
279
|
+
readonly method: "GET";
|
|
280
|
+
readonly path: "/desearch/threads/post/{id}";
|
|
281
|
+
readonly required: readonly ["id"];
|
|
282
|
+
readonly optional: readonly [];
|
|
283
|
+
};
|
|
284
|
+
};
|
|
285
|
+
};
|
|
286
|
+
export type SocialAction<P extends SocialPlatform> = keyof (typeof SOCIAL_ACTIONS)[P] & string;
|
|
287
|
+
/** Action names in table order, for the tool's `action` enum. */
|
|
288
|
+
export declare function socialActionNames<P extends SocialPlatform>(platform: P): [SocialAction<P>, ...SocialAction<P>[]];
|
|
289
|
+
/** "video_id (required), count, cursor" */
|
|
290
|
+
export declare function socialActionUsage(platform: SocialPlatform, action: string): string;
|
|
291
|
+
/**
|
|
292
|
+
* The route and arguments for one call. Throws before any request when a needed
|
|
293
|
+
* argument is missing or an argument does not apply to the action.
|
|
294
|
+
*/
|
|
295
|
+
export declare function socialRequest(platform: SocialPlatform, args: Record<string, unknown>): {
|
|
296
|
+
spec: SocialActionSpec;
|
|
297
|
+
path: string;
|
|
298
|
+
values: Record<string, string | number>;
|
|
299
|
+
};
|
|
300
|
+
/** One sentence on how to get the next page. */
|
|
301
|
+
export declare function socialNextStep(platform: SocialPlatform, action: string, spec: SocialActionSpec, nextCursor: string | null): string;
|
|
302
|
+
/**
|
|
303
|
+
* Run one social action. A single post, profile, media item, video, transcript,
|
|
304
|
+
* channel, or subreddit comes back as the API sent it. A list comes back as
|
|
305
|
+
* `{ results, next_cursor, next }`: `next_cursor` is the `x-desearch-next-cursor`
|
|
306
|
+
* header (null on the last page) and `next` says how to ask for the next page.
|
|
307
|
+
*/
|
|
308
|
+
export declare function runSocialAction(call: DesearchApi, platform: SocialPlatform, args: Record<string, unknown>): Promise<unknown>;
|
|
309
|
+
//# sourceMappingURL=social.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"social.d.ts","sourceRoot":"","sources":["../social.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;;;;;;;;;;;;GAeG;AAEH,eAAO,MAAM,gBAAgB,8EAA+E,CAAC;AAC7G,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/D,eAAO,MAAM,kBAAkB,2BAA2B,CAAC;AAE3D,MAAM,WAAW,gBAAgB;IAC7B,MAAM,EAAE,KAAK,GAAG,MAAM,CAAC;IACvB,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,8EAA8E;IAC9E,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,8CAA8C;IAC9C,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,sFAAsF;IACtF,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;CACzD;AAED,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuMkD,CAAC;AAE9E,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,cAAc,IAAI,MAAM,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;AAE/F,iEAAiE;AACjE,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,cAAc,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAEhH;AAOD,2CAA2C;AAC3C,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAOlF;AA+CD;;;GAGG;AACH,wBAAgB,aAAa,CACzB,QAAQ,EAAE,cAAc,EACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;CAAE,CA0DnF;AAED,gDAAgD;AAChD,wBAAgB,cAAc,CAC1B,QAAQ,EAAE,cAAc,EACxB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,gBAAgB,EACtB,UAAU,EAAE,MAAM,GAAG,IAAI,GAC1B,MAAM,CASR;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACjC,IAAI,EAAE,WAAW,EACjB,QAAQ,EAAE,cAAc,EACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,OAAO,CAAC,OAAO,CAAC,CAclB"}
|
package/build/social.js
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TikTok, Facebook, Instagram, YouTube, Reddit, and Threads on the Desearch API
|
|
3
|
+
* (`/desearch/{platform}/*`).
|
|
4
|
+
*
|
|
5
|
+
* desearch-js 1.5 has no social methods, so the `tiktok`, `facebook`, `instagram`,
|
|
6
|
+
* `youtube`, `reddit`, and `threads` tools call these routes through `desearch-api.ts`.
|
|
7
|
+
* Each tool takes an `action` that picks one route; the table below says which
|
|
8
|
+
* arguments each route needs and accepts, and the request is refused before it is
|
|
9
|
+
* sent when they do not match.
|
|
10
|
+
*
|
|
11
|
+
* Paging (desearch-public-api docs/social-pagination.md): a list route answers with a
|
|
12
|
+
* JSON array and, when there is another page, an `x-desearch-next-cursor` header.
|
|
13
|
+
* The caller sends that value back unchanged as `cursor`, on the same route with the
|
|
14
|
+
* same target. The header is absent on the last page. A cursor is opaque and lasts
|
|
15
|
+
* 24 hours; this module never builds or changes one.
|
|
16
|
+
*/
|
|
17
|
+
export const SOCIAL_PLATFORMS = ["tiktok", "facebook", "instagram", "youtube", "reddit", "threads"];
|
|
18
|
+
export const NEXT_CURSOR_HEADER = "x-desearch-next-cursor";
|
|
19
|
+
export const SOCIAL_ACTIONS = {
|
|
20
|
+
tiktok: {
|
|
21
|
+
search: {
|
|
22
|
+
method: "POST",
|
|
23
|
+
path: "/desearch/tiktok/search",
|
|
24
|
+
required: ["query"],
|
|
25
|
+
optional: ["count", "sort", "cursor"],
|
|
26
|
+
list: true,
|
|
27
|
+
},
|
|
28
|
+
post: { method: "GET", path: "/desearch/tiktok/post/{id}", required: ["id"], optional: [] },
|
|
29
|
+
profile: { method: "GET", path: "/desearch/tiktok/profile/{username}", required: ["username"], optional: [] },
|
|
30
|
+
profile_posts: {
|
|
31
|
+
method: "GET",
|
|
32
|
+
path: "/desearch/tiktok/profile/{username}/posts",
|
|
33
|
+
required: ["username"],
|
|
34
|
+
optional: ["count", "cursor"],
|
|
35
|
+
list: true,
|
|
36
|
+
},
|
|
37
|
+
comments: {
|
|
38
|
+
method: "GET",
|
|
39
|
+
path: "/desearch/tiktok/comments/{video_id}",
|
|
40
|
+
required: ["video_id"],
|
|
41
|
+
optional: ["count", "cursor"],
|
|
42
|
+
list: true,
|
|
43
|
+
},
|
|
44
|
+
hashtag: {
|
|
45
|
+
method: "GET",
|
|
46
|
+
path: "/desearch/tiktok/hashtag/{tag}",
|
|
47
|
+
required: ["tag"],
|
|
48
|
+
optional: ["count", "cursor"],
|
|
49
|
+
list: true,
|
|
50
|
+
},
|
|
51
|
+
trending: {
|
|
52
|
+
method: "GET",
|
|
53
|
+
path: "/desearch/tiktok/trending",
|
|
54
|
+
required: [],
|
|
55
|
+
optional: ["region", "count"],
|
|
56
|
+
list: true,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
facebook: {
|
|
60
|
+
search: {
|
|
61
|
+
method: "POST",
|
|
62
|
+
path: "/desearch/facebook/search",
|
|
63
|
+
required: ["query"],
|
|
64
|
+
optional: ["count", "cursor"],
|
|
65
|
+
list: true,
|
|
66
|
+
},
|
|
67
|
+
post: { method: "GET", path: "/desearch/facebook/post/{id}", required: ["id"], optional: [] },
|
|
68
|
+
profile: {
|
|
69
|
+
method: "GET",
|
|
70
|
+
path: "/desearch/facebook/profile/{profile_id}",
|
|
71
|
+
required: ["profile_id"],
|
|
72
|
+
optional: [],
|
|
73
|
+
},
|
|
74
|
+
profile_posts: {
|
|
75
|
+
method: "GET",
|
|
76
|
+
path: "/desearch/facebook/profile/{profile_id}/posts",
|
|
77
|
+
required: ["profile_id"],
|
|
78
|
+
optional: ["count", "cursor"],
|
|
79
|
+
list: true,
|
|
80
|
+
},
|
|
81
|
+
comments: {
|
|
82
|
+
method: "GET",
|
|
83
|
+
path: "/desearch/facebook/comments/{post_id}",
|
|
84
|
+
required: ["post_id"],
|
|
85
|
+
optional: ["count", "cursor"],
|
|
86
|
+
list: true,
|
|
87
|
+
},
|
|
88
|
+
hashtag: {
|
|
89
|
+
method: "GET",
|
|
90
|
+
path: "/desearch/facebook/hashtag/{tag}",
|
|
91
|
+
required: ["tag"],
|
|
92
|
+
optional: ["count", "cursor"],
|
|
93
|
+
list: true,
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
instagram: {
|
|
97
|
+
// Instagram search returns one page; the API answers 422 to any cursor.
|
|
98
|
+
search: {
|
|
99
|
+
method: "POST",
|
|
100
|
+
path: "/desearch/instagram/search",
|
|
101
|
+
required: ["query"],
|
|
102
|
+
optional: ["count"],
|
|
103
|
+
list: true,
|
|
104
|
+
},
|
|
105
|
+
media: { method: "GET", path: "/desearch/instagram/media/{id}", required: ["id"], optional: [] },
|
|
106
|
+
profile: {
|
|
107
|
+
method: "GET",
|
|
108
|
+
path: "/desearch/instagram/profile/{username}",
|
|
109
|
+
required: ["username"],
|
|
110
|
+
optional: [],
|
|
111
|
+
},
|
|
112
|
+
profile_posts: {
|
|
113
|
+
method: "GET",
|
|
114
|
+
path: "/desearch/instagram/profile/{username}/posts",
|
|
115
|
+
required: ["username"],
|
|
116
|
+
optional: ["count", "cursor"],
|
|
117
|
+
list: true,
|
|
118
|
+
},
|
|
119
|
+
comments: {
|
|
120
|
+
method: "GET",
|
|
121
|
+
path: "/desearch/instagram/comments/{shortcode}",
|
|
122
|
+
required: ["shortcode"],
|
|
123
|
+
optional: ["count", "cursor"],
|
|
124
|
+
list: true,
|
|
125
|
+
},
|
|
126
|
+
hashtag: {
|
|
127
|
+
method: "GET",
|
|
128
|
+
path: "/desearch/instagram/hashtag/{tag}",
|
|
129
|
+
required: ["tag"],
|
|
130
|
+
optional: ["count", "cursor"],
|
|
131
|
+
list: true,
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
youtube: {
|
|
135
|
+
search: {
|
|
136
|
+
method: "POST",
|
|
137
|
+
path: "/desearch/youtube/search",
|
|
138
|
+
required: ["query"],
|
|
139
|
+
optional: ["type", "upload_date", "sort_by", "duration", "cursor"],
|
|
140
|
+
list: true,
|
|
141
|
+
},
|
|
142
|
+
video: { method: "GET", path: "/desearch/youtube/video/{id}", required: ["id"], optional: [] },
|
|
143
|
+
transcript: {
|
|
144
|
+
method: "GET",
|
|
145
|
+
path: "/desearch/youtube/transcript/{video_id}",
|
|
146
|
+
required: ["video_id"],
|
|
147
|
+
optional: ["language"],
|
|
148
|
+
},
|
|
149
|
+
comments: {
|
|
150
|
+
method: "GET",
|
|
151
|
+
path: "/desearch/youtube/comments/{video_id}",
|
|
152
|
+
required: ["video_id"],
|
|
153
|
+
optional: ["order", "cursor"],
|
|
154
|
+
list: true,
|
|
155
|
+
},
|
|
156
|
+
channel: { method: "GET", path: "/desearch/youtube/channel/{handle}", required: ["handle"], optional: [] },
|
|
157
|
+
channel_videos: {
|
|
158
|
+
method: "GET",
|
|
159
|
+
path: "/desearch/youtube/channel/{handle}/videos",
|
|
160
|
+
required: ["handle"],
|
|
161
|
+
optional: ["sort", "cursor"],
|
|
162
|
+
list: true,
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
reddit: {
|
|
166
|
+
search: {
|
|
167
|
+
method: "POST",
|
|
168
|
+
path: "/desearch/reddit/search",
|
|
169
|
+
required: ["query"],
|
|
170
|
+
optional: ["sort", "timeframe", "cursor"],
|
|
171
|
+
list: true,
|
|
172
|
+
choices: { sort: ["relevance", "new", "top", "comment_count"] },
|
|
173
|
+
},
|
|
174
|
+
subreddit: { method: "GET", path: "/desearch/reddit/subreddit/{name}", required: ["name"], optional: [] },
|
|
175
|
+
subreddit_posts: {
|
|
176
|
+
method: "GET",
|
|
177
|
+
path: "/desearch/reddit/subreddit/{name}/posts",
|
|
178
|
+
required: ["name"],
|
|
179
|
+
optional: ["sort", "timeframe", "cursor"],
|
|
180
|
+
list: true,
|
|
181
|
+
choices: { sort: ["best", "hot", "new", "top", "rising"] },
|
|
182
|
+
},
|
|
183
|
+
post: { method: "GET", path: "/desearch/reddit/post/{id}", required: ["id"], optional: [] },
|
|
184
|
+
comments: {
|
|
185
|
+
method: "GET",
|
|
186
|
+
path: "/desearch/reddit/comments/{post_id}",
|
|
187
|
+
required: ["post_id"],
|
|
188
|
+
optional: ["cursor"],
|
|
189
|
+
list: true,
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
// Threads shows one page of results everywhere: no action takes a cursor.
|
|
193
|
+
threads: {
|
|
194
|
+
search: {
|
|
195
|
+
method: "POST",
|
|
196
|
+
path: "/desearch/threads/search",
|
|
197
|
+
required: ["query"],
|
|
198
|
+
optional: ["start_date", "end_date"],
|
|
199
|
+
list: true,
|
|
200
|
+
},
|
|
201
|
+
search_users: {
|
|
202
|
+
method: "POST",
|
|
203
|
+
path: "/desearch/threads/search/users",
|
|
204
|
+
required: ["query"],
|
|
205
|
+
optional: [],
|
|
206
|
+
list: true,
|
|
207
|
+
},
|
|
208
|
+
profile: { method: "GET", path: "/desearch/threads/profile/{username}", required: ["username"], optional: [] },
|
|
209
|
+
profile_posts: {
|
|
210
|
+
method: "GET",
|
|
211
|
+
path: "/desearch/threads/profile/{username}/posts",
|
|
212
|
+
required: ["username"],
|
|
213
|
+
optional: [],
|
|
214
|
+
list: true,
|
|
215
|
+
},
|
|
216
|
+
post: { method: "GET", path: "/desearch/threads/post/{id}", required: ["id"], optional: [] },
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
/** Action names in table order, for the tool's `action` enum. */
|
|
220
|
+
export function socialActionNames(platform) {
|
|
221
|
+
return Object.keys(SOCIAL_ACTIONS[platform]);
|
|
222
|
+
}
|
|
223
|
+
function specFor(platform, action) {
|
|
224
|
+
const actions = SOCIAL_ACTIONS[platform];
|
|
225
|
+
return Object.hasOwn(actions, action) ? actions[action] : undefined;
|
|
226
|
+
}
|
|
227
|
+
/** "video_id (required), count, cursor" */
|
|
228
|
+
export function socialActionUsage(platform, action) {
|
|
229
|
+
const spec = specFor(platform, action);
|
|
230
|
+
if (!spec) {
|
|
231
|
+
return "";
|
|
232
|
+
}
|
|
233
|
+
const parts = [...spec.required.map((name) => `${name} (required)`), ...spec.optional];
|
|
234
|
+
return parts.length > 0 ? parts.join(", ") : "no other arguments";
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Light clean-up of a target: trim it, and drop a leading "@" from a username,
|
|
238
|
+
* "#" from a tag, or "r/" from a subreddit name, which the API takes without them.
|
|
239
|
+
* Cursors are never touched.
|
|
240
|
+
*/
|
|
241
|
+
function cleanTarget(name, value) {
|
|
242
|
+
const trimmed = value.trim();
|
|
243
|
+
if (name === "username") {
|
|
244
|
+
return trimmed.replace(/^@+/, "");
|
|
245
|
+
}
|
|
246
|
+
if (name === "tag") {
|
|
247
|
+
return trimmed.replace(/^#+/, "");
|
|
248
|
+
}
|
|
249
|
+
if (name === "name") {
|
|
250
|
+
return trimmed.replace(/^\/?r\//i, "");
|
|
251
|
+
}
|
|
252
|
+
return trimmed;
|
|
253
|
+
}
|
|
254
|
+
const ARGUMENT_NAMES = [
|
|
255
|
+
"query",
|
|
256
|
+
"type",
|
|
257
|
+
"sort",
|
|
258
|
+
"sort_by",
|
|
259
|
+
"upload_date",
|
|
260
|
+
"duration",
|
|
261
|
+
"timeframe",
|
|
262
|
+
"start_date",
|
|
263
|
+
"end_date",
|
|
264
|
+
"id",
|
|
265
|
+
"username",
|
|
266
|
+
"handle",
|
|
267
|
+
"name",
|
|
268
|
+
"profile_id",
|
|
269
|
+
"post_id",
|
|
270
|
+
"video_id",
|
|
271
|
+
"shortcode",
|
|
272
|
+
"tag",
|
|
273
|
+
"language",
|
|
274
|
+
"order",
|
|
275
|
+
"region",
|
|
276
|
+
"count",
|
|
277
|
+
"cursor",
|
|
278
|
+
];
|
|
279
|
+
/**
|
|
280
|
+
* The route and arguments for one call. Throws before any request when a needed
|
|
281
|
+
* argument is missing or an argument does not apply to the action.
|
|
282
|
+
*/
|
|
283
|
+
export function socialRequest(platform, args) {
|
|
284
|
+
const action = String(args.action);
|
|
285
|
+
const spec = specFor(platform, action);
|
|
286
|
+
if (!spec) {
|
|
287
|
+
throw new Error(`Unknown ${platform} action "${action}". Actions: ${Object.keys(SOCIAL_ACTIONS[platform]).join(", ")}.`);
|
|
288
|
+
}
|
|
289
|
+
const accepted = new Set([...spec.required, ...spec.optional]);
|
|
290
|
+
const values = {};
|
|
291
|
+
const extra = [];
|
|
292
|
+
for (const name of ARGUMENT_NAMES) {
|
|
293
|
+
const raw = args[name];
|
|
294
|
+
if (raw === undefined) {
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
if (!accepted.has(name)) {
|
|
298
|
+
extra.push(name);
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
values[name] =
|
|
302
|
+
typeof raw === "string" && spec.required.includes(name) ? cleanTarget(name, raw) : raw;
|
|
303
|
+
}
|
|
304
|
+
const missing = spec.required.filter((name) => values[name] === undefined || values[name] === "");
|
|
305
|
+
const choices = spec.choices ?? {};
|
|
306
|
+
const wrong = Object.keys(choices).filter((name) => values[name] !== undefined && !choices[name].includes(String(values[name])));
|
|
307
|
+
if (missing.length > 0 || extra.length > 0 || wrong.length > 0) {
|
|
308
|
+
const problems = [];
|
|
309
|
+
if (missing.length > 0) {
|
|
310
|
+
problems.push(`${platform} action "${action}" needs ${missing.join(" and ")}.`);
|
|
311
|
+
}
|
|
312
|
+
if (extra.length > 0) {
|
|
313
|
+
problems.push(`${platform} action "${action}" does not take ${extra.join(", ")}.`);
|
|
314
|
+
}
|
|
315
|
+
for (const name of wrong) {
|
|
316
|
+
problems.push(`${platform} action "${action}" takes ${name} ${choices[name].join(", ")}, not "${String(values[name])}".`);
|
|
317
|
+
}
|
|
318
|
+
throw new Error(`${problems.join(" ")} ${action} takes: ${socialActionUsage(platform, action)}. No request was sent.`);
|
|
319
|
+
}
|
|
320
|
+
const inPath = new Set();
|
|
321
|
+
const path = spec.path.replace(/\{(\w+)\}/g, (_, name) => {
|
|
322
|
+
inPath.add(name);
|
|
323
|
+
// {id:path} routes accept a "/" in the value; encoded, it still reaches the route as one value.
|
|
324
|
+
return encodeURIComponent(String(values[name]));
|
|
325
|
+
});
|
|
326
|
+
const rest = {};
|
|
327
|
+
for (const [name, value] of Object.entries(values)) {
|
|
328
|
+
if (!inPath.has(name)) {
|
|
329
|
+
rest[name] = value;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return { spec, path, values: rest };
|
|
333
|
+
}
|
|
334
|
+
/** One sentence on how to get the next page. */
|
|
335
|
+
export function socialNextStep(platform, action, spec, nextCursor) {
|
|
336
|
+
if (!spec.optional.includes("cursor")) {
|
|
337
|
+
return "This action returns one page and takes no cursor.";
|
|
338
|
+
}
|
|
339
|
+
if (nextCursor === null) {
|
|
340
|
+
return "Last page: there are no more results.";
|
|
341
|
+
}
|
|
342
|
+
const same = spec.required.length > 0 ? `, the same ${spec.required.join(" and ")},` : "";
|
|
343
|
+
return `More results: call ${platform} again with action "${action}"${same} and cursor set to next_cursor, unchanged. A cursor works for 24 hours.`;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Run one social action. A single post, profile, media item, video, transcript,
|
|
347
|
+
* channel, or subreddit comes back as the API sent it. A list comes back as
|
|
348
|
+
* `{ results, next_cursor, next }`: `next_cursor` is the `x-desearch-next-cursor`
|
|
349
|
+
* header (null on the last page) and `next` says how to ask for the next page.
|
|
350
|
+
*/
|
|
351
|
+
export async function runSocialAction(call, platform, args) {
|
|
352
|
+
const { spec, path, values } = socialRequest(platform, args);
|
|
353
|
+
const response = spec.method === "POST" ? await call("POST", path, { body: values }) : await call("GET", path, { query: values });
|
|
354
|
+
if (!spec.list) {
|
|
355
|
+
return response.data;
|
|
356
|
+
}
|
|
357
|
+
const header = response.headers.get(NEXT_CURSOR_HEADER);
|
|
358
|
+
const nextCursor = header ? header : null;
|
|
359
|
+
return {
|
|
360
|
+
results: response.data,
|
|
361
|
+
next_cursor: nextCursor,
|
|
362
|
+
next: socialNextStep(platform, String(args.action), spec, nextCursor),
|
|
363
|
+
};
|
|
364
|
+
}
|