teamleadercrm / sdk-js

MIT License
6 stars 0 forks source link

Proxy implementation for domains and actions. #328

Closed lowiebenoot closed 2 years ago

lowiebenoot commented 2 years ago

Instead of configuring all the possible domains and actions and adding extra domains and actions through configuration, we can just make any domain and action possible by using a proxy.

API.foo.bar() will call the ${url}/foo.bar endpoint.

So no change is needed for using the API, except that you can remove your additional domains and actions configuration.

Proxy is not supported by IE, so we might want to consider this as a breaking change? I still have to update the changelog in this PR.

lowiebenoot commented 2 years ago

@lorgan3 I don't think there is actually a thing such as a non-existent routes. A lot of our api's are only internal, so they're "non-existent" for others, but not for us. Or if you would change your baseUrl, like we did for the customer-platform api, then you have a whole other set of endpoints as well.

lorgan3 commented 2 years ago

@lowiebenoot it's possible to make this configurable but it would mean that you have to override things when initializing the api which is what you're trying to remove/fix with this pr. I think if we could actually generate the types from the api docs (which we can't do currently) it would remove a lot of the annoyance of keeping those overrides in sync.

Changing the baseUrl to point to an entirely different api feels a bit like a hack. To me an "SDK" should actually tell/help you calling a specific api or set of apis while right now this just a wrapper around fetch with some quality of life improvements. But maybe my definition of SDK is off / this repo no longer has an accurate name.

lowiebenoot commented 2 years ago

@lorgan3 I think there could still be a way that we map types to a domain and action, so we could actually still do it in the future.

I agree, pointing the baseUrl to a different indeed is a bit weird actually, and defeats the purpose of this being an sdk for our api.

lowiebenoot commented 2 years ago

Another thing that will make it very hard is that when you use plugins (camelcase/snakecase), the request/response format changes. So it will be very hard (or even impossible?) to get the types correctly, depending on the plugins you use.