@chirper/node 0.0.81 → 0.0.82

Sign up to get free protection for your applications and to get access to all the features.
package/dist/bundle.js CHANGED
@@ -1 +1 @@
1
- var ht=Object.create;var C=Object.defineProperty;var ct=Object.getOwnPropertyDescriptor;var at=Object.getOwnPropertyNames;var dt=Object.getPrototypeOf,ft=Object.prototype.hasOwnProperty;var D=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),pt=(r,t)=>{for(var e in t)C(r,e,{get:t[e],enumerable:!0})},A=(r,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of at(t))!ft.call(r,o)&&o!==e&&C(r,o,{get:()=>t[o],enumerable:!(i=ct(t,o))||i.enumerable});return r};var L=(r,t,e)=>(e=r!=null?ht(dt(r)):{},A(t||!r||!r.__esModule?C(e,"default",{value:r,enumerable:!0}):e,r)),gt=r=>A(C({},"__esModule",{value:!0}),r);var F=D((yt,E)=>{var U=(()=>{var r=Object.defineProperty,t=Object.getOwnPropertySymbols,e=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,o=(v,d,p)=>d in v?r(v,d,{enumerable:!0,configurable:!0,writable:!0,value:p}):v[d]=p,l=(v,d)=>{for(var p in d||(d={}))e.call(d,p)&&o(v,p,d[p]);if(t)for(var p of t(d))i.call(d,p)&&o(v,p,d[p]);return v},u=v=>r(v,"__esModule",{value:!0}),$=(v,d)=>{u(v);for(var p in d)r(v,p,{get:d[p],enumerable:!0})},s={};$(s,{DEFAULT_UUID_LENGTH:()=>m,default:()=>y});var w="4.4.4",m=6,h={dictionary:"alphanum",shuffle:!0,debug:!1,length:m},b=class extends Function{constructor(v={}){super(),this.dictIndex=0,this.dictRange=[],this.lowerBound=0,this.upperBound=0,this.dictLength=0,this._digit_first_ascii=48,this._digit_last_ascii=58,this._alpha_lower_first_ascii=97,this._alpha_lower_last_ascii=123,this._hex_last_ascii=103,this._alpha_upper_first_ascii=65,this._alpha_upper_last_ascii=91,this._number_dict_ranges={digits:[this._digit_first_ascii,this._digit_last_ascii]},this._alpha_dict_ranges={lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii],upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]},this._alpha_lower_dict_ranges={lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii]},this._alpha_upper_dict_ranges={upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]},this._alphanum_dict_ranges={digits:[this._digit_first_ascii,this._digit_last_ascii],lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii],upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]},this._alphanum_lower_dict_ranges={digits:[this._digit_first_ascii,this._digit_last_ascii],lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii]},this._alphanum_upper_dict_ranges={digits:[this._digit_first_ascii,this._digit_last_ascii],upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]},this._hex_dict_ranges={decDigits:[this._digit_first_ascii,this._digit_last_ascii],alphaDigits:[this._alpha_lower_first_ascii,this._hex_last_ascii]},this.log=(...n)=>{let c=[...n];if(c[0]=`[short-unique-id] ${n[0]}`,this.debug===!0&&typeof console<"u"&&console!==null)return console.log(...c)},this.setDictionary=(n,c)=>{let a;if(n&&Array.isArray(n)&&n.length>1)a=n;else{a=[];let g;this.dictIndex=g=0;let x=`_${n}_dict_ranges`,N=this[x];Object.keys(N).forEach(ut=>{let lt=ut;for(this.dictRange=N[lt],this.lowerBound=this.dictRange[0],this.upperBound=this.dictRange[1],this.dictIndex=g=this.lowerBound;this.lowerBound<=this.upperBound?g<this.upperBound:g>this.upperBound;this.dictIndex=this.lowerBound<=this.upperBound?g+=1:g-=1)a.push(String.fromCharCode(this.dictIndex))})}c&&(a=a.sort(()=>Math.random()-.5)),this.dict=a,this.dictLength=this.dict.length,this.counter=0},this.seq=()=>this.sequentialUUID(),this.sequentialUUID=()=>{let n,c,a="";n=this.counter;do c=n%this.dictLength,n=Math.trunc(n/this.dictLength),a+=this.dict[c];while(n!==0);return this.counter+=1,a},this.randomUUID=(n=this.uuidLength||m)=>{let c,a,g;if(n===null||typeof n>"u"||n<1)throw new Error("Invalid UUID Length Provided");let x=n>=0;for(c="",g=0;g<n;g+=1)a=parseInt((Math.random()*this.dictLength).toFixed(0),10)%this.dictLength,c+=this.dict[a];return c},this.availableUUIDs=(n=this.uuidLength)=>parseFloat(Math.pow([...new Set(this.dict)].length,n).toFixed(0)),this.approxMaxBeforeCollision=(n=this.availableUUIDs(this.uuidLength))=>parseFloat(Math.sqrt(Math.PI/2*n).toFixed(20)),this.collisionProbability=(n=this.availableUUIDs(this.uuidLength),c=this.uuidLength)=>parseFloat((this.approxMaxBeforeCollision(n)/this.availableUUIDs(c)).toFixed(20)),this.uniqueness=(n=this.availableUUIDs(this.uuidLength))=>{let c=parseFloat((1-this.approxMaxBeforeCollision(n)/n).toFixed(20));return c>1?1:c<0?0:c},this.getVersion=()=>this.version,this.stamp=n=>{if(typeof n!="number"||n<10)throw new Error("Param finalLength must be number greater than 10");let c=Math.floor(+new Date/1e3).toString(16),a=n-9,g=Math.round(Math.random()*(a>15?15:a)),x=this.randomUUID(a);return`${x.substr(0,g)}${c}${x.substr(g)}${g.toString(16)}`},this.parseStamp=n=>{if(n.length<10)throw new Error("Stamp length invalid");let c=parseInt(n.substr(n.length-1,1),16);return new Date(parseInt(n.substr(c,8),16)*1e3)};let d=l(l({},h),v);this.counter=0,this.debug=!1,this.dict=[],this.version=w;let{dictionary:p,shuffle:nt,length:ot}=d;return this.uuidLength=ot,this.setDictionary(p,nt),this.debug=d.debug,this.log(this.dict),this.log(`Generator instantiated with Dictionary Size ${this.dictLength}`),new Proxy(this,{apply:(n,c,a)=>this.randomUUID(...a)})}},y=b;return y.default=b,s})();typeof E<"u"&&(E.exports=U.default),typeof window<"u"&&(U=U.default)});var J=D((xt,k)=>{"use strict";var _t=Object.prototype.hasOwnProperty,_="~";function O(){}Object.create&&(O.prototype=Object.create(null),new O().__proto__||(_=!1));function $t(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function T(r,t,e,i,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var l=new $t(e,i||r,o),u=_?_+t:t;return r._events[u]?r._events[u].fn?r._events[u]=[r._events[u],l]:r._events[u].push(l):(r._events[u]=l,r._eventsCount++),r}function S(r,t){--r._eventsCount===0?r._events=new O:delete r._events[t]}function f(){this._events=new O,this._eventsCount=0}f.prototype.eventNames=function(){var t=[],e,i;if(this._eventsCount===0)return t;for(i in e=this._events)_t.call(e,i)&&t.push(_?i.slice(1):i);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};f.prototype.listeners=function(t){var e=_?_+t:t,i=this._events[e];if(!i)return[];if(i.fn)return[i.fn];for(var o=0,l=i.length,u=new Array(l);o<l;o++)u[o]=i[o].fn;return u};f.prototype.listenerCount=function(t){var e=_?_+t:t,i=this._events[e];return i?i.fn?1:i.length:0};f.prototype.emit=function(t,e,i,o,l,u){var $=_?_+t:t;if(!this._events[$])return!1;var s=this._events[$],w=arguments.length,m,h;if(s.fn){switch(s.once&&this.removeListener(t,s.fn,void 0,!0),w){case 1:return s.fn.call(s.context),!0;case 2:return s.fn.call(s.context,e),!0;case 3:return s.fn.call(s.context,e,i),!0;case 4:return s.fn.call(s.context,e,i,o),!0;case 5:return s.fn.call(s.context,e,i,o,l),!0;case 6:return s.fn.call(s.context,e,i,o,l,u),!0}for(h=1,m=new Array(w-1);h<w;h++)m[h-1]=arguments[h];s.fn.apply(s.context,m)}else{var b=s.length,y;for(h=0;h<b;h++)switch(s[h].once&&this.removeListener(t,s[h].fn,void 0,!0),w){case 1:s[h].fn.call(s[h].context);break;case 2:s[h].fn.call(s[h].context,e);break;case 3:s[h].fn.call(s[h].context,e,i);break;case 4:s[h].fn.call(s[h].context,e,i,o);break;default:if(!m)for(y=1,m=new Array(w-1);y<w;y++)m[y-1]=arguments[y];s[h].fn.apply(s[h].context,m)}}return!0};f.prototype.on=function(t,e,i){return T(this,t,e,i,!1)};f.prototype.once=function(t,e,i){return T(this,t,e,i,!0)};f.prototype.removeListener=function(t,e,i,o){var l=_?_+t:t;if(!this._events[l])return this;if(!e)return S(this,l),this;var u=this._events[l];if(u.fn)u.fn===e&&(!o||u.once)&&(!i||u.context===i)&&S(this,l);else{for(var $=0,s=[],w=u.length;$<w;$++)(u[$].fn!==e||o&&!u[$].once||i&&u[$].context!==i)&&s.push(u[$]);s.length?this._events[l]=s.length===1?s[0]:s:S(this,l)}return this};f.prototype.removeAllListeners=function(t){var e;return t?(e=_?_+t:t,this._events[e]&&S(this,e)):(this._events=new O,this._eventsCount=0),this};f.prototype.off=f.prototype.removeListener;f.prototype.addListener=f.prototype.on;f.prefixed=_;f.EventEmitter=f;typeof k<"u"&&(k.exports=f)});var mt={};pt(mt,{default:()=>I});module.exports=gt(mt);var it=L(F()),st=L(require("socket.io-client"));var P=L(J(),1);var M=r=>({prompt:t=>r.post("/:account/ai",t),image:t=>r.post("/:account/ai/image",t)});var B=r=>({get:(t,e={})=>r.get(`/user/${t}`,e),list:(t={})=>r.get("/user",t),image:(t,e={})=>r.post(`/user/${t?.id||t}/image`,e),update:(t={})=>r.patch(`/user/${t.id}`,t),validate:(t,e,i)=>r.get("/user/value",{key:e,value:i,user:t?.id}),password:(t,e,i)=>r.patch("/user/password",{password:t,newPassword:e,newPassword2:i}),username:(t,e=null)=>r.post("/user/username",{username:t,id:e?.id||e}),suggestion:(t={})=>r.get("/user/suggestion",t),Pin:{list:(t={})=>r.get("/user/pin",t),create:(t={})=>r.post("/user/pin",t),update:(t={})=>r.patch("/user/pin",t),delete:(t={})=>r.delete("/user/pin",t)}});var j=r=>({get:(t,e)=>r.get(`/chat/${t?.id||t}`,e),list:t=>r.get("/chat",t),read:t=>r.get(`/chat/${t?.id||t}/read`),create:(t,e)=>r.post(`/chat/${t?.id||t}`,e),typing:(t,e=!0)=>r.post(`/chat/${t?.id||t}/typing`,{typing:e}),leaveChat:t=>r.delete(`/chat/${t?.id||t}`),readChat:t=>r.post(`/chat/${t?.id||t}/read`),loadMembers:(t,e)=>r.get(`/chat/${t?.id||t}/member`,e),loadMessages:(t,e)=>r.get(`/chat/${t?.id||t}/message`,e),sendMessage:(t,e)=>r.post(`/chat/${t?.id||t}/message`,e),inviteMember:(t,e)=>r.post(`/chat/${t?.id||t}/member`,{member:e?.id||e}),removeMember:(t,e)=>r.delete(`/chat/${t?.id||t}/member/${e?.id||e}`)});var q=r=>({get:(t,e={})=>r.get(`/file/${t?.id||t}`,e),list:(t={})=>r.get("/file",t),modelList:(t={})=>r.get("/file/model",t)});var R=r=>({get:(t,e=null,i=null)=>r.get(`/:account/stat/${t}`,{from:e,to:i})});var K=r=>({get:t=>r.get(`/event/${t}`),list:(t={})=>r.get("/event",t),image:(t,e={})=>r.post(`/event/${t?.id||t}/image`,e),create:t=>r.post("/event",t),update:t=>r.patch(`/event/${t?.id}`,t),delete:t=>r.delete(`/event/${t?.id||t}`),restore:t=>r.post(`/event/${t?.id||t}/cancel`),validate:(t,e,i)=>r.get("/event/value",{key:e,value:i,event:t?.id})});var G=r=>({code:(t,e)=>r.post("/oauth2/code",{application:t,redirect:e})});var H=r=>({get:(t,e)=>r.get(`/chirp/${t}`,{lang:e},!1,!1),list:(t={})=>r.get("/chirp",t,!1,!1),add:(t,e)=>r.post(`/chirp/${t}/add`,{chirper:e?.id||e}),like:t=>r.post(`/chirp/${t}/like`),dislike:t=>r.post(`/chirp/${t}/dislike`),play:t=>r.post(`/chirp/${t}/play`),view:t=>r.post(`/chirp/${t}/view`),liked:t=>r.get(`/chirp/${t}/like`),count:t=>r.get(`/chirp/${t?.id||t}/count`),delete:t=>r.delete(`/chirp/${t?.id||t}`),create:(t={})=>r.post("/chirp",t),subscribe:t=>r.post(`/chirp/${t?.id||t}/subscribe`),unsubscribe:t=>r.delete(`/chirp/${t?.id||t}/subscribe`)});var V=r=>({get:t=>r.get(`/world/${t}`),list:(t={})=>r.get("/world",t),image:(t,e={})=>r.post(`/world/${t?.id||t}/image`,e),invite:(t,e)=>r.post(`/world/${t?.id||t}/invite`,{chirper:e?.id||e}),remove:(t,e)=>r.post(`/world/${t?.id||t}/remove`,{chirper:e?.id||e}),members:(t,e={})=>r.get(`/world/${t?.id||t}/members`,e),alerts:(t={})=>r.get("/world/alerts",t),create:t=>r.post("/world",t),update:t=>r.patch(`/world/${t?.id}`,t),delete:t=>r.delete(`/world/${t?.id||t}`),restore:t=>r.post(`/world/${t?.id||t}/cancel`),validate:(t,e,i)=>r.get("/world/value",{key:e,value:i,world:t?.id})});var W=r=>({like:(t,e={})=>r.post(`/studio/${t?.id||t||"default"}/like`,e),dislike:(t,e={})=>r.post(`/studio/${t?.id||t||"default"}/dislike`,e),liked:(t,e={})=>r.get(`/studio/${t?.id||t||"default"}/like`,e),upload:(t={})=>r.post("/studio/upload",t),complete:(t,e={})=>r.post(`/studio/upload/${t?.id||t||"default"}`,e),generate:(t,e={})=>r.post(`/studio/${t?.id||t||"default"}/generate`,e),Message:{list:(t,e={})=>r.get(`/studio/${t?.id||t||"default"}/message`,e),delete:(t,e,i={})=>r.delete(`/studio/${t?.id||t||"default"}/message/${e?.id||e}`,i)}});var Y=r=>({get:t=>r.get(`/follow/${t}`),toggle:t=>r.post(`/follow/${t?.id||t}`)});var z=r=>({get:(t,e={})=>r.get(`/chirper/${t}`,e),list:(t={})=>r.get("/chirper",t),spec:(t,e)=>r.post(`/chirper/${t?.id||t}/spec`,{type:e}),bump:t=>r.post(`/chirper/${t?.id||t}/bump`),image:(t,e={})=>r.post(`/chirper/${t?.id||t}/image`,e),journal:(t,e)=>r.get(`/chirper/${t?.id||t}/journal`,e),progress:(t,e)=>r.get(`/chirper/${t?.id||t}/progress`,e),username:(t,e=null)=>r.post("/chirper/username",{username:t,id:e?.id||e}),create:(t={})=>r.post("/chirper",t),update:(t={})=>r.patch(`/chirper/${t.id}`,t),delete:t=>r.delete(`/chirper/${t?.id||t}`),toggleRunning:t=>r.post(`/chirper/${t?.id||t}/running`),validate:(t,e,i)=>r.get("/chirper/value",{key:e,value:i,chirper:t?.id}),trip:(t,e={})=>r.get(`/chirper/${t?.id||t}/trip`,e),Trip:{list:(t,e={})=>r.get(`/chirper/${t?.id||t}/trip`,e),get:(t,e={})=>r.get(`/chirper/trip/${t?.id||t}`,e)}});var Q=r=>({list:({lang:t}={})=>r.get("/trending",{lang:t},!1,!1)});var X=r=>({list:t=>r.get("/activity",t),count:t=>r.get("/activity/count",t),read:t=>r.post("/activity/count",t)});var Z=r=>({get:t=>r.get(`/category/${t?.id||t}`,{}),list:t=>r.get("/category",t)});var tt=r=>({get:t=>r.get(`/adventure/${t}`),list:(t={})=>r.get("/adventure",t),image:(t,e={})=>r.post(`/adventure/${t?.id||t}/image`,e),invite:(t,e)=>r.post(`/adventure/${t?.id||t}/invite`,{chirper:e?.id||e}),remove:(t,e)=>r.post(`/adventure/${t?.id||t}/remove`,{chirper:e?.id||e}),members:(t,e={})=>r.get(`/adventure/${t?.id||t}/members`,e),alerts:(t={})=>r.get("/adventure/alerts",t),choices:(t,e=null)=>r.get(`/adventure/${t?.id||t}/choices`,{parent:e?.id||e}),create:t=>r.post("/adventure",t),update:t=>r.patch(`/adventure/${t?.id}`,t),delete:t=>r.delete(`/adventure/${t?.id||t}`),restore:t=>r.post(`/adventure/${t?.id||t}/cancel`),validate:(t,e,i)=>r.get("/adventure/value",{key:e,value:i,adventure:t?.id}),Page:{create:(t,e,i)=>r.post(`/adventure/${t?.id||t}/page`,{decision:e,parent:i?.id||i})}});var et=r=>({get:t=>r.get(`/application/${t?.id||t}`,{}),list:t=>r.get("/application",t),create:t=>r.post("/application",t),update:(t,e)=>r.patch(`/application/${t?.id||t}`,e),secret:(t,e)=>r.get(`/application/${t?.id||t}/secret`,e)});var rt=r=>({list:t=>r.get("/notification",t),count:t=>r.get("/notification/count",t),read:t=>r.post("/notification/count",t)});var vt=new it.default({length:10}),I=class{constructor({url:t,version:e,options:i={}}){this.key=null;this.url=null;this.cache={};this.events=new P.default;this.call=null;this.socket=null;this.account=null;this.version="v1";this.loading=!0;this.authing=null;this.authKey=null;this.shareKey=null;this.customer=null;this.presences={};this.connecting=null;this.extraOptions={};this.options={path:"/ws",cors:!0,agent:!0,reconnect:!0,transports:["websocket"],withCredentials:!0};t&&(this.url=t),e&&(this.version=e),i&&(this.extraOptions=i),this.build=this.build.bind(this),this.fetch=this.fetch.bind(this),this.wsFetch=this.wsFetch.bind(this),this.on=this.on.bind(this),this.off=this.off.bind(this),this.emit=this.emit.bind(this),this.once=this.once.bind(this),this.addListener=this.events.addListener.bind(this.events),this.removeListener=this.events.removeListener.bind(this.events),this.get=this.get.bind(this),this.put=this.put.bind(this),this.post=this.post.bind(this),this.patch=this.patch.bind(this),this.delete=this.delete.bind(this),this.AI=M(this),this.File=q(this),this.User=B(this),this.Chat=j(this),this.Stat=R(this),this.Event=K(this),this.OAuth=G(this),this.Chirp=H(this),this.World=V(this),this.Studio=W(this),this.Follow=Y(this),this.Chirper=z(this),this.Trending=Q(this),this.Activity=X(this),this.Category=Z(this),this.Adventure=tt(this),this.Application=et(this),this.Notification=rt(this),this.build()}build(){if(this.__resolveConnecting=null,this.connecting=new Promise(e=>{this.__resolveConnecting=e}),!this.url)return;let t=st.default.connect(`${this.url}`,{...this.options,...this.extraOptions});t.on("connect",async(...e)=>{this.authing||(this.authing=this.auth(this.authKey,this.shareKey),await this.authing,this.authing=null,this.__resolveConnecting())}),t.on("disconnect",()=>{this.connecting=new Promise(e=>{this.__resolveConnecting=e})}),this.socket=t}async auth(t){!t&&this.user&&(t=this.user),t||(this.loading=!0,this.events.emit("loading",!0),t=(await this.get("/auth",{key:this.key},!1,!1))?.user),t&&(this.user=t,this.events.emit("user",t)),this.loading=!1,this.events.emit("loading",!1),typeof window<"u"&&(window.chirper=this)}async fetch(t,e,i={},o=!1){if(["patch","put","delete","post"].includes(t.toLowerCase())&&(o=!1),o&&this.cache[`${t}${e}${JSON.stringify(i)}`])return this.cache[`${t}${e}${JSON.stringify(i)}`];delete this.cache[`${t}${e}${JSON.stringify(i)}`],console.time(`[chirper] [fetch] ${t}:${e} ${JSON.stringify(i)}`),Object.keys(i).forEach(u=>{i[u]===void 0&&delete i[u]});let l;try{l=await(await fetch(`${this.url}/${this.version}${e}${`${t}`.toLowerCase()==="get"?`?${new URLSearchParams(i)}`:""}`,{body:`${t}`.toLowerCase()!=="get"?JSON.stringify(i):void 0,headers:{"Content-Type":"application/json",Authentication:this.key?`Bearer ${this.key}`:void 0},credentials:"include"})).json()}catch(u){throw console.timeEnd(`[chirper] [fetch] ${t}:${e} ${JSON.stringify(i)}`),u}if(console.timeEnd(`[chirper] [fetch] ${t}:${e} ${JSON.stringify(i)}`),!l?.success)throw new Error(l.message);return o&&(this.cache[`${t}${e}${JSON.stringify(i)}`]=l,this.cache[`${t}${e}${JSON.stringify(i)}`].then(()=>{typeof o=="number"?setTimeout(()=>{delete this.cache[`${t}${e}${JSON.stringify(i)}`]},o):delete this.cache[`${t}${e}${JSON.stringify(i)}`]})),l.result}async wsFetch(t,e,i={},o=!1,l=!0){if(l&&await this.connecting,l&&await this.authing,["patch","put","delete","post"].includes(t.toLowerCase())&&(o=!1),o&&this.cache[`${t}${e}${JSON.stringify(i)}`])return this.cache[`${t}${e}${JSON.stringify(i)}`];delete this.cache[`${t}${e}${JSON.stringify(i)}`];let u=vt();console.time(`[chirper] [${u}] ${t}:${e} ${JSON.stringify(i)}`);let $=new Promise((s,w)=>{this.socket.once(u,({success:m,result:h,message:b})=>{if(console.timeEnd(`[chirper] [${u}] ${t}:${e} ${JSON.stringify(i)}`),m)return s(h);w(b)})});return o&&(this.cache[`${t}${e}${JSON.stringify(i)}`]=$,this.cache[`${t}${e}${JSON.stringify(i)}`].then(()=>{typeof o=="number"?setTimeout(()=>{delete this.cache[`${t}${e}${JSON.stringify(i)}`]},o):delete this.cache[`${t}${e}${JSON.stringify(i)}`]})),this.socket.emit("call",u,t.toUpperCase(),e,i),$}on(...t){this.socket.on(...t)}off(...t){this.socket.off(...t)}emit(...t){this.socket.emit(...t)}once(...t){this.socket.once(...t)}get(t,e,...i){return this.wsFetch("GET",`/${this.version}${t}`,e,...i)}put(t,e,...i){return this.wsFetch("PUT",`/${this.version}${t}`,e,...i)}post(t,e,...i){return this.wsFetch("POST",`/${this.version}${t}`,e,...i)}patch(t,e,...i){return this.wsFetch("PATCH",`/${this.version}${t}`,e,...i)}delete(t,e,...i){return this.wsFetch("DELETE",`/${this.version}${t}`,e,...i)}};
1
+ var ht=Object.create;var S=Object.defineProperty;var at=Object.getOwnPropertyDescriptor;var ct=Object.getOwnPropertyNames;var dt=Object.getPrototypeOf,ft=Object.prototype.hasOwnProperty;var F=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),pt=(i,t)=>{for(var e in t)S(i,e,{get:t[e],enumerable:!0})},J=(i,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ct(t))!ft.call(i,o)&&o!==e&&S(i,o,{get:()=>t[o],enumerable:!(r=at(t,o))||r.enumerable});return i};var C=(i,t,e)=>(e=i!=null?ht(dt(i)):{},J(t||!i||!i.__esModule?S(e,"default",{value:i,enumerable:!0}):e,i)),gt=i=>J(S({},"__esModule",{value:!0}),i);var T=F((yt,k)=>{var U=(()=>{var i=Object.defineProperty,t=Object.getOwnPropertySymbols,e=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable,o=(f,c,g)=>c in f?i(f,c,{enumerable:!0,configurable:!0,writable:!0,value:g}):f[c]=g,l=(f,c)=>{for(var g in c||(c={}))e.call(c,g)&&o(f,g,c[g]);if(t)for(var g of t(c))r.call(c,g)&&o(f,g,c[g]);return f},u=f=>i(f,"__esModule",{value:!0}),m=(f,c)=>{u(f);for(var g in c)i(f,g,{get:c[g],enumerable:!0})},s={};m(s,{DEFAULT_UUID_LENGTH:()=>v,default:()=>y});var w="4.4.4",v=6,h={dictionary:"alphanum",shuffle:!0,debug:!1,length:v},b=class extends Function{constructor(f={}){super(),this.dictIndex=0,this.dictRange=[],this.lowerBound=0,this.upperBound=0,this.dictLength=0,this._digit_first_ascii=48,this._digit_last_ascii=58,this._alpha_lower_first_ascii=97,this._alpha_lower_last_ascii=123,this._hex_last_ascii=103,this._alpha_upper_first_ascii=65,this._alpha_upper_last_ascii=91,this._number_dict_ranges={digits:[this._digit_first_ascii,this._digit_last_ascii]},this._alpha_dict_ranges={lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii],upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]},this._alpha_lower_dict_ranges={lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii]},this._alpha_upper_dict_ranges={upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]},this._alphanum_dict_ranges={digits:[this._digit_first_ascii,this._digit_last_ascii],lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii],upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]},this._alphanum_lower_dict_ranges={digits:[this._digit_first_ascii,this._digit_last_ascii],lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii]},this._alphanum_upper_dict_ranges={digits:[this._digit_first_ascii,this._digit_last_ascii],upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]},this._hex_dict_ranges={decDigits:[this._digit_first_ascii,this._digit_last_ascii],alphaDigits:[this._alpha_lower_first_ascii,this._hex_last_ascii]},this.log=(...n)=>{let a=[...n];if(a[0]=`[short-unique-id] ${n[0]}`,this.debug===!0&&typeof console<"u"&&console!==null)return console.log(...a)},this.setDictionary=(n,a)=>{let d;if(n&&Array.isArray(n)&&n.length>1)d=n;else{d=[];let _;this.dictIndex=_=0;let x=`_${n}_dict_ranges`,D=this[x];Object.keys(D).forEach(ut=>{let lt=ut;for(this.dictRange=D[lt],this.lowerBound=this.dictRange[0],this.upperBound=this.dictRange[1],this.dictIndex=_=this.lowerBound;this.lowerBound<=this.upperBound?_<this.upperBound:_>this.upperBound;this.dictIndex=this.lowerBound<=this.upperBound?_+=1:_-=1)d.push(String.fromCharCode(this.dictIndex))})}a&&(d=d.sort(()=>Math.random()-.5)),this.dict=d,this.dictLength=this.dict.length,this.counter=0},this.seq=()=>this.sequentialUUID(),this.sequentialUUID=()=>{let n,a,d="";n=this.counter;do a=n%this.dictLength,n=Math.trunc(n/this.dictLength),d+=this.dict[a];while(n!==0);return this.counter+=1,d},this.randomUUID=(n=this.uuidLength||v)=>{let a,d,_;if(n===null||typeof n>"u"||n<1)throw new Error("Invalid UUID Length Provided");let x=n>=0;for(a="",_=0;_<n;_+=1)d=parseInt((Math.random()*this.dictLength).toFixed(0),10)%this.dictLength,a+=this.dict[d];return a},this.availableUUIDs=(n=this.uuidLength)=>parseFloat(Math.pow([...new Set(this.dict)].length,n).toFixed(0)),this.approxMaxBeforeCollision=(n=this.availableUUIDs(this.uuidLength))=>parseFloat(Math.sqrt(Math.PI/2*n).toFixed(20)),this.collisionProbability=(n=this.availableUUIDs(this.uuidLength),a=this.uuidLength)=>parseFloat((this.approxMaxBeforeCollision(n)/this.availableUUIDs(a)).toFixed(20)),this.uniqueness=(n=this.availableUUIDs(this.uuidLength))=>{let a=parseFloat((1-this.approxMaxBeforeCollision(n)/n).toFixed(20));return a>1?1:a<0?0:a},this.getVersion=()=>this.version,this.stamp=n=>{if(typeof n!="number"||n<10)throw new Error("Param finalLength must be number greater than 10");let a=Math.floor(+new Date/1e3).toString(16),d=n-9,_=Math.round(Math.random()*(d>15?15:d)),x=this.randomUUID(d);return`${x.substr(0,_)}${a}${x.substr(_)}${_.toString(16)}`},this.parseStamp=n=>{if(n.length<10)throw new Error("Stamp length invalid");let a=parseInt(n.substr(n.length-1,1),16);return new Date(parseInt(n.substr(a,8),16)*1e3)};let c=l(l({},h),f);this.counter=0,this.debug=!1,this.dict=[],this.version=w;let{dictionary:g,shuffle:nt,length:ot}=c;return this.uuidLength=ot,this.setDictionary(g,nt),this.debug=c.debug,this.log(this.dict),this.log(`Generator instantiated with Dictionary Size ${this.dictLength}`),new Proxy(this,{apply:(n,a,d)=>this.randomUUID(...d)})}},y=b;return y.default=b,s})();typeof k<"u"&&(k.exports=U.default),typeof window<"u"&&(U=U.default)});var B=F((xt,E)=>{"use strict";var _t=Object.prototype.hasOwnProperty,$="~";function O(){}Object.create&&(O.prototype=Object.create(null),new O().__proto__||($=!1));function $t(i,t,e){this.fn=i,this.context=t,this.once=e||!1}function A(i,t,e,r,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var l=new $t(e,r||i,o),u=$?$+t:t;return i._events[u]?i._events[u].fn?i._events[u]=[i._events[u],l]:i._events[u].push(l):(i._events[u]=l,i._eventsCount++),i}function I(i,t){--i._eventsCount===0?i._events=new O:delete i._events[t]}function p(){this._events=new O,this._eventsCount=0}p.prototype.eventNames=function(){var t=[],e,r;if(this._eventsCount===0)return t;for(r in e=this._events)_t.call(e,r)&&t.push($?r.slice(1):r);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};p.prototype.listeners=function(t){var e=$?$+t:t,r=this._events[e];if(!r)return[];if(r.fn)return[r.fn];for(var o=0,l=r.length,u=new Array(l);o<l;o++)u[o]=r[o].fn;return u};p.prototype.listenerCount=function(t){var e=$?$+t:t,r=this._events[e];return r?r.fn?1:r.length:0};p.prototype.emit=function(t,e,r,o,l,u){var m=$?$+t:t;if(!this._events[m])return!1;var s=this._events[m],w=arguments.length,v,h;if(s.fn){switch(s.once&&this.removeListener(t,s.fn,void 0,!0),w){case 1:return s.fn.call(s.context),!0;case 2:return s.fn.call(s.context,e),!0;case 3:return s.fn.call(s.context,e,r),!0;case 4:return s.fn.call(s.context,e,r,o),!0;case 5:return s.fn.call(s.context,e,r,o,l),!0;case 6:return s.fn.call(s.context,e,r,o,l,u),!0}for(h=1,v=new Array(w-1);h<w;h++)v[h-1]=arguments[h];s.fn.apply(s.context,v)}else{var b=s.length,y;for(h=0;h<b;h++)switch(s[h].once&&this.removeListener(t,s[h].fn,void 0,!0),w){case 1:s[h].fn.call(s[h].context);break;case 2:s[h].fn.call(s[h].context,e);break;case 3:s[h].fn.call(s[h].context,e,r);break;case 4:s[h].fn.call(s[h].context,e,r,o);break;default:if(!v)for(y=1,v=new Array(w-1);y<w;y++)v[y-1]=arguments[y];s[h].fn.apply(s[h].context,v)}}return!0};p.prototype.on=function(t,e,r){return A(this,t,e,r,!1)};p.prototype.once=function(t,e,r){return A(this,t,e,r,!0)};p.prototype.removeListener=function(t,e,r,o){var l=$?$+t:t;if(!this._events[l])return this;if(!e)return I(this,l),this;var u=this._events[l];if(u.fn)u.fn===e&&(!o||u.once)&&(!r||u.context===r)&&I(this,l);else{for(var m=0,s=[],w=u.length;m<w;m++)(u[m].fn!==e||o&&!u[m].once||r&&u[m].context!==r)&&s.push(u[m]);s.length?this._events[l]=s.length===1?s[0]:s:I(this,l)}return this};p.prototype.removeAllListeners=function(t){var e;return t?(e=$?$+t:t,this._events[e]&&I(this,e)):(this._events=new O,this._eventsCount=0),this};p.prototype.off=p.prototype.removeListener;p.prototype.addListener=p.prototype.on;p.prefixed=$;p.EventEmitter=p;typeof E<"u"&&(E.exports=p)});var vt={};pt(vt,{default:()=>L});module.exports=gt(vt);var it=C(require("pako")),rt=C(T()),st=C(require("socket.io-client")),P=require("compress-json");var N=C(B(),1);var M=i=>({prompt:t=>i.post("/:account/ai",t),image:t=>i.post("/:account/ai/image",t)});var q=i=>({get:(t,e={})=>i.get(`/user/${t}`,e),list:(t={})=>i.get("/user",t),image:(t,e={})=>i.post(`/user/${t?.id||t}/image`,e),update:(t={})=>i.patch(`/user/${t.id}`,t),validate:(t,e,r)=>i.get("/user/value",{key:e,value:r,user:t?.id}),password:(t,e,r)=>i.patch("/user/password",{password:t,newPassword:e,newPassword2:r}),username:(t,e=null)=>i.post("/user/username",{username:t,id:e?.id||e}),suggestion:(t={})=>i.get("/user/suggestion",t),Pin:{list:(t={})=>i.get("/user/pin",t),create:(t={})=>i.post("/user/pin",t),update:(t={})=>i.patch("/user/pin",t),delete:(t={})=>i.delete("/user/pin",t)}});var j=i=>({get:(t,e)=>i.get(`/chat/${t?.id||t}`,e),list:t=>i.get("/chat",t),read:t=>i.get(`/chat/${t?.id||t}/read`),create:(t,e)=>i.post(`/chat/${t?.id||t}`,e),typing:(t,e=!0)=>i.post(`/chat/${t?.id||t}/typing`,{typing:e}),leaveChat:t=>i.delete(`/chat/${t?.id||t}`),readChat:t=>i.post(`/chat/${t?.id||t}/read`),loadMembers:(t,e)=>i.get(`/chat/${t?.id||t}/member`,e),loadMessages:(t,e)=>i.get(`/chat/${t?.id||t}/message`,e),sendMessage:(t,e)=>i.post(`/chat/${t?.id||t}/message`,e),inviteMember:(t,e)=>i.post(`/chat/${t?.id||t}/member`,{member:e?.id||e}),removeMember:(t,e)=>i.delete(`/chat/${t?.id||t}/member/${e?.id||e}`)});var R=i=>({get:(t,e={})=>i.get(`/file/${t?.id||t}`,e),list:(t={})=>i.get("/file",t),modelList:(t={})=>i.get("/file/model",t)});var K=i=>({get:(t,e=null,r=null)=>i.get(`/:account/stat/${t}`,{from:e,to:r})});var G=i=>({code:(t,e)=>i.post("/oauth2/code",{application:t,redirect:e})});var H=i=>({get:(t,e)=>i.get(`/chirp/${t}`,{lang:e},!1,!1),list:(t={})=>i.get("/chirp",t,!1,!1),add:(t,e)=>i.post(`/chirp/${t}/add`,{chirper:e?.id||e}),like:t=>i.post(`/chirp/${t}/like`),dislike:t=>i.post(`/chirp/${t}/dislike`),play:t=>i.post(`/chirp/${t}/play`),view:t=>i.post(`/chirp/${t}/view`),liked:t=>i.get(`/chirp/${t}/like`),count:t=>i.get(`/chirp/${t?.id||t}/count`),delete:t=>i.delete(`/chirp/${t?.id||t}`),create:(t={})=>i.post("/chirp",t),subscribe:t=>i.post(`/chirp/${t?.id||t}/subscribe`),unsubscribe:t=>i.delete(`/chirp/${t?.id||t}/subscribe`)});var z=i=>({get:t=>i.get(`/world/${t}`),list:(t={})=>i.get("/world",t),image:(t,e={})=>i.post(`/world/${t?.id||t}/image`,e),invite:(t,e)=>i.post(`/world/${t?.id||t}/invite`,{chirper:e?.id||e}),remove:(t,e)=>i.post(`/world/${t?.id||t}/remove`,{chirper:e?.id||e}),members:(t,e={})=>i.get(`/world/${t?.id||t}/members`,e),alerts:(t={})=>i.get("/world/alerts",t),create:t=>i.post("/world",t),update:t=>i.patch(`/world/${t?.id}`,t),delete:t=>i.delete(`/world/${t?.id||t}`),restore:t=>i.post(`/world/${t?.id||t}/cancel`),validate:(t,e,r)=>i.get("/world/value",{key:e,value:r,world:t?.id})});var V=i=>({get:(t,e={})=>i.get(`/brain/${t}`,e),list:(t={})=>i.get("/brain",t),run:(t,e={})=>i.post(`/brain/${t?.id||t}/run`,e),create:(t={})=>i.post("/brain",t),update:(t={})=>i.patch(`/brain/${t.id}`,t),delete:t=>i.delete(`/brain/${t?.id||t}`),validate:(t,e,r)=>i.get("/brain/value",{key:e,value:r,brain:t?.id}),Frame:{list:(t,e={})=>i.get(`/brain/${t?.id||t}/frame`,e)}});var W=i=>({like:(t,e={})=>i.post(`/studio/${t?.id||t||"default"}/like`,e),dislike:(t,e={})=>i.post(`/studio/${t?.id||t||"default"}/dislike`,e),liked:(t,e={})=>i.get(`/studio/${t?.id||t||"default"}/like`,e),upload:(t={})=>i.post("/studio/upload",t),complete:(t,e={})=>i.post(`/studio/upload/${t?.id||t||"default"}`,e),generate:(t,e={})=>i.post(`/studio/${t?.id||t||"default"}/generate`,e),Message:{list:(t,e={})=>i.get(`/studio/${t?.id||t||"default"}/message`,e),delete:(t,e,r={})=>i.delete(`/studio/${t?.id||t||"default"}/message/${e?.id||e}`,r)}});var Y=i=>({get:t=>i.get(`/follow/${t}`),toggle:t=>i.post(`/follow/${t?.id||t}`)});var Q=i=>({get:(t,e={})=>i.get(`/chirper/${t}`,e),list:(t={})=>i.get("/chirper",t),spec:(t,e)=>i.post(`/chirper/${t?.id||t}/spec`,{type:e}),bump:t=>i.post(`/chirper/${t?.id||t}/bump`),image:(t,e={})=>i.post(`/chirper/${t?.id||t}/image`,e),journal:(t,e)=>i.get(`/chirper/${t?.id||t}/journal`,e),progress:(t,e)=>i.get(`/chirper/${t?.id||t}/progress`,e),username:(t,e=null)=>i.post("/chirper/username",{username:t,id:e?.id||e}),create:(t={})=>i.post("/chirper",t),update:(t={})=>i.patch(`/chirper/${t.id}`,t),delete:t=>i.delete(`/chirper/${t?.id||t}`),toggleRunning:t=>i.post(`/chirper/${t?.id||t}/running`),validate:(t,e,r)=>i.get("/chirper/value",{key:e,value:r,chirper:t?.id}),trip:(t,e={})=>i.get(`/chirper/${t?.id||t}/trip`,e),Trip:{list:(t,e={})=>i.get(`/chirper/${t?.id||t}/trip`,e),get:(t,e={})=>i.get(`/chirper/trip/${t?.id||t}`,e)}});var X=i=>({list:({lang:t}={})=>i.get("/trending",{lang:t},!1,!1)});var Z=i=>({get:t=>i.get(`/category/${t?.id||t}`,{}),list:t=>i.get("/category",t)});var tt=i=>({get:t=>i.get(`/application/${t?.id||t}`,{}),list:t=>i.get("/application",t),create:t=>i.post("/application",t),update:(t,e)=>i.patch(`/application/${t?.id||t}`,e),secret:(t,e)=>i.get(`/application/${t?.id||t}/secret`,e)});var et=i=>({list:t=>i.get("/notification",t),count:t=>i.get("/notification/count",t),read:t=>i.post("/notification/count",t)});var mt=new rt.default({length:10}),L=class{constructor({url:t,version:e,options:r={}}){this.key=null;this.url=null;this.cache={};this.events=new N.default;this.call=null;this.socket=null;this.account=null;this.version="v1";this.loading=!0;this.authing=null;this.authKey=null;this.shareKey=null;this.customer=null;this.presences={};this.connecting=null;this.extraOptions={};this.options={path:"/ws",cors:!0,agent:!0,reconnect:!0,transports:["websocket"],withCredentials:!0};t&&(this.url=t),e&&(this.version=e),r&&(this.extraOptions=r),this.build=this.build.bind(this),this.fetch=this.fetch.bind(this),this.wsFetch=this.wsFetch.bind(this),this.on=this.on.bind(this),this.off=this.off.bind(this),this.emit=this.emit.bind(this),this.once=this.once.bind(this),this.addListener=this.events.addListener.bind(this.events),this.removeListener=this.events.removeListener.bind(this.events),this.get=this.get.bind(this),this.put=this.put.bind(this),this.post=this.post.bind(this),this.patch=this.patch.bind(this),this.delete=this.delete.bind(this),this.AI=M(this),this.File=R(this),this.User=q(this),this.Chat=j(this),this.Stat=K(this),this.OAuth=G(this),this.Chirp=H(this),this.Brain=V(this),this.World=z(this),this.Studio=W(this),this.Follow=Y(this),this.Chirper=Q(this),this.Trending=X(this),this.Category=Z(this),this.Application=tt(this),this.Notification=et(this),this.build()}build(){if(this.__resolveConnecting=null,this.connecting=new Promise(r=>{this.__resolveConnecting=r}),!this.url)return;let t={...this.options,...this.extraOptions};t.query||(t.query={}),t.query.compression=!0;let e=st.default.connect(`${this.url}`,t);e.on("connect",async(...r)=>{this.authing||(this.authing=this.auth(this.authKey,this.shareKey),await this.authing,this.authing=null,this.__resolveConnecting())}),e.on("disconnect",()=>{this.connecting=new Promise(r=>{this.__resolveConnecting=r})}),this.socket=e}async auth(t){!t&&this.user&&(t=this.user),t||(this.loading=!0,this.events.emit("loading",!0),t=(await this.get("/auth",{key:this.key},!1,!1))?.user),t&&(this.user=t,this.events.emit("user",t)),this.loading=!1,this.events.emit("loading",!1),typeof window<"u"&&(window.chirper=this)}async fetch(t,e,r={},o=!1){if(["patch","put","delete","post"].includes(t.toLowerCase())&&(o=!1),o&&this.cache[`${t}${e}${JSON.stringify(r)}`])return this.cache[`${t}${e}${JSON.stringify(r)}`];delete this.cache[`${t}${e}${JSON.stringify(r)}`],console.time(`[chirper] [fetch] ${t}:${e} ${JSON.stringify(r)}`),Object.keys(r).forEach(u=>{r[u]===void 0&&delete r[u]});let l;try{l=await(await fetch(`${this.url}/${this.version}${e}${`${t}`.toLowerCase()==="get"?`?${new URLSearchParams(r)}`:""}`,{body:`${t}`.toLowerCase()!=="get"?JSON.stringify(r):void 0,headers:{"Content-Type":"application/json",Authentication:this.key?`Bearer ${this.key}`:void 0},credentials:"include"})).json()}catch(u){throw console.timeEnd(`[chirper] [fetch] ${t}:${e} ${JSON.stringify(r)}`),u}if(console.timeEnd(`[chirper] [fetch] ${t}:${e} ${JSON.stringify(r)}`),!l?.success)throw new Error(l.message);return o&&(this.cache[`${t}${e}${JSON.stringify(r)}`]=l,this.cache[`${t}${e}${JSON.stringify(r)}`].then(()=>{typeof o=="number"?setTimeout(()=>{delete this.cache[`${t}${e}${JSON.stringify(r)}`]},o):delete this.cache[`${t}${e}${JSON.stringify(r)}`]})),l.result}async wsFetch(t,e,r={},o=!1,l=!0){if(l&&await this.connecting,l&&await this.authing,["patch","put","delete","post"].includes(t.toLowerCase())&&(o=!1),o&&this.cache[`${t}${e}${JSON.stringify(r)}`])return this.cache[`${t}${e}${JSON.stringify(r)}`];delete this.cache[`${t}${e}${JSON.stringify(r)}`];let u=mt();console.time(`[chirper] [${u}] ${t}:${e} ${JSON.stringify(r)}`);let m=new Promise((s,w)=>{this.socket.once(u,v=>{let h=it.default.ungzip(v,{to:"string"});console.log((0,P.decompress)(JSON.parse(h)));let{success:b,result:y,message:f,time:c}=(0,P.decompress)(JSON.parse(h));if(console.timeEnd(`[chirper] [${u}] ${t}:${e} ${JSON.stringify(r)}`),console.log(`[chirper] [${u}] backend time ${c}ms`),b)return s(y);w(f)})});return o&&(this.cache[`${t}${e}${JSON.stringify(r)}`]=m,this.cache[`${t}${e}${JSON.stringify(r)}`].then(()=>{typeof o=="number"?setTimeout(()=>{delete this.cache[`${t}${e}${JSON.stringify(r)}`]},o):delete this.cache[`${t}${e}${JSON.stringify(r)}`]})),this.socket.emit("call",u,t.toUpperCase(),e,r),m}on(...t){this.socket.on(...t)}off(...t){this.socket.off(...t)}emit(...t){this.socket.emit(...t)}once(...t){this.socket.once(...t)}get(t,e,...r){return this.wsFetch("GET",`/${this.version}${t}`,e,...r)}put(t,e,...r){return this.wsFetch("PUT",`/${this.version}${t}`,e,...r)}post(t,e,...r){return this.wsFetch("POST",`/${this.version}${t}`,e,...r)}patch(t,e,...r){return this.wsFetch("PATCH",`/${this.version}${t}`,e,...r)}delete(t,e,...r){return this.wsFetch("DELETE",`/${this.version}${t}`,e,...r)}};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chirper/node",
3
- "version": "0.0.81",
3
+ "version": "0.0.82",
4
4
  "description": "",
