hookbridge 2.3.0 → 2.4.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: 31ac5b314c6d5525fc2d2faec83ecb4809454e52b449db44354e230dee9cf58c
4
- data.tar.gz: 989f74a14e87a7f9a41ca68716aabc7a8b6cd38f0ab00d72782c93670d77ad11
3
+ metadata.gz: 55ca05a273bcee967fae0b444983ab9aaeb4db2105712c4f5d71c3fe67ff3321
4
+ data.tar.gz: a152e4b37bf6c3b3c53849d77c06566a3603f381ba3f320f29944efd3a6ca220
5
5
  SHA512:
6
- metadata.gz: 31cd75696ef83464e4e912f8215a02db23965e97568ca027f13e23020b3a306bbdff19fc4a794eb9def6b106e4e17ae5399c023fad0bc64952d88fb04c413c4e
7
- data.tar.gz: 29cf35afae19cd298e50f18c6e1e402ef7a277acc1dbc7aa0e29c1c21d8447bfdf51ff78794d52a8a85e317b8283121a980a1581d83f2c6ab56b7c9c4a09136e
6
+ metadata.gz: d5866352d22b355d26c4a089de80e878b8c4e5b100aac75f6df2405558a5e554722ca0a3add0225dde999fd236d655c37c59b7d76dbc101759a40492617b8166
7
+ data.tar.gz: 2964daa16e61aa71152852f07e08af564015678b6104d24b63ebcb677b30978589c7247fe73fe73293167714a1e305c5fda7ed7b9cb8032f324a70eae2c2b36d
data/CHANGELOG.md CHANGED
@@ -5,6 +5,26 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [2.4.0] - 2026-11-27
9
+
10
+ ### Added
11
+
12
+ - `endpoint_id` filter on `get_metrics`
13
+ - Optional `client_name:` on `replay`, `cancel_retry`, `retry_now`, `replay_all_messages`, `replay_all_inbound_messages`, `replay_batch_messages`, `replay_batch_inbound_messages`, `replay_from_dlq` and `replay_inbound_message`; overrides the client-level name for that call (printable ASCII, up to 200 bytes)
14
+ - `cancel_retry` and `retry_now` now return the response (`message_id`, `status`, and `message` for `retry_now`) instead of `nil`; `replay`, `replay_from_dlq`, `replay_inbound_message`, `replay_all_messages` and `replay_all_inbound_messages` also expose the top-level `message` (`nil` when absent)
15
+ - `update_endpoint` now returns `id`, `updated` and `subscriptions` (when provided) instead of `nil`
16
+
17
+ ### Fixed
18
+
19
+ - `list_endpoints` and `list_inbound_endpoints` always reported `has_more: false`, because the server sends only `next_cursor`. `has_more` is now derived from `next_cursor`
20
+ - An empty-string `next_cursor` on the last page of `list_endpoints`, `list_inbound_endpoints` and `list_pull_endpoints` is now `nil`, so `while page.next_cursor` loops end
21
+ - Optional response fields the server omits now return `nil` instead of raising `NoMethodError`: `delivered_at`, `failed_at`, `deleted_at` and other optional fields on messages; `deleted_at` on message summaries, pull-log and inbound-log entries; `avg_delivery_time_ms` and `avg_queue_wait_ms` on metrics; `signing_key_id` and `key_hint` on created endpoints; `key_hint` and `created_at` on signing keys; `ingest_url` on inbound endpoints; and all documented fields on a pull endpoint when `update_pull_endpoint` gets the `{id}`-only response
22
+
23
+ ### Unchanged by design
24
+
25
+ - Timestamps that are strings today (`delivered_at` and `failed_at` on `get_message`) stay strings to avoid a breaking change
26
+ - `delete_endpoint`, `delete_api_key` and the signing-key deletes still return `true`
27
+
8
28
  ## [2.3.0] - 2026-11-24
9
29
 
10
30
  ### Added
data/README.md CHANGED
@@ -72,9 +72,16 @@ message = client.get_message(result.message_id)
72
72
  logs = client.get_logs(limit: 100)
73
73
  endpoint_logs = client.get_logs(endpoint_id: endpoint.id)
74
74
  metrics = client.get_metrics
75
+ endpoint_metrics = client.get_metrics(endpoint_id: endpoint.id)
75
76
  timeseries = client.get_timeseries_metrics(endpoint_id: endpoint.id)
76
77
 
