@contentstack/cli-utilities 1.4.3 → 1.4.5

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.
File without changes
@@ -102,7 +102,40 @@ class AuthHandler {
102
102
  cli_ux_1.default.print('Access token fetched using auth code successfully.');
103
103
  cli_ux_1.default.print(`You can review the access permissions on the page - ${this.OAuthBaseURL}/#!/marketplace/authorized-apps`);
104
104
  res.writeHead(200, { 'Content-Type': 'text/html' });
105
- res.end(`<h1>Successfully authorized!</h1><h2>You can close this window now.</h2><p>You can review the access permissions on - <a href="${this.OAuthBaseURL}/#!/marketplace/authorized-apps" target="_blank">Authorized Apps page</a></p>`);
105
+ res.end(`<style>
106
+ body {
107
+ font-family: Arial, sans-serif;
108
+ text-align: center;
109
+ margin-top: 100px;
110
+ }
111
+
112
+ p {
113
+ color: #475161;
114
+ margin-bottom: 20px;
115
+ }
116
+ p button {
117
+ background-color: #6c5ce7;
118
+ color: #fff;
119
+ border: 1px solid transparent;
120
+ border-radius: 4px;
121
+ font-weight: 600;
122
+ line-height: 100%;
123
+ text-align: center;
124
+ min-height: 2rem;
125
+ padding: 0.3125rem 1rem;
126
+ }
127
+ </style>
128
+ <h1 style="color: #6c5ce7">Successfully authorized!</h1>
129
+ <p style="color: #475161; font-size: 16px; font-weight: 600">You can close this window now.</p>
130
+ <p>
131
+ You can review the access permissions on the
132
+ <a
133
+ style="color: #6c5ce7; text-decoration: none"
134
+ href="${this.OAuthBaseURL}/#!/marketplace/authorized-apps"
135
+ target="_blank"
136
+ >Authorized Apps page</a
137
+ >.
138
+ </p>`);
106
139
  stopServer();
107
140
  })
108
141
  .catch((error) => {
@@ -0,0 +1,27 @@
1
+ import { Table } from '@oclif/core/lib/cli-ux';
2
+ import { Args, Flags, Command } from '@oclif/core';
3
+ import { Ora } from 'ora';
4
+ import { PrintOptions, InquirePayload, CliUXPromptOptions } from './interfaces';
5
+ /**
6
+ * CLI Interface
7
+ */
8
+ declare class CLIInterface {
9
+ private loading;
10
+ constructor();
11
+ get uxTable(): typeof Table.table;
12
+ init(context: any): void;
13
+ registerSearchPlugin(): void;
14
+ print(message: string, opts?: PrintOptions): void;
15
+ success(message: string): void;
16
+ error(message: string, ...params: any): void;
17
+ loader(message?: string): void;
18
+ table(data: Record<string, unknown>[], columns: Table.table.Columns<Record<string, unknown>>, options?: Table.table.Options): void;
19
+ inquire<T>(inquirePayload: InquirePayload | Array<InquirePayload>): Promise<T>;
20
+ prompt(name: string, options?: CliUXPromptOptions): Promise<any>;
21
+ confirm(message?: string): Promise<boolean>;
22
+ progress(options?: any): any;
23
+ loaderV2(message?: string, spinner?: any): Ora | void;
24
+ }
25
+ declare const _default: CLIInterface;
26
+ export default _default;
27
+ export { Flags, Args, Command };
@@ -5,6 +5,8 @@ const conf_1 = tslib_1.__importDefault(require("conf"));
5
5
  const has_1 = tslib_1.__importDefault(require("lodash/has"));
6
6
  const uuid_1 = require("uuid");
7
7
  const fs_1 = require("fs");
8
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
9
+ const _1 = require(".");
8
10
  const ENC_KEY = process.env.ENC_KEY || 'encryptionKey';
9
11
  const ENCRYPT_CONF = (0, has_1.default)(process.env, 'ENCRYPT_CONF') ? process.env.ENCRYPT_CONF === 'true' : true;
10
12
  const CONFIG_NAME = process.env.CONFIG_NAME || 'contentstack_cli';
@@ -72,10 +74,10 @@ class Config {
72
74
  getObfuscationKey() {
73
75
  const obfuscationKeyName = 'obfuscation_key';
74
76
  const encConfig = new conf_1.default({ configName: ENC_CONFIG_NAME });
75
- let obfuscationKey = encConfig.get(obfuscationKeyName);
77
+ let obfuscationKey = encConfig === null || encConfig === void 0 ? void 0 : encConfig.get(obfuscationKeyName);
76
78
  if (!obfuscationKey) {
77
79
  encConfig.set(obfuscationKeyName, (0, uuid_1.v4)());
78
- obfuscationKey = encConfig.get(obfuscationKeyName);
80
+ obfuscationKey = encConfig === null || encConfig === void 0 ? void 0 : encConfig.get(obfuscationKeyName);
79
81
  }
80
82
  return obfuscationKey;
81
83
  }
@@ -108,7 +110,9 @@ class Config {
108
110
  this.getEncryptedConfig(oldConfigData, true);
109
111
  }
110
112
  catch (_error) {
111
- // console.trace(error.message)
113
+ _1.cliux.print(chalk_1.default.red("Error: Config file is corrupted"));
114
+ _1.cliux.print(_error);
115
+ process.exit(1);
112
116
  }
113
117
  }
114
118
  };
@@ -154,24 +158,31 @@ class Config {
154
158
  }
155
159
  catch (__error) {
156
160
  // console.trace(error.message)
161
+ _1.cliux.print(chalk_1.default.red("Error: Config file is corrupted"));
162
+ _1.cliux.print(_error);
163
+ process.exit(1);
157
164
  }
158
165
  }
