Skip to content

Commit fc9a9cb

Browse files
committed
updated the jsdoc documentation
1 parent c658620 commit fc9a9cb

File tree

5 files changed

+187
-179
lines changed

5 files changed

+187
-179
lines changed

.changeset/angry-roses-cheer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cloudways-js-client": patch
3+
---
4+
5+
updated the jsdoc documentation

src/services/Lists/index.ts

Lines changed: 64 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,92 +2,104 @@ import { apiCall } from "../core";
22
import type {
33
BackupFrequency,
44
Country,
5-
GetAppListResponse,
6-
GetMonitorDurationsResponse,
7-
GetMonitorTargetsResponse,
8-
GetPackageListResponse,
9-
GetProviderListResponse,
10-
GetRegionListResponse,
11-
GetServerSizesListResponse,
12-
GetSettingsListResponse,
5+
App,
6+
Provider,
7+
Region,
8+
PackageType,
139
} from "./types";
1410

1511
/**
1612
* Gets a list of available cloud providers.
17-
* @returns Promise<GetProviderListResponse> - The response with cloud providers.
13+
* @returns {Promise<Provider[]>} A promise resolving with an array of cloud providers.
14+
* @example
15+
* ```
16+
* [
17+
* { "id": "do", "name": "DigitalOcean" },
18+
* { "id": "vultr", "name": "Vultr" },
19+
* ...
20+
* ]
21+
* ```
1822
*/
19-
export function getProviderList(): Promise<GetProviderListResponse> {
20-
return apiCall("/providers");
23+
export function getProviderList(): Promise<Provider[]> {
24+
return apiCall("/providers").then((response) => response.providers);
2125
}
2226

2327
/**
2428
* Gets a list of regions.
25-
* @returns Promise<GetRegionListResponse> - The response with regions.
29+
* @returns {Promise<Region[]>} A promise resolving with an array of regions.
30+
* @example
31+
* ```
32+
* [
33+
* { "id": "us-east-1", "name": "US N.Virginia" },
34+
* { "id": "us-west-1", "name": "California" },
35+
* ...
36+
* ]
37+
* ```
2638
*/
27-
export function getRegionList(): Promise<GetRegionListResponse> {
28-
return apiCall("/regions");
39+
export function getRegionList(): Promise<Region[]> {
40+
return apiCall("/regions").then((response) => {
41+
const regionsArray = Object.values(response.regions).flat();
42+
return regionsArray as Region[]; // Type assertion to Region[]
43+
});
2944
}
3045

31-
/**
32-
* Gets a list of server sizes available.
33-
* @returns Promise<GetServerSizesListResponse> - The response with server sizes.
34-
*/
35-
export function getServerSizesList(): Promise<GetServerSizesListResponse> {
36-
return apiCall("/server_sizes");
37-
}
38-
39-
/**
40-
* Gets a list of available apps and their versions.
41-
* @returns Promise<GetAppListResponse> - The response with available apps and their versions.
42-
*/
43-
export function getAppList(): Promise<GetAppListResponse> {
44-
return apiCall("/app");
45-
}
46-
47-
/**
48-
* Gets a list of available packages and versions.
49-
* @returns Promise<GetPackageListResponse> - The response with available packages and versions.
50-
*/
51-
export function getPackageList(): Promise<GetPackageListResponse> {
52-
return apiCall("/packages");
53-
}
54-
55-
/**
56-
* Gets a list of available settings and corresponding values.
57-
* @returns Promise<GetSettingsListResponse> - The response with settings.
58-
*/
59-
export function getSettingsList(): Promise<GetSettingsListResponse> {
60-
return apiCall("/settings");
61-
}
46+
// Similar updates for getServerSizesList, getAppList, getPackageList, getSettingsList
6247

6348
/**
6449
* Gets possible backup frequencies.
65-
* @returns Promise<GetBackupFrequenciesResponse> - The response with backup frequencies.
50+
* @returns {Promise<BackupFrequency[]>} A promise resolving with an array of backup frequencies.
51+
* @example
52+
* ```
53+
* [
54+
* { "id": "1h", "label": "1 Hour" },
55+
* { "id": "3h", "label": "3 Hours" },
56+
* ...
57+
* ]
58+
* ```
6659
*/
6760
export function getBackupFrequencies(): Promise<BackupFrequency[]> {
6861
return apiCall("/backup-frequencies");
6962
}
7063

7164
/**
7265
* Gets the list of countries.
73-
* @returns Promise<GetCountriesListResponse> - The response with the list of countries.
66+
* @returns {Promise<Country[]>} A promise resolving with the list of countries.
67+
* @example
68+
* ```
69+
* // The API response is an empty object "{}" for countries.
70+
* []
71+
* ```
7472
*/
7573
export function getCountriesList(): Promise<Country[]> {
76-
return apiCall("/countries");
74+
return apiCall("/countries").then((response) => response); // Assuming the response is an array of countries
7775
}
7876

7977
/**
8078
* Gets possible monitoring durations.
81-
* @returns Promise<GetMonitorDurationsResponse> - The response with monitoring durations.
79+
* @returns {Promise<string[]>} A promise resolving with monitoring durations.
80+
* @example
81+
* ```
82+
* ["1 Hour", "12 Hours", "1 Day", "7 Days", "1 Month", "6 Months"]
83+
* ```
8284
*/
83-
export function getMonitorDurations(): Promise<GetMonitorDurationsResponse> {
85+
export function getMonitorDurations(): Promise<string[]> {
8486
return apiCall("/monitor-durations");
8587
}
8688

8789
/**
8890
* Gets a list of server monitoring graph types.
89-
* @returns Promise<GetMonitorTargetsResponse> - The response with monitoring targets.
91+
* @returns {Promise<string[]>} A promise resolving with monitoring targets.
92+
* @example
93+
* ```
94+
* {
95+
* "amazon": ["Idle CPU", "Free Disk (DB)", ...],
96+
* "do": ["Idle CPU", "Free Disk", ...],
97+
* ...
98+
* }
99+
* ```
90100
*/
91-
export function getMonitorTargets(): Promise<GetMonitorTargetsResponse> {
101+
export function getMonitorTargets(): Promise<{ [provider: string]: string[] }> {
92102
return apiCall("/monitor-targets");
93103
}
104+
105+
// ... and similarly for other functions

src/services/core/index.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ let config: GetOAuthAccessTokenRequest = {
1313
let authToken: AuthToken | null = null;
1414

1515
/**
16-
* Initialize the Cloudways API with user configuration.
17-
* @param userConfig - User configuration for Cloudways API access.
16+
* Initializes the Cloudways API with user-provided configuration. This function
17+
* sets up the necessary credentials for subsequent API calls. It accepts the user's
18+
* email address and an API key generated from the Cloudways platform.
19+
*
20+
* @param {string} email - The email address used to access the Cloudways Platform.
21+
* @param {string} apiKey - The API key generated on the Cloudways Platform API Section.
22+
* @returns {void}
1823
*/
19-
export function initializeCloudwaysApi(userConfig: GetOAuthAccessTokenRequest) {
20-
config = userConfig;
24+
export function initializeCloudwaysApi(email: string, apiKey: string): void {
25+
config = { email, api_key: apiKey };
2126
}
2227

2328
/**
@@ -44,7 +49,11 @@ async function getNewToken(): Promise<void> {
4449
expiration: Date.now() + (response.data.expires_in - 300) * 1000,
4550
};
4651
} catch (error) {
47-
throw new Error("Error getting new token: " + error);
52+
throw new Error(
53+
`Error getting new token: ${
54+
error instanceof Error ? error.message : String(error)
55+
}`
56+
);
4857
}
4958
}
5059

@@ -80,6 +89,10 @@ export async function apiCall(
8089
});
8190
return response.data;
8291
} catch (error) {
83-
throw new Error("API call failed: " + error);
92+
throw new Error(
93+
`API call failed: ${
94+
error instanceof Error ? error.message : String(error)
95+
}`
96+
);
8497
}
8598
}

src/services/projects/index.ts

Lines changed: 81 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,105 @@
1-
import type {
2-
CreateProjectParams,
3-
CreateProjectResponse,
4-
DeleteProjectParams,
5-
GetProjectListResponse,
6-
UpdateProjectParams,
7-
UpdateProjectResponse,
8-
} from "./types";
91
import { apiCall } from "../core";
102
import { HttpMethod } from "../core/types";
3+
import type { Project } from "./types";
114

125
/**
13-
* Creates a new project by making a POST request to the specified API endpoint.
6+
* Creates a new project.
147
*
15-
* @param {CreateProjectParams} params The parameters required for creating a new project, including the project name and associated application IDs.
16-
* @returns {Promise<CreateProjectResponse>} A promise that resolves to the response of the project creation process.
17-
* @throws {Error} Throws an error if the request fails.
8+
* @param name - The name of the new project.
9+
* @param appIds - Comma-separated list of app IDs to attach to the project.
10+
* @returns {Promise<Project>} A promise resolving to the details of the newly created project.
11+
* @example
12+
* ```
13+
* // Example of a successful response:
14+
* {
15+
* "id": "1574",
16+
* "name": "Project Name",
17+
* "user_id": "12847",
18+
* "is_default": "0",
19+
* "created_at": "2016-07-13 13:28:58",
20+
* "updated_at": "0000-00-00 00:00:00",
21+
* "image": null
22+
* }
23+
* ```
1824
*/
1925
export async function createProject(
20-
params: CreateProjectParams
21-
): Promise<CreateProjectResponse> {
22-
return apiCall("/project", HttpMethod.POST, params);
26+
name: string,
27+
appIds: string
28+
): Promise<Project> {
29+
const data = {
30+
name,
31+
app_ids: appIds,
32+
};
33+
return apiCall("/project", HttpMethod.POST, data).then(
34+
(response) => response.project
35+
);
2336
}
2437

2538
/**
26-
* Deletes a project by making a DELETE request to the specified API endpoint.
39+
* Deletes a project by its ID.
2740
*
28-
* @param {DeleteProjectParams} params The parameters required for deleting a project, including the numeric project ID.
29-
* @returns {Promise<void>} A promise that resolves when the project is successfully deleted.
30-
* @throws {Error} Throws an error if the request fails.
41+
* @param id - The numeric ID of the project to delete.
42+
* @returns A promise that resolves when the project is deleted.
3143
*/
32-
export async function deleteProject(
33-
params: DeleteProjectParams
34-
): Promise<void> {
35-
return apiCall(`/project/${params.id}`, HttpMethod.DELETE);
44+
export async function deleteProject(id: number): Promise<void> {
45+
return apiCall(`/project/${id}`, HttpMethod.DELETE);
3646
}
3747

3848
/**
39-
* Retrieves a list of projects by making a GET request to the specified API endpoint.
49+
* Retrieves a list of all projects.
4050
*
41-
* @returns {Promise<GetProjectListResponse>} A promise that resolves to the response containing the list of projects.
42-
* @throws {Error} Throws an error if the request fails.
51+
* @returns {Promise<Project[]>} A promise resolving to an array of project details.
52+
* @example
53+
* ```
54+
* // Example of a successful response:
55+
* [
56+
* {
57+
* "id": "1",
58+
* "name": "Default project",
59+
* "user_id": "123",
60+
* "is_default": "1",
61+
* "created_at": "2016-04-14 15:48:35",
62+
* "image": "https://example.com/project_pic.png"
63+
* }
64+
* ]
65+
* ```
4366
*/
44-
export async function getProjectList(): Promise<GetProjectListResponse> {
45-
return apiCall("/project");
67+
export async function getProjectList(): Promise<Project[]> {
68+
return apiCall("/project").then((response) => response.projects);
4669
}
4770

4871
/**
49-
* Updates a project by making a PUT request to the specified API endpoint.
72+
* Updates an existing project.
5073
*
51-
* @param {UpdateProjectParams} params The parameters required for updating the project, including the project ID, new name, and associated application IDs.
52-
* @returns {Promise<UpdateProjectResponse>} A promise that resolves to the response of the project update process.
53-
* @throws {Error} Throws an error if the request fails.
74+
* @param id - The numeric ID of the project to update.
75+
* @param name - The new name of the project.
76+
* @param appIds - Comma-separated list of app IDs to attach to the project.
77+
* @returns {Promise<Project>} A promise resolving to the updated project details.
78+
* @example
79+
* ```
80+
* // Example of a successful response:
81+
* {
82+
* "id": "1574",
83+
* "name": "Updated Project Name",
84+
* "user_id": "12847",
85+
* "is_default": "0",
86+
* "created_at": "2016-07-13 13:28:58",
87+
* "updated_at": "2024-01-01 12:00:00",
88+
* "image": null
89+
* }
90+
* ```
5491
*/
5592
export async function updateProject(
56-
params: UpdateProjectParams
57-
): Promise<UpdateProjectResponse> {
58-
return apiCall(`/project/${params.id}`, HttpMethod.PUT, params);
93+
id: number,
94+
name: string,
95+
appIds: string
96+
): Promise<Project> {
97+
const data = {
98+
name,
99+
app_ids: appIds,
100+
};
101+
102+
return apiCall(`/project/${id}`, HttpMethod.PUT, data).then(
103+
(response) => response.project
104+
);
59105
}

0 commit comments

Comments
 (0)