prefab-cloud-ruby 1.8.3 → 1.8.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ddab427174fc8ee9580364b7f55becb58806d98b94968ee3d903ce67e9b01268
4
- data.tar.gz: 181cdf62f18a7c9b09846746597273230f6b13100b302ef4531693f0a3d07085
3
+ metadata.gz: ec8c47fb2fe1945e2d189198fbb2ecb8b2eee9d77537ac6569196659931badf4
4
+ data.tar.gz: 58afaf18e4541429db3e4204f7bc2c19340028d894b84a75d7195aac39fd6b37
5
5
  SHA512:
6
- metadata.gz: 784b5d8e0229ec1e953d16a2442561a1cc67e18fc4f398f4878ac4672256892a0d6c314b06b9cd835a8309d184d47a2280d348b8afd396f977c6c57248d7c2b9
7
- data.tar.gz: '0865454d8eab0548aff23e3caa338d037babc8d9a49165424e6b8822d6a5f5b5ba67e8395752bebedb9666ff5cd3f1eac46f4d4df66abc1c8f2274770e4d634f'
6
+ metadata.gz: 7ed0b65787d13a25a301a75481cff40db9b7dc1b036aea75c5e241b0bdddfd26577317b013830c7533ad0da51b7d087c3e59df5d8c38c07382509cfbc8d9eeb1
7
+ data.tar.gz: c57bb8881f6a61b252013c118240bc64b8ffaa248caafd234747f1897dd3d67aab6b02b72a3c1e8b164feb689590587475fe5d605f13c1ac4b5c0b426e45f137
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.8.4 - 2024-09-19
4
+
5
+ - Use `stream` subdomain for SSE (#203)
6
+
3
7
  ## 1.8.3 - 2024-09-16
4
8
 
5
9
  - Add JavaScript stub & bootstrapping (#200)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.8.3
1
+ 1.8.4
@@ -8,16 +8,6 @@ module Prefab
8
8
  @client = client || Prefab.instance
9
9
  end
10
10
 
11
- # Generate the JavaScript snippet to bootstrap the client SDK. This will
12
- # include the configuration values that are permitted to be sent to the
13
- # client SDK.
14
- #
15
- # If the context provided to the client SDK is not the same as the context
16
- # used to generate the configuration values, the client SDK will still
17
- # generate a fetch to get the correct values for the context.
18
- #
19
- # Any keys that could not be resolved will be logged as a warning to the
20
- # console.
21
11
  def bootstrap(context)
22
12
  configs, warnings = data(context)
23
13
  <<~JS
@@ -29,24 +19,20 @@ module Prefab
29
19
  JS
30
20
  end
31
21
 
32
- # Generate the JavaScript snippet to *replace* the client SDK. Use this to
33
- # get `prefab.get` and `prefab.isEnabled` functions on the window object.
34
- #
35
- # Only use this if you are not using the client SDK and do not need
36
- # client-side context.
37
- #
38
- # Any keys that could not be resolved will be logged as a warning to the
39
- # console.
40
- def generate_stub(context)
22
+ def generate_stub(context, callback = nil)
41
23
  configs, warnings = data(context)
42
24
  <<~JS
43
25
  window.prefab = window.prefab || {};
44
26
  window.prefab.config = #{JSON.dump(configs)};
45
27
  window.prefab.get = function(key) {
46
- return window.prefab.config[key];
28
+ var value = window.prefab.config[key];
29
+ #{callback && " #{callback}(key, value);"}
30
+ return value;
47
31
  };
48
32
  window.prefab.isEnabled = function(key) {
49
- return window.prefab.config[key] === true;
33
+ var value = window.prefab.config[key] === true;
34
+ #{callback && " #{callback}(key, value);"}
35
+ return value;
50
36
  };
51
37
  #{log_warnings(warnings)}
52
38
  JS
@@ -70,7 +56,7 @@ module Prefab
70
56
  return '' if warnings.empty?
71
57
 
72
58
  <<~JS
73
- console.warn('The following keys could not be resolved:', #{JSON.dump(@warnings)});
59
+ console.warn('The following keys could not be resolved:', #{JSON.dump(warnings)});
74
60
  JS
75
61
  end
76
62
 
@@ -83,7 +69,7 @@ module Prefab
83
69
  begin
84
70
  config = @client.resolver.raw(key)
85
71
 
86
- if config.config_type == :FEATURE_FLAG || config.send_to_client_sdk
72
+ if config.config_type == :FEATURE_FLAG || config.send_to_client_sdk || config.config_type == :LOG_LEVEL
87
73
  permitted[key] = underlying_value(@client.resolver.get(key, context).value)
88
74
  end
89
75
  rescue StandardError => e
data/lib/prefab/prefab.rb CHANGED
@@ -78,14 +78,40 @@ module Prefab
78
78
  @singleton.is_ff?(key)
79
79
  end
80
80
 
81
+ # Generate the JavaScript snippet to bootstrap the client SDK. This will
82
+ # include the configuration values that are permitted to be sent to the
83
+ # client SDK.
84
+ #
85
+ # If the context provided to the client SDK is not the same as the context
86
+ # used to generate the configuration values, the client SDK will still
87
+ # generate a fetch to get the correct values for the context.
88
+ #
89
+ # Any keys that could not be resolved will be logged as a warning to the
90
+ # console.
81
91
  def self.bootstrap_javascript(context)
82
92
  ensure_initialized
83
93
  Prefab::JavaScriptStub.new(@singleton).bootstrap(context)
84
94
  end
85
95
 
86
- def self.generate_javascript_stub(context)
96
+ # Generate the JavaScript snippet to *replace* the client SDK. Use this to
97
+ # get `prefab.get` and `prefab.isEnabled` functions on the window object.
98
+ #
99
+ # Only use this if you are not using the client SDK and do not need
100
+ # client-side context.
101
+ #
102
+ # Any keys that could not be resolved will be logged as a warning to the
103
+ # console.
104
+ #
105
+ # You can pass an optional callback function to be called with the key and
106
+ # value of each configuration value. This can be useful for logging,
107
+ # tracking experiment exposure, etc.
108
+ #
109
+ # e.g.
110
+ # - `Prefab.generate_javascript_stub(context, "reportExperimentExposure")`
111
+ # - `Prefab.generate_javascript_stub(context, "(key,value)=>{console.log({eval: 'eval', key,value})}")`
112
+ def self.generate_javascript_stub(context, callback = nil)
87
113
  ensure_initialized
88
- Prefab::JavaScriptStub.new(@singleton).generate_stub(context)
114
+ Prefab::JavaScriptStub.new(@singleton).generate_stub(context, callback)
89
115
  end
90
116
 
91
117
  private
@@ -106,7 +106,7 @@ module Prefab
106
106
  @source_index = 0
107
107
  end
108
108
 
109
- return @prefab_options.sse_sources[@source_index]
109
+ return @prefab_options.sse_sources[@source_index].sub(/(belt|suspenders)\./, 'stream.')
110
110
  end
111
111
  end
112
112
  end
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: prefab-cloud-ruby 1.8.3 ruby lib
5
+ # stub: prefab-cloud-ruby 1.8.4 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "prefab-cloud-ruby".freeze
9
- s.version = "1.8.3"
9
+ s.version = "1.8.4"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Jeff Dwyer".freeze]
14
- s.date = "2024-09-16"
14
+ s.date = "2024-09-19"
15
15
  s.description = "Feature Flags, Live Config, and Dynamic Log Levels as a service".freeze
16
16
  s.email = "jdwyer@prefab.cloud".freeze
17
17
  s.extra_rdoc_files = [
@@ -87,7 +87,7 @@ class JavascriptStubTest < Minitest::Test
87
87
 
88
88
  assert_equal %(
89
89
  window._prefabBootstrap = {
90
- configs: {"basic-config":"default_value","feature-flag":false},
90
+ configs: {"log-level":"INFO","basic-config":"default_value","feature-flag":false},
91
91
  context: {}
92
92
  }
93
93
  ).strip, result.strip
@@ -96,7 +96,7 @@ window._prefabBootstrap = {
96
96
 
97
97
  assert_equal %(
98
98
  window._prefabBootstrap = {
99
- configs: {"basic-config":"default_value","feature-flag":true},
99
+ configs: {"log-level":"INFO","basic-config":"default_value","feature-flag":true},
100
100
  context: {"user":{"email":"gmail.com"}}
101
101
  }
102
102
  ).strip, result.strip
@@ -107,25 +107,33 @@ window._prefabBootstrap = {
107
107
 
108
108
  assert_equal %(
109
109
  window.prefab = window.prefab || {};
110
- window.prefab.config = {"basic-config":"default_value","feature-flag":false};
110
+ window.prefab.config = {"log-level":"INFO","basic-config":"default_value","feature-flag":false};
111
111
  window.prefab.get = function(key) {
112
- return window.prefab.config[key];
112
+ var value = window.prefab.config[key];
113
+
114
+ return value;
113
115
  };
114
116
  window.prefab.isEnabled = function(key) {
115
- return window.prefab.config[key] === true;
117
+ var value = window.prefab.config[key] === true;
118
+
119
+ return value;
116
120
  };
117
121
  ).strip, result.strip
118
122
 
119
- result = Prefab::JavaScriptStub.new(@client).generate_stub({ user: { email: 'gmail.com' } })
123
+ result = Prefab::JavaScriptStub.new(@client).generate_stub({ user: { email: 'gmail.com' } }, "myEvalCallback")
120
124
 
121
125
  assert_equal %(
122
126
  window.prefab = window.prefab || {};
123
- window.prefab.config = {"basic-config":"default_value","feature-flag":true};
127
+ window.prefab.config = {"log-level":"INFO","basic-config":"default_value","feature-flag":true};
124
128
  window.prefab.get = function(key) {
125
- return window.prefab.config[key];
129
+ var value = window.prefab.config[key];
130
+ myEvalCallback(key, value);
131
+ return value;
126
132
  };
127
133
  window.prefab.isEnabled = function(key) {
128
- return window.prefab.config[key] === true;
134
+ var value = window.prefab.config[key] === true;
135
+ myEvalCallback(key, value);
136
+ return value;
129
137
  };
130
138
 
131
139
  ).strip, result.strip
@@ -6,7 +6,7 @@ require 'webrick'
6
6
  class TestSSEConfigClient < Minitest::Test
7
7
  def test_client
8
8
  sources = [
9
- 'https://api.staging-prefab.cloud/'
9
+ 'https://belt.staging-prefab.cloud/'
10
10
  ]
11
11
 
12
12
  options = Prefab::Options.new(sources: sources, api_key: ENV.fetch('PREFAB_INTEGRATION_TEST_API_KEY', nil))
@@ -16,6 +16,7 @@ class TestSSEConfigClient < Minitest::Test
16
16
  client = Prefab::SSEConfigClient.new(options, config_loader)
17
17
 
18
18
  assert_equal 4, client.headers['x-prefab-start-at-id']
19
+ assert_equal "https://stream.staging-prefab.cloud", client.source
19
20
 
20
21
  result = nil
21
22
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prefab-cloud-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.3
4
+ version: 1.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Dwyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-16 00:00:00.000000000 Z
11
+ date: 2024-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby