diff --git a/packages/clients/src/api/tem/v1alpha1/api.gen.ts b/packages/clients/src/api/tem/v1alpha1/api.gen.ts index 4bf8d7f48..55b108833 100644 --- a/packages/clients/src/api/tem/v1alpha1/api.gen.ts +++ b/packages/clients/src/api/tem/v1alpha1/api.gen.ts @@ -15,13 +15,17 @@ import { import { marshalCreateDomainRequest, marshalCreateEmailRequest, + marshalUpdateWebhookRequest, unmarshalCreateEmailResponse, unmarshalDomain, unmarshalDomainLastStatus, unmarshalEmail, unmarshalListDomainsResponse, unmarshalListEmailsResponse, + unmarshalListWebhookEventsResponse, + unmarshalListWebhooksResponse, unmarshalStatistics, + unmarshalWebhook, } from './marshalling.gen' import type { CancelEmailRequest, @@ -29,6 +33,7 @@ import type { CreateDomainRequest, CreateEmailRequest, CreateEmailResponse, + DeleteWebhookRequest, Domain, DomainLastStatus, Email, @@ -40,8 +45,14 @@ import type { ListDomainsResponse, ListEmailsRequest, ListEmailsResponse, + ListWebhookEventsRequest, + ListWebhookEventsResponse, + ListWebhooksRequest, + ListWebhooksResponse, RevokeDomainRequest, Statistics, + UpdateWebhookRequest, + Webhook, } from './types.gen' const jsonContentHeaders = { @@ -340,4 +351,69 @@ export class API extends ParentAPI { }, unmarshalDomainLastStatus, ) + + protected pageOfListWebhooks = ( + request: Readonly = {}, + ) => + this.client.fetch( + { + method: 'GET', + path: `/transactional-email/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/webhooks`, + urlParams: urlParams( + ['order_by', request.orderBy], + ['organization_id', request.organizationId], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ['project_id', request.projectId], + ), + }, + unmarshalListWebhooksResponse, + ) + + listWebhooks = (request: Readonly = {}) => + enrichForPagination('webhooks', this.pageOfListWebhooks, request) + + updateWebhook = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalUpdateWebhookRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PATCH', + path: `/transactional-email/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/webhooks/${validatePathParam('webhookId', request.webhookId)}`, + }, + unmarshalWebhook, + ) + + deleteWebhook = (request: Readonly) => + this.client.fetch({ + method: 'DELETE', + path: `/transactional-email/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/webhooks/${validatePathParam('webhookId', request.webhookId)}`, + }) + + protected pageOfListWebhookEvents = ( + request: Readonly, + ) => + this.client.fetch( + { + method: 'GET', + path: `/transactional-email/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/webhooks/${validatePathParam('webhookId', request.webhookId)}/events`, + urlParams: urlParams( + ['order_by', request.orderBy], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ), + }, + unmarshalListWebhookEventsResponse, + ) + + listWebhookEvents = (request: Readonly) => + enrichForPagination('webhookEvents', this.pageOfListWebhookEvents, request) } diff --git a/packages/clients/src/api/tem/v1alpha1/index.gen.ts b/packages/clients/src/api/tem/v1alpha1/index.gen.ts index 2db4a8b54..2583bc31e 100644 --- a/packages/clients/src/api/tem/v1alpha1/index.gen.ts +++ b/packages/clients/src/api/tem/v1alpha1/index.gen.ts @@ -11,6 +11,7 @@ export type { CreateEmailRequestAttachment, CreateEmailRequestHeader, CreateEmailResponse, + DeleteWebhookRequest, Domain, DomainLastStatus, DomainLastStatusDkimRecord, @@ -37,6 +38,18 @@ export type { ListEmailsRequest, ListEmailsRequestOrderBy, ListEmailsResponse, + ListWebhookEventsRequest, + ListWebhookEventsRequestOrderBy, + ListWebhookEventsResponse, + ListWebhooksRequest, + ListWebhooksRequestOrderBy, + ListWebhooksResponse, RevokeDomainRequest, Statistics, + UpdateWebhookRequest, + Webhook, + WebhookEvent, + WebhookEventStatus, + WebhookEventType, } from './types.gen' +export * as ValidationRules from './validation-rules.gen' diff --git a/packages/clients/src/api/tem/v1alpha1/marshalling.gen.ts b/packages/clients/src/api/tem/v1alpha1/marshalling.gen.ts index ce1e62e57..5a87d7ac9 100644 --- a/packages/clients/src/api/tem/v1alpha1/marshalling.gen.ts +++ b/packages/clients/src/api/tem/v1alpha1/marshalling.gen.ts @@ -26,7 +26,12 @@ import type { EmailTry, ListDomainsResponse, ListEmailsResponse, + ListWebhookEventsResponse, + ListWebhooksResponse, Statistics, + UpdateWebhookRequest, + Webhook, + WebhookEvent, } from './types.gen' const unmarshalEmailTry = (data: unknown): EmailTry => { @@ -157,6 +162,26 @@ export const unmarshalDomain = (data: unknown): Domain => { } as Domain } +export const unmarshalWebhook = (data: unknown): Webhook => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Webhook' failed as data isn't a dictionary.`, + ) + } + + return { + createdAt: unmarshalDate(data.created_at), + domainId: data.domain_id, + eventTypes: data.event_types, + id: data.id, + name: data.name, + organizationId: data.organization_id, + projectId: data.project_id, + snsArn: data.sns_arn, + updatedAt: unmarshalDate(data.updated_at), + } as Webhook +} + export const unmarshalCreateEmailResponse = ( data: unknown, ): CreateEmailResponse => { @@ -271,6 +296,60 @@ export const unmarshalListEmailsResponse = ( } as ListEmailsResponse } +const unmarshalWebhookEvent = (data: unknown): WebhookEvent => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'WebhookEvent' failed as data isn't a dictionary.`, + ) + } + + return { + createdAt: unmarshalDate(data.created_at), + data: data.data, + emailId: data.email_id, + id: data.id, + organizationId: data.organization_id, + projectId: data.project_id, + status: data.status, + type: data.type, + updatedAt: unmarshalDate(data.updated_at), + webhookId: data.webhook_id, + } as WebhookEvent +} + +export const unmarshalListWebhookEventsResponse = ( + data: unknown, +): ListWebhookEventsResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListWebhookEventsResponse' failed as data isn't a dictionary.`, + ) + } + + return { + totalCount: data.total_count, + webhookEvents: unmarshalArrayOfObject( + data.webhook_events, + unmarshalWebhookEvent, + ), + } as ListWebhookEventsResponse +} + +export const unmarshalListWebhooksResponse = ( + data: unknown, +): ListWebhooksResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListWebhooksResponse' failed as data isn't a dictionary.`, + ) + } + + return { + totalCount: data.total_count, + webhooks: unmarshalArrayOfObject(data.webhooks, unmarshalWebhook), + } as ListWebhooksResponse +} + export const unmarshalStatistics = (data: unknown): Statistics => { if (!isJSONObject(data)) { throw new TypeError( @@ -360,3 +439,13 @@ export const marshalCreateEmailRequest = ( ? request.to.map(elt => marshalCreateEmailRequestAddress(elt, defaults)) : undefined, }) + +export const marshalUpdateWebhookRequest = ( + request: UpdateWebhookRequest, + defaults: DefaultValues, +): Record => ({ + event_types: + request.eventTypes !== undefined ? request.eventTypes : undefined, + name: request.name, + sns_arn: request.snsArn, +}) diff --git a/packages/clients/src/api/tem/v1alpha1/types.gen.ts b/packages/clients/src/api/tem/v1alpha1/types.gen.ts index 3cae1c90d..83930ce9d 100644 --- a/packages/clients/src/api/tem/v1alpha1/types.gen.ts +++ b/packages/clients/src/api/tem/v1alpha1/types.gen.ts @@ -58,6 +58,28 @@ export type ListEmailsRequestOrderBy = | 'subject_desc' | 'subject_asc' +export type ListWebhookEventsRequestOrderBy = + | 'created_at_desc' + | 'created_at_asc' + +export type ListWebhooksRequestOrderBy = 'created_at_desc' | 'created_at_asc' + +export type WebhookEventStatus = + | 'unknown_status' + | 'waiting' + | 'sending' + | 'sent' + | 'error' + +export type WebhookEventType = + | 'unknown_type' + | 'email_queued' + | 'email_dropped' + | 'email_deferred' + | 'email_delivered' + | 'email_spam' + | 'email_mailbox_not_found' + export interface DomainRecordsDMARC { /** Name of the DMARC TXT record. */ name: string @@ -238,6 +260,50 @@ export interface Domain { region: Region } +export interface WebhookEvent { + /** ID of the Webhook Event. */ + id: string + /** ID of the Webhook that triggers the Event. */ + webhookId: string + /** ID of the Webhook Event Organization. */ + organizationId: string + /** ID of the Webhook Event Project. */ + projectId: string + /** Type of the Webhook Event. */ + type: WebhookEventType + /** Status of the Webhook Event. */ + status: WebhookEventStatus + /** Data sent to the Webhook destination. */ + data: string + /** Date and time of the Webhook Event creation. */ + createdAt?: Date + /** Date and time of last Webhook Event updates. */ + updatedAt?: Date + /** Optional Email ID if the event is triggered by an Email resource. */ + emailId?: string +} + +export interface Webhook { + /** ID of the Webhook. */ + id: string + /** ID of the Domain to watch for triggering events. */ + domainId: string + /** ID of the Webhook Organization. */ + organizationId: string + /** ID of the Webhook Project. */ + projectId: string + /** Name of the Webhook. */ + name: string + /** List of event types that will trigger a Webhook Event. */ + eventTypes: WebhookEventType[] + /** Scaleway SNS ARN topic to push the events to. */ + snsArn: string + /** Date and time of the Webhook creation. */ + createdAt?: Date + /** Date and time of last Webhook updates. */ + updatedAt?: Date +} + export type CancelEmailRequest = { /** * Region to target. If none is passed will use default region from the @@ -307,6 +373,16 @@ export interface CreateEmailResponse { emails: Email[] } +export type DeleteWebhookRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** ID of the Webhook to delete. */ + webhookId: string +} + export interface DomainLastStatus { /** The ID of the domain. */ domainId: string @@ -394,6 +470,7 @@ export type ListDomainsRequest = { export interface ListDomainsResponse { /** Number of domains that match the request (without pagination). */ totalCount: number + /** Single page of domains matching the requested criteria. */ domains: Domain[] } @@ -440,6 +517,54 @@ export interface ListEmailsResponse { emails: Email[] } +export type ListWebhookEventsRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** ID of the Webhook linked to the events. */ + webhookId: string + /** (Optional) List Webhook events corresponding to specific criteria. */ + orderBy?: ListWebhookEventsRequestOrderBy + /** Requested page number. Value must be greater or equal to 1. */ + page?: number + /** Requested page size. Value must be between 1 and 100. */ + pageSize?: number +} + +export interface ListWebhookEventsResponse { + /** Number of Webhook events matching the requested criteria. */ + totalCount: number + /** Single page of Webhook events matching the requested criteria. */ + webhookEvents: WebhookEvent[] +} + +export type ListWebhooksRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** (Optional) List Webhooks corresponding to specific criteria. */ + orderBy?: ListWebhooksRequestOrderBy + /** (Optional) Requested page number. Value must be greater or equal to 1. */ + page?: number + /** (Optional) Requested page size. Value must be between 1 and 100. */ + pageSize?: number + /** (Optional) ID of the Project for which to list the Webhooks. */ + projectId?: string + /** (Optional) ID of the Organization for which to list the Webhooks. */ + organizationId?: string +} + +export interface ListWebhooksResponse { + /** Number of Webhooks matching the requested criteria. */ + totalCount: number + /** Single page of Webhooks matching the requested criteria. */ + webhooks: Webhook[] +} + export type RevokeDomainRequest = { /** * Region to target. If none is passed will use default region from the @@ -479,3 +604,19 @@ export interface Statistics { */ canceledCount: number } + +export type UpdateWebhookRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** ID of the Webhook to update. */ + webhookId: string + /** Name of the Webhook to update. */ + name?: string + /** List of event types to update. */ + eventTypes?: WebhookEventType[] + /** Scaleway SNS ARN topic to update. */ + snsArn?: string +} diff --git a/packages/clients/src/api/tem/v1alpha1/validation-rules.gen.ts b/packages/clients/src/api/tem/v1alpha1/validation-rules.gen.ts new file mode 100644 index 000000000..7155cecfb --- /dev/null +++ b/packages/clients/src/api/tem/v1alpha1/validation-rules.gen.ts @@ -0,0 +1,33 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. + +export const ListWebhookEventsRequest = { + page: { + greaterThan: 0, + }, + pageSize: { + greaterThanOrEqual: 1, + lessThanOrEqual: 100, + }, +} + +export const ListWebhooksRequest = { + page: { + greaterThan: 0, + }, + pageSize: { + greaterThanOrEqual: 1, + lessThanOrEqual: 100, + }, +} + +export const UpdateWebhookRequest = { + name: { + maxLength: 127, + minLength: 3, + }, + snsArn: { + maxLength: 127, + minLength: 3, + }, +}