Twenty sdk cli oauth (#18638)
<img width="1418" height="804" alt="image" src="https://github.com/user-attachments/assets/de6c8222-6496-4a71-bc21-7e5e1269d5cb" /> --------- Co-authored-by: Félix Malfait <felix.malfait@gmail.com> Co-authored-by: Félix Malfait <felix@twenty.com>
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import fs from 'fs';
|
||||
|
||||
import { ApiService } from '@/cli/utilities/api/api-service';
|
||||
import { runSafe } from '@/cli/utilities/run-safe';
|
||||
import { appBuild } from './build';
|
||||
import { APP_ERROR_CODES, type CommandResult } from '@/cli/types';
|
||||
|
||||
export type AppDeployOptions = {
|
||||
appPath: string;
|
||||
serverUrl: string;
|
||||
token?: string;
|
||||
onProgress?: (message: string) => void;
|
||||
};
|
||||
|
||||
export type AppDeployResult = {
|
||||
universalIdentifier: string;
|
||||
};
|
||||
|
||||
const innerAppDeploy = async (
|
||||
options: AppDeployOptions,
|
||||
): Promise<CommandResult<AppDeployResult>> => {
|
||||
const { appPath, serverUrl, token, onProgress } = options;
|
||||
|
||||
const buildResult = await appBuild({
|
||||
appPath,
|
||||
tarball: true,
|
||||
onProgress,
|
||||
});
|
||||
|
||||
if (!buildResult.success) {
|
||||
return buildResult;
|
||||
}
|
||||
|
||||
onProgress?.(`Uploading ${buildResult.data.tarballPath}...`);
|
||||
|
||||
const tarballBuffer = fs.readFileSync(buildResult.data.tarballPath!);
|
||||
|
||||
const apiService = new ApiService({
|
||||
serverUrl,
|
||||
token,
|
||||
});
|
||||
|
||||
const uploadResult = await apiService.uploadAppTarball({ tarballBuffer });
|
||||
|
||||
if (!uploadResult.success) {
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: APP_ERROR_CODES.DEPLOY_FAILED,
|
||||
message: `Upload failed: ${uploadResult.error}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
onProgress?.('Installing application...');
|
||||
|
||||
const installResult = await apiService.installTarballApp({
|
||||
universalIdentifier: uploadResult.data.universalIdentifier,
|
||||
});
|
||||
|
||||
if (!installResult.success) {
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: APP_ERROR_CODES.DEPLOY_FAILED,
|
||||
message: `Install failed: ${installResult.error}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
universalIdentifier: uploadResult.data.universalIdentifier,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const appDeploy = (
|
||||
options: AppDeployOptions,
|
||||
): Promise<CommandResult<AppDeployResult>> =>
|
||||
runSafe(() => innerAppDeploy(options), APP_ERROR_CODES.DEPLOY_FAILED);
|
||||
Reference in New Issue
Block a user