From 108883f6a3fb72c029c01c8d9c54e88844093c90 Mon Sep 17 00:00:00 2001 From: Scaleway Bot Date: Mon, 13 Jan 2025 18:54:16 +0100 Subject: [PATCH] feat(tem): generate blocklist sdk (#1707) --- .../clients/src/api/tem/v1alpha1/api.gen.ts | 70 +++++++++++++ .../clients/src/api/tem/v1alpha1/index.gen.ts | 8 ++ .../src/api/tem/v1alpha1/marshalling.gen.ts | 63 ++++++++++++ .../clients/src/api/tem/v1alpha1/types.gen.ts | 98 +++++++++++++++++++ .../api/tem/v1alpha1/validation-rules.gen.ts | 16 +++ 5 files changed, 255 insertions(+) diff --git a/packages/clients/src/api/tem/v1alpha1/api.gen.ts b/packages/clients/src/api/tem/v1alpha1/api.gen.ts index 036a66e9d..c07ef0526 100644 --- a/packages/clients/src/api/tem/v1alpha1/api.gen.ts +++ b/packages/clients/src/api/tem/v1alpha1/api.gen.ts @@ -13,16 +13,19 @@ import { EMAIL_TRANSIENT_STATUSES, } from './content.gen' import { + marshalBulkCreateBlocklistsRequest, marshalCreateDomainRequest, marshalCreateEmailRequest, marshalCreateWebhookRequest, marshalUpdateDomainRequest, marshalUpdateProjectSettingsRequest, marshalUpdateWebhookRequest, + unmarshalBulkCreateBlocklistsResponse, unmarshalCreateEmailResponse, unmarshalDomain, unmarshalDomainLastStatus, unmarshalEmail, + unmarshalListBlocklistsResponse, unmarshalListDomainsResponse, unmarshalListEmailsResponse, unmarshalListWebhookEventsResponse, @@ -32,12 +35,15 @@ import { unmarshalWebhook, } from './marshalling.gen' import type { + BulkCreateBlocklistsRequest, + BulkCreateBlocklistsResponse, CancelEmailRequest, CheckDomainRequest, CreateDomainRequest, CreateEmailRequest, CreateEmailResponse, CreateWebhookRequest, + DeleteBlocklistRequest, DeleteWebhookRequest, Domain, DomainLastStatus, @@ -48,6 +54,8 @@ import type { GetProjectSettingsRequest, GetStatisticsRequest, GetWebhookRequest, + ListBlocklistsRequest, + ListBlocklistsResponse, ListDomainsRequest, ListDomainsResponse, ListEmailsRequest, @@ -554,4 +562,66 @@ export class API extends ParentAPI { }, unmarshalProjectSettings, ) + + protected pageOfListBlocklists = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/transactional-email/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/blocklists`, + urlParams: urlParams( + ['custom', request.custom], + ['domain_id', request.domainId], + ['email', request.email], + ['order_by', request.orderBy], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ['type', request.type], + ), + }, + unmarshalListBlocklistsResponse, + ) + + /** + * List blocklists. Retrieve the list of blocklists. + * + * @param request - The request {@link ListBlocklistsRequest} + * @returns A Promise of ListBlocklistsResponse + */ + listBlocklists = (request: Readonly) => + enrichForPagination('blocklists', this.pageOfListBlocklists, request) + + /** + * Bulk create blocklists. Create multiple blocklists in a specific Project or + * Organization using the `region` parameter. + * + * @param request - The request {@link BulkCreateBlocklistsRequest} + * @returns A Promise of BulkCreateBlocklistsResponse + */ + bulkCreateBlocklists = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalBulkCreateBlocklistsRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/transactional-email/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/blocklists`, + }, + unmarshalBulkCreateBlocklistsResponse, + ) + + /** + * Delete a blocklist. You must specify the blocklist you want to delete by + * the `region` and `blocklist_id`. + * + * @param request - The request {@link DeleteBlocklistRequest} + */ + deleteBlocklist = (request: Readonly) => + this.client.fetch({ + method: 'DELETE', + path: `/transactional-email/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/blocklists/${validatePathParam('blocklistId', request.blocklistId)}`, + }) } diff --git a/packages/clients/src/api/tem/v1alpha1/index.gen.ts b/packages/clients/src/api/tem/v1alpha1/index.gen.ts index 7a6dcaeb0..b041f760d 100644 --- a/packages/clients/src/api/tem/v1alpha1/index.gen.ts +++ b/packages/clients/src/api/tem/v1alpha1/index.gen.ts @@ -3,6 +3,10 @@ export { API } from './api.gen' export * from './content.gen' export type { + Blocklist, + BlocklistType, + BulkCreateBlocklistsRequest, + BulkCreateBlocklistsResponse, CancelEmailRequest, CheckDomainRequest, CreateDomainRequest, @@ -12,6 +16,7 @@ export type { CreateEmailRequestHeader, CreateEmailResponse, CreateWebhookRequest, + DeleteBlocklistRequest, DeleteWebhookRequest, Domain, DomainLastStatus, @@ -38,6 +43,9 @@ export type { GetProjectSettingsRequest, GetStatisticsRequest, GetWebhookRequest, + ListBlocklistsRequest, + ListBlocklistsRequestOrderBy, + ListBlocklistsResponse, ListDomainsRequest, ListDomainsResponse, ListEmailsRequest, diff --git a/packages/clients/src/api/tem/v1alpha1/marshalling.gen.ts b/packages/clients/src/api/tem/v1alpha1/marshalling.gen.ts index 52abf4dcb..8e1d76bd6 100644 --- a/packages/clients/src/api/tem/v1alpha1/marshalling.gen.ts +++ b/packages/clients/src/api/tem/v1alpha1/marshalling.gen.ts @@ -7,6 +7,9 @@ import { } from '../../../bridge' import type { DefaultValues } from '../../../bridge' import type { + Blocklist, + BulkCreateBlocklistsRequest, + BulkCreateBlocklistsResponse, CreateDomainRequest, CreateEmailRequest, CreateEmailRequestAddress, @@ -26,6 +29,7 @@ import type { DomainStatistics, Email, EmailTry, + ListBlocklistsResponse, ListDomainsResponse, ListEmailsResponse, ListWebhookEventsResponse, @@ -190,6 +194,40 @@ export const unmarshalWebhook = (data: unknown): Webhook => { } as Webhook } +const unmarshalBlocklist = (data: unknown): Blocklist => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Blocklist' failed as data isn't a dictionary.`, + ) + } + + return { + createdAt: unmarshalDate(data.created_at), + custom: data.custom, + domainId: data.domain_id, + email: data.email, + endsAt: unmarshalDate(data.ends_at), + id: data.id, + reason: data.reason, + type: data.type, + updatedAt: unmarshalDate(data.updated_at), + } as Blocklist +} + +export const unmarshalBulkCreateBlocklistsResponse = ( + data: unknown, +): BulkCreateBlocklistsResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'BulkCreateBlocklistsResponse' failed as data isn't a dictionary.`, + ) + } + + return { + blocklists: unmarshalArrayOfObject(data.blocklists, unmarshalBlocklist), + } as BulkCreateBlocklistsResponse +} + export const unmarshalCreateEmailResponse = ( data: unknown, ): CreateEmailResponse => { @@ -293,6 +331,21 @@ export const unmarshalDomainLastStatus = (data: unknown): DomainLastStatus => { } as DomainLastStatus } +export const unmarshalListBlocklistsResponse = ( + data: unknown, +): ListBlocklistsResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListBlocklistsResponse' failed as data isn't a dictionary.`, + ) + } + + return { + blocklists: unmarshalArrayOfObject(data.blocklists, unmarshalBlocklist), + totalCount: data.total_count, + } as ListBlocklistsResponse +} + export const unmarshalListDomainsResponse = ( data: unknown, ): ListDomainsResponse => { @@ -426,6 +479,16 @@ export const unmarshalStatistics = (data: unknown): Statistics => { } as Statistics } +export const marshalBulkCreateBlocklistsRequest = ( + request: BulkCreateBlocklistsRequest, + defaults: DefaultValues, +): Record => ({ + domain_id: request.domainId, + emails: request.emails, + reason: request.reason, + type: request.type, +}) + export const marshalCreateDomainRequest = ( request: CreateDomainRequest, 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 9ecc58a5b..792258017 100644 --- a/packages/clients/src/api/tem/v1alpha1/types.gen.ts +++ b/packages/clients/src/api/tem/v1alpha1/types.gen.ts @@ -2,6 +2,11 @@ // If you have any remark or suggestion do not hesitate to open an issue. import type { Region } from '../../../bridge' +export type BlocklistType = + | 'unknown_type' + | 'mailbox_full' + | 'mailbox_not_found' + export type DomainLastStatusAutoconfigStateReason = | 'unknown_reason' | 'permission_denied' @@ -50,6 +55,12 @@ export type EmailStatus = | 'failed' | 'canceled' +export type ListBlocklistsRequestOrderBy = + | 'created_at_desc' + | 'created_at_asc' + | 'ends_at_desc' + | 'ends_at_asc' + export type ListEmailsRequestOrderBy = | 'created_at_desc' | 'created_at_asc' @@ -146,6 +157,30 @@ export interface DomainStatistics { canceledCount: number } +export interface Blocklist { + /** ID of the blocklist. */ + id: string + /** Domain ID linked to the blocklist. */ + domainId: string + /** Date and time of the blocklist creation. */ + createdAt?: Date + /** Date and time of the blocklist's last update. */ + updatedAt?: Date + /** Date and time when the blocklist ends. Empty if the blocklist has no end. */ + endsAt?: Date + /** Email blocked by the blocklist. */ + email: string + /** Type of block for this email. */ + type: BlocklistType + /** Reason to block this email. */ + reason: string + /** + * True if this blocklist was created manually. False for an automatic + * Transactional Email blocklist. + */ + custom: boolean +} + export interface CreateEmailRequestAddress { /** Email address. */ email: string @@ -358,6 +393,27 @@ export interface UpdateProjectSettingsRequestUpdatePeriodicReport { sendingDay?: number } +export type BulkCreateBlocklistsRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** Domain ID linked to the blocklist. */ + domainId: string + /** Email blocked by the blocklist. */ + emails?: string[] + /** Type of blocklist. */ + type?: BlocklistType + /** Reason to block the email. */ + reason?: string +} + +export interface BulkCreateBlocklistsResponse { + /** List of blocklist created. */ + blocklists: Blocklist[] +} + export type CancelEmailRequest = { /** * Region to target. If none is passed will use default region from the @@ -447,6 +503,16 @@ export type CreateWebhookRequest = { snsArn: string } +export type DeleteBlocklistRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** ID of the blocklist to delete. */ + blocklistId: string +} + export type DeleteWebhookRequest = { /** * Region to target. If none is passed will use default region from the @@ -543,6 +609,38 @@ export type GetWebhookRequest = { webhookId: string } +export type ListBlocklistsRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** (Optional) List blocklist corresponding to specific criteria. */ + orderBy?: ListBlocklistsRequestOrderBy + /** (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) Filter by a domain ID. */ + domainId: string + /** (Optional) Filter by an email address. */ + email?: string + /** (Optional) Filter by a blocklist type. */ + type?: BlocklistType + /** + * (Optional) Filter by custom blocklist (true) or automatic Transactional + * Email blocklist (false). + */ + custom?: boolean +} + +export interface ListBlocklistsResponse { + /** Number of blocklists matching the requested criteria. */ + totalCount: number + /** Single page of blocklists matching the requested criteria. */ + blocklists: Blocklist[] +} + export type ListDomainsRequest = { /** * 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 14b12e0ec..e54e23186 100644 --- a/packages/clients/src/api/tem/v1alpha1/validation-rules.gen.ts +++ b/packages/clients/src/api/tem/v1alpha1/validation-rules.gen.ts @@ -1,6 +1,12 @@ // This file was automatically generated. DO NOT EDIT. // If you have any remark or suggestion do not hesitate to open an issue. +export const BulkCreateBlocklistsRequest = { + reason: { + maxLength: 200, + }, +} + export const CreateDomainRequest = { domainName: { maxLength: 255, @@ -49,6 +55,16 @@ export const CreateWebhookRequest = { }, } +export const ListBlocklistsRequest = { + page: { + greaterThan: 0, + }, + pageSize: { + greaterThanOrEqual: 1, + lessThanOrEqual: 100, + }, +} + export const ListDomainsRequest = { page: { greaterThan: 0,