@tallyui/core 3.0.0-next.1 → 3.0.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/dist/index.d.ts CHANGED
@@ -444,6 +444,7 @@ declare function parseTaxRounding(value: unknown, warn?: (reason: string) => voi
444
444
  * `contracts["order.create"]`, or 1 when it's missing or malformed; `register` is the max of
445
445
  * `contracts.register` when valid; `taxRounding` is the top-level sibling of `contracts` (#287).
446
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.
447
448
  */
448
449
  declare function parseInfoCapabilities(body: unknown, warn?: (reason: string) => void): ServerCapabilities | undefined;
449
450
  interface AuthField {
@@ -568,6 +569,11 @@ interface TallyConnector {
568
569
  * block discounts until the cashier signed in again. `undefined` means
569
570
  * the read was inconclusive (offline or a server error), not version 1;
570
571
  * see `resolveCapabilities`.
572
+ * It may throw when the store refuses the read. Medusa throws `SignInError` (`invalid_credentials`) for a 401; its
573
+ * 403 gives `undefined`. Vendure throws `ConnectorUnauthorizedError` only once its sign-in probe settles the
574
+ * cause: `status: 401` when the session is signed out, `status: 403` when a signed-in administrator lacks the
575
+ * CreateOrder permission; a probe that fails gives `undefined`. Branch on the error's `code` (only
576
+ * `unauthorized` or `invalid_credentials` means sign in again), never on its class.
571
577
  */
572
578
  capabilities?: (context: SyncContext) => Promise<ServerCapabilities | undefined>;
573
579
  /** Customer search: online only; `undefined` when the connector has no customer support. */
package/dist/index.js CHANGED
@@ -29,7 +29,11 @@ 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
38
  const rounding = parseTaxRounding(taxRounding);
35
39
  if (taxRounding !== void 0 && rounding === void 0) {
@@ -64,9 +68,9 @@ var ConnectorUnauthorizedError = class extends Error {
64
68
  constructor(message, status) {
65
69
  super(message);
66
70
  this.name = "ConnectorUnauthorizedError";
67
- this.status = status;
68
- this.code = status === 401 ? "unauthorized" : "forbidden";
69
- this.fixedBy = status === 401 ? "till" : "store";
71
+ this.status = status === 403 ? 403 : 401;
72
+ this.code = status === 403 ? "forbidden" : "unauthorized";
73
+ this.fixedBy = status === 403 ? "store" : "till";
70
74
  }
71
75
  };
72
76
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tallyui/core",
3
- "version": "3.0.0-next.1",
3
+ "version": "3.0.0",
4
4
  "type": "module",
5
5
  "description": "Core interfaces, traits, and context providers for Tally UI",
6
6
  "main": "./dist/index.js",
@@ -70,8 +70,9 @@ export function combinePullAdapters<Doc>(
70
70
  // keeps a sub-adapter's explicit undefined (cleared pass state).
71
71
  checkpoint[key] = { ...previous?.[key], ...result.checkpoint };
72
72
  }
73
- // Each sub-adapter returns unique keys, so one full sub-page makes the
74
- // combined page full: RxDB keeps pulling while any sub-adapter has more.
73
+ // The full-page claim rests on each sub-adapter returning unique keys within a page (for WooCommerce,
74
+ // WCPOS keeps uuids unique per response): then one full sub-page makes the combined page full, and RxDB
75
+ // keeps pulling while any sub-adapter has more.
75
76
  return { documents: [...byKey.values()], checkpoint };
76
77
  },
77
78
  },
@@ -96,9 +96,14 @@ const maxVersion = (list: unknown): number | undefined => {
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
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.
99
100
  */
100
101
  export function parseInfoCapabilities(body: unknown, warn?: (reason: string) => void): ServerCapabilities | undefined {
101
- const { contracts, taxRounding } = (body ?? {}) as { contracts?: Record<string, unknown> | null; taxRounding?: unknown };
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 };
102
107
  const register = maxVersion(contracts?.register);
103
108
  const rounding = parseTaxRounding(taxRounding);
104
109
  if (taxRounding !== undefined && rounding === undefined) {
@@ -246,6 +251,11 @@ export interface TallyConnector {
246
251
  * block discounts until the cashier signed in again. `undefined` means
247
252
  * the read was inconclusive (offline or a server error), not version 1;
248
253
  * see `resolveCapabilities`.
254
+ * It may throw when the store refuses the read. Medusa throws `SignInError` (`invalid_credentials`) for a 401; its
255
+ * 403 gives `undefined`. Vendure throws `ConnectorUnauthorizedError` only once its sign-in probe settles the
256
+ * cause: `status: 401` when the session is signed out, `status: 403` when a signed-in administrator lacks the
257
+ * CreateOrder permission; a probe that fails gives `undefined`. Branch on the error's `code` (only
258
+ * `unauthorized` or `invalid_credentials` means sign in again), never on its class.
249
259
  */
250
260
  capabilities?: (context: SyncContext) => Promise<ServerCapabilities | undefined>;
251
261
  /** Customer search: online only; `undefined` when the connector has no customer support. */
@@ -8,8 +8,8 @@ export class ConnectorUnauthorizedError extends Error {
8
8
  constructor(message: string, status: 401 | 403) {
9
9
  super(message);
10
10
  this.name = 'ConnectorUnauthorizedError';
11
- this.status = status;
12
- this.code = status === 401 ? 'unauthorized' : 'forbidden';
13
- this.fixedBy = status === 401 ? 'till' : 'store';
11
+ this.status = status === 403 ? 403 : 401;
12
+ this.code = status === 403 ? 'forbidden' : 'unauthorized';
13
+ this.fixedBy = status === 403 ? 'store' : 'till';
14
14
  }
15
15
  }