launchdarkly-server-sdk 6.0.0 → 6.1.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: fd5b1ccdc654b9ca033547f366d12fe0dde0d25245459de79f9cf1e3ed0e9b79
4
- data.tar.gz: ee6461f8365f0df76055b8c1e5e71b58934df15b24bba22c8b61eb99619b21dc
3
+ metadata.gz: 660fcdc21e7d6c74b118c02e180fc0a2a08279d4c936f4d01b45244e2df88732
4
+ data.tar.gz: 0fc47ce28bb8e66ef1e0c93b06499990366c749adc32250b368d7b25573c971f
5
5
  SHA512:
6
- metadata.gz: d6723297fc581f47325f0147f915efa543f1daf27d01af6d63a13546a5d18e800743060478e9f40c62083ceae5bcd8acfaa8c84d83fc870b893069ae51a9f519
7
- data.tar.gz: 89b4885e33f1ebf61fd88b4a65c4da060087901aaf9772100875888b0983f420099b23971c6b8ba8d71697da410daf0b43e88c946192cb8899682aff9b77a64d
6
+ metadata.gz: 8c93e00623d1e6f954974a3128bd19c31b669eaa440460d1b14c30f4b9581b5aee2c06cf040f2fcbdd815a38384388d3b606c65834ffc4057ade87a083d1eda3
7
+ data.tar.gz: ef7d3c86a418ab1bb07e3b444107fc92d0472e9fe1a2ed9ef87a57527d72a2c63ce6007ad39dd5ff22f242ea420c4524bb292d8a9e3e18d8ebadb4042d82e1d5
data/.circleci/config.yml CHANGED
@@ -20,7 +20,7 @@ jobs:
20
20
  LD_RELEASE_DOCS_TITLE: ""
21
21
  LD_RELEASE_PROJECT: "ruby-server-sdk"
22
22
  LD_RELEASE_PROJECT_TEMPLATE: "ruby"
23
- LD_RELEASE_VERSION: "6.0.0"
23
+ LD_RELEASE_VERSION: "6.1.0"
24
24
  LD_SKIP_DATABASE_TESTS: "1"
25
25
  steps:
26
26
  - checkout
data/CHANGELOG.md CHANGED
@@ -10,6 +10,7 @@ All notable changes to the LaunchDarkly Ruby SDK will be documented in this file
10
10
  - Switched to the `http` gem instead of `socketry` (with a custom http client) for streaming, and instead of `Net::HTTP` for polling / events.
11
11
  - Dropped support for Ruby < version 2.5
12
12
  - Dropped support for JRuby < version 9.2
13
+ - Switched the default polling domain from `app.launchdarkly.com` to `sdk.launchdarkly.com`.
13
14
 
14
15
  ## [5.8.2] - 2021-01-19
15
16
  ### Fixed:
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- launchdarkly-server-sdk (6.0.0)
4
+ launchdarkly-server-sdk (6.1.0)
5
5
  concurrent-ruby (~> 1.1)
6
6
  http (~> 4.4.1)
7
7
  json (~> 2.3.1)
@@ -113,4 +113,4 @@ DEPENDENCIES
113
113
  webrick (~> 1.7)
114
114
 
115
115
  BUNDLED WITH
