trycourier / courier-java

Java SDK for communicating with the Courier REST API.
MIT License
7 stars 5 forks source link

Incorrect data type for MessageDetails properties that store ms since epoch values #58

Open rdrimmie-miovision opened 2 months ago

rdrimmie-miovision commented 2 months ago

Hey folks, it looks as though the code generated for the java sdk is using java int datatypes for properties that hold ms since epoch values. Unfortunately, ms since epoch values are considerably higher than the upper bounds of a java int so it is impossible to work with the response to a SendMessageRequest because the application crashes with an out of bounds error.

in this example, assignment to foo fails with the error that follows.

val bar = courierClient.send(
            SendMessageRequest.builder()
                .message(
                    Message.of(
                        TemplateMessage.builder()
                            .template(templateId)
                            .to(
                                MessageRecipient.of(
                                    Recipient.of(buildUserRecipient(email, phoneNumber, locale))
                                )
                            )
                            .data(data)
                            .build()
                    )
                )
                .build()
        )

        val foo = courierClient.messages().get(bar.requestId)
com.fasterxml.jackson.databind.JsonMappingException: Numeric value (1721756983064) out of range of int (-2147483648 - 2147483647)
 at [Source: (String)"{"enqueued":1721756983064,"error":"Cannot failover when status of sibling provider sends is unknown.","event":"WSA3KMZDVW4KDWN1EERYQSFQSNA1","id":"1-669fed37-14b9bebaba94aff95e4b4b6b","listMessageId":"1-669fed37-14b9bebaba94aff95e4b4b6b","notification":"WSA3KMZDVW4KDWN1EERYQSFQSNA1","providers":[],"reason":"BOUNCED","recipient":"rdrimmie@miovision.com","recipientId":"anon_2d6a0bdbf5eebf7c77396c89716dec4a","requestId":"1-669fed37-14b9bebaba94aff95e4b4b6b","sent":1721756984597,"status":"UNDELIVERA"[truncated 23 chars]; line: 1, column: 26] (through reference chain: com.courier.api.resources.messages.types.MessageDetails$Builder["enqueued"])

This appears to occur because the source is generated with the enqueued property defined as a java int https://github.com/trycourier/courier-java/blob/main/src/main/java/com/courier/api/resources/messages/types/MessageDetails.java#L27

But per the api docs https://www.courier.com/docs/reference/logs/by-id/:

enqueued number A UTC timestamp at which Courier received the message request. This is stored as a millisecond representation of the Unix epoch (the time passed since January 1, 1970).

The UTC time Tue Jul 23 2024 17:49:43.064 in ms since the epoch has the value 1721756983064, and that is well out of bounds for a Java int.

rdrimmie-miovision commented 2 months ago

Oh, this is using v3.2 of the client

dsinghvi commented 2 months ago

@rdrimmie-miovision thanks for filing this issue!

dsinghvi commented 2 months ago

@rdrimmie-miovision this should be fixed in version 3.2.1 https://github.com/trycourier/courier-java/commit/2cd7dac781c1a3ee075fa5e81f3a6bdddf73d5dc which will be published shortly

rdrimmie-miovision commented 2 months ago

Amazing! Thanks so much!

rdrimmie-miovision commented 2 months ago

@dsinghvi It looks as though the push to maven ci job failed: https://github.com/trycourier/courier-java/actions/runs/10064790025/job/27837079790