pulse-ts-sdk 0.0.51 → 0.0.52
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 +59 -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 +10 -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 +59 -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 +10 -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,58 @@
|
|
|
1
|
+
import type { WithRawResponse } from "./RawResponse.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* A promise that returns the parsed response and lets you retrieve the raw response too.
|
|
4
|
+
*/
|
|
5
|
+
export declare class HttpResponsePromise<T> extends Promise<T> {
|
|
6
|
+
private innerPromise;
|
|
7
|
+
private unwrappedPromise;
|
|
8
|
+
private constructor();
|
|
9
|
+
/**
|
|
10
|
+
* Creates an `HttpResponsePromise` from a function that returns a promise.
|
|
11
|
+
*
|
|
12
|
+
* @param fn - A function that returns a promise resolving to a `WithRawResponse` object.
|
|
13
|
+
* @param args - Arguments to pass to the function.
|
|
14
|
+
* @returns An `HttpResponsePromise` instance.
|
|
15
|
+
*/
|
|
16
|
+
static fromFunction<F extends (...args: never[]) => Promise<WithRawResponse<T>>, T>(fn: F, ...args: Parameters<F>): HttpResponsePromise<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a function that returns an `HttpResponsePromise` from a function that returns a promise.
|
|
19
|
+
*
|
|
20
|
+
* @param fn - A function that returns a promise resolving to a `WithRawResponse` object.
|
|
21
|
+
* @returns A function that returns an `HttpResponsePromise` instance.
|
|
22
|
+
*/
|
|
23
|
+
static interceptFunction<F extends (...args: never[]) => Promise<WithRawResponse<T>>, T = Awaited<ReturnType<F>>["data"]>(fn: F): (...args: Parameters<F>) => HttpResponsePromise<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Creates an `HttpResponsePromise` from an existing promise.
|
|
26
|
+
*
|
|
27
|
+
* @param promise - A promise resolving to a `WithRawResponse` object.
|
|
28
|
+
* @returns An `HttpResponsePromise` instance.
|
|
29
|
+
*/
|
|
30
|
+
static fromPromise<T>(promise: Promise<WithRawResponse<T>>): HttpResponsePromise<T>;
|
|
31
|
+
/**
|
|
32
|
+
* Creates an `HttpResponsePromise` from an executor function.
|
|
33
|
+
*
|
|
34
|
+
* @param executor - A function that takes resolve and reject callbacks to create a promise.
|
|
35
|
+
* @returns An `HttpResponsePromise` instance.
|
|
36
|
+
*/
|
|
37
|
+
static fromExecutor<T>(executor: (resolve: (value: WithRawResponse<T>) => void, reject: (reason?: unknown) => void) => void): HttpResponsePromise<T>;
|
|
38
|
+
/**
|
|
39
|
+
* Creates an `HttpResponsePromise` from a resolved result.
|
|
40
|
+
*
|
|
41
|
+
* @param result - A `WithRawResponse` object to resolve immediately.
|
|
42
|
+
* @returns An `HttpResponsePromise` instance.
|
|
43
|
+
*/
|
|
44
|
+
static fromResult<T>(result: WithRawResponse<T>): HttpResponsePromise<T>;
|
|
45
|
+
private unwrap;
|
|
46
|
+
/** @inheritdoc */
|
|
47
|
+
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
48
|
+
/** @inheritdoc */
|
|
49
|
+
catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): Promise<T | TResult>;
|
|
50
|
+
/** @inheritdoc */
|
|
51
|
+
finally(onfinally?: (() => void) | null): Promise<T>;
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves the data and raw response.
|
|
54
|
+
*
|
|
55
|
+
* @returns A promise resolving to a `WithRawResponse` object.
|
|
56
|
+
*/
|
|
57
|
+
withRawResponse(): Promise<WithRawResponse<T>>;
|
|
58
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* A promise that returns the parsed response and lets you retrieve the raw response too.
|
|
12
|
+
*/
|
|
13
|
+
export class HttpResponsePromise extends Promise {
|
|
14
|
+
constructor(promise) {
|
|
15
|
+
// Initialize with a no-op to avoid premature parsing
|
|
16
|
+
super((resolve) => {
|
|
17
|
+
resolve(undefined);
|
|
18
|
+
});
|
|
19
|
+
this.innerPromise = promise;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Creates an `HttpResponsePromise` from a function that returns a promise.
|
|
23
|
+
*
|
|
24
|
+
* @param fn - A function that returns a promise resolving to a `WithRawResponse` object.
|
|
25
|
+
* @param args - Arguments to pass to the function.
|
|
26
|
+
* @returns An `HttpResponsePromise` instance.
|
|
27
|
+
*/
|
|
28
|
+
static fromFunction(fn, ...args) {
|
|
29
|
+
return new HttpResponsePromise(fn(...args));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates a function that returns an `HttpResponsePromise` from a function that returns a promise.
|
|
33
|
+
*
|
|
34
|
+
* @param fn - A function that returns a promise resolving to a `WithRawResponse` object.
|
|
35
|
+
* @returns A function that returns an `HttpResponsePromise` instance.
|
|
36
|
+
*/
|
|
37
|
+
static interceptFunction(fn) {
|
|
38
|
+
return (...args) => {
|
|
39
|
+
return HttpResponsePromise.fromPromise(fn(...args));
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates an `HttpResponsePromise` from an existing promise.
|
|
44
|
+
*
|
|
45
|
+
* @param promise - A promise resolving to a `WithRawResponse` object.
|
|
46
|
+
* @returns An `HttpResponsePromise` instance.
|
|
47
|
+
*/
|
|
48
|
+
static fromPromise(promise) {
|
|
49
|
+
return new HttpResponsePromise(promise);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Creates an `HttpResponsePromise` from an executor function.
|
|
53
|
+
*
|
|
54
|
+
* @param executor - A function that takes resolve and reject callbacks to create a promise.
|
|
55
|
+
* @returns An `HttpResponsePromise` instance.
|
|
56
|
+
*/
|
|
57
|
+
static fromExecutor(executor) {
|
|
58
|
+
const promise = new Promise(executor);
|
|
59
|
+
return new HttpResponsePromise(promise);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Creates an `HttpResponsePromise` from a resolved result.
|
|
63
|
+
*
|
|
64
|
+
* @param result - A `WithRawResponse` object to resolve immediately.
|
|
65
|
+
* @returns An `HttpResponsePromise` instance.
|
|
66
|
+
*/
|
|
67
|
+
static fromResult(result) {
|
|
68
|
+
const promise = Promise.resolve(result);
|
|
69
|
+
return new HttpResponsePromise(promise);
|
|
70
|
+
}
|
|
71
|
+
unwrap() {
|
|
72
|
+
if (!this.unwrappedPromise) {
|
|
73
|
+
this.unwrappedPromise = this.innerPromise.then(({ data }) => data);
|
|
74
|
+
}
|
|
75
|
+
return this.unwrappedPromise;
|
|
76
|
+
}
|
|
77
|
+
/** @inheritdoc */
|
|
78
|
+
then(onfulfilled, onrejected) {
|
|
79
|
+
return this.unwrap().then(onfulfilled, onrejected);
|
|
80
|
+
}
|
|
81
|
+
/** @inheritdoc */
|
|
82
|
+
catch(onrejected) {
|
|
83
|
+
return this.unwrap().catch(onrejected);
|
|
84
|
+
}
|
|
85
|
+
/** @inheritdoc */
|
|
86
|
+
finally(onfinally) {
|
|
87
|
+
return this.unwrap().finally(onfinally);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Retrieves the data and raw response.
|
|
91
|
+
*
|
|
92
|
+
* @returns A promise resolving to a `WithRawResponse` object.
|
|
93
|
+
*/
|
|
94
|
+
withRawResponse() {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
return yield this.innerPromise;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The raw response from the fetch call excluding the body.
|
|
3
|
+
*/
|
|
4
|
+
export type RawResponse = Omit<{
|
|
5
|
+
[K in keyof Response as Response[K] extends Function ? never : K]: Response[K];
|
|
6
|
+
}, "ok" | "body" | "bodyUsed">;
|
|
7
|
+
/**
|
|
8
|
+
* A raw response indicating that the request was aborted.
|
|
9
|
+
*/
|
|
10
|
+
export declare const abortRawResponse: RawResponse;
|
|
11
|
+
/**
|
|
12
|
+
* A raw response indicating an unknown error.
|
|
13
|
+
*/
|
|
14
|
+
export declare const unknownRawResponse: RawResponse;
|
|
15
|
+
/**
|
|
16
|
+
* Converts a `RawResponse` object into a `RawResponse` by extracting its properties,
|
|
17
|
+
* excluding the `body` and `bodyUsed` fields.
|
|
18
|
+
*
|
|
19
|
+
* @param response - The `RawResponse` object to convert.
|
|
20
|
+
* @returns A `RawResponse` object containing the extracted properties of the input response.
|
|
21
|
+
*/
|
|
22
|
+
export declare function toRawResponse(response: Response): RawResponse;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a `RawResponse` from a standard `Response` object.
|
|
25
|
+
*/
|
|
26
|
+
export interface WithRawResponse<T> {
|
|
27
|
+
readonly data: T;
|
|
28
|
+
readonly rawResponse: RawResponse;
|
|
29
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Headers } from "./Headers.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* A raw response indicating that the request was aborted.
|
|
4
|
+
*/
|
|
5
|
+
export const abortRawResponse = {
|
|
6
|
+
headers: new Headers(),
|
|
7
|
+
redirected: false,
|
|
8
|
+
status: 499,
|
|
9
|
+
statusText: "Client Closed Request",
|
|
10
|
+
type: "error",
|
|
11
|
+
url: "",
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A raw response indicating an unknown error.
|
|
15
|
+
*/
|
|
16
|
+
export const unknownRawResponse = {
|
|
17
|
+
headers: new Headers(),
|
|
18
|
+
redirected: false,
|
|
19
|
+
status: 0,
|
|
20
|
+
statusText: "Unknown Error",
|
|
21
|
+
type: "error",
|
|
22
|
+
url: "",
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Converts a `RawResponse` object into a `RawResponse` by extracting its properties,
|
|
26
|
+
* excluding the `body` and `bodyUsed` fields.
|
|
27
|
+
*
|
|
28
|
+
* @param response - The `RawResponse` object to convert.
|
|
29
|
+
* @returns A `RawResponse` object containing the extracted properties of the input response.
|
|
30
|
+
*/
|
|
31
|
+
export function toRawResponse(response) {
|
|
32
|
+
return {
|
|
33
|
+
headers: response.headers,
|
|
34
|
+
redirected: response.redirected,
|
|
35
|
+
status: response.status,
|
|
36
|
+
statusText: response.statusText,
|
|
37
|
+
type: response.type,
|
|
38
|
+
url: response.url,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -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 Supplier = {
|
|
11
|
+
get: (supplier) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
if (typeof supplier === "function") {
|
|
13
|
+
return supplier();
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return supplier;
|
|
17
|
+
}
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createRequestUrl(baseUrl: string, queryParameters?: Record<string, unknown>): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getErrorResponseBody(response: Response): Promise<unknown>;
|
|
@@ -0,0 +1,42 @@
|
|
|
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 { fromJson } from "../json.mjs";
|
|
11
|
+
import { getResponseBody } from "./getResponseBody.mjs";
|
|
12
|
+
export function getErrorResponseBody(response) {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
var _a, _b, _c;
|
|
15
|
+
let contentType = (_a = response.headers.get("Content-Type")) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
16
|
+
if (contentType == null || contentType.length === 0) {
|
|
17
|
+
return getResponseBody(response);
|
|
18
|
+
}
|
|
19
|
+
if (contentType.indexOf(";") !== -1) {
|
|
20
|
+
contentType = (_c = (_b = contentType.split(";")[0]) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : "";
|
|
21
|
+
}
|
|
22
|
+
switch (contentType) {
|
|
23
|
+
case "application/hal+json":
|
|
24
|
+
case "application/json":
|
|
25
|
+
case "application/ld+json":
|
|
26
|
+
case "application/problem+json":
|
|
27
|
+
case "application/vnd.api+json":
|
|
28
|
+
case "text/json": {
|
|
29
|
+
const text = yield response.text();
|
|
30
|
+
return text.length > 0 ? fromJson(text) : undefined;
|
|
31
|
+
}
|
|
32
|
+
default:
|
|
33
|
+
if (contentType.startsWith("application/vnd.") && contentType.endsWith("+json")) {
|
|
34
|
+
const text = yield response.text();
|
|
35
|
+
return text.length > 0 ? fromJson(text) : undefined;
|
|
36
|
+
}
|
|
37
|
+
// Fallback to plain text if content type is not recognized
|
|
38
|
+
// Even if no body is present, the response will be an empty string
|
|
39
|
+
return yield response.text();
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getFetchFn(): Promise<typeof fetch>;
|
|
@@ -0,0 +1,14 @@
|
|
|
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 function getFetchFn() {
|
|
11
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
return fetch;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getHeader(headers: Record<string, any>, header: string): string | undefined;
|
|
@@ -0,0 +1,24 @@
|
|
|
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 { toQueryString } from "../url/qs.mjs";
|
|
12
|
+
export function getRequestBody(_a) {
|
|
13
|
+
return __awaiter(this, arguments, void 0, function* ({ body, type }) {
|
|
14
|
+
if (type === "form") {
|
|
15
|
+
return toQueryString(body, { arrayFormat: "repeat", encode: true });
|
|
16
|
+
}
|
|
17
|
+
if (type.includes("json")) {
|
|
18
|
+
return toJson(body);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return body;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getResponseBody(response: Response, responseType?: string): Promise<unknown>;
|
|
@@ -0,0 +1,66 @@
|
|
|
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 { fromJson } from "../json.mjs";
|
|
11
|
+
import { getBinaryResponse } from "./BinaryResponse.mjs";
|
|
12
|
+
export function getResponseBody(response, responseType) {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
switch (responseType) {
|
|
15
|
+
case "binary-response":
|
|
16
|
+
return getBinaryResponse(response);
|
|
17
|
+
case "blob":
|
|
18
|
+
return yield response.blob();
|
|
19
|
+
case "arrayBuffer":
|
|
20
|
+
return yield response.arrayBuffer();
|
|
21
|
+
case "sse":
|
|
22
|
+
if (response.body == null) {
|
|
23
|
+
return {
|
|
24
|
+
ok: false,
|
|
25
|
+
error: {
|
|
26
|
+
reason: "body-is-null",
|
|
27
|
+
statusCode: response.status,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return response.body;
|
|
32
|
+
case "streaming":
|
|
33
|
+
if (response.body == null) {
|
|
34
|
+
return {
|
|
35
|
+
ok: false,
|
|
36
|
+
error: {
|
|
37
|
+
reason: "body-is-null",
|
|
38
|
+
statusCode: response.status,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return response.body;
|
|
43
|
+
case "text":
|
|
44
|
+
return yield response.text();
|
|
45
|
+
}
|
|
46
|
+
// if responseType is "json" or not specified, try to parse as JSON
|
|
47
|
+
const text = yield response.text();
|
|
48
|
+
if (text.length > 0) {
|
|
49
|
+
try {
|
|
50
|
+
const responseBody = fromJson(text);
|
|
51
|
+
return responseBody;
|
|
52
|
+
}
|
|
53
|
+
catch (_err) {
|
|
54
|
+
return {
|
|
55
|
+
ok: false,
|
|
56
|
+
error: {
|
|
57
|
+
reason: "non-json",
|
|
58
|
+
statusCode: response.status,
|
|
59
|
+
rawBody: text,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type { APIResponse } from "./APIResponse.mjs";
|
|
2
|
+
export type { BinaryResponse } from "./BinaryResponse.mjs";
|
|
3
|
+
export type { EndpointMetadata } from "./EndpointMetadata.mjs";
|
|
4
|
+
export { EndpointSupplier } from "./EndpointSupplier.mjs";
|
|
5
|
+
export type { Fetcher, FetchFunction } from "./Fetcher.mjs";
|
|
6
|
+
export { fetcher } from "./Fetcher.mjs";
|
|
7
|
+
export { getHeader } from "./getHeader.mjs";
|
|
8
|
+
export { HttpResponsePromise } from "./HttpResponsePromise.mjs";
|
|
9
|
+
export type { RawResponse, WithRawResponse } from "./RawResponse.mjs";
|
|
10
|
+
export { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse.mjs";
|
|
11
|
+
export { Supplier } from "./Supplier.mjs";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { EndpointSupplier } from "./EndpointSupplier.mjs";
|
|
2
|
+
export { fetcher } from "./Fetcher.mjs";
|
|
3
|
+
export { getHeader } from "./getHeader.mjs";
|
|
4
|
+
export { HttpResponsePromise } from "./HttpResponsePromise.mjs";
|
|
5
|
+
export { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse.mjs";
|
|
6
|
+
export { Supplier } from "./Supplier.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const makeRequest: (fetchFn: (url: string, init: RequestInit) => Promise<Response>, url: string, method: string, headers: Headers | Record<string, string>, requestBody: BodyInit | undefined, timeoutMs?: number, abortSignal?: AbortSignal, withCredentials?: boolean, duplex?: "half") => Promise<Response>;
|
|
@@ -0,0 +1,36 @@
|
|
|
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 { anySignal, getTimeoutSignal } from "./signals.mjs";
|
|
11
|
+
export const makeRequest = (fetchFn, url, method, headers, requestBody, timeoutMs, abortSignal, withCredentials, duplex) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
const signals = [];
|
|
13
|
+
let timeoutAbortId;
|
|
14
|
+
if (timeoutMs != null) {
|
|
15
|
+
const { signal, abortId } = getTimeoutSignal(timeoutMs);
|
|
16
|
+
timeoutAbortId = abortId;
|
|
17
|
+
signals.push(signal);
|
|
18
|
+
}
|
|
19
|
+
if (abortSignal != null) {
|
|
20
|
+
signals.push(abortSignal);
|
|
21
|
+
}
|
|
22
|
+
const newSignals = anySignal(signals);
|
|
23
|
+
const response = yield fetchFn(url, {
|
|
24
|
+
method: method,
|
|
25
|
+
headers,
|
|
26
|
+
body: requestBody,
|
|
27
|
+
signal: newSignals,
|
|
28
|
+
credentials: withCredentials ? "include" : undefined,
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
duplex,
|
|
31
|
+
});
|
|
32
|
+
if (timeoutAbortId != null) {
|
|
33
|
+
clearTimeout(timeoutAbortId);
|
|
34
|
+
}
|
|
35
|
+
return response;
|
|
36
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function requestWithRetries(requestFn: () => Promise<Response>, maxRetries?: number): Promise<Response>;
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
const INITIAL_RETRY_DELAY = 1000; // in milliseconds
|
|
11
|
+
const MAX_RETRY_DELAY = 60000; // in milliseconds
|
|
12
|
+
const DEFAULT_MAX_RETRIES = 2;
|
|
13
|
+
const JITTER_FACTOR = 0.2; // 20% random jitter
|
|
14
|
+
function addPositiveJitter(delay) {
|
|
15
|
+
const jitterMultiplier = 1 + Math.random() * JITTER_FACTOR;
|
|
16
|
+
return delay * jitterMultiplier;
|
|
17
|
+
}
|
|
18
|
+
function addSymmetricJitter(delay) {
|
|
19
|
+
const jitterMultiplier = 1 + (Math.random() - 0.5) * JITTER_FACTOR;
|
|
20
|
+
return delay * jitterMultiplier;
|
|
21
|
+
}
|
|
22
|
+
function getRetryDelayFromHeaders(response, retryAttempt) {
|
|
23
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
24
|
+
if (retryAfter) {
|
|
25
|
+
const retryAfterSeconds = parseInt(retryAfter, 10);
|
|
26
|
+
if (!Number.isNaN(retryAfterSeconds) && retryAfterSeconds > 0) {
|
|
27
|
+
return Math.min(retryAfterSeconds * 1000, MAX_RETRY_DELAY);
|
|
28
|
+
}
|
|
29
|
+
const retryAfterDate = new Date(retryAfter);
|
|
30
|
+
if (!Number.isNaN(retryAfterDate.getTime())) {
|
|
31
|
+
const delay = retryAfterDate.getTime() - Date.now();
|
|
32
|
+
if (delay > 0) {
|
|
33
|
+
return Math.min(Math.max(delay, 0), MAX_RETRY_DELAY);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const rateLimitReset = response.headers.get("X-RateLimit-Reset");
|
|
38
|
+
if (rateLimitReset) {
|
|
39
|
+
const resetTime = parseInt(rateLimitReset, 10);
|
|
40
|
+
if (!Number.isNaN(resetTime)) {
|
|
41
|
+
const delay = resetTime * 1000 - Date.now();
|
|
42
|
+
if (delay > 0) {
|
|
43
|
+
return addPositiveJitter(Math.min(delay, MAX_RETRY_DELAY));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return addSymmetricJitter(Math.min(INITIAL_RETRY_DELAY * Math.pow(2, retryAttempt), MAX_RETRY_DELAY));
|
|
48
|
+
}
|
|
49
|
+
export function requestWithRetries(requestFn_1) {
|
|
50
|
+
return __awaiter(this, arguments, void 0, function* (requestFn, maxRetries = DEFAULT_MAX_RETRIES) {
|
|
51
|
+
let response = yield requestFn();
|
|
52
|
+
for (let i = 0; i < maxRetries; ++i) {
|
|
53
|
+
if ([408, 429].includes(response.status) || response.status >= 500) {
|
|
54
|
+
const delay = getRetryDelayFromHeaders(response, i);
|
|
55
|
+
yield new Promise((resolve) => setTimeout(resolve, delay));
|
|
56
|
+
response = yield requestFn();
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return response;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const TIMEOUT = "timeout";
|
|
2
|
+
export function getTimeoutSignal(timeoutMs) {
|
|
3
|
+
const controller = new AbortController();
|
|
4
|
+
const abortId = setTimeout(() => controller.abort(TIMEOUT), timeoutMs);
|
|
5
|
+
return { signal: controller.signal, abortId };
|
|
6
|
+
}
|
|
7
|
+
export function anySignal(...args) {
|
|
8
|
+
const signals = (args.length === 1 && Array.isArray(args[0]) ? args[0] : args);
|
|
9
|
+
const controller = new AbortController();
|
|
10
|
+
for (const signal of signals) {
|
|
11
|
+
if (signal.aborted) {
|
|
12
|
+
controller.abort(signal === null || signal === void 0 ? void 0 : signal.reason);
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
signal.addEventListener("abort", () => controller.abort(signal === null || signal === void 0 ? void 0 : signal.reason), {
|
|
16
|
+
signal: controller.signal,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return controller.signal;
|
|
20
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare function mergeHeaders<THeaderValue>(...headersArray: (Record<string, THeaderValue> | null | undefined)[]): Record<string, string | THeaderValue>;
|
|
2
|
+
export declare function mergeOnlyDefinedHeaders<THeaderValue>(...headersArray: (Record<string, THeaderValue> | null | undefined)[]): Record<string, THeaderValue>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function mergeHeaders(...headersArray) {
|
|
2
|
+
const result = {};
|
|
3
|
+
for (const [key, value] of headersArray
|
|
4
|
+
.filter((headers) => headers != null)
|
|
5
|
+
.flatMap((headers) => Object.entries(headers))) {
|
|
6
|
+
const insensitiveKey = key.toLowerCase();
|
|
7
|
+
if (value != null) {
|
|
8
|
+
result[insensitiveKey] = value;
|
|
9
|
+
}
|
|
10
|
+
else if (insensitiveKey in result) {
|
|
11
|
+
delete result[insensitiveKey];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
export function mergeOnlyDefinedHeaders(...headersArray) {
|
|
17
|
+
const result = {};
|
|
18
|
+
for (const [key, value] of headersArray
|
|
19
|
+
.filter((headers) => headers != null)
|
|
20
|
+
.flatMap((headers) => Object.entries(headers))) {
|
|
21
|
+
const insensitiveKey = key.toLowerCase();
|
|
22
|
+
if (value != null) {
|
|
23
|
+
result[insensitiveKey] = value;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|