@azure-rest/maps-route 1.0.0-beta.2 → 1.0.0-beta.4
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/README.md +68 -20
- package/dist/index.js +169 -63
- package/dist/index.js.map +1 -1
- package/dist-esm/src/helpers.js +1 -1
- package/dist-esm/src/helpers.js.map +1 -1
- package/dist-esm/src/index.js +2 -2
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/mapsRoute.js +16 -5
- package/dist-esm/src/mapsRoute.js.map +1 -1
- package/package.json +35 -39
- package/review/maps-route.api.md +117 -90
- package/types/maps-route-rest.d.ts +517 -271
- package/dist-esm/src/generated/clientDefinitions.js +0 -4
- package/dist-esm/src/generated/clientDefinitions.js.map +0 -1
- package/dist-esm/src/generated/index.js +0 -13
- package/dist-esm/src/generated/index.js.map +0 -1
- package/dist-esm/src/generated/isUnexpected.js +0 -77
- package/dist-esm/src/generated/isUnexpected.js.map +0 -1
- package/dist-esm/src/generated/mapsRouteClient.js +0 -25
- package/dist-esm/src/generated/mapsRouteClient.js.map +0 -1
- package/dist-esm/src/generated/models.js +0 -4
- package/dist-esm/src/generated/models.js.map +0 -1
- package/dist-esm/src/generated/outputModels.js +0 -4
- package/dist-esm/src/generated/outputModels.js.map +0 -1
- package/dist-esm/src/generated/parameters.js +0 -4
- package/dist-esm/src/generated/parameters.js.map +0 -1
- package/dist-esm/src/generated/pollingHelper.js +0 -51
- package/dist-esm/src/generated/pollingHelper.js.map +0 -1
- package/dist-esm/src/generated/responses.js +0 -4
- package/dist-esm/src/generated/responses.js.map +0 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ Key links:
|
|
|
15
15
|
|
|
16
16
|
### Currently supported environments
|
|
17
17
|
|
|
18
|
-
- [LTS versions of Node.js](https://
|
|
18
|
+
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
|
|
19
19
|
- Latest versions of Safari, Chrome, Edge and Firefox.
|
|
20
20
|
|
|
21
21
|
### Prerequisites
|
|
@@ -35,19 +35,19 @@ npm install @azure-rest/maps-route
|
|
|
35
35
|
|
|
36
36
|
### Create and authenticate a `MapsRouteClient`
|
|
37
37
|
|
|
38
|
-
To create a client object to access the Azure Maps Route APIs, you will need a `credential` object. The Azure Maps Route client can use
|
|
38
|
+
To create a client object to access the Azure Maps Route APIs, you will need a `credential` object. The Azure Maps Route client can use a Microsoft Entra ID credential or an Azure Key credential to authenticate.
|
|
39
39
|
|
|
40
|
-
#### Using
|
|
40
|
+
#### Using a Microsoft Entra ID Credential
|
|
41
41
|
|
|
42
|
-
You can authenticate with
|
|
42
|
+
You can authenticate with Microsoft Entra ID using the [Azure Identity library][azure_identity]. To use the [DefaultAzureCredential][defaultazurecredential] provider shown below, or other credential providers provided with the Azure SDK, please install the `@azure/identity` package:
|
|
43
43
|
|
|
44
44
|
```bash
|
|
45
45
|
npm install @azure/identity
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
You will also need to register a new
|
|
48
|
+
You will also need to register a new Microsoft Entra ID application and grant access to Azure Maps by assigning the suitable role to your service principal. Please refer to the [Manage authentication](https://docs.microsoft.com/azure/azure-maps/how-to-manage-authentication) page.
|
|
49
49
|
|
|
50
|
-
Set the values of the client ID, tenant ID, and client secret of the
|
|
50
|
+
Set the values of the client ID, tenant ID, and client secret of the Microsoft Entra ID application as environment variables: `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`.
|
|
51
51
|
|
|
52
52
|
You will also need to specify the Azure Maps resource you intend to use by specifying the `clientId` in the client options.
|
|
53
53
|
The Azure Maps resource client id can be found in the Authentication sections in the Azure Maps resource. Please refer to the [documentation](https://docs.microsoft.com/azure/azure-maps/how-to-manage-authentication#view-authentication-details) on how to find it.
|
|
@@ -72,6 +72,52 @@ const credential = new AzureKeyCredential("<subscription-key>");
|
|
|
72
72
|
const client = MapsRoute(credential);
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
+
#### Using a Shared Access Signature (SAS) Token Credential
|
|
76
|
+
|
|
77
|
+
Shared access signature (SAS) tokens are authentication tokens created using the JSON Web token (JWT) format and are cryptographically signed to prove authentication for an application to the Azure Maps REST API.
|
|
78
|
+
|
|
79
|
+
You can get the SAS token using [`AzureMapsManagementClient.accounts.listSas`](https://learn.microsoft.com/javascript/api/%40azure/arm-maps/accounts?view=azure-node-latest#@azure-arm-maps-accounts-listsas) from ["@azure/arm-maps"](https://www.npmjs.com/package/@azure/arm-maps) package. Please follow the section [Create and authenticate a `AzureMapsManagementClient`](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/maps/arm-maps#create-and-authenticate-a-azuremapsmanagementclient) to setup first.
|
|
80
|
+
|
|
81
|
+
Second, follow [Managed identities for Azure Maps](https://techcommunity.microsoft.com/t5/azure-maps-blog/managed-identities-for-azure-maps/ba-p/3666312) to create a managed identity for your Azure Maps account. Copy the principal ID (object ID) of the managed identity.
|
|
82
|
+
|
|
83
|
+
Third, you will need to install["@azure/core-auth"](https://www.npmjs.com/package/@azure/core-auth)package to use `AzureSASCredential`:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
npm install @azure/core-auth
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Finally, you can use the SAS token to authenticate the client:
|
|
90
|
+
|
|
91
|
+
```javascript
|
|
92
|
+
const MapsRoute = require("@azure-rest/maps-route").default;
|
|
93
|
+
const { AzureSASCredential } = require("@azure/core-auth");
|
|
94
|
+
const { DefaultAzureCredential } = require("@azure/identity");
|
|
95
|
+
const { AzureMapsManagementClient } = require("@azure/arm-maps");
|
|
96
|
+
|
|
97
|
+
const subscriptionId = "<subscription ID of the map account>";
|
|
98
|
+
const resourceGroupName = "<resource group name of the map account>";
|
|
99
|
+
const accountName = "<name of the map account>";
|
|
100
|
+
const mapsAccountSasParameters = {
|
|
101
|
+
start: "<start time in ISO format>", // e.g. "2023-11-24T03:51:53.161Z"
|
|
102
|
+
expiry: "<expiry time in ISO format>", // maximum value to start + 1 day
|
|
103
|
+
maxRatePerSecond: 500,
|
|
104
|
+
principalId: "<principle ID (object ID) of the managed identity>",
|
|
105
|
+
signingKey: "primaryKey",
|
|
106
|
+
};
|
|
107
|
+
const credential = new DefaultAzureCredential();
|
|
108
|
+
const managementClient = new AzureMapsManagementClient(credential, subscriptionId);
|
|
109
|
+
const { accountSasToken } = await managementClient.accounts.listSas(
|
|
110
|
+
resourceGroupName,
|
|
111
|
+
accountName,
|
|
112
|
+
mapsAccountSasParameters,
|
|
113
|
+
);
|
|
114
|
+
if (accountSasToken === undefined) {
|
|
115
|
+
throw new Error("No accountSasToken was found for the Maps Account.");
|
|
116
|
+
}
|
|
117
|
+
const sasCredential = new AzureSASCredential(accountSasToken);
|
|
118
|
+
const client = MapsRoute(sasCredential);
|
|
119
|
+
```
|
|
120
|
+
|
|
75
121
|
## Examples
|
|
76
122
|
|
|
77
123
|
The following sections provide several code snippets covering some of the most common Azure Maps Route tasks, including:
|
|
@@ -89,15 +135,15 @@ To retrieve the route direction, you need to pass in the parameters the coordina
|
|
|
89
135
|
By default, the Route service will return an array of coordinates. The response will contain the coordinates that make up the path in a list named points. Route response also includes the distance from the start of the route and the estimated elapsed time. These values can be used to calculate the average speed for the entire route.
|
|
90
136
|
|
|
91
137
|
```javascript
|
|
92
|
-
const
|
|
138
|
+
const { toColonDelimitedLatLonString, isUnexpected } = require("@azure-rest/maps-route");
|
|
139
|
+
const routeDirectionsResult1 = await client.path("/route/directions/{format}", "json").get({
|
|
93
140
|
queryParameters: {
|
|
94
141
|
query: "51.368752,-0.118332:41.385426,-0.128929",
|
|
95
142
|
},
|
|
96
143
|
});
|
|
97
144
|
|
|
98
145
|
// You can use the helper function `toColonDelimitedLatLonString` to compose the query string.
|
|
99
|
-
const
|
|
100
|
-
const routeDirectionsResult = await client.path("/route/directions/{format}", "json").get({
|
|
146
|
+
const routeDirectionsResult2 = await client.path("/route/directions/{format}", "json").get({
|
|
101
147
|
queryParameters: {
|
|
102
148
|
query: toColonDelimitedLatLonString([
|
|
103
149
|
// Origin:
|
|
@@ -113,19 +159,19 @@ const routeDirectionsResult = await client.path("/route/directions/{format}", "j
|
|
|
113
159
|
});
|
|
114
160
|
|
|
115
161
|
// Handle the error if the request failed
|
|
116
|
-
if (isUnexpected(
|
|
117
|
-
throw
|
|
162
|
+
if (isUnexpected(routeDirectionsResult2)) {
|
|
163
|
+
throw routeDirectionsResult2.body.error;
|
|
118
164
|
}
|
|
119
165
|
|
|
120
|
-
|
|
166
|
+
routeDirectionsResult2.body.routes.forEach(({ summary, legs }) => {
|
|
121
167
|
console.log(
|
|
122
|
-
`The total distance is ${summary.lengthInMeters} meters, and it takes ${summary.travelTimeInSeconds} seconds
|
|
168
|
+
`The total distance is ${summary.lengthInMeters} meters, and it takes ${summary.travelTimeInSeconds} seconds.`,
|
|
123
169
|
);
|
|
124
170
|
legs.forEach(({ summary, points }, idx) => {
|
|
125
171
|
console.log(
|
|
126
172
|
`The ${idx + 1}th leg's length is ${summary.lengthInMeters} meters, and it takes ${
|
|
127
173
|
summary.travelTimeInSeconds
|
|
128
|
-
} seconds. Followings are the first 10 points:
|
|
174
|
+
} seconds. Followings are the first 10 points: `,
|
|
129
175
|
);
|
|
130
176
|
console.table(points.slice(0, 10));
|
|
131
177
|
});
|
|
@@ -137,6 +183,7 @@ routeDirectionsResult.body.routes.forEach(({ summary, legs }) => {
|
|
|
137
183
|
The service supports commercial vehicle routing, covering commercial trucks routing. The APIs consider specified limits. Such as, the height and weight of the vehicle, and if the vehicle is carrying hazardous cargo. For example, if a vehicle is carrying flammable, the routing engine avoid certain tunnels that are near residential areas.
|
|
138
184
|
|
|
139
185
|
```javascript
|
|
186
|
+
const { toColonDelimitedLatLonString, isUnexpected } = require("@azure-rest/maps-route");
|
|
140
187
|
const routeDirectionsResult = await client.path("/route/directions/{format}", "json").get({
|
|
141
188
|
queryParameters: {
|
|
142
189
|
query: toColonDelimitedLatLonString([
|
|
@@ -163,13 +210,13 @@ if (isUnexpected(routeDirectionsResult)) {
|
|
|
163
210
|
|
|
164
211
|
routeDirectionsResult.body.routes.forEach(({ summary, legs }) => {
|
|
165
212
|
console.log(
|
|
166
|
-
`The total distance is ${summary.lengthInMeters} meters, and it takes ${summary.travelTimeInSeconds} seconds
|
|
213
|
+
`The total distance is ${summary.lengthInMeters} meters, and it takes ${summary.travelTimeInSeconds} seconds.`,
|
|
167
214
|
);
|
|
168
215
|
legs.forEach(({ summary, points }, idx) => {
|
|
169
216
|
console.log(
|
|
170
217
|
`The ${idx + 1}th leg's length is ${summary.lengthInMeters} meters, and it takes ${
|
|
171
218
|
summary.travelTimeInSeconds
|
|
172
|
-
} seconds. Followings are the first 10 points:
|
|
219
|
+
} seconds. Followings are the first 10 points: `,
|
|
173
220
|
);
|
|
174
221
|
console.table(points.slice(0, 10));
|
|
175
222
|
});
|
|
@@ -188,6 +235,7 @@ For multi-stop routing, up to 150 waypoints may be specified in a single route r
|
|
|
188
235
|
If you want to optimize the best order to visit the given waypoints, then you need to specify `computeBestWaypointOrder=true`. This scenario is also known as the traveling salesman optimization problem.
|
|
189
236
|
|
|
190
237
|
```javascript
|
|
238
|
+
const { toColonDelimitedLatLonString, isUnexpected } = require("@azure-rest/maps-route");
|
|
191
239
|
const routeDirectionsResult = await client.path("/route/directions/{format}", "json").get({
|
|
192
240
|
queryParameters: {
|
|
193
241
|
query: toColonDelimitedLatLonString([
|
|
@@ -200,7 +248,7 @@ const routeDirectionsResult = await client.path("/route/directions/{format}", "j
|
|
|
200
248
|
// Destination:
|
|
201
249
|
[41.385426, -0.128929],
|
|
202
250
|
]),
|
|
203
|
-
|
|
251
|
+
computeBestOrder: true,
|
|
204
252
|
routeType: "shortest",
|
|
205
253
|
},
|
|
206
254
|
});
|
|
@@ -209,13 +257,13 @@ if (isUnexpected(routeDirectionsResult)) {
|
|
|
209
257
|
throw routeDirectionsResult.body.error;
|
|
210
258
|
}
|
|
211
259
|
|
|
212
|
-
const { summary } = routeDirectionsResult.body.routes;
|
|
260
|
+
const { summary } = routeDirectionsResult.body.routes[0];
|
|
213
261
|
console.log(
|
|
214
|
-
`The optimized distance is ${summary.lengthInMeters} meters, and it takes ${summary.travelTimeInSeconds} seconds
|
|
262
|
+
`The optimized distance is ${summary.lengthInMeters} meters, and it takes ${summary.travelTimeInSeconds} seconds.`,
|
|
215
263
|
);
|
|
216
264
|
console.log("The route is optimized by: ");
|
|
217
265
|
routeDirectionsResult.body.optimizedWaypoints.forEach(
|
|
218
|
-
({ providedIndex, optimizedIndex }) => `Moving index ${providedIndex} to ${optimizedIndex}
|
|
266
|
+
({ providedIndex, optimizedIndex }) => `Moving index ${providedIndex} to ${optimizedIndex}`,
|
|
219
267
|
);
|
|
220
268
|
```
|
|
221
269
|
|
package/dist/index.js
CHANGED
|
@@ -4,45 +4,67 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var coreAuth = require('@azure/core-auth');
|
|
6
6
|
var mapsCommon = require('@azure/maps-common');
|
|
7
|
+
var tslib = require('tslib');
|
|
7
8
|
var coreClient = require('@azure-rest/core-client');
|
|
9
|
+
var logger$1 = require('@azure/logger');
|
|
8
10
|
var coreRestPipeline = require('@azure/core-rest-pipeline');
|
|
9
11
|
var coreLro = require('@azure/core-lro');
|
|
10
12
|
|
|
11
13
|
// Copyright (c) Microsoft Corporation.
|
|
14
|
+
// Licensed under the MIT License.
|
|
15
|
+
const logger = logger$1.createClientLogger("maps-route");
|
|
16
|
+
|
|
17
|
+
// Copyright (c) Microsoft Corporation.
|
|
18
|
+
// Licensed under the MIT License.
|
|
12
19
|
/**
|
|
13
|
-
* Initialize a new instance of
|
|
14
|
-
* @param credentials
|
|
20
|
+
* Initialize a new instance of `MapsRouteClient`
|
|
21
|
+
* @param credentials - uniquely identify client credential
|
|
22
|
+
* @param options - the parameter for all optional parameters
|
|
15
23
|
*/
|
|
16
|
-
function createClient(credentials,
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
apiKeyHeaderName: "subscription-key"
|
|
22
|
-
} });
|
|
23
|
-
const userAgentInfo = `azsdk-js-maps-route-rest/1.0.0-beta.1`;
|
|
24
|
+
function createClient(credentials, _a = {}) {
|
|
25
|
+
var _b, _c, _d, _e, _f, _g;
|
|
26
|
+
var { apiVersion = "1.0" } = _a, options = tslib.__rest(_a, ["apiVersion"]);
|
|
27
|
+
const endpointUrl = (_c = (_b = options.endpoint) !== null && _b !== void 0 ? _b : options.baseUrl) !== null && _c !== void 0 ? _c : `https://atlas.microsoft.com`;
|
|
28
|
+
const userAgentInfo = `azsdk-js-maps-route-rest/1.0.0-beta.4`;
|
|
24
29
|
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
25
30
|
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
|
|
26
31
|
: `${userAgentInfo}`;
|
|
27
32
|
options = Object.assign(Object.assign({}, options), { userAgentOptions: {
|
|
28
|
-
userAgentPrefix
|
|
33
|
+
userAgentPrefix,
|
|
34
|
+
}, loggingOptions: {
|
|
35
|
+
logger: (_e = (_d = options.loggingOptions) === null || _d === void 0 ? void 0 : _d.logger) !== null && _e !== void 0 ? _e : logger.info,
|
|
36
|
+
}, credentials: {
|
|
37
|
+
apiKeyHeaderName: (_g = (_f = options.credentials) === null || _f === void 0 ? void 0 : _f.apiKeyHeaderName) !== null && _g !== void 0 ? _g : "subscription-key",
|
|
29
38
|
} });
|
|
30
|
-
const client = coreClient.getClient(
|
|
39
|
+
const client = coreClient.getClient(endpointUrl, credentials, options);
|
|
40
|
+
client.pipeline.removePolicy({ name: "ApiVersionPolicy" });
|
|
41
|
+
client.pipeline.addPolicy({
|
|
42
|
+
name: "ClientApiVersionPolicy",
|
|
43
|
+
sendRequest: (req, next) => {
|
|
44
|
+
// Use the apiVersion defined in request url directly
|
|
45
|
+
// Append one if there is no apiVersion and we have one at client options
|
|
46
|
+
const url = new URL(req.url);
|
|
47
|
+
if (!url.searchParams.get("api-version") && apiVersion) {
|
|
48
|
+
req.url = `${req.url}${Array.from(url.searchParams.keys()).length > 0 ? "&" : "?"}api-version=${apiVersion}`;
|
|
49
|
+
}
|
|
50
|
+
return next(req);
|
|
51
|
+
},
|
|
52
|
+
});
|
|
31
53
|
return client;
|
|
32
54
|
}
|
|
33
55
|
|
|
34
56
|
// Copyright (c) Microsoft Corporation.
|
|
35
|
-
// Licensed under the MIT
|
|
57
|
+
// Licensed under the MIT License.
|
|
36
58
|
const responseMap = {
|
|
37
|
-
"POST /route/matrix/{format}": ["200", "202"],
|
|
38
59
|
"GET /route/matrix/{format}": ["200", "202"],
|
|
60
|
+
"POST /route/matrix/{format}": ["200", "202"],
|
|
39
61
|
"POST /route/matrix/sync/{format}": ["200"],
|
|
40
62
|
"GET /route/directions/{format}": ["200"],
|
|
41
63
|
"POST /route/directions/{format}": ["200"],
|
|
42
64
|
"GET /route/range/{format}": ["200"],
|
|
43
|
-
"POST /route/directions/batch/{format}": ["200", "202"],
|
|
44
65
|
"GET /route/directions/batch/{format}": ["200", "202"],
|
|
45
|
-
"POST /route/directions/batch/
|
|
66
|
+
"POST /route/directions/batch/{format}": ["200", "202"],
|
|
67
|
+
"POST /route/directions/batch/sync/{format}": ["200"],
|
|
46
68
|
};
|
|
47
69
|
function isUnexpected(response) {
|
|
48
70
|
const lroOriginal = response.headers["x-ms-original-url"];
|
|
@@ -50,13 +72,17 @@ function isUnexpected(response) {
|
|
|
50
72
|
const method = response.request.method;
|
|
51
73
|
let pathDetails = responseMap[`${method} ${url.pathname}`];
|
|
52
74
|
if (!pathDetails) {
|
|
53
|
-
pathDetails =
|
|
75
|
+
pathDetails = getParametrizedPathSuccess(method, url.pathname);
|
|
54
76
|
}
|
|
55
77
|
return !pathDetails.includes(response.status);
|
|
56
78
|
}
|
|
57
|
-
function
|
|
58
|
-
var _a, _b;
|
|
79
|
+
function getParametrizedPathSuccess(method, path) {
|
|
80
|
+
var _a, _b, _c, _d;
|
|
59
81
|
const pathParts = path.split("/");
|
|
82
|
+
// Traverse list to match the longest candidate
|
|
83
|
+
// matchedLen: the length of candidate path
|
|
84
|
+
// matchedValue: the matched status code array
|
|
85
|
+
let matchedLen = -1, matchedValue = [];
|
|
60
86
|
// Iterate the responseMap to find a match
|
|
61
87
|
for (const [key, value] of Object.entries(responseMap)) {
|
|
62
88
|
// Extracting the path from the map key which is in format
|
|
@@ -67,41 +93,39 @@ function geParametrizedPathSuccess(method, path) {
|
|
|
67
93
|
const candidatePath = getPathFromMapKey(key);
|
|
68
94
|
// Get each part of the url path
|
|
69
95
|
const candidateParts = candidatePath.split("/");
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
// If the candidate part is not a template and
|
|
85
|
-
// the parts don't match mark the candidate as not found
|
|
86
|
-
// to move on with the next candidate path.
|
|
87
|
-
if (candidateParts[i] !== pathParts[i]) {
|
|
96
|
+
// track if we have found a match to return the values found.
|
|
97
|
+
let found = true;
|
|
98
|
+
for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
|
|
99
|
+
if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) &&
|
|
100
|
+
((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.indexOf("}")) !== -1) {
|
|
101
|
+
const start = candidateParts[i].indexOf("}") + 1, end = (_c = candidateParts[i]) === null || _c === void 0 ? void 0 : _c.length;
|
|
102
|
+
// If the current part of the candidate is a "template" part
|
|
103
|
+
// Try to use the suffix of pattern to match the path
|
|
104
|
+
// {guid} ==> $
|
|
105
|
+
// {guid}:export ==> :export$
|
|
106
|
+
const isMatched = new RegExp(`${(_d = candidateParts[i]) === null || _d === void 0 ? void 0 : _d.slice(start, end)}`).test(pathParts[j] || "");
|
|
107
|
+
if (!isMatched) {
|
|
88
108
|
found = false;
|
|
89
109
|
break;
|
|
90
110
|
}
|
|
111
|
+
continue;
|
|
91
112
|
}
|
|
92
|
-
//
|
|
93
|
-
//
|
|
94
|
-
// the path
|
|
95
|
-
if (
|
|
96
|
-
|
|
113
|
+
// If the candidate part is not a template and
|
|
114
|
+
// the parts don't match mark the candidate as not found
|
|
115
|
+
// to move on with the next candidate path.
|
|
116
|
+
if (candidateParts[i] !== pathParts[j]) {
|
|
117
|
+
found = false;
|
|
118
|
+
break;
|
|
97
119
|
}
|
|
98
120
|
}
|
|
121
|
+
// We finished evaluating the current candidate parts
|
|
122
|
+
// Update the matched value if and only if we found the longer pattern
|
|
123
|
+
if (found && candidatePath.length > matchedLen) {
|
|
124
|
+
matchedLen = candidatePath.length;
|
|
125
|
+
matchedValue = value;
|
|
126
|
+
}
|
|
99
127
|
}
|
|
100
|
-
|
|
101
|
-
return [];
|
|
102
|
-
}
|
|
103
|
-
function hasParametrizedPath(path) {
|
|
104
|
-
return path.includes("/{");
|
|
128
|
+
return matchedValue;
|
|
105
129
|
}
|
|
106
130
|
function getPathFromMapKey(mapKey) {
|
|
107
131
|
const pathStart = mapKey.indexOf("/");
|
|
@@ -109,6 +133,7 @@ function getPathFromMapKey(mapKey) {
|
|
|
109
133
|
}
|
|
110
134
|
|
|
111
135
|
// Copyright (c) Microsoft Corporation.
|
|
136
|
+
// Licensed under the MIT License.
|
|
112
137
|
/**
|
|
113
138
|
* Helper function that builds a Poller object to help polling a long running operation.
|
|
114
139
|
* @param client - Client to use for sending the request to get additional pages.
|
|
@@ -116,36 +141,90 @@ function getPathFromMapKey(mapKey) {
|
|
|
116
141
|
* @param options - Options to set a resume state or custom polling interval.
|
|
117
142
|
* @returns - A poller object to poll for operation state updates and eventually get the final response.
|
|
118
143
|
*/
|
|
119
|
-
function getLongRunningPoller(client, initialResponse, options = {}) {
|
|
144
|
+
async function getLongRunningPoller(client, initialResponse, options = {}) {
|
|
145
|
+
var _a;
|
|
146
|
+
const abortController = new AbortController();
|
|
120
147
|
const poller = {
|
|
121
|
-
requestMethod: initialResponse.request.method,
|
|
122
|
-
requestPath: initialResponse.request.url,
|
|
123
148
|
sendInitialRequest: async () => {
|
|
124
149
|
// In the case of Rest Clients we are building the LRO poller object from a response that's the reason
|
|
125
150
|
// we are not triggering the initial request here, just extracting the information from the
|
|
126
151
|
// response we were provided.
|
|
127
152
|
return getLroResponse(initialResponse);
|
|
128
153
|
},
|
|
129
|
-
sendPollRequest: async (path) => {
|
|
154
|
+
sendPollRequest: async (path, pollOptions) => {
|
|
130
155
|
// This is the callback that is going to be called to poll the service
|
|
131
156
|
// to get the latest status. We use the client provided and the polling path
|
|
132
157
|
// which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location
|
|
133
158
|
// depending on the lro pattern that the service implements. If non is provided we default to the initial path.
|
|
134
|
-
|
|
135
|
-
.
|
|
136
|
-
|
|
159
|
+
function abortListener() {
|
|
160
|
+
abortController.abort();
|
|
161
|
+
}
|
|
162
|
+
const inputAbortSignal = pollOptions === null || pollOptions === void 0 ? void 0 : pollOptions.abortSignal;
|
|
163
|
+
const abortSignal = abortController.signal;
|
|
164
|
+
if (inputAbortSignal === null || inputAbortSignal === void 0 ? void 0 : inputAbortSignal.aborted) {
|
|
165
|
+
abortController.abort();
|
|
166
|
+
}
|
|
167
|
+
else if (!abortSignal.aborted) {
|
|
168
|
+
inputAbortSignal === null || inputAbortSignal === void 0 ? void 0 : inputAbortSignal.addEventListener("abort", abortListener, {
|
|
169
|
+
once: true,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
let response;
|
|
173
|
+
try {
|
|
174
|
+
response = await client
|
|
175
|
+
.pathUnchecked(path !== null && path !== void 0 ? path : initialResponse.request.url)
|
|
176
|
+
.get({ abortSignal });
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
inputAbortSignal === null || inputAbortSignal === void 0 ? void 0 : inputAbortSignal.removeEventListener("abort", abortListener);
|
|
180
|
+
}
|
|
137
181
|
const lroResponse = getLroResponse(response);
|
|
138
182
|
lroResponse.rawResponse.headers["x-ms-original-url"] =
|
|
139
183
|
initialResponse.request.url;
|
|
140
184
|
return lroResponse;
|
|
141
|
-
}
|
|
185
|
+
},
|
|
142
186
|
};
|
|
143
|
-
|
|
187
|
+
options.resolveOnUnsuccessful = (_a = options.resolveOnUnsuccessful) !== null && _a !== void 0 ? _a : true;
|
|
188
|
+
const httpPoller = coreLro.createHttpPoller(poller, options);
|
|
189
|
+
const simplePoller = {
|
|
190
|
+
isDone() {
|
|
191
|
+
return httpPoller.isDone;
|
|
192
|
+
},
|
|
193
|
+
isStopped() {
|
|
194
|
+
return abortController.signal.aborted;
|
|
195
|
+
},
|
|
196
|
+
getOperationState() {
|
|
197
|
+
if (!httpPoller.operationState) {
|
|
198
|
+
throw new Error("Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().");
|
|
199
|
+
}
|
|
200
|
+
return httpPoller.operationState;
|
|
201
|
+
},
|
|
202
|
+
getResult() {
|
|
203
|
+
return httpPoller.result;
|
|
204
|
+
},
|
|
205
|
+
toString() {
|
|
206
|
+
if (!httpPoller.operationState) {
|
|
207
|
+
throw new Error("Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().");
|
|
208
|
+
}
|
|
209
|
+
return JSON.stringify({
|
|
210
|
+
state: httpPoller.operationState,
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
stopPolling() {
|
|
214
|
+
abortController.abort();
|
|
215
|
+
},
|
|
216
|
+
onProgress: httpPoller.onProgress,
|
|
217
|
+
poll: httpPoller.poll,
|
|
218
|
+
pollUntilDone: httpPoller.pollUntilDone,
|
|
219
|
+
serialize: httpPoller.serialize,
|
|
220
|
+
submitted: httpPoller.submitted,
|
|
221
|
+
};
|
|
222
|
+
return simplePoller;
|
|
144
223
|
}
|
|
145
224
|
/**
|
|
146
|
-
* Converts a Rest Client response to a response that the LRO
|
|
225
|
+
* Converts a Rest Client response to a response that the LRO implementation understands
|
|
147
226
|
* @param response - a rest client http response
|
|
148
|
-
* @returns - An LRO response that the LRO
|
|
227
|
+
* @returns - An LRO response that the LRO implementation understands
|
|
149
228
|
*/
|
|
150
229
|
function getLroResponse(response) {
|
|
151
230
|
if (Number.isNaN(response.status)) {
|
|
@@ -153,15 +232,29 @@ function getLroResponse(response) {
|
|
|
153
232
|
}
|
|
154
233
|
return {
|
|
155
234
|
flatResponse: response,
|
|
156
|
-
rawResponse: Object.assign(Object.assign({}, response), { statusCode: Number.parseInt(response.status), body: response.body })
|
|
235
|
+
rawResponse: Object.assign(Object.assign({}, response), { statusCode: Number.parseInt(response.status), body: response.body }),
|
|
157
236
|
};
|
|
158
237
|
}
|
|
159
238
|
|
|
160
239
|
// Copyright (c) Microsoft Corporation.
|
|
240
|
+
// Licensed under the MIT License.
|
|
241
|
+
function buildMultiCollection(items, parameterName) {
|
|
242
|
+
return items
|
|
243
|
+
.map((item, index) => {
|
|
244
|
+
if (index === 0) {
|
|
245
|
+
return item;
|
|
246
|
+
}
|
|
247
|
+
return `${parameterName}=${item}`;
|
|
248
|
+
})
|
|
249
|
+
.join("&");
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Copyright (c) Microsoft Corporation.
|
|
253
|
+
// Licensed under the MIT License.
|
|
161
254
|
function MapsRoute(credential, clientIdOrOptions = {}, maybeOptions = {}) {
|
|
162
255
|
const options = typeof clientIdOrOptions === "string" ? maybeOptions : clientIdOrOptions;
|
|
163
256
|
/**
|
|
164
|
-
* maps service requires a header "ms-x-client-id", which is different from the standard
|
|
257
|
+
* maps service requires a header "ms-x-client-id", which is different from the standard Microsoft Entra ID.
|
|
165
258
|
* So we need to do our own implementation.
|
|
166
259
|
* This customized authentication is following by this guide: https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/RLC-customization.md#custom-authentication
|
|
167
260
|
*/
|
|
@@ -173,16 +266,27 @@ function MapsRoute(credential, clientIdOrOptions = {}, maybeOptions = {}) {
|
|
|
173
266
|
const client = createClient(undefined, options);
|
|
174
267
|
client.pipeline.addPolicy(coreRestPipeline.bearerTokenAuthenticationPolicy({
|
|
175
268
|
credential,
|
|
176
|
-
scopes:
|
|
269
|
+
scopes: "https://atlas.microsoft.com/.default",
|
|
177
270
|
}));
|
|
178
271
|
client.pipeline.addPolicy(mapsCommon.createMapsClientIdPolicy(clientId));
|
|
179
272
|
return client;
|
|
180
273
|
}
|
|
274
|
+
if (coreAuth.isSASCredential(credential)) {
|
|
275
|
+
const client = createClient(undefined, options);
|
|
276
|
+
client.pipeline.addPolicy({
|
|
277
|
+
name: "mapsSASCredentialPolicy",
|
|
278
|
+
async sendRequest(request, next) {
|
|
279
|
+
request.headers.set("Authorization", `jwt-sas ${credential.signature}`);
|
|
280
|
+
return next(request);
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
return client;
|
|
284
|
+
}
|
|
181
285
|
return createClient(credential, options);
|
|
182
286
|
}
|
|
183
287
|
|
|
184
288
|
// Copyright (c) Microsoft Corporation.
|
|
185
|
-
// Licensed under the MIT
|
|
289
|
+
// Licensed under the MIT License.
|
|
186
290
|
function toLatLonString(coordinates) {
|
|
187
291
|
return `${coordinates[0]},${coordinates[1]}`;
|
|
188
292
|
}
|
|
@@ -225,9 +329,11 @@ function createRouteDirectionsBatchRequest(queryParamProperties) {
|
|
|
225
329
|
}
|
|
226
330
|
|
|
227
331
|
// Copyright (c) Microsoft Corporation.
|
|
332
|
+
// Licensed under the MIT License.
|
|
228
333
|
|
|
334
|
+
exports.buildMultiCollection = buildMultiCollection;
|
|
229
335
|
exports.createRouteDirectionsBatchRequest = createRouteDirectionsBatchRequest;
|
|
230
|
-
exports
|
|
336
|
+
exports.default = MapsRoute;
|
|
231
337
|
exports.getLongRunningPoller = getLongRunningPoller;
|
|
232
338
|
exports.isUnexpected = isUnexpected;
|
|
233
339
|
exports.toColonDelimitedLatLonString = toColonDelimitedLatLonString;
|