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

kefetchup

Package Overview
Dependencies
Maintainers
4
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kefetchup - npm Package Compare versions

Comparing version 1.1.3 to 1.2.0

0

dist/cjs/defaultFetch.js

@@ -0,0 +0,0 @@ "use strict";

12

dist/cjs/errors.js

@@ -16,8 +16,16 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var safeAppend = function (init) {
var strs = [];
for (var _i = 1; _i < arguments.length; _i++) {
strs[_i - 1] = arguments[_i];
}
return [init].concat(strs.filter(function (_) { return _ != null; }).map(String)).join('\n');
};
var ResponseError = /** @class */ (function (_super) {
__extends(ResponseError, _super);
function ResponseError(message, status, data) {
function ResponseError(message, status, data, request) {
var _this = _super.call(this, message) /* istanbul ignore next: because stupid typescript */ || this;
_this.status = status;
_this.data = data;
_this.request = request;
Object.setPrototypeOf(_this, ResponseError.prototype);

@@ -28,3 +36,3 @@ _this.name = 'ResponseError';

ResponseError.prototype.toString = function () {
return this.name + ': ' + this.message + (this.data != undefined ? '\n\n' + this.data : '');
return safeAppend(this.name + ': ' + this.message, this.data, this.request);
};

@@ -31,0 +39,0 @@ return ResponseError;

13

dist/cjs/genericClient.js

@@ -73,5 +73,9 @@ "use strict";

* @param e the error catched from the request promise
* @param url a url string that would be passed into the request function
* @param config a request config that would be passed into the request function
* @param request a function that performs a request (for retrying purposes)
* @memberof GenericAPIClient
*/
GenericAPIClient.prototype.$errorHandler = function (e) {
//@ts-ignore
GenericAPIClient.prototype.$errorHandler = function (e, url, config, request) {
if (e instanceof errors_1.ResponseError) {

@@ -82,3 +86,5 @@ throw e;

// Network error!
throw new errors_1.ResponseError('Unkown Error: ', errors_1.ResponseErrors.UnknownError, e);
throw new errors_1.ResponseError('Unkown Error: ', errors_1.ResponseErrors.UnknownError, e, {
url: url, config: config, request: request
});
}

@@ -100,3 +106,3 @@ };

.then(function (r) { return _this.$responseHandler(r); })
.catch(function (e) { return _this.$errorHandler(e); });
.catch(function (e) { return _this.$errorHandler(e, url, config, requestFunction); });
};

@@ -116,3 +122,2 @@ /**

if (fetchConfig === void 0) { fetchConfig = this.$baseClientConfig; }
fetchConfig = fetchConfig;
fetchConfig.method = method ? method.toUpperCase() : (fetchConfig.method || 'GET').toUpperCase();

@@ -119,0 +124,0 @@ return this.$request(url, fetchConfig, overrideDefaultConfig);

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { ResponseErrors } from './errors';

@@ -0,6 +1,8 @@

const safeAppend = (init, ...strs) => [init].concat(strs.filter(_ => _ != null).map(String)).join('\n');
export class ResponseError extends Error {
constructor(message, status, data) {
constructor(message, status, data, request) {
super(message) /* istanbul ignore next: because stupid typescript */;
this.status = status;
this.data = data;
this.request = request;
Object.setPrototypeOf(this, ResponseError.prototype);

@@ -10,3 +12,3 @@ this.name = 'ResponseError';

toString() {
return this.name + ': ' + this.message + (this.data != undefined ? '\n\n' + this.data : '');
return safeAppend(this.name + ': ' + this.message, this.data, this.request);
}

@@ -13,0 +15,0 @@ }

@@ -57,5 +57,9 @@ import { defaultFetch } from './defaultFetch';

* @param e the error catched from the request promise
* @param url a url string that would be passed into the request function
* @param config a request config that would be passed into the request function
* @param request a function that performs a request (for retrying purposes)
* @memberof GenericAPIClient
*/
$errorHandler(e) {
//@ts-ignore
$errorHandler(e, url, config, request) {
if (e instanceof ResponseError) {

@@ -66,3 +70,5 @@ throw e;

// Network error!
throw new ResponseError('Unkown Error: ', ResponseErrors.UnknownError, e);
throw new ResponseError('Unkown Error: ', ResponseErrors.UnknownError, e, {
url, config, request
});
}

@@ -83,3 +89,3 @@ }

.then(r => this.$responseHandler(r))
.catch(e => this.$errorHandler(e));
.catch(e => this.$errorHandler(e, url, config, requestFunction));
}

@@ -98,3 +104,2 @@ /**

return function (url, fetchConfig = this.$baseClientConfig, overrideDefaultConfig) {
fetchConfig = fetchConfig;
fetchConfig.method = method ? method.toUpperCase() : (fetchConfig.method || 'GET').toUpperCase();

@@ -101,0 +106,0 @@ return this.$request(url, fetchConfig, overrideDefaultConfig);

@@ -0,0 +0,0 @@ import { GenericAPIClient } from './genericClient';

@@ -0,0 +0,0 @@ /**

@@ -0,6 +1,8 @@

const safeAppend = (init, ...strs) => [init].concat(strs.filter(_ => _ != null).map(String)).join('\n');
class ResponseError extends Error {
constructor(message, status, data) {
constructor(message, status, data, request) {
super(message) /* istanbul ignore next: because stupid typescript */;
this.status = status;
this.data = data;
this.request = request;
Object.setPrototypeOf(this, ResponseError.prototype);

@@ -10,3 +12,3 @@ this.name = 'ResponseError';

toString() {
return this.name + ': ' + this.message + (this.data != undefined ? '\n\n' + this.data : '');
return safeAppend(this.name + ': ' + this.message, this.data, this.request);
}

@@ -120,5 +122,9 @@ }

* @param e the error catched from the request promise
* @param url a url string that would be passed into the request function
* @param config a request config that would be passed into the request function
* @param request a function that performs a request (for retrying purposes)
* @memberof GenericAPIClient
*/
$errorHandler(e) {
//@ts-ignore
$errorHandler(e, url, config, request) {
if (e instanceof ResponseError) {

@@ -129,3 +135,5 @@ throw e;

// Network error!
throw new ResponseError('Unkown Error: ', ResponseErrors.UnknownError, e);
throw new ResponseError('Unkown Error: ', ResponseErrors.UnknownError, e, {
url, config, request
});
}

@@ -146,3 +154,3 @@ }

.then(r => this.$responseHandler(r))
.catch(e => this.$errorHandler(e));
.catch(e => this.$errorHandler(e, url, config, requestFunction));
}

@@ -161,3 +169,2 @@ /**

return function (url, fetchConfig = this.$baseClientConfig, overrideDefaultConfig) {
fetchConfig = fetchConfig;
fetchConfig.method = method ? method.toUpperCase() : (fetchConfig.method || 'GET').toUpperCase();

@@ -164,0 +171,0 @@ return this.$request(url, fetchConfig, overrideDefaultConfig);

@@ -39,8 +39,16 @@ 'use strict';

var safeAppend = function (init) {
var strs = [];
for (var _i = 1; _i < arguments.length; _i++) {
strs[_i - 1] = arguments[_i];
}
return [init].concat(strs.filter(function (_) { return _ != null; }).map(String)).join('\n');
};
var ResponseError = /** @class */ (function (_super) {
__extends(ResponseError, _super);
function ResponseError(message, status, data) {
function ResponseError(message, status, data, request) {
var _this = _super.call(this, message) /* istanbul ignore next: because stupid typescript */ || this;
_this.status = status;
_this.data = data;
_this.request = request;
Object.setPrototypeOf(_this, ResponseError.prototype);

@@ -51,3 +59,3 @@ _this.name = 'ResponseError';

ResponseError.prototype.toString = function () {
return this.name + ': ' + this.message + (this.data != undefined ? '\n\n' + this.data : '');
return safeAppend(this.name + ': ' + this.message, this.data, this.request);
};

@@ -167,5 +175,9 @@ return ResponseError;

* @param e the error catched from the request promise
* @param url a url string that would be passed into the request function
* @param config a request config that would be passed into the request function
* @param request a function that performs a request (for retrying purposes)
* @memberof GenericAPIClient
*/
GenericAPIClient.prototype.$errorHandler = function (e) {
//@ts-ignore
GenericAPIClient.prototype.$errorHandler = function (e, url, config, request) {
if (e instanceof ResponseError) {

@@ -176,3 +188,5 @@ throw e;

// Network error!
throw new ResponseError('Unkown Error: ', exports.ResponseErrors.UnknownError, e);
throw new ResponseError('Unkown Error: ', exports.ResponseErrors.UnknownError, e, {
url: url, config: config, request: request
});
}

@@ -194,3 +208,3 @@ };

.then(function (r) { return _this.$responseHandler(r); })
.catch(function (e) { return _this.$errorHandler(e); });
.catch(function (e) { return _this.$errorHandler(e, url, config, requestFunction); });
};

@@ -210,3 +224,2 @@ /**

if (fetchConfig === void 0) { fetchConfig = this.$baseClientConfig; }
fetchConfig = fetchConfig;
fetchConfig.method = method ? method.toUpperCase() : (fetchConfig.method || 'GET').toUpperCase();

@@ -213,0 +226,0 @@ return this.$request(url, fetchConfig, overrideDefaultConfig);

@@ -38,8 +38,16 @@ var kefetchup = (function (exports) {

var safeAppend = function (init) {
var strs = [];
for (var _i = 1; _i < arguments.length; _i++) {
strs[_i - 1] = arguments[_i];
}
return [init].concat(strs.filter(function (_) { return _ != null; }).map(String)).join('\n');
};
var ResponseError = /** @class */ (function (_super) {
__extends(ResponseError, _super);
function ResponseError(message, status, data) {
function ResponseError(message, status, data, request) {
var _this = _super.call(this, message) /* istanbul ignore next: because stupid typescript */ || this;
_this.status = status;
_this.data = data;
_this.request = request;
Object.setPrototypeOf(_this, ResponseError.prototype);

@@ -50,3 +58,3 @@ _this.name = 'ResponseError';

ResponseError.prototype.toString = function () {
return this.name + ': ' + this.message + (this.data != undefined ? '\n\n' + this.data : '');
return safeAppend(this.name + ': ' + this.message, this.data, this.request);
};

@@ -166,5 +174,9 @@ return ResponseError;

* @param e the error catched from the request promise
* @param url a url string that would be passed into the request function
* @param config a request config that would be passed into the request function
* @param request a function that performs a request (for retrying purposes)
* @memberof GenericAPIClient
*/
GenericAPIClient.prototype.$errorHandler = function (e) {
//@ts-ignore
GenericAPIClient.prototype.$errorHandler = function (e, url, config, request) {
if (e instanceof ResponseError) {

@@ -175,3 +187,5 @@ throw e;

// Network error!
throw new ResponseError('Unkown Error: ', exports.ResponseErrors.UnknownError, e);
throw new ResponseError('Unkown Error: ', exports.ResponseErrors.UnknownError, e, {
url: url, config: config, request: request
});
}

@@ -193,3 +207,3 @@ };

.then(function (r) { return _this.$responseHandler(r); })
.catch(function (e) { return _this.$errorHandler(e); });
.catch(function (e) { return _this.$errorHandler(e, url, config, requestFunction); });
};

@@ -209,3 +223,2 @@ /**

if (fetchConfig === void 0) { fetchConfig = this.$baseClientConfig; }
fetchConfig = fetchConfig;
fetchConfig.method = method ? method.toUpperCase() : (fetchConfig.method || 'GET').toUpperCase();

@@ -212,0 +225,0 @@ return this.$request(url, fetchConfig, overrideDefaultConfig);

@@ -41,8 +41,16 @@ (function (global, factory) {

var safeAppend = function (init) {
var strs = [];
for (var _i = 1; _i < arguments.length; _i++) {
strs[_i - 1] = arguments[_i];
}
return [init].concat(strs.filter(function (_) { return _ != null; }).map(String)).join('\n');
};
var ResponseError = /** @class */ (function (_super) {
__extends(ResponseError, _super);
function ResponseError(message, status, data) {
function ResponseError(message, status, data, request) {
var _this = _super.call(this, message) /* istanbul ignore next: because stupid typescript */ || this;
_this.status = status;
_this.data = data;
_this.request = request;
Object.setPrototypeOf(_this, ResponseError.prototype);

@@ -53,3 +61,3 @@ _this.name = 'ResponseError';

ResponseError.prototype.toString = function () {
return this.name + ': ' + this.message + (this.data != undefined ? '\n\n' + this.data : '');
return safeAppend(this.name + ': ' + this.message, this.data, this.request);
};

@@ -169,5 +177,9 @@ return ResponseError;

* @param e the error catched from the request promise
* @param url a url string that would be passed into the request function
* @param config a request config that would be passed into the request function
* @param request a function that performs a request (for retrying purposes)
* @memberof GenericAPIClient
*/
GenericAPIClient.prototype.$errorHandler = function (e) {
//@ts-ignore
GenericAPIClient.prototype.$errorHandler = function (e, url, config, request) {
if (e instanceof ResponseError) {

@@ -178,3 +190,5 @@ throw e;

// Network error!
throw new ResponseError('Unkown Error: ', exports.ResponseErrors.UnknownError, e);
throw new ResponseError('Unkown Error: ', exports.ResponseErrors.UnknownError, e, {
url: url, config: config, request: request
});
}

@@ -196,3 +210,3 @@ };

.then(function (r) { return _this.$responseHandler(r); })
.catch(function (e) { return _this.$errorHandler(e); });
.catch(function (e) { return _this.$errorHandler(e, url, config, requestFunction); });
};

@@ -212,3 +226,2 @@ /**

if (fetchConfig === void 0) { fetchConfig = this.$baseClientConfig; }
fetchConfig = fetchConfig;
fetchConfig.method = method ? method.toUpperCase() : (fetchConfig.method || 'GET').toUpperCase();

@@ -215,0 +228,0 @@ return this.$request(url, fetchConfig, overrideDefaultConfig);

@@ -0,5 +1,15 @@

import { RequestFunction } from './genericClient';
export declare class ResponseError<T = Response> extends Error {
status: ResponseErrors;
data?: T | undefined;
constructor(message: string, status: ResponseErrors, data?: T | undefined);
request?: {
url: string;
config: RequestInit;
request: RequestFunction;
} | undefined;
constructor(message: string, status: ResponseErrors, data?: T | undefined, request?: {
url: string;
config: RequestInit;
request: RequestFunction;
} | undefined);
toString(): string;

@@ -6,0 +16,0 @@ }

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

export declare type RequestFunction = (url: string, config?: RequestInit) => Promise<Response>;
/**

@@ -41,5 +42,8 @@ * Generic API client with default request.

* @param e the error catched from the request promise
* @param url a url string that would be passed into the request function
* @param config a request config that would be passed into the request function
* @param request a function that performs a request (for retrying purposes)
* @memberof GenericAPIClient
*/
protected $errorHandler(e: any): any;
protected $errorHandler(e: any, url: string, config: RequestInit, request: RequestFunction): any;
/**

@@ -55,3 +59,3 @@ * A general request factory function.

*/
protected $requestFactory(url: string, config: RequestInit, requestFunction: (url: string, config?: RequestInit) => Promise<Response>): Promise<any>;
protected $requestFactory(url: string, config: RequestInit, requestFunction: RequestFunction): Promise<any>;
/**

@@ -58,0 +62,0 @@ * Request method alias factory.

{
"name": "kefetchup",
"version": "1.1.3",
"version": "1.2.0",
"description": "Simple fetch client API to spice up your application",

@@ -35,3 +35,3 @@ "keywords": [],

"coverage": "cat ./coverage/lcov.info | coveralls",
"preversion": "npm run test:prod && npm run build && (git add .) && git commit -m \"Update [dist]: fresh build\"",
"preversion": "npm run test:prod && npm run build && (git add .) && git commit -m \"Update dist - fresh build\"",
"patch": "npm version patch && npm publish && git push",

@@ -73,3 +73,3 @@ "minor": "npm version minor && npm publish && git push",

"devDependencies": {
"@commitlint/cli": "^7.5.2",
"@kazanexpress/frontend-commitlint": "^1.2.1",
"@types/jest": "^22.0.0",

@@ -76,0 +76,0 @@ "@types/node": "^10.0.3",

@@ -0,1 +1,5 @@

import { RequestFunction } from './genericClient';
const safeAppend = (init: string, ...strs: any[]) => [init].concat(strs.filter(_ => _ != null).map(String)).join('\n');
export class ResponseError<T = Response> extends Error {

@@ -5,3 +9,8 @@ constructor(

public status: ResponseErrors,
public data?: T
public data?: T,
public request?: {
url: string;
config: RequestInit;
request: RequestFunction;
}
) {

@@ -14,3 +23,3 @@ super(message)/* istanbul ignore next: because stupid typescript */;

toString() {
return this.name + ': ' + this.message + (this.data != undefined ? '\n\n' + this.data : '');
return safeAppend(this.name + ': ' + this.message, this.data, this.request);
}

@@ -17,0 +26,0 @@ }

import { defaultFetch } from './defaultFetch';
import { ResponseError, ResponseErrors } from './errors';
export type RequestFunction = (url: string, config?: RequestInit) => Promise<Response>;
/**

@@ -77,5 +79,9 @@ * Generic API client with default request.

* @param e the error catched from the request promise
* @param url a url string that would be passed into the request function
* @param config a request config that would be passed into the request function
* @param request a function that performs a request (for retrying purposes)
* @memberof GenericAPIClient
*/
protected $errorHandler(e): any {
//@ts-ignore
protected $errorHandler(e: any, url: string, config: RequestInit, request: RequestFunction): any {
if (e instanceof ResponseError) {

@@ -85,3 +91,5 @@ throw e;

// Network error!
throw new ResponseError('Unkown Error: ', ResponseErrors.UnknownError, e);
throw new ResponseError('Unkown Error: ', ResponseErrors.UnknownError, e, {
url, config, request
});
}

@@ -103,7 +111,7 @@ }

config: RequestInit,
requestFunction: (url: string, config?: RequestInit) => Promise<Response>
requestFunction: RequestFunction
): Promise<any> {
return requestFunction(url, config)
.then(r => this.$responseHandler(r))
.catch(e => this.$errorHandler(e));
.catch(e => this.$errorHandler(e, url, config, requestFunction));
}

@@ -127,3 +135,2 @@

): ReturnType<typeof this['$request']> {
fetchConfig = fetchConfig;
fetchConfig.method = method ? method.toUpperCase() : (fetchConfig.method || 'GET').toUpperCase();

@@ -130,0 +137,0 @@ return this.$request(url, fetchConfig, overrideDefaultConfig);

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