Skip to content

Commit

Permalink
fix: STRF-11923 - Handle missing Channels auth permission in getStore…
Browse files Browse the repository at this point in the history
…Channels() method.
  • Loading branch information
bc-jz committed Apr 10, 2024
1 parent 2abe41c commit 73703a4
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions lib/theme-api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,28 @@ async function getStoreChannels({ accessToken, apiHost, storeHash }) {
url: `${apiHost}/stores/${storeHash}/v3/sites`,
accessToken,
});
const channelsResponse = await networkUtils.sendApiRequest({
url: `${apiHost}/stores/${storeHash}/v3/channels`,
accessToken,
});
const channelsResponse = await networkUtils
.sendApiRequest({
url: `${apiHost}/stores/${storeHash}/v3/channels?type:in=storefront`,
accessToken,
})
.catch((error) => {
if (error.response.status === 403) {
console.log(
'WARNING: Version 7.4.2+ of stencil-cli added a request to the Channels resource which requires a permission missing on your current stencil cli auth token. Please generate a new auth token at your convenience which includes the "read-only channels" permission to clear up this warning. You can read more about correcting this issue here: https:/bigcommerce/stencil-cli/issues/1185',
);
}
});

const storefrontChannels = channelsResponse.data.data.filter(
(channel) => channel.type === 'storefront',
);
if (channelsResponse) {
return sitesResponse.data.data.filter(
(site) =>
channelsResponse.data.data.filter((channel) => channel.id === site.channel_id)
.length > 0,
);
}

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

0 comments on commit 73703a4

Please sign in to comment.