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:
+12
@@ -1,3 +1,9 @@
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
import {
|
||||
type ApplicationVariableOption,
|
||||
type ApplicationVariableType,
|
||||
} from 'twenty-shared/application';
|
||||
|
||||
import { type EncryptedString } from 'src/engine/core-modules/secret-encryption/branded-strings/encrypted-string.type';
|
||||
import { type UniversalFlatApplicationVariable } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-application-variable.type';
|
||||
|
||||
@@ -8,6 +14,8 @@ export const fromApplicationVariableManifestToUniversalFlatApplicationVariable =
|
||||
description,
|
||||
encryptedValue,
|
||||
isSecret,
|
||||
type,
|
||||
options,
|
||||
applicationUniversalIdentifier,
|
||||
now,
|
||||
}: {
|
||||
@@ -16,6 +24,8 @@ export const fromApplicationVariableManifestToUniversalFlatApplicationVariable =
|
||||
description?: string;
|
||||
encryptedValue: EncryptedString | '';
|
||||
isSecret?: boolean;
|
||||
type?: ApplicationVariableType;
|
||||
options?: ApplicationVariableOption[];
|
||||
applicationUniversalIdentifier: string;
|
||||
now: string;
|
||||
}): UniversalFlatApplicationVariable => {
|
||||
@@ -26,6 +36,8 @@ export const fromApplicationVariableManifestToUniversalFlatApplicationVariable =
|
||||
value: encryptedValue,
|
||||
description: description ?? '',
|
||||
isSecret: isSecret ?? false,
|
||||
type: type ?? FieldMetadataType.TEXT,
|
||||
options: options ?? null,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
};
|
||||
|
||||
+15
-4
@@ -1,7 +1,11 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { type Manifest } from 'twenty-shared/application';
|
||||
import {
|
||||
type Manifest,
|
||||
serializeApplicationVariableValue,
|
||||
} from 'twenty-shared/application';
|
||||
import { MAX_CUSTOM_INDEXES_PER_OBJECT } from 'twenty-shared/constants';
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
import { fromApplicationVariableManifestToUniversalFlatApplicationVariable } from 'src/engine/core-modules/application/application-manifest/converters/from-application-variable-manifest-to-universal-flat-application-variable.util';
|
||||
@@ -604,13 +608,18 @@ export class ComputeApplicationManifestAllUniversalFlatEntityMapsService {
|
||||
for (const [key, applicationVariableManifest] of Object.entries(
|
||||
manifest.application.applicationVariables ?? {},
|
||||
)) {
|
||||
const type = applicationVariableManifest.type ?? FieldMetadataType.TEXT;
|
||||
|
||||
const plaintextValue =
|
||||
'value' in applicationVariableManifest
|
||||
? applicationVariableManifest.value
|
||||
: undefined;
|
||||
? serializeApplicationVariableValue(
|
||||
applicationVariableManifest.value,
|
||||
type,
|
||||
)
|
||||
: '';
|
||||
|
||||
const isSecret = applicationVariableManifest.isSecret;
|
||||
const rawValue = isSecret ? '' : (plaintextValue ?? '');
|
||||
const rawValue = isSecret ? '' : plaintextValue;
|
||||
|
||||
addUniversalFlatEntityToUniversalFlatEntityMapsThroughMutationOrThrow({
|
||||
universalFlatEntity:
|
||||
@@ -624,6 +633,8 @@ export class ComputeApplicationManifestAllUniversalFlatEntityMapsService {
|
||||
),
|
||||
description: applicationVariableManifest.description,
|
||||
isSecret,
|
||||
type,
|
||||
options: applicationVariableManifest.options,
|
||||
applicationUniversalIdentifier,
|
||||
now,
|
||||
}),
|
||||
|
||||
+15
@@ -15,6 +15,13 @@ import {
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
import { GraphQLJSON } from 'graphql-type-json';
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
import {
|
||||
type ApplicationVariableOption,
|
||||
type ApplicationVariableType,
|
||||
} from 'twenty-shared/application';
|
||||
|
||||
import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
|
||||
import { ApplicationRegistrationEntity } from 'src/engine/core-modules/application/application-registration/application-registration.entity';
|
||||
import { type EncryptedString } from 'src/engine/core-modules/secret-encryption/branded-strings/encrypted-string.type';
|
||||
@@ -57,6 +64,14 @@ export class ApplicationRegistrationVariableEntity {
|
||||
@Column({ nullable: false, type: 'boolean', default: false })
|
||||
isRequired: boolean;
|
||||
|
||||
@Field(() => String)
|
||||
@Column({ nullable: false, type: 'text', default: FieldMetadataType.TEXT })
|
||||
type: ApplicationVariableType;
|
||||
|
||||
@Field(() => GraphQLJSON, { nullable: true })
|
||||
@Column({ nullable: true, type: 'jsonb', default: null })
|
||||
options: ApplicationVariableOption[] | null;
|
||||
|
||||
@Field()
|
||||
get isFilled(): boolean {
|
||||
return this.encryptedValue !== '';
|
||||
|
||||
+5
@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import { type ServerVariables } from 'twenty-shared/application';
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { In, Not, type Repository } from 'typeorm';
|
||||
|
||||
@@ -136,6 +137,8 @@ export class ApplicationRegistrationVariableService {
|
||||
description: schema.description ?? '',
|
||||
isSecret: schema.isSecret ?? true,
|
||||
isRequired: schema.isRequired ?? false,
|
||||
type: schema.type ?? FieldMetadataType.TEXT,
|
||||
options: schema.options ?? null,
|
||||
});
|
||||
} else {
|
||||
await this.variableRepository.save(
|
||||
@@ -146,6 +149,8 @@ export class ApplicationRegistrationVariableService {
|
||||
description: schema.description ?? '',
|
||||
isSecret: schema.isSecret ?? true,
|
||||
isRequired: schema.isRequired ?? false,
|
||||
type: schema.type ?? FieldMetadataType.TEXT,
|
||||
options: schema.options ?? null,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
+11
-1
@@ -1,7 +1,9 @@
|
||||
import { Field, ObjectType } from '@nestjs/graphql';
|
||||
import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
|
||||
import { IsBoolean, IsString } from 'class-validator';
|
||||
import { IsBoolean, IsOptional, IsString } from 'class-validator';
|
||||
import { IDField } from '@ptc-org/nestjs-query-graphql';
|
||||
import { GraphQLJSON } from 'graphql-type-json';
|
||||
import { type ApplicationVariableOption } from 'twenty-shared/application';
|
||||
|
||||
@ObjectType()
|
||||
export class ApplicationRegistrationVariableDTO {
|
||||
@@ -32,6 +34,14 @@ export class ApplicationRegistrationVariableDTO {
|
||||
@Field()
|
||||
isFilled: boolean;
|
||||
|
||||
@IsString()
|
||||
@Field()
|
||||
type: string;
|
||||
|
||||
@IsOptional()
|
||||
@Field(() => GraphQLJSON, { nullable: true })
|
||||
options?: ApplicationVariableOption[] | null;
|
||||
|
||||
@Field(() => Date)
|
||||
createdAt: Date;
|
||||
|
||||
|
||||
+2
-1
@@ -9,6 +9,7 @@ import semver from 'semver';
|
||||
import { FileFolder } from 'twenty-shared/types';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { Repository } from 'typeorm';
|
||||
import { type QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
import { ApplicationRegistrationEntity } from 'src/engine/core-modules/application/application-registration/application-registration.entity';
|
||||
@@ -210,7 +211,7 @@ export class ApplicationTarballService {
|
||||
isListed: false,
|
||||
isFeatured: false,
|
||||
ownerWorkspaceId: params.ownerWorkspaceId,
|
||||
});
|
||||
} as QueryDeepPartialEntity<ApplicationRegistrationEntity>);
|
||||
|
||||
if (manifest.application?.serverVariables) {
|
||||
await this.applicationRegistrationVariableService.syncVariableSchemas(
|
||||
|
||||
+22
@@ -10,8 +10,16 @@ import {
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
import {
|
||||
type ApplicationVariableOption,
|
||||
type ApplicationVariableType,
|
||||
} from 'twenty-shared/application';
|
||||
|
||||
import { ADD_TYPE_AND_OPTIONS_TO_APPLICATION_VARIABLES_UPGRADE_COMMAND_NAME } from 'src/database/commands/upgrade-version-command/2-19/add-type-and-options-to-application-variables-upgrade-command-name.constant';
|
||||
import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
|
||||
import { type EncryptedString } from 'src/engine/core-modules/secret-encryption/branded-strings/encrypted-string.type';
|
||||
import { WasIntroducedInUpgrade } from 'src/engine/core-modules/upgrade/decorators/was-introduced-in-upgrade.decorator';
|
||||
import { SyncableEntity } from 'src/engine/workspace-manager/types/syncable-entity.interface';
|
||||
|
||||
@Entity({
|
||||
@@ -42,6 +50,20 @@ export class ApplicationVariableEntity extends SyncableEntity {
|
||||
@Column({ nullable: false, type: 'boolean', default: false })
|
||||
isSecret: boolean;
|
||||
|
||||
@WasIntroducedInUpgrade({
|
||||
upgradeCommandName:
|
||||
ADD_TYPE_AND_OPTIONS_TO_APPLICATION_VARIABLES_UPGRADE_COMMAND_NAME,
|
||||
})
|
||||
@Column({ nullable: false, type: 'text', default: FieldMetadataType.TEXT })
|
||||
type: ApplicationVariableType;
|
||||
|
||||
@WasIntroducedInUpgrade({
|
||||
upgradeCommandName:
|
||||
ADD_TYPE_AND_OPTIONS_TO_APPLICATION_VARIABLES_UPGRADE_COMMAND_NAME,
|
||||
})
|
||||
@Column({ nullable: true, type: 'jsonb', default: null })
|
||||
options: ApplicationVariableOption[] | null;
|
||||
|
||||
@CreateDateColumn({ type: 'timestamptz' })
|
||||
createdAt: Date;
|
||||
|
||||
|
||||
+11
-1
@@ -1,7 +1,9 @@
|
||||
import { Field, ObjectType } from '@nestjs/graphql';
|
||||
|
||||
import { IsBoolean, IsString } from 'class-validator';
|
||||
import { IsBoolean, IsOptional, IsString } from 'class-validator';
|
||||
import { GraphQLJSON } from 'graphql-type-json';
|
||||
import { IDField } from '@ptc-org/nestjs-query-graphql';
|
||||
import { type ApplicationVariableOption } from 'twenty-shared/application';
|
||||
|
||||
import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
|
||||
|
||||
@@ -25,4 +27,12 @@ export class ApplicationVariableEntityDTO {
|
||||
@IsBoolean()
|
||||
@Field()
|
||||
isSecret: boolean;
|
||||
|
||||
@IsString()
|
||||
@Field()
|
||||
type: string;
|
||||
|
||||
@IsOptional()
|
||||
@Field(() => GraphQLJSON, { nullable: true })
|
||||
options?: ApplicationVariableOption[] | null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user