@typespec/ts-http-runtime 0.3.1-alpha.20250716.3 → 0.3.1-alpha.20250730.1
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/getClient.js +8 -10
- package/dist/browser/client/getClient.js.map +1 -1
- package/dist/browser/client/multipart.js +2 -4
- package/dist/browser/client/multipart.js.map +1 -1
- package/dist/browser/client/operationOptionHelpers.js +6 -7
- package/dist/browser/client/operationOptionHelpers.js.map +1 -1
- package/dist/browser/client/restError.js +4 -6
- package/dist/browser/client/restError.js.map +1 -1
- package/dist/browser/client/sendRequest.js +20 -19
- package/dist/browser/client/sendRequest.js.map +1 -1
- package/dist/browser/client/urlHelpers.js +6 -9
- package/dist/browser/client/urlHelpers.js.map +1 -1
- package/dist/browser/fetchHttpClient.js +30 -21
- package/dist/browser/fetchHttpClient.js.map +1 -1
- package/dist/browser/httpHeaders.js +2 -2
- package/dist/browser/httpHeaders.js.map +1 -1
- package/dist/browser/nodeHttpClient.js +27 -21
- package/dist/browser/nodeHttpClient.js.map +1 -1
- package/dist/browser/pipeline.js +3 -3
- package/dist/browser/pipeline.js.map +1 -1
- package/dist/browser/pipelineRequest.js +26 -8
- package/dist/browser/pipelineRequest.js.map +1 -1
- package/dist/browser/policies/auth/apiKeyAuthenticationPolicy.js +1 -2
- package/dist/browser/policies/auth/apiKeyAuthenticationPolicy.js.map +1 -1
- package/dist/browser/policies/auth/basicAuthenticationPolicy.js +1 -2
- package/dist/browser/policies/auth/basicAuthenticationPolicy.js.map +1 -1
- package/dist/browser/policies/auth/bearerAuthenticationPolicy.js +1 -2
- package/dist/browser/policies/auth/bearerAuthenticationPolicy.js.map +1 -1
- package/dist/browser/policies/auth/checkInsecureConnection.js +1 -1
- package/dist/browser/policies/auth/checkInsecureConnection.js.map +1 -1
- package/dist/browser/policies/auth/oauth2AuthenticationPolicy.js +1 -2
- package/dist/browser/policies/auth/oauth2AuthenticationPolicy.js.map +1 -1
- package/dist/browser/policies/defaultRetryPolicy.js +1 -2
- package/dist/browser/policies/defaultRetryPolicy.js.map +1 -1
- package/dist/browser/policies/exponentialRetryPolicy.js +5 -3
- package/dist/browser/policies/exponentialRetryPolicy.js.map +1 -1
- package/dist/browser/policies/formDataPolicy.js +2 -3
- package/dist/browser/policies/formDataPolicy.js.map +1 -1
- package/dist/browser/policies/logPolicy.js +1 -2
- package/dist/browser/policies/logPolicy.js.map +1 -1
- package/dist/browser/policies/multipartPolicy.js +2 -3
- package/dist/browser/policies/multipartPolicy.js.map +1 -1
- package/dist/browser/policies/retryPolicy.js +2 -3
- package/dist/browser/policies/retryPolicy.js.map +1 -1
- package/dist/browser/policies/systemErrorRetryPolicy.js +5 -3
- package/dist/browser/policies/systemErrorRetryPolicy.js.map +1 -1
- package/dist/browser/policies/throttlingRetryPolicy.js +1 -2
- package/dist/browser/policies/throttlingRetryPolicy.js.map +1 -1
- package/dist/browser/restError.js +38 -12
- package/dist/browser/restError.js.map +1 -1
- package/dist/browser/retryStrategies/exponentialRetryStrategy.js +2 -3
- package/dist/browser/retryStrategies/exponentialRetryStrategy.js.map +1 -1
- package/dist/browser/retryStrategies/throttlingRetryStrategy.js +1 -1
- package/dist/browser/retryStrategies/throttlingRetryStrategy.js.map +1 -1
- package/dist/browser/util/checkEnvironment.js +6 -7
- package/dist/browser/util/checkEnvironment.js.map +1 -1
- package/dist/browser/util/helpers.js +4 -4
- package/dist/browser/util/helpers.js.map +1 -1
- package/dist/browser/util/sanitizer.js +7 -1
- package/dist/browser/util/sanitizer.js.map +1 -1
- package/dist/browser/util/userAgentPlatform-browser.mjs.map +1 -1
- package/dist/browser/util/userAgentPlatform.js +2 -2
- package/dist/browser/util/uuidUtils-browser.mjs.map +1 -1
- package/dist/browser/util/uuidUtils.js +1 -2
- package/dist/browser/xhrHttpClient.js +3 -5
- package/dist/browser/xhrHttpClient.js.map +1 -1
- package/dist/commonjs/client/getClient.js +8 -10
- package/dist/commonjs/client/getClient.js.map +1 -1
- package/dist/commonjs/client/multipart.js +2 -4
- package/dist/commonjs/client/multipart.js.map +1 -1
- package/dist/commonjs/client/operationOptionHelpers.js +6 -7
- package/dist/commonjs/client/operationOptionHelpers.js.map +1 -1
- package/dist/commonjs/client/restError.js +4 -6
- package/dist/commonjs/client/restError.js.map +1 -1
- package/dist/commonjs/client/sendRequest.js +20 -19
- package/dist/commonjs/client/sendRequest.js.map +1 -1
- package/dist/commonjs/client/urlHelpers.js +6 -9
- package/dist/commonjs/client/urlHelpers.js.map +1 -1
- package/dist/commonjs/fetchHttpClient.js +30 -21
- package/dist/commonjs/fetchHttpClient.js.map +1 -1
- package/dist/commonjs/httpHeaders.js +2 -2
- package/dist/commonjs/httpHeaders.js.map +1 -1
- package/dist/commonjs/nodeHttpClient.js +27 -21
- package/dist/commonjs/nodeHttpClient.js.map +1 -1
- package/dist/commonjs/pipeline.js +3 -3
- package/dist/commonjs/pipeline.js.map +1 -1
- package/dist/commonjs/pipelineRequest.js +26 -8
- package/dist/commonjs/pipelineRequest.js.map +1 -1
- package/dist/commonjs/policies/auth/apiKeyAuthenticationPolicy.js +1 -2
- package/dist/commonjs/policies/auth/apiKeyAuthenticationPolicy.js.map +1 -1
- package/dist/commonjs/policies/auth/basicAuthenticationPolicy.js +1 -2
- package/dist/commonjs/policies/auth/basicAuthenticationPolicy.js.map +1 -1
- package/dist/commonjs/policies/auth/bearerAuthenticationPolicy.js +1 -2
- package/dist/commonjs/policies/auth/bearerAuthenticationPolicy.js.map +1 -1
- package/dist/commonjs/policies/auth/checkInsecureConnection.js +1 -1
- package/dist/commonjs/policies/auth/checkInsecureConnection.js.map +1 -1
- package/dist/commonjs/policies/auth/oauth2AuthenticationPolicy.js +1 -2
- package/dist/commonjs/policies/auth/oauth2AuthenticationPolicy.js.map +1 -1
- package/dist/commonjs/policies/defaultRetryPolicy.js +1 -2
- package/dist/commonjs/policies/defaultRetryPolicy.js.map +1 -1
- package/dist/commonjs/policies/exponentialRetryPolicy.js +5 -3
- package/dist/commonjs/policies/exponentialRetryPolicy.js.map +1 -1
- package/dist/commonjs/policies/formDataPolicy.js +2 -3
- package/dist/commonjs/policies/formDataPolicy.js.map +1 -1
- package/dist/commonjs/policies/logPolicy.js +1 -2
- package/dist/commonjs/policies/logPolicy.js.map +1 -1
- package/dist/commonjs/policies/multipartPolicy.js +2 -3
- package/dist/commonjs/policies/multipartPolicy.js.map +1 -1
- package/dist/commonjs/policies/proxyPolicy.js +4 -5
- package/dist/commonjs/policies/proxyPolicy.js.map +1 -1
- package/dist/commonjs/policies/retryPolicy.js +2 -3
- package/dist/commonjs/policies/retryPolicy.js.map +1 -1
- package/dist/commonjs/policies/systemErrorRetryPolicy.js +5 -3
- package/dist/commonjs/policies/systemErrorRetryPolicy.js.map +1 -1
- package/dist/commonjs/policies/throttlingRetryPolicy.js +1 -2
- package/dist/commonjs/policies/throttlingRetryPolicy.js.map +1 -1
- package/dist/commonjs/restError.js +38 -12
- package/dist/commonjs/restError.js.map +1 -1
- package/dist/commonjs/retryStrategies/exponentialRetryStrategy.js +2 -3
- package/dist/commonjs/retryStrategies/exponentialRetryStrategy.js.map +1 -1
- package/dist/commonjs/retryStrategies/throttlingRetryStrategy.js +1 -1
- package/dist/commonjs/retryStrategies/throttlingRetryStrategy.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +11 -11
- package/dist/commonjs/util/checkEnvironment.js +6 -7
- package/dist/commonjs/util/checkEnvironment.js.map +1 -1
- package/dist/commonjs/util/concat.js +17 -35
- package/dist/commonjs/util/concat.js.map +1 -1
- package/dist/commonjs/util/helpers.js +4 -4
- package/dist/commonjs/util/helpers.js.map +1 -1
- package/dist/commonjs/util/sanitizer.js +7 -1
- package/dist/commonjs/util/sanitizer.js.map +1 -1
- package/dist/commonjs/util/uuidUtils.js +1 -2
- package/dist/commonjs/util/uuidUtils.js.map +1 -1
- package/dist/commonjs/xhrHttpClient.js +3 -5
- package/dist/commonjs/xhrHttpClient.js.map +1 -1
- package/dist/esm/client/getClient.js +8 -10
- package/dist/esm/client/getClient.js.map +1 -1
- package/dist/esm/client/multipart.js +2 -4
- package/dist/esm/client/multipart.js.map +1 -1
- package/dist/esm/client/operationOptionHelpers.js +6 -7
- package/dist/esm/client/operationOptionHelpers.js.map +1 -1
- package/dist/esm/client/restError.js +4 -6
- package/dist/esm/client/restError.js.map +1 -1
- package/dist/esm/client/sendRequest.js +20 -19
- package/dist/esm/client/sendRequest.js.map +1 -1
- package/dist/esm/client/urlHelpers.js +6 -9
- package/dist/esm/client/urlHelpers.js.map +1 -1
- package/dist/esm/fetchHttpClient.js +30 -21
- package/dist/esm/fetchHttpClient.js.map +1 -1
- package/dist/esm/httpHeaders.js +2 -2
- package/dist/esm/httpHeaders.js.map +1 -1
- package/dist/esm/nodeHttpClient.js +27 -21
- package/dist/esm/nodeHttpClient.js.map +1 -1
- package/dist/esm/pipeline.js +3 -3
- package/dist/esm/pipeline.js.map +1 -1
- package/dist/esm/pipelineRequest.js +26 -8
- package/dist/esm/pipelineRequest.js.map +1 -1
- package/dist/esm/policies/auth/apiKeyAuthenticationPolicy.js +1 -2
- package/dist/esm/policies/auth/apiKeyAuthenticationPolicy.js.map +1 -1
- package/dist/esm/policies/auth/basicAuthenticationPolicy.js +1 -2
- package/dist/esm/policies/auth/basicAuthenticationPolicy.js.map +1 -1
- package/dist/esm/policies/auth/bearerAuthenticationPolicy.js +1 -2
- package/dist/esm/policies/auth/bearerAuthenticationPolicy.js.map +1 -1
- package/dist/esm/policies/auth/checkInsecureConnection.js +1 -1
- package/dist/esm/policies/auth/checkInsecureConnection.js.map +1 -1
- package/dist/esm/policies/auth/oauth2AuthenticationPolicy.js +1 -2
- package/dist/esm/policies/auth/oauth2AuthenticationPolicy.js.map +1 -1
- package/dist/esm/policies/defaultRetryPolicy.js +1 -2
- package/dist/esm/policies/defaultRetryPolicy.js.map +1 -1
- package/dist/esm/policies/exponentialRetryPolicy.js +5 -3
- package/dist/esm/policies/exponentialRetryPolicy.js.map +1 -1
- package/dist/esm/policies/formDataPolicy.js +2 -3
- package/dist/esm/policies/formDataPolicy.js.map +1 -1
- package/dist/esm/policies/logPolicy.js +1 -2
- package/dist/esm/policies/logPolicy.js.map +1 -1
- package/dist/esm/policies/multipartPolicy.js +2 -3
- package/dist/esm/policies/multipartPolicy.js.map +1 -1
- package/dist/esm/policies/proxyPolicy.js +4 -5
- package/dist/esm/policies/proxyPolicy.js.map +1 -1
- package/dist/esm/policies/retryPolicy.js +2 -3
- package/dist/esm/policies/retryPolicy.js.map +1 -1
- package/dist/esm/policies/systemErrorRetryPolicy.js +5 -3
- package/dist/esm/policies/systemErrorRetryPolicy.js.map +1 -1
- package/dist/esm/policies/throttlingRetryPolicy.js +1 -2
- package/dist/esm/policies/throttlingRetryPolicy.js.map +1 -1
- package/dist/esm/restError.js +38 -12
- package/dist/esm/restError.js.map +1 -1
- package/dist/esm/retryStrategies/exponentialRetryStrategy.js +2 -3
- package/dist/esm/retryStrategies/exponentialRetryStrategy.js.map +1 -1
- package/dist/esm/retryStrategies/throttlingRetryStrategy.js +1 -1
- package/dist/esm/retryStrategies/throttlingRetryStrategy.js.map +1 -1
- package/dist/esm/util/checkEnvironment.js +6 -7
- package/dist/esm/util/checkEnvironment.js.map +1 -1
- package/dist/esm/util/concat.js +17 -35
- package/dist/esm/util/concat.js.map +1 -1
- package/dist/esm/util/helpers.js +4 -4
- package/dist/esm/util/helpers.js.map +1 -1
- package/dist/esm/util/sanitizer.js +7 -1
- package/dist/esm/util/sanitizer.js.map +1 -1
- package/dist/esm/util/uuidUtils.js +1 -2
- package/dist/esm/util/uuidUtils.js.map +1 -1
- package/dist/esm/xhrHttpClient.js +3 -5
- package/dist/esm/xhrHttpClient.js.map +1 -1
- package/dist/react-native/client/getClient.js +8 -10
- package/dist/react-native/client/getClient.js.map +1 -1
- package/dist/react-native/client/multipart.js +2 -4
- package/dist/react-native/client/multipart.js.map +1 -1
- package/dist/react-native/client/operationOptionHelpers.js +6 -7
- package/dist/react-native/client/operationOptionHelpers.js.map +1 -1
- package/dist/react-native/client/restError.js +4 -6
- package/dist/react-native/client/restError.js.map +1 -1
- package/dist/react-native/client/sendRequest.js +20 -19
- package/dist/react-native/client/sendRequest.js.map +1 -1
- package/dist/react-native/client/urlHelpers.js +6 -9
- package/dist/react-native/client/urlHelpers.js.map +1 -1
- package/dist/react-native/fetchHttpClient.js +30 -21
- package/dist/react-native/fetchHttpClient.js.map +1 -1
- package/dist/react-native/httpHeaders.js +2 -2
- package/dist/react-native/httpHeaders.js.map +1 -1
- package/dist/react-native/nodeHttpClient.js +27 -21
- package/dist/react-native/nodeHttpClient.js.map +1 -1
- package/dist/react-native/pipeline.js +3 -3
- package/dist/react-native/pipeline.js.map +1 -1
- package/dist/react-native/pipelineRequest.js +26 -8
- package/dist/react-native/pipelineRequest.js.map +1 -1
- package/dist/react-native/policies/auth/apiKeyAuthenticationPolicy.js +1 -2
- package/dist/react-native/policies/auth/apiKeyAuthenticationPolicy.js.map +1 -1
- package/dist/react-native/policies/auth/basicAuthenticationPolicy.js +1 -2
- package/dist/react-native/policies/auth/basicAuthenticationPolicy.js.map +1 -1
- package/dist/react-native/policies/auth/bearerAuthenticationPolicy.js +1 -2
- package/dist/react-native/policies/auth/bearerAuthenticationPolicy.js.map +1 -1
- package/dist/react-native/policies/auth/checkInsecureConnection.js +1 -1
- package/dist/react-native/policies/auth/checkInsecureConnection.js.map +1 -1
- package/dist/react-native/policies/auth/oauth2AuthenticationPolicy.js +1 -2
- package/dist/react-native/policies/auth/oauth2AuthenticationPolicy.js.map +1 -1
- package/dist/react-native/policies/defaultRetryPolicy.js +1 -2
- package/dist/react-native/policies/defaultRetryPolicy.js.map +1 -1
- package/dist/react-native/policies/exponentialRetryPolicy.js +5 -3
- package/dist/react-native/policies/exponentialRetryPolicy.js.map +1 -1
- package/dist/react-native/policies/formDataPolicy.js +2 -3
- package/dist/react-native/policies/formDataPolicy.js.map +1 -1
- package/dist/react-native/policies/logPolicy.js +1 -2
- package/dist/react-native/policies/logPolicy.js.map +1 -1
- package/dist/react-native/policies/multipartPolicy.js +2 -3
- package/dist/react-native/policies/multipartPolicy.js.map +1 -1
- package/dist/react-native/policies/retryPolicy.js +2 -3
- package/dist/react-native/policies/retryPolicy.js.map +1 -1
- package/dist/react-native/policies/systemErrorRetryPolicy.js +5 -3
- package/dist/react-native/policies/systemErrorRetryPolicy.js.map +1 -1
- package/dist/react-native/policies/throttlingRetryPolicy.js +1 -2
- package/dist/react-native/policies/throttlingRetryPolicy.js.map +1 -1
- package/dist/react-native/restError.js +38 -12
- package/dist/react-native/restError.js.map +1 -1
- package/dist/react-native/retryStrategies/exponentialRetryStrategy.js +2 -3
- package/dist/react-native/retryStrategies/exponentialRetryStrategy.js.map +1 -1
- package/dist/react-native/retryStrategies/throttlingRetryStrategy.js +1 -1
- package/dist/react-native/retryStrategies/throttlingRetryStrategy.js.map +1 -1
- package/dist/react-native/util/checkEnvironment.js +6 -7
- package/dist/react-native/util/checkEnvironment.js.map +1 -1
- package/dist/react-native/util/helpers.js +4 -4
- package/dist/react-native/util/helpers.js.map +1 -1
- package/dist/react-native/util/sanitizer.js +7 -1
- package/dist/react-native/util/sanitizer.js.map +1 -1
- package/dist/react-native/util/userAgentPlatform-react-native.mjs.map +1 -1
- package/dist/react-native/util/userAgentPlatform.js +1 -2
- package/dist/react-native/xhrHttpClient.js +3 -5
- package/dist/react-native/xhrHttpClient.js.map +1 -1
- package/package.json +2 -2
|
@@ -11,9 +11,8 @@ import { isNodeLike } from "../util/checkEnvironment.js";
|
|
|
11
11
|
* @param options - Client options
|
|
12
12
|
*/
|
|
13
13
|
export function getClient(endpoint, clientOptions = {}) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if ((_b = clientOptions.additionalPolicies) === null || _b === void 0 ? void 0 : _b.length) {
|
|
14
|
+
const pipeline = clientOptions.pipeline ?? createDefaultPipeline(clientOptions);
|
|
15
|
+
if (clientOptions.additionalPolicies?.length) {
|
|
17
16
|
for (const { policy, position } of clientOptions.additionalPolicies) {
|
|
18
17
|
// Sign happens after Retry and is commonly needed to occur
|
|
19
18
|
// before policies that intercept post-retry.
|
|
@@ -24,9 +23,9 @@ export function getClient(endpoint, clientOptions = {}) {
|
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
25
|
const { allowInsecureConnection, httpClient } = clientOptions;
|
|
27
|
-
const endpointUrl =
|
|
26
|
+
const endpointUrl = clientOptions.endpoint ?? endpoint;
|
|
28
27
|
const client = (path, ...args) => {
|
|
29
|
-
const getUrl = (requestOptions) => buildRequestUrl(endpointUrl, path, args,
|
|
28
|
+
const getUrl = (requestOptions) => buildRequestUrl(endpointUrl, path, args, { allowInsecureConnection, ...requestOptions });
|
|
30
29
|
return {
|
|
31
30
|
get: (requestOptions = {}) => {
|
|
32
31
|
return buildOperation("GET", getUrl(requestOptions), pipeline, requestOptions, allowInsecureConnection, httpClient);
|
|
@@ -61,23 +60,22 @@ export function getClient(endpoint, clientOptions = {}) {
|
|
|
61
60
|
};
|
|
62
61
|
}
|
|
63
62
|
function buildOperation(method, url, pipeline, options, allowInsecureConnection, httpClient) {
|
|
64
|
-
|
|
65
|
-
allowInsecureConnection = (_a = options.allowInsecureConnection) !== null && _a !== void 0 ? _a : allowInsecureConnection;
|
|
63
|
+
allowInsecureConnection = options.allowInsecureConnection ?? allowInsecureConnection;
|
|
66
64
|
return {
|
|
67
65
|
then: function (onFulfilled, onrejected) {
|
|
68
|
-
return sendRequest(method, url, pipeline,
|
|
66
|
+
return sendRequest(method, url, pipeline, { ...options, allowInsecureConnection }, httpClient).then(onFulfilled, onrejected);
|
|
69
67
|
},
|
|
70
68
|
async asBrowserStream() {
|
|
71
69
|
if (isNodeLike) {
|
|
72
70
|
throw new Error("`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`.");
|
|
73
71
|
}
|
|
74
72
|
else {
|
|
75
|
-
return sendRequest(method, url, pipeline,
|
|
73
|
+
return sendRequest(method, url, pipeline, { ...options, allowInsecureConnection, responseAsStream: true }, httpClient);
|
|
76
74
|
}
|
|
77
75
|
},
|
|
78
76
|
async asNodeStream() {
|
|
79
77
|
if (isNodeLike) {
|
|
80
|
-
return sendRequest(method, url, pipeline,
|
|
78
|
+
return sendRequest(method, url, pipeline, { ...options, allowInsecureConnection, responseAsStream: true }, httpClient);
|
|
81
79
|
}
|
|
82
80
|
else {
|
|
83
81
|
throw new Error("`isNodeStream` is not supported in the browser environment. Use `asBrowserStream` to obtain the response body stream.");
|
|
@@ -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,6BAA6B,CAAC;AAEzD;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,QAAgB,EAAE,gBAA+B,EAAE
|
|
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,6BAA6B,CAAC;AAEzD;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,QAAgB,EAAE,gBAA+B,EAAE;IAC3E,MAAM,QAAQ,GAAG,aAAa,CAAC,QAAQ,IAAI,qBAAqB,CAAC,aAAa,CAAC,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IAAI,uBAAuB,CAAC;IACrF,OAAO;QACL,IAAI,EAAE,UAAU,WAAW,EAAE,UAAU;YACrC,OAAO,WAAW,CAChB,MAAM,EACN,GAAG,EACH,QAAQ,EACR,EAAE,GAAG,OAAO,EAAE,uBAAuB,EAAE,EACvC,UAAU,CACX,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,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 \"../util/checkEnvironment.js\";\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"]}
|
|
@@ -51,7 +51,6 @@ function escapeDispositionField(value) {
|
|
|
51
51
|
return JSON.stringify(value);
|
|
52
52
|
}
|
|
53
53
|
function getContentDisposition(descriptor) {
|
|
54
|
-
var _a;
|
|
55
54
|
const contentDispositionHeader = getHeaderValue(descriptor, "content-disposition");
|
|
56
55
|
if (contentDispositionHeader) {
|
|
57
56
|
return contentDispositionHeader;
|
|
@@ -61,7 +60,7 @@ function getContentDisposition(descriptor) {
|
|
|
61
60
|
descriptor.filename === undefined) {
|
|
62
61
|
return undefined;
|
|
63
62
|
}
|
|
64
|
-
const dispositionType =
|
|
63
|
+
const dispositionType = descriptor.dispositionType ?? "form-data";
|
|
65
64
|
let disposition = dispositionType;
|
|
66
65
|
if (descriptor.name) {
|
|
67
66
|
disposition += `; name=${escapeDispositionField(descriptor.name)}`;
|
|
@@ -100,10 +99,9 @@ function normalizeBody(body, contentType) {
|
|
|
100
99
|
throw new RestError(`Unsupported body/content-type combination: ${body}, ${contentType}`);
|
|
101
100
|
}
|
|
102
101
|
export function buildBodyPart(descriptor) {
|
|
103
|
-
var _a;
|
|
104
102
|
const contentType = getPartContentType(descriptor);
|
|
105
103
|
const contentDisposition = getContentDisposition(descriptor);
|
|
106
|
-
const headers = createHttpHeaders(
|
|
104
|
+
const headers = createHttpHeaders(descriptor.headers ?? {});
|
|
107
105
|
if (contentType) {
|
|
108
106
|
headers.set("content-type", contentType);
|
|
109
107
|
}
|
|
@@ -1 +1 @@
|
|
|
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,0BAA0B,CAAC;AAC9D,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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AC,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,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AAC;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"]}
|
|
@@ -6,15 +6,14 @@
|
|
|
6
6
|
* @returns the result of the conversion in RequestParameters of RLC layer
|
|
7
7
|
*/
|
|
8
8
|
export function operationOptionsToRequestParameters(options) {
|
|
9
|
-
var _a, _b, _c, _d, _e, _f;
|
|
10
9
|
return {
|
|
11
|
-
allowInsecureConnection:
|
|
12
|
-
timeout:
|
|
13
|
-
skipUrlEncoding:
|
|
10
|
+
allowInsecureConnection: options.requestOptions?.allowInsecureConnection,
|
|
11
|
+
timeout: options.requestOptions?.timeout,
|
|
12
|
+
skipUrlEncoding: options.requestOptions?.skipUrlEncoding,
|
|
14
13
|
abortSignal: options.abortSignal,
|
|
15
|
-
onUploadProgress:
|
|
16
|
-
onDownloadProgress:
|
|
17
|
-
headers:
|
|
14
|
+
onUploadProgress: options.requestOptions?.onUploadProgress,
|
|
15
|
+
onDownloadProgress: options.requestOptions?.onDownloadProgress,
|
|
16
|
+
headers: { ...options.requestOptions?.headers },
|
|
18
17
|
onResponse: options.onResponse,
|
|
19
18
|
};
|
|
20
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operationOptionHelpers.js","sourceRoot":"","sources":["../../../src/client/operationOptionHelpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC;;;;GAIG;AACH,MAAM,UAAU,mCAAmC,CAAC,OAAyB
|
|
1
|
+
{"version":3,"file":"operationOptionHelpers.js","sourceRoot":"","sources":["../../../src/client/operationOptionHelpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC;;;;GAIG;AACH,MAAM,UAAU,mCAAmC,CAAC,OAAyB;IAC3E,OAAO;QACL,uBAAuB,EAAE,OAAO,CAAC,cAAc,EAAE,uBAAuB;QACxE,OAAO,EAAE,OAAO,CAAC,cAAc,EAAE,OAAO;QACxC,eAAe,EAAE,OAAO,CAAC,cAAc,EAAE,eAAe;QACxD,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,gBAAgB,EAAE,OAAO,CAAC,cAAc,EAAE,gBAAgB;QAC1D,kBAAkB,EAAE,OAAO,CAAC,cAAc,EAAE,kBAAkB;QAC9D,OAAO,EAAE,EAAE,GAAG,OAAO,CAAC,cAAc,EAAE,OAAO,EAAE;QAC/C,UAAU,EAAE,OAAO,CAAC,UAAU;KAC/B,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { OperationOptions, RequestParameters } from \"./common.js\";\n\n/**\n * Helper function to convert OperationOptions to RequestParameters\n * @param options - the options that are used by Modular layer to send the request\n * @returns the result of the conversion in RequestParameters of RLC layer\n */\nexport function operationOptionsToRequestParameters(options: OperationOptions): RequestParameters {\n return {\n allowInsecureConnection: options.requestOptions?.allowInsecureConnection,\n timeout: options.requestOptions?.timeout,\n skipUrlEncoding: options.requestOptions?.skipUrlEncoding,\n abortSignal: options.abortSignal,\n onUploadProgress: options.requestOptions?.onUploadProgress,\n onDownloadProgress: options.requestOptions?.onDownloadProgress,\n headers: { ...options.requestOptions?.headers },\n onResponse: options.onResponse,\n };\n}\n"]}
|
|
@@ -3,25 +3,23 @@
|
|
|
3
3
|
import { RestError } from "../restError.js";
|
|
4
4
|
import { createHttpHeaders } from "../httpHeaders.js";
|
|
5
5
|
export function createRestError(messageOrResponse, response) {
|
|
6
|
-
var _a, _b, _c;
|
|
7
6
|
const resp = typeof messageOrResponse === "string" ? response : messageOrResponse;
|
|
8
|
-
const internalError =
|
|
7
|
+
const internalError = resp.body?.error ?? resp.body;
|
|
9
8
|
const message = typeof messageOrResponse === "string"
|
|
10
9
|
? messageOrResponse
|
|
11
|
-
: (
|
|
10
|
+
: (internalError?.message ?? `Unexpected status code: ${resp.status}`);
|
|
12
11
|
return new RestError(message, {
|
|
13
12
|
statusCode: statusCodeToNumber(resp.status),
|
|
14
|
-
code: internalError
|
|
13
|
+
code: internalError?.code,
|
|
15
14
|
request: resp.request,
|
|
16
15
|
response: toPipelineResponse(resp),
|
|
17
16
|
});
|
|
18
17
|
}
|
|
19
18
|
function toPipelineResponse(response) {
|
|
20
|
-
var _a;
|
|
21
19
|
return {
|
|
22
20
|
headers: createHttpHeaders(response.headers),
|
|
23
21
|
request: response.request,
|
|
24
|
-
status:
|
|
22
|
+
status: statusCodeToNumber(response.status) ?? -1,
|
|
25
23
|
};
|
|
26
24
|
}
|
|
27
25
|
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
|
|
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;IACnF,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,EAAE,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC;IACpD,MAAM,OAAO,GACX,OAAO,iBAAiB,KAAK,QAAQ;QACnC,CAAC,CAAC,iBAAiB;QACnB,CAAC,CAAC,CAAC,aAAa,EAAE,OAAO,IAAI,2BAA2B,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAC3E,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE;QAC5B,UAAU,EAAE,kBAAkB,CAAC,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,QAA+B;IACzD,OAAO;QACL,OAAO,EAAE,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC;QAC5C,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,MAAM,EAAE,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;KAClD,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(response: PathUncheckedResponse): PipelineResponse {\n return {\n headers: createHttpHeaders(response.headers),\n request: response.request,\n status: statusCodeToNumber(response.status) ?? -1,\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"]}
|
|
@@ -16,17 +16,16 @@ import { buildMultipartBody } from "./multipart.js";
|
|
|
16
16
|
* @returns returns and HttpResponse
|
|
17
17
|
*/
|
|
18
18
|
export async function sendRequest(method, url, pipeline, options = {}, customHttpClient) {
|
|
19
|
-
|
|
20
|
-
const httpClient = customHttpClient !== null && customHttpClient !== void 0 ? customHttpClient : getCachedDefaultHttpsClient();
|
|
19
|
+
const httpClient = customHttpClient ?? getCachedDefaultHttpsClient();
|
|
21
20
|
const request = buildPipelineRequest(method, url, options);
|
|
22
21
|
try {
|
|
23
22
|
const response = await pipeline.sendRequest(httpClient, request);
|
|
24
23
|
const headers = response.headers.toJSON();
|
|
25
|
-
const stream =
|
|
24
|
+
const stream = response.readableStreamBody ?? response.browserStreamBody;
|
|
26
25
|
const parsedBody = options.responseAsStream || stream !== undefined ? undefined : getResponseBody(response);
|
|
27
|
-
const body = stream
|
|
28
|
-
if (options
|
|
29
|
-
options.onResponse(
|
|
26
|
+
const body = stream ?? parsedBody;
|
|
27
|
+
if (options?.onResponse) {
|
|
28
|
+
options.onResponse({ ...response, request, rawHeaders: headers, parsedBody });
|
|
30
29
|
}
|
|
31
30
|
return {
|
|
32
31
|
request,
|
|
@@ -40,7 +39,7 @@ export async function sendRequest(method, url, pipeline, options = {}, customHtt
|
|
|
40
39
|
const { response } = e;
|
|
41
40
|
const rawHeaders = response.headers.toJSON();
|
|
42
41
|
// UNBRANDED DIFFERENCE: onResponse callback does not have a second __legacyError property
|
|
43
|
-
options
|
|
42
|
+
options?.onResponse({ ...response, request, rawHeaders }, e);
|
|
44
43
|
}
|
|
45
44
|
throw e;
|
|
46
45
|
}
|
|
@@ -51,8 +50,9 @@ export async function sendRequest(method, url, pipeline, options = {}, customHtt
|
|
|
51
50
|
* @returns returns the content-type
|
|
52
51
|
*/
|
|
53
52
|
function getRequestContentType(options = {}) {
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
return (options.contentType ??
|
|
54
|
+
options.headers?.["content-type"] ??
|
|
55
|
+
getContentType(options.body));
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
58
|
* Function to determine the content-type of a body
|
|
@@ -78,14 +78,17 @@ function getContentType(body) {
|
|
|
78
78
|
return "application/json";
|
|
79
79
|
}
|
|
80
80
|
function buildPipelineRequest(method, url, options = {}) {
|
|
81
|
-
var _a, _b, _c;
|
|
82
81
|
const requestContentType = getRequestContentType(options);
|
|
83
82
|
const { body, multipartBody } = getRequestBody(options.body, requestContentType);
|
|
84
83
|
const hasContent = body !== undefined || multipartBody !== undefined;
|
|
85
|
-
const headers = createHttpHeaders(
|
|
86
|
-
|
|
87
|
-
"
|
|
88
|
-
|
|
84
|
+
const headers = createHttpHeaders({
|
|
85
|
+
...(options.headers ? options.headers : {}),
|
|
86
|
+
accept: options.accept ?? options.headers?.accept ?? "application/json",
|
|
87
|
+
...(hasContent &&
|
|
88
|
+
requestContentType && {
|
|
89
|
+
"content-type": requestContentType,
|
|
90
|
+
}),
|
|
91
|
+
});
|
|
89
92
|
return createPipelineRequest({
|
|
90
93
|
url,
|
|
91
94
|
method,
|
|
@@ -141,11 +144,10 @@ function getRequestBody(body, contentType = "") {
|
|
|
141
144
|
* Prepares the response body
|
|
142
145
|
*/
|
|
143
146
|
function getResponseBody(response) {
|
|
144
|
-
var _a, _b;
|
|
145
147
|
// Set the default response type
|
|
146
|
-
const contentType =
|
|
148
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
147
149
|
const firstType = contentType.split(";")[0];
|
|
148
|
-
const bodyToParse =
|
|
150
|
+
const bodyToParse = response.bodyAsText ?? "";
|
|
149
151
|
if (firstType === "text/plain") {
|
|
150
152
|
return String(bodyToParse);
|
|
151
153
|
}
|
|
@@ -165,9 +167,8 @@ function getResponseBody(response) {
|
|
|
165
167
|
}
|
|
166
168
|
}
|
|
167
169
|
function createParseError(response, err) {
|
|
168
|
-
var _a;
|
|
169
170
|
const msg = `Error "${err}" occurred while parsing the response body - ${response.bodyAsText}.`;
|
|
170
|
-
const errCode =
|
|
171
|
+
const errCode = err.code ?? RestError.PARSE_ERROR;
|
|
171
172
|
return new RestError(msg, {
|
|
172
173
|
code: errCode,
|
|
173
174
|
statusCode: response.status,
|
|
@@ -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,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAAmB,EACnB,GAAW,EACX,QAAkB,EAClB,UAAqC,EAAE,EACvC,gBAA6B;;IAE7B,MAAM,UAAU,GAAG,gBAAgB,aAAhB,gBAAgB,cAAhB,gBAAgB,GAAI,2BAA2B,EAAE,CAAC;IACrE,MAAM,OAAO,GAAG,oBAAoB,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAE3D,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACjE,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,C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d,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,MAAA,GAAG,CAAC,IAAI,mCAAI,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 { 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 {\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 (ArrayBuffer.isView(body)) {\n return \"application/octet-stream\";\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 const hasContent = body !== undefined || multipartBody !== undefined;\n\n const headers = createHttpHeaders({\n ...(options.headers ? options.headers : {}),\n accept: options.accept ?? options.headers?.accept ?? \"application/json\",\n ...(hasContent &&\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 */\nfunction 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 (isReadableStream(body)) {\n return { body };\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;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAAmB,EACnB,GAAW,EACX,QAAkB,EAClB,UAAqC,EAAE,EACvC,gBAA6B;IAE7B,MAAM,UAAU,GAAG,gBAAgB,IAAI,2BAA2B,EAAE,CAAC;IACrE,MAAM,OAAO,GAAG,oBAAoB,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAE3D,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACjE,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QAC1C,MAAM,MAAM,GAAG,QAAQ,CAAC,kBAAkB,IAAI,QAAQ,CAAC,iBAAiB,CAAC;QACzE,MAAM,UAAU,GACd,OAAO,CAAC,gBAAgB,IAAI,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,e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E;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 { 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 {\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 (ArrayBuffer.isView(body)) {\n return \"application/octet-stream\";\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 const hasContent = body !== undefined || multipartBody !== undefined;\n\n const headers = createHttpHeaders({\n ...(options.headers ? options.headers : {}),\n accept: options.accept ?? options.headers?.accept ?? \"application/json\",\n ...(hasContent &&\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 */\nfunction 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 (isReadableStream(body)) {\n return { body };\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"]}
|
|
@@ -63,7 +63,6 @@ function getQueryParamValue(key, allowReserved, style, param) {
|
|
|
63
63
|
return `${allowReserved ? key : encodeURIComponent(key)}=${value}`;
|
|
64
64
|
}
|
|
65
65
|
function appendQueryParams(url, options = {}) {
|
|
66
|
-
var _a, _b, _c, _d;
|
|
67
66
|
if (!options.queryParameters) {
|
|
68
67
|
return url;
|
|
69
68
|
}
|
|
@@ -77,18 +76,18 @@ function appendQueryParams(url, options = {}) {
|
|
|
77
76
|
}
|
|
78
77
|
const hasMetadata = isQueryParameterWithOptions(param);
|
|
79
78
|
const rawValue = hasMetadata ? param.value : param;
|
|
80
|
-
const explode = hasMetadata ? (
|
|
79
|
+
const explode = hasMetadata ? (param.explode ?? false) : false;
|
|
81
80
|
const style = hasMetadata && param.style ? param.style : "form";
|
|
82
81
|
if (explode) {
|
|
83
82
|
if (Array.isArray(rawValue)) {
|
|
84
83
|
for (const item of rawValue) {
|
|
85
|
-
paramStrings.push(getQueryParamValue(key,
|
|
84
|
+
paramStrings.push(getQueryParamValue(key, options.skipUrlEncoding ?? false, style, item));
|
|
86
85
|
}
|
|
87
86
|
}
|
|
88
87
|
else if (typeof rawValue === "object") {
|
|
89
88
|
// For object explode, the name of the query parameter is ignored and we use the object key instead
|
|
90
89
|
for (const [actualKey, value] of Object.entries(rawValue)) {
|
|
91
|
-
paramStrings.push(getQueryParamValue(actualKey,
|
|
90
|
+
paramStrings.push(getQueryParamValue(actualKey, options.skipUrlEncoding ?? false, style, value));
|
|
92
91
|
}
|
|
93
92
|
}
|
|
94
93
|
else {
|
|
@@ -97,7 +96,7 @@ function appendQueryParams(url, options = {}) {
|
|
|
97
96
|
}
|
|
98
97
|
}
|
|
99
98
|
else {
|
|
100
|
-
paramStrings.push(getQueryParamValue(key,
|
|
99
|
+
paramStrings.push(getQueryParamValue(key, options.skipUrlEncoding ?? false, style, rawValue));
|
|
101
100
|
}
|
|
102
101
|
}
|
|
103
102
|
if (parsedUrl.search !== "") {
|
|
@@ -107,7 +106,6 @@ function appendQueryParams(url, options = {}) {
|
|
|
107
106
|
return parsedUrl.toString();
|
|
108
107
|
}
|
|
109
108
|
export function buildBaseUrl(endpoint, options) {
|
|
110
|
-
var _a;
|
|
111
109
|
if (!options.pathParameters) {
|
|
112
110
|
return endpoint;
|
|
113
111
|
}
|
|
@@ -123,14 +121,13 @@ export function buildBaseUrl(endpoint, options) {
|
|
|
123
121
|
if (!options.skipUrlEncoding) {
|
|
124
122
|
value = encodeURIComponent(param);
|
|
125
123
|
}
|
|
126
|
-
endpoint =
|
|
124
|
+
endpoint = replaceAll(endpoint, `{${key}}`, value) ?? "";
|
|
127
125
|
}
|
|
128
126
|
return endpoint;
|
|
129
127
|
}
|
|
130
128
|
function buildRoutePath(routePath, pathParameters, options = {}) {
|
|
131
|
-
var _a;
|
|
132
129
|
for (const pathParam of pathParameters) {
|
|
133
|
-
const allowReserved = typeof pathParam === "object" && (
|
|
130
|
+
const allowReserved = typeof pathParam === "object" && (pathParam.allowReserved ?? false);
|
|
134
131
|
let value = typeof pathParam === "object" ? pathParam.value : pathParam;
|
|
135
132
|
if (!options.skipUrlEncoding && !allowReserved) {
|
|
136
133
|
value = encodeURIComponent(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,EA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AAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,cAAc,CACrB,SAAiB,EACjB,cAA8D,EAC9D,UAA6B,EAAE;;IAE/B,KAAK,MAAM,SAAS,IAAI,cAAc,EAAE,CAAC;QACvC,MAAM,aAAa,GAAG,OAAO,SAAS,KAAK,QAAQ,IAAI,CAAC,MAAA,SAAS,CAAC,aAAa,mCAAI,KAAK,CAAC,CAAC;QAC1F,IAAI,KAAK,GAAG,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;QAExE,IAAI,CAAC,OAAO,CAAC,eAAe,IAAI,CAAC,aAAa,EAAE,CAAC;YAC/C,KAAK,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;QACpC,CAAC;QAED,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 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 routePath = buildRoutePath(routePath, pathParameters, options);\n const requestUrl = appendQueryParams(`${endpoint}/${routePath}`, options);\n const url = new URL(requestUrl);\n\n return (\n url\n .toString()\n // Remove double forward slashes\n .replace(/([^:]\\/)\\/+/g, \"$1\")\n );\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\nfunction 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 const paramStrings: 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 paramStrings.push(getQueryParamValue(key, options.skipUrlEncoding ?? false, style, item));\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 paramStrings.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 paramStrings.push(getQueryParamValue(key, options.skipUrlEncoding ?? false, style, rawValue));\n }\n }\n\n if (parsedUrl.search !== \"\") {\n parsedUrl.search += \"&\";\n }\n parsedUrl.search += paramStrings.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,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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ters } 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 routePath = buildRoutePath(routePath, pathParameters, options);\n const requestUrl = appendQueryParams(`${endpoint}/${routePath}`, options);\n const url = new URL(requestUrl);\n\n return (\n url\n .toString()\n // Remove double forward slashes\n .replace(/([^:]\\/)\\/+/g, \"$1\")\n );\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\nfunction 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 const paramStrings: 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 paramStrings.push(getQueryParamValue(key, options.skipUrlEncoding ?? false, style, item));\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 paramStrings.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 paramStrings.push(getQueryParamValue(key, options.skipUrlEncoding ?? false, style, rawValue));\n }\n }\n\n if (parsedUrl.search !== \"\") {\n parsedUrl.search += \"&\";\n }\n parsedUrl.search += paramStrings.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"]}
|