@search1api/client 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 +22 -0
- package/README.md +80 -0
- package/dist/client.d.ts +31 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/errors.d.ts +41 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/generated.d.ts +1269 -0
- package/dist/generated.d.ts.map +1 -0
- package/dist/index.cjs +448 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +425 -0
- package/dist/index.js.map +7 -0
- package/dist/types.d.ts +199 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Search1API
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Search1API TypeScript SDK
|
|
2
|
+
|
|
3
|
+
Official TypeScript client for Search1API. It supports Node.js 18+ and runtimes
|
|
4
|
+
with a standards-compatible `fetch` implementation.
|
|
5
|
+
|
|
6
|
+
API documentation: [search1api.com/docs](https://www.search1api.com/docs)
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @search1api/client
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Search
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { Search1API } from '@search1api/client';
|
|
18
|
+
|
|
19
|
+
const client = new Search1API({
|
|
20
|
+
apiKey: process.env.SEARCH1API_API_KEY,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const response = await client.search('latest AI agent frameworks', {
|
|
24
|
+
maxResults: 10,
|
|
25
|
+
crawlResults: 3,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
for (const result of response.results) {
|
|
29
|
+
console.log(result.title, result.link);
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The constructor reads `SEARCH1API_API_KEY` when `apiKey` is omitted.
|
|
34
|
+
|
|
35
|
+
CommonJS projects can load the same client with `require`:
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
const { Search1API } = require('@search1api/client');
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Deepcrawl
|
|
42
|
+
|
|
43
|
+
`deepcrawl` starts a task and waits for it to finish:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
const result = await client.deepcrawl('https://example.com', { type: 'all' });
|
|
47
|
+
console.log(result.zipUrl);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Use `startDeepcrawl`, `getDeepcrawlStatus`, and `waitForDeepcrawl` when the
|
|
51
|
+
application needs to control task persistence or polling itself.
|
|
52
|
+
|
|
53
|
+
## Other APIs
|
|
54
|
+
|
|
55
|
+
The client also provides `news`, `crawl`, `sitemap`, `trending`, `extract`,
|
|
56
|
+
`usage`, and their batch or asynchronous variants where the HTTP API supports
|
|
57
|
+
them.
|
|
58
|
+
|
|
59
|
+
Requests time out after 30 seconds and retry `429` and transient `5xx`
|
|
60
|
+
responses twice by default. Authentication, payment, and validation errors are
|
|
61
|
+
never retried. Deepcrawl task creation is not retried automatically because it
|
|
62
|
+
is not idempotent. Configure this with `timeoutMs` and `maxRetries`.
|
|
63
|
+
|
|
64
|
+
## Development
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
npm install
|
|
68
|
+
npm run generate
|
|
69
|
+
npm run typecheck
|
|
70
|
+
npm test
|
|
71
|
+
npm run build
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The generated wire-level types come from the checked-in public OpenAPI
|
|
75
|
+
snapshot. Update the snapshot before regenerating types when the API contract
|
|
76
|
+
changes.
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
MIT
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { BatchResponse, CrawlOptions, CrawlRequest, CrawlResponse, DeepcrawlAcceptedResponse, DeepcrawlOptions, DeepcrawlStatusResponse, ExtractOptions, ExtractResponse, HealthResponse, JsonValue, NewsOptions, NewsRequest, NewsResponse, RequestOptions, Search1APIOptions, SearchOptions, SearchRequest, SearchResponse, SitemapOptions, SitemapResponse, TimeRange, TrendingOptions, TrendingResponse, UsageResponse, WaitForDeepcrawlOptions } from './types.js';
|
|
2
|
+
export declare class Search1API {
|
|
3
|
+
readonly apiKey: string;
|
|
4
|
+
readonly baseUrl: string;
|
|
5
|
+
readonly maxRetries: number;
|
|
6
|
+
readonly timeoutMs: number;
|
|
7
|
+
private readonly defaultHeaders;
|
|
8
|
+
private readonly fetchClient;
|
|
9
|
+
private readonly retryDelayMs;
|
|
10
|
+
constructor(options?: Search1APIOptions | string);
|
|
11
|
+
search(query: string, options?: SearchOptions, requestOptions?: RequestOptions): Promise<SearchResponse>;
|
|
12
|
+
searchBatch(requests: SearchRequest[], requestOptions?: RequestOptions): Promise<BatchResponse<SearchResponse>>;
|
|
13
|
+
news(query: string, options?: NewsOptions, requestOptions?: RequestOptions): Promise<NewsResponse>;
|
|
14
|
+
newsBatch(requests: NewsRequest[], requestOptions?: RequestOptions): Promise<BatchResponse<NewsResponse>>;
|
|
15
|
+
crawl(url: string, options?: CrawlOptions, requestOptions?: RequestOptions): Promise<CrawlResponse>;
|
|
16
|
+
crawlBatch(requests: CrawlRequest[], requestOptions?: RequestOptions): Promise<CrawlResponse[]>;
|
|
17
|
+
sitemap(url: string, options?: SitemapOptions, requestOptions?: RequestOptions): Promise<SitemapResponse>;
|
|
18
|
+
trending(searchService: string, options?: TrendingOptions, requestOptions?: RequestOptions): Promise<TrendingResponse>;
|
|
19
|
+
extract<T = JsonValue>(url: string, options?: ExtractOptions, requestOptions?: RequestOptions): Promise<ExtractResponse<T>>;
|
|
20
|
+
startDeepcrawl(url: string, options?: DeepcrawlOptions, requestOptions?: RequestOptions): Promise<DeepcrawlAcceptedResponse>;
|
|
21
|
+
getDeepcrawlStatus(taskId: string, requestOptions?: RequestOptions): Promise<DeepcrawlStatusResponse>;
|
|
22
|
+
waitForDeepcrawl(taskId: string, options?: WaitForDeepcrawlOptions): Promise<DeepcrawlStatusResponse>;
|
|
23
|
+
deepcrawl(url: string, options?: DeepcrawlOptions, waitOptions?: WaitForDeepcrawlOptions, requestOptions?: RequestOptions): Promise<DeepcrawlStatusResponse>;
|
|
24
|
+
usage(period?: TimeRange, requestOptions?: RequestOptions): Promise<UsageResponse>;
|
|
25
|
+
health(requestOptions?: RequestOptions): Promise<HealthResponse>;
|
|
26
|
+
private requestJson;
|
|
27
|
+
private request;
|
|
28
|
+
private fetchOnce;
|
|
29
|
+
private retryDelay;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAEV,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,yBAAyB,EACzB,gBAAgB,EAChB,uBAAuB,EACvB,cAAc,EACd,eAAe,EACf,cAAc,EACd,SAAS,EACT,WAAW,EACX,WAAW,EACX,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,cAAc,EACd,cAAc,EACd,eAAe,EACf,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAsHpB,qBAAa,UAAU;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAyB;IACxD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAe;IAC3C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;gBAE1B,OAAO,GAAE,iBAAiB,GAAG,MAAW;IAgC9C,MAAM,CACV,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,aAAkB,EAC3B,cAAc,GAAE,cAAmB,GAClC,OAAO,CAAC,cAAc,CAAC;IAQpB,WAAW,CACf,QAAQ,EAAE,aAAa,EAAE,EACzB,cAAc,GAAE,cAAmB,GAClC,OAAO,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;IAQnC,IAAI,CACR,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,WAAgB,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AO,CAAC,uBAAuB,CAAC;IAK7B,KAAK,CACT,MAAM,CAAC,EAAE,SAAS,EAClB,cAAc,GAAE,cAAmB,GAClC,OAAO,CAAC,aAAa,CAAC;IAOnB,MAAM,CAAC,cAAc,GAAE,cAAmB,GAAG,OAAO,CAAC,cAAc,CAAC;YAI5D,WAAW;YAgBX,OAAO;YA+CP,SAAS;IAoDvB,OAAO,CAAC,UAAU;CAInB"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ApiErrorBody, DeepcrawlStatusResponse } from './types.js';
|
|
2
|
+
export declare class Search1APIError extends Error {
|
|
3
|
+
constructor(message: string, options?: ErrorOptions);
|
|
4
|
+
}
|
|
5
|
+
export declare class Search1APIConfigurationError extends Search1APIError {
|
|
6
|
+
}
|
|
7
|
+
export declare class APIConnectionError extends Search1APIError {
|
|
8
|
+
}
|
|
9
|
+
export declare class APITimeoutError extends APIConnectionError {
|
|
10
|
+
}
|
|
11
|
+
export declare class APIStatusError extends Search1APIError {
|
|
12
|
+
readonly body?: ApiErrorBody;
|
|
13
|
+
readonly headers: Headers;
|
|
14
|
+
readonly requestId?: string;
|
|
15
|
+
readonly status: number;
|
|
16
|
+
constructor(message: string, status: number, headers: Headers, body?: ApiErrorBody);
|
|
17
|
+
}
|
|
18
|
+
export declare class BadRequestError extends APIStatusError {
|
|
19
|
+
}
|
|
20
|
+
export declare class AuthenticationError extends APIStatusError {
|
|
21
|
+
}
|
|
22
|
+
export declare class PaymentRequiredError extends APIStatusError {
|
|
23
|
+
}
|
|
24
|
+
export declare class NotFoundError extends APIStatusError {
|
|
25
|
+
}
|
|
26
|
+
export declare class UnprocessableEntityError extends APIStatusError {
|
|
27
|
+
}
|
|
28
|
+
export declare class RateLimitError extends APIStatusError {
|
|
29
|
+
}
|
|
30
|
+
export declare class InternalServerError extends APIStatusError {
|
|
31
|
+
}
|
|
32
|
+
export declare class DeepcrawlFailedError extends Search1APIError {
|
|
33
|
+
readonly response: DeepcrawlStatusResponse;
|
|
34
|
+
constructor(response: DeepcrawlStatusResponse);
|
|
35
|
+
}
|
|
36
|
+
export declare class DeepcrawlTimeoutError extends Search1APIError {
|
|
37
|
+
readonly taskId: string;
|
|
38
|
+
constructor(taskId: string, timeoutMs: number);
|
|
39
|
+
}
|
|
40
|
+
export declare function apiStatusError(status: number, headers: Headers, body?: ApiErrorBody): APIStatusError;
|
|
41
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAExE,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIpD;AAED,qBAAa,4BAA6B,SAAQ,eAAe;CAAG;AAEpE,qBAAa,kBAAmB,SAAQ,eAAe;CAAG;AAE1D,qBAAa,eAAgB,SAAQ,kBAAkB;CAAG;AAE1D,qBAAa,cAAe,SAAQ,eAAe;IACjD,QAAQ,CAAC,IAAI,CAAC,EAAE,YAAY,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAGtB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,EAChB,IAAI,CAAC,EAAE,YAAY;CAQtB;AAED,qBAAa,eAAgB,SAAQ,cAAc;CAAG;AACtD,qBAAa,mBAAoB,SAAQ,cAAc;CAAG;AAC1D,qBAAa,oBAAqB,SAAQ,cAAc;CAAG;AAC3D,qBAAa,aAAc,SAAQ,cAAc;CAAG;AACpD,qBAAa,wBAAyB,SAAQ,cAAc;CAAG;AAC/D,qBAAa,c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