@chirper/node 0.0.100 → 0.0.101
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/bundle.js +1 -1
- package/package.json +1 -1
- package/src/api/Character.ts +90 -0
- package/src/index.ts +5 -2
- package/src/api/Chirper.ts +0 -114
package/dist/bundle.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
var $t=Object.create;var S=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var vt=Object.getOwnPropertyNames;var yt=Object.getPrototypeOf,wt=Object.prototype.hasOwnProperty;var D=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),bt=(r,t)=>{for(var e in t)S(r,e,{get:t[e],enumerable:!0})},F=(r,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of vt(t))!wt.call(r,o)&&o!==e&&S(r,o,{get:()=>t[o],enumerable:!(i=mt(t,o))||i.enumerable});return r};var k=(r,t,e)=>(e=r!=null?$t(yt(r)):{},F(t||!r||!r.__esModule?S(e,"default",{value:r,enumerable:!0}):e,r)),xt=r=>F(S({},"__esModule",{value:!0}),r);var A=D((Lt,U)=>{var L=(()=>{var r=Object.defineProperty,t=Object.getOwnPropertySymbols,e=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,o=(f,a,p)=>a in f?r(f,a,{enumerable:!0,configurable:!0,writable:!0,value:p}):f[a]=p,l=(f,a)=>{for(var p in a||(a={}))e.call(a,p)&&o(f,p,a[p]);if(t)for(var p of t(a))i.call(a,p)&&o(f,p,a[p]);return f},u=f=>r(f,"__esModule",{value:!0}),m=(f,a)=>{u(f);for(var p in a)r(f,p,{get:a[p],enumerable:!0})},s={};m(s,{DEFAULT_UUID_LENGTH:()=>v,default:()=>w});var y="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 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 d;if(n&&Array.isArray(n)&&n.length>1)d=n;else{d=[];let _;this.dictIndex=_=0;let x=`_${n}_dict_ranges`,N=this[x];Object.keys(N).forEach(pt=>{let _t=pt;for(this.dictRange=N[_t],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))})}c&&(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,c,d="";n=this.counter;do c=n%this.dictLength,n=Math.trunc(n/this.dictLength),d+=this.dict[c];while(n!==0);return this.counter+=1,d},this.randomUUID=(n=this.uuidLength||v)=>{let c,d,_;if(n===null||typeof n>"u"||n<1)throw new Error("Invalid UUID Length Provided");let x=n>=0;for(c="",_=0;_<n;_+=1)d=parseInt((Math.random()*this.dictLength).toFixed(0),10)%this.dictLength,c+=this.dict[d];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),d=n-9,_=Math.round(Math.random()*(d>15?15:d)),x=this.randomUUID(d);return`${x.substr(0,_)}${c}${x.substr(_)}${_.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 a=l(l({},h),f);this.counter=0,this.debug=!1,this.dict=[],this.version=y;let{dictionary:p,shuffle:ft,length:gt}=a;return this.uuidLength=gt,this.setDictionary(p,ft),this.debug=a.debug,this.log(this.dict),this.log(`Generator instantiated with Dictionary Size ${this.dictLength}`),new Proxy(this,{apply:(n,c,d)=>this.randomUUID(...d)})}},w=b;return w.default=b,s})();typeof U<"u"&&(U.exports=L.default),typeof window<"u"&&(L=L.default)});var M=D((Et,E)=>{"use strict";var Ot=Object.prototype.hasOwnProperty,$="~";function O(){}Object.create&&(O.prototype=Object.create(null),new O().__proto__||($=!1));function St(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 St(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 C(r,t){--r._eventsCount===0?r._events=new O:delete r._events[t]}function g(){this._events=new O,this._eventsCount=0}g.prototype.eventNames=function(){var t=[],e,i;if(this._eventsCount===0)return t;for(i in e=this._events)Ot.call(e,i)&&t.push($?i.slice(1):i);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};g.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};g.prototype.listenerCount=function(t){var e=$?$+t:t,i=this._events[e];return i?i.fn?1:i.length:0};g.prototype.emit=function(t,e,i,o,l,u){var m=$?$+t:t;if(!this._events[m])return!1;var s=this._events[m],y=arguments.length,v,h;if(s.fn){switch(s.once&&this.removeListener(t,s.fn,void 0,!0),y){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,v=new Array(y-1);h<y;h++)v[h-1]=arguments[h];s.fn.apply(s.context,v)}else{var b=s.length,w;for(h=0;h<b;h++)switch(s[h].once&&this.removeListener(t,s[h].fn,void 0,!0),y){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(!v)for(w=1,v=new Array(y-1);w<y;w++)v[w-1]=arguments[w];s[h].fn.apply(s[h].context,v)}}return!0};g.prototype.on=function(t,e,i){return T(this,t,e,i,!1)};g.prototype.once=function(t,e,i){return T(this,t,e,i,!0)};g.prototype.removeListener=function(t,e,i,o){var l=$?$+t:t;if(!this._events[l])return this;if(!e)return C(this,l),this;var u=this._events[l];if(u.fn)u.fn===e&&(!o||u.once)&&(!i||u.context===i)&&C(this,l);else{for(var m=0,s=[],y=u.length;m<y;m++)(u[m].fn!==e||o&&!u[m].once||i&&u[m].context!==i)&&s.push(u[m]);s.length?this._events[l]=s.length===1?s[0]:s:C(this,l)}return this};g.prototype.removeAllListeners=function(t){var e;return t?(e=$?$+t:t,this._events[e]&&C(this,e)):(this._events=new O,this._eventsCount=0),this};g.prototype.off=g.prototype.removeListener;g.prototype.addListener=g.prototype.on;g.prefixed=$;g.EventEmitter=g;typeof E<"u"&&(E.exports=g)});var Ct={};bt(Ct,{default:()=>I});module.exports=xt(Ct);var ht=k(require("pako")),ct=k(A()),at=k(require("socket.io-client")),dt=require("compress-json");var P=k(M(),1);var B=r=>({prompt:t=>r.post("/:account/ai",t),image:t=>r.post("/:account/ai/image",t)});var J=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 q=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 R=r=>({get:(t,e={})=>r.get(`/file/${t?.id||t}`,e),list:(t={})=>r.get("/file",t),modelList:(t={})=>r.get("/file/model",t),like:(t,e={})=>r.post(`/file/${t?.id||t}/like`,e),liked:(t,e={})=>r.get(`/file/${t?.id||t}/like`,e)});var K=r=>({get:(t,e=null,i=null)=>r.get(`/:account/stat/${t}`,{from:e,to:i})});var j=r=>({get:(t,e={})=>r.get(`/item/${t?.id||t}`,e),list:(t={})=>r.get("/item",t),delete:(t,e={})=>r.delete(`/item/${t?.id||t}`,e)});var G=r=>({get:(t,e={})=>r.get(`/like/${t?.id||t}`,e),toggle:(t,e={})=>r.post(`/like/${t?.id||t}`,e)});var H=r=>({get:(t,e={})=>r.get(`/place/${t?.id||t}`,e),list:(t={})=>r.get("/place",t)});var z=r=>({code:(t,e)=>r.post("/oauth2/code",{application:t,redirect:e})});var V=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`),influence:(t,{value:e,message:i})=>r.post(`/chirp/${t?.id||t}/influence`,{value:e,message:i}),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 W=r=>({get:(t,e={})=>r.get(`/story/${t?.id||t}`,e),list:(t={})=>r.get("/story",t),Frame:{list:(t={})=>r.get(`/story/${t?.story?.id||t?.story}/frame`,t)}});var Y=r=>({get:t=>r.get(`/world/${t}`),list:(t={})=>r.get("/world",t),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}`),validate:(t,e,i)=>r.get("/world/value",{key:e,value:i,world:t?.id}),Member:{get:(t,e)=>r.get(`/world/${t?.id||t}/member/${e?.id||e}`),list:(t={})=>r.get(`/world/${t?.world?.id||t?.world}/member`,t),create:(t,e)=>r.post(`/world/${t?.id||t}/member`,{chirper:e?.id||e}),delete:(t,e)=>r.delete(`/world/${t?.id||t}/member/${e?.id||e}`)}});var Q=r=>({get:(t,e={})=>r.get(`/brain/${t}`,e),list:(t={})=>r.get("/brain",t),run:(t,e={})=>r.post(`/brain/${t?.id||t}/run`,e),create:(t={})=>r.post("/brain",t),update:(t={})=>r.patch(`/brain/${t.id}`,t),delete:t=>r.delete(`/brain/${t?.id||t}`),validate:(t,e,i)=>r.get("/brain/value",{key:e,value:i,brain:t?.id}),Frame:{list:(t,e={})=>r.get(`/brain/${t?.id||t}/frame`,e),delete:(t,e)=>r.delete(`/brain/${t?.id||t}/frame/${e?.id||e}`)}});var X=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 Z=r=>({get:(t,e={})=>r.get(`/follow/${t?.id||t}`,e),toggle:(t,e={})=>r.post(`/follow/${t?.id||t}`,e)});var tt=r=>({get:(t,e)=>r.get(`/search/${t}`,e),update:(t,e)=>r.put(`/search/${t}`,e),delete:(t,e)=>r.delete(`/search/${t}`,e)});var et=r=>({get:(t,e={})=>r.get(`/dislike/${t?.id||t}`,e),toggle:(t,e={})=>r.post(`/dislike/${t?.id||t}`,e)});var rt=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}),import:(t,e)=>r.post(`/chirper/${t}/import`,e),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}),grant:(t={},e={})=>r.post(`/chirper/${t?.id||t}/grant`,e),create:(t={})=>r.post("/chirper",t),update:(t={})=>r.patch(`/chirper/${t.id}`,t),delete:t=>r.delete(`/chirper/${t?.id||t}`),influence:t=>r.post(`/chirper/${t?.id||t}/influence`),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)},Action:{list:(t,e={})=>r.get(`/chirper/${t?.id||t}/action`,e),get:(t,e={})=>r.get(`/chirper/action/${t?.id||t}`,e)},Item:{list:(t,e={})=>r.get(`/chirper/${t?.id||t}/item`,e),get:(t,e={})=>r.get(`/chirper/item/${t?.id||t}`,e)}});var it=r=>({get:(t,e={})=>r.get(`/affinity/${t?.id||t}`,e),list:(t={})=>r.get("/affinity",t)});var st=r=>({list:({lang:t}={})=>r.get("/trending",{lang:t},!1,!1)});var nt=r=>({get:t=>r.get(`/category/${t?.id||t}`,{}),list:t=>r.get("/category",t)});var ot=r=>({list:(t={})=>r.get(`/transaction/${t?.currency||"mana"}`,t)});var ut=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 lt=r=>({list:t=>r.get("/notification",t),count:t=>r.get("/notification/count",t),read:t=>r.post("/notification/count",t)});var kt=new ct.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=B(this),this.File=R(this),this.Item=j(this),this.User=J(this),this.Chat=q(this),this.Stat=K(this),this.Like=G(this),this.OAuth=z(this),this.Chirp=V(this),this.Brain=Q(this),this.World=Y(this),this.Place=H(this),this.Story=W(this),this.Search=tt(this),this.Studio=X(this),this.Follow=Z(this),this.Dislike=et(this),this.Chirper=rt(this),this.Affinity=it(this),this.Trending=st(this),this.Category=nt(this),this.Application=ut(this),this.Transaction=ot(this),this.Notification=lt(this),this.build()}build(){if(this.__resolveConnecting=null,this.connecting=new Promise(i=>{this.__resolveConnecting=i}),!this.url)return;let t={...this.options,...this.extraOptions};t.query||(t.query={}),t.query.compression=!0;let e=at.default.connect(`${this.url}`,t);e.on("connect",async(...i)=>{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(i=>{this.__resolveConnecting=i})}),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,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=kt();console.time(`[chirper] [${u}] ${t}:${e} ${JSON.stringify(i)}`);let m=new Promise((s,y)=>{this.socket.once(u,v=>{let h=ht.default.ungzip(v,{to:"string"}),{success:b,result:w,message:f,time:a}=(0,dt.decompress)(JSON.parse(h));if(console.timeEnd(`[chirper] [${u}] ${t}:${e} ${JSON.stringify(i)}`),console.log(`[chirper] [${u}] backend time ${a}ms`),b)return s(w);y(f)})});return o&&(this.cache[`${t}${e}${JSON.stringify(i)}`]=m,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),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,...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 $t=Object.create;var S=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var vt=Object.getOwnPropertyNames;var yt=Object.getPrototypeOf,wt=Object.prototype.hasOwnProperty;var D=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),bt=(r,t)=>{for(var e in t)S(r,e,{get:t[e],enumerable:!0})},F=(r,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of vt(t))!wt.call(r,o)&&o!==e&&S(r,o,{get:()=>t[o],enumerable:!(i=mt(t,o))||i.enumerable});return r};var k=(r,t,e)=>(e=r!=null?$t(yt(r)):{},F(t||!r||!r.__esModule?S(e,"default",{value:r,enumerable:!0}):e,r)),xt=r=>F(S({},"__esModule",{value:!0}),r);var T=D((Lt,U)=>{var L=(()=>{var r=Object.defineProperty,t=Object.getOwnPropertySymbols,e=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,o=(f,c,p)=>c in f?r(f,c,{enumerable:!0,configurable:!0,writable:!0,value:p}):f[c]=p,l=(f,c)=>{for(var p in c||(c={}))e.call(c,p)&&o(f,p,c[p]);if(t)for(var p of t(c))i.call(c,p)&&o(f,p,c[p]);return f},u=f=>r(f,"__esModule",{value:!0}),m=(f,c)=>{u(f);for(var p in c)r(f,p,{get:c[p],enumerable:!0})},s={};m(s,{DEFAULT_UUID_LENGTH:()=>v,default:()=>w});var y="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`,N=this[x];Object.keys(N).forEach(pt=>{let _t=pt;for(this.dictRange=N[_t],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=y;let{dictionary:p,shuffle:ft,length:gt}=c;return this.uuidLength=gt,this.setDictionary(p,ft),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)})}},w=b;return w.default=b,s})();typeof U<"u"&&(U.exports=L.default),typeof window<"u"&&(L=L.default)});var M=D((Et,E)=>{"use strict";var Ot=Object.prototype.hasOwnProperty,$="~";function O(){}Object.create&&(O.prototype=Object.create(null),new O().__proto__||($=!1));function St(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function A(r,t,e,i,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var l=new St(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 C(r,t){--r._eventsCount===0?r._events=new O:delete r._events[t]}function g(){this._events=new O,this._eventsCount=0}g.prototype.eventNames=function(){var t=[],e,i;if(this._eventsCount===0)return t;for(i in e=this._events)Ot.call(e,i)&&t.push($?i.slice(1):i);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};g.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};g.prototype.listenerCount=function(t){var e=$?$+t:t,i=this._events[e];return i?i.fn?1:i.length:0};g.prototype.emit=function(t,e,i,o,l,u){var m=$?$+t:t;if(!this._events[m])return!1;var s=this._events[m],y=arguments.length,v,h;if(s.fn){switch(s.once&&this.removeListener(t,s.fn,void 0,!0),y){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,v=new Array(y-1);h<y;h++)v[h-1]=arguments[h];s.fn.apply(s.context,v)}else{var b=s.length,w;for(h=0;h<b;h++)switch(s[h].once&&this.removeListener(t,s[h].fn,void 0,!0),y){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(!v)for(w=1,v=new Array(y-1);w<y;w++)v[w-1]=arguments[w];s[h].fn.apply(s[h].context,v)}}return!0};g.prototype.on=function(t,e,i){return A(this,t,e,i,!1)};g.prototype.once=function(t,e,i){return A(this,t,e,i,!0)};g.prototype.removeListener=function(t,e,i,o){var l=$?$+t:t;if(!this._events[l])return this;if(!e)return C(this,l),this;var u=this._events[l];if(u.fn)u.fn===e&&(!o||u.once)&&(!i||u.context===i)&&C(this,l);else{for(var m=0,s=[],y=u.length;m<y;m++)(u[m].fn!==e||o&&!u[m].once||i&&u[m].context!==i)&&s.push(u[m]);s.length?this._events[l]=s.length===1?s[0]:s:C(this,l)}return this};g.prototype.removeAllListeners=function(t){var e;return t?(e=$?$+t:t,this._events[e]&&C(this,e)):(this._events=new O,this._eventsCount=0),this};g.prototype.off=g.prototype.removeListener;g.prototype.addListener=g.prototype.on;g.prefixed=$;g.EventEmitter=g;typeof E<"u"&&(E.exports=g)});var Ct={};bt(Ct,{default:()=>I});module.exports=xt(Ct);var ht=k(require("pako")),at=k(T()),ct=k(require("socket.io-client")),dt=require("compress-json");var P=k(M(),1);var B=r=>({prompt:t=>r.post("/:account/ai",t),image:t=>r.post("/:account/ai/image",t)});var J=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 q=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 R=r=>({get:(t,e={})=>r.get(`/file/${t?.id||t}`,e),list:(t={})=>r.get("/file",t),modelList:(t={})=>r.get("/file/model",t),like:(t,e={})=>r.post(`/file/${t?.id||t}/like`,e),liked:(t,e={})=>r.get(`/file/${t?.id||t}/like`,e)});var K=r=>({get:(t,e=null,i=null)=>r.get(`/:account/stat/${t}`,{from:e,to:i})});var G=r=>({get:(t,e={})=>r.get(`/item/${t?.id||t}`,e),list:(t={})=>r.get("/item",t),delete:(t,e={})=>r.delete(`/item/${t?.id||t}`,e)});var H=r=>({get:(t,e={})=>r.get(`/like/${t?.id||t}`,e),toggle:(t,e={})=>r.post(`/like/${t?.id||t}`,e)});var j=r=>({get:(t,e={})=>r.get(`/place/${t?.id||t}`,e),list:(t={})=>r.get("/place",t)});var z=r=>({code:(t,e)=>r.post("/oauth2/code",{application:t,redirect:e})});var V=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`),influence:(t,{value:e,message:i})=>r.post(`/chirp/${t?.id||t}/influence`,{value:e,message:i}),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 W=r=>({get:(t,e={})=>r.get(`/story/${t?.id||t}`,e),list:(t={})=>r.get("/story",t),Frame:{list:(t={})=>r.get(`/story/${t?.story?.id||t?.story}/frame`,t)}});var Y=r=>({get:t=>r.get(`/world/${t}`),list:(t={})=>r.get("/world",t),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}`),validate:(t,e,i)=>r.get("/world/value",{key:e,value:i,world:t?.id}),Member:{get:(t,e)=>r.get(`/world/${t?.id||t}/member/${e?.id||e}`),list:(t={})=>r.get(`/world/${t?.world?.id||t?.world}/member`,t),create:(t,e)=>r.post(`/world/${t?.id||t}/member`,{chirper:e?.id||e}),delete:(t,e)=>r.delete(`/world/${t?.id||t}/member/${e?.id||e}`)}});var Q=r=>({get:(t,e={})=>r.get(`/brain/${t}`,e),list:(t={})=>r.get("/brain",t),run:(t,e={})=>r.post(`/brain/${t?.id||t}/run`,e),create:(t={})=>r.post("/brain",t),update:(t={})=>r.patch(`/brain/${t.id}`,t),delete:t=>r.delete(`/brain/${t?.id||t}`),validate:(t,e,i)=>r.get("/brain/value",{key:e,value:i,brain:t?.id}),Frame:{list:(t,e={})=>r.get(`/brain/${t?.id||t}/frame`,e),delete:(t,e)=>r.delete(`/brain/${t?.id||t}/frame/${e?.id||e}`)}});var X=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 Z=r=>({get:(t,e={})=>r.get(`/follow/${t?.id||t}`,e),toggle:(t,e={})=>r.post(`/follow/${t?.id||t}`,e)});var tt=r=>({get:(t,e)=>r.get(`/search/${t}`,e),update:(t,e)=>r.put(`/search/${t}`,e),delete:(t,e)=>r.delete(`/search/${t}`,e)});var et=r=>({get:(t,e={})=>r.get(`/dislike/${t?.id||t}`,e),toggle:(t,e={})=>r.post(`/dislike/${t?.id||t}`,e)});var rt=r=>({get:(t,e={})=>r.get(`/affinity/${t?.id||t}`,e),list:(t={})=>r.get("/affinity",t)});var it=r=>({list:({lang:t}={})=>r.get("/trending",{lang:t},!1,!1)});var st=r=>({get:t=>r.get(`/category/${t?.id||t}`,{}),list:t=>r.get("/category",t)});var nt=r=>({get:(t,e={})=>r.get(`/character/${t}`,e),list:(t={})=>r.get("/character",t),spec:(t,e)=>r.post(`/character/${t?.id||t}/spec`,{type:e}),import:(t,e)=>r.post(`/character/${t}/import`,e),image:(t,e={})=>r.post(`/character/${t?.id||t}/image`,e),username:(t,e=null)=>r.post("/character/username",{username:t,id:e?.id||e}),grant:(t={},e={})=>r.post(`/character/${t?.id||t}/grant`,e),create:(t={})=>r.post("/character",t),update:(t={})=>r.patch(`/character/${t.id}`,t),delete:t=>r.delete(`/character/${t?.id||t}`),influence:t=>r.post(`/character/${t?.id||t}/influence`),toggle:t=>r.post(`/character/${t?.id||t}/toggle`),validate:(t,e,i)=>r.get("/character/value",{key:e,value:i,character:t?.id}),Trip:{list:(t,e={})=>r.get(`/character/${t?.id||t}/trip`,e),get:(t,e={})=>r.get(`/character/trip/${t?.id||t}`,e)},Item:{list:(t,e={})=>r.get(`/character/${t?.id||t}/item`,e),get:(t,e={})=>r.get(`/character/item/${t?.id||t}`,e)}});var ot=r=>({list:(t={})=>r.get(`/transaction/${t?.currency||"mana"}`,t)});var ut=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 lt=r=>({list:t=>r.get("/notification",t),count:t=>r.get("/notification/count",t),read:t=>r.post("/notification/count",t)});var kt=new at.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=B(this),this.File=R(this),this.Item=G(this),this.User=J(this),this.Chat=q(this),this.Stat=K(this),this.Like=H(this),this.OAuth=z(this),this.Chirp=V(this),this.Brain=Q(this),this.World=Y(this),this.Place=j(this),this.Story=W(this),this.Search=tt(this),this.Studio=X(this),this.Follow=Z(this),this.Dislike=et(this),this.Affinity=rt(this),this.Trending=it(this),this.Category=st(this),this.Character=nt(this),this.Application=ut(this),this.Transaction=ot(this),this.Notification=lt(this),this.Chirper=this.Character,this.build()}build(){if(this.__resolveConnecting=null,this.connecting=new Promise(i=>{this.__resolveConnecting=i}),!this.url)return;let t={...this.options,...this.extraOptions};t.query||(t.query={}),t.query.compression=!0;let e=ct.default.connect(`${this.url}`,t);e.on("connect",async(...i)=>{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(i=>{this.__resolveConnecting=i})}),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,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=kt();console.time(`[chirper] [${u}] ${t}:${e} ${JSON.stringify(i)}`);let m=new Promise((s,y)=>{this.socket.once(u,v=>{let h=ht.default.ungzip(v,{to:"string"}),{success:b,result:w,message:f,time:c}=(0,dt.decompress)(JSON.parse(h));if(console.timeEnd(`[chirper] [${u}] ${t}:${e} ${JSON.stringify(i)}`),console.log(`[chirper] [${u}] backend time ${c}ms`),b)return s(w);y(f)})});return o&&(this.cache[`${t}${e}${JSON.stringify(i)}`]=m,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),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,...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)}};
|
package/package.json
CHANGED
@@ -0,0 +1,90 @@
|
|
1
|
+
|
2
|
+
/**
|
3
|
+
* character api
|
4
|
+
*/
|
5
|
+
export default (api) => ({
|
6
|
+
get : (id, opts = {}) => {
|
7
|
+
return api.get(`/character/${id}`, opts);
|
8
|
+
},
|
9
|
+
list : (opts = {}) => {
|
10
|
+
// return done
|
11
|
+
return api.get(`/character`, opts);
|
12
|
+
},
|
13
|
+
spec : (character, type) => {
|
14
|
+
// return patch
|
15
|
+
return api.post(`/character/${character?.id || character}/spec`, { type });
|
16
|
+
},
|
17
|
+
import : (provider, data) => {
|
18
|
+
// return patch
|
19
|
+
return api.post(`/character/${provider}/import`, data);
|
20
|
+
},
|
21
|
+
image : (character, opts = {}) => {
|
22
|
+
// return patch
|
23
|
+
return api.post(`/character/${character?.id || character}/image`, opts);
|
24
|
+
},
|
25
|
+
username : (username, character = null) => {
|
26
|
+
// return check
|
27
|
+
return api.post(`/character/username`, {
|
28
|
+
username,
|
29
|
+
id : character?.id || character,
|
30
|
+
});
|
31
|
+
},
|
32
|
+
|
33
|
+
// validate field
|
34
|
+
grant : (character = {}, grant = {}) => {
|
35
|
+
// return patch
|
36
|
+
return api.post(`/character/${character?.id || character}/grant`, grant);
|
37
|
+
},
|
38
|
+
create : (character = {}) => {
|
39
|
+
// return patch
|
40
|
+
return api.post(`/character`, character);
|
41
|
+
},
|
42
|
+
update : (character = {}) => {
|
43
|
+
// return patch
|
44
|
+
return api.patch(`/character/${character.id}`, character);
|
45
|
+
},
|
46
|
+
delete : (character) => {
|
47
|
+
// return patch
|
48
|
+
return api.delete(`/character/${character?.id || character}`);
|
49
|
+
},
|
50
|
+
influence : (character) => {
|
51
|
+
// return influence
|
52
|
+
return api.post(`/character/${character?.id || character}/influence`);
|
53
|
+
},
|
54
|
+
toggle : (character) => {
|
55
|
+
// return patch
|
56
|
+
return api.post(`/character/${character?.id || character}/toggle`);
|
57
|
+
},
|
58
|
+
validate : (character, key, value) => {
|
59
|
+
// return check
|
60
|
+
return api.get(`/character/value`, {
|
61
|
+
key,
|
62
|
+
value,
|
63
|
+
character : character?.id,
|
64
|
+
});
|
65
|
+
},
|
66
|
+
|
67
|
+
Trip : {
|
68
|
+
// list character trips
|
69
|
+
list : (character, opts = {}) => {
|
70
|
+
// return
|
71
|
+
return api.get(`/character/${character?.id || character}/trip`, opts);
|
72
|
+
},
|
73
|
+
get : (trip, opts = {}) => {
|
74
|
+
// return
|
75
|
+
return api.get(`/character/trip/${trip?.id || trip}`, opts);
|
76
|
+
}
|
77
|
+
},
|
78
|
+
|
79
|
+
Item : {
|
80
|
+
// list character items
|
81
|
+
list : (character, opts = {}) => {
|
82
|
+
// return
|
83
|
+
return api.get(`/character/${character?.id || character}/item`, opts);
|
84
|
+
},
|
85
|
+
get : (item, opts = {}) => {
|
86
|
+
// return
|
87
|
+
return api.get(`/character/item/${item?.id || item}`, opts);
|
88
|
+
},
|
89
|
+
}
|
90
|
+
});
|
package/src/index.ts
CHANGED
@@ -27,10 +27,10 @@ import Studio from './api/Studio';
|
|
27
27
|
import Follow from './api/Follow';
|
28
28
|
import Search from './api/Search';
|
29
29
|
import Dislike from './api/Dislike';
|
30
|
-
import Chirper from './api/Chirper';
|
31
30
|
import Affinity from './api/Affinity';
|
32
31
|
import Trending from './api/Trending';
|
33
32
|
import Category from './api/Category';
|
33
|
+
import Character from './api/Character';
|
34
34
|
import Transaction from './api/Transaction';
|
35
35
|
import Application from './api/Application';
|
36
36
|
import Notification from './api/Notification';
|
@@ -121,14 +121,17 @@ export default class chirperNode {
|
|
121
121
|
this.Studio = Studio(this);
|
122
122
|
this.Follow = Follow(this);
|
123
123
|
this.Dislike = Dislike(this);
|
124
|
-
this.Chirper = Chirper(this);
|
125
124
|
this.Affinity = Affinity(this);
|
126
125
|
this.Trending = Trending(this);
|
127
126
|
this.Category = Category(this);
|
127
|
+
this.Character = Character(this);
|
128
128
|
this.Application = Application(this);
|
129
129
|
this.Transaction = Transaction(this);
|
130
130
|
this.Notification = Notification(this);
|
131
131
|
|
132
|
+
// legacy
|
133
|
+
this.Chirper = this.Character;
|
134
|
+
|
132
135
|
// build
|
133
136
|
this.build();
|
134
137
|
}
|
package/src/api/Chirper.ts
DELETED
@@ -1,114 +0,0 @@
|
|
1
|
-
|
2
|
-
/**
|
3
|
-
* chirper api
|
4
|
-
*/
|
5
|
-
export default (api) => ({
|
6
|
-
get : (id, opts = {}) => {
|
7
|
-
return api.get(`/chirper/${id}`, opts);
|
8
|
-
},
|
9
|
-
list : (opts = {}) => {
|
10
|
-
// return done
|
11
|
-
return api.get(`/chirper`, opts);
|
12
|
-
},
|
13
|
-
spec : (chirper, type) => {
|
14
|
-
// return patch
|
15
|
-
return api.post(`/chirper/${chirper?.id || chirper}/spec`, { type });
|
16
|
-
},
|
17
|
-
import : (provider, data) => {
|
18
|
-
// return patch
|
19
|
-
return api.post(`/chirper/${provider}/import`, data);
|
20
|
-
},
|
21
|
-
image : (chirper, opts = {}) => {
|
22
|
-
// return patch
|
23
|
-
return api.post(`/chirper/${chirper?.id || chirper}/image`, opts);
|
24
|
-
},
|
25
|
-
journal : (chirper, opts) => {
|
26
|
-
// return patch
|
27
|
-
return api.get(`/chirper/${chirper?.id || chirper}/journal`, opts);
|
28
|
-
},
|
29
|
-
progress : (chirper, opts) => {
|
30
|
-
// return patch
|
31
|
-
return api.get(`/chirper/${chirper?.id || chirper}/progress`, opts);
|
32
|
-
},
|
33
|
-
username : (username, chirper = null) => {
|
34
|
-
// return check
|
35
|
-
return api.post(`/chirper/username`, {
|
36
|
-
username,
|
37
|
-
id : chirper?.id || chirper,
|
38
|
-
});
|
39
|
-
},
|
40
|
-
|
41
|
-
// validate field
|
42
|
-
grant : (chirper = {}, grant = {}) => {
|
43
|
-
// return patch
|
44
|
-
return api.post(`/chirper/${chirper?.id || chirper}/grant`, grant);
|
45
|
-
},
|
46
|
-
create : (chirper = {}) => {
|
47
|
-
// return patch
|
48
|
-
return api.post(`/chirper`, chirper);
|
49
|
-
},
|
50
|
-
update : (chirper = {}) => {
|
51
|
-
// return patch
|
52
|
-
return api.patch(`/chirper/${chirper.id}`, chirper);
|
53
|
-
},
|
54
|
-
delete : (chirper) => {
|
55
|
-
// return patch
|
56
|
-
return api.delete(`/chirper/${chirper?.id || chirper}`);
|
57
|
-
},
|
58
|
-
influence : (chirper) => {
|
59
|
-
// return influence
|
60
|
-
return api.post(`/chirper/${chirper?.id || chirper}/influence`);
|
61
|
-
},
|
62
|
-
toggleRunning : (chirper) => {
|
63
|
-
// return patch
|
64
|
-
return api.post(`/chirper/${chirper?.id || chirper}/running`);
|
65
|
-
},
|
66
|
-
validate : (chirper, key, value) => {
|
67
|
-
// return check
|
68
|
-
return api.get(`/chirper/value`, {
|
69
|
-
key,
|
70
|
-
value,
|
71
|
-
chirper : chirper?.id,
|
72
|
-
});
|
73
|
-
},
|
74
|
-
trip : (chirper, opts = {}) => {
|
75
|
-
// return
|
76
|
-
return api.get(`/chirper/${chirper?.id || chirper}/trip`, opts);
|
77
|
-
},
|
78
|
-
|
79
|
-
Trip : {
|
80
|
-
// list chirper trips
|
81
|
-
list : (chirper, opts = {}) => {
|
82
|
-
// return
|
83
|
-
return api.get(`/chirper/${chirper?.id || chirper}/trip`, opts);
|
84
|
-
},
|
85
|
-
get : (trip, opts = {}) => {
|
86
|
-
// return
|
87
|
-
return api.get(`/chirper/trip/${trip?.id || trip}`, opts);
|
88
|
-
}
|
89
|
-
},
|
90
|
-
|
91
|
-
Action : {
|
92
|
-
// list chirper actions
|
93
|
-
list : (chirper, opts = {}) => {
|
94
|
-
// return
|
95
|
-
return api.get(`/chirper/${chirper?.id || chirper}/action`, opts);
|
96
|
-
},
|
97
|
-
get : (action, opts = {}) => {
|
98
|
-
// return
|
99
|
-
return api.get(`/chirper/action/${action?.id || action}`, opts);
|
100
|
-
},
|
101
|
-
},
|
102
|
-
|
103
|
-
Item : {
|
104
|
-
// list chirper items
|
105
|
-
list : (chirper, opts = {}) => {
|
106
|
-
// return
|
107
|
-
return api.get(`/chirper/${chirper?.id || chirper}/item`, opts);
|
108
|
-
},
|
109
|
-
get : (item, opts = {}) => {
|
110
|
-
// return
|
111
|
-
return api.get(`/chirper/item/${item?.id || item}`, opts);
|
112
|
-
},
|
113
|
-
}
|
114
|
-
});
|