portage-ucp-woocommerce 0.2.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 267329024b55bc6e5ff322972afa261a42de7461122cf797f180107bf8ea5b47
4
- data.tar.gz: 188c4863958b7764041ecc5b071ab56cfef7ac4e852fd662458994e6d106fbcb
3
+ metadata.gz: 9ff19515d56b687b4e547d3df69a3ba7dfac1def463c42ecd7e699dce78c53a1
4
+ data.tar.gz: 562c0efc3141a5a9cb43eea99b5a32b87eaac8901b4c0d339d939ccd2103916f
5
5
  SHA512:
6
- metadata.gz: f0cb179e1680c0f9b20ed6408829a98ff6d64587ec1cd364a8a151f54eb4416290116311102415968d76aad1f9adb18ad961a86d3941548e66c0b2d808ebe1fb
7
- data.tar.gz: 1f0e0f6b090ae7d370f9a2c282306ebeac965654cb381f741a7d9801136681a92c80f8935cfed8f20b26b2b122719657ecee8c977e1e81a6920680f0ea32dbbd
6
+ metadata.gz: b8cfc685abfdbec37d2495fd1c8b8f639cd824764812bcbaef907da670c37a4e30e0d181d90e6bcfcebc245148f8a7721bbe558ef86177b44c0b822950afecb8
7
+ data.tar.gz: ffd1c4cfcc7bfc55b11c4a942b9397c480316ee499f03d50578fd3077c05a72800a99bcee98d3b18a76c4d214d57675a3ef3998825e6059a8470ddbb322096ea
data/CHANGELOG.md CHANGED
@@ -4,6 +4,43 @@ All notable changes to this project are documented here. Format loosely follows
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.0.0/); this project is
5
5
  pre-1.0, so APIs may still shift between minor versions.
6
6
 
7
+ ## [Unreleased]
8
+
9
+ ## [0.2.2] - 2026-09-29
10
+
11
+ - Fixes a `NoMethodError` at launch: `exe/portage-ucp-woocommerce` handed
12
+ the server `Server.build(adapter:).start`, but `Server.build` returns a
13
+ plain `MCP::Server` (mcp gem 0.25.0), which has no `#start` — only
14
+ `MCP::Server::Transports::StdioTransport#open` reads stdio frames. The exe
15
+ now calls that directly, matching `portage-ucp-etsy`'s exe. Adds
16
+ `spec/portage/ucp/woocommerce/exe_spec.rb`, which runs the exe as a real
17
+ subprocess and pipes it a JSON-RPC `initialize` + `tools/list` handshake
18
+ to prove it actually starts and answers requests.
19
+
20
+ ## [0.2.1] - 2026-09-23
21
+
22
+ - `Mapper.checkout_links`'s `resume-checkout` link now carries the cart
23
+ token as a `?session=` query parameter, e.g.
24
+ `<site_url>/checkout/?session=<cart_token>`. Without it, 0.2.0's link
25
+ landed the shopper on a real checkout page with an *empty* cart: the
26
+ CLI's cart lives in the Store API's token-based session (the `Cart-Token`
27
+ header), while `/checkout/` reads the classic cookie-based session —
28
+ two different rows in `wp_woocommerce_sessions` unless bridged.
29
+ WooCommerce core already ships that bridge —
30
+ `WC_Session_Handler#init_session_from_request` accepts the same Cart-
31
+ Token JWT as `?session=` and clones the guest session's data into a
32
+ fresh cookie session before the page renders — so this is a one-line
33
+ fix, not new infrastructure. Confirmed live against the local Docker
34
+ WooCommerce install (`docs/plans/woocommerce-local-validation.md`'s
35
+ stack): `--auto-open`'s hand-off now opens a browser straight onto a
36
+ checkout page with the cart's actual contents, not an empty one.
37
+ - `Resolver`'s WooCommerce `billing_address` is hardened: malformed
38
+ `WOOCOMMERCE_BILLING_ADDRESS` JSON now raises a clear `ArgumentError`
39
+ (previously a raw, uncaught `JSON::ParserError` out of `portage buy`),
40
+ and when the env var is unset it falls back to the same `PORTAGE_SHIP_*`
41
+ env `portage buy` reads for shipping, mapped to the Store API's billing
42
+ field names, instead of leaving `billing_address` unset.
43
+
7
44
  ## [0.2.0] - 2026-09-22
8
45
 
9
46
  - `Mapper.checkout` builds a `resume-checkout` link at `<site_url>/checkout/`
