mcp-wordpress 1.2.2 → 1.3.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 (251) hide show
  1. package/README.md +210 -182
  2. package/dist/cache/CacheInvalidation.d.ts +3 -3
  3. package/dist/cache/CacheInvalidation.d.ts.map +1 -1
  4. package/dist/cache/CacheInvalidation.js +119 -119
  5. package/dist/cache/CacheInvalidation.js.map +1 -1
  6. package/dist/cache/CacheManager.d.ts +5 -0
  7. package/dist/cache/CacheManager.d.ts.map +1 -1
  8. package/dist/cache/CacheManager.js +26 -16
  9. package/dist/cache/CacheManager.js.map +1 -1
  10. package/dist/cache/HttpCacheWrapper.d.ts +1 -1
  11. package/dist/cache/HttpCacheWrapper.d.ts.map +1 -1
  12. package/dist/cache/HttpCacheWrapper.js +29 -29
  13. package/dist/cache/HttpCacheWrapper.js.map +1 -1
  14. package/dist/cache/__tests__/CacheInvalidation.test.js +96 -94
  15. package/dist/cache/__tests__/CacheInvalidation.test.js.map +1 -1
  16. package/dist/cache/__tests__/CacheManager.test.js +113 -113
  17. package/dist/cache/__tests__/CacheManager.test.js.map +1 -1
  18. package/dist/cache/__tests__/CachedWordPressClient.test.js +102 -99
  19. package/dist/cache/__tests__/CachedWordPressClient.test.js.map +1 -1
  20. package/dist/cache/__tests__/HttpCacheWrapper.test.js +98 -95
  21. package/dist/cache/__tests__/HttpCacheWrapper.test.js.map +1 -1
  22. package/dist/cache/index.d.ts +7 -7
  23. package/dist/cache/index.d.ts.map +1 -1
  24. package/dist/cache/index.js +4 -4
  25. package/dist/cache/index.js.map +1 -1
  26. package/dist/client/CachedWordPressClient.d.ts +4 -4
  27. package/dist/client/CachedWordPressClient.d.ts.map +1 -1
  28. package/dist/client/CachedWordPressClient.js +55 -51
  29. package/dist/client/CachedWordPressClient.js.map +1 -1
  30. package/dist/client/api.d.ts +10 -10
  31. package/dist/client/api.js +158 -158
  32. package/dist/client/api.js.map +1 -1
  33. package/dist/client/auth.d.ts +2 -2
  34. package/dist/client/auth.js +72 -72
  35. package/dist/client/managers/AuthenticationManager.d.ts +2 -2
  36. package/dist/client/managers/AuthenticationManager.js +46 -46
  37. package/dist/client/managers/BaseManager.d.ts +1 -1
  38. package/dist/client/managers/BaseManager.js +9 -9
  39. package/dist/client/managers/RequestManager.d.ts +5 -3
  40. package/dist/client/managers/RequestManager.d.ts.map +1 -1
  41. package/dist/client/managers/RequestManager.js +39 -19
  42. package/dist/client/managers/RequestManager.js.map +1 -1
  43. package/dist/client/managers/index.d.ts +3 -3
  44. package/dist/client/managers/index.js +3 -3
  45. package/dist/config/ConfigurationSchema.d.ts +2 -2
  46. package/dist/config/ConfigurationSchema.d.ts.map +1 -1
  47. package/dist/config/ConfigurationSchema.js +40 -40
  48. package/dist/config/ConfigurationSchema.js.map +1 -1
  49. package/dist/config/ServerConfiguration.d.ts +2 -2
  50. package/dist/config/ServerConfiguration.js +35 -35
  51. package/dist/config/ServerConfiguration.js.map +1 -1
  52. package/dist/docs/DocumentationGenerator.d.ts.map +1 -1
  53. package/dist/docs/DocumentationGenerator.js +296 -255
  54. package/dist/docs/DocumentationGenerator.js.map +1 -1
  55. package/dist/docs/MarkdownFormatter.d.ts +1 -1
  56. package/dist/docs/MarkdownFormatter.d.ts.map +1 -1
  57. package/dist/docs/MarkdownFormatter.js +60 -51
  58. package/dist/docs/MarkdownFormatter.js.map +1 -1
  59. package/dist/docs/index.d.ts +3 -3
  60. package/dist/docs/index.d.ts.map +1 -1
  61. package/dist/docs/index.js +2 -2
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +16 -16
  64. package/dist/index.js.map +1 -1
  65. package/dist/mcp-wordpress-1.3.0.tgz +0 -0
  66. package/dist/performance/MetricsCollector.d.ts +3 -3
  67. package/dist/performance/MetricsCollector.d.ts.map +1 -1
  68. package/dist/performance/MetricsCollector.js +33 -27
  69. package/dist/performance/MetricsCollector.js.map +1 -1
  70. package/dist/performance/PerformanceAnalytics.d.ts +12 -12
  71. package/dist/performance/PerformanceAnalytics.d.ts.map +1 -1
  72. package/dist/performance/PerformanceAnalytics.js +200 -154
  73. package/dist/performance/PerformanceAnalytics.js.map +1 -1
  74. package/dist/performance/PerformanceMonitor.d.ts +5 -5
  75. package/dist/performance/PerformanceMonitor.d.ts.map +1 -1
  76. package/dist/performance/PerformanceMonitor.js +53 -52
  77. package/dist/performance/PerformanceMonitor.js.map +1 -1
  78. package/dist/performance/index.d.ts +6 -6
  79. package/dist/performance/index.d.ts.map +1 -1
  80. package/dist/performance/index.js +3 -3
  81. package/dist/security/InputValidator.d.ts +1 -1
  82. package/dist/security/InputValidator.d.ts.map +1 -1
  83. package/dist/security/InputValidator.js +111 -88
  84. package/dist/security/InputValidator.js.map +1 -1
  85. package/dist/security/SecurityConfig.d.ts +5 -5
  86. package/dist/security/SecurityConfig.js +92 -92
  87. package/dist/security/SecurityConfig.js.map +1 -1
  88. package/dist/server/ConnectionTester.d.ts +1 -1
  89. package/dist/server/ConnectionTester.d.ts.map +1 -1
  90. package/dist/server/ConnectionTester.js +4 -4
  91. package/dist/server/ConnectionTester.js.map +1 -1
  92. package/dist/server/ToolRegistry.d.ts +2 -2
  93. package/dist/server/ToolRegistry.d.ts.map +1 -1
  94. package/dist/server/ToolRegistry.js +35 -32
  95. package/dist/server/ToolRegistry.js.map +1 -1
  96. package/dist/server.d.ts +2 -2
  97. package/dist/server.js +2 -2
  98. package/dist/tools/BaseToolManager.js +5 -5
  99. package/dist/tools/auth.d.ts +2 -2
  100. package/dist/tools/auth.d.ts.map +1 -1
  101. package/dist/tools/auth.js +32 -31
  102. package/dist/tools/auth.js.map +1 -1
  103. package/dist/tools/cache.d.ts +1 -1
  104. package/dist/tools/cache.d.ts.map +1 -1
  105. package/dist/tools/cache.js +71 -71
  106. package/dist/tools/cache.js.map +1 -1
  107. package/dist/tools/comments.d.ts +2 -2
  108. package/dist/tools/comments.d.ts.map +1 -1
  109. package/dist/tools/comments.js +79 -79
  110. package/dist/tools/comments.js.map +1 -1
  111. package/dist/tools/index.d.ts +10 -10
  112. package/dist/tools/index.js +10 -10
  113. package/dist/tools/media.d.ts +2 -2
  114. package/dist/tools/media.js +80 -80
  115. package/dist/tools/pages.d.ts +2 -2
  116. package/dist/tools/pages.d.ts.map +1 -1
  117. package/dist/tools/pages.js +75 -75
  118. package/dist/tools/pages.js.map +1 -1
  119. package/dist/tools/performance.d.ts +1 -1
  120. package/dist/tools/performance.d.ts.map +1 -1
  121. package/dist/tools/performance.js +311 -287
  122. package/dist/tools/performance.js.map +1 -1
  123. package/dist/tools/posts.d.ts +2 -2
  124. package/dist/tools/posts.d.ts.map +1 -1
  125. package/dist/tools/posts.js +94 -94
  126. package/dist/tools/posts.js.map +1 -1
  127. package/dist/tools/site.d.ts +2 -2
  128. package/dist/tools/site.d.ts.map +1 -1
  129. package/dist/tools/site.js +60 -60
  130. package/dist/tools/site.js.map +1 -1
  131. package/dist/tools/taxonomies.d.ts +2 -2
  132. package/dist/tools/taxonomies.js +89 -89
  133. package/dist/tools/users.d.ts +2 -2
  134. package/dist/tools/users.js +68 -68
  135. package/dist/tools/users.js.map +1 -1
  136. package/dist/types/client.d.ts +13 -13
  137. package/dist/types/client.d.ts.map +1 -1
  138. package/dist/types/client.js +12 -12
  139. package/dist/types/client.js.map +1 -1
  140. package/dist/types/index.d.ts +19 -19
  141. package/dist/types/index.d.ts.map +1 -1
  142. package/dist/types/index.js +3 -3
  143. package/dist/types/mcp.d.ts +7 -7
  144. package/dist/types/wordpress.d.ts +21 -21
  145. package/dist/types/wordpress.d.ts.map +1 -1
  146. package/dist/utils/debug.d.ts +2 -2
  147. package/dist/utils/debug.js +28 -28
  148. package/dist/utils/error.d.ts.map +1 -1
  149. package/dist/utils/error.js +13 -13
  150. package/dist/utils/error.js.map +1 -1
  151. package/dist/utils/toolWrapper.d.ts.map +1 -1
  152. package/dist/utils/toolWrapper.js +5 -5
  153. package/dist/utils/toolWrapper.js.map +1 -1
  154. package/dist/utils/validation.d.ts.map +1 -1
  155. package/dist/utils/validation.js +41 -31
  156. package/dist/utils/validation.js.map +1 -1
  157. package/docs/CACHING.md +36 -2
  158. package/docs/DOCKER.md +24 -18
  159. package/docs/PERFORMANCE_MONITORING.md +49 -1
  160. package/docs/SECURITY_TESTING.md +30 -1
  161. package/docs/api/README.md +9 -1
  162. package/docs/api/summary.json +1 -1
  163. package/docs/contract-testing.md +24 -3
  164. package/docs/developer/GITHUB_ACTIONS_SETUP.md +8 -2
  165. package/docs/developer/MAINTENANCE.md +29 -3
  166. package/docs/developer/MIGRATION_GUIDE.md +13 -1
  167. package/docs/developer/NPM_AUTH_SETUP.md +13 -2
  168. package/docs/developer/REFACTORING.md +31 -1
  169. package/docs/releases/COMMUNITY_ANNOUNCEMENT_v1.1.2.md +18 -7
  170. package/docs/releases/RELEASE_NOTES_v1.1.2.md +31 -5
  171. package/docs/user-guides/DOCKER_SETUP.md +264 -0
  172. package/docs/user-guides/DTX_SETUP.md +327 -0
  173. package/docs/user-guides/NPM_SETUP.md +109 -0
  174. package/docs/user-guides/NPX_SETUP.md +281 -0
  175. package/docs/wordpress-rest-api-authentication-troubleshooting.md +13 -2
  176. package/package.json +27 -8
  177. package/src/cache/CacheInvalidation.ts +140 -132
  178. package/src/cache/CacheManager.ts +40 -29
  179. package/src/cache/HttpCacheWrapper.ts +105 -68
  180. package/src/cache/__tests__/CacheInvalidation.test.ts +123 -118
  181. package/src/cache/__tests__/CacheManager.test.ts +156 -152
  182. package/src/cache/__tests__/CachedWordPressClient.test.ts +131 -116
  183. package/src/cache/__tests__/HttpCacheWrapper.test.ts +118 -115
  184. package/src/cache/index.ts +13 -13
  185. package/src/client/CachedWordPressClient.ts +90 -80
  186. package/src/client/api.ts +205 -205
  187. package/src/client/auth.ts +80 -80
  188. package/src/client/managers/AuthenticationManager.ts +61 -61
  189. package/src/client/managers/BaseManager.ts +11 -11
  190. package/src/client/managers/RequestManager.ts +79 -47
  191. package/src/client/managers/index.ts +3 -3
  192. package/src/config/ConfigurationSchema.ts +44 -44
  193. package/src/config/ServerConfiguration.ts +39 -39
  194. package/src/docs/DocumentationGenerator.ts +402 -295
  195. package/src/docs/MarkdownFormatter.ts +94 -69
  196. package/src/docs/index.ts +4 -4
  197. package/src/index.ts +24 -21
  198. package/src/performance/MetricsCollector.ts +90 -58
  199. package/src/performance/PerformanceAnalytics.ts +386 -262
  200. package/src/performance/PerformanceMonitor.ts +152 -118
  201. package/src/performance/index.ts +9 -9
  202. package/src/security/InputValidator.ts +148 -91
  203. package/src/security/SecurityConfig.ts +94 -94
  204. package/src/server/ConnectionTester.ts +21 -15
  205. package/src/server/ToolRegistry.ts +64 -51
  206. package/src/server.ts +2 -2
  207. package/src/tools/BaseToolManager.ts +6 -6
  208. package/src/tools/auth.ts +42 -37
  209. package/src/tools/cache.ts +85 -81
  210. package/src/tools/comments.ts +93 -91
  211. package/src/tools/index.ts +10 -10
  212. package/src/tools/media.ts +89 -89
  213. package/src/tools/pages.ts +89 -87
  214. package/src/tools/performance.ts +443 -352
  215. package/src/tools/posts.ts +109 -107
  216. package/src/tools/site.ts +86 -77
  217. package/src/tools/taxonomies.ts +102 -102
  218. package/src/tools/users.ts +77 -77
  219. package/src/types/client.ts +157 -60
  220. package/src/types/index.ts +49 -27
  221. package/src/types/mcp.ts +15 -15
  222. package/src/types/wordpress.ts +57 -29
  223. package/src/utils/debug.ts +37 -37
  224. package/src/utils/error.ts +47 -25
  225. package/src/utils/toolWrapper.ts +12 -8
  226. package/src/utils/validation.ts +116 -65
  227. package/dist/client/WordPressClient.d.ts +0 -81
  228. package/dist/client/WordPressClient.d.ts.map +0 -1
  229. package/dist/client/WordPressClient.js +0 -354
  230. package/dist/client/WordPressClient.js.map +0 -1
  231. package/dist/performance/AnomalyDetector.d.ts +0 -63
  232. package/dist/performance/AnomalyDetector.d.ts.map +0 -1
  233. package/dist/performance/AnomalyDetector.js +0 -222
  234. package/dist/performance/AnomalyDetector.js.map +0 -1
  235. package/dist/performance/BenchmarkAnalyzer.d.ts +0 -67
  236. package/dist/performance/BenchmarkAnalyzer.d.ts.map +0 -1
  237. package/dist/performance/BenchmarkAnalyzer.js +0 -301
  238. package/dist/performance/BenchmarkAnalyzer.js.map +0 -1
  239. package/dist/performance/TrendAnalyzer.d.ts +0 -69
  240. package/dist/performance/TrendAnalyzer.d.ts.map +0 -1
  241. package/dist/performance/TrendAnalyzer.js +0 -203
  242. package/dist/performance/TrendAnalyzer.js.map +0 -1
  243. package/dist/tools/BaseToolClass.d.ts +0 -76
  244. package/dist/tools/BaseToolClass.d.ts.map +0 -1
  245. package/dist/tools/BaseToolClass.js +0 -104
  246. package/dist/tools/BaseToolClass.js.map +0 -1
  247. package/dist/tools/base.d.ts +0 -37
  248. package/dist/tools/base.d.ts.map +0 -1
  249. package/dist/tools/base.js +0 -60
  250. package/dist/tools/base.js.map +0 -1
  251. package/docs/user-guides/CLAUDE_DESKTOP_SETUP.md +0 -187
