@contentstack/cli-utilities 0.1.1-beta.1

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.
Files changed (52) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc +40 -0
  3. package/.mocharc.json +12 -0
  4. package/.nycrc.json +5 -0
  5. package/LICENSE +21 -0
  6. package/lib/cli-error.js +16 -0
  7. package/lib/cli-ux.js +59 -0
  8. package/lib/config-handler.js +128 -0
  9. package/lib/flag-deprecation-check.js +40 -0
  10. package/lib/http-client/client.js +313 -0
  11. package/lib/http-client/http-response.js +46 -0
  12. package/lib/http-client/index.js +7 -0
  13. package/lib/index.js +17 -0
  14. package/lib/interfaces/index.js +2 -0
  15. package/lib/logger.js +92 -0
  16. package/lib/message-handler.js +43 -0
  17. package/lib/selectors/index.js +376 -0
  18. package/lib/selectors/interfaces.js +2 -0
  19. package/lib/selectors/validations.js +9 -0
  20. package/messages/auth.json +46 -0
  21. package/messages/config.json +9 -0
  22. package/messages/core.json +6 -0
  23. package/package.json +68 -0
  24. package/src/cli-error.ts +15 -0
  25. package/src/cli-ux.ts +78 -0
  26. package/src/config-handler.ts +142 -0
  27. package/src/flag-deprecation-check.ts +41 -0
  28. package/src/http-client/client.ts +369 -0
  29. package/src/http-client/http-response.ts +55 -0
  30. package/src/http-client/index.ts +7 -0
  31. package/src/index.ts +7 -0
  32. package/src/interfaces/index.ts +61 -0
  33. package/src/logger.ts +101 -0
  34. package/src/message-handler.ts +45 -0
  35. package/src/selectors/index.ts +381 -0
  36. package/src/selectors/interfaces.ts +39 -0
  37. package/src/selectors/validations.ts +5 -0
  38. package/test/helpers/init.js +4 -0
  39. package/test/tsconfig.json +6 -0
  40. package/tsconfig.json +20 -0
  41. package/types/cli-error.d.ts +4 -0
  42. package/types/cli-ux.d.ts +22 -0
  43. package/types/config-handler.d.ts +17 -0
  44. package/types/flag-deprecation-check.d.ts +7 -0
  45. package/types/http-client.d.ts +54 -0
  46. package/types/index.d.ts +7 -0
  47. package/types/interfaces/index.d.ts +50 -0
  48. package/types/logger.d.ts +17 -0
  49. package/types/message-handler.d.ts +12 -0
  50. package/types/selectors/index.d.ts +12 -0
  51. package/types/selectors/interfaces.d.ts +32 -0
  52. package/types/selectors/validations.d.ts +1 -0
