🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

mona-js-sdk

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mona-js-sdk - npm Package Compare versions

Comparing version

to
1.0.6

2

dist/index.cjs.js

@@ -1,2 +0,2 @@

"use strict";var b=Object.defineProperty;var m=(a,e,r)=>e in a?b(a,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[e]=r;var s=(a,e,r)=>(m(a,typeof e!="symbol"?e+"":e,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class d{constructor(e){s(this,"key");s(this,"nodeJsMap",null);s(this,"isBrowser",()=>typeof window<"u");s(this,"get",()=>{if(!this.isBrowser())return this.nodeJsMap.get(this.key);const e=localStorage.getItem(this.key);if(!e)return null;try{return JSON.parse(e)}catch{}return e});s(this,"set",e=>{if(!this.isBrowser()){this.nodeJsMap.set(this.key,e);return}localStorage.setItem(this.key,typeof e=="string"?e:JSON.stringify(e))});s(this,"remove",()=>{if(!this.isBrowser()){this.nodeJsMap.delete(this.key);return}localStorage.removeItem(this.key)});this.key=e,typeof window<"u"&&(this.nodeJsMap=new Map)}}class y{constructor(e,r){s(this,"uuid",Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15)+Date.now().toString(36));this.observable=e,this.callback=r}remove(){this.observable.removeObserver(this)}notify(e){this.callback(e)}}class u{constructor(){s(this,"observers",[])}add(e){const r=new y(this,e);return this.observers.push(r),r}notifyObservers(e){for(const r of this.observers)r.notify(e)}removeObserver(e){this.observers=this.observers.filter(r=>r!==e)}}const t=class t{constructor({apiKey:e,autoLogin:r}){s(this,"onRefreshToken",new u);s(this,"automaticallyLogin",async({refreshToken:e})=>{var r,o;if(e&&!t.refreshToken){t.refreshToken=e,await this.OTP_Refresh();const n=await this.getUser();"username"in n&&(r=t.autoLoginParams)!=null&&r.callbackOnLogin&&((o=t.autoLoginParams)==null||o.callbackOnLogin(n))}});s(this,"OTP_Generate",async e=>await this._fetch("https://api.monaverse.com/public/auth/otp/generate",{method:"POST",body:JSON.stringify({email:e})}));s(this,"OTP_Verify",async(e,r)=>{const o=await this._fetch("https://api.monaverse.com/public/auth/otp/verify",{method:"POST",body:JSON.stringify({email:e,otp:r})});return"access"in o?(t.bearer=o.access,t.refreshToken=o.refresh,t.localStorage.set(o.refresh),this.onRefreshToken.notifyObservers({refreshToken:o.refresh}),{success:!0}):(console.error(o),{success:!1})});s(this,"OTP_Refresh",async()=>{const e=await this._fetch("https://api.monaverse.com/public/auth/token/refresh",{method:"POST",body:JSON.stringify({refresh:t.refreshToken})});return"access"in e?(t.bearer=e.access,t.refreshToken=e.refresh,t.localStorage.set(e.refresh),this.onRefreshToken.notifyObservers({refreshToken:e.refresh}),{success:!0}):(console.error(e),{success:!1})});s(this,"getUser",async()=>{const e=await this._fetch("https://api.monaverse.com/public/user/",{method:"GET"});return"error"in e?{error:"Could not get user"}:e});s(this,"getTokens",async({chain_id:e,address:r,queryKey:o})=>{let n=`https://api.monaverse.com/public/user/${e}/${r}/tokens?includeLastSale=false&includeAttributes=true`;o&&(n+=`&continuation=${o}`);const i=await this._fetch(n,{method:"GET"});if("error"in i)return console.error(i),{tokens:[]};{const l=[];for(const c of i.tokens){const f=await this.getAnimation(c);f&&(c.animation=f,l.push(c))}return{tokens:l,continuation:i.continuation}}});s(this,"getAnimation",async e=>{const r=await this._fetch(`https://api.monaverse.com/public/tokens/${e.chainId}/${e.contract}/${e.tokenId}/animation`,{method:"GET"});return"error"in r?(console.error(r),null):r});s(this,"logout",()=>{t.bearer="",t.refreshToken="",t.localStorage.remove()});s(this,"_fetch",async(e,r)=>{const o={...r,headers:{...r.headers,"Content-Type":"application/json","X-Mona-Application-Id":t.key,...t.bearer?{Authorization:`Bearer ${t.bearer}`}:{}}};try{const n=await fetch(e,o);return n.status===400?{error:await n.text()}:n.status===401?{error:await n.json()}:await n.json()}catch(n){return console.error(n),{error:"Network Error"}}});if(!e)throw new Error("MONA API Key is required");t.key=e,t.autoLoginParams=r||t.autoLoginParams,t.localStorage=new d((r==null?void 0:r.localStorageKey)||"x-mona-auth"),this.onRefreshToken.add(this.automaticallyLogin)}};s(t,"key",""),s(t,"bearer",""),s(t,"refreshToken",""),s(t,"localStorage"),s(t,"autoLoginParams",{enabled:!1});let h=t;exports.MonaAPI=h;exports.Observable=u;
"use strict";var b=Object.defineProperty;var m=(a,e,r)=>e in a?b(a,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[e]=r;var s=(a,e,r)=>(m(a,typeof e!="symbol"?e+"":e,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class y{constructor(e){s(this,"key");s(this,"nodeJsMap",null);s(this,"isBrowser",()=>typeof window<"u");s(this,"get",()=>{if(!this.isBrowser())return this.nodeJsMap.get(this.key);const e=localStorage.getItem(this.key);if(!e)return null;try{return JSON.parse(e)}catch{}return e});s(this,"set",e=>{if(!this.isBrowser()){this.nodeJsMap.set(this.key,e);return}localStorage.setItem(this.key,typeof e=="string"?e:JSON.stringify(e))});s(this,"remove",()=>{if(!this.isBrowser()){this.nodeJsMap.delete(this.key);return}localStorage.removeItem(this.key)});this.key=e,typeof window<"u"&&(this.nodeJsMap=new Map)}}class d{constructor(e,r){s(this,"uuid",Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15)+Date.now().toString(36));this.observable=e,this.callback=r}remove(){this.observable.removeObserver(this)}notify(e){this.callback(e)}}class u{constructor(){s(this,"observers",[])}add(e){const r=new d(this,e);return this.observers.push(r),r}notifyObservers(e){for(const r of this.observers)r.notify(e)}removeObserver(e){this.observers=this.observers.filter(r=>r!==e)}}const t=class t{constructor({apiKey:e,autoLogin:r}){s(this,"onRefreshToken",new u);s(this,"automaticallyLogin",async({refreshToken:e})=>{var r,o;if(e&&!t.refreshToken){t.refreshToken=e,await this.OTP_Refresh();const n=await this.getUser();"username"in n&&(r=t.autoLoginParams)!=null&&r.callbackOnLogin&&((o=t.autoLoginParams)==null||o.callbackOnLogin(n))}});s(this,"OTP_Generate",async e=>await this._fetch("https://api.monaverse.com/public/auth/otp/generate",{method:"POST",body:JSON.stringify({email:e})}));s(this,"OTP_Verify",async(e,r)=>{const o=await this._fetch("https://api.monaverse.com/public/auth/otp/verify",{method:"POST",body:JSON.stringify({email:e,otp:r})});return"access"in o?(t.bearer=o.access,t.refreshToken=o.refresh,t.localStorage.set(o.refresh),this.onRefreshToken.notifyObservers({refreshToken:o.refresh}),{success:!0}):(console.error(o),{success:!1})});s(this,"OTP_Refresh",async()=>{const e=await this._fetch("https://api.monaverse.com/public/auth/token/refresh",{method:"POST",body:JSON.stringify({refresh:t.refreshToken})});return"access"in e?(t.bearer=e.access,t.refreshToken=e.refresh,t.localStorage.set(e.refresh),this.onRefreshToken.notifyObservers({refreshToken:e.refresh}),{success:!0}):(console.error(e),{success:!1})});s(this,"getUser",async()=>{const e=await this._fetch("https://api.monaverse.com/public/user/",{method:"GET"});return"error"in e?{error:"Could not get user"}:e});s(this,"getTokens",async({chain_id:e,address:r,queryKey:o})=>{let n=`https://api.monaverse.com/public/user/${e}/${r}/tokens?includeLastSale=false&includeAttributes=true`;o&&(n+=`&continuation=${o}`);const i=await this._fetch(n,{method:"GET"});if("error"in i)return console.error(i),{tokens:[]};{const l=[];for(const c of i.tokens){const f=await this.getAnimation(c);f&&(c.animation=f,l.push(c))}return{tokens:l,continuation:i.continuation}}});s(this,"getAnimation",async e=>{const r=await this._fetch(`https://api.monaverse.com/public/tokens/${e.chainId}/${e.contract}/${e.tokenId}/animation`,{method:"GET"});return"error"in r?(console.error(r),null):r});s(this,"logout",()=>{t.bearer="",t.refreshToken="",t.localStorage.remove()});s(this,"_fetch",async(e,r)=>{const o={...r,headers:{...r.headers,"Content-Type":"application/json","X-Mona-Application-Id":t.key,...t.bearer?{Authorization:`Bearer ${t.bearer}`}:{}}};try{const n=await fetch(e,o);return n.status===400?{error:await n.text()}:n.status===401?{error:await n.json()}:await n.json()}catch(n){return console.error(n),{error:"Network Error"}}});if(!e)throw new Error("MONA API Key is required");t.key=e,t.autoLoginParams=r||t.autoLoginParams,t.localStorage=new y((r==null?void 0:r.localStorageKey)||"x-mona-auth"),this.onRefreshToken.add(this.automaticallyLogin);const o=t.localStorage.get();o&&this.onRefreshToken.notifyObservers({refreshToken:o})}};s(t,"key",""),s(t,"bearer",""),s(t,"refreshToken",""),s(t,"localStorage"),s(t,"autoLoginParams",{enabled:!1});let h=t;exports.MonaAPI=h;exports.Observable=u;
//# sourceMappingURL=index.cjs.js.map
var u = Object.defineProperty;
var m = (a, e, r) => e in a ? u(a, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : a[e] = r;
var s = (a, e, r) => (m(a, typeof e != "symbol" ? e + "" : e, r), r);
var m = (i, e, r) => e in i ? u(i, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : i[e] = r;
var s = (i, e, r) => (m(i, typeof e != "symbol" ? e + "" : e, r), r);
class b {

@@ -50,3 +50,3 @@ constructor(e) {

}
class d {
class y {
constructor(e, r) {

@@ -65,3 +65,3 @@ s(this, "uuid", Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15) + Date.now().toString(36));

}
class y {
class d {
constructor() {

@@ -72,3 +72,3 @@ s(this, "observers", []);

add(e) {
const r = new d(this, e);
const r = new y(this, e);
return this.observers.push(r), r;

@@ -91,3 +91,3 @@ }

}) {
s(this, "onRefreshToken", new y());
s(this, "onRefreshToken", new d());
s(this, "automaticallyLogin", async ({ refreshToken: e }) => {

@@ -128,14 +128,14 @@ var r, o;

o && (n += `&continuation=${o}`);
const i = await this._fetch(n, {
const a = await this._fetch(n, {
method: "GET"
});
if ("error" in i)
return console.error(i), { tokens: [] };
if ("error" in a)
return console.error(a), { tokens: [] };
{
const h = [];
for (const c of i.tokens) {
const l = await this.getAnimation(c);
l && (c.animation = l, h.push(c));
for (const c of a.tokens) {
const f = await this.getAnimation(c);
f && (c.animation = f, h.push(c));
}
return { tokens: h, continuation: i.continuation };
return { tokens: h, continuation: a.continuation };
}

@@ -172,2 +172,4 @@ });

t.key = e, t.autoLoginParams = r || t.autoLoginParams, t.localStorage = new b((r == null ? void 0 : r.localStorageKey) || "x-mona-auth"), this.onRefreshToken.add(this.automaticallyLogin);
const o = t.localStorage.get();
o && this.onRefreshToken.notifyObservers({ refreshToken: o });
}

@@ -178,7 +180,7 @@ };

});
let f = t;
let l = t;
export {
f as MonaAPI,
y as Observable
l as MonaAPI,
d as Observable
};
//# sourceMappingURL=index.es.js.map

@@ -1,2 +0,2 @@

var monaJsSdk=function(a){"use strict";var y=Object.defineProperty;var g=(a,i,c)=>i in a?y(a,i,{enumerable:!0,configurable:!0,writable:!0,value:c}):a[i]=c;var s=(a,i,c)=>(g(a,typeof i!="symbol"?i+"":i,c),c);class i{constructor(e){s(this,"key");s(this,"nodeJsMap",null);s(this,"isBrowser",()=>typeof window<"u");s(this,"get",()=>{if(!this.isBrowser())return this.nodeJsMap.get(this.key);const e=localStorage.getItem(this.key);if(!e)return null;try{return JSON.parse(e)}catch{}return e});s(this,"set",e=>{if(!this.isBrowser()){this.nodeJsMap.set(this.key,e);return}localStorage.setItem(this.key,typeof e=="string"?e:JSON.stringify(e))});s(this,"remove",()=>{if(!this.isBrowser()){this.nodeJsMap.delete(this.key);return}localStorage.removeItem(this.key)});this.key=e,typeof window<"u"&&(this.nodeJsMap=new Map)}}class c{constructor(e,t){s(this,"uuid",Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15)+Date.now().toString(36));this.observable=e,this.callback=t}remove(){this.observable.removeObserver(this)}notify(e){this.callback(e)}}class u{constructor(){s(this,"observers",[])}add(e){const t=new c(this,e);return this.observers.push(t),t}notifyObservers(e){for(const t of this.observers)t.notify(e)}removeObserver(e){this.observers=this.observers.filter(t=>t!==e)}}const r=class r{constructor({apiKey:e,autoLogin:t}){s(this,"onRefreshToken",new u);s(this,"automaticallyLogin",async({refreshToken:e})=>{var t,o;if(e&&!r.refreshToken){r.refreshToken=e,await this.OTP_Refresh();const n=await this.getUser();"username"in n&&(t=r.autoLoginParams)!=null&&t.callbackOnLogin&&((o=r.autoLoginParams)==null||o.callbackOnLogin(n))}});s(this,"OTP_Generate",async e=>await this._fetch("https://api.monaverse.com/public/auth/otp/generate",{method:"POST",body:JSON.stringify({email:e})}));s(this,"OTP_Verify",async(e,t)=>{const o=await this._fetch("https://api.monaverse.com/public/auth/otp/verify",{method:"POST",body:JSON.stringify({email:e,otp:t})});return"access"in o?(r.bearer=o.access,r.refreshToken=o.refresh,r.localStorage.set(o.refresh),this.onRefreshToken.notifyObservers({refreshToken:o.refresh}),{success:!0}):(console.error(o),{success:!1})});s(this,"OTP_Refresh",async()=>{const e=await this._fetch("https://api.monaverse.com/public/auth/token/refresh",{method:"POST",body:JSON.stringify({refresh:r.refreshToken})});return"access"in e?(r.bearer=e.access,r.refreshToken=e.refresh,r.localStorage.set(e.refresh),this.onRefreshToken.notifyObservers({refreshToken:e.refresh}),{success:!0}):(console.error(e),{success:!1})});s(this,"getUser",async()=>{const e=await this._fetch("https://api.monaverse.com/public/user/",{method:"GET"});return"error"in e?{error:"Could not get user"}:e});s(this,"getTokens",async({chain_id:e,address:t,queryKey:o})=>{let n=`https://api.monaverse.com/public/user/${e}/${t}/tokens?includeLastSale=false&includeAttributes=true`;o&&(n+=`&continuation=${o}`);const h=await this._fetch(n,{method:"GET"});if("error"in h)return console.error(h),{tokens:[]};{const b=[];for(const f of h.tokens){const d=await this.getAnimation(f);d&&(f.animation=d,b.push(f))}return{tokens:b,continuation:h.continuation}}});s(this,"getAnimation",async e=>{const t=await this._fetch(`https://api.monaverse.com/public/tokens/${e.chainId}/${e.contract}/${e.tokenId}/animation`,{method:"GET"});return"error"in t?(console.error(t),null):t});s(this,"logout",()=>{r.bearer="",r.refreshToken="",r.localStorage.remove()});s(this,"_fetch",async(e,t)=>{const o={...t,headers:{...t.headers,"Content-Type":"application/json","X-Mona-Application-Id":r.key,...r.bearer?{Authorization:`Bearer ${r.bearer}`}:{}}};try{const n=await fetch(e,o);return n.status===400?{error:await n.text()}:n.status===401?{error:await n.json()}:await n.json()}catch(n){return console.error(n),{error:"Network Error"}}});if(!e)throw new Error("MONA API Key is required");r.key=e,r.autoLoginParams=t||r.autoLoginParams,r.localStorage=new i((t==null?void 0:t.localStorageKey)||"x-mona-auth"),this.onRefreshToken.add(this.automaticallyLogin)}};s(r,"key",""),s(r,"bearer",""),s(r,"refreshToken",""),s(r,"localStorage"),s(r,"autoLoginParams",{enabled:!1});let l=r;return a.MonaAPI=l,a.Observable=u,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"}),a}({});
var monaJsSdk=function(a){"use strict";var y=Object.defineProperty;var g=(a,i,c)=>i in a?y(a,i,{enumerable:!0,configurable:!0,writable:!0,value:c}):a[i]=c;var s=(a,i,c)=>(g(a,typeof i!="symbol"?i+"":i,c),c);class i{constructor(e){s(this,"key");s(this,"nodeJsMap",null);s(this,"isBrowser",()=>typeof window<"u");s(this,"get",()=>{if(!this.isBrowser())return this.nodeJsMap.get(this.key);const e=localStorage.getItem(this.key);if(!e)return null;try{return JSON.parse(e)}catch{}return e});s(this,"set",e=>{if(!this.isBrowser()){this.nodeJsMap.set(this.key,e);return}localStorage.setItem(this.key,typeof e=="string"?e:JSON.stringify(e))});s(this,"remove",()=>{if(!this.isBrowser()){this.nodeJsMap.delete(this.key);return}localStorage.removeItem(this.key)});this.key=e,typeof window<"u"&&(this.nodeJsMap=new Map)}}class c{constructor(e,t){s(this,"uuid",Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15)+Date.now().toString(36));this.observable=e,this.callback=t}remove(){this.observable.removeObserver(this)}notify(e){this.callback(e)}}class u{constructor(){s(this,"observers",[])}add(e){const t=new c(this,e);return this.observers.push(t),t}notifyObservers(e){for(const t of this.observers)t.notify(e)}removeObserver(e){this.observers=this.observers.filter(t=>t!==e)}}const r=class r{constructor({apiKey:e,autoLogin:t}){s(this,"onRefreshToken",new u);s(this,"automaticallyLogin",async({refreshToken:e})=>{var t,o;if(e&&!r.refreshToken){r.refreshToken=e,await this.OTP_Refresh();const n=await this.getUser();"username"in n&&(t=r.autoLoginParams)!=null&&t.callbackOnLogin&&((o=r.autoLoginParams)==null||o.callbackOnLogin(n))}});s(this,"OTP_Generate",async e=>await this._fetch("https://api.monaverse.com/public/auth/otp/generate",{method:"POST",body:JSON.stringify({email:e})}));s(this,"OTP_Verify",async(e,t)=>{const o=await this._fetch("https://api.monaverse.com/public/auth/otp/verify",{method:"POST",body:JSON.stringify({email:e,otp:t})});return"access"in o?(r.bearer=o.access,r.refreshToken=o.refresh,r.localStorage.set(o.refresh),this.onRefreshToken.notifyObservers({refreshToken:o.refresh}),{success:!0}):(console.error(o),{success:!1})});s(this,"OTP_Refresh",async()=>{const e=await this._fetch("https://api.monaverse.com/public/auth/token/refresh",{method:"POST",body:JSON.stringify({refresh:r.refreshToken})});return"access"in e?(r.bearer=e.access,r.refreshToken=e.refresh,r.localStorage.set(e.refresh),this.onRefreshToken.notifyObservers({refreshToken:e.refresh}),{success:!0}):(console.error(e),{success:!1})});s(this,"getUser",async()=>{const e=await this._fetch("https://api.monaverse.com/public/user/",{method:"GET"});return"error"in e?{error:"Could not get user"}:e});s(this,"getTokens",async({chain_id:e,address:t,queryKey:o})=>{let n=`https://api.monaverse.com/public/user/${e}/${t}/tokens?includeLastSale=false&includeAttributes=true`;o&&(n+=`&continuation=${o}`);const h=await this._fetch(n,{method:"GET"});if("error"in h)return console.error(h),{tokens:[]};{const m=[];for(const f of h.tokens){const d=await this.getAnimation(f);d&&(f.animation=d,m.push(f))}return{tokens:m,continuation:h.continuation}}});s(this,"getAnimation",async e=>{const t=await this._fetch(`https://api.monaverse.com/public/tokens/${e.chainId}/${e.contract}/${e.tokenId}/animation`,{method:"GET"});return"error"in t?(console.error(t),null):t});s(this,"logout",()=>{r.bearer="",r.refreshToken="",r.localStorage.remove()});s(this,"_fetch",async(e,t)=>{const o={...t,headers:{...t.headers,"Content-Type":"application/json","X-Mona-Application-Id":r.key,...r.bearer?{Authorization:`Bearer ${r.bearer}`}:{}}};try{const n=await fetch(e,o);return n.status===400?{error:await n.text()}:n.status===401?{error:await n.json()}:await n.json()}catch(n){return console.error(n),{error:"Network Error"}}});if(!e)throw new Error("MONA API Key is required");r.key=e,r.autoLoginParams=t||r.autoLoginParams,r.localStorage=new i((t==null?void 0:t.localStorageKey)||"x-mona-auth"),this.onRefreshToken.add(this.automaticallyLogin);const o=r.localStorage.get();o&&this.onRefreshToken.notifyObservers({refreshToken:o})}};s(r,"key",""),s(r,"bearer",""),s(r,"refreshToken",""),s(r,"localStorage"),s(r,"autoLoginParams",{enabled:!1});let l=r;return a.MonaAPI=l,a.Observable=u,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"}),a}({});
//# sourceMappingURL=index.iife.js.map

@@ -1,2 +0,2 @@

(function(n,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(n=typeof globalThis<"u"?globalThis:n||self,i(n.monaJsSdk={}))})(this,function(n){"use strict";var y=Object.defineProperty;var p=(n,i,c)=>i in n?y(n,i,{enumerable:!0,configurable:!0,writable:!0,value:c}):n[i]=c;var s=(n,i,c)=>(p(n,typeof i!="symbol"?i+"":i,c),c);class i{constructor(e){s(this,"key");s(this,"nodeJsMap",null);s(this,"isBrowser",()=>typeof window<"u");s(this,"get",()=>{if(!this.isBrowser())return this.nodeJsMap.get(this.key);const e=localStorage.getItem(this.key);if(!e)return null;try{return JSON.parse(e)}catch{}return e});s(this,"set",e=>{if(!this.isBrowser()){this.nodeJsMap.set(this.key,e);return}localStorage.setItem(this.key,typeof e=="string"?e:JSON.stringify(e))});s(this,"remove",()=>{if(!this.isBrowser()){this.nodeJsMap.delete(this.key);return}localStorage.removeItem(this.key)});this.key=e,typeof window<"u"&&(this.nodeJsMap=new Map)}}class c{constructor(e,t){s(this,"uuid",Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15)+Date.now().toString(36));this.observable=e,this.callback=t}remove(){this.observable.removeObserver(this)}notify(e){this.callback(e)}}class u{constructor(){s(this,"observers",[])}add(e){const t=new c(this,e);return this.observers.push(t),t}notifyObservers(e){for(const t of this.observers)t.notify(e)}removeObserver(e){this.observers=this.observers.filter(t=>t!==e)}}const r=class r{constructor({apiKey:e,autoLogin:t}){s(this,"onRefreshToken",new u);s(this,"automaticallyLogin",async({refreshToken:e})=>{var t,o;if(e&&!r.refreshToken){r.refreshToken=e,await this.OTP_Refresh();const a=await this.getUser();"username"in a&&(t=r.autoLoginParams)!=null&&t.callbackOnLogin&&((o=r.autoLoginParams)==null||o.callbackOnLogin(a))}});s(this,"OTP_Generate",async e=>await this._fetch("https://api.monaverse.com/public/auth/otp/generate",{method:"POST",body:JSON.stringify({email:e})}));s(this,"OTP_Verify",async(e,t)=>{const o=await this._fetch("https://api.monaverse.com/public/auth/otp/verify",{method:"POST",body:JSON.stringify({email:e,otp:t})});return"access"in o?(r.bearer=o.access,r.refreshToken=o.refresh,r.localStorage.set(o.refresh),this.onRefreshToken.notifyObservers({refreshToken:o.refresh}),{success:!0}):(console.error(o),{success:!1})});s(this,"OTP_Refresh",async()=>{const e=await this._fetch("https://api.monaverse.com/public/auth/token/refresh",{method:"POST",body:JSON.stringify({refresh:r.refreshToken})});return"access"in e?(r.bearer=e.access,r.refreshToken=e.refresh,r.localStorage.set(e.refresh),this.onRefreshToken.notifyObservers({refreshToken:e.refresh}),{success:!0}):(console.error(e),{success:!1})});s(this,"getUser",async()=>{const e=await this._fetch("https://api.monaverse.com/public/user/",{method:"GET"});return"error"in e?{error:"Could not get user"}:e});s(this,"getTokens",async({chain_id:e,address:t,queryKey:o})=>{let a=`https://api.monaverse.com/public/user/${e}/${t}/tokens?includeLastSale=false&includeAttributes=true`;o&&(a+=`&continuation=${o}`);const h=await this._fetch(a,{method:"GET"});if("error"in h)return console.error(h),{tokens:[]};{const m=[];for(const l of h.tokens){const b=await this.getAnimation(l);b&&(l.animation=b,m.push(l))}return{tokens:m,continuation:h.continuation}}});s(this,"getAnimation",async e=>{const t=await this._fetch(`https://api.monaverse.com/public/tokens/${e.chainId}/${e.contract}/${e.tokenId}/animation`,{method:"GET"});return"error"in t?(console.error(t),null):t});s(this,"logout",()=>{r.bearer="",r.refreshToken="",r.localStorage.remove()});s(this,"_fetch",async(e,t)=>{const o={...t,headers:{...t.headers,"Content-Type":"application/json","X-Mona-Application-Id":r.key,...r.bearer?{Authorization:`Bearer ${r.bearer}`}:{}}};try{const a=await fetch(e,o);return a.status===400?{error:await a.text()}:a.status===401?{error:await a.json()}:await a.json()}catch(a){return console.error(a),{error:"Network Error"}}});if(!e)throw new Error("MONA API Key is required");r.key=e,r.autoLoginParams=t||r.autoLoginParams,r.localStorage=new i((t==null?void 0:t.localStorageKey)||"x-mona-auth"),this.onRefreshToken.add(this.automaticallyLogin)}};s(r,"key",""),s(r,"bearer",""),s(r,"refreshToken",""),s(r,"localStorage"),s(r,"autoLoginParams",{enabled:!1});let f=r;n.MonaAPI=f,n.Observable=u,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
(function(n,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(n=typeof globalThis<"u"?globalThis:n||self,i(n.monaJsSdk={}))})(this,function(n){"use strict";var y=Object.defineProperty;var p=(n,i,c)=>i in n?y(n,i,{enumerable:!0,configurable:!0,writable:!0,value:c}):n[i]=c;var s=(n,i,c)=>(p(n,typeof i!="symbol"?i+"":i,c),c);class i{constructor(e){s(this,"key");s(this,"nodeJsMap",null);s(this,"isBrowser",()=>typeof window<"u");s(this,"get",()=>{if(!this.isBrowser())return this.nodeJsMap.get(this.key);const e=localStorage.getItem(this.key);if(!e)return null;try{return JSON.parse(e)}catch{}return e});s(this,"set",e=>{if(!this.isBrowser()){this.nodeJsMap.set(this.key,e);return}localStorage.setItem(this.key,typeof e=="string"?e:JSON.stringify(e))});s(this,"remove",()=>{if(!this.isBrowser()){this.nodeJsMap.delete(this.key);return}localStorage.removeItem(this.key)});this.key=e,typeof window<"u"&&(this.nodeJsMap=new Map)}}class c{constructor(e,t){s(this,"uuid",Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15)+Date.now().toString(36));this.observable=e,this.callback=t}remove(){this.observable.removeObserver(this)}notify(e){this.callback(e)}}class u{constructor(){s(this,"observers",[])}add(e){const t=new c(this,e);return this.observers.push(t),t}notifyObservers(e){for(const t of this.observers)t.notify(e)}removeObserver(e){this.observers=this.observers.filter(t=>t!==e)}}const r=class r{constructor({apiKey:e,autoLogin:t}){s(this,"onRefreshToken",new u);s(this,"automaticallyLogin",async({refreshToken:e})=>{var t,o;if(e&&!r.refreshToken){r.refreshToken=e,await this.OTP_Refresh();const a=await this.getUser();"username"in a&&(t=r.autoLoginParams)!=null&&t.callbackOnLogin&&((o=r.autoLoginParams)==null||o.callbackOnLogin(a))}});s(this,"OTP_Generate",async e=>await this._fetch("https://api.monaverse.com/public/auth/otp/generate",{method:"POST",body:JSON.stringify({email:e})}));s(this,"OTP_Verify",async(e,t)=>{const o=await this._fetch("https://api.monaverse.com/public/auth/otp/verify",{method:"POST",body:JSON.stringify({email:e,otp:t})});return"access"in o?(r.bearer=o.access,r.refreshToken=o.refresh,r.localStorage.set(o.refresh),this.onRefreshToken.notifyObservers({refreshToken:o.refresh}),{success:!0}):(console.error(o),{success:!1})});s(this,"OTP_Refresh",async()=>{const e=await this._fetch("https://api.monaverse.com/public/auth/token/refresh",{method:"POST",body:JSON.stringify({refresh:r.refreshToken})});return"access"in e?(r.bearer=e.access,r.refreshToken=e.refresh,r.localStorage.set(e.refresh),this.onRefreshToken.notifyObservers({refreshToken:e.refresh}),{success:!0}):(console.error(e),{success:!1})});s(this,"getUser",async()=>{const e=await this._fetch("https://api.monaverse.com/public/user/",{method:"GET"});return"error"in e?{error:"Could not get user"}:e});s(this,"getTokens",async({chain_id:e,address:t,queryKey:o})=>{let a=`https://api.monaverse.com/public/user/${e}/${t}/tokens?includeLastSale=false&includeAttributes=true`;o&&(a+=`&continuation=${o}`);const h=await this._fetch(a,{method:"GET"});if("error"in h)return console.error(h),{tokens:[]};{const m=[];for(const l of h.tokens){const b=await this.getAnimation(l);b&&(l.animation=b,m.push(l))}return{tokens:m,continuation:h.continuation}}});s(this,"getAnimation",async e=>{const t=await this._fetch(`https://api.monaverse.com/public/tokens/${e.chainId}/${e.contract}/${e.tokenId}/animation`,{method:"GET"});return"error"in t?(console.error(t),null):t});s(this,"logout",()=>{r.bearer="",r.refreshToken="",r.localStorage.remove()});s(this,"_fetch",async(e,t)=>{const o={...t,headers:{...t.headers,"Content-Type":"application/json","X-Mona-Application-Id":r.key,...r.bearer?{Authorization:`Bearer ${r.bearer}`}:{}}};try{const a=await fetch(e,o);return a.status===400?{error:await a.text()}:a.status===401?{error:await a.json()}:await a.json()}catch(a){return console.error(a),{error:"Network Error"}}});if(!e)throw new Error("MONA API Key is required");r.key=e,r.autoLoginParams=t||r.autoLoginParams,r.localStorage=new i((t==null?void 0:t.localStorageKey)||"x-mona-auth"),this.onRefreshToken.add(this.automaticallyLogin);const o=r.localStorage.get();o&&this.onRefreshToken.notifyObservers({refreshToken:o})}};s(r,"key",""),s(r,"bearer",""),s(r,"refreshToken",""),s(r,"localStorage"),s(r,"autoLoginParams",{enabled:!1});let f=r;n.MonaAPI=f,n.Observable=u,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
//# sourceMappingURL=index.umd.js.map
{
"name": "mona-js-sdk",
"version": "1.0.5",
"version": "1.0.6",
"description": "Mona JS SDK wrapping the Monaverse HTTP API",

@@ -5,0 +5,0 @@ "author": "Benjy Larcher (https://benjylarcher.com)",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet