@contentstack/apps-cli 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,7 +20,7 @@ $ npm install -g @contentstack/apps-cli
20
20
  $ csdx COMMAND
21
21
  running command...
22
22
  $ csdx (--version|-v)
23
- @contentstack/apps-cli/1.0.0 darwin-arm64 node-v20.3.1
23
+ @contentstack/apps-cli/1.0.1 darwin-arm64 node-v20.3.1
24
24
  $ csdx --help [COMMAND]
25
25
  USAGE
26
26
  $ csdx COMMAND
@@ -66,7 +66,7 @@ EXAMPLES
66
66
  $ csdx app:create --name App-3 --app-type organization --org <UID> -d ./boilerplate -c ./external-config.json
67
67
  ```
68
68
 
69
- _See code: [src/commands/app/create.ts](https://github.com/contentstack/apps-cli/blob/v1.0.0/src/commands/app/create.ts)_
69
+ _See code: [src/commands/app/create.ts](https://github.com/contentstack/apps-cli/blob/v1.0.1/src/commands/app/create.ts)_
70
70
 
71
71
  ## `csdx app:delete`
72
72
 
@@ -91,7 +91,7 @@ EXAMPLES
91
91
  $ csdx app:delete --app-uid <value> --org <value> -d ./boilerplate
92
92
  ```
93
93
 
