Skip to content

[Bug]: Operators not supported in notification filters #62

@bastiankistner

Description

@bastiankistner

What happened?

When trying to add filters to a notification but not only with Filter instances but also with Operator instances, the serialization process first turns all values of the Operator into undefined and the resulting payload will then carry an emtpy object {}.

[
    {
        "field": "tag",
        "key": "value",
        "relation": "=",
        "value": "value"
    },
    {
        "field": undefined,
        "key": undefined,
        "relation": undefined,
        "value": undefined
    },
    {
        "field": "tag",
        "key": "value",
        "relation": "=",
        "value": "value"
    }
]

The issues seems to be that internally the filter property of a Notification is set to be of type Array<Filter>. The ObjectSerializer therefore ignores the operator: "OR" as it's not a field of Filter. As a result, the request fails because of a BadRequest error with Body: {"errors":["Segment is not a valid filter field."]}.

The serialization happens here

} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
let transformedData: any[] = [];
for (let index in data) {
let date = data[index];
transformedData.push(ObjectSerializer.serialize(date, subType, format));
}
return transformedData;
. Either the filter property would not only be Array<Filter> (see
'filters'?: Array<Filter>;
) but instead Array<Filter|Operator> and that would properly be parsed. Or you just allow objects to be passed without serializing them through the ObjectSerializer.

In the Go SDK, this case seems to be handled as expected: https://github.com/OneSignal/onesignal-go-api/blob/a573325af1d37a1c7dc8bad8d78fdd33fbfcaf38/model_filter_expressions.go#L27-L54

Also the NodeJS SDK docs state that it should be possible to pass { operator: "OR"}.

Steps to reproduce?

1. create a new notification
2. set `filter` to an array of [Filter, Operator, Filter] instances
3. send the notification

What did you expect to happen?

The notification should be sent and the filter fields in the OneSignal dashboard should show that the notification was sent with three filters, the second being the "OR" operator.

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions