fix(core): update
This commit is contained in:
parent
275c4351e4
commit
a79362b85a
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,8 +15,6 @@ node_modules/
|
|||||||
|
|
||||||
# builds
|
# builds
|
||||||
dist/
|
dist/
|
||||||
dist_web/
|
dist_*/
|
||||||
dist_serve/
|
|
||||||
dist_ts_web/
|
|
||||||
|
|
||||||
# custom
|
# custom
|
@ -12,6 +12,9 @@ stages:
|
|||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- npm install -g @shipzone/npmci
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
@ -19,22 +22,36 @@ mirror:
|
|||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
- npmci command npm install --production --ignore-scripts
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command snyk test
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
allow_failure: true
|
||||||
|
|
||||||
|
auditDevDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
@ -49,9 +66,7 @@ testStable:
|
|||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- priv
|
|
||||||
|
|
||||||
testBuild:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
@ -62,9 +77,7 @@ testBuild:
|
|||||||
- npmci command npm run build
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
@ -84,11 +97,12 @@ release:
|
|||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g typescript
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
@ -108,11 +122,10 @@ trigger:
|
|||||||
pages:
|
pages:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command npm run buildDocs
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
|
9
.snyk
9
.snyk
@ -1,9 +0,0 @@
|
|||||||
# 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: {}
|
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${relativeFile}"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "test.ts",
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"args": [
|
|
||||||
"test/test.ts"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
8
.vscode/settings.json
vendored
8
.vscode/settings.json
vendored
@ -11,7 +11,13 @@
|
|||||||
},
|
},
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "settings for gitzone"
|
"description": "settings for gitzone",
|
||||||
|
"properties": {
|
||||||
|
"projectType": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
{
|
{
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "mojoio",
|
"gitscope": "mojoio",
|
||||||
"gitrepo": "letterxpress",
|
"gitrepo": "letterxpress",
|
||||||
"shortDescription": "an unofficial API package for the letterxpress API",
|
"description": "an unofficial API package for the letterxpress API",
|
||||||
"npmPackagename": "@mojoio/letterxpress",
|
"npmPackagename": "@mojoio/letterxpress",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"projectDomain": "mojo.io"
|
"projectDomain": "mojo.io"
|
||||||
|
14239
package-lock.json
generated
14239
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
37
package.json
37
package.json
@ -3,39 +3,46 @@
|
|||||||
"version": "1.0.11",
|
"version": "1.0.11",
|
||||||
"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_ts/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild --web)",
|
"build": "(tsbuild --web)",
|
||||||
"format": "(gitzone format)"
|
"format": "(gitzone format)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.0.22",
|
"@gitzone/tsbuild": "^2.1.63",
|
||||||
"@gitzone/tstest": "^1.0.15",
|
"@gitzone/tstest": "^1.0.71",
|
||||||
"@pushrocks/qenv": "^4.0.6",
|
"@pushrocks/qenv": "^4.0.10",
|
||||||
"@pushrocks/tapbundle": "^3.2.0",
|
"@pushrocks/tapbundle": "^5.0.3",
|
||||||
"@types/node": "^12.12.11",
|
"@types/node": "^18.0.0"
|
||||||
"tslint": "^5.11.0",
|
|
||||||
"tslint-config-prettier": "^1.15.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smarthash": "^2.1.1",
|
"@pushrocks/smartbuffer": "^1.0.3",
|
||||||
"@pushrocks/smartletter": "^1.0.16",
|
"@pushrocks/smarthash": "^2.1.10",
|
||||||
"@pushrocks/smartrequest": "^1.1.43",
|
"@pushrocks/smartletter": "^2.0.12",
|
||||||
"@pushrocks/smartrx": "^2.0.5"
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
|
"@pushrocks/smartrequest": "^1.1.56",
|
||||||
|
"@pushrocks/smartrx": "^2.0.25",
|
||||||
|
"@tsclass/tsclass": "^4.0.16"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
"ts_web/**/*",
|
"ts_web/**/*",
|
||||||
"dist/**/*",
|
"dist/**/*",
|
||||||
"dist_web/**/*",
|
"dist_*/**/*",
|
||||||
|
"dist_ts/**/*",
|
||||||
"dist_ts_web/**/*",
|
"dist_ts_web/**/*",
|
||||||
"assets/**/*",
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
|
],
|
||||||
|
"type": "module",
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
27
readme.md
27
readme.md
@ -8,13 +8,20 @@ an unofficial API package for the letterxpress API
|
|||||||
* [docs (typedoc)](https://mojoio.gitlab.io/letterxpress/)
|
* [docs (typedoc)](https://mojoio.gitlab.io/letterxpress/)
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
[![build status](https://gitlab.com/mojoio/letterxpress/badges/master/build.svg)](https://gitlab.com/mojoio/letterxpress/commits/master)
|
|
||||||
[![coverage report](https://gitlab.com/mojoio/letterxpress/badges/master/coverage.svg)](https://gitlab.com/mojoio/letterxpress/commits/master)
|
Status Category | Status Badge
|
||||||
[![npm downloads per month](https://img.shields.io/npm/dm/@mojoio/letterxpress.svg)](https://www.npmjs.com/package/@mojoio/letterxpress)
|
-- | --
|
||||||
[![Known Vulnerabilities](https://snyk.io/test/npm/@mojoio/letterxpress/badge.svg)](https://snyk.io/test/npm/@mojoio/letterxpress)
|
GitLab Pipelines | [![pipeline status](https://gitlab.com/mojoio/letterxpress/badges/master/pipeline.svg)](https://lossless.cloud)
|
||||||
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/mojoio/letterxpress/badges/master/coverage.svg)](https://lossless.cloud)
|
||||||
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
npm | [![npm downloads per month](https://badgen.net/npm/dy/@mojoio/letterxpress)](https://lossless.cloud)
|
||||||
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
|
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/mojoio/letterxpress)](https://lossless.cloud)
|
||||||
|
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
|
||||||
|
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
|
||||||
|
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@mojoio/letterxpress)](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@mojoio/letterxpress)](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@mojoio/letterxpress)](https://lossless.cloud)
|
||||||
|
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@ -23,12 +30,12 @@ Use TypeScript for best in class intellisense.
|
|||||||
letterxpress implements the LXP API documented here: [LXP API Documentation](https://www.letterxpress.de/briefe-uebertragen/api)
|
letterxpress implements the LXP API documented here: [LXP API Documentation](https://www.letterxpress.de/briefe-uebertragen/api)
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import * as letterxpress from '@mojoio/letterxpress'
|
import * as letterxpress from '@mojoio/letterxpress';
|
||||||
|
|
||||||
const account = new letterxpress.LetterXpressAccount({
|
const account = new letterxpress.LetterXpressAccount({
|
||||||
email: 'myemail@example.com',
|
email: 'myemail@example.com',
|
||||||
apiToken: 'abcdefghijklmnop1234567890'
|
apiToken: 'abcdefghijklmnop1234567890',
|
||||||
})
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
## Contribution
|
## Contribution
|
||||||
|
111
test/test.nonci.ts
Normal file
111
test/test.nonci.ts
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
|
import * as letterxpress from '../ts/index.js';
|
||||||
|
import * as tsclass from '@tsclass/tsclass';
|
||||||
|
|
||||||
|
import { Qenv } from '@pushrocks/qenv';
|
||||||
|
let testQenv = new Qenv('./', './.nogit/');
|
||||||
|
|
||||||
|
let testAccount: letterxpress.LetterXpressAccount;
|
||||||
|
let testLetter: tsclass.business.ILetter;
|
||||||
|
|
||||||
|
tap.test('should create a valid account', async () => {
|
||||||
|
testAccount = await letterxpress.LetterXpressAccount.createAndInit({
|
||||||
|
apiKey: testQenv.getEnvVarOnDemand('API_TOKEN'),
|
||||||
|
username: testQenv.getEnvVarOnDemand('API_USERNAME'),
|
||||||
|
});
|
||||||
|
expect(testAccount).toBeInstanceOf(letterxpress.LetterXpressAccount);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should send an actual letter', async () => {
|
||||||
|
testLetter = {
|
||||||
|
from: {
|
||||||
|
name: 'Lossless GmbH',
|
||||||
|
type: 'company',
|
||||||
|
description: 'a company',
|
||||||
|
sepaConnection: {
|
||||||
|
iban: 'NL83 BUNQ 2035 5639 41',
|
||||||
|
bic: 'BUNQNL2AXXX',
|
||||||
|
},
|
||||||
|
address: {
|
||||||
|
name: 'default',
|
||||||
|
city: 'Bremen',
|
||||||
|
country: 'Germany',
|
||||||
|
postalCode: '28359',
|
||||||
|
houseNumber: '5',
|
||||||
|
streetName: 'Karl-Ferdinand-Braun-Str.',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
name: 'Lossless GmbH',
|
||||||
|
type: 'company',
|
||||||
|
description: 'a company',
|
||||||
|
address: {
|
||||||
|
city: 'Bremen',
|
||||||
|
country: 'Germany',
|
||||||
|
postalCode: '28359',
|
||||||
|
streetName: 'Karl-Ferdinand-Braun-Str.',
|
||||||
|
houseNumber: '5',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
incidenceId: 'abc123',
|
||||||
|
legalContact: {
|
||||||
|
type: 'company',
|
||||||
|
salutation: null,
|
||||||
|
surname: null,
|
||||||
|
title: null,
|
||||||
|
address: {
|
||||||
|
city: 'Bremen',
|
||||||
|
country: 'Germany',
|
||||||
|
name: 'Lossless GmbH',
|
||||||
|
postalCode: '28359',
|
||||||
|
streetName: 'Karl-Ferdinand-Braun-Str.',
|
||||||
|
houseNumber: '5',
|
||||||
|
},
|
||||||
|
sepaConnection: {
|
||||||
|
iban: 'NL83 BUNQ 2035 5639 41',
|
||||||
|
bic: 'BUNQNL2AXXX',
|
||||||
|
},
|
||||||
|
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',
|
||||||
|
},
|
||||||
|
subject: 'General Terms - Update',
|
||||||
|
text: [
|
||||||
|
`
|
||||||
|
To whome it may concern,
|
||||||
|
|
||||||
|
**this is a testmessage.** 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.
|
||||||
|
|
||||||
|
Regards
|
||||||
|
Lossless GmbH - Legal Department
|
||||||
|
|
||||||
|
`,
|
||||||
|
],
|
||||||
|
date: Date.now(),
|
||||||
|
language: 'DE',
|
||||||
|
logoUrl: '',
|
||||||
|
needsCoverSheet: true,
|
||||||
|
objectActions: [],
|
||||||
|
pdfAttachments: [],
|
||||||
|
timesheetData: null,
|
||||||
|
};
|
||||||
|
await testAccount.sendLetter(testLetter);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should be able to delete the sending job', async (toolsArg) => {
|
||||||
|
await toolsArg.delayFor(3000);
|
||||||
|
await testAccount.cancelLetter(testLetter);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should wrap things up', async () => {
|
||||||
|
await testAccount.stop();
|
||||||
|
console.log(testLetter);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
95
test/test.ts
95
test/test.ts
@ -1,95 +0,0 @@
|
|||||||
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'),
|
|
||||||
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();
|
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@mojoio/letterxpress',
|
||||||
|
version: '1.0.12',
|
||||||
|
description: 'an unofficial API package for the letterxpress API'
|
||||||
|
}
|
@ -1 +1 @@
|
|||||||
export * from './letterxpress.classes.account';
|
export * from './letterxpress.classes.account.js';
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import * as plugins from './letterxpress.plugins';
|
import { IObjectAction } from '@tsclass/tsclass/dist_ts/database/objectaction.js';
|
||||||
import { response } from 'express';
|
|
||||||
|
import * as plugins from './letterxpress.plugins.js';
|
||||||
|
|
||||||
export interface ILetterXpressConstructorOptions {
|
export interface ILetterXpressConstructorOptions {
|
||||||
username: string;
|
username: string;
|
||||||
@ -7,69 +8,103 @@ export interface ILetterXpressConstructorOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class LetterXpressAccount {
|
export class LetterXpressAccount {
|
||||||
|
// STATIC
|
||||||
|
public static async createAndInit(optionsArg: ConstructorParameters<typeof LetterXpressAccount>[0]) {
|
||||||
|
const letterXpressInstance = new LetterXpressAccount(optionsArg);
|
||||||
|
await letterXpressInstance.init();
|
||||||
|
return letterXpressInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
// INSTANCE
|
||||||
public baseApiUrl = 'https://api.letterxpress.de/v1';
|
public baseApiUrl = 'https://api.letterxpress.de/v1';
|
||||||
public options: ILetterXpressConstructorOptions;
|
public options: ILetterXpressConstructorOptions;
|
||||||
|
public smartletterInstance: plugins.smartletter.Smartletter;
|
||||||
|
|
||||||
public letterSentObservable = new plugins.smartrx.rxjs.Subject<plugins.smartletter.Letter>();
|
public letterSentObservable = new plugins.smartrx.rxjs.Subject<plugins.tsclass.business.ILetter>();
|
||||||
|
|
||||||
constructor(optionsArg: ILetterXpressConstructorOptions) {
|
constructor(optionsArg: ILetterXpressConstructorOptions) {
|
||||||
|
const done = plugins.smartpromise.defer();
|
||||||
this.options = optionsArg;
|
this.options = optionsArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async init() {
|
||||||
|
this.smartletterInstance = await plugins.smartletter.Smartletter.createAndInit();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sends a letter
|
* sends a letter
|
||||||
* @param letterArg
|
* @param letterArg
|
||||||
*/
|
*/
|
||||||
public async sendLetter(letterArg: plugins.smartletter.Letter) {
|
public async sendLetter(letterArg: plugins.tsclass.business.ILetter) {
|
||||||
const letterPdfResult = await letterArg.getPdfResult();
|
const letter = await this.smartletterInstance.createLetterFromData(letterArg);
|
||||||
|
const pdfToSend = await letter.getCombinedPdf();
|
||||||
const response = await this.request('/setJob', 'POST', {
|
const response = await this.request('/setJob', 'POST', {
|
||||||
letter: {
|
letter: {
|
||||||
base64_file: letterPdfResult.buffer.toString('base64'),
|
base64_file: plugins.smartbuffer.arrayBufferToBase64(pdfToSend.buffer),
|
||||||
base64_checksum: await plugins.smarthash.md5FromString(
|
base64_checksum: await plugins.smarthash.md5FromString(
|
||||||
letterPdfResult.buffer.toString('base64')
|
plugins.smartbuffer.arrayBufferToBase64(pdfToSend.buffer)
|
||||||
),
|
),
|
||||||
specification: {
|
specification: {
|
||||||
color: '4',
|
color: '4',
|
||||||
mode: 'simplex',
|
mode: 'simplex',
|
||||||
ship: letterArg.options.to.country === 'Germany' ? 'national' : 'international'
|
ship: letterArg.to.address.country === 'Germany' ? 'national' : 'international',
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
letterArg.setProcessingId(response.body.letter.job_id);
|
letterArg.objectActions.push({
|
||||||
|
name: 'letterxpress-sent',
|
||||||
|
message: 'requested letterxpress to send the letter',
|
||||||
|
privateMessage: null,
|
||||||
|
data: response.body.letter.job_id,
|
||||||
|
timestamp: Date.now(),
|
||||||
|
userId: null
|
||||||
|
})
|
||||||
return letterArg;
|
return letterArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async cancelLetter(letterArg: plugins.smartletter.Letter) {
|
public async cancelLetter(letterArg: plugins.tsclass.business.ILetter) {
|
||||||
const processingId = letterArg.getProcessingId();
|
const processingId = letterArg.objectActions.reduce<string>((previousVal, currentVal) => {
|
||||||
|
if (currentVal.name === 'letterxpress-sent') {
|
||||||
|
return currentVal.data
|
||||||
|
} else {
|
||||||
|
return previousVal;
|
||||||
|
}
|
||||||
|
}, null);
|
||||||
return await this.cancelLetterByProcessingId(processingId);
|
return await this.cancelLetterByProcessingId(processingId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async cancelLetterByProcessingId(processingId: string) {
|
public async cancelLetterByProcessingId(processingId: string) {
|
||||||
const response = await this.request(`/deleteJob/${processingId}`, 'DELETE');
|
const response = await this.request(`/deleteJob/${processingId}`, 'DELETE', {
|
||||||
|
letter: {}
|
||||||
|
});
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fires the request
|
* fires the request
|
||||||
*/
|
*/
|
||||||
private async request(routeArg: string, methodArg: 'GET' | 'POST' | 'DELETE', payload: any = {}) {
|
private async request(routeArg: string, methodArg: 'GET' | 'POST' | 'DELETE', payload: any) {
|
||||||
const requestUrl = `${this.baseApiUrl}${routeArg}`;
|
const requestUrl = `${this.baseApiUrl}${routeArg}`;
|
||||||
console.log(requestUrl);
|
console.log(requestUrl);
|
||||||
const requestData = {
|
const requestData = {
|
||||||
auth: {
|
auth: {
|
||||||
username: this.options.username,
|
username: this.options.username,
|
||||||
apikey: this.options.apiKey
|
apikey: this.options.apiKey,
|
||||||
},
|
},
|
||||||
...payload
|
...payload,
|
||||||
};
|
};
|
||||||
const response = await plugins.smartrequest.request(requestUrl, {
|
const response = await plugins.smartrequest.request(requestUrl, {
|
||||||
method: methodArg,
|
method: methodArg,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
requestBody: JSON.stringify(requestData)
|
requestBody: JSON.stringify(requestData),
|
||||||
});
|
});
|
||||||
console.log(response.body);
|
console.log(response.body);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async stop() {
|
||||||
|
await this.smartletterInstance.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,15 @@
|
|||||||
import * as smartletter from '@pushrocks/smartletter';
|
import * as smartbuffer from '@pushrocks/smartbuffer';
|
||||||
import * as smarthash from '@pushrocks/smarthash';
|
import * as smarthash from '@pushrocks/smarthash';
|
||||||
|
import * as smartletter from '@pushrocks/smartletter';
|
||||||
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
import * as smartrequest from '@pushrocks/smartrequest';
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
import * as smartrx from '@pushrocks/smartrx';
|
import * as smartrx from '@pushrocks/smartrx';
|
||||||
|
|
||||||
export { smarthash, smartletter, smartrequest, smartrx };
|
export { smartbuffer, smarthash, smartletter, smartpromise, smartrequest, smartrx };
|
||||||
|
|
||||||
|
// tsclass scope
|
||||||
|
import * as tsclass from '@tsclass/tsclass';
|
||||||
|
|
||||||
|
export {
|
||||||
|
tsclass
|
||||||
|
}
|
||||||
|
9
tsconfig.json
Normal file
9
tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext"
|
||||||
|
}
|
||||||
|
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"],
|
|
||||||
"no-console": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"member-ordering": {
|
|
||||||
"options":{
|
|
||||||
"order": [
|
|
||||||
"static-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user