mailer-log 0.1.9 → 0.2.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: d4126d246df4b031556df419f2fc9c2ea85b2ff1290947e6d832121ff9684672
4
- data.tar.gz: 4b6e0c00f59e2210324d7d9d2e3d6ccb74210984d31c54b702428cd6e801b231
3
+ metadata.gz: 26775ff2d2392f342c9abeaefb88bdfb17eb4cf7474f7b7de2e8455196ccabce
4
+ data.tar.gz: 83ea69d74409c16c64df60899ba17e570f141e608326d54751e5e3603f4c0311
5
5
  SHA512:
6
- metadata.gz: f95a160a50060fec7b7a67f1eeca4f62e5bfe3b15d43d5630113e08bc3497329c8fd674e185567ba8a5ab4f15eb8feb5090f021b4ce3ac0c4261c66ba75728a1
7
- data.tar.gz: 804f2fbeb927c8f963a08dee20a12bbc8cc3d977343a3195443c93999b324bea60258f641d5d51b6aaab0874a896e2cec75ef5320e7f1a0d14c2ded5a7ec7d08
6
+ metadata.gz: 1cc55ff6f8f4f6a399534f201cc528a9ac09a6921e47078cedff710e960b71a0e76e25e0579d4cc1d5167af51b59fb28af070a89cee14652960030443904df7d
7
+ data.tar.gz: a3a234f111a2dcd6d613f44613c15d0222cfad244c87a7664750c694f48766c2eafd544327ea35c360af9fd96f537683b92577284fd8d23c1ecfdbe4075a7215
@@ -2,24 +2,9 @@
2
2
 
3
3
  module MailerLog
4
4
  class AdminController < ::AdminsController
5
- prepend HasScope
6
-
7
- # Expose main app routes to views for navbar/layout links
8
- helper Rails.application.routes.url_helpers
9
-
10
5
  before_action :authenticate_mailer_log!
11
6
 
12
- # Make main_app proxy available in views
13
- helper_method :main_app
14
-
15
- # Override url_options to prevent main app routes from being prefixed
16
- # with the engine's mount path
17
- def url_options
18
- script_name = request.env['SCRIPT_NAME']
19
- return super unless script_name&.include?('mailer_log') || script_name&.include?('mailer-log') || script_name&.include?('email_log')
20
-
21
- super.merge(script_name: '')
22
- end
7
+ rescue_from 'Pundit::NotAuthorizedError', with: :render_not_found
23
8
 
24
9
  private
25
10
 
@@ -29,9 +14,8 @@ module MailerLog
29
14
  MailerLog.configuration.authenticate_with_proc.call(self)
30
15
  end
31
16
 
32
- def mailer_log_engine
33
- MailerLog::Engine.routes.url_helpers
17
+ def render_not_found
18
+ raise ActionController::RoutingError, 'Not Found'
34
19
  end
35
- helper_method :mailer_log_engine
36
20
  end
37
21
  end
@@ -3,6 +3,15 @@
3
3
  module MailerLog
4
4
  module Api
5
5
  class EmailsController < MailerLog::AdminController
6
+ BASE_EMAIL_ATTRIBUTES = %i[
7
+ id tracking_id message_id mailer_class mailer_action
8
+ from_address to_addresses cc_addresses bcc_addresses
9
+ subject domain status delivered_at opened_at clicked_at
10
+ bounced_at created_at updated_at
11
+ ].freeze
12
+ BODY_ATTRIBUTES = %i[html_body text_body headers call_stack].freeze
13
+ EVENT_ATTRIBUTES = %i[id event_type occurred_at recipient ip_address user_agent].freeze
14
+
6
15
  skip_before_action :verify_authenticity_token, only: [:index, :show]
7
16
 
8
17
  def index
@@ -40,47 +49,9 @@ module MailerLog
40
49
  end
41
50
 
42
51
  def email_json(email, include_body: false, include_events: false)
