@@ -10,6 +10,6 @@ import { ZodSchema } from 'zod'; | ||
| interface JsonConfig extends BaseConfig { | ||
| method?: 'json'; | ||
| format?: 'json'; | ||
| } | ||
| interface MarkdownConfig extends BaseConfig { | ||
| method: 'markdown'; | ||
| format: 'markdown'; | ||
| } | ||
@@ -16,0 +16,0 @@ export declare class BitBuffet { |
+15
-15
@@ -31,3 +31,3 @@ "use strict"; | ||
| try { | ||
| let method = 'json'; | ||
| let format = 'json'; | ||
| let schema; | ||
@@ -37,5 +37,5 @@ let config = {}; | ||
| // Parse arguments based on overload | ||
| if (schemaOrConfig && typeof schemaOrConfig === 'object' && 'method' in schemaOrConfig) { | ||
| if (schemaOrConfig && typeof schemaOrConfig === 'object' && 'format' in schemaOrConfig) { | ||
| // Config as second parameter: extract(url, config, timeout?) | ||
| method = schemaOrConfig.method; | ||
| format = schemaOrConfig.format; | ||
| config = schemaOrConfig; | ||
@@ -51,3 +51,3 @@ if (typeof configOrTimeout === 'number') { | ||
| config = configOrTimeout; | ||
| method = configOrTimeout.method || 'json'; | ||
| format = configOrTimeout.format || 'json'; | ||
| } | ||
@@ -62,17 +62,17 @@ else if (typeof configOrTimeout === 'number') { | ||
| } | ||
| // Validate method and schema requirements | ||
| if (method === 'json' && !schema) { | ||
| throw new Error("json_schema is required when method is 'json'"); | ||
| // Validate format and schema requirements | ||
| if (format === 'json' && !schema) { | ||
| throw new Error("json_schema is required when format is 'json'"); | ||
| } | ||
| // Remove the restriction for markdown + schema since it's now allowed | ||
| // The schema will simply be ignored for markdown extraction | ||
| if (method === 'markdown' && schema) { | ||
| throw new Error("json_schema should not be defined when method is 'markdown'"); | ||
| if (format === 'markdown' && schema) { | ||
| throw new Error("json_schema should not be defined when format is 'markdown'"); | ||
| } | ||
| const payload = { | ||
| url, | ||
| method, | ||
| format, | ||
| }; | ||
| // Add schema for JSON method | ||
| if (method === 'json' && schema) { | ||
| // Add schema for JSON format | ||
| if (format === 'json' && schema) { | ||
| const jsonSchema = (0, zod_to_json_schema_1.zodToJsonSchema)(schema); | ||
@@ -101,8 +101,8 @@ payload.json_schema = jsonSchema; | ||
| } | ||
| // Return based on method | ||
| if (method === 'markdown') { | ||
| // Return based on format | ||
| if (format === 'markdown') { | ||
| return result.data; | ||
| } | ||
| else { | ||
| // Validate and return the result using Zod for JSON method | ||
| // Validate and return the result using Zod for JSON format | ||
| return schema.parse(result.data); | ||
@@ -109,0 +109,0 @@ } |
+1
-1
| { | ||
| "name": "bitbuffet", | ||
| "version": "1.0.1", | ||
| "version": "1.0.2", | ||
| "description": "TypeScript SDK for the Structured Scraper API - BitBuffet", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
+30
-30
@@ -80,3 +80,3 @@ <img src="https://www.bitbuffet.dev/_next/image?url=%2Fbitbuffet-logo-closed-transparent.png&w=64&q=75" alt="BitBuffet Logo" width="64" height="64"> | ||
| 'https://example.com/article', | ||
| { method: 'markdown' } | ||
| { format: 'markdown' } | ||
| ); | ||
@@ -95,3 +95,3 @@ | ||
| ### JSON Method (Default) | ||
| ### JSON Format (Default) | ||
| Extracts structured data according to your Zod schema: | ||
@@ -109,7 +109,7 @@ | ||
| ProductSchema, | ||
| { method: 'json' } // Optional - this is the default | ||
| { format: 'json' } // Optional - this is the default | ||
| ); | ||
| ``` | ||
| ### Markdown Method | ||
| ### Markdown Format | ||
| Returns the raw markdown content of the webpage: | ||
@@ -120,15 +120,15 @@ | ||
| 'https://example.com/article', | ||
| { method: 'markdown' } | ||
| { format: 'markdown' } | ||
| ); | ||
| ``` | ||
| **Note:** When using `method: 'markdown'`, do not provide a schema as the second parameter. | ||
| **Note:** When using `format: 'markdown'`, do not provide a schema as the second parameter. | ||
| ### Method Usage Patterns | ||
| ### Format Usage Patterns | ||
| The SDK supports two extraction methods via the `method` parameter: | ||
| The SDK supports two extraction methods via the `format` parameter: | ||
| #### JSON Extraction (Default) | ||
| ```typescript | ||
| // Method 1a: Schema with optional config (method defaults to 'json') | ||
| // Format 1a: Schema with optional config (format defaults to 'json') | ||
| const result = await client.extract( | ||
@@ -138,3 +138,3 @@ 'https://example.com/article', | ||
| { | ||
| method: 'json', // Optional - this is the default | ||
| format: 'json', // Optional - this is the default | ||
| reasoning_effort: 'high' | ||
@@ -144,3 +144,3 @@ } | ||
| // Method 1b: Schema without config (method defaults to 'json') | ||
| // Format 1b: Schema without config (format defaults to 'json') | ||
| const result = await client.extract( | ||
@@ -154,7 +154,7 @@ 'https://example.com/article', | ||
| ```typescript | ||
| // Method 2a: Config object with method specified | ||
| // Format 2a: Config object with format specified | ||
| const markdown = await client.extract( | ||
| 'https://example.com/article', | ||
| { | ||
| method: 'markdown', | ||
| format: 'markdown', | ||
| reasoning_effort: 'medium', | ||
@@ -165,23 +165,23 @@ prompt: 'Focus on main content' | ||
| // Method 2b: Minimal markdown extraction | ||
| // Format 2b: Minimal markdown extraction | ||
| const markdown = await client.extract( | ||
| 'https://example.com/article', | ||
| { method: 'markdown' } | ||
| { format: 'markdown' } | ||
| ); | ||
| ``` | ||
| #### Important Method Rules: | ||
| #### Important Format Rules: | ||
| 1. **JSON Method Requirements:** | ||
| 1. **JSON Format Requirements:** | ||
| - A Zod schema MUST be provided as the second parameter | ||
| - Returns typed data matching your schema | ||
| - `method: 'json'` is optional (default behavior) | ||
| - `format: 'json'` is optional (default behavior) | ||
| 2. **Markdown Method Requirements:** | ||
| 2. **Markdown Format Requirements:** | ||
| - NO schema should be provided | ||
| - `method: 'markdown'` MUST be specified in config object | ||
| - `format: 'markdown'` MUST be specified in config object | ||
| - Returns raw markdown string | ||
| - Schema and markdown method cannot be used together | ||
| - Schema and markdown format cannot be used together | ||
| 3. **Method Parameter Location:** | ||
| 3. **Format Parameter Location:** | ||
| - Always specified in the configuration object | ||
@@ -200,3 +200,3 @@ - Never passed as a separate parameter | ||
| { | ||
| method: 'json', // Optional - default behavior | ||
| format: 'json', // Optional - default behavior | ||
| reasoning_effort: 'high', // 'medium' | 'high' - Higher effort for complex pages | ||
@@ -215,3 +215,3 @@ prompt: 'Focus on extracting the main article content, ignoring ads and navigation', | ||
| { | ||
| method: 'markdown', | ||
| format: 'markdown', | ||
| reasoning_effort: 'medium', | ||
@@ -278,3 +278,3 @@ prompt: 'Focus on the main content, ignore navigation and ads' | ||
| 'https://blog.example.com/post/123', | ||
| { method: 'markdown' } | ||
| { format: 'markdown' } | ||
| ); | ||
@@ -322,3 +322,3 @@ | ||
| - `url`: The URL to extract data from | ||
| - `schema`: Zod schema defining the expected data structure (JSON method only) | ||
| - `schema`: Zod schema defining the expected data structure (JSON format only) | ||
| - `config`: Extraction configuration options | ||
@@ -328,4 +328,4 @@ - `timeout`: Request timeout in milliseconds (default: 30000) | ||
| **Returns:** | ||
| - JSON method: Promise resolving to the extracted data matching your schema | ||
| - Markdown method: Promise resolving to raw markdown content as string | ||
| - JSON format: Promise resolving to the extracted data matching your schema | ||
| - Markdown format: Promise resolving to raw markdown content as string | ||
@@ -336,3 +336,3 @@ ### Types | ||
| interface JsonConfig { | ||
| method?: 'json'; // Optional - this is the default | ||
| format?: 'json'; // Optional - this is the default | ||
| reasoning_effort?: 'medium' | 'high'; | ||
@@ -345,3 +345,3 @@ prompt?: string; | ||
| interface MarkdownConfig { | ||
| method: 'markdown'; // Required for markdown extraction | ||
| format: 'markdown'; // Required for markdown extraction | ||
| reasoning_effort?: 'medium' | 'high'; | ||
@@ -348,0 +348,0 @@ prompt?: string; |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package