import type { ConfigFacade, FetchResult, WordPressConfig, WpBatchOperation, WpBatchResult, WpCategory, WpCategoryCreate, WpCategoryUpdate, WpComment, WpCommentCreate, WpCommentUpdate, WpMedia, WpMediaMeta, WpMediaUpdate, WpPage, WpPageCreate, WpPageUpdate, WpPost, WpPostCreate, WpPostUpdate, WpQueryParams, WpTag, WpTagCreate, WpTagUpdate, WpUser, WpUserCreate, WpUserUpdate } from "../../types/index.js"; /** * WordPressService - Singleton para el cliente del WordPress REST API. * * Aplica el patrón Singleton: una única instancia mantiene la configuración * (URL base, auth, namespace) y centraliza todas las operaciones CRUD contra * la REST API de WordPress, devolviendo siempre Safe Results. * * @example * ```ts * const wp = WordPressService.getInstance(); * wp.useInit({ baseUrl: "https://mysite.com", auth: { type: "jwt", token: "..." } }); * const result = await wp.useGetPosts({ per_page: 5 }); * ``` */ export declare class WordPressService { private static instance; /** Registered WordPress configuration. */ private config; /** * Constructor privado - enforce singleton. */ private constructor(); /** * Obtiene la instancia única del WordPressService (Singleton). * * @returns La instancia única de {@link WordPressService}. */ static getInstance(): WordPressService; /** * Retrieves the registered WordPress config or throws. * @internal */ private useGetConfig; /** * Builds the base API URL from config. * @internal */ private useGetApiBase; /** * Builds authentication headers from config. * @internal */ private useGetAuthHeaders; /** * Internal helper to make requests to the WordPress REST API. * @internal */ private useRequest; /** * Internal helper for multipart file uploads. * @internal */ private useUpload; /** * Registers the WordPress REST API configuration. * * Supports multiple auth methods: Application Passwords, JWT tokens, * Basic Auth, and nonce-based auth for themes. * * @param cfg - Site URL, authentication method, and optional API namespace. * @throws {Error} If the config fails Zod validation. * * @example * ```ts * WordPressService.getInstance().useInit({ * baseUrl: "https://mysite.com", * auth: { type: "application-passwords", username: "admin", password: "xxxx xxxx xxxx" }, * }); * ``` */ useInit(cfg: WordPressConfig): void; /** Retrieves a list of WordPress posts with optional filtering and pagination. */ useGetPosts(options?: WpQueryParams): Promise>; /** Retrieves a single WordPress post by ID. */ useGetPost(id: number, options?: WpQueryParams): Promise>; /** Creates a new WordPress post. */ useCreatePost(data: WpPostCreate): Promise>; /** Updates an existing WordPress post. */ useUpdatePost(id: number, data: WpPostUpdate): Promise>; /** Deletes a WordPress post (trash by default, permanent with `force`). */ useDeletePost(id: number, force?: boolean): Promise>; /** Retrieves a list of WordPress pages. */ useGetPages(options?: WpQueryParams): Promise>; /** Retrieves a single WordPress page by ID. */ useGetPage(id: number, options?: WpQueryParams): Promise>; /** Creates a new WordPress page. */ useCreatePage(data: WpPageCreate): Promise>; /** Updates an existing WordPress page. */ useUpdatePage(id: number, data: WpPageUpdate): Promise>; /** Deletes a WordPress page (trash by default, permanent with `force`). */ useDeletePage(id: number, force?: boolean): Promise>; /** Retrieves a list of WordPress media items. */ useGetMedia(options?: WpQueryParams): Promise>; /** Retrieves a single WordPress media item by ID. */ useGetMediaItem(id: number): Promise>; /** Uploads a file to the WordPress media library. */ useUploadMedia(file: File | Blob | Buffer, meta?: WpMediaMeta): Promise>; /** Updates metadata of a WordPress media item. */ useUpdateMedia(id: number, data: WpMediaUpdate): Promise>; /** Deletes a WordPress media item. */ useDeleteMedia(id: number, force?: boolean): Promise>; /** Retrieves a list of WordPress categories. */ useGetCategories(options?: WpQueryParams): Promise>; /** Retrieves a single WordPress category by ID. */ useGetCategory(id: number): Promise>; /** Creates a new WordPress category. */ useCreateCategory(data: WpCategoryCreate): Promise>; /** Updates an existing WordPress category. */ useUpdateCategory(id: number, data: WpCategoryUpdate): Promise>; /** Deletes a WordPress category. */ useDeleteCategory(id: number, force?: boolean): Promise>; /** Retrieves a list of WordPress tags. */ useGetTags(options?: WpQueryParams): Promise>; /** Retrieves a single WordPress tag by ID. */ useGetTag(id: number): Promise>; /** Creates a new WordPress tag. */ useCreateTag(data: WpTagCreate): Promise>; /** Updates an existing WordPress tag. */ useUpdateTag(id: number, data: WpTagUpdate): Promise>; /** Deletes a WordPress tag. */ useDeleteTag(id: number, force?: boolean): Promise>; /** Retrieves a list of WordPress comments. */ useGetComments(options?: WpQueryParams): Promise>; /** Retrieves a single WordPress comment by ID. */ useGetComment(id: number): Promise>; /** Creates a new WordPress comment. */ useCreateComment(data: WpCommentCreate): Promise>; /** Updates an existing WordPress comment. */ useUpdateComment(id: number, data: WpCommentUpdate): Promise>; /** Deletes a WordPress comment. */ useDeleteComment(id: number, force?: boolean): Promise>; /** Retrieves a list of WordPress users. */ useGetUsers(options?: WpQueryParams): Promise>; /** Retrieves a single WordPress user by ID. */ useGetUser(id: number): Promise>; /** Retrieves the currently authenticated WordPress user. */ useGetCurrentUser(): Promise>; /** Creates a new WordPress user. */ useCreateUser(data: WpUserCreate): Promise>; /** Updates an existing WordPress user. */ useUpdateUser(id: number, data: WpUserUpdate): Promise>; /** Deletes a WordPress user, optionally reassigning their content. */ useDeleteUser(id: number, reassign?: number): Promise>; /** Retrieves a list of custom post type entries. */ useGetCustomPosts(postType: string, options?: WpQueryParams): Promise>; /** Retrieves a single custom post type entry by ID. */ useGetCustomPost(postType: string, id: number, options?: WpQueryParams): Promise>; /** Creates a new custom post type entry. */ useCreateCustomPost(postType: string, data: Record): Promise>; /** Updates a custom post type entry. */ useUpdateCustomPost(postType: string, id: number, data: Record): Promise>; /** Deletes a custom post type entry. */ useDeleteCustomPost(postType: string, id: number, force?: boolean): Promise>; /** Executes multiple WordPress REST API requests in a single batch. */ useBatch(operations: WpBatchOperation[]): Promise>; /** * Fetches ALL posts matching the criteria, automatically handling pagination. * * @param options - Query params for filtering. Do NOT pass `page` or `per_page`. * @param maxItems - Cap on the total number of posts to fetch (default `1000`). */ useListAllPosts(options?: WpQueryParams, maxItems?: number): Promise>; /** Searches ALL posts by keyword, automatically handling pagination. */ useSearchAllPosts(query: string, options?: WpQueryParams): Promise>; /** Finds a single post by its URL slug. Returns `null` if not found. */ useFindPostBySlug(slug: string): Promise>; } /** * Registers the WordPress configuration and returns your methods alongside it — * the config-file entry point. One call is the whole setup: no separate * `useInitWordPress(...)` step. * * Supports multiple auth methods: Application Passwords (recommended for * plugins), JWT tokens, Basic Auth, and nonce-based auth for themes. * * Declare methods with `function` (never arrows) so `this.config` resolves to * the registered config. * * @typeParam T - The literal passed in: WordPress config plus any methods. * @param input - Site URL, auth method and optional namespace, plus your methods. * @returns The registered config plus your methods (see {@link ConfigFacade}). * @throws {Error} If the config fails Zod validation. * * @example * ```ts * import { defineWordPressConfig } from "katanakit-js/adapters/wordpress"; * * export default defineWordPressConfig({ * baseUrl: "https://mysite.com", * auth: { type: "application-passwords", username: "admin", password: "xxxx xxxx xxxx" }, * getLatest: async function () { * return useWpGetPosts({ per_page: 5 }); * }, * }); * ``` */ export declare function defineWordPressConfig(input: T & ThisType>): ConfigFacade; /** * Registers the WordPress REST API configuration. Call this once before * any other WordPress function. * * @deprecated Use {@link defineWordPressConfig}, which registers the config and * returns it with any methods declared on the same literal. * * Supports multiple auth methods: Application Passwords (recommended for * plugins), JWT tokens, Basic Auth, and nonce-based auth for themes. * * @param cfg - Site URL, authentication method, and optional API namespace. * * @example * ```ts * import { useInitWordPress } from "katanakit-js/adapters/wordpress"; * * useInitWordPress({ * baseUrl: "https://mysite.com", * auth: { type: "application-passwords", username: "admin", password: "xxxx xxxx xxxx" }, * }); * ``` */ export declare function useInitWordPress(cfg: WordPressConfig): void; /** * Retrieves a list of WordPress posts with optional filtering and pagination. * * @param options - Query params: `per_page`, `page`, `search`, `categories`, etc. * @returns Array of posts. * * @example * ```ts * const result = await useWpGetPosts({ per_page: 5, status: "publish" }); * ``` */ export declare function useWpGetPosts(options?: WpQueryParams): Promise>; /** * Retrieves a single WordPress post by ID. * * @param id - The post ID. * @param options - Optional query params (e.g. _embed for featured media). * @returns The post object. * * @example * ```ts * const result = await useWpGetPost(42, { _embed: true }); * ``` */ export declare function useWpGetPost(id: number, options?: WpQueryParams): Promise>; /** * Creates a new WordPress post. * * @param data - Post data: `title`, `content`, `status`, `categories`, etc. * @returns The created post. * * @example * ```ts * const result = await useWpCreatePost({ title: "My New Post", content: "

Hello

", status: "publish" }); * ``` */ export declare function useWpCreatePost(data: WpPostCreate): Promise>; /** * Updates an existing WordPress post. * * @param id - The post ID to update. * @param data - Fields to update. * @returns The updated post. * * @example * ```ts * await useWpUpdatePost(42, { title: "Updated Title" }); * ``` */ export declare function useWpUpdatePost(id: number, data: WpPostUpdate): Promise>; /** * Deletes a WordPress post. * * @param id - The post ID to delete. * @param force - If true, permanently deletes. If false, moves to trash. * @returns The deleted post. * * @example * ```ts * await useWpDeletePost(42, true); * ``` */ export declare function useWpDeletePost(id: number, force?: boolean): Promise>; /** * Retrieves a list of WordPress pages. * * @param options - Query params for filtering, sorting, and pagination. * @returns Array of pages. * * @example * ```ts * const result = await useWpGetPages({ per_page: 20 }); * ``` */ export declare function useWpGetPages(options?: WpQueryParams): Promise>; /** * Retrieves a single WordPress page by ID. * * @param id - The page ID. * @param options - Optional query params. * @returns The page object. * * @example * ```ts * const result = await useWpGetPage(10); * ``` */ export declare function useWpGetPage(id: number, options?: WpQueryParams): Promise>; /** * Creates a new WordPress page. * * @param data - Page data (title, content, parent, etc.). * @returns The created page. * * @example * ```ts * await useWpCreatePage({ title: "About Us", content: "

Welcome

", status: "publish" }); * ``` */ export declare function useWpCreatePage(data: WpPageCreate): Promise>; /** * Updates an existing WordPress page. * * @param id - The page ID to update. * @param data - Fields to update. * @returns The updated page. * * @example * ```ts * await useWpUpdatePage(10, { title: "Updated About" }); * ``` */ export declare function useWpUpdatePage(id: number, data: WpPageUpdate): Promise>; /** * Deletes a WordPress page. * * @param id - The page ID to delete. * @param force - If true, permanently deletes. If false, moves to trash. * @returns The deleted page. * * @example * ```ts * await useWpDeletePage(10); * ``` */ export declare function useWpDeletePage(id: number, force?: boolean): Promise>; /** * Retrieves a list of WordPress media items. * * @param options - Query params for filtering and pagination. * @returns Array of media items. * * @example * ```ts * const result = await useWpGetMedia({ per_page: 20 }); * ``` */ export declare function useWpGetMedia(options?: WpQueryParams): Promise>; /** * Retrieves a single WordPress media item by ID. * * @param id - The media item ID. * @returns The media object. * * @example * ```ts * const result = await useWpGetMediaItem(42); * ``` */ export declare function useWpGetMediaItem(id: number): Promise>; /** * Uploads a file to the WordPress media library. * * @param file - File (browser), Blob, or Buffer (Node.js) to upload. * @param meta - Optional metadata: `title`, `alt_text`, `caption`, etc. * @returns The created media item with `source_url`. * * @example * ```ts * const result = await useWpUploadMedia(file, { title: "My Image" }); * ``` */ export declare function useWpUploadMedia(file: File | Blob | Buffer, meta?: WpMediaMeta): Promise>; /** * Updates metadata of a WordPress media item. * * @param id - The media item ID. * @param data - Fields to update. * @returns The updated media item. * * @example * ```ts * await useWpUpdateMedia(42, { alt_text: "New alt text" }); * ``` */ export declare function useWpUpdateMedia(id: number, data: WpMediaUpdate): Promise>; /** * Deletes a WordPress media item. * * @param id - The media item ID. * @param force - If true, permanently deletes. * @returns The deleted media item. * * @example * ```ts * await useWpDeleteMedia(42, true); * ``` */ export declare function useWpDeleteMedia(id: number, force?: boolean): Promise>; /** * Retrieves a list of WordPress categories. * * @param options - Query params for filtering and pagination. * @returns Array of categories. * * @example * ```ts * const result = await useWpGetCategories({ per_page: 50 }); * ``` */ export declare function useWpGetCategories(options?: WpQueryParams): Promise>; /** * Retrieves a single WordPress category by ID. * * @param id - The category ID. * @returns The category object. * * @example * ```ts * const result = await useWpGetCategory(5); * ``` */ export declare function useWpGetCategory(id: number): Promise>; /** * Creates a new WordPress category. * * @param data - Category data (name, slug, parent, etc.). * @returns The created category. * * @example * ```ts * await useWpCreateCategory({ name: "Technology", slug: "tech" }); * ``` */ export declare function useWpCreateCategory(data: WpCategoryCreate): Promise>; /** * Updates an existing WordPress category. * * @param id - The category ID to update. * @param data - Fields to update. * @returns The updated category. * * @example * ```ts * await useWpUpdateCategory(5, { name: "Tech News" }); * ``` */ export declare function useWpUpdateCategory(id: number, data: WpCategoryUpdate): Promise>; /** * Deletes a WordPress category. * * @param id - The category ID to delete. * @param force - If true, permanently deletes. * @returns The deleted category. * * @example * ```ts * await useWpDeleteCategory(5); * ``` */ export declare function useWpDeleteCategory(id: number, force?: boolean): Promise>; /** * Retrieves a list of WordPress tags. * * @param options - Query params for filtering and pagination. * @returns Array of tags. * * @example * ```ts * const result = await useWpGetTags({ search: "javascript" }); * ``` */ export declare function useWpGetTags(options?: WpQueryParams): Promise>; /** * Retrieves a single WordPress tag by ID. * * @param id - The tag ID. * @returns The tag object. * * @example * ```ts * const result = await useWpGetTag(12); * ``` */ export declare function useWpGetTag(id: number): Promise>; /** * Creates a new WordPress tag. * * @param data - Tag data (name, slug, etc.). * @returns The created tag. * * @example * ```ts * await useWpCreateTag({ name: "TypeScript", slug: "typescript" }); * ``` */ export declare function useWpCreateTag(data: WpTagCreate): Promise>; /** * Updates an existing WordPress tag. * * @param id - The tag ID to update. * @param data - Fields to update. * @returns The updated tag. * * @example * ```ts * await useWpUpdateTag(12, { name: "TS" }); * ``` */ export declare function useWpUpdateTag(id: number, data: WpTagUpdate): Promise>; /** * Deletes a WordPress tag. * * @param id - The tag ID to delete. * @param force - If true, permanently deletes. * @returns The deleted tag. * * @example * ```ts * await useWpDeleteTag(12); * ``` */ export declare function useWpDeleteTag(id: number, force?: boolean): Promise>; /** * Retrieves a list of WordPress comments. * * @param options - Query params for filtering and pagination. * @returns Array of comments. * * @example * ```ts * const result = await useWpGetComments({ post: 42 }); * ``` */ export declare function useWpGetComments(options?: WpQueryParams): Promise>; /** * Retrieves a single WordPress comment by ID. * * @param id - The comment ID. * @returns The comment object. * * @example * ```ts * const result = await useWpGetComment(7); * ``` */ export declare function useWpGetComment(id: number): Promise>; /** * Creates a new WordPress comment. * * @param data - Comment data (post ID, content, author, etc.). * @returns The created comment. * * @example * ```ts * await useWpCreateComment({ post: 42, content: "Great article!" }); * ``` */ export declare function useWpCreateComment(data: WpCommentCreate): Promise>; /** * Updates an existing WordPress comment. * * @param id - The comment ID to update. * @param data - Fields to update. * @returns The updated comment. * * @example * ```ts * await useWpUpdateComment(7, { content: "Updated comment" }); * ``` */ export declare function useWpUpdateComment(id: number, data: WpCommentUpdate): Promise>; /** * Deletes a WordPress comment. * * @param id - The comment ID to delete. * @param force - If true, permanently deletes. * @returns The deleted comment. * * @example * ```ts * await useWpDeleteComment(7); * ``` */ export declare function useWpDeleteComment(id: number, force?: boolean): Promise>; /** * Retrieves a list of WordPress users. * * @param options - Query params for filtering and pagination. * @returns Array of users. * * @example * ```ts * const result = await useWpGetUsers({ roles: "editor" }); * ``` */ export declare function useWpGetUsers(options?: WpQueryParams): Promise>; /** * Retrieves a single WordPress user by ID. * * @param id - The user ID. * @returns The user object. * * @example * ```ts * const result = await useWpGetUser(1); * ``` */ export declare function useWpGetUser(id: number): Promise>; /** * Retrieves the currently authenticated WordPress user. * * @returns The current user object. * * @example * ```ts * const result = await useWpGetCurrentUser(); * ``` */ export declare function useWpGetCurrentUser(): Promise>; /** * Creates a new WordPress user. * * @param data - User data (username, email, password, etc.). * @returns The created user. * * @example * ```ts * await useWpCreateUser({ username: "johndoe", email: "john@example.com", password: "..." }); * ``` */ export declare function useWpCreateUser(data: WpUserCreate): Promise>; /** * Updates an existing WordPress user. * * @param id - The user ID to update. * @param data - Fields to update. * @returns The updated user. * * @example * ```ts * await useWpUpdateUser(2, { name: "John Smith" }); * ``` */ export declare function useWpUpdateUser(id: number, data: WpUserUpdate): Promise>; /** * Deletes a WordPress user. * * @param id - The user ID to delete. * @param reassign - User ID to reassign content to (required for non-admin). * @returns The deleted user. * * @example * ```ts * await useWpDeleteUser(2, 1); * ``` */ export declare function useWpDeleteUser(id: number, reassign?: number): Promise>; /** * Retrieves a list of custom post type entries. * * @param postType - The custom post type slug (e.g. "product", "portfolio"). * @param options - Query params for filtering and pagination. * @returns Array of custom post entries. * * @example * ```ts * const result = await useWpGetCustomPosts("product", { per_page: 10 }); * ``` */ export declare function useWpGetCustomPosts(postType: string, options?: WpQueryParams): Promise>; /** * Retrieves a single custom post type entry by ID. * * @param postType - The custom post type slug. * @param id - The entry ID. * @param options - Optional query params. * @returns The custom post entry. * * @example * ```ts * const result = await useWpGetCustomPost("product", 15); * ``` */ export declare function useWpGetCustomPost(postType: string, id: number, options?: WpQueryParams): Promise>; /** * Creates a new custom post type entry. * * @param postType - The custom post type slug. * @param data - Entry data. * @returns The created entry. * * @example * ```ts * await useWpCreateCustomPost("product", { title: "Widget", status: "publish" }); * ``` */ export declare function useWpCreateCustomPost(postType: string, data: Record): Promise>; /** * Updates a custom post type entry. * * @param postType - The custom post type slug. * @param id - The entry ID. * @param data - Fields to update. * @returns The updated entry. * * @example * ```ts * await useWpUpdateCustomPost("product", 15, { title: "Updated Widget" }); * ``` */ export declare function useWpUpdateCustomPost(postType: string, id: number, data: Record): Promise>; /** * Deletes a custom post type entry. * * @param postType - The custom post type slug. * @param id - The entry ID. * @param force - If true, permanently deletes. * @returns The deleted entry. * * @example * ```ts * await useWpDeleteCustomPost("product", 15, true); * ``` */ export declare function useWpDeleteCustomPost(postType: string, id: number, force?: boolean): Promise>; /** * Executes multiple WordPress REST API requests in a single batch. * * @param operations - Array of batch operations to execute. * @returns Combined results from all operations. * * @example * ```ts * const result = await useWpBatch([ * { method: "GET", path: "/wp/v2/posts/1" }, * ]); * ``` */ export declare function useWpBatch(operations: WpBatchOperation[]): Promise>; /** * Fetches ALL posts matching the criteria, automatically handling pagination. * * @param options - Query params for filtering. Do NOT pass `page` or `per_page`. * @param maxItems - Cap on the total number of posts to fetch (default `1000`). * @returns All posts as a flat array. * * @example * ```ts * const result = await useWpListAllPosts({ status: "publish" }); * ``` */ export declare function useWpListAllPosts(options?: WpQueryParams, maxItems?: number): Promise>; /** * Searches ALL posts by keyword, automatically handling pagination. * * @param query - Search term (searches title and content). * @param options - Additional filters (`status`, `categories`, etc.). * @returns All posts matching the search. * * @example * ```ts * const result = await useWpSearchAllPosts("tutorial"); * ``` */ export declare function useWpSearchAllPosts(query: string, options?: WpQueryParams): Promise>; /** * Finds a single post by its URL slug. Returns `null` if not found. * * @param slug - The post slug (e.g. "hello-world"). * @returns The post or `null` if not found. * * @example * ```ts * const result = await useWpFindPostBySlug("hello-world"); * ``` */ export declare function useWpFindPostBySlug(slug: string): Promise>; //# sourceMappingURL=wordpress.service.d.ts.map