@kevludwig/lexware-office 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +6 -0
- package/dist/client.js +4 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/vouchers.d.ts +6 -0
- package/dist/vouchers.js +9 -0
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -21,6 +21,12 @@ export interface LexwareClientOptions {
|
|
|
21
21
|
minSpacingMs?: number;
|
|
22
22
|
/** Time limit per request in ms, counted from when it actually fires. Default: 20 000. */
|
|
23
23
|
timeoutMs?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Time limit for file uploads in ms. A scan of a few MB can take Lexware
|
|
26
|
+
* longer than a JSON call to accept — an early abort reports a failure for
|
|
27
|
+
* a file that arrives anyway. Default: 120 000.
|
|
28
|
+
*/
|
|
29
|
+
uploadTimeoutMs?: number;
|
|
24
30
|
/** Wait before retrying a request answered with 429, in ms. Default: 1 000. */
|
|
25
31
|
rateLimitBackoffMs?: number;
|
|
26
32
|
/** A fetch implementation, e.g. for tests. Default: the global fetch. */
|
package/dist/client.js
CHANGED
|
@@ -61,6 +61,7 @@ export function createLexwareClient(options) {
|
|
|
61
61
|
const appUrl = (options.appUrl ?? DEFAULT_APP_URL).replace(/\/+$/, "");
|
|
62
62
|
const minSpacingMs = options.minSpacingMs ?? 550;
|
|
63
63
|
const timeoutMs = options.timeoutMs ?? 20_000;
|
|
64
|
+
const uploadTimeoutMs = options.uploadTimeoutMs ?? 120_000;
|
|
64
65
|
const backoffMs = options.rateLimitBackoffMs ?? 1_000;
|
|
65
66
|
const fetchImpl = options.fetch ?? fetch;
|
|
66
67
|
// The queue: each request waits for the previous one to start plus the
|
|
@@ -84,10 +85,10 @@ export function createLexwareClient(options) {
|
|
|
84
85
|
* demonstrably did not run it. A transport error after a POST is never
|
|
85
86
|
* retried: the voucher may well exist already.
|
|
86
87
|
*/
|
|
87
|
-
async function send(path, init) {
|
|
88
|
+
async function send(path, init, limitMs = timeoutMs) {
|
|
88
89
|
const method = init.method ?? "GET";
|
|
89
90
|
const fire = () => schedule(() => {
|
|
90
|
-
const timeout = AbortSignal.timeout(
|
|
91
|
+
const timeout = AbortSignal.timeout(limitMs);
|
|
91
92
|
return fetchImpl(`${baseUrl}${path}`, {
|
|
92
93
|
...init,
|
|
93
94
|
headers: { Authorization: `Bearer ${options.apiKey}`, Accept: "application/json", ...init.headers },
|
|
@@ -134,7 +135,7 @@ export function createLexwareClient(options) {
|
|
|
134
135
|
// An own ArrayBuffer: Blob refuses shared buffers.
|
|
135
136
|
form.set("file", new Blob([Uint8Array.from(file.bytes)], { type: file.mediaType }), file.filename);
|
|
136
137
|
// No Content-Type: fetch sets the multipart boundary.
|
|
137
|
-
return json(await send(path, { ...init, method: "POST", body: form }));
|
|
138
|
+
return json(await send(path, { ...init, method: "POST", body: form }, uploadTimeoutMs));
|
|
138
139
|
},
|
|
139
140
|
voucherUrl(id) {
|
|
140
141
|
return `${appUrl}/vouchers#!/VoucherDetail/${id}`;
|
package/dist/index.d.ts
CHANGED
|
@@ -7,5 +7,5 @@ export { MailNotSentError, defaultReminderMail, reminderSubject, type ReminderMa
|
|
|
7
7
|
export { keySegment, memoryStore, type JsonStore } from "./store.ts";
|
|
8
8
|
export { DUPLICATE_TOTAL_TOLERANCE, ITEMS_TOTAL_TOLERANCE, netTotal, round2, taxFromGross, taxFromNet, type PricedLine, } from "./money.ts";
|
|
9
9
|
export { REVERSE_CHARGE_TAX_RATE, isReverseChargeCategory, listPostingCategories, resolveCategory, type PostingCategory, } from "./categories.ts";
|
|
10
|
-
export { createVoucher, findPurchaseInvoiceByNumber, findVendorCategoryHistory, findVouchers, uploadVoucherFile, type CategoryHistory, type CreateVoucherOptions, type CreatedVoucher, type VoucherItem, type VoucherListEntry, type VoucherListFilter, type VoucherStatus, type VoucherTaxType, type VoucherType, } from "./vouchers.ts";
|
|
10
|
+
export { createVoucher, findPurchaseInvoiceByNumber, findVendorCategoryHistory, findVouchers, uploadVoucherFile, voucherFileIds, type CategoryHistory, type CreateVoucherOptions, type CreatedVoucher, type VoucherItem, type VoucherListEntry, type VoucherListFilter, type VoucherStatus, type VoucherTaxType, type VoucherType, } from "./vouchers.ts";
|
|
11
11
|
export { SALES_DOCUMENT_STATUSES, VOUCHERLIST_TYPE, createSalesDocument, findDuplicateSalesDocument, findRecentSalesDocuments, getSalesDocument, invoiceExists, isPursueRejection, type CreatedSalesDocument, type DuplicateSearchResult, type LineItem, type SalesDocumentDetail, type SalesDocumentKind, type SalesListEntry, } from "./sales-documents.ts";
|
package/dist/index.js
CHANGED
|
@@ -7,5 +7,5 @@ export { MailNotSentError, defaultReminderMail, reminderSubject, } from "./remin
|
|
|
7
7
|
export { keySegment, memoryStore } from "./store.js";
|
|
8
8
|
export { DUPLICATE_TOTAL_TOLERANCE, ITEMS_TOTAL_TOLERANCE, netTotal, round2, taxFromGross, taxFromNet, } from "./money.js";
|
|
9
9
|
export { REVERSE_CHARGE_TAX_RATE, isReverseChargeCategory, listPostingCategories, resolveCategory, } from "./categories.js";
|
|
10
|
-
export { createVoucher, findPurchaseInvoiceByNumber, findVendorCategoryHistory, findVouchers, uploadVoucherFile, } from "./vouchers.js";
|
|
10
|
+
export { createVoucher, findPurchaseInvoiceByNumber, findVendorCategoryHistory, findVouchers, uploadVoucherFile, voucherFileIds, } from "./vouchers.js";
|
|
11
11
|
export { SALES_DOCUMENT_STATUSES, VOUCHERLIST_TYPE, createSalesDocument, findDuplicateSalesDocument, findRecentSalesDocuments, getSalesDocument, invoiceExists, isPursueRejection, } from "./sales-documents.js";
|
package/dist/vouchers.d.ts
CHANGED
|
@@ -59,6 +59,12 @@ export declare function createVoucher(client: LexwareClient, options: CreateVouc
|
|
|
59
59
|
export declare function uploadVoucherFile(client: LexwareClient, voucherId: string, file: FileUpload, signal?: AbortSignal): Promise<{
|
|
60
60
|
id: string;
|
|
61
61
|
}>;
|
|
62
|
+
/**
|
|
63
|
+
* The ids of the files attached to a voucher. After an upload that ended in
|
|
64
|
+
* a timeout or a dropped connection this tells whether the file arrived
|
|
65
|
+
* anyway — Lexware often finishes after the client has given up.
|
|
66
|
+
*/
|
|
67
|
+
export declare function voucherFileIds(client: LexwareClient, voucherId: string, signal?: AbortSignal): Promise<string[]>;
|
|
62
68
|
export interface VoucherListEntry {
|
|
63
69
|
id: string;
|
|
64
70
|
voucherType: string;
|
package/dist/vouchers.js
CHANGED
|
@@ -46,6 +46,15 @@ export async function createVoucher(client, options, signal) {
|
|
|
46
46
|
export async function uploadVoucherFile(client, voucherId, file, signal) {
|
|
47
47
|
return client.upload(`/vouchers/${encodeURIComponent(voucherId)}/files`, file, { signal });
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* The ids of the files attached to a voucher. After an upload that ended in
|
|
51
|
+
* a timeout or a dropped connection this tells whether the file arrived
|
|
52
|
+
* anyway — Lexware often finishes after the client has given up.
|
|
53
|
+
*/
|
|
54
|
+
export async function voucherFileIds(client, voucherId, signal) {
|
|
55
|
+
const voucher = await client.request(`/vouchers/${encodeURIComponent(voucherId)}`, { signal });
|
|
56
|
+
return voucher.files ?? [];
|
|
57
|
+
}
|
|
49
58
|
/** The voucher list — the one search across all voucher types. Newest first, 50 by default. */
|
|
50
59
|
export async function findVouchers(client, filter, signal) {
|
|
51
60
|
const page = await client.request(`/voucherlist${query({ size: 50, sort: "voucherDate,DESC", ...filter })}`, { signal });
|
package/package.json
CHANGED