# NativeStorageService

- File ID: file:902xey:nativestorageservice-cs
- Path: NexusReader.Web/Services/NativeStorageService.cs
- Role: service
- Layer: infrastructure

## Purpose

Provides a server-side Blazor implementation of INativeStorageService that reads/writes browser localStorage via IJSRuntime, with protections for prerendering/JS-unavailable scenarios and Result-based error handling.

## Key Details

Wraps IJSRuntime calls with try/catch and FluentResults; provides typed bool parsing with default fallbacks; offers secure-named aliases that delegate to base methods.

## Symbols

- NativeStorageService: Provides a server-side Blazor implementation of INativeStorageService that reads/writes browser localStorage via IJSRuntime, with protections for prerendering/JS-unavailable scenarios and Result-based error handling.
- NativeStorageService(): Constructs the service and stores the IJSRuntime for JS interop calls.
- SaveStringAsync(): Saves a string value into browser localStorage via JS interop; returns a FluentResults Result indicating success or failure.
- GetStringAsync(): Reads a string value from browser localStorage via JS interop and wraps it in a FluentResults Result.
- SaveBoolAsync(): Stores a boolean as a string in localStorage by delegating to SaveStringAsync.
- GetBoolAsync(): Reads a boolean value from localStorage, with parsing, default fallback and exception-safe behavior.
- RemoveAsync(): Removes an item from browser localStorage via JS interop and reports success/failure.
- SaveSecureString(): Alias for SaveStringAsync; intended for secure-string semantics at the API level.
- GetSecureString(): Alias for GetStringAsync; intended for secure-string semantics at the API level.
- RemoveSecureAsync(): Alias for RemoveAsync; intended for secure-string removal semantics.
- NativeStorageService: Server-side implementation class that adapts INativeStorageService to IJSRuntime-based localStorage access.

## Dependencies

- No resolved dependencies.

## Calls

- No resolved calls.

## Unresolved References

- dependency-target: NexusReader.Application.Abstractions.Services (INativeStorageService)
- dependency-target: Microsoft.JSInterop (IJSRuntime)
- dependency-target: FluentResults (Result)
- call-target: self
- call-target: self
- call-target: self
- call-target: self
- interaction-target: await _jsRuntime.InvokeVoidAsync("localStorage.setItem", key, value)
- interaction-target: var value = await _jsRuntime.InvokeAsync<string?>("localStorage.getItem", key)
- interaction-target: var value = await _jsRuntime.InvokeAsync<string?>("localStorage.getItem", key)
- interaction-target: await _jsRuntime.InvokeVoidAsync("localStorage.removeItem", key)

## Coverage

- Symbols: 11
- Executable symbols: 9
- Executable symbols with control flow: 9
- Grounded edges: 11
- Unresolved references: 11
- Control-flow fragments: 9
- Unresolved jumps: 0
- Unsupported constructs: 0
- Control-flow coverage: 100%
- Required diagrams: 2
- Generated diagrams: 6

## Control Flow Fragments

- NativeStorageService: 3 nodes, 2 edges, 0 jumps, 0 unsupported constructs
- SaveStringAsync: 10 nodes, 9 edges, 0 jumps, 0 unsupported constructs
- GetStringAsync: 10 nodes, 9 edges, 0 jumps, 0 unsupported constructs
- SaveBoolAsync: 4 nodes, 3 edges, 1 jumps, 0 unsupported constructs
- GetBoolAsync: 18 nodes, 19 edges, 0 jumps, 0 unsupported constructs
- RemoveAsync: 10 nodes, 9 edges, 0 jumps, 0 unsupported constructs
- SaveSecureString: 5 nodes, 4 edges, 1 jumps, 0 unsupported constructs
- GetSecureString: 5 nodes, 4 edges, 1 jumps, 0 unsupported constructs
- RemoveSecureAsync: 4 nodes, 3 edges, 1 jumps, 0 unsupported constructs

## Diagrams

### NativeStorageService Neighborhood

