@uxland/fetch-client
Advanced tools
Comparing version 1.0.0-alpha.4 to 1.0.0-alpha.5
@@ -6,2 +6,15 @@ # Change Log | ||
# [1.0.0-alpha.5](https://github.com/uxland/uxland/compare/@uxland/fetch-client@1.0.0-alpha.4...@uxland/fetch-client@1.0.0-alpha.5) (2020-02-20) | ||
### Bug Fixes | ||
* reference build config + object-mapper jsdocs ([5b01902](https://github.com/uxland/uxland/commit/5b01902d900a4105f5a9d3f841ffe04bb7d3d984)) | ||
* update author in packages ([db99c3c](https://github.com/uxland/uxland/commit/db99c3c8c54fd0d62dfb0d7894e0e8b0962751b0)) | ||
* update eslint warnings and errors ([a82e1eb](https://github.com/uxland/uxland/commit/a82e1eb57b9c19b16639011f01449a5a14931e01)) | ||
# [1.0.0-alpha.4](https://github.com/uxland/uxland/compare/@uxland/fetch-client@1.0.0-alpha.3...@uxland/fetch-client@1.0.0-alpha.4) (2020-02-13) | ||
@@ -8,0 +21,0 @@ |
@@ -19,2 +19,15 @@ import { publish } from '@uxland/event-aggregator'; | ||
let defaultQueryParams; | ||
const serializeValue = function (value) { | ||
return value === null || typeof value === 'undefined' ? '' : encodeURIComponent(value); | ||
}; | ||
const toQueryParams = function (queryParams, prefix) { | ||
const str = []; | ||
for (const p in queryParams) { | ||
if (queryParams.hasOwnProperty(p)) { | ||
const k = prefix ? prefix + '[' + p + ']' : p, v = queryParams[p]; | ||
str.push(v !== null && typeof v === 'object' ? serialize(v, k) : encodeURIComponent(k) + '=' + serializeValue(v)); | ||
} | ||
} | ||
return str.join('&'); | ||
}; | ||
const getRequestUrl = function (baseUrl, url, queryParams = {}) { | ||
@@ -24,4 +37,4 @@ if (ABSOLUTE_URL_REGEX.test(url)) { | ||
} | ||
let resultingUrl = (baseUrl || '') + url; | ||
let params = toQueryParams(Object.assign({}, defaultQueryParams, queryParams)); | ||
const resultingUrl = (baseUrl || '') + url; | ||
const params = toQueryParams(Object.assign({}, defaultQueryParams, queryParams)); | ||
return params ? resultingUrl + '?' + params : resultingUrl; | ||
@@ -32,7 +45,7 @@ }; | ||
config = config || configuration; | ||
let headers = Object.assign({}, config.headers, requestInit.headers || {}); | ||
const headers = Object.assign({}, config.headers, requestInit.headers || {}); | ||
return Object.assign({}, config, requestInit, { headers: headers }); | ||
}; | ||
const getCode = (r) => { | ||
let code = r ? r.result || r.RESULT : null; | ||
const code = r ? r.result || r.RESULT : null; | ||
if (code) { | ||
@@ -49,11 +62,11 @@ try { | ||
const isUnauthorizedResponse = (r) => { | ||
let code = getCode(r); | ||
const code = getCode(r); | ||
return code && code == 401; | ||
}; | ||
const isInvalidRequest = (r) => { | ||
let code = getCode(r); | ||
const code = getCode(r); | ||
return code && code >= 400; | ||
}; | ||
const isResetCredentialsResponse = (r) => { | ||
let code = getCode(r); | ||
const code = getCode(r); | ||
return code && code == 402; | ||
@@ -92,3 +105,3 @@ }; | ||
export const handleErrors = async (response) => { | ||
let microTask = () => new Promise(resolve => resolve()); | ||
const microTask = () => new Promise(resolve => resolve()); | ||
if (!response.ok) { | ||
@@ -119,15 +132,2 @@ let error; | ||
}; | ||
const serializeValue = function (value) { | ||
return value === null || typeof value === 'undefined' ? '' : encodeURIComponent(value); | ||
}; | ||
const toQueryParams = function (queryParams, prefix) { | ||
let str = [], p; | ||
for (p in queryParams) { | ||
if (queryParams.hasOwnProperty(p)) { | ||
let k = prefix ? prefix + '[' + p + ']' : p, v = queryParams[p]; | ||
str.push(v !== null && typeof v === 'object' ? serialize(v, k) : encodeURIComponent(k) + '=' + serializeValue(v)); | ||
} | ||
} | ||
return str.join('&'); | ||
}; | ||
export const configure = (config) => { | ||
@@ -150,3 +150,3 @@ Object.assign(configuration, config); | ||
export const withSapClientParam = (sapClient) => { | ||
let queryParams = {}; | ||
const queryParams = {}; | ||
queryParams[SAP_CLIENT_PARAM] = sapClient; | ||
@@ -156,4 +156,4 @@ withQueryParams(queryParams); | ||
export const handleBapiret = (bapiRet) => { | ||
let arr = [].concat(bapiRet); | ||
let ret = arr[0]; | ||
const arr = [].concat(bapiRet); | ||
const ret = arr[0]; | ||
if (ret && ret.TYPE == BAPIRET_ERROR_CODE) | ||
@@ -160,0 +160,0 @@ throw new Error(ret.MESSAGE); |
@@ -13,3 +13,3 @@ export interface Configuration { | ||
statusText?: string; | ||
status?: number; | ||
status?: number | void; | ||
} | ||
@@ -16,0 +16,0 @@ export interface IFetchClient { |
@@ -21,2 +21,15 @@ "use strict"; | ||
let defaultQueryParams; | ||
const serializeValue = function (value) { | ||
return value === null || typeof value === 'undefined' ? '' : encodeURIComponent(value); | ||
}; | ||
const toQueryParams = function (queryParams, prefix) { | ||
const str = []; | ||
for (const p in queryParams) { | ||
if (queryParams.hasOwnProperty(p)) { | ||
const k = prefix ? prefix + '[' + p + ']' : p, v = queryParams[p]; | ||
str.push(v !== null && typeof v === 'object' ? serialize(v, k) : encodeURIComponent(k) + '=' + serializeValue(v)); | ||
} | ||
} | ||
return str.join('&'); | ||
}; | ||
const getRequestUrl = function (baseUrl, url, queryParams = {}) { | ||
@@ -26,4 +39,4 @@ if (ABSOLUTE_URL_REGEX.test(url)) { | ||
} | ||
let resultingUrl = (baseUrl || '') + url; | ||
let params = toQueryParams(Object.assign({}, defaultQueryParams, queryParams)); | ||
const resultingUrl = (baseUrl || '') + url; | ||
const params = toQueryParams(Object.assign({}, defaultQueryParams, queryParams)); | ||
return params ? resultingUrl + '?' + params : resultingUrl; | ||
@@ -34,7 +47,7 @@ }; | ||
config = config || configuration; | ||
let headers = Object.assign({}, config.headers, requestInit.headers || {}); | ||
const headers = Object.assign({}, config.headers, requestInit.headers || {}); | ||
return Object.assign({}, config, requestInit, { headers: headers }); | ||
}; | ||
const getCode = (r) => { | ||
let code = r ? r.result || r.RESULT : null; | ||
const code = r ? r.result || r.RESULT : null; | ||
if (code) { | ||
@@ -51,11 +64,11 @@ try { | ||
const isUnauthorizedResponse = (r) => { | ||
let code = getCode(r); | ||
const code = getCode(r); | ||
return code && code == 401; | ||
}; | ||
const isInvalidRequest = (r) => { | ||
let code = getCode(r); | ||
const code = getCode(r); | ||
return code && code >= 400; | ||
}; | ||
const isResetCredentialsResponse = (r) => { | ||
let code = getCode(r); | ||
const code = getCode(r); | ||
return code && code == 402; | ||
@@ -94,3 +107,3 @@ }; | ||
exports.handleErrors = async (response) => { | ||
let microTask = () => new Promise(resolve => resolve()); | ||
const microTask = () => new Promise(resolve => resolve()); | ||
if (!response.ok) { | ||
@@ -121,15 +134,2 @@ let error; | ||
}; | ||
const serializeValue = function (value) { | ||
return value === null || typeof value === 'undefined' ? '' : encodeURIComponent(value); | ||
}; | ||
const toQueryParams = function (queryParams, prefix) { | ||
let str = [], p; | ||
for (p in queryParams) { | ||
if (queryParams.hasOwnProperty(p)) { | ||
let k = prefix ? prefix + '[' + p + ']' : p, v = queryParams[p]; | ||
str.push(v !== null && typeof v === 'object' ? serialize(v, k) : encodeURIComponent(k) + '=' + serializeValue(v)); | ||
} | ||
} | ||
return str.join('&'); | ||
}; | ||
exports.configure = (config) => { | ||
@@ -152,3 +152,3 @@ Object.assign(configuration, config); | ||
exports.withSapClientParam = (sapClient) => { | ||
let queryParams = {}; | ||
const queryParams = {}; | ||
queryParams[SAP_CLIENT_PARAM] = sapClient; | ||
@@ -158,4 +158,4 @@ exports.withQueryParams(queryParams); | ||
exports.handleBapiret = (bapiRet) => { | ||
let arr = [].concat(bapiRet); | ||
let ret = arr[0]; | ||
const arr = [].concat(bapiRet); | ||
const ret = arr[0]; | ||
if (ret && ret.TYPE == BAPIRET_ERROR_CODE) | ||
@@ -162,0 +162,0 @@ throw new Error(ret.MESSAGE); |
{ | ||
"name": "@uxland/fetch-client", | ||
"version": "1.0.0-alpha.4", | ||
"version": "1.0.0-alpha.5", | ||
"description": "Fetch Client", | ||
"author": "Alex Vizcaino <avizcaino@uxland.es>", | ||
"author": "UXLand <dev@uxland.es>", | ||
"homepage": "https://github.com/uxland/uxland/tree/master/packages/fetch-client#readme", | ||
"license": "ISC", | ||
"main": "src/index.ts", | ||
"license": "MIT", | ||
"main": "lib/index", | ||
"module": "es/index.js", | ||
"types": "lib/index.d.ts", | ||
"directories": { | ||
"lib": "lib", | ||
"test": "test" | ||
}, | ||
"files": [ | ||
"src", | ||
"lib", | ||
"es", | ||
"dist", | ||
"README.md", | ||
@@ -31,13 +27,12 @@ "package.json" | ||
"scripts": { | ||
"build:es": "tsc -p tsconfig.build.json --outDir es", | ||
"build:cjs": "tsc -p tsconfig.build.json --outDir lib --module commonjs --declaration", | ||
"build": "yarn build:es && yarn build:cjs", | ||
"build:test": "echo nok > .buildstatus && yarn type-check && echo ok > .buildstatus", | ||
"build:es": "tsc -p tsconfig.json --outDir es --module esnext --noEmit false", | ||
"build:cjs": "tsc -p tsconfig.json --outDir lib --noEmit false --declaration", | ||
"build:cjs:docs": "tsc -p tsconfig.json --outDir tmp --noEmit false --declaration --removeComments false", | ||
"build:umd": "cross-env NODE_ENV=development rollup -c -o dist/index.js", | ||
"build:umd:min": "cross-env NODE_ENV=production rollup -c -o dist/index.min.js", | ||
"build:clean": "rimraf es lib dist tmp tsconfig.tsbuildinfo", | ||
"build": "yarn build:clean && npm-run-all --parallel build:es build:cjs && npm-run-all --parallel build:umd build:umd:min", | ||
"prebuild": "echo nok > .buildstatus", | ||
"postbuild": "echo ok > .buildstatus", | ||
"readme:coverage": "node_modules/.bin/jest-badges-readme", | ||
"semantic-release": "semantic-release", | ||
"semantic-release:dry-run": "semantic-release --dry-run", | ||
"semantic-release:local": "yarn dist && semantic-release --no-ci --debug", | ||
"postsemantic-release:local": "git checkout -- package*", | ||
"tdd": "jest --watch --collect-coverage", | ||
@@ -51,4 +46,3 @@ "tdd:benchmark": "jest --watch test/unit/benchmark.spec.ts --collect-coverage=false --testPathIgnorePatterns []", | ||
"test": "yarn test:unit", | ||
"type-check": "tsc --noEmit", | ||
"type-check:watch": "yarn type-check -- --watch" | ||
"jsdoc": "yarn build:cjs:docs && rimraf docs && jsdoc -r ./tmp -c jsdoc.conf.js && rimraf tmp" | ||
}, | ||
@@ -60,16 +54,24 @@ "bugs": { | ||
"@babel/plugin-proposal-optional-chaining": "^7.8.3", | ||
"@babel/preset-env": "^7.8.4", | ||
"@olavoparno/jest-badges-readme": "^1.4.0", | ||
"@types/jest": "^25.1.0", | ||
"@types/ramda": "^0.26.41", | ||
"cross-env": "^7.0.0", | ||
"cucumber": "^6.0.5", | ||
"jest": "^25.1.0", | ||
"jsdom": "^16.1.0", | ||
"jest-cucumber": "^2.0.11", | ||
"jsdoc": "^3.6.3", | ||
"mutation-observer": "^1.0.3", | ||
"npm-run-all": "^4.1.5", | ||
"raf": "^3.4.1", | ||
"semantic-release": "^17.0.0", | ||
"ts-jest": "^25.0.0", | ||
"rollup": "^1.31.1", | ||
"rollup-plugin-babel": "^4.3.3", | ||
"rollup-plugin-uglify": "^6.0.4", | ||
"ts-jest": "^25.2.0", | ||
"typescript": "^3.7.5" | ||
}, | ||
"dependencies": { | ||
"@uxland/event-aggregator": "^1.0.0-alpha.4" | ||
"@uxland/event-aggregator": "^1.0.0-alpha.5" | ||
}, | ||
"gitHead": "6b7ab516707475823cb9d8851d02094deda9e79b" | ||
"gitHead": "b4dc4405142fa2cbe74aafc787983eac328d85a5" | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
36160
8
746
18
2
7