@fabasoad/sarif-to-slack 0.2.5 → 1.1.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.
Files changed (192) hide show
  1. package/.github/workflows/release.yml +1 -1
  2. package/.github/workflows/security.yml +0 -1
  3. package/.github/workflows/send-sarif-to-slack.yml +145 -73
  4. package/.gitleaksignore +8 -0
  5. package/.pre-commit-config.yaml +3 -3
  6. package/.tool-versions +1 -1
  7. package/dist/Logger.js +4 -1
  8. package/dist/SarifToSlackClient.d.ts +33 -0
  9. package/dist/SarifToSlackClient.d.ts.map +1 -0
  10. package/dist/SarifToSlackClient.js +178 -0
  11. package/dist/SlackMessageBuilder.js +34 -82
  12. package/dist/System.d.ts +1 -3
  13. package/dist/System.d.ts.map +1 -1
  14. package/dist/System.js +10 -3
  15. package/dist/index.cjs +826 -472
  16. package/dist/index.d.ts +35 -12
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +36 -12
  19. package/dist/model/Color.d.ts +80 -0
  20. package/dist/model/Color.d.ts.map +1 -0
  21. package/dist/model/Color.js +106 -0
  22. package/dist/model/Finding.d.ts +2 -0
  23. package/dist/model/Finding.d.ts.map +1 -0
  24. package/dist/model/Finding.js +93 -0
  25. package/dist/model/FindingsArray.d.ts +2 -0
  26. package/dist/model/FindingsArray.d.ts.map +1 -0
  27. package/dist/model/FindingsArray.js +24 -0
  28. package/dist/processors/CodeQLProcessor.d.ts +2 -0
  29. package/dist/processors/CodeQLProcessor.d.ts.map +1 -0
  30. package/dist/processors/CodeQLProcessor.js +17 -0
  31. package/dist/processors/CommonProcessor.d.ts +2 -0
  32. package/dist/processors/CommonProcessor.d.ts.map +1 -0
  33. package/dist/processors/CommonProcessor.js +84 -0
  34. package/dist/processors/ProcessorFactory.d.ts +2 -0
  35. package/dist/processors/ProcessorFactory.d.ts.map +1 -0
  36. package/dist/processors/ProcessorFactory.js +22 -0
  37. package/dist/processors/SnykProcessor.d.ts +2 -0
  38. package/dist/processors/SnykProcessor.d.ts.map +1 -0
  39. package/dist/processors/SnykProcessor.js +18 -0
  40. package/dist/representations/CompactGroupByRepresentation.d.ts +2 -0
  41. package/dist/representations/CompactGroupByRepresentation.d.ts.map +1 -0
  42. package/dist/representations/CompactGroupByRepresentation.js +58 -0
  43. package/dist/representations/CompactGroupByRunPerLevelRepresentation.d.ts +2 -0
  44. package/dist/representations/CompactGroupByRunPerLevelRepresentation.d.ts.map +1 -0
  45. package/dist/representations/CompactGroupByRunPerLevelRepresentation.js +13 -0
  46. package/dist/representations/CompactGroupByRunPerSeverityRepresentation.d.ts +2 -0
  47. package/dist/representations/CompactGroupByRunPerSeverityRepresentation.d.ts.map +1 -0
  48. package/dist/representations/CompactGroupByRunPerSeverityRepresentation.js +13 -0
  49. package/dist/representations/CompactGroupByRunRepresentation.d.ts +2 -0
  50. package/dist/representations/CompactGroupByRunRepresentation.d.ts.map +1 -0
  51. package/dist/representations/CompactGroupByRunRepresentation.js +39 -0
  52. package/dist/representations/CompactGroupBySarifPerLevelRepresentation.d.ts +2 -0
  53. package/dist/representations/CompactGroupBySarifPerLevelRepresentation.d.ts.map +1 -0
  54. package/dist/representations/CompactGroupBySarifPerLevelRepresentation.js +13 -0
  55. package/dist/representations/CompactGroupBySarifPerSeverityRepresentation.d.ts +2 -0
  56. package/dist/representations/CompactGroupBySarifPerSeverityRepresentation.d.ts.map +1 -0
  57. package/dist/representations/CompactGroupBySarifPerSeverityRepresentation.js +13 -0
  58. package/dist/representations/CompactGroupBySarifRepresentation.d.ts +2 -0
  59. package/dist/representations/CompactGroupBySarifRepresentation.d.ts.map +1 -0
  60. package/dist/representations/CompactGroupBySarifRepresentation.js +40 -0
  61. package/dist/representations/CompactGroupByToolNamePerLevelRepresentation.d.ts +2 -0
  62. package/dist/representations/CompactGroupByToolNamePerLevelRepresentation.d.ts.map +1 -0
  63. package/dist/representations/CompactGroupByToolNamePerLevelRepresentation.js +13 -0
  64. package/dist/representations/CompactGroupByToolNamePerSeverityRepresentation.d.ts +2 -0
  65. package/dist/representations/CompactGroupByToolNamePerSeverityRepresentation.d.ts.map +1 -0
  66. package/dist/representations/CompactGroupByToolNamePerSeverityRepresentation.js +13 -0
  67. package/dist/representations/CompactGroupByToolNameRepresentation.d.ts +2 -0
  68. package/dist/representations/CompactGroupByToolNameRepresentation.d.ts.map +1 -0
  69. package/dist/representations/CompactGroupByToolNameRepresentation.js +39 -0
  70. package/dist/representations/CompactTotalPerLevelRepresentation.d.ts +2 -0
  71. package/dist/representations/CompactTotalPerLevelRepresentation.d.ts.map +1 -0
  72. package/dist/representations/CompactTotalPerLevelRepresentation.js +13 -0
  73. package/dist/representations/CompactTotalPerSeverityRepresentation.d.ts +2 -0
  74. package/dist/representations/CompactTotalPerSeverityRepresentation.d.ts.map +1 -0
  75. package/dist/representations/CompactTotalPerSeverityRepresentation.js +13 -0
  76. package/dist/representations/CompactTotalRepresentation.d.ts +2 -0
  77. package/dist/representations/CompactTotalRepresentation.d.ts.map +1 -0
  78. package/dist/representations/CompactTotalRepresentation.js +25 -0
  79. package/dist/representations/Representation.d.ts +2 -0
  80. package/dist/representations/Representation.d.ts.map +1 -0
  81. package/dist/representations/Representation.js +28 -0
  82. package/dist/representations/RepresentationFactory.d.ts +2 -0
  83. package/dist/representations/RepresentationFactory.d.ts.map +1 -0
  84. package/dist/representations/RepresentationFactory.js +37 -0
  85. package/dist/sarif-to-slack.d.ts +347 -85
  86. package/dist/tsdoc-metadata.json +1 -1
  87. package/dist/types.d.ts +215 -51
  88. package/dist/types.d.ts.map +1 -1
  89. package/dist/types.js +225 -33
  90. package/dist/utils/Comparators.d.ts +2 -0
  91. package/dist/utils/Comparators.d.ts.map +1 -0
  92. package/dist/utils/Comparators.js +18 -0
  93. package/dist/utils/ExtendedArray.d.ts +2 -0
  94. package/dist/utils/ExtendedArray.d.ts.map +1 -0
  95. package/dist/utils/ExtendedArray.js +11 -0
  96. package/dist/utils/FileUtils.d.ts +2 -0
  97. package/dist/utils/FileUtils.d.ts.map +1 -0
  98. package/dist/utils/FileUtils.js +51 -0
  99. package/dist/utils/SarifUtils.js +20 -54
  100. package/etc/sarif-to-slack.api.md +162 -99
  101. package/jest.config.json +2 -2
  102. package/package.json +7 -7
  103. package/scripts/save-metadata.sh +12 -10
  104. package/src/Logger.ts +4 -0
  105. package/src/SarifToSlackClient.ts +202 -0
  106. package/src/SlackMessageBuilder.ts +35 -115
  107. package/src/System.ts +9 -2
  108. package/src/index.ts +47 -20
  109. package/src/model/Color.ts +195 -0
  110. package/src/model/Finding.ts +137 -0
  111. package/src/model/FindingsArray.ts +27 -0
  112. package/src/processors/CodeQLProcessor.ts +19 -0
  113. package/src/processors/CommonProcessor.ts +103 -0
  114. package/src/processors/ProcessorFactory.ts +23 -0
  115. package/src/processors/SnykProcessor.ts +19 -0
  116. package/src/representations/CompactGroupByRepresentation.ts +67 -0
  117. package/src/representations/CompactGroupByRunPerLevelRepresentation.ts +14 -0
  118. package/src/representations/CompactGroupByRunPerSeverityRepresentation.ts +14 -0
  119. package/src/representations/CompactGroupByRunRepresentation.ts +44 -0
  120. package/src/representations/CompactGroupBySarifPerLevelRepresentation.ts +15 -0
  121. package/src/representations/CompactGroupBySarifPerSeverityRepresentation.ts +15 -0
  122. package/src/representations/CompactGroupBySarifRepresentation.ts +45 -0
  123. package/src/representations/CompactGroupByToolNamePerLevelRepresentation.ts +15 -0
  124. package/src/representations/CompactGroupByToolNamePerSeverityRepresentation.ts +15 -0
  125. package/src/representations/CompactGroupByToolNameRepresentation.ts +44 -0
  126. package/src/representations/CompactTotalPerLevelRepresentation.ts +14 -0
  127. package/src/representations/CompactTotalPerSeverityRepresentation.ts +14 -0
  128. package/src/representations/CompactTotalRepresentation.ts +27 -0
  129. package/src/representations/Representation.ts +35 -0
  130. package/src/representations/RepresentationFactory.ts +49 -0
  131. package/src/types.ts +270 -53
  132. package/src/utils/Comparators.ts +19 -0
  133. package/src/utils/ExtendedArray.ts +11 -0
  134. package/src/utils/FileUtils.ts +60 -0
  135. package/src/utils/SarifUtils.ts +20 -72
  136. package/test-data/sarif/codeql-python.sarif +1448 -1
  137. package/test-data/sarif/codeql-typescript.sarif +3474 -1
  138. package/test-data/sarif/grype-github-actions.sarif +65 -0
  139. package/test-data/sarif/osv-scanner-composer.sarif +972 -0
  140. package/test-data/sarif/osv-scanner-container.sarif +2278 -0
  141. package/test-data/sarif/osv-scanner-gomodules.sarif +813 -0
  142. package/test-data/sarif/osv-scanner-hex.sarif +147 -0
  143. package/test-data/sarif/osv-scanner-maven.sarif +171 -0
  144. package/test-data/sarif/osv-scanner-npm.sarif +627 -0
  145. package/test-data/sarif/osv-scanner-pip.sarif +206 -0
  146. package/test-data/sarif/osv-scanner-pipenv.sarif +243 -0
  147. package/test-data/sarif/osv-scanner-pnpm.sarif +174 -0
  148. package/test-data/sarif/osv-scanner-poetry.sarif +1893 -0
  149. package/test-data/sarif/osv-scanner-rubygems.sarif +402 -0
  150. package/test-data/sarif/osv-scanner-uv.sarif +206 -0
  151. package/test-data/sarif/osv-scanner-yarn.sarif +5207 -0
  152. package/test-data/sarif/runs-0.sarif +5 -0
  153. package/test-data/sarif/runs-2-tools-2-results-0.sarif +1 -1
  154. package/test-data/sarif/runs-2-tools-2.sarif +1 -1
  155. package/test-data/sarif/runs-3-tools-2-results-0.sarif +1 -1
  156. package/test-data/sarif/runs-3-tools-2.sarif +1 -1
  157. package/test-data/sarif/tmp/codeql-csharp.sarif +1 -0
  158. package/test-data/sarif/tmp/grype-container.sarif +1774 -0
  159. package/test-data/sarif/tmp/runs-1-tools-1-results-0.sarif +18 -0
  160. package/test-data/sarif/tmp/runs-2-tools-2.sarif +686 -0
  161. package/test-data/sarif/trivy-iac.sarif +1 -1
  162. package/tests/integration/SendSarifToSlack.spec.ts +95 -27
  163. package/tsconfig.json +2 -0
  164. package/dist/Processors.d.ts +0 -2
  165. package/dist/Processors.d.ts.map +0 -1
  166. package/dist/Processors.js +0 -61
  167. package/dist/SarifToSlackService.d.ts +0 -39
  168. package/dist/SarifToSlackService.d.ts.map +0 -1
  169. package/dist/SarifToSlackService.js +0 -104
  170. package/dist/metadata.d.ts +0 -2
  171. package/dist/metadata.d.ts.map +0 -1
  172. package/dist/metadata.js +0 -11
  173. package/dist/model/SarifModelPerRun.d.ts +0 -2
  174. package/dist/model/SarifModelPerRun.d.ts.map +0 -1
  175. package/dist/model/SarifModelPerRun.js +0 -90
  176. package/dist/model/SarifModelPerSarif.d.ts +0 -2
  177. package/dist/model/SarifModelPerSarif.d.ts.map +0 -1
  178. package/dist/model/SarifModelPerSarif.js +0 -102
  179. package/dist/model/types.d.ts +0 -2
  180. package/dist/model/types.d.ts.map +0 -1
  181. package/dist/model/types.js +0 -49
  182. package/dist/utils/SortUtils.d.ts +0 -2
  183. package/dist/utils/SortUtils.d.ts.map +0 -1
  184. package/dist/utils/SortUtils.js +0 -20
  185. package/src/Processors.ts +0 -68
  186. package/src/SarifToSlackService.ts +0 -117
  187. package/src/metadata.ts +0 -10
  188. package/src/model/SarifModelPerRun.ts +0 -120
  189. package/src/model/SarifModelPerSarif.ts +0 -126
  190. package/src/model/types.ts +0 -50
  191. package/src/utils/SortUtils.ts +0 -33
  192. package/tests/Processors.spec.ts +0 -76
