The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Choose where app health checks run (#29249)
nitin01c0563d153b
diff --git a/packages/twenty-agent-skills/references/develop-app/logic.md b/packages/twenty-agent-skills/references/develop-app/logic.mdindex 98fc01a4df0..67b66dccfa5 100644--- a/packages/twenty-agent-skills/references/develop-app/logic.md+++ b/packages/twenty-agent-skills/references/develop-app/logic.md@@ -155,9 +155,11 @@ The hook runs before the app's metadata, data, and code are removed, so handlersUse `defineHealthCheck` to report whether the app is actually able to run. It covers what only the app can know: a key that is present but revoked, an account on the wrong plan, a webhook that was never registered. A required variable nobody filled in is already covered by `isRequired` and needs no code.-Health check files live alongside other logic functions (typically `src/logic-functions/health-check.ts`). Only one health check is allowed per app; declaring more than one fails the build.+Health check files live alongside other logic functions (typically `src/logic-functions/health-check.ts`). An app declares one function with `defineHealthCheck`; a second declaration fails the build. Omit `runOnUserPreferences` or set it to `false` for a workspace check. Set it to `true` for a member check on Apps preferences instead; the check then does not run on workspace app settings.-The config takes `universalIdentifier` and `handler`. The handler takes no arguments and runs server-side, so it reads secret variables like any other logic function.+`defineHealthCheck` takes `universalIdentifier` and `handler`. The handler runs server-side, so it reads secret variables like any other logic function. A workspace handler takes no arguments.++A member check reports each member's own setup, such as their own connection. It runs when a member opens the app on their Apps preferences page, as that member, and only that member sees the banner. With `runOnUserPreferences: true`, the handler requires `{ userWorkspaceId: string }` from the authenticated session: `handler: async ({ userWorkspaceId }) => ...`. User-scoped variables hold that member's values. Pass `userWorkspaceId` to `listConnections({ scope: 'USER', userWorkspaceId })` so it returns that member's connections only; a connection whose token refresh fails is left out, so return a `WARNING` ("connect your account") when the list is empty. An action with no `location` lands on the app's General tab of that page. That page is not enabled in every workspace yet, so a member check does not run everywhere. Requires `"engines": { "twenty": ">=2.55.0" }`.The handler returns `ApplicationHealthCheckResult`, a discriminated union:diff --git a/packages/twenty-cli/src/app/manifest/__tests__/manifest-fixtures.spec.ts b/packages/twenty-cli/src/app/manifest/__tests__/manifest-fixtures.spec.tsindex 76c19bc2cbe..4fcd57aa070 100644--- a/packages/twenty-cli/src/app/manifest/__tests__/manifest-fixtures.spec.ts+++ b/packages/twenty-cli/src/app/manifest/__tests__/manifest-fixtures.spec.ts@@ -15,6 +15,7 @@ import { fileURLToPath } from 'node:url';import { stop } from 'esbuild';import { EMPTY_YARN_LOCK_CONTENT } from 'twenty-shared/application';+import { isDefined } from 'twenty-shared/utils';import {afterAll,afterEach,@@ -398,6 +399,73 @@ export default defineWorkflow({}}, 60000);+ it.each([undefined, false, true])(+ 'matches one health check with member opt-in %s and rejects a second declaration',+ async (runOnUserPreferences) => {+ const appPath = await copyFixture('minimal-app');+ const writeHealthCheck = ({+ fileName,+ universalIdentifier,+ runOnUserPreferences,+ }: {+ fileName: string;+ universalIdentifier: string;+ runOnUserPreferences?: boolean;+ }) =>+ writeFile(+ join(appPath, fileName),+ `import { defineHealthCheck } from 'twenty-sdk/define';++export default defineHealthCheck({+ universalIdentifier: '${universalIdentifier}',+ name: '${fileName}',+ ${isDefined(runOnUserPreferences) ? `runOnUserPreferences: ${runOnUserPreferences},` : ''}+ handler: () => ({ status: 'OK' }),+});+`,+ );++ await writeHealthCheck({+ fileName: 'health-check.ts',+ universalIdentifier: 'e1e2e3e4-e5e6-4000-8000-000000000070',+ runOnUserPreferences,+ });+ const result = await compareManifest(appPath);++ expect(result.success).toBe(true);+ if (result.success) {+ const healthCheckLogicFunction = result.manifest.logicFunctions.find(+ ({ universalIdentifier }) =>+ universalIdentifier === 'e1e2e3e4-e5e6-4000-8000-000000000070',+ );++ expect(healthCheckLogicFunction).toBeDefined();+ expect(healthCheckLogicFunction).not.toHaveProperty(+ 'runOnUserPreferences',+ );+ expect(result.manifest.application.healthCheckLogicFunction).toEqual({+ universalIdentifier: 'e1e2e3e4-e5e6-4000-8000-000000000070',+ ...(isDefined(runOnUserPreferences) ? { runOnUserPreferences } : {}),+ });+ }++ await writeHealthCheck({+ fileName: 'second-health-check.ts',+ universalIdentifier: 'e1e2e3e4-e5e6-4000-8000-000000000071',+ runOnUserPreferences: true,+ });+ const duplicateResult = await compareManifest(appPath);++ expect(duplicateResult.success).toBe(false);+ if (!duplicateResult.success) {+ expect(duplicateResult.errors).toContain(+ 'Only one health check is allowed per application',+ );+ }+ },+ 60000,+ );+it('keeps evaluated source output and workspace credentials outside the manifest result', async () => {const appPath = await copyFixture('minimal-app');const applicationFiles = (await buildManifest(appPath)).filePathsdiff --git a/packages/twenty-cli/src/app/manifest/manifest-build.ts b/packages/twenty-cli/src/app/manifest/manifest-build.tsindex c7dad039efe..c2a0a7fb193 100644--- a/packages/twenty-cli/src/app/manifest/manifest-build.ts+++ b/packages/twenty-cli/src/app/manifest/manifest-build.ts@@ -331,7 +331,13 @@ export const buildManifest = async (break;}case 'logicFunctions': {- const extract = await extractManifestFromFile<LogicFunctionConfig>({+ const extract = await extractManifestFromFile<+ LogicFunctionConfig &+ Pick<+ HealthCheckLogicFunctionApplicationManifest,+ 'runOnUserPreferences'+ >+ >({appPath,filePath,});@@ -348,8 +354,9 @@ export const buildManifest = async ();}+ const { runOnUserPreferences, ...logicFunctionConfig } = extract.config;const config = await fromLogicFunctionConfigToLogicFunctionManifest({- logicFunctionConfig: extract.config,+ logicFunctionConfig,sourceCode: fileContent,sourcePath: relativePath,});@@ -390,6 +397,9 @@ export const buildManifest = async (if (targetFunctionName === 'defineHealthCheck') {healthCheckLogicFunctions.push({universalIdentifier: extract.config.universalIdentifier,+ ...(isDefined(runOnUserPreferences)+ ? { runOnUserPreferences }+ : {}),});}@@ -633,6 +643,8 @@ export const buildManifest = async (errors.push('Only one health check is allowed per application');}+ const [healthCheckLogicFunction] = healthCheckLogicFunctions;+if (settingsFrontComponentUniversalIdentifiers.length > 1) {errors.push('Only one settings front component is allowed per application');}@@ -710,8 +722,8 @@ export const buildManifest = async (...(uninstallLogicFunctions.length >= 1? { uninstallLogicFunction: uninstallLogicFunctions[0] }: {}),- ...(healthCheckLogicFunctions.length >= 1- ? { healthCheckLogicFunction: healthCheckLogicFunctions[0] }+ ...(isDefined(healthCheckLogicFunction)+ ? { healthCheckLogicFunction }: {}),...(settingsFrontComponentUniversalIdentifiers.length >= 1? {diff --git a/packages/twenty-docs/developers/extend/apps/config/application.mdx b/packages/twenty-docs/developers/extend/apps/config/application.mdxindex d39d8b49b7c..51c9a3618cc 100644--- a/packages/twenty-docs/developers/extend/apps/config/application.mdx+++ b/packages/twenty-docs/developers/extend/apps/config/application.mdx@@ -48,10 +48,10 @@ Notes:- `applicationVariables` become environment variables for your functions and front components. In logic functions (server-side), they are available as `process.env.VARIABLE_NAME`. In front components, use `getApplicationVariable('VARIABLE_NAME')` from `twenty-sdk/front-component`. Variables marked with `isSecret: true` are only injected into logic functions. Front components receive only non-secret variables. A variable with `scope: 'USER'` holds the value of the member the code runs for: see [Workspace and user variables](#workspace-and-user-variables).- Your app can also read and update its own variable values at runtime, which is how a custom settings component saves what the user typed: see [Reading and updating variables at runtime](/developers/extend/apps/layout/front-components#reading-and-updating-variables-at-runtime). An application only ever reaches its own variables, in its own workspace.- The default role is detected automatically from the role file marked with [`defineApplicationRole()`](/developers/extend/apps/config/roles) — you do not need to reference it from `defineApplication()`.-- Pre-install, post-install, and uninstall functions, and the health check, are detected automatically during the manifest build — you do not need to reference them in `defineApplication()`.+- Pre-install, post-install, and uninstall functions, and health checks, are detected automatically during the manifest build — you do not need to reference them in `defineApplication()`.- Passing `defaultRoleUniversalIdentifier` explicitly is still supported for backward compatibility, but is deprecated in favor of `defineApplicationRole()`.- `serverVariables` are instance-scoped configuration and secrets (e.g. API keys). Unlike `applicationVariables`, they declare no value in the manifest — the workspace operator fills them in from the app's settings, and they are injected into logic functions only once set.-- An app can report its own configuration state with [`defineHealthCheck()`](/developers/extend/apps/logic/logic-functions#health-check), for what only the app can know — a key that is present but revoked, a third-party account on the wrong plan. `isRequired` covers what Twenty can see by itself; the health check covers the rest.+- An app can report its own configuration state with [`defineHealthCheck()`](/developers/extend/apps/logic/logic-functions#health-check), for what only the app can know — a key that is present but revoked, a third-party account on the wrong plan. `isRequired` covers what Twenty can see by itself; the health check covers the rest. Set `runOnUserPreferences: true` to check each member's own setup on their Apps preferences page instead of workspace app settings. Omitting the option or setting it to `false` keeps the existing workspace check.- Both kinds of variable accept `isRequired: true`. A required variable the workspace has not filled in yet leaves the app unconfigured: its settings page shows a banner naming the missing variables, with a button that jumps to the tab where they are set. Mark as required only what the app genuinely cannot run without — an optional variable with a sensible default should stay optional.- Both kinds of variable accept `isDeprecated: true`. Use it to retire a variable instead of deleting it: keeping the key declared preserves the stored value (deleting it destroys the value the operator entered), and the variable is still injected, so your code can fall back to it — `process.env.NEW_API_KEY ?? process.env.API_KEY`. A deprecated variable disappears from the app's settings once it has no value, and never counts toward the app's configuration check, so `isDeprecated` beats `isRequired`.- Twenty sets these names for every logic function run, so they are reserved: `TWENTY_API_URL`, `TWENTY_APP_ACCESS_TOKEN`, `TWENTY_APP_APPLICATION_ACCESS_TOKEN`, `TWENTY_API_KEY`, `TWENTY_FUNCTIONS_URL`, `TWENTY_SERVER_ROUTES_URL` and `APPLICATION_ID`. Every other name starting with `TWENTY_` is reserved too, for variables Twenty adds later. A manifest that declares a reserved name as an application or server variable is rejected when the app is synced or published.diff --git a/packages/twenty-docs/developers/extend/apps/logic/logic-functions.mdx b/packages/twenty-docs/developers/extend/apps/logic/logic-functions.mdxindex 99ed33c8556..5ae2d2de7ed 100644--- a/packages/twenty-docs/developers/extend/apps/logic/logic-functions.mdx+++ b/packages/twenty-docs/developers/extend/apps/logic/logic-functions.mdx@@ -550,7 +550,7 @@ Without `batchMode`, the handler keeps receiving one `DatabaseEventPayload` per#### Execution context-Every handler receives a second argument describing the run itself, whatever triggered it. Where the first argument changes shape per trigger, this one does not:+Generic logic function handlers receive a second argument describing the run itself, whatever triggered it. Where the first argument changes shape per trigger, this one does not:```tsimport type { LogicFunctionExecutionContext } from 'twenty-sdk/logic-function';@@ -895,7 +895,7 @@ const handler = async (params: { parentMessageId?: string }) => {Declare a health check with `defineHealthCheck` to report whether your app is actually able to run. It is for what only the app can know: a key that is present but revoked, an account on the wrong plan, a webhook that was never registered. What Twenty can see by itself — a required variable nobody filled in — is covered by [`isRequired`](/developers/extend/apps/config/application) and needs no code.-It runs server-side, so it reads secret variables like any other logic function. The handler takes no arguments.+It runs server-side, so it reads secret variables like any other logic function. A workspace check has nobody behind it, so the handler needs no arguments.```ts src/logic-functions/health-check.tsimport { defineHealthCheck } from 'twenty-sdk/define';@@ -948,7 +948,42 @@ A check that throws, times out or returns a shape Twenty cannot read is treatedThe location has to stay inside Twenty, so it starts with `/` or `#`: an external, protocol-relative or relative one loses its button rather than becoming a redirect somewhere else. The button is also dropped when the app reports no location and has no configuration tab to fall back to, so a check on an app with no variables and no settings menu items shows its title without a dead button.-Only one health check is allowed per app; declaring more than one fails the build.+### Checking each member's own setup++An app declares one health-check function. Omit `runOnUserPreferences` or set it to `false` to run a workspace check on the app's settings page, with a zero-argument handler. Set `runOnUserPreferences: true` to run a member check on their Apps preferences page instead. A member handler receives the required `{ userWorkspaceId: string }` from the authenticated session:++```ts src/logic-functions/health-check.ts+import { defineHealthCheck } from 'twenty-sdk/define';+import { listConnections } from 'twenty-sdk/logic-function';+import { isDefined } from 'twenty-sdk/utils';++export default defineHealthCheck({+ universalIdentifier: 'f3b6a4d2-9c81-4e0a-b5c7-2d1e8f4a6b03',+ name: 'health-check',+ runOnUserPreferences: true,+ handler: async ({ userWorkspaceId }) => {+ const [myConnection] = await listConnections({+ scope: 'USER',+ userWorkspaceId,+ });++ if (!isDefined(myConnection) || isDefined(myConnection.authFailedAt)) {+ return { status: 'WARNING', title: 'Connect your account' };+ }++ return { status: 'OK' };+ },+});+```++A member check runs when a member opens the app on their **Apps preferences** page, and only that member sees its banner. It runs as that member: the handler receives `{ userWorkspaceId }` from the authenticated session, and user-scoped variables hold their values. The parameter object and ID are required for this mode. It does not run on workspace app settings. Pass `userWorkspaceId` to `listConnections()` so it returns that member's connections only. A connection whose token refresh fails is left out of the list, so "no connection" covers "reconnect" too. A button with no `location` lands on the app's General tab of that page.++<Note>+ Member checks require Twenty 2.55.0 or later. **Apps preferences** is not enabled+ in every workspace yet: where it is not, a member check never runs.+</Note>++An app can declare only one health-check function, in either workspace or member mode. Existing declarations keep their zero-argument workspace handler. Declaring a second function fails the build.## Create a timeline activitydiff --git a/packages/twenty-docs/developers/extend/apps/logic/overview.mdx b/packages/twenty-docs/developers/extend/apps/logic/overview.mdxindex 3985746bcb7..a63b36a5592 100644--- a/packages/twenty-docs/developers/extend/apps/logic/overview.mdx+++ b/packages/twenty-docs/developers/extend/apps/logic/overview.mdx@@ -84,7 +84,7 @@ Functions run sandboxed in isolated Node.js processes and access the workspace t<Note>**Install-time hooks** — code that runs before or after the install — share this runtime but use their own define functions and live under [Config → Install Hooks](/developers/extend/apps/config/install-hooks).-The [**health check**](/developers/extend/apps/logic/logic-functions#health-check) shares it too. It declares no trigger: Twenty calls it on demand when the app's settings page opens.+The [**health check**](/developers/extend/apps/logic/logic-functions#health-check) shares it too. An app declares one check with no trigger. By default, Twenty calls its zero-argument handler when workspace app settings open. Set `runOnUserPreferences: true` to run it on a member's Apps preferences page instead, with their required `userWorkspaceId`.</Note><PageBanner illustration="section-apps-logic" />diff --git a/packages/twenty-sdk/src/sdk/define/index.ts b/packages/twenty-sdk/src/sdk/define/index.tsindex b217a2e3d3d..9f819fe821f 100644--- a/packages/twenty-sdk/src/sdk/define/index.ts+++ b/packages/twenty-sdk/src/sdk/define/index.ts@@ -112,7 +112,10 @@ export type {UninstallHandler,UninstallPayload,} from '@/sdk/define/logic-functions/uninstall-payload-type';-export type { HealthCheckHandler } from '@/sdk/define/logic-functions/health-check-handler-type';+export type {+ HealthCheckHandler,+ UserHealthCheckHandler,+} from '@/sdk/define/logic-functions/health-check-handler-type';export type { HealthCheckLogicFunctionConfig } from '@/sdk/define/common/types/loose-shared-types.type';export type {ApplicationHealthCheckAction,diff --git a/packages/twenty-sdk/src/sdk/define/logic-functions/__tests__/define-health-check.spec.ts b/packages/twenty-sdk/src/sdk/define/logic-functions/__tests__/define-health-check.spec.tsindex f3caf048bbf..b55a69a176a 100644--- a/packages/twenty-sdk/src/sdk/define/logic-functions/__tests__/define-health-check.spec.ts+++ b/packages/twenty-sdk/src/sdk/define/logic-functions/__tests__/define-health-check.spec.ts@@ -1,50 +1,192 @@-import { defineHealthCheck } from '@/sdk/define';+import { describe, expect, expectTypeOf, it } from 'vitest';++import {+ defineHealthCheck,+ type HealthCheckHandler,+ type HealthCheckLogicFunctionConfig,+} from '@/sdk/define';describe('defineHealthCheck', () => {- const validConfig = {+ const VALID_CONFIG = {universalIdentifier: '7f1c2d3e-4a5b-4c6d-8e9f-0a1b2c3d4e5f',name: 'health-check',handler: async () => ({ status: 'OK' as const }),};- it('should return successful validation result when valid', () => {- const result = defineHealthCheck(validConfig);+ it('preserves the original zero-argument workspace handler when omitted', async () => {+ const result = defineHealthCheck(VALID_CONFIG);expect(result.success).toBe(true);- expect(result.config).toEqual(validConfig);+ expect(result.config).toEqual(VALID_CONFIG);expect(result.errors).toEqual([]);+ expectTypeOf(result.config.handler).toEqualTypeOf<HealthCheckHandler>();+ expectTypeOf(result.config.handler).parameters.toEqualTypeOf<[]>();+ await expect(result.config.handler()).resolves.toEqual({ status: 'OK' });+ });++ it('preserves the original zero-argument workspace handler when false', async () => {+ const result = defineHealthCheck({+ ...VALID_CONFIG,+ runOnUserPreferences: false,+ });++ expect(result.success).toBe(true);+ expect(result.config.runOnUserPreferences).toBe(false);+ expectTypeOf(result.config.handler).toEqualTypeOf<HealthCheckHandler>();+ expectTypeOf(result.config.handler).parameters.toEqualTypeOf<[]>();+ await expect(result.config.handler()).resolves.toEqual({ status: 'OK' });});- it('should return error when universalIdentifier is missing', () => {+ it('requires the member object and infers a non-null identity when true', async () => {const result = defineHealthCheck({+ ...VALID_CONFIG,+ runOnUserPreferences: true,+ handler: async ({ userWorkspaceId }) => {+ expectTypeOf(userWorkspaceId).toEqualTypeOf<string>();++ return { status: 'INFO', title: userWorkspaceId };+ },+ });++ expect(result.success).toBe(true);+ expect(result.config.runOnUserPreferences).toBe(true);+ expectTypeOf(result.config.handler).parameters.toEqualTypeOf<+ [parameters: { userWorkspaceId: string }]+ >();+ await expect(+ result.config.handler({ userWorkspaceId: 'first-member' }),+ ).resolves.toEqual({ status: 'INFO', title: 'first-member' });+ await expect(+ result.config.handler({ userWorkspaceId: 'second-member' }),+ ).resolves.toEqual({ status: 'INFO', title: 'second-member' });+ });++ it('keeps the member parameter required when the authored handler ignores it', async () => {+ const result = defineHealthCheck({+ ...VALID_CONFIG,+ runOnUserPreferences: true,+ });++ expectTypeOf(result.config.handler).parameters.toEqualTypeOf<+ [parameters: { userWorkspaceId: string }]+ >();+ await expect(+ result.config.handler({ userWorkspaceId: 'member-id' }),+ ).resolves.toEqual({ status: 'OK' });+ });++ it.each([false, true])(+ 'accepts a forwarded config union with mode %s',+ async (runOnUserPreferences) => {+ const memberConfig: HealthCheckLogicFunctionConfig = {+ ...VALID_CONFIG,+ runOnUserPreferences: true,+ handler: ({ userWorkspaceId }) => ({+ status: 'INFO',+ title: userWorkspaceId,+ }),+ };+ const config: HealthCheckLogicFunctionConfig = runOnUserPreferences+ ? memberConfig+ : VALID_CONFIG;+ const result = defineHealthCheck(config);++ expect(result.success).toBe(true);+ if (result.config.runOnUserPreferences) {+ expectTypeOf(result.config.handler).parameters.toEqualTypeOf<+ [parameters: { userWorkspaceId: string }]+ >();+ await expect(+ Promise.resolve(+ result.config.handler({ userWorkspaceId: 'member-id' }),+ ),+ ).resolves.toEqual({ status: 'INFO', title: 'member-id' });+ } else {+ expectTypeOf(result.config.handler).parameters.toEqualTypeOf<[]>();+ await expect(result.config.handler()).resolves.toEqual({+ status: 'OK',+ });+ }+ },+ );++ it('rejects incompatible handler declarations at the type level', () => {+ const memberHandler = ({+ userWorkspaceId,+ }: {+ userWorkspaceId: string;+ }) => ({ status: 'INFO' as const, title: userWorkspaceId });++ const missingModeConfig = { ...VALID_CONFIG, handler: memberHandler };+ const workspaceModeConfig = {+ ...VALID_CONFIG,+ runOnUserPreferences: false,+ handler: memberHandler,+ };+ const positionalHandlerConfig = {+ ...VALID_CONFIG,+ runOnUserPreferences: true,+ handler: (userWorkspaceId: string) => ({+ status: 'INFO' as const,+ title: userWorkspaceId,+ }),+ };++ // @ts-expect-error Negative overload regression.+ defineHealthCheck(missingModeConfig);+ // @ts-expect-error Negative overload regression.+ defineHealthCheck(workspaceModeConfig);+ // @ts-expect-error Negative overload regression.+ defineHealthCheck(positionalHandlerConfig);++ expectTypeOf(memberHandler).parameters.toEqualTypeOf<+ [parameters: { userWorkspaceId: string }]+ >();+ });++ it('rejects a non-boolean option from a JavaScript declaration', () => {+ const invalidConfig = { ...VALID_CONFIG, runOnUserPreferences: 'true' };+ // @ts-expect-error Exercise the JavaScript validation boundary.+ const result = defineHealthCheck(invalidConfig);++ expect(result.success).toBe(false);+ expect(result.errors).toEqual([+ 'Health check runOnUserPreferences must be a boolean',+ ]);+ });++ it('rejects a missing universalIdentifier', () => {+ const invalidConfig = {name: 'health-check',- handler: async () => ({ status: 'OK' as const }),- } as any);+ handler: VALID_CONFIG.handler,+ };+ // @ts-expect-error Exercise the JavaScript validation boundary.+ const result = defineHealthCheck(invalidConfig);expect(result.success).toBe(false);- expect(result.errors).toContain(+ expect(result.errors).toEqual(['Health check must have a universalIdentifier',- );+ ]);});- it('should return error when handler is missing', () => {- const result = defineHealthCheck({- universalIdentifier: '7f1c2d3e-4a5b-4c6d-8e9f-0a1b2c3d4e5f',+ it('rejects a missing handler', () => {+ const invalidConfig = {+ universalIdentifier: VALID_CONFIG.universalIdentifier,name: 'health-check',- } as any);+ };+ // @ts-expect-error Exercise the JavaScript validation boundary.+ const result = defineHealthCheck(invalidConfig);expect(result.success).toBe(false);expect(result.errors).toEqual(['Health check must have a handler']);});- it('should return error when handler is not a function', () => {- const result = defineHealthCheck({- universalIdentifier: '7f1c2d3e-4a5b-4c6d-8e9f-0a1b2c3d4e5f',- name: 'health-check',- handler: 'not-a-function',- } as any);+ it('rejects a handler that is not a function', () => {+ const invalidConfig = { ...VALID_CONFIG, handler: 'not-a-function' };+ // @ts-expect-error Exercise the JavaScript validation boundary.+ const result = defineHealthCheck(invalidConfig);expect(result.success).toBe(false);- expect(result.errors).toContain('Health check handler must be a function');+ expect(result.errors).toEqual(['Health check handler must be a function']);});});diff --git a/packages/twenty-sdk/src/sdk/define/logic-functions/define-health-check.ts b/packages/twenty-sdk/src/sdk/define/logic-functions/define-health-check.tsindex 3ef95ef4447..d270d583c5f 100644--- a/packages/twenty-sdk/src/sdk/define/logic-functions/define-health-check.ts+++ b/packages/twenty-sdk/src/sdk/define/logic-functions/define-health-check.ts@@ -1,24 +1,45 @@-import type { DefineEntity } from '@/sdk/define/common/types/define-entity.type';+import { isBoolean, isNonEmptyString } from '@sniptt/guards';+import { isDefined } from 'twenty-shared/utils';++import type { ValidationResult } from '@/sdk/define/common/types/define-entity.type';+import type { LooseEnumValues } from '@/sdk/define/common/types/loose-enum-values.type';import { createValidationResult } from '@/sdk/define/common/utils/create-validation-result';-import { type HealthCheckLogicFunctionConfig } from '@/sdk/define/logic-functions/health-check-logic-function-config';+import type {+ HealthCheckLogicFunctionConfig,+ UserHealthCheckLogicFunctionConfig,+ WorkspaceHealthCheckLogicFunctionConfig,+} from '@/sdk/define/logic-functions/health-check-logic-function-config';-export const defineHealthCheck: DefineEntity<HealthCheckLogicFunctionConfig> = (- config,-) => {+export function defineHealthCheck(+ config: LooseEnumValues<UserHealthCheckLogicFunctionConfig>,+): ValidationResult<LooseEnumValues<UserHealthCheckLogicFunctionConfig>>;+export function defineHealthCheck(+ config: LooseEnumValues<WorkspaceHealthCheckLogicFunctionConfig>,+): ValidationResult<LooseEnumValues<WorkspaceHealthCheckLogicFunctionConfig>>;+export function defineHealthCheck(+ config: LooseEnumValues<HealthCheckLogicFunctionConfig>,+): ValidationResult<LooseEnumValues<HealthCheckLogicFunctionConfig>>;+export function defineHealthCheck(+ config: LooseEnumValues<HealthCheckLogicFunctionConfig>,+) {const errors = [];- if (!config.universalIdentifier) {+ if (!isNonEmptyString(config.universalIdentifier)) {errors.push('Health check must have a universalIdentifier');}- if (!config.handler) {+ if (!isDefined(config.handler)) {errors.push('Health check must have a handler');} else if (typeof config.handler !== 'function') {errors.push('Health check handler must be a function');}- return createValidationResult({- config,- errors,- });-};+ if (+ isDefined(config.runOnUserPreferences) &&+ !isBoolean(config.runOnUserPreferences)+ ) {+ errors.push('Health check runOnUserPreferences must be a boolean');+ }++ return createValidationResult({ config, errors });+}diff --git a/packages/twenty-sdk/src/sdk/define/logic-functions/health-check-handler-type.ts b/packages/twenty-sdk/src/sdk/define/logic-functions/health-check-handler-type.tsindex 878efbe09e4..efbe870bafd 100644--- a/packages/twenty-sdk/src/sdk/define/logic-functions/health-check-handler-type.ts+++ b/packages/twenty-sdk/src/sdk/define/logic-functions/health-check-handler-type.ts@@ -3,3 +3,7 @@ import type { ApplicationHealthCheckResult } from 'twenty-shared/application';export type HealthCheckHandler = () =>| ApplicationHealthCheckResult| Promise<ApplicationHealthCheckResult>;++export type UserHealthCheckHandler = (parameters: {+ userWorkspaceId: string;+}) => ReturnType<HealthCheckHandler>;diff --git a/packages/twenty-sdk/src/sdk/define/logic-functions/health-check-logic-function-config.ts b/packages/twenty-sdk/src/sdk/define/logic-functions/health-check-logic-function-config.tsindex 5da3a29ad01..d63cdefc62f 100644--- a/packages/twenty-sdk/src/sdk/define/logic-functions/health-check-logic-function-config.ts+++ b/packages/twenty-sdk/src/sdk/define/logic-functions/health-check-logic-function-config.ts@@ -1,7 +1,10 @@-import type { HealthCheckHandler } from '@/sdk/define/logic-functions/health-check-handler-type';+import type {+ HealthCheckHandler,+ UserHealthCheckHandler,+} from '@/sdk/define/logic-functions/health-check-handler-type';import type { LogicFunctionConfig } from '@/sdk/define/logic-functions/logic-function-config';-export type HealthCheckLogicFunctionConfig = Omit<+type HealthCheckLogicFunctionConfigBase = Omit<LogicFunctionConfig,| 'cronTriggerSettings'| 'databaseEventTriggerSettings'@@ -10,6 +13,20 @@ export type HealthCheckLogicFunctionConfig = Omit<| 'workflowActionTriggerSettings'| 'serverRouteTriggerSettings'| 'handler'-> & {- handler: HealthCheckHandler;-};+>;++export type WorkspaceHealthCheckLogicFunctionConfig =+ HealthCheckLogicFunctionConfigBase & {+ runOnUserPreferences?: false;+ handler: HealthCheckHandler;+ };++export type UserHealthCheckLogicFunctionConfig =+ HealthCheckLogicFunctionConfigBase & {+ runOnUserPreferences: true;+ handler: UserHealthCheckHandler;+ };++export type HealthCheckLogicFunctionConfig =+ | WorkspaceHealthCheckLogicFunctionConfig+ | UserHealthCheckLogicFunctionConfig;diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-55/2-55-instance-command-fast-1793473469981-enable-user-health-check.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-55/2-55-instance-command-fast-1793473469981-enable-user-health-check.tsnew file mode 100644index 00000000000..a4a907a5d9f--- /dev/null+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-55/2-55-instance-command-fast-1793473469981-enable-user-health-check.ts@@ -0,0 +1,21 @@+import { QueryRunner } from 'typeorm';++import { RegisteredInstanceCommand } from 'src/engine/core-modules/upgrade/decorators/registered-instance-command.decorator';+import { FastInstanceCommand } from 'src/engine/core-modules/upgrade/interfaces/fast-instance-command.interface';++@RegisteredInstanceCommand('2.55.0', 1793473469981)+export class EnableUserHealthCheckFastInstanceCommand+ implements FastInstanceCommand+{+ public async up(queryRunner: QueryRunner): Promise<void> {+ await queryRunner.query(+ 'ALTER TABLE "core"."application" ADD "isUserHealthCheckEnabled" boolean NOT NULL DEFAULT false',+ );+ }++ public async down(queryRunner: QueryRunner): Promise<void> {+ await queryRunner.query(+ 'ALTER TABLE "core"."application" DROP COLUMN "isUserHealthCheckEnabled"',+ );+ }+}diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-55/enable-user-health-check-upgrade-command-name.constant.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-55/enable-user-health-check-upgrade-command-name.constant.tsnew file mode 100644index 00000000000..fe0528d12ad--- /dev/null+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-55/enable-user-health-check-upgrade-command-name.constant.ts@@ -0,0 +1,2 @@+export const ENABLE_USER_HEALTH_CHECK_UPGRADE_COMMAND_NAME =+ '2.55.0_EnableUserHealthCheckFastInstanceCommand_1793473469981';diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/instance-commands.constant.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/instance-commands.constant.tsindex b35be06fd24..7e21c8a07f5 100644--- a/packages/twenty-server/src/database/commands/upgrade-version-command/instance-commands.constant.ts+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/instance-commands.constant.ts@@ -277,6 +277,7 @@ import { RenameWorkspaceAllowedIframeOriginsToAllowedEmbeddingOriginsFastInstancimport { AddRelatedRecordPathIsInherentFastInstanceCommand } from 'src/database/commands/upgrade-version-command/2-55/2-55-instance-command-fast-1793375358574-add-related-record-path-is-inherent';import { AddRelationFieldMetadataIdToRowLevelPermissionPredicateFastInstanceCommand } from 'src/database/commands/upgrade-version-command/2-55/2-55-instance-command-fast-1793381326752-add-relation-field-metadata-id-to-row-level-permission-predicate';import { IndexTemporaryFileExpirationSlowInstanceCommand } from 'src/database/commands/upgrade-version-command/2-55/2-55-instance-command-slow-1793462047826-index-temporary-file-expiration';+import { EnableUserHealthCheckFastInstanceCommand } from 'src/database/commands/upgrade-version-command/2-55/2-55-instance-command-fast-1793473469981-enable-user-health-check';export const INSTANCE_COMMANDS = [AddViewFieldGroupIdIndexOnViewFieldFastInstanceCommand,@@ -556,4 +557,5 @@ export const INSTANCE_COMMANDS = [AddRelatedRecordPathIsInherentFastInstanceCommand,AddRelationFieldMetadataIdToRowLevelPermissionPredicateFastInstanceCommand,IndexTemporaryFileExpirationSlowInstanceCommand,+ EnableUserHealthCheckFastInstanceCommand,];diff --git a/packages/twenty-server/src/engine/core-modules/application/application-health/application-health-check.service.ts b/packages/twenty-server/src/engine/core-modules/application/application-health/application-health-check.service.tsindex 7111eee8fec..f597aa869cd 100644--- a/packages/twenty-server/src/engine/core-modules/application/application-health/application-health-check.service.ts+++ b/packages/twenty-server/src/engine/core-modules/application/application-health/application-health-check.service.ts@@ -37,9 +37,14 @@ export class ApplicationHealthCheckService {workspaceId,});- const { healthCheckLogicFunctionId } = application;+ const { healthCheckLogicFunctionId, isUserHealthCheckEnabled } =+ application;- if (!isDefined(healthCheckLogicFunctionId)) {+ if (+ !isDefined(isUserHealthCheckEnabled) ||+ isUserHealthCheckEnabled ||+ !isDefined(healthCheckLogicFunctionId)+ ) {return null;}diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/application-manifest-migration.service.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/application-manifest-migration.service.tsindex 313d86f303d..9a4b1f76583 100644--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/application-manifest-migration.service.ts+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/application-manifest-migration.service.ts@@ -465,7 +465,12 @@ export class ApplicationManifestMigrationService {: {}),...(isDefined(healthCheckLogicFunctionId) ||inferDeletionFromMissingEntities- ? { healthCheckLogicFunctionId }+ ? {+ healthCheckLogicFunctionId,+ isUserHealthCheckEnabled:+ manifest.application.healthCheckLogicFunction+ ?.runOnUserPreferences ?? false,+ }: {}),...(isDefined(defaultRoleId) ? { defaultRoleId } : {}),});diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/application-sync.service.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/application-sync.service.tsindex 797f1cfbbe0..6af8ef4d84f 100644--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/application-sync.service.ts+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/application-sync.service.ts@@ -195,6 +195,7 @@ export class ApplicationSyncService {settingsCustomTabFrontComponentId: null,uninstallLogicFunctionId: null,healthCheckLogicFunctionId: null,+ isUserHealthCheckEnabled: false,uninstallHookCompletedForRequestedAt: null,canBeUninstalled: true,autoUpgrade: false,diff --git a/packages/twenty-server/src/engine/core-modules/application/application.entity.ts b/packages/twenty-server/src/engine/core-modules/application/application.entity.tsindex e89a43299ea..3fcfc2360ef 100644--- a/packages/twenty-server/src/engine/core-modules/application/application.entity.ts+++ b/packages/twenty-server/src/engine/core-modules/application/application.entity.ts@@ -26,6 +26,7 @@ import { FileEntity } from 'src/engine/core-modules/file/entities/file.entity';import { ApplicationVariableEntity } from 'src/engine/core-modules/application/application-variable/application-variable.entity';import { PublicDomainEntity } from 'src/engine/core-modules/public-domain/public-domain.entity';import { ADD_HEALTH_CHECK_TO_APPLICATION_UPGRADE_COMMAND_NAME } from 'src/database/commands/upgrade-version-command/2-42/add-health-check-to-application-upgrade-command-name.constant';+import { ENABLE_USER_HEALTH_CHECK_UPGRADE_COMMAND_NAME } from 'src/database/commands/upgrade-version-command/2-55/enable-user-health-check-upgrade-command-name.constant';import { WasIntroducedInUpgrade } from 'src/engine/core-modules/upgrade/decorators/was-introduced-in-upgrade.decorator';import { AgentEntity } from 'src/engine/metadata-modules/ai/ai-agent/entities/agent.entity';import { CommandMenuItemEntity } from 'src/engine/metadata-modules/command-menu-item/entities/command-menu-item.entity';@@ -168,6 +169,12 @@ export class ApplicationEntity extends WorkspaceRelatedEntity {})healthCheckLogicFunctionId: string | null;+ @Column({ nullable: false, type: 'boolean', default: false })+ @WasIntroducedInUpgrade({+ upgradeCommandName: ENABLE_USER_HEALTH_CHECK_UPGRADE_COMMAND_NAME,+ })+ isUserHealthCheckEnabled: boolean;+@Column({ nullable: false, type: 'boolean', default: true })canBeUninstalled: boolean;diff --git a/packages/twenty-server/src/engine/metadata-modules/flat-field-metadata/__tests__/morph-relation-from-create-field-input-to-flat-field-metadatas-to-create.spec.ts b/packages/twenty-server/src/engine/metadata-modules/flat-field-metadata/__tests__/morph-relation-from-create-field-input-to-flat-field-metadatas-to-create.spec.tsindex f58589be5ec..10b5cb2cf04 100644--- a/packages/twenty-server/src/engine/metadata-modules/flat-field-metadata/__tests__/morph-relation-from-create-field-input-to-flat-field-metadatas-to-create.spec.ts+++ b/packages/twenty-server/src/engine/metadata-modules/flat-field-metadata/__tests__/morph-relation-from-create-field-input-to-flat-field-metadatas-to-create.spec.ts@@ -45,6 +45,7 @@ const MOCK_FLAT_APPLICATION: FlatApplication = {defaultRole: null,settingsCustomTabFrontComponentId: null,healthCheckLogicFunctionId: null,+ isUserHealthCheckEnabled: false,uninstallLogicFunctionId: null,uninstallHookCompletedForRequestedAt: null,canBeUninstalled: false,diff --git a/packages/twenty-server/src/engine/metadata-modules/flat-field-metadata/utils/__tests__/generate-morph-or-relation-flat-field-metadata-pair.spec.ts b/packages/twenty-server/src/engine/metadata-modules/flat-field-metadata/utils/__tests__/generate-morph-or-relation-flat-field-metadata-pair.spec.tsindex 156b56c2777..6a9eb662c7b 100644--- a/packages/twenty-server/src/engine/metadata-modules/flat-field-metadata/utils/__tests__/generate-morph-or-relation-flat-field-metadata-pair.spec.ts+++ b/packages/twenty-server/src/engine/metadata-modules/flat-field-metadata/utils/__tests__/generate-morph-or-relation-flat-field-metadata-pair.spec.ts@@ -40,6 +40,7 @@ const MOCK_FLAT_APPLICATION: FlatApplication = {defaultRole: null,settingsCustomTabFrontComponentId: null,healthCheckLogicFunctionId: null,+ isUserHealthCheckEnabled: false,uninstallLogicFunctionId: null,uninstallHookCompletedForRequestedAt: null,canBeUninstalled: false,diff --git a/packages/twenty-server/test/integration/metadata/suites/application/successful-sync-application-user-health-check.integration-spec.ts b/packages/twenty-server/test/integration/metadata/suites/application/successful-sync-application-user-health-check.integration-spec.tsnew file mode 100644index 00000000000..1b745285eb4--- /dev/null+++ b/packages/twenty-server/test/integration/metadata/suites/application/successful-sync-application-user-health-check.integration-spec.ts@@ -0,0 +1,230 @@+import { createHash } from 'crypto';++import { TEST_APPLICATION_PACKAGE_JSON_CHECKSUM } from 'test/integration/metadata/suites/application/constants/test-application-package-json.constant';+import { buildBaseManifest } from 'test/integration/metadata/suites/application/utils/build-base-manifest.util';+import { cleanupApplicationAndAppRegistration } from 'test/integration/metadata/suites/application/utils/cleanup-application-and-app-registration.util';+import { findOneApplication } from 'test/integration/metadata/suites/application/utils/find-one-application.util';+import { runApplicationHealthCheck } from 'test/integration/metadata/suites/application/utils/run-application-health-check.util';+import { setupApplicationForSync } from 'test/integration/metadata/suites/application/utils/setup-application-for-sync.util';+import { syncApplication } from 'test/integration/metadata/suites/application/utils/sync-application.util';+import { uploadApplicationFile } from 'test/integration/metadata/suites/application/utils/upload-application-file.util';+import {+ type HealthCheckLogicFunctionApplicationManifest,+ type Manifest,+} from 'twenty-shared/application';+import { isDefined } from 'twenty-shared/utils';+import { v4 as uuidv4 } from 'uuid';++const APPLICATION_UNIVERSAL_IDENTIFIER = uuidv4();+const ROLE_UNIVERSAL_IDENTIFIER = uuidv4();+const APPLICATION_NAME = 'Application syncing member health check opt-in';+const HEALTH_CHECK_SOURCE = `export const handler = () => ({ status: 'OK' });`;+const HEALTH_CHECK_NAME = 'health-check';+const HEALTH_CHECK_REFERENCE = { universalIdentifier: uuidv4() };++const buildHealthCheckManifest = ({+ healthCheckLogicFunction,+}: {+ healthCheckLogicFunction?: HealthCheckLogicFunctionApplicationManifest;+}): Manifest =>+ buildBaseManifest({+ appId: APPLICATION_UNIVERSAL_IDENTIFIER,+ roleId: ROLE_UNIVERSAL_IDENTIFIER,+ overrides: {+ application: {+ universalIdentifier: APPLICATION_UNIVERSAL_IDENTIFIER,+ defaultRoleUniversalIdentifier: ROLE_UNIVERSAL_IDENTIFIER,+ displayName: APPLICATION_NAME,+ description: 'App for testing member health check opt-in',+ applicationVariables: {},+ ...(isDefined(healthCheckLogicFunction)+ ? { healthCheckLogicFunction }+ : {}),+ packageJsonChecksum: TEST_APPLICATION_PACKAGE_JSON_CHECKSUM,+ yarnLockChecksum: null,+ },+ logicFunctions: [+ {+ ...HEALTH_CHECK_REFERENCE,+ name: HEALTH_CHECK_NAME,+ handlerName: 'handler',+ sourceHandlerPath: `src/${HEALTH_CHECK_NAME}.ts`,+ builtHandlerPath: `dist/${HEALTH_CHECK_NAME}.mjs`,+ builtHandlerChecksum: createHash('sha256')+ .update(HEALTH_CHECK_SOURCE)+ .digest('hex'),+ timeoutSeconds: 10,+ },+ ],+ },+ });++const findStoredHealthCheck = async (+ applicationId: string,+): Promise<{+ healthCheckUniversalIdentifier: string | null;+ isUserHealthCheckEnabled: boolean;+}> => {+ const [storedApplication] = await globalThis.testDataSource.query(+ `SELECT+ "healthCheckLogicFunction"."universalIdentifier" AS "healthCheckUniversalIdentifier",+ "application"."isUserHealthCheckEnabled"+ FROM core."application" "application"+ LEFT JOIN core."logicFunction" "healthCheckLogicFunction"+ ON "healthCheckLogicFunction".id = "application"."healthCheckLogicFunctionId"+ WHERE "application".id = $1`,+ [applicationId],+ );++ return storedApplication;+};++describe('Sync application member health check opt-in should succeed', () => {+ let applicationId: string;++ beforeAll(async () => {+ await setupApplicationForSync({+ applicationUniversalIdentifier: APPLICATION_UNIVERSAL_IDENTIFIER,+ name: APPLICATION_NAME,+ description: 'App for testing member health check opt-in',+ sourcePath: `test-${APPLICATION_UNIVERSAL_IDENTIFIER}`,+ });+ jest.useRealTimers();++ await uploadApplicationFile({+ applicationUniversalIdentifier: APPLICATION_UNIVERSAL_IDENTIFIER,+ fileFolder: 'BuiltLogicFunction',+ filePath: `dist/${HEALTH_CHECK_NAME}.mjs`,+ filename: `${HEALTH_CHECK_NAME}.mjs`,+ contentType: 'application/javascript',+ fileBuffer: Buffer.from(HEALTH_CHECK_SOURCE),+ expectToFail: false,+ });++ await syncApplication({+ manifest: buildHealthCheckManifest({+ healthCheckLogicFunction: {+ ...HEALTH_CHECK_REFERENCE,+ runOnUserPreferences: true,+ },+ }),+ expectToFail: false,+ });+ jest.useRealTimers();++ const { data } = await findOneApplication({+ input: { universalIdentifier: APPLICATION_UNIVERSAL_IDENTIFIER },+ gqlFields: 'id',+ expectToFail: false,+ });++ applicationId = data.findOneApplication.id;+ }, 120000);++ afterAll(async () => {+ await cleanupApplicationAndAppRegistration({+ applicationUniversalIdentifier: APPLICATION_UNIVERSAL_IDENTIFIER,+ });+ });++ it('stores one health check with member execution enabled', async () => {+ expect(await findStoredHealthCheck(applicationId)).toEqual({+ healthCheckUniversalIdentifier:+ HEALTH_CHECK_REFERENCE.universalIdentifier,+ isUserHealthCheckEnabled: true,+ });++ const { data } = await runApplicationHealthCheck({+ input: { applicationId },+ expectToFail: false,+ });++ expect(data.runApplicationHealthCheck).toBeNull();+ });++ it('preserves the check and member opt-in when omitted from a delta sync', async () => {+ await syncApplication({+ manifest: buildHealthCheckManifest({}),+ inferDeletionFromMissingEntities: false,+ expectToFail: false,+ });+ jest.useRealTimers();++ expect(await findStoredHealthCheck(applicationId)).toEqual({+ healthCheckUniversalIdentifier:+ HEALTH_CHECK_REFERENCE.universalIdentifier,+ isUserHealthCheckEnabled: true,+ });+ });++ it('defaults a declared check without member opt-in to workspace-only', async () => {+ await syncApplication({+ manifest: buildHealthCheckManifest({+ healthCheckLogicFunction: HEALTH_CHECK_REFERENCE,+ }),+ inferDeletionFromMissingEntities: false,+ expectToFail: false,+ });+ jest.useRealTimers();++ expect(await findStoredHealthCheck(applicationId)).toEqual({+ healthCheckUniversalIdentifier:+ HEALTH_CHECK_REFERENCE.universalIdentifier,+ isUserHealthCheckEnabled: false,+ });++ const { data } = await runApplicationHealthCheck({+ input: { applicationId },+ expectToFail: false,+ });++ expect(data.runApplicationHealthCheck).toEqual({+ status: 'OK',+ title: null,+ });+ });++ it.each([true, false])(+ 'updates member execution to %s without replacing the health check',+ async (runOnUserPreferences) => {+ await syncApplication({+ manifest: buildHealthCheckManifest({+ healthCheckLogicFunction: {+ ...HEALTH_CHECK_REFERENCE,+ runOnUserPreferences,+ },+ }),+ expectToFail: false,+ });+ jest.useRealTimers();++ expect(await findStoredHealthCheck(applicationId)).toEqual({+ healthCheckUniversalIdentifier:+ HEALTH_CHECK_REFERENCE.universalIdentifier,+ isUserHealthCheckEnabled: runOnUserPreferences,+ });+ },+ );++ it('clears the check and member opt-in when omitted from a full sync', async () => {+ await syncApplication({+ manifest: buildHealthCheckManifest({+ healthCheckLogicFunction: {+ ...HEALTH_CHECK_REFERENCE,+ runOnUserPreferences: true,+ },+ }),+ expectToFail: false,+ });+ await syncApplication({+ manifest: buildHealthCheckManifest({}),+ expectToFail: false,+ });+ jest.useRealTimers();++ expect(await findStoredHealthCheck(applicationId)).toEqual({+ healthCheckUniversalIdentifier: null,+ isUserHealthCheckEnabled: false,+ });+ });+});diff --git a/packages/twenty-shared/src/application/healthCheckLogicFunctionApplicationType.ts b/packages/twenty-shared/src/application/healthCheckLogicFunctionApplicationType.tsindex 58553cec8d4..3bd3e9e5623 100644--- a/packages/twenty-shared/src/application/healthCheckLogicFunctionApplicationType.ts+++ b/packages/twenty-shared/src/application/healthCheckLogicFunctionApplicationType.ts@@ -1,3 +1,6 @@import type { SyncableEntityOptions } from '@/application/syncableEntityOptionsType';-export type HealthCheckLogicFunctionApplicationManifest = SyncableEntityOptions;+export type HealthCheckLogicFunctionApplicationManifest =+ SyncableEntityOptions & {+ runOnUserPreferences?: boolean;+ };