volcano-sdk 0.6.0 → 0.7.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: e1c358710803cb0542775a53699fda168e00aa0292d6fe0861287d4175373ecb
4
- data.tar.gz: a1e9f5146e6fd06d956ff7a505f391a72eef8b65cc3a4cf39ae4599a9e1346a5
3
+ metadata.gz: a36dee9d50b8138335752de5e3fdb5007ecd5dfa66547150190de691a048052d
4
+ data.tar.gz: 97edb400526abafd980ec19278304f80cff3ead5010d7704da7b55128390879e
5
5
  SHA512:
6
- metadata.gz: e5a1dd2cf0df583e5b02d954aeaaa9c63f4d122658605dbf78dac8a4d6f9fade33422742fc54c6f8dae6d22b4019d91aac73519beb2de83913bc4a27cfe160a9
7
- data.tar.gz: 6939426bd9514b8fe97c8e413c61c04acb1559efbcc33afbcf8e6102ac6b09aa96ecc7369859465b1b8f897ce4fe47d8d329ea4ea6fcdaf5aeaa7f52915e444e
6
+ metadata.gz: 5c3e7ed134b563780e8c1d64ba26f30f7ae9563d7c2ac219a265dabbf6aa04544600ef1a963abd09f9aa3f4efc2a6e32da0adeaf9a2a45905bd793daffd4101d
7
+ data.tar.gz: c2abfe5361e2ccff60f6f76a77aa4e2eedc0a033d1ef7649a63c5a6fa8f1edf0996c8141cc5eede6c08e5848e24fa8159e5a550b12edc5a32d16ea6dbf4311aa
data/README.md CHANGED
@@ -78,7 +78,10 @@ Snapshots contain deeply frozen JSON data. Plain `Time` timestamps become UTC
78
78
  ISO8601 strings with nanosecond precision; symbols become strings. Custom objects,
79
79
  container/string/time subclasses, non-finite numbers, duplicate JSON keys, and
80
80
  structures deeper than 100 levels raise `TypeError`. Use the typed `auth.user`
81
- profile when you need Ruby `Time` values.
81
+ profile when you need Ruby `Time` values. Successful `user`, `update_user`,
82
+ `convert_anonymous`, and `confirm_email_change` calls update this snapshot
83
+ without changing credentials or emitting an authentication-state event.
84
+ Previously returned sessions remain unchanged.
82
85
 
83
86
  ### Get the current user
84
87
 
@@ -89,8 +92,8 @@ raise "wrong user" unless user.id == session.user_id
89
92
 
90
93
  `user` sends the active access token to Volcano and returns an immutable,
91
94
  server-validated `Volcano::User`. The SDK recursively freezes its strings and
92
- metadata, but does not cache the profile or replace the session. A session
93
- change while the request is in flight raises
95
+ metadata and updates `current_session.user`. A session change while the request
96
+ is in flight raises
94
97
  `Volcano::Error::SessionChangedError` instead of returning a stale profile.
95
98
  `get_user` is available as a cross-SDK alias.
96
99
 
@@ -106,8 +109,8 @@ raise "wrong user" unless user.id == session.user_id
106
109
 
107
110
  `update_user` changes the current user's password, metadata, or both. Metadata
108
111
  is a shallow patch: omitted keys remain unchanged, and a `nil` value removes
109
- that key. The method returns an immutable `Volcano::User` without replacing the
110
- active session. It rejects a response if another authentication operation
112
+ that key. The method returns an immutable `Volcano::User` and updates the local
113
+ user snapshot. It rejects a response if another authentication operation
111
114
  replaces the session while the request is in flight.
112
115
 
113
116
  ### Request a password reset email
@@ -170,8 +173,8 @@ user = client.auth.confirm_email_change(token: "email-change-token")
170
173
  puts user.email
