mcp-wordpress 2.11.13 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/README.md +14 -29
  2. package/dist/cache/CacheInvalidation.js.map +1 -1
  3. package/dist/cache/CacheManager.d.ts +7 -0
  4. package/dist/cache/CacheManager.d.ts.map +1 -1
  5. package/dist/cache/CacheManager.js +21 -7
  6. package/dist/cache/CacheManager.js.map +1 -1
  7. package/dist/cache/HttpCacheWrapper.js.map +1 -1
  8. package/dist/cache/SEOCacheManager.d.ts.map +1 -1
  9. package/dist/cache/SEOCacheManager.js +6 -1
  10. package/dist/cache/SEOCacheManager.js.map +1 -1
  11. package/dist/cache/index.d.ts.map +1 -1
  12. package/dist/cache/index.js.map +1 -1
  13. package/dist/client/CachedWordPressClient.d.ts.map +1 -1
  14. package/dist/client/CachedWordPressClient.js.map +1 -1
  15. package/dist/client/MockWordPressClient.d.ts.map +1 -1
  16. package/dist/client/MockWordPressClient.js.map +1 -1
  17. package/dist/client/SEOWordPressClient.d.ts.map +1 -1
  18. package/dist/client/SEOWordPressClient.js.map +1 -1
  19. package/dist/client/api.d.ts +11 -26
  20. package/dist/client/api.d.ts.map +1 -1
  21. package/dist/client/api.js +111 -203
  22. package/dist/client/api.js.map +1 -1
  23. package/dist/client/auth.d.ts.map +1 -1
  24. package/dist/client/auth.js.map +1 -1
  25. package/dist/client/managers/AuthManager.d.ts.map +1 -1
  26. package/dist/client/managers/RequestManager.d.ts.map +1 -1
  27. package/dist/client/managers/RequestManager.js +6 -5
  28. package/dist/client/managers/RequestManager.js.map +1 -1
  29. package/dist/client/managers/composed/MigrationAdapter.d.ts +3 -3
  30. package/dist/client/managers/composed/MigrationAdapter.d.ts.map +1 -1
  31. package/dist/client/managers/composed/MigrationAdapter.js +2 -2
  32. package/dist/client/managers/composed/MigrationAdapter.js.map +1 -1
  33. package/dist/client/managers/composed/index.d.ts +7 -7
  34. package/dist/client/managers/composed/index.d.ts.map +1 -1
  35. package/dist/client/managers/composed/index.js +6 -6
  36. package/dist/client/managers/composed/index.js.map +1 -1
  37. package/dist/client/managers/implementations/ConfigurationProviderImpl.d.ts +1 -1
  38. package/dist/client/managers/implementations/ConfigurationProviderImpl.d.ts.map +1 -1
  39. package/dist/client/managers/implementations/ErrorHandlerImpl.d.ts +1 -1
  40. package/dist/client/managers/implementations/ErrorHandlerImpl.d.ts.map +1 -1
  41. package/dist/client/managers/implementations/ParameterValidatorImpl.d.ts +1 -1
  42. package/dist/client/managers/implementations/ParameterValidatorImpl.d.ts.map +1 -1
  43. package/dist/client/operations/comments.d.ts +58 -0
  44. package/dist/client/operations/comments.d.ts.map +1 -0
  45. package/dist/client/operations/comments.js +74 -0
  46. package/dist/client/operations/comments.js.map +1 -0
  47. package/dist/client/operations/index.d.ts +12 -0
  48. package/dist/client/operations/index.d.ts.map +1 -0
  49. package/dist/client/operations/index.js +12 -0
  50. package/dist/client/operations/index.js.map +1 -0
  51. package/dist/client/operations/media.d.ts +55 -0
  52. package/dist/client/operations/media.d.ts.map +1 -0
  53. package/dist/client/operations/media.js +132 -0
  54. package/dist/client/operations/media.js.map +1 -0
  55. package/dist/client/operations/pages.d.ts +50 -0
  56. package/dist/client/operations/pages.d.ts.map +1 -0
  57. package/dist/client/operations/pages.js +56 -0
  58. package/dist/client/operations/pages.js.map +1 -0
  59. package/dist/client/operations/posts.d.ts +50 -0
  60. package/dist/client/operations/posts.d.ts.map +1 -0
  61. package/dist/client/operations/posts.js +53 -0
  62. package/dist/client/operations/posts.js.map +1 -0
  63. package/dist/client/operations/site.d.ts +60 -0
  64. package/dist/client/operations/site.d.ts.map +1 -0
  65. package/dist/client/operations/site.js +83 -0
  66. package/dist/client/operations/site.js.map +1 -0
  67. package/dist/client/operations/taxonomies.d.ts +69 -0
  68. package/dist/client/operations/taxonomies.d.ts.map +1 -0
  69. package/dist/client/operations/taxonomies.js +87 -0
  70. package/dist/client/operations/taxonomies.js.map +1 -0
  71. package/dist/client/operations/users.d.ts +50 -0
  72. package/dist/client/operations/users.d.ts.map +1 -0
  73. package/dist/client/operations/users.js +57 -0
  74. package/dist/client/operations/users.js.map +1 -0
  75. package/dist/config/ServerConfiguration.d.ts.map +1 -1
  76. package/dist/config/ServerConfiguration.js.map +1 -1
  77. package/dist/docs/DocumentationGenerator.js.map +1 -1
  78. package/dist/performance/MetricsCollector.d.ts.map +1 -1
  79. package/dist/performance/MetricsCollector.js.map +1 -1
  80. package/dist/performance/PerformanceMonitor.js.map +1 -1
  81. package/dist/security/AISecurityScanner.d.ts.map +1 -1
  82. package/dist/security/AISecurityScanner.js +3 -2
  83. package/dist/security/AISecurityScanner.js.map +1 -1
  84. package/dist/security/AutomatedRemediation.js.map +1 -1
  85. package/dist/security/InputValidator.d.ts.map +1 -1
  86. package/dist/security/InputValidator.js +30 -18
  87. package/dist/security/InputValidator.js.map +1 -1
  88. package/dist/security/SecurityCIPipeline.d.ts +19 -196
  89. package/dist/security/SecurityCIPipeline.d.ts.map +1 -1
  90. package/dist/security/SecurityCIPipeline.js +95 -639
  91. package/dist/security/SecurityCIPipeline.js.map +1 -1
  92. package/dist/security/SecurityConfig.js.map +1 -1
  93. package/dist/security/SecurityConfigManager.js.map +1 -1
  94. package/dist/security/SecurityGateExecutor.d.ts +67 -0
  95. package/dist/security/SecurityGateExecutor.d.ts.map +1 -0
  96. package/dist/security/SecurityGateExecutor.js +363 -0
  97. package/dist/security/SecurityGateExecutor.js.map +1 -0
  98. package/dist/security/SecurityMonitoring.js.map +1 -1
  99. package/dist/security/SecurityReportGenerator.d.ts +65 -0
  100. package/dist/security/SecurityReportGenerator.d.ts.map +1 -0
  101. package/dist/security/SecurityReportGenerator.js +210 -0
  102. package/dist/security/SecurityReportGenerator.js.map +1 -0
  103. package/dist/security/SecurityReviewer.js.map +1 -1
  104. package/dist/security/SecurityTypes.d.ts +188 -0
  105. package/dist/security/SecurityTypes.d.ts.map +1 -0
  106. package/dist/security/SecurityTypes.js +6 -0
  107. package/dist/security/SecurityTypes.js.map +1 -0
  108. package/dist/security/index.d.ts +5 -28
  109. package/dist/security/index.d.ts.map +1 -1
  110. package/dist/security/index.js +4 -0
  111. package/dist/security/index.js.map +1 -1
  112. package/dist/server/ConnectionTester.d.ts.map +1 -1
  113. package/dist/server/ConnectionTester.js.map +1 -1
  114. package/dist/server/ToolRegistry.d.ts.map +1 -1
  115. package/dist/server/ToolRegistry.js.map +1 -1
  116. package/dist/tools/BaseToolManager.d.ts.map +1 -1
  117. package/dist/tools/BaseToolManager.js.map +1 -1
  118. package/dist/tools/auth.d.ts.map +1 -1
  119. package/dist/tools/auth.js.map +1 -1
  120. package/dist/tools/cache.d.ts.map +1 -1
  121. package/dist/tools/cache.js.map +1 -1
  122. package/dist/tools/comments.d.ts.map +1 -1
  123. package/dist/tools/comments.js.map +1 -1
  124. package/dist/tools/media.d.ts.map +1 -1
  125. package/dist/tools/media.js.map +1 -1
  126. package/dist/tools/pages.d.ts.map +1 -1
  127. package/dist/tools/pages.js.map +1 -1
  128. package/dist/tools/performance/PerformanceHelpers.d.ts +116 -0
  129. package/dist/tools/performance/PerformanceHelpers.d.ts.map +1 -0
  130. package/dist/tools/performance/PerformanceHelpers.js +298 -0
  131. package/dist/tools/performance/PerformanceHelpers.js.map +1 -0
  132. package/dist/tools/performance/PerformanceTools.d.ts +54 -0
  133. package/dist/tools/performance/PerformanceTools.d.ts.map +1 -0
  134. package/dist/tools/performance/PerformanceTools.js +687 -0
  135. package/dist/tools/performance/PerformanceTools.js.map +1 -0
  136. package/dist/tools/performance/index.d.ts +8 -0
  137. package/dist/tools/performance/index.d.ts.map +1 -0
  138. package/dist/tools/performance/index.js +8 -0
  139. package/dist/tools/performance/index.js.map +1 -0
  140. package/dist/tools/performance.d.ts +12 -69
  141. package/dist/tools/performance.d.ts.map +1 -1
  142. package/dist/tools/performance.js +12 -920
  143. package/dist/tools/performance.js.map +1 -1
  144. package/dist/tools/posts.d.ts.map +1 -1
  145. package/dist/tools/seo/analyzers/ContentAnalyzer.d.ts.map +1 -1
  146. package/dist/tools/seo/analyzers/ContentAnalyzer.js +14 -3
  147. package/dist/tools/seo/analyzers/ContentAnalyzer.js.map +1 -1
  148. package/dist/tools/seo/auditors/SiteAuditor.d.ts.map +1 -1
  149. package/dist/tools/seo/auditors/SiteAuditor.js +12 -3
  150. package/dist/tools/seo/auditors/SiteAuditor.js.map +1 -1
  151. package/dist/tools/seo/generators/MetaGenerator.d.ts.map +1 -1
  152. package/dist/tools/seo/generators/MetaGenerator.js +25 -8
  153. package/dist/tools/seo/generators/MetaGenerator.js.map +1 -1
  154. package/dist/tools/seo/generators/SchemaGenerator.d.ts.map +1 -1
  155. package/dist/tools/seo/generators/SchemaGenerator.js.map +1 -1
  156. package/dist/tools/seo/optimizers/InternalLinkingSuggester.d.ts.map +1 -1
  157. package/dist/tools/seo/optimizers/InternalLinkingSuggester.js.map +1 -1
  158. package/dist/tools/site.d.ts.map +1 -1
  159. package/dist/tools/site.js.map +1 -1
  160. package/dist/tools/taxonomies.d.ts.map +1 -1
  161. package/dist/tools/taxonomies.js.map +1 -1
  162. package/dist/tools/users.d.ts.map +1 -1
  163. package/dist/tools/users.js.map +1 -1
  164. package/dist/utils/CircuitBreaker.d.ts +243 -0
  165. package/dist/utils/CircuitBreaker.d.ts.map +1 -0
  166. package/dist/utils/CircuitBreaker.js +456 -0
  167. package/dist/utils/CircuitBreaker.js.map +1 -0
  168. package/dist/utils/debug.d.ts.map +1 -1
  169. package/dist/utils/debug.js.map +1 -1
  170. package/dist/utils/error.js.map +1 -1
  171. package/dist/utils/index.d.ts +1 -0
  172. package/dist/utils/index.d.ts.map +1 -1
  173. package/dist/utils/index.js +2 -0
  174. package/dist/utils/index.js.map +1 -1
  175. package/dist/utils/logger.js.map +1 -1
  176. package/dist/utils/toolWrapper.d.ts.map +1 -1
  177. package/docs/DEPRECATIONS.md +157 -0
  178. package/package.json +2 -3
  179. package/src/cache/CacheInvalidation.ts +1 -1
  180. package/src/cache/CacheManager.ts +25 -8
  181. package/src/cache/HttpCacheWrapper.ts +1 -1
  182. package/src/cache/SEOCacheManager.ts +9 -3
  183. package/src/cache/index.ts +1 -1
  184. package/src/client/CachedWordPressClient.ts +6 -6
  185. package/src/client/MockWordPressClient.ts +3 -3
  186. package/src/client/SEOWordPressClient.ts +6 -6
  187. package/src/client/api.ts +129 -215
  188. package/src/client/auth.ts +3 -3
  189. package/src/client/managers/AuthManager.ts +1 -1
  190. package/src/client/managers/RequestManager.ts +6 -7
  191. package/src/client/managers/composed/MigrationAdapter.ts +4 -4
  192. package/src/client/managers/composed/index.ts +7 -7
  193. package/src/client/managers/implementations/ConfigurationProviderImpl.ts +1 -1
  194. package/src/client/managers/implementations/ErrorHandlerImpl.ts +1 -1
  195. package/src/client/managers/implementations/ParameterValidatorImpl.ts +1 -1
  196. package/src/client/operations/comments.ts +96 -0
  197. package/src/client/operations/index.ts +12 -0
  198. package/src/client/operations/media.ts +162 -0
  199. package/src/client/operations/pages.ts +71 -0
  200. package/src/client/operations/posts.ts +68 -0
  201. package/src/client/operations/site.ts +106 -0
  202. package/src/client/operations/taxonomies.ts +115 -0
  203. package/src/client/operations/users.ts +72 -0
  204. package/src/config/ServerConfiguration.ts +6 -6
  205. package/src/docs/DocumentationGenerator.ts +3 -3
  206. package/src/performance/MetricsCollector.ts +4 -4
  207. package/src/performance/PerformanceMonitor.ts +1 -1
  208. package/src/security/AISecurityScanner.ts +4 -3
  209. package/src/security/AutomatedRemediation.ts +1 -1
  210. package/src/security/InputValidator.ts +36 -19
  211. package/src/security/SecurityCIPipeline.ts +130 -953
  212. package/src/security/SecurityConfig.ts +1 -1
  213. package/src/security/SecurityConfigManager.ts +1 -1
  214. package/src/security/SecurityGateExecutor.ts +485 -0
  215. package/src/security/SecurityMonitoring.ts +1 -1
  216. package/src/security/SecurityReportGenerator.ts +272 -0
  217. package/src/security/SecurityReviewer.ts +1 -1
  218. package/src/security/SecurityTypes.ts +199 -0
  219. package/src/security/index.ts +6 -1
  220. package/src/server/ConnectionTester.ts +4 -4
  221. package/src/server/ToolRegistry.ts +6 -6
  222. package/src/tools/BaseToolManager.ts +2 -2
  223. package/src/tools/auth.ts +3 -3
  224. package/src/tools/cache.ts +3 -3
  225. package/src/tools/comments.ts +3 -3
  226. package/src/tools/media.ts +3 -3
  227. package/src/tools/pages.ts +3 -3
  228. package/src/tools/performance/PerformanceHelpers.ts +330 -0
  229. package/src/tools/performance/PerformanceTools.ts +854 -0
  230. package/src/tools/performance/index.ts +8 -0
  231. package/src/tools/performance.ts +12 -1073
  232. package/src/tools/posts.ts +1 -1
  233. package/src/tools/seo/analyzers/ContentAnalyzer.ts +21 -7
  234. package/src/tools/seo/auditors/SiteAuditor.ts +18 -7
  235. package/src/tools/seo/generators/MetaGenerator.ts +33 -12
  236. package/src/tools/seo/generators/SchemaGenerator.ts +3 -3
  237. package/src/tools/seo/optimizers/InternalLinkingSuggester.ts +4 -4
  238. package/src/tools/site.ts +3 -3
  239. package/src/tools/taxonomies.ts +3 -3
  240. package/src/tools/users.ts +4 -4
  241. package/src/utils/CircuitBreaker.ts +572 -0
  242. package/src/utils/debug.ts +3 -3
  243. package/src/utils/error.ts +1 -1
  244. package/src/utils/index.ts +3 -0
  245. package/src/utils/logger.ts +1 -1
  246. package/src/utils/toolWrapper.ts +2 -2
  247. package/docs/BRANCH_PROTECTION.md +0 -0
