@typespec/ts-http-runtime 0.3.5-alpha.20260310.2 → 0.3.5
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/multipart.js.map +1 -1
- package/dist/browser/client/sendRequest.js +12 -4
- 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/fetchHttpClient.d.ts +5 -0
- package/dist/browser/fetchHttpClient.js.map +1 -1
- package/dist/browser/logger/logger.js.map +1 -1
- package/dist/browser/policies/retryPolicy.js +4 -3
- package/dist/browser/policies/retryPolicy.js.map +1 -1
- package/dist/browser/util/concat.d.ts +16 -1
- package/dist/browser/util/concat.js +55 -1
- package/dist/browser/util/concat.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/typeGuards.js +2 -2
- package/dist/browser/util/typeGuards.js.map +1 -1
- package/dist/browser/util/userAgentPlatform.d.ts +28 -0
- package/dist/browser/util/userAgentPlatform.js +9 -10
- package/dist/browser/util/userAgentPlatform.js.map +1 -1
- 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 +1 -0
- package/dist/commonjs/client/clientHelpers.js.map +1 -1
- package/dist/commonjs/client/common.js +1 -0
- package/dist/commonjs/client/common.js.map +1 -1
- package/dist/commonjs/client/getClient.js +1 -0
- package/dist/commonjs/client/getClient.js.map +1 -1
- 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 +1 -0
- package/dist/commonjs/client/restError.js.map +1 -1
- package/dist/commonjs/client/sendRequest.js +13 -2
- 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 +1 -0
- package/dist/commonjs/constants.js.map +1 -1
- package/dist/commonjs/createPipelineFromOptions.js +1 -0
- package/dist/commonjs/createPipelineFromOptions.js.map +1 -1
- package/dist/commonjs/defaultHttpClient.js +1 -0
- package/dist/commonjs/defaultHttpClient.js.map +1 -1
- package/dist/commonjs/fetchHttpClient.d.ts +5 -0
- package/dist/commonjs/fetchHttpClient.js +1 -0
- package/dist/commonjs/fetchHttpClient.js.map +3 -3
- package/dist/commonjs/httpHeaders.js +1 -0
- package/dist/commonjs/httpHeaders.js.map +1 -1
- package/dist/commonjs/index.js +1 -0
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/interfaces.js +1 -0
- package/dist/commonjs/interfaces.js.map +1 -1
- package/dist/commonjs/log.js +1 -0
- package/dist/commonjs/log.js.map +1 -1
- package/dist/commonjs/logger/debug.js +1 -0
- package/dist/commonjs/logger/debug.js.map +1 -1
- package/dist/commonjs/logger/internal.js +1 -0
- package/dist/commonjs/logger/internal.js.map +1 -1
- package/dist/commonjs/logger/log.common.js +1 -0
- package/dist/commonjs/logger/log.common.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 +1 -0
- package/dist/commonjs/logger/logger.js.map +3 -3
- package/dist/commonjs/nodeHttpClient.js +1 -0
- package/dist/commonjs/nodeHttpClient.js.map +1 -1
- package/dist/commonjs/pipeline.js +1 -0
- package/dist/commonjs/pipeline.js.map +1 -1
- package/dist/commonjs/pipelineRequest.js +1 -0
- package/dist/commonjs/pipelineRequest.js.map +1 -1
- 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 +1 -1
- 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 +1 -0
- package/dist/commonjs/policies/auth/checkInsecureConnection.js.map +1 -1
- 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 +1 -0
- package/dist/commonjs/policies/formDataPolicy.js.map +1 -1
- package/dist/commonjs/policies/internal.js +1 -0
- package/dist/commonjs/policies/internal.js.map +1 -1
- package/dist/commonjs/policies/logPolicy.js +1 -0
- package/dist/commonjs/policies/logPolicy.js.map +1 -1
- package/dist/commonjs/policies/multipartPolicy.js +1 -0
- package/dist/commonjs/policies/multipartPolicy.js.map +1 -1
- package/dist/commonjs/policies/proxyPolicy.common.js +1 -0
- package/dist/commonjs/policies/proxyPolicy.common.js.map +1 -1
- 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 +1 -1
- 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/util/arrayBuffer.js +1 -0
- package/dist/commonjs/util/arrayBuffer.js.map +1 -1
- package/dist/commonjs/util/bytesEncoding.common.js +1 -0
- package/dist/commonjs/util/bytesEncoding.common.js.map +1 -1
- package/dist/commonjs/util/bytesEncoding.js +1 -0
- package/dist/commonjs/util/bytesEncoding.js.map +1 -1
- package/dist/commonjs/util/checkEnvironment.js +1 -0
- package/dist/commonjs/util/checkEnvironment.js.map +1 -1
- package/dist/commonjs/util/concat.js +1 -0
- package/dist/commonjs/util/concat.js.map +1 -1
- 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.common.js +1 -0
- package/dist/commonjs/util/inspect.common.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.js +1 -0
- package/dist/commonjs/util/internal.js.map +1 -1
- 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.common.js +1 -0
- package/dist/commonjs/util/sha256.common.js.map +1 -1
- package/dist/commonjs/util/sha256.js +1 -0
- package/dist/commonjs/util/sha256.js.map +1 -1
- package/dist/commonjs/util/typeGuards.js +3 -2
- package/dist/commonjs/util/typeGuards.js.map +3 -3
- package/dist/commonjs/util/userAgent.js +1 -0
- package/dist/commonjs/util/userAgent.js.map +1 -1
- 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.common.js +2 -1
- package/dist/commonjs/util/uuidUtils.common.js.map +3 -3
- package/dist/commonjs/util/uuidUtils.js +1 -0
- package/dist/commonjs/util/uuidUtils.js.map +1 -1
- package/dist/commonjs/xhrHttpClient.js +1 -0
- package/dist/commonjs/xhrHttpClient.js.map +1 -1
- package/dist/esm/client/multipart.js.map +1 -1
- package/dist/esm/client/sendRequest.js +12 -4
- 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/fetchHttpClient.d.ts +5 -0
- package/dist/esm/fetchHttpClient.js.map +1 -1
- package/dist/esm/logger/logger.js.map +1 -1
- 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/util/sanitizer.js +3 -3
- package/dist/esm/util/sanitizer.js.map +1 -1
- package/dist/esm/util/typeGuards.js +2 -2
- package/dist/esm/util/typeGuards.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/esm/util/uuidUtils.common.js +1 -1
- package/dist/esm/util/uuidUtils.common.js.map +1 -1
- package/dist/react-native/client/multipart.js.map +1 -1
- package/dist/react-native/client/sendRequest.js +12 -4
- 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/fetchHttpClient.d.ts +5 -0
- package/dist/react-native/fetchHttpClient.js.map +1 -1
- package/dist/react-native/logger/logger.js.map +1 -1
- package/dist/react-native/policies/retryPolicy.js +4 -3
- package/dist/react-native/policies/retryPolicy.js.map +1 -1
- package/dist/react-native/util/concat.d.ts +34 -1
- package/dist/react-native/util/concat.js +48 -1
- package/dist/react-native/util/concat.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/typeGuards.js +2 -2
- package/dist/react-native/util/typeGuards.js.map +1 -1
- package/dist/react-native/util/uuidUtils.common.js +1 -1
- package/dist/react-native/util/uuidUtils.common.js.map +1 -1
- package/package.json +10 -8
- 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/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/esm/util/concat.common.d.ts +0 -17
- package/dist/esm/util/concat.common.js +0 -58
- package/dist/esm/util/concat.common.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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../../../src/util/random.ts"],
|
|
4
4
|
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Returns a random integer value between a lower and upper bound,\n * inclusive of both bounds.\n * Note that this uses Math.random and isn't secure. If you need to use\n * this for any kind of security purpose, find a better source of random.\n * @param min - The smallest integer value allowed.\n * @param max - The largest integer value allowed.\n */\nexport function getRandomIntegerInclusive(min: number, max: number): number {\n // Make sure inputs are integers.\n min = Math.ceil(min);\n max = Math.floor(max);\n // Pick a random offset from zero to the size of the range.\n // Since Math.random() can never return 1, we have to make the range one larger\n // in order to be inclusive of the maximum value after we take the floor.\n const offset = Math.floor(Math.random() * (max - min + 1));\n return offset + min;\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWO,SAAS,0BAA0B,KAAa,KAAqB;AAE1E,QAAM,KAAK,KAAK,GAAG;AACnB,QAAM,KAAK,MAAM,GAAG;AAIpB,QAAM,SAAS,KAAK,MAAM,KAAK,OAAO,KAAK,MAAM,MAAM,EAAE;AACzD,SAAO,SAAS;AAClB;",
|
|
6
6
|
"names": []
|
|
@@ -93,11 +93,11 @@ class Sanitizer {
|
|
|
93
93
|
message: value.message
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
|
-
if (key === "headers") {
|
|
96
|
+
if (key === "headers" && (0, import_object.isObject)(value)) {
|
|
97
97
|
return this.sanitizeHeaders(value);
|
|
98
|
-
} else if (key === "url") {
|
|
98
|
+
} else if (key === "url" && typeof value === "string") {
|
|
99
99
|
return this.sanitizeUrl(value);
|
|
100
|
-
} else if (key === "query") {
|
|
100
|
+
} else if (key === "query" && (0, import_object.isObject)(value)) {
|
|
101
101
|
return this.sanitizeQuery(value);
|
|
102
102
|
} else if (key === "body") {
|
|
103
103
|
return void 0;
|
|
@@ -166,3 +166,4 @@ class Sanitizer {
|
|
|
166
166
|
0 && (module.exports = {
|
|
167
167
|
Sanitizer
|
|
168
168
|
});
|
|
169
|
+
//# sourceMappingURL=sanitizer.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { type UnknownObject, isObject } from \"./object.js\";\n\n/**\n * Sanitizer options\n */\nexport interface SanitizerOptions {\n /**\n * Header names whose values will be logged when logging is enabled.\n * Defaults include a list of well-known safe headers. Any headers\n * specified in this field will be added to that list. Any other values will\n * be written to logs as \"REDACTED\".\n */\n additionalAllowedHeaderNames?: string[];\n\n /**\n * Query string names whose values will be logged when logging is enabled. By default no\n * query string values are logged.\n */\n additionalAllowedQueryParameters?: string[];\n}\n\nconst RedactedString = \"REDACTED\";\n\n// Make sure this list is up-to-date with the one under core/logger/Readme#Keyconcepts\nconst defaultAllowedHeaderNames = [\n \"x-ms-client-request-id\",\n \"x-ms-return-client-request-id\",\n \"x-ms-useragent\",\n \"x-ms-correlation-request-id\",\n \"x-ms-request-id\",\n \"client-request-id\",\n \"ms-cv\",\n \"return-client-request-id\",\n \"traceparent\",\n\n \"Access-Control-Allow-Credentials\",\n \"Access-Control-Allow-Headers\",\n \"Access-Control-Allow-Methods\",\n \"Access-Control-Allow-Origin\",\n \"Access-Control-Expose-Headers\",\n \"Access-Control-Max-Age\",\n \"Access-Control-Request-Headers\",\n \"Access-Control-Request-Method\",\n \"Origin\",\n\n \"Accept\",\n \"Accept-Encoding\",\n \"Cache-Control\",\n \"Connection\",\n \"Content-Length\",\n \"Content-Type\",\n \"Date\",\n \"ETag\",\n \"Expires\",\n \"If-Match\",\n \"If-Modified-Since\",\n \"If-None-Match\",\n \"If-Unmodified-Since\",\n \"Last-Modified\",\n \"Pragma\",\n \"Request-Id\",\n \"Retry-After\",\n \"Server\",\n \"Transfer-Encoding\",\n \"User-Agent\",\n \"WWW-Authenticate\",\n];\n\nconst defaultAllowedQueryParameters: string[] = [\"api-version\"];\n\n/**\n * A utility class to sanitize objects for logging.\n */\nexport class Sanitizer {\n private allowedHeaderNames: Set<string>;\n private allowedQueryParameters: Set<string>;\n\n constructor({\n additionalAllowedHeaderNames: allowedHeaderNames = [],\n additionalAllowedQueryParameters: allowedQueryParameters = [],\n }: SanitizerOptions = {}) {\n allowedHeaderNames = defaultAllowedHeaderNames.concat(allowedHeaderNames);\n allowedQueryParameters = defaultAllowedQueryParameters.concat(allowedQueryParameters);\n\n this.allowedHeaderNames = new Set(allowedHeaderNames.map((n) => n.toLowerCase()));\n this.allowedQueryParameters = new Set(allowedQueryParameters.map((p) => p.toLowerCase()));\n }\n\n /**\n * Sanitizes an object for logging.\n * @param obj - The object to sanitize\n * @returns - The sanitized object as a string\n */\n public sanitize(obj: unknown): string {\n const seen = new Set<unknown>();\n return JSON.stringify(\n obj,\n (key: string, value: unknown) => {\n // Ensure Errors include their interesting non-enumerable members\n if (value instanceof Error) {\n return {\n ...value,\n name: value.name,\n message: value.message,\n };\n }\n\n if (key === \"headers\") {\n return this.sanitizeHeaders(value
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA6C;AAqB7C,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src/util/sanitizer.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { type UnknownObject, isObject } from \"./object.js\";\n\n/**\n * Sanitizer options\n */\nexport interface SanitizerOptions {\n /**\n * Header names whose values will be logged when logging is enabled.\n * Defaults include a list of well-known safe headers. Any headers\n * specified in this field will be added to that list. Any other values will\n * be written to logs as \"REDACTED\".\n */\n additionalAllowedHeaderNames?: string[];\n\n /**\n * Query string names whose values will be logged when logging is enabled. By default no\n * query string values are logged.\n */\n additionalAllowedQueryParameters?: string[];\n}\n\nconst RedactedString = \"REDACTED\";\n\n// Make sure this list is up-to-date with the one under core/logger/Readme#Keyconcepts\nconst defaultAllowedHeaderNames = [\n \"x-ms-client-request-id\",\n \"x-ms-return-client-request-id\",\n \"x-ms-useragent\",\n \"x-ms-correlation-request-id\",\n \"x-ms-request-id\",\n \"client-request-id\",\n \"ms-cv\",\n \"return-client-request-id\",\n \"traceparent\",\n\n \"Access-Control-Allow-Credentials\",\n \"Access-Control-Allow-Headers\",\n \"Access-Control-Allow-Methods\",\n \"Access-Control-Allow-Origin\",\n \"Access-Control-Expose-Headers\",\n \"Access-Control-Max-Age\",\n \"Access-Control-Request-Headers\",\n \"Access-Control-Request-Method\",\n \"Origin\",\n\n \"Accept\",\n \"Accept-Encoding\",\n \"Cache-Control\",\n \"Connection\",\n \"Content-Length\",\n \"Content-Type\",\n \"Date\",\n \"ETag\",\n \"Expires\",\n \"If-Match\",\n \"If-Modified-Since\",\n \"If-None-Match\",\n \"If-Unmodified-Since\",\n \"Last-Modified\",\n \"Pragma\",\n \"Request-Id\",\n \"Retry-After\",\n \"Server\",\n \"Transfer-Encoding\",\n \"User-Agent\",\n \"WWW-Authenticate\",\n];\n\nconst defaultAllowedQueryParameters: string[] = [\"api-version\"];\n\n/**\n * A utility class to sanitize objects for logging.\n */\nexport class Sanitizer {\n private allowedHeaderNames: Set<string>;\n private allowedQueryParameters: Set<string>;\n\n constructor({\n additionalAllowedHeaderNames: allowedHeaderNames = [],\n additionalAllowedQueryParameters: allowedQueryParameters = [],\n }: SanitizerOptions = {}) {\n allowedHeaderNames = defaultAllowedHeaderNames.concat(allowedHeaderNames);\n allowedQueryParameters = defaultAllowedQueryParameters.concat(allowedQueryParameters);\n\n this.allowedHeaderNames = new Set(allowedHeaderNames.map((n) => n.toLowerCase()));\n this.allowedQueryParameters = new Set(allowedQueryParameters.map((p) => p.toLowerCase()));\n }\n\n /**\n * Sanitizes an object for logging.\n * @param obj - The object to sanitize\n * @returns - The sanitized object as a string\n */\n public sanitize(obj: unknown): string {\n const seen = new Set<unknown>();\n return JSON.stringify(\n obj,\n (key: string, value: unknown) => {\n // Ensure Errors include their interesting non-enumerable members\n if (value instanceof Error) {\n return {\n ...value,\n name: value.name,\n message: value.message,\n };\n }\n\n if (key === \"headers\" && isObject(value)) {\n return this.sanitizeHeaders(value);\n } else if (key === \"url\" && typeof value === \"string\") {\n return this.sanitizeUrl(value);\n } else if (key === \"query\" && isObject(value)) {\n return this.sanitizeQuery(value);\n } else if (key === \"body\") {\n // Don't log the request body\n return undefined;\n } else if (key === \"response\") {\n // Don't log response again\n return undefined;\n } else if (key === \"operationSpec\") {\n // When using sendOperationRequest, the request carries a massive\n // field with the autorest spec. No need to log it.\n return undefined;\n } else if (Array.isArray(value) || isObject(value)) {\n if (seen.has(value)) {\n return \"[Circular]\";\n }\n seen.add(value);\n }\n\n return value;\n },\n 2,\n );\n }\n\n /**\n * Sanitizes a URL for logging.\n * @param value - The URL to sanitize\n * @returns - The sanitized URL as a string\n */\n public sanitizeUrl(value: string): string {\n if (typeof value !== \"string\" || value === null || value === \"\") {\n return value;\n }\n\n const url = new URL(value);\n\n if (!url.search) {\n return value;\n }\n\n for (const [key] of url.searchParams) {\n if (!this.allowedQueryParameters.has(key.toLowerCase())) {\n url.searchParams.set(key, RedactedString);\n }\n }\n\n return url.toString();\n }\n\n private sanitizeHeaders(obj: UnknownObject): UnknownObject {\n const sanitized: UnknownObject = {};\n for (const key of Object.keys(obj)) {\n if (this.allowedHeaderNames.has(key.toLowerCase())) {\n sanitized[key] = obj[key];\n } else {\n sanitized[key] = RedactedString;\n }\n }\n return sanitized;\n }\n\n private sanitizeQuery(value: UnknownObject): UnknownObject {\n if (typeof value !== \"object\" || value === null) {\n return value;\n }\n\n const sanitized: UnknownObject = {};\n\n for (const k of Object.keys(value)) {\n if (this.allowedQueryParameters.has(k.toLowerCase())) {\n sanitized[k] = value[k];\n } else {\n sanitized[k] = RedactedString;\n }\n }\n\n return sanitized;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA6C;AAqB7C,MAAM,iBAAiB;AAGvB,MAAM,4BAA4B;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,gCAA0C,CAAC,aAAa;AAKvD,MAAM,UAAU;AAAA,EACb;AAAA,EACA;AAAA,EAER,YAAY;AAAA,IACV,8BAA8B,qBAAqB,CAAC;AAAA,IACpD,kCAAkC,yBAAyB,CAAC;AAAA,EAC9D,IAAsB,CAAC,GAAG;AACxB,yBAAqB,0BAA0B,OAAO,kBAAkB;AACxE,6BAAyB,8BAA8B,OAAO,sBAAsB;AAEpF,SAAK,qBAAqB,IAAI,IAAI,mBAAmB,IA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AEA,eAAW,CAAC,GAAG,KAAK,IAAI,cAAc;AACpC,UAAI,CAAC,KAAK,uBAAuB,IAAI,IAAI,YAAY,CAAC,GAAG;AACvD,YAAI,aAAa,IAAI,KAAK,cAAc;AAAA,MAC1C;AAAA,IACF;AAEA,WAAO,IAAI,SAAS;AAAA,EACtB;AAAA,EAEQ,gBAAgB,KAAmC;AACzD,UAAM,YAA2B,CAAC;AAClC,eAAW,OAAO,OAAO,KAAK,GAAG,GAAG;AAClC,UAAI,KAAK,mBAAmB,IAAI,IAAI,YAAY,CAAC,GAAG;AAClD,kBAAU,GAAG,IAAI,IAAI,GAAG;AAAA,MAC1B,OAAO;AACL,kBAAU,GAAG,IAAI;AAAA,MACnB;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEQ,cAAc,OAAqC;AACzD,QAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,aAAO;AAAA,IACT;AAEA,UAAM,YAA2B,CAAC;AAElC,eAAW,KAAK,OAAO,KAAK,KAAK,GAAG;AAClC,UAAI,KAAK,uBAAuB,IAAI,EAAE,YAAY,CAAC,GAAG;AACpD,kBAAU,CAAC,IAAI,MAAM,CAAC;AAAA,MACxB,OAAO;AACL,kBAAU,CAAC,IAAI;AAAA,MACjB;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../../../src/util/sha256.common.ts"],
|
|
4
4
|
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { stringToUint8Array, uint8ArrayToString } from \"./bytesEncoding.js\";\n\n// stubs for browser self.crypto\ninterface JsonWebKey {}\ninterface CryptoKey {}\ntype KeyUsage =\n | \"decrypt\"\n | \"deriveBits\"\n | \"deriveKey\"\n | \"encrypt\"\n | \"sign\"\n | \"unwrapKey\"\n | \"verify\"\n | \"wrapKey\";\ninterface Algorithm {\n name: string;\n}\ninterface SubtleCrypto {\n importKey(\n format: string,\n keyData: JsonWebKey,\n algorithm: HmacImportParams,\n extractable: boolean,\n usage: KeyUsage[],\n ): Promise<CryptoKey>;\n sign(\n algorithm: HmacImportParams,\n key: CryptoKey,\n data: ArrayBufferView | ArrayBuffer,\n ): Promise<ArrayBuffer>;\n digest(algorithm: Algorithm, data: ArrayBufferView | ArrayBuffer): Promise<ArrayBuffer>;\n}\ninterface Crypto {\n readonly subtle: SubtleCrypto;\n getRandomValues<T extends ArrayBufferView | null>(array: T): T;\n}\ndeclare const self: {\n crypto: Crypto;\n};\ninterface HmacImportParams {\n name: string;\n hash: Algorithm;\n length?: number;\n}\n\nlet subtleCrypto: SubtleCrypto | undefined;\n\n/**\n * Returns a cached reference to the Web API crypto.subtle object.\n * @internal\n */\nfunction getCrypto(): SubtleCrypto {\n if (subtleCrypto) {\n return subtleCrypto;\n }\n\n if (!self.crypto || !self.crypto.subtle) {\n throw new Error(\"Your browser environment does not support cryptography functions.\");\n }\n\n subtleCrypto = self.crypto.subtle;\n return subtleCrypto;\n}\n\n/**\n * Generates a SHA-256 HMAC signature.\n * @param key - The HMAC key represented as a base64 string, used to generate the cryptographic HMAC hash.\n * @param stringToSign - The data to be signed.\n * @param encoding - The textual encoding to use for the returned HMAC digest.\n */\nexport async function computeSha256Hmac(\n key: string,\n stringToSign: string,\n encoding: \"base64\" | \"hex\",\n): Promise<string> {\n const crypto = getCrypto();\n const keyBytes = stringToUint8Array(key, \"base64\");\n const stringToSignBytes = stringToUint8Array(stringToSign, \"utf-8\");\n\n const cryptoKey = await crypto.importKey(\n \"raw\",\n keyBytes,\n {\n name: \"HMAC\",\n hash: { name: \"SHA-256\" },\n },\n false,\n [\"sign\"],\n );\n const signature = await crypto.sign(\n {\n name: \"HMAC\",\n hash: { name: \"SHA-256\" },\n },\n cryptoKey,\n stringToSignBytes,\n );\n\n return uint8ArrayToString(new Uint8Array(signature), encoding);\n}\n\n/**\n * Generates a SHA-256 hash.\n * @param content - The data to be included in the hash.\n * @param encoding - The textual encoding to use for the returned hash.\n */\nexport async function computeSha256Hash(\n content: string,\n encoding: \"base64\" | \"hex\",\n): Promise<string> {\n const contentBytes = stringToUint8Array(content, \"utf-8\");\n const digest = await getCrypto().digest({ name: \"SHA-256\" }, contentBytes);\n\n return uint8ArrayToString(new Uint8Array(digest), encoding);\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,2BAAuD;AA6CvD,IAAI;AAMJ,SAAS,YAA0B;AACjC,MAAI,cAAc;AAChB,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,KAAK,UAAU,CAAC,KAAK,OAAO,QAAQ;AACvC,UAAM,IAAI,MAAM,mEAAmE;AAAA,EACrF;AAEA,iBAAe,KAAK,OAAO;AAC3B,SAAO;AACT;AAQA,eAAsB,kBACpB,KACA,cACA,UACiB;AACjB,QAAM,SAAS,UAAU;AACzB,QAAM,eAAW,yCAAmB,KAAK,QAAQ;AACjD,QAAM,wBAAoB,yCAAmB,cAAc,OAAO;AAElE,QAAM,YAAY,MAAM,OAAO;AAAA,IAC7B;AAAA,IACA;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM,EAAE,MAAM,UAAU;AAAA,IAC1B;AAAA,IACA;AAAA,IACA,CAAC,MAAM;AAAA,EACT;AACA,QAAM,YAAY,MAAM,OAAO;AAAA,IAC7B;AAAA,MACE,MAAM;AAAA,MACN,MAAM,EAAE,MAAM,UAAU;AAAA,IAC1B;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,aAAO,yCAAmB,IAAI,WAAW,SAAS,GAAG,QAAQ;AAC/D;AAOA,eAAsB,kBACpB,SACA,UACiB;AACjB,QAAM,mBAAe,yCAAmB,SAAS,OAAO;AACxD,QAAM,SAAS,MAAM,UAAU,EAAE,OAAO,EAAE,MAAM,UAAU,GAAG,YAAY;AAEzE,aAAO,yCAAmB,IAAI,WAAW,MAAM,GAAG,QAAQ;AAC5D;",
|
|
6
6
|
"names": []
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../../../src/util/sha256.ts"],
|
|
4
4
|
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { createHash, createHmac } from \"node:crypto\";\n\n/**\n * Generates a SHA-256 HMAC signature.\n * @param key - The HMAC key represented as a base64 string, used to generate the cryptographic HMAC hash.\n * @param stringToSign - The data to be signed.\n * @param encoding - The textual encoding to use for the returned HMAC digest.\n */\nexport async function computeSha256Hmac(\n key: string,\n stringToSign: string,\n encoding: \"base64\" | \"hex\",\n): Promise<string> {\n const decodedKey = Buffer.from(key, \"base64\");\n\n return createHmac(\"sha256\", decodedKey).update(stringToSign).digest(encoding);\n}\n\n/**\n * Generates a SHA-256 hash.\n * @param content - The data to be included in the hash.\n * @param encoding - The textual encoding to use for the returned hash.\n */\nexport async function computeSha256Hash(\n content: string,\n encoding: \"base64\" | \"hex\",\n): Promise<string> {\n return createHash(\"sha256\").update(content).digest(encoding);\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yBAAuC;AAQvC,eAAsB,kBACpB,KACA,cACA,UACiB;AACjB,QAAM,aAAa,OAAO,KAAK,KAAK,QAAQ;AAE5C,aAAO,+BAAW,UAAU,UAAU,EAAE,OAAO,YAAY,EAAE,OAAO,QAAQ;AAC9E;AAOA,eAAsB,kBACpB,SACA,UACiB;AACjB,aAAO,+BAAW,QAAQ,EAAE,OAAO,OAAO,EAAE,OAAO,QAAQ;AAC7D;",
|
|
6
6
|
"names": []
|
|
@@ -33,13 +33,13 @@ function isWebReadableStream(x) {
|
|
|
33
33
|
);
|
|
34
34
|
}
|
|
35
35
|
function isBinaryBody(body) {
|
|
36
|
-
return body !== void 0 && (body instanceof Uint8Array || isReadableStream(body) || typeof body === "function" || body instanceof Blob);
|
|
36
|
+
return body !== void 0 && (body instanceof Uint8Array || isReadableStream(body) || typeof body === "function" || typeof Blob !== "undefined" && body instanceof Blob);
|
|
37
37
|
}
|
|
38
38
|
function isReadableStream(x) {
|
|
39
39
|
return isNodeReadableStream(x) || isWebReadableStream(x);
|
|
40
40
|
}
|
|
41
41
|
function isBlob(x) {
|
|
42
|
-
return typeof
|
|
42
|
+
return typeof Blob !== "undefined" && x instanceof Blob;
|
|
43
43
|
}
|
|
44
44
|
// Annotate the CommonJS export names for ESM import in node:
|
|
45
45
|
0 && (module.exports = {
|
|
@@ -49,3 +49,4 @@ function isBlob(x) {
|
|
|
49
49
|
isReadableStream,
|
|
50
50
|
isWebReadableStream
|
|
51
51
|
});
|
|
52
|
+
//# sourceMappingURL=typeGuards.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport function isNodeReadableStream(x: unknown): x is NodeJS.ReadableStream {\n return Boolean(x && typeof (x as NodeJS.ReadableStream)[\"pipe\"] === \"function\");\n}\n\nexport function isWebReadableStream(x: unknown): x is ReadableStream {\n return Boolean(\n x &&\n typeof (x as ReadableStream).getReader === \"function\" &&\n typeof (x as ReadableStream).tee === \"function\",\n );\n}\n\nexport function isBinaryBody(\n body: unknown,\n): body is\n | Uint8Array\n | NodeJS.ReadableStream\n | ReadableStream<Uint8Array>\n | (() => NodeJS.ReadableStream)\n | (() => ReadableStream<Uint8Array>)\n | Blob {\n return (\n body !== undefined &&\n (body instanceof Uint8Array ||\n isReadableStream(body) ||\n typeof body === \"function\" ||\n body instanceof Blob)\n );\n}\n\nexport function isReadableStream(x: unknown): x is ReadableStream | NodeJS.ReadableStream {\n return isNodeReadableStream(x) || isWebReadableStream(x);\n}\n\nexport function isBlob(x: unknown): x is Blob {\n return typeof
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,SAAS,qBAAqB,GAAwC;AAC3E,SAAO,QAAQ,KAAK,OAAQ,EAA4B,MAAM,MAAM,UAAU;AAChF;AAEO,SAAS,oBAAoB,GAAiC;AACnE,SAAO;AAAA,IACL,KACA,OAAQ,EAAqB,cAAc,cAC3C,OAAQ,EAAqB,QAAQ;AAAA,EACvC;AACF;AAEO,SAAS,aACd,MAOO;AACP,SACE,SAAS,WACR,gBAAgB,cACf,iBAAiB,IAAI,KACrB,OAAO,SAAS,
|
|
3
|
+
"sources": ["../../../src/util/typeGuards.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport function isNodeReadableStream(x: unknown): x is NodeJS.ReadableStream {\n return Boolean(x && typeof (x as NodeJS.ReadableStream)[\"pipe\"] === \"function\");\n}\n\nexport function isWebReadableStream(x: unknown): x is ReadableStream {\n return Boolean(\n x &&\n typeof (x as ReadableStream).getReader === \"function\" &&\n typeof (x as ReadableStream).tee === \"function\",\n );\n}\n\nexport function isBinaryBody(\n body: unknown,\n): body is\n | Uint8Array\n | NodeJS.ReadableStream\n | ReadableStream<Uint8Array>\n | (() => NodeJS.ReadableStream)\n | (() => ReadableStream<Uint8Array>)\n | Blob {\n return (\n body !== undefined &&\n (body instanceof Uint8Array ||\n isReadableStream(body) ||\n typeof body === \"function\" ||\n (typeof Blob !== \"undefined\" && body instanceof Blob))\n );\n}\n\nexport function isReadableStream(x: unknown): x is ReadableStream | NodeJS.ReadableStream {\n return isNodeReadableStream(x) || isWebReadableStream(x);\n}\n\nexport function isBlob(x: unknown): x is Blob {\n return typeof Blob !== \"undefined\" && x instanceof Blob;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,SAAS,qBAAqB,GAAwC;AAC3E,SAAO,QAAQ,KAAK,OAAQ,EAA4B,MAAM,MAAM,UAAU;AAChF;AAEO,SAAS,oBAAoB,GAAiC;AACnE,SAAO;AAAA,IACL,KACA,OAAQ,EAAqB,cAAc,cAC3C,OAAQ,EAAqB,QAAQ;AAAA,EACvC;AACF;AAEO,SAAS,aACd,MAOO;AACP,SACE,SAAS,WACR,gBAAgB,cACf,iBAAiB,IAAI,KACrB,OAAO,SAAS,cACf,OAAO,SAAS,eAAe,gBAAgB;AAEtD;AAEO,SAAS,iBAAiB,GAAyD;AACxF,SAAO,qBAAqB,CAAC,KAAK,oBAAoB,CAAC;AACzD;AAEO,SAAS,OAAO,GAAuB;AAC5C,SAAO,OAAO,SAAS,eAAe,aAAa;AACrD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../../../src/util/userAgent.ts"],
|
|
4
4
|
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { getHeaderName, setPlatformSpecificData } from \"./userAgentPlatform.js\";\nimport { SDK_VERSION } from \"../constants.js\";\n\nfunction getUserAgentString(telemetryInfo: Map<string, string>): string {\n const parts: string[] = [];\n for (const [key, value] of telemetryInfo) {\n const token = value ? `${key}/${value}` : key;\n parts.push(token);\n }\n return parts.join(\" \");\n}\n\n/**\n * @internal\n */\nexport function getUserAgentHeaderName(): string {\n return getHeaderName();\n}\n\n/**\n * @internal\n */\nexport async function getUserAgentValue(prefix?: string): Promise<string> {\n const runtimeInfo = new Map<string, string>();\n runtimeInfo.set(\"ts-http-runtime\", SDK_VERSION);\n await setPlatformSpecificData(runtimeInfo);\n const defaultAgent = getUserAgentString(runtimeInfo);\n const userAgentValue = prefix ? `${prefix} ${defaultAgent}` : defaultAgent;\n return userAgentValue;\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,+BAAuD;AACvD,uBAA4B;AAE5B,SAAS,mBAAmB,eAA4C;AACtE,QAAM,QAAkB,CAAC;AACzB,aAAW,CAAC,KAAK,KAAK,KAAK,eAAe;AACxC,UAAM,QAAQ,QAAQ,GAAG,GAAG,IAAI,KAAK,KAAK;AAC1C,UAAM,KAAK,KAAK;AAAA,EAClB;AACA,SAAO,MAAM,KAAK,GAAG;AACvB;AAKO,SAAS,yBAAiC;AAC/C,aAAO,wCAAc;AACvB;AAKA,eAAsB,kBAAkB,QAAkC;AACxE,QAAM,cAAc,oBAAI,IAAoB;AAC5C,cAAY,IAAI,mBAAmB,4BAAW;AAC9C,YAAM,kDAAwB,WAAW;AACzC,QAAM,eAAe,mBAAmB,WAAW;AACnD,QAAM,iBAAiB,SAAS,GAAG,MAAM,IAAI,YAAY,KAAK;AAC9D,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
@@ -39,13 +39,12 @@ function getHeaderName() {
|
|
|
39
39
|
async function setPlatformSpecificData(map) {
|
|
40
40
|
if (import_node_process.default && import_node_process.default.versions) {
|
|
41
41
|
const osInfo = `${import_node_os.default.type()} ${import_node_os.default.release()}; ${import_node_os.default.arch()}`;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
map.set("Node", `${versions.node} (${osInfo})`);
|
|
42
|
+
if (import_node_process.default.versions.bun) {
|
|
43
|
+
map.set("Bun", `${import_node_process.default.versions.bun} (${osInfo})`);
|
|
44
|
+
} else if (import_node_process.default.versions.deno) {
|
|
45
|
+
map.set("Deno", `${import_node_process.default.versions.deno} (${osInfo})`);
|
|
46
|
+
} else if (import_node_process.default.versions.node) {
|
|
47
|
+
map.set("Node", `${import_node_process.default.versions.node} (${osInfo})`);
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
50
|
}
|
|
@@ -54,3 +53,4 @@ async function setPlatformSpecificData(map) {
|
|
|
54
53
|
getHeaderName,
|
|
55
54
|
setPlatformSpecificData
|
|
56
55
|
});
|
|
56
|
+
//# sourceMappingURL=userAgentPlatform.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport os from \"node:os\";\nimport process from \"node:process\";\n\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAe;AACf,0BAAoB;
|
|
3
|
+
"sources": ["../../../src/util/userAgentPlatform.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport os from \"node:os\";\nimport process from \"node:process\";\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace NodeJS {\n interface ProcessVersions {\n bun?: string;\n deno?: string;\n }\n }\n}\n\n/**\n * @internal\n */\nexport function getHeaderName(): string {\n return \"User-Agent\";\n}\n\n/**\n * @internal\n */\nexport async function setPlatformSpecificData(map: Map<string, string>): Promise<void> {\n if (process && process.versions) {\n const osInfo = `${os.type()} ${os.release()}; ${os.arch()}`;\n if (process.versions.bun) {\n map.set(\"Bun\", `${process.versions.bun} (${osInfo})`);\n } else if (process.versions.deno) {\n map.set(\"Deno\", `${process.versions.deno} (${osInfo})`);\n } else if (process.versions.node) {\n map.set(\"Node\", `${process.versions.node} (${osInfo})`);\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAe;AACf,0BAAoB;AAeb,SAAS,gBAAwB;AACtC,SAAO;AACT;AAKA,eAAsB,wBAAwB,KAAyC;AACrF,MAAI,oBAAAA,WAAW,oBAAAA,QAAQ,UAAU;AAC/B,UAAM,SAAS,GAAG,eAAAC,QAAG,KAAK,CAAC,IAAI,eAAAA,QAAG,QAAQ,CAAC,KAAK,eAAAA,QAAG,KAAK,CAAC;AACzD,QAAI,oBAAAD,QAAQ,SAAS,KAAK;AACxB,UAAI,IAAI,OAAO,GAAG,oBAAAA,QAAQ,SAAS,GAAG,KAAK,MAAM,GAAG;AAAA,IACtD,WAAW,oBAAAA,QAAQ,SAAS,MAAM;AAChC,UAAI,IAAI,QAAQ,GAAG,oBAAAA,QAAQ,SAAS,IAAI,KAAK,MAAM,GAAG;AAAA,IACxD,WAAW,oBAAAA,QAAQ,SAAS,MAAM;AAChC,UAAI,IAAI,QAAQ,GAAG,oBAAAA,QAAQ,SAAS,IAAI,KAAK,MAAM,GAAG;AAAA,IACxD;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["process", "os"]
|
|
7
7
|
}
|
|
@@ -28,7 +28,7 @@ function generateUUID() {
|
|
|
28
28
|
if (i === 12) {
|
|
29
29
|
uuid += "4";
|
|
30
30
|
} else if (i === 16) {
|
|
31
|
-
uuid += randomNumber & 3 | 8;
|
|
31
|
+
uuid += (randomNumber & 3 | 8).toString(16);
|
|
32
32
|
} else {
|
|
33
33
|
uuid += randomNumber.toString(16);
|
|
34
34
|
}
|
|
@@ -46,3 +46,4 @@ function randomUUID() {
|
|
|
46
46
|
generateUUID,
|
|
47
47
|
randomUUID
|
|
48
48
|
});
|
|
49
|
+
//# sourceMappingURL=uuidUtils.common.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Generated Universally Unique Identifier\n *\n * @returns RFC4122 v4 UUID.\n */\nexport function generateUUID(): string {\n let uuid = \"\";\n for (let i = 0; i < 32; i++) {\n // Generate a random number between 0 and 15\n const randomNumber = Math.floor(Math.random() * 16);\n // Set the UUID version to 4 in the 13th position\n if (i === 12) {\n uuid += \"4\";\n } else if (i === 16) {\n // Set the UUID variant to \"10\" in the 17th position\n uuid += (randomNumber & 0x3) | 0x8;\n } else {\n // Add a random hexadecimal digit to the UUID string\n uuid += randomNumber.toString(16);\n }\n // Add hyphens to the UUID string at the appropriate positions\n if (i === 7 || i === 11 || i === 15 || i === 19) {\n uuid += \"-\";\n }\n }\n return uuid;\n}\n\n/**\n * Generated Universally Unique Identifier\n *\n * @returns RFC4122 v4 UUID.\n */\nexport function randomUUID(): string {\n return generateUUID();\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQO,SAAS,eAAuB;AACrC,MAAI,OAAO;AACX,WAAS,IAAI,GAAG,IAAI,IAAI,KAAK;AAE3B,UAAM,eAAe,KAAK,MAAM,KAAK,OAAO,IAAI,EAAE;AAElD,QAAI,MAAM,IAAI;AACZ,cAAQ;AAAA,IACV,WAAW,MAAM,IAAI;AAEnB,
|
|
3
|
+
"sources": ["../../../src/util/uuidUtils.common.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Generated Universally Unique Identifier\n *\n * @returns RFC4122 v4 UUID.\n */\nexport function generateUUID(): string {\n let uuid = \"\";\n for (let i = 0; i < 32; i++) {\n // Generate a random number between 0 and 15\n const randomNumber = Math.floor(Math.random() * 16);\n // Set the UUID version to 4 in the 13th position\n if (i === 12) {\n uuid += \"4\";\n } else if (i === 16) {\n // Set the UUID variant to \"10\" in the 17th position\n uuid += ((randomNumber & 0x3) | 0x8).toString(16);\n } else {\n // Add a random hexadecimal digit to the UUID string\n uuid += randomNumber.toString(16);\n }\n // Add hyphens to the UUID string at the appropriate positions\n if (i === 7 || i === 11 || i === 15 || i === 19) {\n uuid += \"-\";\n }\n }\n return uuid;\n}\n\n/**\n * Generated Universally Unique Identifier\n *\n * @returns RFC4122 v4 UUID.\n */\nexport function randomUUID(): string {\n return generateUUID();\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQO,SAAS,eAAuB;AACrC,MAAI,OAAO;AACX,WAAS,IAAI,GAAG,IAAI,IAAI,KAAK;AAE3B,UAAM,eAAe,KAAK,MAAM,KAAK,OAAO,IAAI,EAAE;AAElD,QAAI,MAAM,IAAI;AACZ,cAAQ;AAAA,IACV,WAAW,MAAM,IAAI;AAEnB,eAAU,eAAe,IAAO,GAAK,SAAS,EAAE;AAAA,IAClD,OAAO;AAEL,cAAQ,aAAa,SAAS,EAAE;AAAA,IAClC;AAEA,QAAI,MAAM,KAAK,MAAM,MAAM,MAAM,MAAM,MAAM,IAAI;AAC/C,cAAQ;AAAA,IACV;AAAA,EACF;AACA,SAAO;AACT;AAOO,SAAS,aAAqB;AACnC,SAAO,aAAa;AACtB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../../../src/util/uuidUtils.ts"],
|
|
4
4
|
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Generated Universally Unique Identifier\n *\n * @returns RFC4122 v4 UUID.\n */\nexport function randomUUID(): string {\n return crypto.randomUUID();\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQO,SAAS,aAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;",
|
|
6
6
|
"names": []
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../../src/xhrHttpClient.ts"],
|
|
4
4
|
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { AbortError } from \"./abort-controller/AbortError.js\";\nimport type {\n HttpClient,\n HttpHeaders,\n PipelineRequest,\n PipelineResponse,\n TransferProgressEvent,\n} from \"./interfaces.js\";\nimport { createHttpHeaders } from \"./httpHeaders.js\";\nimport { RestError } from \"./restError.js\";\nimport { isReadableStream } from \"./util/typeGuards.js\";\nimport { arrayBufferViewToArrayBuffer } from \"./util/arrayBuffer.js\";\n\n/**\n * A HttpClient implementation that uses XMLHttpRequest to send HTTP requests.\n * @internal\n */\nclass XhrHttpClient implements HttpClient {\n /**\n * Makes a request over an underlying transport layer and returns the response.\n * @param request - The request to be made.\n */\n public async sendRequest(request: PipelineRequest): Promise<PipelineResponse> {\n const url = new URL(request.url);\n const isInsecure = url.protocol !== \"https:\";\n\n if (isInsecure && !request.allowInsecureConnection) {\n throw new Error(`Cannot connect to ${request.url} while allowInsecureConnection is false.`);\n }\n\n const xhr = new XMLHttpRequest();\n\n if (request.proxySettings) {\n throw new Error(\"HTTP proxy is not supported in browser environment\");\n }\n\n const abortSignal = request.abortSignal;\n if (abortSignal) {\n if (abortSignal.aborted) {\n throw new AbortError(\"The operation was aborted. Request has already been canceled.\");\n }\n\n const listener = (): void => {\n xhr.abort();\n };\n abortSignal.addEventListener(\"abort\", listener);\n xhr.addEventListener(\"readystatechange\", () => {\n if (xhr.readyState === XMLHttpRequest.DONE) {\n abortSignal.removeEventListener(\"abort\", listener);\n }\n });\n }\n\n addProgressListener(xhr.upload, request.onUploadProgress);\n addProgressListener(xhr, request.onDownloadProgress);\n\n xhr.open(request.method, request.url);\n xhr.timeout = request.timeout;\n xhr.withCredentials = request.withCredentials;\n for (const [name, value] of request.headers) {\n xhr.setRequestHeader(name, value);\n }\n\n xhr.responseType = request.streamResponseStatusCodes?.size ? \"blob\" : \"text\";\n\n const body = typeof request.body === \"function\" ? request.body() : request.body;\n if (isReadableStream(body)) {\n throw new Error(\"streams are not supported in XhrHttpClient.\");\n }\n\n if (body instanceof ArrayBuffer) {\n xhr.send(body);\n } else if (typeof body === \"object\" && body && \"buffer\" in body) {\n xhr.send(arrayBufferViewToArrayBuffer(body));\n } else {\n xhr.send(body === undefined ? null : body);\n }\n\n if (xhr.responseType === \"blob\") {\n return new Promise((resolve, reject) => {\n handleBlobResponse(xhr, request, resolve, reject);\n rejectOnTerminalEvent(request, xhr, reject);\n });\n } else {\n return new Promise(function (resolve, reject) {\n xhr.addEventListener(\"load\", () =>\n resolve({\n request,\n status: xhr.status,\n headers: parseHeaders(xhr),\n bodyAsText: xhr.responseText,\n }),\n );\n rejectOnTerminalEvent(request, xhr, reject);\n });\n }\n }\n}\n\nfunction handleBlobResponse(\n xhr: XMLHttpRequest,\n request: PipelineRequest,\n res: (value: PipelineResponse | PromiseLike<PipelineResponse>) => void,\n rej: (reason?: any) => void,\n): void {\n xhr.addEventListener(\"readystatechange\", () => {\n // Resolve as soon as headers are loaded\n if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {\n if (\n // Value of POSITIVE_INFINITY in streamResponseStatusCodes is considered as any status code\n request.streamResponseStatusCodes?.has(Number.POSITIVE_INFINITY) ||\n request.streamResponseStatusCodes?.has(xhr.status)\n ) {\n const blobBody = new Promise<Blob>((resolve, reject) => {\n xhr.addEventListener(\"load\", () => {\n resolve(xhr.response);\n });\n rejectOnTerminalEvent(request, xhr, reject);\n });\n res({\n request,\n status: xhr.status,\n headers: parseHeaders(xhr),\n blobBody,\n });\n } else {\n xhr.addEventListener(\"load\", () => {\n // xhr.response is of Blob type if the request is sent with xhr.responseType === \"blob\"\n // but the status code is not one of the stream response status codes,\n // so treat it as text and convert from Blob to text\n if (xhr.response) {\n xhr.response\n .text()\n .then((text: string) => {\n res({\n request: request,\n status: xhr.status,\n headers: parseHeaders(xhr),\n bodyAsText: text,\n });\n return;\n })\n .catch((e: any) => {\n rej(e);\n });\n } else {\n res({\n request,\n status: xhr.status,\n headers: parseHeaders(xhr),\n });\n }\n });\n }\n }\n });\n}\n\nfunction addProgressListener(\n xhr: XMLHttpRequestEventTarget,\n listener?: (progress: TransferProgressEvent) => void,\n): void {\n if (listener) {\n xhr.addEventListener(\"progress\", (rawEvent) =>\n listener({\n loadedBytes: rawEvent.loaded,\n }),\n );\n }\n}\n\nfunction parseHeaders(xhr: XMLHttpRequest): HttpHeaders {\n const responseHeaders = createHttpHeaders();\n const headerLines = xhr\n .getAllResponseHeaders()\n .trim()\n .split(/[\\r\\n]+/);\n for (const line of headerLines) {\n const index = line.indexOf(\":\");\n const headerName = line.slice(0, index);\n const headerValue = line.slice(index + 2);\n responseHeaders.set(headerName, headerValue);\n }\n return responseHeaders;\n}\n\nfunction rejectOnTerminalEvent(\n request: PipelineRequest,\n xhr: XMLHttpRequest,\n reject: (err: any) => void,\n): void {\n xhr.addEventListener(\"error\", () =>\n reject(\n new RestError(`Failed to send request to ${request.url}`, {\n code: RestError.REQUEST_SEND_ERROR,\n request,\n }),\n ),\n );\n const abortError = new AbortError(\"The operation was aborted.\");\n xhr.addEventListener(\"abort\", () => reject(abortError));\n xhr.addEventListener(\"timeout\", () => reject(abortError));\n}\n\n/**\n * Create a new HttpClient instance for the browser environment.\n * @internal\n */\nexport function createXhrHttpClient(): HttpClient {\n return new XhrHttpClient();\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAA2B;AAQ3B,yBAAkC;AAClC,uBAA0B;AAC1B,wBAAiC;AACjC,yBAA6C;AAM7C,MAAM,cAAoC;AAAA;AAAA;AAAA;AAAA;AAAA,EAKxC,MAAa,YAAY,SAAqD;AAC5E,UAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;AAC/B,UAAM,aAAa,IAAI,aAAa;AAEpC,QAAI,cAAc,CAAC,QAAQ,yBAAyB;AAClD,YAAM,IAAI,MAAM,qBAAqB,QAAQ,GAAG,0CAA0C;AAA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UACL,OAAO;AACL,gBAAI;AAAA,cACF;AAAA,cACA,QAAQ,IAAI;AAAA,cACZ,SAAS,aAAa,GAAG;AAAA,YAC3B,CAAC;AAAA,UACH;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEA,SAAS,oBACP,KACA,UACM;AACN,MAAI,UAAU;AACZ,QAAI;AAAA,MAAiB;AAAA,MAAY,CAAC,aAChC,SAAS;AAAA,QACP,aAAa,SAAS;AAAA,MACxB,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,SAAS,aAAa,KAAkC;AACtD,QAAM,sBAAkB,sCAAkB;AAC1C,QAAM,cAAc,IACjB,sBAAsB,EACtB,KAAK,EACL,MAAM,SAAS;AAClB,aAAW,QAAQ,aAAa;AAC9B,UAAM,QAAQ,KAAK,QAAQ,GAAG;AAC9B,UAAM,aAAa,KAAK,MAAM,GAAG,KAAK;AACtC,UAAM,cAAc,KAAK,MAAM,QAAQ,CAAC;AACxC,oBAAgB,IAAI,YAAY,WAAW;AAAA,EAC7C;AACA,SAAO;AACT;AAEA,SAAS,sBACP,SACA,KACA,QACM;AACN,MAAI;AAAA,IAAiB;AAAA,IAAS,MAC5B;AAAA,MACE,IAAI,2BAAU,6BAA6B,QAAQ,GAAG,IAAI;AAAA,QACxD,MAAM,2BAAU;AAAA,QAChB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACA,QAAM,aAAa,IAAI,6BAAW,4BAA4B;AAC9D,MAAI,iBAAiB,SAAS,MAAM,OAAO,UAAU,CAAC;AACtD,MAAI,iBAAiB,WAAW,MAAM,OAAO,UAAU,CAAC;AAC1D;AAMO,SAAS,sBAAkC;AAChD,SAAO,IAAI,cAAc;AAC3B;",
|
|
6
6
|
"names": []
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multipart.js","sourceRoot":"","sources":["../../../src/client/multipart.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGl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AAU,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,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,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,CAAC;QAC3B,OAAO,UAAU,CAAC,WAAW,CAAC;IAChC,CAAC;IAED,MAAM,EAAE,IAAI,EAA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C;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 \"../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.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"]}
|
|
@@ -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
|
|
@@ -123,9 +128,12 @@ export function getRequestBody(body, contentType = "") {
|
|
|
123
128
|
if (isBlob(body)) {
|
|
124
129
|
return { body };
|
|
125
130
|
}
|
|
126
|
-
if (isReadableStream(body)
|
|
131
|
+
if (isReadableStream(body)) {
|
|
127
132
|
return { body };
|
|
128
133
|
}
|
|
134
|
+
if (typeof body === "function") {
|
|
135
|
+
return { body: body };
|
|
136
|
+
}
|
|
129
137
|
if (ArrayBuffer.isView(body)) {
|
|
130
138
|
return { body: body instanceof Uint8Array ? body : JSON.stringify(body) };
|
|
131
139
|
}
|
|
@@ -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,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M;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 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,EAA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,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 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)) {\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 { 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,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));
|