Skip to content
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
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion packages/contentstack-utilities/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/cli-utilities",
"version": "1.14.1",
"version": "1.14.2",
"description": "Utilities for contentstack projects",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
25 changes: 24 additions & 1 deletion packages/contentstack-utilities/src/auth-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ class AuthHandler {
private oauthHandler: any;
private managementAPIClient: ContentstackClient;
private isRefreshingToken: boolean = false; // Flag to track if a refresh operation is in progress
private cmaHost: string;

set host(contentStackHost) {
this._host = contentStackHost;
// Update cmaHost when host is set
this.cmaHost = this.getCmaHost();
}

constructor() {
Expand Down Expand Up @@ -76,6 +79,24 @@ class AuthHandler {
this.authorisationTypeKeyName,
],
};
this.cmaHost = this.getCmaHost();
}

private getCmaHost(): string {
if (this._host) {
return this._host;
}

const cma = configHandler.get('region')?.cma;
if (cma && cma.startsWith('http')) {
try {
const u = new URL(cma);
if (u.host) return u.host;
} catch (error) {
// If URL parsing fails, return the original cma value
}
}
return cma;
}
initLog() {
this.logger = new LoggerService(process.cwd(), 'cli-log');
Expand All @@ -91,7 +112,9 @@ class AuthHandler {
}

async initSDK() {
this.managementAPIClient = await managementSDKClient({ host: this._host });
// Ensure we have a valid host for the SDK initialization
const host = this._host || this.getCmaHost();
this.managementAPIClient = await managementSDKClient({ host });
this.oauthHandler = this.managementAPIClient.oauth({
appId: this.OAuthAppId,
clientId: this.OAuthClientId,
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@contentstack/cli-config": "~1.15.2",
"@contentstack/cli-launch": "^1.9.2",
"@contentstack/cli-migration": "~1.8.1",
"@contentstack/cli-utilities": "~1.14.1",
"@contentstack/cli-utilities": "~1.14.2",
"@contentstack/cli-variants": "~1.3.1",
"@contentstack/management": "~1.22.0",
"@oclif/core": "^4.3.0",
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

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

Loading