superfaceai / one-sdk-js

1️⃣ One Node.js SDK for all the APIs you want to integrate with
https://superface.ai
MIT License
47 stars 3 forks source link

[Feature Request] Get list of providers configured for a given profile #211

Closed jnv closed 2 years ago

jnv commented 2 years ago

Given a profile name, I would like to get a list of configured providers. For example:

const profile = await sdk.getProfile('weather/current-city');
const providers = profile.getConfiguredProviders();
console.log(providers); // => ['mock', 'openweathermap', 'wttr-in']

(Alternatively the SDK could return an object / map where the key is the name and value is full provider name so it can be passed directly into perform.)

Rationale

For domains like hospitality and social media, we need an explicit control over the passed-in provider. However, if the profiles are sufficiently generic enough, the implementation could be completely driven by the configuration. Take for example our social-media-demo where we need to resort to manual listing of supported providers. Having an easy access to the configured providers would help to make the code even more generic.

Other use-case is for handling incoming webhooks, where I'd like to proactively validate whether there is a map for the given profile instead of invoking an exception when asking for non-existent provider.