verify_it 0.4.0.beta → 0.4.2

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: ccaee3a9738dcd530a9afc7015401a5e13151f19b6e26e76dbf02d88b38294bd
4
- data.tar.gz: 423c5f4b1354fd994be521a72303c6f61435263b5f71477177b0bbd68c9a89a4
3
+ metadata.gz: '0638bdc85958eb337d3239d426d9b68a640d1130614406711dad37c1da11c7a2'
4
+ data.tar.gz: 7c40e0432c8e2627c26cbfac91b32f13358fa13a476cb22bc922d3fa1d5db897
5
5
  SHA512:
6
- metadata.gz: 14e0947db04ce6fab19be9a0b1a475d99d6e16a6967ec079488fa162fecf45c37abdf37b7ad4e763d96a8110b1447dbca1a13923d3e0a5377d7f7e2bad5fe147
7
- data.tar.gz: 3e5a97c488b04b36487c1ee8bb6591c2eb2c2987dd79dc62dbfe5b610ee1dac7813a5fd63927db745354f8ee54abd224fd67f587acbb273283731794c2f42904
6
+ metadata.gz: 159d3ae1264b6095b229c4d5d24a925074c1a49c7be7894b44d1c9a8dfb5f87e840f569f5b54ba9d6b968d3092d34dfe1e9d2d5fb608101d1a730c75f572421d
7
+ data.tar.gz: 46c8621291849844500dfb31753870e7d7de574dbb178c1db318fe64a680cf612110361b162479cb5521047f319d8e609443f5f1f1a7d022a26d5cd0ec8c0fd5
data/.DS_Store CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,4 +1,42 @@
1
- ## [Unreleased]
1
+ ## [0.4.2] - 2026-03-21
2
+
3
+ ### Added
4
+ - `on_verify_success` callback now receives `request:` as an optional keyword argument,
5
+ enabling apps to access HTTP context (e.g. set session) at verification time.
6
+ Existing proc-based callbacks are unaffected (procs ignore unknown keyword args);
7
+ lambda-based callbacks should add `request: nil` to their signature.
8
+ - `Verifiable#verify_{channel}_code` now accepts an optional `request:` keyword,
9
+ forwarding it to `on_verify_success` so the model-level API has parity with the
10
+ engine and the direct `VerifyIt.verify_code` call.
11
+ - `current_record_resolver` and `identifier_resolver` are now listed in the
12
+ Configuration Reference table in the README.
13
+ - Install generator accepts `--engine` flag to mount engine routes and generate
14
+ resolver config. Without the flag, the installer produces a minimal initializer
15
+ with no engine routes or resolver boilerplate.
16
+
17
+ ### Changed
18
+ - **Breaking (engine only):** `POST /verify/send` renamed to `POST /verify/request`
19
+ to avoid collision with Ruby's `Object#send`. Update client code that hits this
20
+ endpoint. The `/verify/confirm` endpoint is unchanged.
21
+ - Dropped Ruby 3.1 support; minimum required Ruby is now 3.2 (due to `connection_pool >= 3.0` transitive dependency).
22
+ - RuboCop `TargetRubyVersion` updated from 3.0 to 3.2 to match `required_ruby_version`.
23
+
24
+ ### Removed
25
+ - Engine no longer auto-includes `VerifyIt::Verifiable` into all ActiveRecord models.
26
+ Add `include VerifyIt::Verifiable` explicitly in models that need it (as shown in
27
+ the README). This avoids polluting unrelated models with verification methods.
28
+ - Install generator no longer unconditionally mounts the engine. Pass `--engine`
29
+ to opt in.
30
+
31
+ ### Fixed
32
+ - Initializer template `delivery_channel` default corrected from `:email` to `:sms`.
33
+ - Unused rescue variable in `Verifier#attempt_delivery` (RuboCop `Lint/UselessAssignment`).
34
+ - README testing example now uses correct engine params (`channel`, `auth_headers`)
35
+ instead of the outdated standalone format.
36
+ - README `on_verify_success` callback signature now includes `request: nil`.
37
+ - Install generator mount path changed from `/verify_it` to `/verify` to match
38
+ README examples.
39
+ - Initializer template `on_verify_success` callback signature now includes `request: nil`.
2
40
 
3
41
  ## [0.4.0] - 2026-03-07
4
42
 
data/README.md CHANGED
@@ -35,15 +35,21 @@ bundle install
35
35
  ### 1. Generate configuration files
