Skip to content

Commit ade5acd

Browse files
feat: get and update command api calls
1 parent 21adf59 commit ade5acd

File tree

5 files changed

+27
-26
lines changed

5 files changed

+27
-26
lines changed

src/commands/app/get.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ export default class Get extends AppCLIBaseCommand {
4141

4242
if (!this.flags["app-uid"]) {
4343
appData = await getApp(this.flags, this.sharedConfig.org, {
44-
managementSdk: this.managementAppSdk,
44+
marketplaceSdk: this.marketplaceAppSdk,
4545
log: this.log,
4646
});
4747
} else {
4848
appData = await fetchApp(this.flags, this.sharedConfig.org, {
49-
managementSdk: this.managementAppSdk,
49+
marketplaceSdk: this.marketplaceAppSdk,
5050
log: this.log,
5151
});
5252
}

src/commands/app/update.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export default class Update extends AppCLIBaseCommand {
121121

122122
if (!this.manifestData.uid) {
123123
appData = (await getApp(this.flags, this.orgUid, {
124-
managementSdk: this.managementAppSdk,
124+
marketplaceSdk: this.marketplaceAppSdk,
125125
log: this.log,
126126
})) as App;
127127
this.manifestData.uid = appData.uid;
@@ -130,7 +130,7 @@ export default class Update extends AppCLIBaseCommand {
130130
{ "app-uid": this.manifestData.uid as any },
131131
this.orgUid,
132132
{
133-
managementSdk: this.managementAppSdk,
133+
marketplaceSdk: this.marketplaceAppSdk,
134134
log: this.log,
135135
}
136136
);

src/util/common-utils.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,14 @@ function getOrgAppUiLocation(): Extension[] {
5454
async function fetchApps(
5555
flags: FlagInput,
5656
orgUid: string,
57-
options: CommonOptions,
57+
options: MarketPlaceOptions,
5858
skip = 0,
5959
apps: Record<string, any>[] = []
6060
): Promise<Record<string, any>[]> {
61-
const { log, managementSdk } = options;
62-
const response = await managementSdk
63-
.organization(orgUid)
64-
.app()
65-
.findAll({
61+
const { log, marketplaceSdk } = options;
62+
const response = await marketplaceSdk
63+
.marketplace(orgUid)
64+
.findAllApps({
6665
limit: 50,
6766
asc: "name",
6867
include_count: true,
@@ -85,11 +84,11 @@ async function fetchApps(
8584
return apps;
8685
}
8786

88-
function fetchApp(flags: FlagInput, orgUid: string, options: CommonOptions) {
89-
const { managementSdk } = options;
87+
function fetchApp(flags: FlagInput, orgUid: string, options: MarketPlaceOptions) {
88+
const { marketplaceSdk } = options;
9089
const app: any = flags["app-uid"];
91-
return managementSdk
92-
.organization(orgUid)
90+
return marketplaceSdk
91+
.marketplace(orgUid)
9392
.app(app as string)
9493
.fetch();
9594
}
@@ -218,9 +217,9 @@ function uninstallApp(
218217
async function fetchInstalledApps(
219218
flags: FlagInput,
220219
orgUid: string,
221-
options: CommonOptions
220+
options: MarketPlaceOptions
222221
) {
223-
const { managementSdk, log } = options;
222+
const { marketplaceSdk, log } = options;
224223
const apps = (await fetchApps(flags, orgUid, options)) || [];
225224
let batchRequests = [];
226225
// Make calls in batch. 10 requests per batch allowed.
@@ -231,11 +230,10 @@ async function fetchInstalledApps(
231230
for (const batch of batchRequests) {
232231
const promises = batch.map(async (app) => {
233232
try {
234-
const installations = await managementSdk
235-
.organization(orgUid)
233+
const installations = await marketplaceSdk
234+
.marketplace(orgUid)
236235
.app(app.uid)
237-
.installation()
238-
.findAll();
236+
.listInstallations();
239237
return installations.items.length ? installations.items : null;
240238
} catch (error) {
241239
log("Unable to fetch installations.", "warn");

src/util/inquirer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
fetchInstalledApps,
2222
fetchApps,
2323
sanitizePath,
24+
MarketPlaceOptions,
2425
} from "./common-utils";
2526

2627
/**
@@ -106,7 +107,7 @@ async function getOrg(flags: FlagInput, options: CommonOptions) {
106107
async function getApp(
107108
flags: FlagInput,
108109
orgUid: string,
109-
options: CommonOptions
110+
options: MarketPlaceOptions
110111
): Promise<Record<string, any> | undefined> {
111112
cliux.loader("Loading Apps");
112113
const apps = await fetchApps(flags, orgUid, options);
@@ -131,7 +132,7 @@ async function getApp(
131132
async function getInstalledApps(
132133
flags: FlagInput,
133134
orgUid: string,
134-
options: CommonOptions
135+
options: MarketPlaceOptions
135136
): Promise<Record<string, any> | undefined> {
136137
cliux.loader("Loading Apps");
137138
const apps = await fetchInstalledApps(flags, orgUid, options);

test/unit/util/common-utils.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import {
44
cliux,
55
configHandler,
66
ContentstackClient,
7+
ContentstackMarketplaceClient,
78
managementSDKClient,
9+
marketplaceSDKClient,
810
} from "@contentstack/cli-utilities";
911

1012
import { LogFn } from "../../../src/types";
@@ -20,13 +22,13 @@ const developerHubBaseUrl = getDeveloperHubUrl();
2022
describe("common utils", () => {
2123
const log: LogFn = () => {};
2224
let managementSdk: ContentstackClient;
23-
let managementAppSdk: ContentstackClient;
25+
let marketplaceAppSdk: ContentstackMarketplaceClient;
2426

2527
before(async () => {
2628
managementSdk = await managementSDKClient({
2729
host: region.cma.replace("https://", ""),
2830
});
29-
managementAppSdk = await managementSDKClient({
31+
marketplaceAppSdk = await marketplaceSDKClient({
3032
host: developerHubBaseUrl,
3133
});
3234
});
@@ -109,7 +111,7 @@ describe("common utils", () => {
109111
"test-uid-1",
110112
{
111113
log,
112-
managementSdk: managementAppSdk,
114+
marketplaceSdk: marketplaceAppSdk,
113115
}
114116
);
115117
expect(app.uid).to.equal(mock.apps[0].uid);
@@ -130,7 +132,7 @@ describe("common utils", () => {
130132
async () =>
131133
await fetchApps({ "app-type": "stack" as any }, "test-uid-1", {
132134
log,
133-
managementSdk: managementAppSdk,
135+
marketplaceSdk: marketplaceAppSdk,
134136
})
135137
)
136138
.catch(({ message }) => expect(message).to.contains('"status":400'))

0 commit comments

Comments
 (0)