novada-proxy-sdk 0.0.1

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.
@@ -0,0 +1,22 @@
1
+ import { type ProxySuccessResponse } from "novada-proxy-core";
2
+ import type { BatchFetchOptions, CrawlOptions, ExtractOptions, FetchOptions, MapOptions, NovadaProxyOptions, RenderOptions, ResearchOptions, SearchOptions, SessionOptions } from "./types.js";
3
+ export type { BatchFetchOptions, CrawlOptions, ExtractOptions, FetchOptions, MapOptions, NovadaProxyOptions, RenderOptions, ResearchOptions, SearchOptions, SessionOptions, } from "./types.js";
4
+ export type { ProxyAdapter, ProxyCredentials, ProxyErrorResponse, ProxyResponse, ProxySuccessResponse, } from "novada-proxy-core";
5
+ export declare class NovadaProxy {
6
+ private readonly adapter;
7
+ private readonly credentials;
8
+ private readonly apiKey?;
9
+ private readonly browserWs?;
10
+ constructor(options?: NovadaProxyOptions);
11
+ static fromEnv(): NovadaProxy;
12
+ fetch(options: FetchOptions): Promise<ProxySuccessResponse>;
13
+ batchFetch(options: BatchFetchOptions): Promise<ProxySuccessResponse>;
14
+ search(options: SearchOptions): Promise<ProxySuccessResponse>;
15
+ extract(options: ExtractOptions): Promise<ProxySuccessResponse>;
16
+ map(options: MapOptions): Promise<ProxySuccessResponse>;
17
+ crawl(options: CrawlOptions): Promise<ProxySuccessResponse>;
18
+ research(options: ResearchOptions): Promise<ProxySuccessResponse>;
19
+ render(options: RenderOptions): Promise<ProxySuccessResponse>;
20
+ session(options: SessionOptions): Promise<ProxySuccessResponse>;
21
+ status(): Promise<ProxySuccessResponse>;
22
+ }
package/build/index.js ADDED
@@ -0,0 +1,156 @@
1
+ import { novadaProxyBatchFetch, novadaProxyCrawl, novadaProxyExtract, novadaProxyFetch, novadaProxyMap, novadaProxyRender, novadaProxyResearch, novadaProxySearch, novadaProxySession, novadaProxyStatus, resolveAdapter, validateBatchFetchParams, validateCrawlParams, validateExtractParams, validateFetchParams, validateMapParams, validateRenderParams, validateResearchParams, validateSearchParams, validateSessionParams, } from "novada-proxy-core";
2
+ function parseResult(raw) {
3
+ return JSON.parse(raw);
4
+ }
5
+ function dropUndefined(value) {
6
+ for (const key of Object.keys(value)) {
7
+ if (value[key] === undefined)
8
+ delete value[key];
9
+ }
10
+ return value;
11
+ }
12
+ function configureEnv(options) {
13
+ if (options.user !== undefined)
14
+ process.env.NOVADA_PROXY_USER = options.user;
15
+ if (options.pass !== undefined)
16
+ process.env.NOVADA_PROXY_PASS = options.pass;
17
+ if (options.host !== undefined)
18
+ process.env.NOVADA_PROXY_HOST = options.host;
19
+ if (options.port !== undefined)
20
+ process.env.NOVADA_PROXY_PORT = String(options.port);
21
+ if (options.apiKey !== undefined)
22
+ process.env.NOVADA_API_KEY = options.apiKey;
23
+ if (options.browserWs !== undefined)
24
+ process.env.NOVADA_BROWSER_WS = options.browserWs;
25
+ if (options.provider !== undefined)
26
+ process.env.NOVADA_PROXY_PROVIDER = options.provider;
27
+ }
28
+ export class NovadaProxy {
29
+ adapter;
30
+ credentials;
31
+ apiKey;
32
+ browserWs;
33
+ constructor(options = {}) {
34
+ configureEnv(options);
35
+ const resolved = resolveAdapter(process.env);
36
+ if (!resolved) {
37
+ throw new Error("No proxy adapter resolved. Provide Novada proxy credentials or set NOVADA_PROXY_USER and NOVADA_PROXY_PASS.");
38
+ }
39
+ this.adapter = resolved.adapter;
40
+ this.credentials = resolved.credentials;
41
+ this.apiKey = options.apiKey ?? process.env.NOVADA_API_KEY;
42
+ this.browserWs = options.browserWs ?? process.env.NOVADA_BROWSER_WS;
43
+ }
44
+ static fromEnv() {
45
+ return new NovadaProxy({});
46
+ }
47
+ async fetch(options) {
48
+ const params = validateFetchParams(dropUndefined({
49
+ url: options.url,
50
+ country: options.country,
51
+ city: options.city,
52
+ session_id: options.sessionId,
53
+ format: options.format,
54
+ timeout: options.timeout,
55
+ }));
56
+ return parseResult(await novadaProxyFetch(params, this.adapter, this.credentials));
57
+ }
58
+ async batchFetch(options) {
59
+ const params = validateBatchFetchParams(dropUndefined({
60
+ urls: options.urls,
61
+ country: options.country,
62
+ session_id: options.sessionId,
63
+ format: options.format,
64
+ timeout: options.timeout,
65
+ concurrency: options.concurrency,
66
+ }));
67
+ return parseResult(await novadaProxyBatchFetch(params, this.adapter, this.credentials));
68
+ }
69
+ async search(options) {
70
+ if (!this.apiKey) {
71
+ throw new Error("NOVADA_API_KEY is required for search.");
72
+ }
73
+ const params = validateSearchParams(dropUndefined({
74
+ query: options.query,
75
+ engine: options.engine,
76
+ num: options.num,
77
+ country: options.country,
78
+ language: options.language,
79
+ }));
80
+ return parseResult(await novadaProxySearch(params, this.apiKey));
81
+ }
82
+ async extract(options) {
83
+ const params = validateExtractParams(dropUndefined({
84
+ url: options.url,
85
+ fields: options.fields,
86
+ schema: options.schema,
87
+ country: options.country,
88
+ city: options.city,
89
+ session_id: options.sessionId,
90
+ timeout: options.timeout,
91
+ render_fallback: options.renderFallback,
92
+ }));
93
+ return parseResult(await novadaProxyExtract(params, this.adapter, this.credentials, this.browserWs));
94
+ }
95
+ async map(options) {
96
+ const params = validateMapParams(dropUndefined({
97
+ url: options.url,
98
+ limit: options.limit,
99
+ include_external: options.includeExternal,
100
+ country: options.country,
101
+ timeout: options.timeout,
102
+ }));
103
+ return parseResult(await novadaProxyMap(params, this.adapter, this.credentials));
104
+ }
105
+ async crawl(options) {
106
+ const params = validateCrawlParams(dropUndefined({
107
+ url: options.url,
108
+ depth: options.depth,
109
+ limit: options.limit,
110
+ include_content: options.includeContent,
111
+ country: options.country,
112
+ timeout: options.timeout,
113
+ format: options.format,
114
+ }));
115
+ return parseResult(await novadaProxyCrawl(params, this.adapter, this.credentials));
116
+ }
117
+ async research(options) {
118
+ if (!this.apiKey) {
119
+ throw new Error("NOVADA_API_KEY is required for research.");
120
+ }
121
+ const params = validateResearchParams(dropUndefined({
122
+ query: options.query,
123
+ depth: options.depth,
124
+ country: options.country,
125
+ timeout: options.timeout,
126
+ }));
127
+ return parseResult(await novadaProxyResearch(params, this.adapter, this.credentials, this.apiKey));
128
+ }
129
+ async render(options) {
130
+ if (!this.browserWs) {
131
+ throw new Error("NOVADA_BROWSER_WS is required for render.");
132
+ }
133
+ const params = validateRenderParams(dropUndefined({
134
+ url: options.url,
135
+ format: options.format,
136
+ wait_for: options.waitFor,
137
+ timeout: options.timeout,
138
+ }));
139
+ return parseResult(await novadaProxyRender(params, this.browserWs));
140
+ }
141
+ async session(options) {
142
+ const params = validateSessionParams(dropUndefined({
143
+ session_id: options.sessionId,
144
+ url: options.url,
145
+ country: options.country,
146
+ city: options.city,
147
+ format: options.format,
148
+ timeout: options.timeout,
149
+ verify_sticky: options.verifySticky,
150
+ }));
151
+ return parseResult(await novadaProxySession(params, this.adapter, this.credentials));
152
+ }
153
+ async status() {
154
+ return parseResult(await novadaProxyStatus(this.adapter, this.credentials));
155
+ }
156
+ }
@@ -0,0 +1,79 @@
1
+ export interface NovadaProxyOptions {
2
+ user?: string;
3
+ pass?: string;
4
+ host?: string;
5
+ port?: string | number;
6
+ apiKey?: string;
7
+ browserWs?: string;
8
+ provider?: string;
9
+ }
10
+ export interface FetchOptions {
11
+ url: string;
12
+ country?: string;
13
+ city?: string;
14
+ sessionId?: string;
15
+ format?: "raw" | "markdown";
16
+ timeout?: number;
17
+ }
18
+ export interface BatchFetchOptions {
19
+ urls: string[];
20
+ country?: string;
21
+ sessionId?: string;
22
+ format?: "raw" | "markdown";
23
+ timeout?: number;
24
+ concurrency?: number;
25
+ }
26
+ export interface SearchOptions {
27
+ query: string;
28
+ engine?: "google";
29
+ num?: number;
30
+ country?: string;
31
+ language?: string;
32
+ }
33
+ export interface ExtractOptions {
34
+ url: string;
35
+ fields: string[];
36
+ schema?: Record<string, string>;
37
+ country?: string;
38
+ city?: string;
39
+ sessionId?: string;
40
+ timeout?: number;
41
+ renderFallback?: boolean;
42
+ }
43
+ export interface MapOptions {
44
+ url: string;
45
+ limit?: number;
46
+ includeExternal?: boolean;
47
+ country?: string;
48
+ timeout?: number;
49
+ }
50
+ export interface CrawlOptions {
51
+ url: string;
52
+ depth?: number;
53
+ limit?: number;
54
+ includeContent?: boolean;
55
+ country?: string;
56
+ timeout?: number;
57
+ format?: "markdown" | "raw";
58
+ }
59
+ export interface ResearchOptions {
60
+ query: string;
61
+ depth?: "quick" | "standard" | "deep";
62
+ country?: string;
63
+ timeout?: number;
64
+ }
65
+ export interface RenderOptions {
66
+ url: string;
67
+ format?: "markdown" | "html" | "text";
68
+ waitFor?: string;
69
+ timeout?: number;
70
+ }
71
+ export interface SessionOptions {
72
+ sessionId: string;
73
+ url: string;
74
+ country?: string;
75
+ city?: string;
76
+ format?: "raw" | "markdown";
77
+ timeout?: number;
78
+ verifySticky?: boolean;
79
+ }
package/build/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "novada-proxy-sdk",
3
+ "version": "0.0.1",
4
+ "description": "Novada Proxy SDK \u2014 residential proxy for TypeScript/JavaScript apps",
5
+ "type": "module",
6
+ "main": "build/index.js",
7
+ "types": "build/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./build/index.d.ts",
11
+ "import": "./build/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "build/**/*.js",
16
+ "build/**/*.d.ts",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc",
21
+ "test": "vitest run"
22
+ },
23
+ "dependencies": {
24
+ "novada-proxy-core": "^0.0.1"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "^20.11.24",
28
+ "typescript": "^5.3.3",
29
+ "vitest": "^4.1.4"
30
+ },
31
+ "engines": {
32
+ "node": ">=18.0.0"
33
+ },
34
+ "license": "MIT"
35
+ }