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

@osskit/fetch-enhancers

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@osskit/fetch-enhancers - npm Package Compare versions

Comparing version 0.0.25 to 0.0.28

dist/src/enhancers/authorizedFetch.d.ts

2

dist/src/enhancers/withRetry.js

@@ -10,3 +10,3 @@ "use strict";

const withRetry = (fetch, options = { minTimeout: 10, retries: 3, factor: 5, onRetry: () => { } }) => (url, init) => {
return async_retry_1.default(async (_bail, attempt) => {
return (0, async_retry_1.default)(async (_bail, attempt) => {
const isRetry = attempt < (options.retries ?? 3);

@@ -13,0 +13,0 @@ const response = await fetch(url, init);

@@ -15,4 +15,4 @@ "use strict";

}
catch (err) {
throw new node_fetch_1.FetchError(err.message ?? 'fetch error', url.toString());
catch (error) {
throw new node_fetch_1.FetchError(error.message ?? 'fetch error', url.toString());
}

@@ -19,0 +19,0 @@ finally {

@@ -1,2 +0,2 @@

import type { RequestInfo, RequestInit, Response } from 'node-fetch';
import type { RequestInfo, RequestInit, Response, Request } from 'node-fetch';
export declare type Fetch = (url: RequestInfo, init?: RequestInit) => Promise<Response>;

@@ -9,1 +9,13 @@ export declare class FetchError extends Error {

}
export declare type EnhancedFetchRequestInit<T> = RequestInit & {
enhancers?: T;
};
export declare type EnhancedFetch<T> = (url: string | Request, init?: RequestInit & EnhancedFetchRequestInit<T>) => Promise<Response>;
export declare type FetchEnhancer<T1> = <T2 extends {}>(fetch: Fetch | EnhancedFetch<T2>, options?: T1) => EnhancedFetch<T1 & T2>;
export declare type FetchEnhancerWithMandatoryOptions<T1> = <T2 extends {}>(fetch: Fetch | EnhancedFetch<T2>, options: T1) => EnhancedFetch<T1 & T2>;
export declare class FetchAuthorizationError extends Error {
constructor(message: string, url: string | Request, requestInit: RequestInit);
status: number;
url: string;
requestInit: RequestInit;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FetchError = void 0;
exports.FetchAuthorizationError = exports.FetchError = void 0;
class FetchError extends Error {

@@ -16,2 +16,15 @@ message;

exports.FetchError = FetchError;
class FetchAuthorizationError extends Error {
constructor(message, url, requestInit) {
super(message);
Object.setPrototypeOf(this, FetchAuthorizationError.prototype);
this.url = url.toString();
this.requestInit = requestInit;
this.status = 403;
}
status;
url;
requestInit;
}
exports.FetchAuthorizationError = FetchAuthorizationError;
//# sourceMappingURL=types.js.map

@@ -8,4 +8,17 @@ "use strict";

testMatch: ['<rootDir>/tests/specs/**.spec.ts'],
globals: {
'ts-jest': {
tsconfig: {
target: 'ESNext',
lib: ['DOM', 'ESNext'],
skipLibCheck: true,
strictPropertyInitialization: false,
noUnusedLocals: false,
noUnusedParameters: false,
isolatedModules: true,
},
},
},
};
exports.default = config;
//# sourceMappingURL=jest.config.js.map

@@ -21,4 +21,4 @@ "use strict";

};
const enhancedFetch = withThrow_1.withThrow(withBasicAuth_1.withBasicAuth(withTimeout_1.withTimeout(withRetry_1.withRetry(node_fetch_1.default, retryOpts), timeoutOpts), basicAuthOpts));
const server = http_1.createServer((_, res) => {
const enhancedFetch = (0, withThrow_1.withThrow)((0, withBasicAuth_1.withBasicAuth)((0, withTimeout_1.withTimeout)((0, withRetry_1.withRetry)(node_fetch_1.default, retryOpts), timeoutOpts), basicAuthOpts));
const server = (0, http_1.createServer)((_, res) => {
res.writeHead(200);

@@ -25,0 +25,0 @@ res.end();

@@ -9,6 +9,6 @@ "use strict";

const withRetry_1 = require("../../src/enhancers/withRetry");
const retryFetch = withRetry_1.withRetry(node_fetch_1.default);
const retryFetch = (0, withRetry_1.withRetry)(node_fetch_1.default);
test('retries upon 500', async () => {
let i = 0;
const server = http_1.createServer((_, res) => {
const server = (0, http_1.createServer)((_, res) => {
if (i++ < 2) {

@@ -39,3 +39,3 @@ res.writeHead(500);

test('resolves on > MAX_RETRIES', async () => {
const server = http_1.createServer((_, res) => {
const server = (0, http_1.createServer)((_, res) => {
res.writeHead(500);

@@ -42,0 +42,0 @@ res.end();

@@ -26,4 +26,4 @@ "use strict";

test('throws error when fetch fails ', async () => {
const throwingFetch = withThrow_1.withThrow(node_fetch_1.default);
const server = http_1.createServer((_, res) => {
const throwingFetch = (0, withThrow_1.withThrow)(node_fetch_1.default);
const server = (0, http_1.createServer)((_, res) => {
res.writeHead(500);

@@ -30,0 +30,0 @@ res.end();

@@ -26,4 +26,4 @@ "use strict";

test('single request configuration - times out when server does not respond in time ', async () => {
const timeoutFetch = withTimeout_1.withTimeout(node_fetch_1.default, { requestTimeoutMs: 100 });
const server = http_1.createServer((_, res) => {
const timeoutFetch = (0, withTimeout_1.withTimeout)(node_fetch_1.default, { requestTimeoutMs: 100 });
const server = (0, http_1.createServer)((_, res) => {
setTimeout(() => {

@@ -53,4 +53,4 @@ res.writeHead(200);

test('global configuration - times out when server does not respond in time ', async () => {
const timeoutFetch = withTimeout_1.withTimeout(node_fetch_1.default, { requestTimeoutMs: 100 });
const server = http_1.createServer((_, res) => {
const timeoutFetch = (0, withTimeout_1.withTimeout)(node_fetch_1.default, { requestTimeoutMs: 100 });
const server = (0, http_1.createServer)((_, res) => {
setTimeout(() => {

@@ -57,0 +57,0 @@ res.writeHead(200);

{
"name": "@osskit/fetch-enhancers",
"version": "0.0.25",
"version": "0.0.28",
"repository": {

@@ -15,41 +15,41 @@ "url": "https://github.com/osskit/monitor"

},
"engines": {
"node": ">=16.0.0"
},
"devDependencies": {
"@types/async-retry": "^1.2.1",
"@types/jest": "^26.0.23",
"@types/async-retry": "^1.4.3",
"@types/jest": "^27.0.2",
"@types/lodash.clonedeep": "^4.5.6",
"@types/node": "^15.12.4",
"@types/node-fetch": "^2.5.10",
"@types/openid-client": "^3.7.0",
"@types/node": "^16.11.6",
"@types/node-fetch": "^2.5.12",
"@types/uuid": "^8.3.1",
"@typescript-eslint/eslint-plugin": "^4.28.0",
"eslint": "^7.29.0",
"eslint-config-noamokman": "^10.3.10",
"@typescript-eslint/eslint-plugin": "^5.2.0",
"eslint": "^8.1.0",
"eslint-config-noamokman": "^10.3.11",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-lodash": "^7.2.0",
"eslint-plugin-unicorn": "^33.0.1",
"husky": "^6.0.0",
"jest": "^27.0.5",
"lint-staged": "^11.0.0",
"node-fetch": "^2.6.1",
"npm-link-check": "^3.0.0",
"oauth2-mock-server": "^3.1.0",
"prettier": "^2.3.1",
"ts-jest": "^27.0.3",
"ts-node": "^10.0.0",
"tsc": "^1.20150623.0",
"tslint": "^6.1.2",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-jest": "^25.2.2",
"eslint-plugin-lodash": "^7.3.0",
"eslint-plugin-unicorn": "^37.0.1",
"husky": "^7.0.4",
"jest": "^27.3.1",
"lint-staged": "^11.2.6",
"node-fetch": "^2.6.6",
"npm-link-check": "^4.0.0",
"prettier": "^2.4.1",
"ts-jest": "^27.0.7",
"ts-node": "^10.4.0",
"tsc": "^2.0.3",
"tslint": "^6.1.3",
"tslint-clean-code": "^0.2.10",
"tslint-config-prettier": "^1.18.0",
"tslint-immutable": "^6.0.1",
"typescript": "^4.3.4",
"typescript": "^4.4.4",
"uuid": "^8.3.2"
},
"dependencies": {
"abort-controller": "^2.0.3",
"async-retry": "^1.2.3",
"abort-controller": "^3.0.0",
"async-retry": "^1.3.3",
"eslint": "^7.30.0",
"lodash.clonedeep": "^4.5.0",
"openid-client": "^4.6.0"
"lodash.clonedeep": "^4.5.0"
},

@@ -56,0 +56,0 @@ "lint-staged": {

@@ -16,4 +16,4 @@ import AbortController from 'abort-controller';

return await fetch(url, Object.assign({ signal: controller.signal }, init));
} catch (err) {
throw new FetchError(err.message ?? 'fetch error', url.toString());
} catch (error) {
throw new FetchError((error as any).message ?? 'fetch error', url.toString());
} finally {

@@ -20,0 +20,0 @@ clearTimeout(timeoutId);

@@ -1,2 +0,3 @@

import type { RequestInfo, RequestInit, Response } from 'node-fetch';
import type { RequestInfo, RequestInit, Response, Request } from 'node-fetch';
export type Fetch = (url: RequestInfo, init?: RequestInit) => Promise<Response>;

@@ -15,1 +16,32 @@

}
export type EnhancedFetchRequestInit<T> = RequestInit & {
enhancers?: T;
};
export type EnhancedFetch<T> = (
url: string | Request,
init?: RequestInit & EnhancedFetchRequestInit<T>,
) => Promise<Response>;
export type FetchEnhancer<T1> = <T2 extends {}>(
fetch: Fetch | EnhancedFetch<T2>,
options?: T1,
) => EnhancedFetch<T1 & T2>;
export type FetchEnhancerWithMandatoryOptions<T1> = <T2 extends {}>(
fetch: Fetch | EnhancedFetch<T2>,
options: T1,
) => EnhancedFetch<T1 & T2>;
export class FetchAuthorizationError extends Error {
constructor(message: string, url: string | Request, requestInit: RequestInit) {
super(message);
Object.setPrototypeOf(this, FetchAuthorizationError.prototype);
this.url = url.toString();
this.requestInit = requestInit;
this.status = 403;
}
status: number;
url: string;
requestInit: RequestInit;
}

@@ -8,4 +8,17 @@ import type { InitialOptionsTsJest } from 'ts-jest/dist/types';

testMatch: ['<rootDir>/tests/specs/**.spec.ts'],
globals: {
'ts-jest': {
tsconfig: {
target: 'ESNext',
lib: ['DOM', 'ESNext'],
skipLibCheck: true,
strictPropertyInitialization: false,
noUnusedLocals: false,
noUnusedParameters: false,
isolatedModules: true,
},
},
},
};
export default config;

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

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

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

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