The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix: drop domain from computed remote name when subdomain present (#22376)
martmull06515408d11b
diff --git a/packages/twenty-sdk/src/cli/commands/remote/__tests__/derive-remote-name.spec.ts b/packages/twenty-sdk/src/cli/commands/remote/__tests__/derive-remote-name.spec.tsnew file mode 100644index 00000000000..67737a7d1bb--- /dev/null+++ b/packages/twenty-sdk/src/cli/commands/remote/__tests__/derive-remote-name.spec.ts@@ -0,0 +1,31 @@+import { deriveRemoteName } from '@/cli/commands/remote/derive-remote-name';++describe('deriveRemoteName', () => {+ it('should use only the subdomain when the host has one', () => {+ expect(deriveRemoteName('https://martin-s-workspace.twenty.com')).toBe(+ 'martin-s-workspace',+ );+ });++ it('should join multiple subdomain labels with dashes', () => {+ expect(deriveRemoteName('https://app.staging.twenty.com')).toBe(+ 'app-staging',+ );+ });++ it('should drop the tld when there is no subdomain', () => {+ expect(deriveRemoteName('https://twenty.com')).toBe('twenty');+ });++ it('should handle single-label hosts like localhost', () => {+ expect(deriveRemoteName('http://localhost:3000')).toBe('localhost');+ });++ it('should keep IPv4 addresses intact', () => {+ expect(deriveRemoteName('http://127.0.0.1:3000')).toBe('127-0-0-1');+ });++ it('should fall back to "remote" for invalid URLs', () => {+ expect(deriveRemoteName('not a url')).toBe('remote');+ });+});diff --git a/packages/twenty-sdk/src/cli/commands/remote/derive-remote-name.ts b/packages/twenty-sdk/src/cli/commands/remote/derive-remote-name.tsnew file mode 100644index 00000000000..ca07507e40d--- /dev/null+++ b/packages/twenty-sdk/src/cli/commands/remote/derive-remote-name.ts@@ -0,0 +1,25 @@+const IPV4_REGEX = /^(\d{1,3}\.){3}\d{1,3}$/;++export const deriveRemoteName = (url: string): string => {+ try {+ const { hostname } = new URL(url);++ if (IPV4_REGEX.test(hostname)) {+ return hostname.replace(/\./g, '-');+ }++ const labels = hostname.split('.');++ if (labels.length > 2) {+ return labels.slice(0, -2).join('-');+ }++ if (labels.length === 2) {+ return labels[0];+ }++ return labels.join('-');+ } catch {+ return 'remote';+ }+};diff --git a/packages/twenty-sdk/src/cli/commands/remote/index.ts b/packages/twenty-sdk/src/cli/commands/remote/index.tsindex 8493454efac..1adbcd9fac3 100644--- a/packages/twenty-sdk/src/cli/commands/remote/index.ts+++ b/packages/twenty-sdk/src/cli/commands/remote/index.ts@@ -1,3 +1,4 @@+import { deriveRemoteName } from '@/cli/commands/remote/derive-remote-name';import { authLogin } from '@/cli/operations/login';import { authLoginOAuth } from '@/cli/operations/login-oauth';import { ApiService } from '@/cli/utilities/api/api-service';@@ -9,16 +10,6 @@ import type { Command } from 'commander';import inquirer from 'inquirer';import { normalizeUrl } from 'twenty-shared/utils';-const deriveRemoteName = (url: string): string => {- try {- const hostname = new URL(url).hostname;-- return hostname.replace(/\./g, '-');- } catch {- return 'remote';- }-};-type AuthMethod = 'OAuth' | 'API key';const authenticate = async (