@@ -11,10 +11,12 @@ import {
1111 waitForResource ,
1212} from '@scaleway/sdk-client'
1313import {
14+ BACKUP_TRANSIENT_STATUSES as BACKUP_TRANSIENT_STATUSES_WEBHOSTING ,
1415 DOMAIN_TRANSIENT_STATUSES as DOMAIN_TRANSIENT_STATUSES_WEBHOSTING ,
1516 HOSTING_TRANSIENT_STATUSES as HOSTING_TRANSIENT_STATUSES_WEBHOSTING ,
1617} from './content.gen'
1718import {
19+ marshalBackupApiRestoreBackupItemsRequest ,
1820 marshalDatabaseApiAssignDatabaseUserRequest ,
1921 marshalDatabaseApiChangeDatabaseUserPasswordRequest ,
2022 marshalDatabaseApiCreateDatabaseRequest ,
@@ -29,13 +31,16 @@ import {
2931 marshalMailAccountApiChangeMailAccountPasswordRequest ,
3032 marshalMailAccountApiCreateMailAccountRequest ,
3133 marshalMailAccountApiRemoveMailAccountRequest ,
34+ unmarshalBackup ,
3235 unmarshalCheckUserOwnsDomainResponse ,
3336 unmarshalDatabase ,
3437 unmarshalDatabaseUser ,
3538 unmarshalDnsRecords ,
3639 unmarshalDomain ,
3740 unmarshalFtpAccount ,
3841 unmarshalHosting ,
42+ unmarshalListBackupItemsResponse ,
43+ unmarshalListBackupsResponse ,
3944 unmarshalListControlPanelsResponse ,
4045 unmarshalListDatabasesResponse ,
4146 unmarshalListDatabaseUsersResponse ,
@@ -47,10 +52,18 @@ import {
4752 unmarshalMailAccount ,
4853 unmarshalResetHostingPasswordResponse ,
4954 unmarshalResourceSummary ,
55+ unmarshalRestoreBackupItemsResponse ,
56+ unmarshalRestoreBackupResponse ,
5057 unmarshalSearchDomainsResponse ,
5158 unmarshalSession ,
5259} from './marshalling.gen'
5360import type {
61+ Backup ,
62+ BackupApiGetBackupRequest ,
63+ BackupApiListBackupItemsRequest ,
64+ BackupApiListBackupsRequest ,
65+ BackupApiRestoreBackupItemsRequest ,
66+ BackupApiRestoreBackupRequest ,
5467 CheckUserOwnsDomainResponse ,
5568 ControlPanelApiListControlPanelsRequest ,
5669 Database ,
@@ -87,6 +100,8 @@ import type {
87100 HostingApiListHostingsRequest ,
88101 HostingApiResetHostingPasswordRequest ,
89102 HostingApiUpdateHostingRequest ,
103+ ListBackupItemsResponse ,
104+ ListBackupsResponse ,
90105 ListControlPanelsResponse ,
91106 ListDatabasesResponse ,
92107 ListDatabaseUsersResponse ,
@@ -103,6 +118,8 @@ import type {
103118 OfferApiListOffersRequest ,
104119 ResetHostingPasswordResponse ,
105120 ResourceSummary ,
121+ RestoreBackupItemsResponse ,
122+ RestoreBackupResponse ,
106123 SearchDomainsResponse ,
107124 Session ,
108125 WebsiteApiListWebsitesRequest ,
@@ -112,6 +129,143 @@ const jsonContentHeaders = {
112129 'Content-Type' : 'application/json; charset=utf-8' ,
113130}
114131
132+ /**
133+ * Web Hosting backup API.
134+
135+ This API allows you to list and restore backups for your cPanel and WordPress Web Hosting service.
136+ */
137+ export class BackupAPI extends ParentAPI {
138+ /**
139+ * Locality of this API.
140+ * type ∈ {'zone','region','global','unspecified'}
141+ */
142+ public static readonly LOCALITY : ApiLocality = toApiLocality ( {
143+ regions : [ 'fr-par' , 'nl-ams' , 'pl-waw' ] ,
144+ } )
145+
146+ protected pageOfListBackups = (
147+ request : Readonly < BackupApiListBackupsRequest > ,
148+ ) =>
149+ this . client . fetch < ListBackupsResponse > (
150+ {
151+ method : 'GET' ,
152+ path : `/webhosting/v1/regions/${ validatePathParam ( 'region' , request . region ?? this . client . settings . defaultRegion ) } /hostings/${ validatePathParam ( 'hostingId' , request . hostingId ) } /backups` ,
153+ urlParams : urlParams (
154+ [ 'order_by' , request . orderBy ] ,
155+ [ 'page' , request . page ] ,
156+ [
157+ 'page_size' ,
158+ request . pageSize ?? this . client . settings . defaultPageSize ,
159+ ] ,
160+ ) ,
161+ } ,
162+ unmarshalListBackupsResponse ,
163+ )
164+
165+ /**
166+ * List all available backups for a hosting account.. List all available backups for a hosting account.
167+ *
168+ * @param request - The request {@link BackupApiListBackupsRequest}
169+ * @returns A Promise of ListBackupsResponse
170+ */
171+ listBackups = ( request : Readonly < BackupApiListBackupsRequest > ) =>
172+ enrichForPagination ( 'backups' , this . pageOfListBackups , request )
173+
174+ /**
175+ * Get info about a backup specified by the backup ID.. Get info about a backup specified by the backup ID.
176+ *
177+ * @param request - The request {@link BackupApiGetBackupRequest}
178+ * @returns A Promise of Backup
179+ */
180+ getBackup = ( request : Readonly < BackupApiGetBackupRequest > ) =>
181+ this . client . fetch < Backup > (
182+ {
183+ method : 'GET' ,
184+ path : `/webhosting/v1/regions/${ validatePathParam ( 'region' , request . region ?? this . client . settings . defaultRegion ) } /hostings/${ validatePathParam ( 'hostingId' , request . hostingId ) } /backups/${ validatePathParam ( 'backupId' , request . backupId ) } ` ,
185+ } ,
186+ unmarshalBackup ,
187+ )
188+
189+ /**
190+ * Waits for {@link Backup} to be in a final state.
191+ *
192+ * @param request - The request {@link BackupApiGetBackupRequest}
193+ * @param options - The waiting options
194+ * @returns A Promise of Backup
195+ */
196+ waitForBackup = (
197+ request : Readonly < BackupApiGetBackupRequest > ,
198+ options ?: Readonly < WaitForOptions < Backup > > ,
199+ ) =>
200+ waitForResource (
201+ options ?. stop ??
202+ ( res =>
203+ Promise . resolve (
204+ ! BACKUP_TRANSIENT_STATUSES_WEBHOSTING . includes ( res . status ) ,
205+ ) ) ,
206+ this . getBackup ,
207+ request ,
208+ options ,
209+ )
210+
211+ /**
212+ * Restore an entire backup to your hosting environment.. Restore an entire backup to your hosting environment.
213+ *
214+ * @param request - The request {@link BackupApiRestoreBackupRequest}
215+ * @returns A Promise of RestoreBackupResponse
216+ */
217+ restoreBackup = ( request : Readonly < BackupApiRestoreBackupRequest > ) =>
218+ this . client . fetch < RestoreBackupResponse > (
219+ {
220+ body : '{}' ,
221+ headers : jsonContentHeaders ,
222+ method : 'POST' ,
223+ path : `/webhosting/v1/regions/${ validatePathParam ( 'region' , request . region ?? this . client . settings . defaultRegion ) } /hostings/${ validatePathParam ( 'hostingId' , request . hostingId ) } /backups/${ validatePathParam ( 'backupId' , request . backupId ) } /restore` ,
224+ } ,
225+ unmarshalRestoreBackupResponse ,
226+ )
227+
228+ /**
229+ * List items within a specific backup, grouped by type.. List items within a specific backup, grouped by type.
230+ *
231+ * @param request - The request {@link BackupApiListBackupItemsRequest}
232+ * @returns A Promise of ListBackupItemsResponse
233+ */
234+ listBackupItems = ( request : Readonly < BackupApiListBackupItemsRequest > ) =>
235+ this . client . fetch < ListBackupItemsResponse > (
236+ {
237+ method : 'GET' ,
238+ path : `/webhosting/v1/regions/${ validatePathParam ( 'region' , request . region ?? this . client . settings . defaultRegion ) } /hostings/${ validatePathParam ( 'hostingId' , request . hostingId ) } /backup-items` ,
239+ urlParams : urlParams ( [ 'backup_id' , request . backupId ] ) ,
240+ } ,
241+ unmarshalListBackupItemsResponse ,
242+ )
243+
244+ /**
245+ * Restore specific items from a backup (e.g., a database or mailbox).. Restore specific items from a backup (e.g., a database or mailbox).
246+ *
247+ * @param request - The request {@link BackupApiRestoreBackupItemsRequest}
248+ * @returns A Promise of RestoreBackupItemsResponse
249+ */
250+ restoreBackupItems = (
251+ request : Readonly < BackupApiRestoreBackupItemsRequest > ,
252+ ) =>
253+ this . client . fetch < RestoreBackupItemsResponse > (
254+ {
255+ body : JSON . stringify (
256+ marshalBackupApiRestoreBackupItemsRequest (
257+ request ,
258+ this . client . settings ,
259+ ) ,
260+ ) ,
261+ headers : jsonContentHeaders ,
262+ method : 'POST' ,
263+ path : `/webhosting/v1/regions/${ validatePathParam ( 'region' , request . region ?? this . client . settings . defaultRegion ) } /hostings/${ validatePathParam ( 'hostingId' , request . hostingId ) } /restore-backup-items` ,
264+ } ,
265+ unmarshalRestoreBackupItemsResponse ,
266+ )
267+ }
268+
115269/**
116270 * Web Hosting Control Panel API.
117271
0 commit comments