-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update config JSON model to v6 * Use int32_t instead of int for Int setting values for better portability * Improve ConfigCatClient public API by making EvaluationDetails generic + add missing getValueDetails overload w/o defaultValue + eliminate getValue code redundancy * Change user param type to shared_ptr<ConfigCatUser> + revise shared_ptr<> param passing * Handle unexpected errors in evaluation methods (to guard against the SDK bringing down the consumer's app) + add the captured exception to EvaluationDetails + add the exception message to the log + change the return type of getKeyAndValue to std::optional for consistency * Remove ConfigCatLogger and SettingResult from public API * Refactor evaluator and evaluation logging to prepare it for the new features * Make onConfigChanged hook's argument const to prevent accidental modifications by end user * Revise std::move usage * Implement new comparison operators * Implement segment condition evaluation * Implement prerequisite flag condition evaluation * Implement SDK key format validation + fix broken tests * Improve message of error 1103 + improve error reporting + fix SDK not returning the error message when forceRefresh fails * Improve code formatting consistency * coding style * NamespaceIndentation: None * config V2 rollout integration tests * evaluateSensitiveTextSliceEqualsAnyOf fix * Correct mistakes in error messages * Handle unexpected errors in forceRefresh (to guard against the SDK bringing down the consumer's app) + expose RefreshResult to end user by returning it from forceRefresh * Adjust terminology to docs (eliminate the usage of term 'match' in the context of conditions) * evaluation log test + evaluation fixes * test fix * specchar test + sdk validation test * v2 eval fixes + tests * etag fix * We should go to the cache in all polling modes instead of using the in memory variable (see https://trello.com/c/rreKm64A) * test fix * windows regex fix * ConfigCatUser::create * ConfigV2EvaluationTest -> EvaluationTest * timeutils * OverrideValueTypeMismatchShouldBeHandledCorrectly_SimplifiedConfig * remove "this->"s + warning fixes * Revert "OverrideValueTypeMismatchShouldBeHandledCorrectly_SimplifiedConfig" This reverts commit 1413fae. * ValueAndDefaultValueTypeCompatibilityTest * keep just datetime_to_isostring and make_datetime on public interface * make_datetime fix * version 4.0.0 * make_datetime millisec 0 default value * Change the return type of ConfigCatClient.get to shared_ptr<ConfigCatClient> to prevent use after free issues * Fix clang error * Add noexcept to move constructors/operators * Minor corrections, maintain naming convention * Add a few addition tests for user attribute value conversion edge cases * Update samples in README.md * Add guard against nullptr dereference in ConfigCatClient::close * Call days_from_civil with 32-bit integer * Manual polling in EnsureCloseWorks on windows * curl close fix * Add missing synchronization to ConfigCatClient::instanceCount * github CI: ctest -j4 * Improve assertions in EnsureCloseWorks test * ResponseErrorCode + cancelled request handling --------- Co-authored-by: kp-cat <[email protected]>
- Loading branch information
Showing
135 changed files
with
10,123 additions
and
2,475 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
BasedOnStyle: Chromium | ||
IndentWidth: 4 | ||
ColumnLimit: 160 | ||
NamespaceIndentation: None | ||
# The number of spaces before trailing line comments (// - comments). | ||
SpacesBeforeTrailingComments: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,101 @@ | ||
#pragma once | ||
|
||
#include <chrono> | ||
#include <memory> | ||
#include <optional> | ||
#include <string> | ||
#include <unordered_map> | ||
#include <variant> | ||
#include <vector> | ||
#include "timeutils.h" | ||
|
||
namespace configcat { | ||
|
||
// An object containing attributes to properly identify a given user for rollout evaluation. | ||
class ConfigCatUser { | ||
public: | ||
struct AttributeValue : public std::variant<std::string, double, date_time_t, std::vector<std::string>> { | ||
private: | ||
using _Base = std::variant<std::string, double, date_time_t, std::vector<std::string>>; | ||
public: | ||
AttributeValue(const char* v) : _Base(std::string(v)) {} | ||
// CLang number type conversion to variant<double> fix | ||
AttributeValue(double value) : _Base(value) {} | ||
|
||
// Disable the implicit conversion from pointer to bool: https://stackoverflow.com/a/59372958/8656352 | ||
template<typename T> | ||
AttributeValue(T*) = delete; | ||
|
||
using _Base::_Base; | ||
using _Base::operator=; | ||
}; | ||
|
||
static constexpr char kIdentifierAttribute[] = "Identifier"; | ||
static constexpr char kEmailAttribute[] = "Email"; | ||
static constexpr char kCountryAttribute[] = "Country"; | ||
|
||
/** | ||
* Creates a new instance of the [ConfigCatUser] class. | ||
* | ||
* Parameter [id]: the unique identifier of the user or session (e.g. email address, primary key, session ID, etc.) | ||
* Parameter [email]: email address of the user. | ||
* Parameter [country]: country of the user. | ||
* Parameter [custom]: custom attributes of the user for advanced targeting rule definitions (e.g. user role, subscription type, etc.) | ||
* | ||
* All comparators support `std::string` values as User Object attribute (in some cases they need to be provided in a specific format though, see below), | ||
* but some of them also support other types of values. It depends on the comparator how the values will be handled. The following rules apply: | ||
* | ||
* **Text-based comparators** (EQUALS, IS ONE OF, etc.) | ||
* * accept `std::string` values, | ||
* * all other values are automatically converted to `std::string` (a warning will be logged but evaluation will continue as normal). | ||
* | ||
* **SemVer-based comparators** (IS ONE OF, <, >=, etc.) | ||
* * accept `std::string` values containing a properly formatted, valid semver value, | ||
* * all other values are considered invalid (a warning will be logged and the currently evaluated targeting rule will be skipped). | ||
* | ||
* **Number-based comparators** (=, <, >=, etc.) | ||
* * accept `double` values, | ||
* * accept `std::string` values containing a properly formatted, valid `double` value, | ||
* * all other values are considered invalid (a warning will be logged and the currently evaluated targeting rule will be skipped). | ||
* | ||
* **Date time-based comparators** (BEFORE / AFTER) | ||
* * accept `configcat::date_time_t` (`std::chrono::system_clock::time_point`) values, | ||
which are automatically converted to a second-based Unix timestamp, | ||
* * accept `double` values representing a second-based Unix timestamp, | ||
* * accept `std::string` values containing a properly formatted, valid `double` value, | ||
* * all other values are considered invalid (a warning will be logged and the currently evaluated targeting rule will be skipped). | ||
* | ||
* **String array-based comparators** (ARRAY CONTAINS ANY OF / ARRAY NOT CONTAINS ANY OF) | ||
* * accept lists of `std::string` (i.e. `std::vector<std::string>`), | ||
* * accept `std::string` values containing a valid JSON string which can be deserialized to a list of `std::string`, | ||
* * all other values are considered invalid (a warning will be logged and the currently evaluated targeting rule will be skipped). | ||
*/ | ||
ConfigCatUser(const std::string& id, | ||
const std::string& email = {}, | ||
const std::string& country = {}, | ||
const std::unordered_map<std::string, std::string>& custom = {}); | ||
const std::optional<std::string>& email = std::nullopt, | ||
const std::optional<std::string>& country = std::nullopt, | ||
const std::unordered_map<std::string, ConfigCatUser::AttributeValue>& custom = {}) | ||
: identifier(id) | ||
, email(email) | ||
, country(country) | ||
, custom(custom) {} | ||
|
||
const std::string* getAttribute(const std::string& key) const; | ||
static inline std::shared_ptr<ConfigCatUser> create(const std::string& id, | ||
const std::optional<std::string>& email = std::nullopt, | ||
const std::optional<std::string>& country = std::nullopt, | ||
const std::unordered_map<std::string, ConfigCatUser::AttributeValue>& custom = {}) { | ||
return std::make_shared<ConfigCatUser>(id, email, country, custom); | ||
} | ||
|
||
inline const std::string& getIdentifier() const { return std::get<std::string>(identifier); } | ||
inline const ConfigCatUser::AttributeValue& getIdentifierAttribute() const { return identifier; } | ||
const ConfigCatUser::AttributeValue* getAttribute(const std::string& key) const; | ||
std::string toJson() const; | ||
|
||
private: | ||
std::unordered_map<std::string, std::string> attributes; | ||
|
||
public: | ||
const std::string& identifier; | ||
ConfigCatUser::AttributeValue identifier; | ||
std::optional<ConfigCatUser::AttributeValue> email; | ||
std::optional<ConfigCatUser::AttributeValue> country; | ||
std::unordered_map<std::string, AttributeValue> custom; | ||
}; | ||
|
||
} // namespace configcat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.