@strands.gg/accui 2.17.33 → 2.17.35
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/index.cjs.js +5 -5
- package/dist/index.es.js +2124 -2220
- package/dist/nuxt/module.cjs.js +1 -1
- package/dist/nuxt/module.es.js +2 -1
- package/dist/nuxt/runtime/composables/useStrandsAuth.cjs.js +1 -1
- package/dist/nuxt/runtime/composables/useStrandsAuth.es.js +1 -1
- package/dist/nuxt/runtime/plugin.client.cjs.js +1 -1
- package/dist/nuxt/runtime/plugin.client.es.js +12 -8
- package/dist/nuxt/runtime/plugin.server.cjs.js +1 -1
- package/dist/nuxt/runtime/plugin.server.es.js +1 -1
- package/dist/nuxt/types.d.ts +5 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/useDarkMode-Cew-NWjS.cjs.js +1 -0
- package/dist/useDarkMode-CvinMR9O.es.js +102 -0
- package/dist/{useStrandsAuth-CTh6ELtc.cjs.js → useStrandsAuth-BGeuqkcO.cjs.js} +1 -1
- package/dist/{useStrandsAuth-mv5zJr7L.es.js → useStrandsAuth-DoFlH5a3.es.js} +1 -1
- package/dist/{useStrandsConfig-CMKVW1p3.es.js → useStrandsConfig-C9TOTAfh.es.js} +2 -1
- package/dist/useStrandsConfig-x5zDprqF.cjs.js +1 -0
- package/dist/vite.cjs.js +1 -1
- package/dist/vite.es.js +1 -1
- package/package.json +1 -1
- package/dist/useStrandsConfig-B5kp4aF9.cjs.js +0 -1
package/dist/nuxt/module.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const r=require("@nuxt/kit");var n=typeof document<"u"?document.currentScript:null;const h={baseUrl:"https://your-api.example.com",accentColor:"#EA00A8",redirectUrl:"/",onSignInUrl:"/dashboard",onSignOutUrl:"/",autoRefresh:!0,refreshInterval:4,protectedRoutes:[],guestOnlyRoutes:["/auth","/login","/register"],devMode:!1,styles:!0,supportEmail:"",oauth2RedirectUrl:""},g=r.defineNuxtModule({meta:{name:"@strands.gg/accui/nuxt",configKey:"strandsAuth",compatibility:{nuxt:"^3.0.0 || ^4.0.0"}},defaults:h,async setup(a,t){const s=r.createResolver(typeof document>"u"?require("url").pathToFileURL(__filename).href:n&&n.tagName.toUpperCase()==="SCRIPT"&&n.src||new URL("nuxt/module.cjs.js",document.baseURI).href);t.options.runtimeConfig.public=t.options.runtimeConfig.public||{};const i={...a,styles:a.styles!==!1};if(t.options.runtimeConfig.public.strandsAuth=i,t.options.appConfig&&(t.options.appConfig.strandsAuth=i),a.styles!==!1&&t.options.css.push("@strands.gg/accui/style.css"),a.accentColor&&a.accentColor!=="#EA00A8"){const e=a.accentColor,p=`
|
|
1
|
+
"use strict";const r=require("@nuxt/kit");var n=typeof document<"u"?document.currentScript:null;const h={baseUrl:"https://your-api.example.com",accentColor:"#EA00A8",redirectUrl:"/",onSignInUrl:"/dashboard",onSignOutUrl:"/",autoRefresh:!0,refreshInterval:4,protectedRoutes:[],guestOnlyRoutes:["/auth","/login","/register"],devMode:!1,styles:!0,supportEmail:"",oauth2RedirectUrl:"",theme:"system"},g=r.defineNuxtModule({meta:{name:"@strands.gg/accui/nuxt",configKey:"strandsAuth",compatibility:{nuxt:"^3.0.0 || ^4.0.0"}},defaults:h,async setup(a,t){const s=r.createResolver(typeof document>"u"?require("url").pathToFileURL(__filename).href:n&&n.tagName.toUpperCase()==="SCRIPT"&&n.src||new URL("nuxt/module.cjs.js",document.baseURI).href);t.options.runtimeConfig.public=t.options.runtimeConfig.public||{};const i={...a,styles:a.styles!==!1};if(t.options.runtimeConfig.public.strandsAuth=i,t.options.appConfig&&(t.options.appConfig.strandsAuth=i),a.styles!==!1&&t.options.css.push("@strands.gg/accui/style.css"),a.accentColor&&a.accentColor!=="#EA00A8"){const e=a.accentColor,p=`
|
|
2
2
|
:root {
|
|
3
3
|
--strands-custom-accent: ${e};
|
|
4
4
|
--strands-custom-50: color-mix(in srgb, ${e} 10%, white);
|
package/dist/nuxt/module.es.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("nuxt/app"),a=require("../../../useStrandsAuth-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("nuxt/app"),a=require("../../../useStrandsAuth-BGeuqkcO.cjs.js"),u=()=>{const t=e.useRuntimeConfig().public.strandsAuth,n=a.useStrandsAuth();return{...n,initialize:async()=>{await n.initialize()},signIn:async s=>{const i=await n.signIn(s);return i&&t.onSignInUrl&&await e.navigateTo(t.onSignInUrl),i},signUp:async s=>await n.signUp({email:s.email,password:"",firstName:"",lastName:""}),signOut:async()=>{await n.signOut(),t.onSignOutUrl&&await e.navigateTo(t.onSignOutUrl)}}},r=()=>{const{user:t}=u();return{user:t}},o=()=>{const{isAuthenticated:t,isLoading:n}=u();return{isAuthenticated:t,isLoading:n}};exports.useAuthState=o;exports.useAuthUser=r;exports.useStrandsAuth=u;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useRuntimeConfig as e, navigateTo as a } from "nuxt/app";
|
|
2
|
-
import { u as r } from "../../../useStrandsAuth-
|
|
2
|
+
import { u as r } from "../../../useStrandsAuth-DoFlH5a3.es.js";
|
|
3
3
|
const u = () => {
|
|
4
4
|
const n = e().public.strandsAuth, t = r();
|
|
5
5
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const n=require("nuxt/app"),t=require("../../useStrandsConfig-x5zDprqF.cjs.js"),d=require("../../useDarkMode-Cew-NWjS.cjs.js"),c=n.defineNuxtPlugin({name:"strands-auth-client",async setup(){const o=n.useRuntimeConfig().public.strandsAuth,e={...t.STRANDS_AUTH_DEFAULTS,...o};if(t.setStrandsConfig(e),typeof window<"u"&&(window.__STRANDS_CONFIG__=e),e?.accentColor&&typeof window<"u"&&document.documentElement.style.setProperty("--strands-accent",e.accentColor),typeof window<"u"){const r=e?.theme||"system";d.useGlobalDarkMode().setTheme(r)}const{useStrandsAuth:s}=await Promise.resolve().then(()=>require("./composables/useStrandsAuth.cjs.js")),{initialize:i}=s();await i()}});module.exports=c;
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import { defineNuxtPlugin as
|
|
2
|
-
import { s as
|
|
3
|
-
|
|
1
|
+
import { defineNuxtPlugin as s, useRuntimeConfig as a } from "nuxt/app";
|
|
2
|
+
import { s as d, S as c } from "../../useStrandsConfig-C9TOTAfh.es.js";
|
|
3
|
+
import { u as r } from "../../useDarkMode-CvinMR9O.es.js";
|
|
4
|
+
const g = s({
|
|
4
5
|
name: "strands-auth-client",
|
|
5
6
|
async setup() {
|
|
6
|
-
const
|
|
7
|
+
const e = a().public.strandsAuth, t = {
|
|
7
8
|
...c,
|
|
8
|
-
...
|
|
9
|
+
...e
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
if (d(t), typeof window < "u" && (window.__STRANDS_CONFIG__ = t), t?.accentColor && typeof window < "u" && document.documentElement.style.setProperty("--strands-accent", t.accentColor), typeof window < "u") {
|
|
12
|
+
const i = t?.theme || "system";
|
|
13
|
+
r().setTheme(i);
|
|
14
|
+
}
|
|
15
|
+
const { useStrandsAuth: n } = await import("./composables/useStrandsAuth.es.js"), { initialize: o } = n();
|
|
12
16
|
await o();
|
|
13
17
|
}
|
|
14
18
|
});
|
|
15
19
|
export {
|
|
16
|
-
|
|
20
|
+
g as default
|
|
17
21
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const n=require("nuxt/app"),s=require("../../useStrandsConfig-
|
|
1
|
+
"use strict";const n=require("nuxt/app"),s=require("../../useStrandsConfig-x5zDprqF.cjs.js"),r=n.defineNuxtPlugin({name:"strands-auth-server",setup(){const e=n.useRuntimeConfig().public.strandsAuth,t={...s.STRANDS_AUTH_DEFAULTS,...e};s.setStrandsConfig(t)}});module.exports=r;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineNuxtPlugin as t, useRuntimeConfig as e } from "nuxt/app";
|
|
2
|
-
import { s as o, S as r } from "../../useStrandsConfig-
|
|
2
|
+
import { s as o, S as r } from "../../useStrandsConfig-C9TOTAfh.es.js";
|
|
3
3
|
const u = t({
|
|
4
4
|
name: "strands-auth-server",
|
|
5
5
|
setup() {
|
package/dist/nuxt/types.d.ts
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -170,6 +170,14 @@ export interface StrandsAuthConfig {
|
|
|
170
170
|
* @default true
|
|
171
171
|
*/
|
|
172
172
|
useSquircle?: boolean;
|
|
173
|
+
/**
|
|
174
|
+
* Theme mode for the UI components
|
|
175
|
+
* - 'light': Force light mode
|
|
176
|
+
* - 'dark': Force dark mode
|
|
177
|
+
* - 'system': Follow system preference (default)
|
|
178
|
+
* @default 'system'
|
|
179
|
+
*/
|
|
180
|
+
theme?: 'light' | 'dark' | 'system';
|
|
173
181
|
}
|
|
174
182
|
export interface StrandsAuthEndpoints {
|
|
175
183
|
signIn: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const r=require("vue"),n=r.ref("system"),u=r.ref(!1),l="strands-ui-theme";function g(){return typeof window>"u"?!1:window.matchMedia("(prefers-color-scheme: dark)").matches}function k(){if(typeof window>"u")return"system";try{const e=localStorage.getItem(l);if(e&&["light","dark","system"].includes(e))return e}catch(e){console.warn("Failed to read theme preference from localStorage:",e)}return"system"}function v(e){if(!(typeof window>"u"))try{localStorage.setItem(l,e)}catch(s){console.warn("Failed to save theme preference to localStorage:",s)}}function m(e){typeof document>"u"||(e?(document.documentElement.setAttribute("data-theme","dark"),document.documentElement.classList.add("dark")):(document.documentElement.setAttribute("data-theme","light"),document.documentElement.classList.remove("dark")))}function w(){const e=r.computed(()=>n.value==="dark"?!0:n.value==="light"?!1:u.value),s=r.computed(()=>{switch(n.value){case"light":return"Light";case"dark":return"Dark";case"system":return"System";default:return"System"}});function a(t){n.value=t,v(t)}function f(){const t=e.value?"light":"dark";a(t)}function h(){switch(n.value){case"light":a("dark");break;case"dark":a("system");break;case"system":a("light");break;default:a("light");break}}function c(){if(typeof window>"u")return;u.value=g();const t=window.matchMedia("(prefers-color-scheme: dark)"),d=i=>{u.value=i.matches};t.addEventListener?t.addEventListener("change",d):t.addListener(d);const y=k();n.value=y,m(e.value),r.watch(e,i=>{m(i)},{immediate:!1})}return r.onMounted(()=>{c()}),{currentTheme:r.computed(()=>n.value),isDark:e,themeLabel:s,setTheme:a,toggle:f,cycleTheme:h,initialize:c,themeOptions:[{value:"light",label:"Light",icon:"sun"},{value:"dark",label:"Dark",icon:"moon"},{value:"system",label:"System",icon:"monitor"}]}}let o=null;function p(){return o||(o=w(),typeof window<"u"&&(localStorage.getItem(l)===null&&(n.value="system"),o.initialize())),o}exports.useGlobalDarkMode=p;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { ref as f, computed as i, onMounted as k, watch as v } from "vue";
|
|
2
|
+
const n = f("system"), l = f(!1), u = "strands-ui-theme";
|
|
3
|
+
function w() {
|
|
4
|
+
return typeof window > "u" ? !1 : window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
5
|
+
}
|
|
6
|
+
function p() {
|
|
7
|
+
if (typeof window > "u") return "system";
|
|
8
|
+
try {
|
|
9
|
+
const e = localStorage.getItem(u);
|
|
10
|
+
if (e && ["light", "dark", "system"].includes(e))
|
|
11
|
+
return e;
|
|
12
|
+
} catch (e) {
|
|
13
|
+
console.warn("Failed to read theme preference from localStorage:", e);
|
|
14
|
+
}
|
|
15
|
+
return "system";
|
|
16
|
+
}
|
|
17
|
+
function S(e) {
|
|
18
|
+
if (!(typeof window > "u"))
|
|
19
|
+
try {
|
|
20
|
+
localStorage.setItem(u, e);
|
|
21
|
+
} catch (o) {
|
|
22
|
+
console.warn("Failed to save theme preference to localStorage:", o);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function m(e) {
|
|
26
|
+
typeof document > "u" || (e ? (document.documentElement.setAttribute("data-theme", "dark"), document.documentElement.classList.add("dark")) : (document.documentElement.setAttribute("data-theme", "light"), document.documentElement.classList.remove("dark")));
|
|
27
|
+
}
|
|
28
|
+
function b() {
|
|
29
|
+
const e = i(() => n.value === "dark" ? !0 : n.value === "light" ? !1 : l.value), o = i(() => {
|
|
30
|
+
switch (n.value) {
|
|
31
|
+
case "light":
|
|
32
|
+
return "Light";
|
|
33
|
+
case "dark":
|
|
34
|
+
return "Dark";
|
|
35
|
+
case "system":
|
|
36
|
+
return "System";
|
|
37
|
+
default:
|
|
38
|
+
return "System";
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
function r(t) {
|
|
42
|
+
n.value = t, S(t);
|
|
43
|
+
}
|
|
44
|
+
function h() {
|
|
45
|
+
const t = e.value ? "light" : "dark";
|
|
46
|
+
r(t);
|
|
47
|
+
}
|
|
48
|
+
function y() {
|
|
49
|
+
switch (n.value) {
|
|
50
|
+
case "light":
|
|
51
|
+
r("dark");
|
|
52
|
+
break;
|
|
53
|
+
case "dark":
|
|
54
|
+
r("system");
|
|
55
|
+
break;
|
|
56
|
+
case "system":
|
|
57
|
+
r("light");
|
|
58
|
+
break;
|
|
59
|
+
default:
|
|
60
|
+
r("light");
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function c() {
|
|
65
|
+
if (typeof window > "u") return;
|
|
66
|
+
l.value = w();
|
|
67
|
+
const t = window.matchMedia("(prefers-color-scheme: dark)"), d = (s) => {
|
|
68
|
+
l.value = s.matches;
|
|
69
|
+
};
|
|
70
|
+
t.addEventListener ? t.addEventListener("change", d) : t.addListener(d);
|
|
71
|
+
const g = p();
|
|
72
|
+
n.value = g, m(e.value), v(e, (s) => {
|
|
73
|
+
m(s);
|
|
74
|
+
}, { immediate: !1 });
|
|
75
|
+
}
|
|
76
|
+
return k(() => {
|
|
77
|
+
c();
|
|
78
|
+
}), {
|
|
79
|
+
// State
|
|
80
|
+
currentTheme: i(() => n.value),
|
|
81
|
+
isDark: e,
|
|
82
|
+
themeLabel: o,
|
|
83
|
+
// Actions
|
|
84
|
+
setTheme: r,
|
|
85
|
+
toggle: h,
|
|
86
|
+
cycleTheme: y,
|
|
87
|
+
initialize: c,
|
|
88
|
+
// Theme options for UI
|
|
89
|
+
themeOptions: [
|
|
90
|
+
{ value: "light", label: "Light", icon: "sun" },
|
|
91
|
+
{ value: "dark", label: "Dark", icon: "moon" },
|
|
92
|
+
{ value: "system", label: "System", icon: "monitor" }
|
|
93
|
+
]
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
let a = null;
|
|
97
|
+
function E() {
|
|
98
|
+
return a || (a = b(), typeof window < "u" && (localStorage.getItem(u) === null && (n.value = "system"), a.initialize())), a;
|
|
99
|
+
}
|
|
100
|
+
export {
|
|
101
|
+
E as u
|
|
102
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const u=require("vue"),we=require("./useStrandsConfig-B5kp4aF9.cjs.js");class ye{cache=new Map;DEFAULT_TTL=300*1e3;async fetch(d,v,g=this.DEFAULT_TTL){const b=Date.now(),s=this.cache.get(d);if(s&&b-s.timestamp<s.ttl)return s.promise;this.cleanExpired();const o=v().finally(()=>{setTimeout(()=>{this.cache.delete(d)},g)});return this.cache.set(d,{promise:o,timestamp:b,ttl:g}),o}clear(){this.cache.clear()}invalidate(d){this.cache.delete(d)}cleanExpired(){const d=Date.now();for(const[v,g]of this.cache.entries())d-g.timestamp>g.ttl&&this.cache.delete(v)}getStats(){return{size:this.cache.size,entries:Array.from(this.cache.keys())}}}const m=new ye;function pe(){return{fetch:m.fetch.bind(m),clear:m.clear.bind(m),invalidate:m.invalidate.bind(m),getStats:m.getStats.bind(m)}}function Se(n,d){let v=null;return(...g)=>{v&&clearTimeout(v),v=setTimeout(()=>{n(...g)},d)}}const F=Se((n,d)=>{typeof window<"u"&&localStorage.setItem(n,d)},300),E=n=>({id:n.id,email:n.email,firstName:n.first_name||n.firstName||"",lastName:n.last_name||n.lastName||"",avatar:n.avatar_url||n.avatar,mfaEnabled:n.mfa_enabled??n.mfaEnabled??!1,emailVerified:n.email_verified??n.emailVerified??!1,passwordUpdatedAt:n.password_updated_at||n.passwordUpdatedAt,settings:n.settings||{},xp:n.xp||0,level:n.level||1,next_level_xp:n.next_level_xp||n.next_level_xp||4,username:n.username,usernameLastChangedAt:n.username_last_changed_at||n.usernameLastChangedAt,createdAt:n.created_at||n.createdAt,updatedAt:n.updated_at||n.updatedAt||new Date().toISOString()}),_e={currentUser:u.ref(null),currentSession:u.ref(null),loadingStates:u.ref({initializing:!0,signingIn:!1,signingUp:!1,signingOut:!1,refreshingToken:!1,sendingMfaEmail:!1,verifyingMfa:!1,loadingProfile:!1}),isInitialized:u.ref(!1),mfaRequired:u.ref(!1),mfaSessionId:u.ref(null),availableMfaMethods:u.ref([])};let k=null,y=null,x=null,A=null;function Te(){const{getUrl:n,config:d}=we.useStrandsConfig(),{fetch:v,clear:g,invalidate:b}=pe(),{currentUser:s,currentSession:o,loadingStates:i,isInitialized:w,mfaRequired:p,mfaSessionId:h,availableMfaMethods:S}=_e,_=()=>{if(s.value=null,o.value=null,p.value=!1,h.value=null,S.value=[],typeof window<"u"&&(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user")),I(),$(),y=null,g(),typeof window<"u"&&d.value?.onSignOutUrl){const e=window.location.pathname+window.location.search,t=d.value.onSignOutUrl;e!==t&&(window.location.href=t)}},L=u.computed(()=>i.value.initializing),U=u.computed(()=>i.value.signingIn),R=u.computed(()=>i.value.signingUp),q=u.computed(()=>i.value.signingOut),B=u.computed(()=>i.value.refreshingToken),V=u.computed(()=>i.value.sendingMfaEmail),K=u.computed(()=>i.value.verifyingMfa);u.computed(()=>i.value.loadingProfile);const j=u.computed(()=>i.value.signingIn||i.value.signingUp||i.value.signingOut||i.value.refreshingToken||i.value.sendingMfaEmail||i.value.verifyingMfa||i.value.loadingProfile),W=u.computed(()=>i.value.initializing||j.value),G=u.computed(()=>{const e=i.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..."}),O=()=>{const e={};return o.value?.accessToken&&(e.Authorization=`Bearer ${o.value.accessToken}`),o.value?.refreshToken&&(e["x-refresh-token"]=o.value.refreshToken),e},H=async(e,t,a)=>{const r=await fetch(n("mfaHardwareCompleteRegistration"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({device_id:e,credential:t})});if(!r.ok){const c=await r.text();let l="Failed to complete hardware key registration";try{const f=JSON.parse(c);l=f.message||f.error||c}catch{l=c||"Failed to complete hardware key registration"}throw new Error(l)}return r.json()},Y=async(e,t,a="hardware")=>{const r=await fetch(n("mfaHardwareStartRegistration"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({device_name:e,device_type:a})});if(!r.ok){const c=await r.text();let l="Failed to start hardware key registration";try{const f=JSON.parse(c);l=f.message||f.error||c}catch{l=c||"Failed to start hardware key registration"}throw new Error(l)}return r.json()},Q=u.computed(()=>s.value!==null),X=async e=>{i.value.signingIn=!0;try{p.value=!1,h.value=null,S.value=[];const t={"Content-Type":"application/json"};typeof window<"u"&&window.location&&(t.Origin=window.location.origin);const a=await fetch(n("signIn"),{method:"POST",headers:t,body:JSON.stringify(e)});if(!a.ok)throw a.status===401?new Error("Invalid email or password"):a.status===403?new Error("Please verify your email address before signing in"):new Error(`Sign in failed: ${a.status} ${a.statusText}`);const r=await a.json();if(r.mfa_required){p.value=!0,h.value=r.mfa_session_id||null;const c=(r.available_mfa_methods||[]).map(l=>{let f=`${l.device_type.charAt(0).toUpperCase()+l.device_type.slice(1)} Authentication`;return l.device_type==="hardware"?f=l.device_name||"Security Key":l.device_type==="totp"?f=l.device_name||"Authenticator App":l.device_type==="email"&&(f=l.device_name||"Email Verification"),{id:l.device_id,device_type:l.device_type,device_name:l.device_name||f,is_active:!0,created_at:new Date().toISOString(),last_used_at:l.last_used_at,credential_id:l.credential_id,device_info:l.device_info}});return S.value=c,i.value.signingIn=!1,r}return await C(r),r}catch(t){throw t}finally{i.value.signingIn=!1}},Z=async e=>{i.value.signingUp=!0;try{throw new Error("Sign up not implemented - please integrate with auth SDK")}finally{i.value.signingUp=!1}},ee=async()=>{i.value.signingOut=!0;try{I(),$(),y=null,g(),s.value=null,o.value=null,p.value=!1,h.value=null,S.value=[],typeof window<"u"&&(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user")),typeof window<"u"&&d.value?.onSignOutUrl&&(window.location.href=d.value.onSignOutUrl)}finally{i.value.signingOut=!1}},P=async()=>{if(!o.value?.refreshToken)return!1;if(y)return await y;y=(async()=>{i.value.refreshingToken=!0;try{const t=await fetch(n("refresh"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh_token:o.value.refreshToken})});if(!t.ok){if(t.status===401)return _(),!1;throw new Error(`Token refresh failed: ${t.status} ${t.statusText}`)}const a=await t.json();a.user&&(s.value=E(a.user),s.value&&typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(s.value)));const r={accessToken:a.access_token,refreshToken:a.refresh_token,expiresAt:new Date(Date.now()+300*1e3),userId:a.user?.id||s.value?.id};return o.value=r,typeof window<"u"&&localStorage.setItem("strands_auth_session",JSON.stringify(r)),T(),M(),b(`sessions:${o.value.accessToken.slice(0,20)}`),!0}catch{return _(),!1}finally{i.value.refreshingToken=!1}})();const e=await y;return y=null,e},te=async()=>{const e=`profile:${o.value.accessToken.slice(0,20)}`;i.value.loadingProfile=!0;try{return await v(e,async()=>{const t=await fetch(n("profile"),{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value?.accessToken}`}});if(!t.ok)throw t.status===401?new Error("Authentication expired. Please sign in again."):new Error(`Failed to fetch profile: ${t.status} ${t.statusText}`);const a=await t.json();return s.value=E(a),s.value&&typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(s.value)),s.value})}finally{i.value.loadingProfile=!1}},ae=async e=>{i.value.loadingProfile=!0;try{const t=await fetch(n("profile"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({first_name:e.firstName,last_name:e.lastName})});if(!t.ok)throw t.status===401?new Error("Authentication expired. Please sign in again."):new Error(`Profile update failed: ${t.status} ${t.statusText}`);const a=await t.json();return s.value=E(a),s.value&&F("strands_auth_user",JSON.stringify(s.value)),s.value}finally{i.value.loadingProfile=!1}},ne=async e=>{i.value.loadingProfile=!0;try{const t=await fetch(n("settings"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({settings:e})});if(!t.ok)throw t.status===401?new Error("Authentication expired. Please sign in again."):new Error(`Settings update failed: ${t.status} ${t.statusText}`);const a=await t.json();return s.value=E(a),s.value&&F("strands_auth_user",JSON.stringify(s.value)),s.value}finally{i.value.loadingProfile=!1}},se=async(e,t)=>{i.value.loadingProfile=!0;try{const a=await fetch(n("changeEmail"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({new_email:e,password:t})});if(!a.ok){if(a.status===401)throw new Error("Authentication expired. Please sign in again.");{const c=await a.json().catch(()=>({}));throw new Error(c.message||`Email change failed: ${a.status} ${a.statusText}`)}}const r=await a.json();return s.value&&(s.value={...s.value,email:e,emailVerified:!1,updatedAt:new Date().toISOString()},typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(s.value))),r}finally{i.value.loadingProfile=!1}},ie=async(e,t,a=!1)=>{if(!h.value)throw new Error("No MFA session available");i.value.verifyingMfa=!0;try{const r=n(a?"mfaBackupCodeVerify":"mfaSigninVerify"),c=a?{mfa_session_id:h.value,backup_code:t}:{mfa_session_id:h.value,device_id:e,code:t},l=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)});if(!l.ok){const z=await l.text();let D="MFA verification failed";try{const J=JSON.parse(z);D=J.message||J.error||z}catch{D=z||"MFA verification failed"}throw new Error(D)}const f=await l.json();return p.value=!1,h.value=null,S.value=[],await C(f),f}finally{i.value.verifyingMfa=!1}},re=async e=>{if(!h.value)throw new Error("No MFA session available");i.value.sendingMfaEmail=!0;try{const t=await fetch(n("mfaSigninSendEmail"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mfa_session_id:h.value,device_id:e})});if(!t.ok){const r=await t.text();let c="Failed to send MFA email code";try{const l=JSON.parse(r);c=l.message||l.error||r}catch{c=r||"Failed to send MFA email code"}throw new Error(c)}return await t.json()}finally{i.value.sendingMfaEmail=!1}},oe=async e=>{if(!h.value)throw new Error("No MFA session available");const t=await fetch(n("mfaWebAuthnChallenge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mfa_session_id:h.value,device_id:e})});if(!t.ok){const a=await t.text();let r="Failed to get WebAuthn challenge";try{const c=JSON.parse(a);r=c.message||c.error||a}catch{r=a||r}throw new Error(r)}return t.json()},C=async e=>{try{e.user&&(s.value=E(e.user));const t={accessToken:e.access_token,refreshToken:e.refresh_token,expiresAt:new Date(Date.now()+300*1e3),userId:s.value?.id||e.user?.id};o.value=t,typeof window<"u"&&(localStorage.setItem("strands_auth_session",JSON.stringify(t)),s.value&&localStorage.setItem("strands_auth_user",JSON.stringify(s.value))),T(),M()}catch{}},T=()=>{if(k&&clearTimeout(k),!o.value||typeof document<"u"&&document.visibilityState==="hidden")return;const e=new Date,a=o.value.expiresAt.getTime()-e.getTime()-60*1e3;if(a<=0){P();return}k=setTimeout(async()=>{(typeof document>"u"||document.visibilityState==="visible")&&await P()&&T()},a)},I=()=>{k&&(clearTimeout(k),k=null)},M=()=>{x||typeof window>"u"||(x=setInterval(()=>{s.value&&o.value&&(localStorage.getItem("strands_auth_session")||($(),_()))},2e3))},$=()=>{x&&(clearInterval(x),x=null)},N=async()=>{if(console.log("[useStrandsAuth] initialize() called, isInitialized:",w.value,"hasPromise:",!!A),w.value){console.log("[useStrandsAuth] Already initialized, setting initializing=false"),i.value.initializing=!1;return}return A?(console.log("[useStrandsAuth] Waiting for existing initialization..."),A):(console.log("[useStrandsAuth] Starting new initialization..."),A=(async()=>{i.value.initializing=!0;try{if(typeof window<"u"){const e=localStorage.getItem("strands_auth_session"),t=localStorage.getItem("strands_auth_user");if(e&&t)try{const a=JSON.parse(e),r=JSON.parse(t);a.expiresAt=new Date(a.expiresAt),a.expiresAt<=new Date&&a.refreshToken?(o.value=a,s.value=r,await Promise.race([P(),new Promise(f=>setTimeout(()=>f(!1),5e3))])||_()):a.expiresAt>new Date?(o.value=a,s.value=r,T(),M()):(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user"))}catch{localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user")}}w.value=!0,console.log("[useStrandsAuth] isInitialized set to true, currentUser:",!!s.value),await new Promise(e=>setTimeout(e,50))}catch(e){console.error("[useStrandsAuth] initialization error:",e)}finally{console.log("[useStrandsAuth] finally - setting initializing=false"),i.value.initializing=!1,A=null}})(),A)},le=async e=>{i.value.loadingProfile=!0;try{const t=await fetch(n("changeUsername"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({username:e})});if(!t.ok){const r=await t.json().catch(()=>({}));throw t.status===409?new Error("Username is already taken"):r.cooldown_end?new Error(`You can only change your username once every 30 days. You can change it again on ${new Date(r.cooldown_end).toLocaleDateString()}`):new Error(r.message||`Username change failed: ${t.status} ${t.statusText}`)}const a=await t.json();return s.value&&(s.value={...s.value,username:e,usernameLastChangedAt:new Date().toISOString(),updatedAt:new Date().toISOString()},typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(s.value))),a}finally{i.value.loadingProfile=!1}},ue=async()=>{const e=await fetch(n("usernameCooldown"),{method:"GET",headers:{Authorization:`Bearer ${o.value.accessToken}`}});if(!e.ok)throw new Error(`Failed to get username cooldown: ${e.status} ${e.statusText}`);return e.json()},ce=async e=>{const t=n("checkUsernameAvailability").replace("{username}",encodeURIComponent(e)),a=await fetch(t,{method:"GET",headers:{"Content-Type":"application/json"}});if(!a.ok)throw new Error(`Failed to check username availability: ${a.status} ${a.statusText}`);return a.json()},de=async()=>{const e=`sessions:${o.value?.accessToken?.slice(0,20)||"no-token"}`;try{return await v(e,async()=>{const t=O(),a=await fetch(n("sessions"),{method:"GET",headers:t});if(!a.ok)throw await a.text(),new Error(`Failed to get user sessions: ${a.status} ${a.statusText}`);return a.json()},120*1e3)}catch(t){throw t}},fe=async()=>{const e=await fetch(n("sessionsStats"),{method:"GET",headers:O()});if(!e.ok)throw new Error(`Failed to get session stats: ${e.status} ${e.statusText}`);return e.json()},he=async e=>{const t=n("sessionRevoke").replace("{session_id}",encodeURIComponent(e)),a=await fetch(t,{method:"POST",headers:O()});if(!a.ok)throw new Error(`Failed to revoke session: ${a.status} ${a.statusText}`);return a.status===200},ge=async()=>{const e=await fetch(n("sessionsRevokeAll"),{method:"POST",headers:O()});if(!e.ok)throw new Error(`Failed to revoke all other sessions: ${e.status} ${e.statusText}`);return e.status===200};typeof document<"u"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&o.value?(T(),ve()):document.visibilityState==="hidden"&&I()}),typeof window<"u"&&window.addEventListener("storage",e=>{(e.key==="strands_auth_session"||e.key==="strands_auth_user")&&!e.newValue&&s.value&&_()});const ve=()=>{if(!(typeof window>"u")&&s.value&&o.value){const e=localStorage.getItem("strands_auth_session"),t=localStorage.getItem("strands_auth_user");(!e||!t)&&_()}},me=()=>{I(),$(),g()};try{u.getCurrentInstance()&&u.onUnmounted(me)}catch{}return w.value||N(),{user:u.computed(()=>s.value),currentUser:u.computed(()=>s.value),currentSession:u.computed(()=>o.value),isAuthenticated:Q,isLoading:u.computed(()=>W.value||!w.value),loading:j,loadingMessage:G,isInitializing:L,isInitialized:u.computed(()=>w.value),isSigningIn:U,isSigningUp:R,isSigningOut:q,isRefreshingToken:B,isSendingMfaEmail:V,isVerifyingMfa:K,mfaRequired:u.computed(()=>p.value),mfaSessionId:u.computed(()=>h.value),availableMfaMethods:u.computed(()=>S.value),signIn:X,signUp:Z,signOut:ee,refreshToken:P,fetchProfile:te,updateProfile:ae,updateUserSettings:ne,changeEmail:se,changeUsername:le,getUsernameCooldown:ue,checkUsernameAvailability:ce,getUserSessions:de,getSessionStats:fe,revokeSession:he,revokeAllOtherSessions:ge,initialize:N,setAuthData:C,verifyMfa:ie,sendMfaEmailCode:re,getMfaWebAuthnChallenge:oe,registerHardwareKey:Y,completeHardwareKeyRegistration:H,startTokenRefreshTimer:T,stopTokenRefreshTimer:I,getAuthHeaders:O,forceReInit:()=>{w.value=!1,i.value.initializing=!0,N()}}}exports.useStrandsAuth=Te;
|
|
1
|
+
"use strict";const u=require("vue"),we=require("./useStrandsConfig-x5zDprqF.cjs.js");class ye{cache=new Map;DEFAULT_TTL=300*1e3;async fetch(d,v,g=this.DEFAULT_TTL){const b=Date.now(),s=this.cache.get(d);if(s&&b-s.timestamp<s.ttl)return s.promise;this.cleanExpired();const o=v().finally(()=>{setTimeout(()=>{this.cache.delete(d)},g)});return this.cache.set(d,{promise:o,timestamp:b,ttl:g}),o}clear(){this.cache.clear()}invalidate(d){this.cache.delete(d)}cleanExpired(){const d=Date.now();for(const[v,g]of this.cache.entries())d-g.timestamp>g.ttl&&this.cache.delete(v)}getStats(){return{size:this.cache.size,entries:Array.from(this.cache.keys())}}}const m=new ye;function pe(){return{fetch:m.fetch.bind(m),clear:m.clear.bind(m),invalidate:m.invalidate.bind(m),getStats:m.getStats.bind(m)}}function Se(n,d){let v=null;return(...g)=>{v&&clearTimeout(v),v=setTimeout(()=>{n(...g)},d)}}const F=Se((n,d)=>{typeof window<"u"&&localStorage.setItem(n,d)},300),E=n=>({id:n.id,email:n.email,firstName:n.first_name||n.firstName||"",lastName:n.last_name||n.lastName||"",avatar:n.avatar_url||n.avatar,mfaEnabled:n.mfa_enabled??n.mfaEnabled??!1,emailVerified:n.email_verified??n.emailVerified??!1,passwordUpdatedAt:n.password_updated_at||n.passwordUpdatedAt,settings:n.settings||{},xp:n.xp||0,level:n.level||1,next_level_xp:n.next_level_xp||n.next_level_xp||4,username:n.username,usernameLastChangedAt:n.username_last_changed_at||n.usernameLastChangedAt,createdAt:n.created_at||n.createdAt,updatedAt:n.updated_at||n.updatedAt||new Date().toISOString()}),_e={currentUser:u.ref(null),currentSession:u.ref(null),loadingStates:u.ref({initializing:!0,signingIn:!1,signingUp:!1,signingOut:!1,refreshingToken:!1,sendingMfaEmail:!1,verifyingMfa:!1,loadingProfile:!1}),isInitialized:u.ref(!1),mfaRequired:u.ref(!1),mfaSessionId:u.ref(null),availableMfaMethods:u.ref([])};let k=null,y=null,x=null,A=null;function Te(){const{getUrl:n,config:d}=we.useStrandsConfig(),{fetch:v,clear:g,invalidate:b}=pe(),{currentUser:s,currentSession:o,loadingStates:i,isInitialized:w,mfaRequired:p,mfaSessionId:h,availableMfaMethods:S}=_e,_=()=>{if(s.value=null,o.value=null,p.value=!1,h.value=null,S.value=[],typeof window<"u"&&(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user")),I(),$(),y=null,g(),typeof window<"u"&&d.value?.onSignOutUrl){const e=window.location.pathname+window.location.search,t=d.value.onSignOutUrl;e!==t&&(window.location.href=t)}},L=u.computed(()=>i.value.initializing),U=u.computed(()=>i.value.signingIn),R=u.computed(()=>i.value.signingUp),q=u.computed(()=>i.value.signingOut),B=u.computed(()=>i.value.refreshingToken),V=u.computed(()=>i.value.sendingMfaEmail),K=u.computed(()=>i.value.verifyingMfa);u.computed(()=>i.value.loadingProfile);const j=u.computed(()=>i.value.signingIn||i.value.signingUp||i.value.signingOut||i.value.refreshingToken||i.value.sendingMfaEmail||i.value.verifyingMfa||i.value.loadingProfile),W=u.computed(()=>i.value.initializing||j.value),G=u.computed(()=>{const e=i.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..."}),O=()=>{const e={};return o.value?.accessToken&&(e.Authorization=`Bearer ${o.value.accessToken}`),o.value?.refreshToken&&(e["x-refresh-token"]=o.value.refreshToken),e},H=async(e,t,a)=>{const r=await fetch(n("mfaHardwareCompleteRegistration"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({device_id:e,credential:t})});if(!r.ok){const c=await r.text();let l="Failed to complete hardware key registration";try{const f=JSON.parse(c);l=f.message||f.error||c}catch{l=c||"Failed to complete hardware key registration"}throw new Error(l)}return r.json()},Y=async(e,t,a="hardware")=>{const r=await fetch(n("mfaHardwareStartRegistration"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({device_name:e,device_type:a})});if(!r.ok){const c=await r.text();let l="Failed to start hardware key registration";try{const f=JSON.parse(c);l=f.message||f.error||c}catch{l=c||"Failed to start hardware key registration"}throw new Error(l)}return r.json()},Q=u.computed(()=>s.value!==null),X=async e=>{i.value.signingIn=!0;try{p.value=!1,h.value=null,S.value=[];const t={"Content-Type":"application/json"};typeof window<"u"&&window.location&&(t.Origin=window.location.origin);const a=await fetch(n("signIn"),{method:"POST",headers:t,body:JSON.stringify(e)});if(!a.ok)throw a.status===401?new Error("Invalid email or password"):a.status===403?new Error("Please verify your email address before signing in"):new Error(`Sign in failed: ${a.status} ${a.statusText}`);const r=await a.json();if(r.mfa_required){p.value=!0,h.value=r.mfa_session_id||null;const c=(r.available_mfa_methods||[]).map(l=>{let f=`${l.device_type.charAt(0).toUpperCase()+l.device_type.slice(1)} Authentication`;return l.device_type==="hardware"?f=l.device_name||"Security Key":l.device_type==="totp"?f=l.device_name||"Authenticator App":l.device_type==="email"&&(f=l.device_name||"Email Verification"),{id:l.device_id,device_type:l.device_type,device_name:l.device_name||f,is_active:!0,created_at:new Date().toISOString(),last_used_at:l.last_used_at,credential_id:l.credential_id,device_info:l.device_info}});return S.value=c,i.value.signingIn=!1,r}return await C(r),r}catch(t){throw t}finally{i.value.signingIn=!1}},Z=async e=>{i.value.signingUp=!0;try{throw new Error("Sign up not implemented - please integrate with auth SDK")}finally{i.value.signingUp=!1}},ee=async()=>{i.value.signingOut=!0;try{I(),$(),y=null,g(),s.value=null,o.value=null,p.value=!1,h.value=null,S.value=[],typeof window<"u"&&(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user")),typeof window<"u"&&d.value?.onSignOutUrl&&(window.location.href=d.value.onSignOutUrl)}finally{i.value.signingOut=!1}},P=async()=>{if(!o.value?.refreshToken)return!1;if(y)return await y;y=(async()=>{i.value.refreshingToken=!0;try{const t=await fetch(n("refresh"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh_token:o.value.refreshToken})});if(!t.ok){if(t.status===401)return _(),!1;throw new Error(`Token refresh failed: ${t.status} ${t.statusText}`)}const a=await t.json();a.user&&(s.value=E(a.user),s.value&&typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(s.value)));const r={accessToken:a.access_token,refreshToken:a.refresh_token,expiresAt:new Date(Date.now()+300*1e3),userId:a.user?.id||s.value?.id};return o.value=r,typeof window<"u"&&localStorage.setItem("strands_auth_session",JSON.stringify(r)),T(),M(),b(`sessions:${o.value.accessToken.slice(0,20)}`),!0}catch{return _(),!1}finally{i.value.refreshingToken=!1}})();const e=await y;return y=null,e},te=async()=>{const e=`profile:${o.value.accessToken.slice(0,20)}`;i.value.loadingProfile=!0;try{return await v(e,async()=>{const t=await fetch(n("profile"),{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value?.accessToken}`}});if(!t.ok)throw t.status===401?new Error("Authentication expired. Please sign in again."):new Error(`Failed to fetch profile: ${t.status} ${t.statusText}`);const a=await t.json();return s.value=E(a),s.value&&typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(s.value)),s.value})}finally{i.value.loadingProfile=!1}},ae=async e=>{i.value.loadingProfile=!0;try{const t=await fetch(n("profile"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({first_name:e.firstName,last_name:e.lastName})});if(!t.ok)throw t.status===401?new Error("Authentication expired. Please sign in again."):new Error(`Profile update failed: ${t.status} ${t.statusText}`);const a=await t.json();return s.value=E(a),s.value&&F("strands_auth_user",JSON.stringify(s.value)),s.value}finally{i.value.loadingProfile=!1}},ne=async e=>{i.value.loadingProfile=!0;try{const t=await fetch(n("settings"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({settings:e})});if(!t.ok)throw t.status===401?new Error("Authentication expired. Please sign in again."):new Error(`Settings update failed: ${t.status} ${t.statusText}`);const a=await t.json();return s.value=E(a),s.value&&F("strands_auth_user",JSON.stringify(s.value)),s.value}finally{i.value.loadingProfile=!1}},se=async(e,t)=>{i.value.loadingProfile=!0;try{const a=await fetch(n("changeEmail"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({new_email:e,password:t})});if(!a.ok){if(a.status===401)throw new Error("Authentication expired. Please sign in again.");{const c=await a.json().catch(()=>({}));throw new Error(c.message||`Email change failed: ${a.status} ${a.statusText}`)}}const r=await a.json();return s.value&&(s.value={...s.value,email:e,emailVerified:!1,updatedAt:new Date().toISOString()},typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(s.value))),r}finally{i.value.loadingProfile=!1}},ie=async(e,t,a=!1)=>{if(!h.value)throw new Error("No MFA session available");i.value.verifyingMfa=!0;try{const r=n(a?"mfaBackupCodeVerify":"mfaSigninVerify"),c=a?{mfa_session_id:h.value,backup_code:t}:{mfa_session_id:h.value,device_id:e,code:t},l=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)});if(!l.ok){const z=await l.text();let D="MFA verification failed";try{const J=JSON.parse(z);D=J.message||J.error||z}catch{D=z||"MFA verification failed"}throw new Error(D)}const f=await l.json();return p.value=!1,h.value=null,S.value=[],await C(f),f}finally{i.value.verifyingMfa=!1}},re=async e=>{if(!h.value)throw new Error("No MFA session available");i.value.sendingMfaEmail=!0;try{const t=await fetch(n("mfaSigninSendEmail"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mfa_session_id:h.value,device_id:e})});if(!t.ok){const r=await t.text();let c="Failed to send MFA email code";try{const l=JSON.parse(r);c=l.message||l.error||r}catch{c=r||"Failed to send MFA email code"}throw new Error(c)}return await t.json()}finally{i.value.sendingMfaEmail=!1}},oe=async e=>{if(!h.value)throw new Error("No MFA session available");const t=await fetch(n("mfaWebAuthnChallenge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mfa_session_id:h.value,device_id:e})});if(!t.ok){const a=await t.text();let r="Failed to get WebAuthn challenge";try{const c=JSON.parse(a);r=c.message||c.error||a}catch{r=a||r}throw new Error(r)}return t.json()},C=async e=>{try{e.user&&(s.value=E(e.user));const t={accessToken:e.access_token,refreshToken:e.refresh_token,expiresAt:new Date(Date.now()+300*1e3),userId:s.value?.id||e.user?.id};o.value=t,typeof window<"u"&&(localStorage.setItem("strands_auth_session",JSON.stringify(t)),s.value&&localStorage.setItem("strands_auth_user",JSON.stringify(s.value))),T(),M()}catch{}},T=()=>{if(k&&clearTimeout(k),!o.value||typeof document<"u"&&document.visibilityState==="hidden")return;const e=new Date,a=o.value.expiresAt.getTime()-e.getTime()-60*1e3;if(a<=0){P();return}k=setTimeout(async()=>{(typeof document>"u"||document.visibilityState==="visible")&&await P()&&T()},a)},I=()=>{k&&(clearTimeout(k),k=null)},M=()=>{x||typeof window>"u"||(x=setInterval(()=>{s.value&&o.value&&(localStorage.getItem("strands_auth_session")||($(),_()))},2e3))},$=()=>{x&&(clearInterval(x),x=null)},N=async()=>{if(console.log("[useStrandsAuth] initialize() called, isInitialized:",w.value,"hasPromise:",!!A),w.value){console.log("[useStrandsAuth] Already initialized, setting initializing=false"),i.value.initializing=!1;return}return A?(console.log("[useStrandsAuth] Waiting for existing initialization..."),A):(console.log("[useStrandsAuth] Starting new initialization..."),A=(async()=>{i.value.initializing=!0;try{if(typeof window<"u"){const e=localStorage.getItem("strands_auth_session"),t=localStorage.getItem("strands_auth_user");if(e&&t)try{const a=JSON.parse(e),r=JSON.parse(t);a.expiresAt=new Date(a.expiresAt),a.expiresAt<=new Date&&a.refreshToken?(o.value=a,s.value=r,await Promise.race([P(),new Promise(f=>setTimeout(()=>f(!1),5e3))])||_()):a.expiresAt>new Date?(o.value=a,s.value=r,T(),M()):(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user"))}catch{localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user")}}w.value=!0,console.log("[useStrandsAuth] isInitialized set to true, currentUser:",!!s.value),await new Promise(e=>setTimeout(e,50))}catch(e){console.error("[useStrandsAuth] initialization error:",e)}finally{console.log("[useStrandsAuth] finally - setting initializing=false"),i.value.initializing=!1,A=null}})(),A)},le=async e=>{i.value.loadingProfile=!0;try{const t=await fetch(n("changeUsername"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({username:e})});if(!t.ok){const r=await t.json().catch(()=>({}));throw t.status===409?new Error("Username is already taken"):r.cooldown_end?new Error(`You can only change your username once every 30 days. You can change it again on ${new Date(r.cooldown_end).toLocaleDateString()}`):new Error(r.message||`Username change failed: ${t.status} ${t.statusText}`)}const a=await t.json();return s.value&&(s.value={...s.value,username:e,usernameLastChangedAt:new Date().toISOString(),updatedAt:new Date().toISOString()},typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(s.value))),a}finally{i.value.loadingProfile=!1}},ue=async()=>{const e=await fetch(n("usernameCooldown"),{method:"GET",headers:{Authorization:`Bearer ${o.value.accessToken}`}});if(!e.ok)throw new Error(`Failed to get username cooldown: ${e.status} ${e.statusText}`);return e.json()},ce=async e=>{const t=n("checkUsernameAvailability").replace("{username}",encodeURIComponent(e)),a=await fetch(t,{method:"GET",headers:{"Content-Type":"application/json"}});if(!a.ok)throw new Error(`Failed to check username availability: ${a.status} ${a.statusText}`);return a.json()},de=async()=>{const e=`sessions:${o.value?.accessToken?.slice(0,20)||"no-token"}`;try{return await v(e,async()=>{const t=O(),a=await fetch(n("sessions"),{method:"GET",headers:t});if(!a.ok)throw await a.text(),new Error(`Failed to get user sessions: ${a.status} ${a.statusText}`);return a.json()},120*1e3)}catch(t){throw t}},fe=async()=>{const e=await fetch(n("sessionsStats"),{method:"GET",headers:O()});if(!e.ok)throw new Error(`Failed to get session stats: ${e.status} ${e.statusText}`);return e.json()},he=async e=>{const t=n("sessionRevoke").replace("{session_id}",encodeURIComponent(e)),a=await fetch(t,{method:"POST",headers:O()});if(!a.ok)throw new Error(`Failed to revoke session: ${a.status} ${a.statusText}`);return a.status===200},ge=async()=>{const e=await fetch(n("sessionsRevokeAll"),{method:"POST",headers:O()});if(!e.ok)throw new Error(`Failed to revoke all other sessions: ${e.status} ${e.statusText}`);return e.status===200};typeof document<"u"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&o.value?(T(),ve()):document.visibilityState==="hidden"&&I()}),typeof window<"u"&&window.addEventListener("storage",e=>{(e.key==="strands_auth_session"||e.key==="strands_auth_user")&&!e.newValue&&s.value&&_()});const ve=()=>{if(!(typeof window>"u")&&s.value&&o.value){const e=localStorage.getItem("strands_auth_session"),t=localStorage.getItem("strands_auth_user");(!e||!t)&&_()}},me=()=>{I(),$(),g()};try{u.getCurrentInstance()&&u.onUnmounted(me)}catch{}return w.value||N(),{user:u.computed(()=>s.value),currentUser:u.computed(()=>s.value),currentSession:u.computed(()=>o.value),isAuthenticated:Q,isLoading:u.computed(()=>W.value||!w.value),loading:j,loadingMessage:G,isInitializing:L,isInitialized:u.computed(()=>w.value),isSigningIn:U,isSigningUp:R,isSigningOut:q,isRefreshingToken:B,isSendingMfaEmail:V,isVerifyingMfa:K,mfaRequired:u.computed(()=>p.value),mfaSessionId:u.computed(()=>h.value),availableMfaMethods:u.computed(()=>S.value),signIn:X,signUp:Z,signOut:ee,refreshToken:P,fetchProfile:te,updateProfile:ae,updateUserSettings:ne,changeEmail:se,changeUsername:le,getUsernameCooldown:ue,checkUsernameAvailability:ce,getUserSessions:de,getSessionStats:fe,revokeSession:he,revokeAllOtherSessions:ge,initialize:N,setAuthData:C,verifyMfa:ie,sendMfaEmailCode:re,getMfaWebAuthnChallenge:oe,registerHardwareKey:Y,completeHardwareKeyRegistration:H,startTokenRefreshTimer:T,stopTokenRefreshTimer:I,getAuthHeaders:O,forceReInit:()=>{w.value=!1,i.value.initializing=!0,N()}}}exports.useStrandsAuth=Te;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { computed as c, ref as y, getCurrentInstance as ye, onUnmounted as pe } from "vue";
|
|
2
|
-
import { u as Se } from "./useStrandsConfig-
|
|
2
|
+
import { u as Se } from "./useStrandsConfig-C9TOTAfh.es.js";
|
|
3
3
|
class _e {
|
|
4
4
|
cache = /* @__PURE__ */ new Map();
|
|
5
5
|
DEFAULT_TTL = 300 * 1e3;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const u=require("vue"),c={baseUrl:"https://your-api.example.com",accentColor:"#EA00A8",redirectUrl:"/",onSignInUrl:"/dashboard",onSignOutUrl:"/",authUrl:"/auth",autoRefresh:!0,refreshInterval:4,protectedRoutes:[],guestOnlyRoutes:["/auth","/login","/register"],devMode:!1,styles:!0,endpoints:{},useSquircle:!0,theme:"system"},a={signIn:"/api/v1/auth/sign-in",signUp:"/api/v1/auth/sign-up",signOut:"/api/v1/auth/sign-out",refresh:"/api/v1/auth/refresh",passwordReset:"/api/v1/auth/password-reset",passwordResetConfirm:"/api/v1/auth/password-reset/confirm",completeRegistration:"/api/v1/auth/complete-registration",profile:"/api/v1/user/profile",verifyEmail:"/api/v1/auth/verify-email",oauthProviders:"/api/v1/oauth/providers",oauthProvider:"/api/v1/oauth/providers/{provider_id}",changeEmail:"/api/v1/user/change-email",avatar:"/api/v1/user/avatar",settings:"/api/v1/user/settings",changeUsername:"/api/v1/user/username",usernameCooldown:"/api/v1/user/username/cooldown",checkUsernameAvailability:"/api/v1/username/{username}/available",mfaDevices:"/api/v1/mfa/devices",mfaTotpSetup:"/api/v1/mfa/totp/setup",mfaTotpVerify:"/api/v1/mfa/totp/verify",mfaEmailSetup:"/api/v1/mfa/email/setup",mfaEmailSend:"/api/v1/mfa/email/send",mfaEmailVerify:"/api/v1/mfa/email/verify",mfaDeviceDisable:"/api/v1/mfa/device/disable",mfaBackupCodes:"/api/v1/mfa/backup-codes/regenerate",mfaHardwareStartRegistration:"/api/v1/mfa/hardware/start-registration",mfaHardwareCompleteRegistration:"/api/v1/mfa/hardware/complete-registration",mfaSigninSendEmail:"/api/v1/auth/mfa/email/send",mfaSigninVerify:"/api/v1/auth/mfa/verify",mfaBackupCodeVerify:"/api/v1/auth/mfa/backup-code/verify",mfaWebAuthnChallenge:"/api/v1/auth/mfa/webauthn/challenge",sessions:"/api/v1/sessions",sessionsStats:"/api/v1/sessions/stats",sessionRevoke:"/api/v1/sessions/{session_id}/revoke",sessionsRevokeAll:"/api/v1/sessions/revoke-all"},p=Symbol("strands-config"),m=u.ref(null);function v(s){if(typeof window>"u"||!document.documentElement)return;if(typeof CSS<"u"&&CSS.registerProperty)try{CSS.registerProperty({name:"--strands-accent",syntax:"<color>",inherits:!0,initialValue:s})}catch{}document.documentElement.style.setProperty("--strands-accent",s),document.documentElement.style.setProperty("--accui-strands-accent",s);const t={"--accui-strands-50":`color-mix(in srgb, ${s} 10%, white)`,"--accui-strands-100":`color-mix(in srgb, ${s} 20%, white)`,"--accui-strands-200":`color-mix(in srgb, ${s} 30%, white)`,"--accui-strands-300":`color-mix(in srgb, ${s} 40%, white)`,"--accui-strands-400":`color-mix(in srgb, ${s} 70%, white)`,"--accui-strands-500":s,"--accui-strands-600":`color-mix(in srgb, ${s} 85%, black)`,"--accui-strands-700":`color-mix(in srgb, ${s} 70%, black)`,"--accui-strands-800":`color-mix(in srgb, ${s} 55%, black)`,"--accui-strands-900":`color-mix(in srgb, ${s} 40%, black)`,"--accui-strands-950":`color-mix(in srgb, ${s} 25%, black)`};for(const[r,n]of Object.entries(t))document.documentElement.style.setProperty(r,n)}function g(s){if(m.value=s,typeof window<"u"&&document.documentElement){const t=s.useSquircle!==void 0?s.useSquircle:!0;document.documentElement.style.setProperty("--strands-allow-squircle",t?"1":"0"),s.accentColor&&v(s.accentColor)}try{u.provide(p,s)}catch(t){console.warn("[Strands Auth] Could not provide config via Vue provide/inject. Config available via global state only.",t)}}function h(s){let t=null;try{u.getCurrentInstance()&&(t=u.inject(p,null))}catch{t=null}let r=null;try{if(typeof window<"u"){if(window.__STRANDS_CONFIG__)r=window.__STRANDS_CONFIG__;else if(window.__NUXT__){const i=window.__NUXT__;r=i?.config?.public?.strandsAuth||i?.public?.strandsAuth||i?.strandsAuth}}}catch(i){console.error("[Strands Auth] Error accessing runtime configuration:",i)}const n=u.computed(()=>{const i={...c,...s||{},...t||{},...m.value||{},...r||{}};if(i.baseUrl===c.baseUrl&&typeof window>"u"&&console.warn("[Strands Auth] No baseUrl configured for SSR. Please provide a baseUrl in your strandsAuth configuration."),typeof window<"u"&&document.documentElement){const e=i.useSquircle!==void 0?i.useSquircle:!0;document.documentElement.style.setProperty("--strands-allow-squircle",e?"1":"0"),i.accentColor&&document.documentElement.style.setProperty("--strands-accent",i.accentColor)}return i}),l=u.computed(()=>{const e=n.value.endpoints||{};return{signIn:e.signIn||a.signIn,signUp:e.signUp||a.signUp,signOut:e.signOut||a.signOut,refresh:e.refresh||a.refresh,passwordReset:e.passwordReset||a.passwordReset,passwordResetConfirm:e.passwordResetConfirm||a.passwordResetConfirm,completeRegistration:e.completeRegistration||a.completeRegistration,profile:e.profile||a.profile,verifyEmail:e.verifyEmail||a.verifyEmail,oauthProviders:e.oauthProviders||a.oauthProviders,oauthProvider:e.oauthProvider||a.oauthProvider,changeEmail:e.changeEmail||a.changeEmail,avatar:e.avatar||a.avatar,settings:e.settings||a.settings,changeUsername:e.changeUsername||a.changeUsername,usernameCooldown:e.usernameCooldown||a.usernameCooldown,checkUsernameAvailability:e.checkUsernameAvailability||a.checkUsernameAvailability,mfaDevices:e.mfaDevices||a.mfaDevices,mfaTotpSetup:e.mfaTotpSetup||a.mfaTotpSetup,mfaTotpVerify:e.mfaTotpVerify||a.mfaTotpVerify,mfaEmailSetup:e.mfaEmailSetup||a.mfaEmailSetup,mfaEmailSend:e.mfaEmailSend||a.mfaEmailSend,mfaEmailVerify:e.mfaEmailVerify||a.mfaEmailVerify,mfaDeviceDisable:e.mfaDeviceDisable||a.mfaDeviceDisable,mfaBackupCodes:e.mfaBackupCodes||a.mfaBackupCodes,mfaHardwareStartRegistration:e.mfaHardwareStartRegistration||a.mfaHardwareStartRegistration,mfaHardwareCompleteRegistration:e.mfaHardwareCompleteRegistration||a.mfaHardwareCompleteRegistration,mfaSigninSendEmail:e.mfaSigninSendEmail||a.mfaSigninSendEmail,mfaSigninVerify:e.mfaSigninVerify||a.mfaSigninVerify,mfaBackupCodeVerify:e.mfaBackupCodeVerify||a.mfaBackupCodeVerify,mfaWebAuthnChallenge:e.mfaWebAuthnChallenge||a.mfaWebAuthnChallenge,sessions:e.sessions||a.sessions,sessionsStats:e.sessionsStats||a.sessionsStats,sessionRevoke:e.sessionRevoke||a.sessionRevoke,sessionsRevokeAll:e.sessionsRevokeAll||a.sessionsRevokeAll}});return{config:n,endpoints:l,getUrl:i=>{const e=n.value;if(!e.baseUrl)throw new Error("Base URL is required in configuration");let o;typeof i=="string"&&i in l.value?o=l.value[i]:typeof i=="string"?o=i:o=l.value[i];const f=e.baseUrl.replace(/\/$/,""),d=o.startsWith("/")?o:`/${o}`;return console.debug(`[Strands Auth] Constructing URL for endpoint "${i}": ${f}${d}`),`${f}${d}`},getSupportEmail:()=>n.value.supportEmail||null}}function S(s){if(m.value=s,typeof window<"u"&&document.documentElement){const t=s.useSquircle!==void 0?s.useSquircle:!0;document.documentElement.style.setProperty("--strands-allow-squircle",t?"1":"0"),s.accentColor&&v(s.accentColor)}}const y=Object.freeze(Object.defineProperty({__proto__:null,provideStrandsConfig:g,setStrandsConfig:S,useStrandsConfig:h},Symbol.toStringTag,{value:"Module"}));exports.STRANDS_AUTH_DEFAULTS=c;exports.provideStrandsConfig=g;exports.setStrandsConfig=S;exports.useStrandsConfig=h;exports.useStrandsConfig$1=y;
|
package/dist/vite.cjs.js
CHANGED
|
@@ -26,4 +26,4 @@ if (typeof window !== 'undefined') {
|
|
|
26
26
|
window.__STRANDS_INJECTED__ = true
|
|
27
27
|
}
|
|
28
28
|
`}
|
|
29
|
-
${s}`,map:null}:null}}}function d(i={}){return{install(a){Promise.resolve().then(()=>require("./StrandsUIPlugin-CW3qy44s.cjs.js")).then(n=>n.StrandsUIPlugin$1).then(n=>{const r=n.default;a.use(r)}),Promise.resolve().then(()=>require("./useStrandsConfig-
|
|
29
|
+
${s}`,map:null}:null}}}function d(i={}){return{install(a){Promise.resolve().then(()=>require("./StrandsUIPlugin-CW3qy44s.cjs.js")).then(n=>n.StrandsUIPlugin$1).then(n=>{const r=n.default;a.use(r)}),Promise.resolve().then(()=>require("./useStrandsConfig-x5zDprqF.cjs.js")).then(n=>n.useStrandsConfig$1).then(n=>{const{setStrandsConfig:r}=n;r(i),typeof window<"u"&&(window.__STRANDS_CONFIG__=i)})}}}exports.StrandsAuth=e;exports.StrandsAuthVitePlugin=e;exports.createStrandsAuth=d;exports.default=e;exports.strandsAuth=e;
|
package/dist/vite.es.js
CHANGED
|
@@ -76,7 +76,7 @@ function d(r = {}) {
|
|
|
76
76
|
import("./StrandsUIPlugin-Ck-X6Cjd.es.js").then((n) => n.n).then((n) => {
|
|
77
77
|
const i = n.default;
|
|
78
78
|
a.use(i);
|
|
79
|
-
}), import("./useStrandsConfig-
|
|
79
|
+
}), import("./useStrandsConfig-C9TOTAfh.es.js").then((n) => n.a).then((n) => {
|
|
80
80
|
const { setStrandsConfig: i } = n;
|
|
81
81
|
i(r), typeof window < "u" && (window.__STRANDS_CONFIG__ = r);
|
|
82
82
|
});
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const u=require("vue"),c={baseUrl:"https://your-api.example.com",accentColor:"#EA00A8",redirectUrl:"/",onSignInUrl:"/dashboard",onSignOutUrl:"/",authUrl:"/auth",autoRefresh:!0,refreshInterval:4,protectedRoutes:[],guestOnlyRoutes:["/auth","/login","/register"],devMode:!1,styles:!0,endpoints:{},useSquircle:!0},a={signIn:"/api/v1/auth/sign-in",signUp:"/api/v1/auth/sign-up",signOut:"/api/v1/auth/sign-out",refresh:"/api/v1/auth/refresh",passwordReset:"/api/v1/auth/password-reset",passwordResetConfirm:"/api/v1/auth/password-reset/confirm",completeRegistration:"/api/v1/auth/complete-registration",profile:"/api/v1/user/profile",verifyEmail:"/api/v1/auth/verify-email",oauthProviders:"/api/v1/oauth/providers",oauthProvider:"/api/v1/oauth/providers/{provider_id}",changeEmail:"/api/v1/user/change-email",avatar:"/api/v1/user/avatar",settings:"/api/v1/user/settings",changeUsername:"/api/v1/user/username",usernameCooldown:"/api/v1/user/username/cooldown",checkUsernameAvailability:"/api/v1/username/{username}/available",mfaDevices:"/api/v1/mfa/devices",mfaTotpSetup:"/api/v1/mfa/totp/setup",mfaTotpVerify:"/api/v1/mfa/totp/verify",mfaEmailSetup:"/api/v1/mfa/email/setup",mfaEmailSend:"/api/v1/mfa/email/send",mfaEmailVerify:"/api/v1/mfa/email/verify",mfaDeviceDisable:"/api/v1/mfa/device/disable",mfaBackupCodes:"/api/v1/mfa/backup-codes/regenerate",mfaHardwareStartRegistration:"/api/v1/mfa/hardware/start-registration",mfaHardwareCompleteRegistration:"/api/v1/mfa/hardware/complete-registration",mfaSigninSendEmail:"/api/v1/auth/mfa/email/send",mfaSigninVerify:"/api/v1/auth/mfa/verify",mfaBackupCodeVerify:"/api/v1/auth/mfa/backup-code/verify",mfaWebAuthnChallenge:"/api/v1/auth/mfa/webauthn/challenge",sessions:"/api/v1/sessions",sessionsStats:"/api/v1/sessions/stats",sessionRevoke:"/api/v1/sessions/{session_id}/revoke",sessionsRevokeAll:"/api/v1/sessions/revoke-all"},p=Symbol("strands-config"),m=u.ref(null);function v(s){if(typeof window>"u"||!document.documentElement)return;if(typeof CSS<"u"&&CSS.registerProperty)try{CSS.registerProperty({name:"--strands-accent",syntax:"<color>",inherits:!0,initialValue:s})}catch{}document.documentElement.style.setProperty("--strands-accent",s),document.documentElement.style.setProperty("--accui-strands-accent",s);const t={"--accui-strands-50":`color-mix(in srgb, ${s} 10%, white)`,"--accui-strands-100":`color-mix(in srgb, ${s} 20%, white)`,"--accui-strands-200":`color-mix(in srgb, ${s} 30%, white)`,"--accui-strands-300":`color-mix(in srgb, ${s} 40%, white)`,"--accui-strands-400":`color-mix(in srgb, ${s} 70%, white)`,"--accui-strands-500":s,"--accui-strands-600":`color-mix(in srgb, ${s} 85%, black)`,"--accui-strands-700":`color-mix(in srgb, ${s} 70%, black)`,"--accui-strands-800":`color-mix(in srgb, ${s} 55%, black)`,"--accui-strands-900":`color-mix(in srgb, ${s} 40%, black)`,"--accui-strands-950":`color-mix(in srgb, ${s} 25%, black)`};for(const[r,n]of Object.entries(t))document.documentElement.style.setProperty(r,n)}function g(s){if(m.value=s,typeof window<"u"&&document.documentElement){const t=s.useSquircle!==void 0?s.useSquircle:!0;document.documentElement.style.setProperty("--strands-allow-squircle",t?"1":"0"),s.accentColor&&v(s.accentColor)}try{u.provide(p,s)}catch(t){console.warn("[Strands Auth] Could not provide config via Vue provide/inject. Config available via global state only.",t)}}function h(s){let t=null;try{u.getCurrentInstance()&&(t=u.inject(p,null))}catch{t=null}let r=null;try{if(typeof window<"u"){if(window.__STRANDS_CONFIG__)r=window.__STRANDS_CONFIG__;else if(window.__NUXT__){const i=window.__NUXT__;r=i?.config?.public?.strandsAuth||i?.public?.strandsAuth||i?.strandsAuth}}}catch(i){console.error("[Strands Auth] Error accessing runtime configuration:",i)}const n=u.computed(()=>{const i={...c,...s||{},...t||{},...m.value||{},...r||{}};if(i.baseUrl===c.baseUrl&&typeof window>"u"&&console.warn("[Strands Auth] No baseUrl configured for SSR. Please provide a baseUrl in your strandsAuth configuration."),typeof window<"u"&&document.documentElement){const e=i.useSquircle!==void 0?i.useSquircle:!0;document.documentElement.style.setProperty("--strands-allow-squircle",e?"1":"0"),i.accentColor&&document.documentElement.style.setProperty("--strands-accent",i.accentColor)}return i}),l=u.computed(()=>{const e=n.value.endpoints||{};return{signIn:e.signIn||a.signIn,signUp:e.signUp||a.signUp,signOut:e.signOut||a.signOut,refresh:e.refresh||a.refresh,passwordReset:e.passwordReset||a.passwordReset,passwordResetConfirm:e.passwordResetConfirm||a.passwordResetConfirm,completeRegistration:e.completeRegistration||a.completeRegistration,profile:e.profile||a.profile,verifyEmail:e.verifyEmail||a.verifyEmail,oauthProviders:e.oauthProviders||a.oauthProviders,oauthProvider:e.oauthProvider||a.oauthProvider,changeEmail:e.changeEmail||a.changeEmail,avatar:e.avatar||a.avatar,settings:e.settings||a.settings,changeUsername:e.changeUsername||a.changeUsername,usernameCooldown:e.usernameCooldown||a.usernameCooldown,checkUsernameAvailability:e.checkUsernameAvailability||a.checkUsernameAvailability,mfaDevices:e.mfaDevices||a.mfaDevices,mfaTotpSetup:e.mfaTotpSetup||a.mfaTotpSetup,mfaTotpVerify:e.mfaTotpVerify||a.mfaTotpVerify,mfaEmailSetup:e.mfaEmailSetup||a.mfaEmailSetup,mfaEmailSend:e.mfaEmailSend||a.mfaEmailSend,mfaEmailVerify:e.mfaEmailVerify||a.mfaEmailVerify,mfaDeviceDisable:e.mfaDeviceDisable||a.mfaDeviceDisable,mfaBackupCodes:e.mfaBackupCodes||a.mfaBackupCodes,mfaHardwareStartRegistration:e.mfaHardwareStartRegistration||a.mfaHardwareStartRegistration,mfaHardwareCompleteRegistration:e.mfaHardwareCompleteRegistration||a.mfaHardwareCompleteRegistration,mfaSigninSendEmail:e.mfaSigninSendEmail||a.mfaSigninSendEmail,mfaSigninVerify:e.mfaSigninVerify||a.mfaSigninVerify,mfaBackupCodeVerify:e.mfaBackupCodeVerify||a.mfaBackupCodeVerify,mfaWebAuthnChallenge:e.mfaWebAuthnChallenge||a.mfaWebAuthnChallenge,sessions:e.sessions||a.sessions,sessionsStats:e.sessionsStats||a.sessionsStats,sessionRevoke:e.sessionRevoke||a.sessionRevoke,sessionsRevokeAll:e.sessionsRevokeAll||a.sessionsRevokeAll}});return{config:n,endpoints:l,getUrl:i=>{const e=n.value;if(!e.baseUrl)throw new Error("Base URL is required in configuration");let o;typeof i=="string"&&i in l.value?o=l.value[i]:typeof i=="string"?o=i:o=l.value[i];const f=e.baseUrl.replace(/\/$/,""),d=o.startsWith("/")?o:`/${o}`;return console.debug(`[Strands Auth] Constructing URL for endpoint "${i}": ${f}${d}`),`${f}${d}`},getSupportEmail:()=>n.value.supportEmail||null}}function S(s){if(m.value=s,typeof window<"u"&&document.documentElement){const t=s.useSquircle!==void 0?s.useSquircle:!0;document.documentElement.style.setProperty("--strands-allow-squircle",t?"1":"0"),s.accentColor&&v(s.accentColor)}}const y=Object.freeze(Object.defineProperty({__proto__:null,provideStrandsConfig:g,setStrandsConfig:S,useStrandsConfig:h},Symbol.toStringTag,{value:"Module"}));exports.STRANDS_AUTH_DEFAULTS=c;exports.provideStrandsConfig=g;exports.setStrandsConfig=S;exports.useStrandsConfig=h;exports.useStrandsConfig$1=y;
|