statsig 1.19.1 → 1.21.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: 768ca65c5f2e54afdc7896eedc8ceb095b44f99ebb861f56ecb10d82c965c9db
4
- data.tar.gz: 9b644e6659565eb44d266fee5d37374f1feee076d789d57c32d744cab6530bb9
3
+ metadata.gz: e976fe13de26ad1653e42b8a5a710210b51234cb96e6eaed6cbd350097f2370f
4
+ data.tar.gz: d0a3e427187fd4ae7cd0ff0b0c0e3c2bb88c3cf5dd7ed14a272f5dae89b18ea1
5
5
  SHA512:
6
- metadata.gz: fca05aceecc4389eec081e98159bcaef3aa1ca91447c99770c62cad3e5e16f5ebf500edf257081b051462028c47cfee060fe41ab362db4468429faea88516872
7
- data.tar.gz: 64755e9303545ba9915e241460c4468a508dcad79057bc4475ba68d6e8edd3fa874e89f1d0709557121bffd037c11ab0d7d229c0da0fb61369a5b0f75e4ec6ee
6
+ metadata.gz: 2eeaf918074df7b66ffd9746d7f1717efa1912be27e86698c44bd57869f2ca023590d5db9779bbf0b3312a26735781b51afc5fd7a5e726f13fc5af00f7395fec
7
+ data.tar.gz: '08d264d18cd2c772f05886782999e8c5703cf92d006a3395f57af84795b4cd309b8a7efe4d98b9e9d62378f584eb3735f3c299f859f0a46e660013e543780dca'
data/lib/statsig.rb CHANGED
@@ -21,6 +21,8 @@ module Statsig
21
21
  return @shared_instance
22
22
  end
23
23
 
24
+ self.bind_sorbet_loggers(options)
25
+
24
26
  @shared_instance = StatsigDriver.new(secret_key, options, error_callback)
25
27
  end
26
28
 
@@ -225,7 +227,7 @@ module Statsig
225
227
  def self.get_statsig_metadata
226
228
  {
227
229
  'sdkType' => 'ruby-server',
228
- 'sdkVersion' => '1.19.1',
230
+ 'sdkVersion' => '1.21.0',
229
231
  }
230
232
  end
231
233
 
@@ -237,20 +239,30 @@ module Statsig
237
239
  end
238
240
  end
239
241
 
240
- T::Configuration.call_validation_error_handler = lambda do |signature, opts|
241
- puts "[Type Error] " + opts[:pretty_message]
242
- end
242
+ sig { params(options: T.any(StatsigOptions, NilClass)).void }
243
243
 
244
- T::Configuration.inline_type_error_handler = lambda do |error, opts|
245
- puts "[Type Error] " + error.message
246
- end
244
+ def self.bind_sorbet_loggers(options)
245
+ if options&.disable_sorbet_logging_handlers == true
246
+ return
247
+ end
247
248
 
248
- T::Configuration.sig_builder_error_handler = lambda do |error, location|
249
- puts "[Type Error] " + error.message
250
- end
249
+ T::Configuration.call_validation_error_handler = lambda do |signature, opts|
250
+ puts "[Type Error] " + opts[:pretty_message]
251
+ end
252
+
253
+ T::Configuration.inline_type_error_handler = lambda do |error, opts|
254
+ puts "[Type Error] " + error.message
255
+ end
256
+
257
+ T::Configuration.sig_builder_error_handler = lambda do |error, location|
258
+ puts "[Type Error] " + error.message
259
+ end
260
+
261
+ T::Configuration.sig_validation_error_handler = lambda do |error, opts|
262
+ puts "[Type Error] " + error.message
263
+ end
251
264
 
252
- T::Configuration.sig_validation_error_handler = lambda do |error, opts|
253
- puts "[Type Error] " + error.message
265
+ return
254
266
  end
255
267
 
256
268
  end
@@ -69,6 +69,12 @@ class StatsigOptions
69
69
  # default: false
70
70
  attr_accessor :disable_diagnostics_logging
71
71
 
72
+ sig { returns(T::Boolean) }
73
+ # Statsig utilizes Sorbet (https://sorbet.org) to ensure type safety of the SDK. This includes logging
74
+ # to console when errors are detected. You can disable this logging by setting this flag to true.
75
+ # default: false
76
+ attr_accessor :disable_sorbet_logging_handlers
77
+
72
78
  sig do
