mcp-wordpress 2.6.3 → 2.7.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 (333) hide show
  1. package/README.md +1 -1
  2. package/dist/cache/CacheInvalidation.d.ts +25 -6
  3. package/dist/cache/CacheInvalidation.d.ts.map +1 -1
  4. package/dist/cache/CacheInvalidation.js +168 -16
  5. package/dist/cache/CacheInvalidation.js.map +1 -1
  6. package/dist/cache/HttpCacheWrapper.d.ts.map +1 -1
  7. package/dist/cache/HttpCacheWrapper.js +3 -4
  8. package/dist/cache/HttpCacheWrapper.js.map +1 -1
  9. package/dist/cache/SEOCacheManager.d.ts +150 -0
  10. package/dist/cache/SEOCacheManager.d.ts.map +1 -0
  11. package/dist/cache/SEOCacheManager.js +275 -0
  12. package/dist/cache/SEOCacheManager.js.map +1 -0
  13. package/dist/client/SEOWordPressClient.d.ts +164 -0
  14. package/dist/client/SEOWordPressClient.d.ts.map +1 -0
  15. package/dist/client/SEOWordPressClient.js +674 -0
  16. package/dist/client/SEOWordPressClient.js.map +1 -0
  17. package/dist/client/api.d.ts.map +1 -1
  18. package/dist/client/api.js +50 -20
  19. package/dist/client/api.js.map +1 -1
  20. package/dist/client/auth.js +19 -19
  21. package/dist/client/auth.js.map +1 -1
  22. package/dist/client/index.d.ts +11 -0
  23. package/dist/client/index.d.ts.map +1 -0
  24. package/dist/client/index.js +14 -0
  25. package/dist/client/index.js.map +1 -0
  26. package/dist/client/managers/AuthManager.d.ts +39 -0
  27. package/dist/client/managers/AuthManager.d.ts.map +1 -0
  28. package/dist/client/managers/AuthManager.js +142 -0
  29. package/dist/client/managers/AuthManager.js.map +1 -0
  30. package/dist/client/managers/AuthenticationManager.d.ts.map +1 -1
  31. package/dist/client/managers/AuthenticationManager.js +10 -9
  32. package/dist/client/managers/AuthenticationManager.js.map +1 -1
  33. package/dist/client/managers/BaseManager.d.ts.map +1 -1
  34. package/dist/client/managers/BaseManager.js +12 -0
  35. package/dist/client/managers/BaseManager.js.map +1 -1
  36. package/dist/client/managers/ComposedAuthenticationManager.d.ts +94 -0
  37. package/dist/client/managers/ComposedAuthenticationManager.d.ts.map +1 -0
  38. package/dist/client/managers/ComposedAuthenticationManager.js +340 -0
  39. package/dist/client/managers/ComposedAuthenticationManager.js.map +1 -0
  40. package/dist/client/managers/ComposedManagerFactory.d.ts +104 -0
  41. package/dist/client/managers/ComposedManagerFactory.d.ts.map +1 -0
  42. package/dist/client/managers/ComposedManagerFactory.js +180 -0
  43. package/dist/client/managers/ComposedManagerFactory.js.map +1 -0
  44. package/dist/client/managers/ComposedRequestManager.d.ts +82 -0
  45. package/dist/client/managers/ComposedRequestManager.d.ts.map +1 -0
  46. package/dist/client/managers/ComposedRequestManager.js +260 -0
  47. package/dist/client/managers/ComposedRequestManager.js.map +1 -0
  48. package/dist/client/managers/JWTAuthImplementation.d.ts +86 -0
  49. package/dist/client/managers/JWTAuthImplementation.d.ts.map +1 -0
  50. package/dist/client/managers/JWTAuthImplementation.js +240 -0
  51. package/dist/client/managers/JWTAuthImplementation.js.map +1 -0
  52. package/dist/client/managers/ManagersIndex.d.ts +6 -0
  53. package/dist/client/managers/ManagersIndex.d.ts.map +1 -0
  54. package/dist/client/managers/ManagersIndex.js +6 -0
  55. package/dist/client/managers/ManagersIndex.js.map +1 -0
  56. package/dist/client/managers/RequestManager.d.ts.map +1 -1
  57. package/dist/client/managers/RequestManager.js +5 -3
  58. package/dist/client/managers/RequestManager.js.map +1 -1
  59. package/dist/client/managers/composed/MigrationAdapter.d.ts +80 -0
  60. package/dist/client/managers/composed/MigrationAdapter.d.ts.map +1 -0
  61. package/dist/client/managers/composed/MigrationAdapter.js +214 -0
  62. package/dist/client/managers/composed/MigrationAdapter.js.map +1 -0
  63. package/dist/client/managers/composed/index.d.ts +23 -0
  64. package/dist/client/managers/composed/index.d.ts.map +1 -0
  65. package/dist/client/managers/composed/index.js +26 -0
  66. package/dist/client/managers/composed/index.js.map +1 -0
  67. package/dist/client/managers/implementations/ConfigurationProviderImpl.d.ts +27 -0
  68. package/dist/client/managers/implementations/ConfigurationProviderImpl.d.ts.map +1 -0
  69. package/dist/client/managers/implementations/ConfigurationProviderImpl.js +41 -0
  70. package/dist/client/managers/implementations/ConfigurationProviderImpl.js.map +1 -0
  71. package/dist/client/managers/implementations/ErrorHandlerImpl.d.ts +31 -0
  72. package/dist/client/managers/implementations/ErrorHandlerImpl.d.ts.map +1 -0
  73. package/dist/client/managers/implementations/ErrorHandlerImpl.js +73 -0
  74. package/dist/client/managers/implementations/ErrorHandlerImpl.js.map +1 -0
  75. package/dist/client/managers/implementations/ParameterValidatorImpl.d.ts +47 -0
  76. package/dist/client/managers/implementations/ParameterValidatorImpl.d.ts.map +1 -0
  77. package/dist/client/managers/implementations/ParameterValidatorImpl.js +141 -0
  78. package/dist/client/managers/implementations/ParameterValidatorImpl.js.map +1 -0
  79. package/dist/client/managers/interfaces/ManagerInterfaces.d.ts +147 -0
  80. package/dist/client/managers/interfaces/ManagerInterfaces.d.ts.map +1 -0
  81. package/dist/client/managers/interfaces/ManagerInterfaces.js +6 -0
  82. package/dist/client/managers/interfaces/ManagerInterfaces.js.map +1 -0
  83. package/dist/config/Config.d.ts +30 -0
  84. package/dist/config/Config.d.ts.map +1 -1
  85. package/dist/config/Config.js +30 -0
  86. package/dist/config/Config.js.map +1 -1
  87. package/dist/config/ConfigurationSchema.d.ts +75 -198
  88. package/dist/config/ConfigurationSchema.d.ts.map +1 -1
  89. package/dist/config/ConfigurationSchema.js +17 -17
  90. package/dist/config/ConfigurationSchema.js.map +1 -1
  91. package/dist/config/ServerConfiguration.d.ts +2 -2
  92. package/dist/config/ServerConfiguration.d.ts.map +1 -1
  93. package/dist/config/ServerConfiguration.js +15 -13
  94. package/dist/config/ServerConfiguration.js.map +1 -1
  95. package/dist/config/index.d.ts +8 -0
  96. package/dist/config/index.d.ts.map +1 -0
  97. package/dist/config/index.js +11 -0
  98. package/dist/config/index.js.map +1 -0
  99. package/dist/docs/DocumentationGenerator.js +2 -2
  100. package/dist/docs/DocumentationGenerator.js.map +1 -1
  101. package/dist/dxt-entry.js +3 -3
  102. package/dist/dxt-entry.js.map +1 -1
  103. package/dist/index.d.ts +1 -0
  104. package/dist/index.d.ts.map +1 -1
  105. package/dist/index.js +38 -37
  106. package/dist/index.js.map +1 -1
  107. package/dist/performance/MetricsCollector.d.ts.map +1 -1
  108. package/dist/performance/MetricsCollector.js +5 -4
  109. package/dist/performance/MetricsCollector.js.map +1 -1
  110. package/dist/security/AISecurityScanner.js +7 -7
  111. package/dist/security/AISecurityScanner.js.map +1 -1
  112. package/dist/security/AutomatedRemediation.d.ts.map +1 -1
  113. package/dist/security/AutomatedRemediation.js +11 -11
  114. package/dist/security/AutomatedRemediation.js.map +1 -1
  115. package/dist/security/InputValidator.d.ts +50 -126
  116. package/dist/security/InputValidator.d.ts.map +1 -1
  117. package/dist/security/InputValidator.js +9 -9
  118. package/dist/security/InputValidator.js.map +1 -1
  119. package/dist/security/SecurityCIPipeline.d.ts +47 -5
  120. package/dist/security/SecurityCIPipeline.d.ts.map +1 -1
  121. package/dist/security/SecurityCIPipeline.js +390 -49
  122. package/dist/security/SecurityCIPipeline.js.map +1 -1
  123. package/dist/security/SecurityConfigManager.js +10 -10
  124. package/dist/security/SecurityConfigManager.js.map +1 -1
  125. package/dist/security/SecurityMonitoring.js +4 -4
  126. package/dist/security/SecurityMonitoring.js.map +1 -1
  127. package/dist/security/SecurityReviewer.d.ts.map +1 -1
  128. package/dist/security/SecurityReviewer.js +13 -6
  129. package/dist/security/SecurityReviewer.js.map +1 -1
  130. package/dist/security/index.js +3 -3
  131. package/dist/security/index.js.map +1 -1
  132. package/dist/server/ConnectionTester.js +5 -5
  133. package/dist/server/ConnectionTester.js.map +1 -1
  134. package/dist/server/ToolRegistry.d.ts +2 -2
  135. package/dist/server/ToolRegistry.d.ts.map +1 -1
  136. package/dist/server/ToolRegistry.js +7 -6
  137. package/dist/server/ToolRegistry.js.map +1 -1
  138. package/dist/server/index.d.ts +7 -0
  139. package/dist/server/index.d.ts.map +1 -0
  140. package/dist/server/index.js +9 -0
  141. package/dist/server/index.js.map +1 -0
  142. package/dist/tools/BaseToolManager.d.ts.map +1 -1
  143. package/dist/tools/BaseToolManager.js +11 -11
  144. package/dist/tools/BaseToolManager.js.map +1 -1
  145. package/dist/tools/auth.d.ts.map +1 -1
  146. package/dist/tools/auth.js +7 -7
  147. package/dist/tools/auth.js.map +1 -1
  148. package/dist/tools/comments.d.ts.map +1 -1
  149. package/dist/tools/comments.js +14 -14
  150. package/dist/tools/comments.js.map +1 -1
  151. package/dist/tools/index.d.ts +1 -0
  152. package/dist/tools/index.d.ts.map +1 -1
  153. package/dist/tools/index.js +1 -0
  154. package/dist/tools/index.js.map +1 -1
  155. package/dist/tools/media.d.ts.map +1 -1
  156. package/dist/tools/media.js +14 -11
  157. package/dist/tools/media.js.map +1 -1
  158. package/dist/tools/pages.d.ts.map +1 -1
  159. package/dist/tools/pages.js +12 -12
  160. package/dist/tools/pages.js.map +1 -1
  161. package/dist/tools/performance.d.ts.map +1 -1
  162. package/dist/tools/performance.js +13 -11
  163. package/dist/tools/performance.js.map +1 -1
  164. package/dist/tools/posts/PostHandlers.d.ts.map +1 -1
  165. package/dist/tools/posts/PostHandlers.js +16 -16
  166. package/dist/tools/posts/PostHandlers.js.map +1 -1
  167. package/dist/tools/posts/PostToolDefinitions.d.ts.map +1 -1
  168. package/dist/tools/posts/index.d.ts.map +1 -1
  169. package/dist/tools/seo/BulkOperations.d.ts +113 -0
  170. package/dist/tools/seo/BulkOperations.d.ts.map +1 -0
  171. package/dist/tools/seo/BulkOperations.js +398 -0
  172. package/dist/tools/seo/BulkOperations.js.map +1 -0
  173. package/dist/tools/seo/SEOHandlers.d.ts +55 -0
  174. package/dist/tools/seo/SEOHandlers.d.ts.map +1 -0
  175. package/dist/tools/seo/SEOHandlers.js +255 -0
  176. package/dist/tools/seo/SEOHandlers.js.map +1 -0
  177. package/dist/tools/seo/SEOToolDefinitions.d.ts +59 -0
  178. package/dist/tools/seo/SEOToolDefinitions.d.ts.map +1 -0
  179. package/dist/tools/seo/SEOToolDefinitions.js +385 -0
  180. package/dist/tools/seo/SEOToolDefinitions.js.map +1 -0
  181. package/dist/tools/seo/SEOTools.d.ts +203 -0
  182. package/dist/tools/seo/SEOTools.d.ts.map +1 -0
  183. package/dist/tools/seo/SEOTools.js +708 -0
  184. package/dist/tools/seo/SEOTools.js.map +1 -0
  185. package/dist/tools/seo/analyzers/ContentAnalyzer.d.ts +94 -0
  186. package/dist/tools/seo/analyzers/ContentAnalyzer.d.ts.map +1 -0
  187. package/dist/tools/seo/analyzers/ContentAnalyzer.js +402 -0
  188. package/dist/tools/seo/analyzers/ContentAnalyzer.js.map +1 -0
  189. package/dist/tools/seo/auditors/SiteAuditor.d.ts +121 -0
  190. package/dist/tools/seo/auditors/SiteAuditor.d.ts.map +1 -0
  191. package/dist/tools/seo/auditors/SiteAuditor.js +600 -0
  192. package/dist/tools/seo/auditors/SiteAuditor.js.map +1 -0
  193. package/dist/tools/seo/generators/MetaGenerator.d.ts +128 -0
  194. package/dist/tools/seo/generators/MetaGenerator.d.ts.map +1 -0
  195. package/dist/tools/seo/generators/MetaGenerator.js +547 -0
  196. package/dist/tools/seo/generators/MetaGenerator.js.map +1 -0
  197. package/dist/tools/seo/generators/SchemaGenerator.d.ts +204 -0
  198. package/dist/tools/seo/generators/SchemaGenerator.d.ts.map +1 -0
  199. package/dist/tools/seo/generators/SchemaGenerator.js +670 -0
  200. package/dist/tools/seo/generators/SchemaGenerator.js.map +1 -0
  201. package/dist/tools/seo/index.d.ts +17 -0
  202. package/dist/tools/seo/index.d.ts.map +1 -0
  203. package/dist/tools/seo/index.js +18 -0
  204. package/dist/tools/seo/index.js.map +1 -0
  205. package/dist/tools/seo/optimizers/InternalLinkingSuggester.d.ts +186 -0
  206. package/dist/tools/seo/optimizers/InternalLinkingSuggester.d.ts.map +1 -0
  207. package/dist/tools/seo/optimizers/InternalLinkingSuggester.js +683 -0
  208. package/dist/tools/seo/optimizers/InternalLinkingSuggester.js.map +1 -0
  209. package/dist/tools/site.d.ts.map +1 -1
  210. package/dist/tools/site.js +12 -12
  211. package/dist/tools/site.js.map +1 -1
  212. package/dist/tools/taxonomies.d.ts.map +1 -1
  213. package/dist/tools/taxonomies.js +20 -20
  214. package/dist/tools/taxonomies.js.map +1 -1
  215. package/dist/tools/users.d.ts.map +1 -1
  216. package/dist/tools/users.js +12 -12
  217. package/dist/tools/users.js.map +1 -1
  218. package/dist/types/client.d.ts +8 -6
  219. package/dist/types/client.d.ts.map +1 -1
  220. package/dist/types/client.js.map +1 -1
  221. package/dist/types/seo.d.ts +473 -0
  222. package/dist/types/seo.d.ts.map +1 -0
  223. package/dist/types/seo.js +94 -0
  224. package/dist/types/seo.js.map +1 -0
  225. package/dist/utils/enhancedError.js +1 -1
  226. package/dist/utils/enhancedError.js.map +1 -1
  227. package/dist/utils/error.d.ts.map +1 -1
  228. package/dist/utils/error.js +0 -1
  229. package/dist/utils/error.js.map +1 -1
  230. package/dist/utils/index.d.ts +12 -0
  231. package/dist/utils/index.d.ts.map +1 -0
  232. package/dist/utils/index.js +18 -0
  233. package/dist/utils/index.js.map +1 -0
  234. package/dist/utils/logger.js +3 -3
  235. package/dist/utils/logger.js.map +1 -1
  236. package/dist/utils/toolWrapper.d.ts +2 -2
  237. package/dist/utils/toolWrapper.js +8 -8
  238. package/dist/utils/toolWrapper.js.map +1 -1
  239. package/dist/utils/validation/core.d.ts.map +1 -1
  240. package/dist/utils/validation/core.js.map +1 -1
  241. package/dist/utils/validation/index.d.ts.map +1 -1
  242. package/dist/utils/validation/index.js.map +1 -1
  243. package/dist/utils/validation/network.js +3 -3
  244. package/dist/utils/validation/network.js.map +1 -1
  245. package/dist/utils/validation/rateLimit.js.map +1 -1
  246. package/dist/utils/validation/security.js.map +1 -1
  247. package/dist/utils/validation/wordpress.js.map +1 -1
  248. package/dist/utils/version.d.ts +144 -0
  249. package/dist/utils/version.d.ts.map +1 -0
  250. package/dist/utils/version.js +318 -0
  251. package/dist/utils/version.js.map +1 -0
  252. package/package.json +24 -58
  253. package/src/cache/CacheInvalidation.ts +183 -20
  254. package/src/cache/HttpCacheWrapper.ts +8 -5
  255. package/src/cache/SEOCacheManager.ts +330 -0
  256. package/src/cache/__tests__/CacheInvalidation.test.ts +6 -11
  257. package/src/cache/__tests__/CachedWordPressClient.test.ts +37 -62
  258. package/src/client/SEOWordPressClient.ts +876 -0
  259. package/src/client/api.ts +50 -21
  260. package/src/client/auth.ts +19 -19
  261. package/src/client/index.ts +16 -0
  262. package/src/client/managers/AuthManager.ts +175 -0
  263. package/src/client/managers/AuthenticationManager.ts +16 -14
  264. package/src/client/managers/BaseManager.ts +24 -5
  265. package/src/client/managers/ComposedAuthenticationManager.ts +409 -0
  266. package/src/client/managers/ComposedManagerFactory.ts +231 -0
  267. package/src/client/managers/ComposedRequestManager.ts +336 -0
  268. package/src/client/managers/JWTAuthImplementation.ts +326 -0
  269. package/src/client/managers/ManagersIndex.ts +6 -0
  270. package/src/client/managers/RequestManager.ts +9 -7
  271. package/src/client/managers/composed/MigrationAdapter.ts +263 -0
  272. package/src/client/managers/composed/index.ts +47 -0
  273. package/src/client/managers/implementations/ConfigurationProviderImpl.ts +52 -0
  274. package/src/client/managers/implementations/ErrorHandlerImpl.ts +102 -0
  275. package/src/client/managers/implementations/ParameterValidatorImpl.ts +221 -0
  276. package/src/client/managers/interfaces/ManagerInterfaces.ts +171 -0
  277. package/src/config/Config.ts +63 -0
  278. package/src/config/ConfigurationSchema.ts +17 -17
  279. package/src/config/ServerConfiguration.ts +18 -16
  280. package/src/config/index.ts +13 -0
  281. package/src/docs/DocumentationGenerator.ts +2 -2
  282. package/src/dxt-entry.ts +3 -3
  283. package/src/index.ts +43 -43
  284. package/src/performance/MetricsCollector.ts +15 -11
  285. package/src/security/AISecurityScanner.ts +7 -7
  286. package/src/security/AutomatedRemediation.ts +13 -11
  287. package/src/security/InputValidator.ts +10 -9
  288. package/src/security/SecurityCIPipeline.ts +494 -56
  289. package/src/security/SecurityConfigManager.ts +10 -10
  290. package/src/security/SecurityMonitoring.ts +5 -5
  291. package/src/security/SecurityReviewer.ts +13 -6
  292. package/src/security/index.ts +3 -3
  293. package/src/server/ConnectionTester.ts +5 -5
  294. package/src/server/ToolRegistry.ts +9 -8
  295. package/src/server/index.ts +10 -0
  296. package/src/tools/BaseToolManager.ts +55 -83
  297. package/src/tools/auth.ts +21 -12
  298. package/src/tools/comments.ts +23 -19
  299. package/src/tools/index.ts +1 -0
  300. package/src/tools/media.ts +23 -20
  301. package/src/tools/pages.ts +20 -13
  302. package/src/tools/performance.ts +101 -32
  303. package/src/tools/posts/PostHandlers.ts +23 -23
  304. package/src/tools/posts/PostToolDefinitions.ts +1 -1
  305. package/src/tools/posts/index.ts +2 -2
  306. package/src/tools/seo/BulkOperations.ts +557 -0
  307. package/src/tools/seo/SEOHandlers.ts +296 -0
  308. package/src/tools/seo/SEOToolDefinitions.ts +402 -0
  309. package/src/tools/seo/SEOTools.ts +871 -0
  310. package/src/tools/seo/analyzers/ContentAnalyzer.ts +493 -0
  311. package/src/tools/seo/auditors/SiteAuditor.ts +787 -0
  312. package/src/tools/seo/generators/MetaGenerator.ts +694 -0
  313. package/src/tools/seo/generators/SchemaGenerator.ts +955 -0
  314. package/src/tools/seo/index.ts +47 -0
  315. package/src/tools/seo/optimizers/InternalLinkingSuggester.ts +934 -0
  316. package/src/tools/site.ts +27 -26
  317. package/src/tools/taxonomies.ts +29 -25
  318. package/src/tools/users.ts +20 -13
  319. package/src/types/client.ts +8 -6
  320. package/src/types/seo.ts +546 -0
  321. package/src/utils/enhancedError.ts +1 -1
  322. package/src/utils/error.ts +1 -2
  323. package/src/utils/index.ts +23 -0
  324. package/src/utils/logger.ts +3 -3
  325. package/src/utils/toolWrapper.ts +10 -10
  326. package/src/utils/validation/core.ts +2 -2
  327. package/src/utils/validation/index.ts +2 -2
  328. package/src/utils/validation/network.ts +5 -5
  329. package/src/utils/validation/rateLimit.ts +1 -1
  330. package/src/utils/validation/security.ts +1 -1
  331. package/src/utils/validation/wordpress.ts +1 -1
  332. package/src/utils/version.ts +402 -0
  333. package/src/dxt-entry.cjs +0 -68
