UNPKG

znapi

Version:

Better TS/JS API for zeronet-conservancy (WIP)

161 lines (160 loc) 3.87 kB
; export class ZNAPIGeneric { callbacks = {}; setCallback(msg, cback) { this.callbacks[msg] = cback; } processCallback(cmd, message) { const cback = this.callbacks[cmd]; if (cback !== undefined) { cback(message); } } sendWithResp(message) { return new Promise((resolve, reject) => { this.send(message, (resp) => { if (resp.error !== undefined) { reject(new Error(resp.error)); } else { resolve(resp); } }); }); } ping() { return this.sendWithResp({ cmd: 'ping', params: {}, }); } getServerInfo() { return this.sendWithResp({ cmd: 'serverInfo', params: {}, }); } // TODO: type getSignerList() { return this.sendWithResp({ cmd: 'signerList', }); } getSiteList() { return this.sendWithResp({ cmd: 'siteList', }); } getSiteDetails(address) { return this.sendWithResp({ cmd: 'siteDetails', params: { address, }, }); } getSizeLimitRules() { return this.sendWithResp({ cmd: 'getSizeLimitRules', }); } requestPermission(permission) { return this.sendWithResp({ cmd: 'wrapperPermissionAdd', params: permission, }); } addPrivateSizeLimitRule(address, rule, value, priority) { return this.sendWithResp({ cmd: 'addPrivateSizeLimitRule', params: { address, rule, value, priority, }, }).then((r) => { return; }); } removePrivateSizeLimitRule(rule_id) { return this.sendWithResp({ cmd: 'removePrivateSizeLimitRule', params: { rule_id, }, }).then((r) => { return; }); } siteFavorite(address) { return this.sendWithResp({ cmd: 'siteFavorite', params: { address, }, }); } siteUnfavorite(address) { return this.sendWithResp({ cmd: 'siteUnfavorite', params: { address, }, }); } siteLimitsUnsubscribe(address) { return this.sendWithResp({ cmd: 'siteLimitsUnsubscribe', params: { address, }, }); } siteLimitsSubscribe(address, priority) { return this.sendWithResp({ cmd: 'siteLimitsSubscribe', params: { address, priority, }, }); } siteDiagnose(address) { return this.sendWithResp({ cmd: 'siteDiagnose', params: { address, }, }); } siteFixUserPermissions(address, content_path, user_addresses) { return this.sendWithResp({ cmd: 'siteFixUserPermissions', params: { address, content_path, user_addresses, }, }); } remoteConnectionList() { return this.sendWithResp({ cmd: 'remoteConnectionList', params: {}, }); } connectionSiteList(conn_id) { return this.sendWithResp({ cmd: 'connectionSiteList', params: { conn_id, }, }); } msgSubscribe(cback) { this.setCallback('newMessage', cback); return this.sendWithResp({ cmd: 'msgSubscribe', params: {}, }); } } ; ;