94
- _See code: [src/commands/app/delete.ts](https://github.com/contentstack/apps-cli/blob/v1.0.0/src/commands/app/delete.ts)_
94
+ _See code: [src/commands/app/delete.ts](https://github.com/contentstack/apps-cli/blob/v1.0.1/src/commands/app/delete.ts)_
95
95
 
96
96
  ## `csdx app:get`
97
97
 
@@ -121,7 +121,7 @@ EXAMPLES
121
121
  $ csdx app:get --org <value> --app-uid <value> --app-type organization
122
122
  ```
123
123
 
124
- _See code: [src/commands/app/get.ts](https://github.com/contentstack/apps-cli/blob/v1.0.0/src/commands/app/get.ts)_
124
+ _See code: [src/commands/app/get.ts](https://github.com/contentstack/apps-cli/blob/v1.0.1/src/commands/app/get.ts)_
125
125
 
126
126
  ## `csdx app:install`
127
127
 
@@ -147,7 +147,7 @@ EXAMPLES
147
147
  $ csdx app:install --org <UID> --app-uid <APP-UID-1> --stack-api-key <STACK-API-KEY-1>
148
148
  ```
149
149
 
150
- _See code: [src/commands/app/install.ts](https://github.com/contentstack/apps-cli/blob/v1.0.0/src/commands/app/install.ts)_
150
+ _See code: [src/commands/app/install.ts](https://github.com/contentstack/apps-cli/blob/v1.0.1/src/commands/app/install.ts)_
151
151
 
152
152
  ## `csdx app:uninstall`
153
153
 
@@ -155,12 +155,13 @@ Uninstall an app
155
155
 
156
156
  ```
157
157
  USAGE
158
- $ csdx app:uninstall [--org <value>] [--app-uid <value>] [--installation-uid <value>]
158
+ $ csdx app:uninstall [--org <value>] [--app-uid <value>] [--installation-uid <value>] [--uninstall-all]
159
159
 
160
160
  FLAGS
161
161
  --app-uid=<value> Provide the app UID
162
162
  --installation-uid=<value> Provide the installation ID of the app that needs to be uninstalled.
163
163
  --org=<value> Provide the organization UID
164
+ --uninstall-all Please select stacks from where the app must be uninstalled.
164
165
 
165
166
  DESCRIPTION
166
167
  Uninstall an app
@@ -173,7 +174,7 @@ EXAMPLES
173
174
  $ csdx app:uninstall --org <UID> --app-uid <APP-UID-1> --installation-uid <INSTALLATION-UID-1>
174
175
  ```
175
176
 
176
- _See code: [src/commands/app/uninstall.ts](https://github.com/contentstack/apps-cli/blob/v1.0.0/src/commands/app/uninstall.ts)_
177
+ _See code: [src/commands/app/uninstall.ts](https://github.com/contentstack/apps-cli/blob/v1.0.1/src/commands/app/uninstall.ts)_
177
178
 
178
179
  ## `csdx app:update`
179
180
 
@@ -196,5 +197,5 @@ EXAMPLES
196
197
  $ csdx app:update --app-manifest ./boilerplate/manifest.json
197
198
  ```
198
199
 
199
- _See code: [src/commands/app/update.ts](https://github.com/contentstack/apps-cli/blob/v1.0.0/src/commands/app/update.ts)_
200
+ _See code: [src/commands/app/update.ts](https://github.com/contentstack/apps-cli/blob/v1.0.1/src/commands/app/update.ts)_
200
201
  <!-- commandsstop -->
@@ -6,6 +6,7 @@ export default class Uninstall extends BaseCommand<typeof Uninstall> {
6
6
  static flags: {
7
7
  'app-uid': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
8
8
  'installation-uid': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
9
+ 'uninstall-all': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
9
10
  };
10
11
  run(): Promise<void>;
11
12
  }
@@ -4,6 +4,7 @@ const base_command_1 = require("./base-command");
4
4
  const cli_utilities_1 = require("@contentstack/cli-utilities");
5
5
  const util_1 = require("../../util");
6
6
  const messages_1 = require("../../messages");
7
+ const uninstall_app_factory_1 = require("../../factories/uninstall-app-factory");
7
8
  class Uninstall extends base_command_1.BaseCommand {
8
9
  async run() {
9
10
  try {
@@ -19,12 +20,9 @@ class Uninstall extends base_command_1.BaseCommand {
19
20
  }
20
21
  this.flags['app-uid'] = app === null || app === void 0 ? void 0 : app.uid;
21
22
  appType = app === null || app === void 0 ? void 0 : app['target_type'];
22
- // select installation uid to uninstall
23
- if (!this.flags['installation-uid']) {
24
- this.flags['installation-uid'] = await (0, util_1.getInstallation)(this.flags, this.sharedConfig.org, this.managementSdk, appType, { managementSdk: this.managementAppSdk, log: this.log });
25
- }
26
- // uninstall app
27
- await (0, util_1.uninstallApp)(this.flags, this.sharedConfig.org, { managementSdk: this.managementAppSdk, log: this.log });
23
+ const factory = new uninstall_app_factory_1.UninstallAppFactory();
24
+ const strategy = factory.getStrategyInstance(this.flags['uninstall-all']);
25
+ await strategy.run(this.flags, this.sharedConfig.org, this.managementSdk, { managementSdk: this.managementAppSdk, log: this.log }, appType);
28
26
  this.log(this.$t(messages_1.uninstallAppMsg.APP_UNINSTALLED, { app: (app === null || app === void 0 ? void 0 : app.name) || this.flags["app-uid"] }), "info");
29
27
  }
30
28
  catch (error) {
@@ -46,6 +44,9 @@ Uninstall.flags = {
46
44
  }),
47
45
  'installation-uid': cli_utilities_1.flags.string({
48
46
  description: messages_1.uninstallAppMsg.INSTALLATION_UID
47
+ }),
48
+ 'uninstall-all': cli_utilities_1.flags.boolean({
49
+ description: messages_1.uninstallAppMsg.UNINSTALL_ALL,
49
50
  })
50
51
  };
51
52
  exports.default = Uninstall;
@@ -0,0 +1,4 @@
1
+ import { UninstallApp } from "../interfaces/uninstall-app";
2
+ export declare class UninstallAppFactory {
3
+ getStrategyInstance(uninstallAll: boolean): UninstallApp;
4
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UninstallAppFactory = void 0;
4
+ const uninstall_all_1 = require("../strategies/uninstall-all");
5
+ const uninstall_selected_1 = require("../strategies/uninstall-selected");
6
+ class UninstallAppFactory {
7
+ getStrategyInstance(uninstallAll) {
8
+ let strategy;
9
+ if (uninstallAll) {
10
+ strategy = new uninstall_all_1.UninstallAll();
11
+ }
12
+ else {
13
+ strategy = new uninstall_selected_1.UninstallSelected();
14
+ }
15
+ return strategy;
16
+ }
17
+ }
18
+ exports.UninstallAppFactory = UninstallAppFactory;
@@ -0,0 +1,6 @@
1
+ import { ContentstackClient, FlagInput } from "@contentstack/cli-utilities";
2
+ import { CommonOptions } from "../util";
3
+ import { AppTarget } from "@contentstack/management/types/app/index";
4
+ export interface UninstallApp {
5
+ run(flags: FlagInput, org: string, managementSdk: ContentstackClient, options: CommonOptions, appType: AppTarget): Promise<void>;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -76,6 +76,7 @@ declare const uninstallAppMsg: {
76
76
  NO_INSTALLATIONS_FOUND: string;
77
77
  APP_UNINSTALLED: string;
78
78
  UNINSTALLING_APP: string;
79
+ UNINSTALL_ALL: string;
79
80
  };
80
81
  declare const messages: typeof errors & typeof commonMsg & typeof appCreate & typeof appUpdate & typeof getApp & typeof deleteAppMsg & typeof installAppMsg & typeof uninstallAppMsg;
81
82
  declare const $t: (msg: string, args: Record<string, string>) => string;
@@ -85,7 +85,8 @@ const uninstallAppMsg = {
85
85
  INSTALLATION_UID: "Provide the installation ID of the app that needs to be uninstalled.",
86
86
  NO_INSTALLATIONS_FOUND: "Cannot find any installations for this app.",
87
87
  APP_UNINSTALLED: "{app} uninstalled successfully.",
88
- UNINSTALLING_APP: "Uninstalling app from {type}..."
88
+ UNINSTALLING_APP: "Uninstalling app from {type}...",
89
+ UNINSTALL_ALL: "Please select stacks from where the app must be uninstalled.",
89
90
  };
90
91
  exports.uninstallAppMsg = uninstallAppMsg;
91
92
  const messages = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, errors), commonMsg), appCreate), appUpdate), getApp), deleteAppMsg), installAppMsg), uninstallAppMsg);
@@ -0,0 +1,8 @@
1
+ import { ContentstackClient, FlagInput } from "@contentstack/cli-utilities";
2
+ import { UninstallApp } from "../interfaces/uninstall-app";
3
+ import { CommonOptions } from "../util";
4
+ import { AppTarget } from "@contentstack/management/types/app/index";
5
+ export declare class UninstallAll implements UninstallApp {
6
+ run(flags: FlagInput, org: string, managementSdk: ContentstackClient, options: CommonOptions, appType: AppTarget): Promise<void>;
7
+ getInstallations(flags: FlagInput, org: string, managementSdk: ContentstackClient, options: CommonOptions, appType: AppTarget): Promise<string[]>;
8
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UninstallAll = void 0;
4
+ const util_1 = require("../util");
5
+ class UninstallAll {
6
+ async run(flags, org, managementSdk, options, appType) {
7
+ // get all installation uids to uninstall
8
+ const installationUids = await this.getInstallations(flags, org, managementSdk, options, appType);
9
+ for (const installationUid of installationUids) {
10
+ await (0, util_1.uninstallApp)(flags, org, options, installationUid);
11
+ }
12
+ }
13
+ async getInstallations(flags, org, managementSdk, options, appType) {
14
+ let installationUids = await (0, util_1.getInstallation)(flags, org, managementSdk, appType, options, true);
15
+ return installationUids.split(',');
16
+ }
17
+ }
18
+ exports.UninstallAll = UninstallAll;
@@ -0,0 +1,8 @@
1
+ import { ContentstackClient, FlagInput } from "@contentstack/cli-utilities";
2
+ import { UninstallApp } from "../interfaces/uninstall-app";
3
+ import { CommonOptions } from "../util";
4
+ import { AppTarget } from "@contentstack/management/types/app/index";
5
+ export declare class UninstallSelected implements UninstallApp {
6
+ run(flags: FlagInput, org: string, managementSdk: ContentstackClient, options: CommonOptions, appType: AppTarget): Promise<void>;
7
+ getInstallations(flags: FlagInput, org: string, managementSdk: ContentstackClient, options: CommonOptions, appType: AppTarget): Promise<string[]>;
8
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UninstallSelected = void 0;
4
+ const util_1 = require("../util");
5
+ class UninstallSelected {
6
+ async run(flags, org, managementSdk, options, appType) {
7
+ // select installation uid to uninstall
8
+ const installationUids = await this.getInstallations(flags, org, managementSdk, options, appType);
9
+ for (const installationUid of installationUids) {
10
+ await (0, util_1.uninstallApp)(flags, org, options, installationUid);
11
+ }
12
+ }
13
+ async getInstallations(flags, org, managementSdk, options, appType) {
14
+ let installationUids = flags['installation-uid'];
15
+ if (!installationUids) {
16
+ installationUids = await (0, util_1.getInstallation)(flags, org, managementSdk, appType, options);
17
+ }
18
+ return installationUids.split(',');
19
+ }
20
+ }
21
+ exports.UninstallSelected = UninstallSelected;
@@ -14,5 +14,5 @@ declare function deleteApp(flags: FlagInput, orgUid: string, options: CommonOpti
14
14
  declare function installApp(flags: FlagInput, orgUid: string, type: string, options: CommonOptions): Promise<import("@contentstack/management/types/app/installation").Installation>;
15
15
  declare function fetchStack(flags: FlagInput, options: CommonOptions): Promise<import("@contentstack/management/types/stack").Stack>;
16
16
  declare function getStacks(options: CommonOptions, orgUid: string, skip?: number, stacks?: Stack[]): Promise<Stack[]>;
17
- declare function uninstallApp(flags: FlagInput, orgUid: string, options: CommonOptions): Promise<import("@contentstack/management/types/utility/fields").AnyProperty>;
17
+ declare function uninstallApp(flags: FlagInput, orgUid: string, options: CommonOptions, installationUid: string): Promise<import("@contentstack/management/types/utility/fields").AnyProperty>;
18
18
  export { getOrganizations, getOrgAppUiLocation, fetchApps, fetchApp, fetchAppInstallations, deleteApp, installApp, getStacks, fetchStack, uninstallApp };
@@ -135,10 +135,9 @@ async function getStacks(options, orgUid, skip = 0, stacks = []) {
135
135
  return stacks;
136
136
  }
137
137
  exports.getStacks = getStacks;
138
- function uninstallApp(flags, orgUid, options) {
138
+ function uninstallApp(flags, orgUid, options, installationUid) {
139
139
  const { managementSdk } = options;
140
140
  const app = flags['app-uid'];
141
- const installationUid = flags['installation-uid'];
142
141
  return managementSdk
143
142
  .organization(orgUid)
144
143
  .app(app)
@@ -30,5 +30,5 @@ declare function getApp(flags: FlagInput, orgUid: string, options: CommonOptions
30
30
  */
31
31
  declare function getDeveloperHubUrl(): Promise<string>;
32
32
  declare function getStack(orgUid: string, options: CommonOptions): Promise<Record<string, any> | undefined>;
33
- declare function getInstallation(flags: FlagInput, orgUid: string, managementSdkForStacks: ContentstackClient, appType: AppTarget, options: CommonOptions): Promise<string>;
33
+ declare function getInstallation(flags: FlagInput, orgUid: string, managementSdkForStacks: ContentstackClient, appType: AppTarget, options: CommonOptions, uninstallAll?: boolean): Promise<string>;
34
34
  export { getOrg, getAppName, getDirName, getDeveloperHubUrl, getApp, getStack, getInstallation };
@@ -145,7 +145,7 @@ async function getStack(orgUid, options) {
145
145
  return selectedStack;
146
146
  }
147
147
  exports.getStack = getStack;
148
- async function getInstallation(flags, orgUid, managementSdkForStacks, appType, options) {
148
+ async function getInstallation(flags, orgUid, managementSdkForStacks, appType, options, uninstallAll) {
149
149
  var _a;
150
150
  const { log } = options;
151
151
  if (appType === 'stack') {
@@ -164,13 +164,18 @@ async function getInstallation(flags, orgUid, managementSdkForStacks, appType, o
164
164
  cli_utilities_1.cliux.loader("done");
165
165
  const stacks = await (0, common_utils_1.getStacks)({ managementSdk: managementSdkForStacks, log: options.log }, orgUid);
166
166
  installations = populateMissingDataInInstallations(installations, stacks);
167
- selectedInstallation = await cli_utilities_1.cliux
167
+ // To support uninstall all flag
168
+ if (uninstallAll) {
169
+ return installations.map(installation => installation.uid).join(',');
170
+ }
171
+ let _selectedInstallation = await cli_utilities_1.cliux
168
172
  .inquire({
169
- type: 'search-list',
173
+ type: 'checkbox',
170
174
  name: 'appInstallation',
171
175
  choices: installations,
172
176
  message: messages_1.default.CHOOSE_AN_INSTALLATION
173
177
  });
178
+ selectedInstallation = _selectedInstallation.join(',');
174
179
  }
175
180
  else {
176
181
  // as this is an organization app, and it is supposed to only be installed on the source organization
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/apps-cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "App ClI",
5
5
  "author": "Contentstack CLI",
6
6
  "homepage": "https://github.com/contentstack/contentstack-apps-cli",