@@ -24,16 +24,16 @@ export type {
24
24
  ComposedManager,
25
25
  ManagerFactory,
26
26
  ManagerCompositionConfig,
27
- } from "../interfaces/ManagerInterfaces.js";
27
+ } from "@/client/managers/interfaces/ManagerInterfaces.js";
28
28
 
29
29
  // Implementations
30
- export { ConfigurationProviderImpl } from "../implementations/ConfigurationProviderImpl.js";
31
- export { ErrorHandlerImpl } from "../implementations/ErrorHandlerImpl.js";
32
- export { ParameterValidatorImpl } from "../implementations/ParameterValidatorImpl.js";
30
+ export { ConfigurationProviderImpl } from "@/client/managers/implementations/ConfigurationProviderImpl.js";
31
+ export { ErrorHandlerImpl } from "@/client/managers/implementations/ErrorHandlerImpl.js";
32
+ export { ParameterValidatorImpl } from "@/client/managers/implementations/ParameterValidatorImpl.js";
33
33
 
34
34
  // Composed Managers
35
- export { ComposedAuthenticationManager } from "../ComposedAuthenticationManager.js";
36
- export { ComposedRequestManager } from "../ComposedRequestManager.js";
35
+ export { ComposedAuthenticationManager } from "@/client/managers/ComposedAuthenticationManager.js";
36
+ export { ComposedRequestManager } from "@/client/managers/ComposedRequestManager.js";
37
37
 
