Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions packages/clients/src/api/tem/v1alpha1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,25 @@ import {
import {
marshalCreateDomainRequest,
marshalCreateEmailRequest,
marshalUpdateWebhookRequest,
unmarshalCreateEmailResponse,
unmarshalDomain,
unmarshalDomainLastStatus,
unmarshalEmail,
unmarshalListDomainsResponse,
unmarshalListEmailsResponse,
unmarshalListWebhookEventsResponse,
unmarshalListWebhooksResponse,
unmarshalStatistics,
unmarshalWebhook,
} from './marshalling.gen'
import type {
CancelEmailRequest,
CheckDomainRequest,
CreateDomainRequest,
CreateEmailRequest,
CreateEmailResponse,
DeleteWebhookRequest,
Domain,
DomainLastStatus,
Email,
Expand All @@ -40,8 +45,14 @@ import type {
ListDomainsResponse,
ListEmailsRequest,
ListEmailsResponse,
ListWebhookEventsRequest,
ListWebhookEventsResponse,
ListWebhooksRequest,
ListWebhooksResponse,
RevokeDomainRequest,
Statistics,
UpdateWebhookRequest,
Webhook,
} from './types.gen'

const jsonContentHeaders = {
Expand Down Expand Up @@ -340,4 +351,69 @@ export class API extends ParentAPI {
},
unmarshalDomainLastStatus,
)

protected pageOfListWebhooks = (
request: Readonly<ListWebhooksRequest> = {},
) =>
this.client.fetch<ListWebhooksResponse>(
{
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<ListWebhooksRequest> = {}) =>
enrichForPagination('webhooks', this.pageOfListWebhooks, request)

updateWebhook = (request: Readonly<UpdateWebhookRequest>) =>
this.client.fetch<Webhook>(
{
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<DeleteWebhookRequest>) =>
this.client.fetch<void>({
method: 'DELETE',
path: `/transactional-email/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/webhooks/${validatePathParam('webhookId', request.webhookId)}`,
})

protected pageOfListWebhookEvents = (
request: Readonly<ListWebhookEventsRequest>,
) =>
this.client.fetch<ListWebhookEventsResponse>(
{
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<ListWebhookEventsRequest>) =>
enrichForPagination('webhookEvents', this.pageOfListWebhookEvents, request)
}
13 changes: 13 additions & 0 deletions packages/clients/src/api/tem/v1alpha1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type {
CreateEmailRequestAttachment,
CreateEmailRequestHeader,
CreateEmailResponse,
DeleteWebhookRequest,
Domain,
DomainLastStatus,
DomainLastStatusDkimRecord,
Expand All @@ -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'
89 changes: 89 additions & 0 deletions packages/clients/src/api/tem/v1alpha1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ import type {
EmailTry,
ListDomainsResponse,
ListEmailsResponse,
ListWebhookEventsResponse,
ListWebhooksResponse,
Statistics,
UpdateWebhookRequest,
Webhook,
WebhookEvent,
} from './types.gen'

const unmarshalEmailTry = (data: unknown): EmailTry => {
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -360,3 +439,13 @@ export const marshalCreateEmailRequest = (
? request.to.map(elt => marshalCreateEmailRequestAddress(elt, defaults))
: undefined,
})

export const marshalUpdateWebhookRequest = (
request: UpdateWebhookRequest,
defaults: DefaultValues,
): Record<string, unknown> => ({
event_types:
request.eventTypes !== undefined ? request.eventTypes : undefined,
name: request.name,
sns_arn: request.snsArn,
})
Loading