@@ -0,0 +1,409 @@
1
+ /**
2
+ * Composed Authentication Manager
3
+ * Uses composition instead of inheritance for better flexibility and testability
4
+ */
5
+
6
+ import type {
7
+ WordPressClientConfig,
8
+ AuthStatus,
9
+ AppPasswordCredentials,
10
+ JwtCredentials,
11
+ BasicCredentials,
12
+ } from "@/types/client.js";
13
+ import { AuthenticationError } from "@/types/client.js";
14
+ import { AUTH_METHODS, type AuthMethod } from "@/types/wordpress.js";
15
+ import { debug } from "@/utils/debug.js";
16
+
17
+ import type {
18
+ ConfigurationProvider,
19
+ ErrorHandler,
20
+ ParameterValidator,
21
+ AuthenticationProvider,
22
+ } from "./interfaces/ManagerInterfaces.js";
23
+
24
+ import { ConfigurationProviderImpl } from "./implementations/ConfigurationProviderImpl.js";
25
+ import { ErrorHandlerImpl } from "./implementations/ErrorHandlerImpl.js";
26
+ import { ParameterValidatorImpl } from "./implementations/ParameterValidatorImpl.js";
27
+
28
+ interface AuthenticationDependencies {
29
+ configProvider: ConfigurationProvider;
30
+ errorHandler: ErrorHandler;
31
+ validator: ParameterValidator;
32
+ }
33
+
34
+ export class ComposedAuthenticationManager implements AuthenticationProvider {
35
+ private isAuth: boolean = false;
36
+ private authToken: string | null = null;
37
+ private tokenExpiry: Date | null = null;
38
+ private lastAuthAttempt: Date | null = null;
39
+ private authMethod: AuthMethod;
40
+
41
+ constructor(private dependencies: AuthenticationDependencies) {
42
+ this.authMethod = this.getAuthMethodFromConfig();
43
+ this.validateAuthConfiguration();
44
+ }
45
+
46
+ /**
47
+ * Factory method to create ComposedAuthenticationManager with default implementations
48
+ */
49
+ static create(clientConfig: WordPressClientConfig): ComposedAuthenticationManager {
50
+ const configProvider = new ConfigurationProviderImpl(clientConfig);
51
+ const errorHandler = new ErrorHandlerImpl(configProvider);
52
+ const validator = new ParameterValidatorImpl();
53
+
54
+ return new ComposedAuthenticationManager({
55
+ configProvider,
56
+ errorHandler,
57
+ validator,
58
+ });
59
+ }
60
+
61
+ /**
62
+ * Authenticate with the configured method
63
+ */
64
+ async authenticate(): Promise<boolean> {
65
+ try {
66
+ this.lastAuthAttempt = new Date();
67
+
68
+ switch (this.authMethod) {
69
+ case "app-password":
70
+ return await this.authenticateAppPassword();
71
+ case "jwt":
72
+ return await this.authenticateJWT();
73
+ case "basic":
74
+ return await this.authenticateBasic();
75
+ case "api-key":
76
+ return await this.authenticateApiKey();
77
+ default:
78
+ throw new AuthenticationError(`Unsupported authentication method: ${this.authMethod}`, this.authMethod);
79
+ }
80
+ } catch (error) {
81
+ this.isAuth = false;
82
+ this.authToken = null;
83
+ this.dependencies.errorHandler.handleError(error, "authentication");
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Check if currently authenticated
89
+ */
90
+ isAuthenticated(): boolean {
91
+ if (!this.isAuth) {
92
+ return false;
93
+ }
94
+
95
+ // Check token expiry for JWT
96
+ if (this.authMethod === "jwt" && this.tokenExpiry) {
97
+ if (new Date() > this.tokenExpiry) {
98
+ this.isAuth = false;
99
+ this.authToken = null;
100
+ return false;
101
+ }
102
+ }
103
+
104
+ return true;
105
+ }
106
+
107
+ /**
108
+ * Get authentication headers for requests
109
+ */
110
+ getAuthHeaders(): Record<string, string> {
111
+ const headers: Record<string, string> = {};
112
+
113
+ switch (this.authMethod) {
114
+ case "app-password":
115
+ case "basic":
116
+ headers.Authorization = this.getBasicAuthHeader();
117
+ break;
118
+ case "jwt":
119
+ if (this.authToken) {
120
+ headers.Authorization = `Bearer ${this.authToken}`;
121
+ }
122
+ break;
123
+ case "api-key":
124
+ const apiKey = this.getApiKeyFromConfig();
125
+ if (apiKey) {
126
+ headers["X-API-Key"] = apiKey;
127
+ }
128
+ break;
129
+ }
130
+
131
+ return headers;
132
+ }
133
+
134
+ /**
135
+ * Handle authentication failure
136
+ */
137
+ async handleAuthFailure(error: unknown): Promise<boolean> {
138
+ debug.log("Handling authentication failure", { error: String(error), method: this.authMethod });
139
+
140
+ this.isAuth = false;
141
+ this.authToken = null;
142
+
143
+ // For JWT, try to refresh token
144
+ if (this.authMethod === "jwt") {
145
+ try {
146
+ return await this.refreshJWTToken();
147
+ } catch (_refreshError) {
148
+ // If refresh fails, try full re-authentication
149
+ return await this.authenticate();
150
+ }
151
+ }
152
+
153
+ // For other methods, try full re-authentication
154
+ return await this.authenticate();
155
+ }
156
+
157
+ /**
158
+ * Get authentication status
159
+ */
160
+ getAuthStatus(): AuthStatus {
161
+ return {
162
+ isAuthenticated: this.isAuthenticated(),
163
+ method: this.authMethod,
164
+ lastAuthAttempt: this.lastAuthAttempt,
165
+ tokenExpiry: this.tokenExpiry,
166
+ };
167
+ }
168
+
169
+ /**
170
+ * App Password authentication
171
+ */
172
+ private async authenticateAppPassword(): Promise<boolean> {
173
+ const credentials = this.getAppPasswordCredentials();
174
+
175
+ // App passwords are stateless - just validate credentials format
176
+ this.dependencies.validator.validateString(credentials.username, "username", { required: true });
177
+ this.dependencies.validator.validateString(credentials.appPassword, "appPassword", { required: true });
178
+
179
+ this.isAuth = true;
180
+ debug.log("App password authentication configured");
181
+ return true;
182
+ }
183
+
184
+ /**
185
+ * JWT authentication
186
+ */
187
+ private async authenticateJWT(): Promise<boolean> {
188
+ const credentials = this.getJWTCredentials();
189
+ const tokenEndpoint = "/jwt-auth/v1/token";
190
+
191
+ try {
192
+ const response = await fetch(`${this.dependencies.configProvider.config.baseUrl}/wp-json${tokenEndpoint}`, {
193
+ method: "POST",
194
+ headers: {
195
+ "Content-Type": "application/json",
196
+ },
197
+ body: JSON.stringify({
198
+ username: credentials.username,
199
+ password: credentials.password,
200
+ }),
201
+ });
202
+
203
+ if (!response.ok) {
204
+ throw new AuthenticationError(`JWT authentication failed: ${response.statusText}`, "jwt");
205
+ }
206
+
207
+ const data = (await response.json()) as { token?: string; expires_in?: number };
208
+
209
+ if (!data.token) {
210
+ throw new AuthenticationError("No token received from JWT authentication", "jwt");
211
+ }
212
+
213
+ this.authToken = data.token;
214
+ this.isAuth = true;
215
+
216
+ // Set token expiry (default to 24 hours if not provided)
217
+ const expiresIn = data.expires_in || 86400; // 24 hours in seconds
218
+ this.tokenExpiry = new Date(Date.now() + expiresIn * 1000);
219
+
220
+ debug.log("JWT authentication successful", {
221
+ expiresIn,
222
+ expiry: this.tokenExpiry.toISOString(),
223
+ });
224
+
225
+ return true;
226
+ } catch (error) {
227
+ throw new AuthenticationError(`JWT authentication failed: ${String(error)}`, "jwt");
228
+ }
229
+ }
230
+
231
+ /**
232
+ * Basic authentication
233
+ */
234
+ private async authenticateBasic(): Promise<boolean> {
235
+ const credentials = this.getBasicCredentials();
236
+
237
+ this.dependencies.validator.validateString(credentials.username, "username", { required: true });
238
+ this.dependencies.validator.validateString(credentials.password, "password", { required: true });
239
+
240
+ this.isAuth = true;
241
+ debug.log("Basic authentication configured");
242
+ return true;
243
+ }
244
+
245
+ /**
246
+ * API Key authentication
247
+ */
248
+ private async authenticateApiKey(): Promise<boolean> {
249
+ const apiKey = this.getApiKeyFromConfig();
250
+
251
+ this.dependencies.validator.validateString(apiKey, "apiKey", { required: true });
252
+
253
+ this.isAuth = true;
254
+ debug.log("API key authentication configured");
255
+ return true;
256
+ }
257
+
258
+ /**
259
+ * Refresh JWT token
260
+ */
261
+ private async refreshJWTToken(): Promise<boolean> {
262
+ if (!this.authToken) {
263
+ throw new AuthenticationError("No token to refresh", "jwt");
264
+ }
265
+
266
+ const refreshEndpoint = "/jwt-auth/v1/token/validate";
267
+
268
+ try {
269
+ const response = await fetch(`${this.dependencies.configProvider.config.baseUrl}/wp-json${refreshEndpoint}`, {
270
+ method: "POST",
271
+ headers: {
272
+ Authorization: `Bearer ${this.authToken}`,
273
+ "Content-Type": "application/json",
274
+ },
275
+ });
276
+
277
+ if (response.ok) {
278
+ // Token is still valid
279
+ debug.log("JWT token validated successfully");
280
+ return true;
281
+ }
282
+
283
+ // Token invalid, need to re-authenticate
284
+ this.authToken = null;
285
+ return await this.authenticateJWT();
286
+ } catch (error) {
287
+ throw new AuthenticationError(`JWT token refresh failed: ${String(error)}`, "jwt");
288
+ }
289
+ }
290
+
291
+ /**
292
+ * Get Basic auth header
293
+ */
294
+ private getBasicAuthHeader(): string {
295
+ let credentials: { username: string; password?: string; appPassword?: string };
296
+
297
+ if (this.authMethod === "app-password") {
298
+ credentials = this.getAppPasswordCredentials();
299
+ const auth = `${credentials.username}:${credentials.appPassword}`;
300
+ return `Basic ${Buffer.from(auth).toString("base64")}`;
301
+ } else {
302
+ credentials = this.getBasicCredentials();
303
+ const auth = `${credentials.username}:${credentials.password}`;
304
+ return `Basic ${Buffer.from(auth).toString("base64")}`;
305
+ }
306
+ }
307
+
308
+ /**
309
+ * Extract auth method from configuration
310
+ */
311
+ private getAuthMethodFromConfig(): AuthMethod {
312
+ const authConfig = this.dependencies.configProvider.config.auth;
313
+
314
+ if (authConfig.method && Object.values(AUTH_METHODS).includes(authConfig.method as AuthMethod)) {
315
+ return authConfig.method as AuthMethod;
316
+ }
317
+
318
+ // Auto-detect based on available credentials
319
+ if (authConfig.appPassword) return "app-password";
320
+ if (authConfig.secret || authConfig.password) return "jwt";
321
+ if (authConfig.apiKey) return "api-key";
322
+
323
+ return "basic"; // fallback
324
+ }
325
+
326
+ /**
327
+ * Validate authentication configuration
328
+ */
329
+ private validateAuthConfiguration(): void {
330
+ const authConfig = this.dependencies.configProvider.config.auth;
331
+
332
+ if (!authConfig) {
333
+ throw new AuthenticationError("No authentication configuration provided", this.authMethod);
334
+ }
335
+
336
+ switch (this.authMethod) {
337
+ case "app-password":
338
+ if (!authConfig.username || !authConfig.appPassword) {
339
+ throw new AuthenticationError(
340
+ "App password authentication requires username and appPassword",
341
+ this.authMethod,
342
+ );
343
+ }
344
+ break;
345
+ case "jwt":
346
+ if (!authConfig.username || !authConfig.password) {
347
+ throw new AuthenticationError("JWT authentication requires username and password", this.authMethod);
348
+ }
349
+ break;
350
+ case "basic":
351
+ if (!authConfig.username || !authConfig.password) {
352
+ throw new AuthenticationError("Basic authentication requires username and password", this.authMethod);
353
+ }
354
+ break;
355
+ case "api-key":
356
+ if (!authConfig.apiKey) {
357
+ throw new AuthenticationError("API key authentication requires apiKey", this.authMethod);
358
+ }
359
+ break;
360
+ }
361
+ }
362
+
363
+ /**
364
+ * Get app password credentials from config
365
+ */
366
+ private getAppPasswordCredentials(): AppPasswordCredentials {
367
+ const authConfig = this.dependencies.configProvider.config.auth;
368
+ return {
369
+ username: authConfig.username!,
370
+ appPassword: authConfig.appPassword!,
371
+ };
372
+ }
373
+
374
+ /**
375
+ * Get JWT credentials from config
376
+ */
377
+ private getJWTCredentials(): JwtCredentials {
378
+ const authConfig = this.dependencies.configProvider.config.auth;
379
+ const credentials: JwtCredentials = {
380
+ username: authConfig.username!,
381
+ password: authConfig.password!,
382
+ };
383
+
384
+ if (authConfig.secret) {
385
+ credentials.jwtSecret = authConfig.secret;
386
+ }
387
+
388
+ return credentials;
389
+ }
390
+
391
+ /**
392
+ * Get basic credentials from config
393
+ */
394
+ private getBasicCredentials(): BasicCredentials {
395
+ const authConfig = this.dependencies.configProvider.config.auth;
396
+ return {
397
+ username: authConfig.username!,
398
+ password: authConfig.password!,
399
+ };
400
+ }
401
+
402
+ /**
403
+ * Get API key from config
404
+ */
405
+ private getApiKeyFromConfig(): string {
406
+ const authConfig = this.dependencies.configProvider.config.auth;
407
+ return authConfig.apiKey || "";
408
+ }
409
+ }
@@ -0,0 +1,231 @@
1
+ /**
2
+ * Composed Manager Factory
3
+ * Factory for creating managers using composition instead of inheritance
4
+ */
5
+
6
+ import type { WordPressClientConfig } from "@/types/client.js";
7
+ import type {
8
+ ManagerFactory,
9
+ ConfigurationProvider,
10
+ ErrorHandler,
11
+ ParameterValidator,
12
+ AuthenticationProvider,
13
+ RequestHandler,
14
+ ManagerCompositionConfig,
15
+ } from "./interfaces/ManagerInterfaces.js";
16
+
17
+ import { ConfigurationProviderImpl } from "./implementations/ConfigurationProviderImpl.js";
18
+ import { ErrorHandlerImpl } from "./implementations/ErrorHandlerImpl.js";
19
+ import { ParameterValidatorImpl } from "./implementations/ParameterValidatorImpl.js";
20
+ import { ComposedAuthenticationManager } from "./ComposedAuthenticationManager.js";
21
+ import { ComposedRequestManager } from "./ComposedRequestManager.js";
22
+
23
+ export class ComposedManagerFactory implements ManagerFactory {
24
+ /**
25
+ * Create configuration provider
26
+ */
27
+ createConfigurationProvider(config: WordPressClientConfig): ConfigurationProvider {
28
+ return new ConfigurationProviderImpl(config);
29
+ }
30
+
31
+ /**
32
+ * Create error handler
33
+ */
34
+ createErrorHandler(config: WordPressClientConfig): ErrorHandler {
35
+ const configProvider = this.createConfigurationProvider(config);
36
+ return new ErrorHandlerImpl(configProvider);
37
+ }
38
+
39
+ /**
40
+ * Create parameter validator
41
+ */
42
+ createParameterValidator(): ParameterValidator {
43
+ return new ParameterValidatorImpl();
44
+ }
45
+
46
+ /**
47
+ * Create authentication provider
48
+ */
49
+ createAuthenticationProvider(config: WordPressClientConfig): AuthenticationProvider {
50
+ return ComposedAuthenticationManager.create(config);
51
+ }
52
+
53
+ /**
54
+ * Create request handler
55
+ */
56
+ createRequestHandler(config: WordPressClientConfig, authProvider: AuthenticationProvider): RequestHandler {
57
+ return ComposedRequestManager.create(config, authProvider);
58
+ }
59
+
60
+ /**
61
+ * Create a complete composed client with all managers
62
+ */
63
+ async createComposedClient(config: ManagerCompositionConfig): Promise<ComposedWordPressClient> {
64
+ const configProvider = this.createConfigurationProvider(config.clientConfig);
65
+ const errorHandler = config.customErrorHandler || this.createErrorHandler(config.clientConfig);
66
+ const validator = config.customValidator || this.createParameterValidator();
67
+ const authProvider = config.customAuthProvider || this.createAuthenticationProvider(config.clientConfig);
68
+
69
+ // Initialize authentication
70
+ await authProvider.authenticate();
71
+
72
+ const requestHandler = this.createRequestHandler(config.clientConfig, authProvider);
73
+
74
+ return new ComposedWordPressClient({
75
+ configProvider,
76
+ errorHandler,
77
+ validator,
78
+ authProvider,
79
+ requestHandler,
80
+ });
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Complete Composed WordPress Client
86
+ * Demonstrates how to combine all composed managers
87
+ */
88
+ export interface ComposedWordPressClientDependencies {
89
+ configProvider: ConfigurationProvider;
90
+ errorHandler: ErrorHandler;
91
+ validator: ParameterValidator;
92
+ authProvider: AuthenticationProvider;
93
+ requestHandler: RequestHandler;
94
+ }
95
+
96
+ export class ComposedWordPressClient {
97
+ private initialized: boolean = false;
98
+
99
+ constructor(private dependencies: ComposedWordPressClientDependencies) {}
100
+
101
+ /**
102
+ * Initialize the client
103
+ */
104
+ async initialize(): Promise<void> {
105
+ if (this.initialized) {
106
+ return;
107
+ }
108
+
109
+ try {
110
+ // Initialize all components
111
+ await this.dependencies.authProvider.authenticate();
112
+
113
+ if (
114
+ "initialize" in this.dependencies.requestHandler &&
115
+ typeof this.dependencies.requestHandler.initialize === "function"
116
+ ) {
117
+ await (this.dependencies.requestHandler as { initialize: () => Promise<void> }).initialize();
118
+ }
119
+
120
+ this.initialized = true;
121
+ this.dependencies.errorHandler.logSuccess("client initialization");
122
+ } catch (error) {
123
+ this.dependencies.errorHandler.handleError(error, "client initialization");
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Make HTTP requests (delegates to request manager)
129
+ */
130
+ async request<T>(method: string, endpoint: string, data?: unknown, options?: unknown): Promise<T> {
131
+ this.ensureInitialized();
132
+ return this.dependencies.requestHandler.request<T>(method, endpoint, data, options);
133
+ }
134
+
135
+ /**
136
+ * Get client configuration
137
+ */
138
+ get config(): WordPressClientConfig {
139
+ return this.dependencies.configProvider.config;
140
+ }
141
+
142
+ /**
143
+ * Check authentication status
144
+ */
145
+ isAuthenticated(): boolean {
146
+ return this.dependencies.authProvider.isAuthenticated();
147
+ }
148
+
149
+ /**
150
+ * Get request statistics
151
+ */
152
+ getStats(): unknown {
153
+ return this.dependencies.requestHandler.getStats();
154
+ }
155
+
156
+ /**
157
+ * WordPress-specific convenience methods
158
+ */
159
+
160
+ /**
161
+ * Get posts
162
+ */
163
+ async getPosts(params?: unknown): Promise<unknown[]> {
164
+ return this.request("GET", "/wp/v2/posts", params);
165
+ }
166
+
167
+ /**
168
+ * Get single post
169
+ */
170
+ async getPost(id: number): Promise<unknown> {
171
+ this.dependencies.validator.validateWordPressId(id, "post ID");
172
+ return this.request("GET", `/wp/v2/posts/${id}`);
173
+ }
174
+
175
+ /**
176
+ * Create post
177
+ */
178
+ async createPost(postData: unknown): Promise<unknown> {
179
+ this.dependencies.validator.validateRequired(postData as Record<string, unknown>, ["title", "content"]);
180
+ return this.request("POST", "/wp/v2/posts", postData);
181
+ }
182
+
183
+ /**
184
+ * Update post
185
+ */
186
+ async updatePost(id: number, postData: unknown): Promise<unknown> {
187
+ this.dependencies.validator.validateWordPressId(id, "post ID");
188
+ return this.request("PUT", `/wp/v2/posts/${id}`, postData);
189
+ }
190
+
191
+ /**
192
+ * Delete post
193
+ */
194
+ async deletePost(id: number, force: boolean = false): Promise<unknown> {
195
+ this.dependencies.validator.validateWordPressId(id, "post ID");
196
+ const params = force ? { force: true } : {};
197
+ return this.request("DELETE", `/wp/v2/posts/${id}`, params);
198
+ }
199
+
200
+ /**
201
+ * Cleanup resources
202
+ */
203
+ dispose(): void {
204
+ if (
205
+ "dispose" in this.dependencies.requestHandler &&
206
+ typeof this.dependencies.requestHandler.dispose === "function"
207
+ ) {
208
+ (this.dependencies.requestHandler as { dispose: () => void }).dispose();
209
+ }
210
+ this.initialized = false;
211
+ }
212
+
213
+ /**
214
+ * Ensure client is initialized
215
+ */
216
+ private ensureInitialized(): void {
217
+ if (!this.initialized) {
218
+ throw new Error("ComposedWordPressClient not initialized. Call initialize() first.");
219
+ }
220
+ }
221
+ }
222
+
223
+ /**
224
+ * Convenience factory function
225
+ */
226
+ export async function createComposedWordPressClient(config: WordPressClientConfig): Promise<ComposedWordPressClient> {
227
+ const factory = new ComposedManagerFactory();
228
+ const client = await factory.createComposedClient({ clientConfig: config });
229
+ await client.initialize();
230
+ return client;
231
+ }