basecradle 0.14.1 → 0.14.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: e24738f465459e941778b070a1ffc7efa17706bf50394d390eb0e79956ced97a
4
- data.tar.gz: a6ff325d3f9982308e095d8301f84be8c6684f74fb979529b1a054277da49004
3
+ metadata.gz: fd8cac9ca320e03ce203f1adc4867d3a9e87adb8512dc34401d4b98ed1a39cda
4
+ data.tar.gz: 8f5240bf68714298207b18bc4a85f71505d5f812d8b795647479ddc3e2bc1ace
5
5
  SHA512:
6
- metadata.gz: fcc928a5d0316b25def0963fcc20aec41e298d2a3a249f8fb45e8b0b56715496793a629fbdb895c84f24f322d231734c6a2b8824b73235fab547982e19755434
7
- data.tar.gz: cb8dcf49330a18e7e05851a62e802d35fd21d975ff15947b96c0ec909013b4087ff92ce9a7978f09b14e90e64eefb02b9d6785415054586c9e219eb3a1c4f5ce
6
+ metadata.gz: 20ddd64efd96b24332c343c08f2d6cede7f7b7bd4ea844eaa04e946a9ff2565534ede68f742d9cbeaef9b605c7400a36b5b44c2c9b822e1c085871dcf7d9fb49
7
+ data.tar.gz: d8da0222407c24563f545d40692745fd066670073ab0cb9ae531232f4adb67d1bec22103df90b531831a553f63bce3a6323f2780645ba46efa878b1fd6cecdf8
data/CHANGELOG.md CHANGED
@@ -9,6 +9,91 @@ section**. The newest heading is always the version `lib/basecradle/version.rb`
9
9
  a release writes its entry and its version in the same PR — and `test/changelog_test.rb`
10
10
  fails CI if the two ever disagree.
11
11
 
