fetch-request-browser 1.0.0 → 1.0.1
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
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
The `fetch-request-browser` package makes working with external APIs simple and efficient. This intuitive wrapper leverages the power of the Fetch API, providing a clean and concise interface for your API interactions.
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
If you are working on a node-based environment, make use of [fetch-request-node](https://github.com/jesusgraterol/fetch-request-node) instead.
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
<br />
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,8 @@ import { IRequestInput, IRequestMethod, IRequestOptions, IResponseDataType, IOpt
|
|
|
9
9
|
* - INVALID_REQUEST_HEADERS: if invalid headers are passed in object format
|
|
10
10
|
* - INVALID_REQUEST_OPTIONS: if the Request Instance cannot be instantiated due to the passed opts
|
|
11
11
|
* - UNEXPECTED_RESPONSE_STATUS_CODE: if the code doesn't meet the requirements set in the options
|
|
12
|
-
* -
|
|
12
|
+
* - INVALID_RESPONSE_CONTENT_TYPE: if the res lacks the Content-Type Header or is an empty string
|
|
13
|
+
* - CONTENT_TYPE_MISSMATCH: if the Content-Type Headers don't match
|
|
13
14
|
* - INVALID_RESPONSE_DTYPE: if the data type is not supported by the Response Instance
|
|
14
15
|
*/
|
|
15
16
|
declare const send: (input: IRequestInput, options?: Partial<IOptions>) => Promise<IRequestResponse>;
|
|
@@ -28,7 +29,8 @@ declare const send: (input: IRequestInput, options?: Partial<IOptions>) => Promi
|
|
|
28
29
|
* - INVALID_REQUEST_HEADERS: if invalid headers are passed in object format
|
|
29
30
|
* - INVALID_REQUEST_OPTIONS: if the Request Instance cannot be instantiated due to the passed opts
|
|
30
31
|
* - UNEXPECTED_RESPONSE_STATUS_CODE: if the code doesn't meet the requirements set in the options
|
|
31
|
-
* -
|
|
32
|
+
* - INVALID_RESPONSE_CONTENT_TYPE: if the res lacks the Content-Type Header or is an empty string
|
|
33
|
+
* - CONTENT_TYPE_MISSMATCH: if the Content-Type Headers don't match
|
|
32
34
|
* - INVALID_RESPONSE_DTYPE: if the data type is not supported by the Response Instance
|
|
33
35
|
*/
|
|
34
36
|
declare const sendGET: (input: IRequestInput, options?: Partial<IOptions>, retryAttempts?: number, retryDelaySeconds?: number) => Promise<IRequestResponse>;
|
|
@@ -42,7 +44,8 @@ declare const sendGET: (input: IRequestInput, options?: Partial<IOptions>, retry
|
|
|
42
44
|
* - INVALID_REQUEST_HEADERS: if invalid headers are passed in object format
|
|
43
45
|
* - INVALID_REQUEST_OPTIONS: if the Request Instance cannot be instantiated due to the passed opts
|
|
44
46
|
* - UNEXPECTED_RESPONSE_STATUS_CODE: if the code doesn't meet the requirements set in the options
|
|
45
|
-
* -
|
|
47
|
+
* - INVALID_RESPONSE_CONTENT_TYPE: if the res lacks the Content-Type Header or is an empty string
|
|
48
|
+
* - CONTENT_TYPE_MISSMATCH: if the Content-Type Headers don't match
|
|
46
49
|
* - INVALID_RESPONSE_DTYPE: if the data type is not supported by the Response Instance
|
|
47
50
|
*/
|
|
48
51
|
declare const sendPOST: (input: IRequestInput, options?: Partial<IOptions>) => Promise<IRequestResponse>;
|
|
@@ -56,7 +59,8 @@ declare const sendPOST: (input: IRequestInput, options?: Partial<IOptions>) => P
|
|
|
56
59
|
* - INVALID_REQUEST_HEADERS: if invalid headers are passed in object format
|
|
57
60
|
* - INVALID_REQUEST_OPTIONS: if the Request Instance cannot be instantiated due to the passed opts
|
|
58
61
|
* - UNEXPECTED_RESPONSE_STATUS_CODE: if the code doesn't meet the requirements set in the options
|
|
59
|
-
* -
|
|
62
|
+
* - INVALID_RESPONSE_CONTENT_TYPE: if the res lacks the Content-Type Header or is an empty string
|
|
63
|
+
* - CONTENT_TYPE_MISSMATCH: if the Content-Type Headers don't match
|
|
60
64
|
* - INVALID_RESPONSE_DTYPE: if the data type is not supported by the Response Instance
|
|
61
65
|
*/
|
|
62
66
|
declare const sendPUT: (input: IRequestInput, options?: Partial<IOptions>) => Promise<IRequestResponse>;
|
|
@@ -70,7 +74,8 @@ declare const sendPUT: (input: IRequestInput, options?: Partial<IOptions>) => Pr
|
|
|
70
74
|
* - INVALID_REQUEST_HEADERS: if invalid headers are passed in object format
|
|
71
75
|
* - INVALID_REQUEST_OPTIONS: if the Request Instance cannot be instantiated due to the passed opts
|
|
72
76
|
* - UNEXPECTED_RESPONSE_STATUS_CODE: if the code doesn't meet the requirements set in the options
|
|
73
|
-
* -
|
|
77
|
+
* - INVALID_RESPONSE_CONTENT_TYPE: if the res lacks the Content-Type Header or is an empty string
|
|
78
|
+
* - CONTENT_TYPE_MISSMATCH: if the Content-Type Headers don't match
|
|
74
79
|
* - INVALID_RESPONSE_DTYPE: if the data type is not supported by the Response Instance
|
|
75
80
|
*/
|
|
76
81
|
declare const sendPATCH: (input: IRequestInput, options?: Partial<IOptions>) => Promise<IRequestResponse>;
|
|
@@ -84,7 +89,8 @@ declare const sendPATCH: (input: IRequestInput, options?: Partial<IOptions>) =>
|
|
|
84
89
|
* - INVALID_REQUEST_HEADERS: if invalid headers are passed in object format
|
|
85
90
|
* - INVALID_REQUEST_OPTIONS: if the Request Instance cannot be instantiated due to the passed opts
|
|
86
91
|
* - UNEXPECTED_RESPONSE_STATUS_CODE: if the code doesn't meet the requirements set in the options
|
|
87
|
-
* -
|
|
92
|
+
* - INVALID_RESPONSE_CONTENT_TYPE: if the res lacks the Content-Type Header or is an empty string
|
|
93
|
+
* - CONTENT_TYPE_MISSMATCH: if the Content-Type Headers don't match
|
|
88
94
|
* - INVALID_RESPONSE_DTYPE: if the data type is not supported by the Response Instance
|
|
89
95
|
*/
|
|
90
96
|
declare const sendDELETE: (input: IRequestInput, options?: Partial<IOptions>) => Promise<IRequestResponse>;
|
package/dist/shared/errors.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ declare enum ERRORS {
|
|
|
4
4
|
INVALID_REQUEST_OPTIONS = "INVALID_REQUEST_OPTIONS",
|
|
5
5
|
INVALID_RESPONSE_DTYPE = "INVALID_RESPONSE_DTYPE",
|
|
6
6
|
UNEXPECTED_RESPONSE_STATUS_CODE = "UNEXPECTED_RESPONSE_STATUS_CODE",
|
|
7
|
+
INVALID_RESPONSE_CONTENT_TYPE = "INVALID_RESPONSE_CONTENT_TYPE",
|
|
7
8
|
CONTENT_TYPE_MISSMATCH = "CONTENT_TYPE_MISSMATCH"
|
|
8
9
|
}
|
|
9
10
|
export { ERRORS, };
|
package/dist/shared/errors.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var ERRORS;!function(E){E.INVALID_REQUEST_URL="INVALID_REQUEST_URL",E.INVALID_REQUEST_HEADERS="INVALID_REQUEST_HEADERS",E.INVALID_REQUEST_OPTIONS="INVALID_REQUEST_OPTIONS",E.INVALID_RESPONSE_DTYPE="INVALID_RESPONSE_DTYPE",E.UNEXPECTED_RESPONSE_STATUS_CODE="UNEXPECTED_RESPONSE_STATUS_CODE",E.CONTENT_TYPE_MISSMATCH="CONTENT_TYPE_MISSMATCH"}(ERRORS||(ERRORS={}));export{ERRORS};
|
|
1
|
+
var ERRORS;!function(E){E.INVALID_REQUEST_URL="INVALID_REQUEST_URL",E.INVALID_REQUEST_HEADERS="INVALID_REQUEST_HEADERS",E.INVALID_REQUEST_OPTIONS="INVALID_REQUEST_OPTIONS",E.INVALID_RESPONSE_DTYPE="INVALID_RESPONSE_DTYPE",E.UNEXPECTED_RESPONSE_STATUS_CODE="UNEXPECTED_RESPONSE_STATUS_CODE",E.INVALID_RESPONSE_CONTENT_TYPE="INVALID_RESPONSE_CONTENT_TYPE",E.CONTENT_TYPE_MISSMATCH="CONTENT_TYPE_MISSMATCH"}(ERRORS||(ERRORS={}));export{ERRORS};
|
|
@@ -6,7 +6,8 @@ import { IOptions } from '../shared/types.js';
|
|
|
6
6
|
* @param options
|
|
7
7
|
* @throws
|
|
8
8
|
* - UNEXPECTED_RESPONSE_STATUS_CODE: if the code doesn't meet the requirements set in the options
|
|
9
|
-
* -
|
|
9
|
+
* - INVALID_RESPONSE_CONTENT_TYPE: if the res lacks the Content-Type Header or is an empty string
|
|
10
|
+
* - CONTENT_TYPE_MISSMATCH: if the Content-Type Headers don't match
|
|
10
11
|
*/
|
|
11
12
|
declare const validateResponse: (req: Request, res: Response, options: IOptions) => void;
|
|
12
13
|
export { validateResponse, };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{encodeError}from"error-message-utils";import{ERRORS}from"../shared/errors.js";const __buildUnexpectedCodeErrorMessage=e=>encodeError(`Request Failed: received unexpected response code '${e.status}': ${e.statusText}`,ERRORS.UNEXPECTED_RESPONSE_STATUS_CODE),__validateStatusCode=(e,t)=>{if(Array.isArray(t.acceptableStatusCodes)&&t.acceptableStatusCodes.length){if(!t.acceptableStatusCodes.includes(e.status))throw new Error(__buildUnexpectedCodeErrorMessage(e))}else if(e.status<t.acceptableStatusCodesRange.min||e.status>t.acceptableStatusCodesRange.max)throw new Error(__buildUnexpectedCodeErrorMessage(e))},__validateContentType=(e,t)=>{const r=e.headers.get("Accept"),s=t.headers.get("Content-Type");if(
|
|
1
|
+
import{encodeError}from"error-message-utils";import{ERRORS}from"../shared/errors.js";const __buildUnexpectedCodeErrorMessage=e=>encodeError(`Request Failed: received unexpected response code '${e.status}': ${e.statusText}`,ERRORS.UNEXPECTED_RESPONSE_STATUS_CODE),__validateStatusCode=(e,t)=>{if(Array.isArray(t.acceptableStatusCodes)&&t.acceptableStatusCodes.length){if(!t.acceptableStatusCodes.includes(e.status))throw new Error(__buildUnexpectedCodeErrorMessage(e))}else if(e.status<t.acceptableStatusCodesRange.min||e.status>t.acceptableStatusCodesRange.max)throw new Error(__buildUnexpectedCodeErrorMessage(e))},__validateContentType=(e,t)=>{const r=e.headers.get("Accept"),s=t.headers.get("Content-Type");if("string"!=typeof s||!s.length)throw new Error(encodeError(`The response's Content-Type Header is invalid. Received: '${s}'.`,ERRORS.INVALID_RESPONSE_CONTENT_TYPE));if(!s.includes(r))throw new Error(encodeError(`The request's Accept Header '${r}' is different to the Content-Type received in the response '${s}'.`,ERRORS.CONTENT_TYPE_MISSMATCH))},validateResponse=(e,t,r)=>{__validateStatusCode(t,r),__validateContentType(e,t)};export{validateResponse};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fetch-request-browser",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "The fetch-request-browser package makes working with external APIs simple and efficient. This intuitive wrapper leverages the power of the Fetch API, providing a clean and concise interface for your API interactions.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|