portage-ucp-client 0.6.2 → 0.6.3

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: 89837fec9676ad52dd925e44ea86b12df99ae2f01ea56eccd4b877bbde7dfb7a
4
- data.tar.gz: 34e0f987ba86fb975eaed185950cc6c2690c3f177ae8eacbbdb718560be4fb5e
3
+ metadata.gz: d79c922ef93a60d8ae293284eb680bb4db51aba09be905ccdd61c0f756723ef5
4
+ data.tar.gz: f133375b2803b101f0c1bf5e9a70fa88cb6bc7c0126277e303eb909b4fff59aa
5
5
  SHA512:
6
- metadata.gz: 99581702b0ff34ed5a8fd680ffac05a05576823a6381bf312b63436107fb55977be865f7649be32827b3503b28465e3a862df9730058fe7ba4033179acd28505
7
- data.tar.gz: db7d14a2a8149ca8b526ab4fc0ee6f6f807cad84b83eb57229879659e75e5d13207f96faada575354da1981fb78bc2a1de72edc98c38405a81a5efc3ddcfa7e1
6
+ metadata.gz: a849432b3f19bfb560d54a7bf5d122dafefc55476a98d93708fed59b6f274362bcbff2c7f1799f833f2237e25991d06064b7bf0481a7c29faa7bd7e7a0e84b79
7
+ data.tar.gz: ee79d83b07f4da1678839b0006de2156112f22327c24e9750bf6c63bf6ef48971e46b9d1e73cc9f136ba11ffa3f4f3fb741b092c6dfb9001b6c69ff6228a492e
data/CHANGELOG.md CHANGED
@@ -4,6 +4,20 @@ 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
+ ## [0.6.3] - 2026-09-24
8
+
9
+ - `Client.connect(url:, proxy:)` and `Client.discover(url, proxy:)` take a
10
+ `proxy:` option (a URL string, Hash or `URI`), passed straight to
11
+ Faraday's own `proxy=` on the Streamable HTTP transport. Faraday already
12
+ reads the env proxy vars itself; this adds an explicit override.
13
+ - Every store-facing request now identifies itself: `Client::USER_AGENT`
14
+ (`"portage-ucp-client/<ver> (+https://github.com/tomtom87/Portage)"`) is
15
+ sent on the manifest GET and every UCP transport call, via
16
+ `Client.with_user_agent(headers)`. A caller's own `User-Agent` header
17
+ still wins (case-insensitive). `discover(url, headers: {})` now forwards
18
+ `headers` to both the manifest GET and the transport it builds.
19
+ `Transports::Http` merges the UA into its `MCP::Client::HTTP` headers.
20
+
7
21
  ## [0.6.2] - 2026-09-23
8
22
 
9
23
  - Fix: the loopback and stdio transports dropped `cart_id` from every call,
@@ -25,8 +25,20 @@ module Portage
25
25
  class Http
26
26
  include UcpWireShape
27
27
 
28
- def initialize(url:, headers: {})
29
- @client = ::MCP::Client.new(transport: ::MCP::Client::HTTP.new(url: url, headers: headers))
28
+ # @param proxy [String, Hash, URI, nil] docs/plans/proxy-support.md
29
+ # Phase 1's "lighter touch" for this gem: Faraday already reads
30
+ # the env proxy vars itself (`Faraday.ignore_env_proxy` is
31
+ # false) and accepts a `proxy:` connection option, so this just
32
+ # wires that option through rather than reimplementing Faraday's
33
+ # own proxy handling. Accepts anything
34
+ # `Faraday::Connection#proxy=`/`Faraday::ProxyOptions.from`
35
+ # accepts — a bare URL string is the common case.
36
+ def initialize(url:, headers: {}, proxy: nil)
37
+ @client = ::MCP::Client.new(
38
+ transport: ::MCP::Client::HTTP.new(url: url, headers: Client.with_user_agent(headers)) do |faraday|
39
+ faraday.proxy = proxy if proxy
40
+ end
41
+ )
30
42
  @client.connect
31
43
  end
32
44
 
@@ -1,7 +1,7 @@
1
1
  module Portage
2
2
  module Ucp
3
3
  module Client
