therungg
Version:
Node wrapper for therun.gg's API.
2 lines (1 loc) • 2.12 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var _class;var _isomorphicws = require('isomorphic-ws'); var _isomorphicws2 = _interopRequireDefault(_isomorphicws);var s="https://therun.gg/api",i="https://d1qsrp2avfthuv.cloudfront.net",a="wss://fh76djw1t9.execute-api.eu-west-1.amazonaws.com/prod";var n= (_class =class{__init() {this.onOpen=void 0}__init2() {this.onClose=void 0}__init3() {this.onMessage=void 0}__init4() {this.onError=void 0}constructor(o){;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);this._websocket=new (0, _isomorphicws2.default)(`${a}${o?`?username=${o}`:""}`),this._websocket.onopen=()=>this.onOpen?this.onOpen():console.info("WebSocket connection to TheRun's Live API established."),this._websocket.onclose=()=>this.onClose?this.onClose():console.info("WebSocket connection to TheRun's Live API closed."),this._websocket.onmessage=e=>{this.onMessage&&this.onMessage(JSON.parse(e.data))},this._websocket.onerror=e=>this.onError?this.onError(e):console.error(e.message)}get connection(){return this._websocket}}, _class);var t=async(r,o)=>{try{let e=await fetch(`${o||s}/${r}`);if(!e.ok)throw new Error(e.status.toString());return await e.json()}catch(e){throw e instanceof Error?e.message==="404"?new Error("Not Found"):e.message==="429"?new Error("Rate Limited"):e.message==="500"?new Error("Bad Request"):e:new Error("Something went wrong")}};var c=async()=>await t("frontpagedata");var m=async r=>await t(r,i);var u=async()=>await t("live");var f=async r=>{let o=`live/${r}`;return await t(o)};var l=async r=>{let o=`users/${r}`;return{runs:await t(o)}};var R=async()=>await t("games");var d=async r=>{let o=`games/${r}`;return await t(o)};exports.LiveWebSocket = n; exports.getAllGames = R; exports.getAllLiveRuns = u; exports.getFrontPageData = c; exports.getGame = d; exports.getHistory = m; exports.getLiveRun = f; exports.getUserProfile = l; exports.httpFetch = t;