statsig 1.27.0 → 1.28.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 +4 -4
- data/lib/client_initialize_helpers.rb +12 -2
- data/lib/evaluator.rb +3 -2
- data/lib/hash_utils.rb +15 -0
- data/lib/statsig.rb +1 -1
- data/lib/statsig_user.rb +43 -0
- 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: 9a8876d235dc185cdc997a812ce941de80f6d5075fb151e8539b65b354419734
|
4
|
+
data.tar.gz: cc7fb865b12a909eb8bf188d9bc7f0e9ad07a70de6a7ac2e4911b1ceeb830281
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c030c79c5d3b98f9f8b6fba4a2afafebe97ddb3522e4b2788c4b1ec4065bf1e3de7f1f667586a3b34bf8a457d784179fa54745a7bfb949914c33079aa8558e95
|
7
|
+
data.tar.gz: d85ada516a510f48e93109c01c3023c1566f3b5b8afc86c83f44b7ce6179946290e80df3c1ed899efd6cf642282e4e3fd5601987ccdaf3844b841acd8ea5af6f
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# typed: true
|
2
2
|
|
3
3
|
require_relative 'hash_utils'
|
4
|
+
require 'sorbet-runtime'
|
4
5
|
|
5
6
|
$empty_eval_result = {
|
6
7
|
:gate_value => false,
|
@@ -12,6 +13,8 @@ $empty_eval_result = {
|
|
12
13
|
|
13
14
|
module ClientInitializeHelpers
|
14
15
|
class ResponseFormatter
|
16
|
+
extend T::Sig
|
17
|
+
|
15
18
|
def initialize(evaluator, user, hash, client_sdk_key)
|
16
19
|
@evaluator = evaluator
|
17
20
|
@user = user
|
@@ -28,6 +31,13 @@ module ClientInitializeHelpers
|
|
28
31
|
|
29
32
|
private
|
30
33
|
|
34
|
+
sig { params(secondary_exposures: T::Array[T::Hash[String, String]]).returns(T::Array[T::Hash[String, String]]) }
|
35
|
+
def filter_segments_from_secondary_exposures(secondary_exposures)
|
36
|
+
secondary_exposures.reject do |exposure|
|
37
|
+
exposure['gate'].to_s.start_with?('segment:')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
31
41
|
def to_response(config_name, config_spec)
|
32
42
|
target_app_id = @evaluator.spec_store.get_app_id_for_sdk_key(@client_sdk_key)
|
33
43
|
config_target_apps = config_spec['targetAppIDs']
|
@@ -49,7 +59,7 @@ module ClientInitializeHelpers
|
|
49
59
|
:id_type => eval_result.id_type,
|
50
60
|
:config_delegate => eval_result.config_delegate,
|
51
61
|
:is_experiment_group => eval_result.is_experiment_group,
|
52
|
-
:secondary_exposures => eval_result.secondary_exposures,
|
62
|
+
:secondary_exposures => filter_segments_from_secondary_exposures(eval_result.secondary_exposures),
|
53
63
|
:undelegated_sec_exps => eval_result.undelegated_sec_exps
|
54
64
|
}
|
55
65
|
|
@@ -94,7 +104,7 @@ module ClientInitializeHelpers
|
|
94
104
|
"name" => hashed_name,
|
95
105
|
"rule_id" => safe_eval_result[:rule_id],
|
96
106
|
"secondary_exposures" => clean_exposures(safe_eval_result[:secondary_exposures])
|
97
|
-
})]
|
107
|
+
}).compact]
|
98
108
|
end
|
99
109
|
|
100
110
|
def clean_exposures(exposures)
|
data/lib/evaluator.rb
CHANGED
@@ -123,7 +123,8 @@ module Statsig
|
|
123
123
|
"generator" => "statsig-ruby-sdk",
|
124
124
|
"evaluated_keys" => evaluated_keys,
|
125
125
|
"time" => 0,
|
126
|
-
"hash_used" => hash
|
126
|
+
"hash_used" => hash,
|
127
|
+
"user_hash" => user.to_hash_without_stable_id()
|
127
128
|
}
|
128
129
|
end
|
129
130
|
|
@@ -200,7 +201,7 @@ module Statsig
|
|
200
201
|
@spec_store.initial_config_sync_time,
|
201
202
|
@spec_store.init_reason
|
202
203
|
),
|
203
|
-
group_name:
|
204
|
+
group_name: nil,
|
204
205
|
id_type: config['idType']
|
205
206
|
)
|
206
207
|
end
|
data/lib/hash_utils.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'json'
|
1
2
|
module Statsig
|
2
3
|
class HashUtils
|
3
4
|
def self.djb2(input_str)
|
@@ -10,8 +11,22 @@ module Statsig
|
|
10
11
|
return hash.to_s
|
11
12
|
end
|
12
13
|
|
14
|
+
def self.djb2ForHash(input_hash)
|
15
|
+
return djb2(input_hash.to_json)
|
16
|
+
end
|
17
|
+
|
13
18
|
def self.sha256(input_str)
|
14
19
|
return Digest::SHA256.base64digest(input_str)
|
15
20
|
end
|
21
|
+
|
22
|
+
def self.sortHash(input_hash)
|
23
|
+
dictionary = input_hash.clone.sort_by { |key| key }.to_h;
|
24
|
+
input_hash.each do |key, value|
|
25
|
+
if value.is_a?(Hash)
|
26
|
+
dictionary[key] = self.sortHash(value)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
return dictionary
|
30
|
+
end
|
16
31
|
end
|
17
32
|
end
|
data/lib/statsig.rb
CHANGED
data/lib/statsig_user.rb
CHANGED
@@ -103,6 +103,49 @@ class StatsigUser
|
|
103
103
|
hash.compact
|
104
104
|
end
|
105
105
|
|
106
|
+
def to_hash_without_stable_id()
|
107
|
+
hash = {}
|
108
|
+
if @user_id != nil
|
109
|
+
hash['userID'] = @user_id
|
110
|
+
end
|
111
|
+
if @email != nil
|
112
|
+
hash['email'] = @email
|
113
|
+
end
|
114
|
+
if @ip != nil
|
115
|
+
hash['ip'] = @ip
|
116
|
+
end
|
117
|
+
if @user_agent != nil
|
118
|
+
hash['userAgent'] = @user_agent
|
119
|
+
end
|
120
|
+
if @country != nil
|
121
|
+
hash['country'] = @country
|
122
|
+
end
|
123
|
+
if @locale != nil
|
124
|
+
hash['locale'] = @locale
|
125
|
+
end
|
126
|
+
if @app_version != nil
|
127
|
+
hash['appVersion'] = @app_version
|
128
|
+
end
|
129
|
+
if @custom != nil
|
130
|
+
hash['custom'] = Statsig::HashUtils.sortHash(@custom)
|
131
|
+
end
|
132
|
+
if @statsig_environment != nil
|
133
|
+
hash['statsigEnvironment'] = @statsig_environment.clone.sort_by { |key| key }.to_h
|
134
|
+
end
|
135
|
+
if @private_attributes != nil
|
136
|
+
hash['privateAttributes'] = Statsig::HashUtils.sortHash(@private_attributes)
|
137
|
+
end
|
138
|
+
custom_ids = {}
|
139
|
+
if @custom_ids != nil
|
140
|
+
custom_ids = @custom_ids.clone
|
141
|
+
if custom_ids.key?("stableID")
|
142
|
+
custom_ids.delete("stableID")
|
143
|
+
end
|
144
|
+
end
|
145
|
+
hash['customIDs'] = custom_ids.sort_by { |key| key }.to_h
|
146
|
+
return Statsig::HashUtils.djb2ForHash(hash.sort_by { |key| key }.to_h)
|
147
|
+
end
|
148
|
+
|
106
149
|
def value_lookup
|
107
150
|
{
|
108
151
|
'userID' => @user_id,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statsig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.28.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Statsig, Inc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|