emailbutler 0.8.0 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb57bd8a59942207f28941dd14e91f17cd5d74982877773415a38b925d49ccaa
4
- data.tar.gz: 0fc748f32a49291175cccdff3a9e89dfe2aefafaacd1c357df38c545d18d768a
3
+ metadata.gz: 8e223a593bef4c9075afed0fa29d31057519250a0949a589c8535232d632bc83
4
+ data.tar.gz: 7355cdbd47a964b9da80cbf0a80203c40865ebc5cec0af272595d105a4cbcb16
5
5
  SHA512:
6
- metadata.gz: 0b5a8e3d1c292ff847623e7f404c5535d4324d9f206b0a15905b982fda3c42bd566039cb6e01727b085b7f924899ec07ffdd8a2d05e5fa418eba4d048f7012f1
7
- data.tar.gz: d1bed20baaadc9b02fe3b8e8f8d4412e575977121d376f2077e18adc35349f5db261c7216f98b0cd0b87a7f875041c7f5614d70cd0c5dc6fe0fd8c6f42091045
6
+ metadata.gz: 0d92a36b9c851110c9c038f7ef077119cde85fed6f1731531db011649cbbe83fa8d2d1ab1db310a5e8df513014277fb074a9445088ff195d5f649ac7d385a97a
7
+ data.tar.gz: 5313f1e26f096577cbc2ad07be23842862ebf9a24b1ccc358a51469130bce50e416b9ffe5e6895b3e14962e43a1f389b271daeca0a0cdedd0516564d270ef632
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Emailbutler
2
2
  Simple email tracker for Ruby on Rails applications.
3
- Emailbutler allows you to track delivery status of emails sent by your app through Sendgrid and/or SMTP2GO.
3
+ Emailbutler allows you to track delivery status of emails sent by your app through Sendgrid, SMTP2GO, Resend.
4
4
 
5
5
  There are situations when you need to check whether a certain letter or certain type of letters was successfully sent from the application, and through the UI of some providers you can try to find such a letter by the recipient or the subject of the letter, but sometimes it's not enough.
6
6
 
@@ -34,7 +34,7 @@ require 'emailbutler/adapters/active_record'
34
34
 
35
35
  Emailbutler.configure do |config|
36
36
  config.adapter = Emailbutler::Adapters::ActiveRecord.new # required
37
- config.providers = %w[sendgrid smtp2go] # required at least 1 provider since 0.8
37
+ config.providers = %w[sendgrid smtp2go resend] # optional
38
38
  config.ui_username = 'username' # optional
39
39
  config.ui_password = 'password' # optional
40
40
  config.ui_secured_environments = ['production'] # optional
@@ -116,6 +116,14 @@ end
116
116
  - select all deliverability data,
117
117
  - save settings.
118
118
 
