Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@gravity-ui/axios-wrapper
Advanced tools
This library provides a convenient wrapper around Axios adding automatic cancelling of concurrent requests to its features.
npm install --save-dev @gravity-ui/axios-wrapper
The configuration of an axios
instance.
The configuration of requests collector is an object:
{
"collectErrors": 10,
"collectRequests": 10
}
Wrapper provides http-methods get
, head
, put
, post
, delete
.
Methods get
and head
have the signature (url, params, options)
; put
, post
, while the delete
method
has (url, data, params, options)
signature.
The params
argument stands for query string parameters while options
is a request settings.
Currently 4 request settings are supported:
concurrentId (string)
: optional request idcollectRequest (bool)
: optional flag, telling if the request should be logger (default true
)requestConfig (object)
: optional config with the custom request parametersheaders (object)
: optional object with custom request headers.timeout (number)
: optional request timeoutonDownloadProgress (function)
: optional callback for processing file download progressThe setDefaultHeader({name (string), value (string), methods (array)})
method allows to add a default
request header.
Arguments name
and value
are required, optional argument methods
specified all methods which get those
default headers (by default all methods will get those headers).
The setCSRFToken
method allows specifying CSRF-token, which will be added to all put
, post
and delete
requests.
Sometimes it is better to cancel the request in flight if its results are no longer needed. To make this
happen, one should pass to request's options
the concurrentId
id. When the next request with the same
concurrentId
occurs the previous request with that id will be cancelled.
One cancel a request manually as well by invoking the cancelRequest(concurrentId)
method.
It is possible to set up requests collection into the local storage using the collector
option. It stores
all requests and errors separately. The following apiInstance
will keep 10 last requests (both successful
and not) and 10 last erroneous requests.
const apiInstance = new API({
collector: {
collectErrors: 10,
collectRequests: 10
}
});
To obtain saved requests one have to invoke the getCollectedRequests
method which returns the object
{errors: [...], requests: [...]}
.
The suggested usage is to subclass the base AxiosWrapper
class:
export class API extends AxiosWrapper {
getProjects() {
return this.get('/projects');
}
getSensors({project, selectors}) {
return this.get(`/projects/${project}/sensors`, {selectors, pageSize: 200});
}
getNames({project, selectors}) {
return this.get(`/projects/${project}/sensors/names`, {selectors});
}
getLabels({project, names, selectors}) {
return this.get(`/projects/${project}/sensors/labels`, {names, selectors});
}
}
When the baseURL
parameter is passed into axios
config, all requested pathnames will be appended to it.
const apiInstance = new API({
config: {
baseURL: '/api/v2'
}
});
FAQs
Generic helper class for wrapping axios calls
The npm package @gravity-ui/axios-wrapper receives a total of 740 weekly downloads. As such, @gravity-ui/axios-wrapper popularity was classified as not popular.
We found that @gravity-ui/axios-wrapper demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.