@docaohuynh/ielts-api-utils 1.0.7 → 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 +43 -0
- package/dist/src/utils/request/fetch.d.ts +15 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5142,6 +5142,38 @@ async function sendPut(url, body, options = {}) {
|
|
|
5142
5142
|
throw error;
|
|
5143
5143
|
}
|
|
5144
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
|
+
}
|
|
5145
5177
|
async function sendGetWithBearer(url, token, options = {}) {
|
|
5146
5178
|
return sendGet(url, {
|
|
5147
5179
|
...options,
|
|
@@ -5169,6 +5201,15 @@ async function sendPutWithBearer(url, body, token, options = {}) {
|
|
|
5169
5201
|
}
|
|
5170
5202
|
});
|
|
5171
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
|
+
}
|
|
5172
5213
|
// node_modules/escape-string-regexp/index.js
|
|
5173
5214
|
function escapeStringRegexp(string) {
|
|
5174
5215
|
if (typeof string !== "string") {
|
|
@@ -7229,6 +7270,8 @@ export {
|
|
|
7229
7270
|
sendPost,
|
|
7230
7271
|
sendGetWithBearer,
|
|
7231
7272
|
sendGet,
|
|
7273
|
+
sendDeleteWithBearer,
|
|
7274
|
+
sendDelete,
|
|
7232
7275
|
replaceWordInList,
|
|
7233
7276
|
normalizeText,
|
|
7234
7277
|
getCurrentDateStr,
|
|
@@ -34,6 +34,13 @@ export declare function sendPost<T = any>(url: string, body: any, options?: Requ
|
|
|
34
34
|
* @returns Promise with response data
|
|
35
35
|
*/
|
|
36
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>>;
|
|
37
44
|
/**
|
|
38
45
|
* Send a GET request with Bearer token authentication
|
|
39
46
|
* @param url - The URL to send the request to
|
|
@@ -60,3 +67,11 @@ export declare function sendPostWithBearer<T = any>(url: string, body: any, toke
|
|
|
60
67
|
* @returns Promise with response data
|
|
61
68
|
*/
|
|
62
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>>;
|