mcp-wordpress 2.12.0 → 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.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 +1 -1
- 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/dist/client/api.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
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
|
import type { IWordPressClient, WordPressClientConfig, HTTPMethod, RequestOptions, ClientStats } from "../types/client.js";
|
|
6
9
|
import type { WordPressPost, WordPressPage, WordPressMedia, WordPressUser, WordPressComment, WordPressCategory, WordPressTag, WordPressSiteSettings, WordPressApplicationPassword, PostQueryParams, MediaQueryParams, UserQueryParams, CommentQueryParams, CreatePostRequest, UpdatePostRequest, CreatePageRequest, UpdatePageRequest, CreateUserRequest, UpdateUserRequest, CreateCommentRequest, UpdateCommentRequest, CreateCategoryRequest, UpdateCategoryRequest, CreateTagRequest, UpdateTagRequest, UploadMediaRequest, UpdateMediaRequest, WordPressSiteInfo, WordPressSearchResult } from "../types/wordpress.js";
|
|
@@ -19,6 +22,7 @@ import type { WordPressPost, WordPressPage, WordPressMedia, WordPressUser, WordP
|
|
|
19
22
|
* - Performance monitoring and request statistics
|
|
20
23
|
* - Caching support for improved performance
|
|
21
24
|
* - Multi-site configuration support
|
|
25
|
+
* - Modular architecture with domain-specific operations
|
|
22
26
|
*
|
|
23
27
|
* @example
|
|
24
28
|
* ```typescript
|
|
@@ -63,6 +67,13 @@ export declare class WordPressClient implements IWordPressClient {
|
|
|
63
67
|
private authenticated;
|
|
64
68
|
private jwtToken;
|
|
65
69
|
private _stats;
|
|
70
|
+
private readonly postsOps;
|
|
71
|
+
private readonly pagesOps;
|
|
72
|
+
private readonly mediaOps;
|
|
73
|
+
private readonly usersOps;
|
|
74
|
+
private readonly commentsOps;
|
|
75
|
+
private readonly taxonomiesOps;
|
|
76
|
+
private readonly siteOps;
|
|
66
77
|
/**
|
|
67
78
|
* Creates a new WordPress API client instance.
|
|
68
79
|
*
|
|
@@ -77,31 +88,6 @@ export declare class WordPressClient implements IWordPressClient {
|
|
|
77
88
|
* @param {boolean} [options.enableCache=true] - Whether to enable response caching
|
|
78
89
|
* @param {number} [options.cacheMaxAge=300000] - Cache max age in milliseconds (5 minutes default)
|
|
79
90
|
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```typescript
|
|
82
|
-
* // Basic configuration with app password
|
|
83
|
-
* const client = new WordPressClient({
|
|
84
|
-
* baseUrl: 'https://mysite.com',
|
|
85
|
-
* auth: {
|
|
86
|
-
* method: 'app-password',
|
|
87
|
-
* username: 'admin',
|
|
88
|
-
* password: 'xxxx xxxx xxxx xxxx xxxx xxxx'
|
|
89
|
-
* }
|
|
90
|
-
* });
|
|
91
|
-
*
|
|
92
|
-
* // Configuration with environment variables
|
|
93
|
-
* // Set WORDPRESS_SITE_URL, WORDPRESS_USERNAME, WORDPRESS_APP_PASSWORD
|
|
94
|
-
* const client = new WordPressClient(); // Auto-detects from env
|
|
95
|
-
*
|
|
96
|
-
* // Custom timeout and retry settings
|
|
97
|
-
* const client = new WordPressClient({
|
|
98
|
-
* baseUrl: 'https://mysite.com',
|
|
99
|
-
* timeout: 60000, // 60 seconds
|
|
100
|
-
* maxRetries: 5, // 5 retry attempts
|
|
101
|
-
* auth: { method: 'app-password', username: 'user', password: 'pass' }
|
|
102
|
-
* });
|
|
103
|
-
* ```
|
|
104
|
-
*
|
|
105
91
|
* @throws {Error} When required configuration is missing or invalid
|
|
106
92
|
*
|
|
107
93
|
* @since 1.0.0
|
|
@@ -237,6 +223,5 @@ export declare class WordPressClient implements IWordPressClient {
|
|
|
237
223
|
getServerInfo(): Promise<Record<string, unknown>>;
|
|
238
224
|
validateEndpoint(endpoint: string): boolean;
|
|
239
225
|
buildUrl(endpoint: string, params?: Record<string, unknown>): string;
|
|
240
|
-
private getMimeType;
|
|
241
226
|
}
|
|
242
227
|
//# sourceMappingURL=api.d.ts.map
|
package/dist/client/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/client/api.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/client/api.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EACV,gBAAgB,EAChB,qBAAqB,EAGrB,UAAU,EACV,cAAc,EACd,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAG3B,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,qBAAqB,EACrB,4BAA4B,EAC5B,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,sBAAsB,CAAC;AAa9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,qBAAa,eAAgB,YAAW,gBAAgB;IACtD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,eAAe,CAAa;IACpC,OAAO,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;QAAC,QAAQ,CAAC,EAAE,YAAY,CAAA;KAAE,CAAC;IAQ5F,eAAe,IAAI,OAAO,CAAC,qBAAqB,CAAC;IAIjD,kBAAkB,CAAC,QAAQ,EAAE,OAAO,CAAC,qBAAqB,CAAC,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAI5F,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAIzC,uBAAuB,CAAC,MAAM,GAAE,MAAM,GAAG,IAAW,GAAG,OAAO,CAAC,4BAA4B,EAAE,CAAC;IAI9F,yBAAyB,CAC7B,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,4BAA4B,CAAC;IAIlC,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAI7F,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAC;IAI3F,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAIxB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAQvD,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAI3C,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;CASrE"}
|
package/dist/client/api.js
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
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
|
// Use native fetch in Node.js 18+
|
|
6
9
|
import FormData from "form-data";
|
|
7
|
-
import { promises as fsPromises } from "fs";
|
|
8
|
-
import * as path from "path";
|
|
9
10
|
import { getUserAgent } from "../utils/version.js";
|
|
10
11
|
import { WordPressAPIError, AuthenticationError, RateLimitError } from "../types/client.js";
|
|
11
12
|
import { config } from "../config/Config.js";
|
|
12
13
|
import { debug, logError, startTimer } from "../utils/debug.js";
|
|
14
|
+
// Import domain-specific operations
|
|
15
|
+
import { PostsOperations } from "./operations/posts.js";
|
|
16
|
+
import { PagesOperations } from "./operations/pages.js";
|
|
17
|
+
import { MediaOperations } from "./operations/media.js";
|
|
18
|
+
import { UsersOperations } from "./operations/users.js";
|
|
19
|
+
import { CommentsOperations } from "./operations/comments.js";
|
|
20
|
+
import { TaxonomiesOperations } from "./operations/taxonomies.js";
|
|
21
|
+
import { SiteOperations } from "./operations/site.js";
|
|
13
22
|
/**
|
|
14
23
|
* WordPress REST API Client
|
|
15
24
|
*
|
|
@@ -25,6 +34,7 @@ import { debug, logError, startTimer } from "../utils/debug.js";
|
|
|
25
34
|
* - Performance monitoring and request statistics
|
|
26
35
|
* - Caching support for improved performance
|
|
27
36
|
* - Multi-site configuration support
|
|
37
|
+
* - Modular architecture with domain-specific operations
|
|
28
38
|
*
|
|
29
39
|
* @example
|
|
30
40
|
* ```typescript
|
|
@@ -69,6 +79,14 @@ export class WordPressClient {
|
|
|
69
79
|
authenticated = false;
|
|
70
80
|
jwtToken = null;
|
|
71
81
|
_stats;
|
|
82
|
+
// Domain-specific operation handlers
|
|
83
|
+
postsOps;
|
|
84
|
+
pagesOps;
|
|
85
|
+
mediaOps;
|
|
86
|
+
usersOps;
|
|
87
|
+
commentsOps;
|
|
88
|
+
taxonomiesOps;
|
|
89
|
+
siteOps;
|
|
72
90
|
/**
|
|
73
91
|
* Creates a new WordPress API client instance.
|
|
74
92
|
*
|
|
@@ -83,31 +101,6 @@ export class WordPressClient {
|
|
|
83
101
|
* @param {boolean} [options.enableCache=true] - Whether to enable response caching
|
|
84
102
|
* @param {number} [options.cacheMaxAge=300000] - Cache max age in milliseconds (5 minutes default)
|
|
85
103
|
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```typescript
|
|
88
|
-
* // Basic configuration with app password
|
|
89
|
-
* const client = new WordPressClient({
|
|
90
|
-
* baseUrl: 'https://mysite.com',
|
|
91
|
-
* auth: {
|
|
92
|
-
* method: 'app-password',
|
|
93
|
-
* username: 'admin',
|
|
94
|
-
* password: 'xxxx xxxx xxxx xxxx xxxx xxxx'
|
|
95
|
-
* }
|
|
96
|
-
* });
|
|
97
|
-
*
|
|
98
|
-
* // Configuration with environment variables
|
|
99
|
-
* // Set WORDPRESS_SITE_URL, WORDPRESS_USERNAME, WORDPRESS_APP_PASSWORD
|
|
100
|
-
* const client = new WordPressClient(); // Auto-detects from env
|
|
101
|
-
*
|
|
102
|
-
* // Custom timeout and retry settings
|
|
103
|
-
* const client = new WordPressClient({
|
|
104
|
-
* baseUrl: 'https://mysite.com',
|
|
105
|
-
* timeout: 60000, // 60 seconds
|
|
106
|
-
* maxRetries: 5, // 5 retry attempts
|
|
107
|
-
* auth: { method: 'app-password', username: 'user', password: 'pass' }
|
|
108
|
-
* });
|
|
109
|
-
* ```
|
|
110
|
-
*
|
|
111
104
|
* @throws {Error} When required configuration is missing or invalid
|
|
112
105
|
*
|
|
113
106
|
* @since 1.0.0
|
|
@@ -162,6 +155,14 @@ export class WordPressClient {
|
|
|
162
155
|
};
|
|
163
156
|
// Validate configuration
|
|
164
157
|
this.validateConfig();
|
|
158
|
+
// Initialize domain-specific operations with this client as the base
|
|
159
|
+
this.postsOps = new PostsOperations(this);
|
|
160
|
+
this.pagesOps = new PagesOperations(this);
|
|
161
|
+
this.mediaOps = new MediaOperations(this);
|
|
162
|
+
this.usersOps = new UsersOperations(this);
|
|
163
|
+
this.commentsOps = new CommentsOperations(this);
|
|
164
|
+
this.taxonomiesOps = new TaxonomiesOperations(this);
|
|
165
|
+
this.siteOps = new SiteOperations(this);
|
|
165
166
|
}
|
|
166
167
|
get config() {
|
|
167
168
|
return {
|
|
@@ -552,7 +553,7 @@ export class WordPressClient {
|
|
|
552
553
|
if (data instanceof FormData) {
|
|
553
554
|
return false;
|
|
554
555
|
}
|
|
555
|
-
if (typeof data === "object" && data
|
|
556
|
+
if (typeof data === "object" && data && "pipe" in data) {
|
|
556
557
|
const potentialStream = data.pipe;
|
|
557
558
|
if (typeof potentialStream === "function") {
|
|
558
559
|
return false;
|
|
@@ -608,7 +609,10 @@ export class WordPressClient {
|
|
|
608
609
|
const fallbackTimeoutId = setTimeout(() => {
|
|
609
610
|
fallbackController.abort();
|
|
610
611
|
}, requestTimeout);
|
|
611
|
-
const fallbackOptions = {
|
|
612
|
+
const fallbackOptions = {
|
|
613
|
+
...fetchOptions,
|
|
614
|
+
signal: fallbackController.signal,
|
|
615
|
+
};
|
|
612
616
|
const fallbackResponse = await fetch(fallbackUrl, fallbackOptions);
|
|
613
617
|
clearTimeout(fallbackTimeoutId);
|
|
614
618
|
if (!fallbackResponse.ok) {
|
|
@@ -664,7 +668,9 @@ export class WordPressClient {
|
|
|
664
668
|
(this._stats.averageResponseTime * (totalSuccessful - 1) + duration) / totalSuccessful;
|
|
665
669
|
this._stats.lastRequestTime = Date.now();
|
|
666
670
|
}
|
|
667
|
-
//
|
|
671
|
+
// ============================================================================
|
|
672
|
+
// HTTP Method Helpers
|
|
673
|
+
// ============================================================================
|
|
668
674
|
async get(endpoint, options) {
|
|
669
675
|
return this.request("GET", endpoint, null, options);
|
|
670
676
|
}
|
|
@@ -680,262 +686,183 @@ export class WordPressClient {
|
|
|
680
686
|
async delete(endpoint, options) {
|
|
681
687
|
return this.request("DELETE", endpoint, null, options);
|
|
682
688
|
}
|
|
683
|
-
//
|
|
684
|
-
// Posts
|
|
689
|
+
// ============================================================================
|
|
690
|
+
// Posts Operations (delegated to PostsOperations)
|
|
691
|
+
// ============================================================================
|
|
685
692
|
async getPosts(params) {
|
|
686
|
-
|
|
687
|
-
return this.get(`posts${queryString}`);
|
|
693
|
+
return this.postsOps.getPosts(params);
|
|
688
694
|
}
|
|
689
695
|
async getPost(id, context = "view") {
|
|
690
|
-
return this.
|
|
696
|
+
return this.postsOps.getPost(id, context);
|
|
691
697
|
}
|
|
692
698
|
async createPost(data) {
|
|
693
|
-
return this.
|
|
699
|
+
return this.postsOps.createPost(data);
|
|
694
700
|
}
|
|
695
701
|
async updatePost(data) {
|
|
696
|
-
|
|
697
|
-
return this.put(`posts/${id}`, updateData);
|
|
702
|
+
return this.postsOps.updatePost(data);
|
|
698
703
|
}
|
|
699
704
|
async deletePost(id, force = false) {
|
|
700
|
-
return this.
|
|
705
|
+
return this.postsOps.deletePost(id, force);
|
|
701
706
|
}
|
|
702
707
|
async getPostRevisions(id) {
|
|
703
|
-
return this.
|
|
708
|
+
return this.postsOps.getPostRevisions(id);
|
|
704
709
|
}
|
|
705
|
-
//
|
|
710
|
+
// ============================================================================
|
|
711
|
+
// Pages Operations (delegated to PagesOperations)
|
|
712
|
+
// ============================================================================
|
|
706
713
|
async getPages(params) {
|
|
707
|
-
|
|
708
|
-
? Object.fromEntries(Object.entries(params).map(([k, v]) => [k, String(v)]))
|
|
709
|
-
: undefined;
|
|
710
|
-
const queryString = normalizedParams ? "?" + new URLSearchParams(normalizedParams).toString() : "";
|
|
711
|
-
return this.get(`pages${queryString}`);
|
|
714
|
+
return this.pagesOps.getPages(params);
|
|
712
715
|
}
|
|
713
716
|
async getPage(id, context = "view") {
|
|
714
|
-
return this.
|
|
717
|
+
return this.pagesOps.getPage(id, context);
|
|
715
718
|
}
|
|
716
719
|
async createPage(data) {
|
|
717
|
-
return this.
|
|
720
|
+
return this.pagesOps.createPage(data);
|
|
718
721
|
}
|
|
719
722
|
async updatePage(data) {
|
|
720
|
-
|
|
721
|
-
return this.put(`pages/${id}`, updateData);
|
|
723
|
+
return this.pagesOps.updatePage(data);
|
|
722
724
|
}
|
|
723
725
|
async deletePage(id, force = false) {
|
|
724
|
-
return this.
|
|
726
|
+
return this.pagesOps.deletePage(id, force);
|
|
725
727
|
}
|
|
726
728
|
async getPageRevisions(id) {
|
|
727
|
-
return this.
|
|
729
|
+
return this.pagesOps.getPageRevisions(id);
|
|
728
730
|
}
|
|
729
|
-
//
|
|
731
|
+
// ============================================================================
|
|
732
|
+
// Media Operations (delegated to MediaOperations)
|
|
733
|
+
// ============================================================================
|
|
730
734
|
async getMedia(params) {
|
|
731
|
-
|
|
732
|
-
? Object.fromEntries(Object.entries(params).map(([k, v]) => [k, String(v)]))
|
|
733
|
-
: undefined;
|
|
734
|
-
const queryString = normalizedParams ? "?" + new URLSearchParams(normalizedParams).toString() : "";
|
|
735
|
-
return this.get(`media${queryString}`);
|
|
735
|
+
return this.mediaOps.getMedia(params);
|
|
736
736
|
}
|
|
737
737
|
async getMediaItem(id, context = "view") {
|
|
738
|
-
return this.
|
|
738
|
+
return this.mediaOps.getMediaItem(id, context);
|
|
739
739
|
}
|
|
740
740
|
async uploadMedia(data) {
|
|
741
|
-
|
|
742
|
-
await fsPromises.access(data.file_path);
|
|
743
|
-
}
|
|
744
|
-
catch {
|
|
745
|
-
throw new Error(`File not found: ${data.file_path}`);
|
|
746
|
-
}
|
|
747
|
-
const stats = await fsPromises.stat(data.file_path);
|
|
748
|
-
const filename = data.title || path.basename(data.file_path);
|
|
749
|
-
const fileBuffer = await fsPromises.readFile(data.file_path);
|
|
750
|
-
// Check if file is too large (WordPress default is 2MB for most installs)
|
|
751
|
-
const maxSize = 10 * 1024 * 1024; // 10MB reasonable limit
|
|
752
|
-
if (stats.size > maxSize) {
|
|
753
|
-
throw new Error(`File too large: ${(stats.size / 1024 / 1024).toFixed(2)}MB. Maximum allowed: ${maxSize / 1024 / 1024}MB`);
|
|
754
|
-
}
|
|
755
|
-
debug.log(`Uploading file: ${filename} (${(stats.size / 1024).toFixed(2)}KB)`);
|
|
756
|
-
return this.uploadFile(fileBuffer, filename, this.getMimeType(data.file_path), data);
|
|
741
|
+
return this.mediaOps.uploadMedia(data);
|
|
757
742
|
}
|
|
758
743
|
async uploadFile(fileData, filename, mimeType, meta = {}, options) {
|
|
759
|
-
|
|
760
|
-
// Use FormData but with correct configuration for node-fetch
|
|
761
|
-
const formData = new FormData();
|
|
762
|
-
formData.setMaxListeners(20);
|
|
763
|
-
// Add file with correct options
|
|
764
|
-
formData.append("file", fileData, {
|
|
765
|
-
filename,
|
|
766
|
-
contentType: mimeType,
|
|
767
|
-
});
|
|
768
|
-
// Add metadata
|
|
769
|
-
if (meta.title)
|
|
770
|
-
formData.append("title", meta.title);
|
|
771
|
-
if (meta.alt_text)
|
|
772
|
-
formData.append("alt_text", meta.alt_text);
|
|
773
|
-
if (meta.caption)
|
|
774
|
-
formData.append("caption", meta.caption);
|
|
775
|
-
if (meta.description)
|
|
776
|
-
formData.append("description", meta.description);
|
|
777
|
-
if (meta.post)
|
|
778
|
-
formData.append("post", meta.post.toString());
|
|
779
|
-
// Use longer timeout for file uploads
|
|
780
|
-
const uploadTimeout = options?.timeout !== undefined ? options.timeout : 600000; // 10 minutes default
|
|
781
|
-
const uploadOptions = {
|
|
782
|
-
...options,
|
|
783
|
-
timeout: uploadTimeout,
|
|
784
|
-
};
|
|
785
|
-
debug.log(`Upload prepared with FormData, timeout: ${uploadTimeout}ms`);
|
|
786
|
-
// Use the regular post method which handles FormData correctly
|
|
787
|
-
return this.post("media", formData, uploadOptions);
|
|
744
|
+
return this.mediaOps.uploadFile(fileData, filename, mimeType, meta, options);
|
|
788
745
|
}
|
|
789
746
|
async updateMedia(data) {
|
|
790
|
-
|
|
791
|
-
return this.put(`media/${id}`, updateData);
|
|
747
|
+
return this.mediaOps.updateMedia(data);
|
|
792
748
|
}
|
|
793
749
|
async deleteMedia(id, force = false) {
|
|
794
|
-
return this.
|
|
750
|
+
return this.mediaOps.deleteMedia(id, force);
|
|
795
751
|
}
|
|
796
|
-
//
|
|
752
|
+
// ============================================================================
|
|
753
|
+
// Users Operations (delegated to UsersOperations)
|
|
754
|
+
// ============================================================================
|
|
797
755
|
async getUsers(params) {
|
|
798
|
-
|
|
799
|
-
? Object.fromEntries(Object.entries(params).map(([k, v]) => [k, String(v)]))
|
|
800
|
-
: undefined;
|
|
801
|
-
const queryString = normalizedParams ? "?" + new URLSearchParams(normalizedParams).toString() : "";
|
|
802
|
-
return this.get(`users${queryString}`);
|
|
756
|
+
return this.usersOps.getUsers(params);
|
|
803
757
|
}
|
|
804
758
|
async getUser(id, context = "view") {
|
|
805
|
-
return this.
|
|
759
|
+
return this.usersOps.getUser(id, context);
|
|
806
760
|
}
|
|
807
761
|
async createUser(data) {
|
|
808
|
-
return this.
|
|
762
|
+
return this.usersOps.createUser(data);
|
|
809
763
|
}
|
|
810
764
|
async updateUser(data) {
|
|
811
|
-
|
|
812
|
-
return this.put(`users/${id}`, updateData);
|
|
765
|
+
return this.usersOps.updateUser(data);
|
|
813
766
|
}
|
|
814
767
|
async deleteUser(id, reassign) {
|
|
815
|
-
|
|
816
|
-
return this.delete(`users/${id}${params}`);
|
|
768
|
+
return this.usersOps.deleteUser(id, reassign);
|
|
817
769
|
}
|
|
818
770
|
async getCurrentUser() {
|
|
819
|
-
return this.
|
|
771
|
+
return this.usersOps.getCurrentUser();
|
|
820
772
|
}
|
|
821
|
-
//
|
|
773
|
+
// ============================================================================
|
|
774
|
+
// Comments Operations (delegated to CommentsOperations)
|
|
775
|
+
// ============================================================================
|
|
822
776
|
async getComments(params) {
|
|
823
|
-
|
|
824
|
-
? Object.fromEntries(Object.entries(params).map(([k, v]) => [k, String(v)]))
|
|
825
|
-
: undefined;
|
|
826
|
-
const queryString = normalizedParams ? "?" + new URLSearchParams(normalizedParams).toString() : "";
|
|
827
|
-
return this.get(`comments${queryString}`);
|
|
777
|
+
return this.commentsOps.getComments(params);
|
|
828
778
|
}
|
|
829
779
|
async getComment(id, context = "view") {
|
|
830
|
-
return this.
|
|
780
|
+
return this.commentsOps.getComment(id, context);
|
|
831
781
|
}
|
|
832
782
|
async createComment(data) {
|
|
833
|
-
return this.
|
|
783
|
+
return this.commentsOps.createComment(data);
|
|
834
784
|
}
|
|
835
785
|
async updateComment(data) {
|
|
836
|
-
|
|
837
|
-
return this.put(`comments/${id}`, updateData);
|
|
786
|
+
return this.commentsOps.updateComment(data);
|
|
838
787
|
}
|
|
839
788
|
async deleteComment(id, force = false) {
|
|
840
|
-
return this.
|
|
789
|
+
return this.commentsOps.deleteComment(id, force);
|
|
841
790
|
}
|
|
842
791
|
async approveComment(id) {
|
|
843
|
-
return this.
|
|
792
|
+
return this.commentsOps.approveComment(id);
|
|
844
793
|
}
|
|
845
794
|
async rejectComment(id) {
|
|
846
|
-
return this.
|
|
847
|
-
status: "unapproved",
|
|
848
|
-
});
|
|
795
|
+
return this.commentsOps.rejectComment(id);
|
|
849
796
|
}
|
|
850
797
|
async spamComment(id) {
|
|
851
|
-
return this.
|
|
798
|
+
return this.commentsOps.spamComment(id);
|
|
852
799
|
}
|
|
853
|
-
//
|
|
800
|
+
// ============================================================================
|
|
801
|
+
// Taxonomies Operations (delegated to TaxonomiesOperations)
|
|
802
|
+
// ============================================================================
|
|
854
803
|
async getCategories(params) {
|
|
855
|
-
|
|
856
|
-
? Object.fromEntries(Object.entries(params).map(([k, v]) => [k, String(v)]))
|
|
857
|
-
: undefined;
|
|
858
|
-
const queryString = normalizedParams ? "?" + new URLSearchParams(normalizedParams).toString() : "";
|
|
859
|
-
return this.get(`categories${queryString}`);
|
|
804
|
+
return this.taxonomiesOps.getCategories(params);
|
|
860
805
|
}
|
|
861
806
|
async getCategory(id) {
|
|
862
|
-
return this.
|
|
807
|
+
return this.taxonomiesOps.getCategory(id);
|
|
863
808
|
}
|
|
864
809
|
async createCategory(data) {
|
|
865
|
-
return this.
|
|
810
|
+
return this.taxonomiesOps.createCategory(data);
|
|
866
811
|
}
|
|
867
812
|
async updateCategory(data) {
|
|
868
|
-
|
|
869
|
-
return this.put(`categories/${id}`, updateData);
|
|
813
|
+
return this.taxonomiesOps.updateCategory(data);
|
|
870
814
|
}
|
|
871
815
|
async deleteCategory(id, force = false) {
|
|
872
|
-
return this.
|
|
816
|
+
return this.taxonomiesOps.deleteCategory(id, force);
|
|
873
817
|
}
|
|
874
818
|
async getTags(params) {
|
|
875
|
-
|
|
876
|
-
? Object.fromEntries(Object.entries(params).map(([k, v]) => [k, String(v)]))
|
|
877
|
-
: undefined;
|
|
878
|
-
const queryString = normalizedParams ? "?" + new URLSearchParams(normalizedParams).toString() : "";
|
|
879
|
-
return this.get(`tags${queryString}`);
|
|
819
|
+
return this.taxonomiesOps.getTags(params);
|
|
880
820
|
}
|
|
881
821
|
async getTag(id) {
|
|
882
|
-
return this.
|
|
822
|
+
return this.taxonomiesOps.getTag(id);
|
|
883
823
|
}
|
|
884
824
|
async createTag(data) {
|
|
885
|
-
return this.
|
|
825
|
+
return this.taxonomiesOps.createTag(data);
|
|
886
826
|
}
|
|
887
827
|
async updateTag(data) {
|
|
888
|
-
|
|
889
|
-
return this.put(`tags/${id}`, updateData);
|
|
828
|
+
return this.taxonomiesOps.updateTag(data);
|
|
890
829
|
}
|
|
891
830
|
async deleteTag(id, force = false) {
|
|
892
|
-
return this.
|
|
831
|
+
return this.taxonomiesOps.deleteTag(id, force);
|
|
893
832
|
}
|
|
894
|
-
//
|
|
833
|
+
// ============================================================================
|
|
834
|
+
// Site Operations (delegated to SiteOperations)
|
|
835
|
+
// ============================================================================
|
|
895
836
|
async getSiteSettings() {
|
|
896
|
-
return this.
|
|
837
|
+
return this.siteOps.getSiteSettings();
|
|
897
838
|
}
|
|
898
839
|
async updateSiteSettings(settings) {
|
|
899
|
-
return this.
|
|
840
|
+
return this.siteOps.updateSiteSettings(settings);
|
|
900
841
|
}
|
|
901
842
|
async getSiteInfo() {
|
|
902
|
-
return this.
|
|
843
|
+
return this.siteOps.getSiteInfo();
|
|
903
844
|
}
|
|
904
|
-
// Application Passwords
|
|
905
845
|
async getApplicationPasswords(userId = "me") {
|
|
906
|
-
return this.
|
|
846
|
+
return this.siteOps.getApplicationPasswords(userId);
|
|
907
847
|
}
|
|
908
848
|
async createApplicationPassword(userId, name, appId) {
|
|
909
|
-
|
|
910
|
-
if (appId)
|
|
911
|
-
data.app_id = appId;
|
|
912
|
-
return this.post(`users/${userId}/application-passwords`, data);
|
|
849
|
+
return this.siteOps.createApplicationPassword(userId, name, appId);
|
|
913
850
|
}
|
|
914
851
|
async deleteApplicationPassword(userId, uuid) {
|
|
915
|
-
return this.
|
|
852
|
+
return this.siteOps.deleteApplicationPassword(userId, uuid);
|
|
916
853
|
}
|
|
917
|
-
// Search
|
|
918
854
|
async search(query, types, subtype) {
|
|
919
|
-
|
|
920
|
-
if (types)
|
|
921
|
-
params.append("type", types.join(","));
|
|
922
|
-
if (subtype)
|
|
923
|
-
params.append("subtype", subtype);
|
|
924
|
-
return this.get(`search?${params.toString()}`);
|
|
855
|
+
return this.siteOps.search(query, types, subtype);
|
|
925
856
|
}
|
|
926
|
-
// Utility Methods
|
|
927
857
|
async ping() {
|
|
928
|
-
|
|
929
|
-
await this.get("");
|
|
930
|
-
return true;
|
|
931
|
-
}
|
|
932
|
-
catch {
|
|
933
|
-
return false;
|
|
934
|
-
}
|
|
858
|
+
return this.siteOps.ping();
|
|
935
859
|
}
|
|
936
860
|
async getServerInfo() {
|
|
937
|
-
return this.
|
|
861
|
+
return this.siteOps.getServerInfo();
|
|
938
862
|
}
|
|
863
|
+
// ============================================================================
|
|
864
|
+
// Utility Methods
|
|
865
|
+
// ============================================================================
|
|
939
866
|
validateEndpoint(endpoint) {
|
|
940
867
|
return /^[a-zA-Z0-9\/\-_]+$/.test(endpoint);
|
|
941
868
|
}
|
|
@@ -948,24 +875,5 @@ export class WordPressClient {
|
|
|
948
875
|
}
|
|
949
876
|
return url;
|
|
950
877
|
}
|
|
951
|
-
getMimeType(filePath) {
|
|
952
|
-
const ext = path.extname(filePath).toLowerCase();
|
|
953
|
-
const mimeTypes = {
|
|
954
|
-
".jpg": "image/jpeg",
|
|
955
|
-
".jpeg": "image/jpeg",
|
|
956
|
-
".png": "image/png",
|
|
957
|
-
".gif": "image/gif",
|
|
958
|
-
".webp": "image/webp",
|
|
959
|
-
".svg": "image/svg+xml",
|
|
960
|
-
".pdf": "application/pdf",
|
|
961
|
-
".doc": "application/msword",
|
|
962
|
-
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
963
|
-
".txt": "text/plain",
|
|
964
|
-
".mp4": "video/mp4",
|
|
965
|
-
".mp3": "audio/mpeg",
|
|
966
|
-
".wav": "audio/wav",
|
|
967
|
-
};
|
|
968
|
-
return mimeTypes[ext] || "application/octet-stream";
|
|
969
|
-
}
|
|
970
878
|
}
|
|
971
879
|
//# sourceMappingURL=api.js.map
|