@@ -2,24 +2,45 @@
2
2
  * Sarif to Slack message converter library.
3
3
  *
4
4
  * @remarks
5
- * This library provides a service to send a Slack messages based on the provided
5
+ * This library provides a client to send a Slack messages based on the provided
6
6
  * SARIF (Static Analysis Results Interchange Format) files.
7
7
  *
8
8
  * @example
9
9
  * ```typescript
10
- * import { SarifToSlackService, FooterType } from '@fabasoad/sarif-to-slack';
10
+ * import {
11
+ * Color,
12
+ * FooterType,
13
+ * LogLevel,
14
+ * RepresentationType,
15
+ * SarifToSlackClient,
16
+ * SendIf
17
+ * } from '@fabasoad/sarif-to-slack';
11
18
  *
12
- * const service = await SarifToSlackService.create({
19
+ * const client: SarifToSlackClient = await SarifToSlackClient.create({
13
20
  * webhookUrl: 'https://hooks.slack.com/services/your/webhook/url',
14
- * sarifPath: 'path/to/your/sarif/file.sarif',
21
+ * username: 'SARIF to Slack Bot',
22
+ * iconUrl: 'https://example.com/icon.png',
23
+ * color: {
24
+ * bySeverity: {
25
+ * critical: new Color('#ff0000'),
26
+ * high: new Color('#ff4500'),
27
+ * medium: new Color('#ffa500'),
28
+ * low: new Color('#ffff00'),
29
+ * none: new Color('#808080'),
30
+ * unknown: new Color('#800080'),
31
+ * empty: new Color('#d3d3d3'),
32
+ * },
33
+ * },
34
+ * sarif: {
35
+ * path: 'path/to/your/sarif-files',
36
+ * recursive: true,
37
+ * extension: 'sarif',
38
+ * },
15
39
  * log: {
16
40
  * level: LogLevel.Info,
17
41
  * template: '[{{logLevelName}}] [{{name}}] {{dateIsoStr}} ',
18
42
  * colored: false,
19
43
  * },
20
- * username: 'SARIF Bot',
21
- * iconUrl: 'https://example.com/icon.png',
22
- * color: '#36a64f',
23
44
  * header: {
24
45
  * include: true,
25
46
  * value: 'SARIF Analysis Results'
@@ -36,40 +57,100 @@
36
57
  * run: {
37
58
  * include: true
38
59
  * },
60
+ * representation: RepresentationType.CompactGroupByToolNamePerSeverity,
61
+ * sendIf: SendIf.MediumOrHigher,
39
62
  * });
40
- * await service.sendAll();
63
+ * await client.send();
41
64
  * ```