12
+ ## [0.14.3] - 2026-11-16
13
+
14
+ A patch release with one behavior fix. No verb is added or removed, and no signature
15
+ changes. It affects a caller whose `idempotency_key` is one HTTP cannot carry exactly as
16
+ given: that create now raises `ArgumentError` before anything is sent. **Some such keys
17
+ used to go through, so a caller whose keys can hold whitespace at either end, a control
18
+ character or a non-ASCII character must change how it makes them** (see below). It is
19
+ also the first release whose publish job fails if the gem goes out without its sigstore
20
+ attestation.
21
+
22
+ ### Fixed
23
+
24
+ - **An `idempotency_key` HTTP cannot carry raises `ArgumentError` before any request**
25
+ ([#299](https://github.com/basecradle/basecradle-ruby/pull/299),
26
+ [#295](https://github.com/basecradle/basecradle-ruby/issues/295)). Every SDK now shares
27
+ one meaning of a key. A blank key (`nil`, empty, or only ASCII whitespace) is still no
28
+ key. Any other key must be printable ASCII, with spaces or tabs only between
29
+ characters. A key that is not is the caller's error: `timeline.messages.create`,
30
+ `timeline.assets.create`, `timeline.tasks.create` and
31
+ `timeline.webhook_endpoints.create` raise `ArgumentError` naming `idempotency_key`,
32
+ saying what is wrong with it and that nothing was sent. The SDK never strips or
33
+ repairs a key. What a caller who passed such a key sees now:
34
+ - Whitespace at either end (`" key-1 "`): until now, **the key was sent as given**, and
35
+ the platform received and stored it without the whitespace, a different key from the
36
+ one you passed. It now raises.
37
+ - A line break, such as the trailing newline of a key read from a file or an
38
+ environment variable (`"key-1\n"`): until now, Net::HTTP's own `ArgumentError`
39
+ ("header field value cannot include CR/LF"), which named no argument. It now raises
40
+ the SDK's `ArgumentError`, which names `idempotency_key`.
41
+ - A key made only of NUL, or of NUL and whitespace (`"\0"`, `" \0 "`): until now,
42
+ Ruby's `strip` counted it as blank, so the create went out unkeyed and was never
43
+ retried. NUL is not whitespace, so it is now a key HTTP cannot carry, and it raises.
44
+ - Any other control character (NUL inside a key, `"\x01"` to `"\x1f"` except tab, and
45
+ DEL, `"\x7f"`) or a non-ASCII character (`"clé-1"`): **until now, the key was sent as
46
+ raw bytes and the create went through.** These keys now raise too. If yours can hold
47
+ one, change how you make keys: a UUID is ideal.
48
+
49
+ An asset upload checks its key before it opens the file, so a bad key opens nothing.
50
+ The Python SDK is making the same change
51
+ ([basecradle-python#351](https://github.com/basecradle/basecradle-python/issues/351)),
52
+ so once it ships the two SDKs agree on every key, a NUL-only key included.
53
+
54
+ ### Security
55
+
56
+ - **The publish job fails when a release goes out without its sigstore attestation**
57
+ ([#298](https://github.com/basecradle/basecradle-ruby/pull/298),
58
+ [#297](https://github.com/basecradle/basecradle-ruby/issues/297)). 0.14.2 is on RubyGems
59
+ with no attestation: signing failed, `rubygems/release-gem` pushed the gem unsigned, and
60
+ its step stayed green. A last step now asks RubyGems for the new version's attestations
61
+ and fails the job when there are none. A version can never be re-signed, so 0.14.2
62
+ stays unattested.
63
+ - **The signer no longer sees the publish job's bundle**
64
+ ([#296](https://github.com/basecradle/basecradle-ruby/pull/296)). That is what broke
65
+ 0.14.2's signing: the bundle was installed into the system gems, and the signer loaded
66
+ a `json` it cannot call. The bundle now installs into `vendor/bundle`, as it did for
67
+ 0.14.1.
68
+ - **Every action in the release workflow and the daily dependency scan is pinned to a
69
+ commit SHA, and neither release job restores a cache**
70
+ ([#294](https://github.com/basecradle/basecradle-ruby/pull/294), part of
71
+ [#286](https://github.com/basecradle/basecradle-ruby/issues/286)). 0.14.1 pinned only
72
+ the publish job. The rehearsal job is pinned too now, and no cache saved by another run
73
+ can reach the job that holds the push credential. `rubygems/release-gem` moves to
74
+ v1.4.2. The CI jobs still use version tags. Nothing in the gem itself changes.
75
+
76
+ ## [0.14.2] - 2026-11-16
77
+
78
+ A patch release with one behavior fix. No verb is added or removed, and no signature
79
+ changes. The one caller it affects passes an `idempotency_key` made only of whitespace:
80
+ that create is now sent without a key and is no longer auto-retried.
81
+
82
+ ### Fixed
83
+
84
+ - **A whitespace-only `idempotency_key` is no key**
85
+ ([#292](https://github.com/basecradle/basecradle-ruby/pull/292),
86
+ [#288](https://github.com/basecradle/basecradle-ruby/issues/288)). A key made only of
87
+ whitespace (`" "`, `"\t"`) used to go out as an `Idempotency-Key` header. A client built
88
+ with `max_retries:` would also re-send that create after a lost connection. The platform
89
+ reads a blank header as no key, so it could not deduplicate that create, and a retry
90
+ could post a duplicate. A key that is `nil`, empty, or only spaces, tabs and line breaks
91
+ now counts as no key on `timeline.messages.create`, `timeline.assets.create`,
92
+ `timeline.tasks.create` and `timeline.webhook_endpoints.create`: no header is sent, and
93
+ the create is never auto-retried. Use a fresh UUID per logical create. The Python SDK
94
+ is making the same change
95
+ ([basecradle-python#349](https://github.com/basecradle/basecradle-python/issues/349)).
96
+
12
97
  ## [0.14.1] - 2026-11-16
13
98
 
14
99
  A patch release. It carries one behavior fix brought over from the Python SDK and a
@@ -773,6 +858,8 @@ the Python SDK's behavior in idiomatic Ruby. Zero runtime dependencies.
773
858
  - **Quality bars** — a README-as-tested-doc harness (every example runs against a mocked
774
859
  API) and a spec drift-guard (CI fails if the live API grows beyond the SDK).
775
860
 
861
+ [0.14.3]: https://github.com/basecradle/basecradle-ruby/releases/tag/v0.14.3
862
+ [0.14.2]: https://github.com/basecradle/basecradle-ruby/releases/tag/v0.14.2
776
863
  [0.14.1]: https://github.com/basecradle/basecradle-ruby/releases/tag/v0.14.1
777
864
  [0.14.0]: https://github.com/basecradle/basecradle-ruby/releases/tag/v0.14.0
778
865
  [0.13.0]: https://github.com/basecradle/basecradle-ruby/releases/tag/v0.13.0
data/README.md CHANGED
@@ -254,7 +254,7 @@ the same way. What gives the folding up is converting away from the type: both
254
254
 
255
255
  ## Idempotent creates & safe retries
256
256
 
257
- A create can succeed on the server while its response is lost on the wire — retrying it blind would duplicate the record. Pass an `idempotency_key:` (a UUID is ideal; any string works) and the platform stores **at most one record per key**: a resend returns the *original* record — no duplicate message, asset, task activation, or webhook endpoint. All four create methods accept it.
257
+ A create can succeed on the server while its response is lost on the wire — retrying it blind would duplicate the record. Pass an `idempotency_key:` (a UUID is ideal) and the platform stores **at most one record per key**: a resend returns the *original* record — no duplicate message, asset, task activation, or webhook endpoint. All four create methods accept it. An empty or whitespace-only key counts as no key. Any other key is sent exactly as given, so it must be one HTTP can carry unchanged: printable ASCII, with spaces or tabs only between characters. A key with whitespace at either end, a control character (such as the trailing newline of a key read from a file), or a non-ASCII character raises `ArgumentError` before the request is built, and nothing is sent. The SDK never strips or repairs a key.
258
258
 
259
259
  Keys are scoped **per timeline and per author** for all four resources — yours never collide with another peer's, and the same key on two timelines creates two records.
260
260
 
@@ -16,12 +16,66 @@ module BaseCradle
16
16
  data["uuid"] || data.fetch("content")["uuid"]
17
17
  end
18
18
 
19
+ # The whitespace a blank key is made of: ASCII's six (space, tab, LF, VT, FF, CR), as the
20
+ # one meaning every SDK shares names them (#295). NUL is not whitespace, though Ruby's
21
+ # +strip+ removes it: a key made of NUL is not blank, it is a key HTTP cannot carry.
22
+ IDEMPOTENCY_KEY_WHITESPACE = " \t\n\v\f\r"
23
+ private_constant :IDEMPOTENCY_KEY_WHITESPACE
24
+
25
+ # A key the platform cannot deduplicate on is no key at all: +nil+, an empty string, or
26
+ # a string of only ASCII whitespace — the platform reads the header with Rails'
27
+ # +presence+, which takes a blank value for none. Both places that read a key (the
28
+ # header a create sends, and whether a request may be retried) ask this one question
29
+ # (#288). It reads bytes, so a key with invalid bytes is answered rather than raised on.
30
+ # A key that is not blank is not always one HTTP can carry; that is the second question,
31
+ # +unsendable_idempotency_key_reason+.
32
+ def self.blank_idempotency_key?(key)
33
+ key.to_s.b.delete(IDEMPOTENCY_KEY_WHITESPACE).empty?
34
+ end
35
+
36
+ # Why HTTP cannot carry this key exactly as given, or +nil+ when it can (#295). A key is
37
+ # sent as given and never repaired, so it must be a header value no hop can change:
38
+ # printable ASCII (+!+ to +~+), with spaces or tabs allowed only between those
39
+ # characters. Net::HTTP refuses only CR and LF; it sends NUL, every other control
40
+ # character and non-ASCII bytes, and a hop that receives whitespace at either end of a
41
+ # value strips it, so the platform would store a different key. The one meaning every
42
+ # SDK shares refuses all of them, not whatever one HTTP library tolerates. A string in
43
+ # an encoding that is not ASCII-compatible (UTF-16, say) is refused as a whole: its
44
+ # bytes are not the characters it holds.
45
+ def self.unsendable_idempotency_key_reason(key)
46
+ unless key.encoding.ascii_compatible?
47
+ return "its encoding, #{key.encoding}, is not ASCII-compatible; pass an ASCII or UTF-8 string"
48
+ end
49
+
50
+ key.each_char.with_index do |char, index|
51
+ return "#{char.inspect} at index #{index} is not ASCII" unless char.ascii_only?
52
+ unless char == " " || char == "\t" || (0x21..0x7E).cover?(char.ord)
53
+ return "#{char.inspect} at index #{index} is a control character"
54
+ end
55
+ end
56
+ return unless key.start_with?(" ", "\t") || key.end_with?(" ", "\t")
57
+
58
+ "it begins or ends with whitespace, which a header value cannot"
59
+ end
60
+
19
61
  # The per-request headers carrying an optional idempotency key — +nil+ when no key was
20
62
  # given (so a create without a key sends no +Idempotency-Key+ header, and is never
21
- # auto-retried). An empty string is no key, the same as +nil+. Shared by the four
22
- # content-create methods.
63
+ # auto-retried). A blank key is no key, the same as +nil+. Any other key HTTP cannot
64
+ # carry exactly as given raises ArgumentError here, before any request is built: it is
65
+ # the caller's error, never stripped or repaired. A key that is not a String is read as
66
+ # its +to_s+, and that string is both the one checked and the one sent. Shared by the
67
+ # four content-create methods, so the header name and the check live in one place.
23
68
  def self.idempotency_headers(key)
24
- key.to_s.empty? ? nil : { "Idempotency-Key" => key }
69
+ return nil if blank_idempotency_key?(key)
70
+
71
+ key = key.to_s
72
+ reason = unsendable_idempotency_key_reason(key)
73
+ if reason
74
+ raise ArgumentError, "idempotency_key cannot be sent as an HTTP header: #{reason}. A key " \
75
+ "must be printable ASCII, with spaces or tabs only between characters. Nothing was sent."
76
+ end
77
+
78
+ { "Idempotency-Key" => key }
25
79
  end
26
80
 
27
81
  # A read-only, wire-exact view of one API JSON object.
@@ -76,8 +76,8 @@ module BaseCradle
76
76
  # off. When set above 0, only requests that are safe to re-send are retried: any +GET+
77
77
  # (reads change nothing) and any create carrying an +idempotency_key+ (the platform
78
78
  # dedupes keyed creates, so a resend can't duplicate the record). An unkeyed +POST+ is
79
- # never retried, whatever this is set to. Retries back off exponentially, capped at
80
- # RETRY_MAX_DELAY seconds.
79
+ # never retried, whatever this is set to — and a blank key (empty, or only ASCII
80
+ # whitespace) is no key. Retries back off exponentially, capped at RETRY_MAX_DELAY seconds.
81
81
  def initialize(token = nil, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT,
82
82
  max_retries: DEFAULT_MAX_RETRIES)
83
83
  resolved = token || ENV.fetch("BASECRADLE_TOKEN", nil)
@@ -323,12 +323,12 @@ module BaseCradle
323
323
 
324
324
  # A request is safe to auto-retry only when re-sending it can't create a duplicate: a
325
325
  # +GET+ (reads change nothing), or any request carrying an +Idempotency-Key+ (the
326
- # platform dedupes keyed creates). An unkeyed write is never retried.
326
+ # platform dedupes keyed creates). An unkeyed write is never retried, and a blank key
327
+ # (empty or only ASCII whitespace) is no key: the platform cannot dedupe on it.
327
328
  def retryable?(method, http_request)
328
329
  return true if method.to_s.upcase == "GET"
329
330
 
330
- key = http_request["Idempotency-Key"]
331
- !(key.nil? || key.empty?)
331
+ !BaseCradle.blank_idempotency_key?(http_request["Idempotency-Key"])
332
332
  end
333
333
 
334
334
  # Build and send an authenticated request; returns the raw Net::HTTPResponse, whatever
@@ -180,6 +180,8 @@ module BaseCradle
180
180
  # platform stores at most one message per key, so a resend returns the original message
181
181
  # instead of posting a second one. See +BaseCradle::Client#max_retries+ for automatic
182
182
  # retries.
183
+ # A key HTTP cannot carry exactly as given raises ArgumentError before anything is
184
+ # sent (see BaseCradle.idempotency_headers).
183
185
  def create(body:, idempotency_key: nil)
184
186
  response = @client.request("POST", "/timelines/#{@timeline_uuid}/messages",
185
187
  json: { "message" => { "body" => body } },
@@ -207,13 +209,18 @@ module BaseCradle
207
209
  # +idempotency_key+ (optional, a UUID recommended) makes the upload safe to retry: the
208
210
  # platform stores at most one asset per key, so a resend returns the original asset
209
211
  # instead of uploading a second one. See +BaseCradle::Client#max_retries+.
212
+ # A key HTTP cannot carry exactly as given raises ArgumentError before anything is
213
+ # sent (see BaseCradle.idempotency_headers).
210
214
  def create(file:, description: nil, idempotency_key: nil)
215
+ # The key is checked before the file is opened: a bad key opens nothing, and a
216
+ # missing path cannot hide the key's error.
217
+ headers = BaseCradle.idempotency_headers(idempotency_key)
211
218
  filename, io, opened = open_upload(file)
212
219
  parts = [ [ "asset[file]", io, { filename: filename } ] ]
213
220
  parts << [ "asset[description]", description ] unless description.nil?
214
221
  begin
215
222
  response = @client.request("POST", "/timelines/#{@timeline_uuid}/assets", form: parts,
216
- headers: BaseCradle.idempotency_headers(idempotency_key))
223
+ headers: headers)
217
224
  ensure
218
225
  io.close if opened
219
226
  end
@@ -253,6 +260,8 @@ module BaseCradle
253
260
  # +idempotency_key+ (optional, a UUID recommended) makes the create safe to retry: the
254
261
  # platform stores at most one task per key — so a resend returns the original task and
255
262
  # never schedules a second activation. See +BaseCradle::Client#max_retries+.
263
+ # A key HTTP cannot carry exactly as given raises ArgumentError before anything is
264
+ # sent (see BaseCradle.idempotency_headers).
256
265
  def create(instructions:, activate_at:, idempotency_key: nil)
257
266
  activate_at = activate_at.iso8601 if activate_at.respond_to?(:iso8601)
258
267
  response = @client.request(
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BaseCradle
4
- VERSION = "0.14.1"
4
+ VERSION = "0.14.3"
5
5
  end
@@ -160,6 +160,8 @@ module BaseCradle
160
160
  # platform stores at most one endpoint per key — scoped per timeline and author, like
161
161
  # the other three creates — so a resend returns the original endpoint. See
162
162
  # +BaseCradle::Client#max_retries+.
163
+ # A key HTTP cannot carry exactly as given raises ArgumentError before anything is
164
+ # sent (see BaseCradle.idempotency_headers).
163
165
  def create(description:, idempotency_key: nil)
164
166
  response = @client.request("POST", "/timelines/#{@timeline_uuid}/webhook_endpoints",
165
167
  json: { "webhook_endpoint" => { "description" => description } },
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basecradle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.1
4
+ version: 0.14.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Drawk Kwast