terminal-shop 3.9.3 → 3.10.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab7a1ea1c8de85523ff44623d41356998dd5bada3747e6efc20dd24dba4075e8
4
- data.tar.gz: 1388a54611762d55dc85565ceffb0e9449c2463c88025084f14862aa4ef3c2c4
3
+ metadata.gz: 274d5c5a57b55288c52218c98666b1daad06931cca073d7fd4a9d753e992312a
4
+ data.tar.gz: 61366798520a4343e75ad66d1901db5b63fa18bcbc368bd775810c40d255d3cc
5
5
  SHA512:
6
- metadata.gz: 9c4c251e363b1e053a7d37393ce44218ae6f40bc876f3e51a7192361fcfaa09ff04b9659e97da304791da91a00e7e77804fb54bd440a17f699e3699d3d63b567
7
- data.tar.gz: 8a325f17115e06bbe3a3ccf2751e03841a4cb7f310ce1fea7cf6b7f7746e160c4a23927e4b5465799e15b4796cd542d3aa28c4e7801e0f49fe21f3f91ca2d734
6
+ metadata.gz: 5e9ddb46fce75de0503c3a28013a499dd75110b9290cc8f7b14e13099d044752c90d1fcce912c7dd63630206f04bc8672780aa90ef793449677fe096556b5333
7
+ data.tar.gz: 3961f07513a416fda2af69ec824ce3f9393cbd9f7708e9a9d34751a6c2c77bf0fc9df93571bcfb1aa05fa3adbde05971fdda34b55c61ac13810c9557f52d53d4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.10.0 (2025-11-05)
4
+
5
+ Full Changelog: [v3.9.3...v3.10.0](https://github.com/terminaldotshop/terminal-sdk-ruby/compare/v3.9.3...v3.10.0)
6
+
7
+ ### Features
8
+
9
+ * handle thread interrupts in the core HTTP client ([6b9ed12](https://github.com/terminaldotshop/terminal-sdk-ruby/commit/6b9ed1271c78b568833e656bb17eaca1ae3b3a9c))
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * better thread safety via early initializing SSL store during HTTP client creation ([70b34dd](https://github.com/terminaldotshop/terminal-sdk-ruby/commit/70b34ddd2ad50a8a9fc573db002fe3c16a9039e3))
15
+
16
+
17
+ ### Chores
18
+
19
+ * bump dependency version and update sorbet types ([9262104](https://github.com/terminaldotshop/terminal-sdk-ruby/commit/92621040ccfecd21b5196766ec8b713af83605ba))
20
+
3
21
  ## 3.9.3 (2025-10-16)
4
22
 
5
23
  Full Changelog: [v3.9.2...v3.9.3](https://github.com/terminaldotshop/terminal-sdk-ruby/compare/v3.9.2...v3.9.3)
data/README.md CHANGED
@@ -17,7 +17,7 @@ To use this gem, install via Bundler by adding the following to your application
17
17
  <!-- x-release-please-start-version -->
18
18
 
19
19
  ```ruby
20
- gem "terminal-shop", "~> 3.9.3"
20
+ gem "terminal-shop", "~> 3.10.0"
21
21
  ```
22
22
 
23
23
  <!-- x-release-please-end -->
@@ -201,7 +201,8 @@ module TerminalShop
201
201
  self.class::PLATFORM_HEADERS,
202
202
  {
203
203
  "accept" => "application/json",
204
- "content-type" => "application/json"
204
+ "content-type" => "application/json",
205
+ "user-agent" => user_agent
205
206
  },
206
207
  headers
207
208
  )
@@ -219,6 +220,11 @@ module TerminalShop
219
220
  # @return [Hash{String=>String}]
220
221
  private def auth_headers = {}
221
222
 
223
+ # @api private
224
+ #
225
+ # @return [String]
226
+ private def user_agent = "#{self.class.name}/Ruby #{TerminalShop::VERSION}"
227
+
222
228
  # @api private
223
229
  #
224
230
  # @return [String]
@@ -16,10 +16,11 @@ module TerminalShop
16
16
  class << self
17
17
  # @api private
18
18
  #
19
+ # @param cert_store [OpenSSL::X509::Store]
19
20
  # @param url [URI::Generic]
20
21
  #
21
22
  # @return [Net::HTTP]
22
- def connect(url)
23
+ def connect(cert_store:, url:)
23
24
  port =
24
25
  case [url.port, url.scheme]
25
26
  in [Integer, _]
@@ -33,6 +34,8 @@ module TerminalShop
33
34
  Net::HTTP.new(url.host, port).tap do
34
35
  _1.use_ssl = %w[https wss].include?(url.scheme)
35
36
  _1.max_retries = 0
37
+
38
+ (_1.cert_store = cert_store) if _1.use_ssl?
36
39
  end
37
40
  end
38
41
 
@@ -102,7 +105,7 @@ module TerminalShop
102
105
  pool =
103
106
  @mutex.synchronize do
104
107
  @pools[origin] ||= ConnectionPool.new(size: @size) do
105
- self.class.connect(url)
108
+ self.class.connect(cert_store: @cert_store, url: url)
106
109
  end
107
110
  end
108
111
 
@@ -128,40 +131,48 @@ module TerminalShop
128
131
  url, deadline = request.fetch_values(:url, :deadline)
129
132
 
130
133
  req = nil
131
- eof = false
132
134
  finished = false
133
- closing = nil
134
135
 
135
136
  # rubocop:disable Metrics/BlockLength
136
137
  enum = Enumerator.new do |y|
137
138
  next if finished
138
139
 
139
140
  with_pool(url, deadline: deadline) do |conn|
140
- req, closing = self.class.build_request(request) do
141
- self.class.calibrate_socket_timeout(conn, deadline)
142
- end
143
-
144
- self.class.calibrate_socket_timeout(conn, deadline)
145
- unless conn.started?
146
- conn.keep_alive_timeout = self.class::KEEP_ALIVE_TIMEOUT
147
- conn.start
148
- end
141
+ eof = false
142
+ closing = nil
143
+ ::Thread.handle_interrupt(Object => :never) do
144
+ ::Thread.handle_interrupt(Object => :immediate) do
145
+ req, closing = self.class.build_request(request) do
146
+ self.class.calibrate_socket_timeout(conn, deadline)
147
+ end
149
148
 
150
- self.class.calibrate_socket_timeout(conn, deadline)
151
- conn.request(req) do |rsp|
152
- y << [req, rsp]
153
- break if finished
154
-
155
- rsp.read_body do |bytes|
156
- y << bytes.force_encoding(Encoding::BINARY)
157
- break if finished
149
+ self.class.calibrate_socket_timeout(conn, deadline)
150
+ unless conn.started?
151
+ conn.keep_alive_timeout = self.class::KEEP_ALIVE_TIMEOUT
152
+ conn.start
153
+ end
158
154
 
159
155
  self.class.calibrate_socket_timeout(conn, deadline)
156
+ conn.request(req) do |rsp|
157
+ y << [req, rsp]
158
+ break if finished
159
+
160
+ rsp.read_body do |bytes|
161
+ y << bytes.force_encoding(Encoding::BINARY)
162
+ break if finished
163
+
164
+ self.class.calibrate_socket_timeout(conn, deadline)
165
+ end
166
+ eof = true
167
+ end
168
+ end
169
+ ensure
170
+ begin
171
+ conn.finish if !eof && conn&.started?
172
+ ensure
173
+ closing&.call
160
174
  end
161
- eof = true
162
175
  end
163
- ensure
164
- conn.finish if !eof && conn&.started?
165
176
  end
166
177
  rescue Timeout::Error
167
178
  raise TerminalShop::Errors::APITimeoutError.new(url: url, request: req)
@@ -174,8 +185,6 @@ module TerminalShop
174
185
  body = TerminalShop::Internal::Util.fused_enum(enum, external: true) do
175
186
  finished = true
176
187
  loop { enum.next }
177
- ensure
178
- closing&.call
179
188
  end
180
189
  [Integer(response.code), response, body]
181
190
  end
@@ -186,6 +195,7 @@ module TerminalShop
186
195
  def initialize(size: self.class::DEFAULT_MAX_CONNECTIONS)
187
196
  @mutex = Mutex.new
188
197
  @size = size
198
+ @cert_store = OpenSSL::X509::Store.new.tap(&:set_default_paths)
189
199
  @pools = {}
190
200
  end
191
201
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TerminalShop
4
- VERSION = "3.9.3"
4
+ VERSION = "3.10.0"
5
5
  end
data/lib/terminal_shop.rb CHANGED
@@ -9,6 +9,7 @@ require "erb"
9
9
  require "etc"
10
10
  require "json"
11
11
  require "net/http"
12
+ require "openssl"
12
13
  require "pathname"
13
14
  require "rbconfig"
14
15
  require "securerandom"
data/manifest.yaml CHANGED
@@ -6,6 +6,7 @@ dependencies:
6
6
  - etc
7
7
  - json
8
8
  - net/http
9
+ - openssl
9
10
  - pathname
10
11
  - rbconfig
11
12
  - securerandom
@@ -180,6 +180,11 @@ module TerminalShop
180
180
  private def auth_headers
181
181
  end
182
182
 
183
+ # @api private
184
+ sig { returns(String) }
185
+ private def user_agent
186
+ end
187
+
183
188
  # @api private
184
189
  sig { returns(String) }
185
190
  private def generate_idempotency_key
@@ -26,8 +26,12 @@ module TerminalShop
26
26
 
27
27
  class << self
28
28
  # @api private
29
- sig { params(url: URI::Generic).returns(Net::HTTP) }
30
- def connect(url)
29
+ sig do
30
+ params(cert_store: OpenSSL::X509::Store, url: URI::Generic).returns(
31
+ Net::HTTP
32
+ )
33
+ end
34
+ def connect(cert_store:, url:)
31
35
  end
32
36
 
33
37
  # @api private
@@ -31,7 +31,7 @@ module TerminalShop
31
31
  #
32
32
  # Assumes superclass fields are totally defined before fields are accessed /
33
33
  # defined on subclasses.
34
- sig { params(child: T.self_type).void }
34
+ sig { params(child: TerminalShop::Internal::Type::BaseModel).void }
35
35
  def inherited(child)
36
36
  end
37
37
 
@@ -282,9 +282,13 @@ module TerminalShop
282
282
 
283
283
  # Create a new instance of a model.
284
284
  sig do
285
- params(data: T.any(T::Hash[Symbol, T.anything], T.self_type)).returns(
286
- T.attached_class
287
- )
285
+ params(
286
+ data:
287
+ T.any(
288
+ T::Hash[Symbol, T.anything],
289
+ TerminalShop::Internal::Type::BaseModel
290
+ )
291
+ ).returns(T.attached_class)
288
292
  end
289
293
  def self.new(data = {})
290
294
  end
@@ -87,6 +87,8 @@ module TerminalShop
87
87
 
88
88
  private def auth_headers: -> ::Hash[String, String]
89
89
 
90
+ private def user_agent: -> String
91
+
90
92
  private def generate_idempotency_key: -> String
91
93
 
92
94
  private def build_request: (
@@ -17,7 +17,10 @@ module TerminalShop
17
17
 
18
18
  DEFAULT_MAX_CONNECTIONS: Integer
19
19
 
20
- def self.connect: (URI::Generic url) -> top
20
+ def self.connect: (
21
+ cert_store: OpenSSL::X509::Store,
22
+ url: URI::Generic
23
+ ) -> top
21
24
 
22
25
  def self.calibrate_socket_timeout: (top conn, Float deadline) -> void
23
26
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terminal-shop
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.3
4
+ version: 3.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Terminal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-10-16 00:00:00.000000000 Z
11
+ date: 2025-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool