socialcrawl-mcp 1.4.0 → 1.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/README.md +90 -35
- package/dist/__tests__/auth.test.d.ts +1 -0
- package/dist/__tests__/auth.test.js +41 -0
- package/dist/__tests__/auth.test.js.map +1 -0
- package/dist/__tests__/check-balance.test.js +11 -15
- package/dist/__tests__/check-balance.test.js.map +1 -1
- package/dist/__tests__/client.test.js +31 -30
- package/dist/__tests__/client.test.js.map +1 -1
- package/dist/__tests__/context.test.d.ts +1 -0
- package/dist/__tests__/context.test.js +27 -0
- package/dist/__tests__/context.test.js.map +1 -0
- package/dist/__tests__/data-integrity.test.js +55 -19
- package/dist/__tests__/data-integrity.test.js.map +1 -1
- package/dist/__tests__/http.test.d.ts +1 -0
- package/dist/__tests__/http.test.js +221 -0
- package/dist/__tests__/http.test.js.map +1 -0
- package/dist/__tests__/monitors.test.d.ts +1 -0
- package/dist/__tests__/monitors.test.js +133 -0
- package/dist/__tests__/monitors.test.js.map +1 -0
- package/dist/__tests__/preflight.test.js +14 -17
- package/dist/__tests__/preflight.test.js.map +1 -1
- package/dist/__tests__/server.test.d.ts +1 -0
- package/dist/__tests__/server.test.js +61 -0
- package/dist/__tests__/server.test.js.map +1 -0
- package/dist/__tests__/truncation.test.js +5 -9
- package/dist/__tests__/truncation.test.js.map +1 -1
- package/dist/__tests__/web.test.d.ts +1 -0
- package/dist/__tests__/web.test.js +147 -0
- package/dist/__tests__/web.test.js.map +1 -0
- package/dist/app.d.ts +29 -0
- package/dist/app.js +147 -0
- package/dist/app.js.map +1 -0
- package/dist/auth.d.ts +8 -0
- package/dist/auth.js +23 -0
- package/dist/auth.js.map +1 -0
- package/dist/client.d.ts +26 -1
- package/dist/client.js +72 -15
- package/dist/client.js.map +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/context.d.ts +14 -0
- package/dist/context.js +15 -0
- package/dist/context.js.map +1 -0
- package/dist/data/docs.js +118 -27
- package/dist/data/docs.js.map +1 -1
- package/dist/data/endpoints.d.ts +7 -1
- package/dist/data/endpoints.js +4228 -1657
- package/dist/data/endpoints.js.map +1 -1
- package/dist/data/platforms.js +44 -14
- package/dist/data/platforms.js.map +1 -1
- package/dist/http.d.ts +2 -0
- package/dist/http.js +71 -0
- package/dist/http.js.map +1 -0
- package/dist/index.js +3 -89
- package/dist/index.js.map +1 -1
- package/dist/schemas/tools.d.ts +102 -0
- package/dist/schemas/tools.js +118 -1
- package/dist/schemas/tools.js.map +1 -1
- package/dist/server.d.ts +8 -0
- package/dist/server.js +129 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/check-balance.d.ts +2 -1
- package/dist/tools/check-balance.js +2 -2
- package/dist/tools/check-balance.js.map +1 -1
- package/dist/tools/list-endpoints.js +18 -7
- package/dist/tools/list-endpoints.js.map +1 -1
- package/dist/tools/monitors.d.ts +32 -0
- package/dist/tools/monitors.js +160 -0
- package/dist/tools/monitors.js.map +1 -0
- package/dist/tools/request.d.ts +3 -1
- package/dist/tools/request.js +79 -11
- package/dist/tools/request.js.map +1 -1
- package/dist/tools/web.d.ts +21 -0
- package/dist/tools/web.js +92 -0
- package/dist/tools/web.js.map +1 -0
- package/dist/types.d.ts +16 -3
- package/package.json +10 -4
package/README.md
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
# socialcrawl-mcp
|
|
4
4
|
|
|
5
|
-
**Give your AI agent access to
|
|
5
|
+
**Give your AI agent access to 44 platforms — social media, commerce & product reviews, app stores, places & travel, business reputation, web research, full web scraping & browser automation, prediction markets, search trends, cross-platform Prism composites, and a universal cross-platform meta-search — through a single API**
|
|
6
6
|
|
|
7
7
|
[](https://www.npmjs.com/package/socialcrawl-mcp)
|
|
8
8
|
[](https://registry.modelcontextprotocol.io)
|
|
9
|
-
[](https://socialcrawl.dev)
|
|
10
|
+
[](https://socialcrawl.dev/docs)
|
|
11
11
|
[](LICENSE)
|
|
12
12
|
[](https://glama.ai/mcp/servers/socialcrawl/mcp)
|
|
13
13
|
|
|
@@ -23,9 +23,11 @@
|
|
|
23
23
|
|
|
24
24
|
## Overview
|
|
25
25
|
|
|
26
|
-
`socialcrawl-mcp` is an [MCP (Model Context Protocol)](https://modelcontextprotocol.io) server that connects AI agents to the [SocialCrawl API](https://socialcrawl.dev) — a unified data API covering
|
|
26
|
+
`socialcrawl-mcp` is an [MCP (Model Context Protocol)](https://modelcontextprotocol.io) server that connects AI agents to the [SocialCrawl API](https://socialcrawl.dev) — a unified data API covering 44 platforms and 357 endpoints.
|
|
27
27
|
|
|
28
|
-
Retrieve profiles, posts, comments, search results, trending content, and analytics from TikTok, Instagram, YouTube, Twitter/X, LinkedIn, Reddit, GitHub, Hacker News, Polymarket, and 30 more platforms. Pull products, reviews, and sellers from Amazon and Google Shopping; apps, charts, and reviews from Google Play and the Apple App Store; places, hotels, and traveler reviews from Tripadvisor and Google Business; brand reputation from Trustpilot; Korean search across 11 Naver corpora; cross-web brand mentions with sentiment via Content Analysis — plus web research via Tavily and Perplexity, AI-powered X search via Grok, and a single `/search/everywhere` endpoint that fans out across 12+ sources in one call.
|
|
28
|
+
Retrieve profiles, posts, comments, search results, trending content, and analytics from TikTok, Instagram, YouTube, Twitter/X, LinkedIn, Reddit, GitHub, Hacker News, Polymarket, and 30 more platforms. Pull products, reviews, and sellers from Amazon and Google Shopping; apps, charts, and reviews from Google Play and the Apple App Store; places, hotels, and traveler reviews from Tripadvisor and Google Business; brand reputation from Trustpilot; Korean search across 11 Naver corpora; cross-web brand mentions with sentiment via Content Analysis; Google News headlines and Google Finance quotes — plus web research via Tavily and Perplexity, AI-powered X search via Grok, and a single `/search/everywhere` endpoint that fans out across 12+ sources in one call.
|
|
29
|
+
|
|
30
|
+
New in this release: a major **LinkedIn** expansion (44 endpoints — full profiles & company pages, posts/reposts/reactions, comments & replies, people & company-people search, structured profile sub-resources, jobs, company insights, and groups), deeper **Instagram** coverage (followers/following, similar accounts, post likers, stories, tagged & location feeds, post-reshare stats, engagement analytics, and one-call reels/posts feeds with per-item share counts), and new **YouTube** capabilities (trending & advanced search, autocomplete suggestions, playlist items, and downloadable media files — audio, video, subtitles, thumbnails). Alongside the **Prism** family — server-side composite endpoints that fan out across many platforms and fold the results into one report (universal URL `lookup`, full `comments` harvesting, cross-source `reputation`, `share-of-voice`, brand-mention and consumer-demand nowcasts, AI consensus `answers`, crisis radar, creator vetting, and video/app/product intelligence). One API key, one consistent response format, every platform.
|
|
29
31
|
|
|
30
32
|
**What the MCP server does:**
|
|
31
33
|
- Discovers available platforms and endpoints dynamically
|
|
@@ -35,6 +37,37 @@ Retrieve profiles, posts, comments, search results, trending content, and analyt
|
|
|
35
37
|
|
|
36
38
|
## Installation
|
|
37
39
|
|
|
40
|
+
### Remote server (hosted — no install)
|
|
41
|
+
|
|
42
|
+
Connect straight to the hosted Streamable HTTP endpoint — nothing to install or run:
|
|
43
|
+
|
|
44
|
+
**Claude Code** (works in the CLI *and* Claude Code on the web / cloud sandboxes)
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
claude mcp add --scope user --transport http socialcrawl https://mcp.socialcrawl.dev/mcp \
|
|
48
|
+
--header "Authorization: Bearer sc_your_key_here"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Any client that reads `.mcp.json`**
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"mcpServers": {
|
|
56
|
+
"socialcrawl": {
|
|
57
|
+
"type": "http",
|
|
58
|
+
"url": "https://mcp.socialcrawl.dev/mcp",
|
|
59
|
+
"headers": { "Authorization": "Bearer ${SOCIALCRAWL_API_KEY}" }
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Cursor / Windsurf / VS Code** — choose the HTTP ("streamable-http") server type with the same URL and header. `x-api-key: sc_your_key_here` works as an alternative header.
|
|
66
|
+
|
|
67
|
+
The discovery tools (`socialcrawl_list_platforms`, `socialcrawl_list_endpoints`, `socialcrawl_get_docs`) work without a key, so you can explore before signing up. claude.ai custom connectors (Settings → Connectors) require OAuth, which ships in a follow-up release — use the header-based setup above in the meantime.
|
|
68
|
+
|
|
69
|
+
Prefer running it locally? Every stdio option below works exactly as before.
|
|
70
|
+
|
|
38
71
|
### npm
|
|
39
72
|
|
|
40
73
|
```bash
|
|
@@ -224,17 +257,34 @@ Every response follows a unified envelope format:
|
|
|
224
257
|
|
|
225
258
|
## Available Tools
|
|
226
259
|
|
|
227
|
-
The MCP server exposes
|
|
260
|
+
The MCP server exposes 7 tools:
|
|
228
261
|
|
|
229
262
|
| Tool | Description | Needs API key? |
|
|
230
263
|
|------|-------------|----------------|
|
|
231
|
-
| `socialcrawl_list_platforms` | Discover all
|
|
264
|
+
| `socialcrawl_list_platforms` | Discover all 44 platforms with their endpoints and capabilities | No |
|
|
232
265
|
| `socialcrawl_list_endpoints` | See all endpoints, required parameters, and credit costs for a platform | No |
|
|
233
|
-
| `socialcrawl_request` | Make any SocialCrawl API call — profiles, posts, comments, search, analytics. Supports an optional `idempotencyKey` for retry-safe calls. | Yes |
|
|
266
|
+
| `socialcrawl_request` | Make any SocialCrawl API call — profiles, posts, comments, search, trends, analytics, Prism composites. GET endpoints take query `params`; POST batch endpoints (e.g. youtube/videos, prism/profiles) take their array/object `body`. Supports an optional `idempotencyKey` for retry-safe calls. | Yes |
|
|
234
267
|
| `socialcrawl_check_balance` | Check remaining credits and recent deduction summary. Calls `/v1/credits/balance` — costs 0 credits. | Yes |
|
|
268
|
+
| `socialcrawl_monitors` | Create and manage stateful monitors that re-run any recipe on a cadence, deliver results to a signed webhook, and accumulate a time-series. Actions: create, list, get, runs, timeseries, pause, resume, delete. | Yes |
|
|
269
|
+
| `socialcrawl_web` | Full web scraping & browser automation (the `web` platform). Sync scrape/search/map/extract; async crawl/batch_scrape/agent jobs with poll/cancel; stateful monitors; interactive browser sessions. One `action` per endpoint. | Yes |
|
|
235
270
|
| `socialcrawl_get_docs` | Access detailed API documentation by topic or platform | No |
|
|
236
271
|
|
|
237
|
-
Three of the
|
|
272
|
+
Three of the seven tools work without an API key — they query local bundled data. `socialcrawl_request`, `socialcrawl_check_balance`, `socialcrawl_monitors`, and `socialcrawl_web` require a key.
|
|
273
|
+
|
|
274
|
+
### Monitors — schedule any recipe
|
|
275
|
+
|
|
276
|
+
`socialcrawl_monitors` wraps any registry endpoint or Prism composite in a scheduled, stateful monitor (`/v1/monitors/*`). It re-runs the recipe hourly/daily/weekly (or on a cron), delivers each result to an HMAC-signed webhook, raises alerts on metric thresholds or changes, and keeps a per-run time-series you can read back. *"Prism answers once; monitors watch it for you."* Managing monitors costs 0 credits; each scheduled run bills the recipe's normal cost plus a 1-credit scheduling premium. See `socialcrawl_get_docs` topic `monitors` for the full contract.
|
|
277
|
+
|
|
278
|
+
### Web — scrape, crawl, browse
|
|
279
|
+
|
|
280
|
+
`socialcrawl_web` drives the full web-scraping and browser-automation surface (the `web` platform, `/v1/web/*`) through a single `action` parameter:
|
|
281
|
+
|
|
282
|
+
- **Sync reads** — `scrape` (URL → markdown/HTML/screenshot/links), `search` (web search with page content), `map` (discover a site's URLs), `extract` (LLM structured data from a page).
|
|
283
|
+
- **Async jobs** — `crawl` a whole site, `batch_scrape` many URLs, or `agent` (autonomous multi-step web task); each returns a job you poll with `job_get`/`job_list` and stop with `job_cancel`.
|
|
284
|
+
- **Monitors** — `monitor_create`/`list`/`get`/`update`/`delete`/`checks` re-check a URL on a cadence and deliver changes to a webhook.
|
|
285
|
+
- **Sessions** — `session_create`/`get`/`list`, `session_execute` (run code in the live page), `session_close`.
|
|
286
|
+
|
|
287
|
+
Pricing varies by action (scrape 1cr, search 2cr, extract & session_create 5cr, agent 25cr; job/monitor/session management 0cr). See `socialcrawl_get_docs` topic `web`.
|
|
238
288
|
|
|
239
289
|
### Smart validation
|
|
240
290
|
|
|
@@ -248,47 +298,52 @@ Pass an `idempotencyKey` to `socialcrawl_request` (UUIDv4 recommended) to make t
|
|
|
248
298
|
|
|
249
299
|
| Platform | Endpoints | Data Available |
|
|
250
300
|
|----------|-----------|----------------|
|
|
251
|
-
| **
|
|
252
|
-
| **
|
|
253
|
-
| **
|
|
254
|
-
| **
|
|
301
|
+
| **LinkedIn** | 44 | Profiles & company pages, posts, reposts, reactions, comments & replies, people/company-people search, profile sub-resources (experience, education, skills, certifications…), jobs (search, company jobs, details), company insights, groups, transcripts, Ad Library, profile-360 |
|
|
302
|
+
| **Instagram** | 33 | Profiles, posts, reels, comments (incl. single-comment lookup), highlights, stories, tagged & location feeds, followers/following, similar accounts, post likers, reshare stats, one-call reels/posts feeds with share counts, engagement analytics, search (reels/hashtag/profile/location/music), trending, transcripts, profile-360 |
|
|
303
|
+
| **Prism** | 33 | Cross-platform composites — URL lookup, comment harvesting, batch comment-lookup & profile-lookup, handle-audit, brand mentions, demand signals, AI visibility, crisis radar/post-mortem, reputation, share-of-voice, creator vetting, AI consensus answers, video/app/product intelligence |
|
|
304
|
+
| **YouTube** | 28 | Channels, videos, shorts, comments & replies, sponsors, playlists & items, community posts, search (advanced + autocomplete), trending, live streams, media files (audio/video/subtitles/thumbnails), transcripts, batch videos/channels/transcripts, profile-360 |
|
|
305
|
+
| **Facebook** | 22 | Pages, posts, comments, groups, photos, reels, events, Marketplace, transcripts, full Ad Library |
|
|
306
|
+
| **Web Scraping** | 22 | Scrape, web search, site map, LLM extract, async crawl/batch-scrape/agent jobs, change monitors, interactive browser sessions, document parse — driven by `socialcrawl_web` |
|
|
307
|
+
| **TikTok** | 20 | Profiles, videos, comments & replies (incl. single-comment lookup), search, trending, audience, followers, live, songs, transcripts, profile-360 |
|
|
255
308
|
| **GitHub** | 12 | Users, repos, issues, PRs, READMEs, releases, search, repo dossier, user profile-velocity |
|
|
256
|
-
| **Naver** |
|
|
257
|
-
| **Google** | 10 | Web search, Ads Transparency, Business Profile (info, reviews, updates, Q&A), Travel hotels |
|
|
309
|
+
| **Naver** | 12 | Korea's #1 portal — blog, news, book, encyclopedia, cafe, KiN, local, shopping, doc, image, web search, brief |
|
|
258
310
|
| **Content Analysis** | 10 | Cross-web brand mentions, sentiment, rating distributions, phrase/category trends |
|
|
259
|
-
| **Google
|
|
260
|
-
| **Apple App Store** |
|
|
261
|
-
| **
|
|
262
|
-
| **Twitter/X** |
|
|
263
|
-
| **Reddit** |
|
|
311
|
+
| **Google** | 10 | Web search, Ads Transparency, Business Profile (info, reviews, updates, Q&A), Travel hotels |
|
|
312
|
+
| **Apple App Store** | 9 | App search, search suggestions, app details, reviews, charts, listings database, reference data |
|
|
313
|
+
| **Google Play** | 9 | App search, search suggestions, app details, reviews, charts, listings database, reference data |
|
|
314
|
+
| **Twitter/X** | 8 | Profiles, tweets, communities, video transcripts, AI search via Grok, profile-360 |
|
|
315
|
+
| **Reddit** | 7 | Subreddits, posts, comments, search, transcripts, omni-search VoC sweep |
|
|
264
316
|
| **Spotify** | 6 | Artists, tracks, albums, podcasts, episodes, search |
|
|
265
|
-
| **TikTok Shop** | 5 | Products, reviews, listings, search, creator showcases |
|
|
266
|
-
| **Threads** | 5 | Profiles, posts, keyword search, user search |
|
|
267
|
-
| **Pinterest** | 5 | Pins, boards, search, URL save-counts |
|
|
268
317
|
| **Amazon** | 5 | Product search, ASIN details, reviews, sellers, shop pages |
|
|
318
|
+
| **Pinterest** | 5 | Pins, boards, search, URL save-counts |
|
|
269
319
|
| **Rumble** | 5 | Search, channel videos, video details, comments, transcripts |
|
|
270
|
-
| **
|
|
320
|
+
| **Threads** | 5 | Profiles, posts, keyword search, user search |
|
|
321
|
+
| **TikTok Shop** | 5 | Products, reviews, listings, search, creator showcases |
|
|
322
|
+
| **Google Shopping** | 4 | Product search, product details, cross-retailer reviews, sellers |
|
|
271
323
|
| **Hacker News** | 4 | Story search, story, comment tree, profile |
|
|
272
324
|
| **Tavily** | 4 | Web search (with LLM answer), URL extraction, sitemap, full crawl |
|
|
273
|
-
| **
|
|
274
|
-
| **Truth Social** | 3 | Profiles, posts |
|
|
275
|
-
| **Kwai** | 3 | Profiles, posts |
|
|
325
|
+
| **Twitch** | 4 | Profiles, clips, videos, schedules |
|
|
276
326
|
| **Bluesky** | 3 | Profiles, posts |
|
|
277
|
-
| **
|
|
327
|
+
| **Google Finance** | 3 | Instrument quotes, markets overview, ticker search |
|
|
328
|
+
| **Kwai** | 3 | Profiles, posts |
|
|
329
|
+
| **Truth Social** | 3 | Profiles, posts |
|
|
330
|
+
| **Google Trends** | 2 | Interest-over-time (explore) + rising/breakout related queries |
|
|
278
331
|
| **Tripadvisor** | 2 | Place search, traveler reviews |
|
|
279
|
-
| **
|
|
332
|
+
| **Trustpilot** | 2 | Business search, company reviews |
|
|
333
|
+
| **Universal Search** | 2 | One query fanned out across 12+ platforms (20cr); forums lane |
|
|
334
|
+
| **Google News** | 1 | Real-time Google News SERP search |
|
|
280
335
|
| **Kick** | 1 | Clips |
|
|
281
|
-
| **
|
|
282
|
-
| **Polymarket** | 1 | Prediction-market research — multi-query fan-out + ranking |
|
|
283
|
-
| **Universal Search** | 1 | One query, fanned out across 12+ platforms (20cr) |
|
|
284
|
-
| **Linktree** | 1 | Link pages |
|
|
336
|
+
| **Komi** | 1 | Link pages |
|
|
285
337
|
| **Linkbio** | 1 | Link pages |
|
|
286
338
|
| **Linkme** | 1 | Link pages |
|
|
287
|
-
| **
|
|
339
|
+
| **Linktree** | 1 | Link pages |
|
|
340
|
+
| **Perplexity** | 1 | Sonar web research with cited sources |
|
|
288
341
|
| **Pillar** | 1 | Link pages |
|
|
342
|
+
| **Polymarket** | 1 | Prediction-market research — multi-query fan-out + ranking |
|
|
343
|
+
| **Snapchat** | 1 | Profiles |
|
|
289
344
|
| **Utility** | 1 | Age & gender detection |
|
|
290
345
|
|
|
291
|
-
**Total:
|
|
346
|
+
**Total: 357 endpoints across 44 platforms.**
|
|
292
347
|
|
|
293
348
|
## Error Handling
|
|
294
349
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import { extractApiKey } from "../auth.js";
|
|
3
|
+
describe("extractApiKey", () => {
|
|
4
|
+
const originalEnv = process.env;
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
// Poison the env to prove the extractor never reads it.
|
|
7
|
+
process.env = { ...originalEnv, SOCIALCRAWL_API_KEY: "sc_operator_secret" };
|
|
8
|
+
});
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
process.env = originalEnv;
|
|
11
|
+
});
|
|
12
|
+
it("reads Authorization: Bearer", () => {
|
|
13
|
+
expect(extractApiKey({ authorization: "Bearer sc_abc123" })).toBe("sc_abc123");
|
|
14
|
+
});
|
|
15
|
+
it("is case-insensitive on the Bearer scheme and trims whitespace", () => {
|
|
16
|
+
expect(extractApiKey({ authorization: "bearer sc_abc123 " })).toBe("sc_abc123");
|
|
17
|
+
});
|
|
18
|
+
it("reads x-api-key", () => {
|
|
19
|
+
expect(extractApiKey({ "x-api-key": "sc_xyz789" })).toBe("sc_xyz789");
|
|
20
|
+
});
|
|
21
|
+
it("prefers Authorization over x-api-key when both are present", () => {
|
|
22
|
+
expect(extractApiKey({ authorization: "Bearer sc_a", "x-api-key": "sc_b" })).toBe("sc_a");
|
|
23
|
+
});
|
|
24
|
+
it("ignores non-Bearer Authorization schemes", () => {
|
|
25
|
+
expect(extractApiKey({ authorization: "Basic dXNlcjpwYXNz" })).toBe("");
|
|
26
|
+
});
|
|
27
|
+
it("falls through to x-api-key when Authorization is non-Bearer or an empty Bearer", () => {
|
|
28
|
+
expect(extractApiKey({ authorization: "Basic dXNlcjpwYXNz", "x-api-key": "sc_fallback" })).toBe("sc_fallback");
|
|
29
|
+
expect(extractApiKey({ authorization: "Bearer ", "x-api-key": "sc_fallback" })).toBe("sc_fallback");
|
|
30
|
+
});
|
|
31
|
+
it("trims whitespace around an x-api-key value", () => {
|
|
32
|
+
expect(extractApiKey({ "x-api-key": " sc_xyz789 " })).toBe("sc_xyz789");
|
|
33
|
+
});
|
|
34
|
+
it("ignores a repeated x-api-key header (array form)", () => {
|
|
35
|
+
expect(extractApiKey({ "x-api-key": ["sc_a", "sc_b"] })).toBe("");
|
|
36
|
+
});
|
|
37
|
+
it("SECURITY: returns empty string — never the process env key — when no headers are sent", () => {
|
|
38
|
+
expect(extractApiKey({})).toBe("");
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=auth.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.test.js","sourceRoot":"","sources":["../../src/__tests__/auth.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;IAEhC,UAAU,CAAC,GAAG,EAAE;QACd,wDAAwD;QACxD,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,WAAW,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,CAAC;IAC9E,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,CAAC,GAAG,GAAG,WAAW,CAAC;IAC5B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACrC,MAAM,CAAC,aAAa,CAAC,EAAE,aAAa,EAAE,kBAAkB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACjF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+DAA+D,EAAE,GAAG,EAAE;QACvE,MAAM,CAAC,aAAa,CAAC,EAAE,aAAa,EAAE,sBAAsB,EAAE,CAAC,CAAC,CAAC,IAAI,CA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MAAM,CAAsB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACzF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uFAAuF,EAAE,GAAG,EAAE;QAC/F,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { describe, it, expect, vi,
|
|
1
|
+
import { describe, it, expect, vi, afterEach } from "vitest";
|
|
2
2
|
import { checkBalance } from "../tools/check-balance.js";
|
|
3
|
+
const ctx = { apiKey: "sc_test_key", baseUrl: "https://www.socialcrawl.dev" };
|
|
4
|
+
const anonCtx = { apiKey: "", baseUrl: "https://www.socialcrawl.dev" };
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
vi.restoreAllMocks();
|
|
7
|
+
});
|
|
3
8
|
describe("socialcrawl_check_balance tool", () => {
|
|
4
|
-
const originalEnv = process.env;
|
|
5
|
-
beforeEach(() => {
|
|
6
|
-
process.env = { ...originalEnv, SOCIALCRAWL_API_KEY: "sc_test_key" };
|
|
7
|
-
});
|
|
8
|
-
afterEach(() => {
|
|
9
|
-
process.env = originalEnv;
|
|
10
|
-
vi.restoreAllMocks();
|
|
11
|
-
});
|
|
12
9
|
it("calls /v1/credits/balance with no platform prefix and no query string", async () => {
|
|
13
10
|
let capturedUrl = "";
|
|
14
11
|
vi.stubGlobal("fetch", async (url) => {
|
|
@@ -22,15 +19,14 @@ describe("socialcrawl_check_balance tool", () => {
|
|
|
22
19
|
credits_remaining: 8432,
|
|
23
20
|
}), { status: 200 });
|
|
24
21
|
});
|
|
25
|
-
const result = await checkBalance();
|
|
22
|
+
const result = await checkBalance(ctx);
|
|
26
23
|
expect(capturedUrl).toContain("/v1/credits/balance");
|
|
27
24
|
expect(capturedUrl).not.toContain("/v1/meta/");
|
|
28
25
|
expect(capturedUrl).not.toContain("?");
|
|
29
26
|
expect(result).toContain("8432");
|
|
30
27
|
});
|
|
31
|
-
it("returns the No-API-key error
|
|
32
|
-
|
|
33
|
-
const result = await checkBalance();
|
|
28
|
+
it("returns the No-API-key error for an anonymous context", async () => {
|
|
29
|
+
const result = await checkBalance(anonCtx);
|
|
34
30
|
expect(result).toContain("No API key configured");
|
|
35
31
|
});
|
|
36
32
|
it("formats the balance response with a header noting 0-credit cost", async () => {
|
|
@@ -42,13 +38,13 @@ describe("socialcrawl_check_balance tool", () => {
|
|
|
42
38
|
credits_used: 0,
|
|
43
39
|
credits_remaining: 100,
|
|
44
40
|
}), { status: 200 }));
|
|
45
|
-
const result = await checkBalance();
|
|
41
|
+
const result = await checkBalance(ctx);
|
|
46
42
|
expect(result).toContain("/v1/credits/balance");
|
|
47
43
|
expect(result).toContain("0 credits");
|
|
48
44
|
});
|
|
49
45
|
it("propagates 401 errors with the Invalid API key message", async () => {
|
|
50
46
|
vi.stubGlobal("fetch", async () => new Response(JSON.stringify({ success: false, error: { type: "INVALID_API_KEY", message: "bad key" } }), { status: 401 }));
|
|
51
|
-
const result = await checkBalance();
|
|
47
|
+
const result = await checkBalance(ctx);
|
|
52
48
|
expect(result).toContain("Invalid API key");
|
|
53
49
|
});
|
|
54
50
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-balance.test.js","sourceRoot":"","sources":["../../src/__tests__/check-balance.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"check-balance.test.js","sourceRoot":"","sources":["../../src/__tests__/check-balance.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,MAAM,GAA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ChB,CACF,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,GAAG,CAAC,CAAC;QACvC,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
import { describe, it, expect, vi,
|
|
1
|
+
import { describe, it, expect, vi, afterEach } from "vitest";
|
|
2
2
|
import { makeRequest } from "../client.js";
|
|
3
3
|
describe("API client", () => {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
process.env = { ...originalEnv, SOCIALCRAWL_API_KEY: "sc_test_key" };
|
|
7
|
-
});
|
|
4
|
+
const ctx = { apiKey: "sc_test_key", baseUrl: "https://www.socialcrawl.dev" };
|
|
5
|
+
const anonCtx = { apiKey: "", baseUrl: "https://www.socialcrawl.dev" };
|
|
8
6
|
afterEach(() => {
|
|
9
|
-
process.env = originalEnv;
|
|
10
7
|
vi.restoreAllMocks();
|
|
11
8
|
});
|
|
12
|
-
it("returns error
|
|
13
|
-
|
|
14
|
-
const result = await makeRequest({ platform: "tiktok", resource: "profile", params: { handle: "test" } });
|
|
15
|
-
expect(result).toContain("No API key configured");
|
|
16
|
-
expect(result).toContain("SOCIALCRAWL_API_KEY");
|
|
17
|
-
});
|
|
18
|
-
it("returns error when API key is not set", async () => {
|
|
19
|
-
delete process.env.SOCIALCRAWL_API_KEY;
|
|
20
|
-
const result = await makeRequest({ platform: "tiktok", resource: "profile", params: { handle: "test" } });
|
|
9
|
+
it("returns the no-key error for an anonymous context", async () => {
|
|
10
|
+
const result = await makeRequest(anonCtx, { platform: "tiktok", resource: "profile", params: { handle: "test" } });
|
|
21
11
|
expect(result).toContain("No API key configured");
|
|
12
|
+
expect(result).toContain("SOCIALCRAWL_API_KEY"); // stdio guidance still present
|
|
13
|
+
expect(result).toContain("Authorization: Bearer"); // HTTP guidance now present
|
|
22
14
|
});
|
|
23
15
|
it("builds correct URL with params", async () => {
|
|
24
16
|
let capturedUrl = "";
|
|
@@ -26,7 +18,7 @@ describe("API client", () => {
|
|
|
26
18
|
capturedUrl = url;
|
|
27
19
|
return new Response(JSON.stringify({ success: true, data: {} }), { status: 200 });
|
|
28
20
|
});
|
|
29
|
-
await makeRequest({ platform: "tiktok", resource: "profile", params: { handle: "charlidamelio" } });
|
|
21
|
+
await makeRequest(ctx, { platform: "tiktok", resource: "profile", params: { handle: "charlidamelio" } });
|
|
30
22
|
expect(capturedUrl).toContain("/v1/tiktok/profile");
|
|
31
23
|
expect(capturedUrl).toContain("handle=charlidamelio");
|
|
32
24
|
});
|
|
@@ -36,35 +28,35 @@ describe("API client", () => {
|
|
|
36
28
|
capturedUrl = url;
|
|
37
29
|
return new Response(JSON.stringify({ success: true, data: {} }), { status: 200 });
|
|
38
30
|
});
|
|
39
|
-
await makeRequest({ platform: "tiktok", resource: "songs/popular" });
|
|
31
|
+
await makeRequest(ctx, { platform: "tiktok", resource: "songs/popular" });
|
|
40
32
|
expect(capturedUrl).toContain("/v1/tiktok/songs/popular");
|
|
41
33
|
expect(capturedUrl).not.toContain("?");
|
|
42
34
|
});
|
|
43
35
|
it("maps 401 to invalid API key message", async () => {
|
|
44
36
|
vi.stubGlobal("fetch", async () => new Response(JSON.stringify({ success: false, error: { type: "INVALID_API_KEY", message: "Invalid key" } }), { status: 401 }));
|
|
45
|
-
const result = await makeRequest({ platform: "tiktok", resource: "profile", params: { handle: "test" } });
|
|
37
|
+
const result = await makeRequest(ctx, { platform: "tiktok", resource: "profile", params: { handle: "test" } });
|
|
46
38
|
expect(result).toContain("Invalid API key");
|
|
47
39
|
});
|
|
48
40
|
it("maps 402 to insufficient credits message", async () => {
|
|
49
41
|
vi.stubGlobal("fetch", async () => new Response(JSON.stringify({ success: false, error: { type: "INSUFFICIENT_CREDITS", message: "No credits" }, credits_remaining: 0 }), { status: 402 }));
|
|
50
|
-
const result = await makeRequest({ platform: "tiktok", resource: "profile", params: { handle: "test" } });
|
|
42
|
+
const result = await makeRequest(ctx, { platform: "tiktok", resource: "profile", params: { handle: "test" } });
|
|
51
43
|
expect(result).toContain("Insufficient credits");
|
|
52
44
|
expect(result).toContain("socialcrawl.dev/dashboard/billing");
|
|
53
45
|
});
|
|
54
46
|
it("maps 404 to endpoint not found message", async () => {
|
|
55
47
|
vi.stubGlobal("fetch", async () => new Response(JSON.stringify({ success: false, error: { type: "ENDPOINT_NOT_FOUND" } }), { status: 404 }));
|
|
56
|
-
const result = await makeRequest({ platform: "tiktok", resource: "fake", params: {} });
|
|
48
|
+
const result = await makeRequest(ctx, { platform: "tiktok", resource: "fake", params: {} });
|
|
57
49
|
expect(result).toContain("not found");
|
|
58
50
|
expect(result).toContain("socialcrawl_list_endpoints");
|
|
59
51
|
});
|
|
60
52
|
it("maps 503 to platform unavailable message", async () => {
|
|
61
53
|
vi.stubGlobal("fetch", async () => new Response(JSON.stringify({ success: false, error: { type: "PLATFORM_UNAVAILABLE" } }), { status: 503 }));
|
|
62
|
-
const result = await makeRequest({ platform: "tiktok", resource: "profile", params: { handle: "test" } });
|
|
54
|
+
const result = await makeRequest(ctx, { platform: "tiktok", resource: "profile", params: { handle: "test" } });
|
|
63
55
|
expect(result).toContain("temporarily unavailable");
|
|
64
56
|
});
|
|
65
57
|
it("maps 502 to upstream error with refund note", async () => {
|
|
66
58
|
vi.stubGlobal("fetch", async () => new Response(JSON.stringify({ success: false, error: { type: "UPSTREAM_ERROR" } }), { status: 502 }));
|
|
67
|
-
const result = await makeRequest({ platform: "tiktok", resource: "profile", params: { handle: "test" } });
|
|
59
|
+
const result = await makeRequest(ctx, { platform: "tiktok", resource: "profile", params: { handle: "test" } });
|
|
68
60
|
expect(result).toContain("Upstream error");
|
|
69
61
|
expect(result).toContain("auto-refunded");
|
|
70
62
|
});
|
|
@@ -73,7 +65,7 @@ describe("API client", () => {
|
|
|
73
65
|
success: false,
|
|
74
66
|
error: { type: "RESOURCE_NOT_FOUND", message: "Resource does not exist" },
|
|
75
67
|
}), { status: 404 }));
|
|
76
|
-
const result = await makeRequest({ platform: "tiktok", resource: "profile", params: { handle: "ghost" } });
|
|
68
|
+
const result = await makeRequest(ctx, { platform: "tiktok", resource: "profile", params: { handle: "ghost" } });
|
|
77
69
|
expect(result).toContain("Resource not found");
|
|
78
70
|
expect(result).toContain("refunded");
|
|
79
71
|
expect(result).not.toContain("socialcrawl_list_endpoints");
|
|
@@ -83,7 +75,7 @@ describe("API client", () => {
|
|
|
83
75
|
success: false,
|
|
84
76
|
error: { type: "METHOD_NOT_ALLOWED", message: "Only GET is allowed" },
|
|
85
77
|
}), { status: 405 }));
|
|
86
|
-
const result = await makeRequest({ platform: "tiktok", resource: "profile", params: { handle: "test" } });
|
|
78
|
+
const result = await makeRequest(ctx, { platform: "tiktok", resource: "profile", params: { handle: "test" } });
|
|
87
79
|
expect(result).toContain("Method not allowed");
|
|
88
80
|
expect(result).toContain("GET");
|
|
89
81
|
});
|
|
@@ -92,7 +84,7 @@ describe("API client", () => {
|
|
|
92
84
|
success: false,
|
|
93
85
|
error: { type: "IDEMPOTENCY_KEY_CONFLICT", message: "Key already used by another account" },
|
|
94
86
|
}), { status: 409 }));
|
|
95
|
-
const result = await makeRequest({
|
|
87
|
+
const result = await makeRequest(ctx, {
|
|
96
88
|
platform: "tiktok",
|
|
97
89
|
resource: "profile",
|
|
98
90
|
params: { handle: "test" },
|
|
@@ -106,7 +98,7 @@ describe("API client", () => {
|
|
|
106
98
|
success: false,
|
|
107
99
|
error: { type: "IDEMPOTENCY_KEY_PAYLOAD_MISMATCH", message: "Key reused with different payload" },
|
|
108
100
|
}), { status: 422 }));
|
|
109
|
-
const result = await makeRequest({
|
|
101
|
+
const result = await makeRequest(ctx, {
|
|
110
102
|
platform: "tiktok",
|
|
111
103
|
resource: "profile",
|
|
112
104
|
params: { handle: "test" },
|
|
@@ -124,7 +116,7 @@ describe("API client", () => {
|
|
|
124
116
|
doc_url: "https://www.socialcrawl.dev/docs/errors/internal-error",
|
|
125
117
|
},
|
|
126
118
|
}), { status: 500 }));
|
|
127
|
-
const result = await makeRequest({ platform: "tiktok", resource: "profile", params: { handle: "test" } });
|
|
119
|
+
const result = await makeRequest(ctx, { platform: "tiktok", resource: "profile", params: { handle: "test" } });
|
|
128
120
|
expect(result).toContain("INTERNAL_ERROR");
|
|
129
121
|
expect(result).toContain("https://www.socialcrawl.dev/docs/errors/internal-error");
|
|
130
122
|
});
|
|
@@ -134,7 +126,7 @@ describe("API client", () => {
|
|
|
134
126
|
capturedHeaders = init.headers;
|
|
135
127
|
return new Response(JSON.stringify({ success: true, data: {} }), { status: 200 });
|
|
136
128
|
});
|
|
137
|
-
await makeRequest({
|
|
129
|
+
await makeRequest(ctx, {
|
|
138
130
|
platform: "tiktok",
|
|
139
131
|
resource: "profile",
|
|
140
132
|
params: { handle: "charlidamelio" },
|
|
@@ -148,7 +140,7 @@ describe("API client", () => {
|
|
|
148
140
|
capturedHeaders = init.headers;
|
|
149
141
|
return new Response(JSON.stringify({ success: true, data: {} }), { status: 200 });
|
|
150
142
|
});
|
|
151
|
-
await makeRequest({ platform: "tiktok", resource: "profile", params: { handle: "charlidamelio" } });
|
|
143
|
+
await makeRequest(ctx, { platform: "tiktok", resource: "profile", params: { handle: "charlidamelio" } });
|
|
152
144
|
expect(capturedHeaders["Idempotency-Key"]).toBeUndefined();
|
|
153
145
|
});
|
|
154
146
|
it("supports the meta platform for /v1/credits/balance", async () => {
|
|
@@ -157,9 +149,18 @@ describe("API client", () => {
|
|
|
157
149
|
capturedUrl = url;
|
|
158
150
|
return new Response(JSON.stringify({ success: true, data: { balance: 42 } }), { status: 200 });
|
|
159
151
|
});
|
|
160
|
-
await makeRequest({ platform: "meta", resource: "credits/balance" });
|
|
152
|
+
await makeRequest(ctx, { platform: "meta", resource: "credits/balance" });
|
|
161
153
|
expect(capturedUrl).toContain("/v1/credits/balance");
|
|
162
154
|
expect(capturedUrl).not.toContain("?");
|
|
163
155
|
});
|
|
156
|
+
it("uses ctx.baseUrl as the request origin", async () => {
|
|
157
|
+
let capturedUrl = "";
|
|
158
|
+
vi.stubGlobal("fetch", async (url) => {
|
|
159
|
+
capturedUrl = url;
|
|
160
|
+
return new Response(JSON.stringify({ success: true, data: {} }), { status: 200 });
|
|
161
|
+
});
|
|
162
|
+
await makeRequest({ apiKey: "sc_test_key", baseUrl: "http://localhost:9999" }, { platform: "tiktok", resource: "profile", params: { handle: "test" } });
|
|
163
|
+
expect(capturedUrl.startsWith("http://localhost:9999/v1/tiktok/profile")).toBe(true);
|
|
164
|
+
});
|
|
164
165
|
});
|
|
165
166
|
//# sourceMappingURL=client.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.test.js","sourceRoot":"","sources":["../../src/__tests__/client.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"client.test.js","sourceRoot":"","sources":["../../src/__tests__/client.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG3C,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,MAAM,GAAG,GAAe,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,6BAA6B,EAAE,CAAC;IAC1F,MAAM,OAAO,GAAe,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,6BAA6B,EAAE,CAAC;IAEnF,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,eAAe,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mDAAmD,EAAE,KAAK,IAAI,EAAE;QACjE,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,OAAO,EAAE,EAAE,QAAQ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import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import { contextFromEnv, DEFAULT_BASE_URL } from "../context.js";
|
|
3
|
+
describe("contextFromEnv (stdio entrypoint only)", () => {
|
|
4
|
+
const originalEnv = process.env;
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
process.env = { ...originalEnv };
|
|
7
|
+
delete process.env.SOCIALCRAWL_API_KEY;
|
|
8
|
+
delete process.env.SOCIALCRAWL_BASE_URL;
|
|
9
|
+
});
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
process.env = originalEnv;
|
|
12
|
+
});
|
|
13
|
+
it("defaults to empty key and the production base URL", () => {
|
|
14
|
+
const ctx = contextFromEnv();
|
|
15
|
+
expect(ctx.apiKey).toBe("");
|
|
16
|
+
expect(ctx.baseUrl).toBe(DEFAULT_BASE_URL);
|
|
17
|
+
expect(DEFAULT_BASE_URL).toBe("https://www.socialcrawl.dev");
|
|
18
|
+
});
|
|
19
|
+
it("reads SOCIALCRAWL_API_KEY and SOCIALCRAWL_BASE_URL when set", () => {
|
|
20
|
+
process.env.SOCIALCRAWL_API_KEY = "sc_env_key";
|
|
21
|
+
process.env.SOCIALCRAWL_BASE_URL = "http://localhost:4000";
|
|
22
|
+
const ctx = contextFromEnv();
|
|
23
|
+
expect(ctx.apiKey).toBe("sc_env_key");
|
|
24
|
+
expect(ctx.baseUrl).toBe("http://localhost:4000");
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=context.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.test.js","sourceRoot":"","sources":["../../src/__tests__/context.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjE,QAAQ,CAAC,wCAAwC,EAAE,G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