levelfour 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 (279) hide show
  1. package/.fernignore +9 -0
  2. package/BaseClient.ts +56 -0
  3. package/Client.ts +90 -0
  4. package/LevelFourClient.ts +50 -0
  5. package/api/errors/UnprocessableEntityError.ts +22 -0
  6. package/api/errors/index.ts +1 -0
  7. package/api/index.ts +3 -0
  8. package/api/resources/apiKeys/client/Client.ts +298 -0
  9. package/api/resources/apiKeys/client/index.ts +1 -0
  10. package/api/resources/apiKeys/client/requests/CreateApiKeyRequest.ts +23 -0
  11. package/api/resources/apiKeys/client/requests/ListApiKeysApiV1ApiKeysGetRequest.ts +11 -0
  12. package/api/resources/apiKeys/client/requests/RevokeApiKeyApiV1ApiKeysKeyIdDeleteRequest.ts +14 -0
  13. package/api/resources/apiKeys/client/requests/RotateApiKeyApiV1ApiKeysKeyIdRotatePostRequest.ts +14 -0
  14. package/api/resources/apiKeys/client/requests/index.ts +4 -0
  15. package/api/resources/apiKeys/exports.ts +4 -0
  16. package/api/resources/apiKeys/index.ts +1 -0
  17. package/api/resources/evaluation/client/Client.ts +71 -0
  18. package/api/resources/evaluation/client/index.ts +1 -0
  19. package/api/resources/evaluation/exports.ts +4 -0
  20. package/api/resources/evaluation/index.ts +1 -0
  21. package/api/resources/health/client/Client.ts +108 -0
  22. package/api/resources/health/client/index.ts +1 -0
  23. package/api/resources/health/exports.ts +4 -0
  24. package/api/resources/health/index.ts +1 -0
  25. package/api/resources/index.ts +24 -0
  26. package/api/resources/prAnalysis/client/Client.ts +100 -0
  27. package/api/resources/prAnalysis/client/index.ts +1 -0
  28. package/api/resources/prAnalysis/client/requests/AnalyzePrRequest.ts +30 -0
  29. package/api/resources/prAnalysis/client/requests/index.ts +1 -0
  30. package/api/resources/prAnalysis/exports.ts +4 -0
  31. package/api/resources/prAnalysis/index.ts +1 -0
  32. package/api/resources/prAnalysisActions/client/Client.ts +418 -0
  33. package/api/resources/prAnalysisActions/client/index.ts +1 -0
  34. package/api/resources/prAnalysisActions/client/requests/DismissSuggestionsApiV1PrAnalysisActionsDismissPostRequest.ts +21 -0
  35. package/api/resources/prAnalysisActions/client/requests/GetIgnoredResourcesApiV1PrAnalysisActionsIgnoreGetRequest.ts +15 -0
  36. package/api/resources/prAnalysisActions/client/requests/GetPrStatusApiV1PrAnalysisActionsStatusGetRequest.ts +15 -0
  37. package/api/resources/prAnalysisActions/client/requests/IgnoreRequest.ts +21 -0
  38. package/api/resources/prAnalysisActions/client/requests/SnoozeSuggestionsApiV1PrAnalysisActionsSnoozePostRequest.ts +21 -0
  39. package/api/resources/prAnalysisActions/client/requests/index.ts +5 -0
  40. package/api/resources/prAnalysisActions/exports.ts +4 -0
  41. package/api/resources/prAnalysisActions/index.ts +1 -0
  42. package/api/resources/prAnalysisInstallations/client/Client.ts +410 -0
  43. package/api/resources/prAnalysisInstallations/client/index.ts +1 -0
  44. package/api/resources/prAnalysisInstallations/client/requests/AddReposRequest.ts +17 -0
  45. package/api/resources/prAnalysisInstallations/client/requests/DeleteInstallationApiV1PrAnalysisInstallationsInstallationIdDeleteRequest.ts +15 -0
  46. package/api/resources/prAnalysisInstallations/client/requests/ListInstallationsApiV1PrAnalysisInstallationsGetRequest.ts +13 -0
  47. package/api/resources/prAnalysisInstallations/client/requests/RegisterInstallationRequest.ts +16 -0
  48. package/api/resources/prAnalysisInstallations/client/requests/RemoveReposRequest.ts +17 -0
  49. package/api/resources/prAnalysisInstallations/client/requests/index.ts +5 -0
  50. package/api/resources/prAnalysisInstallations/exports.ts +4 -0
  51. package/api/resources/prAnalysisInstallations/index.ts +1 -0
  52. package/api/resources/prAnalysisQuery/client/Client.ts +169 -0
  53. package/api/resources/prAnalysisQuery/client/index.ts +1 -0
  54. package/api/resources/prAnalysisQuery/client/requests/ExplainRequest.ts +17 -0
  55. package/api/resources/prAnalysisQuery/client/requests/WhatifRequest.ts +21 -0
  56. package/api/resources/prAnalysisQuery/client/requests/index.ts +2 -0
  57. package/api/resources/prAnalysisQuery/exports.ts +4 -0
  58. package/api/resources/prAnalysisQuery/index.ts +1 -0
  59. package/api/resources/providers/client/Client.ts +991 -0
  60. package/api/resources/providers/client/index.ts +1 -0
  61. package/api/resources/providers/client/requests/GetProviderFilterOptionsApiV1ProvidersProviderIdSpendingFilterOptionsGetRequest.ts +17 -0
  62. package/api/resources/providers/client/requests/GetProviderPotentialSavingsBreakdownApiV1ProvidersProviderIdPotentialSavingsBreakdownGetRequest.ts +19 -0
  63. package/api/resources/providers/client/requests/GetProviderPotentialSavingsSummaryApiV1ProvidersProviderIdPotentialSavingsSummaryGetRequest.ts +11 -0
  64. package/api/resources/providers/client/requests/GetProviderRecommendationFilterOptionsApiV1ProvidersProviderIdRecommendationsFilterOptionsGetRequest.ts +11 -0
  65. package/api/resources/providers/client/requests/GetProviderRecommendationsBreakdownApiV1ProvidersProviderIdRecommendationsGetRequest.ts +33 -0
  66. package/api/resources/providers/client/requests/GetProviderRecommendationsOverviewApiV1ProvidersProviderIdRecommendationsOverviewGetRequest.ts +11 -0
  67. package/api/resources/providers/client/requests/GetProviderRecommendationsSummaryApiV1ProvidersProviderIdRecommendationsSummaryGetRequest.ts +11 -0
  68. package/api/resources/providers/client/requests/GetProviderSavedSummaryApiV1ProvidersProviderIdSavingsSummaryGetRequest.ts +11 -0
  69. package/api/resources/providers/client/requests/GetProviderServiceBreakdownApiV1ProvidersProviderIdSpendingBreakdownGetRequest.ts +45 -0
  70. package/api/resources/providers/client/requests/GetProviderSpendingSummaryApiV1ProvidersProviderIdSpendingSummaryGetRequest.ts +11 -0
  71. package/api/resources/providers/client/requests/GetProviderSpendingTimelineApiV1ProvidersProviderIdSpendingTimelineGetRequest.ts +17 -0
  72. package/api/resources/providers/client/requests/GetSavedByProviderBreakdownApiV1ProvidersProviderIdSavingsBreakdownGetRequest.ts +31 -0
  73. package/api/resources/providers/client/requests/index.ts +12 -0
  74. package/api/resources/providers/exports.ts +4 -0
  75. package/api/resources/providers/index.ts +2 -0
  76. package/api/resources/providers/types/GetProviderServiceBreakdownApiV1ProvidersProviderIdSpendingBreakdownGetResponse.ts +8 -0
  77. package/api/resources/providers/types/index.ts +1 -0
  78. package/api/resources/recommendations/client/Client.ts +815 -0
  79. package/api/resources/recommendations/client/index.ts +1 -0
  80. package/api/resources/recommendations/client/requests/AcceptTermsApiV1RecommendationsRecommendationIdAcceptTermsPostRequest.ts +11 -0
  81. package/api/resources/recommendations/client/requests/CompleteWizardApiV1RecommendationsRecommendationIdCompletePostRequest.ts +11 -0
  82. package/api/resources/recommendations/client/requests/GetRecommendationDetailsApiV1RecommendationsRecommendationIdDetailsGetRequest.ts +11 -0
  83. package/api/resources/recommendations/client/requests/GetRecommendationForWizardApiV1RecommendationsRecommendationIdGetRequest.ts +11 -0
  84. package/api/resources/recommendations/client/requests/GetRecommendationsApiV1RecommendationsGetRequest.ts +16 -0
  85. package/api/resources/recommendations/client/requests/ImplementationMethodRequest.ts +14 -0
  86. package/api/resources/recommendations/client/requests/SavingsDecisionRequest.ts +18 -0
  87. package/api/resources/recommendations/client/requests/UpdateTagRequest.ts +13 -0
  88. package/api/resources/recommendations/client/requests/index.ts +8 -0
  89. package/api/resources/recommendations/exports.ts +4 -0
  90. package/api/resources/recommendations/index.ts +1 -0
  91. package/api/resources/savings/client/Client.ts +231 -0
  92. package/api/resources/savings/client/index.ts +1 -0
  93. package/api/resources/savings/client/requests/ExecutionRequestBody.ts +15 -0
  94. package/api/resources/savings/client/requests/GetSavedBreakdownApiV1SavingsBreakdownGetRequest.ts +30 -0
  95. package/api/resources/savings/client/requests/index.ts +2 -0
  96. package/api/resources/savings/exports.ts +4 -0
  97. package/api/resources/savings/index.ts +1 -0
  98. package/api/resources/spending/client/Client.ts +288 -0
  99. package/api/resources/spending/client/index.ts +1 -0
  100. package/api/resources/spending/client/requests/GetCostBreakdownApiV1SpendingBreakdownGetRequest.ts +30 -0
  101. package/api/resources/spending/client/requests/GetDailySpendingBreakdownApiV1SpendingDailyBreakdownGetRequest.ts +12 -0
  102. package/api/resources/spending/client/requests/index.ts +2 -0
  103. package/api/resources/spending/exports.ts +4 -0
  104. package/api/resources/spending/index.ts +2 -0
  105. package/api/resources/spending/types/GetCostBreakdownApiV1SpendingBreakdownGetResponse.ts +9 -0
  106. package/api/resources/spending/types/index.ts +1 -0
  107. package/api/resources/webhooks/client/Client.ts +232 -0
  108. package/api/resources/webhooks/client/index.ts +1 -0
  109. package/api/resources/webhooks/client/requests/DeleteEndpointApiV1WebhooksEndpointsEndpointIdDeleteRequest.ts +14 -0
  110. package/api/resources/webhooks/client/requests/ListEndpointsApiV1WebhooksEndpointsGetRequest.ts +11 -0
  111. package/api/resources/webhooks/client/requests/RegisterEndpointRequest.ts +18 -0
  112. package/api/resources/webhooks/client/requests/index.ts +3 -0
  113. package/api/resources/webhooks/exports.ts +4 -0
  114. package/api/resources/webhooks/index.ts +1 -0
  115. package/api/types/AcceptTermsData.ts +10 -0
  116. package/api/types/AcceptTermsResponse.ts +12 -0
  117. package/api/types/ActionRequest.ts +14 -0
  118. package/api/types/ApiKeyCreatedData.ts +13 -0
  119. package/api/types/ApiKeyData.ts +12 -0
  120. package/api/types/ComparisonItem.ts +10 -0
  121. package/api/types/CompleteWizardData.ts +12 -0
  122. package/api/types/CompleteWizardResponse.ts +12 -0
  123. package/api/types/CostBreakdownData.ts +14 -0
  124. package/api/types/CostBreakdownItem.ts +27 -0
  125. package/api/types/CostBreakdownRawData.ts +15 -0
  126. package/api/types/CostBreakdownRawResponse.ts +12 -0
  127. package/api/types/CostBreakdownResponse.ts +12 -0
  128. package/api/types/CostsBreakdownChartData.ts +19 -0
  129. package/api/types/CostsBreakdownChartResponse.ts +12 -0
  130. package/api/types/CostsBreakdownDataPoint.ts +17 -0
  131. package/api/types/CostsBreakdownGroupedChartData.ts +21 -0
  132. package/api/types/CostsBreakdownGroupedChartResponse.ts +12 -0
  133. package/api/types/CostsBreakdownGroupedDataPoint.ts +13 -0
  134. package/api/types/CostsBreakdownTotals.ts +15 -0
  135. package/api/types/CreateApiKeyResponse.ts +9 -0
  136. package/api/types/DailySpendingBreakdownData.ts +17 -0
  137. package/api/types/DailySpendingBreakdownResponse.ts +12 -0
  138. package/api/types/DailySpendingDataPoint.ts +11 -0
  139. package/api/types/DashboardSummaryData.ts +29 -0
  140. package/api/types/DashboardSummaryResponse.ts +12 -0
  141. package/api/types/DeleteEndpointData.ts +6 -0
  142. package/api/types/DeleteEndpointResponse.ts +9 -0
  143. package/api/types/EndpointData.ts +9 -0
  144. package/api/types/EvaluationStatusData.ts +27 -0
  145. package/api/types/EvaluationStatusResponse.ts +12 -0
  146. package/api/types/ExecutionLogCommand.ts +7 -0
  147. package/api/types/ExecutionLogEntry.ts +10 -0
  148. package/api/types/ExecutionStepSchema.ts +9 -0
  149. package/api/types/HttpValidationError.ts +7 -0
  150. package/api/types/ImplementationMethodData.ts +10 -0
  151. package/api/types/ImplementationMethodResponse.ts +12 -0
  152. package/api/types/ImplementationStep.ts +8 -0
  153. package/api/types/ListApiKeysData.ts +8 -0
  154. package/api/types/ListApiKeysResponse.ts +9 -0
  155. package/api/types/ListEndpointsResponse.ts +9 -0
  156. package/api/types/MetricDataPoint.ts +8 -0
  157. package/api/types/MetricSeries.ts +15 -0
  158. package/api/types/MetricSeriesEntry.ts +9 -0
  159. package/api/types/MonthlySpendingData.ts +11 -0
  160. package/api/types/MonthlySpendingDataPoint.ts +11 -0
  161. package/api/types/MonthlySpendingResponse.ts +12 -0
  162. package/api/types/PaginationMeta.ts +19 -0
  163. package/api/types/ProcessingRecommendationItem.ts +23 -0
  164. package/api/types/ProcessingRecommendationsData.ts +12 -0
  165. package/api/types/ProcessingRecommendationsResponse.ts +12 -0
  166. package/api/types/Provider.ts +17 -0
  167. package/api/types/ProviderBreakdownData.ts +13 -0
  168. package/api/types/ProviderBreakdownItem.ts +31 -0
  169. package/api/types/ProviderBreakdownResponse.ts +12 -0
  170. package/api/types/ProviderFilterOptionsData.ts +19 -0
  171. package/api/types/ProviderFilterOptionsResponse.ts +12 -0
  172. package/api/types/ProviderPotentialSavingsSummaryData.ts +17 -0
  173. package/api/types/ProviderPotentialSavingsSummaryResponse.ts +12 -0
  174. package/api/types/ProviderRecommendationsSummaryData.ts +15 -0
  175. package/api/types/ProviderRecommendationsSummaryResponse.ts +12 -0
  176. package/api/types/ProviderSavedSummaryData.ts +21 -0
  177. package/api/types/ProviderSavedSummaryResponse.ts +12 -0
  178. package/api/types/ProviderServiceBreakdownData.ts +26 -0
  179. package/api/types/ProviderServiceBreakdownItem.ts +29 -0
  180. package/api/types/ProviderServiceBreakdownRawData.ts +25 -0
  181. package/api/types/ProviderServiceBreakdownRawResponse.ts +12 -0
  182. package/api/types/ProviderServiceBreakdownResponse.ts +12 -0
  183. package/api/types/ProviderServiceCostsBreakdownData.ts +25 -0
  184. package/api/types/ProviderServiceCostsBreakdownResponse.ts +12 -0
  185. package/api/types/ProviderServiceCostsDataPoint.ts +13 -0
  186. package/api/types/ProviderSpending.ts +23 -0
  187. package/api/types/ProviderSpendingSummaryData.ts +27 -0
  188. package/api/types/ProviderSpendingSummaryResponse.ts +12 -0
  189. package/api/types/ProviderTimelineData.ts +23 -0
  190. package/api/types/ProviderTimelineResponse.ts +12 -0
  191. package/api/types/ProviderTopService.ts +13 -0
  192. package/api/types/ProvidersSummaryData.ts +10 -0
  193. package/api/types/ProvidersSummaryResponse.ts +12 -0
  194. package/api/types/RecommendationActions.ts +28 -0
  195. package/api/types/RecommendationDetail.ts +22 -0
  196. package/api/types/RecommendationDetailResponse.ts +12 -0
  197. package/api/types/RecommendationFilterOptionsData.ts +15 -0
  198. package/api/types/RecommendationFilterOptionsResponse.ts +12 -0
  199. package/api/types/RecommendationItem.ts +19 -0
  200. package/api/types/RecommendationWizardData.ts +83 -0
  201. package/api/types/RecommendationWizardResponse.ts +12 -0
  202. package/api/types/RecommendationsBreakdownData.ts +11 -0
  203. package/api/types/RecommendationsBreakdownResponse.ts +12 -0
  204. package/api/types/RecommendationsOverviewData.ts +19 -0
  205. package/api/types/RecommendationsOverviewResponse.ts +12 -0
  206. package/api/types/RegisterEndpointResponse.ts +9 -0
  207. package/api/types/ResourceChange.ts +14 -0
  208. package/api/types/ResourceSnapshot.ts +7 -0
  209. package/api/types/RevokeApiKeyData.ts +6 -0
  210. package/api/types/RevokeApiKeyResponse.ts +9 -0
  211. package/api/types/RiskAssessment.ts +11 -0
  212. package/api/types/RiskFactor.ts +8 -0
  213. package/api/types/SavedBreakdownData.ts +13 -0
  214. package/api/types/SavedBreakdownResponse.ts +12 -0
  215. package/api/types/SavedByProviderBreakdownData.ts +13 -0
  216. package/api/types/SavedByProviderBreakdownResponse.ts +12 -0
  217. package/api/types/SavedByProviderItem.ts +29 -0
  218. package/api/types/SavedItem.ts +20 -0
  219. package/api/types/SavedProviderSummary.ts +13 -0
  220. package/api/types/SavedSummaryData.ts +23 -0
  221. package/api/types/SavedSummaryResponse.ts +12 -0
  222. package/api/types/SavingsDecisionData.ts +13 -0
  223. package/api/types/SavingsDecisionResponse.ts +12 -0
  224. package/api/types/SpendingByDateItem.ts +13 -0
  225. package/api/types/TopRecommendation.ts +21 -0
  226. package/api/types/TriggerInfo.ts +8 -0
  227. package/api/types/UpdateTagData.ts +6 -0
  228. package/api/types/UpdateTagResponse.ts +9 -0
  229. package/api/types/ValidationError.ts +17 -0
  230. package/api/types/index.ts +115 -0
  231. package/core/exports.ts +1 -0
  232. package/core/fetcher/APIResponse.ts +23 -0
  233. package/core/fetcher/BinaryResponse.ts +34 -0
  234. package/core/fetcher/EndpointMetadata.ts +13 -0
  235. package/core/fetcher/EndpointSupplier.ts +14 -0
  236. package/core/fetcher/Fetcher.ts +398 -0
  237. package/core/fetcher/Headers.ts +93 -0
  238. package/core/fetcher/HttpResponsePromise.ts +116 -0
  239. package/core/fetcher/RawResponse.ts +61 -0
  240. package/core/fetcher/Supplier.ts +11 -0
  241. package/core/fetcher/createRequestUrl.ts +6 -0
  242. package/core/fetcher/getErrorResponseBody.ts +33 -0
  243. package/core/fetcher/getFetchFn.ts +3 -0
  244. package/core/fetcher/getHeader.ts +8 -0
  245. package/core/fetcher/getRequestBody.ts +20 -0
  246. package/core/fetcher/getResponseBody.ts +58 -0
  247. package/core/fetcher/index.ts +11 -0
  248. package/core/fetcher/makeRequest.ts +70 -0
  249. package/core/fetcher/requestWithRetries.ts +64 -0
  250. package/core/fetcher/signals.ts +26 -0
  251. package/core/headers.ts +33 -0
  252. package/core/index.ts +4 -0
  253. package/core/json.ts +27 -0
  254. package/core/logging/exports.ts +19 -0
  255. package/core/logging/index.ts +1 -0
  256. package/core/logging/logger.ts +203 -0
  257. package/core/runtime/index.ts +1 -0
  258. package/core/runtime/runtime.ts +134 -0
  259. package/core/url/encodePathParam.ts +18 -0
  260. package/core/url/index.ts +3 -0
  261. package/core/url/join.ts +79 -0
  262. package/core/url/qs.ts +74 -0
  263. package/errors/LevelFourError.ts +58 -0
  264. package/errors/LevelFourTimeoutError.ts +13 -0
  265. package/errors/handleNonStatusCodeError.ts +37 -0
  266. package/errors/index.ts +2 -0
  267. package/errors.ts +100 -0
  268. package/exports.ts +1 -0
  269. package/index.ts +22 -0
  270. package/jest.config.js +17 -0
  271. package/package.json +35 -0
  272. package/pagination.ts +54 -0
  273. package/telemetry.ts +64 -0
  274. package/tests/auth.test.ts +64 -0
  275. package/tests/errors.test.ts +92 -0
  276. package/tests/pagination.test.ts +72 -0
  277. package/tests/telemetry.test.ts +110 -0
  278. package/tsconfig.json +22 -0
  279. package/webhooks.ts +77 -0
