ensembledata 0.0.3 → 0.1.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.
- package/LICENCE +9 -0
- package/README.md +40 -8
- package/package.json +6 -3
- package/src/client.js +310 -207
- package/src/errors.js +19 -0
- package/src/index.js +2 -0
- package/src/requester.js +52 -7
- package/src/version.js +1 -0
- package/types/client.d.ts +261 -106
- package/types/client.d.ts.map +1 -1
- package/types/errors.d.ts +20 -0
- package/types/errors.d.ts.map +1 -0
- package/types/index.d.ts +2 -0
- package/types/requester.d.ts +29 -4
- package/types/requester.d.ts.map +1 -1
- package/types/version.d.ts +2 -0
- package/types/version.d.ts.map +1 -0
package/LICENCE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT Licence
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 EnsembleData
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
# EnsembleData
|
|
1
|
+
# EnsembleData Node.js API
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.org/package/ensembledata)
|
|
2
4
|
|
|
3
5
|
## Documentation
|
|
4
6
|
|
|
@@ -22,7 +24,7 @@ pnpm add ensembledata
|
|
|
22
24
|
|
|
23
25
|
### Requirements
|
|
24
26
|
|
|
25
|
-
- The package requires Node 18 or
|
|
27
|
+
- The package requires Node 18 or higher.
|
|
26
28
|
|
|
27
29
|
## Usage
|
|
28
30
|
|
|
@@ -61,7 +63,7 @@ const result = await client.request("/instagram/example", {
|
|
|
61
63
|
});
|
|
62
64
|
```
|
|
63
65
|
|
|
64
|
-
If you find that one the parameters to an existing endpoint is missing, you can still send this parameter via the `extraParams`
|
|
66
|
+
If you find that one the parameters to an existing endpoint is missing, you can still send this parameter via the `extraParams` which is available on all endpoint methods as shown below:
|
|
65
67
|
|
|
66
68
|
```javascript
|
|
67
69
|
import { EDClient } from "ensembledata";
|
|
@@ -69,7 +71,11 @@ import { EDClient } from "ensembledata";
|
|
|
69
71
|
const client = EDClient({ token: "API-TOKEN" });
|
|
70
72
|
const result = await client.instagram.userInfo(
|
|
71
73
|
{ username: "..." },
|
|
72
|
-
{
|
|
74
|
+
{
|
|
75
|
+
extraParams: {
|
|
76
|
+
baz: "...",
|
|
77
|
+
},
|
|
78
|
+
},
|
|
73
79
|
);
|
|
74
80
|
```
|
|
75
81
|
|
|
@@ -81,7 +87,7 @@ const result = await client.instagram.userInfo(
|
|
|
81
87
|
In the [API docs](https://ensembledata.com/apis/docs), each endpoint lists a handful of possible errors the API may respond with. You can handle these errors by catching the `EDError` exception.
|
|
82
88
|
|
|
83
89
|
```javascript
|
|
84
|
-
import { EDClient } from "ensembledata";
|
|
90
|
+
import { EDClient, errors } from "ensembledata";
|
|
85
91
|
|
|
86
92
|
const client = EDClient({ token: "API-TOKEN" });
|
|
87
93
|
try {
|
|
@@ -89,14 +95,14 @@ try {
|
|
|
89
95
|
username: "daviddobrik",
|
|
90
96
|
});
|
|
91
97
|
} catch (error) {
|
|
92
|
-
switch (error.
|
|
98
|
+
switch (error.statusCode) {
|
|
93
99
|
// Rate limit exceeded...
|
|
94
|
-
case
|
|
100
|
+
case errors.STATUS_429_RATE_LIMIT_EXCEEDED:
|
|
95
101
|
console.log(error.detail);
|
|
96
102
|
break;
|
|
97
103
|
|
|
98
104
|
// Subscription expired...
|
|
99
|
-
case
|
|
105
|
+
case errors.STATUS_493_SUBSCRIPTION_EXPIRED:
|
|
100
106
|
console.log(error.detail);
|
|
101
107
|
break;
|
|
102
108
|
|
|
@@ -129,6 +135,32 @@ client.tiktok
|
|
|
129
135
|
});
|
|
130
136
|
```
|
|
131
137
|
|
|
138
|
+
### Network Retries
|
|
139
|
+
|
|
140
|
+
By default the `EDClient` will perform 3 retries when it encounters network issues. If you would like to customise this behaviour, you can pass in the `maxNetworkRetries` param as show below:
|
|
141
|
+
|
|
142
|
+
Note: if the request times out, it will not be retried.
|
|
143
|
+
|
|
144
|
+
```javascript
|
|
145
|
+
import { EDClient } from "ensembledata";
|
|
146
|
+
|
|
147
|
+
const client = EDClient({ token: "API-TOKEN", maxNetworkRetries: 5 });
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Configure Timeout
|
|
151
|
+
|
|
152
|
+
If you would like control over the timeout, you can configure this either for all request by setting `timeout` (in seconds) when creating the `EDClient`, or you can specify the `timeout` per request, on any of the individual methods as shown below:
|
|
153
|
+
|
|
154
|
+
```javascript
|
|
155
|
+
import { EDClient } from "ensembledata";
|
|
156
|
+
|
|
157
|
+
const client = EDClient({ token: "API-TOKEN", timeout: 120 });
|
|
158
|
+
const result = await client.instagram.userInfo(
|
|
159
|
+
{ username: "..." },
|
|
160
|
+
{ timeout: 10 },
|
|
161
|
+
);
|
|
162
|
+
```
|
|
163
|
+
|
|
132
164
|
### Types
|
|
133
165
|
|
|
134
166
|
This package provides TypeScript types for all the endpoints and their parameters. You can use these types to get autocompletion and type checking in your IDE.
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ensembledata",
|
|
3
|
+
"version": "0.1.1",
|
|
3
4
|
"description": "Node.js bindings for the EnsembleData API",
|
|
4
5
|
"author": "EnsembleData <hello@ensembledata.com>",
|
|
5
6
|
"contributors": [
|
|
@@ -11,8 +12,6 @@
|
|
|
11
12
|
"url": "git://github.com/ensembledata/ensembledata-node.git"
|
|
12
13
|
},
|
|
13
14
|
"bugs": "https://github.com/ensembledata/ensembledata-node/issues",
|
|
14
|
-
"scripts": {},
|
|
15
|
-
"version": "0.0.3",
|
|
16
15
|
"type": "module",
|
|
17
16
|
"license": "MIT",
|
|
18
17
|
"main": "src/index.js",
|
|
@@ -20,9 +19,13 @@
|
|
|
20
19
|
"devDependencies": {
|
|
21
20
|
"@eslint/js": "^9.8.0",
|
|
22
21
|
"eslint-config-prettier": "^9.1.0",
|
|
22
|
+
"globals": "^15.9.0",
|
|
23
23
|
"nunjucks": "^3.2.4",
|
|
24
24
|
"prettier": "3.3.3",
|
|
25
25
|
"prettier-plugin-jsdoc": "^1.3.0",
|
|
26
26
|
"typescript": "^5.5.4"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"version": "./scripts/sync_version.sh $npm_package_version"
|
|
27
30
|
}
|
|
28
|
-
}
|
|
31
|
+
}
|