@tallyui/core 3.0.0-next.1 → 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
@@ -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,9 @@ 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 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.
571
575
  */
572
576
  capabilities?: (context: SyncContext) => Promise<ServerCapabilities | undefined>;
573
577
  /** 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-next.2",
4
4
  "type": "module",
5
5
  "description": "Core interfaces, traits, and context providers for Tally UI",
6
6
  "main": "./dist/index.js",
@@ -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,9 @@ 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 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.
249
257
  */
250
258
  capabilities?: (context: SyncContext) => Promise<ServerCapabilities | undefined>;
251
259
  /** 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
  }