@contentstack/cli-utilities 1.0.4 → 1.1.0

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.
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const ContentstackManagementSDK = tslib_1.__importStar(require("@contentstack/management"));
5
+ const https = require('https');
6
+ const config_handler_1 = tslib_1.__importDefault(require("./config-handler"));
7
+ exports.default = async (config) => {
8
+ try {
9
+ let managementAPIClient;
10
+ const option = {
11
+ host: config.host,
12
+ management_token: config.management_token,
13
+ api_key: config.stack_api_key,
14
+ maxContentLength: 100000000,
15
+ maxBodyLength: 1000000000,
16
+ maxRequests: 10,
17
+ retryLimit: 3,
18
+ timeout: 60000,
19
+ httpsAgent: new https.Agent({
20
+ maxSockets: 100,
21
+ maxFreeSockets: 10,
22
+ keepAlive: true,
23
+ timeout: 60000,
24
+ freeSocketTimeout: 30000, // free socket keepalive for 30 seconds
25
+ }),
26
+ retryDelay: Math.floor(Math.random() * (8000 - 3000 + 1) + 3000),
27
+ logHandler: (level, data) => { },
28
+ retryCondition: (error) => {
29
+ if (error.response && error.response.status) {
30
+ switch (error.response.status) {
31
+ case 401:
32
+ case 429:
33
+ case 408:
34
+ return true;
35
+ default:
36
+ return false;
37
+ }
38
+ }
39
+ },
40
+ retryDelayOptions: {
41
+ base: 1000,
42
+ customBackoff: (retryCount, error) => {
43
+ return 1;
44
+ },
45
+ },
46
+ refreshToken: () => {
47
+ return new Promise((resolve, reject) => {
48
+ reject('You do not have permissions to perform this action, please login to proceed');
49
+ });
50
+ },
51
+ };
52
+ if (typeof config.branchName === 'string') {
53
+ option['headers'] = {
54
+ branch: config.branchName,
55
+ };
56
+ }
57
+ if (!config.management_token) {
58
+ const authtoken = config_handler_1.default.get('authtoken');
59
+ if (authtoken) {
60
+ option['authtoken'] = config_handler_1.default.get('authtoken');
61
+ option['authorization'] = '';
62
+ }
63
+ else {
64
+ option['authtoken'] = '';
65
+ option['authorization'] = '';
66
+ }
67
+ }
68
+ managementAPIClient = ContentstackManagementSDK.client(option);
69
+ return managementAPIClient;
70
+ }
71
+ catch (error) {
72
+ console.error(error);
73
+ throw new Error(error);
74
+ }
75
+ };
@@ -8,12 +8,12 @@ class HttpClient {
8
8
  /**
9
9
  * Createa new pending HTTP request instance.
10
10
  */
11
- constructor() {
11
+ constructor(request = {}) {
12
12
  /**
13
13
  * The payload format for a JSON or form-url-encoded request.
14
14
  */
15
15
  this.bodyFormat = 'json';
16
- this.request = {};
16
+ this.request = request;
17
17
  this.axiosInstance = axios_1.default.create();
18
18
  // Sets payload format as json by default
19
19
  this.asJson();
@@ -23,8 +23,8 @@ class HttpClient {
23
23
  *
24
24
  * @returns {HttpClient}
25
25
  */
26
- static create() {
27
- return new this();
26
+ static create(request = {}) {
27
+ return new this(request);
28
28
  }
29
29
  /**
30
30
  * Returns the Axios request config.
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NodeCrypto = exports.printFlagDeprecation = exports.configHandler = exports.messageHandler = exports.CLIError = exports.cliux = exports.logger = void 0;
3
+ exports.NodeCrypto = exports.printFlagDeprecation = exports.managementSDKClient = exports.configHandler = exports.messageHandler = exports.CLIError = exports.cliux = exports.logger = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  var logger_1 = require("./logger");
6
6
  Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return tslib_1.__importDefault(logger_1).default; } });
@@ -12,6 +12,8 @@ var message_handler_1 = require("./message-handler");
12
12
  Object.defineProperty(exports, "messageHandler", { enumerable: true, get: function () { return tslib_1.__importDefault(message_handler_1).default; } });
13
13
  var config_handler_1 = require("./config-handler");
14
14
  Object.defineProperty(exports, "configHandler", { enumerable: true, get: function () { return tslib_1.__importDefault(config_handler_1).default; } });
15
+ var contentstack_management_sdk_1 = require("./contentstack-management-sdk");
16
+ Object.defineProperty(exports, "managementSDKClient", { enumerable: true, get: function () { return tslib_1.__importDefault(contentstack_management_sdk_1).default; } });
15
17
  var flag_deprecation_check_1 = require("./flag-deprecation-check");
16
18
  Object.defineProperty(exports, "printFlagDeprecation", { enumerable: true, get: function () { return tslib_1.__importDefault(flag_deprecation_check_1).default; } });
17
19
  tslib_1.__exportStar(require("./http-client"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/cli-utilities",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "description": "Utilities for contentstack projects",
5
5
  "main": "lib/index.js",
6
6
  "types": "./types/index.d.ts",
@@ -31,8 +31,8 @@
31
31
  "author": "contentstack",
32
32
  "license": "MIT",
33
33
  "dependencies": {
34
- "@contentstack/management": "^1.6.0",
35
- "@oclif/core": "^1.8.2",
34
+ "@contentstack/management": "^1.6.1",
35
+ "@oclif/core": "^1.21.0",
36
36
  "axios": "1.1.3",
37
37
  "chalk": "^4.0.0",
38
38
  "conf": "^10.1.2",
@@ -47,8 +47,7 @@
47
47
  "xdg-basedir": "^4.0.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@oclif/plugin-help": "^5.1.12",
51
- "@oclif/test": "^1.2.8",
50
+ "@oclif/test": "^2.2.10",
52
51
  "@types/chai": "^4.2.18",
53
52
  "@types/inquirer": "^9.0.3",
54
53
  "@types/mkdirp": "^1.0.1",
@@ -66,7 +65,7 @@
66
65
  "nock": "^13.1.0",
67
66
  "nyc": "^15.1.0",
68
67
  "rimraf": "^2.7.1",
69
- "sinon": "^11.1.1",
68
+ "sinon": "^15.0.1",
70
69
  "tmp": "^0.2.1",
71
70
  "ts-node": "^10.9.1",
72
71
  "typescript": "^4.9.3"
@@ -0,0 +1,3 @@
1
+ import * as ContentstackManagementSDK from '@contentstack/management';
2
+ declare const _default: (config: any) => Promise<ContentstackManagementSDK.ContentstackClient>;
3
+ export default _default;
@@ -16,13 +16,13 @@ export declare class HttpClient {
16
16
  /**
17
17
  * Createa new pending HTTP request instance.
18
18
  */
19
- constructor();
19
+ constructor(request?: AxiosRequestConfig);
20
20
  /**
21
21
  * Create a reusable HttpClient instance.
22
22
  *
23
23
  * @returns {HttpClient}
24
24
  */
25
- static create(): HttpClient;
25
+ static create(request?: AxiosRequestConfig): HttpClient;
26
26
  /**
27
27
  * Returns the Axios request config.
28
28
  *
@@ -225,6 +225,6 @@ export declare class HttpClient {
225
225
  */
226
226
  prepareRequestPayload(): any;
227
227
  }
228
- declare type BodyFormat = 'json' | 'formParams';
229
- declare type HttpMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS';
228
+ type BodyFormat = 'json' | 'formParams';
229
+ type HttpMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS';
230
230
  export {};
package/types/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export { default as cliux } from './cli-ux';
3
3
  export { default as CLIError } from './cli-error';
4
4
  export { default as messageHandler } from './message-handler';
5
5
  export { default as configHandler } from './config-handler';
6
+ export { default as managementSDKClient } from './contentstack-management-sdk';
6
7
  export { default as printFlagDeprecation } from './flag-deprecation-check';
7
8
  export * from './http-client';
8
9
  export { default as NodeCrypto } from './encrypter';