UNPKG

invitation-api

Version:

This module that provide direct access to the Invitation API 🎁 https://invitation.codes

2 lines (1 loc) β€’ 23.1 kB
"use strict";var r=1e3,n=60*r,a=60*n,o=24*a,s=7*o,i=365.25*o,u=function(e,t){t=t||{};var r=typeof e;if("string"==r&&0<e.length)return c(e);if("number"==r&&isFinite(e))return(t.long?h:l)(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function c(e){if(!(100<(e=String(e)).length)){e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(e){var t=parseFloat(e[1]);switch((e[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return t*i;case"weeks":case"week":case"w":return t*s;case"days":case"day":case"d":return t*o;case"hours":case"hour":case"hrs":case"hr":case"h":return t*a;case"minutes":case"minute":case"mins":case"min":case"m":return t*n;case"seconds":case"second":case"secs":case"sec":case"s":return t*r;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function l(e){var t=Math.abs(e);return o<=t?Math.round(e/o)+"d":a<=t?Math.round(e/a)+"h":n<=t?Math.round(e/n)+"m":r<=t?Math.round(e/r)+"s":e+"ms"}function h(e){var t=Math.abs(e);return o<=t?f(e,t,o,"day"):a<=t?f(e,t,a,"hour"):n<=t?f(e,t,n,"minute"):r<=t?f(e,t,r,"second"):e+" ms"}function f(e,t,r,n){t=1.5*r<=t;return Math.round(e/r)+" "+n+(t?"s":"")}var d=function(){return(d=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)},p=function(e){return{arrayFormat:(e=void 0===e?{}:e).arrayFormat||"none",booleanFormat:e.booleanFormat||"none",nullFormat:e.nullFormat||"default"}},m=function(e){return encodeURIComponent(e)},g=function(e){return decodeURIComponent(e)},y=function(e,t,r){if("empty-true"===r.booleanFormat&&t)return e;t="unicode"===r.booleanFormat?t?"βœ“":"βœ—":t.toString();return e+"="+t},v=function(e,t){return"hidden"===t.nullFormat?"":"string"===t.nullFormat?e+"=null":e},b=function(e){return"index"===e.arrayFormat?function(e,t){return e+"["+t+"]"}:"brackets"===e.arrayFormat?function(e){return e+"[]"}:function(e){return e}},x=function(r,e,t){var n=b(t);return e.map(function(e,t){return n(r,t)+"="+m(e)}).join("&")},P=function(e,t,r){return null===t?v(e,r):"boolean"==typeof t?y(e,t,r):Array.isArray(t)?x(e,t,r):e+"="+m(t)},E=function(e,t){if(void 0===e)return"empty-true"===t.booleanFormat||null;if("string"===t.booleanFormat){if("true"===e)return!0;if("false"===e)return!1}if("unicode"===t.booleanFormat){if("βœ“"===g(e))return!0;if("βœ—"===g(e))return!1}return"string"===t.nullFormat&&"null"===e?null:g(e)},w=function(e){var t=e.indexOf("?");return-1===t?e:e.slice(t+1)},S=function(e){return void 0!==e},C=function(e){var t=e.indexOf("["),r=-1!==t;return{hasBrackets:r,name:r?e.slice(0,t):e}},k=function(e,t){var o=p(t);return w(e).split("&").reduce(function(e,t){var r=t.split("="),n=r[0],a=r[1],t=C(n),r=t.hasBrackets,n=t.name,t=e[n],a=E(a,o);return e[n]=void 0===t?r?[a]:a:(Array.isArray(t)?t:[t]).concat(a),e},{})},O=function(t,e){var r=p(e);return Object.keys(t).filter(function(e){return S(t[e])}).map(function(e){return P(e,t[e],r)}).filter(Boolean).join("&")},t=/[^!$'()*+,;|:]/g,I=function(e){return e.replace(t,function(e){return encodeURIComponent(e)})},A={default:I,uri:encodeURI,uriComponent:encodeURIComponent,none:function(e){return e},legacy:encodeURI},T={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:function(e){return e},legacy:decodeURIComponent},R=function(e,t,r){t=A[t]||I;return r?String(e).split("/").map(t).join("/"):t(String(e))},j=function(e,t){return(T[t]||decodeURIComponent)(e)},M=function(e){return"("+(e?e.replace(/(^<|>$)/g,""):"[a-zA-Z0-9-_.~%':|=+\\*@$]+")+")"},e=[{name:"url-parameter",pattern:/^:([a-zA-Z0-9-_]*[a-zA-Z0-9]{1})(<(.+?)>)?/,regex:function(e){return new RegExp(M(e[2]))}},{name:"url-parameter-splat",pattern:/^\*([a-zA-Z0-9-_]*[a-zA-Z0-9]{1})/,regex:/([^?]*)/},{name:"url-parameter-matrix",pattern:/^;([a-zA-Z0-9-_]*[a-zA-Z0-9]{1})(<(.+?)>)?/,regex:function(e){return new RegExp(";"+e[1]+"="+M(e[2]))}},{name:"query-parameter",pattern:/^(?:\?|&)(?::)?([a-zA-Z0-9-_]*[a-zA-Z0-9]{1})/},{name:"delimiter",pattern:/^(\/|\?)/,regex:function(e){return new RegExp("\\"+e[0])}},{name:"sub-delimiter",pattern:/^(!|&|-|_|\.|;)/,regex:function(e){return new RegExp(e[0])}},{name:"fragment",pattern:/^([0-9a-zA-Z]+)/,regex:function(e){return new RegExp(e[0])}}],U=function r(n,a){if(void 0===a&&(a=[]),!e.some(function(e){var t=n.match(e.pattern);return!!t&&(a.push({type:e.name,match:t[0],val:t.slice(1,2),otherVal:t.slice(2),regex:e.regex instanceof Function?e.regex(t):e.regex}),t[0].length<n.length&&(a=r(n.substr(t[0].length),a)),!0)}))throw new Error("Could not parse path '"+n+"'");return a},q=function(e){return null!=e},N=function(e,t){return t||"\\/"===e?e:e.replace(/\\\/$/,"")+"(?:\\/)?"},F=function(e,t){return!t||/(\/)$/.test(e)?e:e+"(\\/|\\?|\\.|;|$)"},$=function(e,t,r){void 0===r&&(r="");var n=e[t];return e[t]=void 0===n?r:Array.isArray(n)?n.concat(r):[n,r],e},D={urlParamsEncoding:"default"},z=function(){function r(e,t){if(!e)throw new Error("Missing path in Path constructor");this.path=e,this.options=d(d({},D),t),this.tokens=U(e),this.hasUrlParams=0<this.tokens.filter(function(e){return/^url-parameter/.test(e.type)}).length,this.hasSpatParam=0<this.tokens.filter(function(e){return/splat$/.test(e.type)}).length,this.hasMatrixParams=0<this.tokens.filter(function(e){return/matrix$/.test(e.type)}).length,this.hasQueryParams=0<this.tokens.filter(function(e){return/^query-parameter/.test(e.type)}).length,this.spatParams=this.getParams("url-parameter-splat"),this.urlParams=this.getParams(/^url-parameter/),this.queryParams=this.getParams("query-parameter"),this.params=this.urlParams.concat(this.queryParams),this.source=this.tokens.filter(function(e){return void 0!==e.regex}).map(function(e){return e.regex.source}).join("")}return r.createPath=function(e,t){return new r(e,t)},r.prototype.isQueryParam=function(e){return-1!==this.queryParams.indexOf(e)},r.prototype.isSpatParam=function(e){return-1!==this.spatParams.indexOf(e)},r.prototype.test=function(e,t){var r=this,n=d(d({caseSensitive:!1,strictTrailingSlash:!1},this.options),t),t=N(this.source,n.strictTrailingSlash),a=this.urlTest(e,t+(this.hasQueryParams?"(\\?.*$|$)":"$"),n.caseSensitive,n.urlParamsEncoding);if(!a||!this.hasQueryParams)return a;var o=k(e,n.queryParams);return 0===Object.keys(o).filter(function(e){return!r.isQueryParam(e)}).length?(Object.keys(o).forEach(function(e){return a[e]=o[e]}),a):null},r.prototype.partialTest=function(e,t){var r=this,n=d(d({caseSensitive:!1,delimited:!0},this.options),t),t=F(this.source,n.delimited),a=this.urlTest(e,t,n.caseSensitive,n.urlParamsEncoding);if(!a)return a;if(!this.hasQueryParams)return a;var o=k(e,n.queryParams);return Object.keys(o).filter(function(e){return r.isQueryParam(e)}).forEach(function(e){return $(a,e,o[e])}),a},r.prototype.build=function(a,e){var o=this;void 0===a&&(a={});var s=d(d({ignoreConstraints:!1,ignoreSearch:!1,queryParams:{}},this.options),e),t=Object.keys(a).filter(function(e){return!o.isQueryParam(e)}).reduce(function(e,t){if(!q(a[t]))return e;var r=a[t],n=o.isSpatParam(t);return"boolean"==typeof r?e[t]=r:Array.isArray(r)?e[t]=r.map(function(e){return R(e,s.urlParamsEncoding,n)}):e[t]=R(r,s.urlParamsEncoding,n),e},{});if(this.urlParams.some(function(e){return!q(a[e])})){var r=this.urlParams.filter(function(e){return!q(a[e])});throw new Error("Cannot build path: '"+this.path+"' requires missing parameters { "+r.join(", ")+" }")}if(!s.ignoreConstraints&&!this.tokens.filter(function(e){return/^url-parameter/.test(e.type)&&!/-splat$/.test(e.type)}).every(function(e){return new RegExp("^"+M(e.otherVal[0])+"$").test(t[e.val])}))throw new Error("Some parameters of '"+this.path+"' are of invalid format");e=this.tokens.filter(function(e){return!1===/^query-parameter/.test(e.type)}).map(function(e){return"url-parameter-matrix"===e.type?";"+e.val+"="+t[e.val[0]]:/^url-parameter/.test(e.type)?t[e.val[0]]:e.match}).join("");if(s.ignoreSearch)return e;r=this.queryParams.filter(function(e){return-1!==Object.keys(a).indexOf(e)}).reduce(function(e,t){return e[t]=a[t],e},{}),r=O(r,s.queryParams);return r?e+"?"+r:e},r.prototype.getParams=function(t){var e=t instanceof RegExp?function(e){return t.test(e.type)}:function(e){return e.type===t};return this.tokens.filter(e).map(function(e){return e.val[0]})},r.prototype.urlTest=function(e,t,r,n){var a=this,r=new RegExp("^"+t,r?"":"i"),r=e.match(r);return r?this.urlParams.length?r.slice(1,this.urlParams.length+1).reduce(function(e,t,r){return e[a.urlParams[r]]=j(t,n),e},{}):{}:null},r}();function G(e,t){for(;e.length<t;)e="0"+e;return e}function B(e,t){var r,n;if(0===t.length)return e;for(r=0,n=t.length;r<n;r++)e=(e<<5)-e+t.charCodeAt(r),e|=0;return e<0?-2*e:e}function L(e,r,n){return Object.keys(r).sort().reduce(function(e,t){return _(e,r[t],t,n)},e)}function _(e,t,r,n){e=B(B(B(e,r),Z(t)),typeof t);if(null===t)return B(e,"null");if(void 0===t)return B(e,"undefined");if("object"==typeof t||"function"==typeof t){if(-1!==n.indexOf(t))return B(e,"[Circular]"+r);n.push(t);n=L(e,t,n);if(!("valueOf"in t)||"function"!=typeof t.valueOf)return n;try{return B(n,String(t.valueOf()))}catch(e){return B(n,"[valueOf exception]"+(e.stack||e.message))}}return B(e,t.toString())}function Z(e){return Object.prototype.toString.call(e)}function J(e){return G(_(0,e,"",[]).toString(16),8)}var Q=J,K=X,H=u,W=X.prototype,V=new Date%1e9;function Y(){return(1e9*Math.random()>>>0)+V++}function X(e){this.id=(e=e||{}).id||Y(),this.max=e.max||1/0,this.items=e.items||[],this._lookup={},this.size=this.items.length,this.lastModified=new Date(e.lastModified||new Date);for(var t,r,n=this.items.length;n--;)t=this.items[n],r=new Date(t.expires)-new Date,this._lookup[t.key]=t,0<r?this.expire(t.key,r):r<=0&&this.delete(t.key)}function ee(e,t,r,n,a){for(t=t.split?t.split("."):t,n=0;n<t.length;n++)e=e?e[t[n]]:a;return e===a?r:e}W.has=function(e){return e in this._lookup},W.get=function(e){if(!this.has(e))return null;var t=this._lookup[e];return t.refresh&&this.expire(e,t.refresh),this.items.splice(this.items.indexOf(t),1),this.items.push(t),t.value},W.meta=function(e){if(!this.has(e))return null;e=this._lookup[e];return"meta"in e?e.meta:null},W.set=function(e,t,r){var n=this._lookup[e],t=this._lookup[e]={key:e,value:t};return this.lastModified=new Date,n?(clearTimeout(n.timeout),this.items.splice(this.items.indexOf(n),1,t)):(this.size>=this.max&&this.delete(this.items[0].key),this.items.push(t),this.size++),r&&("ttl"in r&&this.expire(e,r.ttl),"meta"in r&&(t.meta=r.meta),r.refresh&&(t.refresh=r.ttl)),this},W.delete=function(e){var t=this._lookup[e];return!!t&&(this.lastModified=new Date,this.items.splice(this.items.indexOf(t),1),clearTimeout(t.timeout),delete this._lookup[e],this.size--,this)},W.expire=function(e,t){var r=t||0,e=this._lookup[e];if(!e)return this;if("number"!=typeof(r="string"==typeof r?H(t):r))throw new TypeError("Expiration time must be a string or number.");return clearTimeout(e.timeout),e.timeout=setTimeout(this.delete.bind(this,e.key),r),e.expires=Number(new Date)+r,this},W.clear=function(){for(var e=this.items.length;e--;)this.delete(this.items[e].key);return this},W.toJSON=function(){for(var e,t=new Array(this.items.length),r=t.length;r--;)e=this.items[r],t[r]={key:e.key,meta:e.meta,value:e.value,expires:e.expires,refresh:e.refresh};return{id:this.id,max:isFinite(this.max)?this.max:void 0,lastModified:this.lastModified,items:t}};class te extends Error{constructor(e){super(e),this.name="ExternalReference"}}const re=function(e){if(!e.startsWith("/")&&!e.startsWith("#/"))throw new te("Non-relative JSON Pointers are not supported: "+e);[,...e]=e.split("/");let t=[];for(var r of e)t.push(r.replaceAll("~1","/").replaceAll("~0","~"));return t},ne=e=>e.split?re(e):e,ae=function(e,t){return ee(e,ne(t))};var oe={},se=new K({max:300});se.set("item",1,{ttl:100}),se.get("item"),se.has("item"),console.log(se.get("item"),"$@#$@#5852222");var ie=function(e){return"hsl("+e%360+",70%,90%)"};function ue(e){var t=0;if(0==(e=String(e)).length)return t;for(var r=0;r<e.length;r++)t=e.charCodeAt(r)+((t<<5)-t),t&=t;return t}const ce="actor item".split(" ");function le(e,t){return ae(e,t)||{}}function he(e,r){return e.map(t=>(ce.forEach(e=>{t[e]&&t[e].$ref&&(t[e]=le(r,t[e].$ref))}),t))}function fe(t,e){if(t&&t.data&&t.data.$data&&t.data.$refs)try{t.data=he(t.data.$data,t.data.$refs)}catch(e){console.log("CANT RESOLVE PROINTERSSS, NOT PERFORMING REPLACMENT",e),t.data=t.data.$data}var r=t;return e||t&&void 0!==t.data&&(r=t.data),r}function de(){return!("undefined"!=typeof window&&window.document)}function pe(){return"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope}function me(e,t=2){if(0===e)return"0 Bytes";var r=t<0?0:t,t=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,t)).toFixed(r))+" "+["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][t]}function ge(e){console.log("%c "+e.operationId+"() ","background-color: #fafafa ; color: #ddd ; font-weight: bold ; padding: 2px ; border-radius:20px; border:1px solid #ccc; ","...")}function ye(e,r,t){try{var n,a=de()&&!pe(),o=r.baseUrl||"MISSING222",s=[],i=0,u=t.error||r.error;u&&s.push("❌"),t.memoryCached&&s.push("🧠"),r.res&&r.res.headers&&r.res.headers&&(n=me(i=Number(r.res.headers.get("content-length"))||0,1),1e3<i&&s.push("πŸ“¦"),1e4<i&&s.push("πŸ“¦"),1e5<i&&s.push("πŸ“¦"),1e6<i&&s.push("πŸ“¦"));var c=(new Date).getTime()-r.start;500<c&&s.push("🐒"),2e3<c&&s.push("🐒"),8e3<c&&s.push("🐒"),c<200&&s.push("πŸ‡"),c<50&&s.push("πŸ‡"),r.res&&null===r.res.data&&s.push("🀷"),r.hasSavedCached&&s.push("πŸ’Ύ");var l={GET:"#ffffff",POST:"#000",PUT:"#000",DELETE:"#fff"},h={GET:"#888",POST:"#55ff2b",PUT:"#ffc92f",DELETE:"#e52048"}[e.method]||"#333",f=l[e.method]||"#000";"GET"==e.method&&(h=ie(ue(e.operationId)),f="#000");var d="background-color: "+h+" ; color: "+f+" ; font-weight: bold ; font-size:16px; padding: 2px ; border-radius:20px;",p="background-color: #ddd ; color: #777 ; font-weight: bold ; padding: 0px ; border-radius:3px;",m=s.join(" ");a&&console.log("---------------------------------");var g=Object.keys(r.props).map(function(e){return{k:e,val:r.props[e]}}).map(function(e){return e.val});console.groupCollapsed("%c "+e.operationId+"() ",d,m,g.join(" ")),r.props&&Object.keys(r.props).forEach(function(e){var t=(t=r.props[e])||"❌ required...";console.log("%c "+e+" ","background-color: #ddd ; color: blue ; font-weight: bold ; padding: 0px ; border-radius:3px;",t)}),r.qparams&&console.log("%c options ",p,r.qparams),r.postedData&&console.log("%c posted ","background-color: #ddd ; color: #000 ; font-weight: bold ; padding: 0px ; border-radius:3px;",r.postedData),r.res&&!a&&console.info("%c DATA βž” ","background-color: #b4ff00 ; color: #699500 ; font-weight: bold ; padding: 0px ; border-radius:3px;",r.res.data),u&&console.warn("❌ ❌ ",u),console.log("πŸ• "+c.toLocaleString()+" delay"),10<i&&console.log("πŸ“¦",n);var y=o+r.url;console.log("πŸ”—πŸ§ͺ ",y),console.log("πŸ”‘ ",r.url),r.res&&r.res.headers&&(console.log("🧠 memory cache: "+r.clientMemoryCacheStatus," - ",r.res.headers.get("date")),"HIT"!=r.clientMemoryCacheStatus?console.log("πŸ—„οΈ server cache: "+r.res.headers.get("x-api-server-cache-status")," - ",r.res.headers.get("date")):console.log("πŸ—„οΈ server cache: - ")),a||(r.res&&r.res.headers&&(console.groupCollapsed("πŸ€– headers"),r.res.headers.forEach(function(e,t){r.qparams&&console.log("%c "+t+" ",p,e)}),console.groupEnd()),console.log("πŸ€– endpoint",e),console.log("πŸ€– res object",r.res)),a&&console.log("---------------------------------"),console.groupEnd()}catch(e){console.log("LOGGER FUNCITON ERROR: ",e)}}var ve="[invt-api request] ";function be(e,r){return e.filter(function(e){return e.path}).map(function(t){t=Object.assign({},t);t.maxAgeClient||t.maxAgeClientMs?t.maxAgeClientMs=t.maxAgeClientMs||u(t.maxAgeClient):t.maxAgeClientMs=u(r.defaultMaxAge);try{var e=new String(t.path);t.pathObj=z.createPath(e),t.urlParameters=t.pathObj.params,t.urlParametersJoinned=t.urlParameters.join(", "),t.nbUrlParameters=t.urlParameters.length,t.tokenRequired=t.tokenRequired||t.loggedRequired||t.ownerRequired||t.modRequired||t.adminRequired}catch(e){r.debug&&console.log(ve+" --- API defs has an issue with path: ",t.operationId,t.path,e)}return t})}var xe=["background: #f3f0fe","color: #634eaf","line-height: 30px"].join(";");function Pe(g,y,v){return async function(e,t,r,n){ge(g);var a={start:(new Date).getTime(),baseUrl:v.baseUrl||"NO OPTION",myAxios:y},o=y.userToken,s=g,i=[e,t,r,n],u={},c=!1;s.urlParameters.forEach(function(e,t){null===!i[t]&&(c=!0),u[e]=i[t]}),a.props=u;var l={queryParams:{}};try{var h=s.pathObj.build(u,l)}catch(e){var f=s.operationId+"\n ISSUE BUILDING URL FOR route: /api/v2"+s.path+" \n";if(f+="❌ 🎰 βš™οΈ "+s.urlParameters.length+" parameter(s) required --\x3e "+s.urlParameters.join(", ")+" \n",f+="ex: API."+s.operationId+"("+s.urlParameters.join(", ")+", {}) \n//the last parameter is always an optional Options object \n",v.debug&&console.error("%c "+ve+f,xe),v.onError)try{console.log("❌ ❌ ❌ ❌ ",v),console.log("❌ ❌ ❌ ❌ ",v.onError),v.onError(s.operationId,f)}catch(e){console.log("πŸ€–πŸ€–πŸ€–πŸ€–πŸ€–CANT PROCESS onError custom callback.",e)}if(v.throwOnError)throw new Error(ve+f);return null}if(c)return v.debug&&console.log(ve+"calling the API with null values - > returning null CB, abord call..."),ye(s,a,{status:"warning",msg:"calling the API with null values - > returning null CB, abord call...'"}),null;s.nbUrlParameters;var d=i[s.nbUrlParameters],e=(d=d||{})&&(d.noCache||d.noMemoryCache||d.noServerCache),t=d&&d.noServerCache,r="";if("GET"==s.method){a.qparams=d;n=Object.assign({},d);delete n.noCache,delete n.noServerCache;const m=new URLSearchParams(n);(r=m.toString())&&(h+="?"+r)}if(!(r=o||"")&&s.tokenRequired){console.log();f=s.operationId+"\n ❌ πŸ§‘ βš™οΈ MISSING USER TOKEN: /api/v2"+s.path+" \n";if(v.throwOnError)throw new Error(ve+f);return null}if("uploadUserAvatar"==s.operationId||s.operationId,"GET"!=s.method&&"HEAD"!=s.method||(d=null),a.url=h,a.postedData=d,a.clientMemoryCacheStatus="DYNAMIC",v.caching&&"GET"==s.method&&h&&!e){if(se.has(h)){a.clientMemoryCacheStatus="HIT",a.memCacheKey="url";o=se.get(h),f=fe(o,v.envelope);return a.res=o,ye(s,a,{status:"success",memoryCached:!0}),f}a.clientMemoryCacheStatus="MISS"}var l={e:g.operationId,p:u,q:l},p=Q(l);if(oe[p])return oe[p];r={"cache-control":e?"no-cache":"default",Authorization:r};t&&(r["x-server-cache-control"]="no-cache");r=y({method:s.method,url:h,data:d,cache:{maxAge:s.maxAgeClientMs||0},headers:r}).then(function(e){var t=fe(e,v.envelope);return"GET"==s.method&&(a.hasSavedCached=!0,se.set(h,e,{ttl:s.maxAgeClientMs})),a.res=e,ye(s,a,{status:"success"}),t}).catch(function(e){JSON.parse(JSON.stringify(e));var t="Error recahing the server / processing your request......",r=e.status||501;e.response&&(e.response.data&&e.response.data.error&&(t=e.response.data.error.message),e.response.status&&(r=e.response.status)),e.data&&((e=e.data).error&&e.error.status&&(r=e.error.status),e.error&&e.error.message&&(t=e.error.message));r="\n"+s.operationId+"()\nπŸ€– "+r+"❌";throw ye(s,a,{error:r+="\n"+t}),new Error(ve+r)}).finally(()=>{delete oe[p]});return oe[p]=r}}function Ee(e,o,s){var e=be(e,s),i={me:{}};return i.cache=se,i.clearCache=function(){se.clear(),console.log("CACHE CLEARED IN API.")},e.forEach(function(e){var a=e.operationId||"_missingOperatorId";e.pathObj&&(i[a]=Pe(e,o,s),i.me[a]=async function(e,t,r,n){return o.userId?i[a](o.userId,e,t,r,n):(s.debug&&console.warn(ve,"[API waring ]"+a+" -> calling API.me with empty userId: ",o.userId),null)})}),i}var we=function e(i){function u(e,t,r){var n,a={};if(Array.isArray(e))return e.concat(t);for(n in e)a[r?n.toLowerCase():n]=e[n];for(n in t){var o=r?n.toLowerCase():n,s=t[n];a[o]=o in a&&"object"==typeof s?u(a[o],s,"headers"===o):s}return a}function n(e,t,r,n){"string"!=typeof e&&(e=(t=e).url);var a={config:t},o=u(i,t),t={},s=n||o.data;(o.transformRequest||[]).map(function(e){s=e(s,o.headers)||s}),s&&"object"==typeof s&&"function"!=typeof s.append&&(s=JSON.stringify(s),t["content-type"]="application/json");n="undefined"!=typeof document&&document.cookie.match(RegExp("(^|; )"+o.xsrfCookieName+"=([^;]*)"));return n&&(t[o.xsrfHeaderName]=n[2]),o.auth&&(t.authorization=o.auth),o.baseURL&&(e=e.replace(/^(?!.*\/\/)\/?(.*)$/,o.baseURL+"/$1")),o.params&&(n=~e.indexOf("?")?"&":"?",e+=n+(o.paramsSerializer?o.paramsSerializer(o.params):new URLSearchParams(o.params))),(o.fetch||fetch)(e,{method:r||o.method,body:s,headers:u(o.headers,t,!0),credentials:o.withCredentials?"include":"same-origin"}).then(function(e){for(var t in e)"function"!=typeof e[t]&&(a[t]=e[t]);var r=o.validateStatus?o.validateStatus(e.status):e.ok;return"stream"==o.responseType?(a.data=e.body,a):e[o.responseType||"text"]().then(function(e){a.data=e,a.data=JSON.parse(e)}).catch(Object).then(function(){return r?a:Promise.reject(a)})})}return i=i||{},(n.request=n).get=function(e,t){return n(e,t,"get")},n.delete=function(e,t){return n(e,t,"delete")},n.head=function(e,t){return n(e,t,"head")},n.options=function(e,t){return n(e,t,"options")},n.post=function(e,t,r){return n(e,r,"post",t)},n.put=function(e,t,r){return n(e,r,"put",t)},n.patch=function(e,t,r){return n(e,r,"patch",t)},n.all=Promise.all.bind(Promise),n.spread=function(t){return function(e){return t.apply(this,e)}},n.CancelToken="function"==typeof AbortController?AbortController:Object,n.defaults=i,n.create=e,n}(),Se=[{path:"/search",method:"GET",operationId:"search",maxAgeClient:"6h"},{path:"/clientCountry",method:"GET",operationId:"getClientCountry",maxAgeClient:"90d"}],Ce="[invt-api] ";const ke=0,Oe={localhost:!1,endpoints:Se,baseUrl:"https://api.invitation.codes/api/v2",debug:!1,clientKey:null,clientSecret:null,caching:!0,defaultMaxAge:ke,timeout:5e3,envelope:!1,useFetch:!1,throwOnError:!0};function Ie(e){e.localhost&&(e.baseUrl="http://localhost:3000/api/v2");var t,r={baseURL:e.baseUrl,timeout:e.timeout,headers:{"x-client-key":e.clientKey,"x-client-secret":e.clientSecret}};let n;return e.useFetch?n=we.create(r):(e.caching&&(t=setupCache({maxAge:ke,exclude:{query:!1}}),r.adapter=t.adapter),n=axios.create(r),Ae(n,e)),n}function Ae(e,t){e.interceptors.response.use(function(e){return t.debug&&console.log(Ce+"reponse: ",e),e.data,t.debug&&console.log(Ce+"response is an OBJECT :",e),e},function(e){return Promise.reject(e)})}function Te(e){e=e||{},e=Object.assign(Oe,e),console.log("OPTIONS",e);var t=Ie(e);e.userToken&&(t.userToken=e.userToken),e.userId&&(t.userId=e.userId);e=Ee(e.endpoints,t,e);return e.configUserToken=function(e){return console.log("[API lib ] SETTING NEW USER TOKEN: ",e),t.userToken=e,"done"},e.configUserId=function(e){return t.userId=e,"done"},e.configBaseUrl=function(e){return t.baseUrl=e,"done"},e}module.exports=Te;