@fabasoad/sarif-to-slack 0.2.5 → 1.0.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 +840 -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 +70 -0
  20. package/dist/model/Color.d.ts.map +1 -0
  21. package/dist/model/Color.js +119 -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 +337 -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 +161 -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 +201 -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,90 @@
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. {@link ColorOptions.byLevel} has
135
+ * color scheme for the findings where certain level presented. {@link ColorOptions.bySeverity}
136
+ * has color scheme for the findings where certain severity presented.
137
+ * @public
138
+ */
139
+ export declare type ColorOptions = {
140
+ byLevel?: ColorGroupByLevel;
141
+ bySeverity?: ColorGroupBySeverity;
142
+ };
143
+
73
144
  /**
74
145
  * Options for the footer of a Slack message. "type" is ignored if "value" is
75
146
  * not defined.
@@ -95,27 +166,6 @@ export declare enum FooterType {
95
166
  Markdown = "mrkdwn"
96
167
  }
97
168
 
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
169
  /**
120
170
  * Type representing properties that indicate whether to include certain information
121
171
  * in the Slack message.
@@ -189,76 +239,278 @@ export declare type LogOptions = {
189
239
  };
190
240
 
191
241
  /**
192
- * Type representing a SARIF log.
242
+ * This represents what type of message should be sent. There are various options
243
+ * to show information from SARIF in Slack message.
244
+ * @public
245
+ */
246
+ export declare enum RepresentationType {
247
+ /**
248
+ * Compact information about findings grouped by Run with the level representation.
249
+ * @example
250
+ * ```text
251
+ * [Run 1] Grype
252
+ * Error: 1, Warning: 4
253
+ * [Run 2] Grype
254
+ * Warning: 1, Note: 20
255
+ * ```
256
+ */
257
+ CompactGroupByRunPerLevel = 0,
258
+ /**
259
+ * Compact information about findings grouped by Run with the severity representation.
260
+ * @example
261
+ * ```text
262
+ * [Run 1] Grype
263
+ * Critical: 1, High: 3, Medium: 1
264
+ * [Run 2] Grype
265
+ * Medium: 1, Low: 20
266
+ * ```
267
+ */
268
+ CompactGroupByRunPerSeverity = 1,
269
+ /**
270
+ * Compact information about findings grouped by tool name with the level representation.
271
+ * @example
272
+ * ```text
273
+ * Grype
274
+ * Error: 1, Warning: 5, Note: 20
275
+ * ```
276
+ */
277
+ CompactGroupByToolNamePerLevel = 2,
278
+ /**
279
+ * Compact information about findings grouped by tool name with the severity representation.
280
+ * @example
281
+ * ```text
282
+ * Grype
283
+ * Critical: 1, High: 3, Medium: 2, Low: 20
284
+ * ```
285
+ */
286
+ CompactGroupByToolNamePerSeverity = 3,
287
+ /**
288
+ * Compact information about findings grouped by SARIF file with the level representation.
289
+ * @example
290
+ * ```text
291
+ * grype-results-01.sarif
292
+ * Error: 1, Warning: 2, Note: 1
293
+ * grype-results-02.sarif
294
+ * Warning: 3, Note: 19
295
+ * ```
296
+ */
297
+ CompactGroupBySarifPerLevel = 4,
298
+ /**
299
+ * Compact information about findings grouped by SARIF file with the severity
300
+ * representation.
301
+ * @example
302
+ * ```text
303
+ * grype-results-01.sarif
304
+ * High: 3, Medium: 1, Low: 11
305
+ * grype-results-02.sarif
306
+ * Critical: 1, Medium: 1, Low: 9
307
+ * ```
308
+ */
309
+ CompactGroupBySarifPerSeverity = 5,
310
+ /**
311
+ * Compact information about findings with the level representation.
312
+ * @example
313
+ * ```text
314
+ * Total
315
+ * Error: 1, Warning: 5, Note: 20
316
+ * ```
317
+ */
318
+ CompactTotalPerLevel = 6,
319
+ /**
320
+ * Compact information about findings with the severity representation.
321
+ * @example
322
+ * ```text
323
+ * Total
324
+ * Critical: 1, High: 3, Medium: 2, Low: 20
325
+ * ```
326
+ */
327
+ CompactTotalPerSeverity = 7
328
+ }
329
+
330
+ /**
331
+ * SARIF file extension.
193
332
  * @public
194
333
  */
