@kizlo/woocommerce 0.14.0 → 0.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.js CHANGED
@@ -1383,6 +1383,10 @@ const CART_PROCEDURES = {
1383
1383
  //#endregion
1384
1384
  //#region src/checkout/error.ts
1385
1385
  const CheckoutConflictData = z$2.object({ cart: Cart.nullable() });
1386
+ const CheckoutTotalMismatchData = CheckoutConflictData.extend({
1387
+ expectedTotal: z$2.string().regex(/^[0-9]+$/).optional(),
1388
+ actualTotal: z$2.string().regex(/^[0-9]+$/).optional()
1389
+ });
1386
1390
  const GET_CHECKOUT_ERROR_MAP = defineErrorMap({ CHECKOUT_ORDER_NOT_FOUND: {
1387
1391
  status: 404,
1388
1392
  message: "No checkout order found."
@@ -1454,6 +1458,11 @@ const CONFIRM_CHECKOUT_ERROR_MAP = defineErrorMap({
1454
1458
  message: "The cart is empty.",
1455
1459
  data: CheckoutConflictData
1456
1460
  },
1461
+ CHECKOUT_TOTAL_MISMATCH: {
1462
+ status: 409,
1463
+ message: "The order total increased. Please review the updated total.",
1464
+ data: CheckoutTotalMismatchData
1465
+ },
1457
1466
  CHECKOUT_CART_INVALID: {
1458
1467
  status: 409,
1459
1468
  message: "An item in the cart is no longer valid.",
@@ -1613,6 +1622,7 @@ const ConfirmCheckoutInput = z$2.object({
1613
1622
  billingAddress: CartBillingAddressSubmission,
1614
1623
  shippingAddress: CartShippingAddressSubmission.optional(),
1615
1624
  paymentMethod: z$2.string(),
1625
+ expectedTotal: z$2.string().regex(/^[0-9]+$/).optional(),
1616
1626
  customerNote: z$2.string().optional(),
1617
1627
  createAccount: z$2.boolean().optional(),
1618
1628
  customerPassword: z$2.string().optional(),
@@ -1704,7 +1714,7 @@ function checkoutAdditionalFields(fields) {
1704
1714
 
1705
1715
  //#endregion
1706
1716
  //#region src/checkout/index.ts
1707
- const CHECKOUT_PROCEDURES = {
1717
+ const checkoutProcedures = {
1708
1718
  get: createProcedure({
1709
1719
  scope: "api",
1710
1720
  method: "GET",
@@ -1789,6 +1799,7 @@ const CHECKOUT_PROCEDURES = {
1789
1799
  shipping_address: input.body.shippingAddress ? serializeCheckoutShippingAddress(input.body.shippingAddress) : void 0,
1790
1800
  payment_method: gateway(input.body.paymentMethod),
1791
1801
  customer_note: input.body.customerNote,
1802
+ ...input.body.expectedTotal !== void 0 && { expected_total: input.body.expectedTotal },
1792
1803
  create_account: input.body.createAccount ?? false,
1793
1804
  customer_password: input.body.customerPassword,
1794
1805
  payment_data: input.body.paymentData,
@@ -1832,6 +1843,10 @@ const CHECKOUT_PROCEDURES = {
1832
1843
  message: response.error.message,
1833
1844
  data: conflict
1834
1845
  });
1846
+ case "woocommerce_rest_checkout_total_mismatch": throw errors.CHECKOUT_TOTAL_MISMATCH({
1847
+ message: response.error.message,
1848
+ data: totalMismatchData(response.error.data)
1849
+ });
1835
1850
  case "woocommerce_rest_coupon_reserve_failed": throw errors.CHECKOUT_COUPON_RESERVATION_FAILED({
1836
1851
  message: response.error.message,
1837
1852
  data: conflict
@@ -1918,6 +1933,22 @@ function conflictData(data) {
1918
1933
  function isRecord(value) {
1919
1934
  return typeof value === "object" && value !== null && !Array.isArray(value);
1920
1935
  }
1936
+ function totalMismatchData(data) {
1937
+ const { cart } = conflictData(data);
1938
+ const expectedTotal = minorUnitTotal(isRecord(data) ? data.expected_total : void 0);
1939
+ const actualTotal = minorUnitTotal(isRecord(data) ? data.actual_total : void 0);
1940
+ return {
1941
+ cart: Cart.safeParse(cart).success ? cart : null,
1942
+ ...expectedTotal !== void 0 && { expectedTotal },
1943
+ ...actualTotal !== void 0 && { actualTotal }
1944
+ };
1945
+ }
1946
+ function minorUnitTotal(value) {
1947
+ if (typeof value === "string" && /^[0-9]+$/.test(value)) return value;
1948
+ if (typeof value === "number" && Number.isSafeInteger(value) && value >= 0) return String(value);
1949
+ }
1950
+ /** Keep billing registry aliases consumer-resolved instead of emitting the build-time fallback. */
1951
+ const CHECKOUT_PROCEDURES = checkoutProcedures;
1921
1952
 
1922
1953
  //#endregion
1923
1954
  //#region src/schema.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kizlo/woocommerce",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "WooCommerce integration for Kizlo.",
@@ -60,6 +60,6 @@
60
60
  "zod": "^4.3.6"
61
61
  },
62
62
  "peerDependencies": {
63
- "kizlo": ">=0.16.0"
63
+ "kizlo": ">=0.26.1"
64
64
  }
65
65
  }