passageidentity 0.7.1 → 1.0.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.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openapi_client/api/magic_links_api.rb +1 -1
  3. data/lib/openapi_client/api/tokens_api.rb +1 -1
  4. data/lib/openapi_client/api/user_devices_api.rb +1 -1
  5. data/lib/openapi_client/api/users_api.rb +19 -19
  6. data/lib/openapi_client/api_client.rb +1 -1
  7. data/lib/openapi_client/api_error.rb +1 -1
  8. data/lib/openapi_client/configuration.rb +1 -1
  9. data/lib/openapi_client/models/apple_user_social_connection.rb +1 -1
  10. data/lib/openapi_client/models/create_magic_link_request.rb +22 -3
  11. data/lib/openapi_client/models/{create_user_request.rb → create_user_args.rb} +4 -4
  12. data/lib/openapi_client/models/github_user_social_connection.rb +1 -1
  13. data/lib/openapi_client/models/google_user_social_connection.rb +1 -1
  14. data/lib/openapi_client/models/link.rb +1 -1
  15. data/lib/openapi_client/models/list_devices_response.rb +1 -1
  16. data/lib/openapi_client/models/list_paginated_users_item.rb +1 -1
  17. data/lib/openapi_client/models/list_paginated_users_response.rb +1 -1
  18. data/lib/openapi_client/models/magic_link.rb +2 -1
  19. data/lib/openapi_client/models/magic_link_channel.rb +1 -1
  20. data/lib/openapi_client/models/{theme_type.rb → magic_link_language.rb} +12 -8
  21. data/lib/openapi_client/models/magic_link_response.rb +1 -1
  22. data/lib/openapi_client/models/magic_link_type.rb +1 -1
  23. data/lib/openapi_client/models/model400_error.rb +1 -1
  24. data/lib/openapi_client/models/model401_error.rb +1 -1
  25. data/lib/openapi_client/models/model403_error.rb +1 -1
  26. data/lib/openapi_client/models/model404_error.rb +1 -1
  27. data/lib/openapi_client/models/model500_error.rb +1 -1
  28. data/lib/openapi_client/models/nonce.rb +1 -1
  29. data/lib/openapi_client/models/paginated_links.rb +1 -1
  30. data/lib/openapi_client/models/{user_info.rb → passage_user.rb} +4 -4
  31. data/lib/openapi_client/models/social_connection_type.rb +1 -1
  32. data/lib/openapi_client/models/{update_user_request.rb → update_user_args.rb} +4 -4
  33. data/lib/openapi_client/models/user_event_action.rb +1 -1
  34. data/lib/openapi_client/models/user_event_status.rb +1 -1
  35. data/lib/openapi_client/models/user_recent_event.rb +1 -1
  36. data/lib/openapi_client/models/user_response.rb +2 -2
  37. data/lib/openapi_client/models/user_social_connections.rb +1 -1
  38. data/lib/openapi_client/models/user_status.rb +1 -1
  39. data/lib/openapi_client/models/web_authn_devices.rb +1 -1
  40. data/lib/openapi_client/models/web_authn_icons.rb +1 -1
  41. data/lib/openapi_client/models/web_authn_type.rb +1 -1
  42. data/lib/openapi_client/version.rb +1 -1
  43. data/lib/openapi_client.rb +5 -20
  44. data/lib/passageidentity/auth.rb +43 -156
  45. data/lib/passageidentity/client.rb +16 -96
  46. data/lib/passageidentity/user.rb +246 -0
  47. data/lib/passageidentity/version.rb +1 -1
  48. metadata +42 -40
  49. data/lib/models/update_magic_link_auth_method.rb +0 -276
  50. data/lib/models/update_otp_auth_method.rb +0 -276
  51. data/lib/models/update_passkeys_auth_method.rb +0 -216
  52. data/lib/openapi_client/api/apps_api.rb +0 -85
  53. data/lib/openapi_client/models/app_info.rb +0 -886
  54. data/lib/openapi_client/models/app_response.rb +0 -221
  55. data/lib/openapi_client/models/auth_methods.rb +0 -254
  56. data/lib/openapi_client/models/element_customization.rb +0 -457
  57. data/lib/openapi_client/models/font_family.rb +0 -58
  58. data/lib/openapi_client/models/layout_config.rb +0 -285
  59. data/lib/openapi_client/models/layouts.rb +0 -241
  60. data/lib/openapi_client/models/magic_link_auth_method.rb +0 -295
  61. data/lib/openapi_client/models/otp_auth_method.rb +0 -295
  62. data/lib/openapi_client/models/passkeys_auth_method.rb +0 -221
  63. data/lib/openapi_client/models/technologies.rb +0 -46
  64. data/lib/openapi_client/models/ttl_display_unit.rb +0 -42
  65. data/lib/openapi_client/models/user_metadata_field.rb +0 -323
  66. data/lib/openapi_client/models/user_metadata_field_type.rb +0 -44
  67. data/lib/passageidentity/user_api.rb +0 -218
