@tallyui/core 3.13.0 → 3.15.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
@@ -693,6 +693,44 @@ declare function isCashierPermission(value: unknown): value is CashierPermission
693
693
  /** The known permission names in `values`, first occurrence order, without duplicates; anything else is dropped. */
694
694
  declare function cashierPermissions(values: readonly unknown[]): CashierPermission[];
695
695
 
696
+ /**
697
+ * How well a connector's store answers (v2 parity A6, unit 34). The same three states as WCPOS v2's
698
+ * `EngineConnectivity`: `degraded` means the device is online but the store keeps failing.
699
+ */
700
+ type ConnectivityState = 'online' | 'offline' | 'degraded';
701
+ /**
702
+ * A store's deliberate refusal to sync until someone updates software. `fixedBy` as in `SyncNotice`: `'till'` when
703
+ * this app is older than the store accepts, `'store'` when the store's software is older than the app needs.
704
+ * `reason` is the connector's code for it; `software`, `minVersion` and `status` only when the refusal names them.
705
+ */
706
+ type UpdateRequired = {
707
+ reason: string;
708
+ fixedBy: 'till' | 'store';
709
+ software?: string;
710
+ minVersion?: string;
711
+ status?: number;
712
+ };
713
+ /** What one failed request says: about connectivity, an update-required refusal, or nothing (`null`). */
714
+ type FailureClass = 'offline' | 'degraded' | {
715
+ updateRequired: UpdateRequired;
716
+ } | null;
717
+ /**
718
+ * For a connector's fetch call site alone: `fetch(url, init).catch(noResponse)`. A fetch that rejects got no response,
719
+ * but its `TypeError` looks like one our own code throws, so the call site tags it: rethrown as a `NoResponseError`
720
+ * with `code: 'network'` (offline to `neutralFailureClass`) and the original as `cause`. An abort or timeout is
721
+ * rethrown unchanged. Code that reads the response runs after the catch, so its errors are never tagged.
722
+ */
723
+ declare function noResponse(error: unknown): never;
724
+ /**
725
+ * The rule for a connector without `classifyFailure`: a timeout or a 5xx is `degraded`; a request that got no
726
+ * response (`code: 'network'`, as `noResponse` and `CustomerServiceError` set, or a no-response socket code on the
727
+ * error or its `cause`) is `offline`; anything else is `null`, a bare `TypeError` included, since our own code throws
728
+ * those too. It never answers update-required: only a connector knows its own refusal.
729
+ */
730
+ declare function neutralFailureClass(error: unknown): FailureClass;
731
+ /** The connector's own `classifyFailure` when it has one (its answer is final), else `neutralFailureClass`. A method that throws gives `null`. */
732
+ declare function classifyFailure(connector: Pick<TallyConnector, 'classifyFailure'> | undefined, error: unknown): FailureClass;
733
+
696
734
  /**
697
735
  * Authentication configuration for a connector.
698
736
  * Each API has wildly different auth — JWT, API keys, OAuth, etc.
@@ -940,7 +978,11 @@ interface TallyConnector {
940
978
  * the store. `undefined` when the connector has none of its own: the till offers `defaultPaymentMethods()`.
941
979
  */
942
980
  paymentMethods?: (context: SyncContext) => Promise<PaymentMethodDescriptor[]>;
943
- /** Customer search: online only; `undefined` when the connector has no customer support. */
981
+ /**
982
+ * Customer search: online only. An empty or whitespace query may list a first page of the store's customers
983
+ * (recent ones, or in the store's own picker order); a connector that cannot list them returns `[]`.
984
+ * `undefined` when the connector has no customer support.
985
+ */
944
986
  searchCustomers?: (context: SyncContext, query: string, options?: {
945
987
  limit?: number;
946
988
  }) => Promise<Customer[]>;
