Compare commits

..

15 Commits

Author SHA1 Message Date
f3591bdc67 1.0.13 2020-01-11 11:13:41 +00:00
ece9508161 fix(core): update 2020-01-11 11:13:41 +00:00
761d7e78de 1.0.12 2020-01-11 11:11:49 +00:00
0c44cf09b4 fix(core): update 2020-01-11 11:11:48 +00:00
aee7c80e26 1.0.11 2019-10-28 16:15:16 +01:00
c60702fb49 fix(core): update 2019-10-28 16:15:16 +01:00
354c38a429 1.0.10 2019-10-28 16:10:20 +01:00
f477cad6e9 fix(core): update 2019-10-28 16:10:20 +01:00
631aaadb43 1.0.9 2019-10-28 16:07:15 +01:00
a831cf7e9a fix(core): update 2019-10-28 16:07:14 +01:00
e6125c9a13 1.0.8 2019-10-28 15:57:11 +01:00
a203965e29 1.0.7 2019-10-28 15:55:04 +01:00
4305b53e35 fix(core): update 2019-10-28 15:55:04 +01:00
b7c657a930 1.0.6 2019-10-27 22:53:22 +01:00
0a758cdb60 fix(core): update 2019-10-27 22:53:21 +01:00
7 changed files with 93 additions and 20 deletions

8
.gitlab-webide.yml Normal file
View File

@ -0,0 +1,8 @@
terminal:
image: registry.gitlab.com/hosttoday/ht-docker-node
before_script:
- npm install -g npm-check
variables:
RAILS_ENV: "test"
NODE_ENV: "test"

