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
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
* Extends the base WordPress client with intelligent caching capabilities and performance monitoring
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { WordPressClient } from
|
|
7
|
-
import { CacheManager } from
|
|
8
|
-
import { HttpCacheWrapper } from
|
|
9
|
-
import { CacheInvalidation } from
|
|
10
|
-
import { SecurityConfig } from
|
|
6
|
+
import { WordPressClient } from "./api.js";
|
|
7
|
+
import { CacheManager } from "../cache/CacheManager.js";
|
|
8
|
+
import { HttpCacheWrapper } from "../cache/HttpCacheWrapper.js";
|
|
9
|
+
import { CacheInvalidation } from "../cache/CacheInvalidation.js";
|
|
10
|
+
import { SecurityConfig } from "../security/SecurityConfig.js";
|
|
11
11
|
import type {
|
|
12
12
|
WordPressClientConfig,
|
|
13
13
|
HTTPMethod,
|
|
14
|
-
RequestOptions
|
|
15
|
-
} from
|
|
14
|
+
RequestOptions,
|
|
15
|
+
} from "../types/client.js";
|
|
16
16
|
import type {
|
|
17
17
|
WordPressPost,
|
|
18
18
|
WordPressUser,
|
|
@@ -21,8 +21,8 @@ import type {
|
|
|
21
21
|
WordPressSiteSettings,
|
|
22
22
|
PostQueryParams,
|
|
23
23
|
CreatePostRequest,
|
|
24
|
-
UpdatePostRequest
|
|
25
|
-
} from
|
|
24
|
+
UpdatePostRequest,
|
|
25
|
+
} from "../types/wordpress.js";
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* WordPress client with intelligent caching
|
|
@@ -33,17 +33,17 @@ export class CachedWordPressClient extends WordPressClient {
|
|
|
33
33
|
private cacheInvalidation: CacheInvalidation;
|
|
34
34
|
private siteId: string;
|
|
35
35
|
|
|
36
|
-
constructor(config: WordPressClientConfig, siteId: string =
|
|
36
|
+
constructor(config: WordPressClientConfig, siteId: string = "default") {
|
|
37
37
|
super(config);
|
|
38
38
|
this.siteId = siteId;
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
// Initialize caching system
|
|
41
41
|
this.cacheManager = new CacheManager({
|
|
42
42
|
maxSize: SecurityConfig.cache.maxSize,
|
|
43
43
|
defaultTTL: SecurityConfig.cache.defaultTTL,
|
|
44
44
|
enableLRU: SecurityConfig.cache.enableLRU,
|
|
45
45
|
enableStats: SecurityConfig.cache.enableStats,
|
|
46
|
-
sitePrefix: siteId
|
|
46
|
+
sitePrefix: siteId,
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
this.httpCache = new HttpCacheWrapper(this.cacheManager, siteId);
|
|
@@ -57,44 +57,44 @@ export class CachedWordPressClient extends WordPressClient {
|
|
|
57
57
|
method: HTTPMethod,
|
|
58
58
|
endpoint: string,
|
|
59
59
|
data: any = null,
|
|
60
|
-
options: RequestOptions = {}
|
|
60
|
+
options: RequestOptions = {},
|
|
61
61
|
): Promise<T> {
|
|
62
62
|
// Only cache GET requests
|
|
63
|
-
if (method.toUpperCase() !==
|
|
63
|
+
if (method.toUpperCase() !== "GET" || !SecurityConfig.cache.enabled) {
|
|
64
64
|
const response = await super.request<T>(method, endpoint, data, options);
|
|
65
|
-
|
|
65
|
+
|
|
66
66
|
// Trigger cache invalidation for write operations
|
|
67
|
-
if ([
|
|
67
|
+
if (["POST", "PUT", "PATCH", "DELETE"].includes(method.toUpperCase())) {
|
|
68
68
|
await this.handleCacheInvalidation(method, endpoint, data);
|
|
69
69
|
}
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
return response;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
// Use cached request for GET operations
|
|
75
75
|
const requestFn = () => super.request<T>(method, endpoint, data, options);
|
|
76
|
-
|
|
76
|
+
|
|
77
77
|
const requestOptions = {
|
|
78
78
|
method,
|
|
79
79
|
url: `${this.config.baseUrl}/wp-json/wp/v2/${endpoint}`,
|
|
80
80
|
headers: {},
|
|
81
81
|
params: {},
|
|
82
|
-
data
|
|
82
|
+
data,
|
|
83
83
|
};
|
|
84
84
|
|
|
85
85
|
const cacheOptions = this.getCacheOptions(endpoint);
|
|
86
|
-
|
|
86
|
+
|
|
87
87
|
const response = await this.httpCache.request(
|
|
88
88
|
async () => {
|
|
89
89
|
const result = await requestFn();
|
|
90
90
|
return {
|
|
91
91
|
data: result,
|
|
92
92
|
status: 200,
|
|
93
|
-
headers: {}
|
|
93
|
+
headers: {},
|
|
94
94
|
};
|
|
95
95
|
},
|
|
96
96
|
requestOptions,
|
|
97
|
-
cacheOptions
|
|
97
|
+
cacheOptions,
|
|
98
98
|
);
|
|
99
99
|
|
|
100
100
|
return response.data;
|
|
@@ -108,14 +108,16 @@ export class CachedWordPressClient extends WordPressClient {
|
|
|
108
108
|
* Get posts with intelligent caching
|
|
109
109
|
*/
|
|
110
110
|
async getPosts(params: PostQueryParams = {}): Promise<WordPressPost[]> {
|
|
111
|
-
return await this.request<WordPressPost[]>(
|
|
111
|
+
return await this.request<WordPressPost[]>("GET", "posts", null, {
|
|
112
|
+
params,
|
|
113
|
+
});
|
|
112
114
|
}
|
|
113
115
|
|
|
114
116
|
/**
|
|
115
117
|
* Get single post with caching
|
|
116
118
|
*/
|
|
117
119
|
async getPost(id: number): Promise<WordPressPost> {
|
|
118
|
-
return await this.request<WordPressPost>(
|
|
120
|
+
return await this.request<WordPressPost>("GET", `posts/${id}`);
|
|
119
121
|
}
|
|
120
122
|
|
|
121
123
|
/**
|
|
@@ -123,10 +125,10 @@ export class CachedWordPressClient extends WordPressClient {
|
|
|
123
125
|
*/
|
|
124
126
|
async createPost(data: CreatePostRequest): Promise<WordPressPost> {
|
|
125
127
|
const post = await super.createPost(data);
|
|
126
|
-
|
|
128
|
+
|
|
127
129
|
// Invalidate related caches
|
|
128
|
-
await this.cacheInvalidation.invalidateResource(
|
|
129
|
-
|
|
130
|
+
await this.cacheInvalidation.invalidateResource("posts", post.id, "create");
|
|
131
|
+
|
|
130
132
|
return post;
|
|
131
133
|
}
|
|
132
134
|
|
|
@@ -135,22 +137,25 @@ export class CachedWordPressClient extends WordPressClient {
|
|
|
135
137
|
*/
|
|
136
138
|
async updatePost(data: UpdatePostRequest): Promise<WordPressPost> {
|
|
137
139
|
const post = await super.updatePost(data);
|
|
138
|
-
|
|
140
|
+
|
|
139
141
|
// Invalidate related caches
|
|
140
|
-
await this.cacheInvalidation.invalidateResource(
|
|
141
|
-
|
|
142
|
+
await this.cacheInvalidation.invalidateResource("posts", post.id, "update");
|
|
143
|
+
|
|
142
144
|
return post;
|
|
143
145
|
}
|
|
144
146
|
|
|
145
147
|
/**
|
|
146
148
|
* Delete post with cache invalidation
|
|
147
149
|
*/
|
|
148
|
-
async deletePost(
|
|
150
|
+
async deletePost(
|
|
151
|
+
id: number,
|
|
152
|
+
force?: boolean,
|
|
153
|
+
): Promise<{ deleted: boolean; previous?: WordPressPost }> {
|
|
149
154
|
const result = await super.deletePost(id, force);
|
|
150
|
-
|
|
155
|
+
|
|
151
156
|
// Invalidate related caches
|
|
152
|
-
await this.cacheInvalidation.invalidateResource(
|
|
153
|
-
|
|
157
|
+
await this.cacheInvalidation.invalidateResource("posts", id, "delete");
|
|
158
|
+
|
|
154
159
|
return result;
|
|
155
160
|
}
|
|
156
161
|
|
|
@@ -158,42 +163,43 @@ export class CachedWordPressClient extends WordPressClient {
|
|
|
158
163
|
* Get current user with session caching
|
|
159
164
|
*/
|
|
160
165
|
async getCurrentUser(): Promise<WordPressUser> {
|
|
161
|
-
return await this.request<WordPressUser>(
|
|
166
|
+
return await this.request<WordPressUser>("GET", "users/me");
|
|
162
167
|
}
|
|
163
168
|
|
|
164
169
|
/**
|
|
165
170
|
* Get categories with semi-static caching
|
|
166
171
|
*/
|
|
167
172
|
async getCategories(params: any = {}): Promise<WordPressCategory[]> {
|
|
168
|
-
return await this.request<WordPressCategory[]>(
|
|
173
|
+
return await this.request<WordPressCategory[]>("GET", "categories", null, {
|
|
174
|
+
params,
|
|
175
|
+
});
|
|
169
176
|
}
|
|
170
177
|
|
|
171
178
|
/**
|
|
172
179
|
* Get tags with semi-static caching
|
|
173
180
|
*/
|
|
174
181
|
async getTags(params: any = {}): Promise<WordPressTag[]> {
|
|
175
|
-
return await this.request<WordPressTag[]>(
|
|
182
|
+
return await this.request<WordPressTag[]>("GET", "tags", null, { params });
|
|
176
183
|
}
|
|
177
184
|
|
|
178
185
|
/**
|
|
179
186
|
* Get site settings with static caching
|
|
180
187
|
*/
|
|
181
188
|
async getSiteSettings(): Promise<WordPressSiteSettings> {
|
|
182
|
-
return await this.request<WordPressSiteSettings>(
|
|
189
|
+
return await this.request<WordPressSiteSettings>("GET", "settings");
|
|
183
190
|
}
|
|
184
191
|
|
|
185
192
|
/**
|
|
186
193
|
* Cache management methods
|
|
187
194
|
*/
|
|
188
195
|
|
|
189
|
-
|
|
190
196
|
/**
|
|
191
197
|
* Private helper methods
|
|
192
198
|
*/
|
|
193
199
|
|
|
194
200
|
private extractEndpoint(url: string): string {
|
|
195
201
|
// Simple approach - use the endpoint part
|
|
196
|
-
return url.replace(/^.*\/wp-json\/wp\/v2\//,
|
|
202
|
+
return url.replace(/^.*\/wp-json\/wp\/v2\//, "").split("?")[0];
|
|
197
203
|
}
|
|
198
204
|
|
|
199
205
|
/**
|
|
@@ -204,29 +210,29 @@ export class CachedWordPressClient extends WordPressClient {
|
|
|
204
210
|
if (this.isStaticEndpoint(endpoint)) {
|
|
205
211
|
return {
|
|
206
212
|
ttl: SecurityConfig.cache.ttlPresets.static,
|
|
207
|
-
cacheControl: SecurityConfig.cache.cacheHeaders.static
|
|
213
|
+
cacheControl: SecurityConfig.cache.cacheHeaders.static,
|
|
208
214
|
};
|
|
209
215
|
}
|
|
210
|
-
|
|
216
|
+
|
|
211
217
|
if (this.isSemiStaticEndpoint(endpoint)) {
|
|
212
218
|
return {
|
|
213
219
|
ttl: SecurityConfig.cache.ttlPresets.semiStatic,
|
|
214
|
-
cacheControl: SecurityConfig.cache.cacheHeaders.semiStatic
|
|
220
|
+
cacheControl: SecurityConfig.cache.cacheHeaders.semiStatic,
|
|
215
221
|
};
|
|
216
222
|
}
|
|
217
|
-
|
|
223
|
+
|
|
218
224
|
if (this.isSessionEndpoint(endpoint)) {
|
|
219
225
|
return {
|
|
220
226
|
ttl: SecurityConfig.cache.ttlPresets.session,
|
|
221
227
|
cacheControl: SecurityConfig.cache.cacheHeaders.session,
|
|
222
|
-
private: true
|
|
228
|
+
private: true,
|
|
223
229
|
};
|
|
224
230
|
}
|
|
225
|
-
|
|
231
|
+
|
|
226
232
|
// Default to dynamic caching
|
|
227
233
|
return {
|
|
228
234
|
ttl: SecurityConfig.cache.ttlPresets.dynamic,
|
|
229
|
-
cacheControl: SecurityConfig.cache.cacheHeaders.dynamic
|
|
235
|
+
cacheControl: SecurityConfig.cache.cacheHeaders.dynamic,
|
|
230
236
|
};
|
|
231
237
|
}
|
|
232
238
|
|
|
@@ -236,37 +242,41 @@ export class CachedWordPressClient extends WordPressClient {
|
|
|
236
242
|
private async handleCacheInvalidation(
|
|
237
243
|
method: string,
|
|
238
244
|
endpoint: string,
|
|
239
|
-
data: any
|
|
245
|
+
data: any,
|
|
240
246
|
): Promise<void> {
|
|
241
247
|
const resource = this.extractResourceFromEndpoint(endpoint);
|
|
242
248
|
const id = this.extractIdFromEndpoint(endpoint);
|
|
243
|
-
|
|
244
|
-
let operationType:
|
|
245
|
-
|
|
249
|
+
|
|
250
|
+
let operationType: "create" | "update" | "delete";
|
|
251
|
+
|
|
246
252
|
switch (method.toUpperCase()) {
|
|
247
|
-
case
|
|
248
|
-
operationType =
|
|
253
|
+
case "POST":
|
|
254
|
+
operationType = "create";
|
|
249
255
|
break;
|
|
250
|
-
case
|
|
251
|
-
case
|
|
252
|
-
operationType =
|
|
256
|
+
case "PUT":
|
|
257
|
+
case "PATCH":
|
|
258
|
+
operationType = "update";
|
|
253
259
|
break;
|
|
254
|
-
case
|
|
255
|
-
operationType =
|
|
260
|
+
case "DELETE":
|
|
261
|
+
operationType = "delete";
|
|
256
262
|
break;
|
|
257
263
|
default:
|
|
258
264
|
return;
|
|
259
265
|
}
|
|
260
266
|
|
|
261
|
-
await this.cacheInvalidation.invalidateResource(
|
|
267
|
+
await this.cacheInvalidation.invalidateResource(
|
|
268
|
+
resource,
|
|
269
|
+
id,
|
|
270
|
+
operationType,
|
|
271
|
+
);
|
|
262
272
|
}
|
|
263
273
|
|
|
264
274
|
/**
|
|
265
275
|
* Extract resource type from endpoint
|
|
266
276
|
*/
|
|
267
277
|
private extractResourceFromEndpoint(endpoint: string): string {
|
|
268
|
-
const parts = endpoint.split(
|
|
269
|
-
return parts[0] ||
|
|
278
|
+
const parts = endpoint.split("/");
|
|
279
|
+
return parts[0] || "unknown";
|
|
270
280
|
}
|
|
271
281
|
|
|
272
282
|
/**
|
|
@@ -281,24 +291,24 @@ export class CachedWordPressClient extends WordPressClient {
|
|
|
281
291
|
* Check if endpoint contains static data
|
|
282
292
|
*/
|
|
283
293
|
private isStaticEndpoint(endpoint: string): boolean {
|
|
284
|
-
const staticEndpoints = [
|
|
285
|
-
return staticEndpoints.some(pattern => endpoint.includes(pattern));
|
|
294
|
+
const staticEndpoints = ["settings", "types", "statuses"];
|
|
295
|
+
return staticEndpoints.some((pattern) => endpoint.includes(pattern));
|
|
286
296
|
}
|
|
287
297
|
|
|
288
298
|
/**
|
|
289
299
|
* Check if endpoint contains semi-static data
|
|
290
300
|
*/
|
|
291
301
|
private isSemiStaticEndpoint(endpoint: string): boolean {
|
|
292
|
-
const semiStaticEndpoints = [
|
|
293
|
-
return semiStaticEndpoints.some(pattern => endpoint.includes(pattern));
|
|
302
|
+
const semiStaticEndpoints = ["categories", "tags", "users", "taxonomies"];
|
|
303
|
+
return semiStaticEndpoints.some((pattern) => endpoint.includes(pattern));
|
|
294
304
|
}
|
|
295
305
|
|
|
296
306
|
/**
|
|
297
307
|
* Check if endpoint is session-related
|
|
298
308
|
*/
|
|
299
309
|
private isSessionEndpoint(endpoint: string): boolean {
|
|
300
|
-
const sessionEndpoints = [
|
|
301
|
-
return sessionEndpoints.some(pattern => endpoint.includes(pattern));
|
|
310
|
+
const sessionEndpoints = ["users/me", "application-passwords"];
|
|
311
|
+
return sessionEndpoints.some((pattern) => endpoint.includes(pattern));
|
|
302
312
|
}
|
|
303
313
|
|
|
304
314
|
/**
|
|
@@ -332,7 +342,7 @@ export class CachedWordPressClient extends WordPressClient {
|
|
|
332
342
|
* Clear cache entries matching pattern
|
|
333
343
|
*/
|
|
334
344
|
clearCachePattern(pattern: string): number {
|
|
335
|
-
const regex = new RegExp(pattern,
|
|
345
|
+
const regex = new RegExp(pattern, "i");
|
|
336
346
|
return this.cacheManager.clearPattern(regex);
|
|
337
347
|
}
|
|
338
348
|
|
|
@@ -346,11 +356,11 @@ export class CachedWordPressClient extends WordPressClient {
|
|
|
346
356
|
() => this.getCurrentUser().catch(() => null),
|
|
347
357
|
() => this.getCategories().catch(() => null),
|
|
348
358
|
() => this.getTags().catch(() => null),
|
|
349
|
-
() => this.getSiteSettings().catch(() => null)
|
|
359
|
+
() => this.getSiteSettings().catch(() => null),
|
|
350
360
|
];
|
|
351
361
|
|
|
352
362
|
// Execute warmup operations in parallel
|
|
353
|
-
await Promise.allSettled(warmupOperations.map(op => op()));
|
|
363
|
+
await Promise.allSettled(warmupOperations.map((op) => op()));
|
|
354
364
|
} catch (_error) {
|
|
355
365
|
// Ignore warmup errors - they shouldn't fail the cache warming
|
|
356
366
|
}
|
|
@@ -370,18 +380,18 @@ export class CachedWordPressClient extends WordPressClient {
|
|
|
370
380
|
const total = stats.hits + stats.misses;
|
|
371
381
|
const hitRate = total > 0 ? stats.hits / total : 0;
|
|
372
382
|
const missRate = 1 - hitRate;
|
|
373
|
-
|
|
374
|
-
let efficiency =
|
|
375
|
-
if (hitRate >= 0.9) efficiency =
|
|
376
|
-
else if (hitRate >= 0.8) efficiency =
|
|
377
|
-
else if (hitRate >= 0.6) efficiency =
|
|
383
|
+
|
|
384
|
+
let efficiency = "Poor";
|
|
385
|
+
if (hitRate >= 0.9) efficiency = "Excellent";
|
|
386
|
+
else if (hitRate >= 0.8) efficiency = "Good";
|
|
387
|
+
else if (hitRate >= 0.6) efficiency = "Fair";
|
|
378
388
|
|
|
379
389
|
return {
|
|
380
390
|
hitRate,
|
|
381
391
|
missRate,
|
|
382
392
|
efficiency,
|
|
383
393
|
memoryUsage: this.estimateMemoryUsage(),
|
|
384
|
-
totalEntries: stats.totalSize
|
|
394
|
+
totalEntries: stats.totalSize,
|
|
385
395
|
};
|
|
386
396
|
}
|
|
387
397
|
|
|
@@ -397,14 +407,14 @@ export class CachedWordPressClient extends WordPressClient {
|
|
|
397
407
|
ttlPresets: any;
|
|
398
408
|
} {
|
|
399
409
|
const stats = this.cacheManager.getStats();
|
|
400
|
-
|
|
410
|
+
|
|
401
411
|
return {
|
|
402
412
|
enabled: SecurityConfig.cache.enabled,
|
|
403
413
|
siteId: this.siteId,
|
|
404
414
|
maxSize: SecurityConfig.cache.maxSize,
|
|
405
415
|
defaultTTL: SecurityConfig.cache.defaultTTL,
|
|
406
416
|
currentSize: stats.totalSize,
|
|
407
|
-
ttlPresets: SecurityConfig.cache.ttlPresets
|
|
417
|
+
ttlPresets: SecurityConfig.cache.ttlPresets,
|
|
408
418
|
};
|
|
409
419
|
}
|
|
410
420
|
|
|
@@ -435,8 +445,8 @@ export class CachedWordPressClient extends WordPressClient {
|
|
|
435
445
|
configuration: this.getCacheInfo(),
|
|
436
446
|
siteInfo: {
|
|
437
447
|
siteId: this.siteId,
|
|
438
|
-
baseUrl: this.config.baseUrl
|
|
439
|
-
}
|
|
448
|
+
baseUrl: this.config.baseUrl,
|
|
449
|
+
},
|
|
440
450
|
};
|
|
441
451
|
}
|
|
442
452
|
}
|