import { WordpressCoreService } from '../WordpressCoreService'; /** * A post type the merchant can publish AI articles into. */ export interface PostTypeOption { slug: string; label: string; } /** * A single term (category, tag, ...) belonging to a taxonomy. */ export interface TaxonomyTerm { id: number; name: string; } /** * A taxonomy registered for the selected post type, with its terms. */ export interface Taxonomy { slug: string; label: string; hierarchical: boolean; terms: TaxonomyTerm[]; } /** * The article-publishing configuration returned by the plugin: the current * target plus everything the Settings UI needs to render the pickers. */ export interface ArticlePublishingConfig { post_type: string; parent_path: string; post_types: PostTypeOption[]; taxonomies: Taxonomy[]; selected_terms: Record; } /** * Payload sent when saving the article-publishing configuration. A parent_path * publishes articles as child Pages under that parent; otherwise post_type is * used as-is. */ export interface SaveArticlePublishingPayload { post_type: string; parent_path?: string; label?: string; terms?: Record; } const BASE_PATH: string = 'recomaze/v1/article-publishing'; /** * Fetch the current article-publishing config. Pass a tentative post type to * preview the taxonomies of a type the merchant is considering before saving. * * @param postType Optional post type slug to inspect instead of the saved one. * @return The current configuration and the data needed to render the pickers. */ export const getArticlePublishing = ( postType?: string ): Promise => { const query: string = postType ? `?post_type=${encodeURIComponent(postType)}` : ''; return WordpressCoreService.get( `${BASE_PATH}${query}` ); }; /** * Persist the chosen target post type, permalink root, label, and default * categories. * * @param payload The selection to store. * @return The stored post type slug and resolved default terms. */ export const saveArticlePublishing = ( payload: SaveArticlePublishingPayload ): Promise<{ post_type: string; selected_terms: Record }> => { return WordpressCoreService.post(BASE_PATH, payload); };