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