@chirper/node 0.0.70 → 0.0.72

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 lt=Object.create;var C=Object.defineProperty;var ht=Object.getOwnPropertyDescriptor;var at=Object.getOwnPropertyNames;var ct=Object.getPrototypeOf,dt=Object.prototype.hasOwnProperty;var D=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),ft=(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 at(t))!dt.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?lt(ct(i)):{},A(t||!i||!i.__esModule?C(e,"default",{value:i,enumerable:!0}):e,i)),pt=i=>A(C({},"__esModule",{value:!0}),i);var F=D((wt,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,l=($,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,h={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 g;this.dictIndex=g=0;let x=`_${n}_dict_ranges`,k=this[x];Object.keys(k).forEach(ot=>{let ut=ot;for(this.dictRange=k[ut],this.lowerBound=this.dictRange[0],this.upperBound=this.dictRange[1],this.dictIndex=g=this.lowerBound;this.lowerBound<=this.upperBound?g<this.upperBound:g>this.upperBound;this.dictIndex=this.lowerBound<=this.upperBound?g+=1:g-=1)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,g;if(n===null||typeof n>"u"||n<1)throw new Error("Invalid UUID Length Provided");let x=n>=0;for(a="",g=0;g<n;g+=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,g=Math.round(Math.random()*(c>15?15:c)),x=this.randomUUID(c);return`${x.substr(0,g)}${a}${x.substr(g)}${g.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=l(l({},h),$);this.counter=0,this.debug=!1,this.dict=[],this.version=w;let{dictionary:p,shuffle:st,length:nt}=d;return this.uuidLength=nt,this.setDictionary(p,st),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=D((bt,P)=>{"use strict";var gt=Object.prototype.hasOwnProperty,_="~";function O(){}Object.create&&(O.prototype=Object.create(null),new O().__proto__||(_=!1));function _t(i,t,e){this.fn=i,this.context=t,this.once=e||!1}function T(i,t,e,r,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var l=new _t(e,r||i,o),u=_?_+t:t;return i._events[u]?i._events[u].fn?i._events[u]=[i._events[u],l]:i._events[u].push(l):(i._events[u]=l,i._eventsCount++),i}function 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)gt.call(e,r)&&t.push(_?r.slice(1):r);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};f.prototype.listeners=function(t){var e=_?_+t:t,r=this._events[e];if(!r)return[];if(r.fn)return[r.fn];for(var o=0,l=r.length,u=new Array(l);o<l;o++)u[o]=r[o].fn;return u};f.prototype.listenerCount=function(t){var e=_?_+t:t,r=this._events[e];return r?r.fn?1:r.length:0};f.prototype.emit=function(t,e,r,o,l,u){var v=_?_+t:t;if(!this._events[v])return!1;var s=this._events[v],w=arguments.length,m,h;if(s.fn){switch(s.once&&this.removeListener(t,s.fn,void 0,!0),w){case 1:return s.fn.call(s.context),!0;case 2:return s.fn.call(s.context,e),!0;case 3:return s.fn.call(s.context,e,r),!0;case 4:return s.fn.call(s.context,e,r,o),!0;case 5:return s.fn.call(s.context,e,r,o,l),!0;case 6:return s.fn.call(s.context,e,r,o,l,u),!0}for(h=1,m=new Array(w-1);h<w;h++)m[h-1]=arguments[h];s.fn.apply(s.context,m)}else{var b=s.length,y;for(h=0;h<b;h++)switch(s[h].once&&this.removeListener(t,s[h].fn,void 0,!0),w){case 1:s[h].fn.call(s[h].context);break;case 2:s[h].fn.call(s[h].context,e);break;case 3:s[h].fn.call(s[h].context,e,r);break;case 4:s[h].fn.call(s[h].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[h].fn.apply(s[h].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 l=_?_+t:t;if(!this._events[l])return this;if(!e)return S(this,l),this;var u=this._events[l];if(u.fn)u.fn===e&&(!o||u.once)&&(!r||u.context===r)&&S(this,l);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[l]=s.length===1?s[0]:s:S(this,l)}return this};f.prototype.removeAllListeners=function(t){var e;return t?(e=_?_+t:t,this._events[e]&&S(this,e)):(this._events=new O,this._eventsCount=0),this};f.prototype.off=f.prototype.removeListener;f.prototype.addListener=f.prototype.on;f.prefixed=_;f.EventEmitter=f;typeof P<"u"&&(P.exports=f)});var $t={};ft($t,{default:()=>I});module.exports=pt($t);var it=L(F()),rt=L(require("socket.io-client"));var N=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),list:(t={})=>i.get("/user",t),image:(t,e={})=>i.post(`/user/${t?.id||t}/image`,e),update:(t={})=>i.patch(`/user/${t.id}`,t),validate:(t,e,r)=>i.get("/user/value",{key:e,value:r,user:t?.id}),password:(t,e,r)=>i.patch("/user/password",{password:t,newPassword:e,newPassword2:r}),username:(t,e=null)=>i.post("/user/username",{username:t,id:e?.id||e}),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,e={})=>i.get(`/chirper/${t}`,e),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}),trip:(t,e={})=>i.get(`/chirper/${t?.id||t}/trip`,e),Trip:{list:(t={})=>i.get("/chirper/trip",t),get:(t,e={})=>i.get(`/chirper/trip/${t?.id||t}`,e)}});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 et=i=>({list:t=>i.get("/notification",t),count:t=>i.get("/notification/count",t),read:t=>i.post("/notification/count",t)});var vt=new it.default({length:10}),I=class{constructor({url:t,version:e,options:r={}}){this.key=null;this.url=null;this.cache={};this.events=new N.default;this.call=null;this.socket=null;this.account=null;this.version="v1";this.loading=!0;this.authing=null;this.authKey=null;this.shareKey=null;this.customer=null;this.presences={};this.connecting=null;this.extraOptions={};this.options={path:"/ws",cors:!0,agent:!0,reconnect:!0,transports:["websocket"],withCredentials:!0};t&&(this.url=t),e&&(this.version=e),r&&(this.extraOptions=r),this.build=this.build.bind(this),this.fetch=this.fetch.bind(this),this.wsFetch=this.wsFetch.bind(this),this.on=this.on.bind(this),this.off=this.off.bind(this),this.emit=this.emit.bind(this),this.once=this.once.bind(this),this.addListener=this.events.addListener.bind(this.events),this.removeListener=this.events.removeListener.bind(this.events),this.get=this.get.bind(this),this.put=this.put.bind(this),this.post=this.post.bind(this),this.patch=this.patch.bind(this),this.delete=this.delete.bind(this),this.AI=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.Notification=et(this),this.build()}build(){if(this.__resolveConnecting=null,this.connecting=new Promise(e=>{this.__resolveConnecting=e}),!this.url)return;let t=rt.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 l;try{l=await(await fetch(`${this.url}/${this.version}${e}${`${t}`.toLowerCase()==="get"?`?${new URLSearchParams(r)}`:""}`,{body:`${t}`.toLowerCase()!=="get"?JSON.stringify(r):void 0,headers:{"Content-Type":"application/json",Authentication:this.key?`Bearer ${this.key}`:void 0},credentials:"include"})).json()}catch(u){throw console.timeEnd(`[chirper] [fetch] ${t}:${e} ${JSON.stringify(r)}`),u}if(console.timeEnd(`[chirper] [fetch] ${t}:${e} ${JSON.stringify(r)}`),!l?.success)throw new Error(l.message);return o&&(this.cache[`${t}${e}${JSON.stringify(r)}`]=l,this.cache[`${t}${e}${JSON.stringify(r)}`].then(()=>{typeof o=="number"?setTimeout(()=>{delete this.cache[`${t}${e}${JSON.stringify(r)}`]},o):delete this.cache[`${t}${e}${JSON.stringify(r)}`]})),l.result}async wsFetch(t,e,r={},o=!1,l=!0){if(l&&await this.connecting,l&&await this.authing,["patch","put","delete","post"].includes(t.toLowerCase())&&(o=!1),o&&this.cache[`${t}${e}${JSON.stringify(r)}`])return this.cache[`${t}${e}${JSON.stringify(r)}`];delete this.cache[`${t}${e}${JSON.stringify(r)}`];let u=vt();console.time(`[chirper] [${u}] ${t}:${e} ${JSON.stringify(r)}`);let v=new Promise((s,w)=>{this.socket.once(u,({success:m,result:h,message:b})=>{if(console.timeEnd(`[chirper] [${u}] ${t}:${e} ${JSON.stringify(r)}`),m)return s(h);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)}};
1
+ var lt=Object.create;var C=Object.defineProperty;var ht=Object.getOwnPropertyDescriptor;var ct=Object.getOwnPropertyNames;var at=Object.getPrototypeOf,dt=Object.prototype.hasOwnProperty;var D=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),ft=(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 ct(t))!dt.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?lt(at(i)):{},A(t||!i||!i.__esModule?C(e,"default",{value:i,enumerable:!0}):e,i)),pt=i=>A(C({},"__esModule",{value:!0}),i);var F=D((wt,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,l=($,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,h={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 c=[...n];if(c[0]=`[short-unique-id] ${n[0]}`,this.debug===!0&&typeof console<"u"&&console!==null)return console.log(...c)},this.setDictionary=(n,c)=>{let a;if(n&&Array.isArray(n)&&n.length>1)a=n;else{a=[];let g;this.dictIndex=g=0;let x=`_${n}_dict_ranges`,k=this[x];Object.keys(k).forEach(ot=>{let ut=ot;for(this.dictRange=k[ut],this.lowerBound=this.dictRange[0],this.upperBound=this.dictRange[1],this.dictIndex=g=this.lowerBound;this.lowerBound<=this.upperBound?g<this.upperBound:g>this.upperBound;this.dictIndex=this.lowerBound<=this.upperBound?g+=1:g-=1)a.push(String.fromCharCode(this.dictIndex))})}c&&(a=a.sort(()=>Math.random()-.5)),this.dict=a,this.dictLength=this.dict.length,this.counter=0},this.seq=()=>this.sequentialUUID(),this.sequentialUUID=()=>{let n,c,a="";n=this.counter;do c=n%this.dictLength,n=Math.trunc(n/this.dictLength),a+=this.dict[c];while(n!==0);return this.counter+=1,a},this.randomUUID=(n=this.uuidLength||m)=>{let c,a,g;if(n===null||typeof n>"u"||n<1)throw new Error("Invalid UUID Length Provided");let x=n>=0;for(c="",g=0;g<n;g+=1)a=parseInt((Math.random()*this.dictLength).toFixed(0),10)%this.dictLength,c+=this.dict[a];return c},this.availableUUIDs=(n=this.uuidLength)=>parseFloat(Math.pow([...new Set(this.dict)].length,n).toFixed(0)),this.approxMaxBeforeCollision=(n=this.availableUUIDs(this.uuidLength))=>parseFloat(Math.sqrt(Math.PI/2*n).toFixed(20)),this.collisionProbability=(n=this.availableUUIDs(this.uuidLength),c=this.uuidLength)=>parseFloat((this.approxMaxBeforeCollision(n)/this.availableUUIDs(c)).toFixed(20)),this.uniqueness=(n=this.availableUUIDs(this.uuidLength))=>{let c=parseFloat((1-this.approxMaxBeforeCollision(n)/n).toFixed(20));return c>1?1:c<0?0:c},this.getVersion=()=>this.version,this.stamp=n=>{if(typeof n!="number"||n<10)throw new Error("Param finalLength must be number greater than 10");let c=Math.floor(+new Date/1e3).toString(16),a=n-9,g=Math.round(Math.random()*(a>15?15:a)),x=this.randomUUID(a);return`${x.substr(0,g)}${c}${x.substr(g)}${g.toString(16)}`},this.parseStamp=n=>{if(n.length<10)throw new Error("Stamp length invalid");let c=parseInt(n.substr(n.length-1,1),16);return new Date(parseInt(n.substr(c,8),16)*1e3)};let d=l(l({},h),$);this.counter=0,this.debug=!1,this.dict=[],this.version=w;let{dictionary:p,shuffle:st,length:nt}=d;return this.uuidLength=nt,this.setDictionary(p,st),this.debug=d.debug,this.log(this.dict),this.log(`Generator instantiated with Dictionary Size ${this.dictLength}`),new Proxy(this,{apply:(n,c,a)=>this.randomUUID(...a)})}},y=b;return y.default=b,s})();typeof E<"u"&&(E.exports=U.default),typeof window<"u"&&(U=U.default)});var J=D((bt,P)=>{"use strict";var gt=Object.prototype.hasOwnProperty,_="~";function O(){}Object.create&&(O.prototype=Object.create(null),new O().__proto__||(_=!1));function _t(i,t,e){this.fn=i,this.context=t,this.once=e||!1}function T(i,t,e,r,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var l=new _t(e,r||i,o),u=_?_+t:t;return i._events[u]?i._events[u].fn?i._events[u]=[i._events[u],l]:i._events[u].push(l):(i._events[u]=l,i._eventsCount++),i}function 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)gt.call(e,r)&&t.push(_?r.slice(1):r);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};f.prototype.listeners=function(t){var e=_?_+t:t,r=this._events[e];if(!r)return[];if(r.fn)return[r.fn];for(var o=0,l=r.length,u=new Array(l);o<l;o++)u[o]=r[o].fn;return u};f.prototype.listenerCount=function(t){var e=_?_+t:t,r=this._events[e];return r?r.fn?1:r.length:0};f.prototype.emit=function(t,e,r,o,l,u){var v=_?_+t:t;if(!this._events[v])return!1;var s=this._events[v],w=arguments.length,m,h;if(s.fn){switch(s.once&&this.removeListener(t,s.fn,void 0,!0),w){case 1:return s.fn.call(s.context),!0;case 2:return s.fn.call(s.context,e),!0;case 3:return s.fn.call(s.context,e,r),!0;case 4:return s.fn.call(s.context,e,r,o),!0;case 5:return s.fn.call(s.context,e,r,o,l),!0;case 6:return s.fn.call(s.context,e,r,o,l,u),!0}for(h=1,m=new Array(w-1);h<w;h++)m[h-1]=arguments[h];s.fn.apply(s.context,m)}else{var b=s.length,y;for(h=0;h<b;h++)switch(s[h].once&&this.removeListener(t,s[h].fn,void 0,!0),w){case 1:s[h].fn.call(s[h].context);break;case 2:s[h].fn.call(s[h].context,e);break;case 3:s[h].fn.call(s[h].context,e,r);break;case 4:s[h].fn.call(s[h].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[h].fn.apply(s[h].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 l=_?_+t:t;if(!this._events[l])return this;if(!e)return S(this,l),this;var u=this._events[l];if(u.fn)u.fn===e&&(!o||u.once)&&(!r||u.context===r)&&S(this,l);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[l]=s.length===1?s[0]:s:S(this,l)}return this};f.prototype.removeAllListeners=function(t){var e;return t?(e=_?_+t:t,this._events[e]&&S(this,e)):(this._events=new O,this._eventsCount=0),this};f.prototype.off=f.prototype.removeListener;f.prototype.addListener=f.prototype.on;f.prefixed=_;f.EventEmitter=f;typeof P<"u"&&(P.exports=f)});var $t={};ft($t,{default:()=>I});module.exports=pt($t);var it=L(F()),rt=L(require("socket.io-client"));var N=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),list:(t={})=>i.get("/user",t),image:(t,e={})=>i.post(`/user/${t?.id||t}/image`,e),update:(t={})=>i.patch(`/user/${t.id}`,t),validate:(t,e,r)=>i.get("/user/value",{key:e,value:r,user:t?.id}),password:(t,e,r)=>i.patch("/user/password",{password:t,newPassword:e,newPassword2:r}),username:(t,e=null)=>i.post("/user/username",{username:t,id:e?.id||e}),suggestion:(t={})=>i.get("/user/suggestion",t),Pin:{list:(t={})=>i.get("/user/pin",t),create:(t={})=>i.post("/user/pin",t),update:(t={})=>i.patch("/user/pin",t),delete:(t={})=>i.delete("/user/pin",t)}});var j=i=>({get:(t,e)=>i.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={})=>i.post("/chirp",t),subscribe:t=>i.post(`/chirp/${t?.id||t}/subscribe`),unsubscribe:t=>i.delete(`/chirp/${t?.id||t}/subscribe`)});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,e={})=>i.get(`/chirper/${t}`,e),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}),trip:(t,e={})=>i.get(`/chirper/${t?.id||t}/trip`,e),Trip:{list:(t={})=>i.get("/chirper/trip",t),get:(t,e={})=>i.get(`/chirper/trip/${t?.id||t}`,e)}});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 et=i=>({list:t=>i.get("/notification",t),count:t=>i.get("/notification/count",t),read:t=>i.post("/notification/count",t)});var vt=new it.default({length:10}),I=class{constructor({url:t,version:e,options:r={}}){this.key=null;this.url=null;this.cache={};this.events=new N.default;this.call=null;this.socket=null;this.account=null;this.version="v1";this.loading=!0;this.authing=null;this.authKey=null;this.shareKey=null;this.customer=null;this.presences={};this.connecting=null;this.extraOptions={};this.options={path:"/ws",cors:!0,agent:!0,reconnect:!0,transports:["websocket"],withCredentials:!0};t&&(this.url=t),e&&(this.version=e),r&&(this.extraOptions=r),this.build=this.build.bind(this),this.fetch=this.fetch.bind(this),this.wsFetch=this.wsFetch.bind(this),this.on=this.on.bind(this),this.off=this.off.bind(this),this.emit=this.emit.bind(this),this.once=this.once.bind(this),this.addListener=this.events.addListener.bind(this.events),this.removeListener=this.events.removeListener.bind(this.events),this.get=this.get.bind(this),this.put=this.put.bind(this),this.post=this.post.bind(this),this.patch=this.patch.bind(this),this.delete=this.delete.bind(this),this.AI=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.Notification=et(this),this.build()}build(){if(this.__resolveConnecting=null,this.connecting=new Promise(e=>{this.__resolveConnecting=e}),!this.url)return;let t=rt.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 l;try{l=await(await fetch(`${this.url}/${this.version}${e}${`${t}`.toLowerCase()==="get"?`?${new URLSearchParams(r)}`:""}`,{body:`${t}`.toLowerCase()!=="get"?JSON.stringify(r):void 0,headers:{"Content-Type":"application/json",Authentication:this.key?`Bearer ${this.key}`:void 0},credentials:"include"})).json()}catch(u){throw console.timeEnd(`[chirper] [fetch] ${t}:${e} ${JSON.stringify(r)}`),u}if(console.timeEnd(`[chirper] [fetch] ${t}:${e} ${JSON.stringify(r)}`),!l?.success)throw new Error(l.message);return o&&(this.cache[`${t}${e}${JSON.stringify(r)}`]=l,this.cache[`${t}${e}${JSON.stringify(r)}`].then(()=>{typeof o=="number"?setTimeout(()=>{delete this.cache[`${t}${e}${JSON.stringify(r)}`]},o):delete this.cache[`${t}${e}${JSON.stringify(r)}`]})),l.result}async wsFetch(t,e,r={},o=!1,l=!0){if(l&&await this.connecting,l&&await this.authing,["patch","put","delete","post"].includes(t.toLowerCase())&&(o=!1),o&&this.cache[`${t}${e}${JSON.stringify(r)}`])return this.cache[`${t}${e}${JSON.stringify(r)}`];delete this.cache[`${t}${e}${JSON.stringify(r)}`];let u=vt();console.time(`[chirper] [${u}] ${t}:${e} ${JSON.stringify(r)}`);let v=new Promise((s,w)=>{this.socket.once(u,({success:m,result:h,message:b})=>{if(console.timeEnd(`[chirper] [${u}] ${t}:${e} ${JSON.stringify(r)}`),m)return s(h);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.70",
3
+ "version": "0.0.72",
4
4
  "description": "",
5
5
  "main": "dist/bundle.js",
6
6
  "scripts": {
package/src/api/Chirp.ts CHANGED
@@ -33,13 +33,16 @@ export default (api) => ({
33
33
  // return patch
34
34
  return api.delete(`/chirp/${chirp?.id || chirp}`);
35
35
  },
36
- create : (chirper, thought, chirp, type) => {
36
+ create : (opts = {}) => {
37
37
  // return respond
38
- return api.post(`/chirp`, {
39
- type,
40
- thought,
41
- chirp : chirp?.id || chirp,
42
- chirper : chirper?.id || chirper,
43
- });
38
+ return api.post(`/chirp`, opts);
39
+ },
40
+ subscribe : (thread) => {
41
+ // return done
42
+ return api.post(`/chirp/${thread?.id || thread}/subscribe`);
43
+ },
44
+ unsubscribe : (thread) => {
45
+ // return done
46
+ return api.delete(`/chirp/${thread?.id || thread}/subscribe`);
44
47
  },
45
48
  });
package/src/api/User.ts CHANGED
@@ -42,6 +42,10 @@ export default (api) => ({
42
42
  id : user?.id || user,
43
43
  });
44
44
  },
45
+ suggestion : (opts = {}) => {
46
+ // return promise
47
+ return api.get(`/user/suggestion`, opts);
48
+ },
45
49
 
46
50
  // user pins
47
51
  Pin : {