@azure-rest/core-client 1.3.1 → 1.3.2-alpha.20240329.3
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/clientHelpers.js +4 -3
- package/dist/browser/clientHelpers.js.map +1 -1
- package/dist/browser/getClient.js +10 -8
- package/dist/browser/getClient.js.map +1 -1
- package/dist/browser/operationOptionHelpers.js +7 -6
- package/dist/browser/operationOptionHelpers.js.map +1 -1
- package/dist/browser/restError.js +4 -2
- package/dist/browser/restError.js.map +1 -1
- package/dist/browser/sendRequest.js +18 -19
- package/dist/browser/sendRequest.js.map +1 -1
- package/dist/browser/urlHelpers.js +2 -1
- package/dist/browser/urlHelpers.js.map +1 -1
- package/dist/commonjs/clientHelpers.js +4 -3
- package/dist/commonjs/clientHelpers.js.map +1 -1
- package/dist/commonjs/getClient.js +10 -8
- package/dist/commonjs/getClient.js.map +1 -1
- package/dist/commonjs/operationOptionHelpers.js +7 -6
- package/dist/commonjs/operationOptionHelpers.js.map +1 -1
- package/dist/commonjs/restError.js +4 -2
- package/dist/commonjs/restError.js.map +1 -1
- package/dist/commonjs/sendRequest.js +18 -19
- package/dist/commonjs/sendRequest.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +1 -1
- package/dist/commonjs/urlHelpers.js +2 -1
- package/dist/commonjs/urlHelpers.js.map +1 -1
- package/dist/esm/clientHelpers.js +4 -3
- package/dist/esm/clientHelpers.js.map +1 -1
- package/dist/esm/getClient.js +10 -8
- package/dist/esm/getClient.js.map +1 -1
- package/dist/esm/operationOptionHelpers.js +7 -6
- package/dist/esm/operationOptionHelpers.js.map +1 -1
- package/dist/esm/restError.js +4 -2
- package/dist/esm/restError.js.map +1 -1
- package/dist/esm/sendRequest.js +18 -19
- package/dist/esm/sendRequest.js.map +1 -1
- package/dist/esm/urlHelpers.js +2 -1
- package/dist/esm/urlHelpers.js.map +1 -1
- package/dist/react-native/clientHelpers.js +4 -3
- package/dist/react-native/clientHelpers.js.map +1 -1
- package/dist/react-native/getClient.js +10 -8
- package/dist/react-native/getClient.js.map +1 -1
- package/dist/react-native/operationOptionHelpers.js +7 -6
- package/dist/react-native/operationOptionHelpers.js.map +1 -1
- package/dist/react-native/restError.js +4 -2
- package/dist/react-native/restError.js.map +1 -1
- package/dist/react-native/sendRequest.js +18 -19
- package/dist/react-native/sendRequest.js.map +1 -1
- package/dist/react-native/urlHelpers.js +2 -1
- package/dist/react-native/urlHelpers.js.map +1 -1
- package/package.json +4 -4
|
@@ -9,6 +9,7 @@ let cachedHttpClient;
|
|
|
9
9
|
* Adds a credential policy to the pipeline if a credential is provided. If none is provided, no policy is added.
|
|
10
10
|
*/
|
|
11
11
|
export function addCredentialPipelinePolicy(pipeline, endpoint, options = {}) {
|
|
12
|
+
var _a, _b, _c, _d;
|
|
12
13
|
const { credential, clientOptions } = options;
|
|
13
14
|
if (!credential) {
|
|
14
15
|
return;
|
|
@@ -16,15 +17,15 @@ export function addCredentialPipelinePolicy(pipeline, endpoint, options = {}) {
|
|
|
16
17
|
if (isTokenCredential(credential)) {
|
|
17
18
|
const tokenPolicy = bearerTokenAuthenticationPolicy({
|
|
18
19
|
credential,
|
|
19
|
-
scopes: clientOptions
|
|
20
|
+
scopes: (_b = (_a = clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.credentials) === null || _a === void 0 ? void 0 : _a.scopes) !== null && _b !== void 0 ? _b : `${endpoint}/.default`,
|
|
20
21
|
});
|
|
21
22
|
pipeline.addPolicy(tokenPolicy);
|
|
22
23
|
}
|
|
23
24
|
else if (isKeyCredential(credential)) {
|
|
24
|
-
if (!clientOptions
|
|
25
|
+
if (!((_c = clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.credentials) === null || _c === void 0 ? void 0 : _c.apiKeyHeaderName)) {
|
|
25
26
|
throw new Error(`Missing API Key Header Name`);
|
|
26
27
|
}
|
|
27
|
-
const keyPolicy = keyCredentialAuthenticationPolicy(credential, clientOptions
|
|
28
|
+
const keyPolicy = keyCredentialAuthenticationPolicy(credential, (_d = clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.credentials) === null || _d === void 0 ? void 0 : _d.apiKeyHeaderName);
|
|
28
29
|
pipeline.addPolicy(keyPolicy);
|
|
29
30
|
}
|
|
30
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientHelpers.js","sourceRoot":"","sources":["../../src/clientHelpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAGL,+BAA+B,EAC/B,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAkC,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrF,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAE3F,IAAI,gBAAwC,CAAC;AAgB7C;;GAEG;AACH,MAAM,UAAU,2BAA2B,CACzC,QAAkB,EAClB,QAAgB,EAChB,UAA8C,EAAE
|
|
1
|
+
{"version":3,"file":"clientHelpers.js","sourceRoot":"","sources":["../../src/clientHelpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAGL,+BAA+B,EAC/B,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAkC,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrF,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAE3F,IAAI,gBAAwC,CAAC;AAgB7C;;GAEG;AACH,MAAM,UAAU,2BAA2B,CACzC,QAAkB,EAClB,QAAgB,EAChB,UAA8C,EAAE;;IAEhD,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IAC9C,IAAI,CAAC,UA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gBAAgB,EAAE,CAAC;QACtB,gBAAgB,GAAG,uBAAuB,EAAE,CAAC;IAC/C,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n HttpClient,\n Pipeline,\n bearerTokenAuthenticationPolicy,\n createDefaultHttpClient,\n createPipelineFromOptions,\n} from \"@azure/core-rest-pipeline\";\nimport { KeyCredential, TokenCredential, isTokenCredential } from \"@azure/core-auth\";\n\nimport { ClientOptions } from \"./common.js\";\nimport { apiVersionPolicy } from \"./apiVersionPolicy.js\";\nimport { keyCredentialAuthenticationPolicy } from \"./keyCredentialAuthenticationPolicy.js\";\n\nlet cachedHttpClient: HttpClient | undefined;\n\n/**\n * Optional parameters for adding a credential policy to the pipeline.\n */\nexport interface AddCredentialPipelinePolicyOptions {\n /**\n * Options related to the client.\n */\n clientOptions?: ClientOptions;\n /**\n * The credential to use.\n */\n credential?: TokenCredential | KeyCredential;\n}\n\n/**\n * Adds a credential policy to the pipeline if a credential is provided. If none is provided, no policy is added.\n */\nexport function addCredentialPipelinePolicy(\n pipeline: Pipeline,\n endpoint: string,\n options: AddCredentialPipelinePolicyOptions = {},\n): void {\n const { credential, clientOptions } = options;\n if (!credential) {\n return;\n }\n\n if (isTokenCredential(credential)) {\n const tokenPolicy = bearerTokenAuthenticationPolicy({\n credential,\n scopes: clientOptions?.credentials?.scopes ?? `${endpoint}/.default`,\n });\n pipeline.addPolicy(tokenPolicy);\n } else if (isKeyCredential(credential)) {\n if (!clientOptions?.credentials?.apiKeyHeaderName) {\n throw new Error(`Missing API Key Header Name`);\n }\n const keyPolicy = keyCredentialAuthenticationPolicy(\n credential,\n clientOptions?.credentials?.apiKeyHeaderName,\n );\n pipeline.addPolicy(keyPolicy);\n }\n}\n\n/**\n * Creates a default rest pipeline to re-use accross Rest Level Clients\n */\nexport function createDefaultPipeline(\n endpoint: string,\n credential?: TokenCredential | KeyCredential,\n options: ClientOptions = {},\n): Pipeline {\n const pipeline = createPipelineFromOptions(options);\n\n pipeline.addPolicy(apiVersionPolicy(options));\n\n addCredentialPipelinePolicy(pipeline, endpoint, { credential, clientOptions: options });\n return pipeline;\n}\n\nfunction isKeyCredential(credential: any): credential is KeyCredential {\n return (credential as KeyCredential).key !== undefined;\n}\n\nexport function getCachedDefaultHttpsClient(): HttpClient {\n if (!cachedHttpClient) {\n cachedHttpClient = createDefaultHttpClient();\n }\n\n return cachedHttpClient;\n}\n"]}
|
|
@@ -5,17 +5,18 @@ import { createDefaultPipeline } from "./clientHelpers.js";
|
|
|
5
5
|
import { sendRequest } from "./sendRequest.js";
|
|
6
6
|
import { buildRequestUrl } from "./urlHelpers.js";
|
|
7
7
|
export function getClient(endpoint, credentialsOrPipelineOptions, clientOptions = {}) {
|
|
8
|
+
var _a, _b;
|
|
8
9
|
let credentials;
|
|
9
10
|
if (credentialsOrPipelineOptions) {
|
|
10
11
|
if (isCredential(credentialsOrPipelineOptions)) {
|
|
11
12
|
credentials = credentialsOrPipelineOptions;
|
|
12
13
|
}
|
|
13
14
|
else {
|
|
14
|
-
clientOptions = credentialsOrPipelineOptions
|
|
15
|
+
clientOptions = credentialsOrPipelineOptions !== null && credentialsOrPipelineOptions !== void 0 ? credentialsOrPipelineOptions : {};
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
const pipeline = createDefaultPipeline(endpoint, credentials, clientOptions);
|
|
18
|
-
if (clientOptions.additionalPolicies
|
|
19
|
+
if ((_a = clientOptions.additionalPolicies) === null || _a === void 0 ? void 0 : _a.length) {
|
|
19
20
|
for (const { policy, position } of clientOptions.additionalPolicies) {
|
|
20
21
|
// Sign happens after Retry and is commonly needed to occur
|
|
21
22
|
// before policies that intercept post-retry.
|
|
@@ -26,9 +27,9 @@ export function getClient(endpoint, credentialsOrPipelineOptions, clientOptions
|
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
const { allowInsecureConnection, httpClient } = clientOptions;
|
|
29
|
-
const endpointUrl = clientOptions.endpoint
|
|
30
|
+
const endpointUrl = (_b = clientOptions.endpoint) !== null && _b !== void 0 ? _b : endpoint;
|
|
30
31
|
const client = (path, ...args) => {
|
|
31
|
-
const getUrl = (requestOptions) => buildRequestUrl(endpointUrl, path, args, { allowInsecureConnection,
|
|
32
|
+
const getUrl = (requestOptions) => buildRequestUrl(endpointUrl, path, args, Object.assign({ allowInsecureConnection }, requestOptions));
|
|
32
33
|
return {
|
|
33
34
|
get: (requestOptions = {}) => {
|
|
34
35
|
return buildOperation("GET", getUrl(requestOptions), pipeline, requestOptions, allowInsecureConnection, httpClient);
|
|
@@ -63,16 +64,17 @@ export function getClient(endpoint, credentialsOrPipelineOptions, clientOptions
|
|
|
63
64
|
};
|
|
64
65
|
}
|
|
65
66
|
function buildOperation(method, url, pipeline, options, allowInsecureConnection, httpClient) {
|
|
66
|
-
|
|
67
|
+
var _a;
|
|
68
|
+
allowInsecureConnection = (_a = options.allowInsecureConnection) !== null && _a !== void 0 ? _a : allowInsecureConnection;
|
|
67
69
|
return {
|
|
68
70
|
then: function (onFulfilled, onrejected) {
|
|
69
|
-
return sendRequest(method, url, pipeline, {
|
|
71
|
+
return sendRequest(method, url, pipeline, Object.assign(Object.assign({}, options), { allowInsecureConnection }), httpClient).then(onFulfilled, onrejected);
|
|
70
72
|
},
|
|
71
73
|
async asBrowserStream() {
|
|
72
|
-
return sendRequest(method, url, pipeline, {
|
|
74
|
+
return sendRequest(method, url, pipeline, Object.assign(Object.assign({}, options), { allowInsecureConnection, responseAsStream: true }), httpClient);
|
|
73
75
|
},
|
|
74
76
|
async asNodeStream() {
|
|
75
|
-
return sendRequest(method, url, pipeline, {
|
|
77
|
+
return sendRequest(method, url, pipeline, Object.assign(Object.assign({}, options), { allowInsecureConnection, responseAsStream: true }), httpClient);
|
|
76
78
|
},
|
|
77
79
|
};
|
|
78
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getClient.js","sourceRoot":"","sources":["../../src/getClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAkC,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErF,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAS3D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAmBlD,MAAM,UAAU,SAAS,CACvB,QAAgB,EAChB,4BAAgF,EAChF,gBAA+B,EAAE
|
|
1
|
+
{"version":3,"file":"getClient.js","sourceRoot":"","sources":["../../src/getClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAkC,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErF,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAS3D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAmBlD,MAAM,UAAU,SAAS,CACvB,QAAgB,EAChB,4BAAgF,EAChF,gBAA+B,EAAE;;IAEjC,IAAI,WAAwD,CAAC;IAC7D,IAAI,4BAA4B,EAAE,CAAC;QACjC,IAAI,YAAY,CAAC,4BAA4B,CAAC,EAAE,CAAC;YAC/C,WAAW,GAAG,4BAA4B,CAAC;QAC7C,CAAC;aAAM,CAAC;YACN,aAAa,GAAG,4BAA4B,aAA5B,4BAA4B,cAA5B,4BAA4B,GAAI,EAAE,CAAC;QACrD,CAAC;IACH,CAAC;IAED,MAAM,QAAQ,GAAG,qBAAqB,CAAC,QAAQ,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;IAC7E,IAAI,MAAA,aAAa,CAAC,kBAAkB,0CAAE,MAAM,EAAE,CAAC;QAC7C,KAAK,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,aAAa,CAAC,kBAAkB,EAAE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AuB,KACrC,UAAU,CACX,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QAClC,CAAC;QACD,KAAK,CAAC,eAAe;YACnB,OAAO,WAAW,CAChB,MAAM,EACN,GAAG,EACH,QAAQ,kCACH,OAAO,KAAE,uBAAuB,EAAE,gBAAgB,EAAE,IAAI,KAC7D,UAAU,CAC2B,CAAC;QAC1C,CAAC;QACD,KAAK,CAAC,YAAY;YAChB,OAAO,WAAW,CAChB,MAAM,EACN,GAAG,EACH,QAAQ,kCACH,OAAO,KAAE,uBAAuB,EAAE,gBAAgB,EAAE,IAAI,KAC7D,UAAU,CACwB,CAAC;QACvC,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CACnB,KAA0D;IAE1D,IAAK,KAAuB,CAAC,GAAG,KAAK,SAAS,IAAI,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3E,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { KeyCredential, TokenCredential, isTokenCredential } from \"@azure/core-auth\";\nimport { HttpClient, HttpMethods, Pipeline, PipelineOptions } from \"@azure/core-rest-pipeline\";\nimport { createDefaultPipeline } from \"./clientHelpers.js\";\nimport {\n Client,\n ClientOptions,\n HttpBrowserStreamResponse,\n HttpNodeStreamResponse,\n RequestParameters,\n StreamableMethod,\n} from \"./common.js\";\nimport { sendRequest } from \"./sendRequest.js\";\nimport { buildRequestUrl } from \"./urlHelpers.js\";\n\n/**\n * Creates a client with a default pipeline\n * @param endpoint - Base endpoint for the client\n * @param options - Client options\n */\nexport function getClient(endpoint: string, options?: ClientOptions): Client;\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(\n endpoint: string,\n credentials?: TokenCredential | KeyCredential,\n options?: ClientOptions,\n): Client;\nexport function getClient(\n endpoint: string,\n credentialsOrPipelineOptions?: (TokenCredential | KeyCredential) | ClientOptions,\n clientOptions: ClientOptions = {},\n): Client {\n let credentials: TokenCredential | KeyCredential | undefined;\n if (credentialsOrPipelineOptions) {\n if (isCredential(credentialsOrPipelineOptions)) {\n credentials = credentialsOrPipelineOptions;\n } else {\n clientOptions = credentialsOrPipelineOptions ?? {};\n }\n }\n\n const pipeline = createDefaultPipeline(endpoint, credentials, 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>) => {\n const getUrl = (requestOptions: RequestParameters) =>\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 return sendRequest(\n method,\n url,\n pipeline,\n { ...options, allowInsecureConnection, responseAsStream: true },\n httpClient,\n ) as Promise<HttpBrowserStreamResponse>;\n },\n async asNodeStream() {\n return sendRequest(\n method,\n url,\n pipeline,\n { ...options, allowInsecureConnection, responseAsStream: true },\n httpClient,\n ) as Promise<HttpNodeStreamResponse>;\n },\n };\n}\n\nfunction isCredential(\n param: (TokenCredential | KeyCredential) | PipelineOptions,\n): param is TokenCredential | KeyCredential {\n if ((param as KeyCredential).key !== undefined || isTokenCredential(param)) {\n return true;\n }\n\n return false;\n}\n"]}
|
|
@@ -6,15 +6,16 @@
|
|
|
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;
|
|
9
10
|
return {
|
|
10
|
-
allowInsecureConnection: options.requestOptions
|
|
11
|
-
timeout: options.requestOptions
|
|
12
|
-
skipUrlEncoding: options.requestOptions
|
|
11
|
+
allowInsecureConnection: (_a = options.requestOptions) === null || _a === void 0 ? void 0 : _a.allowInsecureConnection,
|
|
12
|
+
timeout: (_b = options.requestOptions) === null || _b === void 0 ? void 0 : _b.timeout,
|
|
13
|
+
skipUrlEncoding: (_c = options.requestOptions) === null || _c === void 0 ? void 0 : _c.skipUrlEncoding,
|
|
13
14
|
abortSignal: options.abortSignal,
|
|
14
|
-
onUploadProgress: options.requestOptions
|
|
15
|
-
onDownloadProgress: options.requestOptions
|
|
15
|
+
onUploadProgress: (_d = options.requestOptions) === null || _d === void 0 ? void 0 : _d.onUploadProgress,
|
|
16
|
+
onDownloadProgress: (_e = options.requestOptions) === null || _e === void 0 ? void 0 : _e.onDownloadProgress,
|
|
16
17
|
tracingOptions: options.tracingOptions,
|
|
17
|
-
headers: {
|
|
18
|
+
headers: Object.assign({}, (_f = options.requestOptions) === null || _f === void 0 ? void 0 : _f.headers),
|
|
18
19
|
onResponse: options.onResponse,
|
|
19
20
|
};
|
|
20
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operationOptionHelpers.js","sourceRoot":"","sources":["../../src/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/operationOptionHelpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC;;;;GAIG;AACH,MAAM,UAAU,mCAAmC,CAAC,OAAyB;;IAC3E,OAAO;QACL,uBAAuB,EAAE,MAAA,OAAO,CAAC,cAAc,0CAAE,uBAAuB;QACxE,OAAO,EAAE,MAAA,OAAO,CAAC,cAAc,0CAAE,OAAO;QACxC,eAAe,EAAE,MAAA,OAAO,CAAC,cAAc,0CAAE,eAAe;QACxD,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,gBAAgB,EAAE,MAAA,OAAO,CAAC,cAAc,0CAAE,gBAAgB;QAC1D,kBAAkB,EAAE,MAAA,OAAO,CAAC,cAAc,0CAAE,kBAAkB;QAC9D,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,OAAO,oBAAO,MAAA,OAAO,CAAC,cAAc,0CAAE,OAAO,CAAE;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 { 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 tracingOptions: options.tracingOptions,\n headers: { ...options.requestOptions?.headers },\n onResponse: options.onResponse,\n };\n}\n"]}
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
3
|
import { RestError, createHttpHeaders } from "@azure/core-rest-pipeline";
|
|
4
4
|
export function createRestError(messageOrResponse, response) {
|
|
5
|
+
var _a;
|
|
5
6
|
const resp = typeof messageOrResponse === "string" ? response : messageOrResponse;
|
|
6
7
|
const internalError = resp.body.error || resp.body;
|
|
7
8
|
const message = typeof messageOrResponse === "string"
|
|
8
9
|
? messageOrResponse
|
|
9
|
-
: internalError.message
|
|
10
|
+
: (_a = internalError.message) !== null && _a !== void 0 ? _a : `Unexpected status code: ${resp.status}`;
|
|
10
11
|
return new RestError(message, {
|
|
11
12
|
statusCode: statusCodeToNumber(resp.status),
|
|
12
13
|
code: internalError.code,
|
|
@@ -15,10 +16,11 @@ export function createRestError(messageOrResponse, response) {
|
|
|
15
16
|
});
|
|
16
17
|
}
|
|
17
18
|
function toPipelineResponse(response) {
|
|
19
|
+
var _a;
|
|
18
20
|
return {
|
|
19
21
|
headers: createHttpHeaders(response.headers),
|
|
20
22
|
request: response.request,
|
|
21
|
-
status: statusCodeToNumber(response.status)
|
|
23
|
+
status: (_a = statusCodeToNumber(response.status)) !== null && _a !== void 0 ? _a : -1,
|
|
22
24
|
};
|
|
23
25
|
}
|
|
24
26
|
function statusCodeToNumber(statusCode) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restError.js","sourceRoot":"","sources":["../../src/restError.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAoB,SAAS,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAW3F,MAAM,UAAU,eAAe,CAC7B,iBAAiD,EACjD,QAAgC
|
|
1
|
+
{"version":3,"file":"restError.js","sourceRoot":"","sources":["../../src/restError.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAoB,SAAS,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAW3F,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,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC;IACnD,MAAM,OAAO,GACX,OAAO,iBAAiB,KAAK,QAAQ;QACnC,CAAC,CAAC,iBAAiB;QACnB,CAAC,CAAC,MAAA,aAAa,CAAC,OAAO,mCAAI,2BAA2B,IAAI,CAAC,MAAM,EAAE,CAAC;IACxE,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE;QAC5B,UAAU,EAAE,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC;QAC3C,IAAI,EAAE,aAAa,CAAC,IAAI;QACxB,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,MAAA,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,mCAAI,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 { PipelineResponse, RestError, createHttpHeaders } from \"@azure/core-rest-pipeline\";\nimport { 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"]}
|
|
@@ -13,15 +13,16 @@ import { isReadableStream } from "./helpers/isReadableStream.js";
|
|
|
13
13
|
* @returns returns and HttpResponse
|
|
14
14
|
*/
|
|
15
15
|
export async function sendRequest(method, url, pipeline, options = {}, customHttpClient) {
|
|
16
|
-
|
|
16
|
+
var _a;
|
|
17
|
+
const httpClient = customHttpClient !== null && customHttpClient !== void 0 ? customHttpClient : getCachedDefaultHttpsClient();
|
|
17
18
|
const request = buildPipelineRequest(method, url, options);
|
|
18
19
|
const response = await pipeline.sendRequest(httpClient, request);
|
|
19
20
|
const headers = response.headers.toJSON();
|
|
20
|
-
const stream = response.readableStreamBody
|
|
21
|
+
const stream = (_a = response.readableStreamBody) !== null && _a !== void 0 ? _a : response.browserStreamBody;
|
|
21
22
|
const parsedBody = options.responseAsStream || stream !== undefined ? undefined : getResponseBody(response);
|
|
22
|
-
const body = stream
|
|
23
|
-
if (options
|
|
24
|
-
options.onResponse({
|
|
23
|
+
const body = stream !== null && stream !== void 0 ? stream : parsedBody;
|
|
24
|
+
if (options === null || options === void 0 ? void 0 : options.onResponse) {
|
|
25
|
+
options.onResponse(Object.assign(Object.assign({}, response), { request, rawHeaders: headers, parsedBody }));
|
|
25
26
|
}
|
|
26
27
|
return {
|
|
27
28
|
request,
|
|
@@ -36,9 +37,8 @@ export async function sendRequest(method, url, pipeline, options = {}, customHtt
|
|
|
36
37
|
* @returns returns the content-type
|
|
37
38
|
*/
|
|
38
39
|
function getRequestContentType(options = {}) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
getContentType(options.body));
|
|
40
|
+
var _a, _b, _c;
|
|
41
|
+
return ((_c = (_a = options.contentType) !== null && _a !== void 0 ? _a : (_b = options.headers) === null || _b === void 0 ? void 0 : _b["content-type"]) !== null && _c !== void 0 ? _c : getContentType(options.body));
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
44
|
* Function to determine the content-type of a body
|
|
@@ -64,17 +64,14 @@ function getContentType(body) {
|
|
|
64
64
|
return "application/json; charset=UTF-8";
|
|
65
65
|
}
|
|
66
66
|
function buildPipelineRequest(method, url, options = {}) {
|
|
67
|
+
var _a;
|
|
67
68
|
const requestContentType = getRequestContentType(options);
|
|
68
69
|
const { body, formData } = getRequestBody(options.body, requestContentType);
|
|
69
70
|
const hasContent = body !== undefined || formData !== undefined;
|
|
70
|
-
const headers = createHttpHeaders({
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
requestContentType && {
|
|
75
|
-
"content-type": requestContentType,
|
|
76
|
-
}),
|
|
77
|
-
});
|
|
71
|
+
const headers = createHttpHeaders(Object.assign(Object.assign(Object.assign({}, (options.headers ? options.headers : {})), { accept: (_a = options.accept) !== null && _a !== void 0 ? _a : "application/json" }), (hasContent &&
|
|
72
|
+
requestContentType && {
|
|
73
|
+
"content-type": requestContentType,
|
|
74
|
+
})));
|
|
78
75
|
return createPipelineRequest({
|
|
79
76
|
url,
|
|
80
77
|
method,
|
|
@@ -156,10 +153,11 @@ function processFormData(formData) {
|
|
|
156
153
|
* Prepares the response body
|
|
157
154
|
*/
|
|
158
155
|
function getResponseBody(response) {
|
|
156
|
+
var _a, _b;
|
|
159
157
|
// Set the default response type
|
|
160
|
-
const contentType = response.headers.get("content-type")
|
|
158
|
+
const contentType = (_a = response.headers.get("content-type")) !== null && _a !== void 0 ? _a : "";
|
|
161
159
|
const firstType = contentType.split(";")[0];
|
|
162
|
-
const bodyToParse = response.bodyAsText
|
|
160
|
+
const bodyToParse = (_b = response.bodyAsText) !== null && _b !== void 0 ? _b : "";
|
|
163
161
|
if (firstType === "text/plain") {
|
|
164
162
|
return String(bodyToParse);
|
|
165
163
|
}
|
|
@@ -179,8 +177,9 @@ function getResponseBody(response) {
|
|
|
179
177
|
}
|
|
180
178
|
}
|
|
181
179
|
function createParseError(response, err) {
|
|
180
|
+
var _a;
|
|
182
181
|
const msg = `Error "${err}" occurred while parsing the response body - ${response.bodyAsText}.`;
|
|
183
|
-
const errCode = err.code
|
|
182
|
+
const errCode = (_a = err.code) !== null && _a !== void 0 ? _a : RestError.PARSE_ERROR;
|
|
184
183
|
return new RestError(msg, {
|
|
185
184
|
code: errCode,
|
|
186
185
|
statusCode: response.status,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendRequest.js","sourceRoot":"","sources":["../../src/sendRequest.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EASL,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAGjE;;;;;;;;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;IAC3D,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACjE,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;IAC1C,MAAM,MAAM,G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E9C,IAAI,SAAS,KAAK,YAAY,EAAE,CAAC;QAC/B,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC;IAC7B,CAAC;IACD,wDAAwD;IACxD,IAAI,CAAC;QACH,OAAO,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3D,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,yDAAyD;QACzD,6BAA6B;QAC7B,IAAI,SAAS,KAAK,kBAAkB,EAAE,CAAC;YACrC,MAAM,gBAAgB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC1C,CAAC;QAED,gEAAgE;QAChE,cAAc;QACd,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,QAA0B,EAAE,GAAQ;IAC5D,MAAM,GAAG,GAAG,UAAU,GAAG,gDAAgD,QAAQ,CAAC,UAAU,GAAG,CAAC;IAChG,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,IAAI,SAAS,CAAC,WAAW,CAAC;IAClD,OAAO,IAAI,SAAS,CAAC,GAAG,EAAE;QACxB,IAAI,EAAE,OAAO;QACb,UAAU,EAAE,QAAQ,CAAC,MAAM;QAC3B,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,QAAQ,EAAE,QAAQ;KACnB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n FormDataMap,\n FormDataValue,\n HttpClient,\n HttpMethods,\n Pipeline,\n PipelineRequest,\n PipelineResponse,\n RequestBodyType,\n RestError,\n createFile,\n createHttpHeaders,\n createPipelineRequest,\n} from \"@azure/core-rest-pipeline\";\nimport { getCachedDefaultHttpsClient } from \"./clientHelpers.js\";\nimport { isReadableStream } from \"./helpers/isReadableStream.js\";\nimport { HttpResponse, RequestParameters } from \"./common.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 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}\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; charset=UTF-8\";\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; charset=UTF-8\";\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, formData } = getRequestBody(options.body, requestContentType);\n const hasContent = body !== undefined || formData !== undefined;\n\n const headers = createHttpHeaders({\n ...(options.headers ? options.headers : {}),\n accept: options.accept ?? \"application/json\",\n ...(hasContent &&\n requestContentType && {\n \"content-type\": requestContentType,\n }),\n });\n\n return createPipelineRequest({\n url,\n method,\n body,\n formData,\n headers,\n allowInsecureConnection: options.allowInsecureConnection,\n tracingOptions: options.tracingOptions,\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 formData?: FormDataMap;\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 (isReadableStream(body)) {\n return { body };\n }\n\n const firstType = contentType.split(\";\")[0];\n\n if (firstType === \"application/json\") {\n return { body: JSON.stringify(body) };\n }\n\n if (ArrayBuffer.isView(body)) {\n return { body: body instanceof Uint8Array ? body : JSON.stringify(body) };\n }\n\n switch (firstType) {\n case \"multipart/form-data\":\n return isRLCFormDataInput(body)\n ? { formData: processFormData(body) }\n : { 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 * Union of possible input types for multipart/form-data values that are accepted by RLCs.\n * This extends the default FormDataValue type to include Uint8Array, which is accepted as an input by RLCs.\n */\ntype RLCFormDataValue = FormDataValue | Uint8Array;\n\n/**\n * Input shape for a form data body type as generated by an RLC\n */\ntype RLCFormDataInput = Record<string, RLCFormDataValue | RLCFormDataValue[]>;\n\nfunction isRLCFormDataValue(value: unknown): value is RLCFormDataValue {\n return (\n typeof value === \"string\" ||\n value instanceof Uint8Array ||\n // We don't do `instanceof Blob` since we should also accept polyfills of e.g. File in Node.\n typeof (value as Blob).stream === \"function\"\n );\n}\n\nfunction isRLCFormDataInput(body: unknown): body is RLCFormDataInput {\n return (\n body !== undefined &&\n body instanceof Object &&\n Object.values(body).every(\n (value) =>\n isRLCFormDataValue(value) || (Array.isArray(value) && value.every(isRLCFormDataValue)),\n )\n );\n}\n\nfunction processFormDataValue(value: RLCFormDataValue): FormDataValue {\n return value instanceof Uint8Array ? createFile(value, \"blob\") : value;\n}\n\n/**\n * Checks if binary data is in Uint8Array format, if so wrap it in a Blob\n * to send over the wire\n */\nfunction processFormData(formData: RLCFormDataInput): FormDataMap {\n const processedFormData: FormDataMap = {};\n\n for (const element in formData) {\n const value = formData[element];\n\n processedFormData[element] = Array.isArray(value)\n ? value.map(processFormDataValue)\n : processFormDataValue(value);\n }\n\n return processedFormData;\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/sendRequest.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EASL,SAAS,EACT,UAAU,EACV,i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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 {\n FormDataMap,\n FormDataValue,\n HttpClient,\n HttpMethods,\n Pipeline,\n PipelineRequest,\n PipelineResponse,\n RequestBodyType,\n RestError,\n createFile,\n createHttpHeaders,\n createPipelineRequest,\n} from \"@azure/core-rest-pipeline\";\nimport { getCachedDefaultHttpsClient } from \"./clientHelpers.js\";\nimport { isReadableStream } from \"./helpers/isReadableStream.js\";\nimport { HttpResponse, RequestParameters } from \"./common.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 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}\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; charset=UTF-8\";\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; charset=UTF-8\";\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, formData } = getRequestBody(options.body, requestContentType);\n const hasContent = body !== undefined || formData !== undefined;\n\n const headers = createHttpHeaders({\n ...(options.headers ? options.headers : {}),\n accept: options.accept ?? \"application/json\",\n ...(hasContent &&\n requestContentType && {\n \"content-type\": requestContentType,\n }),\n });\n\n return createPipelineRequest({\n url,\n method,\n body,\n formData,\n headers,\n allowInsecureConnection: options.allowInsecureConnection,\n tracingOptions: options.tracingOptions,\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 formData?: FormDataMap;\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 (isReadableStream(body)) {\n return { body };\n }\n\n const firstType = contentType.split(\";\")[0];\n\n if (firstType === \"application/json\") {\n return { body: JSON.stringify(body) };\n }\n\n if (ArrayBuffer.isView(body)) {\n return { body: body instanceof Uint8Array ? body : JSON.stringify(body) };\n }\n\n switch (firstType) {\n case \"multipart/form-data\":\n return isRLCFormDataInput(body)\n ? { formData: processFormData(body) }\n : { 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 * Union of possible input types for multipart/form-data values that are accepted by RLCs.\n * This extends the default FormDataValue type to include Uint8Array, which is accepted as an input by RLCs.\n */\ntype RLCFormDataValue = FormDataValue | Uint8Array;\n\n/**\n * Input shape for a form data body type as generated by an RLC\n */\ntype RLCFormDataInput = Record<string, RLCFormDataValue | RLCFormDataValue[]>;\n\nfunction isRLCFormDataValue(value: unknown): value is RLCFormDataValue {\n return (\n typeof value === \"string\" ||\n value instanceof Uint8Array ||\n // We don't do `instanceof Blob` since we should also accept polyfills of e.g. File in Node.\n typeof (value as Blob).stream === \"function\"\n );\n}\n\nfunction isRLCFormDataInput(body: unknown): body is RLCFormDataInput {\n return (\n body !== undefined &&\n body instanceof Object &&\n Object.values(body).every(\n (value) =>\n isRLCFormDataValue(value) || (Array.isArray(value) && value.every(isRLCFormDataValue)),\n )\n );\n}\n\nfunction processFormDataValue(value: RLCFormDataValue): FormDataValue {\n return value instanceof Uint8Array ? createFile(value, \"blob\") : value;\n}\n\n/**\n * Checks if binary data is in Uint8Array format, if so wrap it in a Blob\n * to send over the wire\n */\nfunction processFormData(formData: RLCFormDataInput): FormDataMap {\n const processedFormData: FormDataMap = {};\n\n for (const element in formData) {\n const value = formData[element];\n\n processedFormData[element] = Array.isArray(value)\n ? value.map(processFormDataValue)\n : processFormDataValue(value);\n }\n\n return processedFormData;\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"]}
|
|
@@ -57,6 +57,7 @@ function skipQueryParameterEncoding(url) {
|
|
|
57
57
|
return url;
|
|
58
58
|
}
|
|
59
59
|
export function buildBaseUrl(endpoint, options) {
|
|
60
|
+
var _a;
|
|
60
61
|
if (!options.pathParameters) {
|
|
61
62
|
return endpoint;
|
|
62
63
|
}
|
|
@@ -72,7 +73,7 @@ export function buildBaseUrl(endpoint, options) {
|
|
|
72
73
|
if (!options.skipUrlEncoding) {
|
|
73
74
|
value = encodeURIComponent(param);
|
|
74
75
|
}
|
|
75
|
-
endpoint = replaceAll(endpoint, `{${key}}`, value)
|
|
76
|
+
endpoint = (_a = replaceAll(endpoint, `{${key}}`, value)) !== null && _a !== void 0 ? _a : "";
|
|
76
77
|
}
|
|
77
78
|
return endpoint;
|
|
78
79
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlHelpers.js","sourceRoot":"","sources":["../../src/urlHelpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAC7B,QAAgB,E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esContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { RequestParameters } from \"./common.js\";\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[],\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 appendQueryParams(url: string, options: RequestParameters = {}) {\n if (!options.queryParameters) {\n return url;\n }\n let parsedUrl = new URL(url);\n const queryParams = options.queryParameters;\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 if (!param.toString || typeof param.toString !== \"function\") {\n throw new Error(`Query parameters must be able to be represented as string, ${key} can't`);\n }\n const value = param.toISOString !== undefined ? param.toISOString() : param.toString();\n parsedUrl.searchParams.append(key, value);\n }\n\n if (options.skipUrlEncoding) {\n parsedUrl = skipQueryParameterEncoding(parsedUrl);\n }\n return parsedUrl.toString();\n}\n\nfunction skipQueryParameterEncoding(url: URL) {\n if (!url) {\n return url;\n }\n const searchPieces: string[] = [];\n for (const [name, value] of url.searchParams) {\n // QUIRK: searchParams.get retrieves the values decoded\n searchPieces.push(`${name}=${value}`);\n }\n // QUIRK: we have to set search manually as searchParams will encode comma when it shouldn't.\n url.search = searchPieces.length ? `?${searchPieces.join(\"&\")}` : \"\";\n return url;\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[],\n options: RequestParameters = {},\n) {\n for (const pathParam of pathParameters) {\n let value = pathParam;\n if (!options.skipUrlEncoding) {\n value = encodeURIComponent(pathParam);\n }\n\n routePath = routePath.replace(/\\{\\w+\\}/, 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"]}
|
|
@@ -12,6 +12,7 @@ let cachedHttpClient;
|
|
|
12
12
|
* Adds a credential policy to the pipeline if a credential is provided. If none is provided, no policy is added.
|
|
13
13
|
*/
|
|
14
14
|
function addCredentialPipelinePolicy(pipeline, endpoint, options = {}) {
|
|
15
|
+
var _a, _b, _c, _d;
|
|
15
16
|
const { credential, clientOptions } = options;
|
|
16
17
|
if (!credential) {
|
|
17
18
|
return;
|
|
@@ -19,15 +20,15 @@ function addCredentialPipelinePolicy(pipeline, endpoint, options = {}) {
|
|
|
19
20
|
if ((0, core_auth_1.isTokenCredential)(credential)) {
|
|
20
21
|
const tokenPolicy = (0, core_rest_pipeline_1.bearerTokenAuthenticationPolicy)({
|
|
21
22
|
credential,
|
|
22
|
-
scopes: clientOptions
|
|
23
|
+
scopes: (_b = (_a = clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.credentials) === null || _a === void 0 ? void 0 : _a.scopes) !== null && _b !== void 0 ? _b : `${endpoint}/.default`,
|
|
23
24
|
});
|
|
24
25
|
pipeline.addPolicy(tokenPolicy);
|
|
25
26
|
}
|
|
26
27
|
else if (isKeyCredential(credential)) {
|
|
27
|
-
if (!clientOptions
|
|
28
|
+
if (!((_c = clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.credentials) === null || _c === void 0 ? void 0 : _c.apiKeyHeaderName)) {
|
|
28
29
|
throw new Error(`Missing API Key Header Name`);
|
|
29
30
|
}
|
|
30
|
-
const keyPolicy = (0, keyCredentialAuthenticationPolicy_js_1.keyCredentialAuthenticationPolicy)(credential, clientOptions
|
|
31
|
+
const keyPolicy = (0, keyCredentialAuthenticationPolicy_js_1.keyCredentialAuthenticationPolicy)(credential, (_d = clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.credentials) === null || _d === void 0 ? void 0 : _d.apiKeyHeaderName);
|
|
31
32
|
pipeline.addPolicy(keyPolicy);
|
|
32
33
|
}
|
|
33
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientHelpers.js","sourceRoot":"","sources":["../../src/clientHelpers.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,kEAMmC;AACnC,gDAAqF;AAGrF,+DAAyD;AACzD,iGAA2F;AAE3F,IAAI,gBAAwC,CAAC;AAgB7C;;GAEG;AACH,SAAgB,2BAA2B,CACzC,QAAkB,EAClB,QAAgB,EAChB,UAA8C,EAAE
|
|
1
|
+
{"version":3,"file":"clientHelpers.js","sourceRoot":"","sources":["../../src/clientHelpers.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,kEAMmC;AACnC,gDAAqF;AAGrF,+DAAyD;AACzD,iGAA2F;AAE3F,IAAI,gBAAwC,C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AE,aAAa,EAAE,OAAO,EAAE,CAAC,CAAC;IACxF,OAAO,QAAQ,CAAC;AAClB,CAAC;AAXD,sDAWC;AAED,SAAS,eAAe,CAAC,UAAe;IACtC,OAAQ,UAA4B,CAAC,GAAG,KAAK,SAAS,CAAC;AACzD,CAAC;AAED,SAAgB,2BAA2B;IACzC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,gBAAgB,GAAG,IAAA,4CAAuB,GAAE,CAAC;IAC/C,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAND,kEAMC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n HttpClient,\n Pipeline,\n bearerTokenAuthenticationPolicy,\n createDefaultHttpClient,\n createPipelineFromOptions,\n} from \"@azure/core-rest-pipeline\";\nimport { KeyCredential, TokenCredential, isTokenCredential } from \"@azure/core-auth\";\n\nimport { ClientOptions } from \"./common.js\";\nimport { apiVersionPolicy } from \"./apiVersionPolicy.js\";\nimport { keyCredentialAuthenticationPolicy } from \"./keyCredentialAuthenticationPolicy.js\";\n\nlet cachedHttpClient: HttpClient | undefined;\n\n/**\n * Optional parameters for adding a credential policy to the pipeline.\n */\nexport interface AddCredentialPipelinePolicyOptions {\n /**\n * Options related to the client.\n */\n clientOptions?: ClientOptions;\n /**\n * The credential to use.\n */\n credential?: TokenCredential | KeyCredential;\n}\n\n/**\n * Adds a credential policy to the pipeline if a credential is provided. If none is provided, no policy is added.\n */\nexport function addCredentialPipelinePolicy(\n pipeline: Pipeline,\n endpoint: string,\n options: AddCredentialPipelinePolicyOptions = {},\n): void {\n const { credential, clientOptions } = options;\n if (!credential) {\n return;\n }\n\n if (isTokenCredential(credential)) {\n const tokenPolicy = bearerTokenAuthenticationPolicy({\n credential,\n scopes: clientOptions?.credentials?.scopes ?? `${endpoint}/.default`,\n });\n pipeline.addPolicy(tokenPolicy);\n } else if (isKeyCredential(credential)) {\n if (!clientOptions?.credentials?.apiKeyHeaderName) {\n throw new Error(`Missing API Key Header Name`);\n }\n const keyPolicy = keyCredentialAuthenticationPolicy(\n credential,\n clientOptions?.credentials?.apiKeyHeaderName,\n );\n pipeline.addPolicy(keyPolicy);\n }\n}\n\n/**\n * Creates a default rest pipeline to re-use accross Rest Level Clients\n */\nexport function createDefaultPipeline(\n endpoint: string,\n credential?: TokenCredential | KeyCredential,\n options: ClientOptions = {},\n): Pipeline {\n const pipeline = createPipelineFromOptions(options);\n\n pipeline.addPolicy(apiVersionPolicy(options));\n\n addCredentialPipelinePolicy(pipeline, endpoint, { credential, clientOptions: options });\n return pipeline;\n}\n\nfunction isKeyCredential(credential: any): credential is KeyCredential {\n return (credential as KeyCredential).key !== undefined;\n}\n\nexport function getCachedDefaultHttpsClient(): HttpClient {\n if (!cachedHttpClient) {\n cachedHttpClient = createDefaultHttpClient();\n }\n\n return cachedHttpClient;\n}\n"]}
|
|
@@ -8,17 +8,18 @@ const clientHelpers_js_1 = require("./clientHelpers.js");
|
|
|
8
8
|
const sendRequest_js_1 = require("./sendRequest.js");
|
|
9
9
|
const urlHelpers_js_1 = require("./urlHelpers.js");
|
|
10
10
|
function getClient(endpoint, credentialsOrPipelineOptions, clientOptions = {}) {
|
|
11
|
+
var _a, _b;
|
|
11
12
|
let credentials;
|
|
12
13
|
if (credentialsOrPipelineOptions) {
|
|
13
14
|
if (isCredential(credentialsOrPipelineOptions)) {
|
|
14
15
|
credentials = credentialsOrPipelineOptions;
|
|
15
16
|
}
|
|
16
17
|
else {
|
|
17
|
-
clientOptions = credentialsOrPipelineOptions
|
|
18
|
+
clientOptions = credentialsOrPipelineOptions !== null && credentialsOrPipelineOptions !== void 0 ? credentialsOrPipelineOptions : {};
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
const pipeline = (0, clientHelpers_js_1.createDefaultPipeline)(endpoint, credentials, clientOptions);
|
|
21
|
-
if (clientOptions.additionalPolicies
|
|
22
|
+
if ((_a = clientOptions.additionalPolicies) === null || _a === void 0 ? void 0 : _a.length) {
|
|
22
23
|
for (const { policy, position } of clientOptions.additionalPolicies) {
|
|
23
24
|
// Sign happens after Retry and is commonly needed to occur
|
|
24
25
|
// before policies that intercept post-retry.
|
|
@@ -29,9 +30,9 @@ function getClient(endpoint, credentialsOrPipelineOptions, clientOptions = {}) {
|
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
const { allowInsecureConnection, httpClient } = clientOptions;
|
|
32
|
-
const endpointUrl = clientOptions.endpoint
|
|
33
|
+
const endpointUrl = (_b = clientOptions.endpoint) !== null && _b !== void 0 ? _b : endpoint;
|
|
33
34
|
const client = (path, ...args) => {
|
|
34
|
-
const getUrl = (requestOptions) => (0, urlHelpers_js_1.buildRequestUrl)(endpointUrl, path, args, { allowInsecureConnection,
|
|
35
|
+
const getUrl = (requestOptions) => (0, urlHelpers_js_1.buildRequestUrl)(endpointUrl, path, args, Object.assign({ allowInsecureConnection }, requestOptions));
|
|
35
36
|
return {
|
|
36
37
|
get: (requestOptions = {}) => {
|
|
37
38
|
return buildOperation("GET", getUrl(requestOptions), pipeline, requestOptions, allowInsecureConnection, httpClient);
|
|
@@ -67,16 +68,17 @@ function getClient(endpoint, credentialsOrPipelineOptions, clientOptions = {}) {
|
|
|
67
68
|
}
|
|
68
69
|
exports.getClient = getClient;
|
|
69
70
|
function buildOperation(method, url, pipeline, options, allowInsecureConnection, httpClient) {
|
|
70
|
-
|
|
71
|
+
var _a;
|
|
72
|
+
allowInsecureConnection = (_a = options.allowInsecureConnection) !== null && _a !== void 0 ? _a : allowInsecureConnection;
|
|
71
73
|
return {
|
|
72
74
|
then: function (onFulfilled, onrejected) {
|
|
73
|
-
return (0, sendRequest_js_1.sendRequest)(method, url, pipeline, {
|
|
75
|
+
return (0, sendRequest_js_1.sendRequest)(method, url, pipeline, Object.assign(Object.assign({}, options), { allowInsecureConnection }), httpClient).then(onFulfilled, onrejected);
|
|
74
76
|
},
|
|
75
77
|
async asBrowserStream() {
|
|
76
|
-
return (0, sendRequest_js_1.sendRequest)(method, url, pipeline, {
|
|
78
|
+
return (0, sendRequest_js_1.sendRequest)(method, url, pipeline, Object.assign(Object.assign({}, options), { allowInsecureConnection, responseAsStream: true }), httpClient);
|
|
77
79
|
},
|
|
78
80
|
async asNodeStream() {
|
|
79
|
-
return (0, sendRequest_js_1.sendRequest)(method, url, pipeline, {
|
|
81
|
+
return (0, sendRequest_js_1.sendRequest)(method, url, pipeline, Object.assign(Object.assign({}, options), { allowInsecureConnection, responseAsStream: true }), httpClient);
|
|
80
82
|
},
|
|
81
83
|
};
|
|
82
84
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getClient.js","sourceRoot":"","sources":["../../src/getClient.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,gDAAqF;AAErF,yDAA2D;AAS3D,qDAA+C;AAC/C,mDAAkD;AAmBlD,SAAgB,SAAS,CACvB,QAAgB,EAChB,4BAAgF,EAChF,gBAA+B,EAAE
|
|
1
|
+
{"version":3,"file":"getClient.js","sourceRoot":"","sources":["../../src/getClient.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,gDAAqF;AAErF,yDAA2D;AAS3D,qDAA+C;AAC/C,mDAAkD;AAmBlD,SAAgB,SAAS,CACvB,QAAgB,EAChB,4BAAgF,EAChF,gBAA+B,EAAE;;IAEjC,IAAI,WAAwD,CAAC;IAC7D,IAAI,4BAA4B,EAAE,CAAC;QACjC,IAAI,YAAY,CAAC,4BAA4B,CAAC,EAAE,CAAC;YAC/C,WAAW,GAAG,4BAA4B,CAAC;QAC7C,CAAC;aAAM,CAAC;YACN,aAAa,GAAG,4BAA4B,aAA5B,4BAA4B,cAA5B,4BAA4B,GAAI,EAAE,CAAC;QACrD,CAAC;IACH,CAAC;IAED,MAAM,QAAQ,GAAG,IAAA,wCAAqB,EAAC,QAAQ,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;IAC7E,IAAI,MAAA,aAAa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AI,uBAAuB,CAAC;IACrF,OAAO;QACL,IAAI,EAAE,UAAU,WAAW,EAAE,UAAU;YACrC,OAAO,IAAA,4BAAW,EAChB,MAAM,EACN,GAAG,EACH,QAAQ,kCACH,OAAO,KAAE,uBAAuB,KACrC,UAAU,CACX,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QAClC,CAAC;QACD,KAAK,CAAC,eAAe;YACnB,OAAO,IAAA,4BAAW,EAChB,MAAM,EACN,GAAG,EACH,QAAQ,kCACH,OAAO,KAAE,uBAAuB,EAAE,gBAAgB,EAAE,IAAI,KAC7D,UAAU,CAC2B,CAAC;QAC1C,CAAC;QACD,KAAK,CAAC,YAAY;YAChB,OAAO,IAAA,4BAAW,EAChB,MAAM,EACN,GAAG,EACH,QAAQ,kCACH,OAAO,KAAE,uBAAuB,EAAE,gBAAgB,EAAE,IAAI,KAC7D,UAAU,CACwB,CAAC;QACvC,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CACnB,KAA0D;IAE1D,IAAK,KAAuB,CAAC,GAAG,KAAK,SAAS,IAAI,IAAA,6BAAiB,EAAC,KAAK,CAAC,EAAE,CAAC;QAC3E,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { KeyCredential, TokenCredential, isTokenCredential } from \"@azure/core-auth\";\nimport { HttpClient, HttpMethods, Pipeline, PipelineOptions } from \"@azure/core-rest-pipeline\";\nimport { createDefaultPipeline } from \"./clientHelpers.js\";\nimport {\n Client,\n ClientOptions,\n HttpBrowserStreamResponse,\n HttpNodeStreamResponse,\n RequestParameters,\n StreamableMethod,\n} from \"./common.js\";\nimport { sendRequest } from \"./sendRequest.js\";\nimport { buildRequestUrl } from \"./urlHelpers.js\";\n\n/**\n * Creates a client with a default pipeline\n * @param endpoint - Base endpoint for the client\n * @param options - Client options\n */\nexport function getClient(endpoint: string, options?: ClientOptions): Client;\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(\n endpoint: string,\n credentials?: TokenCredential | KeyCredential,\n options?: ClientOptions,\n): Client;\nexport function getClient(\n endpoint: string,\n credentialsOrPipelineOptions?: (TokenCredential | KeyCredential) | ClientOptions,\n clientOptions: ClientOptions = {},\n): Client {\n let credentials: TokenCredential | KeyCredential | undefined;\n if (credentialsOrPipelineOptions) {\n if (isCredential(credentialsOrPipelineOptions)) {\n credentials = credentialsOrPipelineOptions;\n } else {\n clientOptions = credentialsOrPipelineOptions ?? {};\n }\n }\n\n const pipeline = createDefaultPipeline(endpoint, credentials, 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>) => {\n const getUrl = (requestOptions: RequestParameters) =>\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 return sendRequest(\n method,\n url,\n pipeline,\n { ...options, allowInsecureConnection, responseAsStream: true },\n httpClient,\n ) as Promise<HttpBrowserStreamResponse>;\n },\n async asNodeStream() {\n return sendRequest(\n method,\n url,\n pipeline,\n { ...options, allowInsecureConnection, responseAsStream: true },\n httpClient,\n ) as Promise<HttpNodeStreamResponse>;\n },\n };\n}\n\nfunction isCredential(\n param: (TokenCredential | KeyCredential) | PipelineOptions,\n): param is TokenCredential | KeyCredential {\n if ((param as KeyCredential).key !== undefined || isTokenCredential(param)) {\n return true;\n }\n\n return false;\n}\n"]}
|