socialcrawl-mcp 2.5.0 → 2.7.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.
@@ -1,3 +1,4 @@
1
+ import { findEndpoint } from "./data/endpoints.js";
1
2
  /**
2
3
  * Two price levers the registry states in words rather than as join lanes,
3
4
  * read from that wording so they cannot drift from the API's pricer:
@@ -14,6 +15,16 @@
14
15
  *
15
16
  * `bandExplained` counts both, so a band they complete is quoted exactly; a
16
17
  * band they do not complete still falls back to its ceiling.
18
+ *
19
+ * Two more meters, from the same wording (API-447, API-450, API-451):
20
+ *
21
+ * - A per-row meter on `limit` (`facebook/post/comments/full` "holds
22
+ * `ceil(limit / 4)` (at least 3)", the TikTok Shop affiliate lanes "holds
23
+ * limit x 107"): the call holds that from the limit sent, or from the
24
+ * limit's stated default, in place of the page price.
25
+ * - A per-handle hold on a batch (`prism/profiles` `include: "insights"` "holds
26
+ * 36 credits a handle"): the sum of each handle's own platform price, and the
27
+ * hold for the handles on a platform that carries insights.
17
28
  */
18
29
  const sentences = (text) => (text ?? "").split(/(?<=\.)\s+/).filter(Boolean);
19
30
  const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -55,6 +66,84 @@ export function includeAddOns(e) {
55
66
  }
56
67
  return out;
57
68
  }
69
+ /**
70
+ * A metered band whose rule says what a `limit` holds: "holds `ceil(limit / 4)`
71
+ * (at least 3)" or "holds limit x 107". The default limit is the one in the
72
+ * `limit` param's own text ("Default 300").
73
+ */
74
+ export function rowMeter(e) {
75
+ const rule = e.pricing.description;
76
+ const limit = e.optionalParams.find((o) => o.name === "limit");
77
+ if (e.pricing.model !== "metered" || !rule || !limit)
78
+ return undefined;
79
+ const dflt = /\bDefault (\d[\d,]*)/.exec(limit.description ?? "");
80
+ if (!dflt)
81
+ return undefined;
82
+ const fallback = Number(dflt[1].replace(/,/g, ""));
83
+ const rows = /\bholds `?ceil\(limit \/ (\d+)\)`?(?: \(at least (\d+)\))?/.exec(rule);
84
+ const each = /\bholds `?limit x (\d+)`?/.exec(rule);
85
+ let price;
86
+ if (rows) {
87
+ const per = Number(rows[1]);
88
+ const floor = rows[2] ? Number(rows[2]) : 0;
89
+ price = (n) => Math.max(floor, Math.ceil(n / per));
90
+ }
91
+ else if (each) {
92
+ const per = Number(each[1]);
93
+ price = (n) => n * per;
94
+ }
95
+ if (!price)
96
+ return undefined;
97
+ const priced = price;
98
+ const max = limit.maximum;
99
+ const clamp = (n) => (max !== undefined ? Math.min(n, max) : n);
100
+ return {
101
+ hold(raw) {
102
+ const n = Number(raw);
103
+ return priced(clamp(raw !== undefined && raw !== null && raw !== "" && Number.isFinite(n) && n >= 1 ? Math.floor(n) : fallback));
104
+ },
105
+ ceiling: max !== undefined ? priced(max) : undefined,
106
+ };
107
+ }
108
+ const INSIGHTS_RULE = /include: "insights" \(([^)]*?) handles only\)[^]*?holds (\d+) credits a handle/;
109
+ const PROFILE_RESOURCES = ["profile", "channel"];
110
+ /**
111
+ * The exact hold of a batch whose rule prices each handle on its own platform
112
+ * (`prism/profiles`): each handle's profile price, and the insights hold on
113
+ * the platforms that carry insights when `include` has it. Undefined when the
114
+ * call joins posts or comments (their pages are the band's ceiling), or a
115
+ * handle's platform has no profile price here.
116
+ */
117
+ export function perHandleHold(e, params) {
118
+ const rule = e.pricing.description;
119
+ const items = params.items;
120
+ if (e.pricing.model !== "metered" || !rule || !Array.isArray(items) || items.length === 0)
121
+ return undefined;
122
+ const meter = INSIGHTS_RULE.exec(rule);
123
+ if (!meter)
124
+ return undefined;
125
+ const carriers = new Set(meter[1].split(/,|\band\b/).map((t) => t.trim().toLowerCase()).filter(Boolean));
126
+ const insightsHold = Number(meter[2]);
127
+ for (const name of ["posts_limit", "comments_top_posts", "comments_per_post", "comments_select_by"]) {
128
+ if (params[name] !== undefined && params[name] !== null && params[name] !== "")
129
+ return undefined;
130
+ }
131
+ const asked = (typeof params.include === "string" ? params.include : "")
132
+ .split(",")
133
+ .map((t) => t.trim().toLowerCase())
134
+ .filter(Boolean);
135
+ if (asked.some((t) => t !== "insights" && t !== "about"))
136
+ return undefined;
137
+ let total = 0;
138
+ for (const item of items) {
139
+ const platform = typeof item?.platform === "string" ? item.platform.toLowerCase() : "";
140
+ const profile = PROFILE_RESOURCES.map((r) => findEndpoint(platform, r, "GET")).find((x) => x !== undefined);
141
+ if (!profile)
142
+ return undefined;
143
+ total += profile.pricing.cost + (asked.includes("insights") && carriers.has(platform) ? insightsHold : 0);
144
+ }
145
+ return total;
146
+ }
58
147
  /** Credits the value-priced params and include add-ons of this call add to the page price. */
59
148
  export function valueAndAddOnCredits(e, params) {
60
149
  let extra = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "socialcrawl-mcp",
3
- "version": "2.5.0",
3
+ "version": "2.7.0",
4
4
  "description": "One unified API for social and web data — social media (incl. Weibo, Douyin, Xiaohongshu, Telegram, Quora, Bluesky, Apple Music, Product Hunt), commerce, marketplaces & product reviews, retail (Amazon, Walmart, Target, Home Depot, eBay, Klarna, AliExpress, Etsy, Sephora, H&M, Kohl's, Wayfair, Gumtree, Google Shopping), app stores (Google Play, App Store), places, travel & stays (Airbnb, Booking.com, Tripadvisor, Yelp, Google Business/Hotels), books (Goodreads), business & software reputation (Trustpilot, G2), jobs & salaries (LinkedIn, Indeed, Bing, Xing), markets & finance, US congressional trading disclosures, on-page SEO audits, web search & research (Bing, DuckDuckGo, Tavily, Perplexity), full web scraping & browser automation (scrape, crawl, agent, monitors, sessions), audience-filtered mention search over a panel you supply (cohorts), Korean search (Naver + Data Lab), content/sentiment analysis, Google News/Trends, GitHub, Hacker News, Polymarket, AI X-search via Grok, cross-platform Prism composites, and a universal /search/everywhere meta-search with background lists and scheduled watches — with exact per-endpoint credit pricing (ladder, flat, and metered bands), free default row judgments with metered label/relevance quotes, and itemised per-call and per-job cost quotes for every one.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",