116
- 2.2.6
116
+ 2.2.8
data/README.md CHANGED
@@ -55,4 +55,3 @@ About LaunchDarkly
55
55
  * [docs.launchdarkly.com](https://docs.launchdarkly.com/ "LaunchDarkly Documentation") for our documentation and SDK reference guides
56
56
  * [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ "LaunchDarkly API Documentation") for our API documentation
57
57
  * [blog.launchdarkly.com](https://blog.launchdarkly.com/ "LaunchDarkly Blog Documentation") for the latest product updates
58
- * [Feature Flagging Guide](https://github.com/launchdarkly/featureflags/ "Feature Flagging Guide") for best practices and strategies
data/azure-pipelines.yml CHANGED
@@ -45,7 +45,7 @@ jobs:
45
45
  workingDirectory: $(System.DefaultWorkingDirectory)
46
46
  script: |
47
47
  ruby -v
48
- gem install bundler
48
+ gem install bundler:2.2.7
49
49
  bundle install
50
50
  mkdir rspec
51
51
  bundle exec rspec --format progress --format RspecJunitFormatter -o ./rspec/rspec.xml spec
@@ -439,6 +439,7 @@ module LaunchDarkly
439
439
  out[:variation] = event[:variation] if event.has_key?(:variation)
440
440
  out[:version] = event[:version] if event.has_key?(:version)
441
441
  out[:prereqOf] = event[:prereqOf] if event.has_key?(:prereqOf)
442
+ out[:contextKind] = event[:contextKind] if event.has_key?(:contextKind)
442
443
  if @inline_users || is_debug
443
444
  out[:user] = process_user(event)
444
445
  else
@@ -466,6 +467,7 @@ module LaunchDarkly
466
467
  out[:userKey] = event[:user].nil? ? nil : event[:user][:key]
467
468
  end
468
469
  out[:metricValue] = event[:metricValue] if event.has_key?(:metricValue)
470
+ out[:contextKind] = event[:contextKind] if event.has_key?(:contextKind)
469
471
  out
470
472
  when "index"
471
473
  {
@@ -28,6 +28,7 @@ module LaunchDarkly
28
28
  e[:debugEventsUntilDate] = flag[:debugEventsUntilDate] if flag[:debugEventsUntilDate]
29
29
  e[:prereqOf] = prereq_of_flag[:key] if !prereq_of_flag.nil?
30
30
  e[:reason] = detail.reason if add_experiment_data || @with_reasons
31
+ e[:contextKind] = context_to_context_kind(user) if !user.nil? && user[:anonymous]
31
32
  e
32
33
  end
33
34
 
@@ -43,6 +44,7 @@ module LaunchDarkly
43
44
  e[:trackEvents] = true if flag[:trackEvents]
44
45
  e[:debugEventsUntilDate] = flag[:debugEventsUntilDate] if flag[:debugEventsUntilDate]
45
46
  e[:reason] = reason if @with_reasons
47
+ e[:contextKind] = context_to_context_kind(user) if !user.nil? && user[:anonymous]
46
48
  e
47
49
  end
48
50
 
@@ -55,6 +57,7 @@ module LaunchDarkly
55
57
  default: default_value
56
58
  }
57
59
  e[:reason] = reason if @with_reasons
60
+ e[:contextKind] = context_to_context_kind(user) if !user.nil? && user[:anonymous]
58
61
  e
59
62
  end
60
63
 
@@ -66,6 +69,16 @@ module LaunchDarkly
66
69
  }
67
70
  end
68
71
 
72
+ def new_alias_event(current_context, previous_context)
73
+ {
74
+ kind: 'alias',
75
+ key: current_context[:key],
76
+ contextKind: context_to_context_kind(current_context),
77
+ previousKey: previous_context[:key],
78
+ previousContextKind: context_to_context_kind(previous_context)
79
+ }
80
+ end
81
+
69
82
  def new_custom_event(event_name, user, data, metric_value)
70
83
  e = {
71
84
  kind: 'custom',
@@ -74,11 +87,20 @@ module LaunchDarkly
74
87
  }
75
88
  e[:data] = data if !data.nil?
76
89
  e[:metricValue] = metric_value if !metric_value.nil?
90
+ e[:contextKind] = context_to_context_kind(user) if !user.nil? && user[:anonymous]
77
91
  e
78
92
  end
79
93
 
80
94
  private
81
95
 
96
+ def context_to_context_kind(user)
97
+ if !user.nil? && user[:anonymous]
98
+ return "anonymousUser"
99
+ else
100
+ return "user"
101
+ end
102
+ end
103
+
82
104
  def is_experiment(flag, reason)
83
105
  return false if !reason
84
106
  case reason[:kind]
@@ -282,6 +282,23 @@ module LaunchDarkly
282
282
  @event_processor.add_event(@event_factory_default.new_custom_event(event_name, user, data, metric_value))
283
283
  end
284
284
 
285
+ #
286
+ # Associates a new and old user object for analytics purposes via an alias event.
287
+ #
288
+ # @param current_context [Hash] The current version of a user.
289
+ # @param previous_context [Hash] The previous version of a user.
290
+ # @return [void]
291
+ #
292
+ def alias(current_context, previous_context)
293
+ if !current_context || current_context[:key].nil? || !previous_context || previous_context[:key].nil?
294
+ @config.logger.warn("Alias called with nil user or nil user key!")
295
+ return
296
+ end
297
+ sanitize_user(current_context)
298
+ sanitize_user(previous_context)
299
+ @event_processor.add_event(@event_factory_default.new_alias_event(current_context, previous_context))
300
+ end
301
+
285
302
  #
286
303
  # Returns all feature flag values for the given user.
287
304
  #
@@ -1,3 +1,3 @@
1
1
  module LaunchDarkly
2
- VERSION = "6.0.0"
2
+ VERSION = "6.1.0"
3
3
  end
data/spec/events_spec.rb CHANGED
@@ -408,6 +408,16 @@ describe LaunchDarkly::EventProcessor do
408
408
  end
409
409
  end
410
410
 
411
+ it "queues alias event" do
412
+ with_processor_and_sender(default_config) do |ep, sender|
413
+ e = { kind: "alias", key: "a", contextKind: "user", previousKey: "b", previousContextKind: "user" }
414
+ ep.add_event(e)
415
+
416
+ output = flush_and_get_events(ep, sender)
417
+ expect(output).to contain_exactly(e)
418
+ end
419
+ end
420
+
411
421
  it "treats nil value for custom the same as an empty hash" do
412
422
  with_processor_and_sender(default_config) do |ep, sender|
413
423
  user_with_nil_custom = { key: "userkey", custom: nil }
@@ -25,6 +25,12 @@ describe LaunchDarkly::LDClient do
25
25
  }
26
26
  }