@@ -988,6 +1030,13 @@ interface TallyConnector {
988
1030
  * Permission names outside `CashierPermission` are dropped by `useCashier` (`cashierPermissions`).
989
1031
  */
990
1032
  cashier?: (context: SyncContext) => Promise<Cashier | null>;
1033
+ /**
1034
+ * Maps one of this connector's request failures (pull, push, reconcile, online calls) to a connectivity verdict or
1035
+ * its own update-required refusal (v2 parity A6). Synchronous and pure. `null` when the failure says nothing about
1036
+ * connectivity (a validation refusal). `undefined` (no method) uses `neutralFailureClass`, which a connector's own
1037
+ * method may also call for the failures it does not map.
1038
+ */
1039
+ classifyFailure?: (error: unknown) => FailureClass;
991
1040
  }
992
1041
 
993
1042
  /**
@@ -1854,4 +1903,4 @@ declare namespace index {
1854
1903
  export { type index_CouponContext as CouponContext, type index_CouponDiscountConfig as CouponDiscountConfig, type index_CouponInput as CouponInput, type index_CouponLineInput as CouponLineInput, type index_CouponRejection as CouponRejection, type index_CouponRejectionCode as CouponRejectionCode, type index_CouponValidationContext as CouponValidationContext, type index_EngineWarning as EngineWarning, type index_LineItemInput as LineItemInput, type index_OrderTotals as OrderTotals, type index_RecalculateInput as RecalculateInput, type index_RecalculateResult as RecalculateResult, type index_TaxRateInput as TaxRateInput, type index_ValidationResult as ValidationResult, index_calculateOrderTotals as calculateOrderTotals, index_enrichCategoriesWithAncestors as enrichCategoriesWithAncestors, index_recalculateCoupons as recalculateCoupons, index_toCouponConfigs as toCouponConfigs, index_validateCoupon as validateCoupon };
1855
1904
  }
1856
1905
 
1857
- export { type AuthField, CASHIER_PERMISSIONS, type CaptureMode, type CaptureModeEntry, type Cashier, type CashierPermission, type CatalogueReconcileAdapter, type CatalogueReconcileEntry, type CollectionSync, CommandWarning, type ConnectorAuth, ConnectorProvider, type ConnectorProviderProps, type ConnectorSchemas, type ConnectorTraits, ConnectorUnauthorizedError, type Customer, type CustomerAddress, type CustomerInput, type CustomerPatch, CustomerServiceError, type CustomerTaxId, type CustomerTraits, type ErrorKind, type FingerprintReconcileAdapter, type IdReconcileAdapter, type KeyedReconcileFeedOptions, type ListOrdersQuery, type Money, type PaymentHardware, type PaymentKind, type PaymentMethodDescriptor, PaymentMethodKind, type PaymentOfflineMode, type PaymentRounding, type PaymentTipsMode, type PaymentTransport, type ProductCategory, type ProductPrice, type ProductTraits, type ReconcileFeed, type ReconcileFeedEntry, type ReconcileFetchEntry, type RegisterInfo, type RemoteIdEntry, type ReplicationAdapter, type ResolvedPrice, STOCK_LEVELS_LAST_PASS, type ServerCapabilities, SignInError, type SignInErrorCode, type SignInResult, type StockLevel, type StockReconcileAdapter, type StockStatus, type StoreOrder, type StoreOrderCharge, type StoreOrderLine, type StoreOrderPage, type StoreOrderPayment, type StoreOrderRefund, type StoreSettings, type StoreSettingsChoice, type StoreSettingsChoices, StoreSettingsError, type StoreSettingsErrorCode, type SyncContext, type SyncNotice, type TallyConnector, type TaxRounding, type TraitContext, type VariantOptionGroup, type VariantSummary, cashierPermissions, combinePullAdapters, compareIds, createReconcileFeed, currencySymbol, customerTraits, defaultPaymentMethods, errorKind, findVariantByCode, formatMoney, getProductStock, isCashierPermission, isRxdbRemoteVersionMismatch, knownWarnings, minorUnitDigits, moneyFromDecimalString, moneyFromMajor, moneyToMajor, parseInfoCapabilities, parseLineTax, parseTaxRounding, paymentMethodOf, resolveCapabilities, resolvePrice, resolvePriceRange, useConnector, useCustomerTraits, useProductStock, useProductTraits, useStockOverlaid, useStockOverlayAsOf, useTraitContext, withStockOverlay, index as woocommerceCoupons, index$1 as woocommerceTax };
1906
+ export { type AuthField, CASHIER_PERMISSIONS, type CaptureMode, type CaptureModeEntry, type Cashier, type CashierPermission, type CatalogueReconcileAdapter, type CatalogueReconcileEntry, type CollectionSync, CommandWarning, type ConnectivityState, type ConnectorAuth, ConnectorProvider, type ConnectorProviderProps, type ConnectorSchemas, type ConnectorTraits, ConnectorUnauthorizedError, type Customer, type CustomerAddress, type CustomerInput, type CustomerPatch, CustomerServiceError, type CustomerTaxId, type CustomerTraits, type ErrorKind, type FailureClass, type FingerprintReconcileAdapter, type IdReconcileAdapter, type KeyedReconcileFeedOptions, type ListOrdersQuery, type Money, type PaymentHardware, type PaymentKind, type PaymentMethodDescriptor, PaymentMethodKind, type PaymentOfflineMode, type PaymentRounding, type PaymentTipsMode, type PaymentTransport, type ProductCategory, type ProductPrice, type ProductTraits, type ReconcileFeed, type ReconcileFeedEntry, type ReconcileFetchEntry, type RegisterInfo, type RemoteIdEntry, type ReplicationAdapter, type ResolvedPrice, STOCK_LEVELS_LAST_PASS, type ServerCapabilities, SignInError, type SignInErrorCode, type SignInResult, type StockLevel, type StockReconcileAdapter, type StockStatus, type StoreOrder, type StoreOrderCharge, type StoreOrderLine, type StoreOrderPage, type StoreOrderPayment, type StoreOrderRefund, type StoreSettings, type StoreSettingsChoice, type StoreSettingsChoices, StoreSettingsError, type StoreSettingsErrorCode, type SyncContext, type SyncNotice, type TallyConnector, type TaxRounding, type TraitContext, type UpdateRequired, type VariantOptionGroup, type VariantSummary, cashierPermissions, classifyFailure, combinePullAdapters, compareIds, createReconcileFeed, currencySymbol, customerTraits, defaultPaymentMethods, errorKind, findVariantByCode, formatMoney, getProductStock, isCashierPermission, isRxdbRemoteVersionMismatch, knownWarnings, minorUnitDigits, moneyFromDecimalString, moneyFromMajor, moneyToMajor, neutralFailureClass, noResponse, parseInfoCapabilities, parseLineTax, parseTaxRounding, paymentMethodOf, resolveCapabilities, resolvePrice, resolvePriceRange, useConnector, useCustomerTraits, useProductStock, useProductTraits, useStockOverlaid, useStockOverlayAsOf, useTraitContext, withStockOverlay, index as woocommerceCoupons, index$1 as woocommerceTax };
package/dist/index.js CHANGED
@@ -127,6 +127,31 @@ function errorKind(error) {
127
127
  return (fixedBy === "till" || fixedBy === "store") && typeof code === "string" ? fixedBy : "transient";
128
128
  }
129
129
 
130
+ // src/connectivity.ts
131
+ var isAbort = (name) => name === "AbortError" || name === "TimeoutError";
132
+ function noResponse(error) {
133
+ if (isAbort(error?.name)) throw error;
134
+ throw Object.assign(new Error("No response from the store"), { name: "NoResponseError", code: "network", cause: error });
135
+ }
136
+ var NO_RESPONSE_CODES = /* @__PURE__ */ new Set(["ECONNREFUSED", "ECONNRESET", "ENOTFOUND", "EAI_AGAIN", "ENETUNREACH", "EHOSTUNREACH", "ENETDOWN"]);
137
+ function neutralFailureClass(error) {
138
+ if (typeof error !== "object" || error === null) return null;
139
+ const { name, code, status, cause } = error;
140
+ if (isAbort(name) || code === "timeout") return "degraded";
141
+ if (typeof status === "number" && status >= 500) return "degraded";
142
+ if (code === "network") return "offline";
143
+ const causeCode = cause?.code;
144
+ return NO_RESPONSE_CODES.has(code) || NO_RESPONSE_CODES.has(causeCode) ? "offline" : null;
145
+ }
146
+ function classifyFailure(connector, error) {
147
+ if (!connector?.classifyFailure) return neutralFailureClass(error);
148
+ try {
149
+ return connector.classifyFailure(error);
150
+ } catch {
151
+ return null;
152
+ }
153
+ }
154
+
130
155
  // src/store-settings.ts
