usesmileid 12.1.0 → 13.1.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: 896bc049c137997c9de0181582b1bb2564e96fbba5bbbac64b640363e7f472b2
4
- data.tar.gz: 7f8bda781a38427a40550e95af93dc0286523b2b41e30a0cc37ef482b6752b8b
3
+ metadata.gz: 2abbefedec80a0a8a9ec33c54da9f4087ecc0db963a420478306d29b9d42554b
4
+ data.tar.gz: de2fa39a788afa69c0eafe263d79eb8b261b4d797977f5fca6a03f7f14589d7b
5
5
  SHA512:
6
- metadata.gz: e0e6772c8b7f6466b8807943dbda2cc72e8e52564ffe745faf9b9bc5cb2623dd43ecae662fab88974ecb98ae780fd713cacc11014bd23157e458b10c5709f17f
7
- data.tar.gz: 94a7ac44229e2d2e43c722a2113a72d589db9a8242ca5f4ec7b1febd7828f35841d15fe1183c713bd91468e45d569f1403a6f392d7f96b13d82e8f00a6ee7fc8
6
+ metadata.gz: 5edaeda6981ae5a1b5a285b60efee1a13ffd3be5d4dcf8e3a2ab90e6302827833182c133ceb3300132b9668d2605c5265bb62be40f23d6bce72b3fbabbe2963c
7
+ data.tar.gz: 7855b6f07f25c6ded0bcb7a3058756dbba9e7984db046238fcd5a99c6e283976a0a90fd9af11c3f04a11011017f20cbf0a5f97856d4e8c4642b461c4e16e446c
data/CHANGELOG.md CHANGED
@@ -7,6 +7,42 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [13.1.0] - 2026-11-19
11
+
12
+ ### Added
13
+
14
+ - One-Time AML: `aml.submit` (async, result on the callback URL) and `aml.submit_sync` (result returned inline, with an optional `idempotency_key:`). The inline result is a `OneTimeAmlResult` that also carries the `SmileID-Job-ID`, `Response-Signature` and `Response-Timestamp` response headers.
15
+ - AML Monitoring: `aml_monitoring.submit` and `aml_monitoring.news`, which reads the news articles for one person in a monitoring result.
16
+ - `countries` and `aliases` are sent as JSON multipart parts, as the AML endpoints require.
17
+
18
+ ### Fixed
19
+
20
+ - `aml_monitoring.news` now mints its token with the `aml` product claim, as the spec's `x-smile-token-product` requires. Each operation's product now comes from the generated operations table (`Operation#product`), and `Client::PRODUCT_BY_PATH` is derived from it.
21
+
22
+ ## [13.0.0] - 2026-11-09
23
+
24
+ Version 12.2.0 was never published. Its changes are in this release, which is a major version because it breaks the 12.1.0 API.
25
+
26
+ ### Breaking changes
27
+
28
+ - `biometric.authenticate` no longer takes `use_enrolled_image:`. Use `biometric_kyc.verify(use_enrolled_image: true, user_id: ...)` instead.
29
+ - `biometric.authenticate` now requires `selfie_image:` and `liveness_images:`. Pass both on every call.
30
+ - `SmileID::TokenManager` has been removed. The client now mints a token for each request, so you do not need to manage tokens.
31
+
32
+ ### Changed
33
+
34
+ - Each request mints its own token, bound to that request's `user_id` and product, instead of reusing one cached token. A 401 is no longer retried with a refreshed token.
35
+ - A `user_id` that is empty or padded with whitespace raises `ValidationError` before any request is sent.
36
+ - `biometric.authenticate` takes `selfie_image:` and `liveness_images:` as required keywords.
37
+
38
+ ### Added
39
+
40
+ - `biometric_kyc.verify(use_enrolled_image: true, user_id: ...)` verifies against the user's enrolled selfie; the grant is bound into the job's token and the selfie and liveness images may be omitted.
41
+
42
+ ### Removed
43
+
44
+ - `use_enrolled_image` from `biometric.authenticate`; selfie and liveness images are now always required.
45
+
10
46
  ## [12.1.0] - 2026-10-01
11
47
 
12
48
  ### Added
@@ -41,6 +77,8 @@ First public release.
41
77
  - Typed errors under `SmileID::Errors`, keyed on HTTP status.
42
78
  - Bank codes, supported ID types and supported documents lookups.
43
79
 
44
- [Unreleased]: https://github.com/smileidentity/smileid-sdk-ruby/compare/v12.1.0...HEAD
80
+ [Unreleased]: https://github.com/smileidentity/smileid-sdk-ruby/compare/v13.1.0...HEAD
81
+ [13.1.0]: https://github.com/smileidentity/smileid-sdk-ruby/compare/v13.0.0...v13.1.0
82
+ [13.0.0]: https://github.com/smileidentity/smileid-sdk-ruby/compare/v12.1.0...v13.0.0
45
83
  [12.1.0]: https://github.com/smileidentity/smileid-sdk-ruby/compare/v12.0.0...v12.1.0
46
84
  [12.0.0]: https://github.com/smileidentity/smileid-sdk-ruby/releases/tag/v12.0.0