```mermaid
flowchart LR
    class_vyfiaz_nativestorageservice("NativeStorageService")
    file_902xey_nativestorageservice_cs("NativeStorageService")
    method_10perg_savesecurestring[["SaveSecureString()"]]
    method_18nxwdn_savestringasync[["SaveStringAsync()"]]
    method_19ghosy_saveboolasync[["SaveBoolAsync()"]]
    method_1gw1s7x_removeasync[["RemoveAsync()"]]
    method_1k49ns3_removesecureasync[["RemoveSecureAsync()"]]
    method_1olwlbd_getsecurestring[["GetSecureString()"]]
    method_4dh69s_nativestorageservice[["NativeStorageService()"]]
    method_nguekt_getboolasync[["GetBoolAsync()"]]
    method_wsqlg8_getstringasync[["GetStringAsync()"]]
    type_5hfl1o_nativestorageservice[/"NativeStorageService"/]
```

### NativeStorageService Execution Overview

```mermaid
flowchart TD
    class_vyfiaz_nativestorageservice("NativeStorageService")
    method_10perg_savesecurestring[["SaveSecureString()"]]
    method_18nxwdn_savestringasync[["SaveStringAsync()"]]
    method_19ghosy_saveboolasync[["SaveBoolAsync()"]]
    method_1gw1s7x_removeasync[["RemoveAsync()"]]
    method_1k49ns3_removesecureasync[["RemoveSecureAsync()"]]
    method_1olwlbd_getsecurestring[["GetSecureString()"]]
    method_4dh69s_nativestorageservice[["NativeStorageService()"]]
    method_nguekt_getboolasync[["GetBoolAsync()"]]
    method_wsqlg8_getstringasync[["GetStringAsync()"]]
    unresolved_unresolved_11sk4fu_interaction_target{"Unresolved: await _jsRuntime.InvokeVoidAsync(\\"localStorage.removeItem\\", key)"}
    unresolved_unresolved_14k7az0_call_target{"Unresolved: GetStringAsync"}
    unresolved_unresolved_1adkv8l_call_target{"Unresolved: SaveStringAsync"}
    unresolved_unresolved_1ih8lqd_interaction_target{"Unresolved: var value = await _jsRuntime.InvokeAsync<string?>(\\"localStorage.getItem\\", key)"}
    unresolved_unresolved_4iz4ad_interaction_target{"Unresolved: await _jsRuntime.InvokeVoidAsync(\\"localStorage.setItem\\", key, value)"}
    unresolved_unresolved_akhi98_call_target{"Unresolved: RemoveAsync"}
    unresolved_unresolved_pffwsg_call_target{"Unresolved: SaveStringAsync"}
    class_vyfiaz_nativestorageservice -->|contains| method_10perg_savesecurestring
    class_vyfiaz_nativestorageservice -->|contains| method_18nxwdn_savestringasync
    class_vyfiaz_nativestorageservice -->|contains| method_19ghosy_saveboolasync
    class_vyfiaz_nativestorageservice -->|contains| method_1gw1s7x_removeasync
    class_vyfiaz_nativestorageservice -->|contains| method_1k49ns3_removesecureasync
    class_vyfiaz_nativestorageservice -->|contains| method_1olwlbd_getsecurestring
    class_vyfiaz_nativestorageservice -->|contains| method_4dh69s_nativestorageservice
    class_vyfiaz_nativestorageservice -->|contains| method_nguekt_getboolasync
    class_vyfiaz_nativestorageservice -->|contains| method_wsqlg8_getstringasync
    class_vyfiaz_nativestorageservice -->|unresolved interaction| unresolved_unresolved_11sk4fu_interaction_target
    class_vyfiaz_nativestorageservice -->|unresolved interaction| unresolved_unresolved_1ih8lqd_interaction_target
    class_vyfiaz_nativestorageservice -->|unresolved interaction| unresolved_unresolved_1ih8lqd_interaction_target
    class_vyfiaz_nativestorageservice -->|unresolved interaction| unresolved_unresolved_4iz4ad_interaction_target
    method_10perg_savesecurestring -->|unresolved call| unresolved_unresolved_pffwsg_call_target
    method_19ghosy_saveboolasync -->|unresolved call| unresolved_unresolved_1adkv8l_call_target
    method_1k49ns3_removesecureasync -->|unresolved call| unresolved_unresolved_akhi98_call_target
    method_1olwlbd_getsecurestring -->|unresolved call| unresolved_unresolved_14k7az0_call_target
```

### SaveStringAsync() Control Flow

