lingara-embed 0.2.0.pre.alpha.6 → 0.3.0.pre.alpha.1

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: f21531bddcdd01d0db583c68da5372358441b0ac7ba308f9ffdf6b9546912953
4
- data.tar.gz: d847ce7d6a3c729009b70a9bd7b67cee87d39a14a65e5cd4788f830cfbb3c793
3
+ metadata.gz: 72d85912b9068fbb3b1298c7cea8e6a17c95878569acca5b5d3bc39a90e2ef59
4
+ data.tar.gz: c26e41090fec2cec95fc625a3f6432857410c953631460de70f55e8d5f00041a
5
5
  SHA512:
6
- metadata.gz: 9c6363aa9326665abd8d1d9475e2a47bbaf813d87b278e3c9d2ad29a7b54aefaa3ea416b5755db172fe48f408e78d9bcd1232635935f9528fd7895b4b69a2a52
7
- data.tar.gz: 71beba2292363f83543de65990319745de09f6973bb9b7fadb2add67e004f7668dc24cbcaaf44c71ab80a269e3882abe56add487afc699a15002601ea6f1c5bf
6
+ metadata.gz: 9ef2d691878ec5037651b49938ff464ce44bab4e7a2ef6317d349b0d84e39b2de7a4bb3b2ddb5ff003cbc6fb1ac81ecac287a19d959e7e891eb6ce3e447064c8
7
+ data.tar.gz: d50dcaac98542a592e299250a0dff4a3e5f747852963ce269cbd339b81b311e8541e0d5a009d7f92c898970d2cc43636b17f0a2ea465b0484c64576d2abae128
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
@@ -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+ and +origin+ are
27
- # sent only when given; +origin+ is your page's origin, one of your
28
- # client's embed origins (a game's server mints without one). Returns
29
- # the library's Lingara::MintedToken. On a failure nothing is
30
- # remembered.
31
- def mint_token(player_ref, scopes: nil, origin: nil)
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. This is the one place the kit exposes the token on
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 over two strings, held to token-handoff.json: compact,
22
- # these two keys in this order, / and non-ASCII unescaped. A String
23
- # expires_at is copied byte for byte. Internal: integrators call
24
- # Lingara::Embed.token_handoff.
25
- def body(token, expires_at)
26
- JSON.generate({"token" => token, "expires_at" => expires_at})
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.6"
8
+ VERSION = "0.3.0-alpha.1"
9
9
 
10
10
  # The same version in the RubyGems spelling the gemspec uses.
11
- GEM_VERSION = "0.2.0.pre.alpha.6"
11
+ GEM_VERSION = "0.3.0.pre.alpha.1"
12
12
  end
13
13
  end
@@ -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?) -> untyped
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
- def self.body: (String token, String expires_at) -> String
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.6
4
+ version: 0.3.0.pre.alpha.1
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-10-31 00:00:00.000000000 Z
11
+ date: 2026-11-04 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.6
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.6
29
+ version: 0.2.0.pre.alpha.7
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '0.3'