Skip to content

Commit

Permalink
fix: STRF-11923 - Handle Missing a New Channels Permission Requiremen…
Browse files Browse the repository at this point in the history
…t in Auth Token (#1191)
  • Loading branch information
bc-jz authored Apr 10, 2024
2 parents 2abe41c + 73703a4 commit 20e5fcb
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://github.com/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 20e5fcb

Please sign in to comment.