The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
revert PR 12884 (#15922)
neo77367846c05bfdf
diff --git a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/services/microsoft-calendar-get-events.service.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/services/microsoft-calendar-get-events.service.tsindex 60fdf4271f5..c10865be7be 100644--- a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/services/microsoft-calendar-get-events.service.ts+++ b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/services/microsoft-calendar-get-events.service.ts@@ -6,15 +6,10 @@ import {type PageIteratorCallback,} from '@microsoft/microsoft-graph-client';-import {- CalendarEventImportDriverException,- CalendarEventImportDriverExceptionCode,-} from 'src/modules/calendar/calendar-event-import-manager/drivers/exceptions/calendar-event-import-driver.exception';import { parseMicrosoftCalendarError } from 'src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/utils/parse-microsoft-calendar-error.util';import { type GetCalendarEventsResponse } from 'src/modules/calendar/calendar-event-import-manager/services/calendar-get-events.service';import { OAuth2ClientManagerService } from 'src/modules/connected-account/oauth2-client-manager/services/oauth2-client-manager.service';import { type ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';-import { isAccessTokenRefreshingError } from 'src/modules/messaging/message-import-manager/drivers/microsoft/utils/is-access-token-refreshing-error.utils';@Injectable()export class MicrosoftCalendarGetEventsService {@@ -61,12 +56,6 @@ export class MicrosoftCalendarGetEventsService {nextSyncCursor: pageIterator.getDeltaLink() || '',};} catch (error) {- if (isAccessTokenRefreshingError(error?.body)) {- throw new CalendarEventImportDriverException(- error.message,- CalendarEventImportDriverExceptionCode.TEMPORARY_ERROR,- );- }throw parseMicrosoftCalendarError(error);}}diff --git a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/services/microsoft-calendar-import-events.service.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/services/microsoft-calendar-import-events.service.tsindex 9cfa0d6a16e..4b526169e45 100644--- a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/services/microsoft-calendar-import-events.service.ts+++ b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/services/microsoft-calendar-import-events.service.ts@@ -2,16 +2,11 @@ import { Injectable } from '@nestjs/common';import { type Event } from '@microsoft/microsoft-graph-types';-import {- CalendarEventImportDriverException,- CalendarEventImportDriverExceptionCode,-} from 'src/modules/calendar/calendar-event-import-manager/drivers/exceptions/calendar-event-import-driver.exception';import { formatMicrosoftCalendarEvents } from 'src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/utils/format-microsoft-calendar-event.util';import { parseMicrosoftCalendarError } from 'src/modules/calendar/calendar-event-import-manager/drivers/microsoft-calendar/utils/parse-microsoft-calendar-error.util';import { type FetchedCalendarEvent } from 'src/modules/calendar/common/types/fetched-calendar-event';import { OAuth2ClientManagerService } from 'src/modules/connected-account/oauth2-client-manager/services/oauth2-client-manager.service';import { type ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';-import { isAccessTokenRefreshingError } from 'src/modules/messaging/message-import-manager/drivers/microsoft/utils/is-access-token-refreshing-error.utils';@Injectable()export class MicrosoftCalendarImportEventsService {@@ -44,13 +39,6 @@ export class MicrosoftCalendarImportEventsService {return formatMicrosoftCalendarEvents(events);} catch (error) {- if (isAccessTokenRefreshingError(error?.body)) {- throw new CalendarEventImportDriverException(- error.message,- CalendarEventImportDriverExceptionCode.TEMPORARY_ERROR,- );- }-throw parseMicrosoftCalendarError(error);}}diff --git a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-account-authentication.service.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-account-authentication.service.tsindex 2526d779b9e..6b058f07d58 100644--- a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-account-authentication.service.ts+++ b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-account-authentication.service.ts@@ -84,7 +84,6 @@ export class CalendarAccountAuthenticationService {error.message,CalendarEventImportDriverExceptionCode.TEMPORARY_ERROR,);- case ConnectedAccountRefreshAccessTokenExceptionCode.REFRESH_ACCESS_TOKEN_FAILED:case ConnectedAccountRefreshAccessTokenExceptionCode.REFRESH_TOKEN_NOT_FOUND:case ConnectedAccountRefreshAccessTokenExceptionCode.INVALID_REFRESH_TOKEN:throw new CalendarEventImportDriverException(diff --git a/packages/twenty-server/src/modules/connected-account/email-alias-manager/drivers/microsoft/microsoft-email-alias-manager.service.ts b/packages/twenty-server/src/modules/connected-account/email-alias-manager/drivers/microsoft/microsoft-email-alias-manager.service.tsindex 7015f576b26..b9126648f9d 100644--- a/packages/twenty-server/src/modules/connected-account/email-alias-manager/drivers/microsoft/microsoft-email-alias-manager.service.ts+++ b/packages/twenty-server/src/modules/connected-account/email-alias-manager/drivers/microsoft/microsoft-email-alias-manager.service.ts@@ -4,11 +4,6 @@ import { isNonEmptyString } from '@sniptt/guards';import { OAuth2ClientManagerService } from 'src/modules/connected-account/oauth2-client-manager/services/oauth2-client-manager.service';import { type ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';-import {- MessageImportDriverException,- MessageImportDriverExceptionCode,-} from 'src/modules/messaging/message-import-manager/drivers/exceptions/message-import-driver.exception';-import { isAccessTokenRefreshingError } from 'src/modules/messaging/message-import-manager/drivers/microsoft/utils/is-access-token-refreshing-error.utils';@Injectable()export class MicrosoftEmailAliasManagerService {@@ -28,12 +23,6 @@ export class MicrosoftEmailAliasManagerService {.api('/me?$select=proxyAddresses').get().catch((error) => {- if (isAccessTokenRefreshingError(error?.message)) {- throw new MessageImportDriverException(- error.message,- MessageImportDriverExceptionCode.CLIENT_NOT_AVAILABLE,- );- }throw new Error(`Failed to fetch email aliases: ${error.message}`);});diff --git a/packages/twenty-server/src/modules/connected-account/refresh-tokens-manager/exceptions/connected-account-refresh-tokens.exception.ts b/packages/twenty-server/src/modules/connected-account/refresh-tokens-manager/exceptions/connected-account-refresh-tokens.exception.tsindex 86aa4fdca3d..908e20b646b 100644--- a/packages/twenty-server/src/modules/connected-account/refresh-tokens-manager/exceptions/connected-account-refresh-tokens.exception.ts+++ b/packages/twenty-server/src/modules/connected-account/refresh-tokens-manager/exceptions/connected-account-refresh-tokens.exception.ts@@ -5,7 +5,6 @@ export class ConnectedAccountRefreshAccessTokenException extends CustomExceptionexport enum ConnectedAccountRefreshAccessTokenExceptionCode {REFRESH_TOKEN_NOT_FOUND = 'REFRESH_TOKEN_NOT_FOUND',INVALID_REFRESH_TOKEN = 'INVALID_REFRESH_TOKEN',- REFRESH_ACCESS_TOKEN_FAILED = 'REFRESH_ACCESS_TOKEN_FAILED',PROVIDER_NOT_SUPPORTED = 'PROVIDER_NOT_SUPPORTED',TEMPORARY_NETWORK_ERROR = 'TEMPORARY_NETWORK_ERROR',}diff --git a/packages/twenty-server/src/modules/connected-account/refresh-tokens-manager/services/connected-account-refresh-tokens.service.ts b/packages/twenty-server/src/modules/connected-account/refresh-tokens-manager/services/connected-account-refresh-tokens.service.tsindex 3b3853f46d2..484ceb0c085 100644--- a/packages/twenty-server/src/modules/connected-account/refresh-tokens-manager/services/connected-account-refresh-tokens.service.ts+++ b/packages/twenty-server/src/modules/connected-account/refresh-tokens-manager/services/connected-account-refresh-tokens.service.ts@@ -133,7 +133,7 @@ export class ConnectedAccountRefreshTokensService {case ConnectedAccountProvider.IMAP_SMTP_CALDAV:throw new ConnectedAccountRefreshAccessTokenException(`Token refresh is not supported for IMAP provider for connected account ${connectedAccount.id} in workspace ${workspaceId}`,- ConnectedAccountRefreshAccessTokenExceptionCode.REFRESH_ACCESS_TOKEN_FAILED,+ ConnectedAccountRefreshAccessTokenExceptionCode.PROVIDER_NOT_SUPPORTED,);default:return assertUnreachable(diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/imap/utils/parse-imap-error.util.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/imap/utils/parse-imap-error.util.tsindex 97e278e0258..7999b5620e4 100644--- a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/imap/utils/parse-imap-error.util.ts+++ b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/imap/utils/parse-imap-error.util.ts@@ -20,7 +20,7 @@ export const parseImapError = (if (error.message.includes('Connection not available')) {return new MessageImportDriverException(`IMAP client not available: ${error.message}`,- MessageImportDriverExceptionCode.CLIENT_NOT_AVAILABLE,+ MessageImportDriverExceptionCode.TEMPORARY_ERROR,{ cause: options?.cause || error },);}diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-get-message-list.service.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-get-message-list.service.tsindex 9d680ae432d..119218770a4 100644--- a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-get-message-list.service.ts+++ b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-get-message-list.service.ts@@ -15,7 +15,6 @@ import {MessageImportDriverExceptionCode,} from 'src/modules/messaging/message-import-manager/drivers/exceptions/message-import-driver.exception';import { MicrosoftMessageListFetchErrorHandler } from 'src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-message-list-fetch-error-handler.service';-import { isAccessTokenRefreshingError } from 'src/modules/messaging/message-import-manager/drivers/microsoft/utils/is-access-token-refreshing-error.utils';import { type GetMessageListsArgs } from 'src/modules/messaging/message-import-manager/types/get-message-lists-args.type';import {type GetMessageListsResponse,@@ -93,12 +92,6 @@ export class MicrosoftGetMessageListService {this.logger.error(`Connected account ${connectedAccount.id}: Error fetching message list: ${JSON.stringify(error)}`,);- if (isAccessTokenRefreshingError(error?.body)) {- throw new MessageImportDriverException(- error.message,- MessageImportDriverExceptionCode.CLIENT_NOT_AVAILABLE,- );- }this.microsoftMessageListFetchErrorHandler.handleError(error);});@@ -119,12 +112,6 @@ export class MicrosoftGetMessageListService {});await pageIterator.iterate().catch((error) => {- if (isAccessTokenRefreshingError(error?.body)) {- throw new MessageImportDriverException(- error.message,- MessageImportDriverExceptionCode.CLIENT_NOT_AVAILABLE,- );- }this.microsoftMessageListFetchErrorHandler.handleError(error);});diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-network-error-handler.service.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-network-error-handler.service.tsindex 302266d193d..86ace1afcf7 100644--- a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-network-error-handler.service.ts+++ b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-network-error-handler.service.ts@@ -4,7 +4,6 @@ import {MessageImportDriverException,MessageImportDriverExceptionCode,} from 'src/modules/messaging/message-import-manager/drivers/exceptions/message-import-driver.exception';-import { isAccessTokenRefreshingError } from 'src/modules/messaging/message-import-manager/drivers/microsoft/utils/is-access-token-refreshing-error.utils';import { isMicrosoftClientTemporaryError } from 'src/modules/messaging/message-import-manager/drivers/microsoft/utils/is-temporary-error.utils';@Injectable()@@ -13,14 +12,6 @@ export class MicrosoftNetworkErrorHandler {// eslint-disable-next-line @typescript-eslint/no-explicit-anypublic handleError(error: any): MessageImportDriverException | null {- if (isAccessTokenRefreshingError(error?.body)) {- return new MessageImportDriverException(- error.message,- MessageImportDriverExceptionCode.CLIENT_NOT_AVAILABLE,- { cause: error },- );- }-const isBodyString = error.body && typeof error.body === 'string';const isTemporaryError =isBodyString && isMicrosoftClientTemporaryError(error.body);diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/utils/is-access-token-refreshing-error.utils.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/utils/is-access-token-refreshing-error.utils.tsdeleted file mode 100644index 396688773f7..00000000000--- a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/microsoft/utils/is-access-token-refreshing-error.utils.ts+++ /dev/null@@ -1,7 +0,0 @@-import { ConnectedAccountRefreshAccessTokenExceptionCode } from 'src/modules/connected-account/refresh-tokens-manager/exceptions/connected-account-refresh-tokens.exception';--export const isAccessTokenRefreshingError = (body: string): boolean => {- return body.includes(- ConnectedAccountRefreshAccessTokenExceptionCode.REFRESH_ACCESS_TOKEN_FAILED,- );-};diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-account-authentication.service.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-account-authentication.service.tsindex 82f561a1d88..f58f0053de4 100644--- a/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-account-authentication.service.ts+++ b/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-account-authentication.service.ts@@ -96,7 +96,6 @@ export class MessagingAccountAuthenticationService {error.message,MessageImportDriverExceptionCode.TEMPORARY_ERROR,);- case ConnectedAccountRefreshAccessTokenExceptionCode.REFRESH_ACCESS_TOKEN_FAILED:case ConnectedAccountRefreshAccessTokenExceptionCode.REFRESH_TOKEN_NOT_FOUND:case ConnectedAccountRefreshAccessTokenExceptionCode.INVALID_REFRESH_TOKEN:await this.messagingMonitoringService.track({diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-import-exception-handler.service.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-import-exception-handler.service.tsindex 4bb42c6ff6b..34e9a6f81a3 100644--- a/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-import-exception-handler.service.ts+++ b/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-import-exception-handler.service.ts@@ -68,7 +68,6 @@ export class MessageImportExceptionHandlerService {case MessageNetworkExceptionCode.ECONNRESET:case MessageNetworkExceptionCode.ETIMEDOUT:case MessageNetworkExceptionCode.ERR_NETWORK:- case MessageImportDriverExceptionCode.CLIENT_NOT_AVAILABLE:await this.handleTemporaryException(syncStep,messageChannel,diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-send-message.service.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-send-message.service.tsindex ae3df05e974..97add291e73 100644--- a/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-send-message.service.ts+++ b/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-send-message.service.ts@@ -8,12 +8,7 @@ import { z } from 'zod';import { OAuth2ClientManagerService } from 'src/modules/connected-account/oauth2-client-manager/services/oauth2-client-manager.service';import { type ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';-import {- MessageImportDriverException,- MessageImportDriverExceptionCode,-} from 'src/modules/messaging/message-import-manager/drivers/exceptions/message-import-driver.exception';import { ImapClientProvider } from 'src/modules/messaging/message-import-manager/drivers/imap/providers/imap-client.provider';-import { isAccessTokenRefreshingError } from 'src/modules/messaging/message-import-manager/drivers/microsoft/utils/is-access-token-refreshing-error.utils';import { SmtpClientProvider } from 'src/modules/messaging/message-import-manager/drivers/smtp/providers/smtp-client.provider';import { mimeEncode } from 'src/modules/messaging/message-import-manager/utils/mime-encode.util';@@ -130,31 +125,11 @@ export class MessagingSendMessageService {const response = await microsoftClient.api(`/me/messages`)- .post(message)- .catch((error) => {- if (isAccessTokenRefreshingError(error?.body)) {- throw new MessageImportDriverException(- error.message,- MessageImportDriverExceptionCode.CLIENT_NOT_AVAILABLE,- );- }- throw error;- });+ .post(message);z.string().parse(response.id);- await microsoftClient- .api(`/me/messages/${response.id}/send`)- .post({})- .catch((error) => {- if (isAccessTokenRefreshingError(error?.body)) {- throw new MessageImportDriverException(- error.message,- MessageImportDriverExceptionCode.CLIENT_NOT_AVAILABLE,- );- }- throw error;- });+ await microsoftClient.api(`/me/messages/${response.id}/send`).post({});break;}