diff --git a/docs/net/auth.md b/docs/net/auth.md index 22f8771..27595cf 100644 --- a/docs/net/auth.md +++ b/docs/net/auth.md @@ -20,6 +20,7 @@ Manages authentication state for a socket connection. **Methods:** - `doAuth(sign)` - Authenticate with the relay using provided signing function - `attemptAuth(sign)` - Attempt authentication with timeout handling +- `retryAuth(sign)` - Retry authentication by resetting state and attempting auth again - `cleanup()` - Clean up event listeners **Events:** @@ -39,4 +40,9 @@ authState.on(AuthStateEvent.Status, (status) => { await authState.attemptAuth(async (template) => { return await signer.signEvent(template) }) + +// Retry authentication if needed +await authState.retryAuth(async (template) => { + return await signer.signEvent(template) +}) ``` diff --git a/docs/store/synced.md b/docs/store/synced.md index 72b8f71..6ccc886 100644 --- a/docs/store/synced.md +++ b/docs/store/synced.md @@ -14,12 +14,13 @@ Creates a writable store that synchronizes with a storage provider using JSON se - `storage` - Storage provider implementing the StorageProvider interface - `defaultValue` - Default value if nothing exists in storage -**Returns:** Writable Svelte store that persists changes to storage +**Returns:** `Synced` - A writable Svelte store with a `ready` promise that resolves when initial storage loading completes The store automatically: -- Loads initial value from storage on creation +- Loads initial value from storage asynchronously on creation - Saves any changes back to storage - Falls back to defaultValue if storage is empty or invalid +- Provides a `ready` promise that resolves when initial loading is complete ## Storage Provider Interface @@ -46,6 +47,9 @@ const userPreferences = synced({ } }) +// Wait for initial loading to complete if needed +await userPreferences.ready + // Use like any writable store userPreferences.subscribe(prefs => { console.log("Preferences:", prefs) diff --git a/package.json b/package.json index b571ec8..e019e01 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@welshman", "private": true, - "version": "0.4.3", + "version": "0.4.4", "workspaces": [ "packages/*" ], diff --git a/packages/app/package.json b/packages/app/package.json index 2f9a771..2431624 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/app", - "version": "0.4.3", + "version": "0.4.4", "author": "hodlbod", "license": "MIT", "description": "A collection of svelte stores for use in building nostr client applications.", diff --git a/packages/content/package.json b/packages/content/package.json index 961c4e9..ab83bf5 100644 --- a/packages/content/package.json +++ b/packages/content/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/content", - "version": "0.4.3", + "version": "0.4.4", "author": "hodlbod", "license": "MIT", "description": "A collection of utilities for parsing nostr note content.", diff --git a/packages/editor/package.json b/packages/editor/package.json index 5c0f5b3..809fe26 100644 --- a/packages/editor/package.json +++ b/packages/editor/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/editor", - "version": "0.4.3", + "version": "0.4.4", "author": "hodlbod", "license": "MIT", "description": "A batteries-included nostr editor.", diff --git a/packages/feeds/package.json b/packages/feeds/package.json index 294999e..8d8b7f2 100644 --- a/packages/feeds/package.json +++ b/packages/feeds/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/feeds", - "version": "0.4.3", + "version": "0.4.4", "author": "hodlbod", "license": "MIT", "description": "Utilities for building dynamic nostr feeds.", diff --git a/packages/lib/package.json b/packages/lib/package.json index dc69471..bbd9bbd 100644 --- a/packages/lib/package.json +++ b/packages/lib/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/lib", - "version": "0.4.3", + "version": "0.4.4", "author": "hodlbod", "license": "MIT", "description": "A collection of utilities.", diff --git a/packages/net/package.json b/packages/net/package.json index fdca53e..6b691f9 100644 --- a/packages/net/package.json +++ b/packages/net/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/net", - "version": "0.4.3", + "version": "0.4.4", "author": "hodlbod", "license": "MIT", "description": "Utilities for connecting with nostr relays.", diff --git a/packages/relay/package.json b/packages/relay/package.json index 397d518..ce080b0 100644 --- a/packages/relay/package.json +++ b/packages/relay/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/relay", - "version": "0.4.3", + "version": "0.4.4", "author": "hodlbod", "license": "MIT", "description": "An in-memory nostr relay implementation.", diff --git a/packages/router/package.json b/packages/router/package.json index b3cbe07..939ffc8 100644 --- a/packages/router/package.json +++ b/packages/router/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/router", - "version": "0.4.3", + "version": "0.4.4", "author": "hodlbod", "license": "MIT", "description": "A collection of utilities for nostr relay selection.", diff --git a/packages/signer/package.json b/packages/signer/package.json index df5470a..0663f79 100644 --- a/packages/signer/package.json +++ b/packages/signer/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/signer", - "version": "0.4.3", + "version": "0.4.4", "author": "hodlbod", "license": "MIT", "description": "A nostr signer implemenation supporting several login methods.", diff --git a/packages/store/__tests__/index.test.ts b/packages/store/__tests__/index.test.ts index f77df6c..ec3a774 100644 --- a/packages/store/__tests__/index.test.ts +++ b/packages/store/__tests__/index.test.ts @@ -42,7 +42,7 @@ describe("Store utilities", () => { describe("synced", () => { it("should sync with localStorage", async () => { - const store = await synced({ + const store = synced({ key: "testKey", storage: localStorageProvider, defaultValue: "default", @@ -63,7 +63,7 @@ describe("Store utilities", () => { it("should load existing value from localStorage", async () => { localStorage.setItem("testKey", JSON.stringify("existing")) - const store = await synced({ + const store = synced({ key: "testKey", storage: localStorageProvider, defaultValue: "default", @@ -78,7 +78,7 @@ describe("Store utilities", () => { describe("getter", () => { it("should return current store value", async () => { - const store = await synced({ + const store = synced({ key: "test", storage: localStorageProvider, defaultValue: "initial", @@ -98,7 +98,7 @@ describe("Store utilities", () => { describe("withGetter", () => { it("should add getter to writable store", async () => { const store = withGetter( - await synced({ + synced({ key: "test", storage: localStorageProvider, defaultValue: "initial", @@ -117,7 +117,7 @@ describe("Store utilities", () => { describe("throttled", () => { it("should throttle updates", async () => { const mockFn = vi.fn() - const store = await synced({ + const store = synced({ key: "test", storage: localStorageProvider, defaultValue: 0, diff --git a/packages/store/package.json b/packages/store/package.json index 4d418f2..6daaaf9 100644 --- a/packages/store/package.json +++ b/packages/store/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/store", - "version": "0.4.3", + "version": "0.4.4", "author": "hodlbod", "license": "MIT", "description": "A collection of utilities based on svelte/store for use with welshman", diff --git a/packages/store/src/synced.ts b/packages/store/src/synced.ts index 23cd902..d94c3c1 100644 --- a/packages/store/src/synced.ts +++ b/packages/store/src/synced.ts @@ -40,8 +40,7 @@ export interface SyncedConfig { export const synced = ({key, storage, defaultValue}: SyncedConfig) => { const store = writable(defaultValue) as Synced - const syncPromise = sync({key, store, storage}) - store.ready = syncPromise + store.ready = sync({key, store, storage}) return store } diff --git a/packages/util/package.json b/packages/util/package.json index d3b164a..4975f0c 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/util", - "version": "0.4.3", + "version": "0.4.4", "author": "hodlbod", "license": "MIT", "description": "A collection of nostr-related utilities.",