-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEVEXP-642: Update types and refactor transformers (#151)
- Loading branch information
1 parent
37bd4a1
commit 55f2cc8
Showing
45 changed files
with
598 additions
and
578 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type YesNoEnum = boolean | 'yes' | 'no'; | ||
|
||
export type YesNoHtmlonlyEnum = YesNoEnum | 'htmlonly'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import FormData = require('form-data'); | ||
|
||
export const appendFilteredPropertiesToFormData = ( | ||
obj: Record<string, any>, | ||
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)); | ||
} | ||
} | ||
} | ||
}; |
57 changes: 57 additions & 0 deletions
57
...mailgun/src/models/v1/emails/request/override-properties/override-properties.transform.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'])); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...s/mailgun/src/models/v1/emails/request/send-email-request/send-email-request.transform.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...src/models/v1/emails/request/send-mime-email-request/send-mime-email-request.transform.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; |
Oops, something went wrong.