38
38
  // Factory and Client
39
39
  export {
@@ -41,7 +41,7 @@ export {
41
41
  ComposedWordPressClient,
42
42
  createComposedWordPressClient,
43
43
  type ComposedWordPressClientDependencies,
44
- } from "../ComposedManagerFactory.js";
44
+ } from "@/client/managers/ComposedManagerFactory.js";
45
45
 
46
46
  // Migration utilities (for gradual migration from inheritance to composition)
47
47
  export { MigrationAdapter } from "./MigrationAdapter.js";
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  import type { WordPressClientConfig } from "@/types/client.js";
7
- import type { ConfigurationProvider } from "../interfaces/ManagerInterfaces.js";
7
+ import type { ConfigurationProvider } from "@/client/managers/interfaces/ManagerInterfaces.js";
8
8
 
9
9
  export class ConfigurationProviderImpl implements ConfigurationProvider {
10
10
  public readonly config: WordPressClientConfig;
@@ -6,7 +6,7 @@
6
6
  import { WordPressAPIError } from "@/types/client.js";
7
7
  import { debug, logError } from "@/utils/debug.js";
8
8
  import { getErrorMessage } from "@/utils/error.js";
9
- import type { ErrorHandler, ConfigurationProvider } from "../interfaces/ManagerInterfaces.js";
9
+ import type { ErrorHandler, ConfigurationProvider } from "@/client/managers/interfaces/ManagerInterfaces.js";
10
10
 
11
11
  export class ErrorHandlerImpl implements ErrorHandler {
12
12
  constructor(private configProvider: ConfigurationProvider) {}
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  import { WordPressAPIError } from "@/types/client.js";
7
- import type { ParameterValidator } from "../interfaces/ManagerInterfaces.js";
7
+ import type { ParameterValidator } from "@/client/managers/interfaces/ManagerInterfaces.js";
8
8
 
9
9
  export class ParameterValidatorImpl implements ParameterValidator {
10
10
  /**
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Comments Operations Module
3
+ * Handles all comment-related WordPress REST API operations
4
+ */
5
+
6
+ import type {
7
+ WordPressComment,
8
+ CommentQueryParams,
9
+ CreateCommentRequest,
10
+ UpdateCommentRequest,
11
+ } from "@/types/wordpress.js";
12
+
13
+ /**
14
+ * Interface for the base client methods needed by comments operations
15
+ */
16
+ export interface CommentsClientBase {
17
+ get<T>(endpoint: string): Promise<T>;
18
+ post<T>(endpoint: string, data?: unknown): Promise<T>;
19
+ put<T>(endpoint: string, data?: unknown): Promise<T>;
20
+ delete<T>(endpoint: string): Promise<T>;
21
+ }
22
+
23
+ /**
24
+ * Comments operations mixin
25
+ * Provides CRUD operations for WordPress comments
26
+ */
27
+ export class CommentsOperations {
28
+ constructor(private client: CommentsClientBase) {}
29
+
30
+ /**
31
+ * Get a list of comments with optional filtering
32
+ */
33
+ async getComments(params?: CommentQueryParams): Promise<WordPressComment[]> {
34
+ const normalizedParams = params
35
+ ? Object.fromEntries(Object.entries(params).map(([k, v]) => [k, String(v)]))
36
+ : undefined;
37
+ const queryString = normalizedParams ? "?" + new URLSearchParams(normalizedParams).toString() : "";
38
+ return this.client.get<WordPressComment[]>(`comments${queryString}`);
39
+ }
40
+
41
+ /**
42
+ * Get a single comment by ID
43
+ */
44
+ async getComment(id: number, context: "view" | "embed" | "edit" = "view"): Promise<WordPressComment> {
45
+ return this.client.get<WordPressComment>(`comments/${id}?context=${context}`);
46
+ }
47
+
48
+ /**
49
+ * Create a new comment
50
+ */
51
+ async createComment(data: CreateCommentRequest): Promise<WordPressComment> {
52
+ return this.client.post<WordPressComment>("comments", data);
53
+ }
54
+
55
+ /**
56
+ * Update an existing comment
57
+ */
58
+ async updateComment(data: UpdateCommentRequest): Promise<WordPressComment> {
59
+ const { id, ...updateData } = data;
60
+ return this.client.put<WordPressComment>(`comments/${id}`, updateData);
61
+ }
62
+
63
+ /**
64
+ * Delete a comment
65
+ */
66
+ async deleteComment(id: number, force = false): Promise<{ deleted: boolean; previous?: WordPressComment }> {
67
+ return this.client.delete(`comments/${id}?force=${force}`);
68
+ }
69
+
70
+ /**
71
+ * Approve a comment
72
+ */
73
+ async approveComment(id: number): Promise<WordPressComment> {
74
+ return this.client.put<WordPressComment>(`comments/${id}`, {
75
+ status: "approved",
76
+ });
77
+ }
78
+
79
+ /**
80
+ * Reject/unapprove a comment
81
+ */
82
+ async rejectComment(id: number): Promise<WordPressComment> {
83
+ return this.client.put<WordPressComment>(`comments/${id}`, {
84
+ status: "unapproved",
85
+ });
86
+ }
87
+
88
+ /**
89
+ * Mark a comment as spam
90
+ */
91
+ async spamComment(id: number): Promise<WordPressComment> {
92
+ return this.client.put<WordPressComment>(`comments/${id}`, {
93
+ status: "spam",
94
+ });
95
+ }
96
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Operations Module Index
3
+ * Re-exports all domain-specific operations for the WordPress API client
4
+ */
5
+
6
+ export { PostsOperations, type PostsClientBase } from "./posts.js";
7
+ export { PagesOperations, type PagesClientBase } from "./pages.js";
8
+ export { MediaOperations, type MediaClientBase } from "./media.js";
9
+ export { UsersOperations, type UsersClientBase } from "./users.js";
10
+ export { CommentsOperations, type CommentsClientBase } from "./comments.js";
11
+ export { TaxonomiesOperations, type TaxonomiesClientBase } from "./taxonomies.js";
12
+ export { SiteOperations, type SiteClientBase } from "./site.js";
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Media Operations Module
3
+ * Handles all media-related WordPress REST API operations
4
+ */
5
+
6
+ import FormData from "form-data";
7
+ import { promises as fsPromises } from "fs";
8
+ import * as path from "path";
9
+ import type { WordPressMedia, MediaQueryParams, UploadMediaRequest, UpdateMediaRequest } from "@/types/wordpress.js";
10
+ import type { RequestOptions } from "@/types/client.js";
11
+ import { debug } from "@/utils/debug.js";
12
+
13
+ /**
14
+ * Interface for the base client methods needed by media operations
15
+ */
16
+ export interface MediaClientBase {
17
+ get<T>(endpoint: string): Promise<T>;
18
+ post<T>(endpoint: string, data?: unknown, options?: RequestOptions): Promise<T>;
19
+ put<T>(endpoint: string, data?: unknown): Promise<T>;
20
+ delete<T>(endpoint: string): Promise<T>;
21
+ }
22
+
23
+ /**
24
+ * Media operations mixin
25
+ * Provides CRUD operations for WordPress media
26
+ */
27
+ export class MediaOperations {
28
+ constructor(private client: MediaClientBase) {}
29
+
30
+ /**
31
+ * Get a list of media items with optional filtering
32
+ */
33
+ async getMedia(params?: MediaQueryParams): Promise<WordPressMedia[]> {
34
+ const normalizedParams = params
35
+ ? Object.fromEntries(Object.entries(params).map(([k, v]) => [k, String(v)]))
36
+ : undefined;
37
+ const queryString = normalizedParams ? "?" + new URLSearchParams(normalizedParams).toString() : "";
38
+ return this.client.get<WordPressMedia[]>(`media${queryString}`);
39
+ }
40
+
41
+ /**
42
+ * Get a single media item by ID
43
+ */
44
+ async getMediaItem(id: number, context: "view" | "embed" | "edit" = "view"): Promise<WordPressMedia> {
45
+ return this.client.get<WordPressMedia>(`media/${id}?context=${context}`);
46
+ }
47
+
48
+ /**
49
+ * Upload media from a file path
50
+ */
51
+ async uploadMedia(data: UploadMediaRequest): Promise<WordPressMedia> {
52
+ // Use file handle to avoid TOCTOU race condition
53
+ let fileHandle;
54
+ try {
55
+ fileHandle = await fsPromises.open(data.file_path, "r");
56
+ } catch {
57
+ throw new Error(`File not found: ${data.file_path}`);
58
+ }
59
+
60
+ try {
61
+ const stats = await fileHandle.stat();
62
+ const filename = data.title || path.basename(data.file_path);
63
+
64
+ // Check if file is too large (WordPress default is 2MB for most installs)
65
+ const maxSize = 10 * 1024 * 1024; // 10MB reasonable limit
66
+ if (stats.size > maxSize) {
67
+ throw new Error(
68
+ `File too large: ${(stats.size / 1024 / 1024).toFixed(2)}MB. Maximum allowed: ${maxSize / 1024 / 1024}MB`,
69
+ );
70
+ }
71
+
72
+ const fileBuffer = await fileHandle.readFile();
73
+
74
+ debug.log(`Uploading file: ${filename} (${(stats.size / 1024).toFixed(2)}KB)`);
75
+
76
+ return this.uploadFile(fileBuffer, filename, this.getMimeType(data.file_path), data);
77
+ } finally {
78
+ await fileHandle.close();
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Upload a file buffer as media
84
+ */
85
+ async uploadFile(
86
+ fileData: Buffer,
87
+ filename: string,
88
+ mimeType: string,
89
+ meta: Partial<UploadMediaRequest> = {},
90
+ options?: RequestOptions,
91
+ ): Promise<WordPressMedia> {
92
+ debug.log(`Uploading file: ${filename} (${fileData.length} bytes)`);
93
+
94
+ // Use FormData but with correct configuration for node-fetch
95
+ const formData = new FormData();
96
+ formData.setMaxListeners(20);
97
+
98
+ // Add file with correct options
99
+ formData.append("file", fileData, {
100
+ filename,
101
+ contentType: mimeType,
102
+ });
103
+
104
+ // Add metadata
105
+ if (meta.title) formData.append("title", meta.title);
106
+ if (meta.alt_text) formData.append("alt_text", meta.alt_text);
107
+ if (meta.caption) formData.append("caption", meta.caption);
108
+ if (meta.description) formData.append("description", meta.description);
109
+ if (meta.post) formData.append("post", meta.post.toString());
110
+
111
+ // Use longer timeout for file uploads
112
+ const uploadTimeout = options?.timeout !== undefined ? options.timeout : 600000; // 10 minutes default
113
+ const uploadOptions: RequestOptions = {
114
+ ...options,
115
+ timeout: uploadTimeout,
116
+ };
117
+
118
+ debug.log(`Upload prepared with FormData, timeout: ${uploadTimeout}ms`);
119
+
120
+ // Use the regular post method which handles FormData correctly
121
+ return this.client.post<WordPressMedia>("media", formData, uploadOptions);
122
+ }
123
+
124
+ /**
125
+ * Update media metadata
126
+ */
127
+ async updateMedia(data: UpdateMediaRequest): Promise<WordPressMedia> {
128
+ const { id, ...updateData } = data;
129
+ return this.client.put<WordPressMedia>(`media/${id}`, updateData);
130
+ }
131
+
132
+ /**
133
+ * Delete a media item
134
+ */
135
+ async deleteMedia(id: number, force = false): Promise<{ deleted: boolean; previous?: WordPressMedia }> {
136
+ return this.client.delete(`media/${id}?force=${force}`);
137
+ }
138
+
139
+ /**
140
+ * Get MIME type from file extension
141
+ */
142
+ private getMimeType(filePath: string): string {
143
+ const ext = path.extname(filePath).toLowerCase();
144
+ const mimeTypes: Record<string, string> = {
145
+ ".jpg": "image/jpeg",
146
+ ".jpeg": "image/jpeg",
147
+ ".png": "image/png",
148
+ ".gif": "image/gif",
149
+ ".webp": "image/webp",
150
+ ".svg": "image/svg+xml",
151
+ ".pdf": "application/pdf",
152
+ ".doc": "application/msword",
153
+ ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
154
+ ".txt": "text/plain",
155
+ ".mp4": "video/mp4",
156
+ ".mp3": "audio/mpeg",
157
+ ".wav": "audio/wav",
158
+ };
159
+
160
+ return mimeTypes[ext] || "application/octet-stream";
161
+ }
162
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Pages Operations Module
3
+ * Handles all page-related WordPress REST API operations
4
+ */
5
+
6
+ import type { WordPressPage, PostQueryParams, CreatePageRequest, UpdatePageRequest } from "@/types/wordpress.js";
7
+
8
+ /**
9
+ * Interface for the base client methods needed by pages operations
10
+ */
11
+ export interface PagesClientBase {
12
+ get<T>(endpoint: string): Promise<T>;
13
+ post<T>(endpoint: string, data?: unknown): Promise<T>;
14
+ put<T>(endpoint: string, data?: unknown): Promise<T>;
15
+ delete<T>(endpoint: string): Promise<T>;
16
+ }
17
+
18
+ /**
19
+ * Pages operations mixin
20
+ * Provides CRUD operations for WordPress pages
21
+ */
22
+ export class PagesOperations {
23
+ constructor(private client: PagesClientBase) {}
24
+
25
+ /**
26
+ * Get a list of pages with optional filtering
27
+ */
28
+ async getPages(params?: PostQueryParams): Promise<WordPressPage[]> {
29
+ const normalizedParams = params
30
+ ? Object.fromEntries(Object.entries(params).map(([k, v]) => [k, String(v)]))
31
+ : undefined;
32
+ const queryString = normalizedParams ? "?" + new URLSearchParams(normalizedParams).toString() : "";
33
+ return this.client.get<WordPressPage[]>(`pages${queryString}`);
34
+ }
35
+
36
+ /**
37
+ * Get a single page by ID
38
+ */
39
+ async getPage(id: number, context: "view" | "embed" | "edit" = "view"): Promise<WordPressPage> {
40
+ return this.client.get<WordPressPage>(`pages/${id}?context=${context}`);
41
+ }
42
+
43
+ /**
44
+ * Create a new page
45
+ */
46
+ async createPage(data: CreatePageRequest): Promise<WordPressPage> {
47
+ return this.client.post<WordPressPage>("pages", data);
48
+ }
49
+
50
+ /**
51
+ * Update an existing page
52
+ */
53
+ async updatePage(data: UpdatePageRequest): Promise<WordPressPage> {
54
+ const { id, ...updateData } = data;
55
+ return this.client.put<WordPressPage>(`pages/${id}`, updateData);
56
+ }
57
+
58
+ /**
59
+ * Delete a page
60
+ */
61
+ async deletePage(id: number, force = false): Promise<{ deleted: boolean; previous?: WordPressPage }> {
62
+ return this.client.delete(`pages/${id}?force=${force}`);
63
+ }
64
+
65
+ /**
66
+ * Get page revisions
67
+ */
68
+ async getPageRevisions(id: number): Promise<WordPressPage[]> {
69
+ return this.client.get<WordPressPage[]>(`pages/${id}/revisions`);
70
+ }
71
+ }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Posts Operations Module
3
+ * Handles all post-related WordPress REST API operations
4
+ */
5
+
6
+ import type { WordPressPost, PostQueryParams, CreatePostRequest, UpdatePostRequest } from "@/types/wordpress.js";
7
+
8
+ /**
9
+ * Interface for the base client methods needed by posts operations
10
+ */
11
+ export interface PostsClientBase {
12
+ get<T>(endpoint: string): Promise<T>;
13
+ post<T>(endpoint: string, data?: unknown): Promise<T>;
14
+ put<T>(endpoint: string, data?: unknown): Promise<T>;
15
+ delete<T>(endpoint: string): Promise<T>;
16
+ }
17
+
18
+ /**
19
+ * Posts operations mixin
20
+ * Provides CRUD operations for WordPress posts
21
+ */
22
+ export class PostsOperations {
23
+ constructor(private client: PostsClientBase) {}
24
+
25
+ /**
26
+ * Get a list of posts with optional filtering
27
+ */
28
+ async getPosts(params?: PostQueryParams): Promise<WordPressPost[]> {
29
+ const queryString = params ? "?" + new URLSearchParams(params as Record<string, string>).toString() : "";
30
+ return this.client.get<WordPressPost[]>(`posts${queryString}`);
31
+ }
32
+
33
+ /**
34
+ * Get a single post by ID
35
+ */
36
+ async getPost(id: number, context: "view" | "embed" | "edit" = "view"): Promise<WordPressPost> {
37
+ return this.client.get<WordPressPost>(`posts/${id}?context=${context}`);
38
+ }
39
+
40
+ /**
41
+ * Create a new post
42
+ */
43
+ async createPost(data: CreatePostRequest): Promise<WordPressPost> {
44
+ return this.client.post<WordPressPost>("posts", data);
45
+ }
46
+
47
+ /**
48
+ * Update an existing post
49
+ */
50
+ async updatePost(data: UpdatePostRequest): Promise<WordPressPost> {
51
+ const { id, ...updateData } = data;
52
+ return this.client.put<WordPressPost>(`posts/${id}`, updateData);
53
+ }
54
+
55
+ /**
56
+ * Delete a post
57
+ */
58
+ async deletePost(id: number, force = false): Promise<{ deleted: boolean; previous?: WordPressPost }> {
59
+ return this.client.delete(`posts/${id}?force=${force}`);
60
+ }
61
+
62
+ /**
63
+ * Get post revisions
64
+ */
65
+ async getPostRevisions(id: number): Promise<WordPressPost[]> {
66
+ return this.client.get<WordPressPost[]>(`posts/${id}/revisions`);
67
+ }
68
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Site Operations Module
3
+ * Handles site management, settings, and application passwords
4
+ */
5
+
6
+ import type {
7
+ WordPressSiteSettings,
8
+ WordPressSiteInfo,
9
+ WordPressApplicationPassword,
10
+ WordPressSearchResult,
11
+ } from "@/types/wordpress.js";
12
+
13
+ /**
14
+ * Interface for the base client methods needed by site operations
15
+ */
16
+ export interface SiteClientBase {
17
+ get<T>(endpoint: string): Promise<T>;
18
+ post<T>(endpoint: string, data?: unknown): Promise<T>;
19
+ delete<T>(endpoint: string): Promise<T>;
20
+ }
21
+
22
+ /**
23
+ * Site operations mixin
24
+ * Provides operations for WordPress site settings, info, and application passwords
25
+ */
26
+ export class SiteOperations {
27
+ constructor(private client: SiteClientBase) {}
28
+
29
+ /**
30
+ * Get site settings
31
+ */
32
+ async getSiteSettings(): Promise<WordPressSiteSettings> {
33
+ return this.client.get<WordPressSiteSettings>("settings");
34
+ }
35
+
36
+ /**
37
+ * Update site settings
38
+ */
39
+ async updateSiteSettings(settings: Partial<WordPressSiteSettings>): Promise<WordPressSiteSettings> {
40
+ return this.client.post<WordPressSiteSettings>("settings", settings);
41
+ }
42
+
43
+ /**
44
+ * Get site info (root endpoint)
45
+ */
46
+ async getSiteInfo(): Promise<WordPressSiteInfo> {
47
+ return this.client.get("");
48
+ }
49
+
50
+ /**
51
+ * Get application passwords for a user
52
+ */
53
+ async getApplicationPasswords(userId: number | "me" = "me"): Promise<WordPressApplicationPassword[]> {
54
+ return this.client.get<WordPressApplicationPassword[]>(`users/${userId}/application-passwords`);
55
+ }
56
+
57
+ /**
58
+ * Create an application password for a user
59
+ */
60
+ async createApplicationPassword(
61
+ userId: number | "me",
62
+ name: string,
63
+ appId?: string,
64
+ ): Promise<WordPressApplicationPassword> {
65
+ const data: Record<string, unknown> = { name };
66
+ if (appId) data.app_id = appId;
67
+ return this.client.post<WordPressApplicationPassword>(`users/${userId}/application-passwords`, data);
68
+ }
69
+
70
+ /**
71
+ * Delete an application password
72
+ */
73
+ async deleteApplicationPassword(userId: number | "me", uuid: string): Promise<{ deleted: boolean }> {
74
+ return this.client.delete(`users/${userId}/application-passwords/${uuid}`);
75
+ }
76
+
77
+ /**
78
+ * Search across WordPress content
79
+ */
80
+ async search(query: string, types?: string[], subtype?: string): Promise<WordPressSearchResult[]> {
81
+ const params = new URLSearchParams({ search: query });
82
+ if (types) params.append("type", types.join(","));
83
+ if (subtype) params.append("subtype", subtype);
84
+
85
+ return this.client.get<WordPressSearchResult[]>(`search?${params.toString()}`);
86
+ }
87
+
88
+ /**
89
+ * Ping the site to check availability
90
+ */
91
+ async ping(): Promise<boolean> {
92
+ try {
93
+ await this.client.get("");
94
+ return true;
95
+ } catch {
96
+ return false;
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Get server info
102
+ */
103
+ async getServerInfo(): Promise<Record<string, unknown>> {
104
+ return this.client.get("");
105
+ }
106
+ }