standard_id 0.63.0 → 0.64.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: f4338b3e28da791aae773a472cbc7eda8a0fcc4d94ee2513f733e84f9b4185a5
4
- data.tar.gz: 23c17a0ea7040d29787ebd23671047eb239f8cf73567c11414f0097f53f02ded
3
+ metadata.gz: 299bfc41d084764b04761feb2ad82437e7ac0cd3ea4dd47667c4e021519211ad
4
+ data.tar.gz: 17c66fdb33e21a1f9b2d694d9e310193133557617b000962089a39db1eb4288e
5
5
  SHA512:
6
- metadata.gz: e4c3dbe4a53c0a84cdc99d73fd5e46e5a820c1ad60f3fd23e5a71bd280aae8c184fcf42e814c9ef6d6e754bd519c839d4a682996a3092730eec49fd012aa646c
7
- data.tar.gz: 43fb59a7c70eef841e53b986420a3fcbe99463de22f4d4b9cc981891be80e311aed0baf720c6df8ef149f23eb35138e552fb435280f2f7460ff8de203c87b38e
6
+ metadata.gz: '08cd8132db371312d928220af8f3a520bd9cc5610c02e255a17e298d5516001a82caabf9c22b16d48898d2f47834742cce8e87f0c4c75389448b3aa82a6aedfc'
7
+ data.tar.gz: '0867392da53c2a1750bec89e41339e2166a63477c8ed88b1553f33a90ecad045b1026ff9c4fda74184017585ce5388533b6aa0d37858ced36586e994bb2eb469'
data/CHANGELOG.md CHANGED
@@ -7,6 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.64.0] - 2026-11-25
11
+
12
+ ### Added
13
+
14
+ - **`config.network_wrapper_passthrough_errors`.** Errors the host's `network_wrapper` raises
15
+ that mean its own setup is wrong, not that the provider is down, reach the caller unchanged
16
+ instead of becoming `ProviderUnavailableError`. An example is `StandardCircuit::UnknownCircuit`
17
+ for a circuit that was never registered. Without the setting, such a misconfiguration shows
18
+ users "temporarily unavailable" and never reaches the error tracker. Entries are classes or
19
+ class-name Strings; a String is resolved when a wrapper error is handled, so it may name a
20
+ class from a gem that isn't loaded, and a name that resolves to nothing is ignored. Defaults
21
+ to `[]`, so nothing changes unless you set it.
22
+ - **`Retry-After` for a refused provider call.** `ProviderUnavailableError` now has
23
+ `retry_after` (Integer seconds, or nil). `NetworkWrapper` fills it in from the wrapper's
24
+ error: a `retry_after` that is a `Time` (seconds until then) or a number of seconds, or else
25
+ `cool_off_time` in seconds, as Stoplight's `RedLight` provides. It is duck-typed and assumes
26
+ no breaker library. The API's 503 `temporarily_unavailable` responses, such as
27
+ `/api/oauth/callback/:provider`, then send a `Retry-After` header. Errors that say nothing
28
+ get no header, as before.
29
+
10
30
  ## [0.63.0] - 2026-11-24
11
31
 
12
32
  ### Added
data/README.md CHANGED
@@ -786,6 +786,10 @@ breaker that turns the request's failure into its own error), StandardId raises
786
786
  `cause`. That is an `OAuthError`, so the web callback sends the user back to the
787
787
  login page with "Google is temporarily unavailable" and the API answers 503
788
788
  `temporarily_unavailable`. The circuit's own message never reaches the user.
789
+ When the wrapper's error says how long to wait, the 503 carries a `Retry-After`
790
+ header: StandardId reads `retry_after` (a `Time` or a number of seconds) or,
791
+ failing that, `cool_off_time` (seconds) from it, as Stoplight's `RedLight`
792
+ provides. It knows no breaker library, so any error with those methods works.
789
793
 
790
794
  Some errors from the wrapper are passed through unchanged:
791
795
  - a `StandardId::OAuthError` it raises on purpose
@@ -794,6 +798,22 @@ Some errors from the wrapper are passed through unchanged:
794
798
  - a programming error (`NameError`/`NoMethodError`, `TypeError`,
795
799
  `ArgumentError`; see `StandardId::NetworkWrapper::PROGRAMMING_ERRORS`), so
796
800
  your error tracker sees the bug
