intercom-rails 1.0.0 → 1.0.4

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: 5dee175c5039fa80194ff69042d5de615a7a801351da87b5c7459e2504f58e05
4
- data.tar.gz: ccbaed8ae280936a62c3c1b3ca90f907b71e67b18b0e3e5f6aa2bcf4e7f11f05
3
+ metadata.gz: 6a0dbbf87c42ebfc8d7ef419b8419c603affa9b404c60aa24fb08d9b97a4d497
4
+ data.tar.gz: 4d651bdef674633a6f2ace4576a8450e97edfb176f05af5227676cebe1568c61
5
5
  SHA512:
6
- metadata.gz: 1bb0fd7b74175353525d1feb105b69be217620b831d17c639aa8666bfd03249ac25a57542be9419294a71ee54990d89af73473952d5fc24fd6b4e25caae83ead
7
- data.tar.gz: eccb8b923bba00629e59784e8ff76f7fd4d8489568d9e3c2d199e30bf9e6e5c1493d4a35d095299dfcca7d3af107df08396aac7cd1e0caae28ba0e1e6e6d092c
6
+ metadata.gz: 736a52b2db369ed6e3716dbac46cd1b30b333644c7a248d45ebceeb2e2c0a7ffc2eb8bb7032c0ba6d931ec715b7356dbfc66f802239d0a437f4a477466c4c388
7
+ data.tar.gz: d3dce65e7f52e5ca96104a65b63434fd2dff1bdd5652a533e2cd9dd13afb00c74d23153d2658ad01e4ba8b0dfb90d5bf5711c49265e94f56d5ff92222518a6fb
@@ -110,6 +110,7 @@ module IntercomRails
110
110
  config_accessor :hide_default_launcher
111
111
  config_accessor :api_base
112
112
  config_accessor :encrypted_mode
113
+ config_accessor :jwt_enabled
113
114
 
114
115
  def self.api_key=(*)
115
116
  warn "Setting an Intercom API key is no longer supported; remove the `config.api_key = ...` line from config/initializers/intercom.rb"
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'active_support/all'
4
4
  require 'action_view'
5
+ require 'jwt'
5
6
 
6
7
  module IntercomRails
7
8
 
@@ -17,7 +18,7 @@ module IntercomRails
17
18
  include ::ActionView::Helpers::TagHelper
18
19
 
19
20
  attr_reader :user_details, :company_details, :show_everywhere, :session_duration
20
- attr_accessor :secret, :widget_options, :controller, :nonce, :encrypted_mode_enabled, :encrypted_mode
21
+ attr_accessor :secret, :widget_options, :controller, :nonce, :encrypted_mode_enabled, :encrypted_mode, :jwt_enabled
21
22
 
22
23
  def initialize(options = {})
23
24
  self.secret = options[:secret] || Config.api_secret
@@ -25,14 +26,21 @@ module IntercomRails
25
26
  self.controller = options[:controller]
26
27
  @show_everywhere = options[:show_everywhere]
27
28
  @session_duration = session_duration_from_config
28
- self.user_details = options[:find_current_user_details] ? find_current_user_details : options[:user_details]
29
+ self.jwt_enabled = options[:jwt_enabled] || Config.jwt_enabled
30
+
31
+ initial_user_details = if options[:find_current_user_details]
32
+ find_current_user_details
33
+ else
34
+ options[:user_details] || {}
35
+ end
36
+
37
+ lead_attributes = find_lead_attributes
38
+
39
+ self.user_details = initial_user_details.merge(lead_attributes)
29
40
 
30
41
  self.encrypted_mode_enabled = options[:encrypted_mode] || Config.encrypted_mode
31
42
  self.encrypted_mode = IntercomRails::EncryptedMode.new(secret, options[:initialization_vector], {:enabled => encrypted_mode_enabled})
32
43
 
33
- # Request specific custom data for non-signed up users base on lead_attributes
34
- self.user_details = self.user_details.merge(find_lead_attributes)
35
-
36
44
  self.company_details = if options[:find_current_company_details]
37
45
  find_current_company_details
38
46
  elsif options[:user_details]
@@ -110,7 +118,17 @@ module IntercomRails
110
118
  plaintext_javascript = ActiveSupport::JSON.encode(plaintext_settings).gsub('<', '\u003C')
111
119
  intercom_encrypted_payload_javascript = encrypted_mode.encrypted_javascript(intercom_settings)
