@datadog/datadog-ci 2.18.0 → 2.19.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 (302) hide show
  1. package/dist/cli.d.ts +3 -1
  2. package/dist/cli.js +9 -2
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/cloud-run/cli.d.ts +1 -0
  5. package/dist/commands/cloud-run/cli.js +5 -0
  6. package/dist/commands/cloud-run/cli.js.map +1 -0
  7. package/dist/commands/cloud-run/constants.d.ts +1 -0
  8. package/dist/commands/cloud-run/constants.js +22 -0
  9. package/dist/commands/cloud-run/constants.js.map +1 -0
  10. package/dist/commands/cloud-run/flare.d.ts +91 -0
  11. package/dist/commands/cloud-run/flare.js +634 -0
  12. package/dist/commands/cloud-run/flare.js.map +1 -0
  13. package/dist/commands/cloud-run/interfaces.d.ts +27 -0
  14. package/dist/commands/cloud-run/interfaces.js +3 -0
  15. package/dist/commands/cloud-run/interfaces.js.map +1 -0
  16. package/dist/commands/cloud-run/renderer.d.ts +4 -0
  17. package/dist/commands/cloud-run/renderer.js +42 -0
  18. package/dist/commands/cloud-run/renderer.js.map +1 -0
  19. package/dist/commands/dsyms/renderer.js +6 -6
  20. package/dist/commands/dsyms/renderer.js.map +1 -1
  21. package/dist/commands/dsyms/upload.d.ts +5 -5
  22. package/dist/commands/dsyms/upload.js +66 -42
  23. package/dist/commands/dsyms/upload.js.map +1 -1
  24. package/dist/commands/dsyms/utils.d.ts +1 -1
  25. package/dist/commands/dsyms/utils.js +3 -3
  26. package/dist/commands/dsyms/utils.js.map +1 -1
  27. package/dist/commands/flutter-symbols/helpers.js +8 -4
  28. package/dist/commands/flutter-symbols/helpers.js.map +1 -1
  29. package/dist/commands/flutter-symbols/renderer.js +2 -2
  30. package/dist/commands/flutter-symbols/renderer.js.map +1 -1
  31. package/dist/commands/flutter-symbols/upload.d.ts +13 -13
  32. package/dist/commands/flutter-symbols/upload.js +66 -66
  33. package/dist/commands/flutter-symbols/upload.js.map +1 -1
  34. package/dist/commands/gate/api.js +4 -2
  35. package/dist/commands/gate/api.js.map +1 -1
  36. package/dist/commands/gate/evaluate.d.ts +18 -6
  37. package/dist/commands/gate/evaluate.js +116 -40
  38. package/dist/commands/gate/evaluate.js.map +1 -1
  39. package/dist/commands/gate/interfaces.d.ts +5 -0
  40. package/dist/commands/gate/renderer.js +16 -14
  41. package/dist/commands/gate/renderer.js.map +1 -1
  42. package/dist/commands/gate/utils.d.ts +1 -0
  43. package/dist/commands/gate/utils.js +8 -4
  44. package/dist/commands/gate/utils.js.map +1 -1
  45. package/dist/commands/git-metadata/git.d.ts +1 -1
  46. package/dist/commands/git-metadata/git.js +7 -3
  47. package/dist/commands/git-metadata/git.js.map +1 -1
  48. package/dist/commands/git-metadata/gitdb.d.ts +1 -1
  49. package/dist/commands/git-metadata/gitdb.js +7 -7
  50. package/dist/commands/git-metadata/gitdb.js.map +1 -1
  51. package/dist/commands/git-metadata/index.js +5 -1
  52. package/dist/commands/git-metadata/index.js.map +1 -1
  53. package/dist/commands/git-metadata/library.d.ts +1 -1
  54. package/dist/commands/git-metadata/library.js +13 -13
  55. package/dist/commands/git-metadata/library.js.map +1 -1
  56. package/dist/commands/git-metadata/upload.d.ts +5 -5
  57. package/dist/commands/git-metadata/upload.js +30 -32
  58. package/dist/commands/git-metadata/upload.js.map +1 -1
  59. package/dist/commands/junit/api.js +4 -4
  60. package/dist/commands/junit/api.js.map +1 -1
  61. package/dist/commands/junit/id.js +1 -1
  62. package/dist/commands/junit/id.js.map +1 -1
  63. package/dist/commands/junit/renderer.d.ts +1 -1
  64. package/dist/commands/junit/renderer.js +3 -3
  65. package/dist/commands/junit/renderer.js.map +1 -1
  66. package/dist/commands/junit/upload.d.ts +12 -11
  67. package/dist/commands/junit/upload.js +74 -63
  68. package/dist/commands/junit/upload.js.map +1 -1
  69. package/dist/commands/junit/utils.d.ts +1 -2
  70. package/dist/commands/junit/utils.js +5 -10
  71. package/dist/commands/junit/utils.js.map +1 -1
  72. package/dist/commands/lambda/constants.d.ts +13 -11
  73. package/dist/commands/lambda/constants.js +41 -70
  74. package/dist/commands/lambda/constants.js.map +1 -1
  75. package/dist/commands/lambda/flare.d.ts +25 -74
  76. package/dist/commands/lambda/flare.js +182 -332
  77. package/dist/commands/lambda/flare.js.map +1 -1
  78. package/dist/commands/lambda/functions/commons.d.ts +8 -14
  79. package/dist/commands/lambda/functions/commons.js +57 -69
  80. package/dist/commands/lambda/functions/commons.js.map +1 -1
  81. package/dist/commands/lambda/functions/instrument.js +66 -65
  82. package/dist/commands/lambda/functions/instrument.js.map +1 -1
  83. package/dist/commands/lambda/functions/uninstrument.js +38 -37
  84. package/dist/commands/lambda/functions/uninstrument.js.map +1 -1
  85. package/dist/commands/lambda/functions/versionChecker.d.ts +2 -2
  86. package/dist/commands/lambda/instrument.d.ts +22 -20
  87. package/dist/commands/lambda/instrument.js +78 -69
  88. package/dist/commands/lambda/instrument.js.map +1 -1
  89. package/dist/commands/lambda/loggroup.js +8 -8
  90. package/dist/commands/lambda/loggroup.js.map +1 -1
  91. package/dist/commands/lambda/prompt.d.ts +1 -4
  92. package/dist/commands/lambda/prompt.js +34 -71
  93. package/dist/commands/lambda/prompt.js.map +1 -1
  94. package/dist/commands/lambda/renderers/__mocks__/instrument-uninstrument-renderer.d.ts +2 -0
  95. package/dist/commands/lambda/renderers/__mocks__/instrument-uninstrument-renderer.js +11 -0
  96. package/dist/commands/lambda/renderers/__mocks__/instrument-uninstrument-renderer.js.map +1 -0
  97. package/dist/commands/lambda/renderers/common-renderer.d.ts +0 -26
  98. package/dist/commands/lambda/renderers/common-renderer.js +4 -32
  99. package/dist/commands/lambda/renderers/common-renderer.js.map +1 -1
  100. package/dist/commands/lambda/renderers/instrument-uninstrument-renderer.d.ts +2 -2
  101. package/dist/commands/lambda/renderers/instrument-uninstrument-renderer.js +57 -49
  102. package/dist/commands/lambda/renderers/instrument-uninstrument-renderer.js.map +1 -1
  103. package/dist/commands/lambda/tags.js +7 -7
  104. package/dist/commands/lambda/tags.js.map +1 -1
  105. package/dist/commands/lambda/uninstrument.d.ts +25 -7
  106. package/dist/commands/lambda/uninstrument.js +59 -49
  107. package/dist/commands/lambda/uninstrument.js.map +1 -1
  108. package/dist/commands/metric/metric.d.ts +4 -3
  109. package/dist/commands/metric/metric.js +10 -9
  110. package/dist/commands/metric/metric.js.map +1 -1
  111. package/dist/commands/react-native/codepush.d.ts +11 -10
  112. package/dist/commands/react-native/codepush.js +17 -19
  113. package/dist/commands/react-native/codepush.js.map +1 -1
  114. package/dist/commands/react-native/interfaces.d.ts +1 -1
  115. package/dist/commands/react-native/renderer.js +6 -6
  116. package/dist/commands/react-native/renderer.js.map +1 -1
  117. package/dist/commands/react-native/upload.d.ts +12 -12
  118. package/dist/commands/react-native/upload.js +67 -45
  119. package/dist/commands/react-native/upload.js.map +1 -1
  120. package/dist/commands/react-native/utils.js +2 -1
  121. package/dist/commands/react-native/utils.js.map +1 -1
  122. package/dist/commands/react-native/validation.js +1 -1
  123. package/dist/commands/react-native/validation.js.map +1 -1
  124. package/dist/commands/react-native/xcode.d.ts +6 -6
  125. package/dist/commands/react-native/xcode.js +25 -29
  126. package/dist/commands/react-native/xcode.js.map +1 -1
  127. package/dist/commands/sarif/api.js +6 -22
  128. package/dist/commands/sarif/api.js.map +1 -1
  129. package/dist/commands/sarif/renderer.d.ts +1 -1
  130. package/dist/commands/sarif/renderer.js +1 -1
  131. package/dist/commands/sarif/renderer.js.map +1 -1
  132. package/dist/commands/sarif/upload.d.ts +6 -6
  133. package/dist/commands/sarif/upload.js +46 -37
  134. package/dist/commands/sarif/upload.js.map +1 -1
  135. package/dist/commands/sbom/api.d.ts +7 -0
  136. package/dist/commands/sbom/api.js +49 -0
  137. package/dist/commands/sbom/api.js.map +1 -0
  138. package/dist/commands/sbom/cli.d.ts +1 -0
  139. package/dist/commands/sbom/cli.js +5 -0
  140. package/dist/commands/sbom/cli.js.map +1 -0
  141. package/dist/commands/sbom/constants.d.ts +2 -0
  142. package/dist/commands/sbom/constants.js +6 -0
  143. package/dist/commands/sbom/constants.js.map +1 -0
  144. package/dist/commands/sbom/json-schema/cyclonedx/bom-1.4.schema.json +1687 -0
  145. package/dist/commands/sbom/json-schema/jsf/jsf-0.82.schema.json +244 -0
  146. package/dist/commands/sbom/json-schema/spdx/spdx.schema.json +507 -0
  147. package/dist/commands/sbom/protobuf/bom-1.4.d.ts +11788 -0
  148. package/dist/commands/sbom/protobuf/bom-1.4.js +5161 -0
  149. package/dist/commands/sbom/protobuf/bom-1.4.js.map +1 -0
  150. package/dist/commands/sbom/protobuf/custom_message.d.ts +11 -0
  151. package/dist/commands/sbom/protobuf/custom_message.js +3 -0
  152. package/dist/commands/sbom/protobuf/custom_message.js.map +1 -0
  153. package/dist/commands/sbom/protobuf/google/protobuf/duration.d.ts +110 -0
  154. package/dist/commands/sbom/protobuf/google/protobuf/duration.js +126 -0
  155. package/dist/commands/sbom/protobuf/google/protobuf/duration.js.map +1 -0
  156. package/dist/commands/sbom/protobuf/google/protobuf/timestamp.d.ts +139 -0
  157. package/dist/commands/sbom/protobuf/google/protobuf/timestamp.js +126 -0
  158. package/dist/commands/sbom/protobuf/google/protobuf/timestamp.js.map +1 -0
  159. package/dist/commands/sbom/protobuf/sbom_intake.d.ts +53 -0
  160. package/dist/commands/sbom/protobuf/sbom_intake.js +383 -0
  161. package/dist/commands/sbom/protobuf/sbom_intake.js.map +1 -0
  162. package/dist/commands/sbom/types.d.ts +4 -0
  163. package/dist/commands/sbom/types.js +3 -0
  164. package/dist/commands/sbom/types.js.map +1 -0
  165. package/dist/commands/sbom/upload.d.ts +16 -0
  166. package/dist/commands/sbom/upload.js +134 -0
  167. package/dist/commands/sbom/upload.js.map +1 -0
  168. package/dist/commands/sbom/validation.d.ts +12 -0
  169. package/dist/commands/sbom/validation.js +51 -0
  170. package/dist/commands/sbom/validation.js.map +1 -0
  171. package/dist/commands/sourcemaps/renderer.js +6 -6
  172. package/dist/commands/sourcemaps/renderer.js.map +1 -1
  173. package/dist/commands/sourcemaps/upload.d.ts +10 -10
  174. package/dist/commands/sourcemaps/upload.js +61 -38
  175. package/dist/commands/sourcemaps/upload.js.map +1 -1
  176. package/dist/commands/sourcemaps/validation.js +4 -4
  177. package/dist/commands/sourcemaps/validation.js.map +1 -1
  178. package/dist/commands/stepfunctions/awsCommands.js +10 -10
  179. package/dist/commands/stepfunctions/awsCommands.js.map +1 -1
  180. package/dist/commands/stepfunctions/helpers.d.ts +4 -4
  181. package/dist/commands/stepfunctions/helpers.js +4 -4
  182. package/dist/commands/stepfunctions/helpers.js.map +1 -1
  183. package/dist/commands/stepfunctions/instrument.d.ts +5 -4
  184. package/dist/commands/stepfunctions/instrument.js +30 -31
  185. package/dist/commands/stepfunctions/instrument.js.map +1 -1
  186. package/dist/commands/stepfunctions/uninstrument.d.ts +6 -1
  187. package/dist/commands/stepfunctions/uninstrument.js +23 -23
  188. package/dist/commands/stepfunctions/uninstrument.js.map +1 -1
  189. package/dist/commands/synthetics/api.d.ts +1 -1
  190. package/dist/commands/synthetics/api.js +11 -11
  191. package/dist/commands/synthetics/api.js.map +1 -1
  192. package/dist/commands/synthetics/errors.d.ts +3 -3
  193. package/dist/commands/synthetics/index.js +5 -1
  194. package/dist/commands/synthetics/index.js.map +1 -1
  195. package/dist/commands/synthetics/interfaces.d.ts +8 -7
  196. package/dist/commands/synthetics/interfaces.js +2 -2
  197. package/dist/commands/synthetics/interfaces.js.map +1 -1
  198. package/dist/commands/synthetics/mobile.d.ts +1 -1
  199. package/dist/commands/synthetics/mobile.js +26 -20
  200. package/dist/commands/synthetics/mobile.js.map +1 -1
  201. package/dist/commands/synthetics/reporters/default.d.ts +2 -2
  202. package/dist/commands/synthetics/reporters/default.js +17 -19
  203. package/dist/commands/synthetics/reporters/default.js.map +1 -1
  204. package/dist/commands/synthetics/reporters/junit.d.ts +2 -2
  205. package/dist/commands/synthetics/reporters/junit.js +11 -11
  206. package/dist/commands/synthetics/reporters/junit.js.map +1 -1
  207. package/dist/commands/synthetics/run-tests-command.d.ts +21 -19
  208. package/dist/commands/synthetics/run-tests-command.js +108 -42
  209. package/dist/commands/synthetics/run-tests-command.js.map +1 -1
  210. package/dist/commands/synthetics/run-tests-lib.d.ts +1 -1
  211. package/dist/commands/synthetics/run-tests-lib.js +16 -16
  212. package/dist/commands/synthetics/run-tests-lib.js.map +1 -1
  213. package/dist/commands/synthetics/tunnel/crypto.js +3 -3
  214. package/dist/commands/synthetics/tunnel/crypto.js.map +1 -1
  215. package/dist/commands/synthetics/tunnel/tunnel.js +11 -11
  216. package/dist/commands/synthetics/tunnel/tunnel.js.map +1 -1
  217. package/dist/commands/synthetics/tunnel/websocket.d.ts +1 -0
  218. package/dist/commands/synthetics/tunnel/websocket.js +7 -3
  219. package/dist/commands/synthetics/tunnel/websocket.js.map +1 -1
  220. package/dist/commands/synthetics/upload-application-command.d.ts +10 -8
  221. package/dist/commands/synthetics/upload-application-command.js +36 -13
  222. package/dist/commands/synthetics/upload-application-command.js.map +1 -1
  223. package/dist/commands/synthetics/utils.d.ts +12 -12
  224. package/dist/commands/synthetics/utils.js +52 -47
  225. package/dist/commands/synthetics/utils.js.map +1 -1
  226. package/dist/commands/tag/tag.d.ts +4 -3
  227. package/dist/commands/tag/tag.js +10 -9
  228. package/dist/commands/tag/tag.js.map +1 -1
  229. package/dist/commands/trace/api.js +4 -4
  230. package/dist/commands/trace/api.js.map +1 -1
  231. package/dist/commands/trace/interfaces.d.ts +1 -1
  232. package/dist/commands/trace/trace.d.ts +5 -4
  233. package/dist/commands/trace/trace.js +11 -10
  234. package/dist/commands/trace/trace.js.map +1 -1
  235. package/dist/commands/version/cli.js +6 -5
  236. package/dist/commands/version/cli.js.map +1 -1
  237. package/dist/constants.d.ts +17 -0
  238. package/dist/constants.js +65 -1
  239. package/dist/constants.js.map +1 -1
  240. package/dist/helpers/api.d.ts +5 -0
  241. package/dist/helpers/api.js +16 -0
  242. package/dist/helpers/api.js.map +1 -0
  243. package/dist/helpers/base-intake-url.d.ts +1 -1
  244. package/dist/helpers/ci.d.ts +13 -13
  245. package/dist/helpers/ci.js +17 -17
  246. package/dist/helpers/ci.js.map +1 -1
  247. package/dist/helpers/config.d.ts +5 -0
  248. package/dist/helpers/config.js +3 -0
  249. package/dist/helpers/config.js.map +1 -0
  250. package/dist/helpers/flare.d.ts +41 -0
  251. package/dist/helpers/flare.js +191 -0
  252. package/dist/helpers/flare.js.map +1 -0
  253. package/dist/helpers/fs.d.ts +31 -0
  254. package/dist/helpers/fs.js +117 -0
  255. package/dist/helpers/fs.js.map +1 -0
  256. package/dist/helpers/git/format-git-sourcemaps-data.js +7 -3
  257. package/dist/helpers/git/format-git-sourcemaps-data.js.map +1 -1
  258. package/dist/helpers/git/format-git-span-data.js +6 -6
  259. package/dist/helpers/git/format-git-span-data.js.map +1 -1
  260. package/dist/helpers/git/get-git-data.js +3 -3
  261. package/dist/helpers/git/get-git-data.js.map +1 -1
  262. package/dist/helpers/interfaces.d.ts +9 -3
  263. package/dist/helpers/logger.js +1 -1
  264. package/dist/helpers/logger.js.map +1 -1
  265. package/dist/helpers/plist.d.ts +1 -1
  266. package/dist/helpers/plist.js +1 -1
  267. package/dist/helpers/plist.js.map +1 -1
  268. package/dist/helpers/prompt.d.ts +7 -0
  269. package/dist/helpers/prompt.js +57 -0
  270. package/dist/helpers/prompt.js.map +1 -0
  271. package/dist/helpers/renderer.d.ts +60 -0
  272. package/dist/helpers/renderer.js +98 -0
  273. package/dist/helpers/renderer.js.map +1 -0
  274. package/dist/helpers/retry.d.ts +1 -1
  275. package/dist/helpers/retry.js +3 -3
  276. package/dist/helpers/retry.js.map +1 -1
  277. package/dist/helpers/tags.d.ts +8 -0
  278. package/dist/helpers/tags.js +27 -1
  279. package/dist/helpers/tags.js.map +1 -1
  280. package/dist/helpers/upload.js +3 -3
  281. package/dist/helpers/upload.js.map +1 -1
  282. package/dist/helpers/user-provided-git.js +6 -6
  283. package/dist/helpers/user-provided-git.js.map +1 -1
  284. package/dist/helpers/utils.d.ts +12 -5
  285. package/dist/helpers/utils.js +57 -25
  286. package/dist/helpers/utils.js.map +1 -1
  287. package/dist/helpers/validation.d.ts +3 -1
  288. package/dist/helpers/validation.js +27 -1
  289. package/dist/helpers/validation.js.map +1 -1
  290. package/dist/helpers/version.d.ts +4 -0
  291. package/dist/helpers/version.js +9 -0
  292. package/dist/helpers/version.js.map +1 -0
  293. package/dist/index.d.ts +4 -4
  294. package/dist/index.js +11 -8
  295. package/dist/index.js.map +1 -1
  296. package/package.json +28 -13
  297. package/dist/commands/lambda/renderers/flare-renderer.d.ts +0 -9
  298. package/dist/commands/lambda/renderers/flare-renderer.js +0 -22
  299. package/dist/commands/lambda/renderers/flare-renderer.js.map +0 -1
  300. package/dist/helpers/file.d.ts +0 -1
  301. package/dist/helpers/file.js +0 -9
  302. package/dist/helpers/file.js.map +0 -1
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -31,87 +35,89 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
31
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
32
36
  };
