litescrape-sdk 0.1.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.
Files changed (104) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +283 -0
  3. package/dist/cjs/batch.d.ts +12 -0
  4. package/dist/cjs/batch.d.ts.map +1 -0
  5. package/dist/cjs/batch.js +131 -0
  6. package/dist/cjs/batch.js.map +1 -0
  7. package/dist/cjs/cache.d.ts +21 -0
  8. package/dist/cjs/cache.d.ts.map +1 -0
  9. package/dist/cjs/cache.js +112 -0
  10. package/dist/cjs/cache.js.map +1 -0
  11. package/dist/cjs/client.d.ts +38 -0
  12. package/dist/cjs/client.d.ts.map +1 -0
  13. package/dist/cjs/client.js +143 -0
  14. package/dist/cjs/client.js.map +1 -0
  15. package/dist/cjs/errors.d.ts +53 -0
  16. package/dist/cjs/errors.d.ts.map +1 -0
  17. package/dist/cjs/errors.js +121 -0
  18. package/dist/cjs/errors.js.map +1 -0
  19. package/dist/cjs/index.d.ts +8 -0
  20. package/dist/cjs/index.d.ts.map +1 -0
  21. package/dist/cjs/index.js +40 -0
  22. package/dist/cjs/index.js.map +1 -0
  23. package/dist/cjs/models.d.ts +1735 -0
  24. package/dist/cjs/models.d.ts.map +1 -0
  25. package/dist/cjs/models.js +389 -0
  26. package/dist/cjs/models.js.map +1 -0
  27. package/dist/cjs/package.json +1 -0
  28. package/dist/cjs/result.d.ts +23 -0
  29. package/dist/cjs/result.d.ts.map +1 -0
  30. package/dist/cjs/result.js +49 -0
  31. package/dist/cjs/result.js.map +1 -0
  32. package/dist/cjs/runtime.d.ts +53 -0
  33. package/dist/cjs/runtime.d.ts.map +1 -0
  34. package/dist/cjs/runtime.js +237 -0
  35. package/dist/cjs/runtime.js.map +1 -0
  36. package/dist/cjs/stores.d.ts +143 -0
  37. package/dist/cjs/stores.d.ts.map +1 -0
  38. package/dist/cjs/stores.js +194 -0
  39. package/dist/cjs/stores.js.map +1 -0
  40. package/dist/cjs/validation.d.ts +65 -0
  41. package/dist/cjs/validation.d.ts.map +1 -0
  42. package/dist/cjs/validation.js +122 -0
  43. package/dist/cjs/validation.js.map +1 -0
  44. package/dist/cjs/version.d.ts +2 -0
  45. package/dist/cjs/version.d.ts.map +1 -0
  46. package/dist/cjs/version.js +5 -0
  47. package/dist/cjs/version.js.map +1 -0
  48. package/dist/esm/batch.d.ts +12 -0
  49. package/dist/esm/batch.d.ts.map +1 -0
  50. package/dist/esm/batch.js +128 -0
  51. package/dist/esm/batch.js.map +1 -0
  52. package/dist/esm/cache.d.ts +21 -0
  53. package/dist/esm/cache.d.ts.map +1 -0
  54. package/dist/esm/cache.js +106 -0
  55. package/dist/esm/cache.js.map +1 -0
  56. package/dist/esm/client.d.ts +38 -0
  57. package/dist/esm/client.d.ts.map +1 -0
  58. package/dist/esm/client.js +138 -0
  59. package/dist/esm/client.js.map +1 -0
  60. package/dist/esm/errors.d.ts +53 -0
  61. package/dist/esm/errors.d.ts.map +1 -0
  62. package/dist/esm/errors.js +106 -0
  63. package/dist/esm/errors.js.map +1 -0
  64. package/dist/esm/index.d.ts +8 -0
  65. package/dist/esm/index.d.ts.map +1 -0
  66. package/dist/esm/index.js +6 -0
  67. package/dist/esm/index.js.map +1 -0
  68. package/dist/esm/models.d.ts +1735 -0
  69. package/dist/esm/models.d.ts.map +1 -0
  70. package/dist/esm/models.js +384 -0
  71. package/dist/esm/models.js.map +1 -0
  72. package/dist/esm/result.d.ts +23 -0
  73. package/dist/esm/result.d.ts.map +1 -0
  74. package/dist/esm/result.js +45 -0
  75. package/dist/esm/result.js.map +1 -0
  76. package/dist/esm/runtime.d.ts +53 -0
  77. package/dist/esm/runtime.d.ts.map +1 -0
  78. package/dist/esm/runtime.js +226 -0
  79. package/dist/esm/runtime.js.map +1 -0
  80. package/dist/esm/stores.d.ts +143 -0
  81. package/dist/esm/stores.d.ts.map +1 -0
  82. package/dist/esm/stores.js +190 -0
  83. package/dist/esm/stores.js.map +1 -0
  84. package/dist/esm/validation.d.ts +65 -0
  85. package/dist/esm/validation.d.ts.map +1 -0
  86. package/dist/esm/validation.js +109 -0
  87. package/dist/esm/validation.js.map +1 -0
  88. package/dist/esm/version.d.ts +2 -0
  89. package/dist/esm/version.d.ts.map +1 -0
  90. package/dist/esm/version.js +2 -0
  91. package/dist/esm/version.js.map +1 -0
  92. package/package.json +74 -0
  93. package/src/batch.ts +158 -0
  94. package/src/cache.ts +123 -0
  95. package/src/client.ts +199 -0
  96. package/src/errors.ts +120 -0
  97. package/src/index.ts +17 -0
  98. package/src/models.ts +570 -0
  99. package/src/package.json +3 -0
  100. package/src/result.ts +49 -0
  101. package/src/runtime.ts +255 -0
  102. package/src/stores.ts +206 -0
  103. package/src/validation.ts +140 -0
  104. package/src/version.ts +1 -0
