Add uninstall button to application setting (#15988)

As title

<img width="878" height="668" alt="image"
src="https://github.com/user-attachments/assets/b0c9ae1e-036f-4bdd-9bd2-a2a37c2e3b99"
/>
This commit is contained in:
martmull
2025-11-21 15:45:07 +01:00
committed by GitHub
parent 1fa9c45879
commit 445b76fa26
25 changed files with 352 additions and 59 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "twenty-cli",
"version": "0.2.2",
"version": "0.2.3",
"description": "Command-line interface for Twenty application development",
"main": "dist/cli.js",
"bin": {
@@ -1,5 +1,5 @@
import { existsSync } from 'fs';
import { AppDeleteCommand } from '../../commands/app-delete.command';
import { AppUninstallCommand } from 'src/commands/app-uninstall.command';
import { AppSyncCommand } from '../../commands/app-sync.command';
import { COVERED_APPLICATION_FOLDERS } from './constants/covered-applications-folder.constant';
import { getTestedApplicationPath } from './utils/get-tested-application-path.util';
@@ -8,7 +8,7 @@ describe.each(COVERED_APPLICATION_FOLDERS)(
'Application: "%s" install delete and reinstall test suite',
(applicationName) => {
const syncCommand = new AppSyncCommand();
const deleteCommand = new AppDeleteCommand();
const deleteCommand = new AppUninstallCommand();
const appPath = getTestedApplicationPath(applicationName);
beforeAll(async () => {
@@ -5,7 +5,7 @@ import { ApiService } from '../services/api.service';
import { ApiResponse } from '../types/config.types';
import { loadManifest } from '../utils/load-manifest';
export class AppDeleteCommand {
export class AppUninstallCommand {
private apiService = new ApiService();
async execute({
@@ -16,31 +16,31 @@ export class AppDeleteCommand {
askForConfirmation: boolean;
}): Promise<ApiResponse<any>> {
try {
console.log(chalk.blue('🚀 Deleting Twenty Application'));
console.log(chalk.blue('🚀 Uninstall Twenty Application'));
console.log(chalk.gray(`📁 App Path: ${appPath}`));
console.log('');
if (askForConfirmation && !(await this.confirmationPrompt())) {
console.error(chalk.red('⛔️ Aborting deletion'));
console.error(chalk.red('⛔️ Aborting uninstall'));
process.exit(1);
}
const { manifest } = await loadManifest(appPath);
const result = await this.apiService.deleteApplication(
const result = await this.apiService.uninstallApplication(
manifest.application.universalIdentifier,
);
if (!result.success) {
console.error(chalk.red('❌ Deletion failed:'), result.error);
console.error(chalk.red('❌ Uninstall failed:'), result.error);
} else {
console.log(chalk.green('✅ Application deleted successfully'));
console.log(chalk.green('✅ Application uninstalled successfully'));
}
return result;
} catch (error) {
console.error(
chalk.red('Deletion failed:'),
chalk.red('Uninstall failed:'),
error instanceof Error ? error.message : error,
);
throw error;
@@ -52,7 +52,7 @@ export class AppDeleteCommand {
{
type: 'confirm',
name: 'confirmation',
message: 'Are you sure you want to delete this application?',
message: 'Are you sure you want to uninstall this application?',
default: false,
},
]);
@@ -5,7 +5,7 @@ import {
isSyncableEntity,
SyncableEntity,
} from './app-add.command';
import { AppDeleteCommand } from './app-delete.command';
import { AppUninstallCommand } from './app-uninstall.command';
import { AppDevCommand } from './app-dev.command';
import { AppInitCommand } from './app-init.command';
import { AppSyncCommand } from './app-sync.command';
@@ -15,7 +15,7 @@ import { AppGenerateCommand } from './app-generate.command';
export class AppCommand {
private devCommand = new AppDevCommand();
private syncCommand = new AppSyncCommand();
private deleteCommand = new AppDeleteCommand();
private uninstallCommand = new AppUninstallCommand();
private initCommand = new AppInitCommand();
private addCommand = new AppAddCommand();
private generateCommand = new AppGenerateCommand();
@@ -50,11 +50,29 @@ export class AppCommand {
});
appCommand
.command('delete [appPath]')
.command('uninstall [appPath]')
.description('Uninstall application from Twenty')
.action(async (appPath?: string) => {
try {
const result = await this.uninstallCommand.execute({
appPath: formatPath(appPath),
askForConfirmation: true,
});
if (!result.success) {
process.exit(1);
}
} catch {
process.exit(1);
}
});
// Keeping to avoid breaking changes
appCommand
.command('delete [appPath]', { hidden: true })
.description('Delete application from Twenty')
.action(async (appPath?: string) => {
try {
const result = await this.deleteCommand.execute({
const result = await this.uninstallCommand.execute({
appPath: formatPath(appPath),
askForConfirmation: true,
});
@@ -146,11 +146,13 @@ export class ApiService {
}
}
async deleteApplication(universalIdentifier: string): Promise<ApiResponse> {
async uninstallApplication(
universalIdentifier: string,
): Promise<ApiResponse> {
try {
const mutation = `
mutation DeleteApplication($universalIdentifier: String!) {
deleteApplication(universalIdentifier: $universalIdentifier)
mutation UninstallApplication($universalIdentifier: String!) {
uninstallApplication(universalIdentifier: $universalIdentifier)
}
`;
@@ -180,8 +182,8 @@ export class ApiService {
return {
success: true,
data: response.data.data.deleteApplication,
message: 'Successfully deleted application',
data: response.data.data.uninstallApplication,
message: 'Successfully uninstalled application',
};
} catch (error) {
if (axios.isAxiosError(error) && error.response) {
@@ -217,6 +217,7 @@ export type Application = {
__typename?: 'Application';
agents: Array<Agent>;
applicationVariables: Array<ApplicationVariable>;
canBeUninstalled: Scalars['Boolean'];
description: Scalars['String'];
id: Scalars['UUID'];
name: Scalars['String'];
@@ -1790,7 +1791,6 @@ export type Mutation = {
createWorkflowVersionEdge: WorkflowVersionStepChanges;
createWorkflowVersionStep: WorkflowVersionStepChanges;
deactivateWorkflowVersion: Scalars['Boolean'];
deleteApplication: Scalars['Boolean'];
deleteApprovedAccessDomain: Scalars['Boolean'];
deleteCoreView: Scalars['Boolean'];
deleteCoreViewField: CoreViewField;
@@ -1881,6 +1881,7 @@ export type Mutation = {
syncRemoteTableSchemaChanges: RemoteTable;
testHttpRequest: TestHttpRequestOutput;
trackAnalytics: Analytics;
uninstallApplication: Scalars['Boolean'];
unsyncRemoteTable: RemoteTable;
updateApiKey?: Maybe<ApiKey>;
updateCoreView: CoreView;
@@ -2168,11 +2169,6 @@ export type MutationDeactivateWorkflowVersionArgs = {
};
export type MutationDeleteApplicationArgs = {
universalIdentifier: Scalars['String'];
};
export type MutationDeleteApprovedAccessDomainArgs = {
input: DeleteApprovedAccessDomainInput;
};
@@ -2602,6 +2598,11 @@ export type MutationTrackAnalyticsArgs = {
};
export type MutationUninstallApplicationArgs = {
universalIdentifier: Scalars['String'];
};
export type MutationUnsyncRemoteTableArgs = {
input: RemoteTableInput;
};
@@ -5045,7 +5046,7 @@ export type UpdateOneApplicationVariableMutationVariables = Exact<{
export type UpdateOneApplicationVariableMutation = { __typename?: 'Mutation', updateOneApplicationVariable: boolean };
export type ApplicationFieldsFragment = { __typename?: 'Application', id: string, name: string, description: string, version: string, applicationVariables: Array<{ __typename?: 'ApplicationVariable', id: string, key: string, value: string, description: string, isSecret: boolean }>, agents: Array<{ __typename?: 'Agent', id: string, name: string, label: string, description?: string | null, icon?: string | null, prompt: string, modelId: string, responseFormat?: any | null, roleId?: string | null, isCustom: boolean, modelConfiguration?: any | null, applicationId?: string | null, createdAt: string, updatedAt: string }>, objects: Array<{ __typename?: 'Object', id: string, nameSingular: string, namePlural: string, labelSingular: string, labelPlural: string, description?: string | null, icon?: string | null, isCustom: boolean, isRemote: boolean, isActive: boolean, isSystem: boolean, isUIReadOnly: boolean, createdAt: string, updatedAt: string, labelIdentifierFieldMetadataId?: string | null, imageIdentifierFieldMetadataId?: string | null, applicationId?: string | null, shortcut?: string | null, isLabelSyncedWithName: boolean, isSearchable: boolean, duplicateCriteria?: Array<Array<string>> | null, indexMetadataList: Array<{ __typename?: 'Index', id: string, createdAt: string, updatedAt: string, name: string, indexWhereClause?: string | null, indexType: IndexType, isUnique: boolean, isCustom?: boolean | null, indexFieldMetadataList: Array<{ __typename?: 'IndexField', id: string, fieldMetadataId: string, createdAt: string, updatedAt: string, order: number }> }>, fieldsList: Array<{ __typename?: 'Field', id: string, type: FieldMetadataType, name: string, label: string, description?: string | null, icon?: string | null, isCustom?: boolean | null, isActive?: boolean | null, isSystem?: boolean | null, isUIReadOnly?: boolean | null, isNullable?: boolean | null, isUnique?: boolean | null, createdAt: string, updatedAt: string, defaultValue?: any | null, options?: any | null, settings?: any | null, isLabelSyncedWithName?: boolean | null, relation?: { __typename?: 'Relation', type: RelationType, sourceObjectMetadata: { __typename?: 'Object', id: string, nameSingular: string, namePlural: string }, targetObjectMetadata: { __typename?: 'Object', id: string, nameSingular: string, namePlural: string }, sourceFieldMetadata: { __typename?: 'Field', id: string, name: string }, targetFieldMetadata: { __typename?: 'Field', id: string, name: string } } | null, morphRelations?: Array<{ __typename?: 'Relation', type: RelationType, sourceObjectMetadata: { __typename?: 'Object', id: string, nameSingular: string, namePlural: string }, targetObjectMetadata: { __typename?: 'Object', id: string, nameSingular: string, namePlural: string }, sourceFieldMetadata: { __typename?: 'Field', id: string, name: string }, targetFieldMetadata: { __typename?: 'Field', id: string, name: string } }> | null }> }>, serverlessFunctions: Array<{ __typename?: 'ServerlessFunction', id: string, name: string, description?: string | null, runtime: string, timeoutSeconds: number, latestVersion?: string | null, publishedVersions: Array<string>, handlerPath: string, handlerName: string, createdAt: string, updatedAt: string, cronTriggers?: Array<{ __typename?: 'CronTrigger', id: string, settings: any, createdAt: string, updatedAt: string }> | null, databaseEventTriggers?: Array<{ __typename?: 'DatabaseEventTrigger', id: string, settings: any, createdAt: string, updatedAt: string }> | null, routeTriggers?: Array<{ __typename?: 'RouteTrigger', id: string, path: string, isAuthRequired: boolean, httpMethod: HttpMethod, createdAt: string, updatedAt: string }> | null }> };
export type ApplicationFieldsFragment = { __typename?: 'Application', id: string, name: string, description: string, version: string, universalIdentifier: string, canBeUninstalled: boolean, applicationVariables: Array<{ __typename?: 'ApplicationVariable', id: string, key: string, value: string, description: string, isSecret: boolean }>, agents: Array<{ __typename?: 'Agent', id: string, name: string, label: string, description?: string | null, icon?: string | null, prompt: string, modelId: string, responseFormat?: any | null, roleId?: string | null, isCustom: boolean, modelConfiguration?: any | null, applicationId?: string | null, createdAt: string, updatedAt: string }>, objects: Array<{ __typename?: 'Object', id: string, nameSingular: string, namePlural: string, labelSingular: string, labelPlural: string, description?: string | null, icon?: string | null, isCustom: boolean, isRemote: boolean, isActive: boolean, isSystem: boolean, isUIReadOnly: boolean, createdAt: string, updatedAt: string, labelIdentifierFieldMetadataId?: string | null, imageIdentifierFieldMetadataId?: string | null, applicationId?: string | null, shortcut?: string | null, isLabelSyncedWithName: boolean, isSearchable: boolean, duplicateCriteria?: Array<Array<string>> | null, indexMetadataList: Array<{ __typename?: 'Index', id: string, createdAt: string, updatedAt: string, name: string, indexWhereClause?: string | null, indexType: IndexType, isUnique: boolean, isCustom?: boolean | null, indexFieldMetadataList: Array<{ __typename?: 'IndexField', id: string, fieldMetadataId: string, createdAt: string, updatedAt: string, order: number }> }>, fieldsList: Array<{ __typename?: 'Field', id: string, type: FieldMetadataType, name: string, label: string, description?: string | null, icon?: string | null, isCustom?: boolean | null, isActive?: boolean | null, isSystem?: boolean | null, isUIReadOnly?: boolean | null, isNullable?: boolean | null, isUnique?: boolean | null, createdAt: string, updatedAt: string, defaultValue?: any | null, options?: any | null, settings?: any | null, isLabelSyncedWithName?: boolean | null, relation?: { __typename?: 'Relation', type: RelationType, sourceObjectMetadata: { __typename?: 'Object', id: string, nameSingular: string, namePlural: string }, targetObjectMetadata: { __typename?: 'Object', id: string, nameSingular: string, namePlural: string }, sourceFieldMetadata: { __typename?: 'Field', id: string, name: string }, targetFieldMetadata: { __typename?: 'Field', id: string, name: string } } | null, morphRelations?: Array<{ __typename?: 'Relation', type: RelationType, sourceObjectMetadata: { __typename?: 'Object', id: string, nameSingular: string, namePlural: string }, targetObjectMetadata: { __typename?: 'Object', id: string, nameSingular: string, namePlural: string }, sourceFieldMetadata: { __typename?: 'Field', id: string, name: string }, targetFieldMetadata: { __typename?: 'Field', id: string, name: string } }> | null }> }>, serverlessFunctions: Array<{ __typename?: 'ServerlessFunction', id: string, name: string, description?: string | null, runtime: string, timeoutSeconds: number, latestVersion?: string | null, publishedVersions: Array<string>, handlerPath: string, handlerName: string, createdAt: string, updatedAt: string, cronTriggers?: Array<{ __typename?: 'CronTrigger', id: string, settings: any, createdAt: string, updatedAt: string }> | null, databaseEventTriggers?: Array<{ __typename?: 'DatabaseEventTrigger', id: string, settings: any, createdAt: string, updatedAt: string }> | null, routeTriggers?: Array<{ __typename?: 'RouteTrigger', id: string, path: string, isAuthRequired: boolean, httpMethod: HttpMethod, createdAt: string, updatedAt: string }> | null }> };
export type FindManyApplicationsQueryVariables = Exact<{ [key: string]: never; }>;
@@ -5057,7 +5058,7 @@ export type FindOneApplicationQueryVariables = Exact<{
}>;
export type FindOneApplicationQuery = { __typename?: 'Query', findOneApplication: { __typename?: 'Application', id: string, name: string, description: string, version: string, applicationVariables: Array<{ __typename?: 'ApplicationVariable', id: string, key: string, value: string, description: string, isSecret: boolean }>, agents: Array<{ __typename?: 'Agent', id: string, name: string, label: string, description?: string | null, icon?: string | null, prompt: string, modelId: string, responseFormat?: any | null, roleId?: string | null, isCustom: boolean, modelConfiguration?: any | null, applicationId?: string | null, createdAt: string, updatedAt: string }>, objects: Array<{ __typename?: 'Object', id: string, nameSingular: string, namePlural: string, labelSingular: string, labelPlural: string, description?: string | null, icon?: string | null, isCustom: boolean, isRemote: boolean, isActive: boolean, isSystem: boolean, isUIReadOnly: boolean, createdAt: string, updatedAt: string, labelIdentifierFieldMetadataId?: string | null, imageIdentifierFieldMetadataId?: string | null, applicationId?: string | null, shortcut?: string | null, isLabelSyncedWithName: boolean, isSearchable: boolean, duplicateCriteria?: Array<Array<string>> | null, indexMetadataList: Array<{ __typename?: 'Index', id: string, createdAt: string, updatedAt: string, name: string, indexWhereClause?: string | null, indexType: IndexType, isUnique: boolean, isCustom?: boolean | null, indexFieldMetadataList: Array<{ __typename?: 'IndexField', id: string, fieldMetadataId: string, createdAt: string, updatedAt: string, order: number }> }>, fieldsList: Array<{ __typename?: 'Field', id: string, type: FieldMetadataType, name: string, label: string, description?: string | null, icon?: string | null, isCustom?: boolean | null, isActive?: boolean | null, isSystem?: boolean | null, isUIReadOnly?: boolean | null, isNullable?: boolean | null, isUnique?: boolean | null, createdAt: string, updatedAt: string, defaultValue?: any | null, options?: any | null, settings?: any | null, isLabelSyncedWithName?: boolean | null, relation?: { __typename?: 'Relation', type: RelationType, sourceObjectMetadata: { __typename?: 'Object', id: string, nameSingular: string, namePlural: string }, targetObjectMetadata: { __typename?: 'Object', id: string, nameSingular: string, namePlural: string }, sourceFieldMetadata: { __typename?: 'Field', id: string, name: string }, targetFieldMetadata: { __typename?: 'Field', id: string, name: string } } | null, morphRelations?: Array<{ __typename?: 'Relation', type: RelationType, sourceObjectMetadata: { __typename?: 'Object', id: string, nameSingular: string, namePlural: string }, targetObjectMetadata: { __typename?: 'Object', id: string, nameSingular: string, namePlural: string }, sourceFieldMetadata: { __typename?: 'Field', id: string, name: string }, targetFieldMetadata: { __typename?: 'Field', id: string, name: string } }> | null }> }>, serverlessFunctions: Array<{ __typename?: 'ServerlessFunction', id: string, name: string, description?: string | null, runtime: string, timeoutSeconds: number, latestVersion?: string | null, publishedVersions: Array<string>, handlerPath: string, handlerName: string, createdAt: string, updatedAt: string, cronTriggers?: Array<{ __typename?: 'CronTrigger', id: string, settings: any, createdAt: string, updatedAt: string }> | null, databaseEventTriggers?: Array<{ __typename?: 'DatabaseEventTrigger', id: string, settings: any, createdAt: string, updatedAt: string }> | null, routeTriggers?: Array<{ __typename?: 'RouteTrigger', id: string, path: string, isAuthRequired: boolean, httpMethod: HttpMethod, createdAt: string, updatedAt: string }> | null }> } };
export type FindOneApplicationQuery = { __typename?: 'Query', findOneApplication: { __typename?: 'Application', id: string, name: string, description: string, version: string, universalIdentifier: string, canBeUninstalled: boolean, applicationVariables: Array<{ __typename?: 'ApplicationVariable', id: string, key: string, value: string, description: string, isSecret: boolean }>, agents: Array<{ __typename?: 'Agent', id: string, name: string, label: string, description?: string | null, icon?: string | null, prompt: string, modelId: string, responseFormat?: any | null, roleId?: string | null, isCustom: boolean, modelConfiguration?: any | null, applicationId?: string | null, createdAt: string, updatedAt: string }>, objects: Array<{ __typename?: 'Object', id: string, nameSingular: string, namePlural: string, labelSingular: string, labelPlural: string, description?: string | null, icon?: string | null, isCustom: boolean, isRemote: boolean, isActive: boolean, isSystem: boolean, isUIReadOnly: boolean, createdAt: string, updatedAt: string, labelIdentifierFieldMetadataId?: string | null, imageIdentifierFieldMetadataId?: string | null, applicationId?: string | null, shortcut?: string | null, isLabelSyncedWithName: boolean, isSearchable: boolean, duplicateCriteria?: Array<Array<string>> | null, indexMetadataList: Array<{ __typename?: 'Index', id: string, createdAt: string, updatedAt: string, name: string, indexWhereClause?: string | null, indexType: IndexType, isUnique: boolean, isCustom?: boolean | null, indexFieldMetadataList: Array<{ __typename?: 'IndexField', id: string, fieldMetadataId: string, createdAt: string, updatedAt: string, order: number }> }>, fieldsList: Array<{ __typename?: 'Field', id: string, type: FieldMetadataType, name: string, label: string, description?: string | null, icon?: string | null, isCustom?: boolean | null, isActive?: boolean | null, isSystem?: boolean | null, isUIReadOnly?: boolean | null, isNullable?: boolean | null, isUnique?: boolean | null, createdAt: string, updatedAt: string, defaultValue?: any | null, options?: any | null, settings?: any | null, isLabelSyncedWithName?: boolean | null, relation?: { __typename?: 'Relation', type: RelationType, sourceObjectMetadata: { __typename?: 'Object', id: string, nameSingular: string, namePlural: string }, targetObjectMetadata: { __typename?: 'Object', id: string, nameSingular: string, namePlural: string }, sourceFieldMetadata: { __typename?: 'Field', id: string, name: string }, targetFieldMetadata: { __typename?: 'Field', id: string, name: string } } | null, morphRelations?: Array<{ __typename?: 'Relation', type: RelationType, sourceObjectMetadata: { __typename?: 'Object', id: string, nameSingular: string, namePlural: string }, targetObjectMetadata: { __typename?: 'Object', id: string, nameSingular: string, namePlural: string }, sourceFieldMetadata: { __typename?: 'Field', id: string, name: string }, targetFieldMetadata: { __typename?: 'Field', id: string, name: string } }> | null }> }>, serverlessFunctions: Array<{ __typename?: 'ServerlessFunction', id: string, name: string, description?: string | null, runtime: string, timeoutSeconds: number, latestVersion?: string | null, publishedVersions: Array<string>, handlerPath: string, handlerName: string, createdAt: string, updatedAt: string, cronTriggers?: Array<{ __typename?: 'CronTrigger', id: string, settings: any, createdAt: string, updatedAt: string }> | null, databaseEventTriggers?: Array<{ __typename?: 'DatabaseEventTrigger', id: string, settings: any, createdAt: string, updatedAt: string }> | null, routeTriggers?: Array<{ __typename?: 'RouteTrigger', id: string, path: string, isAuthRequired: boolean, httpMethod: HttpMethod, createdAt: string, updatedAt: string }> | null }> } };
export type UploadFileMutationVariables = Exact<{
file: Scalars['Upload'];
@@ -5621,6 +5622,13 @@ export type GetSystemHealthStatusQueryVariables = Exact<{ [key: string]: never;
export type GetSystemHealthStatusQuery = { __typename?: 'Query', getSystemHealthStatus: { __typename?: 'SystemHealth', services: Array<{ __typename?: 'SystemHealthService', id: HealthIndicatorId, label: string, status: AdminPanelHealthServiceStatus }> } };
export type UninstallApplicationMutationVariables = Exact<{
universalIdentifier: Scalars['String'];
}>;
export type UninstallApplicationMutation = { __typename?: 'Mutation', uninstallApplication: boolean };
export type ApiKeyFragmentFragment = { __typename?: 'ApiKey', id: string, name: string, expiresAt: string, revokedAt?: string | null, role: { __typename?: 'Role', id: string, label: string, icon?: string | null } };
export type WebhookFragmentFragment = { __typename?: 'Webhook', id: string, targetUrl: string, operations: Array<string>, description?: string | null, secret: string };
@@ -6633,6 +6641,8 @@ export const ApplicationFieldsFragmentDoc = gql`
name
description
version
universalIdentifier
canBeUninstalled
applicationVariables {
id
key
@@ -10766,6 +10776,37 @@ export function useGetSystemHealthStatusLazyQuery(baseOptions?: Apollo.LazyQuery
export type GetSystemHealthStatusQueryHookResult = ReturnType<typeof useGetSystemHealthStatusQuery>;
export type GetSystemHealthStatusLazyQueryHookResult = ReturnType<typeof useGetSystemHealthStatusLazyQuery>;
export type GetSystemHealthStatusQueryResult = Apollo.QueryResult<GetSystemHealthStatusQuery, GetSystemHealthStatusQueryVariables>;
export const UninstallApplicationDocument = gql`
mutation UninstallApplication($universalIdentifier: String!) {
uninstallApplication(universalIdentifier: $universalIdentifier)
}
`;
export type UninstallApplicationMutationFn = Apollo.MutationFunction<UninstallApplicationMutation, UninstallApplicationMutationVariables>;
/**
* __useUninstallApplicationMutation__
*
* To run a mutation, you first call `useUninstallApplicationMutation` within a React component and pass it any options that fit your needs.
* When your component renders, `useUninstallApplicationMutation` returns a tuple that includes:
* - A mutate function that you can call at any time to execute the mutation
* - An object with fields that represent the current status of the mutation's execution
*
* @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2;
*
* @example
* const [uninstallApplicationMutation, { data, loading, error }] = useUninstallApplicationMutation({
* variables: {
* universalIdentifier: // value for 'universalIdentifier'
* },
* });
*/
export function useUninstallApplicationMutation(baseOptions?: Apollo.MutationHookOptions<UninstallApplicationMutation, UninstallApplicationMutationVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useMutation<UninstallApplicationMutation, UninstallApplicationMutationVariables>(UninstallApplicationDocument, options);
}
export type UninstallApplicationMutationHookResult = ReturnType<typeof useUninstallApplicationMutation>;
export type UninstallApplicationMutationResult = Apollo.MutationResult<UninstallApplicationMutation>;
export type UninstallApplicationMutationOptions = Apollo.BaseMutationOptions<UninstallApplicationMutation, UninstallApplicationMutationVariables>;
export const AssignRoleToApiKeyDocument = gql`
mutation AssignRoleToApiKey($apiKeyId: UUID!, $roleId: UUID!) {
assignRoleToApiKey(apiKeyId: $apiKeyId, roleId: $roleId)
@@ -217,6 +217,7 @@ export type Application = {
__typename?: 'Application';
agents: Array<Agent>;
applicationVariables: Array<ApplicationVariable>;
canBeUninstalled: Scalars['Boolean'];
description: Scalars['String'];
id: Scalars['UUID'];
name: Scalars['String'];
@@ -1765,7 +1766,6 @@ export type Mutation = {
createWorkflowVersionEdge: WorkflowVersionStepChanges;
createWorkflowVersionStep: WorkflowVersionStepChanges;
deactivateWorkflowVersion: Scalars['Boolean'];
deleteApplication: Scalars['Boolean'];
deleteApprovedAccessDomain: Scalars['Boolean'];
deleteCoreView: Scalars['Boolean'];
deleteCoreViewField: CoreViewField;
@@ -1853,6 +1853,7 @@ export type Mutation = {
syncApplication: Scalars['Boolean'];
testHttpRequest: TestHttpRequestOutput;
trackAnalytics: Analytics;
uninstallApplication: Scalars['Boolean'];
updateApiKey?: Maybe<ApiKey>;
updateCoreView: CoreView;
updateCoreViewField: CoreViewField;
@@ -2128,11 +2129,6 @@ export type MutationDeactivateWorkflowVersionArgs = {
};
export type MutationDeleteApplicationArgs = {
universalIdentifier: Scalars['String'];
};
export type MutationDeleteApprovedAccessDomainArgs = {
input: DeleteApprovedAccessDomainInput;
};
@@ -2547,6 +2543,11 @@ export type MutationTrackAnalyticsArgs = {
};
export type MutationUninstallApplicationArgs = {
universalIdentifier: Scalars['String'];
};
export type MutationUpdateApiKeyArgs = {
input: UpdateApiKeyInput;
};
@@ -12,6 +12,8 @@ export const APPLICATION_FRAGMENT = gql`
name
description
version
universalIdentifier
canBeUninstalled
applicationVariables {
id
key
@@ -0,0 +1,7 @@
import gql from 'graphql-tag';
export const UNINSTALL_APPLICATION = gql`
mutation UninstallApplication($universalIdentifier: String!) {
uninstallApplication(universalIdentifier: $universalIdentifier)
}
`;
@@ -2,16 +2,41 @@ import { isDefined } from 'twenty-shared/utils';
import type { Application } from '~/generated/graphql';
import { useUpdateOneApplicationVariable } from '~/pages/settings/applications/hooks/useUpdateOneApplicationVariable';
import { SettingsApplicationDetailEnvironmentVariablesTable } from '~/pages/settings/applications/tabs/SettingsApplicationDetailEnvironmentVariablesTable';
import { H2Title, IconTrash } from 'twenty-ui/display';
import { Button } from 'twenty-ui/input';
import { Section } from 'twenty-ui/layout';
import { Trans, useLingui } from '@lingui/react/macro';
import { useModal } from '@/ui/layout/modal/hooks/useModal';
import { ConfirmationModal } from '@/ui/layout/modal/components/ConfirmationModal';
import { useState } from 'react';
import { SettingsPath } from 'twenty-shared/types';
import { useNavigateSettings } from '~/hooks/useNavigateSettings';
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
import { useUninstallApplicationMutation } from '~/generated-metadata/graphql';
const UNINSTALL_APPLICATION_MODAL_ID = 'uninstall-application-modal';
export const SettingsApplicationDetailSettingsTab = ({
application,
}: {
application?: Omit<Application, 'objects' | 'universalIdentifier'> & {
application?: Omit<Application, 'objects'> & {
objects: { id: string }[];
};
}) => {
const { t } = useLingui();
const { openModal } = useModal();
const { enqueueErrorSnackBar, enqueueSuccessSnackBar } = useSnackBar();
const navigate = useNavigateSettings();
const [isLoading, setIsLoading] = useState(false);
const { updateOneApplicationVariable } = useUpdateOneApplicationVariable();
const [uninstallApplication] = useUninstallApplicationMutation();
if (!isDefined(application)) {
return null;
}
@@ -20,16 +45,70 @@ export const SettingsApplicationDetailSettingsTab = ({
(a, b) => a.key.localeCompare(b.key),
);
const handleUninstallApplication = async () => {
setIsLoading(true);
try {
await uninstallApplication({
variables: { universalIdentifier: application.universalIdentifier },
});
enqueueSuccessSnackBar({
message: t`Application successfully uninstalled.`,
});
navigate(SettingsPath.Applications);
} catch {
enqueueErrorSnackBar({ message: t`Error uninstalling application.` });
} finally {
setIsLoading(false);
}
};
const confirmationValue = t`yes`;
return (
<SettingsApplicationDetailEnvironmentVariablesTable
envVariables={envVariables}
onUpdate={({ key, value }) =>
updateOneApplicationVariable({
key,
value,
applicationId: application.id,
})
}
/>
<>
<SettingsApplicationDetailEnvironmentVariablesTable
envVariables={envVariables}
onUpdate={({ key, value }) =>
updateOneApplicationVariable({
key,
value,
applicationId: application.id,
})
}
/>
{application.canBeUninstalled && (
<>
<Section>
<H2Title
title={t`Danger zone`}
description={t`Uninstall this application`}
/>
<Button
accent="danger"
variant="secondary"
title={t`Uninstall`}
Icon={IconTrash}
onClick={() => openModal(UNINSTALL_APPLICATION_MODAL_ID)}
/>
</Section>
<ConfirmationModal
confirmationPlaceholder={confirmationValue}
confirmationValue={confirmationValue}
modalId={UNINSTALL_APPLICATION_MODAL_ID}
title={t`Uninstall Application?`}
subtitle={
<Trans>
Please type {`"${confirmationValue}"`} to confirm you want to
uninstall this application.
</Trans>
}
onConfirmClick={handleUninstallApplication}
confirmButtonText={t`Uninstall`}
loading={isLoading}
/>
</>
)}
</>
);
};
@@ -0,0 +1,70 @@
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Command } from 'nest-commander';
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
import { ApplicationEntity } from 'src/engine/core-modules/application/application.entity';
import { ApplicationService } from 'src/engine/core-modules/application/application.service';
import {
ActiveOrSuspendedWorkspacesMigrationCommandRunner,
RunOnWorkspaceArgs,
} from 'src/database/commands/command-runners/active-or-suspended-workspaces-migration.command-runner';
import { TWENTY_STANDARD_APPLICATION } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/twenty-standard-applications';
@Command({
name: 'upgrade:1-12:set-standard-application-not-uninstallable',
description: 'Set canBeUninstalled flag to false for standard applications',
})
export class SetStandardApplicationNotUninstallableCommand extends ActiveOrSuspendedWorkspacesMigrationCommandRunner {
constructor(
@InjectRepository(WorkspaceEntity)
protected readonly workspaceRepository: Repository<WorkspaceEntity>,
protected readonly twentyORMGlobalManager: TwentyORMGlobalManager,
@InjectRepository(ApplicationEntity)
private readonly applicationRepository: Repository<ApplicationEntity>,
private readonly applicationService: ApplicationService,
) {
super(workspaceRepository, twentyORMGlobalManager);
}
override async runOnWorkspace({
workspaceId,
options,
}: RunOnWorkspaceArgs): Promise<void> {
try {
this.logger.log(
`Checking standard applications for workspace ${workspaceId}`,
);
const existingApplications = await this.applicationRepository.find({
where: [
{
workspaceId,
universalIdentifier:
TWENTY_STANDARD_APPLICATION.universalIdentifier,
},
{
workspaceId,
description: 'Workspace custom application',
sourcePath: 'workspace-custom',
},
],
});
if (options.dryRun) {
return;
}
for (const existingApplication of existingApplications) {
await this.applicationService.update(existingApplication.id, {
canBeUninstalled: false,
});
}
this.logger.log(`Successfully updated standard applications`);
} catch (e) {
this.logger.error(`Failed to update standard applications`, e);
}
}
}
@@ -0,0 +1,19 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
import { ApplicationEntity } from 'src/engine/core-modules/application/application.entity';
import { WorkspaceSchemaManagerModule } from 'src/engine/twenty-orm/workspace-schema-manager/workspace-schema-manager.module';
import { ApplicationModule } from 'src/engine/core-modules/application/application.module';
import { SetStandardApplicationNotUninstallableCommand } from 'src/database/commands/upgrade-version-command/1-12/1-12-set-standard-application-not-uninstallable.command';
@Module({
imports: [
TypeOrmModule.forFeature([WorkspaceEntity, ApplicationEntity]),
WorkspaceSchemaManagerModule,
ApplicationModule,
],
providers: [SetStandardApplicationNotUninstallableCommand],
exports: [SetStandardApplicationNotUninstallableCommand],
})
export class V1_12_UpgradeVersionCommandModule {}
@@ -6,6 +6,7 @@ import { V1_11_UpgradeVersionCommandModule } from 'src/database/commands/upgrade
import { V1_6_UpgradeVersionCommandModule } from 'src/database/commands/upgrade-version-command/1-6/1-6-upgrade-version-command.module';
import { V1_7_UpgradeVersionCommandModule } from 'src/database/commands/upgrade-version-command/1-7/1-7-upgrade-version-command.module';
import { V1_8_UpgradeVersionCommandModule } from 'src/database/commands/upgrade-version-command/1-8/1-8-upgrade-version-command.module';
import { V1_12_UpgradeVersionCommandModule } from 'src/database/commands/upgrade-version-command/1-12/1-12-upgrade-version-command.module';
import { UpgradeCommand } from 'src/database/commands/upgrade-version-command/upgrade.command';
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
import { WorkspaceSyncMetadataModule } from 'src/engine/workspace-manager/workspace-sync-metadata/workspace-sync-metadata.module';
@@ -18,6 +19,7 @@ import { WorkspaceSyncMetadataModule } from 'src/engine/workspace-manager/worksp
V1_8_UpgradeVersionCommandModule,
V1_10_UpgradeVersionCommandModule,
V1_11_UpgradeVersionCommandModule,
V1_12_UpgradeVersionCommandModule,
WorkspaceSyncMetadataModule,
],
providers: [UpgradeCommand],
@@ -33,6 +33,7 @@ import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twent
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
import { SyncWorkspaceMetadataCommand } from 'src/engine/workspace-manager/workspace-sync-metadata/commands/sync-workspace-metadata.command';
import { SetStandardApplicationNotUninstallableCommand } from 'src/database/commands/upgrade-version-command/1-12/1-12-set-standard-application-not-uninstallable.command';
@Command({
name: 'upgrade',
@@ -77,6 +78,9 @@ export class UpgradeCommand extends UpgradeCommandRunner {
protected readonly cleanOrphanedUserWorkspacesCommand: CleanOrphanedUserWorkspacesCommand,
protected readonly cleanOrphanedRoleTargetsCommand: CleanOrphanedRoleTargetsCommand,
protected readonly seedStandardApplicationsCommand: CreateTwentyStandardApplicationCommand,
// 1.12 Commands
protected readonlysetStandardApplicationNotUninstallableCommand: SetStandardApplicationNotUninstallableCommand,
) {
super(
workspaceRepository,
@@ -133,12 +137,20 @@ export class UpgradeCommand extends UpgradeCommandRunner {
],
};
const commands_1120: VersionCommands = {
beforeSyncMetadata: [],
afterSyncMetadata: [
this.readonlysetStandardApplicationNotUninstallableCommand,
],
};
this.allCommands = {
'1.6.0': commands_160,
'1.7.0': commands_170,
'1.8.0': commands_180,
'1.10.0': commands_1100,
'1.11.0': commands_1110,
'1.12.0': commands_1120,
};
}
@@ -0,0 +1,19 @@
import { type MigrationInterface, type QueryRunner } from 'typeorm';
export class AddCanBeUninstalledColumnToApplication1763731277403
implements MigrationInterface
{
name = 'AddCanBeUninstalledColumnToApplication1763731277403';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "core"."application" ADD "canBeUninstalled" boolean NOT NULL DEFAULT true`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "core"."application" DROP COLUMN "canBeUninstalled"`,
);
}
}
@@ -6,7 +6,10 @@ import {
ApplicationException,
ApplicationExceptionCode,
} from 'src/engine/core-modules/application/application.exception';
import { NotFoundError } from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
import {
NotFoundError,
UserInputError,
} from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
@Catch(ApplicationException)
export class ApplicationExceptionFilter implements ExceptionFilter {
@@ -18,6 +21,8 @@ export class ApplicationExceptionFilter implements ExceptionFilter {
case ApplicationExceptionCode.APPLICATION_NOT_FOUND:
case ApplicationExceptionCode.SERVERLESS_FUNCTION_NOT_FOUND:
throw new NotFoundError(exception);
case ApplicationExceptionCode.FORBIDDEN:
throw new UserInputError(exception);
default: {
assertUnreachable(exception.code);
}
@@ -926,7 +926,7 @@ export class ApplicationSyncService {
}
}
public async deleteApplication({
public async uninstallApplication({
workspaceId,
applicationUniversalIdentifier,
}: {
@@ -959,6 +959,13 @@ export class ApplicationSyncService {
);
}
if (!application.canBeUninstalled) {
throw new ApplicationException(
'This application cannot be uninstalled.',
ApplicationExceptionCode.FORBIDDEN,
);
}
const flatObjectMetadataMapsByApplicationId =
getFlatEntitiesByApplicationId(
existingFlatObjectMetadataMaps,
@@ -59,6 +59,9 @@ export class ApplicationEntity {
@Column({ nullable: true, type: 'uuid' })
serverlessFunctionLayerId: string | null;
@Column({ nullable: false, type: 'boolean', default: true })
canBeUninstalled: boolean;
@ManyToOne(() => WorkspaceEntity, {
onDelete: 'CASCADE',
})
@@ -8,4 +8,5 @@ export enum ApplicationExceptionCode {
SERVERLESS_FUNCTION_NOT_FOUND = 'SERVERLESS_FUNCTION_NOT_FOUND',
ENTITY_NOT_FOUND = 'ENTITY_NOT_FOUND',
APPLICATION_NOT_FOUND = 'APPLICATION_NOT_FOUND',
FORBIDDEN = 'FORBIDDEN',
}
@@ -7,7 +7,7 @@ import { ApplicationSyncService } from 'src/engine/core-modules/application/appl
import { ApplicationService } from 'src/engine/core-modules/application/application.service';
import { ApplicationDTO } from 'src/engine/core-modules/application/dtos/application.dto';
import { ApplicationInput } from 'src/engine/core-modules/application/dtos/application.input';
import { DeleteApplicationInput } from 'src/engine/core-modules/application/dtos/deleteApplication.input';
import { UninstallApplicationInput } from 'src/engine/core-modules/application/dtos/uninstallApplicationInput';
import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
@@ -61,11 +61,11 @@ export class ApplicationResolver {
}
@Mutation(() => Boolean)
async deleteApplication(
@Args() { universalIdentifier }: DeleteApplicationInput,
async uninstallApplication(
@Args() { universalIdentifier }: UninstallApplicationInput,
@AuthWorkspace() { id: workspaceId }: WorkspaceEntity,
) {
await this.applicationSyncService.deleteApplication({
await this.applicationSyncService.uninstallApplication({
applicationUniversalIdentifier: universalIdentifier,
workspaceId,
});
@@ -1,6 +1,6 @@
import { Field, ObjectType } from '@nestjs/graphql';
import { IsNotEmpty, IsString, IsUUID } from 'class-validator';
import { IsBoolean, IsNotEmpty, IsString, IsUUID } from 'class-validator';
import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
import { ApplicationVariableEntityDTO } from 'src/engine/core-modules/applicationVariable/dtos/application-variable.dto';
@@ -27,6 +27,14 @@ export class ApplicationDTO {
@Field()
version: string;
@IsString()
@Field()
universalIdentifier: string;
@Field(() => Boolean)
@IsBoolean()
canBeUninstalled: boolean;
@Field(() => [AgentDTO])
agents: AgentDTO[];
@@ -38,8 +46,4 @@ export class ApplicationDTO {
@Field(() => [ApplicationVariableEntityDTO])
applicationVariables: ApplicationVariableEntityDTO[];
@IsString()
@Field()
universalIdentifier: string;
}
@@ -1,7 +1,7 @@
import { ArgsType, Field } from '@nestjs/graphql';
@ArgsType()
export class DeleteApplicationInput {
export class UninstallApplicationInput {
@Field(() => String)
universalIdentifier: string;
}
@@ -8,6 +8,7 @@ export const TWENTY_STANDARD_APPLICATION = {
version: '1.0.0',
sourcePath: 'cli-sync',
sourceType: 'local',
canBeUninstalled: false,
} as const satisfies CreateApplicationInput;
export type CreateApplicationInput = Omit<
@@ -24,5 +25,3 @@ export type CreateApplicationInput = Omit<
| 'objects'
| 'serverlessFunctions'
>;
export type TwentyStandardApplicationUniversalIdentifiers =
(typeof TWENTY_STANDARD_APPLICATION)['universalIdentifier'];
@@ -20,6 +20,7 @@ export const computeWorkspaceCustomCreateApplicationInput = ({
universalIdentifier: applicationId,
workspaceId: workspace.id,
id: applicationId,
canBeUninstalled: false,
}) as const satisfies CreateApplicationInput & {
workspaceId: string;
id: string;
@@ -12,6 +12,7 @@ export const APPLICATION_GQL_FIELDS = `
description
version
universalIdentifier
canBeUninstalled
`;
export const findManyApplications = async ({