Module: KindeSdk::Client::FeatureFlags

Included in:
KindeSdk::Client
Defined in:
lib/kinde_sdk/client/feature_flags.rb

Instance Method Summary collapse

Instance Method Details

#get_boolean_flag(name, default_value = nil) ⇒ Object

Legacy methods for backward compatibility



70
71
72
# File 'lib/kinde_sdk/client/feature_flags.rb', line 70

def get_boolean_flag(name, default_value = nil)
  flag_getter_wrapper(name, "b", default_value)
end

#get_flag(name, options_or_opts = {}, flag_type = nil) ⇒ Hash?

Get a specific feature flag Supports both new API-style calls and legacy 3-parameter calls

Parameters:

  • name (String)

    The flag name/key to retrieve

  • options_or_opts (Hash) (defaults to: {})

    Options for retrieving flags OR legacy opts hash

  • flag_type (String, nil) (defaults to: nil)

    Legacy flag type parameter (for 3-param calls)

Returns:

  • (Hash, nil)

    Flag object or nil if not found



46
47
48
49
50
51
52
53
# File 'lib/kinde_sdk/client/feature_flags.rb', line 46

def get_flag(name, options_or_opts = {}, flag_type = nil)
  # Handle legacy 3-parameter signature: get_flag(name, opts, flag_type)
  if flag_type || (options_or_opts.is_a?(Hash) && options_or_opts.key?(:default_value) && !options_or_opts.key?(:force_api))
    return get_flag_legacy(name, options_or_opts, flag_type)
  end

  get_flag_new_api(name, options_or_opts)
end

#get_flags(options = {}) ⇒ Array

Get all feature flags for the authenticated user Matches the JavaScript SDK API: getFlags(options?)

Examples:

# Soft check (from token)
client.get_flags
# => [{ key: "feature_a", value: true, type: "boolean" }]

# Hard check (from API)
client.get_flags(force_api: true)
# => [{ key: "feature_a", value: true, type: "boolean" }]

Parameters:

  • options (Hash) (defaults to: {})

    Options for retrieving feature flags

Options Hash (options):

  • :force_api (Boolean) — default: false

    If true, calls the API to get fresh flags, otherwise extracts from token claims. Useful for ensuring latest flags but may incur additional API calls

  • :token_type (Symbol) — default: :access_token

    The token type to use for soft check (:access_token or :id_token)

Returns:

  • (Array)

    Array of flag objects with key, value, and type



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/kinde_sdk/client/feature_flags.rb', line 20

def get_flags(options = {})
  # Handle legacy positional argument for backward compatibility
  if options.is_a?(Symbol)
    options = { token_type: options }
  end
  
  # Extract options with defaults - use member variable if not overridden
  force_api = options[:force_api] || @force_api || false
  token_type = options[:token_type] || :access_token

  if force_api
    # Hard check - call API for fresh flags
    get_flags_from_api
  else
    # Soft check - extract from token claims
    get_flags_from_token(token_type)
  end
end

#get_integer_flag(name, default_value = nil) ⇒ Object



78
79
80
# File 'lib/kinde_sdk/client/feature_flags.rb', line 78

def get_integer_flag(name, default_value = nil)
  flag_getter_wrapper(name, "i", default_value)
end

#get_string_flag(name, default_value = nil) ⇒ Object



74
75
76
# File 'lib/kinde_sdk/client/feature_flags.rb', line 74

def get_string_flag(name, default_value = nil)
  flag_getter_wrapper(name, "s", default_value)
end

#getFlagsObject

PHP SDK compatible alias



83
84
85
86
87
# File 'lib/kinde_sdk/client/feature_flags.rb', line 83

def getFlags
  # Use client's force_api setting, default to true for PHP SDK compatibility
  force_api_setting = @force_api.nil? ? true : @force_api
  get_flags(force_api: force_api_setting)
end

#has_feature_flags?(flag_conditions, options = {}) ⇒ Boolean Also known as: hasFeatureFlags

Check if user has specific feature flags

Parameters:

  • flag_conditions (Array)

    Array of flag keys or flag condition objects

  • options (Hash) (defaults to: {})

    Options for retrieving flags (same as get_flags)

Returns:

  • (Boolean)

    True if user has all specified flags, false otherwise



60
61
62
63
64
65
66
67
# File 'lib/kinde_sdk/client/feature_flags.rb', line 60

def has_feature_flags?(flag_conditions, options = {})
  return true if flag_conditions.nil? || flag_conditions.empty?
  
  flags = get_flags(options)
  flag_conditions_array = Array(flag_conditions)
  
  flag_conditions_array.all? { |condition| check_flag_condition(condition, flags) }
end