@@ -4,7 +4,12 @@ import type {
44 SensitiveInfoOptions ,
55} from '../sensitive-info.nitro'
66import { clearService , deleteItem , getAllItems , setItem } from '../core/storage'
7- import { HookError } from './types'
7+ import {
8+ HookError ,
9+ createHookFailureResult ,
10+ createHookSuccessResult ,
11+ type HookMutationResult ,
12+ } from './types'
813import useAsyncLifecycle from './useAsyncLifecycle'
914import useStableOptions from './useStableOptions'
1015import createHookError from './error-utils'
@@ -32,10 +37,8 @@ const DEFAULTS: Required<
3237const extractCoreOptions = (
3338 options : UseSecureStorageOptions
3439) : SensitiveInfoOptions => {
35- const sanitized = { ...options } as Record < string , unknown >
36- delete sanitized . skip
37- delete sanitized . includeValues
38- return sanitized as SensitiveInfoOptions
40+ const { skip : _skip , includeValues : _includeValues , ...core } = options
41+ return core as SensitiveInfoOptions
3942}
4043
4144/**
@@ -48,11 +51,9 @@ export interface UseSecureStorageResult {
4851 readonly saveSecret : (
4952 key : string ,
5053 value : string
51- ) => Promise < { success : boolean ; error ?: HookError } >
52- readonly removeSecret : (
53- key : string
54- ) => Promise < { success : boolean ; error ?: HookError } >
55- readonly clearAll : ( ) => Promise < { success : boolean ; error ?: HookError } >
54+ ) => Promise < HookMutationResult >
55+ readonly removeSecret : ( key : string ) => Promise < HookMutationResult >
56+ readonly clearAll : ( ) => Promise < HookMutationResult >
5657 readonly refreshItems : ( ) => Promise < void >
5758}
5859
@@ -134,7 +135,7 @@ export function useSecureStorage(
134135 if ( mountedRef . current ) {
135136 await fetchItems ( )
136137 }
137- return { success : true } as const
138+ return createHookSuccessResult ( )
138139 } catch ( errorLike ) {
139140 const hookError = createHookError (
140141 'useSecureStorage.saveSecret' ,
@@ -144,7 +145,7 @@ export function useSecureStorage(
144145 if ( mountedRef . current ) {
145146 setError ( hookError )
146147 }
147- return { success : false , error : hookError } as const
148+ return createHookFailureResult ( hookError )
148149 }
149150 } ,
150151 [ fetchItems , mountedRef , stableOptions ]
@@ -157,7 +158,7 @@ export function useSecureStorage(
157158 if ( mountedRef . current ) {
158159 setItems ( ( prev ) => prev . filter ( ( item ) => item . key !== key ) )
159160 }
160- return { success : true } as const
161+ return createHookSuccessResult ( )
161162 } catch ( errorLike ) {
162163 const hookError = createHookError (
163164 'useSecureStorage.removeSecret' ,
@@ -167,7 +168,7 @@ export function useSecureStorage(
167168 if ( mountedRef . current ) {
168169 setError ( hookError )
169170 }
170- return { success : false , error : hookError } as const
171+ return createHookFailureResult ( hookError )
171172 }
172173 } ,
173174 [ mountedRef , stableOptions ]
@@ -180,7 +181,7 @@ export function useSecureStorage(
180181 setItems ( [ ] )
181182 setError ( null )
182183 }
183- return { success : true } as const
184+ return createHookSuccessResult ( )
184185 } catch ( errorLike ) {
185186 const hookError = createHookError (
186187 'useSecureStorage.clearAll' ,
@@ -190,7 +191,7 @@ export function useSecureStorage(
190191 if ( mountedRef . current ) {
191192 setError ( hookError )
192193 }
193- return { success : false , error : hookError } as const
194+ return createHookFailureResult ( hookError )
194195 }
195196 } , [ mountedRef , stableOptions ] )
196197
0 commit comments