From f4bdf620edc452eaf5dbb04adfafe2b1b7c98a3b Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Fri, 26 Jul 2024 17:24:22 +0530 Subject: [PATCH] updated reinstall and deploy with marketplace calls --- src/commands/app/deploy.ts | 21 +++++++----- src/commands/app/reinstall.ts | 9 ++--- src/util/common-utils.ts | 63 ++++++++++++----------------------- 3 files changed, 37 insertions(+), 56 deletions(-) diff --git a/src/commands/app/deploy.ts b/src/commands/app/deploy.ts index 585ce80..1e2e5b1 100644 --- a/src/commands/app/deploy.ts +++ b/src/commands/app/deploy.ts @@ -70,7 +70,7 @@ export default class Deploy extends AppCLIBaseCommand { const apolloClient = await this.getApolloClient(); const projects = await getProjects(apolloClient); await this.handleAppDisconnect(projects); - + flags["hosting-type"] = flags["hosting-type"] || (await getHostingType()); const updateHostingPayload: UpdateHostingParams = { provider: "external", @@ -89,14 +89,18 @@ export default class Deploy extends AppCLIBaseCommand { config["name"] = config["name"] || app?.name; this.flags["launch-project"] = this.flags["launch-project"] || (await askProjectType()); - await this.handleHostingWithLaunch(config, updateHostingPayload, projects); + await this.handleHostingWithLaunch( + config, + updateHostingPayload, + projects + ); break; default: this.log("Please provide a valid Hosting Type.", "error"); return; } - if(this.flags["app-uid"]){ + if (this.flags["app-uid"]) { await updateApp( flags, this.sharedConfig.org, @@ -284,11 +288,10 @@ export default class Deploy extends AppCLIBaseCommand { if (!this.flags["yes"]) { throw new Error(deployAppMsg.APP_UPDATE_TERMINATION_MSG); } - await disconnectApp( - this.flags, - this.sharedConfig.org, - this.developerHubBaseUrl - ); + await disconnectApp(this.flags, this.sharedConfig.org, { + marketplaceSdk: this.marketplaceAppSdk, + log: this.log, + }); } } -} \ No newline at end of file +} diff --git a/src/commands/app/reinstall.ts b/src/commands/app/reinstall.ts index d1305b3..eee2c6a 100644 --- a/src/commands/app/reinstall.ts +++ b/src/commands/app/reinstall.ts @@ -102,12 +102,9 @@ export default class Reinstall extends AppCLIBaseCommand { }), "info" ); - await reinstallApp({ - flags: this.flags, - type: appType, - developerHubBaseUrl: this.developerHubBaseUrl, - orgUid: this.sharedConfig.org, - manifestUid: this.flags["app-uid"], + await reinstallApp(this.flags, this.sharedConfig.org, appType, { + marketplaceSdk: this.marketplaceAppSdk, + log: this.log, }); this.log( $t(reinstallAppMsg.APP_REINSTALLED_SUCCESSFULLY, { diff --git a/src/util/common-utils.ts b/src/util/common-utils.ts index 5aa3807..860c218 100644 --- a/src/util/common-utils.ts +++ b/src/util/common-utils.ts @@ -10,7 +10,6 @@ import { HttpClient, } from "@contentstack/cli-utilities"; import { projectsQuery } from "../graphql/queries"; -import { apiRequestHandler } from "./api-request-handler"; import { AppLocation, Extension, @@ -166,34 +165,23 @@ function installApp( }); } -async function reinstallApp(params: { - flags: FlagInput; - type: string; - developerHubBaseUrl: string; - orgUid: string; - manifestUid: string; -}): Promise { - const { type, developerHubBaseUrl, flags, orgUid, manifestUid } = params; - const payload = { - target_type: type, - target_uid: (flags["stack-api-key"] as any) || orgUid, - }; - - const url = `https://${developerHubBaseUrl}/manifests/${manifestUid}/reinstall`; - try { - const result = await apiRequestHandler({ - orgUid, - payload, - url, - method: "PUT", +function reinstallApp( + flags: FlagInput, + orgUid: string, + type: string, + options: MarketPlaceOptions +) { + const { marketplaceSdk } = options; + return marketplaceSdk + .marketplace(orgUid) + .app(flags["app-uid"] as any) + .reinstall({ + targetUid: (flags["stack-api-key"] as any) || orgUid, + targetType: type as any, }); - return result; - } catch (err) { - throw err; - } } -function fetchStack(flags: FlagInput, options: CommonOptions) { +function fetchStack(flags: FlagInput, options: CommonOptions): Promise { const { managementSdk } = options; return managementSdk .stack({ api_key: flags["stack-api-key"] as any }) @@ -363,21 +351,14 @@ function setupConfig(configPath: string) { async function disconnectApp( flags: FlagInput, orgUid: string, - developerHubBaseUrl: string -) { - const appUid: any = flags["app-uid"]; - const url = `https://${developerHubBaseUrl}/manifests/${appUid}/hosting/disconnect`; - try { - const result = await apiRequestHandler({ - orgUid, - payload: { provider: "launch" }, - url, - method: "PATCH", - }); - return result; - } catch (err) { - throw err; - } + options: MarketPlaceOptions +): Promise { + const { marketplaceSdk } = options; + return marketplaceSdk + .marketplace(orgUid) + .app(flags["app-uid"] as any) + .hosting() + .disconnect({ provider: "launch" }); } function formatUrl(url: string): string {