mixpanel-ruby-openfeature 0.1.0 → 0.3.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: c55b0da96c5ff5418242aa05d02ace4cc3df3f56045ea320aa076f1e3d714191
4
- data.tar.gz: 4ed81d9dd91eb0be8b1bb1c6fdb77107189c20ace63b47d387d1cda02799d4be
3
+ metadata.gz: e9d29a0e7b9305a412989e730ec11fdd8b4d57ccb88d068ca7ad3b753b0f3e5f
4
+ data.tar.gz: fdf41866d6fa4148febdbcdc11b791c505fb0f79776ed2d135d6a715bf5900ca
5
5
  SHA512:
6
- metadata.gz: 4a69d07836c9366924801df9d947b7e3c6d4a2c62376d66e23a5404db49feefff4b4d80a9156c7fc25e566e1e57c7f8dcaba035391a234f67027501998a17f9b
7
- data.tar.gz: 7056a897f579fbae9f1261289a8a7178a1b6bd35952bcb67312dbf803fa9d630621d05eed5f7d2739d5a00791e54f1b13ce5a456b3faf16e859cc9ca0dea07a0
6
+ metadata.gz: 0b7edd78404f6305f60c15ff90f7945811dd1a88f42aa9e370180ffa001243ee2b66b60d5cda539ebfb2dd7cdb38a4ba302e75fd2ee308a9a4c83018666b6aa0
7
+ data.tar.gz: 624605591a8ba5039d98db770b64109463328278324f1285c26bec30c9a155244e9b315cf6fcee4dc0e3e4231502f543c464da3f8c5f124425317bb6047e1c9f
@@ -69,16 +69,41 @@ module Mixpanel
69
69
 
70
70
  begin
71
71
  result = @flags_provider.get_variant(flag_key, fallback, context, report_exposure: true)
72
- rescue StandardError
73
- return error_result(default_value, ::OpenFeature::SDK::Provider::ErrorCode::GENERAL)
72
+ rescue StandardError => e
73
+ return error_result(default_value, ::OpenFeature::SDK::Provider::ErrorCode::GENERAL, e.message)
74
74
  end
75
75
 
76
- if result.equal?(fallback)
76
+ # variant_source distinguishes local / remote / fallback. When fallback,
77
+ # fallback_reason carries the specific reason (PHP-aligned constants)
78
+ # so we can map each to the spec-correct OpenFeature response instead
79
+ # of collapsing every fallback to FLAG_NOT_FOUND. SDK-83: BACKEND_ERROR
80
+ # also carries the backend message, forwarded as error_message.
81
+ case result.fallback_reason&.kind
82
+ when :flag_not_found
77
83
  return ::OpenFeature::SDK::Provider::ResolutionDetails.new(
78
84
  value: default_value,
79
85
  error_code: ::OpenFeature::SDK::Provider::ErrorCode::FLAG_NOT_FOUND,
80
86
  reason: ::OpenFeature::SDK::Provider::Reason::DEFAULT
81
87
  )
88
+ when :missing_context_key
89
+ return error_result(
90
+ default_value,
91
+ ::OpenFeature::SDK::Provider::ErrorCode::TARGETING_KEY_MISSING,
92
+ result.fallback_reason.message
93
+ )
94
+ when :no_rollout_match
95
+ # Flag exists, user just didn't match any rollout — per the
96
+ # OpenFeature spec this is `reason: DEFAULT` with no error.
97
+ return ::OpenFeature::SDK::Provider::ResolutionDetails.new(
98
+ value: default_value,
99
+ reason: ::OpenFeature::SDK::Provider::Reason::DEFAULT
100
+ )
101
+ when :backend_error
102
+ return error_result(
103
+ default_value,
104
+ ::OpenFeature::SDK::Provider::ErrorCode::GENERAL,
105
+ result.fallback_reason.message
106
+ )
82
107
  end
83
108
 
84
109
  value = result.variant_value
@@ -125,15 +150,19 @@ module Mixpanel
125
150
  end
126
151
 
127
152
  def build_context(evaluation_context)
128
- return {} if evaluation_context.nil?
129
-
130
153
  ctx = {}
131
- if evaluation_context.respond_to?(:fields)
132
- evaluation_context.fields.each { |k, v| ctx[k] = unwrap_value(v) }
133
- end
134
- if evaluation_context.respond_to?(:targeting_key) && evaluation_context.targeting_key
135
- ctx['targetingKey'] = unwrap_value(evaluation_context.targeting_key)
154
+ unless evaluation_context.nil?
155
+ if evaluation_context.respond_to?(:fields)
156
+ evaluation_context.fields.each { |k, v| ctx[k] = unwrap_value(v) }
157
+ end
158
+ if evaluation_context.respond_to?(:targeting_key) && evaluation_context.targeting_key
159
+ ctx['targetingKey'] = unwrap_value(evaluation_context.targeting_key)
160
+ end
136
161
  end
162
+ # SDK-448: marks exposures as coming from the OpenFeature provider. The
163
+ # SDK copies this onto `$experiment_started`; older SDKs ignore the key.
164
+ # Set last so a customer attribute of the same name can't override it.
165
+ ctx['$openfeature_provider'] = true
137
166
  ctx
138
167
  end
139
168
 
@@ -158,10 +187,11 @@ module Mixpanel
158
187
  end
159
188
  end
160
189
 
161
- def error_result(default_value, error_code)
190
+ def error_result(default_value, error_code, error_message = nil)
162
191
  ::OpenFeature::SDK::Provider::ResolutionDetails.new(
163
192
  value: default_value,
164
193
  error_code: error_code,
194
+ error_message: error_message,
165
195
  reason: ::OpenFeature::SDK::Provider::Reason::ERROR
166
196
  )
167
197
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mixpanel
4
+ module OpenFeature
5
+ VERSION = '0.3.0'
6
+ end
7
+ end
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'openfeature/version'
3
4
  require_relative 'openfeature/provider'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixpanel-ruby-openfeature
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mixpanel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-09 00:00:00.000000000 Z
11
+ date: 2026-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: openfeature-sdk
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.1'
33
+ version: '3.5'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.1'
40
+ version: '3.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -88,6 +88,7 @@ extra_rdoc_files: []
88
88
  files:
89
89
  - lib/mixpanel/openfeature.rb
90
90
  - lib/mixpanel/openfeature/provider.rb
91
+ - lib/mixpanel/openfeature/version.rb
91
92
  homepage: https://mixpanel.com
92
93
  licenses:
93
94
  - Apache-2.0