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