guesty-client 0.2.2 → 0.2.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 +4 -4
- data/CHANGELOG.md +13 -1
- data/lib/guesty/access_tokens/upsert.rb +24 -3
- data/lib/guesty/version.rb +1 -1
- data/sig/guesty.rbs +2 -0
- 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: 81b130a2500214e38bcdf321b7da4a9270e26885435bdca751578a8041f97c9c
|
|
4
|
+
data.tar.gz: a9beb0d022fd1915aaa09478a3371ee3d12d803c9072384d3e8bc653382b13db
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e72fa07f7d987c3a375efb6b2c46d7f80b0aa27d97dc8fba3ea537f70041a898dc667f6b13a6a064ba85586fa1516ac13d572f805493a094e698eec08fe3296d
|
|
7
|
+
data.tar.gz: 02ac8280a331175279ca17eda6295acd4e4ad89a7516b7341451ea61a3cef03a34da0ec1364e00cc26c571cf563f70f40bb80ab76aec712ea30d94111daae26a
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.2.3] - 2026-11-22
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- `AccessTokens::Upsert` can no longer take a priority offline when Guesty's token endpoint fails. Guesty counts every
|
|
10
|
+
token request, 502 answers included, against 5 per day per client id and answers 429 until 00:00 UTC. Minting is now
|
|
11
|
+
throttled per slot through `Guesty.config.rate_limiter` (`guesty_token_mint_<slot>`, once per 10 minutes, a throttled
|
|
12
|
+
caller raises `ThrottledError` without a request); a token expiring within 30 minutes is refreshed ahead and kept
|
|
13
|
+
when the mint fails; a slot with no valid token borrows another slot's valid token (never saved under the dead slot,
|
|
14
|
+
which keeps minting for itself) and raises the original error only when no slot has one.
|
|
15
|
+
|
|
5
16
|
## [0.2.2] - 2026-11-19
|
|
6
17
|
|
|
7
18
|
### Added
|
|
@@ -105,7 +116,8 @@ that integration's provider specs, ported with their recorded VCR cassettes.
|
|
|
105
116
|
- Webhooks: `Index`, `Create`, `Update`, `Sync`, `Signatures::Verify` for Svix signatures.
|
|
106
117
|
- Views: `Create`, `Update`.
|
|
107
118
|
|
|
108
|
-
[Unreleased]: https://github.com/guestitab/guesty-client/compare/v0.2.
|
|
119
|
+
[Unreleased]: https://github.com/guestitab/guesty-client/compare/v0.2.3...staging
|
|
120
|
+
[0.2.3]: https://github.com/guestitab/guesty-client/compare/v0.2.2...v0.2.3
|
|
109
121
|
[0.2.2]: https://github.com/guestitab/guesty-client/compare/v0.2.1...v0.2.2
|
|
110
122
|
[0.2.1]: https://github.com/guestitab/guesty-client/compare/v0.2.0...v0.2.1
|
|
111
123
|
[0.2.0]: https://github.com/guestitab/guesty-client/compare/v0.1.0...v0.2.0
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
module Guesty
|
|
2
2
|
module AccessTokens
|
|
3
|
-
# Guesty mints only 5 access tokens per client id within 24 hours and
|
|
4
|
-
# answers 429 to everything after, so a token must never be discarded.
|
|
5
3
|
class Upsert
|
|
6
4
|
include Guesty::Operation
|
|
7
5
|
|
|
8
6
|
OAUTH_ENDPOINT = 'https://open-api.guesty.com/oauth2/token'.freeze #: ::String
|
|
7
|
+
MINT_INTERVAL = 10.minutes #: untyped
|
|
8
|
+
REFRESH_WINDOW = 30.minutes #: untyped
|
|
9
9
|
|
|
10
10
|
# @rbs () -> Dry::Monads::Result[untyped]
|
|
11
11
|
def call
|
|
12
12
|
slot = Guesty.current_slot
|
|
13
|
+
token = store.read(slot[:key])
|
|
14
|
+
return Success(token) if token && token.expires_at > REFRESH_WINDOW.from_now
|
|
13
15
|
|
|
14
|
-
Success(
|
|
16
|
+
Success(mint_or_fallback(slot, token))
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
private
|
|
@@ -20,8 +22,27 @@ module Guesty
|
|
|
20
22
|
Guesty.config.token_store
|
|
21
23
|
end
|
|
22
24
|
|
|
25
|
+
# A token must never be discarded: Guesty mints only 5 access tokens per client id per day, counts every
|
|
26
|
+
# token request (502 answers included) and answers 429 to everything after, until 00:00 UTC. A failed or
|
|
27
|
+
# throttled mint keeps the stored token, or borrows another slot's, and never saves the borrowed one here.
|
|
28
|
+
# @rbs (Guesty::slot slot, untyped token) -> untyped
|
|
29
|
+
def mint_or_fallback(slot, token)
|
|
30
|
+
mint(slot)
|
|
31
|
+
rescue Guesty::Error, Faraday::Error => e
|
|
32
|
+
token || borrowed_token || raise(e)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# @rbs () -> untyped
|
|
36
|
+
def borrowed_token
|
|
37
|
+
slots = (Guesty.config.credentials.keys - [:webhook_key]).flat_map { |priority| Guesty.token_slots(priority) }
|
|
38
|
+
|
|
39
|
+
slots.lazy.filter_map { |slot| store.read(slot[:key]) }.first
|
|
40
|
+
end
|
|
41
|
+
|
|
23
42
|
# @rbs (Guesty::slot slot) -> untyped
|
|
24
43
|
def mint(slot)
|
|
44
|
+
Guesty.config.rate_limiter.throttle!(key: :"guesty_token_mint_#{slot[:key]}", threshold: 1, interval: MINT_INTERVAL)
|
|
45
|
+
|
|
25
46
|
response = Guesty.connection(url: OAUTH_ENDPOINT, skip_auth: true).post do |req|
|
|
26
47
|
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
|
27
48
|
req.body = { grant_type: 'client_credentials', scope: 'open-api', client_secret: slot[:secret], client_id: slot[:client_id] }
|
data/lib/guesty/version.rb
CHANGED
data/sig/guesty.rbs
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: guesty-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Guestit
|
|
@@ -190,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
190
190
|
- !ruby/object:Gem::Version
|
|
191
191
|
version: '0'
|
|
192
192
|
requirements: []
|
|
193
|
-
rubygems_version: 4.0.
|
|
193
|
+
rubygems_version: 4.0.20
|
|
194
194
|
specification_version: 4
|
|
195
195
|
summary: Ruby client for the Guesty Open API
|
|
196
196
|
test_files: []
|