bindContextVariables function

Map<String, String> bindContextVariables(
  1. List<VariableSchema> schemas, {
  2. required Map<String, dynamic> userAttributes,
  3. Map<String, Object?> eventProperties = const <String, Object?>{},
})

Looks up the runtime value of each context variable in schemas — user.<key> from userAttributes, event.<key> from eventProperties — keyed by its token. Custom variables are skipped: the CEP payload carries those. VariableScope.fromSchemas applies types and fallbacks, so a CEP-decided campaign, which declares no context variables, gets an empty map.

Implementation

Map<String, String> bindContextVariables(
  List<VariableSchema> schemas, {
  required Map<String, dynamic> userAttributes,
  Map<String, Object?> eventProperties = const <String, Object?>{},
}) {
  final bound = <String, String>{};
  for (final schema in schemas) {
    final dot = schema.name.indexOf('.');
    if (dot < 0) continue;
    final key = schema.name.substring(dot + 1);
    final raw = switch (schema.name.substring(0, dot)) {
      userNamespace => userAttributes[key],
      eventNamespace => eventProperties[key],
      _ => null,
    };
    bound[schema.name] = schema.resolve(raw);
  }
  return bound;
}