calmlens 0.43.0 → 0.44.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 +4 -4
- data/lib/calmlens/internal.rb +12 -3
- data/lib/calmlens/request_options.rb +3 -3
- data/lib/calmlens/server_client.rb +4 -4
- data/lib/calmlens/session.rb +8 -8
- data/lib/calmlens/testing/fake_api.rb +3 -2
- data/lib/calmlens/version.rb +1 -1
- data/sig/calmlens.rbs +2 -2
- 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: 5dfc1d65ca0214bbf29c8c544d7e11baa2c4a36448e0c17cf7cebbc0bdba64f7
|
|
4
|
+
data.tar.gz: 679e4e7fa32c9688d0ca78b6199422c12fac33c6b562aad988b1cba6fef4db3e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9dba7d1cff246e8455846d8c20b008522aff4f1ed5e68d22ed8c962434421f34835a61405905a684ee1f0ff67e5f6bb0d23de5b2cefc921dfc6f3ee265f056ed
|
|
7
|
+
data.tar.gz: 2144ff0e99a7dabddcea9c5ec61af4e4a9f573d39e50cab6c93eceb6e5ad27c2282e47d3f305a5baec2b9aa24143075e5447c4a5806ef9e511154390078f0fc1
|
data/lib/calmlens/internal.rb
CHANGED
|
@@ -7,9 +7,8 @@ module CalmLens
|
|
|
7
7
|
# Option conversion, identifier encoding and argument checks shared by the resources.
|
|
8
8
|
# @api private
|
|
9
9
|
module Internal
|
|
10
|
-
# A key the API
|
|
11
|
-
|
|
12
|
-
IDEMPOTENCY_KEY = /\A[^\r\n\0]+\z/
|
|
10
|
+
# A key the API accepts once HTTP has trimmed spaces and tabs at either end (`check_idempotency_key`).
|
|
11
|
+
IDEMPOTENCY_KEY = /\A[\x20-\x7e]{1,255}\z/n
|
|
13
12
|
HEADER_VALUE = /\A[^\r\n\0]*\z/
|
|
14
13
|
# The CDN resources that take no lens or transform: the exact upload, the adaptive stream, the embed page,
|
|
15
14
|
# the placeholder and the display info.
|
|
@@ -32,6 +31,16 @@ module CalmLens
|
|
|
32
31
|
InvalidArgumentError.new(code, message)
|
|
33
32
|
end
|
|
34
33
|
|
|
34
|
+
# Refuses, before sending, a key the API would refuse: it takes 1 to 255 printable ASCII
|
|
35
|
+
# characters once HTTP has trimmed spaces and tabs at either end. The error has the API's code,
|
|
36
|
+
# `idempotency/invalid-key`.
|
|
37
|
+
def check_idempotency_key(key)
|
|
38
|
+
return key if key.b.gsub(/\A[ \t]+|[ \t]+\z/n, '').match?(IDEMPOTENCY_KEY)
|
|
39
|
+
|
|
40
|
+
raise invalid('An idempotency key must be 1 to 255 printable ASCII characters, such as a UUID.',
|
|
41
|
+
ErrorCodes::IDEMPOTENCY_INVALID_KEY)
|
|
42
|
+
end
|
|
43
|
+
|
|
35
44
|
# The request options of a request the API holds for `wait` seconds, 1 to
|
|
36
45
|
# {Assets::MAX_DECISION_WAIT}: its timeout outlasts the wait by {Assets::HELD_RESPONSE_TIMEOUT_MARGIN}
|
|
37
46
|
# seconds, whatever the client's `timeout`.
|
|
@@ -18,9 +18,9 @@ module CalmLens
|
|
|
18
18
|
|
|
19
19
|
def check_request_options(request)
|
|
20
20
|
key = request[:idempotency_key]
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
raise invalid('idempotency_key must be a String') unless key.nil? || key.is_a?(String)
|
|
22
|
+
|
|
23
|
+
check_idempotency_key(key) unless key.nil?
|
|
24
24
|
|
|
25
25
|
%i[timeout open_timeout upload_timeout].each do |name|
|
|
26
26
|
next if request[name].nil? || positive?(request[name])
|
|
@@ -92,10 +92,10 @@ module CalmLens
|
|
|
92
92
|
# @param log_level [String, nil] `info` (each attempt's outcome) or `debug` (also each attempt as
|
|
93
93
|
# it starts); `CALMLENS_LOG` by default, else `info` when a logger is given.
|
|
94
94
|
# @param on_request [#call, nil] called after each attempt with
|
|
95
|
-
# `{operation:, method:, path:, attempt:,
|
|
96
|
-
# server_timing:, client_overhead_ms:}
|
|
97
|
-
# (nil for {#request}), `
|
|
98
|
-
# `error_code` the attempt's error, `
|
|
95
|
+
# `{operation:, method:, path:, attempt:, delay_ms:, status:, request_id:, error_code:, duration_ms:,
|
|
96
|
+
# server_timing:, client_overhead_ms:}`, every duration in milliseconds: `operation` is the method, such as
|
|
97
|
+
# `assets.retrieve` (nil for {#request}), `delay_ms` the wait before the next attempt (nil when there is none),
|
|
98
|
+
# `error_code` the attempt's error, `duration_ms` how long it took, `server_timing` how long CalmLens
|
|
99
99
|
# spent on it (a {ServerTiming} from the `Server-Timing` header; nil when no response arrived,
|
|
100
100
|
# the header was missing or the client is a mock), `client_overhead_ms` the milliseconds spent
|
|
101
101
|
# outside CalmLens (network, TLS, sending the body, this machine; nil without `server_timing`),
|
data/lib/calmlens/session.rb
CHANGED
|
@@ -107,10 +107,10 @@ module CalmLens
|
|
|
107
107
|
elsif raw
|
|
108
108
|
headers['Transfer-Encoding'] = 'chunked'
|
|
109
109
|
end
|
|
110
|
-
|
|
110
|
+
key = request_options[:idempotency_key] || (SecureRandom.uuid if idempotent)
|
|
111
|
+
headers['Idempotency-Key'] = Internal.check_idempotency_key(key) if key
|
|
111
112
|
limit = request_options.fetch(:max_response_bytes, @max_response_bytes)
|
|
112
113
|
deadline = request_options.fetch(:upload_timeout, @upload_timeout) if upload
|
|
113
|
-
key = headers['Idempotency-Key']
|
|
114
114
|
execute(method, url, headers, raw, request_options, deadline: deadline) { |response| parse(method, response, limit, key, any_body:) }
|
|
115
115
|
end
|
|
116
116
|
|
|
@@ -308,16 +308,16 @@ module CalmLens
|
|
|
308
308
|
# Reports one attempt to the `on_request` hook and the logger, never the API key, bodies or a
|
|
309
309
|
# CDN URL, which may be signed, and gives `error` the attempt's timing.
|
|
310
310
|
def observe(request, context, delay, error)
|
|
311
|
-
|
|
311
|
+
duration_ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - context[:started]) * 1000).round(3)
|
|
312
312
|
timing = ServerTiming.parse(context[:server_timing]) unless error&.local?
|
|
313
|
-
overhead = ServerTiming.client_overhead_ms(
|
|
313
|
+
overhead = ServerTiming.client_overhead_ms(duration_ms, timing)
|
|
314
314
|
error&.record_timing(timing, overhead)
|
|
315
315
|
return unless @on_request || @logger
|
|
316
316
|
|
|
317
|
-
event = { operation: Thread.current[:calmlens_operation], method: request.method,
|
|
318
|
-
path: loggable_path(request.url, context[:authenticate]), attempt: context[:attempt] + 1,
|
|
317
|
+
event = { operation: Thread.current[:calmlens_operation], method: request.method, delay_ms: delay && (delay * 1000).round,
|
|
318
|
+
path: loggable_path(request.url, context[:authenticate]), attempt: context[:attempt] + 1,
|
|
319
319
|
status: context[:status] || error&.status, request_id: context[:request_id] || error&.request_id,
|
|
320
|
-
error_code: error&.code,
|
|
320
|
+
error_code: error&.code, duration_ms: duration_ms, server_timing: timing, client_overhead_ms: overhead }
|
|
321
321
|
@on_request&.call(event)
|
|
322
322
|
log(:info) do
|
|
323
323
|
outcome = if delay
|
|
@@ -326,7 +326,7 @@ module CalmLens
|
|
|
326
326
|
(error ? "failed with #{error.code}" : 'done')
|
|
327
327
|
end
|
|
328
328
|
"calmlens: #{event[:operation] || request.method} #{event[:method]} #{event[:path] || '[cdn]'} " \
|
|
329
|
-
"status=#{event[:status].inspect} attempt=#{event[:attempt]} duration=#{event[:
|
|
329
|
+
"status=#{event[:status].inspect} attempt=#{event[:attempt]} duration=#{event[:duration_ms].round}ms " \
|
|
330
330
|
"#{timing&.summary(overhead)}request_id=#{event[:request_id].inspect} #{outcome}"
|
|
331
331
|
end
|
|
332
332
|
end
|
|
@@ -2321,8 +2321,9 @@ module CalmLens
|
|
|
2321
2321
|
grant, item = resolve_asset(raw_segments[2])
|
|
2322
2322
|
return grant if grant.is_a?(Response)
|
|
2323
2323
|
return asset_not_found unless item && RESOURCES.include?(resource)
|
|
2324
|
-
# Like the CDN, a grant works only while its key may share the asset's folder.
|
|
2325
|
-
|
|
2324
|
+
# Like the CDN, a grant works only while its key may share the asset's folder. The mock's
|
|
2325
|
+
# default key has no grants and may share every asset, as a server integration's key can.
|
|
2326
|
+
if grant && !@grants.empty? && !permits?('assets:share', item['folderId'])
|
|
2326
2327
|
return error(ErrorCodes::SIGNED_URL_INVALID, "The signed asset URL's grant is invalid", status: 403)
|
|
2327
2328
|
end
|
|
2328
2329
|
|
data/lib/calmlens/version.rb
CHANGED
data/sig/calmlens.rbs
CHANGED
|
@@ -232,8 +232,8 @@ module CalmLens
|
|
|
232
232
|
# Your integration's name, version and URL, added to the User-Agent.
|
|
233
233
|
type app_info = { name: String, ?version: String, ?url: String }
|
|
234
234
|
# One request attempt, as ServerClient's `on_request:` hook receives it.
|
|
235
|
-
type request_event = { operation: String?, method: String, path: String?, attempt: Integer,
|
|
236
|
-
status: Integer?, request_id: String?, error_code: String?,
|
|
235
|
+
type request_event = { operation: String?, method: String, path: String?, attempt: Integer, delay_ms: Integer?,
|
|
236
|
+
status: Integer?, request_id: String?, error_code: String?, duration_ms: Float,
|
|
237
237
|
server_timing: ServerTiming?, client_overhead_ms: Float? }
|
|
238
238
|
|
|
239
239
|
# A Ruby Logger, or anything with `info` and `debug` taking a block.
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: calmlens
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.44.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- CalmLens
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-12-
|
|
11
|
+
date: 2026-12-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: 'Server-side client for the CalmLens API: moderation, uploads, events,
|
|
14
14
|
webhooks and CDN delivery.'
|