@@ -5,46 +5,39 @@ import type {
55 App ,
66 Provider ,
77 Region ,
8- PackageType ,
8+ PackageList ,
9+ ServerSize ,
10+ Setting ,
911} from "./types" ;
1012
1113/**
12- * Gets a list of available cloud providers .
13- * @returns {Promise<Provider []> } A promise resolving with an array of cloud providers .
14+ * Gets a list of available apps and their versions .
15+ * @returns {Promise<App []> } A promise resolving with an array of apps and their versions .
1416 * @example
1517 * ```
1618 * [
17- * { "id": "do", "name": "DigitalOcean" },
18- * { "id": "vultr", "name": "Vultr" },
19+ * {
20+ * label: "WordPress",
21+ * versions: [
22+ * { app_version: "4.7", application: "wordpress" },
23+ * ...
24+ * ]
25+ * },
26+ * {
27+ * label: "PHP Stack",
28+ * versions: [
29+ * { app_version: "5.4", application: "phpstack" },
30+ * ...
31+ * ]
32+ * },
1933 * ...
2034 * ]
2135 * ```
2236 */
23- export function getProviderList ( ) : Promise < Provider [ ] > {
24- return apiCall ( "/providers" ) . then ( ( response ) => response . providers ) ;
37+ export function getAppList ( ) : Promise < App [ ] > {
38+ return apiCall ( "/apps" ) ;
2539}
2640
27- /**
28- * Gets a list of 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- * ```
38- */
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- } ) ;
44- }
45-
46- // Similar updates for getServerSizesList, getAppList, getPackageList, getSettingsList
47-
4841/**
4942 * Gets possible backup frequencies.
5043 * @returns {Promise<BackupFrequency[]> } A promise resolving with an array of backup frequencies.
@@ -58,7 +51,9 @@ export function getRegionList(): Promise<Region[]> {
5851 * ```
5952 */
6053export function getBackupFrequencies ( ) : Promise < BackupFrequency [ ] > {
61- return apiCall ( "/backup-frequencies" ) ;
54+ return apiCall ( "/backup-frequencies" ) . then (
55+ ( response ) => response . frequencies
56+ ) ;
6257}
6358
6459/**
@@ -83,7 +78,7 @@ export function getCountriesList(): Promise<Country[]> {
8378 * ```
8479 */
8580export function getMonitorDurations ( ) : Promise < string [ ] > {
86- return apiCall ( "/monitor-durations " ) ;
81+ return apiCall ( "/monitor_durations " ) ;
8782}
8883
8984/**
@@ -99,7 +94,135 @@ export function getMonitorDurations(): Promise<string[]> {
9994 * ```
10095 */
10196export function getMonitorTargets ( ) : Promise < { [ provider : string ] : string [ ] } > {
102- return apiCall ( "/monitor-targets" ) ;
97+ return apiCall ( "/monitor_targets" ) ;
98+ }
99+
100+ /**
101+ * Gets a list of available packages and their versions.
102+ * @returns {Promise<PackageList> } A promise resolving with a list of packages and their versions.
103+ * @example
104+ * ```
105+ * {
106+ * "php": {
107+ * "debian10": {
108+ * "7.0": "PHP 7.0",
109+ * "7.1": "PHP 7.1",
110+ * ...
111+ * },
112+ * ...
113+ * },
114+ * "phpConfig": {
115+ * "debian10": {
116+ * "7.4": ["7.4", "8.0", ...],
117+ * ...
118+ * },
119+ * ...
120+ * },
121+ * "mysql": {
122+ * "debian10": {
123+ * "mysql,5.7": "MySQL 5.7",
124+ * ...
125+ * },
126+ * ...
127+ * },
128+ * "redis": {
129+ * "0": "Uninstall",
130+ * "latest": "Install"
131+ * },
132+ * ...
133+ * }
134+ * ```
135+ */
136+ export function getPackageList ( ) : Promise < PackageList > {
137+ return apiCall ( "/packages" ) ;
138+ }
139+
140+ /**
141+ * Gets a list of available cloud providers.
142+ * @returns {Promise<Provider[]> } A promise resolving with an array of cloud providers.
143+ * @example
144+ * ```
145+ * [
146+ * { "id": "do", "name": "DigitalOcean" },
147+ * { "id": "vultr", "name": "Vultr" },
148+ * ...
149+ * ]
150+ * ```
151+ */
152+ export function getProviderList ( ) : Promise < Provider [ ] > {
153+ return apiCall ( "/providers" ) . then ( ( response ) => response . providers ) ;
103154}
104155
105- // ... and similarly for other functions
156+ /**
157+ * Gets a list of regions.
158+ * @returns {Promise<Region[]> } A promise resolving with an array of regions.
159+ * @example
160+ * ```
161+ * [
162+ * { "id": "us-east-1", "name": "US N.Virginia" },
163+ * { "id": "us-west-1", "name": "California" },
164+ * ...
165+ * ]
166+ * ```
167+ */
168+ export function getRegionList ( ) : Promise < Region [ ] > {
169+ return apiCall ( "/regions" ) . then ( ( response ) => {
170+ const regionsArray = Object . values ( response . regions ) . flat ( ) ;
171+ return regionsArray as Region [ ] ; // Type assertion to Region[]
172+ } ) ;
173+ }
174+
175+ /**
176+ * Gets a list of server sizes available.
177+ * @returns {Promise<ServerSize[]> } A promise resolving with an array of server sizes available for each provider.
178+ * @example
179+ * ```
180+ * [
181+ * { provider: "Amazon", sizes: ["Small", "Medium", ...] },
182+ * { provider: "DO", sizes: ["512MB", "1GB", ...] },
183+ * { provider: "GCE", sizes: ["small", "n1-std-1", ...] },
184+ * { provider: "Vultr", sizes: ["768MB", "1GB", ...] },
185+ * { provider: "Kyup", sizes: ["1 Core", "2 Cores", ...] },
186+ * { provider: "Linode", sizes: ["1GB", "2GB", ...] }
187+ * ]
188+ * ```
189+ */
190+ export function getServerSizesList ( ) : Promise < ServerSize [ ] > {
191+ return apiCall ( "/server_sizes" ) . then ( ( response ) => {
192+ const serverSizesList : ServerSize [ ] = [ ] ;
193+ for ( const provider in response . sizes ) {
194+ serverSizesList . push ( {
195+ provider : provider ,
196+ sizes : response . sizes [ provider ] ,
197+ } ) ;
198+ }
199+ return serverSizesList ;
200+ } ) ;
201+ }
202+
203+ /**
204+ * Gets a list of available settings and corresponding values.
205+ * @returns {Promise<Setting[]> } A promise resolving with an array of settings and their possible values.
206+ * @example
207+ * ```
208+ * [
209+ * { setting: "timezone", values: ["Pacific/Midway", "Pacific/Samoa", ...] },
210+ * { setting: "character_set", values: ["ascii", "greek", ...] },
211+ * { setting: "status", values: [" ----", "Off", "On"] },
212+ * { setting: "error_reporting", values: [" ----", "E_ALL & ~E_DEPRECATED & ~E_STRICT", ...] },
213+ * { setting: "statuses", values: ["disabled", "enabled"] }
214+ * ]
215+ * ```
216+ */
217+ export function getSettingsList ( ) : Promise < Setting [ ] > {
218+ return apiCall ( "/settings" ) . then ( ( response ) => {
219+ const settingsList : Setting [ ] = [ ] ;
220+ for ( const setting in response . settings ) {
221+ settingsList . push ( {
222+ setting : setting ,
223+ values : Object . keys ( response . settings [ setting ] ) ,
224+ } ) ;
225+ }
226+ return settingsList ;
227+ } ) ;
228+ }
0 commit comments