112
120
 
113
- "window.intercomSettings = #{plaintext_javascript};#{intercom_encrypted_payload_javascript}(function(){var w=window;var ic=w.Intercom;if(typeof ic===\"function\"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='#{Config.library_url || "https://widget.intercom.io/widget/#{j app_id}"}';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}};})()"
121
+ "window.intercomSettings = #{plaintext_javascript};#{intercom_encrypted_payload_javascript}(function(){var w=window;var ic=w.Intercom;if(typeof ic===\"function\"){ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='#{Config.library_url || "https://widget.intercom.io/widget/#{j app_id}"}';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(document.readyState==='complete'){l();}else if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}};})()"
122
+ end
123
+
124
+ def generate_jwt
125
+ return nil unless user_details[:user_id].present?
126
+
127
+ payload = {
128
+ user_id: user_details[:user_id].to_s,
129
+ exp: 24.hours.from_now.to_i
130
+ }
131
+ JWT.encode(payload, secret, 'HS256')
114
132
  end
115
133
 
116
134
  def user_details=(user_details)
@@ -118,7 +136,15 @@ module IntercomRails
118
136
  @user_details = @user_details.with_indifferent_access.tap do |u|
119
137
  [:email, :name, :user_id].each { |k| u.delete(k) if u[k].nil? }
120
138
 
121
- u[:user_hash] ||= user_hash if secret.present? && (u[:user_id] || u[:email]).present?
139
+ if secret.present?
140
+ if jwt_enabled && u[:user_id].present?
141
+ u[:intercom_user_jwt] ||= generate_jwt
142
+ u.delete(:user_id) # No need to send plaintext user_id when using JWT
143
+ elsif (u[:user_id] || u[:email]).present?
144
+ u[:user_hash] ||= user_hash
145
+ end
146
+ end
147
+
122
148
  u[:app_id] ||= app_id
123
149
  end
124
150
  end
@@ -1,3 +1,3 @@
1
1
  module IntercomRails
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intercom-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben McRedmond
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-02-13 00:00:00.000000000 Z
13
+ date: 2024-12-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -26,6 +26,20 @@ dependencies:
26
26
  - - ">"
27
27
  - !ruby/object:Gem::Version
28
28
  version: '4.0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: jwt
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '2.0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '2.0'
29
43
  - !ruby/object:Gem::Dependency
30
44
  name: rake
31
45
  requirement: !ruby/object:Gem::Requirement
@@ -102,42 +116,14 @@ dependencies:
102
116
  requirements:
103
117
  - - "~>"
104
118
  - !ruby/object:Gem::Version
105
- version: '2.0'
119
+ version: '3.0'
106
120
  type: :development
107
121
  prerelease: false
108
122
  version_requirements: !ruby/object:Gem::Requirement
109
123
  requirements:
110
124
  - - "~>"
111
125
  - !ruby/object:Gem::Version
112
- version: '2.0'
113
- - !ruby/object:Gem::Dependency
114
- name: thin
115
- requirement: !ruby/object:Gem::Requirement
116
- requirements:
117
- - - "~>"
118
- - !ruby/object:Gem::Version
119
- version: 1.7.0
120
- type: :development
121
- prerelease: false
122
- version_requirements: !ruby/object:Gem::Requirement
123
- requirements:
124
- - - "~>"
125
- - !ruby/object:Gem::Version
126
- version: 1.7.0
127
- - !ruby/object:Gem::Dependency
128
- name: bigdecimal
129
- requirement: !ruby/object:Gem::Requirement
130
- requirements:
131
- - - '='
132
- - !ruby/object:Gem::Version
133
- version: 1.3.5
134
- type: :development
135
- prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- requirements:
138
- - - '='
139
- - !ruby/object:Gem::Version
140
- version: 1.3.5
126
+ version: '3.0'
141
127
  - !ruby/object:Gem::Dependency
142
128
  name: tzinfo
143
129
  requirement: !ruby/object:Gem::Requirement
@@ -216,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
202
  - !ruby/object:Gem::Version
217
203
  version: '0'
218
204
  requirements: []
219
- rubygems_version: 3.1.6
205
+ rubygems_version: 3.5.22
220
206
  signing_key:
221
207
  specification_version: 4
222
208
  summary: Rails helper for emitting javascript script tags for Intercom