@serverbench/js 1.4.10 → 1.4.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Serverbench.cjs +1 -1
- package/dist/Serverbench.js +1 -1
- package/dist/{chunk-DHR2K27A.js → chunk-FPGAQIFN.js} +2 -2
- package/dist/chunk-FPGAQIFN.js.map +1 -0
- package/dist/{chunk-AMS3EZII.cjs → chunk-UE662LDG.cjs} +2 -2
- package/dist/{chunk-AMS3EZII.cjs.map → chunk-UE662LDG.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-DHR2K27A.js.map +0 -1
package/dist/Serverbench.cjs
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkUE662LDGcjs = require('./chunk-UE662LDG.cjs');require('./chunk-BTEUXALX.cjs');require('./chunk-UZVZQL4F.cjs');require('./chunk-3YNQTTHI.cjs');require('./chunk-LUTKTZJQ.cjs');require('./chunk-T4XJ6ERT.cjs');require('./chunk-5EFJ4GIY.cjs');require('./chunk-FXVJCHR6.cjs');require('./chunk-VX4LKECW.cjs');exports.default = _chunkUE662LDGcjs.a;
|
2
2
|
//# sourceMappingURL=Serverbench.cjs.map
|
package/dist/Serverbench.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
import{a}from"./chunk-
|
1
|
+
import{a}from"./chunk-FPGAQIFN.js";import"./chunk-6RGXVIPA.js";import"./chunk-UTQPTYIQ.js";import"./chunk-CTMUE5H3.js";import"./chunk-4GCQV2YR.js";import"./chunk-G27KF7G3.js";import"./chunk-4PA7GD6K.js";import"./chunk-GLEWOHG7.js";import"./chunk-4NMPBSP3.js";export{a as default};
|
2
2
|
//# sourceMappingURL=Serverbench.js.map
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import{a as m}from"./chunk-6RGXVIPA.js";import{a as g}from"./chunk-CTMUE5H3.js";import{a as u}from"./chunk-GLEWOHG7.js";import{nanoid as d}from"nanoid/non-secure";var i=class i{constructor(t,e,s){this.clientId=t,this.clientSecret=e,this.test=s}static get(t,e,s=!1){return(!i.instance||i.instance.clientId!==t||i.instance.clientSecret!==e||i.instance.test!==s)&&(i.instance=new i(t,e,s)),i.instance}get store(){return new m(this)}get voting(){return new g(this)}async member(t){return u.fromObject(this,await this.post("community","/member/search",t))}async fetch(t,e,s){let o=this.test?"https://dev.serverbench.io":"https://api.beta.serverbench.io",n=new Headers({authorization:`ApiKey ${this.clientSecret}`});s&&n.set("Content-Type","application/json");let a=await fetch(`${o}/${t}/${this.clientId}${e}`,{headers:n,method:s?"POST":"GET",body:s?JSON.stringify(s):void 0});if(a.status<200||a.status>=300)throw new Error(a.statusText);return a.json()}rid(){return d()}socket(t,e=o=>{},s=!1){let o=this.test?"ws://localhost:3030":"wss://stream.beta.serverbench.io",n=new WebSocket(`${o}?${new URLSearchParams({key:this.clientSecret})}`),a=0,c=this.rid();return n.onopen=()=>{a=0,n.send(JSON.stringify({action:`community.${this.clientId}.${t}`,rid:c}))},n.onmessage=p=>{let r=JSON.parse(p.data);if(r.
|
2
|
-
//# sourceMappingURL=chunk-
|
1
|
+
import{a as m}from"./chunk-6RGXVIPA.js";import{a as g}from"./chunk-CTMUE5H3.js";import{a as u}from"./chunk-GLEWOHG7.js";import{nanoid as d}from"nanoid/non-secure";var i=class i{constructor(t,e,s){this.clientId=t,this.clientSecret=e,this.test=s}static get(t,e,s=!1){return(!i.instance||i.instance.clientId!==t||i.instance.clientSecret!==e||i.instance.test!==s)&&(i.instance=new i(t,e,s)),i.instance}get store(){return new m(this)}get voting(){return new g(this)}async member(t){return u.fromObject(this,await this.post("community","/member/search",t))}async fetch(t,e,s){let o=this.test?"https://dev.serverbench.io":"https://api.beta.serverbench.io",n=new Headers({authorization:`ApiKey ${this.clientSecret}`});s&&n.set("Content-Type","application/json");let a=await fetch(`${o}/${t}/${this.clientId}${e}`,{headers:n,method:s?"POST":"GET",body:s?JSON.stringify(s):void 0});if(a.status<200||a.status>=300)throw new Error(a.statusText);return a.json()}rid(){return d()}socket(t,e=o=>{},s=!1){let o=this.test?"ws://localhost:3030":"wss://stream.beta.serverbench.io",n=new WebSocket(`${o}?${new URLSearchParams({key:this.clientSecret})}`),a=0,c=this.rid();return n.onopen=()=>{a=0,n.send(JSON.stringify({action:`community.${this.clientId}.${t}`,rid:c}))},n.onmessage=p=>{let r=JSON.parse(p.data);if(r.result!=null&&(Array.isArray(r.result)&&r.result.length||Object.keys(r.result).length>0)&&r.rid==c)e(r.result);else{let l=[r.realm];r.realm=="community"&&l.push(this.clientId),l.push(r.action),c=this.rid(),n.send(JSON.stringify({action:l.join("."),rid:c}))}},s||(n.onclose=()=>{a++,setTimeout(()=>{n=this.socket(t,e,!0).ws},Math.min(1e3*a*5,30*1e3))}),{dispose:()=>{n.onclose=null,n.close()},ws:n}}async get(t,e){return this.fetch(t,e)}async post(t,e,s={}){return this.fetch(t,e,s)}};i.instance=null;var h=i;export{h as a};
|
2
|
+
//# sourceMappingURL=chunk-FPGAQIFN.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/Serverbench.ts"],"sourcesContent":["import { nanoid } from \"nanoid/non-secure\"\nimport Member from \"./Member.js\"\nimport Store from \"./store/Store.js\"\nimport Voting from \"./voting/Voting.js\"\n\nexport default class Serverbench {\n\n clientId: string\n clientSecret: string\n test: boolean\n\n private static instance: Serverbench | null = null\n\n private constructor(clientId: string, clientSecret: string, test: boolean) {\n this.clientId = clientId\n this.clientSecret = clientSecret\n this.test = test\n }\n\n static get(clientId: string, clientSecret: string, test: boolean = false) {\n if (!Serverbench.instance || Serverbench.instance.clientId !== clientId || Serverbench.instance.clientSecret !== clientSecret || Serverbench.instance.test !== test) {\n Serverbench.instance = new Serverbench(clientId, clientSecret, test)\n }\n return Serverbench.instance\n }\n\n get store() {\n return new Store(this)\n }\n\n get voting() {\n return new Voting(this)\n }\n\n public async member(find: {\n username?: string,\n eid?: string,\n }) {\n return Member.fromObject(this, await this.post('community', '/member/search', find))\n }\n\n private async fetch(realm: string, url: string, body?: any) {\n const domain = this.test ? 'https://dev.serverbench.io' : 'https://api.beta.serverbench.io'\n const headers = new Headers({\n authorization: `ApiKey ${this.clientSecret}`,\n })\n if (body) {\n headers.set('Content-Type', 'application/json')\n }\n const response = await fetch(`${domain}/${realm}/${this.clientId}${url}`, {\n headers,\n method: body ? 'POST' : 'GET',\n body: body ? JSON.stringify(body) : undefined\n })\n if (response.status < 200 || response.status >= 300) {\n throw new Error(response.statusText)\n }\n return response.json()\n }\n\n private rid() {\n return nanoid()\n }\n\n public socket(action: string, handleMessage = (data: any) => { }, ignoreClose = false) {\n const domain = this.test ? 'ws://localhost:3030' : 'wss://stream.beta.serverbench.io'\n let ws = new WebSocket(`${domain}?${new URLSearchParams({\n key: this.clientSecret,\n })}`)\n let i = 0\n let expecting = this.rid()\n ws.onopen = () => {\n i = 0\n ws.send(JSON.stringify({\n action: `community.${this.clientId}.${action}`,\n rid: expecting\n }))\n }\n ws.onmessage = (event) => {\n const data = JSON.parse(event.data)\n if (data.result != null && ((Array.isArray(data.result) && data.result.length) || Object.keys(data.result).length > 0) && data.rid == expecting) {\n handleMessage(data.result)\n } else {\n let action = [data.realm]\n if (data.realm == 'community') {\n action.push(this.clientId)\n }\n action.push(data.action)\n expecting = this.rid()\n ws.send(JSON.stringify({\n action: action.join('.'),\n rid: expecting\n }))\n }\n }\n if (!ignoreClose) {\n ws.onclose = () => {\n i++\n setTimeout(() => {\n ws = this.socket(action, handleMessage, true).ws\n }, Math.min(1000 * (i) * 5, 30 * 1000));\n }\n }\n return {\n dispose: () => {\n ws.onclose = null\n ws.close()\n },\n ws\n }\n }\n\n async get(realm: string, url: string) {\n return this.fetch(realm, url)\n }\n\n async post(realm: string, url: string, body: any = {}) {\n return this.fetch(realm, url, body)\n }\n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OC,EAAKC,CAAI,CACtC,CAEJ,EAnHqBV,EAMF,SAA+B,KANlD,IAAqBuB,EAArBvB","names":["nanoid","_Serverbench","clientId","clientSecret","test","Store","Voting","find","Member","realm","url","body","domain","headers","response","nanoid","action","handleMessage","data","ignoreClose","ws","i","expecting","event","Serverbench"]}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkBTEUXALXcjs = require('./chunk-BTEUXALX.cjs');var _chunk3YNQTTHIcjs = require('./chunk-3YNQTTHI.cjs');var _chunkFXVJCHR6cjs = require('./chunk-FXVJCHR6.cjs');var _nonsecure = require('nanoid/non-secure');var i=class i{constructor(t,e,s){this.clientId=t,this.clientSecret=e,this.test=s}static get(t,e,s=!1){return(!i.instance||i.instance.clientId!==t||i.instance.clientSecret!==e||i.instance.test!==s)&&(i.instance=new i(t,e,s)),i.instance}get store(){return new (0, _chunkBTEUXALXcjs.a)(this)}get voting(){return new (0, _chunk3YNQTTHIcjs.a)(this)}async member(t){return _chunkFXVJCHR6cjs.a.fromObject(this,await this.post("community","/member/search",t))}async fetch(t,e,s){let o=this.test?"https://dev.serverbench.io":"https://api.beta.serverbench.io",n=new Headers({authorization:`ApiKey ${this.clientSecret}`});s&&n.set("Content-Type","application/json");let a=await fetch(`${o}/${t}/${this.clientId}${e}`,{headers:n,method:s?"POST":"GET",body:s?JSON.stringify(s):void 0});if(a.status<200||a.status>=300)throw new Error(a.statusText);return a.json()}rid(){return _nonsecure.nanoid.call(void 0, )}socket(t,e=o=>{},s=!1){let o=this.test?"ws://localhost:3030":"wss://stream.beta.serverbench.io",n=new WebSocket(`${o}?${new URLSearchParams({key:this.clientSecret})}`),a=0,c=this.rid();return n.onopen=()=>{a=0,n.send(JSON.stringify({action:`community.${this.clientId}.${t}`,rid:c}))},n.onmessage=p=>{let r=JSON.parse(p.data);if(r.
|
2
|
-
//# sourceMappingURL=chunk-
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkBTEUXALXcjs = require('./chunk-BTEUXALX.cjs');var _chunk3YNQTTHIcjs = require('./chunk-3YNQTTHI.cjs');var _chunkFXVJCHR6cjs = require('./chunk-FXVJCHR6.cjs');var _nonsecure = require('nanoid/non-secure');var i=class i{constructor(t,e,s){this.clientId=t,this.clientSecret=e,this.test=s}static get(t,e,s=!1){return(!i.instance||i.instance.clientId!==t||i.instance.clientSecret!==e||i.instance.test!==s)&&(i.instance=new i(t,e,s)),i.instance}get store(){return new (0, _chunkBTEUXALXcjs.a)(this)}get voting(){return new (0, _chunk3YNQTTHIcjs.a)(this)}async member(t){return _chunkFXVJCHR6cjs.a.fromObject(this,await this.post("community","/member/search",t))}async fetch(t,e,s){let o=this.test?"https://dev.serverbench.io":"https://api.beta.serverbench.io",n=new Headers({authorization:`ApiKey ${this.clientSecret}`});s&&n.set("Content-Type","application/json");let a=await fetch(`${o}/${t}/${this.clientId}${e}`,{headers:n,method:s?"POST":"GET",body:s?JSON.stringify(s):void 0});if(a.status<200||a.status>=300)throw new Error(a.statusText);return a.json()}rid(){return _nonsecure.nanoid.call(void 0, )}socket(t,e=o=>{},s=!1){let o=this.test?"ws://localhost:3030":"wss://stream.beta.serverbench.io",n=new WebSocket(`${o}?${new URLSearchParams({key:this.clientSecret})}`),a=0,c=this.rid();return n.onopen=()=>{a=0,n.send(JSON.stringify({action:`community.${this.clientId}.${t}`,rid:c}))},n.onmessage=p=>{let r=JSON.parse(p.data);if(r.result!=null&&(Array.isArray(r.result)&&r.result.length||Object.keys(r.result).length>0)&&r.rid==c)e(r.result);else{let l=[r.realm];r.realm=="community"&&l.push(this.clientId),l.push(r.action),c=this.rid(),n.send(JSON.stringify({action:l.join("."),rid:c}))}},s||(n.onclose=()=>{a++,setTimeout(()=>{n=this.socket(t,e,!0).ws},Math.min(1e3*a*5,30*1e3))}),{dispose:()=>{n.onclose=null,n.close()},ws:n}}async get(t,e){return this.fetch(t,e)}async post(t,e,s={}){return this.fetch(t,e,s)}};i.instance=null;var h=i;exports.a = h;
|
2
|
+
//# sourceMappingURL=chunk-UE662LDG.cjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["/Users/happy/Documents/purevanilla/js/dist/chunk-
|
1
|
+
{"version":3,"sources":["/Users/happy/Documents/purevanilla/js/dist/chunk-UE662LDG.cjs","../src/Serverbench.ts"],"names":["_Serverbench","clientId","clientSecret","test","Store","Voting","find","Member","realm","url","body","domain","headers"],"mappings":"AAAA,iIAAwC,wDAAyC,wDAAyC,8CCAnG,IAKFA,CAAAA,CAArB,MAAqBA,CAAY,CAQrB,WAAA,CAAYC,CAAAA,CAAkBC,CAAAA,CAAsBC,CAAAA,CAAe,CACvE,IAAA,CAAK,QAAA,CAAWF,CAAAA,CAChB,IAAA,CAAK,YAAA,CAAeC,CAAAA,CACpB,IAAA,CAAK,IAAA,CAAOC,CAChB,CAEA,OAAO,GAAA,CAAIF,CAAAA,CAAkBC,CAAAA,CAAsBC,CAAAA,CAAgB,CAAA,CAAA,CAAO,CACtE,MAAA,CAAI,CAACH,CAAAA,CAAY,QAAA,EAAYA,CAAAA,CAAY,QAAA,CAAS,QAAA,GAAaC,CAAAA,EAAYD,CAAAA,CAAY,QAAA,CAAS,YAAA,GAAiBE,CAAAA,EAAgBF,CAAAA,CAAY,QAAA,CAAS,IAAA,GAASG,CAAAA,CAAAA,EAAAA,CAC3JH,CAAAA,CAAY,QAAA,CAAW,IAAIA,CAAAA,CAAYC,CAAAA,CAAUC,CAAAA,CAAcC,CAAI,CAAA,CAAA,CAEhEH,CAAAA,CAAY,QACvB,CAEA,IAAI,KAAA,CAAA,CAAQ,CACR,OAAO,IAAII,wBAAAA,CAAM,IAAI,CACzB,CAEA,IAAI,MAAA,CAAA,CAAS,CACT,OAAO,IAAIC,wBAAAA,CAAO,IAAI,CAC1B,CAEA,MAAa,MAAA,CAAOC,CAAAA,CAGjB,CACC,OAAOC,mBAAAA,CAAO,UAAA,CAAW,IAAA,CAAM,MAAM,IAAA,CAAK,IAAA,CAAK,WAAA,CAAa,gBAAA,CAAkBD,CAAI,CAAC,CACvF,CAEA,MAAc,KAAA,CAAME,CAAAA,CAAeC,CAAAA,CAAaC,CAAAA,CAAY,CACxD,IAAMC,CAAAA,CAAS,IAAA,CAAK,IAAA,CAAO,4BAAA,CAA+B,iCAAA,CACpDC,CAAAA,CAAU,IAAI,OAAA,CAAQ,CACxB,aAAA,CAAe,CAAA,OAAA,EAAU,IAAA,CAAK,YAAY,CAAA,CAAA","file":"/Users/happy/Documents/purevanilla/js/dist/chunk-UE662LDG.cjs","sourcesContent":[null,"import { nanoid } from \"nanoid/non-secure\"\nimport Member from \"./Member.js\"\nimport Store from \"./store/Store.js\"\nimport Voting from \"./voting/Voting.js\"\n\nexport default class Serverbench {\n\n clientId: string\n clientSecret: string\n test: boolean\n\n private static instance: Serverbench | null = null\n\n private constructor(clientId: string, clientSecret: string, test: boolean) {\n this.clientId = clientId\n this.clientSecret = clientSecret\n this.test = test\n }\n\n static get(clientId: string, clientSecret: string, test: boolean = false) {\n if (!Serverbench.instance || Serverbench.instance.clientId !== clientId || Serverbench.instance.clientSecret !== clientSecret || Serverbench.instance.test !== test) {\n Serverbench.instance = new Serverbench(clientId, clientSecret, test)\n }\n return Serverbench.instance\n }\n\n get store() {\n return new Store(this)\n }\n\n get voting() {\n return new Voting(this)\n }\n\n public async member(find: {\n username?: string,\n eid?: string,\n }) {\n return Member.fromObject(this, await this.post('community', '/member/search', find))\n }\n\n private async fetch(realm: string, url: string, body?: any) {\n const domain = this.test ? 'https://dev.serverbench.io' : 'https://api.beta.serverbench.io'\n const headers = new Headers({\n authorization: `ApiKey ${this.clientSecret}`,\n })\n if (body) {\n headers.set('Content-Type', 'application/json')\n }\n const response = await fetch(`${domain}/${realm}/${this.clientId}${url}`, {\n headers,\n method: body ? 'POST' : 'GET',\n body: body ? JSON.stringify(body) : undefined\n })\n if (response.status < 200 || response.status >= 300) {\n throw new Error(response.statusText)\n }\n return response.json()\n }\n\n private rid() {\n return nanoid()\n }\n\n public socket(action: string, handleMessage = (data: any) => { }, ignoreClose = false) {\n const domain = this.test ? 'ws://localhost:3030' : 'wss://stream.beta.serverbench.io'\n let ws = new WebSocket(`${domain}?${new URLSearchParams({\n key: this.clientSecret,\n })}`)\n let i = 0\n let expecting = this.rid()\n ws.onopen = () => {\n i = 0\n ws.send(JSON.stringify({\n action: `community.${this.clientId}.${action}`,\n rid: expecting\n }))\n }\n ws.onmessage = (event) => {\n const data = JSON.parse(event.data)\n if (data.result != null && ((Array.isArray(data.result) && data.result.length) || Object.keys(data.result).length > 0) && data.rid == expecting) {\n handleMessage(data.result)\n } else {\n let action = [data.realm]\n if (data.realm == 'community') {\n action.push(this.clientId)\n }\n action.push(data.action)\n expecting = this.rid()\n ws.send(JSON.stringify({\n action: action.join('.'),\n rid: expecting\n }))\n }\n }\n if (!ignoreClose) {\n ws.onclose = () => {\n i++\n setTimeout(() => {\n ws = this.socket(action, handleMessage, true).ws\n }, Math.min(1000 * (i) * 5, 30 * 1000));\n }\n }\n return {\n dispose: () => {\n ws.onclose = null\n ws.close()\n },\n ws\n }\n }\n\n async get(realm: string, url: string) {\n return this.fetch(realm, url)\n }\n\n async post(realm: string, url: string, body: any = {}) {\n return this.fetch(realm, url, body)\n }\n\n}"]}
|
package/dist/index.cjs
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('./chunk-OW4YZ724.cjs');require('./chunk-X4NW2R7G.cjs');require('./chunk-DSKIK7XF.cjs');require('./chunk-GOVZHEHO.cjs');require('./chunk-D22KLLON.cjs');require('./chunk-UHS7Z46V.cjs');require('./chunk-OVXIHLHV.cjs');var
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('./chunk-OW4YZ724.cjs');require('./chunk-X4NW2R7G.cjs');require('./chunk-DSKIK7XF.cjs');require('./chunk-GOVZHEHO.cjs');require('./chunk-D22KLLON.cjs');require('./chunk-UHS7Z46V.cjs');require('./chunk-OVXIHLHV.cjs');var _chunkUE662LDGcjs = require('./chunk-UE662LDG.cjs');require('./chunk-BTEUXALX.cjs');var _chunkUZVZQL4Fcjs = require('./chunk-UZVZQL4F.cjs');require('./chunk-3YNQTTHI.cjs');var _chunkLUTKTZJQcjs = require('./chunk-LUTKTZJQ.cjs');var _chunkT4XJ6ERTcjs = require('./chunk-T4XJ6ERT.cjs');var _chunk5EFJ4GIYcjs = require('./chunk-5EFJ4GIY.cjs');var _chunkFXVJCHR6cjs = require('./chunk-FXVJCHR6.cjs');var _chunkVX4LKECWcjs = require('./chunk-VX4LKECW.cjs');require('./chunk-SYLAVD2D.cjs');require('./chunk-CJWXGEQN.cjs');require('./chunk-A63AYQ4G.cjs');var g=_chunkUE662LDGcjs.a;exports.Element = _chunkVX4LKECWcjs.a; exports.IStore = _chunkUZVZQL4Fcjs.a; exports.ListingDisplay = _chunkLUTKTZJQcjs.a; exports.ListingSiteDisplay = _chunkT4XJ6ERTcjs.a; exports.Member = _chunkFXVJCHR6cjs.a; exports.Store = _chunkUZVZQL4Fcjs.a; exports.Vote = _chunk5EFJ4GIYcjs.a; exports.default = g;
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
import"./chunk-FI7FAFLX.js";import"./chunk-LBVHKFZO.js";import"./chunk-7KUMKL43.js";import"./chunk-RY7QEHM4.js";import"./chunk-ZYLLOUW6.js";import"./chunk-AS4B37XA.js";import"./chunk-56HSL4MD.js";import{a as r}from"./chunk-
|
1
|
+
import"./chunk-FI7FAFLX.js";import"./chunk-LBVHKFZO.js";import"./chunk-7KUMKL43.js";import"./chunk-RY7QEHM4.js";import"./chunk-ZYLLOUW6.js";import"./chunk-AS4B37XA.js";import"./chunk-56HSL4MD.js";import{a as r}from"./chunk-FPGAQIFN.js";import"./chunk-6RGXVIPA.js";import{a as m}from"./chunk-UTQPTYIQ.js";import"./chunk-CTMUE5H3.js";import{a as p}from"./chunk-4GCQV2YR.js";import{a as e}from"./chunk-G27KF7G3.js";import{a as i}from"./chunk-4PA7GD6K.js";import{a as o}from"./chunk-GLEWOHG7.js";import{a as t}from"./chunk-4NMPBSP3.js";import"./chunk-5YLG7KH6.js";import"./chunk-EMFCL4IX.js";import"./chunk-33DIW7ZK.js";var g=r;export{t as Element,m as IStore,p as ListingDisplay,e as ListingSiteDisplay,o as Member,m as Store,i as Vote,g as default};
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../src/Serverbench.ts"],"sourcesContent":["import { nanoid } from \"nanoid/non-secure\"\nimport Member from \"./Member.js\"\nimport Store from \"./store/Store.js\"\nimport Voting from \"./voting/Voting.js\"\n\nexport default class Serverbench {\n\n clientId: string\n clientSecret: string\n test: boolean\n\n private static instance: Serverbench | null = null\n\n private constructor(clientId: string, clientSecret: string, test: boolean) {\n this.clientId = clientId\n this.clientSecret = clientSecret\n this.test = test\n }\n\n static get(clientId: string, clientSecret: string, test: boolean = false) {\n if (!Serverbench.instance || Serverbench.instance.clientId !== clientId || Serverbench.instance.clientSecret !== clientSecret || Serverbench.instance.test !== test) {\n Serverbench.instance = new Serverbench(clientId, clientSecret, test)\n }\n return Serverbench.instance\n }\n\n get store() {\n return new Store(this)\n }\n\n get voting() {\n return new Voting(this)\n }\n\n public async member(find: {\n username?: string,\n eid?: string,\n }) {\n return Member.fromObject(this, await this.post('community', '/member/search', find))\n }\n\n private async fetch(realm: string, url: string, body?: any) {\n const domain = this.test ? 'https://dev.serverbench.io' : 'https://api.beta.serverbench.io'\n const headers = new Headers({\n authorization: `ApiKey ${this.clientSecret}`,\n })\n if (body) {\n headers.set('Content-Type', 'application/json')\n }\n const response = await fetch(`${domain}/${realm}/${this.clientId}${url}`, {\n headers,\n method: body ? 'POST' : 'GET',\n body: body ? JSON.stringify(body) : undefined\n })\n if (response.status < 200 || response.status >= 300) {\n throw new Error(response.statusText)\n }\n return response.json()\n }\n\n private rid() {\n return nanoid()\n }\n\n public socket(action: string, handleMessage = (data: any) => { }, ignoreClose = false) {\n const domain = this.test ? 'ws://localhost:3030' : 'wss://stream.beta.serverbench.io'\n let ws = new WebSocket(`${domain}?${new URLSearchParams({\n key: this.clientSecret,\n })}`)\n let i = 0\n let expecting = this.rid()\n ws.onopen = () => {\n i = 0\n ws.send(JSON.stringify({\n action: `community.${this.clientId}.${action}`,\n rid: expecting\n }))\n }\n ws.onmessage = (event) => {\n const data = JSON.parse(event.data)\n if (data.rid != expecting) {\n return\n }\n if (data.result != null && ((Array.isArray(data.result) && data.result.length) || Object.keys(data.result).length > 0)) {\n handleMessage(data.result)\n } else {\n let action = [data.realm]\n if (data.realm == 'community') {\n action.push(this.clientId)\n }\n action.push(data.action)\n expecting = this.rid()\n ws.send(JSON.stringify({\n action: action.join('.'),\n rid: expecting\n }))\n }\n }\n if (!ignoreClose) {\n ws.onclose = () => {\n i++\n setTimeout(() => {\n ws = this.socket(action, handleMessage, true).ws\n }, Math.min(1000 * (i) * 5, 30 * 1000));\n }\n }\n return {\n dispose: () => {\n ws.onclose = null\n ws.close()\n },\n ws\n }\n }\n\n async get(realm: string, url: string) {\n return this.fetch(realm, url)\n }\n\n async post(realm: string, url: string, body: any = {}) {\n return this.fetch(realm, url, body)\n }\n\n}"],"mappings":"wHAAA,OAAS,UAAAA,MAAc,oBAKvB,IAAqBC,EAArB,MAAqBA,CAAY,CAQrB,YAAYC,EAAkBC,EAAsBC,EAAe,CACvE,KAAK,SAAWF,EAChB,KAAK,aAAeC,EACpB,KAAK,KAAOC,CAChB,CAEA,OAAO,IAAIF,EAAkBC,EAAsBC,EAAgB,GAAO,CACtE,OAAI,CAACH,EAAY,UAAYA,EAAY,SAAS,WAAaC,GAAYD,EAAY,SAAS,eAAiBE,GAAgBF,EAAY,SAAS,OAASG,KAC3JH,EAAY,SAAW,IAAIA,EAAYC,EAAUC,EAAcC,CAAI,GAEhEH,EAAY,Q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,EAAK,KAAOI,EAGhB,GAAIJ,EAAK,QAAU,OAAU,MAAM,QAAQA,EAAK,MAAM,GAAKA,EAAK,OAAO,QAAW,OAAO,KAAKA,EAAK,MAAM,EAAE,OAAS,GAChHD,EAAcC,EAAK,MAAM,MACtB,CACH,IAAIF,EAAS,CAACE,EAAK,KAAK,EACpBA,EAAK,OAAS,aACdF,EAAO,KAAK,KAAK,QAAQ,EAE7BA,EAAO,KAAKE,EAAK,MAAM,EACvBI,EAAY,KAAK,IAAI,EACrBF,EAAG,KAAK,KAAK,UAAU,CACnB,OAAQJ,EAAO,KAAK,GAAG,EACvB,IAAKM,CACT,CAAC,CAAC,CACN,CACJ,EACKH,IACDC,EAAG,QAAU,IAAM,CACfC,IACA,WAAW,IAAM,CACbD,EAAK,KAAK,OAAOJ,EAAQC,EAAe,EAAI,EAAE,EAClD,EAAG,KAAK,IAAI,IAAQI,EAAK,EAAG,GAAK,GAAI,CAAC,CAC1C,GAEG,CACH,QAAS,IAAM,CACXD,EAAG,QAAU,KACbA,EAAG,MAAM,CACb,EACA,GAAAA,CACJ,CACJ,CAEA,MAAM,IAAIX,EAAeC,EAAa,CAClC,OAAO,KAAK,MAAMD,EAAOC,CAAG,CAChC,CAEA,MAAM,KAAKD,EAAeC,EAAaC,EAAY,CAAC,EAAG,CACnD,OAAO,KAAK,MAAMF,EAAOC,EAAKC,CAAI,CACtC,CAEJ,EAtHqBV,EAMF,SAA+B,KANlD,IAAqBuB,EAArBvB","names":["nanoid","_Serverbench","clientId","clientSecret","test","Store","Voting","find","Member","realm","url","body","domain","headers","response","nanoid","action","handleMessage","data","ignoreClose","ws","i","expecting","event","Serverbench"]}
|