@framerauth/sdk 2.1.10 → 2.1.12
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 +4 -4
- package/dist/framerauth.mjs +1 -1
- package/package.json +1 -1
package/dist/framerauth.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";(()=>{var Ze=Object.defineProperty,Xe=Object.defineProperties,et=Object.getOwnPropertyDescriptors,ce=Object.getOwnPropertySymbols,tt=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,de=(t,e,r)=>e in t?Ze(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,x=(t,e)=>{for(var r in e||(e={}))tt.call(e,r)&&de(t,r,e[r]);if(ce)for(var r of ce(e))rt.call(e,r)&&de(t,r,e[r]);return t},U=(t,e)=>Xe(t,et(e)),nt=class extends Error{constructor(t,e,r){super(e||t.toString(),{cause:r}),this.status=t,this.statusText=e,this.error=r}},ot=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}},ue=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}},at=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 it(t){if(typeof t=="number")return new ue({type:"linear",attempts:t,delay:1e3});switch(t.type){case"linear":return new ue(t);case"exponential":return new at(t);default:throw new Error("Invalid retry strategy")}}var st=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},lt=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function ct(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 lt.test(n)?"json":r.has(n)||n.startsWith("text/")?"text":"blob"}function dt(t){try{return JSON.parse(t),!0}catch{return!1}}function pe(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 he(t){try{return JSON.parse(t)}catch{return t}}function fe(t){return typeof t=="function"}function ut(t){if(t?.customFetchImpl)return t.customFetchImpl;if(typeof globalThis<"u"&&fe(globalThis.fetch))return globalThis.fetch;if(typeof window<"u"&&fe(window.fetch))return window.fetch;throw new Error("No fetch implementation found")}async function ht(t){let e=new Headers(t?.headers),r=await st(t);for(let[n,o]of Object.entries(r||{}))e.set(n,o);if(!e.has("content-type")){let n=ft(t?.body);n&&e.set("content-type",n)}return e}function ft(t){return pe(t)?"application/json":null}function pt(t){if(!t?.body)return null;let e=new Headers(t?.headers);if(pe(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 mt(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 ge.includes(n)?n.toUpperCase():e?.body?"POST":"GET"}return e?.body?"POST":"GET"}function gt(t,e){let r;return!t?.signal&&t?.timeout&&(r=setTimeout(()=>e?.abort(),t?.timeout)),{abortTimeout:r,clearTimeout:()=>{r&&clearTimeout(r)}}}var bt=class me extends Error{constructor(e,r){super(r||JSON.stringify(e,null,2)),this.issues=e,Object.setPrototypeOf(this,me.prototype)}};async function yt(t,e){let r=await t["~standard"].validate(e);if(r.issues)throw new bt(r.issues);return r.value}var ge=["get","post","put","patch","delete"];function vt(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];ge.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,Q]of v.entries()){let C=n[g];i=i.replace(Q,C)}}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 ot(t,e),Q=ut(g),C=new AbortController,Ie=(r=g.signal)!=null?r:C.signal,We=vt(v,g),qe=pt(g),Je=await ht(g),Ve=mt(v,g),p=U(x({},g),{url:We,headers:Je,body:qe,method:Ve,signal:Ie});for(let k of f.onRequest)if(k){let y=await k(p);y instanceof Object&&(p=y)}("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:Ge}=gt(g,C),d=await Q(p.url,p);Ge();let se={response:d,request:p};for(let k of f.onResponse)if(k){let y=await k(U(x({},se),{response:(o=e?.hookOptions)!=null&&o.cloneResponse?d.clone():d}));y instanceof Response?d=y:y instanceof Object&&(d=y.response)}if(d.ok){if(!(p.method!=="HEAD"))return{data:"",error:null};let y=ct(d),O={data:"",response:d,request:p};if(y==="json"||y==="text"){let E=await d.text(),Ye=await((a=p.jsonParser)!=null?a:he)(E);O.data=Ye}else O.data=await d[y]();p?.output&&p.output&&!p.disableValidation&&(O.data=await yt(p.output,O.data));for(let E of f.onSuccess)E&&await E(U(x({},O),{response:(i=e?.hookOptions)!=null&&i.cloneResponse?d.clone():d}));return e?.throw?O.data:{data:O.data,error:null}}let Ke=(u=e?.jsonParser)!=null?u:he,B=await d.text(),le=dt(B),Y=le?await Ke(B):null,Qe={response:d,responseText:B,request:p,error:U(x({},Y),{status:d.status,statusText:d.statusText})};for(let k of f.onError)k&&await k(U(x({},Qe),{response:(c=e?.hookOptions)!=null&&c.cloneResponse?d.clone():d}));if(e?.retry){let k=it(e.retry),y=(s=e.retryAttempt)!=null?s:0;if(await k.shouldAttemptRetry(y,d)){for(let E of f.onRetry)E&&await E(se);let O=k.getDelay(y);return await new Promise(E=>setTimeout(E,O)),await h(t,U(x({},e),{retryAttempt:y+1}))}}if(e?.throw)throw new nt(d.status,d.statusText,le?Y:B);return{data:null,error:U(x({},Y),{status:d.status,statusText:d.statusText})}};var kt="https://core.framerauth.com/v2",j=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(`${kt}/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=[],L=0,N=4,wt=0,b=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=L+N;a<R.length;)R[a]===n?R.splice(a,N):a+=N;let o=e.indexOf(n);~o&&(e.splice(o,1),--r.lc||r.off())}},notify(n,o){wt++;let a=!R.length;for(let i of e)R.push(i,r.value,n,o);if(a){for(L=0;L<R.length;L+=N)R[L](R[L+1],R[L+2],R[L+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 Pt=5,M=6,H=10,St=(t,e,r,n)=>(t.events=t.events||{},t.events[r+H]||(t.events[r+H]=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+H](),delete t.events[r+H])});var be=1e3,Z=(t,e)=>St(t,n=>{let o=e(n);o&&t.events[M].push(o)},Pt,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]=[]}},be)},()=>{t.listen=o,t.off=a}});var $=(t={})=>{let e=b(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 ye=t=>t,_={},X={addEventListener(){},removeEventListener(){}};function Rt(){try{return typeof localStorage<"u"}catch{return!1}}Rt()&&(_=localStorage);var Ot={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"&&(X=Ot);function w(t,e=void 0,r={}){let n=r.encode||ye,o=r.decode||ye,a=b(e),i=a.set;a.set=s=>{let f=n(s);typeof f>"u"?delete _[t]:_[t]=f,i(s)};function u(s){s.key===t?s.newValue===null?i(e):i(o(s.newValue)):_[t]||i(e)}function c(){a.set(_[t]?o(_[t]):e)}return Z(a,()=>{if(c(),r.listen!==!1)return X.addEventListener(t,u,c),()=>{X.removeEventListener(t,u,c)}}),a}var Et="framerauth_v2_",ve=new TextEncoder,Lt=new TextDecoder;function ke(){let t=typeof window<"u"?window.location.hostname:"1f8cXd6c7b4a3vL4z5746oUgQ28190adbef";return ve.encode(Et+t)}function Tt(t){let e=ke(),r=ve.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 At(t){let e=Tt(t),r=Array.from(e,n=>String.fromCharCode(n)).join("");return btoa(r)}function xt(t){let e=ke(),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 Lt.decode(o)}function P({obfuscate:t}){return e=>{let r=JSON.stringify(e);return t&&(r=At(r)),r}}function S({deobfuscate:t,fallback:e,validator:r}){return n=>{try{if(!n)return e;t&&(n=xt(n));let o=JSON.parse(n);if(r){let a=r(o);return a===null?e:a}return o}catch{return e}}}var we=w("fa-project",null,{encode:P({obfuscate:!0}),decode:S({deobfuscate:!0,fallback:null})}),Pe=b(!1);var Se=w("fa-tags",[],{encode:P({obfuscate:!0}),decode:S({deobfuscate:!0,fallback:[]})}),Re=b(!1);function Oe(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 Ut(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:Oe(e.tags)}function _t(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 Ee(t){if(!t||typeof t!="object")return null;let e=t;return Oe(e.tags)||(e.tags=[]),Ut(e)?e:null}function Le(t){return _t(t)?t:null}function Dt(t){return!t||typeof t!="object"||Array.isArray(t)?!1:Object.entries(t).every(([e,r])=>typeof e=="string"&&typeof r=="boolean")}function Te(t){return!t||typeof t!="object"||Array.isArray(t)?{}:Dt(t)?t:{}}var Ae=w("fa-user",null,{encode:P({obfuscate:!0}),decode:S({deobfuscate:!0,fallback:null,validator:Ee})}),xe=b(!1);var Ue=w("fa-session",null,{encode:P({obfuscate:!0}),decode:S({deobfuscate:!0,fallback:null,validator:Le})}),_e=b(!1);var De=b(!0);var Fe="This page is restricted.",Ft={lock:`
|
|
1
|
+
"use strict";(()=>{var tt=Object.defineProperty,rt=Object.defineProperties,nt=Object.getOwnPropertyDescriptors,he=Object.getOwnPropertySymbols,ot=Object.prototype.hasOwnProperty,at=Object.prototype.propertyIsEnumerable,fe=(t,e,r)=>e in t?tt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,x=(t,e)=>{for(var r in e||(e={}))ot.call(e,r)&&fe(t,r,e[r]);if(he)for(var r of he(e))at.call(e,r)&&fe(t,r,e[r]);return t},U=(t,e)=>rt(t,nt(e)),it=class extends Error{constructor(t,e,r){super(e||t.toString(),{cause:r}),this.status=t,this.statusText=e,this.error=r}},st=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}},pe=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}},lt=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 ct(t){if(typeof t=="number")return new pe({type:"linear",attempts:t,delay:1e3});switch(t.type){case"linear":return new pe(t);case"exponential":return new lt(t);default:throw new Error("Invalid retry strategy")}}var dt=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},ut=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function ht(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 ut.test(n)?"json":r.has(n)||n.startsWith("text/")?"text":"blob"}function ft(t){try{return JSON.parse(t),!0}catch{return!1}}function be(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 me(t){try{return JSON.parse(t)}catch{return t}}function ge(t){return typeof t=="function"}function pt(t){if(t?.customFetchImpl)return t.customFetchImpl;if(typeof globalThis<"u"&&ge(globalThis.fetch))return globalThis.fetch;if(typeof window<"u"&&ge(window.fetch))return window.fetch;throw new Error("No fetch implementation found")}async function mt(t){let e=new Headers(t?.headers),r=await dt(t);for(let[n,o]of Object.entries(r||{}))e.set(n,o);if(!e.has("content-type")){let n=gt(t?.body);n&&e.set("content-type",n)}return e}function gt(t){return be(t)?"application/json":null}function bt(t){if(!t?.body)return null;let e=new Headers(t?.headers);if(be(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 yt(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 ve.includes(n)?n.toUpperCase():e?.body?"POST":"GET"}return e?.body?"POST":"GET"}function vt(t,e){let r;return!t?.signal&&t?.timeout&&(r=setTimeout(()=>e?.abort(),t?.timeout)),{abortTimeout:r,clearTimeout:()=>{r&&clearTimeout(r)}}}var wt=class ye extends Error{constructor(e,r){super(r||JSON.stringify(e,null,2)),this.issues=e,Object.setPrototypeOf(this,ye.prototype)}};async function kt(t,e){let r=await t["~standard"].validate(e);if(r.issues)throw new wt(r.issues);return r.value}var ve=["get","post","put","patch","delete"];function Pt(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];ve.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,Q]of v.entries()){let j=n[g];i=i.replace(Q,j)}}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 st(t,e),Q=pt(g),j=new AbortController,Je=(r=g.signal)!=null?r:j.signal,Ve=Pt(v,g),Ge=bt(g),Ke=await mt(g),Qe=yt(v,g),p=U(x({},g),{url:Ve,headers:Ke,body:Ge,method:Qe,signal:Je});for(let w of f.onRequest)if(w){let y=await w(p);y instanceof Object&&(p=y)}("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:Ye}=vt(g,j),d=await Q(p.url,p);Ye();let de={response:d,request:p};for(let w of f.onResponse)if(w){let y=await w(U(x({},de),{response:(o=e?.hookOptions)!=null&&o.cloneResponse?d.clone():d}));y instanceof Response?d=y:y instanceof Object&&(d=y.response)}if(d.ok){if(!(p.method!=="HEAD"))return{data:"",error:null};let y=ht(d),E={data:"",response:d,request:p};if(y==="json"||y==="text"){let O=await d.text(),et=await((a=p.jsonParser)!=null?a:me)(O);E.data=et}else E.data=await d[y]();p?.output&&p.output&&!p.disableValidation&&(E.data=await kt(p.output,E.data));for(let O of f.onSuccess)O&&await O(U(x({},E),{response:(i=e?.hookOptions)!=null&&i.cloneResponse?d.clone():d}));return e?.throw?E.data:{data:E.data,error:null}}let Ze=(u=e?.jsonParser)!=null?u:me,N=await d.text(),ue=ft(N),Y=ue?await Ze(N):null,Xe={response:d,responseText:N,request:p,error:U(x({},Y),{status:d.status,statusText:d.statusText})};for(let w of f.onError)w&&await w(U(x({},Xe),{response:(c=e?.hookOptions)!=null&&c.cloneResponse?d.clone():d}));if(e?.retry){let w=ct(e.retry),y=(s=e.retryAttempt)!=null?s:0;if(await w.shouldAttemptRetry(y,d)){for(let O of f.onRetry)O&&await O(de);let E=w.getDelay(y);return await new Promise(O=>setTimeout(O,E)),await h(t,U(x({},e),{retryAttempt:y+1}))}}if(e?.throw)throw new it(d.status,d.statusText,ue?Y:N);return{data:null,error:U(x({},Y),{status:d.status,statusText:d.statusText})}};var St="https://core.framerauth.com/v2",Rt="application/octet-stream",Et=t=>{if(t instanceof Blob)return t;let e=typeof FormData<"u"&&t instanceof FormData?t.get("file"):t?.file;if(!(e instanceof Blob))throw new Error("No image was provided");return e},H=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(`${St}/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`,o=this.authOptions();return await h(n,{...o,method:"POST",headers:{...o.headers,"Content-Type":Rt},body:Et(r)})},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=[],T=0,M=4,Ot=0,b=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=T+M;a<R.length;)R[a]===n?R.splice(a,M):a+=M;let o=e.indexOf(n);~o&&(e.splice(o,1),--r.lc||r.off())}},notify(n,o){Ot++;let a=!R.length;for(let i of e)R.push(i,r.value,n,o);if(a){for(T=0;T<R.length;T+=M)R[T](R[T+1],R[T+2],R[T+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 Lt=5,$=6,z=10,Tt=(t,e,r,n)=>(t.events=t.events||{},t.events[r+z]||(t.events[r+z]=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+z](),delete t.events[r+z])});var we=1e3,Z=(t,e)=>Tt(t,n=>{let o=e(n);o&&t.events[$].push(o)},Lt,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[$]=[],t.off=()=>{a(),setTimeout(()=>{if(t.active&&!t.lc){t.active=!1;for(let i of t.events[$])i();t.events[$]=[]}},we)},()=>{t.listen=o,t.off=a}});var I=(t={})=>{let e=b(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 ke=t=>t,_={},X={addEventListener(){},removeEventListener(){}};function At(){try{return typeof localStorage<"u"}catch{return!1}}At()&&(_=localStorage);var xt={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"&&(X=xt);function k(t,e=void 0,r={}){let n=r.encode||ke,o=r.decode||ke,a=b(e),i=a.set;a.set=s=>{let f=n(s);typeof f>"u"?delete _[t]:_[t]=f,i(s)};function u(s){s.key===t?s.newValue===null?i(e):i(o(s.newValue)):_[t]||i(e)}function c(){a.set(_[t]?o(_[t]):e)}return Z(a,()=>{if(c(),r.listen!==!1)return X.addEventListener(t,u,c),()=>{X.removeEventListener(t,u,c)}}),a}var Ut="framerauth_v2_",Pe=new TextEncoder,_t=new TextDecoder;function Se(){let t=typeof window<"u"?window.location.hostname:"1f8cXd6c7b4a3vL4z5746oUgQ28190adbef";return Pe.encode(Ut+t)}function Dt(t){let e=Se(),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 Ft(t){let e=Dt(t),r=Array.from(e,n=>String.fromCharCode(n)).join("");return btoa(r)}function Ct(t){let e=Se(),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 _t.decode(o)}function P({obfuscate:t}){return e=>{let r=JSON.stringify(e);return t&&(r=Ft(r)),r}}function S({deobfuscate:t,fallback:e,validator:r}){return n=>{try{if(!n)return e;t&&(n=Ct(n));let o=JSON.parse(n);if(r){let a=r(o);return a===null?e:a}return o}catch{return e}}}var Re=k("fa-project",null,{encode:P({obfuscate:!0}),decode:S({deobfuscate:!0,fallback:null})}),Ee=b(!1);var Oe=k("fa-tags",[],{encode:P({obfuscate:!0}),decode:S({deobfuscate:!0,fallback:[]})}),Le=b(!1);function Te(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 Bt(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:Te(e.tags)}function jt(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 Ae(t){if(!t||typeof t!="object")return null;let e=t;return Te(e.tags)||(e.tags=[]),Bt(e)?e:null}function xe(t){return jt(t)?t:null}function Nt(t){return!t||typeof t!="object"||Array.isArray(t)?!1:Object.entries(t).every(([e,r])=>typeof e=="string"&&typeof r=="boolean")}function Ue(t){return!t||typeof t!="object"||Array.isArray(t)?{}:Nt(t)?t:{}}var _e=k("fa-user",null,{encode:P({obfuscate:!0}),decode:S({deobfuscate:!0,fallback:null,validator:Ae})}),De=b(!1);var Fe=k("fa-session",null,{encode:P({obfuscate:!0}),decode:S({deobfuscate:!0,fallback:null,validator:xe})}),Ce=b(!1);var Be=b(!0);var je="This page is restricted.",Ht={lock:`
|
|
2
2
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16">
|
|
3
3
|
<path
|
|
4
4
|
d="M 2 7.5 L 14 7.5 L 14 12.5 C 14 14.157 12.657 15.5 11 15.5 L 5 15.5 C 3.343 15.5 2 14.157 2 12.5 Z"
|
|
@@ -174,11 +174,11 @@
|
|
|
174
174
|
opacity: 1;
|
|
175
175
|
background-color: var(--button-background-active-color);
|
|
176
176
|
}
|
|
177
|
-
`;shadow;config={heading:"",message:
|
|
177
|
+
`;shadow;config={heading:"",message:je,actionLabel:"",actionHref:"",icon:"lock"};onAction;handleAction=()=>{this.onAction?.()};static get observedAttributes(){return["heading","message","action-label","action-href","icon"]}constructor(){super(),this.shadow=this.attachShadow({mode:"closed"})}attributeChangedCallback(e,r,n){switch(e){case"heading":this.config.heading=n||"";break;case"message":this.config.message=n||je;break;case"action-label":this.config.actionLabel=n||"";break;case"action-href":this.config.actionHref=n||"";break;case"icon":this.config.icon=n==="warning"?"warning":"lock";break}this.isConnected&&this.render()}connectedCallback(){this.style.fontFamily=getComputedStyle(document.body).fontFamily,this.render(),this.focusInitial()}focusInitial(){(this.shadow.querySelector(".btn--action")??this.shadow.querySelector(".section"))?.focus()}renderAction(){return this.config.actionLabel?this.config.actionHref?'<a class="btn--action" target="_blank" rel="noopener noreferrer"></a>':this.onAction?'<button class="btn--action" type="button"></button>':"":""}render(){let e=this.config.heading.length>0,r=e?'aria-labelledby="fa-overlay-heading" aria-describedby="fa-overlay-description"':'aria-labelledby="fa-overlay-description"',n=document.createElement("template");n.innerHTML=`
|
|
178
178
|
<style>${t.styles}</style>
|
|
179
179
|
<div class="section" role="dialog" aria-modal="true" tabindex="-1" ${r}>
|
|
180
180
|
<main>
|
|
181
|
-
<div class="icon" aria-hidden="true">${
|
|
181
|
+
<div class="icon" aria-hidden="true">${Ht[this.config.icon]}</div>
|
|
182
182
|
<div id="container">
|
|
183
183
|
${e?'<div class="heading" id="fa-overlay-heading"></div>':""}
|
|
184
184
|
<div class="description" id="fa-overlay-description"></div>
|
|
@@ -186,4 +186,4 @@
|
|
|
186
186
|
</div>
|
|
187
187
|
</main>
|
|
188
188
|
</div>
|
|
189
|
-
`,this.shadow.replaceChildren(n.content.cloneNode(!0));let o=this.shadow.querySelector(".heading");o&&(o.textContent=this.config.heading);let a=this.shadow.querySelector(".description");a&&(a.textContent=this.config.message);let i=this.shadow.querySelector(".btn--action");i&&(i.textContent=this.config.actionLabel,i instanceof HTMLAnchorElement?i.href=this.config.actionHref:i.addEventListener("click",this.handleAction))}},te="fa-overlay";function Ct(){customElements.get(te)||customElements.define(te,ee)}function z(t){Ct();let e=document.createElement(te);return t.onAction&&(e.onAction=t.onAction),t.heading&&e.setAttribute("heading",t.heading),e.setAttribute("message",t.message),t.actionLabel&&e.setAttribute("action-label",t.actionLabel),t.actionHref&&e.setAttribute("action-href",t.actionHref),t.icon&&e.setAttribute("icon",t.icon),t.theme&&e.setAttribute("theme",t.theme),e}function T(){document.body.style.visibility="hidden"}function A(){document.body.style.visibility="visible"}var Bt="/sign-in",jt="This page is restricted.",I=null;function W(t,e){let n=document.querySelector(`meta[name="${t}"]`)?.content.trim();return n||e&&document.querySelector(`meta[name="${e}"]`)?.content.trim()||null}function Nt(t){return t?t.split(",").map(e=>e.trim()).filter(Boolean):[]}function re(){return I||(I={errorPath:m(W("fa:error-path","framerauth:error-path")??Bt),boostPatterns:Nt(W("fa:boost","framerauth:boost")),router:W("fa:router"),accessDeniedMessage:W("fa:access-denied-message")??jt},I)}function Mt(){return re().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 Ht(t,e){return m(t)===m(e)}function q(t=window.location.pathname){return m(t)==="/"}function D(t=window.location.pathname,e=Mt()){return Ht(t,e)}function Ce(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 J=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(D(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 D(e,this.errorPath)}redirectToError(){if(this.isOnErrorPage()){A();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)||(T(),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)||(T(),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(T(),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)){T(),this.renderLockedOverlay();return}this.removeLockedOverlay(),A()},window.addEventListener("popstate",this.fallbackPopStateHandler))}stopObservingFallbackPopState(){this.fallbackPopStateHandler&&(window.removeEventListener("popstate",this.fallbackPopStateHandler),this.fallbackPopStateHandler=null)}renderLockedOverlay(){if(this.lockedOverlay)return;this.startObservingFallbackPopState();let e=z({message:this.accessDeniedMessage,actionLabel:"Back",onAction:()=>history.back()});e.id="fa-access-denied",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(),A()}};var Be=w("fa-bookmarks",$(),{encode:P({obfuscate:!0}),decode:S({deobfuscate:!0,fallback:{},validator:Te})}),je=b(!1);var Ne=w("fa-bearer-token",null,{encode:P({obfuscate:!0}),decode:S({deobfuscate:!0,fallback:null})});var Me=(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.10");var $t="/v2",zt=0,He="https://frameauth.com/guides-v2/configuration-error",l=new j({data:{user:Ae,project:we,tags:Se,bookmarks:Be,session:Ue,bearerToken:Ne},state:{initializing:De,userLoading:xe,projectLoading:Pe,tagsLoading:Re,bookmarksLoading:je,sessionLoading:_e}});window.FramerAuth=l;var F=re(),$e=Ce(F.boostPatterns),V=null,ne=!1;function oe(t){return t?.status===404}function ae(){if(ne)return;if(ne=!0,l.data.project.set(null),l.state.projectLoading.set(!1),q()){console.warn(`FramerAuth: this domain is not linked to a FramerAuth project. The home page is shown signed-out; other pages show a warning. Fix: ${He}`),V||K(),A();return}V?.stop(),V=null,T();let t=z({heading:"FrameAuth can\u2019t verify this domain",message:"This site has FrameAuth installed which handles sign-up, sign-in, user accounts, and member-only content. Access stays locked until this domain is verified.",actionLabel:"Fix this",actionHref:He,icon:"warning",theme:"warning"});t.id="fa-project-not-configured",document.documentElement.appendChild(t)}function It(){return D()?!0:l.data.project.get()!==null&&$e(window.location.pathname)}function G(t){let e=ze(t);if(!e)throw new Error("Unable to initialize FramerAuth: project tenantHost is missing");l.updateBaseURL(`https://${e}${$t}`),l.updateAuthMode(Wt(t))}function Wt(t){return t.sessionTransport==="bearer"}function ze(t){if(t.customDomain)return t.customDomain;let e=qt(t);return e?`${t.slug}.${e}`:null}function qt(t){return zt||t.tenantHost||null}function ie(){l.api.fetchBookmarks().then(({data:t})=>{l.data.bookmarks.set(t??{})})}function Jt(){return new J({hasAccess:t=>Me(l,t),isPublicPath:t=>q(t)||$e(t),errorPath:F.errorPath,forceFallbackOverlay:F.router==="overlay",accessDeniedMessage:F.accessDeniedMessage,onError:t=>{console.error("[Router] Error in router:",t)}})}function K(){let t=Jt();return t.checkAccess(window.location.pathname)?(t.start(),V=t,!0):(t.handleAccessDenied(),!1)}function Vt(){let t=l.data.project.get();return t&&ze(t)?(G(t),l.api.fetchProject().then(e=>{e.data?(l.data.project.set(e.data),G(e.data)):oe(e.error)&&ae()}).catch(e=>{console.error("Failed to refresh FramerAuth project:",e)}),l.handleOTTFromURL().then(()=>ne?null:l.auth.getSession()).then(e=>{e&&e.data!==null&&ie()}).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),G(e.data),l.state.projectLoading.set(!1),l.handleOTTFromURL().then(()=>l.auth.getSession());if(oe(e.error)){ae();return}l.state.projectLoading.set(!1)}).then(e=>{e&&e.data!==null&&ie()}).catch(e=>{console.error("Failed to initialize FramerAuth in the background:",e),l.state.projectLoading.set(!1)})),K()}async function Gt(){T();let t=l.data.project.get(),e=await l.api.fetchProject();if(e.data)t=e.data,l.data.project.set(t);else{if(oe(e.error))return ae(),!1;if(!t)throw new Error(e.error.message||"Unable to load FramerAuth project!")}G(t),await l.handleOTTFromURL(),(await l.auth.getSession()).data!==null&&ie();let n=K();return n&&A(),n}async function Kt(){l.state.initializing.set(!0);try{(It()?Vt():await Gt())&&window.dispatchEvent(new CustomEvent("framerauth:initialized"))}catch(t){console.error("Failed to initialize FramerAuth:",t),q()||D(window.location.pathname,F.errorPath)?(K(),A()):window.location.replace(F.errorPath),window.dispatchEvent(new CustomEvent("framerauth:initialization-failed",{detail:{error:t}}))}finally{l.state.initializing.set(!1)}}Kt();})();
|
|
189
|
+
`,this.shadow.replaceChildren(n.content.cloneNode(!0));let o=this.shadow.querySelector(".heading");o&&(o.textContent=this.config.heading);let a=this.shadow.querySelector(".description");a&&(a.textContent=this.config.message);let i=this.shadow.querySelector(".btn--action");i&&(i.textContent=this.config.actionLabel,i instanceof HTMLAnchorElement?i.href=this.config.actionHref:i.addEventListener("click",this.handleAction))}},te="fa-overlay";function Mt(){customElements.get(te)||customElements.define(te,ee)}function B(t){Mt();let e=document.createElement(te);return t.onAction&&(e.onAction=t.onAction),t.heading&&e.setAttribute("heading",t.heading),e.setAttribute("message",t.message),t.actionLabel&&e.setAttribute("action-label",t.actionLabel),t.actionHref&&e.setAttribute("action-href",t.actionHref),t.icon&&e.setAttribute("icon",t.icon),t.theme&&e.setAttribute("theme",t.theme),e}function L(){document.body.style.visibility="hidden"}function A(){document.body.style.visibility="visible"}var $t="/sign-in",zt="This page is restricted.",W=null;function q(t,e){let n=document.querySelector(`meta[name="${t}"]`)?.content.trim();return n||e&&document.querySelector(`meta[name="${e}"]`)?.content.trim()||null}function It(t){return t?t.split(",").map(e=>e.trim()).filter(Boolean):[]}function re(){return W||(W={errorPath:m(q("fa:error-path","framerauth:error-path")??$t),boostPatterns:It(q("fa:boost","framerauth:boost")),router:q("fa:router"),accessDeniedMessage:q("fa:access-denied-message")??zt},W)}function Wt(){return re().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 qt(t,e){return m(t)===m(e)}function J(t=window.location.pathname){return m(t)==="/"}function D(t=window.location.pathname,e=Wt()){return qt(t,e)}function Ne(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 V=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(D(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 D(e,this.errorPath)}redirectToError(){if(this.isOnErrorPage()){A();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)||(L(),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)||(L(),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(L(),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)){L(),this.renderLockedOverlay();return}this.removeLockedOverlay(),A()},window.addEventListener("popstate",this.fallbackPopStateHandler))}stopObservingFallbackPopState(){this.fallbackPopStateHandler&&(window.removeEventListener("popstate",this.fallbackPopStateHandler),this.fallbackPopStateHandler=null)}renderLockedOverlay(){if(this.lockedOverlay)return;this.startObservingFallbackPopState();let e=B({message:this.accessDeniedMessage,actionLabel:"Back",onAction:()=>history.back()});e.id="fa-access-denied",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(),A()}};var He=k("fa-bookmarks",I(),{encode:P({obfuscate:!0}),decode:S({deobfuscate:!0,fallback:{},validator:Ue})}),Me=b(!1);var $e=k("fa-bearer-token",null,{encode:P({obfuscate:!0}),decode:S({deobfuscate:!0,fallback:null})});var ze=(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.12");var Jt="/v2",Vt=0,Ie="https://frameauth.com/guides-v2/configuration-error",Gt="https://app.frameauth.com",l=new H({data:{user:_e,project:Re,tags:Oe,bookmarks:He,session:Fe,bearerToken:$e},state:{initializing:Be,userLoading:De,projectLoading:Ee,tagsLoading:Le,bookmarksLoading:Me,sessionLoading:Ce}});window.FramerAuth=l;var F=re(),We=Ne(F.boostPatterns),C=null,ne=!1,oe=!1;function ae(t){return t?.status===404}function ie(t){return t?.status===403}function Kt(){return ne||oe}function se(t){if(oe)return;oe=!0,l.data.project.set(null),l.state.projectLoading.set(!1),C?.stop(),C=null,L();let e=B({heading:"FrameAuth - Action required",message:t??"",actionLabel:"Open FrameAuth dashboard",actionHref:Gt,icon:"warning",theme:"warning"});e.id="fa-project-suspended",document.documentElement.appendChild(e)}function le(){if(ne)return;if(ne=!0,l.data.project.set(null),l.state.projectLoading.set(!1),J()){console.warn(`FramerAuth: this domain is not linked to a FramerAuth project. The home page is shown signed-out; other pages show a warning. Fix: ${Ie}`),C||K(),A();return}C?.stop(),C=null,L();let t=B({heading:"FrameAuth can\u2019t verify this domain",message:"This site has FrameAuth installed which handles sign-up, sign-in, user accounts, and member-only content. Access stays locked until this domain is verified.",actionLabel:"Fix this",actionHref:Ie,icon:"warning",theme:"warning"});t.id="fa-project-not-configured",document.documentElement.appendChild(t)}function Qt(){return D()?!0:l.data.project.get()!==null&&We(window.location.pathname)}function G(t){let e=qe(t);if(!e)throw new Error("Unable to initialize FramerAuth: project tenantHost is missing");l.updateBaseURL(`https://${e}${Jt}`),l.updateAuthMode(Yt(t))}function Yt(t){return t.sessionTransport==="bearer"}function qe(t){if(t.customDomain)return t.customDomain;let e=Zt(t);return e?`${t.slug}.${e}`:null}function Zt(t){return Vt||t.tenantHost||null}function ce(){l.api.fetchBookmarks().then(({data:t})=>{l.data.bookmarks.set(t??{})})}function Xt(){return new V({hasAccess:t=>ze(l,t),isPublicPath:t=>J(t)||We(t),errorPath:F.errorPath,forceFallbackOverlay:F.router==="overlay",accessDeniedMessage:F.accessDeniedMessage,onError:t=>{console.error("[Router] Error in router:",t)}})}function K(){let t=Xt();return t.checkAccess(window.location.pathname)?(t.start(),C=t,!0):(t.handleAccessDenied(),!1)}function er(){let t=l.data.project.get();return t&&qe(t)?(G(t),l.api.fetchProject().then(e=>{e.data?(l.data.project.set(e.data),G(e.data)):ae(e.error)?le():ie(e.error)&&se(e.error.message)}).catch(e=>{console.error("Failed to refresh FramerAuth project:",e)}),l.handleOTTFromURL().then(()=>Kt()?null:l.auth.getSession()).then(e=>{e&&e.data!==null&&ce()}).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),G(e.data),l.state.projectLoading.set(!1),l.handleOTTFromURL().then(()=>l.auth.getSession());if(ae(e.error)){le();return}if(ie(e.error)){se(e.error.message);return}l.state.projectLoading.set(!1)}).then(e=>{e&&e.data!==null&&ce()}).catch(e=>{console.error("Failed to initialize FramerAuth in the background:",e),l.state.projectLoading.set(!1)})),K()}async function tr(){L();let t=l.data.project.get(),e=await l.api.fetchProject();if(e.data)t=e.data,l.data.project.set(t);else{if(ae(e.error))return le(),!1;if(ie(e.error))return se(e.error.message),!1;if(!t)throw new Error(e.error.message||"Unable to load FramerAuth project!")}G(t),await l.handleOTTFromURL(),(await l.auth.getSession()).data!==null&&ce();let n=K();return n&&A(),n}async function rr(){l.state.initializing.set(!0);try{(Qt()?er():await tr())&&window.dispatchEvent(new CustomEvent("framerauth:initialized"))}catch(t){console.error("Failed to initialize FramerAuth:",t),J()||D(window.location.pathname,F.errorPath)?(K(),A()):window.location.replace(F.errorPath),window.dispatchEvent(new CustomEvent("framerauth:initialization-failed",{detail:{error:t}}))}finally{l.state.initializing.set(!1)}}rr();})();
|
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.10");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.12");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};
|