Skip to content

Commit 76e5f0f

Browse files
committed
added operation api service
1 parent fc9a9cb commit 76e5f0f

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

.changeset/giant-plums-guess.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+
added operation api service

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
// export all the services
12
export * from "./services/Lists";
23
export * from "./services/core";
34
export * from "./services/projects";
5+
export * from "./services/operation";
46

7+
// export all the types
58
export * from "./services/Lists/types";
69
export * from "./services/core/types";
710
export * from "./services/projects/types";

src/services/core/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
2429
export function initializeCloudwaysApi(email: string, apiKey: string): void {
2530
config = { email, api_key: apiKey };
2631
}

src/services/operation/index.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
}

0 commit comments

Comments
 (0)