```mermaid
flowchart TD
    method_18nxwdn_savestringasync__action_23_savestringasync_try_23_0__try("Begins protected execution")
    method_18nxwdn_savestringasync__action_23_try_catch_23__linear("Return success or failure based on JS call")
    method_18nxwdn_savestringasync__action_25_savestringasync_await_25_1__await[["Waits for async work"]]
    method_18nxwdn_savestringasync__action_28_savestringasync_catch_28_3__catch("catch Exception ex")
    method_18nxwdn_savestringasync__entry(["SaveStringAsync entry"])
    method_18nxwdn_savestringasync__action_25_external_call_25__linear("Invoke JS to set localStorage item")
    method_18nxwdn_savestringasync__action_26_return_26__return(["Result.Ok on success"])
    method_18nxwdn_savestringasync__action_26_savestringasync_return_26_2__return(["Returns result"])
    method_18nxwdn_savestringasync__action_30_return_30__return(["Result.Fail on exception"])
    method_18nxwdn_savestringasync__action_30_savestringasync_return_30_4__return(["Returns result"])
    method_18nxwdn_savestringasync__action_23_savestringasync_try_23_0__try -->|next| method_18nxwdn_savestringasync__action_25_savestringasync_await_25_1__await
    method_18nxwdn_savestringasync__action_23_try_catch_23__linear -->|next| method_18nxwdn_savestringasync__action_23_savestringasync_try_23_0__try
    method_18nxwdn_savestringasync__action_25_external_call_25__linear -->|return| method_18nxwdn_savestringasync__action_26_savestringasync_return_26_2__return
    method_18nxwdn_savestringasync__action_25_savestringasync_await_25_1__await -->|next| method_18nxwdn_savestringasync__action_25_external_call_25__linear
    method_18nxwdn_savestringasync__action_26_return_26__return -->|exception| method_18nxwdn_savestringasync__action_28_savestringasync_catch_28_3__catch
    method_18nxwdn_savestringasync__action_26_savestringasync_return_26_2__return -->|return| method_18nxwdn_savestringasync__action_26_return_26__return
    method_18nxwdn_savestringasync__action_28_savestringasync_catch_28_3__catch -->|return| method_18nxwdn_savestringasync__action_30_savestringasync_return_30_4__return
    method_18nxwdn_savestringasync__action_30_savestringasync_return_30_4__return -->|return| method_18nxwdn_savestringasync__action_30_return_30__return
    method_18nxwdn_savestringasync__entry -->|next| method_18nxwdn_savestringasync__action_23_try_catch_23__linear
```

### GetStringAsync() Control Flow

```mermaid
flowchart TD
    method_wsqlg8_getstringasync__action_36_getstringasync_try_36_0__try("Begins protected execution")
    method_wsqlg8_getstringasync__action_36_try_catch_36__linear("Return value or failure based on JS call")
    method_wsqlg8_getstringasync__action_38_getstringasync_await_38_1__await[["Waits for async work"]]
    method_wsqlg8_getstringasync__action_41_getstringasync_catch_41_3__catch("catch Exception ex")
    method_wsqlg8_getstringasync__entry(["GetStringAsync entry"])
    method_wsqlg8_getstringasync__action_38_external_call_38__linear("Invoke JS to get localStorage item")
    method_wsqlg8_getstringasync__action_39_getstringasync_return_39_2__return(["Returns result"])
    method_wsqlg8_getstringasync__action_39_return_39__return(["Result.Ok with returned string"])
    method_wsqlg8_getstringasync__action_43_getstringasync_return_43_4__return(["Returns result"])
    method_wsqlg8_getstringasync__action_43_return_43__return(["Result.Fail on exception"])
    method_wsqlg8_getstringasync__action_36_getstringasync_try_36_0__try -->|next| method_wsqlg8_getstringasync__action_38_getstringasync_await_38_1__await
    method_wsqlg8_getstringasync__action_36_try_catch_36__linear -->|next| method_wsqlg8_getstringasync__action_36_getstringasync_try_36_0__try
    method_wsqlg8_getstringasync__action_38_external_call_38__linear -->|return| method_wsqlg8_getstringasync__action_39_getstringasync_return_39_2__return
    method_wsqlg8_getstringasync__action_38_getstringasync_await_38_1__await -->|next| method_wsqlg8_getstringasync__action_38_external_call_38__linear
    method_wsqlg8_getstringasync__action_39_getstringasync_return_39_2__return -->|return| method_wsqlg8_getstringasync__action_39_return_39__return
    method_wsqlg8_getstringasync__action_39_return_39__return -->|exception| method_wsqlg8_getstringasync__action_41_getstringasync_catch_41_3__catch
    method_wsqlg8_getstringasync__action_41_getstringasync_catch_41_3__catch -->|return| method_wsqlg8_getstringasync__action_43_getstringasync_return_43_4__return
    method_wsqlg8_getstringasync__action_43_getstringasync_return_43_4__return -->|return| method_wsqlg8_getstringasync__action_43_return_43__return
    method_wsqlg8_getstringasync__entry -->|next| method_wsqlg8_getstringasync__action_36_try_catch_36__linear
```

