@contentstack/cli-utilities 1.14.1 → 1.14.2

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.
@@ -25,8 +25,10 @@ declare class AuthHandler {
25
25
  private oauthHandler;
26
26
  private managementAPIClient;
27
27
  private isRefreshingToken;
28
+ private cmaHost;
28
29
  set host(contentStackHost: any);
29
30
  constructor();
31
+ private getCmaHost;
30
32
  initLog(): void;
31
33
  setOAuthBaseURL(): Promise<void>;
32
34
  initSDK(): Promise<void>;
@@ -18,6 +18,8 @@ dotenv_1.default.config();
18
18
  class AuthHandler {
19
19
  set host(contentStackHost) {
20
20
  this._host = contentStackHost;
21
+ // Update cmaHost when host is set
22
+ this.cmaHost = this.getCmaHost();
21
23
  }
22
24
  constructor() {
23
25
  this.isRefreshingToken = false; // Flag to track if a refresh operation is in progress
@@ -55,6 +57,25 @@ class AuthHandler {
55
57
  this.authorisationTypeKeyName,
56
58
  ],
57
59
  };
60
+ this.cmaHost = this.getCmaHost();
61
+ }
62
+ getCmaHost() {
63
+ var _a;
64
+ if (this._host) {
65
+ return this._host;
66
+ }
67
+ const cma = (_a = config_handler_1.default.get('region')) === null || _a === void 0 ? void 0 : _a.cma;
68
+ if (cma && cma.startsWith('http')) {
69
+ try {
70
+ const u = new URL(cma);
71
+ if (u.host)
72
+ return u.host;
73
+ }
74
+ catch (error) {
75
+ // If URL parsing fails, return the original cma value
76
+ }
77
+ }
78
+ return cma;
58
79
  }
59
80
  initLog() {
60
81
  this.logger = new logger_1.LoggerService(process.cwd(), 'cli-log');
@@ -68,7 +89,9 @@ class AuthHandler {
68
89
  }
69
90
  }
70
91
  async initSDK() {
71
- this.managementAPIClient = await (0, contentstack_management_sdk_1.default)({ host: this._host });
92
+ // Ensure we have a valid host for the SDK initialization
93
+ const host = this._host || this.getCmaHost();
94
+ this.managementAPIClient = await (0, contentstack_management_sdk_1.default)({ host });
72
95
  this.oauthHandler = this.managementAPIClient.oauth({
73
96
  appId: this.OAuthAppId,
74
97
  clientId: this.OAuthClientId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/cli-utilities",
3
- "version": "1.14.1",
3
+ "version": "1.14.2",
4
4
  "description": "Utilities for contentstack projects",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",