From 4305b53e3517130641b7231c0671aad10577f8bc Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Mon, 28 Oct 2019 15:55:04 +0100 Subject: [PATCH] fix(core): update --- package-lock.json | 22 ++++++++++++++++------ package.json | 5 +++-- qenv.yml | 2 ++ test/test.ts | 25 ++++++++++++++++++++++++- ts/index.ts | 4 +--- ts/mailgun.classes.account.ts | 14 ++++++++------ 6 files changed, 54 insertions(+), 18 deletions(-) create mode 100644 qenv.yml diff --git a/package-lock.json b/package-lock.json index 5f005e3..07a97c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 99378dc..ad6db43 100644 --- a/package.json +++ b/package.json @@ -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": [ diff --git a/qenv.yml b/qenv.yml new file mode 100644 index 0000000..2ee9002 --- /dev/null +++ b/qenv.yml @@ -0,0 +1,2 @@ +required: + - MAILGUN_API_TOKEN \ No newline at end of file diff --git a/test/test.ts b/test/test.ts index 0fb5a80..538caf2 100644 --- a/test/test.ts +++ b/test/test.ts @@ -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, 'phil@lossless.com'); }); tap.start(); diff --git a/ts/index.ts b/ts/index.ts index 40d53c3..495d4a5 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,3 +1 @@ -import * as plugins from './mailgun.plugins'; - -export let standardExport = 'Hi there! :) This is an exported string'; +export * from './mailgun.classes.account'; diff --git a/ts/mailgun.classes.account.ts b/ts/mailgun.classes.account.ts index e6b75a4..18937c0 100644 --- a/ts/mailgun.classes.account.ts +++ b/ts/mailgun.classes.account.ts @@ -14,7 +14,7 @@ export class MailgunAccount { method: 'GET', headers: { Authorization: `Basic ${plugins.smartstring.base64.encode( - `api:key-a049e048b7029b9621c41b5682fadee9` + this.apiToken )}`, 'Content-Type': 'application/json' } @@ -24,7 +24,7 @@ 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( @@ -40,7 +40,7 @@ export class MailgunAccount { /** * sends a SmartMail */ - public sendSmartMail(smartmailArg: plugins.smartmail.Smartmail, toArg: string, dataArg = {}) { + public async sendSmartMail(smartmailArg: plugins.smartmail.Smartmail, toArg: string, dataArg = {}) { const domain = smartmailArg.options.from.split('@')[1]; const formFields: plugins.smartrequest.IFormField[] = [ { @@ -69,10 +69,12 @@ export class MailgunAccount { formFields.push({ name: 'attachment', type: 'Buffer', - payload: attachment.contentBuffer - }) + payload: attachment.contentBuffer, + fileName: attachment.parsedPath.base + }); } - this.postFormData(`/${domain}/messages`, formFields); + const response = await this.postFormData(`/${domain}/messages`, formFields); + console.log(response); } }