@@ -0,0 +1,246 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../openapi_client'
4
+
5
+ module Passage
6
+ # The User class provides methods for interacting with Passage Users
7
+ class User
8
+ def initialize(app_id:, req_opts:)
9
+ @app_id = app_id
10
+ @req_opts = req_opts
11
+
12
+ @user_client = OpenapiClient::UsersApi.new
13
+ @user_device_client = OpenapiClient::UserDevicesApi.new
14
+ @tokens_client = OpenapiClient::TokensApi.new
15
+ end
16
+
17
+ def get(user_id:)
18
+ raise ArgumentError, 'user_id is required.' if blank_str?(user_id)
19
+
20
+ begin
21
+ response = @user_client.get_user(@app_id, user_id, @req_opts)
22
+ response.user
23
+ rescue OpenapiClient::ApiError => e
24
+ raise PassageError.new(
25
+ status_code: e.code,
26
+ body: try_parse_json_string(e.response_body)
27
+ )
28
+ rescue Faraday::Error => e
29
+ raise PassageError.new(
30
+ status_code: e.response[:status],
31
+ body: e.response[:body]
32
+ )
33
+ end
34
+ end
35
+
36
+ def get_by_identifier(identifier:)
37
+ raise ArgumentError, 'identifier is required.' if blank_str?(identifier)
38
+
39
+ begin
40
+ req_opts = set_get_by_identifier_query_params(identifier: identifier)
41
+ response = @user_client.list_paginated_users(@app_id, req_opts)
42
+ rescue OpenapiClient::ApiError => e
43
+ raise PassageError.new(
44
+ status_code: e.code,
45
+ body: try_parse_json_string(e.response_body)
46
+ )
47
+ rescue Faraday::Error => e
48
+ raise PassageError.new(
49
+ status_code: e.response[:status],
50
+ body: e.response[:body]
51
+ )
52
+ end
53
+
54
+ handle_get_by_identifier(users: response.users)
55
+ end
56
+
57
+ def activate(user_id:)
58
+ raise ArgumentError, 'user_id is required.' if blank_str?(user_id)
59
+
60
+ begin
61
+ response = @user_client.activate_user(@app_id, user_id, @req_opts)
62
+ response.user
63
+ rescue OpenapiClient::ApiError => e
64
+ raise PassageError.new(
65
+ status_code: e.code,
66
+ body: try_parse_json_string(e.response_body)
67
+ )
68
+ rescue Faraday::Error => e
69
+ raise PassageError.new(
70
+ status_code: e.response[:status],
71
+ body: e.response[:body]
72
+ )
73
+ end
74
+ end
75
+
76
+ def deactivate(user_id:)
77
+ raise ArgumentError, 'user_id is required.' if blank_str?(user_id)
78
+
79
+ begin
80
+ response = @user_client.deactivate_user(@app_id, user_id, @req_opts)
81
+ response.user
82
+ rescue OpenapiClient::ApiError => e
83
+ raise PassageError.new(
84
+ status_code: e.code,
85
+ body: try_parse_json_string(e.response_body)
86
+ )
87
+ rescue Faraday::Error => e
88
+ raise PassageError.new(
89
+ status_code: e.response[:status],
90
+ body: e.response[:body]
91
+ )
92
+ end
93
+ end
94
+
95
+ def update(user_id:, options:)
96
+ raise ArgumentError, 'user_id is required.' if blank_str?(user_id)
97
+ raise ArgumentError, 'options are required.' if options.empty?
98
+
99
+ begin
100
+ response = @user_client.update_user(@app_id, user_id, options, @req_opts)
101
+ response.user
102
+ rescue OpenapiClient::ApiError => e
103
+ raise PassageError.new(
104
+ status_code: e.code,
105
+ body: try_parse_json_string(e.response_body)
106
+ )
107
+ rescue Faraday::Error => e
108
+ raise PassageError.new(
109
+ status_code: e.response[:status],
110
+ body: e.response[:body]
111
+ )
112
+ end
113
+ end
114
+
115
+ def create(args:)
116
+ if blank_str?(args['email']) && blank_str?(args['phone'])
117
+ raise ArgumentError,
118
+ 'At least one of args.email or args.phone is required.'
119
+ end
120
+
121
+ begin
122
+ response = @user_client.create_user(@app_id, args, @req_opts)
123
+ response.user
124
+ rescue OpenapiClient::ApiError => e
125
+ raise PassageError.new(
126
+ status_code: e.code,
127
+ body: try_parse_json_string(e.response_body)
128
+ )
129
+ rescue Faraday::Error => e
130
+ raise PassageError.new(
131
+ status_code: e.response[:status],
132
+ body: e.response[:body]
133
+ )
134
+ end
135
+ end
136
+
137
+ def delete(user_id:)
138
+ raise ArgumentError, 'user_id is required.' if blank_str?(user_id)
139
+
140
+ begin
141
+ @user_client.delete_user(@app_id, user_id, @req_opts)
142
+ rescue OpenapiClient::ApiError => e
143
+ raise PassageError.new(
144
+ status_code: e.code,
145
+ body: try_parse_json_string(e.response_body)
146
+ )
147
+ rescue Faraday::Error => e
148
+ raise PassageError.new(
149
+ 'failed to delete Passage User',
150
+ status_code: e.response[:status],
151
+ body: e.response[:body]
152
+ )
153
+ end
154
+ end
155
+
156
+ def revoke_device(user_id:, device_id:)
157
+ raise ArgumentError, 'user_id is required.' if blank_str?(user_id)
158
+ raise ArgumentError, 'device_id is required.' if blank_str?(device_id)
159
+
160
+ begin
161
+ @user_device_client.delete_user_devices(@app_id, user_id, device_id, @req_opts)
162
+ rescue OpenapiClient::ApiError => e
163
+ raise PassageError.new(
164
+ status_code: e.code,
165
+ body: try_parse_json_string(e.response_body)
166
+ )
167
+ rescue Faraday::Error => e
168
+ raise PassageError.new(
169
+ status_code: e.response[:status],
170
+ body: e.response[:body]
171
+ )
172
+ end
173
+ end
174
+
175
+ def list_devices(user_id:)
176
+ raise ArgumentError, 'user_id is required.' if blank_str?(user_id)
177
+
178
+ begin
179
+ response = @user_device_client.list_user_devices(@app_id, user_id, @req_opts)
180
+ response.devices
181
+ rescue OpenapiClient::ApiError => e
182
+ raise PassageError.new(
183
+ status_code: e.code,
184
+ body: try_parse_json_string(e.response_body)
185
+ )
186
+ rescue Faraday::Error => e
187
+ raise PassageError.new(
188
+ status_code: e.response[:status],
189
+ body: e.response[:body]
190
+ )
191
+ end
192
+ end
193
+
194
+ def revoke_refresh_tokens(user_id:)
195
+ raise ArgumentError, 'user_id is required.' if blank_str?(user_id)
196
+
197
+ begin
198
+ @tokens_client.revoke_user_refresh_tokens(@app_id, user_id, @req_opts)
199
+ rescue OpenapiClient::ApiError => e
200
+ raise PassageError.new(
201
+ status_code: e.code,
202
+ body: try_parse_json_string(e.response_body)
203
+ )
204
+ rescue Faraday::Error => e
205
+ raise PassageError.new(
206
+ status_code: e.response[:status],
207
+ body: e.response[:body]
208
+ )
209
+ end
210
+ end
211
+
212
+ private
213
+
214
+ def blank_str?(str)
215
+ blank_pattern = /\A[[:space:]]*\z/
216
+ str.empty? || blank_pattern.match?(str)
217
+ end
218
+
219
+ def set_get_by_identifier_query_params(identifier:)
220
+ req_opts = @req_opts.dup
221
+ req_opts[:limit] = 1
222
+ req_opts[:identifier] = identifier.downcase
223
+ req_opts
224
+ end
225
+
226
+ def handle_get_by_identifier(users:)
227
+ if users.empty?
228
+ raise PassageError.new(
229
+ status_code: 404,
230
+ body: {
231
+ error: 'User not found.',
232
+ code: 'user_not_found'
233
+ }
234
+ )
235
+ end
236
+
237
+ get(user_id: users.first.id)
238
+ end
239
+
240
+ def try_parse_json_string(string)
241
+ JSON.parse(string)
242
+ rescue JSON::ParserError
243
+ string
244
+ end
245
+ end
246
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Passage
4
- VERSION = '0.7.1'
4
+ VERSION = '1.0.1'
5
5
  end
