5748 Create contacts for emails sent and received by email aliases (#5855)

Closes #5748
- Create feature flag
- Add scope `https://www.googleapis.com/auth/profile.emails.read` when
connecting an account
- Get email aliases with google people API, store them in
connectedAccount and refresh them before each message-import
- Update the contact creation logic accordingly
- Refactor

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
bosiraphael
2024-07-01 14:21:34 +02:00
committed by GitHub
parent a15884ea0a
commit 8c33d91734
52 changed files with 1143 additions and 754 deletions

View File

@ -16,33 +16,27 @@ export class GoogleAPIRefreshAccessTokenService {
) {}
async refreshAndSaveAccessToken(
connectedAccount: ConnectedAccountWorkspaceEntity,
workspaceId: string,
connectedAccountId: string,
): Promise<string> {
const connectedAccount = await this.connectedAccountRepository.getById(
connectedAccountId,
workspaceId,
);
if (!connectedAccount) {
throw new Error(
`No connected account found for ${connectedAccountId} in workspace ${workspaceId}`,
);
}
const refreshToken = connectedAccount.refreshToken;
if (!refreshToken) {
throw new Error(
`No refresh token found for connected account ${connectedAccountId} in workspace ${workspaceId}`,
`No refresh token found for connected account ${connectedAccount.id} in workspace ${workspaceId}`,
);
}
const accessToken = await this.refreshAccessToken(refreshToken);
await this.connectedAccountRepository.updateAccessToken(
accessToken,
connectedAccountId,
connectedAccount.id,
workspaceId,
);
await this.connectedAccountRepository.updateAccessToken(
accessToken,
connectedAccount.id,
workspaceId,
);