159
166
  }
160
167
  return this.config;
161
168
  }
162
169
  get(key) {
163
- return this.config.get(key);
170
+ var _a;
171
+ return (_a = this.config) === null || _a === void 0 ? void 0 : _a.get(key);
164
172
  }
165
173
  async set(key, value) {
166
- this.config.set(key, value);
174
+ var _a;
175
+ (_a = this.config) === null || _a === void 0 ? void 0 : _a.set(key, value);
167
176
  return this.config;
168
177
  }
169
178
  delete(key) {
170
- this.config.delete(key);
179
+ var _a;
180
+ (_a = this.config) === null || _a === void 0 ? void 0 : _a.delete(key);
171
181
  return this.config;
172
182
  }
173
183
  clear() {
174
- this.config.clear();
184
+ var _a;
185
+ (_a = this.config) === null || _a === void 0 ? void 0 : _a.clear();
175
186
  }
176
187
  }
177
188
  exports.default = new Config();
File without changes
@@ -0,0 +1,2 @@
1
+ export declare const isAuthenticated: () => boolean;
2
+ export declare const doesBranchExist: (stack: any, branchName: any) => Promise<any>;
package/lib/helpers.js CHANGED
@@ -1,7 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isAuthenticated = void 0;
3
+ exports.doesBranchExist = exports.isAuthenticated = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const auth_handler_1 = tslib_1.__importDefault(require("./auth-handler"));
6
6
  const isAuthenticated = () => auth_handler_1.default.isAuthenticated();
7
7
  exports.isAuthenticated = isAuthenticated;
