Skip to content

Kody is live

Watch the launch video — what Kody is, and why it exists.

← Public packages

@kentcdodds/package-app-kit

Design tokens, PWA install/update, About/version, cache helpers, and optional realtime notes sync for Kody package apps.

starter-remix/src/record-version.ts

40 lines · 1.4 KB · TypeScript
import { getAppVersion, setAppVersion, type AppVersion } from './version.ts'

/**
 * Persist publish metadata in this app's packageStorage for About + update checks.
 * Do not re-export the kit's ./record-version — that writes the kit's storage and
 * fails packageStorage provenance when called as kody:@scope/app/record-version.
 *
 * @param input.sha - Full git commit SHA (required)
 * @param input.message - First-line commit message
 * @param input.committedAt - Commit author/committer ISO time
 * @param input.publishedAt - Publish time (defaults to now)
 * @returns Normalized AppVersion stored in packageStorage
 *
 * @example
 * import recordVersion from 'kody:__PACKAGE_NAME__/record-version'
 * await recordVersion({ sha: 'abc123', message: 'Ship' })
 */
export default async function recordVersion(input: {
	sha: string
	message?: string
	committedAt?: string
	publishedAt?: string
}): Promise<AppVersion> {
	if (!input?.sha) throw new Error('sha is required')
	return await setAppVersion(input)
}

/**
 * Read the recorded version without writing.
 * Prefer this (or a relative import) for About / update-check server routes.
 *
 * @example
 * import { readRecordedVersion } from '../../src/record-version.ts'
 * const version = await readRecordedVersion()
 */
export async function readRecordedVersion(): Promise<AppVersion> {
	return await getAppVersion()
}

export type { AppVersion }