@aikidosec/ci-api-client 1.0.0 → 1.0.2

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/src/output.ts CHANGED
@@ -1,87 +1,87 @@
1
- import ora, { Ora } from 'ora';
2
- import { program } from './index.js';
3
- import { AxiosError } from 'axios';
4
- import chalk from 'chalk';
5
-
6
- // Output a console message
7
- export const outputLog = (message: string): void => {
8
- if (!process.env.QUIET) {
9
- console.log(message);
10
- }
11
- };
12
-
13
- // Output some message, var, .. if --debug was provided
14
- export const outputDebug = (variable: any): void => {
15
- if (process.env.CLI_DEBUG == true || process.env.CLI_DEBUG == 'true') {
16
- console.log(
17
- chalk.blue(
18
- typeof variable == 'object' ? JSON.stringify(variable) : variable
19
- )
20
- );
21
- }
22
- };
23
-
24
- // Output an error message
25
- // Error output should not take into account the global "quiet" option
26
- export const outputError = (message: string, exitCode: number = 1): void => {
27
- program.error(message, {
28
- exitCode,
29
- });
30
- };
31
-
32
- export const outputHttpError = (axiosError: AxiosError): void => {
33
- if (axiosError.code === 'ECONNREFUSED') {
34
- outputError(
35
- `Could not connect to Aikido API (${axiosError.message}). Please verify your network settings`
36
- );
37
- } else if (
38
- axiosError.response?.status &&
39
- axiosError.response?.status === 401
40
- ) {
41
- outputError(
42
- 'Request failed. The provided api key is most likely no longer valid and has been rotated or revoked. Visit https://app.aikido.dev/settings/integrations/continuous-integration to generate a new key.'
43
- );
44
- } else if (
45
- axiosError.response?.status &&
46
- axiosError.response?.status === 403
47
- ) {
48
- outputError(
49
- 'Could not authenticate with the Aikido API. Please verify your Aikdio API key.'
50
- );
51
- } else if (
52
- axiosError.response?.status &&
53
- axiosError.response?.status === 500
54
- ) {
55
- outputError('Something went wrong contacting the Aikido API.');
56
- }
57
-
58
- const statusStr = axiosError.response?.status
59
- ? ` (${axiosError.response?.status})`
60
- : '';
61
-
62
- if (axiosError.response) {
63
- outputDebug(axiosError.response?.status);
64
- outputDebug(axiosError.response?.headers);
65
- outputDebug(axiosError.response?.data);
66
- }
67
-
68
- outputError(
69
- `Something unexpected went wrong${statusStr}... Please contact us if this problem persists.`
70
- );
71
- };
72
-
73
- // Start a new spinner
74
- // The result of this function can be null if the global "quiet" option
75
- // was set. Spinners should always be treated as optionals
76
- // (e.g. mySpinner?.stop())
77
- export const startSpinner = (message: string): Ora | null => {
78
- if (process.env.QUIET) {
79
- return null;
80
- }
81
-
82
- const spinner = ora(message);
83
- spinner.color = 'magenta';
84
- spinner.start();
85
-
86
- return spinner;
87
- };
1
+ import ora, { Ora } from 'ora';
2
+ import { program } from './index.js';
3
+ import { AxiosError } from 'axios';
4
+ import chalk from 'chalk';
5
+
6
+ // Output a console message
7
+ export const outputLog = (message: string): void => {
8
+ if (!process.env.QUIET) {
9
+ console.log(message);
10
+ }
11
+ };
12
+
13
+ // Output some message, var, .. if --debug was provided
14
+ export const outputDebug = (variable: any): void => {
15
+ if (process.env.CLI_DEBUG == true || process.env.CLI_DEBUG == 'true') {
16
+ console.log(
17
+ chalk.blue(
18
+ typeof variable == 'object' ? JSON.stringify(variable) : variable
19
+ )
20
+ );
21
+ }
22
+ };
23
+
24
+ // Output an error message
25
+ // Error output should not take into account the global "quiet" option
26
+ export const outputError = (message: string, exitCode: number = 1): void => {
27
+ program.error(message, {
28
+ exitCode,
29
+ });
30
+ };
31
+
32
+ export const outputHttpError = (axiosError: AxiosError): void => {
33
+ if (axiosError.code === 'ECONNREFUSED') {
34
+ outputError(
35
+ `Could not connect to Aikido API (${axiosError.message}). Please verify your network settings`
36
+ );
37
+ } else if (
38
+ axiosError.response?.status &&
39
+ axiosError.response?.status === 401
40
+ ) {
41
+ outputError(
42
+ 'Request failed. The provided api key is most likely no longer valid and has been rotated or revoked. Visit https://app.aikido.dev/settings/integrations/continuous-integration to generate a new key.'
43
+ );
44
+ } else if (
45
+ axiosError.response?.status &&
46
+ axiosError.response?.status === 403
47
+ ) {
48
+ outputError(
49
+ 'Could not authenticate with the Aikido API. Please verify your Aikdio API key.'
50
+ );
51
+ } else if (
52
+ axiosError.response?.status &&
53
+ axiosError.response?.status === 500
54
+ ) {
55
+ outputError('Something went wrong contacting the Aikido API.');
56
+ }
57
+
58
+ const statusStr = axiosError.response?.status
59
+ ? ` (${axiosError.response?.status})`
60
+ : '';
61
+
62
+ if (axiosError.response) {
63
+ outputDebug(axiosError.response?.status);
64
+ outputDebug(axiosError.response?.headers);
65
+ outputDebug(axiosError.response?.data);
66
+ }
67
+
68
+ outputError(
69
+ `Something unexpected went wrong${statusStr}... Please contact us if this problem persists.`
70
+ );
71
+ };
72
+
73
+ // Start a new spinner
74
+ // The result of this function can be null if the global "quiet" option
75
+ // was set. Spinners should always be treated as optionals
76
+ // (e.g. mySpinner?.stop())
77
+ export const startSpinner = (message: string): Ora | null => {
78
+ if (process.env.QUIET) {
79
+ return null;
80
+ }
81
+
82
+ const spinner = ora(message);
83
+ spinner.color = 'magenta';
84
+ spinner.start();
85
+
86
+ return spinner;
87
+ };
package/tsconfig.json CHANGED
@@ -1,27 +1,27 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "es2020",
5
- "outDir": "lib",
6
- "rootDir": "src",
7
- "strict": true,
8
- "declaration": true,
9
-
10
- /* Use Node ECMAScript modules */
11
- "moduleResolution": "nodenext",
12
-
13
- /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
14
- "esModuleInterop": true,
15
-
16
- /* Skip type checking of declaration files. */
17
- "skipLibCheck": true,
18
-
19
- /* Remove comments in target files */
20
- "removeComments": true,
21
-
22
- /* Disallow inconsistently-cased references to the same file. */
23
- "forceConsistentCasingInFileNames": true
24
- },
25
- "include": [".env", ".env.*", "src/*.ts", "src/**/*.ts"],
26
- "exclude": ["lib", "dist", "node_modules"]
27
- }
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "es2020",
5
+ "outDir": "lib",
6
+ "rootDir": "src",
7
+ "strict": true,
8
+ "declaration": true,
9
+
10
+ /* Use Node ECMAScript modules */
11
+ "moduleResolution": "nodenext",
12
+
13
+ /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
14
+ "esModuleInterop": true,
15
+
16
+ /* Skip type checking of declaration files. */
17
+ "skipLibCheck": true,
18
+
19
+ /* Remove comments in target files */
20
+ "removeComments": true,
21
+
22
+ /* Disallow inconsistently-cased references to the same file. */
23
+ "forceConsistentCasingInFileNames": true
24
+ },
25
+ "include": [".env", ".env.*", "src/*.ts", "src/**/*.ts"],
26
+ "exclude": ["lib", "dist", "node_modules"]
27
+ }