Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4606 from coasy/pieces/mailjet
feat(mailjet): send action
- Loading branch information
Showing
8 changed files
with
228 additions
and
0 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,33 @@ | ||
{ | ||
"extends": [ | ||
"../../../../.eslintrc.base.json" | ||
], | ||
"ignorePatterns": [ | ||
"!**/*" | ||
], | ||
"overrides": [ | ||
{ | ||
"files": [ | ||
"*.ts", | ||
"*.tsx", | ||
"*.js", | ||
"*.jsx" | ||
], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": [ | ||
"*.ts", | ||
"*.tsx" | ||
], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": [ | ||
"*.js", | ||
"*.jsx" | ||
], | ||
"rules": {} | ||
} | ||
] | ||
} |
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,7 @@ | ||
# pieces-mailjet | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Building | ||
|
||
Run `nx build pieces-mailjet` to build the library. |
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,4 @@ | ||
{ | ||
"name": "@activepieces/piece-mailjet", | ||
"version": "0.0.1" | ||
} |
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,38 @@ | ||
{ | ||
"name": "pieces-mailjet", | ||
"$schema": "../../../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "packages/pieces/community/mailjet/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "@nx/js:tsc", | ||
"outputs": [ | ||
"{options.outputPath}" | ||
], | ||
"options": { | ||
"outputPath": "dist/packages/pieces/community/mailjet", | ||
"tsConfig": "packages/pieces/community/mailjet/tsconfig.lib.json", | ||
"packageJson": "packages/pieces/community/mailjet/package.json", | ||
"main": "packages/pieces/community/mailjet/src/index.ts", | ||
"assets": [ | ||
"packages/pieces/community/mailjet/*.md" | ||
], | ||
"buildableProjectDepsInPackageJsonType": "dependencies", | ||
"updateBuildableProjectDepsInPackageJson": true | ||
} | ||
}, | ||
"publish": { | ||
"command": "node tools/scripts/publish.mjs pieces-mailjet {args.ver} {args.tag}", | ||
"dependsOn": [ | ||
"build" | ||
] | ||
}, | ||
"lint": { | ||
"executor": "@nx/eslint:lint", | ||
"outputs": [ | ||
"{options.outputFile}" | ||
] | ||
} | ||
}, | ||
"tags": [] | ||
} |
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,28 @@ | ||
import { createPiece, PieceAuth } from '@activepieces/pieces-framework'; | ||
import { PieceCategory } from '@activepieces/shared'; | ||
import { sendEmail } from './lib/actions/send-email'; | ||
|
||
export const mailjetAuth = PieceAuth.BasicAuth({ | ||
description: 'Enter your api credentials', | ||
required: true, | ||
username: { | ||
displayName: 'API Key', | ||
description: 'Enter your API Key here' | ||
}, | ||
password: { | ||
displayName: 'API Secret', | ||
description: 'Enter your API Secret here' | ||
} | ||
}); | ||
|
||
export const mailjet = createPiece({ | ||
displayName: 'Mailjet', | ||
description: 'Email delivery service for sending transactional and marketing emails', | ||
auth: mailjetAuth, | ||
minimumSupportedRelease: '0.20.0', | ||
logoUrl: 'https://cdn.activepieces.com/pieces/mailjet.svg', | ||
categories: [PieceCategory.COMMUNICATION], | ||
authors: ['christian-schab'], | ||
actions: [sendEmail], | ||
triggers: [] | ||
}); |
88 changes: 88 additions & 0 deletions
88
packages/pieces/community/mailjet/src/lib/actions/send-email.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,88 @@ | ||
import { createAction, Property } from '@activepieces/pieces-framework'; | ||
import { AuthenticationType, httpClient, HttpMethod, HttpRequest } from '@activepieces/pieces-common'; | ||
import { mailjetAuth } from '../../'; | ||
|
||
export const sendEmail = createAction({ | ||
auth: mailjetAuth, | ||
name: 'send_email', | ||
displayName: 'Send Email', | ||
description: 'Send a text, HTML or template email through Mailjet', | ||
props: { | ||
fromEmail: Property.ShortText({ | ||
displayName: 'From (Email)', | ||
description: 'Sender email, must be verified in Mailjet', | ||
required: true | ||
}), | ||
fromName: Property.ShortText({ | ||
displayName: 'From (Name)', | ||
required: false | ||
}), | ||
toEmails: Property.Array({ | ||
displayName: 'Emails of recipients', | ||
required: true | ||
}), | ||
subject: Property.ShortText({ | ||
displayName: 'Subject', | ||
description: undefined, | ||
required: true | ||
}), | ||
textPart: Property.LongText({ | ||
displayName: 'Text part', | ||
description: undefined, | ||
required: false | ||
}), | ||
htmlPart: Property.LongText({ | ||
displayName: 'HTML part', | ||
description: undefined, | ||
required: false | ||
}), | ||
templateId: Property.Number({ | ||
displayName: 'Template Id', | ||
description: 'Template Id (number) defined in Mailjet', | ||
required: false | ||
}), | ||
templateVariables: Property.Object({ | ||
displayName: 'Template variables', | ||
description: undefined, | ||
required: false | ||
}) | ||
}, | ||
async run(configValue) { | ||
const { propsValue, auth } = configValue; | ||
|
||
const message = { | ||
From: { | ||
Email: propsValue.fromEmail, | ||
Name: propsValue.fromName || propsValue.fromEmail | ||
}, | ||
To: propsValue.toEmails.map(to => ({ | ||
Email: to, | ||
Name: to | ||
})), | ||
Subject: propsValue.subject, | ||
TextPart: propsValue.textPart, | ||
TemplateID: propsValue.templateId, | ||
TemplateLanguage: !!propsValue.templateId, | ||
Variables: propsValue.templateVariables | ||
}; | ||
const request: HttpRequest<string> = { | ||
method: HttpMethod.POST, | ||
url: `https://api.mailjet.com/v3.1/send`, | ||
body: JSON.stringify({ messages: [message] }), | ||
authentication: { | ||
type: AuthenticationType.BASIC, | ||
username: auth.username, | ||
password: auth.password | ||
}, | ||
queryParams: {} | ||
}; | ||
|
||
const response = await httpClient.sendRequest(request); | ||
|
||
if (response.status !== 200) { | ||
throw new Error(`Failed to communicate with Mailjet`); | ||
} else { | ||
return response.body.Messages[0]; | ||
} | ||
} | ||
}); |
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,19 @@ | ||
{ | ||
"extends": "../../../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"noImplicitOverride": true, | ||
"noPropertyAccessFromIndexSignature": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
} | ||
] | ||
} |
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,11 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"outDir": "../../../../dist/out-tsc", | ||
"declaration": true, | ||
"types": ["node"] | ||
}, | ||
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"], | ||
"include": ["src/**/*.ts"] | ||
} |