Compare commits

..

21 Commits

Author SHA1 Message Date
168cb9d5d7 1.0.20 2020-01-13 16:04:25 +00:00
f61e119912 fix(core): update 2020-01-13 16:04:25 +00:00
f5c3fc6ee6 1.0.19 2020-01-13 14:34:14 +00:00
6643b9c3dd fix(core): update 2020-01-13 14:34:13 +00:00
157bf6a893 fix(interfaces): export interfaces 2020-01-13 14:06:34 +00:00
5d5e2076d8 1.0.17 2020-01-13 08:09:37 +00:00
815b455dbb fix(core): update 2020-01-13 08:09:37 +00:00
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
10 changed files with 216 additions and 73 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"

117
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@mojoio/mailgun", "name": "@mojoio/mailgun",
"version": "1.0.9", "version": "1.0.20",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -199,23 +199,23 @@
} }
}, },
"@pushrocks/smarthash": { "@pushrocks/smarthash": {
"version": "2.0.6", "version": "2.1.6",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmarthash/-/smarthash-2.0.6.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmarthash/-/smarthash-2.1.6.tgz",
"integrity": "sha512-jHk9srgRLkszk/oPCUOkxTX2Fqu7qKwx13aEeSIBx8UCtFbXPLecJAqEaGEVk1mw9e4Oq0iC6O0jEnxKo5NQwA==", "integrity": "sha512-TYa3wECYkeDoE8SomxcCJFg5Kt4+G4MtNMu3yATJCCoPLJIbyV1CwUvYuFYkkce2W4ZvH9h/N6dsHc69oI5Jcw==",
"requires": { "requires": {
"@pushrocks/smartjson": "^3.0.5", "@pushrocks/smartjson": "^3.0.10",
"@pushrocks/smartpromise": "^3.0.2", "@pushrocks/smartpromise": "^3.0.6",
"@types/through2": "^2.0.34", "@types/through2": "^2.0.34",
"through2": "^3.0.1" "through2": "^3.0.1"
} }
}, },
"@pushrocks/smartjson": { "@pushrocks/smartjson": {
"version": "3.0.8", "version": "3.0.10",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartjson/-/smartjson-3.0.8.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartjson/-/smartjson-3.0.10.tgz",
"integrity": "sha512-EjC3611RSZaZmK+nXxXrYDBxdxYWtrxjOrZtQzbYn0yM33KSCH0sLIAG8B2wYZVAOj4A2pC8mVxFSJ1w3iRFHg==", "integrity": "sha512-0tBkET2yjmSSIf4DlgeyU8U/J2EshTmQGuMY28EjPq9VvuCFXLh72WmETpA4QqKRMqhWp1+P+RZgnQupW3GQxQ==",
"requires": { "requires": {
"@types/fast-json-stable-stringify": "^2.0.0", "@types/fast-json-stable-stringify": "^2.0.0",
"fast-json-stable-stringify": "^2.0.0", "fast-json-stable-stringify": "^2.1.0",
"lodash.clonedeep": "^4.5.0" "lodash.clonedeep": "^4.5.0"
} }
}, },
@ -248,20 +248,20 @@
} }
}, },
"@pushrocks/smartmail": { "@pushrocks/smartmail": {
"version": "1.0.6", "version": "1.0.11",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartmail/-/smartmail-1.0.6.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartmail/-/smartmail-1.0.11.tgz",
"integrity": "sha512-dQZi8FOLVfX6qo7b73HQ5SgdMHpS1mHNJTbwpgVT/XlhVCdreXfrAbFLVXECH4EZ8WYt9KoSUo4zHSw31g97sw==", "integrity": "sha512-m6qtwoaDXp/2IAmWEccMGhkAtl8cTncBIm1bJo7bKr9GqWvNmnJi8ObnyjzDFFxbtYnmyYbipmo3Blj+i3m/2g==",
"requires": { "requires": {
"@pushrocks/smartfile": "^7.0.6", "@pushrocks/smartfile": "^7.0.6",
"@pushrocks/smartmustache": "^2.0.8" "@pushrocks/smartmustache": "^2.0.9"
} }
}, },
"@pushrocks/smartmustache": { "@pushrocks/smartmustache": {
"version": "2.0.8", "version": "2.0.9",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartmustache/-/smartmustache-2.0.8.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartmustache/-/smartmustache-2.0.9.tgz",
"integrity": "sha512-bnOST5zKPKSpCUiYqSHRdJ4NpO3/xz3LLtNE+xfWLS9Eyor/dIapqOpqwmZXNYr8QZuZWC//dlTIiQcv02D8Rg==", "integrity": "sha512-Wumikw03se8/hpPDyBUt0o/JynkNLhuv667jUYyXmTbs4DLnlRAwTpLTYDUoaJpNWsCN3Jg9AgVSrteRozbFig==",
"requires": { "requires": {
"handlebars": "^4.4.5" "handlebars": "^4.7.1"
} }
}, },
"@pushrocks/smartparam": { "@pushrocks/smartparam": {
@ -294,9 +294,9 @@
"integrity": "sha512-vlQlBGNVIjfClgnsfgQBU6GIKcskYSFzEcKLt18ngPzPEcjKklXcxaqzLXpnoxR+KBh30QPE8255ncYHXuPPOg==" "integrity": "sha512-vlQlBGNVIjfClgnsfgQBU6GIKcskYSFzEcKLt18ngPzPEcjKklXcxaqzLXpnoxR+KBh30QPE8255ncYHXuPPOg=="
}, },
"@pushrocks/smartrequest": { "@pushrocks/smartrequest": {
"version": "1.1.41", "version": "1.1.47",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.41.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.47.tgz",
"integrity": "sha512-Kv2HXydJ3epFDEgfXm1RMLMQC6ix3sin8Gb3MioBWStqH3Aik6XvwNqPnBX5MBcVcbFOWQooJjjBRHM5k/hRXA==", "integrity": "sha512-0AuqtAI14VeWeXl2WpJbgCybVlG03rOjdGchAqy5k5lg9ACLhN3Z4kmoLgpBysWO/L2SjlAKB489SRyV3acykg==",
"requires": { "requires": {
"@pushrocks/smartpromise": "^3.0.5", "@pushrocks/smartpromise": "^3.0.5",
"@types/form-data": "^2.5.0", "@types/form-data": "^2.5.0",
@ -330,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",
@ -355,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": {
@ -443,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",
@ -792,9 +793,9 @@
} }
}, },
"fast-json-stable-stringify": { "fast-json-stable-stringify": {
"version": "2.0.0", "version": "2.1.0",
"resolved": "https://verdaccio.lossless.one/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", "resolved": "https://verdaccio.lossless.one/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz",
"integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=" "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw=="
}, },
"figures": { "figures": {
"version": "3.1.0", "version": "3.1.0",
@ -874,14 +875,14 @@
} }
}, },
"graceful-fs": { "graceful-fs": {
"version": "4.2.2", "version": "4.2.3",
"resolved": "https://verdaccio.lossless.one/graceful-fs/-/graceful-fs-4.2.2.tgz", "resolved": "https://verdaccio.lossless.one/graceful-fs/-/graceful-fs-4.2.3.tgz",
"integrity": "sha512-IItsdsea19BoLC7ELy13q1iJFNmd7ofZH5+X/pJr90/nRoPEX0DJo1dHDbgtYWOhJhcCgMDTOw84RZ72q6lB+Q==" "integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ=="
}, },
"handlebars": { "handlebars": {
"version": "4.4.5", "version": "4.7.1",
"resolved": "https://verdaccio.lossless.one/handlebars/-/handlebars-4.4.5.tgz", "resolved": "https://verdaccio.lossless.one/handlebars/-/handlebars-4.7.1.tgz",
"integrity": "sha512-0Ce31oWVB7YidkaTq33ZxEbN+UDxMMgThvCe8ptgQViymL5DPis9uLdTA13MiRPhgvqyxIegugrP97iK3JeBHg==", "integrity": "sha512-2dd6soo60cwKNJ90VewNLIzdZPR/E2YhszOTgHpN9V0YuwZk7x33/iZoIBnASwDFVHMY7iJ6NPL8d9f/DWYCTA==",
"requires": { "requires": {
"neo-async": "^2.6.0", "neo-async": "^2.6.0",
"optimist": "^0.6.1", "optimist": "^0.6.1",
@ -1056,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": {
@ -1342,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"
@ -1525,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",
@ -1578,9 +1579,9 @@
"dev": true "dev": true
}, },
"uglify-js": { "uglify-js": {
"version": "3.6.4", "version": "3.7.5",
"resolved": "https://verdaccio.lossless.one/uglify-js/-/uglify-js-3.6.4.tgz", "resolved": "https://verdaccio.lossless.one/uglify-js/-/uglify-js-3.7.5.tgz",
"integrity": "sha512-9Yc2i881pF4BPGhjteCXQNaXx1DCwm3dtOyBaG2hitHjLWOczw/ki8vD1bqyT3u6K0Ms/FpCShkmfg+FtlOfYA==", "integrity": "sha512-GFZ3EXRptKGvb/C1Sq6nO1iI7AGcjyqmIyOw0DrD0675e+NNbGO72xmMM2iEBdFbxaTLo70NbjM/Wy54uZIlsg==",
"optional": true, "optional": true,
"requires": { "requires": {
"commander": "~2.20.3", "commander": "~2.20.3",

View File

@ -1,6 +1,6 @@
{ {
"name": "@mojoio/mailgun", "name": "@mojoio/mailgun",
"version": "1.0.9", "version": "1.0.20",
"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",
@ -16,15 +16,16 @@
"@gitzone/tsbuild": "^2.0.22", "@gitzone/tsbuild": "^2.0.22",
"@gitzone/tstest": "^1.0.15", "@gitzone/tstest": "^1.0.15",
"@pushrocks/qenv": "^4.0.6", "@pushrocks/qenv": "^4.0.6",
"@pushrocks/tapbundle": "^3.0.7", "@pushrocks/tapbundle": "^3.2.0",
"@types/node": "^12.11.7", "@types/node": "^13.1.6",
"tslint": "^5.11.0", "tslint": "^5.20.1",
"tslint-config-prettier": "^1.15.0" "tslint-config-prettier": "^1.15.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartmail": "^1.0.6", "@pushrocks/smartfile": "^7.0.6",
"@pushrocks/smartrequest": "^1.1.41", "@pushrocks/smartmail": "^1.0.11",
"@pushrocks/smartstring": "^3.0.14" "@pushrocks/smartrequest": "^1.1.47",
"@pushrocks/smartstring": "^3.0.17"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",

View File

@ -28,4 +28,11 @@ tap.test('should send a smartmail', async () => {
testMailgunAccount.sendSmartMail(testSmartmail, 'sandbox@mail.git.zone'); testMailgunAccount.sendSmartMail(testSmartmail, 'sandbox@mail.git.zone');
}); });
tap.test('should retrieve a mail using a retrieval url', async () => {
const result = await testMailgunAccount.retrieveSmartMailFromMessageUrl('https://sw.api.mailgun.net/v3/domains/mail.lossless.one/messages/AgMFnnnAKC8xp_dDa79LyoxhloxtaVmnRA==');
result.options.subject = 'hi there. This is a testmail with attachment';
result.options.from = 'noreply@mail.lossless.com';
testMailgunAccount.sendSmartMail(result, 'sandbox@mail.git.zone');
});
tap.start(); tap.start();

View File

@ -1 +1,2 @@
export * from './mailgun.classes.account'; export * from './mailgun.classes.account';
export * from './interfaces';

2
ts/interfaces/index.ts Normal file
View File

@ -0,0 +1,2 @@
export * from './message';
export * from './notification';

30
ts/interfaces/message.ts Normal file
View File

@ -0,0 +1,30 @@
export interface IMailgunMessage {
Received: string;
From: string;
'X-Envelope-From': string;
recipients: string;
'X-Google-Dkim-Signature': string;
To: string;
'message-headers': [[string, string]];
'Dkim-Signature': string;
'content-id-map': any;
subject: 'test2';
'stripped-html': string;
'X-Mailgun-Incoming': 'Yes';
'X-Received': string;
'X-Gm-Message-State': string;
'body-plain': string;
attachments: Array<{
url: string,
'content-type': string,
name: string,
size: number
}>;
'body-html': string;
'Mime-Version': string;
Date: string,
'Message-Id': string;
'Content-Type': string;
'X-Google-Smtp-Source': string;
Subject: string;
}

View File

@ -0,0 +1,47 @@
export interface IMailgunNotification {
timestamp: string;
token: string;
signature: string;
domain: string;
'Received-Spf': string;
From: string;
'Return-Path': string;
'Arc-Seal': string[],
'Delivered-To': string;
'X-Google-Dkim-Signature': string;
To: string;
'Dkim-Signature': string;
subject: string;
from: string;
'X-Received': string[];
'Ironport-Sdr': string;
'Arc-Authentication-Results': string[];
'Arc-Message-Signature': string[];
Date: string;
'Message-Id': string;
'Mime-Version': string;
Received: string[];
'Authentication-Results': string[];
'X-Ipas-Result': string;
'message-url': string;
'message-headers': string;
'Reply-To': string;
recipient: string;
sender: string;
'X-Mailgun-Incoming': string;
'X-Forwarded-For': string;
'X-Gm-Message-State': string;
'X-Google-Smtp-Source': string;
'X-Envelope-From': string;
'Content-Type': string;
'X-Forwarded-To': string;
Subject: string;
attachments: string;
'body-plain': string;
'stripped-text': string;
'stripped-html': string;
'stripped-signature': string;
// Lossless specific
X-Lossless-Auth: string
}

View File

@ -1,4 +1,5 @@
import * as plugins from './mailgun.plugins'; import * as plugins from './mailgun.plugins';
import * as interfaces from './interfaces';
export class MailgunAccount { export class MailgunAccount {
public baseUrl = 'https://api.mailgun.net/v3'; public baseUrl = 'https://api.mailgun.net/v3';
@ -8,17 +9,27 @@ export class MailgunAccount {
this.apiToken = apiTokenArg; this.apiToken = apiTokenArg;
} }
public getRequest(routeArg: string) { public async getRequest(routeArg: string, binaryArg: boolean = false) {
const requestUrl = `${this.baseUrl}${routeArg}`; // TODO; let requestUrl = routeArg;
const response = plugins.smartrequest.request(routeArg, { const needsBaseUrlPrefix = !routeArg.startsWith('https://');
needsBaseUrlPrefix ? requestUrl = `${this.baseUrl}${routeArg}` : null;
console.log(requestUrl);
const requestOptions: plugins.smartrequest.ISmartRequestOptions = {
method: 'GET', method: 'GET',
headers: { headers: {
Authorization: `Basic ${plugins.smartstring.base64.encode( Authorization: `Basic ${plugins.smartstring.base64.encode(
this.apiToken `api:${this.apiToken}`
)}`, )}`,
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }
}); };
let response: plugins.smartrequest.IExtendedIncomingMessage;
if (!binaryArg) {
response = await plugins.smartrequest.request(requestUrl, requestOptions);
} else {
response = await plugins.smartrequest.getBinary(requestUrl, requestOptions);
}
return response;
} }
public async postFormData(routeArg: string, formFields: plugins.smartrequest.IFormField[]) { public async postFormData(routeArg: string, formFields: plugins.smartrequest.IFormField[]) {
@ -28,7 +39,7 @@ export class MailgunAccount {
{ {
headers: { headers: {
Authorization: `Basic ${plugins.smartstring.base64.encode( Authorization: `Basic ${plugins.smartstring.base64.encode(
`api:key-a049e048b7029b9621c41b5682fadee9` `api:${this.apiToken}`
)}` )}`
} }
}, },
@ -65,6 +76,8 @@ export class MailgunAccount {
} }
]; ];
console.log(smartmailArg.attachments);
for (const attachment of smartmailArg.attachments) { for (const attachment of smartmailArg.attachments) {
formFields.push({ formFields.push({
name: 'attachment', name: 'attachment',
@ -75,6 +88,38 @@ export class MailgunAccount {
} }
const response = await this.postFormData(`/${domain}/messages`, formFields); const response = await this.postFormData(`/${domain}/messages`, formFields);
console.log(response); 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);
const responseBody: interfaces.IMailgunMessage = response.body;
const smartmail = new plugins.smartmail.Smartmail<interfaces.IMailgunMessage>({
from: responseBody.From,
body: responseBody["body-html"],
subject: responseBody.Subject,
});
// lets care about attachments
for (const attachmentInfo of responseBody.attachments) {
const attachmentName = attachmentInfo.name;
const attachmentContents = await this.getRequest(attachmentInfo.url, true);
smartmail.addAttachment(new plugins.smartfile.Smartfile({
path: `./${attachmentName}`,
base: `./${attachmentName}`,
contentBuffer: attachmentContents.body
}));
}
return smartmail;
}
public async retrieveSmartMailFromNotifyPayload(notifyPayloadArg: any) {
return await this.retrieveSmartMailFromMessageUrl(notifyPayloadArg['message-url']);
} }
} }

View File

@ -1,6 +1,7 @@
// @pushrocks scope // @pushrocks scope
import * as smartfile from '@pushrocks/smartfile';
import * as smartmail from '@pushrocks/smartmail'; import * as smartmail from '@pushrocks/smartmail';
import * as smartrequest from '@pushrocks/smartrequest'; import * as smartrequest from '@pushrocks/smartrequest';
import * as smartstring from '@pushrocks/smartstring'; import * as smartstring from '@pushrocks/smartstring';
export { smartmail, smartrequest, smartstring }; export { smartfile, smartmail, smartrequest, smartstring };