36
36
 
37
37
  ```bash
38
- bundle exec verify_it install
38
+ rails generate verify_it:install --storage=redis
39
39
  ```
40
40
 
41
- The installer will ask you to choose a storage backend and generate:
41
+ The installer generates:
42
42
 
43
43
  - `config/initializers/verify_it.rb` — your main configuration
44
- - A database migration (if you chose Database storage)
44
+ - A database migration (if you chose `--storage=database`)
45
45
 
46
- If you chose Database storage, run:
46
+ Pass `--engine` to also mount the engine routes and generate resolver config:
47
+
48
+ ```bash
49
+ rails generate verify_it:install --storage=redis --engine
50
+ ```
51
+
52
+ If you chose database storage, run:
47
53
 
48
54
  ```bash
49
55
  rails db:migrate
@@ -187,8 +193,10 @@ VerifyIt.cleanup(to: "+15551234567", record: current_user)
187
193
 
188
194
  ## Rails Engine (HTTP Endpoints)
189
195
 
190
- VerifyIt ships a mountable Rails Engine that exposes two JSON endpoints. This is
191
- optional, if you prefer to not use the engine, skip to the next section.
196
+ VerifyIt ships a mountable Rails Engine that exposes two JSON endpoints. Use the
197
+ engine when you want drop-in endpoints without writing controller code. This is
198
+ optional - skip this section if you prefer to handle verification in your own
199
+ controllers using the `Verifiable` concern or the plain Ruby API.
192
200
 
193
201
  ### Mount the engine
194
202
 
@@ -201,7 +209,7 @@ This adds two routes:
201
209
 
202
210
  | Method | Path | Action |
203
211
  |---|---|---|
204
- | POST | `/verify/send` | Send a verification code |
212
+ | POST | `/verify/request` | Send a verification code |
205
213
  | POST | `/verify/confirm` | Confirm a verification code |
206
214
 
207
215
  ### Configure the resolvers
@@ -240,7 +248,7 @@ end
240
248
  **Send a code:**
241
249
 
242
250
  ```bash
243
- POST /verify/send
251
+ POST /verify/request
244
252
  Content-Type: application/json
245
253
 
246
254
  { "channel": "sms" }
@@ -297,11 +305,14 @@ en:
297
305
  | `max_verification_attempts` | `5` | Integer |
298
306
  | `max_identifier_changes` | `5` | Integer |
299
307
  | `rate_limit_window` | `3600` | Seconds (integer) |
308
+ | `delivery_channel` | `:sms` | `:sms`, `:email` |
300
309
  | `sms_sender` | `nil` | Lambda `(to:, code:, context:) { }` |
301
310
  | `email_sender` | `nil` | Lambda `(to:, code:, context:) { }` |
302
311
  | `on_send` | `nil` | Lambda `(record:, identifier:, channel:) { }` |
303
- | `on_verify_success` | `nil` | Lambda `(record:, identifier:) { }` |
312
+ | `on_verify_success` | `nil` | Lambda `(record:, identifier:, request: nil) { }` |
304
313
  | `on_verify_failure` | `nil` | Lambda `(record:, identifier:, attempts:) { }` |
314
+ | `current_record_resolver` | `nil` | Lambda `(request) { }` — required when mounting the engine |
315
+ | `identifier_resolver` | `nil` | Lambda `(record, channel) { }` — required when mounting the engine |
305
316
  | `namespace` | `nil` | Lambda `(record) { }` returning a string or nil |
306
317
  | `test_mode` | `false` | Boolean — exposes `result.code` |
307
318
  | `bypass_delivery` | `false` | Boolean — skips actual delivery |
@@ -313,7 +324,7 @@ config.on_send = ->(record:, identifier:, channel:) {
313
324
  Analytics.track("verification_sent", user_id: record.id, channel: channel)
314
325
  }
315
326
 
