@tallyui/connector-woocommerce 3.4.0 → 3.5.1

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
@@ -450,7 +450,8 @@ var wooProductTraits = {
450
450
  getVariantCount: (doc) => doc.type === "variable" ? doc.variations?.length ?? 0 : 1,
451
451
  getType: (doc) => doc.type ?? "simple",
452
452
  getBarcode: (doc) => wooProductBarcode(doc),
453
- getCategoryNames: (doc) => (doc.categories ?? []).map((cat) => cat.name).filter(Boolean)
453
+ getCategoryNames: (doc) => (doc.categories ?? []).map((cat) => cat.name).filter(Boolean),
454
+ getCategories: (doc) => (doc.categories ?? []).filter((cat) => cat.name).map((cat) => ({ id: cat.id != null ? String(cat.id) : cat.name, name: cat.name }))
454
455
  };
455
456
 
456
457
  // src/sync/products.ts
@@ -719,6 +720,12 @@ function createWooCustomers(options) {
719
720
  // src/store-settings.ts
720
721
  import { ConnectorUnauthorizedError as ConnectorUnauthorizedError2, StoreSettingsError, minorUnitDigits, woocommerceTax } from "@tallyui/core";
721
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
+ }
722
729
  async function wooStoreSettings(context) {
723
730
  try {
724
731
  const init = { method: "GET", headers: context.headers, signal: context.signal };
@@ -811,6 +818,7 @@ async function readWooCapabilities(context) {
811
818
  const stores = await response.json();
812
819
  if (!Array.isArray(stores) || !stores[0] || typeof stores[0] !== "object" || Array.isArray(stores[0])) return void 0;
813
820
  let multiplePayments = false;
821
+ let capabilities = [];
814
822
  try {
815
823
  const status = await fetch(`${context.baseUrl}/status`, {
816
824
  method: "GET",
@@ -822,16 +830,25 @@ async function readWooCapabilities(context) {
822
830
  }
823
831
  if (status.ok) {
824
832
  const body = await status.json();
825
- 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");
826
835
  }
827
836
  } catch (error) {
828
837
  if (error instanceof ConnectorUnauthorizedError2) throw error;
829
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
+ }
830
847
  return {
831
- orderCreate: WOO_ORDER_CREATE_VERSION,
848
+ orderCreate,
832
849
  taxRounding: { granularity: "woocommerce", roundAtSubtotal: stores[0].tax_round_at_subtotal === "yes" },
833
850
  multiplePayments,
834
- // 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.
835
852
  lineTax: { none: true, classes: true }
836
853
  };
837
854
  } catch (error) {
@@ -841,7 +858,7 @@ async function readWooCapabilities(context) {
841
858
  }
842
859
 
843
860
  // package.json
844
- var version = "3.4.0";
861
+ var version = "3.5.1";
845
862
 
846
863
  // src/commands/transport.ts
847
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.4.0",
3
+ "version": "3.5.1",
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.4.0"
29
+ "@tallyui/core": "^3.5.1"
30
30
  },
31
31
  "devDependencies": {
32
- "@tallyui/database": "3.4.0",
32
+ "@tallyui/database": "3.5.1",
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) {
@@ -107,4 +107,8 @@ export const wooProductTraits: ProductTraits = {
107
107
 
108
108
  getCategoryNames: (doc) =>
109
109
  (doc.categories ?? []).map((cat: any) => cat.name).filter(Boolean),
110
+
111
+ getCategories: (doc) =>
112
+ (doc.categories ?? []).filter((cat: any) => cat.name)
113
+ .map((cat: any) => ({ id: cat.id != null ? String(cat.id) : cat.name, name: cat.name })),
110
114
  };