33
37
  Object.defineProperty(exports, "__esModule", { value: true });
34
- exports.sendToDatadog = exports.getEndpointUrl = exports.zipContents = exports.sleep = exports.convertToCSV = exports.getUniqueFileNames = exports.writeFile = exports.getTags = exports.getAllLogs = exports.getLogEvents = exports.getLogStreamNames = exports.validateFilePath = exports.getProjectFiles = exports.createDirectories = exports.deleteFolder = exports.maskConfig = exports.validateStartEndFlags = exports.LambdaFlareCommand = void 0;
38
+ exports.generateInsightsFile = exports.getFramework = exports.sleep = exports.convertToCSV = exports.getUniqueFileNames = exports.getTags = exports.getAllLogs = exports.getLogEvents = exports.getLogStreamNames = exports.summarizeConfig = exports.LambdaFlareCommand = void 0;
35
39
  const fs = __importStar(require("fs"));
36
40
  const path = __importStar(require("path"));
37
41
  const util_1 = __importDefault(require("util"));
38
42
  const client_cloudwatch_logs_1 = require("@aws-sdk/client-cloudwatch-logs");
39
43
  const client_lambda_1 = require("@aws-sdk/client-lambda");
40
- const axios_1 = __importDefault(require("axios"));
41
44
  const chalk_1 = __importDefault(require("chalk"));