package/webhooks.ts ADDED
@@ -0,0 +1,77 @@
1
+ import { createHmac, timingSafeEqual } from "node:crypto";
2
+
3
+ export class WebhookVerificationError extends Error {
4
+ constructor(message: string) {
5
+ super(message);
6
+ this.name = "WebhookVerificationError";
7
+ }
8
+ }
9
+
10
+ export class WebhookVerifier {
11
+ private readonly secret: Buffer;
12
+
13
+ constructor(secret: string) {
14
+ if (secret.startsWith("whsec_")) {
15
+ secret = secret.slice(6);
16
+ }
17
+ this.secret = Buffer.from(secret, "base64");
18
+ }
19
+
20
+ verify(
21
+ payload: string | Buffer,
22
+ headers: Record<string, string | undefined>,
23
+ options: { toleranceSeconds?: number } = {},
24
+ ): unknown {
25
+ const tolerance = options.toleranceSeconds ?? 300;
26
+
27
+ const msgId = headers["webhook-id"] ?? headers["svix-id"];
28
+ const msgTimestamp = headers["webhook-timestamp"] ?? headers["svix-timestamp"];
29
+ const msgSignature = headers["webhook-signature"] ?? headers["svix-signature"];
30
+
31
+ if (!msgId || !msgTimestamp || !msgSignature) {
32
+ throw new WebhookVerificationError("Missing required webhook headers");
33
+ }
34
+
35
+ const ts = parseInt(msgTimestamp, 10);
36
+ if (isNaN(ts)) {
37
+ throw new WebhookVerificationError("Invalid timestamp");
38
+ }
39
+
40
+ const now = Math.floor(Date.now() / 1000);
41
+ if (Math.abs(now - ts) > tolerance) {
42
+ throw new WebhookVerificationError("Timestamp too old or too new");
43
+ }
44
+
45
+ const payloadBytes = typeof payload === "string" ? Buffer.from(payload, "utf-8") : payload;
46
+ const toSign = Buffer.concat([
47
+ Buffer.from(`${msgId}.${msgTimestamp}.`),
48
+ payloadBytes,
49
+ ]);
50
+
51
+ const expected = createHmac("sha256", this.secret).update(toSign).digest("base64");
52
+
53
+ let passed = false;
54
+ for (const sig of msgSignature.split(" ")) {
55
+ const sigValue = sig.includes(",") ? sig.split(",")[1] : sig;
56
+ try {
57
+ if (
58
+ timingSafeEqual(
59
+ Buffer.from(expected),
60
+ Buffer.from(sigValue ?? ""),
61
+ )
62
+ ) {
63
+ passed = true;
64
+ break;
65
+ }
66
+ } catch {
67
+ continue;
68
+ }
69
+ }
70
+
71
+ if (!passed) {
72
+ throw new WebhookVerificationError("Invalid signature");
73
+ }
74
+
75
+ return JSON.parse(payloadBytes.toString("utf-8"));
76
+ }
77
+ }