77
- client.replay(message.id)
78
+ result = client.replay(message.id) # => result.message_id, result.status ("queued"), result.message
79
+ client.cancel_retry(message.id) # => message_id and status ("failed_permanent")
80
+ client.retry_now(message.id) # => message_id and status ("pending_retry"), message
81
+
82
+ # Replay, retry and cancel calls accept a per-call client_name, recorded in the audit trail.
83
+ # It overrides the client-level name; printable ASCII, up to 200 bytes.
84
+ client.replay(message.id, client_name: "nightly-recovery/1.0")
78
85
  client.replay_all_messages(status: "failed_permanent", endpoint_id: endpoint.id, limit: 50)
79
86
 
80
87
  preview = client.replay_all_messages_dry_run(status: "failed_permanent", endpoint_id: endpoint.id, limit: 50)
@@ -94,7 +101,8 @@ endpoint = client.create_endpoint(
94
101
  url: "https://customer.app/webhooks",
95
102
  subscriptions: { event_types: ["order.created"], groups: ["billing"] }
96
103
  )
97
- client.update_endpoint(endpoint.id, subscriptions: { event_types: ["order.*"] }) # omit to leave unchanged
104
+ updated = client.update_endpoint(endpoint.id, subscriptions: { event_types: ["order.*"] }) # omit to leave unchanged
105
+ puts updated.updated # => true
98
106
  client.list_endpoints(event_type: "order.created")
99
107
 
100
108
  sent = client.send_event("order.created", { order_id: "ord_123" }) # fans out to subscribed endpoints
@@ -11,6 +11,7 @@ module HookBridge
11
11
  DEFAULT_SEND_URL = "https://send.hookbridge.io"
12
12
  DEFAULT_TIMEOUT = 30
13
13
  DEFAULT_RETRIES = 3
14
+ MAX_CLIENT_NAME_BYTES = 200
14
15
  UNSET = Object.new.freeze
15
16
  private_constant :UNSET
16
17
 
@@ -57,25 +58,27 @@ module HookBridge
57
58
  AttemptsResponse.new(extract_data(response), extract_meta(response))
58
59
  end
59
60
 
60
- def replay(message_id)
61
- ReplayResponse.new(extract_data(request(:post, "/v1/messages/#{message_id}/replay")))
61
+ def replay(message_id, client_name: nil)
62
+ response = request(:post, "/v1/messages/#{message_id}/replay", client_name: client_name)
63
+ ReplayResponse.new(extract_data_with_message(response))
62
64
  end
63
65
 
64
- def cancel_retry(message_id)
65
- request(:post, "/v1/messages/#{message_id}/cancel")
66
- nil
66
+ def cancel_retry(message_id, client_name: nil)
67
+ response = request(:post, "/v1/messages/#{message_id}/cancel", client_name: client_name)
68
+ CancelRetryResponse.new(extract_data_with_message(response))
67
69
  end
68
70
 
69
- def retry_now(message_id)
70
- request(:post, "/v1/messages/#{message_id}/retry-now")
71
- nil
71
+ def retry_now(message_id, client_name: nil)
72
+ response = request(:post, "/v1/messages/#{message_id}/retry-now", client_name: client_name)
73
+ RetryNowResponse.new(extract_data_with_message(response))
72
74
  end
73
75
 
74
- def replay_all_messages(status:, endpoint_id: nil, limit: nil)
76
+ def replay_all_messages(status:, endpoint_id: nil, limit: nil, client_name: nil)
75
77
  params = { status: status }
76
78
  params[:endpoint_id] = endpoint_id if endpoint_id
77
79
  params[:limit] = limit if limit
78
- ReplayAllMessagesResponse.new(extract_data(request(:post, "/v1/messages/replay-all", nil, params)))
80
+ response = request(:post, "/v1/messages/replay-all", nil, params, client_name: client_name)
81
+ ReplayAllMessagesResponse.new(extract_data_with_message(response))
79
82
  end
80
83
 
81
84
  def replay_all_messages_dry_run(status:, endpoint_id: nil, limit: nil)
@@ -90,9 +93,10 @@ module HookBridge
90
93
  fetch_message_actions("/v1/messages/#{ERB::Util.url_encode(message_id)}/actions", cursor, limit)
91
94
  end
92
95
 