43
- data = {
44
- id: email.id,
45
- tracking_id: email.tracking_id,
46
- message_id: email.message_id,
47
- mailer_class: email.mailer_class,
48
- mailer_action: email.mailer_action,
49
- from_address: email.from_address,
50
- to_addresses: email.to_addresses,
51
- cc_addresses: email.cc_addresses,
52
- bcc_addresses: email.bcc_addresses,
53
- subject: email.subject,
54
- domain: email.domain,
55
- status: email.status,
56
- delivered_at: email.delivered_at,
57
- opened_at: email.opened_at,
58
- clicked_at: email.clicked_at,
59
- bounced_at: email.bounced_at,
60
- created_at: email.created_at,
61
- updated_at: email.updated_at
62
- }
63
-
64
- if include_body
65
- data[:html_body] = email.html_body
66
- data[:text_body] = email.text_body
67
- data[:headers] = email.headers
68
- data[:call_stack] = email.call_stack
69
- end
70
-
71
- if include_events
72
- data[:events] = email.events.recent.map do |event|
73
- {
74
- id: event.id,
75
- event_type: event.event_type,
76
- occurred_at: event.occurred_at,
77
- recipient: event.recipient,
78
- ip_address: event.ip_address,
79
- user_agent: event.user_agent
80
- }
81
- end
82
- end
83
-
52
+ data = email.slice(*BASE_EMAIL_ATTRIBUTES)
53
+ data.merge!(email.slice(*BODY_ATTRIBUTES)) if include_body
54
+ data[:events] = email.events.recent.map { _1.slice(*EVENT_ATTRIBUTES) } if include_events
84
55
  data
85
56
  end
86
57
  end
@@ -11,11 +11,16 @@
11
11
  <% end %>
12
12
  </head>
13
13
  <body class="bg-gray-100 min-h-screen">
14
+ <% header_partial = MailerLog.configuration.header_partial %>
14
15
  <script>
15
16
  window.MAILER_LOG_CONFIG = {
16
- mountPath: '<%= request.script_name %>'
17
+ mountPath: '<%= request.script_name %>',
18
+ hideNavbar: <%= header_partial.present? %>
17
19
  };
18
20
  </script>
21
+ <% if header_partial %>
22
+ <%= render partial: header_partial %>
23
+ <% end %>
19
24
  <div id="app"></div>
20
25
  <% if (js = mailer_log_js_entry) %>
21
26
  <script type="module" src="<%= request.script_name %>/<%= js %>"></script>
@@ -6,7 +6,8 @@ module MailerLog
6
6
  :webhook_signing_key,
7
7
  :capture_call_stack,
8
8
  :call_stack_depth,
9
- :per_page
9
+ :per_page,
10
+ :header_partial
10
11
 
11
12
  attr_reader :authenticate_with_proc, :resolve_accountable_proc
12
13
 
@@ -16,6 +17,7 @@ module MailerLog
16
17
  @capture_call_stack = true
17
18
  @call_stack_depth = 20
18
19
  @per_page = 25
20
+ @header_partial = nil # e.g., 'shared/admin_navbar'
19
21
  @authenticate_with_proc = nil
20
22
  @resolve_accountable_proc = nil
21
23
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MailerLog
4
- VERSION = '0.1.9'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -1,75 +1,43 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  namespace :mailer_log do
4
- desc 'Build MailerLog Vue.js frontend (set MAILER_LOG_OVERRIDES_PATH to customize components)'
5
- task :build_frontend do
6
- frontend_dir = MailerLog::Engine.root.join('frontend')
7
-
8
- unless frontend_dir.exist?
9
- puts <<~MSG
10
- ERROR: Frontend source not available.
11
-
12
- This task is for gem development only. When using mailer-log from RubyGems,
13
- the frontend is pre-built and included in public/mailer_log/.
4
+ desc 'Copy MailerLog assets to public/'
5
+ task install_assets: :environment do
6
+ source = MailerLog::Engine.root.join('public', 'mailer_log')
7
+ destination = Rails.root.join('public', 'mailer_log')
14
8
 
