@chirper/node 0.0.48 → 0.0.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bundle.js CHANGED
@@ -1 +1 @@
1
- var st=Object.create;var C=Object.defineProperty;var rt=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var ot=Object.getPrototypeOf,ht=Object.prototype.hasOwnProperty;var N=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),lt=(i,t)=>{for(var e in t)C(i,e,{get:t[e],enumerable:!0})},F=(i,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of nt(t))!ht.call(i,o)&&o!==e&&C(i,o,{get:()=>t[o],enumerable:!(s=rt(t,o))||s.enumerable});return i};var L=(i,t,e)=>(e=i!=null?st(ot(i)):{},F(t||!i||!i.__esModule?C(e,"default",{value:i,enumerable:!0}):e,i)),ut=i=>F(C({},"__esModule",{value:!0}),i);var T=N((_t,E)=>{var U=(()=>{var i=Object.defineProperty,t=Object.getOwnPropertySymbols,e=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable,o=($,f,d)=>f in $?i($,f,{enumerable:!0,configurable:!0,writable:!0,value:d}):$[f]=d,l=($,f)=>{for(var d in f||(f={}))e.call(f,d)&&o($,d,f[d]);if(t)for(var d of t(f))s.call(f,d)&&o($,d,f[d]);return $},h=$=>i($,"__esModule",{value:!0}),v=($,f)=>{h($);for(var d in f)i($,d,{get:f[d],enumerable:!0})},r={};v(r,{DEFAULT_UUID_LENGTH:()=>w,default:()=>y});var m="4.4.4",w=6,u={dictionary:"alphanum",shuffle:!0,debug:!1,length:w},b=class extends Function{constructor($={}){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 _;this.dictIndex=_=0;let x=`_${n}_dict_ranges`,D=this[x];Object.keys(D).forEach(et=>{let it=et;for(this.dictRange=D[it],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)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||w)=>{let c,a,_;if(n===null||typeof n>"u"||n<1)throw new Error("Invalid UUID Length Provided");let x=n>=0;for(c="",_=0;_<n;_+=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,_=Math.round(Math.random()*(a>15?15:a)),x=this.randomUUID(a);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 f=l(l({},u),$);this.counter=0,this.debug=!1,this.dict=[],this.version=m;let{dictionary:d,shuffle:Z,length:tt}=f;return this.uuidLength=tt,this.setDictionary(d,Z),this.debug=f.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,r})();typeof E<"u"&&(E.exports=U.default),typeof window<"u"&&(U=U.default)});var A=N((vt,P)=>{"use strict";var ct=Object.prototype.hasOwnProperty,g="~";function O(){}Object.create&&(O.prototype=Object.create(null),new O().__proto__||(g=!1));function at(i,t,e){this.fn=i,this.context=t,this.once=e||!1}function J(i,t,e,s,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var l=new at(e,s||i,o),h=g?g+t:t;return i._events[h]?i._events[h].fn?i._events[h]=[i._events[h],l]:i._events[h].push(l):(i._events[h]=l,i._eventsCount++),i}function S(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,s;if(this._eventsCount===0)return t;for(s in e=this._events)ct.call(e,s)&&t.push(g?s.slice(1):s);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};p.prototype.listeners=function(t){var e=g?g+t:t,s=this._events[e];if(!s)return[];if(s.fn)return[s.fn];for(var o=0,l=s.length,h=new Array(l);o<l;o++)h[o]=s[o].fn;return h};p.prototype.listenerCount=function(t){var e=g?g+t:t,s=this._events[e];return s?s.fn?1:s.length:0};p.prototype.emit=function(t,e,s,o,l,h){var v=g?g+t:t;if(!this._events[v])return!1;var r=this._events[v],m=arguments.length,w,u;if(r.fn){switch(r.once&&this.removeListener(t,r.fn,void 0,!0),m){case 1:return r.fn.call(r.context),!0;case 2:return r.fn.call(r.context,e),!0;case 3:return r.fn.call(r.context,e,s),!0;case 4:return r.fn.call(r.context,e,s,o),!0;case 5:return r.fn.call(r.context,e,s,o,l),!0;case 6:return r.fn.call(r.context,e,s,o,l,h),!0}for(u=1,w=new Array(m-1);u<m;u++)w[u-1]=arguments[u];r.fn.apply(r.context,w)}else{var b=r.length,y;for(u=0;u<b;u++)switch(r[u].once&&this.removeListener(t,r[u].fn,void 0,!0),m){case 1:r[u].fn.call(r[u].context);break;case 2:r[u].fn.call(r[u].context,e);break;case 3:r[u].fn.call(r[u].context,e,s);break;case 4:r[u].fn.call(r[u].context,e,s,o);break;default:if(!w)for(y=1,w=new Array(m-1);y<m;y++)w[y-1]=arguments[y];r[u].fn.apply(r[u].context,w)}}return!0};p.prototype.on=function(t,e,s){return J(this,t,e,s,!1)};p.prototype.once=function(t,e,s){return J(this,t,e,s,!0)};p.prototype.removeListener=function(t,e,s,o){var l=g?g+t:t;if(!this._events[l])return this;if(!e)return S(this,l),this;var h=this._events[l];if(h.fn)h.fn===e&&(!o||h.once)&&(!s||h.context===s)&&S(this,l);else{for(var v=0,r=[],m=h.length;v<m;v++)(h[v].fn!==e||o&&!h[v].once||s&&h[v].context!==s)&&r.push(h[v]);r.length?this._events[l]=r.length===1?r[0]:r:S(this,l)}return this};p.prototype.removeAllListeners=function(t){var e;return t?(e=g?g+t:t,this._events[e]&&S(this,e)):(this._events=new O,this._eventsCount=0),this};p.prototype.off=p.prototype.removeListener;p.prototype.addListener=p.prototype.on;p.prefixed=g;p.EventEmitter=p;typeof P<"u"&&(P.exports=p)});var pt={};lt(pt,{default:()=>I});module.exports=ut(pt);var Q=L(T()),X=L(require("socket.io-client"));var k=L(A(),1);var B=i=>({prompt:t=>i.post("/:account/ai",t),image:t=>i.post("/:account/ai/image",t)});var M=i=>({get:(t,e={})=>i.get(`/user/${t}`,e)});var j=i=>({get:(t,e)=>i.post(`/chat/${t?.id||t}`,e),list:t=>i.get("/chat",t),create:(t,e)=>i.post(`/chat/${t?.id||t}`,e),leaveChat:t=>i.post(`/chat/${t?.id||t}/leave`),loadMembers:(t,e)=>i.get(`/chat/${t?.id||t}/members`,e),loadMessages:(t,e)=>i.get(`/chat/${t?.id||t}/messages`,e),sendMessage:(t,e)=>i.post(`/chat/${t?.id||t}/send`,e),inviteMember:(t,e)=>i.post(`/chat/${t?.id||t}/invite`,{chirper:e?.id||e}),removeMember:(t,e)=>i.post(`/chat/${t?.id||t}/remove`,{chirper:e?.id||e})});var q=i=>({list:(t={})=>i.get("/file",t)});var R=i=>({get:(t,e=null,s=null)=>i.get(`/:account/stat/${t}`,{from:e,to:s})});var K=i=>({get:(t,e)=>i.get(`/chirp/${t}`,{lang:e},!1,!1),list:(t={})=>i.get("/chirp",t,!1,!1),like:t=>i.post(`/chirp/${t}/like`),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}`),respond:(t,e,s)=>i.post(`/chirp/${e?.id||e}/respond`,{thought:s,chirper:t?.id||t})});var G=i=>({get:t=>i.get(`/world/${t}`),list:(t={})=>i.get("/world",t),alerts:(t={})=>i.get("/world/alerts",t),create:t=>i.post("/world",t),update:(t,e,s)=>i.patch(`/world/${t.id}`,e?{lang:s,updates:e}:t),delete:t=>i.delete(`/world/${t}`),restore:t=>i.post(`/world/${t}/cancel`),slug:(t,e=null)=>i.post("/world/slug",{slug:t,id:e?.id||e}),image:(t,e,s,o=null)=>i.post(`/world/${t?.id||t}/image`,{type:o,locked:s,appearance: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)});var H=i=>({get:t=>i.get(`/follow/${t}`),toggle:t=>i.post(`/follow/${t?.id||t}`)});var V=i=>({get:t=>i.get(`/chirper/${t}`),list:(t={})=>i.get("/chirper",t),task:(t,e)=>i.post(`/chirper/${t?.id||t}/task`,{task:e?.id||e}),bump:t=>i.post(`/chirper/${t}/bump`),bumpAll:()=>i.post("/chirper/bump/all"),order:t=>i.post("/chirper/order",{chirpers:t}),create:t=>i.post("/chirper",t),update:(t,e,s)=>i.patch(`/chirper/${t.id}`,e?{lang:s,updates:e}:t),delete:t=>i.delete(`/chirper/${t}`),restore:t=>i.post(`/chirper/${t}/cancel`),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}),appearance:(t,e={})=>i.post(`/chirper/${t?.id||t}/appearance`,e)});var W=i=>({list:({lang:t}={})=>i.get("/trending",{lang:t},!1,!1)});var Y=i=>({list:t=>i.get("/activity",t),count:t=>i.get("/activity/count",t),read:t=>i.post("/activity/count",t)});var z=i=>({get:t=>i.get(`/category/${t?.id||t}`,{}),list:t=>i.get("/category",t)});var ft=new Q.default({length:10}),I=class{constructor({url:t,version:e,options:s={}}){this.key=null;this.url=null;this.cache={};this.events=new k.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),s&&(this.extraOptions=s),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=q(this),this.User=M(this),this.Chat=j(this),this.Stat=R(this),this.Chirp=K(this),this.World=G(this),this.Follow=H(this),this.Chirper=V(this),this.Trending=W(this),this.Activity=Y(this),this.Category=z(this),this.build()}build(){if(this.__resolveConnecting=null,this.connecting=new Promise(e=>{this.__resolveConnecting=e}),!this.url)return;let t=X.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(){this.loading=!0,this.events.emit("loading",!0);let t=await this.get("/auth",{key:this.key},!1,!1);t?.user&&(this.user=t.user,this.events.emit("user",t.user)),this.loading=!1,this.events.emit("loading",!1),typeof window<"u"&&(window.chirper=this)}async fetch(t,e,s={},o=!1){if(["patch","put","delete","post"].includes(t.toLowerCase())&&(o=!1),o&&this.cache[`${t}${e}${JSON.stringify(s)}`])return this.cache[`${t}${e}${JSON.stringify(s)}`];delete this.cache[`${t}${e}${JSON.stringify(s)}`],console.time(`[chirper] [fetch] ${t}:${e} ${JSON.stringify(s)}`),Object.keys(s).forEach(h=>{s[h]===void 0&&delete s[h]});let l;try{l=await(await fetch(`${this.url}/${this.version}${e}${`${t}`.toLowerCase()==="get"?`?${new URLSearchParams(s)}`:""}`,{body:`${t}`.toLowerCase()!=="get"?JSON.stringify(s):void 0,headers:{"Content-Type":"application/json",Authentication:this.key?`Bearer ${this.key}`:void 0},credentials:"include"})).json()}catch(h){throw console.timeEnd(`[chirper] [fetch] ${t}:${e} ${JSON.stringify(s)}`),h}if(console.timeEnd(`[chirper] [fetch] ${t}:${e} ${JSON.stringify(s)}`),!l?.success)throw new Error(l.message);return o&&(this.cache[`${t}${e}${JSON.stringify(s)}`]=l,this.cache[`${t}${e}${JSON.stringify(s)}`].then(()=>{typeof o=="number"?setTimeout(()=>{delete this.cache[`${t}${e}${JSON.stringify(s)}`]},o):delete this.cache[`${t}${e}${JSON.stringify(s)}`]})),l.result}async wsFetch(t,e,s={},o=!1,l=!0){if(l&&await this.connecting,l&&await this.authing,l&&!this.account&&e.includes(":account")&&await new Promise(r=>{this.events.once("account",r)}),this.account&&(e=e.replace(":account",this.account?.id)),["patch","put","delete","post"].includes(t.toLowerCase())&&(o=!1),o&&this.cache[`${t}${e}${JSON.stringify(s)}`])return this.cache[`${t}${e}${JSON.stringify(s)}`];delete this.cache[`${t}${e}${JSON.stringify(s)}`];let h=ft();console.time(`[chirper] [${h}] ${t}:${e} ${JSON.stringify(s)}`);let v=new Promise((r,m)=>{this.socket.once(h,({success:w,result:u,message:b})=>{if(console.timeEnd(`[chirper] [${h}] ${t}:${e} ${JSON.stringify(s)}`),w)return r(u);m(b)})});return o&&(this.cache[`${t}${e}${JSON.stringify(s)}`]=v,this.cache[`${t}${e}${JSON.stringify(s)}`].then(()=>{typeof o=="number"?setTimeout(()=>{delete this.cache[`${t}${e}${JSON.stringify(s)}`]},o):delete this.cache[`${t}${e}${JSON.stringify(s)}`]})),this.socket.emit("call",h,t.toUpperCase(),e,s),v}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,...s){return this.wsFetch("GET",`/${this.version}${t}`,e,...s)}put(t,e,...s){return this.wsFetch("PUT",`/${this.version}${t}`,e,...s)}post(t,e,...s){return this.wsFetch("POST",`/${this.version}${t}`,e,...s)}patch(t,e,...s){return this.wsFetch("PATCH",`/${this.version}${t}`,e,...s)}delete(t,e,...s){return this.wsFetch("DELETE",`/${this.version}${t}`,e,...s)}};
1
+ var st=Object.create;var C=Object.defineProperty;var rt=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var ot=Object.getPrototypeOf,ht=Object.prototype.hasOwnProperty;var k=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),lt=(i,t)=>{for(var e in t)C(i,e,{get:t[e],enumerable:!0})},F=(i,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of nt(t))!ht.call(i,o)&&o!==e&&C(i,o,{get:()=>t[o],enumerable:!(s=rt(t,o))||s.enumerable});return i};var L=(i,t,e)=>(e=i!=null?st(ot(i)):{},F(t||!i||!i.__esModule?C(e,"default",{value:i,enumerable:!0}):e,i)),ut=i=>F(C({},"__esModule",{value:!0}),i);var T=k((_t,E)=>{var U=(()=>{var i=Object.defineProperty,t=Object.getOwnPropertySymbols,e=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable,o=($,f,d)=>f in $?i($,f,{enumerable:!0,configurable:!0,writable:!0,value:d}):$[f]=d,l=($,f)=>{for(var d in f||(f={}))e.call(f,d)&&o($,d,f[d]);if(t)for(var d of t(f))s.call(f,d)&&o($,d,f[d]);return $},h=$=>i($,"__esModule",{value:!0}),v=($,f)=>{h($);for(var d in f)i($,d,{get:f[d],enumerable:!0})},r={};v(r,{DEFAULT_UUID_LENGTH:()=>w,default:()=>y});var m="4.4.4",w=6,u={dictionary:"alphanum",shuffle:!0,debug:!1,length:w},b=class extends Function{constructor($={}){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 _;this.dictIndex=_=0;let x=`_${n}_dict_ranges`,N=this[x];Object.keys(N).forEach(et=>{let it=et;for(this.dictRange=N[it],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)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||w)=>{let c,a,_;if(n===null||typeof n>"u"||n<1)throw new Error("Invalid UUID Length Provided");let x=n>=0;for(c="",_=0;_<n;_+=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,_=Math.round(Math.random()*(a>15?15:a)),x=this.randomUUID(a);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 f=l(l({},u),$);this.counter=0,this.debug=!1,this.dict=[],this.version=m;let{dictionary:d,shuffle:Z,length:tt}=f;return this.uuidLength=tt,this.setDictionary(d,Z),this.debug=f.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,r})();typeof E<"u"&&(E.exports=U.default),typeof window<"u"&&(U=U.default)});var B=k((vt,P)=>{"use strict";var ct=Object.prototype.hasOwnProperty,g="~";function O(){}Object.create&&(O.prototype=Object.create(null),new O().__proto__||(g=!1));function at(i,t,e){this.fn=i,this.context=t,this.once=e||!1}function J(i,t,e,s,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var l=new at(e,s||i,o),h=g?g+t:t;return i._events[h]?i._events[h].fn?i._events[h]=[i._events[h],l]:i._events[h].push(l):(i._events[h]=l,i._eventsCount++),i}function S(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,s;if(this._eventsCount===0)return t;for(s in e=this._events)ct.call(e,s)&&t.push(g?s.slice(1):s);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};p.prototype.listeners=function(t){var e=g?g+t:t,s=this._events[e];if(!s)return[];if(s.fn)return[s.fn];for(var o=0,l=s.length,h=new Array(l);o<l;o++)h[o]=s[o].fn;return h};p.prototype.listenerCount=function(t){var e=g?g+t:t,s=this._events[e];return s?s.fn?1:s.length:0};p.prototype.emit=function(t,e,s,o,l,h){var v=g?g+t:t;if(!this._events[v])return!1;var r=this._events[v],m=arguments.length,w,u;if(r.fn){switch(r.once&&this.removeListener(t,r.fn,void 0,!0),m){case 1:return r.fn.call(r.context),!0;case 2:return r.fn.call(r.context,e),!0;case 3:return r.fn.call(r.context,e,s),!0;case 4:return r.fn.call(r.context,e,s,o),!0;case 5:return r.fn.call(r.context,e,s,o,l),!0;case 6:return r.fn.call(r.context,e,s,o,l,h),!0}for(u=1,w=new Array(m-1);u<m;u++)w[u-1]=arguments[u];r.fn.apply(r.context,w)}else{var b=r.length,y;for(u=0;u<b;u++)switch(r[u].once&&this.removeListener(t,r[u].fn,void 0,!0),m){case 1:r[u].fn.call(r[u].context);break;case 2:r[u].fn.call(r[u].context,e);break;case 3:r[u].fn.call(r[u].context,e,s);break;case 4:r[u].fn.call(r[u].context,e,s,o);break;default:if(!w)for(y=1,w=new Array(m-1);y<m;y++)w[y-1]=arguments[y];r[u].fn.apply(r[u].context,w)}}return!0};p.prototype.on=function(t,e,s){return J(this,t,e,s,!1)};p.prototype.once=function(t,e,s){return J(this,t,e,s,!0)};p.prototype.removeListener=function(t,e,s,o){var l=g?g+t:t;if(!this._events[l])return this;if(!e)return S(this,l),this;var h=this._events[l];if(h.fn)h.fn===e&&(!o||h.once)&&(!s||h.context===s)&&S(this,l);else{for(var v=0,r=[],m=h.length;v<m;v++)(h[v].fn!==e||o&&!h[v].once||s&&h[v].context!==s)&&r.push(h[v]);r.length?this._events[l]=r.length===1?r[0]:r:S(this,l)}return this};p.prototype.removeAllListeners=function(t){var e;return t?(e=g?g+t:t,this._events[e]&&S(this,e)):(this._events=new O,this._eventsCount=0),this};p.prototype.off=p.prototype.removeListener;p.prototype.addListener=p.prototype.on;p.prefixed=g;p.EventEmitter=p;typeof P<"u"&&(P.exports=p)});var pt={};lt(pt,{default:()=>I});module.exports=ut(pt);var Q=L(T()),X=L(require("socket.io-client"));var D=L(B(),1);var M=i=>({prompt:t=>i.post("/:account/ai",t),image:t=>i.post("/:account/ai/image",t)});var A=i=>({get:(t,e={})=>i.get(`/user/${t}`,e),image:(t,e={})=>i.post(`/user/${t?.id||t}/image`,e),update:(t,e,s)=>i.patch(`/user/${t.id}`,e?{lang:s,updates:e}:t),username:(t,e=null)=>i.post("/user/username",{username:t,id:e?.id||e})});var j=i=>({get:(t,e)=>i.post(`/chat/${t?.id||t}`,e),list:t=>i.get("/chat",t),create:(t,e)=>i.post(`/chat/${t?.id||t}`,e),leaveChat:t=>i.post(`/chat/${t?.id||t}/leave`),loadMembers:(t,e)=>i.get(`/chat/${t?.id||t}/members`,e),loadMessages:(t,e)=>i.get(`/chat/${t?.id||t}/messages`,e),sendMessage:(t,e)=>i.post(`/chat/${t?.id||t}/send`,e),inviteMember:(t,e)=>i.post(`/chat/${t?.id||t}/invite`,{chirper:e?.id||e}),removeMember:(t,e)=>i.post(`/chat/${t?.id||t}/remove`,{chirper:e?.id||e})});var q=i=>({list:(t={})=>i.get("/file",t)});var R=i=>({get:(t,e=null,s=null)=>i.get(`/:account/stat/${t}`,{from:e,to:s})});var K=i=>({get:(t,e)=>i.get(`/chirp/${t}`,{lang:e},!1,!1),list:(t={})=>i.get("/chirp",t,!1,!1),like:t=>i.post(`/chirp/${t}/like`),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}`),respond:(t,e,s)=>i.post(`/chirp/${e?.id||e}/respond`,{thought:s,chirper:t?.id||t})});var G=i=>({get:t=>i.get(`/world/${t}`),list:(t={})=>i.get("/world",t),alerts:(t={})=>i.get("/world/alerts",t),create:t=>i.post("/world",t),update:(t,e)=>i.patch(`/world/${t.id}`,e?{updates:e}:t),delete:t=>i.delete(`/world/${t}`),restore:t=>i.post(`/world/${t}/cancel`),slug:(t,e=null)=>i.post("/world/slug",{slug:t,id:e?.id||e}),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)});var H=i=>({get:t=>i.get(`/follow/${t}`),toggle:t=>i.post(`/follow/${t?.id||t}`)});var V=i=>({get:t=>i.get(`/chirper/${t}`),list:(t={})=>i.get("/chirper",t),image:(t,e={})=>i.post(`/chirper/${t?.id||t}/image`,e),create:t=>i.post("/chirper",t),update:(t,e)=>i.patch(`/chirper/${t.id}`,e?{updates:e}:t),delete:t=>i.delete(`/chirper/${t}`),restore:t=>i.post(`/chirper/${t}/cancel`),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})});var W=i=>({list:({lang:t}={})=>i.get("/trending",{lang:t},!1,!1)});var Y=i=>({list:t=>i.get("/activity",t),count:t=>i.get("/activity/count",t),read:t=>i.post("/activity/count",t)});var z=i=>({get:t=>i.get(`/category/${t?.id||t}`,{}),list:t=>i.get("/category",t)});var ft=new Q.default({length:10}),I=class{constructor({url:t,version:e,options:s={}}){this.key=null;this.url=null;this.cache={};this.events=new D.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),s&&(this.extraOptions=s),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=A(this),this.Chat=j(this),this.Stat=R(this),this.Chirp=K(this),this.World=G(this),this.Follow=H(this),this.Chirper=V(this),this.Trending=W(this),this.Activity=Y(this),this.Category=z(this),this.build()}build(){if(this.__resolveConnecting=null,this.connecting=new Promise(e=>{this.__resolveConnecting=e}),!this.url)return;let t=X.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(){this.loading=!0,this.events.emit("loading",!0);let t=await this.get("/auth",{key:this.key},!1,!1);t?.user&&(this.user=t.user,this.events.emit("user",t.user)),this.loading=!1,this.events.emit("loading",!1),typeof window<"u"&&(window.chirper=this)}async fetch(t,e,s={},o=!1){if(["patch","put","delete","post"].includes(t.toLowerCase())&&(o=!1),o&&this.cache[`${t}${e}${JSON.stringify(s)}`])return this.cache[`${t}${e}${JSON.stringify(s)}`];delete this.cache[`${t}${e}${JSON.stringify(s)}`],console.time(`[chirper] [fetch] ${t}:${e} ${JSON.stringify(s)}`),Object.keys(s).forEach(h=>{s[h]===void 0&&delete s[h]});let l;try{l=await(await fetch(`${this.url}/${this.version}${e}${`${t}`.toLowerCase()==="get"?`?${new URLSearchParams(s)}`:""}`,{body:`${t}`.toLowerCase()!=="get"?JSON.stringify(s):void 0,headers:{"Content-Type":"application/json",Authentication:this.key?`Bearer ${this.key}`:void 0},credentials:"include"})).json()}catch(h){throw console.timeEnd(`[chirper] [fetch] ${t}:${e} ${JSON.stringify(s)}`),h}if(console.timeEnd(`[chirper] [fetch] ${t}:${e} ${JSON.stringify(s)}`),!l?.success)throw new Error(l.message);return o&&(this.cache[`${t}${e}${JSON.stringify(s)}`]=l,this.cache[`${t}${e}${JSON.stringify(s)}`].then(()=>{typeof o=="number"?setTimeout(()=>{delete this.cache[`${t}${e}${JSON.stringify(s)}`]},o):delete this.cache[`${t}${e}${JSON.stringify(s)}`]})),l.result}async wsFetch(t,e,s={},o=!1,l=!0){if(l&&await this.connecting,l&&await this.authing,l&&!this.account&&e.includes(":account")&&await new Promise(r=>{this.events.once("account",r)}),this.account&&(e=e.replace(":account",this.account?.id)),["patch","put","delete","post"].includes(t.toLowerCase())&&(o=!1),o&&this.cache[`${t}${e}${JSON.stringify(s)}`])return this.cache[`${t}${e}${JSON.stringify(s)}`];delete this.cache[`${t}${e}${JSON.stringify(s)}`];let h=ft();console.time(`[chirper] [${h}] ${t}:${e} ${JSON.stringify(s)}`);let v=new Promise((r,m)=>{this.socket.once(h,({success:w,result:u,message:b})=>{if(console.timeEnd(`[chirper] [${h}] ${t}:${e} ${JSON.stringify(s)}`),w)return r(u);m(b)})});return o&&(this.cache[`${t}${e}${JSON.stringify(s)}`]=v,this.cache[`${t}${e}${JSON.stringify(s)}`].then(()=>{typeof o=="number"?setTimeout(()=>{delete this.cache[`${t}${e}${JSON.stringify(s)}`]},o):delete this.cache[`${t}${e}${JSON.stringify(s)}`]})),this.socket.emit("call",h,t.toUpperCase(),e,s),v}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,...s){return this.wsFetch("GET",`/${this.version}${t}`,e,...s)}put(t,e,...s){return this.wsFetch("PUT",`/${this.version}${t}`,e,...s)}post(t,e,...s){return this.wsFetch("POST",`/${this.version}${t}`,e,...s)}patch(t,e,...s){return this.wsFetch("PATCH",`/${this.version}${t}`,e,...s)}delete(t,e,...s){return this.wsFetch("DELETE",`/${this.version}${t}`,e,...s)}};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chirper/node",
3
- "version": "0.0.48",
3
+ "version": "0.0.50",
4
4
  "description": "",