### GetBoolAsync() Control Flow

```mermaid
flowchart TD
    method_nguekt_getboolasync__action_51_getboolasync_try_51_0__try("Begins protected execution")
    method_nguekt_getboolasync__action_51_try_catch_51__linear("Catch any exception and return default")
    method_nguekt_getboolasync__action_53_getboolasync_await_53_1__await[["Waits for async work"]]
    method_nguekt_getboolasync__action_54_getboolasync_guard_clause_54_2__condition{"string.IsNullOrEmpty(value)) return Result.Ok(defaultValue"}
    method_nguekt_getboolasync__action_54_getboolasync_guard_clause_54_2__false("continue")
    method_nguekt_getboolasync__action_54_getboolasync_guard_clause_54_2__merge("merge")
    method_nguekt_getboolasync__action_54_getboolasync_guard_clause_54_2__true("exit")
    method_nguekt_getboolasync__action_54_guard_clause_54__condition{"string.IsNullOrEmpty(value)"}
    method_nguekt_getboolasync__action_54_guard_clause_54__false("continue")
    method_nguekt_getboolasync__action_54_guard_clause_54__merge("merge")
    method_nguekt_getboolasync__action_54_guard_clause_54__true("return default")
    method_nguekt_getboolasync__action_55_parsing_55__linear("Try parse bool")
    method_nguekt_getboolasync__action_57_getboolasync_catch_57_4__catch("Handles exception path")
    method_nguekt_getboolasync__entry(["GetBoolAsync entry"])
    method_nguekt_getboolasync__action_53_external_call_53__linear("Invoke JS to get localStorage item")
    method_nguekt_getboolasync__action_55_getboolasync_return_55_3__return(["Returns result"])
    method_nguekt_getboolasync__action_55_return_55__return(["Result.Ok with boolean (parsed or default)"])
    method_nguekt_getboolasync__action_59_getboolasync_return_59_5__return(["Returns result"])
    method_nguekt_getboolasync__action_51_getboolasync_try_51_0__try -->|next| method_nguekt_getboolasync__action_53_getboolasync_await_53_1__await
    method_nguekt_getboolasync__action_51_try_catch_51__linear -->|next| method_nguekt_getboolasync__action_51_getboolasync_try_51_0__try
    method_nguekt_getboolasync__action_53_external_call_53__linear -->|next| method_nguekt_getboolasync__action_54_guard_clause_54__condition
    method_nguekt_getboolasync__action_53_getboolasync_await_53_1__await -->|next| method_nguekt_getboolasync__action_53_external_call_53__linear
    method_nguekt_getboolasync__action_54_getboolasync_guard_clause_54_2__condition -->|continue| method_nguekt_getboolasync__action_54_getboolasync_guard_clause_54_2__false
    method_nguekt_getboolasync__action_54_getboolasync_guard_clause_54_2__condition -->|exit| method_nguekt_getboolasync__action_54_getboolasync_guard_clause_54_2__true
    method_nguekt_getboolasync__action_54_getboolasync_guard_clause_54_2__false -->|next| method_nguekt_getboolasync__action_54_getboolasync_guard_clause_54_2__merge
    method_nguekt_getboolasync__action_54_getboolasync_guard_clause_54_2__merge -->|next| method_nguekt_getboolasync__action_55_parsing_55__linear
    method_nguekt_getboolasync__action_54_getboolasync_guard_clause_54_2__true -->|next| method_nguekt_getboolasync__action_54_getboolasync_guard_clause_54_2__merge
    method_nguekt_getboolasync__action_54_guard_clause_54__condition -->|continue| method_nguekt_getboolasync__action_54_guard_clause_54__false
    method_nguekt_getboolasync__action_54_guard_clause_54__condition -->|return default| method_nguekt_getboolasync__action_54_guard_clause_54__true
    method_nguekt_getboolasync__action_54_guard_clause_54__false -->|next| method_nguekt_getboolasync__action_54_guard_clause_54__merge
    method_nguekt_getboolasync__action_54_guard_clause_54__merge -->|next| method_nguekt_getboolasync__action_54_getboolasync_guard_clause_54_2__condition
    method_nguekt_getboolasync__action_54_guard_clause_54__true -->|next| method_nguekt_getboolasync__action_54_guard_clause_54__merge
    method_nguekt_getboolasync__action_55_getboolasync_return_55_3__return -->|return| method_nguekt_getboolasync__action_55_return_55__return
    method_nguekt_getboolasync__action_55_parsing_55__linear -->|return| method_nguekt_getboolasync__action_55_getboolasync_return_55_3__return
    method_nguekt_getboolasync__action_55_return_55__return -->|exception| method_nguekt_getboolasync__action_57_getboolasync_catch_57_4__catch
    method_nguekt_getboolasync__action_57_getboolasync_catch_57_4__catch -->|return| method_nguekt_getboolasync__action_59_getboolasync_return_59_5__return
    method_nguekt_getboolasync__entry -->|next| method_nguekt_getboolasync__action_51_try_catch_51__linear
```

