scavio 0.24.1 → 0.25.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 CHANGED
@@ -261,6 +261,33 @@ await client.google.news({ query: "openai" });
261
261
  await client.google.trends({ query: "bitcoin" });
262
262
  ```
263
263
 
264
+ #### Migrating from the Google Custom Search JSON API (new in 0.25.0)
265
+
266
+ `google.customSearch` takes the Custom Search JSON API (`cse.list`) parameters and
267
+ returns the same `customsearch#search` response: `items[]` with `title`, `link`,
268
+ `snippet` and `displayLink`, `searchInformation.totalResults` and
269
+ `queries.nextPage`, so code that parsed Custom Search results keeps working.
270
+ Options are snake_case like the rest of this SDK and are sent as the CSE wire
271
+ names (`site_search` -> `siteSearch`, `date_restrict` -> `dateRestrict`). 1 credit.
272
+
273
+ ```typescript
274
+ const res = await client.google.customSearch({
275
+ q: "abortcontroller fetch timeout",
276
+ num: 5,
277
+ site_search: "stackoverflow.com", // enforced on the returned results
278
+ date_restrict: "y1",
279
+ });
280
+ for (const item of res.items ?? []) console.log(item.displayLink, item.title, item.link);
281
+ const next = res.queries.nextPage?.[0]?.startIndex;
282
+ ```
283
+
284
+ Not using this SDK? Keep your existing Custom Search code and change the host:
285
+ `https://api.scavio.dev/customsearch/v1?key=YOUR_SCAVIO_KEY&q=...`. `cx` is
286
+ accepted and ignored. Parameters that cannot be honoured (image search, `sort`,
287
+ `rights`) throw `BadRequestError` instead of being silently dropped. For the full
288
+ SERP (knowledge graph, AI overview, People Also Ask) use `google.search`.
289
+ [Docs](https://scavio.dev/docs/google-custom-search-api?utm_source=npm-scavio-js&utm_medium=package&utm_campaign=readme)
290
+
264
291
  ### Amazon
265
292
 
266
293
  Responses are normalized to a stable shape (see the breaking-change note
package/dist/index.cjs CHANGED
@@ -232,7 +232,7 @@ function parseRetryAfter(header) {
232
232
  var BASE_URL = "https://api.scavio.dev";
233
233
  var DEFAULT_TIMEOUT = 3e4;
234
234
  var DEFAULT_MAX_RETRIES = 2;
235
- var SDK_VERSION = true ? "0.24.1" : "0.0.0";
235
+ var SDK_VERSION = true ? "0.25.0" : "0.0.0";
236
236
  var USER_AGENT = `scavio-js/${SDK_VERSION}`;
237
237
  function isServerRuntime() {
238
238
  const g = globalThis;
@@ -421,6 +421,15 @@ var AmazonNamespace = class {
421
421
  };
422
422
 
423
423
  // src/namespaces/google.ts
424
+ var CUSTOM_SEARCH_WIRE = {
425
+ date_restrict: "dateRestrict",
426
+ site_search: "siteSearch",
427
+ site_search_filter: "siteSearchFilter",
428
+ exact_terms: "exactTerms",
429
+ exclude_terms: "excludeTerms",
430
+ or_terms: "orTerms",
431
+ file_type: "fileType"
432
+ };
424
433
  var GoogleNamespace = class {
425
434
  constructor(client) {
426
435
  this.client = client;
@@ -430,6 +439,21 @@ var GoogleNamespace = class {
430
439
  async search(options) {
431
440
  return this.client._post("/api/v2/google", options);
432
441
  }
442
+ /**
443
+ * Google search in the Custom Search JSON API format: a drop-in for cse.list.
444
+ * Returns customsearch#search (items[], searchInformation, queries.nextPage)
445
+ * plus a scavio billing object, so CSE parsing code keeps working. For the
446
+ * full SERP (knowledge graph, AI overview, People Also Ask) use search().
447
+ * Unsupported CSE params (image search, sort, rights) throw BadRequestError.
448
+ * 1 credit.
449
+ */
450
+ async customSearch(options) {
451
+ const body = {};
452
+ for (const [key, value] of Object.entries(options)) {
453
+ body[CUSTOM_SEARCH_WIRE[key] ?? key] = value;
454
+ }
455
+ return await this.client._post("/api/v1/google/customsearch", body);
456
+ }
433
457
  /** Google AI Mode answer. */
434
458
  async aiMode(options) {
435
459
  return this.client._post("/api/v2/google/ai-mode", options);