diff --git a/packages_generated/webhosting/src/v1/api.gen.ts b/packages_generated/webhosting/src/v1/api.gen.ts index a0a3562b0..db373b68f 100644 --- a/packages_generated/webhosting/src/v1/api.gen.ts +++ b/packages_generated/webhosting/src/v1/api.gen.ts @@ -11,10 +11,12 @@ import { waitForResource, } from '@scaleway/sdk-client' import { + BACKUP_TRANSIENT_STATUSES as BACKUP_TRANSIENT_STATUSES_WEBHOSTING, DOMAIN_TRANSIENT_STATUSES as DOMAIN_TRANSIENT_STATUSES_WEBHOSTING, HOSTING_TRANSIENT_STATUSES as HOSTING_TRANSIENT_STATUSES_WEBHOSTING, } from './content.gen' import { + marshalBackupApiRestoreBackupItemsRequest, marshalDatabaseApiAssignDatabaseUserRequest, marshalDatabaseApiChangeDatabaseUserPasswordRequest, marshalDatabaseApiCreateDatabaseRequest, @@ -29,6 +31,7 @@ import { marshalMailAccountApiChangeMailAccountPasswordRequest, marshalMailAccountApiCreateMailAccountRequest, marshalMailAccountApiRemoveMailAccountRequest, + unmarshalBackup, unmarshalCheckUserOwnsDomainResponse, unmarshalDatabase, unmarshalDatabaseUser, @@ -36,6 +39,8 @@ import { unmarshalDomain, unmarshalFtpAccount, unmarshalHosting, + unmarshalListBackupItemsResponse, + unmarshalListBackupsResponse, unmarshalListControlPanelsResponse, unmarshalListDatabasesResponse, unmarshalListDatabaseUsersResponse, @@ -47,10 +52,18 @@ import { unmarshalMailAccount, unmarshalResetHostingPasswordResponse, unmarshalResourceSummary, + unmarshalRestoreBackupItemsResponse, + unmarshalRestoreBackupResponse, unmarshalSearchDomainsResponse, unmarshalSession, } from './marshalling.gen' import type { + Backup, + BackupApiGetBackupRequest, + BackupApiListBackupItemsRequest, + BackupApiListBackupsRequest, + BackupApiRestoreBackupItemsRequest, + BackupApiRestoreBackupRequest, CheckUserOwnsDomainResponse, ControlPanelApiListControlPanelsRequest, Database, @@ -87,6 +100,8 @@ import type { HostingApiListHostingsRequest, HostingApiResetHostingPasswordRequest, HostingApiUpdateHostingRequest, + ListBackupItemsResponse, + ListBackupsResponse, ListControlPanelsResponse, ListDatabasesResponse, ListDatabaseUsersResponse, @@ -103,6 +118,8 @@ import type { OfferApiListOffersRequest, ResetHostingPasswordResponse, ResourceSummary, + RestoreBackupItemsResponse, + RestoreBackupResponse, SearchDomainsResponse, Session, WebsiteApiListWebsitesRequest, @@ -112,6 +129,143 @@ const jsonContentHeaders = { 'Content-Type': 'application/json; charset=utf-8', } +/** + * Web Hosting backup API. + +This API allows you to list and restore backups for your cPanel and WordPress Web Hosting service. + */ +export class BackupAPI extends ParentAPI { + /** + * Locality of this API. + * type ∈ {'zone','region','global','unspecified'} + */ + public static readonly LOCALITY: ApiLocality = toApiLocality({ + regions: ['fr-par', 'nl-ams', 'pl-waw'], + }) + + protected pageOfListBackups = ( + request: Readonly, + ) => + this.client.fetch( + { + method: 'GET', + path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}/backups`, + urlParams: urlParams( + ['order_by', request.orderBy], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ), + }, + unmarshalListBackupsResponse, + ) + + /** + * List all available backups for a hosting account.. List all available backups for a hosting account. + * + * @param request - The request {@link BackupApiListBackupsRequest} + * @returns A Promise of ListBackupsResponse + */ + listBackups = (request: Readonly) => + enrichForPagination('backups', this.pageOfListBackups, request) + + /** + * Get info about a backup specified by the backup ID.. Get info about a backup specified by the backup ID. + * + * @param request - The request {@link BackupApiGetBackupRequest} + * @returns A Promise of Backup + */ + getBackup = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}/backups/${validatePathParam('backupId', request.backupId)}`, + }, + unmarshalBackup, + ) + + /** + * Waits for {@link Backup} to be in a final state. + * + * @param request - The request {@link BackupApiGetBackupRequest} + * @param options - The waiting options + * @returns A Promise of Backup + */ + waitForBackup = ( + request: Readonly, + options?: Readonly>, + ) => + waitForResource( + options?.stop ?? + (res => + Promise.resolve( + !BACKUP_TRANSIENT_STATUSES_WEBHOSTING.includes(res.status), + )), + this.getBackup, + request, + options, + ) + + /** + * Restore an entire backup to your hosting environment.. Restore an entire backup to your hosting environment. + * + * @param request - The request {@link BackupApiRestoreBackupRequest} + * @returns A Promise of RestoreBackupResponse + */ + restoreBackup = (request: Readonly) => + this.client.fetch( + { + body: '{}', + headers: jsonContentHeaders, + method: 'POST', + path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}/backups/${validatePathParam('backupId', request.backupId)}/restore`, + }, + unmarshalRestoreBackupResponse, + ) + + /** + * List items within a specific backup, grouped by type.. List items within a specific backup, grouped by type. + * + * @param request - The request {@link BackupApiListBackupItemsRequest} + * @returns A Promise of ListBackupItemsResponse + */ + listBackupItems = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}/backup-items`, + urlParams: urlParams(['backup_id', request.backupId]), + }, + unmarshalListBackupItemsResponse, + ) + + /** + * Restore specific items from a backup (e.g., a database or mailbox).. Restore specific items from a backup (e.g., a database or mailbox). + * + * @param request - The request {@link BackupApiRestoreBackupItemsRequest} + * @returns A Promise of RestoreBackupItemsResponse + */ + restoreBackupItems = ( + request: Readonly, + ) => + this.client.fetch( + { + body: JSON.stringify( + marshalBackupApiRestoreBackupItemsRequest( + request, + this.client.settings, + ), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}/restore-backup-items`, + }, + unmarshalRestoreBackupItemsResponse, + ) +} + /** * Web Hosting Control Panel API. diff --git a/packages_generated/webhosting/src/v1/content.gen.ts b/packages_generated/webhosting/src/v1/content.gen.ts index f666805dd..f98399bec 100644 --- a/packages_generated/webhosting/src/v1/content.gen.ts +++ b/packages_generated/webhosting/src/v1/content.gen.ts @@ -1,11 +1,15 @@ // This file was automatically generated. DO NOT EDIT. // If you have any remark or suggestion do not hesitate to open an issue. import type { + BackupStatus, DomainAvailabilityStatus, DomainStatus, HostingStatus, } from './types.gen' +/** Lists transient statutes of the enum {@link BackupStatus}. */ +export const BACKUP_TRANSIENT_STATUSES: BackupStatus[] = ['restoring'] + /** Lists transient statutes of the enum {@link DomainAvailabilityStatus}. */ export const DOMAIN_AVAILABILITY_TRANSIENT_STATUSES: DomainAvailabilityStatus[] = ['validating'] diff --git a/packages_generated/webhosting/src/v1/index.gen.ts b/packages_generated/webhosting/src/v1/index.gen.ts index b1203d752..936ad321a 100644 --- a/packages_generated/webhosting/src/v1/index.gen.ts +++ b/packages_generated/webhosting/src/v1/index.gen.ts @@ -1,6 +1,7 @@ // This file was automatically generated. DO NOT EDIT. // If you have any remark or suggestion do not hesitate to open an issue. export { + BackupAPI, ControlPanelAPI, DatabaseAPI, DnsAPI, @@ -14,6 +15,16 @@ export * from './content.gen' export * from './marshalling.gen' export type { AutoConfigDomainDns, + Backup, + BackupApiGetBackupRequest, + BackupApiListBackupItemsRequest, + BackupApiListBackupsRequest, + BackupApiRestoreBackupItemsRequest, + BackupApiRestoreBackupRequest, + BackupItem, + BackupItemGroup, + BackupItemType, + BackupStatus, CheckUserOwnsDomainResponse, ControlPanel, ControlPanelApiListControlPanelsRequest, @@ -69,6 +80,9 @@ export type { HostingStatus, HostingSummary, HostingUser, + ListBackupItemsResponse, + ListBackupsRequestOrderBy, + ListBackupsResponse, ListControlPanelsResponse, ListDatabasesRequestOrderBy, ListDatabasesResponse, @@ -103,6 +117,8 @@ export type { PlatformPlatformGroup, ResetHostingPasswordResponse, ResourceSummary, + RestoreBackupItemsResponse, + RestoreBackupResponse, SearchDomainsResponse, Session, SyncDomainDnsRecordsRequestRecord, diff --git a/packages_generated/webhosting/src/v1/marshalling.gen.ts b/packages_generated/webhosting/src/v1/marshalling.gen.ts index 257a28746..cd4822eef 100644 --- a/packages_generated/webhosting/src/v1/marshalling.gen.ts +++ b/packages_generated/webhosting/src/v1/marshalling.gen.ts @@ -11,6 +11,10 @@ import { } from '@scaleway/sdk-client' import type { AutoConfigDomainDns, + Backup, + BackupApiRestoreBackupItemsRequest, + BackupItem, + BackupItemGroup, CheckUserOwnsDomainResponse, ControlPanel, CreateDatabaseRequestUser, @@ -38,6 +42,8 @@ import type { HostingDomainCustomDomain, HostingSummary, HostingUser, + ListBackupItemsResponse, + ListBackupsResponse, ListControlPanelsResponse, ListDatabasesResponse, ListDatabaseUsersResponse, @@ -59,12 +65,30 @@ import type { PlatformControlPanelUrls, ResetHostingPasswordResponse, ResourceSummary, + RestoreBackupItemsResponse, + RestoreBackupResponse, SearchDomainsResponse, Session, SyncDomainDnsRecordsRequestRecord, Website, } from './types.gen' +export const unmarshalBackup = (data: unknown): Backup => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Backup' failed as data isn't a dictionary.`, + ) + } + + return { + createdAt: unmarshalDate(data.created_at), + id: data.id, + size: data.size, + status: data.status, + totalItems: data.total_items, + } as Backup +} + export const unmarshalDatabaseUser = (data: unknown): DatabaseUser => { if (!isJSONObject(data)) { throw new TypeError( @@ -383,6 +407,66 @@ export const unmarshalHosting = (data: unknown): Hosting => { } as Hosting } +const unmarshalBackupItem = (data: unknown): BackupItem => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'BackupItem' failed as data isn't a dictionary.`, + ) + } + + return { + createdAt: unmarshalDate(data.created_at), + id: data.id, + name: data.name, + size: data.size, + status: data.status, + type: data.type, + } as BackupItem +} + +const unmarshalBackupItemGroup = (data: unknown): BackupItemGroup => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'BackupItemGroup' failed as data isn't a dictionary.`, + ) + } + + return { + items: unmarshalArrayOfObject(data.items, unmarshalBackupItem), + type: data.type, + } as BackupItemGroup +} + +export const unmarshalListBackupItemsResponse = ( + data: unknown, +): ListBackupItemsResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListBackupItemsResponse' failed as data isn't a dictionary.`, + ) + } + + return { + groups: unmarshalArrayOfObject(data.groups, unmarshalBackupItemGroup), + totalCount: data.total_count, + } as ListBackupItemsResponse +} + +export const unmarshalListBackupsResponse = ( + data: unknown, +): ListBackupsResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListBackupsResponse' failed as data isn't a dictionary.`, + ) + } + + return { + backups: unmarshalArrayOfObject(data.backups, unmarshalBackup), + totalCount: data.total_count, + } as ListBackupsResponse +} + const unmarshalControlPanel = (data: unknown): ControlPanel => { if (!isJSONObject(data)) { throw new TypeError( @@ -593,6 +677,30 @@ export const unmarshalResourceSummary = (data: unknown): ResourceSummary => { } as ResourceSummary } +export const unmarshalRestoreBackupItemsResponse = ( + data: unknown, +): RestoreBackupItemsResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'RestoreBackupItemsResponse' failed as data isn't a dictionary.`, + ) + } + + return {} as RestoreBackupItemsResponse +} + +export const unmarshalRestoreBackupResponse = ( + data: unknown, +): RestoreBackupResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'RestoreBackupResponse' failed as data isn't a dictionary.`, + ) + } + + return {} as RestoreBackupResponse +} + const unmarshalDomainAvailability = (data: unknown): DomainAvailability => { if (!isJSONObject(data)) { throw new TypeError( @@ -639,6 +747,13 @@ export const unmarshalSession = (data: unknown): Session => { } as Session } +export const marshalBackupApiRestoreBackupItemsRequest = ( + request: BackupApiRestoreBackupItemsRequest, + defaults: DefaultValues, +): Record => ({ + item_ids: request.itemIds, +}) + export const marshalDatabaseApiAssignDatabaseUserRequest = ( request: DatabaseApiAssignDatabaseUserRequest, defaults: DefaultValues, diff --git a/packages_generated/webhosting/src/v1/types.gen.ts b/packages_generated/webhosting/src/v1/types.gen.ts index 34f60114b..f4d8ed618 100644 --- a/packages_generated/webhosting/src/v1/types.gen.ts +++ b/packages_generated/webhosting/src/v1/types.gen.ts @@ -3,6 +3,26 @@ import type { Money, Region as ScwRegion } from '@scaleway/sdk-client' import type { LanguageCode as StdLanguageCode } from '@scaleway/sdk-std' +export type BackupItemType = + | 'unknown_backup_item_type' + | 'full' + | 'web' + | 'mail' + | 'db' + | 'db_user' + | 'ftp_user' + | 'dns_zone' + | 'cron_job' + | 'ssl_certificate' + +export type BackupStatus = + | 'unknown_backup_status' + | 'active' + | 'locked' + | 'disabled' + | 'damaged' + | 'restoring' + export type DnsRecordStatus = 'unknown_status' | 'valid' | 'invalid' export type DnsRecordType = @@ -68,6 +88,8 @@ export type HostingStatus = | 'migrating' | 'updating' +export type ListBackupsRequestOrderBy = 'created_at_desc' | 'created_at_asc' + export type ListDatabaseUsersRequestOrderBy = 'username_asc' | 'username_desc' export type ListDatabasesRequestOrderBy = @@ -209,6 +231,33 @@ export interface PlatformControlPanel { urls?: PlatformControlPanelUrls } +export interface BackupItem { + /** + * ID of the item. + */ + id: string + /** + * Name of the item (e.g., `database name`, `email address`). + */ + name: string + /** + * Type of the item (e.g., email, database, FTP). + */ + type: BackupItemType + /** + * Size of the item in bytes. + */ + size: number + /** + * Status of the item. Available values are `active`, `damaged`, and `restoring`. + */ + status: BackupStatus + /** + * Date and time at which this item was backed up. + */ + createdAt?: Date +} + export interface HostingDomain { /** * Optional free subdomain linked to the Web Hosting plan. @@ -379,6 +428,40 @@ export interface Platform { controlPanel?: PlatformControlPanel } +export interface BackupItemGroup { + /** + * Type of items (e.g., email, database, FTP). + */ + type: BackupItemType + /** + * List of individual backup items of this type. + */ + items: BackupItem[] +} + +export interface Backup { + /** + * ID of the backup. + */ + id: string + /** + * Total size of the backup in bytes. + */ + size: number + /** + * Creation date of the backup. + */ + createdAt?: Date + /** + * Status of the backup. Available values are `active`, `locked`, and `restoring`. + */ + status: BackupStatus + /** + * Total number of restorable items in the backup. + */ + totalItems: number +} + export interface ControlPanel { /** * Control panel name. @@ -535,6 +618,89 @@ export interface DomainAvailability { price?: Money } +export type BackupApiGetBackupRequest = { + /** + * Region to target. If none is passed will use default region from the config. + */ + region?: ScwRegion + /** + * UUID of the hosting account. + */ + hostingId: string + /** + * ID of the backup to retrieve. + */ + backupId: string +} + +export type BackupApiListBackupItemsRequest = { + /** + * Region to target. If none is passed will use default region from the config. + */ + region?: ScwRegion + /** + * UUID of the hosting account. + */ + hostingId: string + /** + * ID of the backup to list items from. + */ + backupId: string +} + +export type BackupApiListBackupsRequest = { + /** + * Region to target. If none is passed will use default region from the config. + */ + region?: ScwRegion + /** + * UUID of the hosting account. + */ + hostingId: string + /** + * Page number to retrieve. + */ + page?: number + /** + * Number of backups to return per page. + */ + pageSize?: number + /** + * Order in which to return the list of backups. + */ + orderBy?: ListBackupsRequestOrderBy +} + +export type BackupApiRestoreBackupItemsRequest = { + /** + * Region to target. If none is passed will use default region from the config. + */ + region?: ScwRegion + /** + * UUID of the hosting account. + */ + hostingId: string + /** + * List of backup item IDs to restore individually. + */ + itemIds?: string[] +} + +export type BackupApiRestoreBackupRequest = { + /** + * Region to target. If none is passed will use default region from the config. + */ + region?: ScwRegion + /** + * UUID of the hosting account. + */ + hostingId: string + /** + * ID of the backup to fully restore. + */ + backupId: string +} + export interface CheckUserOwnsDomainResponse { /** * Indicates whether the specified project owns the domain. @@ -1246,6 +1412,28 @@ export type HostingApiUpdateHostingRequest = { protected?: boolean } +export interface ListBackupItemsResponse { + /** + * Total number of backup item groups. + */ + totalCount: number + /** + * List of backup item groups categorized by type. + */ + groups: BackupItemGroup[] +} + +export interface ListBackupsResponse { + /** + * Total number of available backups. + */ + totalCount: number + /** + * List of available backups. + */ + backups: Backup[] +} + export interface ListControlPanelsResponse { /** * Number of control panels returned. @@ -1483,6 +1671,10 @@ export interface ResourceSummary { websitesCount: number } +export interface RestoreBackupItemsResponse {} + +export interface RestoreBackupResponse {} + export interface SearchDomainsResponse { /** * List of domains availability. diff --git a/packages_generated/webhosting/src/v1/validation-rules.gen.ts b/packages_generated/webhosting/src/v1/validation-rules.gen.ts index 659447614..bbadc1ac2 100644 --- a/packages_generated/webhosting/src/v1/validation-rules.gen.ts +++ b/packages_generated/webhosting/src/v1/validation-rules.gen.ts @@ -1,6 +1,16 @@ // This file was automatically generated. DO NOT EDIT. // If you have any remark or suggestion do not hesitate to open an issue. +export const BackupApiListBackupsRequest = { + page: { + greaterThan: 0, + }, + pageSize: { + greaterThan: 0, + lessThanOrEqual: 100, + }, +} + export const ControlPanelApiListControlPanelsRequest = { page: { greaterThan: 0,