Skip to content

Commit 773f36c

Browse files
authored
feat(tem): add project settings endpoint (#1435)
1 parent f55d194 commit 773f36c

File tree

5 files changed

+179
-0
lines changed

5 files changed

+179
-0
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
marshalCreateEmailRequest,
1818
marshalCreateWebhookRequest,
1919
marshalUpdateDomainRequest,
20+
marshalUpdateProjectSettingsRequest,
2021
marshalUpdateWebhookRequest,
2122
unmarshalCreateEmailResponse,
2223
unmarshalDomain,
@@ -26,6 +27,7 @@ import {
2627
unmarshalListEmailsResponse,
2728
unmarshalListWebhookEventsResponse,
2829
unmarshalListWebhooksResponse,
30+
unmarshalProjectSettings,
2931
unmarshalStatistics,
3032
unmarshalWebhook,
3133
} from './marshalling.gen'
@@ -43,6 +45,7 @@ import type {
4345
GetDomainLastStatusRequest,
4446
GetDomainRequest,
4547
GetEmailRequest,
48+
GetProjectSettingsRequest,
4649
GetStatisticsRequest,
4750
GetWebhookRequest,
4851
ListDomainsRequest,
@@ -53,9 +56,11 @@ import type {
5356
ListWebhookEventsResponse,
5457
ListWebhooksRequest,
5558
ListWebhooksResponse,
59+
ProjectSettings,
5660
RevokeDomainRequest,
5761
Statistics,
5862
UpdateDomainRequest,
63+
UpdateProjectSettingsRequest,
5964
UpdateWebhookRequest,
6065
Webhook,
6166
} from './types.gen'
@@ -511,4 +516,42 @@ export class API extends ParentAPI {
511516
*/
512517
listWebhookEvents = (request: Readonly<ListWebhookEventsRequest>) =>
513518
enrichForPagination('webhookEvents', this.pageOfListWebhookEvents, request)
519+
520+
/**
521+
* List project settings. Retrieve the project settings including periodic
522+
* reports.
523+
*
524+
* @param request - The request {@link GetProjectSettingsRequest}
525+
* @returns A Promise of ProjectSettings
526+
*/
527+
getProjectSettings = (request: Readonly<GetProjectSettingsRequest> = {}) =>
528+
this.client.fetch<ProjectSettings>(
529+
{
530+
method: 'GET',
531+
path: `/transactional-email/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/project/${validatePathParam('projectId', request.projectId ?? this.client.settings.defaultProjectId)}/settings`,
532+
},
533+
unmarshalProjectSettings,
534+
)
535+
536+
/**
537+
* Update project settings. Update the project settings including periodic
538+
* reports.
539+
*
540+
* @param request - The request {@link UpdateProjectSettingsRequest}
541+
* @returns A Promise of ProjectSettings
542+
*/
543+
updateProjectSettings = (
544+
request: Readonly<UpdateProjectSettingsRequest> = {},
545+
) =>
546+
this.client.fetch<ProjectSettings>(
547+
{
548+
body: JSON.stringify(
549+
marshalUpdateProjectSettingsRequest(request, this.client.settings),
550+
),
551+
headers: jsonContentHeaders,
552+
method: 'PATCH',
553+
path: `/transactional-email/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/project/${validatePathParam('projectId', request.projectId ?? this.client.settings.defaultProjectId)}/settings`,
554+
},
555+
unmarshalProjectSettings,
556+
)
514557
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export type {
3333
GetDomainLastStatusRequest,
3434
GetDomainRequest,
3535
GetEmailRequest,
36+
GetProjectSettingsRequest,
3637
GetStatisticsRequest,
3738
GetWebhookRequest,
3839
ListDomainsRequest,
@@ -46,9 +47,14 @@ export type {
4647
ListWebhooksRequest,
4748
ListWebhooksRequestOrderBy,
4849
ListWebhooksResponse,
50+
ProjectSettings,
51+
ProjectSettingsPeriodicReport,
52+
ProjectSettingsPeriodicReportFrequency,
4953
RevokeDomainRequest,
5054
Statistics,
5155
UpdateDomainRequest,
56+
UpdateProjectSettingsRequest,
57+
UpdateProjectSettingsRequestUpdatePeriodicReport,
5258
UpdateWebhookRequest,
5359
Webhook,
5460
WebhookEvent,

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ import type {
2929
ListEmailsResponse,
3030
ListWebhookEventsResponse,
3131
ListWebhooksResponse,
32+
ProjectSettings,
33+
ProjectSettingsPeriodicReport,
3234
Statistics,
3335
UpdateDomainRequest,
36+
UpdateProjectSettingsRequest,
37+
UpdateProjectSettingsRequestUpdatePeriodicReport,
3438
UpdateWebhookRequest,
3539
Webhook,
3640
WebhookEvent,
@@ -354,6 +358,37 @@ export const unmarshalListWebhooksResponse = (
354358
} as ListWebhooksResponse
355359
}
356360

361+
const unmarshalProjectSettingsPeriodicReport = (
362+
data: unknown,
363+
): ProjectSettingsPeriodicReport => {
364+
if (!isJSONObject(data)) {
365+
throw new TypeError(
366+
`Unmarshalling the type 'ProjectSettingsPeriodicReport' failed as data isn't a dictionary.`,
367+
)
368+
}
369+
370+
return {
371+
enabled: data.enabled,
372+
frequency: data.frequency,
373+
sendingDay: data.sending_day,
374+
sendingHour: data.sending_hour,
375+
} as ProjectSettingsPeriodicReport
376+
}
377+
378+
export const unmarshalProjectSettings = (data: unknown): ProjectSettings => {
379+
if (!isJSONObject(data)) {
380+
throw new TypeError(
381+
`Unmarshalling the type 'ProjectSettings' failed as data isn't a dictionary.`,
382+
)
383+
}
384+
385+
return {
386+
periodicReport: data.periodic_report
387+
? unmarshalProjectSettingsPeriodicReport(data.periodic_report)
388+
: undefined,
389+
} as ProjectSettings
390+
}
391+
357392
export const unmarshalStatistics = (data: unknown): Statistics => {
358393
if (!isJSONObject(data)) {
359394
throw new TypeError(
@@ -461,6 +496,29 @@ export const marshalUpdateDomainRequest = (
461496
autoconfig: request.autoconfig,
462497
})
463498

499+
const marshalUpdateProjectSettingsRequestUpdatePeriodicReport = (
500+
request: UpdateProjectSettingsRequestUpdatePeriodicReport,
501+
defaults: DefaultValues,
502+
): Record<string, unknown> => ({
503+
enabled: request.enabled,
504+
frequency: request.frequency,
505+
sending_day: request.sendingDay,
506+
sending_hour: request.sendingHour,
507+
})
508+
509+
export const marshalUpdateProjectSettingsRequest = (
510+
request: UpdateProjectSettingsRequest,
511+
defaults: DefaultValues,
512+
): Record<string, unknown> => ({
513+
periodic_report:
514+
request.periodicReport !== undefined
515+
? marshalUpdateProjectSettingsRequestUpdatePeriodicReport(
516+
request.periodicReport,
517+
defaults,
518+
)
519+
: undefined,
520+
})
521+
464522
export const marshalUpdateWebhookRequest = (
465523
request: UpdateWebhookRequest,
466524
defaults: DefaultValues,

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ export type ListWebhookEventsRequestOrderBy =
6565

6666
export type ListWebhooksRequestOrderBy = 'created_at_desc' | 'created_at_asc'
6767

68+
export type ProjectSettingsPeriodicReportFrequency =
69+
| 'unknown_frequency'
70+
| 'monthly'
71+
| 'weekly'
72+
| 'daily'
73+
6874
export type WebhookEventStatus =
6975
| 'unknown_status'
7076
| 'sending'
@@ -308,6 +314,34 @@ export interface Webhook {
308314
updatedAt?: Date
309315
}
310316

317+
export interface ProjectSettingsPeriodicReport {
318+
/** Enable or disable periodic report notifications. */
319+
enabled: boolean
320+
/** At which frequency you receive periodic report notifications. */
321+
frequency: ProjectSettingsPeriodicReportFrequency
322+
/** At which hour you receive periodic report notifications. */
323+
sendingHour: number
324+
/**
325+
* On which day you receive periodic report notifications (1-7 weekly, 1-28
326+
* monthly).
327+
*/
328+
sendingDay: number
329+
}
330+
331+
export interface UpdateProjectSettingsRequestUpdatePeriodicReport {
332+
/** (Optional) Enable or disable periodic report notifications. */
333+
enabled?: boolean
334+
/** (Optional) At which frequency you receive periodic report notifications. */
335+
frequency?: ProjectSettingsPeriodicReportFrequency
336+
/** (Optional) At which hour you receive periodic report notifications. */
337+
sendingHour?: number
338+
/**
339+
* (Optional) On which day you receive periodic report notifications (1-7
340+
* weekly, 1-28 monthly).
341+
*/
342+
sendingDay?: number
343+
}
344+
311345
export type CancelEmailRequest = {
312346
/**
313347
* Region to target. If none is passed will use default region from the
@@ -450,6 +484,16 @@ export type GetEmailRequest = {
450484
emailId: string
451485
}
452486

487+
export type GetProjectSettingsRequest = {
488+
/**
489+
* Region to target. If none is passed will use default region from the
490+
* config.
491+
*/
492+
region?: Region
493+
/** ID of the project. */
494+
projectId?: string
495+
}
496+
453497
export type GetStatisticsRequest = {
454498
/**
455499
* Region to target. If none is passed will use default region from the
@@ -613,6 +657,11 @@ export interface ListWebhooksResponse {
613657
webhooks: Webhook[]
614658
}
615659

660+
export interface ProjectSettings {
661+
/** Information about your periodic report. */
662+
periodicReport?: ProjectSettingsPeriodicReport
663+
}
664+
616665
export type RevokeDomainRequest = {
617666
/**
618667
* Region to target. If none is passed will use default region from the
@@ -668,6 +717,18 @@ export type UpdateDomainRequest = {
668717
autoconfig?: boolean
669718
}
670719

720+
export type UpdateProjectSettingsRequest = {
721+
/**
722+
* Region to target. If none is passed will use default region from the
723+
* config.
724+
*/
725+
region?: Region
726+
/** ID of the project. */
727+
projectId?: string
728+
/** Periodic report update details - all fields are optional. */
729+
periodicReport?: UpdateProjectSettingsRequestUpdatePeriodicReport
730+
}
731+
671732
export type UpdateWebhookRequest = {
672733
/**
673734
* 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
@@ -96,6 +96,17 @@ export const ListWebhooksRequest = {
9696
},
9797
}
9898

99+
export const UpdateProjectSettingsRequestUpdatePeriodicReport = {
100+
sendingDay: {
101+
greaterThanOrEqual: 1,
102+
lessThanOrEqual: 28,
103+
},
104+
sendingHour: {
105+
greaterThanOrEqual: 0,
106+
lessThanOrEqual: 23,
107+
},
108+
}
109+
99110
export const UpdateWebhookRequest = {
100111
name: {
101112
maxLength: 127,

0 commit comments

Comments
 (0)