8
+ const doesBranchExist = async (stack, branchName) => {
9
+ return stack
10
+ .branch(branchName)
11
+ .fetch()
12
+ .catch((error) => {
13
+ return error;
14
+ });
15
+ };
16
+ exports.doesBranchExist = doesBranchExist;
@@ -0,0 +1,13 @@
1
+ import { HttpClient } from './client';
2
+ import { IHttpClient } from './client-interface';
3
+ import { HttpResponse } from './http-response';
4
+ export declare class BaseClientDecorator implements IHttpClient {
5
+ protected client: IHttpClient;
6
+ constructor(client: IHttpClient);
7
+ headers(headers: any): HttpClient;
8
+ contentType(contentType: string): HttpClient;
9
+ get<R>(url: string, queryParams?: object): Promise<HttpResponse<R>>;
10
+ post<R>(url: string, payload?: any): Promise<HttpResponse<R>>;
11
+ put<R>(url: string, payload?: any): Promise<HttpResponse<R>>;
12
+ delete<R>(url: string, queryParams?: object): Promise<HttpResponse<R>>;
13
+ }
@@ -0,0 +1,10 @@
1
+ import { HttpClient } from './client';
2
+ import { HttpResponse } from './http-response';
3
+ export interface IHttpClient {
4
+ headers(headers: any): HttpClient;
5
+ contentType(contentType: string): HttpClient;
6
+ get<R>(url: string, queryParams: object): Promise<HttpResponse<R>>;
7
+ post<R>(url: string, payload?: any): Promise<HttpResponse<R>>;
8
+ put<R>(url: string, payload?: any): Promise<HttpResponse<R>>;
9
+ delete<R>(url: string, queryParams: object): Promise<HttpResponse<R>>;
10
+ }
File without changes
@@ -0,0 +1,14 @@
1
+ import { BaseClientDecorator } from './base-client-decorator';
2
+ import { HttpClient } from './client';
3
+ import { IHttpClient } from './client-interface';
4
+ import { HttpResponse } from './http-response';
5
+ export declare class HttpClientDecorator extends BaseClientDecorator {
6
+ protected client: IHttpClient;
7
+ constructor(client: IHttpClient);
8
+ headers(headers: any): HttpClient;
9
+ contentType(contentType: string): HttpClient;
10
+ get<R>(url: string, queryParams?: object): Promise<HttpResponse<R>>;
11
+ post<R>(url: string, payload?: any): Promise<HttpResponse<R>>;
12
+ put<R>(url: string, payload?: any): Promise<HttpResponse<R>>;
13
+ delete<R>(url: string, queryParams?: object): Promise<HttpResponse<R>>;
14
+ }
@@ -1,4 +1,4 @@
1
- import { AxiosResponse } from 'axios';
1
+ import { AxiosResponse, AxiosResponseHeaders, RawAxiosResponseHeaders } from 'axios';
2
2
  export declare class HttpResponse<ResponseType = any> {
3
3
  /**
4
4
  * The Axios response object.
@@ -33,7 +33,5 @@ export declare class HttpResponse<ResponseType = any> {
33
33
  *
34
34
  * @returns {Object}
35
35
  */
36
- get headers(): import("axios").AxiosResponseHeaders | Partial<Record<string, string> & {
37
- "set-cookie"?: string[];
38
- }>;
36
+ get headers(): RawAxiosResponseHeaders | AxiosResponseHeaders;
39
37
  }
@@ -0,0 +1,15 @@
1
+ import { BaseClientDecorator } from './base-client-decorator';
2
+ import { HttpClient } from './client';
3
+ import { IHttpClient } from './client-interface';
4
+ import { HttpResponse } from './http-response';
5
+ export declare class OauthDecorator extends BaseClientDecorator {
6
+ protected client: IHttpClient;
7
+ constructor(client: IHttpClient);
8
+ preHeadersCheck(config: any): Promise<any>;
9
+ headers(headers: any): HttpClient;
10
+ contentType(contentType: string): HttpClient;
11
+ get<R>(url: string, queryParams: object): Promise<HttpResponse<R>>;
12
+ post<R>(url: string, payload?: object): Promise<HttpResponse<R>>;
13
+ put<R>(url: string, payload?: object): Promise<HttpResponse<R>>;
14
+ delete<R>(url: string, queryParams?: object): Promise<HttpResponse<R>>;
15
+ }
@@ -10,5 +10,7 @@ export * from './http-client';
10
10
  export { default as NodeCrypto } from './encrypter';
11
11
  export { Args as args, Flags as flags, Command } from './cli-ux';
12
12
  export * from './helpers';
13
+ export * from './interfaces';
13
14
  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';
