Skip to content

The open alternative to Salesforce, designed for AI.

microsoft webhook ttl fix (#22300)

neo77366edd9621392
diff --git a/packages/twenty-server/src/modules/connected-account/webhook-subscription-manager/drivers/microsoft/constants/microsoft-subscription-ttl-ms-buffer.constant.ts b/packages/twenty-server/src/modules/connected-account/webhook-subscription-manager/drivers/microsoft/constants/microsoft-subscription-ttl-ms-buffer.constant.ts
new file mode 100644
index 00000000000..322afcd7589
--- /dev/null
+++ b/packages/twenty-server/src/modules/connected-account/webhook-subscription-manager/drivers/microsoft/constants/microsoft-subscription-ttl-ms-buffer.constant.ts
@@ -0,0 +1 @@
+export const MICROSOFT_SUBSCRIPTION_TTL_BUFFER_MS = 60 * 60 * 1000;
diff --git a/packages/twenty-server/src/modules/connected-account/webhook-subscription-manager/drivers/microsoft/microsoft-subscription-ttl-ms.constant.ts b/packages/twenty-server/src/modules/connected-account/webhook-subscription-manager/drivers/microsoft/constants/microsoft-subscription-ttl-ms.constant.ts
similarity index 100%
rename from packages/twenty-server/src/modules/connected-account/webhook-subscription-manager/drivers/microsoft/microsoft-subscription-ttl-ms.constant.ts
rename to packages/twenty-server/src/modules/connected-account/webhook-subscription-manager/drivers/microsoft/constants/microsoft-subscription-ttl-ms.constant.ts
diff --git a/packages/twenty-server/src/modules/connected-account/webhook-subscription-manager/drivers/microsoft/microsoft-webhook-subscription.driver.ts b/packages/twenty-server/src/modules/connected-account/webhook-subscription-manager/drivers/microsoft/microsoft-webhook-subscription.driver.ts
index fb2595202f1..2dbdc10e72d 100644
--- a/packages/twenty-server/src/modules/connected-account/webhook-subscription-manager/drivers/microsoft/microsoft-webhook-subscription.driver.ts
+++ b/packages/twenty-server/src/modules/connected-account/webhook-subscription-manager/drivers/microsoft/microsoft-webhook-subscription.driver.ts
@@ -6,7 +6,7 @@ import { isDefined } from 'twenty-shared/utils';
import { WebhookSubscriptionChannelType } from 'twenty-shared/types';
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
-import { MICROSOFT_SUBSCRIPTION_TTL_MS } from 'src/modules/connected-account/webhook-subscription-manager/drivers/microsoft/microsoft-subscription-ttl-ms.constant';
+import { MICROSOFT_SUBSCRIPTION_TTL_MS } from 'src/modules/connected-account/webhook-subscription-manager/drivers/microsoft/constants/microsoft-subscription-ttl-ms.constant';
import {
WebhookSubscriptionDriverException,
WebhookSubscriptionDriverExceptionCode,
@@ -17,6 +17,7 @@ import {
type WebhookSubscriptionResult,
} from 'src/modules/connected-account/webhook-subscription-manager/types/webhook-subscription-driver.type';
import { MicrosoftOAuth2ClientProvider } from 'src/modules/connected-account/oauth2-client-manager/drivers/microsoft/microsoft-oauth2-client.provider';
+import { MICROSOFT_SUBSCRIPTION_TTL_BUFFER_MS } from './constants/microsoft-subscription-ttl-ms-buffer.constant';
type MicrosoftGraphResourceConfig = Pick<
Subscription,
@@ -60,13 +61,16 @@ export class MicrosoftWebhookSubscriptionDriver implements WebhookSubscriptionDr
const notificationUrl = `${this.twentyConfigService.get('SERVER_URL')}/${resourceConfig.notificationPath}`;
+ const SUBSCRIPTION_TTL_MS =
+ MICROSOFT_SUBSCRIPTION_TTL_MS - MICROSOFT_SUBSCRIPTION_TTL_BUFFER_MS;
+
const subscriptionPayload: Subscription = {
changeType: resourceConfig.changeType,
notificationUrl,
lifecycleNotificationUrl: notificationUrl,
resource: resourceConfig.resource,
expirationDateTime: new Date(
- Date.now() + MICROSOFT_SUBSCRIPTION_TTL_MS,
+ Date.now() + SUBSCRIPTION_TTL_MS,
).toISOString(),
clientState,
};
@@ -85,9 +89,12 @@ export class MicrosoftWebhookSubscriptionDriver implements WebhookSubscriptionDr
context.connectedAccountId,
);
+ const SUBSCRIPTION_TTL_MS =
+ MICROSOFT_SUBSCRIPTION_TTL_MS - MICROSOFT_SUBSCRIPTION_TTL_BUFFER_MS;
+
const subscriptionPatch: Subscription = {
expirationDateTime: new Date(
- Date.now() + MICROSOFT_SUBSCRIPTION_TTL_MS,
+ Date.now() + SUBSCRIPTION_TTL_MS,
).toISOString(),
};