Skip to content

Commit bf6314d

Browse files
Merge pull request #282 from contentstack/fix/dx-668-replace-reinstall-call
updated reinstall and deploy with marketplace calls
2 parents 02ce60c + 515bb4a commit bf6314d

File tree

3 files changed

+37
-56
lines changed

3 files changed

+37
-56
lines changed

src/commands/app/deploy.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default class Deploy extends AppCLIBaseCommand {
7070
const apolloClient = await this.getApolloClient();
7171
const projects = await getProjects(apolloClient);
7272
await this.handleAppDisconnect(projects);
73-
73+
7474
flags["hosting-type"] = flags["hosting-type"] || (await getHostingType());
7575
const updateHostingPayload: UpdateHostingParams = {
7676
provider: "external",
@@ -89,14 +89,18 @@ export default class Deploy extends AppCLIBaseCommand {
8989
config["name"] = config["name"] || app?.name;
9090
this.flags["launch-project"] =
9191
this.flags["launch-project"] || (await askProjectType());
92-
await this.handleHostingWithLaunch(config, updateHostingPayload, projects);
92+
await this.handleHostingWithLaunch(
93+
config,
94+
updateHostingPayload,
95+
projects
96+
);
9397
break;
9498
default:
9599
this.log("Please provide a valid Hosting Type.", "error");
96100
return;
97101
}
98102

99-
if(this.flags["app-uid"]){
103+
if (this.flags["app-uid"]) {
100104
await updateApp(
101105
flags,
102106
this.sharedConfig.org,
@@ -284,11 +288,10 @@ export default class Deploy extends AppCLIBaseCommand {
284288
if (!this.flags["yes"]) {
285289
throw new Error(deployAppMsg.APP_UPDATE_TERMINATION_MSG);
286290
}
287-
await disconnectApp(
288-
this.flags,
289-
this.sharedConfig.org,
290-
this.developerHubBaseUrl
291-
);
291+
await disconnectApp(this.flags, this.sharedConfig.org, {
292+
marketplaceSdk: this.marketplaceAppSdk,
293+
log: this.log,
294+
});
292295
}
293296
}
294-
}
297+
}

src/commands/app/reinstall.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,9 @@ export default class Reinstall extends AppCLIBaseCommand {
102102
}),
103103
"info"
104104
);
105-
await reinstallApp({
106-
flags: this.flags,
107-
type: appType,
108-
developerHubBaseUrl: this.developerHubBaseUrl,
109-
orgUid: this.sharedConfig.org,
110-
manifestUid: this.flags["app-uid"],
105+
await reinstallApp(this.flags, this.sharedConfig.org, appType, {
106+
marketplaceSdk: this.marketplaceAppSdk,
107+
log: this.log,
111108
});
112109
this.log(
113110
$t(reinstallAppMsg.APP_REINSTALLED_SUCCESSFULLY, {

src/util/common-utils.ts

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
HttpClient,
1111
} from "@contentstack/cli-utilities";
1212
import { projectsQuery } from "../graphql/queries";
13-
import { apiRequestHandler } from "./api-request-handler";
1413
import {
1514
AppLocation,
1615
Extension,
@@ -166,34 +165,23 @@ function installApp(
166165
});
167166
}
168167

169-
async function reinstallApp(params: {
170-
flags: FlagInput;
171-
type: string;
172-
developerHubBaseUrl: string;
173-
orgUid: string;
174-
manifestUid: string;
175-
}): Promise<void> {
176-
const { type, developerHubBaseUrl, flags, orgUid, manifestUid } = params;
177-
const payload = {
178-
target_type: type,
179-
target_uid: (flags["stack-api-key"] as any) || orgUid,
180-
};
181-
182-
const url = `https://${developerHubBaseUrl}/manifests/${manifestUid}/reinstall`;
183-
try {
184-
const result = await apiRequestHandler({
185-
orgUid,
186-
payload,
187-
url,
188-
method: "PUT",
168+
function reinstallApp(
169+
flags: FlagInput,
170+
orgUid: string,
171+
type: string,
172+
options: MarketPlaceOptions
173+
) {
174+
const { marketplaceSdk } = options;
175+
return marketplaceSdk
176+
.marketplace(orgUid)
177+
.app(flags["app-uid"] as any)
178+
.reinstall({
179+
targetUid: (flags["stack-api-key"] as any) || orgUid,
180+
targetType: type as any,
189181
});
190-
return result;
191-
} catch (err) {
192-
throw err;
193-
}
194182
}
195183

196-
function fetchStack(flags: FlagInput, options: CommonOptions) {
184+
function fetchStack(flags: FlagInput, options: CommonOptions): Promise<any> {
197185
const { managementSdk } = options;
198186
return managementSdk
199187
.stack({ api_key: flags["stack-api-key"] as any })
@@ -363,21 +351,14 @@ function setupConfig(configPath: string) {
363351
async function disconnectApp(
364352
flags: FlagInput,
365353
orgUid: string,
366-
developerHubBaseUrl: string
367-
) {
368-
const appUid: any = flags["app-uid"];
369-
const url = `https://${developerHubBaseUrl}/manifests/${appUid}/hosting/disconnect`;
370-
try {
371-
const result = await apiRequestHandler({
372-
orgUid,
373-
payload: { provider: "launch" },
374-
url,
375-
method: "PATCH",
376-
});
377-
return result;
378-
} catch (err) {
379-
throw err;
380-
}
354+
options: MarketPlaceOptions
355+
): Promise<any> {
356+
const { marketplaceSdk } = options;
357+
return marketplaceSdk
358+
.marketplace(orgUid)
359+
.app(flags["app-uid"] as any)
360+
.hosting()
361+
.disconnect({ provider: "launch" });
381362
}
382363

383364
function formatUrl(url: string): string {

0 commit comments

Comments
 (0)