@tallyui/core 2.0.0 → 3.0.0-next.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/chunk-C4PWPOKO.js +18 -0
- package/dist/commands-BW4YYgRG.d.ts +306 -0
- package/dist/index.d.ts +247 -130
- package/dist/index.js +210 -22
- package/dist/rxdb/index.d.ts +5 -9
- package/dist/server/index.d.ts +213 -0
- package/dist/server/index.js +591 -0
- package/package.json +8 -2
- package/src/commands.ts +1 -1
- package/src/context/connector-context.tsx +30 -1
- package/src/index.ts +17 -5
- package/src/known-warnings.ts +77 -0
- package/src/replication/combine.ts +13 -7
- package/src/replication/reconcile-feed.ts +73 -20
- package/src/rxdb/read-fresh.ts +3 -7
- package/src/rxdb/watch-fresh.ts +2 -2
- package/src/rxdb-remote-version-mismatch.ts +30 -0
- package/src/server/__fixtures__/fingerprint-vectors.json +139 -0
- package/src/server/__fixtures__/order-create-v3.json +97 -0
- package/src/server/batch-outcome.ts +19 -0
- package/src/server/batch.ts +112 -0
- package/src/server/command-result.ts +138 -0
- package/src/server/fingerprint.ts +18 -0
- package/src/server/fiscal-figures.ts +84 -0
- package/src/server/index.ts +20 -0
- package/src/server/money.ts +34 -0
- package/src/server/order-payload-shape.ts +112 -0
- package/src/server/register-figures.ts +32 -0
- package/src/server/register-outcome.ts +12 -0
- package/src/server/register-payload-shape.ts +86 -0
- package/src/server/rejection-codes.ts +49 -0
- package/src/server/total-warnings.ts +10 -0
- package/src/server/versions.ts +9 -0
- package/src/sync-notice.ts +26 -0
- package/src/types/commands.ts +138 -9
- package/src/types/connector.ts +63 -1
- package/src/types/customers.ts +26 -0
- package/src/types/index.ts +9 -2
- package/src/types/reconcile.ts +40 -0
- package/src/types/replication.ts +6 -0
- package/src/types/store-settings.ts +6 -0
- package/src/types/traits/product.ts +7 -0
- package/src/unauthorized.ts +15 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { RxReplicationPullStreamItem, RxReplicationWriteToMasterRow, RxJsonSchema } from 'rxdb';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
+
import { C as CommandWarning } from './commands-BW4YYgRG.js';
|
|
4
|
+
export { A as AnyCommandEnvelope, B as BatchTooLargeBody, a as COMMANDS_PATH, b as CommandBatchRequest, c as CommandBatchResponse, d as CommandEnvelope, e as CommandError, f as CommandResult, g as CommandServerRefs, h as CommandStatus, i as CommandType, M as MAX_COMMANDS_PER_BATCH, O as OrderCreateDisplay, j as OrderCreateEnvelope, k as OrderCreateLine, l as OrderCreatePayload, m as OrderCreatePayment, n as OrderCreateTaxRate, P as PROTOCOL_HEADER, o as PROTOCOL_VERSION, p as PaymentMethodKind, R as RegisterClosureSubmitPayload, q as RegisterCommandEnvelope, r as RegisterCommandResult, s as RegisterCommandType, t as RegisterMovementRecordPayload, u as RegisterMovementVoidPayload, v as RegisterSessionOpenPayload, w as RegisterSessionTransitionPayload, x as isCommandBatchResponse } from './commands-BW4YYgRG.js';
|
|
3
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
6
|
import { ReactNode } from 'react';
|
|
5
7
|
|
|
@@ -107,6 +109,12 @@ interface ProductTraits<Doc = any> {
|
|
|
107
109
|
getStock: (doc: Doc) => StockLevel;
|
|
108
110
|
/** All purchasable variants, in id order (connectors store variants sorted by id). Optional: connectors without variant support omit it. */
|
|
109
111
|
getVariants?: (doc: Doc, context?: TraitContext) => VariantSummary[];
|
|
112
|
+
/**
|
|
113
|
+
* The backend's tax class id for the variant `variantId`, or for the product (its default variant) when omitted.
|
|
114
|
+
* The id is a key of `StoreSettings.taxRatesPpm`; undefined means the default class. Optional: without it, every
|
|
115
|
+
* line is taxed at the default rate.
|
|
116
|
+
*/
|
|
117
|
+
getTaxClass?: (doc: Doc, variantId?: string) => string | undefined;
|
|
110
118
|
/** @deprecated Use `getPrices` with `resolvePrice`. */
|
|
111
119
|
getPrice: (doc: Doc) => string | undefined;
|
|
112
120
|
/** Regular (non-sale) price. @deprecated Use `getPrices` with `resolvePrice`. */
|
|
@@ -180,6 +188,11 @@ interface ReplicationAdapter<RxDocType, CheckpointType = any> {
|
|
|
180
188
|
}>;
|
|
181
189
|
checkpoint: CheckpointType;
|
|
182
190
|
}>;
|
|
191
|
+
/**
|
|
192
|
+
* Documents per pull page, passed to handler as batchSize. RxDB treats a
|
|
193
|
+
* shorter page as the end of the cycle. Defaults to RxDB's 100.
|
|
194
|
+
*/
|
|
195
|
+
batchSize?: number;
|
|
183
196
|
/**
|
|
184
197
|
* Fresh install only: the checkpoint this feed starts from instead of a full first pass,
|
|
185
198
|
* read before any feed runs (combinePullAdapters). Absent: a full first pass, as today.
|
|
@@ -237,6 +250,8 @@ interface IdReconcileAdapter<Doc = any> {
|
|
|
237
250
|
id: string;
|
|
238
251
|
local: Doc;
|
|
239
252
|
}>): void;
|
|
253
|
+
/** Ids per `fetchByIds` request; see `CatalogueReconcileAdapter.refetchBatchSize`. */
|
|
254
|
+
refetchBatchSize?: number;
|
|
240
255
|
}
|
|
241
256
|
/** Re-delivers products whose remote fingerprint differs from the local one (ADR-060). */
|
|
242
257
|
interface FingerprintReconcileAdapter<Doc = any> {
|
|
@@ -254,6 +269,54 @@ interface FingerprintReconcileAdapter<Doc = any> {
|
|
|
254
269
|
local: Doc;
|
|
255
270
|
refreshOnly?: boolean;
|
|
256
271
|
}>): void;
|
|
272
|
+
/** Ids per `fetchByIds` request; see `CatalogueReconcileAdapter.refetchBatchSize`. */
|
|
273
|
+
refetchBatchSize?: number;
|
|
274
|
+
}
|
|
275
|
+
/** One product in the catalogue listing. `key` is the local primary key, or the `matchKey` value when the adapter sets one; `remote` is whatever the connector needs to refetch it (a numeric backend id, say). */
|
|
276
|
+
interface CatalogueReconcileEntry {
|
|
277
|
+
key: string;
|
|
278
|
+
fingerprint: string;
|
|
279
|
+
remote?: unknown;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* The daily catalogue check (#248): one walk that refetches what differs and
|
|
283
|
+
* deletes only with proof. Nothing is written locally: `enqueue` hands
|
|
284
|
+
* documents to the collection's pull (the reconcile feed). `Cursor` must be
|
|
285
|
+
* JSON-serialisable, since the runner persists it to resume a stopped pass.
|
|
286
|
+
*/
|
|
287
|
+
interface CatalogueReconcileAdapter<Doc = any, Cursor = unknown> {
|
|
288
|
+
/** Remote listing, one backend request per page, from `from` (a cursor this adapter yielded earlier) or the start. */
|
|
289
|
+
fetchPages(context: SyncContext, from?: Cursor): AsyncIterable<{
|
|
290
|
+
entries: CatalogueReconcileEntry[];
|
|
291
|
+
cursor: Cursor;
|
|
292
|
+
}>;
|
|
293
|
+
/** Pure: the same fingerprint from a local document. */
|
|
294
|
+
fingerprint(doc: Doc): string;
|
|
295
|
+
/**
|
|
296
|
+
* When set, each listing entry's `key` is this value, not the local primary key (a listing that carries no
|
|
297
|
+
* primary key, such as WCPOS's fast path, #313). The runner indexes the local documents by it for the pass.
|
|
298
|
+
* A document for which it returns undefined can't be matched: it is never compared, and it is a deletion
|
|
299
|
+
* candidate, as today.
|
|
300
|
+
*/
|
|
301
|
+
matchKey?(doc: Doc): string | undefined;
|
|
302
|
+
/**
|
|
303
|
+
* Deletion proof, required: of these local documents (the ones the listing did not name), the primary keys
|
|
304
|
+
* the backend confirms gone (absent, or no longer sellable), with or without `matchKey`. One or more requests.
|
|
305
|
+
* Only confirmed keys are tombstoned; an adapter that never deletes returns none.
|
|
306
|
+
*/
|
|
307
|
+
confirmGone(locals: Doc[], context: SyncContext): Promise<string[]>;
|
|
308
|
+
/**
|
|
309
|
+
* Hand documents to the collection's pull (the reconcile feed). An entry's `key` is the local primary key when
|
|
310
|
+
* there is a local copy, and otherwise the listing's key.
|
|
311
|
+
*/
|
|
312
|
+
enqueue(entries: Array<{
|
|
313
|
+
key: string;
|
|
314
|
+
local?: Doc;
|
|
315
|
+
remote?: unknown;
|
|
316
|
+
tombstone?: boolean;
|
|
317
|
+
}>): void;
|
|
318
|
+
/** Ids per `fetchByIds` request of the feed this adapter enqueues into: a page's `n` refetches take `ceil(n / refetchBatchSize)` budget slots (1 when unset). */
|
|
319
|
+
refetchBatchSize?: number;
|
|
257
320
|
}
|
|
258
321
|
|
|
259
322
|
/** What the POS needs from the store's own settings (TV4). Read once after sign-in; the app feeds all three consumers from it. */
|
|
@@ -267,8 +330,12 @@ interface StoreSettings {
|
|
|
267
330
|
default: number;
|
|
268
331
|
[taxClass: string]: number;
|
|
269
332
|
};
|
|
333
|
+
/** The backend's tax rate name per tax class (same keys as `taxRatesPpm`, including `default`), for `per_rate_group_items`' grouping (#324). Set by a connector whose rounding groups by rate name; absent otherwise. */
|
|
334
|
+
taxRateCodes?: Record<string, string>;
|
|
270
335
|
/** Connector-specific and opaque to the app: what the connector needs to price documents. The app passes it back to the connector unchanged, and never logs it. */
|
|
271
336
|
pricingContext?: Record<string, string>;
|
|
337
|
+
/** Derived, never read by `storeSettings`: the store's `ServerCapabilities.taxRounding`, which `useStoreSettings` fills in (#324). */
|
|
338
|
+
taxRounding?: TaxRounding;
|
|
272
339
|
}
|
|
273
340
|
/**
|
|
274
341
|
* Picks among several regions, countries or sales channels when the store has more than one.
|
|
@@ -282,6 +349,33 @@ interface StoreSettingsChoice {
|
|
|
282
349
|
channel?: string;
|
|
283
350
|
}
|
|
284
351
|
|
|
352
|
+
/** A store customer, as the till shows and picks it (programme item 14). Platform-neutral. */
|
|
353
|
+
interface Customer {
|
|
354
|
+
/** The platform's id: order.create v3 sends it as `customer.customerId`. */
|
|
355
|
+
id: string;
|
|
356
|
+
/** Display name: first + last, else company, else email, else id. Never empty. */
|
|
357
|
+
name: string;
|
|
358
|
+
firstName?: string;
|
|
359
|
+
lastName?: string;
|
|
360
|
+
email?: string;
|
|
361
|
+
phone?: string;
|
|
362
|
+
company?: string;
|
|
363
|
+
}
|
|
364
|
+
/** What the till collects to create a customer. v1 requires an email. */
|
|
365
|
+
interface CustomerInput {
|
|
366
|
+
email: string;
|
|
367
|
+
firstName?: string;
|
|
368
|
+
lastName?: string;
|
|
369
|
+
phone?: string;
|
|
370
|
+
company?: string;
|
|
371
|
+
}
|
|
372
|
+
declare const customerTraits: CustomerTraits<Customer>;
|
|
373
|
+
/** A customer call that failed for a reason other than credentials (credentials throw ConnectorUnauthorizedError). */
|
|
374
|
+
declare class CustomerServiceError extends Error {
|
|
375
|
+
readonly code: 'network' | 'server' | 'invalid';
|
|
376
|
+
constructor(code: 'network' | 'server' | 'invalid', message: string);
|
|
377
|
+
}
|
|
378
|
+
|
|
285
379
|
/**
|
|
286
380
|
* Authentication configuration for a connector.
|
|
287
381
|
* Each API has wildly different auth — JWT, API keys, OAuth, etc.
|
|
@@ -318,7 +412,18 @@ interface SignInResult {
|
|
|
318
412
|
/** The highest `order.create` contract version a store's server currently accepts (ADR-062). */
|
|
319
413
|
interface ServerCapabilities {
|
|
320
414
|
orderCreate: number;
|
|
321
|
-
|
|
415
|
+
/** The highest `register` contract version; absent or 0 means no register sync. */
|
|
416
|
+
register?: number;
|
|
417
|
+
/** How the store rounds tax (#287). Absent: an older server, per_order + half_away_from_zero. */
|
|
418
|
+
taxRounding?: TaxRounding;
|
|
419
|
+
}
|
|
420
|
+
/** #287, ADR-071. `custom`: the till computes as when absent; that server never emits `figures_mismatch` for subtotal or tax. */
|
|
421
|
+
type TaxRounding = {
|
|
422
|
+
granularity: 'per_order' | 'per_line_items' | 'per_rate_group_items';
|
|
423
|
+
mode: 'half_away_from_zero' | 'half_up';
|
|
424
|
+
} | {
|
|
425
|
+
granularity: 'custom';
|
|
426
|
+
};
|
|
322
427
|
/**
|
|
323
428
|
* Resolves the capabilities to act on: a definitive fresh read always wins,
|
|
324
429
|
* even a downgrade to 1; an inconclusive fresh read (`undefined`) keeps the
|
|
@@ -328,6 +433,19 @@ interface ServerCapabilities {
|
|
|
328
433
|
* only happens when the value has never been read (ADR-062).
|
|
329
434
|
*/
|
|
330
435
|
declare function resolveCapabilities(fresh: ServerCapabilities | undefined, stored: ServerCapabilities | undefined): ServerCapabilities | undefined;
|
|
436
|
+
/**
|
|
437
|
+
* Reads the `taxRounding` of `GET /tally/v1/info` (#287): a valid value comes back without
|
|
438
|
+
* extra keys, and `custom` drops any `mode`. Absent gives `undefined`, the default. Core has
|
|
439
|
+
* no logger, so a malformed value gives `undefined` and one reason to `warn` for the caller to log.
|
|
440
|
+
*/
|
|
441
|
+
declare function parseTaxRounding(value: unknown, warn?: (reason: string) => void): TaxRounding | undefined;
|
|
442
|
+
/**
|
|
443
|
+
* Reads a 2xx body of `GET /tally/v1/info` (ADR-062): `orderCreate` is the max of
|
|
444
|
+
* `contracts["order.create"]`, or 1 when it's missing or malformed; `register` is the max of
|
|
445
|
+
* `contracts.register` when valid; `taxRounding` is the top-level sibling of `contracts` (#287).
|
|
446
|
+
* Absent `taxRounding` uses the default; a present malformed value is unknown, so settings wait.
|
|
447
|
+
*/
|
|
448
|
+
declare function parseInfoCapabilities(body: unknown, warn?: (reason: string) => void): ServerCapabilities | undefined;
|
|
331
449
|
interface AuthField {
|
|
332
450
|
key: string;
|
|
333
451
|
label: string;
|
|
@@ -434,6 +552,8 @@ interface TallyConnector {
|
|
|
434
552
|
prices?: FingerprintReconcileAdapter;
|
|
435
553
|
/** Prices the backend calculates for the sales context (price lists, sale dates), which change without a timestamp bump. */
|
|
436
554
|
calculatedPrices?: FingerprintReconcileAdapter;
|
|
555
|
+
/** The daily catalogue check (#248): refetches what differs, deletes only with proof. */
|
|
556
|
+
catalogue?: CatalogueReconcileAdapter;
|
|
437
557
|
};
|
|
438
558
|
/**
|
|
439
559
|
* Reads the store's own settings (TV4): currency, tax inclusivity, tax
|
|
@@ -450,110 +570,14 @@ interface TallyConnector {
|
|
|
450
570
|
* see `resolveCapabilities`.
|
|
451
571
|
*/
|
|
452
572
|
capabilities?: (context: SyncContext) => Promise<ServerCapabilities | undefined>;
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
/**
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
/** 2 only when an `order.create` carries a discount (ADR-062); a discount-free payload stays 1, byte-identical. */
|
|
462
|
-
version: 1 | 2;
|
|
463
|
-
payload: P;
|
|
464
|
-
createdAt: string;
|
|
465
|
-
deviceId: string;
|
|
466
|
-
attempt: number;
|
|
467
|
-
}
|
|
468
|
-
/** Outcome of processing a command. */
|
|
469
|
-
type CommandStatus = 'applied' | 'duplicate' | 'rejected';
|
|
470
|
-
/** Server order identifiers and authoritative total. */
|
|
471
|
-
interface CommandServerRefs {
|
|
472
|
-
orderId: string;
|
|
473
|
-
displayId?: string;
|
|
474
|
-
totalMinor: number;
|
|
475
|
-
}
|
|
476
|
-
/** Non-fatal discrepancies reported while processing a command. */
|
|
477
|
-
type CommandWarning = {
|
|
478
|
-
code: 'total_mismatch';
|
|
479
|
-
expectedMinor: number;
|
|
480
|
-
serverMinor: number;
|
|
481
|
-
} | {
|
|
482
|
-
code: 'insufficient_stock';
|
|
483
|
-
variantId: string;
|
|
484
|
-
quantity: number;
|
|
485
|
-
};
|
|
486
|
-
/** Error reported when a command is rejected. */
|
|
487
|
-
interface CommandError {
|
|
488
|
-
code: string;
|
|
489
|
-
message: string;
|
|
490
|
-
}
|
|
491
|
-
/** Server result for a single command. */
|
|
492
|
-
interface CommandResult {
|
|
493
|
-
id: string;
|
|
494
|
-
status: CommandStatus;
|
|
495
|
-
serverRefs?: CommandServerRefs;
|
|
496
|
-
warnings?: CommandWarning[];
|
|
497
|
-
error?: CommandError;
|
|
498
|
-
}
|
|
499
|
-
/** Order line with client identity and price in minor units. */
|
|
500
|
-
interface OrderCreateLine {
|
|
501
|
-
clientLineId: string;
|
|
502
|
-
variantId: string;
|
|
503
|
-
title?: string;
|
|
504
|
-
quantity: number;
|
|
505
|
-
unitPriceMinor: number;
|
|
506
|
-
/**
|
|
507
|
-
* This line's own tax mode, when it differs from the order's `pricesIncludeTax`
|
|
508
|
-
* (a price that carries its own flag, D2c). Absent means the order's flag, so
|
|
509
|
-
* older clients and single-mode orders are unchanged.
|
|
510
|
-
*/
|
|
511
|
-
taxInclusive?: boolean;
|
|
512
|
-
/**
|
|
513
|
-
* Version 2 (ADR-062): this line's total discount, its own line discounts plus its allocated share of
|
|
514
|
-
* the order discount, in the line's own tax mode and integer minor units. The line is taxed on
|
|
515
|
-
* `unitPriceMinor × quantity − discountMinor`. Present only when above 0.
|
|
516
|
-
*/
|
|
517
|
-
discountMinor?: number;
|
|
518
|
-
}
|
|
519
|
-
/** Supported order payment method. */
|
|
520
|
-
type PaymentMethodKind = 'cash' | 'external';
|
|
521
|
-
/** Order payment with client identity and amounts in minor units. */
|
|
522
|
-
interface OrderCreatePayment {
|
|
523
|
-
clientPaymentId: string;
|
|
524
|
-
method: PaymentMethodKind;
|
|
525
|
-
amountMinor: number;
|
|
526
|
-
tenderedMinor?: number;
|
|
527
|
-
changeMinor?: number;
|
|
528
|
-
reference?: string;
|
|
529
|
-
}
|
|
530
|
-
/** Client order data submitted by an order.create command. */
|
|
531
|
-
interface OrderCreatePayload {
|
|
532
|
-
clientOrderId: string;
|
|
533
|
-
createdAt: string;
|
|
534
|
-
currency: string;
|
|
535
|
-
pricesIncludeTax: boolean;
|
|
536
|
-
lines: OrderCreateLine[];
|
|
537
|
-
subtotalMinor: number;
|
|
538
|
-
/** Version 2 (ADR-062): the order's total discount, equal to Σ `lines[].discountMinor`. Present only when above 0. */
|
|
539
|
-
discountMinor?: number;
|
|
540
|
-
taxMinor: number;
|
|
541
|
-
totalMinor: number;
|
|
542
|
-
payments: OrderCreatePayment[];
|
|
543
|
-
customer?: {
|
|
544
|
-
email?: string;
|
|
545
|
-
} | null;
|
|
546
|
-
registerId?: string;
|
|
547
|
-
cashierRef?: string;
|
|
548
|
-
locationId?: string;
|
|
549
|
-
}
|
|
550
|
-
/** Batch of commands submitted to the server. */
|
|
551
|
-
interface CommandBatchRequest {
|
|
552
|
-
commands: CommandEnvelope[];
|
|
553
|
-
}
|
|
554
|
-
/** Results returned by the server for a command batch. */
|
|
555
|
-
interface CommandBatchResponse {
|
|
556
|
-
results: CommandResult[];
|
|
573
|
+
/** Customer search: online only; `undefined` when the connector has no customer support. */
|
|
574
|
+
searchCustomers?: (context: SyncContext, query: string, options?: {
|
|
575
|
+
limit?: number;
|
|
576
|
+
}) => Promise<Customer[]>;
|
|
577
|
+
/** Customer creation: online only; `undefined` when the connector has no customer support. */
|
|
578
|
+
createCustomer?: (context: SyncContext, input: CustomerInput) => Promise<Customer>;
|
|
579
|
+
/** Customer lookup: online only; `undefined` when the connector has no customer support. */
|
|
580
|
+
getCustomer?: (context: SyncContext, id: string) => Promise<Customer | null>;
|
|
557
581
|
}
|
|
558
582
|
|
|
559
583
|
/**
|
|
@@ -571,6 +595,51 @@ declare class SignInError extends Error {
|
|
|
571
595
|
constructor(code: SignInErrorCode, message: string, status?: number);
|
|
572
596
|
}
|
|
573
597
|
|
|
598
|
+
/** 401 needs sign-in again (`unauthorized`, till); 403 is signed in but not allowed (`forbidden`, store). A 403 pull retries on the store schedule; apps must not sign out. */
|
|
599
|
+
declare class ConnectorUnauthorizedError extends Error {
|
|
600
|
+
readonly code: 'unauthorized' | 'forbidden';
|
|
601
|
+
readonly fixedBy: 'till' | 'store';
|
|
602
|
+
/** Set by meaning, not copied from the HTTP answer: a backend that answers both with the same code decides first (Vendure's session probe). */
|
|
603
|
+
readonly status: 401 | 403;
|
|
604
|
+
constructor(message: string, status: 401 | 403);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* True for RxDB's RM1: the remote storage worker was built on another RxDB
|
|
609
|
+
* version than the main thread, e.g. a stale worker the browser cached from
|
|
610
|
+
* before an upgrade. Reloading loads the matching worker.
|
|
611
|
+
*
|
|
612
|
+
* Matched by structure, never by substring. An `RxError` (rxdb 17.5.0
|
|
613
|
+
* src/rx-error.ts) has own `code`, `message`, `url`, `parameters` and
|
|
614
|
+
* `rxdb: true`; its `name` is a getter. So RM1 is either an object whose own
|
|
615
|
+
* `code` is `'RM1'` (with `rxdb === true` when `rxdb` is present), or an
|
|
616
|
+
* error, `{ message }` copy or string whose message is the remote storage's
|
|
617
|
+
* `could not create instance ` followed by JSON with `rxdb: true` and
|
|
618
|
+
* `code: 'RM1'`. Needs no rxdb import.
|
|
619
|
+
*/
|
|
620
|
+
declare function isRxdbRemoteVersionMismatch(error: unknown): boolean;
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* A pull that stopped until someone acts; `SyncStatus` owns the words for each `code`.
|
|
624
|
+
* `fixedBy` says who can fix it: the till (sign in again) or the store owner.
|
|
625
|
+
* `software` / `minVersion` / `fix` are copied from the error when it names them.
|
|
626
|
+
*/
|
|
627
|
+
type SyncNotice = {
|
|
628
|
+
code: string;
|
|
629
|
+
since: number;
|
|
630
|
+
fixedBy: 'till' | 'store';
|
|
631
|
+
software?: string;
|
|
632
|
+
minVersion?: string;
|
|
633
|
+
fix?: string;
|
|
634
|
+
};
|
|
635
|
+
/** Who can fix a pull error: the till, the store owner, or nobody (it passes, so it is retried). */
|
|
636
|
+
type ErrorKind = 'till' | 'store' | 'transient';
|
|
637
|
+
/**
|
|
638
|
+
* 'till' or 'store' for an error whose class sets `fixedBy` to that value and a
|
|
639
|
+
* string `code`; 'transient' for anything else.
|
|
640
|
+
*/
|
|
641
|
+
declare function errorKind(error: unknown): ErrorKind;
|
|
642
|
+
|
|
574
643
|
/**
|
|
575
644
|
* Why `TallyConnector.storeSettings` failed:
|
|
576
645
|
* - `choice_required`: the store has more than one region, country or
|
|
@@ -599,21 +668,6 @@ declare class StoreSettingsError extends Error {
|
|
|
599
668
|
constructor(code: StoreSettingsErrorCode, message: string, choices?: StoreSettingsChoices);
|
|
600
669
|
}
|
|
601
670
|
|
|
602
|
-
/** Path of the command endpoint, relative to the backend's base URL. */
|
|
603
|
-
declare const COMMANDS_PATH = "/tally/v1/commands";
|
|
604
|
-
/** Header carrying the protocol version. */
|
|
605
|
-
declare const PROTOCOL_HEADER = "X-Tally-Protocol";
|
|
606
|
-
/** Current protocol version. */
|
|
607
|
-
declare const PROTOCOL_VERSION = 1;
|
|
608
|
-
/** Maximum commands per batch request. */
|
|
609
|
-
declare const MAX_COMMANDS_PER_BATCH = 50;
|
|
610
|
-
/**
|
|
611
|
-
* True if `value` has the shape of a CommandBatchResponse: an object with a
|
|
612
|
-
* `results` array whose every entry has a string `id` and a `status` of
|
|
613
|
-
* 'applied' | 'duplicate' | 'rejected'. Optional fields are not deep-checked.
|
|
614
|
-
*/
|
|
615
|
-
declare function isCommandBatchResponse(value: unknown): value is CommandBatchResponse;
|
|
616
|
-
|
|
617
671
|
/** Number of minor-unit digits for an ISO 4217 code (2 for EUR, 0 for JPY). */
|
|
618
672
|
declare function minorUnitDigits(currency: string): number;
|
|
619
673
|
/** The currency's symbol for a plain-English label ('€' for EUR, '$' for USD), not a full amount. */
|
|
@@ -658,6 +712,18 @@ declare function resolvePriceRange(variants: Array<{
|
|
|
658
712
|
*/
|
|
659
713
|
declare function findVariantByCode(variants: VariantSummary[], code: string): VariantSummary | undefined;
|
|
660
714
|
|
|
715
|
+
/**
|
|
716
|
+
* The till's single reader of stored warnings. `[]` for anything that isn't a warnings array.
|
|
717
|
+
* A `total_mismatch`'s `bridgeMinor` is dropped (the rest of the warning is kept) when it's
|
|
718
|
+
* absent, `null`, not a safe integer, zero, or not equal to `expectedMinor - serverMinor`.
|
|
719
|
+
* A `tax_rate_mismatch` with a negative `ratePpm` is dropped entirely; zero stays valid.
|
|
720
|
+
* A `customer_ignored` is dropped unless its `customerId` is a string of 1 to 64 characters.
|
|
721
|
+
* A `figures_mismatch` is dropped entirely unless `fields` is non-empty and each entry names a
|
|
722
|
+
* different figure with two differing safe integers; each entry is rebuilt from its known keys.
|
|
723
|
+
* A figure name it doesn't know (any non-empty string) is kept, since a newer store may send one.
|
|
724
|
+
*/
|
|
725
|
+
declare function knownWarnings(warnings: unknown): CommandWarning[];
|
|
726
|
+
|
|
661
727
|
/** Orders backend ids: numerically when both are integer strings (Vendure '9' < '10', compared with BigInt so long ids stay exact), with ties in numeric value (e.g. '01' vs '1') broken by plain string order; an integer id always sorts before a non-integer one; otherwise (neither is an integer string) by plain string order (not `localeCompare`, which is locale-dependent). This is a total order, so sorting is consistent regardless of input order. */
|
|
662
728
|
declare function compareIds(a: string | number, b: string | number): number;
|
|
663
729
|
|
|
@@ -690,41 +756,83 @@ declare function getProductStock<Doc>(doc: Doc, traits: ProductTraits<Doc>, adap
|
|
|
690
756
|
* checkpoint with none of the keys becomes that key's checkpoint. With no stored
|
|
691
757
|
* checkpoint at all, each sub-adapter with `pull.seedCheckpoint` starts from its seed.
|
|
692
758
|
*
|
|
759
|
+
* `options.batchSize` sets the combined pull page size; sub-adapters' own
|
|
760
|
+
* `pull.batchSize` is ignored.
|
|
761
|
+
* Duplicates across sub-adapters are resolved by this key, the last one winning; it defaults to `doc.id`. Pass the collection's primary key when `id` is not it (WooCommerce's uuid, #331): two documents that share an `id`, such as a product's new copy and its old copy's tombstone, must both reach the collection.
|
|
693
762
|
* Pull only: a sub-adapter with `push` or `pull.stream$` throws here.
|
|
694
763
|
*/
|
|
695
764
|
declare function combinePullAdapters<Doc>(adapters: Record<string, ReplicationAdapter<Doc, any>>, options?: {
|
|
696
765
|
legacyKey?: string;
|
|
766
|
+
batchSize?: number;
|
|
767
|
+
key?: (doc: Doc) => unknown;
|
|
697
768
|
}): ReplicationAdapter<Doc, Record<string, any>>;
|
|
698
769
|
|
|
699
|
-
|
|
770
|
+
/**
|
|
771
|
+
* One queued correction, keyed by the local primary key: `key`, or `id`, its
|
|
772
|
+
* older name. An entry without a local copy may carry the listing's key instead
|
|
773
|
+
* (#313). `local` is the till's copy, if it has one; `remote` is whatever the
|
|
774
|
+
* connector needs to refetch it.
|
|
775
|
+
*/
|
|
776
|
+
type ReconcileFeedEntry<Doc = any> = ({
|
|
777
|
+
key: string;
|
|
778
|
+
id?: undefined;
|
|
779
|
+
} | {
|
|
700
780
|
id: string;
|
|
701
|
-
|
|
781
|
+
key?: undefined;
|
|
782
|
+
}) & {
|
|
783
|
+
local?: Doc;
|
|
784
|
+
remote?: unknown;
|
|
702
785
|
/**
|
|
703
786
|
* Re-deliver if the product still exists; never tombstone if missing (the
|
|
704
787
|
* fingerprint path, ADR-060). Only the id reconcile, with its mass-delete
|
|
705
788
|
* brake, enqueues deletable entries.
|
|
706
789
|
*/
|
|
707
790
|
refreshOnly?: boolean;
|
|
791
|
+
/** Proven gone (the catalogue reconcile, #248): written as deleted from `local`, without a fetch. */
|
|
792
|
+
tombstone?: boolean;
|
|
793
|
+
};
|
|
794
|
+
/** What a keyed feed's `fetchByIds` receives for each entry. */
|
|
795
|
+
interface ReconcileFetchEntry<Doc = any> {
|
|
796
|
+
key: string;
|
|
797
|
+
local?: Doc;
|
|
798
|
+
remote?: unknown;
|
|
708
799
|
}
|
|
709
800
|
interface CreateReconcileFeedOptions<Doc = any> {
|
|
710
|
-
/** The current projected documents for the ids that still exist. */
|
|
801
|
+
/** The current projected documents for the ids that still exist, matched back by `doc.id`. */
|
|
711
802
|
fetchByIds(ids: string[], context: SyncContext): Promise<Doc[]>;
|
|
712
803
|
}
|
|
804
|
+
/** A feed keyed by the primary key where that is not `doc.id` (WooCommerce's uuid, #248). */
|
|
805
|
+
interface KeyedReconcileFeedOptions<Doc = any> {
|
|
806
|
+
/** The local primary key of a fetched document; fetched documents are matched to entries by it. */
|
|
807
|
+
key(doc: Doc): string;
|
|
808
|
+
/**
|
|
809
|
+
* The value an entry's `remote` names this document by. An entry with no local copy whose key finds no
|
|
810
|
+
* fetched document is matched by it (a listing that carries no primary key, #313).
|
|
811
|
+
*/
|
|
812
|
+
remote?(doc: Doc): unknown;
|
|
813
|
+
/** The current documents for the entries that still exist. A document may carry `_deleted: true` (an unpublished product). */
|
|
814
|
+
fetchByIds(entries: Array<ReconcileFetchEntry<Doc>>, context: SyncContext): Promise<Doc[]>;
|
|
815
|
+
}
|
|
713
816
|
interface ReconcileFeed<Doc = any> {
|
|
714
817
|
/** Pull-only; meant as the last key of `combinePullAdapters` so its fetch wins duplicates. */
|
|
715
818
|
adapter: ReplicationAdapter<Doc, {
|
|
716
819
|
n: number;
|
|
717
820
|
}>;
|
|
718
821
|
/**
|
|
719
|
-
* Add entries to the in-memory queue, de-duplicated by
|
|
720
|
-
* `
|
|
721
|
-
*
|
|
722
|
-
*
|
|
822
|
+
* Add entries to the in-memory queue, de-duplicated by key, last entry wins.
|
|
823
|
+
* `refreshOnly` is merged separately: it is true only when every merged
|
|
824
|
+
* entry for that key was `refreshOnly`, so a deletable entry (the id
|
|
825
|
+
* reconcile's) is never downgraded by a later refresh-only one.
|
|
723
826
|
*/
|
|
724
827
|
enqueue(entries: Array<ReconcileFeedEntry<Doc>>): void;
|
|
725
828
|
}
|
|
726
|
-
/**
|
|
727
|
-
|
|
829
|
+
/**
|
|
830
|
+
* Turns queued corrections into a pull adapter's documents; nothing here writes locally (ADR-060).
|
|
831
|
+
* Two overloads: with `key`, `fetchByIds` receives the entries and fetched documents are matched by
|
|
832
|
+
* `key(doc)`; without it, `fetchByIds` receives bare ids and documents are matched by `doc.id`.
|
|
833
|
+
*/
|
|
834
|
+
declare function createReconcileFeed<Doc = any>(options: KeyedReconcileFeedOptions<Doc>): ReconcileFeed<Doc>;
|
|
835
|
+
declare function createReconcileFeed<Doc = any>(options: CreateReconcileFeedOptions<Doc>): ReconcileFeed<Doc>;
|
|
728
836
|
|
|
729
837
|
interface ConnectorProviderProps {
|
|
730
838
|
connector: TallyConnector;
|
|
@@ -760,10 +868,19 @@ declare function useTraitContext(): TraitContext;
|
|
|
760
868
|
declare function useProductStock(doc: any): StockLevel & {
|
|
761
869
|
asOf?: string;
|
|
762
870
|
};
|
|
871
|
+
/**
|
|
872
|
+
* The products with the nearest ConnectorProvider's reconciled stock overlay merged in (copies only; the
|
|
873
|
+
* documents are never changed), for components that derive stock from documents themselves. Returns
|
|
874
|
+
* `products` itself, unchanged, when there is no provider, no overlay, or the connector has no stock
|
|
875
|
+
* reconcile adapter, and the same array while its inputs are unchanged.
|
|
876
|
+
*/
|
|
877
|
+
declare function useStockOverlaid<Doc>(products: readonly Doc[]): readonly Doc[];
|
|
878
|
+
/** The reconciled stock overlay's confirmed-as-of time from the nearest ConnectorProvider, or undefined without one or when its connector has no `reconcile.stock` (the same gate `useProductStock` uses). */
|
|
879
|
+
declare function useStockOverlayAsOf(): string | undefined;
|
|
763
880
|
/**
|
|
764
881
|
* Convenience hook: grab just the customer traits from the active connector.
|
|
765
882
|
* Returns undefined if the connector doesn't implement customer traits.
|
|
766
883
|
*/
|
|
767
884
|
declare function useCustomerTraits(): CustomerTraits<any> | undefined;
|
|
768
885
|
|
|
769
|
-
export { type AuthField,
|
|
886
|
+
export { type AuthField, type CatalogueReconcileAdapter, type CatalogueReconcileEntry, type CollectionSync, CommandWarning, type ConnectorAuth, ConnectorProvider, type ConnectorProviderProps, type ConnectorSchemas, type ConnectorTraits, ConnectorUnauthorizedError, type Customer, type CustomerInput, CustomerServiceError, type CustomerTraits, type ErrorKind, type FingerprintReconcileAdapter, type IdReconcileAdapter, type KeyedReconcileFeedOptions, type Money, type ProductPrice, type ProductTraits, type ReconcileFeed, type ReconcileFeedEntry, type ReconcileFetchEntry, type RemoteIdEntry, type ReplicationAdapter, type ResolvedPrice, STOCK_LEVELS_LAST_PASS, type ServerCapabilities, SignInError, type SignInErrorCode, type SignInResult, type StockLevel, type StockReconcileAdapter, type StockStatus, type StoreSettings, type StoreSettingsChoice, type StoreSettingsChoices, StoreSettingsError, type StoreSettingsErrorCode, type SyncContext, type SyncNotice, type TallyConnector, type TaxRounding, type TraitContext, type VariantSummary, combinePullAdapters, compareIds, createReconcileFeed, currencySymbol, customerTraits, errorKind, findVariantByCode, formatMoney, getProductStock, isRxdbRemoteVersionMismatch, knownWarnings, minorUnitDigits, moneyFromDecimalString, moneyFromMajor, moneyToMajor, parseInfoCapabilities, parseTaxRounding, resolveCapabilities, resolvePrice, resolvePriceRange, useConnector, useCustomerTraits, useProductStock, useProductTraits, useStockOverlaid, useStockOverlayAsOf, useTraitContext, withStockOverlay };
|