import { Fluxomail } from '@fluxomail/sdk'
const { token } = await (await fetch('/api/fluxomail/token', { method: 'POST' })).json()
const fm = new Fluxomail({ token, getToken: async () => {
// Auto-refresh for REST requests after 401
const r = await fetch('/api/fluxomail/token', { method: 'POST' })
return (await r.json()).token
}})
// Stream events (token sent as query param by the SDK)
const sub = fm.events.subscribe({ types: ['email.*'], checkpoint: {
get: () => localStorage.getItem('fluxo:lastEventId') || undefined,
set: (id) => localStorage.setItem('fluxo:lastEventId', id)
} }, (evt) => {
console.log(evt)
})