-
Notifications
You must be signed in to change notification settings - Fork 307
/
eventfilter.go
71 lines (67 loc) · 2.35 KB
/
eventfilter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package eventfilter
import (
backendconfig "github.com/rudderlabs/rudder-server/config/backend-config"
"github.com/rudderlabs/rudder-server/utils/misc"
)
// GetSupportedMessageTypes returns the supported message types for the given event, based on configuration.
// If no relevant configuration is found, returns false
func GetSupportedMessageTypes(destination *backendconfig.DestinationT) ([]string, bool) {
var supportedMessageTypes []string
if supportedTypes, ok := destination.DestinationDefinition.Config["supportedMessageTypes"]; ok {
if supportedTypeInterface, ok := supportedTypes.([]interface{}); ok {
supportedTypesArr := misc.ConvertInterfaceToStringArray(supportedTypeInterface)
for _, supportedType := range supportedTypesArr {
var skip bool
switch supportedType {
case "identify":
skip = identifyDisabled(destination)
default:
}
if !skip {
supportedMessageTypes = append(supportedMessageTypes, supportedType)
}
}
return supportedMessageTypes, true
}
}
return nil, false
}
func identifyDisabled(destination *backendconfig.DestinationT) bool {
if serverSideIdentify, flag := destination.Config["enableServerSideIdentify"]; flag {
if v, ok := serverSideIdentify.(bool); ok {
return !v
}
}
return false
}
// GetSupportedEvents returns the supported message events for the given destination, based on configuration.
// If no relevant configuration is found, returns false
func GetSupportedMessageEvents(destination *backendconfig.DestinationT) ([]string, bool) {
// "listOfConversions": [
// {
// "conversions": "Credit Card Added"
// },
// {
// "conversions": "Credit Card Removed"
// }
// ]
if supportedEventsI, ok := destination.Config["listOfConversions"]; ok {
if supportedEvents, ok := supportedEventsI.([]interface{}); ok {
var supportedMessageEvents []string
for _, supportedEvent := range supportedEvents {
if supportedEventMap, ok := supportedEvent.(map[string]interface{}); ok {
if conversions, ok := supportedEventMap["conversions"]; ok {
if supportedMessageEvent, ok := conversions.(string); ok {
supportedMessageEvents = append(supportedMessageEvents, supportedMessageEvent)
}
}
}
}
if len(supportedMessageEvents) != len(supportedEvents) {
return nil, false
}
return supportedMessageEvents, true
}
}
return nil, false
}