fix(core): update

This commit is contained in:
Philipp Kunz 2019-11-22 14:02:56 +00:00
parent cf02cd86e5
commit 37850f92b6
6 changed files with 146 additions and 38 deletions

52
package-lock.json generated
View File

@ -203,12 +203,12 @@
}
},
"@pushrocks/smarthash": {
"version": "2.0.6",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmarthash/-/smarthash-2.0.6.tgz",
"integrity": "sha512-jHk9srgRLkszk/oPCUOkxTX2Fqu7qKwx13aEeSIBx8UCtFbXPLecJAqEaGEVk1mw9e4Oq0iC6O0jEnxKo5NQwA==",
"version": "2.1.1",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmarthash/-/smarthash-2.1.1.tgz",
"integrity": "sha512-zVfqXsi0T+PZQJpXsQf7KJpoCUOv97q7//ccp5o/07Bo77gjLO966fevYO+1y7pbvLZ0nQ4pE536YmLkgwluPQ==",
"requires": {
"@pushrocks/smartjson": "^3.0.5",
"@pushrocks/smartpromise": "^3.0.2",
"@pushrocks/smartjson": "^3.0.8",
"@pushrocks/smartpromise": "^3.0.6",
"@types/through2": "^2.0.34",
"through2": "^3.0.1"
}
@ -224,9 +224,9 @@
}
},
"@pushrocks/smartletter": {
"version": "1.0.15",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartletter/-/smartletter-1.0.15.tgz",
"integrity": "sha512-ErW0VoRqJtFKIaIG+VlPfmfBtdTmd3dTnlW6SF2zxRaZf0cIq43P2h+wdKYpJO8lKESl3kidItVSXZ7WB9pLpg==",
"version": "1.0.16",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartletter/-/smartletter-1.0.16.tgz",
"integrity": "sha512-58+e0TW+lQkmJguq9uegrlk+k34XC2/TrWspMZa7ElviNSi6Xp6ON/lnuf5L6Uos3716t4ErkojwN6VNLJSmjw==",
"requires": {
"@pushrocks/smartdelay": "^2.0.6",
"@pushrocks/smartmarkdown": "^2.0.2",
@ -276,18 +276,18 @@
}
},
"@pushrocks/smartnetwork": {
"version": "1.1.14",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartnetwork/-/smartnetwork-1.1.14.tgz",
"integrity": "sha512-0zNTypPGqA9mUaGxTPkqHYWDnonY6QpRo5ejVpFMdRI3H/3V4PyKkb6BTOnbMHcUFv38CnvnR9TYteCdiIbLKg==",
"version": "1.1.16",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartnetwork/-/smartnetwork-1.1.16.tgz",
"integrity": "sha512-IWvOqpV/PN4XXQ74fJy5Qc9MThPhY1C0T1IS1AY36wskiS5ExZ8ekT0352uMomTTtsBRtkrLwO+LIiBhFwdnwA==",
"requires": {
"@pushrocks/smartpromise": "^3.0.2",
"@pushrocks/smartstring": "^3.0.10",
"@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartstring": "^3.0.14",
"@types/default-gateway": "^3.0.0",
"@types/portscanner": "^2.1.0",
"default-gateway": "^5.0.3",
"default-gateway": "^5.0.5",
"portscanner": "^2.2.0",
"speedtest-net": "^1.5.1",
"systeminformation": "^4.14.8"
"speedtest-net": "^1.6.0",
"systeminformation": "^4.15.3"
}
},
"@pushrocks/smartparam": {
@ -343,9 +343,9 @@
}
},
"@pushrocks/smartrequest": {
"version": "1.1.42",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.42.tgz",
"integrity": "sha512-sCEousyvnbW9IvBVHt3ZTjV1IP2vxJQ8TqG5GqxRk82wyVB0SCZfuMWW/guQA1+DmxfUfMsqBxzvovtM/bOc1w==",
"version": "1.1.43",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.43.tgz",
"integrity": "sha512-bgzzKN9SxJaYhh+BN3tuLSgdphWsxAOHgNjWWay3o/ib8/c2RwRlmjoxzxXrIhKFEwJjGIo7w04045VgkoWkMQ==",
"requires": {
"@pushrocks/smartpromise": "^3.0.5",
"@types/form-data": "^2.5.0",
@ -564,9 +564,9 @@
"integrity": "sha512-II0FA05TSt4r7PBUvYTqub+yrXTRu7L/PQnTtjcJYzAeBts6xHM/OA2MKyeQ80sFxX7p+0BTo68Nh1P3N6Oj/g=="
},
"@types/puppeteer": {
"version": "1.20.2",
"resolved": "https://verdaccio.lossless.one/@types%2fpuppeteer/-/puppeteer-1.20.2.tgz",
"integrity": "sha512-oSFCtftHSfVx8K9XPdNNYs79Zt4pYJs/0NP78ltuGCB25zS3UNGJSiypBfbhbvRC5Dcsh0k1R5Z0i8HHtqQUPQ==",
"version": "1.20.3",
"resolved": "https://verdaccio.lossless.one/@types%2fpuppeteer/-/puppeteer-1.20.3.tgz",
"integrity": "sha512-U1H7E4wHDsPe2s7wa2fpUD4kPYmu3n4hYRmlFK4WgKQxXE1ctY2h9Exely8GXs7743gLvrnzuX7aJuyG0SEMIQ==",
"requires": {
"@types/node": "*"
}
@ -1902,11 +1902,11 @@
"dev": true
},
"is-symbol": {
"version": "1.0.2",
"resolved": "https://verdaccio.lossless.one/is-symbol/-/is-symbol-1.0.2.tgz",
"integrity": "sha512-HS8bZ9ox60yCJLH9snBpIwv9pYUAkcuLhSA1oero1UB5y9aiQpRA8y2ex945AOtCZL1lJDeIk3G5LthswI46Lw==",
"version": "1.0.3",
"resolved": "https://verdaccio.lossless.one/is-symbol/-/is-symbol-1.0.3.tgz",
"integrity": "sha512-OwijhaRSgqvhm/0ZdAcXNZt9lYdKFpcRDT5ULUuYXPoT794UNOdU+gpT6Rzo7b4V2HUl/op6GqY894AZwv9faQ==",
"requires": {
"has-symbols": "^1.0.0"
"has-symbols": "^1.0.1"
}
},
"is-typedarray": {

View File

@ -22,8 +22,9 @@
"tslint-config-prettier": "^1.15.0"
},
"dependencies": {
"@pushrocks/smartletter": "^1.0.15",
"@pushrocks/smartrequest": "^1.1.42",
"@pushrocks/smarthash": "^2.1.1",
"@pushrocks/smartletter": "^1.0.16",
"@pushrocks/smartrequest": "^1.1.43",
"@pushrocks/smartrx": "^2.0.5"
},
"files": [

View File

@ -1,3 +1,3 @@
required:
- API_EMAIL
- API_USERNAME
- API_TOKEN

View File

@ -1,17 +1,95 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as letterxpress from '../ts/index';
import * as smartletter from '@pushrocks/smartletter';
const smartletterInstance = new smartletter.Smartletter();
let testletter: smartletter.Letter;
import { Qenv } from '@pushrocks/qenv';
let testQenv = new Qenv('./', './.nogit/');
let testAccount: letterxpress.LetterXpressAccount;
tap.test('start things', async () => {
await smartletterInstance.start();
});
tap.test('should create a valid account', async () => {
testAccount = new letterxpress.LetterXpressAccount({
apiKey: testQenv.getEnvVarOnDemand('API_TOKEN'),
email: testQenv.getEnvVarOnDemand('API_EMAIL')
username: testQenv.getEnvVarOnDemand('API_USERNAME')
});
expect(testAccount).to.be.instanceOf(letterxpress.LetterXpressAccount);
});
tap.test('should send an actual letter', async () => {
testletter = await smartletterInstance.createLetter({
from: {
name: 'Lossless GmbH',
city: 'Bremen',
country: 'Germany',
postalCode: '28213',
houseNumber: '16',
streetName: 'Ottilie-Hoffmann-Str.'
},
to: {
name: 'Lossless GmbH',
city: 'Berlin',
country: 'Germany',
postalCode: '10245',
houseNumber: '16a, Scanbox #06320',
streetName: 'Ehrenbergstr.'
},
incidenceId: 'abc123',
legalInfo: {
name: 'Lossless GmbH',
status: 'active',
contact: {
type: 'company',
salutation: null,
surname: null,
title: null,
address: {
city: 'Bremen',
country: 'Germany',
houseNumber: '16',
name: 'Lossless GmbH',
postalCode: '28213',
streetName: 'Ottilie-Hoffmann Str.'
},
bankAccountNumber: 'NL83 BUNQ 2035 5639 41',
customerNumber: null,
description: null,
email: 'hello@lossless.com',
fax: '+49 421 408951 46',
phone: '+49 421 16767 548',
legalEntity: 'Lossless GmbH',
name: 'Lossless GmbH',
vatId: 'DE293580420'
},
closedDate: null,
foundedDate: null
},
subject: 'General Terms - Update',
text: `<p>To whome it may concern,</p>
<p>
<strong>this is a testmessage.</strong> we write to inform you about a change in our General Terms.
As of December 1st 2019 we will start storing IPs that connect to our app for a period of 3 month.
<p>
Regards<br>
Lossless GmbH - Legal Department`
});
await testAccount.sendLetter(testletter);
});
tap.test('should be able to delete the sending job', async () => {
await testAccount.cancelLetter(testletter);
});
tap.test('should wrap things up', async () => {
await smartletterInstance.stop();
})
tap.start();

View File

@ -1,12 +1,13 @@
import * as plugins from './letterxpress.plugins';
import { response } from 'express';
export interface ILetterXpressConstructorOptions {
email: string;
username: string;
apiKey: string;
}
export class LetterXpressAccount {
public baseApiUrl = 'https://api.letterxpress.de/v1/';
public baseApiUrl = 'https://api.letterxpress.de/v1';
public options: ILetterXpressConstructorOptions;
public letterSentObservable = new plugins.smartrx.rxjs.Subject<plugins.smartletter.Letter>();
@ -21,27 +22,54 @@ export class LetterXpressAccount {
*/
public async sendLetter(letterArg: plugins.smartletter.Letter) {
const letterPdfResult = await letterArg.getPdfResult();
const response = await this.request('/setJob', 'POST', {});
const response = await this.request('/setJob', 'POST', {
letter: {
base64_file: letterPdfResult.buffer.toString('base64'),
base64_checksum: await plugins.smarthash.md5FromString(
letterPdfResult.buffer.toString('base64')
),
specification: {
color: '4',
mode: 'simplex',
ship: letterArg.options.to.country === 'Germany' ? 'national' : 'international'
}
}
});
letterArg.setProcessingId(response.body.letter.job_id);
return letterArg;
}
public async cancelLetter(letterArg: plugins.smartletter.Letter) {
const processingId = letterArg.getProcessingId();
return await this.cancelLetterByProcessingId(processingId);
}
public async cancelLetterByProcessingId(processingId: string) {
const response = await this.request(`/deleteJob/${processingId}`, 'DELETE');
return response;
}
/**
* fires the request
*/
private async request(routeArg: string, methodArg: 'GET' | 'POST', payload?: any) {
const requestUrl = `${this.baseApiUrl}`;
private async request(routeArg: string, methodArg: 'GET' | 'POST' | 'DELETE', payload: any = {}) {
const requestUrl = `${this.baseApiUrl}${routeArg}`;
console.log(requestUrl);
const requestData = {
auth: {
username: this.options.email,
username: this.options.username,
apikey: this.options.apiKey
},
...payload
};
const response = await plugins.smartrequest.request(routeArg, {
const response = await plugins.smartrequest.request(requestUrl, {
method: methodArg,
headers: {
'Content-Type': 'application/json'
},
requestBody: JSON.stringify(requestData)
});
console.log(response.body);
return response;
}
}

View File

@ -1,5 +1,6 @@
import * as smartletter from '@pushrocks/smartletter';
import * as smarthash from '@pushrocks/smarthash';
import * as smartrequest from '@pushrocks/smartrequest';
import * as smartrx from '@pushrocks/smartrx';
export { smartletter, smartrequest, smartrx };
export { smarthash, smartletter, smartrequest, smartrx };