@hostinger/mcp 3.37.1 → 3.38.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.
Files changed (62) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +1 -1
  3. package/gemini-extension.json +1 -1
  4. package/package.json +1 -1
  5. package/server.json +2 -2
  6. package/skills/deploy-to-hosting/SKILL.md +1 -1
  7. package/skills/headless/VERSION +3 -3
  8. package/src/core/catalog.js +9 -1
  9. package/src/core/catalog.ts +11 -2
  10. package/src/core/instructions.agency-hosting.js +1 -1
  11. package/src/core/instructions.agency-hosting.ts +1 -1
  12. package/src/core/instructions.js +1 -1
  13. package/src/core/instructions.ts +1 -1
  14. package/src/core/runtime.js +2 -1483
  15. package/src/core/runtime.ts +4 -1483
  16. package/src/core/skills.js +3 -3
  17. package/src/core/skills.ts +3 -3
  18. package/src/core/tools/agency-hosting.ts +2 -0
  19. package/src/core/tools/agent-readiness.ts +2 -0
  20. package/src/core/tools/all.js +72 -330
  21. package/src/core/tools/all.ts +74 -330
  22. package/src/core/tools/billing.ts +2 -0
  23. package/src/core/tools/dns.ts +2 -0
  24. package/src/core/tools/domains.ts +2 -0
  25. package/src/core/tools/ecommerce.ts +2 -0
  26. package/src/core/tools/gpu.ts +2 -0
  27. package/src/core/tools/horizons.ts +2 -0
  28. package/src/core/tools/hosting.js +63 -327
  29. package/src/core/tools/hosting.ts +65 -327
  30. package/src/core/tools/mail.ts +2 -0
  31. package/src/core/tools/reach.ts +2 -0
  32. package/src/core/tools/vps.ts +2 -0
  33. package/src/core/tools/wordpress.ts +2 -0
  34. package/src/servers/agency-hosting.js +1 -1
  35. package/src/servers/agency-hosting.ts +1 -1
  36. package/src/servers/agent-readiness.js +1 -1
  37. package/src/servers/agent-readiness.ts +1 -1
  38. package/src/servers/all.js +1 -1
  39. package/src/servers/all.ts +1 -1
  40. package/src/servers/billing.js +1 -1
  41. package/src/servers/billing.ts +1 -1
  42. package/src/servers/dns.js +1 -1
  43. package/src/servers/dns.ts +1 -1
  44. package/src/servers/domains.js +1 -1
  45. package/src/servers/domains.ts +1 -1
  46. package/src/servers/ecommerce.js +1 -1
  47. package/src/servers/ecommerce.ts +1 -1
  48. package/src/servers/gpu.js +1 -1
  49. package/src/servers/gpu.ts +1 -1
  50. package/src/servers/horizons.js +1 -1
  51. package/src/servers/horizons.ts +1 -1
  52. package/src/servers/hosting.js +1 -1
  53. package/src/servers/hosting.ts +1 -1
  54. package/src/servers/mail.js +1 -1
  55. package/src/servers/mail.ts +1 -1
  56. package/src/servers/reach.js +1 -1
  57. package/src/servers/reach.ts +1 -1
  58. package/src/servers/vps.js +1 -1
  59. package/src/servers/vps.ts +1 -1
  60. package/src/servers/wordpress.js +1 -1
  61. package/src/servers/wordpress.ts +1 -1
  62. package/types.d.ts +0 -155