data/README.md CHANGED
@@ -40,7 +40,7 @@ smile = SmileID::Client.new(
40
40
 
41
41
  Partner ids are displayed zero-padded (for example 002) but must be passed without leading zeros (2).
42
42
 
43
- Authentication is internal: the SDK fetches a short-lived token from the API, caches it until just before expiry, and refreshes it once automatically if a request returns 401. You never see or pass a token.
43
+ Authentication is internal: before each request the SDK fetches a short-lived token from the API. A job's token is bound to that job's product and, when the job names one, its user; other calls get a token with neither. A 401 raises `AuthenticationError` without a retry. You never see or pass a token.
44
44
 
45
45
  ### Environment selection
46
46
 
@@ -110,6 +110,42 @@ accepted.job_id # => "job_..."
110
110
  accepted.accepted? # => true
111
111
  ```
112
112
 
113
+ ### AML screening
114
+
115
+ One-Time AML screens a name against sanctions, PEP and adverse-media lists. `aml.submit` queues the screening and the result goes to your callback URL:
116
+
117
+ ```ruby
118
+ accepted = smile.aml.submit(
119
+ countries: ["NG", "KE"],
120
+ full_name: "John Doe",
121
+ user_details: user_details,
122
+ consent: consent,
123
+ callback_url: "https://example.com/callback" # optional if a default is configured
124
+ )
125
+ ```
126
+
127
+ `aml.submit_sync` takes the same arguments but returns the result in the response, so `callback_url` is optional. Pass an `idempotency_key:` (16 to 128 characters of `A-Z a-z 0-9 - _`) so a retry returns the original result instead of a second billed screening. A provider timeout raises `SmileID::Errors::SmileIDError` with `status_code` 408.
128
+
129
+ ```ruby
130
+ result = smile.aml.submit_sync(
131
+ countries: ["NG"], full_name: "John Doe",
132
+ user_details: user_details, consent: consent,
133
+ idempotency_key: "onboarding-8f14e45fceea167a"
134
+ )
135
+ result.status # => "clear", "block", "attention" or "error"
136
+ result.no_of_persons_found # => 0
137
+ result.job_id # from the SmileID-Job-ID header
138
+ ```
139
+
140
+ AML Monitoring enrols the person for ongoing screening. `aml_monitoring.submit` takes the same arguments (`full_name:` is optional with `search_existing_user: true` and a `user_id:`). `aml_monitoring.news` reads the news articles behind a person reference in a result:
141
+
142
+ ```ruby
143
+ smile.aml_monitoring.submit(countries: ["NG"], full_name: "Jane Doe",
144
+ user_details: user_details, consent: consent)
145
+ news = smile.aml_monitoring.news("a1b2c3d4e5", "ref_001", news_category: "financial_crime", page: 1, limit: 25)
146
+ news.news.first.title
147
+ ```
148
+
113
149
  ### Document verification
114
150
 
115
151
  ```ruby
@@ -177,6 +213,20 @@ accepted = smile.biometric_kyc.verify(
177
213
  )
178
214
  ```
179
215
 
216
+ To verify against a user's enrolled selfie instead of a fresh capture, set `use_enrolled_image: true` and pass the enrolled `user_id`; the selfie and liveness images may then be omitted.
217
+
218
+ ```ruby
219
+ accepted = smile.biometric_kyc.verify(
220
+ use_enrolled_image: true,
221
+ user_id: "user-42",
222
+ country: "NG",
223
+ id_type: "NIN",
224
+ id_number: "12345678901",
225
+ user_details: user_details,
226
+ consent: consent
227
+ )
228
+ ```
229
+
180
230
  ### Biometric enrollment
181
231
 
182
232
  ```ruby
@@ -192,7 +242,7 @@ accepted = smile.biometric.enroll(
192
242
 
193
243
  ### Biometric authentication
194
244
 
195
- `user_id` is required and must match an enrolled user. Images are required unless you set `use_enrolled_image: true`.
245
+ `user_id` is required and must match an enrolled user. The selfie and liveness images are always required.
196
246
 
197
247
  ```ruby
198
248
  accepted = smile.biometric.authenticate(
@@ -296,7 +346,7 @@ Every API failure raises a typed error under `SmileID::Errors`, keyed on the HTT
296
346
  | Error | Raised on |
297
347
  |---|---|
298
348
  | `InvalidRequestError` | 400, 415, and failed client-side validation (`ValidationError` subclass) |
299
- | `AuthenticationError` | 401 after one automatic token refresh |
349
+ | `AuthenticationError` | 401 |
300
350
  | `PaymentRequiredError` | 402 — insufficient wallet balance |
301
351
  | `PermissionError` | 403 |
302
352
  | `NotFoundError` | 404 (except `verifications.retrieve`, which returns a `not_found` status) |
@@ -7,6 +7,13 @@ module SmileID
7
7
  # The Smile ID client (spec section 2.1, 4). Construct once, then call
8
8
  # resource verbs, e.g. client.enhanced_kyc.verify(...).
9
9
  class Client
10
+ # Product claim by path, taken from the spec's x-smile-token-product via the
11
+ # generated operations table. Kept for compatibility; the client reads each
12
+ # operation's product directly.
13
+ PRODUCT_BY_PATH = Generated::Operations::OPS.values
14
+ .select(&:product)
15
+ .to_h { |op| [op.path, op.product] }.freeze
16
+
10
17
  attr_reader :config
11
18
 
12
19
  def initialize(partner_id:, api_key:, environment: :sandbox,
@@ -18,7 +25,6 @@ module SmileID
18
25
  base_url: base_url, timeout: timeout, max_retries: max_retries, http_client: http_client
19
26
  )
20
27
  @transport = Transport.new(@config)
21
- @token_manager = TokenManager.new(@config, @transport)
22
28
  end
23
29
 
24
30
  def enhanced_kyc
@@ -45,36 +51,37 @@ module SmileID
45
51
  @users ||= Resources::Users.new(self)
46
52
  end
47
53
 
54
+ def aml
55
+ @aml ||= Resources::Aml.new(self)
56
+ end
57
+
58
+ def aml_monitoring
59
+ @aml_monitoring ||= Resources::AmlMonitoring.new(self)
60
+ end
61
+
48
62
  def services
49
63
  @services ||= Resources::Services.new(self)
50
64
  end
51
65
 
52
- # Execute an operation end to end: build the request, attach auth and
53
- # telemetry, sign if configured, send it, refresh-on-401 once, and either
54
- # return the response or raise a typed error (spec section 2A, 7).
66
+ # Execute an operation end to end: mint its token, build the request, attach
67
+ # auth and telemetry, send it, and either return the response or raise a
68
+ # typed error (spec section 2A, 7). Every authenticated call mints its own
69
+ # token; retries of an idempotent call reuse it.
55
70
  #
56
71
  # @return [SmileID::Response] on a success status for the operation.
57
- def call(op_key, form: nil, path_params: {}, query: {}, user_id_header: nil, timeout: nil)
72
+ def call(op_key, form: nil, path_params: {}, query: {}, user_id_header: nil, timeout: nil,
73
+ use_enrolled_image: false, extra_headers: nil)
58
74
  op = Generated::Operations.fetch(op_key)
59
75
  url = @config.base_url + interpolate(op.path, path_params)
60
76
  content_type, body = serialize(op, form)
61
- refreshed = false
77
+ token = mint_token(op, form, user_id_header, use_enrolled_image, timeout) if op.authenticated
62
78
 
63
- loop do
64
- headers = build_headers(op, content_type, user_id_header)
65
- response = @transport.send_request(
66
- method: op.http_method, url: url, headers: headers, query: query || {},
67
- body: body, retryable: op.idempotent, timeout: timeout
68
- )
69
-
70
- if response.status == 401 && op.authenticated && !refreshed
71
- @token_manager.force_refresh
72
- refreshed = true
73
- next
74
- end
75
-
76
- return handle(op, response)
77
- end
79
+ headers = build_headers(op, content_type, user_id_header, token).merge(extra_headers || {})
80
+ response = @transport.send_request(
81
+ method: op.http_method, url: url, headers: headers, query: query || {},
82
+ body: body, retryable: op.idempotent, timeout: timeout
83
+ )
84
+ handle(op, response)
78
85
  end
79
86
 
80
87
  private
@@ -88,15 +95,86 @@ module SmileID
88
95
  Helpers::Multipart.build(form)
89
96
  end
90
97
 
91
- def build_headers(op, content_type, user_id_header)
98
+ def build_headers(op, content_type, user_id_header, token)
92
99
  headers = Telemetry.headers
93
100
  headers['Content-Type'] = content_type if content_type
94
- headers['SmileID-Token'] = @token_manager.token if op.authenticated
101
+ headers['SmileID-Token'] = token if token
95
102
  headers['SmileID-Partner-ID'] = @config.partner_id if op.partner_id_header
96
103
  headers['User-ID'] = user_id_header if user_id_header
97
104
  headers
98
105
  end
99
106
 
107
+ # The token is bound to this one request's user and product. A grant
108
+ # (use_enrolled_image) authorises a captureless job for one user, so it must
109
+ # never reach another call's token.
110
+ def mint_token(op, form, user_id_header, use_enrolled_image, timeout)
111
+ product = op.product
112
+ user_id = job_user_id(form, user_id_header) if product
113
+ if use_enrolled_image && user_id.nil?
114
+ raise Errors::ValidationError.new('user_id is required when use_enrolled_image is true')
115
+ end
116
+
117
+ claims = { 'user_id' => user_id, 'product' => product,
118
+ 'use_enrolled_image' => (true if use_enrolled_image) }.compact
119
+ request_token(claims, timeout)
120
+ end
121
+
122
+ def request_token(claims, timeout)
123
+ content_type, body = Helpers::Multipart.build(claims) unless claims.empty?
124
+ response = @transport.send_request(
125
+ method: :post,
126
+ url: "#{@config.base_url}/v3/token",
127
+ headers: token_headers(content_type),
128
+ body: body,
129
+ retryable: true,
130
+ timeout: timeout
131
+ )
132
+
133
+ unless response.status == 200
134
+ raise Errors.from_response(
135
+ status_code: response.status,
136
+ body: response.json,
137
+ raw_body: response.raw_body,
138
+ headers: response.headers
139
+ )
140
+ end
141
+
142
+ jwt = response.json && response.json['token']
143
+ if jwt.nil? || jwt.to_s.empty?
144
+ raise Errors::UnexpectedResponseError.new(
145
+ 'token endpoint returned no token',
146
+ status_code: response.status,
147
+ request_id: Errors.request_id_from(response.headers),
148
+ raw_body: response.raw_body
149
+ )
150
+ end
151
+
152
+ jwt
153
+ end
154
+
155
+ # The API trims the User-ID header but not the token's user_id claim, so a
156
+ # padded id would mint a token for a different user than the job names.
157
+ def job_user_id(form, user_id_header)
158
+ user_id = user_id_header.nil? ? form && form['user_id'] : user_id_header
159
+ return nil if user_id.nil?
160
+
161
+ text = user_id.to_s
162
+ if text.empty? || text != text.strip
163
+ raise Errors::ValidationError.new('user_id must not be empty or padded with whitespace')
164
+ end
165
+
166
+ user_id
167
+ end
168
+
169
+ def token_headers(content_type)
170
+ headers = Telemetry.headers.merge(
171
+ 'smileid-partner-id' => @config.partner_id,
172
+ 'smileid-api-key' => @config.api_key
173
+ )
174
+ headers['Content-Type'] = content_type if content_type
175
+ headers
176
+ end
177
+
100
178
  def handle(op, response)
101
179
  if op.success_statuses.include?(response.status)
102
180
  return response if response.json.is_a?(Hash)
@@ -29,6 +29,13 @@ module SmileID
29
29
  callback_url || @client.config.default_callback_url
30
30
  end
31
31
 
32
+ def require_images!(selfie_image, liveness_images, condition = nil)
33
+ return unless selfie_image.nil? || liveness_images.nil? || Array(liveness_images).empty?
34
+
35
+ message = ['selfie_image and liveness_images are required', condition].compact.join(' ')
36
+ raise Errors::ValidationError.new(message)
37
+ end
38
+
32
39
  def accepted(response)
33
40
  Generated::Models::AcceptedResponse.from(response.json)
34
41
  end
@@ -133,9 +140,24 @@ module SmileID
133
140
 
134
141
  # POST /v3/biometric_kyc
135
142
  class BiometricKyc < Base
136
- def verify(selfie_image:, liveness_images:, consent:, country:, id_type:, id_number:,
137
- user_details:, callback_url: nil, sandbox_result: nil,
143
+ # With use_enrolled_image: true the job verifies against user_id's enrolled
144
+ # selfie, so the images may be omitted. The grant is bound into this job's
145
+ # token, never sent in the body.
146
+ def verify(consent:, country:, id_type:, id_number:, user_details:,
147
+ selfie_image: nil, liveness_images: nil, use_enrolled_image: false,
148
+ callback_url: nil, sandbox_result: nil,
138
149
  partner_params: nil, metadata: nil, user_id: nil, timeout: nil)
150
+ unless [true, false].include?(use_enrolled_image)
151
+ raise Errors::ValidationError.new('use_enrolled_image must be true or false')
152
+ end
153
+
154
+ if use_enrolled_image
155
+ if user_id.to_s.strip.empty?
156
+ raise Errors::ValidationError.new('user_id is required when use_enrolled_image is true')
157
+ end
158
+ else
159
+ require_images!(selfie_image, liveness_images, 'unless use_enrolled_image is true')
160
+ end
139
161
  form = {
140
162
  'country' => country,
141
163
  'id_type' => id_type,
@@ -149,7 +171,8 @@ module SmileID
149
171
  'partner_params' => partner_params,
150
172
  'metadata' => metadata
151
173
  }.compact
152
- accepted(@client.call(:biometric_kyc, form: form, user_id_header: user_id, timeout: timeout))
174
+ accepted(@client.call(:biometric_kyc, form: form, user_id_header: user_id, timeout: timeout,
175
+ use_enrolled_image: use_enrolled_image))
153
176
  end
154
177
  end
155
178
 
@@ -173,17 +196,16 @@ module SmileID
173
196
  end
174
197
 
175
198
  # user_id goes in the BODY here (required), not the User-ID header.
176
- def authenticate(user_id:, consent:, user_details:, selfie_image: nil, liveness_images: nil,
177
- use_enrolled_image: nil, callback_url: nil, sandbox_result: nil,
199
+ def authenticate(user_id:, consent:, user_details:, selfie_image:, liveness_images:,
200
+ callback_url: nil, sandbox_result: nil,
178
201
  partner_params: nil, metadata: nil, timeout: nil)
179
- require_images!(use_enrolled_image, selfie_image, liveness_images)
202
+ require_images!(selfie_image, liveness_images)
180
203
  form = {
181
204
  'user_id' => user_id,
182
205
  'selfie_image' => selfie_image,
183
206
  'liveness_images' => liveness_images,
184
207
  'user_details' => coerce_user_details(user_details),
185
208
  'consent' => coerce_consent(consent),
186
- 'use_enrolled_image' => use_enrolled_image,
187
209
  'callback_url' => resolve_callback(callback_url),
188
210
  'sandbox_result' => sandbox_result,
189
211
  'partner_params' => partner_params,
@@ -212,16 +234,109 @@ module SmileID
212
234
  }.compact
213
235
  accepted(@client.call(:compare, form: form, timeout: timeout))
214
236
  end
237
+ end
238
+
239
+ # POST /v3/aml and /v3/aml/sync
240
+ class Aml < Base
241
+ # Queues a One-Time AML screening. The result arrives on callback_url.
242
+ def submit(countries:, full_name:, user_details:, consent:, birth_year: nil,
243
+ strict_match: nil, aliases: nil, search_existing_user: nil,
244
+ callback_url: nil, partner_params: nil, metadata: nil, user_id: nil, timeout: nil)
245
+ form = aml_form(
246
+ countries: countries, full_name: full_name, user_details: user_details,
247
+ consent: consent, birth_year: birth_year, strict_match: strict_match,
248
+ aliases: aliases, search_existing_user: search_existing_user,
249
+ callback_url: resolve_callback(callback_url), partner_params: partner_params,
250
+ metadata: metadata, user_id: user_id
251
+ )
252
+ accepted(@client.call(:one_time_aml, form: form, user_id_header: user_id, timeout: timeout))
253
+ end
254
+
255
+ # Runs the same screening and returns the terminal result in the response.
256
+ # callback_url is optional: no callback is sent, but a given one is kept
257
+ # for replay. Send the same idempotency_key on a retry to get the original
258
+ # result instead of a second, billed screening. A provider timeout raises
259
+ # SmileIDError with status_code 408; nothing is billed.
260
+ def submit_sync(countries:, full_name:, user_details:, consent:, birth_year: nil,
261
+ strict_match: nil, aliases: nil, search_existing_user: nil,
262
+ callback_url: nil, partner_params: nil, metadata: nil, user_id: nil,
263
+ idempotency_key: nil, timeout: nil)
264
+ Config.validate_callback_url!(callback_url) if callback_url
265
+ form = aml_form(
266
+ countries: countries, full_name: full_name, user_details: user_details,
267
+ consent: consent, birth_year: birth_year, strict_match: strict_match,
268
+ aliases: aliases, search_existing_user: search_existing_user,
269
+ callback_url: callback_url, partner_params: partner_params,
270
+ metadata: metadata, user_id: user_id
271
+ )
272
+ extra_headers = idempotency_key ? { 'SmileID-Idempotency-Key' => idempotency_key } : nil
273
+ response = @client.call(:one_time_aml_sync, form: form, user_id_header: user_id,
274
+ timeout: timeout, extra_headers: extra_headers)
275
+ Generated::Models::OneTimeAmlResult.from(response.json, response.headers)
276
+ end
215
277
 
216
278
  private
217
279
 
218
- def require_images!(use_enrolled_image, selfie_image, liveness_images)
219
- return if use_enrolled_image == true
220
- return unless selfie_image.nil? || liveness_images.nil? || Array(liveness_images).empty?
280
+ def aml_form(countries:, full_name:, user_details:, consent:, birth_year:, strict_match:,
281
+ aliases:, search_existing_user:, callback_url:, partner_params:, metadata:, user_id:)
282
+ {
283
+ 'countries' => countries,
284
+ 'full_name' => full_name,
285
+ 'birth_year' => birth_year,
286
+ 'strict_match' => strict_match,
287
+ 'aliases' => aliases,
288
+ 'search_existing_user' => search_existing_user,
289
+ 'user_id' => user_id,
290
+ 'user_details' => coerce_user_details(user_details),
291
+ 'consent' => coerce_consent(consent),
292
+ 'callback_url' => callback_url,
293
+ 'partner_params' => partner_params,
294
+ 'metadata' => metadata
295
+ }.compact
296
+ end
297
+ end
221
298
 
222
- raise Errors::ValidationError.new(
223
- 'selfie_image and liveness_images are required unless use_enrolled_image is true'
224
- )
299
+ # POST /v3/aml/monitoring and GET /v3/aml/monitoring/{job_id}/news/{reference}
300
+ class AmlMonitoring < Base
301
+ NEWS_CATEGORIES = %w[
302
+ arms_trafficking credit_update environmental_crime financial_crime
303
+ human_rights_violation leadership_change legal_risk location_change narcotics
304
+ other other_crime ownership_change product_change regulatory sexual_crime
305
+ technology_event terrorism violent_crime
306
+ ].freeze
307
+
308
+ # full_name is required unless search_existing_user is true, which takes
309
+ # the name from the user's earlier KYC record and needs user_id.
310
+ def submit(countries:, user_details:, consent:, full_name: nil, birth_year: nil,
311
+ strict_match: nil, aliases: nil, search_existing_user: nil,
312
+ callback_url: nil, partner_params: nil, metadata: nil, user_id: nil, timeout: nil)
313
+ form = {
314
+ 'countries' => countries,
315
+ 'full_name' => full_name,
316
+ 'birth_year' => birth_year,
317
+ 'strict_match' => strict_match,
318
+ 'aliases' => aliases,
319
+ 'search_existing_user' => search_existing_user,
320
+ 'user_id' => user_id,
321
+ 'user_details' => coerce_user_details(user_details),
322
+ 'consent' => coerce_consent(consent),
323
+ 'callback_url' => resolve_callback(callback_url),
324
+ 'partner_params' => partner_params,
325
+ 'metadata' => metadata
326
+ }.compact
327
+ accepted(@client.call(:aml_monitoring, form: form, user_id_header: user_id, timeout: timeout))
328
+ end
329
+
330
+ def news(job_id, reference, news_category:, page: nil, limit: nil, timeout: nil)
331
+ unless NEWS_CATEGORIES.include?(news_category.to_s)
332
+ raise Errors::ValidationError.new("news_category must be one of #{NEWS_CATEGORIES.join(', ')}")
333
+ end
334
+
335
+ query = { 'news_category' => news_category, 'page' => page, 'limit' => limit }.compact
336
+ response = @client.call(:aml_monitoring_news,
337
+ path_params: { 'job_id' => job_id, 'reference' => reference },
338
+ query: query, timeout: timeout)
339
+ Generated::Models::AmlMonitoringNewsResponse.from(response.json)
225
340
  end
226
341
  end
227
342
 
@@ -36,7 +36,7 @@ module SmileID
36
36
  # The single HTTP transport (spec section 2.2, 2.6). Builds the Faraday
37
37
  # request, sends it, retries idempotent operations on transient failures
38
38
  # honouring Retry-After, and normalizes the response. It does not touch auth;
39
- # the client injects tokens and handles the refresh-on-401 dance.
39
+ # the client mints and injects tokens.
40
40
  class Transport
41
41
  RETRY_STATUSES = [408, 429, 500, 502, 503, 504].freeze
42
42
  BACKOFF_BASE = 0.5
@@ -39,7 +39,7 @@ module SmileID
39
39
  # Raised before send when a local validation rule fails (spec section 5.1, 6.11).
40
40
  class ValidationError < InvalidRequestError; end
41
41
 
42
- # 401 — token missing, invalid, or expired after a single refresh attempt.
42
+ # 401 — token missing, invalid or expired.
43
43
  class AuthenticationError < SmileIDError; end
44
44
 
45
45
  # 402 — insufficient wallet balance.
@@ -107,6 +107,85 @@ module SmileID
107
107
  end
108
108
  end
109
109
 
110
+ # Result of a One-Time AML screening: the body of POST /v3/aml/sync, which
111
+ # is the payload the async callback would have delivered. `status` is
112
+ # `clear`, `block`, `attention` or `error`. The response headers are kept
113
+ # alongside the body: the job and user ids, and the signature and
114
+ # timestamp that webhook verification code can check unchanged.
115
+ class OneTimeAmlResult
116
+ attr_reader :status, :message, :reason, :created_at, :completed_at, :product,
117
+ :partner_params, :kyc_receipt, :strict_match, :no_of_persons_found,
118
+ :people, :user_provided_info, :consent, :antifraud, :device_signals,
119
+ :job_id, :user_id, :response_signature, :response_timestamp, :raw
120
+
121
+ def initialize(hash, headers = {})
122
+ @status = hash['status']
123
+ @message = hash['message']
124
+ @reason = hash['reason']
125
+ @created_at = hash['created_at']
126
+ @completed_at = hash['completed_at']
127
+ @product = hash['product']
128
+ @partner_params = hash['partner_params']
129
+ @kyc_receipt = hash['kyc_receipt']
130
+ @strict_match = hash['strict_match']
131
+ @no_of_persons_found = hash['no_of_persons_found']
132
+ @people = hash['people'] || []
133
+ @user_provided_info = hash['user_provided_info']
134
+ @consent = hash['consent']
135
+ @antifraud = hash['antifraud']
136
+ @device_signals = hash['device_signals']
137
+ @job_id = headers['smileid-job-id']
138
+ @user_id = headers['user-id']
139
+ @response_signature = headers['response-signature']
140
+ @response_timestamp = headers['response-timestamp']
141
+ @raw = hash
142
+ end
143
+
144
+ def self.from(hash, headers = {})
145
+ new(hash, headers)
146
+ end
147
+ end
148
+
149
+ # One article in an AML Monitoring news response.
150
+ class AmlMonitoringNewsItem
151
+ attr_reader :body, :published_date, :publisher, :publisher_country_code,
152
+ :title, :url, :raw
153
+
154
+ def initialize(hash)
155
+ @body = hash['body']
156
+ @published_date = hash['published_date']
157
+ @publisher = hash['publisher']
158
+ @publisher_country_code = hash['publisher_country_code']
159
+ @title = hash['title']
160
+ @url = hash['url']
161
+ @raw = hash
162
+ end
163
+
164
+ def self.from(hash)
165
+ new(hash)
166
+ end
167
+ end
168
+
169
+ # Response from GET /v3/aml/monitoring/{job_id}/news/{reference}. `meta`
170
+ # is a plain hash with string keys (`current_page`, `limit`,
171
+ # `total_count`); `news` holds AmlMonitoringNewsItem objects.
172
+ class AmlMonitoringNewsResponse
173
+ attr_reader :job_id, :product, :user_id, :meta, :news, :raw
174
+
175
+ def initialize(hash)
176
+ @job_id = hash['job_id']
177
+ @product = hash['product']
178
+ @user_id = hash['user_id']
179
+ @meta = hash['meta']
180
+ @news = (hash['news'] || []).map { |item| AmlMonitoringNewsItem.from(item) }
181
+ @raw = hash
182
+ end
183
+
184
+ def self.from(hash)
185
+ new(hash)
186
+ end
187
+ end
188
+
110
189
  # Service responses (spec section 5.2). Nested collections are exposed as
111
190
  # plain hashes with string keys, exactly as they arrive on the wire.
112
191
  class BankCodesResponse
@@ -14,6 +14,7 @@ module SmileID
14
14
  :body_kind, # :multipart / :json / nil
15
15
  :idempotent, # safe to auto-retry? (GETs + token only)
16
16
  :success_statuses, # statuses treated as success (not raised)
17
+ :product, # x-smile-token-product: the token's product claim, nil for none
17
18
  keyword_init: true
18
19
  )
19
20
 
@@ -21,42 +22,74 @@ module SmileID
21
22
  enhanced_kyc: Operation.new(
22
23
  http_method: :post, path: '/v3/enhanced_kyc', authenticated: true,
23
24
  partner_id_header: false, body_kind: :multipart, idempotent: false,
24
- success_statuses: [202]
25
+ success_statuses: [202],
26
+ product: 'enhanced_kyc'
25
27
  ),
26
28
  document_verification: Operation.new(
27
29
  http_method: :post, path: '/v3/document_verification', authenticated: true,
28
30
  partner_id_header: true, body_kind: :multipart, idempotent: false,
29
- success_statuses: [202]
31
+ success_statuses: [202],
32
+ product: 'document_verification'
30
33
  ),
31
34
  enhanced_document_verification: Operation.new(
32
35
  http_method: :post, path: '/v3/enhanced_document_verification', authenticated: true,
33
36
  partner_id_header: true, body_kind: :multipart, idempotent: false,
34
- success_statuses: [202]
37
+ success_statuses: [202],
38
+ product: 'enhanced_document_verification'
35
39
  ),
36
40
  residency_document_verification: Operation.new(
37
41
  http_method: :post, path: '/v3/residency_document_verification', authenticated: true,
38
42
  partner_id_header: true, body_kind: :multipart, idempotent: false,
39
- success_statuses: [202]
43
+ success_statuses: [202],
44
+ product: 'residency_document_verification'
40
45
  ),
41
46
  biometric_kyc: Operation.new(
42
47
  http_method: :post, path: '/v3/biometric_kyc', authenticated: true,
43
48
  partner_id_header: true, body_kind: :multipart, idempotent: false,
44
- success_statuses: [202]
49
+ success_statuses: [202],
50
+ product: 'biometric_kyc'
45
51
  ),
46
52
  registration: Operation.new(
47
53
  http_method: :post, path: '/v3/registration', authenticated: true,
48
54
  partner_id_header: false, body_kind: :multipart, idempotent: false,
49
- success_statuses: [202]
55
+ success_statuses: [202],
56
+ product: 'smart_selfie_registration'
50
57
  ),
51
58
  authentication: Operation.new(
52
59
  http_method: :post, path: '/v3/authentication', authenticated: true,
53
60
  partner_id_header: false, body_kind: :multipart, idempotent: false,
54
- success_statuses: [202]
61
+ success_statuses: [202],
62
+ product: 'smart_selfie_authentication'
55
63
  ),
56
64
  compare: Operation.new(
57
65
  http_method: :post, path: '/v3/compare', authenticated: true,
58
66
  partner_id_header: false, body_kind: :multipart, idempotent: false,
59
- success_statuses: [202]
67
+ success_statuses: [202],
68
+ product: 'smart_selfie_compare'
69
+ ),
70
+ one_time_aml: Operation.new(
71
+ http_method: :post, path: '/v3/aml', authenticated: true,
72
+ partner_id_header: false, body_kind: :multipart, idempotent: false,
73
+ success_statuses: [202],
74
+ product: 'one_time_aml'
75
+ ),
76
+ one_time_aml_sync: Operation.new(
77
+ http_method: :post, path: '/v3/aml/sync', authenticated: true,
78
+ partner_id_header: false, body_kind: :multipart, idempotent: false,
79
+ success_statuses: [200],
80
+ product: 'one_time_aml'
81
+ ),
82
+ aml_monitoring: Operation.new(
83
+ http_method: :post, path: '/v3/aml/monitoring', authenticated: true,
84
+ partner_id_header: false, body_kind: :multipart, idempotent: false,
85
+ success_statuses: [202],
86
+ product: 'aml'
87
+ ),
88
+ aml_monitoring_news: Operation.new(
89
+ http_method: :get, path: '/v3/aml/monitoring/{job_id}/news/{reference}',
90
+ authenticated: true, partner_id_header: false, body_kind: nil, idempotent: true,
91
+ success_statuses: [200],
92
+ product: 'aml'
60
93
  ),
61
94
  status: Operation.new(
62
95
  http_method: :get, path: '/v3/status/{job_id}', authenticated: true,
@@ -19,7 +19,7 @@ module SmileID
19
19
  # item 4, the OpenAPI-Generator bug to avoid).
20
20
  module Multipart
21
21
  # Fields serialized as JSON parts.
22
- JSON_PART_FIELDS = %w[consent user_details partner_params metadata].freeze
22
+ JSON_PART_FIELDS = %w[consent user_details partner_params metadata countries aliases].freeze
23
23
  # Single binary fields.
24
24
  BINARY_FIELDS = %w[selfie_image document document_back visa comparison_image].freeze
25
25
  # Repeated binary fields.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SmileID
4
- VERSION = '12.1.0'
4
+ VERSION = '13.1.0'
5
5
  end
data/lib/usesmileid.rb CHANGED
@@ -9,7 +9,6 @@ require 'usesmileid/helpers/user_details'
9
9
  require 'usesmileid/helpers/multipart'
10
10
  require 'usesmileid/client/config'
11
11
  require 'usesmileid/client/transport'
12
- require 'usesmileid/client/auth'
13
12
  require 'usesmileid/client/resources'
14
13
  require 'usesmileid/client/client'
15
14
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usesmileid
3
3
  version: !ruby/object:Gem::Version
4
- version: 12.1.0
4
+ version: 13.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Smile Identity
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-10-01 00:00:00.000000000 Z
11
+ date: 2026-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -49,7 +49,6 @@ files:
49
49
  - LICENSE
50
50
  - README.md
51
51
  - lib/usesmileid.rb
52
- - lib/usesmileid/client/auth.rb
53
52
  - lib/usesmileid/client/client.rb
54
53
  - lib/usesmileid/client/config.rb
55
54
  - lib/usesmileid/client/resources.rb
@@ -83,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
82
  - !ruby/object:Gem::Version
84
83
  version: '0'
85
84
  requirements: []
86
- rubygems_version: 3.4.10
85
+ rubygems_version: 3.4.19
87
86
  signing_key:
88
87
  specification_version: 4
89
88
  summary: Official Smile ID server-side SDK for Ruby.
@@ -1,98 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'base64'
4
- require 'json'
5
-
6
- module SmileID
7
- # Internal JWT lifecycle (spec section 2.3, 2A). Partners never see the token.
8
- #
9
- # The cache is thread-safe: concurrent calls do not stampede the token
10
- # endpoint. The token is cached until its JWT `exp` claim minus a 60s skew; a
11
- # token whose expiry cannot be decoded is treated as single-use (refreshed on
12
- # the next call, and always on a 401).
13
- class TokenManager
14
- EXPIRY_SKEW = 60
15
-
16
- def initialize(config, transport)
17
- @config = config
18
- @transport = transport
19
- @mutex = Mutex.new
20
- @cached = nil
21
- end
22
-
23
- # Return a valid token, fetching one if the cache is empty or expired.
24
- def token
25
- @mutex.synchronize do
26
- return @cached[:jwt] if valid?
27
-
28
- fetch
29
- end
30
- end
31
-
32
- # Force a refresh (used after a 401). Fetches a new token unconditionally.
33
- def force_refresh
34
- @mutex.synchronize do
35
- @cached = nil
36
- fetch
37
- end
38
- end
39
-
40
- private
41
-
42
- def valid?
43
- @cached && Time.now < @cached[:expires_at]
44
- end
45
-
46
- def fetch
47
- response = @transport.send_request(
48
- method: :post,
49
- url: "#{@config.base_url}/v3/token",
50
- headers: Telemetry.headers.merge(
51
- 'smileid-partner-id' => @config.partner_id,
52
- 'smileid-api-key' => @config.api_key
53
- ),
54
- query: {},
55
- body: nil,
56
- retryable: true
57
- )
58
-
59
- unless response.status == 200
60
- raise Errors.from_response(
61
- status_code: response.status,
62
- body: response.json,
63
- raw_body: response.raw_body,
64
- headers: response.headers
65
- )
66
- end
67
-
68
- jwt = response.json && response.json['token']
69
- raise Errors::AuthenticationError.new('token endpoint returned no token') if jwt.nil?
70
-
71
- @cached = { jwt: jwt, expires_at: expires_at(jwt) }
72
- jwt
73
- end
74
-
75
- def expires_at(jwt)
76
- exp = decode_exp(jwt)
77
- exp ? Time.at(exp) - EXPIRY_SKEW : Time.now
78
- end
79
-
80
- # Decode the `exp` claim from a JWT without verifying the signature. Returns
81
- # nil when the token cannot be decoded.
82
- def decode_exp(jwt)
83
- payload_segment = jwt.to_s.split('.')[1]
84
- return nil if payload_segment.nil?
85
-
86
- payload = JSON.parse(Base64.urlsafe_decode64(pad(payload_segment)))
87
- exp = payload['exp']
88
- exp.is_a?(Numeric) ? exp : nil
89
- rescue ArgumentError, JSON::ParserError
90
- nil
91
- end
92
-
93
- def pad(segment)
94
- remainder = segment.length % 4
95
- remainder.zero? ? segment : segment + ('=' * (4 - remainder))
96
- end
97
- end
98
- end