@strands.gg/accui 2.8.1 → 2.9.1
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 +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.es.js +5 -5
- package/dist/nuxt/module.d.ts +4 -1
- package/dist/nuxt/runtime/composables/useAuthenticatedFetch.d.ts +20 -1
- package/dist/nuxt/runtime/composables/useStrandsAuth.cjs.js +1 -1
- package/dist/nuxt/runtime/composables/useStrandsAuth.d.ts +65 -1
- package/dist/nuxt/runtime/composables/useStrandsAuth.es.js +1 -1
- package/dist/nuxt/runtime/middleware/auth.d.ts +6 -0
- package/dist/nuxt/runtime/middleware/auth.global.d.ts +2 -1
- package/dist/nuxt/runtime/middleware/guest.d.ts +6 -0
- package/dist/nuxt/runtime/plugin.client.d.ts +2 -1
- package/dist/nuxt/runtime/plugin.server.d.ts +2 -1
- package/dist/nuxt/runtime/plugins/auth-interceptor.client.d.ts +2 -1
- package/dist/nuxt/types.d.ts +45 -0
- package/dist/nuxt.d.ts +4 -1
- package/dist/shared/defaults.d.ts +2 -0
- package/dist/types/composables.d.ts +96 -0
- package/dist/types/index.d.ts +242 -0
- package/dist/useStrandsAuth-Bp5aTR3h.cjs.js +1 -0
- package/dist/{useStrandsAuth-jI_X_wiK.es.js → useStrandsAuth-Xz8lnhv7.es.js} +1 -1
- package/dist/utils/colors.d.ts +10 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/slots.d.ts +1 -0
- package/dist/utils/validation.d.ts +12 -0
- package/dist/vue/components/StrandsNav/index.d.ts +8 -0
- package/dist/vue/components/StrandsNav/types.d.ts +12 -0
- package/dist/vue/components/icons/index.d.ts +2 -0
- package/dist/vue/components/index.d.ts +27 -0
- package/dist/vue/composables/useAuthenticatedFetch.d.ts +20 -0
- package/dist/vue/composables/useDarkMode.d.ts +48 -0
- package/dist/vue/composables/useFloatingPosition.d.ts +22 -0
- package/dist/vue/composables/useModalStack.d.ts +86 -0
- package/dist/vue/composables/useOAuthProviders.d.ts +73 -0
- package/dist/vue/composables/useStrandsAuth.d.ts +2 -0
- package/dist/vue/composables/useStrandsConfig.d.ts +5 -0
- package/dist/vue/composables/useStrandsMfa.d.ts +36 -0
- package/dist/vue/composables/useTheme.d.ts +18 -0
- package/dist/vue/index.d.ts +16 -0
- package/dist/vue/plugins/StrandsUIPlugin.d.ts +20 -0
- package/dist/vue/ui/UiButton/index.d.ts +13 -0
- package/dist/vue/ui/index.d.ts +54 -0
- package/dist/vue/utils/contrast.d.ts +75 -0
- package/dist/vue/utils/debounce.d.ts +12 -0
- package/dist/vue/utils/fontPreloader.d.ts +11 -0
- package/dist/vue/utils/iconProps.d.ts +9 -0
- package/dist/vue/utils/lazyComponents.d.ts +4 -0
- package/dist/vue/utils/levels.d.ts +27 -0
- package/dist/vue/utils/modalStack.d.ts +31 -0
- package/dist/vue/utils/performanceInit.d.ts +40 -0
- package/dist/vue/utils/requestCache.d.ts +49 -0
- package/dist/vue/utils/sounds.d.ts +57 -0
- package/package.json +2 -3
- package/dist/auth-interceptor.client.d.ts +0 -1
- package/dist/auth.global.d.ts +0 -1
- package/dist/module.d.ts +0 -1
- package/dist/plugin.client.d.ts +0 -1
- package/dist/plugin.server.d.ts +0 -1
- package/dist/useAuthenticatedFetch.d.ts +0 -1
- package/dist/useStrandsAuth-Ca9Zqmfy.cjs.js +0 -1
- package/dist/useStrandsAuth.d.ts +0 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface ModalInstance {
|
|
2
|
+
id: symbol;
|
|
3
|
+
closeModal: () => void;
|
|
4
|
+
closeOnEscape: boolean;
|
|
5
|
+
zIndex: number;
|
|
6
|
+
component?: string;
|
|
7
|
+
priority?: 'low' | 'normal' | 'high' | 'critical';
|
|
8
|
+
}
|
|
9
|
+
export interface ModalStackState {
|
|
10
|
+
modals: ModalInstance[];
|
|
11
|
+
topModal: ModalInstance | null;
|
|
12
|
+
hasModals: boolean;
|
|
13
|
+
highestZIndex: number;
|
|
14
|
+
}
|
|
15
|
+
declare class ModalStack {
|
|
16
|
+
private stack;
|
|
17
|
+
private escapeHandlerRegistered;
|
|
18
|
+
private baseZIndex;
|
|
19
|
+
private subscribers;
|
|
20
|
+
private handleEscape;
|
|
21
|
+
private calculateZIndex;
|
|
22
|
+
private notifySubscribers;
|
|
23
|
+
add(modal: Omit<ModalInstance, 'zIndex'>): ModalInstance;
|
|
24
|
+
remove(modalId: symbol): void;
|
|
25
|
+
subscribe(callback: (state: ModalStackState) => void): () => void;
|
|
26
|
+
get length(): number;
|
|
27
|
+
get state(): ModalStackState;
|
|
28
|
+
cleanup(): void;
|
|
29
|
+
}
|
|
30
|
+
export declare const modalStack: ModalStack;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Performance initialization utility
|
|
3
|
+
* Optimizes loading and runtime performance
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Initialize all performance optimizations
|
|
7
|
+
*/
|
|
8
|
+
export declare function initializePerformanceOptimizations(): void;
|
|
9
|
+
/**
|
|
10
|
+
* Optimize runtime performance
|
|
11
|
+
*/
|
|
12
|
+
export declare function optimizeRuntimePerformance(): void;
|
|
13
|
+
/**
|
|
14
|
+
* Cleanup performance optimizations
|
|
15
|
+
*/
|
|
16
|
+
export declare function cleanupPerformanceOptimizations(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Get performance metrics
|
|
19
|
+
*/
|
|
20
|
+
export declare function getPerformanceMetrics(): {
|
|
21
|
+
domContentLoaded?: undefined;
|
|
22
|
+
loadComplete?: undefined;
|
|
23
|
+
dns?: undefined;
|
|
24
|
+
tcp?: undefined;
|
|
25
|
+
ttfb?: undefined;
|
|
26
|
+
domInteractive?: undefined;
|
|
27
|
+
memoryUsage?: undefined;
|
|
28
|
+
} | {
|
|
29
|
+
domContentLoaded: number;
|
|
30
|
+
loadComplete: number;
|
|
31
|
+
dns: number;
|
|
32
|
+
tcp: number;
|
|
33
|
+
ttfb: number;
|
|
34
|
+
domInteractive: number;
|
|
35
|
+
memoryUsage: {
|
|
36
|
+
used: any;
|
|
37
|
+
total: any;
|
|
38
|
+
limit: any;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request deduplication and caching utility
|
|
3
|
+
* Prevents duplicate API calls and provides simple caching
|
|
4
|
+
*/
|
|
5
|
+
declare class RequestCache {
|
|
6
|
+
private cache;
|
|
7
|
+
private readonly DEFAULT_TTL;
|
|
8
|
+
/**
|
|
9
|
+
* Memoized fetch - prevents duplicate requests and caches results
|
|
10
|
+
*/
|
|
11
|
+
fetch<T>(key: string, fetcher: () => Promise<T>, ttl?: number): Promise<T>;
|
|
12
|
+
/**
|
|
13
|
+
* Clear all cached entries
|
|
14
|
+
*/
|
|
15
|
+
clear(): void;
|
|
16
|
+
/**
|
|
17
|
+
* Remove a specific cache entry
|
|
18
|
+
*/
|
|
19
|
+
invalidate(key: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Clean expired cache entries
|
|
22
|
+
*/
|
|
23
|
+
private cleanExpired;
|
|
24
|
+
/**
|
|
25
|
+
* Get cache statistics (for debugging)
|
|
26
|
+
*/
|
|
27
|
+
getStats(): {
|
|
28
|
+
size: number;
|
|
29
|
+
entries: string[];
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export declare const requestCache: RequestCache;
|
|
33
|
+
/**
|
|
34
|
+
* Composable for request deduplication
|
|
35
|
+
*/
|
|
36
|
+
export declare function useRequestCache(): {
|
|
37
|
+
fetch: <T>(key: string, fetcher: () => Promise<T>, ttl?: number) => Promise<T>;
|
|
38
|
+
clear: () => void;
|
|
39
|
+
invalidate: (key: string) => void;
|
|
40
|
+
getStats: () => {
|
|
41
|
+
size: number;
|
|
42
|
+
entries: string[];
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Generate cache key from URL and options
|
|
47
|
+
*/
|
|
48
|
+
export declare function getCacheKey(url: string, options?: RequestInit): string;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sound effects utility functions using Web Audio API
|
|
3
|
+
* These generate sounds programmatically without needing external audio files
|
|
4
|
+
*/
|
|
5
|
+
export declare class SoundEffects {
|
|
6
|
+
private static audioContext;
|
|
7
|
+
/**
|
|
8
|
+
* Get or create a shared AudioContext
|
|
9
|
+
*/
|
|
10
|
+
private static getAudioContext;
|
|
11
|
+
/**
|
|
12
|
+
* Play a level up sound effect
|
|
13
|
+
* A pleasant major chord with arpeggio and bell overtones
|
|
14
|
+
*/
|
|
15
|
+
static playLevelUp(level?: number, userSettings?: any): void;
|
|
16
|
+
/**
|
|
17
|
+
* Play regular level up sound for normal levels
|
|
18
|
+
* A gentle, smooth celebration sound
|
|
19
|
+
*/
|
|
20
|
+
private static playRegularLevelUp;
|
|
21
|
+
/**
|
|
22
|
+
* Play epic milestone level up sound for special levels (10, 25, 50, 100, 150, 200)
|
|
23
|
+
* A beautiful, uplifting celebration sound for major achievements
|
|
24
|
+
*/
|
|
25
|
+
private static playMilestoneLevelUp;
|
|
26
|
+
/**
|
|
27
|
+
* Play a success/completion sound
|
|
28
|
+
* A short, bright confirmation tone
|
|
29
|
+
*/
|
|
30
|
+
static playSuccess(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Play an error/failure sound
|
|
33
|
+
* A low, descending tone
|
|
34
|
+
*/
|
|
35
|
+
static playError(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Play a click/button press sound
|
|
38
|
+
* A very short, soft click
|
|
39
|
+
*/
|
|
40
|
+
static playClick(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Play a notification sound
|
|
43
|
+
* A gentle two-tone chime
|
|
44
|
+
*/
|
|
45
|
+
static playNotification(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Play an XP gain sound
|
|
48
|
+
* A quick, ascending glissando
|
|
49
|
+
*/
|
|
50
|
+
static playXpGain(): void;
|
|
51
|
+
}
|
|
52
|
+
export declare const playLevelUp: (level?: number, userSettings?: any) => void;
|
|
53
|
+
export declare const playSuccess: () => void;
|
|
54
|
+
export declare const playError: () => void;
|
|
55
|
+
export declare const playClick: () => void;
|
|
56
|
+
export declare const playNotification: () => void;
|
|
57
|
+
export declare const playXpGain: () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strands.gg/accui",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.1",
|
|
4
4
|
"description": "Strands Authentication UI Components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs.js",
|
|
@@ -56,8 +56,7 @@
|
|
|
56
56
|
"author": "Strands Services Limited",
|
|
57
57
|
"license": "MIT",
|
|
58
58
|
"scripts": {
|
|
59
|
-
"build": "vite build",
|
|
60
|
-
"build-runtime": "node scripts/build-runtime.js",
|
|
59
|
+
"build": "vite build && tsc --emitDeclarationOnly",
|
|
61
60
|
"build-demo": "vite build --config vite.demo.config.ts",
|
|
62
61
|
"serve": "vite",
|
|
63
62
|
"serve-demo": "vite --config vite.demo.config.ts",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { }
|
package/dist/auth.global.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { }
|
package/dist/module.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { }
|
package/dist/plugin.client.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { }
|
package/dist/plugin.server.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { }
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { }
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const e=require("vue"),t=require("./useStrandsConfig-CLSzvTvE.cjs.js"),n=new class{cache=new Map;DEFAULT_TTL=3e5;async fetch(e,t,n=this.DEFAULT_TTL){const a=Date.now(),i=this.cache.get(e);if(i&&a-i.timestamp<i.ttl)return i.promise;this.cleanExpired();const r=t().finally(()=>{setTimeout(()=>{this.cache.delete(e)},n)});return this.cache.set(e,{promise:r,timestamp:a,ttl:n}),r}clear(){this.cache.clear()}invalidate(e){this.cache.delete(e)}cleanExpired(){const e=Date.now();for(const[t,n]of this.cache.entries())e-n.timestamp>n.ttl&&this.cache.delete(t)}getStats(){return{size:this.cache.size,entries:Array.from(this.cache.keys())}}},a=function(){let e=null;return(...t)=>{e&&clearTimeout(e),e=setTimeout(()=>{((e,t)=>{"undefined"!=typeof window&&localStorage.setItem(e,t)})(...t)},300)}}(),i=e=>({id:e.id,email:e.email,firstName:e.first_name||e.firstName||"",lastName:e.last_name||e.lastName||"",avatar:e.avatar_url||e.avatar,mfaEnabled:e.mfa_enabled??e.mfaEnabled??0,emailVerified:e.email_verified??e.emailVerified??0,passwordUpdatedAt:e.password_updated_at||e.passwordUpdatedAt,settings:e.settings||{},xp:e.xp||0,level:e.level||1,next_level_xp:e.next_level_xp||e.next_level_xp||4,username:e.username,usernameLastChangedAt:e.username_last_changed_at||e.usernameLastChangedAt,createdAt:e.created_at||e.createdAt,updatedAt:e.updated_at||e.updatedAt||(new Date).toISOString()}),r={currentUser:e.ref(null),currentSession:e.ref(null),loadingStates:e.ref({initializing:1,signingIn:0,signingUp:0,signingOut:0,refreshingToken:0,sendingMfaEmail:0,verifyingMfa:0,loadingProfile:0}),isInitialized:e.ref(0),mfaRequired:e.ref(0),mfaSessionId:e.ref(null),availableMfaMethods:e.ref([])};let o=null,s=null;exports.useStrandsAuth=function(){const{getUrl:d,config:c}=t.useStrandsConfig(),{fetch:l,clear:u,invalidate:h}={fetch:n.fetch.bind(n),clear:n.clear.bind(n),invalidate:n.invalidate.bind(n),getStats:n.getStats.bind(n)},{currentUser:f,currentSession:w,loadingStates:y,isInitialized:g,mfaRequired:m,mfaSessionId:p,availableMfaMethods:S}=r,_=()=>{if(f.value=null,w.value=null,m.value=0,p.value=null,S.value=[],"undefined"!=typeof window&&(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user")),D(),s=null,u(),"undefined"!=typeof window&&c.value?.onSignOutUrl){const e=window.location.pathname+window.location.search,t=c.value.onSignOutUrl;e!==t&&(window.location.href=t)}},T=e.computed(()=>y.value.initializing),E=e.computed(()=>y.value.signingIn),O=e.computed(()=>y.value.signingUp),v=e.computed(()=>y.value.signingOut),A=e.computed(()=>y.value.refreshingToken),$=e.computed(()=>y.value.sendingMfaEmail),N=e.computed(()=>y.value.verifyingMfa);e.computed(()=>y.value.loadingProfile);const b=e.computed(()=>y.value.signingIn||y.value.signingUp||y.value.signingOut||y.value.refreshingToken||y.value.sendingMfaEmail||y.value.verifyingMfa||y.value.loadingProfile),k=e.computed(()=>y.value.initializing||b.value),C=e.computed(()=>{const e=y.value;return e.initializing?"Checking authentication...":e.signingIn?"Signing you in...":e.signingUp?"Creating your account...":e.signingOut?"Signing you out...":e.refreshingToken?"Refreshing session...":e.sendingMfaEmail?"Sending verification code...":e.verifyingMfa?"Verifying code...":e.loadingProfile?"Loading profile...":"Loading..."}),J=()=>{const e={};return w.value?.accessToken&&(e.Authorization=`Bearer ${w.value.accessToken}`),w.value?.refreshToken&&(e["x-refresh-token"]=w.value.refreshToken),e},P=e.computed(()=>null!==f.value),F=async()=>{if(!w.value?.refreshToken)return 0;if(s)return await s;s=(async()=>{y.value.refreshingToken=1;try{const e=await fetch(d("refresh"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh_token:w.value.refreshToken})});if(!e.ok){if(401===e.status)return _(),0;throw new Error(`Token refresh failed: ${e.status} ${e.statusText}`)}const t=await e.json();t.user&&(f.value=i(t.user),f.value&&"undefined"!=typeof window&&localStorage.setItem("strands_auth_user",JSON.stringify(f.value)));const n={accessToken:t.access_token,refreshToken:t.refresh_token,expiresAt:new Date(Date.now()+3e5),userId:t.user?.id||f.value?.id};return w.value=n,"undefined"!=typeof window&&localStorage.setItem("strands_auth_session",JSON.stringify(n)),U(),h(`sessions:${w.value.accessToken.slice(0,20)}`),1}catch(e){return _(),0}finally{y.value.refreshingToken=0}})();const e=await s;return s=null,e},M=async e=>{try{e.user&&(f.value=i(e.user));const t={accessToken:e.access_token,refreshToken:e.refresh_token,expiresAt:new Date(Date.now()+3e5),userId:f.value?.id||e.user?.id};w.value=t,"undefined"!=typeof window&&(localStorage.setItem("strands_auth_session",JSON.stringify(t)),f.value&&localStorage.setItem("strands_auth_user",JSON.stringify(f.value))),U()}catch(t){}},U=()=>{if(o&&clearTimeout(o),!w.value)return;if("undefined"!=typeof document&&"hidden"===document.visibilityState)return;const e=new Date,t=w.value.expiresAt.getTime()-e.getTime()-6e4;t<=0?F():o=setTimeout(async()=>{"undefined"!=typeof document&&"visible"!==document.visibilityState||await F()&&U()},t)},D=()=>{o&&(clearTimeout(o),o=null)},I=async()=>{if(!g.value){y.value.initializing=1;try{if("undefined"!=typeof window){const t=localStorage.getItem("strands_auth_session"),n=localStorage.getItem("strands_auth_user");if(t&&n)try{const e=JSON.parse(t),a=JSON.parse(n);e.expiresAt=new Date(e.expiresAt),e.expiresAt<=new Date&&e.refreshToken?(w.value=e,f.value=a,await F()||_()):e.expiresAt>new Date?(w.value=e,f.value=a,U()):(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user"))}catch(e){localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user")}}g.value=1,await new Promise(e=>setTimeout(e,50))}catch(e){}finally{y.value.initializing=0}}};"undefined"!=typeof document&&document.addEventListener("visibilitychange",()=>{"visible"===document.visibilityState&&w.value?(U(),j()):"hidden"===document.visibilityState&&D()}),"undefined"!=typeof window&&window.addEventListener("storage",e=>{"strands_auth_session"!==e.key&&"strands_auth_user"!==e.key||!e.newValue&&f.value&&_()});const j=()=>{if("undefined"!=typeof window&&f.value&&w.value){const e=localStorage.getItem("strands_auth_session"),t=localStorage.getItem("strands_auth_user");e&&t||_()}},R=()=>{D(),u()};try{e.getCurrentInstance()&&e.onUnmounted(R)}catch(z){}return g.value||I(),{user:e.computed(()=>f.value),currentUser:e.computed(()=>f.value),currentSession:e.computed(()=>w.value),isAuthenticated:P,isLoading:e.computed(()=>k.value||!g.value),loading:e.computed(()=>b.value),loadingMessage:C,isInitializing:T,isSigningIn:E,isSigningUp:O,isSigningOut:v,isRefreshingToken:A,isSendingMfaEmail:$,isVerifyingMfa:N,mfaRequired:e.computed(()=>m.value),mfaSessionId:e.computed(()=>p.value),availableMfaMethods:e.computed(()=>S.value),signIn:async e=>{y.value.signingIn=1;try{m.value=0,p.value=null,S.value=[];const t={"Content-Type":"application/json"};"undefined"!=typeof window&&window.location&&(t.Origin=window.location.origin);const n=await fetch(d("signIn"),{method:"POST",headers:t,body:JSON.stringify(e)});if(!n.ok)throw 401===n.status?new Error("Invalid email or password"):403===n.status?new Error("Please verify your email address before signing in"):new Error(`Sign in failed: ${n.status} ${n.statusText}`);const a=await n.json();if(a.mfa_required){m.value=1,p.value=a.mfa_session_id||null;const e=(a.available_mfa_methods||[]).map(e=>{let t=`${e.device_type.charAt(0).toUpperCase()+e.device_type.slice(1)} Authentication`;return"hardware"===e.device_type?t=e.device_name||"Security Key":"totp"===e.device_type?t=e.device_name||"Authenticator App":"email"===e.device_type&&(t=e.device_name||"Email Verification"),{id:e.device_id,device_type:e.device_type,device_name:e.device_name||t,is_active:1,created_at:(new Date).toISOString(),last_used_at:e.last_used_at,credential_id:e.credential_id,device_info:e.device_info}});return S.value=e,y.value.signingIn=0,a}return await M(a),a}catch(t){throw t}finally{y.value.signingIn=0}},signUp:async e=>{y.value.signingUp=1;try{throw new Error("Sign up not implemented - please integrate with auth SDK")}finally{y.value.signingUp=0}},signOut:async()=>{y.value.signingOut=1;try{D(),s=null,u(),f.value=null,w.value=null,m.value=0,p.value=null,S.value=[],"undefined"!=typeof window&&(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user"))}finally{y.value.signingOut=0}},refreshToken:F,fetchProfile:async()=>{const e=`profile:${w.value.accessToken.slice(0,20)}`;y.value.loadingProfile=1;try{return await l(e,async()=>{const e=await fetch(d("profile"),{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${w.value?.accessToken}`}});if(!e.ok)throw 401===e.status?new Error("Authentication expired. Please sign in again."):new Error(`Failed to fetch profile: ${e.status} ${e.statusText}`);const t=await e.json();return f.value=i(t),f.value&&"undefined"!=typeof window&&localStorage.setItem("strands_auth_user",JSON.stringify(f.value)),f.value})}finally{y.value.loadingProfile=0}},updateProfile:async e=>{y.value.loadingProfile=1;try{const t=await fetch(d("profile"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${w.value.accessToken}`},body:JSON.stringify({first_name:e.firstName,last_name:e.lastName})});if(!t.ok)throw 401===t.status?new Error("Authentication expired. Please sign in again."):new Error(`Profile update failed: ${t.status} ${t.statusText}`);const n=await t.json();return f.value=i(n),f.value&&a("strands_auth_user",JSON.stringify(f.value)),f.value}finally{y.value.loadingProfile=0}},updateUserSettings:async e=>{y.value.loadingProfile=1;try{const t=await fetch(d("settings"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${w.value.accessToken}`},body:JSON.stringify({settings:e})});if(!t.ok)throw 401===t.status?new Error("Authentication expired. Please sign in again."):new Error(`Settings update failed: ${t.status} ${t.statusText}`);const n=await t.json();return f.value=i(n),f.value&&a("strands_auth_user",JSON.stringify(f.value)),f.value}finally{y.value.loadingProfile=0}},changeEmail:async(e,t)=>{y.value.loadingProfile=1;try{const n=await fetch(d("changeEmail"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${w.value.accessToken}`},body:JSON.stringify({new_email:e,password:t})});if(!n.ok){if(401===n.status)throw new Error("Authentication expired. Please sign in again.");{const e=await n.json().catch(()=>({}));throw new Error(e.message||`Email change failed: ${n.status} ${n.statusText}`)}}const a=await n.json();return f.value&&(f.value={...f.value,email:e,emailVerified:0,updatedAt:(new Date).toISOString()},"undefined"!=typeof window&&localStorage.setItem("strands_auth_user",JSON.stringify(f.value))),a}finally{y.value.loadingProfile=0}},changeUsername:async e=>{y.value.loadingProfile=1;try{const t=await fetch(d("changeUsername"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${w.value.accessToken}`},body:JSON.stringify({username:e})});if(!t.ok){const e=await t.json().catch(()=>({}));if(409===t.status)throw new Error("Username is already taken");if(e.cooldown_end)throw new Error(`You can only change your username once every 30 days. You can change it again on ${new Date(e.cooldown_end).toLocaleDateString()}`);throw new Error(e.message||`Username change failed: ${t.status} ${t.statusText}`)}const n=await t.json();return f.value&&(f.value={...f.value,username:e,usernameLastChangedAt:(new Date).toISOString(),updatedAt:(new Date).toISOString()},"undefined"!=typeof window&&localStorage.setItem("strands_auth_user",JSON.stringify(f.value))),n}finally{y.value.loadingProfile=0}},getUsernameCooldown:async()=>{const e=await fetch(d("usernameCooldown"),{method:"GET",headers:{Authorization:`Bearer ${w.value.accessToken}`}});if(!e.ok)throw new Error(`Failed to get username cooldown: ${e.status} ${e.statusText}`);return e.json()},checkUsernameAvailability:async e=>{const t=d("checkUsernameAvailability").replace("{username}",encodeURIComponent(e)),n=await fetch(t,{method:"GET",headers:{"Content-Type":"application/json"}});if(!n.ok)throw new Error(`Failed to check username availability: ${n.status} ${n.statusText}`);return n.json()},getUserSessions:async()=>{const e=`sessions:${w.value?.accessToken?.slice(0,20)||"no-token"}`;try{return await l(e,async()=>{const e=J(),t=await fetch(d("sessions"),{method:"GET",headers:e});if(!t.ok)throw await t.text(),new Error(`Failed to get user sessions: ${t.status} ${t.statusText}`);return t.json()},12e4)}catch(t){throw t}},getSessionStats:async()=>{const e=await fetch(d("sessionsStats"),{method:"GET",headers:J()});if(!e.ok)throw new Error(`Failed to get session stats: ${e.status} ${e.statusText}`);return e.json()},revokeSession:async e=>{const t=d("sessionRevoke").replace("{session_id}",encodeURIComponent(e)),n=await fetch(t,{method:"POST",headers:J()});if(!n.ok)throw new Error(`Failed to revoke session: ${n.status} ${n.statusText}`);return 200===n.status},revokeAllOtherSessions:async()=>{const e=await fetch(d("sessionsRevokeAll"),{method:"POST",headers:J()});if(!e.ok)throw new Error(`Failed to revoke all other sessions: ${e.status} ${e.statusText}`);return 200===e.status},initialize:I,setAuthData:M,verifyMfa:async(e,t,n=0)=>{if(!p.value)throw new Error("No MFA session available");y.value.verifyingMfa=1;try{const a=d(n?"mfaBackupCodeVerify":"mfaSigninVerify"),i=n?{mfa_session_id:p.value,backup_code:t}:{mfa_session_id:p.value,device_id:e,code:t},r=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!r.ok){const e=await r.text();let t="MFA verification failed";try{const n=JSON.parse(e);t=n.message||n.error||e}catch{t=e||"MFA verification failed"}throw new Error(t)}const o=await r.json();return m.value=0,p.value=null,S.value=[],await M(o),o}finally{y.value.verifyingMfa=0}},sendMfaEmailCode:async e=>{if(!p.value)throw new Error("No MFA session available");y.value.sendingMfaEmail=1;try{const t=await fetch(d("mfaSigninSendEmail"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mfa_session_id:p.value,device_id:e})});if(!t.ok){const e=await t.text();let n="Failed to send MFA email code";try{const t=JSON.parse(e);n=t.message||t.error||e}catch{n=e||"Failed to send MFA email code"}throw new Error(n)}return await t.json()}finally{y.value.sendingMfaEmail=0}},getMfaWebAuthnChallenge:async e=>{if(!p.value)throw new Error("No MFA session available");const t=await fetch(d("mfaWebAuthnChallenge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mfa_session_id:p.value,device_id:e})});if(!t.ok){const e=await t.text();let n="Failed to get WebAuthn challenge";try{const t=JSON.parse(e);n=t.message||t.error||e}catch{n=e||n}throw new Error(n)}return t.json()},registerHardwareKey:async(e,t,n="hardware")=>{const a=await fetch(d("mfaHardwareStartRegistration"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${w.value.accessToken}`},body:JSON.stringify({device_name:e,device_type:n})});if(!a.ok){const e=await a.text();let t="Failed to start hardware key registration";try{const n=JSON.parse(e);t=n.message||n.error||e}catch{t=e||"Failed to start hardware key registration"}throw new Error(t)}return a.json()},completeHardwareKeyRegistration:async(e,t,n)=>{const a=await fetch(d("mfaHardwareCompleteRegistration"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${w.value.accessToken}`},body:JSON.stringify({device_id:e,credential:t})});if(!a.ok){const e=await a.text();let t="Failed to complete hardware key registration";try{const n=JSON.parse(e);t=n.message||n.error||e}catch{t=e||"Failed to complete hardware key registration"}throw new Error(t)}return a.json()},startTokenRefreshTimer:U,stopTokenRefreshTimer:D,getAuthHeaders:J,forceReInit:()=>{g.value=0,y.value.initializing=1,I()}}};
|
package/dist/useStrandsAuth.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { }
|