@contentstack/cli-utilities 1.5.9 → 1.5.11

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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 Contentstack
3
+ Copyright (c) 2024 Contentstack
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/lib/encrypter.js CHANGED
@@ -14,6 +14,7 @@ class NodeCrypto {
14
14
  const { algorithm, encryptionKey, typeIdentifier } = (0, merge_1.default)(defaultValues, config);
15
15
  this.algorithm = algorithm;
16
16
  this.typeIdentifier = typeIdentifier;
17
+ // deepcode ignore HardcodedSecret: <please specify a reason of ignoring this>
17
18
  this.key = crypto_1.default.scryptSync(encryptionKey, 'salt', 24);
18
19
  }
19
20
  encrypt(plainData) {
@@ -1,6 +1,9 @@
1
1
  import { AxiosRequestConfig, AxiosResponse } from 'axios';
2
2
  import { IHttpClient } from './client-interface';
3
3
  import { HttpResponse } from './http-response';
4
+ type HttpClientOptions = {
5
+ disableEarlyAccessHeaders?: boolean;
6
+ };
4
7
  export declare class HttpClient implements IHttpClient {
5
8
  /**
6
9
  * The request configuration.
@@ -10,6 +13,7 @@ export declare class HttpClient implements IHttpClient {
10
13
  * The request configuration.
11
14
  */
12
15
  private readonly axiosInstance;
16
+ private disableEarlyAccessHeaders;
13
17
  /**
14
18
  * The payload format for a JSON or form-url-encoded request.
15
19
  */
@@ -17,7 +21,7 @@ export declare class HttpClient implements IHttpClient {
17
21
  /**
18
22
  * Createa new pending HTTP request instance.
19
23
  */
20
- constructor(request?: AxiosRequestConfig);
24
+ constructor(request?: AxiosRequestConfig, options?: HttpClientOptions);
21
25
  /**
22
26
  * Create a reusable HttpClient instance.
23
27
  *
@@ -10,13 +10,14 @@ class HttpClient {
10
10
  /**
11
11
  * Createa new pending HTTP request instance.
12
12
  */
13
- constructor(request = {}) {
13
+ constructor(request = {}, options = {}) {
14
14
  /**
15
15
  * The payload format for a JSON or form-url-encoded request.
16
16
  */
17
17
  this.bodyFormat = 'json';
18
18
  this.request = request;
19
19
  this.axiosInstance = axios_1.default.create();
20
+ this.disableEarlyAccessHeaders = options.disableEarlyAccessHeaders || false;
20
21
  // Sets payload format as json by default
21
22
  this.asJson();
22
23
  }
@@ -309,7 +310,8 @@ class HttpClient {
309
310
  if ((_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.error_message) === null || _b === void 0 ? void 0 : _b.includes('access token is invalid or expired')) {
310
311
  const token = await this.refreshToken();
311
312
  this.headers(Object.assign(Object.assign({}, this.request.headers), { authorization: token.authorization }));
312
- return await this.axiosInstance(Object.assign(Object.assign({ url, method, withCredentials: true }, this.request), { data: this.prepareRequestPayload() }));
313
+ return await this.axiosInstance(Object.assign(Object.assign({ url,
314
+ method, withCredentials: true }, this.request), { data: this.prepareRequestPayload() }));
313
315
  }
314
316
  // Retry while Network timeout or Network Error
315
317
  if (!(message.includes('timeout') || message.includes('Network Error') || message.includes('getaddrinfo ENOTFOUND'))) {
@@ -317,11 +319,20 @@ class HttpClient {
317
319
  }
318
320
  if (counter < 1) {
319
321
  counter++;
320
- return await this.axiosInstance(Object.assign(Object.assign({ url, method, withCredentials: true }, this.request), { data: this.prepareRequestPayload() }));
322
+ return await this.axiosInstance(Object.assign(Object.assign({ url,
323
+ method, withCredentials: true }, this.request), { data: this.prepareRequestPayload() }));
321
324
  }
322
325
  return Promise.reject(error);
323
326
  });
324
- return await this.axiosInstance(Object.assign(Object.assign({ url, method, withCredentials: true }, this.request), { data: this.prepareRequestPayload() }));
327
+ if (!this.disableEarlyAccessHeaders) {
328
+ // Add early access header by default
329
+ const earlyAccessHeaders = config_handler_1.default.get(`earlyAccessHeaders`);
330
+ if (earlyAccessHeaders && Object.keys(earlyAccessHeaders).length > 0) {
331
+ this.headers({ 'x-header-ea': Object.values(earlyAccessHeaders).join(',') });
332
+ }
333
+ }
334
+ return await this.axiosInstance(Object.assign(Object.assign({ url,
335
+ method, withCredentials: true }, this.request), { data: this.prepareRequestPayload() }));
325
336
  }
326
337
  /**
327
338
  * Returns the request payload depending on the selected request payload format.
@@ -335,8 +346,9 @@ class HttpClient {
335
346
  return Promise.reject('Your session is timed out, please login to proceed');
336
347
  }
337
348
  else if (authorisationType === 'OAUTH') {
338
- return auth_handler_1.default.compareOAuthExpiry(true)
339
- .then(() => Promise.resolve({ authorization: `Bearer ${config_handler_1.default.get('oauthAccessToken')}`, }))
349
+ return auth_handler_1.default
350
+ .compareOAuthExpiry(true)
351
+ .then(() => Promise.resolve({ authorization: `Bearer ${config_handler_1.default.get('oauthAccessToken')}` }))
340
352
  .catch((error) => Promise.reject(error));
341
353
  }
342
354
  else {
package/lib/index.d.ts CHANGED
@@ -18,6 +18,6 @@ export * from './date-time';
18
18
  export * from './add-locale';
19
19
  export { App, AppData, Installation, marketplaceSDKClient, MarketplaceSDKInitiator, marketplaceSDKInitiator, ContentstackMarketplaceClient, ContentstackMarketplaceConfig, };
20
20
  export { Args, CommandHelp, Config, Errors, Flags, loadHelpClass, Help, HelpBase, HelpSection, HelpSectionRenderer, HelpSectionKeyValueTable, Hook, Interfaces, Parser, Plugin, run, toCached, tsPath, toStandardizedId, toConfiguredId, settings, Settings, flush, ux, execute, stderr, stdout, } from '@oclif/core';
21
- export { FlagInput, ArgInput } from '@oclif/core/lib/interfaces/parser';
21
+ export { FlagInput, ArgInput, FlagDefinition } from '@oclif/core/lib/interfaces/parser';
22
22
  export { default as TablePrompt } from './inquirer-table-prompt';
23
23
  export { Logger };
@@ -20,6 +20,7 @@ export interface Region {
20
20
  name: string;
21
21
  cma: string;
22
22
  cda: string;
23
+ uiHost: string;
23
24
  }
24
25
  export interface Token {
25
26
  token: string;
package/lib/logger.js CHANGED
@@ -169,7 +169,7 @@ class Logger {
169
169
  * the sensitiveKeys array, and false otherwise.
170
170
  */
171
171
  isSensitiveKey(keyStr) {
172
- if (keyStr) {
172
+ if (keyStr && typeof keyStr === 'string') {
173
173
  return this.sensitiveKeys.some((regex) => regex.test(keyStr));
174
174
  }
175
175
  }
@@ -196,11 +196,16 @@ class Logger {
196
196
  * redacted.
197
197
  */
198
198
  redact(obj) {
199
- const copy = (0, full_1.klona)(obj);
200
- this.redactObject(copy);
201
- const splat = copy[Symbol.for('splat')];
202
- this.redactObject(splat);
203
- return copy;
199
+ try {
200
+ const copy = (0, full_1.klona)(obj);
201
+ this.redactObject(copy);
202
+ const splat = copy[Symbol.for('splat')];
203
+ this.redactObject(splat);
204
+ return copy;
205
+ }
206
+ catch (error) {
207
+ return obj;
208
+ }
204
209
  }
205
210
  /**
206
211
  * The function checks if an object is a LogEntry by verifying if it has the properties 'level' and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/cli-utilities",
3
- "version": "1.5.9",
3
+ "version": "1.5.11",
4
4
  "description": "Utilities for contentstack projects",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -35,7 +35,7 @@
35
35
  "@contentstack/management": "~1.13.0",
36
36
  "@contentstack/marketplace-sdk": "^1.0.1",
37
37
  "@oclif/core": "^2.9.3",
38
- "axios": "^1.6.0",
38
+ "axios": "^1.6.4",
39
39
  "chalk": "^4.0.0",
40
40
  "cli-cursor": "^3.1.0",
41
41
  "cli-table": "^0.3.11",