xbyorange / mercury-api Goto Github PK
View Code? Open in Web Editor NEWMercury REST API origin
License: Apache License 2.0
Mercury REST API origin
License: Apache License 2.0
It is desirable to avoid the coexistence of different versions of the library in the same application.
When this happens, the apis
methods, used to configure all origins at a time, are only working on origins related to one of the multiple versions.
When different origins depend of different versions of this library, or an application defines a version different to the origins, this bug will occur.
To avoid this, it is desirable that this library executes a check in the initialization, ensuring that no other versions of it has been loaded previously. In that case, an error trace could be printed into the console, warning the developer about the fact.
As reported by Sonar, there is a bug in the "events" unit tests. It should be fixed to ensure that unit tests are working properly, and to make Sonar analysis pass.
Sonar reported a code smell in the test/events.spec.js file, at line 186:
Add the "let", "const" or "var" keyword to this declaration of "anyCalled" to make it explicit.
Possible scenario:
When you have two requests, you need to wait for the first request is resolved for can start the second. It should cancel a pending request if you leave a page before the request has been completed. For example:
You're in the Product page, there's a pending request and you go to user page. Actually, if you leave the product page, the request is kept and the user request doesn't execute until that product request would be completed.
I think we can implement the Cancel feature to avoid this behavior. So, we could manage more efficiently the requests in our application.
FYI: Axios' cancellation
Describe the bug
When having an error response, such as 400, 401 or 500, the error received in the catch, or in the component, has only the response body.
To Reproduce
In this selector for example
export const mySuperSelector = new Selector(
{
source: myAwesomeOrigin,
query: query => query,
catch: e => {
// e is only response body error, and you can't access to status or other properties
return false;
}
},
data => data,
false
);
Expected behavior
You should be able to access full response error object.
When you have to configure many origins at a time with the same value (a very common scenario for "baseUrl", or authentication headers, for example), you have to import all desired origins and iterate over all calling to its "config" method.
This is really annoying because for each origin you use, you have to add the new dependency to your "configurator" piece, and you have to repeat this pattern in every applications.
It would be very useful to export a method for configuring or cleaning groups of Api
instances at a time. (Maybe a system based on tags will be very flexible to allow configuring or cleaning only certain subgroups).
A proposal:
import { Api } from "@xbyorange/mercury-api";
export const fooCollection = new Api("/foo-url", {
tags: ["xbyorange-api", "need-auth"]
})
export const fooPublicCollection = new Api("/foo-public-url", {
tags: ["xbyorange-api"]
})
export const fooExternalApi = new Api("/foo-url", {
tags: ["external-api"]
})
Now, you can configure each api url separately:
import { apis } from "@xbyorange/mercury-api"
apis.config("xbyorange-api", {
baseUrl: "https://foo-url/api"
})
apis.config("external-api", {
baseUrl: "https://foo-external-domain"
})
To configure authentication:
import { apis } from "@xbyorange/mercury-api"
export const setAuth = token => {
apis.setHeaders("need-auth", {
"Authorization": `Bearer ${token}`
})
}
Migrate library from gitlab private repository and publish it into public NPM registry
Currently, when passing an array to a query string parameter it is always stringified as a list separated by commas.
It is desirable that this behavior can be configured to use another array formats, such as in the query-string npm package
For doing this, a new configuration option called queryStringArrayFormat
could be added:
import { Api } from "@xbyorange/mercury-api";
const myApi = new Api("/foo-url", {
queryStringArrayFormat: "none"
});
fooApi.query({
queryString: { foo: [1, 2, 3] }
}).read();
//=> 'foo=1,2'
Available formats could be the same than in the query-string npm package:
//=> 'foo[]=1&foo[]=2&foo[]=3'
//=> 'foo[0]=1&foo[1]=2&foo[3]=3'
//=> 'foo=1,2,3'
//=> 'foo=1&foo=2&foo=3'
It is desirable to upgrade the @xbyorange/mercury
dependency to latest released version.
I think could be a good idea to implement setters for all configurations and HTTP's request methods.
If we want to an API is prepare only to get providers list and create a new log:
import { Api } from "@xbyorange/mercury-api";
const catalog = new Api('/catalog-api')
catalog.only(['get', 'post'])
Also, we could apply this practice for tags:
import { Api } from "@xbyorange/mercury-api";
const catalog = new Api('/catalog-api')
catalog.tags(['external-api', 'internal-api'])
When an axios request fails, it is retried infinitely. This behavior has been reproduced with a 500 status code response.
A workaround is to set the retries
option to 0.
Axios should retry requests only number of times defined in the retries
option, and then fail.
After debugging the library code, it is maybe related with used versions of axios
and axios-retry
, or maybe with another dependency version causing an unexpected conflict. Options from mercury-api
are being passed to axios-retry
correctly.
It is needed to upgrade the currently used Axios dependency in order to avoid a potential security vulnerability.
Dependency is currently defined as ^0.18.0. It is required to upgrade it to version 0.19.0 or later.
Sonar has reported 5 code smells in the code of unit tests. https://sonarcloud.io/dashboard?id=xbyorange-mercury-api
It is desirable to fix this code smells and merge the code into the master branch (it is not necessary to release a new version of the library, as tests are not being published in the npm package)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.