@docaohuynh/ielts-api-utils 1.0.6 → 1.0.7
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/index.js +44 -0
- package/dist/src/utils/request/fetch.d.ts +17 -0
- package/package.json +1 -11
package/dist/index.js
CHANGED
|
@@ -5109,6 +5109,39 @@ async function sendPost(url, body, options = {}) {
|
|
|
5109
5109
|
throw error;
|
|
5110
5110
|
}
|
|
5111
5111
|
}
|
|
5112
|
+
async function sendPut(url, body, options = {}) {
|
|
5113
|
+
const { headers = {}, timeout: timeout3 = 30000 } = options;
|
|
5114
|
+
const controller = new AbortController;
|
|
5115
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout3);
|
|
5116
|
+
try {
|
|
5117
|
+
const response = await fetch(url, {
|
|
5118
|
+
method: "PUT",
|
|
5119
|
+
headers: {
|
|
5120
|
+
"Content-Type": "application/json",
|
|
5121
|
+
...headers
|
|
5122
|
+
},
|
|
5123
|
+
body: JSON.stringify(body),
|
|
5124
|
+
signal: controller.signal
|
|
5125
|
+
});
|
|
5126
|
+
clearTimeout(timeoutId);
|
|
5127
|
+
if (!response.ok) {
|
|
5128
|
+
throw new Error(`HTTP error! status: ${response.status} ${response.statusText}`);
|
|
5129
|
+
}
|
|
5130
|
+
const data = await response.json();
|
|
5131
|
+
return {
|
|
5132
|
+
data,
|
|
5133
|
+
status: response.status,
|
|
5134
|
+
statusText: response.statusText,
|
|
5135
|
+
headers: response.headers
|
|
5136
|
+
};
|
|
5137
|
+
} catch (error) {
|
|
5138
|
+
clearTimeout(timeoutId);
|
|
5139
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
5140
|
+
throw new Error(`Request timeout after ${timeout3}ms`);
|
|
5141
|
+
}
|
|
5142
|
+
throw error;
|
|
5143
|
+
}
|
|
5144
|
+
}
|
|
5112
5145
|
async function sendGetWithBearer(url, token, options = {}) {
|
|
5113
5146
|
return sendGet(url, {
|
|
5114
5147
|
...options,
|
|
@@ -5127,6 +5160,15 @@ async function sendPostWithBearer(url, body, token, options = {}) {
|
|
|
5127
5160
|
}
|
|
5128
5161
|
});
|
|
5129
5162
|
}
|
|
5163
|
+
async function sendPutWithBearer(url, body, token, options = {}) {
|
|
5164
|
+
return sendPut(url, body, {
|
|
5165
|
+
...options,
|
|
5166
|
+
headers: {
|
|
5167
|
+
...options.headers,
|
|
5168
|
+
Authorization: `Bearer ${token}`
|
|
5169
|
+
}
|
|
5170
|
+
});
|
|
5171
|
+
}
|
|
5130
5172
|
// node_modules/escape-string-regexp/index.js
|
|
5131
5173
|
function escapeStringRegexp(string) {
|
|
5132
5174
|
if (typeof string !== "string") {
|
|
@@ -7181,6 +7223,8 @@ export {
|
|
|
7181
7223
|
textToSlug,
|
|
7182
7224
|
splitIntoSentencesSimple,
|
|
7183
7225
|
splitIntoSentences,
|
|
7226
|
+
sendPutWithBearer,
|
|
7227
|
+
sendPut,
|
|
7184
7228
|
sendPostWithBearer,
|
|
7185
7229
|
sendPost,
|
|
7186
7230
|
sendGetWithBearer,
|
|
@@ -26,6 +26,14 @@ export declare function sendGet<T = any>(url: string, options?: RequestOptions):
|
|
|
26
26
|
* @returns Promise with response data
|
|
27
27
|
*/
|
|
28
28
|
export declare function sendPost<T = any>(url: string, body: any, options?: RequestOptions): Promise<ResponseData<T>>;
|
|
29
|
+
/**
|
|
30
|
+
* Send a PUT request
|
|
31
|
+
* @param url - The URL to send the request to
|
|
32
|
+
* @param body - The request body
|
|
33
|
+
* @param options - Request options including headers and timeout
|
|
34
|
+
* @returns Promise with response data
|
|
35
|
+
*/
|
|
36
|
+
export declare function sendPut<T = any>(url: string, body: any, options?: RequestOptions): Promise<ResponseData<T>>;
|
|
29
37
|
/**
|
|
30
38
|
* Send a GET request with Bearer token authentication
|
|
31
39
|
* @param url - The URL to send the request to
|
|
@@ -43,3 +51,12 @@ export declare function sendGetWithBearer<T = any>(url: string, token: string, o
|
|
|
43
51
|
* @returns Promise with response data
|
|
44
52
|
*/
|
|
45
53
|
export declare function sendPostWithBearer<T = any>(url: string, body: any, token: string, options?: RequestOptions): Promise<ResponseData<T>>;
|
|
54
|
+
/**
|
|
55
|
+
* Send a PUT request with Bearer token authentication
|
|
56
|
+
* @param url - The URL to send the request to
|
|
57
|
+
* @param body - The request body
|
|
58
|
+
* @param token - The Bearer token
|
|
59
|
+
* @param options - Request options including headers and timeout
|
|
60
|
+
* @returns Promise with response data
|
|
61
|
+
*/
|
|
62
|
+
export declare function sendPutWithBearer<T = any>(url: string, body: any, token: string, options?: RequestOptions): Promise<ResponseData<T>>;
|
package/package.json
CHANGED
|
@@ -1,21 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docaohuynh/ielts-api-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Utilities for IELTS API",
|
|
5
5
|
"module": "index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"type": "module",
|
|
9
|
-
"typesVersions": {
|
|
10
|
-
"*": {
|
|
11
|
-
"*": ["dist/index.d.ts"]
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"exports": {
|
|
15
|
-
".": {
|
|
16
|
-
"types": "./dist/index.d.ts"
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
9
|
"scripts": {
|
|
20
10
|
"build": "bun build index.ts --outdir dist --target node && tsc -p tsconfig.build.json"
|
|
21
11
|
},
|