@uxland/fetch-client
Advanced tools
Comparing version 1.0.0-alpha.10 to 1.0.0-alpha.11
@@ -6,2 +6,14 @@ # Change Log | ||
# [1.0.0-alpha.11](https://github.com/uxland/uxland/compare/@uxland/fetch-client@1.0.0-alpha.10...@uxland/fetch-client@1.0.0-alpha.11) (2020-09-16) | ||
### Bug Fixes | ||
* centralize configs ([8d84721](https://github.com/uxland/uxland/commit/8d84721bcec875272f05b4269ad978f0606e934b)) | ||
* centralize test configs ([4599b48](https://github.com/uxland/uxland/commit/4599b488f82d5884bac6ee7dee33437c13bba054)) | ||
# [1.0.0-alpha.10](https://github.com/uxland/uxland/compare/@uxland/fetch-client@1.0.0-alpha.9...@uxland/fetch-client@1.0.0-alpha.10) (2020-03-02) | ||
@@ -8,0 +20,0 @@ |
@@ -1,3 +0,3 @@ | ||
// Fetch Client v1.0.0-alpha.9 | ||
// https://github.com/uxland/uxland/tree/master/packages/fetch-client#readme | ||
// undefined vundefined | ||
// undefined | ||
// (c) 2020-2020 UXLand | ||
@@ -88,2 +88,3 @@ // UXLand libraries may be freely distributed under the MIT license. | ||
}); | ||
exports.registerResponseHandler = exports.fetchClient = exports.ServiceBase = exports.handleBapiret = exports.withSapClientParam = exports.withQueryParams = exports.withBaseUrl = exports.removeHeader = exports.withHeaders = exports.configure = exports.handleErrors = exports.handleResponse = exports.INVALID_REQUEST_EVENT = exports.RESET_CREDENTIALS_EVENT = exports.INVALID_CREDENTIALS_EVENT = void 0; | ||
@@ -219,8 +220,4 @@ var event_aggregator_1 = require("@uxland/event-aggregator"); | ||
exports.handleErrors = | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee(response) { | ||
exports.handleErrors = /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(response) { | ||
var microTask, error, result; | ||
@@ -348,5 +345,3 @@ return regeneratorRuntime.wrap(function _callee$(_context) { | ||
var FetchClient = | ||
/*#__PURE__*/ | ||
function () { | ||
var FetchClient = /*#__PURE__*/function () { | ||
function FetchClient() { | ||
@@ -382,5 +377,3 @@ _classCallCheck(this, FetchClient); | ||
var ServiceBase = | ||
/*#__PURE__*/ | ||
function () { | ||
var ServiceBase = /*#__PURE__*/function () { | ||
function ServiceBase() { | ||
@@ -387,0 +380,0 @@ _classCallCheck(this, ServiceBase); |
@@ -1,1 +0,1 @@ | ||
!function(e){"function"==typeof define&&define.amd?define(e):e()}(function(){"use strict";function i(e){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function a(e,t,n,r,o,s,u){try{var i=e[s](u),a=i.value}catch(e){return void n(e)}i.done?t(a):Promise.resolve(a).then(r,o)}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function o(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}Object.defineProperty(exports,"__esModule",{value:!0});var s=require("@uxland/event-aggregator"),u="application/json",c=/^([a-z][a-z0-9+\-.]*:)?\/\//i;exports.INVALID_CREDENTIALS_EVENT="UXL-CLIENT:INVALID_CREDENTIALS_EVENT",exports.RESET_CREDENTIALS_EVENT="UXL-CLIENT:RESET_CREDENTIALS_EVENT",exports.INVALID_REQUEST_EVENT="UXL-CLIENT:INVALID_REQUEST_EVENT";function f(e,t,n){var r=2<arguments.length&&void 0!==n?n:{};if(c.test(t))return t;var o=(e||"")+t,s=function(e,t){var n,r=[];for(var o in e)if(e.hasOwnProperty(o)){var s=t?t+"["+o+"]":o,u=e[o];r.push(null!==u&&"object"===i(u)?serialize(u,s):encodeURIComponent(s)+"="+(null==(n=u)?"":encodeURIComponent(n)))}return r.join("&")}(Object.assign({},h,r));return s?o+"?"+s:o}function p(e){var t=e?e.result||e.RESULT:null;if(t)try{return parseInt(t)}catch(e){return null}return null}function E(e){return{status:p(e),statusText:e.text||e.TEXT}}var l,h,x={headers:{"Content-Type":u},credentials:"include",mode:"cors"},T=[];exports.handleResponse=function(e){return(t=e.headers.get("Content-Type"))&&~t.indexOf(u)?e.json().then(function(e){return T.reduce(function(e,t){return t(e)},e)}):e.text();var t},exports.handleErrors=function(){var i,t=(i=regeneratorRuntime.mark(function e(t){var n,r,o;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(n=function(){return new Promise(function(e){return e()})},t.ok){e.next=26;break}return e.prev=2,e.next=5,t.json();case 5:o=e.sent,r=Object.assign(Error(),o,{status:t.status,statusText:t.statusText}),e.next=12;break;case 9:e.prev=9,e.t0=e.catch(2),r=Object.assign(Error(),{status:t.status,statusText:t.statusText});case 12:if(401===t.status)return e.next=15,n();e.next=16;break;case 15:s.publish(exports.INVALID_CREDENTIALS_EVENT,r);case 16:if(402===t.status)return e.next=19,n();e.next=22;break;case 19:s.publish(exports.RESET_CREDENTIALS_EVENT,r),e.next=25;break;case 22:return e.next=24,n();case 24:s.publish(exports.INVALID_REQUEST_EVENT,r);case 25:throw r;case 26:return e.abrupt("return",t);case 27:case"end":return e.stop()}},e,null,[[2,9]])}),function(){var e=this,u=arguments;return new Promise(function(t,n){var r=i.apply(e,u);function o(e){a(r,t,n,o,s,"next",e)}function s(e){a(r,t,n,o,s,"throw",e)}o(void 0)})});return function(e){return t.apply(this,arguments)}}(),exports.configure=function(e){Object.assign(x,e)},exports.withHeaders=function(e){Object.assign(x.headers,e)},exports.removeHeader=function(e){x.headers[e]&&delete x.headers[e]},exports.withBaseUrl=function(e){l=e},exports.withQueryParams=function(e){h=e},exports.withSapClientParam=function(e){var t={};t["sap-client"]=e,exports.withQueryParams(t)},exports.handleBapiret=function(e){var t=[].concat(e)[0];if(t&&"E"==t.TYPE)throw Error(t.MESSAGE);return t?t.MESSAGE:""};var t=function(){function e(){n(this,e),this.handleBapiRet=exports.handleBapiret}function t(e,t,n){return r.apply(this,arguments)}var r;return o(e,[{key:"fetch",value:(r=function(e,t,n){return fetch(f(l,e,n),(s=Object.assign({},(o=(o=x)||x).headers,(r=(r=t)||{}).headers||{}),Object.assign({},o,r,{headers:s}))).then(function(e){return exports.handleErrors(e)}).then(function(e){return exports.handleResponse(e)});var r,o,s},t.toString=function(){return""+r},t)}]),e}();exports.ServiceBase=function(){function e(){n(this,e)}return o(e,[{key:"fetchClient",get:function(){return null==this._fetchClient&&(this._fetchClient=new t),this._fetchClient}}]),e}(),exports.fetchClient=new t,exports.registerResponseHandler=function(e){T.push(e)},exports.registerResponseHandler(function(e){if((t=p(e))&&401==t)throw s.publish(exports.INVALID_CREDENTIALS_EVENT,e),E(e);var t,n,r;if((n=p(e))&&402==n)throw s.publish(exports.RESET_CREDENTIALS_EVENT,e),E(e);if((r=p(e))&&400<=r)throw s.publish(exports.INVALID_REQUEST_EVENT,E(e)),E(e);return e})}); | ||
!function(e){"function"==typeof define&&define.amd?define(e):e()}(function(){"use strict";function i(e){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function u(e,t,r,n,o,s,a){try{var i=e[s](a),u=i.value}catch(e){return void r(e)}i.done?t(u):Promise.resolve(u).then(n,o)}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function o(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}Object.defineProperty(exports,"__esModule",{value:!0}),exports.registerResponseHandler=exports.fetchClient=exports.ServiceBase=exports.handleBapiret=exports.withSapClientParam=exports.withQueryParams=exports.withBaseUrl=exports.removeHeader=exports.withHeaders=exports.configure=exports.handleErrors=exports.handleResponse=exports.INVALID_REQUEST_EVENT=exports.RESET_CREDENTIALS_EVENT=exports.INVALID_CREDENTIALS_EVENT=void 0;var s=require("@uxland/event-aggregator"),a="application/json",c=/^([a-z][a-z0-9+\-.]*:)?\/\//i;exports.INVALID_CREDENTIALS_EVENT="UXL-CLIENT:INVALID_CREDENTIALS_EVENT",exports.RESET_CREDENTIALS_EVENT="UXL-CLIENT:RESET_CREDENTIALS_EVENT",exports.INVALID_REQUEST_EVENT="UXL-CLIENT:INVALID_REQUEST_EVENT";function p(e,t){var r,n,o,s,a=[];for(r in e){e.hasOwnProperty(r)&&(n=t?t+"["+r+"]":r,a.push(null!==(o=e[r])&&"object"===i(o)?serialize(o,n):encodeURIComponent(n)+"="+(null==(s=o)?"":encodeURIComponent(s))))}return a.join("&")}function E(e){var t=e?e.result||e.RESULT:null;if(t)try{return parseInt(t)}catch(e){return null}return null}function f(e){return{status:E(e),statusText:e.text||e.TEXT}}var l,h,x={headers:{"Content-Type":a},credentials:"include",mode:"cors"},T=[];exports.handleResponse=function(e){return(t=e.headers.get("Content-Type"))&&!!~t.indexOf(a)?e.json().then(function(e){return T.reduce(function(e,t){return t(e)},e)}):e.text();var t},exports.handleErrors=function(){var i,t=(i=regeneratorRuntime.mark(function e(t){var r,n,o;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r=function(){return new Promise(function(e){return e()})},t.ok){e.next=26;break}return e.prev=2,e.next=5,t.json();case 5:o=e.sent,n=Object.assign(Error(),o,{status:t.status,statusText:t.statusText}),e.next=12;break;case 9:e.prev=9,e.t0=e.catch(2),n=Object.assign(Error(),{status:t.status,statusText:t.statusText});case 12:if(401===t.status)return e.next=15,r();e.next=16;break;case 15:s.publish(exports.INVALID_CREDENTIALS_EVENT,n);case 16:if(402===t.status)return e.next=19,r();e.next=22;break;case 19:s.publish(exports.RESET_CREDENTIALS_EVENT,n),e.next=25;break;case 22:return e.next=24,r();case 24:s.publish(exports.INVALID_REQUEST_EVENT,n);case 25:throw n;case 26:return e.abrupt("return",t);case 27:case"end":return e.stop()}},e,null,[[2,9]])}),function(){var e=this,a=arguments;return new Promise(function(t,r){var n=i.apply(e,a);function o(e){u(n,t,r,o,s,"next",e)}function s(e){u(n,t,r,o,s,"throw",e)}o(void 0)})});return function(e){return t.apply(this,arguments)}}(),exports.configure=function(e){Object.assign(x,e)},exports.withHeaders=function(e){Object.assign(x.headers,e)},exports.removeHeader=function(e){x.headers[e]&&delete x.headers[e]},exports.withBaseUrl=function(e){l=e},exports.withQueryParams=function(e){h=e},exports.withSapClientParam=function(e){var t={};t["sap-client"]=e,exports.withQueryParams(t)},exports.handleBapiret=function(e){var t=[].concat(e)[0];if(t&&"E"==t.TYPE)throw Error(t.MESSAGE);return t?t.MESSAGE:""};var t=function(){function e(){r(this,e),this.handleBapiRet=exports.handleBapiret}function t(e,t,r){return n.apply(this,arguments)}var n;return o(e,[{key:"fetch",value:(n=function(e,t,r){return fetch(function(e,t,r){var n=2<arguments.length&&void 0!==r?r:{};if(c.test(t))return t;var o=(e||"")+t,s=p(Object.assign({},h,n));return s?o+"?"+s:o}(l,e,r),(s=Object.assign({},(o=(o=x)||x).headers,(n=(n=t)||{}).headers||{}),Object.assign({},o,n,{headers:s}))).then(function(e){return exports.handleErrors(e)}).then(function(e){return exports.handleResponse(e)});var n,o,s},t.toString=function(){return""+n},t)}]),e}();exports.ServiceBase=function(){function e(){r(this,e)}return o(e,[{key:"fetchClient",get:function(){return null==this._fetchClient&&(this._fetchClient=new t),this._fetchClient}}]),e}(),exports.fetchClient=new t,exports.registerResponseHandler=function(e){T.push(e)},exports.registerResponseHandler(function(e){if((t=E(e))&&401==t)throw s.publish(exports.INVALID_CREDENTIALS_EVENT,e),f(e);var t,r,n;if((r=E(e))&&402==r)throw s.publish(exports.RESET_CREDENTIALS_EVENT,e),f(e);if((n=E(e))&&400<=n)throw s.publish(exports.INVALID_REQUEST_EVENT,f(e)),f(e);return e})}); |
@@ -0,1 +1,24 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2020 UXLand | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to use, | ||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the | ||
* Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN | ||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH | ||
* THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
/** @namespace FetchClient */ | ||
import { publish } from '@uxland/event-aggregator'; | ||
@@ -2,0 +25,0 @@ const HEADER_CONTENT_TYPE = 'Content-Type'; |
@@ -25,3 +25,3 @@ /** @namespace FetchClient */ | ||
export declare const handleResponse: <T>(response: Response) => Promise<T>; | ||
export declare const handleErrors: (response: Response) => Promise<Response>; | ||
export declare const handleErrors: (response: Response) => Promise<Response | never>; | ||
export declare const configure: (config: Configuration) => void; | ||
@@ -28,0 +28,0 @@ export declare const withHeaders: (headers: any) => void; |
@@ -26,2 +26,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.registerResponseHandler = exports.fetchClient = exports.ServiceBase = exports.handleBapiret = exports.withSapClientParam = exports.withQueryParams = exports.withBaseUrl = exports.removeHeader = exports.withHeaders = exports.configure = exports.handleErrors = exports.handleResponse = exports.INVALID_REQUEST_EVENT = exports.RESET_CREDENTIALS_EVENT = exports.INVALID_CREDENTIALS_EVENT = void 0; | ||
const event_aggregator_1 = require("@uxland/event-aggregator"); | ||
@@ -28,0 +29,0 @@ const HEADER_CONTENT_TYPE = 'Content-Type'; |
{ | ||
"name": "@uxland/fetch-client", | ||
"version": "1.0.0-alpha.10", | ||
"version": "1.0.0-alpha.11", | ||
"description": "Fetch Client", | ||
@@ -29,3 +29,3 @@ "author": "UXLand <dev@uxland.es>", | ||
"build:cjs": "tsc -p tsconfig.json --outDir lib --noEmit false --declaration --removeComments false", | ||
"build:umd": "cross-env NODE_ENV=development rollup -c -o dist/index.js", | ||
"build:umd": "cross-env NODE_ENV=development rollup -c ../project-tools/build/rollup.config.js -o dist/index.js", | ||
"build:umd:min": "cross-env NODE_ENV=production rollup -c -o dist/index.min.js", | ||
@@ -58,3 +58,3 @@ "build:clean": "rimraf es lib dist tmp tsconfig.tsbuildinfo", | ||
"@olavoparno/jest-badges-readme": "^1.4.0", | ||
"@types/jest": "^25.1.0", | ||
"@types/jest": "^26.0.14", | ||
"@types/ramda": "^0.26.41", | ||
@@ -64,4 +64,4 @@ "cat": "^0.2.0", | ||
"cucumber": "^6.0.5", | ||
"jest": "^25.1.0", | ||
"jest-cucumber": "^2.0.11", | ||
"jest": "^26.4.2", | ||
"jest-cucumber": "^3.0.0", | ||
"jsdoc": "^3.6.3", | ||
@@ -74,9 +74,9 @@ "mutation-observer": "^1.0.3", | ||
"rollup-plugin-uglify": "^6.0.4", | ||
"ts-jest": "^25.2.0", | ||
"typescript": "^3.7.5" | ||
"ts-jest": "^26.3.0", | ||
"typescript": "^4.0.2" | ||
}, | ||
"dependencies": { | ||
"@uxland/event-aggregator": "^1.0.0-alpha.10" | ||
"@uxland/event-aggregator": "^1.0.0-alpha.11" | ||
}, | ||
"gitHead": "12f22864b817112c994cb22f00a35deab29b9884" | ||
"gitHead": "f9be00ef91d21621d175cb2fa270c60696f3347f" | ||
} |
@@ -5,3 +5,3 @@ # UXL Fetch Client [![npm version](https://badge.fury.io/js/%40uxland%2Ffetch-client.svg)](https://badge.fury.io/js/%40uxland%2Ffetch-client) | ||
| ----------------------------------------------- | --------------------------------------------- | ----------------------------------------- | ------------------------------------------- | ----------------------------------- | | ||
| ![BuildStatus](https://img.shields.io/badge/Build-Passing-brightgreen.svg 'Building Status') | ![Statements](https://img.shields.io/badge/Coverage-30.83%25-red.svg 'Make me better!') | ![Branches](https://img.shields.io/badge/Coverage-0%25-red.svg 'Make me better!') | ![Functions](https://img.shields.io/badge/Coverage-6.67%25-red.svg 'Make me better!') | ![Lines](https://img.shields.io/badge/Coverage-32.46%25-red.svg 'Make me better!') | | ||
| ![BuildStatus](https://img.shields.io/badge/Build-Passing-brightgreen.svg "Building Status") | ![Statements](https://img.shields.io/badge/Coverage-30.83%25-red.svg "Make me better!") | ![Branches](https://img.shields.io/badge/Coverage-0%25-red.svg "Make me better!") | ![Functions](https://img.shields.io/badge/Coverage-6.67%25-red.svg "Make me better!") | ![Lines](https://img.shields.io/badge/Coverage-32.46%25-red.svg "Make me better!") | | ||
@@ -8,0 +8,0 @@ ## Installation |
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
41584
790