intercom-rails 1.0.4 → 1.0.6
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 +4 -4
- data/lib/intercom-rails/config.rb +10 -1
- data/lib/intercom-rails/script_tag.rb +21 -7
- data/lib/intercom-rails/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 5c9335eca559ae32c3965cf1969443c0e20b65d29b81f1e5c6200d1d9e8d734c
         | 
| 4 | 
            +
              data.tar.gz: 120b0878b7f09a4301c94c2c8dbc0c0376623a91e48948339482aafd203c9b99
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: f584dbf2f062e00f9b3d00b53a5cf8b9bef4406cf79f1afa5af805e106a7ef52402668a01f45f5302c04a15985d808651022d45be8b4af6ec8a52a571c12b7f9
         | 
| 7 | 
            +
              data.tar.gz: cadbf3a8a2927260fc51131f688f8a5ae321af6d5d661db9688efa3c2bf2276608ae28264c0b535494610cac561f551151cdedaca4f78dae9b39f9f0bf1ec2d4
         | 
| @@ -110,7 +110,6 @@ 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
         | 
| 114 113 |  | 
| 115 114 | 
             
                def self.api_key=(*)
         | 
| 116 115 | 
             
                  warn "Setting an Intercom API key is no longer supported; remove the `config.api_key = ...` line from config/initializers/intercom.rb"
         | 
| @@ -144,6 +143,16 @@ module IntercomRails | |
| 144 143 | 
             
                  end
         | 
| 145 144 | 
             
                end
         | 
| 146 145 |  | 
| 146 | 
            +
                config_group :jwt do
         | 
| 147 | 
            +
                  config_accessor :enabled
         | 
| 148 | 
            +
                  config_accessor :expiry
         | 
| 149 | 
            +
                  config_accessor :signed_user_fields do |value|
         | 
| 150 | 
            +
                    unless value.nil? || (value.kind_of?(Array) && value.all? { |v| v.kind_of?(Symbol) || v.kind_of?(String) })
         | 
| 151 | 
            +
                      raise ArgumentError, "jwt.signed_user_fields must be an array of symbols or strings"
         | 
| 152 | 
            +
                    end
         | 
| 153 | 
            +
                  end
         | 
| 154 | 
            +
                end
         | 
| 155 | 
            +
             | 
| 147 156 | 
             
              end
         | 
| 148 157 |  | 
| 149 158 | 
             
            end
         | 
| @@ -18,7 +18,7 @@ module IntercomRails | |
| 18 18 | 
             
                include ::ActionView::Helpers::TagHelper
         | 
| 19 19 |  | 
| 20 20 | 
             
                attr_reader :user_details, :company_details, :show_everywhere, :session_duration
         | 
| 21 | 
            -
                attr_accessor :secret, :widget_options, :controller, :nonce, :encrypted_mode_enabled, :encrypted_mode, :jwt_enabled
         | 
| 21 | 
            +
                attr_accessor :secret, :widget_options, :controller, :nonce, :encrypted_mode_enabled, :encrypted_mode, :jwt_enabled, :jwt_expiry
         | 
| 22 22 |  | 
| 23 23 | 
             
                def initialize(options = {})
         | 
| 24 24 | 
             
                  self.secret = options[:secret] || Config.api_secret
         | 
| @@ -26,7 +26,8 @@ module IntercomRails | |
| 26 26 | 
             
                  self.controller = options[:controller]
         | 
| 27 27 | 
             
                  @show_everywhere = options[:show_everywhere]
         | 
| 28 28 | 
             
                  @session_duration = session_duration_from_config
         | 
| 29 | 
            -
                  self.jwt_enabled = options[:jwt_enabled] || Config. | 
| 29 | 
            +
                  self.jwt_enabled = options[:jwt_enabled] || Config.jwt.enabled
         | 
| 30 | 
            +
                  self.jwt_expiry = options[:jwt_expiry] || Config.jwt.expiry
         | 
| 30 31 |  | 
| 31 32 | 
             
                  initial_user_details = if options[:find_current_user_details]
         | 
| 32 33 | 
             
                    find_current_user_details
         | 
| @@ -124,10 +125,19 @@ module IntercomRails | |
| 124 125 | 
             
                def generate_jwt
         | 
| 125 126 | 
             
                  return nil unless user_details[:user_id].present?
         | 
| 126 127 |  | 
| 127 | 
            -
                  payload = {
         | 
| 128 | 
            -
             | 
| 129 | 
            -
             | 
| 130 | 
            -
             | 
| 128 | 
            +
                  payload = { user_id: user_details[:user_id].to_s }
         | 
| 129 | 
            +
             | 
| 130 | 
            +
                  if jwt_expiry
         | 
| 131 | 
            +
                    payload[:exp] = jwt_expiry.from_now.to_i
         | 
| 132 | 
            +
                  end
         | 
| 133 | 
            +
             | 
| 134 | 
            +
                  if Config.jwt.signed_user_fields.present?
         | 
| 135 | 
            +
                    Config.jwt.signed_user_fields.each do |field|
         | 
| 136 | 
            +
                      field = field.to_sym
         | 
| 137 | 
            +
                      payload[field] = user_details[field].to_s if user_details[field].present?
         | 
| 138 | 
            +
                    end
         | 
| 139 | 
            +
                  end
         | 
| 140 | 
            +
             | 
| 131 141 | 
             
                  JWT.encode(payload, secret, 'HS256')
         | 
| 132 142 | 
             
                end
         | 
| 133 143 |  | 
| @@ -139,7 +149,11 @@ module IntercomRails | |
| 139 149 | 
             
                    if secret.present?
         | 
| 140 150 | 
             
                      if jwt_enabled && u[:user_id].present?
         | 
| 141 151 | 
             
                        u[:intercom_user_jwt] ||= generate_jwt
         | 
| 142 | 
            -
                         | 
| 152 | 
            +
                        
         | 
| 153 | 
            +
                        u.delete(:user_id)
         | 
| 154 | 
            +
                        Config.jwt.signed_user_fields&.each do |field|
         | 
| 155 | 
            +
                          u.delete(field.to_sym)
         | 
| 156 | 
            +
                        end
         | 
| 143 157 | 
             
                      elsif (u[:user_id] || u[:email]).present?
         | 
| 144 158 | 
             
                        u[:user_hash] ||= user_hash
         | 
| 145 159 | 
             
                      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.6
         | 
| 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:  | 
| 13 | 
            +
            date: 2025-01-13 00:00:00.000000000 Z
         | 
| 14 14 | 
             
            dependencies:
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 16 16 | 
             
              name: activesupport
         |