195
- export declare type SarifLog = Log;
334
+ export declare type SarifFileExtension = 'sarif' | 'json';
196
335
 
197
336
  /**
198
- * Options for how to output the results in the Slack message.
337
+ * Represents options for the provided SARIF file(s), such as path, should files
338
+ * from this path be retrieved recursively or not, and file extension.
199
339
  * @public
200
340
  */
201
- export declare type SarifToSlackOutput = {
202
- groupBy?: GroupResultsBy;
203
- calculateBy?: CalculateResultsBy;
341
+ export declare type SarifOptions = {
342
+ path: string;
343
+ recursive?: boolean;
344
+ extension?: SarifFileExtension;
204
345
  };
205
346
 
206
347
  /**
207
348
  * Service to convert SARIF files to Slack messages and send them.
208
349
  * @public
209
350
  */
210
- export declare class SarifToSlackService {
211
- private readonly _slackMessages;
351
+ export declare class SarifToSlackClient {
352
+ private _message?;
353
+ private _sarifModel?;
354
+ private _sendIf;
212
355
  private constructor();
356
+ private static createRunIdGenerator;
357
+ static create(opts: SarifToSlackClientOptions): Promise<SarifToSlackClient>;
358
+ private static buildModel;
213
359
  /**
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
360
+ * The main function to initialize a list of {@link SlackMessage} objects based
361
+ * on the given SARIF file(s).
362
+ * @param sarifModel An instance of {@link SarifModel} object.
363
+ * @param opts An instance of {@link SarifToSlackClientOptions} object.
364
+ * @returns A map where key is the SARIF file and value is an instance of
365
+ * {@link SlackMessage} object
366
+ * @private
217
367
  */
218
- get slackMessages(): ReadonlyMap<string, SlackMessage>;
368
+ private static initialize;
219
369
  /**
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.
370
+ * Sends a Slack message.
237
371
  * @returns A promise that resolves when the message has been sent.
238
372
  * @throws Error if a Slack message was not prepared for the given SARIF path.
239
373
  * @public
240
374
  */
241
- send(sarifPath: string): Promise<void>;
375
+ send(): Promise<void>;
376
+ private get shouldSendMessage();
242
377
  }
243
378
 
244
379
  /**
245
- * Options for the SarifToSlackService.
380
+ * Options for the SarifToSlackClient.
246
381
  * @public
247
382
  */
248
- export declare type SarifToSlackServiceOptions = {
383
+ export declare type SarifToSlackClientOptions = {
249
384
  webhookUrl: string;
250
- sarifPath: string;
385
+ sarif: SarifOptions;
251
386
  username?: string;
252
387
  iconUrl?: string;
253
- color?: string;
388
+ color?: Color | ColorOptions;
254
389
  log?: LogOptions;
255
390
  header?: IncludeAwareWithValueOptions;
256
391
  footer?: FooterOptions;
257
392
  actor?: IncludeAwareWithValueOptions;
258
393
  run?: IncludeAwareOptions;
259
- output?: SarifToSlackOutput;
394
+ representation?: RepresentationType;
395
+ sendIf?: SendIf;
260
396
  };
261
397
 
398
+ /**
399
+ * This enum represents the condition on when message should be sent. If this
400
+ * condition is satisfied then message is sent, otherwise - message is not sent.
401
+ * @public
402
+ */
403
+ export declare enum SendIf {
404
+ /**
405
+ * Send message only if there is at least one finding with "Critical" severity.
406
+ * Since it is the higher possible severity, it is the same as "Critical" or
407
+ * higher.
408
+ */
409
+ SeverityCritical = 0,
410
+ /**
411
+ * Send message only if there is at least one finding with "High" severity.
412
+ */
413
+ SeverityHigh = 1,
414
+ /**
415
+ * Send message only if there is at least one finding with "High" severity or
416
+ * higher, that includes "High" and "Critical".
417
+ */
418
+ SeverityHighOrHigher = 2,
419
+ /**
420
+ * Send message only if there is at least one finding with "Medium" severity.
421
+ */
422
+ SeverityMedium = 3,
423
+ /**
424
+ * Send message only if there is at least one finding with "Medium" severity
425
+ * or higher, that includes "Medium", "High" and "Critical".
426
+ */
427
+ SeverityMediumOrHigher = 4,
428
+ /**
429
+ * Send message only if there is at least one finding with "Low" severity.
430
+ */
431
+ SeverityLow = 5,
432
+ /**
433
+ * Send message only if there is at least one finding with "Low" severity or
434
+ * higher, that includes "Low", "Medium", "High" and "Critical".
435
+ */
436
+ SeverityLowOrHigher = 6,
437
+ /**
438
+ * Send message only if there is at least one finding with "None" severity.
439
+ */
440
+ SeverityNone = 7,
441
+ /**
442
+ * Send message only if there is at least one finding with "None" severity or
443
+ * higher, that includes "None", "Low", "Medium", "High" and "Critical".
444
+ */
445
+ SeverityNoneOrHigher = 8,
446
+ /**
447
+ * Send message only if there is at least one finding with "Unknown" severity.
448
+ */
449
+ SeverityUnknown = 9,
450
+ /**
451
+ * Send message only if there is at least one finding with "Unknown" severity
452
+ * or higher, that includes "Unknown", "None", "Low", "Medium", "High" and "Critical".
453
+ */
454
+ SeverityUnknownOrHigher = 10,
455
+ /**
456
+ * Send message only if there is at least one finding with "Error" level.
457
+ * Since it is the higher possible level, it is the same as "Error" or higher.
458
+ */
459
+ LevelError = 11,
460
+ /**
461
+ * Send message only if there is at least one finding with "Warning" level.
462
+ */
463
+ LevelWarning = 12,
464
+ /**
465
+ * Send message only if there is at least one finding with "Warning" level or
466
+ * higher, that includes "Warning" and "Error".
467
+ */
468
+ LevelWarningOrHigher = 13,
469
+ /**
470
+ * Send message only if there is at least one finding with "Note" level.
471
+ */
472
+ LevelNote = 14,
473
+ /**
474
+ * Send message only if there is at least one finding with "Note" level or
475
+ * higher, that includes "Note", "Warning" and "Error.
476
+ */
477
+ LevelNoteOrHigher = 15,
478
+ /**
479
+ * Send message only if there is at least one finding with "None" level.
480
+ */
481
+ LevelNone = 16,
482
+ /**
483
+ * Send message only if there is at least one finding with "None" level or
484
+ * higher, that includes "None", "Note", "Warning" and "Error.
485
+ */
486
+ LevelNoneOrHigher = 17,
487
+ /**
488
+ * Send message only if there is at least one finding with "Unknown" level.
489
+ */
490
+ LevelUnknown = 18,
491
+ /**
492
+ * Send message only if there is at least one finding with "Unknown" level or
493
+ * higher, that includes "Unknown", "None", "Note", "Warning" and "Error.
494
+ */
495
+ LevelUnknownOrHigher = 19,
496
+ /**
497
+ * Always send a message.
498
+ */
499
+ Always = 20,
500
+ /**
501
+ * Send a message if at least 1 vulnerability is found.
502
+ */
503
+ Some = 21,
504
+ /**
505
+ * Send a message only if no vulnerabilities are found.
506
+ */
507
+ Empty = 22,
508
+ /**
509
+ * Never send a message.
510
+ */
511
+ Never = 23
512
+ }
513
+
262
514
  /**
263
515
  * Interface for a Slack message that can be sent.
264
516
  * @public
@@ -269,10 +521,10 @@ export declare interface SlackMessage {
269
521
  * @returns A promise that resolves to the response from the Slack webhook.
270
522
  */
271
523
  send: () => Promise<string>;
272
- /**
273
- * The SARIF log associated with this Slack message.
274
- */
275
- sarif: SarifLog;
524
+ withActor(actor?: string): void;
525
+ withFooter(text?: string, type?: FooterType): void;
526
+ withHeader(header?: string): void;
527
+ withRun(): void;
276
528
  }
277
529
 
278
530
  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
  }