@tallyui/core 3.0.0-next.0 → 3.0.0-next.2

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/index.d.ts CHANGED
@@ -272,7 +272,7 @@ interface FingerprintReconcileAdapter<Doc = any> {
272
272
  /** Ids per `fetchByIds` request; see `CatalogueReconcileAdapter.refetchBatchSize`. */
273
273
  refetchBatchSize?: number;
274
274
  }
275
- /** One product in the catalogue listing. `key` is the local primary key value; `remote` is whatever the connector needs to refetch it (a numeric backend id, say). */
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
276
  interface CatalogueReconcileEntry {
277
277
  key: string;
278
278
  fingerprint: string;
@@ -293,12 +293,22 @@ interface CatalogueReconcileAdapter<Doc = any, Cursor = unknown> {
293
293
  /** Pure: the same fingerprint from a local document. */
294
294
  fingerprint(doc: Doc): string;
295
295
  /**
296
- * Deletion proof, required: of these local documents (the ones the listing did not name), the keys
297
- * the backend confirms gone (absent, or no longer sellable). One or more requests. Only confirmed
298
- * keys are tombstoned; an adapter that never deletes returns none.
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.
299
306
  */
300
307
  confirmGone(locals: Doc[], context: SyncContext): Promise<string[]>;
301
- /** Hand documents to the collection's pull (the reconcile feed). */
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
+ */
302
312
  enqueue(entries: Array<{
303
313
  key: string;
304
314
  local?: Doc;
@@ -320,6 +330,8 @@ interface StoreSettings {
320
330
  default: number;
321
331
  [taxClass: string]: number;
322
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>;
323
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. */
324
336
  pricingContext?: Record<string, string>;
325
337
  /** Derived, never read by `storeSettings`: the store's `ServerCapabilities.taxRounding`, which `useStoreSettings` fills in (#324). */
@@ -431,8 +443,10 @@ declare function parseTaxRounding(value: unknown, warn?: (reason: string) => voi
431
443
  * Reads a 2xx body of `GET /tally/v1/info` (ADR-062): `orderCreate` is the max of
432
444
  * `contracts["order.create"]`, or 1 when it's missing or malformed; `register` is the max of
433
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
+ * A non-object body is also unknown, not a statement of the store's defaults.
434
448
  */
435
- declare function parseInfoCapabilities(body: unknown, warn?: (reason: string) => void): ServerCapabilities;
449
+ declare function parseInfoCapabilities(body: unknown, warn?: (reason: string) => void): ServerCapabilities | undefined;
436
450
  interface AuthField {
437
451
  key: string;
438
452
  label: string;
@@ -555,6 +569,9 @@ interface TallyConnector {
555
569
  * block discounts until the cashier signed in again. `undefined` means
556
570
  * the read was inconclusive (offline or a server error), not version 1;
557
571
  * see `resolveCapabilities`.
572
+ * It throws when the store refuses the read. Medusa throws `SignInError` (`invalid_credentials`) for a 401. Vendure
573
+ * throws `ConnectorUnauthorizedError`: `status: 401` when the session is signed out, `status: 403` when a signed-in
574
+ * administrator lacks the CreateOrder permission.
558
575
  */
559
576
  capabilities?: (context: SyncContext) => Promise<ServerCapabilities | undefined>;
560
577
  /** Customer search: online only; `undefined` when the connector has no customer support. */
@@ -582,13 +599,13 @@ declare class SignInError extends Error {
582
599
  constructor(code: SignInErrorCode, message: string, status?: number);
583
600
  }
584
601
 
585
- /** A backend refused the stored credentials (expired, revoked or insufficient); the app should sign in again. */
602
+ /** 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. */
586
603
  declare class ConnectorUnauthorizedError extends Error {
587
- readonly code: "unauthorized";
588
- /** Only signing in on this till fixes it, so the pull stops until `resume()` (`errorKind`). */
589
- readonly fixedBy: "till";
590
- readonly status?: number;
591
- constructor(message: string, status?: number);
604
+ readonly code: 'unauthorized' | 'forbidden';
605
+ readonly fixedBy: 'till' | 'store';
606
+ /** Set by meaning, not copied from the HTTP answer: a backend that answers both with the same code decides first (Vendure's session probe). */
607
+ readonly status: 401 | 403;
608
+ constructor(message: string, status: 401 | 403);
592
609
  }
593
610
 
594
611
  /**
@@ -745,17 +762,20 @@ declare function getProductStock<Doc>(doc: Doc, traits: ProductTraits<Doc>, adap
745
762
  *
746
763
  * `options.batchSize` sets the combined pull page size; sub-adapters' own
747
764
  * `pull.batchSize` is ignored.
765
+ * 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.
748
766
  * Pull only: a sub-adapter with `push` or `pull.stream$` throws here.
749
767
  */
750
768
  declare function combinePullAdapters<Doc>(adapters: Record<string, ReplicationAdapter<Doc, any>>, options?: {
751
769
  legacyKey?: string;
752
770
  batchSize?: number;
771
+ key?: (doc: Doc) => unknown;
753
772
  }): ReplicationAdapter<Doc, Record<string, any>>;
754
773
 
755
774
  /**
756
775
  * One queued correction, keyed by the local primary key: `key`, or `id`, its
757
- * older name. `local` is the till's copy, if it has one; `remote` is whatever
758
- * the connector needs to refetch it.
776
+ * older name. An entry without a local copy may carry the listing's key instead
777
+ * (#313). `local` is the till's copy, if it has one; `remote` is whatever the
778
+ * connector needs to refetch it.
759
779
  */
760
780
  type ReconcileFeedEntry<Doc = any> = ({
761
781
  key: string;
@@ -789,6 +809,11 @@ interface CreateReconcileFeedOptions<Doc = any> {
789
809
  interface KeyedReconcileFeedOptions<Doc = any> {
790
810
  /** The local primary key of a fetched document; fetched documents are matched to entries by it. */
791
811
  key(doc: Doc): string;
812
+ /**
813
+ * The value an entry's `remote` names this document by. An entry with no local copy whose key finds no
814
+ * fetched document is matched by it (a listing that carries no primary key, #313).
815
+ */
816
+ remote?(doc: Doc): unknown;
792
817
  /** The current documents for the entries that still exist. A document may carry `_deleted: true` (an unpublished product). */
793
818
  fetchByIds(entries: Array<ReconcileFetchEntry<Doc>>, context: SyncContext): Promise<Doc[]>;
794
819
  }
package/dist/index.js CHANGED
@@ -29,9 +29,17 @@ var maxVersion = (list) => {
29
29
  return valid.length > 0 ? Math.max(...valid) : void 0;
30
30
  };
31
31
  function parseInfoCapabilities(body, warn) {
32
- const { contracts, taxRounding } = body ?? {};
32
+ if (body === null || Array.isArray(body) || typeof body !== "object") {
33
+ warn?.("non-object info body: capabilities unknown");
34
+ return void 0;
35
+ }
36
+ const { contracts, taxRounding } = body;
33
37
  const register = maxVersion(contracts?.register);
34
- const rounding = parseTaxRounding(taxRounding, warn);
38
+ const rounding = parseTaxRounding(taxRounding);
39
+ if (taxRounding !== void 0 && rounding === void 0) {
40
+ warn?.(`malformed taxRounding: rounding is unknown, so settings wait: ${JSON.stringify(taxRounding)}`);
41
+ return void 0;
42
+ }
35
43
  return {
36
44
  orderCreate: maxVersion(contracts?.["order.create"]) ?? 1,
37
45
  ...register !== void 0 ? { register } : {},
@@ -53,14 +61,16 @@ var SignInError = class extends Error {
53
61
 
54
62
  // src/unauthorized.ts
55
63
  var ConnectorUnauthorizedError = class extends Error {
56
- code = "unauthorized";
57
- /** Only signing in on this till fixes it, so the pull stops until `resume()` (`errorKind`). */
58
- fixedBy = "till";
64
+ code;
65
+ fixedBy;
66
+ /** Set by meaning, not copied from the HTTP answer: a backend that answers both with the same code decides first (Vendure's session probe). */
59
67
  status;
60
68
  constructor(message, status) {
61
69
  super(message);
62
70
  this.name = "ConnectorUnauthorizedError";
63
- this.status = status;
71
+ this.status = status === 403 ? 403 : 401;
72
+ this.code = status === 403 ? "forbidden" : "unauthorized";
73
+ this.fixedBy = status === 403 ? "store" : "till";
64
74
  }
65
75
  };
66
76
 
@@ -329,14 +339,15 @@ function combinePullAdapters(adapters, options = {}) {
329
339
  }
330
340
  previous = seeded;
331
341
  }
332
- const byId = /* @__PURE__ */ new Map();
342
+ const keyOf2 = options.key ?? ((doc) => doc.id);
343
+ const byKey = /* @__PURE__ */ new Map();
333
344
  const checkpoint = {};
334
345
  for (const key of keys) {
335
346
  const result = await adapters[key].pull.handler(previous?.[key], batchSize, context);
336
- for (const doc of result.documents) byId.set(doc.id, doc);
347
+ for (const doc of result.documents) byKey.set(keyOf2(doc), doc);
337
348
  checkpoint[key] = { ...previous?.[key], ...result.checkpoint };
338
349
  }
339
- return { documents: [...byId.values()], checkpoint };
350
+ return { documents: [...byKey.values()], checkpoint };
340
351
  }
341
352
  }
342
353
  };
@@ -366,10 +377,17 @@ function createReconcileFeed(options) {
366
377
  const toFetch = chunk.filter((e) => !e.tombstone);
367
378
  const fetched = toFetch.length ? await fetch(toFetch, context) : [];
368
379
  const byKey = new Map(fetched.map((doc) => [docKey(doc), doc]));
380
+ const byRemote = keyed?.remote && new Map(fetched.map((doc) => [keyed.remote(doc), doc]));
381
+ const pushed = /* @__PURE__ */ new Set();
369
382
  for (const entry of chunk) {
370
- const doc = entry.tombstone ? void 0 : byKey.get(keyOf(entry));
371
- if (doc) documents.push({ ...doc, _deleted: doc._deleted ?? false });
372
- else if (!entry.refreshOnly && entry.local) documents.push({ ...entry.local, _deleted: true });
383
+ const doc = entry.tombstone ? void 0 : byKey.get(keyOf(entry)) ?? (entry.local === void 0 && entry.remote !== void 0 && byRemote ? byRemote.get(entry.remote) : void 0);
384
+ const moved = !entry.tombstone && !doc && entry.local !== void 0 && entry.remote !== void 0 && byRemote ? byRemote.get(entry.remote) : void 0;
385
+ const fetchedDoc = doc ?? moved;
386
+ if (fetchedDoc && !pushed.has(fetchedDoc)) {
387
+ documents.push({ ...fetchedDoc, _deleted: fetchedDoc._deleted ?? false });
388
+ pushed.add(fetchedDoc);
389
+ }
390
+ if (!doc && !entry.refreshOnly && entry.local) documents.push({ ...entry.local, _deleted: true });
373
391
  }
374
392
  }
375
393
  return { documents, checkpoint: { n: (lastCheckpoint?.n ?? 0) + 1 } };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tallyui/core",
3
- "version": "3.0.0-next.0",
3
+ "version": "3.0.0-next.2",
4
4
  "type": "module",
5
5
  "description": "Core interfaces, traits, and context providers for Tally UI",
6
6
  "main": "./dist/index.js",
@@ -14,11 +14,12 @@ import type { ReplicationAdapter } from '../types';
14
14
  *
15
15
  * `options.batchSize` sets the combined pull page size; sub-adapters' own
16
16
  * `pull.batchSize` is ignored.
17
+ * 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.
17
18
  * Pull only: a sub-adapter with `push` or `pull.stream$` throws here.
18
19
  */
19
20
  export function combinePullAdapters<Doc>(
20
21
  adapters: Record<string, ReplicationAdapter<Doc, any>>,
21
- options: { legacyKey?: string; batchSize?: number } = {},
22
+ options: { legacyKey?: string; batchSize?: number; key?: (doc: Doc) => unknown } = {},
22
23
  ): ReplicationAdapter<Doc, Record<string, any>> {
23
24
  const keys = Object.keys(adapters);
24
25
  for (const key of keys) {
@@ -50,7 +51,8 @@ export function combinePullAdapters<Doc>(
50
51
  }
51
52
  previous = seeded;
52
53
  }
53
- const byId = new Map<unknown, Doc & { _deleted: boolean }>();
54
+ const keyOf = options.key ?? ((doc: Doc) => (doc as { id?: unknown }).id);
55
+ const byKey = new Map<unknown, Doc & { _deleted: boolean }>();
54
56
  const checkpoint: Record<string, any> = {};
55
57
  // Call sub-adapters strictly one after another, in key order: a
56
58
  // correctness rule, not politeness. Each feed writes whole documents.
@@ -62,15 +64,15 @@ export function combinePullAdapters<Doc>(
62
64
  // it, with neither checkpoint ever revisiting the document.
63
65
  for (const key of keys) {
64
66
  const result = await adapters[key].pull.handler(previous?.[key], batchSize, context);
65
- for (const doc of result.documents) byId.set((doc as { id?: unknown }).id, doc);
67
+ for (const doc of result.documents) byKey.set(keyOf(doc), doc);
66
68
  // RxDB merges only the top level of the combined checkpoint, so merge
67
69
  // each sub-checkpoint here as it would for a single adapter. Spread
68
70
  // keeps a sub-adapter's explicit undefined (cleared pass state).
69
71
  checkpoint[key] = { ...previous?.[key], ...result.checkpoint };
70
72
  }
71
- // Each sub-adapter returns unique ids, so one full sub-page makes the
73
+ // Each sub-adapter returns unique keys, so one full sub-page makes the
72
74
  // combined page full: RxDB keeps pulling while any sub-adapter has more.
73
- return { documents: [...byId.values()], checkpoint };
75
+ return { documents: [...byKey.values()], checkpoint };
74
76
  },
75
77
  },
76
78
  };
@@ -6,8 +6,9 @@ const MAX_CHUNK = 1000;
6
6
 
7
7
  /**
8
8
  * One queued correction, keyed by the local primary key: `key`, or `id`, its
9
- * older name. `local` is the till's copy, if it has one; `remote` is whatever
10
- * the connector needs to refetch it.
9
+ * older name. An entry without a local copy may carry the listing's key instead
10
+ * (#313). `local` is the till's copy, if it has one; `remote` is whatever the
11
+ * connector needs to refetch it.
11
12
  */
12
13
  export type ReconcileFeedEntry<Doc = any> = ({ key: string; id?: undefined } | { id: string; key?: undefined }) & {
13
14
  local?: Doc;
@@ -31,6 +32,11 @@ export interface CreateReconcileFeedOptions<Doc = any> {
31
32
  export interface KeyedReconcileFeedOptions<Doc = any> {
32
33
  /** The local primary key of a fetched document; fetched documents are matched to entries by it. */
33
34
  key(doc: Doc): string;
35
+ /**
36
+ * The value an entry's `remote` names this document by. An entry with no local copy whose key finds no
37
+ * fetched document is matched by it (a listing that carries no primary key, #313).
38
+ */
39
+ remote?(doc: Doc): unknown;
34
40
  /** The current documents for the entries that still exist. A document may carry `_deleted: true` (an unpublished product). */
35
41
  fetchByIds(entries: Array<ReconcileFetchEntry<Doc>>, context: SyncContext): Promise<Doc[]>;
36
42
  }
@@ -85,14 +91,24 @@ export function createReconcileFeed<Doc = any>(
85
91
  const toFetch = chunk.filter((e) => !e.tombstone);
86
92
  const fetched = toFetch.length ? await fetch(toFetch, context) : [];
87
93
  const byKey = new Map(fetched.map((doc) => [docKey(doc), doc]));
94
+ const byRemote = keyed?.remote && new Map(fetched.map((doc) => [keyed.remote!(doc), doc]));
95
+ const pushed = new Set<Doc>();
88
96
  for (const entry of chunk) {
89
- const doc = entry.tombstone ? undefined : byKey.get(keyOf(entry));
97
+ const doc = entry.tombstone ? undefined : byKey.get(keyOf(entry))
98
+ ?? (entry.local === undefined && entry.remote !== undefined && byRemote ? byRemote.get(entry.remote) : undefined);
99
+ // The backend primary key changed (a WCPOS uuid reassigned, #331): the old copy goes and the current one arrives.
100
+ const moved = !entry.tombstone && !doc && entry.local !== undefined && entry.remote !== undefined && byRemote
101
+ ? byRemote.get(entry.remote) : undefined;
102
+ const fetchedDoc = doc ?? moved;
90
103
  // A fetched document keeps a `_deleted` the connector set (an unpublished product, #248).
91
- if (doc) documents.push({ ...doc, _deleted: (doc as { _deleted?: boolean })._deleted ?? false });
104
+ if (fetchedDoc && !pushed.has(fetchedDoc)) {
105
+ documents.push({ ...fetchedDoc, _deleted: (fetchedDoc as { _deleted?: boolean })._deleted ?? false });
106
+ pushed.add(fetchedDoc);
107
+ }
92
108
  // A refreshOnly entry (the fingerprint path) is skipped, not tombstoned, when the
93
109
  // product is missing: only the id reconcile's braked entries may delete (ADR-060).
94
110
  // An entry with no local copy has nothing to delete.
95
- else if (!entry.refreshOnly && entry.local) documents.push({ ...entry.local, _deleted: true });
111
+ if (!doc && !entry.refreshOnly && entry.local) documents.push({ ...entry.local, _deleted: true });
96
112
  }
97
113
  }
98
114
  return { documents, checkpoint: { n: (lastCheckpoint?.n ?? 0) + 1 } };
@@ -95,11 +95,21 @@ const maxVersion = (list: unknown): number | undefined => {
95
95
  * Reads a 2xx body of `GET /tally/v1/info` (ADR-062): `orderCreate` is the max of
96
96
  * `contracts["order.create"]`, or 1 when it's missing or malformed; `register` is the max of
97
97
  * `contracts.register` when valid; `taxRounding` is the top-level sibling of `contracts` (#287).
98
+ * Absent `taxRounding` uses the default; a present malformed value is unknown, so settings wait.
99
+ * A non-object body is also unknown, not a statement of the store's defaults.
98
100
  */
99
- export function parseInfoCapabilities(body: unknown, warn?: (reason: string) => void): ServerCapabilities {
100
- const { contracts, taxRounding } = (body ?? {}) as { contracts?: Record<string, unknown> | null; taxRounding?: unknown };
101
+ export function parseInfoCapabilities(body: unknown, warn?: (reason: string) => void): ServerCapabilities | undefined {
102
+ if (body === null || Array.isArray(body) || typeof body !== 'object') {
103
+ warn?.('non-object info body: capabilities unknown');
104
+ return undefined;
105
+ }
106
+ const { contracts, taxRounding } = body as { contracts?: Record<string, unknown> | null; taxRounding?: unknown };
101
107
  const register = maxVersion(contracts?.register);
102
- const rounding = parseTaxRounding(taxRounding, warn);
108
+ const rounding = parseTaxRounding(taxRounding);
109
+ if (taxRounding !== undefined && rounding === undefined) {
110
+ warn?.(`malformed taxRounding: rounding is unknown, so settings wait: ${JSON.stringify(taxRounding)}`);
111
+ return undefined;
112
+ }
103
113
  return { orderCreate: maxVersion(contracts?.['order.create']) ?? 1,
104
114
  ...(register !== undefined ? { register } : {}), ...(rounding ? { taxRounding: rounding } : {}) };
105
115
  }
@@ -241,6 +251,9 @@ export interface TallyConnector {
241
251
  * block discounts until the cashier signed in again. `undefined` means
242
252
  * the read was inconclusive (offline or a server error), not version 1;
243
253
  * see `resolveCapabilities`.
254
+ * It throws when the store refuses the read. Medusa throws `SignInError` (`invalid_credentials`) for a 401. Vendure
255
+ * throws `ConnectorUnauthorizedError`: `status: 401` when the session is signed out, `status: 403` when a signed-in
256
+ * administrator lacks the CreateOrder permission.
244
257
  */
245
258
  capabilities?: (context: SyncContext) => Promise<ServerCapabilities | undefined>;
246
259
  /** Customer search: online only; `undefined` when the connector has no customer support. */
@@ -46,7 +46,7 @@ export interface FingerprintReconcileAdapter<Doc = any> {
46
46
  refetchBatchSize?: number;
47
47
  }
48
48
 
49
- /** One product in the catalogue listing. `key` is the local primary key value; `remote` is whatever the connector needs to refetch it (a numeric backend id, say). */
49
+ /** 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). */
50
50
  export interface CatalogueReconcileEntry { key: string; fingerprint: string; remote?: unknown }
51
51
 
52
52
  /**
@@ -61,12 +61,22 @@ export interface CatalogueReconcileAdapter<Doc = any, Cursor = unknown> {
61
61
  /** Pure: the same fingerprint from a local document. */
62
62
  fingerprint(doc: Doc): string;
63
63
  /**
64
- * Deletion proof, required: of these local documents (the ones the listing did not name), the keys
65
- * the backend confirms gone (absent, or no longer sellable). One or more requests. Only confirmed
66
- * keys are tombstoned; an adapter that never deletes returns none.
64
+ * When set, each listing entry's `key` is this value, not the local primary key (a listing that carries no
65
+ * primary key, such as WCPOS's fast path, #313). The runner indexes the local documents by it for the pass.
66
+ * A document for which it returns undefined can't be matched: it is never compared, and it is a deletion
67
+ * candidate, as today.
68
+ */
69
+ matchKey?(doc: Doc): string | undefined;
70
+ /**
71
+ * Deletion proof, required: of these local documents (the ones the listing did not name), the primary keys
72
+ * the backend confirms gone (absent, or no longer sellable), with or without `matchKey`. One or more requests.
73
+ * Only confirmed keys are tombstoned; an adapter that never deletes returns none.
67
74
  */
68
75
  confirmGone(locals: Doc[], context: SyncContext): Promise<string[]>;
69
- /** Hand documents to the collection's pull (the reconcile feed). */
76
+ /**
77
+ * Hand documents to the collection's pull (the reconcile feed). An entry's `key` is the local primary key when
78
+ * there is a local copy, and otherwise the listing's key.
79
+ */
70
80
  enqueue(entries: Array<{ key: string; local?: Doc; remote?: unknown; tombstone?: boolean }>): void;
71
81
  /** 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). */
72
82
  refetchBatchSize?: number;
@@ -8,6 +8,8 @@ export interface StoreSettings {
8
8
  pricesIncludeTax: boolean;
9
9
  /** Tax rates for the store's location as integer parts per million (25% = 250000), keyed by the backend's tax class; `default` applies to a product with no class. Always integers: a connector rounds a backend's decimal rate once, at its edge. Structurally the same as @tallyui/pos's TaxRateMap. */
10
10
  taxRatesPpm: { default: number; [taxClass: string]: number };
11
+ /** 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. */
12
+ taxRateCodes?: Record<string, string>;
11
13
  /** 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. */
12
14
  pricingContext?: Record<string, string>;
13
15
  /** Derived, never read by `storeSettings`: the store's `ServerCapabilities.taxRounding`, which `useStoreSettings` fills in (#324). */
@@ -1,13 +1,15 @@
1
- /** A backend refused the stored credentials (expired, revoked or insufficient); the app should sign in again. */
1
+ /** 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. */
2
2
  export class ConnectorUnauthorizedError extends Error {
3
- readonly code = 'unauthorized' as const;
4
- /** Only signing in on this till fixes it, so the pull stops until `resume()` (`errorKind`). */
5
- readonly fixedBy = 'till' as const;
6
- readonly status?: number;
3
+ readonly code: 'unauthorized' | 'forbidden';
4
+ readonly fixedBy: 'till' | 'store';
5
+ /** Set by meaning, not copied from the HTTP answer: a backend that answers both with the same code decides first (Vendure's session probe). */
6
+ readonly status: 401 | 403;
7
7
 
8
- constructor(message: string, status?: number) {
8
+ constructor(message: string, status: 401 | 403) {
9
9
  super(message);
10
10
  this.name = 'ConnectorUnauthorizedError';
11
- this.status = status;
11
+ this.status = status === 403 ? 403 : 401;
12
+ this.code = status === 403 ? 'forbidden' : 'unauthorized';
13
+ this.fixedBy = status === 403 ? 'store' : 'till';
12
14
  }
13
15
  }