42
45
  const clipanion_1 = require("clipanion");
43
- const form_data_1 = __importDefault(require("form-data"));
44
- const jszip_1 = __importDefault(require("jszip"));
45
46
  const constants_1 = require("../../constants");
46
- const validation_1 = require("../../helpers/validation");
47
+ const flare_1 = require("../../helpers/flare");
48
+ const fs_1 = require("../../helpers/fs");
49
+ const prompt_1 = require("../../helpers/prompt");
50
+ const helpersRenderer = __importStar(require("../../helpers/renderer"));
51
+ const renderer_1 = require("../../helpers/renderer");
52
+ const utils_1 = require("../../helpers/utils");
53
+ const version_1 = require("../../helpers/version");
47
54
  const constants_2 = require("./constants");
48
55
  const commons_1 = require("./functions/commons");
49
- const prompt_1 = require("./prompt");
56
+ const prompt_2 = require("./prompt");
50
57
  const commonRenderer = __importStar(require("./renderers/common-renderer"));
51
- const flareRenderer = __importStar(require("./renderers/flare-renderer"));
52
- const { version } = require('../../../package.json');
53
- const ENDPOINT_PATH = '/api/ui/support/serverless/flare';
54
- const FLARE_OUTPUT_DIRECTORY = '.datadog-ci';
55
- const LOGS_DIRECTORY = 'logs';
56
- const PROJECT_FILES_DIRECTORY = 'project_files';
57
- const ADDITIONAL_FILES_DIRECTORY = 'additional_files';
58
58
  const FUNCTION_CONFIG_FILE_NAME = 'function_config.json';
59
59
  const TAGS_FILE_NAME = 'tags.json';
60
- const ZIP_FILE_NAME = 'lambda-flare-output.zip';
60
+ const FLARE_ZIP_FILE_NAME = 'lambda-flare-output.zip';
61
61
  const MAX_LOG_STREAMS = 50;
