طقم تطوير JavaScript / TypeScript
@serpcheap/sdk هو عميل JavaScript/TypeScript الرسمي — Node 18+، بصفر تبعيات (يستخدم fetch
الأصلي)، ومُحدّد الأنواع بالكامل.
التثبيت
Section titled “التثبيت”npm install @serpcheap/sdkالبدء السريع
Section titled “البدء السريع”import { SerpCheap } from "@serpcheap/sdk";
const client = new SerpCheap("YOUR_API_KEY");
const res = await client.search({ q: "best running shoes", gl: "us" });for (const r of res.organic) { console.log(`${r.position}. ${r.title} — ${r.link}`);}الخيارات
Section titled “الخيارات”const client = new SerpCheap("YOUR_API_KEY", { baseUrl: "https://api.serp.cheap", // default timeoutMs: 15000, // default maxRetries: 2, // retries on transient errors});الترقيم
Section titled “الترقيم”تتنقل searchPages عبر الصفحات نيابةً عنك (from/to شاملان):
for await (const page of client.searchPages({ q: "coffee makers" }, 1, 5)) { console.log(`page ${page.page}: ${page.organic.length} results`);}معالجة الأخطاء
Section titled “معالجة الأخطاء”import { SerpCheapError } from "@serpcheap/sdk";
try { const res = await client.search({ q: "query" });} catch (err) { if (err instanceof SerpCheapError) { console.error(`[${err.code}] ${err.message} (retryable=${err.retryable})`); }}