newt-client-js 1.1.0 → 1.2.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/README.md +2 -0
- package/dist/createClient.d.ts +1 -1
- package/dist/createClient.js +16 -1
- package/dist/types.d.ts +2 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -53,6 +53,8 @@ The `createClient` method supports several options you may set to achieve the ex
|
|
|
53
53
|
| `projectUid` | | **Required.** Your project uid. |
|
|
54
54
|
| `token` | | **Required.** Your Newt CDN API token or Newt API token. |
|
|
55
55
|
| `apiType` | `cdn` | You can specify `cdn` or `api`. Please specify `cdn` to send a request to the Newt CDN API, or `api` to send a request to the Newt API. |
|
|
56
|
+
| `retryOnError` | `true` | By default, this client will retry if the response status is 429 too many requests or 500 server error. To turn off this behavior, set this to `false`. |
|
|
57
|
+
| `retryLimit` | `3` | The number of times to retry before failure. Please specify a value less than or equal to `10`. |
|
|
56
58
|
|
|
57
59
|
### Get contents
|
|
58
60
|
|
package/dist/createClient.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CreateClientParams, GetContentsParams, GetContentParams, Contents, GetAppParams, AppMeta } from './types';
|
|
2
|
-
export declare const createClient: ({ projectUid, token, apiType, }: CreateClientParams) => {
|
|
2
|
+
export declare const createClient: ({ projectUid, token, apiType, retryOnError, retryLimit, }: CreateClientParams) => {
|
|
3
3
|
getContents: <T>({ appUid, modelUid, query, }: GetContentsParams) => Promise<Contents<T>>;
|
|
4
4
|
getContent: <T_1>({ appUid, modelUid, contentId, query, }: GetContentParams) => Promise<T_1>;
|
|
5
5
|
getApp: ({ appUid }: GetAppParams) => Promise<AppMeta | null>;
|
package/dist/createClient.js
CHANGED
|
@@ -41,19 +41,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
exports.createClient = void 0;
|
|
43
43
|
var axios_1 = __importDefault(require("axios"));
|
|
44
|
+
var axios_retry_1 = __importDefault(require("axios-retry"));
|
|
44
45
|
var parseQuery_1 = require("./utils/parseQuery");
|
|
45
46
|
var createClient = function (_a) {
|
|
46
|
-
var projectUid = _a.projectUid, token = _a.token, _b = _a.apiType, apiType = _b === void 0 ? 'cdn' : _b;
|
|
47
|
+
var projectUid = _a.projectUid, token = _a.token, _b = _a.apiType, apiType = _b === void 0 ? 'cdn' : _b, _c = _a.retryOnError, retryOnError = _c === void 0 ? true : _c, _d = _a.retryLimit, retryLimit = _d === void 0 ? 3 : _d;
|
|
47
48
|
if (!projectUid)
|
|
48
49
|
throw new Error('projectUid parameter is required.');
|
|
49
50
|
if (!token)
|
|
50
51
|
throw new Error('token parameter is required.');
|
|
51
52
|
if (!['cdn', 'api'].includes(apiType))
|
|
52
53
|
throw new Error("apiType parameter should be set to \"cdn\" or \"api\". apiType: " + apiType);
|
|
54
|
+
if (retryLimit > 10)
|
|
55
|
+
throw new Error('retryLimit should be a value less than or equal to 10.');
|
|
53
56
|
var axiosInstance = axios_1.default.create({
|
|
54
57
|
baseURL: "https://" + projectUid + "." + apiType + ".newt.so/v1",
|
|
55
58
|
headers: { Authorization: "Bearer " + token },
|
|
56
59
|
});
|
|
60
|
+
if (retryOnError) {
|
|
61
|
+
(0, axios_retry_1.default)(axiosInstance, {
|
|
62
|
+
retries: retryLimit,
|
|
63
|
+
retryCondition: function (error) {
|
|
64
|
+
var _a, _b;
|
|
65
|
+
return ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 429 || ((_b = error.response) === null || _b === void 0 ? void 0 : _b.status) === 500;
|
|
66
|
+
},
|
|
67
|
+
retryDelay: function (retryCount) {
|
|
68
|
+
return retryCount * 1000;
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
57
72
|
var getContents = function (_a) {
|
|
58
73
|
var appUid = _a.appUid, modelUid = _a.modelUid, query = _a.query;
|
|
59
74
|
return __awaiter(void 0, void 0, void 0, function () {
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "newt-client-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "JavaScript SDK for Newt's API",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
]
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"axios": "^0.
|
|
42
|
+
"axios": "^0.25.0",
|
|
43
|
+
"axios-retry": "^3.2.4",
|
|
43
44
|
"qs": "^6.10.1"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|