@azure/core-client 1.6.0-alpha.20220420.2 → 1.6.0-alpha.20220503.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -7
- package/dist/index.js +121 -13
- package/dist/index.js.map +1 -1
- package/dist-esm/src/authorizeRequestOnClaimChallenge.js +2 -3
- package/dist-esm/src/authorizeRequestOnClaimChallenge.js.map +1 -1
- package/dist-esm/src/authorizeRequestOnTenantChallenge.js +99 -0
- package/dist-esm/src/authorizeRequestOnTenantChallenge.js.map +1 -0
- package/dist-esm/src/base64.browser.js.map +1 -1
- package/dist-esm/src/index.js +1 -0
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/log.js +5 -0
- package/dist-esm/src/log.js.map +1 -0
- package/dist-esm/src/serviceClient.js +15 -8
- package/dist-esm/src/serviceClient.js.map +1 -1
- package/package.json +3 -2
- package/types/3.1/core-client.d.ts +14 -1
- package/types/latest/core-client.d.ts +15 -1
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
|
-
import {
|
|
3
|
+
import { logger as coreClientLogger } from "./log";
|
|
4
4
|
import { decodeStringToString } from "./base64";
|
|
5
|
-
const defaultLogger = createClientLogger("authorizeRequestOnClaimChallenge");
|
|
6
5
|
/**
|
|
7
6
|
* Converts: `Bearer a="b", c="d", Bearer d="e", f="g"`.
|
|
8
7
|
* Into: `[ { a: 'b', c: 'd' }, { d: 'e', f: 'g' } ]`.
|
|
@@ -46,7 +45,7 @@ export function parseCAEChallenge(challenges) {
|
|
|
46
45
|
*/
|
|
47
46
|
export async function authorizeRequestOnClaimChallenge(onChallengeOptions) {
|
|
48
47
|
const { scopes, response } = onChallengeOptions;
|
|
49
|
-
const logger = onChallengeOptions.logger ||
|
|
48
|
+
const logger = onChallengeOptions.logger || coreClientLogger;
|
|
50
49
|
const challenge = response.headers.get("WWW-Authenticate");
|
|
51
50
|
if (!challenge) {
|
|
52
51
|
logger.info(`The WWW-Authenticate header was missing. Failed to perform the Continuous Access Evaluation authentication flow.`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorizeRequestOnClaimChallenge.js","sourceRoot":"","sources":["../../src/authorizeRequestOnClaimChallenge.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"authorizeRequestOnClaimChallenge.js","sourceRoot":"","sources":["../../src/authorizeRequestOnClaimChallenge.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAkB;IAClD,MAAM,gBAAgB,GAAG,KAAK,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IACtF,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;QACxC,MAAM,cAAc,GAAG,GAAG,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;QAC7E,MAAM,aAAa,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CACpD,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,C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eAAe,EAAE,UAAU,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC;IACvF,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AuthorizeRequestOnChallengeOptions } from \"@azure/core-rest-pipeline\";\nimport { GetTokenOptions } from \"@azure/core-auth\";\nimport { logger as coreClientLogger } from \"./log\";\nimport { decodeStringToString } from \"./base64\";\n\n/**\n * Converts: `Bearer a=\"b\", c=\"d\", Bearer d=\"e\", f=\"g\"`.\n * Into: `[ { a: 'b', c: 'd' }, { d: 'e', f: 'g' } ]`.\n *\n * @internal\n */\nexport function parseCAEChallenge(challenges: string): any[] {\n const bearerChallenges = `, ${challenges.trim()}`.split(\", Bearer \").filter((x) => x);\n return bearerChallenges.map((challenge) => {\n const challengeParts = `${challenge.trim()}, `.split('\", ').filter((x) => x);\n const keyValuePairs = challengeParts.map((keyValue) =>\n (([key, value]) => ({ [key]: value }))(keyValue.trim().split('=\"'))\n );\n // Key-value pairs to plain object:\n return keyValuePairs.reduce((a, b) => ({ ...a, ...b }), {});\n });\n}\n\n/**\n * CAE Challenge structure\n */\nexport interface CAEChallenge {\n scope: string;\n claims: string;\n}\n\n/**\n * This function can be used as a callback for the `bearerTokenAuthenticationPolicy` of `@azure/core-rest-pipeline`, to support CAE challenges:\n * [Continuous Access Evaluation](https://docs.microsoft.com/azure/active-directory/conditional-access/concept-continuous-access-evaluation).\n *\n * Call the `bearerTokenAuthenticationPolicy` with the following options:\n *\n * ```ts\n * import { bearerTokenAuthenticationPolicy } from \"@azure/core-rest-pipeline\";\n * import { authorizeRequestOnClaimChallenge } from \"@azure/core-client\";\n *\n * const bearerTokenAuthenticationPolicy = bearerTokenAuthenticationPolicy({\n * authorizeRequestOnChallenge: authorizeRequestOnClaimChallenge\n * });\n * ```\n *\n * Once provided, the `bearerTokenAuthenticationPolicy` policy will internally handle Continuous Access Evaluation (CAE) challenges.\n * When it can't complete a challenge it will return the 401 (unauthorized) response from ARM.\n *\n * Example challenge with claims:\n *\n * ```\n * Bearer authorization_uri=\"https://login.windows-ppe.net/\", error=\"invalid_token\",\n * error_description=\"User session has been revoked\",\n * claims=\"eyJhY2Nlc3NfdG9rZW4iOnsibmJmIjp7ImVzc2VudGlhbCI6dHJ1ZSwgInZhbHVlIjoiMTYwMzc0MjgwMCJ9fX0=\"\n * ```\n */\nexport async function authorizeRequestOnClaimChallenge(\n onChallengeOptions: AuthorizeRequestOnChallengeOptions\n): Promise<boolean> {\n const { scopes, response } = onChallengeOptions;\n const logger = onChallengeOptions.logger || coreClientLogger;\n\n const challenge = response.headers.get(\"WWW-Authenticate\");\n if (!challenge) {\n logger.info(\n `The WWW-Authenticate header was missing. Failed to perform the Continuous Access Evaluation authentication flow.`\n );\n return false;\n }\n const challenges: CAEChallenge[] = parseCAEChallenge(challenge) || [];\n\n const parsedChallenge = challenges.find((x) => x.claims);\n if (!parsedChallenge) {\n logger.info(\n `The WWW-Authenticate header was missing the necessary \"claims\" to perform the Continuous Access Evaluation authentication flow.`\n );\n return false;\n }\n\n const accessToken = await onChallengeOptions.getAccessToken(\n parsedChallenge.scope ? [parsedChallenge.scope] : scopes,\n {\n claims: decodeStringToString(parsedChallenge.claims),\n } as GetTokenOptions\n );\n\n if (!accessToken) {\n return false;\n }\n\n onChallengeOptions.request.headers.set(\"Authorization\", `Bearer ${accessToken.token}`);\n return true;\n}\n"]}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
/**
|
|
4
|
+
* A set of constants used internally when processing requests.
|
|
5
|
+
*/
|
|
6
|
+
const Constants = {
|
|
7
|
+
DefaultScope: "/.default",
|
|
8
|
+
/**
|
|
9
|
+
* Defines constants for use with HTTP headers.
|
|
10
|
+
*/
|
|
11
|
+
HeaderConstants: {
|
|
12
|
+
/**
|
|
13
|
+
* The Authorization header.
|
|
14
|
+
*/
|
|
15
|
+
AUTHORIZATION: "authorization",
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Defines a callback to handle auth challenge for Storage APIs.
|
|
20
|
+
* This implements the bearer challenge process described here: https://docs.microsoft.com/rest/api/storageservices/authorize-with-azure-active-directory#bearer-challenge
|
|
21
|
+
* Handling has specific features for storage that departs to the general AAD challenge docs.
|
|
22
|
+
**/
|
|
23
|
+
export const authorizeRequestOnTenantChallenge = async (challengeOptions) => {
|
|
24
|
+
const requestOptions = requestToOptions(challengeOptions.request);
|
|
25
|
+
const challenge = getChallenge(challengeOptions.response);
|
|
26
|
+
if (challenge) {
|
|
27
|
+
const challengeInfo = parseChallenge(challenge);
|
|
28
|
+
const challengeScopes = buildScopes(challengeOptions, challengeInfo);
|
|
29
|
+
const tenantId = extractTenantId(challengeInfo);
|
|
30
|
+
const accessToken = await challengeOptions.getAccessToken(challengeScopes, Object.assign(Object.assign({}, requestOptions), { tenantId }));
|
|
31
|
+
if (!accessToken) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
challengeOptions.request.headers.set(Constants.HeaderConstants.AUTHORIZATION, `Bearer ${accessToken.token}`);
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Extracts the tenant id from the challenge information
|
|
41
|
+
* The tenant id is contained in the authorization_uri as the first
|
|
42
|
+
* path part.
|
|
43
|
+
*/
|
|
44
|
+
function extractTenantId(challengeInfo) {
|
|
45
|
+
const parsedAuthUri = new URL(challengeInfo.authorization_uri);
|
|
46
|
+
const pathSegments = parsedAuthUri.pathname.split("/");
|
|
47
|
+
const tenantId = pathSegments[1];
|
|
48
|
+
return tenantId;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Builds the authentication scopes based on the information that comes in the
|
|
52
|
+
* challenge information. Scopes url is present in the resource_id, if it is empty
|
|
53
|
+
* we keep using the original scopes.
|
|
54
|
+
*/
|
|
55
|
+
function buildScopes(challengeOptions, challengeInfo) {
|
|
56
|
+
if (!challengeInfo.resource_uri) {
|
|
57
|
+
return challengeOptions.scopes;
|
|
58
|
+
}
|
|
59
|
+
const challengeScopes = new URL(challengeInfo.resource_uri);
|
|
60
|
+
challengeScopes.pathname = Constants.DefaultScope;
|
|
61
|
+
return [challengeScopes.toString()];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* We will retrieve the challenge only if the response status code was 401,
|
|
65
|
+
* and if the response contained the header "WWW-Authenticate" with a non-empty value.
|
|
66
|
+
*/
|
|
67
|
+
function getChallenge(response) {
|
|
68
|
+
const challenge = response.headers.get("WWW-Authenticate");
|
|
69
|
+
if (response.status === 401 && challenge) {
|
|
70
|
+
return challenge;
|
|
71
|
+
}
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Converts: `Bearer a="b" c="d"`.
|
|
76
|
+
* Into: `[ { a: 'b', c: 'd' }]`.
|
|
77
|
+
*
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
function parseChallenge(challenge) {
|
|
81
|
+
const bearerChallenge = challenge.slice("Bearer ".length);
|
|
82
|
+
const challengeParts = `${bearerChallenge.trim()} `.split(" ").filter((x) => x);
|
|
83
|
+
const keyValuePairs = challengeParts.map((keyValue) => (([key, value]) => ({ [key]: value }))(keyValue.trim().split("=")));
|
|
84
|
+
// Key-value pairs to plain object:
|
|
85
|
+
return keyValuePairs.reduce((a, b) => (Object.assign(Object.assign({}, a), b)), {});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Extracts the options form a Pipeline Request for later re-use
|
|
89
|
+
*/
|
|
90
|
+
function requestToOptions(request) {
|
|
91
|
+
return {
|
|
92
|
+
abortSignal: request.abortSignal,
|
|
93
|
+
requestOptions: {
|
|
94
|
+
timeout: request.timeout,
|
|
95
|
+
},
|
|
96
|
+
tracingOptions: request.tracingOptions,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=authorizeRequestOnTenantChallenge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorizeRequestOnTenantChallenge.js","sourceRoot":"","sources":["../../src/authorizeRequestOnTenantChallenge.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC;;GAEG;AACH,MAAM,SAAS,GAAG;IAChB,YAAY,EAAE,WAAW;IACzB;;OAEG;IACH,eAAe,EAAE;QACf;;WAEG;QACH,aAAa,EAAE,eAAe;KAC/B;CACF,CAAC;AAEF;;;;IAII;AACJ,MAAM,CAAC,MAAM,iCAAiC,GAEtB,KAAK,EAAE,gBAAgB,EAAE,EAAE;IACjD,MAAM,cAAc,GAAG,gBAAgB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAClE,MAAM,SAAS,GAAG,YAAY,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC1D,IAAI,SAAS,EAAE;QACb,MAAM,aAAa,GAAc,cAAc,CAAC,SAAS,CAAC,CAAC;QAC3D,MAAM,eAAe,GAAG,WAAW,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAC;QACrE,MAAM,QAAQ,GAAG,eAAe,CAAC,aAAa,CAAC,CAAC;QAChD,MAAM,WAAW,GAAG,MAAM,gBAAgB,CAAC,cAAc,CAAC,eAAe,kCACpE,cAAc,KACjB,QAAQ,IACR,CAAC;QAEH,IAAI,CAAC,WAAW,EAAE;YAChB,OAAO,KAAK,CAAC;SACd;QAED,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAClC,SAAS,CAAC,eAAe,CAAC,aAAa,EACvC,UAAU,WAAW,CAAC,KAAK,EAAE,CAC9B,CAAC;QACF,OAAO,IAAI,CAAC;KACb;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF;;;;GAIG;AACH,SAAS,eAAe,CAAC,aAAwB;IAC/C,MAAM,aAAa,GAAG,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AC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CACnE,CAAC;IACF,mCAAmC;IACnC,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,iCAAM,CAAC,GAAK,CAAC,EAAG,EAAE,EAAe,CAAC,CAAC;AAC3E,CAAC;AAED;;GAEG;AACH,SAAS,gBAAgB,CAAC,OAAwB;IAChD,OAAO;QACL,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,cAAc,EAAE;YACd,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB;QACD,cAAc,EAAE,OAAO,CAAC,cAAc;KACvC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n AuthorizeRequestOnChallengeOptions,\n PipelineRequest,\n PipelineResponse,\n} from \"@azure/core-rest-pipeline\";\n\nimport { GetTokenOptions } from \"@azure/core-auth\";\n\n/**\n * A set of constants used internally when processing requests.\n */\nconst Constants = {\n DefaultScope: \"/.default\",\n /**\n * Defines constants for use with HTTP headers.\n */\n HeaderConstants: {\n /**\n * The Authorization header.\n */\n AUTHORIZATION: \"authorization\",\n },\n};\n\n/**\n * Defines a callback to handle auth challenge for Storage APIs.\n * This implements the bearer challenge process described here: https://docs.microsoft.com/rest/api/storageservices/authorize-with-azure-active-directory#bearer-challenge\n * Handling has specific features for storage that departs to the general AAD challenge docs.\n **/\nexport const authorizeRequestOnTenantChallenge: (\n challengeOptions: AuthorizeRequestOnChallengeOptions\n) => Promise<boolean> = async (challengeOptions) => {\n const requestOptions = requestToOptions(challengeOptions.request);\n const challenge = getChallenge(challengeOptions.response);\n if (challenge) {\n const challengeInfo: Challenge = parseChallenge(challenge);\n const challengeScopes = buildScopes(challengeOptions, challengeInfo);\n const tenantId = extractTenantId(challengeInfo);\n const accessToken = await challengeOptions.getAccessToken(challengeScopes, {\n ...requestOptions,\n tenantId,\n });\n\n if (!accessToken) {\n return false;\n }\n\n challengeOptions.request.headers.set(\n Constants.HeaderConstants.AUTHORIZATION,\n `Bearer ${accessToken.token}`\n );\n return true;\n }\n return false;\n};\n\n/**\n * Extracts the tenant id from the challenge information\n * The tenant id is contained in the authorization_uri as the first\n * path part.\n */\nfunction extractTenantId(challengeInfo: Challenge): string {\n const parsedAuthUri = new URL(challengeInfo.authorization_uri);\n const pathSegments = parsedAuthUri.pathname.split(\"/\");\n const tenantId = pathSegments[1];\n\n return tenantId;\n}\n\n/**\n * Builds the authentication scopes based on the information that comes in the\n * challenge information. Scopes url is present in the resource_id, if it is empty\n * we keep using the original scopes.\n */\nfunction buildScopes(\n challengeOptions: AuthorizeRequestOnChallengeOptions,\n challengeInfo: Challenge\n): string[] {\n if (!challengeInfo.resource_uri) {\n return challengeOptions.scopes;\n }\n\n const challengeScopes = new URL(challengeInfo.resource_uri);\n challengeScopes.pathname = Constants.DefaultScope;\n return [challengeScopes.toString()];\n}\n\n/**\n * We will retrieve the challenge only if the response status code was 401,\n * and if the response contained the header \"WWW-Authenticate\" with a non-empty value.\n */\nfunction getChallenge(response: PipelineResponse): string | undefined {\n const challenge = response.headers.get(\"WWW-Authenticate\");\n if (response.status === 401 && challenge) {\n return challenge;\n }\n return;\n}\n\n/**\n * Challenge structure\n */\ninterface Challenge {\n authorization_uri: string;\n resource_uri?: string;\n}\n\n/**\n * Converts: `Bearer a=\"b\" c=\"d\"`.\n * Into: `[ { a: 'b', c: 'd' }]`.\n *\n * @internal\n */\nfunction parseChallenge(challenge: string): Challenge {\n const bearerChallenge = challenge.slice(\"Bearer \".length);\n const challengeParts = `${bearerChallenge.trim()} `.split(\" \").filter((x) => x);\n const keyValuePairs = challengeParts.map((keyValue) =>\n (([key, value]) => ({ [key]: value }))(keyValue.trim().split(\"=\"))\n );\n // Key-value pairs to plain object:\n return keyValuePairs.reduce((a, b) => ({ ...a, ...b }), {} as Challenge);\n}\n\n/**\n * Extracts the options form a Pipeline Request for later re-use\n */\nfunction requestToOptions(request: PipelineRequest): GetTokenOptions {\n return {\n abortSignal: request.abortSignal,\n requestOptions: {\n timeout: request.timeout,\n },\n tracingOptions: request.tracingOptions,\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64.browser.js","sourceRoot":"","sources":["../../src/base64.browser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;
|
|
1
|
+
{"version":3,"file":"base64.browser.js","sourceRoot":"","sources":["../../src/base64.browser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAQlC;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;AACrB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,KAAiB;IAC/C,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACrC,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;KACtC;IACD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AACnB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IAC/B,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAC9C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC1C,GAAG,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;KACnC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;AACrB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\ndeclare global {\n // stub these out for the browser\n function btoa(input: string): string;\n function atob(input: string): string;\n}\n\n/**\n * Encodes a string in base64 format.\n * @param value - the string to encode\n */\nexport function encodeString(value: string): string {\n return btoa(value);\n}\n\n/**\n * Encodes a byte array in base64 format.\n * @param value - the Uint8Aray to encode\n */\nexport function encodeByteArray(value: Uint8Array): string {\n let str = \"\";\n for (let i = 0; i < value.length; i++) {\n str += String.fromCharCode(value[i]);\n }\n return btoa(str);\n}\n\n/**\n * Decodes a base64 string into a byte array.\n * @param value - the base64 string to decode\n */\nexport function decodeString(value: string): Uint8Array {\n const byteString = atob(value);\n const arr = new Uint8Array(byteString.length);\n for (let i = 0; i < byteString.length; i++) {\n arr[i] = byteString.charCodeAt(i);\n }\n return arr;\n}\n\n/**\n * Decodes a base64 string into a string.\n * @param value - the base64 string to decode\n */\nexport function decodeStringToString(value: string): string {\n return atob(value);\n}\n"]}
|
package/dist-esm/src/index.js
CHANGED
|
@@ -7,4 +7,5 @@ export { XML_ATTRKEY, XML_CHARKEY, } from "./interfaces";
|
|
|
7
7
|
export { deserializationPolicy, deserializationPolicyName, } from "./deserializationPolicy";
|
|
8
8
|
export { serializationPolicy, serializationPolicyName, } from "./serializationPolicy";
|
|
9
9
|
export { authorizeRequestOnClaimChallenge } from "./authorizeRequestOnClaimChallenge";
|
|
10
|
+
export { authorizeRequestOnTenantChallenge } from "./authorizeRequestOnTenantChallenge";
|
|
10
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,aAAa,EAAwB,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAiC,MAAM,YAAY,CAAC;AACjF,OAAO,EA8BL,WAAW,EACX,WAAW,GAMZ,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,qBAAqB,EACrB,yBAAyB,GAG1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,mBAAmB,EACnB,uBAAuB,GAExB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport { createSerializer, MapperTypeNames } from \"./serializer\";\nexport { ServiceClient, ServiceClientOptions } from \"./serviceClient\";\nexport { createClientPipeline, InternalClientPipelineOptions } from \"./pipeline\";\nexport {\n OperationSpec,\n OperationArguments,\n OperationOptions,\n OperationResponseMap,\n OperationParameter,\n OperationQueryParameter,\n OperationURLParameter,\n Serializer,\n BaseMapper,\n Mapper,\n MapperType,\n SimpleMapperType,\n EnumMapper,\n EnumMapperType,\n SequenceMapper,\n SequenceMapperType,\n DictionaryMapper,\n DictionaryMapperType,\n CompositeMapper,\n CompositeMapperType,\n MapperConstraints,\n OperationRequest,\n OperationRequestOptions,\n OperationRequestInfo,\n QueryCollectionFormat,\n ParameterPath,\n FullOperationResponse,\n PolymorphicDiscriminator,\n SpanConfig,\n XML_ATTRKEY,\n XML_CHARKEY,\n XmlOptions,\n SerializerOptions,\n RawResponseCallback,\n CommonClientOptions,\n AdditionalPolicyConfig,\n} from \"./interfaces\";\nexport {\n deserializationPolicy,\n deserializationPolicyName,\n DeserializationPolicyOptions,\n DeserializationContentTypes,\n} from \"./deserializationPolicy\";\nexport {\n serializationPolicy,\n serializationPolicyName,\n SerializationPolicyOptions,\n} from \"./serializationPolicy\";\nexport { authorizeRequestOnClaimChallenge } from \"./authorizeRequestOnClaimChallenge\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,aAAa,EAAwB,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAiC,MAAM,YAAY,CAAC;AACjF,OAAO,EA8BL,WAAW,EACX,WAAW,GAMZ,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,qBAAqB,EACrB,yBAAyB,GAG1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,mBAAmB,EACnB,uBAAuB,GAExB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAC;AACtF,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport { createSerializer, MapperTypeNames } from \"./serializer\";\nexport { ServiceClient, ServiceClientOptions } from \"./serviceClient\";\nexport { createClientPipeline, InternalClientPipelineOptions } from \"./pipeline\";\nexport {\n OperationSpec,\n OperationArguments,\n OperationOptions,\n OperationResponseMap,\n OperationParameter,\n OperationQueryParameter,\n OperationURLParameter,\n Serializer,\n BaseMapper,\n Mapper,\n MapperType,\n SimpleMapperType,\n EnumMapper,\n EnumMapperType,\n SequenceMapper,\n SequenceMapperType,\n DictionaryMapper,\n DictionaryMapperType,\n CompositeMapper,\n CompositeMapperType,\n MapperConstraints,\n OperationRequest,\n OperationRequestOptions,\n OperationRequestInfo,\n QueryCollectionFormat,\n ParameterPath,\n FullOperationResponse,\n PolymorphicDiscriminator,\n SpanConfig,\n XML_ATTRKEY,\n XML_CHARKEY,\n XmlOptions,\n SerializerOptions,\n RawResponseCallback,\n CommonClientOptions,\n AdditionalPolicyConfig,\n} from \"./interfaces\";\nexport {\n deserializationPolicy,\n deserializationPolicyName,\n DeserializationPolicyOptions,\n DeserializationContentTypes,\n} from \"./deserializationPolicy\";\nexport {\n serializationPolicy,\n serializationPolicyName,\n SerializationPolicyOptions,\n} from \"./serializationPolicy\";\nexport { authorizeRequestOnClaimChallenge } from \"./authorizeRequestOnClaimChallenge\";\nexport { authorizeRequestOnTenantChallenge } from \"./authorizeRequestOnTenantChallenge\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/log.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,MAAM,CAAC,MAAM,MAAM,GAAG,kBAAkB,CAAC,aAAa,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { createClientLogger } from \"@azure/logger\";\nexport const logger = createClientLogger(\"core-client\");\n"]}
|
|
@@ -7,6 +7,7 @@ import { getCachedDefaultHttpClient } from "./httpClientCache";
|
|
|
7
7
|
import { getOperationRequestInfo } from "./operationHelpers";
|
|
8
8
|
import { getRequestUrl } from "./urlHelpers";
|
|
9
9
|
import { getStreamingResponseStatusCodes } from "./interfaceHelpers";
|
|
10
|
+
import { logger } from "./log";
|
|
10
11
|
/**
|
|
11
12
|
* Initializes a new instance of the ServiceClient.
|
|
12
13
|
*/
|
|
@@ -17,13 +18,16 @@ export class ServiceClient {
|
|
|
17
18
|
* @param options - The service client options that govern the behavior of the client.
|
|
18
19
|
*/
|
|
19
20
|
constructor(options = {}) {
|
|
20
|
-
var _a;
|
|
21
|
+
var _a, _b;
|
|
21
22
|
this._requestContentType = options.requestContentType;
|
|
22
|
-
this.
|
|
23
|
+
this._endpoint = (_a = options.endpoint) !== null && _a !== void 0 ? _a : options.baseUri;
|
|
24
|
+
if (options.baseUri) {
|
|
25
|
+
logger.warning("The baseUri option for SDK Clients has been deprecated, please use endpoint instead.");
|
|
26
|
+
}
|
|
23
27
|
this._allowInsecureConnection = options.allowInsecureConnection;
|
|
24
28
|
this._httpClient = options.httpClient || getCachedDefaultHttpClient();
|
|
25
29
|
this.pipeline = options.pipeline || createDefaultPipeline(options);
|
|
26
|
-
if ((
|
|
30
|
+
if ((_b = options.additionalPolicies) === null || _b === void 0 ? void 0 : _b.length) {
|
|
27
31
|
for (const { policy, position } of options.additionalPolicies) {
|
|
28
32
|
// Sign happens after Retry and is commonly needed to occur
|
|
29
33
|
// before policies that intercept post-retry.
|
|
@@ -47,14 +51,14 @@ export class ServiceClient {
|
|
|
47
51
|
* @param operationSpec - The OperationSpec to use to populate the httpRequest.
|
|
48
52
|
*/
|
|
49
53
|
async sendOperationRequest(operationArguments, operationSpec) {
|
|
50
|
-
const
|
|
51
|
-
if (!
|
|
52
|
-
throw new Error("If operationSpec.baseUrl is not specified, then the ServiceClient must have a
|
|
54
|
+
const endpoint = operationSpec.baseUrl || this._endpoint;
|
|
55
|
+
if (!endpoint) {
|
|
56
|
+
throw new Error("If operationSpec.baseUrl is not specified, then the ServiceClient must have a endpoint string property that contains the base URL to use.");
|
|
53
57
|
}
|
|
54
58
|
// Templatized URLs sometimes reference properties on the ServiceClient child class,
|
|
55
59
|
// so we have to pass `this` below in order to search these properties if they're
|
|
56
60
|
// not part of OperationArguments
|
|
57
|
-
const url = getRequestUrl(
|
|
61
|
+
const url = getRequestUrl(endpoint, operationSpec, operationArguments, this);
|
|
58
62
|
const request = createPipelineRequest({
|
|
59
63
|
url,
|
|
60
64
|
});
|
|
@@ -134,11 +138,14 @@ function getCredentialScopes(options) {
|
|
|
134
138
|
? scopes.map((scope) => new URL(scope).toString())
|
|
135
139
|
: new URL(scopes).toString();
|
|
136
140
|
}
|
|
141
|
+
if (options.endpoint) {
|
|
142
|
+
return `${options.endpoint}/.default`;
|
|
143
|
+
}
|
|
137
144
|
if (options.baseUri) {
|
|
138
145
|
return `${options.baseUri}/.default`;
|
|
139
146
|
}
|
|
140
147
|
if (options.credential && !options.credentialScopes) {
|
|
141
|
-
throw new Error(`When using credentials, the ServiceClientOptions must contain either a
|
|
148
|
+
throw new Error(`When using credentials, the ServiceClientOptions must contain either a endpoint or a credentialScopes. Unable to create a bearerTokenAuthenticationPolicy`);
|
|
142
149
|
}
|
|
143
150
|
return undefined;
|
|
144
151
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serviceClient.js","sourceRoot":"","sources":["../../src/serviceClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAQlC,OAAO,EAKL,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AA8BrE;;GAEG;AACH,MAAM,OAAO,aAAa;IA4BxB;;;;OAIG;IACH,YAAY,UAAgC,EAAE;;QAC5C,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC;QACtD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;QAChC,IAAI,CAAC,wBAAwB,GAAG,OAAO,CAAC,uBAAuB,CAAC;QAChE,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,UAAU,IAAI,0BAA0B,EAAE,CAAC;QAEtE,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,qBAAqB,CAAC,OAAO,CAAC,CAAC;QACnE,IAAI,MAAA,OAAO,CAAC,kBAAkB,0CAAE,MAAM,EAAE;YACtC,KAAK,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE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AC,gBAAgB,CAAC;QACxC,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;YAC1B,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC;YAClD,CAAC,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;KAChC;IAED,IAAI,OAAO,CAAC,OAAO,EAAE;QACnB,OAAO,GAAG,OAAO,CAAC,OAAO,WAAW,CAAC;KACtC;IAED,IAAI,OAAO,CAAC,UAAU,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE;QACnD,MAAM,IAAI,KAAK,CACb,0JAA0J,CAC3J,CAAC;KACH;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n CommonClientOptions,\n OperationArguments,\n OperationRequest,\n OperationSpec,\n} from \"./interfaces\";\nimport {\n HttpClient,\n Pipeline,\n PipelineRequest,\n PipelineResponse,\n createPipelineRequest,\n} from \"@azure/core-rest-pipeline\";\nimport { TokenCredential } from \"@azure/core-auth\";\nimport { createClientPipeline } from \"./pipeline\";\nimport { flattenResponse } from \"./utils\";\nimport { getCachedDefaultHttpClient } from \"./httpClientCache\";\nimport { getOperationRequestInfo } from \"./operationHelpers\";\nimport { getRequestUrl } from \"./urlHelpers\";\nimport { getStreamingResponseStatusCodes } from \"./interfaceHelpers\";\n\n/**\n * Options to be provided while creating the client.\n */\nexport interface ServiceClientOptions extends CommonClientOptions {\n /**\n * If specified, this is the base URI that requests will be made against for this ServiceClient.\n * If it is not specified, then all OperationSpecs must contain a baseUrl property.\n */\n baseUri?: string;\n /**\n * If specified, will be used to build the BearerTokenAuthenticationPolicy.\n */\n credentialScopes?: string | string[];\n /**\n * The default request content type for the service.\n * Used if no requestContentType is present on an OperationSpec.\n */\n requestContentType?: string;\n /**\n * Credential used to authenticate the request.\n */\n credential?: TokenCredential;\n /**\n * A customized pipeline to use, otherwise a default one will be created.\n */\n pipeline?: Pipeline;\n}\n\n/**\n * Initializes a new instance of the ServiceClient.\n */\nexport class ServiceClient {\n /**\n * If specified, this is the base URI that requests will be made against for this ServiceClient.\n * If it is not specified, then all OperationSpecs must contain a baseUrl property.\n */\n private readonly _baseUri?: string;\n\n /**\n * The default request content type for the service.\n * Used if no requestContentType is present on an OperationSpec.\n */\n private readonly _requestContentType?: string;\n\n /**\n * Set to true if the request is sent over HTTP instead of HTTPS\n */\n private readonly _allowInsecureConnection?: boolean;\n\n /**\n * The HTTP client that will be used to send requests.\n */\n private readonly _httpClient: HttpClient;\n\n /**\n * The pipeline used by this client to make requests\n */\n public readonly pipeline: Pipeline;\n\n /**\n * The ServiceClient constructor\n * @param credential - The credentials used for authentication with the service.\n * @param options - The service client options that govern the behavior of the client.\n */\n constructor(options: ServiceClientOptions = {}) {\n this._requestContentType = options.requestContentType;\n this._baseUri = options.baseUri;\n this._allowInsecureConnection = options.allowInsecureConnection;\n this._httpClient = options.httpClient || getCachedDefaultHttpClient();\n\n this.pipeline = options.pipeline || createDefaultPipeline(options);\n if (options.additionalPolicies?.length) {\n for (const { policy, position } of options.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 this.pipeline.addPolicy(policy, {\n afterPhase,\n });\n }\n }\n }\n\n /**\n * Send the provided httpRequest.\n */\n async sendRequest(request: PipelineRequest): Promise<PipelineResponse> {\n return this.pipeline.sendRequest(this._httpClient, request);\n }\n\n /**\n * Send an HTTP request that is populated using the provided OperationSpec.\n * @typeParam T - The typed result of the request, based on the OperationSpec.\n * @param operationArguments - The arguments that the HTTP request's templated values will be populated from.\n * @param operationSpec - The OperationSpec to use to populate the httpRequest.\n */\n async sendOperationRequest<T>(\n operationArguments: OperationArguments,\n operationSpec: OperationSpec\n ): Promise<T> {\n const baseUri: string | undefined = operationSpec.baseUrl || this._baseUri;\n if (!baseUri) {\n throw new Error(\n \"If operationSpec.baseUrl is not specified, then the ServiceClient must have a baseUri string property that contains the base URL to use.\"\n );\n }\n\n // Templatized URLs sometimes reference properties on the ServiceClient child class,\n // so we have to pass `this` below in order to search these properties if they're\n // not part of OperationArguments\n const url = getRequestUrl(baseUri, operationSpec, operationArguments, this);\n\n const request: OperationRequest = createPipelineRequest({\n url,\n });\n request.method = operationSpec.httpMethod;\n const operationInfo = getOperationRequestInfo(request);\n operationInfo.operationSpec = operationSpec;\n operationInfo.operationArguments = operationArguments;\n\n const contentType = operationSpec.contentType || this._requestContentType;\n if (contentType && operationSpec.requestBody) {\n request.headers.set(\"Content-Type\", contentType);\n }\n\n const options = operationArguments.options;\n if (options) {\n const requestOptions = options.requestOptions;\n\n if (requestOptions) {\n if (requestOptions.timeout) {\n request.timeout = requestOptions.timeout;\n }\n\n if (requestOptions.onUploadProgress) {\n request.onUploadProgress = requestOptions.onUploadProgress;\n }\n\n if (requestOptions.onDownloadProgress) {\n request.onDownloadProgress = requestOptions.onDownloadProgress;\n }\n\n if (requestOptions.shouldDeserialize !== undefined) {\n operationInfo.shouldDeserialize = requestOptions.shouldDeserialize;\n }\n\n if (requestOptions.allowInsecureConnection) {\n request.allowInsecureConnection = true;\n }\n }\n\n if (options.abortSignal) {\n request.abortSignal = options.abortSignal;\n }\n\n if (options.tracingOptions) {\n request.tracingOptions = options.tracingOptions;\n }\n }\n\n if (this._allowInsecureConnection) {\n request.allowInsecureConnection = true;\n }\n\n if (request.streamResponseStatusCodes === undefined) {\n request.streamResponseStatusCodes = getStreamingResponseStatusCodes(operationSpec);\n }\n\n try {\n const rawResponse = await this.sendRequest(request);\n const flatResponse = flattenResponse(\n rawResponse,\n operationSpec.responses[rawResponse.status]\n ) as T;\n if (options?.onResponse) {\n options.onResponse(rawResponse, flatResponse);\n }\n return flatResponse;\n } catch (error: any) {\n if (typeof error === \"object\" && error?.response) {\n const rawResponse = error.response;\n const flatResponse = flattenResponse(\n rawResponse,\n operationSpec.responses[error.statusCode] || operationSpec.responses[\"default\"]\n );\n error.details = flatResponse;\n if (options?.onResponse) {\n options.onResponse(rawResponse, flatResponse, error);\n }\n }\n throw error;\n }\n }\n}\n\nfunction createDefaultPipeline(options: ServiceClientOptions): Pipeline {\n const credentialScopes = getCredentialScopes(options);\n const credentialOptions =\n options.credential && credentialScopes\n ? { credentialScopes, credential: options.credential }\n : undefined;\n\n return createClientPipeline({\n ...options,\n credentialOptions,\n });\n}\n\nfunction getCredentialScopes(options: ServiceClientOptions): string | string[] | undefined {\n if (options.credentialScopes) {\n const scopes = options.credentialScopes;\n return Array.isArray(scopes)\n ? scopes.map((scope) => new URL(scope).toString())\n : new URL(scopes).toString();\n }\n\n if (options.baseUri) {\n return `${options.baseUri}/.default`;\n }\n\n if (options.credential && !options.credentialScopes) {\n throw new Error(\n `When using credentials, the ServiceClientOptions must contain either a baseUri or a credentialScopes. Unable to create a bearerTokenAuthenticationPolicy`\n );\n }\n\n return undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"serviceClient.js","sourceRoot":"","sources":["../../src/serviceClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAQlC,OAAO,EAKL,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAqC/B;;GAEG;AACH,MAAM,OAAO,aAAa;IA4Bx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right (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n CommonClientOptions,\n OperationArguments,\n OperationRequest,\n OperationSpec,\n} from \"./interfaces\";\nimport {\n HttpClient,\n Pipeline,\n PipelineRequest,\n PipelineResponse,\n createPipelineRequest,\n} from \"@azure/core-rest-pipeline\";\nimport { TokenCredential } from \"@azure/core-auth\";\nimport { createClientPipeline } from \"./pipeline\";\nimport { flattenResponse } from \"./utils\";\nimport { getCachedDefaultHttpClient } from \"./httpClientCache\";\nimport { getOperationRequestInfo } from \"./operationHelpers\";\nimport { getRequestUrl } from \"./urlHelpers\";\nimport { getStreamingResponseStatusCodes } from \"./interfaceHelpers\";\nimport { logger } from \"./log\";\n\n/**\n * Options to be provided while creating the client.\n */\nexport interface ServiceClientOptions extends CommonClientOptions {\n /**\n * If specified, this is the base URI that requests will be made against for this ServiceClient.\n * If it is not specified, then all OperationSpecs must contain a baseUrl property.\n * @deprecated This property is deprecated and will be removed soon, please use endpoint instead\n */\n baseUri?: string;\n /**\n * If specified, this is the endpoint that requests will be made against for this ServiceClient.\n * If it is not specified, then all OperationSpecs must contain a baseUrl property.\n * to encourage customer to use endpoint, we mark the baseUri as deprecated.\n */\n endpoint?: string;\n /**\n * If specified, will be used to build the BearerTokenAuthenticationPolicy.\n */\n credentialScopes?: string | string[];\n /**\n * The default request content type for the service.\n * Used if no requestContentType is present on an OperationSpec.\n */\n requestContentType?: string;\n /**\n * Credential used to authenticate the request.\n */\n credential?: TokenCredential;\n /**\n * A customized pipeline to use, otherwise a default one will be created.\n */\n pipeline?: Pipeline;\n}\n\n/**\n * Initializes a new instance of the ServiceClient.\n */\nexport class ServiceClient {\n /**\n * If specified, this is the base URI that requests will be made against for this ServiceClient.\n * If it is not specified, then all OperationSpecs must contain a baseUrl property.\n */\n private readonly _endpoint?: string;\n\n /**\n * The default request content type for the service.\n * Used if no requestContentType is present on an OperationSpec.\n */\n private readonly _requestContentType?: string;\n\n /**\n * Set to true if the request is sent over HTTP instead of HTTPS\n */\n private readonly _allowInsecureConnection?: boolean;\n\n /**\n * The HTTP client that will be used to send requests.\n */\n private readonly _httpClient: HttpClient;\n\n /**\n * The pipeline used by this client to make requests\n */\n public readonly pipeline: Pipeline;\n\n /**\n * The ServiceClient constructor\n * @param credential - The credentials used for authentication with the service.\n * @param options - The service client options that govern the behavior of the client.\n */\n constructor(options: ServiceClientOptions = {}) {\n this._requestContentType = options.requestContentType;\n this._endpoint = options.endpoint ?? options.baseUri;\n if (options.baseUri) {\n logger.warning(\n \"The baseUri option for SDK Clients has been deprecated, please use endpoint instead.\"\n );\n }\n this._allowInsecureConnection = options.allowInsecureConnection;\n this._httpClient = options.httpClient || getCachedDefaultHttpClient();\n\n this.pipeline = options.pipeline || createDefaultPipeline(options);\n if (options.additionalPolicies?.length) {\n for (const { policy, position } of options.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 this.pipeline.addPolicy(policy, {\n afterPhase,\n });\n }\n }\n }\n\n /**\n * Send the provided httpRequest.\n */\n async sendRequest(request: PipelineRequest): Promise<PipelineResponse> {\n return this.pipeline.sendRequest(this._httpClient, request);\n }\n\n /**\n * Send an HTTP request that is populated using the provided OperationSpec.\n * @typeParam T - The typed result of the request, based on the OperationSpec.\n * @param operationArguments - The arguments that the HTTP request's templated values will be populated from.\n * @param operationSpec - The OperationSpec to use to populate the httpRequest.\n */\n async sendOperationRequest<T>(\n operationArguments: OperationArguments,\n operationSpec: OperationSpec\n ): Promise<T> {\n const endpoint: string | undefined = operationSpec.baseUrl || this._endpoint;\n if (!endpoint) {\n throw new Error(\n \"If operationSpec.baseUrl is not specified, then the ServiceClient must have a endpoint string property that contains the base URL to use.\"\n );\n }\n\n // Templatized URLs sometimes reference properties on the ServiceClient child class,\n // so we have to pass `this` below in order to search these properties if they're\n // not part of OperationArguments\n const url = getRequestUrl(endpoint, operationSpec, operationArguments, this);\n\n const request: OperationRequest = createPipelineRequest({\n url,\n });\n request.method = operationSpec.httpMethod;\n const operationInfo = getOperationRequestInfo(request);\n operationInfo.operationSpec = operationSpec;\n operationInfo.operationArguments = operationArguments;\n\n const contentType = operationSpec.contentType || this._requestContentType;\n if (contentType && operationSpec.requestBody) {\n request.headers.set(\"Content-Type\", contentType);\n }\n\n const options = operationArguments.options;\n if (options) {\n const requestOptions = options.requestOptions;\n\n if (requestOptions) {\n if (requestOptions.timeout) {\n request.timeout = requestOptions.timeout;\n }\n\n if (requestOptions.onUploadProgress) {\n request.onUploadProgress = requestOptions.onUploadProgress;\n }\n\n if (requestOptions.onDownloadProgress) {\n request.onDownloadProgress = requestOptions.onDownloadProgress;\n }\n\n if (requestOptions.shouldDeserialize !== undefined) {\n operationInfo.shouldDeserialize = requestOptions.shouldDeserialize;\n }\n\n if (requestOptions.allowInsecureConnection) {\n request.allowInsecureConnection = true;\n }\n }\n\n if (options.abortSignal) {\n request.abortSignal = options.abortSignal;\n }\n\n if (options.tracingOptions) {\n request.tracingOptions = options.tracingOptions;\n }\n }\n\n if (this._allowInsecureConnection) {\n request.allowInsecureConnection = true;\n }\n\n if (request.streamResponseStatusCodes === undefined) {\n request.streamResponseStatusCodes = getStreamingResponseStatusCodes(operationSpec);\n }\n\n try {\n const rawResponse = await this.sendRequest(request);\n const flatResponse = flattenResponse(\n rawResponse,\n operationSpec.responses[rawResponse.status]\n ) as T;\n if (options?.onResponse) {\n options.onResponse(rawResponse, flatResponse);\n }\n return flatResponse;\n } catch (error: any) {\n if (typeof error === \"object\" && error?.response) {\n const rawResponse = error.response;\n const flatResponse = flattenResponse(\n rawResponse,\n operationSpec.responses[error.statusCode] || operationSpec.responses[\"default\"]\n );\n error.details = flatResponse;\n if (options?.onResponse) {\n options.onResponse(rawResponse, flatResponse, error);\n }\n }\n throw error;\n }\n }\n}\n\nfunction createDefaultPipeline(options: ServiceClientOptions): Pipeline {\n const credentialScopes = getCredentialScopes(options);\n const credentialOptions =\n options.credential && credentialScopes\n ? { credentialScopes, credential: options.credential }\n : undefined;\n\n return createClientPipeline({\n ...options,\n credentialOptions,\n });\n}\n\nfunction getCredentialScopes(options: ServiceClientOptions): string | string[] | undefined {\n if (options.credentialScopes) {\n const scopes = options.credentialScopes;\n return Array.isArray(scopes)\n ? scopes.map((scope) => new URL(scope).toString())\n : new URL(scopes).toString();\n }\n\n if (options.endpoint) {\n return `${options.endpoint}/.default`;\n }\n\n if (options.baseUri) {\n return `${options.baseUri}/.default`;\n }\n\n if (options.credential && !options.credentialScopes) {\n throw new Error(\n `When using credentials, the ServiceClientOptions must contain either a endpoint or a credentialScopes. Unable to create a bearerTokenAuthenticationPolicy`\n );\n }\n\n return undefined;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure/core-client",
|
|
3
|
-
"version": "1.6.0-alpha.
|
|
3
|
+
"version": "1.6.0-alpha.20220503.1",
|
|
4
4
|
"description": "Core library for interfacing with AutoRest generated code",
|
|
5
5
|
"sdk-type": "client",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -72,12 +72,13 @@
|
|
|
72
72
|
"@azure/core-auth": "^1.3.0",
|
|
73
73
|
"@azure/core-rest-pipeline": "^1.5.0",
|
|
74
74
|
"@azure/core-tracing": "^1.0.0",
|
|
75
|
+
"@azure/core-util": ">=1.0.0-alpha <1.0.0-alphb",
|
|
75
76
|
"@azure/logger": "^1.0.0",
|
|
76
77
|
"tslib": "^2.2.0"
|
|
77
78
|
},
|
|
78
79
|
"devDependencies": {
|
|
79
80
|
"@azure/core-xml": "^1.0.0",
|
|
80
|
-
"@microsoft/api-extractor": "
|
|
81
|
+
"@microsoft/api-extractor": "7.18.11",
|
|
81
82
|
"@types/chai": "^4.1.6",
|
|
82
83
|
"@types/mocha": "^7.0.2",
|
|
83
84
|
"@types/node": "^12.0.0",
|
|
@@ -54,6 +54,12 @@ export declare interface AdditionalPolicyConfig {
|
|
|
54
54
|
* ```
|
|
55
55
|
*/
|
|
56
56
|
export declare function authorizeRequestOnClaimChallenge(onChallengeOptions: AuthorizeRequestOnChallengeOptions): Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* Defines a callback to handle auth challenge for Storage APIs.
|
|
59
|
+
* This implements the bearer challenge process described here: https://docs.microsoft.com/rest/api/storageservices/authorize-with-azure-active-directory#bearer-challenge
|
|
60
|
+
* Handling has specific features for storage that departs to the general AAD challenge docs.
|
|
61
|
+
**/
|
|
62
|
+
export declare const authorizeRequestOnTenantChallenge: (challengeOptions: AuthorizeRequestOnChallengeOptions) => Promise<boolean>;
|
|
57
63
|
/**
|
|
58
64
|
* The base definition of a mapper. Can be used for XML and plain JavaScript objects.
|
|
59
65
|
*/
|
|
@@ -764,7 +770,7 @@ export declare class ServiceClient {
|
|
|
764
770
|
* If specified, this is the base URI that requests will be made against for this ServiceClient.
|
|
765
771
|
* If it is not specified, then all OperationSpecs must contain a baseUrl property.
|
|
766
772
|
*/
|
|
767
|
-
private readonly
|
|
773
|
+
private readonly _endpoint?;
|
|
768
774
|
/**
|
|
769
775
|
* The default request content type for the service.
|
|
770
776
|
* Used if no requestContentType is present on an OperationSpec.
|
|
@@ -807,8 +813,15 @@ export declare interface ServiceClientOptions extends CommonClientOptions {
|
|
|
807
813
|
/**
|
|
808
814
|
* If specified, this is the base URI that requests will be made against for this ServiceClient.
|
|
809
815
|
* If it is not specified, then all OperationSpecs must contain a baseUrl property.
|
|
816
|
+
* @deprecated This property is deprecated and will be removed soon, please use endpoint instead
|
|
810
817
|
*/
|
|
811
818
|
baseUri?: string;
|
|
819
|
+
/**
|
|
820
|
+
* If specified, this is the endpoint that requests will be made against for this ServiceClient.
|
|
821
|
+
* If it is not specified, then all OperationSpecs must contain a baseUrl property.
|
|
822
|
+
* to encourage customer to use endpoint, we mark the baseUri as deprecated.
|
|
823
|
+
*/
|
|
824
|
+
endpoint?: string;
|
|
812
825
|
/**
|
|
813
826
|
* If specified, will be used to build the BearerTokenAuthenticationPolicy.
|
|
814
827
|
*/
|
|
@@ -57,6 +57,13 @@ export declare interface AdditionalPolicyConfig {
|
|
|
57
57
|
*/
|
|
58
58
|
export declare function authorizeRequestOnClaimChallenge(onChallengeOptions: AuthorizeRequestOnChallengeOptions): Promise<boolean>;
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Defines a callback to handle auth challenge for Storage APIs.
|
|
62
|
+
* This implements the bearer challenge process described here: https://docs.microsoft.com/rest/api/storageservices/authorize-with-azure-active-directory#bearer-challenge
|
|
63
|
+
* Handling has specific features for storage that departs to the general AAD challenge docs.
|
|
64
|
+
**/
|
|
65
|
+
export declare const authorizeRequestOnTenantChallenge: (challengeOptions: AuthorizeRequestOnChallengeOptions) => Promise<boolean>;
|
|
66
|
+
|
|
60
67
|
/**
|
|
61
68
|
* The base definition of a mapper. Can be used for XML and plain JavaScript objects.
|
|
62
69
|
*/
|
|
@@ -808,7 +815,7 @@ export declare class ServiceClient {
|
|
|
808
815
|
* If specified, this is the base URI that requests will be made against for this ServiceClient.
|
|
809
816
|
* If it is not specified, then all OperationSpecs must contain a baseUrl property.
|
|
810
817
|
*/
|
|
811
|
-
private readonly
|
|
818
|
+
private readonly _endpoint?;
|
|
812
819
|
/**
|
|
813
820
|
* The default request content type for the service.
|
|
814
821
|
* Used if no requestContentType is present on an OperationSpec.
|
|
@@ -852,8 +859,15 @@ export declare interface ServiceClientOptions extends CommonClientOptions {
|
|
|
852
859
|
/**
|
|
853
860
|
* If specified, this is the base URI that requests will be made against for this ServiceClient.
|
|
854
861
|
* If it is not specified, then all OperationSpecs must contain a baseUrl property.
|
|
862
|
+
* @deprecated This property is deprecated and will be removed soon, please use endpoint instead
|
|
855
863
|
*/
|
|
856
864
|
baseUri?: string;
|
|
865
|
+
/**
|
|
866
|
+
* If specified, this is the endpoint that requests will be made against for this ServiceClient.
|
|
867
|
+
* If it is not specified, then all OperationSpecs must contain a baseUrl property.
|
|
868
|
+
* to encourage customer to use endpoint, we mark the baseUri as deprecated.
|
|
869
|
+
*/
|
|
870
|
+
endpoint?: string;
|
|
857
871
|
/**
|
|
858
872
|
* If specified, will be used to build the BearerTokenAuthenticationPolicy.
|
|
859
873
|
*/
|