metadata CHANGED
@@ -1,75 +1,95 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passageidentity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Passage by 1Password
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-20 00:00:00.000000000 Z
11
+ date: 2025-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '7.2'
20
- - - ">="
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7.0'
22
+ version: '9'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - "~>"
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '7.2'
30
- - - ">="
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7.0'
32
+ version: '9'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: faraday
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 0.17.0
39
+ version: '2.12'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '2.0'
42
+ version: '3.0'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 0.17.0
49
+ version: '2.12'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '2.0'
52
+ version: '3.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: faraday-multipart
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.1'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 1.1.0
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.1'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 1.1.0
53
73
  - !ruby/object:Gem::Dependency
54
74
  name: jwt
55
75
  requirement: !ruby/object:Gem::Requirement
56
76
  requirements:
57
77
  - - "~>"
58
78
  - !ruby/object:Gem::Version
59
- version: '2.3'
79
+ version: '2.10'
60
80
  - - ">="
61
81
  - !ruby/object:Gem::Version
62
- version: 2.3.0
82
+ version: 2.10.1
63
83
  type: :runtime
64
84
  prerelease: false
65
85
  version_requirements: !ruby/object:Gem::Requirement
66
86
  requirements:
67
87
  - - "~>"
68
88
  - !ruby/object:Gem::Version
