Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
29a7472b3c | |||
5490be1033 | |||
6ee7c6af76 | |||
aa1750524b | |||
da7c57165e | |||
708c05d1e3 | |||
58b7f602bd | |||
23507b83fc | |||
c160cfd94e | |||
920399a495 |
@ -3,14 +3,14 @@ image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
@ -18,21 +18,23 @@ stages:
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
@ -41,37 +43,40 @@ snyk:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
@ -85,18 +90,20 @@ codequality:
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
stage: metadata
|
||||
@ -107,6 +114,7 @@ pages:
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
@ -114,5 +122,5 @@ pages:
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
- public
|
||||
allow_failure: true
|
||||
|
4
.snyk
Normal file
4
.snyk
Normal file
@ -0,0 +1,4 @@
|
||||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
||||
version: v1.13.5
|
||||
ignore: {}
|
||||
patch: {}
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "mojoio",
|
||||
|
777
package-lock.json
generated
777
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@mojoio/mailgun",
|
||||
"version": "1.0.20",
|
||||
"version": "1.0.25",
|
||||
"private": false,
|
||||
"description": "an api abstraction package for mailgun",
|
||||
"main": "dist/index.js",
|
||||
@ -13,19 +13,19 @@
|
||||
"format": "(gitzone format)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.0.22",
|
||||
"@gitzone/tsbuild": "^2.1.22",
|
||||
"@gitzone/tstest": "^1.0.15",
|
||||
"@pushrocks/qenv": "^4.0.6",
|
||||
"@pushrocks/tapbundle": "^3.2.0",
|
||||
"@types/node": "^13.1.6",
|
||||
"tslint": "^5.20.1",
|
||||
"@pushrocks/tapbundle": "^3.2.1",
|
||||
"@types/node": "^13.13.4",
|
||||
"tslint": "^6.1.1",
|
||||
"tslint-config-prettier": "^1.15.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartfile": "^7.0.6",
|
||||
"@pushrocks/smartfile": "^7.0.12",
|
||||
"@pushrocks/smartmail": "^1.0.11",
|
||||
"@pushrocks/smartrequest": "^1.1.47",
|
||||
"@pushrocks/smartstring": "^3.0.17"
|
||||
"@pushrocks/smartstring": "^3.0.18"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
|
19
test/test.ts
19
test/test.ts
@ -5,12 +5,13 @@ import * as smartmail from '@pushrocks/smartmail';
|
||||
const testQenv = new Qenv('./', './.nogit');
|
||||
|
||||
import * as mailgun from '../ts/index';
|
||||
import { IMailgunMessage } from '../ts/index';
|
||||
|
||||
|
||||
let testMailgunAccount: mailgun.MailgunAccount;
|
||||
let testSmartmail: smartmail.Smartmail;
|
||||
let testSmartmail: smartmail.Smartmail<IMailgunMessage>;
|
||||
|
||||
tap.test('first test', async () => {
|
||||
tap.test('should create a mailgun account', async () => {
|
||||
testMailgunAccount = new mailgun.MailgunAccount(testQenv.getEnvVarOnDemand('MAILGUN_API_TOKEN'));
|
||||
expect(testMailgunAccount).to.be.instanceOf(mailgun.MailgunAccount);
|
||||
});
|
||||
@ -18,21 +19,23 @@ tap.test('first test', async () => {
|
||||
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'
|
||||
from: 'Lossless GmbH <noreply@mail.lossless.com>',
|
||||
subject: 'TestMessage from @mojoio/mailgun test'
|
||||
});
|
||||
return testSmartmail;
|
||||
});
|
||||
|
||||
tap.test('should send a smartmail', async () => {
|
||||
testMailgunAccount.sendSmartMail(testSmartmail, 'sandbox@mail.git.zone');
|
||||
await testMailgunAccount.sendSmartMail(testSmartmail, 'Sandbox Team <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');
|
||||
if (result) {
|
||||
result.options.subject = 'hi there. This is a testmail with attachment';
|
||||
result.options.from = 'noreply@mail.lossless.com';
|
||||
await testMailgunAccount.sendSmartMail(result, 'Sandbox Team <sandbox@mail.git.zone>');
|
||||
}
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
@ -15,14 +15,14 @@ export interface IMailgunMessage {
|
||||
'X-Gm-Message-State': string;
|
||||
'body-plain': string;
|
||||
attachments: Array<{
|
||||
url: string,
|
||||
'content-type': string,
|
||||
name: string,
|
||||
size: number
|
||||
}>;
|
||||
url: string;
|
||||
'content-type': string;
|
||||
name: string;
|
||||
size: number;
|
||||
}>;
|
||||
'body-html': string;
|
||||
'Mime-Version': string;
|
||||
Date: string,
|
||||
Date: string;
|
||||
'Message-Id': string;
|
||||
'Content-Type': string;
|
||||
'X-Google-Smtp-Source': string;
|
||||
|
@ -43,5 +43,5 @@ export interface IMailgunNotification {
|
||||
'stripped-signature': string;
|
||||
|
||||
// Lossless specific
|
||||
X-Lossless-Auth: string
|
||||
"X-Lossless-Auth": string;
|
||||
}
|
@ -51,8 +51,8 @@ export class MailgunAccount {
|
||||
/**
|
||||
* sends a SmartMail
|
||||
*/
|
||||
public async sendSmartMail(smartmailArg: plugins.smartmail.Smartmail, toArg: string, dataArg = {}) {
|
||||
const domain = smartmailArg.options.from.split('@')[1];
|
||||
public async sendSmartMail(smartmailArg: plugins.smartmail.Smartmail<interfaces.IMailgunMessage>, toArg: string, dataArg = {}) {
|
||||
const domain = smartmailArg.options.from.split('@')[1].replace('>', '');
|
||||
const formFields: plugins.smartrequest.IFormField[] = [
|
||||
{
|
||||
name: 'from',
|
||||
@ -98,22 +98,29 @@ export class MailgunAccount {
|
||||
|
||||
public async retrieveSmartMailFromMessageUrl(messageUrlArg: string) {
|
||||
const response = await this.getRequest(messageUrlArg);
|
||||
if (response.statusCode === 404) {
|
||||
console.log(response.body.message);
|
||||
return null;
|
||||
}
|
||||
const responseBody: interfaces.IMailgunMessage = response.body;
|
||||
const smartmail = new plugins.smartmail.Smartmail<interfaces.IMailgunMessage>({
|
||||
from: responseBody.From,
|
||||
body: responseBody["body-html"],
|
||||
subject: responseBody.Subject,
|
||||
creationObjectRef: responseBody
|
||||
});
|
||||
|
||||
// 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
|
||||
}));
|
||||
if (responseBody.attachments && responseBody.attachments instanceof Array) {
|
||||
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;
|
||||
|
Reference in New Issue
Block a user