-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathsdk.js
More file actions
3 lines (3 loc) · 10.6 KB
/
sdk.js
File metadata and controls
3 lines (3 loc) · 10.6 KB
1
2
3
document.addEventListener("contentsLoaded", ()=>{
!function(){"use strict";function e(e,t,a,n){return new(a||(a=Promise))((function(o,r){function i(e){try{l(n.next(e))}catch(e){r(e)}}function s(e){try{l(n.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof a?t:new a((function(e){e(t)}))).then(i,s)}l((n=n.apply(e,t||[])).next())}))}function t(e,t){var a,n,o,r,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function s(r){return function(s){return function(r){if(a)throw new TypeError("Generator is already executing.");for(;i;)try{if(a=1,n&&(o=2&r[0]?n.return:r[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,r[1])).done)return o;switch(n=0,o&&(r=[2&r[0],o.value]),r[0]){case 0:case 1:o=r;break;case 4:return i.label++,{value:r[1],done:!1};case 5:i.label++,n=r[1],r=[0];continue;case 7:r=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==r[0]&&2!==r[0])){i=0;continue}if(3===r[0]&&(!o||r[1]>o[0]&&r[1]<o[3])){i.label=r[1];break}if(6===r[0]&&i.label<o[1]){i.label=o[1],o=r;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(r);break}o[2]&&i.ops.pop(),i.trys.pop();continue}r=t.call(e,i)}catch(e){r=[6,e],n=0}finally{a=o=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,s])}}}var a=function(){return(a=Object.assign||function(e){for(var t,a=1,n=arguments.length;a<n;a++)for(var o in t=arguments[a])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},n={getHackathonData:function(e){return o.get(o._PREFIX+"hackathons/"+e).then((function(e){var t,a;if(!(null==e?void 0:e.error))return{uuid:e.uuid,slug:e.slug,name:e.name,regEndsAt:null===(t=null==e?void 0:e.hackathon_setting)||void 0===t?void 0:t.reg_ends_at,regStartsAt:null===(a=null==e?void 0:e.hackathon_setting)||void 0===a?void 0:a.reg_starts_at,endsAt:null==e?void 0:e.ends_at,devfolioOfficial:(null==e?void 0:e.devfolio_official)||!1};throw e.error}))},signIn:function(e,t,a){return o.post(o._PREFIX+"users/signin",{username:e,password:t,captcha_response:a}).then((function(t){var a;if(!(null==t?void 0:t.error))return{username:t.username,uuid:t.uuid,roles:t.roles,accessToken:t.access_token,refreshToken:t.refresh_token};var o=[];switch(null===(a=t.error)||void 0===a?void 0:a.message){case"Invalid username":o.push({field:"id",message:"Sorry, we couldn't find an account with that username."});break;case"Account with this email or username does not exists":o.push({field:"id",message:"Sorry, we couldn't find an account with that "+(e.includes("@")?"email":"username")});break;case"Invalid Password":o.push({field:"password",message:"Sorry, that password isn't right."});break;case"Invalid captcha response":o.push({field:"generic",message:"Sorry, we could not sign you in as the captcha validation failed."});break;case"Login attempts over":o.push({field:"generic",message:"The maximum number of login attempts has been reached. Please try again in an hour."})}throw 0===o.length&&(n.captureException(t.error),o.push({field:"generic",message:"Sorry, we could not sign you in at the moment."})),o}))},register:function(e,t,a,r){return o.post(o._PREFIX+"users",{email:t,password:a,username:e,mailing_lists_opt_in:r}).then((function(e){var t,a,o,r,i;if(!(null==e?void 0:e.error))return{username:e.username,uuid:e.uuid,roles:e.roles,accessToken:e.access_token,refreshToken:e.refresh_token};var s=[];if("The server received a request that could not be processed."===(null===(t=e.error)||void 0===t?void 0:t.message)){var l=null===(a=e.error)||void 0===a?void 0:a.source;if(null==l?void 0:l.email)switch(null===(o=l.email)||void 0===o?void 0:o.msg){case"email already in use":s.push({field:"email",message:"Someone (maybe you?) has already created an account using this email."});break;case"must be an email":s.push({field:"email",message:"This doesn't appear to be a valid email address. Please try a different email address."})}if(null==l?void 0:l.username)switch(null===(r=l.username)||void 0===r?void 0:r.msg){case"username not available":s.push({field:"username",message:"Another user with this username already exists. Please try a different username."});break;case"invalid username":s.push({field:"username",message:"Username must be minimum 2 characters long, and should not contain spaces or special characters."})}if(null==l?void 0:l.password)switch(null===(i=l.password)||void 0===i?void 0:i.msg){case"password must be atleast 8 characters long":s.push({field:"password",message:"Password must be minimum 8 characters long."})}}throw 0===s.length&&(n.captureException(e.error),s.push({field:"generic",message:"Sorry, we could not create your account at the moment."})),s}))},apply:function(e,t,r){var i="users/"+e+"/hackathon/"+t+"/apply";return o.post(o._PREFIX+i,{},a(a({},o._HEADERS),{access_token:r})).then((function(e){var t;if(!(null==e?void 0:e.error))return e;var a={field:"generic",message:"Unable to apply to this hackathon."};switch(null===(t=e.error)||void 0===t?void 0:t.message){case"Can't apply, hackathon registrations are not open.":a.message="Sorry, the hackathon registrations are not open.";break;case"Can't apply, hackathon registration are close.":a.message="Sorry, this hackathon is no longer accepting new registrations.";break;default:n.captureException(e.error)}throw a}))},getOrganizedHackathons:function(e,t){return o.get(o._PREFIX+"users/"+e+"/my_organized_hackathons",a(a({},o._HEADERS),{access_token:t})).then((function(e){if(!(null==e?void 0:e.error))return{data:e};throw n.captureException(e.error),e.error}))},captureException:function(e){var t;null===(t=null===window||void 0===window?void 0:window.Sentry)||void 0===t||t.captureException(e)}},o={_PREFIX:"https://api.devfolio.co/api/",_HEADERS:{"Content-Type":"application/json; charset=utf-8"},get:function(e,t){return void 0===e&&(e=""),fetch(e,{method:"GET",mode:"cors",cache:"no-cache",credentials:"same-origin",headers:t||o._HEADERS,referrer:"no-referrer"}).then((function(e){return e.json()})).catch((function(e){throw e}))},post:function(e,t,a){return void 0===e&&(e=""),void 0===t&&(t={}),fetch(e,{method:"POST",mode:"cors",cache:"no-cache",credentials:"same-origin",headers:a||o._HEADERS,referrer:"no-referrer",body:JSON.stringify(t)}).then((function(e){var t=e.headers.get("content-type");return t&&t.includes("application/json")?e.json():e})).catch((function(e){throw e}))}},r={padding:0,border:0,margin:0,height:"44px",width:"320px"},i={position:"fixed",left:0,top:0,display:"none",width:"100%",height:"100%",zIndex:2147483647},s={position:"relative",height:"100%",width:"100%",display:"block",backgroundColor:"transparent",padding:0,border:0,margin:0},l={_CLASSNAME:"devfolio-button-iframe",_SANDBOX:"allow-scripts allow-same-origin allow-top-navigation allow-top-navigation-by-user-activation",createFrame:function(e){var t=document.createElement("iframe");return t.src="https://apply.devfolio.co/v2/button?"+new URLSearchParams(e).toString(),t.title="Apply with Devfolio",t.className=l._CLASSNAME,Object.assign(t.style,r),t.setAttribute("sandbox",l._SANDBOX),t},allFrames:function(){return document.querySelectorAll("."+l._CLASSNAME)},postMessage:function(e,t){l.allFrames().forEach((function(a,n){var o;null===(o=null==a?void 0:a.contentWindow)||void 0===o||o.postMessage({type:e,payload:t},"*")}))}},c={_ID:"devfolio-overlay-iframe",_CONTAINER_ID:"devfolio-overlay-container",_SANDBOX:"allow-scripts allow-same-origin allow-top-navigation allow-top-navigation-by-user-activation allow-forms allow-popups",hasLoaded:!1,createFrame:function(){var e=document.createElement("iframe");e.src="https://apply.devfolio.co/v2/overlay"+window.location.search,e.title="Continue your hackathon application",e.id=c._ID,Object.assign(e.style,s),e.setAttribute("sandbox",c._SANDBOX),e.addEventListener("load",(function(){c.hasLoaded=!0}));var t=document.createElement("div");return t.id=c._CONTAINER_ID,Object.assign(t.style,i),t.appendChild(e),t},frame:function(){return document.querySelector("#"+c._ID)},container:function(){return document.querySelector("#"+c._CONTAINER_ID)},postMessage:function(e,t){var a=c.frame();function n(){var n;null===(n=null==a?void 0:a.contentWindow)||void 0===n||n.postMessage({type:e,payload:t},"*")}c.hasLoaded?n():null==a||a.addEventListener("load",n)}};if("https:"!==window.location.protocol&&!function(){var e=window.location.hostname.split(".");return"localhost"===e[e.length-1]}())throw new Error("Could not initialize the Apply Now script over a non-secure connection.");var u=new Proxy({available:0,loaded:0,hackathonData:null,hasSentHackathonData:!1},{set:function(e,t,a){e[t]=a;var n=function(){l.postMessage("SEND_HACKATHON_DATA",e.hackathonData),c.postMessage("SEND_HACKATHON_DATA",e.hackathonData),e.hasSentHackathonData=!0};return("loaded"===t&&e.available===a&&e.hackathonData&&!e.hasSentHackathonData||"hackathonData"===t&&e.available===e.loaded&&a&&!e.hasSentHackathonData)&&n(),!0}});function d(){return document.querySelectorAll(".apply-button")}window.addEventListener("message",(function(e){var t=e.isTrusted,a=e.data;if(t&&(null==a?void 0:a.type)){var n=c.container();if(!n)return void console.log("(SDK) Could not find the overlay container.");switch(a.type){case"BUTTON_IFRAME_LOADED":u.loaded+=1;break;case"OPEN_OVERLAY":n.style.display="block";break;case"CLOSE_OVERLAY":n.style.display="none";break;default:console.log("(SDK) Received unexpected message.",e)}}})),function(){e(this,void 0,void 0,(function(){var e,a,o,r;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,3,,4]),[4,new Promise((function(e,t){var a=d();if(a.length>0){var n=a[0].getAttribute("data-hackathon-slug");"string"==typeof n&&n.length>0&&e(n)}t("Could not find an element with the class name 'apply-button' that has a data-hackathon-slug attribute.")}))];case 1:return e=t.sent(),a=d(),u.available=a.length,a.forEach((function(e){var t;null===(t=null==e?void 0:e.parentNode)||void 0===t||t.replaceChild(l.createFrame(e.dataset),e)})),i={"ethindia-2022--no-shadow":"60px","ethindia-2022--light-shadow":"64px","ethindia-2022--dark-shadow":"64px","ethindia-2023":"62px"},document.querySelectorAll(".devfolio-button-iframe").forEach((function(e){var t=e.getAttribute("src");if(null!==t){var a=new URL(t),n=a.searchParams.get("buttonWidth"),o=a.searchParams.get("buttonTheme");null!=o&&Object.keys(i).includes(o)&&(e.style.height=i[o]),n&&(e.style.width=n+"px")}})),document.body.appendChild(c.createFrame()),[4,n.getHackathonData(e)];case 2:return o=t.sent(),u.hackathonData=o,[3,4];case 3:return"Failed to fetch"===(null==(r=t.sent())?void 0:r.message)?l.postMessage("ENABLE_DEV_MODE"):console.log("(SDK)",r),[3,4];case 4:return[2]}var i}))}))}()}();
})