@@ -2,10 +2,10 @@
2
2
  * Tests for HttpCacheWrapper
3
3
  */
4
4
 
5
- import { CacheManager } from '../CacheManager.js';
6
- import { HttpCacheWrapper } from '../HttpCacheWrapper.js';
5
+ import { CacheManager } from "../CacheManager.js";
6
+ import { HttpCacheWrapper } from "../HttpCacheWrapper.js";
7
7
 
8
- describe('HttpCacheWrapper', () => {
8
+ describe("HttpCacheWrapper", () => {
9
9
  let cacheManager: CacheManager;
10
10
  let httpCache: HttpCacheWrapper;
11
11
  let mockRequestFn: jest.Mock;
@@ -15,11 +15,11 @@ describe('HttpCacheWrapper', () => {
15
15
  maxSize: 100,
16
16
  defaultTTL: 1000,
17
17
  enableLRU: true,
18
- enableStats: true
18
+ enableStats: true,
19
19
  });
20
-
21
- httpCache = new HttpCacheWrapper(cacheManager, 'test-site');
22
-
20
+
21
+ httpCache = new HttpCacheWrapper(cacheManager, "test-site");
22
+
23
23
  mockRequestFn = jest.fn();
24
24
  });
25
25
 
@@ -28,21 +28,21 @@ describe('HttpCacheWrapper', () => {
28
28
  jest.clearAllMocks();
29
29
  });
30
30
 
31
- describe('Request Caching', () => {
32
- test('should cache GET requests', async () => {
31
+ describe("Request Caching", () => {
32
+ test("should cache GET requests", async () => {
33
33
  const mockResponse = {
34
- data: { id: 1, title: 'Test Post' },
34
+ data: { id: 1, title: "Test Post" },
35
35
  status: 200,
36
- headers: {}
36
+ headers: {},
37
37
  };
38
-
38
+
39
39
  mockRequestFn.mockResolvedValue(mockResponse);
40
-
40
+
41
41
  const requestOptions = {
42
- method: 'GET',
43
- url: 'https://example.com/wp-json/wp/v2/posts',
42
+ method: "GET",
43
+ url: "https://example.com/wp-json/wp/v2/posts",
44
44
  headers: {},
45
- params: {}
45
+ params: {},
46
46
  };
47
47
 
48
48
  // First request should hit the API
@@ -58,96 +58,96 @@ describe('HttpCacheWrapper', () => {
58
58
  expect(result2.cached).toBe(true);
59
59
  });
60
60
 
61
- test('should not cache non-GET requests', async () => {
61
+ test("should not cache non-GET requests", async () => {
62
62
  const mockResponse = {
63
- data: { id: 1, title: 'Test Post' },
63
+ data: { id: 1, title: "Test Post" },
64
64
  status: 201,
65
- headers: {}
65
+ headers: {},
66
66
  };
67
-
67
+
68
68
  mockRequestFn.mockResolvedValue(mockResponse);
69
-
69
+
70
70
  const requestOptions = {
71
- method: 'POST',
72
- url: 'https://example.com/wp-json/wp/v2/posts',
71
+ method: "POST",
72
+ url: "https://example.com/wp-json/wp/v2/posts",
73
73
  headers: {},
74
74
  params: {},
75
- data: { title: 'New Post' }
75
+ data: { title: "New Post" },
76
76
  };
77
77
 
78
78
  // Both requests should hit the API
79
79
  const result1 = await httpCache.request(mockRequestFn, requestOptions);
80
80
  const result2 = await httpCache.request(mockRequestFn, requestOptions);
81
-
81
+
82
82
  expect(mockRequestFn).toHaveBeenCalledTimes(2);
83
83
  expect(result1.cached).toBeUndefined();
84
84
  expect(result2.cached).toBeUndefined();
85
85
  });
86
86
 
87
- test('should not cache error responses', async () => {
87
+ test("should not cache error responses", async () => {
88
88
  const errorResponse = {
89
- data: { error: 'Not found' },
89
+ data: { error: "Not found" },
90
90
  status: 404,
91
- headers: {}
91
+ headers: {},
92
92
  };
93
-
93
+
94
94
  mockRequestFn.mockResolvedValue(errorResponse);
95
-
95
+
96
96
  const requestOptions = {
97
- method: 'GET',
98
- url: 'https://example.com/wp-json/wp/v2/posts/999',
97
+ method: "GET",
98
+ url: "https://example.com/wp-json/wp/v2/posts/999",
99
99
  headers: {},
100
- params: {}
100
+ params: {},
101
101
  };
102
102
 
103
103
  // Both requests should hit the API (no caching of 404)
104
104
  await httpCache.request(mockRequestFn, requestOptions);
105
105
  await httpCache.request(mockRequestFn, requestOptions);
106
-
106
+
107
107
  expect(mockRequestFn).toHaveBeenCalledTimes(2);
108
108
  });
109
109
 
110
- test('should generate ETags for responses', async () => {
110
+ test("should generate ETags for responses", async () => {
111
111
  const mockResponse = {
112
- data: { id: 1, title: 'Test Post' },
112
+ data: { id: 1, title: "Test Post" },
113
113
  status: 200,
114
- headers: {}
114
+ headers: {},
115
115
  };
116
-
116
+
117
117
  mockRequestFn.mockResolvedValue(mockResponse);
118
-
118
+
119
119
  const requestOptions = {
120
- method: 'GET',
121
- url: 'https://example.com/wp-json/wp/v2/posts/1',
120
+ method: "GET",
121
+ url: "https://example.com/wp-json/wp/v2/posts/1",
122
122
  headers: {},
123
- params: {}
123
+ params: {},
124
124
  };
125
125
 
126
126
  const result = await httpCache.request(mockRequestFn, requestOptions);
127
-
127
+
128
128
  expect(result.headers.etag).toBeDefined();
129
129
  expect(result.headers.etag).toMatch(/^"[a-f0-9]{32}"$/);
130
- expect(result.headers['last-modified']).toBeDefined();
131
- expect(result.headers['cache-control']).toBeDefined();
130
+ expect(result.headers["last-modified"]).toBeDefined();
131
+ expect(result.headers["cache-control"]).toBeDefined();
132
132
  });
133
133
  });
134
134
 
135
- describe('Cache Invalidation', () => {
136
- test('should invalidate specific endpoint', async () => {
135
+ describe("Cache Invalidation", () => {
136
+ test("should invalidate specific endpoint", async () => {
137
137
  // Cache a response
138
138
  const mockResponse = {
139
- data: { id: 1, title: 'Test Post' },
139
+ data: { id: 1, title: "Test Post" },
140
140
  status: 200,
141
- headers: {}
141
+ headers: {},
142
142
  };
143
-
143
+
144
144
  mockRequestFn.mockResolvedValue(mockResponse);
145
-
145
+
146
146
  const requestOptions = {
147
- method: 'GET',
148
- url: 'https://example.com/wp-json/wp/v2/posts/1',
147
+ method: "GET",
148
+ url: "https://example.com/wp-json/wp/v2/posts/1",
149
149
  headers: {},
150
- params: {}
150
+ params: {},
151
151
  };
152
152
 
153
153
  await httpCache.request(mockRequestFn, requestOptions);
@@ -158,74 +158,74 @@ describe('HttpCacheWrapper', () => {
158
158
  expect(mockRequestFn).toHaveBeenCalledTimes(1);
159
159
 
160
160
  // Invalidate cache
161
- httpCache.invalidate('posts/1');
161
+ httpCache.invalidate("posts/1");
162
162
 
163
163
  // Should hit API again
164
164
  await httpCache.request(mockRequestFn, requestOptions);
165
165
  expect(mockRequestFn).toHaveBeenCalledTimes(2);
166
166
  });
167
167
 
168
- test('should invalidate by pattern', async () => {
168
+ test("should invalidate by pattern", async () => {
169
169
  // Cache multiple responses
170
170
  const responses = [
171
- { url: 'posts', data: [{ id: 1 }, { id: 2 }] },
172
- { url: 'posts/1', data: { id: 1 } },
173
- { url: 'pages/1', data: { id: 1 } }
171
+ { url: "posts", data: [{ id: 1 }, { id: 2 }] },
172
+ { url: "posts/1", data: { id: 1 } },
173
+ { url: "pages/1", data: { id: 1 } },
174
174
  ];
175
175
 
176
176
  for (const response of responses) {
177
177
  mockRequestFn.mockResolvedValueOnce({
178
178
  data: response.data,
179
179
  status: 200,
180
- headers: {}
180
+ headers: {},
181
181
  });
182
182
 
183
183
  await httpCache.request(mockRequestFn, {
184
- method: 'GET',
184
+ method: "GET",
185
185
  url: `https://example.com/wp-json/wp/v2/${response.url}`,
186
186
  headers: {},
187
- params: {}
187
+ params: {},
188
188
  });
189
189
  }
190
190
 
191
191
  expect(mockRequestFn).toHaveBeenCalledTimes(3);
192
192
 
193
193
  // Invalidate all posts
194
- const invalidated = httpCache.invalidatePattern('posts');
194
+ const invalidated = httpCache.invalidatePattern("posts");
195
195
  expect(invalidated).toBe(2); // Should invalidate 2 post-related entries
196
196
 
197
197
  // Verify pages cache still works
198
198
  await httpCache.request(mockRequestFn, {
199
- method: 'GET',
200
- url: 'https://example.com/wp-json/wp/v2/pages/1',
199
+ method: "GET",
200
+ url: "https://example.com/wp-json/wp/v2/pages/1",
201
201
  headers: {},
202
- params: {}
202
+ params: {},
203
203
  });
204
204
  expect(mockRequestFn).toHaveBeenCalledTimes(3); // No new call for pages
205
205
  });
206
206
 
207
- test('should invalidate all cache for site', async () => {
207
+ test("should invalidate all cache for site", async () => {
208
208
  // Cache some responses
209
209
  const mockResponse = {
210
210
  data: { id: 1 },
211
211
  status: 200,
212
- headers: {}
212
+ headers: {},
213
213
  };
214
-
214
+
215
215
  mockRequestFn.mockResolvedValue(mockResponse);
216
216
 
217
217
  await httpCache.request(mockRequestFn, {
218
- method: 'GET',
219
- url: 'https://example.com/wp-json/wp/v2/posts',
218
+ method: "GET",
219
+ url: "https://example.com/wp-json/wp/v2/posts",
220
220
  headers: {},
221
- params: {}
221
+ params: {},
222
222
  });
223
223
 
224
224
  await httpCache.request(mockRequestFn, {
225
- method: 'GET',
226
- url: 'https://example.com/wp-json/wp/v2/pages',
225
+ method: "GET",
226
+ url: "https://example.com/wp-json/wp/v2/pages",
227
227
  headers: {},
228
- params: {}
228
+ params: {},
229
229
  });
230
230
 
231
231
  expect(mockRequestFn).toHaveBeenCalledTimes(2);
@@ -236,46 +236,49 @@ describe('HttpCacheWrapper', () => {
236
236
 
237
237
  // Verify cache is cleared
238
238
  await httpCache.request(mockRequestFn, {
239
- method: 'GET',
240
- url: 'https://example.com/wp-json/wp/v2/posts',
239
+ method: "GET",
240
+ url: "https://example.com/wp-json/wp/v2/posts",
241
241
  headers: {},
242
- params: {}
242
+ params: {},
243
243
  });
244
244
  expect(mockRequestFn).toHaveBeenCalledTimes(3);
245
245
  });
246
246
  });
247
247
 
248
- describe('Cache Warming', () => {
249
- test('should pre-warm cache with data', () => {
250
- const endpoint = 'posts';
251
- const data = [{ id: 1, title: 'Post 1' }, { id: 2, title: 'Post 2' }];
248
+ describe("Cache Warming", () => {
249
+ test("should pre-warm cache with data", () => {
250
+ const endpoint = "posts";
251
+ const data = [
252
+ { id: 1, title: "Post 1" },
253
+ { id: 2, title: "Post 2" },
254
+ ];
252
255
  const params = { per_page: 10 };
253
256
 
254
257
  httpCache.warm(endpoint, data, params);
255
258
 
256
259
  // Verify cache entry exists
257
- const cacheKey = cacheManager.generateKey('test-site', endpoint, params);
260
+ const cacheKey = cacheManager.generateKey("test-site", endpoint, params);
258
261
  const cached = cacheManager.get(cacheKey);
259
-
262
+
260
263
  expect(cached).toBeDefined();
261
- if (cached && typeof cached === 'object' && 'data' in cached) {
264
+ if (cached && typeof cached === "object" && "data" in cached) {
262
265
  expect((cached as any).data).toEqual(data);
263
266
  expect((cached as any).etag).toBeDefined();
264
267
  expect((cached as any).lastModified).toBeDefined();
265
268
  }
266
269
  });
267
270
 
268
- test('should use warmed cache for requests', async () => {
269
- const endpoint = 'posts';
270
- const data = [{ id: 1, title: 'Post 1' }];
271
-
271
+ test("should use warmed cache for requests", async () => {
272
+ const endpoint = "posts";
273
+ const data = [{ id: 1, title: "Post 1" }];
274
+
272
275
  httpCache.warm(endpoint, data);
273
276
 
274
277
  const result = await httpCache.request(mockRequestFn, {
275
- method: 'GET',
276
- url: 'https://example.com/wp-json/wp/v2/posts',
278
+ method: "GET",
279
+ url: "https://example.com/wp-json/wp/v2/posts",
277
280
  headers: {},
278
- params: {}
281
+ params: {},
279
282
  });
280
283
 
281
284
  expect(mockRequestFn).not.toHaveBeenCalled();
@@ -284,29 +287,29 @@ describe('HttpCacheWrapper', () => {
284
287
  });
285
288
  });
286
289
 
287
- describe('Cache Statistics', () => {
288
- test('should return cache statistics', async () => {
290
+ describe("Cache Statistics", () => {
291
+ test("should return cache statistics", async () => {
289
292
  const mockResponse = {
290
293
  data: { id: 1 },
291
294
  status: 200,
292
- headers: {}
295
+ headers: {},
293
296
  };
294
-
297
+
295
298
  mockRequestFn.mockResolvedValue(mockResponse);
296
299
 
297
300
  // Generate some cache activity
298
301
  await httpCache.request(mockRequestFn, {
299
- method: 'GET',
300
- url: 'https://example.com/wp-json/wp/v2/posts/1',
302
+ method: "GET",
303
+ url: "https://example.com/wp-json/wp/v2/posts/1",
301
304
  headers: {},
302
- params: {}
305
+ params: {},
303
306
  });
304
307
 
305
308
  await httpCache.request(mockRequestFn, {
306
- method: 'GET',
307
- url: 'https://example.com/wp-json/wp/v2/posts/1',
309
+ method: "GET",
310
+ url: "https://example.com/wp-json/wp/v2/posts/1",
308
311
  headers: {},
309
- params: {}
312
+ params: {},
310
313
  });
311
314
 
312
315
  const stats = httpCache.getStats();
@@ -317,37 +320,37 @@ describe('HttpCacheWrapper', () => {
317
320
  });
318
321
  });
319
322
 
320
- describe('URL and Endpoint Extraction', () => {
321
- test('should extract endpoint from WordPress API URLs', async () => {
323
+ describe("URL and Endpoint Extraction", () => {
324
+ test("should extract endpoint from WordPress API URLs", async () => {
322
325
  const testCases = [
323
326
  {
324
- url: 'https://example.com/wp-json/wp/v2/posts',
325
- expectedEndpoint: 'posts'
327
+ url: "https://example.com/wp-json/wp/v2/posts",
328
+ expectedEndpoint: "posts",
326
329
  },
327
330
  {
328
- url: 'https://example.com/wp-json/wp/v2/posts/123',
329
- expectedEndpoint: 'posts/123'
331
+ url: "https://example.com/wp-json/wp/v2/posts/123",
332
+ expectedEndpoint: "posts/123",
330
333
  },
331
334
  {
332
- url: 'https://example.com/wp-json/wp/v2/categories?per_page=10',
333
- expectedEndpoint: 'categories'
334
- }
335
+ url: "https://example.com/wp-json/wp/v2/categories?per_page=10",
336
+ expectedEndpoint: "categories",
337
+ },
335
338
  ];
336
339
 
337
340
  const mockResponse = {
338
341
  data: {},
339
342
  status: 200,
340
- headers: {}
343
+ headers: {},
341
344
  };
342
-
345
+
343
346
  mockRequestFn.mockResolvedValue(mockResponse);
344
347
 
345
348
  for (const testCase of testCases) {
346
349
  await httpCache.request(mockRequestFn, {
347
- method: 'GET',
350
+ method: "GET",
348
351
  url: testCase.url,
349
352
  headers: {},
350
- params: {}
353
+ params: {},
351
354
  });
352
355
 
353
356
  // Verify cache key contains the correct endpoint
@@ -3,24 +3,24 @@
3
3
  * Provides centralized access to all caching components
4
4
  */
5
5
 
6
- export { CacheManager, CachePresets } from './CacheManager.js';
7
- export { HttpCacheWrapper } from './HttpCacheWrapper.js';
8
- export { CacheInvalidation, WordPressCachePatterns, CacheWarmer } from './CacheInvalidation.js';
9
- export { CachedWordPressClient } from '../client/CachedWordPressClient.js';
6
+ export { CacheManager, CachePresets } from "./CacheManager.js";
7
+ export { HttpCacheWrapper } from "./HttpCacheWrapper.js";
8
+ export {
9
+ CacheInvalidation,
10
+ WordPressCachePatterns,
11
+ CacheWarmer,
12
+ } from "./CacheInvalidation.js";
13
+ export { CachedWordPressClient } from "../client/CachedWordPressClient.js";
10
14
 
11
- export type {
12
- CacheEntry,
13
- CacheStats,
14
- CacheConfig
15
- } from './CacheManager.js';
15
+ export type { CacheEntry, CacheStats, CacheConfig } from "./CacheManager.js";
16
16
 
17
17
  export type {
18
18
  HttpCacheOptions,
19
19
  CachedResponse,
20
- RequestOptions
21
- } from './HttpCacheWrapper.js';
20
+ RequestOptions,
21
+ } from "./HttpCacheWrapper.js";
22
22
 
23
23
  export type {
24
24
  InvalidationRule,
25
- InvalidationEvent
26
- } from './CacheInvalidation.js';
25
+ InvalidationEvent,
26
+ } from "./CacheInvalidation.js";