@knowledgesdk/node 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.
- package/LICENSE +21 -0
- package/README.md +495 -0
- package/dist/api/classify.d.ts +24 -0
- package/dist/api/classify.js +19 -0
- package/dist/api/classify.js.map +1 -0
- package/dist/api/extract.d.ts +118 -0
- package/dist/api/extract.js +60 -0
- package/dist/api/extract.js.map +1 -0
- package/dist/api/jobs.d.ts +35 -0
- package/dist/api/jobs.js +43 -0
- package/dist/api/jobs.js.map +1 -0
- package/dist/api/scrape.d.ts +18 -0
- package/dist/api/scrape.js +18 -0
- package/dist/api/scrape.js.map +1 -0
- package/dist/api/screenshot.d.ts +15 -0
- package/dist/api/screenshot.js +18 -0
- package/dist/api/screenshot.js.map +1 -0
- package/dist/api/search.d.ts +29 -0
- package/dist/api/search.js +22 -0
- package/dist/api/search.js.map +1 -0
- package/dist/api/sitemap.d.ts +17 -0
- package/dist/api/sitemap.js +19 -0
- package/dist/api/sitemap.js.map +1 -0
- package/dist/api/webhooks.d.ts +40 -0
- package/dist/api/webhooks.js +39 -0
- package/dist/api/webhooks.js.map +1 -0
- package/dist/constants.d.ts +5 -0
- package/dist/constants.js +9 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors.d.ts +32 -0
- package/dist/errors.js +52 -0
- package/dist/errors.js.map +1 -0
- package/dist/esm/api/classify.d.ts +24 -0
- package/dist/esm/api/classify.js +15 -0
- package/dist/esm/api/classify.js.map +1 -0
- package/dist/esm/api/extract.d.ts +118 -0
- package/dist/esm/api/extract.js +56 -0
- package/dist/esm/api/extract.js.map +1 -0
- package/dist/esm/api/jobs.d.ts +35 -0
- package/dist/esm/api/jobs.js +39 -0
- package/dist/esm/api/jobs.js.map +1 -0
- package/dist/esm/api/scrape.d.ts +18 -0
- package/dist/esm/api/scrape.js +14 -0
- package/dist/esm/api/scrape.js.map +1 -0
- package/dist/esm/api/screenshot.d.ts +15 -0
- package/dist/esm/api/screenshot.js +14 -0
- package/dist/esm/api/screenshot.js.map +1 -0
- package/dist/esm/api/search.d.ts +29 -0
- package/dist/esm/api/search.js +18 -0
- package/dist/esm/api/search.js.map +1 -0
- package/dist/esm/api/sitemap.d.ts +17 -0
- package/dist/esm/api/sitemap.js +15 -0
- package/dist/esm/api/sitemap.js.map +1 -0
- package/dist/esm/api/webhooks.d.ts +40 -0
- package/dist/esm/api/webhooks.js +35 -0
- package/dist/esm/api/webhooks.js.map +1 -0
- package/dist/esm/constants.d.ts +5 -0
- package/dist/esm/constants.js +6 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/errors.d.ts +32 -0
- package/dist/esm/errors.js +43 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.d.ts +100 -0
- package/dist/esm/index.js +91 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/utils/http-client.d.ts +62 -0
- package/dist/esm/utils/http-client.js +354 -0
- package/dist/esm/utils/http-client.js.map +1 -0
- package/dist/index.d.ts +100 -0
- package/dist/index.js +102 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/utils/http-client.d.ts +62 -0
- package/dist/utils/http-client.js +361 -0
- package/dist/utils/http-client.js.map +1 -0
- package/package.json +93 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Extract } from './api/extract';
|
|
2
|
+
import { Scrape } from './api/scrape';
|
|
3
|
+
import { Classify } from './api/classify';
|
|
4
|
+
import { Screenshot } from './api/screenshot';
|
|
5
|
+
import { Sitemap } from './api/sitemap';
|
|
6
|
+
import { Search } from './api/search';
|
|
7
|
+
import { Webhooks } from './api/webhooks';
|
|
8
|
+
import { Jobs } from './api/jobs';
|
|
9
|
+
import { KnowledgeSDKError, APIError, AuthenticationError, NetworkError, RateLimitError, TimeoutError } from './errors';
|
|
10
|
+
export interface KnowledgeSDKOptions {
|
|
11
|
+
baseUrl?: string;
|
|
12
|
+
maxRetries?: number;
|
|
13
|
+
timeout?: number;
|
|
14
|
+
apiVersion?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare class KnowledgeSDK {
|
|
17
|
+
/**
|
|
18
|
+
* The Extract resource — full pipeline extraction (sync and async)
|
|
19
|
+
*/
|
|
20
|
+
readonly extract: Extract;
|
|
21
|
+
/**
|
|
22
|
+
* The Scrape resource — single-page scraping to Markdown
|
|
23
|
+
*/
|
|
24
|
+
readonly scrape: Scrape;
|
|
25
|
+
/**
|
|
26
|
+
* The Classify resource — business classification from a URL
|
|
27
|
+
*/
|
|
28
|
+
readonly classify: Classify;
|
|
29
|
+
/**
|
|
30
|
+
* The Screenshot resource — full-page screenshots as base64 PNG
|
|
31
|
+
*/
|
|
32
|
+
readonly screenshot: Screenshot;
|
|
33
|
+
/**
|
|
34
|
+
* The Sitemap resource — URL discovery via sitemap crawling
|
|
35
|
+
*/
|
|
36
|
+
readonly sitemap: Sitemap;
|
|
37
|
+
/**
|
|
38
|
+
* The Search resource — semantic search across indexed knowledge items
|
|
39
|
+
*/
|
|
40
|
+
readonly search: Search;
|
|
41
|
+
/**
|
|
42
|
+
* The Webhooks resource — manage webhook endpoints
|
|
43
|
+
*/
|
|
44
|
+
readonly webhooks: Webhooks;
|
|
45
|
+
/**
|
|
46
|
+
* The Jobs resource — retrieve and poll async job results
|
|
47
|
+
*/
|
|
48
|
+
readonly jobs: Jobs;
|
|
49
|
+
private httpClient;
|
|
50
|
+
/**
|
|
51
|
+
* Create a new KnowledgeSDK client instance.
|
|
52
|
+
*
|
|
53
|
+
* @param apiKey Your KnowledgeSDK API key (must start with 'sk_ks_')
|
|
54
|
+
* @param options Optional configuration for the client
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* import { KnowledgeSDK } from '@knowledgesdk/node';
|
|
59
|
+
*
|
|
60
|
+
* const client = new KnowledgeSDK('sk_ks_your_api_key');
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
constructor(apiKey: string, options?: KnowledgeSDKOptions);
|
|
64
|
+
/**
|
|
65
|
+
* Set custom headers to be included with every request
|
|
66
|
+
* @param headers Record of header names and values
|
|
67
|
+
* @returns The KnowledgeSDK instance for chaining
|
|
68
|
+
*/
|
|
69
|
+
setHeaders(headers: Record<string, string>): KnowledgeSDK;
|
|
70
|
+
/**
|
|
71
|
+
* Set a specific custom header
|
|
72
|
+
* @param name Header name
|
|
73
|
+
* @param value Header value
|
|
74
|
+
* @returns The KnowledgeSDK instance for chaining
|
|
75
|
+
*/
|
|
76
|
+
setHeader(name: string, value: string): KnowledgeSDK;
|
|
77
|
+
/**
|
|
78
|
+
* Enable or disable debug mode.
|
|
79
|
+
* When enabled, all requests and responses will be logged to the console.
|
|
80
|
+
* @param enabled Whether debug mode should be enabled
|
|
81
|
+
* @returns The KnowledgeSDK instance for chaining
|
|
82
|
+
*/
|
|
83
|
+
setDebugMode(enabled: boolean): KnowledgeSDK;
|
|
84
|
+
/**
|
|
85
|
+
* Set the API version to use for requests
|
|
86
|
+
* @param version API version string (e.g., 'v1', 'v2')
|
|
87
|
+
* @returns The KnowledgeSDK instance for chaining
|
|
88
|
+
*/
|
|
89
|
+
setApiVersion(version: string): KnowledgeSDK;
|
|
90
|
+
}
|
|
91
|
+
export { KnowledgeSDKError, APIError, AuthenticationError, NetworkError, RateLimitError, TimeoutError, };
|
|
92
|
+
export { DEFAULT_BASE_URL, DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT } from './constants';
|
|
93
|
+
export type { ExtractResult, ExtractOptions, ExtractAsyncOptions, ExtractAsyncResult, ExtractStreamOptions, ExtractStreamEvent, KnowledgeItem, BusinessProfile } from './api/extract';
|
|
94
|
+
export type { ScrapeResult } from './api/scrape';
|
|
95
|
+
export type { BusinessClassification } from './api/classify';
|
|
96
|
+
export type { ScreenshotResult } from './api/screenshot';
|
|
97
|
+
export type { SitemapResult } from './api/sitemap';
|
|
98
|
+
export type { SearchResult, SearchHit, SearchOptions } from './api/search';
|
|
99
|
+
export type { WebhookFull, WebhookCreateOptions } from './api/webhooks';
|
|
100
|
+
export type { JobResult, JobStatus, PollOptions } from './api/jobs';
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Extract } from './api/extract';
|
|
2
|
+
import { Scrape } from './api/scrape';
|
|
3
|
+
import { Classify } from './api/classify';
|
|
4
|
+
import { Screenshot } from './api/screenshot';
|
|
5
|
+
import { Sitemap } from './api/sitemap';
|
|
6
|
+
import { Search } from './api/search';
|
|
7
|
+
import { Webhooks } from './api/webhooks';
|
|
8
|
+
import { Jobs } from './api/jobs';
|
|
9
|
+
import { HttpClient } from './utils/http-client';
|
|
10
|
+
import { KnowledgeSDKError, APIError, AuthenticationError, NetworkError, RateLimitError, TimeoutError, } from './errors';
|
|
11
|
+
import { DEFAULT_BASE_URL, DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT, DEFAULT_API_VERSION } from './constants';
|
|
12
|
+
export class KnowledgeSDK {
|
|
13
|
+
/**
|
|
14
|
+
* Create a new KnowledgeSDK client instance.
|
|
15
|
+
*
|
|
16
|
+
* @param apiKey Your KnowledgeSDK API key (must start with 'sk_ks_')
|
|
17
|
+
* @param options Optional configuration for the client
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { KnowledgeSDK } from '@knowledgesdk/node';
|
|
22
|
+
*
|
|
23
|
+
* const client = new KnowledgeSDK('sk_ks_your_api_key');
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
constructor(apiKey, options = {}) {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
if (!apiKey) {
|
|
29
|
+
throw new AuthenticationError('API key is required', {
|
|
30
|
+
code: 'api_key_required',
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (!apiKey.startsWith('sk_ks_')) {
|
|
34
|
+
throw new AuthenticationError('Invalid API key format. Keys must start with sk_ks_', { code: 'invalid_api_key_format' });
|
|
35
|
+
}
|
|
36
|
+
// Initialize the HTTP client
|
|
37
|
+
this.httpClient = new HttpClient(apiKey, options.baseUrl || DEFAULT_BASE_URL, (_a = options.maxRetries) !== null && _a !== void 0 ? _a : DEFAULT_MAX_RETRIES, (_b = options.timeout) !== null && _b !== void 0 ? _b : DEFAULT_TIMEOUT, options.apiVersion || DEFAULT_API_VERSION);
|
|
38
|
+
// Initialize API resources
|
|
39
|
+
this.extract = new Extract(this.httpClient);
|
|
40
|
+
this.scrape = new Scrape(this.httpClient);
|
|
41
|
+
this.classify = new Classify(this.httpClient);
|
|
42
|
+
this.screenshot = new Screenshot(this.httpClient);
|
|
43
|
+
this.sitemap = new Sitemap(this.httpClient);
|
|
44
|
+
this.search = new Search(this.httpClient);
|
|
45
|
+
this.webhooks = new Webhooks(this.httpClient);
|
|
46
|
+
this.jobs = new Jobs(this.httpClient);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Set custom headers to be included with every request
|
|
50
|
+
* @param headers Record of header names and values
|
|
51
|
+
* @returns The KnowledgeSDK instance for chaining
|
|
52
|
+
*/
|
|
53
|
+
setHeaders(headers) {
|
|
54
|
+
this.httpClient.setHeaders(headers);
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Set a specific custom header
|
|
59
|
+
* @param name Header name
|
|
60
|
+
* @param value Header value
|
|
61
|
+
* @returns The KnowledgeSDK instance for chaining
|
|
62
|
+
*/
|
|
63
|
+
setHeader(name, value) {
|
|
64
|
+
this.httpClient.setHeader(name, value);
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Enable or disable debug mode.
|
|
69
|
+
* When enabled, all requests and responses will be logged to the console.
|
|
70
|
+
* @param enabled Whether debug mode should be enabled
|
|
71
|
+
* @returns The KnowledgeSDK instance for chaining
|
|
72
|
+
*/
|
|
73
|
+
setDebugMode(enabled) {
|
|
74
|
+
this.httpClient.setDebugMode(enabled);
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Set the API version to use for requests
|
|
79
|
+
* @param version API version string (e.g., 'v1', 'v2')
|
|
80
|
+
* @returns The KnowledgeSDK instance for chaining
|
|
81
|
+
*/
|
|
82
|
+
setApiVersion(version) {
|
|
83
|
+
this.httpClient.setApiVersion(version);
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Re-export error classes
|
|
88
|
+
export { KnowledgeSDKError, APIError, AuthenticationError, NetworkError, RateLimitError, TimeoutError, };
|
|
89
|
+
// Re-export constants
|
|
90
|
+
export { DEFAULT_BASE_URL, DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT } from './constants';
|
|
91
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EACL,iBAAiB,EACjB,QAAQ,EACR,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,YAAY,GACb,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAS1G,MAAM,OA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,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC;IAED;;;;OAIG;IACH,UAAU,CAAC,OAA+B;QACxC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACpC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,IAAY,EAAE,KAAa;QACnC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACvC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,YAAY,CAAC,OAAgB;QAC3B,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,aAAa,CAAC,OAAe;QAC3B,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACvC,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,0BAA0B;AAC1B,OAAO,EACL,iBAAiB,EACjB,QAAQ,EACR,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,YAAY,GACb,CAAC;AAEF,sBAAsB;AACtB,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
2
|
+
export interface RequestOptions {
|
|
3
|
+
method?: HttpMethod;
|
|
4
|
+
headers?: Record<string, string>;
|
|
5
|
+
params?: Record<string, any>;
|
|
6
|
+
data?: any;
|
|
7
|
+
maxRetries?: number;
|
|
8
|
+
retryCount?: number;
|
|
9
|
+
retryDelay?: number;
|
|
10
|
+
timeout?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare class HttpClient {
|
|
13
|
+
private apiKey;
|
|
14
|
+
private baseUrl;
|
|
15
|
+
private apiVersion;
|
|
16
|
+
private defaultMaxRetries;
|
|
17
|
+
private defaultTimeout;
|
|
18
|
+
private customHeaders;
|
|
19
|
+
private debugMode;
|
|
20
|
+
constructor(apiKey: string, baseUrl?: string, maxRetries?: number, timeout?: number, apiVersion?: string);
|
|
21
|
+
/**
|
|
22
|
+
* Set custom headers to be included with every request
|
|
23
|
+
* @param headers Record of header names and values
|
|
24
|
+
* @returns The HttpClient instance for chaining
|
|
25
|
+
*/
|
|
26
|
+
setHeaders(headers: Record<string, string>): HttpClient;
|
|
27
|
+
/**
|
|
28
|
+
* Set a specific custom header
|
|
29
|
+
* @param name Header name
|
|
30
|
+
* @param value Header value
|
|
31
|
+
* @returns The HttpClient instance for chaining
|
|
32
|
+
*/
|
|
33
|
+
setHeader(name: string, value: string): HttpClient;
|
|
34
|
+
/**
|
|
35
|
+
* Enable or disable debug mode
|
|
36
|
+
* When enabled, requests and responses will be logged to console
|
|
37
|
+
* @param enabled Whether debug mode should be enabled
|
|
38
|
+
* @returns The HttpClient instance for chaining
|
|
39
|
+
*/
|
|
40
|
+
setDebugMode(enabled: boolean): HttpClient;
|
|
41
|
+
/**
|
|
42
|
+
* Set the API version to use for requests
|
|
43
|
+
* @param version API version string (e.g., 'v1', 'v2', etc.)
|
|
44
|
+
* @returns The HttpClient instance for chaining
|
|
45
|
+
*/
|
|
46
|
+
setApiVersion(version: string): HttpClient;
|
|
47
|
+
private createUrl;
|
|
48
|
+
private getHeaders;
|
|
49
|
+
private calculateBackoff;
|
|
50
|
+
request<T = any>(path: string, options?: RequestOptions): Promise<T>;
|
|
51
|
+
get<T = any>(path: string, options?: Omit<RequestOptions, 'method'>): Promise<T>;
|
|
52
|
+
post<T = any>(path: string, data?: any, options?: Omit<RequestOptions, 'method' | 'data'>): Promise<T>;
|
|
53
|
+
put<T = any>(path: string, data?: any, options?: Omit<RequestOptions, 'method' | 'data'>): Promise<T>;
|
|
54
|
+
patch<T = any>(path: string, data?: any, options?: Omit<RequestOptions, 'method' | 'data'>): Promise<T>;
|
|
55
|
+
delete<T = any>(path: string, options?: Omit<RequestOptions, 'method'>): Promise<T>;
|
|
56
|
+
/**
|
|
57
|
+
* POST to a server-sent events endpoint and yield typed events as an async generator.
|
|
58
|
+
* Requires Node.js 18+ (or a runtime with native fetch support).
|
|
59
|
+
*/
|
|
60
|
+
streamPost<T = any>(path: string, data?: any): AsyncGenerator<T>;
|
|
61
|
+
}
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { APIError, AuthenticationError, NetworkError, RateLimitError, TimeoutError, KnowledgeSDKError, } from '../errors';
|
|
2
|
+
import { VERSION } from '../constants';
|
|
3
|
+
import fetch from 'cross-fetch';
|
|
4
|
+
import { fetchEventSource } from '@microsoft/fetch-event-source';
|
|
5
|
+
export class HttpClient {
|
|
6
|
+
constructor(apiKey, baseUrl = 'https://api.knowledgesdk.com', maxRetries = 3, timeout = 30000, apiVersion = 'v1') {
|
|
7
|
+
this.customHeaders = {};
|
|
8
|
+
this.debugMode = false;
|
|
9
|
+
this.apiKey = apiKey;
|
|
10
|
+
this.baseUrl = baseUrl;
|
|
11
|
+
this.defaultMaxRetries = maxRetries;
|
|
12
|
+
this.defaultTimeout = timeout;
|
|
13
|
+
this.apiVersion = apiVersion;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Set custom headers to be included with every request
|
|
17
|
+
* @param headers Record of header names and values
|
|
18
|
+
* @returns The HttpClient instance for chaining
|
|
19
|
+
*/
|
|
20
|
+
setHeaders(headers) {
|
|
21
|
+
this.customHeaders = { ...this.customHeaders, ...headers };
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Set a specific custom header
|
|
26
|
+
* @param name Header name
|
|
27
|
+
* @param value Header value
|
|
28
|
+
* @returns The HttpClient instance for chaining
|
|
29
|
+
*/
|
|
30
|
+
setHeader(name, value) {
|
|
31
|
+
this.customHeaders[name] = value;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Enable or disable debug mode
|
|
36
|
+
* When enabled, requests and responses will be logged to console
|
|
37
|
+
* @param enabled Whether debug mode should be enabled
|
|
38
|
+
* @returns The HttpClient instance for chaining
|
|
39
|
+
*/
|
|
40
|
+
setDebugMode(enabled) {
|
|
41
|
+
this.debugMode = enabled;
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Set the API version to use for requests
|
|
46
|
+
* @param version API version string (e.g., 'v1', 'v2', etc.)
|
|
47
|
+
* @returns The HttpClient instance for chaining
|
|
48
|
+
*/
|
|
49
|
+
setApiVersion(version) {
|
|
50
|
+
this.apiVersion = version;
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
createUrl(path, params) {
|
|
54
|
+
// Add version prefix to the path if it doesn't already have it
|
|
55
|
+
const versionedPath = path.startsWith('/')
|
|
56
|
+
? `/${this.apiVersion}${path}`
|
|
57
|
+
: `/${this.apiVersion}/${path}`;
|
|
58
|
+
const url = new URL(versionedPath, this.baseUrl);
|
|
59
|
+
if (params) {
|
|
60
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
61
|
+
if (Array.isArray(value)) {
|
|
62
|
+
value.forEach((v) => url.searchParams.append(key, v));
|
|
63
|
+
}
|
|
64
|
+
else if (value !== undefined && value !== null) {
|
|
65
|
+
url.searchParams.append(key, String(value));
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return url.toString();
|
|
70
|
+
}
|
|
71
|
+
getHeaders() {
|
|
72
|
+
return {
|
|
73
|
+
'x-api-key': this.apiKey,
|
|
74
|
+
'Content-Type': 'application/json',
|
|
75
|
+
'User-Agent': `KnowledgeSDK Node SDK v${VERSION}`,
|
|
76
|
+
Accept: 'application/json',
|
|
77
|
+
...this.customHeaders,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
calculateBackoff(retryCount, retryDelay) {
|
|
81
|
+
// Use a more aggressive factor (4 instead of 2)
|
|
82
|
+
const exponentialPart = retryDelay * Math.pow(4, retryCount);
|
|
83
|
+
// Add jitter (between 80-120% of calculated time)
|
|
84
|
+
const withJitter = exponentialPart * (0.8 + 0.4 * Math.random());
|
|
85
|
+
// Cap at 30 seconds maximum backoff
|
|
86
|
+
return Math.min(withJitter, 30000);
|
|
87
|
+
}
|
|
88
|
+
async request(path, options = {}) {
|
|
89
|
+
const { method = 'GET', headers = {}, params, data, maxRetries = this.defaultMaxRetries, retryCount = 0, retryDelay = 100, timeout = this.defaultTimeout, } = options;
|
|
90
|
+
const url = this.createUrl(path, params);
|
|
91
|
+
// Create a timeout promise instead of using AbortController for timeout
|
|
92
|
+
let timeoutId;
|
|
93
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
94
|
+
timeoutId = setTimeout(() => {
|
|
95
|
+
reject(new TimeoutError(`Request timed out after ${timeout}ms`, { code: 'timeout' }));
|
|
96
|
+
}, timeout);
|
|
97
|
+
});
|
|
98
|
+
try {
|
|
99
|
+
const requestHeaders = {
|
|
100
|
+
...this.getHeaders(),
|
|
101
|
+
...headers,
|
|
102
|
+
};
|
|
103
|
+
const requestOptions = {
|
|
104
|
+
method,
|
|
105
|
+
headers: requestHeaders,
|
|
106
|
+
};
|
|
107
|
+
// Add body for non-GET requests
|
|
108
|
+
if (method !== 'GET' && data !== undefined) {
|
|
109
|
+
requestOptions.body = JSON.stringify(data);
|
|
110
|
+
}
|
|
111
|
+
// Log request in debug mode
|
|
112
|
+
if (this.debugMode) {
|
|
113
|
+
console.log(`[KNOWLEDGESDK] Request: ${method} ${url}`);
|
|
114
|
+
console.log('[KNOWLEDGESDK] Headers:', requestHeaders);
|
|
115
|
+
if (data)
|
|
116
|
+
console.log('[KNOWLEDGESDK] Body:', JSON.stringify(data, null, 2));
|
|
117
|
+
}
|
|
118
|
+
// Use Promise.race to implement timeout
|
|
119
|
+
const response = (await Promise.race([
|
|
120
|
+
fetch(url, requestOptions),
|
|
121
|
+
timeoutPromise,
|
|
122
|
+
]));
|
|
123
|
+
if (timeoutId) {
|
|
124
|
+
clearTimeout(timeoutId);
|
|
125
|
+
}
|
|
126
|
+
// Extract request ID from headers
|
|
127
|
+
const requestId = response.headers.get('x-request-id');
|
|
128
|
+
// Try to parse the response as JSON
|
|
129
|
+
let responseData;
|
|
130
|
+
const contentType = response.headers.get('content-type');
|
|
131
|
+
if (contentType && contentType.includes('application/json')) {
|
|
132
|
+
responseData = await response.json();
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
responseData = await response.text();
|
|
136
|
+
}
|
|
137
|
+
// Log response in debug mode
|
|
138
|
+
if (this.debugMode) {
|
|
139
|
+
console.log(`[KNOWLEDGESDK] Response: ${response.status}`);
|
|
140
|
+
console.log('[KNOWLEDGESDK] Response body:', typeof responseData === 'string' ? responseData : JSON.stringify(responseData, null, 2));
|
|
141
|
+
}
|
|
142
|
+
// Handle different status codes
|
|
143
|
+
if (response.status === 429) {
|
|
144
|
+
if (retryCount < maxRetries) {
|
|
145
|
+
const nextDelay = this.calculateBackoff(retryCount, retryDelay);
|
|
146
|
+
if (this.debugMode) {
|
|
147
|
+
console.log(`[KNOWLEDGESDK] Rate limited, retrying in ${nextDelay}ms (attempt ${retryCount + 1}/${maxRetries})`);
|
|
148
|
+
}
|
|
149
|
+
await new Promise((resolve) => setTimeout(resolve, nextDelay));
|
|
150
|
+
return this.request(path, {
|
|
151
|
+
method,
|
|
152
|
+
headers,
|
|
153
|
+
params,
|
|
154
|
+
data,
|
|
155
|
+
maxRetries,
|
|
156
|
+
retryCount: retryCount + 1,
|
|
157
|
+
retryDelay,
|
|
158
|
+
timeout,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
throw new RateLimitError('Rate limit exceeded', {
|
|
162
|
+
statusCode: response.status,
|
|
163
|
+
requestId: requestId || undefined,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
if (response.status === 401) {
|
|
167
|
+
throw new AuthenticationError('Invalid API key', {
|
|
168
|
+
statusCode: response.status,
|
|
169
|
+
code: 'invalid_api_key',
|
|
170
|
+
requestId: requestId || undefined,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
// Handle server errors (5xx)
|
|
174
|
+
if (response.status >= 500) {
|
|
175
|
+
if (retryCount < maxRetries) {
|
|
176
|
+
const nextDelay = this.calculateBackoff(retryCount, retryDelay);
|
|
177
|
+
if (this.debugMode) {
|
|
178
|
+
console.log(`[KNOWLEDGESDK] Server error, retrying in ${nextDelay}ms (attempt ${retryCount + 1}/${maxRetries})`);
|
|
179
|
+
}
|
|
180
|
+
await new Promise((resolve) => setTimeout(resolve, nextDelay));
|
|
181
|
+
return this.request(path, {
|
|
182
|
+
method,
|
|
183
|
+
headers,
|
|
184
|
+
params,
|
|
185
|
+
data,
|
|
186
|
+
maxRetries,
|
|
187
|
+
retryCount: retryCount + 1,
|
|
188
|
+
retryDelay,
|
|
189
|
+
timeout,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
throw new APIError(`Server error: ${response.status}`, {
|
|
193
|
+
statusCode: response.status,
|
|
194
|
+
code: 'server_error',
|
|
195
|
+
requestId: requestId || undefined,
|
|
196
|
+
data: responseData,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
// Handle other errors (4xx)
|
|
200
|
+
if (!response.ok) {
|
|
201
|
+
let errorMessage = `API error: ${response.status}`;
|
|
202
|
+
let errorCode = 'api_error';
|
|
203
|
+
if (responseData && typeof responseData === 'object') {
|
|
204
|
+
// Parse Hapi error format: { error: string, statusCode: number }
|
|
205
|
+
errorMessage = responseData.message || responseData.error || errorMessage;
|
|
206
|
+
errorCode = responseData.code || errorCode;
|
|
207
|
+
}
|
|
208
|
+
throw new APIError(errorMessage, {
|
|
209
|
+
statusCode: response.status,
|
|
210
|
+
code: errorCode,
|
|
211
|
+
requestId: requestId || undefined,
|
|
212
|
+
data: responseData,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
return responseData;
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
if (timeoutId) {
|
|
219
|
+
clearTimeout(timeoutId);
|
|
220
|
+
}
|
|
221
|
+
// Re-throw KnowledgeSDKError instances
|
|
222
|
+
if (error instanceof KnowledgeSDKError) {
|
|
223
|
+
throw error;
|
|
224
|
+
}
|
|
225
|
+
// Handle timeout errors from our Promise.race
|
|
226
|
+
if (error instanceof TimeoutError) {
|
|
227
|
+
throw error;
|
|
228
|
+
}
|
|
229
|
+
// Handle network errors
|
|
230
|
+
if (error.name === 'TypeError' && error.message.includes('fetch')) {
|
|
231
|
+
throw new NetworkError('Network error', {
|
|
232
|
+
code: 'network_error',
|
|
233
|
+
data: error.message,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
// Handle other errors
|
|
237
|
+
throw new KnowledgeSDKError('Unexpected error', {
|
|
238
|
+
code: 'unexpected_error',
|
|
239
|
+
data: error,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
async get(path, options) {
|
|
244
|
+
return this.request(path, {
|
|
245
|
+
method: 'GET',
|
|
246
|
+
...options,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
async post(path, data, options) {
|
|
250
|
+
return this.request(path, {
|
|
251
|
+
method: 'POST',
|
|
252
|
+
data,
|
|
253
|
+
...options,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
async put(path, data, options) {
|
|
257
|
+
return this.request(path, {
|
|
258
|
+
method: 'PUT',
|
|
259
|
+
data,
|
|
260
|
+
...options,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
async patch(path, data, options) {
|
|
264
|
+
return this.request(path, {
|
|
265
|
+
method: 'PATCH',
|
|
266
|
+
data,
|
|
267
|
+
...options,
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
async delete(path, options) {
|
|
271
|
+
return this.request(path, {
|
|
272
|
+
method: 'DELETE',
|
|
273
|
+
...options,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* POST to a server-sent events endpoint and yield typed events as an async generator.
|
|
278
|
+
* Requires Node.js 18+ (or a runtime with native fetch support).
|
|
279
|
+
*/
|
|
280
|
+
async *streamPost(path, data) {
|
|
281
|
+
const url = this.createUrl(path);
|
|
282
|
+
const headers = { ...this.getHeaders(), Accept: 'text/event-stream', 'Content-Type': 'application/json' };
|
|
283
|
+
const queue = [];
|
|
284
|
+
let waitResolve = null;
|
|
285
|
+
let done = false;
|
|
286
|
+
let streamError = null;
|
|
287
|
+
const controller = new AbortController();
|
|
288
|
+
const enqueue = (item) => {
|
|
289
|
+
queue.push(item);
|
|
290
|
+
waitResolve === null || waitResolve === void 0 ? void 0 : waitResolve();
|
|
291
|
+
waitResolve = null;
|
|
292
|
+
};
|
|
293
|
+
const finish = (err) => {
|
|
294
|
+
done = true;
|
|
295
|
+
streamError = err !== null && err !== void 0 ? err : null;
|
|
296
|
+
waitResolve === null || waitResolve === void 0 ? void 0 : waitResolve();
|
|
297
|
+
waitResolve = null;
|
|
298
|
+
};
|
|
299
|
+
fetchEventSource(url, {
|
|
300
|
+
method: 'POST',
|
|
301
|
+
headers,
|
|
302
|
+
body: JSON.stringify(data),
|
|
303
|
+
signal: controller.signal,
|
|
304
|
+
async onopen(response) {
|
|
305
|
+
if (!response.ok) {
|
|
306
|
+
const text = await response.text().catch(() => '');
|
|
307
|
+
let body = {};
|
|
308
|
+
try {
|
|
309
|
+
body = JSON.parse(text);
|
|
310
|
+
}
|
|
311
|
+
catch { }
|
|
312
|
+
throw new APIError(body.message || `Stream failed: ${response.status}`, {
|
|
313
|
+
statusCode: response.status,
|
|
314
|
+
code: 'stream_error',
|
|
315
|
+
data: body,
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
onmessage(ev) {
|
|
320
|
+
if (!ev.data)
|
|
321
|
+
return;
|
|
322
|
+
try {
|
|
323
|
+
const parsed = JSON.parse(ev.data);
|
|
324
|
+
enqueue({ type: ev.event || 'message', ...parsed });
|
|
325
|
+
}
|
|
326
|
+
catch { }
|
|
327
|
+
},
|
|
328
|
+
onclose() { finish(); },
|
|
329
|
+
onerror(err) {
|
|
330
|
+
finish(err instanceof Error ? err : new Error(String(err)));
|
|
331
|
+
throw err; // prevent automatic retry
|
|
332
|
+
},
|
|
333
|
+
}).catch((err) => {
|
|
334
|
+
if (!done)
|
|
335
|
+
finish(err instanceof Error ? err : new Error(String(err)));
|
|
336
|
+
});
|
|
337
|
+
try {
|
|
338
|
+
while (!done || queue.length > 0) {
|
|
339
|
+
if (queue.length > 0) {
|
|
340
|
+
yield queue.shift();
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
await new Promise((r) => { waitResolve = r; });
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
finally {
|
|
348
|
+
controller.abort();
|
|
349
|
+
}
|
|
350
|
+
if (streamError)
|
|
351
|
+
throw streamError;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
//# sourceMappingURL=http-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-client.js","sourceRoot":"","sources":["../../../src/utils/http-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,iBAAiB,GAClB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,MAAM,aAAa,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAejE,MAAM,OAAO,UAAU;IASrB,YACE,MAAc,EACd,UAAkB,8BAA8B,EAChD,aAAqB,CAAC,EACtB,UAAkB,KAAK,EACvB,aAAqB,IAAI;QARnB,kBAAa,GAA2B,EAAE,CAAC;QAC3C,cAAS,GAAY,KAAK,CAAC;QASjC,IAA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