UNPKG

eventbrite

Version:
3 lines (2 loc) 12.5 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Eventbrite={})}(this,function(t){"use strict";var o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(t,e)};function r(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var c=function(){return(c=Object.assign||function(t){for(var e,r=1,o=arguments.length;r<o;r++)for(var n in e=arguments[r])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)};var a="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||void 0!==a&&a,n="URLSearchParams"in a,i="Symbol"in a&&"iterator"in Symbol,u="FileReader"in a&&"Blob"in a&&function(){try{return new Blob,!0}catch(t){return!1}}(),s="FormData"in a,f="ArrayBuffer"in a;if(f)var e=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],h=ArrayBuffer.isView||function(t){return t&&-1<e.indexOf(Object.prototype.toString.call(t))};function d(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(t)||""===t)throw new TypeError('Invalid character in header field name: "'+t+'"');return t.toLowerCase()}function p(t){return"string"!=typeof t&&(t=String(t)),t}function l(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return i&&(t[Symbol.iterator]=function(){return t}),t}function y(e){this.map={},e instanceof y?e.forEach(function(t,e){this.append(e,t)},this):Array.isArray(e)?e.forEach(function(t){this.append(t[0],t[1])},this):e&&Object.getOwnPropertyNames(e).forEach(function(t){this.append(t,e[t])},this)}function b(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function m(r){return new Promise(function(t,e){r.onload=function(){t(r.result)},r.onerror=function(){e(r.error)}})}function w(t){var e=new FileReader,r=m(e);return e.readAsArrayBuffer(t),r}function v(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function _(){return this.bodyUsed=!1,this._initBody=function(t){var e;this.bodyUsed=this.bodyUsed,(this._bodyInit=t)?"string"==typeof t?this._bodyText=t:u&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:s&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:n&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():f&&u&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=v(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):f&&(ArrayBuffer.prototype.isPrototypeOf(t)||h(t))?this._bodyArrayBuffer=v(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):n&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},u&&(this.blob=function(){var t=b(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){if(this._bodyArrayBuffer){var t=b(this);return t||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer))}return this.blob().then(w)}),this.text=function(){var t,e,r,o=b(this);if(o)return o;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,r=m(e),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),o=0;o<e.length;o++)r[o]=String.fromCharCode(e[o]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},s&&(this.formData=function(){return this.text().then(E)}),this.json=function(){return this.text().then(JSON.parse)},this}y.prototype.append=function(t,e){t=d(t),e=p(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},y.prototype.delete=function(t){delete this.map[d(t)]},y.prototype.get=function(t){return t=d(t),this.has(t)?this.map[t]:null},y.prototype.has=function(t){return this.map.hasOwnProperty(d(t))},y.prototype.set=function(t,e){this.map[d(t)]=p(e)},y.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},y.prototype.keys=function(){var r=[];return this.forEach(function(t,e){r.push(e)}),l(r)},y.prototype.values=function(){var e=[];return this.forEach(function(t){e.push(t)}),l(e)},y.prototype.entries=function(){var r=[];return this.forEach(function(t,e){r.push([e,t])}),l(r)},i&&(y.prototype[Symbol.iterator]=y.prototype.entries);var g=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function T(t,e){if(!(this instanceof T))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');var r,o,n=(e=e||{}).body;if(t instanceof T){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new y(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,n||null==t._bodyInit||(n=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new y(e.headers)),this.method=(r=e.method||this.method||"GET",o=r.toUpperCase(),-1<g.indexOf(o)?o:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(n),!("GET"!==this.method&&"HEAD"!==this.method||"no-store"!==e.cache&&"no-cache"!==e.cache)){var i=/([?&])_=[^&]*/;if(i.test(this.url))this.url=this.url.replace(i,"$1_="+(new Date).getTime());else{this.url+=(/\?/.test(this.url)?"&":"?")+"_="+(new Date).getTime()}}}function E(t){var n=new FormData;return t.trim().split("&").forEach(function(t){if(t){var e=t.split("="),r=e.shift().replace(/\+/g," "),o=e.join("=").replace(/\+/g," ");n.append(decodeURIComponent(r),decodeURIComponent(o))}}),n}function A(t,e){if(!(this instanceof A))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=200<=this.status&&this.status<300,this.statusText=void 0===e.statusText?"":""+e.statusText,this.headers=new y(e.headers),this.url=e.url||"",this._initBody(t)}T.prototype.clone=function(){return new T(this,{body:this._bodyInit})},_.call(T.prototype),_.call(A.prototype),A.prototype.clone=function(){return new A(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new y(this.headers),url:this.url})},A.error=function(){var t=new A(null,{status:0,statusText:""});return t.type="error",t};var O=[301,302,303,307,308];A.redirect=function(t,e){if(-1===O.indexOf(e))throw new RangeError("Invalid status code");return new A(null,{status:e,headers:{location:t}})};var j,P=a.DOMException;try{new P}catch(t){(P=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack}).prototype=Object.create(Error.prototype),P.prototype.constructor=P}function B(n,s){return new Promise(function(o,t){var e=new T(n,s);if(e.signal&&e.signal.aborted)return t(new P("Aborted","AbortError"));var i=new XMLHttpRequest;function r(){i.abort()}i.onload=function(){var t,n,e={status:i.status,statusText:i.statusText,headers:(t=i.getAllResponseHeaders()||"",n=new y,t.replace(/\r?\n[\t ]+/g," ").split("\r").map(function(t){return 0===t.indexOf("\n")?t.substr(1,t.length):t}).forEach(function(t){var e=t.split(":"),r=e.shift().trim();if(r){var o=e.join(":").trim();n.append(r,o)}}),n)};e.url="responseURL"in i?i.responseURL:e.headers.get("X-Request-URL");var r="response"in i?i.response:i.responseText;setTimeout(function(){o(new A(r,e))},0)},i.onerror=function(){setTimeout(function(){t(new TypeError("Network request failed"))},0)},i.ontimeout=function(){setTimeout(function(){t(new TypeError("Network request failed"))},0)},i.onabort=function(){setTimeout(function(){t(new P("Aborted","AbortError"))},0)},i.open(e.method,function(e){try{return""===e&&a.location.href?a.location.href:e}catch(t){return e}}(e.url),!0),"include"===e.credentials?i.withCredentials=!0:"omit"===e.credentials&&(i.withCredentials=!1),"responseType"in i&&(u?i.responseType="blob":f&&e.headers.get("Content-Type")&&-1!==e.headers.get("Content-Type").indexOf("application/octet-stream")&&(i.responseType="arraybuffer")),!s||"object"!=typeof s.headers||s.headers instanceof y?e.headers.forEach(function(t,e){i.setRequestHeader(e,t)}):Object.getOwnPropertyNames(s.headers).forEach(function(t){i.setRequestHeader(t,p(s.headers[t]))}),e.signal&&(e.signal.addEventListener("abort",r),i.onreadystatechange=function(){4===i.readyState&&e.signal.removeEventListener("abort",r)}),i.send(void 0===e._bodyInit?null:e._bodyInit)})}B.polyfill=!0,a.fetch||(a.fetch=B,a.Headers=y,a.Request=T,a.Response=A),(j=Object.freeze({__proto__:null,Headers:y,Request:T,Response:A,get DOMException(){return P},fetch:B}))&&j.default;self.fetch.bind(self);var x=function(t){return 400<=t.status?Promise.reject(t):Promise.resolve(t)},U=function(e){try{return e.json().catch(function(){return Promise.reject(e)})}catch(t){return Promise.reject(e)}},R=function(t,e){void 0===e&&(e={});var r=e.headers,o=void 0===r?{}:r,n=e.method,i=void 0===n?"GET":n,s=e.mode,a=function(t,e){var r={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(r[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(t);n<o.length;n++)e.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(t,o[n])&&(r[o[n]]=t[o[n]])}return r}(e,["headers","method","mode"]),u=o;"GET"!==i&&(u=c({"Content-Type":"application/json"},o));var f=c({method:i,mode:s,headers:u,credentials:"cors"===s?"include":"same-origin"},a);return fetch(t,f).then(x).then(U)},S=function(r){return new Promise(function(t,e){U(r).then(function(t){return e({response:r,parsedError:function(t){if(!t.error)return null;var e,r={error:t.error,description:t.error_description};return(e=t).error_detail&&e.error_detail.ARGUMENTS_ERROR&&(r=c(c({},r),{argumentErrors:t.error_detail.ARGUMENTS_ERROR})),r}(t)})}).catch(function(){return e({response:r})})})},D=/_\w/g,I=function(i){return Object.keys(i).reduce(function(t,e){var r,o=i[e],n=e.replace(D,function(t){return t[1].toUpperCase()});return o&&"object"==typeof o&&!Array.isArray(o)&&(o=I(o)),c(c({},t),((r={})[n]=o,r))},{})},C=function(t){var r,o;this.request=(r=t,o=[I],function(t,e){return r(t,e).then(function(r){return o.reduce(function(t,e){return e(r)},r)})})},F=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e.prototype.me=function(){return this.request("/users/me/")},e.prototype.get=function(t){return this.request("/users/"+t+"/")},e}(C),q=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e.prototype.getByUser=function(t){return this.request("/users/"+t+"/organizations/")},e}(C),L=function(n,i){return function(t,e){void 0===e&&(e={});var r=""+n+t,o=e;return i&&(o=c(c({},o),{headers:c(c({},o.headers||{}),{Authorization:"Bearer "+i})})),R(r,o).catch(S)}};t.CONTINUATION_KEY="continuation",t.PAGE_KEY="page",t.default=function(t){var e=void 0===t?{}:t,r=e.baseUrl,o=void 0===r?"https://www.eventbriteapi.com/v3":r,n=e.token,i=L(o,n);return{request:i,users:new F(i),organizations:new q(i)}},Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=eventbrite.min.js.map