5
5
  "main": "dist/bundle.js",
6
6
  "scripts": {
@@ -31,6 +31,8 @@
31
31
  "url": "^0.11.0"
32
32
  },
33
33
  "peerDependencies": {
34
+ "compress-json": "*",
35
+ "pako": "*",
34
36
  "socket.io-client": "*"
35
37
  }
36
38
  }
@@ -0,0 +1,44 @@
1
+
2
+ /**
3
+ * brain api
4
+ */
5
+ export default (api) => ({
6
+ get : (id, opts = {}) => {
7
+ return api.get(`/brain/${id}`, opts);
8
+ },
9
+ list : (opts = {}) => {
10
+ // return done
11
+ return api.get(`/brain`, opts);
12
+ },
13
+ run : (brain, opts = {}) => {
14
+ // return done
15
+ return api.post(`/brain/${brain?.id || brain}/run`, opts);
16
+ },
17
+ create : (brain = {}) => {
18
+ // return patch
19
+ return api.post(`/brain`, brain);
20
+ },
21
+ update : (brain = {}) => {
22
+ // return patch
23
+ return api.patch(`/brain/${brain.id}`, brain);
24
+ },
25
+ delete : (brain) => {
26
+ // return patch
27
+ return api.delete(`/brain/${brain?.id || brain}`);
28
+ },
29
+ validate : (brain, key, value) => {
30
+ // return check
31
+ return api.get(`/brain/value`, {
32
+ key,
33
+ value,
34
+ brain : brain?.id,
35
+ });
36
+ },
37
+
38
+ Frame : {
39
+ list : (brain, opts = {}) => {
40
+ // return done
41
+ return api.get(`/brain/${brain?.id || brain}/frame`, opts);
42
+ }
43
+ }
44
+ });
package/src/index.ts CHANGED
@@ -1,7 +1,9 @@
1
1
 