93
- def replay_batch_messages(message_ids)
96
+ def replay_batch_messages(message_ids, client_name: nil)
94
97
  ReplayBatchMessagesResponse.new(
95
- extract_data(request(:post, "/v1/messages/replay-batch", { message_ids: message_ids }))
98
+ extract_data(request(:post, "/v1/messages/replay-batch", { message_ids: message_ids },
99
+ client_name: client_name))
96
100
  )
97
101
  end
98
102
 
@@ -112,8 +116,10 @@ module HookBridge
112
116
  )
113
117
  end
114
118
 
115
- def get_metrics(window: MetricsWindow::TWENTY_FOUR_HOURS)
116
- Metrics.new(extract_data(request(:get, "/v1/metrics", nil, { window: window })))
119
+ def get_metrics(window: MetricsWindow::TWENTY_FOUR_HOURS, endpoint_id: nil)
120
+ params = { window: window }
121
+ params[:endpoint_id] = endpoint_id if endpoint_id
122
+ Metrics.new(extract_data(request(:get, "/v1/metrics", nil, params)))
117
123
  end
118
124
 
119
125
  def get_timeseries_metrics(window: MetricsWindow::TWENTY_FOUR_HOURS, endpoint_id: nil)
@@ -138,8 +144,9 @@ module HookBridge
138
144
  )
139
145
  end
140
146
 
141
- def replay_from_dlq(message_id)
142
- ReplayResponse.new(extract_data(request(:post, "/v1/dlq/replay/#{message_id}")))
147
+ def replay_from_dlq(message_id, client_name: nil)
148
+ response = request(:post, "/v1/dlq/replay/#{message_id}", client_name: client_name)
149
+ ReplayResponse.new(extract_data_with_message(response))
143
150
  end
144
151
 
145
152
  def list_api_keys
@@ -198,8 +205,7 @@ module HookBridge
198
205
  body[:burst] = burst if burst
199
206
  body[:headers] = headers if headers
200
207
  body[:subscriptions] = subscriptions unless subscriptions.nil?
201
- request(:patch, "/v1/endpoints/#{endpoint_id}", body)
202
- nil
208
+ UpdateEndpointResponse.new(extract_data(request(:patch, "/v1/endpoints/#{endpoint_id}", body)))
203
209
  end
204
210
 
205
211
  def delete_endpoint(endpoint_id)
@@ -541,15 +547,17 @@ module HookBridge
541
547
  AttemptsResponse.new(extract_data(response), extract_meta(response))
542
548
  end
543
549
 
544
- def replay_inbound_message(message_id)
545
- ReplayResponse.new(extract_data(request(:post, "/v1/inbound-messages/#{message_id}/replay")))
550
+ def replay_inbound_message(message_id, client_name: nil)
551
+ response = request(:post, "/v1/inbound-messages/#{message_id}/replay", client_name: client_name)
552
+ ReplayResponse.new(extract_data_with_message(response))
546
553
  end
547
554
 
548
- def replay_all_inbound_messages(status:, inbound_endpoint_id: nil, limit: nil)
555
+ def replay_all_inbound_messages(status:, inbound_endpoint_id: nil, limit: nil, client_name: nil)
549
556
  params = { status: status }
550
557
  params[:inbound_endpoint_id] = inbound_endpoint_id if inbound_endpoint_id
551
558
  params[:limit] = limit if limit
552
- ReplayAllMessagesResponse.new(extract_data(request(:post, "/v1/inbound-messages/replay-all", nil, params)))
559
+ response = request(:post, "/v1/inbound-messages/replay-all", nil, params, client_name: client_name)
560
+ ReplayAllMessagesResponse.new(extract_data_with_message(response))
553
561
  end
554
562
 
555
563
  def replay_all_inbound_messages_dry_run(status:, inbound_endpoint_id: nil, limit: nil)
@@ -564,9 +572,10 @@ module HookBridge
564
572
  fetch_message_actions("/v1/inbound-messages/#{ERB::Util.url_encode(message_id)}/actions", cursor, limit)
565
573
  end
566
574
 
567
- def replay_batch_inbound_messages(message_ids)
575
+ def replay_batch_inbound_messages(message_ids, client_name: nil)
568
576
  ReplayBatchMessagesResponse.new(
569
- extract_data(request(:post, "/v1/inbound-messages/replay-batch", { message_ids: message_ids }))
577
+ extract_data(request(:post, "/v1/inbound-messages/replay-batch", { message_ids: message_ids },
578
+ client_name: client_name))
570
579
  )
