import apiFetch from '@wordpress/api-fetch' import { __ } from '@wordpress/i18n' export interface ChangelogEntry { /** Last path segment of the entry permalink, e.g. 2026-08-24-automatic-label-printing */ slug: string title: string date: string type: string /** Release the change shipped in, empty for changes made without a release */ version: string /** Whether this site already has the change */ installed: boolean contentHtml: string } export interface ChangelogResponse { /** False when the feed could not be read, so the page can say so */ feedOk: boolean /** Plugin version installed on this site */ currentVersion: string entries: Array } export const CHANGELOG_TYPES = [ 'new', 'improvement', 'fix', 'deprecated', 'removed', ] as const export const fetchChangelog = (): Promise => apiFetch({ path: '/posten-bring-checkout/changelog' }) export const changelogTypeLabel = (type: string): string => ({ new: __('New', 'posten-bring-checkout'), improvement: __('Improvement', 'posten-bring-checkout'), fix: __('Fix', 'posten-bring-checkout'), deprecated: __('Deprecated', 'posten-bring-checkout'), removed: __('Removed', 'posten-bring-checkout'), })[type] || type /** The entry a link points at, or nothing when the link cannot be read */ export const linkedEntryId = (hash: string): string | undefined => { try { return decodeURIComponent(hash.slice(1)) || undefined } catch { return undefined } } export const formatChangelogDate = (date: string): string => { if (!date) { return '' } // Feed dates are midnight UTC, so formatting in the browser's zone would // show the previous day for anyone west of UTC return new Date(date).toLocaleDateString(undefined, { timeZone: 'UTC', day: 'numeric', month: 'short', year: 'numeric', }) }