Skip to content

Commit

Permalink
fix: STRF-11856 - Filter the response for getStoreChannels() to only …
Browse files Browse the repository at this point in the history
…include type 'storefront' channels.
  • Loading branch information
bc-jz committed Apr 4, 2024
1 parent 718ee9f commit 4376c9e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/theme-api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,23 @@ async function getChannelActiveTheme({ accessToken, apiHost, storeHash, channelI
*/
async function getStoreChannels({ accessToken, apiHost, storeHash }) {
try {
const response = await networkUtils.sendApiRequest({
const sitesResponse = await networkUtils.sendApiRequest({
url: `${apiHost}/stores/${storeHash}/v3/sites`,
accessToken,
});
return response.data.data;
const channelsResponse = await networkUtils.sendApiRequest({
url: `${apiHost}/stores/${storeHash}/v3/channels`,
accessToken,
});

const storefrontChannels = channelsResponse.data.data.filter(
(channel) => channel.type === 'storefront',
);

return sitesResponse.data.data.filter(
(site) =>
storefrontChannels.filter((channel) => channel.id === site.channel_id).length > 0,
);
} catch (err) {
throw new Error(`Could not fetch a list of the store channels: ${err.message}`);
}
Expand Down

0 comments on commit 4376c9e

Please sign in to comment.