42
65
  *
43
- * @see {@link SarifToSlackService}
66
+ * @see {@link SarifToSlackClient}
44
67
  *
45
68
  * @packageDocumentation
46
69
  */
47
70
 
48
- import type { Log } from 'sarif';
49
-
50
71
  /**
51
- * Enum representing how to calculate results.
72
+ * This class represents a color in hex format.
52
73
  * @public
53
74
  */
54
- export declare enum CalculateResultsBy {
75
+ export declare class Color {
76
+ private readonly _color?;
55
77
  /**
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.
78
+ * Creates an instance of {@link Color} class. Before creating an instance of
79
+ * {@link Color} class, it (if applicable) maps CI status into the hex color,
80
+ * and also validates {@param color} to be a valid string that represents a
81
+ * color in hex format.
82
+ * @param color Can be either undefined, valid color in hex format or GitHub
83
+ * CI status (one of: success, failure, cancelled, skipped)
84
+ * @public
61
85
  */
62
- Level = 0,
86
+ constructor(color?: string);
63
87
  /**
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.
88
+ * Returns a valid string that represents a color in hex format, or undefined.
69
89
  */
70
- Severity = 1
90
+ get value(): string | undefined;
91
+ private validateHexColor;
92
+ private mapColor;
71
93
  }
72
94
 
95
+ /**
96
+ * Color schema for the findings with the certain level. Color is used by the
97
+ * level importance, i.e. if at least 1 error finding exists then
98
+ * {@link ColorGroupByLevel.error} color is used, then if at least 1 warning
99
+ * finding exists then {@link ColorGroupByLevel.warning} color is used, etc.
100
+ * @public
101
+ */
102
+ export declare type ColorGroupByLevel = ColorGroupCommon & {
103
+ error?: Color;
104
+ warning?: Color;
105
+ note?: Color;
106
+ };
107
+
108
+ /**
109
+ * Color schema for the findings with the certain severity. Color is used by the
110
+ * severity importance, i.e. if at least 1 critical finding exists then
111
+ * {@link ColorGroupBySeverity.critical} color is used, then if at least 1 high
112
+ * finding exists then {@link ColorGroupBySeverity.high} color is used, etc.
113
+ * @public
114
+ */
115
+ export declare type ColorGroupBySeverity = ColorGroupCommon & {
116
+ critical?: Color;
117
+ high?: Color;
118
+ medium?: Color;
119
+ low?: Color;
120
+ };
121
+
122
+ /**
123
+ * Base type that has common fields for both {@link ColorGroupByLevel} and
124
+ * {@link ColorGroupBySeverity}.
125
+ * @private
126
+ */
127
+ declare type ColorGroupCommon = {
128
+ none?: Color;
129
+ unknown?: Color;
130
+ empty?: Color;
131
+ };
132
+
133
+ /**
134
+ * Represents configuration of the color scheme. If both {@link ColorOptions.byLevel}
135
+ * and {@link ColorOptions.bySeverity} are defined, then {@link ColorOptions.bySeverity}
136
+ * takes precedence.
137
+ * @public
138
+ */
139
+ export declare type ColorOptions = {
140
+ /**
141
+ * Default color if specific color was not found. It is a fallback option.
142
+ */
143
+ default?: Color;
144
+ /**
145
+ * Color scheme for the findings where certain level is presented.
146
+ */
147
+ byLevel?: ColorGroupByLevel;
148
+ /**
149
+ * Color scheme for the findings where certain severity is presented.
150
+ */
151
+ bySeverity?: ColorGroupBySeverity;
152
+ };
153
+
73
154
  /**
74
155
  * Options for the footer of a Slack message. "type" is ignored if "value" is
75
156
  * not defined.
@@ -95,27 +176,6 @@ export declare enum FooterType {
95
176
  Markdown = "mrkdwn"
96
177
  }
97
178
 
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
179
  /**
120
180
  * Type representing properties that indicate whether to include certain information
121
181
  * in the Slack message.
@@ -189,76 +249,278 @@ export declare type LogOptions = {
189
249
  };
190
250
 
191
251
  /**
192
- * Type representing a SARIF log.
252
+ * This represents what type of message should be sent. There are various options
253
+ * to show information from SARIF in Slack message.
254
+ * @public
255
+ */
256
+ export declare enum RepresentationType {
257
+ /**
258
+ * Compact information about findings grouped by Run with the level representation.
259
+ * @example
260
+ * ```text
261
+ * [Run 1] Grype
262
+ * Error: 1, Warning: 4
263
+ * [Run 2] Grype
264
+ * Warning: 1, Note: 20
265
+ * ```
266
+ */
267
+ CompactGroupByRunPerLevel = 0,
268
+ /**
269
+ * Compact information about findings grouped by Run with the severity representation.
270
+ * @example
271
+ * ```text
272
+ * [Run 1] Grype
273
+ * Critical: 1, High: 3, Medium: 1
274
+ * [Run 2] Grype
275
+ * Medium: 1, Low: 20
276
+ * ```
277
+ */
278
+ CompactGroupByRunPerSeverity = 1,
279
+ /**
280
+ * Compact information about findings grouped by tool name with the level representation.
281
+ * @example
282
+ * ```text
283
+ * Grype
284
+ * Error: 1, Warning: 5, Note: 20
285
+ * ```
286
+ */
287
+ CompactGroupByToolNamePerLevel = 2,
288
+ /**
289
+ * Compact information about findings grouped by tool name with the severity representation.
290
+ * @example
291
+ * ```text
292
+ * Grype
293
+ * Critical: 1, High: 3, Medium: 2, Low: 20
294
+ * ```
295
+ */
296
+ CompactGroupByToolNamePerSeverity = 3,
297
+ /**
298
+ * Compact information about findings grouped by SARIF file with the level representation.
299
+ * @example
300
+ * ```text
301
+ * grype-results-01.sarif
302
+ * Error: 1, Warning: 2, Note: 1
303
+ * grype-results-02.sarif
304
+ * Warning: 3, Note: 19
305
+ * ```
306
+ */
307
+ CompactGroupBySarifPerLevel = 4,
308
+ /**
309
+ * Compact information about findings grouped by SARIF file with the severity
310
+ * representation.
311
+ * @example
312
+ * ```text
313
+ * grype-results-01.sarif
314
+ * High: 3, Medium: 1, Low: 11
315
+ * grype-results-02.sarif
316
+ * Critical: 1, Medium: 1, Low: 9
317
+ * ```
318
+ */
319
+ CompactGroupBySarifPerSeverity = 5,
320
+ /**
321
+ * Compact information about findings with the level representation.
322
+ * @example
323
+ * ```text
324
+ * Total
325
+ * Error: 1, Warning: 5, Note: 20
326
+ * ```
327
+ */
328
+ CompactTotalPerLevel = 6,
329
+ /**
330
+ * Compact information about findings with the severity representation.
331
+ * @example
332
+ * ```text
333
+ * Total
334
+ * Critical: 1, High: 3, Medium: 2, Low: 20
335
+ * ```
336
+ */
337
+ CompactTotalPerSeverity = 7
338
+ }
339
+
340
+ /**
341
+ * SARIF file extension.
193
342
  * @public
194
343
  */
195
- export declare type SarifLog = Log;
344
+ export declare type SarifFileExtension = 'sarif' | 'json';
196
345
 
197
346
  /**
198
- * Options for how to output the results in the Slack message.
347
+ * Represents options for the provided SARIF file(s), such as path, should files
348
+ * from this path be retrieved recursively or not, and file extension.
199
349
  * @public
200
350
  */
201
- export declare type SarifToSlackOutput = {
202
- groupBy?: GroupResultsBy;
203
- calculateBy?: CalculateResultsBy;
351
+ export declare type SarifOptions = {
352
+ path: string;
353
+ recursive?: boolean;
354
+ extension?: SarifFileExtension;
204
355
  };
205
356
 
206
357
  /**
207
358
  * Service to convert SARIF files to Slack messages and send them.
208
359
  * @public
209
360
  */
210
- export declare class SarifToSlackService {
211
- private readonly _slackMessages;
361
+ export declare class SarifToSlackClient {
362
+ private _message?;
363
+ private _sarifModel?;
364
+ private _sendIf;
212
365
  private constructor();
366
+ private static createRunIdGenerator;
367
+ static create(opts: SarifToSlackClientOptions): Promise<SarifToSlackClient>;
368
+ private static buildModel;
213
369
  /**
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
370
+ * The main function to initialize a list of {@link SlackMessage} objects based
371
+ * on the given SARIF file(s).
372
+ * @param sarifModel An instance of {@link SarifModel} object.
373
+ * @param opts An instance of {@link SarifToSlackClientOptions} object.
374
+ * @returns A map where key is the SARIF file and value is an instance of
375
+ * {@link SlackMessage} object
376
+ * @private
225
377
  */
226
- static create(opts: SarifToSlackServiceOptions): Promise<SarifToSlackService>;
378
+ private static initialize;
227
379
  /**
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.
380
+ * Sends a Slack message.
237
381
  * @returns A promise that resolves when the message has been sent.
238
382
  * @throws Error if a Slack message was not prepared for the given SARIF path.
239
383
  * @public
240
384
  */
241
- send(sarifPath: string): Promise<void>;
385
+ send(): Promise<void>;
386
+ private get shouldSendMessage();
242
387
  }
243
388
 
244
389
  /**
245
- * Options for the SarifToSlackService.
390
+ * Options for the SarifToSlackClient.
246
391
  * @public
247
392
  */
248
- export declare type SarifToSlackServiceOptions = {
393
+ export declare type SarifToSlackClientOptions = {
249
394
  webhookUrl: string;
250
- sarifPath: string;
395
+ sarif: SarifOptions;
251
396
  username?: string;
252
397
  iconUrl?: string;
253
- color?: string;
398
+ color?: ColorOptions;
254
399
  log?: LogOptions;
255
400
  header?: IncludeAwareWithValueOptions;
256
401
  footer?: FooterOptions;
257
402
  actor?: IncludeAwareWithValueOptions;
258
403
  run?: IncludeAwareOptions;
259
- output?: SarifToSlackOutput;
404
+ representation?: RepresentationType;
405
+ sendIf?: SendIf;
260
406
  };
261
407
 
408
+ /**
409
+ * This enum represents the condition on when message should be sent. If this
410
+ * condition is satisfied then message is sent, otherwise - message is not sent.
411
+ * @public
412
+ */
413
+ export declare enum SendIf {
414
+ /**
415
+ * Send message only if there is at least one finding with "Critical" severity.
416
+ * Since it is the higher possible severity, it is the same as "Critical" or
417
+ * higher.
418
+ */
419
+ SeverityCritical = 0,
420
+ /**
421
+ * Send message only if there is at least one finding with "High" severity.
422
+ */
423
+ SeverityHigh = 1,
424
+ /**
425
+ * Send message only if there is at least one finding with "High" severity or
426
+ * higher, that includes "High" and "Critical".
427
+ */
428
+ SeverityHighOrHigher = 2,
429
+ /**
430
+ * Send message only if there is at least one finding with "Medium" severity.
431
+ */
432
+ SeverityMedium = 3,
433
+ /**
434
+ * Send message only if there is at least one finding with "Medium" severity
435
+ * or higher, that includes "Medium", "High" and "Critical".
436
+ */
437
+ SeverityMediumOrHigher = 4,
438
+ /**
439
+ * Send message only if there is at least one finding with "Low" severity.
440
+ */
441
+ SeverityLow = 5,
442
+ /**
443
+ * Send message only if there is at least one finding with "Low" severity or
444
+ * higher, that includes "Low", "Medium", "High" and "Critical".
445
+ */
446
+ SeverityLowOrHigher = 6,
447
+ /**
448
+ * Send message only if there is at least one finding with "None" severity.
449
+ */
450
+ SeverityNone = 7,
451
+ /**
452
+ * Send message only if there is at least one finding with "None" severity or
453
+ * higher, that includes "None", "Low", "Medium", "High" and "Critical".
454
+ */
455
+ SeverityNoneOrHigher = 8,
456
+ /**
457
+ * Send message only if there is at least one finding with "Unknown" severity.
458
+ */
459
+ SeverityUnknown = 9,
460
+ /**
461
+ * Send message only if there is at least one finding with "Unknown" severity
462
+ * or higher, that includes "Unknown", "None", "Low", "Medium", "High" and "Critical".
463
+ */
464
+ SeverityUnknownOrHigher = 10,
465
+ /**
466
+ * Send message only if there is at least one finding with "Error" level.
467
+ * Since it is the higher possible level, it is the same as "Error" or higher.
468
+ */
469
+ LevelError = 11,
470
+ /**
471
+ * Send message only if there is at least one finding with "Warning" level.
472
+ */
473
+ LevelWarning = 12,
474
+ /**
475
+ * Send message only if there is at least one finding with "Warning" level or
476
+ * higher, that includes "Warning" and "Error".
477
+ */
478
+ LevelWarningOrHigher = 13,
479
+ /**
480
+ * Send message only if there is at least one finding with "Note" level.
481
+ */
482
+ LevelNote = 14,
483
+ /**
484
+ * Send message only if there is at least one finding with "Note" level or
485
+ * higher, that includes "Note", "Warning" and "Error.
486
+ */
487
+ LevelNoteOrHigher = 15,
488
+ /**
489
+ * Send message only if there is at least one finding with "None" level.
490
+ */
491
+ LevelNone = 16,
492
+ /**
493
+ * Send message only if there is at least one finding with "None" level or
494
+ * higher, that includes "None", "Note", "Warning" and "Error.
495
+ */
496
+ LevelNoneOrHigher = 17,
497
+ /**
498
+ * Send message only if there is at least one finding with "Unknown" level.
499
+ */
500
+ LevelUnknown = 18,
501
+ /**
502
+ * Send message only if there is at least one finding with "Unknown" level or
503
+ * higher, that includes "Unknown", "None", "Note", "Warning" and "Error.
504
+ */
505
+ LevelUnknownOrHigher = 19,
506
+ /**
507
+ * Always send a message.
508
+ */
509
+ Always = 20,
510
+ /**
511
+ * Send a message if at least 1 vulnerability is found.
512
+ */
513
+ Some = 21,
514
+ /**
515
+ * Send a message only if no vulnerabilities are found.
516
+ */
517
+ Empty = 22,
518
+ /**
519
+ * Never send a message.
520
+ */
521
+ Never = 23
522
+ }
523
+
262
524
  /**
263
525
  * Interface for a Slack message that can be sent.
264
526
  * @public
@@ -269,10 +531,10 @@ export declare interface SlackMessage {
269
531
  * @returns A promise that resolves to the response from the Slack webhook.
270
532
  */
271
533
  send: () => Promise<string>;
272
- /**
273
- * The SARIF log associated with this Slack message.
274
- */
275
- sarif: SarifLog;
534
+ withActor(actor?: string): void;
535
+ withFooter(text?: string, type?: FooterType): void;
536
+ withHeader(header?: string): void;
537
+ withRun(): void;
276
538
  }
277
539
 
278
540
  export { }
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.52.9"
8
+ "packageVersion": "7.52.10"
9
9
  }
10
10
  ]
11
11
  }