62
62
  const DEFAULT_LOG_STREAMS = 3;
63
63
  const MAX_LOG_EVENTS_PER_STREAM = 1000;
64
+ const SUMMARIZED_FIELDS = new Set(['FunctionName', 'Runtime', 'FunctionArn', 'Handler', 'Environment']);
64
65
  class LambdaFlareCommand extends clipanion_1.Command {
65
66
  constructor() {
66
67
  super(...arguments);
67
- this.isDryRun = false;
68
- this.withLogs = false;
68
+ this.isDryRun = clipanion_1.Option.Boolean('-d,--dry,--dry-run', false);
69
+ this.withLogs = clipanion_1.Option.Boolean('--with-logs', false);
70
+ this.functionName = clipanion_1.Option.String('-f,--function');
71
+ this.region = clipanion_1.Option.String('-r,--region');
72
+ this.caseId = clipanion_1.Option.String('-c,--case-id');
73
+ this.email = clipanion_1.Option.String('-e,--email');
74
+ this.start = clipanion_1.Option.String('--start');
75
+ this.end = clipanion_1.Option.String('--end');
69
76
  }
70
77
  /**
71
78
  * Entry point for the `lambda flare` command.
72
- * Gathers lambda function configuration and sends it to Datadog.
79
+ * Gathers config, logs, tags, project files, and more from a
80
+ * Lambda function and sends them to Datadog support.
73
81
  * @returns 0 if the command ran successfully, 1 otherwise.
74
82
  */
75
83
  execute() {
76
84
  var _a, _b, _c;
77
85
  return __awaiter(this, void 0, void 0, function* () {
78
- this.context.stdout.write(flareRenderer.renderLambdaFlareHeader(this.isDryRun));
86
+ this.context.stdout.write(helpersRenderer.renderFlareHeader('Lambda', this.isDryRun));
79
87
  // Validate function name
80
88
  if (this.functionName === undefined) {
81
- this.context.stderr.write(commonRenderer.renderError('No function name specified. [-f,--function]'));
89
+ this.context.stderr.write(helpersRenderer.renderError('No function name specified. [-f,--function]'));
82
90
  return 1;
83
91
  }
84
92
  const errorMessages = [];
85
93
  // Validate region
86
- const region = (_b = (_a = commons_1.getRegion(this.functionName)) !== null && _a !== void 0 ? _a : this.region) !== null && _b !== void 0 ? _b : process.env[constants_2.AWS_DEFAULT_REGION_ENV_VAR];
94
+ const region = (_b = (_a = (0, commons_1.getRegion)(this.functionName)) !== null && _a !== void 0 ? _a : this.region) !== null && _b !== void 0 ? _b : process.env[constants_2.AWS_DEFAULT_REGION_ENV_VAR];
87
95
  if (region === undefined) {
88
96
  errorMessages.push(commonRenderer.renderNoDefaultRegionSpecifiedError());
89
97
  }
90
98
  // Validate Datadog API key
91
- this.apiKey = (_c = process.env[constants_2.CI_API_KEY_ENV_VAR]) !== null && _c !== void 0 ? _c : process.env[constants_2.API_KEY_ENV_VAR];
99
+ this.apiKey = (_c = process.env[constants_1.CI_API_KEY_ENV_VAR]) !== null && _c !== void 0 ? _c : process.env[constants_1.API_KEY_ENV_VAR];
92
100
  if (this.apiKey === undefined) {
93
- errorMessages.push(commonRenderer.renderError('No Datadog API key specified. Set an API key with the DATADOG_API_KEY environment variable.'));
101
+ errorMessages.push(helpersRenderer.renderError('No Datadog API key specified. Set an API key with the DATADOG_API_KEY environment variable.'));
94
102
  }
95
- if (!this.isDryRun) {
96
- // Validate case ID
97
- if (this.caseId === undefined) {
98
- errorMessages.push(commonRenderer.renderError('No case ID specified. [-c,--case-id]'));
99
- }
100
- // Validate email
101
- if (this.email === undefined) {
102
- errorMessages.push(commonRenderer.renderError('No email specified. [-e,--email]'));
103
- }
103
+ // Validate case ID
104
+ if (this.caseId === undefined) {
105
+ errorMessages.push(helpersRenderer.renderError('No case ID specified. [-c,--case-id]'));
106
+ }
107
+ // Validate email
108
+ if (this.email === undefined) {
109
+ errorMessages.push(helpersRenderer.renderError('No email specified. [-e,--email]'));
104
110
  }
105
111
  // Validate start/end flags if both are specified
106
112
  let startMillis;
107
113
  let endMillis;
108
114
  try {
109
115
  ;
110
- [startMillis, endMillis] = exports.validateStartEndFlags(this.start, this.end);
116
+ [startMillis, endMillis] = (0, flare_1.validateStartEndFlags)(this.start, this.end);
111
117
  }
112
118
  catch (err) {
113
119
  if (err instanceof Error) {
114
- errorMessages.push(commonRenderer.renderError(err.message));
120
+ errorMessages.push(helpersRenderer.renderError(err.message));
115
121
  }
116
122
  }
117
123
  if (errorMessages.length > 0) {
@@ -123,22 +129,22 @@ class LambdaFlareCommand extends clipanion_1.Command {
123
129
  // Get AWS credentials
124
130
  this.context.stdout.write(chalk_1.default.bold('\n🔑 Getting AWS credentials...\n'));
125
131
  try {
126
- this.credentials = yield commons_1.getAWSCredentials();
132
+ this.credentials = yield (0, commons_1.getAWSCredentials)();
127
133
  }
128
134
  catch (err) {
129
135
  if (err instanceof Error) {
130
- this.context.stderr.write(commonRenderer.renderError(err.message));
136
+ this.context.stderr.write(helpersRenderer.renderError(err.message));
131
137
  }
132
138
  return 1;
133
139
  }
134
140
  if (this.credentials === undefined) {
135
141
  this.context.stdout.write('\n' + commonRenderer.renderNoAWSCredentialsFound());
136
142
  try {
137
- yield prompt_1.requestAWSCredentials();
143
+ yield (0, prompt_2.requestAWSCredentials)();
138
144
  }
139
145
  catch (err) {
140
146
  if (err instanceof Error) {
141
- this.context.stderr.write(commonRenderer.renderError(err.message));
147
+ this.context.stderr.write(helpersRenderer.renderError(err.message));
142
148
  }
143
149
  return 1;
144
150
  }
@@ -152,39 +158,33 @@ class LambdaFlareCommand extends clipanion_1.Command {
152
158
  const lambdaClient = new client_lambda_1.LambdaClient(lambdaClientConfig);
153
159
  let config;
154
160
  try {
155
- config = yield commons_1.getLambdaFunctionConfig(lambdaClient, this.functionName);
161
+ config = yield (0, commons_1.getLambdaFunctionConfig)(lambdaClient, this.functionName);
156
162
  }
157
163
  catch (err) {
158
164
  if (err instanceof Error) {
159
- this.context.stderr.write(commonRenderer.renderError(`Unable to get Lambda function configuration: ${err.message}`));
165
+ this.context.stderr.write(helpersRenderer.renderError(`Unable to get Lambda function configuration: ${err.message}`));
160
166
  }
161
167
  return 1;
162
168
  }
163
- config = exports.maskConfig(config);
164
- const configStr = util_1.default.inspect(config, false, undefined, true);
165
- this.context.stdout.write(`\n${configStr}\n`);
169
+ config = (0, commons_1.maskConfig)(config);
170
+ const summarizedConfig = (0, exports.summarizeConfig)(config);
171
+ const summarizedConfigStr = util_1.default.inspect(summarizedConfig, false, undefined, true);
172
+ this.context.stdout.write(`\n${summarizedConfigStr}\n`);
173
+ this.context.stdout.write(chalk_1.default.italic(`(This is a summary of the configuration. The full configuration will be saved in "${FUNCTION_CONFIG_FILE_NAME}".)\n`));
166
174
  // Get project files
167
175
  this.context.stdout.write(chalk_1.default.bold('\n📁 Searching for project files in current directory...\n'));
168
- const projectFilePaths = yield exports.getProjectFiles();
169
- let projectFilesMessage = chalk_1.default.bold(`\n✅ Found project file(s) in ${process.cwd()}:\n`);
170
- if (projectFilePaths.size === 0) {
171
- projectFilesMessage = commonRenderer.renderSoftWarning('No project files found.');
172
- }
173
- this.context.stdout.write(projectFilesMessage);
174
- for (const filePath of projectFilePaths) {
175
- const fileName = path.basename(filePath);
176
- this.context.stdout.write(`• ${fileName}\n`);
177
- }
176
+ const projectFilePaths = yield (0, flare_1.getProjectFiles)(constants_2.LAMBDA_PROJECT_FILES);
177
+ this.context.stdout.write((0, renderer_1.renderProjectFiles)(projectFilePaths));
178
178
  // Additional files
179
179
  this.context.stdout.write('\n');
180
180
  const additionalFilePaths = new Set();
181
181
  let confirmAdditionalFiles;
182
182
  try {
183
- confirmAdditionalFiles = yield prompt_1.requestConfirmation('Do you want to specify any additional files to flare?', false);
183
+ confirmAdditionalFiles = yield (0, prompt_1.requestConfirmation)('Do you want to specify any additional files to flare?', false);
184
184
  }
185
185
  catch (err) {
186
186
  if (err instanceof Error) {
187
- this.context.stderr.write(commonRenderer.renderError(err.message));
187
+ this.context.stderr.write(helpersRenderer.renderError(err.message));
188
188
  }
189
189
  return 1;
190
190
  }
@@ -192,24 +192,20 @@ class LambdaFlareCommand extends clipanion_1.Command {
192
192
  this.context.stdout.write('\n');
193
193
  let filePath;
194
194
  try {
195
- filePath = yield prompt_1.requestFilePath();
195
+ filePath = yield (0, prompt_1.requestFilePath)();
196
196
  }
197
197
  catch (err) {
198
198
  if (err instanceof Error) {
199
- this.context.stderr.write(commonRenderer.renderError(err.message));
199
+ this.context.stderr.write(helpersRenderer.renderError(err.message));
200
200
  }
201
201
  return 1;
202
202
  }
203
203
  if (filePath === '') {
204
- this.context.stdout.write(`Added ${additionalFilePaths.size} custom file(s):\n`);
205
- for (const additionalFilePath of additionalFilePaths) {
206
- const fileName = path.basename(additionalFilePath);
207
- this.context.stdout.write(`• ${fileName}\n`);
208
- }
204
+ this.context.stdout.write((0, renderer_1.renderAdditionalFiles)(additionalFilePaths));
209
205
  break;
210
206
  }
211
207
  try {
212
- filePath = exports.validateFilePath(filePath, projectFilePaths, additionalFilePaths);
208
+ filePath = (0, flare_1.validateFilePath)(filePath, projectFilePaths, additionalFilePaths);
213
209
  additionalFilePaths.add(filePath);
214
210
  const fileName = path.basename(filePath);
215
211
  this.context.stdout.write(`• Added file '${fileName}'\n`);
@@ -224,17 +220,17 @@ class LambdaFlareCommand extends clipanion_1.Command {
224
220
  this.context.stdout.write(chalk_1.default.bold('\n🏷 Getting Resource Tags...\n'));
225
221
  let tags;
226
222
  try {
227
- tags = yield exports.getTags(lambdaClient, region, config.FunctionArn);
223
+ tags = yield (0, exports.getTags)(lambdaClient, region, config.FunctionArn);
228
224
  }
229
225
  catch (err) {
230
226
  if (err instanceof Error) {
231
- this.context.stderr.write(commonRenderer.renderError(err.message));
227
+ this.context.stderr.write(helpersRenderer.renderError(err.message));
232
228
  }
233
229
  return 1;
234
230
  }
235
231
  const tagsLength = Object.keys(tags).length;
236
232
  if (tagsLength === 0) {
237
- this.context.stdout.write(commonRenderer.renderSoftWarning(`No resource tags were found.`));
233
+ this.context.stdout.write(helpersRenderer.renderSoftWarning(`No resource tags were found.`));
238
234
  }
239
235
  else {
240
236
  this.context.stdout.write(`Found ${tagsLength} resource tag(s).\n`);
@@ -244,11 +240,11 @@ class LambdaFlareCommand extends clipanion_1.Command {
244
240
  if (this.withLogs) {
245
241
  this.context.stdout.write(chalk_1.default.bold('\n🌧 Getting CloudWatch logs...\n'));
246
242
  try {
247
- logs = yield exports.getAllLogs(region, this.functionName, startMillis, endMillis);
243
+ logs = yield (0, exports.getAllLogs)(region, this.functionName, startMillis, endMillis);
248
244
  }
249
245
  catch (err) {
250
246
  if (err instanceof Error) {
251
- this.context.stderr.write(commonRenderer.renderError(err.message));
247
+ this.context.stderr.write(helpersRenderer.renderError(err.message));
252
248
  }
253
249
  return 1;
254
250
  }
@@ -258,25 +254,25 @@ class LambdaFlareCommand extends clipanion_1.Command {
258
254
  if (this.withLogs) {
259
255
  let message = chalk_1.default.bold('\n✅ Found log streams:\n');
260
256
  if (logs.size === 0) {
261
- message = commonRenderer.renderSoftWarning('No CloudWatch log streams were found. Logs will not be retrieved or sent.');
257
+ message = helpersRenderer.renderSoftWarning('No CloudWatch log streams were found. Logs will not be retrieved or sent.');
262
258
  }
263
259
  this.context.stdout.write(message);
264
260
  for (const [logStreamName, logEvents] of logs) {
265
261
  let warningMessage = '\n';
266
262
  if (logEvents.length === 0) {
267
- warningMessage = ' - ' + commonRenderer.renderSoftWarning('No log events found in this stream');
263
+ warningMessage = ` - ${helpersRenderer.renderSoftWarning('No log events found in this stream')}`;
268
264
  }
269
265
  this.context.stdout.write(`• ${logStreamName}${warningMessage}`);
270
266
  }
271
267
  }
272
268
  // Create folders
273
- const rootFolderPath = path.join(process.cwd(), FLARE_OUTPUT_DIRECTORY);
274
- const logsFolderPath = path.join(rootFolderPath, LOGS_DIRECTORY);
275
- const projectFilesFolderPath = path.join(rootFolderPath, PROJECT_FILES_DIRECTORY);
276
- const additionalFilesFolderPath = path.join(rootFolderPath, ADDITIONAL_FILES_DIRECTORY);
269
+ const rootFolderPath = path.join(process.cwd(), constants_1.FLARE_OUTPUT_DIRECTORY);
270
+ const logsFolderPath = path.join(rootFolderPath, constants_1.LOGS_DIRECTORY);
271
+ const projectFilesFolderPath = path.join(rootFolderPath, constants_1.PROJECT_FILES_DIRECTORY);
272
+ const additionalFilesFolderPath = path.join(rootFolderPath, constants_1.ADDITIONAL_FILES_DIRECTORY);
277
273
  this.context.stdout.write(chalk_1.default.bold(`\n💾 Saving files to ${rootFolderPath}...\n`));
278
274
  if (fs.existsSync(rootFolderPath)) {
279
- exports.deleteFolder(rootFolderPath);
275
+ (0, fs_1.deleteFolder)(rootFolderPath);
280
276
  }
281
277
  const subFolders = [];
282
278
  if (logs.size > 0) {
@@ -288,15 +284,15 @@ class LambdaFlareCommand extends clipanion_1.Command {
288
284
  if (additionalFilePaths.size > 0) {
289
285
  subFolders.push(additionalFilesFolderPath);
290
286
  }
291
- exports.createDirectories(rootFolderPath, subFolders);
287
+ (0, fs_1.createDirectories)(rootFolderPath, subFolders);
292
288
  // Write config file
293
289
  const configFilePath = path.join(rootFolderPath, FUNCTION_CONFIG_FILE_NAME);
294
- exports.writeFile(configFilePath, JSON.stringify(config, undefined, 2));
290
+ (0, fs_1.writeFile)(configFilePath, JSON.stringify(config, undefined, 2));
295
291
  this.context.stdout.write(`• Saved function config to ./${FUNCTION_CONFIG_FILE_NAME}\n`);
296
292
  // Write tags file
297
293
  if (tagsLength > 0) {
298
294
  const tagsFilePath = path.join(rootFolderPath, TAGS_FILE_NAME);
299
- exports.writeFile(tagsFilePath, JSON.stringify(tags, undefined, 2));
295
+ (0, fs_1.writeFile)(tagsFilePath, JSON.stringify(tags, undefined, 2));
300
296
  this.context.stdout.write(`• Saved tags to ./${TAGS_FILE_NAME}\n`);
301
297
  }
302
298
  // Write log files
@@ -305,65 +301,66 @@ class LambdaFlareCommand extends clipanion_1.Command {
305
301
  continue;
306
302
  }
307
303
  const logFilePath = path.join(logsFolderPath, `${logStreamName.split('/').join('-')}.csv`);
308
- const data = exports.convertToCSV(logEvents);
309
- exports.writeFile(logFilePath, data);
310
- this.context.stdout.write(`• Saved logs to ./${LOGS_DIRECTORY}/${logStreamName}\n`);
304
+ const data = (0, exports.convertToCSV)(logEvents);
305
+ (0, fs_1.writeFile)(logFilePath, data);
306
+ this.context.stdout.write(`• Saved logs to ./${constants_1.LOGS_DIRECTORY}/${logStreamName}\n`);
311
307
  // Sleep for 1 millisecond so creation times are different
312
308
  // This allows the logs to be sorted by creation time by the support team
313
- yield exports.sleep(1);
309
+ yield (0, exports.sleep)(1);
314
310
  }
315
311
  // Write project files
316
312
  for (const filePath of projectFilePaths) {
317
313
  const fileName = path.basename(filePath);
318
314
  const newFilePath = path.join(projectFilesFolderPath, fileName);
319
315
  fs.copyFileSync(filePath, newFilePath);
320
- this.context.stdout.write(`• Copied ${fileName} to ./${PROJECT_FILES_DIRECTORY}/${fileName}\n`);
316
+ this.context.stdout.write(`• Copied ${fileName} to ./${constants_1.PROJECT_FILES_DIRECTORY}/${fileName}\n`);
321
317
  }
322
318
  // Write additional files
323
- const additionalFilesMap = exports.getUniqueFileNames(additionalFilePaths);
319
+ const additionalFilesMap = (0, exports.getUniqueFileNames)(additionalFilePaths);
324
320
  for (const [originalFilePath, newFileName] of additionalFilesMap) {
325
321
  const originalFileName = path.basename(originalFilePath);
326
322
  const newFilePath = path.join(additionalFilesFolderPath, newFileName);
327
323
  fs.copyFileSync(originalFilePath, newFilePath);
328
- this.context.stdout.write(`• Copied ${originalFileName} to ./${ADDITIONAL_FILES_DIRECTORY}/${newFileName}\n`);
324
+ this.context.stdout.write(`• Copied ${originalFileName} to ./${constants_1.ADDITIONAL_FILES_DIRECTORY}/${newFileName}\n`);
325
+ }
326
+ // Write insights file
327
+ try {
328
+ const insightsFilePath = path.join(rootFolderPath, constants_1.INSIGHTS_FILE_NAME);
329
+ (0, exports.generateInsightsFile)(insightsFilePath, this.isDryRun, config);
330
+ this.context.stdout.write(`• Saved the insights file to ./${constants_1.INSIGHTS_FILE_NAME}\n`);
331
+ }
332
+ catch (err) {
333
+ const errorDetails = err instanceof Error ? err.message : '';
334
+ this.context.stdout.write(helpersRenderer.renderSoftWarning(`Unable to create INSIGHTS.md file. ${errorDetails}`));
329
335
  }
330
336
  // Exit if dry run
331
337
  const outputMsg = `\nℹ️ Your output files are located at: ${rootFolderPath}\n\n`;
332
338
  if (this.isDryRun) {
333
- this.context.stdout.write('\n🚫 The flare files were not sent as it was executed in dry run mode.');
339
+ this.context.stdout.write('\n🚫 The flare files were not sent because the command was executed in dry run mode.');
334
340
  this.context.stdout.write(outputMsg);
335
341
  return 0;
336
342
  }
337
343
  // Confirm before sending
338
344
  this.context.stdout.write('\n');
339
- let confirmSendFiles;
340
- try {
341
- confirmSendFiles = yield prompt_1.requestConfirmation('Are you sure you want to send the flare file to Datadog Support?', false);
342
- }
343
- catch (err) {
344
- if (err instanceof Error) {
345
- this.context.stderr.write(commonRenderer.renderError(err.message));
346
- }
347
- return 1;
348
- }
345
+ const confirmSendFiles = yield (0, prompt_1.requestConfirmation)('Are you sure you want to send the flare file to Datadog Support?', false);
349
346
  if (!confirmSendFiles) {
350
347
  this.context.stdout.write('\n🚫 The flare files were not sent based on your selection.');
351
348
  this.context.stdout.write(outputMsg);
352
349
  return 0;
353
350
  }
354
351
  // Zip folder
355
- const zipPath = path.join(rootFolderPath, ZIP_FILE_NAME);
356
- yield exports.zipContents(rootFolderPath, zipPath);
352
+ const zipPath = path.join(rootFolderPath, FLARE_ZIP_FILE_NAME);
353
+ yield (0, fs_1.zipContents)(rootFolderPath, zipPath);
357
354
  // Send to Datadog
358
355
  this.context.stdout.write(chalk_1.default.bold('\n🚀 Sending to Datadog Support...\n'));
359
- yield exports.sendToDatadog(zipPath, this.caseId, this.email, this.apiKey, rootFolderPath);
356
+ yield (0, flare_1.sendToDatadog)(zipPath, this.caseId, this.email, this.apiKey, rootFolderPath);
360
357
  this.context.stdout.write(chalk_1.default.bold('\n✅ Successfully sent flare file to Datadog Support!\n'));
361
358
  // Delete contents
362
- exports.deleteFolder(rootFolderPath);
359
+ (0, fs_1.deleteFolder)(rootFolderPath);
363
360
  }
364
361
  catch (err) {
365
362
  if (err instanceof Error) {
366
- this.context.stderr.write(commonRenderer.renderError(err.message));
363
+ this.context.stderr.write(helpersRenderer.renderError(err.message));
367
364
  }
368
365
  return 1;
369
366
  }
@@ -372,127 +369,26 @@ class LambdaFlareCommand extends clipanion_1.Command {
372
369
  }
373
370
  }
374
371
  exports.LambdaFlareCommand = LambdaFlareCommand;
372
+ LambdaFlareCommand.paths = [['lambda', 'flare']];
373
+ LambdaFlareCommand.usage = clipanion_1.Command.Usage({
374
+ category: 'Serverless',
375
+ description: 'Gather config, logs, tags, project files, and more from a Lambda function and sends them to Datadog support.',
376
+ });
375
377
  /**
376
- * Validate the start and end flags and adds error messages if found
377
- * @param start start time as a string
378
- * @param end end time as a string
379
- * @throws error if start or end are not valid numbers
380
- * @returns [startMillis, endMillis] as numbers or [undefined, undefined] if both are undefined
381
- */
382
- const validateStartEndFlags = (start, end) => {
383
- if (!start && !end) {
384
- return [undefined, undefined];
385
- }
386
- if (!start) {
387
- throw Error('Start time is required when end time is specified. [--start]');
388
- }
389
- if (!end) {
390
- throw Error('End time is required when start time is specified. [--end]');
391
- }
392
- const startMillis = Number(start);
393
- let endMillis = Number(end);
394
- if (isNaN(startMillis)) {
395
- throw Error(`Start time must be a time in milliseconds since Unix Epoch. '${start}' is not a number.`);
396
- }
397
- if (isNaN(endMillis)) {
398
- throw Error(`End time must be a time in milliseconds since Unix Epoch. '${end}' is not a number.`);
399
- }
400
- // Required for AWS SDK to work correctly
401
- endMillis = Math.min(endMillis, Date.now());
402
- if (startMillis >= endMillis) {
403
- throw Error('Start time must be before end time.');
404
- }
405
- return [startMillis, endMillis];
406
- };
407
- exports.validateStartEndFlags = validateStartEndFlags;
408
- /**
409
- * Mask the environment variables in a Lambda function configuration
378
+ * Summarizes the Lambda config as to not flood the terminal
410
379
  * @param config
380
+ * @returns a summarized config
411
381
  */
412
- const maskConfig = (config) => {
413
- var _a;
414
- const environmentVariables = (_a = config.Environment) === null || _a === void 0 ? void 0 : _a.Variables;
415
- if (!environmentVariables) {
416
- return config;
417
- }
418
- const replacer = commons_1.maskStringifiedEnvVar(environmentVariables);
419
- const stringifiedConfig = JSON.stringify(config, replacer);
420
- return JSON.parse(stringifiedConfig);
421
- };
422
- exports.maskConfig = maskConfig;
423
- /**
424
- * Delete a folder and all its contents
425
- * @param folderPath the folder to delete
426
- * @throws Error if the deletion fails
427
- */
428
- const deleteFolder = (folderPath) => {
429
- try {
430
- fs.rmSync(folderPath, { recursive: true, force: true });
431
- }
432
- catch (err) {
433
- if (err instanceof Error) {
434
- throw Error(`Failed to delete files located at ${folderPath}: ${err.message}`);
435
- }
436
- }
437
- };
438
- exports.deleteFolder = deleteFolder;
439
- /**
440
- * Creates the root folder and any subfolders
441
- * @param rootFolderPath path to the root folder
442
- * @param subFolders paths to any subfolders to be created
443
- * @throws Error if the root folder cannot be deleted or folders cannot be created
444
- */
445
- const createDirectories = (rootFolderPath, subFolders) => {
446
- try {
447
- fs.mkdirSync(rootFolderPath);
448
- for (const subFolder of subFolders) {
449
- fs.mkdirSync(subFolder);
450
- }
451
- }
452
- catch (err) {
453
- if (err instanceof Error) {
454
- throw Error(`Unable to create directories: ${err.message}`);
455
- }
456
- }
457
- };
458
- exports.createDirectories = createDirectories;
459
- /**
460
- * Searches current directory for project files
461
- * @returns a set of file paths of project files
462
- */
463
- const getProjectFiles = () => __awaiter(void 0, void 0, void 0, function* () {
464
- const filePaths = new Set();
465
- const cwd = process.cwd();
466
- for (const fileName of constants_2.PROJECT_FILES) {
467
- const filePath = path.join(cwd, fileName);
468
- if (fs.existsSync(filePath)) {
469
- filePaths.add(filePath);
382
+ const summarizeConfig = (config) => {
383
+ const summarizedConfig = {};
384
+ for (const key in config) {
385
+ if (SUMMARIZED_FIELDS.has(key)) {
386
+ summarizedConfig[key] = config[key];
470
387
  }
471
388
  }
472
- return filePaths;
473
- });
474
- exports.getProjectFiles = getProjectFiles;
475
- /**
476
- * Validates a path to a file
477
- * @param filePath path to the file
478
- * @param projectFilePaths map of file names to file paths
479
- * @param additionalFiles set of additional file paths
480
- * @throws Error if the file path is invalid or the file was already added
481
- * @returns the full path to the file
482
- */
483
- const validateFilePath = (filePath, projectFilePaths, additionalFiles) => {
484
- const originalPath = filePath;
485
- filePath = fs.existsSync(filePath) ? filePath : path.join(process.cwd(), filePath);
486
- if (!fs.existsSync(filePath)) {
487
- throw Error(commonRenderer.renderError(`File path '${originalPath}' not found. Please try again.`));
488
- }
489
- filePath = path.resolve(filePath);
490
- if (projectFilePaths.has(filePath) || additionalFiles.has(filePath)) {
491
- throw Error(commonRenderer.renderSoftWarning(`File '${filePath}' has already been added.`));
492
- }
493
- return filePath;
389
+ return summarizedConfig;
494
390
  };
495
- exports.validateFilePath = validateFilePath;
391
+ exports.summarizeConfig = summarizeConfig;
496
392
  /**
497
393
  * Gets the LOG_STREAM_COUNT latest log stream names, sorted by last event time
498
394
  * @param cwlClient CloudWatch Logs client
@@ -587,7 +483,7 @@ const getAllLogs = (region, functionName, startMillis, endMillis) => __awaiter(v
587
483
  const logGroupName = `/aws/lambda/${functionName}`;
588
484
  let logStreamNames;
589
485
  try {
590
- logStreamNames = yield exports.getLogStreamNames(cwlClient, logGroupName, startMillis, endMillis);
486
+ logStreamNames = yield (0, exports.getLogStreamNames)(cwlClient, logGroupName, startMillis, endMillis);
591
487
  }
592
488
  catch (err) {
593
489
  const msg = err instanceof Error ? err.message : '';
@@ -596,7 +492,7 @@ const getAllLogs = (region, functionName, startMillis, endMillis) => __awaiter(v
596
492
  for (const logStreamName of logStreamNames) {
597
493
  let logEvents;
598
494
  try {
599
- logEvents = yield exports.getLogEvents(cwlClient, logGroupName, logStreamName, startMillis, endMillis);
495
+ logEvents = yield (0, exports.getLogEvents)(cwlClient, logGroupName, logStreamName, startMillis, endMillis);
600
496
  }
601
497
  catch (err) {
602
498
  const msg = err instanceof Error ? err.message : '';
@@ -636,23 +532,6 @@ const getTags = (lambdaClient, region, arn) => __awaiter(void 0, void 0, void 0,
636
532
  }
637
533
  });
638
534
  exports.getTags = getTags;
639
- /**
640
- * Write the function config to a file
641
- * @param filePath path to the file
642
- * @param data the data to write
643
- * @throws Error if the file cannot be written
644
- */
645
- const writeFile = (filePath, data) => {
646
- try {
647
- fs.writeFileSync(filePath, data);
648
- }
649
- catch (err) {
650
- if (err instanceof Error) {
651
- throw Error(`Unable to create function configuration file: ${err.message}`);
652
- }
653
- }
654
- };
655
- exports.writeFile = writeFile;
656
535
  /**
657
536
  * Generate unique file names
658
537
  * If the original file name is unique, keep it as is
@@ -716,108 +595,79 @@ const sleep = (ms) => __awaiter(void 0, void 0, void 0, function* () {
716
595
  });
717
596
  exports.sleep = sleep;
718
597
  /**
719
- * Zip the contents of the flare folder
720
- * @param rootFolderPath path to the root folder to zip
721
- * @param zipPath path to save the zip file
722
- * @throws Error if the zip fails
598
+ * Get the framework used based on the files in the directory
599
+ * @returns the framework used or undefined if no framework is found
723
600
  */
724
- const zipContents = (rootFolderPath, zipPath) => __awaiter(void 0, void 0, void 0, function* () {
725
- const zip = new jszip_1.default();
726
- const addFolderToZip = (folderPath) => {
727
- if (!fs.existsSync(folderPath)) {
728
- throw Error(`Folder does not exist: ${folderPath}`);
729
- }
730
- const folder = fs.statSync(folderPath);
731
- if (!folder.isDirectory()) {
732
- throw Error(`Path is not a directory: ${folderPath}`);
733
- }
734
- const contents = fs.readdirSync(folderPath);
735
- for (const item of contents) {
736
- const fullPath = path.join(folderPath, item);
737
- const file = fs.statSync(fullPath);
738
- if (file.isDirectory()) {
739
- addFolderToZip(fullPath);
740
- }
741
- else {
742
- const data = fs.readFileSync(fullPath);
743
- zip.file(path.relative(rootFolderPath, fullPath), data);
744
- }
745
- }
746
- };
747
- try {
748
- addFolderToZip(rootFolderPath);
749
- const zipContent = yield zip.generateAsync({ type: 'nodebuffer' });
750
- fs.writeFileSync(zipPath, zipContent);
751
- }
752
- catch (err) {
753
- if (err instanceof Error) {
754
- throw Error(`Unable to zip the flare files: ${err.message}`);
601
+ const getFramework = () => {
602
+ const frameworks = new Set();
603
+ const files = fs.readdirSync(process.cwd());
604
+ files.forEach((file) => {
605
+ if (constants_2.FRAMEWORK_FILES_MAPPING.has(file)) {
606
+ frameworks.add(constants_2.FRAMEWORK_FILES_MAPPING.get(file));
755
607
  }
608
+ });
609
+ if (frameworks.size > 0) {
610
+ return Array.from(frameworks).join(', ');
756
611
  }
757
- });
758
- exports.zipContents = zipContents;
759
- /**
760
- * Calculates the full endpoint URL
761
- * @throws Error if the site is invalid
762
- * @returns the full endpoint URL
763
- */
764
- const getEndpointUrl = () => {
765
- var _a, _b;
766
- const baseUrl = (_b = (_a = process.env[constants_2.CI_SITE_ENV_VAR]) !== null && _a !== void 0 ? _a : process.env[constants_2.SITE_ENV_VAR]) !== null && _b !== void 0 ? _b : constants_1.DATADOG_SITE_US1;
767
- // The DNS doesn't redirect to the proper endpoint when a subdomain is not present in the baseUrl.
768
- // There is a DNS inconsistency
769
- let endpointUrl = baseUrl;
770
- if ([constants_1.DATADOG_SITE_US1, constants_1.DATADOG_SITE_EU1, constants_1.DATADOG_SITE_GOV].includes(baseUrl)) {
771
- endpointUrl = 'app.' + baseUrl;
772
- }
773
- if (!validation_1.isValidDatadogSite(baseUrl)) {
774
- throw Error(`Invalid site: ${baseUrl}. Must be one of: ${constants_1.DATADOG_SITES.join(', ')}`);
775
- }
776
- return 'https://' + endpointUrl + ENDPOINT_PATH;
612
+ return constants_2.DeploymentFrameworks.Unknown;
777
613
  };
778
- exports.getEndpointUrl = getEndpointUrl;
614
+ exports.getFramework = getFramework;
779
615
  /**
780
- * Send the zip file to Datadog support
781
- * @param zipPath
782
- * @param caseId
783
- * @param email
784
- * @param apiKey
785
- * @param rootFolderPath
786
- * @throws Error if the request fails
616
+ * Generate the insights file
617
+ * @param insightsFilePath path to the insights file
618
+ * @param isDryRun whether or not this is a dry run
619
+ * @param config Lambda function configuration
787
620
  */
788
- const sendToDatadog = (zipPath, caseId, email, apiKey, rootFolderPath) => __awaiter(void 0, void 0, void 0, function* () {
789
- var _b, _c, _d;
790
- const endpointUrl = exports.getEndpointUrl();
791
- const form = new form_data_1.default();
792
- form.append('case_id', caseId);
793
- form.append('flare_file', fs.createReadStream(zipPath));
794
- form.append('datadog_ci_version', version);
795
- form.append('email', email);
796
- const headerConfig = {
797
- headers: Object.assign(Object.assign({}, form.getHeaders()), { 'DD-API-KEY': apiKey }),
798
- };
799
- try {
800
- yield axios_1.default.post(endpointUrl, form, headerConfig);
801
- }
802
- catch (err) {
803
- // Ensure the root folder is deleted if the request fails
804
- exports.deleteFolder(rootFolderPath);
805
- if (axios_1.default.isAxiosError(err)) {
806
- const errResponse = (_c = (_b = err.response) === null || _b === void 0 ? void 0 : _b.data.error) !== null && _c !== void 0 ? _c : '';
807
- const errorMessage = (_d = err.message) !== null && _d !== void 0 ? _d : '';
808
- throw Error(`Failed to send flare file to Datadog Support: ${errorMessage}. ${errResponse}\n`);
621
+ const generateInsightsFile = (insightsFilePath, isDryRun, config) => {
622
+ var _a, _b, _c, _d, _e;
623
+ const lines = [];
624
+ // Header
625
+ lines.push('# Flare Insights');
626
+ lines.push('\n_Autogenerated file from `lambda flare`_ ');
627
+ if (isDryRun) {
628
+ lines.push('_This command was run in dry mode._');
629
+ }
630
+ // AWS Lambda Configuration
631
+ lines.push('\n## AWS Lambda Configuration');
632
+ lines.push(`**Function Name**: \`${config.FunctionName}\` `);
633
+ lines.push(`**Function ARN**: \`${config.FunctionArn}\` `);
634
+ lines.push(`**Runtime**: \`${config.Runtime}\` `);
635
+ lines.push(`**Handler**: \`${config.Handler}\` `);
636
+ lines.push(`**Timeout**: \`${config.Timeout}\` `);
637
+ lines.push(`**Memory Size**: \`${config.MemorySize}\` `);
638
+ const architectures = (_a = config.Architectures) !== null && _a !== void 0 ? _a : ['Unknown'];
639
+ lines.push(`**Architecture**: \`${architectures.join(', ')}\` `);
640
+ lines.push('**Environment Variables**:');
641
+ const envVars = Object.entries((_c = (_b = config.Environment) === null || _b === void 0 ? void 0 : _b.Variables) !== null && _c !== void 0 ? _c : {});
642
+ if (envVars.length === 0) {
643
+ lines.push('- No environment variables found.');
644
+ }
645
+ for (const [key, value] of envVars) {
646
+ lines.push(`- \`${key}\`: \`${value}\``);
647
+ }
648
+ lines.push('\n**Layers**:');
649
+ const layers = (_d = config.Layers) !== null && _d !== void 0 ? _d : [];
650
+ if (layers.length === 0) {
651
+ lines.push(' - No layers found.');
652
+ }
653
+ let codeSize = (_e = config.CodeSize) !== null && _e !== void 0 ? _e : 0;
654
+ layers.forEach((layer) => {
655
+ var _a, _b;
656
+ const nameAndVersion = (0, commons_1.getLayerNameWithVersion)((_a = layer.Arn) !== null && _a !== void 0 ? _a : '');
657
+ if (nameAndVersion) {
658
+ lines.push(`- \`${nameAndVersion}\``);
809
659
  }
810
- throw err;
811
- }
812
- });
813
- exports.sendToDatadog = sendToDatadog;
814
- LambdaFlareCommand.addPath('lambda', 'flare');
815
- LambdaFlareCommand.addOption('isDryRun', clipanion_1.Command.Boolean('-d,--dry'));
816
- LambdaFlareCommand.addOption('withLogs', clipanion_1.Command.Boolean('--with-logs'));
817
- LambdaFlareCommand.addOption('functionName', clipanion_1.Command.String('-f,--function'));
818
- LambdaFlareCommand.addOption('region', clipanion_1.Command.String('-r,--region'));
819
- LambdaFlareCommand.addOption('caseId', clipanion_1.Command.String('-c,--case-id'));
820
- LambdaFlareCommand.addOption('email', clipanion_1.Command.String('-e,--email'));
821
- LambdaFlareCommand.addOption('start', clipanion_1.Command.String('--start'));
822
- LambdaFlareCommand.addOption('end', clipanion_1.Command.String('--end'));
660
+ codeSize += (_b = layer.CodeSize) !== null && _b !== void 0 ? _b : 0;
661
+ });
662
+ lines.push(`\n**Package Size**: \`${(0, utils_1.formatBytes)(codeSize)}\``);
663
+ // CLI Insights
664
+ lines.push('\n ## CLI');
665
+ lines.push(`**Run Location**: \`${process.cwd()}\` `);
666
+ lines.push(`**CLI Version**: \`${version_1.version}\` `);
667
+ const timeString = new Date().toISOString().replace('T', ' ').replace('Z', '') + ' UTC';
668
+ lines.push(`**Timestamp**: \`${timeString}\` `);
669
+ lines.push(`**Framework**: \`${(0, exports.getFramework)()}\``);
670
+ (0, fs_1.writeFile)(insightsFilePath, lines.join('\n'));
671
+ };
672
+ exports.generateInsightsFile = generateInsightsFile;
823
673
  //# sourceMappingURL=flare.js.map