2
2
  // socketio client
3
+ import pako from 'pako';
3
4
  import shortid from 'short-unique-id';
4
5
  import socketio from 'socket.io-client';
6
+ import { decompress } from 'compress-json';
5
7
  import { EventEmitter } from 'eventemitter3';
6
8
 
7
9
  // create short id
@@ -13,17 +15,15 @@ import User from './api/User';
13
15
  import Chat from './api/Chat';
14
16
  import File from './api/File';
15
17
  import Stat from './api/Stat';
16
- import Event from './api/Event';
17
18
  import OAuth from './api/OAuth';
18
19
  import Chirp from './api/Chirp';
19
20
  import World from './api/World';
21
+ import Brain from './api/Brain';
20
22
  import Studio from './api/Studio';
21
23
  import Follow from './api/Follow';
22
24
  import Chirper from './api/Chirper';
23
25
  import Trending from './api/Trending';
24
- import Activity from './api/Activity';
25
26
  import Category from './api/Category';
26
- import Adventure from './api/Adventure';
27
27
  import Application from './api/Application';
28
28
  import Notification from './api/Notification';
29
29
 
@@ -101,17 +101,15 @@ export default class chirperNode {
101
101
  this.User = User(this);
102
102
  this.Chat = Chat(this);
103
103
  this.Stat = Stat(this);
104
- this.Event = Event(this);
105
104
  this.OAuth = OAuth(this);
106
105
  this.Chirp = Chirp(this);
106
+ this.Brain = Brain(this);
107
107
  this.World = World(this);
108
108
  this.Studio = Studio(this);
109
109
  this.Follow = Follow(this);
110
110
  this.Chirper = Chirper(this);
111
111
  this.Trending = Trending(this);
112
- this.Activity = Activity(this);
113
112
  this.Category = Category(this);
114
- this.Adventure = Adventure(this);
115
113
  this.Application = Application(this);
116
114
  this.Notification = Notification(this);
117
115
 
@@ -139,11 +137,20 @@ export default class chirperNode {
139
137
  // check url
140
138
  if (!this.url) return;
141
139
 
142
- // connect
143
- const actualSocket = socketio.connect(`${this.url}`, {
140
+ // options
141
+ const options = {
144
142
  ...(this.options),
145
143
  ...(this.extraOptions),
146
- });
144
+ };
145
+
146
+ // set query
147
+ if (!options.query) options.query = {};
148
+
149
+ // set compression
150
+ options.query.compression = true;
151
+
152
+ // connect
153
+ const actualSocket = socketio.connect(`${this.url}`, options);
147
154
 
148
155
  // on connect
149
156
  actualSocket.on('connect', async (...args) => {
@@ -334,9 +341,19 @@ export default class chirperNode {
334
341
  // create promise
335
342
  const result = new Promise((resolve, reject) => {
336
343
  // resolve
337
- this.socket.once(id, ({ success, result, message }) => {
344
+ this.socket.once(id, (resultMessage) => {
345
+ // uncompressed message
346
+ const uncompressedMessage = pako.ungzip(resultMessage, { to: 'string' });
347
+
348
+ // uncompress message
349
+ console.log(decompress(JSON.parse(uncompressedMessage)))
350
+
351
+ // unpacked
352
+ const { success, result, message, time } = decompress(JSON.parse(uncompressedMessage));
353
+
338
354
  // time end
339
355
  console.timeEnd(`[chirper] [${id}] ${method}:${path} ${JSON.stringify(data)}`);
356
+ console.log(`[chirper] [${id}] backend time ${time}ms`);
340
357
 
341
358
  // check result
342
359
  if (success) return resolve(result);
@@ -1,18 +0,0 @@
1
-
2
- /**
3
- * key api
4
- */
5
- export default (api) => ({
6
- list : (opts) => {
7
- // return promise
8
- return api.get(`/activity`, opts);
9
- },
10
- count : (opts) => {
11
- // return promise
12
- return api.get(`/activity/count`, opts);
13
- },
14
- read : (opts) => {
15
- // return promise
16
- return api.post(`/activity/count`, opts);
17
- }
18
- });
@@ -1,80 +0,0 @@
1
-
2
- /**
3
- * adventure api
4
- */
5
- export default (api) => ({
6
- get : (id) => {
7
- return api.get(`/adventure/${id}`);
8
- },
9
- list : (opts = {}) => {
10
- // return done
11
- return api.get(`/adventure`, opts);
12
- },
13
- image : (chirper, opts = {}) => {
14
- // return patch
15
- return api.post(`/adventure/${chirper?.id || chirper}/image`, opts);
16
- },
17
- invite : (adventure, chirper) => {
18
- // invite to adventure
19
- return api.post(`/adventure/${adventure?.id || adventure}/invite`, {
20
- chirper : chirper?.id || chirper,
21
- });
22
- },
23
- remove : (adventure, chirper) => {
24
- // invite to adventure
25
- return api.post(`/adventure/${adventure?.id || adventure}/remove`, {
26
- chirper : chirper?.id || chirper,
27
- });
28
- },
29
- members : (adventure, opts = {}) => {
30
- // return members
31
- return api.get(`/adventure/${adventure?.id || adventure}/members`, opts);
32
- },
33
-
34
-
35
- // adventure
36
- alerts : (opts = {}) => {
37
- // return done
38
- return api.get(`/adventure/alerts`, opts);
39
- },
40
- choices : (adventure, parent = null) => {
41
- // return adventure choices
42
- return api.get(`/adventure/${adventure?.id || adventure}/choices`, {
43
- parent : parent?.id || parent,
44
- });
45
- },
46
- create : (adventure) => {
47
- // return patch
48
- return api.post(`/adventure`, adventure);
49
- },
50
- update : (adventure) => {
51
- // return patch
52
- return api.patch(`/adventure/${adventure?.id}`, adventure);
53
- },
54
- delete : (adventure) => {
55
- // return patch
56
- return api.delete(`/adventure/${adventure?.id || adventure}`);
57
- },
58
- restore : (adventure) => {
59
- // return patch
60
- return api.post(`/adventure/${adventure?.id || adventure}/cancel`);
61
- },
62
- validate : (adventure, key, value) => {
63
- // return check
64
- return api.get(`/adventure/value`, {
65
- key,
66
- value,
67
- adventure : adventure?.id,
68
- });
69
- },
70
-
71
- Page : {
72
- create : (adventure, decision, parent) => {
73
- // create next page
74
- return api.post(`/adventure/${adventure?.id || adventure}/page`, {
75
- decision,
76
- parent : parent?.id || parent,
77
- });
78
- },
79
- }
80
- });
package/src/api/Event.ts DELETED
@@ -1,44 +0,0 @@
1
-
2
- /**
3
- * event api
4
- */
5
- export default (api) => ({
6
- get : (id) => {
7
- return api.get(`/event/${id}`);
8
- },
9
- list : (opts = {}) => {
10
- // return done
11
- return api.get(`/event`, opts);
12
- },
13
- image : (chirper, opts = {}) => {
14
- // return patch
15
- return api.post(`/event/${chirper?.id || chirper}/image`, opts);
16
- },
17
-
18
-
19
- // event
20
- create : (event) => {
21
- // return patch
22
- return api.post(`/event`, event);
23
- },
24
- update : (event) => {
25
- // return patch
26
- return api.patch(`/event/${event?.id}`, event);
27
- },
28
- delete : (event) => {
29
- // return patch
30
- return api.delete(`/event/${event?.id || event}`);
31
- },
32
- restore : (event) => {
33
- // return patch
34
- return api.post(`/event/${event?.id || event}/cancel`);
35
- },
36
- validate : (event, key, value) => {
37
- // return check
38
- return api.get(`/event/value`, {
39
- key,
40
- value,
41
- event : event?.id,
42
- });
43
- }
44
- });