5
5
  "main": "dist/bundle.js",
6
6
  "scripts": {
@@ -10,34 +10,17 @@ export default (api) => ({
10
10
  // return done
11
11
  return api.get(`/chirper`, opts);
12
12
  },
13
- task : (chirper, task) => {
14
- // return done
15
- return api.post(`/chirper/${chirper?.id || chirper}/task`, {
16
- task : task?.id || task,
17
- });
18
- },
19
- bump : (id) => {
20
- // return patch
21
- return api.post(`/chirper/${id}/bump`);
22
- },
23
- bumpAll : () => {
13
+ image : (chirper, opts = {}) => {
24
14
  // return patch
25
- return api.post(`/chirper/bump/all`);
26
- },
27
- order : (chirpers) => {
28
- // return patch
29
- return api.post(`/chirper/order`, {
30
- chirpers,
31
- });
15
+ return api.post(`/chirper/${chirper?.id || chirper}/image`, opts);
32
16
  },
33
17
  create : (item) => {
34
18
  // return patch
35
19
  return api.post(`/chirper`, item);
36
20
  },
37
- update : (item, updates, lang) => {
21
+ update : (item, updates) => {
38
22
  // return patch
39
23
  return api.patch(`/chirper/${item.id}`, updates ? {
40
- lang,
41
24
  updates,
42
25
  } : item);
43
26
  },
@@ -64,8 +47,4 @@ export default (api) => ({
64
47
  id : chirper?.id || chirper,
65
48
  });
66
49
  },
67
- appearance : (chirper, opts = {}) => {
68
- // return patch
69
- return api.post(`/chirper/${chirper?.id || chirper}/appearance`, opts);
70
- },
71
50
  });
package/src/api/User.ts CHANGED
@@ -7,4 +7,22 @@ export default (api) => ({
7
7
  // return promise
8
8
  return api.get(`/user/${id}`, opts);
9
9
  },
10
+ image : (user, opts = {}) => {
11
+ // return patch
12
+ return api.post(`/user/${user?.id || user}/image`, opts);
13
+ },
14
+ update : (item, updates, lang) => {
15
+ // return patch
16
+ return api.patch(`/user/${item.id}`, updates ? {
17
+ lang,
18
+ updates,
19
+ } : item);
20
+ },
21
+ username : (username, user = null) => {
22
+ // return check
23
+ return api.post(`/user/username`, {
24
+ username,
25
+ id : user?.id || user,
26
+ });
27
+ },
10
28
  });
package/src/api/World.ts CHANGED
@@ -18,10 +18,9 @@ export default (api) => ({
18
18
  // return patch
19
19
  return api.post(`/world`, item);
20
20
  },
21
- update : (item, updates, lang) => {
21
+ update : (item, updates) => {
22
22
  // return patch
23
23
  return api.patch(`/world/${item.id}`, updates ? {
24
- lang,
25
24
  updates,
26
25
  } : item);
27
26
  },
@@ -40,13 +39,9 @@ export default (api) => ({
40
39
  id : world?.id || world,
41
40
  });
42
41
  },
43
- image : (world, appearance, locked, type = null) => {
42
+ image : (chirper, opts = {}) => {
44
43
  // return patch
45
- return api.post(`/world/${world?.id || world}/image`, {
46
- type,
47
- locked,
48
- appearance,
49
- });
44
+ return api.post(`/world/${chirper?.id || chirper}/image`, opts);
50
45
  },
51
46
  invite : (world, chirper) => {
52
47
  // invite to world