feat: add npm and tarball app distribution with upgrade mechanism (#18358)

## Summary

- **npm + tarball app distribution**: Apps can be installed from the npm
registry (public or private) or uploaded as `.tar.gz` tarballs, with
`AppRegistrationSourceType` tracking the origin
- **Upgrade mechanism**: `AppUpgradeService` checks for newer versions,
supports rollback for npm-sourced apps, and a cron job runs every 6
hours to update `latestAvailableVersion` on registrations
- **Security hardening**: Tarball extraction uses path traversal
protection, and `enableScripts: false` in `.yarnrc.yml` disables all
lifecycle scripts during `yarn install` to prevent RCE
- **Frontend**: "Install from npm" and "Upload tarball" modals, upgrade
button on app detail page, blue "Update" badge on installed apps table
when a newer version is available
- **Marketplace catalog sync**: Hourly cron job syncs a hardcoded
catalog index into `ApplicationRegistration` entities
- **Integration tests**: Coverage for install, upgrade, tarball upload,
and catalog sync flows

## Backend changes

| Area | Files |
|------|-------|
| Entity & migration | `ApplicationRegistrationEntity` (sourceType,
sourcePackage, latestAvailableVersion), `ApplicationEntity`
(applicationRegistrationId), migration |
| Services | `AppPackageResolverService`, `ApplicationInstallService`,
`AppUpgradeService`, `MarketplaceCatalogSyncService` |
| Cron jobs | `MarketplaceCatalogSyncCronJob` (hourly),
`AppVersionCheckCronJob` (every 6h) |
| REST endpoint | `AppRegistrationUploadController` — tarball upload
with secure extraction |
| Resolver | `MarketplaceResolver` — simplified `installMarketplaceApp`
(removed redundant `sourcePackage` arg) |
| Security | `.yarnrc.yml` — `enableScripts: false` to block postinstall
RCE |

## Frontend changes

| Area | Files |
|------|-------|
| Modals | `SettingsInstallNpmAppModal`, `SettingsUploadTarballModal`,
`SettingsAppModalLayout` |
| Hooks | `useUploadAppTarball`, `useInstallMarketplaceApp` (cleaned up)
|
| Upgrade UI | `SettingsApplicationVersionContainer`,
`SettingsApplicationDetailAboutTab` |
| Badge | `SettingsApplicationTableRow` — blue "Update" tag,
`SettingsApplicationsInstalledTab` — fetches registrations for version
comparison |
| Styling | Migrated to Linaria (matching main) |

## Test plan

- [ ] Install an app from npm via the "Install from npm" modal
- [ ] Upload a `.tar.gz` tarball via the "Upload tarball" modal
- [ ] Verify upgrade badge appears when `latestAvailableVersion >
version`
- [ ] Verify upgrade flow from app detail page
- [ ] Run integration tests: `app-distribution.integration-spec.ts`,
`marketplace-catalog-sync.integration-spec.ts`
- [ ] Verify `enableScripts: false` blocks postinstall scripts during
yarn install


Made with [Cursor](https://cursor.com)
This commit is contained in:
Félix Malfait
2026-03-05 10:34:08 +01:00
committed by GitHub
parent bfa50f566e
commit 0e89c96170
205 changed files with 4741 additions and 1014 deletions
@@ -14,18 +14,24 @@ export class ApiService {
private client: AxiosInstance;
private configService: ConfigService;
constructor(options?: { disableInterceptors: boolean }) {
const { disableInterceptors = false } = options || {};
constructor(options?: {
disableInterceptors?: boolean;
serverUrl?: string;
token?: string;
}) {
const { disableInterceptors = false, serverUrl, token } = options || {};
this.configService = new ConfigService();
this.client = axios.create();
this.client.interceptors.request.use(async (config) => {
const twentyConfig = await this.configService.getConfig();
config.baseURL = twentyConfig.apiUrl;
config.baseURL = serverUrl ?? twentyConfig.apiUrl;
if (!config.headers.Authorization && twentyConfig.apiKey) {
config.headers.Authorization = `Bearer ${twentyConfig.apiKey}`;
const authToken = token ?? twentyConfig.apiKey;
if (!config.headers.Authorization && authToken) {
config.headers.Authorization = `Bearer ${authToken}`;
}
return config;
@@ -794,6 +800,140 @@ export class ApiService {
);
}
// TODO: Migrate to MetadataClient once available
// (see https://github.com/twentyhq/core-team-issues/issues/2289)
async uploadAppTarball({
tarballBuffer,
universalIdentifier,
}: {
tarballBuffer: Buffer;
universalIdentifier?: string;
}): Promise<
ApiResponse<{
id: string;
universalIdentifier: string;
name: string;
}>
> {
try {
const mutation = `
mutation UploadAppTarball($file: Upload!, $universalIdentifier: String) {
uploadAppTarball(file: $file, universalIdentifier: $universalIdentifier) {
id
universalIdentifier
name
}
}
`;
const operations = JSON.stringify({
query: mutation,
variables: {
file: null,
universalIdentifier: universalIdentifier ?? null,
},
});
const map = JSON.stringify({
'0': ['variables.file'],
});
const formData = new FormData();
formData.append('operations', operations);
formData.append('map', map);
formData.append(
'0',
new Blob([new Uint8Array(tarballBuffer)], {
type: 'application/gzip',
}),
'app.tar.gz',
);
const response: AxiosResponse = await this.client.post(
'/metadata',
formData,
);
if (response.data.errors) {
return {
success: false,
error: response.data.errors[0]?.message || 'Failed to upload tarball',
};
}
return {
success: true,
data: response.data.data.uploadAppTarball,
};
} catch (error) {
if (axios.isAxiosError(error) && error.response) {
return {
success: false,
error: error.response.data?.errors?.[0]?.message || error.message,
};
}
return {
success: false,
error,
};
}
}
async installTarballApp({
universalIdentifier,
}: {
universalIdentifier: string;
}): Promise<ApiResponse<boolean>> {
try {
const mutation = `
mutation InstallMarketplaceApp($universalIdentifier: String!) {
installMarketplaceApp(universalIdentifier: $universalIdentifier)
}
`;
const response: AxiosResponse = await this.client.post(
'/metadata',
{
query: mutation,
variables: { universalIdentifier },
},
{
headers: {
'Content-Type': 'application/json',
Accept: '*/*',
},
},
);
if (response.data.errors) {
return {
success: false,
error:
response.data.errors[0]?.message || 'Failed to install application',
};
}
return {
success: true,
data: response.data.data.installMarketplaceApp,
};
} catch (error) {
if (axios.isAxiosError(error) && error.response) {
return {
success: false,
error: error.response.data?.errors?.[0]?.message || error.message,
};
}
return {
success: false,
error,
};
}
}
async uploadFile({
filePath,
builtHandlerPath,