### RemoveAsync() Control Flow

```mermaid
flowchart TD
    method_1gw1s7x_removeasync__action_65_removeasync_try_65_0__try("Begins protected execution")
    method_1gw1s7x_removeasync__action_65_try_catch_65__linear("Return success or failure based on JS call")
    method_1gw1s7x_removeasync__action_67_removeasync_await_67_1__await[["Waits for async work"]]
    method_1gw1s7x_removeasync__action_70_removeasync_catch_70_3__catch("catch Exception ex")
    method_1gw1s7x_removeasync__entry(["RemoveAsync entry"])
    method_1gw1s7x_removeasync__action_67_external_call_67__linear("Invoke JS to remove localStorage item")
    method_1gw1s7x_removeasync__action_68_removeasync_return_68_2__return(["Returns result"])
    method_1gw1s7x_removeasync__action_68_return_68__return(["Result.Ok on success"])
    method_1gw1s7x_removeasync__action_72_removeasync_return_72_4__return(["Returns result"])
    method_1gw1s7x_removeasync__action_72_return_72__return(["Result.Fail on exception"])
    method_1gw1s7x_removeasync__action_65_removeasync_try_65_0__try -->|next| method_1gw1s7x_removeasync__action_67_removeasync_await_67_1__await
    method_1gw1s7x_removeasync__action_65_try_catch_65__linear -->|next| method_1gw1s7x_removeasync__action_65_removeasync_try_65_0__try
    method_1gw1s7x_removeasync__action_67_external_call_67__linear -->|return| method_1gw1s7x_removeasync__action_68_removeasync_return_68_2__return
    method_1gw1s7x_removeasync__action_67_removeasync_await_67_1__await -->|next| method_1gw1s7x_removeasync__action_67_external_call_67__linear
    method_1gw1s7x_removeasync__action_68_removeasync_return_68_2__return -->|return| method_1gw1s7x_removeasync__action_68_return_68__return
    method_1gw1s7x_removeasync__action_68_return_68__return -->|exception| method_1gw1s7x_removeasync__action_70_removeasync_catch_70_3__catch
    method_1gw1s7x_removeasync__action_70_removeasync_catch_70_3__catch -->|return| method_1gw1s7x_removeasync__action_72_removeasync_return_72_4__return
    method_1gw1s7x_removeasync__action_72_removeasync_return_72_4__return -->|return| method_1gw1s7x_removeasync__action_72_return_72__return
    method_1gw1s7x_removeasync__entry -->|next| method_1gw1s7x_removeasync__action_65_try_catch_65__linear
```

## Diagram Validation

- Status: pass