15
- To customize the frontend with overrides:
16
- 1. Clone the gem repository: git clone https://github.com/trafficrunners/mailer-log.git
17
- 2. cd mailer-log/frontend
18
- 3. MAILER_LOG_OVERRIDES_PATH=/path/to/your/overrides npm run build
19
- 4. Copy public/mailer_log/ to your app
20
- MSG
9
+ unless source.exist?
10
+ puts "ERROR: MailerLog assets not found at #{source}"
21
11
  exit 1
22
12
  end
23
13
 
24
- overrides_path = ENV['MAILER_LOG_OVERRIDES_PATH']
25
-
26
- puts 'Installing npm dependencies...'
27
- system('npm install', chdir: frontend_dir.to_s) || raise('npm install failed')
28
-
29
- if overrides_path
30
- puts "Building frontend with overrides from: #{overrides_path}"
31
- else
32
- puts 'Building frontend (no overrides)...'
33
- puts 'Tip: Set MAILER_LOG_OVERRIDES_PATH to customize navbar and other components'
34
- end
35
-
36
- env = overrides_path ? { 'MAILER_LOG_OVERRIDES_PATH' => overrides_path } : {}
37
- system(env, 'npm run build', chdir: frontend_dir.to_s) || raise('npm build failed')
38
-
39
- puts 'Frontend built successfully!'
14
+ FileUtils.rm_rf(destination) if destination.exist?
15
+ FileUtils.cp_r(source, destination)
16
+ puts "MailerLog assets copied to #{destination}"
40
17
  end
41
18
 
42
- desc 'Start Vite development server for MailerLog frontend'
43
- task :dev_server do
19
+ desc 'Build MailerLog Vue.js frontend (for gem development only)'
20
+ task :build_frontend do
44
21
  frontend_dir = MailerLog::Engine.root.join('frontend')
45
22
 
46
23
  unless frontend_dir.exist?
47
- puts <<~MSG
48
- ERROR: Frontend source not available.
49
-
50
- This task is for gem development only. When using mailer-log from RubyGems,
51
- the frontend is pre-built and served automatically.
52
-
53
- To develop the frontend with hot-reload:
54
- 1. Clone the gem repository: git clone https://github.com/trafficrunners/mailer-log.git
55
- 2. cd mailer-log/frontend
56
- 3. npm install
57
- 4. MAILER_LOG_OVERRIDES_PATH=/path/to/your/overrides npm run dev
58
- MSG
24
+ puts 'ERROR: Frontend source not available (only in gem source, not RubyGems)'
59
25
  exit 1
60
26
  end
61
27
 
62
- overrides_path = ENV['MAILER_LOG_OVERRIDES_PATH']
28
+ puts 'Installing npm dependencies...'
29
+ system('npm install', chdir: frontend_dir.to_s) || raise('npm install failed')
63
30
 
64
- puts 'Starting Vite dev server...'
65
- puts 'Frontend will be available at http://localhost:5173'
66
- puts 'Make sure Rails is running on http://localhost:3000'
31
+ puts 'Building frontend...'
32
+ system('npm run build', chdir: frontend_dir.to_s) || raise('npm build failed')
67
33
 
68
- if overrides_path
69
- puts "Using overrides from: #{overrides_path}"
70
- end
34
+ puts 'Frontend built successfully!'
35
+ end
36
+ end
71
37
 
72
- env = overrides_path ? { 'MAILER_LOG_OVERRIDES_PATH' => overrides_path } : {}
73
- exec(env, 'npm run dev', chdir: frontend_dir.to_s)
38
+ # Hook into assets:precompile to copy MailerLog assets
39
+ if Rake::Task.task_defined?('assets:precompile')
40
+ Rake::Task['assets:precompile'].enhance do
41
+ Rake::Task['mailer_log:install_assets'].invoke
74
42
  end
75
43
  end
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "index.html": {
3
- "file": "assets/mailer_log-CzkGXWPn.js",
3
+ "file": "assets/mailer_log-zD1d7Bvi.js",
4
4
  "name": "index",
5
5
  "src": "index.html",
6
6
  "isEntry": true,