@vitrical/utils
Advanced tools
Comparing version 1.4.1 to 1.4.2
12
api.d.ts
@@ -12,5 +12,5 @@ import { AxiosError } from 'axios'; | ||
export declare const handleApiError: (url: string, newStack: string, err: AxiosError) => ApiError | Error | unknown; | ||
export type CustomRequestResponse = { | ||
export type CustomRequestResponse<R = any> = { | ||
status: number; | ||
body: any; | ||
body: R; | ||
headers: { | ||
@@ -20,6 +20,6 @@ [key: string]: any; | ||
}; | ||
export type CustomRequestOptions = { | ||
method: 'get' | 'post' | 'put' | 'delete'; | ||
export type CustomRequestOptions<B = any> = { | ||
method: 'get' | 'post' | 'put' | 'delete' | 'patch' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'; | ||
url: string; | ||
body?: any; | ||
body?: B; | ||
query?: { | ||
@@ -33,3 +33,3 @@ [key: string]: any; | ||
export declare const removeUndefined: (obj: any) => any; | ||
export declare const request: ({ method, url, body, query, headers, }: CustomRequestOptions) => Promise<CustomRequestResponse>; | ||
export declare const request: <B = any, R = any>({ method, url, body, query, headers, }: CustomRequestOptions<B>) => Promise<CustomRequestResponse<R>>; | ||
export declare const makeMicroserviceRequest: (baseURL: string, key: string) => <T extends unknown>(method: 'get' | 'post' | 'put' | 'delete', url: string, options?: { | ||
@@ -36,0 +36,0 @@ body?: any; |
@@ -91,2 +91,3 @@ "use strict"; | ||
const request = ({ method, url, body, query, headers, }) => new Promise((resolve, reject) => { | ||
const lcaseMethod = method.toLowerCase(); | ||
const newStack = new Error().stack; | ||
@@ -97,3 +98,3 @@ if (isFetchAvailable() && !isXMLHttpRequestAvailable()) { | ||
: url + '?' + new URLSearchParams((0, exports.removeUndefined)(query)), { | ||
method, | ||
method: lcaseMethod, | ||
body: body && typeof body === 'string' ? body : JSON.stringify(body), | ||
@@ -133,3 +134,3 @@ headers: { | ||
const request = axios_1.default.request({ | ||
method, | ||
method: lcaseMethod, | ||
url, | ||
@@ -136,0 +137,0 @@ data: body, |
{ | ||
"name": "@vitrical/utils", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"description": "Collection of useful functions and typings", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
62810
1108