data/README.md CHANGED
@@ -30,10 +30,11 @@ Run against a throwaway Docker WooCommerce (WP 7.1.1 + WooCommerce 11.1.1, TLS v
30
30
 
31
31
  **Fixed since this pass:**
32
32
 
33
- 1. **Hand-off now fires on WooCommerce.** `Mapper.checkout` builds a `resume-checkout` link at `<site_url>/checkout/` (WooCommerce's default slug — a store that's renamed its checkout page gets a dead link) for any non-completed checkout, so `Buy#checkout_url_of`/`#hand_off` have something to work with instead of bailing early on `links: []`.
33
+ 1. **Hand-off now fires on WooCommerce, and lands on a populated cart.** `Mapper.checkout` builds a `resume-checkout` link at `<site_url>/checkout/?session=<cart_token>` (WooCommerce's default checkout slug — a store that's renamed its checkout page gets a dead link) for any non-completed checkout, so `Buy#checkout_url_of`/`#hand_off` have something to work with instead of bailing early on `links: []`. The `?session=` query param matters: without it, the browser lands on `/checkout/` with an *empty* cart, because the CLI's cart lives in the Store API's token-based session while `/checkout/` reads the classic cookie-based one — two different rows in `wp_woocommerce_sessions`. WooCommerce core ships the bridge itself (`WC_Session_Handler#init_session_from_request` accepts the same Cart-Token JWT as `?session=` and clones that guest session into a fresh cookie session before the page renders), confirmed live: `--auto-open` now opens a browser straight onto a checkout page with the actual cart contents.
34
34
  2. **`Resolver` now threads `payment_method`/`billing_address` through to the adapter.** Its WooCommerce entry was missing both from its `env:` map, so `complete_checkout` failed with no gateway or address configured even when `WOOCOMMERCE_PAYMENT_METHOD`/`WOOCOMMERCE_BILLING_ADDRESS` were set.
35
35
  3. **`portage buy`'s `adapter_flow` no longer hides a live adapter's own error.** It rescued `LoadError` and `StandardError` identically, so a real, actionable failure (e.g. "no payment_method configured on this Adapter") surfaced as the same generic "no automated path" dead end as an adapter that isn't installed at all. A `StandardError` past that point now comes back as its own report, distinguishable by `source`.
36
36
  4. **`submit_checkout` now supplies `billing_address`.** `POST /wc/store/v1/checkout` 400s without one; there's no UCP `complete_checkout` parameter for it, so — same stopgap posture as `payment_method` — the adapter takes one fixed `billing_address` hash at construction time via `WOOCOMMERCE_BILLING_ADDRESS` (JSON, Store API field names), not per-checkout. Fine for a single-buyer-per-process, wrong the moment something needs a different address per checkout.
37
+ 5. **Hardened `Resolver`'s WooCommerce wiring.** Malformed `WOOCOMMERCE_BILLING_ADDRESS` JSON used to raise a raw `JSON::ParserError` straight out of `portage buy` (uncaught — `adapter_flow` only rescued `LoadError` around `build_adapter`); it now raises a clear `ArgumentError` naming the var, and `adapter_flow` reports it as an actionable "adapter misconfigured" outcome instead of crashing. `WOOCOMMERCE_BILLING_ADDRESS` also no longer has to be hand-built separately — when unset, `Resolver` derives it from the same `PORTAGE_SHIP_*` env `portage buy` already reads for shipping, mapped to the Store API's billing field names.
37
38
 
38
39
  **Remaining gaps, still unfixed:**
39
40
 
@@ -55,7 +56,7 @@ bundle install
55
56
 
56
57
  ## Setup
57
58
 
58
- You need a site URL, an Admin REST API consumer key/secret pair (wp-admin → WooCommerce → Settings → Advanced → REST API — grant Read/Write), your store's currency (the Admin product resource doesn't return one), and — only if you'll call `complete_checkout` — the WC payment gateway id you want to submit orders through and a `billing_address` the Store API's `/checkout` endpoint requires.
59
+ You need a site URL, an Admin REST API consumer key/secret pair (wp-admin → WooCommerce → Settings → Advanced → REST API — grant Read/Write), your store's currency (the Admin product resource doesn't return one), and — only if you'll call `complete_checkout` — the WC payment gateway id you want to submit orders through and a `billing_address` the Store API's `/checkout` endpoint requires. Via `Resolver` (i.e. `portage buy`), `billing_address` doesn't have to be its own JSON blob: set `WOOCOMMERCE_BILLING_ADDRESS` to override, or leave it unset and it's built from `PORTAGE_SHIP_*` (the same env `portage buy` reads for shipping) mapped to the Store API's field names.
59
60
 
