Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vitrical/utils

Package Overview
Dependencies
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vitrical/utils - npm Package Compare versions

Comparing version 1.6.0 to 1.6.1

3

api.d.ts

@@ -29,5 +29,6 @@ export declare class ApiError extends Error {

};
debug?: boolean;
};
export declare const removeUndefined: (obj: any) => any;
export declare const request: <B = any, R = any>({ method, url, body, formData, query, headers, }: CustomRequestOptions<B>) => Promise<CustomRequestResponse<R>>;
export declare const request: <B = any, R = any>({ method, url, body, formData, query, headers, debug, }: CustomRequestOptions<B>) => Promise<CustomRequestResponse<R>>;
export declare const makeMicroserviceRequest: (baseURL: string, key: string) => <T extends unknown>(method: 'get' | 'post' | 'put' | 'delete', url: string, options?: {

@@ -34,0 +35,0 @@ body?: any;

@@ -117,21 +117,19 @@ "use strict";

exports.removeUndefined = removeUndefined;
const request = ({ method, url, body, formData, query, headers, }) => new Promise((resolve, reject) => {
const request = ({ method, url, body, formData, query, headers, debug, }) => new Promise((resolve, reject) => {
const lcaseMethod = method.toLowerCase();
const newStack = new Error().stack;
if (isFetchAvailable() && (!isXMLHttpRequestAvailable() || !axios_1.default?.request)) {
const request = fetch(!query || Object.keys(query).length === 0
? url
: url + '?' + new URLSearchParams((0, exports.removeUndefined)(query)), {
method: lcaseMethod,
body: formData !== undefined
? formData
: body &&
(typeof body === 'string' ||
headers?.['Content-Type'] === 'multipart/form-data' ||
headers?.['Content-Type'] === 'text/plain' ||
headers?.['Content-Type'] === 'application/octet-stream')
? body
: JSON.stringify(body),
headers: {
...(body
const bodyData = formData !== undefined
? formData
: body !== undefined &&
(typeof body === 'string' ||
headers?.['Content-Type'] === 'multipart/form-data' ||
headers?.['Content-Type'] === 'text/plain' ||
headers?.['Content-Type'] === 'application/octet-stream')
? body
: JSON.stringify(body);
const headerData = {
...(formData
? {}
: body
? typeof body === 'string'

@@ -141,4 +139,14 @@ ? { 'Content-Type': 'text/plain' }

: {}),
...headers,
},
...headers,
};
const urlData = !query || Object.keys(query).length === 0
? url
: url + '?' + new URLSearchParams((0, exports.removeUndefined)(query));
if (debug) {
console.log('fetch', lcaseMethod, urlData, bodyData, headerData);
}
const request = fetch(urlData, {
method: lcaseMethod,
body: bodyData,
headers: headerData,
});

@@ -178,19 +186,22 @@ request

}
const headerData = {
...(formData
? {}
: body
? typeof body === 'string'
? { 'Content-Type': 'text/plain' }
: { 'Content-Type': 'application/json' }
: {}),
...headers,
};
const bodyData = formData !== undefined ? formData : body;
if (debug) {
console.log('axios', lcaseMethod, url, bodyData, query, headerData);
}
const request = axios_1.default.request({
method: lcaseMethod,
url,
data: formData !== undefined ? formData : body,
data: bodyData,
params: query,
headers: {
...(body
? typeof body === 'string'
? { 'Content-Type': 'text/plain' }
: { 'Content-Type': 'application/json' }
: formData
? {
'Content-Type': 'multipart/form-data',
}
: {}),
...headers,
},
headers: headerData,
timeout: 1000 * 60 * 5,

@@ -197,0 +208,0 @@ });

{
"name": "@vitrical/utils",
"version": "1.6.0",
"version": "1.6.1",
"description": "Collection of useful functions and typings",

@@ -5,0 +5,0 @@ "main": "index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc