Skip to content

Commit 316581d

Browse files
Merge pull request #234 from contentstack/fix/DX-345-remove-static-url
DX- 345 | removed static url
2 parents 82a6acd + 065e56b commit 316581d

File tree

11 files changed

+26
-40
lines changed

11 files changed

+26
-40
lines changed

src/base-command.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
7070
this.registerConfig();
7171

7272
this.developerHubBaseUrl =
73-
this.sharedConfig.developerHubBaseUrl || (await getDeveloperHubUrl());
73+
this.sharedConfig.developerHubBaseUrl || getDeveloperHubUrl();
7474
await this.initCmaSDK();
75-
75+
7676
// Init logger
7777
const logger = new Logger(this.sharedConfig);
7878
this.log = logger.log.bind(logger);
@@ -164,9 +164,9 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
164164
validateRegionAndAuth() {
165165
if (this.region) {
166166
if (!isAuthenticated()) {
167-
this.log(this.messages.CLI_APP_CLI_LOGIN_FAILED, "error");
168-
this.exit(1);
169-
}
167+
this.log(this.messages.CLI_APP_CLI_LOGIN_FAILED, "error");
168+
this.exit(1);
169+
}
170170
}
171171
}
172172
}

src/config/index.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@ const config = {
55
manifestPath: resolve(__dirname, "manifest.json"),
66
boilerplateName: "marketplace-app-boilerplate-main",
77
developerHubBaseUrl: "",
8-
developerHubUrls: {
9-
// NOTE CDA url used as developer-hub url mapper to avoid conflict if user used any custom name
10-
"https://api.contentstack.io": "developerhub-api.contentstack.com",
11-
"https://eu-api.contentstack.com": "eu-developerhub-api.contentstack.com",
12-
"https://azure-na-api.contentstack.com":
13-
"azure-na-developerhub-api.contentstack.com",
14-
"https://azure-eu-api.contentstack.com":
15-
"azure-eu-developerhub-api.contentstack.com",
16-
"https://gcp-na-api.contentstack.com": "gcp-na-developerhub-api.contentstack.com",
17-
},
188
appBoilerplateGithubUrl:
199
"https://codeload.github.com/contentstack/marketplace-app-boilerplate/zip/refs/heads/main",
2010
defaultAppFileName: "manifest",

src/util/inquirer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ async function getInstalledApps(
158158
*
159159
* @return {*} {Promise<string>}
160160
*/
161-
async function getDeveloperHubUrl(): Promise<string> {
161+
function getDeveloperHubUrl(): string {
162162
const { cma } = configHandler.get("region") || {};
163163
let developerHubBaseUrl = cma.replace("api", "developerhub-api");
164164

test/unit/commands/app/create.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ import config from "../../../../src/config";
1212
import messages from "../../../../src/messages";
1313
import * as mock from "../../mock/common.mock.json";
1414
import manifestData from "../../../../src/config/manifest.json";
15+
import { getDeveloperHubUrl } from "../../../../src/util/inquirer";
1516

1617
const { origin, pathname } = new URL(config.appBoilerplateGithubUrl);
1718
const zipPath = join(process.cwd(), "test", "unit", "mock", "boilerplate.zip");
1819
const region: { cma: string; name: string; cda: string } =
1920
configHandler.get("region");
20-
const developerHubBaseUrl = (config.developerHubUrls as Record<string, any>)[
21-
region.cma
22-
];
21+
const developerHubBaseUrl = getDeveloperHubUrl();
2322

2423
describe("app:create", () => {
2524
beforeEach(() => {

test/unit/commands/app/delete.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ import { test, expect } from "@oclif/test";
22
import { cliux, configHandler, ux } from "@contentstack/cli-utilities";
33
import * as mock from "../../mock/common.mock.json"
44

5-
import config from "../../../../src/config";
65
import messages, {$t} from "../../../../src/messages";
6+
import { getDeveloperHubUrl } from "../../../../src/util/inquirer";
77

88
const region: { cma: string; name: string; cda: string } =
99
configHandler.get("region");
10-
const developerHubBaseUrl = (config.developerHubUrls as Record<string, any>)[
11-
region.cma
12-
];
10+
const developerHubBaseUrl = getDeveloperHubUrl();
1311

1412
describe("app:delete", () => {
1513
describe("app:delete with --org and --app-uid flags", () => {

test/unit/commands/app/get.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import * as mock from "../../mock/common.mock.json";
99
import manifestData from "../../config/manifest.json";
1010
import messages, { $t } from "../../../../src/messages";
1111
import * as commonUtils from "../../../../src/util/common-utils";
12+
import { getDeveloperHubUrl } from "../../../../src/util/inquirer";
1213

1314
const region: { cma: string; name: string; cda: string } =
1415
configHandler.get("region");
15-
const developerHubBaseUrl = (config.developerHubUrls as Record<string, any>)[
16-
region.cma
17-
];
16+
const developerHubBaseUrl = getDeveloperHubUrl();
17+
1818

1919
describe("app:get", () => {
2020
describe("Get app manifest", () => {

test/unit/commands/app/install.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import {expect, test} from "@oclif/test";
33

44
import * as mock from "../../mock/common.mock.json"
55

6-
import config from "../../../../src/config";
76
import messages, { $t } from "../../../../src/messages";
7+
import { getDeveloperHubUrl } from "../../../../src/util/inquirer";
88

99
const region: { cma: string, cda: string, name: string } = configHandler.get("region");
10-
const developerHubBaseUrl = (config.developerHubUrls as Record<string, any>)[region.cma];
10+
const developerHubBaseUrl = getDeveloperHubUrl();
1111

1212
describe("app:install", () => {
1313
describe("Install an app on organization", () => {

test/unit/commands/app/reinstall.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import { ux, cliux, configHandler } from "@contentstack/cli-utilities";
22
import { expect, test } from "@oclif/test";
33
import * as mock from "../../mock/common.mock.json";
44
import messages, { $t } from "../../../../src/messages";
5+
import { getDeveloperHubUrl } from "../../../../lib/util/inquirer";
56

67
const region: { cma: string; cda: string; name: string } =
78
configHandler.get("region");
8-
const developerHubBaseUrl = configHandler.get("developerHubBaseUrl");
9+
const developerHubBaseUrl = getDeveloperHubUrl();
10+
911
describe("app:reinstall", () => {
1012
describe("Reinstall an app on a stack", () => {
1113
test
12-
.stdout({ print: true })
14+
.stdout({ print: process.env.PRINT === "true" || false })
1315
.stub(ux.action, "stop", () => {})
1416
.stub(ux.action, "start", () => {})
1517
.stub(cliux, "inquire", async (...args: any) => {

test/unit/commands/app/uninstall.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { expect, test } from "@oclif/test";
33

44
import * as mock from "../../mock/common.mock.json"
55

6-
import config from "../../../../src/config"
76
import messages, {$t} from "../../../../src/messages";
7+
import { getDeveloperHubUrl } from "../../../../src/util/inquirer";
88

99
const region: { cma: string, cda: string, name: string } = configHandler.get("region");
10-
const developerHubBaseUrl = (config.developerHubUrls as Record<string, any>)[region.cma];
10+
const developerHubBaseUrl = getDeveloperHubUrl();
1111

1212
describe("app:uninstall", () => {
1313
describe("Uninstall an app from organization", () => {

test/unit/commands/app/update.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ import { PassThrough } from "stream";
44
import { expect, test } from "@oclif/test";
55
import { cliux, ux, configHandler } from "@contentstack/cli-utilities";
66

7-
import config from "../../../../src/config";
87
import messages from "../../../../src/messages";
98
import * as mock from "../../mock/common.mock.json";
109
import manifestData from "../../config/manifest.json";
10+
import { getDeveloperHubUrl } from "../../../../src/util/inquirer";
1111

1212
const region: { cma: string; name: string; cda: string } =
1313
configHandler.get("region");
14-
const developerHubBaseUrl = (config.developerHubUrls as Record<string, any>)[
15-
region.cma
16-
];
14+
const developerHubBaseUrl = getDeveloperHubUrl();
1715

1816
describe("app:update", () => {
1917
describe("Update app with `--app-manifest` flag", () => {

0 commit comments

Comments
 (0)