@strands.gg/accui 2.16.0 → 2.17.10

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.
Files changed (38) hide show
  1. package/dist/StrandsUIPlugin-Bwc7jBcb.cjs.js +143 -0
  2. package/dist/StrandsUIPlugin-RTFzvRED.es.js +20536 -0
  3. package/dist/accui.css +1 -1
  4. package/dist/index.cjs.js +5 -1
  5. package/dist/index.es.js +8822 -12491
  6. package/dist/nuxt/module.cjs.js +23 -1
  7. package/dist/nuxt/module.es.js +58 -82
  8. package/dist/nuxt/runtime/composables/useAuthenticatedFetch.cjs.js +1 -1
  9. package/dist/nuxt/runtime/composables/useAuthenticatedFetch.es.js +82 -111
  10. package/dist/nuxt/runtime/composables/useStrandsAuth.cjs.js +1 -1
  11. package/dist/nuxt/runtime/composables/useStrandsAuth.es.js +30 -46
  12. package/dist/nuxt/runtime/middleware/auth.global.cjs.js +1 -1
  13. package/dist/nuxt/runtime/middleware/auth.global.es.js +28 -44
  14. package/dist/nuxt/runtime/plugin.client.cjs.js +1 -1
  15. package/dist/nuxt/runtime/plugin.client.es.js +10 -19
  16. package/dist/nuxt/runtime/plugin.server.cjs.js +1 -1
  17. package/dist/nuxt/runtime/plugin.server.es.js +8 -10
  18. package/dist/nuxt/runtime/plugins/auth-interceptor.client.cjs.js +1 -1
  19. package/dist/nuxt/runtime/plugins/auth-interceptor.client.es.js +27 -48
  20. package/dist/nuxt/types.d.ts +1 -0
  21. package/dist/nuxt.cjs.js +1 -1
  22. package/dist/nuxt.es.js +9 -9
  23. package/dist/types/index.d.ts +5 -0
  24. package/dist/useStrandsAuth-DSBvF4ky.es.js +653 -0
  25. package/dist/useStrandsAuth-EqbzuNAn.cjs.js +1 -0
  26. package/dist/useStrandsConfig-B5kp4aF9.cjs.js +1 -0
  27. package/dist/useStrandsConfig-CMKVW1p3.es.js +210 -0
  28. package/dist/vite.cjs.js +29 -1
  29. package/dist/vite.es.js +58 -75
  30. package/dist/vue/utils/modalStack.d.ts +3 -0
  31. package/dist/webcomponents/define-element.d.ts +3 -2
  32. package/package.json +2 -2
  33. package/dist/StrandsUIPlugin-C9rrMU2i.cjs.js +0 -1
  34. package/dist/StrandsUIPlugin-tl7L52hZ.es.js +0 -26130
  35. package/dist/useStrandsAuth-BCnUxo-R.es.js +0 -915
  36. package/dist/useStrandsAuth-DoJxpNLb.cjs.js +0 -1
  37. package/dist/useStrandsConfig-Sr6NG90B.cjs.js +0 -1
  38. package/dist/useStrandsConfig-fRu-OG08.es.js +0 -248