69
- version: '2.3'
89
+ version: '2.10'
70
90
  - - ">="
71
91
  - !ruby/object:Gem::Version
72
- version: 2.3.0
92
+ version: 2.10.1
73
93
  - !ruby/object:Gem::Dependency
74
94
  name: marcel
75
95
  requirement: !ruby/object:Gem::Requirement
@@ -97,11 +117,7 @@ executables: []
97
117
  extensions: []
98
118
  extra_rdoc_files: []
99
119
  files:
100
- - lib/models/update_magic_link_auth_method.rb
101
- - lib/models/update_otp_auth_method.rb
102
- - lib/models/update_passkeys_auth_method.rb
103
120
  - lib/openapi_client.rb
104
- - lib/openapi_client/api/apps_api.rb
105
121
  - lib/openapi_client/api/magic_links_api.rb
106
122
  - lib/openapi_client/api/tokens_api.rb
107
123
  - lib/openapi_client/api/user_devices_api.rb
@@ -109,25 +125,18 @@ files:
109
125
  - lib/openapi_client/api_client.rb
110
126
  - lib/openapi_client/api_error.rb
111
127
  - lib/openapi_client/configuration.rb
112
- - lib/openapi_client/models/app_info.rb
113
- - lib/openapi_client/models/app_response.rb
114
128
  - lib/openapi_client/models/apple_user_social_connection.rb
