@rendomnet/apiservice 1.3.3 → 1.3.4
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/dist/HttpClient.js +4 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -1
- package/dist/types.d.ts +1 -0
- package/package.json +12 -10
package/dist/HttpClient.js
CHANGED
|
@@ -15,7 +15,7 @@ class HttpClient {
|
|
|
15
15
|
* Make an HTTP request
|
|
16
16
|
*/
|
|
17
17
|
async makeRequest(apiParams, authToken) {
|
|
18
|
-
const { accountId, method, route, base, body, data, headers, queryParams, contentType = 'application/json', accessToken: forcedAccessToken, useAuth = true, files, } = apiParams;
|
|
18
|
+
const { accountId, method, route, base, body, data, headers, queryParams, contentType = 'application/json', accessToken: forcedAccessToken, useAuth = true, files, abortSignal, } = apiParams;
|
|
19
19
|
// Build URL and request body
|
|
20
20
|
const url = this.buildUrl(base, route, queryParams);
|
|
21
21
|
const requestBody = body || data;
|
|
@@ -32,6 +32,7 @@ class HttpClient {
|
|
|
32
32
|
forcedAccessToken,
|
|
33
33
|
useAuth,
|
|
34
34
|
headers,
|
|
35
|
+
abortSignal,
|
|
35
36
|
});
|
|
36
37
|
// Make the request
|
|
37
38
|
try {
|
|
@@ -71,10 +72,11 @@ class HttpClient {
|
|
|
71
72
|
/**
|
|
72
73
|
* Build fetch options for request
|
|
73
74
|
*/
|
|
74
|
-
buildFetchOptions({ method, body, formData, contentType, authToken, forcedAccessToken, useAuth, headers, }) {
|
|
75
|
+
buildFetchOptions({ method, body, formData, contentType, authToken, forcedAccessToken, useAuth, headers, abortSignal, }) {
|
|
75
76
|
const allowedMethods = ['POST', 'PUT', 'PATCH'];
|
|
76
77
|
return {
|
|
77
78
|
method,
|
|
79
|
+
signal: abortSignal,
|
|
78
80
|
headers: {
|
|
79
81
|
...(useAuth && {
|
|
80
82
|
Authorization: `Bearer ${forcedAccessToken || authToken.access_token}`
|
package/dist/index.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ declare class ApiService {
|
|
|
42
42
|
*/
|
|
43
43
|
call(apiCallParams: Omit<ApiCallParams, 'accountId'> & {
|
|
44
44
|
accountId?: string;
|
|
45
|
+
abortSignal?: AbortSignal;
|
|
45
46
|
}): Promise<any>;
|
|
46
47
|
/**
|
|
47
48
|
* Legacy method for backward compatibility
|
|
@@ -49,6 +50,7 @@ declare class ApiService {
|
|
|
49
50
|
*/
|
|
50
51
|
makeApiCall(apiCallParams: Omit<ApiCallParams, 'accountId'> & {
|
|
51
52
|
accountId?: string;
|
|
53
|
+
abortSignal?: AbortSignal;
|
|
52
54
|
}): Promise<any>;
|
|
53
55
|
/**
|
|
54
56
|
* Make a request with retry capability
|
package/dist/index.js
CHANGED
|
@@ -135,7 +135,7 @@ class ApiService {
|
|
|
135
135
|
*/
|
|
136
136
|
async makeRequestWithRetry(apiCallParams) {
|
|
137
137
|
var _a;
|
|
138
|
-
const { accountId } = apiCallParams;
|
|
138
|
+
const { accountId, abortSignal } = apiCallParams;
|
|
139
139
|
let attempts = 0;
|
|
140
140
|
const statusRetries = {};
|
|
141
141
|
let currentParams = { ...apiCallParams };
|
|
@@ -150,6 +150,9 @@ class ApiService {
|
|
|
150
150
|
}
|
|
151
151
|
// Main retry loop
|
|
152
152
|
while (attempts < this.maxAttempts) {
|
|
153
|
+
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
|
|
154
|
+
throw new Error('Request aborted');
|
|
155
|
+
}
|
|
153
156
|
attempts++;
|
|
154
157
|
try {
|
|
155
158
|
// Get authentication headers if needed
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rendomnet/apiservice",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4",
|
|
4
4
|
"description": "A robust TypeScript API service framework for making authenticated API calls",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"clean": "rimraf dist",
|
|
13
|
+
"prebuild": "npm run clean",
|
|
14
|
+
"prepublishOnly": "npm run build",
|
|
15
|
+
"test": "jest",
|
|
16
|
+
"test:watch": "jest --watch",
|
|
17
|
+
"test:coverage": "jest --coverage",
|
|
18
|
+
"prepare": "npm run build"
|
|
19
|
+
},
|
|
10
20
|
"keywords": [
|
|
11
21
|
"api",
|
|
12
22
|
"service",
|
|
@@ -40,13 +50,5 @@
|
|
|
40
50
|
},
|
|
41
51
|
"publishConfig": {
|
|
42
52
|
"access": "public"
|
|
43
|
-
},
|
|
44
|
-
"scripts": {
|
|
45
|
-
"build": "tsc",
|
|
46
|
-
"clean": "rimraf dist",
|
|
47
|
-
"prebuild": "npm run clean",
|
|
48
|
-
"test": "jest",
|
|
49
|
-
"test:watch": "jest --watch",
|
|
50
|
-
"test:coverage": "jest --coverage"
|
|
51
53
|
}
|
|
52
|
-
}
|
|
54
|
+
}
|