4
- VERSION = "0.6.2".freeze
4
+ VERSION = "0.6.3".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -22,6 +22,11 @@ module Portage
22
22
  # Adapter directly, and place an order.
23
23
  module Client
24
24
  MANIFEST_PATH = "/.well-known/ucp".freeze
25
+ # Sent on every request this gem makes to a store (the manifest GET and
26
+ # each Streamable HTTP call) unless the caller's own headers name one,
27
+ # so a merchant reading its logs can tell a Portage agent from Ruby's
28
+ # or Faraday's default and find out what it is.
29
+ USER_AGENT = "portage-ucp-client/#{VERSION} (+https://github.com/tomtom87/Portage)".freeze
25
30
 
26
31
  # Wraps an already-built Adapter directly — no subprocess/socket. Still
27
32
  # runs the real merchant-side contract (authenticator, rate limiter,
@@ -35,11 +40,13 @@ module Portage
35
40
 
36
41
  # Connects over stdio (a subprocess) or Streamable HTTP (a URL) — pass
37
42
  # exactly one of `command:` or `url:`.
38
- def self.connect(command: nil, args: [], env: nil, url: nil, headers: {}, capabilities: nil)
43
+ # @param proxy [String, Hash, nil] forwarded to Transports::Http (a
44
+ # `url:` connection only) — see its own doc comment.
45
+ def self.connect(command: nil, args: [], env: nil, url: nil, headers: {}, capabilities: nil, proxy: nil)
39
46
  transport = if command
40
47
  Transports::Stdio.new(command: command, args: args, env: env)
41
48
  elsif url
42
- Transports::Http.new(url: url, headers: headers)
49
+ Transports::Http.new(url: url, headers: headers, proxy: proxy)
43
50
  else
44
51
  raise ArgumentError, "connect requires either command: or url:"
45
52
  end
@@ -51,14 +58,19 @@ module Portage
51
58
  # Portage::Ucp::Manifest#services — the core-gem fix this client
52
59
  # depends on to know where to connect).
53
60
  # @return [Session] scoped to the manifest's advertised capabilities.
54
- def self.discover(url)
55
- manifest = fetch_manifest(url)
56
- connect(url: mcp_endpoint(manifest), capabilities: capability_names(manifest))
61
+ # @param headers [Hash{String => String}] sent with the manifest GET
62
+ # and every call after it — e.g. a "User-Agent" naming the app
63
+ # built on this gem.
64
+ # @param proxy [String, Hash, nil] forwarded to the Streamable HTTP
65
+ # connection this discovers into — see Transports::Http.
66
+ def self.discover(url, headers: {}, proxy: nil)
67
+ manifest = fetch_manifest(url, headers)
68
+ connect(url: mcp_endpoint(manifest), headers: headers, capabilities: capability_names(manifest), proxy: proxy)
57
69
  end
58
70
 
59
- def self.fetch_manifest(url)
71
+ def self.fetch_manifest(url, headers = {})
60
72
  uri = URI.parse("#{url.to_s.sub(%r{/\z}, '')}#{MANIFEST_PATH}")
61
- response = Net::HTTP.get_response(uri)
73
+ response = Net::HTTP.get_response(uri, with_user_agent(headers))
62
74
  raise DiscoveryError, "GET #{uri} returned #{response.code}" unless response.is_a?(Net::HTTPSuccess)
63
75
 
64
76
  JSON.parse(response.body)
@@ -71,6 +83,13 @@ module Portage
71
83
  end
72
84
  private_class_method :fetch_manifest
73
85
 
86
+ # USER_AGENT unless `headers` already names one, in any case.
87
+ def self.with_user_agent(headers)
88
+ return headers if headers.keys.any? { |name| name.to_s.casecmp?("user-agent") }
89
+
90
+ { "User-Agent" => USER_AGENT }.merge(headers)
91
+ end
92
+
74
93
  # Real UCP manifests (confirmed live on Casper, Allbirds, Glossier, and
75
94
  # 34+ other Shopify UCP rollouts as of "2026-08-25") nest everything one
76
95
  # level deeper under a "ucp" key. This gem's own server side
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: portage-ucp-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Whitbread
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-09-23 00:00:00.000000000 Z
11
+ date: 2026-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday