diff --git a/packages/mailgun/src/models/v1/emails/request/enum.ts b/packages/mailgun/src/models/v1/emails/request/enum.ts new file mode 100644 index 0000000..747f1d2 --- /dev/null +++ b/packages/mailgun/src/models/v1/emails/request/enum.ts @@ -0,0 +1,3 @@ +export type YesNoEnum = boolean | 'yes' | 'no'; + +export type YesNoHtmlonlyEnum = YesNoEnum | 'htmlonly'; diff --git a/packages/mailgun/src/models/v1/emails/request/helper.ts b/packages/mailgun/src/models/v1/emails/request/helper.ts new file mode 100644 index 0000000..4bd1994 --- /dev/null +++ b/packages/mailgun/src/models/v1/emails/request/helper.ts @@ -0,0 +1,17 @@ +import FormData = require('form-data'); + +export const appendFilteredPropertiesToFormData = ( + obj: Record, + prefix: string, + formData: FormData, +) => { + for (const [key, value] of Object.entries(obj)) { + if (key.startsWith(prefix) && value != null) { + if (value instanceof Date) { + formData.append(key, value.toUTCString()); + } else { + formData.append(key, String(value)); + } + } + } +}; diff --git a/packages/mailgun/src/models/v1/emails/request/override-properties/override-properties.transform.ts b/packages/mailgun/src/models/v1/emails/request/override-properties/override-properties.transform.ts new file mode 100644 index 0000000..6212153 --- /dev/null +++ b/packages/mailgun/src/models/v1/emails/request/override-properties/override-properties.transform.ts @@ -0,0 +1,57 @@ +import { OverrideProperties } from './override-properties'; +import FormData = require('form-data'); + +// eslint-disable-next-line valid-jsdoc +/** + * ** INTERNAL METHOD ** IT SHOULD NOT BE USED DIRECTLY BY SDK USERS AS IT CAN BE REMOVED OR MODIFIED WITHOUT NOTICE + */ +export const appendOverridePropertiesToFormData = (overrideProperties: OverrideProperties, formData: FormData) => { + if (overrideProperties['tag'] != null) { + formData.append('o:tag', overrideProperties['tag']); + } + if (overrideProperties['deliveryTimeOptimizePeriod'] != null) { + formData.append('o:deliverytime-optimize-period', `${overrideProperties['deliveryTimeOptimizePeriod']}h`); + } + if (overrideProperties['enableDkimSignature'] != null) { + formData.append('o:dkim', String(overrideProperties['enableDkimSignature'])); + } + if (overrideProperties['secondaryDkim'] != null) { + formData.append('o:secondary-dkim', overrideProperties['secondaryDkim']); + } + if (overrideProperties['secondaryDkimPublic'] != null) { + formData.append('o:secondary-dkim-public', overrideProperties['secondaryDkimPublic']); + } + if (overrideProperties['deliveryTime'] != null) { + formData.append('o:deliverytime', overrideProperties['deliveryTime']); + } + if (overrideProperties['timeZoneLocalize'] != null) { + formData.append('o:time-zone-localize', overrideProperties['timeZoneLocalize']); + } + if (overrideProperties['tracking'] != null) { + formData.append('o:tracking', String(overrideProperties['tracking'])); + } + if (overrideProperties['trackingClicks'] != null) { + formData.append('o:tracking-clicks', String(overrideProperties['trackingClicks'])); + } + if (overrideProperties['trackingOpens'] != null) { + formData.append('o:tracking-opens', String(overrideProperties['trackingOpens'])); + } + if (overrideProperties['trackingPixelLocationTop'] != null) { + formData.append('o:tracking-pixel-location-top', String(overrideProperties['trackingPixelLocationTop'])); + } + if (overrideProperties['sendingIp'] != null) { + formData.append('o:sending-ip', overrideProperties['sendingIp']); + } + if (overrideProperties['sendingIpPool'] != null) { + formData.append('o:sending-ip-pool', overrideProperties['sendingIpPool']); + } + if (overrideProperties['requireTls'] != null) { + formData.append('o:require-tls', String(overrideProperties['requireTls'])); + } + if (overrideProperties['skipVerification'] != null) { + formData.append('o:skip-verification', String(overrideProperties['skipVerification'])); + } + if (overrideProperties['isTestMode'] != null) { + formData.append('o:testmode', String(overrideProperties['isTestMode'])); + } +}; diff --git a/packages/mailgun/src/models/v1/emails/request/override-properties/override-properties.ts b/packages/mailgun/src/models/v1/emails/request/override-properties/override-properties.ts index ada5feb..43a5d48 100644 --- a/packages/mailgun/src/models/v1/emails/request/override-properties/override-properties.ts +++ b/packages/mailgun/src/models/v1/emails/request/override-properties/override-properties.ts @@ -1,10 +1,12 @@ +import { YesNoEnum, YesNoHtmlonlyEnum } from '../enum'; + export interface OverrideProperties { /** Tag string. See **Tagging** for more information */ tag?: string; /** Toggles Send Time Optimization (STO) on a per-message basis. String should be set to the number of hours in `[0-9]+h` format, with the minimum being `24h` and the maximum being `72h`. This value defines the time window in which Mailgun will run the optimization algorithm based on prior engagement data of a given recipient. See **Sending a Message with STO** for details. *Please note that STO is only available on certain plans. See www.mailgun.com/pricing for more info* */ - deliveryTimeOptimizePeriod?: string; + deliveryTimeOptimizePeriod?: number; /** Enables/disables DKIM signatures on a per-message basis. Pass `yes` or `no`, `true` or `false` */ - enableDkimSignature?: string; + enableDkimSignature?: YesNoEnum; /** Specify a second domain key to sign the email with. The value is formatted as `signing_domain/selector`, e.g. `example.com/s1`. This tells Mailgun to sign the message with the signing domain `example.com` using the selector `s1`. Note: the domain key specified must have been previously created and activated. */ secondaryDkim?: string; /** Specify an alias of the domain key specified in `o:secondary-dkim`. Also formatted as `public_signing_domain/selector`. `o:secondary-dkim` option must also be provided. Mailgun will sign the message with the provided key of the secondary DKIM, but use the public secondary DKIM name and selector. Note: We will perform a DNS check prior to signing the message to ensure the public keys matches the secondary DKIM. */ @@ -14,21 +16,21 @@ export interface OverrideProperties { /** Toggles Timezone Optimization (TZO) on a per message basis. String should be set to preferred delivery time in `HH:mm` or `hh:mmaa` format, where `HH:mm` is used for 24 hour format without AM/PM and hh:mmaa is used for 12 hour format with AM/PM. See **Sending a Message with TZO** for details. *Please note that TZO is only available on certain plans. See www.mailgun.com/pricing for more info* */ timeZoneLocalize?: string; /** Toggles click tracking on a per-message basis. Has higher priority than domain-level setting. Pass `yes` or `no`, `true` or `false`, or `htmlonly` if you only want links rewritten in the HTML part of the message */ - trackingClicks?: string; + trackingClicks?: YesNoHtmlonlyEnum; /** Toggles both click and open tracking on a per-message basis, see **Tracking Messages** for details. Pass `yes` or `no`, `true` or `false`, or `htmlonly` if you only want links rewritten in the HTML part of the message */ - tracking?: string; + tracking?: YesNoHtmlonlyEnum; /** Toggles opens tracking on a per-message basis. Has higher priority than domain-level setting. Pass `yes` or `no`, `true` or `false` */ - trackingOpens?: string; + trackingOpens?: YesNoEnum; /** If you send long emails that experience truncation or other rendering issues at the recipient, you can ensure opens are being tracked accurately with placement of the tracking pixel at the top of your emails */ - trackingPixelLocationTop?: string; + trackingPixelLocationTop?: YesNoEnum; /** Used to specify an IP Address to send an email that is owned by your account */ sendingIp?: string; /** If an IP Pool ID is provided, the email will be delivered with an IP that belongs in that pool */ sendingIpPool?: string; /** If set to `true` or `yes` this requires the message only be sent over a TLS connection. If a TLS connection can not be established, Mailgun will not deliver the message. If set to `false` or `no`, Mailgun will still try and upgrade the connection, but if Mailgun cannot, the message will be delivered over a plaintext SMTP connection. The default is `false` */ - requireTls?: string; + requireTls?: YesNoEnum; /** If set to `true` or `yes`, the certificate and hostname of the resolved MX Host will not be verified when trying to establish a TLS connection. If set to `false` or `no`, Mailgun will verify the certificate and hostname. If either one can not be verified, a TLS connection will not be established. The default is `false` */ - skipVerification?: string; + skipVerification?: YesNoEnum; /** Enables sending in test mode. Pass `yes` if needed. See **Sending in Test Mode** */ - isTestMode?: boolean; + isTestMode?: YesNoEnum; } diff --git a/packages/mailgun/src/models/v1/emails/request/send-email-request/send-email-request.transform.ts b/packages/mailgun/src/models/v1/emails/request/send-email-request/send-email-request.transform.ts new file mode 100644 index 0000000..6e01953 --- /dev/null +++ b/packages/mailgun/src/models/v1/emails/request/send-email-request/send-email-request.transform.ts @@ -0,0 +1,55 @@ +import { appendOverridePropertiesToFormData } from '../override-properties/override-properties.transform'; +import { appendTemplatePropertiesToFormData } from '../template-properties/template-properties.transform'; +import { appendFilteredPropertiesToFormData } from '../helper'; +import { SendEmailRequest } from './send-email-request'; +import FormData = require('form-data'); + +// eslint-disable-next-line valid-jsdoc +/** + * ** INTERNAL METHOD ** IT SHOULD NOT BE USED DIRECTLY BY SDK USERS AS IT CAN BE REMOVED OR MODIFIED WITHOUT NOTICE + */ +export const transformSendEmailRequestIntoApiRequestBody = (sdkRequest: SendEmailRequest): FormData => { + const formData = new FormData(); + if (sdkRequest.html != null) { + formData.append('html', sdkRequest.html); + } + if (sdkRequest.ampHtml != null) { + formData.append('amp-html', sdkRequest['ampHtml']); + } + if (sdkRequest.text!= null) { + formData.append('text', sdkRequest.text); + } + if (sdkRequest.to != null) { + formData.append('to', sdkRequest.to); + } + if (sdkRequest.from != null) { + formData.append('from', sdkRequest.from); + } + if (sdkRequest.cc != null) { + formData.append('cc', sdkRequest.cc); + } + if (sdkRequest.bcc != null) { + formData.append('bcc', sdkRequest.bcc); + } + if (sdkRequest.subject != null) { + formData.append('subject', sdkRequest.subject); + } + if (sdkRequest.attachment != null) { + formData.append('attachment', sdkRequest.attachment); + } + if (sdkRequest.inline != null) { + formData.append('inline', sdkRequest.inline); + } + if (sdkRequest.overrideProperties != null) { + appendOverridePropertiesToFormData(sdkRequest.overrideProperties, formData); + } + if (sdkRequest.template != null) { + formData.append('template', sdkRequest.template); + } + if (sdkRequest.templateProperties != null) { + appendTemplatePropertiesToFormData(sdkRequest.templateProperties, formData); + } + appendFilteredPropertiesToFormData(sdkRequest, 'h:', formData); + appendFilteredPropertiesToFormData(sdkRequest, 'v:', formData); + return formData; +}; diff --git a/packages/mailgun/src/models/v1/emails/request/send-email-request/send-email-request.ts b/packages/mailgun/src/models/v1/emails/request/send-email-request/send-email-request.ts index ab7b29f..0afcbe4 100644 --- a/packages/mailgun/src/models/v1/emails/request/send-email-request/send-email-request.ts +++ b/packages/mailgun/src/models/v1/emails/request/send-email-request/send-email-request.ts @@ -1,25 +1,19 @@ import { TemplateProperties } from '../template-properties'; import { OverrideProperties } from '../override-properties'; -import FormData = require('form-data'); -export type MessageContentWhereHtmlContentCanBeInlineOnly = { + +export type MessageContentWithHtmlInline = { /** Body of the message (HTML version) */ html?: string; - /** AMP part of the message. Please follow Google guidelines to compose and send AMP emails */ - amp_html?: string; - /** Body of the message (text version) */ - text?: string; /** Name of a template stored via template API to use to render the email body. See **Templates** for more information */ template?: never; + /** @see TemplateProperties */ + templateProperties?: never; } & CommonEmailProperties; -export type MessageContentWhereHtmlContentCanBeFromTemplateOnly = { +export type MessageContentWithHtmlInTemplate = { /** Name of a template stored via template API to use to render the email body. See **Templates** for more information */ template?: string; - /** AMP part of the message. Please follow Google guidelines to compose and send AMP emails */ - amp_html?: string; - /** Body of the message (text version) */ - text?: string; /** Body of the message (HTML version) */ html?: never; /** @see TemplateProperties */ @@ -37,6 +31,10 @@ export interface CommonEmailProperties { bcc?: string; /** Message subject */ subject: string; + /** Body of the message (text version) */ + text?: string; + /** AMP part of the message. Please follow Google guidelines to compose and send AMP emails */ + ampHtml?: string; /** File attachment. You can post multiple `attachment` values. **Important:** You must use `multipart/form-data` encoding for sending attachments */ attachment?: string; /** Attachment with `inline` disposition. Can be used to send inline images (see example). You can post multiple `inline` values */ @@ -46,123 +44,8 @@ export interface CommonEmailProperties { /** h: prefix followed by a Header/Value pair. For example: h:X-Mailgun-Sending-Ip-Pool=xx.xx.xxx.x. */ [key: `h:${string}`]: string; /** `v:` prefix followed by an arbitrary name allows to attach a custom JSON data to the message. See **Attaching Data to Messages** for more information */ - [key: `v:${string}`]: string | number; + [key: `v:${string}`]: string | number | Date; } -export type SendEmailRequest = MessageContentWhereHtmlContentCanBeInlineOnly - | MessageContentWhereHtmlContentCanBeFromTemplateOnly; - -export const transformSendEmailRequestIntoApiRequestBody = (sdkRequest: SendEmailRequest): FormData => { - const formData = new FormData(); - if ('html' in sdkRequest && sdkRequest['html'] !== undefined && sdkRequest['html'] !== null) { - formData.append('html', sdkRequest['html']); - } - if ('template' in sdkRequest && sdkRequest['template'] !== undefined && sdkRequest['template'] !== null) { - formData.append('template', sdkRequest['template']); - } - if (sdkRequest['amp_html'] !== undefined && sdkRequest['amp_html'] !== null) { - formData.append('amp-html', sdkRequest['amp_html']); - } - if (sdkRequest['text'] !== undefined && sdkRequest['text'] !== null) { - formData.append('text', sdkRequest['text']); - } - if (sdkRequest['to'] !== undefined && sdkRequest['to'] !== null) { - formData.append('to', sdkRequest['to']); - } - if (sdkRequest['from'] !== undefined && sdkRequest['from'] !== null) { - formData.append('from', sdkRequest['from']); - } - if (sdkRequest['cc'] !== undefined && sdkRequest['cc'] !== null) { - formData.append('cc', sdkRequest['cc']); - } - if (sdkRequest['bcc'] !== undefined && sdkRequest['bcc'] !== null) { - formData.append('bcc', sdkRequest['bcc']); - } - if (sdkRequest['subject'] !== undefined && sdkRequest['subject'] !== null) { - formData.append('subject', sdkRequest['subject']); - } - if (sdkRequest['attachment'] !== undefined && sdkRequest['attachment'] !== null) { - formData.append('attachment', sdkRequest['attachment']); - } - if (sdkRequest['inline'] !== undefined && sdkRequest['inline'] !== null) { - formData.append('inline', sdkRequest['inline']); - } - if ('templateProperties' in sdkRequest - && sdkRequest.templateProperties !== null - && sdkRequest.templateProperties !== undefined) { - const templateProperties = sdkRequest.templateProperties; - if (templateProperties['text'] !== undefined && templateProperties['text'] !== null) { - formData.append('t:text', templateProperties['text']); - } - if (templateProperties['version'] !== undefined && templateProperties['version'] !== null) { - formData.append('t:version', templateProperties['version']); - } - if (templateProperties['variables'] !== undefined && templateProperties['variables'] !== null) { - formData.append('t:variables', templateProperties['variables']); - } - } - if (sdkRequest['overrideProperties'] !== undefined && sdkRequest['overrideProperties'] !== null) { - const overrideProperties = sdkRequest['overrideProperties']; - if (overrideProperties['tag'] !== undefined && overrideProperties['tag'] !== null) { - formData.append('o:tag', overrideProperties['tag']); - } - if (overrideProperties['deliveryTimeOptimizePeriod'] !== undefined - && overrideProperties['deliveryTimeOptimizePeriod'] !== null) { - formData.append('o:deliverytime-optimize-period', overrideProperties['deliveryTimeOptimizePeriod']); - } - if (overrideProperties['enableDkimSignature'] !== undefined && overrideProperties['enableDkimSignature'] !== null) { - formData.append('o:dkim', overrideProperties['enableDkimSignature']); - } - if (overrideProperties['secondaryDkim'] !== undefined && overrideProperties['secondaryDkim'] !== null) { - formData.append('o:secondary-dkim', overrideProperties['secondaryDkim']); - } - if (overrideProperties['secondaryDkimPublic'] !== undefined && overrideProperties['secondaryDkimPublic'] !== null) { - formData.append('o:secondary-dkim-public', overrideProperties['secondaryDkimPublic']); - } - if (overrideProperties['deliveryTime'] !== undefined && overrideProperties['deliveryTime'] !== null) { - formData.append('o:deliverytime', overrideProperties['deliveryTime']); - } - if (overrideProperties['timeZoneLocalize'] !== undefined && overrideProperties['timeZoneLocalize'] !== null) { - formData.append('o:time-zone-localize', overrideProperties['timeZoneLocalize']); - } - if (overrideProperties['tracking'] !== undefined && overrideProperties['tracking'] !== null) { - formData.append('o:tracking', overrideProperties['tracking']); - } - if (overrideProperties['trackingClicks'] !== undefined && overrideProperties['trackingClicks'] !== null) { - formData.append('o:tracking-clicks', overrideProperties['trackingClicks']); - } - if (overrideProperties['trackingOpens'] !== undefined && overrideProperties['trackingOpens'] !== null) { - formData.append('o:tracking-opens', overrideProperties['trackingOpens']); - } - if (overrideProperties['trackingPixelLocationTop'] !== undefined - && overrideProperties['trackingPixelLocationTop'] !== null) { - formData.append('o:tracking-pixel-location-top', overrideProperties['trackingPixelLocationTop']); - } - if (overrideProperties['sendingIp'] !== undefined && overrideProperties['sendingIp'] !== null) { - formData.append('o:sending-ip', overrideProperties['sendingIp']); - } - if (overrideProperties['sendingIpPool'] !== undefined && overrideProperties['sendingIpPool'] !== null) { - formData.append('o:sending-ip-pool', overrideProperties['sendingIpPool']); - } - if (overrideProperties['requireTls'] !== undefined && overrideProperties['requireTls'] !== null) { - formData.append('o:require-tls', overrideProperties['requireTls']); - } - if (overrideProperties['skipVerification'] !== undefined && overrideProperties['skipVerification'] !== null) { - formData.append('o:skip-verification', overrideProperties['skipVerification']); - } - if (overrideProperties['isTestMode'] !== undefined && overrideProperties['isTestMode'] !== null) { - formData.append('o:testmode', overrideProperties['isTestMode']); - } - } - addPropertiesToFormData(sdkRequest, 'h:', formData); - addPropertiesToFormData(sdkRequest, 'v:', formData); - return formData; -}; - -const addPropertiesToFormData = (obj: SendEmailRequest, prefix: string, formData: FormData) => { - for (const [key, value] of Object.entries(obj)) { - if (key.startsWith(prefix) && !!value) { - formData.append(key, value); - } - } -}; +export type SendEmailRequest = MessageContentWithHtmlInline + | MessageContentWithHtmlInTemplate; diff --git a/packages/mailgun/src/models/v1/emails/request/send-mime-email-request/send-mime-email-request.transform.ts b/packages/mailgun/src/models/v1/emails/request/send-mime-email-request/send-mime-email-request.transform.ts new file mode 100644 index 0000000..0612e4d --- /dev/null +++ b/packages/mailgun/src/models/v1/emails/request/send-mime-email-request/send-mime-email-request.transform.ts @@ -0,0 +1,31 @@ +import { appendTemplatePropertiesToFormData } from '../template-properties/template-properties.transform'; +import { appendOverridePropertiesToFormData } from '../override-properties/override-properties.transform'; +import { appendFilteredPropertiesToFormData } from '../helper'; +import { SendMimeEmailRequest } from './send-mime-email-request'; +import FormData = require('form-data'); + +// eslint-disable-next-line valid-jsdoc +/** + * ** INTERNAL METHOD ** IT SHOULD NOT BE USED DIRECTLY BY SDK USERS AS IT CAN BE REMOVED OR MODIFIED WITHOUT NOTICE + */ +export const transformSendMimeEmailRequestIntoApiRequestBody = (sdkRequest: SendMimeEmailRequest): FormData => { + const formData = new FormData(); + if (sdkRequest.to != null) { + formData.append('to', sdkRequest.to); + } + if (sdkRequest.message != null) { + formData.append('message', sdkRequest.message, { filename: 'MimeMessage' }); + } + if (sdkRequest.template != null) { + formData.append('template', sdkRequest['template']); + } + if (sdkRequest.templateProperties != null) { + appendTemplatePropertiesToFormData(sdkRequest.templateProperties, formData); + } + if (sdkRequest.overrideProperties != null) { + appendOverridePropertiesToFormData(sdkRequest.overrideProperties, formData); + } + appendFilteredPropertiesToFormData(sdkRequest, 'h:', formData); + appendFilteredPropertiesToFormData(sdkRequest, 'v:', formData); + return formData; +}; diff --git a/packages/mailgun/src/models/v1/emails/request/send-mime-email-request/send-mime-email-request.ts b/packages/mailgun/src/models/v1/emails/request/send-mime-email-request/send-mime-email-request.ts index ac66408..3abe909 100644 --- a/packages/mailgun/src/models/v1/emails/request/send-mime-email-request/send-mime-email-request.ts +++ b/packages/mailgun/src/models/v1/emails/request/send-mime-email-request/send-mime-email-request.ts @@ -1,6 +1,5 @@ import { TemplateProperties } from '../template-properties'; import { OverrideProperties } from '../override-properties'; -import FormData = require('form-data'); export interface SendMimeEmailRequest { /** MIME string of the message. Make sure to use `multipart/form-data` content type to send this as a file upload */ @@ -21,93 +20,3 @@ export interface SendMimeEmailRequest { [key: `v:${string}`]: string | number; } -export const transformSendMimeEmailRequestIntoApiRequestBody = (sdkRequest: SendMimeEmailRequest): FormData => { - const formData = new FormData(); - if (sdkRequest['to'] !== undefined && sdkRequest['to'] !== null) { - formData.append('to', sdkRequest['to']); - } - if ('message' in sdkRequest && sdkRequest['message'] !== undefined && sdkRequest['template'] !== null) { - formData.append('message', sdkRequest['message'], { - filename: 'MimeMessage', - }); - } - if ('template' in sdkRequest && sdkRequest['template'] !== undefined && sdkRequest['template'] !== null) { - formData.append('template', sdkRequest['template']); - } - if (sdkRequest['templateProperties'] !== undefined && sdkRequest['templateProperties'] !== null) { - const templateProperties = sdkRequest['templateProperties']; - if (templateProperties['text'] !== undefined && templateProperties['text'] !== null) { - formData.append('t:text', templateProperties['text']); - } - if (templateProperties['version'] !== undefined && templateProperties['version'] !== null) { - formData.append('t:version', templateProperties['version']); - } - if (templateProperties['variables'] !== undefined && templateProperties['variables'] !== null) { - formData.append('t:variables', templateProperties['variables']); - } - } - if (sdkRequest['overrideProperties'] !== undefined && sdkRequest['overrideProperties'] !== null) { - const overrideProperties = sdkRequest['overrideProperties']; - if (overrideProperties['tag'] !== undefined && overrideProperties['tag'] !== null) { - formData.append('o:tag', overrideProperties['tag']); - } - if (overrideProperties['deliveryTimeOptimizePeriod'] !== undefined - && overrideProperties['deliveryTimeOptimizePeriod'] !== null) { - formData.append('o:deliverytime-optimize-period', overrideProperties['deliveryTimeOptimizePeriod']); - } - if (overrideProperties['enableDkimSignature'] !== undefined && overrideProperties['enableDkimSignature'] !== null) { - formData.append('o:dkim', overrideProperties['enableDkimSignature']); - } - if (overrideProperties['secondaryDkim'] !== undefined && overrideProperties['secondaryDkim'] !== null) { - formData.append('o:secondary-dkim', overrideProperties['secondaryDkim']); - } - if (overrideProperties['secondaryDkimPublic'] !== undefined && overrideProperties['secondaryDkimPublic'] !== null) { - formData.append('o:secondary-dkim-public', overrideProperties['secondaryDkimPublic']); - } - if (overrideProperties['deliveryTime'] !== undefined && overrideProperties['deliveryTime'] !== null) { - formData.append('o:deliverytime', overrideProperties['deliveryTime']); - } - if (overrideProperties['timeZoneLocalize'] !== undefined && overrideProperties['timeZoneLocalize'] !== null) { - formData.append('o:time-zone-localize', overrideProperties['timeZoneLocalize']); - } - if (overrideProperties['tracking'] !== undefined && overrideProperties['tracking'] !== null) { - formData.append('o:tracking', overrideProperties['tracking']); - } - if (overrideProperties['trackingClicks'] !== undefined && overrideProperties['trackingClicks'] !== null) { - formData.append('o:tracking-clicks', overrideProperties['trackingClicks']); - } - if (overrideProperties['trackingOpens'] !== undefined && overrideProperties['trackingOpens'] !== null) { - formData.append('o:tracking-opens', overrideProperties['trackingOpens']); - } - if (overrideProperties['trackingPixelLocationTop'] !== undefined - && overrideProperties['trackingPixelLocationTop'] !== null) { - formData.append('o:tracking-pixel-location-top', overrideProperties['trackingPixelLocationTop']); - } - if (overrideProperties['sendingIp'] !== undefined && overrideProperties['sendingIp'] !== null) { - formData.append('o:sending-ip', overrideProperties['sendingIp']); - } - if (overrideProperties['sendingIpPool'] !== undefined && overrideProperties['sendingIpPool'] !== null) { - formData.append('o:sending-ip-pool', overrideProperties['sendingIpPool']); - } - if (overrideProperties['requireTls'] !== undefined && overrideProperties['requireTls'] !== null) { - formData.append('o:require-tls', overrideProperties['requireTls']); - } - if (overrideProperties['skipVerification'] !== undefined && overrideProperties['skipVerification'] !== null) { - formData.append('o:skip-verification', overrideProperties['skipVerification']); - } - if (overrideProperties['isTestMode'] !== undefined && overrideProperties['isTestMode'] !== null) { - formData.append('o:testmode', overrideProperties['isTestMode']); - } - } - addPropertiesToFormData(sdkRequest, 'h:', formData); - addPropertiesToFormData(sdkRequest, 'v:', formData); - return formData; -}; - -const addPropertiesToFormData = (obj: SendMimeEmailRequest, prefix: string, formData: FormData) => { - for (const [key, value] of Object.entries(obj)) { - if (key.startsWith(prefix) && !!value) { - formData.append(key, value); - } - } -}; diff --git a/packages/mailgun/src/models/v1/emails/request/template-properties/template-properties.transform.ts b/packages/mailgun/src/models/v1/emails/request/template-properties/template-properties.transform.ts new file mode 100644 index 0000000..de95bf1 --- /dev/null +++ b/packages/mailgun/src/models/v1/emails/request/template-properties/template-properties.transform.ts @@ -0,0 +1,18 @@ +import { TemplateProperties } from './template-properties'; +import FormData = require('form-data'); + +// eslint-disable-next-line valid-jsdoc +/** + * ** INTERNAL METHOD ** IT SHOULD NOT BE USED DIRECTLY BY SDK USERS AS IT CAN BE REMOVED OR MODIFIED WITHOUT NOTICE + */ +export const appendTemplatePropertiesToFormData = (templateProperties: TemplateProperties, formData: FormData) => { + if (templateProperties['text'] != null) { + formData.append('t:text', String(templateProperties['text'])); + } + if (templateProperties['version'] != null) { + formData.append('t:version', templateProperties['version']); + } + if (templateProperties['variables'] != null) { + formData.append('t:variables', templateProperties['variables']); + } +}; diff --git a/packages/mailgun/src/models/v1/emails/request/template-properties/template-properties.ts b/packages/mailgun/src/models/v1/emails/request/template-properties/template-properties.ts index 1bb3524..e1b131d 100644 --- a/packages/mailgun/src/models/v1/emails/request/template-properties/template-properties.ts +++ b/packages/mailgun/src/models/v1/emails/request/template-properties/template-properties.ts @@ -1,8 +1,11 @@ +import { YesNoEnum } from '../enum'; + export interface TemplateProperties { /** Pass `yes` if you want to have a rendered template in the text part of the message in case of template sending */ - text?: string; + text?: YesNoEnum; /** Render a specific version of the given template instead of the latest version. `o:template` option must also be provided. */ version?: string; /** A valid JSON-encoded dictionary used as the input for template variable expansion. See **Templates** for more information */ variables?: string; } + diff --git a/packages/mailgun/src/models/v1/emails/response/bad-request/bad-request.transform.ts b/packages/mailgun/src/models/v1/emails/response/bad-request/bad-request.transform.ts new file mode 100644 index 0000000..abef2b1 --- /dev/null +++ b/packages/mailgun/src/models/v1/emails/response/bad-request/bad-request.transform.ts @@ -0,0 +1,14 @@ +import { BadRequest, BadRequestFromApi } from './bad-request'; + +// eslint-disable-next-line valid-jsdoc +/** + * ** INTERNAL METHOD ** IT SHOULD NOT BE USED DIRECTLY BY SDK USERS AS IT CAN BE REMOVED OR MODIFIED WITHOUT NOTICE + */ +export const transformBadRequestIntoClientResponse = ( + apiResponse: BadRequestFromApi, +): BadRequest => { + const { + ...response + } = apiResponse; + return response; +}; diff --git a/packages/mailgun/src/models/v1/emails/response/bad-request/bad-request.ts b/packages/mailgun/src/models/v1/emails/response/bad-request/bad-request.ts index 80dd82a..94a8e17 100644 --- a/packages/mailgun/src/models/v1/emails/response/bad-request/bad-request.ts +++ b/packages/mailgun/src/models/v1/emails/response/bad-request/bad-request.ts @@ -1,12 +1,3 @@ -export const transformBadRequestIntoClientResponse = ( - apiResponse: BadRequestFromApi, -): BadRequest => { - const { - ...response - } = apiResponse; - return response; -}; - export type BadRequest = Omit; export interface BadRequestFromApi { message: string; diff --git a/packages/mailgun/src/models/v1/emails/response/email-not-found/email-not-found.transform.ts b/packages/mailgun/src/models/v1/emails/response/email-not-found/email-not-found.transform.ts new file mode 100644 index 0000000..9e97ba7 --- /dev/null +++ b/packages/mailgun/src/models/v1/emails/response/email-not-found/email-not-found.transform.ts @@ -0,0 +1,14 @@ +import { EmailNotFound, EmailNotFoundFromApi } from './email-not-found'; + +// eslint-disable-next-line valid-jsdoc +/** + * ** INTERNAL METHOD ** IT SHOULD NOT BE USED DIRECTLY BY SDK USERS AS IT CAN BE REMOVED OR MODIFIED WITHOUT NOTICE + */ +export const transformEmailNotFoundIntoClientResponse = ( + apiResponse: EmailNotFoundFromApi, +): EmailNotFound => { + const { + ...response + } = apiResponse; + return response; +}; diff --git a/packages/mailgun/src/models/v1/emails/response/email-not-found/email-not-found.ts b/packages/mailgun/src/models/v1/emails/response/email-not-found/email-not-found.ts index 733d835..2a6546e 100644 --- a/packages/mailgun/src/models/v1/emails/response/email-not-found/email-not-found.ts +++ b/packages/mailgun/src/models/v1/emails/response/email-not-found/email-not-found.ts @@ -1,12 +1,3 @@ -export const transformEmailNotFoundIntoClientResponse = ( - apiResponse: EmailNotFoundFromApi, -): EmailNotFound => { - const { - ...response - } = apiResponse; - return response; -}; - export type EmailNotFound = Omit; export interface EmailNotFoundFromApi { diff --git a/packages/mailgun/src/models/v1/emails/response/exceeded-queue-quota/exceeded-queue-quota.transform.ts b/packages/mailgun/src/models/v1/emails/response/exceeded-queue-quota/exceeded-queue-quota.transform.ts new file mode 100644 index 0000000..7435d9e --- /dev/null +++ b/packages/mailgun/src/models/v1/emails/response/exceeded-queue-quota/exceeded-queue-quota.transform.ts @@ -0,0 +1,17 @@ +import { ExceededQueueQuota, ExceededQueueQuotaFromApi } from './exceeded-queue-quota'; +import { + transformQueueStatusDisabledDetailsIntoClientResponse, +} from '../queue-status-disabled-details/queue-status-disabled-details.transform'; + +// eslint-disable-next-line valid-jsdoc +/** + * ** INTERNAL METHOD ** IT SHOULD NOT BE USED DIRECTLY BY SDK USERS AS IT CAN BE REMOVED OR MODIFIED WITHOUT NOTICE + */ +export const transformExceededQueueQuota = ( + apiResponse: ExceededQueueQuotaFromApi, +): ExceededQueueQuota => { + return { + disabled: transformQueueStatusDisabledDetailsIntoClientResponse(apiResponse['disabled']), + isDisabled: apiResponse['is_disabled'], + }; +}; diff --git a/packages/mailgun/src/models/v1/emails/response/exceeded-queue-quota/exceeded-queue-quota.ts b/packages/mailgun/src/models/v1/emails/response/exceeded-queue-quota/exceeded-queue-quota.ts index 17b0729..12f2544 100644 --- a/packages/mailgun/src/models/v1/emails/response/exceeded-queue-quota/exceeded-queue-quota.ts +++ b/packages/mailgun/src/models/v1/emails/response/exceeded-queue-quota/exceeded-queue-quota.ts @@ -1,13 +1,5 @@ import { QueueStatusDisabledDetails } from '../queue-status-disabled-details'; - -export const transformExceededQueueQuota = ( - apiResponse: ExceededQueueQuotaFromApi, -): ExceededQueueQuota => { - return { - disabled: apiResponse.disabled, - isDisabled: apiResponse.is_disabled, - }; -}; +import { QueueStatusDisabledDetailsFromApi } from '../queue-status-disabled-details/queue-status-disabled-details'; export interface ExceededQueueQuota { /** @see QueueStatusDisabledDetails */ @@ -16,7 +8,7 @@ export interface ExceededQueueQuota { } export interface ExceededQueueQuotaFromApi { - /** @see QueueStatusDisabledDetails */ - disabled?: QueueStatusDisabledDetails; + /** @see QueueStatusDisabledDetailsFromApi */ + disabled?: QueueStatusDisabledDetailsFromApi; is_disabled: boolean; } diff --git a/packages/mailgun/src/models/v1/emails/response/generic-response/generic-response.transform.ts b/packages/mailgun/src/models/v1/emails/response/generic-response/generic-response.transform.ts new file mode 100644 index 0000000..1af3320 --- /dev/null +++ b/packages/mailgun/src/models/v1/emails/response/generic-response/generic-response.transform.ts @@ -0,0 +1,14 @@ +import { GenericResponse, GenericResponseFromApi } from './generic-response'; + +// eslint-disable-next-line valid-jsdoc +/** + * ** INTERNAL METHOD ** IT SHOULD NOT BE USED DIRECTLY BY SDK USERS AS IT CAN BE REMOVED OR MODIFIED WITHOUT NOTICE + */ +export const transformGenericResponseIntoClientResponse = ( + apiResponse: GenericResponseFromApi, +): GenericResponse => { + const { + ...response + } = apiResponse; + return response; +}; diff --git a/packages/mailgun/src/models/v1/emails/response/generic-response/generic-response.ts b/packages/mailgun/src/models/v1/emails/response/generic-response/generic-response.ts index f475b1e..0ab03f3 100644 --- a/packages/mailgun/src/models/v1/emails/response/generic-response/generic-response.ts +++ b/packages/mailgun/src/models/v1/emails/response/generic-response/generic-response.ts @@ -1,12 +1,3 @@ -export const transformGenericResponseIntoClientResponse = ( - apiResponse: GenericResponseFromApi, -): GenericResponse => { - const { - ...response - } = apiResponse; - return response; -}; - export type GenericResponse = Omit export interface GenericResponseFromApi { diff --git a/packages/mailgun/src/models/v1/emails/response/get-email-response/get-stored-email-response.transform.ts b/packages/mailgun/src/models/v1/emails/response/get-email-response/get-stored-email-response.transform.ts new file mode 100644 index 0000000..a34957a --- /dev/null +++ b/packages/mailgun/src/models/v1/emails/response/get-email-response/get-stored-email-response.transform.ts @@ -0,0 +1,34 @@ +import { + GetStoredEmailResponse, + GetStoredEmailResponseFromApi, + MessageHeaders, + MessageHeadersFromApi, +} from './get-stored-email-response'; + +// eslint-disable-next-line valid-jsdoc +/** + * ** INTERNAL METHOD ** IT SHOULD NOT BE USED DIRECTLY BY SDK USERS AS IT CAN BE REMOVED OR MODIFIED WITHOUT NOTICE + */ +export const transformGetEmailResponseIntoClientResponse = ( + apiResponse: GetStoredEmailResponseFromApi, +): GetStoredEmailResponse => { + return { + sender: apiResponse['sender'], + recipients: apiResponse['recipients'], + from: apiResponse['from'], + subject: apiResponse['subject'], + bodyHtml: apiResponse['body-html'], + bodyPlain: apiResponse['body-plain'], + messageHeaders: convertHeaders(apiResponse['message-headers']), + strippedHtml: apiResponse['stripped-html'], + strippedText: apiResponse['stripped-text'], + strippedSignature: apiResponse['stripped-signature'], + }; +}; + +const convertHeaders = (headers: MessageHeadersFromApi): MessageHeaders => { + return headers.reduce((acc, [key, value]) => { + acc[key] = value; + return acc; + }, {} as MessageHeaders); +}; diff --git a/packages/mailgun/src/models/v1/emails/response/get-email-response/get-stored-email-response.ts b/packages/mailgun/src/models/v1/emails/response/get-email-response/get-stored-email-response.ts index 6e08dd2..d25891e 100644 --- a/packages/mailgun/src/models/v1/emails/response/get-email-response/get-stored-email-response.ts +++ b/packages/mailgun/src/models/v1/emails/response/get-email-response/get-stored-email-response.ts @@ -1,27 +1,3 @@ -export const transformGetEmailResponseIntoClientResponse = ( - apiResponse: GetStoredEmailResponseFromApi, -): GetStoredEmailResponse => { - return { - sender: apiResponse['sender'], - recipients: apiResponse['recipients'], - from: apiResponse['from'], - subject: apiResponse['subject'], - bodyHtml: apiResponse['body-html'], - bodyPlain: apiResponse['body-plain'], - messageHeaders: convertHeaders(apiResponse['message-headers']), - strippedHtml: apiResponse['stripped-html'], - strippedText: apiResponse['stripped-text'], - strippedSignature: apiResponse['stripped-signature'], - }; -}; - -function convertHeaders(headers: MessageHeadersFromApi): MessageHeaders { - return headers.reduce((acc, [key, value]) => { - acc[key] = value; - return acc; - }, {} as MessageHeaders); -} - export interface GetStoredEmailResponse { sender: string, recipients: string, @@ -51,6 +27,6 @@ export interface GetStoredEmailResponseFromApi { export type MessageHeadersFromApi = [string, string | Date][]; -export type MessageHeaders= { +export type MessageHeaders = { [key: string]: string | Date; }; diff --git a/packages/mailgun/src/models/v1/emails/response/queue-status-disabled-details/queue-status-disabled-details.transform.ts b/packages/mailgun/src/models/v1/emails/response/queue-status-disabled-details/queue-status-disabled-details.transform.ts new file mode 100644 index 0000000..53c8534 --- /dev/null +++ b/packages/mailgun/src/models/v1/emails/response/queue-status-disabled-details/queue-status-disabled-details.transform.ts @@ -0,0 +1,14 @@ +import { QueueStatusDisabledDetails, QueueStatusDisabledDetailsFromApi } from './queue-status-disabled-details'; + +// eslint-disable-next-line valid-jsdoc +/** + * ** INTERNAL METHOD ** IT SHOULD NOT BE USED DIRECTLY BY SDK USERS AS IT CAN BE REMOVED OR MODIFIED WITHOUT NOTICE + */ +export const transformQueueStatusDisabledDetailsIntoClientResponse = ( + apiResponse?: QueueStatusDisabledDetailsFromApi, +): QueueStatusDisabledDetails => { + const { + ...response + } = apiResponse; + return response; +}; diff --git a/packages/mailgun/src/models/v1/emails/response/queue-status-disabled-details/queue-status-disabled-details.ts b/packages/mailgun/src/models/v1/emails/response/queue-status-disabled-details/queue-status-disabled-details.ts index 5a302a1..534094b 100644 --- a/packages/mailgun/src/models/v1/emails/response/queue-status-disabled-details/queue-status-disabled-details.ts +++ b/packages/mailgun/src/models/v1/emails/response/queue-status-disabled-details/queue-status-disabled-details.ts @@ -1,4 +1,6 @@ -export interface QueueStatusDisabledDetails { - reason: string; - until: string; +export type QueueStatusDisabledDetails = Omit; + +export interface QueueStatusDisabledDetailsFromApi { + 'reason': string; + 'until': string; } diff --git a/packages/mailgun/src/models/v1/emails/response/send-email-response/send-email-response.transform.ts b/packages/mailgun/src/models/v1/emails/response/send-email-response/send-email-response.transform.ts new file mode 100644 index 0000000..ddfb2d7 --- /dev/null +++ b/packages/mailgun/src/models/v1/emails/response/send-email-response/send-email-response.transform.ts @@ -0,0 +1,14 @@ +import { SendEmailResponse, SendEmailResponseFromApi } from './send-email-response'; + +// eslint-disable-next-line valid-jsdoc +/** + * ** INTERNAL METHOD ** IT SHOULD NOT BE USED DIRECTLY BY SDK USERS AS IT CAN BE REMOVED OR MODIFIED WITHOUT NOTICE + */ +export const transformSendEmailResponseIntoClientResponse = ( + apiResponse: SendEmailResponseFromApi, +): SendEmailResponse => { + const { + ...response + } = apiResponse; + return response; +}; diff --git a/packages/mailgun/src/models/v1/emails/response/send-email-response/send-email-response.ts b/packages/mailgun/src/models/v1/emails/response/send-email-response/send-email-response.ts index eedfbc2..5a81016 100644 --- a/packages/mailgun/src/models/v1/emails/response/send-email-response/send-email-response.ts +++ b/packages/mailgun/src/models/v1/emails/response/send-email-response/send-email-response.ts @@ -1,12 +1,3 @@ -export const transformSendEmailResponseIntoClientResponse = ( - apiResponse: SendEmailResponseFromApi, -): SendEmailResponse => { - const { - ...response - } = apiResponse; - return response; -}; - export type SendEmailResponse = Omit export interface SendEmailResponseFromApi { diff --git a/packages/mailgun/src/models/v1/emails/response/sending-queues-status-response/sending-queues-status-response.transform.ts b/packages/mailgun/src/models/v1/emails/response/sending-queues-status-response/sending-queues-status-response.transform.ts new file mode 100644 index 0000000..f9e0e13 --- /dev/null +++ b/packages/mailgun/src/models/v1/emails/response/sending-queues-status-response/sending-queues-status-response.transform.ts @@ -0,0 +1,15 @@ +import { SendingQueuesStatusResponse, SendingQueuesStatusResponseFromApi } from './sending-queues-status-response'; +import { transformExceededQueueQuota } from '../exceeded-queue-quota/exceeded-queue-quota.transform'; + +// eslint-disable-next-line valid-jsdoc +/** + * ** INTERNAL METHOD ** IT SHOULD NOT BE USED DIRECTLY BY SDK USERS AS IT CAN BE REMOVED OR MODIFIED WITHOUT NOTICE + */ +export const transformSendingQueuesStatusResponseIntoClientResponse = ( + apiResponse: SendingQueuesStatusResponseFromApi, +): SendingQueuesStatusResponse => { + return { + scheduled: transformExceededQueueQuota(apiResponse['scheduled']), + regular: transformExceededQueueQuota(apiResponse['regular']), + }; +}; diff --git a/packages/mailgun/src/models/v1/emails/response/sending-queues-status-response/sending-queues-status-response.ts b/packages/mailgun/src/models/v1/emails/response/sending-queues-status-response/sending-queues-status-response.ts index ba92da4..7aca45a 100644 --- a/packages/mailgun/src/models/v1/emails/response/sending-queues-status-response/sending-queues-status-response.ts +++ b/packages/mailgun/src/models/v1/emails/response/sending-queues-status-response/sending-queues-status-response.ts @@ -1,14 +1,5 @@ import { ExceededQueueQuota } from '../exceeded-queue-quota'; -import { ExceededQueueQuotaFromApi, transformExceededQueueQuota } from '../exceeded-queue-quota/exceeded-queue-quota'; - -export const transformSendingQueuesStatusResponseIntoClientResponse = ( - apiResponse: SendingQueuesStatusResponseFromApi, -): SendingQueuesStatusResponse => { - return { - scheduled: transformExceededQueueQuota(apiResponse.scheduled), - regular: transformExceededQueueQuota(apiResponse.regular), - }; -}; +import { ExceededQueueQuotaFromApi } from '../exceeded-queue-quota/exceeded-queue-quota'; export interface SendingQueuesStatusResponse { /** @see ExceededQueueQuota */ @@ -18,8 +9,8 @@ export interface SendingQueuesStatusResponse { } export interface SendingQueuesStatusResponseFromApi { - /** @see ExceededQueueQuota */ + /** @see ExceededQueueQuotaFromApi */ scheduled: ExceededQueueQuotaFromApi; - /** @see ExceededQueueQuota */ + /** @see ExceededQueueQuotaFromApi */ regular: ExceededQueueQuotaFromApi; } diff --git a/packages/mailgun/src/models/v1/index.ts b/packages/mailgun/src/models/v1/index.ts index c4fc5a1..4c7239d 100644 --- a/packages/mailgun/src/models/v1/index.ts +++ b/packages/mailgun/src/models/v1/index.ts @@ -1,12 +1,12 @@ -export * from './emails/request/override-properties/override-properties'; -export * from './emails/request/send-email-request/send-email-request'; -export * from './emails/request/send-mime-email-request/send-mime-email-request'; -export * from './emails/request/template-properties/template-properties'; -export * from './emails/response/bad-request/bad-request'; -export * from './emails/response/email-not-found/email-not-found'; -export * from './emails/response/exceeded-queue-quota/exceeded-queue-quota'; -export * from './emails/response/generic-response/generic-response'; -export * from './emails/response/get-email-response/get-stored-email-response'; -export * from './emails/response/queue-status-disabled-details/queue-status-disabled-details'; -export * from './emails/response/send-email-response/send-email-response'; -export * from './emails/response/sending-queues-status-response/sending-queues-status-response'; +export * from './emails/request/override-properties'; +export * from './emails/request/send-email-request'; +export * from './emails/request/send-mime-email-request'; +export * from './emails/request/template-properties'; +export * from './emails/response/bad-request'; +export * from './emails/response/email-not-found'; +export * from './emails/response/exceeded-queue-quota'; +export * from './emails/response/generic-response'; +export * from './emails/response/get-email-response'; +export * from './emails/response/queue-status-disabled-details'; +export * from './emails/response/send-email-response'; +export * from './emails/response/sending-queues-status-response'; diff --git a/packages/mailgun/src/rest/v1/emails/emails-api.ts b/packages/mailgun/src/rest/v1/emails/emails-api.ts index ce9cf62..35b7dd4 100644 --- a/packages/mailgun/src/rest/v1/emails/emails-api.ts +++ b/packages/mailgun/src/rest/v1/emails/emails-api.ts @@ -1,18 +1,9 @@ import { - GenericResponseFromApi, GetStoredEmailResponse, - GetStoredEmailResponseFromApi, SendEmailRequest, SendEmailResponse, - SendEmailResponseFromApi, SendingQueuesStatusResponse, - SendingQueuesStatusResponseFromApi, SendMimeEmailRequest, - transformGetEmailResponseIntoClientResponse, - transformSendEmailRequestIntoApiRequestBody, - transformSendEmailResponseIntoClientResponse, - transformSendingQueuesStatusResponseIntoClientResponse, - transformSendMimeEmailRequestIntoApiRequestBody, } from '../../../models'; import { RequestBody, @@ -20,6 +11,33 @@ import { MailgunStorageHostname, } from '@sinch/sdk-client'; import { MailgunDomainApi } from '../mailgun-domain-api'; +import { + transformSendEmailRequestIntoApiRequestBody, +} from '../../../models/v1/emails/request/send-email-request/send-email-request.transform'; +import { + transformSendMimeEmailRequestIntoApiRequestBody, +} from '../../../models/v1/emails/request/send-mime-email-request/send-mime-email-request.transform'; +import { + transformSendEmailResponseIntoClientResponse, +} from '../../../models/v1/emails/response/send-email-response/send-email-response.transform'; +import { + transformGetEmailResponseIntoClientResponse, +} from '../../../models/v1/emails/response/get-email-response/get-stored-email-response.transform'; +import { + transformSendingQueuesStatusResponseIntoClientResponse, +} from '../../../models/v1/emails/response/sending-queues-status-response/sending-queues-status-response.transform'; +import { + SendEmailResponseFromApi, +} from '../../../models/v1/emails/response/send-email-response/send-email-response'; +import { + GetStoredEmailResponseFromApi, +} from '../../../models/v1/emails/response/get-email-response/get-stored-email-response'; +import { + GenericResponseFromApi, +} from '../../../models/v1/emails/response/generic-response/generic-response'; +import { + SendingQueuesStatusResponseFromApi, +} from '../../../models/v1/emails/response/sending-queues-status-response/sending-queues-status-response'; export class EmailsApi extends MailgunDomainApi { storageHostnames: string[]; diff --git a/packages/mailgun/tests/models/v1/emails/request/helper.test.ts b/packages/mailgun/tests/models/v1/emails/request/helper.test.ts new file mode 100644 index 0000000..95c3884 --- /dev/null +++ b/packages/mailgun/tests/models/v1/emails/request/helper.test.ts @@ -0,0 +1,50 @@ +import FormData = require('form-data'); +import { appendFilteredPropertiesToFormData } from '../../../../../src/models/v1/emails/request/helper'; + +describe('appendFilteredPropertiesToFormData', () => { + let formData: FormData; + let appendSpy: jest.SpyInstance; + + beforeEach(() => { + formData = new FormData(); + appendSpy = jest.spyOn(formData, 'append'); + }); + + afterEach(() => { + appendSpy.mockRestore(); + }); + + it('should append properties with the specified prefix to FormData', () => { + const obj = { + 'o:dkim': true, + 'o:tracking': 'yes', + 'v:first_name': 'John', + 'v:last_name': 'Smith', + 'v:my_message_id': '123', + 'v:date1': '2024-06-06T13:42:42Z', + 'v:date2': new Date('2024-06-06T13:42:42Z'), + }; + + appendFilteredPropertiesToFormData(obj, 'v:', formData); + + expect(appendSpy).toHaveBeenCalledTimes(5); + expect(appendSpy).toHaveBeenCalledWith('v:first_name', 'John'); + expect(appendSpy).toHaveBeenCalledWith('v:last_name', 'Smith'); + expect(appendSpy).toHaveBeenCalledWith('v:my_message_id', '123'); + expect(appendSpy).toHaveBeenCalledWith('v:date1', '2024-06-06T13:42:42Z'); + expect(appendSpy).toHaveBeenCalledWith('v:date2', 'Thu, 06 Jun 2024 13:42:42 GMT'); + }); + + it('should not append properties with null or undefined values', () => { + const obj = { + 'o:dkim': true, + 'o:tracking': 'yes', + 'v:null': null, + 'v:undefined': undefined, + }; + + appendFilteredPropertiesToFormData(obj, 'v:', formData); + + expect(appendSpy).not.toHaveBeenCalled(); + }); +}); diff --git a/packages/mailgun/tests/models/v1/emails/request/send-email-request.models.ts b/packages/mailgun/tests/models/v1/emails/request/send-email-request.models.ts index 12c70f0..3007e9c 100644 --- a/packages/mailgun/tests/models/v1/emails/request/send-email-request.models.ts +++ b/packages/mailgun/tests/models/v1/emails/request/send-email-request.models.ts @@ -8,7 +8,7 @@ export const sendEmailRequestWithHtml: Mailgun.SendEmailRequest = { subject: 'subject value', text: 'text value', html: 'html value', - amp_html: 'amp_html value', + ampHtml: 'amp_html value', attachment: 'attachment value', inline: 'inline value', overrideProperties: { @@ -16,17 +16,17 @@ export const sendEmailRequestWithHtml: Mailgun.SendEmailRequest = { sendingIp: 'sendingIp value', sendingIpPool: 'sendingIpPool value', deliveryTime: 'deliveryTime value', - deliveryTimeOptimizePeriod: 'deliveryTimeOptimizePeriod value', - enableDkimSignature: 'enableDkimSignature value', + deliveryTimeOptimizePeriod: 24, + enableDkimSignature: 'yes', secondaryDkim: 'secondaryDkim value', - secondaryDkimPublic: 'secondaryDkim value', - requireTls: 'requireTls value', - skipVerification: 'skipVerification value', - timeZoneLocalize: 'timeZoneLocalize value', - tracking: 'tracking value', - trackingClicks: 'trackingClicks value', - trackingOpens: 'trackingOpens value', - trackingPixelLocationTop: 'trackingPixelLocationTop value', + secondaryDkimPublic: 'secondaryDkimPublic value', + requireTls: false, + skipVerification: true, + timeZoneLocalize: '02:00PM', + tracking: 'htmlonly', + trackingClicks: 'htmlonly', + trackingOpens: 'yes', + trackingPixelLocationTop: 'no', isTestMode: false, }, 'h:X-Mailgun-Sending-Ip-Pool': 'xx.xx.xxx.x', @@ -43,12 +43,12 @@ export const sendEmailRequestWithTemplate: Mailgun.SendEmailRequest = { subject: 'subject value', text: 'text value', template: 'template value', - amp_html: 'amp_html value', + ampHtml: 'amp_html value', attachment: 'attachment value', inline: 'inline value', templateProperties: { version: 'version value', - text: 'text value', + text: 'yes', variables: 'variables value', }, overrideProperties: { @@ -56,17 +56,17 @@ export const sendEmailRequestWithTemplate: Mailgun.SendEmailRequest = { sendingIp: 'sendingIp value', sendingIpPool: 'sendingIpPool value', deliveryTime: 'deliveryTime value', - deliveryTimeOptimizePeriod: 'deliveryTimeOptimizePeriod value', - enableDkimSignature: 'enableDkimSignature value', + deliveryTimeOptimizePeriod: 36, + enableDkimSignature: true, secondaryDkim: 'secondaryDkim value', - secondaryDkimPublic: 'secondaryDkim value', - requireTls: 'requireTls value', - skipVerification: 'skipVerification value', - timeZoneLocalize: 'timeZoneLocalize value', - tracking: 'tracking value', - trackingClicks: 'trackingClicks value', - trackingOpens: 'trackingOpens value', - trackingPixelLocationTop: 'trackingPixelLocationTop value', + secondaryDkimPublic: 'secondaryDkimPublic value', + requireTls: 'yes', + skipVerification: 'no', + timeZoneLocalize: '04:15AM', + tracking: 'yes', + trackingClicks: 'no', + trackingOpens: true, + trackingPixelLocationTop: false, isTestMode: false, }, 'h:X-Mailgun-Sending-Ip-Pool': 'xx.xx.xxx.x', diff --git a/packages/mailgun/tests/models/v1/emails/request/send-email-request.test.ts b/packages/mailgun/tests/models/v1/emails/request/send-email-request.test.ts index e1965fa..f423e8d 100644 --- a/packages/mailgun/tests/models/v1/emails/request/send-email-request.test.ts +++ b/packages/mailgun/tests/models/v1/emails/request/send-email-request.test.ts @@ -1,9 +1,8 @@ import FormData = require('form-data'); -import { Mailgun } from '../../../../../src'; +import { sendEmailRequestWithHtml, sendEmailRequestWithTemplate } from './send-email-request.models'; import { transformSendEmailRequestIntoApiRequestBody, -} from '../../../../../src/models'; -import { sendEmailRequestWithHtml, sendEmailRequestWithTemplate } from './send-email-request.models'; +} from '../../../../../src/models/v1/emails/request/send-email-request/send-email-request.transform'; describe('SendEmailRequest', () => { @@ -20,140 +19,74 @@ describe('SendEmailRequest', () => { it('should transform a client object using HTML into an API object', () => { transformSendEmailRequestIntoApiRequestBody(sendEmailRequestWithHtml); expect(appendSpy).toHaveBeenCalledTimes(30); - expect(appendSpy).toHaveBeenCalledWith('from', - sendEmailRequestWithHtml.from); - expect(appendSpy).toHaveBeenCalledWith('to', - sendEmailRequestWithHtml.to); - expect(appendSpy).toHaveBeenCalledWith('cc', - sendEmailRequestWithHtml.cc); - expect(appendSpy).toHaveBeenCalledWith('bcc', - sendEmailRequestWithHtml.bcc); - expect(appendSpy).toHaveBeenCalledWith('subject', - sendEmailRequestWithHtml.subject); - expect(appendSpy).toHaveBeenCalledWith('text', - sendEmailRequestWithHtml.text); - expect(appendSpy).toHaveBeenCalledWith('html', - sendEmailRequestWithHtml.html); - expect(appendSpy).toHaveBeenCalledWith('amp-html', - sendEmailRequestWithHtml.amp_html); - expect(appendSpy).toHaveBeenCalledWith('attachment', - sendEmailRequestWithHtml.attachment); - expect(appendSpy).toHaveBeenCalledWith('inline', - sendEmailRequestWithHtml.inline); - expect(appendSpy).toHaveBeenCalledWith('o:tag', - sendEmailRequestWithHtml.overrideProperties?.tag); - expect(appendSpy).toHaveBeenCalledWith('o:sending-ip', - sendEmailRequestWithHtml.overrideProperties?.sendingIp); - expect(appendSpy).toHaveBeenCalledWith('o:sending-ip-pool', - sendEmailRequestWithHtml.overrideProperties?.sendingIpPool); - expect(appendSpy).toHaveBeenCalledWith('o:deliverytime', - sendEmailRequestWithHtml.overrideProperties?.deliveryTime); - expect(appendSpy).toHaveBeenCalledWith('o:deliverytime-optimize-period', - sendEmailRequestWithHtml.overrideProperties?.deliveryTimeOptimizePeriod); - expect(appendSpy).toHaveBeenCalledWith('o:dkim', - sendEmailRequestWithHtml.overrideProperties?.enableDkimSignature); - expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim', - sendEmailRequestWithHtml.overrideProperties?.secondaryDkim); - expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim-public', - sendEmailRequestWithHtml.overrideProperties?.secondaryDkimPublic); - expect(appendSpy).toHaveBeenCalledWith('o:require-tls', - sendEmailRequestWithHtml.overrideProperties?.requireTls); - expect(appendSpy).toHaveBeenCalledWith('o:skip-verification', - sendEmailRequestWithHtml.overrideProperties?.skipVerification); - expect(appendSpy).toHaveBeenCalledWith('o:time-zone-localize', - sendEmailRequestWithHtml.overrideProperties?.timeZoneLocalize); - expect(appendSpy).toHaveBeenCalledWith('o:tracking', - sendEmailRequestWithHtml.overrideProperties?.tracking); - expect(appendSpy).toHaveBeenCalledWith('o:tracking-opens', - sendEmailRequestWithHtml.overrideProperties?.trackingOpens); - expect(appendSpy).toHaveBeenCalledWith('o:tracking-clicks', - sendEmailRequestWithHtml.overrideProperties?.trackingClicks); - expect(appendSpy).toHaveBeenCalledWith('o:tracking-pixel-location-top', - sendEmailRequestWithHtml.overrideProperties?.trackingPixelLocationTop); - expect(appendSpy).toHaveBeenCalledWith('o:testmode', - sendEmailRequestWithHtml.overrideProperties?.isTestMode); - expect(appendSpy).toHaveBeenCalledWith('h:X-Mailgun-Sending-Ip-Pool', - sendEmailRequestWithHtml['h:X-Mailgun-Sending-Ip-Pool']); - expect(appendSpy).toHaveBeenCalledWith('v:first_name', - sendEmailRequestWithHtml['v:first_name']); - expect(appendSpy).toHaveBeenCalledWith('v:last_name', - sendEmailRequestWithHtml['v:last_name']); - expect(appendSpy).toHaveBeenCalledWith('v:my_message_id', - sendEmailRequestWithHtml['v:my_message_id']); + expect(appendSpy).toHaveBeenCalledWith('from', 'from value'); + expect(appendSpy).toHaveBeenCalledWith('to', 'to value'); + expect(appendSpy).toHaveBeenCalledWith('cc', 'cc value'); + expect(appendSpy).toHaveBeenCalledWith('bcc', 'bcc value'); + expect(appendSpy).toHaveBeenCalledWith('subject', 'subject value'); + expect(appendSpy).toHaveBeenCalledWith('text', 'text value'); + expect(appendSpy).toHaveBeenCalledWith('html', 'html value'); + expect(appendSpy).toHaveBeenCalledWith('amp-html', 'amp_html value'); + expect(appendSpy).toHaveBeenCalledWith('attachment', 'attachment value'); + expect(appendSpy).toHaveBeenCalledWith('inline', 'inline value'); + expect(appendSpy).toHaveBeenCalledWith('o:tag', 'tag value'); + expect(appendSpy).toHaveBeenCalledWith('o:sending-ip', 'sendingIp value'); + expect(appendSpy).toHaveBeenCalledWith('o:sending-ip-pool', 'sendingIpPool value'); + expect(appendSpy).toHaveBeenCalledWith('o:deliverytime', 'deliveryTime value'); + expect(appendSpy).toHaveBeenCalledWith('o:deliverytime-optimize-period', '24h'); + expect(appendSpy).toHaveBeenCalledWith('o:dkim', 'yes'); + expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim', 'secondaryDkim value'); + expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim-public', 'secondaryDkimPublic value'); + expect(appendSpy).toHaveBeenCalledWith('o:require-tls', 'false'); + expect(appendSpy).toHaveBeenCalledWith('o:skip-verification', 'true'); + expect(appendSpy).toHaveBeenCalledWith('o:time-zone-localize', '02:00PM'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking', 'htmlonly'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking-clicks', 'htmlonly'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking-opens', 'yes'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking-pixel-location-top', 'no'); + expect(appendSpy).toHaveBeenCalledWith('o:testmode', 'false'); + expect(appendSpy).toHaveBeenCalledWith('h:X-Mailgun-Sending-Ip-Pool', 'xx.xx.xxx.x'); + expect(appendSpy).toHaveBeenCalledWith('v:first_name', 'John'); + expect(appendSpy).toHaveBeenCalledWith('v:last_name', 'Smith'); + expect(appendSpy).toHaveBeenCalledWith('v:my_message_id', '123'); }); it('should transform a client object using a template into an API object', () => { transformSendEmailRequestIntoApiRequestBody(sendEmailRequestWithTemplate); expect(appendSpy).toHaveBeenCalledTimes(33); - expect(appendSpy).toHaveBeenCalledWith('from', - sendEmailRequestWithTemplate.from); - expect(appendSpy).toHaveBeenCalledWith('to', - sendEmailRequestWithTemplate.to); - expect(appendSpy).toHaveBeenCalledWith('cc', - sendEmailRequestWithTemplate.cc); - expect(appendSpy).toHaveBeenCalledWith('bcc', - sendEmailRequestWithTemplate.bcc); - expect(appendSpy).toHaveBeenCalledWith('subject', - sendEmailRequestWithTemplate.subject); - expect(appendSpy).toHaveBeenCalledWith('text', - sendEmailRequestWithTemplate.text); - expect(appendSpy).toHaveBeenCalledWith('template', - sendEmailRequestWithTemplate.template); - expect(appendSpy).toHaveBeenCalledWith('amp-html', - sendEmailRequestWithTemplate.amp_html); - expect(appendSpy).toHaveBeenCalledWith('attachment', - sendEmailRequestWithTemplate.attachment); - expect(appendSpy).toHaveBeenCalledWith('inline', - sendEmailRequestWithTemplate.inline); - expect(appendSpy).toHaveBeenCalledWith('o:tag', - sendEmailRequestWithTemplate.overrideProperties?.tag); - expect(appendSpy).toHaveBeenCalledWith('o:sending-ip', - sendEmailRequestWithTemplate.overrideProperties?.sendingIp); - expect(appendSpy).toHaveBeenCalledWith('o:sending-ip-pool', - sendEmailRequestWithTemplate.overrideProperties?.sendingIpPool); - expect(appendSpy).toHaveBeenCalledWith('o:deliverytime', - sendEmailRequestWithTemplate.overrideProperties?.deliveryTime); - expect(appendSpy).toHaveBeenCalledWith('o:deliverytime-optimize-period', - sendEmailRequestWithTemplate.overrideProperties?.deliveryTimeOptimizePeriod); - expect(appendSpy).toHaveBeenCalledWith('o:dkim', - sendEmailRequestWithTemplate.overrideProperties?.enableDkimSignature); - expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim', - sendEmailRequestWithTemplate.overrideProperties?.secondaryDkim); - expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim-public', - sendEmailRequestWithTemplate.overrideProperties?.secondaryDkimPublic); - expect(appendSpy).toHaveBeenCalledWith('o:require-tls', - sendEmailRequestWithTemplate.overrideProperties?.requireTls); - expect(appendSpy).toHaveBeenCalledWith('o:skip-verification', - sendEmailRequestWithTemplate.overrideProperties?.skipVerification); - expect(appendSpy).toHaveBeenCalledWith('o:time-zone-localize', - sendEmailRequestWithTemplate.overrideProperties?.timeZoneLocalize); - expect(appendSpy).toHaveBeenCalledWith('o:tracking', - sendEmailRequestWithTemplate.overrideProperties?.tracking); - expect(appendSpy).toHaveBeenCalledWith('o:tracking-opens', - sendEmailRequestWithTemplate.overrideProperties?.trackingOpens); - expect(appendSpy).toHaveBeenCalledWith('o:tracking-clicks', - sendEmailRequestWithTemplate.overrideProperties?.trackingClicks); - expect(appendSpy).toHaveBeenCalledWith('o:tracking-pixel-location-top', - sendEmailRequestWithTemplate.overrideProperties?.trackingPixelLocationTop); - expect(appendSpy).toHaveBeenCalledWith('o:testmode', - sendEmailRequestWithTemplate.overrideProperties?.isTestMode); - expect(appendSpy).toHaveBeenCalledWith('t:text', - // eslint-disable-next-line max-len - (sendEmailRequestWithTemplate as Mailgun.MessageContentWhereHtmlContentCanBeFromTemplateOnly).templateProperties?.text); - expect(appendSpy).toHaveBeenCalledWith('t:version', - // eslint-disable-next-line max-len - (sendEmailRequestWithTemplate as Mailgun.MessageContentWhereHtmlContentCanBeFromTemplateOnly).templateProperties?.version); - expect(appendSpy).toHaveBeenCalledWith('t:variables', - // eslint-disable-next-line max-len - (sendEmailRequestWithTemplate as Mailgun.MessageContentWhereHtmlContentCanBeFromTemplateOnly).templateProperties?.variables); - expect(appendSpy).toHaveBeenCalledWith('h:X-Mailgun-Sending-Ip-Pool', - sendEmailRequestWithTemplate['h:X-Mailgun-Sending-Ip-Pool']); - expect(appendSpy).toHaveBeenCalledWith('v:first_name', - sendEmailRequestWithTemplate['v:first_name']); - expect(appendSpy).toHaveBeenCalledWith('v:last_name', - sendEmailRequestWithTemplate['v:last_name']); - expect(appendSpy).toHaveBeenCalledWith('v:my_message_id', - sendEmailRequestWithTemplate['v:my_message_id']); + expect(appendSpy).toHaveBeenCalledWith('from', 'from value'); + expect(appendSpy).toHaveBeenCalledWith('to', 'to value'); + expect(appendSpy).toHaveBeenCalledWith('cc', 'cc value'); + expect(appendSpy).toHaveBeenCalledWith('bcc', 'bcc value'); + expect(appendSpy).toHaveBeenCalledWith('subject', 'subject value'); + expect(appendSpy).toHaveBeenCalledWith('text', 'text value'); + expect(appendSpy).toHaveBeenCalledWith('template', 'template value'); + expect(appendSpy).toHaveBeenCalledWith('amp-html', 'amp_html value'); + expect(appendSpy).toHaveBeenCalledWith('attachment', 'attachment value'); + expect(appendSpy).toHaveBeenCalledWith('inline', 'inline value'); + expect(appendSpy).toHaveBeenCalledWith('o:tag', 'tag value'); + expect(appendSpy).toHaveBeenCalledWith('o:sending-ip', 'sendingIp value'); + expect(appendSpy).toHaveBeenCalledWith('o:sending-ip-pool', 'sendingIpPool value'); + expect(appendSpy).toHaveBeenCalledWith('o:deliverytime', 'deliveryTime value'); + expect(appendSpy).toHaveBeenCalledWith('o:deliverytime-optimize-period', '36h'); + expect(appendSpy).toHaveBeenCalledWith('o:dkim', 'true'); + expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim', 'secondaryDkim value'); + expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim-public', 'secondaryDkimPublic value'); + expect(appendSpy).toHaveBeenCalledWith('o:require-tls', 'yes'); + expect(appendSpy).toHaveBeenCalledWith('o:skip-verification', 'no'); + expect(appendSpy).toHaveBeenCalledWith('o:time-zone-localize', '04:15AM'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking', 'yes'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking-clicks', 'no'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking-opens', 'true'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking-pixel-location-top', 'false'); + expect(appendSpy).toHaveBeenCalledWith('o:testmode', 'false'); + expect(appendSpy).toHaveBeenCalledWith('t:text', 'yes'); + expect(appendSpy).toHaveBeenCalledWith('t:version', 'version value'); + expect(appendSpy).toHaveBeenCalledWith('t:variables', 'variables value'); + expect(appendSpy).toHaveBeenCalledWith('h:X-Mailgun-Sending-Ip-Pool', 'xx.xx.xxx.x'); + expect(appendSpy).toHaveBeenCalledWith('v:first_name', 'John'); + expect(appendSpy).toHaveBeenCalledWith('v:last_name', 'Smith'); + expect(appendSpy).toHaveBeenCalledWith('v:my_message_id', '123'); }); }); diff --git a/packages/mailgun/tests/models/v1/emails/request/send-mime-email-request.models.ts b/packages/mailgun/tests/models/v1/emails/request/send-mime-email-request.models.ts index 345d530..2188c21 100644 --- a/packages/mailgun/tests/models/v1/emails/request/send-mime-email-request.models.ts +++ b/packages/mailgun/tests/models/v1/emails/request/send-mime-email-request.models.ts @@ -6,7 +6,7 @@ export const sendMimeEmailRequest: Mailgun.SendMimeEmailRequest = { template: 'template value', templateProperties: { version: 'version value', - text: 'text value', + text: 'yes', variables: 'variables value', }, overrideProperties: { @@ -14,17 +14,17 @@ export const sendMimeEmailRequest: Mailgun.SendMimeEmailRequest = { sendingIp: 'sendingIp value', sendingIpPool: 'sendingIpPool value', deliveryTime: 'deliveryTime value', - deliveryTimeOptimizePeriod: 'deliveryTimeOptimizePeriod value', - enableDkimSignature: 'enableDkimSignature value', + deliveryTimeOptimizePeriod: 72, + enableDkimSignature: false, secondaryDkim: 'secondaryDkim value', - secondaryDkimPublic: 'secondaryDkim value', - requireTls: 'requireTls value', - skipVerification: 'skipVerification value', - timeZoneLocalize: 'timeZoneLocalize value', - tracking: 'tracking value', - trackingClicks: 'trackingClicks value', - trackingOpens: 'trackingOpens value', - trackingPixelLocationTop: 'trackingPixelLocationTop value', + secondaryDkimPublic: 'secondaryDkimPublic value', + requireTls: false, + skipVerification: false, + timeZoneLocalize: '12:00PM', + tracking: 'no', + trackingClicks: 'no', + trackingOpens: 'no', + trackingPixelLocationTop: 'no', isTestMode: false, }, 'h:X-Mailgun-Sending-Ip-Pool': 'xx.xx.xxx.x', diff --git a/packages/mailgun/tests/models/v1/emails/request/send-mime-email-request.test.ts b/packages/mailgun/tests/models/v1/emails/request/send-mime-email-request.test.ts index 12b57af..2e6fb6b 100644 --- a/packages/mailgun/tests/models/v1/emails/request/send-mime-email-request.test.ts +++ b/packages/mailgun/tests/models/v1/emails/request/send-mime-email-request.test.ts @@ -1,6 +1,8 @@ import FormData = require('form-data'); -import { transformSendMimeEmailRequestIntoApiRequestBody } from '../../../../../src/models'; import { sendMimeEmailRequest } from './send-mime-email-request.models'; +import { + transformSendMimeEmailRequestIntoApiRequestBody, +} from '../../../../../src/models/v1/emails/request/send-mime-email-request/send-mime-email-request.transform'; describe('SendMimeEmailRequest', () => { @@ -8,56 +10,31 @@ describe('SendMimeEmailRequest', () => { const appendSpy = jest.spyOn(FormData.prototype, 'append'); transformSendMimeEmailRequestIntoApiRequestBody(sendMimeEmailRequest); expect(appendSpy).toHaveBeenCalledTimes(26); - expect(appendSpy).toHaveBeenCalledWith('to', - sendMimeEmailRequest.to); - expect(appendSpy).toHaveBeenCalledWith('template', - sendMimeEmailRequest.template); - expect(appendSpy).toHaveBeenCalledWith('o:tag', - sendMimeEmailRequest.overrideProperties?.tag); - expect(appendSpy).toHaveBeenCalledWith('o:sending-ip', - sendMimeEmailRequest.overrideProperties?.sendingIp); - expect(appendSpy).toHaveBeenCalledWith('o:sending-ip-pool', - sendMimeEmailRequest.overrideProperties?.sendingIpPool); - expect(appendSpy).toHaveBeenCalledWith('o:deliverytime', - sendMimeEmailRequest.overrideProperties?.deliveryTime); - expect(appendSpy).toHaveBeenCalledWith('o:deliverytime-optimize-period', - sendMimeEmailRequest.overrideProperties?.deliveryTimeOptimizePeriod); - expect(appendSpy).toHaveBeenCalledWith('o:dkim', - sendMimeEmailRequest.overrideProperties?.enableDkimSignature); - expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim', - sendMimeEmailRequest.overrideProperties?.secondaryDkim); - expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim-public', - sendMimeEmailRequest.overrideProperties?.secondaryDkimPublic); - expect(appendSpy).toHaveBeenCalledWith('o:require-tls', - sendMimeEmailRequest.overrideProperties?.requireTls); - expect(appendSpy).toHaveBeenCalledWith('o:skip-verification', - sendMimeEmailRequest.overrideProperties?.skipVerification); - expect(appendSpy).toHaveBeenCalledWith('o:time-zone-localize', - sendMimeEmailRequest.overrideProperties?.timeZoneLocalize); - expect(appendSpy).toHaveBeenCalledWith('o:tracking', - sendMimeEmailRequest.overrideProperties?.tracking); - expect(appendSpy).toHaveBeenCalledWith('o:tracking-opens', - sendMimeEmailRequest.overrideProperties?.trackingOpens); - expect(appendSpy).toHaveBeenCalledWith('o:tracking-clicks', - sendMimeEmailRequest.overrideProperties?.trackingClicks); - expect(appendSpy).toHaveBeenCalledWith('o:tracking-pixel-location-top', - sendMimeEmailRequest.overrideProperties?.trackingPixelLocationTop); - expect(appendSpy).toHaveBeenCalledWith('o:testmode', - sendMimeEmailRequest.overrideProperties?.isTestMode); - expect(appendSpy).toHaveBeenCalledWith('t:text', - sendMimeEmailRequest.templateProperties?.text); - expect(appendSpy).toHaveBeenCalledWith('t:version', - sendMimeEmailRequest.templateProperties?.version); - expect(appendSpy).toHaveBeenCalledWith('t:variables', - sendMimeEmailRequest.templateProperties?.variables); - expect(appendSpy).toHaveBeenCalledWith('h:X-Mailgun-Sending-Ip-Pool', - sendMimeEmailRequest['h:X-Mailgun-Sending-Ip-Pool']); - expect(appendSpy).toHaveBeenCalledWith('v:first_name', - sendMimeEmailRequest['v:first_name']); - expect(appendSpy).toHaveBeenCalledWith('v:last_name', - sendMimeEmailRequest['v:last_name']); - expect(appendSpy).toHaveBeenCalledWith('v:my_message_id', - sendMimeEmailRequest['v:my_message_id']); + expect(appendSpy).toHaveBeenCalledWith('to', 'to value'); + expect(appendSpy).toHaveBeenCalledWith('template', 'template value'); + expect(appendSpy).toHaveBeenCalledWith('o:tag', 'tag value'); + expect(appendSpy).toHaveBeenCalledWith('o:sending-ip', 'sendingIp value'); + expect(appendSpy).toHaveBeenCalledWith('o:sending-ip-pool', 'sendingIpPool value'); + expect(appendSpy).toHaveBeenCalledWith('o:deliverytime', 'deliveryTime value'); + expect(appendSpy).toHaveBeenCalledWith('o:deliverytime-optimize-period', '72h'); + expect(appendSpy).toHaveBeenCalledWith('o:dkim', 'false'); + expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim', 'secondaryDkim value'); + expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim-public', 'secondaryDkimPublic value'); + expect(appendSpy).toHaveBeenCalledWith('o:require-tls', 'false'); + expect(appendSpy).toHaveBeenCalledWith('o:skip-verification', 'false'); + expect(appendSpy).toHaveBeenCalledWith('o:time-zone-localize', '12:00PM'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking', 'no'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking-opens', 'no'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking-clicks', 'no'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking-pixel-location-top', 'no'); + expect(appendSpy).toHaveBeenCalledWith('o:testmode', 'false'); + expect(appendSpy).toHaveBeenCalledWith('t:text', 'yes'); + expect(appendSpy).toHaveBeenCalledWith('t:version', 'version value'); + expect(appendSpy).toHaveBeenCalledWith('t:variables', 'variables value'); + expect(appendSpy).toHaveBeenCalledWith('h:X-Mailgun-Sending-Ip-Pool', 'xx.xx.xxx.x'); + expect(appendSpy).toHaveBeenCalledWith('v:first_name', 'John'); + expect(appendSpy).toHaveBeenCalledWith('v:last_name', 'Smith'); + expect(appendSpy).toHaveBeenCalledWith('v:my_message_id', '123'); }); }); diff --git a/packages/mailgun/tests/models/v1/emails/response/bad-request.models.ts b/packages/mailgun/tests/models/v1/emails/response/bad-request.models.ts index ec9a2d7..fa0206d 100644 --- a/packages/mailgun/tests/models/v1/emails/response/bad-request.models.ts +++ b/packages/mailgun/tests/models/v1/emails/response/bad-request.models.ts @@ -1,6 +1,7 @@ import { Mailgun } from '../../../../../src'; +import { BadRequestFromApi } from '../../../../../src/models/v1/emails/response/bad-request/bad-request'; -export const badRequestFromApi: Mailgun.BadRequestFromApi = { +export const badRequestFromApi: BadRequestFromApi = { message: 'Invalid storage key', }; diff --git a/packages/mailgun/tests/models/v1/emails/response/bad-request.test.ts b/packages/mailgun/tests/models/v1/emails/response/bad-request.test.ts index 8c9733e..1e5bf8f 100644 --- a/packages/mailgun/tests/models/v1/emails/response/bad-request.test.ts +++ b/packages/mailgun/tests/models/v1/emails/response/bad-request.test.ts @@ -1,7 +1,5 @@ -import { - transformBadRequestIntoClientResponse, -} from '../../../../../src/models'; import { badRequest, badRequestFromApi } from './bad-request.models'; +import { transformBadRequestIntoClientResponse } from '../../../../../src/models/v1/emails/response/bad-request/bad-request.transform'; describe('BadRequest', () => { diff --git a/packages/mailgun/tests/models/v1/emails/response/email-not-found.models.ts b/packages/mailgun/tests/models/v1/emails/response/email-not-found.models.ts index 5b188ed..6d5140d 100644 --- a/packages/mailgun/tests/models/v1/emails/response/email-not-found.models.ts +++ b/packages/mailgun/tests/models/v1/emails/response/email-not-found.models.ts @@ -1,6 +1,7 @@ import { Mailgun } from '../../../../../src'; +import { EmailNotFoundFromApi } from '../../../../../src/models/v1/emails/response/email-not-found/email-not-found'; -export const emailNotFoundFromApi: Mailgun.EmailNotFoundFromApi = { +export const emailNotFoundFromApi: EmailNotFoundFromApi = { message: 'Message not found', }; diff --git a/packages/mailgun/tests/models/v1/emails/response/email-not-found.test.ts b/packages/mailgun/tests/models/v1/emails/response/email-not-found.test.ts index 1ecb09c..fccf2a9 100644 --- a/packages/mailgun/tests/models/v1/emails/response/email-not-found.test.ts +++ b/packages/mailgun/tests/models/v1/emails/response/email-not-found.test.ts @@ -1,7 +1,5 @@ -import { - transformEmailNotFoundIntoClientResponse, -} from '../../../../../src/models'; import { emailNotFound, emailNotFoundFromApi } from './email-not-found.models'; +import { transformEmailNotFoundIntoClientResponse } from '../../../../../src/models/v1/emails/response/email-not-found/email-not-found.transform'; describe('EmailNotFound', () => { diff --git a/packages/mailgun/tests/models/v1/emails/response/generic-response.models.ts b/packages/mailgun/tests/models/v1/emails/response/generic-response.models.ts index e6f1458..79447d8 100644 --- a/packages/mailgun/tests/models/v1/emails/response/generic-response.models.ts +++ b/packages/mailgun/tests/models/v1/emails/response/generic-response.models.ts @@ -1,6 +1,7 @@ import { Mailgun } from '../../../../../src'; +import { GenericResponseFromApi } from '../../../../../src/models/v1/emails/response/generic-response/generic-response'; -export const genericResponseFromApi: Mailgun.GenericResponseFromApi = { +export const genericResponseFromApi: GenericResponseFromApi = { message: 'message value', }; diff --git a/packages/mailgun/tests/models/v1/emails/response/generic-response.test.ts b/packages/mailgun/tests/models/v1/emails/response/generic-response.test.ts index dd63968..358bd23 100644 --- a/packages/mailgun/tests/models/v1/emails/response/generic-response.test.ts +++ b/packages/mailgun/tests/models/v1/emails/response/generic-response.test.ts @@ -1,7 +1,7 @@ +import { genericResponse, genericResponseFromApi } from './generic-response.models'; import { transformGenericResponseIntoClientResponse, -} from '../../../../../src/models'; -import { genericResponse, genericResponseFromApi } from './generic-response.models'; +} from '../../../../../src/models/v1/emails/response/generic-response/generic-response.transform'; describe('GenericResponse', () => { diff --git a/packages/mailgun/tests/models/v1/emails/response/get-stored-email-response.models.ts b/packages/mailgun/tests/models/v1/emails/response/get-stored-email-response.models.ts index d8f0581..e01005a 100644 --- a/packages/mailgun/tests/models/v1/emails/response/get-stored-email-response.models.ts +++ b/packages/mailgun/tests/models/v1/emails/response/get-stored-email-response.models.ts @@ -1,6 +1,7 @@ import { Mailgun } from '../../../../../src'; +import { GetStoredEmailResponseFromApi } from '../../../../../src/models/v1/emails/response/get-email-response/get-stored-email-response'; -export const getStoredEmailResponseFromApi: Mailgun.GetStoredEmailResponseFromApi = { +export const getStoredEmailResponseFromApi: GetStoredEmailResponseFromApi = { 'X-Mailgun-Deliver-By': new Date('Wed, 06 Jun 2024 07:40:00 +0000'), subject: '"Mailgun is awesome"', Subject: '"Mailgun is awesome"', diff --git a/packages/mailgun/tests/models/v1/emails/response/get-stored-email-response.test.ts b/packages/mailgun/tests/models/v1/emails/response/get-stored-email-response.test.ts index 15d94a8..cb65c82 100644 --- a/packages/mailgun/tests/models/v1/emails/response/get-stored-email-response.test.ts +++ b/packages/mailgun/tests/models/v1/emails/response/get-stored-email-response.test.ts @@ -1,7 +1,7 @@ +import { getStoredEmailResponse, getStoredEmailResponseFromApi } from './get-stored-email-response.models'; import { transformGetEmailResponseIntoClientResponse, -} from '../../../../../src/models'; -import { getStoredEmailResponse, getStoredEmailResponseFromApi } from './get-stored-email-response.models'; +} from '../../../../../src/models/v1/emails/response/get-email-response/get-stored-email-response.transform'; describe('GetEmailResponse', () => { diff --git a/packages/mailgun/tests/models/v1/emails/response/send-email-response.models.ts b/packages/mailgun/tests/models/v1/emails/response/send-email-response.models.ts index 2d9cf7c..6ac1ca1 100644 --- a/packages/mailgun/tests/models/v1/emails/response/send-email-response.models.ts +++ b/packages/mailgun/tests/models/v1/emails/response/send-email-response.models.ts @@ -1,6 +1,7 @@ import { Mailgun } from '../../../../../src'; +import { SendEmailResponseFromApi } from '../../../../../src/models/v1/emails/response/send-email-response/send-email-response'; -export const sendEmailResponseFromApi: Mailgun.SendEmailResponseFromApi = { +export const sendEmailResponseFromApi: SendEmailResponseFromApi = { id: 'id value', message: 'Queued. Thank you.', }; diff --git a/packages/mailgun/tests/models/v1/emails/response/send-email-response.test.ts b/packages/mailgun/tests/models/v1/emails/response/send-email-response.test.ts index ca314a0..5434e32 100644 --- a/packages/mailgun/tests/models/v1/emails/response/send-email-response.test.ts +++ b/packages/mailgun/tests/models/v1/emails/response/send-email-response.test.ts @@ -1,12 +1,10 @@ +import { sendEmailResponse, sendEmailResponseFromApi } from './send-email-response.models'; import { transformSendEmailResponseIntoClientResponse, -} from '../../../../../src/models'; -import { sendEmailResponse, sendEmailResponseFromApi } from './send-email-response.models'; +} from '../../../../../src/models/v1/emails/response/send-email-response/send-email-response.transform'; describe('SendEmailResponse', () => { - - it('should convert an API object into a client object', () => { const transformedResponse = transformSendEmailResponseIntoClientResponse(sendEmailResponseFromApi); expect(transformedResponse).toEqual(sendEmailResponse); diff --git a/packages/mailgun/tests/models/v1/emails/response/sending-queues-status-response.models.ts b/packages/mailgun/tests/models/v1/emails/response/sending-queues-status-response.models.ts index 1ca11f0..ceeee2d 100644 --- a/packages/mailgun/tests/models/v1/emails/response/sending-queues-status-response.models.ts +++ b/packages/mailgun/tests/models/v1/emails/response/sending-queues-status-response.models.ts @@ -1,6 +1,9 @@ import { Mailgun } from '../../../../../src'; +import { + SendingQueuesStatusResponseFromApi, +} from '../../../../../src/models/v1/emails/response/sending-queues-status-response/sending-queues-status-response'; -export const sendingQueuesStatusResponseFromApi: Mailgun.SendingQueuesStatusResponseFromApi = { +export const sendingQueuesStatusResponseFromApi: SendingQueuesStatusResponseFromApi = { scheduled: { is_disabled: false, disabled: { diff --git a/packages/mailgun/tests/models/v1/emails/response/sending-queues-status-response.test.ts b/packages/mailgun/tests/models/v1/emails/response/sending-queues-status-response.test.ts index bee61aa..b4fe417 100644 --- a/packages/mailgun/tests/models/v1/emails/response/sending-queues-status-response.test.ts +++ b/packages/mailgun/tests/models/v1/emails/response/sending-queues-status-response.test.ts @@ -1,10 +1,11 @@ -import { - transformSendingQueuesStatusResponseIntoClientResponse, -} from '../../../../../src/models'; import { sendingQueuesStatusResponse, sendingQueuesStatusResponseFromApi, } from './sending-queues-status-response.models'; +import { + transformSendingQueuesStatusResponseIntoClientResponse, +// eslint-disable-next-line max-len +} from '../../../../../src/models/v1/emails/response/sending-queues-status-response/sending-queues-status-response.transform'; describe('SendingQueuesStatusResponse', () => {