webflow / js-webflow-api

Node.js SDK for the Webflow Data API
https://www.npmjs.com/package/webflow-api
296 stars 95 forks source link

Add check for body type #14

Closed ericdevelops closed 4 years ago

ericdevelops commented 6 years ago

I believe this is the least invasive method of resolving this.

Simple requests like /sites return in an array whereas requests on a collection like /collections simply return an object. The array type responses prevent _meta object from getting appended to the response body. Even though the logic is written as if it should. By simply checking for the body type, we can reference the array index and append the buildMeta response to it.

kyleshevlin commented 4 years ago

I can't speak for everyone at Webflow, nor do I know the history of this API very well, but I don't think we can accept this PR (I know it's over 2 years old) for 2 reasons:

First, it's a breaking change. While the code as it exists may be imperfect, arrays can have properties (because they are a typeof object). So even when body is an array, the _meta property is getting added to that array object. Changing this breaks the API. Breaking the API is fine, but it requires a major version change which we are unprepared to do at the moment. This brings me to my second point.

Second, if this is a problem and we need to solve it, we should solve it in a more robust way. The best way to handle this is to add a normalizing function to handle responses so that bodys that are of different shapes are all conformed to a standardized shape. For example, once normalized into an object, we can add the _meta data the same way for every response. This would help consumers of the API by reducing their need to respond differently to different responses, as well as prevent implementation details from leaking into responses.

I want to thank you for your contribution. I'm sorry it didn't get the attention it probably deserved. This API is not owned by any particular team at Webflow at the moment, and thus, it has not received the attention an open source project truly deserves.

I hope this wasn't too great an inconvenience for you and that you've found workarounds since the time of this.

I am going to close this PR. If a Webflow team is able to take ownership of this project and wants to reopen it, I leave that to them.