@chirper/node 0.0.18 → 0.0.19

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 Z=Object.create;var S=Object.defineProperty;var tt=Object.getOwnPropertyDescriptor;var et=Object.getOwnPropertyNames;var it=Object.getPrototypeOf,st=Object.prototype.hasOwnProperty;var N=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),rt=(i,t)=>{for(var e in t)S(i,e,{get:t[e],enumerable:!0})},F=(i,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of et(t))!st.call(i,n)&&n!==e&&S(i,n,{get:()=>t[n],enumerable:!(s=tt(t,n))||s.enumerable});return i};var L=(i,t,e)=>(e=i!=null?Z(it(i)):{},F(t||!i||!i.__esModule?S(e,"default",{value:i,enumerable:!0}):e,i)),nt=i=>F(S({},"__esModule",{value:!0}),i);var T=N((ut,E)=>{var U=(()=>{var i=Object.defineProperty,t=Object.getOwnPropertySymbols,e=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable,n=(_,p,v)=>p in _?i(_,p,{enumerable:!0,configurable:!0,writable:!0,value:v}):_[p]=v,l=(_,p)=>{for(var v in p||(p={}))e.call(p,v)&&n(_,v,p[v]);if(t)for(var v of t(p))s.call(p,v)&&n(_,v,p[v]);return _},h=_=>i(_,"__esModule",{value:!0}),u=(_,p)=>{h(_);for(var v in p)i(_,v,{get:p[v],enumerable:!0})},r={};u(r,{DEFAULT_UUID_LENGTH:()=>g,default:()=>m});var y="4.4.4",g=6,c={dictionary:"alphanum",shuffle:!0,debug:!1,length:g},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=(...o)=>{let a=[...o];if(a[0]=`[short-unique-id] ${o[0]}`,this.debug===!0&&typeof console<"u"&&console!==null)return console.log(...a)},this.setDictionary=(o,a)=>{let f;if(o&&Array.isArray(o)&&o.length>1)f=o;else{f=[];let $;this.dictIndex=$=0;let x=`_${o}_dict_ranges`,D=this[x];Object.keys(D).forEach(W=>{let X=W;for(this.dictRange=D[X],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)f.push(String.fromCharCode(this.dictIndex))})}a&&(f=f.sort(()=>Math.random()-.5)),this.dict=f,this.dictLength=this.dict.length,this.counter=0},this.seq=()=>this.sequentialUUID(),this.sequentialUUID=()=>{let o,a,f="";o=this.counter;do a=o%this.dictLength,o=Math.trunc(o/this.dictLength),f+=this.dict[a];while(o!==0);return this.counter+=1,f},this.randomUUID=(o=this.uuidLength||g)=>{let a,f,$;if(o===null||typeof o>"u"||o<1)throw new Error("Invalid UUID Length Provided");let x=o>=0;for(a="",$=0;$<o;$+=1)f=parseInt((Math.random()*this.dictLength).toFixed(0),10)%this.dictLength,a+=this.dict[f];return a},this.availableUUIDs=(o=this.uuidLength)=>parseFloat(Math.pow([...new Set(this.dict)].length,o).toFixed(0)),this.approxMaxBeforeCollision=(o=this.availableUUIDs(this.uuidLength))=>parseFloat(Math.sqrt(Math.PI/2*o).toFixed(20)),this.collisionProbability=(o=this.availableUUIDs(this.uuidLength),a=this.uuidLength)=>parseFloat((this.approxMaxBeforeCollision(o)/this.availableUUIDs(a)).toFixed(20)),this.uniqueness=(o=this.availableUUIDs(this.uuidLength))=>{let a=parseFloat((1-this.approxMaxBeforeCollision(o)/o).toFixed(20));return a>1?1:a<0?0:a},this.getVersion=()=>this.version,this.stamp=o=>{if(typeof o!="number"||o<10)throw new Error("Param finalLength must be number greater than 10");let a=Math.floor(+new Date/1e3).toString(16),f=o-9,$=Math.round(Math.random()*(f>15?15:f)),x=this.randomUUID(f);return`${x.substr(0,$)}${a}${x.substr($)}${$.toString(16)}`},this.parseStamp=o=>{if(o.length<10)throw new Error("Stamp length invalid");let a=parseInt(o.substr(o.length-1,1),16);return new Date(parseInt(o.substr(a,8),16)*1e3)};let p=l(l({},c),_);this.counter=0,this.debug=!1,this.dict=[],this.version=y;let{dictionary:v,shuffle:z,length:Q}=p;return this.uuidLength=Q,this.setDictionary(v,z),this.debug=p.debug,this.log(this.dict),this.log(`Generator instantiated with Dictionary Size ${this.dictLength}`),new Proxy(this,{apply:(o,a,f)=>this.randomUUID(...f)})}},m=b;return m.default=b,r})();typeof E<"u"&&(E.exports=U.default),typeof window<"u"&&(U=U.default)});var A=N((pt,P)=>{"use strict";var ot=Object.prototype.hasOwnProperty,w="~";function O(){}Object.create&&(O.prototype=Object.create(null),new O().__proto__||(w=!1));function ht(i,t,e){this.fn=i,this.context=t,this.once=e||!1}function J(i,t,e,s,n){if(typeof e!="function")throw new TypeError("The listener must be a function");var l=new ht(e,s||i,n),h=w?w+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 C(i,t){--i._eventsCount===0?i._events=new O:delete i._events[t]}function d(){this._events=new O,this._eventsCount=0}d.prototype.eventNames=function(){var t=[],e,s;if(this._eventsCount===0)return t;for(s in e=this._events)ot.call(e,s)&&t.push(w?s.slice(1):s);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};d.prototype.listeners=function(t){var e=w?w+t:t,s=this._events[e];if(!s)return[];if(s.fn)return[s.fn];for(var n=0,l=s.length,h=new Array(l);n<l;n++)h[n]=s[n].fn;return h};d.prototype.listenerCount=function(t){var e=w?w+t:t,s=this._events[e];return s?s.fn?1:s.length:0};d.prototype.emit=function(t,e,s,n,l,h){var u=w?w+t:t;if(!this._events[u])return!1;var r=this._events[u],y=arguments.length,g,c;if(r.fn){switch(r.once&&this.removeListener(t,r.fn,void 0,!0),y){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,n),!0;case 5:return r.fn.call(r.context,e,s,n,l),!0;case 6:return r.fn.call(r.context,e,s,n,l,h),!0}for(c=1,g=new Array(y-1);c<y;c++)g[c-1]=arguments[c];r.fn.apply(r.context,g)}else{var b=r.length,m;for(c=0;c<b;c++)switch(r[c].once&&this.removeListener(t,r[c].fn,void 0,!0),y){case 1:r[c].fn.call(r[c].context);break;case 2:r[c].fn.call(r[c].context,e);break;case 3:r[c].fn.call(r[c].context,e,s);break;case 4:r[c].fn.call(r[c].context,e,s,n);break;default:if(!g)for(m=1,g=new Array(y-1);m<y;m++)g[m-1]=arguments[m];r[c].fn.apply(r[c].context,g)}}return!0};d.prototype.on=function(t,e,s){return J(this,t,e,s,!1)};d.prototype.once=function(t,e,s){return J(this,t,e,s,!0)};d.prototype.removeListener=function(t,e,s,n){var l=w?w+t:t;if(!this._events[l])return this;if(!e)return C(this,l),this;var h=this._events[l];if(h.fn)h.fn===e&&(!n||h.once)&&(!s||h.context===s)&&C(this,l);else{for(var u=0,r=[],y=h.length;u<y;u++)(h[u].fn!==e||n&&!h[u].once||s&&h[u].context!==s)&&r.push(h[u]);r.length?this._events[l]=r.length===1?r[0]:r:C(this,l)}return this};d.prototype.removeAllListeners=function(t){var e;return t?(e=w?w+t:t,this._events[e]&&C(this,e)):(this._events=new O,this._eventsCount=0),this};d.prototype.off=d.prototype.removeListener;d.prototype.addListener=d.prototype.on;d.prefixed=w;d.EventEmitter=d;typeof P<"u"&&(P.exports=d)});var ct={};rt(ct,{default:()=>I});module.exports=nt(ct);var V=L(T()),Y=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=>({add:(t,e)=>i.post(`/chat/${t?.id||t}/invite`,{chirper:e?.id||e}),list:(t,e)=>i.get("/chat",e),create:(t,e)=>i.post(`/chat/${t?.id||t}`,e),members:(t,e)=>i.get(`/chat/${t?.id||t}/members`,e),messages:(t,e)=>i.get(`/chat/${t?.id||t}/messages`,e),send:(t,e)=>i.post(`/chat/${t?.id||t}/send`,e),get:(t,e)=>i.post(`/chat/${t?.id||t}`,e)});var q=i=>({get:(t,e=null,s=null)=>i.get(`/:account/stat/${t}`,{from:e,to:s})});var j=i=>({get:t=>i.get(`/chirp/${t}`,{},!1,!1),list:({user:t,query:e,lang:s,mine:n,following:l,parent:h,username:u,skip:r,limit:y,search:g,contact:c,sort:b,filter:m,page:_}={})=>i.get("/chirp",{user:t,lang:s,mine:n,parent:h,following:l,query:e,username:u,skip:r,limit:y,search:g,contact:c,sort:b,filter:m,page:_},!1,!1),like:t=>i.post(`/chirp/${t}/like`),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)=>i.post(`/chirp/${e?.id||e}/respond`,{chirper:t?.id||t})});var R=i=>({get:t=>i.get(`/follow/${t}`),toggle:t=>i.post(`/follow/${t?.id||t}`)});var K=i=>({get:t=>i.get(`/chirper/${t}`),list:({user:t,skip:e,limit:s,search:n,contact:l,sort:h,filter:u,page:r}={})=>i.get("/chirper",{user:t,skip:e,limit:s,search:n,contact:l,sort:h,filter:u,page:r}),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"),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`)});var G=i=>({list:({lang:t}={})=>i.get("/trending",{lang:t},!1,!1)});var H=i=>({list:t=>i.get("/activity",t),count:t=>i.get("/activity/count",t),read:t=>i.post("/activity/count",t)});var lt=new V.default({length:10}),I=class{constructor({url:t,version:e}){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.options={path:"/ws",cors:!0,agent:!0,reconnect:!0,transports:["websocket"],withCredentials:!0};t&&(this.url=t),e&&(this.version=e),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.Chat=M(this),this.Stat=q(this),this.Chirp=j(this),this.Follow=R(this),this.Chirper=K(this),this.Trending=G(this),this.Activity=H(this),this.build()}build(){if(this.__resolveConnecting=null,this.connecting=new Promise(e=>{this.__resolveConnecting=e}),!this.url)return;let t=Y.default.connect(`${this.url}`,this.options);t.on("connect",async()=>{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={},n=!1){if(["patch","put","delete","post"].includes(t.toLowerCase())&&(n=!1),n&&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 n&&(this.cache[`${t}${e}${JSON.stringify(s)}`]=l,this.cache[`${t}${e}${JSON.stringify(s)}`].then(()=>{typeof n=="number"?setTimeout(()=>{delete this.cache[`${t}${e}${JSON.stringify(s)}`]},n):delete this.cache[`${t}${e}${JSON.stringify(s)}`]})),l.result}async wsFetch(t,e,s={},n=!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())&&(n=!1),n&&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=lt();console.time(`[chirper] [${h}] ${t}:${e} ${JSON.stringify(s)}`);let u=new Promise((r,y)=>{this.socket.once(h,({success:g,result:c,message:b})=>{if(console.timeEnd(`[chirper] [${h}] ${t}:${e} ${JSON.stringify(s)}`),g)return r(c);y(b)})});return n&&(this.cache[`${t}${e}${JSON.stringify(s)}`]=u,this.cache[`${t}${e}${JSON.stringify(s)}`].then(()=>{typeof n=="number"?setTimeout(()=>{delete this.cache[`${t}${e}${JSON.stringify(s)}`]},n):delete this.cache[`${t}${e}${JSON.stringify(s)}`]})),this.socket.emit("call",h,t.toUpperCase(),e,s),u}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 Z=Object.create;var S=Object.defineProperty;var tt=Object.getOwnPropertyDescriptor;var et=Object.getOwnPropertyNames;var it=Object.getPrototypeOf,st=Object.prototype.hasOwnProperty;var N=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),rt=(i,t)=>{for(var e in t)S(i,e,{get:t[e],enumerable:!0})},F=(i,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of et(t))!st.call(i,n)&&n!==e&&S(i,n,{get:()=>t[n],enumerable:!(s=tt(t,n))||s.enumerable});return i};var L=(i,t,e)=>(e=i!=null?Z(it(i)):{},F(t||!i||!i.__esModule?S(e,"default",{value:i,enumerable:!0}):e,i)),nt=i=>F(S({},"__esModule",{value:!0}),i);var T=N((ut,E)=>{var U=(()=>{var i=Object.defineProperty,t=Object.getOwnPropertySymbols,e=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable,n=(_,p,v)=>p in _?i(_,p,{enumerable:!0,configurable:!0,writable:!0,value:v}):_[p]=v,l=(_,p)=>{for(var v in p||(p={}))e.call(p,v)&&n(_,v,p[v]);if(t)for(var v of t(p))s.call(p,v)&&n(_,v,p[v]);return _},h=_=>i(_,"__esModule",{value:!0}),u=(_,p)=>{h(_);for(var v in p)i(_,v,{get:p[v],enumerable:!0})},r={};u(r,{DEFAULT_UUID_LENGTH:()=>g,default:()=>m});var y="4.4.4",g=6,c={dictionary:"alphanum",shuffle:!0,debug:!1,length:g},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=(...o)=>{let a=[...o];if(a[0]=`[short-unique-id] ${o[0]}`,this.debug===!0&&typeof console<"u"&&console!==null)return console.log(...a)},this.setDictionary=(o,a)=>{let f;if(o&&Array.isArray(o)&&o.length>1)f=o;else{f=[];let $;this.dictIndex=$=0;let x=`_${o}_dict_ranges`,D=this[x];Object.keys(D).forEach(W=>{let X=W;for(this.dictRange=D[X],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)f.push(String.fromCharCode(this.dictIndex))})}a&&(f=f.sort(()=>Math.random()-.5)),this.dict=f,this.dictLength=this.dict.length,this.counter=0},this.seq=()=>this.sequentialUUID(),this.sequentialUUID=()=>{let o,a,f="";o=this.counter;do a=o%this.dictLength,o=Math.trunc(o/this.dictLength),f+=this.dict[a];while(o!==0);return this.counter+=1,f},this.randomUUID=(o=this.uuidLength||g)=>{let a,f,$;if(o===null||typeof o>"u"||o<1)throw new Error("Invalid UUID Length Provided");let x=o>=0;for(a="",$=0;$<o;$+=1)f=parseInt((Math.random()*this.dictLength).toFixed(0),10)%this.dictLength,a+=this.dict[f];return a},this.availableUUIDs=(o=this.uuidLength)=>parseFloat(Math.pow([...new Set(this.dict)].length,o).toFixed(0)),this.approxMaxBeforeCollision=(o=this.availableUUIDs(this.uuidLength))=>parseFloat(Math.sqrt(Math.PI/2*o).toFixed(20)),this.collisionProbability=(o=this.availableUUIDs(this.uuidLength),a=this.uuidLength)=>parseFloat((this.approxMaxBeforeCollision(o)/this.availableUUIDs(a)).toFixed(20)),this.uniqueness=(o=this.availableUUIDs(this.uuidLength))=>{let a=parseFloat((1-this.approxMaxBeforeCollision(o)/o).toFixed(20));return a>1?1:a<0?0:a},this.getVersion=()=>this.version,this.stamp=o=>{if(typeof o!="number"||o<10)throw new Error("Param finalLength must be number greater than 10");let a=Math.floor(+new Date/1e3).toString(16),f=o-9,$=Math.round(Math.random()*(f>15?15:f)),x=this.randomUUID(f);return`${x.substr(0,$)}${a}${x.substr($)}${$.toString(16)}`},this.parseStamp=o=>{if(o.length<10)throw new Error("Stamp length invalid");let a=parseInt(o.substr(o.length-1,1),16);return new Date(parseInt(o.substr(a,8),16)*1e3)};let p=l(l({},c),_);this.counter=0,this.debug=!1,this.dict=[],this.version=y;let{dictionary:v,shuffle:z,length:Q}=p;return this.uuidLength=Q,this.setDictionary(v,z),this.debug=p.debug,this.log(this.dict),this.log(`Generator instantiated with Dictionary Size ${this.dictLength}`),new Proxy(this,{apply:(o,a,f)=>this.randomUUID(...f)})}},m=b;return m.default=b,r})();typeof E<"u"&&(E.exports=U.default),typeof window<"u"&&(U=U.default)});var A=N((pt,P)=>{"use strict";var ot=Object.prototype.hasOwnProperty,w="~";function O(){}Object.create&&(O.prototype=Object.create(null),new O().__proto__||(w=!1));function ht(i,t,e){this.fn=i,this.context=t,this.once=e||!1}function J(i,t,e,s,n){if(typeof e!="function")throw new TypeError("The listener must be a function");var l=new ht(e,s||i,n),h=w?w+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 C(i,t){--i._eventsCount===0?i._events=new O:delete i._events[t]}function d(){this._events=new O,this._eventsCount=0}d.prototype.eventNames=function(){var t=[],e,s;if(this._eventsCount===0)return t;for(s in e=this._events)ot.call(e,s)&&t.push(w?s.slice(1):s);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};d.prototype.listeners=function(t){var e=w?w+t:t,s=this._events[e];if(!s)return[];if(s.fn)return[s.fn];for(var n=0,l=s.length,h=new Array(l);n<l;n++)h[n]=s[n].fn;return h};d.prototype.listenerCount=function(t){var e=w?w+t:t,s=this._events[e];return s?s.fn?1:s.length:0};d.prototype.emit=function(t,e,s,n,l,h){var u=w?w+t:t;if(!this._events[u])return!1;var r=this._events[u],y=arguments.length,g,c;if(r.fn){switch(r.once&&this.removeListener(t,r.fn,void 0,!0),y){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,n),!0;case 5:return r.fn.call(r.context,e,s,n,l),!0;case 6:return r.fn.call(r.context,e,s,n,l,h),!0}for(c=1,g=new Array(y-1);c<y;c++)g[c-1]=arguments[c];r.fn.apply(r.context,g)}else{var b=r.length,m;for(c=0;c<b;c++)switch(r[c].once&&this.removeListener(t,r[c].fn,void 0,!0),y){case 1:r[c].fn.call(r[c].context);break;case 2:r[c].fn.call(r[c].context,e);break;case 3:r[c].fn.call(r[c].context,e,s);break;case 4:r[c].fn.call(r[c].context,e,s,n);break;default:if(!g)for(m=1,g=new Array(y-1);m<y;m++)g[m-1]=arguments[m];r[c].fn.apply(r[c].context,g)}}return!0};d.prototype.on=function(t,e,s){return J(this,t,e,s,!1)};d.prototype.once=function(t,e,s){return J(this,t,e,s,!0)};d.prototype.removeListener=function(t,e,s,n){var l=w?w+t:t;if(!this._events[l])return this;if(!e)return C(this,l),this;var h=this._events[l];if(h.fn)h.fn===e&&(!n||h.once)&&(!s||h.context===s)&&C(this,l);else{for(var u=0,r=[],y=h.length;u<y;u++)(h[u].fn!==e||n&&!h[u].once||s&&h[u].context!==s)&&r.push(h[u]);r.length?this._events[l]=r.length===1?r[0]:r:C(this,l)}return this};d.prototype.removeAllListeners=function(t){var e;return t?(e=w?w+t:t,this._events[e]&&C(this,e)):(this._events=new O,this._eventsCount=0),this};d.prototype.off=d.prototype.removeListener;d.prototype.addListener=d.prototype.on;d.prefixed=w;d.EventEmitter=d;typeof P<"u"&&(P.exports=d)});var ct={};rt(ct,{default:()=>I});module.exports=nt(ct);var V=L(T()),Y=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=>({add:(t,e)=>i.post(`/chat/${t?.id||t}/invite`,{chirper:e?.id||e}),list:(t,e)=>i.get("/chat",e),create:(t,e)=>i.post(`/chat/${t?.id||t}`,e),members:(t,e)=>i.get(`/chat/${t?.id||t}/members`,e),messages:(t,e)=>i.get(`/chat/${t?.id||t}/messages`,e),send:(t,e)=>i.post(`/chat/${t?.id||t}/send`,e),get:(t,e)=>i.post(`/chat/${t?.id||t}`,e)});var q=i=>({get:(t,e=null,s=null)=>i.get(`/:account/stat/${t}`,{from:e,to:s})});var j=i=>({get:t=>i.get(`/chirp/${t}`,{},!1,!1),list:({user:t,query:e,lang:s,mine:n,following:l,parent:h,username:u,skip:r,limit:y,search:g,contact:c,sort:b,filter:m,page:_}={})=>i.get("/chirp",{array:!0,user:t,lang:s,mine:n,parent:h,following:l,query:e,username:u,skip:r,limit:y,search:g,contact:c,sort:b,filter:m,page:_},!1,!1),like:t=>i.post(`/chirp/${t}/like`),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)=>i.post(`/chirp/${e?.id||e}/respond`,{chirper:t?.id||t})});var R=i=>({get:t=>i.get(`/follow/${t}`),toggle:t=>i.post(`/follow/${t?.id||t}`)});var K=i=>({get:t=>i.get(`/chirper/${t}`),list:({user:t,skip:e,limit:s,search:n,contact:l,sort:h,filter:u,page:r}={})=>i.get("/chirper",{user:t,skip:e,limit:s,search:n,contact:l,sort:h,filter:u,page:r}),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"),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`)});var G=i=>({list:({lang:t}={})=>i.get("/trending",{lang:t},!1,!1)});var H=i=>({list:t=>i.get("/activity",t),count:t=>i.get("/activity/count",t),read:t=>i.post("/activity/count",t)});var lt=new V.default({length:10}),I=class{constructor({url:t,version:e}){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.options={path:"/ws",cors:!0,agent:!0,reconnect:!0,transports:["websocket"],withCredentials:!0};t&&(this.url=t),e&&(this.version=e),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.Chat=M(this),this.Stat=q(this),this.Chirp=j(this),this.Follow=R(this),this.Chirper=K(this),this.Trending=G(this),this.Activity=H(this),this.build()}build(){if(this.__resolveConnecting=null,this.connecting=new Promise(e=>{this.__resolveConnecting=e}),!this.url)return;let t=Y.default.connect(`${this.url}`,this.options);t.on("connect",async()=>{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={},n=!1){if(["patch","put","delete","post"].includes(t.toLowerCase())&&(n=!1),n&&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 n&&(this.cache[`${t}${e}${JSON.stringify(s)}`]=l,this.cache[`${t}${e}${JSON.stringify(s)}`].then(()=>{typeof n=="number"?setTimeout(()=>{delete this.cache[`${t}${e}${JSON.stringify(s)}`]},n):delete this.cache[`${t}${e}${JSON.stringify(s)}`]})),l.result}async wsFetch(t,e,s={},n=!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())&&(n=!1),n&&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=lt();console.time(`[chirper] [${h}] ${t}:${e} ${JSON.stringify(s)}`);let u=new Promise((r,y)=>{this.socket.once(h,({success:g,result:c,message:b})=>{if(console.timeEnd(`[chirper] [${h}] ${t}:${e} ${JSON.stringify(s)}`),g)return r(c);y(b)})});return n&&(this.cache[`${t}${e}${JSON.stringify(s)}`]=u,this.cache[`${t}${e}${JSON.stringify(s)}`].then(()=>{typeof n=="number"?setTimeout(()=>{delete this.cache[`${t}${e}${JSON.stringify(s)}`]},n):delete this.cache[`${t}${e}${JSON.stringify(s)}`]})),this.socket.emit("call",h,t.toUpperCase(),e,s),u}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.18",
3
+ "version": "0.0.19",
4
4
  "description": "",
5
5
  "main": "dist/bundle.js",
6
6
  "scripts": {
package/src/api/Chirp.ts CHANGED
@@ -8,7 +8,7 @@ export default (api) => ({
8
8
  },
9
9
  list : ({ user, query, lang, mine, following, parent, username, skip, limit, search, contact, sort, filter, page } = {}) => {
10
10
  // return done
11
- return api.get(`/chirp`, { user, lang, mine, parent, following, query, username, skip, limit, search, contact, sort, filter, page }, false, false);
11
+ return api.get(`/chirp`, { array : true, user, lang, mine, parent, following, query, username, skip, limit, search, contact, sort, filter, page }, false, false);
12
12
  },
13
13
  like : (id) => {
14
14
  return api.post(`/chirp/${id}/like`);