316
- config.on_verify_success = ->(record:, identifier:) {
327
+ config.on_verify_success = ->(record:, identifier:, request: nil) {
317
328
  Analytics.track("verification_success", user_id: record.id)
318
329
  }
319
330
 
@@ -368,14 +379,14 @@ RSpec.configure do |config|
368
379
  end
369
380
  ```
370
381
 
371
- In a request spec:
382
+ In a request spec (with the engine mounted):
372
383
 
373
384
  ```ruby
374
385
  it "verifies phone number" do
375
- post "/verify/send", params: { phone: "+15551234567" }
386
+ post "/verify/request", params: { channel: "sms" }, headers: auth_headers
376
387
  code = JSON.parse(response.body)["code"] # available in test_mode
377
388
 
378
- post "/verify/confirm", params: { phone: "+15551234567", code: code }
389
+ post "/verify/confirm", params: { channel: "sms", code: code }, headers: auth_headers
379
390
  expect(response).to have_http_status(:ok)
380
391
  end
381
392
  ```
@@ -34,7 +34,7 @@ module VerifyIt
34
34
 
35
35
  channel = resolve_channel
36
36
  identifier = resolve_identifier(record, channel)
37
- result = VerifyIt.verify_code(to: identifier, code: params[:code].to_s, record: record)
37
+ result = VerifyIt.verify_code(to: identifier, code: params[:code].to_s, record: record, request: request)
38
38
 
39
39
  if result.success?
40
40
  render json: { message: I18n.t("verify_it.responses.verified") }, status: :ok
data/config/routes.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  VerifyIt::Engine.routes.draw do
4
- post "send", to: "verifications#create", as: :send_verification
4
+ post "request", to: "verifications#create", as: :request_verification
5
5
  post "confirm", to: "verifications#verify", as: :confirm_verification
6
6
  end
@@ -10,11 +10,13 @@ module VerifyIt
10
10
 
11
11
  source_root File.expand_path("templates", __dir__)
12
12
 
13
- desc "Creates a VerifyIt initializer, mounts the engine in routes, " \
13
+ desc "Creates a VerifyIt initializer and optionally mounts the engine routes " \
14
14
  "and generates a migration when using database storage."
15
15
 
16
16
  class_option :storage, type: :string, default: "memory",
17
17
  desc: "Storage backend to use: memory, redis, or database"
18
+ class_option :engine, type: :boolean, default: false,
19
+ desc: "Mount the VerifyIt engine and generate resolver config"
18
20
 
19
21
  def self.next_migration_number(dirname)
20
22
  next_num = current_migration_number(dirname) + 1
@@ -26,7 +28,9 @@ module VerifyIt
26
28
  end
27
29
 
28
30
  def mount_engine
29
- route 'mount VerifyIt::Engine, at: "/verify_it"'
31
+ return unless options[:engine]
32
+
33
+ route 'mount VerifyIt::Engine, at: "/verify"'
30
34
  end
31
35
 
32
36
  def generate_migration
@@ -23,24 +23,27 @@ VerifyIt.configure do |config|
23
23
  # e.g. Twilio, Vonage, etc.
24
24
  }
25
25
 
26
- # Required: resolve the current authenticated record from a request.
26
+ <% if options[:engine] -%>
27
+ # Required when mounting the engine (VerifyIt::Engine):
28
+ # Resolve the current authenticated record from a request.
27
29
  config.current_record_resolver = ->(request) {
28
30
  # User.find_by(id: request.session[:user_id])
29
31
  }
30
32
 
31
- # Required: resolve the delivery identifier (phone/email) from the record and channel.
33
+ # Resolve the delivery identifier (phone/email) from the record and channel.
32
34
  config.identifier_resolver = ->(record, channel) {
33
35
  # channel == :sms ? record.phone_number : record.email
34
36
  }
35
37
 
38
+ <% end -%>
36
39
  # Optional overrides (shown with defaults):
37
40
  # config.code_length = 6
38
41
  # config.code_ttl = 300
39
42
  # config.code_format = :numeric
40
43
  # config.max_send_attempts = 3
41
44
  # config.max_verification_attempts = 5
42
- # config.delivery_channel = :email
45
+ # config.delivery_channel = :sms
43
46
  # config.on_send = ->(record:, identifier:, channel:) {}
44
- # config.on_verify_success = ->(record:, identifier:) {}
47
+ # config.on_verify_success = ->(record:, identifier:, request: nil) {}
45
48
  # config.on_verify_failure = ->(record:, identifier:, attempts:) {}
46
49
  end
@@ -9,11 +9,5 @@ module VerifyIt
9
9
  initializer "verify_it.i18n" do
10
10
  config.i18n.load_path += Dir[Engine.root.join("config", "locales", "**", "*.yml").to_s]
11
11
  end
12
-
13
- initializer "verify_it.active_record" do
14
- ActiveSupport.on_load(:active_record) do
15
- include VerifyIt::Verifiable
16
- end
17
- end
18
12
  end
19
13
  end
@@ -30,12 +30,13 @@ module VerifyIt
30
30
  )
31
31
  end
32
32
 
33
- define_method(verify_method) do |code|
33
+ define_method(verify_method) do |code, request: nil|
34
34
  identifier = send(attribute)
35
35
  VerifyIt.verify_code(
36
36
  to: identifier,
37
37
  code: code,
38
- record: self
38
+ record: self,
39
+ request: request
39
40
  )
40
41
  end
41
42
 
@@ -30,7 +30,7 @@ module VerifyIt
30
30
  finalize_send(to: to, record: record, channel: channel, code_data: code_data)
31
31
  end
32
32
 
33
- def verify_code(to:, code:, record:)
33
+ def verify_code(to:, code:, record:, request: nil)
34
34
  rate_limit_result = check_verification_rate_limit(to: to, record: record)
35
35
  return rate_limit_result if rate_limit_result
36
36
 
@@ -40,7 +40,7 @@ module VerifyIt
40
40
  current_attempts = rate_limiter.record_verification_attempt(identifier: to, record: record)
41
41
 
42
42
  if code_matches?(code, stored_code)
43
- handle_verification_success(to: to, record: record, attempts: current_attempts)
43
+ handle_verification_success(to: to, record: record, attempts: current_attempts, request: request)
44
44
  else
45
45
  handle_verification_failure(to: to, record: record, attempts: current_attempts)
46
46
  end
@@ -100,7 +100,7 @@ module VerifyIt
100
100
  delivery = get_delivery_adapter(channel)
101
101
  delivery.deliver(to: to, code: code, context: context)
102
102
  nil
103
- rescue StandardError => e
103
+ rescue StandardError
104
104
  delivery_failed_result
105
105
  end
106
106
 
@@ -120,12 +120,12 @@ module VerifyIt
120
120
  )
121
121
  end
122
122
 
123
- def handle_verification_success(to:, record:, attempts:)
123
+ def handle_verification_success(to:, record:, attempts:, request: nil)
124
124
  storage.delete_code(identifier: to, record: record)
125
125
  storage.reset_attempts(identifier: to, record: record)
126
126
  storage.reset_send_count(identifier: to, record: record)
127
127
 
128
- invoke_callback(config.on_verify_success, record: record, identifier: to)
128
+ invoke_callback(config.on_verify_success, record: record, identifier: to, request: request)
129
129
 
130
130
  success_result("Verification successful", verified: true, attempts: attempts)
131
131
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module VerifyIt
4
- VERSION = "0.4.0.beta"
4
+ VERSION = "0.4.2"
5
5
  end
data/lib/verify_it.rb CHANGED
@@ -37,8 +37,8 @@ module VerifyIt
37
37
  verifier.send_code(to: to, record: record, channel: channel, context: context)
38
38
  end
39
39
 
40
- def verify_code(to:, code:, record:)
41
- verifier.verify_code(to: to, code: code, record: record)
40
+ def verify_code(to:, code:, record:, request: nil)
41
+ verifier.verify_code(to: to, code: code, record: record, request: request)
42
42
  end
43
43
 
44
44
  def cleanup(to:, record:)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verify_it
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.beta
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremias Ramirez
@@ -193,12 +193,7 @@ files:
193
193
  - lib/verify_it/verifiable.rb
194
194
  - lib/verify_it/verifier.rb
195
195
  - lib/verify_it/version.rb
196
- - pkg/verify_it-0.1.0.gem
197
196
  - sig/verify_it.rbs
198
- - verify_it-0.1.0.gem
199
- - verify_it-0.1.1.gem
200
- - verify_it-0.2.0.gem
201
- - verify_it-0.3.0.gem
202
197
  homepage: https://github.com/JeremasPosta/verify_it
203
198
  licenses:
204
199
  - MIT
@@ -215,7 +210,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
215
210
  requirements:
216
211
  - - ">="
217
212
  - !ruby/object:Gem::Version
218
- version: '3.0'
213
+ version: '3.2'
219
214
  required_rubygems_version: !ruby/object:Gem::Requirement
220
215
  requirements:
221
216
  - - ">="
Binary file
data/verify_it-0.1.0.gem DELETED
Binary file
data/verify_it-0.1.1.gem DELETED
Binary file
data/verify_it-0.2.0.gem DELETED
Binary file
data/verify_it-0.3.0.gem DELETED
Binary file