omnifetch-lib 1.0.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 +51 -0
- package/dist/index.d.mts +92 -0
- package/dist/index.d.ts +92 -0
- package/dist/index.js +728 -0
- package/dist/index.mjs +688 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# OmniFetch JavaScript Library
|
|
2
|
+
|
|
3
|
+
JavaScript/TypeScript implementation of OmniFetch - a universal content extraction library.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install omnifetch
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { omniFetch } from 'omnifetch';
|
|
15
|
+
|
|
16
|
+
// Text extraction
|
|
17
|
+
const result = await omniFetch('https://example.com', { mode: 'TEXT' });
|
|
18
|
+
console.log(result.content);
|
|
19
|
+
|
|
20
|
+
// JSON extraction
|
|
21
|
+
const jsonResult = await omniFetch('https://example.com', { mode: 'JSON' });
|
|
22
|
+
console.log(jsonResult.content.title);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Configuration
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
interface OmniFetchConfig {
|
|
29
|
+
mode: 'JSON' | 'TEXT'; // Output format
|
|
30
|
+
timeout?: number; // Request timeout in ms (default: 30000)
|
|
31
|
+
netlifyEndpoint?: string; // Headless browser endpoint
|
|
32
|
+
headers?: Record<string, string>; // Custom headers
|
|
33
|
+
skipHeadless?: boolean; // Skip Tier 2
|
|
34
|
+
skipSearch?: boolean; // Skip Tier 3
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Building
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install
|
|
42
|
+
npm run build
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Development
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm run dev # Watch mode
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
See the main [README.md](../../README.md) for full documentation.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OmniFetch TypeScript Type Definitions
|
|
3
|
+
*/
|
|
4
|
+
/** Supported output modes */
|
|
5
|
+
type OutputMode = 'JSON' | 'TEXT';
|
|
6
|
+
/** Configuration options for OmniFetch */
|
|
7
|
+
interface OmniFetchConfig {
|
|
8
|
+
/** Output mode: 'JSON' for structured data, 'TEXT' for plain text */
|
|
9
|
+
mode: OutputMode;
|
|
10
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
11
|
+
timeout?: number;
|
|
12
|
+
/** Custom Netlify endpoint for headless browser fallback */
|
|
13
|
+
netlifyEndpoint?: string;
|
|
14
|
+
/** Custom headers to include in requests */
|
|
15
|
+
headers?: Record<string, string>;
|
|
16
|
+
/** Whether to skip Tier 2 (headless) and go directly to search fallback */
|
|
17
|
+
skipHeadless?: boolean;
|
|
18
|
+
/** Whether to skip Tier 3 (search fallback) entirely */
|
|
19
|
+
skipSearch?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/** Result returned by OmniFetch */
|
|
22
|
+
interface OmniFetchResult {
|
|
23
|
+
/** Whether the fetch was successful */
|
|
24
|
+
success: boolean;
|
|
25
|
+
/** The extracted content (string for TEXT mode, object for JSON mode) */
|
|
26
|
+
content?: string | Record<string, unknown>;
|
|
27
|
+
/** Array of suggested alternative URLs (when content not found) */
|
|
28
|
+
suggestions?: string[];
|
|
29
|
+
/** Error message if fetch failed */
|
|
30
|
+
error?: string;
|
|
31
|
+
/** Which tier successfully retrieved the content */
|
|
32
|
+
tier?: 1 | 2 | 3;
|
|
33
|
+
/** The final URL after any redirects */
|
|
34
|
+
finalUrl?: string;
|
|
35
|
+
/** Page title extracted from the content */
|
|
36
|
+
title?: string;
|
|
37
|
+
}
|
|
38
|
+
/** Default configuration values */
|
|
39
|
+
declare const DEFAULT_CONFIG: Required<Omit<OmniFetchConfig, 'headers'>> & {
|
|
40
|
+
headers: Record<string, string>;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* OmniFetch - Universal Content Extraction Library
|
|
45
|
+
*
|
|
46
|
+
* A cross-platform library for intelligent content extraction
|
|
47
|
+
* with tiered fetching strategies to bypass bot detection and paywalls.
|
|
48
|
+
*
|
|
49
|
+
* @packageDocumentation
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Fetch content from a URL using OmniFetch's tiered strategy
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* import { omniFetch } from 'omnifetch';
|
|
58
|
+
*
|
|
59
|
+
* // Simple text extraction
|
|
60
|
+
* const result = await omniFetch('https://example.com', { mode: 'TEXT' });
|
|
61
|
+
* console.log(result.content);
|
|
62
|
+
*
|
|
63
|
+
* // JSON extraction with custom endpoint
|
|
64
|
+
* const jsonResult = await omniFetch('https://example.com/article', {
|
|
65
|
+
* mode: 'JSON',
|
|
66
|
+
* netlifyEndpoint: 'https://your-app.netlify.app/.netlify/functions/headless-fetch'
|
|
67
|
+
* });
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @param url - The URL to fetch content from
|
|
71
|
+
* @param config - Configuration options (mode, timeout, etc.)
|
|
72
|
+
* @returns Promise resolving to OmniFetchResult
|
|
73
|
+
*/
|
|
74
|
+
declare function omniFetch(url: string, config?: Partial<OmniFetchConfig>): Promise<OmniFetchResult>;
|
|
75
|
+
/**
|
|
76
|
+
* Convenience function for TEXT mode extraction
|
|
77
|
+
*
|
|
78
|
+
* @param url - The URL to fetch
|
|
79
|
+
* @param options - Optional configuration (excluding mode)
|
|
80
|
+
* @returns Promise resolving to text content or error
|
|
81
|
+
*/
|
|
82
|
+
declare function fetchText(url: string, options?: Omit<Partial<OmniFetchConfig>, 'mode'>): Promise<OmniFetchResult>;
|
|
83
|
+
/**
|
|
84
|
+
* Convenience function for JSON mode extraction
|
|
85
|
+
*
|
|
86
|
+
* @param url - The URL to fetch
|
|
87
|
+
* @param options - Optional configuration (excluding mode)
|
|
88
|
+
* @returns Promise resolving to JSON content or error
|
|
89
|
+
*/
|
|
90
|
+
declare function fetchJson(url: string, options?: Omit<Partial<OmniFetchConfig>, 'mode'>): Promise<OmniFetchResult>;
|
|
91
|
+
|
|
92
|
+
export { DEFAULT_CONFIG, type OmniFetchConfig, type OmniFetchResult, type OutputMode, omniFetch as default, fetchJson, fetchText, omniFetch };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OmniFetch TypeScript Type Definitions
|
|
3
|
+
*/
|
|
4
|
+
/** Supported output modes */
|
|
5
|
+
type OutputMode = 'JSON' | 'TEXT';
|
|
6
|
+
/** Configuration options for OmniFetch */
|
|
7
|
+
interface OmniFetchConfig {
|
|
8
|
+
/** Output mode: 'JSON' for structured data, 'TEXT' for plain text */
|
|
9
|
+
mode: OutputMode;
|
|
10
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
11
|
+
timeout?: number;
|
|
12
|
+
/** Custom Netlify endpoint for headless browser fallback */
|
|
13
|
+
netlifyEndpoint?: string;
|
|
14
|
+
/** Custom headers to include in requests */
|
|
15
|
+
headers?: Record<string, string>;
|
|
16
|
+
/** Whether to skip Tier 2 (headless) and go directly to search fallback */
|
|
17
|
+
skipHeadless?: boolean;
|
|
18
|
+
/** Whether to skip Tier 3 (search fallback) entirely */
|
|
19
|
+
skipSearch?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/** Result returned by OmniFetch */
|
|
22
|
+
interface OmniFetchResult {
|
|
23
|
+
/** Whether the fetch was successful */
|
|
24
|
+
success: boolean;
|
|
25
|
+
/** The extracted content (string for TEXT mode, object for JSON mode) */
|
|
26
|
+
content?: string | Record<string, unknown>;
|
|
27
|
+
/** Array of suggested alternative URLs (when content not found) */
|
|
28
|
+
suggestions?: string[];
|
|
29
|
+
/** Error message if fetch failed */
|
|
30
|
+
error?: string;
|
|
31
|
+
/** Which tier successfully retrieved the content */
|
|
32
|
+
tier?: 1 | 2 | 3;
|
|
33
|
+
/** The final URL after any redirects */
|
|
34
|
+
finalUrl?: string;
|
|
35
|
+
/** Page title extracted from the content */
|
|
36
|
+
title?: string;
|
|
37
|
+
}
|
|
38
|
+
/** Default configuration values */
|
|
39
|
+
declare const DEFAULT_CONFIG: Required<Omit<OmniFetchConfig, 'headers'>> & {
|
|
40
|
+
headers: Record<string, string>;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* OmniFetch - Universal Content Extraction Library
|
|
45
|
+
*
|
|
46
|
+
* A cross-platform library for intelligent content extraction
|
|
47
|
+
* with tiered fetching strategies to bypass bot detection and paywalls.
|
|
48
|
+
*
|
|
49
|
+
* @packageDocumentation
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Fetch content from a URL using OmniFetch's tiered strategy
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* import { omniFetch } from 'omnifetch';
|
|
58
|
+
*
|
|
59
|
+
* // Simple text extraction
|
|
60
|
+
* const result = await omniFetch('https://example.com', { mode: 'TEXT' });
|
|
61
|
+
* console.log(result.content);
|
|
62
|
+
*
|
|
63
|
+
* // JSON extraction with custom endpoint
|
|
64
|
+
* const jsonResult = await omniFetch('https://example.com/article', {
|
|
65
|
+
* mode: 'JSON',
|
|
66
|
+
* netlifyEndpoint: 'https://your-app.netlify.app/.netlify/functions/headless-fetch'
|
|
67
|
+
* });
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @param url - The URL to fetch content from
|
|
71
|
+
* @param config - Configuration options (mode, timeout, etc.)
|
|
72
|
+
* @returns Promise resolving to OmniFetchResult
|
|
73
|
+
*/
|
|
74
|
+
declare function omniFetch(url: string, config?: Partial<OmniFetchConfig>): Promise<OmniFetchResult>;
|
|
75
|
+
/**
|
|
76
|
+
* Convenience function for TEXT mode extraction
|
|
77
|
+
*
|
|
78
|
+
* @param url - The URL to fetch
|
|
79
|
+
* @param options - Optional configuration (excluding mode)
|
|
80
|
+
* @returns Promise resolving to text content or error
|
|
81
|
+
*/
|
|
82
|
+
declare function fetchText(url: string, options?: Omit<Partial<OmniFetchConfig>, 'mode'>): Promise<OmniFetchResult>;
|
|
83
|
+
/**
|
|
84
|
+
* Convenience function for JSON mode extraction
|
|
85
|
+
*
|
|
86
|
+
* @param url - The URL to fetch
|
|
87
|
+
* @param options - Optional configuration (excluding mode)
|
|
88
|
+
* @returns Promise resolving to JSON content or error
|
|
89
|
+
*/
|
|
90
|
+
declare function fetchJson(url: string, options?: Omit<Partial<OmniFetchConfig>, 'mode'>): Promise<OmniFetchResult>;
|
|
91
|
+
|
|
92
|
+
export { DEFAULT_CONFIG, type OmniFetchConfig, type OmniFetchResult, type OutputMode, omniFetch as default, fetchJson, fetchText, omniFetch };
|