@framerauth/sdk 2.1.7 → 2.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/framerauth.js +3 -3
- package/dist/framerauth.mjs +1 -1
- package/package.json +1 -1
package/dist/framerauth.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";(()=>{var Je=Object.defineProperty,Ve=Object.defineProperties,Ge=Object.getOwnPropertyDescriptors,ne=Object.getOwnPropertySymbols,Ke=Object.prototype.hasOwnProperty,Qe=Object.prototype.propertyIsEnumerable,ae=(t,e,r)=>e in t?Je(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,L=(t,e)=>{for(var r in e||(e={}))Ke.call(e,r)&&ae(t,r,e[r]);if(ne)for(var r of ne(e))Qe.call(e,r)&&ae(t,r,e[r]);return t},A=(t,e)=>Ve(t,Ge(e)),Ye=class extends Error{constructor(t,e,r){super(e||t.toString(),{cause:r}),this.status=t,this.statusText=e,this.error=r}},Ze=async(t,e)=>{var r,o,n,a,i,u;let c=e||{},s={onRequest:[e?.onRequest],onResponse:[e?.onResponse],onSuccess:[e?.onSuccess],onError:[e?.onError],onRetry:[e?.onRetry]};if(!e||!e?.plugins)return{url:t,options:c,hooks:s};for(let f of e?.plugins||[]){if(f.init){let v=await((r=f.init)==null?void 0:r.call(f,t.toString(),e));c=v.options||c,t=v.url}s.onRequest.push((o=f.hooks)==null?void 0:o.onRequest),s.onResponse.push((n=f.hooks)==null?void 0:n.onResponse),s.onSuccess.push((a=f.hooks)==null?void 0:a.onSuccess),s.onError.push((i=f.hooks)==null?void 0:i.onError),s.onRetry.push((u=f.hooks)==null?void 0:u.onRetry)}return{url:t,options:c,hooks:s}},ie=class{constructor(t){this.options=t}shouldAttemptRetry(t,e){return this.options.shouldRetry?Promise.resolve(t<this.options.attempts&&this.options.shouldRetry(e)):Promise.resolve(t<this.options.attempts)}getDelay(){return this.options.delay}},Xe=class{constructor(t){this.options=t}shouldAttemptRetry(t,e){return this.options.shouldRetry?Promise.resolve(t<this.options.attempts&&this.options.shouldRetry(e)):Promise.resolve(t<this.options.attempts)}getDelay(t){return Math.min(this.options.maxDelay,this.options.baseDelay*2**t)}};function et(t){if(typeof t=="number")return new ie({type:"linear",attempts:t,delay:1e3});switch(t.type){case"linear":return new ie(t);case"exponential":return new Xe(t);default:throw new Error("Invalid retry strategy")}}var tt=async t=>{let e={},r=async o=>typeof o=="function"?await o():o;if(t?.auth){if(t.auth.type==="Bearer"){let o=await r(t.auth.token);if(!o)return e;e.authorization=`Bearer ${o}`}else if(t.auth.type==="Basic"){let o=r(t.auth.username),n=r(t.auth.password);if(!o||!n)return e;e.authorization=`Basic ${btoa(`${o}:${n}`)}`}else if(t.auth.type==="Custom"){let o=r(t.auth.value);if(!o)return e;e.authorization=`${r(t.auth.prefix)} ${o}`}}return e},rt=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function ot(t){let e=t.headers.get("content-type"),r=new Set(["image/svg","application/xml","application/xhtml","application/html"]);if(!e)return"json";let o=e.split(";").shift()||"";return rt.test(o)?"json":r.has(o)||o.startsWith("text/")?"text":"blob"}function nt(t){try{return JSON.parse(t),!0}catch{return!1}}function ce(t){if(t===void 0)return!1;let e=typeof t;return e==="string"||e==="number"||e==="boolean"||e===null?!0:e!=="object"?!1:Array.isArray(t)?!0:t.buffer?!1:t.constructor&&t.constructor.name==="Object"||typeof t.toJSON=="function"}function se(t){try{return JSON.parse(t)}catch{return t}}function le(t){return typeof t=="function"}function at(t){if(t?.customFetchImpl)return t.customFetchImpl;if(typeof globalThis<"u"&&le(globalThis.fetch))return globalThis.fetch;if(typeof window<"u"&&le(window.fetch))return window.fetch;throw new Error("No fetch implementation found")}async function it(t){let e=new Headers(t?.headers),r=await tt(t);for(let[o,n]of Object.entries(r||{}))e.set(o,n);if(!e.has("content-type")){let o=st(t?.body);o&&e.set("content-type",o)}return e}function st(t){return ce(t)?"application/json":null}function lt(t){if(!t?.body)return null;let e=new Headers(t?.headers);if(ce(t.body)&&!e.has("content-type")){for(let[r,o]of Object.entries(t?.body))o instanceof Date&&(t.body[r]=o.toISOString());return JSON.stringify(t.body)}return t.body}function ct(t,e){var r;if(e?.method)return e.method.toUpperCase();if(t.startsWith("@")){let o=(r=t.split("@")[1])==null?void 0:r.split("/")[0];return ue.includes(o)?o.toUpperCase():e?.body?"POST":"GET"}return e?.body?"POST":"GET"}function dt(t,e){let r;return!t?.signal&&t?.timeout&&(r=setTimeout(()=>e?.abort(),t?.timeout)),{abortTimeout:r,clearTimeout:()=>{r&&clearTimeout(r)}}}var ut=class de extends Error{constructor(e,r){super(r||JSON.stringify(e,null,2)),this.issues=e,Object.setPrototypeOf(this,de.prototype)}};async function ht(t,e){let r=await t["~standard"].validate(e);if(r.issues)throw new ut(r.issues);return r.value}var ue=["get","post","put","patch","delete"];function ft(t,e){let{baseURL:r,params:o,query:n}=e||{query:{},params:{},baseURL:""},a=t.startsWith("http")?t.split("/").slice(0,3).join("/"):r||"";if(t.startsWith("@")){let v=t.toString().split("@")[1].split("/")[0];ue.includes(v)&&(t=t.replace(`@${v}/`,"/"))}a.endsWith("/")||(a+="/");let[i,u]=t.replace(a,"").split("?"),c=new URLSearchParams(u);for(let[v,g]of Object.entries(n||{}))g!=null&&c.set(v,String(g));if(o)if(Array.isArray(o)){let v=i.split("/").filter(g=>g.startsWith(":"));for(let[g,V]of v.entries()){let F=o[g];i=i.replace(V,F)}}else for(let[v,g]of Object.entries(o))i=i.replace(`:${v}`,String(g));i=i.split("/").map(encodeURIComponent).join("/"),i.startsWith("/")&&(i=i.slice(1));let s=c.toString();return s=s.length>0?`?${s}`.replace(/\+/g,"%20"):"",a.startsWith("http")?new URL(`${i}${s}`,a):`${a}${i}${s}`}var h=async(t,e)=>{var r,o,n,a,i,u,c,s;let{hooks:f,url:v,options:g}=await Ze(t,e),V=at(g),F=new AbortController,Ne=(r=g.signal)!=null?r:F.signal,je=ft(v,g),Me=lt(g),$e=await it(g),ze=ct(v,g),p=A(L({},g),{url:je,headers:$e,body:Me,method:ze,signal:Ne});for(let P of f.onRequest)if(P){let b=await P(p);b instanceof Object&&(p=b)}("pipeTo"in p&&typeof p.pipeTo=="function"||typeof((o=e?.body)==null?void 0:o.pipe)=="function")&&("duplex"in p||(p.duplex="half"));let{clearTimeout:He}=dt(g,F),d=await V(p.url,p);He();let re={response:d,request:p};for(let P of f.onResponse)if(P){let b=await P(A(L({},re),{response:(n=e?.hookOptions)!=null&&n.cloneResponse?d.clone():d}));b instanceof Response?d=b:b instanceof Object&&(d=b.response)}if(d.ok){if(!(p.method!=="HEAD"))return{data:"",error:null};let b=ot(d),E={data:"",response:d,request:p};if(b==="json"||b==="text"){let T=await d.text(),qe=await((a=p.jsonParser)!=null?a:se)(T);E.data=qe}else E.data=await d[b]();p?.output&&p.output&&!p.disableValidation&&(E.data=await ht(p.output,E.data));for(let T of f.onSuccess)T&&await T(A(L({},E),{response:(i=e?.hookOptions)!=null&&i.cloneResponse?d.clone():d}));return e?.throw?E.data:{data:E.data,error:null}}let We=(u=e?.jsonParser)!=null?u:se,C=await d.text(),oe=nt(C),G=oe?await We(C):null,Ie={response:d,responseText:C,request:p,error:A(L({},G),{status:d.status,statusText:d.statusText})};for(let P of f.onError)P&&await P(A(L({},Ie),{response:(c=e?.hookOptions)!=null&&c.cloneResponse?d.clone():d}));if(e?.retry){let P=et(e.retry),b=(s=e.retryAttempt)!=null?s:0;if(await P.shouldAttemptRetry(b,d)){for(let T of f.onRetry)T&&await T(re);let E=P.getDelay(b);return await new Promise(T=>setTimeout(T,E)),await h(t,A(L({},e),{retryAttempt:b+1}))}}if(e?.throw)throw new Ye(d.status,d.statusText,oe?G:C);return{data:null,error:A(L({},G),{status:d.status,statusText:d.statusText})}};var pt="https://core.framerauth.com/v2",N=class{baseURL=null;useBearerAuth=!1;data;state;api;auth;constructor(e){this.baseURL=null,this.data=e.data,this.state=e.state,this.api={fetchBookmarks:async()=>{if(!this.baseURL)throw new Error("Auth client not initialized");let r=await h(`${this.baseURL}/profile/bookmarks`,{...this.authOptions()});if(!r.data)return r;let o=new Set(r.data),n={};for(let a of o)n[a]=!0;return{data:n,error:null}},fetchProject:async()=>await h(`${pt}/public/project/config`)},this.auth={getSession:async()=>{if(!this.baseURL)throw new Error("Auth client not initialized");let r=await h(`${this.baseURL}/get-session`,{method:"GET",...this.authOptions(),query:{disableCookieCache:!0}});return r.data?(this.data.user.set(r.data.user),this.data.session.set(r.data.session),this.data.tags.set(r.data.user.tags??[])):(this.data.user.set(null),this.data.session.set(null),this.data.tags.set([]),this.data.bookmarks.set({}),this.data.bearerToken.set(null)),r},signUp:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let{fetchOptions:o,...n}=r,a=this.authOptions(),i={...a,...o,headers:{...a.headers,...o?.headers}},u=await h(`${this.baseURL}/sign-up/email`,{...i,method:"POST",body:n,onSuccess:c=>{let s=c.response.headers.get("set-auth-token");s&&this.data.bearerToken.set(s)}});return u.error||(await this.auth.getSession(),this.api.fetchBookmarks().then(c=>{this.data.bookmarks.set(c.data??{})})),u},signIn:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let{fetchOptions:o,...n}=r,a=this.authOptions(),i={...a,...o,headers:{...a.headers,...o?.headers}},u=await h(`${this.baseURL}/sign-in/email`,{...i,method:"POST",body:n,onSuccess:c=>{let s=c.response.headers.get("set-auth-token");s&&this.data.bearerToken.set(s)}});return u.error||(await this.auth.getSession(),this.api.fetchBookmarks().then(c=>{this.data.bookmarks.set(c.data??{})})),u},signInSocial:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let o=await h(`${this.baseURL}/sign-in/social`,{method:"POST",...this.authOptions(),body:r});return o.data?.url&&(window.location.href=o.data.url),o},signOut:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let o=await h(`${this.baseURL}/sign-out`,{method:"POST",...this.authOptions(),body:{}});return this.data.user.set(null),this.data.session.set(null),this.data.tags.set([]),this.data.bookmarks.set({}),this.data.bearerToken.set(null),r?.redirectTo&&(window.location.href=r.redirectTo),o},sendOTP:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let o=`${this.baseURL}/email-otp/send-verification-otp`;return await h(o,{body:r,...this.authOptions(),method:"POST"})},signInOTP:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let o=`${this.baseURL}/sign-in/email-otp`,n=await h(o,{body:r,...this.authOptions(),method:"POST",onSuccess:a=>{let i=a.response.headers.get("set-auth-token");i&&this.data.bearerToken.set(i)}});return n.error||(await this.auth.getSession(),this.api.fetchBookmarks().then(a=>{this.data.bookmarks.set(a.data??{})})),n},updateProfile:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let o=`${this.baseURL}/profile`;return await h(o,{body:r,...this.authOptions(),method:"PATCH"})},updateProfilePicture:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let o=`${this.baseURL}/profile/avatar`;return await h(o,{method:"POST",body:r,...this.authOptions()})},createBookmark:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let o=`${this.baseURL}/profile/bookmarks`;return await h(o,{body:r,...this.authOptions(),method:"POST"})},deleteBookmark:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let o=`${this.baseURL}/profile/bookmarks/${r.bookmark_type}/${r.id}`;return await h(o,{...this.authOptions(),method:"DELETE"})},sendForgotPasswordEmail:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let o=`${this.baseURL}/request-password-reset`;return await h(o,{body:r,...this.authOptions(),method:"POST"})},resetPassword:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let o=`${this.baseURL}/reset-password`;return await h(o,{body:r,...this.authOptions(),method:"POST"})},storeCheckout:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let o=`${this.baseURL}/store/checkout/session`;return await h(o,{body:r,...this.authOptions(),method:"POST"})},storePortal:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let o=`${this.baseURL}/plugins/${r.pluginId}/portal`,n=this.authOptions();return await h(o,{...n,method:"GET",headers:{...n.headers,Accept:"application/json"}})},sendVerificationEmail:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let o=`${this.baseURL}/send-verification-email`;return await h(o,{body:r,...this.authOptions(),method:"POST"})},exchangeOneTimeToken:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let o=await h(`${this.baseURL}/one-time-token/verify`,{method:"POST",body:{token:r}});return o.data?.session?.token&&this.data.bearerToken.set(o.data.session.token),o}}}updateBaseURL(e){this.baseURL=e}updateAuthMode(e){this.useBearerAuth=e}async handleOTTFromURL(){if(!this.useBearerAuth)return;let e=new URLSearchParams(window.location.search),r=e.get("ott");if(!r)return;e.delete("ott");let o=e.size?`${window.location.pathname}?${e.toString()}${window.location.hash}`:`${window.location.pathname}${window.location.hash}`;history.replaceState(null,"",o),await this.auth.exchangeOneTimeToken(r)}authOptions(){if(this.useBearerAuth){let e=this.data.bearerToken.get();return e?{headers:{Authorization:`Bearer ${e}`}}:{}}return{credentials:"include"}}};var R=[],O=0,j=4,mt=0,y=t=>{let e=[],r={get(){return r.lc||r.listen(()=>{})(),r.value},lc:0,listen(o){return r.lc=e.push(o),()=>{for(let a=O+j;a<R.length;)R[a]===o?R.splice(a,j):a+=j;let n=e.indexOf(o);~n&&(e.splice(n,1),--r.lc||r.off())}},notify(o,n){mt++;let a=!R.length;for(let i of e)R.push(i,r.value,o,n);if(a){for(O=0;O<R.length;O+=j)R[O](R[O+1],R[O+2],R[O+3]);R.length=0}},off(){},set(o){let n=r.value;n!==o&&(r.value=o,r.notify(n))},subscribe(o){let n=r.listen(o);return o(r.value),n},value:t};return r};var gt=5,M=6,$=10,yt=(t,e,r,o)=>(t.events=t.events||{},t.events[r+$]||(t.events[r+$]=o(n=>{t.events[r].reduceRight((a,i)=>(i(a),a),{shared:{},...n})})),t.events[r]=t.events[r]||[],t.events[r].push(e),()=>{let n=t.events[r],a=n.indexOf(e);n.splice(a,1),n.length||(delete t.events[r],t.events[r+$](),delete t.events[r+$])});var he=1e3,K=(t,e)=>yt(t,o=>{let n=e(o);n&&t.events[M].push(n)},gt,o=>{let n=t.listen;t.listen=(...i)=>(!t.lc&&!t.active&&(t.active=!0,o()),n(...i));let a=t.off;return t.events[M]=[],t.off=()=>{a(),setTimeout(()=>{if(t.active&&!t.lc){t.active=!1;for(let i of t.events[M])i();t.events[M]=[]}},he)},()=>{t.listen=n,t.off=a}});var z=(t={})=>{let e=y(t);return e.setKey=function(r,o){let n=e.value;typeof o>"u"&&r in e.value?(e.value={...e.value},delete e.value[r],e.notify(n,r)):e.value[r]!==o&&(e.value={...e.value,[r]:o},e.notify(n,r))},e};var fe=t=>t,D={},Q={addEventListener(){},removeEventListener(){}};function bt(){try{return typeof localStorage<"u"}catch{return!1}}bt()&&(D=localStorage);var vt={addEventListener(t,e,r){window.addEventListener("storage",e),window.addEventListener("pageshow",r)},removeEventListener(t,e,r){window.removeEventListener("storage",e),window.removeEventListener("pageshow",r)}};typeof window<"u"&&(Q=vt);function k(t,e=void 0,r={}){let o=r.encode||fe,n=r.decode||fe,a=y(e),i=a.set;a.set=s=>{let f=o(s);typeof f>"u"?delete D[t]:D[t]=f,i(s)};function u(s){s.key===t?s.newValue===null?i(e):i(n(s.newValue)):D[t]||i(e)}function c(){a.set(D[t]?n(D[t]):e)}return K(a,()=>{if(c(),r.listen!==!1)return Q.addEventListener(t,u,c),()=>{Q.removeEventListener(t,u,c)}}),a}var Pt="framerauth_v2_",pe=new TextEncoder,kt=new TextDecoder;function me(){let t=typeof window<"u"?window.location.hostname:"1f8cXd6c7b4a3vL4z5746oUgQ28190adbef";return pe.encode(Pt+t)}function wt(t){let e=me(),r=pe.encode(t),o=new Uint8Array(r.length);for(let n=0;n<r.length;n++)o[n]=r[n]^e[n%e.length];return o}function St(t){let e=wt(t),r=Array.from(e,o=>String.fromCharCode(o)).join("");return btoa(r)}function Rt(t){let e=me(),r=atob(t),o=Uint8Array.from(r,a=>a.charCodeAt(0)),n=new Uint8Array(o.length);for(let a=0;a<o.length;a++)n[a]=o[a]^e[a%e.length];return kt.decode(n)}function w({obfuscate:t}){return e=>{let r=JSON.stringify(e);return t&&(r=St(r)),r}}function S({deobfuscate:t,fallback:e,validator:r}){return o=>{try{if(!o)return e;t&&(o=Rt(o));let n=JSON.parse(o);if(r){let a=r(n);return a===null?e:a}return n}catch{return e}}}var ge=k("fa-project",null,{encode:w({obfuscate:!0}),decode:S({deobfuscate:!0,fallback:null})}),ye=y(!1);var be=k("fa-tags",[],{encode:w({obfuscate:!0}),decode:S({deobfuscate:!0,fallback:[]})}),ve=y(!1);function Pe(t){return Array.isArray(t)?t.length===0?!0:t.every(e=>e!==null&&typeof e=="object"&&typeof e.id=="string"&&typeof e.name=="string"):!1}function Et(t){if(!t||typeof t!="object")return!1;let e=t;return typeof e.id!="string"||typeof e.email!="string"||typeof e.name!="string"||typeof e.email_verified!="boolean"||!(e.created_at instanceof Date||typeof e.created_at=="string")||!(e.updated_at instanceof Date||typeof e.updated_at=="string")?!1:Pe(e.tags)}function Tt(t){if(!t||typeof t!="object")return!1;let e=t;return typeof e.id=="string"&&typeof e.user_id=="string"&&typeof e.token=="string"&&(e.expires_at instanceof Date||typeof e.expires_at=="string")&&(e.created_at instanceof Date||typeof e.created_at=="string")&&(e.updated_at instanceof Date||typeof e.updated_at=="string")}function ke(t){if(!t||typeof t!="object")return null;let e=t;return Pe(e.tags)||(e.tags=[]),Et(e)?e:null}function we(t){return Tt(t)?t:null}function Ot(t){return!t||typeof t!="object"||Array.isArray(t)?!1:Object.entries(t).every(([e,r])=>typeof e=="string"&&typeof r=="boolean")}function Se(t){return!t||typeof t!="object"||Array.isArray(t)?{}:Ot(t)?t:{}}var Re=k("fa-user",null,{encode:w({obfuscate:!0}),decode:S({deobfuscate:!0,fallback:null,validator:ke})}),Ee=y(!1);var Te=k("fa-session",null,{encode:w({obfuscate:!0}),decode:S({deobfuscate:!0,fallback:null,validator:we})}),Oe=y(!1);var Le=y(!0);var Y=class t extends HTMLElement{static styles=`
|
|
1
|
+
"use strict";(()=>{var Je=Object.defineProperty,Ve=Object.defineProperties,Ge=Object.getOwnPropertyDescriptors,oe=Object.getOwnPropertySymbols,Ke=Object.prototype.hasOwnProperty,Qe=Object.prototype.propertyIsEnumerable,ae=(t,e,r)=>e in t?Je(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,L=(t,e)=>{for(var r in e||(e={}))Ke.call(e,r)&&ae(t,r,e[r]);if(oe)for(var r of oe(e))Qe.call(e,r)&&ae(t,r,e[r]);return t},A=(t,e)=>Ve(t,Ge(e)),Ye=class extends Error{constructor(t,e,r){super(e||t.toString(),{cause:r}),this.status=t,this.statusText=e,this.error=r}},Ze=async(t,e)=>{var r,n,o,a,i,u;let c=e||{},s={onRequest:[e?.onRequest],onResponse:[e?.onResponse],onSuccess:[e?.onSuccess],onError:[e?.onError],onRetry:[e?.onRetry]};if(!e||!e?.plugins)return{url:t,options:c,hooks:s};for(let f of e?.plugins||[]){if(f.init){let v=await((r=f.init)==null?void 0:r.call(f,t.toString(),e));c=v.options||c,t=v.url}s.onRequest.push((n=f.hooks)==null?void 0:n.onRequest),s.onResponse.push((o=f.hooks)==null?void 0:o.onResponse),s.onSuccess.push((a=f.hooks)==null?void 0:a.onSuccess),s.onError.push((i=f.hooks)==null?void 0:i.onError),s.onRetry.push((u=f.hooks)==null?void 0:u.onRetry)}return{url:t,options:c,hooks:s}},ie=class{constructor(t){this.options=t}shouldAttemptRetry(t,e){return this.options.shouldRetry?Promise.resolve(t<this.options.attempts&&this.options.shouldRetry(e)):Promise.resolve(t<this.options.attempts)}getDelay(){return this.options.delay}},Xe=class{constructor(t){this.options=t}shouldAttemptRetry(t,e){return this.options.shouldRetry?Promise.resolve(t<this.options.attempts&&this.options.shouldRetry(e)):Promise.resolve(t<this.options.attempts)}getDelay(t){return Math.min(this.options.maxDelay,this.options.baseDelay*2**t)}};function et(t){if(typeof t=="number")return new ie({type:"linear",attempts:t,delay:1e3});switch(t.type){case"linear":return new ie(t);case"exponential":return new Xe(t);default:throw new Error("Invalid retry strategy")}}var tt=async t=>{let e={},r=async n=>typeof n=="function"?await n():n;if(t?.auth){if(t.auth.type==="Bearer"){let n=await r(t.auth.token);if(!n)return e;e.authorization=`Bearer ${n}`}else if(t.auth.type==="Basic"){let n=r(t.auth.username),o=r(t.auth.password);if(!n||!o)return e;e.authorization=`Basic ${btoa(`${n}:${o}`)}`}else if(t.auth.type==="Custom"){let n=r(t.auth.value);if(!n)return e;e.authorization=`${r(t.auth.prefix)} ${n}`}}return e},rt=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function nt(t){let e=t.headers.get("content-type"),r=new Set(["image/svg","application/xml","application/xhtml","application/html"]);if(!e)return"json";let n=e.split(";").shift()||"";return rt.test(n)?"json":r.has(n)||n.startsWith("text/")?"text":"blob"}function ot(t){try{return JSON.parse(t),!0}catch{return!1}}function ce(t){if(t===void 0)return!1;let e=typeof t;return e==="string"||e==="number"||e==="boolean"||e===null?!0:e!=="object"?!1:Array.isArray(t)?!0:t.buffer?!1:t.constructor&&t.constructor.name==="Object"||typeof t.toJSON=="function"}function se(t){try{return JSON.parse(t)}catch{return t}}function le(t){return typeof t=="function"}function at(t){if(t?.customFetchImpl)return t.customFetchImpl;if(typeof globalThis<"u"&&le(globalThis.fetch))return globalThis.fetch;if(typeof window<"u"&&le(window.fetch))return window.fetch;throw new Error("No fetch implementation found")}async function it(t){let e=new Headers(t?.headers),r=await tt(t);for(let[n,o]of Object.entries(r||{}))e.set(n,o);if(!e.has("content-type")){let n=st(t?.body);n&&e.set("content-type",n)}return e}function st(t){return ce(t)?"application/json":null}function lt(t){if(!t?.body)return null;let e=new Headers(t?.headers);if(ce(t.body)&&!e.has("content-type")){for(let[r,n]of Object.entries(t?.body))n instanceof Date&&(t.body[r]=n.toISOString());return JSON.stringify(t.body)}return t.body}function ct(t,e){var r;if(e?.method)return e.method.toUpperCase();if(t.startsWith("@")){let n=(r=t.split("@")[1])==null?void 0:r.split("/")[0];return ue.includes(n)?n.toUpperCase():e?.body?"POST":"GET"}return e?.body?"POST":"GET"}function dt(t,e){let r;return!t?.signal&&t?.timeout&&(r=setTimeout(()=>e?.abort(),t?.timeout)),{abortTimeout:r,clearTimeout:()=>{r&&clearTimeout(r)}}}var ut=class de extends Error{constructor(e,r){super(r||JSON.stringify(e,null,2)),this.issues=e,Object.setPrototypeOf(this,de.prototype)}};async function ht(t,e){let r=await t["~standard"].validate(e);if(r.issues)throw new ut(r.issues);return r.value}var ue=["get","post","put","patch","delete"];function ft(t,e){let{baseURL:r,params:n,query:o}=e||{query:{},params:{},baseURL:""},a=t.startsWith("http")?t.split("/").slice(0,3).join("/"):r||"";if(t.startsWith("@")){let v=t.toString().split("@")[1].split("/")[0];ue.includes(v)&&(t=t.replace(`@${v}/`,"/"))}a.endsWith("/")||(a+="/");let[i,u]=t.replace(a,"").split("?"),c=new URLSearchParams(u);for(let[v,g]of Object.entries(o||{}))g!=null&&c.set(v,String(g));if(n)if(Array.isArray(n)){let v=i.split("/").filter(g=>g.startsWith(":"));for(let[g,V]of v.entries()){let F=n[g];i=i.replace(V,F)}}else for(let[v,g]of Object.entries(n))i=i.replace(`:${v}`,String(g));i=i.split("/").map(encodeURIComponent).join("/"),i.startsWith("/")&&(i=i.slice(1));let s=c.toString();return s=s.length>0?`?${s}`.replace(/\+/g,"%20"):"",a.startsWith("http")?new URL(`${i}${s}`,a):`${a}${i}${s}`}var h=async(t,e)=>{var r,n,o,a,i,u,c,s;let{hooks:f,url:v,options:g}=await Ze(t,e),V=at(g),F=new AbortController,Ne=(r=g.signal)!=null?r:F.signal,je=ft(v,g),Me=lt(g),$e=await it(g),ze=ct(v,g),p=A(L({},g),{url:je,headers:$e,body:Me,method:ze,signal:Ne});for(let P of f.onRequest)if(P){let b=await P(p);b instanceof Object&&(p=b)}("pipeTo"in p&&typeof p.pipeTo=="function"||typeof((n=e?.body)==null?void 0:n.pipe)=="function")&&("duplex"in p||(p.duplex="half"));let{clearTimeout:He}=dt(g,F),d=await V(p.url,p);He();let re={response:d,request:p};for(let P of f.onResponse)if(P){let b=await P(A(L({},re),{response:(o=e?.hookOptions)!=null&&o.cloneResponse?d.clone():d}));b instanceof Response?d=b:b instanceof Object&&(d=b.response)}if(d.ok){if(!(p.method!=="HEAD"))return{data:"",error:null};let b=nt(d),E={data:"",response:d,request:p};if(b==="json"||b==="text"){let T=await d.text(),qe=await((a=p.jsonParser)!=null?a:se)(T);E.data=qe}else E.data=await d[b]();p?.output&&p.output&&!p.disableValidation&&(E.data=await ht(p.output,E.data));for(let T of f.onSuccess)T&&await T(A(L({},E),{response:(i=e?.hookOptions)!=null&&i.cloneResponse?d.clone():d}));return e?.throw?E.data:{data:E.data,error:null}}let We=(u=e?.jsonParser)!=null?u:se,C=await d.text(),ne=ot(C),G=ne?await We(C):null,Ie={response:d,responseText:C,request:p,error:A(L({},G),{status:d.status,statusText:d.statusText})};for(let P of f.onError)P&&await P(A(L({},Ie),{response:(c=e?.hookOptions)!=null&&c.cloneResponse?d.clone():d}));if(e?.retry){let P=et(e.retry),b=(s=e.retryAttempt)!=null?s:0;if(await P.shouldAttemptRetry(b,d)){for(let T of f.onRetry)T&&await T(re);let E=P.getDelay(b);return await new Promise(T=>setTimeout(T,E)),await h(t,A(L({},e),{retryAttempt:b+1}))}}if(e?.throw)throw new Ye(d.status,d.statusText,ne?G:C);return{data:null,error:A(L({},G),{status:d.status,statusText:d.statusText})}};var pt="https://core.framerauth.com/v2",N=class{baseURL=null;useBearerAuth=!1;data;state;api;auth;constructor(e){this.baseURL=null,this.data=e.data,this.state=e.state,this.api={fetchBookmarks:async()=>{if(!this.baseURL)throw new Error("Auth client not initialized");let r=await h(`${this.baseURL}/profile/bookmarks`,{...this.authOptions()});if(!r.data)return r;let n=new Set(r.data),o={};for(let a of n)o[a]=!0;return{data:o,error:null}},fetchProject:async()=>await h(`${pt}/public/project/config`)},this.auth={getSession:async()=>{if(!this.baseURL)throw new Error("Auth client not initialized");let r=await h(`${this.baseURL}/get-session`,{method:"GET",...this.authOptions(),query:{disableCookieCache:!0}});return r.data?(this.data.user.set(r.data.user),this.data.session.set(r.data.session),this.data.tags.set(r.data.user.tags??[])):(this.data.user.set(null),this.data.session.set(null),this.data.tags.set([]),this.data.bookmarks.set({}),this.data.bearerToken.set(null)),r},signUp:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let{fetchOptions:n,...o}=r,a=this.authOptions(),i={...a,...n,headers:{...a.headers,...n?.headers}},u=await h(`${this.baseURL}/sign-up/email`,{...i,method:"POST",body:o,onSuccess:c=>{let s=c.response.headers.get("set-auth-token");s&&this.data.bearerToken.set(s)}});return u.error||(await this.auth.getSession(),this.api.fetchBookmarks().then(c=>{this.data.bookmarks.set(c.data??{})})),u},signIn:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let{fetchOptions:n,...o}=r,a=this.authOptions(),i={...a,...n,headers:{...a.headers,...n?.headers}},u=await h(`${this.baseURL}/sign-in/email`,{...i,method:"POST",body:o,onSuccess:c=>{let s=c.response.headers.get("set-auth-token");s&&this.data.bearerToken.set(s)}});return u.error||(await this.auth.getSession(),this.api.fetchBookmarks().then(c=>{this.data.bookmarks.set(c.data??{})})),u},signInSocial:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let n=await h(`${this.baseURL}/sign-in/social`,{method:"POST",...this.authOptions(),body:r});return n.data?.url&&(window.location.href=n.data.url),n},signOut:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let n=await h(`${this.baseURL}/sign-out`,{method:"POST",...this.authOptions(),body:{}});return this.data.user.set(null),this.data.session.set(null),this.data.tags.set([]),this.data.bookmarks.set({}),this.data.bearerToken.set(null),r?.redirectTo&&(window.location.href=r.redirectTo),n},sendOTP:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let n=`${this.baseURL}/email-otp/send-verification-otp`;return await h(n,{body:r,...this.authOptions(),method:"POST"})},signInOTP:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let n=`${this.baseURL}/sign-in/email-otp`,o=await h(n,{body:r,...this.authOptions(),method:"POST",onSuccess:a=>{let i=a.response.headers.get("set-auth-token");i&&this.data.bearerToken.set(i)}});return o.error||(await this.auth.getSession(),this.api.fetchBookmarks().then(a=>{this.data.bookmarks.set(a.data??{})})),o},updateProfile:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let n=`${this.baseURL}/profile`;return await h(n,{body:r,...this.authOptions(),method:"PATCH"})},updateProfilePicture:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let n=`${this.baseURL}/profile/avatar`;return await h(n,{method:"POST",body:r,...this.authOptions()})},createBookmark:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let n=`${this.baseURL}/profile/bookmarks`;return await h(n,{body:r,...this.authOptions(),method:"POST"})},deleteBookmark:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let n=`${this.baseURL}/profile/bookmarks/${r.bookmark_type}/${r.id}`;return await h(n,{...this.authOptions(),method:"DELETE"})},sendForgotPasswordEmail:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let n=`${this.baseURL}/request-password-reset`;return await h(n,{body:r,...this.authOptions(),method:"POST"})},resetPassword:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let n=`${this.baseURL}/reset-password`;return await h(n,{body:r,...this.authOptions(),method:"POST"})},storeCheckout:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let n=`${this.baseURL}/store/checkout/session`;return await h(n,{body:r,...this.authOptions(),method:"POST"})},storePortal:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let n=`${this.baseURL}/plugins/${r.pluginId}/portal`,o=this.authOptions();return await h(n,{...o,method:"GET",headers:{...o.headers,Accept:"application/json"},query:r.returnURL?{returnURL:r.returnURL}:void 0})},sendVerificationEmail:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let n=`${this.baseURL}/send-verification-email`;return await h(n,{body:r,...this.authOptions(),method:"POST"})},exchangeOneTimeToken:async r=>{if(!this.baseURL)throw new Error("Auth client not initialized");let n=await h(`${this.baseURL}/one-time-token/verify`,{method:"POST",body:{token:r}});return n.data?.session?.token&&this.data.bearerToken.set(n.data.session.token),n}}}updateBaseURL(e){this.baseURL=e}updateAuthMode(e){this.useBearerAuth=e}async handleOTTFromURL(){if(!this.useBearerAuth)return;let e=new URLSearchParams(window.location.search),r=e.get("ott");if(!r)return;e.delete("ott");let n=e.size?`${window.location.pathname}?${e.toString()}${window.location.hash}`:`${window.location.pathname}${window.location.hash}`;history.replaceState(null,"",n),await this.auth.exchangeOneTimeToken(r)}authOptions(){if(this.useBearerAuth){let e=this.data.bearerToken.get();return e?{headers:{Authorization:`Bearer ${e}`}}:{}}return{credentials:"include"}}};var R=[],O=0,j=4,mt=0,y=t=>{let e=[],r={get(){return r.lc||r.listen(()=>{})(),r.value},lc:0,listen(n){return r.lc=e.push(n),()=>{for(let a=O+j;a<R.length;)R[a]===n?R.splice(a,j):a+=j;let o=e.indexOf(n);~o&&(e.splice(o,1),--r.lc||r.off())}},notify(n,o){mt++;let a=!R.length;for(let i of e)R.push(i,r.value,n,o);if(a){for(O=0;O<R.length;O+=j)R[O](R[O+1],R[O+2],R[O+3]);R.length=0}},off(){},set(n){let o=r.value;o!==n&&(r.value=n,r.notify(o))},subscribe(n){let o=r.listen(n);return n(r.value),o},value:t};return r};var gt=5,M=6,$=10,yt=(t,e,r,n)=>(t.events=t.events||{},t.events[r+$]||(t.events[r+$]=n(o=>{t.events[r].reduceRight((a,i)=>(i(a),a),{shared:{},...o})})),t.events[r]=t.events[r]||[],t.events[r].push(e),()=>{let o=t.events[r],a=o.indexOf(e);o.splice(a,1),o.length||(delete t.events[r],t.events[r+$](),delete t.events[r+$])});var he=1e3,K=(t,e)=>yt(t,n=>{let o=e(n);o&&t.events[M].push(o)},gt,n=>{let o=t.listen;t.listen=(...i)=>(!t.lc&&!t.active&&(t.active=!0,n()),o(...i));let a=t.off;return t.events[M]=[],t.off=()=>{a(),setTimeout(()=>{if(t.active&&!t.lc){t.active=!1;for(let i of t.events[M])i();t.events[M]=[]}},he)},()=>{t.listen=o,t.off=a}});var z=(t={})=>{let e=y(t);return e.setKey=function(r,n){let o=e.value;typeof n>"u"&&r in e.value?(e.value={...e.value},delete e.value[r],e.notify(o,r)):e.value[r]!==n&&(e.value={...e.value,[r]:n},e.notify(o,r))},e};var fe=t=>t,D={},Q={addEventListener(){},removeEventListener(){}};function bt(){try{return typeof localStorage<"u"}catch{return!1}}bt()&&(D=localStorage);var vt={addEventListener(t,e,r){window.addEventListener("storage",e),window.addEventListener("pageshow",r)},removeEventListener(t,e,r){window.removeEventListener("storage",e),window.removeEventListener("pageshow",r)}};typeof window<"u"&&(Q=vt);function k(t,e=void 0,r={}){let n=r.encode||fe,o=r.decode||fe,a=y(e),i=a.set;a.set=s=>{let f=n(s);typeof f>"u"?delete D[t]:D[t]=f,i(s)};function u(s){s.key===t?s.newValue===null?i(e):i(o(s.newValue)):D[t]||i(e)}function c(){a.set(D[t]?o(D[t]):e)}return K(a,()=>{if(c(),r.listen!==!1)return Q.addEventListener(t,u,c),()=>{Q.removeEventListener(t,u,c)}}),a}var Pt="framerauth_v2_",pe=new TextEncoder,kt=new TextDecoder;function me(){let t=typeof window<"u"?window.location.hostname:"1f8cXd6c7b4a3vL4z5746oUgQ28190adbef";return pe.encode(Pt+t)}function wt(t){let e=me(),r=pe.encode(t),n=new Uint8Array(r.length);for(let o=0;o<r.length;o++)n[o]=r[o]^e[o%e.length];return n}function St(t){let e=wt(t),r=Array.from(e,n=>String.fromCharCode(n)).join("");return btoa(r)}function Rt(t){let e=me(),r=atob(t),n=Uint8Array.from(r,a=>a.charCodeAt(0)),o=new Uint8Array(n.length);for(let a=0;a<n.length;a++)o[a]=n[a]^e[a%e.length];return kt.decode(o)}function w({obfuscate:t}){return e=>{let r=JSON.stringify(e);return t&&(r=St(r)),r}}function S({deobfuscate:t,fallback:e,validator:r}){return n=>{try{if(!n)return e;t&&(n=Rt(n));let o=JSON.parse(n);if(r){let a=r(o);return a===null?e:a}return o}catch{return e}}}var ge=k("fa-project",null,{encode:w({obfuscate:!0}),decode:S({deobfuscate:!0,fallback:null})}),ye=y(!1);var be=k("fa-tags",[],{encode:w({obfuscate:!0}),decode:S({deobfuscate:!0,fallback:[]})}),ve=y(!1);function Pe(t){return Array.isArray(t)?t.length===0?!0:t.every(e=>e!==null&&typeof e=="object"&&typeof e.id=="string"&&typeof e.name=="string"):!1}function Et(t){if(!t||typeof t!="object")return!1;let e=t;return typeof e.id!="string"||typeof e.email!="string"||typeof e.name!="string"||typeof e.email_verified!="boolean"||!(e.created_at instanceof Date||typeof e.created_at=="string")||!(e.updated_at instanceof Date||typeof e.updated_at=="string")?!1:Pe(e.tags)}function Tt(t){if(!t||typeof t!="object")return!1;let e=t;return typeof e.id=="string"&&typeof e.user_id=="string"&&typeof e.token=="string"&&(e.expires_at instanceof Date||typeof e.expires_at=="string")&&(e.created_at instanceof Date||typeof e.created_at=="string")&&(e.updated_at instanceof Date||typeof e.updated_at=="string")}function ke(t){if(!t||typeof t!="object")return null;let e=t;return Pe(e.tags)||(e.tags=[]),Et(e)?e:null}function we(t){return Tt(t)?t:null}function Ot(t){return!t||typeof t!="object"||Array.isArray(t)?!1:Object.entries(t).every(([e,r])=>typeof e=="string"&&typeof r=="boolean")}function Se(t){return!t||typeof t!="object"||Array.isArray(t)?{}:Ot(t)?t:{}}var Re=k("fa-user",null,{encode:w({obfuscate:!0}),decode:S({deobfuscate:!0,fallback:null,validator:ke})}),Ee=y(!1);var Te=k("fa-session",null,{encode:w({obfuscate:!0}),decode:S({deobfuscate:!0,fallback:null,validator:we})}),Oe=y(!1);var Le=y(!0);var Y=class t extends HTMLElement{static styles=`
|
|
2
2
|
:host {
|
|
3
3
|
--color-primary: #f9f9f9;
|
|
4
4
|
--color-secondary: #333333;
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
opacity: 1;
|
|
117
117
|
background-color: var(--button-background-active-color);
|
|
118
118
|
}
|
|
119
|
-
`;shadow;config={message:"This page is restricted."};handleBack=()=>{history.back()};static get observedAttributes(){return["message"]}constructor(){super(),this.shadow=this.attachShadow({mode:"closed"})}attributeChangedCallback(e,r,
|
|
119
|
+
`;shadow;config={message:"This page is restricted."};handleBack=()=>{history.back()};static get observedAttributes(){return["message"]}constructor(){super(),this.shadow=this.attachShadow({mode:"closed"})}attributeChangedCallback(e,r,n){e==="message"&&(this.config.message=n||"This page is restricted."),this.render()}connectedCallback(){this.style.fontFamily=getComputedStyle(document.body).fontFamily,this.render()}render(){let e=document.createElement("template");e.innerHTML=`
|
|
120
120
|
<style>${t.styles}</style>
|
|
121
121
|
<div class="section" role="dialog" aria-modal="true" aria-labelledby="fa-access-denied-description">
|
|
122
122
|
<main>
|
|
@@ -140,4 +140,4 @@
|
|
|
140
140
|
</div>
|
|
141
141
|
</main>
|
|
142
142
|
</div>
|
|
143
|
-
`,this.shadow.replaceChildren(e.content.cloneNode(!0));let r=this.shadow.querySelector(".description");r&&(r.textContent=this.config.message),this.shadow.querySelector(".btn--action")?.addEventListener("click",this.handleBack)}},H="fa-access-denied";function Ae(){customElements.get(H)||customElements.define(H,Y)}function x(){document.body.style.visibility="hidden"}function U(){document.body.style.visibility="visible"}var Lt="/sign-in",At="This page is restricted.",W=null;function I(t,e){let
|
|
143
|
+
`,this.shadow.replaceChildren(e.content.cloneNode(!0));let r=this.shadow.querySelector(".description");r&&(r.textContent=this.config.message),this.shadow.querySelector(".btn--action")?.addEventListener("click",this.handleBack)}},H="fa-access-denied";function Ae(){customElements.get(H)||customElements.define(H,Y)}function x(){document.body.style.visibility="hidden"}function U(){document.body.style.visibility="visible"}var Lt="/sign-in",At="This page is restricted.",W=null;function I(t,e){let n=document.querySelector(`meta[name="${t}"]`)?.content.trim();return n||e&&document.querySelector(`meta[name="${e}"]`)?.content.trim()||null}function xt(t){return t?t.split(",").map(e=>e.trim()).filter(Boolean):[]}function Z(){return W||(W={errorPath:m(I("fa:error-path","framerauth:error-path")??Lt),boostPatterns:xt(I("fa:boost","framerauth:boost")),router:I("fa:router"),accessDeniedMessage:I("fa:access-denied-message")??At},W)}function Ut(){return Z().errorPath}function m(t){let r=(t??"").trim();if(r.includes("://"))try{r=new URL(r).pathname}catch{}return r=r.split("#")[0]??"",r=r.split("?")[0]??"",r.length===0&&(r="/"),r.startsWith("/")||(r=`/${r}`),r!=="/"&&r.endsWith("/")&&(r=r.slice(0,-1)),r}function Dt(t,e){return m(t)===m(e)}function X(t=window.location.pathname){return m(t)==="/"}function _(t=window.location.pathname,e=Ut()){return Dt(t,e)}function xe(t){let e=t.map(r=>r.trim()).filter(Boolean).map(r=>{if(r==="*"||r==="/*")return{kind:"all"};let n=r.startsWith("/")?r:`/${r}`;return n.endsWith("/**")?{kind:"deep",base:m(n.slice(0,-3))}:n.endsWith("/*")?{kind:"oneSegment",base:m(n.slice(0,-2))}:n.endsWith("*")?{kind:"prefixPathSegment",base:m(n.slice(0,-1))}:{kind:"exact",base:m(n)}});return r=>{let n=m(r);return e.some(o=>{if(o.kind==="all")return!0;if(o.kind==="exact")return n===o.base;if(o.kind==="deep")return n.startsWith(`${o.base}/`);if(o.kind==="oneSegment"){if(!n.startsWith(`${o.base}/`))return!1;let a=n.slice(o.base.length+1);return a.length>0&&!a.includes("/")}return n===o.base||n.startsWith(`${o.base}/`)})}}var q=class{hasAccess;isPublicPath;errorPath;forceFallbackOverlay;accessDeniedMessage;onError;originalPushState;originalReplaceState;isMonkeyPatched=!1;navigationHandler=null;navigationSuccessHandler=null;fallbackPopStateHandler=null;lockedOverlay=null;shouldReloadAfterErrorRedirect=!1;isObservingNavigation=!1;constructor(e){this.hasAccess=e.hasAccess,this.isPublicPath=e.isPublicPath,this.errorPath=e.errorPath,this.forceFallbackOverlay=e.forceFallbackOverlay,this.accessDeniedMessage=e.accessDeniedMessage,this.onError=e.onError,this.originalPushState=history.pushState.bind(history),this.originalReplaceState=history.replaceState.bind(history)}normalizeToPath(e){if(e instanceof URL)return m(e.pathname);if(e.startsWith("./"))return m(e.slice(1));if(e.startsWith("/"))return m(e);try{let r=new URL(e);return m(r.pathname)}catch{return m(e.startsWith("/")?e:"/"+e)}}normalizePathInput(e){let r=e.startsWith("/")?e:`/${e}`;return m(r)}checkAccess(e){let r=this.normalizePathInput(e);if(_(r,this.errorPath)||this.isPublicPath(r))return!0;try{return this.hasAccess(r)}catch{return!1}}isOnErrorPage(){let e=this.normalizePathInput(window.location.pathname);return _(e,this.errorPath)}redirectToError(){if(this.isOnErrorPage()){U();return}window.location.replace(this.errorPath)}handleAccessDenied(e){e&&this.onError&&this.onError(e),this.redirectToError()}monkeyPatchHistory(){if(this.isMonkeyPatched)return;let e=this;history.pushState=function(r,n,o){if(o){let a=e.normalizeToPath(o);e.checkAccess(a)||(x(),e.isObservingNavigation||e.renderLockedOverlay())}return e.originalPushState.call(this,r,n,o)},history.replaceState=function(r,n,o){if(o){let a=e.normalizeToPath(o);e.checkAccess(a)||(x(),e.isObservingNavigation||e.renderLockedOverlay())}return e.originalReplaceState.call(this,r,n,o)},this.isMonkeyPatched=!0}startObservingNavigation(){if(this.forceFallbackOverlay)return!1;let e=window.navigation;return!e||this.navigationHandler?!1:(this.navigationHandler=r=>{let n=r,o=n.destination?.url;if(!o)return;let a=new URL(o);if(!(a.origin!==window.location.origin||this.checkAccess(a.pathname))){if(x(),n.canIntercept&&r.cancelable&&typeof n.intercept=="function"){n.intercept({precommitHandler:u=>{u.redirect(this.errorPath,{history:n.navigationType==="push"?"push":"replace"}),this.shouldReloadAfterErrorRedirect=!0}});return}this.renderLockedOverlay()}},this.navigationSuccessHandler=()=>{this.shouldReloadAfterErrorRedirect&&this.isOnErrorPage()&&(this.shouldReloadAfterErrorRedirect=!1,window.location.reload())},e.addEventListener("navigate",this.navigationHandler),e.addEventListener("navigatesuccess",this.navigationSuccessHandler),this.isObservingNavigation=!0,!0)}stopObservingNavigation(){let e=window.navigation;!e||!this.navigationHandler||(e.removeEventListener("navigate",this.navigationHandler),this.navigationSuccessHandler&&e.removeEventListener("navigatesuccess",this.navigationSuccessHandler),this.navigationHandler=null,this.navigationSuccessHandler=null,this.shouldReloadAfterErrorRedirect=!1,this.isObservingNavigation=!1)}startObservingFallbackPopState(){this.fallbackPopStateHandler||(this.fallbackPopStateHandler=()=>{if(!this.checkAccess(window.location.pathname)){x(),this.renderLockedOverlay();return}this.removeLockedOverlay(),U()},window.addEventListener("popstate",this.fallbackPopStateHandler))}stopObservingFallbackPopState(){this.fallbackPopStateHandler&&(window.removeEventListener("popstate",this.fallbackPopStateHandler),this.fallbackPopStateHandler=null)}renderLockedOverlay(){if(this.lockedOverlay)return;this.startObservingFallbackPopState(),Ae();let e=document.createElement(H);e.id="fa-access-denied",e.setAttribute("message",this.accessDeniedMessage),document.documentElement.appendChild(e),this.lockedOverlay=e}removeLockedOverlay(){this.lockedOverlay?.remove(),this.lockedOverlay=null}restoreHistory(){this.isMonkeyPatched&&(history.pushState=this.originalPushState,history.replaceState=this.originalReplaceState,this.isMonkeyPatched=!1)}start(){this.stop(),this.startObservingNavigation(),this.monkeyPatchHistory()}stop(){this.restoreHistory(),this.stopObservingNavigation(),this.stopObservingFallbackPopState(),this.removeLockedOverlay(),U()}};var Ue=k("fa-bookmarks",z(),{encode:w({obfuscate:!0}),decode:S({deobfuscate:!0,fallback:{},validator:Se})}),De=y(!1);var _e=k("fa-bearer-token",null,{encode:w({obfuscate:!0}),decode:S({deobfuscate:!0,fallback:null})});var Be=(t,e)=>{let r=m(e),n=t.data.user.get(),o=t.data.session.get(),a=t.data.project.get();if(!a)return!1;if(!Object.prototype.hasOwnProperty.call(a.pages,r))return!0;if(!n||!o)return!1;let u=a.pages[r];return u.length===0?!0:u.some(c=>n.tags.find(s=>s.id===c))};console.log("FramerAuth SDK (JavaScript): 2.1.8");var _t="/v2",Bt=0,l=new N({data:{user:Re,project:ge,tags:be,bookmarks:Ue,session:Te,bearerToken:_e},state:{initializing:Le,userLoading:Ee,projectLoading:ye,tagsLoading:ve,bookmarksLoading:De,sessionLoading:Oe}});window.FramerAuth=l;var B=Z(),Fe=xe(B.boostPatterns);function Ft(){return _()?!0:l.data.project.get()!==null&&Fe(window.location.pathname)}function J(t){let e=Ce(t);if(!e)throw new Error("Unable to initialize FramerAuth: project tenantHost is missing");l.updateBaseURL(`https://${e}${_t}`),l.updateAuthMode(Ct(t))}function Ct(t){return t.sessionTransport==="bearer"}function Ce(t){if(t.customDomain)return t.customDomain;let e=Nt(t);return e?`${t.slug}.${e}`:null}function Nt(t){return Bt||t.tenantHost||null}function ee(){l.api.fetchBookmarks().then(({data:t})=>{l.data.bookmarks.set(t??{})})}function jt(){return new q({hasAccess:t=>Be(l,t),isPublicPath:t=>X(t)||Fe(t),errorPath:B.errorPath,forceFallbackOverlay:B.router==="overlay",accessDeniedMessage:B.accessDeniedMessage,onError:t=>{console.error("[Router] Error in router:",t)}})}function te(){let t=jt();return t.checkAccess(window.location.pathname)?(t.start(),!0):(t.handleAccessDenied(),!1)}function Mt(){let t=l.data.project.get();return t&&Ce(t)?(J(t),l.api.fetchProject().then(e=>{e.data&&(l.data.project.set(e.data),J(e.data))}).catch(e=>{console.error("Failed to refresh FramerAuth project:",e)}),l.handleOTTFromURL().then(()=>l.auth.getSession()).then(e=>{e.data!==null&&ee()}).catch(e=>{console.error("Failed to refresh FramerAuth session:",e)})):(l.state.projectLoading.set(!0),l.api.fetchProject().then(e=>{if(e.data)return l.data.project.set(e.data),J(e.data),l.state.projectLoading.set(!1),l.handleOTTFromURL().then(()=>l.auth.getSession());l.state.projectLoading.set(!1)}).then(e=>{e?.data!==null&&ee()}).catch(e=>{console.error("Failed to initialize FramerAuth in the background:",e),l.state.projectLoading.set(!1)})),te()}async function $t(){x();let t=l.data.project.get(),e=await l.api.fetchProject();if(e.data)t=e.data,l.data.project.set(t);else if(!t)throw new Error(e.error.message||"Unable to load FramerAuth project!");J(t),await l.handleOTTFromURL(),(await l.auth.getSession()).data!==null&&ee();let n=te();return n&&U(),n}async function zt(){l.state.initializing.set(!0);try{(Ft()?Mt():await $t())&&window.dispatchEvent(new CustomEvent("framerauth:initialized"))}catch(t){console.error("Failed to initialize FramerAuth:",t),X()||_(window.location.pathname,B.errorPath)?(te(),U()):window.location.replace(B.errorPath),window.dispatchEvent(new CustomEvent("framerauth:initialization-failed",{detail:{error:t}}))}finally{l.state.initializing.set(!1)}}zt();})();
|
package/dist/framerauth.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var he=()=>typeof window<"u",ge=()=>window.location.host.endsWith("framercanvas.com"),w="FramerAuth snippet missing from start of <body>",v=()=>!he()||ge()||!window?.FramerAuth?null:window.FramerAuth;async function Ge(){let t=v();if(!t)return{data:null,error:{message:w}};try{return await t.auth.getSession()}catch(e){return{data:null,error:{message:e instanceof Error?e.message:"Unknown error"}}}}async function Qe(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.signUp(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function Ye(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.signIn(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function Xe(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.signInOTP(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function Ze(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.sendOTP(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function et(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.signOut(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function tt(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.updateProfile(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function rt(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.updateProfilePicture(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function nt(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.sendForgotPasswordEmail(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function at(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.resetPassword(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function ot(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.signInSocial(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function st(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.storeCheckout(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function it(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.storePortal(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function ut(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.sendVerificationEmail(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}var ye=Object.defineProperty,we=Object.defineProperties,ve=Object.getOwnPropertyDescriptors,G=Object.getOwnPropertySymbols,ke=Object.prototype.hasOwnProperty,Pe=Object.prototype.propertyIsEnumerable,Q=(t,e,r)=>e in t?ye(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,O=(t,e)=>{for(var r in e||(e={}))ke.call(e,r)&&Q(t,r,e[r]);if(G)for(var r of G(e))Pe.call(e,r)&&Q(t,r,e[r]);return t},A=(t,e)=>we(t,ve(e)),be=class extends Error{constructor(t,e,r){super(e||t.toString(),{cause:r}),this.status=t,this.statusText=e,this.error=r}},Te=async(t,e)=>{var r,n,o,a,s,c;let i=e||{},u={onRequest:[e?.onRequest],onResponse:[e?.onResponse],onSuccess:[e?.onSuccess],onError:[e?.onError],onRetry:[e?.onRetry]};if(!e||!e?.plugins)return{url:t,options:i,hooks:u};for(let f of e?.plugins||[]){if(f.init){let l=await((r=f.init)==null?void 0:r.call(f,t.toString(),e));i=l.options||i,t=l.url}u.onRequest.push((n=f.hooks)==null?void 0:n.onRequest),u.onResponse.push((o=f.hooks)==null?void 0:o.onResponse),u.onSuccess.push((a=f.hooks)==null?void 0:a.onSuccess),u.onError.push((s=f.hooks)==null?void 0:s.onError),u.onRetry.push((c=f.hooks)==null?void 0:c.onRetry)}return{url:t,options:i,hooks:u}},Y=class{constructor(t){this.options=t}shouldAttemptRetry(t,e){return this.options.shouldRetry?Promise.resolve(t<this.options.attempts&&this.options.shouldRetry(e)):Promise.resolve(t<this.options.attempts)}getDelay(){return this.options.delay}},Se=class{constructor(t){this.options=t}shouldAttemptRetry(t,e){return this.options.shouldRetry?Promise.resolve(t<this.options.attempts&&this.options.shouldRetry(e)):Promise.resolve(t<this.options.attempts)}getDelay(t){return Math.min(this.options.maxDelay,this.options.baseDelay*2**t)}};function xe(t){if(typeof t=="number")return new Y({type:"linear",attempts:t,delay:1e3});switch(t.type){case"linear":return new Y(t);case"exponential":return new Se(t);default:throw new Error("Invalid retry strategy")}}var Oe=async t=>{let e={},r=async n=>typeof n=="function"?await n():n;if(t?.auth){if(t.auth.type==="Bearer"){let n=await r(t.auth.token);if(!n)return e;e.authorization=`Bearer ${n}`}else if(t.auth.type==="Basic"){let n=r(t.auth.username),o=r(t.auth.password);if(!n||!o)return e;e.authorization=`Basic ${btoa(`${n}:${o}`)}`}else if(t.auth.type==="Custom"){let n=r(t.auth.value);if(!n)return e;e.authorization=`${r(t.auth.prefix)} ${n}`}}return e},Ae=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function Ee(t){let e=t.headers.get("content-type"),r=new Set(["image/svg","application/xml","application/xhtml","application/html"]);if(!e)return"json";let n=e.split(";").shift()||"";return Ae.test(n)?"json":r.has(n)||n.startsWith("text/")?"text":"blob"}function Re(t){try{return JSON.parse(t),!0}catch{return!1}}function ee(t){if(t===void 0)return!1;let e=typeof t;return e==="string"||e==="number"||e==="boolean"||e===null?!0:e!=="object"?!1:Array.isArray(t)?!0:t.buffer?!1:t.constructor&&t.constructor.name==="Object"||typeof t.toJSON=="function"}function X(t){try{return JSON.parse(t)}catch{return t}}function Z(t){return typeof t=="function"}function _e(t){if(t?.customFetchImpl)return t.customFetchImpl;if(typeof globalThis<"u"&&Z(globalThis.fetch))return globalThis.fetch;if(typeof window<"u"&&Z(window.fetch))return window.fetch;throw new Error("No fetch implementation found")}async function Ue(t){let e=new Headers(t?.headers),r=await Oe(t);for(let[n,o]of Object.entries(r||{}))e.set(n,o);if(!e.has("content-type")){let n=Fe(t?.body);n&&e.set("content-type",n)}return e}function Fe(t){return ee(t)?"application/json":null}function je(t){if(!t?.body)return null;let e=new Headers(t?.headers);if(ee(t.body)&&!e.has("content-type")){for(let[r,n]of Object.entries(t?.body))n instanceof Date&&(t.body[r]=n.toISOString());return JSON.stringify(t.body)}return t.body}function Le(t,e){var r;if(e?.method)return e.method.toUpperCase();if(t.startsWith("@")){let n=(r=t.split("@")[1])==null?void 0:r.split("/")[0];return re.includes(n)?n.toUpperCase():e?.body?"POST":"GET"}return e?.body?"POST":"GET"}function Ce(t,e){let r;return!t?.signal&&t?.timeout&&(r=setTimeout(()=>e?.abort(),t?.timeout)),{abortTimeout:r,clearTimeout:()=>{r&&clearTimeout(r)}}}var Ie=class te extends Error{constructor(e,r){super(r||JSON.stringify(e,null,2)),this.issues=e,Object.setPrototypeOf(this,te.prototype)}};async function Be(t,e){let r=await t["~standard"].validate(e);if(r.issues)throw new Ie(r.issues);return r.value}var re=["get","post","put","patch","delete"];function $e(t,e){let{baseURL:r,params:n,query:o}=e||{query:{},params:{},baseURL:""},a=t.startsWith("http")?t.split("/").slice(0,3).join("/"):r||"";if(t.startsWith("@")){let l=t.toString().split("@")[1].split("/")[0];re.includes(l)&&(t=t.replace(`@${l}/`,"/"))}a.endsWith("/")||(a+="/");let[s,c]=t.replace(a,"").split("?"),i=new URLSearchParams(c);for(let[l,m]of Object.entries(o||{}))m!=null&&i.set(l,String(m));if(n)if(Array.isArray(n)){let l=s.split("/").filter(m=>m.startsWith(":"));for(let[m,x]of l.entries()){let y=n[m];s=s.replace(x,y)}}else for(let[l,m]of Object.entries(n))s=s.replace(`:${l}`,String(m));s=s.split("/").map(encodeURIComponent).join("/"),s.startsWith("/")&&(s=s.slice(1));let u=i.toString();return u=u.length>0?`?${u}`.replace(/\+/g,"%20"):"",a.startsWith("http")?new URL(`${s}${u}`,a):`${a}${s}${u}`}var M=async(t,e)=>{var r,n,o,a,s,c,i,u;let{hooks:f,url:l,options:m}=await Te(t,e),x=_e(m),y=new AbortController,U=(r=m.signal)!=null?r:y.signal,B=$e(l,m),ue=je(m),le=await Ue(m),ce=Le(l,m),p=A(O({},m),{url:B,headers:le,body:ue,method:ce,signal:U});for(let P of f.onRequest)if(P){let h=await P(p);h instanceof Object&&(p=h)}("pipeTo"in p&&typeof p.pipeTo=="function"||typeof((n=e?.body)==null?void 0:n.pipe)=="function")&&("duplex"in p||(p.duplex="half"));let{clearTimeout:fe}=Ce(m,y),d=await x(p.url,p);fe();let J={response:d,request:p};for(let P of f.onResponse)if(P){let h=await P(A(O({},J),{response:(o=e?.hookOptions)!=null&&o.cloneResponse?d.clone():d}));h instanceof Response?d=h:h instanceof Object&&(d=h.response)}if(d.ok){if(!(p.method!=="HEAD"))return{data:"",error:null};let h=Ee(d),b={data:"",response:d,request:p};if(h==="json"||h==="text"){let T=await d.text(),pe=await((a=p.jsonParser)!=null?a:X)(T);b.data=pe}else b.data=await d[h]();p?.output&&p.output&&!p.disableValidation&&(b.data=await Be(p.output,b.data));for(let T of f.onSuccess)T&&await T(A(O({},b),{response:(s=e?.hookOptions)!=null&&s.cloneResponse?d.clone():d}));return e?.throw?b.data:{data:b.data,error:null}}let de=(c=e?.jsonParser)!=null?c:X,F=await d.text(),K=Re(F),$=K?await de(F):null,me={response:d,responseText:F,request:p,error:A(O({},$),{status:d.status,statusText:d.statusText})};for(let P of f.onError)P&&await P(A(O({},me),{response:(i=e?.hookOptions)!=null&&i.cloneResponse?d.clone():d}));if(e?.retry){let P=xe(e.retry),h=(u=e.retryAttempt)!=null?u:0;if(await P.shouldAttemptRetry(h,d)){for(let T of f.onRetry)T&&await T(J);let b=P.getDelay(h);return await new Promise(T=>setTimeout(T,b)),await M(t,A(O({},e),{retryAttempt:h+1}))}}if(e?.throw)throw new be(d.status,d.statusText,K?$:F);return{data:null,error:A(O({},$),{status:d.status,statusText:d.statusText})}};function q(t,e,r){let n=new Set(e).add(void 0);return t.listen((o,a,s)=>{n.has(s)&&r(o,a,s)})}import{useCallback as Me,useRef as qe,useSyncExternalStore as He}from"react";var H=(t,e)=>r=>{t.current!==r&&(t.current=r,e())};function S(t,{keys:e,deps:r=[t,e]}={}){let n=qe();n.current=t.get();let o=Me(s=>(H(n,s)(t.value),e?.length>0?q(t,e,H(n,s)):t.listen(H(n,s))),r),a=()=>n.current;return He(o,a,a)}import{useState as ne}from"react";var Ne="https://core.framerauth.com/v2",R=()=>typeof window<"u",j=()=>window.location.host.endsWith("framercanvas.com"),We=()=>{let t=Object.keys(window.parent);for(let e=t.length-1;e>=0;e--)try{let r=new URLSearchParams(window.parent[t[e]].location.search).get("siteId");if(r)return r}catch{}},Ve=async()=>{let t=We()||"";return await M(`${Ne}/public/project/config`,{headers:{"x-framer-project-id":t}})};function St(){if(!R()||j()||!window?.FramerAuth)return{initializing:!0,setInitializing:()=>{}};let t=window.FramerAuth;return{initializing:S(t.state.initializing)}}function E(){if(!R()||j()||!window?.FramerAuth)return{session:null,loading:!1,setSession:()=>{},setLoading:()=>{}};let t=window.FramerAuth,e=S(t.data.session),r=S(t.state.sessionLoading);return{session:e,loading:r,setSession:a=>t.data.session.set(a),setLoading:a=>t.state.sessionLoading.set(a)}}function L(){if(!R()||j()||!window?.FramerAuth)return{user:null,loading:!1,setUser:()=>{},setLoading:()=>{}};let t=window.FramerAuth,e=S(t.data.user),r=S(t.state.userLoading),n=a=>t.data.user.set(a),o=a=>t.state.userLoading.set(a);return e&&!Object.prototype.hasOwnProperty.call(e,"tags")&&(e.tags=[]),{user:e,loading:r,setUser:n,setLoading:o}}function xt(){let[t,e]=ne(null),[r,n]=ne(!1);if(!R())return{project:null,loading:!1,setProject:()=>{},setLoading:()=>{},fetchProject:async()=>({data:null,error:{message:"Browser not available"}})};if(!window?.FramerAuth){let l=y=>e(y),m=y=>n(y);return{project:t,loading:r,setProject:l,setLoading:m,fetchProject:async()=>{m(!0);let y=await Ve();return y.data&&l(y.data),m(!1),y}}}let a=window.FramerAuth,s=S(a.data.project),c=S(a.state.projectLoading),i=l=>a.data.project.set(l),u=l=>a.state.projectLoading.set(l);return{project:s,loading:c,setProject:i,setLoading:u,fetchProject:async()=>{u(!0);let l=await a.api.fetchProject();return l.data&&i(l.data),u(!1),l}}}function C(t){if(!R()||j()||!window?.FramerAuth)return{bookmarks:null,loading:!1,createBookmark:a=>{},deleteBookmark:a=>{},setLoading:()=>{}};let e=window.FramerAuth;return{bookmarks:S(e.data.bookmarks,{keys:t}),createBookmark:a=>{let c={...e.data.bookmarks.get(),[a]:!0};e.data.bookmarks.set(c)},deleteBookmark:a=>{let c={...e.data.bookmarks.get()};delete c[a],e.data.bookmarks.set(c)}}}import{useEffect as V,useMemo as k,useRef as D}from"react";import{useRouter as De,RenderTarget as oe,inferInitialRouteFromPath as ze}from"framer";function ae(t){return t.toLowerCase()}function N(t,e="any"){return t==="all"||t==="any"?t:e}function _(t){return t!==null}function I(t,e,r="all"){if(!_(t))return!1;if(e.length===0)return t.tags.length>0;let n=t.tags.map(a=>ae(a.name)),o=e.map(ae);return r==="any"?o.some(a=>n.includes(a)):o.every(a=>n.includes(a))}import{jsx as g}from"react/jsx-runtime";typeof window<"u"&&window.FramerAuth&&console.log("FramerAuth SDK (React): 2.1.7");function se(t){let e=t;return typeof e?.displayName=="string"&&e.displayName.length>0&&typeof e?.defaultProps=="object"&&e.defaultProps!==null}function ie(t,e){return e?t.parentElement:t}function W(t){let e;if(typeof t=="string")e=t.split(",");else if(Array.isArray(t))e=t.filter(n=>typeof n=="string");else return null;let r=e.map(n=>n.trim()).filter(Boolean);return r.length>0?r:null}function z(t,e){return e!==void 0?typeof e=="string"||Array.isArray(e)||e===null?{tags:W(e),operator:"any"}:{tags:W(e.tags),operator:N(e.require)}:{tags:W(t?.tags),operator:N(t?.require)}}function Lt(t){return e=>{let{session:r}=E();return r?g(t,{...e}):null}}function Ct(t){return e=>{let{session:r}=E();return r?null:g(t,{...e})}}function It(t){return e=>{let{session:r}=E(),n=r?null:e?.variant;return g(t,{...e,variant:n})}}function Bt(t,e){let r=se(t);return n=>{let{user:o}=L(),a=D(null),{tags:s,operator:c}=k(()=>z(n,e),[n?.tags,n?.require,e]),i=k(()=>_(o)?s?I(o,s,c):o.tags.length>0:!1,[o,s,c]);return V(()=>{if(a.current){let f=ie(a.current,r);if(!f)return;i?f.style.display="":f.style.display="none"}},[a.current,i]),k(()=>i!==!0?g("div",{ref:a}):g(t,{ref:a,...n}),[n,i,void 0])}}function $t(t,e){let r=se(t);return n=>{let{user:o}=L(),a=D(null),{tags:s,operator:c}=k(()=>z(n,e),[n?.tags,n?.require,e]),i=k(()=>_(o)?s?I(o,s,c):o.tags.length>0:!1,[o,s,c]);return V(()=>{if(a.current){let f=ie(a.current,r);if(!f)return;i?f.style.display="none":f.style.display=""}},[a.current,i]),k(()=>i===!0?g("div",{ref:a}):g(t,{ref:a,...n}),[n,i,void 0])}}function Mt(t,e){return r=>{let{user:n}=L(),o=r?.variant,{tags:a,operator:s}=z(r,e);if(!a){let u=null;return(!_(n)||n.tags.length===0)&&(u=o),g(t,{...r,variant:u})}let i=I(n,a,s)?null:o;return g(t,{...r,variant:i})}}function qt(t,e="saved-for-later"){return r=>{let{bookmarks:n}=C(),a=k(()=>n?Object.keys(n).some(c=>c.startsWith(`${e}:`)):!1,[n])?null:"Empty State";return g(t,{...r,variant:a})}}function Ht(t,e="saved-for-later"){return r=>{let{bookmarks:n}=C(),o=D(null),a=k(()=>`${e}:${r?.slug}`,[r]),s=k(()=>Je()?!0:n?a in n:!1,[n?.[a],a]);return V(()=>{if(o.current){let i=o.current.parentElement;if(!i)return;s?i.style.display="":i.style.display="none"}},[o.current,s]),k(()=>s?g(t,{ref:o,...r}):g("div",{ref:o}),[r,s,void 0])}}function Nt(t,e="saved-for-later"){return r=>{let n=De(),{session:o}=E(),{bookmarks:a,createBookmark:s,deleteBookmark:c}=C([`${e}:${r?.slug}`]),i=k(()=>`${e}:${r?.slug}`,[r]),u=k(()=>a?i in a:!1,[a?.[i],i]),f=async m=>{try{if(u)c(i),window?.FramerAuth.auth.deleteBookmark({id:r?.slug,bookmark_type:e});else if(s(i),window?.FramerAuth.auth.createBookmark({id:r?.slug,bookmark_type:e}),r?.link){let[x,y]=r.link.split("#"),{routeId:U,pathVariables:B}=ze(n.routes,x);U&&n.navigate(U,y,B)}}catch(x){console.error(x)}},l=k(()=>u?r?.variant:void 0,[u,r?.variant]);return o?g(t,{...r,variant:l,onClick:f}):null}}function Wt(t){return e=>g(t,{...e,onClick:async n=>{window?.FramerAuth.auth.signInSocial({provider:"github",callbackURL:window.location.origin+"/account"})}})}function Vt(t,e){return r=>{let{session:n}=E();return n?g(t,{...r,onClick:async a=>{window?.FramerAuth.auth.signOut({redirectTo:e.redirectTo})}}):null}}function Je(){return oe.current()===oe.canvas}export{Wt as buttonSignInSocial,Vt as buttonSignOut,Ge as getSession,Je as isCanvas,at as resetPassword,nt as sendForgotPasswordEmail,Ze as sendOTP,ut as sendVerificationEmail,Lt as showIfSignedIn,Ct as showIfSignedOut,Bt as showIfWithTag,$t as showIfWithoutTag,Ye as signIn,Xe as signInOTP,ot as signInSocial,et as signOut,Qe as signUp,st as storeCheckout,it as storePortal,It as toggleVariant,Mt as toggleVariantIfWithTag,tt as updateProfile,rt as updateProfilePicture,C as useBookmarks,St as useIsInitializing,xt as useProject,E as useSession,L as useUser,qt as withBookmarks,Ht as withIsBookmarked,Nt as withToggleBookmark};
|
|
1
|
+
var he=()=>typeof window<"u",ge=()=>window.location.host.endsWith("framercanvas.com"),w="FramerAuth snippet missing from start of <body>",v=()=>!he()||ge()||!window?.FramerAuth?null:window.FramerAuth;async function Ge(){let t=v();if(!t)return{data:null,error:{message:w}};try{return await t.auth.getSession()}catch(e){return{data:null,error:{message:e instanceof Error?e.message:"Unknown error"}}}}async function Qe(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.signUp(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function Ye(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.signIn(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function Xe(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.signInOTP(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function Ze(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.sendOTP(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function et(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.signOut(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function tt(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.updateProfile(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function rt(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.updateProfilePicture(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function nt(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.sendForgotPasswordEmail(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function at(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.resetPassword(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function ot(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.signInSocial(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function st(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.storeCheckout(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function it(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.storePortal(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}async function ut(t){let e=v();if(!e)return{data:null,error:{message:w}};try{return await e.auth.sendVerificationEmail(t)}catch(r){return{data:null,error:{message:r instanceof Error?r.message:"Unknown error"}}}}var ye=Object.defineProperty,we=Object.defineProperties,ve=Object.getOwnPropertyDescriptors,G=Object.getOwnPropertySymbols,ke=Object.prototype.hasOwnProperty,Pe=Object.prototype.propertyIsEnumerable,Q=(t,e,r)=>e in t?ye(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,O=(t,e)=>{for(var r in e||(e={}))ke.call(e,r)&&Q(t,r,e[r]);if(G)for(var r of G(e))Pe.call(e,r)&&Q(t,r,e[r]);return t},A=(t,e)=>we(t,ve(e)),be=class extends Error{constructor(t,e,r){super(e||t.toString(),{cause:r}),this.status=t,this.statusText=e,this.error=r}},Te=async(t,e)=>{var r,n,o,a,s,c;let i=e||{},u={onRequest:[e?.onRequest],onResponse:[e?.onResponse],onSuccess:[e?.onSuccess],onError:[e?.onError],onRetry:[e?.onRetry]};if(!e||!e?.plugins)return{url:t,options:i,hooks:u};for(let f of e?.plugins||[]){if(f.init){let l=await((r=f.init)==null?void 0:r.call(f,t.toString(),e));i=l.options||i,t=l.url}u.onRequest.push((n=f.hooks)==null?void 0:n.onRequest),u.onResponse.push((o=f.hooks)==null?void 0:o.onResponse),u.onSuccess.push((a=f.hooks)==null?void 0:a.onSuccess),u.onError.push((s=f.hooks)==null?void 0:s.onError),u.onRetry.push((c=f.hooks)==null?void 0:c.onRetry)}return{url:t,options:i,hooks:u}},Y=class{constructor(t){this.options=t}shouldAttemptRetry(t,e){return this.options.shouldRetry?Promise.resolve(t<this.options.attempts&&this.options.shouldRetry(e)):Promise.resolve(t<this.options.attempts)}getDelay(){return this.options.delay}},Se=class{constructor(t){this.options=t}shouldAttemptRetry(t,e){return this.options.shouldRetry?Promise.resolve(t<this.options.attempts&&this.options.shouldRetry(e)):Promise.resolve(t<this.options.attempts)}getDelay(t){return Math.min(this.options.maxDelay,this.options.baseDelay*2**t)}};function xe(t){if(typeof t=="number")return new Y({type:"linear",attempts:t,delay:1e3});switch(t.type){case"linear":return new Y(t);case"exponential":return new Se(t);default:throw new Error("Invalid retry strategy")}}var Oe=async t=>{let e={},r=async n=>typeof n=="function"?await n():n;if(t?.auth){if(t.auth.type==="Bearer"){let n=await r(t.auth.token);if(!n)return e;e.authorization=`Bearer ${n}`}else if(t.auth.type==="Basic"){let n=r(t.auth.username),o=r(t.auth.password);if(!n||!o)return e;e.authorization=`Basic ${btoa(`${n}:${o}`)}`}else if(t.auth.type==="Custom"){let n=r(t.auth.value);if(!n)return e;e.authorization=`${r(t.auth.prefix)} ${n}`}}return e},Ae=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function Ee(t){let e=t.headers.get("content-type"),r=new Set(["image/svg","application/xml","application/xhtml","application/html"]);if(!e)return"json";let n=e.split(";").shift()||"";return Ae.test(n)?"json":r.has(n)||n.startsWith("text/")?"text":"blob"}function Re(t){try{return JSON.parse(t),!0}catch{return!1}}function ee(t){if(t===void 0)return!1;let e=typeof t;return e==="string"||e==="number"||e==="boolean"||e===null?!0:e!=="object"?!1:Array.isArray(t)?!0:t.buffer?!1:t.constructor&&t.constructor.name==="Object"||typeof t.toJSON=="function"}function X(t){try{return JSON.parse(t)}catch{return t}}function Z(t){return typeof t=="function"}function _e(t){if(t?.customFetchImpl)return t.customFetchImpl;if(typeof globalThis<"u"&&Z(globalThis.fetch))return globalThis.fetch;if(typeof window<"u"&&Z(window.fetch))return window.fetch;throw new Error("No fetch implementation found")}async function Ue(t){let e=new Headers(t?.headers),r=await Oe(t);for(let[n,o]of Object.entries(r||{}))e.set(n,o);if(!e.has("content-type")){let n=Fe(t?.body);n&&e.set("content-type",n)}return e}function Fe(t){return ee(t)?"application/json":null}function je(t){if(!t?.body)return null;let e=new Headers(t?.headers);if(ee(t.body)&&!e.has("content-type")){for(let[r,n]of Object.entries(t?.body))n instanceof Date&&(t.body[r]=n.toISOString());return JSON.stringify(t.body)}return t.body}function Le(t,e){var r;if(e?.method)return e.method.toUpperCase();if(t.startsWith("@")){let n=(r=t.split("@")[1])==null?void 0:r.split("/")[0];return re.includes(n)?n.toUpperCase():e?.body?"POST":"GET"}return e?.body?"POST":"GET"}function Ce(t,e){let r;return!t?.signal&&t?.timeout&&(r=setTimeout(()=>e?.abort(),t?.timeout)),{abortTimeout:r,clearTimeout:()=>{r&&clearTimeout(r)}}}var Ie=class te extends Error{constructor(e,r){super(r||JSON.stringify(e,null,2)),this.issues=e,Object.setPrototypeOf(this,te.prototype)}};async function Be(t,e){let r=await t["~standard"].validate(e);if(r.issues)throw new Ie(r.issues);return r.value}var re=["get","post","put","patch","delete"];function $e(t,e){let{baseURL:r,params:n,query:o}=e||{query:{},params:{},baseURL:""},a=t.startsWith("http")?t.split("/").slice(0,3).join("/"):r||"";if(t.startsWith("@")){let l=t.toString().split("@")[1].split("/")[0];re.includes(l)&&(t=t.replace(`@${l}/`,"/"))}a.endsWith("/")||(a+="/");let[s,c]=t.replace(a,"").split("?"),i=new URLSearchParams(c);for(let[l,m]of Object.entries(o||{}))m!=null&&i.set(l,String(m));if(n)if(Array.isArray(n)){let l=s.split("/").filter(m=>m.startsWith(":"));for(let[m,x]of l.entries()){let y=n[m];s=s.replace(x,y)}}else for(let[l,m]of Object.entries(n))s=s.replace(`:${l}`,String(m));s=s.split("/").map(encodeURIComponent).join("/"),s.startsWith("/")&&(s=s.slice(1));let u=i.toString();return u=u.length>0?`?${u}`.replace(/\+/g,"%20"):"",a.startsWith("http")?new URL(`${s}${u}`,a):`${a}${s}${u}`}var M=async(t,e)=>{var r,n,o,a,s,c,i,u;let{hooks:f,url:l,options:m}=await Te(t,e),x=_e(m),y=new AbortController,U=(r=m.signal)!=null?r:y.signal,B=$e(l,m),ue=je(m),le=await Ue(m),ce=Le(l,m),p=A(O({},m),{url:B,headers:le,body:ue,method:ce,signal:U});for(let P of f.onRequest)if(P){let h=await P(p);h instanceof Object&&(p=h)}("pipeTo"in p&&typeof p.pipeTo=="function"||typeof((n=e?.body)==null?void 0:n.pipe)=="function")&&("duplex"in p||(p.duplex="half"));let{clearTimeout:fe}=Ce(m,y),d=await x(p.url,p);fe();let J={response:d,request:p};for(let P of f.onResponse)if(P){let h=await P(A(O({},J),{response:(o=e?.hookOptions)!=null&&o.cloneResponse?d.clone():d}));h instanceof Response?d=h:h instanceof Object&&(d=h.response)}if(d.ok){if(!(p.method!=="HEAD"))return{data:"",error:null};let h=Ee(d),b={data:"",response:d,request:p};if(h==="json"||h==="text"){let T=await d.text(),pe=await((a=p.jsonParser)!=null?a:X)(T);b.data=pe}else b.data=await d[h]();p?.output&&p.output&&!p.disableValidation&&(b.data=await Be(p.output,b.data));for(let T of f.onSuccess)T&&await T(A(O({},b),{response:(s=e?.hookOptions)!=null&&s.cloneResponse?d.clone():d}));return e?.throw?b.data:{data:b.data,error:null}}let de=(c=e?.jsonParser)!=null?c:X,F=await d.text(),K=Re(F),$=K?await de(F):null,me={response:d,responseText:F,request:p,error:A(O({},$),{status:d.status,statusText:d.statusText})};for(let P of f.onError)P&&await P(A(O({},me),{response:(i=e?.hookOptions)!=null&&i.cloneResponse?d.clone():d}));if(e?.retry){let P=xe(e.retry),h=(u=e.retryAttempt)!=null?u:0;if(await P.shouldAttemptRetry(h,d)){for(let T of f.onRetry)T&&await T(J);let b=P.getDelay(h);return await new Promise(T=>setTimeout(T,b)),await M(t,A(O({},e),{retryAttempt:h+1}))}}if(e?.throw)throw new be(d.status,d.statusText,K?$:F);return{data:null,error:A(O({},$),{status:d.status,statusText:d.statusText})}};function q(t,e,r){let n=new Set(e).add(void 0);return t.listen((o,a,s)=>{n.has(s)&&r(o,a,s)})}import{useCallback as Me,useRef as qe,useSyncExternalStore as He}from"react";var H=(t,e)=>r=>{t.current!==r&&(t.current=r,e())};function S(t,{keys:e,deps:r=[t,e]}={}){let n=qe();n.current=t.get();let o=Me(s=>(H(n,s)(t.value),e?.length>0?q(t,e,H(n,s)):t.listen(H(n,s))),r),a=()=>n.current;return He(o,a,a)}import{useState as ne}from"react";var Ne="https://core.framerauth.com/v2",R=()=>typeof window<"u",j=()=>window.location.host.endsWith("framercanvas.com"),We=()=>{let t=Object.keys(window.parent);for(let e=t.length-1;e>=0;e--)try{let r=new URLSearchParams(window.parent[t[e]].location.search).get("siteId");if(r)return r}catch{}},Ve=async()=>{let t=We()||"";return await M(`${Ne}/public/project/config`,{headers:{"x-framer-project-id":t}})};function St(){if(!R()||j()||!window?.FramerAuth)return{initializing:!0,setInitializing:()=>{}};let t=window.FramerAuth;return{initializing:S(t.state.initializing)}}function E(){if(!R()||j()||!window?.FramerAuth)return{session:null,loading:!1,setSession:()=>{},setLoading:()=>{}};let t=window.FramerAuth,e=S(t.data.session),r=S(t.state.sessionLoading);return{session:e,loading:r,setSession:a=>t.data.session.set(a),setLoading:a=>t.state.sessionLoading.set(a)}}function L(){if(!R()||j()||!window?.FramerAuth)return{user:null,loading:!1,setUser:()=>{},setLoading:()=>{}};let t=window.FramerAuth,e=S(t.data.user),r=S(t.state.userLoading),n=a=>t.data.user.set(a),o=a=>t.state.userLoading.set(a);return e&&!Object.prototype.hasOwnProperty.call(e,"tags")&&(e.tags=[]),{user:e,loading:r,setUser:n,setLoading:o}}function xt(){let[t,e]=ne(null),[r,n]=ne(!1);if(!R())return{project:null,loading:!1,setProject:()=>{},setLoading:()=>{},fetchProject:async()=>({data:null,error:{message:"Browser not available"}})};if(!window?.FramerAuth){let l=y=>e(y),m=y=>n(y);return{project:t,loading:r,setProject:l,setLoading:m,fetchProject:async()=>{m(!0);let y=await Ve();return y.data&&l(y.data),m(!1),y}}}let a=window.FramerAuth,s=S(a.data.project),c=S(a.state.projectLoading),i=l=>a.data.project.set(l),u=l=>a.state.projectLoading.set(l);return{project:s,loading:c,setProject:i,setLoading:u,fetchProject:async()=>{u(!0);let l=await a.api.fetchProject();return l.data&&i(l.data),u(!1),l}}}function C(t){if(!R()||j()||!window?.FramerAuth)return{bookmarks:null,loading:!1,createBookmark:a=>{},deleteBookmark:a=>{},setLoading:()=>{}};let e=window.FramerAuth;return{bookmarks:S(e.data.bookmarks,{keys:t}),createBookmark:a=>{let c={...e.data.bookmarks.get(),[a]:!0};e.data.bookmarks.set(c)},deleteBookmark:a=>{let c={...e.data.bookmarks.get()};delete c[a],e.data.bookmarks.set(c)}}}import{useEffect as V,useMemo as k,useRef as D}from"react";import{useRouter as De,RenderTarget as oe,inferInitialRouteFromPath as ze}from"framer";function ae(t){return t.toLowerCase()}function N(t,e="any"){return t==="all"||t==="any"?t:e}function _(t){return t!==null}function I(t,e,r="all"){if(!_(t))return!1;if(e.length===0)return t.tags.length>0;let n=t.tags.map(a=>ae(a.name)),o=e.map(ae);return r==="any"?o.some(a=>n.includes(a)):o.every(a=>n.includes(a))}import{jsx as g}from"react/jsx-runtime";typeof window<"u"&&window.FramerAuth&&console.log("FramerAuth SDK (React): 2.1.8");function se(t){let e=t;return typeof e?.displayName=="string"&&e.displayName.length>0&&typeof e?.defaultProps=="object"&&e.defaultProps!==null}function ie(t,e){return e?t.parentElement:t}function W(t){let e;if(typeof t=="string")e=t.split(",");else if(Array.isArray(t))e=t.filter(n=>typeof n=="string");else return null;let r=e.map(n=>n.trim()).filter(Boolean);return r.length>0?r:null}function z(t,e){return e!==void 0?typeof e=="string"||Array.isArray(e)||e===null?{tags:W(e),operator:"any"}:{tags:W(e.tags),operator:N(e.require)}:{tags:W(t?.tags),operator:N(t?.require)}}function Lt(t){return e=>{let{session:r}=E();return r?g(t,{...e}):null}}function Ct(t){return e=>{let{session:r}=E();return r?null:g(t,{...e})}}function It(t){return e=>{let{session:r}=E(),n=r?null:e?.variant;return g(t,{...e,variant:n})}}function Bt(t,e){let r=se(t);return n=>{let{user:o}=L(),a=D(null),{tags:s,operator:c}=k(()=>z(n,e),[n?.tags,n?.require,e]),i=k(()=>_(o)?s?I(o,s,c):o.tags.length>0:!1,[o,s,c]);return V(()=>{if(a.current){let f=ie(a.current,r);if(!f)return;i?f.style.display="":f.style.display="none"}},[a.current,i]),k(()=>i!==!0?g("div",{ref:a}):g(t,{ref:a,...n}),[n,i,void 0])}}function $t(t,e){let r=se(t);return n=>{let{user:o}=L(),a=D(null),{tags:s,operator:c}=k(()=>z(n,e),[n?.tags,n?.require,e]),i=k(()=>_(o)?s?I(o,s,c):o.tags.length>0:!1,[o,s,c]);return V(()=>{if(a.current){let f=ie(a.current,r);if(!f)return;i?f.style.display="none":f.style.display=""}},[a.current,i]),k(()=>i===!0?g("div",{ref:a}):g(t,{ref:a,...n}),[n,i,void 0])}}function Mt(t,e){return r=>{let{user:n}=L(),o=r?.variant,{tags:a,operator:s}=z(r,e);if(!a){let u=null;return(!_(n)||n.tags.length===0)&&(u=o),g(t,{...r,variant:u})}let i=I(n,a,s)?null:o;return g(t,{...r,variant:i})}}function qt(t,e="saved-for-later"){return r=>{let{bookmarks:n}=C(),a=k(()=>n?Object.keys(n).some(c=>c.startsWith(`${e}:`)):!1,[n])?null:"Empty State";return g(t,{...r,variant:a})}}function Ht(t,e="saved-for-later"){return r=>{let{bookmarks:n}=C(),o=D(null),a=k(()=>`${e}:${r?.slug}`,[r]),s=k(()=>Je()?!0:n?a in n:!1,[n?.[a],a]);return V(()=>{if(o.current){let i=o.current.parentElement;if(!i)return;s?i.style.display="":i.style.display="none"}},[o.current,s]),k(()=>s?g(t,{ref:o,...r}):g("div",{ref:o}),[r,s,void 0])}}function Nt(t,e="saved-for-later"){return r=>{let n=De(),{session:o}=E(),{bookmarks:a,createBookmark:s,deleteBookmark:c}=C([`${e}:${r?.slug}`]),i=k(()=>`${e}:${r?.slug}`,[r]),u=k(()=>a?i in a:!1,[a?.[i],i]),f=async m=>{try{if(u)c(i),window?.FramerAuth.auth.deleteBookmark({id:r?.slug,bookmark_type:e});else if(s(i),window?.FramerAuth.auth.createBookmark({id:r?.slug,bookmark_type:e}),r?.link){let[x,y]=r.link.split("#"),{routeId:U,pathVariables:B}=ze(n.routes,x);U&&n.navigate(U,y,B)}}catch(x){console.error(x)}},l=k(()=>u?r?.variant:void 0,[u,r?.variant]);return o?g(t,{...r,variant:l,onClick:f}):null}}function Wt(t){return e=>g(t,{...e,onClick:async n=>{window?.FramerAuth.auth.signInSocial({provider:"github",callbackURL:window.location.origin+"/account"})}})}function Vt(t,e){return r=>{let{session:n}=E();return n?g(t,{...r,onClick:async a=>{window?.FramerAuth.auth.signOut({redirectTo:e.redirectTo})}}):null}}function Je(){return oe.current()===oe.canvas}export{Wt as buttonSignInSocial,Vt as buttonSignOut,Ge as getSession,Je as isCanvas,at as resetPassword,nt as sendForgotPasswordEmail,Ze as sendOTP,ut as sendVerificationEmail,Lt as showIfSignedIn,Ct as showIfSignedOut,Bt as showIfWithTag,$t as showIfWithoutTag,Ye as signIn,Xe as signInOTP,ot as signInSocial,et as signOut,Qe as signUp,st as storeCheckout,it as storePortal,It as toggleVariant,Mt as toggleVariantIfWithTag,tt as updateProfile,rt as updateProfilePicture,C as useBookmarks,St as useIsInitializing,xt as useProject,E as useSession,L as useUser,qt as withBookmarks,Ht as withIsBookmarked,Nt as withToggleBookmark};
|