Feature/idaas 805/tenants client alternative
What is the purpose of this pull request?
Add LM and Catalog client methods to enable applications to replace requests to the Tenants systems (the Tenants client should be marked as deprecated from now on).
The new API client methods reflect the API interface directly, without converting data or applying business logic. Therefore, any code that depends on the Tenants client or API should adapt to the new data structure interface.
Data fetch and CRUD operations should be replaced like this:
- Requests to
/api/tenant/bindingsroutes should use/api/license-manager/bindingroutes instead (you can use this PR's new client methods as reference). - Requests to
/api/tenant/tenantsroute should be replaced by inferred data or data sought from different places:- The
idandmetadataproperties returned from the Tenants client were incorrectly typed, because the API did not actually return these fields. -
slugandtitlecorrespond to the requestedtenantname. - I (@rafarubim) am uncertain of how to replace the
editionandinfrafields, but I found out that these fields are mostly hard-coded by the Tenants system to return'vtex:tier-1339'and'VTEX'. - The
bindingsfield should be sought from the License Manager API:/api/license-manager/binding/site/{tenant}. In the new client, you should usecontext.clients.licenseManager.listBindings({ tenant, adminUserAuthToken })instead (more details below). - The
defaultCurrencyanddefaultLocalefields should be sought from the Tenant's first sales channel, from the Catalog API:/api/catalog_system/pub/saleschannel/1. In the new client, you should usecontext.clients.catalog.getSalesChannel(1)(more details below).
- The
Result from Tenants client should be replaced like this:
-
defaultLocale->CultureInfofromcontext.clients.catalog.getSalesChannel(1). -
defaultCurrency->CurrencyCodefromcontext.clients.catalog.getSalesChannel(1). -
bindings[x].id->Idfromcontext.clients.licenseManager.listBindings(). -
bindings[x].canonicalBaseAddress-> result of concatenation:
`${Addresses[i].Host}/${Addresses[i].BasePath}`
Where
Addressesis fromcontext.clients.licenseManager.listBindings()andicorresponds to the address withAddresses[i].IsCanonicalequal totrue.
-
bindings[x].alternateBaseAddresses-> list with concatenation results:
`${Addresses[i].Host}/${Addresses[i].BasePath}`
Where
Addressesis fromcontext.clients.licenseManager.listBindings()andicorresponds to all addresses withAdresses[i].IsCanonicalequal tofalse.
-
bindings[x].defaultLocale->DefaultLocalefromcontext.clients.licenseManager.listBindings(). -
bindings[x].supportedLocales-> fromSupportedLocalesfromcontext.clients.licenseManager.listBindings(). -
bindings[x].defaultCurrency->CurrencyCodefromcontext.clients.catalog.getSalesChannel(1). -
bindings[x].supportedCurrencies-> I (@rafarubim) am uncertain of a replacement, but[CurrencyCode]seems acceptable. -
bindings[x].extraContext-> I (@rafarubim) am uncertain of a replacement, but I believe it could be related toDefaultSalesChannelIdfromcontext.clients.licenseManager.listBindings(). -
bindings[x].targetProduct-> This value should be inferred from thebindings[x].canonicalBaseAddressandbindings[x].alternateBaseAddressesfields, following this logic:
const isAdmin = canonicalBaseAddress.endsWith('myvtex.com/admin') || alternateBaseAddresses.some(addr => addr.endsWith('myvtex.com/admin'))
const targetProduct = isAdmin ? 'vtex-admin' : 'vtex-storefront'
How should this be manually tested?
This PR's changes have been locally linked, then have been added to a test branch in the vtex/auth-admin repository.
This branch adds GraphQL queries and server resolvers that correspond to a node-vtex-api client call, like this:
graphql/schema.graphql
node/index.ts
To test these GraphQL queries, go into this GraphiQL workspace.
You can check out the following queries/mutations to test the application:
⚠️ Ensure you pass valid parameters (e.g., use a valid
hostregistered in the tenant, don't startpathwith a leading slash/) to avoid a 4xx response ⚠️ Wait a few minutes after deletion, as License Manager has a durable cache.
⚠️ Wait a few minutes after deletion, as License Manager has a durable cache.
⚠️ Wait a few minutes after updating, as License Manager has a durable cache.
Types of changes
- [ ] Bug fix (a non-breaking change which fixes an issue)
- [X] New feature (a non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Requires change to documentation, which has been updated accordingly.