@crawlora-org/sdk 1.2.0-sdk.13 → 1.2.0-sdk.14
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/CHANGELOG.md +5 -0
- package/README.md +106 -55
- package/package.json +1 -1
- package/src/client.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v1.2.0-sdk.14
|
|
4
|
+
|
|
5
|
+
- Aligned the promoted SDK beta tag with the Python and Go SDKs.
|
|
6
|
+
- Added explicit coverage for request-level header overrides.
|
|
7
|
+
|
|
3
8
|
## v1.2.0-sdk.13
|
|
4
9
|
|
|
5
10
|
- Updated the published npmjs package homepage to `https://crawlora.net`.
|
package/README.md
CHANGED
|
@@ -1,102 +1,154 @@
|
|
|
1
1
|
# Crawlora JavaScript SDK
|
|
2
2
|
|
|
3
|
-
JavaScript and TypeScript
|
|
4
|
-
|
|
3
|
+
Official JavaScript and TypeScript client for the public Crawlora API. Use it
|
|
4
|
+
to call Crawlora scraping, search, marketplace, media, maps, finance, and usage
|
|
5
|
+
endpoints with a small `fetch`-based client and generated TypeScript types.
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
- Runtime: Node.js 18+ or any modern runtime with `fetch`
|
|
8
|
+
- Auth: `x-api-key`
|
|
9
|
+
- Default API base URL: `https://api.crawlora.net/api/v1`
|
|
10
|
+
- Reference: [operations](docs/operations.md) and [recipes](docs/recipes.md)
|
|
7
11
|
|
|
8
|
-
##
|
|
12
|
+
## Install
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
then open the dashboard and create an API key. Set it as `CRAWLORA_API_KEY` in
|
|
12
|
-
your environment before running the examples or using the SDK.
|
|
14
|
+
Install the latest published npm package:
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
```sh
|
|
17
|
+
npm install @crawlora-org/sdk
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
For reproducible builds, pin a published package version:
|
|
15
21
|
|
|
16
22
|
```sh
|
|
17
|
-
npm install @crawlora-org/sdk@
|
|
23
|
+
npm install @crawlora-org/sdk@VERSION
|
|
18
24
|
```
|
|
19
25
|
|
|
20
|
-
|
|
26
|
+
## API Key
|
|
27
|
+
|
|
28
|
+
Create or sign in to your Crawlora account at [crawlora.net](https://crawlora.net),
|
|
29
|
+
then create an API key in the dashboard.
|
|
21
30
|
|
|
22
31
|
```sh
|
|
23
|
-
|
|
32
|
+
read -r CRAWLORA_API_KEY
|
|
33
|
+
export CRAWLORA_API_KEY
|
|
24
34
|
```
|
|
25
35
|
|
|
26
|
-
##
|
|
36
|
+
## First Request
|
|
27
37
|
|
|
28
38
|
```js
|
|
29
39
|
import { CrawloraClient } from "@crawlora-org/sdk";
|
|
30
40
|
|
|
31
|
-
const crawlora = new CrawloraClient({
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
const crawlora = new CrawloraClient({
|
|
42
|
+
apiKey: process.env.CRAWLORA_API_KEY
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const response = await crawlora.bing.search({
|
|
46
|
+
q: "coffee shops",
|
|
47
|
+
count: 10
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
console.log(response.data?.results?.[0]);
|
|
34
51
|
```
|
|
35
52
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
53
|
+
Endpoint groups are generated from the public API contract, so common calls are
|
|
54
|
+
available as methods such as `crawlora.bing.search(...)`,
|
|
55
|
+
`crawlora.youtube.transcript(...)`, and `crawlora.google.mapSearch(...)`.
|
|
56
|
+
|
|
57
|
+
## Typed Dynamic Calls
|
|
58
|
+
|
|
59
|
+
You can also call by operation id. Literal operation ids infer parameter and
|
|
60
|
+
response types in TypeScript:
|
|
39
61
|
|
|
40
62
|
```ts
|
|
41
|
-
const
|
|
42
|
-
|
|
63
|
+
const response = await crawlora.request("bing-search", {
|
|
64
|
+
q: "coffee shops",
|
|
65
|
+
count: 10
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
response.data?.results?.[0]?.title;
|
|
43
69
|
```
|
|
44
70
|
|
|
71
|
+
Generated declarations include operation ids, endpoint groups, request
|
|
72
|
+
parameters, enum values, response aliases, and request options.
|
|
73
|
+
|
|
45
74
|
## Configuration
|
|
46
75
|
|
|
47
76
|
```js
|
|
48
77
|
const crawlora = new CrawloraClient({
|
|
49
78
|
apiKey: process.env.CRAWLORA_API_KEY,
|
|
50
79
|
baseUrl: "https://api.crawlora.net/api/v1",
|
|
80
|
+
timeout: 30_000,
|
|
51
81
|
retries: 2,
|
|
52
82
|
retryDelay: 250,
|
|
53
|
-
headers: {
|
|
83
|
+
headers: {
|
|
84
|
+
"x-client": "my-app"
|
|
85
|
+
}
|
|
54
86
|
});
|
|
55
87
|
```
|
|
56
88
|
|
|
57
|
-
Per-request options
|
|
89
|
+
Per-request options can override headers, timeout, abort signal, and response
|
|
90
|
+
mode:
|
|
58
91
|
|
|
59
92
|
```js
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
93
|
+
const controller = new AbortController();
|
|
94
|
+
|
|
95
|
+
const response = await crawlora.bing.search(
|
|
96
|
+
{ q: "coffee shops" },
|
|
97
|
+
{
|
|
98
|
+
timeout: 10_000,
|
|
99
|
+
signal: controller.signal,
|
|
100
|
+
headers: { "x-request-id": "search-001" }
|
|
101
|
+
}
|
|
63
102
|
);
|
|
64
103
|
```
|
|
65
104
|
|
|
66
|
-
|
|
67
|
-
parsed `body`, and the original `response` when available.
|
|
105
|
+
## Text Responses
|
|
68
106
|
|
|
69
|
-
|
|
107
|
+
Most endpoints return JSON. Endpoints that support alternate text output, such
|
|
108
|
+
as YouTube transcripts, can opt into text mode:
|
|
70
109
|
|
|
71
|
-
|
|
72
|
-
|
|
110
|
+
```js
|
|
111
|
+
const transcript = await crawlora.youtube.transcript(
|
|
112
|
+
{ id: "VIDEO_ID", format: "text" },
|
|
113
|
+
{ responseType: "text" }
|
|
114
|
+
);
|
|
73
115
|
|
|
74
|
-
|
|
116
|
+
console.log(transcript);
|
|
117
|
+
```
|
|
75
118
|
|
|
76
|
-
|
|
119
|
+
## Errors
|
|
77
120
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
121
|
+
Failed API calls throw `CrawloraError`:
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
import { CrawloraClient, CrawloraError } from "@crawlora-org/sdk";
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
await crawlora.bing.search({ q: "coffee shops" });
|
|
128
|
+
} catch (error) {
|
|
129
|
+
if (error instanceof CrawloraError) {
|
|
130
|
+
console.error(error.status, error.code, error.body);
|
|
131
|
+
}
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
81
134
|
```
|
|
82
135
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
136
|
+
The error includes `status`, optional API `code`, parsed `body`, the original
|
|
137
|
+
`response` when available, and a parser or transport `cause` when relevant.
|
|
138
|
+
|
|
139
|
+
## Examples
|
|
86
140
|
|
|
87
|
-
|
|
141
|
+
Runnable examples live under `examples/` and skip cleanly when required
|
|
142
|
+
environment variables are missing:
|
|
88
143
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
an explicit version in production applications and upgrade intentionally.
|
|
144
|
+
```sh
|
|
145
|
+
npm run example:bing-search
|
|
146
|
+
npm run example:youtube-transcript
|
|
147
|
+
```
|
|
94
148
|
|
|
95
|
-
|
|
96
|
-
`@crawlora-org` scope to `https://npm.pkg.github.com` and a GitHub token that
|
|
97
|
-
can read packages.
|
|
149
|
+
Set `CRAWLORA_BASE_URL` to point examples at a staging or local API.
|
|
98
150
|
|
|
99
|
-
## Package
|
|
151
|
+
## Package Notes
|
|
100
152
|
|
|
101
153
|
The npm package name is `@crawlora-org/sdk`:
|
|
102
154
|
|
|
@@ -104,11 +156,10 @@ The npm package name is `@crawlora-org/sdk`:
|
|
|
104
156
|
import { CrawloraClient } from "@crawlora-org/sdk";
|
|
105
157
|
```
|
|
106
158
|
|
|
107
|
-
The package names `crawlora` and `@crawlora/sdk` are not used by this
|
|
108
|
-
because they already exist on npm and point to
|
|
109
|
-
|
|
110
|
-
## Optional Live Smoke Test
|
|
159
|
+
The package names `crawlora` and `@crawlora/sdk` are not used by this
|
|
160
|
+
repository because they already exist on npm and point to different package
|
|
161
|
+
sources.
|
|
111
162
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
163
|
+
This SDK is published to npmjs and may also be mirrored to GitHub Packages. Pin
|
|
164
|
+
an explicit published version for production applications and upgrade
|
|
165
|
+
intentionally.
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { operations, groups } from "./operations.js";
|
|
2
2
|
|
|
3
3
|
const DEFAULT_BASE_URL = "https://api.crawlora.net/api/v1";
|
|
4
|
-
export const VERSION = "1.2.0-sdk.
|
|
4
|
+
export const VERSION = "1.2.0-sdk.14";
|
|
5
5
|
const DEFAULT_USER_AGENT = `crawlora-js-sdk/${VERSION}`;
|
|
6
6
|
|
|
7
7
|
export class CrawloraError extends Error {
|