lingara-embed 0.2.0.pre.alpha.6 → 0.2.0.pre.alpha.7
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/README.md +28 -3
- data/lib/lingara/embed/server.rb +30 -6
- data/lib/lingara/embed/token_handoff.rb +23 -9
- data/lib/lingara/embed/version.rb +2 -2
- data/sig/lingara_embed.rbs +11 -2
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: aa821a18737f5143194141b5e8d0642a7476dccc34f098618c417b7c286bf22f
|
|
4
|
+
data.tar.gz: 0bc51b934c6910e87467eef55d5395b85695c89625c6d2a17735248c207b02ee
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 565573aa9bfb4eecad8a88a56b6ce68f69d76a91851161ae3ce636f3db5b790da680b821c5b27b1f3202740d55d96d7500f01a4a1d4e2bb351236c91e6690172
|
|
7
|
+
data.tar.gz: 8c03dc465a73419b887c303e460767fa91231465090f0641bf4e77b72f867c38b12f009464c244398a69991cd31ee4a5ddab4e4c2d46b848d312b35231b4e204
|
data/README.md
CHANGED
|
@@ -47,14 +47,15 @@ Here it is in Sinatra:
|
|
|
47
47
|
```ruby
|
|
48
48
|
post "/lingara/token" do
|
|
49
49
|
halt 401 unless current_user
|
|
50
|
-
minted = server.mint_token(current_user.id.to_s, origin: "https://game.example"
|
|
50
|
+
minted = server.mint_token(current_user.id.to_s, origin: "https://game.example",
|
|
51
|
+
embed_version: Lingara::Embed.embed_version_from(request.env))
|
|
51
52
|
content_type :json
|
|
52
53
|
cache_control :no_store
|
|
53
|
-
Lingara::Embed.token_handoff(minted) # {"token":"lgr_et_…","expires_at":"…Z"}
|
|
54
|
+
Lingara::Embed.token_handoff(minted) # {"token":"lgr_et_…","expires_at":"…Z"}, plus update_available when answered
|
|
54
55
|
end
|
|
55
56
|
```
|
|
56
57
|
|
|
57
|
-
- `mint_token(player_ref, scopes: nil, origin: nil)` makes exactly one
|
|
58
|
+
- `mint_token(player_ref, scopes: nil, origin: nil, embed_version: nil)` makes exactly one
|
|
58
59
|
`POST /v1/embed/tokens` and returns the library's `Lingara::MintedToken`.
|
|
59
60
|
It then calls `directory.remember(player_ref, subject)`. Nothing is
|
|
60
61
|
cached. Each token lives 900 s, and the player kit asks again before it
|
|
@@ -72,6 +73,30 @@ end
|
|
|
72
73
|
is remembered. The library does the retries and the token refresh, so the
|
|
73
74
|
kit adds none of its own.
|
|
74
75
|
|
|
76
|
+
### The player's declared version
|
|
77
|
+
|
|
78
|
+
- A player kit sends its build's version to your token route as the
|
|
79
|
+
`Lingara-Embed-Version` header. `Lingara::Embed.embed_version_from(headers)`
|
|
80
|
+
reads it from a Rack `request.env` (`HTTP_LINGARA_EMBED_VERSION`) or a Hash
|
|
81
|
+
of header names, case-insensitively, and returns it trimmed; a missing or
|
|
82
|
+
blank header is `nil`, so the mint sends no `embed_version` key.
|
|
83
|
+
- Pass it as `mint_token(…, embed_version:)`. It is sent only when given, and
|
|
84
|
+
the kit does not validate it: Lingara is the authority.
|
|
85
|
+
- When that build is behind, deprecated or withdrawn, the mint answers
|
|
86
|
+
`minted.update_available` (the library's `Lingara::UpdateAvailable`), and
|
|
87
|
+
`token_handoff` forwards it as a third key,
|
|
88
|
+
`"update_available":{"latest":…,"deprecated":…,"message":…}`, for the
|
|
89
|
+
player kit to show. Without one the body is the two-key body.
|
|
90
|
+
- Lingara refuses three mints over the version. Each is a **developer**
|
|
91
|
+
condition: your route turns the `Lingara::ApiError` into its own error, and
|
|
92
|
+
the player kit then sees `TokenUnavailable`, as for any failed fetch.
|
|
93
|
+
- `409 embed_version_withdrawn`: a new player on a yanked build. Existing
|
|
94
|
+
players keep minting.
|
|
95
|
+
- `400 embed_version_unknown`: a well-formed version that is not one of this
|
|
96
|
+
embed's published versions.
|
|
97
|
+
- `400 invalid_request_body`: an `embed_version` that fails the version
|
|
98
|
+
grammar.
|
|
99
|
+
|
|
75
100
|
## 2. Route a webhook to its player
|
|
76
101
|
|
|
77
102
|
```ruby
|
data/lib/lingara/embed/server.rb
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
module Lingara
|
|
4
4
|
module Embed
|
|
5
|
+
# The header a player kit sends its build's version in (ADR 30.10.26p D1).
|
|
6
|
+
EMBED_VERSION_HEADER = "Lingara-Embed-Version"
|
|
7
|
+
# Rack's spelling of it in request.env.
|
|
8
|
+
EMBED_VERSION_RACK = "HTTP_LINGARA_EMBED_VERSION"
|
|
9
|
+
|
|
10
|
+
# The Lingara-Embed-Version header a player kit sends to your token
|
|
11
|
+
# route, trimmed (ADR 31.10.26f D1): pass it to Server#mint_token as
|
|
12
|
+
# +embed_version:+. +headers+ is what PlayerRouter#handle takes: a Rack
|
|
13
|
+
# request.env (HTTP_LINGARA_EMBED_VERSION) or a Hash of names to values,
|
|
14
|
+
# read case-insensitively. A missing or blank header is nil, so the mint
|
|
15
|
+
# sends no key. The value is not validated: Lingara is the authority.
|
|
16
|
+
def self.embed_version_from(headers)
|
|
17
|
+
headers.each do |key, value|
|
|
18
|
+
key = key.to_s
|
|
19
|
+
next unless key.casecmp?(EMBED_VERSION_HEADER) || key == EMBED_VERSION_RACK
|
|
20
|
+
value = (value.is_a?(Array) ? value.join(", ") : value.to_s).strip
|
|
21
|
+
return value.empty? ? nil : value
|
|
22
|
+
end
|
|
23
|
+
nil
|
|
24
|
+
end
|
|
25
|
+
|
|
5
26
|
# Mint and delete (ADR 1.10.26af D4, D9): one library call each, the
|
|
6
27
|
# directory written only after a success. There is no cache: every
|
|
7
28
|
# #mint_token is one POST, so a token #delete_player revoked on another
|
|
@@ -23,15 +44,18 @@ module Lingara
|
|
|
23
44
|
end
|
|
24
45
|
|
|
25
46
|
# Mints a token for one player: one POST /v1/embed/tokens, then
|
|
26
|
-
# directory.remember(player_ref, subject). +scopes
|
|
27
|
-
# sent only when given; +origin+ is your page's
|
|
28
|
-
# client's embed origins (a game's server mints
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
|
|
47
|
+
# directory.remember(player_ref, subject). +scopes+, +origin+ and
|
|
48
|
+
# +embed_version+ are sent only when given; +origin+ is your page's
|
|
49
|
+
# origin, one of your client's embed origins (a game's server mints
|
|
50
|
+
# without one), and +embed_version+ is the player build's declared
|
|
51
|
+
# version, read with Lingara::Embed.embed_version_from. Lingara answers
|
|
52
|
+
# an outdated one with the token's update_available. Returns the
|
|
53
|
+
# library's Lingara::MintedToken. On a failure nothing is remembered.
|
|
54
|
+
def mint_token(player_ref, scopes: nil, origin: nil, embed_version: nil)
|
|
32
55
|
body = {player_ref: player_ref}
|
|
33
56
|
body[:scopes] = scopes unless scopes.nil?
|
|
34
57
|
body[:origin] = origin unless origin.nil?
|
|
58
|
+
body[:embed_version] = embed_version unless embed_version.nil?
|
|
35
59
|
minted = @client.create_embed_token(**body).value
|
|
36
60
|
@directory&.remember(player_ref, minted.subject)
|
|
37
61
|
minted
|
|
@@ -6,24 +6,38 @@ module Lingara
|
|
|
6
6
|
module Embed
|
|
7
7
|
# The handoff body (ADR 1.10.26af D6, ES6): exactly
|
|
8
8
|
# {"token":"lgr_et_…","expires_at":"…"}, the shape every player kit and
|
|
9
|
-
# the widget read
|
|
9
|
+
# the widget read, plus "update_available" when the mint answered one
|
|
10
|
+
# (ADR 31.10.26f D1). This is the one place the kit exposes the token on
|
|
10
11
|
# purpose.
|
|
11
12
|
module TokenHandoff
|
|
12
13
|
module_function
|
|
13
14
|
|
|
14
15
|
# The JSON a token route returns for +minted+, a Lingara::MintedToken.
|
|
15
16
|
# The library holds expires_at as a Time, so it is written back as
|
|
16
|
-
# RFC 3339 in UTC; expires_in and subject are not forwarded.
|
|
17
|
+
# RFC 3339 in UTC; expires_in and subject are not forwarded. The
|
|
18
|
+
# mint's update_available, its notice that the player's declared build
|
|
19
|
+
# is behind, deprecated or withdrawn, is forwarded when there is one.
|
|
17
20
|
def from(minted)
|
|
18
|
-
body(minted.token.expose_secret, rfc3339(minted.expires_at))
|
|
21
|
+
body(minted.token.expose_secret, rfc3339(minted.expires_at), minted.update_available)
|
|
19
22
|
end
|
|
20
23
|
|
|
21
|
-
# The pure body
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
# The pure body, held to token-handoff.json: compact, "token",
|
|
25
|
+
# "expires_at" and, only when +update_available+ (a
|
|
26
|
+
# Lingara::UpdateAvailable) is given, "update_available", in this
|
|
27
|
+
# order; / and non-ASCII unescaped. Without a notice the body is
|
|
28
|
+
# exactly the two-key body. A String expires_at is copied byte for
|
|
29
|
+
# byte. Internal: integrators call Lingara::Embed.token_handoff.
|
|
30
|
+
def body(token, expires_at, update_available = nil)
|
|
31
|
+
fields = {"token" => token, "expires_at" => expires_at}
|
|
32
|
+
fields["update_available"] = notice(update_available) unless update_available.nil?
|
|
33
|
+
JSON.generate(fields)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# The notice from its typed value, never a raw Hash: "latest",
|
|
37
|
+
# "deprecated", "message", in this order, all three always written and
|
|
38
|
+
# a nil kept as JSON null.
|
|
39
|
+
def notice(update)
|
|
40
|
+
{"latest" => update.latest, "deprecated" => update.deprecated, "message" => update.message}
|
|
27
41
|
end
|
|
28
42
|
|
|
29
43
|
# +time+ in UTC with a Z, its fractional seconds only when non-zero:
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
module Lingara
|
|
6
6
|
module Embed
|
|
7
7
|
# This kit release, SemVer: the default elementSrc reads it.
|
|
8
|
-
VERSION = "0.2.0-alpha.
|
|
8
|
+
VERSION = "0.2.0-alpha.7"
|
|
9
9
|
|
|
10
10
|
# The same version in the RubyGems spelling the gemspec uses.
|
|
11
|
-
GEM_VERSION = "0.2.0.pre.alpha.
|
|
11
|
+
GEM_VERSION = "0.2.0.pre.alpha.7"
|
|
12
12
|
end
|
|
13
13
|
end
|
data/sig/lingara_embed.rbs
CHANGED
|
@@ -19,9 +19,16 @@ module Lingara
|
|
|
19
19
|
?nonce: String?, ?element_src: String?) -> String
|
|
20
20
|
def self.token_handoff: (untyped minted) -> String
|
|
21
21
|
|
|
22
|
+
EMBED_VERSION_HEADER: String
|
|
23
|
+
EMBED_VERSION_RACK: String
|
|
24
|
+
|
|
25
|
+
# A Rack env or a Hash of header names to values, as PlayerRouter#handle.
|
|
26
|
+
def self.embed_version_from: (Hash[untyped, untyped] headers) -> String?
|
|
27
|
+
|
|
22
28
|
class Server
|
|
23
29
|
def initialize: (untyped client, ?directory: _Directory?) -> void
|
|
24
|
-
def mint_token: (String player_ref, ?scopes: Array[String]?, ?origin: String
|
|
30
|
+
def mint_token: (String player_ref, ?scopes: Array[String]?, ?origin: String?,
|
|
31
|
+
?embed_version: String?) -> untyped
|
|
25
32
|
def delete_player: (String player_ref) -> nil
|
|
26
33
|
end
|
|
27
34
|
|
|
@@ -63,7 +70,9 @@ module Lingara
|
|
|
63
70
|
# Internal: integrators call Lingara::Embed.token_handoff.
|
|
64
71
|
module TokenHandoff
|
|
65
72
|
def self.from: (untyped minted) -> String
|
|
66
|
-
|
|
73
|
+
# +update_available+ is the library's Lingara::UpdateAvailable.
|
|
74
|
+
def self.body: (String token, String expires_at, ?untyped update_available) -> String
|
|
75
|
+
def self.notice: (untyped update) -> Hash[String, untyped]
|
|
67
76
|
def self.rfc3339: (Time | String time) -> String
|
|
68
77
|
end
|
|
69
78
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lingara-embed
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.0.pre.alpha.
|
|
4
|
+
version: 0.2.0.pre.alpha.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Spinning Cat Studios
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: lingara
|
|
@@ -16,7 +16,7 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 0.2.0.pre.alpha.
|
|
19
|
+
version: 0.2.0.pre.alpha.7
|
|
20
20
|
- - "<"
|
|
21
21
|
- !ruby/object:Gem::Version
|
|
22
22
|
version: '0.3'
|
|
@@ -26,7 +26,7 @@ dependencies:
|
|
|
26
26
|
requirements:
|
|
27
27
|
- - ">="
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: 0.2.0.pre.alpha.
|
|
29
|
+
version: 0.2.0.pre.alpha.7
|
|
30
30
|
- - "<"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
32
|
version: '0.3'
|