Giter Club home page Giter Club logo

mercury-api's People

Contributors

javierbrea avatar methadata avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

mercury-api's Issues

Avoid different versions coexistence

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.

Fix events unit test

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.

Add Cancel request feature

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.

123
LOL

FYI: Axios' cancellation

Can't manage full error object

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.

Configure all api instances at a time

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}`
  })
}

First public release

Migrate library from gitlab private repository and publish it into public NPM registry

Array format in query string parameters

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:

  • 'bracket': Serialize arrays using bracket representation:
//=> 'foo[]=1&foo[]=2&foo[]=3'
  • 'index': Serialize arrays using index representation:
//=> 'foo[0]=1&foo[1]=2&foo[3]=3'
  • 'comma': Serialize arrays by separating elements with comma (default behavior until next major version for maintaining retrocompatibility):
//=> 'foo=1,2,3'
  • 'none': Serialize arrays by using duplicate keys (default behavior in next major version):
//=> 'foo=1&foo=2&foo=3'

Implement setters for all configurations and HTTP's request methods

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'])

Infinite loop in Axios retries.

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.

Vulnerability in Axios dependency

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.