131
156
  var StoreSettingsError = class extends Error {
132
157
  code;
@@ -1811,6 +1836,7 @@ export {
1811
1836
  SignInError,
1812
1837
  StoreSettingsError,
1813
1838
  cashierPermissions,
1839
+ classifyFailure,
1814
1840
  combinePullAdapters,
1815
1841
  compareIds,
1816
1842
  createReconcileFeed,
@@ -1829,6 +1855,8 @@ export {
1829
1855
  moneyFromDecimalString,
1830
1856
  moneyFromMajor,
1831
1857
  moneyToMajor,
1858
+ neutralFailureClass,
1859
+ noResponse,
1832
1860
  parseCommandResult,
1833
1861
  parseInfoCapabilities,
1834
1862
  parseLineTax,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tallyui/core",
3
- "version": "3.13.0",
3
+ "version": "3.15.0",
4
4
  "type": "module",
5
5
  "description": "Core interfaces, traits, and context providers for Tally UI",
6
6
  "main": "./dist/index.js",
@@ -0,0 +1,59 @@
1
+ import type { TallyConnector } from './types/connector';
2
+
3
+ /**
4
+ * How well a connector's store answers (v2 parity A6, unit 34). The same three states as WCPOS v2's
5
+ * `EngineConnectivity`: `degraded` means the device is online but the store keeps failing.
6
+ */
7
+ export type ConnectivityState = 'online' | 'offline' | 'degraded';
8
+
9
+ /**
10
+ * A store's deliberate refusal to sync until someone updates software. `fixedBy` as in `SyncNotice`: `'till'` when
11
+ * this app is older than the store accepts, `'store'` when the store's software is older than the app needs.
12
+ * `reason` is the connector's code for it; `software`, `minVersion` and `status` only when the refusal names them.
13
+ */
14
+ export type UpdateRequired = { reason: string; fixedBy: 'till' | 'store'; software?: string; minVersion?: string; status?: number };
15
+
16
+ /** What one failed request says: about connectivity, an update-required refusal, or nothing (`null`). */
17
+ export type FailureClass = 'offline' | 'degraded' | { updateRequired: UpdateRequired } | null;
18
+
19
+ const isAbort = (name: unknown) => name === 'AbortError' || name === 'TimeoutError';
20
+
21
+ /**
22
+ * For a connector's fetch call site alone: `fetch(url, init).catch(noResponse)`. A fetch that rejects got no response,
23
+ * but its `TypeError` looks like one our own code throws, so the call site tags it: rethrown as a `NoResponseError`
24
+ * with `code: 'network'` (offline to `neutralFailureClass`) and the original as `cause`. An abort or timeout is
25
+ * rethrown unchanged. Code that reads the response runs after the catch, so its errors are never tagged.
26
+ */
27
+ export function noResponse(error: unknown): never {
28
+ if (isAbort((error as { name?: unknown } | null)?.name)) throw error;
29
+ throw Object.assign(new Error('No response from the store'), { name: 'NoResponseError', code: 'network', cause: error });
30
+ }
31
+
32
+ /** Node's socket and DNS error codes for a request that got no response; Node's fetch puts them on `cause.code`. */
33
+ const NO_RESPONSE_CODES = new Set(['ECONNREFUSED', 'ECONNRESET', 'ENOTFOUND', 'EAI_AGAIN', 'ENETUNREACH', 'EHOSTUNREACH', 'ENETDOWN']);
34
+
35
+ /**
36
+ * The rule for a connector without `classifyFailure`: a timeout or a 5xx is `degraded`; a request that got no
37
+ * response (`code: 'network'`, as `noResponse` and `CustomerServiceError` set, or a no-response socket code on the
38
+ * error or its `cause`) is `offline`; anything else is `null`, a bare `TypeError` included, since our own code throws
39
+ * those too. It never answers update-required: only a connector knows its own refusal.
40
+ */
41
+ export function neutralFailureClass(error: unknown): FailureClass {
42
+ if (typeof error !== 'object' || error === null) return null;
43
+ const { name, code, status, cause } = error as { name?: unknown; code?: unknown; status?: unknown; cause?: unknown };
44
+ if (isAbort(name) || code === 'timeout') return 'degraded';
45
+ if (typeof status === 'number' && status >= 500) return 'degraded';
46
+ if (code === 'network') return 'offline';
47
+ const causeCode = (cause as { code?: unknown } | null | undefined)?.code;
48
+ return NO_RESPONSE_CODES.has(code as string) || NO_RESPONSE_CODES.has(causeCode as string) ? 'offline' : null;
49
+ }
50
+
51
+ /** The connector's own `classifyFailure` when it has one (its answer is final), else `neutralFailureClass`. A method that throws gives `null`. */
52
+ export function classifyFailure(connector: Pick<TallyConnector, 'classifyFailure'> | undefined, error: unknown): FailureClass {
53
+ if (!connector?.classifyFailure) return neutralFailureClass(error);
54
+ try {
55
+ return connector.classifyFailure(error);
56
+ } catch {
57
+ return null;
58
+ }
59
+ }
package/src/index.ts CHANGED
@@ -33,6 +33,7 @@ export { SignInError } from './sign-in';
33
33
  export { ConnectorUnauthorizedError } from './unauthorized';
34
34
  export { isRxdbRemoteVersionMismatch } from './rxdb-remote-version-mismatch';
35
35
  export { errorKind, type ErrorKind, type SyncNotice } from './sync-notice';
36
+ export { classifyFailure, neutralFailureClass, noResponse, type ConnectivityState, type FailureClass, type UpdateRequired } from './connectivity';
36
37
  export type { SignInErrorCode } from './sign-in';
37
38
  export { StoreSettingsError } from './store-settings';
38
39
  export { customerTraits, CustomerServiceError, type Customer, type CustomerInput, type CustomerAddress, type CustomerTaxId, type CustomerPatch } from './types/customers';
@@ -10,6 +10,7 @@ import type { ListOrdersQuery, StoreOrder, StoreOrderPage } from './orders';
10
10
  import type { PaymentMethodDescriptor } from './payment-methods';
11
11
  import type { RegisterInfo } from './registers';
12
12
  import type { Cashier } from './cashier';
13
+ import type { FailureClass } from '../connectivity';
13
14
 
14
15
  /**
15
16
  * Authentication configuration for a connector.
@@ -325,7 +326,11 @@ export interface TallyConnector {
325
326
  * the store. `undefined` when the connector has none of its own: the till offers `defaultPaymentMethods()`.
326
327
  */
327
328
  paymentMethods?: (context: SyncContext) => Promise<PaymentMethodDescriptor[]>;
328
- /** Customer search: online only; `undefined` when the connector has no customer support. */
329
+ /**
330
+ * Customer search: online only. An empty or whitespace query may list a first page of the store's customers
331
+ * (recent ones, or in the store's own picker order); a connector that cannot list them returns `[]`.
332
+ * `undefined` when the connector has no customer support.
333
+ */
329
334
  searchCustomers?: (context: SyncContext, query: string, options?: { limit?: number }) => Promise<Customer[]>;
330
335
  /** Customer creation: online only; `undefined` when the connector has no customer support. */
331
336
  createCustomer?: (context: SyncContext, input: CustomerInput) => Promise<Customer>;
@@ -369,4 +374,11 @@ export interface TallyConnector {
369
374
  * Permission names outside `CashierPermission` are dropped by `useCashier` (`cashierPermissions`).
370
375
  */
371
376
  cashier?: (context: SyncContext) => Promise<Cashier | null>;
377
+ /**
378
+ * Maps one of this connector's request failures (pull, push, reconcile, online calls) to a connectivity verdict or
379
+ * its own update-required refusal (v2 parity A6). Synchronous and pure. `null` when the failure says nothing about
380
+ * connectivity (a validation refusal). `undefined` (no method) uses `neutralFailureClass`, which a connector's own
381
+ * method may also call for the failures it does not map.
382
+ */
383
+ classifyFailure?: (error: unknown) => FailureClass;
372
384
  }