Skip to content

Commit e3b68ba

Browse files
committed
cambios en la libreria
1 parent c16e140 commit e3b68ba

File tree

10 files changed

+279
-379
lines changed

10 files changed

+279
-379
lines changed

src/services/app-management/index.ts

+84-138
Large diffs are not rendered by default.

src/services/application-vulnerability/index.ts

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { apiCall } from "../core";
22
import { HttpMethod } from "../core/types";
3+
import { getAndWaitForOperationStatusCompleted } from "../operation";
4+
import type { OperationStatus } from "../operation/types";
35

46
import type { ListApplicationVulnerabilitiesResponse } from "./types";
57

@@ -88,27 +90,22 @@ export function listApplicationVulnerabilities(
8890
* Initiates a refresh of application vulnerabilities.
8991
* @param {number} appId - The numeric ID of the application.
9092
* @param {number} serverId - The numeric ID of the server.
91-
* @returns {Promise<{status: boolean, operation_id: number}>} A Promise that resolves to an object containing the status and operation ID of the refresh operation.
93+
* @returns {Promise<OperationStatus>} A Promise that resolves to an object containing the status and operation ID of the refresh operation.
9294
* @example
9395
* {
9496
"status": true,
9597
"operation_id": 525888
9698
}
9799
*/
98-
export function refreshApplicationVulnerabilities(
100+
export async function refreshApplicationVulnerabilities(
99101
appId: number,
100102
serverId: number
101-
): Promise<{ status: boolean; operation_id: number }> {
103+
): Promise<OperationStatus> {
102104
const data = {
103105
app_id: appId,
104106
server_id: serverId,
105107
};
106-
return apiCall(
107-
`/app/vulnerabilities/${appId}/refresh`,
108-
HttpMethod.GET,
109-
data
110-
).then((response) => ({
111-
status: response.status,
112-
operation_id: response.operation_id,
113-
}));
108+
const req = await apiCall(`/app/vulnerabilities/${appId}/refresh`,HttpMethod.GET,data);
109+
return await getAndWaitForOperationStatusCompleted(req.operation_id);
110+
114111
}

src/services/application/index.ts

+24-44
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { OperationStatus } from "../operation/types";
99
* @param {string} application App to be installed (e.g., "wordpress", "joomla").
1010
* @param {string} appLabel Name of the app.
1111
* @param {string} projectName (Optional) Name of the project to tag the newly created app with.
12-
* @returns {Promise< number >} A promise resolving with the operation id.
12+
* @returns {Promise<OperationStatus>} A promise resolving with the operation id.
1313
* @example
1414
* ```
1515
*
@@ -39,7 +39,7 @@ export async function addApp(
3939
* @param {number} serverId Numeric id of the server.
4040
* @param {number} appId Numeric id of the application.
4141
* @param {string} appLabel Name of the app.
42-
* @returns {Promise<{ appId: number, operationId: number }>} A promise resolving with the cloned app's id and operation id.
42+
* @returns {Promise<OperationStatus>} A promise resolving with the cloned app's id and operation id.
4343
* @example
4444
* ```
4545
* {
@@ -67,7 +67,7 @@ export async function cloneApp(
6767
* @param {number} serverId Numeric id of the source server.
6868
* @param {number} appId Numeric id of the application.
6969
* @param {number} destinationServerId Numeric id of the destination server.
70-
* @returns {Promise<{ sourceOperationId: number, destinationOperationId: number, appId: number }>} A promise resolving with the source and destination operation ids along with the cloned app's id.
70+
* @returns {Promise<OperationStatus>} A promise resolving with the source and destination operation ids along with the cloned app's id.
7171
* @example
7272
* ```
7373
* {
@@ -77,34 +77,26 @@ export async function cloneApp(
7777
* }
7878
* ```
7979
*/
80-
export function cloneAppToOtherServer(
80+
export async function cloneAppToOtherServer(
8181
serverId: number,
8282
appId: number,
8383
destinationServerId: number
84-
): Promise<{
85-
sourceOperationId: number;
86-
destinationOperationId: number;
87-
appId: number;
88-
}> {
84+
): Promise<OperationStatus> {
8985
const data = {
9086
server_id: serverId,
9187
app_id: appId,
9288
destination_server_id: destinationServerId,
9389
};
94-
return apiCall("/app/cloneToOtherServer", HttpMethod.POST, data).then(
95-
(response) => ({
96-
sourceOperationId: response.source_operation_id,
97-
destinationOperationId: response.destination_operation_id,
98-
appId: response.app_id,
99-
})
100-
);
90+
const req = await apiCall("/app/cloneToOtherServer", HttpMethod.POST, data);
91+
return await getAndWaitForOperationStatusCompleted(req.operation_id);
92+
10193
}
10294

10395
/**
10496
* Clone a staging app to the same server.
10597
* @param {number} serverId Numeric id of the server.
10698
* @param {number} appId Numeric id of the staging application.
107-
* @returns {Promise<{ appId: number, operationId: number }>} A promise resolving with the cloned staging app's id and operation id.
99+
* @returns {Promise<OperationStatus>} A promise resolving with the cloned staging app's id and operation id.
108100
* @example
109101
* ```
110102
* {
@@ -113,28 +105,24 @@ export function cloneAppToOtherServer(
113105
* }
114106
* ```
115107
*/
116-
export function cloneStagingApp(
108+
export async function cloneStagingApp(
117109
serverId: number,
118110
appId: number
119-
): Promise<{ appId: number; operationId: number }> {
111+
): Promise<OperationStatus> {
120112
const data = {
121113
server_id: serverId,
122114
app_id: appId,
123115
};
124-
return apiCall("/staging/app/cloneApp", HttpMethod.POST, data).then(
125-
(response) => ({
126-
appId: response.app_id,
127-
operationId: response.operation_id,
128-
})
129-
);
116+
const req = await apiCall("/staging/app/cloneApp", HttpMethod.POST, data);
117+
return await getAndWaitForOperationStatusCompleted(req.destination_operation_id);
130118
}
131119

132120
/**
133121
* Clone a staging app to another existing server.
134122
* @param {number} serverId Numeric id of the source server.
135123
* @param {number} appId Numeric id of the staging application.
136124
* @param {number} destinationServerId Numeric id of the destination server.
137-
* @returns {Promise<{ sourceOperationId: number, destinationOperationId: number, appId: number }>} A promise resolving with the operation ids and the cloned staging app's id.
125+
* @returns {Promise<OperationStatus>} A promise resolving with the operation ids and the cloned staging app's id.
138126
* @example
139127
* ```
140128
* {
@@ -144,46 +132,38 @@ export function cloneStagingApp(
144132
* }
145133
* ```
146134
*/
147-
export function cloneStagingAppToOtherServer(
135+
export async function cloneStagingAppToOtherServer(
148136
serverId: number,
149137
appId: number,
150138
destinationServerId: number
151-
): Promise<{
152-
sourceOperationId: number;
153-
destinationOperationId: number;
154-
appId: number;
155-
}> {
139+
): Promise<OperationStatus> {
156140
const data = {
157141
server_id: serverId,
158142
app_id: appId,
159143
destination_server_id: destinationServerId,
160144
};
161-
return apiCall("/staging/app/cloneToOtherServer", HttpMethod.POST, data).then(
162-
(response) => ({
163-
sourceOperationId: response.source_operation_id,
164-
destinationOperationId: response.destination_operation_id,
165-
appId: response.app_id,
166-
})
167-
);
145+
const req = await apiCall("/staging/app/cloneToOtherServer", HttpMethod.POST, data);
146+
return await getAndWaitForOperationStatusCompleted(req.destination_operation_id);
168147
}
169148

170149
/**
171150
* Start the process of removing an app.
172151
* @param {number} serverId Numeric id of the server.
173152
* @param {number} appId Numeric id of the application.
174-
* @returns {Promise<number>} A promise resolving with the operation id.
153+
* @returns {Promise<OperationStatus>} A promise resolving with the operation id.
175154
* @example
176155
* ```
177156
* 12345
178157
* ```
179158
*/
180-
export function startRemoveAppProcess(
159+
export async function DeleteApp(
181160
serverId: number,
182161
appId: number
183-
): Promise<number> {
184-
return apiCall(`/app/${appId}`, HttpMethod.DELETE, {
162+
): Promise<OperationStatus> {
163+
const req = await apiCall(`/app/${appId}`, HttpMethod.DELETE, {
185164
server_id: serverId,
186-
}).then((response) => response.operation_id);
165+
});
166+
return await getAndWaitForOperationStatusCompleted(req.operation_id);
187167
}
188168

189169
/**

src/services/bot-protection/index.ts

+17-25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { apiCall } from "../core";
22
import { HttpMethod } from "../core/types";
3+
import { getAndWaitForOperationStatusCompleted } from "../operation";
4+
import type { OperationStatus } from "../operation/types";
35
import type {
46
BotProtectionTrafficResponse,
57
BotProtectionTrafficSummaryResponse,
@@ -251,51 +253,45 @@ export function BotProtectionWhiteListedBots(
251253
* Activates bot protection for a specific server and application.
252254
* @param {number} serverId - The numeric ID of the server.
253255
* @param {number} appId - The numeric ID of the application.
254-
* @returns {Promise<{ operation_id: number }>} A Promise that resolves with the operation ID upon successful activation.
256+
* @returns {Promise<OperationStatus>} A Promise that resolves with the operation ID upon successful activation.
255257
* @example
256258
* {
257259
"operation_id": 12345
258260
}
259261
*/
260-
export function BotProtectionActivation(
262+
export async function BotProtectionActivation(
261263
serverId: number,
262264
appId: number
263-
): Promise<{ operation_id: number }> {
265+
): Promise<OperationStatus>{
264266
const data = {
265267
server_id: serverId,
266268
app_id: appId,
267269
};
268-
return apiCall("/app/malcare/enable", HttpMethod.PUT, data).then(
269-
(response) => ({
270-
operation_id: response.operation_id,
271-
})
272-
);
270+
const req = await apiCall("/app/malcare/enable", HttpMethod.PUT, data);
271+
return await getAndWaitForOperationStatusCompleted(req.operation_id);
273272
}
274273

275274

276275
/**
277276
* Deactivates bot protection for a specific server and application.
278277
* @param {number} serverId - The numeric ID of the server.
279278
* @param {number} appId - The numeric ID of the application.
280-
* @returns {Promise<{ operation_id: number }>} A Promise that resolves with the operation ID upon successful deactivation.
279+
* @returns {Promise<OperationStatus>} A Promise that resolves with the operation ID upon successful deactivation.
281280
* @example
282281
* {
283282
"operation_id": 12345
284283
}
285284
*/
286-
export function BotProtectionDeactivation(
285+
export async function BotProtectionDeactivation(
287286
serverId: number,
288287
appId: number
289-
): Promise<{ operation_id: number }> {
288+
): Promise<OperationStatus> {
290289
const data = {
291290
server_id: serverId,
292291
app_id: appId,
293292
};
294-
return apiCall("/app/malcare/disable", HttpMethod.PUT, data).then(
295-
(response) => ({
296-
operation_id: response.operation_id,
297-
})
298-
);
293+
const req = await apiCall("/app/malcare/disable", HttpMethod.PUT, data);
294+
return await getAndWaitForOperationStatusCompleted(req.operation_id);
299295
}
300296

301297
/**
@@ -371,27 +367,23 @@ export function BotProtectionBadBotsWhitelisting(
371367
*
372368
* @param {number} serverId - The numeric id of the server.
373369
* @param {number} appId - The numeric id of the application.
374-
* @returns {Promise<{ status: boolean, operation_id: number }>} A promise that resolves to an object containing the status and operation id of the cache purge operation.
370+
* @returns {Promise<OperationStatus>} A promise that resolves to an object containing the status and operation id of the cache purge operation.
375371
* @example
376372
* {
377373
"status": true,
378374
"operation_id": 12345
379375
}
380376
*/
381-
export function ClearAppCache(
377+
export async function ClearAppCache(
382378
serverId: number,
383379
appId: number
384-
): Promise<{ status : boolean, operation_id : number }> {
380+
): Promise<OperationStatus> {
385381
const data = {
386382
server_id: serverId,
387383
app_id: appId,
388384
};
389-
return apiCall("/app/cache/purge", HttpMethod.POST, data).then(
390-
(response) => ({
391-
status : response.status,
392-
operation_id : response.operation_id
393-
})
394-
);
385+
const req = await apiCall("/app/cache/purge", HttpMethod.POST, data);
386+
return await getAndWaitForOperationStatusCompleted(req.operation_id);
395387
}
396388

397389

0 commit comments

Comments
 (0)