801
+ - an error you list in `config.network_wrapper_passthrough_errors`
802
+
803
+ That last setting is for errors that mean your own setup is wrong rather than
804
+ the provider being down. `StandardCircuit.run` raises
805
+ `StandardCircuit::UnknownCircuit` (not a programming error) when no circuit is
806
+ registered under the name, and without the setting that misconfiguration would
807
+ look like an outage to users and never reach your error tracker:
808
+
809
+ ```ruby
810
+ c.network_wrapper_passthrough_errors = ["StandardCircuit::UnknownCircuit"]
811
+ ```
812
+
813
+ Entries are classes or class names. A name is resolved when a wrapper error is
814
+ handled, so it may name a class from a gem that isn't loaded; a name that
815
+ resolves to nothing is ignored. An error passes through when it `is_a?` any
816
+ entry. Errors the request itself raised are passed through regardless.
797
817
 
798
818
  `provider` is the plugin's name
799
819
  (`:google`, `:apple`, ...), or `:standard_id` for a plugin release that does not
@@ -643,10 +643,19 @@ StandardId.configure do |c|
643
643
  # the request as a block; must call the block and return its result. A
644
644
  # refusal by the wrapper itself (an open circuit) becomes
645
645
  # StandardId::ProviderUnavailableError, so sign-in fails as "temporarily
646
- # unavailable" (API: 503) without the circuit's message.
646
+ # unavailable" (API: 503, with Retry-After when the refusal says how long
647
+ # to wait) without the circuit's message.
647
648
  # Default: nil (the request runs directly)
648
649
  # c.network_wrapper = ->(provider:, &b) { StandardCircuit.run(:"oauth_#{provider}", &b) }
649
650
 
651
+ # Errors network_wrapper raises that mean your setup is wrong, not that the
652
+ # provider is down (a circuit that was never registered, say). They reach
653
+ # the caller and your error tracker unchanged instead of becoming
654
+ # ProviderUnavailableError. Classes or class names; a name that resolves to
655
+ # nothing (its gem isn't loaded) is ignored.
656
+ # Default: []
657
+ # c.network_wrapper_passthrough_errors = ["StandardCircuit::UnknownCircuit"]
658
+
650
659
  # Receives errors StandardId handles and carries on from (a subscriber that
651
660
  # raised after its change committed). Receives (error, context).
652
661
  # Default: nil (Rails.error.report(error, handled: true, source: "standard_id"))
@@ -179,15 +179,30 @@ StandardId::ConfigSchema.define do
179
179
  # (timeouts, refused connections) raises inside the wrapper and, re-raised,
180
180
  # reaches the caller unchanged. A refusal by the wrapper itself (an open
181
181
  # circuit) becomes StandardId::ProviderUnavailableError, `cause` set to it,
182
- # so a sign-in fails as "temporarily unavailable" (API: 503) without the
183
- # circuit's message. Programming errors in the wrapper, and errors it
184
- # raises after the block returned, pass through unchanged (see
185
- # StandardId::NetworkWrapper).
182
+ # so a sign-in fails as "temporarily unavailable" (API: 503, with
183
+ # Retry-After when the refusal says how long to wait) without the
184
+ # circuit's message. Programming errors in the wrapper, errors listed in
185
+ # network_wrapper_passthrough_errors, and errors it raises after the
186
+ # block returned pass through unchanged (see StandardId::NetworkWrapper).
186
187
  # nil (the default) runs the block directly.
187
188
  #
188
189
  # c.network_wrapper = ->(provider:, &b) { StandardCircuit.run(:"oauth_#{provider}", &b) }
189
190
  field :network_wrapper, type: :any, default: nil
190
191
 
192
+ # network_wrapper_passthrough_errors: errors network_wrapper raises that
193
+ # mean the host's own setup is wrong, not that the provider is down, such
194
+ # as a circuit that was never registered. They reach the caller (and the
195
+ # error tracker) unchanged instead of becoming
196
+ # StandardId::ProviderUnavailableError. An error passes through when it
197
+ # `is_a?` any entry.
198
+ # Entries: classes, or class names as Strings. A String is resolved
199
+ # when a wrapper error is handled, so it may name a class from a gem
200
+ # that is not loaded; a name that resolves to nothing is ignored.
201
+ # [] (the default) passes none through.
202
+ #
203
+ # c.network_wrapper_passthrough_errors = ["StandardCircuit::UnknownCircuit"]
204
+ field :network_wrapper_passthrough_errors, type: :array, default: -> { [] }
205
+
191
206
  # error_reporter: receives errors StandardId handles and carries on from —
192
207
  # today, an event subscriber that raised after the change it reports had
193
208
  # already committed (a completed password reset, a password rehash, a
@@ -229,8 +229,14 @@ module StandardId
229
229
  # @return [Symbol, nil] the provider the request was for (`:google`, ...)
230
230
  attr_reader :provider
231
231
 
232
- def initialize(message = nil, provider: nil)
232
+ # @return [Integer, nil] seconds the wrapper's error says to wait before
233
+ # retrying (StandardId::NetworkWrapper reads it from the error), sent
234
+ # by the API as a Retry-After header; nil when it doesn't say
235
+ attr_reader :retry_after
236
+
237
+ def initialize(message = nil, provider: nil, retry_after: nil)
233
238
  @provider = provider