571
580
  end
572
581
 
@@ -737,10 +746,21 @@ module HookBridge
737
746
  name.nil? || name.match?(/\A[\x20-\x7E]*\z/)
738
747
  end
739
748
 
740
- def request(method, path, body = nil, params = nil, use_send_connection: false, allow_redirect: false)
749
+ def validate_call_client_name!(name)
750
+ return if name.nil?
751
+ return if name.is_a?(String) && name.valid_encoding? && valid_client_name?(name) &&
752
+ name.bytesize <= MAX_CLIENT_NAME_BYTES
753
+
754
+ raise ValidationError, "client_name must be printable ASCII, up to #{MAX_CLIENT_NAME_BYTES} bytes"
755
+ end
756
+
757
+ def request(method, path, body = nil, params = nil, use_send_connection: false, allow_redirect: false,
758
+ client_name: nil)
759
+ validate_call_client_name!(client_name)
741
760
  conn = use_send_connection ? @send_connection : @connection
742
761
  response = conn.run_request(method, path, body&.to_json, nil) do |req|
743
762
  req.params.update(params) if params
763
+ req.headers["X-Hookbridge-Client"] = client_name unless client_name.nil? || client_name.empty?
744
764
  end
745
765
 
746
766
  handle_response(response, allow_redirect: allow_redirect)
@@ -834,6 +854,13 @@ module HookBridge
834
854
  response.is_a?(Hash) && response.key?("data") ? response["data"] : response
835
855
  end
836
856
 
857
+ def extract_data_with_message(response)
858
+ data = extract_data(response)
859
+ return data unless data.is_a?(Hash) && response.is_a?(Hash) && response["message"].is_a?(String)
860
+
861
+ data.merge("message" => response["message"])
862
+ end
863
+
837
864
  def extract_meta(response)
838
865
  response.is_a?(Hash) ? (response["meta"] || {}) : {}
839
866
  end
@@ -78,7 +78,9 @@ module HookBridge
78
78
  end
79
79
 
80
80
  class Message < BaseModel
81
- optional_fields :event_type, :event_id, :is_test
81
+ optional_fields :event_type, :event_id, :is_test, :idempotency_key, :next_attempt_at, :last_error,
82
+ :response_status, :response_latency_ms, :processing_ms, :retention_hours, :delivered_at,
83
+ :failed_at, :first_attempt_at, :total_delivery_ms, :queue_wait_ms, :deleted_at
82
84
 
83
85
  def initialize(data)
84
86
  super(data, time_fields: %w[next_attempt_at first_attempt_at created_at updated_at deleted_at])
@@ -86,7 +88,7 @@ module HookBridge
86
88
  end
87
89
 
88
90
  class MessageSummary < BaseModel
89
- optional_fields :event_type, :event_id, :is_test
91
+ optional_fields :event_type, :event_id, :is_test, :deleted_at
90
92
 
91
93
  def initialize(data)
92
94
  super(data, time_fields: %w[created_at delivered_at next_attempt_at first_attempt_at deleted_at])
@@ -99,6 +101,12 @@ module HookBridge
99
101
  class ReplayResponse < BaseModel
100
102
  end
101
103
 
104
+ class CancelRetryResponse < BaseModel
105
+ end
106
+
107
+ class RetryNowResponse < BaseModel
108
+ end
109
+
102
110
  class SendEventResponse < BaseModel
103
111
  end
104
112
 
@@ -166,9 +174,11 @@ module HookBridge
166
174
  end
167
175
 
168
176
  class Metrics < BaseModel
177
+ optional_fields :avg_delivery_time_ms, :avg_queue_wait_ms
169
178
  end
170
179
 
171
180
  class InboundMetrics < BaseModel
181
+ optional_fields :avg_delivery_time_ms, :avg_queue_wait_ms
172
182
  end
173
183
 
174
184
  class DLQMessage < BaseModel
@@ -241,6 +251,8 @@ module HookBridge
241
251
  class CreateEndpointResponse < BaseModel
242
252
  include NormalizesSubscriptions
243
253
 
254
+ optional_fields :signing_key_id, :key_hint
255
+
244
256
  def initialize(data)
245
257
  super(data, time_fields: %w[created_at expires_at])
246
258
  normalize_subscriptions
@@ -265,29 +277,45 @@ module HookBridge
265
277
  end
266
278
  end
267
279
 