package/src/models.ts ADDED
@@ -0,0 +1,570 @@
1
+ import { z } from "zod";
2
+ import { ValidationError, isObject } from "./errors.js";
3
+ import {
4
+ optional as opt,
5
+ text,
6
+ number,
7
+ integer,
8
+ boolean,
9
+ flag,
10
+ strictBoolean,
11
+ timeoutSeconds,
12
+ device,
13
+ defineRequest,
14
+ requireAny,
15
+ exactlyOne,
16
+ atMostOne,
17
+ paired,
18
+ requires,
19
+ has,
20
+ issue,
21
+ } from "./validation.js";
22
+ import {
23
+ playApps,
24
+ playGames,
25
+ playBooks,
26
+ playMovies,
27
+ playProduct,
28
+ playReviews,
29
+ playRules,
30
+ appleSearch,
31
+ appleProduct,
32
+ appleReviews,
33
+ } from "./stores.js";
34
+
35
+ export { ScrapeRequest } from "./validation.js";
36
+
37
+ const base = { timeout: opt(timeoutSeconds) };
38
+ const locale = { ...base, hl: opt(text), gl: opt(text), google_domain: opt(text) };
39
+ const origin = { location: opt(text), uule: opt(text) };
40
+ const originRules = [atMostOne("location", "uule")];
41
+ const safe = z.enum(["active", "off"]);
42
+ const search = {
43
+ ...locale,
44
+ ...origin,
45
+ q: opt(text),
46
+ ludocid: opt(text),
47
+ kgmid: opt(text),
48
+ lat: opt(number),
49
+ lon: opt(number),
50
+ radius: opt(number),
51
+ lsig: opt(text),
52
+ si: opt(text),
53
+ ibp: opt(text),
54
+ uds: opt(text),
55
+ color_scheme: opt(z.enum(["light", "dark"])),
56
+ cr: opt(text),
57
+ lr: opt(text),
58
+ tbs: opt(text),
59
+ safe: opt(safe),
60
+ nfpr: opt(flag),
61
+ filter: opt(flag),
62
+ pws: opt(flag),
63
+ peek_pws: opt(flag),
64
+ tbm: opt(z.enum(["lcl", "vid", "nws", "shop", "pts"])),
65
+ start: opt(integer),
66
+ num: opt(integer),
67
+ device: opt(device),
68
+ oq: opt(text),
69
+ gs_lp: opt(text),
70
+ sclient: opt(text),
71
+ as_dt: opt(z.enum(["i", "e"])),
72
+ as_epq: opt(text),
73
+ as_eq: opt(text),
74
+ as_lq: opt(text),
75
+ as_nlo: opt(text),
76
+ as_nhi: opt(text),
77
+ as_oq: opt(text),
78
+ as_q: opt(text),
79
+ as_qdr: opt(text),
80
+ as_rq: opt(text),
81
+ as_sitesearch: opt(text),
82
+ };
83
+ const searchRules = [
84
+ requireAny("q", "ludocid", "kgmid"),
85
+ paired("lat", "lon"),
86
+ atMostOne("location", "uule", "lat"),
87
+ paired("as_nlo", "as_nhi"),
88
+ requires("as_dt", "as_sitesearch"),
89
+ ];
90
+
91
+ export const GoogleSearch = defineRequest(
92
+ "google_search",
93
+ "/api/google/search",
94
+ { ...search, fast_mode: opt(strictBoolean) },
95
+ searchRules,
96
+ );
97
+ export const GoogleAiOverview = defineRequest(
98
+ "google_ai_overview",
99
+ "/api/google/ai-overview",
100
+ search,
101
+ searchRules,
102
+ );
103
+ export const GoogleAiMode = defineRequest(
104
+ "google_ai_mode",
105
+ "/api/google/ai-mode",
106
+ {
107
+ ...locale,
108
+ ...origin,
109
+ q: text,
110
+ device: opt(device),
111
+ continuable: opt(boolean),
112
+ subsequent_request_token: opt(text),
113
+ image_url: opt(text),
114
+ },
115
+ [...originRules, atMostOne("image_url", "subsequent_request_token")],
116
+ );
117
+ export const GoogleAds = defineRequest("google_ads", "/api/google/ads", {
118
+ ...base,
119
+ q: text,
120
+ location: text,
121
+ hl: opt(text),
122
+ safe: opt(safe),
123
+ nfpr: opt(flag),
124
+ device: opt(device),
125
+ });
126
+ export const GoogleShopping = defineRequest(
127
+ "google_shopping",
128
+ "/api/google/shopping",
129
+ {
130
+ ...locale,
131
+ ...origin,
132
+ q: opt(text),
133
+ shoprs: opt(text),
134
+ min_price: opt(number),
135
+ max_price: opt(number),
136
+ sort_by: opt(
137
+ z
138
+ .union([z.enum(["1", "2", "3", "4"]), z.literal(1), z.literal(2), z.literal(3), z.literal(4)])
139
+ .transform(String),
140
+ ),
141
+ free_shipping: opt(boolean),
142
+ on_sale: opt(boolean),
143
+ small_business: opt(boolean),
144
+ start: opt(integer),
145
+ num: opt(integer),
146
+ device: opt(device),
147
+ },
148
+ [
149
+ ...originRules,
150
+ requireAny("q", "shoprs"),
151
+ (p, c) => {
152
+ if (
153
+ [
154
+ has(p, "min_price") || has(p, "max_price"),
155
+ !!p.on_sale,
156
+ !!p.free_shipping,
157
+ !!p.small_business,
158
+ ].filter(Boolean).length > 1
159
+ )
160
+ issue(c, "only one of a price range, on_sale, free_shipping, or small_business may be used");
161
+ },
162
+ ],
163
+ );
164
+ export const GoogleShoppingProduct = defineRequest(
165
+ "google_shopping_product",
166
+ "/api/google/shopping/product",
167
+ {
168
+ ...locale,
169
+ ...origin,
170
+ q: text,
171
+ gpcid: opt(text),
172
+ headline_offer_docid: opt(text),
173
+ image_docid: opt(text),
174
+ prds: opt(text),
175
+ device: opt(device),
176
+ },
177
+ [
178
+ ...originRules,
179
+ exactlyOne("gpcid", "prds"),
180
+ requires("headline_offer_docid", "gpcid"),
181
+ requires("image_docid", "gpcid"),
182
+ ],
183
+ );
184
+ export const GoogleLocal = defineRequest(
185
+ "google_local",
186
+ "/api/google/local",
187
+ {
188
+ ...locale,
189
+ ...origin,
190
+ q: text,
191
+ ludocid: opt(text),
192
+ tbs: opt(text),
193
+ start: opt(integer),
194
+ device: opt(device),
195
+ },
196
+ originRules,
197
+ );
198
+ export const GoogleMaps = defineRequest(
199
+ "google_maps",
200
+ "/api/google/maps",
201
+ {
202
+ ...locale,
203
+ q: opt(text),
204
+ ll: opt(text),
205
+ location: opt(text),
206
+ lat: opt(number),
207
+ lon: opt(number),
208
+ z: opt(number),
209
+ m: opt(integer),
210
+ nearby: opt(boolean),
211
+ data: opt(text),
212
+ place_id: opt(text),
213
+ data_cid: opt(text),
214
+ type: opt(z.enum(["search", "place"])),
215
+ start: opt(integer),
216
+ min_price: opt(integer),
217
+ max_price: opt(integer),
218
+ min_rating: opt(number),
219
+ open_state: opt(z.enum(["now", "24h"])),
220
+ open_on_day: opt(z.enum(["mon", "tue", "wed", "thu", "fri", "sat", "sun"])),
221
+ open_at_hour: opt(integer),
222
+ },
223
+ [
224
+ requireAny("q", "place_id", "data_cid", "data"),
225
+ atMostOne("place_id", "data_cid", "data"),
226
+ paired("lat", "lon"),
227
+ atMostOne("ll", "lat", "location"),
228
+ atMostOne("z", "m"),
229
+ atMostOne("open_state", "open_on_day"),
230
+ atMostOne("open_state", "open_at_hour"),
231
+ requires("open_at_hour", "open_on_day"),
232
+ (p, c) => {
233
+ if (!["place_id", "data_cid", "data"].some((f) => has(p, f)) && !has(p, "type"))
234
+ issue(c, "type is required when searching by q");
235
+ if (p.type === "search" && !has(p, "q")) issue(c, "q is required when type=search");
236
+ },
237
+ ],
238
+ );
239
+ export const GoogleMapsLiveFootTraffic = defineRequest(
240
+ "google_maps_live_foot_traffic",
241
+ "/api/google/maps/popular-times",
242
+ { ...locale, place_id: text },
243
+ );
244
+ export const GoogleMapsPosts = defineRequest("google_maps_posts", "/api/google/maps/posts", {
245
+ ...locale,
246
+ data_id: text,
247
+ next_page_token: opt(text),
248
+ });
249
+ export const GoogleMapsPhoto = defineRequest("google_maps_photo", "/api/google/maps/photo-meta", {
250
+ ...locale,
251
+ data_id: text,
252
+ });
253
+ export const GoogleMapsWebResults = defineRequest("google_maps_web_results", "/api/google/maps/web", {
254
+ ...locale,
255
+ q: text,
256
+ ibp: text,
257
+ device: opt(z.literal("desktop")),
258
+ start: opt(integer),
259
+ });
260
+ export const GoogleReviews = defineRequest(
261
+ "google_reviews",
262
+ "/api/google/reviews",
263
+ {
264
+ ...base,
265
+ place_id: opt(text),
266
+ data_id: opt(text),
267
+ hl: opt(text),
268
+ gl: opt(text),
269
+ sort_by: opt(z.enum(["qualityScore", "newestFirst", "ratingHigh", "ratingLow"])),
270
+ topic_id: opt(text),
271
+ query: opt(text),
272
+ num: opt(integer),
273
+ next_page_token: opt(text),
274
+ source_metadata: opt(boolean),
275
+ },
276
+ [exactlyOne("place_id", "data_id"), atMostOne("topic_id", "query")],
277
+ );
278
+ export const GoogleContributorReviews = defineRequest(
279
+ "google_contributor_reviews",
280
+ "/api/google/contributor-reviews",
281
+ {
282
+ ...base,
283
+ contributor_id: text,
284
+ hl: opt(text),
285
+ gl: opt(text),
286
+ limit: opt(integer),
287
+ },
288
+ );
289
+ export const BingSearch = defineRequest(
290
+ "bing_search",
291
+ "/api/bing/search",
292
+ {
293
+ ...base,
294
+ engine: opt(z.literal("bing")),
295
+ q: text,
296
+ location: opt(text),
297
+ lat: opt(number),
298
+ lon: opt(number),
299
+ mkt: opt(text),
300
+ cc: opt(text),
301
+ first: opt(integer),
302
+ safeSearch: opt(z.enum(["off", "moderate", "strict"])),
303
+ filters: opt(text),
304
+ device: opt(device),
305
+ },
306
+ [atMostOne("mkt", "cc")],
307
+ );
308
+ export const BingMaps = defineRequest(
309
+ "bing_maps",
310
+ "/api/bing/maps",
311
+ {
312
+ ...base,
313
+ q: opt(text),
314
+ place_id: opt(text),
315
+ cp: opt(text),
316
+ setlang: opt(text),
317
+ first: opt(integer),
318
+ count: opt(integer),
319
+ },
320
+ [requireAny("q", "place_id")],
321
+ );
322
+ export const DuckDuckGoSearch = defineRequest(
323
+ "duckduckgo_search",
324
+ "/api/duckduckgo/search",
325
+ {
326
+ ...base,
327
+ q: text,
328
+ kl: opt(text),
329
+ search_assist: opt(boolean),
330
+ safe: opt(
331
+ z.union([z.enum(["1", "-1", "-2"]), z.literal(1), z.literal(-1), z.literal(-2)]).transform(String),
332
+ ),
333
+ df: opt(text),
334
+ start: opt(integer),
335
+ m: opt(integer),
336
+ },
337
+ [atMostOne("m", "search_assist")],
338
+ );
339
+ export const DuckDuckGoMaps = defineRequest(
340
+ "duckduckgo_maps",
341
+ "/api/duckduckgo/maps",
342
+ {
343
+ ...base,
344
+ q: text,
345
+ bbox: opt(text),
346
+ lat: opt(number),
347
+ lon: opt(number),
348
+ strict_bbox: opt(boolean),
349
+ },
350
+ [paired("lat", "lon"), exactlyOne("bbox", "lat")],
351
+ );
352
+ export const YelpSearch = defineRequest("yelp_search", "/api/yelp/search", {
353
+ ...base,
354
+ find_desc: opt(text),
355
+ find_loc: text,
356
+ yelp_domain: opt(text),
357
+ l: opt(text),
358
+ cflt: opt(text),
359
+ sortby: opt(z.enum(["recommended", "rating", "review_count"])),
360
+ attrs: opt(text),
361
+ start: opt(integer),
362
+ });
363
+ export const YelpReviews = defineRequest("yelp_reviews", "/api/yelp/reviews", {
364
+ ...base,
365
+ place_id: text,
366
+ yelp_domain: opt(text),
367
+ hl: opt(text),
368
+ q: opt(text),
369
+ sortby: opt(
370
+ z.enum(["relevance_desc", "date_desc", "date_asc", "rating_desc", "rating_asc", "elites_desc"]),
371
+ ),
372
+ rating: opt(text),
373
+ not_recommended: opt(boolean),
374
+ start: opt(integer),
375
+ num: opt(integer),
376
+ not_recommended_start: opt(integer),
377
+ });
378
+ const tripadvisor = { ...base, tripadvisor_domain: opt(text), locale: opt(text) };
379
+ export const TripadvisorSearch = defineRequest(
380
+ "tripadvisor_search",
381
+ "/api/tripadvisor/search",
382
+ {
383
+ ...tripadvisor,
384
+ q: text,
385
+ geo_id: opt(integer),
386
+ lat: opt(number),
387
+ lon: opt(number),
388
+ place_type: opt(z.enum(["all", "accommodation", "attraction", "attraction_product", "eatery", "geo"])),
389
+ start: opt(integer),
390
+ num: opt(integer),
391
+ },
392
+ [paired("lat", "lon")],
393
+ );
394
+ export const TripadvisorPlace = defineRequest("tripadvisor_place", "/api/tripadvisor/place", {
395
+ ...tripadvisor,
396
+ place_id: text,
397
+ currency: opt(text),
398
+ geo_id: opt(integer),
399
+ });
400
+ export const TripadvisorReviews = defineRequest("tripadvisor_reviews", "/api/tripadvisor/reviews", {
401
+ ...tripadvisor,
402
+ place_id: text,
403
+ start: opt(integer),
404
+ num: opt(integer),
405
+ sort_by: opt(z.enum(["recent", "relevance"])),
406
+ translate: opt(boolean),
407
+ });
408
+ export const AppleMapsPlaces = defineRequest("apple_maps_places", "/api/apple/maps/places", {
409
+ ...base,
410
+ muid: text,
411
+ locale: opt(text),
412
+ });
413
+ export const AppleMapsReviews = defineRequest("apple_maps_reviews", "/api/apple/maps/reviews", {
414
+ ...base,
415
+ muid: text,
416
+ locale: opt(text),
417
+ });
418
+ export const GooglePlayApps = defineRequest(
419
+ "google_play_apps",
420
+ "/api/google/play/apps",
421
+ { ...base, ...playApps },
422
+ playRules("apps"),
423
+ );
424
+ export const GooglePlayGames = defineRequest(
425
+ "google_play_games",
426
+ "/api/google/play/games",
427
+ { ...base, ...playGames },
428
+ playRules("games"),
429
+ );
430
+ export const GooglePlayBooks = defineRequest(
431
+ "google_play_books",
432
+ "/api/google/play/books",
433
+ { ...base, ...playBooks },
434
+ playRules("books"),
435
+ );
436
+ export const GooglePlayMovies = defineRequest(
437
+ "google_play_movies",
438
+ "/api/google/play/movies",
439
+ { ...base, ...playMovies },
440
+ playRules("movies"),
441
+ );
442
+ export const GooglePlayProduct = defineRequest(
443
+ "google_play_product",
444
+ "/api/google/play/product",
445
+ { ...base, ...playProduct },
446
+ playRules("product"),
447
+ );
448
+ export const GooglePlayReviews = defineRequest(
449
+ "google_play_reviews",
450
+ "/api/google/play/reviews",
451
+ { ...base, ...playReviews },
452
+ playRules("reviews"),
453
+ );
454
+ export const AppleAppStoreSearch = defineRequest("apple_app_store_search", "/api/apple/app-store/search", {
455
+ ...base,
456
+ ...appleSearch,
457
+ });
458
+ export const AppleAppStoreProduct = defineRequest("apple_app_store_product", "/api/apple/app-store/product", {
459
+ ...base,
460
+ ...appleProduct,
461
+ });
462
+ export const AppleAppStoreReviews = defineRequest("apple_app_store_reviews", "/api/apple/app-store/reviews", {
463
+ ...base,
464
+ ...appleReviews,
465
+ });
466
+
467
+ export const REQUEST_TYPES = Object.freeze({
468
+ google_search: GoogleSearch,
469
+ google_ai_overview: GoogleAiOverview,
470
+ google_ai_mode: GoogleAiMode,
471
+ google_ads: GoogleAds,
472
+ google_shopping: GoogleShopping,
473
+ google_shopping_product: GoogleShoppingProduct,
474
+ google_local: GoogleLocal,
475
+ google_maps: GoogleMaps,
476
+ google_maps_live_foot_traffic: GoogleMapsLiveFootTraffic,
477
+ google_maps_posts: GoogleMapsPosts,
478
+ google_maps_photo: GoogleMapsPhoto,
479
+ google_maps_web_results: GoogleMapsWebResults,
480
+ google_reviews: GoogleReviews,
481
+ google_contributor_reviews: GoogleContributorReviews,
482
+ bing_search: BingSearch,
483
+ bing_maps: BingMaps,
484
+ duckduckgo_search: DuckDuckGoSearch,
485
+ duckduckgo_maps: DuckDuckGoMaps,
486
+ yelp_search: YelpSearch,
487
+ yelp_reviews: YelpReviews,
488
+ tripadvisor_search: TripadvisorSearch,
489
+ tripadvisor_place: TripadvisorPlace,
490
+ tripadvisor_reviews: TripadvisorReviews,
491
+ apple_maps_places: AppleMapsPlaces,
492
+ apple_maps_reviews: AppleMapsReviews,
493
+ google_play_apps: GooglePlayApps,
494
+ google_play_games: GooglePlayGames,
495
+ google_play_books: GooglePlayBooks,
496
+ google_play_movies: GooglePlayMovies,
497
+ google_play_product: GooglePlayProduct,
498
+ google_play_reviews: GooglePlayReviews,
499
+ apple_app_store_search: AppleAppStoreSearch,
500
+ apple_app_store_product: AppleAppStoreProduct,
501
+ apple_app_store_reviews: AppleAppStoreReviews,
502
+ });
503
+ export type Endpoint = keyof typeof REQUEST_TYPES;
504
+ export type AnyRequest = InstanceType<(typeof REQUEST_TYPES)[Endpoint]>;
505
+ export type RequestInput = {
506
+ [E in Endpoint]: { endpoint: E } & ConstructorParameters<(typeof REQUEST_TYPES)[E]>[0];
507
+ }[Endpoint];
508
+ export type RequestItem = RequestInput | AnyRequest;
509
+
510
+ export type GoogleSearch = InstanceType<typeof GoogleSearch>;
511
+ export type GoogleAiOverview = InstanceType<typeof GoogleAiOverview>;
512
+ export type GoogleAiMode = InstanceType<typeof GoogleAiMode>;
513
+ export type GoogleAds = InstanceType<typeof GoogleAds>;
514
+ export type GoogleShopping = InstanceType<typeof GoogleShopping>;
515
+ export type GoogleShoppingProduct = InstanceType<typeof GoogleShoppingProduct>;
516
+ export type GoogleLocal = InstanceType<typeof GoogleLocal>;
517
+ export type GoogleMaps = InstanceType<typeof GoogleMaps>;
518
+ export type GoogleMapsLiveFootTraffic = InstanceType<typeof GoogleMapsLiveFootTraffic>;
519
+ export type GoogleMapsPosts = InstanceType<typeof GoogleMapsPosts>;
520
+ export type GoogleMapsPhoto = InstanceType<typeof GoogleMapsPhoto>;
521
+ export type GoogleMapsWebResults = InstanceType<typeof GoogleMapsWebResults>;
522
+ export type GoogleReviews = InstanceType<typeof GoogleReviews>;
523
+ export type GoogleContributorReviews = InstanceType<typeof GoogleContributorReviews>;
524
+ export type BingSearch = InstanceType<typeof BingSearch>;
525
+ export type BingMaps = InstanceType<typeof BingMaps>;
526
+ export type DuckDuckGoSearch = InstanceType<typeof DuckDuckGoSearch>;
527
+ export type DuckDuckGoMaps = InstanceType<typeof DuckDuckGoMaps>;
528
+ export type YelpSearch = InstanceType<typeof YelpSearch>;
529
+ export type YelpReviews = InstanceType<typeof YelpReviews>;
530
+ export type TripadvisorSearch = InstanceType<typeof TripadvisorSearch>;
531
+ export type TripadvisorPlace = InstanceType<typeof TripadvisorPlace>;
532
+ export type TripadvisorReviews = InstanceType<typeof TripadvisorReviews>;
533
+ export type AppleMapsPlaces = InstanceType<typeof AppleMapsPlaces>;
534
+ export type AppleMapsReviews = InstanceType<typeof AppleMapsReviews>;
535
+ export type GooglePlayApps = InstanceType<typeof GooglePlayApps>;
536
+ export type GooglePlayGames = InstanceType<typeof GooglePlayGames>;
537
+ export type GooglePlayBooks = InstanceType<typeof GooglePlayBooks>;
538
+ export type GooglePlayMovies = InstanceType<typeof GooglePlayMovies>;
539
+ export type GooglePlayProduct = InstanceType<typeof GooglePlayProduct>;
540
+ export type GooglePlayReviews = InstanceType<typeof GooglePlayReviews>;
541
+ export type AppleAppStoreSearch = InstanceType<typeof AppleAppStoreSearch>;
542
+ export type AppleAppStoreProduct = InstanceType<typeof AppleAppStoreProduct>;
543
+ export type AppleAppStoreReviews = InstanceType<typeof AppleAppStoreReviews>;
544
+
545
+ /** Validate an untrusted object, including its endpoint discriminator. */
546
+ export function parseRequest(input: unknown): AnyRequest {
547
+ if (!isObject(input) || typeof input.endpoint !== "string" || !Object.hasOwn(REQUEST_TYPES, input.endpoint))
548
+ throw new ValidationError([[0, `endpoint must be one of: ${Object.keys(REQUEST_TYPES).join(", ")}`]]);
549
+ const { endpoint, ...params } = input;
550
+ // A registry lookup selects one constructor; its schema validates the unknown parameters.
551
+ const Constructor = REQUEST_TYPES[endpoint as Endpoint] as unknown as new (params: unknown) => AnyRequest;
552
+ return new Constructor(params);
553
+ }
554
+
555
+ export const keyStatusSchema = z
556
+ .object({
557
+ remaining_calls: z.number().int(),
558
+ concurrency_limit: z.number().int().nullish(),
559
+ status: z.string().default(""),
560
+ free_calls: z.number().int().nullish(),
561
+ minimum_top_up_cents: z.number().int().nullish(),
562
+ cents_per_1000_calls: z.number().int().nullish(),
563
+ has_billing_email: z.boolean().nullish(),
564
+ credit_expiry_months: z.number().int().nullish(),
565
+ credits_expire_at: z.string().nullish(),
566
+ expiring_calls: z.number().int().nullish(),
567
+ request_id: z.string().default(""),
568
+ })
569
+ .passthrough();
570
+ export type KeyStatus = z.output<typeof keyStatusSchema>;
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
package/src/result.ts ADDED
@@ -0,0 +1,49 @@
1
+ import type { LitescrapeError } from "./errors.js";
2
+ import type { AnyRequest } from "./models.js";
3
+ import type { Outcome } from "./runtime.js";
4
+
5
+ /** One outcome per input, including failed items. Elapsed time is in seconds. */
6
+ export class Result {
7
+ readonly data: Record<string, unknown> | null;
8
+ readonly error: LitescrapeError | null;
9
+ readonly statusCode: number | null;
10
+ readonly requestId: string;
11
+ readonly attempts: number;
12
+
13
+ constructor(
14
+ public readonly index: number,
15
+ public readonly request: AnyRequest,
16
+ outcome: Outcome,
17
+ public readonly elapsed: number,
18
+ public readonly jobId = "",
19
+ ) {
20
+ this.data = outcome.data;
21
+ this.error = outcome.error;
22
+ this.statusCode = outcome.statusCode;
23
+ this.requestId = outcome.requestId;
24
+ this.attempts = outcome.attempts;
25
+ Object.freeze(this);
26
+ }
27
+
28
+ get ok(): boolean {
29
+ return this.error === null;
30
+ }
31
+ get status_code() {
32
+ return this.statusCode;
33
+ }
34
+ get request_id() {
35
+ return this.requestId;
36
+ }
37
+ get job_id() {
38
+ return this.jobId;
39
+ }
40
+
41
+ raiseForError(): Record<string, unknown> {
42
+ if (this.error) throw this.error;
43
+ return this.data ?? {};
44
+ }
45
+
46
+ raise_for_error(): Record<string, unknown> {
47
+ return this.raiseForError();
48
+ }
49
+ }