@tallyui/core 3.14.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
@@ -715,9 +715,17 @@ type FailureClass = 'offline' | 'degraded' | {
715
715
  updateRequired: UpdateRequired;
716
716
  } | null;
717
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.
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.
721
729
  */
722
730
  declare function neutralFailureClass(error: unknown): FailureClass;
723
731
  /** The connector's own `classifyFailure` when it has one (its answer is final), else `neutralFailureClass`. A method that throws gives `null`. */
@@ -1895,4 +1903,4 @@ declare namespace index {
1895
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 };
1896
1904
  }
1897
1905
 
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 };
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
@@ -128,13 +128,20 @@ function errorKind(error) {
128
128
  }
129
129
 
130
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"]);
131
137
  function neutralFailureClass(error) {
132
138
  if (typeof error !== "object" || error === null) return null;
133
- const { name, code, status } = error;
134
- if (name === "AbortError" || name === "TimeoutError" || code === "timeout") return "degraded";
139
+ const { name, code, status, cause } = error;
140
+ if (isAbort(name) || code === "timeout") return "degraded";
135
141
  if (typeof status === "number" && status >= 500) return "degraded";
136
- if (name === "TypeError" || code === "network") return "offline";
137
- return null;
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;
138
145
  }
139
146
  function classifyFailure(connector, error) {
140
147
  if (!connector?.classifyFailure) return neutralFailureClass(error);
@@ -1849,6 +1856,7 @@ export {
1849
1856
  moneyFromMajor,
1850
1857
  moneyToMajor,
1851
1858
  neutralFailureClass,
1859
+ noResponse,
1852
1860
  parseCommandResult,
1853
1861
  parseInfoCapabilities,
1854
1862
  parseLineTax,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tallyui/core",
3
- "version": "3.14.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",
@@ -16,18 +16,36 @@ export type UpdateRequired = { reason: string; fixedBy: 'till' | 'store'; softwa
16
16
  /** What one failed request says: about connectivity, an update-required refusal, or nothing (`null`). */
17
17
  export type FailureClass = 'offline' | 'degraded' | { updateRequired: UpdateRequired } | null;
18
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
+
19
35
  /**
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.
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.
23
40
  */
24
41
  export function neutralFailureClass(error: unknown): FailureClass {
25
42
  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';
43
+ const { name, code, status, cause } = error as { name?: unknown; code?: unknown; status?: unknown; cause?: unknown };
44
+ if (isAbort(name) || code === 'timeout') return 'degraded';
28
45
  if (typeof status === 'number' && status >= 500) return 'degraded';
29
- if (name === 'TypeError' || code === 'network') return 'offline';
30
- return null;
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;
31
49
  }
32
50
 
33
51
  /** The connector's own `classifyFailure` when it has one (its answer is final), else `neutralFailureClass`. A method that throws gives `null`. */
package/src/index.ts CHANGED
@@ -33,7 +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
+ export { classifyFailure, neutralFailureClass, noResponse, type ConnectivityState, type FailureClass, type UpdateRequired } from './connectivity';
37
37
  export type { SignInErrorCode } from './sign-in';
38
38
  export { StoreSettingsError } from './store-settings';
39
39
  export { customerTraits, CustomerServiceError, type Customer, type CustomerInput, type CustomerAddress, type CustomerTaxId, type CustomerPatch } from './types/customers';