confeature-openfeature 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e710a285ea77f85332fb451f4c8277064d485b19cbc526a95a39eb14fb92ab55
4
+ data.tar.gz: f9d1720a935289738fedfa47c187d156f66060576f433199372fc41c9b4f3934
5
+ SHA512:
6
+ metadata.gz: 8f06acf01f6851bc51b914947d10830f8bff49ce4ab6c6644e608306841b6c08ee82c4364d79aa73143f7f2268a46ccc29a1ae7ab0b909ed0f269bc45a1afbed
7
+ data.tar.gz: be57c35a0750acdd81548a86049d830860bbf6b43e59b5ec375764a7bffd6ba8f7270784bc2bff4e06089e438796a9eb5209ef6d31c206fe49d3ed84bf0f5191
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MakerLabs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ <!-- SPDX-License-Identifier: MIT -->
2
+
3
+ # Confeature OpenFeature provider for Ruby
4
+
5
+ Use the optional `confeature-openfeature` gem to evaluate Confeature flags through
6
+ the official OpenFeature Ruby SDK. Version 0.1.0 requires Ruby 3.4 or later and
7
+ pins `confeature` to 0.2.0 and `openfeature-sdk` to 0.8.1.
8
+
9
+ ## Install
10
+
11
+ Add the provider to your Gemfile and run `bundle install`.
12
+
13
+ ```ruby
14
+ gem "confeature-openfeature", "0.1.0"
15
+ ```
16
+
17
+ ## Evaluate a flag
18
+
19
+ Set `CONFEATURE_SDK_KEY` to your Confeature SDK key. The example looks up the
20
+ boolean flag `feature.dark-mode` and falls back to `false` if evaluation fails.
21
+
22
+ ```ruby
23
+ require "confeature_openfeature"
24
+
25
+ api = OpenFeature::SDK::API.instance
26
+ native_client = Confeature::Client.new(sdk_key: ENV.fetch("CONFEATURE_SDK_KEY"))
27
+
28
+ begin
29
+ api.set_provider_and_wait(ConfeatureOpenFeature::Provider.new(client: native_client), domain: "checkout")
30
+ flags = api.build_client(domain: "checkout")
31
+ context = OpenFeature::SDK::EvaluationContext.new(targeting_key: "example-user", plan: "beta")
32
+
33
+ enabled = flags.fetch_boolean_value(
34
+ flag_key: "feature.dark-mode",
35
+ default_value: false,
36
+ evaluation_context: context
37
+ )
38
+ puts enabled
39
+ ensure
40
+ begin
41
+ api.shutdown
42
+ ensure
43
+ native_client.close
44
+ end
45
+ end
46
+ ```
47
+
48
+ Create the native client at application startup and reuse it. The provider uses
49
+ that client's polling mode, cache and loaded configuration. With manual
50
+ polling, call `native_client.force_refresh` to load or update flags. At
51
+ application shutdown, shut down OpenFeature and close the native client.
52
+
53
+ OpenFeature merges API, transaction, client and invocation context in that order.
54
+ The resulting `targeting_key` supplies the Confeature user identifier. An absent
55
+ key leaves the identifier unset, even if the native client has a default user.
56
+ An empty string counts as an identifier for percentage rollouts. The provider
57
+ reads string `Email` and `Country` fields and passes supported custom attributes,
58
+ such as `plan`, to targeting.
59
+
60
+ Use boolean, string, integer or float evaluations for the matching Confeature
61
+ flag types. Number evaluations accept both integer and float flags and return
62
+ the stored type. Object evaluations return the supplied default with
63
+ `TYPE_MISMATCH`. Use the corresponding `fetch_*_details` method to read the
64
+ evaluated variant when available or the OpenFeature error code on failure.
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ require "date"
6
+
7
+ module ConfeatureOpenFeature
8
+ module Context
9
+ TARGETING_KEY = OpenFeature::SDK::EvaluationContext::TARGETING_KEY
10
+ RESERVED = [TARGETING_KEY, "Identifier", "Email", "Country"].freeze
11
+
12
+ module_function
13
+
14
+ def user_attributes(context)
15
+ identifier = context&.targeting_key
16
+ return unless identifier.nil? || identifier.is_a?(String)
17
+
18
+ fields = context&.fields || {}
19
+ {
20
+ identifier: identifier&.dup,
21
+ email: copy_string(fields["Email"]),
22
+ country: copy_string(fields["Country"]),
23
+ custom: custom_attributes(fields)
24
+ }
25
+ end
26
+
27
+ def copy_string(value)
28
+ value.dup if value.is_a?(String)
29
+ end
30
+
31
+ def custom_attributes(fields)
32
+ fields.each_with_object({}) do |(key, value), custom|
33
+ next if RESERVED.include?(key)
34
+
35
+ selected = attribute_value(value)
36
+ custom[key] = selected unless selected.nil?
37
+ end
38
+ end
39
+
40
+ def attribute_value(value)
41
+ case value
42
+ when String, Time, DateTime then value.dup
43
+ when Integer, TrueClass, FalseClass then value
44
+ when Float then value if value.finite?
45
+ when Array then value.map(&:dup) if value.all?(String)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ module ConfeatureOpenFeature
6
+ VERSION = "0.1.0"
7
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ require "confeature"
6
+ require "open_feature/sdk"
7
+ require_relative "confeature_openfeature/context"
8
+ require_relative "confeature_openfeature/version"
9
+
10
+ module ConfeatureOpenFeature
11
+ class Provider
12
+ OpenFeatureProvider = OpenFeature::SDK::Provider
13
+ ErrorCode = OpenFeatureProvider::ErrorCode
14
+ Reason = OpenFeatureProvider::Reason
15
+ ResolutionDetails = OpenFeatureProvider::ResolutionDetails
16
+ FLAG_TYPES = %i[boolean string number integer float object].freeze
17
+ ERROR_CODES = {
18
+ "CLIENT_CLOSED" => ErrorCode::PROVIDER_NOT_READY,
19
+ "NO_CONFIG" => ErrorCode::PROVIDER_NOT_READY,
20
+ "KEY_NOT_FOUND" => ErrorCode::FLAG_NOT_FOUND,
21
+ "UNSUPPORTED_TYPE" => ErrorCode::TYPE_MISMATCH,
22
+ "TYPE_MISMATCH" => ErrorCode::TYPE_MISMATCH,
23
+ "MALFORMED_VALUE" => ErrorCode::PARSE_ERROR,
24
+ "MALFORMED_CONFIG" => ErrorCode::PARSE_ERROR,
25
+ "VALUE_NOT_BOOL" => ErrorCode::PARSE_ERROR
26
+ }.freeze
27
+
28
+ attr_reader :metadata
29
+
30
+ # The caller owns the lifecycle and polling configuration of its client.
31
+ def initialize(client:)
32
+ raise ArgumentError, "A Confeature client is required." unless client.is_a?(Confeature::Client)
33
+
34
+ @client = client
35
+ @metadata = OpenFeatureProvider::ProviderMetadata.new(name: "Confeature").freeze
36
+ end
37
+
38
+ FLAG_TYPES.each do |type|
39
+ define_method(:"fetch_#{type}_value") do |flag_key:, default_value:, evaluation_context: nil|
40
+ resolve(type, flag_key, default_value, evaluation_context)
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def resolve(type, key, fallback, context)
47
+ return failed(fallback, ErrorCode::TYPE_MISMATCH) if type == :object
48
+
49
+ attributes = Context.user_attributes(context)
50
+ return failed(fallback, ErrorCode::INVALID_CONTEXT) if attributes.nil?
51
+
52
+ details = Confeature::Internal::ProviderEvaluation.evaluate(
53
+ @client, key, fallback, flag_type: type, **attributes
54
+ )
55
+ if details.is_default_value || !details.error.nil?
56
+ return failed(fallback, ERROR_CODES.fetch(details.error, ErrorCode::GENERAL))
57
+ end
58
+
59
+ ResolutionDetails.new(value: details.value, variant: details.variation_id, reason: reason(details))
60
+ end
61
+
62
+ def failed(fallback, code)
63
+ ResolutionDetails.new(value: fallback, reason: Reason::ERROR, error_code: code)
64
+ end
65
+
66
+ def reason(details)
67
+ return Reason::SPLIT unless details.matched_percentage_option.nil?
68
+ return Reason::TARGETING_MATCH unless details.matched_targeting_rule.nil?
69
+
70
+ Reason::UNKNOWN
71
+ end
72
+ end
73
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: confeature-openfeature
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - MakerLabs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-11-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: confeature
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: openfeature-sdk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.1
41
+ description:
42
+ email:
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - LICENSE
48
+ - README.md
49
+ - lib/confeature_openfeature.rb
50
+ - lib/confeature_openfeature/context.rb
51
+ - lib/confeature_openfeature/version.rb
52
+ homepage: https://confeature.io
53
+ licenses:
54
+ - MIT
55
+ metadata:
56
+ source_code_uri: https://github.com/confeature/sdks
57
+ bug_tracker_uri: https://github.com/confeature/sdks/issues
58
+ rubygems_mfa_required: 'true'
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '3.4'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.5.22
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Confeature provider for the OpenFeature Ruby SDK
78
+ test_files: []