|
| 1 | +import { apiCall } from "../core"; |
| 2 | +import { HttpMethod } from "../core/types"; |
| 3 | + |
| 4 | +/** |
| 5 | + * Start the process of adding an app to a server. |
| 6 | + * @param {number} serverId Numeric id of the server. |
| 7 | + * @param {string} application App to be installed (e.g., "wordpress", "joomla"). |
| 8 | + * @param {string} appLabel Name of the app. |
| 9 | + * @param {string} projectName (Optional) Name of the project to tag the newly created app with. |
| 10 | + * @returns {Promise< number >} A promise resolving with the operation id. |
| 11 | + * @example |
| 12 | + * ``` |
| 13 | + * |
| 14 | + * 12345 |
| 15 | + * |
| 16 | + * ``` |
| 17 | + */ |
| 18 | +export function startAddAppProcess( |
| 19 | + serverId: number, |
| 20 | + application: string, |
| 21 | + appLabel: string, |
| 22 | + projectName?: string |
| 23 | +): Promise<number> { |
| 24 | + const data = { |
| 25 | + server_id: serverId, |
| 26 | + application: application, |
| 27 | + app_label: appLabel, |
| 28 | + project_name: projectName || "", |
| 29 | + }; |
| 30 | + return apiCall("/app", HttpMethod.POST, data).then( |
| 31 | + (response) => response.operation_id |
| 32 | + ); |
| 33 | +} |
| 34 | + |
| 35 | +/** |
| 36 | + * Clone an app to the same server. |
| 37 | + * @param {number} serverId Numeric id of the server. |
| 38 | + * @param {number} appId Numeric id of the application. |
| 39 | + * @param {string} appLabel Name of the app. |
| 40 | + * @returns {Promise<{ appId: number, operationId: number }>} A promise resolving with the cloned app's id and operation id. |
| 41 | + * @example |
| 42 | + * ``` |
| 43 | + * { |
| 44 | + * "appId": 1111, |
| 45 | + * "operationId": 12345 |
| 46 | + * } |
| 47 | + * ``` |
| 48 | + */ |
| 49 | +export function cloneApp( |
| 50 | + serverId: number, |
| 51 | + appId: number, |
| 52 | + appLabel: string |
| 53 | +): Promise<{ appId: number; operationId: number }> { |
| 54 | + const data = { |
| 55 | + server_id: serverId, |
| 56 | + app_id: appId, |
| 57 | + app_label: appLabel, |
| 58 | + }; |
| 59 | + return apiCall("/app/clone", HttpMethod.POST, data).then((response) => ({ |
| 60 | + appId: response.app_id, |
| 61 | + operationId: response.operation_id, |
| 62 | + })); |
| 63 | +} |
| 64 | + |
| 65 | +/** |
| 66 | + * Clone an app to another existing server. |
| 67 | + * @param {number} serverId Numeric id of the source server. |
| 68 | + * @param {number} appId Numeric id of the application. |
| 69 | + * @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. |
| 71 | + * @example |
| 72 | + * ``` |
| 73 | + * { |
| 74 | + * "sourceOperationId": 12345, |
| 75 | + * "destinationOperationId": 12346, |
| 76 | + * "appId": 1111 |
| 77 | + * } |
| 78 | + * ``` |
| 79 | + */ |
| 80 | +export function cloneAppToOtherServer( |
| 81 | + serverId: number, |
| 82 | + appId: number, |
| 83 | + destinationServerId: number |
| 84 | +): Promise<{ |
| 85 | + sourceOperationId: number; |
| 86 | + destinationOperationId: number; |
| 87 | + appId: number; |
| 88 | +}> { |
| 89 | + const data = { |
| 90 | + server_id: serverId, |
| 91 | + app_id: appId, |
| 92 | + destination_server_id: destinationServerId, |
| 93 | + }; |
| 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 | + ); |
| 101 | +} |
| 102 | + |
| 103 | +/** |
| 104 | + * Clone a staging app to the same server. |
| 105 | + * @param {number} serverId Numeric id of the server. |
| 106 | + * @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. |
| 108 | + * @example |
| 109 | + * ``` |
| 110 | + * { |
| 111 | + * "appId": 1111, |
| 112 | + * "operationId": 12345 |
| 113 | + * } |
| 114 | + * ``` |
| 115 | + */ |
| 116 | +export function cloneStagingApp( |
| 117 | + serverId: number, |
| 118 | + appId: number |
| 119 | +): Promise<{ appId: number; operationId: number }> { |
| 120 | + const data = { |
| 121 | + server_id: serverId, |
| 122 | + app_id: appId, |
| 123 | + }; |
| 124 | + return apiCall("/staging/app/cloneApp", HttpMethod.POST, data).then( |
| 125 | + (response) => ({ |
| 126 | + appId: response.app_id, |
| 127 | + operationId: response.operation_id, |
| 128 | + }) |
| 129 | + ); |
| 130 | +} |
| 131 | + |
| 132 | +/** |
| 133 | + * Clone a staging app to another existing server. |
| 134 | + * @param {number} serverId Numeric id of the source server. |
| 135 | + * @param {number} appId Numeric id of the staging application. |
| 136 | + * @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. |
| 138 | + * @example |
| 139 | + * ``` |
| 140 | + * { |
| 141 | + * "sourceOperationId": 12345, |
| 142 | + * "destinationOperationId": 12346, |
| 143 | + * "appId": 1111 |
| 144 | + * } |
| 145 | + * ``` |
| 146 | + */ |
| 147 | +export function cloneStagingAppToOtherServer( |
| 148 | + serverId: number, |
| 149 | + appId: number, |
| 150 | + destinationServerId: number |
| 151 | +): Promise<{ |
| 152 | + sourceOperationId: number; |
| 153 | + destinationOperationId: number; |
| 154 | + appId: number; |
| 155 | +}> { |
| 156 | + const data = { |
| 157 | + server_id: serverId, |
| 158 | + app_id: appId, |
| 159 | + destination_server_id: destinationServerId, |
| 160 | + }; |
| 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 | + ); |
| 168 | +} |
| 169 | + |
| 170 | +/** |
| 171 | + * Start the process of removing an app. |
| 172 | + * @param {number} serverId Numeric id of the server. |
| 173 | + * @param {number} appId Numeric id of the application. |
| 174 | + * @returns {Promise<number>} A promise resolving with the operation id. |
| 175 | + * @example |
| 176 | + * ``` |
| 177 | + * 12345 |
| 178 | + * ``` |
| 179 | + */ |
| 180 | +export function startRemoveAppProcess( |
| 181 | + serverId: number, |
| 182 | + appId: number |
| 183 | +): Promise<number> { |
| 184 | + return apiCall(`/app/${appId}`, HttpMethod.DELETE, { |
| 185 | + server_id: serverId, |
| 186 | + }).then((response) => response.operation_id); |
| 187 | +} |
| 188 | + |
| 189 | +/** |
| 190 | + * Update the label of an application. |
| 191 | + * @param {number} appId Numeric id of the application. |
| 192 | + * @param {number} serverId Numeric id of the server. |
| 193 | + * @param {string} label New label of the application. |
| 194 | + * @returns {Promise<boolean>} A promise resolving with a boolean indicating the update status. |
| 195 | + * @example |
| 196 | + * ``` |
| 197 | + * true |
| 198 | + * ``` |
| 199 | + */ |
| 200 | +export function updateAppLabel( |
| 201 | + appId: number, |
| 202 | + serverId: number, |
| 203 | + label: string |
| 204 | +): Promise<boolean> { |
| 205 | + const data = { |
| 206 | + server_id: serverId, |
| 207 | + label: label, |
| 208 | + }; |
| 209 | + return apiCall(`/app/${appId}`, HttpMethod.PUT, data).then( |
| 210 | + (response) => response.status |
| 211 | + ); |
| 212 | +} |
0 commit comments