@@ -0,0 +1,4 @@
1
+ const path = require('path');
2
+
3
+ process.env.TS_NODE_PROJECT = path.resolve('test/tsconfig.json');
4
+ process.env.CLI_ENV = 'TEST';
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": "../tsconfig",
3
+ "compilerOptions": {
4
+ "noEmit": true
5
+ }
6
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": false,
4
+ "importHelpers": true,
5
+ "module": "commonjs",
6
+ "outDir": "lib",
7
+ "rootDir": "src",
8
+ "strict": false,
9
+ "target": "es2017",
10
+ "allowJs": true,
11
+ "skipLibCheck": true,
12
+ "esModuleInterop": true
13
+ },
14
+ "include": [
15
+ "src/**/*"
16
+ ],
17
+ "exclude": [
18
+ "src/**/*.d.ts"
19
+ ]
20
+ }
@@ -0,0 +1,4 @@
1
+ export default class CLIError extends Error {
2
+ suggestions?: string[];
3
+ constructor(message: any, suggestions?: string[]);
4
+ }
@@ -0,0 +1,22 @@
1
+ import { Table } from '@oclif/core/lib/cli-ux';
2
+ import { PrintOptions, InquirePayload, CliUXPromptOptions } from './interfaces';
3
+ /**
4
+ * CLI Interface
5
+ */
6
+ declare class CLIInterface {
7
+ private loading;
8
+ constructor();
9
+ get uxTable(): typeof Table.table;
10
+ init(context: any): void;
11
+ print(message: string, opts?: PrintOptions): void;
12
+ success(message: string): void;
13
+ error(message: string, ...params: any): void;
14
+ loader(message?: string): void;
15
+ table(data: Record<string, unknown>[], columns: Table.table.Columns<Record<string, unknown>>, options?: Table.table.Options): void;
16
+ inquire<T>(inquirePayload: InquirePayload): Promise<T>;
17
+ prompt(name: string, options?: CliUXPromptOptions): Promise<any>;
18
+ confirm(message?: string): Promise<boolean>;
19
+ progress(options?: any): any;
20
+ }
21
+ declare const _default: CLIInterface;
22
+ export default _default;
@@ -0,0 +1,17 @@
1
+ import Conf from 'conf';
2
+ declare class Config {
3
+ private config;
4
+ constructor();
5
+ init(): Conf<Record<string, unknown>>;
6
+ private fallbackInit;
7
+ private getObfuscationKey;
8
+ private getConfigDataAndUnlinkConfigFile;
9
+ private getEncryptedConfig;
10
+ private getDecryptedConfig;
11
+ get(key: any): string | any;
12
+ set(key: any, value: any): Promise<Conf<Record<string, unknown>>>;
13
+ delete(key: any): Conf<Record<string, unknown>>;
14
+ clear(): void;
15
+ }
16
+ declare const _default: Config;
17
+ export default _default;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * checks the deprecation and prints it
3
+ * @param {Array} deprecatedFlags flags to be deprecated
4
+ * @param {String} customMessage [optional] a custom message
5
+ * @returns flag parser
6
+ */
7
+ export default function (deprecatedFlags?: any[], suggestions?: any[], customMessage?: string): (input: any, command: any) => any;
@@ -0,0 +1,54 @@
1
+ import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
2
+ import { HttpResponse } from '../src/http-client';
3
+
4
+ type BodyFormat = 'json' | 'formParams';
5
+
6
+ type HttpMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS';
7
+
8
+ /**
9
+ * CLI HttpClient
10
+ */
11
+ export declare class HttpClient {
12
+ private request: AxiosRequestConfig;
13
+ private readonly axiosInstance: AxiosInstance;
14
+ constructor();
15
+ static create(): HttpClient;
16
+ requestConfig(): AxiosRequestConfig;
17
+ resetConfig(): HttpClient;
18
+ baseUrl(baseUrl: string): HttpClient;
19
+ headers(headers: any): HttpClient;
20
+ queryParams(queryParams: object): HttpClient;
21
+ basicAuth(username: string, password: string): HttpClient;
22
+ token(token: string, type: string): HttpClient;
23
+ options(options: AxiosRequestConfig): HttpClient;
24
+ payload(data: any): HttpClient;
25
+ timeout(timeout: number): this;
26
+ asJson(): HttpClient;
27
+ asFormParams(): HttpClient;
28
+ payloadFormat(format: BodyFormat): HttpClient;
29
+ accept(accept: string): HttpClient;
30
+ acceptJson(): HttpClient;
31
+ contentType(contentType: string): HttpClient;
32
+ get<R>(url: string, queryParams?: object): Promise<HttpResponse<R>>;
33
+ post<R>(url: string, payload?: any): Promise<HttpResponse<R>>;
34
+ put<R>(url: string, payload?: any): Promise<HttpResponse<R>>;
35
+ patch<R>(url: string, payload?: any): Promise<HttpResponse<R>>;
36
+ delete<R>(url: string, queryParams?: object): Promise<HttpResponse<R>>;
37
+ send<R>(method: HttpMethod, url: string): Promise<HttpResponse<R>>;
38
+ createAndSendRequest(method: HttpMethod, url: string): Promise<AxiosResponse>;
39
+ prepareRequestPayload(): any;
40
+ }
41
+
42
+ /**
43
+ * CLI HttpClient
44
+ */
45
+ export declare class HttpResponse {
46
+ private readonly response: AxiosResponse;
47
+ constructor();
48
+ get status(): number;
49
+ get data();
50
+ get payload();
51
+ get headers();
52
+ }
53
+
54
+ export interface HttpRequestConfig extends AxiosRequestConfig {}
@@ -0,0 +1,7 @@
1
+ export { default as logger } from './logger';
2
+ export { default as cliux } from './cli-ux';
3
+ export { default as CLIError } from './cli-error';
4
+ export { default as messageHandler } from './message-handler';
5
+ export { default as configHandler } from './config-handler';
6
+ export { default as printFlagDeprecation } from './flag-deprecation-check';
7
+ export * from './http-client';
@@ -0,0 +1,50 @@
1
+ import { IPromptOptions } from "@oclif/core/lib/cli-ux";
2
+ export interface PrintOptions {
3
+ color?: string;
4
+ }
5
+ export interface InquirePayload {
6
+ type: string;
7
+ name: string;
8
+ message: string;
9
+ choices?: Array<any>;
10
+ transformer?: Function;
11
+ }
12
+ export interface Region {
13
+ name: string;
14
+ cma: string;
15
+ cda: string;
16
+ }
17
+ export interface Token {
18
+ token: string;
19
+ apiKey: string;
20
+ }
21
+ export interface Organization {
22
+ uid: string;
23
+ name: string;
24
+ }
25
+ export interface selectedOrganization {
26
+ orgUid: string;
27
+ orgName: string;
28
+ }
29
+ export interface Stack {
30
+ name: string;
31
+ api_key: string;
32
+ }
33
+ export interface ContentType {
34
+ uid: string;
35
+ title: string;
36
+ }
37
+ export interface Environment {
38
+ name: string;
39
+ uid: string;
40
+ }
41
+ export interface Entry {
42
+ uid: string;
43
+ title: string;
44
+ }
45
+ export interface Locale {
46
+ name: string;
47
+ code: string;
48
+ }
49
+ export interface CliUXPromptOptions extends IPromptOptions {
50
+ }
@@ -0,0 +1,17 @@
1
+ import winston from 'winston';
2
+ declare class LoggerService {
3
+ name: string;
4
+ data: object | null;
5
+ logger: winston.Logger;
6
+ static dateFormat(): string;
7
+ constructor(name: string);
8
+ init(context: any): void;
9
+ set loggerName(name: string);
10
+ setLogData(data: object): void;
11
+ info(message: string, param?: any): Promise<any>;
12
+ debug(message: string, param?: any): Promise<any>;
13
+ error(message: string, param?: any): Promise<any>;
14
+ warn(message: string, param?: any): Promise<any>;
15
+ }
16
+ declare const _default: LoggerService;
17
+ export default _default;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Message handler
3
+ */
4
+ declare class Messages {
5
+ private messages;
6
+ messageFilePath: any;
7
+ constructor();
8
+ init(context: any): void;
9
+ parse(messageKey: string, ...substitutions: Array<any>): string;
10
+ }
11
+ declare const _default: Messages;
12
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import { Token, selectedOrganization, Stack, ContentType, Environment, Entry, Locale } from './interfaces';
2
+ export declare function chooseOrganization(client: any, displayMessage?: string, region?: string, orgUid?: string): Promise<selectedOrganization>;
3
+ export declare function chooseStack(client: any, organizationId: string, displayMessage?: string, region?: string): Promise<Stack>;
4
+ export declare function chooseContentType(stackApiKey: string, displayMessage?: string, region?: string): Promise<ContentType>;
5
+ export declare function chooseEntry(contentTypeUid: string, stackApiKey: string, displayMessage?: string, region?: string): Promise<Entry>;
6
+ export declare function chooseContentTypes(stack: any, displayMessage?: string): Promise<ContentType[]>;
7
+ export declare function chooseEnvironments(stack: any, displayMessage?: string): Promise<Environment[]>;
8
+ export declare function chooseEnvironment(stack: any, displayMessage?: string): Promise<Environment>;
9
+ export declare function chooseLocales(stack: any, displayMessage?: string): Promise<Locale[]>;
10
+ export declare function chooseLocale(stack: any, displayMessage?: string): Promise<Locale>;
11
+ export declare function chooseTokenAlias(): Promise<Token>;
12
+ export declare function chooseDeliveryTokenAlias(): Promise<Token>;
@@ -0,0 +1,32 @@
1
+ export interface Token {
2
+ token: string;
3
+ apiKey: string;
4
+ }
5
+ export interface Organization {
6
+ uid: string;
7
+ name: string;
8
+ }
9
+ export interface selectedOrganization {
10
+ orgUid: string;
11
+ orgName: string;
12
+ }
13
+ export interface Stack {
14
+ name: string;
15
+ api_key: string;
16
+ }
17
+ export interface ContentType {
18
+ uid: string;
19
+ title: string;
20
+ }
21
+ export interface Environment {
22
+ name: string;
23
+ uid: string;
24
+ }
25
+ export interface Entry {
26
+ uid: string;
27
+ title: string;
28
+ }
29
+ export interface Locale {
30
+ name: string;
31
+ code: string;
32
+ }
@@ -0,0 +1 @@
1
+ export declare function shouldNotBeEmpty(input: any): boolean;