14
- export { FlagInput } from '@oclif/core/lib/interfaces/parser';
15
+ export { FlagInput, ArgInput } from '@oclif/core/lib/interfaces/parser';
16
+ export { default as TablePrompt } from './inquirer-table-prompt';
package/lib/index.js CHANGED
@@ -27,6 +27,7 @@ Object.defineProperty(exports, "args", { enumerable: true, get: function () { re
27
27
  Object.defineProperty(exports, "flags", { enumerable: true, get: function () { return cli_ux_2.Flags; } });
28
28
  Object.defineProperty(exports, "Command", { enumerable: true, get: function () { return cli_ux_2.Command; } });
29
29
  tslib_1.__exportStar(require("./helpers"), exports);
30
+ tslib_1.__exportStar(require("./interfaces"), exports);
30
31
  // NOTE Exporting all @oclif/core modules: So that all the module can be acessed through cli-utility
31
32
  var core_1 = require("@oclif/core");
32
33
  Object.defineProperty(exports, "Args", { enumerable: true, get: function () { return core_1.Args; } });
@@ -0,0 +1,30 @@
1
+ declare const Base: any;
2
+ declare class TablePrompt extends Base {
3
+ /**
4
+ * Initialise the prompt
5
+ *
6
+ * @param {Object} questions
7
+ * @param {Object} rl
8
+ * @param {Object} answers
9
+ */
10
+ constructor(questions: any, rl: any, answers: any);
11
+ /**
12
+ * Start the inquirer session
13
+ *
14
+ * @param {Function} callback
15
+ * @return {TablePrompt}
16
+ */
17
+ _run(callback: any): this;
18
+ getCurrentValue(): any[];
19
+ onDownKey(): void;
20
+ onEnd(state: any): void;
21
+ onError(state: any): void;
22
+ onLeftKey(): void;
23
+ onRightKey(): void;
24
+ selectAllValues(value: any): void;
25
+ onSpaceKey(): void;
26
+ onUpKey(): void;
27
+ paginate(): number[];
28
+ render(error?: string): void;
29
+ }
30
+ export = TablePrompt;
@@ -0,0 +1,57 @@
1
+ import { IPromptOptions } from "@oclif/core/lib/cli-ux";
2
+ export interface PrintOptions {
3
+ bold?: boolean;
4
+ color?: string;
5
+ }
6
+ export interface InquirePayload {
7
+ type: string;
8
+ name: string;
9
+ default?: any;
10
+ message: string;
11
+ choices?: Array<any>;
12
+ transformer?: Function;
13
+ validate?(input: any, answers?: any): boolean | string | Promise<boolean | string>;
14
+ selectAll?: boolean;
15
+ pageSize?: number;
16
+ columns?: Record<string, any>[];
17
+ rows?: Array<any>;
18
+ }
19
+ export interface Region {
20
+ name: string;
21
+ cma: string;
22
+ cda: string;
23
+ }
24
+ export interface Token {
25
+ token: string;
26
+ apiKey: string;
27
+ }
28
+ export interface Organization {
29
+ uid: string;
30
+ name: string;
31
+ }
32
+ export interface selectedOrganization {
33
+ orgUid: string;
34
+ orgName: string;
35
+ }
36
+ export interface Stack {
37
+ name: string;
38
+ api_key: string;
39
+ }
40
+ export interface ContentType {
41
+ uid: string;
42
+ title: string;
43
+ }
44
+ export interface Environment {
45
+ name: string;
46
+ uid: string;
47
+ }
48
+ export interface Entry {
49
+ uid: string;
50
+ title: string;
51
+ }
52
+ export interface Locale {
53
+ name: string;
54
+ code: string;
55
+ }
56
+ export interface CliUXPromptOptions extends IPromptOptions {
57
+ }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@contentstack/cli-utilities",
3
- "version": "1.4.3",
3
+ "version": "1.4.5",
4
4
  "description": "Utilities for contentstack projects",
5
5
  "main": "lib/index.js",
6
- "types": "./types/index.d.ts",
6
+ "types": "lib/index.d.ts",
7
7
  "scripts": {
8
8
  "prepack": "pnpm compile",
9
9
  "clean": "rm -rf ./lib ./node_modules tsconfig.build.tsbuildinfo",
@@ -13,7 +13,9 @@
13
13
  "test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
14
14
  "posttest": "npm run lint",
15
15
  "lint": "eslint src/**/*.ts",
16
- "format": "eslint src/**/*.ts --fix"
16
+ "format": "eslint src/**/*.ts --fix",
17
+ "test:unit": "mocha --forbid-only \"test/unit/**/*.test.ts\"",
18
+ "test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\""
17
19
  },
18
20
  "repository": {
19
21
  "type": "git",
@@ -25,8 +27,7 @@
25
27
  ],
26
28
  "files": [
27
29
  "/npm-shrinkwrap.json",
28
- "/lib",
29
- "/types"
30
+ "/lib"
30
31
  ],
31
32
  "author": "contentstack",
32
33
  "license": "MIT",
@@ -37,7 +38,7 @@
37
38
  "chalk": "^4.0.0",
38
39
  "cli-cursor": "^3.1.0",
39
40
  "cli-table": "^0.3.11",
40
- "conf": "^10.1.2",
41
+ "conf": "^10.2.0",
41
42
  "debug": "^4.1.1",
42
43
  "figures": "^3.2.0",
43
44
  "inquirer": "8.2.4",
@@ -76,4 +77,4 @@
76
77
  "tslib": "^1.13.0",
77
78
  "typescript": "^4.9.3"
78
79
  }
79
- }
80
+ }
package/types/cli-ux.d.ts DELETED
@@ -1,31 +0,0 @@
1
- import { Table } from '@oclif/core/lib/cli-ux';
2
- import { Args, Flags, Command } from '@oclif/core';
3
- import { Ora } from 'ora';
4
- import { PrintOptions, InquirePayload, CliUXPromptOptions } from './interfaces';
5
- /**
6
- * CLI Interface
7
- */
8
- declare class CLIInterface {
9
- private loading;
10
- constructor();
11
- get uxTable(): typeof Table.table;
12
- init(context: any): void;
13
- registerSearchPlugin(): void;
14
- print(message: string, opts?: PrintOptions): void;
15
- success(message: string): void;
16
- error(message: string, ...params: any): void;
17
- loader(message?: string): void;
18
- table(
19
- data: Record<string, unknown>[],
20
- columns: Table.table.Columns<Record<string, unknown>>,
21
- options?: Table.table.Options,
22
- ): void;
23
- inquire<T>(inquirePayload: InquirePayload | Array<InquirePayload>): Promise<T>;
24
- prompt(name: string, options?: CliUXPromptOptions): Promise<any>;
25
- confirm(message?: string): Promise<boolean>;
26
- progress(options?: any): any;
27
- loaderV2(message?: string, spinner?: any): Ora | void;
28
- }
29
- declare const _default: CLIInterface;
30
- export default _default;
31
- export { Flags, Args, Command };
@@ -1 +0,0 @@
1
- export declare const isAuthenticated: () => boolean;
@@ -1,56 +0,0 @@
1
- import { IPromptOptions } from '@oclif/core/lib/cli-ux';
2
- export interface PrintOptions {
3
- bold?: boolean;
4
- color?: string;
5
- }
6
- export interface InquirePayload {
7
- type: string;
8
- name: string;
9
- default?: any;
10
- message: string;
11
- choices?: Array<any>;
12
- transformer?: Function;
13
- validate?(input: any, answers?: any): boolean | string | Promise<boolean | string>;
14
- columns?: Array<any>;
15
- rows?: Array<any>;
16
- selectAll?: boolean;
17
- pageSize?: number;
18
- }
19
- export interface Region {
20
- name: string;
21
- cma: string;
22
- cda: string;
23
- }
24
- export interface Token {
25
- token: string;
26
- apiKey: string;
27
- }
28
- export interface Organization {
29
- uid: string;
30
- name: string;
31
- }
32
- export interface selectedOrganization {
33
- orgUid: string;
34
- orgName: string;
35
- }
36
- export interface Stack {
37
- name: string;
38
- api_key: string;
39
- }
40
- export interface ContentType {
41
- uid: string;
42
- title: string;
43
- }
44
- export interface Environment {
45
- name: string;
46
- uid: string;
47
- }
48
- export interface Entry {
49
- uid: string;
50
- title: string;
51
- }
52
- export interface Locale {
53
- name: string;
54
- code: string;
55
- }
56
- export interface CliUXPromptOptions extends IPromptOptions {}
@@ -1,19 +0,0 @@
1
- declare class CustomAbortSignal {
2
- aborted: any;
3
- onabort: any;
4
- eventEmitter: any;
5
- constructor();
6
- toString(): string;
7
- get [Symbol.toStringTag](): string;
8
- removeEventListener(name: any, handler: any): void;
9
- addEventListener(name: any, handler: any): void;
10
- dispatchEvent(type: any): void;
11
- }
12
- declare class CustomAbortController {
13
- signal: any;
14
- constructor();
15
- abort(): void;
16
- toString(): string;
17
- get [Symbol.toStringTag](): string;
18
- }
19
- export { CustomAbortController, CustomAbortSignal };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes