Compare commits

..

21 Commits

Author SHA1 Message Date
9d5907a7a7 1.0.16 2020-01-11 19:02:00 +00:00
0212d476c2 fix(core): update 2020-01-11 19:01:59 +00:00
2b8aadc816 1.0.15 2020-01-11 11:15:53 +00:00
1149ee6759 fix(core): update 2020-01-11 11:15:52 +00:00
fa012409ff 1.0.14 2020-01-11 11:15:12 +00:00
40bd96bf41 fix(core): update 2020-01-11 11:15:11 +00:00
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 139 additions and 51 deletions

View File

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

75
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@mojoio/mailgun", "name": "@mojoio/mailgun",
"version": "1.0.5", "version": "1.0.16",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -113,6 +113,16 @@
"symbol-tree": "^3.2.4" "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": { "@pushrocks/smartcli": {
"version": "3.0.7", "version": "3.0.7",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartcli/-/smartcli-3.0.7.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartcli/-/smartcli-3.0.7.tgz",
@ -238,9 +248,9 @@
} }
}, },
"@pushrocks/smartmail": { "@pushrocks/smartmail": {
"version": "1.0.5", "version": "1.0.6",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartmail/-/smartmail-1.0.5.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartmail/-/smartmail-1.0.6.tgz",
"integrity": "sha512-AFezij0ftmAW99o5oHdZx2RaI+46Y/1uMRc2cgl+E8V1t7bYoHT6PipUr9SdNQ3UGhH3TPzj7FuXLn9tHnE4Sw==", "integrity": "sha512-dQZi8FOLVfX6qo7b73HQ5SgdMHpS1mHNJTbwpgVT/XlhVCdreXfrAbFLVXECH4EZ8WYt9KoSUo4zHSw31g97sw==",
"requires": { "requires": {
"@pushrocks/smartfile": "^7.0.6", "@pushrocks/smartfile": "^7.0.6",
"@pushrocks/smartmustache": "^2.0.8" "@pushrocks/smartmustache": "^2.0.8"
@ -284,9 +294,9 @@
"integrity": "sha512-vlQlBGNVIjfClgnsfgQBU6GIKcskYSFzEcKLt18ngPzPEcjKklXcxaqzLXpnoxR+KBh30QPE8255ncYHXuPPOg==" "integrity": "sha512-vlQlBGNVIjfClgnsfgQBU6GIKcskYSFzEcKLt18ngPzPEcjKklXcxaqzLXpnoxR+KBh30QPE8255ncYHXuPPOg=="
}, },
"@pushrocks/smartrequest": { "@pushrocks/smartrequest": {
"version": "1.1.36", "version": "1.1.43",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.36.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.43.tgz",
"integrity": "sha512-qeTRLFZZ3WOui7TkMNg8eGgZe3J9HG2XoaxR8hW65oX+TBUHcMEwA6EKuBaTWk6WUe/aJmfClw9DjjBnFCqtvQ==", "integrity": "sha512-bgzzKN9SxJaYhh+BN3tuLSgdphWsxAOHgNjWWay3o/ib8/c2RwRlmjoxzxXrIhKFEwJjGIo7w04045VgkoWkMQ==",
"requires": { "requires": {
"@pushrocks/smartpromise": "^3.0.5", "@pushrocks/smartpromise": "^3.0.5",
"@types/form-data": "^2.5.0", "@types/form-data": "^2.5.0",
@ -320,9 +330,9 @@
} }
}, },
"@pushrocks/smartstring": { "@pushrocks/smartstring": {
"version": "3.0.14", "version": "3.0.17",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartstring/-/smartstring-3.0.14.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartstring/-/smartstring-3.0.17.tgz",
"integrity": "sha512-hN3IwTb5VBUis8Z5U5U6dDCnap6zBmkc9/IVx8lxAbsxl5TYQ4RiYlJ2JM4tih7EdE80ZeSdpprzChYrWmSwDg==", "integrity": "sha512-60JQptpgw+PjxoC5Gx+Y9m3/dtMstHC5ElpdJhIlbJ7dQV7LkCGSonLAG+NZhPbvrhow2KZ3fob8stW0Iuy3JQ==",
"requires": { "requires": {
"crypto-random-string": "^3.0.1", "crypto-random-string": "^3.0.1",
"js-base64": "^2.5.1", "js-base64": "^2.5.1",
@ -345,21 +355,22 @@
} }
}, },
"@pushrocks/tapbundle": { "@pushrocks/tapbundle": {
"version": "3.0.13", "version": "3.2.0",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2ftapbundle/-/tapbundle-3.0.13.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2ftapbundle/-/tapbundle-3.2.0.tgz",
"integrity": "sha512-23O4UMBafCuD+RnUlXNvtT9DGbL1HMD+xZE1Zcr7Ll7WvgxUgRQQfk9kq6qbLLbjaRe1J2Ijsgh1HuZbBaucLQ==", "integrity": "sha512-xnKIGe7NJqxWBaFeKIEXShDjV2wap1XJqmlp3m1MKqmIF62vRpZnkzpyE1ZAoNwiYQmIsXIpvP/PDv+iPevPfw==",
"dev": true, "dev": true,
"requires": { "requires": {
"@pushrocks/early": "^3.0.3", "@pushrocks/early": "^3.0.3",
"@pushrocks/smartdelay": "^2.0.3", "@pushrocks/smartdelay": "^2.0.3",
"@pushrocks/smartfile": "^7.0.6",
"@pushrocks/smartpromise": "^3.0.2", "@pushrocks/smartpromise": "^3.0.2",
"smartchai": "^2.0.1" "smartchai": "^2.0.1"
} }
}, },
"@types/chai": { "@types/chai": {
"version": "4.2.4", "version": "4.2.7",
"resolved": "https://verdaccio.lossless.one/@types%2fchai/-/chai-4.2.4.tgz", "resolved": "https://verdaccio.lossless.one/@types%2fchai/-/chai-4.2.7.tgz",
"integrity": "sha512-7qvf9F9tMTzo0akeswHPGqgUx/gIaJqrOEET/FCD8CFRkSUHlygQiM5yB6OvjrtdxBVLSyw7COJubsFYs0683g==", "integrity": "sha512-luq8meHGYwvky0O7u0eQZdA7B4Wd9owUCqvbw2m3XCrCU8mplYOujMBbvyS547AxJkC+pGnd0Cm15eNxEUNU8g==",
"dev": true "dev": true
}, },
"@types/chai-as-promised": { "@types/chai-as-promised": {
@ -433,9 +444,9 @@
"dev": true "dev": true
}, },
"@types/node": { "@types/node": {
"version": "12.11.7", "version": "13.1.6",
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.11.7.tgz", "resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-13.1.6.tgz",
"integrity": "sha512-JNbGaHFCLwgHn/iCckiGSOZ1XYHsKFwREtzPwSGCVld1SGhOlmZw2D4ZI94HQCrBHbADzW9m4LER/8olJTRGHA==" "integrity": "sha512-Jg1F+bmxcpENHP23sVKkNuU3uaxPnsBMW0cLjleiikFKomJQbsn0Cqk2yDvQArqzZN6ABfBkZ0To7pQ8sLdWDg=="
}, },
"@types/through2": { "@types/through2": {
"version": "2.0.34", "version": "2.0.34",
@ -1046,16 +1057,16 @@
} }
}, },
"mime-db": { "mime-db": {
"version": "1.40.0", "version": "1.43.0",
"resolved": "https://verdaccio.lossless.one/mime-db/-/mime-db-1.40.0.tgz", "resolved": "https://verdaccio.lossless.one/mime-db/-/mime-db-1.43.0.tgz",
"integrity": "sha512-jYdeOMPy9vnxEqFRRo6ZvTZ8d9oPb+k18PKoYNYUe2stVEBPPwsln/qWzdbmaIvnhZ9v2P+CuecK+fpUfsV2mA==" "integrity": "sha512-+5dsGEEovYbT8UY9yD7eE4XTc4UwJ1jBYlgaQQF38ENsKR3wj/8q8RFZrF9WIZpB2V1ArTVFUva8sAul1NzRzQ=="
}, },
"mime-types": { "mime-types": {
"version": "2.1.24", "version": "2.1.26",
"resolved": "https://verdaccio.lossless.one/mime-types/-/mime-types-2.1.24.tgz", "resolved": "https://verdaccio.lossless.one/mime-types/-/mime-types-2.1.26.tgz",
"integrity": "sha512-WaFHS3MCl5fapm3oLxU4eYDw77IQM2ACcxQ9RIxfaC3ooc6PFuBMGZZsYpvoXS5D5QTWPieo1jjLdAm3TBP3cQ==", "integrity": "sha512-01paPWYgLrkqAyrlDorC1uDwl2p3qZT7yl806vW7DvDoxwXi46jsjFbg+WdwotBIk6/MbEhO/dh5aZ5sNj/dWQ==",
"requires": { "requires": {
"mime-db": "1.40.0" "mime-db": "1.43.0"
} }
}, },
"mimic-fn": { "mimic-fn": {
@ -1332,9 +1343,9 @@
"dev": true "dev": true
}, },
"resolve": { "resolve": {
"version": "1.12.0", "version": "1.14.2",
"resolved": "https://verdaccio.lossless.one/resolve/-/resolve-1.12.0.tgz", "resolved": "https://verdaccio.lossless.one/resolve/-/resolve-1.14.2.tgz",
"integrity": "sha512-B/dOmuoAik5bKcD6s6nXDCjzUKnaDvdkRyAk6rsmsKLipWj4797iothd7jmmUhWTfinVMU+wc56rYKsit2Qy4w==", "integrity": "sha512-EjlOBLBO1kxsUxsKjLt7TAECyKW6fOh1VRkykQkKGzcBbjjPIxBqGh0jf7GJ3k/f5mxMqW3htMD3WdTUVtW8HQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"path-parse": "^1.0.6" "path-parse": "^1.0.6"
@ -1515,9 +1526,9 @@
"dev": true "dev": true
}, },
"tslint": { "tslint": {
"version": "5.20.0", "version": "5.20.1",
"resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.20.0.tgz", "resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.20.1.tgz",
"integrity": "sha512-2vqIvkMHbnx8acMogAERQ/IuINOq6DFqgF8/VDvhEkBqQh/x6SP0Y+OHnKth9/ZcHQSroOZwUQSN18v8KKF0/g==", "integrity": "sha512-EcMxhzCFt8k+/UP5r8waCf/lzmeSyVlqxqMEDQE7rWYiQky8KpIBz1JAoYXfROHrPZ1XXd43q8yQnULOLiBRQg==",
"dev": true, "dev": true,
"requires": { "requires": {
"@babel/code-frame": "^7.0.0", "@babel/code-frame": "^7.0.0",

View File

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

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 { 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'; import * as mailgun from '../ts/index';
let testMailgunAccount: mailgun.MailgunAccount;
let testSmartmail: smartmail.Smartmail;
tap.test('first test', async () => { 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(); tap.start();

View File

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

View File

@ -2,6 +2,7 @@ import * as plugins from './mailgun.plugins';
export class MailgunAccount { export class MailgunAccount {
public baseUrl = 'https://api.mailgun.net/v3'; public baseUrl = 'https://api.mailgun.net/v3';
public baseUrlSe = 'https://se.api.mailgun.net/v3';
public apiToken: string; public apiToken: string;
constructor(apiTokenArg: string) { constructor(apiTokenArg: string) {
@ -9,26 +10,29 @@ export class MailgunAccount {
} }
public getRequest(routeArg: string) { public getRequest(routeArg: string) {
const requestUrl = `${this.baseUrl}${routeArg}`; // TODO; let requestUrl = routeArg;
const response = plugins.smartrequest.request(routeArg, { const needsBaseUrlPrefix = (routeArg.startsWith(this.baseUrl)) || routeArg.startsWith(this.baseUrlSe);
needsBaseUrlPrefix ? requestUrl = `${this.baseUrl}${routeArg}` : null;
const response = plugins.smartrequest.request(requestUrl, {
method: 'GET', method: 'GET',
headers: { headers: {
Authorization: `Basic ${plugins.smartstring.base64.encode( Authorization: `Basic ${plugins.smartstring.base64.encode(
`api:key-a049e048b7029b9621c41b5682fadee9` `api:${this.apiToken}`
)}`, )}`,
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }
}); });
return response;
} }
public async postFormData(routeArg: string, formFields: plugins.smartrequest.IFormField[]) { public async postFormData(routeArg: string, formFields: plugins.smartrequest.IFormField[]) {
const requestUrl = `${this.baseUrl}${routeArg}`; // TODO; const requestUrl = `${this.baseUrl}${routeArg}`; // TODO;
const response = await plugins.smartrequest.postFormData( const response = await plugins.smartrequest.postFormData(
routeArg, requestUrl,
{ {
headers: { headers: {
Authorization: `Basic ${plugins.smartstring.base64.encode( Authorization: `Basic ${plugins.smartstring.base64.encode(
`api:key-a049e048b7029b9621c41b5682fadee9` `api:${this.apiToken}`
)}` )}`
} }
}, },
@ -40,14 +44,55 @@ export class MailgunAccount {
/** /**
* sends a SmartMail * 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]; const domain = smartmailArg.options.from.split('@')[1];
this.postFormData(`/${domain}/messages`, [ const formFields: plugins.smartrequest.IFormField[] = [
{ {
name: 'from', name: 'from',
type: 'string', type: 'string',
payload: smartmailArg.options.from 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 {
console.log(response.body);
throw new Error('could not send email');
}
}
public async retrieveSmartMailFromMessageUrl(messageUrlArg: string) {
const response = await this.getRequest(messageUrlArg);
return response.body;
}
public async retrieveSmartMailFromNotifyPayload(notifyPayloadArg: any) {
return await this.retrieveSmartMailFromMessageUrl(notifyPayloadArg['message-url']);
} }
} }