contensis-cli 1.4.1-beta.1 → 1.4.2-beta.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.
- package/CHANGELOG.md +8 -0
- package/README.md +360 -1
- package/dist/commands/create.js +83 -2
- package/dist/commands/create.js.map +2 -2
- package/dist/commands/get.js +33 -1
- package/dist/commands/get.js.map +2 -2
- package/dist/commands/import.js +62 -0
- package/dist/commands/import.js.map +2 -2
- package/dist/commands/list.js +48 -1
- package/dist/commands/list.js.map +2 -2
- package/dist/commands/remove.js +50 -1
- package/dist/commands/remove.js.map +2 -2
- package/dist/localisation/en-GB.js +38 -8
- package/dist/localisation/en-GB.js.map +2 -2
- package/dist/providers/HttpProvider.js +4 -4
- package/dist/providers/HttpProvider.js.map +2 -2
- package/dist/providers/ManifestProvider.js +2 -2
- package/dist/providers/ManifestProvider.js.map +2 -2
- package/dist/providers/SessionCacheProvider.js +6 -3
- package/dist/providers/SessionCacheProvider.js.map +2 -2
- package/dist/providers/file-provider.js +2 -2
- package/dist/providers/file-provider.js.map +2 -2
- package/dist/services/ContensisCliService.js +370 -22
- package/dist/services/ContensisCliService.js.map +3 -3
- package/dist/shell.js +14 -1
- package/dist/shell.js.map +2 -2
- package/dist/util/assert.js +62 -0
- package/dist/util/assert.js.map +7 -0
- package/dist/util/index.js +11 -36
- package/dist/util/index.js.map +2 -2
- package/dist/util/logger.js +17 -6
- package/dist/util/logger.js.map +2 -2
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +2 -2
- package/src/commands/create.ts +118 -0
- package/src/commands/get.ts +48 -1
- package/src/commands/import.ts +86 -0
- package/src/commands/list.ts +80 -1
- package/src/commands/remove.ts +91 -1
- package/src/localisation/en-GB.ts +62 -9
- package/src/models/Cache.d.ts +2 -1
- package/src/providers/HttpProvider.ts +1 -1
- package/src/providers/ManifestProvider.ts +1 -1
- package/src/providers/SessionCacheProvider.ts +6 -1
- package/src/providers/file-provider.ts +1 -1
- package/src/services/ContensisCliService.ts +480 -24
- package/src/shell.ts +14 -1
- package/src/util/assert.ts +35 -0
- package/src/util/index.ts +15 -36
- package/src/util/logger.ts +18 -6
- package/src/version.ts +1 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export const isSharedSecret = (str = '') =>
|
|
2
|
+
str.length > 80 && str.split('-').length === 3 ? str : undefined;
|
|
3
|
+
|
|
4
|
+
export const isPassword = (str = '') =>
|
|
5
|
+
!isSharedSecret(str) ? str : undefined;
|
|
6
|
+
|
|
7
|
+
export const tryParse = (str: any) => {
|
|
8
|
+
try {
|
|
9
|
+
return typeof str === 'object' ? str : JSON.parse(str);
|
|
10
|
+
} catch (e) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const isJson = (str?: string) =>
|
|
16
|
+
typeof str === 'object' || !!tryParse(str);
|
|
17
|
+
|
|
18
|
+
export const tryStringify = (obj: any) => {
|
|
19
|
+
try {
|
|
20
|
+
return typeof obj === 'object' ? JSON.stringify(obj) : obj;
|
|
21
|
+
} catch (e) {
|
|
22
|
+
return obj;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const isSysError = (error: any): error is Error =>
|
|
27
|
+
error?.message !== undefined && error.stack;
|
|
28
|
+
|
|
29
|
+
export const isUuid = (str: string) => {
|
|
30
|
+
// Regular expression to check if string is a valid UUID
|
|
31
|
+
const regexExp =
|
|
32
|
+
/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi;
|
|
33
|
+
|
|
34
|
+
return regexExp.test(str);
|
|
35
|
+
};
|
package/src/util/index.ts
CHANGED
|
@@ -1,42 +1,8 @@
|
|
|
1
|
+
import { ICreateTag, ICreateTagGroup } from 'contensis-management-api';
|
|
1
2
|
import mergeWith from 'lodash/mergeWith';
|
|
2
3
|
import { Logger } from './logger';
|
|
3
4
|
import { LogMessages as enGB } from '../localisation/en-GB.js';
|
|
4
|
-
|
|
5
|
-
export const isSharedSecret = (str = '') =>
|
|
6
|
-
str.length > 80 && str.split('-').length === 3 ? str : undefined;
|
|
7
|
-
|
|
8
|
-
export const isPassword = (str = '') =>
|
|
9
|
-
!isSharedSecret(str) ? str : undefined;
|
|
10
|
-
|
|
11
|
-
export const tryParse = (str: any) => {
|
|
12
|
-
try {
|
|
13
|
-
return typeof str === 'object' ? str : JSON.parse(str);
|
|
14
|
-
} catch (e) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const isJson = (str?: string) =>
|
|
20
|
-
typeof str === 'object' || !!tryParse(str);
|
|
21
|
-
|
|
22
|
-
export const tryStringify = (obj: any) => {
|
|
23
|
-
try {
|
|
24
|
-
return typeof obj === 'object' ? JSON.stringify(obj) : obj;
|
|
25
|
-
} catch (e) {
|
|
26
|
-
return obj;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export const isSysError = (error: any): error is Error =>
|
|
31
|
-
error?.message !== undefined && error.stack;
|
|
32
|
-
|
|
33
|
-
export const isUuid = (str: string) => {
|
|
34
|
-
// Regular expression to check if string is a valid UUID
|
|
35
|
-
const regexExp =
|
|
36
|
-
/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi;
|
|
37
|
-
|
|
38
|
-
return regexExp.test(str);
|
|
39
|
-
};
|
|
5
|
+
import { isObject } from 'lodash';
|
|
40
6
|
|
|
41
7
|
export const url = (alias: string, project: string) => {
|
|
42
8
|
const projectAndAlias =
|
|
@@ -74,3 +40,16 @@ export const Logging = async (language = 'en-GB') => {
|
|
|
74
40
|
Log: Logger,
|
|
75
41
|
};
|
|
76
42
|
};
|
|
43
|
+
|
|
44
|
+
export const splitTagsAndGroups = (
|
|
45
|
+
tagsAndGroups: unknown[] = [],
|
|
46
|
+
tags: ICreateTag[] = [],
|
|
47
|
+
groups: ICreateTagGroup[] = []
|
|
48
|
+
) => {
|
|
49
|
+
for (const item of tagsAndGroups) {
|
|
50
|
+
if (isObject(item) && 'id' in item) {
|
|
51
|
+
if ('name' in item) groups.push(item as ICreateTagGroup);
|
|
52
|
+
else tags.push(item as ICreateTag);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
package/src/util/logger.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
strlen,
|
|
9
9
|
} from 'printable-characters';
|
|
10
10
|
// import ProgressBar from 'progress';
|
|
11
|
-
import { isSysError, tryStringify } from '
|
|
11
|
+
import { isSysError, tryStringify } from './assert';
|
|
12
12
|
|
|
13
13
|
type LogMethod = (content: string) => void;
|
|
14
14
|
type LogErrorMethod = (content: string, err?: any, newline?: string) => void;
|
|
@@ -21,6 +21,22 @@ type LogErrorFunc = (
|
|
|
21
21
|
level?: 'error' | 'critical'
|
|
22
22
|
) => void;
|
|
23
23
|
|
|
24
|
+
const cleanseError = (e: any) => {
|
|
25
|
+
if (e && typeof e === 'object') {
|
|
26
|
+
if (isSysError(e) && e instanceof Error) return e.toString();
|
|
27
|
+
if (e.type === 'undefined') delete e.type;
|
|
28
|
+
if (e.status === 500) delete e.status;
|
|
29
|
+
delete e.stack;
|
|
30
|
+
}
|
|
31
|
+
return JSON.stringify(e, null, 2);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const errorMessages = (errors: any) => {
|
|
35
|
+
if (Array.isArray(errors))
|
|
36
|
+
return errors.map(error => cleanseError(error)).join('\n\n');
|
|
37
|
+
return cleanseError(errors);
|
|
38
|
+
};
|
|
39
|
+
|
|
24
40
|
export class Logger {
|
|
25
41
|
static isUserTerminal = !!process.stdout.columns;
|
|
26
42
|
static getPrefix = () => {
|
|
@@ -45,11 +61,7 @@ export class Logger {
|
|
|
45
61
|
static error: LogErrorMethod = (content, err, newline = '\n') => {
|
|
46
62
|
const message = `${Logger.getPrefix()} ${Logger.errorText(
|
|
47
63
|
`${Logger.isUserTerminal ? '❌' : '[ERROR]'} ${content}${
|
|
48
|
-
err
|
|
49
|
-
? `\n\n${Logger.infoText(
|
|
50
|
-
isSysError(err) ? err.toString() : JSON.stringify(err, null, 2)
|
|
51
|
-
)}`
|
|
52
|
-
: ''
|
|
64
|
+
err ? `\n${Logger.infoText(errorMessages(err))}` : ''
|
|
53
65
|
}`
|
|
54
66
|
)}${newline}`;
|
|
55
67
|
if (progress.active) progress.current.interrupt(message);
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const LIB_VERSION = "1.4.
|
|
1
|
+
export const LIB_VERSION = "1.4.2-beta.0";
|