Skip to content

Commit 329b018

Browse files
authored
feat(tem): read update delete webhook(s) (#1301)
1 parent b7b32a9 commit 329b018

File tree

5 files changed

+352
-0
lines changed

5 files changed

+352
-0
lines changed

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

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,25 @@ import {
1515
import {
1616
marshalCreateDomainRequest,
1717
marshalCreateEmailRequest,
18+
marshalUpdateWebhookRequest,
1819
unmarshalCreateEmailResponse,
1920
unmarshalDomain,
2021
unmarshalDomainLastStatus,
2122
unmarshalEmail,
2223
unmarshalListDomainsResponse,
2324
unmarshalListEmailsResponse,
25+
unmarshalListWebhookEventsResponse,
26+
unmarshalListWebhooksResponse,
2427
unmarshalStatistics,
28+
unmarshalWebhook,
2529
} from './marshalling.gen'
2630
import type {
2731
CancelEmailRequest,
2832
CheckDomainRequest,
2933
CreateDomainRequest,
3034
CreateEmailRequest,
3135
CreateEmailResponse,
36+
DeleteWebhookRequest,
3237
Domain,
3338
DomainLastStatus,
3439
Email,
@@ -40,8 +45,14 @@ import type {
4045
ListDomainsResponse,
4146
ListEmailsRequest,
4247
ListEmailsResponse,
48+
ListWebhookEventsRequest,
49+
ListWebhookEventsResponse,
50+
ListWebhooksRequest,
51+
ListWebhooksResponse,
4352
RevokeDomainRequest,
4453
Statistics,
54+
UpdateWebhookRequest,
55+
Webhook,
4556
} from './types.gen'
4657

4758
const jsonContentHeaders = {
@@ -340,4 +351,69 @@ export class API extends ParentAPI {
340351
},
341352
unmarshalDomainLastStatus,
342353
)
354+
355+
protected pageOfListWebhooks = (
356+
request: Readonly<ListWebhooksRequest> = {},
357+
) =>
358+
this.client.fetch<ListWebhooksResponse>(
359+
{
360+
method: 'GET',
361+
path: `/transactional-email/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/webhooks`,
362+
urlParams: urlParams(
363+
['order_by', request.orderBy],
364+
['organization_id', request.organizationId],
365+
['page', request.page],
366+
[
367+
'page_size',
368+
request.pageSize ?? this.client.settings.defaultPageSize,
369+
],
370+
['project_id', request.projectId],
371+
),
372+
},
373+
unmarshalListWebhooksResponse,
374+
)
375+
376+
listWebhooks = (request: Readonly<ListWebhooksRequest> = {}) =>
377+
enrichForPagination('webhooks', this.pageOfListWebhooks, request)
378+
379+
updateWebhook = (request: Readonly<UpdateWebhookRequest>) =>
380+
this.client.fetch<Webhook>(
381+
{
382+
body: JSON.stringify(
383+
marshalUpdateWebhookRequest(request, this.client.settings),
384+
),
385+
headers: jsonContentHeaders,
386+
method: 'PATCH',
387+
path: `/transactional-email/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/webhooks/${validatePathParam('webhookId', request.webhookId)}`,
388+
},
389+
unmarshalWebhook,
390+
)
391+
392+
deleteWebhook = (request: Readonly<DeleteWebhookRequest>) =>
393+
this.client.fetch<void>({
394+
method: 'DELETE',
395+
path: `/transactional-email/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/webhooks/${validatePathParam('webhookId', request.webhookId)}`,
396+
})
397+
398+
protected pageOfListWebhookEvents = (
399+
request: Readonly<ListWebhookEventsRequest>,
400+
) =>
401+
this.client.fetch<ListWebhookEventsResponse>(
402+
{
403+
method: 'GET',
404+
path: `/transactional-email/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/webhooks/${validatePathParam('webhookId', request.webhookId)}/events`,
405+
urlParams: urlParams(
406+
['order_by', request.orderBy],
407+
['page', request.page],
408+
[
409+
'page_size',
410+
request.pageSize ?? this.client.settings.defaultPageSize,
411+
],
412+
),
413+
},
414+
unmarshalListWebhookEventsResponse,
415+
)
416+
417+
listWebhookEvents = (request: Readonly<ListWebhookEventsRequest>) =>
418+
enrichForPagination('webhookEvents', this.pageOfListWebhookEvents, request)
343419
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type {
1111
CreateEmailRequestAttachment,
1212
CreateEmailRequestHeader,
1313
CreateEmailResponse,
14+
DeleteWebhookRequest,
1415
Domain,
1516
DomainLastStatus,
1617
DomainLastStatusDkimRecord,
@@ -37,6 +38,18 @@ export type {
3738
ListEmailsRequest,
3839
ListEmailsRequestOrderBy,
3940
ListEmailsResponse,
41+
ListWebhookEventsRequest,
42+
ListWebhookEventsRequestOrderBy,
43+
ListWebhookEventsResponse,
44+
ListWebhooksRequest,
45+
ListWebhooksRequestOrderBy,
46+
ListWebhooksResponse,
4047
RevokeDomainRequest,
4148
Statistics,
49+
UpdateWebhookRequest,
50+
Webhook,
51+
WebhookEvent,
52+
WebhookEventStatus,
53+
WebhookEventType,
4254
} from './types.gen'
55+
export * as ValidationRules from './validation-rules.gen'

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

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ import type {
2626
EmailTry,
2727
ListDomainsResponse,
2828
ListEmailsResponse,
29+
ListWebhookEventsResponse,
30+
ListWebhooksResponse,
2931
Statistics,
32+
UpdateWebhookRequest,
33+
Webhook,
34+
WebhookEvent,
3035
} from './types.gen'
3136

3237
const unmarshalEmailTry = (data: unknown): EmailTry => {
@@ -157,6 +162,26 @@ export const unmarshalDomain = (data: unknown): Domain => {
157162
} as Domain
158163
}
159164

165+
export const unmarshalWebhook = (data: unknown): Webhook => {
166+
if (!isJSONObject(data)) {
167+
throw new TypeError(
168+
`Unmarshalling the type 'Webhook' failed as data isn't a dictionary.`,
169+
)
170+
}
171+
172+
return {
173+
createdAt: unmarshalDate(data.created_at),
174+
domainId: data.domain_id,
175+
eventTypes: data.event_types,
176+
id: data.id,
177+
name: data.name,
178+
organizationId: data.organization_id,
179+
projectId: data.project_id,
180+
snsArn: data.sns_arn,
181+
updatedAt: unmarshalDate(data.updated_at),
182+
} as Webhook
183+
}
184+
160185
export const unmarshalCreateEmailResponse = (
161186
data: unknown,
162187
): CreateEmailResponse => {
@@ -271,6 +296,60 @@ export const unmarshalListEmailsResponse = (
271296
} as ListEmailsResponse
272297
}
273298

299+
const unmarshalWebhookEvent = (data: unknown): WebhookEvent => {
300+
if (!isJSONObject(data)) {
301+
throw new TypeError(
302+
`Unmarshalling the type 'WebhookEvent' failed as data isn't a dictionary.`,
303+
)
304+
}
305+
306+
return {
307+
createdAt: unmarshalDate(data.created_at),
308+
data: data.data,
309+
emailId: data.email_id,
310+
id: data.id,
311+
organizationId: data.organization_id,
312+
projectId: data.project_id,
313+
status: data.status,
314+
type: data.type,
315+
updatedAt: unmarshalDate(data.updated_at),
316+
webhookId: data.webhook_id,
317+
} as WebhookEvent
318+
}
319+
320+
export const unmarshalListWebhookEventsResponse = (
321+
data: unknown,
322+
): ListWebhookEventsResponse => {
323+
if (!isJSONObject(data)) {
324+
throw new TypeError(
325+
`Unmarshalling the type 'ListWebhookEventsResponse' failed as data isn't a dictionary.`,
326+
)
327+
}
328+
329+
return {
330+
totalCount: data.total_count,
331+
webhookEvents: unmarshalArrayOfObject(
332+
data.webhook_events,
333+
unmarshalWebhookEvent,
334+
),
335+
} as ListWebhookEventsResponse
336+
}
337+
338+
export const unmarshalListWebhooksResponse = (
339+
data: unknown,
340+
): ListWebhooksResponse => {
341+
if (!isJSONObject(data)) {
342+
throw new TypeError(
343+
`Unmarshalling the type 'ListWebhooksResponse' failed as data isn't a dictionary.`,
344+
)
345+
}
346+
347+
return {
348+
totalCount: data.total_count,
349+
webhooks: unmarshalArrayOfObject(data.webhooks, unmarshalWebhook),
350+
} as ListWebhooksResponse
351+
}
352+
274353
export const unmarshalStatistics = (data: unknown): Statistics => {
275354
if (!isJSONObject(data)) {
276355
throw new TypeError(
@@ -360,3 +439,13 @@ export const marshalCreateEmailRequest = (
360439
? request.to.map(elt => marshalCreateEmailRequestAddress(elt, defaults))
361440
: undefined,
362441
})
442+
443+
export const marshalUpdateWebhookRequest = (
444+
request: UpdateWebhookRequest,
445+
defaults: DefaultValues,
446+
): Record<string, unknown> => ({
447+
event_types:
448+
request.eventTypes !== undefined ? request.eventTypes : undefined,
449+
name: request.name,
450+
sns_arn: request.snsArn,
451+
})

0 commit comments

Comments
 (0)