@@ -1 +0,0 @@
1
- "use strict";const e=require("vue"),t=require("./useStrandsConfig-Sr6NG90B.cjs.js"),n=new class{cache=new Map;DEFAULT_TTL=3e5;async fetch(e,t,n=this.DEFAULT_TTL){const a=Date.now(),i=this.cache.get(e);if(i&&a-i.timestamp<i.ttl)return i.promise;this.cleanExpired();const r=t().finally(()=>{setTimeout(()=>{this.cache.delete(e)},n)});return this.cache.set(e,{promise:r,timestamp:a,ttl:n}),r}clear(){this.cache.clear()}invalidate(e){this.cache.delete(e)}cleanExpired(){const e=Date.now();for(const[t,n]of this.cache.entries())e-n.timestamp>n.ttl&&this.cache.delete(t)}getStats(){return{size:this.cache.size,entries:Array.from(this.cache.keys())}}},a=function(){let e=null;return(...t)=>{e&&clearTimeout(e),e=setTimeout(()=>{((e,t)=>{"undefined"!=typeof window&&localStorage.setItem(e,t)})(...t)},300)}}(),i=e=>({id:e.id,email:e.email,firstName:e.first_name||e.firstName||"",lastName:e.last_name||e.lastName||"",avatar:e.avatar_url||e.avatar,mfaEnabled:e.mfa_enabled??e.mfaEnabled??0,emailVerified:e.email_verified??e.emailVerified??0,passwordUpdatedAt:e.password_updated_at||e.passwordUpdatedAt,settings:e.settings||{},xp:e.xp||0,level:e.level||1,next_level_xp:e.next_level_xp||e.next_level_xp||4,username:e.username,usernameLastChangedAt:e.username_last_changed_at||e.usernameLastChangedAt,createdAt:e.created_at||e.createdAt,updatedAt:e.updated_at||e.updatedAt||(new Date).toISOString()}),r={currentUser:e.ref(null),currentSession:e.ref(null),loadingStates:e.ref({initializing:1,signingIn:0,signingUp:0,signingOut:0,refreshingToken:0,sendingMfaEmail:0,verifyingMfa:0,loadingProfile:0}),isInitialized:e.ref(0),mfaRequired:e.ref(0),mfaSessionId:e.ref(null),availableMfaMethods:e.ref([])};let o=null,s=null;exports.useStrandsAuth=function(){const{getUrl:d,config:c}=t.useStrandsConfig(),{fetch:l,clear:u,invalidate:h}={fetch:n.fetch.bind(n),clear:n.clear.bind(n),invalidate:n.invalidate.bind(n),getStats:n.getStats.bind(n)},{currentUser:f,currentSession:w,loadingStates:y,isInitialized:g,mfaRequired:m,mfaSessionId:p,availableMfaMethods:S}=r,_=()=>{if(f.value=null,w.value=null,m.value=0,p.value=null,S.value=[],"undefined"!=typeof window&&(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user")),D(),s=null,u(),"undefined"!=typeof window&&c.value?.onSignOutUrl){const e=window.location.pathname+window.location.search,t=c.value.onSignOutUrl;e!==t&&(window.location.href=t)}},T=e.computed(()=>y.value.initializing),E=e.computed(()=>y.value.signingIn),O=e.computed(()=>y.value.signingUp),v=e.computed(()=>y.value.signingOut),A=e.computed(()=>y.value.refreshingToken),$=e.computed(()=>y.value.sendingMfaEmail),N=e.computed(()=>y.value.verifyingMfa);e.computed(()=>y.value.loadingProfile);const b=e.computed(()=>y.value.signingIn||y.value.signingUp||y.value.signingOut||y.value.refreshingToken||y.value.sendingMfaEmail||y.value.verifyingMfa||y.value.loadingProfile),k=e.computed(()=>y.value.initializing||b.value),C=e.computed(()=>{const e=y.value;return e.initializing?"Checking authentication...":e.signingIn?"Signing you in...":e.signingUp?"Creating your account...":e.signingOut?"Signing you out...":e.refreshingToken?"Refreshing session...":e.sendingMfaEmail?"Sending verification code...":e.verifyingMfa?"Verifying code...":e.loadingProfile?"Loading profile...":"Loading..."}),J=()=>{const e={};return w.value?.accessToken&&(e.Authorization=`Bearer ${w.value.accessToken}`),w.value?.refreshToken&&(e["x-refresh-token"]=w.value.refreshToken),e},P=e.computed(()=>null!==f.value),F=async()=>{if(!w.value?.refreshToken)return 0;if(s)return await s;s=(async()=>{y.value.refreshingToken=1;try{const e=await fetch(d("refresh"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh_token:w.value.refreshToken})});if(!e.ok){if(401===e.status)return _(),0;throw new Error(`Token refresh failed: ${e.status} ${e.statusText}`)}const t=await e.json();t.user&&(f.value=i(t.user),f.value&&"undefined"!=typeof window&&localStorage.setItem("strands_auth_user",JSON.stringify(f.value)));const n={accessToken:t.access_token,refreshToken:t.refresh_token,expiresAt:new Date(Date.now()+3e5),userId:t.user?.id||f.value?.id};return w.value=n,"undefined"!=typeof window&&localStorage.setItem("strands_auth_session",JSON.stringify(n)),U(),h(`sessions:${w.value.accessToken.slice(0,20)}`),1}catch(e){return _(),0}finally{y.value.refreshingToken=0}})();const e=await s;return s=null,e},M=async e=>{try{e.user&&(f.value=i(e.user));const t={accessToken:e.access_token,refreshToken:e.refresh_token,expiresAt:new Date(Date.now()+3e5),userId:f.value?.id||e.user?.id};w.value=t,"undefined"!=typeof window&&(localStorage.setItem("strands_auth_session",JSON.stringify(t)),f.value&&localStorage.setItem("strands_auth_user",JSON.stringify(f.value))),U()}catch(t){}},U=()=>{if(o&&clearTimeout(o),!w.value)return;if("undefined"!=typeof document&&"hidden"===document.visibilityState)return;const e=new Date,t=w.value.expiresAt.getTime()-e.getTime()-6e4;t<=0?F():o=setTimeout(async()=>{"undefined"!=typeof document&&"visible"!==document.visibilityState||await F()&&U()},t)},D=()=>{o&&(clearTimeout(o),o=null)},I=async()=>{if(!g.value){y.value.initializing=1;try{if("undefined"!=typeof window){const t=localStorage.getItem("strands_auth_session"),n=localStorage.getItem("strands_auth_user");if(t&&n)try{const e=JSON.parse(t),a=JSON.parse(n);e.expiresAt=new Date(e.expiresAt),e.expiresAt<=new Date&&e.refreshToken?(w.value=e,f.value=a,await F()||_()):e.expiresAt>new Date?(w.value=e,f.value=a,U()):(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user"))}catch(e){localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user")}}g.value=1,await new Promise(e=>setTimeout(e,50))}catch(e){}finally{y.value.initializing=0}}};"undefined"!=typeof document&&document.addEventListener("visibilitychange",()=>{"visible"===document.visibilityState&&w.value?(U(),j()):"hidden"===document.visibilityState&&D()}),"undefined"!=typeof window&&window.addEventListener("storage",e=>{"strands_auth_session"!==e.key&&"strands_auth_user"!==e.key||!e.newValue&&f.value&&_()});const j=()=>{if("undefined"!=typeof window&&f.value&&w.value){const e=localStorage.getItem("strands_auth_session"),t=localStorage.getItem("strands_auth_user");e&&t||_()}},R=()=>{D(),u()};try{e.getCurrentInstance()&&e.onUnmounted(R)}catch(z){}return g.value||I(),{user:e.computed(()=>f.value),currentUser:e.computed(()=>f.value),currentSession:e.computed(()=>w.value),isAuthenticated:P,isLoading:e.computed(()=>k.value||!g.value),loading:b,loadingMessage:C,isInitializing:T,isSigningIn:E,isSigningUp:O,isSigningOut:v,isRefreshingToken:A,isSendingMfaEmail:$,isVerifyingMfa:N,mfaRequired:e.computed(()=>m.value),mfaSessionId:e.computed(()=>p.value),availableMfaMethods:e.computed(()=>S.value),signIn:async e=>{y.value.signingIn=1;try{m.value=0,p.value=null,S.value=[];const t={"Content-Type":"application/json"};"undefined"!=typeof window&&window.location&&(t.Origin=window.location.origin);const n=await fetch(d("signIn"),{method:"POST",headers:t,body:JSON.stringify(e)});if(!n.ok)throw 401===n.status?new Error("Invalid email or password"):403===n.status?new Error("Please verify your email address before signing in"):new Error(`Sign in failed: ${n.status} ${n.statusText}`);const a=await n.json();if(a.mfa_required){m.value=1,p.value=a.mfa_session_id||null;const e=(a.available_mfa_methods||[]).map(e=>{let t=`${e.device_type.charAt(0).toUpperCase()+e.device_type.slice(1)} Authentication`;return"hardware"===e.device_type?t=e.device_name||"Security Key":"totp"===e.device_type?t=e.device_name||"Authenticator App":"email"===e.device_type&&(t=e.device_name||"Email Verification"),{id:e.device_id,device_type:e.device_type,device_name:e.device_name||t,is_active:1,created_at:(new Date).toISOString(),last_used_at:e.last_used_at,credential_id:e.credential_id,device_info:e.device_info}});return S.value=e,y.value.signingIn=0,a}return await M(a),a}catch(t){throw t}finally{y.value.signingIn=0}},signUp:async e=>{y.value.signingUp=1;try{throw new Error("Sign up not implemented - please integrate with auth SDK")}finally{y.value.signingUp=0}},signOut:async()=>{y.value.signingOut=1;try{D(),s=null,u(),f.value=null,w.value=null,m.value=0,p.value=null,S.value=[],"undefined"!=typeof window&&(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user"))}finally{y.value.signingOut=0}},refreshToken:F,fetchProfile:async()=>{const e=`profile:${w.value.accessToken.slice(0,20)}`;y.value.loadingProfile=1;try{return await l(e,async()=>{const e=await fetch(d("profile"),{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${w.value?.accessToken}`}});if(!e.ok)throw 401===e.status?new Error("Authentication expired. Please sign in again."):new Error(`Failed to fetch profile: ${e.status} ${e.statusText}`);const t=await e.json();return f.value=i(t),f.value&&"undefined"!=typeof window&&localStorage.setItem("strands_auth_user",JSON.stringify(f.value)),f.value})}finally{y.value.loadingProfile=0}},updateProfile:async e=>{y.value.loadingProfile=1;try{const t=await fetch(d("profile"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${w.value.accessToken}`},body:JSON.stringify({first_name:e.firstName,last_name:e.lastName})});if(!t.ok)throw 401===t.status?new Error("Authentication expired. Please sign in again."):new Error(`Profile update failed: ${t.status} ${t.statusText}`);const n=await t.json();return f.value=i(n),f.value&&a("strands_auth_user",JSON.stringify(f.value)),f.value}finally{y.value.loadingProfile=0}},updateUserSettings:async e=>{y.value.loadingProfile=1;try{const t=await fetch(d("settings"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${w.value.accessToken}`},body:JSON.stringify({settings:e})});if(!t.ok)throw 401===t.status?new Error("Authentication expired. Please sign in again."):new Error(`Settings update failed: ${t.status} ${t.statusText}`);const n=await t.json();return f.value=i(n),f.value&&a("strands_auth_user",JSON.stringify(f.value)),f.value}finally{y.value.loadingProfile=0}},changeEmail:async(e,t)=>{y.value.loadingProfile=1;try{const n=await fetch(d("changeEmail"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${w.value.accessToken}`},body:JSON.stringify({new_email:e,password:t})});if(!n.ok){if(401===n.status)throw new Error("Authentication expired. Please sign in again.");{const e=await n.json().catch(()=>({}));throw new Error(e.message||`Email change failed: ${n.status} ${n.statusText}`)}}const a=await n.json();return f.value&&(f.value={...f.value,email:e,emailVerified:0,updatedAt:(new Date).toISOString()},"undefined"!=typeof window&&localStorage.setItem("strands_auth_user",JSON.stringify(f.value))),a}finally{y.value.loadingProfile=0}},changeUsername:async e=>{y.value.loadingProfile=1;try{const t=await fetch(d("changeUsername"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${w.value.accessToken}`},body:JSON.stringify({username:e})});if(!t.ok){const e=await t.json().catch(()=>({}));if(409===t.status)throw new Error("Username is already taken");if(e.cooldown_end)throw new Error(`You can only change your username once every 30 days. You can change it again on ${new Date(e.cooldown_end).toLocaleDateString()}`);throw new Error(e.message||`Username change failed: ${t.status} ${t.statusText}`)}const n=await t.json();return f.value&&(f.value={...f.value,username:e,usernameLastChangedAt:(new Date).toISOString(),updatedAt:(new Date).toISOString()},"undefined"!=typeof window&&localStorage.setItem("strands_auth_user",JSON.stringify(f.value))),n}finally{y.value.loadingProfile=0}},getUsernameCooldown:async()=>{const e=await fetch(d("usernameCooldown"),{method:"GET",headers:{Authorization:`Bearer ${w.value.accessToken}`}});if(!e.ok)throw new Error(`Failed to get username cooldown: ${e.status} ${e.statusText}`);return e.json()},checkUsernameAvailability:async e=>{const t=d("checkUsernameAvailability").replace("{username}",encodeURIComponent(e)),n=await fetch(t,{method:"GET",headers:{"Content-Type":"application/json"}});if(!n.ok)throw new Error(`Failed to check username availability: ${n.status} ${n.statusText}`);return n.json()},getUserSessions:async()=>{const e=`sessions:${w.value?.accessToken?.slice(0,20)||"no-token"}`;try{return await l(e,async()=>{const e=J(),t=await fetch(d("sessions"),{method:"GET",headers:e});if(!t.ok)throw await t.text(),new Error(`Failed to get user sessions: ${t.status} ${t.statusText}`);return t.json()},12e4)}catch(t){throw t}},getSessionStats:async()=>{const e=await fetch(d("sessionsStats"),{method:"GET",headers:J()});if(!e.ok)throw new Error(`Failed to get session stats: ${e.status} ${e.statusText}`);return e.json()},revokeSession:async e=>{const t=d("sessionRevoke").replace("{session_id}",encodeURIComponent(e)),n=await fetch(t,{method:"POST",headers:J()});if(!n.ok)throw new Error(`Failed to revoke session: ${n.status} ${n.statusText}`);return 200===n.status},revokeAllOtherSessions:async()=>{const e=await fetch(d("sessionsRevokeAll"),{method:"POST",headers:J()});if(!e.ok)throw new Error(`Failed to revoke all other sessions: ${e.status} ${e.statusText}`);return 200===e.status},initialize:I,setAuthData:M,verifyMfa:async(e,t,n=0)=>{if(!p.value)throw new Error("No MFA session available");y.value.verifyingMfa=1;try{const a=d(n?"mfaBackupCodeVerify":"mfaSigninVerify"),i=n?{mfa_session_id:p.value,backup_code:t}:{mfa_session_id:p.value,device_id:e,code:t},r=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!r.ok){const e=await r.text();let t="MFA verification failed";try{const n=JSON.parse(e);t=n.message||n.error||e}catch{t=e||"MFA verification failed"}throw new Error(t)}const o=await r.json();return m.value=0,p.value=null,S.value=[],await M(o),o}finally{y.value.verifyingMfa=0}},sendMfaEmailCode:async e=>{if(!p.value)throw new Error("No MFA session available");y.value.sendingMfaEmail=1;try{const t=await fetch(d("mfaSigninSendEmail"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mfa_session_id:p.value,device_id:e})});if(!t.ok){const e=await t.text();let n="Failed to send MFA email code";try{const t=JSON.parse(e);n=t.message||t.error||e}catch{n=e||"Failed to send MFA email code"}throw new Error(n)}return await t.json()}finally{y.value.sendingMfaEmail=0}},getMfaWebAuthnChallenge:async e=>{if(!p.value)throw new Error("No MFA session available");const t=await fetch(d("mfaWebAuthnChallenge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mfa_session_id:p.value,device_id:e})});if(!t.ok){const e=await t.text();let n="Failed to get WebAuthn challenge";try{const t=JSON.parse(e);n=t.message||t.error||e}catch{n=e||n}throw new Error(n)}return t.json()},registerHardwareKey:async(e,t,n="hardware")=>{const a=await fetch(d("mfaHardwareStartRegistration"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${w.value.accessToken}`},body:JSON.stringify({device_name:e,device_type:n})});if(!a.ok){const e=await a.text();let t="Failed to start hardware key registration";try{const n=JSON.parse(e);t=n.message||n.error||e}catch{t=e||"Failed to start hardware key registration"}throw new Error(t)}return a.json()},completeHardwareKeyRegistration:async(e,t,n)=>{const a=await fetch(d("mfaHardwareCompleteRegistration"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${w.value.accessToken}`},body:JSON.stringify({device_id:e,credential:t})});if(!a.ok){const e=await a.text();let t="Failed to complete hardware key registration";try{const n=JSON.parse(e);t=n.message||n.error||e}catch{t=e||"Failed to complete hardware key registration"}throw new Error(t)}return a.json()},startTokenRefreshTimer:U,stopTokenRefreshTimer:D,getAuthHeaders:J,forceReInit:()=>{g.value=0,y.value.initializing=1,I()}}};
@@ -1 +0,0 @@
1
- "use strict";const e=require("vue"),i={baseUrl:"https://your-api.example.com",accentColor:"#EA00A8",redirectUrl:"/",onSignInUrl:"/dashboard",onSignOutUrl:"/",autoRefresh:1,refreshInterval:4,protectedRoutes:[],guestOnlyRoutes:["/auth","/login","/register"],devMode:0,styles:1,endpoints:{},useSquircle:1},a=Symbol("strands-config"),s=e.ref(null);function t(e){if("undefined"==typeof window||!document.documentElement)return;if("undefined"!=typeof CSS&&CSS.registerProperty)try{CSS.registerProperty({name:"--strands-accent",syntax:"<color>",inherits:1,initialValue:e})}catch(a){}document.documentElement.style.setProperty("--strands-accent",e),document.documentElement.style.setProperty("--accui-strands-accent",e);const i={"--accui-strands-50":`color-mix(in srgb, ${e} 10%, white)`,"--accui-strands-100":`color-mix(in srgb, ${e} 20%, white)`,"--accui-strands-200":`color-mix(in srgb, ${e} 30%, white)`,"--accui-strands-300":`color-mix(in srgb, ${e} 40%, white)`,"--accui-strands-400":`color-mix(in srgb, ${e} 70%, white)`,"--accui-strands-500":e,"--accui-strands-600":`color-mix(in srgb, ${e} 85%, black)`,"--accui-strands-700":`color-mix(in srgb, ${e} 70%, black)`,"--accui-strands-800":`color-mix(in srgb, ${e} 55%, black)`,"--accui-strands-900":`color-mix(in srgb, ${e} 40%, black)`,"--accui-strands-950":`color-mix(in srgb, ${e} 25%, black)`};for(const[s,t]of Object.entries(i))document.documentElement.style.setProperty(s,t)}function n(i){if(s.value=i,"undefined"!=typeof window&&document.documentElement){const e=void 0!==i.useSquircle?i.useSquircle:1;document.documentElement.style.setProperty("--strands-allow-squircle",e?"1":"0"),i.accentColor&&t(i.accentColor)}try{e.provide(a,i)}catch(n){}}function r(t){let n=null;try{e.getCurrentInstance()&&(n=e.inject(a,null))}catch(u){n=null}let r=null;try{if("undefined"!=typeof window)if(window.__STRANDS_CONFIG__)r=window.__STRANDS_CONFIG__;else if(window.__NUXT__){const e=window.__NUXT__;r=e?.config?.public?.strandsAuth||e?.public?.strandsAuth||e?.strandsAuth}}catch(u){}const o=e.computed(()=>{const e={...i,...t||{},...n||{},...s.value||{},...r||{}};if(e.baseUrl,"undefined"!=typeof window&&document.documentElement){const i=void 0!==e.useSquircle?e.useSquircle:1;document.documentElement.style.setProperty("--strands-allow-squircle",i?"1":"0"),e.accentColor&&document.documentElement.style.setProperty("--strands-accent",e.accentColor)}return e}),c=e.computed(()=>{const e=o.value.endpoints||{};return{signIn:e.signIn||"/api/v1/auth/sign-in",signUp:e.signUp||"/api/v1/auth/sign-up",signOut:e.signOut||"/api/v1/auth/sign-out",refresh:e.refresh||"/api/v1/auth/refresh",passwordReset:e.passwordReset||"/api/v1/auth/password-reset",passwordResetConfirm:e.passwordResetConfirm||"/api/v1/auth/password-reset/confirm",completeRegistration:e.completeRegistration||"/api/v1/auth/complete-registration",profile:e.profile||"/api/v1/user/profile",verifyEmail:e.verifyEmail||"/api/v1/auth/verify-email",oauthProviders:e.oauthProviders||"/api/v1/oauth/providers",oauthProvider:e.oauthProvider||"/api/v1/oauth/providers/{provider_id}",changeEmail:e.changeEmail||"/api/v1/user/change-email",avatar:e.avatar||"/api/v1/user/avatar",settings:e.settings||"/api/v1/user/settings",changeUsername:e.changeUsername||"/api/v1/user/username",usernameCooldown:e.usernameCooldown||"/api/v1/user/username/cooldown",checkUsernameAvailability:e.checkUsernameAvailability||"/api/v1/username/{username}/available",mfaDevices:e.mfaDevices||"/api/v1/mfa/devices",mfaTotpSetup:e.mfaTotpSetup||"/api/v1/mfa/totp/setup",mfaTotpVerify:e.mfaTotpVerify||"/api/v1/mfa/totp/verify",mfaEmailSetup:e.mfaEmailSetup||"/api/v1/mfa/email/setup",mfaEmailSend:e.mfaEmailSend||"/api/v1/mfa/email/send",mfaEmailVerify:e.mfaEmailVerify||"/api/v1/mfa/email/verify",mfaDeviceDisable:e.mfaDeviceDisable||"/api/v1/mfa/device/disable",mfaBackupCodes:e.mfaBackupCodes||"/api/v1/mfa/backup-codes/regenerate",mfaHardwareStartRegistration:e.mfaHardwareStartRegistration||"/api/v1/mfa/hardware/start-registration",mfaHardwareCompleteRegistration:e.mfaHardwareCompleteRegistration||"/api/v1/mfa/hardware/complete-registration",mfaSigninSendEmail:e.mfaSigninSendEmail||"/api/v1/auth/mfa/email/send",mfaSigninVerify:e.mfaSigninVerify||"/api/v1/auth/mfa/verify",mfaBackupCodeVerify:e.mfaBackupCodeVerify||"/api/v1/auth/mfa/backup-code/verify",mfaWebAuthnChallenge:e.mfaWebAuthnChallenge||"/api/v1/auth/mfa/webauthn/challenge",sessions:e.sessions||"/api/v1/sessions",sessionsStats:e.sessionsStats||"/api/v1/sessions/stats",sessionRevoke:e.sessionRevoke||"/api/v1/sessions/{session_id}/revoke",sessionsRevokeAll:e.sessionsRevokeAll||"/api/v1/sessions/revoke-all"}});return{config:o,endpoints:c,getUrl:e=>{const i=o.value;if(!i.baseUrl)throw new Error("Base URL is required in configuration");let a;return a="string"==typeof e&&e in c.value?c.value[e]:"string"==typeof e?e:c.value[e],`${i.baseUrl.replace(/\/$/,"")}${a.startsWith("/")?a:`/${a}`}`},getSupportEmail:()=>o.value.supportEmail||null}}function o(e){if(s.value=e,"undefined"!=typeof window&&document.documentElement){const i=void 0!==e.useSquircle?e.useSquircle:1;document.documentElement.style.setProperty("--strands-allow-squircle",i?"1":"0"),e.accentColor&&t(e.accentColor)}}const c=Object.freeze(Object.defineProperty({__proto__:null,provideStrandsConfig:n,setStrandsConfig:o,useStrandsConfig:r},Symbol.toStringTag,{value:"Module"}));exports.STRANDS_AUTH_DEFAULTS=i,exports.provideStrandsConfig=n,exports.setStrandsConfig=o,exports.useStrandsConfig=r,exports.useStrandsConfig$1=c;
@@ -1,248 +0,0 @@
1
- import { ref, getCurrentInstance, inject, computed, provide } from "vue";
2
- const STRANDS_AUTH_DEFAULTS = {
3
- baseUrl: "https://your-api.example.com",
4
- accentColor: "#EA00A8",
5
- redirectUrl: "/",
6
- onSignInUrl: "/dashboard",
7
- onSignOutUrl: "/",
8
- autoRefresh: true,
9
- refreshInterval: 4,
10
- protectedRoutes: [],
11
- guestOnlyRoutes: ["/auth", "/login", "/register"],
12
- devMode: false,
13
- styles: true,
14
- endpoints: {},
15
- useSquircle: true
16
- };
17
- const DEFAULT_ENDPOINTS = {
18
- signIn: "/api/v1/auth/sign-in",
19
- signUp: "/api/v1/auth/sign-up",
20
- signOut: "/api/v1/auth/sign-out",
21
- refresh: "/api/v1/auth/refresh",
22
- passwordReset: "/api/v1/auth/password-reset",
23
- passwordResetConfirm: "/api/v1/auth/password-reset/confirm",
24
- completeRegistration: "/api/v1/auth/complete-registration",
25
- profile: "/api/v1/user/profile",
26
- verifyEmail: "/api/v1/auth/verify-email",
27
- oauthProviders: "/api/v1/oauth/providers",
28
- oauthProvider: "/api/v1/oauth/providers/{provider_id}",
29
- changeEmail: "/api/v1/user/change-email",
30
- avatar: "/api/v1/user/avatar",
31
- settings: "/api/v1/user/settings",
32
- // Username endpoints
33
- changeUsername: "/api/v1/user/username",
34
- usernameCooldown: "/api/v1/user/username/cooldown",
35
- checkUsernameAvailability: "/api/v1/username/{username}/available",
36
- // MFA endpoints
37
- mfaDevices: "/api/v1/mfa/devices",
38
- mfaTotpSetup: "/api/v1/mfa/totp/setup",
39
- mfaTotpVerify: "/api/v1/mfa/totp/verify",
40
- mfaEmailSetup: "/api/v1/mfa/email/setup",
41
- mfaEmailSend: "/api/v1/mfa/email/send",
42
- mfaEmailVerify: "/api/v1/mfa/email/verify",
43
- mfaDeviceDisable: "/api/v1/mfa/device/disable",
44
- mfaBackupCodes: "/api/v1/mfa/backup-codes/regenerate",
45
- // Hardware key endpoints
46
- mfaHardwareStartRegistration: "/api/v1/mfa/hardware/start-registration",
47
- mfaHardwareCompleteRegistration: "/api/v1/mfa/hardware/complete-registration",
48
- // MFA sign-in specific endpoints
49
- mfaSigninSendEmail: "/api/v1/auth/mfa/email/send",
50
- mfaSigninVerify: "/api/v1/auth/mfa/verify",
51
- mfaBackupCodeVerify: "/api/v1/auth/mfa/backup-code/verify",
52
- mfaWebAuthnChallenge: "/api/v1/auth/mfa/webauthn/challenge",
53
- // Session management endpoints
54
- sessions: "/api/v1/sessions",
55
- sessionsStats: "/api/v1/sessions/stats",
56
- sessionRevoke: "/api/v1/sessions/{session_id}/revoke",
57
- sessionsRevokeAll: "/api/v1/sessions/revoke-all"
58
- };
59
- const STRANDS_CONFIG_KEY = Symbol("strands-config");
60
- const globalConfig = ref(null);
61
- function generateColorShades(accentColor) {
62
- if (typeof window === "undefined" || !document.documentElement) return;
63
- if (typeof CSS !== "undefined" && CSS.registerProperty) {
64
- try {
65
- CSS.registerProperty({
66
- name: "--strands-accent",
67
- syntax: "<color>",
68
- inherits: true,
69
- initialValue: accentColor
70
- });
71
- } catch (e) {
72
- }
73
- }
74
- document.documentElement.style.setProperty("--strands-accent", accentColor);
75
- document.documentElement.style.setProperty("--accui-strands-accent", accentColor);
76
- const shades = {
77
- "--accui-strands-50": `color-mix(in srgb, ${accentColor} 10%, white)`,
78
- "--accui-strands-100": `color-mix(in srgb, ${accentColor} 20%, white)`,
79
- "--accui-strands-200": `color-mix(in srgb, ${accentColor} 30%, white)`,
80
- "--accui-strands-300": `color-mix(in srgb, ${accentColor} 40%, white)`,
81
- "--accui-strands-400": `color-mix(in srgb, ${accentColor} 70%, white)`,
82
- "--accui-strands-500": accentColor,
83
- "--accui-strands-600": `color-mix(in srgb, ${accentColor} 85%, black)`,
84
- "--accui-strands-700": `color-mix(in srgb, ${accentColor} 70%, black)`,
85
- "--accui-strands-800": `color-mix(in srgb, ${accentColor} 55%, black)`,
86
- "--accui-strands-900": `color-mix(in srgb, ${accentColor} 40%, black)`,
87
- "--accui-strands-950": `color-mix(in srgb, ${accentColor} 25%, black)`
88
- };
89
- for (const [property, value] of Object.entries(shades)) {
90
- document.documentElement.style.setProperty(property, value);
91
- }
92
- }
93
- function provideStrandsConfig(config) {
94
- globalConfig.value = config;
95
- if (typeof window !== "undefined" && document.documentElement) {
96
- const useSquircle = config.useSquircle !== void 0 ? config.useSquircle : true;
97
- document.documentElement.style.setProperty("--strands-allow-squircle", useSquircle ? "1" : "0");
98
- if (config.accentColor) {
99
- generateColorShades(config.accentColor);
100
- }
101
- }
102
- try {
103
- provide(STRANDS_CONFIG_KEY, config);
104
- } catch (error) {
105
- console.warn("[Strands Auth] Could not provide config via Vue provide/inject. Config available via global state only.", error);
106
- }
107
- }
108
- function useStrandsConfig(fallbackConfig) {
109
- let injectedConfig = null;
110
- try {
111
- const currentInstance = getCurrentInstance();
112
- if (currentInstance) {
113
- injectedConfig = inject(STRANDS_CONFIG_KEY, null);
114
- }
115
- } catch (error) {
116
- injectedConfig = null;
117
- }
118
- let nuxtConfig = null;
119
- try {
120
- if (typeof window !== "undefined") {
121
- if (window.__STRANDS_CONFIG__) {
122
- nuxtConfig = window.__STRANDS_CONFIG__;
123
- } else if (window.__NUXT__) {
124
- const nuxtData = window.__NUXT__;
125
- nuxtConfig = nuxtData?.config?.public?.strandsAuth || nuxtData?.public?.strandsAuth || nuxtData?.strandsAuth;
126
- }
127
- }
128
- } catch (error) {
129
- console.error("[Strands Auth] Error accessing runtime configuration:", error);
130
- }
131
- const activeConfig = computed(() => {
132
- const config = {
133
- ...STRANDS_AUTH_DEFAULTS,
134
- ...fallbackConfig || {},
135
- ...injectedConfig || {},
136
- ...globalConfig.value || {},
137
- ...nuxtConfig || {}
138
- };
139
- if (config.baseUrl === STRANDS_AUTH_DEFAULTS.baseUrl && typeof window === "undefined") {
140
- console.warn("[Strands Auth] No baseUrl configured for SSR. Please provide a baseUrl in your strandsAuth configuration.");
141
- }
142
- if (typeof window !== "undefined" && document.documentElement) {
143
- const useSquircle = config.useSquircle !== void 0 ? config.useSquircle : true;
144
- document.documentElement.style.setProperty("--strands-allow-squircle", useSquircle ? "1" : "0");
145
- if (config.accentColor) {
146
- document.documentElement.style.setProperty("--strands-accent", config.accentColor);
147
- }
148
- }
149
- return config;
150
- });
151
- const endpoints = computed(() => {
152
- const config = activeConfig.value;
153
- const customEndpoints = config.endpoints || {};
154
- return {
155
- signIn: customEndpoints.signIn || DEFAULT_ENDPOINTS.signIn,
156
- signUp: customEndpoints.signUp || DEFAULT_ENDPOINTS.signUp,
157
- signOut: customEndpoints.signOut || DEFAULT_ENDPOINTS.signOut,
158
- refresh: customEndpoints.refresh || DEFAULT_ENDPOINTS.refresh,
159
- passwordReset: customEndpoints.passwordReset || DEFAULT_ENDPOINTS.passwordReset,
160
- passwordResetConfirm: customEndpoints.passwordResetConfirm || DEFAULT_ENDPOINTS.passwordResetConfirm,
161
- completeRegistration: customEndpoints.completeRegistration || DEFAULT_ENDPOINTS.completeRegistration,
162
- profile: customEndpoints.profile || DEFAULT_ENDPOINTS.profile,
163
- verifyEmail: customEndpoints.verifyEmail || DEFAULT_ENDPOINTS.verifyEmail,
164
- oauthProviders: customEndpoints.oauthProviders || DEFAULT_ENDPOINTS.oauthProviders,
165
- oauthProvider: customEndpoints.oauthProvider || DEFAULT_ENDPOINTS.oauthProvider,
166
- changeEmail: customEndpoints.changeEmail || DEFAULT_ENDPOINTS.changeEmail,
167
- avatar: customEndpoints.avatar || DEFAULT_ENDPOINTS.avatar,
168
- settings: customEndpoints.settings || DEFAULT_ENDPOINTS.settings,
169
- // Username endpoints
170
- changeUsername: customEndpoints.changeUsername || DEFAULT_ENDPOINTS.changeUsername,
171
- usernameCooldown: customEndpoints.usernameCooldown || DEFAULT_ENDPOINTS.usernameCooldown,
172
- checkUsernameAvailability: customEndpoints.checkUsernameAvailability || DEFAULT_ENDPOINTS.checkUsernameAvailability,
173
- // MFA endpoints
174
- mfaDevices: customEndpoints.mfaDevices || DEFAULT_ENDPOINTS.mfaDevices,
175
- mfaTotpSetup: customEndpoints.mfaTotpSetup || DEFAULT_ENDPOINTS.mfaTotpSetup,
176
- mfaTotpVerify: customEndpoints.mfaTotpVerify || DEFAULT_ENDPOINTS.mfaTotpVerify,
177
- mfaEmailSetup: customEndpoints.mfaEmailSetup || DEFAULT_ENDPOINTS.mfaEmailSetup,
178
- mfaEmailSend: customEndpoints.mfaEmailSend || DEFAULT_ENDPOINTS.mfaEmailSend,
179
- mfaEmailVerify: customEndpoints.mfaEmailVerify || DEFAULT_ENDPOINTS.mfaEmailVerify,
180
- mfaDeviceDisable: customEndpoints.mfaDeviceDisable || DEFAULT_ENDPOINTS.mfaDeviceDisable,
181
- mfaBackupCodes: customEndpoints.mfaBackupCodes || DEFAULT_ENDPOINTS.mfaBackupCodes,
182
- // Hardware key endpoints
183
- mfaHardwareStartRegistration: customEndpoints.mfaHardwareStartRegistration || DEFAULT_ENDPOINTS.mfaHardwareStartRegistration,
184
- mfaHardwareCompleteRegistration: customEndpoints.mfaHardwareCompleteRegistration || DEFAULT_ENDPOINTS.mfaHardwareCompleteRegistration,
185
- // MFA sign-in specific endpoints
186
- mfaSigninSendEmail: customEndpoints.mfaSigninSendEmail || DEFAULT_ENDPOINTS.mfaSigninSendEmail,
187
- mfaSigninVerify: customEndpoints.mfaSigninVerify || DEFAULT_ENDPOINTS.mfaSigninVerify,
188
- mfaBackupCodeVerify: customEndpoints.mfaBackupCodeVerify || DEFAULT_ENDPOINTS.mfaBackupCodeVerify,
189
- mfaWebAuthnChallenge: customEndpoints.mfaWebAuthnChallenge || DEFAULT_ENDPOINTS.mfaWebAuthnChallenge,
190
- // Session management endpoints
191
- sessions: customEndpoints.sessions || DEFAULT_ENDPOINTS.sessions,
192
- sessionsStats: customEndpoints.sessionsStats || DEFAULT_ENDPOINTS.sessionsStats,
193
- sessionRevoke: customEndpoints.sessionRevoke || DEFAULT_ENDPOINTS.sessionRevoke,
194
- sessionsRevokeAll: customEndpoints.sessionsRevokeAll || DEFAULT_ENDPOINTS.sessionsRevokeAll
195
- };
196
- });
197
- const getUrl = (endpoint) => {
198
- const config = activeConfig.value;
199
- if (!config.baseUrl) {
200
- throw new Error("Base URL is required in configuration");
201
- }
202
- let endpointPath;
203
- if (typeof endpoint === "string" && endpoint in endpoints.value) {
204
- endpointPath = endpoints.value[endpoint];
205
- } else if (typeof endpoint === "string") {
206
- endpointPath = endpoint;
207
- } else {
208
- endpointPath = endpoints.value[endpoint];
209
- }
210
- const baseUrl = config.baseUrl.replace(/\/$/, "");
211
- const path = endpointPath.startsWith("/") ? endpointPath : `/${endpointPath}`;
212
- console.debug(`[Strands Auth] Constructing URL for endpoint "${endpoint}": ${baseUrl}${path}`);
213
- return `${baseUrl}${path}`;
214
- };
215
- const getSupportEmail = () => {
216
- const config = activeConfig.value;
217
- return config.supportEmail || null;
218
- };
219
- return {
220
- config: activeConfig,
221
- endpoints,
222
- getUrl,
223
- getSupportEmail
224
- };
225
- }
226
- function setStrandsConfig(config) {
227
- globalConfig.value = config;
228
- if (typeof window !== "undefined" && document.documentElement) {
229
- const useSquircle = config.useSquircle !== void 0 ? config.useSquircle : true;
230
- document.documentElement.style.setProperty("--strands-allow-squircle", useSquircle ? "1" : "0");
231
- if (config.accentColor) {
232
- generateColorShades(config.accentColor);
233
- }
234
- }
235
- }
236
- const useStrandsConfig$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
237
- __proto__: null,
238
- provideStrandsConfig,
239
- setStrandsConfig,
240
- useStrandsConfig
241
- }, Symbol.toStringTag, { value: "Module" }));
242
- export {
243
- STRANDS_AUTH_DEFAULTS as S,
244
- useStrandsConfig$1 as a,
245
- provideStrandsConfig as p,
246
- setStrandsConfig as s,
247
- useStrandsConfig as u
248
- };