feat(applications): add type and options to application variables (#22157)

## Before
<img width="1452" height="709" alt="image"
src="https://github.com/user-attachments/assets/cd384ffa-cbe6-49d5-a807-ca8d580f55a9"
/>

<img width="1074" height="452" alt="image"
src="https://github.com/user-attachments/assets/720d38db-3495-4032-8831-17d24ec6a7e7"
/>

## After

<img width="1421" height="865" alt="image"
src="https://github.com/user-attachments/assets/2275c996-c895-4800-8324-2aa2ddfddd43"
/>

<img width="1348" height="870" alt="image"
src="https://github.com/user-attachments/assets/3e1a891d-6db0-4cbd-870a-2a5bbde4929d"
/>


## Summary

Adds typed application variables with optional select **options**. This
is the other half of #22059, split out from the custom-settings-tab
removal.

## Changes

- **Shared types**: `ApplicationVariable` / `ServerVariables` gain an
optional `type` (a `FieldMetadataType` subset — `TEXT`, `BOOLEAN`,
`NUMBER`, `DATE`, `SELECT`, `MULTI_SELECT`, `RAW_JSON`, `RICH_TEXT`,
`ARRAY`, …) and select `options`. New
`serializeApplicationVariableValue` /
`deserializeApplicationVariableValue` helpers convert typed values
to/from the encrypted string storage.
- **Server**: `type`/`options` columns on `applicationVariable` and
`applicationRegistrationVariable` (entities + DTOs), a fast `2-17`
instance command, manifest processing via the serialization helpers, and
a `QueryDeepPartialEntity` cast where the manifest JSON column is
persisted.
- **Frontend**: a polymorphic `SettingsApplicationVariableInput` that
renders the native `Form*` field component for each type (boolean,
number, date/date-time, select, multi-select, array, raw JSON, rich
text, text); fragment/query updates to fetch `type`/`options`.
- **SDK**: `defineApplication` validates that `SELECT`/`MULTI_SELECT`
variables declare non-empty `options` at build time (since `options` is
kept structurally optional for TypeORM/SDK compatibility).

Variables default to `TEXT` when no type is given, so existing manifests
are unaffected.

## Notes

The generated GraphQL artifacts (`type`/`options` on the variable types)
are regenerated by codegen; that change accompanies this PR.

https://claude.ai/code/session_013Z7UB35V2mvUozh55QHG23

---
_Generated by [Claude
Code](https://claude.ai/code/session_013Z7UB35V2mvUozh55QHG23)_

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/twentyhq/twenty/pull/22157?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:
martmull
2026-07-03 10:52:22 +02:00
committed by GitHub
parent 90f35658c5
commit 25fe66565c
42 changed files with 1318 additions and 594 deletions
@@ -0,0 +1,86 @@
import {
type ApplicationVariableType,
type ApplicationVariableValue,
} from '@/application/applicationVariablesType';
import { FieldMetadataType } from '@/types/FieldMetadataType';
export const serializeApplicationVariableValue = (
value: ApplicationVariableValue | undefined,
type: ApplicationVariableType = FieldMetadataType.TEXT,
): string => {
if (value === null || value === undefined) {
return '';
}
switch (type) {
case FieldMetadataType.BOOLEAN:
return String(value) === 'true' ? 'true' : 'false';
case FieldMetadataType.NUMBER:
case FieldMetadataType.NUMERIC:
return String(value);
case FieldMetadataType.ARRAY:
case FieldMetadataType.MULTI_SELECT:
if (Array.isArray(value)) {
return JSON.stringify(value);
}
if (typeof value === 'string') {
try {
const parsed = JSON.parse(value) as unknown;
if (Array.isArray(parsed)) {
return value;
}
} catch {}
return JSON.stringify([value]);
}
return JSON.stringify(value);
case FieldMetadataType.RAW_JSON:
case FieldMetadataType.RICH_TEXT:
return typeof value === 'string' ? value : JSON.stringify(value);
default:
return typeof value === 'string' ? value : String(value);
}
};
export const deserializeApplicationVariableValue = (
value: string,
type: ApplicationVariableType = FieldMetadataType.TEXT,
): ApplicationVariableValue => {
if (value === '') {
return type === FieldMetadataType.ARRAY ||
type === FieldMetadataType.MULTI_SELECT
? []
: '';
}
switch (type) {
case FieldMetadataType.BOOLEAN:
return value === 'true';
case FieldMetadataType.NUMBER:
case FieldMetadataType.NUMERIC: {
const parsed = Number(value);
return Number.isNaN(parsed) ? value : parsed;
}
case FieldMetadataType.ARRAY:
case FieldMetadataType.MULTI_SELECT:
try {
const parsed = JSON.parse(value) as unknown;
return Array.isArray(parsed) ? (parsed as string[]) : [];
} catch {
return [];
}
case FieldMetadataType.RAW_JSON:
case FieldMetadataType.RICH_TEXT:
try {
return JSON.parse(value) as Record<string, unknown>;
} catch {
return value;
}
default:
return value;
}
};