From 66e70935244bc3ec29af7ff04dc63a69c2d0b401 Mon Sep 17 00:00:00 2001
From: nitin <142569587+ehconitin@users.noreply.github.com>
Date: Thu, 30 Jul 2026 18:10:43 +0530
Subject: [PATCH] Use client SDK /s dispatch for call-recorder own-route posts
(#23558)
Migrates call-recorder's own-route self-invoke helper off hand-resolved
`TWENTY_FUNCTIONS_URL` and onto the client SDK's built-in `/s` dispatch
(#22863): `postToOwnRoute` now constructs `RestApiClient` with no base
URL and posts to `/s${path}`, letting the SDK resolve
`TWENTY_FUNCTIONS_URL` itself and fall back to `${TWENTY_API_URL}/s`
when it is empty (works on bare multiworkspace hosts since #23490).
Removes the now-unused `resolveOwnRouteBaseUrl` util, its test, and the
env-var-name constant.
Where `TWENTY_FUNCTIONS_URL` is injected non-empty the SDK builds the
identical URL; where it is empty the old code threw and returned false,
while the SDK fallback works on servers with #23490 and fails-caught
identically on servers without it.
---
.../twenty-functions-url-env-var-name.ts | 1 -
.../data/__tests__/post-to-own-route.test.ts | 1 +
.../resolve-own-route-base-url.test.ts | 23 -------------------
.../data/post-to-own-route.util.ts | 6 ++---
.../data/resolve-own-route-base-url.util.ts | 14 -----------
5 files changed, 3 insertions(+), 42 deletions(-)
delete mode 100644 packages/twenty-apps/public/call-recorder/src/constants/twenty-functions-url-env-var-name.ts
delete mode 100644 packages/twenty-apps/public/call-recorder/src/logic-functions/data/__tests__/resolve-own-route-base-url.test.ts
delete mode 100644 packages/twenty-apps/public/call-recorder/src/logic-functions/data/resolve-own-route-base-url.util.ts
diff --git a/packages/twenty-apps/public/call-recorder/src/constants/twenty-functions-url-env-var-name.ts b/packages/twenty-apps/public/call-recorder/src/constants/twenty-functions-url-env-var-name.ts
deleted file mode 100644
index ddd582a4c0..0000000000
--- a/packages/twenty-apps/public/call-recorder/src/constants/twenty-functions-url-env-var-name.ts
+++ /dev/null
@@ -1 +0,0 @@
-export const TWENTY_FUNCTIONS_URL_ENV_VAR_NAME = 'TWENTY_FUNCTIONS_URL';
diff --git a/packages/twenty-apps/public/call-recorder/src/logic-functions/data/__tests__/post-to-own-route.test.ts b/packages/twenty-apps/public/call-recorder/src/logic-functions/data/__tests__/post-to-own-route.test.ts
index 824117bd9d..6d738c3748 100644
--- a/packages/twenty-apps/public/call-recorder/src/logic-functions/data/__tests__/post-to-own-route.test.ts
+++ b/packages/twenty-apps/public/call-recorder/src/logic-functions/data/__tests__/post-to-own-route.test.ts
@@ -55,6 +55,7 @@ describe('postToOwnRoute', () => {
it('returns false when the route base url cannot be resolved', async () => {
vi.stubEnv('TWENTY_FUNCTIONS_URL', '');
+ vi.stubEnv('TWENTY_API_URL', '');
await expect(
postToOwnRoute({ path: '/call-recorder/some-route', body: {} }),
diff --git a/packages/twenty-apps/public/call-recorder/src/logic-functions/data/__tests__/resolve-own-route-base-url.test.ts b/packages/twenty-apps/public/call-recorder/src/logic-functions/data/__tests__/resolve-own-route-base-url.test.ts
deleted file mode 100644
index 4d5761e133..0000000000
--- a/packages/twenty-apps/public/call-recorder/src/logic-functions/data/__tests__/resolve-own-route-base-url.test.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import { afterEach, describe, expect, it, vi } from 'vitest';
-
-import { resolveOwnRouteBaseUrl } from 'src/logic-functions/data/resolve-own-route-base-url.util';
-
-describe('resolveOwnRouteBaseUrl', () => {
- afterEach(() => {
- vi.unstubAllEnvs();
- });
-
- it('returns the injected functions url', () => {
- vi.stubEnv('TWENTY_FUNCTIONS_URL', 'https://acme.functions.example.com');
-
- expect(resolveOwnRouteBaseUrl()).toBe('https://acme.functions.example.com');
- });
-
- it('fails clearly when the functions url is not injected', () => {
- vi.stubEnv('TWENTY_FUNCTIONS_URL', '');
-
- expect(() => resolveOwnRouteBaseUrl()).toThrow(
- 'Unable to resolve Call Recorder own route target without TWENTY_FUNCTIONS_URL',
- );
- });
-});
diff --git a/packages/twenty-apps/public/call-recorder/src/logic-functions/data/post-to-own-route.util.ts b/packages/twenty-apps/public/call-recorder/src/logic-functions/data/post-to-own-route.util.ts
index 9445f41a22..2cd3c4d5a6 100644
--- a/packages/twenty-apps/public/call-recorder/src/logic-functions/data/post-to-own-route.util.ts
+++ b/packages/twenty-apps/public/call-recorder/src/logic-functions/data/post-to-own-route.util.ts
@@ -1,7 +1,5 @@
import { RestApiClient } from 'twenty-client-sdk/rest';
-import { resolveOwnRouteBaseUrl } from 'src/logic-functions/data/resolve-own-route-base-url.util';
-
const OWN_ROUTE_FLUSH_MS = 5_000;
// Fire-and-forget POST to one of this app's own HTTP routes; a timeout only
@@ -14,9 +12,9 @@ export const postToOwnRoute = async ({
body: object;
}): Promise => {
try {
- const client = new RestApiClient({ baseUrl: resolveOwnRouteBaseUrl() });
+ const client = new RestApiClient();
- await client.post(path, body, {
+ await client.post(`/s${path}`, body, {
signal: AbortSignal.timeout(OWN_ROUTE_FLUSH_MS),
});
diff --git a/packages/twenty-apps/public/call-recorder/src/logic-functions/data/resolve-own-route-base-url.util.ts b/packages/twenty-apps/public/call-recorder/src/logic-functions/data/resolve-own-route-base-url.util.ts
deleted file mode 100644
index d8491ccf3d..0000000000
--- a/packages/twenty-apps/public/call-recorder/src/logic-functions/data/resolve-own-route-base-url.util.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { TWENTY_FUNCTIONS_URL_ENV_VAR_NAME } from 'src/constants/twenty-functions-url-env-var-name';
-import { isNonEmptyString } from 'src/logic-functions/utils/is-non-empty-string.util';
-
-export const resolveOwnRouteBaseUrl = (): string => {
- const injectedFunctionsUrl = process.env[TWENTY_FUNCTIONS_URL_ENV_VAR_NAME];
-
- if (!isNonEmptyString(injectedFunctionsUrl)) {
- throw new Error(
- `Unable to resolve Call Recorder own route target without ${TWENTY_FUNCTIONS_URL_ENV_VAR_NAME}`,
- );
- }
-
- return injectedFunctionsUrl;
-};