import type { PortalMediaKind, SupportDocPayload, SupportDocSlug, SupportDocumentDetail, SupportDocVersionDetail, SupportDocVersionSummary, } from "@edr/types"; import { api as client } from "../auth/http"; const ROOT = "/support-content"; const BASE = `${ROOT}/documents`; /** * Customer-facing help/FAQ/legal copy for the freight portal. The client's * response interceptor already unwraps the `{ success, data }` envelope, so * every method is a one-liner. */ export const portalContentService = { async getBySlug(slug: SupportDocSlug): Promise { const { data } = await client.get(`${BASE}/${slug}`); return data; }, /** * Replaces the document's whole payload. Whole-payload rather than per-field * on purpose: one Save becomes exactly one version, which is what keeps the * history list readable. */ async update( slug: SupportDocSlug, payload: SupportDocPayload, note?: string, ): Promise { const { data } = await client.patch( `${BASE}/${slug}`, { payload, note }, ); return data; }, async listVersions(slug: SupportDocSlug): Promise { const { data } = await client.get( `${BASE}/${slug}/versions`, ); return data; }, async getVersion( slug: SupportDocSlug, version: number, ): Promise { const { data } = await client.get( `${BASE}/${slug}/versions/${version}`, ); return data; }, /** * Uploads an image or video and returns its object *key*. The key is what * gets saved in the document; `url` is only for showing the editor a preview * right now, and expires. */ async uploadMedia( file: File, ): Promise<{ key: string; kind: PortalMediaKind; url: string }> { const form = new FormData(); form.append("file", file); const { data } = await client.post<{ key: string; kind: PortalMediaKind; url: string; }>(`${ROOT}/media`, form); return data; }, /** Resolves one stored key to a temporary URL, for editor previews. */ async mediaUrl(key: string): Promise { const { data } = await client.get<{ url: string }>(`${ROOT}/media-url`, { params: { key }, }); return data.url; }, /** Re-saves an old payload as a new version — never destructive. */ async restore( slug: SupportDocSlug, version: number, ): Promise { const { data } = await client.post( `${BASE}/${slug}/versions/${version}/restore`, {}, ); return data; }, };