🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@cloudcommerce/api

Package Overview
Dependencies
Maintainers
1
Versions
535
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cloudcommerce/api - npm Package Compare versions

Comparing version

to
0.0.6

2

lib/index.d.ts

@@ -7,3 +7,3 @@ import type { Endpoint, Config, ResponseBody } from './types';

declare const api: {
<T extends Config>(config: T): Promise<Response & {
<T extends Config>(config: T, retries?: number): Promise<Response & {
config: Config;

@@ -10,0 +10,0 @@ data: ResponseBody<T>;

@@ -32,5 +32,7 @@ // @ts-ignore

};
const api = async (config) => {
const api = async (config, retries = 0) => {
const url = def.middleware(config);
const { method, headers, timeout = 20000 } = config;
const {
method, headers, timeout = 20000, maxRetries = 3,
} = config;
const abortController = new AbortController();

@@ -51,6 +53,15 @@ const timer = setTimeout(() => abortController.abort(), timeout);

}
const { status } = response;
if (maxRetries < retries && (status === 429 || status >= 500)) {
const retryAfter = response.headers.get('retry-after');
return new Promise((resolve, reject) => {
setTimeout(() => {
api(config, retries + 1).then(resolve).catch(reject);
}, (retryAfter && parseInt(retryAfter, 10)) || 5000);
});
}
const error = new Error(response.statusText);
error.config = config;
error.response = response;
error.statusCode = response.status;
error.statusCode = status;
throw error;

@@ -57,0 +68,0 @@ };

@@ -27,2 +27,3 @@ import type { Products } from './types/products';

timeout?: number;
maxRetries?: number;
};

@@ -29,0 +30,0 @@ declare type ReadConfig<endpoint> = Config & {

{
"name": "@cloudcommerce/api",
"version": "0.0.5",
"version": "0.0.6",
"description": "E-Com Plus Cloud Commerce APIs client/adapter",

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

@@ -37,3 +37,3 @@ import type { Endpoint, Config, ResponseBody } from './types';

const api = async <T extends Config>(config: T): Promise<Response & {
const api = async <T extends Config>(config: T, retries = 0): Promise<Response & {
config: Config,

@@ -43,3 +43,8 @@ data: ResponseBody<T>,

const url = def.middleware(config);
const { method, headers, timeout = 20000 } = config;
const {
method,
headers,
timeout = 20000,
maxRetries = 3,
} = config;
const abortController = new AbortController();

@@ -60,6 +65,15 @@ const timer = setTimeout(() => abortController.abort(), timeout);

}
const { status } = response;
if (maxRetries < retries && (status === 429 || status >= 500)) {
const retryAfter = response.headers.get('retry-after');
return new Promise((resolve, reject) => {
setTimeout(() => {
api(config, retries + 1).then(resolve).catch(reject);
}, (retryAfter && parseInt(retryAfter, 10)) || 5000);
});
}
const error: any = new Error(response.statusText);
error.config = config;
error.response = response;
error.statusCode = response.status;
error.statusCode = status;
throw error;

@@ -66,0 +80,0 @@ };

@@ -40,2 +40,3 @@ import type { Products } from './types/products';

timeout?: number,
maxRetries?: number,
};

@@ -42,0 +43,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet