pulse-ts-sdk 0.0.51 → 0.0.53
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/dist/cjs/BaseClient.d.ts +39 -0
- package/dist/cjs/BaseClient.js +62 -0
- package/dist/cjs/Client.d.ts +57 -0
- package/dist/cjs/Client.js +189 -0
- package/dist/cjs/api/errors/BadRequestError.d.ts +5 -0
- package/dist/cjs/api/errors/BadRequestError.js +54 -0
- package/dist/cjs/api/errors/ForbiddenError.d.ts +5 -0
- package/dist/cjs/api/errors/ForbiddenError.js +54 -0
- package/dist/cjs/api/errors/InternalServerError.d.ts +5 -0
- package/dist/cjs/api/errors/InternalServerError.js +54 -0
- package/dist/cjs/api/errors/NotFoundError.d.ts +5 -0
- package/dist/cjs/api/errors/NotFoundError.js +54 -0
- package/dist/cjs/api/errors/TooManyRequestsError.d.ts +5 -0
- package/dist/cjs/api/errors/TooManyRequestsError.js +54 -0
- package/dist/cjs/api/errors/UnauthorizedError.d.ts +5 -0
- package/dist/cjs/api/errors/UnauthorizedError.js +54 -0
- package/dist/cjs/api/errors/index.d.ts +6 -0
- package/dist/cjs/api/errors/index.js +22 -0
- package/dist/cjs/api/index.d.ts +3 -0
- package/dist/cjs/api/index.js +19 -0
- package/dist/cjs/api/resources/index.d.ts +4 -0
- package/dist/cjs/api/resources/index.js +43 -0
- package/dist/cjs/api/resources/jobs/client/Client.d.ts +53 -0
- package/dist/cjs/api/resources/jobs/client/Client.js +185 -0
- package/dist/cjs/api/resources/jobs/client/index.d.ts +1 -0
- package/dist/cjs/api/resources/jobs/client/index.js +17 -0
- package/dist/cjs/api/resources/jobs/client/requests/CancelJobRequest.d.ts +10 -0
- package/dist/cjs/api/resources/jobs/client/requests/CancelJobRequest.js +3 -0
- package/dist/cjs/api/resources/jobs/client/requests/GetJobRequest.d.ts +10 -0
- package/dist/cjs/api/resources/jobs/client/requests/GetJobRequest.js +3 -0
- package/dist/cjs/api/resources/jobs/client/requests/index.d.ts +2 -0
- package/dist/cjs/api/resources/jobs/client/requests/index.js +2 -0
- package/dist/cjs/api/resources/jobs/index.d.ts +1 -0
- package/dist/cjs/api/resources/jobs/index.js +17 -0
- package/dist/cjs/api/resources/webhooks/client/Client.d.ts +26 -0
- package/dist/cjs/api/resources/webhooks/client/Client.js +108 -0
- package/dist/cjs/api/resources/webhooks/client/index.d.ts +1 -0
- package/dist/cjs/api/resources/webhooks/client/index.js +2 -0
- package/dist/cjs/api/resources/webhooks/index.d.ts +2 -0
- package/dist/cjs/api/resources/webhooks/index.js +18 -0
- package/dist/cjs/api/resources/webhooks/types/CreateWebhookLinkResponse.d.ts +4 -0
- package/dist/cjs/api/resources/webhooks/types/CreateWebhookLinkResponse.js +3 -0
- package/dist/cjs/api/resources/webhooks/types/index.d.ts +1 -0
- package/dist/cjs/api/resources/webhooks/types/index.js +17 -0
- package/dist/cjs/api/types/ExtractAsyncInput.d.ts +1 -0
- package/dist/cjs/api/types/ExtractAsyncInput.js +3 -0
- package/dist/cjs/api/types/ExtractAsyncResponse.d.ts +22 -0
- package/dist/cjs/api/types/ExtractAsyncResponse.js +15 -0
- package/dist/cjs/api/types/ExtractInput.d.ts +1 -0
- package/dist/cjs/api/types/ExtractInput.js +3 -0
- package/dist/cjs/api/types/ExtractJsonInput.d.ts +61 -0
- package/dist/cjs/api/types/ExtractJsonInput.js +3 -0
- package/dist/cjs/api/types/ExtractMultipartInput.d.ts +63 -0
- package/dist/cjs/api/types/ExtractMultipartInput.js +3 -0
- package/dist/cjs/api/types/ExtractOptions.d.ts +59 -0
- package/dist/cjs/api/types/ExtractOptions.js +3 -0
- package/dist/cjs/api/types/ExtractResponse.d.ts +17 -0
- package/dist/cjs/api/types/ExtractResponse.js +3 -0
- package/dist/cjs/api/types/JobCancellationResponse.d.ts +9 -0
- package/dist/cjs/api/types/JobCancellationResponse.js +3 -0
- package/dist/cjs/api/types/JobStatus.d.ts +9 -0
- package/dist/cjs/api/types/JobStatus.js +12 -0
- package/dist/cjs/api/types/JobStatusResponse.d.ts +17 -0
- package/dist/cjs/api/types/JobStatusResponse.js +3 -0
- package/dist/cjs/api/types/JsonSource.d.ts +7 -0
- package/dist/cjs/api/types/JsonSource.js +3 -0
- package/dist/cjs/api/types/MultipartSource.d.ts +9 -0
- package/dist/cjs/api/types/MultipartSource.js +3 -0
- package/dist/cjs/api/types/index.d.ts +12 -0
- package/dist/cjs/api/types/index.js +28 -0
- package/dist/cjs/auth/HeaderAuthProvider.d.ts +16 -0
- package/dist/cjs/auth/HeaderAuthProvider.js +71 -0
- package/dist/cjs/auth/index.d.ts +1 -0
- package/dist/cjs/auth/index.js +5 -0
- package/dist/cjs/core/auth/AuthProvider.d.ts +7 -0
- package/dist/cjs/core/auth/AuthProvider.js +2 -0
- package/dist/cjs/core/auth/AuthRequest.d.ts +9 -0
- package/dist/cjs/core/auth/AuthRequest.js +2 -0
- package/dist/cjs/core/auth/BasicAuth.d.ts +8 -0
- package/dist/cjs/core/auth/BasicAuth.js +27 -0
- package/dist/cjs/core/auth/BearerToken.d.ts +7 -0
- package/dist/cjs/core/auth/BearerToken.js +16 -0
- package/dist/cjs/core/auth/NoOpAuthProvider.d.ts +5 -0
- package/dist/cjs/core/auth/NoOpAuthProvider.js +9 -0
- package/dist/cjs/core/auth/index.d.ts +5 -0
- package/dist/cjs/core/auth/index.js +9 -0
- package/dist/cjs/core/base64.d.ts +2 -0
- package/dist/cjs/core/base64.js +26 -0
- package/dist/cjs/core/exports.d.ts +1 -0
- package/dist/cjs/core/exports.js +17 -0
- package/dist/cjs/core/fetcher/APIResponse.d.ts +20 -0
- package/dist/cjs/core/fetcher/APIResponse.js +2 -0
- package/dist/cjs/core/fetcher/BinaryResponse.d.ts +19 -0
- package/dist/cjs/core/fetcher/BinaryResponse.js +17 -0
- package/dist/cjs/core/fetcher/EndpointMetadata.d.ts +13 -0
- package/dist/cjs/core/fetcher/EndpointMetadata.js +2 -0
- package/dist/cjs/core/fetcher/EndpointSupplier.d.ts +12 -0
- package/dist/cjs/core/fetcher/EndpointSupplier.js +22 -0
- package/dist/cjs/core/fetcher/Fetcher.d.ts +49 -0
- package/dist/cjs/core/fetcher/Fetcher.js +316 -0
- package/dist/cjs/core/fetcher/Headers.d.ts +2 -0
- package/dist/cjs/core/fetcher/Headers.js +84 -0
- package/dist/cjs/core/fetcher/HttpResponsePromise.d.ts +58 -0
- package/dist/cjs/core/fetcher/HttpResponsePromise.js +103 -0
- package/dist/cjs/core/fetcher/RawResponse.d.ts +29 -0
- package/dist/cjs/core/fetcher/RawResponse.js +44 -0
- package/dist/cjs/core/fetcher/Supplier.d.ts +4 -0
- package/dist/cjs/core/fetcher/Supplier.js +22 -0
- package/dist/cjs/core/fetcher/createRequestUrl.d.ts +1 -0
- package/dist/cjs/core/fetcher/createRequestUrl.js +8 -0
- package/dist/cjs/core/fetcher/getErrorResponseBody.d.ts +1 -0
- package/dist/cjs/core/fetcher/getErrorResponseBody.js +45 -0
- package/dist/cjs/core/fetcher/getFetchFn.d.ts +1 -0
- package/dist/cjs/core/fetcher/getFetchFn.js +17 -0
- package/dist/cjs/core/fetcher/getHeader.d.ts +1 -0
- package/dist/cjs/core/fetcher/getHeader.js +11 -0
- package/dist/cjs/core/fetcher/getRequestBody.d.ts +7 -0
- package/dist/cjs/core/fetcher/getRequestBody.js +27 -0
- package/dist/cjs/core/fetcher/getResponseBody.d.ts +1 -0
- package/dist/cjs/core/fetcher/getResponseBody.js +69 -0
- package/dist/cjs/core/fetcher/index.d.ts +11 -0
- package/dist/cjs/core/fetcher/index.js +17 -0
- package/dist/cjs/core/fetcher/makeRequest.d.ts +1 -0
- package/dist/cjs/core/fetcher/makeRequest.js +40 -0
- package/dist/cjs/core/fetcher/requestWithRetries.d.ts +1 -0
- package/dist/cjs/core/fetcher/requestWithRetries.js +67 -0
- package/dist/cjs/core/fetcher/signals.d.ts +5 -0
- package/dist/cjs/core/fetcher/signals.js +24 -0
- package/dist/cjs/core/headers.d.ts +2 -0
- package/dist/cjs/core/headers.js +31 -0
- package/dist/cjs/core/index.d.ts +6 -0
- package/dist/cjs/core/index.js +45 -0
- package/dist/cjs/core/json.d.ts +15 -0
- package/dist/cjs/core/json.js +24 -0
- package/dist/cjs/core/logging/exports.d.ts +18 -0
- package/dist/cjs/core/logging/exports.js +45 -0
- package/dist/cjs/core/logging/index.d.ts +1 -0
- package/dist/cjs/core/logging/index.js +17 -0
- package/dist/cjs/core/logging/logger.d.ts +126 -0
- package/dist/cjs/core/logging/logger.js +144 -0
- package/dist/cjs/core/runtime/index.d.ts +1 -0
- package/dist/cjs/core/runtime/index.js +5 -0
- package/dist/cjs/core/runtime/runtime.d.ts +9 -0
- package/dist/cjs/core/runtime/runtime.js +103 -0
- package/dist/cjs/core/url/encodePathParam.d.ts +1 -0
- package/dist/cjs/core/url/encodePathParam.js +21 -0
- package/dist/cjs/core/url/index.d.ts +3 -0
- package/dist/cjs/core/url/index.js +9 -0
- package/dist/cjs/core/url/join.d.ts +1 -0
- package/dist/cjs/core/url/join.js +68 -0
- package/dist/cjs/core/url/qs.d.ts +6 -0
- package/dist/cjs/core/url/qs.js +64 -0
- package/dist/cjs/environments.d.ts +4 -0
- package/dist/cjs/environments.js +7 -0
- package/dist/cjs/errors/PulseError.d.ts +12 -0
- package/dist/cjs/errors/PulseError.js +32 -0
- package/dist/cjs/errors/PulseTimeoutError.d.ts +3 -0
- package/dist/cjs/errors/PulseTimeoutError.js +15 -0
- package/dist/cjs/errors/handleNonStatusCodeError.d.ts +2 -0
- package/dist/cjs/errors/handleNonStatusCodeError.js +65 -0
- package/dist/cjs/errors/index.d.ts +2 -0
- package/dist/cjs/errors/index.js +7 -0
- package/dist/cjs/exports.d.ts +1 -0
- package/dist/cjs/exports.js +17 -0
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.js +48 -0
- package/dist/cjs/version.d.ts +1 -0
- package/dist/cjs/version.js +4 -0
- package/dist/esm/BaseClient.d.mts +39 -0
- package/dist/esm/BaseClient.mjs +25 -0
- package/dist/esm/Client.d.mts +57 -0
- package/dist/esm/Client.mjs +152 -0
- package/dist/esm/api/errors/BadRequestError.d.mts +5 -0
- package/dist/esm/api/errors/BadRequestError.mjs +17 -0
- package/dist/esm/api/errors/ForbiddenError.d.mts +5 -0
- package/dist/esm/api/errors/ForbiddenError.mjs +17 -0
- package/dist/esm/api/errors/InternalServerError.d.mts +5 -0
- package/dist/esm/api/errors/InternalServerError.mjs +17 -0
- package/dist/esm/api/errors/NotFoundError.d.mts +5 -0
- package/dist/esm/api/errors/NotFoundError.mjs +17 -0
- package/dist/esm/api/errors/TooManyRequestsError.d.mts +5 -0
- package/dist/esm/api/errors/TooManyRequestsError.mjs +17 -0
- package/dist/esm/api/errors/UnauthorizedError.d.mts +5 -0
- package/dist/esm/api/errors/UnauthorizedError.mjs +17 -0
- package/dist/esm/api/errors/index.d.mts +6 -0
- package/dist/esm/api/errors/index.mjs +6 -0
- package/dist/esm/api/index.d.mts +3 -0
- package/dist/esm/api/index.mjs +3 -0
- package/dist/esm/api/resources/index.d.mts +4 -0
- package/dist/esm/api/resources/index.mjs +4 -0
- package/dist/esm/api/resources/jobs/client/Client.d.mts +53 -0
- package/dist/esm/api/resources/jobs/client/Client.mjs +148 -0
- package/dist/esm/api/resources/jobs/client/index.d.mts +1 -0
- package/dist/esm/api/resources/jobs/client/index.mjs +1 -0
- package/dist/esm/api/resources/jobs/client/requests/CancelJobRequest.d.mts +10 -0
- package/dist/esm/api/resources/jobs/client/requests/CancelJobRequest.mjs +2 -0
- package/dist/esm/api/resources/jobs/client/requests/GetJobRequest.d.mts +10 -0
- package/dist/esm/api/resources/jobs/client/requests/GetJobRequest.mjs +2 -0
- package/dist/esm/api/resources/jobs/client/requests/index.d.mts +2 -0
- package/dist/esm/api/resources/jobs/client/requests/index.mjs +1 -0
- package/dist/esm/api/resources/jobs/index.d.mts +1 -0
- package/dist/esm/api/resources/jobs/index.mjs +1 -0
- package/dist/esm/api/resources/webhooks/client/Client.d.mts +26 -0
- package/dist/esm/api/resources/webhooks/client/Client.mjs +71 -0
- package/dist/esm/api/resources/webhooks/client/index.d.mts +1 -0
- package/dist/esm/api/resources/webhooks/client/index.mjs +1 -0
- package/dist/esm/api/resources/webhooks/index.d.mts +2 -0
- package/dist/esm/api/resources/webhooks/index.mjs +2 -0
- package/dist/esm/api/resources/webhooks/types/CreateWebhookLinkResponse.d.mts +4 -0
- package/dist/esm/api/resources/webhooks/types/CreateWebhookLinkResponse.mjs +2 -0
- package/dist/esm/api/resources/webhooks/types/index.d.mts +1 -0
- package/dist/esm/api/resources/webhooks/types/index.mjs +1 -0
- package/dist/esm/api/types/ExtractAsyncInput.d.mts +1 -0
- package/dist/esm/api/types/ExtractAsyncInput.mjs +2 -0
- package/dist/esm/api/types/ExtractAsyncResponse.d.mts +22 -0
- package/dist/esm/api/types/ExtractAsyncResponse.mjs +12 -0
- package/dist/esm/api/types/ExtractInput.d.mts +1 -0
- package/dist/esm/api/types/ExtractInput.mjs +2 -0
- package/dist/esm/api/types/ExtractJsonInput.d.mts +61 -0
- package/dist/esm/api/types/ExtractJsonInput.mjs +2 -0
- package/dist/esm/api/types/ExtractMultipartInput.d.mts +63 -0
- package/dist/esm/api/types/ExtractMultipartInput.mjs +2 -0
- package/dist/esm/api/types/ExtractOptions.d.mts +59 -0
- package/dist/esm/api/types/ExtractOptions.mjs +2 -0
- package/dist/esm/api/types/ExtractResponse.d.mts +17 -0
- package/dist/esm/api/types/ExtractResponse.mjs +2 -0
- package/dist/esm/api/types/JobCancellationResponse.d.mts +9 -0
- package/dist/esm/api/types/JobCancellationResponse.mjs +2 -0
- package/dist/esm/api/types/JobStatus.d.mts +9 -0
- package/dist/esm/api/types/JobStatus.mjs +9 -0
- package/dist/esm/api/types/JobStatusResponse.d.mts +17 -0
- package/dist/esm/api/types/JobStatusResponse.mjs +2 -0
- package/dist/esm/api/types/JsonSource.d.mts +7 -0
- package/dist/esm/api/types/JsonSource.mjs +2 -0
- package/dist/esm/api/types/MultipartSource.d.mts +9 -0
- package/dist/esm/api/types/MultipartSource.mjs +2 -0
- package/dist/esm/api/types/index.d.mts +12 -0
- package/dist/esm/api/types/index.mjs +12 -0
- package/dist/esm/auth/HeaderAuthProvider.d.mts +16 -0
- package/dist/esm/auth/HeaderAuthProvider.mjs +34 -0
- package/dist/esm/auth/index.d.mts +1 -0
- package/dist/esm/auth/index.mjs +1 -0
- package/dist/esm/core/auth/AuthProvider.d.mts +7 -0
- package/dist/esm/core/auth/AuthProvider.mjs +1 -0
- package/dist/esm/core/auth/AuthRequest.d.mts +9 -0
- package/dist/esm/core/auth/AuthRequest.mjs +1 -0
- package/dist/esm/core/auth/BasicAuth.d.mts +8 -0
- package/dist/esm/core/auth/BasicAuth.mjs +24 -0
- package/dist/esm/core/auth/BearerToken.d.mts +7 -0
- package/dist/esm/core/auth/BearerToken.mjs +13 -0
- package/dist/esm/core/auth/NoOpAuthProvider.d.mts +5 -0
- package/dist/esm/core/auth/NoOpAuthProvider.mjs +5 -0
- package/dist/esm/core/auth/index.d.mts +5 -0
- package/dist/esm/core/auth/index.mjs +3 -0
- package/dist/esm/core/base64.d.mts +2 -0
- package/dist/esm/core/base64.mjs +22 -0
- package/dist/esm/core/exports.d.mts +1 -0
- package/dist/esm/core/exports.mjs +1 -0
- package/dist/esm/core/fetcher/APIResponse.d.mts +20 -0
- package/dist/esm/core/fetcher/APIResponse.mjs +1 -0
- package/dist/esm/core/fetcher/BinaryResponse.d.mts +19 -0
- package/dist/esm/core/fetcher/BinaryResponse.mjs +14 -0
- package/dist/esm/core/fetcher/EndpointMetadata.d.mts +13 -0
- package/dist/esm/core/fetcher/EndpointMetadata.mjs +1 -0
- package/dist/esm/core/fetcher/EndpointSupplier.d.mts +12 -0
- package/dist/esm/core/fetcher/EndpointSupplier.mjs +19 -0
- package/dist/esm/core/fetcher/Fetcher.d.mts +49 -0
- package/dist/esm/core/fetcher/Fetcher.mjs +312 -0
- package/dist/esm/core/fetcher/Headers.d.mts +2 -0
- package/dist/esm/core/fetcher/Headers.mjs +82 -0
- package/dist/esm/core/fetcher/HttpResponsePromise.d.mts +58 -0
- package/dist/esm/core/fetcher/HttpResponsePromise.mjs +99 -0
- package/dist/esm/core/fetcher/RawResponse.d.mts +29 -0
- package/dist/esm/core/fetcher/RawResponse.mjs +40 -0
- package/dist/esm/core/fetcher/Supplier.d.mts +4 -0
- package/dist/esm/core/fetcher/Supplier.mjs +19 -0
- package/dist/esm/core/fetcher/createRequestUrl.d.mts +1 -0
- package/dist/esm/core/fetcher/createRequestUrl.mjs +5 -0
- package/dist/esm/core/fetcher/getErrorResponseBody.d.mts +1 -0
- package/dist/esm/core/fetcher/getErrorResponseBody.mjs +42 -0
- package/dist/esm/core/fetcher/getFetchFn.d.mts +1 -0
- package/dist/esm/core/fetcher/getFetchFn.mjs +14 -0
- package/dist/esm/core/fetcher/getHeader.d.mts +1 -0
- package/dist/esm/core/fetcher/getHeader.mjs +8 -0
- package/dist/esm/core/fetcher/getRequestBody.d.mts +7 -0
- package/dist/esm/core/fetcher/getRequestBody.mjs +24 -0
- package/dist/esm/core/fetcher/getResponseBody.d.mts +1 -0
- package/dist/esm/core/fetcher/getResponseBody.mjs +66 -0
- package/dist/esm/core/fetcher/index.d.mts +11 -0
- package/dist/esm/core/fetcher/index.mjs +6 -0
- package/dist/esm/core/fetcher/makeRequest.d.mts +1 -0
- package/dist/esm/core/fetcher/makeRequest.mjs +36 -0
- package/dist/esm/core/fetcher/requestWithRetries.d.mts +1 -0
- package/dist/esm/core/fetcher/requestWithRetries.mjs +64 -0
- package/dist/esm/core/fetcher/signals.d.mts +5 -0
- package/dist/esm/core/fetcher/signals.mjs +20 -0
- package/dist/esm/core/headers.d.mts +2 -0
- package/dist/esm/core/headers.mjs +27 -0
- package/dist/esm/core/index.d.mts +6 -0
- package/dist/esm/core/index.mjs +6 -0
- package/dist/esm/core/json.d.mts +15 -0
- package/dist/esm/core/json.mjs +19 -0
- package/dist/esm/core/logging/exports.d.mts +18 -0
- package/dist/esm/core/logging/exports.mjs +9 -0
- package/dist/esm/core/logging/index.d.mts +1 -0
- package/dist/esm/core/logging/index.mjs +1 -0
- package/dist/esm/core/logging/logger.d.mts +126 -0
- package/dist/esm/core/logging/logger.mjs +138 -0
- package/dist/esm/core/runtime/index.d.mts +1 -0
- package/dist/esm/core/runtime/index.mjs +1 -0
- package/dist/esm/core/runtime/runtime.d.mts +9 -0
- package/dist/esm/core/runtime/runtime.mjs +100 -0
- package/dist/esm/core/url/encodePathParam.d.mts +1 -0
- package/dist/esm/core/url/encodePathParam.mjs +18 -0
- package/dist/esm/core/url/index.d.mts +3 -0
- package/dist/esm/core/url/index.mjs +3 -0
- package/dist/esm/core/url/join.d.mts +1 -0
- package/dist/esm/core/url/join.mjs +65 -0
- package/dist/esm/core/url/qs.d.mts +6 -0
- package/dist/esm/core/url/qs.mjs +61 -0
- package/dist/esm/environments.d.mts +4 -0
- package/dist/esm/environments.mjs +4 -0
- package/dist/esm/errors/PulseError.d.mts +12 -0
- package/dist/esm/errors/PulseError.mjs +28 -0
- package/dist/esm/errors/PulseTimeoutError.d.mts +3 -0
- package/dist/esm/errors/PulseTimeoutError.mjs +11 -0
- package/dist/esm/errors/handleNonStatusCodeError.d.mts +2 -0
- package/dist/esm/errors/handleNonStatusCodeError.mjs +29 -0
- package/dist/esm/errors/index.d.mts +2 -0
- package/dist/esm/errors/index.mjs +2 -0
- package/dist/esm/exports.d.mts +1 -0
- package/dist/esm/exports.mjs +1 -0
- package/dist/esm/index.d.mts +6 -0
- package/dist/esm/index.mjs +5 -0
- package/dist/esm/version.d.mts +1 -0
- package/dist/esm/version.mjs +1 -0
- package/package.json +1 -1
- package/reference.md +6 -6
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { base64Decode, base64Encode } from "../base64.mjs";
|
|
2
|
+
const BASIC_AUTH_HEADER_PREFIX = /^Basic /i;
|
|
3
|
+
export const BasicAuth = {
|
|
4
|
+
toAuthorizationHeader: (basicAuth) => {
|
|
5
|
+
if (basicAuth == null) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
const token = base64Encode(`${basicAuth.username}:${basicAuth.password}`);
|
|
9
|
+
return `Basic ${token}`;
|
|
10
|
+
},
|
|
11
|
+
fromAuthorizationHeader: (header) => {
|
|
12
|
+
const credentials = header.replace(BASIC_AUTH_HEADER_PREFIX, "");
|
|
13
|
+
const decoded = base64Decode(credentials);
|
|
14
|
+
const [username, ...passwordParts] = decoded.split(":");
|
|
15
|
+
const password = passwordParts.length > 0 ? passwordParts.join(":") : undefined;
|
|
16
|
+
if (username == null || password == null) {
|
|
17
|
+
throw new Error("Invalid basic auth");
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
username,
|
|
21
|
+
password,
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type BearerToken = string;
|
|
2
|
+
declare function toAuthorizationHeader(token: string | undefined): string | undefined;
|
|
3
|
+
export declare const BearerToken: {
|
|
4
|
+
toAuthorizationHeader: typeof toAuthorizationHeader;
|
|
5
|
+
fromAuthorizationHeader: (header: string) => BearerToken;
|
|
6
|
+
};
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const BEARER_AUTH_HEADER_PREFIX = /^Bearer /i;
|
|
2
|
+
function toAuthorizationHeader(token) {
|
|
3
|
+
if (token == null) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
return `Bearer ${token}`;
|
|
7
|
+
}
|
|
8
|
+
export const BearerToken = {
|
|
9
|
+
toAuthorizationHeader: toAuthorizationHeader,
|
|
10
|
+
fromAuthorizationHeader: (header) => {
|
|
11
|
+
return header.replace(BEARER_AUTH_HEADER_PREFIX, "").trim();
|
|
12
|
+
},
|
|
13
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function base64ToBytes(base64) {
|
|
2
|
+
const binString = atob(base64);
|
|
3
|
+
return Uint8Array.from(binString, (m) => m.codePointAt(0));
|
|
4
|
+
}
|
|
5
|
+
function bytesToBase64(bytes) {
|
|
6
|
+
const binString = String.fromCodePoint(...bytes);
|
|
7
|
+
return btoa(binString);
|
|
8
|
+
}
|
|
9
|
+
export function base64Encode(input) {
|
|
10
|
+
if (typeof Buffer !== "undefined") {
|
|
11
|
+
return Buffer.from(input, "utf8").toString("base64");
|
|
12
|
+
}
|
|
13
|
+
const bytes = new TextEncoder().encode(input);
|
|
14
|
+
return bytesToBase64(bytes);
|
|
15
|
+
}
|
|
16
|
+
export function base64Decode(input) {
|
|
17
|
+
if (typeof Buffer !== "undefined") {
|
|
18
|
+
return Buffer.from(input, "base64").toString("utf8");
|
|
19
|
+
}
|
|
20
|
+
const bytes = base64ToBytes(input);
|
|
21
|
+
return new TextDecoder().decode(bytes);
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./logging/exports.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./logging/exports.mjs";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { RawResponse } from "./RawResponse.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* The response of an API call.
|
|
4
|
+
* It is a successful response or a failed response.
|
|
5
|
+
*/
|
|
6
|
+
export type APIResponse<Success, Failure> = SuccessfulResponse<Success> | FailedResponse<Failure>;
|
|
7
|
+
export interface SuccessfulResponse<T> {
|
|
8
|
+
ok: true;
|
|
9
|
+
body: T;
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use `rawResponse` instead
|
|
12
|
+
*/
|
|
13
|
+
headers?: Record<string, any>;
|
|
14
|
+
rawResponse: RawResponse;
|
|
15
|
+
}
|
|
16
|
+
export interface FailedResponse<T> {
|
|
17
|
+
ok: false;
|
|
18
|
+
error: T;
|
|
19
|
+
rawResponse: RawResponse;
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
export declare function getBinaryResponse(response: Response): BinaryResponse;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function getBinaryResponse(response) {
|
|
2
|
+
const binaryResponse = {
|
|
3
|
+
get bodyUsed() {
|
|
4
|
+
return response.bodyUsed;
|
|
5
|
+
},
|
|
6
|
+
stream: () => response.body,
|
|
7
|
+
arrayBuffer: response.arrayBuffer.bind(response),
|
|
8
|
+
blob: response.blob.bind(response),
|
|
9
|
+
};
|
|
10
|
+
if ("bytes" in response && typeof response.bytes === "function") {
|
|
11
|
+
binaryResponse.bytes = response.bytes.bind(response);
|
|
12
|
+
}
|
|
13
|
+
return binaryResponse;
|
|
14
|
+
}
|
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EndpointMetadata } from "./EndpointMetadata.mjs";
|
|
2
|
+
import type { Supplier } from "./Supplier.mjs";
|
|
3
|
+
type EndpointSupplierFn<T> = (arg: {
|
|
4
|
+
endpointMetadata: EndpointMetadata;
|
|
5
|
+
}) => T | Promise<T>;
|
|
6
|
+
export type EndpointSupplier<T> = Supplier<T> | EndpointSupplierFn<T>;
|
|
7
|
+
export declare const EndpointSupplier: {
|
|
8
|
+
get: <T>(supplier: EndpointSupplier<T>, arg: {
|
|
9
|
+
endpointMetadata: EndpointMetadata;
|
|
10
|
+
}) => Promise<T>;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export const EndpointSupplier = {
|
|
11
|
+
get: (supplier, arg) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
if (typeof supplier === "function") {
|
|
13
|
+
return supplier(arg);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return supplier;
|
|
17
|
+
}
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type LogConfig, type Logger } from "../logging/logger.mjs";
|
|
2
|
+
import type { APIResponse } from "./APIResponse.mjs";
|
|
3
|
+
import type { EndpointMetadata } from "./EndpointMetadata.mjs";
|
|
4
|
+
import { EndpointSupplier } from "./EndpointSupplier.mjs";
|
|
5
|
+
export type FetchFunction = <R = unknown>(args: Fetcher.Args) => Promise<APIResponse<R, Fetcher.Error>>;
|
|
6
|
+
export declare namespace Fetcher {
|
|
7
|
+
interface Args {
|
|
8
|
+
url: string;
|
|
9
|
+
method: string;
|
|
10
|
+
contentType?: string;
|
|
11
|
+
headers?: Record<string, string | EndpointSupplier<string | null | undefined> | null | undefined>;
|
|
12
|
+
queryParameters?: Record<string, unknown>;
|
|
13
|
+
body?: unknown;
|
|
14
|
+
timeoutMs?: number;
|
|
15
|
+
maxRetries?: number;
|
|
16
|
+
withCredentials?: boolean;
|
|
17
|
+
abortSignal?: AbortSignal;
|
|
18
|
+
requestType?: "json" | "file" | "bytes" | "form" | "other";
|
|
19
|
+
responseType?: "json" | "blob" | "sse" | "streaming" | "text" | "arrayBuffer" | "binary-response";
|
|
20
|
+
duplex?: "half";
|
|
21
|
+
endpointMetadata?: EndpointMetadata;
|
|
22
|
+
fetchFn?: typeof fetch;
|
|
23
|
+
logging?: LogConfig | Logger;
|
|
24
|
+
}
|
|
25
|
+
type Error = FailedStatusCodeError | NonJsonError | BodyIsNullError | TimeoutError | UnknownError;
|
|
26
|
+
interface FailedStatusCodeError {
|
|
27
|
+
reason: "status-code";
|
|
28
|
+
statusCode: number;
|
|
29
|
+
body: unknown;
|
|
30
|
+
}
|
|
31
|
+
interface NonJsonError {
|
|
32
|
+
reason: "non-json";
|
|
33
|
+
statusCode: number;
|
|
34
|
+
rawBody: string;
|
|
35
|
+
}
|
|
36
|
+
interface BodyIsNullError {
|
|
37
|
+
reason: "body-is-null";
|
|
38
|
+
statusCode: number;
|
|
39
|
+
}
|
|
40
|
+
interface TimeoutError {
|
|
41
|
+
reason: "timeout";
|
|
42
|
+
}
|
|
43
|
+
interface UnknownError {
|
|
44
|
+
reason: "unknown";
|
|
45
|
+
errorMessage: string;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export declare function fetcherImpl<R = unknown>(args: Fetcher.Args): Promise<APIResponse<R, Fetcher.Error>>;
|
|
49
|
+
export declare const fetcher: FetchFunction;
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { toJson } from "../json.mjs";
|
|
11
|
+
import { createLogger } from "../logging/logger.mjs";
|
|
12
|
+
import { createRequestUrl } from "./createRequestUrl.mjs";
|
|
13
|
+
import { EndpointSupplier } from "./EndpointSupplier.mjs";
|
|
14
|
+
import { getErrorResponseBody } from "./getErrorResponseBody.mjs";
|
|
15
|
+
import { getFetchFn } from "./getFetchFn.mjs";
|
|
16
|
+
import { getRequestBody } from "./getRequestBody.mjs";
|
|
17
|
+
import { getResponseBody } from "./getResponseBody.mjs";
|
|
18
|
+
import { Headers } from "./Headers.mjs";
|
|
19
|
+
import { makeRequest } from "./makeRequest.mjs";
|
|
20
|
+
import { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse.mjs";
|
|
21
|
+
import { requestWithRetries } from "./requestWithRetries.mjs";
|
|
22
|
+
const SENSITIVE_HEADERS = new Set([
|
|
23
|
+
"authorization",
|
|
24
|
+
"www-authenticate",
|
|
25
|
+
"x-api-key",
|
|
26
|
+
"api-key",
|
|
27
|
+
"apikey",
|
|
28
|
+
"x-api-token",
|
|
29
|
+
"x-auth-token",
|
|
30
|
+
"auth-token",
|
|
31
|
+
"cookie",
|
|
32
|
+
"set-cookie",
|
|
33
|
+
"proxy-authorization",
|
|
34
|
+
"proxy-authenticate",
|
|
35
|
+
"x-csrf-token",
|
|
36
|
+
"x-xsrf-token",
|
|
37
|
+
"x-session-token",
|
|
38
|
+
"x-access-token",
|
|
39
|
+
]);
|
|
40
|
+
function redactHeaders(headers) {
|
|
41
|
+
const filtered = {};
|
|
42
|
+
for (const [key, value] of headers instanceof Headers ? headers.entries() : Object.entries(headers)) {
|
|
43
|
+
if (SENSITIVE_HEADERS.has(key.toLowerCase())) {
|
|
44
|
+
filtered[key] = "[REDACTED]";
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
filtered[key] = value;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return filtered;
|
|
51
|
+
}
|
|
52
|
+
const SENSITIVE_QUERY_PARAMS = new Set([
|
|
53
|
+
"api_key",
|
|
54
|
+
"api-key",
|
|
55
|
+
"apikey",
|
|
56
|
+
"token",
|
|
57
|
+
"access_token",
|
|
58
|
+
"access-token",
|
|
59
|
+
"auth_token",
|
|
60
|
+
"auth-token",
|
|
61
|
+
"password",
|
|
62
|
+
"passwd",
|
|
63
|
+
"secret",
|
|
64
|
+
"api_secret",
|
|
65
|
+
"api-secret",
|
|
66
|
+
"apisecret",
|
|
67
|
+
"key",
|
|
68
|
+
"session",
|
|
69
|
+
"session_id",
|
|
70
|
+
"session-id",
|
|
71
|
+
]);
|
|
72
|
+
function redactQueryParameters(queryParameters) {
|
|
73
|
+
if (queryParameters == null) {
|
|
74
|
+
return queryParameters;
|
|
75
|
+
}
|
|
76
|
+
const redacted = {};
|
|
77
|
+
for (const [key, value] of Object.entries(queryParameters)) {
|
|
78
|
+
if (SENSITIVE_QUERY_PARAMS.has(key.toLowerCase())) {
|
|
79
|
+
redacted[key] = "[REDACTED]";
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
redacted[key] = value;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return redacted;
|
|
86
|
+
}
|
|
87
|
+
function redactUrl(url) {
|
|
88
|
+
const protocolIndex = url.indexOf("://");
|
|
89
|
+
if (protocolIndex === -1)
|
|
90
|
+
return url;
|
|
91
|
+
const afterProtocol = protocolIndex + 3;
|
|
92
|
+
// Find the first delimiter that marks the end of the authority section
|
|
93
|
+
const pathStart = url.indexOf("/", afterProtocol);
|
|
94
|
+
let queryStart = url.indexOf("?", afterProtocol);
|
|
95
|
+
let fragmentStart = url.indexOf("#", afterProtocol);
|
|
96
|
+
const firstDelimiter = Math.min(pathStart === -1 ? url.length : pathStart, queryStart === -1 ? url.length : queryStart, fragmentStart === -1 ? url.length : fragmentStart);
|
|
97
|
+
// Find the LAST @ before the delimiter (handles multiple @ in credentials)
|
|
98
|
+
let atIndex = -1;
|
|
99
|
+
for (let i = afterProtocol; i < firstDelimiter; i++) {
|
|
100
|
+
if (url[i] === "@") {
|
|
101
|
+
atIndex = i;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (atIndex !== -1) {
|
|
105
|
+
url = `${url.slice(0, afterProtocol)}[REDACTED]@${url.slice(atIndex + 1)}`;
|
|
106
|
+
}
|
|
107
|
+
// Recalculate queryStart since url might have changed
|
|
108
|
+
queryStart = url.indexOf("?");
|
|
109
|
+
if (queryStart === -1)
|
|
110
|
+
return url;
|
|
111
|
+
fragmentStart = url.indexOf("#", queryStart);
|
|
112
|
+
const queryEnd = fragmentStart !== -1 ? fragmentStart : url.length;
|
|
113
|
+
const queryString = url.slice(queryStart + 1, queryEnd);
|
|
114
|
+
if (queryString.length === 0)
|
|
115
|
+
return url;
|
|
116
|
+
// FAST PATH: Quick check if any sensitive keywords present
|
|
117
|
+
// Using indexOf is faster than regex for simple substring matching
|
|
118
|
+
const lower = queryString.toLowerCase();
|
|
119
|
+
const hasSensitive = lower.includes("token") ||
|
|
120
|
+
lower.includes("key") ||
|
|
121
|
+
lower.includes("password") ||
|
|
122
|
+
lower.includes("passwd") ||
|
|
123
|
+
lower.includes("secret") ||
|
|
124
|
+
lower.includes("session") ||
|
|
125
|
+
lower.includes("auth");
|
|
126
|
+
if (!hasSensitive) {
|
|
127
|
+
return url;
|
|
128
|
+
}
|
|
129
|
+
// SLOW PATH: Parse and redact
|
|
130
|
+
const redactedParams = [];
|
|
131
|
+
const params = queryString.split("&");
|
|
132
|
+
for (const param of params) {
|
|
133
|
+
const equalIndex = param.indexOf("=");
|
|
134
|
+
if (equalIndex === -1) {
|
|
135
|
+
redactedParams.push(param);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const key = param.slice(0, equalIndex);
|
|
139
|
+
let shouldRedact = SENSITIVE_QUERY_PARAMS.has(key.toLowerCase());
|
|
140
|
+
if (!shouldRedact && key.includes("%")) {
|
|
141
|
+
try {
|
|
142
|
+
const decodedKey = decodeURIComponent(key);
|
|
143
|
+
shouldRedact = SENSITIVE_QUERY_PARAMS.has(decodedKey.toLowerCase());
|
|
144
|
+
}
|
|
145
|
+
catch (_a) { }
|
|
146
|
+
}
|
|
147
|
+
redactedParams.push(shouldRedact ? `${key}=[REDACTED]` : param);
|
|
148
|
+
}
|
|
149
|
+
return url.slice(0, queryStart + 1) + redactedParams.join("&") + url.slice(queryEnd);
|
|
150
|
+
}
|
|
151
|
+
function getHeaders(args) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
var _a;
|
|
154
|
+
const newHeaders = new Headers();
|
|
155
|
+
newHeaders.set("Accept", args.responseType === "json" ? "application/json" : args.responseType === "text" ? "text/plain" : "*/*");
|
|
156
|
+
if (args.body !== undefined && args.contentType != null) {
|
|
157
|
+
newHeaders.set("Content-Type", args.contentType);
|
|
158
|
+
}
|
|
159
|
+
if (args.headers == null) {
|
|
160
|
+
return newHeaders;
|
|
161
|
+
}
|
|
162
|
+
for (const [key, value] of Object.entries(args.headers)) {
|
|
163
|
+
const result = yield EndpointSupplier.get(value, { endpointMetadata: (_a = args.endpointMetadata) !== null && _a !== void 0 ? _a : {} });
|
|
164
|
+
if (typeof result === "string") {
|
|
165
|
+
newHeaders.set(key, result);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (result == null) {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
newHeaders.set(key, `${result}`);
|
|
172
|
+
}
|
|
173
|
+
return newHeaders;
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
export function fetcherImpl(args) {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
var _a, _b, _c;
|
|
179
|
+
const url = createRequestUrl(args.url, args.queryParameters);
|
|
180
|
+
const requestBody = yield getRequestBody({
|
|
181
|
+
body: args.body,
|
|
182
|
+
type: (_a = args.requestType) !== null && _a !== void 0 ? _a : "other",
|
|
183
|
+
});
|
|
184
|
+
const fetchFn = (_b = args.fetchFn) !== null && _b !== void 0 ? _b : (yield getFetchFn());
|
|
185
|
+
const headers = yield getHeaders(args);
|
|
186
|
+
const logger = createLogger(args.logging);
|
|
187
|
+
if (logger.isDebug()) {
|
|
188
|
+
const metadata = {
|
|
189
|
+
method: args.method,
|
|
190
|
+
url: redactUrl(url),
|
|
191
|
+
headers: redactHeaders(headers),
|
|
192
|
+
queryParameters: redactQueryParameters(args.queryParameters),
|
|
193
|
+
hasBody: requestBody != null,
|
|
194
|
+
};
|
|
195
|
+
logger.debug("Making HTTP request", metadata);
|
|
196
|
+
}
|
|
197
|
+
try {
|
|
198
|
+
const response = yield requestWithRetries(() => __awaiter(this, void 0, void 0, function* () {
|
|
199
|
+
return makeRequest(fetchFn, url, args.method, headers, requestBody, args.timeoutMs, args.abortSignal, args.withCredentials, args.duplex);
|
|
200
|
+
}), args.maxRetries);
|
|
201
|
+
if (response.status >= 200 && response.status < 400) {
|
|
202
|
+
if (logger.isDebug()) {
|
|
203
|
+
const metadata = {
|
|
204
|
+
method: args.method,
|
|
205
|
+
url: redactUrl(url),
|
|
206
|
+
statusCode: response.status,
|
|
207
|
+
responseHeaders: redactHeaders(response.headers),
|
|
208
|
+
};
|
|
209
|
+
logger.debug("HTTP request succeeded", metadata);
|
|
210
|
+
}
|
|
211
|
+
const body = yield getResponseBody(response, args.responseType);
|
|
212
|
+
return {
|
|
213
|
+
ok: true,
|
|
214
|
+
body: body,
|
|
215
|
+
headers: response.headers,
|
|
216
|
+
rawResponse: toRawResponse(response),
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
if (logger.isError()) {
|
|
221
|
+
const metadata = {
|
|
222
|
+
method: args.method,
|
|
223
|
+
url: redactUrl(url),
|
|
224
|
+
statusCode: response.status,
|
|
225
|
+
responseHeaders: redactHeaders(Object.fromEntries(response.headers.entries())),
|
|
226
|
+
};
|
|
227
|
+
logger.error("HTTP request failed with error status", metadata);
|
|
228
|
+
}
|
|
229
|
+
return {
|
|
230
|
+
ok: false,
|
|
231
|
+
error: {
|
|
232
|
+
reason: "status-code",
|
|
233
|
+
statusCode: response.status,
|
|
234
|
+
body: yield getErrorResponseBody(response),
|
|
235
|
+
},
|
|
236
|
+
rawResponse: toRawResponse(response),
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
if ((_c = args.abortSignal) === null || _c === void 0 ? void 0 : _c.aborted) {
|
|
242
|
+
if (logger.isError()) {
|
|
243
|
+
const metadata = {
|
|
244
|
+
method: args.method,
|
|
245
|
+
url: redactUrl(url),
|
|
246
|
+
};
|
|
247
|
+
logger.error("HTTP request was aborted", metadata);
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
ok: false,
|
|
251
|
+
error: {
|
|
252
|
+
reason: "unknown",
|
|
253
|
+
errorMessage: "The user aborted a request",
|
|
254
|
+
},
|
|
255
|
+
rawResponse: abortRawResponse,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
else if (error instanceof Error && error.name === "AbortError") {
|
|
259
|
+
if (logger.isError()) {
|
|
260
|
+
const metadata = {
|
|
261
|
+
method: args.method,
|
|
262
|
+
url: redactUrl(url),
|
|
263
|
+
timeoutMs: args.timeoutMs,
|
|
264
|
+
};
|
|
265
|
+
logger.error("HTTP request timed out", metadata);
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
ok: false,
|
|
269
|
+
error: {
|
|
270
|
+
reason: "timeout",
|
|
271
|
+
},
|
|
272
|
+
rawResponse: abortRawResponse,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
else if (error instanceof Error) {
|
|
276
|
+
if (logger.isError()) {
|
|
277
|
+
const metadata = {
|
|
278
|
+
method: args.method,
|
|
279
|
+
url: redactUrl(url),
|
|
280
|
+
errorMessage: error.message,
|
|
281
|
+
};
|
|
282
|
+
logger.error("HTTP request failed with error", metadata);
|
|
283
|
+
}
|
|
284
|
+
return {
|
|
285
|
+
ok: false,
|
|
286
|
+
error: {
|
|
287
|
+
reason: "unknown",
|
|
288
|
+
errorMessage: error.message,
|
|
289
|
+
},
|
|
290
|
+
rawResponse: unknownRawResponse,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
if (logger.isError()) {
|
|
294
|
+
const metadata = {
|
|
295
|
+
method: args.method,
|
|
296
|
+
url: redactUrl(url),
|
|
297
|
+
error: toJson(error),
|
|
298
|
+
};
|
|
299
|
+
logger.error("HTTP request failed with unknown error", metadata);
|
|
300
|
+
}
|
|
301
|
+
return {
|
|
302
|
+
ok: false,
|
|
303
|
+
error: {
|
|
304
|
+
reason: "unknown",
|
|
305
|
+
errorMessage: toJson(error),
|
|
306
|
+
},
|
|
307
|
+
rawResponse: unknownRawResponse,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
export const fetcher = fetcherImpl;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
let Headers;
|
|
2
|
+
if (typeof globalThis.Headers !== "undefined") {
|
|
3
|
+
Headers = globalThis.Headers;
|
|
4
|
+
}
|
|
5
|
+
else {
|
|
6
|
+
Headers = class Headers {
|
|
7
|
+
constructor(init) {
|
|
8
|
+
this.headers = new Map();
|
|
9
|
+
if (init) {
|
|
10
|
+
if (init instanceof Headers) {
|
|
11
|
+
init.forEach((value, key) => this.append(key, value));
|
|
12
|
+
}
|
|
13
|
+
else if (Array.isArray(init)) {
|
|
14
|
+
for (const [key, value] of init) {
|
|
15
|
+
if (typeof key === "string" && typeof value === "string") {
|
|
16
|
+
this.append(key, value);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
throw new TypeError("Each header entry must be a [string, string] tuple");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
for (const [key, value] of Object.entries(init)) {
|
|
25
|
+
if (typeof value === "string") {
|
|
26
|
+
this.append(key, value);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
throw new TypeError("Header values must be strings");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
append(name, value) {
|
|
36
|
+
const key = name.toLowerCase();
|
|
37
|
+
const existing = this.headers.get(key) || [];
|
|
38
|
+
this.headers.set(key, [...existing, value]);
|
|
39
|
+
}
|
|
40
|
+
delete(name) {
|
|
41
|
+
const key = name.toLowerCase();
|
|
42
|
+
this.headers.delete(key);
|
|
43
|
+
}
|
|
44
|
+
get(name) {
|
|
45
|
+
const key = name.toLowerCase();
|
|
46
|
+
const values = this.headers.get(key);
|
|
47
|
+
return values ? values.join(", ") : null;
|
|
48
|
+
}
|
|
49
|
+
has(name) {
|
|
50
|
+
const key = name.toLowerCase();
|
|
51
|
+
return this.headers.has(key);
|
|
52
|
+
}
|
|
53
|
+
set(name, value) {
|
|
54
|
+
const key = name.toLowerCase();
|
|
55
|
+
this.headers.set(key, [value]);
|
|
56
|
+
}
|
|
57
|
+
forEach(callbackfn, thisArg) {
|
|
58
|
+
const boundCallback = thisArg ? callbackfn.bind(thisArg) : callbackfn;
|
|
59
|
+
this.headers.forEach((values, key) => boundCallback(values.join(", "), key, this));
|
|
60
|
+
}
|
|
61
|
+
getSetCookie() {
|
|
62
|
+
return this.headers.get("set-cookie") || [];
|
|
63
|
+
}
|
|
64
|
+
*entries() {
|
|
65
|
+
for (const [key, values] of this.headers.entries()) {
|
|
66
|
+
yield [key, values.join(", ")];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
*keys() {
|
|
70
|
+
yield* this.headers.keys();
|
|
71
|
+
}
|
|
72
|
+
*values() {
|
|
73
|
+
for (const values of this.headers.values()) {
|
|
74
|
+
yield values.join(", ");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
[Symbol.iterator]() {
|
|
78
|
+
return this.entries();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export { Headers };
|