@contentstack/cli-utilities 1.14.1 → 1.14.3

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,
@@ -1,8 +1,30 @@
1
1
  import Conf from 'conf';
2
+ declare class Config {
3
+ private config;
4
+ private inMemoryStore;
5
+ private isPrepackMode;
6
+ constructor();
7
+ init(): Conf<Record<string, unknown>>;
8
+ importOldConfig(): void;
9
+ setOldConfigStoreData(data: any, _path?: string): void;
10
+ isConfigFileValid(configPath: string): boolean;
11
+ safeDeleteConfigIfInvalid(configFilePath: string): void;
12
+ removeOldConfigStoreFile(): void;
13
+ private getOldConfig;
14
+ private fallbackInit;
15
+ private getObfuscationKey;
16
+ private getConfigDataAndUnlinkConfigFile;
17
+ private getEncryptedConfig;
18
+ private getDecryptedConfig;
19
+ get(key: any): string | any;
20
+ set(key: any, value: any): this | Conf<Record<string, unknown>>;
21
+ delete(key: any): this | Conf<Record<string, unknown>>;
22
+ clear(): void;
23
+ }
2
24
  declare const lazyConfig: {
3
25
  get(key: string): any;
4
- set(key: string, value: any): Conf<Record<string, unknown>>;
5
- delete(key: string): Conf<Record<string, unknown>>;
26
+ set(key: string, value: any): Config | Conf<Record<string, unknown>>;
27
+ delete(key: string): Config | Conf<Record<string, unknown>>;
6
28
  clear(): void;
7
29
  };
8
30
  export default lazyConfig;
@@ -22,10 +22,19 @@ const oldConfigPath = path.join(oldConfigDirectory, pathPrefix);
22
22
  const cwd = process.env.CS_CLI_CONFIG_PATH;
23
23
  class Config {
24
24
  constructor() {
25
+ this.inMemoryStore = new Map();
26
+ this.isPrepackMode = process.env.NODE_ENV === 'PREPACK_MODE';
25
27
  this.init();
26
- this.importOldConfig();
28
+ if (!this.isPrepackMode) {
29
+ this.importOldConfig();
30
+ }
27
31
  }
28
32
  init() {
33
+ // Skip file-based config during prepack to prevent race conditions
34
+ if (this.isPrepackMode) {
35
+ // Initialize with empty in-memory store for prepack
36
+ return;
37
+ }
29
38
  return ENCRYPT_CONF === true ? this.getEncryptedConfig() : this.getDecryptedConfig();
30
39
  }
31
40
  importOldConfig() {
@@ -189,20 +198,35 @@ class Config {
189
198
  }
190
199
  get(key) {
191
200
  var _a;
201
+ if (this.isPrepackMode) {
202
+ return this.inMemoryStore.get(key);
203
+ }
192
204
  return (_a = this.config) === null || _a === void 0 ? void 0 : _a.get(key);
193
205
  }
194
206
  set(key, value) {
195
207
  var _a;
208
+ if (this.isPrepackMode) {
209
+ this.inMemoryStore.set(key, value);
210
+ return this;
211
+ }
196
212
  (_a = this.config) === null || _a === void 0 ? void 0 : _a.set(key, value);
197
213
  return this.config;
198
214
  }
199
215
  delete(key) {
200
216
  var _a;
217
+ if (this.isPrepackMode) {
218
+ this.inMemoryStore.delete(key);
219
+ return this;
220
+ }
201
221
  (_a = this.config) === null || _a === void 0 ? void 0 : _a.delete(key);
202
222
  return this.config;
203
223
  }
204
224
  clear() {
205
225
  var _a;
226
+ if (this.isPrepackMode) {
227
+ this.inMemoryStore.clear();
228
+ return;
229
+ }
206
230
  (_a = this.config) === null || _a === void 0 ? void 0 : _a.clear();
207
231
  }
208
232
  }
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.3",
4
4
  "description": "Utilities for contentstack projects",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",