File tree Expand file tree Collapse file tree 4 files changed +60
-0
lines changed Expand file tree Collapse file tree 4 files changed +60
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " cloudways-js-client " : patch
3+ ---
4+
5+ added operation api service
Original file line number Diff line number Diff line change 1+ // export all the services
12export * from "./services/Lists" ;
23export * from "./services/core" ;
34export * from "./services/projects" ;
5+ export * from "./services/operation" ;
46
7+ // export all the types
58export * from "./services/Lists/types" ;
69export * from "./services/core/types" ;
710export * from "./services/projects/types" ;
Original file line number Diff line number Diff line change @@ -17,10 +17,15 @@ let authToken: AuthToken | null = null;
1717 * sets up the necessary credentials for subsequent API calls. It accepts the user's
1818 * email address and an API key generated from the Cloudways platform.
1919 *
20+ * This function should be called once to configure the library. After initial setup,
21+ * the library will automatically handle token renewal, ensuring continued access
22+ * to the Cloudways API without needing to reinitialize or manually refresh tokens.
23+ *
2024 * @param {string } email - The email address used to access the Cloudways Platform.
2125 * @param {string } apiKey - The API key generated on the Cloudways Platform API Section.
2226 * @returns {void }
2327 */
28+
2429export function initializeCloudwaysApi ( email : string , apiKey : string ) : void {
2530 config = { email, api_key : apiKey } ;
2631}
Original file line number Diff line number Diff line change 1+ import { apiCall } from "../core" ;
2+ import { HttpMethod } from "../core/types" ;
3+
4+ // Define an interface for the operation status response
5+ interface OperationStatus {
6+ id : string ;
7+ type : string ;
8+ server_id : string ;
9+ estimated_time_remaining : string ;
10+ frontend_step_number : string ;
11+ status : string ;
12+ is_completed : string ;
13+ message : string ;
14+ app_id : string ;
15+ }
16+
17+ interface GetOperationStatusResponse {
18+ operation : OperationStatus ;
19+ }
20+
21+ /**
22+ * Gets the status of an operation that is running in the background.
23+ *
24+ * @param id - The numeric ID of the operation.
25+ * @returns {Promise<OperationStatus> } A promise resolving to the operation status details.
26+ * @example
27+ * ```
28+ * {
29+ * "operation": {
30+ * "id": "596283",
31+ * "type": "restarting_server",
32+ * "server_id": "50482",
33+ * "estimated_time_remaining": "2",
34+ * "frontend_step_number": "1",
35+ * "status": "Process is initiated",
36+ * "is_completed": "0",
37+ * "message": "Process is initiated",
38+ * "app_id": "0"
39+ * }
40+ * }
41+ * ```
42+ */
43+ export function getOperationStatus ( id : number ) : Promise < OperationStatus > {
44+ return apiCall ( `/operation/${ id } ` , HttpMethod . GET ) . then (
45+ ( response : GetOperationStatusResponse ) => response . operation
46+ ) ;
47+ }
You can’t perform that action at this time.
0 commit comments