Socket
Socket
Sign inDemoInstall

@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.5.6 to 1.5.7

5

api.d.ts

@@ -8,2 +8,3 @@ export declare class ApiError extends Error {

msg: string;
constructor(status: number | string, msg?: string);
}

@@ -22,2 +23,3 @@ export declare const handleApiError: (url: string, newStack: string, err: unknown) => ApiError | Error | unknown;

body?: B;
formData?: any;
query?: {

@@ -31,5 +33,6 @@ [key: string]: any;

export declare const removeUndefined: (obj: any) => any;
export declare const request: <B = any, R = any>({ method, url, body, query, headers, }: CustomRequestOptions<B>) => Promise<CustomRequestResponse<R>>;
export declare const request: <B = any, R = any>({ method, url, body, formData, 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?: {
body?: any;
formData?: any;
query?: {

@@ -36,0 +39,0 @@ [key: string]: any;

26

api.js

@@ -15,2 +15,9 @@ "use strict";

class ApiError extends Error {
constructor(status, msg) {
super(typeof status === 'number' ? `Request failed with status code ${status}` : status);
this.status = typeof status === 'number' ? status : 500;
this.headers = {};
this.url = '';
this.msg = msg || this.message;
}
}

@@ -111,3 +118,3 @@ exports.ApiError = ApiError;

exports.removeUndefined = removeUndefined;
const request = ({ method, url, body, query, headers, }) => new Promise((resolve, reject) => {
const request = ({ method, url, body, formData, query, headers, }) => new Promise((resolve, reject) => {
const lcaseMethod = method.toLowerCase();

@@ -120,9 +127,11 @@ const newStack = new Error().stack;

method: lcaseMethod,
body: 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),
body: formData
? 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: {

@@ -200,2 +209,3 @@ ...(body && typeof body === 'string'

body: options?.body,
formData: options?.formData,
query: options?.query,

@@ -202,0 +212,0 @@ headers: {

{
"name": "@vitrical/utils",
"version": "1.5.6",
"version": "1.5.7",
"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