Skip to content

Commit ad3dfed

Browse files
feat(webhosting): add first version of the classic mail api (#1386)
Co-authored-by: Rémy Léone <[email protected]>
1 parent 79c21cd commit ad3dfed

File tree

5 files changed

+304
-1
lines changed

5 files changed

+304
-1
lines changed

packages/clients/src/api/webhosting/v1alpha1/api.gen.ts

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,29 @@ import type { Region, WaitForOptions } from '../../../bridge'
1111
import { HOSTING_TRANSIENT_STATUSES } from './content.gen'
1212
import {
1313
marshalCheckUserOwnsDomainRequest,
14+
marshalClassicMailApiCreateMailboxRequest,
15+
marshalClassicMailApiUpdateMailboxRequest,
1416
marshalCreateHostingRequest,
1517
marshalUpdateHostingRequest,
1618
unmarshalCheckUserOwnsDomainResponse,
1719
unmarshalDnsRecords,
1820
unmarshalHosting,
1921
unmarshalListControlPanelsResponse,
2022
unmarshalListHostingsResponse,
23+
unmarshalListMailboxesResponse,
2124
unmarshalListOffersResponse,
25+
unmarshalMailbox,
2226
unmarshalResetHostingPasswordResponse,
2327
unmarshalSession,
2428
} from './marshalling.gen'
2529
import type {
2630
CheckUserOwnsDomainRequest,
2731
CheckUserOwnsDomainResponse,
32+
ClassicMailApiCreateMailboxRequest,
33+
ClassicMailApiDeleteMailboxRequest,
34+
ClassicMailApiGetMailboxRequest,
35+
ClassicMailApiListMailboxesRequest,
36+
ClassicMailApiUpdateMailboxRequest,
2837
CreateHostingRequest,
2938
CreateSessionRequest,
3039
DeleteHostingRequest,
@@ -36,8 +45,10 @@ import type {
3645
ListControlPanelsResponse,
3746
ListHostingsRequest,
3847
ListHostingsResponse,
48+
ListMailboxesResponse,
3949
ListOffersRequest,
4050
ListOffersResponse,
51+
Mailbox,
4152
ResetHostingPasswordRequest,
4253
ResetHostingPasswordResponse,
4354
RestoreHostingRequest,
@@ -324,3 +335,113 @@ export class API extends ParentAPI {
324335
unmarshalResetHostingPasswordResponse,
325336
)
326337
}
338+
339+
/**
340+
* Web Hosting Classic Mailbox API.
341+
*
342+
* This API allows you to manage your mailboxes for your Web Hosting services.
343+
*/
344+
export class ClassicMailAPI extends ParentAPI {
345+
/** Lists the available regions of the API. */
346+
public static readonly LOCALITIES: Region[] = ['fr-par', 'nl-ams', 'pl-waw']
347+
348+
/**
349+
* Create a new mailbox within your hosting plan.. Create a new mailbox within
350+
* your hosting plan.
351+
*
352+
* @param request - The request {@link ClassicMailApiCreateMailboxRequest}
353+
* @returns A Promise of Mailbox
354+
*/
355+
createMailbox = (request: Readonly<ClassicMailApiCreateMailboxRequest>) =>
356+
this.client.fetch<Mailbox>(
357+
{
358+
body: JSON.stringify(
359+
marshalClassicMailApiCreateMailboxRequest(
360+
request,
361+
this.client.settings,
362+
),
363+
),
364+
headers: jsonContentHeaders,
365+
method: 'POST',
366+
path: `/webhosting/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/classic-hostings/${validatePathParam('onlineId', request.onlineId)}/mailboxes`,
367+
},
368+
unmarshalMailbox,
369+
)
370+
371+
/**
372+
* Get a mailbox by id within your hosting plan.. Get a mailbox by id within
373+
* your hosting plan.
374+
*
375+
* @param request - The request {@link ClassicMailApiGetMailboxRequest}
376+
* @returns A Promise of Mailbox
377+
*/
378+
getMailbox = (request: Readonly<ClassicMailApiGetMailboxRequest>) =>
379+
this.client.fetch<Mailbox>(
380+
{
381+
method: 'GET',
382+
path: `/webhosting/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/classic-hostings/${validatePathParam('onlineId', request.onlineId)}/mailboxes/${validatePathParam('mailboxId', request.mailboxId)}`,
383+
},
384+
unmarshalMailbox,
385+
)
386+
387+
protected pageOfListMailboxes = (
388+
request: Readonly<ClassicMailApiListMailboxesRequest>,
389+
) =>
390+
this.client.fetch<ListMailboxesResponse>(
391+
{
392+
method: 'GET',
393+
path: `/webhosting/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/classic-hostings/${validatePathParam('onlineId', request.onlineId)}/mailboxes`,
394+
urlParams: urlParams(
395+
['domain', request.domain],
396+
['page', request.page],
397+
[
398+
'page_size',
399+
request.pageSize ?? this.client.settings.defaultPageSize,
400+
],
401+
),
402+
},
403+
unmarshalListMailboxesResponse,
404+
)
405+
406+
/**
407+
* List all mailboxes within your hosting plan.. List all mailboxes within
408+
* your hosting plan.
409+
*
410+
* @param request - The request {@link ClassicMailApiListMailboxesRequest}
411+
* @returns A Promise of ListMailboxesResponse
412+
*/
413+
listMailboxes = (request: Readonly<ClassicMailApiListMailboxesRequest>) =>
414+
enrichForPagination('mailboxes', this.pageOfListMailboxes, request)
415+
416+
deleteMailbox = (request: Readonly<ClassicMailApiDeleteMailboxRequest>) =>
417+
this.client.fetch<Mailbox>(
418+
{
419+
method: 'DELETE',
420+
path: `/webhosting/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/classic-hostings/${validatePathParam('onlineId', request.onlineId)}/mailboxes/${validatePathParam('mailboxId', request.mailboxId)}`,
421+
},
422+
unmarshalMailbox,
423+
)
424+
425+
/**
426+
* Update the mailbox within your hosting plan.. Update the mailbox within
427+
* your hosting plan.
428+
*
429+
* @param request - The request {@link ClassicMailApiUpdateMailboxRequest}
430+
* @returns A Promise of Mailbox
431+
*/
432+
updateMailbox = (request: Readonly<ClassicMailApiUpdateMailboxRequest>) =>
433+
this.client.fetch<Mailbox>(
434+
{
435+
body: JSON.stringify(
436+
marshalClassicMailApiUpdateMailboxRequest(
437+
request,
438+
this.client.settings,
439+
),
440+
),
441+
headers: jsonContentHeaders,
442+
method: 'PATCH',
443+
path: `/webhosting/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/classic-hostings/${validatePathParam('onlineId', request.onlineId)}/mailboxes/${validatePathParam('mailboxId', request.mailboxId)}`,
444+
},
445+
unmarshalMailbox,
446+
)
447+
}

packages/clients/src/api/webhosting/v1alpha1/index.gen.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
// This file was automatically generated. DO NOT EDIT.
22
// If you have any remark or suggestion do not hesitate to open an issue.
3-
export { API } from './api.gen'
3+
export { API, ClassicMailAPI } from './api.gen'
44
export * from './content.gen'
55
export type {
66
CheckUserOwnsDomainRequest,
77
CheckUserOwnsDomainResponse,
8+
ClassicMailApiCreateMailboxRequest,
9+
ClassicMailApiDeleteMailboxRequest,
10+
ClassicMailApiGetMailboxRequest,
11+
ClassicMailApiListMailboxesRequest,
12+
ClassicMailApiUpdateMailboxRequest,
813
ControlPanel,
914
CreateHostingRequest,
1015
CreateHostingRequestDomainConfiguration,
@@ -15,6 +20,7 @@ export type {
1520
DnsRecordType,
1621
DnsRecords,
1722
DnsRecordsStatus,
23+
EmailAddress,
1824
GetDomainDnsRecordsRequest,
1925
GetHostingRequest,
2026
Hosting,
@@ -27,9 +33,11 @@ export type {
2733
ListHostingsRequest,
2834
ListHostingsRequestOrderBy,
2935
ListHostingsResponse,
36+
ListMailboxesResponse,
3037
ListOffersRequest,
3138
ListOffersRequestOrderBy,
3239
ListOffersResponse,
40+
Mailbox,
3341
Nameserver,
3442
NameserverStatus,
3543
Offer,

packages/clients/src/api/webhosting/v1alpha1/marshalling.gen.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,22 @@ import type { DefaultValues } from '../../../bridge'
1010
import type {
1111
CheckUserOwnsDomainRequest,
1212
CheckUserOwnsDomainResponse,
13+
ClassicMailApiCreateMailboxRequest,
14+
ClassicMailApiUpdateMailboxRequest,
1315
ControlPanel,
1416
CreateHostingRequest,
1517
CreateHostingRequestDomainConfiguration,
1618
DnsRecord,
1719
DnsRecords,
20+
EmailAddress,
1821
Hosting,
1922
HostingCpanelUrls,
2023
HostingOption,
2124
ListControlPanelsResponse,
2225
ListHostingsResponse,
26+
ListMailboxesResponse,
2327
ListOffersResponse,
28+
Mailbox,
2429
Nameserver,
2530
Offer,
2631
OfferProduct,
@@ -92,6 +97,32 @@ export const unmarshalHosting = (data: unknown): Hosting => {
9297
} as Hosting
9398
}
9499

100+
const unmarshalEmailAddress = (data: unknown): EmailAddress => {
101+
if (!isJSONObject(data)) {
102+
throw new TypeError(
103+
`Unmarshalling the type 'EmailAddress' failed as data isn't a dictionary.`,
104+
)
105+
}
106+
107+
return {
108+
domain: data.domain,
109+
login: data.login,
110+
} as EmailAddress
111+
}
112+
113+
export const unmarshalMailbox = (data: unknown): Mailbox => {
114+
if (!isJSONObject(data)) {
115+
throw new TypeError(
116+
`Unmarshalling the type 'Mailbox' failed as data isn't a dictionary.`,
117+
)
118+
}
119+
120+
return {
121+
email: data.email ? unmarshalEmailAddress(data.email) : undefined,
122+
mailboxId: data.mailbox_id,
123+
} as Mailbox
124+
}
125+
95126
export const unmarshalCheckUserOwnsDomainResponse = (
96127
data: unknown,
97128
): CheckUserOwnsDomainResponse => {
@@ -199,6 +230,21 @@ export const unmarshalListHostingsResponse = (
199230
} as ListHostingsResponse
200231
}
201232

233+
export const unmarshalListMailboxesResponse = (
234+
data: unknown,
235+
): ListMailboxesResponse => {
236+
if (!isJSONObject(data)) {
237+
throw new TypeError(
238+
`Unmarshalling the type 'ListMailboxesResponse' failed as data isn't a dictionary.`,
239+
)
240+
}
241+
242+
return {
243+
mailboxes: unmarshalArrayOfObject(data.mailboxes, unmarshalMailbox),
244+
totalCount: data.total_count,
245+
} as ListMailboxesResponse
246+
}
247+
202248
const unmarshalOfferProduct = (data: unknown): OfferProduct => {
203249
if (!isJSONObject(data)) {
204250
throw new TypeError(
@@ -286,6 +332,32 @@ export const marshalCheckUserOwnsDomainRequest = (
286332
project_id: request.projectId ?? defaults.defaultProjectId,
287333
})
288334

335+
const marshalEmailAddress = (
336+
request: EmailAddress,
337+
defaults: DefaultValues,
338+
): Record<string, unknown> => ({
339+
domain: request.domain,
340+
login: request.login,
341+
})
342+
343+
export const marshalClassicMailApiCreateMailboxRequest = (
344+
request: ClassicMailApiCreateMailboxRequest,
345+
defaults: DefaultValues,
346+
): Record<string, unknown> => ({
347+
email:
348+
request.email !== undefined
349+
? marshalEmailAddress(request.email, defaults)
350+
: undefined,
351+
password: request.password,
352+
})
353+
354+
export const marshalClassicMailApiUpdateMailboxRequest = (
355+
request: ClassicMailApiUpdateMailboxRequest,
356+
defaults: DefaultValues,
357+
): Record<string, unknown> => ({
358+
password: request.password,
359+
})
360+
289361
const marshalCreateHostingRequestDomainConfiguration = (
290362
request: CreateHostingRequestDomainConfiguration,
291363
defaults: DefaultValues,

0 commit comments

Comments
 (0)