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.
- package/README.md +210 -182
- package/dist/cache/CacheInvalidation.d.ts +3 -3
- package/dist/cache/CacheInvalidation.d.ts.map +1 -1
- package/dist/cache/CacheInvalidation.js +119 -119
- package/dist/cache/CacheInvalidation.js.map +1 -1
- package/dist/cache/CacheManager.d.ts +5 -0
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.js +26 -16
- package/dist/cache/CacheManager.js.map +1 -1
- package/dist/cache/HttpCacheWrapper.d.ts +1 -1
- package/dist/cache/HttpCacheWrapper.d.ts.map +1 -1
- package/dist/cache/HttpCacheWrapper.js +29 -29
- package/dist/cache/HttpCacheWrapper.js.map +1 -1
- package/dist/cache/__tests__/CacheInvalidation.test.js +96 -94
- package/dist/cache/__tests__/CacheInvalidation.test.js.map +1 -1
- package/dist/cache/__tests__/CacheManager.test.js +113 -113
- package/dist/cache/__tests__/CacheManager.test.js.map +1 -1
- package/dist/cache/__tests__/CachedWordPressClient.test.js +102 -99
- package/dist/cache/__tests__/CachedWordPressClient.test.js.map +1 -1
- package/dist/cache/__tests__/HttpCacheWrapper.test.js +98 -95
- package/dist/cache/__tests__/HttpCacheWrapper.test.js.map +1 -1
- package/dist/cache/index.d.ts +7 -7
- package/dist/cache/index.d.ts.map +1 -1
- package/dist/cache/index.js +4 -4
- package/dist/cache/index.js.map +1 -1
- package/dist/client/CachedWordPressClient.d.ts +4 -4
- package/dist/client/CachedWordPressClient.d.ts.map +1 -1
- package/dist/client/CachedWordPressClient.js +55 -51
- package/dist/client/CachedWordPressClient.js.map +1 -1
- package/dist/client/api.d.ts +10 -10
- package/dist/client/api.js +158 -158
- package/dist/client/api.js.map +1 -1
- package/dist/client/auth.d.ts +2 -2
- package/dist/client/auth.js +72 -72
- package/dist/client/managers/AuthenticationManager.d.ts +2 -2
- package/dist/client/managers/AuthenticationManager.js +46 -46
- package/dist/client/managers/BaseManager.d.ts +1 -1
- package/dist/client/managers/BaseManager.js +9 -9
- package/dist/client/managers/RequestManager.d.ts +5 -3
- package/dist/client/managers/RequestManager.d.ts.map +1 -1
- package/dist/client/managers/RequestManager.js +39 -19
- package/dist/client/managers/RequestManager.js.map +1 -1
- package/dist/client/managers/index.d.ts +3 -3
- package/dist/client/managers/index.js +3 -3
- package/dist/config/ConfigurationSchema.d.ts +2 -2
- package/dist/config/ConfigurationSchema.d.ts.map +1 -1
- package/dist/config/ConfigurationSchema.js +40 -40
- package/dist/config/ConfigurationSchema.js.map +1 -1
- package/dist/config/ServerConfiguration.d.ts +2 -2
- package/dist/config/ServerConfiguration.js +35 -35
- package/dist/config/ServerConfiguration.js.map +1 -1
- package/dist/docs/DocumentationGenerator.d.ts.map +1 -1
- package/dist/docs/DocumentationGenerator.js +296 -255
- package/dist/docs/DocumentationGenerator.js.map +1 -1
- package/dist/docs/MarkdownFormatter.d.ts +1 -1
- package/dist/docs/MarkdownFormatter.d.ts.map +1 -1
- package/dist/docs/MarkdownFormatter.js +60 -51
- package/dist/docs/MarkdownFormatter.js.map +1 -1
- package/dist/docs/index.d.ts +3 -3
- package/dist/docs/index.d.ts.map +1 -1
- package/dist/docs/index.js +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -16
- package/dist/index.js.map +1 -1
- package/dist/mcp-wordpress-1.3.0.tgz +0 -0
- package/dist/performance/MetricsCollector.d.ts +3 -3
- package/dist/performance/MetricsCollector.d.ts.map +1 -1
- package/dist/performance/MetricsCollector.js +33 -27
- package/dist/performance/MetricsCollector.js.map +1 -1
- package/dist/performance/PerformanceAnalytics.d.ts +12 -12
- package/dist/performance/PerformanceAnalytics.d.ts.map +1 -1
- package/dist/performance/PerformanceAnalytics.js +200 -154
- package/dist/performance/PerformanceAnalytics.js.map +1 -1
- package/dist/performance/PerformanceMonitor.d.ts +5 -5
- package/dist/performance/PerformanceMonitor.d.ts.map +1 -1
- package/dist/performance/PerformanceMonitor.js +53 -52
- package/dist/performance/PerformanceMonitor.js.map +1 -1
- package/dist/performance/index.d.ts +6 -6
- package/dist/performance/index.d.ts.map +1 -1
- package/dist/performance/index.js +3 -3
- package/dist/security/InputValidator.d.ts +1 -1
- package/dist/security/InputValidator.d.ts.map +1 -1
- package/dist/security/InputValidator.js +111 -88
- package/dist/security/InputValidator.js.map +1 -1
- package/dist/security/SecurityConfig.d.ts +5 -5
- package/dist/security/SecurityConfig.js +92 -92
- package/dist/security/SecurityConfig.js.map +1 -1
- package/dist/server/ConnectionTester.d.ts +1 -1
- package/dist/server/ConnectionTester.d.ts.map +1 -1
- package/dist/server/ConnectionTester.js +4 -4
- package/dist/server/ConnectionTester.js.map +1 -1
- package/dist/server/ToolRegistry.d.ts +2 -2
- package/dist/server/ToolRegistry.d.ts.map +1 -1
- package/dist/server/ToolRegistry.js +35 -32
- package/dist/server/ToolRegistry.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.js +2 -2
- package/dist/tools/BaseToolManager.js +5 -5
- package/dist/tools/auth.d.ts +2 -2
- package/dist/tools/auth.d.ts.map +1 -1
- package/dist/tools/auth.js +32 -31
- package/dist/tools/auth.js.map +1 -1
- package/dist/tools/cache.d.ts +1 -1
- package/dist/tools/cache.d.ts.map +1 -1
- package/dist/tools/cache.js +71 -71
- package/dist/tools/cache.js.map +1 -1
- package/dist/tools/comments.d.ts +2 -2
- package/dist/tools/comments.d.ts.map +1 -1
- package/dist/tools/comments.js +79 -79
- package/dist/tools/comments.js.map +1 -1
- package/dist/tools/index.d.ts +10 -10
- package/dist/tools/index.js +10 -10
- package/dist/tools/media.d.ts +2 -2
- package/dist/tools/media.js +80 -80
- package/dist/tools/pages.d.ts +2 -2
- package/dist/tools/pages.d.ts.map +1 -1
- package/dist/tools/pages.js +75 -75
- package/dist/tools/pages.js.map +1 -1
- package/dist/tools/performance.d.ts +1 -1
- package/dist/tools/performance.d.ts.map +1 -1
- package/dist/tools/performance.js +311 -287
- package/dist/tools/performance.js.map +1 -1
- package/dist/tools/posts.d.ts +2 -2
- package/dist/tools/posts.d.ts.map +1 -1
- package/dist/tools/posts.js +94 -94
- package/dist/tools/posts.js.map +1 -1
- package/dist/tools/site.d.ts +2 -2
- package/dist/tools/site.d.ts.map +1 -1
- package/dist/tools/site.js +60 -60
- package/dist/tools/site.js.map +1 -1
- package/dist/tools/taxonomies.d.ts +2 -2
- package/dist/tools/taxonomies.js +89 -89
- package/dist/tools/users.d.ts +2 -2
- package/dist/tools/users.js +68 -68
- package/dist/tools/users.js.map +1 -1
- package/dist/types/client.d.ts +13 -13
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/client.js +12 -12
- package/dist/types/client.js.map +1 -1
- package/dist/types/index.d.ts +19 -19
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +3 -3
- package/dist/types/mcp.d.ts +7 -7
- package/dist/types/wordpress.d.ts +21 -21
- package/dist/types/wordpress.d.ts.map +1 -1
- package/dist/utils/debug.d.ts +2 -2
- package/dist/utils/debug.js +28 -28
- package/dist/utils/error.d.ts.map +1 -1
- package/dist/utils/error.js +13 -13
- package/dist/utils/error.js.map +1 -1
- package/dist/utils/toolWrapper.d.ts.map +1 -1
- package/dist/utils/toolWrapper.js +5 -5
- package/dist/utils/toolWrapper.js.map +1 -1
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +41 -31
- package/dist/utils/validation.js.map +1 -1
- package/docs/CACHING.md +36 -2
- package/docs/DOCKER.md +24 -18
- package/docs/PERFORMANCE_MONITORING.md +49 -1
- package/docs/SECURITY_TESTING.md +30 -1
- package/docs/api/README.md +9 -1
- package/docs/api/summary.json +1 -1
- package/docs/contract-testing.md +24 -3
- package/docs/developer/GITHUB_ACTIONS_SETUP.md +8 -2
- package/docs/developer/MAINTENANCE.md +29 -3
- package/docs/developer/MIGRATION_GUIDE.md +13 -1
- package/docs/developer/NPM_AUTH_SETUP.md +13 -2
- package/docs/developer/REFACTORING.md +31 -1
- package/docs/releases/COMMUNITY_ANNOUNCEMENT_v1.1.2.md +18 -7
- package/docs/releases/RELEASE_NOTES_v1.1.2.md +31 -5
- package/docs/user-guides/DOCKER_SETUP.md +264 -0
- package/docs/user-guides/DTX_SETUP.md +327 -0
- package/docs/user-guides/NPM_SETUP.md +109 -0
- package/docs/user-guides/NPX_SETUP.md +281 -0
- package/docs/wordpress-rest-api-authentication-troubleshooting.md +13 -2
- package/package.json +27 -8
- package/src/cache/CacheInvalidation.ts +140 -132
- package/src/cache/CacheManager.ts +40 -29
- package/src/cache/HttpCacheWrapper.ts +105 -68
- package/src/cache/__tests__/CacheInvalidation.test.ts +123 -118
- package/src/cache/__tests__/CacheManager.test.ts +156 -152
- package/src/cache/__tests__/CachedWordPressClient.test.ts +131 -116
- package/src/cache/__tests__/HttpCacheWrapper.test.ts +118 -115
- package/src/cache/index.ts +13 -13
- package/src/client/CachedWordPressClient.ts +90 -80
- package/src/client/api.ts +205 -205
- package/src/client/auth.ts +80 -80
- package/src/client/managers/AuthenticationManager.ts +61 -61
- package/src/client/managers/BaseManager.ts +11 -11
- package/src/client/managers/RequestManager.ts +79 -47
- package/src/client/managers/index.ts +3 -3
- package/src/config/ConfigurationSchema.ts +44 -44
- package/src/config/ServerConfiguration.ts +39 -39
- package/src/docs/DocumentationGenerator.ts +402 -295
- package/src/docs/MarkdownFormatter.ts +94 -69
- package/src/docs/index.ts +4 -4
- package/src/index.ts +24 -21
- package/src/performance/MetricsCollector.ts +90 -58
- package/src/performance/PerformanceAnalytics.ts +386 -262
- package/src/performance/PerformanceMonitor.ts +152 -118
- package/src/performance/index.ts +9 -9
- package/src/security/InputValidator.ts +148 -91
- package/src/security/SecurityConfig.ts +94 -94
- package/src/server/ConnectionTester.ts +21 -15
- package/src/server/ToolRegistry.ts +64 -51
- package/src/server.ts +2 -2
- package/src/tools/BaseToolManager.ts +6 -6
- package/src/tools/auth.ts +42 -37
- package/src/tools/cache.ts +85 -81
- package/src/tools/comments.ts +93 -91
- package/src/tools/index.ts +10 -10
- package/src/tools/media.ts +89 -89
- package/src/tools/pages.ts +89 -87
- package/src/tools/performance.ts +443 -352
- package/src/tools/posts.ts +109 -107
- package/src/tools/site.ts +86 -77
- package/src/tools/taxonomies.ts +102 -102
- package/src/tools/users.ts +77 -77
- package/src/types/client.ts +157 -60
- package/src/types/index.ts +49 -27
- package/src/types/mcp.ts +15 -15
- package/src/types/wordpress.ts +57 -29
- package/src/utils/debug.ts +37 -37
- package/src/utils/error.ts +47 -25
- package/src/utils/toolWrapper.ts +12 -8
- package/src/utils/validation.ts +116 -65
- package/dist/client/WordPressClient.d.ts +0 -81
- package/dist/client/WordPressClient.d.ts.map +0 -1
- package/dist/client/WordPressClient.js +0 -354
- package/dist/client/WordPressClient.js.map +0 -1
- package/dist/performance/AnomalyDetector.d.ts +0 -63
- package/dist/performance/AnomalyDetector.d.ts.map +0 -1
- package/dist/performance/AnomalyDetector.js +0 -222
- package/dist/performance/AnomalyDetector.js.map +0 -1
- package/dist/performance/BenchmarkAnalyzer.d.ts +0 -67
- package/dist/performance/BenchmarkAnalyzer.d.ts.map +0 -1
- package/dist/performance/BenchmarkAnalyzer.js +0 -301
- package/dist/performance/BenchmarkAnalyzer.js.map +0 -1
- package/dist/performance/TrendAnalyzer.d.ts +0 -69
- package/dist/performance/TrendAnalyzer.d.ts.map +0 -1
- package/dist/performance/TrendAnalyzer.js +0 -203
- package/dist/performance/TrendAnalyzer.js.map +0 -1
- package/dist/tools/BaseToolClass.d.ts +0 -76
- package/dist/tools/BaseToolClass.d.ts.map +0 -1
- package/dist/tools/BaseToolClass.js +0 -104
- package/dist/tools/BaseToolClass.js.map +0 -1
- package/dist/tools/base.d.ts +0 -37
- package/dist/tools/base.d.ts.map +0 -1
- package/dist/tools/base.js +0 -60
- package/dist/tools/base.js.map +0 -1
- 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
|
|
6
|
-
import { HttpCacheWrapper } from
|
|
5
|
+
import { CacheManager } from "../CacheManager.js";
|
|
6
|
+
import { HttpCacheWrapper } from "../HttpCacheWrapper.js";
|
|
7
7
|
|
|
8
|
-
describe(
|
|
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,
|
|
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(
|
|
32
|
-
test(
|
|
31
|
+
describe("Request Caching", () => {
|
|
32
|
+
test("should cache GET requests", async () => {
|
|
33
33
|
const mockResponse = {
|
|
34
|
-
data: { id: 1, title:
|
|
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:
|
|
43
|
-
url:
|
|
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(
|
|
61
|
+
test("should not cache non-GET requests", async () => {
|
|
62
62
|
const mockResponse = {
|
|
63
|
-
data: { id: 1, title:
|
|
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:
|
|
72
|
-
url:
|
|
71
|
+
method: "POST",
|
|
72
|
+
url: "https://example.com/wp-json/wp/v2/posts",
|
|
73
73
|
headers: {},
|
|
74
74
|
params: {},
|
|
75
|
-
data: { title:
|
|
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(
|
|
87
|
+
test("should not cache error responses", async () => {
|
|
88
88
|
const errorResponse = {
|
|
89
|
-
data: { error:
|
|
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:
|
|
98
|
-
url:
|
|
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(
|
|
110
|
+
test("should generate ETags for responses", async () => {
|
|
111
111
|
const mockResponse = {
|
|
112
|
-
data: { id: 1, title:
|
|
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:
|
|
121
|
-
url:
|
|
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[
|
|
131
|
-
expect(result.headers[
|
|
130
|
+
expect(result.headers["last-modified"]).toBeDefined();
|
|
131
|
+
expect(result.headers["cache-control"]).toBeDefined();
|
|
132
132
|
});
|
|
133
133
|
});
|
|
134
134
|
|
|
135
|
-
describe(
|
|
136
|
-
test(
|
|
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:
|
|
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:
|
|
148
|
-
url:
|
|
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(
|
|
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(
|
|
168
|
+
test("should invalidate by pattern", async () => {
|
|
169
169
|
// Cache multiple responses
|
|
170
170
|
const responses = [
|
|
171
|
-
{ url:
|
|
172
|
-
{ url:
|
|
173
|
-
{ url:
|
|
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:
|
|
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(
|
|
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:
|
|
200
|
-
url:
|
|
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(
|
|
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:
|
|
219
|
-
url:
|
|
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:
|
|
226
|
-
url:
|
|
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:
|
|
240
|
-
url:
|
|
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(
|
|
249
|
-
test(
|
|
250
|
-
const endpoint =
|
|
251
|
-
const data = [
|
|
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(
|
|
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 ===
|
|
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(
|
|
269
|
-
const endpoint =
|
|
270
|
-
const data = [{ id: 1, title:
|
|
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:
|
|
276
|
-
url:
|
|
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(
|
|
288
|
-
test(
|
|
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:
|
|
300
|
-
url:
|
|
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:
|
|
307
|
-
url:
|
|
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(
|
|
321
|
-
test(
|
|
323
|
+
describe("URL and Endpoint Extraction", () => {
|
|
324
|
+
test("should extract endpoint from WordPress API URLs", async () => {
|
|
322
325
|
const testCases = [
|
|
323
326
|
{
|
|
324
|
-
url:
|
|
325
|
-
expectedEndpoint:
|
|
327
|
+
url: "https://example.com/wp-json/wp/v2/posts",
|
|
328
|
+
expectedEndpoint: "posts",
|
|
326
329
|
},
|
|
327
330
|
{
|
|
328
|
-
url:
|
|
329
|
-
expectedEndpoint:
|
|
331
|
+
url: "https://example.com/wp-json/wp/v2/posts/123",
|
|
332
|
+
expectedEndpoint: "posts/123",
|
|
330
333
|
},
|
|
331
334
|
{
|
|
332
|
-
url:
|
|
333
|
-
expectedEndpoint:
|
|
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:
|
|
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
|
package/src/cache/index.ts
CHANGED
|
@@ -3,24 +3,24 @@
|
|
|
3
3
|
* Provides centralized access to all caching components
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
export { CacheManager, CachePresets } from
|
|
7
|
-
export { HttpCacheWrapper } from
|
|
8
|
-
export {
|
|
9
|
-
|
|
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
|
|
20
|
+
RequestOptions,
|
|
21
|
+
} from "./HttpCacheWrapper.js";
|
|
22
22
|
|
|
23
23
|
export type {
|
|
24
24
|
InvalidationRule,
|
|
25
|
-
InvalidationEvent
|
|
26
|
-
} from
|
|
25
|
+
InvalidationEvent,
|
|
26
|
+
} from "./CacheInvalidation.js";
|