The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Always regenerate SDK client on application install and upgrade (#24696)
martmull37d3879c0dfa
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-install/application-install.service.ts b/packages/twenty-server/src/engine/core-modules/application/application-install/application-install.service.tsindex 91d19d6fa6a..7d2698af83a 100644--- a/packages/twenty-server/src/engine/core-modules/application/application-install/application-install.service.ts+++ b/packages/twenty-server/src/engine/core-modules/application/application-install/application-install.service.ts@@ -373,6 +373,7 @@ export class ApplicationInstallService {manifest: resolvedPackage.manifest,applicationRegistrationId: appRegistration.id,application,+ forceSdkClientGeneration: true,});await this.runPostInstallHook({diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/__tests__/application-manifest-apply.service.spec.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/__tests__/application-manifest-apply.service.spec.tsnew file mode 100644index 00000000000..e82ca9d9759--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/__tests__/application-manifest-apply.service.spec.ts@@ -0,0 +1,118 @@+import { Test, type TestingModule } from '@nestjs/testing';++import { type Manifest } from 'twenty-shared/application';++import { ApplicationManifestApplyService } from 'src/engine/core-modules/application/application-manifest/application-manifest-apply.service';+import { ApplicationSyncService } from 'src/engine/core-modules/application/application-manifest/application-sync.service';+import { ApplicationRegistrationService } from 'src/engine/core-modules/application/application-registration/application-registration.service';+import { SdkClientGenerationService } from 'src/engine/core-modules/sdk-client/sdk-client-generation.service';++const WORKSPACE_ID = '20202020-0000-0000-0000-000000000001';+const APPLICATION_ID = '20202020-0000-0000-0000-000000000002';++const application = {+ id: APPLICATION_ID,+ universalIdentifier: 'test-app',+ version: '1.2.3',+};++const manifest = {+ application: { universalIdentifier: 'test-app' },+} as Manifest;++describe('ApplicationManifestApplyService', () => {+ let service: ApplicationManifestApplyService;++ const applicationSyncService = { synchronizeFromManifest: jest.fn() };+ const sdkClientGenerationService = {+ generateSdkClientForApplication: jest.fn(),+ };+ const applicationRegistrationService = {};++ beforeEach(async () => {+ jest.clearAllMocks();+ applicationSyncService.synchronizeFromManifest.mockResolvedValue({+ workspaceMigration: { actions: [] },+ hasSchemaMetadataChanged: false,+ });++ const module: TestingModule = await Test.createTestingModule({+ providers: [+ ApplicationManifestApplyService,+ { provide: ApplicationSyncService, useValue: applicationSyncService },+ {+ provide: SdkClientGenerationService,+ useValue: sdkClientGenerationService,+ },+ {+ provide: ApplicationRegistrationService,+ useValue: applicationRegistrationService,+ },+ ],+ }).compile();++ service = module.get(ApplicationManifestApplyService);+ });++ it('regenerates the SDK client on install/upgrade even without schema changes', async () => {+ await service.applyManifestToWorkspace({+ workspaceId: WORKSPACE_ID,+ manifest,+ application,+ forceSdkClientGeneration: true,+ });++ expect(+ sdkClientGenerationService.generateSdkClientForApplication,+ ).toHaveBeenCalledTimes(1);+ expect(+ sdkClientGenerationService.generateSdkClientForApplication,+ ).toHaveBeenCalledWith({+ workspaceId: WORKSPACE_ID,+ applicationId: APPLICATION_ID,+ applicationUniversalIdentifier: 'test-app',+ trigger: 'manifest-sync',+ });+ });++ it('skips SDK client generation on dev sync when the schema is unchanged', async () => {+ await service.applyManifestToWorkspace({+ workspaceId: WORKSPACE_ID,+ manifest,+ application,+ });++ expect(+ sdkClientGenerationService.generateSdkClientForApplication,+ ).not.toHaveBeenCalled();+ });++ it('regenerates the SDK client on dev sync when the schema changed', async () => {+ applicationSyncService.synchronizeFromManifest.mockResolvedValue({+ workspaceMigration: { actions: [] },+ hasSchemaMetadataChanged: true,+ });++ await service.applyManifestToWorkspace({+ workspaceId: WORKSPACE_ID,+ manifest,+ application,+ });++ expect(+ sdkClientGenerationService.generateSdkClientForApplication,+ ).toHaveBeenCalledTimes(1);+ });++ it('regenerates the SDK client on dev sync first apply even without schema changes', async () => {+ await service.applyManifestToWorkspace({+ workspaceId: WORKSPACE_ID,+ manifest,+ application: { ...application, version: null },+ });++ expect(+ sdkClientGenerationService.generateSdkClientForApplication,+ ).toHaveBeenCalledTimes(1);+ });+});diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/application-manifest-apply.service.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/application-manifest-apply.service.tsindex 0eba646665f..79b12ef4321 100644--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/application-manifest-apply.service.ts+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/application-manifest-apply.service.ts@@ -25,11 +25,19 @@ export class ApplicationManifestApplyService {manifest,applicationRegistrationId,application,+ forceSdkClientGeneration = false,}: {workspaceId: string;manifest: Manifest;applicationRegistrationId?: string;- application: ApplicationEntity;+ application: Pick<+ ApplicationEntity,+ 'id' | 'universalIdentifier' | 'version'+ >;+ // Installs and upgrades force regeneration so function-only upgrades pick+ // up SDK-level changes; dev sync relies on first-apply/schema-change to+ // avoid regenerating on every save.+ forceSdkClientGeneration?: boolean;}): Promise<{workspaceMigration: WorkspaceMigration;hasSchemaMetadataChanged: boolean;@@ -46,7 +54,7 @@ export class ApplicationManifestApplyService {applicationRegistrationId,});- if (isFirstApply || hasSchemaMetadataChanged) {+ if (forceSdkClientGeneration || isFirstApply || hasSchemaMetadataChanged) {await this.sdkClientGenerationService.generateSdkClientForApplication({workspaceId,applicationId: application.id,