Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
6e5faaef35 | |||
5aa148ef7d | |||
9a08c869ed | |||
37850f92b6 | |||
cf02cd86e5 | |||
d50cb5449a | |||
c40d745f98 | |||
a619fbb239 | |||
|
fdb3c792f0 | ||
|
340287ea55 |
9
.snyk
Normal file
9
.snyk
Normal 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
2078
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@@ -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/**/*",
|
||||
|
12
readme.md
12
readme.md
@@ -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
|
||||
|
||||
|
86
test/test.ts
86
test/test.ts
@@ -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();
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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 };
|
||||
|
Reference in New Issue
Block a user