@fabasoad/sarif-to-slack 0.2.2 → 0.2.4
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/security.yml +1 -0
- package/.github/workflows/send-sarif-to-slack.yml +6 -0
- package/api-extractor.json +2 -2
- package/dist/index.cjs +643 -0
- package/dist/model/SarifModelPerRun.js +3 -3
- package/dist/sarif-to-slack.d.ts +278 -278
- package/dist/tsdoc-metadata.json +11 -11
- package/dist/utils/SarifUtils.js +29 -9
- package/dist/version.js +1 -1
- package/jest.config.json +1 -1
- package/package.json +4 -4
- package/scripts/build.sh +11 -0
- package/src/model/SarifModelPerRun.ts +5 -2
- package/src/utils/SarifUtils.ts +35 -10
- package/src/version.ts +1 -1
- package/test-data/sarif/runs-1-extensions-1-results-0.sarif +24 -0
- package/test-data/sarif/runs-1-extensions-1.sarif +79 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { tryGetRulePropertyByResult } from '../utils/SarifUtils';
|
|
1
|
+
import { findToolComponentByResult, tryGetRulePropertyByResult } from '../utils/SarifUtils';
|
|
2
2
|
import { SecurityLevel, SecuritySeverity } from './types';
|
|
3
3
|
import Logger from '../Logger';
|
|
4
4
|
import { Map as ImmutableMap } from 'immutable';
|
|
@@ -14,7 +14,7 @@ export class SarifModelPerRun {
|
|
|
14
14
|
_securitySeverityMap;
|
|
15
15
|
_securityLevelMap;
|
|
16
16
|
constructor(run) {
|
|
17
|
-
this.toolName = run.
|
|
17
|
+
this.toolName = findToolComponentByResult(run, run.results?.[0]).name;
|
|
18
18
|
this._securitySeverityMap = ImmutableMap().asMutable();
|
|
19
19
|
this._securityLevelMap = ImmutableMap().asMutable();
|
|
20
20
|
this.buildSecuritySeverityMap(run);
|
|
@@ -87,4 +87,4 @@ export class SarifModelPerRun {
|
|
|
87
87
|
return sortSecurityLevelMap(this._securityLevelMap);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
//# sourceMappingUR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a service to send a Slack messages based on the provided
|
|
6
|
-
* SARIF (Static Analysis Results Interchange Format) files.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* import { SarifToSlackService, FooterType } from '@fabasoad/sarif-to-slack';
|
|
11
|
-
*
|
|
12
|
-
* const service = await SarifToSlackService.create({
|
|
13
|
-
* webhookUrl: 'https://hooks.slack.com/services/your/webhook/url',
|
|
14
|
-
* sarifPath: 'path/to/your/sarif/file.sarif',
|
|
15
|
-
* log: {
|
|
16
|
-
* level: LogLevel.Info,
|
|
17
|
-
* template: '[{{logLevelName}}] [{{name}}] {{dateIsoStr}} ',
|
|
18
|
-
* colored: false,
|
|
19
|
-
* },
|
|
20
|
-
* username: 'SARIF Bot',
|
|
21
|
-
* iconUrl: 'https://example.com/icon.png',
|
|
22
|
-
* color: '#36a64f',
|
|
23
|
-
* header: {
|
|
24
|
-
* include: true,
|
|
25
|
-
* value: 'SARIF Analysis Results'
|
|
26
|
-
* },
|
|
27
|
-
* footer: {
|
|
28
|
-
* include: true,
|
|
29
|
-
* type: FooterType.PLAIN_TEXT,
|
|
30
|
-
* value: 'Generated by @fabasoad/sarif-to-slack'
|
|
31
|
-
* },
|
|
32
|
-
* actor: {
|
|
33
|
-
* include: true,
|
|
34
|
-
* value: 'fabasoad'
|
|
35
|
-
* },
|
|
36
|
-
* run: {
|
|
37
|
-
* include: true
|
|
38
|
-
* },
|
|
39
|
-
* });
|
|
40
|
-
* await service.sendAll();
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
|
-
* @see {@link SarifToSlackService}
|
|
44
|
-
*
|
|
45
|
-
* @packageDocumentation
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
import type { Log } from 'sarif';
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Enum representing how to calculate results.
|
|
52
|
-
* @public
|
|
53
|
-
*/
|
|
54
|
-
export declare enum CalculateResultsBy {
|
|
55
|
-
/**
|
|
56
|
-
* Calculates results by the security level of the findings: Error, Warning,
|
|
57
|
-
* Note and Unknown. At first, it tries to get the security level from runs[].results[].level
|
|
58
|
-
* property. If it is not defined, it tries to get the security level from the
|
|
59
|
-
* respective rule of each result, using the rules[].properties['problem.severity']
|
|
60
|
-
* property.
|
|
61
|
-
*/
|
|
62
|
-
Level = 0,
|
|
63
|
-
/**
|
|
64
|
-
* Calculates results by the security severity of the findings: Critical, High,
|
|
65
|
-
* Medium, Low, None and Unknown. it tries to get the security severity from the
|
|
66
|
-
* respective rule of each result, using the rules[].properties['security-severity']
|
|
67
|
-
* property. This property contains CVSS score, which is then mapped to the
|
|
68
|
-
* security severity value.
|
|
69
|
-
*/
|
|
70
|
-
Severity = 1
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Options for the footer of a Slack message. "type" is ignored if "value" is
|
|
75
|
-
* not defined.
|
|
76
|
-
* @public
|
|
77
|
-
*/
|
|
78
|
-
export declare type FooterOptions = IncludeAwareWithValueOptions & {
|
|
79
|
-
type?: FooterType;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Enum representing the type of footer in a Slack message.
|
|
84
|
-
* @public
|
|
85
|
-
*/
|
|
86
|
-
export declare enum FooterType {
|
|
87
|
-
/**
|
|
88
|
-
* Represents a plain text footer. Text is not formatted and appears as-is.
|
|
89
|
-
*/
|
|
90
|
-
PlainText = "plain_text",
|
|
91
|
-
/**
|
|
92
|
-
* Represents a footer with Markdown formatting. Text can include formatting
|
|
93
|
-
* such as bold, italics, and links.
|
|
94
|
-
*/
|
|
95
|
-
Markdown = "mrkdwn"
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Enum representing how to group results.
|
|
100
|
-
* @public
|
|
101
|
-
*/
|
|
102
|
-
export declare enum GroupResultsBy {
|
|
103
|
-
/**
|
|
104
|
-
* Groups results by the tool name. Particularly, groups by the runs[].tool.driver.name
|
|
105
|
-
* property from the SARIF file(s).
|
|
106
|
-
*/
|
|
107
|
-
ToolName = 0,
|
|
108
|
-
/**
|
|
109
|
-
* Groups results by the run. It provides the result from each run individually.
|
|
110
|
-
*/
|
|
111
|
-
Run = 1,
|
|
112
|
-
/**
|
|
113
|
-
* Does not group results. It provides the result from all the runs from all
|
|
114
|
-
* the provided SARIF files.
|
|
115
|
-
*/
|
|
116
|
-
Total = 2
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Type representing properties that indicate whether to include certain information
|
|
121
|
-
* in the Slack message.
|
|
122
|
-
* @public
|
|
123
|
-
*/
|
|
124
|
-
export declare type IncludeAwareOptions = {
|
|
125
|
-
include: boolean;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Type representing properties that indicate whether to include certain information
|
|
130
|
-
* in the Slack message, along with an optional value.
|
|
131
|
-
* @public
|
|
132
|
-
*/
|
|
133
|
-
export declare type IncludeAwareWithValueOptions = IncludeAwareOptions & {
|
|
134
|
-
value?: string;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Enum representing log levels for the service.
|
|
139
|
-
* @public
|
|
140
|
-
*/
|
|
141
|
-
export declare enum LogLevel {
|
|
142
|
-
/**
|
|
143
|
-
* Represents the most verbose logging level, typically used for detailed
|
|
144
|
-
* debugging information.
|
|
145
|
-
*/
|
|
146
|
-
Silly = 0,
|
|
147
|
-
/**
|
|
148
|
-
* Represents a logging level for tracing the flow of the application.
|
|
149
|
-
*/
|
|
150
|
-
Trace = 1,
|
|
151
|
-
/**
|
|
152
|
-
* Represents a logging level for debugging information that is less verbose
|
|
153
|
-
* than silly.
|
|
154
|
-
*/
|
|
155
|
-
Debug = 2,
|
|
156
|
-
/**
|
|
157
|
-
* Represents a logging level for general informational messages that highlight
|
|
158
|
-
* the progress of the application.
|
|
159
|
-
*/
|
|
160
|
-
Info = 3,
|
|
161
|
-
/**
|
|
162
|
-
* Represents a logging level for potentially harmful situations that require
|
|
163
|
-
* attention.
|
|
164
|
-
*/
|
|
165
|
-
Warning = 4,
|
|
166
|
-
/**
|
|
167
|
-
* Represents a logging level for error conditions that do not require immediate
|
|
168
|
-
* action but should be noted.
|
|
169
|
-
*/
|
|
170
|
-
Error = 5,
|
|
171
|
-
/**
|
|
172
|
-
* Represents a logging level for critical errors that require immediate attention
|
|
173
|
-
* and may cause the application to terminate.
|
|
174
|
-
*/
|
|
175
|
-
Fatal = 6
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Options for logging.
|
|
180
|
-
* @public
|
|
181
|
-
*/
|
|
182
|
-
export declare type LogOptions = {
|
|
183
|
-
level?: LogLevel;
|
|
184
|
-
/**
|
|
185
|
-
* More details here: https://github.com/fullstack-build/tslog?tab=readme-ov-file#pretty-templates-and-styles-color-settings
|
|
186
|
-
*/
|
|
187
|
-
template?: string;
|
|
188
|
-
colored?: boolean;
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Type representing a SARIF log.
|
|
193
|
-
* @public
|
|
194
|
-
*/
|
|
195
|
-
export declare type SarifLog = Log;
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Options for how to output the results in the Slack message.
|
|
199
|
-
* @public
|
|
200
|
-
*/
|
|
201
|
-
export declare type SarifToSlackOutput = {
|
|
202
|
-
groupBy?: GroupResultsBy;
|
|
203
|
-
calculateBy?: CalculateResultsBy;
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Service to convert SARIF files to Slack messages and send them.
|
|
208
|
-
* @public
|
|
209
|
-
*/
|
|
210
|
-
export declare class SarifToSlackService {
|
|
211
|
-
private readonly _slackMessages;
|
|
212
|
-
private constructor();
|
|
213
|
-
/**
|
|
214
|
-
* Gets the Slack messages prepared for each SARIF file.
|
|
215
|
-
* @returns A read-only map where keys are SARIF file paths and values are SlackMessage instances.
|
|
216
|
-
* @public
|
|
217
|
-
*/
|
|
218
|
-
get slackMessages(): ReadonlyMap<string, SlackMessage>;
|
|
219
|
-
/**
|
|
220
|
-
* Creates an instance of SarifToSlackService.
|
|
221
|
-
* @param opts - Options for the service, including webhook URL, SARIF path, and other configurations.
|
|
222
|
-
* @returns A promise that resolves to an instance of SarifToSlackService.
|
|
223
|
-
* @throws Error if no SARIF files are found at the provided path.
|
|
224
|
-
* @public
|
|
225
|
-
*/
|
|
226
|
-
static create(opts: SarifToSlackServiceOptions): Promise<SarifToSlackService>;
|
|
227
|
-
/**
|
|
228
|
-
* Sends all prepared Slack messages.
|
|
229
|
-
* @returns A promise that resolves when all messages have been sent.
|
|
230
|
-
* @throws Error if a Slack message was not prepared for a SARIF path.
|
|
231
|
-
* @public
|
|
232
|
-
*/
|
|
233
|
-
sendAll(): Promise<void>;
|
|
234
|
-
/**
|
|
235
|
-
* Sends a Slack message for a specific SARIF path.
|
|
236
|
-
* @param sarifPath - The path of the SARIF file for which the message should be sent.
|
|
237
|
-
* @returns A promise that resolves when the message has been sent.
|
|
238
|
-
* @throws Error if a Slack message was not prepared for the given SARIF path.
|
|
239
|
-
* @public
|
|
240
|
-
*/
|
|
241
|
-
send(sarifPath: string): Promise<void>;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Options for the SarifToSlackService.
|
|
246
|
-
* @public
|
|
247
|
-
*/
|
|
248
|
-
export declare type SarifToSlackServiceOptions = {
|
|
249
|
-
webhookUrl: string;
|
|
250
|
-
sarifPath: string;
|
|
251
|
-
username?: string;
|
|
252
|
-
iconUrl?: string;
|
|
253
|
-
color?: string;
|
|
254
|
-
log?: LogOptions;
|
|
255
|
-
header?: IncludeAwareWithValueOptions;
|
|
256
|
-
footer?: FooterOptions;
|
|
257
|
-
actor?: IncludeAwareWithValueOptions;
|
|
258
|
-
run?: IncludeAwareOptions;
|
|
259
|
-
output?: SarifToSlackOutput;
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Interface for a Slack message that can be sent.
|
|
264
|
-
* @public
|
|
265
|
-
*/
|
|
266
|
-
export declare interface SlackMessage {
|
|
267
|
-
/**
|
|
268
|
-
* Sends the Slack message.
|
|
269
|
-
* @returns A promise that resolves to the response from the Slack webhook.
|
|
270
|
-
*/
|
|
271
|
-
send: () => Promise<string>;
|
|
272
|
-
/**
|
|
273
|
-
* The SARIF log associated with this Slack message.
|
|
274
|
-
*/
|
|
275
|
-
sarif: SarifLog;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
export { }
|
|
1
|
+
/**
|
|
2
|
+
* Sarif to Slack message converter library.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* This library provides a service to send a Slack messages based on the provided
|
|
6
|
+
* SARIF (Static Analysis Results Interchange Format) files.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { SarifToSlackService, FooterType } from '@fabasoad/sarif-to-slack';
|
|
11
|
+
*
|
|
12
|
+
* const service = await SarifToSlackService.create({
|
|
13
|
+
* webhookUrl: 'https://hooks.slack.com/services/your/webhook/url',
|
|
14
|
+
* sarifPath: 'path/to/your/sarif/file.sarif',
|
|
15
|
+
* log: {
|
|
16
|
+
* level: LogLevel.Info,
|
|
17
|
+
* template: '[{{logLevelName}}] [{{name}}] {{dateIsoStr}} ',
|
|
18
|
+
* colored: false,
|
|
19
|
+
* },
|
|
20
|
+
* username: 'SARIF Bot',
|
|
21
|
+
* iconUrl: 'https://example.com/icon.png',
|
|
22
|
+
* color: '#36a64f',
|
|
23
|
+
* header: {
|
|
24
|
+
* include: true,
|
|
25
|
+
* value: 'SARIF Analysis Results'
|
|
26
|
+
* },
|
|
27
|
+
* footer: {
|
|
28
|
+
* include: true,
|
|
29
|
+
* type: FooterType.PLAIN_TEXT,
|
|
30
|
+
* value: 'Generated by @fabasoad/sarif-to-slack'
|
|
31
|
+
* },
|
|
32
|
+
* actor: {
|
|
33
|
+
* include: true,
|
|
34
|
+
* value: 'fabasoad'
|
|
35
|
+
* },
|
|
36
|
+
* run: {
|
|
37
|
+
* include: true
|
|
38
|
+
* },
|
|
39
|
+
* });
|
|
40
|
+
* await service.sendAll();
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @see {@link SarifToSlackService}
|
|
44
|
+
*
|
|
45
|
+
* @packageDocumentation
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
import type { Log } from 'sarif';
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Enum representing how to calculate results.
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
export declare enum CalculateResultsBy {
|
|
55
|
+
/**
|
|
56
|
+
* Calculates results by the security level of the findings: Error, Warning,
|
|
57
|
+
* Note and Unknown. At first, it tries to get the security level from runs[].results[].level
|
|
58
|
+
* property. If it is not defined, it tries to get the security level from the
|
|
59
|
+
* respective rule of each result, using the rules[].properties['problem.severity']
|
|
60
|
+
* property.
|
|
61
|
+
*/
|
|
62
|
+
Level = 0,
|
|
63
|
+
/**
|
|
64
|
+
* Calculates results by the security severity of the findings: Critical, High,
|
|
65
|
+
* Medium, Low, None and Unknown. it tries to get the security severity from the
|
|
66
|
+
* respective rule of each result, using the rules[].properties['security-severity']
|
|
67
|
+
* property. This property contains CVSS score, which is then mapped to the
|
|
68
|
+
* security severity value.
|
|
69
|
+
*/
|
|
70
|
+
Severity = 1
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Options for the footer of a Slack message. "type" is ignored if "value" is
|
|
75
|
+
* not defined.
|
|
76
|
+
* @public
|
|
77
|
+
*/
|
|
78
|
+
export declare type FooterOptions = IncludeAwareWithValueOptions & {
|
|
79
|
+
type?: FooterType;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Enum representing the type of footer in a Slack message.
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
export declare enum FooterType {
|
|
87
|
+
/**
|
|
88
|
+
* Represents a plain text footer. Text is not formatted and appears as-is.
|
|
89
|
+
*/
|
|
90
|
+
PlainText = "plain_text",
|
|
91
|
+
/**
|
|
92
|
+
* Represents a footer with Markdown formatting. Text can include formatting
|
|
93
|
+
* such as bold, italics, and links.
|
|
94
|
+
*/
|
|
95
|
+
Markdown = "mrkdwn"
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Enum representing how to group results.
|
|
100
|
+
* @public
|
|
101
|
+
*/
|
|
102
|
+
export declare enum GroupResultsBy {
|
|
103
|
+
/**
|
|
104
|
+
* Groups results by the tool name. Particularly, groups by the runs[].tool.driver.name
|
|
105
|
+
* property from the SARIF file(s).
|
|
106
|
+
*/
|
|
107
|
+
ToolName = 0,
|
|
108
|
+
/**
|
|
109
|
+
* Groups results by the run. It provides the result from each run individually.
|
|
110
|
+
*/
|
|
111
|
+
Run = 1,
|
|
112
|
+
/**
|
|
113
|
+
* Does not group results. It provides the result from all the runs from all
|
|
114
|
+
* the provided SARIF files.
|
|
115
|
+
*/
|
|
116
|
+
Total = 2
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Type representing properties that indicate whether to include certain information
|
|
121
|
+
* in the Slack message.
|
|
122
|
+
* @public
|
|
123
|
+
*/
|
|
124
|
+
export declare type IncludeAwareOptions = {
|
|
125
|
+
include: boolean;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Type representing properties that indicate whether to include certain information
|
|
130
|
+
* in the Slack message, along with an optional value.
|
|
131
|
+
* @public
|
|
132
|
+
*/
|
|
133
|
+
export declare type IncludeAwareWithValueOptions = IncludeAwareOptions & {
|
|
134
|
+
value?: string;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Enum representing log levels for the service.
|
|
139
|
+
* @public
|
|
140
|
+
*/
|
|
141
|
+
export declare enum LogLevel {
|
|
142
|
+
/**
|
|
143
|
+
* Represents the most verbose logging level, typically used for detailed
|
|
144
|
+
* debugging information.
|
|
145
|
+
*/
|
|
146
|
+
Silly = 0,
|
|
147
|
+
/**
|
|
148
|
+
* Represents a logging level for tracing the flow of the application.
|
|
149
|
+
*/
|
|
150
|
+
Trace = 1,
|
|
151
|
+
/**
|
|
152
|
+
* Represents a logging level for debugging information that is less verbose
|
|
153
|
+
* than silly.
|
|
154
|
+
*/
|
|
155
|
+
Debug = 2,
|
|
156
|
+
/**
|
|
157
|
+
* Represents a logging level for general informational messages that highlight
|
|
158
|
+
* the progress of the application.
|
|
159
|
+
*/
|
|
160
|
+
Info = 3,
|
|
161
|
+
/**
|
|
162
|
+
* Represents a logging level for potentially harmful situations that require
|
|
163
|
+
* attention.
|
|
164
|
+
*/
|
|
165
|
+
Warning = 4,
|
|
166
|
+
/**
|
|
167
|
+
* Represents a logging level for error conditions that do not require immediate
|
|
168
|
+
* action but should be noted.
|
|
169
|
+
*/
|
|
170
|
+
Error = 5,
|
|
171
|
+
/**
|
|
172
|
+
* Represents a logging level for critical errors that require immediate attention
|
|
173
|
+
* and may cause the application to terminate.
|
|
174
|
+
*/
|
|
175
|
+
Fatal = 6
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Options for logging.
|
|
180
|
+
* @public
|
|
181
|
+
*/
|
|
182
|
+
export declare type LogOptions = {
|
|
183
|
+
level?: LogLevel;
|
|
184
|
+
/**
|
|
185
|
+
* More details here: https://github.com/fullstack-build/tslog?tab=readme-ov-file#pretty-templates-and-styles-color-settings
|
|
186
|
+
*/
|
|
187
|
+
template?: string;
|
|
188
|
+
colored?: boolean;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Type representing a SARIF log.
|
|
193
|
+
* @public
|
|
194
|
+
*/
|
|
195
|
+
export declare type SarifLog = Log;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Options for how to output the results in the Slack message.
|
|
199
|
+
* @public
|
|
200
|
+
*/
|
|
201
|
+
export declare type SarifToSlackOutput = {
|
|
202
|
+
groupBy?: GroupResultsBy;
|
|
203
|
+
calculateBy?: CalculateResultsBy;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Service to convert SARIF files to Slack messages and send them.
|
|
208
|
+
* @public
|
|
209
|
+
*/
|
|
210
|
+
export declare class SarifToSlackService {
|
|
211
|
+
private readonly _slackMessages;
|
|
212
|
+
private constructor();
|
|
213
|
+
/**
|
|
214
|
+
* Gets the Slack messages prepared for each SARIF file.
|
|
215
|
+
* @returns A read-only map where keys are SARIF file paths and values are SlackMessage instances.
|
|
216
|
+
* @public
|
|
217
|
+
*/
|
|
218
|
+
get slackMessages(): ReadonlyMap<string, SlackMessage>;
|
|
219
|
+
/**
|
|
220
|
+
* Creates an instance of SarifToSlackService.
|
|
221
|
+
* @param opts - Options for the service, including webhook URL, SARIF path, and other configurations.
|
|
222
|
+
* @returns A promise that resolves to an instance of SarifToSlackService.
|
|
223
|
+
* @throws Error if no SARIF files are found at the provided path.
|
|
224
|
+
* @public
|
|
225
|
+
*/
|
|
226
|
+
static create(opts: SarifToSlackServiceOptions): Promise<SarifToSlackService>;
|
|
227
|
+
/**
|
|
228
|
+
* Sends all prepared Slack messages.
|
|
229
|
+
* @returns A promise that resolves when all messages have been sent.
|
|
230
|
+
* @throws Error if a Slack message was not prepared for a SARIF path.
|
|
231
|
+
* @public
|
|
232
|
+
*/
|
|
233
|
+
sendAll(): Promise<void>;
|
|
234
|
+
/**
|
|
235
|
+
* Sends a Slack message for a specific SARIF path.
|
|
236
|
+
* @param sarifPath - The path of the SARIF file for which the message should be sent.
|
|
237
|
+
* @returns A promise that resolves when the message has been sent.
|
|
238
|
+
* @throws Error if a Slack message was not prepared for the given SARIF path.
|
|
239
|
+
* @public
|
|
240
|
+
*/
|
|
241
|
+
send(sarifPath: string): Promise<void>;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Options for the SarifToSlackService.
|
|
246
|
+
* @public
|
|
247
|
+
*/
|
|
248
|
+
export declare type SarifToSlackServiceOptions = {
|
|
249
|
+
webhookUrl: string;
|
|
250
|
+
sarifPath: string;
|
|
251
|
+
username?: string;
|
|
252
|
+
iconUrl?: string;
|
|
253
|
+
color?: string;
|
|
254
|
+
log?: LogOptions;
|
|
255
|
+
header?: IncludeAwareWithValueOptions;
|
|
256
|
+
footer?: FooterOptions;
|
|
257
|
+
actor?: IncludeAwareWithValueOptions;
|
|
258
|
+
run?: IncludeAwareOptions;
|
|
259
|
+
output?: SarifToSlackOutput;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Interface for a Slack message that can be sent.
|
|
264
|
+
* @public
|
|
265
|
+
*/
|
|
266
|
+
export declare interface SlackMessage {
|
|
267
|
+
/**
|
|
268
|
+
* Sends the Slack message.
|
|
269
|
+
* @returns A promise that resolves to the response from the Slack webhook.
|
|
270
|
+
*/
|
|
271
|
+
send: () => Promise<string>;
|
|
272
|
+
/**
|
|
273
|
+
* The SARIF log associated with this Slack message.
|
|
274
|
+
*/
|
|
275
|
+
sarif: SarifLog;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export { }
|
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
-
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
-
{
|
|
4
|
-
"tsdocVersion": "0.12",
|
|
5
|
-
"toolPackages": [
|
|
6
|
-
{
|
|
7
|
-
"packageName": "@microsoft/api-extractor",
|
|
8
|
-
"packageVersion": "7.52.9"
|
|
9
|
-
}
|
|
10
|
-
]
|
|
11
|
-
}
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.52.9"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|