239
+ @retry_after = retry_after
234
240
  super(message || "#{provider_label(provider)} is temporarily unavailable")
235
241
  end
236
242
 
@@ -23,11 +23,17 @@ module StandardId
23
23
  # 4. A programming error in the wrapper (PROGRAMMING_ERRORS: a typo, an
24
24
  # unloaded constant, a wrong call) reaches the caller as is, so it is
25
25
  # reported as the bug it is, not shown as an outage.
26
- # 5. Anything else (an open circuit that never ran the block, a breaker
26
+ # 5. An error the host listed in `config.network_wrapper_passthrough_errors`
27
+ # (a misconfiguration of its own, such as a circuit that was never
28
+ # registered) reaches the caller as is, for the same reason.
29
+ # 6. Anything else (an open circuit that never ran the block, a breaker
27
30
  # that turns the request's failure into its own error) becomes
28
31
  # StandardId::ProviderUnavailableError, with the wrapper's error as
29
32
  # `cause`. Callers therefore need no knowledge of the host's
30
- # circuit-breaker library to map an outage.
33
+ # circuit-breaker library to map an outage. When the wrapper's error
34
+ # says how long to wait (see .retry_after_from), the
35
+ # ProviderUnavailableError carries it as `retry_after`, which the API
36
+ # sends as a Retry-After header.
31
37
  #
32
38
  # Non-StandardError exceptions (Interrupt, ...) are never touched.
33
39
  module NetworkWrapper
@@ -41,7 +47,7 @@ module StandardId
41
47
  # `:apple`, ...), handed to the wrapper as `provider:`
42
48
  # @return whatever the block (through the wrapper) returns
43
49
  # @raise [StandardId::ProviderUnavailableError] the wrapper refused the
44
- # request (rule 5 above)
50
+ # request (rule 6 above)
45
51
  def run(provider:, &block)
46
52
  wrapper = StandardId.config.network_wrapper
47
53
  return yield unless wrapper.respond_to?(:call)
@@ -70,9 +76,43 @@ module StandardId
70
76
  raise if raised.any? { |error| error.equal?(e) }
71
77
  raise if returned
72
78
  raise if PROGRAMMING_ERRORS.any? { |klass| e.is_a?(klass) }
79
+ raise if passthrough_errors.any? { |klass| e.is_a?(klass) }
73
80
 
74
- raise StandardId::ProviderUnavailableError.new(provider: provider), cause: e
81
+ raise StandardId::ProviderUnavailableError.new(provider: provider, retry_after: retry_after_from(e)), cause: e
75
82
  end
76
83
  end
84
+
85
+ # The classes in `config.network_wrapper_passthrough_errors`. A String
86
+ # names a class that may not be loaded (it may come from a gem the host
87
+ # has not required), so it is resolved on each call and skipped while it
88
+ # names nothing.
89
+ #
90
+ # @return [Array<Module>]
91
+ def passthrough_errors
92
+ Array(StandardId.config.network_wrapper_passthrough_errors).filter_map do |entry|
93
+ klass = entry.is_a?(Module) ? entry : entry.to_s.safe_constantize
94
+ klass if klass.is_a?(Module)
95
+ end
96
+ end
97
+
98
+ # How long, in whole seconds, the wrapper's error says to wait before
99
+ # retrying, or nil when it doesn't say. Duck-typed, so no breaker library
100
+ # is assumed: a `retry_after` that is a Time (when to retry) or a Numeric
101
+ # (seconds) decides; without one, `cool_off_time` in seconds. Stoplight's
102
+ # RedLight has both, with `retry_after` nil while a light is locked red.
103
+ #
104
+ # @param error [Exception] the wrapper's error
105
+ # @return [Integer, nil] a positive number of seconds, or nil
106
+ def retry_after_from(error)
107
+ value = error.retry_after if error.respond_to?(:retry_after)
108
+ value -= Time.now if value.is_a?(Time)
109
+ value = error.cool_off_time if !value.is_a?(Numeric) && error.respond_to?(:cool_off_time)
110
+
111
+ value.ceil if value.is_a?(Numeric) && value.positive?
112
+ rescue StandardError
113
+ # Only a hint for a header: a host error whose accessor misbehaves must
114
+ # not replace the ProviderUnavailableError being raised.
115
+ nil
116
+ end
77
117
  end
78
118
  end
@@ -1,3 +1,3 @@
1
1
  module StandardId
2
- VERSION = "0.63.0"
2
+ VERSION = "0.64.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standard_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.63.0
4
+ version: 0.64.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rarebit One