119
+ #### Resend
120
+
121
+ - go to [Mail settings](https://resend.com/webhooks),
122
+ - add Webhook,
123
+ - in the Endpoint URL field, paste the URL to webhook controller of your app (host/emailbutler/webhooks/resend),
124
+ - select all deliverability data,
125
+ - save settings.
126
+
119
127
  ## Usage
120
128
 
121
129
  1. Each event with sending email will create new record with message params in database.
@@ -2,22 +2,9 @@
2
2
 
3
3
  module Emailbutler
4
4
  class WebhooksController < Emailbutler::ApplicationController
5
- # deprecated constants
6
- SENDGRID_USER_AGENT = 'SendGrid Event API'
7
- SMTP2GO_USER_AGENT = 'Go-http-client/1.1'
8
-
9
5
  skip_before_action :verify_authenticity_token
10
6
  before_action :validate_provider, only: %i[create]
11
7
 
12
- def create_deprecated
13
- Emailbutler::Container.resolve(:webhooks_receiver).call(
14
- mapper: receiver_mapper_deprecated(request.headers['HTTP_USER_AGENT']),
15
- payload: mapper_params_deprecated.to_h
16
- )
17
-
18
- head :ok
19
- end
20
-
21
8
  def create
22
9
  Emailbutler::Container.resolve(:webhooks_receiver).call(
23
10
  mapper: receiver_mapper,
@@ -37,6 +24,7 @@ module Emailbutler
37
24
  case params[:provider]
38
25
  when 'sendgrid' then Emailbutler::Container.resolve(:sendgrid_mapper)
39
26
  when 'smtp2go' then Emailbutler::Container.resolve(:smtp2go_mapper)
27
+ when 'resend' then Emailbutler::Container.resolve(:resend_mapper)
40
28
  end
41
29
  end
42
30
 
@@ -44,6 +32,7 @@ module Emailbutler
44
32
  case params[:provider]
45
33
  when 'sendgrid' then sendgrid_params
46
34
  when 'smtp2go' then smtp2go_params
35
+ when 'resend' then resend_params
47
36
  end
48
37
  end
49
38
 
@@ -55,18 +44,8 @@ module Emailbutler
55
44
  params.permit('event', 'sendtime', 'message-id')
56
45
  end
57
46
 
58
- def receiver_mapper_deprecated(user_agent)
59
- case user_agent
60
- when SENDGRID_USER_AGENT then Emailbutler::Container.resolve(:sendgrid_mapper)
61
- when SMTP2GO_USER_AGENT then Emailbutler::Container.resolve(:smtp2go_mapper)
62
- end
63
- end
64
-
65
- def mapper_params_deprecated
66
- params.permit(
67
- 'event', 'sendtime', 'message-id',
68
- '_json' => %w[event timestamp smtp-id sg_message_id]
69
- )
47
+ def resend_params
48
+ params.permit('type', 'created_at', 'data' => %w[email_id])
70
49
  end
71
50
  end
72
51
  end
data/config/routes.rb CHANGED
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Emailbutler::Engine.routes.draw do
4
- post '/webhooks', to: 'webhooks#create_deprecated'
5
- post '/webhooks/:provider', to: 'webhooks#create'
4
+ post '/webhooks/:provider', to: 'webhooks#create' if Emailbutler.configuration.providers.any?
6
5
 
7
6
  resources :ui, only: %i[index show]
8
7
  namespace :ui do
@@ -7,7 +7,7 @@ module Emailbutler
7
7
  AVAILABLE_ADAPTERS = %w[
8
8
  Emailbutler::Adapters::ActiveRecord
9
9
  ].freeze
10
- AVAILABLE_PROVIDERS = %w[sendgrid smtp2go].freeze
10
+ AVAILABLE_PROVIDERS = %w[sendgrid smtp2go resend].freeze
11
11
 
12
12
  attr_accessor :adapter, :providers, :ui_username, :ui_password, :ui_secured_environments
13
13
 
@@ -39,7 +39,6 @@ module Emailbutler
39
39
 
40
40
  def validate_providers
41
41
  raise InitializeError, 'Providers list must be array' unless providers.is_a?(Array)
42
- raise InitializeError, 'At least 1 provider must be present' if providers.blank?
43
42
 
44
43
  return unless providers.any? { |provider| AVAILABLE_PROVIDERS.exclude?(provider) }
45
44
 
@@ -3,6 +3,7 @@
3
3
  require 'dry/container'
4
4
  require 'emailbutler/webhooks/mappers/sendgrid'
5
5
  require 'emailbutler/webhooks/mappers/smtp2go'
6
+ require 'emailbutler/webhooks/mappers/resend'
6
7
  require 'emailbutler/webhooks/receiver'
7
8
 
8
9
  module Emailbutler
@@ -20,6 +21,7 @@ module Emailbutler
20
21
  # webhook mappers
21
22
  register(:sendgrid_mapper) { Emailbutler::Webhooks::Mappers::Sendgrid.new }
22
23
  register(:smtp2go_mapper) { Emailbutler::Webhooks::Mappers::Smtp2Go.new }
24
+ register(:resend_mapper) { Emailbutler::Webhooks::Mappers::Resend.new }
23
25
 
24
26
  # webhook receiver
25
27
  register(:webhooks_receiver) { Emailbutler::Webhooks::Receiver.new }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Emailbutler
4
- VERSION = '0.8.0'
4
+ VERSION = '0.8.2'
5
5
  end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Emailbutler
4
+ module Webhooks
5
+ module Mappers
6
+ class Resend
7
+ DELIVERABILITY_MAPPER = {
8
+ 'email.sent' => 'processed',
9
+ 'email.delivered' => 'delivered',
10
+ 'email.opened' => 'delivered',
11
+ 'email.clicked' => 'delivered',
12
+ 'email.delivered_delayed' => 'failed',
13
+ 'email.bounced' => 'failed',
14
+ 'email.complained' => 'failed'
15
+ }.freeze
16
+
17
+ def call(payload:)
18
+ payload.stringify_keys!
19
+ # message-id contains data like <uuid>
20
+ message_uuid = payload.dig('data', 'email_id')
21
+ status = DELIVERABILITY_MAPPER[payload['type']]
22
+ return [] if message_uuid.nil? || status.nil?
23
+
24
+ [
25
+ {
26
+ message_uuid: message_uuid,
27
+ status: status,
28
+ timestamp: payload['created_at'] ? DateTime.parse(payload['created_at']).utc : nil
29
+ }
30
+ ]
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
data/lib/emailbutler.rb CHANGED
@@ -24,12 +24,6 @@ module Emailbutler
24
24
  # end
25
25
  #
26
26
  def configure
27
- ActiveSupport::Deprecation.new.warn(
28
- 'Webhook endpoint should receive provider name in params. ' \
29
- 'Please update webhook url in settings of your SMTP provider.' \
30
- 'Webhook without provider in params will be removed soon.'
31
- )
32
-
33
27
  yield configuration
34
28
 
35
29
  configuration.validate
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emailbutler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdanov Anton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-11 00:00:00.000000000 Z
11
+ date: 2024-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-container
@@ -216,6 +216,7 @@ files:
216
216
  - lib/emailbutler/helpers.rb
217
217
  - lib/emailbutler/mailers/helpers.rb
218
218
  - lib/emailbutler/version.rb
219
+ - lib/emailbutler/webhooks/mappers/resend.rb
219
220
  - lib/emailbutler/webhooks/mappers/sendgrid.rb
220
221
  - lib/emailbutler/webhooks/mappers/smtp2go.rb
221
222
  - lib/emailbutler/webhooks/receiver.rb