({
account,
domain,
accountId,
fetchTeamInfo,
}: {
account: AccountWithSlackAuthAndChannels;
domain?: string;
accountId: string;
fetchTeamInfo: Function;
})
| 2 | import { AccountWithSlackAuthAndChannels } from '@linen/types'; |
| 3 | |
| 4 | export async function fetchToken({ |
| 5 | account, |
| 6 | domain, |
| 7 | accountId, |
| 8 | fetchTeamInfo, |
| 9 | }: { |
| 10 | account: AccountWithSlackAuthAndChannels; |
| 11 | domain?: string; |
| 12 | accountId: string; |
| 13 | fetchTeamInfo: Function; |
| 14 | }) { |
| 15 | const slackAuth = account.slackAuthorizations?.shift(); |
| 16 | |
| 17 | const token = slackAuth?.accessToken || ''; |
| 18 | const syncFrom = slackAuth?.syncFrom || new Date(0); |
| 19 | const shouldJoinChannel = slackAuth?.joinChannel !== false; |
| 20 | |
| 21 | const teamInfoResponse = await fetchTeamInfo(token); |
| 22 | const communityUrl = teamInfoResponse?.body?.team?.url; |
| 23 | |
| 24 | if (!!domain && !!communityUrl) { |
| 25 | await updateAccountRedirectDomain(accountId, domain, communityUrl); |
| 26 | } |
| 27 | return { token, syncFrom, shouldJoinChannel }; |
| 28 | } |
no test coverage detected