@docaohuynh/ielts-api-utils 1.0.6 → 1.0.8
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 +87 -0
- package/dist/src/utils/request/fetch.d.ts +32 -0
- package/package.json +1 -11
package/dist/index.js
CHANGED
|
@@ -5109,6 +5109,71 @@ 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
|
+
}
|
|
5145
|
+
async function sendDelete(url, options = {}) {
|
|
5146
|
+
const { headers = {}, timeout: timeout3 = 30000 } = options;
|
|
5147
|
+
const controller = new AbortController;
|
|
5148
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout3);
|
|
5149
|
+
try {
|
|
5150
|
+
const response = await fetch(url, {
|
|
5151
|
+
method: "DELETE",
|
|
5152
|
+
headers: {
|
|
5153
|
+
"Content-Type": "application/json",
|
|
5154
|
+
...headers
|
|
5155
|
+
},
|
|
5156
|
+
signal: controller.signal
|
|
5157
|
+
});
|
|
5158
|
+
clearTimeout(timeoutId);
|
|
5159
|
+
if (!response.ok) {
|
|
5160
|
+
throw new Error(`HTTP error! status: ${response.status} ${response.statusText}`);
|
|
5161
|
+
}
|
|
5162
|
+
const data = await response.json();
|
|
5163
|
+
return {
|
|
5164
|
+
data,
|
|
5165
|
+
status: response.status,
|
|
5166
|
+
statusText: response.statusText,
|
|
5167
|
+
headers: response.headers
|
|
5168
|
+
};
|
|
5169
|
+
} catch (error) {
|
|
5170
|
+
clearTimeout(timeoutId);
|
|
5171
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
5172
|
+
throw new Error(`Request timeout after ${timeout3}ms`);
|
|
5173
|
+
}
|
|
5174
|
+
throw error;
|
|
5175
|
+
}
|
|
5176
|
+
}
|
|
5112
5177
|
async function sendGetWithBearer(url, token, options = {}) {
|
|
5113
5178
|
return sendGet(url, {
|
|
5114
5179
|
...options,
|
|
@@ -5127,6 +5192,24 @@ async function sendPostWithBearer(url, body, token, options = {}) {
|
|
|
5127
5192
|
}
|
|
5128
5193
|
});
|
|
5129
5194
|
}
|
|
5195
|
+
async function sendPutWithBearer(url, body, token, options = {}) {
|
|
5196
|
+
return sendPut(url, body, {
|
|
5197
|
+
...options,
|
|
5198
|
+
headers: {
|
|
5199
|
+
...options.headers,
|
|
5200
|
+
Authorization: `Bearer ${token}`
|
|
5201
|
+
}
|
|
5202
|
+
});
|
|
5203
|
+
}
|
|
5204
|
+
async function sendDeleteWithBearer(url, token, options = {}) {
|
|
5205
|
+
return sendDelete(url, {
|
|
5206
|
+
...options,
|
|
5207
|
+
headers: {
|
|
5208
|
+
...options.headers,
|
|
5209
|
+
Authorization: `Bearer ${token}`
|
|
5210
|
+
}
|
|
5211
|
+
});
|
|
5212
|
+
}
|
|
5130
5213
|
// node_modules/escape-string-regexp/index.js
|
|
5131
5214
|
function escapeStringRegexp(string) {
|
|
5132
5215
|
if (typeof string !== "string") {
|
|
@@ -7181,10 +7264,14 @@ export {
|
|
|
7181
7264
|
textToSlug,
|
|
7182
7265
|
splitIntoSentencesSimple,
|
|
7183
7266
|
splitIntoSentences,
|
|
7267
|
+
sendPutWithBearer,
|
|
7268
|
+
sendPut,
|
|
7184
7269
|
sendPostWithBearer,
|
|
7185
7270
|
sendPost,
|
|
7186
7271
|
sendGetWithBearer,
|
|
7187
7272
|
sendGet,
|
|
7273
|
+
sendDeleteWithBearer,
|
|
7274
|
+
sendDelete,
|
|
7188
7275
|
replaceWordInList,
|
|
7189
7276
|
normalizeText,
|
|
7190
7277
|
getCurrentDateStr,
|
|
@@ -26,6 +26,21 @@ 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>>;
|
|
37
|
+
/**
|
|
38
|
+
* Send a DELETE request
|
|
39
|
+
* @param url - The URL to send the request to
|
|
40
|
+
* @param options - Request options including headers and timeout
|
|
41
|
+
* @returns Promise with response data
|
|
42
|
+
*/
|
|
43
|
+
export declare function sendDelete<T = any>(url: string, options?: RequestOptions): Promise<ResponseData<T>>;
|
|
29
44
|
/**
|
|
30
45
|
* Send a GET request with Bearer token authentication
|
|
31
46
|
* @param url - The URL to send the request to
|
|
@@ -43,3 +58,20 @@ export declare function sendGetWithBearer<T = any>(url: string, token: string, o
|
|
|
43
58
|
* @returns Promise with response data
|
|
44
59
|
*/
|
|
45
60
|
export declare function sendPostWithBearer<T = any>(url: string, body: any, token: string, options?: RequestOptions): Promise<ResponseData<T>>;
|
|
61
|
+
/**
|
|
62
|
+
* Send a PUT request with Bearer token authentication
|
|
63
|
+
* @param url - The URL to send the request to
|
|
64
|
+
* @param body - The request body
|
|
65
|
+
* @param token - The Bearer token
|
|
66
|
+
* @param options - Request options including headers and timeout
|
|
67
|
+
* @returns Promise with response data
|
|
68
|
+
*/
|
|
69
|
+
export declare function sendPutWithBearer<T = any>(url: string, body: any, token: string, options?: RequestOptions): Promise<ResponseData<T>>;
|
|
70
|
+
/**
|
|
71
|
+
* Send a DELETE request with Bearer token authentication
|
|
72
|
+
* @param url - The URL to send the request to
|
|
73
|
+
* @param token - The Bearer token
|
|
74
|
+
* @param options - Request options including headers and timeout
|
|
75
|
+
* @returns Promise with response data
|
|
76
|
+
*/
|
|
77
|
+
export declare function sendDeleteWithBearer<T = any>(url: string, 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.8",
|
|
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
|
},
|