commercetools / commercetools-sdk-typescript

The e-commerce SDK from commercetools for JavaScript written in TypeScript.
https://commercetools.github.io/commercetools-sdk-typescript/
MIT License
45 stars 25 forks source link

Why apiRoot created from the client requires a projectKey for every call ? #224

Closed ahmetoz closed 2 years ago

ahmetoz commented 2 years ago

ClientBuilder has to have the projectKey to create a ctpClient, but when I create an apiRoot with using createApiBuilderFromCtpClient(ctpClient), I did not understand why do we need to pass the projectKey everytime, is not the apiRoot bound this ctpClient already 🤔 It's a bit confusing tbh. I just wonder if you have an alternative use case to explain the need.

jenschude commented 2 years ago

Because we didn't added a project scoped apiRoot yet like for the other SDKs. :)

jenschude commented 2 years ago

But it's fine to do something like

const projectApiRoot = apiRoot.withProjectKey(projectKey)

and then use the projectApiRoot instead

ahmetoz commented 2 years ago

Because we didn't added a project scoped apiRoot yet like for the other SDKs. :)

Thanks for the prompt answer. I think I did not got the idea here, can you elaborate a bit, what is project scoped apiRoot ? 🙏🏽

jenschude commented 2 years ago

The ApiRoot is generated and the entry point is always on the root directory level.

For the other SDKs we added a manually maintained ApiRoot which is scoped to the project key. E.g. the Java SDK one:

https://github.com/commercetools/commercetools-sdk-java-v2/blob/main/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/client/ProjectApiRoot.java