serpkite 0.1.1 → 0.3.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 +7 -9
- package/dist/index.cjs +2 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -191
- package/dist/index.d.ts +16 -191
- package/dist/index.js +2 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -88,7 +88,7 @@ interface paths {
|
|
|
88
88
|
/** Same as POST /v1/search with query-string parameters */
|
|
89
89
|
get: operations["searchGet"];
|
|
90
90
|
put?: never;
|
|
91
|
-
/** Google web search (organic results,
|
|
91
|
+
/** Google web search (organic results, knowledge graph, answer box, people also ask, top stories, local pack…) */
|
|
92
92
|
post: operations["search"];
|
|
93
93
|
delete?: never;
|
|
94
94
|
options?: never;
|
|
@@ -156,7 +156,7 @@ interface paths {
|
|
|
156
156
|
};
|
|
157
157
|
get?: never;
|
|
158
158
|
put?: never;
|
|
159
|
-
/** Google Maps search (places with coordinates). Accepts `ll` ("@lat,lng,zoomz") */
|
|
159
|
+
/** Google Maps search (places with coordinates). Accepts `ll` ("@lat,lng,zoomz") to search around a point */
|
|
160
160
|
post: operations["maps"];
|
|
161
161
|
delete?: never;
|
|
162
162
|
options?: never;
|
|
@@ -266,40 +266,6 @@ interface paths {
|
|
|
266
266
|
patch?: never;
|
|
267
267
|
trace?: never;
|
|
268
268
|
};
|
|
269
|
-
"/v1/lens": {
|
|
270
|
-
parameters: {
|
|
271
|
-
query?: never;
|
|
272
|
-
header?: never;
|
|
273
|
-
path?: never;
|
|
274
|
-
cookie?: never;
|
|
275
|
-
};
|
|
276
|
-
get?: never;
|
|
277
|
-
put?: never;
|
|
278
|
-
/** Google Lens visual matches for an image URL (2 credits) */
|
|
279
|
-
post: operations["lens"];
|
|
280
|
-
delete?: never;
|
|
281
|
-
options?: never;
|
|
282
|
-
head?: never;
|
|
283
|
-
patch?: never;
|
|
284
|
-
trace?: never;
|
|
285
|
-
};
|
|
286
|
-
"/v1/ai-mode": {
|
|
287
|
-
parameters: {
|
|
288
|
-
query?: never;
|
|
289
|
-
header?: never;
|
|
290
|
-
path?: never;
|
|
291
|
-
cookie?: never;
|
|
292
|
-
};
|
|
293
|
-
get?: never;
|
|
294
|
-
put?: never;
|
|
295
|
-
/** Google AI Mode answer with citations (3 credits) */
|
|
296
|
-
post: operations["aiMode"];
|
|
297
|
-
delete?: never;
|
|
298
|
-
options?: never;
|
|
299
|
-
head?: never;
|
|
300
|
-
patch?: never;
|
|
301
|
-
trace?: never;
|
|
302
|
-
};
|
|
303
269
|
"/v1/webpage": {
|
|
304
270
|
parameters: {
|
|
305
271
|
query?: never;
|
|
@@ -465,7 +431,7 @@ interface paths {
|
|
|
465
431
|
};
|
|
466
432
|
get?: never;
|
|
467
433
|
put?: never;
|
|
468
|
-
/** Remote MCP server (streamable HTTP, JSON-RPC 2.0). Tools search, news, maps, scholar, webpage
|
|
434
|
+
/** Remote MCP server (streamable HTTP, JSON-RPC 2.0). Tools search, news, maps, scholar, webpage */
|
|
469
435
|
post: operations["mcp"];
|
|
470
436
|
delete?: never;
|
|
471
437
|
options?: never;
|
|
@@ -504,20 +470,20 @@ interface components {
|
|
|
504
470
|
SearchRequest: {
|
|
505
471
|
q: string;
|
|
506
472
|
/**
|
|
507
|
-
* @description Country code (ISO 3166-1 alpha-2)
|
|
473
|
+
* @description Country code (ISO 3166-1 alpha-2, case-insensitive; uk is accepted as gb). When omitted and location ends in a country name, that country is used
|
|
508
474
|
* @default us
|
|
509
475
|
*/
|
|
510
476
|
country?: string;
|
|
511
477
|
/**
|
|
512
|
-
* @description Interface language (e.g. en
|
|
478
|
+
* @description Interface language: a language code with an optional region (e.g. en, de, pt-br, zh-tw, es-419)
|
|
513
479
|
* @default en
|
|
514
480
|
*/
|
|
515
481
|
language?: string;
|
|
516
482
|
/** @description Free-text location, e.g. "Austin, Texas, United States" */
|
|
517
483
|
location?: string;
|
|
518
|
-
/** @description Pre-encoded Google location (overrides location) */
|
|
484
|
+
/** @description Pre-encoded Google location (overrides ll and location; percent-encoded values are decoded) */
|
|
519
485
|
uule?: string;
|
|
520
|
-
/** @description
|
|
486
|
+
/** @description Map point "@lat,lng,14z" (maps and places only; zoom optional): the search runs as a searcher at that point. Overrides location */
|
|
521
487
|
ll?: string;
|
|
522
488
|
/**
|
|
523
489
|
* @description 10, or up to 100 for the depth bundle on search and news (7 credits for 100; values between round up to whole pages). Other verticals return one page of 10
|
|
@@ -527,11 +493,11 @@ interface components {
|
|
|
527
493
|
/** @default 1 */
|
|
528
494
|
page?: number;
|
|
529
495
|
/**
|
|
530
|
-
* @description Only results from the last hour/day/…
|
|
496
|
+
* @description Only results from the last hour/day/… (search, news, images, videos, shopping). A fallback engine without that window is skipped, never answered unfiltered
|
|
531
497
|
* @enum {string}
|
|
532
498
|
*/
|
|
533
499
|
time?: "hour" | "day" | "week" | "month" | "year";
|
|
534
|
-
/** @description Advanced: raw Google tbs filter (e.g. qdr:d); overrides time */
|
|
500
|
+
/** @description Advanced: raw Google tbs filter (e.g. qdr:d, qdr:w2, cdr:1,cd_min:1/1/2026,cd_max:1/31/2026); overrides time */
|
|
535
501
|
tbs?: string;
|
|
536
502
|
/**
|
|
537
503
|
* @default desktop
|
|
@@ -550,15 +516,13 @@ interface components {
|
|
|
550
516
|
* @enum {string}
|
|
551
517
|
*/
|
|
552
518
|
format?: "json" | "markdown" | "compact";
|
|
553
|
-
/** @description Comma-separated projection, e.g. "results.title,results.link,
|
|
519
|
+
/** @description Comma-separated projection, e.g. "results.title,results.link,knowledge_graph" */
|
|
554
520
|
fields?: string;
|
|
555
521
|
/**
|
|
556
522
|
* @description Also fetch the top N organic pages as Markdown (+1 credit each fetched page)
|
|
557
523
|
* @default 0
|
|
558
524
|
*/
|
|
559
525
|
include_content?: number;
|
|
560
|
-
/** @default true */
|
|
561
|
-
ai_overview?: boolean;
|
|
562
526
|
/**
|
|
563
527
|
* @description Include sponsored results
|
|
564
528
|
* @default false
|
|
@@ -592,19 +556,6 @@ interface components {
|
|
|
592
556
|
fields?: string;
|
|
593
557
|
max_age?: number;
|
|
594
558
|
};
|
|
595
|
-
LensRequest: {
|
|
596
|
-
/**
|
|
597
|
-
* Format: uri
|
|
598
|
-
* @description Image URL
|
|
599
|
-
*/
|
|
600
|
-
url: string;
|
|
601
|
-
country?: string;
|
|
602
|
-
language?: string;
|
|
603
|
-
/** @enum {string} */
|
|
604
|
-
format?: "json" | "markdown" | "compact";
|
|
605
|
-
fields?: string;
|
|
606
|
-
max_age?: number;
|
|
607
|
-
};
|
|
608
559
|
WebpageRequest: {
|
|
609
560
|
/** Format: uri */
|
|
610
561
|
url: string;
|
|
@@ -662,7 +613,7 @@ interface components {
|
|
|
662
613
|
/**
|
|
663
614
|
* @example search
|
|
664
615
|
* @example news
|
|
665
|
-
* @example
|
|
616
|
+
* @example webpage
|
|
666
617
|
*/
|
|
667
618
|
endpoint: string;
|
|
668
619
|
/** @description The engine policy as asked (google, auto, one provider or a list) */
|
|
@@ -720,17 +671,6 @@ interface components {
|
|
|
720
671
|
*/
|
|
721
672
|
sources?: components["schemas"]["Provider"][];
|
|
722
673
|
};
|
|
723
|
-
Reference: {
|
|
724
|
-
title?: string;
|
|
725
|
-
link: string;
|
|
726
|
-
domain?: string;
|
|
727
|
-
snippet?: string;
|
|
728
|
-
};
|
|
729
|
-
AIOverview: {
|
|
730
|
-
text?: string;
|
|
731
|
-
markdown?: string;
|
|
732
|
-
references?: components["schemas"]["Reference"][];
|
|
733
|
-
};
|
|
734
674
|
AnswerBox: {
|
|
735
675
|
title?: string;
|
|
736
676
|
answer?: string;
|
|
@@ -762,7 +702,6 @@ interface components {
|
|
|
762
702
|
SearchResponse: {
|
|
763
703
|
request: components["schemas"]["RequestEcho"];
|
|
764
704
|
results: components["schemas"]["OrganicResult"][];
|
|
765
|
-
ai_overview: components["schemas"]["AIOverview"] | null;
|
|
766
705
|
answer_box?: components["schemas"]["AnswerBox"];
|
|
767
706
|
knowledge_graph?: components["schemas"]["KnowledgeGraph"];
|
|
768
707
|
ads?: components["schemas"]["OrganicResult"][];
|
|
@@ -935,28 +874,6 @@ interface components {
|
|
|
935
874
|
results: components["schemas"]["Suggestion"][];
|
|
936
875
|
meta: components["schemas"]["Meta"];
|
|
937
876
|
};
|
|
938
|
-
LensResult: {
|
|
939
|
-
position: number;
|
|
940
|
-
title: string;
|
|
941
|
-
source?: string;
|
|
942
|
-
link: string;
|
|
943
|
-
domain?: string;
|
|
944
|
-
image_url?: string;
|
|
945
|
-
thumbnail_url?: string;
|
|
946
|
-
};
|
|
947
|
-
LensResponse: {
|
|
948
|
-
request: components["schemas"]["RequestEcho"];
|
|
949
|
-
results: components["schemas"]["LensResult"][];
|
|
950
|
-
meta: components["schemas"]["Meta"];
|
|
951
|
-
};
|
|
952
|
-
AIModeResponse: {
|
|
953
|
-
request: components["schemas"]["RequestEcho"];
|
|
954
|
-
answer: string;
|
|
955
|
-
markdown?: string;
|
|
956
|
-
/** @description Cited sources */
|
|
957
|
-
results: components["schemas"]["Reference"][];
|
|
958
|
-
meta: components["schemas"]["Meta"];
|
|
959
|
-
};
|
|
960
877
|
PageMetadata: {
|
|
961
878
|
title?: string;
|
|
962
879
|
description?: string;
|
|
@@ -1059,7 +976,7 @@ interface components {
|
|
|
1059
976
|
};
|
|
1060
977
|
BatchCreateRequest: {
|
|
1061
978
|
/** @enum {string} */
|
|
1062
|
-
endpoint: "search" | "images" | "videos" | "news" | "maps" | "places" | "reviews" | "shopping" | "scholar" | "patents" | "autocomplete" | "
|
|
979
|
+
endpoint: "search" | "images" | "videos" | "news" | "maps" | "places" | "reviews" | "shopping" | "scholar" | "patents" | "autocomplete" | "webpage";
|
|
1063
980
|
/** @description Request bodies for `endpoint` (same fields as the realtime endpoint) */
|
|
1064
981
|
requests: {
|
|
1065
982
|
[key: string]: unknown;
|
|
@@ -1304,38 +1221,6 @@ interface components {
|
|
|
1304
1221
|
};
|
|
1305
1222
|
};
|
|
1306
1223
|
/** @description OK (text/markdown when format=markdown) */
|
|
1307
|
-
LensOK: {
|
|
1308
|
-
headers: {
|
|
1309
|
-
"X-Credits-Used": components["headers"]["CreditsUsed"];
|
|
1310
|
-
"X-Credits-Remaining": components["headers"]["CreditsRemaining"];
|
|
1311
|
-
"X-Cost-USD": components["headers"]["CostUSD"];
|
|
1312
|
-
"X-Cache": components["headers"]["Cache"];
|
|
1313
|
-
"X-Latency-Ms": components["headers"]["LatencyMs"];
|
|
1314
|
-
"X-Tokens-Estimate": components["headers"]["TokensEstimate"];
|
|
1315
|
-
[name: string]: unknown;
|
|
1316
|
-
};
|
|
1317
|
-
content: {
|
|
1318
|
-
"application/json": components["schemas"]["LensResponse"];
|
|
1319
|
-
"text/markdown": string;
|
|
1320
|
-
};
|
|
1321
|
-
};
|
|
1322
|
-
/** @description OK (text/markdown when format=markdown) */
|
|
1323
|
-
AIModeOK: {
|
|
1324
|
-
headers: {
|
|
1325
|
-
"X-Credits-Used": components["headers"]["CreditsUsed"];
|
|
1326
|
-
"X-Credits-Remaining": components["headers"]["CreditsRemaining"];
|
|
1327
|
-
"X-Cost-USD": components["headers"]["CostUSD"];
|
|
1328
|
-
"X-Cache": components["headers"]["Cache"];
|
|
1329
|
-
"X-Latency-Ms": components["headers"]["LatencyMs"];
|
|
1330
|
-
"X-Tokens-Estimate": components["headers"]["TokensEstimate"];
|
|
1331
|
-
[name: string]: unknown;
|
|
1332
|
-
};
|
|
1333
|
-
content: {
|
|
1334
|
-
"application/json": components["schemas"]["AIModeResponse"];
|
|
1335
|
-
"text/markdown": string;
|
|
1336
|
-
};
|
|
1337
|
-
};
|
|
1338
|
-
/** @description OK (text/markdown when format=markdown) */
|
|
1339
1224
|
WebpageOK: {
|
|
1340
1225
|
headers: {
|
|
1341
1226
|
"X-Credits-Used": components["headers"]["CreditsUsed"];
|
|
@@ -1392,7 +1277,6 @@ interface operations {
|
|
|
1392
1277
|
format?: string;
|
|
1393
1278
|
fields?: string;
|
|
1394
1279
|
include_content?: number;
|
|
1395
|
-
ai_overview?: boolean;
|
|
1396
1280
|
ads?: boolean;
|
|
1397
1281
|
max_age?: number;
|
|
1398
1282
|
/** @description google (default), auto, consensus, one provider, or a comma-separated list (e.g. google,brave) */
|
|
@@ -1616,46 +1500,6 @@ interface operations {
|
|
|
1616
1500
|
503: components["responses"]["Unavailable"];
|
|
1617
1501
|
};
|
|
1618
1502
|
};
|
|
1619
|
-
lens: {
|
|
1620
|
-
parameters: {
|
|
1621
|
-
query?: never;
|
|
1622
|
-
header?: never;
|
|
1623
|
-
path?: never;
|
|
1624
|
-
cookie?: never;
|
|
1625
|
-
};
|
|
1626
|
-
requestBody: {
|
|
1627
|
-
content: {
|
|
1628
|
-
"application/json": components["schemas"]["LensRequest"];
|
|
1629
|
-
};
|
|
1630
|
-
};
|
|
1631
|
-
responses: {
|
|
1632
|
-
200: components["responses"]["LensOK"];
|
|
1633
|
-
400: components["responses"]["Error"];
|
|
1634
|
-
401: components["responses"]["Error"];
|
|
1635
|
-
402: components["responses"]["Error"];
|
|
1636
|
-
403: components["responses"]["Error"];
|
|
1637
|
-
429: components["responses"]["Error"];
|
|
1638
|
-
503: components["responses"]["Unavailable"];
|
|
1639
|
-
};
|
|
1640
|
-
};
|
|
1641
|
-
aiMode: {
|
|
1642
|
-
parameters: {
|
|
1643
|
-
query?: never;
|
|
1644
|
-
header?: never;
|
|
1645
|
-
path?: never;
|
|
1646
|
-
cookie?: never;
|
|
1647
|
-
};
|
|
1648
|
-
requestBody: components["requestBodies"]["Search"];
|
|
1649
|
-
responses: {
|
|
1650
|
-
200: components["responses"]["AIModeOK"];
|
|
1651
|
-
400: components["responses"]["Error"];
|
|
1652
|
-
401: components["responses"]["Error"];
|
|
1653
|
-
402: components["responses"]["Error"];
|
|
1654
|
-
403: components["responses"]["Error"];
|
|
1655
|
-
429: components["responses"]["Error"];
|
|
1656
|
-
503: components["responses"]["Unavailable"];
|
|
1657
|
-
};
|
|
1658
|
-
};
|
|
1659
1503
|
webpage: {
|
|
1660
1504
|
parameters: {
|
|
1661
1505
|
query?: never;
|
|
@@ -1955,13 +1799,12 @@ type Engine = "google" | "auto" | "consensus" | Provider | Provider[] | (string
|
|
|
1955
1799
|
/** One provider attempt in `meta.route`. */
|
|
1956
1800
|
type RouteStep = Schemas["RouteStep"];
|
|
1957
1801
|
type RouteOutcome = RouteStep["outcome"];
|
|
1958
|
-
/** Parameters for search, images, videos, news, maps, places, shopping, scholar, patents
|
|
1802
|
+
/** Parameters for search, images, videos, news, maps, places, shopping, scholar, patents and autocomplete. */
|
|
1959
1803
|
type SearchParams = Omit<Schemas["SearchRequest"], "engine"> & {
|
|
1960
1804
|
/** Search providers allowed to answer. Default `"google"`. See {@link Engine}. */
|
|
1961
1805
|
engine?: Engine;
|
|
1962
1806
|
};
|
|
1963
1807
|
type ReviewsParams = Schemas["ReviewsRequest"];
|
|
1964
|
-
type LensParams = Schemas["LensRequest"];
|
|
1965
1808
|
type WebpageParams = Schemas["WebpageRequest"];
|
|
1966
1809
|
type RankParams = Schemas["RankRequest"];
|
|
1967
1810
|
/** `format` values accepted by the verticals. */
|
|
@@ -1971,8 +1814,6 @@ type RequestEcho = Schemas["RequestEcho"];
|
|
|
1971
1814
|
type ErrorBody = Schemas["Error"];
|
|
1972
1815
|
type OrganicResult = Schemas["OrganicResult"];
|
|
1973
1816
|
type Sitelink = Schemas["Sitelink"];
|
|
1974
|
-
type Reference = Schemas["Reference"];
|
|
1975
|
-
type AIOverview = Schemas["AIOverview"];
|
|
1976
1817
|
type AnswerBox = Schemas["AnswerBox"];
|
|
1977
1818
|
type KnowledgeGraph = Schemas["KnowledgeGraph"];
|
|
1978
1819
|
type PeopleAlsoAsk = Schemas["PeopleAlsoAsk"];
|
|
@@ -1986,7 +1827,6 @@ type ShoppingResult = Schemas["ShoppingResult"];
|
|
|
1986
1827
|
type ScholarResult = Schemas["ScholarResult"];
|
|
1987
1828
|
type PatentResult = Schemas["PatentResult"];
|
|
1988
1829
|
type Suggestion = Schemas["Suggestion"];
|
|
1989
|
-
type LensResult = Schemas["LensResult"];
|
|
1990
1830
|
type PageMetadata = Schemas["PageMetadata"];
|
|
1991
1831
|
type RankMatch = Schemas["RankResponse"]["matches"][number];
|
|
1992
1832
|
type SearchResponse = Schemas["SearchResponse"];
|
|
@@ -2001,8 +1841,6 @@ type ShoppingResponse = Schemas["ShoppingResponse"];
|
|
|
2001
1841
|
type ScholarResponse = Schemas["ScholarResponse"];
|
|
2002
1842
|
type PatentsResponse = Schemas["PatentsResponse"];
|
|
2003
1843
|
type AutocompleteResponse = Schemas["AutocompleteResponse"];
|
|
2004
|
-
type LensResponse = Schemas["LensResponse"];
|
|
2005
|
-
type AIModeResponse = Schemas["AIModeResponse"];
|
|
2006
1844
|
type WebpageResponse = Schemas["WebpageResponse"];
|
|
2007
1845
|
type RankResponse = Schemas["RankResponse"];
|
|
2008
1846
|
type Account = Schemas["Account"];
|
|
@@ -2041,8 +1879,6 @@ type BatchRequestMap = {
|
|
|
2041
1879
|
scholar: SearchParams;
|
|
2042
1880
|
patents: SearchParams;
|
|
2043
1881
|
autocomplete: SearchParams;
|
|
2044
|
-
lens: LensParams;
|
|
2045
|
-
"ai-mode": SearchParams;
|
|
2046
1882
|
webpage: WebpageParams;
|
|
2047
1883
|
};
|
|
2048
1884
|
/** Body of `POST /v1/batches`. `requests` takes the same fields as the realtime endpoint. */
|
|
@@ -2056,7 +1892,7 @@ type BatchCreateParams = {
|
|
|
2056
1892
|
};
|
|
2057
1893
|
}[BatchEndpoint];
|
|
2058
1894
|
|
|
2059
|
-
declare const VERSION = "0.
|
|
1895
|
+
declare const VERSION = "0.3.0";
|
|
2060
1896
|
declare const DEFAULT_BASE_URL = "https://api.serpkite.com";
|
|
2061
1897
|
interface SerpKiteOptions {
|
|
2062
1898
|
/** API key (`skt_live_…`). Defaults to the `SERPKITE_API_KEY` environment variable. */
|
|
@@ -2143,11 +1979,10 @@ declare class SerpKite {
|
|
|
2143
1979
|
readonly maxRetries: number;
|
|
2144
1980
|
readonly retryDelayMs: number;
|
|
2145
1981
|
constructor(options?: SerpKiteOptions);
|
|
2146
|
-
/** Google web search: organic results,
|
|
1982
|
+
/** Google web search: organic results, answer box, knowledge graph, people also ask… */
|
|
2147
1983
|
readonly search: VerticalMethod<SearchParams, {
|
|
2148
1984
|
request: components["schemas"]["RequestEcho"];
|
|
2149
1985
|
results: components["schemas"]["OrganicResult"][];
|
|
2150
|
-
ai_overview: components["schemas"]["AIOverview"] | null;
|
|
2151
1986
|
answer_box?: components["schemas"]["AnswerBox"];
|
|
2152
1987
|
knowledge_graph?: components["schemas"]["KnowledgeGraph"];
|
|
2153
1988
|
ads?: components["schemas"]["OrganicResult"][];
|
|
@@ -2230,14 +2065,6 @@ declare class SerpKite {
|
|
|
2230
2065
|
results: components["schemas"]["Suggestion"][];
|
|
2231
2066
|
meta: components["schemas"]["Meta"];
|
|
2232
2067
|
}>;
|
|
2233
|
-
/** Google AI Mode answer with cited sources. */
|
|
2234
|
-
readonly aiMode: VerticalMethod<SearchParams, {
|
|
2235
|
-
request: components["schemas"]["RequestEcho"];
|
|
2236
|
-
answer: string;
|
|
2237
|
-
markdown?: string;
|
|
2238
|
-
results: components["schemas"]["Reference"][];
|
|
2239
|
-
meta: components["schemas"]["Meta"];
|
|
2240
|
-
}>;
|
|
2241
2068
|
/** Fetch any public URL as clean Markdown plus metadata. */
|
|
2242
2069
|
readonly webpage: VerticalMethod<{
|
|
2243
2070
|
url: string;
|
|
@@ -2254,8 +2081,6 @@ declare class SerpKite {
|
|
|
2254
2081
|
metadata: components["schemas"]["PageMetadata"];
|
|
2255
2082
|
meta: components["schemas"]["Meta"];
|
|
2256
2083
|
}>;
|
|
2257
|
-
/** Google Lens visual matches for an image URL. */
|
|
2258
|
-
lens(params: LensParams, options?: RequestOptions): Promise<LensResponse>;
|
|
2259
2084
|
/** Position of `domain` for keyword `q` in the top `num` results (default 100). */
|
|
2260
2085
|
rank(params: RankParams, options?: RequestOptions): Promise<RankResponse>;
|
|
2261
2086
|
/** Balance, limits and this month's usage for the key's account. */
|
|
@@ -2343,4 +2168,4 @@ type HeaderSource = Headers | Record<string, string | string[] | undefined>;
|
|
|
2343
2168
|
*/
|
|
2344
2169
|
declare function verifyWebhook(secret: string, payload: string | Uint8Array, headers: HeaderSource, options?: VerifyWebhookOptions): Promise<boolean>;
|
|
2345
2170
|
|
|
2346
|
-
export { type
|
|
2171
|
+
export { type Account, type AnswerBox, type AutocompleteResponse, type Batch, type BatchCreateEntry, type BatchCreateError, type BatchCreateOptions, type BatchCreateParams, type BatchCreateResponse, type BatchEndpoint, type BatchStatus, type CompactResponse, DEFAULT_BASE_URL, type Engine, type ErrorBody, type Format, type ImageResult, type ImagesResponse, type KnowledgeGraph, type MapsResponse, type Meta, type NewsResponse, type NewsResult, type OrganicResult, type PageMetadata, type PatentResult, type PatentsResponse, type PeopleAlsoAsk, type PlaceResult, type PlacesResponse, type Provider, type RankMatch, type RankParams, type RankResponse, type RelatedSearch, type RequestEcho, type RequestOptions, type ResponseInfo, type ReviewResult, type ReviewsParams, type ReviewsResponse, type RouteOutcome, type RouteStep, type ScholarResponse, type ScholarResult, type SearchParams, type SearchResponse, SerpKite, SerpKiteError, type SerpKiteOptions, type ShoppingResponse, type ShoppingResult, type Sitelink, type Status, type Suggestion, VERSION, type VerifyWebhookOptions, type VerticalMethod, type VideoResult, type VideosResponse, type WaitOptions, type WebpageParams, type WebpageResponse, type components, isBatchError, type operations, parseRetryAfter, type paths, verifyWebhook };
|
package/dist/index.js
CHANGED
|
@@ -48,7 +48,7 @@ function errorFromResponse(status, headers, body) {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
// src/client.ts
|
|
51
|
-
var VERSION = "0.
|
|
51
|
+
var VERSION = "0.3.0";
|
|
52
52
|
var DEFAULT_BASE_URL = "https://api.serpkite.com";
|
|
53
53
|
var SerpKite = class {
|
|
54
54
|
baseUrl;
|
|
@@ -87,7 +87,7 @@ var SerpKite = class {
|
|
|
87
87
|
this.#headers = { ...options.headers };
|
|
88
88
|
}
|
|
89
89
|
// ── Verticals ─────────────────────────────────────────────────────────
|
|
90
|
-
/** Google web search: organic results,
|
|
90
|
+
/** Google web search: organic results, answer box, knowledge graph, people also ask… */
|
|
91
91
|
search = this.#vertical("/v1/search");
|
|
92
92
|
/** Google Images. */
|
|
93
93
|
images = this.#vertical("/v1/images");
|
|
@@ -109,14 +109,8 @@ var SerpKite = class {
|
|
|
109
109
|
patents = this.#vertical("/v1/patents");
|
|
110
110
|
/** Google autocomplete suggestions. */
|
|
111
111
|
autocomplete = this.#vertical("/v1/autocomplete");
|
|
112
|
-
/** Google AI Mode answer with cited sources. */
|
|
113
|
-
aiMode = this.#vertical("/v1/ai-mode");
|
|
114
112
|
/** Fetch any public URL as clean Markdown plus metadata. */
|
|
115
113
|
webpage = this.#vertical("/v1/webpage");
|
|
116
|
-
/** Google Lens visual matches for an image URL. */
|
|
117
|
-
lens(params, options) {
|
|
118
|
-
return this.request({ method: "POST", path: "/v1/lens", body: params, options });
|
|
119
|
-
}
|
|
120
114
|
/** Position of `domain` for keyword `q` in the top `num` results (default 100). */
|
|
121
115
|
rank(params, options) {
|
|
122
116
|
return this.request({ method: "POST", path: "/v1/rank", body: params, options });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/client.ts","../src/util.ts","../src/webhooks.ts"],"names":[],"mappings":";AAKO,IAAM,aAAA,GAAN,cAA4B,KAAA,CAAM;AAAA;AAAA,EAE9B,MAAA;AAAA;AAAA,EAEA,IAAA;AAAA;AAAA,EAEA,SAAA;AAAA;AAAA,EAEA,OAAA;AAAA,EAET,YACE,MAAA,EACA,IAAA,EACA,OAAA,EACA,SAAA,EACA,SACA,OAAA,EACA;AACA,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AACtB,IAAA,IAAA,CAAK,IAAA,GAAO,eAAA;AACZ,IAAA,IAAA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AAS,CAAA;AAClB","file":"index.js","sourcesContent":["/**\n * Every failure thrown by the SDK. API errors carry the fields of the\n * `{\"error\":{\"code\",\"message\",\"request_id\"}}` envelope; network failures and\n * timeouts use `status: 0` with code `connection_error` or `timeout`.\n */\nexport class SerpKiteError extends Error {\n /** HTTP status, or 0 when no response was received. */\n readonly status: number;\n /** Machine-readable code, e.g. `unauthorized`, `insufficient_credits`, `rate_limited`. */\n readonly code: string;\n /** `X-Request-Id` of the failed request, when the API returned one. */\n readonly requestId: string | undefined;\n /** Response headers, when the API responded. */\n readonly headers: Headers | undefined;\n\n constructor(\n status: number,\n code: string,\n message: string,\n requestId?: string,\n headers?: Headers,\n options?: { cause?: unknown },\n ) {\n super(message, options);\n this.name = \"SerpKiteError\";\n this.status = status;\n this.code = code;\n this.requestId = requestId || undefined;\n this.headers = headers;\n }\n}\n\nconst fallbackCodes: Record<number, string> = {\n 400: \"invalid_request\",\n 401: \"unauthorized\",\n 402: \"insufficient_credits\",\n 403: \"forbidden\",\n 404: \"not_found\",\n 429: \"rate_limited\",\n // The API sends upstream failures as 503 with a JSON body; a bare 502/504\n // comes from a proxy (Cloudflare replaces origin 502/504 bodies).\n 502: \"upstream_error\",\n 503: \"unavailable\",\n 504: \"upstream_timeout\",\n};\n\n/** Builds a SerpKiteError from a non-2xx response body (JSON envelope or anything else). */\nexport function errorFromResponse(status: number, headers: Headers, body: string): SerpKiteError {\n let code = fallbackCodes[status] ?? (status >= 500 ? \"server_error\" : \"http_error\");\n let message = body.trim().slice(0, 500) || `HTTP ${status}`;\n let requestId = headers.get(\"x-request-id\") ?? undefined;\n try {\n const parsed = JSON.parse(body) as {\n error?: { code?: unknown; message?: unknown; request_id?: unknown };\n };\n const e = parsed?.error;\n if (e && typeof e === \"object\") {\n if (typeof e.code === \"string\" && e.code) code = e.code;\n if (typeof e.message === \"string\" && e.message) message = e.message;\n if (typeof e.request_id === \"string\" && e.request_id) requestId = e.request_id;\n }\n } catch {\n // Not JSON: keep the text body as the message.\n }\n return new SerpKiteError(status, code, message, requestId, headers);\n}\n","import { errorFromResponse, SerpKiteError } from \"./errors\";\nimport type {\n Account,\n AIModeResponse,\n AutocompleteResponse,\n Batch,\n BatchCreateEntry,\n BatchCreateParams,\n BatchCreateResponse,\n CompactResponse,\n ImagesResponse,\n LensParams,\n LensResponse,\n NewsResponse,\n PatentsResponse,\n PlacesResponse,\n RankParams,\n RankResponse,\n ReviewsParams,\n ReviewsResponse,\n ScholarResponse,\n SearchParams,\n SearchResponse,\n ShoppingResponse,\n VideosResponse,\n WebpageParams,\n WebpageResponse,\n} from \"./types\";\n\nexport const VERSION = \"0.1.1\";\nexport const DEFAULT_BASE_URL = \"https://api.serpkite.com\";\n\nexport interface SerpKiteOptions {\n /** API key (`skt_live_…`). Defaults to the `SERPKITE_API_KEY` environment variable. */\n apiKey?: string;\n /** Defaults to `SERPKITE_BASE_URL` or https://api.serpkite.com. */\n baseUrl?: string;\n /** Per-attempt timeout in milliseconds. Default 60000. */\n timeoutMs?: number;\n /** Retries after the first attempt on 429, 5xx and network errors. Default 2. */\n maxRetries?: number;\n /** Base delay of the exponential backoff in milliseconds. Default 500. */\n retryDelayMs?: number;\n /** Custom fetch implementation. Defaults to the global `fetch`. */\n fetch?: typeof fetch;\n /** Extra headers sent with every request. */\n headers?: Record<string, string>;\n}\n\n/** Billing and tracing details from the response headers. */\nexport interface ResponseInfo {\n status: number;\n headers: Headers;\n requestId: string | undefined;\n creditsUsed: number | undefined;\n creditsRemaining: number | undefined;\n costUsd: number | undefined;\n /** `HIT` when served from cache (`max_age`), else `MISS`. */\n cache: \"HIT\" | \"MISS\" | undefined;\n latencyMs: number | undefined;\n tokensEstimate: number | undefined;\n}\n\nexport interface RequestOptions {\n signal?: AbortSignal;\n /** Overrides the client's per-attempt timeout. */\n timeoutMs?: number;\n /** Overrides the client's retry count. */\n maxRetries?: number;\n headers?: Record<string, string>;\n /** Called with the final response's headers (credits used/remaining, cache, request id). */\n onResponse?: (info: ResponseInfo) => void;\n}\n\nexport interface BatchCreateOptions extends RequestOptions {\n /**\n * Sent as `Idempotency-Key` (1-255 printable ASCII characters, e.g. a UUID).\n * For 24 hours a retry with the same key and body returns the first response\n * instead of queueing and billing the jobs again.\n */\n idempotencyKey?: string;\n}\n\nexport interface WaitOptions {\n /** Give up after this many milliseconds. Default 600000 (10 minutes). */\n timeoutMs?: number;\n /** First delay between polls. Default 1000. Grows 1.5× per poll. */\n pollIntervalMs?: number;\n /** Upper bound of the delay between polls. Default 10000. */\n maxPollIntervalMs?: number;\n signal?: AbortSignal;\n}\n\n/** A vertical whose return type follows `format`: `\"markdown\"` → string, `\"compact\"` → CompactResponse. */\nexport interface VerticalMethod<P, R> {\n (params: P & { format: \"markdown\" }, options?: RequestOptions): Promise<string>;\n (params: P & { format: \"compact\" }, options?: RequestOptions): Promise<CompactResponse>;\n (params: P & { format?: \"json\" }, options?: RequestOptions): Promise<R>;\n (params: P, options?: RequestOptions): Promise<R | CompactResponse | string>;\n}\n\ntype Method = \"GET\" | \"POST\";\n\ninterface Call {\n method: Method;\n path: string;\n body?: unknown;\n options?: RequestOptions;\n /** Which failures are safe to retry. `all` = 429, 5xx and network errors. */\n retry?: \"all\" | \"rate_limit\";\n}\n\nexport class SerpKite {\n readonly baseUrl: string;\n readonly timeoutMs: number;\n readonly maxRetries: number;\n readonly retryDelayMs: number;\n readonly #apiKey: string;\n readonly #fetch: typeof fetch;\n readonly #headers: Record<string, string>;\n\n constructor(options: SerpKiteOptions = {}) {\n const apiKey = options.apiKey ?? env(\"SERPKITE_API_KEY\");\n if (!apiKey) {\n throw new SerpKiteError(\n 0,\n \"missing_api_key\",\n \"No API key: pass { apiKey } or set the SERPKITE_API_KEY environment variable\",\n );\n }\n this.#apiKey = apiKey;\n this.baseUrl = (options.baseUrl ?? env(\"SERPKITE_BASE_URL\") ?? DEFAULT_BASE_URL).replace(\n /\\/+$/,\n \"\",\n );\n this.timeoutMs = options.timeoutMs ?? 60_000;\n this.maxRetries = Math.max(0, options.maxRetries ?? 2);\n this.retryDelayMs = options.retryDelayMs ?? 500;\n const f = options.fetch ?? globalThis.fetch;\n if (typeof f !== \"function\") {\n throw new SerpKiteError(\n 0,\n \"missing_fetch\",\n \"No global fetch: pass { fetch } (Node 18+ has one)\",\n );\n }\n this.#fetch = f;\n this.#headers = { ...options.headers };\n }\n\n // ── Verticals ─────────────────────────────────────────────────────────\n\n /** Google web search: organic results, AI Overview, answer box, knowledge graph, people also ask… */\n readonly search = this.#vertical<SearchParams, SearchResponse>(\"/v1/search\");\n /** Google Images. */\n readonly images = this.#vertical<SearchParams, ImagesResponse>(\"/v1/images\");\n /** Google Videos. */\n readonly videos = this.#vertical<SearchParams, VideosResponse>(\"/v1/videos\");\n /** Google News. */\n readonly news = this.#vertical<SearchParams, NewsResponse>(\"/v1/news\");\n /** Google Maps search (places with coordinates). Accepts `ll` (\"@lat,lng,14z\"). */\n readonly maps = this.#vertical<SearchParams, PlacesResponse>(\"/v1/maps\");\n /** Google local results. */\n readonly places = this.#vertical<SearchParams, PlacesResponse>(\"/v1/places\");\n /** Reviews of a place by `place_id`, `cid` or `fid`. Page with `page_token` = `next_page_token`. */\n readonly reviews = this.#vertical<ReviewsParams, ReviewsResponse>(\"/v1/reviews\");\n /** Google Shopping. */\n readonly shopping = this.#vertical<SearchParams, ShoppingResponse>(\"/v1/shopping\");\n /** Google Scholar. */\n readonly scholar = this.#vertical<SearchParams, ScholarResponse>(\"/v1/scholar\");\n /** Google Patents. */\n readonly patents = this.#vertical<SearchParams, PatentsResponse>(\"/v1/patents\");\n /** Google autocomplete suggestions. */\n readonly autocomplete = this.#vertical<SearchParams, AutocompleteResponse>(\"/v1/autocomplete\");\n /** Google AI Mode answer with cited sources. */\n readonly aiMode = this.#vertical<SearchParams, AIModeResponse>(\"/v1/ai-mode\");\n /** Fetch any public URL as clean Markdown plus metadata. */\n readonly webpage = this.#vertical<WebpageParams, WebpageResponse>(\"/v1/webpage\");\n\n /** Google Lens visual matches for an image URL. */\n lens(params: LensParams, options?: RequestOptions): Promise<LensResponse> {\n return this.request({ method: \"POST\", path: \"/v1/lens\", body: params, options });\n }\n\n /** Position of `domain` for keyword `q` in the top `num` results (default 100). */\n rank(params: RankParams, options?: RequestOptions): Promise<RankResponse> {\n return this.request({ method: \"POST\", path: \"/v1/rank\", body: params, options });\n }\n\n /** Balance, limits and this month's usage for the key's account. */\n account(options?: RequestOptions): Promise<Account> {\n return this.request({ method: \"GET\", path: \"/v1/account\", options });\n }\n\n // ── Batches ───────────────────────────────────────────────────────────\n\n readonly batches = {\n /**\n * Queue 1-100 requests for one endpoint at half price. Returns one entry per\n * request, in order: a queued `Batch` or an error object. Without an\n * `idempotencyKey` it is only retried on 429, so a lost response never queues\n * (and bills) the same requests twice. With one, 5xx and network errors are\n * retried too: the server replays the first response for the same key and body.\n */\n create: (\n params: BatchCreateParams,\n options: BatchCreateOptions = {},\n ): Promise<BatchCreateResponse> => {\n const { idempotencyKey, ...rest } = options;\n return this.request({\n method: \"POST\",\n path: \"/v1/batches\",\n body: params,\n options: idempotencyKey\n ? { ...rest, headers: { ...rest.headers, \"Idempotency-Key\": idempotencyKey } }\n : rest,\n retry: idempotencyKey ? \"all\" : \"rate_limit\",\n });\n },\n\n /** Poll one batch job. */\n get: (id: string, options?: RequestOptions): Promise<Batch> =>\n this.request({ method: \"GET\", path: `/v1/batches/${encodeURIComponent(id)}`, options }),\n\n /**\n * Poll until the job is `done` or `failed` and return it (a failed job is\n * returned, not thrown; check `status` and `error`). Accepts an id or an\n * entry from `create`; an entry that failed to queue throws its error.\n */\n wait: (idOrEntry: string | BatchCreateEntry | undefined, options: WaitOptions = {}) =>\n this.#wait(idOrEntry, options),\n };\n\n // ── Plumbing ──────────────────────────────────────────────────────────\n\n #vertical<P, R>(path: string): VerticalMethod<P, R> {\n return ((params: P, options?: RequestOptions) =>\n this.request({ method: \"POST\", path, body: params, options })) as VerticalMethod<P, R>;\n }\n\n async #wait(idOrEntry: string | BatchCreateEntry | undefined, o: WaitOptions): Promise<Batch> {\n let id: string | undefined;\n if (typeof idOrEntry === \"string\") {\n id = idOrEntry;\n } else if (idOrEntry && \"id\" in idOrEntry && typeof idOrEntry.id === \"string\") {\n id = idOrEntry.id;\n } else if (idOrEntry && \"error\" in idOrEntry && idOrEntry.error && !(\"id\" in idOrEntry)) {\n const e = idOrEntry.error as { code?: string; message?: string; request_id?: string };\n throw new SerpKiteError(\n 400,\n e.code ?? \"invalid_request\",\n e.message ?? \"batch entry was not queued\",\n e.request_id,\n );\n }\n if (!id) {\n throw new SerpKiteError(0, \"invalid_request\", \"batches.wait needs a batch id\");\n }\n const timeoutMs = o.timeoutMs ?? 600_000;\n const maxInterval = o.maxPollIntervalMs ?? 10_000;\n let interval = o.pollIntervalMs ?? 1_000;\n const deadline = Date.now() + timeoutMs;\n for (;;) {\n const batch = await this.batches.get(id, { signal: o.signal });\n if (batch.status === \"done\" || batch.status === \"failed\") return batch;\n const left = deadline - Date.now();\n if (left <= 0) {\n throw new SerpKiteError(\n 0,\n \"timeout\",\n `batch ${id} still ${batch.status} after ${timeoutMs} ms`,\n );\n }\n await sleep(Math.min(interval, left), o.signal);\n interval = Math.min(interval * 1.5, maxInterval);\n }\n }\n\n /** Low-level request: JSON body in, parsed JSON (or text for non-JSON responses) out. */\n async request<T>(call: Call): Promise<T> {\n const { method, path, body, options = {} } = call;\n const maxRetries = Math.max(0, options.maxRetries ?? this.maxRetries);\n const timeoutMs = options.timeoutMs ?? this.timeoutMs;\n const headers: Record<string, string> = {\n Accept: \"application/json, text/markdown;q=0.9\",\n Authorization: `Bearer ${this.#apiKey}`,\n ...this.#headers,\n ...options.headers,\n };\n if (body !== undefined) headers[\"Content-Type\"] = \"application/json\";\n // Browsers would turn a custom User-Agent into a CORS preflight header.\n if (!isBrowser()) headers[\"User-Agent\"] = `serpkite-typescript/${VERSION}`;\n const init: RequestInit = {\n method,\n headers,\n body: body === undefined ? undefined : JSON.stringify(body),\n };\n\n for (let attempt = 0; ; attempt++) {\n const canRetry = attempt < maxRetries;\n let res: Response;\n const { signal, cleanup, timedOut } = withTimeout(options.signal, timeoutMs);\n try {\n res = await this.#fetch(this.baseUrl + path, { ...init, signal });\n } catch (err) {\n cleanup();\n if (options.signal?.aborted) throw err;\n const code = timedOut() ? \"timeout\" : \"connection_error\";\n if (canRetry && call.retry !== \"rate_limit\") {\n await sleep(this.#backoff(attempt), options.signal);\n continue;\n }\n const msg = timedOut()\n ? `request timed out after ${timeoutMs} ms`\n : `request failed: ${err instanceof Error ? err.message : String(err)}`;\n throw new SerpKiteError(0, code, msg, undefined, undefined, { cause: err });\n }\n\n let text: string;\n try {\n text = await res.text();\n } catch (err) {\n cleanup();\n if (options.signal?.aborted) throw err;\n if (canRetry && call.retry !== \"rate_limit\") {\n await sleep(this.#backoff(attempt), options.signal);\n continue;\n }\n const code = timedOut() ? \"timeout\" : \"connection_error\";\n throw new SerpKiteError(\n 0,\n code,\n \"failed to read the response body\",\n undefined,\n res.headers,\n {\n cause: err,\n },\n );\n }\n cleanup();\n\n if (!res.ok) {\n const retryable = res.status === 429 || (res.status >= 500 && call.retry !== \"rate_limit\");\n if (canRetry && retryable) {\n await sleep(this.#retryDelay(attempt, res.headers), options.signal);\n continue;\n }\n throw errorFromResponse(res.status, res.headers, text);\n }\n\n options.onResponse?.(responseInfo(res));\n const type = res.headers.get(\"content-type\") ?? \"\";\n if (type.includes(\"json\")) {\n try {\n return JSON.parse(text) as T;\n } catch (err) {\n throw new SerpKiteError(\n res.status,\n \"invalid_response\",\n \"response is not valid JSON\",\n res.headers.get(\"x-request-id\") ?? undefined,\n res.headers,\n { cause: err },\n );\n }\n }\n return text as T;\n }\n }\n\n #backoff(attempt: number): number {\n const base = Math.min(this.retryDelayMs * 2 ** attempt, 8_000);\n return base / 2 + Math.random() * (base / 2);\n }\n\n #retryDelay(attempt: number, headers: Headers): number {\n const after = parseRetryAfter(headers.get(\"retry-after\"));\n return after === undefined ? this.#backoff(attempt) : Math.min(after, 60_000);\n }\n}\n\n// ── helpers ─────────────────────────────────────────────────────────────\n\n/** Parses Retry-After (seconds or an HTTP date) into milliseconds. */\nexport function parseRetryAfter(v: string | null): number | undefined {\n if (!v) return undefined;\n const secs = Number(v);\n if (Number.isFinite(secs)) return Math.max(0, secs * 1000);\n const at = Date.parse(v);\n return Number.isNaN(at) ? undefined : Math.max(0, at - Date.now());\n}\n\nfunction responseInfo(res: Response): ResponseInfo {\n const h = res.headers;\n const num = (name: string) => {\n const v = h.get(name);\n if (v === null || v === \"\") return undefined;\n const n = Number(v);\n return Number.isFinite(n) ? n : undefined;\n };\n const cache = h.get(\"x-cache\")?.toUpperCase();\n return {\n status: res.status,\n headers: h,\n requestId: h.get(\"x-request-id\") ?? undefined,\n creditsUsed: num(\"x-credits-used\"),\n creditsRemaining: num(\"x-credits-remaining\"),\n costUsd: num(\"x-cost-usd\"),\n cache: cache === \"HIT\" || cache === \"MISS\" ? cache : undefined,\n latencyMs: num(\"x-latency-ms\"),\n tokensEstimate: num(\"x-tokens-estimate\"),\n };\n}\n\nfunction withTimeout(outer: AbortSignal | undefined, ms: number) {\n const ctrl = new AbortController();\n let timedOut = false;\n const onAbort = () => ctrl.abort(outer?.reason);\n if (outer?.aborted) ctrl.abort(outer.reason);\n else outer?.addEventListener(\"abort\", onAbort, { once: true });\n const timer =\n ms > 0 && Number.isFinite(ms)\n ? setTimeout(() => {\n timedOut = true;\n ctrl.abort(new SerpKiteError(0, \"timeout\", `request timed out after ${ms} ms`));\n }, ms)\n : undefined;\n return {\n signal: ctrl.signal,\n timedOut: () => timedOut,\n cleanup: () => {\n if (timer !== undefined) clearTimeout(timer);\n outer?.removeEventListener(\"abort\", onAbort);\n },\n };\n}\n\nfunction sleep(ms: number, signal?: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n if (signal?.aborted) return reject(signal.reason);\n const t = setTimeout(() => {\n signal?.removeEventListener(\"abort\", onAbort);\n resolve();\n }, ms);\n const onAbort = () => {\n clearTimeout(t);\n reject(signal?.reason);\n };\n signal?.addEventListener(\"abort\", onAbort, { once: true });\n });\n}\n\ntype EnvHost = {\n process?: { env?: Record<string, string | undefined> };\n Deno?: { env?: { get?: (name: string) => string | undefined } };\n document?: unknown;\n};\n\nfunction env(name: string): string | undefined {\n const g = globalThis as EnvHost;\n try {\n const v = g.process?.env?.[name];\n if (v) return v;\n } catch {\n // process.env may be a throwing proxy on some edge runtimes.\n }\n try {\n return g.Deno?.env?.get?.(name) || undefined;\n } catch {\n // Deno without --allow-env.\n return undefined;\n }\n}\n\nfunction isBrowser(): boolean {\n return typeof (globalThis as EnvHost).document !== \"undefined\";\n}\n","import type { BatchCreateEntry, BatchCreateError } from \"./types\";\n\n/** True when a `batches.create` entry was rejected instead of queued. */\nexport function isBatchError(entry: BatchCreateEntry): entry is BatchCreateError {\n return !(\"id\" in entry && typeof entry.id === \"string\") && \"error\" in entry && !!entry.error;\n}\n","/** Options for {@link verifyWebhook}. */\nexport interface VerifyWebhookOptions {\n /** Reject deliveries whose timestamp is further than this from now. Default 300. */\n toleranceSeconds?: number;\n /** Current time in Unix seconds (tests). */\n now?: number;\n}\n\ntype HeaderSource = Headers | Record<string, string | string[] | undefined>;\n\nfunction header(headers: HeaderSource, name: string): string | undefined {\n if (typeof (headers as Headers).get === \"function\") {\n return (headers as Headers).get(name) ?? undefined;\n }\n const rec = headers as Record<string, string | string[] | undefined>;\n const key = Object.keys(rec).find((k) => k.toLowerCase() === name.toLowerCase());\n const v = key === undefined ? undefined : rec[key];\n return Array.isArray(v) ? v[0] : v;\n}\n\n/**\n * Checks a batch webhook delivery: `X-SerpKite-Signature` must be\n * `v1=<hex HMAC-SHA256(secret, \"<X-SerpKite-Timestamp>.<raw body>\")>` and the\n * timestamp recent. Pass the raw request body exactly as received (not\n * re-serialised JSON). Uses Web Crypto (Node 18+, Deno, Bun, browsers).\n *\n * ```ts\n * const ok = await verifyWebhook(process.env.SERPKITE_WEBHOOK_SECRET!, rawBody, req.headers);\n * ```\n */\nexport async function verifyWebhook(\n secret: string,\n payload: string | Uint8Array,\n headers: HeaderSource,\n options: VerifyWebhookOptions = {},\n): Promise<boolean> {\n const signature = header(headers, \"x-serpkite-signature\");\n const ts = header(headers, \"x-serpkite-timestamp\");\n if (!secret || !signature?.startsWith(\"v1=\") || !ts || !/^\\d+$/.test(ts)) return false;\n const now = options.now ?? Math.floor(Date.now() / 1000);\n if (Math.abs(now - Number(ts)) > (options.toleranceSeconds ?? 300)) return false;\n\n const enc = new TextEncoder();\n const body = typeof payload === \"string\" ? enc.encode(payload) : payload;\n const prefix = enc.encode(`${ts}.`);\n const msg = new Uint8Array(prefix.length + body.length);\n msg.set(prefix);\n msg.set(body, prefix.length);\n const key = await crypto.subtle.importKey(\n \"raw\",\n enc.encode(secret),\n { name: \"HMAC\", hash: \"SHA-256\" },\n false,\n [\"sign\"],\n );\n const mac = new Uint8Array(await crypto.subtle.sign(\"HMAC\", key, msg));\n const want = Array.from(mac, (b) => b.toString(16).padStart(2, \"0\")).join(\"\");\n const got = signature.slice(3).toLowerCase();\n if (got.length !== want.length) return false;\n let diff = 0;\n for (let i = 0; i < want.length; i++) diff |= want.charCodeAt(i) ^ got.charCodeAt(i);\n return diff === 0;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/client.ts","../src/util.ts","../src/webhooks.ts"],"names":[],"mappings":";AAKO,IAAM,aAAA,GAAN,cAA4B,KAAA,CAAM;AAAA;AAAA,EAE9B,MAAA;AAAA;AAAA,EAEA,IAAA;AAAA;AAAA,EAEA,SAAA;AAAA;AAAA,EAEA,OAAA;AAAA,EAET,YACE,MAAA,EACA,IAAA,EACA,OAAA,EACA,SAAA,EACA,SACA,OAAA,EACA;AACA,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AACtB,IAAA,IAAA,CAAK,IAAA,GAAO,eAAA;AACZ,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAA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C9B,KAAA;AAAA,IACA,GAAA,CAAI,OAAO,MAAM,CAAA;AAAA,IACjB,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,SAAA,EAAU;AAAA,IAChC,KAAA;AAAA,IACA,CAAC,MAAM;AAAA,GACT;AACA,EAAA,MAAM,GAAA,GAAM,IAAI,UAAA,CAAW,MAAM,MAAA,CAAO,OAAO,IAAA,CAAK,MAAA,EAAQ,GAAA,EAAK,GAAG,CAAC,CAAA;AACrE,EAAA,MAAM,OAAO,KAAA,CAAM,IAAA,CAAK,GAAA,EAAK,CAAC,MAAM,CAAA,CAAE,QAAA,CAAS,EAAE,CAAA,CAAE,SAAS,CAAA,EAAG,GAAG,CAAC,CAAA,CAAE,KAAK,EAAE,CAAA;AAC5E,EAAA,MAAM,GAAA,GAAM,SAAA,CAAU,KAAA,CAAM,CAAC,EAAE,WAAA,EAAY;AAC3C,EAAA,IAAI,GAAA,CAAI,MAAA,KAAW,IAAA,CAAK,MAAA,EAAQ,OAAO,KAAA;AACvC,EAAA,IAAI,IAAA,GAAO,CAAA;AACX,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,IAAA,CAAK,MAAA,EAAQ,CAAA,EAAA,EAAK,IAAA,IAAQ,IAAA,CAAK,UAAA,CAAW,CAAC,CAAA,GAAI,GAAA,CAAI,WAAW,CAAC,CAAA;AACnF,EAAA,OAAO,IAAA,KAAS,CAAA;AAClB","file":"index.js","sourcesContent":["/**\n * Every failure thrown by the SDK. API errors carry the fields of the\n * `{\"error\":{\"code\",\"message\",\"request_id\"}}` envelope; network failures and\n * timeouts use `status: 0` with code `connection_error` or `timeout`.\n */\nexport class SerpKiteError extends Error {\n /** HTTP status, or 0 when no response was received. */\n readonly status: number;\n /** Machine-readable code, e.g. `unauthorized`, `insufficient_credits`, `rate_limited`. */\n readonly code: string;\n /** `X-Request-Id` of the failed request, when the API returned one. */\n readonly requestId: string | undefined;\n /** Response headers, when the API responded. */\n readonly headers: Headers | undefined;\n\n constructor(\n status: number,\n code: string,\n message: string,\n requestId?: string,\n headers?: Headers,\n options?: { cause?: unknown },\n ) {\n super(message, options);\n this.name = \"SerpKiteError\";\n this.status = status;\n this.code = code;\n this.requestId = requestId || undefined;\n this.headers = headers;\n }\n}\n\nconst fallbackCodes: Record<number, string> = {\n 400: \"invalid_request\",\n 401: \"unauthorized\",\n 402: \"insufficient_credits\",\n 403: \"forbidden\",\n 404: \"not_found\",\n 429: \"rate_limited\",\n // The API sends upstream failures as 503 with a JSON body; a bare 502/504\n // comes from a proxy (Cloudflare replaces origin 502/504 bodies).\n 502: \"upstream_error\",\n 503: \"unavailable\",\n 504: \"upstream_timeout\",\n};\n\n/** Builds a SerpKiteError from a non-2xx response body (JSON envelope or anything else). */\nexport function errorFromResponse(status: number, headers: Headers, body: string): SerpKiteError {\n let code = fallbackCodes[status] ?? (status >= 500 ? \"server_error\" : \"http_error\");\n let message = body.trim().slice(0, 500) || `HTTP ${status}`;\n let requestId = headers.get(\"x-request-id\") ?? undefined;\n try {\n const parsed = JSON.parse(body) as {\n error?: { code?: unknown; message?: unknown; request_id?: unknown };\n };\n const e = parsed?.error;\n if (e && typeof e === \"object\") {\n if (typeof e.code === \"string\" && e.code) code = e.code;\n if (typeof e.message === \"string\" && e.message) message = e.message;\n if (typeof e.request_id === \"string\" && e.request_id) requestId = e.request_id;\n }\n } catch {\n // Not JSON: keep the text body as the message.\n }\n return new SerpKiteError(status, code, message, requestId, headers);\n}\n","import { errorFromResponse, SerpKiteError } from \"./errors\";\nimport type {\n Account,\n AutocompleteResponse,\n Batch,\n BatchCreateEntry,\n BatchCreateParams,\n BatchCreateResponse,\n CompactResponse,\n ImagesResponse,\n NewsResponse,\n PatentsResponse,\n PlacesResponse,\n RankParams,\n RankResponse,\n ReviewsParams,\n ReviewsResponse,\n ScholarResponse,\n SearchParams,\n SearchResponse,\n ShoppingResponse,\n VideosResponse,\n WebpageParams,\n WebpageResponse,\n} from \"./types\";\n\nexport const VERSION = \"0.3.0\";\nexport const DEFAULT_BASE_URL = \"https://api.serpkite.com\";\n\nexport interface SerpKiteOptions {\n /** API key (`skt_live_…`). Defaults to the `SERPKITE_API_KEY` environment variable. */\n apiKey?: string;\n /** Defaults to `SERPKITE_BASE_URL` or https://api.serpkite.com. */\n baseUrl?: string;\n /** Per-attempt timeout in milliseconds. Default 60000. */\n timeoutMs?: number;\n /** Retries after the first attempt on 429, 5xx and network errors. Default 2. */\n maxRetries?: number;\n /** Base delay of the exponential backoff in milliseconds. Default 500. */\n retryDelayMs?: number;\n /** Custom fetch implementation. Defaults to the global `fetch`. */\n fetch?: typeof fetch;\n /** Extra headers sent with every request. */\n headers?: Record<string, string>;\n}\n\n/** Billing and tracing details from the response headers. */\nexport interface ResponseInfo {\n status: number;\n headers: Headers;\n requestId: string | undefined;\n creditsUsed: number | undefined;\n creditsRemaining: number | undefined;\n costUsd: number | undefined;\n /** `HIT` when served from cache (`max_age`), else `MISS`. */\n cache: \"HIT\" | \"MISS\" | undefined;\n latencyMs: number | undefined;\n tokensEstimate: number | undefined;\n}\n\nexport interface RequestOptions {\n signal?: AbortSignal;\n /** Overrides the client's per-attempt timeout. */\n timeoutMs?: number;\n /** Overrides the client's retry count. */\n maxRetries?: number;\n headers?: Record<string, string>;\n /** Called with the final response's headers (credits used/remaining, cache, request id). */\n onResponse?: (info: ResponseInfo) => void;\n}\n\nexport interface BatchCreateOptions extends RequestOptions {\n /**\n * Sent as `Idempotency-Key` (1-255 printable ASCII characters, e.g. a UUID).\n * For 24 hours a retry with the same key and body returns the first response\n * instead of queueing and billing the jobs again.\n */\n idempotencyKey?: string;\n}\n\nexport interface WaitOptions {\n /** Give up after this many milliseconds. Default 600000 (10 minutes). */\n timeoutMs?: number;\n /** First delay between polls. Default 1000. Grows 1.5× per poll. */\n pollIntervalMs?: number;\n /** Upper bound of the delay between polls. Default 10000. */\n maxPollIntervalMs?: number;\n signal?: AbortSignal;\n}\n\n/** A vertical whose return type follows `format`: `\"markdown\"` → string, `\"compact\"` → CompactResponse. */\nexport interface VerticalMethod<P, R> {\n (params: P & { format: \"markdown\" }, options?: RequestOptions): Promise<string>;\n (params: P & { format: \"compact\" }, options?: RequestOptions): Promise<CompactResponse>;\n (params: P & { format?: \"json\" }, options?: RequestOptions): Promise<R>;\n (params: P, options?: RequestOptions): Promise<R | CompactResponse | string>;\n}\n\ntype Method = \"GET\" | \"POST\";\n\ninterface Call {\n method: Method;\n path: string;\n body?: unknown;\n options?: RequestOptions;\n /** Which failures are safe to retry. `all` = 429, 5xx and network errors. */\n retry?: \"all\" | \"rate_limit\";\n}\n\nexport class SerpKite {\n readonly baseUrl: string;\n readonly timeoutMs: number;\n readonly maxRetries: number;\n readonly retryDelayMs: number;\n readonly #apiKey: string;\n readonly #fetch: typeof fetch;\n readonly #headers: Record<string, string>;\n\n constructor(options: SerpKiteOptions = {}) {\n const apiKey = options.apiKey ?? env(\"SERPKITE_API_KEY\");\n if (!apiKey) {\n throw new SerpKiteError(\n 0,\n \"missing_api_key\",\n \"No API key: pass { apiKey } or set the SERPKITE_API_KEY environment variable\",\n );\n }\n this.#apiKey = apiKey;\n this.baseUrl = (options.baseUrl ?? env(\"SERPKITE_BASE_URL\") ?? DEFAULT_BASE_URL).replace(\n /\\/+$/,\n \"\",\n );\n this.timeoutMs = options.timeoutMs ?? 60_000;\n this.maxRetries = Math.max(0, options.maxRetries ?? 2);\n this.retryDelayMs = options.retryDelayMs ?? 500;\n const f = options.fetch ?? globalThis.fetch;\n if (typeof f !== \"function\") {\n throw new SerpKiteError(\n 0,\n \"missing_fetch\",\n \"No global fetch: pass { fetch } (Node 18+ has one)\",\n );\n }\n this.#fetch = f;\n this.#headers = { ...options.headers };\n }\n\n // ── Verticals ─────────────────────────────────────────────────────────\n\n /** Google web search: organic results, answer box, knowledge graph, people also ask… */\n readonly search = this.#vertical<SearchParams, SearchResponse>(\"/v1/search\");\n /** Google Images. */\n readonly images = this.#vertical<SearchParams, ImagesResponse>(\"/v1/images\");\n /** Google Videos. */\n readonly videos = this.#vertical<SearchParams, VideosResponse>(\"/v1/videos\");\n /** Google News. */\n readonly news = this.#vertical<SearchParams, NewsResponse>(\"/v1/news\");\n /** Google Maps search (places with coordinates). Accepts `ll` (\"@lat,lng,14z\"). */\n readonly maps = this.#vertical<SearchParams, PlacesResponse>(\"/v1/maps\");\n /** Google local results. */\n readonly places = this.#vertical<SearchParams, PlacesResponse>(\"/v1/places\");\n /** Reviews of a place by `place_id`, `cid` or `fid`. Page with `page_token` = `next_page_token`. */\n readonly reviews = this.#vertical<ReviewsParams, ReviewsResponse>(\"/v1/reviews\");\n /** Google Shopping. */\n readonly shopping = this.#vertical<SearchParams, ShoppingResponse>(\"/v1/shopping\");\n /** Google Scholar. */\n readonly scholar = this.#vertical<SearchParams, ScholarResponse>(\"/v1/scholar\");\n /** Google Patents. */\n readonly patents = this.#vertical<SearchParams, PatentsResponse>(\"/v1/patents\");\n /** Google autocomplete suggestions. */\n readonly autocomplete = this.#vertical<SearchParams, AutocompleteResponse>(\"/v1/autocomplete\");\n /** Fetch any public URL as clean Markdown plus metadata. */\n readonly webpage = this.#vertical<WebpageParams, WebpageResponse>(\"/v1/webpage\");\n\n /** Position of `domain` for keyword `q` in the top `num` results (default 100). */\n rank(params: RankParams, options?: RequestOptions): Promise<RankResponse> {\n return this.request({ method: \"POST\", path: \"/v1/rank\", body: params, options });\n }\n\n /** Balance, limits and this month's usage for the key's account. */\n account(options?: RequestOptions): Promise<Account> {\n return this.request({ method: \"GET\", path: \"/v1/account\", options });\n }\n\n // ── Batches ───────────────────────────────────────────────────────────\n\n readonly batches = {\n /**\n * Queue 1-100 requests for one endpoint at half price. Returns one entry per\n * request, in order: a queued `Batch` or an error object. Without an\n * `idempotencyKey` it is only retried on 429, so a lost response never queues\n * (and bills) the same requests twice. With one, 5xx and network errors are\n * retried too: the server replays the first response for the same key and body.\n */\n create: (\n params: BatchCreateParams,\n options: BatchCreateOptions = {},\n ): Promise<BatchCreateResponse> => {\n const { idempotencyKey, ...rest } = options;\n return this.request({\n method: \"POST\",\n path: \"/v1/batches\",\n body: params,\n options: idempotencyKey\n ? { ...rest, headers: { ...rest.headers, \"Idempotency-Key\": idempotencyKey } }\n : rest,\n retry: idempotencyKey ? \"all\" : \"rate_limit\",\n });\n },\n\n /** Poll one batch job. */\n get: (id: string, options?: RequestOptions): Promise<Batch> =>\n this.request({ method: \"GET\", path: `/v1/batches/${encodeURIComponent(id)}`, options }),\n\n /**\n * Poll until the job is `done` or `failed` and return it (a failed job is\n * returned, not thrown; check `status` and `error`). Accepts an id or an\n * entry from `create`; an entry that failed to queue throws its error.\n */\n wait: (idOrEntry: string | BatchCreateEntry | undefined, options: WaitOptions = {}) =>\n this.#wait(idOrEntry, options),\n };\n\n // ── Plumbing ──────────────────────────────────────────────────────────\n\n #vertical<P, R>(path: string): VerticalMethod<P, R> {\n return ((params: P, options?: RequestOptions) =>\n this.request({ method: \"POST\", path, body: params, options })) as VerticalMethod<P, R>;\n }\n\n async #wait(idOrEntry: string | BatchCreateEntry | undefined, o: WaitOptions): Promise<Batch> {\n let id: string | undefined;\n if (typeof idOrEntry === \"string\") {\n id = idOrEntry;\n } else if (idOrEntry && \"id\" in idOrEntry && typeof idOrEntry.id === \"string\") {\n id = idOrEntry.id;\n } else if (idOrEntry && \"error\" in idOrEntry && idOrEntry.error && !(\"id\" in idOrEntry)) {\n const e = idOrEntry.error as { code?: string; message?: string; request_id?: string };\n throw new SerpKiteError(\n 400,\n e.code ?? \"invalid_request\",\n e.message ?? \"batch entry was not queued\",\n e.request_id,\n );\n }\n if (!id) {\n throw new SerpKiteError(0, \"invalid_request\", \"batches.wait needs a batch id\");\n }\n const timeoutMs = o.timeoutMs ?? 600_000;\n const maxInterval = o.maxPollIntervalMs ?? 10_000;\n let interval = o.pollIntervalMs ?? 1_000;\n const deadline = Date.now() + timeoutMs;\n for (;;) {\n const batch = await this.batches.get(id, { signal: o.signal });\n if (batch.status === \"done\" || batch.status === \"failed\") return batch;\n const left = deadline - Date.now();\n if (left <= 0) {\n throw new SerpKiteError(\n 0,\n \"timeout\",\n `batch ${id} still ${batch.status} after ${timeoutMs} ms`,\n );\n }\n await sleep(Math.min(interval, left), o.signal);\n interval = Math.min(interval * 1.5, maxInterval);\n }\n }\n\n /** Low-level request: JSON body in, parsed JSON (or text for non-JSON responses) out. */\n async request<T>(call: Call): Promise<T> {\n const { method, path, body, options = {} } = call;\n const maxRetries = Math.max(0, options.maxRetries ?? this.maxRetries);\n const timeoutMs = options.timeoutMs ?? this.timeoutMs;\n const headers: Record<string, string> = {\n Accept: \"application/json, text/markdown;q=0.9\",\n Authorization: `Bearer ${this.#apiKey}`,\n ...this.#headers,\n ...options.headers,\n };\n if (body !== undefined) headers[\"Content-Type\"] = \"application/json\";\n // Browsers would turn a custom User-Agent into a CORS preflight header.\n if (!isBrowser()) headers[\"User-Agent\"] = `serpkite-typescript/${VERSION}`;\n const init: RequestInit = {\n method,\n headers,\n body: body === undefined ? undefined : JSON.stringify(body),\n };\n\n for (let attempt = 0; ; attempt++) {\n const canRetry = attempt < maxRetries;\n let res: Response;\n const { signal, cleanup, timedOut } = withTimeout(options.signal, timeoutMs);\n try {\n res = await this.#fetch(this.baseUrl + path, { ...init, signal });\n } catch (err) {\n cleanup();\n if (options.signal?.aborted) throw err;\n const code = timedOut() ? \"timeout\" : \"connection_error\";\n if (canRetry && call.retry !== \"rate_limit\") {\n await sleep(this.#backoff(attempt), options.signal);\n continue;\n }\n const msg = timedOut()\n ? `request timed out after ${timeoutMs} ms`\n : `request failed: ${err instanceof Error ? err.message : String(err)}`;\n throw new SerpKiteError(0, code, msg, undefined, undefined, { cause: err });\n }\n\n let text: string;\n try {\n text = await res.text();\n } catch (err) {\n cleanup();\n if (options.signal?.aborted) throw err;\n if (canRetry && call.retry !== \"rate_limit\") {\n await sleep(this.#backoff(attempt), options.signal);\n continue;\n }\n const code = timedOut() ? \"timeout\" : \"connection_error\";\n throw new SerpKiteError(\n 0,\n code,\n \"failed to read the response body\",\n undefined,\n res.headers,\n {\n cause: err,\n },\n );\n }\n cleanup();\n\n if (!res.ok) {\n const retryable = res.status === 429 || (res.status >= 500 && call.retry !== \"rate_limit\");\n if (canRetry && retryable) {\n await sleep(this.#retryDelay(attempt, res.headers), options.signal);\n continue;\n }\n throw errorFromResponse(res.status, res.headers, text);\n }\n\n options.onResponse?.(responseInfo(res));\n const type = res.headers.get(\"content-type\") ?? \"\";\n if (type.includes(\"json\")) {\n try {\n return JSON.parse(text) as T;\n } catch (err) {\n throw new SerpKiteError(\n res.status,\n \"invalid_response\",\n \"response is not valid JSON\",\n res.headers.get(\"x-request-id\") ?? undefined,\n res.headers,\n { cause: err },\n );\n }\n }\n return text as T;\n }\n }\n\n #backoff(attempt: number): number {\n const base = Math.min(this.retryDelayMs * 2 ** attempt, 8_000);\n return base / 2 + Math.random() * (base / 2);\n }\n\n #retryDelay(attempt: number, headers: Headers): number {\n const after = parseRetryAfter(headers.get(\"retry-after\"));\n return after === undefined ? this.#backoff(attempt) : Math.min(after, 60_000);\n }\n}\n\n// ── helpers ─────────────────────────────────────────────────────────────\n\n/** Parses Retry-After (seconds or an HTTP date) into milliseconds. */\nexport function parseRetryAfter(v: string | null): number | undefined {\n if (!v) return undefined;\n const secs = Number(v);\n if (Number.isFinite(secs)) return Math.max(0, secs * 1000);\n const at = Date.parse(v);\n return Number.isNaN(at) ? undefined : Math.max(0, at - Date.now());\n}\n\nfunction responseInfo(res: Response): ResponseInfo {\n const h = res.headers;\n const num = (name: string) => {\n const v = h.get(name);\n if (v === null || v === \"\") return undefined;\n const n = Number(v);\n return Number.isFinite(n) ? n : undefined;\n };\n const cache = h.get(\"x-cache\")?.toUpperCase();\n return {\n status: res.status,\n headers: h,\n requestId: h.get(\"x-request-id\") ?? undefined,\n creditsUsed: num(\"x-credits-used\"),\n creditsRemaining: num(\"x-credits-remaining\"),\n costUsd: num(\"x-cost-usd\"),\n cache: cache === \"HIT\" || cache === \"MISS\" ? cache : undefined,\n latencyMs: num(\"x-latency-ms\"),\n tokensEstimate: num(\"x-tokens-estimate\"),\n };\n}\n\nfunction withTimeout(outer: AbortSignal | undefined, ms: number) {\n const ctrl = new AbortController();\n let timedOut = false;\n const onAbort = () => ctrl.abort(outer?.reason);\n if (outer?.aborted) ctrl.abort(outer.reason);\n else outer?.addEventListener(\"abort\", onAbort, { once: true });\n const timer =\n ms > 0 && Number.isFinite(ms)\n ? setTimeout(() => {\n timedOut = true;\n ctrl.abort(new SerpKiteError(0, \"timeout\", `request timed out after ${ms} ms`));\n }, ms)\n : undefined;\n return {\n signal: ctrl.signal,\n timedOut: () => timedOut,\n cleanup: () => {\n if (timer !== undefined) clearTimeout(timer);\n outer?.removeEventListener(\"abort\", onAbort);\n },\n };\n}\n\nfunction sleep(ms: number, signal?: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n if (signal?.aborted) return reject(signal.reason);\n const t = setTimeout(() => {\n signal?.removeEventListener(\"abort\", onAbort);\n resolve();\n }, ms);\n const onAbort = () => {\n clearTimeout(t);\n reject(signal?.reason);\n };\n signal?.addEventListener(\"abort\", onAbort, { once: true });\n });\n}\n\ntype EnvHost = {\n process?: { env?: Record<string, string | undefined> };\n Deno?: { env?: { get?: (name: string) => string | undefined } };\n document?: unknown;\n};\n\nfunction env(name: string): string | undefined {\n const g = globalThis as EnvHost;\n try {\n const v = g.process?.env?.[name];\n if (v) return v;\n } catch {\n // process.env may be a throwing proxy on some edge runtimes.\n }\n try {\n return g.Deno?.env?.get?.(name) || undefined;\n } catch {\n // Deno without --allow-env.\n return undefined;\n }\n}\n\nfunction isBrowser(): boolean {\n return typeof (globalThis as EnvHost).document !== \"undefined\";\n}\n","import type { BatchCreateEntry, BatchCreateError } from \"./types\";\n\n/** True when a `batches.create` entry was rejected instead of queued. */\nexport function isBatchError(entry: BatchCreateEntry): entry is BatchCreateError {\n return !(\"id\" in entry && typeof entry.id === \"string\") && \"error\" in entry && !!entry.error;\n}\n","/** Options for {@link verifyWebhook}. */\nexport interface VerifyWebhookOptions {\n /** Reject deliveries whose timestamp is further than this from now. Default 300. */\n toleranceSeconds?: number;\n /** Current time in Unix seconds (tests). */\n now?: number;\n}\n\ntype HeaderSource = Headers | Record<string, string | string[] | undefined>;\n\nfunction header(headers: HeaderSource, name: string): string | undefined {\n if (typeof (headers as Headers).get === \"function\") {\n return (headers as Headers).get(name) ?? undefined;\n }\n const rec = headers as Record<string, string | string[] | undefined>;\n const key = Object.keys(rec).find((k) => k.toLowerCase() === name.toLowerCase());\n const v = key === undefined ? undefined : rec[key];\n return Array.isArray(v) ? v[0] : v;\n}\n\n/**\n * Checks a batch webhook delivery: `X-SerpKite-Signature` must be\n * `v1=<hex HMAC-SHA256(secret, \"<X-SerpKite-Timestamp>.<raw body>\")>` and the\n * timestamp recent. Pass the raw request body exactly as received (not\n * re-serialised JSON). Uses Web Crypto (Node 18+, Deno, Bun, browsers).\n *\n * ```ts\n * const ok = await verifyWebhook(process.env.SERPKITE_WEBHOOK_SECRET!, rawBody, req.headers);\n * ```\n */\nexport async function verifyWebhook(\n secret: string,\n payload: string | Uint8Array,\n headers: HeaderSource,\n options: VerifyWebhookOptions = {},\n): Promise<boolean> {\n const signature = header(headers, \"x-serpkite-signature\");\n const ts = header(headers, \"x-serpkite-timestamp\");\n if (!secret || !signature?.startsWith(\"v1=\") || !ts || !/^\\d+$/.test(ts)) return false;\n const now = options.now ?? Math.floor(Date.now() / 1000);\n if (Math.abs(now - Number(ts)) > (options.toleranceSeconds ?? 300)) return false;\n\n const enc = new TextEncoder();\n const body = typeof payload === \"string\" ? enc.encode(payload) : payload;\n const prefix = enc.encode(`${ts}.`);\n const msg = new Uint8Array(prefix.length + body.length);\n msg.set(prefix);\n msg.set(body, prefix.length);\n const key = await crypto.subtle.importKey(\n \"raw\",\n enc.encode(secret),\n { name: \"HMAC\", hash: \"SHA-256\" },\n false,\n [\"sign\"],\n );\n const mac = new Uint8Array(await crypto.subtle.sign(\"HMAC\", key, msg));\n const want = Array.from(mac, (b) => b.toString(16).padStart(2, \"0\")).join(\"\");\n const got = signature.slice(3).toLowerCase();\n if (got.length !== want.length) return false;\n let diff = 0;\n for (let i = 0; i < want.length; i++) diff |= want.charCodeAt(i) ^ got.charCodeAt(i);\n return diff === 0;\n}\n"]}
|
package/package.json
CHANGED