mixpanel-ruby 3.3.0 → 3.5.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/.github/workflows/release-rubygems.yml +1 -1
- data/.github/workflows/ruby.yml +10 -4
- data/CHANGELOG.md +21 -0
- data/Readme.rdoc +39 -8
- data/lib/mixpanel-ruby/events.rb +16 -1
- data/lib/mixpanel-ruby/flags/custom_operators.rb +207 -0
- data/lib/mixpanel-ruby/flags/flags_provider.rb +5 -0
- data/lib/mixpanel-ruby/flags/local_flags_provider.rb +5 -1
- data/lib/mixpanel-ruby/tracker.rb +11 -7
- data/lib/mixpanel-ruby/version.rb +1 -1
- data/mixpanel-ruby.gemspec +1 -1
- data/openfeature-provider/CHANGELOG.md +10 -0
- data/openfeature-provider/README.md +1 -1
- data/openfeature-provider/lib/mixpanel/openfeature/provider.rb +11 -7
- data/openfeature-provider/lib/mixpanel/openfeature/version.rb +1 -1
- data/openfeature-provider/mixpanel-ruby-openfeature.gemspec +1 -1
- data/openfeature-provider/spec/mixpanel_openfeature_provider_spec.rb +45 -8
- data/spec/fixtures/datetime_compare_tests.json +100 -0
- data/spec/fixtures/semver_compare_tests.json +161 -0
- data/spec/mixpanel-ruby/events_spec.rb +103 -0
- data/spec/mixpanel-ruby/flags/custom_operators_spec.rb +74 -0
- data/spec/mixpanel-ruby/flags/local_flags_spec.rb +109 -0
- data/spec/mixpanel-ruby/flags/remote_flags_spec.rb +34 -0
- data/spec/mixpanel-ruby/tracker_spec.rb +63 -0
- metadata +8 -4
|
@@ -486,6 +486,68 @@ describe Mixpanel::Flags::LocalFlagsProvider do
|
|
|
486
486
|
expect(result).to eq('fallback')
|
|
487
487
|
end
|
|
488
488
|
|
|
489
|
+
it 'respects runtime evaluation rule with semver_compare operator when satisfied' do
|
|
490
|
+
runtime_eval = {
|
|
491
|
+
'semver_compare' => [{'var' => 'app_version'}, '>=', '1.2.0']
|
|
492
|
+
}
|
|
493
|
+
flag = create_test_flag(runtime_evaluation_rule: runtime_eval)
|
|
494
|
+
|
|
495
|
+
stub_flag_definitions([flag])
|
|
496
|
+
provider.start_polling_for_definitions!
|
|
497
|
+
|
|
498
|
+
context = user_context_with_properties({'app_version' => '1.5.0'})
|
|
499
|
+
result = provider.get_variant_value('test_flag', 'fallback', context)
|
|
500
|
+
|
|
501
|
+
expect(result).not_to eq('fallback')
|
|
502
|
+
expect(['control', 'treatment']).to include(result)
|
|
503
|
+
end
|
|
504
|
+
|
|
505
|
+
it 'respects runtime evaluation rule with semver_compare operator when not satisfied' do
|
|
506
|
+
runtime_eval = {
|
|
507
|
+
'semver_compare' => [{'var' => 'app_version'}, '>=', '1.2.0']
|
|
508
|
+
}
|
|
509
|
+
flag = create_test_flag(runtime_evaluation_rule: runtime_eval)
|
|
510
|
+
|
|
511
|
+
stub_flag_definitions([flag])
|
|
512
|
+
provider.start_polling_for_definitions!
|
|
513
|
+
|
|
514
|
+
context = user_context_with_properties({'app_version' => '1.0.0'})
|
|
515
|
+
result = provider.get_variant_value('test_flag', 'fallback', context)
|
|
516
|
+
|
|
517
|
+
expect(result).to eq('fallback')
|
|
518
|
+
end
|
|
519
|
+
|
|
520
|
+
it 'respects runtime evaluation rule with datetime_compare operator when satisfied' do
|
|
521
|
+
runtime_eval = {
|
|
522
|
+
'datetime_compare' => [{'var' => 'signup'}, '>=', 1_784_160_000_000]
|
|
523
|
+
}
|
|
524
|
+
flag = create_test_flag(runtime_evaluation_rule: runtime_eval)
|
|
525
|
+
|
|
526
|
+
stub_flag_definitions([flag])
|
|
527
|
+
provider.start_polling_for_definitions!
|
|
528
|
+
|
|
529
|
+
context = user_context_with_properties({'signup' => '2026-07-17T00:00:00Z'})
|
|
530
|
+
result = provider.get_variant_value('test_flag', 'fallback', context)
|
|
531
|
+
|
|
532
|
+
expect(result).not_to eq('fallback')
|
|
533
|
+
expect(['control', 'treatment']).to include(result)
|
|
534
|
+
end
|
|
535
|
+
|
|
536
|
+
it 'respects runtime evaluation rule with datetime_compare operator when not satisfied' do
|
|
537
|
+
runtime_eval = {
|
|
538
|
+
'datetime_compare' => [{'var' => 'signup'}, '>=', 1_784_160_000_000]
|
|
539
|
+
}
|
|
540
|
+
flag = create_test_flag(runtime_evaluation_rule: runtime_eval)
|
|
541
|
+
|
|
542
|
+
stub_flag_definitions([flag])
|
|
543
|
+
provider.start_polling_for_definitions!
|
|
544
|
+
|
|
545
|
+
context = user_context_with_properties({'signup' => '2026-07-15T00:00:00Z'})
|
|
546
|
+
result = provider.get_variant_value('test_flag', 'fallback', context)
|
|
547
|
+
|
|
548
|
+
expect(result).to eq('fallback')
|
|
549
|
+
end
|
|
550
|
+
|
|
489
551
|
it 'picks correct variant with hundred percent split' do
|
|
490
552
|
variants = [
|
|
491
553
|
{ 'key' => 'A', 'value' => 'variant_a', 'is_control' => false, 'split' => 100.0 },
|
|
@@ -592,6 +654,53 @@ describe Mixpanel::Flags::LocalFlagsProvider do
|
|
|
592
654
|
provider.get_variant_value('test_flag', 'fallback', { 'distinct_id' => 'qa_user' })
|
|
593
655
|
end
|
|
594
656
|
|
|
657
|
+
it 'marks exposure with $openfeature_provider when context carries the marker (SDK-448)' do
|
|
658
|
+
flag = create_test_flag
|
|
659
|
+
stub_flag_definitions([flag])
|
|
660
|
+
provider.start_polling_for_definitions!
|
|
661
|
+
|
|
662
|
+
captured = nil
|
|
663
|
+
expect(mock_tracker).to receive(:call).once do |_distinct_id, _event_name, properties|
|
|
664
|
+
captured = properties
|
|
665
|
+
end
|
|
666
|
+
|
|
667
|
+
result = provider.get_variant_value('test_flag', 'fallback', test_context.merge('$openfeature_provider' => true))
|
|
668
|
+
|
|
669
|
+
# The marker must not change variant assignment.
|
|
670
|
+
expect(result).to eq(provider.get_variant_value('test_flag', 'fallback', test_context, report_exposure: false))
|
|
671
|
+
expect(captured['$openfeature_provider']).to eq(true)
|
|
672
|
+
end
|
|
673
|
+
|
|
674
|
+
it 'accepts a symbol-keyed $openfeature_provider marker (SDK-448)' do
|
|
675
|
+
flag = create_test_flag
|
|
676
|
+
stub_flag_definitions([flag])
|
|
677
|
+
provider.start_polling_for_definitions!
|
|
678
|
+
|
|
679
|
+
captured = nil
|
|
680
|
+
expect(mock_tracker).to receive(:call).once do |_distinct_id, _event_name, properties|
|
|
681
|
+
captured = properties
|
|
682
|
+
end
|
|
683
|
+
|
|
684
|
+
provider.get_variant_value('test_flag', 'fallback', test_context.merge('$openfeature_provider': true))
|
|
685
|
+
|
|
686
|
+
expect(captured['$openfeature_provider']).to eq(true)
|
|
687
|
+
end
|
|
688
|
+
|
|
689
|
+
it 'omits $openfeature_provider from exposure for direct SDK calls (SDK-448)' do
|
|
690
|
+
flag = create_test_flag
|
|
691
|
+
stub_flag_definitions([flag])
|
|
692
|
+
provider.start_polling_for_definitions!
|
|
693
|
+
|
|
694
|
+
captured = nil
|
|
695
|
+
expect(mock_tracker).to receive(:call).once do |_distinct_id, _event_name, properties|
|
|
696
|
+
captured = properties
|
|
697
|
+
end
|
|
698
|
+
|
|
699
|
+
provider.get_variant_value('test_flag', 'fallback', test_context)
|
|
700
|
+
|
|
701
|
+
expect(captured).not_to have_key('$openfeature_provider')
|
|
702
|
+
end
|
|
703
|
+
|
|
595
704
|
it 'does not track exposure on fallback' do
|
|
596
705
|
stub_flag_definitions([])
|
|
597
706
|
provider.start_polling_for_definitions!
|
|
@@ -303,6 +303,40 @@ describe Mixpanel::Flags::RemoteFlagsProvider do
|
|
|
303
303
|
provider.get_variant('test-flag', fallback_variant, test_context)
|
|
304
304
|
end
|
|
305
305
|
|
|
306
|
+
it 'marks exposure with $openfeature_provider when context carries the marker (SDK-448)' do
|
|
307
|
+
stub_flags_request(create_success_response({
|
|
308
|
+
'test-flag' => { 'variant_key' => 'treatment', 'variant_value' => true }
|
|
309
|
+
}))
|
|
310
|
+
fallback_variant = Mixpanel::Flags::SelectedVariant.new(variant_key: 'control', variant_value: false)
|
|
311
|
+
|
|
312
|
+
captured = nil
|
|
313
|
+
expect(mock_tracker).to receive(:call).once do |_distinct_id, _event_name, properties|
|
|
314
|
+
captured = properties
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
result = provider.get_variant('test-flag', fallback_variant, test_context.merge('$openfeature_provider' => true))
|
|
318
|
+
|
|
319
|
+
expect(result.variant_key).to eq('treatment')
|
|
320
|
+
expect(captured['Flag evaluation mode']).to eq('remote')
|
|
321
|
+
expect(captured['$openfeature_provider']).to eq(true)
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
it 'omits $openfeature_provider from exposure for direct SDK calls (SDK-448)' do
|
|
325
|
+
stub_flags_request(create_success_response({
|
|
326
|
+
'test-flag' => { 'variant_key' => 'treatment', 'variant_value' => true }
|
|
327
|
+
}))
|
|
328
|
+
fallback_variant = Mixpanel::Flags::SelectedVariant.new(variant_key: 'control', variant_value: false)
|
|
329
|
+
|
|
330
|
+
captured = nil
|
|
331
|
+
expect(mock_tracker).to receive(:call).once do |_distinct_id, _event_name, properties|
|
|
332
|
+
captured = properties
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
provider.get_variant('test-flag', fallback_variant, test_context)
|
|
336
|
+
|
|
337
|
+
expect(captured).not_to have_key('$openfeature_provider')
|
|
338
|
+
end
|
|
339
|
+
|
|
306
340
|
it 'does not track exposure event when fallback variant is selected' do
|
|
307
341
|
stub_flags_request(create_success_response({}))
|
|
308
342
|
|
|
@@ -10,6 +10,69 @@ describe Mixpanel::Tracker do
|
|
|
10
10
|
allow(Time).to receive(:now).and_return(@time_now)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
describe 'import rejected by the server (GitHub #106)' do
|
|
14
|
+
before(:each) { WebMock.reset! }
|
|
15
|
+
|
|
16
|
+
it 'returns true, sends Basic Auth and project_id, and prints nothing when /import accepts the event' do
|
|
17
|
+
stub_request(:post, 'https://api.mixpanel.com/import?project_id=123').
|
|
18
|
+
to_return(status: 200, body: '{"code": 200, "num_records_imported": 1, "status": 1}')
|
|
19
|
+
credentials = Mixpanel::ServiceAccountCredentials.new('sa-user', 'sa-secret', 123)
|
|
20
|
+
tracker = Mixpanel::Tracker.new('TEST TOKEN', credentials: credentials)
|
|
21
|
+
|
|
22
|
+
result = nil
|
|
23
|
+
expect {
|
|
24
|
+
result = tracker.import_events('ID', 'Import', { 'time' => 1369353600 })
|
|
25
|
+
}.not_to output.to_stderr
|
|
26
|
+
expect(result).to be true
|
|
27
|
+
|
|
28
|
+
expect(WebMock).to have_requested(:post, 'https://api.mixpanel.com/import?project_id=123').
|
|
29
|
+
with(basic_auth: ['sa-user', 'sa-secret']) { |req|
|
|
30
|
+
form = URI.decode_www_form(req.body).to_h
|
|
31
|
+
payload = JSON.parse(Base64.decode64(form['data']))
|
|
32
|
+
!form.key?('api_key') && payload['event'] == 'Import' &&
|
|
33
|
+
payload['properties']['distinct_id'] == 'ID' && payload['properties']['time'] == 1369353600
|
|
34
|
+
}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'does not claim rejection when /import returns 200 with an unreadable body' do
|
|
38
|
+
stub_request(:post, 'https://api.mixpanel.com/import?project_id=123').
|
|
39
|
+
to_return(status: 200, body: '<html>bad gateway</html>')
|
|
40
|
+
credentials = Mixpanel::ServiceAccountCredentials.new('user', 'secret', 123)
|
|
41
|
+
tracker = Mixpanel::Tracker.new('TEST TOKEN', credentials: credentials)
|
|
42
|
+
|
|
43
|
+
result = nil
|
|
44
|
+
expect {
|
|
45
|
+
result = tracker.import_events('ID', 'Import', { 'time' => 1369353600 })
|
|
46
|
+
}.to output(/\[Mixpanel\] import failed; the event may not have been stored: Could not interpret/).to_stderr
|
|
47
|
+
expect(result).to be false
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'returns false and warns when /import rejects service account credentials' do
|
|
51
|
+
stub_request(:post, 'https://api.mixpanel.com/import?project_id=123').
|
|
52
|
+
to_return(status: 401, body: '{"error": "Invalid credentials", "status": 0}')
|
|
53
|
+
credentials = Mixpanel::ServiceAccountCredentials.new('user', 'bad-secret', 123)
|
|
54
|
+
tracker = Mixpanel::Tracker.new('TEST TOKEN', credentials: credentials)
|
|
55
|
+
|
|
56
|
+
result = nil
|
|
57
|
+
expect {
|
|
58
|
+
result = tracker.import_events('ID', 'Import', { 'time' => 1369353600 })
|
|
59
|
+
}.to output(/\[Mixpanel\] import failed; the event may not have been stored: .*401/).to_stderr
|
|
60
|
+
expect(result).to be false
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'returns false and warns when /import rejects a legacy api_key' do
|
|
64
|
+
stub_request(:post, 'https://api.mixpanel.com/import').
|
|
65
|
+
to_return(status: 401, body: '{"error": "Unauthorized", "status": 0}')
|
|
66
|
+
tracker = Mixpanel::Tracker.new('TEST TOKEN')
|
|
67
|
+
|
|
68
|
+
result = nil
|
|
69
|
+
expect {
|
|
70
|
+
result = tracker.import('API_KEY', 'ID', 'Import', { 'time' => 1369353600 })
|
|
71
|
+
}.to output(/may be rejected by Mixpanel's \/import endpoint.*\[Mixpanel\] import failed; the event may not have been stored/m).to_stderr
|
|
72
|
+
expect(result).to be false
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
13
76
|
it 'should send an alias message to mixpanel no matter what the consumer is' do
|
|
14
77
|
WebMock.reset!
|
|
15
78
|
stub_request(:any, 'https://api.mixpanel.com/track').to_return({:body => '{"status": 1, "error": null}'})
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mixpanel-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.5.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-
|
|
11
|
+
date: 2026-11-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: mutex_m
|
|
@@ -44,14 +44,14 @@ dependencies:
|
|
|
44
44
|
requirements:
|
|
45
45
|
- - "~>"
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: 0.
|
|
47
|
+
version: '0.3'
|
|
48
48
|
type: :runtime
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: 0.
|
|
54
|
+
version: '0.3'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: activesupport
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -194,6 +194,7 @@ files:
|
|
|
194
194
|
- lib/mixpanel-ruby/credentials.rb
|
|
195
195
|
- lib/mixpanel-ruby/error.rb
|
|
196
196
|
- lib/mixpanel-ruby/events.rb
|
|
197
|
+
- lib/mixpanel-ruby/flags/custom_operators.rb
|
|
197
198
|
- lib/mixpanel-ruby/flags/flags_provider.rb
|
|
198
199
|
- lib/mixpanel-ruby/flags/local_flags_provider.rb
|
|
199
200
|
- lib/mixpanel-ruby/flags/remote_flags_provider.rb
|
|
@@ -214,11 +215,14 @@ files:
|
|
|
214
215
|
- openfeature-provider/mixpanel-ruby-openfeature.gemspec
|
|
215
216
|
- openfeature-provider/spec/mixpanel_openfeature_provider_spec.rb
|
|
216
217
|
- openfeature-provider/spec/spec_helper.rb
|
|
218
|
+
- spec/fixtures/datetime_compare_tests.json
|
|
219
|
+
- spec/fixtures/semver_compare_tests.json
|
|
217
220
|
- spec/mixpanel-ruby/consumer_spec.rb
|
|
218
221
|
- spec/mixpanel-ruby/credentials_security_spec.rb
|
|
219
222
|
- spec/mixpanel-ruby/credentials_spec.rb
|
|
220
223
|
- spec/mixpanel-ruby/error_spec.rb
|
|
221
224
|
- spec/mixpanel-ruby/events_spec.rb
|
|
225
|
+
- spec/mixpanel-ruby/flags/custom_operators_spec.rb
|
|
222
226
|
- spec/mixpanel-ruby/flags/local_flags_spec.rb
|
|
223
227
|
- spec/mixpanel-ruby/flags/remote_flags_spec.rb
|
|
224
228
|
- spec/mixpanel-ruby/flags/types_spec.rb
|