Docs

Start here

Eidos has two jobs: keep your Save clicks safe when the network flakes, and let reads work offline. Everything else is optional.

Next: Never lose a save →

Three steps

  1. Install

    terminal
    npm install @sweidos/eidos
    # pnpm add @sweidos/eidos
  2. Copy the helper file (Vite does this for you)

    Add the Vite plugin so eidos-sw.js lands in public/ on every build.

    vite.config.ts
    import { defineConfig } from 'vite'
    import { eidos } from '@sweidos/eidos/vite'
    export default defineConfig({
    plugins: [eidos()],
    })

    Not on Vite? Copy once: cp node_modules/@sweidos/eidos/dist/eidos-sw.js public/

  3. Wrap once, then declare Save + Read

    main.tsx
    import { createRoot } from 'react-dom/client'
    import { EidosProvider } from '@sweidos/eidos'
    import { App } from './App'
    createRoot(document.getElementById('root')!).render(
    <EidosProvider swPath="/eidos-sw.js">
    <App />
    </EidosProvider>,
    )
    src/lib/eidos.ts
    import { resource, action } from '@sweidos/eidos'
    import type { ActionContext } from '@sweidos/eidos'
    // Read — cache this GET when offline
    export const products = resource('/api/products', { offline: true })
    // Save — never lose this write; forward the ticket to your API
    export const createOrder = action(
    async (payload, ctx: ActionContext) => {
    const res = await fetch('/api/orders', {
    method: 'POST',
    headers: {
    'Content-Type': 'application/json',
    'Idempotency-Key': ctx.idempotencyKey,
    },
    body: JSON.stringify(payload),
    })
    return res.json()
    },
    { reliability: 'neverLose', name: 'createOrder' },
    )

    Keep resource / action at module scope so replay can find them after a reload.

Call it like a normal function

OrderButton.tsx
const result = await createOrder({ productId: 1, qty: 2 })
if ('queued' in result) {
// Offline or flaky — already saved in the pocket. Will retry.
showToast(result.message)
}

Try it without reading more

  • Open the playground → Try it.
  • Press sim offline in the header.
  • Hit Save on an action — watch the queue keep it.
  • Turn the network back on — it sends itself.