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

DX- 345 | removed static url #234

Merged
merged 2 commits into from
May 29, 2024
Merged
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
10 changes: 5 additions & 5 deletions src/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
this.registerConfig();

this.developerHubBaseUrl =
this.sharedConfig.developerHubBaseUrl || (await getDeveloperHubUrl());
this.sharedConfig.developerHubBaseUrl || getDeveloperHubUrl();
await this.initCmaSDK();

// Init logger
const logger = new Logger(this.sharedConfig);
this.log = logger.log.bind(logger);
Expand Down Expand Up @@ -164,9 +164,9 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
validateRegionAndAuth() {
if (this.region) {
if (!isAuthenticated()) {
this.log(this.messages.CLI_APP_CLI_LOGIN_FAILED, "error");
this.exit(1);
}
this.log(this.messages.CLI_APP_CLI_LOGIN_FAILED, "error");
this.exit(1);
}
}
}
}
10 changes: 0 additions & 10 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ const config = {
manifestPath: resolve(__dirname, "manifest.json"),
boilerplateName: "marketplace-app-boilerplate-main",
developerHubBaseUrl: "",
developerHubUrls: {
// NOTE CDA url used as developer-hub url mapper to avoid conflict if user used any custom name
"https://api.contentstack.io": "developerhub-api.contentstack.com",
"https://eu-api.contentstack.com": "eu-developerhub-api.contentstack.com",
"https://azure-na-api.contentstack.com":
"azure-na-developerhub-api.contentstack.com",
"https://azure-eu-api.contentstack.com":
"azure-eu-developerhub-api.contentstack.com",
"https://gcp-na-api.contentstack.com": "gcp-na-developerhub-api.contentstack.com",
},
appBoilerplateGithubUrl:
"https://codeload.github.com/contentstack/marketplace-app-boilerplate/zip/refs/heads/main",
defaultAppFileName: "manifest",
Expand Down
2 changes: 1 addition & 1 deletion src/util/inquirer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ async function getInstalledApps(
*
* @return {*} {Promise<string>}
*/
async function getDeveloperHubUrl(): Promise<string> {
function getDeveloperHubUrl(): string {
const { cma } = configHandler.get("region") || {};
let developerHubBaseUrl = cma.replace("api", "developerhub-api");

Expand Down
5 changes: 2 additions & 3 deletions test/unit/commands/app/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ import config from "../../../../src/config";
import messages from "../../../../src/messages";
import * as mock from "../../mock/common.mock.json";
import manifestData from "../../../../src/config/manifest.json";
import { getDeveloperHubUrl } from "../../../../src/util/inquirer";

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

describe("app:create", () => {
beforeEach(() => {
Expand Down
6 changes: 2 additions & 4 deletions test/unit/commands/app/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import { test, expect } from "@oclif/test";
import { cliux, configHandler, ux } from "@contentstack/cli-utilities";
import * as mock from "../../mock/common.mock.json"

import config from "../../../../src/config";
import messages, {$t} from "../../../../src/messages";
import { getDeveloperHubUrl } from "../../../../src/util/inquirer";

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

describe("app:delete", () => {
describe("app:delete with --org and --app-uid flags", () => {
Expand Down
6 changes: 3 additions & 3 deletions test/unit/commands/app/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import * as mock from "../../mock/common.mock.json";
import manifestData from "../../config/manifest.json";
import messages, { $t } from "../../../../src/messages";
import * as commonUtils from "../../../../src/util/common-utils";
import { getDeveloperHubUrl } from "../../../../src/util/inquirer";

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


describe("app:get", () => {
describe("Get app manifest", () => {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/commands/app/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import {expect, test} from "@oclif/test";

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

import config from "../../../../src/config";
import messages, { $t } from "../../../../src/messages";
import { getDeveloperHubUrl } from "../../../../src/util/inquirer";

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

describe("app:install", () => {
describe("Install an app on organization", () => {
Expand Down
6 changes: 4 additions & 2 deletions test/unit/commands/app/reinstall.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import { ux, cliux, configHandler } from "@contentstack/cli-utilities";
import { expect, test } from "@oclif/test";
import * as mock from "../../mock/common.mock.json";
import messages, { $t } from "../../../../src/messages";
import { getDeveloperHubUrl } from "../../../../lib/util/inquirer";

const region: { cma: string; cda: string; name: string } =
configHandler.get("region");
const developerHubBaseUrl = configHandler.get("developerHubBaseUrl");
const developerHubBaseUrl = getDeveloperHubUrl();

describe("app:reinstall", () => {
describe("Reinstall an app on a stack", () => {
test
.stdout({ print: true })
.stdout({ print: process.env.PRINT === "true" || false })
.stub(ux.action, "stop", () => {})
.stub(ux.action, "start", () => {})
.stub(cliux, "inquire", async (...args: any) => {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/commands/app/uninstall.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { expect, test } from "@oclif/test";

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

import config from "../../../../src/config"
import messages, {$t} from "../../../../src/messages";
import { getDeveloperHubUrl } from "../../../../src/util/inquirer";

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

describe("app:uninstall", () => {
describe("Uninstall an app from organization", () => {
Expand Down
6 changes: 2 additions & 4 deletions test/unit/commands/app/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import { PassThrough } from "stream";
import { expect, test } from "@oclif/test";
import { cliux, ux, configHandler } from "@contentstack/cli-utilities";

import config from "../../../../src/config";
import messages from "../../../../src/messages";
import * as mock from "../../mock/common.mock.json";
import manifestData from "../../config/manifest.json";
import { getDeveloperHubUrl } from "../../../../src/util/inquirer";

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

describe("app:update", () => {
describe("Update app with `--app-manifest` flag", () => {
Expand Down
7 changes: 3 additions & 4 deletions test/unit/util/common-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ import {
managementSDKClient,
} from "@contentstack/cli-utilities";

import config from "../../../src/config";
import { LogFn } from "../../../src/types";
import * as mock from "../mock/common.mock.json";
import { fetchApps, getOrganizations } from "../../../src/util/common-utils";
import { getDeveloperHubUrl } from "../../../src/util/inquirer";

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


describe("common utils", () => {
const log: LogFn = () => {};
Expand Down
Loading