27
27
  end
28
+ let(:user_anonymous) do
29
+ {
30
+ key: "anonymous@test.com",
31
+ anonymous: true
32
+ }
33
+ end
28
34
  let(:numeric_key_user) do
29
35
  {
30
36
  key: 33,
@@ -155,6 +161,24 @@ describe LaunchDarkly::LDClient do
155
161
  client.variation("key", nil, "default")
156
162
  end
157
163
 
164
+ it "queues a feature event for an existing feature when user is anonymous" do
165
+ config.feature_store.init({ LaunchDarkly::FEATURES => {} })
166
+ config.feature_store.upsert(LaunchDarkly::FEATURES, feature_with_value)
167
+ expect(event_processor).to receive(:add_event).with(hash_including(
168
+ kind: "feature",
169
+ key: "key",
170
+ version: 100,
171
+ contextKind: "anonymousUser",
172
+ user: user_anonymous,
173
+ variation: 0,
174
+ value: "value",
175
+ default: "default",
176
+ trackEvents: true,
177
+ debugEventsUntilDate: 1000
178
+ ))
179
+ client.variation("key", user_anonymous, "default")
180
+ end
181
+
158
182
  it "queues a feature event for an existing feature when user key is nil" do
159
183
  config.feature_store.init({ LaunchDarkly::FEATURES => {} })
160
184
  config.feature_store.upsert(LaunchDarkly::FEATURES, feature_with_value)
@@ -455,6 +479,12 @@ describe LaunchDarkly::LDClient do
455
479
  client.track("custom_event_name", user, nil, 1.5)
456
480
  end
457
481
 
482
+ it "includes contextKind with anonymous user" do
483
+ expect(event_processor).to receive(:add_event).with(hash_including(
484
+ kind: "custom", key: "custom_event_name", user: user_anonymous, metricValue: 2.2, contextKind: "anonymousUser"))
485
+ client.track("custom_event_name", user_anonymous, nil, 2.2)
486
+ end
487
+
458
488
  it "sanitizes the user in the event" do
459
489
  expect(event_processor).to receive(:add_event).with(hash_including(user: sanitized_numeric_key_user))
460
490
  client.track("custom_event_name", numeric_key_user, nil)
@@ -473,6 +503,26 @@ describe LaunchDarkly::LDClient do
473
503
  end
474
504
  end
475
505
 
506
+ describe '#alias' do
507
+ it "queues up an alias event" do
508
+ expect(event_processor).to receive(:add_event).with(hash_including(
509
+ kind: "alias", key: user[:key], contextKind: "user", previousKey: user_anonymous[:key], previousContextKind: "anonymousUser"))
510
+ client.alias(user, user_anonymous)
511
+ end
512
+
513
+ it "does not send an event, and logs a warning, if user is nil" do
514
+ expect(event_processor).not_to receive(:add_event)
515
+ expect(logger).to receive(:warn)
516
+ client.alias(nil, nil)
517
+ end
518
+
519
+ it "does not send an event, and logs a warning, if user key is nil" do
520
+ expect(event_processor).not_to receive(:add_event)
521
+ expect(logger).to receive(:warn)
522
+ client.alias(user_without_key, user_without_key)
523
+ end
524
+ end
525
+
476
526
  describe '#identify' do
477
527
  it "queues up an identify event" do
478
528
  expect(event_processor).to receive(:add_event).with(hash_including(kind: "identify", key: user[:key], user: user))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: launchdarkly-server-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - LaunchDarkly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-26 00:00:00.000000000 Z
11
+ date: 2021-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-dynamodb