
Research
Active Supply Chain Attack Compromises @antv Packages on npm
Active npm supply chain attack compromises @antv packages in a fast-moving malicious publish wave tied to Mini Shai-Hulud.
@bbfe/data-provider
Advanced tools
基于Fetch规范的请求处理模块,提供对Request和Response对象的切面,具备请求合并的能力。
npm install @bbfe/data-provider
import DataProvider from 'data-provider';
import pathToRegexp from 'path-to-regexp';
import { isObject } from 'lodash';
let baseURL = 'http://mock.bbfe.group/mock/5a1e89e8d3ef9a75725992d3/snc/api/v1';
let id = 0;
const urlCompiler = (path, params) => {
let url = pathToRegexp.compile(path)(params);
return url;
};
let dataProvider = new DataProvider({
timeout: 5000,
requestIdResolver: function(options) {
return options.method === 'GET' ? JSON.stringify({ options }) : id++;
}
});
dataProvider.addRequestInterceptor(request => {
console.log('--------------request:', request);
return request;
});
dataProvider.addResponseInterceptor(response => {
console.log('--------------response:', response);
return response;
});
const request = async (url, method, body, query) => {
let options = {
url,
method,
baseURL: baseURL || '',
headers: {
'Content-Type': 'application/json'
}
};
if (body) {
options.body = isObject(body) ? JSON.stringify(body) : body;
}
if (query) {
options.query = query;
}
let res = await dataProvider.request(options);
if (res instanceof Error || res.status === 204) {
return res;
} else {
return res.clone().json();
}
};
async getAdmin({ path, params }) {
let url = urlCompiler(path, params);
let data = await request(url, 'GET');
return data;
}
getAdmin({ path: '/admins/:adminId', params: { adminId: 1 } })
.then(data => {
if (data instanceof Error) {
console.log(data.toString());
} else {
conselo.log(data);
}
});
new DataProvider(options)初始化DataProvider 实例需要的参数如下:
| 参数名 | 默认值 | 参数类型 | 说明 |
|---|---|---|---|
| timeout | 5000 | Number | 请求超时的时间 |
| requestIdResolver | () => id++ | Function | 用于产生请求id的策略函数,如果多个请求的id相等,则这几个请求会被合并。 |
dataProvider.request(options)DataProvider实例发起请求时需要的参数如下:
| 参数名 | 默认值 | 参数类型 | 说明 |
|---|---|---|---|
| url | -(必传) | string | 资源的URL(包含param) |
| headers | {'Accept':'application/json, text/plain, */*'} | object | 请求头,Accept已经默认加上了。 |
| method | 'GET' | string | 请求的方法 |
| baseURL | - | string | 提供了这个参数的话,他会被拼接到url的前面 |
| body | - | string/object | 请求数据,可以是Blob, BufferSource, FormData, URLSearchParams, 或 USVString对象(from mdn) |
| query | - | string/object | query参数,会被拼接到url的后面 |
| mode | 'cors' | string | 请求的模式, 比如 cors, no-cors, same-origin, 或 navigate。默认值应该为 cors。(from mdn) |
| credentials | 'include' | string | 想要在请求中使用的credentials:: omit, same-origin, 或 include。data-provider将其默认设为了include,即一直会带上cookie。如果不希望这样,需要自行将其设为omit。 |
| cache | 'default' | string | 请求中想要使用的cache mode。(from mdn) |
| redirect | 'follow' | string | 对重定向处理的模式: follow, error, or manual。(from mdn) |
| referrer | 'client' | string | 可选值no-referrer, client, 或一个 URL的 USVString 。(from mdn) |
| integrity | - | string | 包括请求的 subresource integrity 值(from mdn) |
除此之外,options也可以是一个Request对象,如果直接传入Request对象的话,data-provider会直接以这个Request对象发起请求。
FAQs
request manager with AOP interceptors
We found that @bbfe/data-provider demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 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
Active npm supply chain attack compromises @antv packages in a fast-moving malicious publish wave tied to Mini Shai-Hulud.

Security News
/Research
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.

Security News
TeamPCP and BreachForums are promoting a Shai-Hulud supply chain attack contest with a $1,000 prize for the biggest package compromise.