From c90ce33516bc583420954a72ef80a09671701560 Mon Sep 17 00:00:00 2001 From: Samyak Piya Date: Thu, 19 Dec 2024 13:27:00 -0500 Subject: [PATCH 1/7] feat: add company enrichment service for logo fetching --- .../company-enrichment.service.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 packages/twenty-server/src/engine/core-modules/company-enrichment/company-enrichment.service.ts diff --git a/packages/twenty-server/src/engine/core-modules/company-enrichment/company-enrichment.service.ts b/packages/twenty-server/src/engine/core-modules/company-enrichment/company-enrichment.service.ts new file mode 100644 index 000000000000..5ca288af1cae --- /dev/null +++ b/packages/twenty-server/src/engine/core-modules/company-enrichment/company-enrichment.service.ts @@ -0,0 +1,24 @@ +import { Injectable } from '@nestjs/common'; + +import { isWorkEmail } from 'src/utils/is-work-email'; +import { getDomainNameByEmail } from 'src/utils/get-domain-name-by-email'; + +@Injectable() +export class CompanyEnrichmentService { + private readonly TWENTY_ICONS_BASE_URL = 'https://twenty-icons.com'; + + async getCompanyLogoUrl(email: string): Promise { + if (!isWorkEmail(email)) { + return undefined; + } + + const domain = getDomainNameByEmail(email); + + return `${this.TWENTY_ICONS_BASE_URL}/${domain}`; + } + + // Future enrichment methods can be added here + // async getCompanyData(email: string): Promise { + // // Pull data from twenty-companies.com + // } +} From fe14bc7a5ce216c0a6a307206704e52f75df3bed Mon Sep 17 00:00:00 2001 From: Samyak Piya Date: Thu, 19 Dec 2024 13:28:43 -0500 Subject: [PATCH 2/7] feat: add company enrichment module --- .../company-enrichment/company-enrichment.module.ts | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 packages/twenty-server/src/engine/core-modules/company-enrichment/company-enrichment.module.ts diff --git a/packages/twenty-server/src/engine/core-modules/company-enrichment/company-enrichment.module.ts b/packages/twenty-server/src/engine/core-modules/company-enrichment/company-enrichment.module.ts new file mode 100644 index 000000000000..c5ea6ff88244 --- /dev/null +++ b/packages/twenty-server/src/engine/core-modules/company-enrichment/company-enrichment.module.ts @@ -0,0 +1,9 @@ +import { Module } from '@nestjs/common'; + +import { CompanyEnrichmentService } from './company-enrichment.service'; + +@Module({ + providers: [CompanyEnrichmentService], + exports: [CompanyEnrichmentService], +}) +export class CompanyEnrichmentModule {} From 00a9033d86b5031f98b1943bcf09b694e904b5d4 Mon Sep 17 00:00:00 2001 From: Samyak Piya Date: Thu, 19 Dec 2024 13:43:10 -0500 Subject: [PATCH 3/7] feat: integrate company enrichment module with auth --- .../twenty-server/src/engine/core-modules/auth/auth.module.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/twenty-server/src/engine/core-modules/auth/auth.module.ts b/packages/twenty-server/src/engine/core-modules/auth/auth.module.ts index 401ce04b0a4e..e2ff0465d83d 100644 --- a/packages/twenty-server/src/engine/core-modules/auth/auth.module.ts +++ b/packages/twenty-server/src/engine/core-modules/auth/auth.module.ts @@ -39,6 +39,7 @@ import { UserModule } from 'src/engine/core-modules/user/user.module'; import { WorkspaceInvitationModule } from 'src/engine/core-modules/workspace-invitation/workspace-invitation.module'; import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity'; import { WorkspaceModule } from 'src/engine/core-modules/workspace/workspace.module'; +import { CompanyEnrichmentModule } from 'src/engine/core-modules/company-enrichment/company-enrichment.module'; import { DataSourceModule } from 'src/engine/metadata-modules/data-source/data-source.module'; import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module'; import { WorkspaceManagerModule } from 'src/engine/workspace-manager/workspace-manager.module'; @@ -79,6 +80,7 @@ import { JwtAuthStrategy } from './strategies/jwt.auth.strategy'; WorkspaceSSOModule, FeatureFlagModule, WorkspaceInvitationModule, + CompanyEnrichmentModule, ], controllers: [ GoogleAuthController, From 08d23a9905d3d6ecca49870b0096a8a473f93277 Mon Sep 17 00:00:00 2001 From: Samyak Piya Date: Thu, 19 Dec 2024 13:43:27 -0500 Subject: [PATCH 4/7] feat: add automatic company logo setting during workspace creation --- .../engine/core-modules/auth/services/sign-in-up.service.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/twenty-server/src/engine/core-modules/auth/services/sign-in-up.service.ts b/packages/twenty-server/src/engine/core-modules/auth/services/sign-in-up.service.ts index f11b02d7dcd4..b48ea953bc87 100644 --- a/packages/twenty-server/src/engine/core-modules/auth/services/sign-in-up.service.ts +++ b/packages/twenty-server/src/engine/core-modules/auth/services/sign-in-up.service.ts @@ -34,6 +34,7 @@ import { workspaceValidator } from 'src/engine/core-modules/workspace/workspace. import { getImageBufferFromUrl } from 'src/utils/image'; import { WorkspaceAuthProvider } from 'src/engine/core-modules/workspace/types/workspace.type'; import { UserService } from 'src/engine/core-modules/user/services/user.service'; +import { CompanyEnrichmentService } from 'src/engine/core-modules/company-enrichment/company-enrichment.service'; export type SignInUpServiceInput = { email: string; @@ -64,6 +65,7 @@ export class SignInUpService { private readonly environmentService: EnvironmentService, private readonly domainManagerService: DomainManagerService, private readonly userService: UserService, + private readonly companyEnrichmentService: CompanyEnrichmentService, ) {} async signInUp({ @@ -333,11 +335,15 @@ export class SignInUpService { } } + const logoUrl = + await this.companyEnrichmentService.getCompanyLogoUrl(email); + const workspaceToCreate = this.workspaceRepository.create({ subdomain: await this.domainManagerService.generateSubdomain(), displayName: '', domainName: '', inviteHash: v4(), + logo: logoUrl, activationStatus: WorkspaceActivationStatus.PENDING_CREATION, }); From f1a616c77e9a6c13fe48fd2f47bdabb01297b53b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Malfait?= Date: Fri, 20 Dec 2024 17:18:27 +0100 Subject: [PATCH 5/7] Simplify --- .vscode/twenty.code-workspace | 4 ++++ .../twenty-server/jest-integration.config.ts | 1 + packages/twenty-server/package.json | 3 ++- .../engine/core-modules/auth/auth.module.ts | 2 -- .../auth/services/sign-in-up.service.ts | 16 +++++++------ .../company-enrichment.module.ts | 9 ------- .../company-enrichment.service.ts | 24 ------------------- .../services/create-company.service.ts | 3 ++- packages/twenty-server/tsconfig.json | 3 ++- packages/twenty-shared/package.json | 2 +- .../src/constants/TwentyCompaniesBaseUrl.ts | 1 + .../src/constants/TwentyIconsBaseUrl.ts | 1 + packages/twenty-shared/src/index.ts | 2 ++ 13 files changed, 25 insertions(+), 46 deletions(-) delete mode 100644 packages/twenty-server/src/engine/core-modules/company-enrichment/company-enrichment.module.ts delete mode 100644 packages/twenty-server/src/engine/core-modules/company-enrichment/company-enrichment.service.ts create mode 100644 packages/twenty-shared/src/constants/TwentyCompaniesBaseUrl.ts create mode 100644 packages/twenty-shared/src/constants/TwentyIconsBaseUrl.ts diff --git a/.vscode/twenty.code-workspace b/.vscode/twenty.code-workspace index 38d8b34543a6..57d28b0450b7 100644 --- a/.vscode/twenty.code-workspace +++ b/.vscode/twenty.code-workspace @@ -24,6 +24,10 @@ "name": "packages/twenty-emails", "path": "../packages/twenty-emails" }, + { + "name": "packages/twenty-shared", + "path": "../packages/twenty-shared" + }, { "name": "packages/twenty-server", "path": "../packages/twenty-server" diff --git a/packages/twenty-server/jest-integration.config.ts b/packages/twenty-server/jest-integration.config.ts index 5cf3ce61f371..cbb53051d1fd 100644 --- a/packages/twenty-server/jest-integration.config.ts +++ b/packages/twenty-server/jest-integration.config.ts @@ -21,6 +21,7 @@ const jestConfig: JestConfigWithTsJest = { }), '^test/(.*)$': '/test/$1', 'twenty-emails': '/../twenty-emails/dist/index.js', + 'twenty-shared': '/../twenty-shared/dist/index.js', }, fakeTimers: { enableGlobally: true, diff --git a/packages/twenty-server/package.json b/packages/twenty-server/package.json index 6de9253d6e35..1c7529d92e5e 100644 --- a/packages/twenty-server/package.json +++ b/packages/twenty-server/package.json @@ -53,7 +53,8 @@ "tsconfig-paths": "^4.2.0", "typeorm": "patch:typeorm@0.3.20#./patches/typeorm+0.3.20.patch", "unzipper": "^0.12.3", - "zod-to-json-schema": "^3.23.1" + "zod-to-json-schema": "^3.23.1", + "@twenty/twenty-shared": "0.40.0-canary" }, "devDependencies": { "@nestjs/cli": "10.3.0", diff --git a/packages/twenty-server/src/engine/core-modules/auth/auth.module.ts b/packages/twenty-server/src/engine/core-modules/auth/auth.module.ts index e2ff0465d83d..401ce04b0a4e 100644 --- a/packages/twenty-server/src/engine/core-modules/auth/auth.module.ts +++ b/packages/twenty-server/src/engine/core-modules/auth/auth.module.ts @@ -39,7 +39,6 @@ import { UserModule } from 'src/engine/core-modules/user/user.module'; import { WorkspaceInvitationModule } from 'src/engine/core-modules/workspace-invitation/workspace-invitation.module'; import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity'; import { WorkspaceModule } from 'src/engine/core-modules/workspace/workspace.module'; -import { CompanyEnrichmentModule } from 'src/engine/core-modules/company-enrichment/company-enrichment.module'; import { DataSourceModule } from 'src/engine/metadata-modules/data-source/data-source.module'; import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module'; import { WorkspaceManagerModule } from 'src/engine/workspace-manager/workspace-manager.module'; @@ -80,7 +79,6 @@ import { JwtAuthStrategy } from './strategies/jwt.auth.strategy'; WorkspaceSSOModule, FeatureFlagModule, WorkspaceInvitationModule, - CompanyEnrichmentModule, ], controllers: [ GoogleAuthController, diff --git a/packages/twenty-server/src/engine/core-modules/auth/services/sign-in-up.service.ts b/packages/twenty-server/src/engine/core-modules/auth/services/sign-in-up.service.ts index b48ea953bc87..2f9a3beb8b2c 100644 --- a/packages/twenty-server/src/engine/core-modules/auth/services/sign-in-up.service.ts +++ b/packages/twenty-server/src/engine/core-modules/auth/services/sign-in-up.service.ts @@ -4,6 +4,7 @@ import { InjectRepository } from '@nestjs/typeorm'; import { isDefined } from 'class-validator'; import FileType from 'file-type'; +import { TWENTY_ICONS_BASE_URL } from 'twenty-shared'; import { Repository } from 'typeorm'; import { v4 } from 'uuid'; @@ -23,18 +24,19 @@ import { EnvironmentService } from 'src/engine/core-modules/environment/environm import { FileUploadService } from 'src/engine/core-modules/file/file-upload/services/file-upload.service'; import { OnboardingService } from 'src/engine/core-modules/onboarding/onboarding.service'; import { UserWorkspaceService } from 'src/engine/core-modules/user-workspace/user-workspace.service'; +import { UserService } from 'src/engine/core-modules/user/services/user.service'; import { User } from 'src/engine/core-modules/user/user.entity'; import { userValidator } from 'src/engine/core-modules/user/user.validate'; import { WorkspaceInvitationService } from 'src/engine/core-modules/workspace-invitation/services/workspace-invitation.service'; +import { WorkspaceAuthProvider } from 'src/engine/core-modules/workspace/types/workspace.type'; import { Workspace, WorkspaceActivationStatus, } from 'src/engine/core-modules/workspace/workspace.entity'; import { workspaceValidator } from 'src/engine/core-modules/workspace/workspace.validate'; +import { getDomainNameByEmail } from 'src/utils/get-domain-name-by-email'; import { getImageBufferFromUrl } from 'src/utils/image'; -import { WorkspaceAuthProvider } from 'src/engine/core-modules/workspace/types/workspace.type'; -import { UserService } from 'src/engine/core-modules/user/services/user.service'; -import { CompanyEnrichmentService } from 'src/engine/core-modules/company-enrichment/company-enrichment.service'; +import { isWorkEmail } from 'src/utils/is-work-email'; export type SignInUpServiceInput = { email: string; @@ -65,7 +67,6 @@ export class SignInUpService { private readonly environmentService: EnvironmentService, private readonly domainManagerService: DomainManagerService, private readonly userService: UserService, - private readonly companyEnrichmentService: CompanyEnrichmentService, ) {} async signInUp({ @@ -335,16 +336,17 @@ export class SignInUpService { } } - const logoUrl = - await this.companyEnrichmentService.getCompanyLogoUrl(email); + const logo = isWorkEmail(email) + ? `${TWENTY_ICONS_BASE_URL}/${getDomainNameByEmail(email)}` + : undefined; const workspaceToCreate = this.workspaceRepository.create({ subdomain: await this.domainManagerService.generateSubdomain(), displayName: '', domainName: '', inviteHash: v4(), - logo: logoUrl, activationStatus: WorkspaceActivationStatus.PENDING_CREATION, + logo, }); const workspace = await this.workspaceRepository.save(workspaceToCreate); diff --git a/packages/twenty-server/src/engine/core-modules/company-enrichment/company-enrichment.module.ts b/packages/twenty-server/src/engine/core-modules/company-enrichment/company-enrichment.module.ts deleted file mode 100644 index c5ea6ff88244..000000000000 --- a/packages/twenty-server/src/engine/core-modules/company-enrichment/company-enrichment.module.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Module } from '@nestjs/common'; - -import { CompanyEnrichmentService } from './company-enrichment.service'; - -@Module({ - providers: [CompanyEnrichmentService], - exports: [CompanyEnrichmentService], -}) -export class CompanyEnrichmentModule {} diff --git a/packages/twenty-server/src/engine/core-modules/company-enrichment/company-enrichment.service.ts b/packages/twenty-server/src/engine/core-modules/company-enrichment/company-enrichment.service.ts deleted file mode 100644 index 5ca288af1cae..000000000000 --- a/packages/twenty-server/src/engine/core-modules/company-enrichment/company-enrichment.service.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Injectable } from '@nestjs/common'; - -import { isWorkEmail } from 'src/utils/is-work-email'; -import { getDomainNameByEmail } from 'src/utils/get-domain-name-by-email'; - -@Injectable() -export class CompanyEnrichmentService { - private readonly TWENTY_ICONS_BASE_URL = 'https://twenty-icons.com'; - - async getCompanyLogoUrl(email: string): Promise { - if (!isWorkEmail(email)) { - return undefined; - } - - const domain = getDomainNameByEmail(email); - - return `${this.TWENTY_ICONS_BASE_URL}/${domain}`; - } - - // Future enrichment methods can be added here - // async getCompanyData(email: string): Promise { - // // Pull data from twenty-companies.com - // } -} diff --git a/packages/twenty-server/src/modules/contact-creation-manager/services/create-company.service.ts b/packages/twenty-server/src/modules/contact-creation-manager/services/create-company.service.ts index bed7f1509bb5..a8388ec2d285 100644 --- a/packages/twenty-server/src/modules/contact-creation-manager/services/create-company.service.ts +++ b/packages/twenty-server/src/modules/contact-creation-manager/services/create-company.service.ts @@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common'; import axios, { AxiosInstance } from 'axios'; import uniqBy from 'lodash.uniqby'; +import { TWENTY_COMPANIES_BASE_URL } from 'twenty-shared'; import { DeepPartial, EntityManager, ILike } from 'typeorm'; import { FieldActorSource } from 'src/engine/metadata-modules/field-metadata/composite-types/actor.composite-type'; @@ -25,7 +26,7 @@ export class CreateCompanyService { constructor(private readonly twentyORMGlobalManager: TwentyORMGlobalManager) { this.httpService = axios.create({ - baseURL: 'https://twenty-companies.com', + baseURL: TWENTY_COMPANIES_BASE_URL, }); } diff --git a/packages/twenty-server/tsconfig.json b/packages/twenty-server/tsconfig.json index 272cbdde673c..fe1ccbd7a8f5 100644 --- a/packages/twenty-server/tsconfig.json +++ b/packages/twenty-server/tsconfig.json @@ -27,7 +27,8 @@ "paths": { "src/*": ["packages/twenty-server/src/*"], "test/*": ["packages/twenty-server/test/*"], - "twenty-emails": ["packages/twenty-emails/dist"] + "twenty-emails": ["packages/twenty-emails/dist"], + "twenty-shared": ["packages/twenty-shared/dist"] } }, "ts-node": { diff --git a/packages/twenty-shared/package.json b/packages/twenty-shared/package.json index 8f6d615d972d..ae07a273a0f1 100644 --- a/packages/twenty-shared/package.json +++ b/packages/twenty-shared/package.json @@ -1,5 +1,5 @@ { - "name": "twenty-shared", + "name": "@twenty/twenty-shared", "version": "0.40.0-canary", "license": "AGPL-3.0", "main": "./dist/index.js", diff --git a/packages/twenty-shared/src/constants/TwentyCompaniesBaseUrl.ts b/packages/twenty-shared/src/constants/TwentyCompaniesBaseUrl.ts new file mode 100644 index 000000000000..544ae6e730a0 --- /dev/null +++ b/packages/twenty-shared/src/constants/TwentyCompaniesBaseUrl.ts @@ -0,0 +1 @@ +export const TWENTY_COMPANIES_BASE_URL = 'https://twenty-companies.com'; diff --git a/packages/twenty-shared/src/constants/TwentyIconsBaseUrl.ts b/packages/twenty-shared/src/constants/TwentyIconsBaseUrl.ts new file mode 100644 index 000000000000..82e460872b52 --- /dev/null +++ b/packages/twenty-shared/src/constants/TwentyIconsBaseUrl.ts @@ -0,0 +1 @@ +export const TWENTY_ICONS_BASE_URL = 'https://twenty-icons.com'; diff --git a/packages/twenty-shared/src/index.ts b/packages/twenty-shared/src/index.ts index 7665115392af..894818340dcc 100644 --- a/packages/twenty-shared/src/index.ts +++ b/packages/twenty-shared/src/index.ts @@ -1 +1,3 @@ +export * from './constants/TwentyCompaniesBaseUrl'; +export * from './constants/TwentyIconsBaseUrl'; export * from './utils/image/getImageAbsoluteURI'; From 192f539434c682f7ec6100c90cb8c1a256e4f62f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Malfait?= Date: Fri, 20 Dec 2024 17:23:41 +0100 Subject: [PATCH 6/7] Didnt mean to change this --- packages/twenty-shared/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/twenty-shared/package.json b/packages/twenty-shared/package.json index ae07a273a0f1..8f6d615d972d 100644 --- a/packages/twenty-shared/package.json +++ b/packages/twenty-shared/package.json @@ -1,5 +1,5 @@ { - "name": "@twenty/twenty-shared", + "name": "twenty-shared", "version": "0.40.0-canary", "license": "AGPL-3.0", "main": "./dist/index.js", From 3c1c7f01d26a74ff12cad6939e18d8699209a495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Malfait?= Date: Fri, 20 Dec 2024 18:15:43 +0100 Subject: [PATCH 7/7] Update package.json --- packages/twenty-server/package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/twenty-server/package.json b/packages/twenty-server/package.json index 1c7529d92e5e..6de9253d6e35 100644 --- a/packages/twenty-server/package.json +++ b/packages/twenty-server/package.json @@ -53,8 +53,7 @@ "tsconfig-paths": "^4.2.0", "typeorm": "patch:typeorm@0.3.20#./patches/typeorm+0.3.20.patch", "unzipper": "^0.12.3", - "zod-to-json-schema": "^3.23.1", - "@twenty/twenty-shared": "0.40.0-canary" + "zod-to-json-schema": "^3.23.1" }, "devDependencies": { "@nestjs/cli": "10.3.0",