PaddleHQ / paddle-node-sdk

Node.js SDK for working with the Paddle API in server-side apps.
https://developer.paddle.com/
Apache License 2.0
28 stars 5 forks source link

[Bug]: casting event ProductNotification to Product throw error #26

Closed jobcespedes closed 2 months ago

jobcespedes commented 2 months ago

What happened?

Getting casting error from ProductNotification to Product

Property 'prices' is missing in type 'ProductNotification' but required in type 'Product'.ts

Steps to reproduce

  1. Cast from ProductNotification to Product

What did you expect to happen?

ProductNotification becomes a Product entity for storage purposes

Logs

Property 'prices' is missing in type 'ProductNotification' but required in type 'Product'.ts
vijayasingam-paddle commented 2 months ago

Hi @jobcespedes, Thank you for raising this bug report.

The notification classes and their API counterparts are different by design.

When we introduce a non-nullable field to the API, all the events that occurred before this change will be missing the field. To prevent any runtime errors, all new non-nullable fields in the API entity will be marked as optional in the Notification entity.

In this instance, you can optionally include prices in a Product. However, it will never be available in Product related events. So the missing prices property in ProductNotification is valid.

I would strongly recommend updating your function to accept both types. Worst case, you could try typecasting the ProductNotification to the Product class, but I would be very wary as typecasting removes some type safety and could lead to runtime issues.

product-typecasting

Please let us know if you need further help.

Thank you.