intercom-rails 1.0.1 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/intercom-rails/config.rb +9 -0
- data/lib/intercom-rails/script_tag.rb +44 -6
- data/lib/intercom-rails/version.rb +1 -1
- metadata +19 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8672ce0798e1f6ed14669e026fb048640c70592e27a3d34e217a6bddb0cbf097
|
4
|
+
data.tar.gz: e62b7cb80da4e200b47b4454b67e87c5a229702a6f626b471c117de433e28794
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5ee15eb8b021131a761f45ac8a749a7c2ecec50813c7d0befdb6aa59a9b0f8281e9867a65b09bdbfdf4b5e2894ebebef940d03aae85618b4cb7490308f181b9
|
7
|
+
data.tar.gz: 6a5b063fde892db61708f02a868af8fe2879a54225b2d471fcdd15fb4af654318b2a26af3d0e8f1eba9a99fc01ee2424af3a1b95e6cb849e26dbd61ea51b3527
|
@@ -143,6 +143,15 @@ module IntercomRails
|
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
|
+
config_group :jwt do
|
147
|
+
config_accessor :enabled
|
148
|
+
config_accessor :signed_user_fields do |value|
|
149
|
+
unless value.nil? || (value.kind_of?(Array) && value.all? { |v| v.kind_of?(Symbol) || v.kind_of?(String) })
|
150
|
+
raise ArgumentError, "jwt.signed_user_fields must be an array of symbols or strings"
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
146
155
|
end
|
147
156
|
|
148
157
|
end
|
@@ -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.
|
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]
|
@@ -113,12 +121,42 @@ module IntercomRails
|
|
113
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);}};})()"
|
114
122
|
end
|
115
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
|
+
|
132
|
+
if Config.jwt.signed_user_fields.present?
|
133
|
+
Config.jwt.signed_user_fields.each do |field|
|
134
|
+
field = field.to_sym
|
135
|
+
payload[field] = user_details[field].to_s if user_details[field].present?
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
JWT.encode(payload, secret, 'HS256')
|
140
|
+
end
|
141
|
+
|
116
142
|
def user_details=(user_details)
|
117
143
|
@user_details = DateHelper.convert_dates_to_unix_timestamps(user_details || {})
|
118
144
|
@user_details = @user_details.with_indifferent_access.tap do |u|
|
119
145
|
[:email, :name, :user_id].each { |k| u.delete(k) if u[k].nil? }
|
120
146
|
|
121
|
-
|
147
|
+
if secret.present?
|
148
|
+
if jwt_enabled && u[:user_id].present?
|
149
|
+
u[:intercom_user_jwt] ||= generate_jwt
|
150
|
+
|
151
|
+
u.delete(:user_id)
|
152
|
+
Config.jwt.signed_user_fields&.each do |field|
|
153
|
+
u.delete(field.to_sym)
|
154
|
+
end
|
155
|
+
elsif (u[:user_id] || u[:email]).present?
|
156
|
+
u[:user_hash] ||= user_hash
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
122
160
|
u[:app_id] ||= app_id
|
123
161
|
end
|
124
162
|
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.
|
4
|
+
version: 1.0.5
|
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-
|
13
|
+
date: 2024-12-20 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,28 +116,14 @@ dependencies:
|
|
102
116
|
requirements:
|
103
117
|
- - "~>"
|
104
118
|
- !ruby/object:Gem::Version
|
105
|
-
version: '
|
106
|
-
type: :development
|
107
|
-
prerelease: false
|
108
|
-
version_requirements: !ruby/object:Gem::Requirement
|
109
|
-
requirements:
|
110
|
-
- - "~>"
|
111
|
-
- !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.8.0
|
119
|
+
version: '3.0'
|
120
120
|
type: :development
|
121
121
|
prerelease: false
|
122
122
|
version_requirements: !ruby/object:Gem::Requirement
|
123
123
|
requirements:
|
124
124
|
- - "~>"
|
125
125
|
- !ruby/object:Gem::Version
|
126
|
-
version:
|
126
|
+
version: '3.0'
|
127
127
|
- !ruby/object:Gem::Dependency
|
128
128
|
name: tzinfo
|
129
129
|
requirement: !ruby/object:Gem::Requirement
|
@@ -202,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
202
|
- !ruby/object:Gem::Version
|
203
203
|
version: '0'
|
204
204
|
requirements: []
|
205
|
-
rubygems_version: 3.
|
205
|
+
rubygems_version: 3.5.22
|
206
206
|
signing_key:
|
207
207
|
specification_version: 4
|
208
208
|
summary: Rails helper for emitting javascript script tags for Intercom
|