171
174
  ```
172
175
 
173
- The method returns the immutable updated user without replacing the active
174
- session. A successful stale response is rejected if another authentication
176
+ The method returns the immutable updated user and updates the local user
177
+ snapshot. A successful stale response is rejected if another authentication
175
178
  operation replaces that session in flight.
176
179
 
177
180
  ### List sessions
@@ -20,10 +20,7 @@ module Volcano
20
20
  anonymous_conversion_response(current.access_token, email, password, metadata),
21
21
  200
22
22
  )
23
- user = build_user(user_payload(payload))
24
- raise Error::SessionChangedError unless @client.capture_session.first == generation
25
-
26
- user
23
+ cache_current_user(payload, generation)
27
24
  end
28
25
 
29
26
  private
@@ -30,10 +30,7 @@ module Volcano
30
30
  raise Error::AuthenticationError, 'No active session' unless current
31
31
 
32
32
  payload = Transport.body(confirm_email_change_response(current.access_token, token), 200)
33
- user = build_user(user_payload(payload))
34
- raise Error::SessionChangedError unless @client.capture_session.first == generation
35
-
36
- user
33
+ cache_current_user(payload, generation)
37
34
  end
38
35
 
39
36
  private
@@ -19,16 +19,21 @@ module Volcano
19
19
  raise Error::AuthenticationError, 'No active session' unless current
20
20
 
21
21
  payload = Transport.body(get_user_response(current.access_token), 200)
22
- user = build_user(user_payload(payload))
23
- raise Error::SessionChangedError unless @client.capture_session.first == generation
24
-
25
- user
22
+ cache_current_user(payload, generation)
26
23
  end
27
24
 
28
25
  alias get_user user
29
26
 
30
27
  private
31
28
 
29
+ def cache_current_user(payload, generation)
30
+ profile = user_payload(payload)
31
+ user = build_user(profile)
32
+ raise Error::SessionChangedError unless @client.update_session_user_if_current?(profile, generation)
33
+
34
+ user
35
+ end
36
+
32
37
  def get_user_response(access_token)
33
38
  Transport.invoke do
34
39
  @transport.auth_get_user(authorization: access_token)
@@ -50,10 +50,9 @@ module Volcano
50
50
 
51
51
  def store_if_current?(session, generation, event: :signed_in, notifications: nil)
52
52
  dispatch = @mutex.synchronize do
53
- callbacks = replace_if_current(session, generation, event)
54
- return false unless callbacks
53
+ return false unless generation == @generation
55
54
 
56
- enqueue_notification(callbacks, event, session)
55
+ enqueue_notification(replace(session, event), event, session)
57
56
  end
58
57
  return true unless dispatch
59
58
 
@@ -61,6 +60,16 @@ module Volcano
61
60
  true
62
61
  end
63
62
 
63
+ def update_user_if_current?(user, generation)
64
+ @mutex.synchronize do
65
+ return false unless generation == @generation && @session
66
+ raise Error::AuthenticationError, 'Profile belongs to a different user' unless user['id'] == @session.user_id
67
+
68
+ @session = Session.new(**@session.to_h, user: user)
69
+ true
70
+ end
71
+ end
72
+
64
73
  def subscribe(&callback)
65
74
  callback_id, dispatch = @mutex.synchronize do
66
75
  id, current = register(callback)
@@ -79,12 +88,6 @@ module Volcano
79
88
  @callbacks.keys
80
89
  end
81
90
 
82
- def replace_if_current(session, generation, event)
83
- return unless generation == @generation
84
-
85
- replace(session, event)
86
- end
87
-
88
91
  def register(callback)
89
92
  callback_id = @next_callback_id
90
93
  @next_callback_id += 1
@@ -130,7 +133,7 @@ module Volcano
130
133
  def notify(callback_ids, event, session)
131
134
  failure = nil
132
135
  callback_ids.each do |callback_id|
133
- notify_callback(callback_id, event, session)
136
+ @mutex.synchronize { @callbacks[callback_id] }&.call(event, session)
134
137
  rescue StandardError => e
135
138
  Warning.warn("Volcano auth-state callback failed (#{e.class})\n")
136
139
  rescue *CALLBACK_FAILURES => e
@@ -139,10 +142,5 @@ module Volcano
139
142
  end
140
143
  failure
141
144
  end
142
-
143
- def notify_callback(callback_id, event, session)
144
- callback = @mutex.synchronize { @callbacks[callback_id] }
145
- callback&.call(event, session)
146
- end
147
145
  end
148
146
  end
@@ -11,10 +11,7 @@ module Volcano
11
11
  update_user_response(current.access_token, password:, metadata:),
12
12
  200
13
13
  )
14
- user = build_user(user_payload(payload))
15
- raise Error::SessionChangedError unless @client.capture_session.first == generation
16
-
17
- user
14
+ cache_current_user(payload, generation)
18
15
  end
19
16
 
20
17
  private
@@ -89,6 +89,10 @@ module Volcano
89
89
  @auth_state.subscribe(...)
90
90
  end
91
91
 
92
+ def update_session_user_if_current?(...)
93
+ @auth_state.update_user_if_current?(...)
94
+ end
95
+
92
96
  private
93
97
 
94
98
  def database_with_token(name, token)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Volcano
4
- VERSION = '0.6.0'
4
+ VERSION = '0.7.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: volcano-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kong