From 5a3468ac62a6a12d837dbf90903d1305c1897a66 Mon Sep 17 00:00:00 2001 From: Scaleway Bot Date: Tue, 24 Dec 2024 10:32:43 +0100 Subject: [PATCH] feat(webhosting): add SyncDomainDnsRecords method (#1673) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jules Castéran --- .../src/api/secret/v1beta1/marshalling.gen.ts | 1 + .../src/api/secret/v1beta1/types.gen.ts | 2 ++ .../clients/src/api/webhosting/v1/api.gen.ts | 26 +++++++++++++++++++ .../src/api/webhosting/v1/index.gen.ts | 2 ++ .../src/api/webhosting/v1/marshalling.gen.ts | 25 ++++++++++++++++++ .../src/api/webhosting/v1/types.gen.ts | 23 ++++++++++++++++ 6 files changed, 79 insertions(+) diff --git a/packages/clients/src/api/secret/v1beta1/marshalling.gen.ts b/packages/clients/src/api/secret/v1beta1/marshalling.gen.ts index 565e1cc93..4b308fd56 100644 --- a/packages/clients/src/api/secret/v1beta1/marshalling.gen.ts +++ b/packages/clients/src/api/secret/v1beta1/marshalling.gen.ts @@ -50,6 +50,7 @@ export const unmarshalSecretVersion = (data: unknown): SecretVersion => { return { createdAt: unmarshalDate(data.created_at), + deletedAt: unmarshalDate(data.deleted_at), description: data.description, ephemeralProperties: data.ephemeral_properties ? unmarshalEphemeralProperties(data.ephemeral_properties) diff --git a/packages/clients/src/api/secret/v1beta1/types.gen.ts b/packages/clients/src/api/secret/v1beta1/types.gen.ts index 854686c50..8bac2b849 100644 --- a/packages/clients/src/api/secret/v1beta1/types.gen.ts +++ b/packages/clients/src/api/secret/v1beta1/types.gen.ts @@ -103,6 +103,8 @@ export interface SecretVersion { createdAt?: Date /** Last update of the version. */ updatedAt?: Date + /** Date and time of the version's deletion. */ + deletedAt?: Date /** Description of the version. */ description?: string /** Returns `true` if the version is the latest. */ diff --git a/packages/clients/src/api/webhosting/v1/api.gen.ts b/packages/clients/src/api/webhosting/v1/api.gen.ts index c443046dc..9b75cb5d5 100644 --- a/packages/clients/src/api/webhosting/v1/api.gen.ts +++ b/packages/clients/src/api/webhosting/v1/api.gen.ts @@ -16,6 +16,7 @@ import { marshalDatabaseApiCreateDatabaseUserRequest, marshalDatabaseApiUnassignDatabaseUserRequest, marshalDnsApiCheckUserOwnsDomainRequest, + marshalDnsApiSyncDomainDnsRecordsRequest, marshalFtpAccountApiChangeFtpAccountPasswordRequest, marshalFtpAccountApiCreateFtpAccountRequest, marshalHostingApiCreateHostingRequest, @@ -60,6 +61,7 @@ import type { DatabaseUser, DnsApiCheckUserOwnsDomainRequest, DnsApiGetDomainDnsRecordsRequest, + DnsApiSyncDomainDnsRecordsRequest, DnsRecords, FtpAccount, FtpAccountApiChangeFtpAccountPasswordRequest, @@ -433,6 +435,30 @@ export class DnsAPI extends ParentAPI { }, unmarshalCheckUserOwnsDomainResponse, ) + + /** + * "Synchronize your DNS records on the Elements Console and on cPanel.". + * + * @param request - The request {@link DnsApiSyncDomainDnsRecordsRequest} + * @returns A Promise of DnsRecords + */ + syncDomainDnsRecords = ( + request: Readonly, + ) => + this.client.fetch( + { + body: JSON.stringify( + marshalDnsApiSyncDomainDnsRecordsRequest( + request, + this.client.settings, + ), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/domains/${validatePathParam('domain', request.domain)}/sync-domain-dns-records`, + }, + unmarshalDnsRecords, + ) } /** diff --git a/packages/clients/src/api/webhosting/v1/index.gen.ts b/packages/clients/src/api/webhosting/v1/index.gen.ts index 9f1ef58ea..f82f79689 100644 --- a/packages/clients/src/api/webhosting/v1/index.gen.ts +++ b/packages/clients/src/api/webhosting/v1/index.gen.ts @@ -32,6 +32,7 @@ export type { DatabaseUser, DnsApiCheckUserOwnsDomainRequest, DnsApiGetDomainDnsRecordsRequest, + DnsApiSyncDomainDnsRecordsRequest, DnsRecord, DnsRecordStatus, DnsRecordType, @@ -90,6 +91,7 @@ export type { ResetHostingPasswordResponse, ResourceSummary, Session, + SyncDomainDnsRecordsRequestRecord, Website, WebsiteApiListWebsitesRequest, } from './types.gen' diff --git a/packages/clients/src/api/webhosting/v1/marshalling.gen.ts b/packages/clients/src/api/webhosting/v1/marshalling.gen.ts index 3f531f36d..0b93660f4 100644 --- a/packages/clients/src/api/webhosting/v1/marshalling.gen.ts +++ b/packages/clients/src/api/webhosting/v1/marshalling.gen.ts @@ -21,6 +21,7 @@ import type { DatabaseApiUnassignDatabaseUserRequest, DatabaseUser, DnsApiCheckUserOwnsDomainRequest, + DnsApiSyncDomainDnsRecordsRequest, DnsRecord, DnsRecords, FtpAccount, @@ -53,6 +54,7 @@ import type { ResetHostingPasswordResponse, ResourceSummary, Session, + SyncDomainDnsRecordsRequestRecord, Website, } from './types.gen' @@ -568,6 +570,29 @@ export const marshalDnsApiCheckUserOwnsDomainRequest = ( project_id: request.projectId ?? defaults.defaultProjectId, }) +const marshalSyncDomainDnsRecordsRequestRecord = ( + request: SyncDomainDnsRecordsRequestRecord, + defaults: DefaultValues, +): Record => ({ + name: request.name, + type: request.type, +}) + +export const marshalDnsApiSyncDomainDnsRecordsRequest = ( + request: DnsApiSyncDomainDnsRecordsRequest, + defaults: DefaultValues, +): Record => ({ + custom_records: + request.customRecords !== undefined + ? request.customRecords.map(elt => + marshalSyncDomainDnsRecordsRequestRecord(elt, defaults), + ) + : undefined, + update_all_records: request.updateAllRecords, + update_mail_records: request.updateMailRecords, + update_web_records: request.updateWebRecords, +}) + export const marshalFtpAccountApiChangeFtpAccountPasswordRequest = ( request: FtpAccountApiChangeFtpAccountPasswordRequest, defaults: DefaultValues, diff --git a/packages/clients/src/api/webhosting/v1/types.gen.ts b/packages/clients/src/api/webhosting/v1/types.gen.ts index b6e6e2fae..5ad3bf999 100644 --- a/packages/clients/src/api/webhosting/v1/types.gen.ts +++ b/packages/clients/src/api/webhosting/v1/types.gen.ts @@ -125,6 +125,11 @@ export interface OfferOptionRequest { quantity: number } +export interface SyncDomainDnsRecordsRequestRecord { + name: string + type: DnsRecordType +} + export interface DnsRecord { /** Record name. */ name: string @@ -475,6 +480,24 @@ export type DnsApiGetDomainDnsRecordsRequest = { domain: string } +export type DnsApiSyncDomainDnsRecordsRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** Domain for which the DNS records will be synchronized. */ + domain: string + /** Whether or not to synchronize the web records. */ + updateWebRecords: boolean + /** Whether or not to synchronize the mail records. */ + updateMailRecords: boolean + /** Whether or not to synchronize all types of records. This one has priority. */ + updateAllRecords: boolean + /** Custom records to synchronize. */ + customRecords?: SyncDomainDnsRecordsRequestRecord[] +} + export interface DnsRecords { /** List of DNS records. */ records: DnsRecord[]