fix(core): update

This commit is contained in:
2024-02-16 20:27:14 +01:00
parent 1cf81f86ff
commit 9f70eba74a
8 changed files with 7155 additions and 779 deletions

View File

@ -2,7 +2,7 @@
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@mojoio/letterxpress',
version: '1.0.15',
name: '@apiclient.xyz/letterxpress',
version: '1.0.16',
description: 'an unofficial API package for the letterxpress API'
}

View File

@ -1,5 +1,3 @@
import { IObjectAction } from '@tsclass/tsclass/dist_ts/database/objectaction.js';
import * as plugins from './letterxpress.plugins.js';
export interface ILetterXpressConstructorOptions {
@ -16,9 +14,9 @@ export class LetterXpressAccount {
}
// INSTANCE
public baseApiUrl = 'https://api.letterxpress.de/v1';
public baseApiUrl = 'https://api.letterxpress.de/v2';
public options: ILetterXpressConstructorOptions;
public smartletterInstance: plugins.smartletter.Smartletter;
public deesDocumentInstance: plugins.deesDocument.PdfService;
public letterSentObservable = new plugins.smartrx.rxjs.Subject<plugins.tsclass.business.ILetter>();
@ -28,7 +26,7 @@ export class LetterXpressAccount {
}
public async init() {
this.smartletterInstance = await plugins.smartletter.Smartletter.createAndInit();
this.deesDocumentInstance = await plugins.deesDocument.PdfService.createAndStart({});
}
/**
@ -36,18 +34,17 @@ export class LetterXpressAccount {
* @param letterArg
*/
public async sendLetter(letterArg: plugins.tsclass.business.ILetter) {
const letter = await this.smartletterInstance.createLetterFromData(letterArg);
const pdfToSend = await letter.getCombinedPdf();
const response = await this.request('/setJob', 'POST', {
const pdfToSend = await this.deesDocumentInstance.createPdfFromLetterObject(letterArg);
const response = await this.request('/printjobs', 'POST', {
letter: {
base64_file: plugins.smartbuffer.arrayBufferToBase64(pdfToSend.buffer),
base64_checksum: await plugins.smarthash.md5FromString(
base64_file_checksum: await plugins.smarthash.md5FromString(
plugins.smartbuffer.arrayBufferToBase64(pdfToSend.buffer)
),
specification: {
color: '4',
mode: 'simplex',
ship: letterArg.to.address.country === 'Germany' ? 'national' : 'international',
shipping: letterArg.to.address.country === 'Germany' ? 'national' : 'international',
},
},
});
@ -55,7 +52,7 @@ export class LetterXpressAccount {
name: 'letterxpress-sent',
message: 'requested letterxpress to send the letter',
privateMessage: null,
data: response.body.letter.job_id,
data: response.body.data.id,
timestamp: Date.now(),
userId: null
})
@ -74,9 +71,7 @@ export class LetterXpressAccount {
}
public async cancelLetterByProcessingId(processingId: string) {
const response = await this.request(`/deleteJob/${processingId}`, 'DELETE', {
letter: {}
});
const response = await this.request(`/printjobs/${processingId}`, 'DELETE', {});
return response;
}
@ -88,11 +83,14 @@ export class LetterXpressAccount {
console.log(requestUrl);
const requestData = {
auth: {
mode: "live",
username: this.options.username,
apikey: this.options.apiKey,
},
...payload,
};
// console.log(methodArg);
// console.log(requestData);
const response = await plugins.smartrequest.request(requestUrl, {
method: methodArg,
headers: {
@ -105,6 +103,6 @@ export class LetterXpressAccount {
}
public async stop() {
await this.smartletterInstance.stop();
await this.deesDocumentInstance.stop();
}
}

View File

@ -1,11 +1,17 @@
import * as smartbuffer from '@pushrocks/smartbuffer';
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 smartrx from '@pushrocks/smartrx';
import * as smartbuffer from '@push.rocks/smartbuffer';
import * as smarthash from '@push.rocks/smarthash';
import * as smartpromise from '@push.rocks/smartpromise';
import * as smartrequest from '@push.rocks/smartrequest';
import * as smartrx from '@push.rocks/smartrx';
export { smartbuffer, smarthash, smartletter, smartpromise, smartrequest, smartrx };
export { smartbuffer, smarthash, smartpromise, smartrequest, smartrx };
// @design.estate scope
import * as deesDocument from '@design.estate/dees-document/ts';
export {
deesDocument
}
// tsclass scope
import * as tsclass from '@tsclass/tsclass';