Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
asein-sinch committed Dec 15, 2024
1 parent b7c1b4a commit e522331
Show file tree
Hide file tree
Showing 55 changed files with 390 additions and 346 deletions.
2 changes: 1 addition & 1 deletion packages/mailgun/src/models/v1/emails/request/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const appendFilteredPropertiesToFormData = (
for (const [key, value] of Object.entries(obj)) {
if (key.startsWith(prefix) && value != null) {
if (value instanceof Date) {
formData.append(key, value.toISOString());
formData.append(key, value.toUTCString());
} else {
formData.append(key, String(value));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export type { OverrideProperties } from './override-properties';
export { appendOverridePropertiesToFormData } from './override-properties';
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']));
}
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { YesNoEnum, YesNoHtmlonlyEnum } from '../enum';
import FormData = require('form-data');

export interface OverrideProperties {
/** Tag string. See **Tagging** for more information */
Expand Down Expand Up @@ -35,54 +34,3 @@ export interface OverrideProperties {
/** Enables sending in test mode. Pass `yes` if needed. See **Sending in Test Mode** */
isTestMode?: YesNoEnum;
}

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']));
}
};
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export type { SendEmailRequest } from './send-email-request';
export { transformSendEmailRequestIntoApiRequestBody } from './send-email-request';
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;
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { appendTemplatePropertiesToFormData, TemplateProperties } from '../template-properties';
import { appendOverridePropertiesToFormData, OverrideProperties } from '../override-properties';
import { appendFilteredPropertiesToFormData } from '../helper';
import FormData = require('form-data');
import { TemplateProperties } from '../template-properties';
import { OverrideProperties } from '../override-properties';


export type MessageContentWithHtmlInline = {
/** Body of the message (HTML version) */
Expand Down Expand Up @@ -35,7 +34,7 @@ export interface CommonEmailProperties {
/** Body of the message (text version) */
text?: string;
/** AMP part of the message. Please follow Google guidelines to compose and send AMP emails */
amp_html?: string;
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 */
Expand All @@ -50,49 +49,3 @@ export interface CommonEmailProperties {

export type SendEmailRequest = MessageContentWithHtmlInline
| MessageContentWithHtmlInTemplate;

export const transformSendEmailRequestIntoApiRequestBody = (sdkRequest: SendEmailRequest): FormData => {
const formData = new FormData();
if (sdkRequest['html'] != null) {
formData.append('html', sdkRequest['html']);
}
if (sdkRequest['amp_html'] != null) {
formData.append('amp-html', sdkRequest['amp_html']);
}
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;
};
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export type { SendMimeEmailRequest } from './send-mime-email-request';
export { transformSendMimeEmailRequestIntoApiRequestBody } from './send-mime-email-request';
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;
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { appendTemplatePropertiesToFormData, TemplateProperties } from '../template-properties';
import { appendOverridePropertiesToFormData, OverrideProperties } from '../override-properties';
import { appendFilteredPropertiesToFormData } from '../helper';
import FormData = require('form-data');
import { TemplateProperties } from '../template-properties';
import { OverrideProperties } from '../override-properties';

export interface SendMimeEmailRequest {
/** MIME string of the message. Make sure to use `multipart/form-data` content type to send this as a file upload */
Expand All @@ -22,24 +20,3 @@ export interface SendMimeEmailRequest {
[key: `v:${string}`]: string | number;
}

export const transformSendMimeEmailRequestIntoApiRequestBody = (sdkRequest: SendMimeEmailRequest): FormData => {
const formData = new FormData();
if (sdkRequest['to'] != null) {
formData.append('to', sdkRequest['to']);
}
if ('message' in sdkRequest && sdkRequest['message'] != null) {
formData.append('message', sdkRequest['message'], { filename: 'MimeMessage' });
}
if ('template' in sdkRequest && 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;
};
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export type { TemplateProperties } from './template-properties';
export { appendTemplatePropertiesToFormData } from './template-properties';
Original file line number Diff line number Diff line change
@@ -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']);
}
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import FormData = require('form-data');
import { YesNoEnum } from '../enum';

export interface TemplateProperties {
Expand All @@ -10,14 +9,3 @@ export interface TemplateProperties {
variables?: string;
}

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']);
}
};
Original file line number Diff line number Diff line change
@@ -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;
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,3 @@ export type BadRequest = Omit<BadRequestFromApi, never>;
export interface BadRequestFromApi {
message: string;
}

export const transformBadRequestIntoClientResponse = (
apiResponse: BadRequestFromApi,
): BadRequest => {
const {
...response
} = apiResponse;
return response;
};
Loading

0 comments on commit e522331

Please sign in to comment.