@kreiseck/kasseneck-api 1.7.1 → 1.8.0
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/CHANGELOG.md +106 -0
- package/README.md +170 -1
- package/dist/cjs/client/aufrufe.d.ts +9 -7
- package/dist/cjs/client/aufrufe.js +57 -2
- package/dist/cjs/client/errors.js +2 -0
- package/dist/cjs/client/index.d.ts +1 -1
- package/dist/cjs/client/index.js +2 -1
- package/dist/cjs/client/transport.d.ts +27 -3
- package/dist/cjs/client/transport.js +29 -3
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +3 -2
- package/dist/cjs/inventory/api.d.ts +21 -2
- package/dist/cjs/inventory/api.js +22 -3
- package/dist/cjs/inventory/fehler.d.ts +6 -0
- package/dist/cjs/inventory/fehler.js +12 -0
- package/dist/cjs/inventory/index.d.ts +6 -4
- package/dist/cjs/inventory/index.js +33 -3
- package/dist/cjs/inventory/inventur.d.ts +104 -0
- package/dist/cjs/inventory/inventur.js +245 -0
- package/dist/cjs/inventory/lesen.d.ts +20 -1
- package/dist/cjs/inventory/lesen.js +307 -0
- package/dist/cjs/inventory/typen.d.ts +410 -1
- package/dist/cjs/inventory/vertrag.d.ts +94 -8
- package/dist/cjs/inventory/vertrag.js +117 -5
- package/dist/cjs/invoice/vertrag.d.ts +1 -1
- package/dist/cjs/invoice/vertrag.js +2 -0
- package/dist/cjs/models/cancellation.d.ts +1 -1
- package/dist/cjs/models/cancellation.js +2 -0
- package/dist/cjs/models/payment-errors.d.ts +1 -1
- package/dist/cjs/models/payment-errors.js +2 -0
- package/dist/cjs/models/receipt-email.d.ts +1 -1
- package/dist/cjs/models/receipt-email.js +2 -0
- package/dist/cjs/models/receipt-errors.d.ts +1 -1
- package/dist/cjs/models/receipt-errors.js +2 -0
- package/dist/cjs/pos/errors.d.ts +4 -3
- package/dist/cjs/pos/errors.js +23 -2
- package/dist/cjs/pos/index.d.ts +4 -1
- package/dist/cjs/pos/index.js +9 -2
- package/dist/cjs/pos/inventur.d.ts +104 -0
- package/dist/cjs/pos/inventur.js +117 -0
- package/dist/cjs/pos/texte.d.ts +82 -0
- package/dist/cjs/pos/texte.js +35 -0
- package/dist/cjs/register/errors.d.ts +1 -1
- package/dist/cjs/register/errors.js +2 -0
- package/dist/cjs/stored/vokabular.d.ts +1 -1
- package/dist/cjs/stored/vokabular.js +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/client/aufrufe.d.ts +9 -7
- package/dist/esm/client/aufrufe.js +57 -2
- package/dist/esm/client/errors.js +2 -0
- package/dist/esm/client/index.d.ts +1 -1
- package/dist/esm/client/index.js +1 -1
- package/dist/esm/client/transport.d.ts +27 -3
- package/dist/esm/client/transport.js +28 -3
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/inventory/api.d.ts +21 -2
- package/dist/esm/inventory/api.js +23 -4
- package/dist/esm/inventory/fehler.d.ts +6 -0
- package/dist/esm/inventory/fehler.js +11 -0
- package/dist/esm/inventory/index.d.ts +6 -4
- package/dist/esm/inventory/index.js +5 -3
- package/dist/esm/inventory/inventur.d.ts +104 -0
- package/dist/esm/inventory/inventur.js +226 -0
- package/dist/esm/inventory/lesen.d.ts +20 -1
- package/dist/esm/inventory/lesen.js +301 -0
- package/dist/esm/inventory/typen.d.ts +410 -1
- package/dist/esm/inventory/vertrag.d.ts +94 -8
- package/dist/esm/inventory/vertrag.js +116 -4
- package/dist/esm/invoice/vertrag.d.ts +1 -1
- package/dist/esm/invoice/vertrag.js +2 -0
- package/dist/esm/models/cancellation.d.ts +1 -1
- package/dist/esm/models/cancellation.js +2 -0
- package/dist/esm/models/payment-errors.d.ts +1 -1
- package/dist/esm/models/payment-errors.js +2 -0
- package/dist/esm/models/receipt-email.d.ts +1 -1
- package/dist/esm/models/receipt-email.js +2 -0
- package/dist/esm/models/receipt-errors.d.ts +1 -1
- package/dist/esm/models/receipt-errors.js +2 -0
- package/dist/esm/pos/errors.d.ts +4 -3
- package/dist/esm/pos/errors.js +23 -2
- package/dist/esm/pos/index.d.ts +4 -1
- package/dist/esm/pos/index.js +2 -1
- package/dist/esm/pos/inventur.d.ts +104 -0
- package/dist/esm/pos/inventur.js +109 -0
- package/dist/esm/pos/texte.d.ts +82 -0
- package/dist/esm/pos/texte.js +35 -0
- package/dist/esm/register/errors.d.ts +1 -1
- package/dist/esm/register/errors.js +2 -0
- package/dist/esm/stored/vokabular.d.ts +1 -1
- package/dist/esm/stored/vokabular.js +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/fixtures/hobex-hps-codes.json +1 -1
- package/fixtures/invoice-api.schema.json +1 -1
- package/fixtures/invoice-texts.json +1 -1
- package/fixtures/pos-texts.json +94 -1
- package/fixtures/stocktake-quantity-cases.json +55 -0
- package/fixtures/surface.json +151 -8
- package/fixtures/v3/antworten/belege.json +1 -1
- package/fixtures/v3/antworten/belegmail.json +1 -1
- package/fixtures/v3/antworten/kasse-belege.json +1 -1
- package/fixtures/v3/antworten/kasse.json +2958 -3
- package/fixtures/v3/antworten/lager.json +1727 -3
- package/fixtures/v3/antworten/rechnungen.json +1 -1
- package/fixtures/v3/antworten/storno.json +1 -1
- package/fixtures/v3/stored/belege.json +1 -1
- package/fixtures/v3/stored/kasse.json +414 -3
- package/fixtures/v3/stored/rechnungen.json +1 -1
- package/fixtures/v3/v3-vokabular.json +475 -8
- package/fixtures/v3/zahlbetrag-faelle.json +1 -1
- package/package.json +1 -1
|
@@ -93,7 +93,19 @@ export function createBinaryTransport(options) {
|
|
|
93
93
|
return (functionName, params) => kern(functionName, params, undefined, undefined, undefined, alsBytes, pdfAuswerten);
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
|
-
*
|
|
96
|
+
* Dritter Einstiegspunkt, fuer Aufrufe, die eine Datei oder eine Nutzlast
|
|
97
|
+
* liefern (`getStocktakePdf` aus `./inventory`). Wie [createBinaryTransport]
|
|
98
|
+
* wird die Antwort nur als Bytes gelesen; die ersten Bytes entscheiden: `%PDF`
|
|
99
|
+
* ergibt `{ pdf }`, eine Erfolgshuelle `{ data }`, eine Fehlerhuelle denselben
|
|
100
|
+
* fachlichen Fehler wie auf dem JSON-Weg. Leer, kein JSON oder ohne Statusfeld
|
|
101
|
+
* ist unlesbar mit denselben Gruenden wie dort.
|
|
102
|
+
*/
|
|
103
|
+
export function createPdfOrDataTransport(options) {
|
|
104
|
+
const kern = createCore(options);
|
|
105
|
+
return (functionName, params) => kern(functionName, params, undefined, undefined, undefined, alsBytes, pdfOderDatenAuswerten);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Gemeinsamer Kern aller Einstiegspunkte: Anmeldung, Zeitlimit, Anfrage und
|
|
97
109
|
* HTTP-Status. Was danach mit dem Rumpf geschieht, entscheiden `lesen` und
|
|
98
110
|
* `auswerten`.
|
|
99
111
|
*/
|
|
@@ -107,9 +119,9 @@ function createCore(options) {
|
|
|
107
119
|
pruefeKennung(kennung);
|
|
108
120
|
const kopfzeilenSenden = options.omitKasseneckHeaders !== true;
|
|
109
121
|
/**
|
|
110
|
-
* Basis je Aufruf. Die
|
|
122
|
+
* Basis je Aufruf. Die 27 reinen Kassenaufrufe gehen immer an den
|
|
111
123
|
* Kassenweg (unter der oeffentlichen Basis gibt es sie nicht), und die
|
|
112
|
-
* Kassen-Anmeldung ruft alle
|
|
124
|
+
* Kassen-Anmeldung ruft alle 33 Aufrufe des Kassenwegs dort, auch die sechs
|
|
113
125
|
* oeffentlichen (Kanal `app`). Was der Kassenweg gar nicht fuehrt
|
|
114
126
|
* (Berichte, Zahlungen, FinanzOnline), geht an die oeffentliche Basis.
|
|
115
127
|
*/
|
|
@@ -431,6 +443,19 @@ function pdfAuswerten(bytes, functionName, statusCode, inhaltstyp, geheimnisse,
|
|
|
431
443
|
// es keinen Unterschied, ob er ein PDF oder eine Nutzlast erwartet hat.
|
|
432
444
|
throw fachfehler(functionName, huelle.message, huelle.data, geheimnisse, huelle.code);
|
|
433
445
|
}
|
|
446
|
+
/**
|
|
447
|
+
* Auswertung von [createPdfOrDataTransport]: ein PDF geht als Bytes zurueck,
|
|
448
|
+
* eine Erfolgshuelle als ihre `data`, eine Fehlerhuelle als derselbe
|
|
449
|
+
* fachliche Fehler wie auf dem JSON-Weg. Alles andere (leer, kein JSON, ohne
|
|
450
|
+
* Statusfeld) ist unlesbar mit denselben Gruenden wie dort.
|
|
451
|
+
*/
|
|
452
|
+
function pdfOderDatenAuswerten(bytes, functionName, statusCode, inhaltstyp, geheimnisse, unlesbar) {
|
|
453
|
+
if (istPdf(bytes)) {
|
|
454
|
+
return { pdf: bytes };
|
|
455
|
+
}
|
|
456
|
+
const text = new TextDecoder('utf-8').decode(bytes);
|
|
457
|
+
return { data: jsonAuswerten(text, functionName, statusCode, inhaltstyp, geheimnisse, unlesbar) };
|
|
458
|
+
}
|
|
434
459
|
/** `%PDF` am Anfang — die Kennung jeder PDF-Datei. */
|
|
435
460
|
function istPdf(bytes) {
|
|
436
461
|
return bytes.length >= 4 && bytes[0] === 0x25 && bytes[1] === 0x50 && bytes[2] === 0x44 && bytes[3] === 0x46;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { ReceiptType, type ReceiptTypeKey, VatRate, type VatRateKey, KeckPaymentMethod, type KeckPaymentMethodKey, CreditCardProvider, type CreditCardProviderKey, VoucherType, type VoucherTypeKey, VoucherAction, type VoucherActionKey, StripeLinkMode, type StripeLinkModeKey, } from './enums/index.js';
|
|
2
2
|
export { type ReceiptItem, type ReceiptItemPayload, type ReceiptItemPayloadRead, toReceiptItemPayload, fromReceiptItemPayload, receiptItemTotalCents, receiptItemIsValid, negateReceiptItem, type TipRecipient, isTipItem, type Voucher, type VoucherPayload, toVoucherPayload, fromVoucherPayload, voucherIsValid, type Receipt, type RegistrationInfo, type ReceiptPayload, type ReceiptPayloadRead, toReceiptPayload, fromReceiptPayload, receiptSubSumCents, receiptSumCents, type CancellationOf, type CancellationItem, type Cancellation, type CancellationReason, type CancellationErrorCode, type CancellationStatus, type ReturnDisposition, RETURN_DISPOSITIONS, CANCELLATION_REASONS, CANCELLATION_STATUSES, CANCELLATION_ERROR_CODES, CANCELLATION_RESERVATION_MS, isCancellationReason, isReturnDisposition, isCancellationErrorCode, cancellationErrorCode, isCancellationError, cancellationFieldErrors, type CancellationFieldError, type ReceiptPayment, type ReceiptPaymentPayload, type ReceiptPaymentInput, fromReceiptPaymentPayload, toReceiptPaymentPayload, type PaymentErrorCode, PAYMENT_ERROR_CODES, isPaymentErrorCode, paymentErrorCode, isPaymentError, paymentFieldErrors, type PaymentFieldError, type ReceiptEmailErrorCode, type ReceiptEmailVia, RECEIPT_EMAIL_ERROR_CODES, RECEIPT_EMAIL_SEND_ERROR_CODES, type ReceiptEmailSendErrorCode, RECEIPT_EMAIL_VIAS, isReceiptEmailErrorCode, receiptEmailErrorCode, isReceiptEmailError, receiptEmailFieldErrors, type ReceiptEmailFieldError, type ReceiptErrorCode, type ReceiptFieldError, RECEIPT_ERROR_CODES, isReceiptErrorCode, receiptErrorCode, isReceiptError, receiptFieldErrors, remainingQuantities, type ReceiptCompany, type ReceiptCompanyPayload, fromReceiptCompanyPayload, receiptCompanyTaxInfo, type Cashregister, type CashregisterOnboarding, type CashregisterPayload, type CashregisterOnboardingPayload, type CashregisterAutoLogout, type CashregisterAutoLogoutPayload, fromCashregisterPayload, type ReceiptSummary, type ReceiptSummaryPayload, fromReceiptSummaryPayload, type ZeroKind, ZERO_KINDS, isZeroKind, type ReportMonth, reportMonthFromDate, previousReportMonth, nextReportMonth, reportMonthKey, reportMonthReadable, type StripeUrlSession, type StripeUrlSessionPayload, toStripeUrlSessionPayload, fromStripeUrlSessionPayload, type HobexReceipt, type HobexReceiptPayload, toHobexReceiptPayload, fromHobexReceiptPayload, hobexReceiptToCardPaymentData, hobexReceiptNeedsSignature, } from './models/index.js';
|
|
3
|
-
export { type AuthCredentials, type KasseneckAuth, type ApiKeyAuthOptions, type RegisterUserAuthOptions, apiKeyAuth, registerUserAuth, DEFAULT_BASE_URL, POS_BASE_URL, DEFAULT_TIMEOUT_MS, type HttpResponseLike, type HttpRequestInit, type FetchLike, type TransportOptions, type TransportBodyFields, type TransportCallOptions, type KasseneckTransport, type KasseneckBinaryTransport, ALL_CALLS, type ApiCall, PUBLIC_CALLS, POS_CALLS, UNKNOWN_OUTCOME_CALLS, type PublicCall, type PosCall, createTransport, createBinaryTransport, KasseneckApiError, KasseneckAuthError, KasseneckHttpError, KasseneckNetworkError, KasseneckValidationError, type ValidationScope, type KasseneckError, type HttpFailureReason, type CauseDigest, type ErrorOutcome, CLIENT_ERROR_CODES, type ClientErrorCode, isKasseneckApiError, isKasseneckAuthError, isKasseneckHttpError, isKasseneckNetworkError, isKasseneckValidationError, isOutcomeUnknown, type ReceiptCommonOptions, type SellReceiptOptions, type TipOptions, type TipRecipientShare, type CancelReceiptOptions, type CancelReceiptResult, type ReceiptWithCompany, sellReceipt, sellReceiptWithCompany, paymentsExpectedCents, cardRefundReference, receiptLayoutFromResult, cancelReceipt, zeroReceipt, getReceipt, getReceiptWithCompany, generateFullReceiptId, getFirstReceiptDate, listMyReceipts, type ListMyReceiptsOptions, type ReceiptList, type ReceiptListStats, listMyCashregisters, checkVoucherCombinationError, type SendReceiptEmailOptions, type SendReceiptEmailResult, sendReceiptEmail, downloadDailyReport, downloadMonthlyReport, getReportV2, type ReportV2, type ReportV2Metadata, type ReportV2Options, type CashboxStatus, type SignatureStatus, getCashboxStatus, getSignatureStatus, type KasseneckApi, createKasseneckApi, } from './client/index.js';
|
|
3
|
+
export { type AuthCredentials, type KasseneckAuth, type ApiKeyAuthOptions, type RegisterUserAuthOptions, apiKeyAuth, registerUserAuth, DEFAULT_BASE_URL, POS_BASE_URL, DEFAULT_TIMEOUT_MS, type HttpResponseLike, type HttpRequestInit, type FetchLike, type TransportOptions, type TransportBodyFields, type TransportCallOptions, type KasseneckTransport, type KasseneckBinaryTransport, type KasseneckPdfOrDataTransport, type PdfOrData, ALL_CALLS, type ApiCall, PUBLIC_CALLS, POS_CALLS, UNKNOWN_OUTCOME_CALLS, type PublicCall, type PosCall, createTransport, createBinaryTransport, createPdfOrDataTransport, KasseneckApiError, KasseneckAuthError, KasseneckHttpError, KasseneckNetworkError, KasseneckValidationError, type ValidationScope, type KasseneckError, type HttpFailureReason, type CauseDigest, type ErrorOutcome, CLIENT_ERROR_CODES, type ClientErrorCode, isKasseneckApiError, isKasseneckAuthError, isKasseneckHttpError, isKasseneckNetworkError, isKasseneckValidationError, isOutcomeUnknown, type ReceiptCommonOptions, type SellReceiptOptions, type TipOptions, type TipRecipientShare, type CancelReceiptOptions, type CancelReceiptResult, type ReceiptWithCompany, sellReceipt, sellReceiptWithCompany, paymentsExpectedCents, cardRefundReference, receiptLayoutFromResult, cancelReceipt, zeroReceipt, getReceipt, getReceiptWithCompany, generateFullReceiptId, getFirstReceiptDate, listMyReceipts, type ListMyReceiptsOptions, type ReceiptList, type ReceiptListStats, listMyCashregisters, checkVoucherCombinationError, type SendReceiptEmailOptions, type SendReceiptEmailResult, sendReceiptEmail, downloadDailyReport, downloadMonthlyReport, getReportV2, type ReportV2, type ReportV2Metadata, type ReportV2Options, type CashboxStatus, type SignatureStatus, getCashboxStatus, getSignatureStatus, type KasseneckApi, createKasseneckApi, } from './client/index.js';
|
|
4
4
|
export { type ReceiptDueTip, type ReceiptDueTipRecipient, type ReceiptDueOptions, type ReceiptDueBuckets, type ReceiptDueBreakdown, type ReceiptDueErrorReason, receiptDueCents, receiptDueBreakdown, ReceiptDueError, RECEIPT_DUE_ERROR_REASONS, isReceiptDueError, } from './receipt/due.js';
|
|
5
5
|
export { parseServerTimeStamp, toViennaWallClock, type ViennaWallClock } from './vienna-time.js';
|
|
6
6
|
export { type PosBusinessSettings, type PosDeviceSettings, type PosSettings, type ArticleGroup, type PosArticle, POS_BUSINESS_DEFAULTS, POS_DEVICE_DEFAULTS, mergePosSettings, fromArticleGroupPayload, fromPosArticlePayload, listMyArticleGroups, listMyArticles, getPosSettings, setMyPosSettings, setMyRegisterDeviceSettings, distributeDiscount, cancelScopeOf, receiptsScopeOf, stockViewOf, } from './pos/index.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { ReceiptType, VatRate, KeckPaymentMethod, CreditCardProvider, VoucherType, VoucherAction, StripeLinkMode, } from './enums/index.js';
|
|
2
2
|
export { toReceiptItemPayload, fromReceiptItemPayload, receiptItemTotalCents, receiptItemIsValid, negateReceiptItem, isTipItem, toVoucherPayload, fromVoucherPayload, voucherIsValid, toReceiptPayload, fromReceiptPayload, receiptSubSumCents, receiptSumCents, RETURN_DISPOSITIONS, CANCELLATION_REASONS, CANCELLATION_STATUSES, CANCELLATION_ERROR_CODES, CANCELLATION_RESERVATION_MS, isCancellationReason, isReturnDisposition, isCancellationErrorCode, cancellationErrorCode, isCancellationError, cancellationFieldErrors, fromReceiptPaymentPayload, toReceiptPaymentPayload, PAYMENT_ERROR_CODES, isPaymentErrorCode, paymentErrorCode, isPaymentError, paymentFieldErrors, RECEIPT_EMAIL_ERROR_CODES, RECEIPT_EMAIL_SEND_ERROR_CODES, RECEIPT_EMAIL_VIAS, isReceiptEmailErrorCode, receiptEmailErrorCode, isReceiptEmailError, receiptEmailFieldErrors, RECEIPT_ERROR_CODES, isReceiptErrorCode, receiptErrorCode, isReceiptError, receiptFieldErrors, remainingQuantities, fromReceiptCompanyPayload, receiptCompanyTaxInfo, fromCashregisterPayload, fromReceiptSummaryPayload, ZERO_KINDS, isZeroKind, reportMonthFromDate, previousReportMonth, nextReportMonth, reportMonthKey, reportMonthReadable, toStripeUrlSessionPayload, fromStripeUrlSessionPayload, toHobexReceiptPayload, fromHobexReceiptPayload, hobexReceiptToCardPaymentData, hobexReceiptNeedsSignature, } from './models/index.js';
|
|
3
|
-
export { apiKeyAuth, registerUserAuth, DEFAULT_BASE_URL, POS_BASE_URL, DEFAULT_TIMEOUT_MS, ALL_CALLS, PUBLIC_CALLS, POS_CALLS, UNKNOWN_OUTCOME_CALLS, createTransport, createBinaryTransport, KasseneckApiError, KasseneckAuthError, KasseneckHttpError, KasseneckNetworkError, KasseneckValidationError, CLIENT_ERROR_CODES, isKasseneckApiError, isKasseneckAuthError, isKasseneckHttpError, isKasseneckNetworkError, isKasseneckValidationError, isOutcomeUnknown, sellReceipt, sellReceiptWithCompany, paymentsExpectedCents, cardRefundReference, receiptLayoutFromResult, cancelReceipt, zeroReceipt, getReceipt, getReceiptWithCompany, generateFullReceiptId, getFirstReceiptDate, listMyReceipts, listMyCashregisters, checkVoucherCombinationError, sendReceiptEmail, downloadDailyReport, downloadMonthlyReport, getReportV2, getCashboxStatus, getSignatureStatus, createKasseneckApi, } from './client/index.js';
|
|
3
|
+
export { apiKeyAuth, registerUserAuth, DEFAULT_BASE_URL, POS_BASE_URL, DEFAULT_TIMEOUT_MS, ALL_CALLS, PUBLIC_CALLS, POS_CALLS, UNKNOWN_OUTCOME_CALLS, createTransport, createBinaryTransport, createPdfOrDataTransport, KasseneckApiError, KasseneckAuthError, KasseneckHttpError, KasseneckNetworkError, KasseneckValidationError, CLIENT_ERROR_CODES, isKasseneckApiError, isKasseneckAuthError, isKasseneckHttpError, isKasseneckNetworkError, isKasseneckValidationError, isOutcomeUnknown, sellReceipt, sellReceiptWithCompany, paymentsExpectedCents, cardRefundReference, receiptLayoutFromResult, cancelReceipt, zeroReceipt, getReceipt, getReceiptWithCompany, generateFullReceiptId, getFirstReceiptDate, listMyReceipts, listMyCashregisters, checkVoucherCombinationError, sendReceiptEmail, downloadDailyReport, downloadMonthlyReport, getReportV2, getCashboxStatus, getSignatureStatus, createKasseneckApi, } from './client/index.js';
|
|
4
4
|
export { receiptDueCents, receiptDueBreakdown, ReceiptDueError, RECEIPT_DUE_ERROR_REASONS, isReceiptDueError, } from './receipt/due.js';
|
|
5
5
|
export { parseServerTimeStamp, toViennaWallClock } from './vienna-time.js';
|
|
6
6
|
export { POS_BUSINESS_DEFAULTS, POS_DEVICE_DEFAULTS, mergePosSettings, fromArticleGroupPayload, fromPosArticlePayload, listMyArticleGroups, listMyArticles, getPosSettings, setMyPosSettings, setMyRegisterDeviceSettings, distributeDiscount, cancelScopeOf, receiptsScopeOf, stockViewOf, } from './pos/index.js';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Fassade ueber den Aufrufen der Lager-API (lesen, Webhooks, schreiben,
|
|
3
|
-
* reservieren, Varianten): Schluessel einmal binden, dann rufen. Wie [createInvoiceApi] bewusst keine Klasse; die Aufrufe sind freie
|
|
3
|
+
* reservieren, Varianten, Inventur): Schluessel einmal binden, dann rufen. Wie [createInvoiceApi] bewusst keine Klasse; die Aufrufe sind freie
|
|
4
4
|
* Funktionen (endpunkte.ts) und bleiben einzeln importierbar.
|
|
5
5
|
*/
|
|
6
6
|
import { type FetchLike } from '../client/transport.js';
|
|
7
|
-
import type { AddVariantRequest, CreateVariantGroupRequest, UpdateVariantGroupRequest, VariantGroup, VariantGroupListQuery, VariantGroupPage, Article, ChangeStockConditionRequest, CreateArticleRequest, CreateReservationRequest, DeactivateArticleRequest, ExtendReservationRequest, GoodsReceiptPreview, GoodsReceiptPreviewRequest, ReceiveGoodsRequest, RecordStockLossRequest, ReleaseReservationRequest, Reservation, ReservationListQuery, ReservationPage, ReverseStockMovementRequest, StockOperation, TransferStockRequest, UpdateArticleRequest, ArticleListQuery, ArticleLookup, ArticlePage, CreateInventoryWebhookOptions, InventoryWebhook, InventoryWebhookDelivery, InventoryWebhookList, InventoryWebhookPatch, InventoryWebhookTestResult, InventoryWebhookWithSecret, Location, StockLevel, StockListQuery, StockMovement, StockMovementPage, StockMovementQuery, StockPage, StockResult } from './typen.js';
|
|
7
|
+
import type { CancelStocktakeRequest, CloseStocktakeRequest, CloseStocktakeResult, CreateStocktakeRequest, RecordStocktakeCountRequest, RecountStocktakeRequest, ReviewStocktakeRequest, Stocktake, StocktakeCount, StocktakeCountListQuery, StocktakeCountPage, StocktakeCountResult, StocktakeItem, StocktakeItemListQuery, StocktakeItemPage, StocktakeListQuery, StocktakePage, StocktakePdf, VoidStocktakeCountRequest, AddVariantRequest, CreateVariantGroupRequest, UpdateVariantGroupRequest, VariantGroup, VariantGroupListQuery, VariantGroupPage, Article, ChangeStockConditionRequest, CreateArticleRequest, CreateReservationRequest, DeactivateArticleRequest, ExtendReservationRequest, GoodsReceiptPreview, GoodsReceiptPreviewRequest, ReceiveGoodsRequest, RecordStockLossRequest, ReleaseReservationRequest, Reservation, ReservationListQuery, ReservationPage, ReverseStockMovementRequest, StockOperation, TransferStockRequest, UpdateArticleRequest, ArticleListQuery, ArticleLookup, ArticlePage, CreateInventoryWebhookOptions, InventoryWebhook, InventoryWebhookDelivery, InventoryWebhookList, InventoryWebhookPatch, InventoryWebhookTestResult, InventoryWebhookWithSecret, Location, StockLevel, StockListQuery, StockMovement, StockMovementPage, StockMovementQuery, StockPage, StockResult } from './typen.js';
|
|
8
8
|
import type { InventoryWebhookEventType } from './vertrag.js';
|
|
9
9
|
export interface InventoryClientOptions {
|
|
10
10
|
/** `api_key` des Kontos (`kr_live_…` / `kr_test_…`). Gehoert auf einen Server. */
|
|
@@ -65,5 +65,24 @@ export interface InventoryClient {
|
|
|
65
65
|
getVariantGroup(variantGroupId: string): Promise<VariantGroup>;
|
|
66
66
|
listVariantGroups(query?: VariantGroupListQuery): Promise<VariantGroupPage>;
|
|
67
67
|
iterateVariantGroups(query?: VariantGroupListQuery): AsyncGenerator<VariantGroup, void, undefined>;
|
|
68
|
+
createStocktake(request: CreateStocktakeRequest): Promise<Stocktake>;
|
|
69
|
+
/** Ohne `updatedSince` zuletzt geaenderte zuerst, mit `updatedSince` aufsteigend und inklusive. */
|
|
70
|
+
listStocktakes(query?: StocktakeListQuery): Promise<StocktakePage>;
|
|
71
|
+
iterateStocktakes(query?: StocktakeListQuery): AsyncGenerator<Stocktake, void, undefined>;
|
|
72
|
+
getStocktake(stocktakeId: string): Promise<Stocktake>;
|
|
73
|
+
listStocktakeItems(query: StocktakeItemListQuery): Promise<StocktakeItemPage>;
|
|
74
|
+
iterateStocktakeItems(query: StocktakeItemListQuery): AsyncGenerator<StocktakeItem, void, undefined>;
|
|
75
|
+
recordStocktakeCount(request: RecordStocktakeCountRequest): Promise<StocktakeCountResult>;
|
|
76
|
+
voidStocktakeCount(request: VoidStocktakeCountRequest): Promise<StocktakeCountResult>;
|
|
77
|
+
listStocktakeCounts(query: StocktakeCountListQuery): Promise<StocktakeCountPage>;
|
|
78
|
+
iterateStocktakeCounts(query: StocktakeCountListQuery): AsyncGenerator<StocktakeCount, void, undefined>;
|
|
79
|
+
/** Pruefen; die Antwort kommt mit `review.complete: false`, gerechnet wird im Hintergrund. */
|
|
80
|
+
reviewStocktake(request: ReviewStocktakeRequest): Promise<Stocktake>;
|
|
81
|
+
recountStocktake(request: RecountStocktakeRequest): Promise<Stocktake>;
|
|
82
|
+
/** Abschliessen; der Server bucht in Teilen weiter (`status: 'closing'`). */
|
|
83
|
+
closeStocktake(request: CloseStocktakeRequest): Promise<CloseStocktakeResult>;
|
|
84
|
+
cancelStocktake(request: CancelStocktakeRequest): Promise<Stocktake>;
|
|
85
|
+
/** Das Inventurprotokoll: die Datei (`kind: 'pdf'`) oder, ueber 9 MiB, ein Lese-Link (`kind: 'download'`). */
|
|
86
|
+
getStocktakePdf(stocktakeId: string): Promise<StocktakePdf>;
|
|
68
87
|
}
|
|
69
88
|
export declare function createInventoryClient(options: InventoryClientOptions): InventoryClient;
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Fassade ueber den Aufrufen der Lager-API (lesen, Webhooks, schreiben,
|
|
3
|
-
* reservieren, Varianten): Schluessel einmal binden, dann rufen. Wie [createInvoiceApi] bewusst keine Klasse; die Aufrufe sind freie
|
|
3
|
+
* reservieren, Varianten, Inventur): Schluessel einmal binden, dann rufen. Wie [createInvoiceApi] bewusst keine Klasse; die Aufrufe sind freie
|
|
4
4
|
* Funktionen (endpunkte.ts) und bleiben einzeln importierbar.
|
|
5
5
|
*/
|
|
6
|
-
import { createTransport } from '../client/transport.js';
|
|
6
|
+
import { createPdfOrDataTransport, createTransport } from '../client/transport.js';
|
|
7
7
|
import { inventoryKeyAuth } from './auth.js';
|
|
8
8
|
import { createWebhook, deleteWebhook, getArticle, getStock, iterateArticles, iterateStock, iterateStockMovements, listArticles, listLocations, listStock, listStockMovements, listWebhookDeliveries, listWebhooks, lookupArticleByCode, rotateWebhookSecret, sendWebhookTest, updateWebhook, } from './endpunkte.js';
|
|
9
9
|
import { changeStockCondition, createArticle, createReservation, deactivateArticle, extendReservation, getReservation, iterateReservations, listReservations, previewGoodsReceipt, receiveGoods, recordStockLoss, releaseReservation, reverseStockMovement, transferStock, updateArticle, } from './schreiben.js';
|
|
10
|
+
import { cancelStocktake, closeStocktake, createStocktake, getStocktake, getStocktakePdf, iterateStocktakeCounts, iterateStocktakeItems, iterateStocktakes, listStocktakeCounts, listStocktakeItems, listStocktakes, recordStocktakeCount, recountStocktake, reviewStocktake, voidStocktakeCount, } from './inventur.js';
|
|
10
11
|
import { addVariant, createVariantGroup, getVariantGroup, iterateVariantGroups, listVariantGroups, updateVariantGroup, } from './varianten.js';
|
|
11
12
|
export function createInventoryClient(options) {
|
|
12
|
-
const
|
|
13
|
+
const transportOptionen = {
|
|
13
14
|
auth: inventoryKeyAuth({ apiKey: options.apiKey }),
|
|
14
15
|
baseUrl: options.baseUrl,
|
|
15
16
|
timeoutMs: options.timeoutMs,
|
|
16
17
|
fetch: options.fetch,
|
|
17
|
-
}
|
|
18
|
+
};
|
|
19
|
+
const rufen = createTransport(transportOptionen);
|
|
20
|
+
// Das Inventurprotokoll kommt als Datei oder als Lese-Link (ueber 9 MiB).
|
|
21
|
+
const rufenDatei = createPdfOrDataTransport(transportOptionen);
|
|
18
22
|
return {
|
|
19
23
|
getArticle: (id) => getArticle(rufen, id),
|
|
20
24
|
listArticles: (q) => listArticles(rufen, q),
|
|
@@ -54,5 +58,20 @@ export function createInventoryClient(options) {
|
|
|
54
58
|
getVariantGroup: (id) => getVariantGroup(rufen, id),
|
|
55
59
|
listVariantGroups: (q) => listVariantGroups(rufen, q),
|
|
56
60
|
iterateVariantGroups: (q) => iterateVariantGroups(rufen, q),
|
|
61
|
+
createStocktake: (r) => createStocktake(rufen, r),
|
|
62
|
+
listStocktakes: (q) => listStocktakes(rufen, q),
|
|
63
|
+
iterateStocktakes: (q) => iterateStocktakes(rufen, q),
|
|
64
|
+
getStocktake: (id) => getStocktake(rufen, id),
|
|
65
|
+
listStocktakeItems: (q) => listStocktakeItems(rufen, q),
|
|
66
|
+
iterateStocktakeItems: (q) => iterateStocktakeItems(rufen, q),
|
|
67
|
+
recordStocktakeCount: (r) => recordStocktakeCount(rufen, r),
|
|
68
|
+
voidStocktakeCount: (r) => voidStocktakeCount(rufen, r),
|
|
69
|
+
listStocktakeCounts: (q) => listStocktakeCounts(rufen, q),
|
|
70
|
+
iterateStocktakeCounts: (q) => iterateStocktakeCounts(rufen, q),
|
|
71
|
+
reviewStocktake: (r) => reviewStocktake(rufen, r),
|
|
72
|
+
recountStocktake: (r) => recountStocktake(rufen, r),
|
|
73
|
+
closeStocktake: (r) => closeStocktake(rufen, r),
|
|
74
|
+
cancelStocktake: (r) => cancelStocktake(rufen, r),
|
|
75
|
+
getStocktakePdf: (id) => getStocktakePdf(rufenDatei, id),
|
|
57
76
|
};
|
|
58
77
|
}
|
|
@@ -41,3 +41,9 @@ export declare function inventoryRetryAfterSec(error: unknown): number | undefin
|
|
|
41
41
|
export declare function inventoryShortfalls(error: unknown): InventoryShortfall[];
|
|
42
42
|
/** `true` fuer einen Hinweis-Code einer Buchung (`warnings[].code`); Hinweise sind nie Fehler. */
|
|
43
43
|
export declare function isInventoryWarningCode(value: unknown): value is InventoryWarningCode;
|
|
44
|
+
/**
|
|
45
|
+
* Die Inventur, die einen Standort belegt (`stocktake_location_busy`,
|
|
46
|
+
* `data.stocktakeId`): weiterzaehlen statt neu anlegen. `undefined`, wenn der
|
|
47
|
+
* Fehler ein anderer ist oder der Server keine Kennung nennt.
|
|
48
|
+
*/
|
|
49
|
+
export declare function inventoryBusyStocktakeId(error: unknown): string | undefined;
|
|
@@ -55,3 +55,14 @@ const HINWEISE = new Set(INVENTORY_WARNING_CODES);
|
|
|
55
55
|
export function isInventoryWarningCode(value) {
|
|
56
56
|
return typeof value === 'string' && HINWEISE.has(value);
|
|
57
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Die Inventur, die einen Standort belegt (`stocktake_location_busy`,
|
|
60
|
+
* `data.stocktakeId`): weiterzaehlen statt neu anlegen. `undefined`, wenn der
|
|
61
|
+
* Fehler ein anderer ist oder der Server keine Kennung nennt.
|
|
62
|
+
*/
|
|
63
|
+
export function inventoryBusyStocktakeId(error) {
|
|
64
|
+
if (inventoryErrorCode(error) !== 'stocktake_location_busy')
|
|
65
|
+
return undefined;
|
|
66
|
+
const wert = error.details['stocktakeId'];
|
|
67
|
+
return typeof wert === 'string' && wert !== '' ? wert : undefined;
|
|
68
|
+
}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* Bestand und Lagerprotokoll lesen, Konto-Webhooks verwalten und eingehende
|
|
4
4
|
* Zustellungen pruefen (Backend Stufe 5a); Artikel anlegen und aendern,
|
|
5
5
|
* Bestand buchen und Ware reservieren (Stufe 5b, seit 1.5.0);
|
|
6
|
-
* Variantengruppen (Stufe 5c, seit 1.6.0)
|
|
6
|
+
* Variantengruppen (Stufe 5c, seit 1.6.0); Inventur (Lager-Kern Stufe 3,
|
|
7
|
+
* seit 1.8.0).
|
|
7
8
|
*
|
|
8
9
|
* Ein eigener Unterpfad wie `invoice`: der `api_key` eines Kontos gehoert auf
|
|
9
10
|
* einen **Server** (etwa das Backend eines Online-Shops) und soll nicht
|
|
@@ -14,10 +15,11 @@
|
|
|
14
15
|
*/
|
|
15
16
|
export { createInventoryClient, type InventoryClient, type InventoryClientOptions } from './api.js';
|
|
16
17
|
export { inventoryKeyAuth, type InventoryKeyAuthOptions } from './auth.js';
|
|
17
|
-
export { isInventoryError, isInventoryErrorCode, inventoryErrorCode, inventoryFieldErrors, inventoryRetryAfterSec, inventoryShortfalls, isInventoryWarningCode, type InventoryApiErrorCode, type InventoryFieldError, } from './fehler.js';
|
|
18
|
+
export { isInventoryError, isInventoryErrorCode, inventoryErrorCode, inventoryFieldErrors, inventoryRetryAfterSec, inventoryShortfalls, inventoryBusyStocktakeId, isInventoryWarningCode, type InventoryApiErrorCode, type InventoryFieldError, } from './fehler.js';
|
|
18
19
|
export { createWebhook, deleteWebhook, getArticle, getStock, iterateArticles, iterateStock, iterateStockMovements, listArticles, listLocations, listStock, listStockMovements, listWebhookDeliveries, listWebhooks, lookupArticleByCode, rotateWebhookSecret, sendWebhookTest, updateWebhook, } from './endpunkte.js';
|
|
19
20
|
export { changeStockCondition, createArticle, createReservation, deactivateArticle, extendReservation, getReservation, iterateReservations, listReservations, previewGoodsReceipt, receiveGoods, recordStockLoss, releaseReservation, reverseStockMovement, transferStock, updateArticle, } from './schreiben.js';
|
|
20
21
|
export { addVariant, createVariantGroup, getVariantGroup, iterateVariantGroups, listVariantGroups, updateVariantGroup, } from './varianten.js';
|
|
22
|
+
export { cancelStocktake, closeStocktake, createStocktake, getStocktake, getStocktakePdf, iterateStocktakeCounts, iterateStocktakeItems, iterateStocktakes, listStocktakeCounts, listStocktakeItems, listStocktakes, recordStocktakeCount, recountStocktake, reviewStocktake, voidStocktakeCount, } from './inventur.js';
|
|
21
23
|
export { verifyInventoryWebhookSignature, parseInventoryWebhookEvent, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_EVENT_HEADER, WEBHOOK_DELIVERY_HEADER, WEBHOOK_TOLERANCE_SEC, type VerifyInventoryWebhookOptions, } from './webhook.js';
|
|
22
|
-
export type { AddVariantRequest, Article, ArticleInput, ArticleListQuery, ArticleLookup, ArticlePage, ChangeStockConditionRequest, CreateArticleRequest, CreateInventoryWebhookOptions, CreateReservationRequest, CreateVariantGroupRequest, DeactivateArticleRequest, ExtendReservationRequest, GoodsReceiptItem, GoodsReceiptPreview, GoodsReceiptPreviewLine, GoodsReceiptPreviewRequest, InventoryShortfall, InventoryWarning, InventoryWebhook, InventoryWebhookDelivery, InventoryWebhookEnvelope, InventoryWebhookEvent, InventoryWebhookList, InventoryWebhookPatch, InventoryWebhookTestDelivery, InventoryWebhookTestResult, InventoryWebhookWithSecret, LandedCost, Location, LocationAddress, ReceiveGoodsRequest, RecordStockLossRequest, ReleaseReservationItem, ReleaseReservationRequest, Reservation, ReservationItem, ReservationItemInput, ReservationListQuery, ReservationPage, ReverseStockMovementRequest, StockBelowMinimumEventData, StockChangedEventData, StockItem, StockLevel, StockListQuery, StockMovement, StockMovementLot, StockMovementPage, StockMovementQuery, StockMovementSourceRef, StockOperation, StockPage, StockResult, StockValue, TransferStockRequest, UpdateArticleRequest, UpdateVariantGroupRequest, VariantAttribute, VariantGroup, VariantGroupDefaults, VariantGroupDefaultsInput, VariantGroupListQuery, VariantGroupMember, VariantGroupPage, VariantInput, } from './typen.js';
|
|
23
|
-
export { INVENTORY_ENDPOINTS, INVENTORY_ERROR_CODES, INVENTORY_REQUEST_ERROR_CODES, INVENTORY_WEBHOOK_EVENTS, INVENTORY_WEBHOOK_ENVELOPE_FIELDS, INVENTORY_WEBHOOK_LIMIT, INVENTORY_LIST_LIMIT_MAX, LOCATION_TYPES, STOCK_MOVEMENT_TYPES, STOCK_MOVEMENT_SOURCES, STOCK_CONDITIONS, STOCK_CHANGE_CAUSES, WEBHOOK_DELIVERY_STATUSES, INVENTORY_WARNING_CODES, STOCK_KINDS, STOCK_LOSS_REASONS, WITHDRAWAL_TYPES, LANDED_COST_TYPES, LANDED_COST_ALLOCATIONS, RESERVATION_STATUSES, INVENTORY_IDEMPOTENCY_KEY_MAX, RESERVATION_MINUTES_MIN, RESERVATION_MINUTES_MAX, VARIANT_ATTRIBUTES_MAX, VARIANT_VALUES_MAX, VARIANT_MATRIX_MAX, VARIANT_GROUP_ACTIVE_MAX, type InventoryEndpoint, type InventoryErrorCode, type InventoryRequestErrorCode, type InventoryWebhookEventType, type LocationType, type StockMovementType, type StockMovementSource, type StockCondition, type StockChangeCause, type WebhookDeliveryStatus, type InventoryWarningCode, type StockKind, type StockLossReason, type WithdrawalType, type LandedCostType, type LandedCostAllocation, type ReservationStatus, } from './vertrag.js';
|
|
24
|
+
export type { AddVariantRequest, Article, CancelStocktakeRequest, CloseStocktakeRequest, CloseStocktakeResult, CreateStocktakeRequest, RecordStocktakeCountRequest, RecountStocktakeRequest, ReviewStocktakeRequest, Stocktake, StocktakeActor, StocktakeCancellation, StocktakeClosing, StocktakeCount, StocktakeCountListQuery, StocktakeCountPage, StocktakeCountResult, StocktakeInventoryLine, StocktakeItem, StocktakeItemListQuery, StocktakeItemPage, StocktakeListQuery, StocktakeNotBooked, StocktakePage, StocktakePdf, StocktakePdfDownload, StocktakePdfInfo, StocktakeProgress, StocktakeRecount, StocktakeReview, StocktakeScope, StocktakeScopeInput, StocktakeSeal, StocktakeTotals, StocktakeWarning, VoidStocktakeCountRequest, ArticleInput, ArticleListQuery, ArticleLookup, ArticlePage, ChangeStockConditionRequest, CreateArticleRequest, CreateInventoryWebhookOptions, CreateReservationRequest, CreateVariantGroupRequest, DeactivateArticleRequest, ExtendReservationRequest, GoodsReceiptItem, GoodsReceiptPreview, GoodsReceiptPreviewLine, GoodsReceiptPreviewRequest, InventoryShortfall, InventoryWarning, InventoryWebhook, InventoryWebhookDelivery, InventoryWebhookEnvelope, InventoryWebhookEvent, InventoryWebhookList, InventoryWebhookPatch, InventoryWebhookTestDelivery, InventoryWebhookTestResult, InventoryWebhookWithSecret, LandedCost, Location, LocationAddress, ReceiveGoodsRequest, RecordStockLossRequest, ReleaseReservationItem, ReleaseReservationRequest, Reservation, ReservationItem, ReservationItemInput, ReservationListQuery, ReservationPage, ReverseStockMovementRequest, StockBelowMinimumEventData, StockChangedEventData, StockItem, StockLevel, StockListQuery, StockMovement, StockMovementLot, StockMovementPage, StockMovementQuery, StockMovementSourceRef, StockOperation, StockPage, StockResult, StockValue, TransferStockRequest, UpdateArticleRequest, UpdateVariantGroupRequest, VariantAttribute, VariantGroup, VariantGroupDefaults, VariantGroupDefaultsInput, VariantGroupListQuery, VariantGroupMember, VariantGroupPage, VariantInput, } from './typen.js';
|
|
25
|
+
export { INVENTORY_ENDPOINTS, INVENTORY_ERROR_CODES, INVENTORY_REQUEST_ERROR_CODES, INVENTORY_WEBHOOK_EVENTS, INVENTORY_WEBHOOK_ENVELOPE_FIELDS, INVENTORY_WEBHOOK_LIMIT, INVENTORY_LIST_LIMIT_MAX, LOCATION_TYPES, STOCK_MOVEMENT_TYPES, STOCK_MOVEMENT_SOURCES, STOCK_CONDITIONS, STOCK_CHANGE_CAUSES, WEBHOOK_DELIVERY_STATUSES, INVENTORY_WARNING_CODES, STOCK_KINDS, STOCK_LOSS_REASONS, WITHDRAWAL_TYPES, LANDED_COST_TYPES, LANDED_COST_ALLOCATIONS, RESERVATION_STATUSES, INVENTORY_IDEMPOTENCY_KEY_MAX, RESERVATION_MINUTES_MIN, RESERVATION_MINUTES_MAX, VARIANT_ATTRIBUTES_MAX, VARIANT_VALUES_MAX, VARIANT_MATRIX_MAX, VARIANT_GROUP_ACTIVE_MAX, STOCKTAKE_STATUSES, STOCKTAKE_TYPES, STOCKTAKE_SCOPE_TYPES, STOCKTAKE_CHECK_REASONS, STOCKTAKE_NOT_BOOKED_REASONS, STOCKTAKE_SOURCES, STOCKTAKE_ACTOR_TYPES, STOCKTAKE_INVENTORY_AS_OF, STOCKTAKE_ITEMS_MAX, STOCKTAKE_RECOUNT_ITEMS_MAX, STOCKTAKE_COUNTS_PER_ITEM_MAX, type StocktakeStatus, type StocktakeType, type StocktakeScopeType, type StocktakeCheckReason, type StocktakeNotBookedReason, type StocktakeSource, type StocktakeActorType, type StocktakeInventoryAsOf, type InventoryEndpoint, type InventoryErrorCode, type InventoryRequestErrorCode, type InventoryWebhookEventType, type LocationType, type StockMovementType, type StockMovementSource, type StockCondition, type StockChangeCause, type WebhookDeliveryStatus, type InventoryWarningCode, type StockKind, type StockLossReason, type WithdrawalType, type LandedCostType, type LandedCostAllocation, type ReservationStatus, } from './vertrag.js';
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* Bestand und Lagerprotokoll lesen, Konto-Webhooks verwalten und eingehende
|
|
4
4
|
* Zustellungen pruefen (Backend Stufe 5a); Artikel anlegen und aendern,
|
|
5
5
|
* Bestand buchen und Ware reservieren (Stufe 5b, seit 1.5.0);
|
|
6
|
-
* Variantengruppen (Stufe 5c, seit 1.6.0)
|
|
6
|
+
* Variantengruppen (Stufe 5c, seit 1.6.0); Inventur (Lager-Kern Stufe 3,
|
|
7
|
+
* seit 1.8.0).
|
|
7
8
|
*
|
|
8
9
|
* Ein eigener Unterpfad wie `invoice`: der `api_key` eines Kontos gehoert auf
|
|
9
10
|
* einen **Server** (etwa das Backend eines Online-Shops) und soll nicht
|
|
@@ -14,9 +15,10 @@
|
|
|
14
15
|
*/
|
|
15
16
|
export { createInventoryClient } from './api.js';
|
|
16
17
|
export { inventoryKeyAuth } from './auth.js';
|
|
17
|
-
export { isInventoryError, isInventoryErrorCode, inventoryErrorCode, inventoryFieldErrors, inventoryRetryAfterSec, inventoryShortfalls, isInventoryWarningCode, } from './fehler.js';
|
|
18
|
+
export { isInventoryError, isInventoryErrorCode, inventoryErrorCode, inventoryFieldErrors, inventoryRetryAfterSec, inventoryShortfalls, inventoryBusyStocktakeId, isInventoryWarningCode, } from './fehler.js';
|
|
18
19
|
export { createWebhook, deleteWebhook, getArticle, getStock, iterateArticles, iterateStock, iterateStockMovements, listArticles, listLocations, listStock, listStockMovements, listWebhookDeliveries, listWebhooks, lookupArticleByCode, rotateWebhookSecret, sendWebhookTest, updateWebhook, } from './endpunkte.js';
|
|
19
20
|
export { changeStockCondition, createArticle, createReservation, deactivateArticle, extendReservation, getReservation, iterateReservations, listReservations, previewGoodsReceipt, receiveGoods, recordStockLoss, releaseReservation, reverseStockMovement, transferStock, updateArticle, } from './schreiben.js';
|
|
20
21
|
export { addVariant, createVariantGroup, getVariantGroup, iterateVariantGroups, listVariantGroups, updateVariantGroup, } from './varianten.js';
|
|
22
|
+
export { cancelStocktake, closeStocktake, createStocktake, getStocktake, getStocktakePdf, iterateStocktakeCounts, iterateStocktakeItems, iterateStocktakes, listStocktakeCounts, listStocktakeItems, listStocktakes, recordStocktakeCount, recountStocktake, reviewStocktake, voidStocktakeCount, } from './inventur.js';
|
|
21
23
|
export { verifyInventoryWebhookSignature, parseInventoryWebhookEvent, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_EVENT_HEADER, WEBHOOK_DELIVERY_HEADER, WEBHOOK_TOLERANCE_SEC, } from './webhook.js';
|
|
22
|
-
export { INVENTORY_ENDPOINTS, INVENTORY_ERROR_CODES, INVENTORY_REQUEST_ERROR_CODES, INVENTORY_WEBHOOK_EVENTS, INVENTORY_WEBHOOK_ENVELOPE_FIELDS, INVENTORY_WEBHOOK_LIMIT, INVENTORY_LIST_LIMIT_MAX, LOCATION_TYPES, STOCK_MOVEMENT_TYPES, STOCK_MOVEMENT_SOURCES, STOCK_CONDITIONS, STOCK_CHANGE_CAUSES, WEBHOOK_DELIVERY_STATUSES, INVENTORY_WARNING_CODES, STOCK_KINDS, STOCK_LOSS_REASONS, WITHDRAWAL_TYPES, LANDED_COST_TYPES, LANDED_COST_ALLOCATIONS, RESERVATION_STATUSES, INVENTORY_IDEMPOTENCY_KEY_MAX, RESERVATION_MINUTES_MIN, RESERVATION_MINUTES_MAX, VARIANT_ATTRIBUTES_MAX, VARIANT_VALUES_MAX, VARIANT_MATRIX_MAX, VARIANT_GROUP_ACTIVE_MAX, } from './vertrag.js';
|
|
24
|
+
export { INVENTORY_ENDPOINTS, INVENTORY_ERROR_CODES, INVENTORY_REQUEST_ERROR_CODES, INVENTORY_WEBHOOK_EVENTS, INVENTORY_WEBHOOK_ENVELOPE_FIELDS, INVENTORY_WEBHOOK_LIMIT, INVENTORY_LIST_LIMIT_MAX, LOCATION_TYPES, STOCK_MOVEMENT_TYPES, STOCK_MOVEMENT_SOURCES, STOCK_CONDITIONS, STOCK_CHANGE_CAUSES, WEBHOOK_DELIVERY_STATUSES, INVENTORY_WARNING_CODES, STOCK_KINDS, STOCK_LOSS_REASONS, WITHDRAWAL_TYPES, LANDED_COST_TYPES, LANDED_COST_ALLOCATIONS, RESERVATION_STATUSES, INVENTORY_IDEMPOTENCY_KEY_MAX, RESERVATION_MINUTES_MIN, RESERVATION_MINUTES_MAX, VARIANT_ATTRIBUTES_MAX, VARIANT_VALUES_MAX, VARIANT_MATRIX_MAX, VARIANT_GROUP_ACTIVE_MAX, STOCKTAKE_STATUSES, STOCKTAKE_TYPES, STOCKTAKE_SCOPE_TYPES, STOCKTAKE_CHECK_REASONS, STOCKTAKE_NOT_BOOKED_REASONS, STOCKTAKE_SOURCES, STOCKTAKE_ACTOR_TYPES, STOCKTAKE_INVENTORY_AS_OF, STOCKTAKE_ITEMS_MAX, STOCKTAKE_RECOUNT_ITEMS_MAX, STOCKTAKE_COUNTS_PER_ITEM_MAX, } from './vertrag.js';
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inventur der Lager-API (Lager-Kern Stufe 3): anlegen, zaehlen, Zaehlungen
|
|
3
|
+
* stornieren, pruefen, nachzaehlen, abschliessen, abbrechen, Inventurprotokoll
|
|
4
|
+
* holen; dazu die Listen der Inventuren, Positionen und Zaehlungen.
|
|
5
|
+
*
|
|
6
|
+
* Ablauf: `createStocktake` → `recordStocktakeCount` (beliebig oft, auch von
|
|
7
|
+
* mehreren Geraeten; je Position addiert) → `reviewStocktake` (erst jetzt Soll
|
|
8
|
+
* und Differenz) → bei Bedarf `recountStocktake` und erneut `reviewStocktake`
|
|
9
|
+
* → `closeStocktake` → `getStocktakePdf`. Pruefen und Abschliessen rechnet der
|
|
10
|
+
* Server im Hintergrund: die Antwort traegt den Zwischenstand
|
|
11
|
+
* (`review.complete: false` bzw. `status: 'closing'`), `getStocktake` den
|
|
12
|
+
* Fortgang.
|
|
13
|
+
*
|
|
14
|
+
* **Blind:** vor `review` traegt keine Antwort ein Soll; `blind: false` zeigt
|
|
15
|
+
* beim Zaehlen nur den heutigen Buchbestand (`bookStockNow`), nie das Soll
|
|
16
|
+
* zur Referenzzeit.
|
|
17
|
+
*
|
|
18
|
+
* Rechte wie in Stufe 5b: Lesen mit jedem Schluessel, alles Schreibende (auch
|
|
19
|
+
* Zaehlen) mit dem Konto-Schalter „Lager-API schreiben“ (Test-Schluessel
|
|
20
|
+
* immer), sonst `inventory_api_not_enabled`; Werte und das Protokoll mit
|
|
21
|
+
* Werten nur mit `lagerApi.kosten`.
|
|
22
|
+
*
|
|
23
|
+
* **Vor dem Senden geprueft wird nur, was ohne Netz sicher falsch ist:**
|
|
24
|
+
* `idempotencyKey` (Pflicht bei jedem Schreiben, 1–120 Zeichen), fehlende
|
|
25
|
+
* Kennungen (`stocktakeId`, `articleId`, `countId`, `locationId`), `scope`
|
|
26
|
+
* kein Objekt, eine Menge, die keine Ganzzahl ist (Tausendstel), ein leerer
|
|
27
|
+
* Grund, `items` beim Nachzaehlen leer oder ohne `articleId`,
|
|
28
|
+
* `serialNumbers` keine Liste, `uncountedAsZero` kein Wahrheitswert. Alles
|
|
29
|
+
* Fachliche (Umfang, Stichtag, Seriennummern, Zustand) prueft der Server.
|
|
30
|
+
*
|
|
31
|
+
* **Wiederholen** wie bei jedem Schreiben: nach `outcome: 'unknown'` denselben
|
|
32
|
+
* Aufruf mit **demselben** `idempotencyKey`. Eine Zaehlung wirkt dann genau
|
|
33
|
+
* einmal (das Zaehldokument ist selbst der Nachweis); ein neuer Schluessel
|
|
34
|
+
* zaehlte die Ware ein zweites Mal.
|
|
35
|
+
*/
|
|
36
|
+
import type { ApiCall, InternerPdfOderDatenTransport, InternerTransport } from '../client/aufrufe.js';
|
|
37
|
+
import type { CancelStocktakeRequest, CloseStocktakeRequest, CloseStocktakeResult, CreateStocktakeRequest, RecordStocktakeCountRequest, RecountStocktakeRequest, ReviewStocktakeRequest, Stocktake, StocktakeCount, StocktakeCountListQuery, StocktakeCountPage, StocktakeCountResult, StocktakeItem, StocktakeItemListQuery, StocktakeItemPage, StocktakeListQuery, StocktakePage, StocktakePdf, VoidStocktakeCountRequest } from './typen.js';
|
|
38
|
+
type Params = Record<string, unknown>;
|
|
39
|
+
/**
|
|
40
|
+
* Legt eine Inventur an. Je Standort hoechstens eine offene
|
|
41
|
+
* (`stocktake_location_busy`, `data.stocktakeId` nennt sie); Umfang `groups`
|
|
42
|
+
* bzw. `articles` nur mit bestandsgefuehrten Artikeln (`article_not_tracked`).
|
|
43
|
+
* Jede Inventur beginnt in `counting`.
|
|
44
|
+
*/
|
|
45
|
+
export declare function createStocktake(transport: InternerTransport, request: CreateStocktakeRequest): Promise<Stocktake>;
|
|
46
|
+
/**
|
|
47
|
+
* Inventuren des Kontos. Ohne `updatedSince` zuletzt geaenderte zuerst; mit
|
|
48
|
+
* `updatedSince` aufsteigend nach `updatedAt` und inklusive (Abgleich: das
|
|
49
|
+
* groesste gesehene `updatedAt` als naechstes `updatedSince`). Filter
|
|
50
|
+
* `status` und `locationId`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function listStocktakes(transport: InternerTransport, query?: StocktakeListQuery): Promise<StocktakePage>;
|
|
53
|
+
/** Alle Inventuren der Abfrage, Seite fuer Seite, in der Reihenfolge von [listStocktakes]. */
|
|
54
|
+
export declare function iterateStocktakes(transport: InternerTransport, query?: StocktakeListQuery): AsyncGenerator<Stocktake, void, undefined>;
|
|
55
|
+
/** Eine Inventur samt `progress.counted` (gezaehlte Positionen). */
|
|
56
|
+
export declare function getStocktake(transport: InternerTransport, stocktakeId: string): Promise<Stocktake>;
|
|
57
|
+
/** Positionen einer Inventur nach Kennung; `openOnly` = ungezaehlt bzw. in `review` zum Nachzaehlen offen. */
|
|
58
|
+
export declare function listStocktakeItems(transport: InternerTransport, query: StocktakeItemListQuery): Promise<StocktakeItemPage>;
|
|
59
|
+
export declare function iterateStocktakeItems(transport: InternerTransport, query: StocktakeItemListQuery): AsyncGenerator<StocktakeItem, void, undefined>;
|
|
60
|
+
/** Zaehlungen einer Inventur, neueste zuerst, auch stornierte; mit `articleId` nur die des Artikels. */
|
|
61
|
+
export declare function listStocktakeCounts(transport: InternerTransport, query: StocktakeCountListQuery): Promise<StocktakeCountPage>;
|
|
62
|
+
export declare function iterateStocktakeCounts(transport: InternerTransport, query: StocktakeCountListQuery): AsyncGenerator<StocktakeCount, void, undefined>;
|
|
63
|
+
/** Pruefung einer Zaehlung vor dem Senden, geteilt mit dem Kassenweg. Paketintern. */
|
|
64
|
+
export declare function zaehlungPruefen(name: ApiCall, p: Params): void;
|
|
65
|
+
/** Pruefung eines Stornos vor dem Senden, geteilt mit dem Kassenweg. Paketintern. */
|
|
66
|
+
export declare function stornoPruefen(name: ApiCall, p: Params): void;
|
|
67
|
+
/**
|
|
68
|
+
* Eine Zaehlung. Antwort: die Zaehlung und ihre Position danach (Summe der
|
|
69
|
+
* Runde in `item.quantity`). Gezaehlt wird in `counting`, in `review` nur an
|
|
70
|
+
* Positionen, die zum Nachzaehlen frei sind (sonst `stocktake_not_open`).
|
|
71
|
+
*/
|
|
72
|
+
export declare function recordStocktakeCount(transport: InternerTransport, request: RecordStocktakeCountRequest): Promise<StocktakeCountResult>;
|
|
73
|
+
/** Storniert eine Zaehlung mit Grund; die Position wird aus den uebrigen Zaehlungen neu summiert. */
|
|
74
|
+
export declare function voidStocktakeCount(transport: InternerTransport, request: VoidStocktakeCountRequest): Promise<StocktakeCountResult>;
|
|
75
|
+
/**
|
|
76
|
+
* Pruefen: `counting` → `review`, in `review` neu rechnen (nach dem
|
|
77
|
+
* Nachzaehlen). Die Antwort kommt sofort mit `review.complete: false`; Soll
|
|
78
|
+
* und Differenz stehen an den Positionen, sobald `complete` `true` ist.
|
|
79
|
+
*/
|
|
80
|
+
export declare function reviewStocktake(transport: InternerTransport, request: ReviewStocktakeRequest): Promise<Stocktake>;
|
|
81
|
+
/** Nachzaehlen: je genannter Position eine neue Runde; danach zaehlen und erneut [reviewStocktake]. */
|
|
82
|
+
export declare function recountStocktake(transport: InternerTransport, request: RecountStocktakeRequest): Promise<Stocktake>;
|
|
83
|
+
/**
|
|
84
|
+
* Abschliessen (nur aus `review`, sonst `stocktake_not_in_review`; offene
|
|
85
|
+
* Nachzaehlungen ergeben `stocktake_recount_open`). Der Server bucht in
|
|
86
|
+
* Teilen weiter; die Antwort traegt meist `status: 'closing'`. Ein erneuter
|
|
87
|
+
* Aufruf waehrend `closing` stoesst den Abschluss wieder an.
|
|
88
|
+
*/
|
|
89
|
+
export declare function closeStocktake(transport: InternerTransport, request: CloseStocktakeRequest): Promise<CloseStocktakeResult>;
|
|
90
|
+
/** Abbrechen mit Grund (aus `counting` oder `review`); der Standort ist danach frei. */
|
|
91
|
+
export declare function cancelStocktake(transport: InternerTransport, request: CancelStocktakeRequest): Promise<Stocktake>;
|
|
92
|
+
/**
|
|
93
|
+
* Das Inventurprotokoll (PDF), erst nach dem Abschluss (`stocktake_not_closed`,
|
|
94
|
+
* auch fuer eine abgebrochene Inventur). Mit `lagerApi.kosten` die Fassung mit
|
|
95
|
+
* Werten, sonst die nur mit Mengen. Bis 9 MiB kommt die Datei selbst
|
|
96
|
+
* (`kind: 'pdf'`), darueber ein signierter Lese-Link fuer 15 Minuten
|
|
97
|
+
* (`kind: 'download'`); die geladene Datei an `download.sha256` pruefen.
|
|
98
|
+
*
|
|
99
|
+
* Als freie Funktion braucht sie den Transport aus `createPdfOrDataTransport`
|
|
100
|
+
* (Paketwurzel): ein JSON-Transport laese die Datei als Text, ein reiner
|
|
101
|
+
* Binaer-Transport kennt den Link nicht. [createInventoryClient] bindet ihn selbst.
|
|
102
|
+
*/
|
|
103
|
+
export declare function getStocktakePdf(transport: InternerPdfOderDatenTransport, stocktakeId: string): Promise<StocktakePdf>;
|
|
104
|
+
export {};
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inventur der Lager-API (Lager-Kern Stufe 3): anlegen, zaehlen, Zaehlungen
|
|
3
|
+
* stornieren, pruefen, nachzaehlen, abschliessen, abbrechen, Inventurprotokoll
|
|
4
|
+
* holen; dazu die Listen der Inventuren, Positionen und Zaehlungen.
|
|
5
|
+
*
|
|
6
|
+
* Ablauf: `createStocktake` → `recordStocktakeCount` (beliebig oft, auch von
|
|
7
|
+
* mehreren Geraeten; je Position addiert) → `reviewStocktake` (erst jetzt Soll
|
|
8
|
+
* und Differenz) → bei Bedarf `recountStocktake` und erneut `reviewStocktake`
|
|
9
|
+
* → `closeStocktake` → `getStocktakePdf`. Pruefen und Abschliessen rechnet der
|
|
10
|
+
* Server im Hintergrund: die Antwort traegt den Zwischenstand
|
|
11
|
+
* (`review.complete: false` bzw. `status: 'closing'`), `getStocktake` den
|
|
12
|
+
* Fortgang.
|
|
13
|
+
*
|
|
14
|
+
* **Blind:** vor `review` traegt keine Antwort ein Soll; `blind: false` zeigt
|
|
15
|
+
* beim Zaehlen nur den heutigen Buchbestand (`bookStockNow`), nie das Soll
|
|
16
|
+
* zur Referenzzeit.
|
|
17
|
+
*
|
|
18
|
+
* Rechte wie in Stufe 5b: Lesen mit jedem Schluessel, alles Schreibende (auch
|
|
19
|
+
* Zaehlen) mit dem Konto-Schalter „Lager-API schreiben“ (Test-Schluessel
|
|
20
|
+
* immer), sonst `inventory_api_not_enabled`; Werte und das Protokoll mit
|
|
21
|
+
* Werten nur mit `lagerApi.kosten`.
|
|
22
|
+
*
|
|
23
|
+
* **Vor dem Senden geprueft wird nur, was ohne Netz sicher falsch ist:**
|
|
24
|
+
* `idempotencyKey` (Pflicht bei jedem Schreiben, 1–120 Zeichen), fehlende
|
|
25
|
+
* Kennungen (`stocktakeId`, `articleId`, `countId`, `locationId`), `scope`
|
|
26
|
+
* kein Objekt, eine Menge, die keine Ganzzahl ist (Tausendstel), ein leerer
|
|
27
|
+
* Grund, `items` beim Nachzaehlen leer oder ohne `articleId`,
|
|
28
|
+
* `serialNumbers` keine Liste, `uncountedAsZero` kein Wahrheitswert. Alles
|
|
29
|
+
* Fachliche (Umfang, Stichtag, Seriennummern, Zustand) prueft der Server.
|
|
30
|
+
*
|
|
31
|
+
* **Wiederholen** wie bei jedem Schreiben: nach `outcome: 'unknown'` denselben
|
|
32
|
+
* Aufruf mit **demselben** `idempotencyKey`. Eine Zaehlung wirkt dann genau
|
|
33
|
+
* einmal (das Zaehldokument ist selbst der Nachweis); ein neuer Schluessel
|
|
34
|
+
* zaehlte die Ware ein zweites Mal.
|
|
35
|
+
*/
|
|
36
|
+
import { abfrage, anfragefehler, kennung, seitenweise } from './endpunkte.js';
|
|
37
|
+
import { antwortfehler, inventur, inventurPosition, inventurWarnungen, inventurZaehlung, liste, naechsterCursor, objekt, protokollLink, zaehlungMitPosition, } from './lesen.js';
|
|
38
|
+
import { anfrage, ganz, schluessel } from './schreiben.js';
|
|
39
|
+
const istObjekt = (w) => w !== null && typeof w === 'object' && !Array.isArray(w);
|
|
40
|
+
const kopfAus = (name, daten) => inventur({ name, pfad: 'stocktake' }, objekt(daten)?.stocktake);
|
|
41
|
+
/** Ein Grund (Storno, Nachzaehlen, Abbruch): nicht leer. Die Laenge prueft der Server. */
|
|
42
|
+
function grund(name, w) {
|
|
43
|
+
if (typeof w !== 'string' || w.trim() === '')
|
|
44
|
+
throw anfragefehler(name, 'reason fehlt (Grund mit 1 bis 500 Zeichen)');
|
|
45
|
+
}
|
|
46
|
+
/** Schreibende Anfrage mit `stocktakeId`: Schluessel und Kennung geprueft, flach wie gesendet. */
|
|
47
|
+
function schreibend(name, request) {
|
|
48
|
+
const p = anfrage(name, request);
|
|
49
|
+
schluessel(name, p, { pflicht: true });
|
|
50
|
+
kennung(name, 'stocktakeId', p.stocktakeId);
|
|
51
|
+
return p;
|
|
52
|
+
}
|
|
53
|
+
/** Eine Liste unter einer Inventur: `stocktakeId` Pflicht, sonst wie jede Abfrage. */
|
|
54
|
+
function abfrageMitInventur(name, query) {
|
|
55
|
+
if (!istObjekt(query))
|
|
56
|
+
throw anfragefehler(name, 'Abfrage mit stocktakeId erwartet');
|
|
57
|
+
const p = abfrage(name, query);
|
|
58
|
+
kennung(name, 'stocktakeId', p.stocktakeId);
|
|
59
|
+
return p;
|
|
60
|
+
}
|
|
61
|
+
// ---- Anlegen und Lesen -------------------------------------------------------------
|
|
62
|
+
/**
|
|
63
|
+
* Legt eine Inventur an. Je Standort hoechstens eine offene
|
|
64
|
+
* (`stocktake_location_busy`, `data.stocktakeId` nennt sie); Umfang `groups`
|
|
65
|
+
* bzw. `articles` nur mit bestandsgefuehrten Artikeln (`article_not_tracked`).
|
|
66
|
+
* Jede Inventur beginnt in `counting`.
|
|
67
|
+
*/
|
|
68
|
+
export async function createStocktake(transport, request) {
|
|
69
|
+
const name = 'createStocktake';
|
|
70
|
+
const p = anfrage(name, request);
|
|
71
|
+
schluessel(name, p, { pflicht: true });
|
|
72
|
+
kennung(name, 'locationId', p.locationId);
|
|
73
|
+
if (!istObjekt(p.scope))
|
|
74
|
+
throw anfragefehler(name, 'scope fehlt oder ist kein Objekt { type, groupIds?, articleIds? }');
|
|
75
|
+
return kopfAus(name, await transport(name, p));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Inventuren des Kontos. Ohne `updatedSince` zuletzt geaenderte zuerst; mit
|
|
79
|
+
* `updatedSince` aufsteigend nach `updatedAt` und inklusive (Abgleich: das
|
|
80
|
+
* groesste gesehene `updatedAt` als naechstes `updatedSince`). Filter
|
|
81
|
+
* `status` und `locationId`.
|
|
82
|
+
*/
|
|
83
|
+
export async function listStocktakes(transport, query) {
|
|
84
|
+
const name = 'listStocktakes';
|
|
85
|
+
const daten = await transport(name, abfrage(name, query));
|
|
86
|
+
return { stocktakes: liste(name, daten, 'stocktakes', inventur), nextCursor: naechsterCursor(name, daten) };
|
|
87
|
+
}
|
|
88
|
+
/** Alle Inventuren der Abfrage, Seite fuer Seite, in der Reihenfolge von [listStocktakes]. */
|
|
89
|
+
export function iterateStocktakes(transport, query) {
|
|
90
|
+
const { cursor, ...rest } = query ?? {};
|
|
91
|
+
return seitenweise('listStocktakes', cursor, async (c) => {
|
|
92
|
+
const s = await listStocktakes(transport, { ...rest, cursor: c });
|
|
93
|
+
return { eintraege: s.stocktakes, nextCursor: s.nextCursor };
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/** Eine Inventur samt `progress.counted` (gezaehlte Positionen). */
|
|
97
|
+
export async function getStocktake(transport, stocktakeId) {
|
|
98
|
+
const name = 'getStocktake';
|
|
99
|
+
return kopfAus(name, await transport(name, { stocktakeId: kennung(name, 'stocktakeId', stocktakeId) }));
|
|
100
|
+
}
|
|
101
|
+
/** Positionen einer Inventur nach Kennung; `openOnly` = ungezaehlt bzw. in `review` zum Nachzaehlen offen. */
|
|
102
|
+
export async function listStocktakeItems(transport, query) {
|
|
103
|
+
const name = 'listStocktakeItems';
|
|
104
|
+
const daten = await transport(name, abfrageMitInventur(name, query));
|
|
105
|
+
return { items: liste(name, daten, 'items', inventurPosition), nextCursor: naechsterCursor(name, daten) };
|
|
106
|
+
}
|
|
107
|
+
export function iterateStocktakeItems(transport, query) {
|
|
108
|
+
const { cursor, ...rest } = query;
|
|
109
|
+
return seitenweise('listStocktakeItems', cursor, async (c) => {
|
|
110
|
+
const s = await listStocktakeItems(transport, { ...rest, cursor: c });
|
|
111
|
+
return { eintraege: s.items, nextCursor: s.nextCursor };
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/** Zaehlungen einer Inventur, neueste zuerst, auch stornierte; mit `articleId` nur die des Artikels. */
|
|
115
|
+
export async function listStocktakeCounts(transport, query) {
|
|
116
|
+
const name = 'listStocktakeCounts';
|
|
117
|
+
const daten = await transport(name, abfrageMitInventur(name, query));
|
|
118
|
+
return { counts: liste(name, daten, 'counts', inventurZaehlung), nextCursor: naechsterCursor(name, daten) };
|
|
119
|
+
}
|
|
120
|
+
export function iterateStocktakeCounts(transport, query) {
|
|
121
|
+
const { cursor, ...rest } = query;
|
|
122
|
+
return seitenweise('listStocktakeCounts', cursor, async (c) => {
|
|
123
|
+
const s = await listStocktakeCounts(transport, { ...rest, cursor: c });
|
|
124
|
+
return { eintraege: s.counts, nextCursor: s.nextCursor };
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
// ---- Zaehlen und Stornieren ------------------------------------------------------
|
|
128
|
+
/** Pruefung einer Zaehlung vor dem Senden, geteilt mit dem Kassenweg. Paketintern. */
|
|
129
|
+
export function zaehlungPruefen(name, p) {
|
|
130
|
+
kennung(name, 'articleId', p.articleId);
|
|
131
|
+
ganz(name, 'quantity', p.quantity, { pflicht: true });
|
|
132
|
+
if (p.serialNumbers !== undefined && p.serialNumbers !== null && !Array.isArray(p.serialNumbers)) {
|
|
133
|
+
throw anfragefehler(name, 'serialNumbers muss eine Liste sein');
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/** Pruefung eines Stornos vor dem Senden, geteilt mit dem Kassenweg. Paketintern. */
|
|
137
|
+
export function stornoPruefen(name, p) {
|
|
138
|
+
kennung(name, 'countId', p.countId);
|
|
139
|
+
grund(name, p.reason);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Eine Zaehlung. Antwort: die Zaehlung und ihre Position danach (Summe der
|
|
143
|
+
* Runde in `item.quantity`). Gezaehlt wird in `counting`, in `review` nur an
|
|
144
|
+
* Positionen, die zum Nachzaehlen frei sind (sonst `stocktake_not_open`).
|
|
145
|
+
*/
|
|
146
|
+
export async function recordStocktakeCount(transport, request) {
|
|
147
|
+
const name = 'recordStocktakeCount';
|
|
148
|
+
const p = schreibend(name, request);
|
|
149
|
+
zaehlungPruefen(name, p);
|
|
150
|
+
return zaehlungMitPosition(name, await transport(name, p));
|
|
151
|
+
}
|
|
152
|
+
/** Storniert eine Zaehlung mit Grund; die Position wird aus den uebrigen Zaehlungen neu summiert. */
|
|
153
|
+
export async function voidStocktakeCount(transport, request) {
|
|
154
|
+
const name = 'voidStocktakeCount';
|
|
155
|
+
const p = schreibend(name, request);
|
|
156
|
+
stornoPruefen(name, p);
|
|
157
|
+
return zaehlungMitPosition(name, await transport(name, p));
|
|
158
|
+
}
|
|
159
|
+
// ---- Pruefen bis Abbruch ------------------------------------------------------------
|
|
160
|
+
/**
|
|
161
|
+
* Pruefen: `counting` → `review`, in `review` neu rechnen (nach dem
|
|
162
|
+
* Nachzaehlen). Die Antwort kommt sofort mit `review.complete: false`; Soll
|
|
163
|
+
* und Differenz stehen an den Positionen, sobald `complete` `true` ist.
|
|
164
|
+
*/
|
|
165
|
+
export async function reviewStocktake(transport, request) {
|
|
166
|
+
const name = 'reviewStocktake';
|
|
167
|
+
return kopfAus(name, await transport(name, schreibend(name, request)));
|
|
168
|
+
}
|
|
169
|
+
/** Nachzaehlen: je genannter Position eine neue Runde; danach zaehlen und erneut [reviewStocktake]. */
|
|
170
|
+
export async function recountStocktake(transport, request) {
|
|
171
|
+
const name = 'recountStocktake';
|
|
172
|
+
const p = schreibend(name, request);
|
|
173
|
+
if (!Array.isArray(p.items) || p.items.length === 0)
|
|
174
|
+
throw anfragefehler(name, 'items fehlt oder ist leer');
|
|
175
|
+
p.items.forEach((x, i) => {
|
|
176
|
+
if (!istObjekt(x))
|
|
177
|
+
throw anfragefehler(name, `items[${i}] muss ein Objekt sein`);
|
|
178
|
+
kennung(name, `items[${i}].articleId`, x.articleId);
|
|
179
|
+
});
|
|
180
|
+
grund(name, p.reason);
|
|
181
|
+
return kopfAus(name, await transport(name, p));
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Abschliessen (nur aus `review`, sonst `stocktake_not_in_review`; offene
|
|
185
|
+
* Nachzaehlungen ergeben `stocktake_recount_open`). Der Server bucht in
|
|
186
|
+
* Teilen weiter; die Antwort traegt meist `status: 'closing'`. Ein erneuter
|
|
187
|
+
* Aufruf waehrend `closing` stoesst den Abschluss wieder an.
|
|
188
|
+
*/
|
|
189
|
+
export async function closeStocktake(transport, request) {
|
|
190
|
+
const name = 'closeStocktake';
|
|
191
|
+
const p = schreibend(name, request);
|
|
192
|
+
if (p.uncountedAsZero !== undefined && typeof p.uncountedAsZero !== 'boolean') {
|
|
193
|
+
throw anfragefehler(name, 'uncountedAsZero muss true oder false sein');
|
|
194
|
+
}
|
|
195
|
+
const daten = await transport(name, p);
|
|
196
|
+
return { stocktake: kopfAus(name, daten), warnings: inventurWarnungen({ name, pfad: 'warnings' }, objekt(daten)?.warnings) };
|
|
197
|
+
}
|
|
198
|
+
/** Abbrechen mit Grund (aus `counting` oder `review`); der Standort ist danach frei. */
|
|
199
|
+
export async function cancelStocktake(transport, request) {
|
|
200
|
+
const name = 'cancelStocktake';
|
|
201
|
+
const p = schreibend(name, request);
|
|
202
|
+
grund(name, p.reason);
|
|
203
|
+
return kopfAus(name, await transport(name, p));
|
|
204
|
+
}
|
|
205
|
+
// ---- Protokoll ------------------------------------------------------------------
|
|
206
|
+
/**
|
|
207
|
+
* Das Inventurprotokoll (PDF), erst nach dem Abschluss (`stocktake_not_closed`,
|
|
208
|
+
* auch fuer eine abgebrochene Inventur). Mit `lagerApi.kosten` die Fassung mit
|
|
209
|
+
* Werten, sonst die nur mit Mengen. Bis 9 MiB kommt die Datei selbst
|
|
210
|
+
* (`kind: 'pdf'`), darueber ein signierter Lese-Link fuer 15 Minuten
|
|
211
|
+
* (`kind: 'download'`); die geladene Datei an `download.sha256` pruefen.
|
|
212
|
+
*
|
|
213
|
+
* Als freie Funktion braucht sie den Transport aus `createPdfOrDataTransport`
|
|
214
|
+
* (Paketwurzel): ein JSON-Transport laese die Datei als Text, ein reiner
|
|
215
|
+
* Binaer-Transport kennt den Link nicht. [createInventoryClient] bindet ihn selbst.
|
|
216
|
+
*/
|
|
217
|
+
export async function getStocktakePdf(transport, stocktakeId) {
|
|
218
|
+
const name = 'getStocktakePdf';
|
|
219
|
+
const ergebnis = await transport(name, { stocktakeId: kennung(name, 'stocktakeId', stocktakeId) });
|
|
220
|
+
if ('pdf' in ergebnis)
|
|
221
|
+
return { kind: 'pdf', pdf: ergebnis.pdf };
|
|
222
|
+
const link = objekt(ergebnis.data)?.download;
|
|
223
|
+
if (link === undefined || link === null)
|
|
224
|
+
throw antwortfehler(name, 'Antwort ist weder ein PDF noch ein Lese-Link (data.download fehlt)');
|
|
225
|
+
return { kind: 'download', download: protokollLink(name, link) };
|
|
226
|
+
}
|