{"version":3,"file":"thenty-sdk.min.CJL6otOV.mjs","names":["e","t"],"sources":["https:/cdn.thenty.io/beta/thenty-sdk.min.js"],"sourcesContent":["const logStyle=\"color:white;background-color:#FF4A29;font-family:system-ui;font-size:1.2rem;font-weight:bold\";class ThentySDK{constructor(){console.log(\"%cthenty SDK Module\",logStyle),this.apiURL=\"https://api.thenty.io\"}fetchAuthorizationKey(){return(window?.location?new URL(window.location.origin):\"\").host+\".authorization\"}fetchAuthorization(){var e=localStorage.getItem(this.fetchAuthorizationKey());return e?JSON.parse(e):null}setAuthorization(e){var t=this.fetchAuthorizationKey();localStorage.setItem(t,JSON.stringify(e)),window.dispatchEvent(new CustomEvent(\"storage\",{detail:{key:t,newValue:e}}))}fetchMetadataKey(){return(window?.location?new URL(window.location.origin):\"\").host+\".metadata\"}fetchMetadata(){var e=localStorage.getItem(this.fetchMetadataKey());return e?JSON.parse(e):null}logout(e=\"/\"){localStorage.removeItem(this.fetchAuthorizationKey()),window.location.pathname=e}checkForProduct(e=[],t=null){let r=t,o=(r=r||this.fetchAuthorization(),!1);if(r?.hasOwnProperty(\"member\"))for(const a of(r.member.products??[]).map(e=>e.id))if(e.includes(a)){o=!0;break}return o}getDataForCanvas(){var e=this.fetchMetadataKey(),t=this.fetchAuthorizationKey();let r=localStorage.getItem(e),o=localStorage.getItem(t)??null;o=o&&JSON.parse(o),r=r&&JSON.parse(r);var e=o?.hasOwnProperty(\"authorization\")&&o?.hasOwnProperty(\"member\"),t=o?.key?r?.logged_in_access_denied_redirect_path??\"#\":r?.login_redirect_path??\"#\",a=o?.member?.products??[];return{siteMeta:r,authorization:o,isLoggedIn:e,redirect_path:t,memberProducts:a}}isAccessDenied({regex_pattern:e,product_ids:t},r=[],o){e=new RegExp(e),t=!t.length||t.findIndex(e=>r.includes(e));return e.test(o)&&-1===t}assessPathForAccess(e,t=\"\"){var{siteMeta:r,redirect_path:o,memberProducts:a}=this.getDataForCanvas(),i=a.map(e=>e.id),n=e.startsWith(\"/\")?(\"\"+e).slice(1):e;for(const s of r?.protected_pages||[])if(this.isAccessDenied(s,i,n))return o?\"/\"+o:\"/access-denied\";return e+t}getRequestHeaders(e=!1){let t=!1;return e&&(t=this.fetchAuthorization()),{\"Content-Type\":\"application/json\",Accept:\"application/json\",\"x-secret-key\":window.variables.secretKey,\"x-site-key\":window.variables.siteKey,\"x-refresh-token\":window.variables.siteKey,...t&&{authorization:t?.authorization?.key,\"x-refresh-token\":t?.authorization.refresh}}}isGoogleRedirect(e=null){e=e??new URLSearchParams(window.location.search);return e?.has(\"code\")&&e?.has(\"state\")&&\"GOOGLE_LOGIN\"===e?.get(\"state\")}fetchGoogleCallback(e=null,t=null){const r=t??new URLSearchParams(window.location.search);fetch(this.apiURL+\"/oauth/members/callback/google\",{method:\"POST\",headers:this.getRequestHeaders(),body:JSON.stringify({code:r.get(\"code\"),...e&&{planIdOverride:e},...window?.Rewardful?.referral&&{rewardfulClientReferenceId:window.Rewardful.referral}})}).then(async e=>{var t=await e.json();if(200<e.status)throw new Error(t.errorMessage);return t}).then(e=>{r.delete(\"code\"),r.delete(\"state\");var t=new URL(window.location.href);t.search=r.toString(),history.replaceState(null,\"\",t.toString()),this.setAuthorization(e),setTimeout(()=>{window.open(e.redirect_url??\"#\",\"_self\")},500)})}refetchSiteMetadataTrigger=()=>{var e=new URL(window.location.origin);window.dispatchEvent(new CustomEvent(\"storage\",{detail:{key:e.host+\".reauth\",newValue:!0}}))};toggleBookmark(e,t,r=void 0){var o=this.fetchAuthorization();return this.fetchGeneric(\"/bookmarks\",\"POST\",{slug:t,collection:e,...void 0!==r&&{value:r}},o?.authorization?.key).then(this.refetchSiteMetadataTrigger)}fetchGeneric(e,t=\"GET\",r=null,o=null){return fetch(\"\"+this.apiURL+e,{method:t,headers:this.getRequestHeaders(o),...r&&{body:JSON.stringify(r)}}).then(async e=>{var t=await e.json();if(200<e.status)throw new Error(t.errorMessage);return t})}}const thentyAuth=new ThentySDK;\"undefined\"!=typeof window&&(window.thentyA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