280
+ class UpdateEndpointResponse < BaseModel
281
+ include NormalizesSubscriptions
282
+
283
+ optional_fields :subscriptions
284
+
285
+ def initialize(data)
286
+ super
287
+ normalize_subscriptions
288
+ end
289
+ end
290
+
268
291
  class ListEndpointsResponse
269
292
  attr_reader :endpoints, :has_more, :next_cursor
270
293
 
271
294
  def initialize(data)
272
295
  @endpoints = (data["data"] || data || []).map { |entry| EndpointSummary.new(entry) }
273
- @has_more = data["has_more"] || false
274
- @next_cursor = data["next_cursor"]
296
+ @next_cursor = data["next_cursor"].then { |cursor| cursor&.empty? ? nil : cursor }
297
+ @has_more = data["has_more"] || !@next_cursor.nil?
275
298
  end
276
299
  end
277
300
 
278
301
  class RotateSecretResponse < BaseModel
302
+ optional_fields :key_hint, :created_at
303
+
279
304
  def initialize(data)
280
305
  super(data, time_fields: %w[created_at])
281
306
  end
282
307
  end
283
308
 
284
309
  class SigningKey < BaseModel
310
+ optional_fields :key_hint, :created_at
311
+
285
312
  def initialize(data)
286
313
  super(data, time_fields: %w[created_at])
287
314
  end
288
315
  end
289
316
 
290
317
  class ReplayAllMessagesResponse < BaseModel
318
+ optional_fields :message
291
319
  end
292
320
 
293
321
  class ReplayAllDryRunResponse < BaseModel
@@ -419,6 +447,8 @@ module HookBridge
419
447
  end
420
448
 
421
449
  class InboundEndpoint < BaseModel
450
+ optional_fields :ingest_url
451
+
422
452
  def initialize(data)
423
453
  super(data, time_fields: %w[created_at updated_at expires_at])
424
454
  end
@@ -435,8 +465,8 @@ module HookBridge
435
465
 
436
466
  def initialize(data)
437
467
  @endpoints = (data["data"] || data || []).map { |entry| InboundEndpointSummary.new(entry) }
438
- @has_more = data["has_more"] || false
439
- @next_cursor = data["next_cursor"]
468
+ @next_cursor = data["next_cursor"].then { |cursor| cursor&.empty? ? nil : cursor }
469
+ @has_more = data["has_more"] || !@next_cursor.nil?
440
470
  end
441
471
  end
442
472
 
@@ -468,6 +498,9 @@ module HookBridge
468
498
  end
469
499
 
470
500
  class PullEndpoint < BaseModel
501
+ optional_fields :name, :description, :mode, :ingest_url, :active, :paused, :retention_days, :event_type_source,
502
+ :event_type_path, :counts, :created_at, :updated_at
503
+
471
504
  def initialize(data)
472
505
  attributes = (data || {}).dup
473
506
  attributes["counts"] = PullEndpointCounts.new(attributes["counts"]) if attributes["counts"].is_a?(Hash)
@@ -489,8 +522,8 @@ module HookBridge
489
522
 
490
523
  def initialize(data)
491
524
  @endpoints = (data["data"] || data || []).map { |entry| PullEndpointSummary.new(entry) }
492
- @has_more = !data["next_cursor"].nil? && data["next_cursor"] != ""
493
- @next_cursor = data["next_cursor"]
525
+ @next_cursor = data["next_cursor"].then { |cursor| cursor&.empty? ? nil : cursor }
526
+ @has_more = !@next_cursor.nil?
494
527
  end
495
528
  end
496
529
 
@@ -527,6 +560,8 @@ module HookBridge
527
560
  end
528
561
 
529
562
  class PullLogEntry < BaseModel
563
+ optional_fields :deleted_at
564
+
530
565
  def initialize(data)
531
566
  attributes = (data || {}).dup
532
567
  attributes["timing"] = PullTimingBreakdown.new(attributes["timing"]) if attributes["timing"].is_a?(Hash)
@@ -545,6 +580,8 @@ module HookBridge
545
580
  end
546
581
 
547
582
  class InboundLogEntry < BaseModel
583
+ optional_fields :deleted_at
584
+
548
585
  def initialize(data)
549
586
  super(data, time_fields: %w[received_at delivered_at deleted_at])
550
587
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HookBridge
4
- VERSION = "2.3.0"
4
+ VERSION = "2.4.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hookbridge
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - HookBridge