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 +4 -4
- data/CHANGELOG.md +14 -0
- data/lib/portage/ucp/client/transports/http.rb +14 -2
- data/lib/portage/ucp/client/version.rb +1 -1
- data/lib/portage/ucp/client.rb +26 -7
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d79c922ef93a60d8ae293284eb680bb4db51aba09be905ccdd61c0f756723ef5
|
|
4
|
+
data.tar.gz: f133375b2803b101f0c1bf5e9a70fa88cb6bc7c0126277e303eb909b4fff59aa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
29
|
-
|
|
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
|
|
data/lib/portage/ucp/client.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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.
|
|
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-
|
|
11
|
+
date: 2026-09-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|