60
61
  ```ruby
61
62
  require "portage/ucp/woocommerce"
@@ -26,7 +26,8 @@ client = Portage::Ucp::WooCommerce::Client.new(
26
26
  consumer_key: ENV.fetch("WOOCOMMERCE_CONSUMER_KEY"),
27
27
  consumer_secret: ENV.fetch("WOOCOMMERCE_CONSUMER_SECRET")
28
28
  )
29
- billing_address = ENV["WOOCOMMERCE_BILLING_ADDRESS"] && JSON.parse(ENV["WOOCOMMERCE_BILLING_ADDRESS"])
29
+ billing_json = ENV.fetch("WOOCOMMERCE_BILLING_ADDRESS", nil)
30
+ billing_address = billing_json && JSON.parse(billing_json)
30
31
  adapter = Portage::Ucp::WooCommerce::Adapter.new(
31
32
  client: client,
32
33
  site_url: ENV.fetch("WOOCOMMERCE_SITE_URL"),
@@ -35,4 +36,5 @@ adapter = Portage::Ucp::WooCommerce::Adapter.new(
35
36
  billing_address: billing_address
36
37
  )
37
38
 
38
- Portage::Ucp::Mcp::Server.build(adapter: adapter).start
39
+ server = Portage::Ucp::Mcp::Server.build(adapter: adapter)
40
+ MCP::Server::Transports::StdioTransport.new(server).open
@@ -181,7 +181,10 @@ module Portage
181
181
  # than a confirmed gateway-specific shape.
182
182
  def submit_checkout(checkout_id, payment_token)
183
183
  raise Portage::Ucp::WooCommerce::Error, "no payment_method configured on this Adapter" unless @payment_method
184
- raise Portage::Ucp::WooCommerce::Error, "no billing_address configured on this Adapter" unless @billing_address
184
+ unless @billing_address
185
+ raise Portage::Ucp::WooCommerce::Error,
186
+ "no billing_address configured on this Adapter"
187
+ end
185
188
 
186
189
  data = @client.store_post("/checkout", {
187
190
  payment_method: @payment_method,
@@ -1,3 +1,5 @@
1
+ require "cgi"
2
+
1
3
  module Portage
2
4
  module Ucp
3
5
  module WooCommerce
@@ -104,7 +106,7 @@ module Portage
104
106
  line_items: (node["items"] || []).map { |n| cart_line_item(n, currency) },
105
107
  currency: currency,
106
108
  totals: totals(node["totals"] || {}),
107
- links: checkout_links(status: status, site_url: site_url),
109
+ links: checkout_links(status: status, site_url: site_url, cart_token: id),
108
110
  order: order
109
111
  )
110
112
  end
@@ -113,10 +115,22 @@ module Portage
113
115
  # `/checkout/` is WooCommerce's *default* slug, not guaranteed (a
114
116
  # store can rename it). Good-enough-not-exhaustive, same posture as
115
117
  # this adapter's other documented caveats (see README).
116
- def checkout_links(status:, site_url:)
118
+ #
119
+ # The bare URL alone lands on an empty cart: the CLI's cart lives in
120
+ # the Store API's token-based session (`Cart-Token` header), while
121
+ # `/checkout/` reads the classic cookie-based session — two separate
122
+ # rows in `wp_woocommerce_sessions` unless bridged. WooCommerce core
123
+ # already ships the bridge: `WC_Session_Handler#init_session_from_request`
124
+ # accepts the same Cart-Token JWT as a `?session=` query param and
125
+ # clones that guest session's data into a fresh cookie session before
126
+ # the page renders. Confirmed live (2026-09-22): opening
127
+ # `<checkout>/?session=<token>` sets `woocommerce_items_in_cart` and
128
+ # the cart's contents actually appear on the rendered page.
129
+ def checkout_links(status:, site_url:, cart_token:)
117
130
  return [] if status == "completed"
118
131
 
119
- [Portage::Ucp::Link.new(type: "resume-checkout", url: "#{site_url}/checkout/")]
132
+ url = "#{site_url}/checkout/?session=#{CGI.escape(cart_token)}"
133
+ [Portage::Ucp::Link.new(type: "resume-checkout", url: url)]
120
134
  end
121
135
 
122
136
  def cart_line_item(node, _currency)
@@ -1,7 +1,7 @@
1
1
  module Portage
2
2
  module Ucp
3
3
  module WooCommerce
4
- VERSION = "0.2.0".freeze
4
+ VERSION = "0.2.2".freeze
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: portage-ucp-woocommerce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Whitbread
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-09-22 00:00:00.000000000 Z
11
+ date: 2026-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: portage-ucp