@fabasoad/sarif-to-slack 1.3.5 → 1.4.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/.github/workflows/release.yml +18 -9
- package/.github/workflows/security.yml +1 -0
- package/.github/workflows/send-sarif-to-slack.yml +49 -17
- package/.github/workflows/unit-tests.yml +3 -3
- package/.pre-commit-config.yaml +5 -5
- package/.tool-versions +1 -1
- package/Makefile +13 -13
- package/README.md +8 -7
- package/api-extractor.json +1 -1
- package/biome.json +1 -1
- package/dist/SarifToSlackClient.d.ts +0 -1
- package/dist/SarifToSlackClient.d.ts.map +1 -1
- package/dist/SarifToSlackClient.js +12 -9
- package/dist/globalState.d.ts +2 -0
- package/dist/globalState.d.ts.map +1 -0
- package/dist/globalState.js +2 -0
- package/dist/index.cjs +86 -100
- package/dist/index.d.ts +36 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/model/Finding.js +7 -6
- package/dist/model/FindingArray.js +1 -1
- package/dist/model/SendIf.js +1 -1
- package/dist/model/SlackMessage.d.ts.map +1 -1
- package/dist/model/SlackMessage.js +6 -6
- package/dist/model/color/Color.d.ts.map +1 -1
- package/dist/model/color/Color.js +1 -1
- package/dist/model/color/ColorIdentification.js +7 -7
- package/dist/model/color/ColorOptions.d.ts.map +1 -1
- package/dist/processors/CodeQLProcessor.js +1 -1
- package/dist/processors/CommonProcessor.js +1 -1
- package/dist/processors/ProcessorFactory.js +1 -1
- package/dist/processors/SnykProcessor.js +2 -1
- package/dist/representations/CompactGroupByRepresentation.js +1 -1
- package/dist/representations/CompactGroupByRunPerLevelRepresentation.js +1 -1
- package/dist/representations/CompactGroupByRunPerSeverityRepresentation.js +1 -1
- package/dist/representations/CompactGroupByRunRepresentation.js +1 -1
- package/dist/representations/CompactGroupBySarifPerLevelRepresentation.js +1 -1
- package/dist/representations/CompactGroupBySarifPerSeverityRepresentation.js +1 -1
- package/dist/representations/CompactGroupBySarifRepresentation.js +1 -1
- package/dist/representations/CompactGroupByToolNamePerLevelRepresentation.js +1 -1
- package/dist/representations/CompactGroupByToolNamePerSeverityRepresentation.js +1 -1
- package/dist/representations/CompactGroupByToolNameRepresentation.js +1 -1
- package/dist/representations/CompactTotalPerLevelRepresentation.js +1 -1
- package/dist/representations/CompactTotalPerSeverityRepresentation.js +1 -1
- package/dist/representations/CompactTotalRepresentation.js +1 -1
- package/dist/representations/Representation.js +1 -1
- package/dist/representations/RepresentationFactory.js +1 -1
- package/dist/representations/TableGroupByRunPerLevelRepresentation.d.ts.map +1 -1
- package/dist/representations/TableGroupByRunPerLevelRepresentation.js +1 -1
- package/dist/representations/TableGroupByRunPerSeverityRepresentation.d.ts.map +1 -1
- package/dist/representations/TableGroupByRunPerSeverityRepresentation.js +1 -1
- package/dist/representations/TableGroupByRunRepresentation.d.ts.map +1 -1
- package/dist/representations/TableGroupByRunRepresentation.js +1 -1
- package/dist/representations/TableGroupBySarifPerLevelRepresentation.d.ts.map +1 -1
- package/dist/representations/TableGroupBySarifPerLevelRepresentation.js +1 -1
- package/dist/representations/TableGroupBySarifPerSeverityRepresentation.d.ts.map +1 -1
- package/dist/representations/TableGroupBySarifPerSeverityRepresentation.js +1 -1
- package/dist/representations/TableGroupBySarifRepresentation.d.ts.map +1 -1
- package/dist/representations/TableGroupBySarifRepresentation.js +1 -1
- package/dist/representations/TableGroupByToolNamePerLevelRepresentation.d.ts.map +1 -1
- package/dist/representations/TableGroupByToolNamePerLevelRepresentation.js +1 -1
- package/dist/representations/TableGroupByToolNamePerSeverityRepresentation.d.ts.map +1 -1
- package/dist/representations/TableGroupByToolNamePerSeverityRepresentation.js +1 -1
- package/dist/representations/TableGroupByToolNameRepresentation.d.ts.map +1 -1
- package/dist/representations/TableGroupByToolNameRepresentation.js +1 -1
- package/dist/representations/TableGroupRepresentation.d.ts +0 -1
- package/dist/representations/TableGroupRepresentation.d.ts.map +1 -1
- package/dist/representations/TableGroupRepresentation.js +4 -4
- package/dist/representations/table/Cell.d.ts.map +1 -1
- package/dist/representations/table/Cell.js +1 -1
- package/dist/representations/table/Column.d.ts +0 -1
- package/dist/representations/table/Column.d.ts.map +1 -1
- package/dist/representations/table/Column.js +4 -4
- package/dist/representations/table/Row.d.ts +0 -1
- package/dist/representations/table/Row.d.ts.map +1 -1
- package/dist/representations/table/Row.js +4 -4
- package/dist/representations/table/Table.d.ts.map +1 -1
- package/dist/representations/table/Table.js +1 -1
- package/dist/setupLogger.d.ts +16 -0
- package/dist/setupLogger.d.ts.map +1 -0
- package/dist/setupLogger.js +43 -0
- package/dist/system.js +6 -6
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/types.d.ts +25 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +11 -1
- package/dist/utils/Comparators.js +1 -1
- package/dist/utils/ExtendedArray.js +1 -1
- package/dist/utils/FileUtils.js +3 -3
- package/dist/utils/SarifUtils.js +1 -1
- package/dist/utils/StringUtils.js +1 -1
- package/etc/sarif-to-slack.api.md +17 -1
- package/package.json +24 -22
- package/pnpm-workspace.yaml +8 -0
- package/scripts/build.sh +1 -1
- package/src/SarifToSlackClient.ts +73 -68
- package/src/globalState.ts +11 -0
- package/src/index.ts +23 -12
- package/src/model/Finding.ts +36 -35
- package/src/model/FindingArray.ts +5 -5
- package/src/model/SendIf.ts +25 -25
- package/src/model/SlackMessage.ts +52 -49
- package/src/model/color/Color.ts +7 -7
- package/src/model/color/ColorIdentification.ts +77 -77
- package/src/model/color/ColorOptions.ts +1 -1
- package/src/processors/CodeQLProcessor.ts +3 -3
- package/src/processors/CommonProcessor.ts +24 -24
- package/src/processors/ProcessorFactory.ts +9 -9
- package/src/processors/SnykProcessor.ts +3 -2
- package/src/representations/CompactGroupByRepresentation.ts +20 -20
- package/src/representations/CompactGroupByRunPerLevelRepresentation.ts +2 -2
- package/src/representations/CompactGroupByRunPerSeverityRepresentation.ts +2 -2
- package/src/representations/CompactGroupByRunRepresentation.ts +10 -10
- package/src/representations/CompactGroupBySarifPerLevelRepresentation.ts +2 -2
- package/src/representations/CompactGroupBySarifPerSeverityRepresentation.ts +2 -2
- package/src/representations/CompactGroupBySarifRepresentation.ts +11 -11
- package/src/representations/CompactGroupByToolNamePerLevelRepresentation.ts +2 -2
- package/src/representations/CompactGroupByToolNamePerSeverityRepresentation.ts +2 -2
- package/src/representations/CompactGroupByToolNameRepresentation.ts +10 -10
- package/src/representations/CompactTotalPerLevelRepresentation.ts +2 -2
- package/src/representations/CompactTotalPerSeverityRepresentation.ts +2 -2
- package/src/representations/CompactTotalRepresentation.ts +5 -5
- package/src/representations/Representation.ts +8 -8
- package/src/representations/RepresentationFactory.ts +32 -32
- package/src/representations/TableGroupByRunPerLevelRepresentation.ts +3 -3
- package/src/representations/TableGroupByRunPerSeverityRepresentation.ts +3 -3
- package/src/representations/TableGroupByRunRepresentation.ts +5 -5
- package/src/representations/TableGroupBySarifPerLevelRepresentation.ts +3 -3
- package/src/representations/TableGroupBySarifPerSeverityRepresentation.ts +3 -3
- package/src/representations/TableGroupBySarifRepresentation.ts +9 -9
- package/src/representations/TableGroupByToolNamePerLevelRepresentation.ts +3 -3
- package/src/representations/TableGroupByToolNamePerSeverityRepresentation.ts +3 -3
- package/src/representations/TableGroupByToolNameRepresentation.ts +4 -4
- package/src/representations/TableGroupRepresentation.ts +32 -32
- package/src/representations/table/Cell.ts +8 -8
- package/src/representations/table/Column.ts +13 -13
- package/src/representations/table/Row.ts +17 -17
- package/src/representations/table/Table.ts +21 -21
- package/src/setupLogger.ts +62 -0
- package/src/system.ts +6 -6
- package/src/types.ts +39 -13
- package/src/utils/Comparators.ts +6 -6
- package/src/utils/ExtendedArray.ts +1 -1
- package/src/utils/FileUtils.ts +4 -4
- package/src/utils/SarifUtils.ts +6 -6
- package/src/utils/StringUtils.ts +3 -3
- package/tests/integration/SendSarifToSlack.spec.ts +73 -67
- package/tests/representations/CompactGroupByRunPerLevelRepresentation.spec.ts +121 -0
- package/tests/representations/CompactGroupByRunPerSeverityRepresentation.spec.ts +122 -0
- package/tests/representations/CompactGroupBySarifPerLevelRepresentation.spec.ts +132 -0
- package/tests/representations/CompactGroupBySarifPerSeverityRepresentation.spec.ts +133 -0
- package/tests/tsconfig.json +8 -0
- package/tests/vitest.d.ts +1 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +5 -5
- package/tsconfig.test.json +8 -0
- package/vitest.config.ts +22 -0
- package/dist/Logger.d.ts +0 -2
- package/dist/Logger.d.ts.map +0 -1
- package/dist/Logger.js +0 -66
- package/jest.config.json +0 -33
- package/src/Logger.ts +0 -81
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import CompactGroupBySarifPerSeverityRepresentation from '../../src/representations/CompactGroupBySarifPerSeverityRepresentation';
|
|
2
|
+
import FindingArray from '../../src/model/FindingArray';
|
|
3
|
+
import type Finding from '../../src/model/Finding';
|
|
4
|
+
import { SecurityLevel, SecuritySeverity } from '../../src/types';
|
|
5
|
+
import type { RunData, SarifModel } from '../../src/types';
|
|
6
|
+
|
|
7
|
+
function mockFinding(opts: {
|
|
8
|
+
sarifPath?: string,
|
|
9
|
+
runId?: number,
|
|
10
|
+
toolName?: string,
|
|
11
|
+
level?: SecurityLevel,
|
|
12
|
+
severity?: SecuritySeverity,
|
|
13
|
+
}): Finding {
|
|
14
|
+
const finding: Finding = {
|
|
15
|
+
get sarifPath() { return opts.sarifPath ?? '/default.sarif' },
|
|
16
|
+
get runId() { return opts.runId ?? 1 },
|
|
17
|
+
get toolName() { return opts.toolName ?? 'Tool' },
|
|
18
|
+
get cvssScore() { return undefined },
|
|
19
|
+
get level() { return opts.level ?? SecurityLevel.Unknown },
|
|
20
|
+
get severity() { return opts.severity ?? SecuritySeverity.Unknown },
|
|
21
|
+
clone() { return mockFinding(opts) },
|
|
22
|
+
};
|
|
23
|
+
return finding;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function buildModel(
|
|
27
|
+
sarifFiles: string[],
|
|
28
|
+
findings: Finding[],
|
|
29
|
+
): SarifModel {
|
|
30
|
+
const arr = new FindingArray();
|
|
31
|
+
findings.forEach(f => arr.push(f));
|
|
32
|
+
return {
|
|
33
|
+
sarifFiles,
|
|
34
|
+
runs: [{ id: 1, toolName: 'Tool', run: {} as RunData['run'] }],
|
|
35
|
+
findings: arr,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe('(unit): CompactGroupBySarifPerSeverityRepresentation', (): void => {
|
|
40
|
+
describe('compose()', (): void => {
|
|
41
|
+
test('should return "No vulnerabilities found" when there are no sarif files', (): void => {
|
|
42
|
+
const repr = new CompactGroupBySarifPerSeverityRepresentation(buildModel([], []));
|
|
43
|
+
expect(repr.compose()).toBe('No vulnerabilities found');
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('should return group header with "No vulnerabilities found" when file has no findings', (): void => {
|
|
47
|
+
const repr = new CompactGroupBySarifPerSeverityRepresentation(
|
|
48
|
+
buildModel(['/path/to/results.sarif'], []),
|
|
49
|
+
);
|
|
50
|
+
expect(repr.compose()).toBe('_[File 1]_ *results.sarif*\nNo vulnerabilities found');
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test('should compose single finding with correct severity label', (): void => {
|
|
54
|
+
const repr = new CompactGroupBySarifPerSeverityRepresentation(
|
|
55
|
+
buildModel(
|
|
56
|
+
['/path/to/grype.sarif'],
|
|
57
|
+
[mockFinding({ sarifPath: '/path/to/grype.sarif', severity: SecuritySeverity.Critical })],
|
|
58
|
+
),
|
|
59
|
+
);
|
|
60
|
+
expect(repr.compose()).toBe('_[File 1]_ *grype.sarif*\n*Critical*: 1');
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
test('should group and sort findings by severity descending', (): void => {
|
|
64
|
+
const sarifPath = '/scans/results.sarif';
|
|
65
|
+
const findings = [
|
|
66
|
+
mockFinding({ sarifPath, severity: SecuritySeverity.Low }),
|
|
67
|
+
mockFinding({ sarifPath, severity: SecuritySeverity.Critical }),
|
|
68
|
+
mockFinding({ sarifPath, severity: SecuritySeverity.High }),
|
|
69
|
+
mockFinding({ sarifPath, severity: SecuritySeverity.High }),
|
|
70
|
+
];
|
|
71
|
+
const repr = new CompactGroupBySarifPerSeverityRepresentation(
|
|
72
|
+
buildModel([sarifPath], findings),
|
|
73
|
+
);
|
|
74
|
+
expect(repr.compose()).toBe('_[File 1]_ *results.sarif*\n*Critical*: 1, *High*: 2, *Low*: 1');
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('should compose multiple sarif files with incrementing indices', (): void => {
|
|
78
|
+
const file1 = '/scans/grype-01.sarif';
|
|
79
|
+
const file2 = '/scans/grype-02.sarif';
|
|
80
|
+
const findings = [
|
|
81
|
+
mockFinding({ sarifPath: file1, severity: SecuritySeverity.High }),
|
|
82
|
+
mockFinding({ sarifPath: file2, severity: SecuritySeverity.Medium }),
|
|
83
|
+
];
|
|
84
|
+
const repr = new CompactGroupBySarifPerSeverityRepresentation(
|
|
85
|
+
buildModel([file1, file2], findings),
|
|
86
|
+
);
|
|
87
|
+
expect(repr.compose()).toBe(
|
|
88
|
+
'_[File 1]_ *grype-01.sarif*\n*High*: 1\n\n_[File 2]_ *grype-02.sarif*\n*Medium*: 1',
|
|
89
|
+
);
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
test('should show "No vulnerabilities found" for a file that has no matching findings', (): void => {
|
|
93
|
+
const file1 = '/scans/grype-01.sarif';
|
|
94
|
+
const file2 = '/scans/grype-02.sarif';
|
|
95
|
+
const findings = [mockFinding({ sarifPath: file1, severity: SecuritySeverity.Critical })];
|
|
96
|
+
const repr = new CompactGroupBySarifPerSeverityRepresentation(
|
|
97
|
+
buildModel([file1, file2], findings),
|
|
98
|
+
);
|
|
99
|
+
expect(repr.compose()).toBe(
|
|
100
|
+
'_[File 1]_ *grype-01.sarif*\n*Critical*: 1\n\n_[File 2]_ *grype-02.sarif*\nNo vulnerabilities found',
|
|
101
|
+
);
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test('should use only basename for the group title', (): void => {
|
|
105
|
+
const sarifPath = '/very/long/path/to/nested/scan-results.sarif';
|
|
106
|
+
const repr = new CompactGroupBySarifPerSeverityRepresentation(
|
|
107
|
+
buildModel(
|
|
108
|
+
[sarifPath],
|
|
109
|
+
[mockFinding({ sarifPath, severity: SecuritySeverity.Medium })],
|
|
110
|
+
),
|
|
111
|
+
);
|
|
112
|
+
expect(repr.compose()).toBe('_[File 1]_ *scan-results.sarif*\n*Medium*: 1');
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
test('should handle all severity variants correctly', (): void => {
|
|
116
|
+
const sarifPath = '/scans/all-severities.sarif';
|
|
117
|
+
const findings = [
|
|
118
|
+
mockFinding({ sarifPath, severity: SecuritySeverity.Critical }),
|
|
119
|
+
mockFinding({ sarifPath, severity: SecuritySeverity.High }),
|
|
120
|
+
mockFinding({ sarifPath, severity: SecuritySeverity.Medium }),
|
|
121
|
+
mockFinding({ sarifPath, severity: SecuritySeverity.Low }),
|
|
122
|
+
mockFinding({ sarifPath, severity: SecuritySeverity.None }),
|
|
123
|
+
mockFinding({ sarifPath, severity: SecuritySeverity.Unknown }),
|
|
124
|
+
];
|
|
125
|
+
const repr = new CompactGroupBySarifPerSeverityRepresentation(
|
|
126
|
+
buildModel([sarifPath], findings),
|
|
127
|
+
);
|
|
128
|
+
expect(repr.compose()).toBe(
|
|
129
|
+
'_[File 1]_ *all-severities.sarif*\n*Critical*: 1, *High*: 1, *Medium*: 1, *Low*: 1, *None*: 1, *Unknown*: 1',
|
|
130
|
+
);
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vitest/globals" />
|
package/tsconfig.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"declaration": true,
|
|
7
7
|
"declarationDir": "dist",
|
|
8
8
|
"declarationMap": true,
|
|
9
|
-
"emitDecoratorMetadata":
|
|
9
|
+
"emitDecoratorMetadata": false,
|
|
10
10
|
"esModuleInterop": true,
|
|
11
11
|
"experimentalDecorators": true,
|
|
12
12
|
"forceConsistentCasingInFileNames": true,
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"lib": ["es2024"],
|
|
15
15
|
"module": "es2022",
|
|
16
16
|
"moduleResolution": "bundler",
|
|
17
|
-
"rootDir": "
|
|
17
|
+
"rootDir": ".",
|
|
18
18
|
"newLine": "lf",
|
|
19
19
|
"noFallthroughCasesInSwitch": true,
|
|
20
20
|
"noImplicitAny": true,
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"stripInternal": true,
|
|
30
30
|
"target": "es2024",
|
|
31
31
|
"typeRoots": ["node_modules/@types", "@types"],
|
|
32
|
-
"types": ["node"
|
|
32
|
+
"types": ["node"]
|
|
33
33
|
},
|
|
34
|
-
"include": ["src"],
|
|
35
|
-
"exclude": ["node_modules", "dist"
|
|
34
|
+
"include": ["src", "tests"],
|
|
35
|
+
"exclude": ["node_modules", "dist"]
|
|
36
36
|
}
|
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config';
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
test: {
|
|
5
|
+
globals: true,
|
|
6
|
+
clearMocks: true,
|
|
7
|
+
coverage: {
|
|
8
|
+
include: ['**/*.ts'],
|
|
9
|
+
exclude: ['**/*.d.ts', '**/node_modules/**'],
|
|
10
|
+
reporter: ['lcov', 'text', 'text-summary'],
|
|
11
|
+
thresholds: {
|
|
12
|
+
branches: 10,
|
|
13
|
+
functions: 40,
|
|
14
|
+
lines: 25,
|
|
15
|
+
statements: 30,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
environment: 'node',
|
|
19
|
+
include: ['**/*.spec.ts'],
|
|
20
|
+
testTimeout: 20000,
|
|
21
|
+
},
|
|
22
|
+
});
|
package/dist/Logger.d.ts
DELETED
package/dist/Logger.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../src/Logger.ts"],"names":[],"mappings":""}
|
package/dist/Logger.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { Logger as TSLogger } from 'tslog';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { isDebug } from './system';
|
|
4
|
-
const LogLevelItems = ['silly', 'trace', 'debug', 'info', 'warning', 'error', 'fatal'];
|
|
5
|
-
/**
|
|
6
|
-
* Logger class for managing logging operations.
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
export default class Logger {
|
|
10
|
-
static APP_NAME = '@fabasoad/sarif-to-slack';
|
|
11
|
-
static DEFAULT_LOG_LEVEL = 'info';
|
|
12
|
-
static DEFAULT_LOG_TEMPLATE = '[{{logLevelName}}] [{{name}}] {{dateIsoStr}} ';
|
|
13
|
-
static DEFAULT_LOG_COLORED = true;
|
|
14
|
-
_instance;
|
|
15
|
-
isLogLevel(v) {
|
|
16
|
-
return LogLevelItems.includes(v);
|
|
17
|
-
}
|
|
18
|
-
getMinLevel() {
|
|
19
|
-
let result = Logger.DEFAULT_LOG_LEVEL;
|
|
20
|
-
if (isDebug()) {
|
|
21
|
-
result = 'silly';
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
const parseResult = z
|
|
25
|
-
.string()
|
|
26
|
-
.refine((v) => this.isLogLevel(v))
|
|
27
|
-
.transform((v) => v)
|
|
28
|
-
.safeParse(process.env.SARIF_TO_SLACK_LOG_LEVEL);
|
|
29
|
-
if (parseResult.success) {
|
|
30
|
-
result = parseResult.data;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return LogLevelItems.findIndex((v) => v === result);
|
|
34
|
-
}
|
|
35
|
-
getLogTemplate() {
|
|
36
|
-
const result = z.string().safeParse(process.env.SARIF_TO_SLACK_LOG_TEMPLATE);
|
|
37
|
-
return result.success ? result.data : Logger.DEFAULT_LOG_TEMPLATE;
|
|
38
|
-
}
|
|
39
|
-
getLogColored() {
|
|
40
|
-
const result = z.stringbool().safeParse(process.env.SARIF_TO_SLACK_LOG_COLORED);
|
|
41
|
-
return result.success ? result.data : Logger.DEFAULT_LOG_COLORED;
|
|
42
|
-
}
|
|
43
|
-
constructor(memberName) {
|
|
44
|
-
this._instance = new TSLogger({
|
|
45
|
-
name: `${Logger.APP_NAME}${memberName === undefined ? '' : `::${memberName}`}`,
|
|
46
|
-
minLevel: this.getMinLevel(),
|
|
47
|
-
type: 'pretty',
|
|
48
|
-
prettyLogTimeZone: 'UTC',
|
|
49
|
-
prettyLogTemplate: this.getLogTemplate(),
|
|
50
|
-
stylePrettyLogs: this.getLogColored(),
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
info(...args) {
|
|
54
|
-
this._instance.info(...args);
|
|
55
|
-
}
|
|
56
|
-
warn(...args) {
|
|
57
|
-
this._instance.warn(...args);
|
|
58
|
-
}
|
|
59
|
-
trace(...args) {
|
|
60
|
-
this._instance.trace(...args);
|
|
61
|
-
}
|
|
62
|
-
debug(...args) {
|
|
63
|
-
this._instance.debug(...args);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTG9nZ2VyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL0xvZ2dlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQWdCLE1BQU0sSUFBSSxRQUFRLEVBQUUsTUFBTSxPQUFPLENBQUE7QUFDeEQsT0FBTyxFQUFFLENBQUMsRUFBMkIsTUFBTSxLQUFLLENBQUM7QUFDakQsT0FBTyxFQUFFLE9BQU8sRUFBRSxNQUFNLFVBQVUsQ0FBQztBQUVuQyxNQUFNLGFBQWEsR0FBRyxDQUFDLE9BQU8sRUFBRSxPQUFPLEVBQUUsT0FBTyxFQ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RSxJQUFJLENBQUMsY0FBYyxFQUFFO1lBQ3hDLGVBQWUsRUFBRSxJQUFJLENBQUMsYUFBYSxFQUFFO1NBQ3RDLENBQUMsQ0FBQTtJQUNKLENBQUM7SUFFTSxJQUFJLENBQUMsR0FBRyxJQUFlO1FBQzVCLElBQUksQ0FBQyxTQUFTLENBQUMsSUFBSSxDQUFDLEdBQUcsSUFBSSxDQUFDLENBQUM7SUFDL0IsQ0FBQztJQUVNLElBQUksQ0FBQyxHQUFHLElBQWU7UUFDNUIsSUFBSSxDQUFDLFNBQVMsQ0FBQyxJQUFJLENBQUMsR0FBRyxJQUFJLENBQUMsQ0FBQztJQUMvQixDQUFDO0lBRU0sS0FBSyxDQUFDLEdBQUcsSUFBZTtRQUM3QixJQUFJLENBQUMsU0FBUyxDQUFDLEtBQUssQ0FBQyxHQUFHLElBQUksQ0FBQyxDQUFDO0lBQ2hDLENBQUM7SUFFTSxLQUFLLENBQUMsR0FBRyxJQUFlO1FBQzdCLElBQUksQ0FBQyxTQUFTLENBQUMsS0FBSyxDQUFDLEdBQUcsSUFBSSxDQUFDLENBQUM7SUFDaEMsQ0FBQyJ9
|
package/jest.config.json
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"clearMocks": true,
|
|
3
|
-
"collectCoverageFrom": [
|
|
4
|
-
"**/*.ts",
|
|
5
|
-
"!**/*.d.ts",
|
|
6
|
-
"!**/node_modules/**"
|
|
7
|
-
],
|
|
8
|
-
"coverageReporters": [
|
|
9
|
-
"lcov", "text", "text-summary"
|
|
10
|
-
],
|
|
11
|
-
"coverageThreshold": {
|
|
12
|
-
"global": {
|
|
13
|
-
"branches": 3,
|
|
14
|
-
"functions": 3,
|
|
15
|
-
"lines": 15,
|
|
16
|
-
"statements": 15
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
"moduleFileExtensions": [
|
|
20
|
-
"js",
|
|
21
|
-
"ts"
|
|
22
|
-
],
|
|
23
|
-
"testEnvironment": "node",
|
|
24
|
-
"testMatch": [
|
|
25
|
-
"**/*.spec.ts"
|
|
26
|
-
],
|
|
27
|
-
"testRunner": "jest-circus/runner",
|
|
28
|
-
"testTimeout": 20000,
|
|
29
|
-
"transform": {
|
|
30
|
-
"^.+\\.ts$": "ts-jest"
|
|
31
|
-
},
|
|
32
|
-
"verbose": true
|
|
33
|
-
}
|
package/src/Logger.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { type ILogObj, Logger as TSLogger } from 'tslog'
|
|
2
|
-
import { z, type ZodSafeParseResult } from 'zod';
|
|
3
|
-
import { isDebug } from './system';
|
|
4
|
-
|
|
5
|
-
const LogLevelItems = ['silly', 'trace', 'debug', 'info', 'warning', 'error', 'fatal'] as const;
|
|
6
|
-
type LogLevel = (typeof LogLevelItems)[number];
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Logger class for managing logging operations.
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
export default class Logger {
|
|
13
|
-
private static APP_NAME: string = '@fabasoad/sarif-to-slack';
|
|
14
|
-
private static DEFAULT_LOG_LEVEL: LogLevel = 'info';
|
|
15
|
-
private static DEFAULT_LOG_TEMPLATE: string = '[{{logLevelName}}] [{{name}}] {{dateIsoStr}} ';
|
|
16
|
-
private static DEFAULT_LOG_COLORED: boolean = true;
|
|
17
|
-
|
|
18
|
-
private readonly _instance: TSLogger<ILogObj>;
|
|
19
|
-
|
|
20
|
-
private isLogLevel(v: string): v is LogLevel {
|
|
21
|
-
return (LogLevelItems as ReadonlyArray<string>).includes(v);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
private getMinLevel(): number {
|
|
25
|
-
let result: LogLevel = Logger.DEFAULT_LOG_LEVEL;
|
|
26
|
-
|
|
27
|
-
if (isDebug()) {
|
|
28
|
-
result = 'silly';
|
|
29
|
-
} else {
|
|
30
|
-
const parseResult: ZodSafeParseResult<LogLevel> = z
|
|
31
|
-
.string()
|
|
32
|
-
.refine((v: string): boolean => this.isLogLevel(v))
|
|
33
|
-
.transform((v: string): LogLevel => v as LogLevel)
|
|
34
|
-
.safeParse(process.env.SARIF_TO_SLACK_LOG_LEVEL);
|
|
35
|
-
if (parseResult.success) {
|
|
36
|
-
result = parseResult.data;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return LogLevelItems.findIndex((v: LogLevel): boolean => v === result);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
private getLogTemplate(): string {
|
|
44
|
-
const result: ZodSafeParseResult<string> =
|
|
45
|
-
z.string().safeParse(process.env.SARIF_TO_SLACK_LOG_TEMPLATE);
|
|
46
|
-
return result.success ? result.data : Logger.DEFAULT_LOG_TEMPLATE;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
private getLogColored(): boolean {
|
|
50
|
-
const result: ZodSafeParseResult<boolean> =
|
|
51
|
-
z.stringbool().safeParse(process.env.SARIF_TO_SLACK_LOG_COLORED);
|
|
52
|
-
return result.success ? result.data : Logger.DEFAULT_LOG_COLORED;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
public constructor(memberName?: string) {
|
|
56
|
-
this._instance = new TSLogger({
|
|
57
|
-
name: `${Logger.APP_NAME}${memberName === undefined ? '' : `::${memberName}`}`,
|
|
58
|
-
minLevel: this.getMinLevel(),
|
|
59
|
-
type: 'pretty',
|
|
60
|
-
prettyLogTimeZone: 'UTC',
|
|
61
|
-
prettyLogTemplate: this.getLogTemplate(),
|
|
62
|
-
stylePrettyLogs: this.getLogColored(),
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
public info(...args: unknown[]): void {
|
|
67
|
-
this._instance.info(...args);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public warn(...args: unknown[]): void {
|
|
71
|
-
this._instance.warn(...args);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
public trace(...args: unknown[]): void {
|
|
75
|
-
this._instance.trace(...args);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
public debug(...args: unknown[]): void {
|
|
79
|
-
this._instance.debug(...args);
|
|
80
|
-
}
|
|
81
|
-
}
|