diff --git a/packages/clients/src/api/tem/v1alpha1/api.gen.ts b/packages/clients/src/api/tem/v1alpha1/api.gen.ts index be0771e62..75b2c3b31 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, unmarshalCreateEmailResponse, unmarshalDomain, + unmarshalDomainLastStatus, unmarshalEmail, unmarshalListDomainsResponse, unmarshalListEmailsResponse, @@ -24,11 +25,13 @@ import { } from './marshalling.gen' import type { CancelEmailRequest, + CheckDomainLastStatusRequest, CheckDomainRequest, CreateDomainRequest, CreateEmailRequest, CreateEmailResponse, Domain, + DomainLastStatus, Email, GetDomainRequest, GetEmailRequest, @@ -339,4 +342,29 @@ export class API extends ParentAPI { }, unmarshalDomain, ) + + /** + * Display SPF and DKIM records status and potential errors. Display SPF and + * DKIM records status and potential errors, including the found records to + * make debugging easier. + * + * @param request - The request {@link CheckDomainLastStatusRequest} + * @returns A Promise of DomainLastStatus + */ + checkDomainLastStatus = (request: Readonly) => + this.client.fetch( + { + body: '{}', + headers: jsonContentHeaders, + method: 'POST', + path: `/transactional-email/v1alpha1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/domains/${validatePathParam( + 'domainId', + request.domainId, + )}/verification`, + }, + unmarshalDomainLastStatus, + ) } diff --git a/packages/clients/src/api/tem/v1alpha1/index.gen.ts b/packages/clients/src/api/tem/v1alpha1/index.gen.ts index 5c9dfd7cc..97fc42a1e 100644 --- a/packages/clients/src/api/tem/v1alpha1/index.gen.ts +++ b/packages/clients/src/api/tem/v1alpha1/index.gen.ts @@ -4,6 +4,7 @@ export { API } from './api.gen' export * from './content.gen' export type { CancelEmailRequest, + CheckDomainLastStatusRequest, CheckDomainRequest, CreateDomainRequest, CreateEmailRequest, @@ -11,6 +12,10 @@ export type { CreateEmailRequestAttachment, CreateEmailResponse, Domain, + DomainLastStatus, + DomainLastStatusDkimRecord, + DomainLastStatusRecordStatus, + DomainLastStatusSpfRecord, DomainStatistics, DomainStatus, Email, diff --git a/packages/clients/src/api/tem/v1alpha1/marshalling.gen.ts b/packages/clients/src/api/tem/v1alpha1/marshalling.gen.ts index cb623fdbd..4f9faaf19 100644 --- a/packages/clients/src/api/tem/v1alpha1/marshalling.gen.ts +++ b/packages/clients/src/api/tem/v1alpha1/marshalling.gen.ts @@ -13,6 +13,9 @@ import type { CreateEmailRequestAttachment, CreateEmailResponse, Domain, + DomainLastStatus, + DomainLastStatusDkimRecord, + DomainLastStatusSpfRecord, DomainStatistics, Email, EmailTry, @@ -78,6 +81,34 @@ export const unmarshalDomain = (data: unknown) => { } as Domain } +const unmarshalDomainLastStatusDkimRecord = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'DomainLastStatusDkimRecord' failed as data isn't a dictionary.`, + ) + } + + return { + error: data.error, + lastValidAt: unmarshalDate(data.last_valid_at), + status: data.status, + } as DomainLastStatusDkimRecord +} + +const unmarshalDomainLastStatusSpfRecord = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'DomainLastStatusSpfRecord' failed as data isn't a dictionary.`, + ) + } + + return { + error: data.error, + lastValidAt: unmarshalDate(data.last_valid_at), + status: data.status, + } as DomainLastStatusSpfRecord +} + export const unmarshalEmail = (data: unknown) => { if (!isJSONObject(data)) { throw new TypeError( @@ -115,6 +146,25 @@ export const unmarshalCreateEmailResponse = (data: unknown) => { } as CreateEmailResponse } +export const unmarshalDomainLastStatus = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'DomainLastStatus' failed as data isn't a dictionary.`, + ) + } + + return { + dkimRecord: data.dkim_record + ? unmarshalDomainLastStatusDkimRecord(data.dkim_record) + : undefined, + domainId: data.domain_id, + domainName: data.domain_name, + spfRecord: data.spf_record + ? unmarshalDomainLastStatusSpfRecord(data.spf_record) + : undefined, + } as DomainLastStatus +} + export const unmarshalListDomainsResponse = (data: unknown) => { if (!isJSONObject(data)) { throw new TypeError( diff --git a/packages/clients/src/api/tem/v1alpha1/types.gen.ts b/packages/clients/src/api/tem/v1alpha1/types.gen.ts index aedab5703..314452d76 100644 --- a/packages/clients/src/api/tem/v1alpha1/types.gen.ts +++ b/packages/clients/src/api/tem/v1alpha1/types.gen.ts @@ -2,6 +2,12 @@ // If you have any remark or suggestion do not hesitate to open an issue. import type { Region } from '../../../bridge' +export type DomainLastStatusRecordStatus = + | 'unknown_record_status' + | 'valid' + | 'invalid' + | 'not_found' + export type DomainStatus = | 'unknown' | 'checked' @@ -79,7 +85,7 @@ export interface Domain { lastValidAt?: Date /** Date and time of the domain's deletion. */ revokedAt?: Date - /** Error message returned if the last check failed. */ + /** @deprecated Error message returned if the last check failed. */ lastError?: string /** Snippet of the SPF record to register in the DNS zone. */ spfConfig: string @@ -90,6 +96,38 @@ export interface Domain { region: Region } +/** Domain last status. */ +export interface DomainLastStatus { + /** The id of the domain. */ + domainId: string + /** The domain name (example.com). */ + domainName: string + /** The SPF record verification data. */ + spfRecord?: DomainLastStatusSpfRecord + /** The DKIM record verification data. */ + dkimRecord?: DomainLastStatusDkimRecord +} + +/** Domain last status. dkim record. */ +export interface DomainLastStatusDkimRecord { + /** Status of the DKIM record's configurartion. */ + status: DomainLastStatusRecordStatus + /** Time and date the DKIM record was last valid. */ + lastValidAt?: Date + /** An error text displays in case the record is not valid. */ + error?: string +} + +/** Domain last status. spf record. */ +export interface DomainLastStatusSpfRecord { + /** Status of the SPF record's configurartion. */ + status: DomainLastStatusRecordStatus + /** Time and date the SPF record was last valid. */ + lastValidAt?: Date + /** An error text displays in case the record is not valid. */ + error?: string +} + export interface DomainStatistics { totalCount: number sentCount: number @@ -107,7 +145,7 @@ export interface Email { projectId: string /** Email address of the sender. */ mailFrom: string - /** @deprecated (Deprecated) Email address of the recipient. */ + /** @deprecated Email address of the recipient. */ rcptTo?: string /** Email address of the recipient. */ mailRcpt: string @@ -251,10 +289,7 @@ export type ListEmailsRequest = { until?: Date /** (Optional) List emails sent with this sender's email address. */ mailFrom?: string - /** - * @deprecated (Deprecated) List emails sent to this recipient's email - * address. - */ + /** @deprecated List emails sent to this recipient's email address. */ mailTo?: string /** (Optional) List emails sent to this recipient's email address. */ mailRcpt?: string @@ -358,3 +393,13 @@ export type CheckDomainRequest = { /** ID of the domain to check. */ domainId: string } + +export type CheckDomainLastStatusRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** ID of the domain to delete. */ + domainId: string +}