@@ -314,20 +314,6 @@ class MCPServer {
314
314
  return await this.handleHostingWebsitesRemoveDomain(params);
315
315
  case 'hosting_websites_start-setup':
316
316
  return await this.handleHostingWebsitesStartSetup(params);
317
- case 'hosting_import-wordpress-website':
318
- return await this.handleWordpressWebsiteImport(params);
319
- case 'hosting_deploy-wordpress-plugin':
320
- return await this.handleWordpressPluginDeploy(params);
321
- case 'hosting_deploy-wordpress-theme':
322
- return await this.handleWordpressThemeDeploy(params);
323
- case 'hosting_deploy-js-application':
324
- return await this.handleJavascriptApplicationDeploy(params);
325
- case 'hosting_deploy-static-website':
326
- return await this.handleStaticWebsiteDeploy(params);
327
- case 'hosting_list-js-deployments':
328
- return await this.handleListJavascriptDeployments(params);
329
- case 'hosting_show-js-deployment-logs':
330
- return await this.handleShowJsDeploymentLogs(params);
331
317
  case 'hosting_websites_trigger-event':
332
318
  return await this.handleHostingTriggerWebsiteEvent(params);
333
319
  case 'agency-hosting_deploy-node-static-website':
@@ -498,62 +484,6 @@ class MCPServer {
498
484
  return { files: files.sort(), skipped: skipped.sort() };
499
485
  }
500
486
 
501
- async resolveUsername(domain) {
502
- const baseUrl = this.baseUrl.endsWith("/") ? this.baseUrl : `${this.baseUrl}/`;
503
- const url = new URL(`api/hosting/v1/websites?domain=${encodeURIComponent(domain)}`, baseUrl).toString();
504
-
505
- try {
506
- const bearerToken = await this.getAuthToken();
507
-
508
- const config = {
509
- method: 'get',
510
- url,
511
- headers: {
512
- ...this.headers,
513
- 'Authorization': `Bearer ${bearerToken}`
514
- },
515
- timeout: 60000, // 60s
516
- validateStatus: function (status) {
517
- return status < 500;
518
- }
519
- };
520
-
521
- const response = await axios(config);
522
-
523
- if (response.status !== 200) {
524
- throw new Error(`API returned status ${response.status}: ${JSON.stringify(response.data)}`);
525
- }
526
-
527
- const websites = response.data?.data;
528
- if (!websites || websites.length === 0) {
529
- throw new Error(`No website found for domain: ${domain}`);
530
- }
531
-
532
- const username = websites[0].username;
533
- if (!username) {
534
- throw new Error(`Username not found in website data for domain: ${domain}`);
535
- }
536
-
537
- this.log('info', `Resolved username: ${username} for domain: ${domain}`);
538
- return username;
539
-
540
- } catch (error) {
541
- const errorMessage = error instanceof Error ? error.message : String(error);
542
- this.log('error', `Failed to resolve username for domain ${domain}: ${errorMessage}`);
543
-
544
- if (axios.isAxiosError(error)) {
545
- const responseData = error.response?.data;
546
- const responseStatus = error.response?.status;
547
- this.log('error', 'API Error Details:', {
548
- status: responseStatus,
549
- data: typeof responseData === 'object' ? JSON.stringify(responseData) : responseData
550
- });
551
- }
552
-
553
- throw error;
554
- }
555
- }
556
-
557
487
  // upload-urls fails for a few seconds while the server's file browser starts or is under maintenance, and a retry
558
488
  // usually succeeds, so 5xx responses and connection errors are retried; a 4xx and our own timeout are not.
559
489
  async retryUploadCredentialsRequest(request) {
@@ -717,8 +647,8 @@ class MCPServer {
717
647
  }
718
648
 
719
649
  // Run a catalog operation by name through the runtime's own request code (auth,
720
- // path parameters, API errors). Hidden operations are still in the catalog, and
721
- // calling them here does not log the deprecation warning that execute does.
650
+ // path parameters, API errors). Hidden and internal operations are still in the catalog:
651
+ // calling them here neither logs execute's deprecation warning nor hits its internal refusal.
722
652
  async callOperation(name, params) {
723
653
  const tool = this.operations.get(name);
724
654
  if (!tool) {
@@ -1862,1417 +1792,6 @@ class MCPServer {
1862
1792
  return this.callOperation('hosting_websites_create', forwarded);
1863
1793
  }
1864
1794
 
1865
- hosting_importWordpressWebsite_validateArchiveFormat(filePath) {
1866
- const validExtensions = ['zip', 'tar', 'tar.gz', 'tgz', '7z', 'gz', 'gzip'];
1867
- const fileName = path.basename(filePath).toLowerCase();
1868
-
1869
- for (const ext of validExtensions) {
1870
- if (fileName.endsWith(`.${ext}`)) {
1871
- return true;
1872
- }
1873
- }
1874
-
1875
- return false;
1876
- }
1877
-
1878
- hosting_importWordpressWebsite_validateRequiredParams(params) {
1879
- const { domain, archivePath, databaseDump } = params;
1880
-
1881
- if (!domain || typeof domain !== 'string') {
1882
- throw new Error('domain is required and must be a string');
1883
- }
1884
-
1885
- if (!archivePath || typeof archivePath !== 'string') {
1886
- throw new Error('archivePath is required and must be a string');
1887
- }
1888
-
1889
- if (!databaseDump || typeof databaseDump !== 'string') {
1890
- throw new Error('databaseDump is required and must be a string');
1891
- }
1892
- }
1893
-
1894
- hosting_importWordpressWebsite_validateArchiveFile(archivePath) {
1895
- this.assertDeployablePath(archivePath);
1896
- if (!fs.existsSync(archivePath)) {
1897
- throw new Error(`Archive file not found: ${archivePath}`);
1898
- }
1899
-
1900
- const archiveStats = fs.statSync(archivePath);
1901
- if (!archiveStats.isFile()) {
1902
- throw new Error(`Archive path is not a file: ${archivePath}`);
1903
- }
1904
-
1905
- if (!this.hosting_importWordpressWebsite_validateArchiveFormat(archivePath)) {
1906
- throw new Error('Invalid archive format. Supported formats: zip, tar, tar.gz, tgz, 7z, gz, gzip');
1907
- }
1908
- }
1909
-
1910
- hosting_importWordpressWebsite_validateDatabaseFile(databaseDump) {
1911
- this.assertDeployablePath(databaseDump);
1912
- if (!fs.existsSync(databaseDump)) {
1913
- throw new Error(`Database dump file not found: ${databaseDump}`);
1914
- }
1915
-
1916
- const dbStats = fs.statSync(databaseDump);
1917
- if (!dbStats.isFile()) {
1918
- throw new Error(`Database dump path is not a file: ${databaseDump}`);
1919
- }
1920
-
1921
- if (!databaseDump.toLowerCase().endsWith('.sql')) {
1922
- throw new Error('Database dump must be a .sql file');
1923
- }
1924
- }
1925
-
1926
- async hosting_importWordpressWebsite_checkWebsiteIsEmpty(username, domain) {
1927
- const baseUrl = this.baseUrl.endsWith("/") ? this.baseUrl : `${this.baseUrl}/`;
1928
- const url = new URL(`api/hosting/v1/accounts/${username}/domains/${domain}/is-empty`, baseUrl).toString();
1929
-
1930
- try {
1931
- const bearerToken = await this.getAuthToken();
1932
-
1933
- const config = {
1934
- method: 'get',
1935
- url,
1936
- headers: {
1937
- ...this.headers,
1938
- 'Authorization': `Bearer ${bearerToken}`
1939
- },
1940
- timeout: 60000, // 60s
1941
- validateStatus: function (status) {
1942
- return status < 500;
1943
- }
1944
- };
1945
-
1946
- const response = await axios(config);
1947
-
1948
- if (response.status !== 200) {
1949
- throw new Error(`API returned status ${response.status}: ${JSON.stringify(response.data)}`);
1950
- }
1951
-
1952
- const { is_empty } = response.data;
1953
-
1954
- if (!is_empty) {
1955
- throw new Error('Website is not empty. WordPress import can only be performed on empty sites. Please visit hPanel (https://hpanel.hostinger.com) and remove all existing files from the website before attempting to import.');
1956
- }
1957
-
1958
- this.log('info', `Website ${domain} is empty, proceeding with import`);
1959
- return true;
1960
-
1961
- } catch (error) {
1962
- const errorMessage = error instanceof Error ? error.message : String(error);
1963
- this.log('error', `Failed to check if website is empty: ${errorMessage}`);
1964
-
1965
- if (axios.isAxiosError(error)) {
1966
- const responseData = error.response?.data;
1967
- const responseStatus = error.response?.status;
1968
- this.log('error', 'API Error Details:', {
1969
- status: responseStatus,
1970
- data: typeof responseData === 'object' ? JSON.stringify(responseData) : responseData
1971
- });
1972
- }
1973
-
1974
- throw error;
1975
- }
1976
- }
1977
-
1978
- async hosting_importWordpressWebsite_extractFiles(username, domain, archivePath, databaseDump) {
1979
- const baseUrl = this.baseUrl.endsWith("/") ? this.baseUrl : `${this.baseUrl}/`;
1980
- const url = new URL(`api/hosting/v1/accounts/${username}/websites/${domain}/wordpress/import`, baseUrl).toString();
1981
-
1982
- try {
1983
- const bearerToken = await this.getAuthToken();
1984
-
1985
- const config = {
1986
- method: 'post',
1987
- url,
1988
- headers: {
1989
- ...this.headers,
1990
- 'Authorization': `Bearer ${bearerToken}`,
1991
- 'Content-Type': 'application/json'
1992
- },
1993
- data: {
1994
- archive_path: path.basename(archivePath),
1995
- sql_path: path.basename(databaseDump)
1996
- },
1997
- timeout: 60000, // 60s
1998
- validateStatus: function (status) {
1999
- return status < 500;
2000
- }
2001
- };
2002
-
2003
- const response = await axios(config);
2004
-
2005
- this.log('info', `Successfully triggered file extraction for ${domain}`);
2006
- return true;
2007
-
2008
- } catch (error) {
2009
- const errorMessage = error instanceof Error ? error.message : String(error);
2010
- this.log('error', `Failed to trigger file extraction: ${errorMessage}`);
2011
-
2012
- if (axios.isAxiosError(error)) {
2013
- const responseData = error.response?.data;
2014
- const responseStatus = error.response?.status;
2015
- this.log('error', 'API Error Details:', {
2016
- status: responseStatus,
2017
- data: typeof responseData === 'object' ? JSON.stringify(responseData) : responseData
2018
- });
2019
- }
2020
-
2021
- throw error;
2022
- }
2023
- }
2024
-
2025
- async handleWordpressWebsiteImport(params) {
2026
- const { domain, archivePath, databaseDump } = params;
2027
-
2028
- this.hosting_importWordpressWebsite_validateRequiredParams(params);
2029
- this.hosting_importWordpressWebsite_validateArchiveFile(archivePath);
2030
- this.hosting_importWordpressWebsite_validateDatabaseFile(databaseDump);
2031
-
2032
- // Auto-resolve username from domain
2033
- this.log('info', `Resolving username from domain: ${domain}`);
2034
- const username = await this.resolveUsername(domain);
2035
-
2036
- await this.hosting_importWordpressWebsite_checkWebsiteIsEmpty(username, domain);
2037
-
2038
- const filesToUpload = [{
2039
- absolutePath: archivePath,
2040
- relativePath: path.basename(archivePath),
2041
- type: 'archive'
2042
- }, {
2043
- absolutePath: databaseDump,
2044
- relativePath: path.basename(databaseDump),
2045
- type: 'database'
2046
- }];
2047
-
2048
- let uploadCredentials;
2049
- try {
2050
- uploadCredentials = await this.fetchUploadCredentials(username, domain);
2051
- } catch (error) {
2052
- const errorMessage = error instanceof Error ? error.message : String(error);
2053
- throw new Error(`Failed to fetch upload credentials: ${errorMessage}`);
2054
- }
2055
-
2056
- const { url: uploadUrl, auth_key: authToken, rest_auth_key: authRestToken } = uploadCredentials;
2057
-
2058
- if (!uploadUrl || !authToken || !authRestToken) {
2059
- throw new Error('Invalid upload credentials received from API');
2060
- }
2061
-
2062
- this.log('info', `Starting website archive import to ${uploadUrl}`);
2063
-
2064
- const results = [];
2065
- let successCount = 0;
2066
- let failureCount = 0;
2067
-
2068
- for (const fileInfo of filesToUpload) {
2069
- try {
2070
- this.log('info', `Uploading ${fileInfo.type}: ${fileInfo.absolutePath}`);
2071
-
2072
- const stats = fs.statSync(fileInfo.absolutePath);
2073
- const uploadResult = await this.uploadFile(
2074
- fileInfo.absolutePath,
2075
- fileInfo.relativePath,
2076
- uploadUrl,
2077
- authRestToken,
2078
- authToken
2079
- );
2080
-
2081
- results.push({
2082
- file: fileInfo.absolutePath,
2083
- remotePath: fileInfo.relativePath,
2084
- type: fileInfo.type,
2085
- status: 'success',
2086
- uploadUrl: uploadResult.url,
2087
- size: stats.size
2088
- });
2089
-
2090
- successCount++;
2091
- this.log('info', `Successfully uploaded ${fileInfo.type}: ${fileInfo.relativePath}`);
2092
-
2093
- } catch (error) {
2094
- const errorMessage = error instanceof Error ? error.message : String(error);
2095
- results.push({
2096
- file: fileInfo.absolutePath,
2097
- remotePath: fileInfo.relativePath,
2098
- type: fileInfo.type,
2099
- status: 'error',
2100
- error: errorMessage
2101
- });
2102
-
2103
- failureCount++;
2104
- this.log('error', `Failed to upload ${fileInfo.type} ${fileInfo.absolutePath}: ${errorMessage}`);
2105
- }
2106
- }
2107
-
2108
- const overallStatus = failureCount === 0 ? 'success' : (successCount === 0 ? 'failure' : 'partial');
2109
-
2110
- if (failureCount === 0) {
2111
- try {
2112
- this.log('info', 'All files uploaded successfully, triggering extraction...');
2113
- await this.hosting_importWordpressWebsite_extractFiles(username, domain, archivePath, databaseDump);
2114
- } catch (error) {
2115
- const errorMessage = error instanceof Error ? error.message : String(error);
2116
- this.log('error', `File extraction failed: ${errorMessage}`);
2117
- return {
2118
- status: 'partial',
2119
- summary: {
2120
- total: filesToUpload.length,
2121
- successful: successCount,
2122
- failed: failureCount
2123
- },
2124
- results,
2125
- extractionError: errorMessage
2126
- };
2127
- }
2128
- }
2129
-
2130
- return {
2131
- status: overallStatus,
2132
- summary: {
2133
- total: filesToUpload.length,
2134
- successful: successCount,
2135
- failed: failureCount
2136
- },
2137
- results
2138
- };
2139
- }
2140
-
2141
- hosting_deployWordpressPlugin_generateRandomString(length) {
2142
- const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
2143
- let result = '';
2144
- for (let i = 0; i < length; i++) {
2145
- result += chars.charAt(Math.floor(Math.random() * chars.length));
2146
- }
2147
- return result;
2148
- }
2149
-
2150
- hosting_deployWordpressPlugin_validateRequiredParams(params) {
2151
- const { domain, slug, pluginPath } = params;
2152
-
2153
- if (!domain || typeof domain !== 'string') {
2154
- throw new Error('domain is required and must be a string');
2155
- }
2156
-
2157
- if (!slug || typeof slug !== 'string') {
2158
- throw new Error('slug is required and must be a string');
2159
- }
2160
-
2161
- if (!pluginPath || typeof pluginPath !== 'string') {
2162
- throw new Error('pluginPath is required and must be a string');
2163
- }
2164
- }
2165
-
2166
- hosting_deployWordpressPlugin_validatePluginDirectory(pluginPath) {
2167
- this.assertDeployablePath(pluginPath);
2168
- if (!fs.existsSync(pluginPath)) {
2169
- throw new Error(`Plugin directory not found: ${pluginPath}`);
2170
- }
2171
-
2172
- const pluginStats = fs.statSync(pluginPath);
2173
- if (!pluginStats.isDirectory()) {
2174
- throw new Error(`Plugin path is not a directory: ${pluginPath}`);
2175
- }
2176
- }
2177
-
2178
- async hosting_deployWordpressPlugin_deployPlugin(username, domain, slug, pluginPath) {
2179
- const baseUrl = this.baseUrl.endsWith("/") ? this.baseUrl : `${this.baseUrl}/`;
2180
- const url = new URL(`api/hosting/v1/accounts/${username}/websites/${domain}/wordpress/plugins/deploy`, baseUrl).toString();
2181
-
2182
- try {
2183
- const bearerToken = await this.getAuthToken();
2184
-
2185
- const config = {
2186
- method: 'post',
2187
- url,
2188
- headers: {
2189
- ...this.headers,
2190
- 'Authorization': `Bearer ${bearerToken}`,
2191
- 'Content-Type': 'application/json'
2192
- },
2193
- data: {
2194
- slug,
2195
- plugin_path: pluginPath
2196
- },
2197
- timeout: 60000, // 60s
2198
- validateStatus: function (status) {
2199
- return status < 500;
2200
- }
2201
- };
2202
-
2203
- const response = await axios(config);
2204
-
2205
- if (response.status !== 200) {
2206
- throw new Error(`API returned status ${response.status}: ${JSON.stringify(response.data)}`);
2207
- }
2208
-
2209
- this.log('info', `Successfully triggered plugin deployment for ${domain}`);
2210
- return true;
2211
-
2212
- } catch (error) {
2213
- const errorMessage = error instanceof Error ? error.message : String(error);
2214
- this.log('error', `Failed to trigger plugin deployment: ${errorMessage}`);
2215
-
2216
- if (axios.isAxiosError(error)) {
2217
- const responseData = error.response?.data;
2218
- const responseStatus = error.response?.status;
2219
- this.log('error', 'API Error Details:', {
2220
- status: responseStatus,
2221
- data: typeof responseData === 'object' ? JSON.stringify(responseData) : responseData
2222
- });
2223
- }
2224
-
2225
- throw error;
2226
- }
2227
- }
2228
-
2229
- async handleWordpressPluginDeploy(params) {
2230
- const { domain, slug, pluginPath } = params;
2231
-
2232
- this.hosting_deployWordpressPlugin_validateRequiredParams(params);
2233
- this.hosting_deployWordpressPlugin_validatePluginDirectory(pluginPath);
2234
-
2235
- this.log('info', `Resolving username from domain: ${domain}`);
2236
- const username = await this.resolveUsername(domain);
2237
-
2238
- const randomSuffix = this.hosting_deployWordpressPlugin_generateRandomString(8);
2239
- const uploadDirName = `${slug}-${randomSuffix}`;
2240
-
2241
- this.log('info', `Scanning plugin directory: ${pluginPath}`);
2242
- const { files, skipped } = this.listDeployFiles(pluginPath);
2243
- const pluginFiles = files.map((relativePath) => ({ absolutePath: path.join(pluginPath, relativePath), relativePath }));
2244
-
2245
- if (pluginFiles.length === 0) {
2246
- throw new Error(`No files found in plugin directory: ${pluginPath}`);
2247
- }
2248
-
2249
- this.log('info', `Found ${pluginFiles.length} files to upload`);
2250
-
2251
- let uploadCredentials;
2252
- try {
2253
- uploadCredentials = await this.fetchUploadCredentials(username, domain);
2254
- } catch (error) {
2255
- const errorMessage = error instanceof Error ? error.message : String(error);
2256
- throw new Error(`Failed to fetch upload credentials: ${errorMessage}`);
2257
- }
2258
-
2259
- const { url: uploadUrl, auth_key: authToken, rest_auth_key: authRestToken } = uploadCredentials;
2260
-
2261
- if (!uploadUrl || !authToken || !authRestToken) {
2262
- throw new Error('Invalid upload credentials received from API');
2263
- }
2264
-
2265
- this.log('info', `Starting plugin file upload to ${uploadUrl}`);
2266
-
2267
- const results = [];
2268
- let successCount = 0;
2269
- let failureCount = 0;
2270
-
2271
- for (const fileInfo of pluginFiles) {
2272
- try {
2273
- const normalizedRelativePath = this.normalizePath(fileInfo.relativePath);
2274
- const uploadPath = `wp-content/plugins/${uploadDirName}/${normalizedRelativePath}`;
2275
- this.log('info', `Uploading: ${fileInfo.absolutePath} -> ${uploadPath}`);
2276
-
2277
- const stats = fs.statSync(fileInfo.absolutePath);
2278
- const uploadResult = await this.uploadFile(
2279
- fileInfo.absolutePath,
2280
- uploadPath,
2281
- uploadUrl,
2282
- authRestToken,
2283
- authToken
2284
- );
2285
-
2286
- results.push({
2287
- file: fileInfo.absolutePath,
2288
- remotePath: uploadPath,
2289
- status: 'success',
2290
- uploadUrl: uploadResult.url,
2291
- size: stats.size
2292
- });
2293
-
2294
- successCount++;
2295
- this.log('info', `Successfully uploaded: ${uploadPath}`);
2296
-
2297
- } catch (error) {
2298
- const errorMessage = error instanceof Error ? error.message : String(error);
2299
- const normalizedRelativePath = this.normalizePath(fileInfo.relativePath);
2300
- const uploadPath = `wp-content/plugins/${uploadDirName}/${normalizedRelativePath}`;
2301
-
2302
- results.push({
2303
- file: fileInfo.absolutePath,
2304
- remotePath: uploadPath,
2305
- status: 'error',
2306
- error: errorMessage
2307
- });
2308
-
2309
- failureCount++;
2310
- this.log('error', `Failed to upload ${fileInfo.absolutePath}: ${errorMessage}`);
2311
- }
2312
- }
2313
-
2314
- const overallStatus = failureCount === 0 ? 'success' : (successCount === 0 ? 'failure' : 'partial');
2315
-
2316
- if (failureCount === 0) {
2317
- try {
2318
- this.log('info', 'All files uploaded successfully, triggering plugin deployment...');
2319
- await this.hosting_deployWordpressPlugin_deployPlugin(username, domain, slug, uploadDirName);
2320
- } catch (error) {
2321
- const errorMessage = error instanceof Error ? error.message : String(error);
2322
- this.log('error', `Plugin deployment failed: ${errorMessage}`);
2323
- return {
2324
- status: 'partial',
2325
- summary: {
2326
- total: pluginFiles.length,
2327
- successful: successCount,
2328
- failed: failureCount
2329
- },
2330
- results,
2331
- ...(skipped.length > 0 ? { skippedFiles: skipped } : {}),
2332
- deploymentError: errorMessage
2333
- };
2334
- }
2335
- }
2336
-
2337
- return {
2338
- status: overallStatus,
2339
- summary: {
2340
- total: pluginFiles.length,
2341
- successful: successCount,
2342
- failed: failureCount
2343
- },
2344
- results,
2345
- ...(skipped.length > 0 ? { skippedFiles: skipped } : {}),
2346
- uploadDirName
2347
- };
2348
- }
2349
-
2350
- hosting_deployWordpressTheme_generateRandomString(length) {
2351
- const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
2352
- let result = '';
2353
- for (let i = 0; i < length; i++) {
2354
- result += chars.charAt(Math.floor(Math.random() * chars.length));
2355
- }
2356
- return result;
2357
- }
2358
-
2359
- hosting_deployWordpressTheme_validateRequiredParams(params) {
2360
- const { domain, slug, themePath } = params;
2361
-
2362
- if (!domain || typeof domain !== 'string') {
2363
- throw new Error('domain is required and must be a string');
2364
- }
2365
-
2366
- if (!slug || typeof slug !== 'string') {
2367
- throw new Error('slug is required and must be a string');
2368
- }
2369
-
2370
- if (!themePath || typeof themePath !== 'string') {
2371
- throw new Error('themePath is required and must be a string');
2372
- }
2373
- }
2374
-
2375
- hosting_deployWordpressTheme_validateThemeDirectory(themePath) {
2376
- this.assertDeployablePath(themePath);
2377
- if (!fs.existsSync(themePath)) {
2378
- throw new Error(`Theme directory not found: ${themePath}`);
2379
- }
2380
-
2381
- const themeStats = fs.statSync(themePath);
2382
- if (!themeStats.isDirectory()) {
2383
- throw new Error(`Theme path is not a directory: ${themePath}`);
2384
- }
2385
- }
2386
-
2387
- async hosting_deployWordpressTheme_deployTheme(username, domain, slug, themePath, activate = false) {
2388
- const baseUrl = this.baseUrl.endsWith("/") ? this.baseUrl : `${this.baseUrl}/`;
2389
- const url = new URL(`api/hosting/v1/accounts/${username}/websites/${domain}/wordpress/themes/deploy`, baseUrl).toString();
2390
-
2391
- try {
2392
- const bearerToken = await this.getAuthToken();
2393
-
2394
- const config = {
2395
- method: 'post',
2396
- url,
2397
- headers: {
2398
- ...this.headers,
2399
- 'Authorization': `Bearer ${bearerToken}`,
2400
- 'Content-Type': 'application/json'
2401
- },
2402
- data: {
2403
- slug,
2404
- theme_path: themePath,
2405
- is_activated: activate
2406
- },
2407
- timeout: 60000, // 60s
2408
- validateStatus: function (status) {
2409
- return status < 500;
2410
- }
2411
- };
2412
-
2413
- const response = await axios(config);
2414
-
2415
- if (response.status !== 200) {
2416
- throw new Error(`API returned status ${response.status}: ${JSON.stringify(response.data)}`);
2417
- }
2418
-
2419
- this.log('info', `Successfully triggered theme deployment for ${domain}`);
2420
- return true;
2421
-
2422
- } catch (error) {
2423
- const errorMessage = error instanceof Error ? error.message : String(error);
2424
- this.log('error', `Failed to trigger theme deployment: ${errorMessage}`);
2425
-
2426
- if (axios.isAxiosError(error)) {
2427
- const responseData = error.response?.data;
2428
- const responseStatus = error.response?.status;
2429
- this.log('error', 'API Error Details:', {
2430
- status: responseStatus,
2431
- data: typeof responseData === 'object' ? JSON.stringify(responseData) : responseData
2432
- });
2433
- }
2434
-
2435
- throw error;
2436
- }
2437
- }
2438
-
2439
- async handleWordpressThemeDeploy(params) {
2440
- const { domain, slug, themePath, activate = false } = params;
2441
-
2442
- this.hosting_deployWordpressTheme_validateRequiredParams(params);
2443
- this.hosting_deployWordpressTheme_validateThemeDirectory(themePath);
2444
-
2445
- this.log('info', `Resolving username from domain: ${domain}`);
2446
- const username = await this.resolveUsername(domain);
2447
-
2448
- const randomSuffix = this.hosting_deployWordpressTheme_generateRandomString(8);
2449
- const uploadDirName = `${slug}-${randomSuffix}`;
2450
-
2451
- this.log('info', `Scanning theme directory: ${themePath}`);
2452
- const { files, skipped } = this.listDeployFiles(themePath);
2453
- const themeFiles = files.map((relativePath) => ({ absolutePath: path.join(themePath, relativePath), relativePath }));
2454
-
2455
- if (themeFiles.length === 0) {
2456
- throw new Error(`No files found in theme directory: ${themePath}`);
2457
- }
2458
-
2459
- this.log('info', `Found ${themeFiles.length} files to upload`);
2460
-
2461
- let uploadCredentials;
2462
- try {
2463
- uploadCredentials = await this.fetchUploadCredentials(username, domain);
2464
- } catch (error) {
2465
- const errorMessage = error instanceof Error ? error.message : String(error);
2466
- throw new Error(`Failed to fetch upload credentials: ${errorMessage}`);
2467
- }
2468
-
2469
- const { url: uploadUrl, auth_key: authToken, rest_auth_key: authRestToken } = uploadCredentials;
2470
-
2471
- if (!uploadUrl || !authToken || !authRestToken) {
2472
- throw new Error('Invalid upload credentials received from API');
2473
- }
2474
-
2475
- this.log('info', `Starting theme file upload to ${uploadUrl}`);
2476
-
2477
- const results = [];
2478
- let successCount = 0;
2479
- let failureCount = 0;
2480
-
2481
- for (const fileInfo of themeFiles) {
2482
- try {
2483
- const normalizedRelativePath = this.normalizePath(fileInfo.relativePath);
2484
- const uploadPath = `wp-content/themes/${uploadDirName}/${normalizedRelativePath}`;
2485
- this.log('info', `Uploading: ${fileInfo.absolutePath} -> ${uploadPath}`);
2486
-
2487
- const stats = fs.statSync(fileInfo.absolutePath);
2488
- const uploadResult = await this.uploadFile(
2489
- fileInfo.absolutePath,
2490
- uploadPath,
2491
- uploadUrl,
2492
- authRestToken,
2493
- authToken
2494
- );
2495
-
2496
- results.push({
2497
- file: fileInfo.absolutePath,
2498
- remotePath: uploadPath,
2499
- status: 'success',
2500
- uploadUrl: uploadResult.url,
2501
- size: stats.size
2502
- });
2503
-
2504
- successCount++;
2505
- this.log('info', `Successfully uploaded: ${uploadPath}`);
2506
-
2507
- } catch (error) {
2508
- const errorMessage = error instanceof Error ? error.message : String(error);
2509
- const normalizedRelativePath = this.normalizePath(fileInfo.relativePath);
2510
- const uploadPath = `wp-content/themes/${uploadDirName}/${normalizedRelativePath}`;
2511
-
2512
- results.push({
2513
- file: fileInfo.absolutePath,
2514
- remotePath: uploadPath,
2515
- status: 'error',
2516
- error: errorMessage
2517
- });
2518
-
2519
- failureCount++;
2520
- this.log('error', `Failed to upload ${fileInfo.absolutePath}: ${errorMessage}`);
2521
- }
2522
- }
2523
-
2524
- const overallStatus = failureCount === 0 ? 'success' : (successCount === 0 ? 'failure' : 'partial');
2525
-
2526
- if (failureCount === 0) {
2527
- try {
2528
- this.log('info', 'All files uploaded successfully, triggering theme deployment...');
2529
- await this.hosting_deployWordpressTheme_deployTheme(username, domain, slug, uploadDirName, activate);
2530
- } catch (error) {
2531
- const errorMessage = error instanceof Error ? error.message : String(error);
2532
- this.log('error', `Theme deployment failed: ${errorMessage}`);
2533
- return {
2534
- status: 'partial',
2535
- summary: {
2536
- total: themeFiles.length,
2537
- successful: successCount,
2538
- failed: failureCount
2539
- },
2540
- results,
2541
- ...(skipped.length > 0 ? { skippedFiles: skipped } : {}),
2542
- deploymentError: errorMessage
2543
- };
2544
- }
2545
- }
2546
-
2547
- return {
2548
- status: overallStatus,
2549
- summary: {
2550
- total: themeFiles.length,
2551
- successful: successCount,
2552
- failed: failureCount
2553
- },
2554
- results,
2555
- ...(skipped.length > 0 ? { skippedFiles: skipped } : {}),
2556
- uploadDirName,
2557
- activated: activate
2558
- };
2559
- }
2560
-
2561
- hosting_deployJsApplication_validateArchiveFormat(filePath) {
2562
- const validExtensions = ['zip', 'tar', 'tar.gz', 'tgz', '7z', 'gz', 'gzip'];
2563
- const fileName = path.basename(filePath).toLowerCase();
2564
-
2565
- for (const ext of validExtensions) {
2566
- if (fileName.endsWith(`.${ext}`)) {
2567
- return true;
2568
- }
2569
- }
2570
-
2571
- return false;
2572
- }
2573
-
2574
- hosting_deployJsApplication_validateRequiredParams(params) {
2575
- const { domain, archivePath, removeArchive } = params;
2576
-
2577
- if (!domain || typeof domain !== 'string') {
2578
- throw new Error('domain is required and must be a string');
2579
- }
2580
-
2581
- if (!archivePath || typeof archivePath !== 'string') {
2582
- throw new Error('archivePath is required and must be a string');
2583
- }
2584
-
2585
- if (removeArchive !== undefined && typeof removeArchive !== 'boolean') {
2586
- throw new Error('removeArchive must be a boolean if provided');
2587
- }
2588
- }
2589
-
2590
- hosting_deployJsApplication_removeArchive(archivePath, removeArchive) {
2591
- if (!removeArchive) {
2592
- return false;
2593
- }
2594
-
2595
- try {
2596
- this.log('info', `Removing archive file: ${archivePath}`);
2597
- fs.unlinkSync(archivePath);
2598
- this.log('info', `Successfully removed archive file: ${archivePath}`);
2599
- return true;
2600
- } catch (error) {
2601
- const errorMessage = error instanceof Error ? error.message : String(error);
2602
- this.log('error', `Failed to remove archive file: ${errorMessage}`);
2603
- // Don't fail the entire operation if archive removal fails
2604
- return false;
2605
- }
2606
- }
2607
-
2608
- hosting_deployJsApplication_validateArchiveFile(archivePath) {
2609
- this.assertDeployablePath(archivePath);
2610
- if (!fs.existsSync(archivePath)) {
2611
- throw new Error(`Archive file not found: ${archivePath}`);
2612
- }
2613
-
2614
- const archiveStats = fs.statSync(archivePath);
2615
- if (!archiveStats.isFile()) {
2616
- throw new Error(`Archive path is not a file: ${archivePath}`);
2617
- }
2618
-
2619
- if (!this.hosting_deployJsApplication_validateArchiveFormat(archivePath)) {
2620
- throw new Error('Invalid archive format. Supported formats: zip, tar, tar.gz, tgz, 7z, gz, gzip');
2621
- }
2622
- }
2623
-
2624
- async hosting_deployJsApplication_fetchBuildSettings(username, domain, archivePath) {
2625
- const baseUrl = this.baseUrl.endsWith("/") ? this.baseUrl : `${this.baseUrl}/`;
2626
- const archiveBasename = path.basename(archivePath);
2627
- const url = new URL(`api/hosting/v1/accounts/${username}/websites/${domain}/nodejs/builds/settings/from-archive?archive_path=${encodeURIComponent(archiveBasename)}`, baseUrl).toString();
2628
-
2629
- try {
2630
- const bearerToken = await this.getAuthToken();
2631
-
2632
- const config = {
2633
- method: 'get',
2634
- url,
2635
- headers: {
2636
- ...this.headers,
2637
- 'Authorization': `Bearer ${bearerToken}`
2638
- },
2639
- timeout: 60000, // 60s
2640
- validateStatus: function (status) {
2641
- return status < 500;
2642
- }
2643
- };
2644
-
2645
- const response = await axios(config);
2646
-
2647
- if (response.status !== 200) {
2648
- throw new Error(`API returned status ${response.status}: ${JSON.stringify(response.data)}`);
2649
- }
2650
-
2651
- this.log('info', `Successfully fetched build settings for ${domain}`);
2652
- return response.data;
2653
-
2654
- } catch (error) {
2655
- const errorMessage = error instanceof Error ? error.message : String(error);
2656
- this.log('error', `Failed to fetch build settings: ${errorMessage}`);
2657
-
2658
- if (axios.isAxiosError(error)) {
2659
- const responseData = error.response?.data;
2660
- const responseStatus = error.response?.status;
2661
- this.log('error', 'API Error Details:', {
2662
- status: responseStatus,
2663
- data: typeof responseData === 'object' ? JSON.stringify(responseData) : responseData
2664
- });
2665
- }
2666
-
2667
- throw error;
2668
- }
2669
- }
2670
-
2671
- async hosting_deployJsApplication_triggerBuild(username, domain, archivePath, buildSettings) {
2672
- const baseUrl = this.baseUrl.endsWith("/") ? this.baseUrl : `${this.baseUrl}/`;
2673
- const url = new URL(`api/hosting/v1/accounts/${username}/websites/${domain}/nodejs/builds`, baseUrl).toString();
2674
-
2675
- try {
2676
- const bearerToken = await this.getAuthToken();
2677
-
2678
- const archiveBasename = path.basename(archivePath);
2679
- const buildData = {
2680
- ...buildSettings,
2681
- node_version: buildSettings?.node_version || 20,
2682
- source_type: 'archive',
2683
- source_options: {
2684
- archive_path: archiveBasename
2685
- }
2686
- };
2687
-
2688
- const config = {
2689
- method: 'post',
2690
- url,
2691
- headers: {
2692
- ...this.headers,
2693
- 'Authorization': `Bearer ${bearerToken}`,
2694
- 'Content-Type': 'application/json'
2695
- },
2696
- data: buildData,
2697
- timeout: 60000, // 60s
2698
- validateStatus: function (status) {
2699
- return status < 500;
2700
- }
2701
- };
2702
-
2703
- const response = await axios(config);
2704
-
2705
- if (response.status !== 200) {
2706
- throw new Error(`API returned status ${response.status}: ${JSON.stringify(response.data)}`);
2707
- }
2708
-
2709
- this.log('info', `Successfully triggered build for ${domain}`);
2710
- return response.data;
2711
-
2712
- } catch (error) {
2713
- const errorMessage = error instanceof Error ? error.message : String(error);
2714
- this.log('error', `Failed to trigger build: ${errorMessage}`);
2715
-
2716
- if (axios.isAxiosError(error)) {
2717
- const responseData = error.response?.data;
2718
- const responseStatus = error.response?.status;
2719
- this.log('error', 'API Error Details:', {
2720
- status: responseStatus,
2721
- data: typeof responseData === 'object' ? JSON.stringify(responseData) : responseData
2722
- });
2723
- }
2724
-
2725
- throw error;
2726
- }
2727
- }
2728
-
2729
- async handleJavascriptApplicationDeploy(params) {
2730
- const { domain, archivePath, removeArchive = false } = params;
2731
-
2732
- this.hosting_deployJsApplication_validateRequiredParams(params);
2733
- this.hosting_deployJsApplication_validateArchiveFile(archivePath);
2734
-
2735
- // Auto-resolve username from domain
2736
- this.log('info', `Resolving username from domain: ${domain}`);
2737
- const username = await this.resolveUsername(domain);
2738
-
2739
- // Upload archive file
2740
- this.log('info', `Starting archive upload for ${domain}`);
2741
-
2742
- let uploadCredentials;
2743
- try {
2744
- uploadCredentials = await this.fetchUploadCredentials(username, domain);
2745
- } catch (error) {
2746
- const errorMessage = error instanceof Error ? error.message : String(error);
2747
- throw new Error(`Failed to fetch upload credentials: ${errorMessage}`);
2748
- }
2749
-
2750
- const { url: uploadUrl, auth_key: authToken, rest_auth_key: authRestToken } = uploadCredentials;
2751
-
2752
- if (!uploadUrl || !authToken || !authRestToken) {
2753
- throw new Error('Invalid upload credentials received from API');
2754
- }
2755
-
2756
- const archiveBasename = path.basename(archivePath);
2757
- let uploadResult;
2758
- try {
2759
- const stats = fs.statSync(archivePath);
2760
- uploadResult = await this.uploadFile(
2761
- archivePath,
2762
- archiveBasename,
2763
- uploadUrl,
2764
- authRestToken,
2765
- authToken
2766
- );
2767
-
2768
- this.log('info', `Successfully uploaded archive: ${archiveBasename}`);
2769
- } catch (error) {
2770
- const errorMessage = error instanceof Error ? error.message : String(error);
2771
- throw new Error(`Failed to upload archive: ${errorMessage}`);
2772
- }
2773
-
2774
- // Fetch build settings
2775
- let buildSettings;
2776
- try {
2777
- this.log('info', `Fetching build settings for ${domain}`);
2778
- buildSettings = await this.hosting_deployJsApplication_fetchBuildSettings(username, domain, archivePath);
2779
- } catch (error) {
2780
- const errorMessage = error instanceof Error ? error.message : String(error);
2781
- this.log('error', `Failed to fetch build settings: ${errorMessage}`);
2782
-
2783
- return {
2784
- upload: {
2785
- status: 'success',
2786
- data: {
2787
- filename: uploadResult.filename
2788
- }
2789
- },
2790
- resolveSettings: {
2791
- status: 'error',
2792
- error: errorMessage
2793
- },
2794
- build: {
2795
- status: 'skipped'
2796
- },
2797
- removeArchive: {
2798
- status: 'skipped'
2799
- }
2800
- };
2801
- }
2802
-
2803
- // Trigger build
2804
- let buildResult;
2805
- try {
2806
- this.log('info', `Triggering build for ${domain}`);
2807
- buildResult = await this.hosting_deployJsApplication_triggerBuild(username, domain, archivePath, buildSettings);
2808
- } catch (error) {
2809
- const errorMessage = error instanceof Error ? error.message : String(error);
2810
- this.log('error', `Failed to trigger build: ${errorMessage}`);
2811
-
2812
- return {
2813
- upload: {
2814
- status: 'success',
2815
- data: {
2816
- filename: uploadResult.filename
2817
- }
2818
- },
2819
- resolveSettings: {
2820
- status: 'success',
2821
- data: buildSettings
2822
- },
2823
- build: {
2824
- status: 'error',
2825
- error: errorMessage
2826
- },
2827
- removeArchive: {
2828
- status: 'skipped'
2829
- }
2830
- };
2831
- }
2832
-
2833
- const archiveRemoved = this.hosting_deployJsApplication_removeArchive(archivePath, removeArchive);
2834
-
2835
- return {
2836
- upload: {
2837
- status: 'success',
2838
- data: {
2839
- filename: uploadResult.filename
2840
- }
2841
- },
2842
- resolveSettings: {
2843
- status: 'success',
2844
- data: buildSettings
2845
- },
2846
- build: {
2847
- status: 'success',
2848
- data: buildResult
2849
- },
2850
- removeArchive: {
2851
- status: archiveRemoved ? 'success' : 'skipped'
2852
- }
2853
- };
2854
- }
2855
-
2856
- hosting_deployStaticWebsite_validateArchiveFormat(filePath) {
2857
- const validExtensions = ['zip', 'tar', 'tar.gz', 'tgz', '7z', 'gz', 'gzip'];
2858
- const fileName = path.basename(filePath).toLowerCase();
2859
-
2860
- for (const ext of validExtensions) {
2861
- if (fileName.endsWith(`.${ext}`)) {
2862
- return true;
2863
- }
2864
- }
2865
-
2866
- return false;
2867
- }
2868
-
2869
- hosting_deployStaticWebsite_validateRequiredParams(params) {
2870
- const { domain, archivePath, removeArchive } = params;
2871
-
2872
- if (!domain || typeof domain !== 'string') {
2873
- throw new Error('domain is required and must be a string');
2874
- }
2875
-
2876
- if (!archivePath || typeof archivePath !== 'string') {
2877
- throw new Error('archivePath is required and must be a string');
2878
- }
2879
-
2880
- if (removeArchive !== undefined && typeof removeArchive !== 'boolean') {
2881
- throw new Error('removeArchive must be a boolean if provided');
2882
- }
2883
- }
2884
-
2885
- hosting_deployStaticWebsite_removeArchive(archivePath, removeArchive) {
2886
- if (!removeArchive) {
2887
- return false;
2888
- }
2889
-
2890
- try {
2891
- this.log('info', `Removing archive file: ${archivePath}`);
2892
- fs.unlinkSync(archivePath);
2893
- this.log('info', `Successfully removed archive file: ${archivePath}`);
2894
- return true;
2895
- } catch (error) {
2896
- const errorMessage = error instanceof Error ? error.message : String(error);
2897
- this.log('error', `Failed to remove archive file: ${errorMessage}`);
2898
- return false;
2899
- }
2900
- }
2901
-
2902
- hosting_deployStaticWebsite_validateArchiveFile(archivePath) {
2903
- this.assertDeployablePath(archivePath);
2904
- if (!fs.existsSync(archivePath)) {
2905
- throw new Error(`Archive file not found: ${archivePath}`);
2906
- }
2907
-
2908
- const archiveStats = fs.statSync(archivePath);
2909
- if (!archiveStats.isFile()) {
2910
- throw new Error(`Archive path is not a file: ${archivePath}`);
2911
- }
2912
-
2913
- if (!this.hosting_deployStaticWebsite_validateArchiveFormat(archivePath)) {
2914
- throw new Error('Invalid archive format. Supported formats: zip, tar, tar.gz, tgz, 7z, gz, gzip');
2915
- }
2916
- }
2917
-
2918
- async hosting_deployStaticWebsite_triggerDeploy(username, domain, archivePath) {
2919
- const baseUrl = this.baseUrl.endsWith("/") ? this.baseUrl : `${this.baseUrl}/`;
2920
- const url = new URL(`api/hosting/v1/accounts/${username}/websites/${domain}/deploy`, baseUrl).toString();
2921
-
2922
- try {
2923
- const bearerToken = await this.getAuthToken();
2924
-
2925
- const archiveBasename = path.basename(archivePath);
2926
- const deployData = {
2927
- archive_path: archiveBasename
2928
- };
2929
-
2930
- const config = {
2931
- method: 'post',
2932
- url,
2933
- headers: {
2934
- ...this.headers,
2935
- 'Authorization': `Bearer ${bearerToken}`,
2936
- 'Content-Type': 'application/json'
2937
- },
2938
- data: deployData,
2939
- timeout: 60000,
2940
- validateStatus: function (status) {
2941
- return status < 500;
2942
- }
2943
- };
2944
-
2945
- const response = await axios(config);
2946
-
2947
- if (response.status !== 200) {
2948
- throw new Error(`API returned status ${response.status}: ${JSON.stringify(response.data)}`);
2949
- }
2950
-
2951
- this.log('info', `Successfully triggered deployment for ${domain}`);
2952
- return response.data;
2953
-
2954
- } catch (error) {
2955
- const errorMessage = error instanceof Error ? error.message : String(error);
2956
- this.log('error', `Failed to trigger deployment: ${errorMessage}`);
2957
-
2958
- if (axios.isAxiosError(error)) {
2959
- const responseData = error.response?.data;
2960
- const responseStatus = error.response?.status;
2961
- this.log('error', 'API Error Details:', {
2962
- status: responseStatus,
2963
- data: typeof responseData === 'object' ? JSON.stringify(responseData) : responseData
2964
- });
2965
- }
2966
-
2967
- throw error;
2968
- }
2969
- }
2970
-
2971
- async handleStaticWebsiteDeploy(params) {
2972
- const { domain, archivePath, removeArchive = false } = params;
2973
-
2974
- this.hosting_deployStaticWebsite_validateRequiredParams(params);
2975
- this.hosting_deployStaticWebsite_validateArchiveFile(archivePath);
2976
-
2977
- this.log('info', `Resolving username from domain: ${domain}`);
2978
- const username = await this.resolveUsername(domain);
2979
-
2980
- this.log('info', `Starting archive upload for ${domain}`);
2981
-
2982
- let uploadCredentials;
2983
- try {
2984
- uploadCredentials = await this.fetchUploadCredentials(username, domain);
2985
- } catch (error) {
2986
- const errorMessage = error instanceof Error ? error.message : String(error);
2987
- throw new Error(`Failed to fetch upload credentials: ${errorMessage}`);
2988
- }
2989
-
2990
- const { url: uploadUrl, auth_key: authToken, rest_auth_key: authRestToken } = uploadCredentials;
2991
-
2992
- if (!uploadUrl || !authToken || !authRestToken) {
2993
- throw new Error('Invalid upload credentials received from API');
2994
- }
2995
-
2996
- const archiveBasename = path.basename(archivePath);
2997
- let uploadResult;
2998
- try {
2999
- const stats = fs.statSync(archivePath);
3000
- uploadResult = await this.uploadFile(
3001
- archivePath,
3002
- archiveBasename,
3003
- uploadUrl,
3004
- authRestToken,
3005
- authToken
3006
- );
3007
-
3008
- this.log('info', `Successfully uploaded archive: ${archiveBasename}`);
3009
- } catch (error) {
3010
- const errorMessage = error instanceof Error ? error.message : String(error);
3011
- throw new Error(`Failed to upload archive: ${errorMessage}`);
3012
- }
3013
-
3014
- let deployResult;
3015
- try {
3016
- this.log('info', `Triggering deployment for ${domain}`);
3017
- deployResult = await this.hosting_deployStaticWebsite_triggerDeploy(username, domain, archivePath);
3018
- } catch (error) {
3019
- const errorMessage = error instanceof Error ? error.message : String(error);
3020
- this.log('error', `Failed to trigger deployment: ${errorMessage}`);
3021
-
3022
- return {
3023
- upload: {
3024
- status: 'success',
3025
- data: {
3026
- filename: uploadResult.filename
3027
- }
3028
- },
3029
- deploy: {
3030
- status: 'error',
3031
- error: errorMessage
3032
- },
3033
- removeArchive: {
3034
- status: 'skipped'
3035
- }
3036
- };
3037
- }
3038
-
3039
- const archiveRemoved = this.hosting_deployStaticWebsite_removeArchive(archivePath, removeArchive);
3040
-
3041
- return {
3042
- upload: {
3043
- status: 'success',
3044
- data: {
3045
- filename: uploadResult.filename
3046
- }
3047
- },
3048
- deploy: {
3049
- status: 'success',
3050
- data: deployResult
3051
- },
3052
- removeArchive: {
3053
- status: archiveRemoved ? 'success' : 'skipped'
3054
- }
3055
- };
3056
- }
3057
-
3058
- hosting_listJsDeployments_validateRequiredParams(params) {
3059
- const { domain } = params;
3060
-
3061
- if (!domain || typeof domain !== 'string') {
3062
- throw new Error('domain is required and must be a string');
3063
- }
3064
- }
3065
-
3066
- hosting_listJsDeployments_buildQueryParams(params) {
3067
- const { page, perPage, states } = params;
3068
- const queryParams = new URLSearchParams();
3069
-
3070
- if (page !== undefined && page !== null) {
3071
- queryParams.append('page', page.toString());
3072
- }
3073
-
3074
- if (perPage !== undefined && perPage !== null) {
3075
- queryParams.append('per_page', perPage.toString());
3076
- }
3077
-
3078
- if (states && Array.isArray(states) && states.length > 0) {
3079
- states.forEach(state => {
3080
- queryParams.append('states[]', state);
3081
- });
3082
- }
3083
-
3084
- return queryParams.toString();
3085
- }
3086
-
3087
- async hosting_listJsDeployments_fetchDeployments(username, domain, queryParams) {
3088
- const baseUrl = this.baseUrl.endsWith("/") ? this.baseUrl : `${this.baseUrl}/`;
3089
- const url = new URL(`api/hosting/v1/accounts/${username}/websites/${domain}/nodejs/builds`, baseUrl).toString();
3090
-
3091
- const fullUrl = queryParams ? `${url}?${queryParams}` : url;
3092
-
3093
- try {
3094
- const bearerToken = await this.getAuthToken();
3095
-
3096
- const config = {
3097
- method: 'get',
3098
- url: fullUrl,
3099
- headers: {
3100
- ...this.headers,
3101
- 'Authorization': `Bearer ${bearerToken}`
3102
- },
3103
- timeout: 60000, // 60s
3104
- validateStatus: function (status) {
3105
- return status < 500;
3106
- }
3107
- };
3108
-
3109
- const response = await axios(config);
3110
-
3111
- if (response.status !== 200) {
3112
- throw new Error(`API returned status ${response.status}: ${JSON.stringify(response.data)}`);
3113
- }
3114
-
3115
- this.log('info', `Successfully fetched deployments for ${domain}`);
3116
- return response.data;
3117
-
3118
- } catch (error) {
3119
- const errorMessage = error instanceof Error ? error.message : String(error);
3120
- this.log('error', `Failed to fetch deployments: ${errorMessage}`);
3121
-
3122
- if (axios.isAxiosError(error)) {
3123
- const responseData = error.response?.data;
3124
- const responseStatus = error.response?.status;
3125
- this.log('error', 'API Error Details:', {
3126
- status: responseStatus,
3127
- data: typeof responseData === 'object' ? JSON.stringify(responseData) : responseData
3128
- });
3129
- }
3130
-
3131
- throw error;
3132
- }
3133
- }
3134
-
3135
- async handleListJavascriptDeployments(params) {
3136
- const { domain, page, perPage, states } = params;
3137
-
3138
- this.hosting_listJsDeployments_validateRequiredParams(params);
3139
-
3140
- // Auto-resolve username from domain
3141
- this.log('info', `Resolving username from domain: ${domain}`);
3142
- const username = await this.resolveUsername(domain);
3143
-
3144
- // Build query parameters
3145
- const queryParams = this.hosting_listJsDeployments_buildQueryParams(params);
3146
-
3147
- // Fetch deployments
3148
- let deployments;
3149
- try {
3150
- this.log('info', `Fetching deployments for ${domain}`);
3151
- deployments = await this.hosting_listJsDeployments_fetchDeployments(username, domain, queryParams);
3152
- } catch (error) {
3153
- const errorMessage = error instanceof Error ? error.message : String(error);
3154
- this.log('error', `Failed to fetch deployments: ${errorMessage}`);
3155
- throw error;
3156
- }
3157
-
3158
- return {
3159
- status: 'success',
3160
- domain,
3161
- username,
3162
- queryParams: {
3163
- page,
3164
- perPage,
3165
- states
3166
- },
3167
- deployments
3168
- };
3169
- }
3170
-
3171
- hosting_showJsDeploymentLogs_validateRequiredParams(params) {
3172
- const { domain, buildUuid, fromLine } = params;
3173
-
3174
- if (!domain || typeof domain !== 'string') {
3175
- throw new Error('domain is required and must be a string');
3176
- }
3177
-
3178
- if (!buildUuid || typeof buildUuid !== 'string') {
3179
- throw new Error('buildUuid is required and must be a string');
3180
- }
3181
-
3182
- if (fromLine !== undefined && (typeof fromLine !== 'number' || !Number.isInteger(fromLine) || fromLine < 0)) {
3183
- throw new Error('fromLine must be a non-negative integer when provided');
3184
- }
3185
- }
3186
-
3187
- hosting_showJsDeploymentLogs_buildQueryParams(params) {
3188
- const { fromLine } = params;
3189
- const queryParams = new URLSearchParams();
3190
-
3191
- const line = (typeof fromLine === 'number' && Number.isInteger(fromLine) && fromLine >= 0) ? fromLine : 0;
3192
- queryParams.append('from_line', line.toString());
3193
-
3194
- return queryParams.toString();
3195
- }
3196
-
3197
- async hosting_showJsDeploymentLogs_fetchLogs(username, domain, buildUuid, queryParams) {
3198
- const baseUrl = this.baseUrl.endsWith("/") ? this.baseUrl : `${this.baseUrl}/`;
3199
- const url = new URL(`api/hosting/v1/accounts/${username}/websites/${domain}/nodejs/builds/${buildUuid}/logs`, baseUrl).toString();
3200
-
3201
- const fullUrl = queryParams ? `${url}?${queryParams}` : url;
3202
-
3203
- try {
3204
- const bearerToken = await this.getAuthToken();
3205
-
3206
- const config = {
3207
- method: 'get',
3208
- url: fullUrl,
3209
- headers: {
3210
- ...this.headers,
3211
- 'Authorization': `Bearer ${bearerToken}`
3212
- },
3213
- timeout: 60000,
3214
- validateStatus: function (status) {
3215
- return status < 500;
3216
- }
3217
- };
3218
-
3219
- const response = await axios(config);
3220
-
3221
- if (response.status !== 200) {
3222
- throw new Error(`API returned status ${response.status}: ${JSON.stringify(response.data)}`);
3223
- }
3224
-
3225
- this.log('info', `Successfully fetched logs for ${domain} build ${buildUuid}`);
3226
- return response.data;
3227
-
3228
- } catch (error) {
3229
- const errorMessage = error instanceof Error ? error.message : String(error);
3230
- this.log('error', `Failed to fetch logs: ${errorMessage}`);
3231
-
3232
- if (axios.isAxiosError(error)) {
3233
- const responseData = error.response?.data;
3234
- const responseStatus = error.response?.status;
3235
- this.log('error', 'API Error Details:', {
3236
- status: responseStatus,
3237
- data: typeof responseData === 'object' ? JSON.stringify(responseData) : responseData
3238
- });
3239
- }
3240
-
3241
- throw error;
3242
- }
3243
- }
3244
-
3245
- async handleShowJsDeploymentLogs(params) {
3246
- const { domain, buildUuid, fromLine } = params;
3247
-
3248
- this.hosting_showJsDeploymentLogs_validateRequiredParams(params);
3249
-
3250
- this.log('info', `Resolving username from domain: ${domain}`);
3251
- const username = await this.resolveUsername(domain);
3252
-
3253
- const queryParams = this.hosting_showJsDeploymentLogs_buildQueryParams(params);
3254
-
3255
- let logs;
3256
- try {
3257
- this.log('info', `Fetching logs for ${domain}, build ${buildUuid}`);
3258
- logs = await this.hosting_showJsDeploymentLogs_fetchLogs(username, domain, buildUuid, queryParams);
3259
- } catch (error) {
3260
- const errorMessage = error instanceof Error ? error.message : String(error);
3261
- this.log('error', `Failed to fetch logs: ${errorMessage}`);
3262
- throw error;
3263
- }
3264
-
3265
- const effectiveFromLine = (typeof fromLine === 'number' && Number.isInteger(fromLine) && fromLine >= 0) ? fromLine : 0;
3266
-
3267
- return {
3268
- domain,
3269
- username,
3270
- buildUuid,
3271
- fromLine: effectiveFromLine,
3272
- logs
3273
- };
3274
- }
3275
-
3276
1795
  async handleHostingTriggerWebsiteEvent(params) {
3277
1796
  const { username, domain, event } = params;
3278
1797
  const baseUrl = this.baseUrl.endsWith("/") ? this.baseUrl : `${this.baseUrl}/`;