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.

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/twentyhq/twenty/pull/23558?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
This commit is contained in:
nitin
2026-07-30 18:10:43 +05:30
committed by GitHub
parent e4e1d24731
commit 66e7093524
5 changed files with 3 additions and 42 deletions
@@ -1 +0,0 @@
export const TWENTY_FUNCTIONS_URL_ENV_VAR_NAME = 'TWENTY_FUNCTIONS_URL';
@@ -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: {} }),
@@ -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',
);
});
});
@@ -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<boolean> => {
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),
});
@@ -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;
};