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
package/src/client/api.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress API Client
|
|
3
3
|
* Handles all REST API communication with WordPress
|
|
4
|
+
*
|
|
5
|
+
* This module has been refactored to use a modular architecture with
|
|
6
|
+
* domain-specific operations extracted into separate modules under ./operations/
|
|
4
7
|
*/
|
|
5
8
|
|
|
6
9
|
// Use native fetch in Node.js 18+
|
|
7
10
|
import FormData from "form-data";
|
|
8
|
-
import {
|
|
9
|
-
import * as path from "path";
|
|
10
|
-
import { getUserAgent } from "../utils/version.js";
|
|
11
|
+
import { getUserAgent } from "@/utils/version.js";
|
|
11
12
|
import type {
|
|
12
13
|
IWordPressClient,
|
|
13
14
|
WordPressClientConfig,
|
|
@@ -16,9 +17,9 @@ import type {
|
|
|
16
17
|
HTTPMethod,
|
|
17
18
|
RequestOptions,
|
|
18
19
|
ClientStats,
|
|
19
|
-
} from "
|
|
20
|
-
import { WordPressAPIError, AuthenticationError, RateLimitError } from "
|
|
21
|
-
import { config } from "
|
|
20
|
+
} from "@/types/client.js";
|
|
21
|
+
import { WordPressAPIError, AuthenticationError, RateLimitError } from "@/types/client.js";
|
|
22
|
+
import { config } from "@/config/Config.js";
|
|
22
23
|
import type {
|
|
23
24
|
WordPressPost,
|
|
24
25
|
WordPressPage,
|
|
@@ -49,9 +50,18 @@ import type {
|
|
|
49
50
|
UpdateMediaRequest,
|
|
50
51
|
WordPressSiteInfo,
|
|
51
52
|
WordPressSearchResult,
|
|
52
|
-
} from "
|
|
53
|
-
import { debug, logError, startTimer } from "
|
|
54
|
-
import type { QueuedRequest } from "
|
|
53
|
+
} from "@/types/wordpress.js";
|
|
54
|
+
import { debug, logError, startTimer } from "@/utils/debug.js";
|
|
55
|
+
import type { QueuedRequest } from "@/types/requests.js";
|
|
56
|
+
|
|
57
|
+
// Import domain-specific operations
|
|
58
|
+
import { PostsOperations } from "./operations/posts.js";
|
|
59
|
+
import { PagesOperations } from "./operations/pages.js";
|
|
60
|
+
import { MediaOperations } from "./operations/media.js";
|
|
61
|
+
import { UsersOperations } from "./operations/users.js";
|
|
62
|
+
import { CommentsOperations } from "./operations/comments.js";
|
|
63
|
+
import { TaxonomiesOperations } from "./operations/taxonomies.js";
|
|
64
|
+
import { SiteOperations } from "./operations/site.js";
|
|
55
65
|
|
|
56
66
|
/**
|
|
57
67
|
* WordPress REST API Client
|
|
@@ -68,6 +78,7 @@ import type { QueuedRequest } from "../types/requests.js";
|
|
|
68
78
|
* - Performance monitoring and request statistics
|
|
69
79
|
* - Caching support for improved performance
|
|
70
80
|
* - Multi-site configuration support
|
|
81
|
+
* - Modular architecture with domain-specific operations
|
|
71
82
|
*
|
|
72
83
|
* @example
|
|
73
84
|
* ```typescript
|
|
@@ -113,6 +124,15 @@ export class WordPressClient implements IWordPressClient {
|
|
|
113
124
|
private jwtToken: string | null = null;
|
|
114
125
|
private _stats: ClientStats;
|
|
115
126
|
|
|
127
|
+
// Domain-specific operation handlers
|
|
128
|
+
private readonly postsOps: PostsOperations;
|
|
129
|
+
private readonly pagesOps: PagesOperations;
|
|
130
|
+
private readonly mediaOps: MediaOperations;
|
|
131
|
+
private readonly usersOps: UsersOperations;
|
|
132
|
+
private readonly commentsOps: CommentsOperations;
|
|
133
|
+
private readonly taxonomiesOps: TaxonomiesOperations;
|
|
134
|
+
private readonly siteOps: SiteOperations;
|
|
135
|
+
|
|
116
136
|
/**
|
|
117
137
|
* Creates a new WordPress API client instance.
|
|
118
138
|
*
|
|
@@ -127,31 +147,6 @@ export class WordPressClient implements IWordPressClient {
|
|
|
127
147
|
* @param {boolean} [options.enableCache=true] - Whether to enable response caching
|
|
128
148
|
* @param {number} [options.cacheMaxAge=300000] - Cache max age in milliseconds (5 minutes default)
|
|
129
149
|
*
|
|
130
|
-
* @example
|
|
131
|
-
* ```typescript
|
|
132
|
-
* // Basic configuration with app password
|
|
133
|
-
* const client = new WordPressClient({
|
|
134
|
-
* baseUrl: 'https://mysite.com',
|
|
135
|
-
* auth: {
|
|
136
|
-
* method: 'app-password',
|
|
137
|
-
* username: 'admin',
|
|
138
|
-
* password: 'xxxx xxxx xxxx xxxx xxxx xxxx'
|
|
139
|
-
* }
|
|
140
|
-
* });
|
|
141
|
-
*
|
|
142
|
-
* // Configuration with environment variables
|
|
143
|
-
* // Set WORDPRESS_SITE_URL, WORDPRESS_USERNAME, WORDPRESS_APP_PASSWORD
|
|
144
|
-
* const client = new WordPressClient(); // Auto-detects from env
|
|
145
|
-
*
|
|
146
|
-
* // Custom timeout and retry settings
|
|
147
|
-
* const client = new WordPressClient({
|
|
148
|
-
* baseUrl: 'https://mysite.com',
|
|
149
|
-
* timeout: 60000, // 60 seconds
|
|
150
|
-
* maxRetries: 5, // 5 retry attempts
|
|
151
|
-
* auth: { method: 'app-password', username: 'user', password: 'pass' }
|
|
152
|
-
* });
|
|
153
|
-
* ```
|
|
154
|
-
*
|
|
155
150
|
* @throws {Error} When required configuration is missing or invalid
|
|
156
151
|
*
|
|
157
152
|
* @since 1.0.0
|
|
@@ -211,6 +206,15 @@ export class WordPressClient implements IWordPressClient {
|
|
|
211
206
|
|
|
212
207
|
// Validate configuration
|
|
213
208
|
this.validateConfig();
|
|
209
|
+
|
|
210
|
+
// Initialize domain-specific operations with this client as the base
|
|
211
|
+
this.postsOps = new PostsOperations(this);
|
|
212
|
+
this.pagesOps = new PagesOperations(this);
|
|
213
|
+
this.mediaOps = new MediaOperations(this);
|
|
214
|
+
this.usersOps = new UsersOperations(this);
|
|
215
|
+
this.commentsOps = new CommentsOperations(this);
|
|
216
|
+
this.taxonomiesOps = new TaxonomiesOperations(this);
|
|
217
|
+
this.siteOps = new SiteOperations(this);
|
|
214
218
|
}
|
|
215
219
|
|
|
216
220
|
get config(): WordPressClientConfig {
|
|
@@ -691,7 +695,7 @@ export class WordPressClient implements IWordPressClient {
|
|
|
691
695
|
return false;
|
|
692
696
|
}
|
|
693
697
|
|
|
694
|
-
if (typeof data === "object" && data
|
|
698
|
+
if (typeof data === "object" && data && "pipe" in (data as Record<string, unknown>)) {
|
|
695
699
|
const potentialStream = (data as Record<string, unknown>).pipe;
|
|
696
700
|
if (typeof potentialStream === "function") {
|
|
697
701
|
return false;
|
|
@@ -777,7 +781,10 @@ export class WordPressClient implements IWordPressClient {
|
|
|
777
781
|
fallbackController.abort();
|
|
778
782
|
}, requestTimeout);
|
|
779
783
|
|
|
780
|
-
const fallbackOptions = {
|
|
784
|
+
const fallbackOptions = {
|
|
785
|
+
...fetchOptions,
|
|
786
|
+
signal: fallbackController.signal,
|
|
787
|
+
};
|
|
781
788
|
const fallbackResponse = await fetch(fallbackUrl, fallbackOptions);
|
|
782
789
|
clearTimeout(fallbackTimeoutId);
|
|
783
790
|
|
|
@@ -842,7 +849,10 @@ export class WordPressClient implements IWordPressClient {
|
|
|
842
849
|
this._stats.lastRequestTime = Date.now();
|
|
843
850
|
}
|
|
844
851
|
|
|
845
|
-
//
|
|
852
|
+
// ============================================================================
|
|
853
|
+
// HTTP Method Helpers
|
|
854
|
+
// ============================================================================
|
|
855
|
+
|
|
846
856
|
async get<T = unknown>(endpoint: string, options?: RequestOptions): Promise<T> {
|
|
847
857
|
return this.request<T>("GET", endpoint, null, options);
|
|
848
858
|
}
|
|
@@ -863,100 +873,76 @@ export class WordPressClient implements IWordPressClient {
|
|
|
863
873
|
return this.request<T>("DELETE", endpoint, null, options);
|
|
864
874
|
}
|
|
865
875
|
|
|
866
|
-
//
|
|
876
|
+
// ============================================================================
|
|
877
|
+
// Posts Operations (delegated to PostsOperations)
|
|
878
|
+
// ============================================================================
|
|
867
879
|
|
|
868
|
-
// Posts
|
|
869
880
|
async getPosts(params?: PostQueryParams): Promise<WordPressPost[]> {
|
|
870
|
-
|
|
871
|
-
return this.get<WordPressPost[]>(`posts${queryString}`);
|
|
881
|
+
return this.postsOps.getPosts(params);
|
|
872
882
|
}
|
|
873
883
|
|
|
874
884
|
async getPost(id: number, context: "view" | "embed" | "edit" = "view"): Promise<WordPressPost> {
|
|
875
|
-
return this.
|
|
885
|
+
return this.postsOps.getPost(id, context);
|
|
876
886
|
}
|
|
877
887
|
|
|
878
888
|
async createPost(data: CreatePostRequest): Promise<WordPressPost> {
|
|
879
|
-
return this.
|
|
889
|
+
return this.postsOps.createPost(data);
|
|
880
890
|
}
|
|
881
891
|
|
|
882
892
|
async updatePost(data: UpdatePostRequest): Promise<WordPressPost> {
|
|
883
|
-
|
|
884
|
-
return this.put<WordPressPost>(`posts/${id}`, updateData);
|
|
893
|
+
return this.postsOps.updatePost(data);
|
|
885
894
|
}
|
|
886
895
|
|
|
887
896
|
async deletePost(id: number, force = false): Promise<{ deleted: boolean; previous?: WordPressPost }> {
|
|
888
|
-
return this.
|
|
897
|
+
return this.postsOps.deletePost(id, force);
|
|
889
898
|
}
|
|
890
899
|
|
|
891
900
|
async getPostRevisions(id: number): Promise<WordPressPost[]> {
|
|
892
|
-
return this.
|
|
901
|
+
return this.postsOps.getPostRevisions(id);
|
|
893
902
|
}
|
|
894
903
|
|
|
895
|
-
//
|
|
904
|
+
// ============================================================================
|
|
905
|
+
// Pages Operations (delegated to PagesOperations)
|
|
906
|
+
// ============================================================================
|
|
907
|
+
|
|
896
908
|
async getPages(params?: PostQueryParams): Promise<WordPressPage[]> {
|
|
897
|
-
|
|
898
|
-
? Object.fromEntries(Object.entries(params).map(([k, v]) => [k, String(v)]))
|
|
899
|
-
: undefined;
|
|
900
|
-
const queryString = normalizedParams ? "?" + new URLSearchParams(normalizedParams).toString() : "";
|
|
901
|
-
return this.get<WordPressPage[]>(`pages${queryString}`);
|
|
909
|
+
return this.pagesOps.getPages(params);
|
|
902
910
|
}
|
|
903
911
|
|
|
904
912
|
async getPage(id: number, context: "view" | "embed" | "edit" = "view"): Promise<WordPressPage> {
|
|
905
|
-
return this.
|
|
913
|
+
return this.pagesOps.getPage(id, context);
|
|
906
914
|
}
|
|
907
915
|
|
|
908
916
|
async createPage(data: CreatePageRequest): Promise<WordPressPage> {
|
|
909
|
-
return this.
|
|
917
|
+
return this.pagesOps.createPage(data);
|
|
910
918
|
}
|
|
911
919
|
|
|
912
920
|
async updatePage(data: UpdatePageRequest): Promise<WordPressPage> {
|
|
913
|
-
|
|
914
|
-
return this.put<WordPressPage>(`pages/${id}`, updateData);
|
|
921
|
+
return this.pagesOps.updatePage(data);
|
|
915
922
|
}
|
|
916
923
|
|
|
917
924
|
async deletePage(id: number, force = false): Promise<{ deleted: boolean; previous?: WordPressPage }> {
|
|
918
|
-
return this.
|
|
925
|
+
return this.pagesOps.deletePage(id, force);
|
|
919
926
|
}
|
|
920
927
|
|
|
921
928
|
async getPageRevisions(id: number): Promise<WordPressPage[]> {
|
|
922
|
-
return this.
|
|
929
|
+
return this.pagesOps.getPageRevisions(id);
|
|
923
930
|
}
|
|
924
931
|
|
|
925
|
-
//
|
|
932
|
+
// ============================================================================
|
|
933
|
+
// Media Operations (delegated to MediaOperations)
|
|
934
|
+
// ============================================================================
|
|
935
|
+
|
|
926
936
|
async getMedia(params?: MediaQueryParams): Promise<WordPressMedia[]> {
|
|
927
|
-
|
|
928
|
-
? Object.fromEntries(Object.entries(params).map(([k, v]) => [k, String(v)]))
|
|
929
|
-
: undefined;
|
|
930
|
-
const queryString = normalizedParams ? "?" + new URLSearchParams(normalizedParams).toString() : "";
|
|
931
|
-
return this.get<WordPressMedia[]>(`media${queryString}`);
|
|
937
|
+
return this.mediaOps.getMedia(params);
|
|
932
938
|
}
|
|
933
939
|
|
|
934
940
|
async getMediaItem(id: number, context: "view" | "embed" | "edit" = "view"): Promise<WordPressMedia> {
|
|
935
|
-
return this.
|
|
941
|
+
return this.mediaOps.getMediaItem(id, context);
|
|
936
942
|
}
|
|
937
943
|
|
|
938
944
|
async uploadMedia(data: UploadMediaRequest): Promise<WordPressMedia> {
|
|
939
|
-
|
|
940
|
-
await fsPromises.access(data.file_path);
|
|
941
|
-
} catch {
|
|
942
|
-
throw new Error(`File not found: ${data.file_path}`);
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
const stats = await fsPromises.stat(data.file_path);
|
|
946
|
-
const filename = data.title || path.basename(data.file_path);
|
|
947
|
-
const fileBuffer = await fsPromises.readFile(data.file_path);
|
|
948
|
-
|
|
949
|
-
// Check if file is too large (WordPress default is 2MB for most installs)
|
|
950
|
-
const maxSize = 10 * 1024 * 1024; // 10MB reasonable limit
|
|
951
|
-
if (stats.size > maxSize) {
|
|
952
|
-
throw new Error(
|
|
953
|
-
`File too large: ${(stats.size / 1024 / 1024).toFixed(2)}MB. Maximum allowed: ${maxSize / 1024 / 1024}MB`,
|
|
954
|
-
);
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
debug.log(`Uploading file: ${filename} (${(stats.size / 1024).toFixed(2)}KB)`);
|
|
958
|
-
|
|
959
|
-
return this.uploadFile(fileBuffer, filename, this.getMimeType(data.file_path), data);
|
|
945
|
+
return this.mediaOps.uploadMedia(data);
|
|
960
946
|
}
|
|
961
947
|
|
|
962
948
|
async uploadFile(
|
|
@@ -966,185 +952,143 @@ export class WordPressClient implements IWordPressClient {
|
|
|
966
952
|
meta: Partial<UploadMediaRequest> = {},
|
|
967
953
|
options?: RequestOptions,
|
|
968
954
|
): Promise<WordPressMedia> {
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
// Use FormData but with correct configuration for node-fetch
|
|
972
|
-
const formData = new FormData();
|
|
973
|
-
formData.setMaxListeners(20);
|
|
974
|
-
|
|
975
|
-
// Add file with correct options
|
|
976
|
-
formData.append("file", fileData, {
|
|
977
|
-
filename,
|
|
978
|
-
contentType: mimeType,
|
|
979
|
-
});
|
|
980
|
-
|
|
981
|
-
// Add metadata
|
|
982
|
-
if (meta.title) formData.append("title", meta.title);
|
|
983
|
-
if (meta.alt_text) formData.append("alt_text", meta.alt_text);
|
|
984
|
-
if (meta.caption) formData.append("caption", meta.caption);
|
|
985
|
-
if (meta.description) formData.append("description", meta.description);
|
|
986
|
-
if (meta.post) formData.append("post", meta.post.toString());
|
|
987
|
-
|
|
988
|
-
// Use longer timeout for file uploads
|
|
989
|
-
const uploadTimeout = options?.timeout !== undefined ? options.timeout : 600000; // 10 minutes default
|
|
990
|
-
const uploadOptions: RequestOptions = {
|
|
991
|
-
...options,
|
|
992
|
-
timeout: uploadTimeout,
|
|
993
|
-
};
|
|
994
|
-
|
|
995
|
-
debug.log(`Upload prepared with FormData, timeout: ${uploadTimeout}ms`);
|
|
996
|
-
|
|
997
|
-
// Use the regular post method which handles FormData correctly
|
|
998
|
-
return this.post<WordPressMedia>("media", formData, uploadOptions);
|
|
955
|
+
return this.mediaOps.uploadFile(fileData, filename, mimeType, meta, options);
|
|
999
956
|
}
|
|
1000
957
|
|
|
1001
958
|
async updateMedia(data: UpdateMediaRequest): Promise<WordPressMedia> {
|
|
1002
|
-
|
|
1003
|
-
return this.put<WordPressMedia>(`media/${id}`, updateData);
|
|
959
|
+
return this.mediaOps.updateMedia(data);
|
|
1004
960
|
}
|
|
1005
961
|
|
|
1006
962
|
async deleteMedia(id: number, force = false): Promise<{ deleted: boolean; previous?: WordPressMedia }> {
|
|
1007
|
-
return this.
|
|
963
|
+
return this.mediaOps.deleteMedia(id, force);
|
|
1008
964
|
}
|
|
1009
965
|
|
|
1010
|
-
//
|
|
966
|
+
// ============================================================================
|
|
967
|
+
// Users Operations (delegated to UsersOperations)
|
|
968
|
+
// ============================================================================
|
|
969
|
+
|
|
1011
970
|
async getUsers(params?: UserQueryParams): Promise<WordPressUser[]> {
|
|
1012
|
-
|
|
1013
|
-
? Object.fromEntries(Object.entries(params).map(([k, v]) => [k, String(v)]))
|
|
1014
|
-
: undefined;
|
|
1015
|
-
const queryString = normalizedParams ? "?" + new URLSearchParams(normalizedParams).toString() : "";
|
|
1016
|
-
return this.get<WordPressUser[]>(`users${queryString}`);
|
|
971
|
+
return this.usersOps.getUsers(params);
|
|
1017
972
|
}
|
|
1018
973
|
|
|
1019
974
|
async getUser(id: number | "me", context: "view" | "embed" | "edit" = "view"): Promise<WordPressUser> {
|
|
1020
|
-
return this.
|
|
975
|
+
return this.usersOps.getUser(id, context);
|
|
1021
976
|
}
|
|
1022
977
|
|
|
1023
978
|
async createUser(data: CreateUserRequest): Promise<WordPressUser> {
|
|
1024
|
-
return this.
|
|
979
|
+
return this.usersOps.createUser(data);
|
|
1025
980
|
}
|
|
1026
981
|
|
|
1027
982
|
async updateUser(data: UpdateUserRequest): Promise<WordPressUser> {
|
|
1028
|
-
|
|
1029
|
-
return this.put<WordPressUser>(`users/${id}`, updateData);
|
|
983
|
+
return this.usersOps.updateUser(data);
|
|
1030
984
|
}
|
|
1031
985
|
|
|
1032
986
|
async deleteUser(id: number, reassign?: number): Promise<{ deleted: boolean; previous?: WordPressUser }> {
|
|
1033
|
-
|
|
1034
|
-
return this.delete(`users/${id}${params}`);
|
|
987
|
+
return this.usersOps.deleteUser(id, reassign);
|
|
1035
988
|
}
|
|
1036
989
|
|
|
1037
990
|
async getCurrentUser(): Promise<WordPressUser> {
|
|
1038
|
-
return this.
|
|
991
|
+
return this.usersOps.getCurrentUser();
|
|
1039
992
|
}
|
|
1040
993
|
|
|
1041
|
-
//
|
|
994
|
+
// ============================================================================
|
|
995
|
+
// Comments Operations (delegated to CommentsOperations)
|
|
996
|
+
// ============================================================================
|
|
997
|
+
|
|
1042
998
|
async getComments(params?: CommentQueryParams): Promise<WordPressComment[]> {
|
|
1043
|
-
|
|
1044
|
-
? Object.fromEntries(Object.entries(params).map(([k, v]) => [k, String(v)]))
|
|
1045
|
-
: undefined;
|
|
1046
|
-
const queryString = normalizedParams ? "?" + new URLSearchParams(normalizedParams).toString() : "";
|
|
1047
|
-
return this.get<WordPressComment[]>(`comments${queryString}`);
|
|
999
|
+
return this.commentsOps.getComments(params);
|
|
1048
1000
|
}
|
|
1049
1001
|
|
|
1050
1002
|
async getComment(id: number, context: "view" | "embed" | "edit" = "view"): Promise<WordPressComment> {
|
|
1051
|
-
return this.
|
|
1003
|
+
return this.commentsOps.getComment(id, context);
|
|
1052
1004
|
}
|
|
1053
1005
|
|
|
1054
1006
|
async createComment(data: CreateCommentRequest): Promise<WordPressComment> {
|
|
1055
|
-
return this.
|
|
1007
|
+
return this.commentsOps.createComment(data);
|
|
1056
1008
|
}
|
|
1057
1009
|
|
|
1058
1010
|
async updateComment(data: UpdateCommentRequest): Promise<WordPressComment> {
|
|
1059
|
-
|
|
1060
|
-
return this.put<WordPressComment>(`comments/${id}`, updateData);
|
|
1011
|
+
return this.commentsOps.updateComment(data);
|
|
1061
1012
|
}
|
|
1062
1013
|
|
|
1063
1014
|
async deleteComment(id: number, force = false): Promise<{ deleted: boolean; previous?: WordPressComment }> {
|
|
1064
|
-
return this.
|
|
1015
|
+
return this.commentsOps.deleteComment(id, force);
|
|
1065
1016
|
}
|
|
1066
1017
|
|
|
1067
1018
|
async approveComment(id: number): Promise<WordPressComment> {
|
|
1068
|
-
return this.
|
|
1019
|
+
return this.commentsOps.approveComment(id);
|
|
1069
1020
|
}
|
|
1070
1021
|
|
|
1071
1022
|
async rejectComment(id: number): Promise<WordPressComment> {
|
|
1072
|
-
return this.
|
|
1073
|
-
status: "unapproved",
|
|
1074
|
-
});
|
|
1023
|
+
return this.commentsOps.rejectComment(id);
|
|
1075
1024
|
}
|
|
1076
1025
|
|
|
1077
1026
|
async spamComment(id: number): Promise<WordPressComment> {
|
|
1078
|
-
return this.
|
|
1027
|
+
return this.commentsOps.spamComment(id);
|
|
1079
1028
|
}
|
|
1080
1029
|
|
|
1081
|
-
//
|
|
1030
|
+
// ============================================================================
|
|
1031
|
+
// Taxonomies Operations (delegated to TaxonomiesOperations)
|
|
1032
|
+
// ============================================================================
|
|
1033
|
+
|
|
1082
1034
|
async getCategories(params?: Record<string, string | number | boolean>): Promise<WordPressCategory[]> {
|
|
1083
|
-
|
|
1084
|
-
? Object.fromEntries(Object.entries(params).map(([k, v]) => [k, String(v)]))
|
|
1085
|
-
: undefined;
|
|
1086
|
-
const queryString = normalizedParams ? "?" + new URLSearchParams(normalizedParams).toString() : "";
|
|
1087
|
-
return this.get<WordPressCategory[]>(`categories${queryString}`);
|
|
1035
|
+
return this.taxonomiesOps.getCategories(params);
|
|
1088
1036
|
}
|
|
1089
1037
|
|
|
1090
1038
|
async getCategory(id: number): Promise<WordPressCategory> {
|
|
1091
|
-
return this.
|
|
1039
|
+
return this.taxonomiesOps.getCategory(id);
|
|
1092
1040
|
}
|
|
1093
1041
|
|
|
1094
1042
|
async createCategory(data: CreateCategoryRequest): Promise<WordPressCategory> {
|
|
1095
|
-
return this.
|
|
1043
|
+
return this.taxonomiesOps.createCategory(data);
|
|
1096
1044
|
}
|
|
1097
1045
|
|
|
1098
1046
|
async updateCategory(data: UpdateCategoryRequest): Promise<WordPressCategory> {
|
|
1099
|
-
|
|
1100
|
-
return this.put<WordPressCategory>(`categories/${id}`, updateData);
|
|
1047
|
+
return this.taxonomiesOps.updateCategory(data);
|
|
1101
1048
|
}
|
|
1102
1049
|
|
|
1103
1050
|
async deleteCategory(id: number, force = false): Promise<{ deleted: boolean; previous?: WordPressCategory }> {
|
|
1104
|
-
return this.
|
|
1051
|
+
return this.taxonomiesOps.deleteCategory(id, force);
|
|
1105
1052
|
}
|
|
1106
1053
|
|
|
1107
1054
|
async getTags(params?: Record<string, string | number | boolean>): Promise<WordPressTag[]> {
|
|
1108
|
-
|
|
1109
|
-
? Object.fromEntries(Object.entries(params).map(([k, v]) => [k, String(v)]))
|
|
1110
|
-
: undefined;
|
|
1111
|
-
const queryString = normalizedParams ? "?" + new URLSearchParams(normalizedParams).toString() : "";
|
|
1112
|
-
return this.get<WordPressTag[]>(`tags${queryString}`);
|
|
1055
|
+
return this.taxonomiesOps.getTags(params);
|
|
1113
1056
|
}
|
|
1114
1057
|
|
|
1115
1058
|
async getTag(id: number): Promise<WordPressTag> {
|
|
1116
|
-
return this.
|
|
1059
|
+
return this.taxonomiesOps.getTag(id);
|
|
1117
1060
|
}
|
|
1118
1061
|
|
|
1119
1062
|
async createTag(data: CreateTagRequest): Promise<WordPressTag> {
|
|
1120
|
-
return this.
|
|
1063
|
+
return this.taxonomiesOps.createTag(data);
|
|
1121
1064
|
}
|
|
1122
1065
|
|
|
1123
1066
|
async updateTag(data: UpdateTagRequest): Promise<WordPressTag> {
|
|
1124
|
-
|
|
1125
|
-
return this.put<WordPressTag>(`tags/${id}`, updateData);
|
|
1067
|
+
return this.taxonomiesOps.updateTag(data);
|
|
1126
1068
|
}
|
|
1127
1069
|
|
|
1128
1070
|
async deleteTag(id: number, force = false): Promise<{ deleted: boolean; previous?: WordPressTag }> {
|
|
1129
|
-
return this.
|
|
1071
|
+
return this.taxonomiesOps.deleteTag(id, force);
|
|
1130
1072
|
}
|
|
1131
1073
|
|
|
1132
|
-
//
|
|
1074
|
+
// ============================================================================
|
|
1075
|
+
// Site Operations (delegated to SiteOperations)
|
|
1076
|
+
// ============================================================================
|
|
1077
|
+
|
|
1133
1078
|
async getSiteSettings(): Promise<WordPressSiteSettings> {
|
|
1134
|
-
return this.
|
|
1079
|
+
return this.siteOps.getSiteSettings();
|
|
1135
1080
|
}
|
|
1136
1081
|
|
|
1137
1082
|
async updateSiteSettings(settings: Partial<WordPressSiteSettings>): Promise<WordPressSiteSettings> {
|
|
1138
|
-
return this.
|
|
1083
|
+
return this.siteOps.updateSiteSettings(settings);
|
|
1139
1084
|
}
|
|
1140
1085
|
|
|
1141
1086
|
async getSiteInfo(): Promise<WordPressSiteInfo> {
|
|
1142
|
-
return this.
|
|
1087
|
+
return this.siteOps.getSiteInfo();
|
|
1143
1088
|
}
|
|
1144
1089
|
|
|
1145
|
-
// Application Passwords
|
|
1146
1090
|
async getApplicationPasswords(userId: number | "me" = "me"): Promise<WordPressApplicationPassword[]> {
|
|
1147
|
-
return this.
|
|
1091
|
+
return this.siteOps.getApplicationPasswords(userId);
|
|
1148
1092
|
}
|
|
1149
1093
|
|
|
1150
1094
|
async createApplicationPassword(
|
|
@@ -1152,38 +1096,29 @@ export class WordPressClient implements IWordPressClient {
|
|
|
1152
1096
|
name: string,
|
|
1153
1097
|
appId?: string,
|
|
1154
1098
|
): Promise<WordPressApplicationPassword> {
|
|
1155
|
-
|
|
1156
|
-
if (appId) data.app_id = appId;
|
|
1157
|
-
return this.post<WordPressApplicationPassword>(`users/${userId}/application-passwords`, data);
|
|
1099
|
+
return this.siteOps.createApplicationPassword(userId, name, appId);
|
|
1158
1100
|
}
|
|
1159
1101
|
|
|
1160
1102
|
async deleteApplicationPassword(userId: number | "me", uuid: string): Promise<{ deleted: boolean }> {
|
|
1161
|
-
return this.
|
|
1103
|
+
return this.siteOps.deleteApplicationPassword(userId, uuid);
|
|
1162
1104
|
}
|
|
1163
1105
|
|
|
1164
|
-
// Search
|
|
1165
1106
|
async search(query: string, types?: string[], subtype?: string): Promise<WordPressSearchResult[]> {
|
|
1166
|
-
|
|
1167
|
-
if (types) params.append("type", types.join(","));
|
|
1168
|
-
if (subtype) params.append("subtype", subtype);
|
|
1169
|
-
|
|
1170
|
-
return this.get<WordPressSearchResult[]>(`search?${params.toString()}`);
|
|
1107
|
+
return this.siteOps.search(query, types, subtype);
|
|
1171
1108
|
}
|
|
1172
1109
|
|
|
1173
|
-
// Utility Methods
|
|
1174
1110
|
async ping(): Promise<boolean> {
|
|
1175
|
-
|
|
1176
|
-
await this.get("");
|
|
1177
|
-
return true;
|
|
1178
|
-
} catch {
|
|
1179
|
-
return false;
|
|
1180
|
-
}
|
|
1111
|
+
return this.siteOps.ping();
|
|
1181
1112
|
}
|
|
1182
1113
|
|
|
1183
1114
|
async getServerInfo(): Promise<Record<string, unknown>> {
|
|
1184
|
-
return this.
|
|
1115
|
+
return this.siteOps.getServerInfo();
|
|
1185
1116
|
}
|
|
1186
1117
|
|
|
1118
|
+
// ============================================================================
|
|
1119
|
+
// Utility Methods
|
|
1120
|
+
// ============================================================================
|
|
1121
|
+
|
|
1187
1122
|
validateEndpoint(endpoint: string): boolean {
|
|
1188
1123
|
return /^[a-zA-Z0-9\/\-_]+$/.test(endpoint);
|
|
1189
1124
|
}
|
|
@@ -1197,25 +1132,4 @@ export class WordPressClient implements IWordPressClient {
|
|
|
1197
1132
|
}
|
|
1198
1133
|
return url;
|
|
1199
1134
|
}
|
|
1200
|
-
|
|
1201
|
-
private getMimeType(filePath: string): string {
|
|
1202
|
-
const ext = path.extname(filePath).toLowerCase();
|
|
1203
|
-
const mimeTypes: Record<string, string> = {
|
|
1204
|
-
".jpg": "image/jpeg",
|
|
1205
|
-
".jpeg": "image/jpeg",
|
|
1206
|
-
".png": "image/png",
|
|
1207
|
-
".gif": "image/gif",
|
|
1208
|
-
".webp": "image/webp",
|
|
1209
|
-
".svg": "image/svg+xml",
|
|
1210
|
-
".pdf": "application/pdf",
|
|
1211
|
-
".doc": "application/msword",
|
|
1212
|
-
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
1213
|
-
".txt": "text/plain",
|
|
1214
|
-
".mp4": "video/mp4",
|
|
1215
|
-
".mp3": "audio/mpeg",
|
|
1216
|
-
".wav": "audio/wav",
|
|
1217
|
-
};
|
|
1218
|
-
|
|
1219
|
-
return mimeTypes[ext] || "application/octet-stream";
|
|
1220
|
-
}
|
|
1221
1135
|
}
|
package/src/client/auth.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Manages different authentication methods for WordPress REST API
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { logger } from "
|
|
6
|
+
import { logger } from "@/utils/debug.js";
|
|
7
7
|
import { URL } from "url";
|
|
8
8
|
import type {
|
|
9
9
|
IAuthProvider,
|
|
@@ -11,8 +11,8 @@ import type {
|
|
|
11
11
|
AuthMethod,
|
|
12
12
|
AuthConfig,
|
|
13
13
|
AuthenticationError as _AuthenticationError,
|
|
14
|
-
} from "
|
|
15
|
-
import type { WordPressUser } from "
|
|
14
|
+
} from "@/types/client.js";
|
|
15
|
+
import type { WordPressUser } from "@/types/wordpress.js";
|
|
16
16
|
|
|
17
17
|
export class WordPressAuth {
|
|
18
18
|
private client: IWordPressClient;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Handles all authentication methods for WordPress REST API
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type { WordPressClient } from "
|
|
6
|
+
import type { WordPressClient } from "@/client/api.js";
|
|
7
7
|
import type { AuthConfig, AuthMethod } from "@/types/client.js";
|
|
8
8
|
import { AuthenticationError } from "@/types/client.js";
|
|
9
9
|
import { LoggerFactory } from "@/utils/logger.js";
|
|
@@ -130,15 +130,14 @@ export class RequestManager extends BaseManager {
|
|
|
130
130
|
if (data && method !== "GET") {
|
|
131
131
|
if (
|
|
132
132
|
data instanceof FormData ||
|
|
133
|
-
(typeof data === "object" &&
|
|
133
|
+
(typeof data === "object" &&
|
|
134
|
+
"append" in data &&
|
|
135
|
+
typeof (data as Record<string, unknown>).append === "function")
|
|
134
136
|
) {
|
|
135
137
|
// For FormData, don't set Content-Type (let fetch set it with boundary)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
"Content-Type" in fetchOptions.headers
|
|
140
|
-
) {
|
|
141
|
-
delete (fetchOptions.headers as Record<string, string>)["Content-Type"];
|
|
138
|
+
const headers = fetchOptions.headers as Record<string, string>;
|
|
139
|
+
if ("Content-Type" in headers) {
|
|
140
|
+
delete headers["Content-Type"];
|
|
142
141
|
}
|
|
143
142
|
fetchOptions.body = data as FormData;
|
|
144
143
|
} else if (Buffer.isBuffer(data)) {
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { WordPressClientConfig, HTTPMethod } from "@/types/client.js";
|
|
7
|
-
import { RequestManager } from "
|
|
8
|
-
import { AuthenticationManager } from "
|
|
9
|
-
import { ComposedRequestManager } from "
|
|
10
|
-
import { ComposedAuthenticationManager } from "
|
|
7
|
+
import { RequestManager } from "@/client/managers/RequestManager.js";
|
|
8
|
+
import { AuthenticationManager } from "@/client/managers/AuthenticationManager.js";
|
|
9
|
+
import { ComposedRequestManager } from "@/client/managers/ComposedRequestManager.js";
|
|
10
|
+
import { ComposedAuthenticationManager } from "@/client/managers/ComposedAuthenticationManager.js";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Adapter that wraps composed managers to provide the same interface as inheritance-based ones
|