10 Commits

Author SHA1 Message Date
6e5faaef35 1.0.10 2019-11-22 14:15:38 +00:00
5aa148ef7d fix(security): update snyk 2019-11-22 14:15:37 +00:00
9a08c869ed 1.0.9 2019-11-22 14:02:57 +00:00
37850f92b6 fix(core): update 2019-11-22 14:02:56 +00:00
cf02cd86e5 1.0.8 2019-11-21 14:01:42 +00:00
d50cb5449a fix(core): update 2019-11-21 14:01:41 +00:00
c40d745f98 1.0.7 2019-11-18 16:26:02 +00:00
a619fbb239 fix(readme): show how to instantiate account 2019-11-18 16:26:01 +00:00
Philipp Kunz
fdb3c792f0 1.0.6 2019-11-18 16:18:59 +00:00
Philipp Kunz
340287ea55 fix(readme): add links to documentation 2019-11-18 16:18:58 +00:00
8 changed files with 2124 additions and 157 deletions

9
.snyk Normal file
View File

@@ -0,0 +1,9 @@
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.13.5
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
ignore:
SNYK-JS-MARKED-451341:
- '@pushrocks/smartletter > @pushrocks/smartmarkdown > marked':
reason: None given
expires: '2019-12-22T14:15:23.685Z'
patch: {}

2078
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "@mojoio/letterxpress",
"version": "1.0.5",
"version": "1.0.10",
"private": false,
"description": "an unofficial API package for the letterxpress API",
"main": "dist/index.js",
@@ -15,13 +15,17 @@
"devDependencies": {
"@gitzone/tsbuild": "^2.0.22",
"@gitzone/tstest": "^1.0.15",
"@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^10.11.7",
"@pushrocks/qenv": "^4.0.6",
"@pushrocks/tapbundle": "^3.2.0",
"@types/node": "^12.12.11",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.15.0"
},
"dependencies": {
"@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": [
"ts/**/*",

3
qenv.yml Normal file
View File

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

View File

@@ -18,6 +18,18 @@ an unofficial API package for the letterxpress API
## Usage
Use TypeScript for best in class intellisense.
letterxpress implements the LXP API documented here: [LXP API Documentation](https://www.letterxpress.de/briefe-uebertragen/api)
```typescript
import * as letterxpress from '@mojoio/letterxpress'
const account = new letterxpress.LetterXpressAccount({
email: 'myemail@example.com',
apiToken: 'abcdefghijklmnop1234567890'
})
```
## Contribution

View File

@@ -1,11 +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();
testAccount = new letterxpress.LetterXpressAccount({
apiKey: testQenv.getEnvVarOnDemand('API_TOKEN'),
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,5 +1,75 @@
import * as plugins from './letterxpress.plugins';
import { response } from 'express';
export interface ILetterXpressConstructorOptions {
username: string;
apiKey: string;
}
export class LetterXpressAccount {
}
public baseApiUrl = 'https://api.letterxpress.de/v1';
public options: ILetterXpressConstructorOptions;
public letterSentObservable = new plugins.smartrx.rxjs.Subject<plugins.smartletter.Letter>();
constructor(optionsArg: ILetterXpressConstructorOptions) {
this.options = optionsArg;
}
/**
* sends a letter
* @param letterArg
*/
public async sendLetter(letterArg: plugins.smartletter.Letter) {
const letterPdfResult = await letterArg.getPdfResult();
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' | 'DELETE', payload: any = {}) {
const requestUrl = `${this.baseApiUrl}${routeArg}`;
console.log(requestUrl);
const requestData = {
auth: {
username: this.options.username,
apikey: this.options.apiKey
},
...payload
};
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 {
smartrequest
};
export { smarthash, smartletter, smartrequest, smartrx };