Comparing version 1.0.1 to 1.0.2
@@ -84,3 +84,3 @@ /*! ***************************************************************************** | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, new Response(JSON.stringify({ error: 'Response via default fetch handler', to: url, options: options }), { status: 200 })]; | ||
case 0: return [4 /*yield*/, new Response(JSON.stringify(defaultFetchHandlerResponseBody(url, options)), defaultFetchHandlerResponseOptions)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -91,2 +91,12 @@ } | ||
} | ||
var defaultFetchHandlerResponseBody = function (url, options) { return ({ | ||
error: 'Default fetch handler response.', | ||
to: url, | ||
options: options | ||
}); }; | ||
var defaultFetchHandlerResponseOptions = { | ||
status: 418, | ||
statusText: '`fetch` missing in `window`' | ||
}; | ||
/** | ||
@@ -152,3 +162,3 @@ * Generic API client with default request | ||
* | ||
* @private | ||
* @protected | ||
* @param {string} method HTTP method (GET, PUT, POST, etc) | ||
@@ -315,3 +325,3 @@ * @param {string} url Url to make request | ||
export { JsonAPIClient, TextAPIClient, defaultFetch, GenericAPIClient, ResponseException, handleStatus, ResponseErrors }; | ||
export { JsonAPIClient, TextAPIClient, GenericAPIClient, ResponseException, handleStatus, ResponseErrors }; | ||
//# sourceMappingURL=kefetchup.es5.js.map |
@@ -90,3 +90,3 @@ (function (global, factory) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, new Response(JSON.stringify({ error: 'Response via default fetch handler', to: url, options: options }), { status: 200 })]; | ||
case 0: return [4 /*yield*/, new Response(JSON.stringify(defaultFetchHandlerResponseBody(url, options)), defaultFetchHandlerResponseOptions)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -97,2 +97,12 @@ } | ||
} | ||
var defaultFetchHandlerResponseBody = function (url, options) { return ({ | ||
error: 'Default fetch handler response.', | ||
to: url, | ||
options: options | ||
}); }; | ||
var defaultFetchHandlerResponseOptions = { | ||
status: 418, | ||
statusText: '`fetch` missing in `window`' | ||
}; | ||
/** | ||
@@ -158,3 +168,3 @@ * Generic API client with default request | ||
* | ||
* @private | ||
* @protected | ||
* @param {string} method HTTP method (GET, PUT, POST, etc) | ||
@@ -322,3 +332,2 @@ * @param {string} url Url to make request | ||
exports.TextAPIClient = TextAPIClient; | ||
exports.defaultFetch = defaultFetch; | ||
exports.GenericAPIClient = GenericAPIClient; | ||
@@ -325,0 +334,0 @@ exports.ResponseException = ResponseException; |
@@ -62,22 +62,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var default_fetch_1 = require("./default-fetch"); | ||
/** | ||
* Default fetch handler | ||
* | ||
* @export | ||
* @param {string} url | ||
* @param {RequestInit} [options] | ||
* @returns {Promise<Response>} | ||
*/ | ||
function defaultFetch(url, options) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, new Response(JSON.stringify({ error: 'Response via default fetch handler', to: url, options: options }), { status: 200 })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
} | ||
exports.defaultFetch = defaultFetch; | ||
/** | ||
* Generic API client with default request | ||
@@ -94,3 +76,3 @@ * | ||
var defaultHandlers = { | ||
fetchHandler: window.fetch || defaultFetch, | ||
fetchHandler: window.fetch || default_fetch_1.defaultFetch, | ||
errorHandler: function (resp) { | ||
@@ -143,3 +125,3 @@ throw new ResponseException(handleStatus(resp.status), resp.status, resp); | ||
* | ||
* @private | ||
* @protected | ||
* @param {string} method HTTP method (GET, PUT, POST, etc) | ||
@@ -146,0 +128,0 @@ * @param {string} url Url to make request |
@@ -10,11 +10,2 @@ export declare type APIClientHandlers = { | ||
/** | ||
* Default fetch handler | ||
* | ||
* @export | ||
* @param {string} url | ||
* @param {RequestInit} [options] | ||
* @returns {Promise<Response>} | ||
*/ | ||
export declare function defaultFetch(url: string, options?: RequestInit): Promise<Response>; | ||
/** | ||
* Generic API client with default request | ||
@@ -43,3 +34,3 @@ * | ||
* | ||
* @private | ||
* @protected | ||
* @param {string} method HTTP method (GET, PUT, POST, etc) | ||
@@ -52,3 +43,3 @@ * @param {string} url Url to make request | ||
*/ | ||
private alias; | ||
protected alias(method: string, url: string, fetchConfig?: RequestInit, overrideDefaultConfig?: boolean): Promise<Response | any>; | ||
get(url: string, fetchConfig?: RequestInit, overrideDefaultConfig?: boolean): Promise<Response | any>; | ||
@@ -55,0 +46,0 @@ put(url: string, fetchConfig?: RequestInit, overrideDefaultConfig?: boolean): Promise<Response | any>; |
{ | ||
"name": "kefetchup", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Simple fetch client API to spice up your application", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -1,7 +0,6 @@ | ||
[![Build Status](https://travis-ci.org/KazanExpress/kefetchup.svg?branch=master)](https://travis-ci.org/KazanExpress/kefetchup) [![Coverage Status](https://coveralls.io/repos/github/KazanExpress/kefetchup/badge.svg?branch=master)](https://coveralls.io/github/KazanExpress/kefetchup?branch=master) [![npm](https://img.shields.io/npm/v/kefetchup.svg?style=flat)](https://www.npmjs.com/package/kefetchup) | ||
# KeFetchUp! | ||
[![Build Status](https://img.shields.io/travis/KazanExpress/kefetchup/master.svg?logo=travis)](https://travis-ci.org/KazanExpress/kefetchup) [![Coverage Status](https://coveralls.io/repos/github/KazanExpress/kefetchup/badge.svg?branch=master)](https://coveralls.io/github/KazanExpress/kefetchup?branch=master) [![npm](https://img.shields.io/npm/v/kefetchup.svg?style=flat)](https://www.npmjs.com/package/kefetchup) | ||
![npm bundle size (minified)](https://img.shields.io/bundlephobia/minzip/kefetchup.svg) ![dependencies (minified)](https://img.shields.io/badge/dependencies-none-yellow.svg) | ||
# KeFetchUp! | ||
Simple fetch client API to spice up your application | ||
> Simple fetch client API to spice up your application |
@@ -0,1 +1,3 @@ | ||
import { defaultFetch } from './default-fetch'; | ||
export type APIClientHandlers = { | ||
@@ -8,16 +10,3 @@ fetchHandler: (url: string, options?: RequestInit) => Promise<Response> | ||
type Optional<T> = { [key in keyof T]?: T[key] }; | ||
/** | ||
* Default fetch handler | ||
* | ||
* @export | ||
* @param {string} url | ||
* @param {RequestInit} [options] | ||
* @returns {Promise<Response>} | ||
*/ | ||
export async function defaultFetch(url: string, options?: RequestInit): Promise<Response> { | ||
return await new Response(JSON.stringify({ error: 'Response via default fetch handler', to: url, options }), { status: 200 }); | ||
} | ||
/** | ||
* Generic API client with default request | ||
@@ -72,3 +61,3 @@ * | ||
* | ||
* @private | ||
* @protected | ||
* @param {string} method HTTP method (GET, PUT, POST, etc) | ||
@@ -81,3 +70,3 @@ * @param {string} url Url to make request | ||
*/ | ||
private async alias(method: string, url: string, fetchConfig?: RequestInit, overrideDefaultConfig?: boolean): Promise<Response | any> { | ||
protected async alias(method: string, url: string, fetchConfig?: RequestInit, overrideDefaultConfig?: boolean): Promise<Response | any> { | ||
fetchConfig = fetchConfig || {}; | ||
@@ -84,0 +73,0 @@ fetchConfig.method = method; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
93931
23
1328
7