24
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@mojoio/mailgun",
"version": "1.0.5",
"version": "1.0.13",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -113,6 +113,16 @@
"symbol-tree": "^3.2.4"
}
},
"@pushrocks/qenv": {
"version": "4.0.6",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fqenv/-/qenv-4.0.6.tgz",
"integrity": "sha512-4uQyhkXYAcNW+f2ZA0DHok6Sb4i91jGW6Nom47JMIRxrNNs0okqA5AW5tdz4S1NcJO9s+0rx3rrGlGeADygn2Q==",
"dev": true,
"requires": {
"@pushrocks/smartfile": "^7.0.6",
"@pushrocks/smartlog": "^2.0.19"
}
},
"@pushrocks/smartcli": {
"version": "3.0.7",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartcli/-/smartcli-3.0.7.tgz",
@ -238,9 +248,9 @@
}
},
"@pushrocks/smartmail": {
"version": "1.0.5",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartmail/-/smartmail-1.0.5.tgz",
"integrity": "sha512-AFezij0ftmAW99o5oHdZx2RaI+46Y/1uMRc2cgl+E8V1t7bYoHT6PipUr9SdNQ3UGhH3TPzj7FuXLn9tHnE4Sw==",
"version": "1.0.6",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartmail/-/smartmail-1.0.6.tgz",
"integrity": "sha512-dQZi8FOLVfX6qo7b73HQ5SgdMHpS1mHNJTbwpgVT/XlhVCdreXfrAbFLVXECH4EZ8WYt9KoSUo4zHSw31g97sw==",
"requires": {
"@pushrocks/smartfile": "^7.0.6",
"@pushrocks/smartmustache": "^2.0.8"
@ -284,9 +294,9 @@
"integrity": "sha512-vlQlBGNVIjfClgnsfgQBU6GIKcskYSFzEcKLt18ngPzPEcjKklXcxaqzLXpnoxR+KBh30QPE8255ncYHXuPPOg=="
},
"@pushrocks/smartrequest": {
"version": "1.1.36",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.36.tgz",
"integrity": "sha512-qeTRLFZZ3WOui7TkMNg8eGgZe3J9HG2XoaxR8hW65oX+TBUHcMEwA6EKuBaTWk6WUe/aJmfClw9DjjBnFCqtvQ==",
"version": "1.1.41",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.41.tgz",
"integrity": "sha512-Kv2HXydJ3epFDEgfXm1RMLMQC6ix3sin8Gb3MioBWStqH3Aik6XvwNqPnBX5MBcVcbFOWQooJjjBRHM5k/hRXA==",
"requires": {
"@pushrocks/smartpromise": "^3.0.5",
"@types/form-data": "^2.5.0",

View File

@ -1,6 +1,6 @@
{
"name": "@mojoio/mailgun",
"version": "1.0.5",
"version": "1.0.13",
"private": false,
"description": "an api abstraction package for mailgun",
"main": "dist/index.js",
@ -15,14 +15,15 @@
"devDependencies": {
"@gitzone/tsbuild": "^2.0.22",
"@gitzone/tstest": "^1.0.15",
"@pushrocks/qenv": "^4.0.6",
"@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^12.11.7",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.15.0"
},
"dependencies": {
"@pushrocks/smartmail": "^1.0.5",
"@pushrocks/smartrequest": "^1.1.36",
"@pushrocks/smartmail": "^1.0.6",
"@pushrocks/smartrequest": "^1.1.41",
"@pushrocks/smartstring": "^3.0.14"
},
"files": [

2
qenv.yml Normal file
View File

@ -0,0 +1,2 @@
required:
- MAILGUN_API_TOKEN

View File

@ -1,8 +1,31 @@
import { expect, tap } from '@pushrocks/tapbundle';
import { Qenv } from '@pushrocks/qenv';
import * as smartmail from '@pushrocks/smartmail';
const testQenv = new Qenv('./', './.nogit');
import * as mailgun from '../ts/index';
let testMailgunAccount: mailgun.MailgunAccount;
let testSmartmail: smartmail.Smartmail;
tap.test('first test', async () => {
console.log(mailgun.standardExport);
testMailgunAccount = new mailgun.MailgunAccount(testQenv.getEnvVarOnDemand('MAILGUN_API_TOKEN'));
expect(testMailgunAccount).to.be.instanceOf(mailgun.MailgunAccount);
});
tap.test('should create a smartmail', async () => {
testSmartmail = new smartmail.Smartmail({
body: 'hi there. This is the body.',
from: 'noreply@mail.lossless.com',
subject: 'hi there. This is the subject'
});
return testSmartmail;
});
tap.test('should send a smartmail', async () => {
testMailgunAccount.sendSmartMail(testSmartmail, 'sandbox@mail.git.zone');
});
tap.start();

View File

@ -1,3 +1 @@
import * as plugins from './mailgun.plugins';
export let standardExport = 'Hi there! :) This is an exported string';
export * from './mailgun.classes.account';

View File

@ -14,7 +14,7 @@ export class MailgunAccount {
method: 'GET',
headers: {
Authorization: `Basic ${plugins.smartstring.base64.encode(
`api:key-a049e048b7029b9621c41b5682fadee9`
`api:${this.apiToken}`
)}`,
'Content-Type': 'application/json'
}
@ -24,11 +24,11 @@ export class MailgunAccount {
public async postFormData(routeArg: string, formFields: plugins.smartrequest.IFormField[]) {
const requestUrl = `${this.baseUrl}${routeArg}`; // TODO;
const response = await plugins.smartrequest.postFormData(
routeArg,
requestUrl,
{
headers: {
Authorization: `Basic ${plugins.smartstring.base64.encode(
`api:key-a049e048b7029b9621c41b5682fadee9`
`api:${this.apiToken}`
)}`
}
},
@ -40,14 +40,45 @@ export class MailgunAccount {
/**
* sends a SmartMail
*/
public sendSmartMail(smartmailArg: plugins.smartmail.Smartmail) {
public async sendSmartMail(smartmailArg: plugins.smartmail.Smartmail, toArg: string, dataArg = {}) {
const domain = smartmailArg.options.from.split('@')[1];
this.postFormData(`/${domain}/messages`, [
const formFields: plugins.smartrequest.IFormField[] = [
{
name: 'from',
type: 'string',
payload: smartmailArg.options.from
},
{
name: 'to',
type: 'string',
payload: toArg
},
{
name: 'subject',
type: 'string',
payload: smartmailArg.getSubject(dataArg)
},
{
name: 'html',
type: 'string',
payload: smartmailArg.getBody(dataArg)
}
]);
];
for (const attachment of smartmailArg.attachments) {
formFields.push({
name: 'attachment',
type: 'Buffer',
payload: attachment.contentBuffer,
fileName: attachment.parsedPath.base
});
}
const response = await this.postFormData(`/${domain}/messages`, formFields);
if (response.statusCode === 200) {
return response.body;
} else {
throw new Error('could not send email');
}
}
}