From 1b8939fdd6ad006ce828c852fee1881630cec6e9 Mon Sep 17 00:00:00 2001 From: scaleway-bot Date: Fri, 2 Aug 2024 14:47:34 +0000 Subject: [PATCH] feat: update generated APIs --- .../src/api/webhosting/v1alpha1/api.gen.ts | 121 ++++++++++++++++++ .../src/api/webhosting/v1alpha1/index.gen.ts | 10 +- .../webhosting/v1alpha1/marshalling.gen.ts | 72 +++++++++++ .../src/api/webhosting/v1alpha1/types.gen.ts | 92 +++++++++++++ .../v1alpha1/validation-rules.gen.ts | 10 ++ 5 files changed, 304 insertions(+), 1 deletion(-) diff --git a/packages/clients/src/api/webhosting/v1alpha1/api.gen.ts b/packages/clients/src/api/webhosting/v1alpha1/api.gen.ts index bb79ae5ab..ff7894f3e 100644 --- a/packages/clients/src/api/webhosting/v1alpha1/api.gen.ts +++ b/packages/clients/src/api/webhosting/v1alpha1/api.gen.ts @@ -11,6 +11,8 @@ import type { Region, WaitForOptions } from '../../../bridge' import { HOSTING_TRANSIENT_STATUSES } from './content.gen' import { marshalCheckUserOwnsDomainRequest, + marshalClassicMailApiCreateMailboxRequest, + marshalClassicMailApiUpdateMailboxRequest, marshalCreateHostingRequest, marshalUpdateHostingRequest, unmarshalCheckUserOwnsDomainResponse, @@ -18,13 +20,20 @@ import { unmarshalHosting, unmarshalListControlPanelsResponse, unmarshalListHostingsResponse, + unmarshalListMailboxesResponse, unmarshalListOffersResponse, + unmarshalMailbox, unmarshalResetHostingPasswordResponse, unmarshalSession, } from './marshalling.gen' import type { CheckUserOwnsDomainRequest, CheckUserOwnsDomainResponse, + ClassicMailApiCreateMailboxRequest, + ClassicMailApiDeleteMailboxRequest, + ClassicMailApiGetMailboxRequest, + ClassicMailApiListMailboxesRequest, + ClassicMailApiUpdateMailboxRequest, CreateHostingRequest, CreateSessionRequest, DeleteHostingRequest, @@ -36,8 +45,10 @@ import type { ListControlPanelsResponse, ListHostingsRequest, ListHostingsResponse, + ListMailboxesResponse, ListOffersRequest, ListOffersResponse, + Mailbox, ResetHostingPasswordRequest, ResetHostingPasswordResponse, RestoreHostingRequest, @@ -324,3 +335,113 @@ export class API extends ParentAPI { unmarshalResetHostingPasswordResponse, ) } + +/** + * Web Hosting Classic Mailbox API. + * + * This API allows you to manage your mailboxes for your Web Hosting services. + */ +export class ClassicMailAPI extends ParentAPI { + /** Lists the available regions of the API. */ + public static readonly LOCALITIES: Region[] = ['fr-par', 'nl-ams', 'pl-waw'] + + /** + * Create a new mailbox within your hosting plan.. Create a new mailbox within + * your hosting plan. + * + * @param request - The request {@link ClassicMailApiCreateMailboxRequest} + * @returns A Promise of Mailbox + */ + createMailbox = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalClassicMailApiCreateMailboxRequest( + request, + this.client.settings, + ), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/webhosting/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/classic-hostings/${validatePathParam('onlineId', request.onlineId)}/mailboxes`, + }, + unmarshalMailbox, + ) + + /** + * Get a mailbox by id within your hosting plan.. Get a mailbox by id within + * your hosting plan. + * + * @param request - The request {@link ClassicMailApiGetMailboxRequest} + * @returns A Promise of Mailbox + */ + getMailbox = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/webhosting/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/classic-hostings/${validatePathParam('onlineId', request.onlineId)}/mailboxes/${validatePathParam('mailboxId', request.mailboxId)}`, + }, + unmarshalMailbox, + ) + + protected pageOfListMailboxes = ( + request: Readonly, + ) => + this.client.fetch( + { + method: 'GET', + path: `/webhosting/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/classic-hostings/${validatePathParam('onlineId', request.onlineId)}/mailboxes`, + urlParams: urlParams( + ['domain', request.domain], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ), + }, + unmarshalListMailboxesResponse, + ) + + /** + * List all mailboxes within your hosting plan.. List all mailboxes within + * your hosting plan. + * + * @param request - The request {@link ClassicMailApiListMailboxesRequest} + * @returns A Promise of ListMailboxesResponse + */ + listMailboxes = (request: Readonly) => + enrichForPagination('mailboxes', this.pageOfListMailboxes, request) + + deleteMailbox = (request: Readonly) => + this.client.fetch( + { + method: 'DELETE', + path: `/webhosting/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/classic-hostings/${validatePathParam('onlineId', request.onlineId)}/mailboxes/${validatePathParam('mailboxId', request.mailboxId)}`, + }, + unmarshalMailbox, + ) + + /** + * Update the mailbox within your hosting plan.. Update the mailbox within + * your hosting plan. + * + * @param request - The request {@link ClassicMailApiUpdateMailboxRequest} + * @returns A Promise of Mailbox + */ + updateMailbox = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalClassicMailApiUpdateMailboxRequest( + request, + this.client.settings, + ), + ), + headers: jsonContentHeaders, + method: 'PATCH', + path: `/webhosting/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/classic-hostings/${validatePathParam('onlineId', request.onlineId)}/mailboxes/${validatePathParam('mailboxId', request.mailboxId)}`, + }, + unmarshalMailbox, + ) +} diff --git a/packages/clients/src/api/webhosting/v1alpha1/index.gen.ts b/packages/clients/src/api/webhosting/v1alpha1/index.gen.ts index 68a156297..0d5e5f1c1 100644 --- a/packages/clients/src/api/webhosting/v1alpha1/index.gen.ts +++ b/packages/clients/src/api/webhosting/v1alpha1/index.gen.ts @@ -1,10 +1,15 @@ // This file was automatically generated. DO NOT EDIT. // If you have any remark or suggestion do not hesitate to open an issue. -export { API } from './api.gen' +export { API, ClassicMailAPI } from './api.gen' export * from './content.gen' export type { CheckUserOwnsDomainRequest, CheckUserOwnsDomainResponse, + ClassicMailApiCreateMailboxRequest, + ClassicMailApiDeleteMailboxRequest, + ClassicMailApiGetMailboxRequest, + ClassicMailApiListMailboxesRequest, + ClassicMailApiUpdateMailboxRequest, ControlPanel, CreateHostingRequest, CreateHostingRequestDomainConfiguration, @@ -15,6 +20,7 @@ export type { DnsRecordType, DnsRecords, DnsRecordsStatus, + EmailAddress, GetDomainDnsRecordsRequest, GetHostingRequest, Hosting, @@ -27,9 +33,11 @@ export type { ListHostingsRequest, ListHostingsRequestOrderBy, ListHostingsResponse, + ListMailboxesResponse, ListOffersRequest, ListOffersRequestOrderBy, ListOffersResponse, + Mailbox, Nameserver, NameserverStatus, Offer, diff --git a/packages/clients/src/api/webhosting/v1alpha1/marshalling.gen.ts b/packages/clients/src/api/webhosting/v1alpha1/marshalling.gen.ts index f49f3d3bc..01f05994b 100644 --- a/packages/clients/src/api/webhosting/v1alpha1/marshalling.gen.ts +++ b/packages/clients/src/api/webhosting/v1alpha1/marshalling.gen.ts @@ -10,17 +10,22 @@ import type { DefaultValues } from '../../../bridge' import type { CheckUserOwnsDomainRequest, CheckUserOwnsDomainResponse, + ClassicMailApiCreateMailboxRequest, + ClassicMailApiUpdateMailboxRequest, ControlPanel, CreateHostingRequest, CreateHostingRequestDomainConfiguration, DnsRecord, DnsRecords, + EmailAddress, Hosting, HostingCpanelUrls, HostingOption, ListControlPanelsResponse, ListHostingsResponse, + ListMailboxesResponse, ListOffersResponse, + Mailbox, Nameserver, Offer, OfferProduct, @@ -92,6 +97,32 @@ export const unmarshalHosting = (data: unknown): Hosting => { } as Hosting } +const unmarshalEmailAddress = (data: unknown): EmailAddress => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'EmailAddress' failed as data isn't a dictionary.`, + ) + } + + return { + domain: data.domain, + login: data.login, + } as EmailAddress +} + +export const unmarshalMailbox = (data: unknown): Mailbox => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Mailbox' failed as data isn't a dictionary.`, + ) + } + + return { + email: data.email ? unmarshalEmailAddress(data.email) : undefined, + mailboxId: data.mailbox_id, + } as Mailbox +} + export const unmarshalCheckUserOwnsDomainResponse = ( data: unknown, ): CheckUserOwnsDomainResponse => { @@ -199,6 +230,21 @@ export const unmarshalListHostingsResponse = ( } as ListHostingsResponse } +export const unmarshalListMailboxesResponse = ( + data: unknown, +): ListMailboxesResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListMailboxesResponse' failed as data isn't a dictionary.`, + ) + } + + return { + mailboxes: unmarshalArrayOfObject(data.mailboxes, unmarshalMailbox), + totalCount: data.total_count, + } as ListMailboxesResponse +} + const unmarshalOfferProduct = (data: unknown): OfferProduct => { if (!isJSONObject(data)) { throw new TypeError( @@ -286,6 +332,32 @@ export const marshalCheckUserOwnsDomainRequest = ( project_id: request.projectId ?? defaults.defaultProjectId, }) +const marshalEmailAddress = ( + request: EmailAddress, + defaults: DefaultValues, +): Record => ({ + domain: request.domain, + login: request.login, +}) + +export const marshalClassicMailApiCreateMailboxRequest = ( + request: ClassicMailApiCreateMailboxRequest, + defaults: DefaultValues, +): Record => ({ + email: + request.email !== undefined + ? marshalEmailAddress(request.email, defaults) + : undefined, + password: request.password, +}) + +export const marshalClassicMailApiUpdateMailboxRequest = ( + request: ClassicMailApiUpdateMailboxRequest, + defaults: DefaultValues, +): Record => ({ + password: request.password, +}) + const marshalCreateHostingRequestDomainConfiguration = ( request: CreateHostingRequestDomainConfiguration, defaults: DefaultValues, diff --git a/packages/clients/src/api/webhosting/v1alpha1/types.gen.ts b/packages/clients/src/api/webhosting/v1alpha1/types.gen.ts index 4b00da42b..2bc3793dd 100644 --- a/packages/clients/src/api/webhosting/v1alpha1/types.gen.ts +++ b/packages/clients/src/api/webhosting/v1alpha1/types.gen.ts @@ -51,6 +51,13 @@ export interface HostingOption { name: string } +export interface EmailAddress { + /** Domain part of the mailbox address. */ + domain: string + /** Username part address of the mailbox address. */ + login: string +} + export interface OfferProduct { /** Product name. */ name: string @@ -170,6 +177,13 @@ export interface Hosting { region: Region } +export interface Mailbox { + /** The ID of the mailbox. */ + mailboxId: number + /** The email address of the mailbox. */ + email?: EmailAddress +} + export interface Offer { /** Offer ID. */ id: string @@ -209,6 +223,77 @@ export interface CheckUserOwnsDomainResponse { ownsDomain: boolean } +export type ClassicMailApiCreateMailboxRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** The Online hosting ID. */ + onlineId: number + /** The email address of the mailbox. */ + email?: EmailAddress + /** Password for the new mailbox. */ + password: string +} + +export type ClassicMailApiDeleteMailboxRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** The Online hosting ID. */ + onlineId: number + /** The ID of the mailbox to delete. */ + mailboxId: number +} + +export type ClassicMailApiGetMailboxRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** The Online hosting ID. */ + onlineId: number + /** The ID of the mailbox to get. */ + mailboxId: number +} + +export type ClassicMailApiListMailboxesRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** The Online hosting ID. */ + onlineId: number + /** Page number (must be a positive integer). */ + page?: number + /** + * Number of mailboxes to return (must be a positive integer lower or equal to + * 100). + */ + pageSize?: number + /** Domain to filter the mailboxes. */ + domain?: string +} + +export type ClassicMailApiUpdateMailboxRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** The Online hosting ID. */ + onlineId: number + /** The ID of the mailbox to update. */ + mailboxId: number + /** New password for the mailbox. */ + password?: string +} + export type CreateHostingRequest = { /** * Region to target. If none is passed will use default region from the @@ -370,6 +455,13 @@ export interface ListHostingsResponse { hostings: Hosting[] } +export interface ListMailboxesResponse { + /** Total number of mailboxes. */ + totalCount: number + /** List of mailboxes. */ + mailboxes: Mailbox[] +} + export type ListOffersRequest = { /** * Region to target. If none is passed will use default region from the diff --git a/packages/clients/src/api/webhosting/v1alpha1/validation-rules.gen.ts b/packages/clients/src/api/webhosting/v1alpha1/validation-rules.gen.ts index 3619289a8..c886d2e84 100644 --- a/packages/clients/src/api/webhosting/v1alpha1/validation-rules.gen.ts +++ b/packages/clients/src/api/webhosting/v1alpha1/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 ClassicMailApiListMailboxesRequest = { + page: { + greaterThan: 0, + }, + pageSize: { + greaterThan: 0, + lessThanOrEqual: 100, + }, +} + export const ListControlPanelsRequest = { page: { greaterThan: 0,