@tallyui/core 3.13.0 → 3.14.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,36 @@ 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
+ * The rule for a connector without `classifyFailure`: a timeout or a 5xx is `degraded`, a request that got no
719
+ * response (a fetch's `TypeError`, or a `network` code as `CustomerServiceError` has) is `offline`, anything else is
720
+ * `null`. It never answers update-required: only a connector knows its own refusal.
721
+ */
722
+ declare function neutralFailureClass(error: unknown): FailureClass;
723
+ /** The connector's own `classifyFailure` when it has one (its answer is final), else `neutralFailureClass`. A method that throws gives `null`. */
724
+ declare function classifyFailure(connector: Pick<TallyConnector, 'classifyFailure'> | undefined, error: unknown): FailureClass;
725
+
696
726
  /**
697
727
  * Authentication configuration for a connector.
698
728
  * Each API has wildly different auth — JWT, API keys, OAuth, etc.
@@ -940,7 +970,11 @@ interface TallyConnector {
940
970
  * the store. `undefined` when the connector has none of its own: the till offers `defaultPaymentMethods()`.
941
971
  */
942
972
  paymentMethods?: (context: SyncContext) => Promise<PaymentMethodDescriptor[]>;
943
- /** Customer search: online only; `undefined` when the connector has no customer support. */
973
+ /**
974
+ * Customer search: online only. An empty or whitespace query may list a first page of the store's customers
975
+ * (recent ones, or in the store's own picker order); a connector that cannot list them returns `[]`.
976
+ * `undefined` when the connector has no customer support.
977
+ */
944
978
  searchCustomers?: (context: SyncContext, query: string, options?: {
945
979
  limit?: number;
946
980
  }) => Promise<Customer[]>;
@@ -988,6 +1022,13 @@ interface TallyConnector {
988
1022
  * Permission names outside `CashierPermission` are dropped by `useCashier` (`cashierPermissions`).
989
1023
  */
990
1024
  cashier?: (context: SyncContext) => Promise<Cashier | null>;
1025
+ /**
1026
+ * Maps one of this connector's request failures (pull, push, reconcile, online calls) to a connectivity verdict or
1027
+ * its own update-required refusal (v2 parity A6). Synchronous and pure. `null` when the failure says nothing about
1028
+ * connectivity (a validation refusal). `undefined` (no method) uses `neutralFailureClass`, which a connector's own
1029
+ * method may also call for the failures it does not map.
1030
+ */
1031
+ classifyFailure?: (error: unknown) => FailureClass;
991
1032
  }
992
1033
 
993
1034
  /**
@@ -1854,4 +1895,4 @@ declare namespace index {
1854
1895
  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
1896
  }
1856
1897
 
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 };
1898
+ 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, 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,24 @@ function errorKind(error) {
127
127
  return (fixedBy === "till" || fixedBy === "store") && typeof code === "string" ? fixedBy : "transient";
128
128
  }
129
129
 
130
+ // src/connectivity.ts
131
+ function neutralFailureClass(error) {
132
+ if (typeof error !== "object" || error === null) return null;
133
+ const { name, code, status } = error;
134
+ if (name === "AbortError" || name === "TimeoutError" || code === "timeout") return "degraded";
135
+ if (typeof status === "number" && status >= 500) return "degraded";
136
+ if (name === "TypeError" || code === "network") return "offline";
137
+ return null;
138
+ }
139
+ function classifyFailure(connector, error) {
140
+ if (!connector?.classifyFailure) return neutralFailureClass(error);
141
+ try {
142
+ return connector.classifyFailure(error);
143
+ } catch {
144
+ return null;
145
+ }
146
+ }
147
+
130
148
  // src/store-settings.ts
131
149
  var StoreSettingsError = class extends Error {
132
150
  code;
@@ -1811,6 +1829,7 @@ export {
1811
1829
  SignInError,
1812
1830
  StoreSettingsError,
1813
1831
  cashierPermissions,
1832
+ classifyFailure,
1814
1833
  combinePullAdapters,
1815
1834
  compareIds,
1816
1835
  createReconcileFeed,
@@ -1829,6 +1848,7 @@ export {
1829
1848
  moneyFromDecimalString,
1830
1849
  moneyFromMajor,
1831
1850
  moneyToMajor,
1851
+ neutralFailureClass,
1832
1852
  parseCommandResult,
1833
1853
  parseInfoCapabilities,
1834
1854
  parseLineTax,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tallyui/core",
3
- "version": "3.13.0",
3
+ "version": "3.14.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,41 @@
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
+ /**
20
+ * The rule for a connector without `classifyFailure`: a timeout or a 5xx is `degraded`, a request that got no
21
+ * response (a fetch's `TypeError`, or a `network` code as `CustomerServiceError` has) is `offline`, anything else is
22
+ * `null`. It never answers update-required: only a connector knows its own refusal.
23
+ */
24
+ export function neutralFailureClass(error: unknown): FailureClass {
25
+ if (typeof error !== 'object' || error === null) return null;
26
+ const { name, code, status } = error as { name?: unknown; code?: unknown; status?: unknown };
27
+ if (name === 'AbortError' || name === 'TimeoutError' || code === 'timeout') return 'degraded';
28
+ if (typeof status === 'number' && status >= 500) return 'degraded';
29
+ if (name === 'TypeError' || code === 'network') return 'offline';
30
+ return null;
31
+ }
32
+
33
+ /** The connector's own `classifyFailure` when it has one (its answer is final), else `neutralFailureClass`. A method that throws gives `null`. */
34
+ export function classifyFailure(connector: Pick<TallyConnector, 'classifyFailure'> | undefined, error: unknown): FailureClass {
35
+ if (!connector?.classifyFailure) return neutralFailureClass(error);
36
+ try {
37
+ return connector.classifyFailure(error);
38
+ } catch {
39
+ return null;
40
+ }
41
+ }
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, 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
  }