Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@cloudbase/adapter-interface
Advanced tools
Readme
tcb-js-sdk适配器接口,各平台适配器按照此接口规范进行开发。
npm i @cloudbase/adapter-interface -S
import {
AbstractSDKRequest,
IRequestOptions,
IUploadRequestOptions,
StorageInterface,
WebSocketInterface,
WebSocketContructor,
SDKAdapterInterface,
StorageType,
formatUrl
} from '@cloudbase/adapter-interface';
// isMatch函数判断当前平台是否匹配
function isMatch(): boolean {
// ...
return true;
}
// Request类为平台特有的网络请求,必须实现post/upload/download三个public接口
export class Request extends AbstractSDKRequest {
// 实现post接口
public post(options: IRequestOptions) {
return new Promise(resolve=>{
// ...
resolve();
})
}
// 实现upload接口
public upload(options: IUploadRequestOptions) {
return new Promise(resolve=>{
// ...
resolve();
})
}
// 实现download接口
public download(options: IRequestOptions) {
return new Promise(resolve=>{
// ...
resolve();
})
}
}
// Storage为平台特有的本地存储,必须实现setItem/getItem/removeItem/clear四个接口
export const Storage: StorageInterface = {
setItem(key: string, value: any) {
// ...
},
getItem(key: string): any {
// ...
},
removeItem(key: string) {
// ...
},
clear() {
// ...
}
};
// WebSocket为平台特有的WebSocket,与HTML5标准规范一致
export class WebSocket {
constructor(url: string, options: object = {}) {
const socketTask: WebSocketInterface = {
set onopen(cb) {
// ...
},
set onmessage(cb) {
// ...
},
set onclose(cb) {
// ...
},
set onerror(cb) {
// ...
},
send: (data) => {
// ...
},
close: (code? : number, reason? : string) => {
// ...
},
get readyState() {
// ...
return readyState;
},
CONNECTING: 0,
OPEN: 1,
CLOSING: 2,
CLOSED: 3
};
return socketTask;
}
}
// genAdapter函数创建adapter实体
function genAdapter() {
const adapter: SDKAdapterInterface = {
// root对象为全局根对象,没有则填空对象{}
root: window,
reqClass: Request,
wsClass: WebSocket as WebSocketContructor,
localStorage: Storage,
// 首先缓存存放策略,建议始终保持localstorage
primaryStorage: StorageType.local,
// sessionStorage为可选项,如果平台不支持可不填
sessionStorage: sessionStorage
};
return adapter;
}
// 三者缺一不可
const adapter = {
genAdapter,
isMatch,
// runtime为标记平台唯一性的说明
runtime: 'wx_mp'
};
export default adapter;
FAQs
cloudbase javascript sdk adapter interface
The npm package @cloudbase/adapter-interface receives a total of 324 weekly downloads. As such, @cloudbase/adapter-interface popularity was classified as not popular.
We found that @cloudbase/adapter-interface demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 10 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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.