@hydrafetch/node-sdk 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -82,6 +82,16 @@ out.results.forEach((item) => console.log(item.url, item.data?.name));
82
82
 
83
83
  Pass `prompt` instead of, or alongside, `schema` to describe the fields in plain language.
84
84
 
85
+ Sites that price or stock by delivery area serve a different page for each area. Pass `location` to fetch as if from a country and language, and `headers` to send the cookie that picks the store or area, the same options `scrape` takes.
86
+
87
+ ```ts
88
+ const out = await hf.extract(['https://shop.example/search?q=ghee'], {
89
+ prompt: 'every product with its size and price',
90
+ location: { country: 'in' },
91
+ headers: { Cookie: 'store_id=42' },
92
+ });
93
+ ```
94
+
85
95
  ### Zod schemas
86
96
 
87
97
  If you already use Zod, pass the schema directly. Zod stays optional and is imported only when you
@@ -162,6 +172,7 @@ results.forEach((r) => console.log(r.title, r.url, r.data?.markdown));
162
172
  await hf.brand('stripe.com'); // logos, colours, fonts, socials
163
173
  await hf.logo('stripe.com', { theme: 'dark', type: 'icon' }); // one asset
164
174
  await hf.styleguide('stripe.com'); // computed design system
175
+ await hf.styleguide('https://stripe.com/pricing', { maxAge: 0 }); // one page, read fresh
165
176
  ```
166
177
 
167
178
  For logos in a browser use [`@hydrafetch/client-sdk`](https://github.com/Hydrafetch/client-sdk) or [`@hydrafetch/react`](https://github.com/Hydrafetch/react-sdk) with a publishable key. Those bill against logo pulls rather than credits.
@@ -225,7 +236,7 @@ const hf = new Hydrafetch({
225
236
  | `extract(urls, options?)` | `ExtractResult<T>` | 5 per URL |
226
237
  | `brand(domain)` | `BrandResult` | 5 |
227
238
  | `logo(domain, options?)` | `LogoResult` | 1 |
228
- | `styleguide(domain)` | `StyleguideResult` | 10 |
239
+ | `styleguide(domainOrUrl, options?)` | `StyleguideResult` | 10 |
229
240
  | `screenshot(url, options?)` | `ScreenshotResult` | 5 |
230
241
  | `images(url)` | `ImagesResult` | 1 |
231
242
  | `links(url, options?)` | `ScrapeResult<'links'>` | 1 |
package/dist/index.cjs CHANGED
@@ -241,8 +241,12 @@ var Hydrafetch = class {
241
241
  logo(domain, options = {}) {
242
242
  return this.request("GET", "/v1/web/brand/logo", void 0, { domain, ...options });
243
243
  }
244
- styleguide(domain) {
245
- return this.request("GET", "/v1/web/styleguide", void 0, { domain });
244
+ styleguide(domainOrUrl, options = {}) {
245
+ const target = /^https?:\/\//i.test(domainOrUrl) ? { url: domainOrUrl } : { domain: domainOrUrl };
246
+ return this.request("GET", "/v1/web/styleguide", void 0, {
247
+ ...target,
248
+ ...options
249
+ });
246
250
  }
247
251
  screenshot(url, options = {}) {
248
252
  return this.request("POST", "/v1/web/screenshot", { url, ...options });
package/dist/index.d.cts CHANGED
@@ -34,6 +34,10 @@ interface ScrapeBase {
34
34
  type ScrapeResult<F extends Format = 'markdown'> = ScrapeBase & {
35
35
  [K in F]: ScrapeContent[K];
36
36
  } & Partial<Omit<ScrapeContent, F>>;
37
+ interface Location {
38
+ country?: string;
39
+ languages?: string[];
40
+ }
37
41
  interface ScrapeOptions<F extends readonly Format[] = readonly Format[]> {
38
42
  formats?: F;
39
43
  maxAge?: number;
@@ -48,6 +52,7 @@ interface ScrapeOptions<F extends readonly Format[] = readonly Format[]> {
48
52
  includeLinks?: boolean;
49
53
  waitFor?: number;
50
54
  timeout?: number;
55
+ location?: Location;
51
56
  headers?: Record<string, string>;
52
57
  jsonOptions?: Record<string, unknown>;
53
58
  }
@@ -114,6 +119,8 @@ interface ExtractOptions {
114
119
  showConfidence?: boolean;
115
120
  mergeEntities?: boolean;
116
121
  maxAge?: number;
122
+ location?: Location;
123
+ headers?: Record<string, string>;
117
124
  }
118
125
  interface ExtractItem<T = unknown> {
119
126
  url: string;
@@ -185,8 +192,12 @@ interface LogoResult {
185
192
  type?: string;
186
193
  [key: string]: unknown;
187
194
  }
195
+ interface StyleguideOptions {
196
+ maxAge?: number;
197
+ }
188
198
  interface StyleguideResult {
189
199
  domain?: string;
200
+ page?: string;
190
201
  colors?: Record<string, unknown>;
191
202
  typography?: Record<string, unknown>;
192
203
  [key: string]: unknown;
@@ -250,7 +261,7 @@ declare class Hydrafetch {
250
261
  extract<T = unknown>(urls: string | string[], options?: ExtractOptions): Promise<ExtractResult<T>>;
251
262
  brand(domain: string): Promise<BrandResult>;
252
263
  logo(domain: string, options?: BrandOptions): Promise<LogoResult>;
253
- styleguide(domain: string): Promise<StyleguideResult>;
264
+ styleguide(domainOrUrl: string, options?: StyleguideOptions): Promise<StyleguideResult>;
254
265
  screenshot(url: string, options?: ScreenshotOptions): Promise<ScreenshotResult>;
255
266
  images(url: string, options?: {
256
267
  maxAge?: number;
@@ -286,4 +297,4 @@ declare class HydrafetchTimeoutError extends HydrafetchError {
286
297
  constructor(message: string);
287
298
  }
288
299
 
289
- export { type BatchOptions, type BrandOptions, type BrandResult, type CrawlOptions, type ExtractItem, type ExtractOptions, type ExtractResult, type ExtractSchema, type Format, Hydrafetch, HydrafetchError, type HydrafetchOptions, HydrafetchTimeoutError, type ImagesResult, type JobPage, type JobResult, type JobStatus, type LogoResult, type MapOptions, type MapResult, type PageImage, type PageMetadata, type ScrapeBase, type ScrapeContent, type ScrapeOptions, type ScrapeResult, type ScreenshotOptions, type ScreenshotResult, type SearchOptions, type SearchResult, type SearchResultItem, type StyleguideResult, type Usage, type WaitOptions, type ZodLike };
300
+ export { type BatchOptions, type BrandOptions, type BrandResult, type CrawlOptions, type ExtractItem, type ExtractOptions, type ExtractResult, type ExtractSchema, type Format, Hydrafetch, HydrafetchError, type HydrafetchOptions, HydrafetchTimeoutError, type ImagesResult, type JobPage, type JobResult, type JobStatus, type Location, type LogoResult, type MapOptions, type MapResult, type PageImage, type PageMetadata, type ScrapeBase, type ScrapeContent, type ScrapeOptions, type ScrapeResult, type ScreenshotOptions, type ScreenshotResult, type SearchOptions, type SearchResult, type SearchResultItem, type StyleguideOptions, type StyleguideResult, type Usage, type WaitOptions, type ZodLike };
package/dist/index.d.ts CHANGED
@@ -34,6 +34,10 @@ interface ScrapeBase {
34
34
  type ScrapeResult<F extends Format = 'markdown'> = ScrapeBase & {
35
35
  [K in F]: ScrapeContent[K];
36
36
  } & Partial<Omit<ScrapeContent, F>>;
37
+ interface Location {
38
+ country?: string;
39
+ languages?: string[];
40
+ }
37
41
  interface ScrapeOptions<F extends readonly Format[] = readonly Format[]> {
38
42
  formats?: F;
39
43
  maxAge?: number;
@@ -48,6 +52,7 @@ interface ScrapeOptions<F extends readonly Format[] = readonly Format[]> {
48
52
  includeLinks?: boolean;
49
53
  waitFor?: number;
50
54
  timeout?: number;
55
+ location?: Location;
51
56
  headers?: Record<string, string>;
52
57
  jsonOptions?: Record<string, unknown>;
53
58
  }
@@ -114,6 +119,8 @@ interface ExtractOptions {
114
119
  showConfidence?: boolean;
115
120
  mergeEntities?: boolean;
116
121
  maxAge?: number;
122
+ location?: Location;
123
+ headers?: Record<string, string>;
117
124
  }
118
125
  interface ExtractItem<T = unknown> {
119
126
  url: string;
@@ -185,8 +192,12 @@ interface LogoResult {
185
192
  type?: string;
186
193
  [key: string]: unknown;
187
194
  }
195
+ interface StyleguideOptions {
196
+ maxAge?: number;
197
+ }
188
198
  interface StyleguideResult {
189
199
  domain?: string;
200
+ page?: string;
190
201
  colors?: Record<string, unknown>;
191
202
  typography?: Record<string, unknown>;
192
203
  [key: string]: unknown;
@@ -250,7 +261,7 @@ declare class Hydrafetch {
250
261
  extract<T = unknown>(urls: string | string[], options?: ExtractOptions): Promise<ExtractResult<T>>;
251
262
  brand(domain: string): Promise<BrandResult>;
252
263
  logo(domain: string, options?: BrandOptions): Promise<LogoResult>;
253
- styleguide(domain: string): Promise<StyleguideResult>;
264
+ styleguide(domainOrUrl: string, options?: StyleguideOptions): Promise<StyleguideResult>;
254
265
  screenshot(url: string, options?: ScreenshotOptions): Promise<ScreenshotResult>;
255
266
  images(url: string, options?: {
256
267
  maxAge?: number;
@@ -286,4 +297,4 @@ declare class HydrafetchTimeoutError extends HydrafetchError {
286
297
  constructor(message: string);
287
298
  }
288
299
 
289
- export { type BatchOptions, type BrandOptions, type BrandResult, type CrawlOptions, type ExtractItem, type ExtractOptions, type ExtractResult, type ExtractSchema, type Format, Hydrafetch, HydrafetchError, type HydrafetchOptions, HydrafetchTimeoutError, type ImagesResult, type JobPage, type JobResult, type JobStatus, type LogoResult, type MapOptions, type MapResult, type PageImage, type PageMetadata, type ScrapeBase, type ScrapeContent, type ScrapeOptions, type ScrapeResult, type ScreenshotOptions, type ScreenshotResult, type SearchOptions, type SearchResult, type SearchResultItem, type StyleguideResult, type Usage, type WaitOptions, type ZodLike };
300
+ export { type BatchOptions, type BrandOptions, type BrandResult, type CrawlOptions, type ExtractItem, type ExtractOptions, type ExtractResult, type ExtractSchema, type Format, Hydrafetch, HydrafetchError, type HydrafetchOptions, HydrafetchTimeoutError, type ImagesResult, type JobPage, type JobResult, type JobStatus, type Location, type LogoResult, type MapOptions, type MapResult, type PageImage, type PageMetadata, type ScrapeBase, type ScrapeContent, type ScrapeOptions, type ScrapeResult, type ScreenshotOptions, type ScreenshotResult, type SearchOptions, type SearchResult, type SearchResultItem, type StyleguideOptions, type StyleguideResult, type Usage, type WaitOptions, type ZodLike };
package/dist/index.js CHANGED
@@ -213,8 +213,12 @@ var Hydrafetch = class {
213
213
  logo(domain, options = {}) {
214
214
  return this.request("GET", "/v1/web/brand/logo", void 0, { domain, ...options });
215
215
  }
216
- styleguide(domain) {
217
- return this.request("GET", "/v1/web/styleguide", void 0, { domain });
216
+ styleguide(domainOrUrl, options = {}) {
217
+ const target = /^https?:\/\//i.test(domainOrUrl) ? { url: domainOrUrl } : { domain: domainOrUrl };
218
+ return this.request("GET", "/v1/web/styleguide", void 0, {
219
+ ...target,
220
+ ...options
221
+ });
218
222
  }
219
223
  screenshot(url, options = {}) {
220
224
  return this.request("POST", "/v1/web/screenshot", { url, ...options });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hydrafetch/node-sdk",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Official Node/TypeScript client for the Hydrafetch web data API. Turn any URL into clean Markdown and structured data.",
5
5
  "keywords": [
6
6
  "hydrafetch",