Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
9a08c869ed | |||
37850f92b6 | |||
cf02cd86e5 | |||
d50cb5449a | |||
c40d745f98 | |||
a619fbb239 | |||
|
fdb3c792f0 | ||
|
340287ea55 | ||
|
a602155d0b | ||
|
e2e20bab94 | ||
|
097039c34c | ||
|
d7b713fdad | ||
c6cdfdf137 | |||
71d14fa32f |
2104
package-lock.json
generated
2104
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/letterxpress",
|
"name": "@mojoio/letterxpress",
|
||||||
"version": "1.0.2",
|
"version": "1.0.9",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "an unofficial API package for the letterxpress API",
|
"description": "an unofficial API package for the letterxpress API",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@@ -15,12 +15,18 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.0.22",
|
"@gitzone/tsbuild": "^2.0.22",
|
||||||
"@gitzone/tstest": "^1.0.15",
|
"@gitzone/tstest": "^1.0.15",
|
||||||
"@pushrocks/tapbundle": "^3.0.7",
|
"@pushrocks/qenv": "^4.0.6",
|
||||||
"@types/node": "^10.11.7",
|
"@pushrocks/tapbundle": "^3.2.0",
|
||||||
|
"@types/node": "^12.12.11",
|
||||||
"tslint": "^5.11.0",
|
"tslint": "^5.11.0",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
"dependencies": {},
|
"dependencies": {
|
||||||
|
"@pushrocks/smarthash": "^2.1.1",
|
||||||
|
"@pushrocks/smartletter": "^1.0.16",
|
||||||
|
"@pushrocks/smartrequest": "^1.1.43",
|
||||||
|
"@pushrocks/smartrx": "^2.0.5"
|
||||||
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
"ts_web/**/*",
|
"ts_web/**/*",
|
||||||
|
12
readme.md
12
readme.md
@@ -18,6 +18,18 @@ an unofficial API package for the letterxpress API
|
|||||||
|
|
||||||
## Usage
|
## 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
|
## Contribution
|
||||||
|
|
||||||
|
91
test/test.ts
91
test/test.ts
@@ -1,8 +1,95 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import * as letterxpress from '../ts/index';
|
import * as letterxpress from '../ts/index';
|
||||||
|
|
||||||
tap.test('first test', async () => {
|
import * as smartletter from '@pushrocks/smartletter';
|
||||||
console.log(letterxpress.standardExport);
|
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'),
|
||||||
|
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();
|
tap.start();
|
||||||
|
@@ -1,3 +1 @@
|
|||||||
import * as plugins from './letterxpress.plugins';
|
export * from './letterxpress.classes.account';
|
||||||
|
|
||||||
export let standardExport = 'Hi there! :) This is an exported string';
|
|
||||||
|
75
ts/letterxpress.classes.account.ts
Normal file
75
ts/letterxpress.classes.account.ts
Normal file
@@ -0,0 +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;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,2 +1,6 @@
|
|||||||
const removeme = {};
|
import * as smartletter from '@pushrocks/smartletter';
|
||||||
export { removeme };
|
import * as smarthash from '@pushrocks/smarthash';
|
||||||
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
|
import * as smartrx from '@pushrocks/smartrx';
|
||||||
|
|
||||||
|
export { smarthash, smartletter, smartrequest, smartrx };
|
||||||
|
Reference in New Issue
Block a user