Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Snyk] Upgrade @contentstack/cli-command from 1.2.9 to 1.2.12 #109

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 42 additions & 91 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/apps-cli",
"version": "1.0.1",
"version": "1.0.3",
"description": "App ClI",
"author": "Contentstack CLI",
"homepage": "https://github.com/contentstack/contentstack-apps-cli",
Expand All @@ -17,15 +17,15 @@
"/oclif.manifest.json"
],
"dependencies": {
"@contentstack/cli-command": "^1.2.9",
"@contentstack/cli-utilities": "^1.4.5",
"@contentstack/cli-command": "^1.2.12",
"@contentstack/cli-utilities": "^1.5.1",
"adm-zip": "^0.5.10",
"chalk": "^4.1.2",
"lodash": "^4.17.21",
"open": "^9.1.0",
"shelljs": "^0.8.5",
"tmp": "^0.2.1",
"winston": "^3.9.0"
"winston": "^3.10.0"
},
"devDependencies": {
"@oclif/test": "^2.0.3",
Expand Down
4 changes: 2 additions & 2 deletions src/commands/app/uninstall.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseCommand } from "./base-command";
import { flags } from "@contentstack/cli-utilities";
import { getOrg, getApp, fetchApp } from "../../util";
import { getOrg, fetchApp, getInstalledApps } from "../../util";
import { commonMsg, uninstallAppMsg } from "../../messages";
import { UninstallAppFactory } from "../../factories/uninstall-app-factory";

Expand Down Expand Up @@ -34,7 +34,7 @@ export default class Uninstall extends BaseCommand<typeof Uninstall> {

// fetch app details
if (!this.flags['app-uid']) {
app = await getApp(this.flags, this.sharedConfig.org, {managementSdk: this.managementAppSdk, log: this.log})
app = await getInstalledApps(this.flags, this.sharedConfig.org, {managementSdk: this.managementAppSdk, log: this.log})
} else {
app = await fetchApp(this.flags, this.sharedConfig.org, {managementSdk: this.managementAppSdk, log: this.log})
}
Expand Down
42 changes: 41 additions & 1 deletion src/util/common-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,45 @@ function uninstallApp(flags: FlagInput, orgUid: string, options: CommonOptions,
.uninstall()
}

async function fetchInstalledApps(flags: FlagInput, orgUid: string, options: CommonOptions) {
const { managementSdk, log } = options;
const apps = (await fetchApps(flags, orgUid, options)) || [];
let batchRequests = [];
// Make calls in batch. 10 requests per batch allowed.
while (apps.length) {
batchRequests.push(apps.splice(0, 10));
}
const results = [];
for (const batch of batchRequests) {
const promises = batch.map(async (app) => {
try {
const installations = await managementSdk
.organization(orgUid)
.app(app.uid)
.installation()
.findAll();
return installations.items.length ? installations.items : null;
}
catch (error) {
log("Unable to fetch installations.", "warn");
log(error, "error");
throw error;
}
});
results.push(await Promise.all(promises));
}
for (let i = batchRequests.length - 1; i >= 0; i--) {
const batchLength = batchRequests[i].length;
for (let j = batchLength - 1; j >= 0; j--) {
if (!results[i][j]) {
batchRequests[i].splice(j, 1);
results[i].splice(j, 1);
}
}
}
return batchRequests.flat();
}

export {
getOrganizations,
getOrgAppUiLocation,
Expand All @@ -189,5 +228,6 @@ export {
installApp,
getStacks,
fetchStack,
uninstallApp
uninstallApp,
fetchInstalledApps,
};
Loading