@tallyui/connector-woocommerce 3.5.0 → 3.5.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.js CHANGED
@@ -720,6 +720,12 @@ function createWooCustomers(options) {
720
720
  // src/store-settings.ts
721
721
  import { ConnectorUnauthorizedError as ConnectorUnauthorizedError2, StoreSettingsError, minorUnitDigits, woocommerceTax } from "@tallyui/core";
722
722
  var WOO_ORDER_CREATE_VERSION = 5;
723
+ var WOO_BASE_ORDER_CREATE_VERSION = 3;
724
+ var WOO_V5_MIN_PLUGIN_VERSION = [1, 10, 20];
725
+ function atLeastVersion(value, min) {
726
+ const parts = typeof value === "string" ? /^(\d+)\.(\d+)\.(\d+)/.exec(value)?.slice(1).map(Number) : void 0;
727
+ return !!parts && (parts[0] > min[0] || parts[0] === min[0] && (parts[1] > min[1] || parts[1] === min[1] && parts[2] >= min[2]));
728
+ }
723
729
  async function wooStoreSettings(context) {
724
730
  try {
725
731
  const init = { method: "GET", headers: context.headers, signal: context.signal };
@@ -812,6 +818,7 @@ async function readWooCapabilities(context) {
812
818
  const stores = await response.json();
813
819
  if (!Array.isArray(stores) || !stores[0] || typeof stores[0] !== "object" || Array.isArray(stores[0])) return void 0;
814
820
  let multiplePayments = false;
821
+ let capabilities = [];
815
822
  try {
816
823
  const status = await fetch(`${context.baseUrl}/status`, {
817
824
  method: "GET",
@@ -823,16 +830,25 @@ async function readWooCapabilities(context) {
823
830
  }
824
831
  if (status.ok) {
825
832
  const body = await status.json();
826
- multiplePayments = Array.isArray(body?.capabilities) && body.capabilities.includes("order_payments_list");
833
+ capabilities = Array.isArray(body?.capabilities) ? body.capabilities : [];
834
+ multiplePayments = capabilities.includes("order_payments_list");
827
835
  }
828
836
  } catch (error) {
829
837
  if (error instanceof ConnectorUnauthorizedError2) throw error;
830
838
  }
839
+ let orderCreate = capabilities.includes("order_create_v5") || capabilities.includes("order_payments_list") ? WOO_ORDER_CREATE_VERSION : WOO_BASE_ORDER_CREATE_VERSION;
840
+ if (orderCreate === WOO_BASE_ORDER_CREATE_VERSION) {
841
+ try {
842
+ const response2 = await fetch(`${context.baseUrl}/site`, { method: "GET", headers: context.headers, signal: context.signal });
843
+ if (response2.ok && atLeastVersion((await response2.json())?.wcpos_version, WOO_V5_MIN_PLUGIN_VERSION)) orderCreate = WOO_ORDER_CREATE_VERSION;
844
+ } catch {
845
+ }
846
+ }
831
847
  return {
832
- orderCreate: WOO_ORDER_CREATE_VERSION,
848
+ orderCreate,
833
849
  taxRounding: { granularity: "woocommerce", roundAtSubtotal: stores[0].tax_round_at_subtotal === "yes" },
834
850
  multiplePayments,
835
- // WCPOS always takes a fee's, shipping line's and custom line's tax_status and tax_class (orders #146, #161); it has no /tally/v1/info.
851
+ // WCPOS v5 takes a fee's, shipping line's and custom line's tax_status and tax_class (orders #146, #161); it has no /tally/v1/info.
836
852
  lineTax: { none: true, classes: true }
837
853
  };
838
854
  } catch (error) {
@@ -842,7 +858,7 @@ async function readWooCapabilities(context) {
842
858
  }
843
859
 
844
860
  // package.json
845
- var version = "3.5.0";
861
+ var version = "3.5.2";
846
862
 
847
863
  // src/commands/transport.ts
848
864
  import { minorUnitDigits as minorUnitDigits2, moneyFromDecimalString, moneyFromMajor as moneyFromMajor2 } from "@tallyui/core";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tallyui/connector-woocommerce",
3
- "version": "3.5.0",
3
+ "version": "3.5.2",
4
4
  "type": "module",
5
5
  "description": "WooCommerce connector for Tally UI",
6
6
  "main": "./dist/index.js",
@@ -26,10 +26,10 @@
26
26
  "directory": "connectors/woocommerce"
27
27
  },
28
28
  "peerDependencies": {
29
- "@tallyui/core": "^3.5.0"
29
+ "@tallyui/core": "^3.5.2"
30
30
  },
31
31
  "devDependencies": {
32
- "@tallyui/database": "3.5.0",
32
+ "@tallyui/database": "3.5.2",
33
33
  "rxdb": "17.5.0"
34
34
  },
35
35
  "scripts": {
@@ -3,6 +3,15 @@ import type { ServerCapabilities, StoreSettings, SyncContext } from '@tallyui/co
3
3
 
4
4
  /** The highest order.create version the WooCommerce transport maps: v4's net discounts, and v5's fees, shipping and custom lines (WCPOS push/orders; orders #146, #161). */
5
5
  export const WOO_ORDER_CREATE_VERSION = 5;
6
+ // The order.create version a store gets without proof of v5.
7
+ const WOO_BASE_ORDER_CREATE_VERSION = 3;
8
+ // The oldest WCPOS release with a proven v5 push (orders #146, #147).
9
+ const WOO_V5_MIN_PLUGIN_VERSION = [1, 10, 20] as const;
10
+
11
+ function atLeastVersion(value: unknown, min: readonly [number, number, number]): boolean {
12
+ const parts = typeof value === 'string' ? /^(\d+)\.(\d+)\.(\d+)/.exec(value)?.slice(1).map(Number) : undefined;
13
+ return !!parts && (parts[0] > min[0] || (parts[0] === min[0] && (parts[1] > min[1] || (parts[1] === min[1] && parts[2] >= min[2]))));
14
+ }
6
15
 
7
16
  export async function wooStoreSettings(context: SyncContext): Promise<StoreSettings> {
8
17
  try {
@@ -100,6 +109,7 @@ export async function readWooCapabilities(context: SyncContext): Promise<ServerC
100
109
  const stores = await response.json();
101
110
  if (!Array.isArray(stores) || !stores[0] || typeof stores[0] !== 'object' || Array.isArray(stores[0])) return undefined;
102
111
  let multiplePayments = false;
112
+ let capabilities: unknown[] = [];
103
113
  try {
104
114
  const status = await fetch(`${context.baseUrl}/status`, {
105
115
  method: 'GET', headers: context.headers, signal: context.signal,
@@ -109,16 +119,24 @@ export async function readWooCapabilities(context: SyncContext): Promise<ServerC
109
119
  }
110
120
  if (status.ok) {
111
121
  const body = await status.json();
112
- multiplePayments = Array.isArray(body?.capabilities) && body.capabilities.includes('order_payments_list');
122
+ capabilities = Array.isArray(body?.capabilities) ? body.capabilities : [];
123
+ multiplePayments = capabilities.includes('order_payments_list');
113
124
  }
114
125
  } catch (error) {
115
126
  if (error instanceof ConnectorUnauthorizedError) throw error;
116
127
  }
128
+ let orderCreate = capabilities.includes('order_create_v5') || capabilities.includes('order_payments_list') ? WOO_ORDER_CREATE_VERSION : WOO_BASE_ORDER_CREATE_VERSION;
129
+ if (orderCreate === WOO_BASE_ORDER_CREATE_VERSION) {
130
+ try {
131
+ const response = await fetch(`${context.baseUrl}/site`, { method: 'GET', headers: context.headers, signal: context.signal });
132
+ if (response.ok && atLeastVersion((await response.json())?.wcpos_version, WOO_V5_MIN_PLUGIN_VERSION)) orderCreate = WOO_ORDER_CREATE_VERSION;
133
+ } catch {}
134
+ }
117
135
  return {
118
- orderCreate: WOO_ORDER_CREATE_VERSION,
136
+ orderCreate,
119
137
  taxRounding: { granularity: 'woocommerce', roundAtSubtotal: stores[0].tax_round_at_subtotal === 'yes' },
120
138
  multiplePayments,
121
- // WCPOS always takes a fee's, shipping line's and custom line's tax_status and tax_class (orders #146, #161); it has no /tally/v1/info.
139
+ // WCPOS v5 takes a fee's, shipping line's and custom line's tax_status and tax_class (orders #146, #161); it has no /tally/v1/info.
122
140
  lineTax: { none: true, classes: true },
123
141
  };
124
142
  } catch (error) {