@typespec/ts-http-runtime 0.3.5-alpha.20260311.2 → 0.3.6
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/browser/client/clientHelpers.js +1 -1
- package/dist/browser/client/clientHelpers.js.map +1 -1
- package/dist/browser/client/common.d.ts +3 -2
- package/dist/browser/client/common.js.map +1 -1
- package/dist/browser/client/getClient.js +1 -1
- package/dist/browser/client/getClient.js.map +1 -1
- package/dist/browser/client/multipart.js +1 -1
- package/dist/browser/client/multipart.js.map +1 -1
- package/dist/browser/client/restError.js +5 -4
- package/dist/browser/client/restError.js.map +1 -1
- package/dist/browser/client/sendRequest.js +25 -14
- package/dist/browser/client/sendRequest.js.map +1 -1
- package/dist/browser/client/urlHelpers.js +9 -3
- package/dist/browser/client/urlHelpers.js.map +1 -1
- package/dist/browser/constants.js +1 -1
- package/dist/browser/constants.js.map +1 -1
- package/dist/browser/createPipelineFromOptions.d.ts +1 -1
- package/dist/browser/createPipelineFromOptions.js +2 -21
- package/dist/browser/createPipelineFromOptions.js.map +1 -1
- package/dist/browser/{defaultHttpClient.d.ts → defaultHttpClient-browser.d.mts} +1 -1
- package/dist/browser/{defaultHttpClient.js → defaultHttpClient-browser.mjs} +1 -1
- package/dist/browser/defaultHttpClient-browser.mjs.map +1 -0
- package/dist/browser/encoding.d.ts +13 -0
- package/dist/browser/encoding.js +19 -0
- package/dist/browser/encoding.js.map +1 -0
- package/dist/{esm/util/checkEnvironment.d.ts → browser/env-browser.d.mts} +21 -1
- package/dist/{esm/util/checkEnvironment.js → browser/env-browser.mjs} +26 -12
- package/dist/browser/env-browser.mjs.map +1 -0
- package/dist/browser/fetchHttpClient.d.ts +5 -0
- package/dist/browser/fetchHttpClient.js.map +1 -1
- package/dist/browser/formData-web.d.mts +9 -0
- package/dist/browser/formData-web.mjs +12 -0
- package/dist/browser/formData-web.mjs.map +1 -0
- package/dist/browser/httpHeaders.js +11 -1
- package/dist/browser/httpHeaders.js.map +1 -1
- package/dist/browser/index.d.ts +3 -14
- package/dist/browser/index.js +2 -2
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/interfaces.d.ts +15 -14
- package/dist/browser/interfaces.js.map +1 -1
- package/dist/browser/logger/debug.js +3 -2
- package/dist/browser/logger/debug.js.map +1 -1
- package/dist/{react-native/logger/log.d.ts → browser/logger/log-web.d.mts} +1 -1
- package/dist/browser/logger/{log.js → log-web.mjs} +1 -1
- package/dist/browser/logger/log-web.mjs.map +1 -0
- package/dist/browser/logger/logger.js +2 -2
- package/dist/browser/logger/logger.js.map +1 -1
- package/dist/browser/pipelineRequest.js +1 -1
- package/dist/browser/pipelineRequest.js.map +1 -1
- package/dist/browser/policies/auth/basicAuthenticationPolicy.js +1 -1
- package/dist/browser/policies/auth/basicAuthenticationPolicy.js.map +1 -1
- package/dist/browser/policies/auth/checkInsecureConnection.js +3 -2
- package/dist/browser/policies/auth/checkInsecureConnection.js.map +1 -1
- package/dist/browser/policies/{decompressResponsePolicy.d.ts → decompressResponsePolicy-web.d.mts} +1 -1
- package/dist/browser/policies/{decompressResponsePolicy.js → decompressResponsePolicy-web.mjs} +1 -1
- package/dist/browser/policies/decompressResponsePolicy-web.mjs.map +1 -0
- package/dist/browser/policies/formDataPolicy.js +5 -12
- package/dist/browser/policies/formDataPolicy.js.map +1 -1
- package/dist/browser/policies/internal.d.ts +2 -2
- package/dist/browser/policies/internal.js +2 -2
- package/dist/browser/policies/internal.js.map +1 -1
- package/dist/browser/policies/multipartPolicy.js +7 -3
- package/dist/browser/policies/multipartPolicy.js.map +1 -1
- package/dist/browser/policies/platformPolicies-web.d.mts +10 -0
- package/dist/browser/policies/platformPolicies-web.mjs +12 -0
- package/dist/browser/policies/platformPolicies-web.mjs.map +1 -0
- package/dist/browser/policies/platformPolicies.d.ts +25 -0
- package/dist/browser/policies/platformPolicies.js +30 -0
- package/dist/browser/policies/platformPolicies.js.map +1 -0
- package/dist/browser/policies/proxyPolicy-web.d.mts +2 -0
- package/dist/{react-native/policies/proxyPolicy.js → browser/policies/proxyPolicy-web.mjs} +1 -1
- package/dist/browser/policies/proxyPolicy-web.mjs.map +1 -0
- package/dist/browser/policies/retryPolicy.js +4 -3
- package/dist/browser/policies/retryPolicy.js.map +1 -1
- package/dist/browser/restError.js +1 -1
- package/dist/browser/restError.js.map +1 -1
- package/dist/browser/types-browser.d.mts +19 -0
- package/dist/browser/{util/concat.js → types-browser.mjs} +2 -2
- package/dist/browser/types-browser.mjs.map +1 -0
- package/dist/browser/util/bytesEncoding-web.d.mts +2 -0
- package/dist/{react-native/util/bytesEncoding.js → browser/util/bytesEncoding-web.mjs} +1 -1
- package/dist/browser/util/bytesEncoding-web.mjs.map +1 -0
- package/dist/browser/util/bytesEncoding.common.d.ts +4 -4
- package/dist/browser/util/bytesEncoding.common.js +3 -4
- package/dist/browser/util/bytesEncoding.common.js.map +1 -1
- package/dist/browser/util/concat-browser.d.mts +16 -0
- package/dist/{esm/util/concat.common.js → browser/util/concat-browser.mjs} +4 -11
- package/dist/browser/util/concat-browser.mjs.map +1 -0
- package/dist/browser/util/inspect-web.d.mts +2 -0
- package/dist/{react-native/util/inspect.js → browser/util/inspect-web.mjs} +1 -1
- package/dist/browser/util/inspect-web.mjs.map +1 -0
- package/dist/browser/util/internal.d.ts +4 -4
- package/dist/browser/util/internal.js +4 -4
- package/dist/browser/util/internal.js.map +1 -1
- package/dist/browser/util/sanitizer.js +3 -3
- package/dist/browser/util/sanitizer.js.map +1 -1
- package/dist/browser/util/sha256-web.d.mts +2 -0
- package/dist/{react-native/util/sha256.js → browser/util/sha256-web.mjs} +1 -1
- package/dist/browser/util/sha256-web.mjs.map +1 -0
- package/dist/browser/util/sha256.common.js +1 -1
- package/dist/browser/util/sha256.common.js.map +1 -1
- package/dist/browser/util/typeGuards-browser.d.mts +14 -0
- package/dist/browser/util/typeGuards-browser.mjs +26 -0
- package/dist/browser/util/typeGuards-browser.mjs.map +1 -0
- package/dist/browser/util/typeGuards.d.ts +5 -4
- package/dist/browser/util/typeGuards.js +3 -9
- package/dist/browser/util/typeGuards.js.map +1 -1
- package/dist/browser/util/userAgent.d.ts +2 -0
- package/dist/browser/util/userAgent.js +2 -1
- package/dist/browser/util/userAgent.js.map +1 -1
- package/dist/browser/util/userAgentPlatform-browser.d.mts +37 -0
- package/dist/browser/util/{userAgentPlatform.js → userAgentPlatform-browser.mjs} +10 -11
- package/dist/browser/util/userAgentPlatform-browser.mjs.map +1 -0
- package/dist/browser/util/{uuidUtils.d.ts → uuidUtils-browser.d.mts} +1 -1
- package/dist/browser/util/{uuidUtils.js → uuidUtils-browser.mjs} +1 -1
- package/dist/browser/util/uuidUtils-browser.mjs.map +1 -0
- package/dist/browser/util/uuidUtils.common.js +1 -1
- package/dist/browser/util/uuidUtils.common.js.map +1 -1
- package/dist/commonjs/abort-controller/AbortError.js +1 -0
- package/dist/commonjs/abort-controller/AbortError.js.map +1 -1
- package/dist/commonjs/auth/credentials.js +1 -0
- package/dist/commonjs/auth/credentials.js.map +1 -1
- package/dist/commonjs/auth/oauth2Flows.js +1 -0
- package/dist/commonjs/auth/oauth2Flows.js.map +1 -1
- package/dist/commonjs/auth/schemes.js +1 -0
- package/dist/commonjs/auth/schemes.js.map +1 -1
- package/dist/commonjs/client/apiVersionPolicy.js +1 -0
- package/dist/commonjs/client/apiVersionPolicy.js.map +1 -1
- package/dist/commonjs/client/clientHelpers.js +3 -2
- package/dist/commonjs/client/clientHelpers.js.map +3 -3
- package/dist/commonjs/client/common.d.ts +3 -2
- package/dist/commonjs/client/common.js +1 -0
- package/dist/commonjs/client/common.js.map +2 -2
- package/dist/commonjs/client/getClient.js +4 -3
- package/dist/commonjs/client/getClient.js.map +3 -3
- package/dist/commonjs/client/multipart.js +1 -0
- package/dist/commonjs/client/multipart.js.map +3 -3
- package/dist/commonjs/client/operationOptionHelpers.js +1 -0
- package/dist/commonjs/client/operationOptionHelpers.js.map +1 -1
- package/dist/commonjs/client/restError.js +6 -4
- package/dist/commonjs/client/restError.js.map +3 -3
- package/dist/commonjs/client/sendRequest.js +39 -10
- package/dist/commonjs/client/sendRequest.js.map +3 -3
- package/dist/commonjs/client/urlHelpers.js +7 -3
- package/dist/commonjs/client/urlHelpers.js.map +3 -3
- package/dist/commonjs/constants.js +2 -1
- package/dist/commonjs/constants.js.map +2 -2
- package/dist/commonjs/createPipelineFromOptions.d.ts +1 -1
- package/dist/commonjs/createPipelineFromOptions.js +3 -19
- package/dist/commonjs/createPipelineFromOptions.js.map +3 -3
- package/dist/commonjs/defaultHttpClient.js +1 -0
- package/dist/commonjs/defaultHttpClient.js.map +1 -1
- package/dist/{browser/util/checkEnvironment.d.ts → commonjs/env.d.ts} +21 -1
- package/dist/commonjs/env.js +67 -0
- package/dist/commonjs/env.js.map +7 -0
- package/dist/commonjs/formData.d.ts +10 -0
- package/dist/commonjs/{logger/log.common.js → formData.js} +18 -18
- package/dist/commonjs/formData.js.map +7 -0
- package/dist/commonjs/httpHeaders.js +5 -1
- package/dist/commonjs/httpHeaders.js.map +3 -3
- package/dist/commonjs/index.d.ts +1 -12
- package/dist/commonjs/index.js +3 -2
- package/dist/commonjs/index.js.map +3 -3
- package/dist/commonjs/interfaces.d.ts +15 -14
- package/dist/commonjs/interfaces.js +1 -0
- package/dist/commonjs/interfaces.js.map +2 -2
- package/dist/commonjs/log.js +1 -0
- package/dist/commonjs/log.js.map +1 -1
- package/dist/commonjs/logger/debug.js +3 -1
- package/dist/commonjs/logger/debug.js.map +3 -3
- package/dist/commonjs/logger/internal.js +1 -0
- package/dist/commonjs/logger/internal.js.map +1 -1
- package/dist/commonjs/logger/log.js +1 -0
- package/dist/commonjs/logger/log.js.map +1 -1
- package/dist/commonjs/logger/logger.js +3 -1
- package/dist/commonjs/logger/logger.js.map +3 -3
- package/dist/commonjs/nodeHttpClient.js +4 -1
- package/dist/commonjs/nodeHttpClient.js.map +3 -3
- package/dist/commonjs/pipeline.js +1 -0
- package/dist/commonjs/pipeline.js.map +1 -1
- package/dist/commonjs/pipelineRequest.js +3 -2
- package/dist/commonjs/pipelineRequest.js.map +3 -3
- package/dist/commonjs/policies/agentPolicy.js +1 -0
- package/dist/commonjs/policies/agentPolicy.js.map +1 -1
- package/dist/commonjs/policies/auth/apiKeyAuthenticationPolicy.js +1 -0
- package/dist/commonjs/policies/auth/apiKeyAuthenticationPolicy.js.map +1 -1
- package/dist/commonjs/policies/auth/basicAuthenticationPolicy.js +1 -0
- package/dist/commonjs/policies/auth/basicAuthenticationPolicy.js.map +2 -2
- package/dist/commonjs/policies/auth/bearerAuthenticationPolicy.js +1 -0
- package/dist/commonjs/policies/auth/bearerAuthenticationPolicy.js.map +1 -1
- package/dist/commonjs/policies/auth/checkInsecureConnection.js +4 -2
- package/dist/commonjs/policies/auth/checkInsecureConnection.js.map +3 -3
- package/dist/commonjs/policies/auth/oauth2AuthenticationPolicy.js +1 -0
- package/dist/commonjs/policies/auth/oauth2AuthenticationPolicy.js.map +1 -1
- package/dist/commonjs/policies/decompressResponsePolicy.js +1 -0
- package/dist/commonjs/policies/decompressResponsePolicy.js.map +1 -1
- package/dist/commonjs/policies/defaultRetryPolicy.js +1 -0
- package/dist/commonjs/policies/defaultRetryPolicy.js.map +1 -1
- package/dist/commonjs/policies/exponentialRetryPolicy.js +1 -0
- package/dist/commonjs/policies/exponentialRetryPolicy.js.map +1 -1
- package/dist/commonjs/policies/formDataPolicy.js +5 -11
- package/dist/commonjs/policies/formDataPolicy.js.map +3 -3
- package/dist/commonjs/policies/internal.d.ts +1 -1
- package/dist/commonjs/policies/internal.js +8 -7
- package/dist/commonjs/policies/internal.js.map +3 -3
- package/dist/commonjs/policies/logPolicy.js +1 -0
- package/dist/commonjs/policies/logPolicy.js.map +1 -1
- package/dist/commonjs/policies/multipartPolicy.js +3 -2
- package/dist/commonjs/policies/multipartPolicy.js.map +3 -3
- package/dist/commonjs/policies/platformPolicies.d.ts +25 -0
- package/dist/commonjs/policies/platformPolicies.js +43 -0
- package/dist/commonjs/policies/platformPolicies.js.map +7 -0
- package/dist/commonjs/policies/proxyPolicy.js +3 -3
- package/dist/commonjs/policies/proxyPolicy.js.map +3 -3
- package/dist/commonjs/policies/redirectPolicy.js +1 -0
- package/dist/commonjs/policies/redirectPolicy.js.map +1 -1
- package/dist/commonjs/policies/retryPolicy.js +5 -3
- package/dist/commonjs/policies/retryPolicy.js.map +3 -3
- package/dist/commonjs/policies/systemErrorRetryPolicy.js +1 -0
- package/dist/commonjs/policies/systemErrorRetryPolicy.js.map +1 -1
- package/dist/commonjs/policies/throttlingRetryPolicy.js +1 -0
- package/dist/commonjs/policies/throttlingRetryPolicy.js.map +1 -1
- package/dist/commonjs/policies/tlsPolicy.js +1 -0
- package/dist/commonjs/policies/tlsPolicy.js.map +1 -1
- package/dist/commonjs/policies/userAgentPolicy.js +1 -0
- package/dist/commonjs/policies/userAgentPolicy.js.map +1 -1
- package/dist/commonjs/restError.js +1 -0
- package/dist/commonjs/restError.js.map +2 -2
- package/dist/commonjs/retryStrategies/exponentialRetryStrategy.js +1 -0
- package/dist/commonjs/retryStrategies/exponentialRetryStrategy.js.map +1 -1
- package/dist/commonjs/retryStrategies/retryStrategy.js +1 -0
- package/dist/commonjs/retryStrategies/retryStrategy.js.map +1 -1
- package/dist/commonjs/retryStrategies/throttlingRetryStrategy.js +1 -0
- package/dist/commonjs/retryStrategies/throttlingRetryStrategy.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +1 -1
- package/dist/commonjs/types.d.ts +19 -0
- package/dist/commonjs/types.js +16 -0
- package/dist/commonjs/types.js.map +7 -0
- package/dist/commonjs/util/bytesEncoding.js +1 -0
- package/dist/commonjs/util/bytesEncoding.js.map +1 -1
- package/dist/commonjs/util/concat.d.ts +1 -1
- package/dist/commonjs/util/concat.js +1 -0
- package/dist/commonjs/util/concat.js.map +3 -3
- package/dist/commonjs/util/delay.js +1 -0
- package/dist/commonjs/util/delay.js.map +1 -1
- package/dist/commonjs/util/error.js +1 -0
- package/dist/commonjs/util/error.js.map +1 -1
- package/dist/commonjs/util/helpers.js +1 -0
- package/dist/commonjs/util/helpers.js.map +1 -1
- package/dist/commonjs/util/inspect.js +1 -0
- package/dist/commonjs/util/inspect.js.map +1 -1
- package/dist/commonjs/util/internal.d.ts +1 -1
- package/dist/commonjs/util/internal.js +11 -10
- package/dist/commonjs/util/internal.js.map +3 -3
- package/dist/commonjs/util/object.js +1 -0
- package/dist/commonjs/util/object.js.map +1 -1
- package/dist/commonjs/util/random.js +1 -0
- package/dist/commonjs/util/random.js.map +1 -1
- package/dist/commonjs/util/sanitizer.js +4 -3
- package/dist/commonjs/util/sanitizer.js.map +3 -3
- package/dist/commonjs/util/sha256.js +1 -0
- package/dist/commonjs/util/sha256.js.map +1 -1
- package/dist/commonjs/util/typeGuards-node.d.ts +13 -0
- package/dist/commonjs/util/{inspect.common.js → typeGuards-node.js} +15 -6
- package/dist/commonjs/util/typeGuards-node.js.map +7 -0
- package/dist/commonjs/util/typeGuards.d.ts +5 -4
- package/dist/commonjs/util/typeGuards.js +6 -12
- package/dist/commonjs/util/typeGuards.js.map +3 -3
- package/dist/commonjs/util/userAgent.d.ts +2 -0
- package/dist/commonjs/util/userAgent.js +8 -5
- package/dist/commonjs/util/userAgent.js.map +3 -3
- package/dist/commonjs/util/userAgentPlatform.d.ts +8 -0
- package/dist/commonjs/util/userAgentPlatform.js +7 -7
- package/dist/commonjs/util/userAgentPlatform.js.map +3 -3
- package/dist/commonjs/util/uuidUtils.js +1 -0
- package/dist/commonjs/util/uuidUtils.js.map +1 -1
- package/dist/esm/client/clientHelpers.js.map +1 -1
- package/dist/esm/client/common.d.ts +3 -2
- package/dist/esm/client/common.js.map +1 -1
- package/dist/esm/client/getClient.js +1 -1
- package/dist/esm/client/getClient.js.map +1 -1
- package/dist/esm/client/multipart.js.map +1 -1
- package/dist/esm/client/restError.js +5 -4
- package/dist/esm/client/restError.js.map +1 -1
- package/dist/esm/client/sendRequest.js +25 -14
- package/dist/esm/client/sendRequest.js.map +1 -1
- package/dist/esm/client/urlHelpers.js +9 -3
- package/dist/esm/client/urlHelpers.js.map +1 -1
- package/dist/esm/constants.js +1 -1
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/createPipelineFromOptions.d.ts +1 -1
- package/dist/esm/createPipelineFromOptions.js +2 -21
- package/dist/esm/createPipelineFromOptions.js.map +1 -1
- package/dist/{react-native/util/checkEnvironment.d.ts → esm/env.d.ts} +21 -1
- package/dist/esm/env.js +48 -0
- package/dist/esm/env.js.map +1 -0
- package/dist/esm/formData.d.ts +10 -0
- package/dist/esm/formData.js +26 -0
- package/dist/esm/formData.js.map +1 -0
- package/dist/esm/httpHeaders.js +11 -1
- package/dist/esm/httpHeaders.js.map +1 -1
- package/dist/esm/index.d.ts +1 -12
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interfaces.d.ts +15 -14
- package/dist/esm/interfaces.js.map +1 -1
- package/dist/esm/logger/debug.js +2 -1
- package/dist/esm/logger/debug.js.map +1 -1
- package/dist/esm/logger/logger.js +2 -2
- package/dist/esm/logger/logger.js.map +1 -1
- package/dist/esm/nodeHttpClient.js +3 -1
- package/dist/esm/nodeHttpClient.js.map +1 -1
- package/dist/esm/pipelineRequest.js.map +1 -1
- package/dist/esm/policies/auth/basicAuthenticationPolicy.js.map +1 -1
- package/dist/esm/policies/auth/checkInsecureConnection.js +3 -2
- package/dist/esm/policies/auth/checkInsecureConnection.js.map +1 -1
- package/dist/esm/policies/formDataPolicy.js +4 -11
- package/dist/esm/policies/formDataPolicy.js.map +1 -1
- package/dist/esm/policies/internal.d.ts +1 -1
- package/dist/esm/policies/internal.js +1 -1
- package/dist/esm/policies/internal.js.map +1 -1
- package/dist/esm/policies/multipartPolicy.js +4 -0
- package/dist/esm/policies/multipartPolicy.js.map +1 -1
- package/dist/esm/policies/platformPolicies.d.ts +25 -0
- package/dist/esm/policies/platformPolicies.js +30 -0
- package/dist/esm/policies/platformPolicies.js.map +1 -0
- package/dist/esm/policies/proxyPolicy.js +2 -3
- package/dist/esm/policies/proxyPolicy.js.map +1 -1
- package/dist/esm/policies/retryPolicy.js +4 -3
- package/dist/esm/policies/retryPolicy.js.map +1 -1
- package/dist/esm/restError.js.map +1 -1
- package/dist/esm/types.d.ts +19 -0
- package/dist/esm/types.js +4 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/util/concat.d.ts +1 -1
- package/dist/esm/util/concat.js.map +1 -1
- package/dist/esm/util/internal.d.ts +1 -1
- package/dist/esm/util/internal.js +1 -1
- package/dist/esm/util/internal.js.map +1 -1
- package/dist/esm/util/sanitizer.js +3 -3
- package/dist/esm/util/sanitizer.js.map +1 -1
- package/dist/esm/util/typeGuards-node.d.ts +13 -0
- package/dist/esm/util/typeGuards-node.js +20 -0
- package/dist/esm/util/typeGuards-node.js.map +1 -0
- package/dist/esm/util/typeGuards.d.ts +5 -4
- package/dist/esm/util/typeGuards.js +3 -9
- package/dist/esm/util/typeGuards.js.map +1 -1
- package/dist/esm/util/userAgent.d.ts +2 -0
- package/dist/esm/util/userAgent.js +1 -0
- package/dist/esm/util/userAgent.js.map +1 -1
- package/dist/esm/util/userAgentPlatform.d.ts +8 -0
- package/dist/esm/util/userAgentPlatform.js +6 -7
- package/dist/esm/util/userAgentPlatform.js.map +1 -1
- package/dist/react-native/client/clientHelpers.js +1 -1
- package/dist/react-native/client/clientHelpers.js.map +1 -1
- package/dist/react-native/client/common.d.ts +3 -2
- package/dist/react-native/client/common.js.map +1 -1
- package/dist/react-native/client/getClient.js +1 -1
- package/dist/react-native/client/getClient.js.map +1 -1
- package/dist/react-native/client/multipart.js +1 -1
- package/dist/react-native/client/multipart.js.map +1 -1
- package/dist/react-native/client/restError.js +5 -4
- package/dist/react-native/client/restError.js.map +1 -1
- package/dist/react-native/client/sendRequest.js +25 -14
- package/dist/react-native/client/sendRequest.js.map +1 -1
- package/dist/react-native/client/urlHelpers.js +9 -3
- package/dist/react-native/client/urlHelpers.js.map +1 -1
- package/dist/react-native/constants.js +1 -1
- package/dist/react-native/constants.js.map +1 -1
- package/dist/react-native/createPipelineFromOptions.d.ts +1 -1
- package/dist/react-native/createPipelineFromOptions.js +2 -21
- package/dist/react-native/createPipelineFromOptions.js.map +1 -1
- package/dist/react-native/{defaultHttpClient.d.ts → defaultHttpClient-react-native.d.mts} +1 -1
- package/dist/react-native/{defaultHttpClient.js → defaultHttpClient-react-native.mjs} +1 -1
- package/dist/react-native/defaultHttpClient-react-native.mjs.map +1 -0
- package/dist/react-native/encoding-react-native.d.mts +21 -0
- package/dist/react-native/encoding-react-native.mjs +25 -0
- package/dist/react-native/encoding-react-native.mjs.map +1 -0
- package/dist/{commonjs/util/checkEnvironment.d.ts → react-native/env-react-native.d.mts} +21 -1
- package/dist/react-native/env-react-native.mjs +50 -0
- package/dist/react-native/env-react-native.mjs.map +1 -0
- package/dist/react-native/formData-web.d.mts +9 -0
- package/dist/react-native/formData-web.mjs +12 -0
- package/dist/react-native/formData-web.mjs.map +1 -0
- package/dist/react-native/httpHeaders.js +11 -1
- package/dist/react-native/httpHeaders.js.map +1 -1
- package/dist/react-native/index.d.ts +3 -14
- package/dist/react-native/index.js +2 -2
- package/dist/react-native/index.js.map +1 -1
- package/dist/react-native/interfaces.d.ts +15 -14
- package/dist/react-native/interfaces.js.map +1 -1
- package/dist/react-native/logger/debug.js +3 -2
- package/dist/react-native/logger/debug.js.map +1 -1
- package/dist/{browser/logger/log.d.ts → react-native/logger/log-web.d.mts} +1 -1
- package/dist/react-native/logger/{log.js → log-web.mjs} +1 -1
- package/dist/react-native/logger/log-web.mjs.map +1 -0
- package/dist/react-native/logger/logger.js +2 -2
- package/dist/react-native/logger/logger.js.map +1 -1
- package/dist/react-native/pipelineRequest.js +1 -1
- package/dist/react-native/pipelineRequest.js.map +1 -1
- package/dist/react-native/policies/auth/basicAuthenticationPolicy.js +1 -1
- package/dist/react-native/policies/auth/basicAuthenticationPolicy.js.map +1 -1
- package/dist/react-native/policies/auth/checkInsecureConnection.js +3 -2
- package/dist/react-native/policies/auth/checkInsecureConnection.js.map +1 -1
- package/dist/react-native/policies/decompressResponsePolicy-web.d.mts +8 -0
- package/dist/react-native/policies/decompressResponsePolicy-web.mjs +11 -0
- package/dist/react-native/policies/decompressResponsePolicy-web.mjs.map +1 -0
- package/dist/react-native/policies/formDataPolicy.js +5 -12
- package/dist/react-native/policies/formDataPolicy.js.map +1 -1
- package/dist/react-native/policies/internal.d.ts +2 -2
- package/dist/react-native/policies/internal.js +2 -2
- package/dist/react-native/policies/internal.js.map +1 -1
- package/dist/react-native/policies/multipartPolicy.js +7 -3
- package/dist/react-native/policies/multipartPolicy.js.map +1 -1
- package/dist/react-native/policies/platformPolicies-web.d.mts +10 -0
- package/dist/react-native/policies/platformPolicies-web.mjs +12 -0
- package/dist/react-native/policies/platformPolicies-web.mjs.map +1 -0
- package/dist/react-native/policies/platformPolicies.d.ts +25 -0
- package/dist/react-native/policies/platformPolicies.js +30 -0
- package/dist/react-native/policies/platformPolicies.js.map +1 -0
- package/dist/react-native/policies/proxyPolicy-web.d.mts +2 -0
- package/dist/{browser/policies/proxyPolicy.js → react-native/policies/proxyPolicy-web.mjs} +1 -1
- package/dist/react-native/policies/proxyPolicy-web.mjs.map +1 -0
- package/dist/react-native/policies/retryPolicy.js +4 -3
- package/dist/react-native/policies/retryPolicy.js.map +1 -1
- package/dist/react-native/restError.js +1 -1
- package/dist/react-native/restError.js.map +1 -1
- package/dist/react-native/types-react-native.d.mts +19 -0
- package/dist/react-native/types-react-native.mjs +4 -0
- package/dist/react-native/types-react-native.mjs.map +1 -0
- package/dist/react-native/util/bytesEncoding-web.d.mts +2 -0
- package/dist/{browser/util/bytesEncoding.js → react-native/util/bytesEncoding-web.mjs} +1 -1
- package/dist/react-native/util/bytesEncoding-web.mjs.map +1 -0
- package/dist/react-native/util/bytesEncoding.common.d.ts +4 -4
- package/dist/react-native/util/bytesEncoding.common.js +3 -4
- package/dist/react-native/util/bytesEncoding.common.js.map +1 -1
- package/dist/react-native/util/concat-react-native.d.mts +42 -0
- package/dist/react-native/util/concat-react-native.mjs +51 -0
- package/dist/react-native/util/concat-react-native.mjs.map +1 -0
- package/dist/react-native/util/inspect-web.d.mts +2 -0
- package/dist/{browser/util/inspect.js → react-native/util/inspect-web.mjs} +1 -1
- package/dist/react-native/util/inspect-web.mjs.map +1 -0
- package/dist/react-native/util/internal.d.ts +4 -4
- package/dist/react-native/util/internal.js +4 -4
- package/dist/react-native/util/internal.js.map +1 -1
- package/dist/react-native/util/sanitizer.js +3 -3
- package/dist/react-native/util/sanitizer.js.map +1 -1
- package/dist/react-native/util/sha256-web.d.mts +2 -0
- package/dist/{browser/util/sha256.js → react-native/util/sha256-web.mjs} +1 -1
- package/dist/react-native/util/sha256-web.mjs.map +1 -0
- package/dist/react-native/util/sha256.common.js +1 -1
- package/dist/react-native/util/sha256.common.js.map +1 -1
- package/dist/react-native/util/typeGuards-react-native.d.mts +16 -0
- package/dist/react-native/util/typeGuards-react-native.mjs +34 -0
- package/dist/react-native/util/typeGuards-react-native.mjs.map +1 -0
- package/dist/react-native/util/typeGuards.d.ts +5 -4
- package/dist/react-native/util/typeGuards.js +3 -9
- package/dist/react-native/util/typeGuards.js.map +1 -1
- package/dist/react-native/util/userAgent.d.ts +2 -0
- package/dist/react-native/util/userAgent.js +2 -1
- package/dist/react-native/util/userAgent.js.map +1 -1
- package/dist/react-native/util/{userAgentPlatform.d.ts → userAgentPlatform-react-native.d.mts} +1 -1
- package/dist/react-native/util/{userAgentPlatform.js → userAgentPlatform-react-native.mjs} +1 -1
- package/dist/react-native/util/userAgentPlatform-react-native.mjs.map +1 -0
- package/dist/react-native/util/uuidUtils-react-native.d.mts +2 -0
- package/dist/react-native/util/{uuidUtils.js → uuidUtils-react-native.mjs} +1 -1
- package/dist/react-native/util/uuidUtils-react-native.mjs.map +1 -0
- package/dist/react-native/util/uuidUtils.common.js +1 -1
- package/dist/react-native/util/uuidUtils.common.js.map +1 -1
- package/package.json +102 -14
- package/dist/browser/defaultHttpClient.js.map +0 -1
- package/dist/browser/logger/log.js.map +0 -1
- package/dist/browser/nodeHttpClient.d.ts +0 -9
- package/dist/browser/nodeHttpClient.js +0 -347
- package/dist/browser/nodeHttpClient.js.map +0 -1
- package/dist/browser/policies/decompressResponsePolicy.js.map +0 -1
- package/dist/browser/policies/proxyPolicy.d.ts +0 -2
- package/dist/browser/policies/proxyPolicy.js.map +0 -1
- package/dist/browser/util/bytesEncoding.d.ts +0 -2
- package/dist/browser/util/bytesEncoding.js.map +0 -1
- package/dist/browser/util/checkEnvironment.js +0 -41
- package/dist/browser/util/checkEnvironment.js.map +0 -1
- package/dist/browser/util/concat.common.d.ts +0 -17
- package/dist/browser/util/concat.common.js +0 -58
- package/dist/browser/util/concat.common.js.map +0 -1
- package/dist/browser/util/concat.d.ts +0 -2
- package/dist/browser/util/concat.js.map +0 -1
- package/dist/browser/util/inspect.d.ts +0 -2
- package/dist/browser/util/inspect.js.map +0 -1
- package/dist/browser/util/sha256.d.ts +0 -2
- package/dist/browser/util/sha256.js.map +0 -1
- package/dist/browser/util/userAgentPlatform.d.ts +0 -9
- package/dist/browser/util/userAgentPlatform.js.map +0 -1
- package/dist/browser/util/uuidUtils.js.map +0 -1
- package/dist/browser/xhrHttpClient.d.ts +0 -7
- package/dist/browser/xhrHttpClient.js +0 -174
- package/dist/browser/xhrHttpClient.js.map +0 -1
- package/dist/commonjs/fetchHttpClient.d.ts +0 -7
- package/dist/commonjs/fetchHttpClient.js +0 -237
- package/dist/commonjs/fetchHttpClient.js.map +0 -7
- package/dist/commonjs/logger/log.common.d.ts +0 -2
- package/dist/commonjs/logger/log.common.js.map +0 -7
- package/dist/commonjs/policies/proxyPolicy.common.d.ts +0 -19
- package/dist/commonjs/policies/proxyPolicy.common.js +0 -43
- package/dist/commonjs/policies/proxyPolicy.common.js.map +0 -7
- package/dist/commonjs/util/arrayBuffer.d.ts +0 -7
- package/dist/commonjs/util/arrayBuffer.js +0 -36
- package/dist/commonjs/util/arrayBuffer.js.map +0 -7
- package/dist/commonjs/util/bytesEncoding.common.d.ts +0 -61
- package/dist/commonjs/util/bytesEncoding.common.js +0 -105
- package/dist/commonjs/util/bytesEncoding.common.js.map +0 -7
- package/dist/commonjs/util/checkEnvironment.js +0 -45
- package/dist/commonjs/util/checkEnvironment.js.map +0 -7
- package/dist/commonjs/util/concat.common.d.ts +0 -17
- package/dist/commonjs/util/concat.common.js +0 -60
- package/dist/commonjs/util/concat.common.js.map +0 -7
- package/dist/commonjs/util/inspect.common.d.ts +0 -2
- package/dist/commonjs/util/inspect.common.js.map +0 -7
- package/dist/commonjs/util/sha256.common.d.ts +0 -14
- package/dist/commonjs/util/sha256.common.js +0 -69
- package/dist/commonjs/util/sha256.common.js.map +0 -7
- package/dist/commonjs/util/uuidUtils.common.d.ts +0 -13
- package/dist/commonjs/util/uuidUtils.common.js +0 -48
- package/dist/commonjs/util/uuidUtils.common.js.map +0 -7
- package/dist/commonjs/xhrHttpClient.d.ts +0 -7
- package/dist/commonjs/xhrHttpClient.js +0 -185
- package/dist/commonjs/xhrHttpClient.js.map +0 -7
- package/dist/esm/fetchHttpClient.d.ts +0 -7
- package/dist/esm/fetchHttpClient.js +0 -279
- package/dist/esm/fetchHttpClient.js.map +0 -1
- package/dist/esm/logger/log.common.d.ts +0 -2
- package/dist/esm/logger/log.common.js +0 -23
- package/dist/esm/logger/log.common.js.map +0 -1
- package/dist/esm/policies/proxyPolicy.common.d.ts +0 -19
- package/dist/esm/policies/proxyPolicy.common.js +0 -24
- package/dist/esm/policies/proxyPolicy.common.js.map +0 -1
- package/dist/esm/util/arrayBuffer.d.ts +0 -7
- package/dist/esm/util/arrayBuffer.js +0 -20
- package/dist/esm/util/arrayBuffer.js.map +0 -1
- package/dist/esm/util/bytesEncoding.common.d.ts +0 -61
- package/dist/esm/util/bytesEncoding.common.js +0 -110
- package/dist/esm/util/bytesEncoding.common.js.map +0 -1
- package/dist/esm/util/checkEnvironment.js.map +0 -1
- package/dist/esm/util/concat.common.d.ts +0 -17
- package/dist/esm/util/concat.common.js.map +0 -1
- package/dist/esm/util/inspect.common.d.ts +0 -2
- package/dist/esm/util/inspect.common.js +0 -4
- package/dist/esm/util/inspect.common.js.map +0 -1
- package/dist/esm/util/sha256.common.d.ts +0 -14
- package/dist/esm/util/sha256.common.js +0 -49
- package/dist/esm/util/sha256.common.js.map +0 -1
- package/dist/esm/util/uuidUtils.common.d.ts +0 -13
- package/dist/esm/util/uuidUtils.common.js +0 -40
- package/dist/esm/util/uuidUtils.common.js.map +0 -1
- package/dist/esm/xhrHttpClient.d.ts +0 -7
- package/dist/esm/xhrHttpClient.js +0 -174
- package/dist/esm/xhrHttpClient.js.map +0 -1
- package/dist/react-native/defaultHttpClient.js.map +0 -1
- package/dist/react-native/fetchHttpClient.d.ts +0 -7
- package/dist/react-native/fetchHttpClient.js +0 -279
- package/dist/react-native/fetchHttpClient.js.map +0 -1
- package/dist/react-native/logger/log.js.map +0 -1
- package/dist/react-native/nodeHttpClient.d.ts +0 -9
- package/dist/react-native/nodeHttpClient.js +0 -347
- package/dist/react-native/nodeHttpClient.js.map +0 -1
- package/dist/react-native/policies/decompressResponsePolicy.d.ts +0 -11
- package/dist/react-native/policies/decompressResponsePolicy.js +0 -23
- package/dist/react-native/policies/decompressResponsePolicy.js.map +0 -1
- package/dist/react-native/policies/proxyPolicy.d.ts +0 -2
- package/dist/react-native/policies/proxyPolicy.js.map +0 -1
- package/dist/react-native/util/bytesEncoding.d.ts +0 -2
- package/dist/react-native/util/bytesEncoding.js.map +0 -1
- package/dist/react-native/util/checkEnvironment.js +0 -41
- package/dist/react-native/util/checkEnvironment.js.map +0 -1
- package/dist/react-native/util/concat.common.d.ts +0 -17
- package/dist/react-native/util/concat.common.js +0 -58
- package/dist/react-native/util/concat.common.js.map +0 -1
- package/dist/react-native/util/concat.d.ts +0 -2
- package/dist/react-native/util/concat.js +0 -4
- package/dist/react-native/util/concat.js.map +0 -1
- package/dist/react-native/util/inspect.d.ts +0 -2
- package/dist/react-native/util/inspect.js.map +0 -1
- package/dist/react-native/util/sha256.d.ts +0 -2
- package/dist/react-native/util/sha256.js.map +0 -1
- package/dist/react-native/util/userAgentPlatform.js.map +0 -1
- package/dist/react-native/util/uuidUtils.d.ts +0 -2
- package/dist/react-native/util/uuidUtils.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
|
-
import { createDefaultHttpClient } from "../defaultHttpClient.
|
|
3
|
+
import { createDefaultHttpClient } from "../defaultHttpClient-browser.mjs";
|
|
4
4
|
import { createPipelineFromOptions } from "../createPipelineFromOptions.js";
|
|
5
5
|
import { apiVersionPolicy } from "./apiVersionPolicy.js";
|
|
6
6
|
import { isApiKeyCredential, isBasicCredential, isBearerTokenCredential, isOAuth2TokenCredential, } from "../auth/credentials.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientHelpers.js","sourceRoot":"","sources":["../../../src/client/clientHelpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,uBAAuB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"clientHelpers.js","sourceRoot":"","sources":["../../../src/client/clientHelpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAE5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,0BAA0B,EAAE,MAAM,gDAAgD,CAAC;AAC5F,OAAO,EAAE,yBAAyB,EAAE,MAAM,+CAA+C,CAAC;AAC1F,OAAO,EAAE,0BAA0B,EAAE,MAAM,gDAAgD,CA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ED,OAAO,gBAAgB,CAAC;AAC1B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { HttpClient } from \"../interfaces.js\";\nimport type { Pipeline } from \"../pipeline.js\";\nimport { createDefaultHttpClient } from \"#platform/httpClient\";\nimport { createPipelineFromOptions } from \"../createPipelineFromOptions.js\";\nimport type { ClientOptions } from \"./common.js\";\nimport { apiVersionPolicy } from \"./apiVersionPolicy.js\";\nimport {\n isApiKeyCredential,\n isBasicCredential,\n isBearerTokenCredential,\n isOAuth2TokenCredential,\n} from \"../auth/credentials.js\";\nimport { apiKeyAuthenticationPolicy } from \"../policies/auth/apiKeyAuthenticationPolicy.js\";\nimport { basicAuthenticationPolicy } from \"../policies/auth/basicAuthenticationPolicy.js\";\nimport { bearerAuthenticationPolicy } from \"../policies/auth/bearerAuthenticationPolicy.js\";\nimport { oauth2AuthenticationPolicy } from \"../policies/auth/oauth2AuthenticationPolicy.js\";\n\nlet cachedHttpClient: HttpClient | undefined;\n\n/**\n * Creates a default rest pipeline to re-use accross Rest Level Clients\n */\nexport function createDefaultPipeline(options: ClientOptions = {}): Pipeline {\n const pipeline = createPipelineFromOptions(options);\n\n pipeline.addPolicy(apiVersionPolicy(options));\n\n const { credential, authSchemes, allowInsecureConnection } = options;\n if (credential) {\n if (isApiKeyCredential(credential)) {\n pipeline.addPolicy(\n apiKeyAuthenticationPolicy({ authSchemes, credential, allowInsecureConnection }),\n );\n } else if (isBasicCredential(credential)) {\n pipeline.addPolicy(\n basicAuthenticationPolicy({ authSchemes, credential, allowInsecureConnection }),\n );\n } else if (isBearerTokenCredential(credential)) {\n pipeline.addPolicy(\n bearerAuthenticationPolicy({ authSchemes, credential, allowInsecureConnection }),\n );\n } else if (isOAuth2TokenCredential(credential)) {\n pipeline.addPolicy(\n oauth2AuthenticationPolicy({ authSchemes, credential, allowInsecureConnection }),\n );\n }\n }\n\n return pipeline;\n}\n\nexport function getCachedDefaultHttpsClient(): HttpClient {\n if (!cachedHttpClient) {\n cachedHttpClient = createDefaultHttpClient();\n }\n\n return cachedHttpClient;\n}\n"]}
|
|
@@ -2,6 +2,7 @@ import type { HttpClient, PipelineRequest, PipelineResponse, RawHttpHeaders, Req
|
|
|
2
2
|
import type { Pipeline, PipelinePolicy } from "../pipeline.js";
|
|
3
3
|
import type { PipelineOptions } from "../createPipelineFromOptions.js";
|
|
4
4
|
import type { LogPolicyOptions } from "../policies/logPolicy.js";
|
|
5
|
+
import type { NodeReadableStream, WebReadableStream } from "../types-browser.mjs";
|
|
5
6
|
import type { AuthScheme } from "../auth/schemes.js";
|
|
6
7
|
import type { ClientCredential } from "../auth/credentials.js";
|
|
7
8
|
/**
|
|
@@ -175,7 +176,7 @@ export type HttpNodeStreamResponse = HttpResponse & {
|
|
|
175
176
|
/**
|
|
176
177
|
* Streamable body
|
|
177
178
|
*/
|
|
178
|
-
body?:
|
|
179
|
+
body?: NodeReadableStream;
|
|
179
180
|
};
|
|
180
181
|
/**
|
|
181
182
|
* Http Response which body is a NodeJS stream object
|
|
@@ -184,7 +185,7 @@ export type HttpBrowserStreamResponse = HttpResponse & {
|
|
|
184
185
|
/**
|
|
185
186
|
* Streamable body
|
|
186
187
|
*/
|
|
187
|
-
body?:
|
|
188
|
+
body?: WebReadableStream<Uint8Array>;
|
|
188
189
|
};
|
|
189
190
|
/**
|
|
190
191
|
* Defines the type for a method that supports getting the response body as
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/client/common.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpClient,\n PipelineRequest,\n PipelineResponse,\n RawHttpHeaders,\n RequestBodyType,\n TransferProgressEvent,\n RawHttpHeadersInput,\n} from \"../interfaces.js\";\nimport type { Pipeline, PipelinePolicy } from \"../pipeline.js\";\nimport type { PipelineOptions } from \"../createPipelineFromOptions.js\";\nimport type { LogPolicyOptions } from \"../policies/logPolicy.js\";\nimport type { AuthScheme } from \"../auth/schemes.js\";\nimport type { ClientCredential } from \"../auth/credentials.js\";\n\n/**\n * Shape of the default request parameters, this may be overridden by the specific\n * request types to provide strong types\n */\nexport type RequestParameters = {\n /**\n * Headers to send along with the request\n */\n headers?: RawHttpHeadersInput;\n /**\n * Sets the accept header to send to the service\n * defaults to 'application/json'. If also a header \"accept\" is set\n * this property will take precedence.\n */\n accept?: string;\n /**\n * Body to send with the request\n */\n body?: unknown;\n /**\n * Query parameters to send with the request\n */\n queryParameters?: Record<string, unknown>;\n /**\n * Set an explicit content-type to send with the request. If also a header \"content-type\" is set\n * this property will take precedence.\n */\n contentType?: string;\n /** Set to true if the request is sent over HTTP instead of HTTPS */\n allowInsecureConnection?: boolean;\n /** Set to true if you want to skip encoding the path parameters */\n skipUrlEncoding?: boolean;\n /**\n * Path parameters for custom the base url\n */\n pathParameters?: Record<string, any>;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Callback which fires upon download progress.\n */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignal;\n\n /**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n onResponse?: RawResponseCallback;\n};\n\n/**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n// UNBRANDED DIFFERENCE: onResponse callback does not have a second __legacyError parameter which was provided for backwards compatibility\nexport type RawResponseCallback = (rawResponse: FullOperationResponse, error?: unknown) => void;\n\n/**\n * Wrapper object for http request and response. Deserialized object is stored in\n * the `parsedBody` property when the response body is received in JSON.\n */\nexport interface FullOperationResponse extends PipelineResponse {\n /**\n * The raw HTTP response headers.\n */\n rawHeaders?: RawHttpHeaders;\n\n /**\n * The response body as parsed JSON.\n */\n parsedBody?: RequestBodyType;\n\n /**\n * The request that generated the response.\n */\n request: PipelineRequest;\n}\n\n/**\n * The base options type for all operations.\n */\nexport interface OperationOptions {\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignal;\n /**\n * Options used when creating and sending HTTP requests for this operation.\n */\n requestOptions?: OperationRequestOptions;\n /**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n onResponse?: RawResponseCallback;\n}\n\n/**\n * Options used when creating and sending HTTP requests for this operation.\n */\nexport interface OperationRequestOptions {\n /**\n * User defined custom request headers that\n * will be applied before the request is sent.\n */\n headers?: RawHttpHeadersInput;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Callback which fires upon download progress.\n */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Set to true if the request is sent over HTTP instead of HTTPS\n */\n allowInsecureConnection?: boolean;\n\n /**\n * Set to true if you want to skip encoding the path parameters\n */\n skipUrlEncoding?: boolean;\n}\n\n/**\n * Type to use with pathUnchecked, overrides the body type to any to allow flexibility\n */\nexport type PathUncheckedResponse = HttpResponse & { body: any };\n\n/**\n * Shape of a Rest Level Client\n */\nexport interface Client {\n /**\n * The pipeline used by this client to make requests\n */\n pipeline: Pipeline;\n /**\n * This method will be used to send request that would check the path to provide\n * strong types. When used by the codegen this type gets overridden with the generated\n * types. For example:\n * ```typescript snippet:ReadmeSamplePathExample\n * import { Client } from \"@typespec/ts-http-runtime\";\n *\n * type MyClient = Client & {\n * path: Routes;\n * };\n * ```\n */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n path: Function;\n /**\n * This method allows arbitrary paths and doesn't provide strong types\n */\n pathUnchecked: PathUnchecked;\n}\n\n/**\n * Http Response which body is a NodeJS stream object\n */\nexport type HttpNodeStreamResponse = HttpResponse & {\n /**\n * Streamable body\n */\n body?: NodeJS.ReadableStream;\n};\n\n/**\n * Http Response which body is a NodeJS stream object\n */\nexport type HttpBrowserStreamResponse = HttpResponse & {\n /**\n * Streamable body\n */\n body?: ReadableStream<Uint8Array>;\n};\n\n/**\n * Defines the type for a method that supports getting the response body as\n * a raw stream\n */\nexport type StreamableMethod<TResponse = PathUncheckedResponse> = PromiseLike<TResponse> & {\n /**\n * Returns the response body as a NodeJS stream. Only available in Node-like environments.\n */\n asNodeStream: () => Promise<HttpNodeStreamResponse>;\n /**\n * Returns the response body as a browser (Web) stream. Only available in the browser. If you require a Web Stream of the response in Node, consider using the\n * `Readable.toWeb` Node API on the result of `asNodeStream`.\n */\n asBrowserStream: () => Promise<HttpBrowserStreamResponse>;\n};\n\n/**\n * Defines the signature for pathUnchecked.\n */\nexport type PathUnchecked = <TPath extends string>(\n path: TPath,\n ...args: PathParameters<TPath>\n) => ResourceMethods<StreamableMethod>;\n\n/**\n * Defines the methods that can be called on a resource\n */\nexport interface ResourceMethods<TResponse = PromiseLike<PathUncheckedResponse>> {\n /**\n * Definition of the GET HTTP method for a resource\n */\n get: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the POST HTTP method for a resource\n */\n post: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the PUT HTTP method for a resource\n */\n put: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the PATCH HTTP method for a resource\n */\n patch: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the DELETE HTTP method for a resource\n */\n delete: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the HEAD HTTP method for a resource\n */\n head: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the OPTIONS HTTP method for a resource\n */\n options: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the TRACE HTTP method for a resource\n */\n trace: (options?: RequestParameters) => TResponse;\n}\n\n/**\n * Used to configure additional policies added to the pipeline at construction.\n */\nexport interface AdditionalPolicyConfig {\n /**\n * A policy to be added.\n */\n policy: PipelinePolicy;\n /**\n * Determines if this policy be applied before or after retry logic.\n * Only use `perRetry` if you need to modify the request again\n * each time the operation is retried due to retryable service\n * issues.\n */\n position: \"perCall\" | \"perRetry\";\n}\n\n/**\n * General options that a Rest Level Client can take\n */\nexport type ClientOptions = PipelineOptions & {\n /**\n * List of authentication schemes supported by the client.\n * These schemes define how the client can authenticate requests.\n */\n authSchemes?: AuthScheme[];\n\n /**\n * The credential used to authenticate requests.\n * Must be compatible with one of the specified authentication schemes.\n */\n credential?: ClientCredential;\n\n // UNBRANDED DIFFERENCE: The deprecated baseUrl property is removed in favor of the endpoint property in the unbranded Core package\n\n /**\n * Endpoint for the client\n */\n endpoint?: string;\n /**\n * Options for setting a custom apiVersion.\n */\n apiVersion?: string;\n /**\n * Option to allow calling http (insecure) endpoints\n */\n allowInsecureConnection?: boolean;\n /**\n * Additional policies to include in the HTTP pipeline.\n */\n additionalPolicies?: AdditionalPolicyConfig[];\n /**\n * Specify a custom HttpClient when making requests.\n */\n httpClient?: HttpClient;\n /**\n * Options to configure request/response logging.\n */\n loggingOptions?: LogPolicyOptions;\n /**\n * Pipeline to use for the client. If not provided, a default pipeline will be created using the options provided.\n * Use with caution -- when setting this option, all client options that are used in the creation of the default pipeline\n * will be ignored.\n */\n pipeline?: Pipeline;\n};\n\n/**\n * Represents the shape of an HttpResponse\n */\nexport type HttpResponse = {\n /**\n * The request that generated this response.\n */\n request: PipelineRequest;\n /**\n * The HTTP response headers.\n */\n headers: RawHttpHeaders;\n /**\n * Parsed body\n */\n body: unknown;\n /**\n * The HTTP status code of the response.\n */\n status: string;\n};\n\n/**\n * Helper type used to detect parameters in a path template\n * text surrounded by \\{\\} will be considered a path parameter\n */\nexport type PathParameters<\n TRoute extends string,\n // This is trying to match the string in TRoute with a template where HEAD/{PARAM}/TAIL\n // for example in the followint path: /foo/{fooId}/bar/{barId}/baz the template will infer\n // HEAD: /foo\n // Param: fooId\n // Tail: /bar/{barId}/baz\n // The above sample path would return [pathParam: string, pathParam: string]\n> = TRoute extends `${infer _Head}/{${infer _Param}}${infer Tail}`\n ? // In case we have a match for the template above we know for sure\n // that we have at least one pathParameter, that's why we set the first pathParam\n // in the tuple. At this point we have only matched up until param, if we want to identify\n // additional parameters we can call RouteParameters recursively on the Tail to match the remaining parts,\n // in case the Tail has more parameters, it will return a tuple with the parameters found in tail.\n // We spread the second path params to end up with a single dimension tuple at the end.\n [\n pathParameter: string | number | PathParameterWithOptions,\n ...pathParameters: PathParameters<Tail>,\n ]\n : // When the path doesn't match the template, it means that we have no path parameters so we return\n // an empty tuple.\n [];\n\n/** A response containing error details. */\nexport interface ErrorResponse {\n /** The error object. */\n error: ErrorModel;\n}\n\n/** The error object. */\nexport interface ErrorModel {\n /** One of a server-defined set of error codes. */\n code: string;\n /** A human-readable representation of the error. */\n message: string;\n /** The target of the error. */\n target?: string;\n /** An array of details about specific errors that led to this reported error. */\n details: Array<ErrorModel>;\n /** An object containing more specific information than the current object about the error. */\n innererror?: InnerError;\n}\n\n/** An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. */\nexport interface InnerError {\n /** One of a server-defined set of error codes. */\n code: string;\n /** Inner error. */\n innererror?: InnerError;\n}\n\n/**\n * An object that can be passed as a path parameter, allowing for additional options to be set relating to how the parameter is encoded.\n */\nexport interface PathParameterWithOptions {\n /**\n * The value of the parameter.\n */\n value: string | number;\n\n /**\n * Whether to allow for reserved characters in the value. If set to true, special characters such as '/' in the parameter's value will not be URL encoded.\n * Defaults to false.\n */\n allowReserved?: boolean;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/client/common.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpClient,\n PipelineRequest,\n PipelineResponse,\n RawHttpHeaders,\n RequestBodyType,\n TransferProgressEvent,\n RawHttpHeadersInput,\n} from \"../interfaces.js\";\nimport type { Pipeline, PipelinePolicy } from \"../pipeline.js\";\nimport type { PipelineOptions } from \"../createPipelineFromOptions.js\";\nimport type { LogPolicyOptions } from \"../policies/logPolicy.js\";\nimport type { NodeReadableStream, WebReadableStream } from \"#platform/types\";\nimport type { AuthScheme } from \"../auth/schemes.js\";\nimport type { ClientCredential } from \"../auth/credentials.js\";\n\n/**\n * Shape of the default request parameters, this may be overridden by the specific\n * request types to provide strong types\n */\nexport type RequestParameters = {\n /**\n * Headers to send along with the request\n */\n headers?: RawHttpHeadersInput;\n /**\n * Sets the accept header to send to the service\n * defaults to 'application/json'. If also a header \"accept\" is set\n * this property will take precedence.\n */\n accept?: string;\n /**\n * Body to send with the request\n */\n body?: unknown;\n /**\n * Query parameters to send with the request\n */\n queryParameters?: Record<string, unknown>;\n /**\n * Set an explicit content-type to send with the request. If also a header \"content-type\" is set\n * this property will take precedence.\n */\n contentType?: string;\n /** Set to true if the request is sent over HTTP instead of HTTPS */\n allowInsecureConnection?: boolean;\n /** Set to true if you want to skip encoding the path parameters */\n skipUrlEncoding?: boolean;\n /**\n * Path parameters for custom the base url\n */\n pathParameters?: Record<string, any>;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Callback which fires upon download progress.\n */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignal;\n\n /**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n onResponse?: RawResponseCallback;\n};\n\n/**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n// UNBRANDED DIFFERENCE: onResponse callback does not have a second __legacyError parameter which was provided for backwards compatibility\nexport type RawResponseCallback = (rawResponse: FullOperationResponse, error?: unknown) => void;\n\n/**\n * Wrapper object for http request and response. Deserialized object is stored in\n * the `parsedBody` property when the response body is received in JSON.\n */\nexport interface FullOperationResponse extends PipelineResponse {\n /**\n * The raw HTTP response headers.\n */\n rawHeaders?: RawHttpHeaders;\n\n /**\n * The response body as parsed JSON.\n */\n parsedBody?: RequestBodyType;\n\n /**\n * The request that generated the response.\n */\n request: PipelineRequest;\n}\n\n/**\n * The base options type for all operations.\n */\nexport interface OperationOptions {\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignal;\n /**\n * Options used when creating and sending HTTP requests for this operation.\n */\n requestOptions?: OperationRequestOptions;\n /**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n onResponse?: RawResponseCallback;\n}\n\n/**\n * Options used when creating and sending HTTP requests for this operation.\n */\nexport interface OperationRequestOptions {\n /**\n * User defined custom request headers that\n * will be applied before the request is sent.\n */\n headers?: RawHttpHeadersInput;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Callback which fires upon download progress.\n */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Set to true if the request is sent over HTTP instead of HTTPS\n */\n allowInsecureConnection?: boolean;\n\n /**\n * Set to true if you want to skip encoding the path parameters\n */\n skipUrlEncoding?: boolean;\n}\n\n/**\n * Type to use with pathUnchecked, overrides the body type to any to allow flexibility\n */\nexport type PathUncheckedResponse = HttpResponse & { body: any };\n\n/**\n * Shape of a Rest Level Client\n */\nexport interface Client {\n /**\n * The pipeline used by this client to make requests\n */\n pipeline: Pipeline;\n /**\n * This method will be used to send request that would check the path to provide\n * strong types. When used by the codegen this type gets overridden with the generated\n * types. For example:\n * ```typescript snippet:ReadmeSamplePathExample\n * import { Client } from \"@typespec/ts-http-runtime\";\n *\n * type MyClient = Client & {\n * path: Routes;\n * };\n * ```\n */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n path: Function;\n /**\n * This method allows arbitrary paths and doesn't provide strong types\n */\n pathUnchecked: PathUnchecked;\n}\n\n/**\n * Http Response which body is a NodeJS stream object\n */\nexport type HttpNodeStreamResponse = HttpResponse & {\n /**\n * Streamable body\n */\n body?: NodeReadableStream;\n};\n\n/**\n * Http Response which body is a NodeJS stream object\n */\nexport type HttpBrowserStreamResponse = HttpResponse & {\n /**\n * Streamable body\n */\n body?: WebReadableStream<Uint8Array>;\n};\n\n/**\n * Defines the type for a method that supports getting the response body as\n * a raw stream\n */\nexport type StreamableMethod<TResponse = PathUncheckedResponse> = PromiseLike<TResponse> & {\n /**\n * Returns the response body as a NodeJS stream. Only available in Node-like environments.\n */\n asNodeStream: () => Promise<HttpNodeStreamResponse>;\n /**\n * Returns the response body as a browser (Web) stream. Only available in the browser. If you require a Web Stream of the response in Node, consider using the\n * `Readable.toWeb` Node API on the result of `asNodeStream`.\n */\n asBrowserStream: () => Promise<HttpBrowserStreamResponse>;\n};\n\n/**\n * Defines the signature for pathUnchecked.\n */\nexport type PathUnchecked = <TPath extends string>(\n path: TPath,\n ...args: PathParameters<TPath>\n) => ResourceMethods<StreamableMethod>;\n\n/**\n * Defines the methods that can be called on a resource\n */\nexport interface ResourceMethods<TResponse = PromiseLike<PathUncheckedResponse>> {\n /**\n * Definition of the GET HTTP method for a resource\n */\n get: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the POST HTTP method for a resource\n */\n post: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the PUT HTTP method for a resource\n */\n put: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the PATCH HTTP method for a resource\n */\n patch: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the DELETE HTTP method for a resource\n */\n delete: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the HEAD HTTP method for a resource\n */\n head: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the OPTIONS HTTP method for a resource\n */\n options: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the TRACE HTTP method for a resource\n */\n trace: (options?: RequestParameters) => TResponse;\n}\n\n/**\n * Used to configure additional policies added to the pipeline at construction.\n */\nexport interface AdditionalPolicyConfig {\n /**\n * A policy to be added.\n */\n policy: PipelinePolicy;\n /**\n * Determines if this policy be applied before or after retry logic.\n * Only use `perRetry` if you need to modify the request again\n * each time the operation is retried due to retryable service\n * issues.\n */\n position: \"perCall\" | \"perRetry\";\n}\n\n/**\n * General options that a Rest Level Client can take\n */\nexport type ClientOptions = PipelineOptions & {\n /**\n * List of authentication schemes supported by the client.\n * These schemes define how the client can authenticate requests.\n */\n authSchemes?: AuthScheme[];\n\n /**\n * The credential used to authenticate requests.\n * Must be compatible with one of the specified authentication schemes.\n */\n credential?: ClientCredential;\n\n // UNBRANDED DIFFERENCE: The deprecated baseUrl property is removed in favor of the endpoint property in the unbranded Core package\n\n /**\n * Endpoint for the client\n */\n endpoint?: string;\n /**\n * Options for setting a custom apiVersion.\n */\n apiVersion?: string;\n /**\n * Option to allow calling http (insecure) endpoints\n */\n allowInsecureConnection?: boolean;\n /**\n * Additional policies to include in the HTTP pipeline.\n */\n additionalPolicies?: AdditionalPolicyConfig[];\n /**\n * Specify a custom HttpClient when making requests.\n */\n httpClient?: HttpClient;\n /**\n * Options to configure request/response logging.\n */\n loggingOptions?: LogPolicyOptions;\n /**\n * Pipeline to use for the client. If not provided, a default pipeline will be created using the options provided.\n * Use with caution -- when setting this option, all client options that are used in the creation of the default pipeline\n * will be ignored.\n */\n pipeline?: Pipeline;\n};\n\n/**\n * Represents the shape of an HttpResponse\n */\nexport type HttpResponse = {\n /**\n * The request that generated this response.\n */\n request: PipelineRequest;\n /**\n * The HTTP response headers.\n */\n headers: RawHttpHeaders;\n /**\n * Parsed body\n */\n body: unknown;\n /**\n * The HTTP status code of the response.\n */\n status: string;\n};\n\n/**\n * Helper type used to detect parameters in a path template\n * text surrounded by \\{\\} will be considered a path parameter\n */\nexport type PathParameters<\n TRoute extends string,\n // This is trying to match the string in TRoute with a template where HEAD/{PARAM}/TAIL\n // for example in the followint path: /foo/{fooId}/bar/{barId}/baz the template will infer\n // HEAD: /foo\n // Param: fooId\n // Tail: /bar/{barId}/baz\n // The above sample path would return [pathParam: string, pathParam: string]\n> = TRoute extends `${infer _Head}/{${infer _Param}}${infer Tail}`\n ? // In case we have a match for the template above we know for sure\n // that we have at least one pathParameter, that's why we set the first pathParam\n // in the tuple. At this point we have only matched up until param, if we want to identify\n // additional parameters we can call RouteParameters recursively on the Tail to match the remaining parts,\n // in case the Tail has more parameters, it will return a tuple with the parameters found in tail.\n // We spread the second path params to end up with a single dimension tuple at the end.\n [\n pathParameter: string | number | PathParameterWithOptions,\n ...pathParameters: PathParameters<Tail>,\n ]\n : // When the path doesn't match the template, it means that we have no path parameters so we return\n // an empty tuple.\n [];\n\n/** A response containing error details. */\nexport interface ErrorResponse {\n /** The error object. */\n error: ErrorModel;\n}\n\n/** The error object. */\nexport interface ErrorModel {\n /** One of a server-defined set of error codes. */\n code: string;\n /** A human-readable representation of the error. */\n message: string;\n /** The target of the error. */\n target?: string;\n /** An array of details about specific errors that led to this reported error. */\n details: Array<ErrorModel>;\n /** An object containing more specific information than the current object about the error. */\n innererror?: InnerError;\n}\n\n/** An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. */\nexport interface InnerError {\n /** One of a server-defined set of error codes. */\n code: string;\n /** Inner error. */\n innererror?: InnerError;\n}\n\n/**\n * An object that can be passed as a path parameter, allowing for additional options to be set relating to how the parameter is encoded.\n */\nexport interface PathParameterWithOptions {\n /**\n * The value of the parameter.\n */\n value: string | number;\n\n /**\n * Whether to allow for reserved characters in the value. If set to true, special characters such as '/' in the parameter's value will not be URL encoded.\n * Defaults to false.\n */\n allowReserved?: boolean;\n}\n"]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { createDefaultPipeline } from "./clientHelpers.js";
|
|
4
4
|
import { sendRequest } from "./sendRequest.js";
|
|
5
5
|
import { buildRequestUrl } from "./urlHelpers.js";
|
|
6
|
-
import { isNodeLike } from "../
|
|
6
|
+
import { isNodeLike } from "../env-browser.mjs";
|
|
7
7
|
/**
|
|
8
8
|
* Creates a client with a default pipeline
|
|
9
9
|
* @param endpoint - Base endpoint for the client
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getClient.js","sourceRoot":"","sources":["../../../src/client/getClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAU3D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"getClient.js","sourceRoot":"","sources":["../../../src/client/getClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAU3D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,QAAgB,EAAE,gBAA+B,EAAE;IAC3E,MAAM,QAAQ,GAAG,aAAa,CAAC,QAAQ,IAAI,qBAAqB,CAAC,aAAa,CAAC,CAAC;IAChF,IAAI,aAAa,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC;QAC7C,KAAK,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,aAAa,CAAC,kBAAkB,EAAE,CAAC;YACpE,2DAA2D;YAC3D,6CAA6C;YAC7C,MAAM,UAAU,GAAG,QAAQ,KAAK,UAAU,CA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CAAC;QAClC,CAAC;QACD,KAAK,CAAC,eAAe;YACnB,IAAI,UAAU,EAAE,CAAC;gBACf,MAAM,IAAI,KAAK,CACb,sPAAsP,CACvP,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,OAAO,WAAW,CAChB,MAAM,EACN,GAAG,EACH,QAAQ,EACR,EAAE,GAAG,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,IAAI,EAAE,EAC/D,UAAU,CAC2B,CAAC;YAC1C,CAAC;QACH,CAAC;QACD,KAAK,CAAC,YAAY;YAChB,IAAI,UAAU,EAAE,CAAC;gBACf,OAAO,WAAW,CAChB,MAAM,EACN,GAAG,EACH,QAAQ,EACR,EAAE,GAAG,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,IAAI,EAAE,EAC/D,UAAU,CACwB,CAAC;YACvC,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CACb,uHAAuH,CACxH,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { HttpClient, HttpMethods } from \"../interfaces.js\";\nimport type { Pipeline } from \"../pipeline.js\";\nimport { createDefaultPipeline } from \"./clientHelpers.js\";\nimport type {\n Client,\n ClientOptions,\n HttpBrowserStreamResponse,\n HttpNodeStreamResponse,\n RequestParameters,\n ResourceMethods,\n StreamableMethod,\n} from \"./common.js\";\nimport { sendRequest } from \"./sendRequest.js\";\nimport { buildRequestUrl } from \"./urlHelpers.js\";\nimport { isNodeLike } from \"#platform/env\";\n\n/**\n * Creates a client with a default pipeline\n * @param endpoint - Base endpoint for the client\n * @param credentials - Credentials to authenticate the requests\n * @param options - Client options\n */\nexport function getClient(endpoint: string, clientOptions: ClientOptions = {}): Client {\n const pipeline = clientOptions.pipeline ?? createDefaultPipeline(clientOptions);\n if (clientOptions.additionalPolicies?.length) {\n for (const { policy, position } of clientOptions.additionalPolicies) {\n // Sign happens after Retry and is commonly needed to occur\n // before policies that intercept post-retry.\n const afterPhase = position === \"perRetry\" ? \"Sign\" : undefined;\n pipeline.addPolicy(policy, {\n afterPhase,\n });\n }\n }\n\n const { allowInsecureConnection, httpClient } = clientOptions;\n const endpointUrl = clientOptions.endpoint ?? endpoint;\n const client = (path: string, ...args: Array<any>): ResourceMethods<StreamableMethod> => {\n const getUrl = (requestOptions: RequestParameters): string =>\n buildRequestUrl(endpointUrl, path, args, { allowInsecureConnection, ...requestOptions });\n\n return {\n get: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"GET\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n post: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"POST\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n put: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"PUT\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n patch: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"PATCH\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n delete: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"DELETE\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n head: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"HEAD\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n options: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"OPTIONS\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n trace: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"TRACE\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n };\n };\n\n return {\n path: client,\n pathUnchecked: client,\n pipeline,\n };\n}\n\nfunction buildOperation(\n method: HttpMethods,\n url: string,\n pipeline: Pipeline,\n options: RequestParameters,\n allowInsecureConnection?: boolean,\n httpClient?: HttpClient,\n): StreamableMethod {\n allowInsecureConnection = options.allowInsecureConnection ?? allowInsecureConnection;\n return {\n then: function (onFulfilled, onrejected) {\n return sendRequest(\n method,\n url,\n pipeline,\n { ...options, allowInsecureConnection },\n httpClient,\n ).then(onFulfilled, onrejected);\n },\n async asBrowserStream() {\n if (isNodeLike) {\n throw new Error(\n \"`asBrowserStream` is supported only in the browser environment. Use `asNodeStream` instead to obtain the response body stream. If you require a Web stream of the response in Node, consider using `Readable.toWeb` on the result of `asNodeStream`.\",\n );\n } else {\n return sendRequest(\n method,\n url,\n pipeline,\n { ...options, allowInsecureConnection, responseAsStream: true },\n httpClient,\n ) as Promise<HttpBrowserStreamResponse>;\n }\n },\n async asNodeStream() {\n if (isNodeLike) {\n return sendRequest(\n method,\n url,\n pipeline,\n { ...options, allowInsecureConnection, responseAsStream: true },\n httpClient,\n ) as Promise<HttpNodeStreamResponse>;\n } else {\n throw new Error(\n \"`isNodeStream` is not supported in the browser environment. Use `asBrowserStream` to obtain the response body stream.\",\n );\n }\n },\n };\n}\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
import { RestError } from "../restError.js";
|
|
4
4
|
import { createHttpHeaders } from "../httpHeaders.js";
|
|
5
|
-
import { stringToUint8Array } from "../util/bytesEncoding.
|
|
5
|
+
import { stringToUint8Array } from "../util/bytesEncoding-web.mjs";
|
|
6
6
|
import { isBinaryBody } from "../util/typeGuards.js";
|
|
7
7
|
/**
|
|
8
8
|
* Get value of a header in the part descriptor ignoring case
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multipart.js","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,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAC;IAC7D,MAAM,OAAO,GAAG,iBAAiB,CAAC,UAAU,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IAE5D,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,kBAAkB,EAAE,CAAC;QACvB,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,kBAAkB,CAAC,CAAC;IACzD,CAAC;IAED,MAAM,IAAI,GAAG,aAAa,CAAC,UAAU,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IAEzD,OAAO;QACL,OAAO;QACP,IAAI;KACL,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,KAAuB;IACxD,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { BodyPart, MultipartRequestBody, RawHttpHeadersInput } from \"../interfaces.js\";\nimport { RestError } from \"../restError.js\";\nimport { createHttpHeaders } from \"../httpHeaders.js\";\nimport { stringToUint8Array } from \"../util/bytesEncoding.js\";\nimport { isBinaryBody } from \"../util/typeGuards.js\";\n\n/**\n * Describes a single part in a multipart body.\n */\nexport interface PartDescriptor {\n /**\n * Content type of this part. If set, this value will be used to set the Content-Type MIME header for this part, although explicitly\n * setting the Content-Type header in the headers bag will override this value. If set to `null`, no content type will be inferred from\n * the body field. Otherwise, the value of the Content-Type MIME header will be inferred based on the type of the body.\n */\n contentType?: string | null;\n\n /**\n * The disposition type of this part (for example, \"form-data\" for parts making up a multipart/form-data request). If set, this value\n * will be used to set the Content-Disposition MIME header for this part, in addition to the `name` and `filename` properties.\n * If the `name` or `filename` properties are set while `dispositionType` is left undefined, `dispositionType` will default to \"form-data\".\n *\n * Explicitly setting the Content-Disposition header in the headers bag will override this value.\n */\n dispositionType?: string;\n\n /**\n * The field name associated with this part. This value will be used to construct the Content-Disposition header,\n * along with the `dispositionType` and `filename` properties, if the header has not been set in the `headers` bag.\n */\n name?: string;\n\n /**\n * The file name of the content if it is a file. This value will be used to construct the Content-Disposition header,\n * along with the `dispositionType` and `name` properties, if the header has not been set in the `headers` bag.\n */\n filename?: string;\n\n /**\n * The multipart headers for this part of the multipart body. Values of the Content-Type and Content-Disposition headers set in the headers bag\n * will take precedence over those computed from the request body or the contentType, dispositionType, name, and filename fields on this object.\n */\n headers?: RawHttpHeadersInput;\n\n /**\n * The body of this part of the multipart request.\n */\n body?: unknown;\n}\n\ntype MultipartBodyType = BodyPart[\"body\"];\n\ntype HeaderValue = RawHttpHeadersInput[string];\n\n/**\n * Get value of a header in the part descriptor ignoring case\n */\nfunction getHeaderValue(descriptor: PartDescriptor, headerName: string): HeaderValue | undefined {\n if (descriptor.headers) {\n const actualHeaderName = Object.keys(descriptor.headers).find(\n (x) => x.toLowerCase() === headerName.toLowerCase(),\n );\n if (actualHeaderName) {\n return descriptor.headers[actualHeaderName];\n }\n }\n\n return undefined;\n}\n\nfunction getPartContentType(descriptor: PartDescriptor): HeaderValue | undefined {\n const contentTypeHeader = getHeaderValue(descriptor, \"content-type\");\n if (contentTypeHeader) {\n return contentTypeHeader;\n }\n\n // Special value of null means content type is to be omitted\n if (descriptor.contentType === null) {\n return undefined;\n }\n\n if (descriptor.contentType) {\n return descriptor.contentType;\n }\n\n const { body } = descriptor;\n\n if (body === null || body === undefined) {\n return undefined;\n }\n\n if (typeof body === \"string\" || typeof body === \"number\" || typeof body === \"boolean\") {\n return \"text/plain; charset=UTF-8\";\n }\n\n if (body instanceof Blob) {\n return body.type || \"application/octet-stream\";\n }\n\n if (isBinaryBody(body)) {\n return \"application/octet-stream\";\n }\n\n // arbitrary non-text object -> generic JSON content type by default. We will try to JSON.stringify the body.\n return \"application/json\";\n}\n\n/**\n * Enclose value in quotes and escape special characters, for use in the Content-Disposition header\n */\nfunction escapeDispositionField(value: string): string {\n return JSON.stringify(value);\n}\n\nfunction getContentDisposition(descriptor: PartDescriptor): HeaderValue | undefined {\n const contentDispositionHeader = getHeaderValue(descriptor, \"content-disposition\");\n if (contentDispositionHeader) {\n return contentDispositionHeader;\n }\n\n if (\n descriptor.dispositionType === undefined &&\n descriptor.name === undefined &&\n descriptor.filename === undefined\n ) {\n return undefined;\n }\n\n const dispositionType = descriptor.dispositionType ?? \"form-data\";\n\n let disposition = dispositionType;\n if (descriptor.name) {\n disposition += `; name=${escapeDispositionField(descriptor.name)}`;\n }\n\n let filename: string | undefined = undefined;\n if (descriptor.filename) {\n filename = descriptor.filename;\n } else if (typeof File !== \"undefined\" && descriptor.body instanceof File) {\n const filenameFromFile = (descriptor.body as File).name;\n if (filenameFromFile !== \"\") {\n filename = filenameFromFile;\n }\n }\n\n if (filename) {\n disposition += `; filename=${escapeDispositionField(filename)}`;\n }\n\n return disposition;\n}\n\nfunction normalizeBody(body?: unknown, contentType?: HeaderValue): MultipartBodyType {\n if (body === undefined) {\n // zero-length body\n return new Uint8Array([]);\n }\n\n // binary and primitives should go straight on the wire regardless of content type\n if (isBinaryBody(body)) {\n return body;\n }\n if (typeof body === \"string\" || typeof body === \"number\" || typeof body === \"boolean\") {\n return stringToUint8Array(String(body), \"utf-8\");\n }\n\n // stringify objects for JSON-ish content types e.g. application/json, application/merge-patch+json, application/vnd.oci.manifest.v1+json, application.json; charset=UTF-8\n if (contentType && /application\\/(.+\\+)?json(;.+)?/i.test(String(contentType))) {\n return stringToUint8Array(JSON.stringify(body), \"utf-8\");\n }\n\n throw new RestError(`Unsupported body/content-type combination: ${body}, ${contentType}`);\n}\n\nexport function buildBodyPart(descriptor: PartDescriptor): BodyPart {\n const contentType = getPartContentType(descriptor);\n const contentDisposition = getContentDisposition(descriptor);\n const headers = createHttpHeaders(descriptor.headers ?? {});\n\n if (contentType) {\n headers.set(\"content-type\", contentType);\n }\n if (contentDisposition) {\n headers.set(\"content-disposition\", contentDisposition);\n }\n\n const body = normalizeBody(descriptor.body, contentType);\n\n return {\n headers,\n body,\n };\n}\n\nexport function buildMultipartBody(parts: PartDescriptor[]): MultipartRequestBody {\n return { parts: parts.map(buildBodyPart) };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"multipart.js","sourceRoot":"","sources":["../../../src/client/multipart.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAkDrD;;GAEG;AACH,SAAS,cAAc,CAAC,UAA0B,EAAE,UAAkB;IACpE,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;QACvB,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,CAC3D,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,UAAU,CAAC,WAAW,EAAE,CACpD,CAAC;QACF,IAAI,gBAAgB,EAAE,CAAC;YACrB,OAAO,UAAU,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,kBAAkB,CAAC,UAA0B;IACpD,MAAM,iBAAiB,GAAG,cAAc,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IACrE,IAAI,iBAAiB,EAAE,CAAC;QACtB,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAED,4DAA4D;IAC5D,IAAI,UAAU,CAAC,WAAW,KAAK,IAAI,EAAE,CAAC;QACpC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,UAAU,CAAC,WAAW,EAAE,C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,MAAM,IAAI,SAAS,CAAC,8CAA8C,IAAI,KAAK,WAAW,EAAE,CAAC,CAAC;AAC5F,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,UAA0B;IACtD,MAAM,WAAW,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;IACnD,MAAM,kBAAkB,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAC;IAC7D,MAAM,OAAO,GAAG,iBAAiB,CAAC,UAAU,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IAE5D,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,kBAAkB,EAAE,CAAC;QACvB,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,kBAAkB,CAAC,CAAC;IACzD,CAAC;IAED,MAAM,IAAI,GAAG,aAAa,CAAC,UAAU,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IAEzD,OAAO;QACL,OAAO;QACP,IAAI;KACL,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,KAAuB;IACxD,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { BodyPart, MultipartRequestBody, RawHttpHeadersInput } from \"../interfaces.js\";\nimport { RestError } from \"../restError.js\";\nimport { createHttpHeaders } from \"../httpHeaders.js\";\nimport { stringToUint8Array } from \"#platform/bytesEncoding\";\nimport { isBinaryBody } from \"../util/typeGuards.js\";\n\n/**\n * Describes a single part in a multipart body.\n */\nexport interface PartDescriptor {\n /**\n * Content type of this part. If set, this value will be used to set the Content-Type MIME header for this part, although explicitly\n * setting the Content-Type header in the headers bag will override this value. If set to `null`, no content type will be inferred from\n * the body field. Otherwise, the value of the Content-Type MIME header will be inferred based on the type of the body.\n */\n contentType?: string | null;\n\n /**\n * The disposition type of this part (for example, \"form-data\" for parts making up a multipart/form-data request). If set, this value\n * will be used to set the Content-Disposition MIME header for this part, in addition to the `name` and `filename` properties.\n * If the `name` or `filename` properties are set while `dispositionType` is left undefined, `dispositionType` will default to \"form-data\".\n *\n * Explicitly setting the Content-Disposition header in the headers bag will override this value.\n */\n dispositionType?: string;\n\n /**\n * The field name associated with this part. This value will be used to construct the Content-Disposition header,\n * along with the `dispositionType` and `filename` properties, if the header has not been set in the `headers` bag.\n */\n name?: string;\n\n /**\n * The file name of the content if it is a file. This value will be used to construct the Content-Disposition header,\n * along with the `dispositionType` and `name` properties, if the header has not been set in the `headers` bag.\n */\n filename?: string;\n\n /**\n * The multipart headers for this part of the multipart body. Values of the Content-Type and Content-Disposition headers set in the headers bag\n * will take precedence over those computed from the request body or the contentType, dispositionType, name, and filename fields on this object.\n */\n headers?: RawHttpHeadersInput;\n\n /**\n * The body of this part of the multipart request.\n */\n body?: unknown;\n}\n\ntype MultipartBodyType = BodyPart[\"body\"];\n\ntype HeaderValue = RawHttpHeadersInput[string];\n\n/**\n * Get value of a header in the part descriptor ignoring case\n */\nfunction getHeaderValue(descriptor: PartDescriptor, headerName: string): HeaderValue | undefined {\n if (descriptor.headers) {\n const actualHeaderName = Object.keys(descriptor.headers).find(\n (x) => x.toLowerCase() === headerName.toLowerCase(),\n );\n if (actualHeaderName) {\n return descriptor.headers[actualHeaderName];\n }\n }\n\n return undefined;\n}\n\nfunction getPartContentType(descriptor: PartDescriptor): HeaderValue | undefined {\n const contentTypeHeader = getHeaderValue(descriptor, \"content-type\");\n if (contentTypeHeader) {\n return contentTypeHeader;\n }\n\n // Special value of null means content type is to be omitted\n if (descriptor.contentType === null) {\n return undefined;\n }\n\n if (descriptor.contentType) {\n return descriptor.contentType;\n }\n\n const { body } = descriptor;\n\n if (body === null || body === undefined) {\n return undefined;\n }\n\n if (typeof body === \"string\" || typeof body === \"number\" || typeof body === \"boolean\") {\n return \"text/plain; charset=UTF-8\";\n }\n\n if (body instanceof Blob) {\n return body.type || \"application/octet-stream\";\n }\n\n if (isBinaryBody(body)) {\n return \"application/octet-stream\";\n }\n\n // arbitrary non-text object -> generic JSON content type by default. We will try to JSON.stringify the body.\n return \"application/json\";\n}\n\n/**\n * Enclose value in quotes and escape special characters, for use in the Content-Disposition header\n */\nfunction escapeDispositionField(value: string): string {\n return JSON.stringify(value);\n}\n\nfunction getContentDisposition(descriptor: PartDescriptor): HeaderValue | undefined {\n const contentDispositionHeader = getHeaderValue(descriptor, \"content-disposition\");\n if (contentDispositionHeader) {\n return contentDispositionHeader;\n }\n\n if (\n descriptor.dispositionType === undefined &&\n descriptor.name === undefined &&\n descriptor.filename === undefined\n ) {\n return undefined;\n }\n\n const dispositionType = descriptor.dispositionType ?? \"form-data\";\n\n let disposition = dispositionType;\n if (descriptor.name) {\n disposition += `; name=${escapeDispositionField(descriptor.name)}`;\n }\n\n let filename: string | undefined = undefined;\n if (descriptor.filename) {\n filename = descriptor.filename;\n } else if (typeof File !== \"undefined\" && descriptor.body instanceof File) {\n const filenameFromFile = descriptor.body.name;\n if (filenameFromFile !== \"\") {\n filename = filenameFromFile;\n }\n }\n\n if (filename) {\n disposition += `; filename=${escapeDispositionField(filename)}`;\n }\n\n return disposition;\n}\n\nfunction normalizeBody(body?: unknown, contentType?: HeaderValue): MultipartBodyType {\n if (body === undefined) {\n // zero-length body\n return new Uint8Array([]);\n }\n\n // binary and primitives should go straight on the wire regardless of content type\n if (isBinaryBody(body)) {\n return body;\n }\n if (typeof body === \"string\" || typeof body === \"number\" || typeof body === \"boolean\") {\n return stringToUint8Array(String(body), \"utf-8\");\n }\n\n // stringify objects for JSON-ish content types e.g. application/json, application/merge-patch+json, application/vnd.oci.manifest.v1+json, application.json; charset=UTF-8\n if (contentType && /application\\/(.+\\+)?json(;.+)?/i.test(String(contentType))) {\n return stringToUint8Array(JSON.stringify(body), \"utf-8\");\n }\n\n throw new RestError(`Unsupported body/content-type combination: ${body}, ${contentType}`);\n}\n\nexport function buildBodyPart(descriptor: PartDescriptor): BodyPart {\n const contentType = getPartContentType(descriptor);\n const contentDisposition = getContentDisposition(descriptor);\n const headers = createHttpHeaders(descriptor.headers ?? {});\n\n if (contentType) {\n headers.set(\"content-type\", contentType);\n }\n if (contentDisposition) {\n headers.set(\"content-disposition\", contentDisposition);\n }\n\n const body = normalizeBody(descriptor.body, contentType);\n\n return {\n headers,\n body,\n };\n}\n\nexport function buildMultipartBody(parts: PartDescriptor[]): MultipartRequestBody {\n return { parts: parts.map(buildBodyPart) };\n}\n"]}
|
|
@@ -15,11 +15,12 @@ export function createRestError(messageOrResponse, response) {
|
|
|
15
15
|
response: toPipelineResponse(resp),
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
|
-
function toPipelineResponse(
|
|
18
|
+
function toPipelineResponse(errorResponse) {
|
|
19
19
|
return {
|
|
20
|
-
headers: createHttpHeaders(
|
|
21
|
-
request:
|
|
22
|
-
status: statusCodeToNumber(
|
|
20
|
+
headers: createHttpHeaders(errorResponse.headers),
|
|
21
|
+
request: errorResponse.request,
|
|
22
|
+
status: statusCodeToNumber(errorResponse.status) ?? -1,
|
|
23
|
+
...(typeof errorResponse.body === "string" ? { bodyAsText: errorResponse.body } : {}),
|
|
23
24
|
};
|
|
24
25
|
}
|
|
25
26
|
function statusCodeToNumber(statusCode) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restError.js","sourceRoot":"","sources":["../../../src/client/restError.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAWtD,MAAM,UAAU,eAAe,CAC7B,iBAAiD,EACjD,QAAgC;IAEhC,MAAM,IAAI,GAAG,OAAO,iBAAiB,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAS,CAAC,CAAC,CAAC,iBAAiB,CAAC;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C,IAAI,CAAC,MAAM,CAAC;QAC3C,IAAI,EAAE,aAAa,EAAE,IAAI;QACzB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,QAAQ,EAAE,kBAAkB,CAAC,IAAI,CAAC;KACnC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,kBAAkB,CAAC,aAAoC;IAC9D,OAAO;QACL,OAAO,EAAE,iBAAiB,CAAC,aAAa,CAAC,OAAO,CAAC;QACjD,OAAO,EAAE,aAAa,CAAC,OAAO;QAC9B,MAAM,EAAE,kBAAkB,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACtD,GAAG,CAAC,OAAO,aAAa,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACtF,CAAC;AACJ,CAAC;AAED,SAAS,kBAAkB,CAAC,UAAkB;IAC5C,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAE3C,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;AACnD,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PipelineResponse } from \"../interfaces.js\";\nimport { RestError } from \"../restError.js\";\nimport { createHttpHeaders } from \"../httpHeaders.js\";\nimport type { PathUncheckedResponse } from \"./common.js\";\n\n/**\n * Creates a rest error from a PathUnchecked response\n */\nexport function createRestError(response: PathUncheckedResponse): RestError;\n/**\n * Creates a rest error from an error message and a PathUnchecked response\n */\nexport function createRestError(message: string, response: PathUncheckedResponse): RestError;\nexport function createRestError(\n messageOrResponse: string | PathUncheckedResponse,\n response?: PathUncheckedResponse,\n): RestError {\n const resp = typeof messageOrResponse === \"string\" ? response! : messageOrResponse;\n const internalError = resp.body?.error ?? resp.body;\n const message =\n typeof messageOrResponse === \"string\"\n ? messageOrResponse\n : (internalError?.message ?? `Unexpected status code: ${resp.status}`);\n return new RestError(message, {\n statusCode: statusCodeToNumber(resp.status),\n code: internalError?.code,\n request: resp.request,\n response: toPipelineResponse(resp),\n });\n}\n\nfunction toPipelineResponse(errorResponse: PathUncheckedResponse): PipelineResponse {\n return {\n headers: createHttpHeaders(errorResponse.headers),\n request: errorResponse.request,\n status: statusCodeToNumber(errorResponse.status) ?? -1,\n ...(typeof errorResponse.body === \"string\" ? { bodyAsText: errorResponse.body } : {}),\n };\n}\n\nfunction statusCodeToNumber(statusCode: string): number | undefined {\n const status = Number.parseInt(statusCode);\n\n return Number.isNaN(status) ? undefined : status;\n}\n"]}
|
|
@@ -50,9 +50,14 @@ export async function sendRequest(method, url, pipeline, options = {}, customHtt
|
|
|
50
50
|
* @returns returns the content-type
|
|
51
51
|
*/
|
|
52
52
|
function getRequestContentType(options = {}) {
|
|
53
|
-
|
|
54
|
-
options.
|
|
55
|
-
|
|
53
|
+
if (options.contentType) {
|
|
54
|
+
return options.contentType;
|
|
55
|
+
}
|
|
56
|
+
const headerContentType = options.headers?.["content-type"];
|
|
57
|
+
if (typeof headerContentType === "string") {
|
|
58
|
+
return headerContentType;
|
|
59
|
+
}
|
|
60
|
+
return getContentType(options.body);
|
|
56
61
|
}
|
|
57
62
|
/**
|
|
58
63
|
* Function to determine the content-type of a body
|
|
@@ -93,22 +98,23 @@ function buildPipelineRequest(method, url, options = {}) {
|
|
|
93
98
|
"content-type": requestContentType,
|
|
94
99
|
}),
|
|
95
100
|
});
|
|
96
|
-
|
|
101
|
+
const { allowInsecureConnection, abortSignal, onUploadProgress, onDownloadProgress, timeout, responseAsStream, url: _url, method: _method, body: _body, multipartBody: _multiBody, headers: _headers, ...rest } = options;
|
|
102
|
+
const request = createPipelineRequest({
|
|
97
103
|
url,
|
|
98
104
|
method,
|
|
99
105
|
body,
|
|
100
106
|
multipartBody,
|
|
101
107
|
headers,
|
|
102
|
-
allowInsecureConnection
|
|
103
|
-
abortSignal
|
|
104
|
-
onUploadProgress
|
|
105
|
-
onDownloadProgress
|
|
106
|
-
timeout
|
|
108
|
+
allowInsecureConnection,
|
|
109
|
+
abortSignal,
|
|
110
|
+
onUploadProgress,
|
|
111
|
+
onDownloadProgress,
|
|
112
|
+
timeout,
|
|
107
113
|
enableBrowserStreams: true,
|
|
108
|
-
streamResponseStatusCodes:
|
|
109
|
-
? new Set([Number.POSITIVE_INFINITY])
|
|
110
|
-
: undefined,
|
|
114
|
+
streamResponseStatusCodes: responseAsStream ? new Set([Number.POSITIVE_INFINITY]) : undefined,
|
|
111
115
|
});
|
|
116
|
+
Object.assign(request, rest);
|
|
117
|
+
return request;
|
|
112
118
|
}
|
|
113
119
|
/**
|
|
114
120
|
* Prepares the body before sending the request
|
|
@@ -123,11 +129,16 @@ export function getRequestBody(body, contentType = "") {
|
|
|
123
129
|
if (isBlob(body)) {
|
|
124
130
|
return { body };
|
|
125
131
|
}
|
|
126
|
-
if (isReadableStream(body)
|
|
132
|
+
if (isReadableStream(body)) {
|
|
127
133
|
return { body };
|
|
128
134
|
}
|
|
135
|
+
if (typeof body === "function") {
|
|
136
|
+
return { body: body };
|
|
137
|
+
}
|
|
129
138
|
if (ArrayBuffer.isView(body)) {
|
|
130
|
-
return {
|
|
139
|
+
return {
|
|
140
|
+
body: body instanceof Uint8Array ? body : JSON.stringify(body),
|
|
141
|
+
};
|
|
131
142
|
}
|
|
132
143
|
const firstType = contentType.split(";")[0];
|
|
133
144
|
switch (firstType) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendRequest.js","sourceRoot":"","sources":["../../../src/client/sendRequest.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE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esContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpClient,\n HttpMethods,\n MultipartRequestBody,\n PipelineRequest,\n PipelineResponse,\n RequestBodyType,\n} from \"../interfaces.js\";\nimport { isRestError, RestError } from \"../restError.js\";\nimport type { Pipeline } from \"../pipeline.js\";\nimport { createHttpHeaders } from \"../httpHeaders.js\";\nimport { createPipelineRequest } from \"../pipelineRequest.js\";\nimport { getCachedDefaultHttpsClient } from \"./clientHelpers.js\";\nimport { isBlob, isReadableStream } from \"../util/typeGuards.js\";\nimport type { HttpResponse, RequestParameters } from \"./common.js\";\nimport type { PartDescriptor } from \"./multipart.js\";\nimport { buildMultipartBody } from \"./multipart.js\";\n\n/**\n * Helper function to send request used by the client\n * @param method - method to use to send the request\n * @param url - url to send the request to\n * @param pipeline - pipeline with the policies to run when sending the request\n * @param options - request options\n * @param customHttpClient - a custom HttpClient to use when making the request\n * @returns returns and HttpResponse\n */\nexport async function sendRequest(\n method: HttpMethods,\n url: string,\n pipeline: Pipeline,\n options: InternalRequestParameters = {},\n customHttpClient?: HttpClient,\n): Promise<HttpResponse> {\n const httpClient = customHttpClient ?? getCachedDefaultHttpsClient();\n const request = buildPipelineRequest(method, url, options);\n\n try {\n const response = await pipeline.sendRequest(httpClient, request);\n const headers = response.headers.toJSON();\n const stream = response.readableStreamBody ?? response.browserStreamBody;\n const parsedBody =\n options.responseAsStream || stream !== undefined ? undefined : getResponseBody(response);\n const body = stream ?? parsedBody;\n\n if (options?.onResponse) {\n options.onResponse({ ...response, request, rawHeaders: headers, parsedBody });\n }\n\n return {\n request,\n headers,\n status: `${response.status}`,\n body,\n };\n } catch (e: unknown) {\n if (isRestError(e) && e.response && options.onResponse) {\n const { response } = e;\n const rawHeaders = response.headers.toJSON();\n // UNBRANDED DIFFERENCE: onResponse callback does not have a second __legacyError property\n options?.onResponse({ ...response, request, rawHeaders }, e);\n }\n\n throw e;\n }\n}\n\n/**\n * Function to determine the request content type\n * @param options - request options InternalRequestParameters\n * @returns returns the content-type\n */\nfunction getRequestContentType(options: InternalRequestParameters = {}): string | undefined {\n return (\n options.contentType ??\n (options.headers?.[\"content-type\"] as string) ??\n getContentType(options.body)\n );\n}\n\n/**\n * Function to determine the content-type of a body\n * this is used if an explicit content-type is not provided\n * @param body - body in the request\n * @returns returns the content-type\n */\nfunction getContentType(body: any): string | undefined {\n if (body === undefined) {\n return undefined;\n }\n\n if (ArrayBuffer.isView(body)) {\n return \"application/octet-stream\";\n }\n\n if (isBlob(body) && body.type) {\n return body.type;\n }\n\n if (typeof body === \"string\") {\n try {\n JSON.parse(body);\n return \"application/json\";\n } catch (error: any) {\n // If we fail to parse the body, it is not json\n return undefined;\n }\n }\n // By default return json\n return \"application/json\";\n}\n\nexport interface InternalRequestParameters extends RequestParameters {\n responseAsStream?: boolean;\n}\n\nfunction buildPipelineRequest(\n method: HttpMethods,\n url: string,\n options: InternalRequestParameters = {},\n): PipelineRequest {\n const requestContentType = getRequestContentType(options);\n const { body, multipartBody } = getRequestBody(options.body, requestContentType);\n\n const headers = createHttpHeaders({\n ...(options.headers ? options.headers : {}),\n accept: options.accept ?? options.headers?.accept ?? \"application/json\",\n ...(requestContentType && {\n \"content-type\": requestContentType,\n }),\n });\n\n return createPipelineRequest({\n url,\n method,\n body,\n multipartBody,\n headers,\n allowInsecureConnection: options.allowInsecureConnection,\n abortSignal: options.abortSignal,\n onUploadProgress: options.onUploadProgress,\n onDownloadProgress: options.onDownloadProgress,\n timeout: options.timeout,\n enableBrowserStreams: true,\n streamResponseStatusCodes: options.responseAsStream\n ? new Set([Number.POSITIVE_INFINITY])\n : undefined,\n });\n}\n\ninterface RequestBody {\n body?: RequestBodyType;\n multipartBody?: MultipartRequestBody;\n}\n\n/**\n * Prepares the body before sending the request\n */\nexport function getRequestBody(body?: unknown, contentType: string = \"\"): RequestBody {\n if (body === undefined) {\n return { body: undefined };\n }\n\n if (typeof FormData !== \"undefined\" && body instanceof FormData) {\n return { body };\n }\n\n if (isBlob(body)) {\n return { body };\n }\n\n if (isReadableStream(body) || typeof body === \"function\") {\n return { body } as RequestBody;\n }\n\n if (ArrayBuffer.isView(body)) {\n return { body: body instanceof Uint8Array ? body : JSON.stringify(body) };\n }\n\n const firstType = contentType.split(\";\")[0];\n\n switch (firstType) {\n case \"application/json\":\n return { body: JSON.stringify(body) };\n case \"multipart/form-data\":\n if (Array.isArray(body)) {\n return { multipartBody: buildMultipartBody(body as PartDescriptor[]) };\n }\n return { body: JSON.stringify(body) };\n case \"text/plain\":\n return { body: String(body) };\n default:\n if (typeof body === \"string\") {\n return { body };\n }\n return { body: JSON.stringify(body) };\n }\n}\n\n/**\n * Prepares the response body\n */\nfunction getResponseBody(response: PipelineResponse): RequestBodyType | undefined {\n // Set the default response type\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n const firstType = contentType.split(\";\")[0];\n const bodyToParse = response.bodyAsText ?? \"\";\n\n if (firstType === \"text/plain\") {\n return String(bodyToParse);\n }\n // Default to \"application/json\" and fallback to string;\n try {\n return bodyToParse ? JSON.parse(bodyToParse) : undefined;\n } catch (error: any) {\n // If we were supposed to get a JSON object and failed to\n // parse, throw a parse error\n if (firstType === \"application/json\") {\n throw createParseError(response, error);\n }\n\n // We are not sure how to handle the response so we return it as\n // plain text.\n return String(bodyToParse);\n }\n}\n\nfunction createParseError(response: PipelineResponse, err: any): RestError {\n const msg = `Error \"${err}\" occurred while parsing the response body - ${response.bodyAsText}.`;\n const errCode = err.code ?? RestError.PARSE_ERROR;\n return new RestError(msg, {\n code: errCode,\n statusCode: response.status,\n request: response.request,\n response: response,\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sendRequest.js","sourceRoot":"","sources":["../../../src/client/sendRequest.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC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AAC;QAED,gEAAgE;QAChE,cAAc;QACd,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,QAA0B,EAAE,GAAQ;IAC5D,MAAM,GAAG,GAAG,UAAU,GAAG,gDAAgD,QAAQ,CAAC,UAAU,GAAG,CAAC;IAChG,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,IAAI,SAAS,CAAC,WAAW,CAAC;IAClD,OAAO,IAAI,SAAS,CAAC,GAAG,EAAE;QACxB,IAAI,EAAE,OAAO;QACb,UAAU,EAAE,QAAQ,CAAC,MAAM;QAC3B,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,QAAQ,EAAE,QAAQ;KACnB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpClient,\n HttpMethods,\n MultipartRequestBody,\n PipelineRequest,\n PipelineResponse,\n RequestBodyType,\n} from \"../interfaces.js\";\nimport { isRestError, RestError } from \"../restError.js\";\nimport type { Pipeline } from \"../pipeline.js\";\nimport { createHttpHeaders } from \"../httpHeaders.js\";\nimport { createPipelineRequest } from \"../pipelineRequest.js\";\nimport { getCachedDefaultHttpsClient } from \"./clientHelpers.js\";\nimport { isBlob, isReadableStream } from \"../util/typeGuards.js\";\nimport type { HttpResponse, RequestParameters } from \"./common.js\";\nimport type { PartDescriptor } from \"./multipart.js\";\nimport { buildMultipartBody } from \"./multipart.js\";\n\n/**\n * Helper function to send request used by the client\n * @param method - method to use to send the request\n * @param url - url to send the request to\n * @param pipeline - pipeline with the policies to run when sending the request\n * @param options - request options\n * @param customHttpClient - a custom HttpClient to use when making the request\n * @returns returns and HttpResponse\n */\nexport async function sendRequest(\n method: HttpMethods,\n url: string,\n pipeline: Pipeline,\n options: InternalRequestParameters = {},\n customHttpClient?: HttpClient,\n): Promise<HttpResponse> {\n const httpClient = customHttpClient ?? getCachedDefaultHttpsClient();\n const request = buildPipelineRequest(method, url, options);\n\n try {\n const response = await pipeline.sendRequest(httpClient, request);\n const headers = response.headers.toJSON();\n const stream = response.readableStreamBody ?? response.browserStreamBody;\n const parsedBody =\n options.responseAsStream || stream !== undefined ? undefined : getResponseBody(response);\n const body = stream ?? parsedBody;\n\n if (options?.onResponse) {\n options.onResponse({ ...response, request, rawHeaders: headers, parsedBody });\n }\n\n return {\n request,\n headers,\n status: `${response.status}`,\n body,\n };\n } catch (e: unknown) {\n if (isRestError(e) && e.response && options.onResponse) {\n const { response } = e;\n const rawHeaders = response.headers.toJSON();\n // UNBRANDED DIFFERENCE: onResponse callback does not have a second __legacyError property\n options?.onResponse({ ...response, request, rawHeaders }, e);\n }\n\n throw e;\n }\n}\n\n/**\n * Function to determine the request content type\n * @param options - request options InternalRequestParameters\n * @returns returns the content-type\n */\nfunction getRequestContentType(options: InternalRequestParameters = {}): string | undefined {\n if (options.contentType) {\n return options.contentType;\n }\n const headerContentType = options.headers?.[\"content-type\"];\n if (typeof headerContentType === \"string\") {\n return headerContentType;\n }\n return getContentType(options.body);\n}\n\n/**\n * Function to determine the content-type of a body\n * this is used if an explicit content-type is not provided\n * @param body - body in the request\n * @returns returns the content-type\n */\nfunction getContentType(body: any): string | undefined {\n if (body === undefined) {\n return undefined;\n }\n\n if (ArrayBuffer.isView(body)) {\n return \"application/octet-stream\";\n }\n\n if (isBlob(body) && body.type) {\n return body.type;\n }\n\n if (typeof body === \"string\") {\n try {\n JSON.parse(body);\n return \"application/json\";\n } catch (error: any) {\n // If we fail to parse the body, it is not json\n return undefined;\n }\n }\n // By default return json\n return \"application/json\";\n}\n\nexport interface InternalRequestParameters extends RequestParameters {\n responseAsStream?: boolean;\n}\n\nfunction buildPipelineRequest(\n method: HttpMethods,\n url: string,\n options: InternalRequestParameters = {},\n): PipelineRequest {\n const requestContentType = getRequestContentType(options);\n const { body, multipartBody } = getRequestBody(options.body, requestContentType);\n\n const headers = createHttpHeaders({\n ...(options.headers ? options.headers : {}),\n accept: options.accept ?? options.headers?.accept ?? \"application/json\",\n ...(requestContentType && {\n \"content-type\": requestContentType,\n }),\n });\n\n const {\n allowInsecureConnection,\n abortSignal,\n onUploadProgress,\n onDownloadProgress,\n timeout,\n responseAsStream,\n url: _url,\n method: _method,\n body: _body,\n multipartBody: _multiBody,\n headers: _headers,\n ...rest\n } = options as InternalRequestParameters & {\n url: string;\n method: string;\n multipartBody: unknown;\n };\n\n const request = createPipelineRequest({\n url,\n method,\n body,\n multipartBody,\n headers,\n allowInsecureConnection,\n abortSignal,\n onUploadProgress,\n onDownloadProgress,\n timeout,\n enableBrowserStreams: true,\n streamResponseStatusCodes: responseAsStream ? new Set([Number.POSITIVE_INFINITY]) : undefined,\n });\n\n Object.assign(request, rest);\n return request;\n}\n\ninterface RequestBody {\n body?: RequestBodyType;\n multipartBody?: MultipartRequestBody;\n}\n\n/**\n * Prepares the body before sending the request\n */\nexport function getRequestBody(body?: unknown, contentType: string = \"\"): RequestBody {\n if (body === undefined) {\n return { body: undefined };\n }\n\n if (typeof FormData !== \"undefined\" && body instanceof FormData) {\n return { body };\n }\n\n if (isBlob(body)) {\n return { body };\n }\n\n if (isReadableStream(body)) {\n return { body };\n }\n\n if (typeof body === \"function\") {\n return { body: body as RequestBodyType };\n }\n\n if (ArrayBuffer.isView(body)) {\n return {\n body: body instanceof Uint8Array ? body : JSON.stringify(body),\n };\n }\n\n const firstType = contentType.split(\";\")[0];\n\n switch (firstType) {\n case \"application/json\":\n return { body: JSON.stringify(body) };\n case \"multipart/form-data\":\n if (Array.isArray(body)) {\n return { multipartBody: buildMultipartBody(body as unknown as PartDescriptor[]) };\n }\n return { body: JSON.stringify(body) };\n case \"text/plain\":\n return { body: String(body) };\n default:\n if (typeof body === \"string\") {\n return { body };\n }\n return { body: JSON.stringify(body) };\n }\n}\n\n/**\n * Prepares the response body\n */\nfunction getResponseBody(response: PipelineResponse): RequestBodyType | undefined {\n // Set the default response type\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n const firstType = contentType.split(\";\")[0];\n const bodyToParse = response.bodyAsText ?? \"\";\n\n if (firstType === \"text/plain\") {\n return String(bodyToParse);\n }\n // Default to \"application/json\" and fallback to string;\n try {\n return bodyToParse ? JSON.parse(bodyToParse) : undefined;\n } catch (error: any) {\n // If we were supposed to get a JSON object and failed to\n // parse, throw a parse error\n if (firstType === \"application/json\") {\n throw createParseError(response, error);\n }\n\n // We are not sure how to handle the response so we return it as\n // plain text.\n return String(bodyToParse);\n }\n}\n\nfunction createParseError(response: PipelineResponse, err: any): RestError {\n const msg = `Error \"${err}\" occurred while parsing the response body - ${response.bodyAsText}.`;\n const errCode = err.code ?? RestError.PARSE_ERROR;\n return new RestError(msg, {\n code: errCode,\n statusCode: response.status,\n request: response.request,\n response: response,\n });\n}\n"]}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
function isQueryParameterWithOptions(x) {
|
|
4
|
+
if (typeof x !== "object" || x === null || !Object.hasOwn(x, "value")) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
4
7
|
const value = x.value;
|
|
5
|
-
return
|
|
8
|
+
return typeof value?.toString === "function";
|
|
6
9
|
}
|
|
7
10
|
/**
|
|
8
11
|
* Builds the request url, filling in query and path parameters
|
|
@@ -38,7 +41,10 @@ function appendPath(endpoint, pathToAppend) {
|
|
|
38
41
|
const combinedSearch = [endpointParts[1], pathParts[1].replaceAll("?", "&")]
|
|
39
42
|
.filter(Boolean)
|
|
40
43
|
.join("&");
|
|
41
|
-
|
|
44
|
+
// Replace consecutive forward slashes with a single forward slash, but only for the part right after the host in the endpoint.
|
|
45
|
+
// This is to maintain compatibility with old behavior for cases where the endpoint has been provided with extra forward slashes,
|
|
46
|
+
// while still allowing for intentional consecutive forward slashes in the path to be preserved.
|
|
47
|
+
const baseEndpoint = endpointParts[0].replace(/(^[^:]+:\/\/[^/]+)\/\/+/, "$1/");
|
|
42
48
|
const basePathToAppend = pathParts[0];
|
|
43
49
|
let combinedUrl = baseEndpoint;
|
|
44
50
|
if (!baseEndpoint.endsWith("/") && !basePathToAppend.startsWith("/") && basePathToAppend !== "") {
|
|
@@ -149,7 +155,7 @@ export function appendQueryParams(url, options = {}) {
|
|
|
149
155
|
newParamStrings.push(getQueryParamValue(key, options.skipUrlEncoding ?? false, style, item));
|
|
150
156
|
}
|
|
151
157
|
}
|
|
152
|
-
else if (typeof rawValue === "object") {
|
|
158
|
+
else if (rawValue !== null && typeof rawValue === "object") {
|
|
153
159
|
// For object explode, the name of the query parameter is ignored and we use the object key instead
|
|
154
160
|
for (const [actualKey, value] of Object.entries(rawValue)) {
|
|
155
161
|
newParamStrings.push(getQueryParamValue(actualKey, options.skipUrlEncoding ?? false, style, value));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlHelpers.js","sourceRoot":"","sources":["../../../src/client/urlHelpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAqClC,SAAS,2BAA2B,CAAC,CAAU;IAC7C,MAAM,KAAK,GAAI,CAA+B,CAAC,KAAY,CAAC;IAC5D,OAAO,CACL,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,IAAI,OAAO,KAAK,CAAC,QAAQ,KAAK,UAAU,CAC5F,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAC7B,QAAgB,EAChB,SAAiB,EACjB,cAA8D,EAC9D,UAA6B,EAAE;IAE/B,IAAI,SAAS,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QACxE,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,QAAQ,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3C,qBAAqB;IACrB,sCAAsC;IACtC,mHAAmH;IACnH,wGAAwG;IACxG,MAA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;AAC5F,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PathParameterWithOptions, RequestParameters } from \"./common.js\";\n\ntype QueryParameterStyle = \"form\" | \"spaceDelimited\" | \"pipeDelimited\";\n\n/**\n * An object that can be passed as a query parameter, allowing for additional options to be set relating to how the parameter is encoded.\n */\ninterface QueryParameterWithOptions {\n /**\n * The value of the query parameter.\n */\n value: unknown;\n\n /**\n * If set to true, value must be an array. Setting this option to true will cause the array to be encoded as multiple query parameters.\n * Setting it to false will cause the array values to be encoded as a single query parameter, with each value separated by a comma ','.\n *\n * For example, with `explode` set to true, a query parameter named \"foo\" with value [\"a\", \"b\", \"c\"] will be encoded as foo=a&foo=b&foo=c.\n * If `explode` was set to false, the same example would instead be encouded as foo=a,b,c.\n *\n * Defaults to false.\n */\n explode?: boolean;\n\n /**\n * Style for encoding arrays. Three possible values:\n * - \"form\": array values will be separated by a comma \",\" in the query parameter value.\n * - \"spaceDelimited\": array values will be separated by a space (\" \", url-encoded to \"%20\").\n * - \"pipeDelimited\": array values will be separated by a pipe (\"|\").\n *\n * Defaults to \"form\".\n */\n style?: QueryParameterStyle;\n}\n\nfunction isQueryParameterWithOptions(x: unknown): x is QueryParameterWithOptions {\n const value = (x as QueryParameterWithOptions).value as any;\n return (\n value !== undefined && value.toString !== undefined && typeof value.toString === \"function\"\n );\n}\n\n/**\n * Builds the request url, filling in query and path parameters\n * @param endpoint - base url which can be a template url\n * @param routePath - path to append to the endpoint\n * @param pathParameters - values of the path parameters\n * @param options - request parameters including query parameters\n * @returns a full url with path and query parameters\n */\nexport function buildRequestUrl(\n endpoint: string,\n routePath: string,\n pathParameters: (string | number | PathParameterWithOptions)[],\n options: RequestParameters = {},\n): string {\n if (routePath.startsWith(\"https://\") || routePath.startsWith(\"http://\")) {\n return routePath;\n }\n endpoint = buildBaseUrl(endpoint, options);\n // the route could be\n // 1. a path: \"container123/blob456\"\n // 2. a component string from template which starts with \"?\" and may contain more \"?\" after template is expanded,\n // e.g., \"?restype=container&comp=blobs?where=key177196556777405927%3D%27val1177196556777407626%27\"\n const updatedRoutePath = buildRoutePath(routePath, pathParameters, options);\n\n const requestUrl = appendQueryParams(appendPath(endpoint, updatedRoutePath), options);\n const url = new URL(requestUrl);\n\n return url.toString();\n}\n\nfunction appendPath(endpoint: string, pathToAppend: string): string {\n const endpointSearchStart = endpoint.indexOf(\"?\");\n const pathSearchStart = pathToAppend.indexOf(\"?\");\n const endpointParts =\n endpointSearchStart !== -1\n ? [endpoint.substring(0, endpointSearchStart), endpoint.substring(endpointSearchStart + 1)]\n : [endpoint, \"\"];\n const pathParts =\n pathSearchStart !== -1\n ? [pathToAppend.substring(0, pathSearchStart), pathToAppend.substring(pathSearchStart + 1)]\n : [pathToAppend, \"\"];\n\n const combinedSearch = [endpointParts[1], pathParts[1].replaceAll(\"?\", \"&\")]\n .filter(Boolean)\n .join(\"&\");\n const baseEndpoint = endpointParts[0];\n const basePathToAppend = pathParts[0];\n\n let combinedUrl = baseEndpoint;\n if (!baseEndpoint.endsWith(\"/\") && !basePathToAppend.startsWith(\"/\") && basePathToAppend !== \"\") {\n combinedUrl += `/${basePathToAppend}`;\n } else if (baseEndpoint.endsWith(\"/\") && basePathToAppend.startsWith(\"/\")) {\n combinedUrl += basePathToAppend.substring(1);\n } else {\n combinedUrl += basePathToAppend;\n }\n\n if (combinedSearch) {\n combinedUrl += `?${combinedSearch}`;\n }\n\n return combinedUrl;\n}\n\nfunction getQueryParamValue(\n key: string,\n allowReserved: boolean,\n style: QueryParameterStyle,\n param: any,\n): string {\n let separator: string;\n if (style === \"pipeDelimited\") {\n separator = \"|\";\n } else if (style === \"spaceDelimited\") {\n separator = \"%20\";\n } else {\n separator = \",\";\n }\n\n let paramValues: any[];\n if (Array.isArray(param)) {\n paramValues = param;\n } else if (typeof param === \"object\" && param.toString === Object.prototype.toString) {\n // If the parameter is an object without a custom toString implementation (e.g. a Date),\n // then we should deconstruct the object into an array [key1, value1, key2, value2, ...].\n paramValues = Object.entries(param).flat();\n } else {\n paramValues = [param];\n }\n\n const value = paramValues\n .map((p) => {\n if (p === null || p === undefined) {\n return \"\";\n }\n\n if (!p.toString || typeof p.toString !== \"function\") {\n throw new Error(`Query parameters must be able to be represented as string, ${key} can't`);\n }\n\n const rawValue = p.toISOString !== undefined ? p.toISOString() : p.toString();\n return allowReserved ? rawValue : encodeURIComponent(rawValue);\n })\n .join(separator);\n\n return `${allowReserved ? key : encodeURIComponent(key)}=${value}`;\n}\n\n/**\n * Parses a query string into a map of key/value pairs without decoding the values.\n * This avoids the issue where `URL.searchParams` would decode values, potentially\n * corrupting already-encoded values such as SAS signatures.\n */\nfunction simpleParseQueryParams(queryString: string): Map<string, string | string[]> {\n const result = new Map<string, string | string[]>();\n if (!queryString || queryString[0] !== \"?\") {\n return result;\n }\n\n // remove the leading ?\n queryString = queryString.slice(1);\n const pairs = queryString.split(\"&\");\n\n for (const pair of pairs) {\n const eqIndex = pair.indexOf(\"=\");\n const name = eqIndex === -1 ? pair : pair.substring(0, eqIndex);\n const value = eqIndex === -1 ? \"\" : pair.substring(eqIndex + 1);\n\n const existingValue = result.get(name);\n if (existingValue !== undefined) {\n if (Array.isArray(existingValue)) {\n existingValue.push(value);\n } else {\n result.set(name, [existingValue, value]);\n }\n } else {\n result.set(name, value);\n }\n }\n\n return result;\n}\n\n/** @internal */\nexport function appendQueryParams(url: string, options: RequestParameters = {}): string {\n if (!options.queryParameters) {\n return url;\n }\n const parsedUrl = new URL(url);\n const queryParams = options.queryParameters;\n\n // Parse existing query params from the URL manually to avoid re-encoding issues\n const existingParams = simpleParseQueryParams(parsedUrl.search);\n\n const newParamStrings: string[] = [];\n for (const key of Object.keys(queryParams)) {\n const param = queryParams[key] as any;\n if (param === undefined || param === null) {\n continue;\n }\n\n const hasMetadata = isQueryParameterWithOptions(param);\n const rawValue = hasMetadata ? param.value : param;\n const explode = hasMetadata ? (param.explode ?? false) : false;\n const style = hasMetadata && param.style ? param.style : \"form\";\n\n if (explode) {\n if (Array.isArray(rawValue)) {\n for (const item of rawValue) {\n newParamStrings.push(\n getQueryParamValue(key, options.skipUrlEncoding ?? false, style, item),\n );\n }\n } else if (typeof rawValue === \"object\") {\n // For object explode, the name of the query parameter is ignored and we use the object key instead\n for (const [actualKey, value] of Object.entries(rawValue)) {\n newParamStrings.push(\n getQueryParamValue(actualKey, options.skipUrlEncoding ?? false, style, value),\n );\n }\n } else {\n // Explode doesn't really make sense for primitives\n throw new Error(\"explode can only be set to true for objects and arrays\");\n }\n } else {\n newParamStrings.push(\n getQueryParamValue(key, options.skipUrlEncoding ?? false, style, rawValue),\n );\n }\n }\n\n // Merge new params into existing params, deduplicating values for the same key\n for (const paramString of newParamStrings) {\n const eqIndex = paramString.indexOf(\"=\");\n const name = paramString.substring(0, eqIndex);\n const value = paramString.substring(eqIndex + 1);\n\n const existingValue = existingParams.get(name);\n if (existingValue !== undefined) {\n if (Array.isArray(existingValue)) {\n if (!existingValue.includes(value)) {\n existingValue.push(value);\n }\n } else if (existingValue !== value) {\n existingParams.set(name, [existingValue, value]);\n }\n // if existingValue === value (single string match), no change needed\n } else {\n existingParams.set(name, value);\n }\n }\n\n // Reconstruct the search string manually to avoid URL re-encoding\n const searchPieces: string[] = [];\n for (const [name, value] of existingParams) {\n if (Array.isArray(value)) {\n for (const subValue of value) {\n searchPieces.push(`${name}=${subValue}`);\n }\n } else {\n searchPieces.push(`${name}=${value}`);\n }\n }\n\n parsedUrl.search = searchPieces.length ? `?${searchPieces.join(\"&\")}` : \"\";\n return parsedUrl.toString();\n}\n\nexport function buildBaseUrl(endpoint: string, options: RequestParameters): string {\n if (!options.pathParameters) {\n return endpoint;\n }\n const pathParams = options.pathParameters;\n for (const [key, param] of Object.entries(pathParams)) {\n if (param === undefined || param === null) {\n throw new Error(`Path parameters ${key} must not be undefined or null`);\n }\n if (!param.toString || typeof param.toString !== \"function\") {\n throw new Error(`Path parameters must be able to be represented as string, ${key} can't`);\n }\n let value = param.toISOString !== undefined ? param.toISOString() : String(param);\n if (!options.skipUrlEncoding) {\n value = encodeURIComponent(param);\n }\n endpoint = replaceAll(endpoint, `{${key}}`, value) ?? \"\";\n }\n return endpoint;\n}\n\nfunction buildRoutePath(\n routePath: string,\n pathParameters: (string | number | PathParameterWithOptions)[],\n options: RequestParameters = {},\n): string {\n for (const pathParam of pathParameters) {\n const allowReserved = typeof pathParam === \"object\" && (pathParam.allowReserved ?? false);\n let value = typeof pathParam === \"object\" ? pathParam.value : pathParam;\n\n if (!options.skipUrlEncoding && !allowReserved) {\n value = encodeURIComponent(value);\n }\n\n routePath = routePath.replace(/\\{[\\w-]+\\}/, String(value));\n }\n return routePath;\n}\n\n/**\n * Replace all of the instances of searchValue in value with the provided replaceValue.\n * @param value - The value to search and replace in.\n * @param searchValue - The value to search for in the value argument.\n * @param replaceValue - The value to replace searchValue with in the value argument.\n * @returns The value where each instance of searchValue was replaced with replacedValue.\n */\nexport function replaceAll(\n value: string | undefined,\n searchValue: string,\n replaceValue: string,\n): string | undefined {\n return !value || !searchValue ? value : value.split(searchValue).join(replaceValue || \"\");\n}\n"]}
|
|
1
|
+
{"version":3,"file":"urlHelpers.js","sourceRoot":"","sources":["../../../src/client/urlHelpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAqClC,SAAS,2BAA2B,CAAC,CAAU;IAC7C,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC;QACtE,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,KAAK,GAAI,CAA+B,CAAC,KAAK,CAAC;IACrD,OAAO,OAAO,KAAK,EAAE,QAAQ,KAAK,UAAU,CAAC;AAC/C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAC7B,QAAgB,EAChB,SAAiB,EACjB,cAA8D,EAC9D,UAA6B,EAAE;I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ED,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CACxB,KAAyB,EACzB,WAAmB,EACnB,YAAoB;IAEpB,OAAO,CAAC,KAAK,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;AAC5F,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PathParameterWithOptions, RequestParameters } from \"./common.js\";\n\ntype QueryParameterStyle = \"form\" | \"spaceDelimited\" | \"pipeDelimited\";\n\n/**\n * An object that can be passed as a query parameter, allowing for additional options to be set relating to how the parameter is encoded.\n */\ninterface QueryParameterWithOptions {\n /**\n * The value of the query parameter.\n */\n value: unknown;\n\n /**\n * If set to true, value must be an array. Setting this option to true will cause the array to be encoded as multiple query parameters.\n * Setting it to false will cause the array values to be encoded as a single query parameter, with each value separated by a comma ','.\n *\n * For example, with `explode` set to true, a query parameter named \"foo\" with value [\"a\", \"b\", \"c\"] will be encoded as foo=a&foo=b&foo=c.\n * If `explode` was set to false, the same example would instead be encouded as foo=a,b,c.\n *\n * Defaults to false.\n */\n explode?: boolean;\n\n /**\n * Style for encoding arrays. Three possible values:\n * - \"form\": array values will be separated by a comma \",\" in the query parameter value.\n * - \"spaceDelimited\": array values will be separated by a space (\" \", url-encoded to \"%20\").\n * - \"pipeDelimited\": array values will be separated by a pipe (\"|\").\n *\n * Defaults to \"form\".\n */\n style?: QueryParameterStyle;\n}\n\nfunction isQueryParameterWithOptions(x: unknown): x is QueryParameterWithOptions {\n if (typeof x !== \"object\" || x === null || !Object.hasOwn(x, \"value\")) {\n return false;\n }\n const value = (x as QueryParameterWithOptions).value;\n return typeof value?.toString === \"function\";\n}\n\n/**\n * Builds the request url, filling in query and path parameters\n * @param endpoint - base url which can be a template url\n * @param routePath - path to append to the endpoint\n * @param pathParameters - values of the path parameters\n * @param options - request parameters including query parameters\n * @returns a full url with path and query parameters\n */\nexport function buildRequestUrl(\n endpoint: string,\n routePath: string,\n pathParameters: (string | number | PathParameterWithOptions)[],\n options: RequestParameters = {},\n): string {\n if (routePath.startsWith(\"https://\") || routePath.startsWith(\"http://\")) {\n return routePath;\n }\n endpoint = buildBaseUrl(endpoint, options);\n // the route could be\n // 1. a path: \"container123/blob456\"\n // 2. a component string from template which starts with \"?\" and may contain more \"?\" after template is expanded,\n // e.g., \"?restype=container&comp=blobs?where=key177196556777405927%3D%27val1177196556777407626%27\"\n const updatedRoutePath = buildRoutePath(routePath, pathParameters, options);\n\n const requestUrl = appendQueryParams(appendPath(endpoint, updatedRoutePath), options);\n const url = new URL(requestUrl);\n\n return url.toString();\n}\n\nfunction appendPath(endpoint: string, pathToAppend: string): string {\n const endpointSearchStart = endpoint.indexOf(\"?\");\n const pathSearchStart = pathToAppend.indexOf(\"?\");\n const endpointParts =\n endpointSearchStart !== -1\n ? [endpoint.substring(0, endpointSearchStart), endpoint.substring(endpointSearchStart + 1)]\n : [endpoint, \"\"];\n const pathParts =\n pathSearchStart !== -1\n ? [pathToAppend.substring(0, pathSearchStart), pathToAppend.substring(pathSearchStart + 1)]\n : [pathToAppend, \"\"];\n\n const combinedSearch = [endpointParts[1], pathParts[1].replaceAll(\"?\", \"&\")]\n .filter(Boolean)\n .join(\"&\");\n // Replace consecutive forward slashes with a single forward slash, but only for the part right after the host in the endpoint.\n // This is to maintain compatibility with old behavior for cases where the endpoint has been provided with extra forward slashes,\n // while still allowing for intentional consecutive forward slashes in the path to be preserved.\n const baseEndpoint = endpointParts[0].replace(/(^[^:]+:\\/\\/[^/]+)\\/\\/+/, \"$1/\");\n const basePathToAppend = pathParts[0];\n let combinedUrl = baseEndpoint;\n if (!baseEndpoint.endsWith(\"/\") && !basePathToAppend.startsWith(\"/\") && basePathToAppend !== \"\") {\n combinedUrl += `/${basePathToAppend}`;\n } else if (baseEndpoint.endsWith(\"/\") && basePathToAppend.startsWith(\"/\")) {\n combinedUrl += basePathToAppend.substring(1);\n } else {\n combinedUrl += basePathToAppend;\n }\n\n if (combinedSearch) {\n combinedUrl += `?${combinedSearch}`;\n }\n\n return combinedUrl;\n}\n\nfunction getQueryParamValue(\n key: string,\n allowReserved: boolean,\n style: QueryParameterStyle,\n param: any,\n): string {\n let separator: string;\n if (style === \"pipeDelimited\") {\n separator = \"|\";\n } else if (style === \"spaceDelimited\") {\n separator = \"%20\";\n } else {\n separator = \",\";\n }\n\n let paramValues: any[];\n if (Array.isArray(param)) {\n paramValues = param;\n } else if (typeof param === \"object\" && param.toString === Object.prototype.toString) {\n // If the parameter is an object without a custom toString implementation (e.g. a Date),\n // then we should deconstruct the object into an array [key1, value1, key2, value2, ...].\n paramValues = Object.entries(param).flat();\n } else {\n paramValues = [param];\n }\n\n const value = paramValues\n .map((p) => {\n if (p === null || p === undefined) {\n return \"\";\n }\n\n if (!p.toString || typeof p.toString !== \"function\") {\n throw new Error(`Query parameters must be able to be represented as string, ${key} can't`);\n }\n\n const rawValue = p.toISOString !== undefined ? p.toISOString() : p.toString();\n return allowReserved ? rawValue : encodeURIComponent(rawValue);\n })\n .join(separator);\n\n return `${allowReserved ? key : encodeURIComponent(key)}=${value}`;\n}\n\n/**\n * Parses a query string into a map of key/value pairs without decoding the values.\n * This avoids the issue where `URL.searchParams` would decode values, potentially\n * corrupting already-encoded values such as SAS signatures.\n */\nfunction simpleParseQueryParams(queryString: string): Map<string, string | string[]> {\n const result = new Map<string, string | string[]>();\n if (!queryString || queryString[0] !== \"?\") {\n return result;\n }\n\n // remove the leading ?\n queryString = queryString.slice(1);\n const pairs = queryString.split(\"&\");\n\n for (const pair of pairs) {\n const eqIndex = pair.indexOf(\"=\");\n const name = eqIndex === -1 ? pair : pair.substring(0, eqIndex);\n const value = eqIndex === -1 ? \"\" : pair.substring(eqIndex + 1);\n\n const existingValue = result.get(name);\n if (existingValue !== undefined) {\n if (Array.isArray(existingValue)) {\n existingValue.push(value);\n } else {\n result.set(name, [existingValue, value]);\n }\n } else {\n result.set(name, value);\n }\n }\n\n return result;\n}\n\n/** @internal */\nexport function appendQueryParams(url: string, options: RequestParameters = {}): string {\n if (!options.queryParameters) {\n return url;\n }\n const parsedUrl = new URL(url);\n const queryParams = options.queryParameters;\n\n // Parse existing query params from the URL manually to avoid re-encoding issues\n const existingParams = simpleParseQueryParams(parsedUrl.search);\n\n const newParamStrings: string[] = [];\n for (const key of Object.keys(queryParams)) {\n const param = queryParams[key];\n if (param === undefined || param === null) {\n continue;\n }\n\n const hasMetadata = isQueryParameterWithOptions(param);\n const rawValue = hasMetadata ? param.value : param;\n const explode = hasMetadata ? (param.explode ?? false) : false;\n const style = hasMetadata && param.style ? param.style : \"form\";\n\n if (explode) {\n if (Array.isArray(rawValue)) {\n for (const item of rawValue) {\n newParamStrings.push(\n getQueryParamValue(key, options.skipUrlEncoding ?? false, style, item),\n );\n }\n } else if (rawValue !== null && typeof rawValue === \"object\") {\n // For object explode, the name of the query parameter is ignored and we use the object key instead\n for (const [actualKey, value] of Object.entries(rawValue)) {\n newParamStrings.push(\n getQueryParamValue(actualKey, options.skipUrlEncoding ?? false, style, value),\n );\n }\n } else {\n // Explode doesn't really make sense for primitives\n throw new Error(\"explode can only be set to true for objects and arrays\");\n }\n } else {\n newParamStrings.push(\n getQueryParamValue(key, options.skipUrlEncoding ?? false, style, rawValue),\n );\n }\n }\n\n // Merge new params into existing params, deduplicating values for the same key\n for (const paramString of newParamStrings) {\n const eqIndex = paramString.indexOf(\"=\");\n const name = paramString.substring(0, eqIndex);\n const value = paramString.substring(eqIndex + 1);\n\n const existingValue = existingParams.get(name);\n if (existingValue !== undefined) {\n if (Array.isArray(existingValue)) {\n if (!existingValue.includes(value)) {\n existingValue.push(value);\n }\n } else if (existingValue !== value) {\n existingParams.set(name, [existingValue, value]);\n }\n // if existingValue === value (single string match), no change needed\n } else {\n existingParams.set(name, value);\n }\n }\n\n // Reconstruct the search string manually to avoid URL re-encoding\n const searchPieces: string[] = [];\n for (const [name, value] of existingParams) {\n if (Array.isArray(value)) {\n for (const subValue of value) {\n searchPieces.push(`${name}=${subValue}`);\n }\n } else {\n searchPieces.push(`${name}=${value}`);\n }\n }\n\n parsedUrl.search = searchPieces.length ? `?${searchPieces.join(\"&\")}` : \"\";\n return parsedUrl.toString();\n}\n\nexport function buildBaseUrl(endpoint: string, options: RequestParameters): string {\n if (!options.pathParameters) {\n return endpoint;\n }\n const pathParams = options.pathParameters;\n for (const [key, param] of Object.entries(pathParams)) {\n if (param === undefined || param === null) {\n throw new Error(`Path parameters ${key} must not be undefined or null`);\n }\n if (!param.toString || typeof param.toString !== \"function\") {\n throw new Error(`Path parameters must be able to be represented as string, ${key} can't`);\n }\n let value = param.toISOString !== undefined ? param.toISOString() : String(param);\n if (!options.skipUrlEncoding) {\n value = encodeURIComponent(param);\n }\n endpoint = replaceAll(endpoint, `{${key}}`, value) ?? \"\";\n }\n\n return endpoint;\n}\n\nfunction buildRoutePath(\n routePath: string,\n pathParameters: (string | number | PathParameterWithOptions)[],\n options: RequestParameters = {},\n): string {\n for (const pathParam of pathParameters) {\n const allowReserved = typeof pathParam === \"object\" && (pathParam.allowReserved ?? false);\n let value = typeof pathParam === \"object\" ? pathParam.value : pathParam;\n\n if (!options.skipUrlEncoding && !allowReserved) {\n value = encodeURIComponent(value);\n }\n\n routePath = routePath.replace(/\\{[\\w-]+\\}/, String(value));\n }\n return routePath;\n}\n\n/**\n * Replace all of the instances of searchValue in value with the provided replaceValue.\n * @param value - The value to search and replace in.\n * @param searchValue - The value to search for in the value argument.\n * @param replaceValue - The value to replace searchValue with in the value argument.\n * @returns The value where each instance of searchValue was replaced with replacedValue.\n */\nexport function replaceAll(\n value: string | undefined,\n searchValue: string,\n replaceValue: string,\n): string | undefined {\n return !value || !searchValue ? value : value.split(searchValue).join(replaceValue || \"\");\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,CAAC,MAAM,WAAW,GAAW,OAAO,CAAC;AAE3C,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport const SDK_VERSION: string = \"0.3.
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,CAAC,MAAM,WAAW,GAAW,OAAO,CAAC;AAE3C,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport const SDK_VERSION: string = \"0.3.6\";\n\nexport const DEFAULT_RETRY_POLICY_COUNT = 3;\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type LogPolicyOptions } from "./policies/logPolicy.js";
|
|
2
2
|
import { type Pipeline } from "./pipeline.js";
|
|
3
3
|
import type { Agent, PipelineRetryOptions, ProxySettings, TlsSettings } from "./interfaces.js";
|
|
4
|
-
import {
|
|
4
|
+
import type { RedirectPolicyOptions } from "./policies/redirectPolicy.js";
|
|
5
5
|
import { type UserAgentPolicyOptions } from "./policies/userAgentPolicy.js";
|
|
6
6
|
/**
|
|
7
7
|
* Defines options that are used to configure the HTTP pipeline for
|