73
79
  params(
74
80
  environment: T.any(T::Hash[String, String], NilClass),
@@ -82,7 +88,8 @@ class StatsigOptions
82
88
  rules_updated_callback: T.any(Method, Proc, NilClass),
83
89
  data_store: T.any(Statsig::Interfaces::IDataStore, NilClass),
84
90
  idlist_threadpool_size: Integer,
85
- disable_diagnostics_logging: T::Boolean
91
+ disable_diagnostics_logging: T::Boolean,
92
+ disable_sorbet_logging_handlers: T::Boolean
86
93
  ).void
87
94
  end
88
95
 
@@ -98,7 +105,8 @@ class StatsigOptions
98
105
  rules_updated_callback: nil,
99
106
  data_store: nil,
100
107
  idlist_threadpool_size: 3,
101
- disable_diagnostics_logging: false)
108
+ disable_diagnostics_logging: false,
109
+ disable_sorbet_logging_handlers: false)
102
110
  @environment = environment.is_a?(Hash) ? environment : nil
103
111
  @api_url_base = api_url_base
104
112
  @rulesets_sync_interval = rulesets_sync_interval
@@ -111,5 +119,6 @@ class StatsigOptions
111
119
  @data_store = data_store
112
120
  @idlist_threadpool_size = idlist_threadpool_size
113
121
  @disable_diagnostics_logging = disable_diagnostics_logging
122
+ @disable_sorbet_logging_handlers = disable_sorbet_logging_handlers
114
123
  end
115
124
  end
data/lib/statsig_user.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # typed: true
2
2
 
3
3
  require 'sorbet-runtime'
4
+ require 'json'
4
5
 
5
6
  ##
6
7
  # The user object to be evaluated against your Statsig configurations (gates/experiments/dynamic configs).
@@ -62,17 +63,24 @@ class StatsigUser
62
63
  sig { params(user_hash: T.any(T::Hash[T.any(String, Symbol), T.untyped], NilClass)).void }
63
64
 
64
65
  def initialize(user_hash)
65
- @user_id = from_hash(user_hash, [:user_id, :userID], String)
66
- @email = from_hash(user_hash, [:email], String)
67
- @ip = from_hash(user_hash, [:ip], String)
68
- @user_agent = from_hash(user_hash, [:user_agent, :userAgent], String)
69
- @country = from_hash(user_hash, [:country], String)
70
- @locale = from_hash(user_hash, [:locale], String)
71
- @app_version = from_hash(user_hash, [:app_version, :appVersion], String)
72
- @custom = from_hash(user_hash, [:custom], Hash)
73
- @private_attributes = from_hash(user_hash, [:private_attributes, :privateAttributes], Hash)
74
- @custom_ids = from_hash(user_hash, [:custom_ids, :customIDs], Hash)
75
- @statsig_environment = from_hash(user_hash, [:statsig_environment, :statsigEnvironment], Hash)
66
+ the_hash = user_hash
67
+ begin
68
+ the_hash = JSON.parse(user_hash&.to_json || "")
69
+ rescue
70
+ puts 'Failed to clone user hash'
71
+ end
72
+
73
+ @user_id = from_hash(the_hash, [:user_id, :userID], String)
74
+ @email = from_hash(the_hash, [:email], String)
75
+ @ip = from_hash(the_hash, [:ip], String)
76
+ @user_agent = from_hash(the_hash, [:user_agent, :userAgent], String)
77
+ @country = from_hash(the_hash, [:country], String)
78
+ @locale = from_hash(the_hash, [:locale], String)
79
+ @app_version = from_hash(the_hash, [:app_version, :appVersion], String)
80
+ @custom = from_hash(the_hash, [:custom], Hash)
81
+ @private_attributes = from_hash(the_hash, [:private_attributes, :privateAttributes], Hash)
82
+ @custom_ids = from_hash(the_hash, [:custom_ids, :customIDs], Hash)
83
+ @statsig_environment = from_hash(the_hash, [:statsig_environment, :statsigEnvironment], Hash)
76
84
  end
77
85
 
78
86
  def serialize(for_logging)
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.19.1
4
+ version: 1.21.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-01-17 00:00:00.000000000 Z
11
+ date: 2023-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -215,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
215
  - !ruby/object:Gem::Version
216
216
  version: '0'
217
217
  requirements: []
218
- rubygems_version: 3.3.26
218
+ rubygems_version: 3.4.1
219
219
  signing_key:
220
220
  specification_version: 4
221
221
  summary: Statsig server SDK for Ruby