← Public packages
@kody/mailroom
Offline-first PWA for your Kody mailbox: sent and received threads, copy-prompt for agents, no send.
src/version.ts
33 lines · 821 B · TypeScriptimport { getSetting, setSetting } from './settings.ts'
import {
emptyVersion,
normalizeVersion,
type AppVersion,
} from './version-shape.ts'
export type { AppVersion } from './version-shape.ts'
export { emptyVersion, normalizeVersion }
const KEY = 'app_version'
export async function getAppVersion(): Promise<AppVersion> {
const raw = await getSetting(KEY)
if (!raw) return emptyVersion()
try {
return normalizeVersion(JSON.parse(raw) as Partial<AppVersion>)
} catch {
return emptyVersion()
}
}
export async function setAppVersion(
input: Partial<AppVersion> & { sha: string },
): Promise<AppVersion> {
const next = normalizeVersion({
...(await getAppVersion()),
...input,
publishedAt: input.publishedAt || new Date().toISOString(),
})
await setSetting(KEY, JSON.stringify(next))
return next
}