Socket
Socket
Sign inDemoInstall

xrpl-client

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xrpl-client - npm Package Compare versions

Comparing version 1.1.6 to 1.2.0

2

dist/browser.min.js

@@ -13,2 +13,2 @@ require=function e(t,n,r){function i(s,l){if(!n[s]){if(!t[s]){var u="function"==typeof require&&require;if(!l&&u)return u(s,!0);if(o)return o(s,!0);var a=new Error("Cannot find module '"+s+"'");throw a.code="MODULE_NOT_FOUND",a}var c=n[s]={exports:{}};t[s][0].call(c.exports,(function(e){return i(t[s][1][e]||e)}),c,c.exports,e,t,n,r)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;s<r.length;s++)i(r[s]);return i}({1:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0})},{}],2:[function(e,t,n){(function(n){(function(){"use strict";var r=e("object-assign");

*/
"use strict";var r=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,o=Object.prototype.propertyIsEnumerable;function s(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}t.exports=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map((function(e){return t[e]})).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach((function(e){r[e]=e})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(e){return!1}}()?Object.assign:function(e,t){for(var n,l,u=s(e),a=1;a<arguments.length;a++){for(var c in n=Object(arguments[a]))i.call(n,c)&&(u[c]=n[c]);if(r){l=r(n);for(var f=0;f<l.length;f++)o.call(n,l[f])&&(u[l[f]]=n[l[f]])}}return u}},{}],12:[function(e,t,n){var r,i,o=t.exports={};function s(){throw new Error("setTimeout has not been defined")}function l(){throw new Error("clearTimeout has not been defined")}function u(e){if(r===setTimeout)return setTimeout(e,0);if((r===s||!r)&&setTimeout)return r=setTimeout,setTimeout(e,0);try{return r(e,0)}catch(t){try{return r.call(null,e,0)}catch(t){return r.call(this,e,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:s}catch(e){r=s}try{i="function"==typeof clearTimeout?clearTimeout:l}catch(e){i=l}}();var a,c=[],f=!1,d=-1;function p(){f&&a&&(f=!1,a.length?c=a.concat(c):d=-1,c.length&&h())}function h(){if(!f){var e=u(p);f=!0;for(var t=c.length;t;){for(a=c,c=[];++d<t;)a&&a[d].run();d=-1,t=c.length}a=null,f=!1,function(e){if(i===clearTimeout)return clearTimeout(e);if((i===l||!i)&&clearTimeout)return i=clearTimeout,clearTimeout(e);try{i(e)}catch(t){try{return i.call(null,e)}catch(t){return i.call(this,e)}}}(e)}}function v(e,t){this.fun=e,this.array=t}function m(){}o.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];c.push(new v(e,t)),1!==c.length||f||u(h)},v.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=m,o.addListener=m,o.once=m,o.off=m,o.removeListener=m,o.removeAllListeners=m,o.emit=m,o.prependListener=m,o.prependOnceListener=m,o.listeners=function(e){return[]},o.binding=function(e){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(e){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},{}],13:[function(e,t,n){var r;if("object"==typeof globalThis)r=globalThis;else try{r=e("es5-ext/global")}catch(e){}finally{if(r||"undefined"==typeof window||(r=window),!r)throw new Error("Could not determine global this")}var i=r.WebSocket||r.MozWebSocket,o=e("./version");function s(e,t){return t?new i(e,t):new i(e)}i&&["CONNECTING","OPEN","CLOSING","CLOSED"].forEach((function(e){Object.defineProperty(s,e,{get:function(){return i[e]}})})),t.exports={w3cwebsocket:i?s:null,version:o}},{"./version":14,"es5-ext/global":8}],14:[function(e,t,n){t.exports=e("../package.json").version},{"../package.json":15}],15:[function(e,t,n){t.exports={name:"websocket",description:"Websocket Client & Server Library implementing the WebSocket protocol as specified in RFC 6455.",keywords:["websocket","websockets","socket","networking","comet","push","RFC-6455","realtime","server","client"],author:"Brian McKelvey <theturtle32@gmail.com> (https://github.com/theturtle32)",contributors:["Iรฑaki Baz Castillo <ibc@aliax.net> (http://dev.sipdoc.net)"],version:"1.0.34",repository:{type:"git",url:"https://github.com/theturtle32/WebSocket-Node.git"},homepage:"https://github.com/theturtle32/WebSocket-Node",engines:{node:">=4.0.0"},dependencies:{bufferutil:"^4.0.1",debug:"^2.2.0","es5-ext":"^0.10.50","typedarray-to-buffer":"^3.1.5","utf-8-validate":"^5.0.2",yaeti:"^0.0.6"},devDependencies:{"buffer-equal":"^1.0.0",gulp:"^4.0.2","gulp-jshint":"^2.0.4","jshint-stylish":"^2.2.1",jshint:"^2.0.0",tape:"^4.9.1"},config:{verbose:!1},scripts:{test:"tape test/unit/*.js",gulp:"gulp"},main:"index",directories:{lib:"./lib"},browser:"lib/browser.js",license:"Apache-2.0"}},{}],"xrpl-client":[function(e,t,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),i=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)},o=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{u(r.next(e))}catch(e){o(e)}}function l(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,l)}u((r=r.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(n,"__esModule",{value:!0}),n.XrplClient=void 0;const l=s(e("assert")),u=e("events"),a=e("debug"),c=e("websocket");i(e("./types"),n);const f=a.debug("xrplclient"),d=f.extend("warning"),p=f.extend("message"),h=f.extend("node");class v extends u.EventEmitter{constructor(e="wss://xrplcluster.com",t){let n;super(),this.connectBackoff=1e3/1.2,this.closed=!1,this.uplinkReady=!1,this.options={connectAttemptTimeoutSeconds:4,assumeOfflineAfterSeconds:20,maxConnectionAttempts:null},this.callId=0,this.pendingCalls=[],this.subscriptions=[],this.serverState={validatedLedgers:"",reserveBase:null,reserveInc:null,latency:[],fee:[],connectAttempts:0},t&&Object.assign(this.options,t);const r=()=>{var e;clearTimeout(n);const t=1e3*Number((null===(e=null==this?void 0:this.options)||void 0===e?void 0:e.assumeOfflineAfterSeconds)||20);n=setTimeout((()=>{var e;d("----- CONNECTION TIMEOUT, NO LEDER INFO RECEIVED FOR ",t,"SECONDS -----");try{null===(e=this.connection)||void 0===e||e.close()}catch(e){}}),t)};r(),this.endpoint=e.trim(),f("Initialized xrpld WebSocket Client"),this.on("ledger",(()=>{i(),r()}));const i=()=>{this.uplinkReady||(this.serverState.connectAttempts=0,h("Connection ready, fire events"),this.connectBackoff=1e3/1.2,this.uplinkReady=!0,this.emit("flush"),this.emit("state",this.getState()))},s=()=>{f("Connection opened :)"),this.send({id:"_WsClient_Internal_Subscription",command:"subscribe",streams:["ledger"]},{sendIfNotReady:!0,noReplayAfterReconnect:!0}),this.send({id:"_WsClient_Internal_ServerInfo@"+Number(new Date),command:"server_info"},{sendIfNotReady:!0,noReplayAfterReconnect:!0}).then((()=>{i()}))},u=e=>{var t;this.emit("close"),this.emit("state",this.getState()),this.connectBackoff=Math.min(Math.round(1.2*this.connectBackoff),1e3*Number((null===(t=this.options)||void 0===t?void 0:t.connectAttemptTimeoutSeconds)||4)),this.uplinkReady=!1,this.serverInfo=void 0,d("Upstream/Websocket closed",null==e?void 0:e.code,null==e?void 0:e.reason),O(),this.closed?f("Closed on purpose, not reconnecting"):(this.emit("retry"),d(`Not closed on purpose, reconnecting after ${this.connectBackoff}...`),setTimeout((()=>{this.emit("reconnect")}),this.connectBackoff))},a=e=>{var t,n;if(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.info){const t=e;this.serverInfo||h("Connected, server_info:",{pubkey_node:t.result.info.pubkey_node,build_version:t.result.info.build_version,complete_ledgers:t.result.info.complete_ledgers});const r=Number(new Date)-Number(String((null==e?void 0:e.id)||"").split("@").reverse()[0]);r&&(this.serverState.latency.push({moment:new Date,value:r}),this.serverState.latency.splice(0,this.serverState.latency.length-10));const i=1.2,o=t.result.info.load_factor*Number(null===(n=t.result.info.validated_ledger)||void 0===n?void 0:n.base_fee_xrp)*1e6*i;o&&(this.serverState.fee.push({moment:new Date,value:o}),this.serverState.fee.splice(0,this.serverState.fee.length-5)),this.serverInfo=t}},v=e=>{var t,n,r,i,o,s,l,u,a,c;if("_WsClient_Internal_Subscription"!==(null===(t=null==e?void 0:e.id)||void 0===t?void 0:t._Request))if(this.emit("message",e),"ledgerClosed"===(null==e?void 0:e.type))p("Async",e.type),Object.assign(this.serverState,{validatedLedgers:null==e?void 0:e.validated_ledgers,reserveBase:Number(null==e?void 0:e.reserve_base)/1e6||null,reserveInc:Number(null==e?void 0:e.reserve_inc)/1e6||null}),this.emit("ledger",e),this.send({id:"_WsClient_Internal_ServerInfo@"+Number(new Date),command:"server_info"});else if("path_find"===(null==e?void 0:e.type))p("Async",e.type),this.emit("path",e);else if("transaction"===(null==e?void 0:e.type))p("Async",e.type),this.emit("transaction",e);else if(null==e?void 0:e.validation_public_key)p("Async","validation"),this.emit("validation",e);else{let t;if(null===(n=null==e?void 0:e.id)||void 0===n?void 0:n._WsClient){const n=this.subscriptions.filter((t=>{var n;return t.id===(null===(n=null==e?void 0:e.id)||void 0===n?void 0:n._WsClient)}));n.length>0&&(t=n[0])}if("path_find"===(null===(r=null==t?void 0:t.request)||void 0===r?void 0:r.command))p("Async",null===(i=null==t?void 0:t.request)||void 0===i?void 0:i.command),this.emit("path",e);else if("subscribe"===(null===(o=null==t?void 0:t.request)||void 0===o?void 0:o.command)&&Array.isArray(null===(s=null==t?void 0:t.request)||void 0===s?void 0:s.streams)&&(null===(l=null==t?void 0:t.request)||void 0===l?void 0:l.streams.indexOf("ledger"))>-1)p("Async","subscription:ledger"),this.emit("ledger",e);else if(t)t.promiseCallables.resolve(Object.assign(e,{id:null===(u=null==e?void 0:e.id)||void 0===u?void 0:u._Request}));else{(null===(a=null==e?void 0:e.id)||void 0===a?void 0:a._Request)&&String(e.id._Request).match(/^_WsClient_Internal/)||p("Handle <UNKNOWN> Async Message",{internalId:null===(c=null==e?void 0:e.id)||void 0===c?void 0:c._WsClient,matchingSubscription:t,type:null==e?void 0:e.type,message:e})}}},m=e=>{var t,n,r,i,o,s;try{l.default("string"==typeof e.data,"Unexpected incoming WebSocket message data type");const u=JSON.parse(e.data);if(this.lastContact=new Date,null===(t=null==u?void 0:u.id)||void 0===t?void 0:t._WsClient){const e=this.subscriptions.filter((e=>{var t;return e.id===(null===(t=null==u?void 0:u.id)||void 0===t?void 0:t._WsClient)})),t=this.pendingCalls.filter((e=>{var t;return e.id===(null===(t=null==u?void 0:u.id)||void 0===t?void 0:t._WsClient)}));if(1===e.length)v(u);else if(1===t.length){const e="_WsClient_Internal_ServerInfo"===String((null===(i=null===(r=null===(n=t[0])||void 0===n?void 0:n.request)||void 0===r?void 0:r.id)||void 0===i?void 0:i._Request)||"").split("@")[0];Object.assign(u,{id:null===(o=null==u?void 0:u.id)||void 0===o?void 0:o._Request}),(null===(s=t[0].sendOptions)||void 0===s?void 0:s.timeoutSeconds)&&t[0].timeout&&clearTimeout(t[0].timeout),t[0].promiseCallables.resolve((null==u?void 0:u.result)||u),this.pendingCalls.splice(this.pendingCalls.indexOf(t[0]),1),e?a(u):f("ยป Pending Call Length",this.pendingCalls.length)}else v(u)}else v(u)}catch(e){d("Uplink response: parse error",e.message)}},g=e=>{d("Upstream/Websocket error")},y=e=>{var t;(null===(t=null==e?void 0:e.sendOptions)||void 0===t?void 0:t.timeoutSeconds)&&!(null==e?void 0:e.timeout)&&Object.assign(e,{timeout:setTimeout((()=>o(this,void 0,void 0,(function*(){var t;"_WsClient_Internal_CallResolved"===(yield Promise.race([e.promise,Promise.resolve("_WsClient_Internal_CallResolved")]))&&e.promiseCallables.reject(new Error(`Call timeout after ${null===(t=e.sendOptions)||void 0===t?void 0:t.timeoutSeconds} seconds`))}))),1e3*Number(e.sendOptions.timeoutSeconds))})},b=e=>{var t,n,r;"_WsClient_Internal_ServerInfo"!==String((null===(n=null===(t=null==e?void 0:e.request)||void 0===t?void 0:t.id)||void 0===n?void 0:n._Request)||"").split("@")[0]&&f(" > Process call",e.id,e.request.command);try{this.connection.send(JSON.stringify(e.request)),(null===(r=null==e?void 0:e.sendOptions)||void 0===r?void 0:r.timeoutStartsWhenOnline)&&(d("APPLY TIMEOUT ONLY AFTER GOING ONLINE"),y(e))}catch(e){d("Process (send to uplink) error",e.message)}},C=e=>{var t,n,r,i,o;"_WsClient_Internal_ServerInfo"!==String((null===(n=null===(t=null==e?void 0:e.request)||void 0===t?void 0:t.id)||void 0===n?void 0:n._Request)||"").split("@")[0]&&f(`Call ${e.id}: ${e.request.command}\n > `,this.uplinkReady?"Uplink ready, pass immediately":(null===(r=null==e?void 0:e.sendOptions)||void 0===r?void 0:r.sendIfNotReady)?"Uplink not flagged as ready yet, but `sendIfNotReady` = true, so go ahead":"Uplink not ready, wait for flush"),(null===(i=null==e?void 0:e.sendOptions)||void 0===i?void 0:i.timeoutStartsWhenOnline)||(d("APPLY TIMEOUT NO MATTER ONLINE/OFFLINE STATE"),y(e)),(this.uplinkReady||(null===(o=null==e?void 0:e.sendOptions)||void 0===o?void 0:o.sendIfNotReady))&&b(e)},w=()=>{f("Connected, flushing pending calls & subscriptions"),this.pendingCalls.forEach((e=>{b(e)})),this.subscriptions.forEach((e=>{b(e)}))},_=e=>{this.closed=!0,f("Closing connection"),O();try{this.connection.close()}catch(e){}clearTimeout(n),this.subscriptions.forEach((e=>{e.promiseCallables.reject(new Error("Class (connection) hard close requested"))})),this.pendingCalls.forEach((e=>{e.promiseCallables.reject(new Error("Class (connection) hard close requested"))})),this.off("__WsClient_call",C),this.off("__WsClient_close",_),this.off("flush",w),this.off("reconnect",E),e&&this.emit("error",e)},O=()=>{f("Cleanup"),this.connection.removeEventListener("open",s),this.connection.removeEventListener("message",m),this.connection.removeEventListener("error",g),this.connection.removeEventListener("close",u)},E=()=>{var e,t,n;try{this.connection.close()}catch(e){}f("Connecting",this.endpoint),this.serverState.connectAttempts++,this.options.maxConnectionAttempts&&Number((null===(e=this.options)||void 0===e?void 0:e.maxConnectionAttempts)||1)>1&&this.serverState.connectAttempts>Number((null===(t=this.options)||void 0===t?void 0:t.maxConnectionAttempts)||1)&&(h("Too many connection attempts",this.serverState.connectAttempts,null===(n=this.options)||void 0===n?void 0:n.maxConnectionAttempts),_(new Error("Max. connection attempts exceeded")));const r=new c.w3cwebsocket(this.endpoint);return setTimeout((()=>{r.readyState!==c.w3cwebsocket.OPEN&&r.close()}),1.2*this.connectBackoff-1),r.addEventListener("open",s),r.addEventListener("message",m),r.addEventListener("error",g),r.addEventListener("close",u),this.connection=r,r};this.on("__WsClient_call",C),this.on("__WsClient_close",_),this.on("flush",w),this.on("reconnect",E),this.connection=E()}ready(){return new Promise(((e,t)=>{const n=this.getState();n.online&&n.secLastContact&&n.secLastContact<10&&n.ledger.last?e(this):this.on("ledger",(()=>{e(this)}))}))}send(e,t={}){var n,r,i;l.default("object"==typeof e&&e,"`send()`: expecting object containing `command`"),l.default("string"==typeof e.command,"`command` must be typeof string"),this.callId++;const o={resolve:e=>{},reject:e=>{}},s=new Promise(((e,t)=>{Object.assign(o,{resolve:e,reject:t})})),u={id:this.callId,request:Object.assign(e,{id:{_WsClient:this.callId,_Request:null==e?void 0:e.id},command:e.command.toLowerCase().trim()}),promise:s,promiseCallables:o,sendOptions:t};if(this.closed)return o.reject(new Error("Client in closed state")),s;const a=("subscribe"===u.request.command||"unsubscribe"===u.request.command||"path_find"===u.request.command)&&!(null==t?void 0:t.noReplayAfterReconnect);return"unsubscribe"===(null===(n=u.request)||void 0===n?void 0:n.command)&&Array.isArray(null===(r=u.request)||void 0===r?void 0:r.streams)&&(null===(i=u.request)||void 0===i?void 0:i.streams.indexOf("ledger"))>-1&&(u.request.streams.splice(u.request.streams.indexOf("ledger"),1),0===u.request.streams.length&&0===Object.keys(u.request).filter((e=>"id"!==e&&"streams"!==e&&"command"!==e)).length)?Promise.reject(new Error("Unsubscribing from (just) the ledger stream is not allowed")):("_WsClient_Internal_ServerInfo"!==String((null==e?void 0:e.id)||"").split("@")[0]&&this[a?"subscriptions":"pendingCalls"].push(u),this.emit("__WsClient_call",u),s)}getState(){var e,t,n,r,i,o,s,l,u;const a=this.serverState.validatedLedgers.split(",").map((e=>{const t=e.split("-");return t.length>1?parseInt(t[1])-parseInt(t[0]):1})).reduce(((e,t)=>e+t),0);return{online:this.uplinkReady&&!this.closed&&this.connection.readyState===c.w3cwebsocket.OPEN,latencyMs:{last:this.serverState.latency.slice(-1).map((e=>e.value))[0]||null,avg:this.serverState.latency.map((e=>e.value)).reduce(((e,t)=>e+t),0)/this.serverState.latency.length||null,secAgo:Number(new Date)/1e3-this.serverState.latency.slice(-1).map((e=>Number(e.moment)/1e3))[0]||null},server:{version:(null===(n=null===(t=null===(e=this.serverInfo)||void 0===e?void 0:e.result)||void 0===t?void 0:t.info)||void 0===n?void 0:n.build_version)||"",uptime:(null===(o=null===(i=null===(r=this.serverInfo)||void 0===r?void 0:r.result)||void 0===i?void 0:i.info)||void 0===o?void 0:o.uptime)||0,publicKey:(null===(u=null===(l=null===(s=this.serverInfo)||void 0===s?void 0:s.result)||void 0===l?void 0:l.info)||void 0===u?void 0:u.pubkey_node)||"",uri:this.endpoint},ledger:{last:Number(this.serverState.validatedLedgers.split(",").reverse()[0].split("-").reverse()[0]),validated:this.serverState.validatedLedgers,count:""===this.serverState.validatedLedgers?0:a},fee:{last:this.serverState.fee.slice(-1).map((e=>e.value))[0]||null,avg:this.serverState.fee.map((e=>e.value)).reduce(((e,t)=>e+t),0)/this.serverState.fee.length||null,secAgo:Number(new Date)/1e3-this.serverState.fee.slice(-1).map((e=>Number(e.moment)/1e3))[0]||null},reserve:{base:this.serverState.reserveBase,owner:this.serverState.reserveInc},secLastContact:this.lastContact?Number(new Date)/1e3-Number(this.lastContact)/1e3:null}}close(){l.default(!this.closed,"Object already in closed state"),this.emit("__WsClient_close")}}n.XrplClient=v},{"./types":1,assert:2,debug:6,events:9,websocket:13}]},{},[]);
"use strict";var r=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,o=Object.prototype.propertyIsEnumerable;function s(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}t.exports=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map((function(e){return t[e]})).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach((function(e){r[e]=e})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(e){return!1}}()?Object.assign:function(e,t){for(var n,l,u=s(e),a=1;a<arguments.length;a++){for(var c in n=Object(arguments[a]))i.call(n,c)&&(u[c]=n[c]);if(r){l=r(n);for(var f=0;f<l.length;f++)o.call(n,l[f])&&(u[l[f]]=n[l[f]])}}return u}},{}],12:[function(e,t,n){var r,i,o=t.exports={};function s(){throw new Error("setTimeout has not been defined")}function l(){throw new Error("clearTimeout has not been defined")}function u(e){if(r===setTimeout)return setTimeout(e,0);if((r===s||!r)&&setTimeout)return r=setTimeout,setTimeout(e,0);try{return r(e,0)}catch(t){try{return r.call(null,e,0)}catch(t){return r.call(this,e,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:s}catch(e){r=s}try{i="function"==typeof clearTimeout?clearTimeout:l}catch(e){i=l}}();var a,c=[],f=!1,d=-1;function p(){f&&a&&(f=!1,a.length?c=a.concat(c):d=-1,c.length&&h())}function h(){if(!f){var e=u(p);f=!0;for(var t=c.length;t;){for(a=c,c=[];++d<t;)a&&a[d].run();d=-1,t=c.length}a=null,f=!1,function(e){if(i===clearTimeout)return clearTimeout(e);if((i===l||!i)&&clearTimeout)return i=clearTimeout,clearTimeout(e);try{i(e)}catch(t){try{return i.call(null,e)}catch(t){return i.call(this,e)}}}(e)}}function v(e,t){this.fun=e,this.array=t}function m(){}o.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];c.push(new v(e,t)),1!==c.length||f||u(h)},v.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=m,o.addListener=m,o.once=m,o.off=m,o.removeListener=m,o.removeAllListeners=m,o.emit=m,o.prependListener=m,o.prependOnceListener=m,o.listeners=function(e){return[]},o.binding=function(e){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(e){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},{}],13:[function(e,t,n){var r;if("object"==typeof globalThis)r=globalThis;else try{r=e("es5-ext/global")}catch(e){}finally{if(r||"undefined"==typeof window||(r=window),!r)throw new Error("Could not determine global this")}var i=r.WebSocket||r.MozWebSocket,o=e("./version");function s(e,t){return t?new i(e,t):new i(e)}i&&["CONNECTING","OPEN","CLOSING","CLOSED"].forEach((function(e){Object.defineProperty(s,e,{get:function(){return i[e]}})})),t.exports={w3cwebsocket:i?s:null,version:o}},{"./version":14,"es5-ext/global":8}],14:[function(e,t,n){t.exports=e("../package.json").version},{"../package.json":15}],15:[function(e,t,n){t.exports={name:"websocket",description:"Websocket Client & Server Library implementing the WebSocket protocol as specified in RFC 6455.",keywords:["websocket","websockets","socket","networking","comet","push","RFC-6455","realtime","server","client"],author:"Brian McKelvey <theturtle32@gmail.com> (https://github.com/theturtle32)",contributors:["Iรฑaki Baz Castillo <ibc@aliax.net> (http://dev.sipdoc.net)"],version:"1.0.34",repository:{type:"git",url:"https://github.com/theturtle32/WebSocket-Node.git"},homepage:"https://github.com/theturtle32/WebSocket-Node",engines:{node:">=4.0.0"},dependencies:{bufferutil:"^4.0.1",debug:"^2.2.0","es5-ext":"^0.10.50","typedarray-to-buffer":"^3.1.5","utf-8-validate":"^5.0.2",yaeti:"^0.0.6"},devDependencies:{"buffer-equal":"^1.0.0",gulp:"^4.0.2","gulp-jshint":"^2.0.4","jshint-stylish":"^2.2.1",jshint:"^2.0.0",tape:"^4.9.1"},config:{verbose:!1},scripts:{test:"tape test/unit/*.js",gulp:"gulp"},main:"index",directories:{lib:"./lib"},browser:"lib/browser.js",license:"Apache-2.0"}},{}],"xrpl-client":[function(e,t,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),i=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)},o=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{u(r.next(e))}catch(e){o(e)}}function l(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,l)}u((r=r.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(n,"__esModule",{value:!0}),n.XrplClient=void 0;const l=s(e("assert")),u=e("events"),a=e("debug"),c=e("websocket");i(e("./types"),n);const f=a.debug("xrplclient"),d=f.extend("warning"),p=f.extend("message"),h=f.extend("node");class v extends u.EventEmitter{constructor(e="wss://xrplcluster.com",t){let n;super(),this.eventBus=new u.EventEmitter,this.connectBackoff=1e3/1.2,this.closed=!1,this.uplinkReady=!1,this.options={connectAttemptTimeoutSeconds:4,assumeOfflineAfterSeconds:20,maxConnectionAttempts:null},this.callId=0,this.pendingCalls=[],this.subscriptions=[],this.serverState={validatedLedgers:"",reserveBase:null,reserveInc:null,latency:[],fee:[],connectAttempts:0},t&&Object.assign(this.options,t);const r=()=>{var e;clearTimeout(n);const t=1e3*Number((null===(e=null==this?void 0:this.options)||void 0===e?void 0:e.assumeOfflineAfterSeconds)||20);n=setTimeout((()=>{var e;d("----- CONNECTION TIMEOUT, NO LEDER INFO RECEIVED FOR ",t,"SECONDS -----");try{null===(e=this.connection)||void 0===e||e.close()}catch(e){}}),t)};r(),this.endpoint=e.trim(),f("Initialized xrpld WebSocket Client"),this.on("ledger",(()=>{i(),r()}));const i=()=>{this.uplinkReady||(this.serverState.connectAttempts=0,h("Connection ready, fire events"),this.connectBackoff=1e3/1.2,this.uplinkReady=!0,this.eventBus.emit("flush"),this.emit("state",this.getState()))},s=()=>{f("Connection opened :)"),this.send({id:"_WsClient_Internal_Subscription",command:"subscribe",streams:["ledger"]},{sendIfNotReady:!0,noReplayAfterReconnect:!0}),this.send({id:"_WsClient_Internal_ServerInfo@"+Number(new Date),command:"server_info"},{sendIfNotReady:!0,noReplayAfterReconnect:!0}).then((()=>{i()}))},a=e=>{var t;this.emit("close"),this.emit("state",this.getState()),this.connectBackoff=Math.min(Math.round(1.2*this.connectBackoff),1e3*Number((null===(t=this.options)||void 0===t?void 0:t.connectAttemptTimeoutSeconds)||4)),this.uplinkReady=!1,this.serverInfo=void 0,d("Upstream/Websocket closed",null==e?void 0:e.code,null==e?void 0:e.reason),E(),this.closed?f("Closed on purpose, not reconnecting"):(this.emit("retry"),d(`Not closed on purpose, reconnecting after ${this.connectBackoff}...`),setTimeout((()=>{this.eventBus.emit("reconnect")}),this.connectBackoff))},v=e=>{var t,n;if(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.info){const t=e;this.serverInfo||h("Connected, server_info:",{pubkey_node:t.result.info.pubkey_node,build_version:t.result.info.build_version,complete_ledgers:t.result.info.complete_ledgers});const r=Number(new Date)-Number(String((null==e?void 0:e.id)||"").split("@").reverse()[0]);r&&(this.serverState.latency.push({moment:new Date,value:r}),this.serverState.latency.splice(0,this.serverState.latency.length-10));const i=1.2,o=t.result.info.load_factor*Number(null===(n=t.result.info.validated_ledger)||void 0===n?void 0:n.base_fee_xrp)*1e6*i;o&&(this.serverState.fee.push({moment:new Date,value:o}),this.serverState.fee.splice(0,this.serverState.fee.length-5)),this.serverInfo=t}},m=e=>{var t,n,r,i,o,s,l,u,a,c;if("_WsClient_Internal_Subscription"!==(null===(t=null==e?void 0:e.id)||void 0===t?void 0:t._Request)){let t;if(null===(n=null==e?void 0:e.id)||void 0===n?void 0:n._WsClient){const n=this.subscriptions.filter((t=>{var n;return t.id===(null===(n=null==e?void 0:e.id)||void 0===n?void 0:n._WsClient)}));n.length>0&&(t=n[0],t.promiseCallables.resolve(Object.assign(e,{id:null===(r=null==e?void 0:e.id)||void 0===r?void 0:r._Request})))}if(this.emit("message",e),"ledgerClosed"===(null==e?void 0:e.type))p("Async",e.type),Object.assign(this.serverState,{validatedLedgers:null==e?void 0:e.validated_ledgers,reserveBase:Number(null==e?void 0:e.reserve_base)/1e6||null,reserveInc:Number(null==e?void 0:e.reserve_inc)/1e6||null}),this.emit("ledger",e),this.send({id:"_WsClient_Internal_ServerInfo@"+Number(new Date),command:"server_info"});else if("path_find"===(null==e?void 0:e.type))p("Async",e.type),this.emit("path",e);else if("transaction"===(null==e?void 0:e.type))p("Async",e.type),this.emit("transaction",e);else if(null==e?void 0:e.validation_public_key)p("Async","validation"),this.emit("validation",e);else if("path_find"===(null===(i=null==t?void 0:t.request)||void 0===i?void 0:i.command))p("Async",null===(o=null==t?void 0:t.request)||void 0===o?void 0:o.command),this.emit("path",e);else if("subscribe"===(null===(s=null==t?void 0:t.request)||void 0===s?void 0:s.command)&&Array.isArray(null===(l=null==t?void 0:t.request)||void 0===l?void 0:l.streams)&&(null===(u=null==t?void 0:t.request)||void 0===u?void 0:u.streams.indexOf("ledger"))>-1)p("Async","subscription:ledger"),this.emit("ledger",e);else if(t);else{(null===(a=null==e?void 0:e.id)||void 0===a?void 0:a._Request)&&String(e.id._Request).match(/^_WsClient_Internal/)||p("Handle <UNKNOWN> Async Message",{internalId:null===(c=null==e?void 0:e.id)||void 0===c?void 0:c._WsClient,matchingSubscription:t,type:null==e?void 0:e.type,message:e})}}},g=e=>{var t,n,r,i,o,s;try{l.default("string"==typeof e.data,"Unexpected incoming WebSocket message data type");const u=JSON.parse(e.data);if(this.lastContact=new Date,null===(t=null==u?void 0:u.id)||void 0===t?void 0:t._WsClient){const e=this.subscriptions.filter((e=>{var t;return e.id===(null===(t=null==u?void 0:u.id)||void 0===t?void 0:t._WsClient)})),t=this.pendingCalls.filter((e=>{var t;return e.id===(null===(t=null==u?void 0:u.id)||void 0===t?void 0:t._WsClient)}));if(1===e.length)m(u);else if(1===t.length){const e="_WsClient_Internal_ServerInfo"===String((null===(i=null===(r=null===(n=t[0])||void 0===n?void 0:n.request)||void 0===r?void 0:r.id)||void 0===i?void 0:i._Request)||"").split("@")[0];Object.assign(u,{id:null===(o=null==u?void 0:u.id)||void 0===o?void 0:o._Request}),(null===(s=t[0].sendOptions)||void 0===s?void 0:s.timeoutSeconds)&&t[0].timeout&&clearTimeout(t[0].timeout),t[0].promiseCallables.resolve((null==u?void 0:u.result)||u),this.pendingCalls.splice(this.pendingCalls.indexOf(t[0]),1),e?v(u):f("ยป Pending Call Length",this.pendingCalls.length)}else m(u)}else m(u)}catch(e){d("Uplink response: parse error",e.message)}},y=e=>{d("Upstream/Websocket error")},b=e=>{var t;(null===(t=null==e?void 0:e.sendOptions)||void 0===t?void 0:t.timeoutSeconds)&&!(null==e?void 0:e.timeout)&&Object.assign(e,{timeout:setTimeout((()=>o(this,void 0,void 0,(function*(){var t;"_WsClient_Internal_CallResolved"===(yield Promise.race([e.promise,Promise.resolve("_WsClient_Internal_CallResolved")]))&&e.promiseCallables.reject(new Error(`Call timeout after ${null===(t=e.sendOptions)||void 0===t?void 0:t.timeoutSeconds} seconds`))}))),1e3*Number(e.sendOptions.timeoutSeconds))})},C=e=>{var t,n,r;"_WsClient_Internal_ServerInfo"!==String((null===(n=null===(t=null==e?void 0:e.request)||void 0===t?void 0:t.id)||void 0===n?void 0:n._Request)||"").split("@")[0]&&f(" > Process call",e.id,e.request.command);try{this.connection.send(JSON.stringify(e.request)),(null===(r=null==e?void 0:e.sendOptions)||void 0===r?void 0:r.timeoutStartsWhenOnline)&&b(e)}catch(e){d("Process (send to uplink) error",e.message)}},w=e=>{var t,n,r,i,o;"_WsClient_Internal_ServerInfo"!==String((null===(n=null===(t=null==e?void 0:e.request)||void 0===t?void 0:t.id)||void 0===n?void 0:n._Request)||"").split("@")[0]&&f(`Call ${e.id}: ${e.request.command}\n > `,this.uplinkReady?"Uplink ready, pass immediately":(null===(r=null==e?void 0:e.sendOptions)||void 0===r?void 0:r.sendIfNotReady)?"Uplink not flagged as ready yet, but `sendIfNotReady` = true, so go ahead":"Uplink not ready, wait for flush"),(null===(i=null==e?void 0:e.sendOptions)||void 0===i?void 0:i.timeoutStartsWhenOnline)||b(e),(this.uplinkReady||(null===(o=null==e?void 0:e.sendOptions)||void 0===o?void 0:o.sendIfNotReady))&&C(e)},_=()=>{f("Connected, flushing pending calls & subscriptions"),this.pendingCalls.forEach((e=>{C(e)})),this.subscriptions.forEach((e=>{C(e)}))},O=e=>{this.closed=!0,f("Closing connection"),E();try{this.connection.close()}catch(e){}clearTimeout(n),this.subscriptions.forEach((e=>{e.promiseCallables.reject(new Error("Class (connection) hard close requested"))})),this.pendingCalls.forEach((e=>{e.promiseCallables.reject(new Error("Class (connection) hard close requested"))})),this.eventBus.off("__WsClient_call",w),this.eventBus.off("__WsClient_close",O),this.eventBus.off("flush",_),this.eventBus.off("reconnect",S),e&&this.emit("error",e)},E=()=>{f("Cleanup"),this.connection.removeEventListener("open",s),this.connection.removeEventListener("message",g),this.connection.removeEventListener("error",y),this.connection.removeEventListener("close",a)},S=()=>{var e,t,n;try{this.connection.close()}catch(e){}f("Connecting",this.endpoint),this.serverState.connectAttempts++,this.options.maxConnectionAttempts&&Number((null===(e=this.options)||void 0===e?void 0:e.maxConnectionAttempts)||1)>1&&this.serverState.connectAttempts>Number((null===(t=this.options)||void 0===t?void 0:t.maxConnectionAttempts)||1)&&(h("Too many connection attempts",this.serverState.connectAttempts,null===(n=this.options)||void 0===n?void 0:n.maxConnectionAttempts),O(new Error("Max. connection attempts exceeded")));const r=new c.w3cwebsocket(this.endpoint);return setTimeout((()=>{r.readyState!==c.w3cwebsocket.OPEN&&r.close()}),1.2*this.connectBackoff-1),r.addEventListener("open",s),r.addEventListener("message",g),r.addEventListener("error",y),r.addEventListener("close",a),this.connection=r,r};this.eventBus.on("__WsClient_call",w),this.eventBus.on("__WsClient_close",O),this.eventBus.on("flush",_),this.eventBus.on("reconnect",S),this.connection=S()}ready(){return new Promise(((e,t)=>{const n=this.getState();n.online&&n.secLastContact&&n.secLastContact<10&&n.ledger.last?e(this):this.on("ledger",(()=>{e(this)}))}))}send(e,t={}){var n,r,i;l.default("object"==typeof e&&e,"`send()`: expecting object containing `command`"),l.default("string"==typeof e.command,"`command` must be typeof string"),this.callId++;const o={resolve:e=>{},reject:e=>{}},s=new Promise(((e,t)=>{Object.assign(o,{resolve:e,reject:t})})),u={id:this.callId,request:Object.assign(e,{id:{_WsClient:this.callId,_Request:null==e?void 0:e.id},command:e.command.toLowerCase().trim()}),promise:s,promiseCallables:o,sendOptions:t};if(this.closed)return o.reject(new Error("Client in closed state")),s;const a=("subscribe"===u.request.command||"unsubscribe"===u.request.command||"path_find"===u.request.command)&&!(null==t?void 0:t.noReplayAfterReconnect);return"unsubscribe"===(null===(n=u.request)||void 0===n?void 0:n.command)&&Array.isArray(null===(r=u.request)||void 0===r?void 0:r.streams)&&(null===(i=u.request)||void 0===i?void 0:i.streams.indexOf("ledger"))>-1&&(u.request.streams.splice(u.request.streams.indexOf("ledger"),1),0===u.request.streams.length&&0===Object.keys(u.request).filter((e=>"id"!==e&&"streams"!==e&&"command"!==e)).length)?Promise.reject(new Error("Unsubscribing from (just) the ledger stream is not allowed")):("_WsClient_Internal_ServerInfo"!==String((null==e?void 0:e.id)||"").split("@")[0]&&this[a?"subscriptions":"pendingCalls"].push(u),this.eventBus.emit("__WsClient_call",u),s)}getState(){var e,t,n,r,i,o,s,l,u;const a=this.serverState.validatedLedgers.split(",").map((e=>{const t=e.split("-");return t.length>1?parseInt(t[1])-parseInt(t[0]):1})).reduce(((e,t)=>e+t),0);return{online:this.uplinkReady&&!this.closed&&this.connection.readyState===c.w3cwebsocket.OPEN,latencyMs:{last:this.serverState.latency.slice(-1).map((e=>e.value))[0]||null,avg:this.serverState.latency.map((e=>e.value)).reduce(((e,t)=>e+t),0)/this.serverState.latency.length||null,secAgo:Number(new Date)/1e3-this.serverState.latency.slice(-1).map((e=>Number(e.moment)/1e3))[0]||null},server:{version:(null===(n=null===(t=null===(e=this.serverInfo)||void 0===e?void 0:e.result)||void 0===t?void 0:t.info)||void 0===n?void 0:n.build_version)||"",uptime:(null===(o=null===(i=null===(r=this.serverInfo)||void 0===r?void 0:r.result)||void 0===i?void 0:i.info)||void 0===o?void 0:o.uptime)||0,publicKey:(null===(u=null===(l=null===(s=this.serverInfo)||void 0===s?void 0:s.result)||void 0===l?void 0:l.info)||void 0===u?void 0:u.pubkey_node)||"",uri:this.endpoint},ledger:{last:Number(this.serverState.validatedLedgers.split(",").reverse()[0].split("-").reverse()[0]),validated:this.serverState.validatedLedgers,count:""===this.serverState.validatedLedgers?0:a},fee:{last:this.serverState.fee.slice(-1).map((e=>e.value))[0]||null,avg:this.serverState.fee.map((e=>e.value)).reduce(((e,t)=>e+t),0)/this.serverState.fee.length||null,secAgo:Number(new Date)/1e3-this.serverState.fee.slice(-1).map((e=>Number(e.moment)/1e3))[0]||null},reserve:{base:this.serverState.reserveBase,owner:this.serverState.reserveInc},secLastContact:this.lastContact?Number(new Date)/1e3-Number(this.lastContact)/1e3:null}}close(){l.default(!this.closed,"Object already in closed state"),this.eventBus.emit("__WsClient_close")}}n.XrplClient=v},{"./types":1,assert:2,debug:6,events:9,websocket:13}]},{},[]);
/// <reference types="node" />
import { EventEmitter } from "events";
import { WsClientOptions, CallResponse, Call, AnyJson, ConnectionState, SendOptions } from "./types";
import { WsClientOptions, Call, AnyJson, ConnectionState, SendOptions, XrplClientEvents } from "./types";
export * from "./types";
export declare interface XrplClient {
on(event: "close"): this;
on(event: "state", listener: (state: ConnectionState) => any): this;
on(event: "retry"): this;
on(event: "reconnect"): this;
on(event: "message", listener: (message: CallResponse | AnyJson) => any): this;
on(event: "transaction", listener: (transaction: CallResponse | AnyJson) => any): this;
on(event: "validation", listener: (validation: CallResponse | AnyJson) => any): this;
on(event: "path", listener: (path: CallResponse | AnyJson) => any): this;
on(event: "ledger", listener: (ledger: CallResponse | AnyJson) => any): this;
on(event: "error", listener: (e: Error) => any): this;
on(event: string, listener: Function): this;
on<U extends keyof XrplClientEvents>(event: U, listener: XrplClientEvents[U]): this;
}
export declare class XrplClient extends EventEmitter {
private eventBus;
private connectBackoff;

@@ -20,0 +11,0 @@ private closed;

@@ -38,6 +38,6 @@ "use strict";

const maxConnectionAttempts = null;
// Class
class XrplClient extends events_1.EventEmitter {
constructor(endpoint = "wss://xrplcluster.com", options) {
super();
this.eventBus = new events_1.EventEmitter();
this.connectBackoff = 1000 / 1.2;

@@ -103,3 +103,3 @@ this.closed = false;

this.uplinkReady = true;
this.emit("flush");
this.eventBus.emit("flush");
this.emit("state", this.getState());

@@ -146,3 +146,3 @@ }

setTimeout(() => {
this.emit("reconnect");
this.eventBus.emit("reconnect");
}, this.connectBackoff);

@@ -194,2 +194,12 @@ }

if (((_a = message === null || message === void 0 ? void 0 : message.id) === null || _a === void 0 ? void 0 : _a._Request) !== "_WsClient_Internal_Subscription") {
let matchingSubscription;
if ((_b = message === null || message === void 0 ? void 0 : message.id) === null || _b === void 0 ? void 0 : _b._WsClient) {
const _matching = this.subscriptions.filter((s) => { var _a; return s.id === ((_a = message === null || message === void 0 ? void 0 : message.id) === null || _a === void 0 ? void 0 : _a._WsClient); });
if (_matching.length > 0) {
matchingSubscription = _matching[0];
matchingSubscription.promiseCallables.resolve(Object.assign(message, {
id: (_c = message === null || message === void 0 ? void 0 : message.id) === null || _c === void 0 ? void 0 : _c._Request,
}));
}
}
this.emit("message", message);

@@ -225,16 +235,9 @@ if ((message === null || message === void 0 ? void 0 : message.type) === "ledgerClosed") {

else {
let matchingSubscription;
if ((_b = message === null || message === void 0 ? void 0 : message.id) === null || _b === void 0 ? void 0 : _b._WsClient) {
const _matching = this.subscriptions.filter((s) => { var _a; return s.id === ((_a = message === null || message === void 0 ? void 0 : message.id) === null || _a === void 0 ? void 0 : _a._WsClient); });
if (_matching.length > 0) {
matchingSubscription = _matching[0];
}
}
if (((_c = matchingSubscription === null || matchingSubscription === void 0 ? void 0 : matchingSubscription.request) === null || _c === void 0 ? void 0 : _c.command) === "path_find") {
logMessage("Async", (_d = matchingSubscription === null || matchingSubscription === void 0 ? void 0 : matchingSubscription.request) === null || _d === void 0 ? void 0 : _d.command);
if (((_d = matchingSubscription === null || matchingSubscription === void 0 ? void 0 : matchingSubscription.request) === null || _d === void 0 ? void 0 : _d.command) === "path_find") {
logMessage("Async", (_e = matchingSubscription === null || matchingSubscription === void 0 ? void 0 : matchingSubscription.request) === null || _e === void 0 ? void 0 : _e.command);
this.emit("path", message);
}
else if (((_e = matchingSubscription === null || matchingSubscription === void 0 ? void 0 : matchingSubscription.request) === null || _e === void 0 ? void 0 : _e.command) === "subscribe" &&
Array.isArray((_f = matchingSubscription === null || matchingSubscription === void 0 ? void 0 : matchingSubscription.request) === null || _f === void 0 ? void 0 : _f.streams) &&
((_g = matchingSubscription === null || matchingSubscription === void 0 ? void 0 : matchingSubscription.request) === null || _g === void 0 ? void 0 : _g.streams.indexOf("ledger")) > -1) {
else if (((_f = matchingSubscription === null || matchingSubscription === void 0 ? void 0 : matchingSubscription.request) === null || _f === void 0 ? void 0 : _f.command) === "subscribe" &&
Array.isArray((_g = matchingSubscription === null || matchingSubscription === void 0 ? void 0 : matchingSubscription.request) === null || _g === void 0 ? void 0 : _g.streams) &&
((_h = matchingSubscription === null || matchingSubscription === void 0 ? void 0 : matchingSubscription.request) === null || _h === void 0 ? void 0 : _h.streams.indexOf("ledger")) > -1) {
logMessage("Async", "subscription:ledger");

@@ -244,5 +247,3 @@ this.emit("ledger", message);

else if (matchingSubscription) {
matchingSubscription.promiseCallables.resolve(Object.assign(message, {
id: (_h = message === null || message === void 0 ? void 0 : message.id) === null || _h === void 0 ? void 0 : _h._Request,
}));
// Don't log `Unknown` as we know this
}

@@ -346,3 +347,3 @@ else {

if ((_c = call === null || call === void 0 ? void 0 : call.sendOptions) === null || _c === void 0 ? void 0 : _c.timeoutStartsWhenOnline) {
logWarning("APPLY TIMEOUT ONLY AFTER GOING ONLINE");
// logWarning("APPLY TIMEOUT ONLY AFTER GOING ONLINE");
applyCallTimeout(call);

@@ -366,3 +367,3 @@ }

if (!((_d = call === null || call === void 0 ? void 0 : call.sendOptions) === null || _d === void 0 ? void 0 : _d.timeoutStartsWhenOnline)) {
logWarning("APPLY TIMEOUT NO MATTER ONLINE/OFFLINE STATE");
// logWarning("APPLY TIMEOUT NO MATTER ONLINE/OFFLINE STATE");
applyCallTimeout(call);

@@ -404,6 +405,6 @@ }

});
this.off("__WsClient_call", call);
this.off("__WsClient_close", close);
this.off("flush", flush);
this.off("reconnect", connect);
this.eventBus.off("__WsClient_call", call);
this.eventBus.off("__WsClient_close", close);
this.eventBus.off("flush", flush);
this.eventBus.off("reconnect", connect);
if (error) {

@@ -452,6 +453,6 @@ this.emit("error", error);

};
this.on("__WsClient_call", call);
this.on("__WsClient_close", close);
this.on("flush", flush);
this.on("reconnect", connect);
this.eventBus.on("__WsClient_call", call);
this.eventBus.on("__WsClient_close", close);
this.eventBus.on("flush", flush);
this.eventBus.on("reconnect", connect);
// setTimeout(() => {

@@ -528,3 +529,3 @@ this.connection = connect();

}
this.emit("__WsClient_call", pendingCall);
this.eventBus.emit("__WsClient_call", pendingCall);
return promise;

@@ -597,5 +598,5 @@ }

assert_1.default(!this.closed, "Object already in closed state");
this.emit("__WsClient_close");
this.eventBus.emit("__WsClient_close");
}
}
exports.XrplClient = XrplClient;
/// <reference types="node" />
export declare type AnyJson = Record<string, unknown>;
export interface EventBusEvents {
__WsClient_call: (call: PendingCall) => void;
__WsClient_close: () => void;
reconnect: () => void;
flush: () => void;
}
export declare interface EventBus {
on<U extends keyof EventBusEvents>(event: U, listener: EventBusEvents[U]): this;
off<U extends keyof EventBusEvents>(event: U, listener: EventBusEvents[U]): this;
emit<U extends keyof EventBusEvents>(event: U, ...args: Parameters<EventBusEvents[U]>): boolean;
}
export interface XrplClientEvents {
close: () => void;
retry: () => void;
state: (state: ConnectionState) => void;
message: (message: CallResponse | AnyJson) => void;
transaction: (transaction: CallResponse | AnyJson) => void;
validation: (validation: CallResponse | AnyJson) => void;
path: (path: CallResponse | AnyJson) => void;
ledger: (ledger: CallResponse | AnyJson) => void;
error: (e: Error) => void;
}
export interface WsClientOptions {

@@ -4,0 +26,0 @@ connectAttemptTimeoutSeconds?: number;

{
"name": "xrpl-client",
"version": "1.1.6",
"version": "1.2.0",
"description": "Connect to the XRP Ledger using websockets",

@@ -5,0 +5,0 @@ "main": "dist/src/index.js",

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc