Skip to content

Commit 930cd2c

Browse files
authored
docs(tem): add info about webhooks (#1373)
1 parent ead32a1 commit 930cd2c

File tree

5 files changed

+92
-0
lines changed

5 files changed

+92
-0
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
import {
1616
marshalCreateDomainRequest,
1717
marshalCreateEmailRequest,
18+
marshalCreateWebhookRequest,
1819
marshalUpdateWebhookRequest,
1920
unmarshalCreateEmailResponse,
2021
unmarshalDomain,
@@ -33,6 +34,7 @@ import type {
3334
CreateDomainRequest,
3435
CreateEmailRequest,
3536
CreateEmailResponse,
37+
CreateWebhookRequest,
3638
DeleteWebhookRequest,
3739
Domain,
3840
DomainLastStatus,
@@ -41,6 +43,7 @@ import type {
4143
GetDomainRequest,
4244
GetEmailRequest,
4345
GetStatisticsRequest,
46+
GetWebhookRequest,
4447
ListDomainsRequest,
4548
ListDomainsResponse,
4649
ListEmailsRequest,
@@ -352,6 +355,26 @@ export class API extends ParentAPI {
352355
unmarshalDomainLastStatus,
353356
)
354357

358+
/**
359+
* Create a Webhook. Create a new Webhook triggered by a list of event types
360+
* and pushed to a Scaleway SNS ARN.
361+
*
362+
* @param request - The request {@link CreateWebhookRequest}
363+
* @returns A Promise of Webhook
364+
*/
365+
createWebhook = (request: Readonly<CreateWebhookRequest>) =>
366+
this.client.fetch<Webhook>(
367+
{
368+
body: JSON.stringify(
369+
marshalCreateWebhookRequest(request, this.client.settings),
370+
),
371+
headers: jsonContentHeaders,
372+
method: 'POST',
373+
path: `/transactional-email/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/webhooks`,
374+
},
375+
unmarshalWebhook,
376+
)
377+
355378
protected pageOfListWebhooks = (
356379
request: Readonly<ListWebhooksRequest> = {},
357380
) =>
@@ -377,6 +400,21 @@ export class API extends ParentAPI {
377400
listWebhooks = (request: Readonly<ListWebhooksRequest> = {}) =>
378401
enrichForPagination('webhooks', this.pageOfListWebhooks, request)
379402

403+
/**
404+
* Get information about a Webhook.
405+
*
406+
* @param request - The request {@link GetWebhookRequest}
407+
* @returns A Promise of Webhook
408+
*/
409+
getWebhook = (request: Readonly<GetWebhookRequest>) =>
410+
this.client.fetch<Webhook>(
411+
{
412+
method: 'GET',
413+
path: `/transactional-email/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/webhooks/${validatePathParam('webhookId', request.webhookId)}`,
414+
},
415+
unmarshalWebhook,
416+
)
417+
380418
updateWebhook = (request: Readonly<UpdateWebhookRequest>) =>
381419
this.client.fetch<Webhook>(
382420
{

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type {
1111
CreateEmailRequestAttachment,
1212
CreateEmailRequestHeader,
1313
CreateEmailResponse,
14+
CreateWebhookRequest,
1415
DeleteWebhookRequest,
1516
Domain,
1617
DomainLastStatus,
@@ -33,6 +34,7 @@ export type {
3334
GetDomainRequest,
3435
GetEmailRequest,
3536
GetStatisticsRequest,
37+
GetWebhookRequest,
3638
ListDomainsRequest,
3739
ListDomainsResponse,
3840
ListEmailsRequest,

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
CreateEmailRequestAttachment,
1414
CreateEmailRequestHeader,
1515
CreateEmailResponse,
16+
CreateWebhookRequest,
1617
Domain,
1718
DomainLastStatus,
1819
DomainLastStatusDkimRecord,
@@ -438,6 +439,18 @@ export const marshalCreateEmailRequest = (
438439
: undefined,
439440
})
440441

442+
export const marshalCreateWebhookRequest = (
443+
request: CreateWebhookRequest,
444+
defaults: DefaultValues,
445+
): Record<string, unknown> => ({
446+
domain_id: request.domainId,
447+
event_types:
448+
request.eventTypes !== undefined ? request.eventTypes : undefined,
449+
name: request.name,
450+
project_id: request.projectId ?? defaults.defaultProjectId,
451+
sns_arn: request.snsArn,
452+
})
453+
441454
export const marshalUpdateWebhookRequest = (
442455
request: UpdateWebhookRequest,
443456
defaults: DefaultValues,

packages/clients/src/api/tem/v1alpha1/types.gen.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,24 @@ export interface CreateEmailResponse {
374374
emails: Email[]
375375
}
376376

377+
export type CreateWebhookRequest = {
378+
/**
379+
* Region to target. If none is passed will use default region from the
380+
* config.
381+
*/
382+
region?: Region
383+
/** ID of the Domain to watch for triggering events. */
384+
domainId: string
385+
/** ID of the project to which the Webhook belongs. */
386+
projectId?: string
387+
/** Name of the Webhook. */
388+
name: string
389+
/** List of event types that will trigger an event. */
390+
eventTypes?: WebhookEventType[]
391+
/** Scaleway SNS ARN topic to push the events to. */
392+
snsArn: string
393+
}
394+
377395
export type DeleteWebhookRequest = {
378396
/**
379397
* Region to target. If none is passed will use default region from the
@@ -448,6 +466,16 @@ export type GetStatisticsRequest = {
448466
mailFrom?: string
449467
}
450468

469+
export type GetWebhookRequest = {
470+
/**
471+
* Region to target. If none is passed will use default region from the
472+
* config.
473+
*/
474+
region?: Region
475+
/** ID of the Webhook to check. */
476+
webhookId: string
477+
}
478+
451479
export type ListDomainsRequest = {
452480
/**
453481
* Region to target. If none is passed will use default region from the

packages/clients/src/api/tem/v1alpha1/validation-rules.gen.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ export const CreateEmailRequestHeader = {
3838
},
3939
}
4040

41+
export const CreateWebhookRequest = {
42+
name: {
43+
maxLength: 127,
44+
minLength: 3,
45+
},
46+
snsArn: {
47+
maxLength: 127,
48+
minLength: 3,
49+
},
50+
}
51+
4152
export const ListDomainsRequest = {
4253
page: {
4354
greaterThan: 0,

0 commit comments

Comments
 (0)