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.
- package/.fernignore +9 -0
- package/BaseClient.ts +56 -0
- package/Client.ts +90 -0
- package/LevelFourClient.ts +50 -0
- package/api/errors/UnprocessableEntityError.ts +22 -0
- package/api/errors/index.ts +1 -0
- package/api/index.ts +3 -0
- package/api/resources/apiKeys/client/Client.ts +298 -0
- package/api/resources/apiKeys/client/index.ts +1 -0
- package/api/resources/apiKeys/client/requests/CreateApiKeyRequest.ts +23 -0
- package/api/resources/apiKeys/client/requests/ListApiKeysApiV1ApiKeysGetRequest.ts +11 -0
- package/api/resources/apiKeys/client/requests/RevokeApiKeyApiV1ApiKeysKeyIdDeleteRequest.ts +14 -0
- package/api/resources/apiKeys/client/requests/RotateApiKeyApiV1ApiKeysKeyIdRotatePostRequest.ts +14 -0
- package/api/resources/apiKeys/client/requests/index.ts +4 -0
- package/api/resources/apiKeys/exports.ts +4 -0
- package/api/resources/apiKeys/index.ts +1 -0
- package/api/resources/evaluation/client/Client.ts +71 -0
- package/api/resources/evaluation/client/index.ts +1 -0
- package/api/resources/evaluation/exports.ts +4 -0
- package/api/resources/evaluation/index.ts +1 -0
- package/api/resources/health/client/Client.ts +108 -0
- package/api/resources/health/client/index.ts +1 -0
- package/api/resources/health/exports.ts +4 -0
- package/api/resources/health/index.ts +1 -0
- package/api/resources/index.ts +24 -0
- package/api/resources/prAnalysis/client/Client.ts +100 -0
- package/api/resources/prAnalysis/client/index.ts +1 -0
- package/api/resources/prAnalysis/client/requests/AnalyzePrRequest.ts +30 -0
- package/api/resources/prAnalysis/client/requests/index.ts +1 -0
- package/api/resources/prAnalysis/exports.ts +4 -0
- package/api/resources/prAnalysis/index.ts +1 -0
- package/api/resources/prAnalysisActions/client/Client.ts +418 -0
- package/api/resources/prAnalysisActions/client/index.ts +1 -0
- package/api/resources/prAnalysisActions/client/requests/DismissSuggestionsApiV1PrAnalysisActionsDismissPostRequest.ts +21 -0
- package/api/resources/prAnalysisActions/client/requests/GetIgnoredResourcesApiV1PrAnalysisActionsIgnoreGetRequest.ts +15 -0
- package/api/resources/prAnalysisActions/client/requests/GetPrStatusApiV1PrAnalysisActionsStatusGetRequest.ts +15 -0
- package/api/resources/prAnalysisActions/client/requests/IgnoreRequest.ts +21 -0
- package/api/resources/prAnalysisActions/client/requests/SnoozeSuggestionsApiV1PrAnalysisActionsSnoozePostRequest.ts +21 -0
- package/api/resources/prAnalysisActions/client/requests/index.ts +5 -0
- package/api/resources/prAnalysisActions/exports.ts +4 -0
- package/api/resources/prAnalysisActions/index.ts +1 -0
- package/api/resources/prAnalysisInstallations/client/Client.ts +410 -0
- package/api/resources/prAnalysisInstallations/client/index.ts +1 -0
- package/api/resources/prAnalysisInstallations/client/requests/AddReposRequest.ts +17 -0
- package/api/resources/prAnalysisInstallations/client/requests/DeleteInstallationApiV1PrAnalysisInstallationsInstallationIdDeleteRequest.ts +15 -0
- package/api/resources/prAnalysisInstallations/client/requests/ListInstallationsApiV1PrAnalysisInstallationsGetRequest.ts +13 -0
- package/api/resources/prAnalysisInstallations/client/requests/RegisterInstallationRequest.ts +16 -0
- package/api/resources/prAnalysisInstallations/client/requests/RemoveReposRequest.ts +17 -0
- package/api/resources/prAnalysisInstallations/client/requests/index.ts +5 -0
- package/api/resources/prAnalysisInstallations/exports.ts +4 -0
- package/api/resources/prAnalysisInstallations/index.ts +1 -0
- package/api/resources/prAnalysisQuery/client/Client.ts +169 -0
- package/api/resources/prAnalysisQuery/client/index.ts +1 -0
- package/api/resources/prAnalysisQuery/client/requests/ExplainRequest.ts +17 -0
- package/api/resources/prAnalysisQuery/client/requests/WhatifRequest.ts +21 -0
- package/api/resources/prAnalysisQuery/client/requests/index.ts +2 -0
- package/api/resources/prAnalysisQuery/exports.ts +4 -0
- package/api/resources/prAnalysisQuery/index.ts +1 -0
- package/api/resources/providers/client/Client.ts +991 -0
- package/api/resources/providers/client/index.ts +1 -0
- package/api/resources/providers/client/requests/GetProviderFilterOptionsApiV1ProvidersProviderIdSpendingFilterOptionsGetRequest.ts +17 -0
- package/api/resources/providers/client/requests/GetProviderPotentialSavingsBreakdownApiV1ProvidersProviderIdPotentialSavingsBreakdownGetRequest.ts +19 -0
- package/api/resources/providers/client/requests/GetProviderPotentialSavingsSummaryApiV1ProvidersProviderIdPotentialSavingsSummaryGetRequest.ts +11 -0
- package/api/resources/providers/client/requests/GetProviderRecommendationFilterOptionsApiV1ProvidersProviderIdRecommendationsFilterOptionsGetRequest.ts +11 -0
- package/api/resources/providers/client/requests/GetProviderRecommendationsBreakdownApiV1ProvidersProviderIdRecommendationsGetRequest.ts +33 -0
- package/api/resources/providers/client/requests/GetProviderRecommendationsOverviewApiV1ProvidersProviderIdRecommendationsOverviewGetRequest.ts +11 -0
- package/api/resources/providers/client/requests/GetProviderRecommendationsSummaryApiV1ProvidersProviderIdRecommendationsSummaryGetRequest.ts +11 -0
- package/api/resources/providers/client/requests/GetProviderSavedSummaryApiV1ProvidersProviderIdSavingsSummaryGetRequest.ts +11 -0
- package/api/resources/providers/client/requests/GetProviderServiceBreakdownApiV1ProvidersProviderIdSpendingBreakdownGetRequest.ts +45 -0
- package/api/resources/providers/client/requests/GetProviderSpendingSummaryApiV1ProvidersProviderIdSpendingSummaryGetRequest.ts +11 -0
- package/api/resources/providers/client/requests/GetProviderSpendingTimelineApiV1ProvidersProviderIdSpendingTimelineGetRequest.ts +17 -0
- package/api/resources/providers/client/requests/GetSavedByProviderBreakdownApiV1ProvidersProviderIdSavingsBreakdownGetRequest.ts +31 -0
- package/api/resources/providers/client/requests/index.ts +12 -0
- package/api/resources/providers/exports.ts +4 -0
- package/api/resources/providers/index.ts +2 -0
- package/api/resources/providers/types/GetProviderServiceBreakdownApiV1ProvidersProviderIdSpendingBreakdownGetResponse.ts +8 -0
- package/api/resources/providers/types/index.ts +1 -0
- package/api/resources/recommendations/client/Client.ts +815 -0
- package/api/resources/recommendations/client/index.ts +1 -0
- package/api/resources/recommendations/client/requests/AcceptTermsApiV1RecommendationsRecommendationIdAcceptTermsPostRequest.ts +11 -0
- package/api/resources/recommendations/client/requests/CompleteWizardApiV1RecommendationsRecommendationIdCompletePostRequest.ts +11 -0
- package/api/resources/recommendations/client/requests/GetRecommendationDetailsApiV1RecommendationsRecommendationIdDetailsGetRequest.ts +11 -0
- package/api/resources/recommendations/client/requests/GetRecommendationForWizardApiV1RecommendationsRecommendationIdGetRequest.ts +11 -0
- package/api/resources/recommendations/client/requests/GetRecommendationsApiV1RecommendationsGetRequest.ts +16 -0
- package/api/resources/recommendations/client/requests/ImplementationMethodRequest.ts +14 -0
- package/api/resources/recommendations/client/requests/SavingsDecisionRequest.ts +18 -0
- package/api/resources/recommendations/client/requests/UpdateTagRequest.ts +13 -0
- package/api/resources/recommendations/client/requests/index.ts +8 -0
- package/api/resources/recommendations/exports.ts +4 -0
- package/api/resources/recommendations/index.ts +1 -0
- package/api/resources/savings/client/Client.ts +231 -0
- package/api/resources/savings/client/index.ts +1 -0
- package/api/resources/savings/client/requests/ExecutionRequestBody.ts +15 -0
- package/api/resources/savings/client/requests/GetSavedBreakdownApiV1SavingsBreakdownGetRequest.ts +30 -0
- package/api/resources/savings/client/requests/index.ts +2 -0
- package/api/resources/savings/exports.ts +4 -0
- package/api/resources/savings/index.ts +1 -0
- package/api/resources/spending/client/Client.ts +288 -0
- package/api/resources/spending/client/index.ts +1 -0
- package/api/resources/spending/client/requests/GetCostBreakdownApiV1SpendingBreakdownGetRequest.ts +30 -0
- package/api/resources/spending/client/requests/GetDailySpendingBreakdownApiV1SpendingDailyBreakdownGetRequest.ts +12 -0
- package/api/resources/spending/client/requests/index.ts +2 -0
- package/api/resources/spending/exports.ts +4 -0
- package/api/resources/spending/index.ts +2 -0
- package/api/resources/spending/types/GetCostBreakdownApiV1SpendingBreakdownGetResponse.ts +9 -0
- package/api/resources/spending/types/index.ts +1 -0
- package/api/resources/webhooks/client/Client.ts +232 -0
- package/api/resources/webhooks/client/index.ts +1 -0
- package/api/resources/webhooks/client/requests/DeleteEndpointApiV1WebhooksEndpointsEndpointIdDeleteRequest.ts +14 -0
- package/api/resources/webhooks/client/requests/ListEndpointsApiV1WebhooksEndpointsGetRequest.ts +11 -0
- package/api/resources/webhooks/client/requests/RegisterEndpointRequest.ts +18 -0
- package/api/resources/webhooks/client/requests/index.ts +3 -0
- package/api/resources/webhooks/exports.ts +4 -0
- package/api/resources/webhooks/index.ts +1 -0
- package/api/types/AcceptTermsData.ts +10 -0
- package/api/types/AcceptTermsResponse.ts +12 -0
- package/api/types/ActionRequest.ts +14 -0
- package/api/types/ApiKeyCreatedData.ts +13 -0
- package/api/types/ApiKeyData.ts +12 -0
- package/api/types/ComparisonItem.ts +10 -0
- package/api/types/CompleteWizardData.ts +12 -0
- package/api/types/CompleteWizardResponse.ts +12 -0
- package/api/types/CostBreakdownData.ts +14 -0
- package/api/types/CostBreakdownItem.ts +27 -0
- package/api/types/CostBreakdownRawData.ts +15 -0
- package/api/types/CostBreakdownRawResponse.ts +12 -0
- package/api/types/CostBreakdownResponse.ts +12 -0
- package/api/types/CostsBreakdownChartData.ts +19 -0
- package/api/types/CostsBreakdownChartResponse.ts +12 -0
- package/api/types/CostsBreakdownDataPoint.ts +17 -0
- package/api/types/CostsBreakdownGroupedChartData.ts +21 -0
- package/api/types/CostsBreakdownGroupedChartResponse.ts +12 -0
- package/api/types/CostsBreakdownGroupedDataPoint.ts +13 -0
- package/api/types/CostsBreakdownTotals.ts +15 -0
- package/api/types/CreateApiKeyResponse.ts +9 -0
- package/api/types/DailySpendingBreakdownData.ts +17 -0
- package/api/types/DailySpendingBreakdownResponse.ts +12 -0
- package/api/types/DailySpendingDataPoint.ts +11 -0
- package/api/types/DashboardSummaryData.ts +29 -0
- package/api/types/DashboardSummaryResponse.ts +12 -0
- package/api/types/DeleteEndpointData.ts +6 -0
- package/api/types/DeleteEndpointResponse.ts +9 -0
- package/api/types/EndpointData.ts +9 -0
- package/api/types/EvaluationStatusData.ts +27 -0
- package/api/types/EvaluationStatusResponse.ts +12 -0
- package/api/types/ExecutionLogCommand.ts +7 -0
- package/api/types/ExecutionLogEntry.ts +10 -0
- package/api/types/ExecutionStepSchema.ts +9 -0
- package/api/types/HttpValidationError.ts +7 -0
- package/api/types/ImplementationMethodData.ts +10 -0
- package/api/types/ImplementationMethodResponse.ts +12 -0
- package/api/types/ImplementationStep.ts +8 -0
- package/api/types/ListApiKeysData.ts +8 -0
- package/api/types/ListApiKeysResponse.ts +9 -0
- package/api/types/ListEndpointsResponse.ts +9 -0
- package/api/types/MetricDataPoint.ts +8 -0
- package/api/types/MetricSeries.ts +15 -0
- package/api/types/MetricSeriesEntry.ts +9 -0
- package/api/types/MonthlySpendingData.ts +11 -0
- package/api/types/MonthlySpendingDataPoint.ts +11 -0
- package/api/types/MonthlySpendingResponse.ts +12 -0
- package/api/types/PaginationMeta.ts +19 -0
- package/api/types/ProcessingRecommendationItem.ts +23 -0
- package/api/types/ProcessingRecommendationsData.ts +12 -0
- package/api/types/ProcessingRecommendationsResponse.ts +12 -0
- package/api/types/Provider.ts +17 -0
- package/api/types/ProviderBreakdownData.ts +13 -0
- package/api/types/ProviderBreakdownItem.ts +31 -0
- package/api/types/ProviderBreakdownResponse.ts +12 -0
- package/api/types/ProviderFilterOptionsData.ts +19 -0
- package/api/types/ProviderFilterOptionsResponse.ts +12 -0
- package/api/types/ProviderPotentialSavingsSummaryData.ts +17 -0
- package/api/types/ProviderPotentialSavingsSummaryResponse.ts +12 -0
- package/api/types/ProviderRecommendationsSummaryData.ts +15 -0
- package/api/types/ProviderRecommendationsSummaryResponse.ts +12 -0
- package/api/types/ProviderSavedSummaryData.ts +21 -0
- package/api/types/ProviderSavedSummaryResponse.ts +12 -0
- package/api/types/ProviderServiceBreakdownData.ts +26 -0
- package/api/types/ProviderServiceBreakdownItem.ts +29 -0
- package/api/types/ProviderServiceBreakdownRawData.ts +25 -0
- package/api/types/ProviderServiceBreakdownRawResponse.ts +12 -0
- package/api/types/ProviderServiceBreakdownResponse.ts +12 -0
- package/api/types/ProviderServiceCostsBreakdownData.ts +25 -0
- package/api/types/ProviderServiceCostsBreakdownResponse.ts +12 -0
- package/api/types/ProviderServiceCostsDataPoint.ts +13 -0
- package/api/types/ProviderSpending.ts +23 -0
- package/api/types/ProviderSpendingSummaryData.ts +27 -0
- package/api/types/ProviderSpendingSummaryResponse.ts +12 -0
- package/api/types/ProviderTimelineData.ts +23 -0
- package/api/types/ProviderTimelineResponse.ts +12 -0
- package/api/types/ProviderTopService.ts +13 -0
- package/api/types/ProvidersSummaryData.ts +10 -0
- package/api/types/ProvidersSummaryResponse.ts +12 -0
- package/api/types/RecommendationActions.ts +28 -0
- package/api/types/RecommendationDetail.ts +22 -0
- package/api/types/RecommendationDetailResponse.ts +12 -0
- package/api/types/RecommendationFilterOptionsData.ts +15 -0
- package/api/types/RecommendationFilterOptionsResponse.ts +12 -0
- package/api/types/RecommendationItem.ts +19 -0
- package/api/types/RecommendationWizardData.ts +83 -0
- package/api/types/RecommendationWizardResponse.ts +12 -0
- package/api/types/RecommendationsBreakdownData.ts +11 -0
- package/api/types/RecommendationsBreakdownResponse.ts +12 -0
- package/api/types/RecommendationsOverviewData.ts +19 -0
- package/api/types/RecommendationsOverviewResponse.ts +12 -0
- package/api/types/RegisterEndpointResponse.ts +9 -0
- package/api/types/ResourceChange.ts +14 -0
- package/api/types/ResourceSnapshot.ts +7 -0
- package/api/types/RevokeApiKeyData.ts +6 -0
- package/api/types/RevokeApiKeyResponse.ts +9 -0
- package/api/types/RiskAssessment.ts +11 -0
- package/api/types/RiskFactor.ts +8 -0
- package/api/types/SavedBreakdownData.ts +13 -0
- package/api/types/SavedBreakdownResponse.ts +12 -0
- package/api/types/SavedByProviderBreakdownData.ts +13 -0
- package/api/types/SavedByProviderBreakdownResponse.ts +12 -0
- package/api/types/SavedByProviderItem.ts +29 -0
- package/api/types/SavedItem.ts +20 -0
- package/api/types/SavedProviderSummary.ts +13 -0
- package/api/types/SavedSummaryData.ts +23 -0
- package/api/types/SavedSummaryResponse.ts +12 -0
- package/api/types/SavingsDecisionData.ts +13 -0
- package/api/types/SavingsDecisionResponse.ts +12 -0
- package/api/types/SpendingByDateItem.ts +13 -0
- package/api/types/TopRecommendation.ts +21 -0
- package/api/types/TriggerInfo.ts +8 -0
- package/api/types/UpdateTagData.ts +6 -0
- package/api/types/UpdateTagResponse.ts +9 -0
- package/api/types/ValidationError.ts +17 -0
- package/api/types/index.ts +115 -0
- package/core/exports.ts +1 -0
- package/core/fetcher/APIResponse.ts +23 -0
- package/core/fetcher/BinaryResponse.ts +34 -0
- package/core/fetcher/EndpointMetadata.ts +13 -0
- package/core/fetcher/EndpointSupplier.ts +14 -0
- package/core/fetcher/Fetcher.ts +398 -0
- package/core/fetcher/Headers.ts +93 -0
- package/core/fetcher/HttpResponsePromise.ts +116 -0
- package/core/fetcher/RawResponse.ts +61 -0
- package/core/fetcher/Supplier.ts +11 -0
- package/core/fetcher/createRequestUrl.ts +6 -0
- package/core/fetcher/getErrorResponseBody.ts +33 -0
- package/core/fetcher/getFetchFn.ts +3 -0
- package/core/fetcher/getHeader.ts +8 -0
- package/core/fetcher/getRequestBody.ts +20 -0
- package/core/fetcher/getResponseBody.ts +58 -0
- package/core/fetcher/index.ts +11 -0
- package/core/fetcher/makeRequest.ts +70 -0
- package/core/fetcher/requestWithRetries.ts +64 -0
- package/core/fetcher/signals.ts +26 -0
- package/core/headers.ts +33 -0
- package/core/index.ts +4 -0
- package/core/json.ts +27 -0
- package/core/logging/exports.ts +19 -0
- package/core/logging/index.ts +1 -0
- package/core/logging/logger.ts +203 -0
- package/core/runtime/index.ts +1 -0
- package/core/runtime/runtime.ts +134 -0
- package/core/url/encodePathParam.ts +18 -0
- package/core/url/index.ts +3 -0
- package/core/url/join.ts +79 -0
- package/core/url/qs.ts +74 -0
- package/errors/LevelFourError.ts +58 -0
- package/errors/LevelFourTimeoutError.ts +13 -0
- package/errors/handleNonStatusCodeError.ts +37 -0
- package/errors/index.ts +2 -0
- package/errors.ts +100 -0
- package/exports.ts +1 -0
- package/index.ts +22 -0
- package/jest.config.js +17 -0
- package/package.json +35 -0
- package/pagination.ts +54 -0
- package/telemetry.ts +64 -0
- package/tests/auth.test.ts +64 -0
- package/tests/errors.test.ts +92 -0
- package/tests/pagination.test.ts +72 -0
- package/tests/telemetry.test.ts +110 -0
- package/tsconfig.json +22 -0
- package/webhooks.ts +77 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
export * from "./AcceptTermsData.js";
|
|
2
|
+
export * from "./AcceptTermsResponse.js";
|
|
3
|
+
export * from "./ActionRequest.js";
|
|
4
|
+
export * from "./ApiKeyCreatedData.js";
|
|
5
|
+
export * from "./ApiKeyData.js";
|
|
6
|
+
export * from "./ComparisonItem.js";
|
|
7
|
+
export * from "./CompleteWizardData.js";
|
|
8
|
+
export * from "./CompleteWizardResponse.js";
|
|
9
|
+
export * from "./CostBreakdownData.js";
|
|
10
|
+
export * from "./CostBreakdownItem.js";
|
|
11
|
+
export * from "./CostBreakdownRawData.js";
|
|
12
|
+
export * from "./CostBreakdownRawResponse.js";
|
|
13
|
+
export * from "./CostBreakdownResponse.js";
|
|
14
|
+
export * from "./CostsBreakdownChartData.js";
|
|
15
|
+
export * from "./CostsBreakdownChartResponse.js";
|
|
16
|
+
export * from "./CostsBreakdownDataPoint.js";
|
|
17
|
+
export * from "./CostsBreakdownGroupedChartData.js";
|
|
18
|
+
export * from "./CostsBreakdownGroupedChartResponse.js";
|
|
19
|
+
export * from "./CostsBreakdownGroupedDataPoint.js";
|
|
20
|
+
export * from "./CostsBreakdownTotals.js";
|
|
21
|
+
export * from "./CreateApiKeyResponse.js";
|
|
22
|
+
export * from "./DailySpendingBreakdownData.js";
|
|
23
|
+
export * from "./DailySpendingBreakdownResponse.js";
|
|
24
|
+
export * from "./DailySpendingDataPoint.js";
|
|
25
|
+
export * from "./DashboardSummaryData.js";
|
|
26
|
+
export * from "./DashboardSummaryResponse.js";
|
|
27
|
+
export * from "./DeleteEndpointData.js";
|
|
28
|
+
export * from "./DeleteEndpointResponse.js";
|
|
29
|
+
export * from "./EndpointData.js";
|
|
30
|
+
export * from "./EvaluationStatusData.js";
|
|
31
|
+
export * from "./EvaluationStatusResponse.js";
|
|
32
|
+
export * from "./ExecutionLogCommand.js";
|
|
33
|
+
export * from "./ExecutionLogEntry.js";
|
|
34
|
+
export * from "./ExecutionStepSchema.js";
|
|
35
|
+
export * from "./HttpValidationError.js";
|
|
36
|
+
export * from "./ImplementationMethodData.js";
|
|
37
|
+
export * from "./ImplementationMethodResponse.js";
|
|
38
|
+
export * from "./ImplementationStep.js";
|
|
39
|
+
export * from "./ListApiKeysData.js";
|
|
40
|
+
export * from "./ListApiKeysResponse.js";
|
|
41
|
+
export * from "./ListEndpointsResponse.js";
|
|
42
|
+
export * from "./MetricDataPoint.js";
|
|
43
|
+
export * from "./MetricSeries.js";
|
|
44
|
+
export * from "./MetricSeriesEntry.js";
|
|
45
|
+
export * from "./MonthlySpendingData.js";
|
|
46
|
+
export * from "./MonthlySpendingDataPoint.js";
|
|
47
|
+
export * from "./MonthlySpendingResponse.js";
|
|
48
|
+
export * from "./PaginationMeta.js";
|
|
49
|
+
export * from "./ProcessingRecommendationItem.js";
|
|
50
|
+
export * from "./ProcessingRecommendationsData.js";
|
|
51
|
+
export * from "./ProcessingRecommendationsResponse.js";
|
|
52
|
+
export * from "./Provider.js";
|
|
53
|
+
export * from "./ProviderBreakdownData.js";
|
|
54
|
+
export * from "./ProviderBreakdownItem.js";
|
|
55
|
+
export * from "./ProviderBreakdownResponse.js";
|
|
56
|
+
export * from "./ProviderFilterOptionsData.js";
|
|
57
|
+
export * from "./ProviderFilterOptionsResponse.js";
|
|
58
|
+
export * from "./ProviderPotentialSavingsSummaryData.js";
|
|
59
|
+
export * from "./ProviderPotentialSavingsSummaryResponse.js";
|
|
60
|
+
export * from "./ProviderRecommendationsSummaryData.js";
|
|
61
|
+
export * from "./ProviderRecommendationsSummaryResponse.js";
|
|
62
|
+
export * from "./ProviderSavedSummaryData.js";
|
|
63
|
+
export * from "./ProviderSavedSummaryResponse.js";
|
|
64
|
+
export * from "./ProviderServiceBreakdownData.js";
|
|
65
|
+
export * from "./ProviderServiceBreakdownItem.js";
|
|
66
|
+
export * from "./ProviderServiceBreakdownRawData.js";
|
|
67
|
+
export * from "./ProviderServiceBreakdownRawResponse.js";
|
|
68
|
+
export * from "./ProviderServiceBreakdownResponse.js";
|
|
69
|
+
export * from "./ProviderServiceCostsBreakdownData.js";
|
|
70
|
+
export * from "./ProviderServiceCostsBreakdownResponse.js";
|
|
71
|
+
export * from "./ProviderServiceCostsDataPoint.js";
|
|
72
|
+
export * from "./ProviderSpending.js";
|
|
73
|
+
export * from "./ProviderSpendingSummaryData.js";
|
|
74
|
+
export * from "./ProviderSpendingSummaryResponse.js";
|
|
75
|
+
export * from "./ProvidersSummaryData.js";
|
|
76
|
+
export * from "./ProvidersSummaryResponse.js";
|
|
77
|
+
export * from "./ProviderTimelineData.js";
|
|
78
|
+
export * from "./ProviderTimelineResponse.js";
|
|
79
|
+
export * from "./ProviderTopService.js";
|
|
80
|
+
export * from "./RecommendationActions.js";
|
|
81
|
+
export * from "./RecommendationDetail.js";
|
|
82
|
+
export * from "./RecommendationDetailResponse.js";
|
|
83
|
+
export * from "./RecommendationFilterOptionsData.js";
|
|
84
|
+
export * from "./RecommendationFilterOptionsResponse.js";
|
|
85
|
+
export * from "./RecommendationItem.js";
|
|
86
|
+
export * from "./RecommendationsBreakdownData.js";
|
|
87
|
+
export * from "./RecommendationsBreakdownResponse.js";
|
|
88
|
+
export * from "./RecommendationsOverviewData.js";
|
|
89
|
+
export * from "./RecommendationsOverviewResponse.js";
|
|
90
|
+
export * from "./RecommendationWizardData.js";
|
|
91
|
+
export * from "./RecommendationWizardResponse.js";
|
|
92
|
+
export * from "./RegisterEndpointResponse.js";
|
|
93
|
+
export * from "./ResourceChange.js";
|
|
94
|
+
export * from "./ResourceSnapshot.js";
|
|
95
|
+
export * from "./RevokeApiKeyData.js";
|
|
96
|
+
export * from "./RevokeApiKeyResponse.js";
|
|
97
|
+
export * from "./RiskAssessment.js";
|
|
98
|
+
export * from "./RiskFactor.js";
|
|
99
|
+
export * from "./SavedBreakdownData.js";
|
|
100
|
+
export * from "./SavedBreakdownResponse.js";
|
|
101
|
+
export * from "./SavedByProviderBreakdownData.js";
|
|
102
|
+
export * from "./SavedByProviderBreakdownResponse.js";
|
|
103
|
+
export * from "./SavedByProviderItem.js";
|
|
104
|
+
export * from "./SavedItem.js";
|
|
105
|
+
export * from "./SavedProviderSummary.js";
|
|
106
|
+
export * from "./SavedSummaryData.js";
|
|
107
|
+
export * from "./SavedSummaryResponse.js";
|
|
108
|
+
export * from "./SavingsDecisionData.js";
|
|
109
|
+
export * from "./SavingsDecisionResponse.js";
|
|
110
|
+
export * from "./SpendingByDateItem.js";
|
|
111
|
+
export * from "./TopRecommendation.js";
|
|
112
|
+
export * from "./TriggerInfo.js";
|
|
113
|
+
export * from "./UpdateTagData.js";
|
|
114
|
+
export * from "./UpdateTagResponse.js";
|
|
115
|
+
export * from "./ValidationError.js";
|
package/core/exports.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./logging/exports.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { RawResponse } from "./RawResponse.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The response of an API call.
|
|
5
|
+
* It is a successful response or a failed response.
|
|
6
|
+
*/
|
|
7
|
+
export type APIResponse<Success, Failure> = SuccessfulResponse<Success> | FailedResponse<Failure>;
|
|
8
|
+
|
|
9
|
+
export interface SuccessfulResponse<T> {
|
|
10
|
+
ok: true;
|
|
11
|
+
body: T;
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use `rawResponse` instead
|
|
14
|
+
*/
|
|
15
|
+
headers?: Record<string, any>;
|
|
16
|
+
rawResponse: RawResponse;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface FailedResponse<T> {
|
|
20
|
+
ok: false;
|
|
21
|
+
error: T;
|
|
22
|
+
rawResponse: RawResponse;
|
|
23
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type BinaryResponse = {
|
|
2
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bodyUsed) */
|
|
3
|
+
bodyUsed: Response["bodyUsed"];
|
|
4
|
+
/**
|
|
5
|
+
* Returns a ReadableStream of the response body.
|
|
6
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/body)
|
|
7
|
+
*/
|
|
8
|
+
stream: () => Response["body"];
|
|
9
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/arrayBuffer) */
|
|
10
|
+
arrayBuffer: () => ReturnType<Response["arrayBuffer"]>;
|
|
11
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/blob) */
|
|
12
|
+
blob: () => ReturnType<Response["blob"]>;
|
|
13
|
+
/**
|
|
14
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bytes)
|
|
15
|
+
* Some versions of the Fetch API may not support this method.
|
|
16
|
+
*/
|
|
17
|
+
bytes?(): ReturnType<Response["bytes"]>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export function getBinaryResponse(response: Response): BinaryResponse {
|
|
21
|
+
const binaryResponse: BinaryResponse = {
|
|
22
|
+
get bodyUsed() {
|
|
23
|
+
return response.bodyUsed;
|
|
24
|
+
},
|
|
25
|
+
stream: () => response.body,
|
|
26
|
+
arrayBuffer: response.arrayBuffer.bind(response),
|
|
27
|
+
blob: response.blob.bind(response),
|
|
28
|
+
};
|
|
29
|
+
if ("bytes" in response && typeof response.bytes === "function") {
|
|
30
|
+
binaryResponse.bytes = response.bytes.bind(response);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return binaryResponse;
|
|
34
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type SecuritySchemeKey = string;
|
|
2
|
+
/**
|
|
3
|
+
* A collection of security schemes, where the key is the name of the security scheme and the value is the list of scopes required for that scheme.
|
|
4
|
+
* All schemes in the collection must be satisfied for authentication to be successful.
|
|
5
|
+
*/
|
|
6
|
+
export type SecuritySchemeCollection = Record<SecuritySchemeKey, AuthScope[]>;
|
|
7
|
+
export type AuthScope = string;
|
|
8
|
+
export type EndpointMetadata = {
|
|
9
|
+
/**
|
|
10
|
+
* An array of security scheme collections. Each collection represents an alternative way to authenticate.
|
|
11
|
+
*/
|
|
12
|
+
security?: SecuritySchemeCollection[];
|
|
13
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { EndpointMetadata } from "./EndpointMetadata.js";
|
|
2
|
+
import type { Supplier } from "./Supplier.js";
|
|
3
|
+
|
|
4
|
+
type EndpointSupplierFn<T> = (arg: { endpointMetadata?: EndpointMetadata }) => T | Promise<T>;
|
|
5
|
+
export type EndpointSupplier<T> = Supplier<T> | EndpointSupplierFn<T>;
|
|
6
|
+
export const EndpointSupplier = {
|
|
7
|
+
get: async <T>(supplier: EndpointSupplier<T>, arg: { endpointMetadata?: EndpointMetadata }): Promise<T> => {
|
|
8
|
+
if (typeof supplier === "function") {
|
|
9
|
+
return (supplier as EndpointSupplierFn<T>)(arg);
|
|
10
|
+
} else {
|
|
11
|
+
return supplier;
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
};
|
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import { toJson } from "../json.js";
|
|
2
|
+
import { createLogger, type LogConfig, type Logger } from "../logging/logger.js";
|
|
3
|
+
import type { APIResponse } from "./APIResponse.js";
|
|
4
|
+
import { createRequestUrl } from "./createRequestUrl.js";
|
|
5
|
+
import type { EndpointMetadata } from "./EndpointMetadata.js";
|
|
6
|
+
import { EndpointSupplier } from "./EndpointSupplier.js";
|
|
7
|
+
import { getErrorResponseBody } from "./getErrorResponseBody.js";
|
|
8
|
+
import { getFetchFn } from "./getFetchFn.js";
|
|
9
|
+
import { getRequestBody } from "./getRequestBody.js";
|
|
10
|
+
import { getResponseBody } from "./getResponseBody.js";
|
|
11
|
+
import { Headers } from "./Headers.js";
|
|
12
|
+
import { makeRequest } from "./makeRequest.js";
|
|
13
|
+
import { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse.js";
|
|
14
|
+
import { requestWithRetries } from "./requestWithRetries.js";
|
|
15
|
+
|
|
16
|
+
export type FetchFunction = <R = unknown>(args: Fetcher.Args) => Promise<APIResponse<R, Fetcher.Error>>;
|
|
17
|
+
|
|
18
|
+
export declare namespace Fetcher {
|
|
19
|
+
export interface Args {
|
|
20
|
+
url: string;
|
|
21
|
+
method: string;
|
|
22
|
+
contentType?: string;
|
|
23
|
+
headers?: Record<string, unknown>;
|
|
24
|
+
queryParameters?: Record<string, unknown>;
|
|
25
|
+
body?: unknown;
|
|
26
|
+
timeoutMs?: number;
|
|
27
|
+
maxRetries?: number;
|
|
28
|
+
withCredentials?: boolean;
|
|
29
|
+
abortSignal?: AbortSignal;
|
|
30
|
+
requestType?: "json" | "file" | "bytes" | "form" | "other";
|
|
31
|
+
responseType?: "json" | "blob" | "sse" | "streaming" | "text" | "arrayBuffer" | "binary-response";
|
|
32
|
+
duplex?: "half";
|
|
33
|
+
endpointMetadata?: EndpointMetadata;
|
|
34
|
+
fetchFn?: typeof fetch;
|
|
35
|
+
logging?: LogConfig | Logger;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type Error = FailedStatusCodeError | NonJsonError | BodyIsNullError | TimeoutError | UnknownError;
|
|
39
|
+
|
|
40
|
+
export interface FailedStatusCodeError {
|
|
41
|
+
reason: "status-code";
|
|
42
|
+
statusCode: number;
|
|
43
|
+
body: unknown;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface NonJsonError {
|
|
47
|
+
reason: "non-json";
|
|
48
|
+
statusCode: number;
|
|
49
|
+
rawBody: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface BodyIsNullError {
|
|
53
|
+
reason: "body-is-null";
|
|
54
|
+
statusCode: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface TimeoutError {
|
|
58
|
+
reason: "timeout";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface UnknownError {
|
|
62
|
+
reason: "unknown";
|
|
63
|
+
errorMessage: string;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const SENSITIVE_HEADERS = new Set([
|
|
68
|
+
"authorization",
|
|
69
|
+
"www-authenticate",
|
|
70
|
+
"x-api-key",
|
|
71
|
+
"api-key",
|
|
72
|
+
"apikey",
|
|
73
|
+
"x-api-token",
|
|
74
|
+
"x-auth-token",
|
|
75
|
+
"auth-token",
|
|
76
|
+
"cookie",
|
|
77
|
+
"set-cookie",
|
|
78
|
+
"proxy-authorization",
|
|
79
|
+
"proxy-authenticate",
|
|
80
|
+
"x-csrf-token",
|
|
81
|
+
"x-xsrf-token",
|
|
82
|
+
"x-session-token",
|
|
83
|
+
"x-access-token",
|
|
84
|
+
]);
|
|
85
|
+
|
|
86
|
+
function redactHeaders(headers: Headers | Record<string, string>): Record<string, string> {
|
|
87
|
+
const filtered: Record<string, string> = {};
|
|
88
|
+
for (const [key, value] of headers instanceof Headers ? headers.entries() : Object.entries(headers)) {
|
|
89
|
+
if (SENSITIVE_HEADERS.has(key.toLowerCase())) {
|
|
90
|
+
filtered[key] = "[REDACTED]";
|
|
91
|
+
} else {
|
|
92
|
+
filtered[key] = value;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return filtered;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const SENSITIVE_QUERY_PARAMS = new Set([
|
|
99
|
+
"api_key",
|
|
100
|
+
"api-key",
|
|
101
|
+
"apikey",
|
|
102
|
+
"token",
|
|
103
|
+
"access_token",
|
|
104
|
+
"access-token",
|
|
105
|
+
"auth_token",
|
|
106
|
+
"auth-token",
|
|
107
|
+
"password",
|
|
108
|
+
"passwd",
|
|
109
|
+
"secret",
|
|
110
|
+
"api_secret",
|
|
111
|
+
"api-secret",
|
|
112
|
+
"apisecret",
|
|
113
|
+
"key",
|
|
114
|
+
"session",
|
|
115
|
+
"session_id",
|
|
116
|
+
"session-id",
|
|
117
|
+
]);
|
|
118
|
+
|
|
119
|
+
function redactQueryParameters(queryParameters?: Record<string, unknown>): Record<string, unknown> | undefined {
|
|
120
|
+
if (queryParameters == null) {
|
|
121
|
+
return queryParameters;
|
|
122
|
+
}
|
|
123
|
+
const redacted: Record<string, unknown> = {};
|
|
124
|
+
for (const [key, value] of Object.entries(queryParameters)) {
|
|
125
|
+
if (SENSITIVE_QUERY_PARAMS.has(key.toLowerCase())) {
|
|
126
|
+
redacted[key] = "[REDACTED]";
|
|
127
|
+
} else {
|
|
128
|
+
redacted[key] = value;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return redacted;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function redactUrl(url: string): string {
|
|
135
|
+
const protocolIndex = url.indexOf("://");
|
|
136
|
+
if (protocolIndex === -1) return url;
|
|
137
|
+
|
|
138
|
+
const afterProtocol = protocolIndex + 3;
|
|
139
|
+
|
|
140
|
+
// Find the first delimiter that marks the end of the authority section
|
|
141
|
+
const pathStart = url.indexOf("/", afterProtocol);
|
|
142
|
+
let queryStart = url.indexOf("?", afterProtocol);
|
|
143
|
+
let fragmentStart = url.indexOf("#", afterProtocol);
|
|
144
|
+
|
|
145
|
+
const firstDelimiter = Math.min(
|
|
146
|
+
pathStart === -1 ? url.length : pathStart,
|
|
147
|
+
queryStart === -1 ? url.length : queryStart,
|
|
148
|
+
fragmentStart === -1 ? url.length : fragmentStart,
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
// Find the LAST @ before the delimiter (handles multiple @ in credentials)
|
|
152
|
+
let atIndex = -1;
|
|
153
|
+
for (let i = afterProtocol; i < firstDelimiter; i++) {
|
|
154
|
+
if (url[i] === "@") {
|
|
155
|
+
atIndex = i;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (atIndex !== -1) {
|
|
160
|
+
url = `${url.slice(0, afterProtocol)}[REDACTED]@${url.slice(atIndex + 1)}`;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Recalculate queryStart since url might have changed
|
|
164
|
+
queryStart = url.indexOf("?");
|
|
165
|
+
if (queryStart === -1) return url;
|
|
166
|
+
|
|
167
|
+
fragmentStart = url.indexOf("#", queryStart);
|
|
168
|
+
const queryEnd = fragmentStart !== -1 ? fragmentStart : url.length;
|
|
169
|
+
const queryString = url.slice(queryStart + 1, queryEnd);
|
|
170
|
+
|
|
171
|
+
if (queryString.length === 0) return url;
|
|
172
|
+
|
|
173
|
+
// FAST PATH: Quick check if any sensitive keywords present
|
|
174
|
+
// Using indexOf is faster than regex for simple substring matching
|
|
175
|
+
const lower = queryString.toLowerCase();
|
|
176
|
+
const hasSensitive =
|
|
177
|
+
lower.includes("token") ||
|
|
178
|
+
lower.includes("key") ||
|
|
179
|
+
lower.includes("password") ||
|
|
180
|
+
lower.includes("passwd") ||
|
|
181
|
+
lower.includes("secret") ||
|
|
182
|
+
lower.includes("session") ||
|
|
183
|
+
lower.includes("auth");
|
|
184
|
+
|
|
185
|
+
if (!hasSensitive) {
|
|
186
|
+
return url;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// SLOW PATH: Parse and redact
|
|
190
|
+
const redactedParams: string[] = [];
|
|
191
|
+
const params = queryString.split("&");
|
|
192
|
+
|
|
193
|
+
for (const param of params) {
|
|
194
|
+
const equalIndex = param.indexOf("=");
|
|
195
|
+
if (equalIndex === -1) {
|
|
196
|
+
redactedParams.push(param);
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const key = param.slice(0, equalIndex);
|
|
201
|
+
let shouldRedact = SENSITIVE_QUERY_PARAMS.has(key.toLowerCase());
|
|
202
|
+
|
|
203
|
+
if (!shouldRedact && key.includes("%")) {
|
|
204
|
+
try {
|
|
205
|
+
const decodedKey = decodeURIComponent(key);
|
|
206
|
+
shouldRedact = SENSITIVE_QUERY_PARAMS.has(decodedKey.toLowerCase());
|
|
207
|
+
} catch {}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
redactedParams.push(shouldRedact ? `${key}=[REDACTED]` : param);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return url.slice(0, queryStart + 1) + redactedParams.join("&") + url.slice(queryEnd);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
async function getHeaders(args: Fetcher.Args): Promise<Headers> {
|
|
217
|
+
const newHeaders: Headers = new Headers();
|
|
218
|
+
|
|
219
|
+
newHeaders.set(
|
|
220
|
+
"Accept",
|
|
221
|
+
args.responseType === "json"
|
|
222
|
+
? "application/json"
|
|
223
|
+
: args.responseType === "text"
|
|
224
|
+
? "text/plain"
|
|
225
|
+
: args.responseType === "sse"
|
|
226
|
+
? "text/event-stream"
|
|
227
|
+
: "*/*",
|
|
228
|
+
);
|
|
229
|
+
if (args.body !== undefined && args.contentType != null) {
|
|
230
|
+
newHeaders.set("Content-Type", args.contentType);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (args.headers == null) {
|
|
234
|
+
return newHeaders;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
for (const [key, value] of Object.entries(args.headers)) {
|
|
238
|
+
const result = await EndpointSupplier.get(value, { endpointMetadata: args.endpointMetadata ?? {} });
|
|
239
|
+
if (typeof result === "string") {
|
|
240
|
+
newHeaders.set(key, result);
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
if (result == null) {
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
newHeaders.set(key, `${result}`);
|
|
247
|
+
}
|
|
248
|
+
return newHeaders;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export async function fetcherImpl<R = unknown>(args: Fetcher.Args): Promise<APIResponse<R, Fetcher.Error>> {
|
|
252
|
+
const url = createRequestUrl(args.url, args.queryParameters);
|
|
253
|
+
const requestBody: BodyInit | undefined = await getRequestBody({
|
|
254
|
+
body: args.body,
|
|
255
|
+
type: args.requestType ?? "other",
|
|
256
|
+
});
|
|
257
|
+
const fetchFn = args.fetchFn ?? (await getFetchFn());
|
|
258
|
+
const headers = await getHeaders(args);
|
|
259
|
+
const logger = createLogger(args.logging);
|
|
260
|
+
|
|
261
|
+
if (logger.isDebug()) {
|
|
262
|
+
const metadata = {
|
|
263
|
+
method: args.method,
|
|
264
|
+
url: redactUrl(url),
|
|
265
|
+
headers: redactHeaders(headers),
|
|
266
|
+
queryParameters: redactQueryParameters(args.queryParameters),
|
|
267
|
+
hasBody: requestBody != null,
|
|
268
|
+
};
|
|
269
|
+
logger.debug("Making HTTP request", metadata);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
try {
|
|
273
|
+
const response = await requestWithRetries(
|
|
274
|
+
async () =>
|
|
275
|
+
makeRequest(
|
|
276
|
+
fetchFn,
|
|
277
|
+
url,
|
|
278
|
+
args.method,
|
|
279
|
+
headers,
|
|
280
|
+
requestBody,
|
|
281
|
+
args.timeoutMs,
|
|
282
|
+
args.abortSignal,
|
|
283
|
+
args.withCredentials,
|
|
284
|
+
args.duplex,
|
|
285
|
+
args.responseType === "streaming" || args.responseType === "sse",
|
|
286
|
+
),
|
|
287
|
+
args.maxRetries,
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
if (response.status >= 200 && response.status < 400) {
|
|
291
|
+
if (logger.isDebug()) {
|
|
292
|
+
const metadata = {
|
|
293
|
+
method: args.method,
|
|
294
|
+
url: redactUrl(url),
|
|
295
|
+
statusCode: response.status,
|
|
296
|
+
responseHeaders: redactHeaders(response.headers),
|
|
297
|
+
};
|
|
298
|
+
logger.debug("HTTP request succeeded", metadata);
|
|
299
|
+
}
|
|
300
|
+
const body = await getResponseBody(response, args.responseType);
|
|
301
|
+
return {
|
|
302
|
+
ok: true,
|
|
303
|
+
body: body as R,
|
|
304
|
+
headers: response.headers,
|
|
305
|
+
rawResponse: toRawResponse(response),
|
|
306
|
+
};
|
|
307
|
+
} else {
|
|
308
|
+
if (logger.isError()) {
|
|
309
|
+
const metadata = {
|
|
310
|
+
method: args.method,
|
|
311
|
+
url: redactUrl(url),
|
|
312
|
+
statusCode: response.status,
|
|
313
|
+
responseHeaders: redactHeaders(Object.fromEntries(response.headers.entries())),
|
|
314
|
+
};
|
|
315
|
+
logger.error("HTTP request failed with error status", metadata);
|
|
316
|
+
}
|
|
317
|
+
return {
|
|
318
|
+
ok: false,
|
|
319
|
+
error: {
|
|
320
|
+
reason: "status-code",
|
|
321
|
+
statusCode: response.status,
|
|
322
|
+
body: await getErrorResponseBody(response),
|
|
323
|
+
},
|
|
324
|
+
rawResponse: toRawResponse(response),
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
} catch (error) {
|
|
328
|
+
if (args.abortSignal?.aborted) {
|
|
329
|
+
if (logger.isError()) {
|
|
330
|
+
const metadata = {
|
|
331
|
+
method: args.method,
|
|
332
|
+
url: redactUrl(url),
|
|
333
|
+
};
|
|
334
|
+
logger.error("HTTP request was aborted", metadata);
|
|
335
|
+
}
|
|
336
|
+
return {
|
|
337
|
+
ok: false,
|
|
338
|
+
error: {
|
|
339
|
+
reason: "unknown",
|
|
340
|
+
errorMessage: "The user aborted a request",
|
|
341
|
+
},
|
|
342
|
+
rawResponse: abortRawResponse,
|
|
343
|
+
};
|
|
344
|
+
} else if (error instanceof Error && error.name === "AbortError") {
|
|
345
|
+
if (logger.isError()) {
|
|
346
|
+
const metadata = {
|
|
347
|
+
method: args.method,
|
|
348
|
+
url: redactUrl(url),
|
|
349
|
+
timeoutMs: args.timeoutMs,
|
|
350
|
+
};
|
|
351
|
+
logger.error("HTTP request timed out", metadata);
|
|
352
|
+
}
|
|
353
|
+
return {
|
|
354
|
+
ok: false,
|
|
355
|
+
error: {
|
|
356
|
+
reason: "timeout",
|
|
357
|
+
},
|
|
358
|
+
rawResponse: abortRawResponse,
|
|
359
|
+
};
|
|
360
|
+
} else if (error instanceof Error) {
|
|
361
|
+
if (logger.isError()) {
|
|
362
|
+
const metadata = {
|
|
363
|
+
method: args.method,
|
|
364
|
+
url: redactUrl(url),
|
|
365
|
+
errorMessage: error.message,
|
|
366
|
+
};
|
|
367
|
+
logger.error("HTTP request failed with error", metadata);
|
|
368
|
+
}
|
|
369
|
+
return {
|
|
370
|
+
ok: false,
|
|
371
|
+
error: {
|
|
372
|
+
reason: "unknown",
|
|
373
|
+
errorMessage: error.message,
|
|
374
|
+
},
|
|
375
|
+
rawResponse: unknownRawResponse,
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (logger.isError()) {
|
|
380
|
+
const metadata = {
|
|
381
|
+
method: args.method,
|
|
382
|
+
url: redactUrl(url),
|
|
383
|
+
error: toJson(error),
|
|
384
|
+
};
|
|
385
|
+
logger.error("HTTP request failed with unknown error", metadata);
|
|
386
|
+
}
|
|
387
|
+
return {
|
|
388
|
+
ok: false,
|
|
389
|
+
error: {
|
|
390
|
+
reason: "unknown",
|
|
391
|
+
errorMessage: toJson(error),
|
|
392
|
+
},
|
|
393
|
+
rawResponse: unknownRawResponse,
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export const fetcher: FetchFunction = fetcherImpl;
|