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

fetch-retry

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-retry - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1

4

index.d.ts
declare module 'fetch-retry' {
const _fetch: typeof fetch;
type RequestDelayFunction = ((

@@ -20,4 +22,4 @@ attempt: number,

function fetchBuilder(fetch: (url: String, options?: RequestInit) => Promise<Response>): ((url: String, options?: IRequestInitWithRetry) => Promise<Response>);
function fetchBuilder(fetch: typeof _fetch): ((input: RequestInfo, init?: IRequestInitWithRetry) => Promise<Response>);
export = fetchBuilder;
}

@@ -9,3 +9,3 @@ 'use strict';

return function fetchRetry(url, options) {
return function fetchRetry(input, init) {
var retries = 3;

@@ -15,5 +15,5 @@ var retryDelay = 1000;

if (options && options.retries !== undefined) {
if (isPositiveInteger(options.retries)) {
retries = options.retries;
if (init && init.retries !== undefined) {
if (isPositiveInteger(init.retries)) {
retries = init.retries;
} else {

@@ -24,5 +24,5 @@ throw new ArgumentError('retries must be a positive integer');

if (options && options.retryDelay !== undefined) {
if (isPositiveInteger(options.retryDelay) || (typeof options.retryDelay === 'function')) {
retryDelay = options.retryDelay;
if (init && init.retryDelay !== undefined) {
if (isPositiveInteger(init.retryDelay) || (typeof init.retryDelay === 'function')) {
retryDelay = init.retryDelay;
} else {

@@ -33,5 +33,5 @@ throw new ArgumentError('retryDelay must be a positive integer or a function returning a positive integer');

if (options && options.retryOn) {
if (Array.isArray(options.retryOn) || (typeof options.retryOn === 'function')) {
retryOn = options.retryOn;
if (init && init.retryOn) {
if (Array.isArray(init.retryOn) || (typeof init.retryOn === 'function')) {
retryOn = init.retryOn;
} else {

@@ -44,3 +44,3 @@ throw new ArgumentError('retryOn property expects an array or function');

var wrappedFetch = function (attempt) {
fetch(url, options)
fetch(input, init)
.then(function (response) {

@@ -47,0 +47,0 @@ if (Array.isArray(retryOn) && retryOn.indexOf(response.status) === -1) {

{
"name": "fetch-retry",
"version": "3.0.0",
"description": "Adds retry functionality to the Fetch API",
"version": "3.0.1",
"description": "Extend any fetch library with retry functionality",
"repository": "https://github.com/jonbern/fetch-retry.git",

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

@@ -77,3 +77,3 @@ 'use strict';

it('retries the request #retries times', () => {
const options = {
const init = {
retries: 3,

@@ -84,5 +84,5 @@ retryDelay: 100,

const expectedCallCount = options.retries + 1;
const expectedCallCount = init.retries + 1;
return fetchRetry(baseUrl, options)
return fetchRetry(baseUrl, init)
.then(getCallCount)

@@ -93,3 +93,3 @@ .should.eventually.equal(expectedCallCount);

it('eventually resolves the promise with the response of the last request', () => {
const options = {
const init = {
retries: 3,

@@ -105,3 +105,3 @@ retryDelay: 100,

return fetchRetry(baseUrl, options)
return fetchRetry(baseUrl, init)
.then(response => {

@@ -131,3 +131,3 @@ return {

it('retries the request up to #retries times', () => {
const options = {
const init = {
retries: 3,

@@ -140,3 +140,3 @@ retryDelay: 100,

return fetchRetry(baseUrl, options)
return fetchRetry(baseUrl, init)
.then(getCallCount)

@@ -147,3 +147,3 @@ .should.eventually.equal(expectedCallCount);

it('eventually resolves the promise with the received response of the last request', () => {
const options = {
const init = {
retries: 3,

@@ -159,3 +159,3 @@ retryDelay: 100,

return fetchRetry(baseUrl, options)
return fetchRetry(baseUrl, init)
.then(response => {

@@ -185,3 +185,3 @@ return {

it('retries the request #retries times', () => {
const options = {
const init = {
retries: 3,

@@ -192,5 +192,5 @@ retryDelay: 100,

const expectedCallCount = options.retries + 1;
const expectedCallCount = init.retries + 1;
return fetchRetry(baseUrl, options)
return fetchRetry(baseUrl, init)
.then(getCallCount)

@@ -197,0 +197,0 @@ .should.eventually.equal(expectedCallCount);

@@ -63,3 +63,3 @@ 'use strict';

describe('#url', function () {
describe('#input', function () {

@@ -72,3 +72,3 @@ var expectedUrl = 'http://some-url.com';

it('passes #url to fetch', function () {
it('passes #input to fetch', function () {
expect(fetch.getCall(0).args[0]).toBe(expectedUrl);

@@ -79,10 +79,10 @@ });

describe('#options', function () {
describe('#init', function () {
describe('when #options is provided', function () {
describe('when #init is provided', function () {
var options;
var init;
beforeEach(function () {
options = {
init = {
retries: 3,

@@ -92,15 +92,15 @@ whatever: 'something'

fetchRetry('http://someUrl', options);
fetchRetry('http://someUrl', init);
});
it('passes options to fetch', function () {
expect(fetch.getCall(0).args[1]).toEqual(options);
it('passes init to fetch', function () {
expect(fetch.getCall(0).args[1]).toEqual(init);
});
describe('when #options.retryOn is not an array or function', () => {
describe('when #init.retryOn is not an array or function', () => {
it('throws exception', () => {
expect(function () {
options.retryOn = 503;
fetchRetry('http://someUrl', options);
init.retryOn = 503;
fetchRetry('http://someUrl', init);
}).toThrow({

@@ -116,3 +116,3 @@ name: 'ArgumentError',

describe('when #options is undefined or null', function () {
describe('when #init is undefined or null', function () {

@@ -125,3 +125,3 @@ [undefined, null].forEach(function (testCase) {

it('does not pass through options to fetch', function () {
it('does not pass through init to fetch', function () {
expect(fetch.getCall(0).args[1]).toEqual(undefined);

@@ -136,5 +136,5 @@ });

describe('#options.retries', function () {
describe('#init.retries', function () {
describe('when #options.retries=3 (default)', function () {
describe('when #init.retries=3 (default)', function () {

@@ -282,3 +282,3 @@ beforeEach(function () {

describe('when #options.retries=1', function () {
describe('when #init.retries=1', function () {

@@ -367,3 +367,3 @@ beforeEach(function () {

describe('when #options.retries=0', function () {
describe('when #init.retries=0', function () {

@@ -417,3 +417,3 @@ beforeEach(function () {

describe('when #options.retries is not a a positive integer', () => {
describe('when #init.retries is not a a positive integer', () => {

@@ -438,7 +438,7 @@ ['1', -1, 'not a number', null].forEach(invalidRetries => {

describe('#options.retryDelay', function () {
describe('#init.retryDelay', function () {
describe('when #options.retryDelay is a number', function () {
describe('when #init.retryDelay is a number', function () {
var options;
var init;
var retryDelay;

@@ -448,3 +448,3 @@

retryDelay = 5000;
options = {
init = {
retryDelay: retryDelay

@@ -455,3 +455,3 @@ };

fetchRetry('http://someUrl', options)
fetchRetry('http://someUrl', init)
.then(thenCallback);

@@ -494,5 +494,5 @@ });

describe('when #options.retryDelay is 0', function () {
describe('when #init.retryDelay is 0', function () {
var options;
var init;
var retryDelay;

@@ -502,3 +502,3 @@

retryDelay = 0;
options = {
init = {
retryDelay: retryDelay

@@ -509,3 +509,3 @@ };

fetchRetry('http://someUrl', options)
fetchRetry('http://someUrl', init)
.then(thenCallback);

@@ -536,3 +536,3 @@ });

describe('when #options.retryDelay is not a a positive integer', () => {
describe('when #init.retryDelay is not a a positive integer', () => {

@@ -555,5 +555,5 @@ ['1', -1, 'not a number', null].forEach(invalidDelay => {

describe('when #options.retryDelay is a function', function () {
describe('when #init.retryDelay is a function', function () {
var options;
var init;
var retryDelay;

@@ -563,3 +563,3 @@

retryDelay = sinon.stub().returns(5000);
options = {
init = {
retryDelay: retryDelay

@@ -570,3 +570,3 @@ };

fetchRetry('http://someUrl', options)
fetchRetry('http://someUrl', init)
.then(thenCallback);

@@ -627,7 +627,7 @@ });

describe('#options.retryOn', () => {
describe('#init.retryOn', () => {
describe('when #options.retryOn is an array', () => {
describe('when #init.retryOn is an array', () => {
var options;
var init;
var retryOn;

@@ -637,3 +637,3 @@

retryOn = [503, 404];
options = {
init = {
retryOn: retryOn

@@ -645,3 +645,3 @@ };

fetchRetry('http://someUrl', options)
fetchRetry('http://someUrl', init)
.then(thenCallback)

@@ -693,5 +693,5 @@ .catch((catchCallback));

describe('when #options.retryOn is a function', function () {
describe('when #init.retryOn is a function', function () {
var options;
var init;
var retryOn;

@@ -701,3 +701,3 @@

retryOn = sinon.stub();
options = {
init = {
retryOn: retryOn

@@ -709,3 +709,3 @@ };

fetchRetry('http://someUrl', options)
fetchRetry('http://someUrl', init)
.then(thenCallback)

@@ -872,12 +872,12 @@ .catch((catchCallback));

describe('when #options.retryOn is not an array or function', function () {
describe('when #init.retryOn is not an array or function', function () {
var options;
var init;
describe('when #options.retryOn is not an array or function', () => {
describe('when #init.retryOn is not an array or function', () => {
it('throws exception', () => {
expect(function () {
options.retryOn = 503;
fetchRetry('http://someUrl', options);
init.retryOn = 503;
fetchRetry('http://someUrl', init);
}).toThrow({

@@ -884,0 +884,0 @@ name: 'ArgumentError',

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