115
- - lib/openapi_client/models/auth_methods.rb
116
129
  - lib/openapi_client/models/create_magic_link_request.rb
117
- - lib/openapi_client/models/create_user_request.rb
118
- - lib/openapi_client/models/element_customization.rb
119
- - lib/openapi_client/models/font_family.rb
130
+ - lib/openapi_client/models/create_user_args.rb
120
131
  - lib/openapi_client/models/github_user_social_connection.rb
121
132
  - lib/openapi_client/models/google_user_social_connection.rb
122
- - lib/openapi_client/models/layout_config.rb
123
- - lib/openapi_client/models/layouts.rb
124
133
  - lib/openapi_client/models/link.rb
125
134
  - lib/openapi_client/models/list_devices_response.rb
126
135
  - lib/openapi_client/models/list_paginated_users_item.rb
127
136
  - lib/openapi_client/models/list_paginated_users_response.rb
128
137
  - lib/openapi_client/models/magic_link.rb
129
- - lib/openapi_client/models/magic_link_auth_method.rb
130
138
  - lib/openapi_client/models/magic_link_channel.rb
139
+ - lib/openapi_client/models/magic_link_language.rb
131
140
  - lib/openapi_client/models/magic_link_response.rb
132
141
  - lib/openapi_client/models/magic_link_type.rb
133
142
  - lib/openapi_client/models/model400_error.rb
@@ -136,19 +145,12 @@ files:
136
145
  - lib/openapi_client/models/model404_error.rb
137
146
  - lib/openapi_client/models/model500_error.rb
138
147
  - lib/openapi_client/models/nonce.rb
139
- - lib/openapi_client/models/otp_auth_method.rb
140
148
  - lib/openapi_client/models/paginated_links.rb
141
- - lib/openapi_client/models/passkeys_auth_method.rb
149
+ - lib/openapi_client/models/passage_user.rb
142
150
  - lib/openapi_client/models/social_connection_type.rb
143
- - lib/openapi_client/models/technologies.rb
144
- - lib/openapi_client/models/theme_type.rb
145
- - lib/openapi_client/models/ttl_display_unit.rb
146
- - lib/openapi_client/models/update_user_request.rb
151
+ - lib/openapi_client/models/update_user_args.rb
147
152
  - lib/openapi_client/models/user_event_action.rb
148
153
  - lib/openapi_client/models/user_event_status.rb
149
- - lib/openapi_client/models/user_info.rb
150
- - lib/openapi_client/models/user_metadata_field.rb
151
- - lib/openapi_client/models/user_metadata_field_type.rb
152
154
  - lib/openapi_client/models/user_recent_event.rb
153
155
  - lib/openapi_client/models/user_response.rb
154
156
  - lib/openapi_client/models/user_social_connections.rb
@@ -161,7 +163,7 @@ files:
161
163
  - lib/passageidentity/auth.rb
162
164
  - lib/passageidentity/client.rb
163
165
  - lib/passageidentity/error.rb
164
- - lib/passageidentity/user_api.rb
166
+ - lib/passageidentity/user.rb
165
167
  - lib/passageidentity/version.rb
166
168
  homepage: http://docs.passage.id/complete
167
169
  licenses:
@@ -177,7 +179,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
179
  requirements:
178
180
  - - ">="
179
181
  - !ruby/object:Gem::Version
180
- version: 3.1.3
182
+ version: 3.1.6
181
183
  required_rubygems_version: !ruby/object:Gem::Requirement
182
184
  requirements:
183
185
  - - ">="