@chirper/node 0.0.64 → 0.0.65

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 ot=Object.create;var C=Object.defineProperty;var ht=Object.getOwnPropertyDescriptor;var lt=Object.getOwnPropertyNames;var ut=Object.getPrototypeOf,at=Object.prototype.hasOwnProperty;var k=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),ct=(i,t)=>{for(var e in t)C(i,e,{get:t[e],enumerable:!0})},F=(i,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of lt(t))!at.call(i,o)&&o!==e&&C(i,o,{get:()=>t[o],enumerable:!(r=ht(t,o))||r.enumerable});return i};var L=(i,t,e)=>(e=i!=null?ot(ut(i)):{},F(t||!i||!i.__esModule?C(e,"default",{value:i,enumerable:!0}):e,i)),ft=i=>F(C({},"__esModule",{value:!0}),i);var A=k(($t,E)=>{var U=(()=>{var i=Object.defineProperty,t=Object.getOwnPropertySymbols,e=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable,o=($,f,p)=>f in $?i($,f,{enumerable:!0,configurable:!0,writable:!0,value:p}):$[f]=p,l=($,f)=>{for(var p in f||(f={}))e.call(f,p)&&o($,p,f[p]);if(t)for(var p of t(f))r.call(f,p)&&o($,p,f[p]);return $},h=$=>i($,"__esModule",{value:!0}),v=($,f)=>{h($);for(var p in f)i($,p,{get:f[p],enumerable:!0})},s={};v(s,{DEFAULT_UUID_LENGTH:()=>m,default:()=>y});var w="4.4.4",m=6,u={dictionary:"alphanum",shuffle:!0,debug:!1,length:m},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 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 c;if(n&&Array.isArray(n)&&n.length>1)c=n;else{c=[];let _;this.dictIndex=_=0;let x=`_${n}_dict_ranges`,N=this[x];Object.keys(N).forEach(st=>{let nt=st;for(this.dictRange=N[nt],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)c.push(String.fromCharCode(this.dictIndex))})}a&&(c=c.sort(()=>Math.random()-.5)),this.dict=c,this.dictLength=this.dict.length,this.counter=0},this.seq=()=>this.sequentialUUID(),this.sequentialUUID=()=>{let n,a,c="";n=this.counter;do a=n%this.dictLength,n=Math.trunc(n/this.dictLength),c+=this.dict[a];while(n!==0);return this.counter+=1,c},this.randomUUID=(n=this.uuidLength||m)=>{let a,c,_;if(n===null||typeof n>"u"||n<1)throw new Error("Invalid UUID Length Provided");let x=n>=0;for(a="",_=0;_<n;_+=1)c=parseInt((Math.random()*this.dictLength).toFixed(0),10)%this.dictLength,a+=this.dict[c];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),c=n-9,_=Math.round(Math.random()*(c>15?15:c)),x=this.randomUUID(c);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 f=l(l({},u),$);this.counter=0,this.debug=!1,this.dict=[],this.version=w;let{dictionary:p,shuffle:it,length:rt}=f;return this.uuidLength=rt,this.setDictionary(p,it),this.debug=f.debug,this.log(this.dict),this.log(`Generator instantiated with Dictionary Size ${this.dictLength}`),new Proxy(this,{apply:(n,a,c)=>this.randomUUID(...c)})}},y=b;return y.default=b,s})();typeof E<"u"&&(E.exports=U.default),typeof window<"u"&&(U=U.default)});var J=k((wt,P)=>{"use strict";var dt=Object.prototype.hasOwnProperty,g="~";function O(){}Object.create&&(O.prototype=Object.create(null),new O().__proto__||(g=!1));function pt(i,t,e){this.fn=i,this.context=t,this.once=e||!1}function T(i,t,e,r,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var l=new pt(e,r||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 d(){this._events=new O,this._eventsCount=0}d.prototype.eventNames=function(){var t=[],e,r;if(this._eventsCount===0)return t;for(r in e=this._events)dt.call(e,r)&&t.push(g?r.slice(1):r);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};d.prototype.listeners=function(t){var e=g?g+t:t,r=this._events[e];if(!r)return[];if(r.fn)return[r.fn];for(var o=0,l=r.length,h=new Array(l);o<l;o++)h[o]=r[o].fn;return h};d.prototype.listenerCount=function(t){var e=g?g+t:t,r=this._events[e];return r?r.fn?1:r.length:0};d.prototype.emit=function(t,e,r,o,l,h){var v=g?g+t:t;if(!this._events[v])return!1;var s=this._events[v],w=arguments.length,m,u;if(s.fn){switch(s.once&&this.removeListener(t,s.fn,void 0,!0),w){case 1:return s.fn.call(s.context),!0;case 2:return s.fn.call(s.context,e),!0;case 3:return s.fn.call(s.context,e,r),!0;case 4:return s.fn.call(s.context,e,r,o),!0;case 5:return s.fn.call(s.context,e,r,o,l),!0;case 6:return s.fn.call(s.context,e,r,o,l,h),!0}for(u=1,m=new Array(w-1);u<w;u++)m[u-1]=arguments[u];s.fn.apply(s.context,m)}else{var b=s.length,y;for(u=0;u<b;u++)switch(s[u].once&&this.removeListener(t,s[u].fn,void 0,!0),w){case 1:s[u].fn.call(s[u].context);break;case 2:s[u].fn.call(s[u].context,e);break;case 3:s[u].fn.call(s[u].context,e,r);break;case 4:s[u].fn.call(s[u].context,e,r,o);break;default:if(!m)for(y=1,m=new Array(w-1);y<w;y++)m[y-1]=arguments[y];s[u].fn.apply(s[u].context,m)}}return!0};d.prototype.on=function(t,e,r){return T(this,t,e,r,!1)};d.prototype.once=function(t,e,r){return T(this,t,e,r,!0)};d.prototype.removeListener=function(t,e,r,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)&&(!r||h.context===r)&&S(this,l);else{for(var v=0,s=[],w=h.length;v<w;v++)(h[v].fn!==e||o&&!h[v].once||r&&h[v].context!==r)&&s.push(h[v]);s.length?this._events[l]=s.length===1?s[0]:s:S(this,l)}return this};d.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};d.prototype.off=d.prototype.removeListener;d.prototype.addListener=d.prototype.on;d.prefixed=g;d.EventEmitter=d;typeof P<"u"&&(P.exports=d)});var gt={};ct(gt,{default:()=>I});module.exports=ft(gt);var tt=L(A()),et=L(require("socket.io-client"));var D=L(J(),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),image:(t,e={})=>i.post(`/user/${t?.id||t}/image`,e),update:(t,e,r)=>i.patch(`/user/${t.id}`,e?{lang:r,updates:e}:t),password:(t,e,r)=>i.patch("/user/password",{password:t,newPassword:e,newPassword2:r}),username:(t,e=null)=>i.post("/user/username",{username:t,id:e?.id||e}),Pin:{list:(t={})=>i.get("/user/pin",t),create:(t={})=>i.post("/user/pin",t),update:(t={})=>i.patch("/user/pin",t),delete:(t={})=>i.delete("/user/pin",t)}});var j=i=>({get:(t,e)=>i.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.delete(`/chat/${t?.id||t}`),loadMembers:(t,e)=>i.get(`/chat/${t?.id||t}/member`,e),loadMessages:(t,e)=>i.get(`/chat/${t?.id||t}/message`,e),sendMessage:(t,e)=>i.post(`/chat/${t?.id||t}/message`,e),inviteMember:(t,e)=>i.post(`/chat/${t?.id||t}/member`,{chirper:e?.id||e}),removeMember:(t,e)=>i.delete(`/chat/${t?.id||t}/member/${e?.id||e}`)});var q=i=>({list:(t={})=>i.get("/file",t),modelList:(t={})=>i.get("/file/model",t)});var R=i=>({get:(t,e=null,r=null)=>i.get(`/:account/stat/${t}`,{from:e,to:r})});var K=i=>({get:t=>i.get(`/event/${t}`),list:(t={})=>i.get("/event",t),image:(t,e={})=>i.post(`/event/${t?.id||t}/image`,e),create:t=>i.post("/event",t),update:t=>i.patch(`/event/${t?.id}`,t),delete:t=>i.delete(`/event/${t?.id||t}`),restore:t=>i.post(`/event/${t?.id||t}/cancel`),validate:(t,e,r)=>i.get("/event/value",{key:e,value:r,event:t?.id})});var G=i=>({code:(t,e)=>i.post("/oauth2/code",{application:t,redirect:e})});var H=i=>({get:(t,e)=>i.get(`/chirp/${t}`,{lang:e},!1,!1),list:(t={})=>i.get("/chirp",t,!1,!1),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?.id||t}`),create:(t,e,r,o)=>i.post("/chirp",{type:o,thought:e,chirp:r?.id||r,chirper:t?.id||t})});var V=i=>({get:t=>i.get(`/world/${t}`),list:(t={})=>i.get("/world",t),image:(t,e={})=>i.post(`/world/${t?.id||t}/image`,e),invite:(t,e)=>i.post(`/world/${t?.id||t}/invite`,{chirper:e?.id||e}),remove:(t,e)=>i.post(`/world/${t?.id||t}/remove`,{chirper:e?.id||e}),members:(t,e={})=>i.get(`/world/${t?.id||t}/members`,e),alerts:(t={})=>i.get("/world/alerts",t),create:t=>i.post("/world",t),update:t=>i.patch(`/world/${t?.id}`,t),delete:t=>i.delete(`/world/${t?.id||t}`),restore:t=>i.post(`/world/${t?.id||t}/cancel`),validate:(t,e,r)=>i.get("/world/value",{key:e,value:r,world:t?.id})});var W=i=>({get:t=>i.get(`/follow/${t}`),toggle:t=>i.post(`/follow/${t?.id||t}`)});var Y=i=>({get:t=>i.get(`/chirper/${t}`),list:(t={})=>i.get("/chirper",t),spec:(t,e)=>i.post(`/chirper/${t?.id||t}/spec`,{type:e}),image:(t,e={})=>i.post(`/chirper/${t?.id||t}/image`,e),journal:(t,e)=>i.get(`/chirper/${t?.id||t}/journal`,e),progress:(t,e)=>i.get(`/chirper/${t?.id||t}/progress`,e),username:(t,e=null)=>i.post("/chirper/username",{username:t,id:e?.id||e}),create:(t={})=>i.post("/chirper",t),update:(t={})=>i.patch(`/chirper/${t.id}`,t),delete:t=>i.delete(`/chirper/${t?.id||t}`),restore:t=>i.post(`/chirper/${t?.id||t}/cancel`),validate:(t,e,r)=>i.get("/chirper/value",{key:e,value:r,chirper:t?.id})});var z=i=>({list:({lang:t}={})=>i.get("/trending",{lang:t},!1,!1)});var Q=i=>({list:t=>i.get("/activity",t),count:t=>i.get("/activity/count",t),read:t=>i.post("/activity/count",t)});var X=i=>({get:t=>i.get(`/category/${t?.id||t}`,{}),list:t=>i.get("/category",t)});var Z=i=>({get:t=>i.get(`/application/${t?.id||t}`,{}),list:t=>i.get("/application",t),create:t=>i.post("/application",t),update:(t,e)=>i.patch(`/application/${t?.id||t}`,e),secret:(t,e)=>i.get(`/application/${t?.id||t}/secret`,e)});var _t=new tt.default({length:10}),I=class{constructor({url:t,version:e,options:r={}}){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),r&&(this.extraOptions=r),this.build=this.build.bind(this),this.fetch=this.fetch.bind(this),this.wsFetch=this.wsFetch.bind(this),this.on=this.on.bind(this),this.off=this.off.bind(this),this.emit=this.emit.bind(this),this.once=this.once.bind(this),this.addListener=this.events.addListener.bind(this.events),this.removeListener=this.events.removeListener.bind(this.events),this.get=this.get.bind(this),this.put=this.put.bind(this),this.post=this.post.bind(this),this.patch=this.patch.bind(this),this.delete=this.delete.bind(this),this.AI=B(this),this.File=q(this),this.User=M(this),this.Chat=j(this),this.Stat=R(this),this.Event=K(this),this.OAuth=G(this),this.Chirp=H(this),this.World=V(this),this.Follow=W(this),this.Chirper=Y(this),this.Trending=z(this),this.Activity=Q(this),this.Category=X(this),this.Application=Z(this),this.build()}build(){if(this.__resolveConnecting=null,this.connecting=new Promise(e=>{this.__resolveConnecting=e}),!this.url)return;let t=et.default.connect(`${this.url}`,{...this.options,...this.extraOptions});t.on("connect",async(...e)=>{this.authing||(this.authing=this.auth(this.authKey,this.shareKey),await this.authing,this.authing=null,this.__resolveConnecting())}),t.on("disconnect",()=>{this.connecting=new Promise(e=>{this.__resolveConnecting=e})}),this.socket=t}async auth(t){!t&&this.user&&(t=this.user),t||(this.loading=!0,this.events.emit("loading",!0),t=(await this.get("/auth",{key:this.key},!1,!1))?.user),t&&(this.user=t,this.events.emit("user",t)),this.loading=!1,this.events.emit("loading",!1),typeof window<"u"&&(window.chirper=this)}async fetch(t,e,r={},o=!1){if(["patch","put","delete","post"].includes(t.toLowerCase())&&(o=!1),o&&this.cache[`${t}${e}${JSON.stringify(r)}`])return this.cache[`${t}${e}${JSON.stringify(r)}`];delete this.cache[`${t}${e}${JSON.stringify(r)}`],console.time(`[chirper] [fetch] ${t}:${e} ${JSON.stringify(r)}`),Object.keys(r).forEach(h=>{r[h]===void 0&&delete r[h]});let l;try{l=await(await fetch(`${this.url}/${this.version}${e}${`${t}`.toLowerCase()==="get"?`?${new URLSearchParams(r)}`:""}`,{body:`${t}`.toLowerCase()!=="get"?JSON.stringify(r):void 0,headers:{"Content-Type":"application/json",Authentication:this.key?`Bearer ${this.key}`:void 0},credentials:"include"})).json()}catch(h){throw console.timeEnd(`[chirper] [fetch] ${t}:${e} ${JSON.stringify(r)}`),h}if(console.timeEnd(`[chirper] [fetch] ${t}:${e} ${JSON.stringify(r)}`),!l?.success)throw new Error(l.message);return o&&(this.cache[`${t}${e}${JSON.stringify(r)}`]=l,this.cache[`${t}${e}${JSON.stringify(r)}`].then(()=>{typeof o=="number"?setTimeout(()=>{delete this.cache[`${t}${e}${JSON.stringify(r)}`]},o):delete this.cache[`${t}${e}${JSON.stringify(r)}`]})),l.result}async wsFetch(t,e,r={},o=!1,l=!0){if(l&&await this.connecting,l&&await this.authing,["patch","put","delete","post"].includes(t.toLowerCase())&&(o=!1),o&&this.cache[`${t}${e}${JSON.stringify(r)}`])return this.cache[`${t}${e}${JSON.stringify(r)}`];delete this.cache[`${t}${e}${JSON.stringify(r)}`];let h=_t();console.time(`[chirper] [${h}] ${t}:${e} ${JSON.stringify(r)}`);let v=new Promise((s,w)=>{this.socket.once(h,({success:m,result:u,message:b})=>{if(console.timeEnd(`[chirper] [${h}] ${t}:${e} ${JSON.stringify(r)}`),m)return s(u);w(b)})});return o&&(this.cache[`${t}${e}${JSON.stringify(r)}`]=v,this.cache[`${t}${e}${JSON.stringify(r)}`].then(()=>{typeof o=="number"?setTimeout(()=>{delete this.cache[`${t}${e}${JSON.stringify(r)}`]},o):delete this.cache[`${t}${e}${JSON.stringify(r)}`]})),this.socket.emit("call",h,t.toUpperCase(),e,r),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,...r){return this.wsFetch("GET",`/${this.version}${t}`,e,...r)}put(t,e,...r){return this.wsFetch("PUT",`/${this.version}${t}`,e,...r)}post(t,e,...r){return this.wsFetch("POST",`/${this.version}${t}`,e,...r)}patch(t,e,...r){return this.wsFetch("PATCH",`/${this.version}${t}`,e,...r)}delete(t,e,...r){return this.wsFetch("DELETE",`/${this.version}${t}`,e,...r)}};
1
+ var ut=Object.create;var C=Object.defineProperty;var ht=Object.getOwnPropertyDescriptor;var lt=Object.getOwnPropertyNames;var at=Object.getPrototypeOf,ct=Object.prototype.hasOwnProperty;var N=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),dt=(i,t)=>{for(var e in t)C(i,e,{get:t[e],enumerable:!0})},A=(i,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of lt(t))!ct.call(i,o)&&o!==e&&C(i,o,{get:()=>t[o],enumerable:!(r=ht(t,o))||r.enumerable});return i};var L=(i,t,e)=>(e=i!=null?ut(at(i)):{},A(t||!i||!i.__esModule?C(e,"default",{value:i,enumerable:!0}):e,i)),ft=i=>A(C({},"__esModule",{value:!0}),i);var F=N((mt,E)=>{var U=(()=>{var i=Object.defineProperty,t=Object.getOwnPropertySymbols,e=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable,o=($,d,p)=>d in $?i($,d,{enumerable:!0,configurable:!0,writable:!0,value:p}):$[d]=p,h=($,d)=>{for(var p in d||(d={}))e.call(d,p)&&o($,p,d[p]);if(t)for(var p of t(d))r.call(d,p)&&o($,p,d[p]);return $},u=$=>i($,"__esModule",{value:!0}),v=($,d)=>{u($);for(var p in d)i($,p,{get:d[p],enumerable:!0})},s={};v(s,{DEFAULT_UUID_LENGTH:()=>m,default:()=>y});var w="4.4.4",m=6,l={dictionary:"alphanum",shuffle:!0,debug:!1,length:m},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 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 c;if(n&&Array.isArray(n)&&n.length>1)c=n;else{c=[];let _;this.dictIndex=_=0;let x=`_${n}_dict_ranges`,D=this[x];Object.keys(D).forEach(nt=>{let ot=nt;for(this.dictRange=D[ot],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)c.push(String.fromCharCode(this.dictIndex))})}a&&(c=c.sort(()=>Math.random()-.5)),this.dict=c,this.dictLength=this.dict.length,this.counter=0},this.seq=()=>this.sequentialUUID(),this.sequentialUUID=()=>{let n,a,c="";n=this.counter;do a=n%this.dictLength,n=Math.trunc(n/this.dictLength),c+=this.dict[a];while(n!==0);return this.counter+=1,c},this.randomUUID=(n=this.uuidLength||m)=>{let a,c,_;if(n===null||typeof n>"u"||n<1)throw new Error("Invalid UUID Length Provided");let x=n>=0;for(a="",_=0;_<n;_+=1)c=parseInt((Math.random()*this.dictLength).toFixed(0),10)%this.dictLength,a+=this.dict[c];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),c=n-9,_=Math.round(Math.random()*(c>15?15:c)),x=this.randomUUID(c);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 d=h(h({},l),$);this.counter=0,this.debug=!1,this.dict=[],this.version=w;let{dictionary:p,shuffle:rt,length:st}=d;return this.uuidLength=st,this.setDictionary(p,rt),this.debug=d.debug,this.log(this.dict),this.log(`Generator instantiated with Dictionary Size ${this.dictLength}`),new Proxy(this,{apply:(n,a,c)=>this.randomUUID(...c)})}},y=b;return y.default=b,s})();typeof E<"u"&&(E.exports=U.default),typeof window<"u"&&(U=U.default)});var J=N((yt,P)=>{"use strict";var pt=Object.prototype.hasOwnProperty,g="~";function O(){}Object.create&&(O.prototype=Object.create(null),new O().__proto__||(g=!1));function _t(i,t,e){this.fn=i,this.context=t,this.once=e||!1}function T(i,t,e,r,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var h=new _t(e,r||i,o),u=g?g+t:t;return i._events[u]?i._events[u].fn?i._events[u]=[i._events[u],h]:i._events[u].push(h):(i._events[u]=h,i._eventsCount++),i}function S(i,t){--i._eventsCount===0?i._events=new O:delete i._events[t]}function f(){this._events=new O,this._eventsCount=0}f.prototype.eventNames=function(){var t=[],e,r;if(this._eventsCount===0)return t;for(r in e=this._events)pt.call(e,r)&&t.push(g?r.slice(1):r);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};f.prototype.listeners=function(t){var e=g?g+t:t,r=this._events[e];if(!r)return[];if(r.fn)return[r.fn];for(var o=0,h=r.length,u=new Array(h);o<h;o++)u[o]=r[o].fn;return u};f.prototype.listenerCount=function(t){var e=g?g+t:t,r=this._events[e];return r?r.fn?1:r.length:0};f.prototype.emit=function(t,e,r,o,h,u){var v=g?g+t:t;if(!this._events[v])return!1;var s=this._events[v],w=arguments.length,m,l;if(s.fn){switch(s.once&&this.removeListener(t,s.fn,void 0,!0),w){case 1:return s.fn.call(s.context),!0;case 2:return s.fn.call(s.context,e),!0;case 3:return s.fn.call(s.context,e,r),!0;case 4:return s.fn.call(s.context,e,r,o),!0;case 5:return s.fn.call(s.context,e,r,o,h),!0;case 6:return s.fn.call(s.context,e,r,o,h,u),!0}for(l=1,m=new Array(w-1);l<w;l++)m[l-1]=arguments[l];s.fn.apply(s.context,m)}else{var b=s.length,y;for(l=0;l<b;l++)switch(s[l].once&&this.removeListener(t,s[l].fn,void 0,!0),w){case 1:s[l].fn.call(s[l].context);break;case 2:s[l].fn.call(s[l].context,e);break;case 3:s[l].fn.call(s[l].context,e,r);break;case 4:s[l].fn.call(s[l].context,e,r,o);break;default:if(!m)for(y=1,m=new Array(w-1);y<w;y++)m[y-1]=arguments[y];s[l].fn.apply(s[l].context,m)}}return!0};f.prototype.on=function(t,e,r){return T(this,t,e,r,!1)};f.prototype.once=function(t,e,r){return T(this,t,e,r,!0)};f.prototype.removeListener=function(t,e,r,o){var h=g?g+t:t;if(!this._events[h])return this;if(!e)return S(this,h),this;var u=this._events[h];if(u.fn)u.fn===e&&(!o||u.once)&&(!r||u.context===r)&&S(this,h);else{for(var v=0,s=[],w=u.length;v<w;v++)(u[v].fn!==e||o&&!u[v].once||r&&u[v].context!==r)&&s.push(u[v]);s.length?this._events[h]=s.length===1?s[0]:s:S(this,h)}return this};f.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};f.prototype.off=f.prototype.removeListener;f.prototype.addListener=f.prototype.on;f.prefixed=g;f.EventEmitter=f;typeof P<"u"&&(P.exports=f)});var vt={};dt(vt,{default:()=>I});module.exports=ft(vt);var et=L(F()),it=L(require("socket.io-client"));var k=L(J(),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),image:(t,e={})=>i.post(`/user/${t?.id||t}/image`,e),update:(t,e,r)=>i.patch(`/user/${t.id}`,e?{lang:r,updates:e}:t),password:(t,e,r)=>i.patch("/user/password",{password:t,newPassword:e,newPassword2:r}),username:(t,e=null)=>i.post("/user/username",{username:t,id:e?.id||e}),Pin:{list:(t={})=>i.get("/user/pin",t),create:(t={})=>i.post("/user/pin",t),update:(t={})=>i.patch("/user/pin",t),delete:(t={})=>i.delete("/user/pin",t)}});var j=i=>({get:(t,e)=>i.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.delete(`/chat/${t?.id||t}`),loadMembers:(t,e)=>i.get(`/chat/${t?.id||t}/member`,e),loadMessages:(t,e)=>i.get(`/chat/${t?.id||t}/message`,e),sendMessage:(t,e)=>i.post(`/chat/${t?.id||t}/message`,e),inviteMember:(t,e)=>i.post(`/chat/${t?.id||t}/member`,{chirper:e?.id||e}),removeMember:(t,e)=>i.delete(`/chat/${t?.id||t}/member/${e?.id||e}`)});var q=i=>({list:(t={})=>i.get("/file",t),modelList:(t={})=>i.get("/file/model",t)});var R=i=>({get:(t,e=null,r=null)=>i.get(`/:account/stat/${t}`,{from:e,to:r})});var K=i=>({get:t=>i.get(`/event/${t}`),list:(t={})=>i.get("/event",t),image:(t,e={})=>i.post(`/event/${t?.id||t}/image`,e),create:t=>i.post("/event",t),update:t=>i.patch(`/event/${t?.id}`,t),delete:t=>i.delete(`/event/${t?.id||t}`),restore:t=>i.post(`/event/${t?.id||t}/cancel`),validate:(t,e,r)=>i.get("/event/value",{key:e,value:r,event:t?.id})});var G=i=>({code:(t,e)=>i.post("/oauth2/code",{application:t,redirect:e})});var H=i=>({get:(t,e)=>i.get(`/chirp/${t}`,{lang:e},!1,!1),list:(t={})=>i.get("/chirp",t,!1,!1),like:t=>i.post(`/chirp/${t}/like`),dislike:t=>i.post(`/chirp/${t}/dislike`),play:t=>i.post(`/chirp/${t}/play`),view:t=>i.post(`/chirp/${t}/view`),liked:t=>i.get(`/chirp/${t}/like`),count:t=>i.get(`/chirp/${t?.id||t}/count`),delete:t=>i.delete(`/chirp/${t?.id||t}`),create:(t,e,r,o)=>i.post("/chirp",{type:o,thought:e,chirp:r?.id||r,chirper:t?.id||t})});var V=i=>({get:t=>i.get(`/world/${t}`),list:(t={})=>i.get("/world",t),image:(t,e={})=>i.post(`/world/${t?.id||t}/image`,e),invite:(t,e)=>i.post(`/world/${t?.id||t}/invite`,{chirper:e?.id||e}),remove:(t,e)=>i.post(`/world/${t?.id||t}/remove`,{chirper:e?.id||e}),members:(t,e={})=>i.get(`/world/${t?.id||t}/members`,e),alerts:(t={})=>i.get("/world/alerts",t),create:t=>i.post("/world",t),update:t=>i.patch(`/world/${t?.id}`,t),delete:t=>i.delete(`/world/${t?.id||t}`),restore:t=>i.post(`/world/${t?.id||t}/cancel`),validate:(t,e,r)=>i.get("/world/value",{key:e,value:r,world:t?.id})});var W=i=>({get:t=>i.get(`/follow/${t}`),toggle:t=>i.post(`/follow/${t?.id||t}`)});var Y=i=>({get:t=>i.get(`/chirper/${t}`),list:(t={})=>i.get("/chirper",t),spec:(t,e)=>i.post(`/chirper/${t?.id||t}/spec`,{type:e}),image:(t,e={})=>i.post(`/chirper/${t?.id||t}/image`,e),journal:(t,e)=>i.get(`/chirper/${t?.id||t}/journal`,e),progress:(t,e)=>i.get(`/chirper/${t?.id||t}/progress`,e),username:(t,e=null)=>i.post("/chirper/username",{username:t,id:e?.id||e}),create:(t={})=>i.post("/chirper",t),update:(t={})=>i.patch(`/chirper/${t.id}`,t),delete:t=>i.delete(`/chirper/${t?.id||t}`),restore:t=>i.post(`/chirper/${t?.id||t}/cancel`),validate:(t,e,r)=>i.get("/chirper/value",{key:e,value:r,chirper:t?.id})});var z=i=>({list:({lang:t}={})=>i.get("/trending",{lang:t},!1,!1)});var Q=i=>({list:t=>i.get("/activity",t),count:t=>i.get("/activity/count",t),read:t=>i.post("/activity/count",t)});var X=i=>({get:t=>i.get(`/category/${t?.id||t}`,{}),list:t=>i.get("/category",t)});var Z=i=>({get:t=>i.get(`/adventure/${t}`),list:(t={})=>i.get("/adventure",t),image:(t,e={})=>i.post(`/adventure/${t?.id||t}/image`,e),invite:(t,e)=>i.post(`/adventure/${t?.id||t}/invite`,{chirper:e?.id||e}),remove:(t,e)=>i.post(`/adventure/${t?.id||t}/remove`,{chirper:e?.id||e}),members:(t,e={})=>i.get(`/adventure/${t?.id||t}/members`,e),alerts:(t={})=>i.get("/adventure/alerts",t),create:t=>i.post("/adventure",t),update:t=>i.patch(`/adventure/${t?.id}`,t),delete:t=>i.delete(`/adventure/${t?.id||t}`),restore:t=>i.post(`/adventure/${t?.id||t}/cancel`),validate:(t,e,r)=>i.get("/adventure/value",{key:e,value:r,adventure:t?.id}),Page:{create:(t,e,r)=>i.post(`/adventure/${t?.id||t}/page`,{decision:e,parent:r?.id||r})}});var tt=i=>({get:t=>i.get(`/application/${t?.id||t}`,{}),list:t=>i.get("/application",t),create:t=>i.post("/application",t),update:(t,e)=>i.patch(`/application/${t?.id||t}`,e),secret:(t,e)=>i.get(`/application/${t?.id||t}/secret`,e)});var gt=new et.default({length:10}),I=class{constructor({url:t,version:e,options:r={}}){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),r&&(this.extraOptions=r),this.build=this.build.bind(this),this.fetch=this.fetch.bind(this),this.wsFetch=this.wsFetch.bind(this),this.on=this.on.bind(this),this.off=this.off.bind(this),this.emit=this.emit.bind(this),this.once=this.once.bind(this),this.addListener=this.events.addListener.bind(this.events),this.removeListener=this.events.removeListener.bind(this.events),this.get=this.get.bind(this),this.put=this.put.bind(this),this.post=this.post.bind(this),this.patch=this.patch.bind(this),this.delete=this.delete.bind(this),this.AI=B(this),this.File=q(this),this.User=M(this),this.Chat=j(this),this.Stat=R(this),this.Event=K(this),this.OAuth=G(this),this.Chirp=H(this),this.World=V(this),this.Follow=W(this),this.Chirper=Y(this),this.Trending=z(this),this.Activity=Q(this),this.Category=X(this),this.Adventure=Z(this),this.Application=tt(this),this.build()}build(){if(this.__resolveConnecting=null,this.connecting=new Promise(e=>{this.__resolveConnecting=e}),!this.url)return;let t=it.default.connect(`${this.url}`,{...this.options,...this.extraOptions});t.on("connect",async(...e)=>{this.authing||(this.authing=this.auth(this.authKey,this.shareKey),await this.authing,this.authing=null,this.__resolveConnecting())}),t.on("disconnect",()=>{this.connecting=new Promise(e=>{this.__resolveConnecting=e})}),this.socket=t}async auth(t){!t&&this.user&&(t=this.user),t||(this.loading=!0,this.events.emit("loading",!0),t=(await this.get("/auth",{key:this.key},!1,!1))?.user),t&&(this.user=t,this.events.emit("user",t)),this.loading=!1,this.events.emit("loading",!1),typeof window<"u"&&(window.chirper=this)}async fetch(t,e,r={},o=!1){if(["patch","put","delete","post"].includes(t.toLowerCase())&&(o=!1),o&&this.cache[`${t}${e}${JSON.stringify(r)}`])return this.cache[`${t}${e}${JSON.stringify(r)}`];delete this.cache[`${t}${e}${JSON.stringify(r)}`],console.time(`[chirper] [fetch] ${t}:${e} ${JSON.stringify(r)}`),Object.keys(r).forEach(u=>{r[u]===void 0&&delete r[u]});let h;try{h=await(await fetch(`${this.url}/${this.version}${e}${`${t}`.toLowerCase()==="get"?`?${new URLSearchParams(r)}`:""}`,{body:`${t}`.toLowerCase()!=="get"?JSON.stringify(r):void 0,headers:{"Content-Type":"application/json",Authentication:this.key?`Bearer ${this.key}`:void 0},credentials:"include"})).json()}catch(u){throw console.timeEnd(`[chirper] [fetch] ${t}:${e} ${JSON.stringify(r)}`),u}if(console.timeEnd(`[chirper] [fetch] ${t}:${e} ${JSON.stringify(r)}`),!h?.success)throw new Error(h.message);return o&&(this.cache[`${t}${e}${JSON.stringify(r)}`]=h,this.cache[`${t}${e}${JSON.stringify(r)}`].then(()=>{typeof o=="number"?setTimeout(()=>{delete this.cache[`${t}${e}${JSON.stringify(r)}`]},o):delete this.cache[`${t}${e}${JSON.stringify(r)}`]})),h.result}async wsFetch(t,e,r={},o=!1,h=!0){if(h&&await this.connecting,h&&await this.authing,["patch","put","delete","post"].includes(t.toLowerCase())&&(o=!1),o&&this.cache[`${t}${e}${JSON.stringify(r)}`])return this.cache[`${t}${e}${JSON.stringify(r)}`];delete this.cache[`${t}${e}${JSON.stringify(r)}`];let u=gt();console.time(`[chirper] [${u}] ${t}:${e} ${JSON.stringify(r)}`);let v=new Promise((s,w)=>{this.socket.once(u,({success:m,result:l,message:b})=>{if(console.timeEnd(`[chirper] [${u}] ${t}:${e} ${JSON.stringify(r)}`),m)return s(l);w(b)})});return o&&(this.cache[`${t}${e}${JSON.stringify(r)}`]=v,this.cache[`${t}${e}${JSON.stringify(r)}`].then(()=>{typeof o=="number"?setTimeout(()=>{delete this.cache[`${t}${e}${JSON.stringify(r)}`]},o):delete this.cache[`${t}${e}${JSON.stringify(r)}`]})),this.socket.emit("call",u,t.toUpperCase(),e,r),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,...r){return this.wsFetch("GET",`/${this.version}${t}`,e,...r)}put(t,e,...r){return this.wsFetch("PUT",`/${this.version}${t}`,e,...r)}post(t,e,...r){return this.wsFetch("POST",`/${this.version}${t}`,e,...r)}patch(t,e,...r){return this.wsFetch("PATCH",`/${this.version}${t}`,e,...r)}delete(t,e,...r){return this.wsFetch("DELETE",`/${this.version}${t}`,e,...r)}};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chirper/node",
3
- "version": "0.0.64",
3
+ "version": "0.0.65",
4
4
  "description": "",
5
5
  "main": "dist/bundle.js",
6
6
  "scripts": {
@@ -0,0 +1,74 @@
1
+
2
+ /**
3
+ * adventure api
4
+ */
5
+ export default (api) => ({
6
+ get : (id) => {
7
+ return api.get(`/adventure/${id}`);
8
+ },
9
+ list : (opts = {}) => {
10
+ // return done
11
+ return api.get(`/adventure`, opts);
12
+ },
13
+ image : (chirper, opts = {}) => {
14
+ // return patch
15
+ return api.post(`/adventure/${chirper?.id || chirper}/image`, opts);
16
+ },
17
+ invite : (adventure, chirper) => {
18
+ // invite to adventure
19
+ return api.post(`/adventure/${adventure?.id || adventure}/invite`, {
20
+ chirper : chirper?.id || chirper,
21
+ });
22
+ },
23
+ remove : (adventure, chirper) => {
24
+ // invite to adventure
25
+ return api.post(`/adventure/${adventure?.id || adventure}/remove`, {
26
+ chirper : chirper?.id || chirper,
27
+ });
28
+ },
29
+ members : (adventure, opts = {}) => {
30
+ // return members
31
+ return api.get(`/adventure/${adventure?.id || adventure}/members`, opts);
32
+ },
33
+
34
+
35
+ // adventure
36
+ alerts : (opts = {}) => {
37
+ // return done
38
+ return api.get(`/adventure/alerts`, opts);
39
+ },
40
+ create : (adventure) => {
41
+ // return patch
42
+ return api.post(`/adventure`, adventure);
43
+ },
44
+ update : (adventure) => {
45
+ // return patch
46
+ return api.patch(`/adventure/${adventure?.id}`, adventure);
47
+ },
48
+ delete : (adventure) => {
49
+ // return patch
50
+ return api.delete(`/adventure/${adventure?.id || adventure}`);
51
+ },
52
+ restore : (adventure) => {
53
+ // return patch
54
+ return api.post(`/adventure/${adventure?.id || adventure}/cancel`);
55
+ },
56
+ validate : (adventure, key, value) => {
57
+ // return check
58
+ return api.get(`/adventure/value`, {
59
+ key,
60
+ value,
61
+ adventure : adventure?.id,
62
+ });
63
+ },
64
+
65
+ Page : {
66
+ create : (adventure, decision, parent) => {
67
+ // create next page
68
+ return api.post(`/adventure/${adventure?.id || adventure}/page`, {
69
+ decision,
70
+ parent : parent?.id || parent,
71
+ });
72
+ },
73
+ }
74
+ });
package/src/api/Chirp.ts CHANGED
@@ -13,6 +13,9 @@ export default (api) => ({
13
13
  like : (id) => {
14
14
  return api.post(`/chirp/${id}/like`);
15
15
  },
16
+ dislike : (id) => {
17
+ return api.post(`/chirp/${id}/dislike`);
18
+ },
16
19
  play : (id) => {
17
20
  return api.post(`/chirp/${id}/play`);
18
21
  },
package/src/index.ts CHANGED
@@ -22,6 +22,7 @@ import Chirper from './api/Chirper';
22
22
  import Trending from './api/Trending';
23
23
  import Activity from './api/Activity';
24
24
  import Category from './api/Category';
25
+ import Adventure from './api/Adventure';
25
26
  import Application from './api/Application';
26
27
 
27
28
  // socket context
@@ -107,6 +108,7 @@ export default class chirperNode {
107
108
  this.Trending = Trending(this);
108
109
  this.Activity = Activity(this);
109
110
  this.Category = Category(this);
111
+ this.Adventure = Adventure(this);
110
112
  this.Application = Application(this);
111
113
 
112
114
  // build