basecradle 0.14.2 → 0.14.4

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: e2f24c012adffce3eb5bf812fd4fe41244e33a255f63a7b6c4c751e919d77740
4
- data.tar.gz: ba6c3c758aa25b0d744c8dcf5362cfa754de9e32f7a6fcdbdad5ed749afe643d
3
+ metadata.gz: 15369066a66a4115017b92fc2e32e53a046a227c90bc3d39ea34b5afdb1740b3
4
+ data.tar.gz: 718f27aa9d46d2b8bb126b2cc5edf721e958d11cb8f2557f5438c1d4ce82b369
5
5
  SHA512:
6
- metadata.gz: 53023dc5e3c3c2cfca97302f7c158859945e526649f986e90b598f73a83ed87ad6d3c5851c014c8302a01c4dbe56be90940f746a931b2103633deaf4595e0f58
7
- data.tar.gz: 3013c477c9c3e10c0a3a5a7accf7a462f45c006e1d2b204344cd8727201f6cae2056451595cce61509c33b7efdd4f5c78ebfc683990ed53013d631e679d3fe02
6
+ metadata.gz: b63763f3c1021e0cd6e989c04cd72c24730e1cc28967ebc985fe6b895afbb93f9bda2529a92c719631d25c8eb50b410fec0920ac33b39900743485e01e80fe35
7
+ data.tar.gz: 45c156098df90bcfbfd1886576568c1ec9787c94720c457272f90ad3f660bf2b1e375b2884e5894ba964fb64b37e9113e60d14a2d4d10cf8b90ed3bd6892e4cf
data/CHANGELOG.md CHANGED
@@ -9,6 +9,127 @@ 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.4] - 2026-11-17
13
+
14
+ A patch release with two behavior fixes, both about a credential. No verb is added or
15
+ removed, and no signature changes. It affects a caller whose token is one HTTP cannot
16
+ carry exactly as given: `Client.new` now raises `ArgumentError` before any request.
17
+ **Some such tokens used to authenticate, so a caller whose token can carry whitespace at
18
+ either end (a padded line in an env file, say) must pass it exactly as minted** (see
19
+ below). The `login` fix changes nothing for a caller who already passes a `max_retries`
20
+ of zero or more.
21
+
22
+ ### Fixed
23
+
24
+ - **A token HTTP cannot carry raises `ArgumentError` when the client is built, and the
25
+ error never shows it**
26
+ ([#304](https://github.com/basecradle/basecradle-ruby/pull/304),
27
+ [#301](https://github.com/basecradle/basecradle-ruby/issues/301)). A token follows the
28
+ same rule as an `idempotency_key` (0.14.3): printable ASCII, with spaces or tabs only
29
+ between characters. `BaseCradle::Client.new`, whether given the token or reading
30
+ `BASECRADLE_TOKEN`, raises `ArgumentError` for any other token, saying where the fault
31
+ is and never showing the token, not even the character at fault. The SDK never strips
32
+ or repairs a token. What a caller who passed such a token sees now:
33
+ - Whitespace at either end (`"bc_uat_… "`): until now, **the token was sent as given and
34
+ the request authenticated**, because a hop stripped the whitespace before the platform
35
+ read it. It now raises.
36
+ - A token made only of whitespace (`BASECRADLE_TOKEN=" "`): until now, a client was
37
+ built and every request failed. It now raises `ArgumentError`, not
38
+ `MissingTokenError`, which is still raised only for a missing or empty token.
39
+ - A trailing newline, as a token read from a file or an env file often keeps
40
+ (`"bc_uat_…\n"`): until now, the client was built and every request failed with
41
+ Net::HTTP's own `ArgumentError` ("header field value cannot include CR/LF"), which
42
+ named no argument. It now raises when the client is built, and the message says a
43
+ file or an env file often keeps the trailing newline.
44
+ - Any other control character, or a non-ASCII character: until now, the token was sent
45
+ as raw bytes. It now raises.
46
+ - A string in an encoding that is not ASCII-compatible (UTF-16, say): until now, every
47
+ request failed with an `Encoding::CompatibilityError`. It now raises `ArgumentError`
48
+ naming the encoding.
49
+
50
+ The Python SDK made the same change
51
+ ([basecradle-python#359](https://github.com/basecradle/basecradle-python/issues/359)).
52
+ - **`Client.login` with a negative `max_retries` raises before it mints a credential**
53
+ ([#305](https://github.com/basecradle/basecradle-ruby/pull/305)). `login` checked
54
+ `max_retries` only when it built the client, after `POST /session` had already minted a
55
+ token, so `login(max_retries: -1)` created a live credential the caller never received.
56
+ It still raises the same `ArgumentError`, but now before anything is sent, as the
57
+ Python SDK's `login` does.
58
+
59
+ ### Security
60
+
61
+ - **The daily dependency scan writes as this repository's own bot, and only as it**
62
+ ([#303](https://github.com/basecradle/basecradle-ruby/pull/303),
63
+ [#309](https://github.com/basecradle/basecradle-ruby/pull/309),
64
+ [basecradle#870](https://github.com/basecradle/basecradle/issues/870)). Its
65
+ `[SECURITY]` issues and their labels now come from `basecradle-ruby-ai[bot]`, not the
66
+ capital's App, and the scan reads only issues that bot wrote. Nothing in the gem itself
67
+ changes.
68
+
69
+ ## [0.14.3] - 2026-11-16
70
+
71
+ A patch release with one behavior fix. No verb is added or removed, and no signature
72
+ changes. It affects a caller whose `idempotency_key` is one HTTP cannot carry exactly as
73
+ given: that create now raises `ArgumentError` before anything is sent. **Some such keys
74
+ used to go through, so a caller whose keys can hold whitespace at either end, a control
75
+ character or a non-ASCII character must change how it makes them** (see below). It is
76
+ also the first release whose publish job fails if the gem goes out without its sigstore
77
+ attestation.
78
+
79
+ ### Fixed
80
+
81
+ - **An `idempotency_key` HTTP cannot carry raises `ArgumentError` before any request**
82
+ ([#299](https://github.com/basecradle/basecradle-ruby/pull/299),
83
+ [#295](https://github.com/basecradle/basecradle-ruby/issues/295)). Every SDK now shares
84
+ one meaning of a key. A blank key (`nil`, empty, or only ASCII whitespace) is still no
85
+ key. Any other key must be printable ASCII, with spaces or tabs only between
86
+ characters. A key that is not is the caller's error: `timeline.messages.create`,
87
+ `timeline.assets.create`, `timeline.tasks.create` and
88
+ `timeline.webhook_endpoints.create` raise `ArgumentError` naming `idempotency_key`,
89
+ saying what is wrong with it and that nothing was sent. The SDK never strips or
90
+ repairs a key. What a caller who passed such a key sees now:
91
+ - Whitespace at either end (`" key-1 "`): until now, **the key was sent as given**, and
92
+ the platform received and stored it without the whitespace, a different key from the
93
+ one you passed. It now raises.
94
+ - A line break, such as the trailing newline of a key read from a file or an
95
+ environment variable (`"key-1\n"`): until now, Net::HTTP's own `ArgumentError`
96
+ ("header field value cannot include CR/LF"), which named no argument. It now raises
97
+ the SDK's `ArgumentError`, which names `idempotency_key`.
98
+ - A key made only of NUL, or of NUL and whitespace (`"\0"`, `" \0 "`): until now,
99
+ Ruby's `strip` counted it as blank, so the create went out unkeyed and was never
100
+ retried. NUL is not whitespace, so it is now a key HTTP cannot carry, and it raises.
101
+ - Any other control character (NUL inside a key, `"\x01"` to `"\x1f"` except tab, and
102
+ DEL, `"\x7f"`) or a non-ASCII character (`"clé-1"`): **until now, the key was sent as
103
+ raw bytes and the create went through.** These keys now raise too. If yours can hold
104
+ one, change how you make keys: a UUID is ideal.
105
+
106
+ An asset upload checks its key before it opens the file, so a bad key opens nothing.
107
+ The Python SDK is making the same change
108
+ ([basecradle-python#351](https://github.com/basecradle/basecradle-python/issues/351)),
109
+ so once it ships the two SDKs agree on every key, a NUL-only key included.
110
+
111
+ ### Security
112
+
113
+ - **The publish job fails when a release goes out without its sigstore attestation**
114
+ ([#298](https://github.com/basecradle/basecradle-ruby/pull/298),
115
+ [#297](https://github.com/basecradle/basecradle-ruby/issues/297)). 0.14.2 is on RubyGems
116
+ with no attestation: signing failed, `rubygems/release-gem` pushed the gem unsigned, and
117
+ its step stayed green. A last step now asks RubyGems for the new version's attestations
118
+ and fails the job when there are none. A version can never be re-signed, so 0.14.2
119
+ stays unattested.
120
+ - **The signer no longer sees the publish job's bundle**
121
+ ([#296](https://github.com/basecradle/basecradle-ruby/pull/296)). That is what broke
122
+ 0.14.2's signing: the bundle was installed into the system gems, and the signer loaded
123
+ a `json` it cannot call. The bundle now installs into `vendor/bundle`, as it did for
124
+ 0.14.1.
125
+ - **Every action in the release workflow and the daily dependency scan is pinned to a
126
+ commit SHA, and neither release job restores a cache**
127
+ ([#294](https://github.com/basecradle/basecradle-ruby/pull/294), part of
128
+ [#286](https://github.com/basecradle/basecradle-ruby/issues/286)). 0.14.1 pinned only
129
+ the publish job. The rehearsal job is pinned too now, and no cache saved by another run
130
+ can reach the job that holds the push credential. `rubygems/release-gem` moves to
131
+ v1.4.2. The CI jobs still use version tags. Nothing in the gem itself changes.
132
+
12
133
  ## [0.14.2] - 2026-11-16
13
134
 
14
135
  A patch release with one behavior fix. No verb is added or removed, and no signature
@@ -794,6 +915,8 @@ the Python SDK's behavior in idiomatic Ruby. Zero runtime dependencies.
794
915
  - **Quality bars** — a README-as-tested-doc harness (every example runs against a mocked
795
916
  API) and a spec drift-guard (CI fails if the live API grows beyond the SDK).
796
917
 
918
+ [0.14.4]: https://github.com/basecradle/basecradle-ruby/releases/tag/v0.14.4
919
+ [0.14.3]: https://github.com/basecradle/basecradle-ruby/releases/tag/v0.14.3
797
920
  [0.14.2]: https://github.com/basecradle/basecradle-ruby/releases/tag/v0.14.2
798
921
  [0.14.1]: https://github.com/basecradle/basecradle-ruby/releases/tag/v0.14.1
799
922
  [0.14.0]: https://github.com/basecradle/basecradle-ruby/releases/tag/v0.14.0
data/README.md CHANGED
@@ -27,6 +27,11 @@ bc = BaseCradle::Client.new # reads BASECRADLE_TOKEN
27
27
  bc = BaseCradle::Client.new("bc_uat_...") # …or pass it explicitly
28
28
  ```
29
29
 
30
+ The token is sent exactly as given, so it must be one HTTP can carry. A token read from a
31
+ file or an env file often keeps its trailing newline, and a token with a control
32
+ character, a non-ASCII character, or whitespace at either end raises `ArgumentError` when
33
+ the client is built. The SDK never strips or repairs it, and the error never shows it.
34
+
30
35
  No token yet? Mint one with your basecradle.com credentials. `login` hands back a
31
36
  ready-to-use client — the new token is on `bc.token`:
32
37
 
@@ -254,7 +259,7 @@ the same way. What gives the folding up is converting away from the type: both
254
259
 
255
260
  ## Idempotent creates & safe retries
256
261
 
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 non-blank string works — an empty or whitespace-only key counts as no key) 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.
262
+ 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
263
 
259
264
  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
265
 
@@ -3,6 +3,7 @@
3
3
  require "json"
4
4
 
5
5
  require_relative "errors"
6
+ require_relative "header_value"
6
7
  require_relative "rendering"
7
8
 
8
9
  module BaseCradle
@@ -16,21 +17,53 @@ module BaseCradle
16
17
  data["uuid"] || data.fetch("content")["uuid"]
17
18
  end
18
19
 
20
+ # The whitespace a blank key is made of: ASCII's six (space, tab, LF, VT, FF, CR), as the
21
+ # one meaning every SDK shares names them (#295). NUL is not whitespace, though Ruby's
22
+ # +strip+ removes it: a key made of NUL is not blank, it is a key HTTP cannot carry.
23
+ IDEMPOTENCY_KEY_WHITESPACE = " \t\n\v\f\r"
24
+ private_constant :IDEMPOTENCY_KEY_WHITESPACE
25
+
19
26
  # A key the platform cannot deduplicate on is no key at all: +nil+, an empty string, or
20
- # a string of only whitespace — the platform reads the header with Rails' +presence+,
21
- # which takes a blank value for none. Both places that read a key (the header a create
22
- # sends, and whether a request may be retried) ask this one question (#288). +scrub+
23
- # keeps a key with invalid bytes a key, rather than raising out of +strip+.
27
+ # a string of only ASCII whitespace — the platform reads the header with Rails'
28
+ # +presence+, which takes a blank value for none. Both places that read a key (the
29
+ # header a create sends, and whether a request may be retried) ask this one question
30
+ # (#288). It reads bytes, so a key with invalid bytes is answered rather than raised on.
31
+ # A key that is not blank is not always one HTTP can carry; that is the second question,
32
+ # +unsendable_idempotency_key_reason+.
24
33
  def self.blank_idempotency_key?(key)
25
- key.to_s.scrub.strip.empty?
34
+ key.to_s.b.delete(IDEMPOTENCY_KEY_WHITESPACE).empty?
35
+ end
36
+
37
+ # Why HTTP cannot carry this key exactly as given, or +nil+ when it can (#295). A key is
38
+ # sent as given and never repaired, so it must be a header value no hop can change: the
39
+ # rule is +header_value_defect+, the one the token is held to as well. A key is not a
40
+ # secret, so the reason shows the character at fault.
41
+ def self.unsendable_idempotency_key_reason(key)
42
+ index, reason = header_value_defect(key)
43
+ return if reason.nil?
44
+ return reason if index.nil?
45
+
46
+ "#{key[index].inspect} at index #{index} #{reason}"
26
47
  end
27
48
 
28
49
  # The per-request headers carrying an optional idempotency key — +nil+ when no key was
29
50
  # given (so a create without a key sends no +Idempotency-Key+ header, and is never
30
- # auto-retried). A blank key is no key, the same as +nil+. Shared by the four
31
- # content-create methods.
51
+ # auto-retried). A blank key is no key, the same as +nil+. Any other key HTTP cannot
52
+ # carry exactly as given raises ArgumentError here, before any request is built: it is
53
+ # the caller's error, never stripped or repaired. A key that is not a String is read as
54
+ # its +to_s+, and that string is both the one checked and the one sent. Shared by the
55
+ # four content-create methods, so the header name and the check live in one place.
32
56
  def self.idempotency_headers(key)
33
- blank_idempotency_key?(key) ? nil : { "Idempotency-Key" => key }
57
+ return nil if blank_idempotency_key?(key)
58
+
59
+ key = key.to_s
60
+ reason = unsendable_idempotency_key_reason(key)
61
+ if reason
62
+ raise ArgumentError, "idempotency_key cannot be sent as an HTTP header: #{reason}. A key " \
63
+ "must be printable ASCII, with spaces or tabs only between characters. Nothing was sent."
64
+ end
65
+
66
+ { "Idempotency-Key" => key }
34
67
  end
35
68
 
36
69
  # A read-only, wire-exact view of one API JSON object.
@@ -7,6 +7,7 @@ require "uri"
7
7
  require_relative "contact_messages"
8
8
  require_relative "dashboard"
9
9
  require_relative "errors"
10
+ require_relative "header_value"
10
11
  require_relative "items"
11
12
  require_relative "rendering"
12
13
  require_relative "serialization"
@@ -76,15 +77,22 @@ module BaseCradle
76
77
  # off. When set above 0, only requests that are safe to re-send are retried: any +GET+
77
78
  # (reads change nothing) and any create carrying an +idempotency_key+ (the platform
78
79
  # dedupes keyed creates, so a resend can't duplicate the record). An unkeyed +POST+ is
79
- # never retried, whatever this is set to — and a blank key (empty, or only whitespace)
80
- # is no key. Retries back off exponentially, capped at RETRY_MAX_DELAY seconds.
80
+ # never retried, whatever this is set to — and a blank key (empty, or only ASCII
81
+ # whitespace) is no key. Retries back off exponentially, capped at RETRY_MAX_DELAY seconds.
82
+ #
83
+ # The token is sent exactly as given, so it must be one HTTP can carry: a token with a
84
+ # control character (the trailing newline of one read from a file or an env file), a
85
+ # non-ASCII character, or whitespace at either end raises ArgumentError here, before
86
+ # any request. The SDK never strips or repairs it, and the error never shows it.
81
87
  def initialize(token = nil, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT,
82
88
  max_retries: DEFAULT_MAX_RETRIES)
83
89
  resolved = token || ENV.fetch("BASECRADLE_TOKEN", nil)
84
90
  raise MissingTokenError, MISSING_TOKEN_MESSAGE if resolved.nil? || resolved.empty?
85
- raise ArgumentError, "max_retries must be >= 0" if max_retries.negative?
91
+ self.class.refuse_negative_max_retries(max_retries)
86
92
 
87
- @token = resolved
93
+ # The one string checked is the one sent: "Bearer #{@token}" interpolates it as is.
94
+ @token = resolved.to_s
95
+ refuse_unsendable_token(@token)
88
96
  @base_url = base_url
89
97
  @timeout = timeout
90
98
  @max_retries = max_retries
@@ -123,9 +131,14 @@ module BaseCradle
123
131
  # The minted token is on the returned client as +#token+ — save it; it is never
124
132
  # retrievable again. The credential itself is on +#session+ (so +bc.session.uuid+ is
125
133
  # what revokes it later), and +#start_here+ points at the Dashboard. +name+ is an
126
- # optional label to tell credentials apart later.
134
+ # optional label to tell credentials apart later. A negative +max_retries+ raises
135
+ # ArgumentError before anything is sent, so no credential is minted.
127
136
  def self.login(email_address:, password:, name: nil, base_url: DEFAULT_BASE_URL,
128
137
  timeout: DEFAULT_TIMEOUT, max_retries: DEFAULT_MAX_RETRIES)
138
+ # Before the mint, as the Python SDK's login does: a bad count refused only when the
139
+ # client is built would have minted a credential the caller never receives.
140
+ refuse_negative_max_retries(max_retries)
141
+
129
142
  payload = { "email_address" => email_address, "password" => password }
130
143
  payload["name"] = name unless name.nil?
131
144
 
@@ -227,6 +240,11 @@ module BaseCradle
227
240
  handle(deliver(method, path, json: json, params: params, form: form, headers: headers))
228
241
  end
229
242
 
243
+ # One check for +new+ and +login+, so a count +new+ refuses never reaches the mint.
244
+ def self.refuse_negative_max_retries(max_retries)
245
+ raise ArgumentError, "max_retries must be >= 0" if max_retries.negative?
246
+ end
247
+
230
248
  # The shared low-level send: returns the Net::HTTPResponse or raises APIConnectionError.
231
249
  def self.perform(uri, request, timeout)
232
250
  http = Net::HTTP.new(uri.host, uri.port)
@@ -291,6 +309,30 @@ module BaseCradle
291
309
  "than the object: model.to_h holds no client."
292
310
  end
293
311
 
312
+ # Refuse a token HTTP cannot carry exactly as given, when the client is built (#301).
313
+ # The idempotency key's rule (BaseCradle.header_value_defect), applied to the token: the
314
+ # caller's error, never stripped or repaired. Without it, a token read with its trailing
315
+ # newline built a client that failed every request with Net::HTTP's own ArgumentError,
316
+ # and every other such token was sent: a hop strips whitespace at either end, and the
317
+ # platform received the rest as given. The message says where the fault is and never
318
+ # shows the token, not even the character at fault.
319
+ def refuse_unsendable_token(token)
320
+ index, reason = BaseCradle.header_value_defect(token)
321
+ return if reason.nil?
322
+
323
+ where = index.nil? ? reason : "the character at index #{index} #{reason}"
324
+ # A token ending in CR or LF is the newline a file or an env file keeps (CRLF from
325
+ # Windows too); for any other fault, the token's source has to say. Read as bytes, so
326
+ # a token in an encoding that is not ASCII-compatible is answered rather than raised on.
327
+ hint = if token.b.end_with?("\n", "\r")
328
+ "A token read from a file or an env file often keeps its trailing newline."
329
+ else
330
+ "Check where the token was read from."
331
+ end
332
+ raise ArgumentError, "The token cannot be sent in an HTTP header: #{where}. It is not shown " \
333
+ "here, as it is a credential. #{hint} Pass it exactly as minted."
334
+ end
335
+
294
336
  # Record what the mint response said about the credential just issued. Private: only
295
337
  # +.login+ calls it, on a client it has just built.
296
338
  def minted(body)
@@ -324,7 +366,7 @@ module BaseCradle
324
366
  # A request is safe to auto-retry only when re-sending it can't create a duplicate: a
325
367
  # +GET+ (reads change nothing), or any request carrying an +Idempotency-Key+ (the
326
368
  # platform dedupes keyed creates). An unkeyed write is never retried, and a blank key
327
- # (empty or only whitespace) is no key: the platform cannot dedupe on it.
369
+ # (empty or only ASCII whitespace) is no key: the platform cannot dedupe on it.
328
370
  def retryable?(method, http_request)
329
371
  return true if method.to_s.upcase == "GET"
330
372
 
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BaseCradle
4
+ # What stops HTTP carrying +value+ exactly as given, or +nil+ when nothing does. It is the
5
+ # one rule for a value the SDK sends in a header as the caller gave it, never stripped or
6
+ # repaired: an idempotency key (#295) and the bearer token (#301) alike. The rule lives
7
+ # here, below the client and the resources, so both can ask it.
8
+ #
9
+ # The value must be printable ASCII (+!+ to +~+), with spaces or tabs allowed only between
10
+ # those characters. Net::HTTP refuses only CR and LF. It sends NUL, every other control
11
+ # character and non-ASCII bytes. A hop that receives whitespace at either end of a value
12
+ # strips it, so the platform would read a different value. The rule every SDK shares
13
+ # refuses all of them, not whatever one HTTP library tolerates. A string in an encoding
14
+ # that is not ASCII-compatible (UTF-16, say) is refused as a whole: its bytes are not the
15
+ # characters it holds.
16
+ #
17
+ # The answer is <tt>[index, reason]</tt>: the index of the character at fault, or +nil+
18
+ # where no one character is (whitespace at either end, an encoding). The character itself
19
+ # is never part of the answer, so a caller describing the token can say where the fault
20
+ # is without showing any of it.
21
+ def self.header_value_defect(value)
22
+ unless value.encoding.ascii_compatible?
23
+ return [ nil, "its encoding, #{value.encoding}, is not ASCII-compatible; pass an ASCII or UTF-8 string" ]
24
+ end
25
+
26
+ value.each_char.with_index do |char, index|
27
+ # ascii_only? first: an invalid byte is not ASCII, and +ord+ would raise on it.
28
+ return [ index, "is not ASCII" ] unless char.ascii_only?
29
+ return [ index, "is a control character" ] unless char == " " || char == "\t" || (0x21..0x7E).cover?(char.ord)
30
+ end
31
+ return unless value.start_with?(" ", "\t") || value.end_with?(" ", "\t")
32
+
33
+ [ nil, "it begins or ends with whitespace, which a header value cannot" ]
34
+ end
35
+ end
@@ -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.2"
4
+ VERSION = "0.14.4"
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.2
4
+ version: 0.14.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Drawk Kwast
@@ -25,6 +25,7 @@ files:
25
25
  - lib/basecradle/contact_messages.rb
26
26
  - lib/basecradle/dashboard.rb
27
27
  - lib/basecradle/errors.rb
28
+ - lib/basecradle/header_value.rb
28
29
  - lib/basecradle/headers.rb
29
30
  - lib/basecradle/items.rb
30
31
  - lib/basecradle/pagination.rb