@strands.gg/accui 2.6.2 → 2.6.3
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/accui.css +1 -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 +1 -1
- package/dist/nuxt/runtime/plugin.server.cjs.js +1 -1
- package/dist/nuxt/runtime/plugin.server.es.js +1 -1
- package/dist/strands-auth-ui.cjs.js +1 -1
- package/dist/strands-auth-ui.es.js +38 -19
- package/dist/{useStrandsAuth-DoUupKb8.es.js → useStrandsAuth-B0jI8Gbq.es.js} +1 -1
- package/dist/{useStrandsAuth-WChBcwNF.cjs.js → useStrandsAuth-Dt4KTg73.cjs.js} +1 -1
- package/dist/useStrandsConfig-BUmt8HfH.cjs.js +1 -0
- package/dist/{useStrandsConfig-C3gBJK6y.es.js → useStrandsConfig-f200kXFG.es.js} +6 -1
- package/package.json +1 -1
- package/dist/useStrandsConfig-B6uW6Zkd.cjs.js +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineComponent, computed, provide, onMounted, onUnmounted, createElementBlock, openBlock, normalizeClass, createElementVNode, createBlock, renderSlot, Teleport, createCommentVNode, toDisplayString, createTextVNode, unref, normalizeStyle, useSlots, createVNode, Fragment as Fragment$1, withCtx, resolveComponent, resolveDynamicComponent, createSlots, h as h$1, ref, nextTick, withModifiers, renderList, watch, toRefs, withDirectives, vModelSelect, getCurrentInstance, watchEffect, onBeforeUnmount, shallowRef, markRaw, customRef, useCssVars, reactive, createStaticVNode, vModelText, Transition, mergeProps, inject, withKeys, isMemoSame } from "vue";
|
|
2
|
-
import { u as useStrandsConfig, p as provideStrandsConfig } from "./useStrandsConfig-
|
|
3
|
-
import { s } from "./useStrandsConfig-
|
|
4
|
-
import { u as useStrandsAuth } from "./useStrandsAuth-
|
|
2
|
+
import { u as useStrandsConfig, p as provideStrandsConfig } from "./useStrandsConfig-f200kXFG.es.js";
|
|
3
|
+
import { s } from "./useStrandsConfig-f200kXFG.es.js";
|
|
4
|
+
import { u as useStrandsAuth } from "./useStrandsAuth-B0jI8Gbq.es.js";
|
|
5
5
|
const _hoisted_1$T = { class: "app-content" };
|
|
6
6
|
const _hoisted_2$K = {
|
|
7
7
|
key: 0,
|
|
@@ -206,9 +206,9 @@ const _hoisted_7$r = {
|
|
|
206
206
|
const _sfc_main$Z = /* @__PURE__ */ defineComponent({
|
|
207
207
|
__name: "UiLoader",
|
|
208
208
|
props: {
|
|
209
|
-
size: { default:
|
|
209
|
+
size: { default: "md" },
|
|
210
210
|
color: { default: "primary" },
|
|
211
|
-
variant: { default: "
|
|
211
|
+
variant: { default: "circle" },
|
|
212
212
|
text: {},
|
|
213
213
|
centered: { type: Boolean, default: true },
|
|
214
214
|
weight: { default: 30 },
|
|
@@ -217,6 +217,19 @@ const _sfc_main$Z = /* @__PURE__ */ defineComponent({
|
|
|
217
217
|
setup(__props) {
|
|
218
218
|
const path = logo.replace(/<svg[^>]*>/, "").replace(/<\/svg>/, "").trim();
|
|
219
219
|
const d = path.match(/d="([^"]*)"/)?.[1] || "";
|
|
220
|
+
const props = __props;
|
|
221
|
+
const sizeMap = {
|
|
222
|
+
"sm": 32,
|
|
223
|
+
"md": 48,
|
|
224
|
+
"lg": 64,
|
|
225
|
+
"xl": 80
|
|
226
|
+
};
|
|
227
|
+
const computedSize = computed(() => {
|
|
228
|
+
if (typeof props.size === "number") {
|
|
229
|
+
return props.size;
|
|
230
|
+
}
|
|
231
|
+
return sizeMap[props.size] || sizeMap.md;
|
|
232
|
+
});
|
|
220
233
|
return (_ctx, _cache) => {
|
|
221
234
|
return openBlock(), createElementBlock("div", {
|
|
222
235
|
class: normalizeClass(["loader-container", [
|
|
@@ -226,8 +239,8 @@ const _sfc_main$Z = /* @__PURE__ */ defineComponent({
|
|
|
226
239
|
}, [
|
|
227
240
|
_ctx.variant === "spinner" ? (openBlock(), createElementBlock("div", _hoisted_1$R, [
|
|
228
241
|
(openBlock(), createElementBlock("svg", {
|
|
229
|
-
width:
|
|
230
|
-
height:
|
|
242
|
+
width: computedSize.value,
|
|
243
|
+
height: computedSize.value,
|
|
231
244
|
viewBox: "0 0 500 500"
|
|
232
245
|
}, [
|
|
233
246
|
createElementVNode("defs", null, [
|
|
@@ -258,11 +271,11 @@ const _sfc_main$Z = /* @__PURE__ */ defineComponent({
|
|
|
258
271
|
])) : _ctx.variant === "circle" ? (openBlock(), createElementBlock("div", {
|
|
259
272
|
key: 1,
|
|
260
273
|
class: "loader-circle",
|
|
261
|
-
style: normalizeStyle({ width: `${
|
|
274
|
+
style: normalizeStyle({ width: `${computedSize.value}px`, height: `${computedSize.value}px` })
|
|
262
275
|
}, [
|
|
263
276
|
(openBlock(), createElementBlock("svg", {
|
|
264
|
-
width:
|
|
265
|
-
height:
|
|
277
|
+
width: computedSize.value,
|
|
278
|
+
height: computedSize.value,
|
|
266
279
|
viewBox: "0 0 50 50"
|
|
267
280
|
}, [..._cache[0] || (_cache[0] = [
|
|
268
281
|
createElementVNode("circle", {
|
|
@@ -280,8 +293,8 @@ const _sfc_main$Z = /* @__PURE__ */ defineComponent({
|
|
|
280
293
|
key: 2,
|
|
281
294
|
class: "loader-bar",
|
|
282
295
|
style: normalizeStyle({
|
|
283
|
-
width: _ctx.fullWidth ? "100%" : `${
|
|
284
|
-
height: `${Math.max(
|
|
296
|
+
width: _ctx.fullWidth ? "100%" : `${computedSize.value * 1.5}px`,
|
|
297
|
+
height: `${Math.max(computedSize.value * 0.1, 4)}px`
|
|
285
298
|
})
|
|
286
299
|
}, [..._cache[1] || (_cache[1] = [
|
|
287
300
|
createElementVNode("div", { class: "loader-bar-track" }, [
|
|
@@ -293,7 +306,7 @@ const _sfc_main$Z = /* @__PURE__ */ defineComponent({
|
|
|
293
306
|
};
|
|
294
307
|
}
|
|
295
308
|
});
|
|
296
|
-
const StrandsUiLoader = /* @__PURE__ */ _export_sfc(_sfc_main$Z, [["__scopeId", "data-v-
|
|
309
|
+
const StrandsUiLoader = /* @__PURE__ */ _export_sfc(_sfc_main$Z, [["__scopeId", "data-v-4b565c5d"]]);
|
|
297
310
|
const _hoisted_1$Q = {
|
|
298
311
|
key: 0,
|
|
299
312
|
class: "button-loading-content"
|
|
@@ -26741,11 +26754,14 @@ function useModalStack(options = {}) {
|
|
|
26741
26754
|
if (!modalInstance.value) return null;
|
|
26742
26755
|
return document.querySelector(`.ui-app-modal-backdrop[style*="z-index: ${modalInstance.value.zIndex - 1}"]`);
|
|
26743
26756
|
};
|
|
26744
|
-
|
|
26745
|
-
|
|
26746
|
-
|
|
26747
|
-
|
|
26748
|
-
|
|
26757
|
+
try {
|
|
26758
|
+
onUnmounted(() => {
|
|
26759
|
+
if (isOpen.value) {
|
|
26760
|
+
closeModal();
|
|
26761
|
+
}
|
|
26762
|
+
});
|
|
26763
|
+
} catch (e) {
|
|
26764
|
+
}
|
|
26749
26765
|
return {
|
|
26750
26766
|
// State
|
|
26751
26767
|
isOpen,
|
|
@@ -26782,7 +26798,10 @@ function useGlobalModalStack() {
|
|
|
26782
26798
|
const unsubscribe = modalStack.subscribe((state) => {
|
|
26783
26799
|
stackState.value = state;
|
|
26784
26800
|
});
|
|
26785
|
-
|
|
26801
|
+
try {
|
|
26802
|
+
onUnmounted(unsubscribe);
|
|
26803
|
+
} catch (e) {
|
|
26804
|
+
}
|
|
26786
26805
|
return {
|
|
26787
26806
|
state: stackState,
|
|
26788
26807
|
closeAll: () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { computed, ref, onUnmounted } from "vue";
|
|
2
|
-
import { u as useStrandsConfig } from "./useStrandsConfig-
|
|
2
|
+
import { u as useStrandsConfig } from "./useStrandsConfig-f200kXFG.es.js";
|
|
3
3
|
class RequestCache {
|
|
4
4
|
cache = /* @__PURE__ */ new Map();
|
|
5
5
|
DEFAULT_TTL = 5 * 60 * 1e3;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=require("vue"),t=require("./useStrandsConfig-B6uW6Zkd.cjs.js"),a=new class{cache=new Map;DEFAULT_TTL=3e5;async fetch(e,t,a=this.DEFAULT_TTL){const n=Date.now(),i=this.cache.get(e);if(i&&n-i.timestamp<i.ttl)return i.promise;this.cleanExpired();const r=t().finally(()=>{setTimeout(()=>{this.cache.delete(e)},a)});return this.cache.set(e,{promise:r,timestamp:n,ttl:a}),r}clear(){this.cache.clear()}invalidate(e){this.cache.delete(e)}cleanExpired(){const e=Date.now();for(const[t,a]of this.cache.entries())e-a.timestamp>a.ttl&&this.cache.delete(t)}getStats(){return{size:this.cache.size,entries:Array.from(this.cache.keys())}}},n=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:c}=t.useStrandsConfig(),{fetch:d,clear:l,invalidate:h}={fetch:a.fetch.bind(a),clear:a.clear.bind(a),invalidate:a.invalidate.bind(a),getStats:a.getStats.bind(a)},{currentUser:u,currentSession:f,loadingStates:w,isInitialized:y,mfaRequired:g,mfaSessionId:m,availableMfaMethods:p}=r,S=e.computed(()=>w.value.initializing),_=e.computed(()=>w.value.signingIn),T=e.computed(()=>w.value.signingUp),E=e.computed(()=>w.value.signingOut),v=e.computed(()=>w.value.refreshingToken),O=e.computed(()=>w.value.sendingMfaEmail),A=e.computed(()=>w.value.verifyingMfa);e.computed(()=>w.value.loadingProfile);const $=e.computed(()=>w.value.signingIn||w.value.signingUp||w.value.signingOut||w.value.refreshingToken||w.value.sendingMfaEmail||w.value.verifyingMfa||w.value.loadingProfile),N=e.computed(()=>w.value.initializing||$.value),b=e.computed(()=>{const e=w.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..."}),k=()=>{const e={};return f.value?.accessToken&&(e.Authorization=`Bearer ${f.value.accessToken}`),f.value?.refreshToken&&(e["x-refresh-token"]=f.value.refreshToken),e},C=e.computed(()=>null!==u.value),J=async()=>{w.value.signingOut=1;try{U(),s=null,l(),u.value=null,f.value=null,g.value=0,m.value=null,p.value=[],"undefined"!=typeof window&&(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user"))}finally{w.value.signingOut=0}},P=async()=>{if(!f.value?.refreshToken)return 0;if(s)return await s;s=(async()=>{w.value.refreshingToken=1;try{const e=await fetch(c("refresh"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh_token:f.value.refreshToken})});if(!e.ok){if(401===e.status)return await J(),0;throw new Error(`Token refresh failed: ${e.status} ${e.statusText}`)}const t=await e.json();t.user&&(u.value=i(t.user),u.value&&"undefined"!=typeof window&&localStorage.setItem("strands_auth_user",JSON.stringify(u.value)));const a={accessToken:t.access_token,refreshToken:t.refresh_token,expiresAt:new Date(Date.now()+3e5),userId:t.user?.id||u.value?.id};return f.value=a,"undefined"!=typeof window&&localStorage.setItem("strands_auth_session",JSON.stringify(a)),M(),h(`sessions:${f.value.accessToken.slice(0,20)}`),1}catch(e){return await J(),0}finally{w.value.refreshingToken=0}})();const e=await s;return s=null,e},F=async e=>{try{e.user&&(u.value=i(e.user));const t={accessToken:e.access_token,refreshToken:e.refresh_token,expiresAt:new Date(Date.now()+3e5),userId:u.value?.id||e.user?.id};f.value=t,"undefined"!=typeof window&&(localStorage.setItem("strands_auth_session",JSON.stringify(t)),u.value&&localStorage.setItem("strands_auth_user",JSON.stringify(u.value))),M()}catch(t){}},M=()=>{if(o&&clearTimeout(o),!f.value)return;if("undefined"!=typeof document&&"hidden"===document.visibilityState)return;const e=new Date,t=f.value.expiresAt.getTime()-e.getTime()-6e4;t<=0?P():o=setTimeout(async()=>{"undefined"!=typeof document&&"visible"!==document.visibilityState||await P()&&M()},t)},U=()=>{o&&(clearTimeout(o),o=null)},D=async()=>{if(!y.value){w.value.initializing=1;try{if("undefined"!=typeof window){const t=localStorage.getItem("strands_auth_session"),a=localStorage.getItem("strands_auth_user");if(t&&a)try{const e=JSON.parse(t),n=JSON.parse(a);e.expiresAt=new Date(e.expiresAt),e.expiresAt<=new Date&&e.refreshToken?(f.value=e,u.value=n,await P()||(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user"),f.value=null,u.value=null)):e.expiresAt>new Date?(f.value=e,u.value=n,M()):(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user"))}catch(e){localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user")}}y.value=1,await new Promise(e=>setTimeout(e,50))}catch(e){}finally{w.value.initializing=0}}};"undefined"!=typeof document&&document.addEventListener("visibilitychange",()=>{"visible"===document.visibilityState&&f.value?M():"hidden"===document.visibilityState&&U()});const I=()=>{U(),l(),"undefined"!=typeof document&&document.removeEventListener("visibilitychange",()=>{})};try{e.onUnmounted(I)}catch(j){}return y.value||D(),{user:e.computed(()=>u.value),currentUser:e.computed(()=>u.value),currentSession:e.computed(()=>f.value),isAuthenticated:C,isLoading:e.computed(()=>N.value||!y.value),loading:e.computed(()=>$.value),loadingMessage:b,isInitializing:S,isSigningIn:_,isSigningUp:T,isSigningOut:E,isRefreshingToken:v,isSendingMfaEmail:O,isVerifyingMfa:A,mfaRequired:e.computed(()=>g.value),mfaSessionId:e.computed(()=>m.value),availableMfaMethods:e.computed(()=>p.value),signIn:async e=>{w.value.signingIn=1;try{g.value=0,m.value=null,p.value=[];const t={"Content-Type":"application/json"};"undefined"!=typeof window&&window.location&&(t.Origin=window.location.origin);const a=await fetch(c("signIn"),{method:"POST",headers:t,body:JSON.stringify(e)});if(!a.ok)throw 401===a.status?new Error("Invalid email or password"):403===a.status?new Error("Please verify your email address before signing in"):new Error(`Sign in failed: ${a.status} ${a.statusText}`);const n=await a.json();if(n.mfa_required){g.value=1,m.value=n.mfa_session_id||null;const e=(n.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 p.value=e,w.value.signingIn=0,n}return await F(n),n}catch(t){throw t}finally{w.value.signingIn=0}},signUp:async e=>{w.value.signingUp=1;try{throw new Error("Sign up not implemented - please integrate with auth SDK")}finally{w.value.signingUp=0}},signOut:J,refreshToken:P,fetchProfile:async()=>{const e=`profile:${f.value.accessToken.slice(0,20)}`;w.value.loadingProfile=1;try{return await d(e,async()=>{const e=await fetch(c("profile"),{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${f.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 u.value=i(t),u.value&&"undefined"!=typeof window&&localStorage.setItem("strands_auth_user",JSON.stringify(u.value)),u.value})}finally{w.value.loadingProfile=0}},updateProfile:async e=>{w.value.loadingProfile=1;try{const t=await fetch(c("profile"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${f.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 a=await t.json();return u.value=i(a),u.value&&n("strands_auth_user",JSON.stringify(u.value)),u.value}finally{w.value.loadingProfile=0}},updateUserSettings:async e=>{w.value.loadingProfile=1;try{const t=await fetch(c("settings"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${f.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 a=await t.json();return u.value=i(a),u.value&&n("strands_auth_user",JSON.stringify(u.value)),u.value}finally{w.value.loadingProfile=0}},changeEmail:async(e,t)=>{w.value.loadingProfile=1;try{const a=await fetch(c("changeEmail"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${f.value.accessToken}`},body:JSON.stringify({new_email:e,password:t})});if(!a.ok){if(401===a.status)throw new Error("Authentication expired. Please sign in again.");{const e=await a.json().catch(()=>({}));throw new Error(e.message||`Email change failed: ${a.status} ${a.statusText}`)}}const n=await a.json();return u.value&&(u.value={...u.value,email:e,emailVerified:0,updatedAt:(new Date).toISOString()},"undefined"!=typeof window&&localStorage.setItem("strands_auth_user",JSON.stringify(u.value))),n}finally{w.value.loadingProfile=0}},changeUsername:async e=>{w.value.loadingProfile=1;try{const t=await fetch(c("changeUsername"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${f.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 a=await t.json();return u.value&&(u.value={...u.value,username:e,usernameLastChangedAt:(new Date).toISOString(),updatedAt:(new Date).toISOString()},"undefined"!=typeof window&&localStorage.setItem("strands_auth_user",JSON.stringify(u.value))),a}finally{w.value.loadingProfile=0}},getUsernameCooldown:async()=>{const e=await fetch(c("usernameCooldown"),{method:"GET",headers:{Authorization:`Bearer ${f.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=c("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()},getUserSessions:async()=>{const e=`sessions:${f.value?.accessToken?.slice(0,20)||"no-token"}`;try{return await d(e,async()=>{const e=k(),t=await fetch(c("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(c("sessionsStats"),{method:"GET",headers:k()});if(!e.ok)throw new Error(`Failed to get session stats: ${e.status} ${e.statusText}`);return e.json()},revokeSession:async e=>{const t=c("sessionRevoke").replace("{session_id}",encodeURIComponent(e)),a=await fetch(t,{method:"POST",headers:k()});if(!a.ok)throw new Error(`Failed to revoke session: ${a.status} ${a.statusText}`);return 200===a.status},revokeAllOtherSessions:async()=>{const e=await fetch(c("sessionsRevokeAll"),{method:"POST",headers:k()});if(!e.ok)throw new Error(`Failed to revoke all other sessions: ${e.status} ${e.statusText}`);return 200===e.status},initialize:D,setAuthData:F,verifyMfa:async(e,t,a=0)=>{if(!m.value)throw new Error("No MFA session available");w.value.verifyingMfa=1;try{const n=c(a?"mfaBackupCodeVerify":"mfaSigninVerify"),i=a?{mfa_session_id:m.value,backup_code:t}:{mfa_session_id:m.value,device_id:e,code:t},r=await fetch(n,{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 a=JSON.parse(e);t=a.message||a.error||e}catch{t=e||"MFA verification failed"}throw new Error(t)}const o=await r.json();return g.value=0,m.value=null,p.value=[],await F(o),o}finally{w.value.verifyingMfa=0}},sendMfaEmailCode:async e=>{if(!m.value)throw new Error("No MFA session available");w.value.sendingMfaEmail=1;try{const t=await fetch(c("mfaSigninSendEmail"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mfa_session_id:m.value,device_id:e})});if(!t.ok){const e=await t.text();let a="Failed to send MFA email code";try{const t=JSON.parse(e);a=t.message||t.error||e}catch{a=e||"Failed to send MFA email code"}throw new Error(a)}return await t.json()}finally{w.value.sendingMfaEmail=0}},getMfaWebAuthnChallenge:async e=>{if(!m.value)throw new Error("No MFA session available");const t=await fetch(c("mfaWebAuthnChallenge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mfa_session_id:m.value,device_id:e})});if(!t.ok){const e=await t.text();let a="Failed to get WebAuthn challenge";try{const t=JSON.parse(e);a=t.message||t.error||e}catch{a=e||a}throw new Error(a)}return t.json()},registerHardwareKey:async(e,t,a="hardware")=>{const n=await fetch(c("mfaHardwareStartRegistration"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${f.value.accessToken}`},body:JSON.stringify({device_name:e,device_type:a})});if(!n.ok){const e=await n.text();let t="Failed to start hardware key registration";try{const a=JSON.parse(e);t=a.message||a.error||e}catch{t=e||"Failed to start hardware key registration"}throw new Error(t)}return n.json()},completeHardwareKeyRegistration:async(e,t,a)=>{const n=await fetch(c("mfaHardwareCompleteRegistration"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${f.value.accessToken}`},body:JSON.stringify({device_id:e,credential:t})});if(!n.ok){const e=await n.text();let t="Failed to complete hardware key registration";try{const a=JSON.parse(e);t=a.message||a.error||e}catch{t=e||"Failed to complete hardware key registration"}throw new Error(t)}return n.json()},startTokenRefreshTimer:M,stopTokenRefreshTimer:U,getAuthHeaders:k,forceReInit:()=>{y.value=0,w.value.initializing=1,D()}}};
|
|
1
|
+
"use strict";const e=require("vue"),t=require("./useStrandsConfig-BUmt8HfH.cjs.js"),a=new class{cache=new Map;DEFAULT_TTL=3e5;async fetch(e,t,a=this.DEFAULT_TTL){const n=Date.now(),i=this.cache.get(e);if(i&&n-i.timestamp<i.ttl)return i.promise;this.cleanExpired();const r=t().finally(()=>{setTimeout(()=>{this.cache.delete(e)},a)});return this.cache.set(e,{promise:r,timestamp:n,ttl:a}),r}clear(){this.cache.clear()}invalidate(e){this.cache.delete(e)}cleanExpired(){const e=Date.now();for(const[t,a]of this.cache.entries())e-a.timestamp>a.ttl&&this.cache.delete(t)}getStats(){return{size:this.cache.size,entries:Array.from(this.cache.keys())}}},n=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:c}=t.useStrandsConfig(),{fetch:d,clear:l,invalidate:h}={fetch:a.fetch.bind(a),clear:a.clear.bind(a),invalidate:a.invalidate.bind(a),getStats:a.getStats.bind(a)},{currentUser:u,currentSession:f,loadingStates:w,isInitialized:y,mfaRequired:g,mfaSessionId:m,availableMfaMethods:p}=r,S=e.computed(()=>w.value.initializing),_=e.computed(()=>w.value.signingIn),T=e.computed(()=>w.value.signingUp),E=e.computed(()=>w.value.signingOut),v=e.computed(()=>w.value.refreshingToken),O=e.computed(()=>w.value.sendingMfaEmail),A=e.computed(()=>w.value.verifyingMfa);e.computed(()=>w.value.loadingProfile);const $=e.computed(()=>w.value.signingIn||w.value.signingUp||w.value.signingOut||w.value.refreshingToken||w.value.sendingMfaEmail||w.value.verifyingMfa||w.value.loadingProfile),N=e.computed(()=>w.value.initializing||$.value),b=e.computed(()=>{const e=w.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..."}),k=()=>{const e={};return f.value?.accessToken&&(e.Authorization=`Bearer ${f.value.accessToken}`),f.value?.refreshToken&&(e["x-refresh-token"]=f.value.refreshToken),e},C=e.computed(()=>null!==u.value),J=async()=>{w.value.signingOut=1;try{U(),s=null,l(),u.value=null,f.value=null,g.value=0,m.value=null,p.value=[],"undefined"!=typeof window&&(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user"))}finally{w.value.signingOut=0}},P=async()=>{if(!f.value?.refreshToken)return 0;if(s)return await s;s=(async()=>{w.value.refreshingToken=1;try{const e=await fetch(c("refresh"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh_token:f.value.refreshToken})});if(!e.ok){if(401===e.status)return await J(),0;throw new Error(`Token refresh failed: ${e.status} ${e.statusText}`)}const t=await e.json();t.user&&(u.value=i(t.user),u.value&&"undefined"!=typeof window&&localStorage.setItem("strands_auth_user",JSON.stringify(u.value)));const a={accessToken:t.access_token,refreshToken:t.refresh_token,expiresAt:new Date(Date.now()+3e5),userId:t.user?.id||u.value?.id};return f.value=a,"undefined"!=typeof window&&localStorage.setItem("strands_auth_session",JSON.stringify(a)),M(),h(`sessions:${f.value.accessToken.slice(0,20)}`),1}catch(e){return await J(),0}finally{w.value.refreshingToken=0}})();const e=await s;return s=null,e},F=async e=>{try{e.user&&(u.value=i(e.user));const t={accessToken:e.access_token,refreshToken:e.refresh_token,expiresAt:new Date(Date.now()+3e5),userId:u.value?.id||e.user?.id};f.value=t,"undefined"!=typeof window&&(localStorage.setItem("strands_auth_session",JSON.stringify(t)),u.value&&localStorage.setItem("strands_auth_user",JSON.stringify(u.value))),M()}catch(t){}},M=()=>{if(o&&clearTimeout(o),!f.value)return;if("undefined"!=typeof document&&"hidden"===document.visibilityState)return;const e=new Date,t=f.value.expiresAt.getTime()-e.getTime()-6e4;t<=0?P():o=setTimeout(async()=>{"undefined"!=typeof document&&"visible"!==document.visibilityState||await P()&&M()},t)},U=()=>{o&&(clearTimeout(o),o=null)},D=async()=>{if(!y.value){w.value.initializing=1;try{if("undefined"!=typeof window){const t=localStorage.getItem("strands_auth_session"),a=localStorage.getItem("strands_auth_user");if(t&&a)try{const e=JSON.parse(t),n=JSON.parse(a);e.expiresAt=new Date(e.expiresAt),e.expiresAt<=new Date&&e.refreshToken?(f.value=e,u.value=n,await P()||(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user"),f.value=null,u.value=null)):e.expiresAt>new Date?(f.value=e,u.value=n,M()):(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user"))}catch(e){localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user")}}y.value=1,await new Promise(e=>setTimeout(e,50))}catch(e){}finally{w.value.initializing=0}}};"undefined"!=typeof document&&document.addEventListener("visibilitychange",()=>{"visible"===document.visibilityState&&f.value?M():"hidden"===document.visibilityState&&U()});const I=()=>{U(),l(),"undefined"!=typeof document&&document.removeEventListener("visibilitychange",()=>{})};try{e.onUnmounted(I)}catch(j){}return y.value||D(),{user:e.computed(()=>u.value),currentUser:e.computed(()=>u.value),currentSession:e.computed(()=>f.value),isAuthenticated:C,isLoading:e.computed(()=>N.value||!y.value),loading:e.computed(()=>$.value),loadingMessage:b,isInitializing:S,isSigningIn:_,isSigningUp:T,isSigningOut:E,isRefreshingToken:v,isSendingMfaEmail:O,isVerifyingMfa:A,mfaRequired:e.computed(()=>g.value),mfaSessionId:e.computed(()=>m.value),availableMfaMethods:e.computed(()=>p.value),signIn:async e=>{w.value.signingIn=1;try{g.value=0,m.value=null,p.value=[];const t={"Content-Type":"application/json"};"undefined"!=typeof window&&window.location&&(t.Origin=window.location.origin);const a=await fetch(c("signIn"),{method:"POST",headers:t,body:JSON.stringify(e)});if(!a.ok)throw 401===a.status?new Error("Invalid email or password"):403===a.status?new Error("Please verify your email address before signing in"):new Error(`Sign in failed: ${a.status} ${a.statusText}`);const n=await a.json();if(n.mfa_required){g.value=1,m.value=n.mfa_session_id||null;const e=(n.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 p.value=e,w.value.signingIn=0,n}return await F(n),n}catch(t){throw t}finally{w.value.signingIn=0}},signUp:async e=>{w.value.signingUp=1;try{throw new Error("Sign up not implemented - please integrate with auth SDK")}finally{w.value.signingUp=0}},signOut:J,refreshToken:P,fetchProfile:async()=>{const e=`profile:${f.value.accessToken.slice(0,20)}`;w.value.loadingProfile=1;try{return await d(e,async()=>{const e=await fetch(c("profile"),{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${f.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 u.value=i(t),u.value&&"undefined"!=typeof window&&localStorage.setItem("strands_auth_user",JSON.stringify(u.value)),u.value})}finally{w.value.loadingProfile=0}},updateProfile:async e=>{w.value.loadingProfile=1;try{const t=await fetch(c("profile"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${f.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 a=await t.json();return u.value=i(a),u.value&&n("strands_auth_user",JSON.stringify(u.value)),u.value}finally{w.value.loadingProfile=0}},updateUserSettings:async e=>{w.value.loadingProfile=1;try{const t=await fetch(c("settings"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${f.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 a=await t.json();return u.value=i(a),u.value&&n("strands_auth_user",JSON.stringify(u.value)),u.value}finally{w.value.loadingProfile=0}},changeEmail:async(e,t)=>{w.value.loadingProfile=1;try{const a=await fetch(c("changeEmail"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${f.value.accessToken}`},body:JSON.stringify({new_email:e,password:t})});if(!a.ok){if(401===a.status)throw new Error("Authentication expired. Please sign in again.");{const e=await a.json().catch(()=>({}));throw new Error(e.message||`Email change failed: ${a.status} ${a.statusText}`)}}const n=await a.json();return u.value&&(u.value={...u.value,email:e,emailVerified:0,updatedAt:(new Date).toISOString()},"undefined"!=typeof window&&localStorage.setItem("strands_auth_user",JSON.stringify(u.value))),n}finally{w.value.loadingProfile=0}},changeUsername:async e=>{w.value.loadingProfile=1;try{const t=await fetch(c("changeUsername"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${f.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 a=await t.json();return u.value&&(u.value={...u.value,username:e,usernameLastChangedAt:(new Date).toISOString(),updatedAt:(new Date).toISOString()},"undefined"!=typeof window&&localStorage.setItem("strands_auth_user",JSON.stringify(u.value))),a}finally{w.value.loadingProfile=0}},getUsernameCooldown:async()=>{const e=await fetch(c("usernameCooldown"),{method:"GET",headers:{Authorization:`Bearer ${f.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=c("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()},getUserSessions:async()=>{const e=`sessions:${f.value?.accessToken?.slice(0,20)||"no-token"}`;try{return await d(e,async()=>{const e=k(),t=await fetch(c("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(c("sessionsStats"),{method:"GET",headers:k()});if(!e.ok)throw new Error(`Failed to get session stats: ${e.status} ${e.statusText}`);return e.json()},revokeSession:async e=>{const t=c("sessionRevoke").replace("{session_id}",encodeURIComponent(e)),a=await fetch(t,{method:"POST",headers:k()});if(!a.ok)throw new Error(`Failed to revoke session: ${a.status} ${a.statusText}`);return 200===a.status},revokeAllOtherSessions:async()=>{const e=await fetch(c("sessionsRevokeAll"),{method:"POST",headers:k()});if(!e.ok)throw new Error(`Failed to revoke all other sessions: ${e.status} ${e.statusText}`);return 200===e.status},initialize:D,setAuthData:F,verifyMfa:async(e,t,a=0)=>{if(!m.value)throw new Error("No MFA session available");w.value.verifyingMfa=1;try{const n=c(a?"mfaBackupCodeVerify":"mfaSigninVerify"),i=a?{mfa_session_id:m.value,backup_code:t}:{mfa_session_id:m.value,device_id:e,code:t},r=await fetch(n,{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 a=JSON.parse(e);t=a.message||a.error||e}catch{t=e||"MFA verification failed"}throw new Error(t)}const o=await r.json();return g.value=0,m.value=null,p.value=[],await F(o),o}finally{w.value.verifyingMfa=0}},sendMfaEmailCode:async e=>{if(!m.value)throw new Error("No MFA session available");w.value.sendingMfaEmail=1;try{const t=await fetch(c("mfaSigninSendEmail"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mfa_session_id:m.value,device_id:e})});if(!t.ok){const e=await t.text();let a="Failed to send MFA email code";try{const t=JSON.parse(e);a=t.message||t.error||e}catch{a=e||"Failed to send MFA email code"}throw new Error(a)}return await t.json()}finally{w.value.sendingMfaEmail=0}},getMfaWebAuthnChallenge:async e=>{if(!m.value)throw new Error("No MFA session available");const t=await fetch(c("mfaWebAuthnChallenge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mfa_session_id:m.value,device_id:e})});if(!t.ok){const e=await t.text();let a="Failed to get WebAuthn challenge";try{const t=JSON.parse(e);a=t.message||t.error||e}catch{a=e||a}throw new Error(a)}return t.json()},registerHardwareKey:async(e,t,a="hardware")=>{const n=await fetch(c("mfaHardwareStartRegistration"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${f.value.accessToken}`},body:JSON.stringify({device_name:e,device_type:a})});if(!n.ok){const e=await n.text();let t="Failed to start hardware key registration";try{const a=JSON.parse(e);t=a.message||a.error||e}catch{t=e||"Failed to start hardware key registration"}throw new Error(t)}return n.json()},completeHardwareKeyRegistration:async(e,t,a)=>{const n=await fetch(c("mfaHardwareCompleteRegistration"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${f.value.accessToken}`},body:JSON.stringify({device_id:e,credential:t})});if(!n.ok){const e=await n.text();let t="Failed to complete hardware key registration";try{const a=JSON.parse(e);t=a.message||a.error||e}catch{t=e||"Failed to complete hardware key registration"}throw new Error(t)}return n.json()},startTokenRefreshTimer:M,stopTokenRefreshTimer:U,getAuthHeaders:k,forceReInit:()=>{y.value=0,w.value.initializing=1,D()}}};
|
|
@@ -0,0 +1 @@
|
|
|
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)}exports.STRANDS_AUTH_DEFAULTS=i,exports.provideStrandsConfig=function(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){}},exports.setStrandsConfig=function(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)}},exports.useStrandsConfig=function(t){let n=null;try{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}};
|
|
@@ -106,7 +106,12 @@ function provideStrandsConfig(config) {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
function useStrandsConfig(fallbackConfig) {
|
|
109
|
-
|
|
109
|
+
let injectedConfig = null;
|
|
110
|
+
try {
|
|
111
|
+
injectedConfig = inject(STRANDS_CONFIG_KEY, null);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
injectedConfig = null;
|
|
114
|
+
}
|
|
110
115
|
let nuxtConfig = null;
|
|
111
116
|
try {
|
|
112
117
|
if (typeof window !== "undefined") {
|
package/package.json
CHANGED
|
@@ -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)}exports.STRANDS_AUTH_DEFAULTS=i,exports.provideStrandsConfig=function(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){}},exports.setStrandsConfig=function(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)}},exports.useStrandsConfig=function(t){const n=e.inject(a,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}};
|