New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rest-api-kit

Package Overview
Dependencies
Maintainers
0
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rest-api-kit - npm Package Compare versions

Comparing version 0.0.39 to 0.0.40

18

dist/index.d.ts

@@ -67,4 +67,16 @@ type MethodType = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";

declare function createRequest(url?: string, headers?: {}, method?: MethodType, body?: {}, rest?: Partial<Omit<RequestType, "headers" | "url" | "method" | "body">>): Promise<any>;
declare function makeRequest(payload: string | Partial<RequestType>, headers: Headers): Promise<any> | undefined;
declare function createRequest(url?: string, headers?: {}, method?: MethodType, body?: {}, rest?: Partial<Omit<RequestType, "headers" | "url" | "method" | "body">>): Promise<{
type: string;
data: string;
} | {
type: string;
data: Promise<any>;
}>;
declare function makeRequest(payload: string | Partial<RequestType>, headers: Headers): Promise<{
type: string;
data: string;
} | {
type: string;
data: Promise<any>;
}> | undefined;

@@ -81,3 +93,3 @@ /**

*/
declare function useRest<R = unknown, T = void>(url: string, paramsFromBase: IOptions<any, any>, options?: Partial<RestOptionsType>): TypedQueryHookReturnType<string | T>;
declare function useRest<R = unknown, T = void>(url: string, paramsFromBase: IOptions<any, any>, options?: Partial<RestOptionsType>): TypedQueryHookReturnType<T>;

@@ -84,0 +96,0 @@ declare const defaultOptions: IOptions<any, any>;

26

dist/index.js

@@ -63,5 +63,13 @@ "use strict";

const response = await fetch(url, params);
return response.json();
if (!response.ok) {
if (response.status > 299) {
return {
type: "error",
data: `Request failed with status: ${response.status}`
};
}
}
return { type: "success", data: response.json() };
} catch (error) {
console.log(error, "rest-api-kit-error");
return { type: "error", data: "An error occured" };
}

@@ -294,3 +302,3 @@ }

} = useStore();
const trigger = async (body) => {
const trigger = async (body, urlParams) => {
try {

@@ -306,3 +314,3 @@ const params = { ...paramsFromBase };

url = getBaseUrl(url, options?.baseUrl);
const formattedUrl = params.method === "GET" || params.bodyAsQueryParams ? concatenateParamsWithUrl(url, body) : url;
const formattedUrl = params.method === "GET" || params.bodyAsQueryParams ? concatenateParamsWithUrl(url, body) : !!body && !!urlParams ? concatenateParamsWithUrl(url, urlParams) : url;
load(dispatch, formattedUrl, { ...params, headers }, body);

@@ -341,8 +349,12 @@ let storeIdentifier = `${options.baseUrl || ""}&${params.endpointName}`;

);
if (response?.type === "error") {
dispatch({ type: "data/error", payload: response?.data });
return;
}
if (params.saveToCache) {
saveToStore(storeIdentifier, response, { ...params });
saveToStore(storeIdentifier, response?.data, { ...params });
}
const { type: checkType, response: payload } = applyChecks(
{ ...params, headers },
response
response?.data
);

@@ -358,3 +370,3 @@ if (checkType === "error") {

type: "response/save",
payload: response
payload: response?.data
});

@@ -361,0 +373,0 @@ dispatch({

{
"name": "rest-api-kit",
"version": "0.0.39",
"version": "0.0.40",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "module": "dist/index.mjs",

Sorry, the diff of this file is not supported yet

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