feat: add periodic NPC quote sync to daemon#2
Conversation
sh1ftred
commented
Mar 12, 2026
- Add /npc/sync endpoint to manually sync+redeem paid NPC quotes
- Add /npc/quotes endpoint to view quote history
- Add CLI commands: 'cocod npc quotes' and 'cocod npc sync'
- Add periodic sync to daemon (every 5 min by default)
- Configurable via COCOD_NPC_SYNC_INTERVAL_SECONDS env var
- Extract syncNpcQuotes as reusable function in routes.ts
Egge21M
left a comment
There was a problem hiding this comment.
Thank you for tackling this! I think this is a great solution for the problem, but on the wrong layer. This repeats lots of logic that is already part of https://github.com/Egge21M/coco-cashu-plugin-npc and should be solved there.
So I propose that we add a sync method on the plugin API, that can be called by cocod through the CLI. Additionally we use the plugins internal timer logic and wire up the sinceStore to properly persist sync timestamps
| import { createRouteHandlers, buildRoutes, syncNpcQuotes } from "./routes.js"; | ||
| import type { WalletConfig } from "./utils/config.js"; | ||
|
|
||
| const DEFAULT_NPC_SYNC_INTERVAL_SECONDS = 300; |
There was a problem hiding this comment.
The NPC Plugin for Coco has a syncIntervalMs option, that arms an additional interval based sync, additional to the websocket based sync.
| } | ||
|
|
||
| export async function syncNpcQuotes(manager: Manager, since = 0): Promise<NpcSyncResult> { | ||
| const quotes = await manager.ext.npc.getQuotesSince(since); |
There was a problem hiding this comment.
Everything after this point should not be necessary. The NPC Plugin is built to interact with the underlying coco services so that the synced mint quotes get added to the coco lifecycle automatically. I think we should add a sync method to the plugin API and call it from here
| ); | ||
| } | ||
|
|
||
| const result = await syncNpcQuotes(state.manager, since); |
There was a problem hiding this comment.
This should be replaced by a sync function that needs to be added to the plugin