From 773f36c17b4cbbda599bf56921a9c4bcc960fe00 Mon Sep 17 00:00:00 2001 From: Scaleway Bot Date: Wed, 18 Sep 2024 16:30:42 +0200 Subject: [PATCH] feat(tem): add project settings endpoint (#1435) --- .../clients/src/api/tem/v1alpha1/api.gen.ts | 43 +++++++++++++ .../clients/src/api/tem/v1alpha1/index.gen.ts | 6 ++ .../src/api/tem/v1alpha1/marshalling.gen.ts | 58 ++++++++++++++++++ .../clients/src/api/tem/v1alpha1/types.gen.ts | 61 +++++++++++++++++++ .../api/tem/v1alpha1/validation-rules.gen.ts | 11 ++++ 5 files changed, 179 insertions(+) diff --git a/packages/clients/src/api/tem/v1alpha1/api.gen.ts b/packages/clients/src/api/tem/v1alpha1/api.gen.ts index 6bda73e87..036a66e9d 100644 --- a/packages/clients/src/api/tem/v1alpha1/api.gen.ts +++ b/packages/clients/src/api/tem/v1alpha1/api.gen.ts @@ -17,6 +17,7 @@ import { marshalCreateEmailRequest, marshalCreateWebhookRequest, marshalUpdateDomainRequest, + marshalUpdateProjectSettingsRequest, marshalUpdateWebhookRequest, unmarshalCreateEmailResponse, unmarshalDomain, @@ -26,6 +27,7 @@ import { unmarshalListEmailsResponse, unmarshalListWebhookEventsResponse, unmarshalListWebhooksResponse, + unmarshalProjectSettings, unmarshalStatistics, unmarshalWebhook, } from './marshalling.gen' @@ -43,6 +45,7 @@ import type { GetDomainLastStatusRequest, GetDomainRequest, GetEmailRequest, + GetProjectSettingsRequest, GetStatisticsRequest, GetWebhookRequest, ListDomainsRequest, @@ -53,9 +56,11 @@ import type { ListWebhookEventsResponse, ListWebhooksRequest, ListWebhooksResponse, + ProjectSettings, RevokeDomainRequest, Statistics, UpdateDomainRequest, + UpdateProjectSettingsRequest, UpdateWebhookRequest, Webhook, } from './types.gen' @@ -511,4 +516,42 @@ export class API extends ParentAPI { */ listWebhookEvents = (request: Readonly) => enrichForPagination('webhookEvents', this.pageOfListWebhookEvents, request) + + /** + * List project settings. Retrieve the project settings including periodic + * reports. + * + * @param request - The request {@link GetProjectSettingsRequest} + * @returns A Promise of ProjectSettings + */ + getProjectSettings = (request: Readonly = {}) => + this.client.fetch( + { + method: 'GET', + path: `/transactional-email/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/project/${validatePathParam('projectId', request.projectId ?? this.client.settings.defaultProjectId)}/settings`, + }, + unmarshalProjectSettings, + ) + + /** + * Update project settings. Update the project settings including periodic + * reports. + * + * @param request - The request {@link UpdateProjectSettingsRequest} + * @returns A Promise of ProjectSettings + */ + updateProjectSettings = ( + request: Readonly = {}, + ) => + this.client.fetch( + { + body: JSON.stringify( + marshalUpdateProjectSettingsRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PATCH', + path: `/transactional-email/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/project/${validatePathParam('projectId', request.projectId ?? this.client.settings.defaultProjectId)}/settings`, + }, + unmarshalProjectSettings, + ) } diff --git a/packages/clients/src/api/tem/v1alpha1/index.gen.ts b/packages/clients/src/api/tem/v1alpha1/index.gen.ts index 25868146e..3c8406a62 100644 --- a/packages/clients/src/api/tem/v1alpha1/index.gen.ts +++ b/packages/clients/src/api/tem/v1alpha1/index.gen.ts @@ -33,6 +33,7 @@ export type { GetDomainLastStatusRequest, GetDomainRequest, GetEmailRequest, + GetProjectSettingsRequest, GetStatisticsRequest, GetWebhookRequest, ListDomainsRequest, @@ -46,9 +47,14 @@ export type { ListWebhooksRequest, ListWebhooksRequestOrderBy, ListWebhooksResponse, + ProjectSettings, + ProjectSettingsPeriodicReport, + ProjectSettingsPeriodicReportFrequency, RevokeDomainRequest, Statistics, UpdateDomainRequest, + UpdateProjectSettingsRequest, + UpdateProjectSettingsRequestUpdatePeriodicReport, UpdateWebhookRequest, Webhook, WebhookEvent, diff --git a/packages/clients/src/api/tem/v1alpha1/marshalling.gen.ts b/packages/clients/src/api/tem/v1alpha1/marshalling.gen.ts index 915f27137..488aa74a9 100644 --- a/packages/clients/src/api/tem/v1alpha1/marshalling.gen.ts +++ b/packages/clients/src/api/tem/v1alpha1/marshalling.gen.ts @@ -29,8 +29,12 @@ import type { ListEmailsResponse, ListWebhookEventsResponse, ListWebhooksResponse, + ProjectSettings, + ProjectSettingsPeriodicReport, Statistics, UpdateDomainRequest, + UpdateProjectSettingsRequest, + UpdateProjectSettingsRequestUpdatePeriodicReport, UpdateWebhookRequest, Webhook, WebhookEvent, @@ -354,6 +358,37 @@ export const unmarshalListWebhooksResponse = ( } as ListWebhooksResponse } +const unmarshalProjectSettingsPeriodicReport = ( + data: unknown, +): ProjectSettingsPeriodicReport => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ProjectSettingsPeriodicReport' failed as data isn't a dictionary.`, + ) + } + + return { + enabled: data.enabled, + frequency: data.frequency, + sendingDay: data.sending_day, + sendingHour: data.sending_hour, + } as ProjectSettingsPeriodicReport +} + +export const unmarshalProjectSettings = (data: unknown): ProjectSettings => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ProjectSettings' failed as data isn't a dictionary.`, + ) + } + + return { + periodicReport: data.periodic_report + ? unmarshalProjectSettingsPeriodicReport(data.periodic_report) + : undefined, + } as ProjectSettings +} + export const unmarshalStatistics = (data: unknown): Statistics => { if (!isJSONObject(data)) { throw new TypeError( @@ -461,6 +496,29 @@ export const marshalUpdateDomainRequest = ( autoconfig: request.autoconfig, }) +const marshalUpdateProjectSettingsRequestUpdatePeriodicReport = ( + request: UpdateProjectSettingsRequestUpdatePeriodicReport, + defaults: DefaultValues, +): Record => ({ + enabled: request.enabled, + frequency: request.frequency, + sending_day: request.sendingDay, + sending_hour: request.sendingHour, +}) + +export const marshalUpdateProjectSettingsRequest = ( + request: UpdateProjectSettingsRequest, + defaults: DefaultValues, +): Record => ({ + periodic_report: + request.periodicReport !== undefined + ? marshalUpdateProjectSettingsRequestUpdatePeriodicReport( + request.periodicReport, + defaults, + ) + : undefined, +}) + export const marshalUpdateWebhookRequest = ( request: UpdateWebhookRequest, defaults: DefaultValues, diff --git a/packages/clients/src/api/tem/v1alpha1/types.gen.ts b/packages/clients/src/api/tem/v1alpha1/types.gen.ts index acdbe8bcd..620e39940 100644 --- a/packages/clients/src/api/tem/v1alpha1/types.gen.ts +++ b/packages/clients/src/api/tem/v1alpha1/types.gen.ts @@ -65,6 +65,12 @@ export type ListWebhookEventsRequestOrderBy = export type ListWebhooksRequestOrderBy = 'created_at_desc' | 'created_at_asc' +export type ProjectSettingsPeriodicReportFrequency = + | 'unknown_frequency' + | 'monthly' + | 'weekly' + | 'daily' + export type WebhookEventStatus = | 'unknown_status' | 'sending' @@ -308,6 +314,34 @@ export interface Webhook { updatedAt?: Date } +export interface ProjectSettingsPeriodicReport { + /** Enable or disable periodic report notifications. */ + enabled: boolean + /** At which frequency you receive periodic report notifications. */ + frequency: ProjectSettingsPeriodicReportFrequency + /** At which hour you receive periodic report notifications. */ + sendingHour: number + /** + * On which day you receive periodic report notifications (1-7 weekly, 1-28 + * monthly). + */ + sendingDay: number +} + +export interface UpdateProjectSettingsRequestUpdatePeriodicReport { + /** (Optional) Enable or disable periodic report notifications. */ + enabled?: boolean + /** (Optional) At which frequency you receive periodic report notifications. */ + frequency?: ProjectSettingsPeriodicReportFrequency + /** (Optional) At which hour you receive periodic report notifications. */ + sendingHour?: number + /** + * (Optional) On which day you receive periodic report notifications (1-7 + * weekly, 1-28 monthly). + */ + sendingDay?: number +} + export type CancelEmailRequest = { /** * Region to target. If none is passed will use default region from the @@ -450,6 +484,16 @@ export type GetEmailRequest = { emailId: string } +export type GetProjectSettingsRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** ID of the project. */ + projectId?: string +} + export type GetStatisticsRequest = { /** * Region to target. If none is passed will use default region from the @@ -613,6 +657,11 @@ export interface ListWebhooksResponse { webhooks: Webhook[] } +export interface ProjectSettings { + /** Information about your periodic report. */ + periodicReport?: ProjectSettingsPeriodicReport +} + export type RevokeDomainRequest = { /** * Region to target. If none is passed will use default region from the @@ -668,6 +717,18 @@ export type UpdateDomainRequest = { autoconfig?: boolean } +export type UpdateProjectSettingsRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** ID of the project. */ + projectId?: string + /** Periodic report update details - all fields are optional. */ + periodicReport?: UpdateProjectSettingsRequestUpdatePeriodicReport +} + export type UpdateWebhookRequest = { /** * Region to target. If none is passed will use default region from the diff --git a/packages/clients/src/api/tem/v1alpha1/validation-rules.gen.ts b/packages/clients/src/api/tem/v1alpha1/validation-rules.gen.ts index ee8a5bb66..14b12e0ec 100644 --- a/packages/clients/src/api/tem/v1alpha1/validation-rules.gen.ts +++ b/packages/clients/src/api/tem/v1alpha1/validation-rules.gen.ts @@ -96,6 +96,17 @@ export const ListWebhooksRequest = { }, } +export const UpdateProjectSettingsRequestUpdatePeriodicReport = { + sendingDay: { + greaterThanOrEqual: 1, + lessThanOrEqual: 28, + }, + sendingHour: { + greaterThanOrEqual: 0, + lessThanOrEqual: 23, + }, +} + export const UpdateWebhookRequest = { name: { maxLength: 127,