@azure-rest/maps-search 1.0.0-beta.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/LICENSE +21 -0
- package/README.md +216 -0
- package/dist/index.js +218 -0
- package/dist/index.js.map +1 -0
- package/dist-esm/src/MapsSearch.js +29 -0
- package/dist-esm/src/MapsSearch.js.map +1 -0
- package/dist-esm/src/createBatchItems.js +16 -0
- package/dist-esm/src/createBatchItems.js.map +1 -0
- package/dist-esm/src/generated/clientDefinitions.js +4 -0
- package/dist-esm/src/generated/clientDefinitions.js.map +1 -0
- package/dist-esm/src/generated/index.js +13 -0
- package/dist-esm/src/generated/index.js.map +1 -0
- package/dist-esm/src/generated/isUnexpected.js +89 -0
- package/dist-esm/src/generated/isUnexpected.js.map +1 -0
- package/dist-esm/src/generated/mapsSearchClient.js +25 -0
- package/dist-esm/src/generated/mapsSearchClient.js.map +1 -0
- package/dist-esm/src/generated/models.js +4 -0
- package/dist-esm/src/generated/models.js.map +1 -0
- package/dist-esm/src/generated/outputModels.js +4 -0
- package/dist-esm/src/generated/outputModels.js.map +1 -0
- package/dist-esm/src/generated/parameters.js +4 -0
- package/dist-esm/src/generated/parameters.js.map +1 -0
- package/dist-esm/src/generated/pollingHelper.js +51 -0
- package/dist-esm/src/generated/pollingHelper.js.map +1 -0
- package/dist-esm/src/generated/responses.js +4 -0
- package/dist-esm/src/generated/responses.js.map +1 -0
- package/dist-esm/src/index.js +7 -0
- package/dist-esm/src/index.js.map +1 -0
- package/package.json +132 -0
- package/review/maps-search.api.md +1522 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Microsoft
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# Azure Maps Search REST client library for JavaScript
|
|
2
|
+
|
|
3
|
+
Azure Maps Search Client
|
|
4
|
+
|
|
5
|
+
\*\*If you are not familiar with our REST client, please spend 5 minutes to take a look at our [REST client docs](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md) to use this library, the REST client provides a light-weighted & developer friendly way to call azure rest api
|
|
6
|
+
|
|
7
|
+
Key links:
|
|
8
|
+
|
|
9
|
+
- [Source code]<!-- (https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/maps/maps-search-rest) -->
|
|
10
|
+
- [Package (NPM)]<!-- (https://www.npmjs.com/package/@azure-rest/maps-search) -->
|
|
11
|
+
- [API reference documentation]<!-- (https://docs.microsoft.com/javascript/api/@azure-rest/maps-search?view=azure-node-preview) -->
|
|
12
|
+
- [Samples]<!-- (https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/maps/maps-search-rest/samples) -->
|
|
13
|
+
- [Product Information](https://docs.microsoft.com/rest/api/maps/search)
|
|
14
|
+
|
|
15
|
+
## Getting started
|
|
16
|
+
|
|
17
|
+
### Currently supported environments
|
|
18
|
+
|
|
19
|
+
- [LTS versions of Node.js](https://nodejs.org/about/releases/)
|
|
20
|
+
- Latest versions of Safari, Chrome, Edge and Firefox.
|
|
21
|
+
|
|
22
|
+
### Prerequisites
|
|
23
|
+
|
|
24
|
+
- You must have an [Azure subscription](https://azure.microsoft.com/free/) to use this package.
|
|
25
|
+
- An [Azure Maps account](https://docs.microsoft.com/azure/azure-maps/how-to-manage-account-keys). You can create the resource via the [Azure Portal](https://portal.azure.com), the [Azure PowerShell](https://docs.microsoft.com/powershell/module/az.maps/new-azmapsaccount), or the [Azure CLI](https://docs.microsoft.com/cli/azure).
|
|
26
|
+
|
|
27
|
+
If you use Azure CLI, replace `<resource-group-name>` and `<map-account-name>` of your choice, and select a proper [pricing tier](https://docs.microsoft.com/azure/azure-maps/choose-pricing-tier) based on your needs via the `<sku-name>` parameter. Please refer to [this page](https://docs.microsoft.com/cli/azure/maps/account?view=azure-cli-latest#az_maps_account_create) for more details.
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
az maps account create --resource-group <resource-group-name> --name <map-account-name> --sku <sku-name>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Install the `@azure-rest/maps-search` package
|
|
34
|
+
|
|
35
|
+
Install the Azure Maps Search REST client library for JavaScript with `npm`:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm install @azure-rest/maps-search
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Create and authenticate a `MapsSearchClient`
|
|
42
|
+
|
|
43
|
+
To create a client object to access the Azure Maps Search APIs, you will need a `credential` object. The Azure Maps Search client can use an Azure Active Directory credential or an Azure Key credential to authenticate.
|
|
44
|
+
|
|
45
|
+
#### Using an Azure Active Directory Credential
|
|
46
|
+
|
|
47
|
+
You can authenticate with Azure Active Directory using the [Azure Identity library](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity). To use the [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential) provider shown below, or other credential providers provided with the Azure SDK, please install the `@azure/identity` package:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npm install @azure/identity
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
You will also need to register a new AAD 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.
|
|
54
|
+
|
|
55
|
+
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`.
|
|
56
|
+
|
|
57
|
+
You will also need to specify the Azure Maps resource you intend to use by specifying the `clientId` in the client options.
|
|
58
|
+
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.
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
const MapsSearch = require("@azure-rest/maps-search").default;
|
|
62
|
+
const { DefaultAzureCredential } = require("@azure/identity");
|
|
63
|
+
|
|
64
|
+
const credential = new DefaultAzureCredential();
|
|
65
|
+
const client = MapsSearch(credential, "<maps-account-client-id>");
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### Using a Subscription Key Credential
|
|
69
|
+
|
|
70
|
+
You can authenticate with your Azure Maps Subscription Key.
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
const MapsSearch = require("@azure-rest/maps-search").default;
|
|
74
|
+
const { AzureKeyCredential } = require("@azure/core-auth");
|
|
75
|
+
|
|
76
|
+
const credential = new AzureKeyCredential("<subscription-key>");
|
|
77
|
+
const client = MapsSearch(credential);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Key concepts
|
|
81
|
+
|
|
82
|
+
### MapsSearchClient
|
|
83
|
+
|
|
84
|
+
`MapsSearchClient` is the primary interface for developers using the Azure Maps Search client library. Explore the methods on this client object to understand the different features of the Azure Maps Search service that you can access.
|
|
85
|
+
|
|
86
|
+
## Examples
|
|
87
|
+
|
|
88
|
+
The following sections provide several code snippets covering some of the most common Azure Maps Search tasks, including:
|
|
89
|
+
|
|
90
|
+
- [Request latitude and longitude coordinates for an address](#request-latitude-and-longitude-coordinates-for-an-address)
|
|
91
|
+
- [Search for an address or Point of Interest](#search-for-an-address-or-point-of-interest)
|
|
92
|
+
- [Make a Reverse Address Search to translate coordinate location to street address](#make-a-reverse-address-search-to-translate-coordinate-location-to-street-address)
|
|
93
|
+
- [Translate coordinate location into a human understandable cross street](#translate-coordinate-location-into-a-human-understandable-cross-street)
|
|
94
|
+
|
|
95
|
+
### Request latitude and longitude coordinates for an address
|
|
96
|
+
|
|
97
|
+
You can use an authenticated client to convert an address into latitude and longitude coordinates. This process is also called geocoding. In addition to returning the coordinates, the response will also return detailed address properties such as street, postal code, municipality, and country/region information.
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
const MapsSearch = require("@azure-rest/maps-search").default;
|
|
101
|
+
const { AzureKeyCredential } = require("@azure/core-auth");
|
|
102
|
+
const { isUnexpected } = require("@azure-rest/maps-search");
|
|
103
|
+
|
|
104
|
+
/** Initialize the MapsSearchClient */
|
|
105
|
+
const client = MapsSearch(new AzureKeyCredential("<subscription-key>"));
|
|
106
|
+
/** Make a request to the geocoding API */
|
|
107
|
+
const response = await client
|
|
108
|
+
.path("/search/address/{format}", "json")
|
|
109
|
+
.get({ queryParameters: { query: "400 Broad, Seattle" } });
|
|
110
|
+
/** Handle error response */
|
|
111
|
+
if (isUnexpected(response)) {
|
|
112
|
+
throw response.body.error;
|
|
113
|
+
}
|
|
114
|
+
/** Log the response body. */
|
|
115
|
+
console.log(`The followings are the possible coordinates of the address:`);
|
|
116
|
+
response.body.results.forEach((result) => {
|
|
117
|
+
const { lat, lon } = result.position;
|
|
118
|
+
console.log(`Latitude: ${lat}, Longitude: ${lon}`);
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Search for an address or Point of Interest
|
|
123
|
+
|
|
124
|
+
You can use Fuzzy Search to search an address or a point of interest (POI). The following example demonstrates how to search for `pizza` over the scope of a specific country (`France`, in this example).
|
|
125
|
+
|
|
126
|
+
```javascript
|
|
127
|
+
const MapsSearch = require("@azure-rest/maps-search").default;
|
|
128
|
+
const { AzureKeyCredential } = require("@azure/core-auth");
|
|
129
|
+
const { isUnexpected } = require("@azure-rest/maps-search");
|
|
130
|
+
|
|
131
|
+
/** Initialize the MapsSearchClient */
|
|
132
|
+
const client = MapsSearch(new AzureKeyCredential("<subscription-key>"));
|
|
133
|
+
/** Make a request */
|
|
134
|
+
const response = await client
|
|
135
|
+
.path("/search/fuzzy/{format}", "json")
|
|
136
|
+
.get({ queryParameters: { query: "pizza", countrySet: ["fr"] } });
|
|
137
|
+
/** Handle the error response */
|
|
138
|
+
if (isUnexpected(response)) {
|
|
139
|
+
throw response.body.error;
|
|
140
|
+
}
|
|
141
|
+
/** Log the response body */
|
|
142
|
+
response.body.results.forEach((result) => {
|
|
143
|
+
console.log(`Address: ${result.address.freeformAddress}`);
|
|
144
|
+
console.log(`Coordinate: (${result.position.lat}, ${result.position.lon})\n`);
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Make a Reverse Address Search to translate coordinate location to street address
|
|
149
|
+
|
|
150
|
+
You can translate coordinates into human readable street addresses. This process is also called reverse geocoding.
|
|
151
|
+
This is often used for applications that consume GPS feeds and want to discover addresses at specific coordinate points.
|
|
152
|
+
|
|
153
|
+
```javascript
|
|
154
|
+
const MapsSearch = require("@azure-rest/maps-search").default;
|
|
155
|
+
const { AzureKeyCredential } = require("@azure/core-auth");
|
|
156
|
+
const { isUnexpected } = require("@azure-rest/maps-search");
|
|
157
|
+
|
|
158
|
+
/** Initialize the MapsSearchClient */
|
|
159
|
+
const client = MapsSearch(new AzureKeyCredential("<subscription-key>"));
|
|
160
|
+
/** Make the request. */
|
|
161
|
+
const response = await client.path("/search/address/reverse/{format}", "json").get({
|
|
162
|
+
queryParameters: { query: [37.337, -121.89] }, // [latitude, longitude],
|
|
163
|
+
});
|
|
164
|
+
/** Handle error response. */
|
|
165
|
+
if (isUnexpected(response)) {
|
|
166
|
+
throw response.body.error;
|
|
167
|
+
}
|
|
168
|
+
/** Log the response body. */
|
|
169
|
+
response.body.addresses.forEach((address) => {
|
|
170
|
+
console.log(address.address.freeformAddress);
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Translate coordinate location into a human understandable cross street
|
|
175
|
+
|
|
176
|
+
Translate coordinate location into a human understandable cross street by using Search Address Reverse Cross Street API. Most often, this is needed in tracking applications that receive a GPS feed from a device or asset, and wish to know where the coordinate is located.
|
|
177
|
+
|
|
178
|
+
```javascript
|
|
179
|
+
const MapsSearch = require("@azure-rest/maps-search").default;
|
|
180
|
+
const { AzureKeyCredential } = require("@azure/core-auth");
|
|
181
|
+
const { isUnexpected } = require("@azure-rest/maps-search");
|
|
182
|
+
|
|
183
|
+
/** Initialize the MapsSearchClient */
|
|
184
|
+
const client = MapsSearch(new AzureKeyCredential("<subscription-key>"));
|
|
185
|
+
/** Make the request. */
|
|
186
|
+
const response = await client.path("/search/address/reverse/crossStreet/{format}", "json").get({
|
|
187
|
+
queryParameters: { query: [37.337, -121.89] },
|
|
188
|
+
});
|
|
189
|
+
/** Handle error response */
|
|
190
|
+
if (isUnexpected(response)) {
|
|
191
|
+
throw response.body.error;
|
|
192
|
+
}
|
|
193
|
+
/** Log the response body */
|
|
194
|
+
response.body.addresses.forEach(({ address }) => {
|
|
195
|
+
if (!address) {
|
|
196
|
+
throw Error("Unexpected error: address is undefined");
|
|
197
|
+
}
|
|
198
|
+
console.log(address.streetName);
|
|
199
|
+
});
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Troubleshooting
|
|
203
|
+
|
|
204
|
+
### Logging
|
|
205
|
+
|
|
206
|
+
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
|
|
207
|
+
|
|
208
|
+
```javascript
|
|
209
|
+
const { setLogLevel } = require("@azure/logger");
|
|
210
|
+
|
|
211
|
+
setLogLevel("info");
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).
|
|
215
|
+
|
|
216
|
+

|
package/dist/index.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var coreAuth = require('@azure/core-auth');
|
|
6
|
+
var mapsCommon = require('@azure/maps-common');
|
|
7
|
+
var coreClient = require('@azure-rest/core-client');
|
|
8
|
+
var coreRestPipeline = require('@azure/core-rest-pipeline');
|
|
9
|
+
var coreLro = require('@azure/core-lro');
|
|
10
|
+
|
|
11
|
+
// Copyright (c) Microsoft Corporation.
|
|
12
|
+
/**
|
|
13
|
+
* Initialize a new instance of the class MapsSearchClient class.
|
|
14
|
+
* @param credentials type: KeyCredential
|
|
15
|
+
*/
|
|
16
|
+
function createClient(credentials, options = {}) {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
const baseUrl = (_a = options.baseUrl) !== null && _a !== void 0 ? _a : `https://atlas.microsoft.com`;
|
|
19
|
+
options.apiVersion = (_b = options.apiVersion) !== null && _b !== void 0 ? _b : "1.0";
|
|
20
|
+
options = Object.assign(Object.assign({}, options), { credentials: {
|
|
21
|
+
apiKeyHeaderName: "subscription-key"
|
|
22
|
+
} });
|
|
23
|
+
const userAgentInfo = `azsdk-js-maps-search-rest/1.0.0-beta.1`;
|
|
24
|
+
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
25
|
+
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
|
|
26
|
+
: `${userAgentInfo}`;
|
|
27
|
+
options = Object.assign(Object.assign({}, options), { userAgentOptions: {
|
|
28
|
+
userAgentPrefix
|
|
29
|
+
} });
|
|
30
|
+
const client = coreClient.getClient(baseUrl, credentials, options);
|
|
31
|
+
return client;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Copyright (c) Microsoft Corporation.
|
|
35
|
+
// Licensed under the MIT license.
|
|
36
|
+
const responseMap = {
|
|
37
|
+
"GET /search/polygon/{format}": ["200"],
|
|
38
|
+
"GET /search/fuzzy/{format}": ["200"],
|
|
39
|
+
"GET /search/poi/{format}": ["200"],
|
|
40
|
+
"GET /search/nearby/{format}": ["200"],
|
|
41
|
+
"GET /search/poi/category/{format}": ["200"],
|
|
42
|
+
"GET /search/poi/category/tree/{format}": ["200"],
|
|
43
|
+
"GET /search/address/{format}": ["200"],
|
|
44
|
+
"GET /search/address/reverse/{format}": ["200"],
|
|
45
|
+
"GET /search/address/reverse/crossStreet/{format}": ["200"],
|
|
46
|
+
"GET /search/address/structured/{format}": ["200"],
|
|
47
|
+
"POST /search/geometry/{format}": ["200"],
|
|
48
|
+
"POST /search/alongRoute/{format}": ["200"],
|
|
49
|
+
"POST /search/fuzzy/batch/sync/{format}": ["200"],
|
|
50
|
+
"POST /search/fuzzy/batch/{format}": ["200", "202"],
|
|
51
|
+
"GET /search/fuzzy/batch/{format}": ["200", "202"],
|
|
52
|
+
"POST /search/address/batch/sync/{format}": ["200"],
|
|
53
|
+
"POST /search/address/batch/{format}": ["200", "202"],
|
|
54
|
+
"GET /search/address/batch/{format}": ["200", "202"],
|
|
55
|
+
"POST /search/address/reverse/batch/sync/{format}": ["200"],
|
|
56
|
+
"POST /search/address/reverse/batch/{format}": ["200", "202"],
|
|
57
|
+
"GET /search/address/reverse/batch/{format}": ["200", "202"]
|
|
58
|
+
};
|
|
59
|
+
function isUnexpected(response) {
|
|
60
|
+
const lroOriginal = response.headers["x-ms-original-url"];
|
|
61
|
+
const url = new URL(lroOriginal !== null && lroOriginal !== void 0 ? lroOriginal : response.request.url);
|
|
62
|
+
const method = response.request.method;
|
|
63
|
+
let pathDetails = responseMap[`${method} ${url.pathname}`];
|
|
64
|
+
if (!pathDetails) {
|
|
65
|
+
pathDetails = geParametrizedPathSuccess(method, url.pathname);
|
|
66
|
+
}
|
|
67
|
+
return !pathDetails.includes(response.status);
|
|
68
|
+
}
|
|
69
|
+
function geParametrizedPathSuccess(method, path) {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
const pathParts = path.split("/");
|
|
72
|
+
// Iterate the responseMap to find a match
|
|
73
|
+
for (const [key, value] of Object.entries(responseMap)) {
|
|
74
|
+
// Extracting the path from the map key which is in format
|
|
75
|
+
// GET /path/foo
|
|
76
|
+
if (!key.startsWith(method)) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const candidatePath = getPathFromMapKey(key);
|
|
80
|
+
// Get each part of the url path
|
|
81
|
+
const candidateParts = candidatePath.split("/");
|
|
82
|
+
// If the candidate and actual paths don't match in size
|
|
83
|
+
// we move on to the next candidate path
|
|
84
|
+
if (candidateParts.length === pathParts.length &&
|
|
85
|
+
hasParametrizedPath(key)) {
|
|
86
|
+
// track if we have found a match to return the values found.
|
|
87
|
+
let found = true;
|
|
88
|
+
for (let i = 0; i < candidateParts.length; i++) {
|
|
89
|
+
if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) &&
|
|
90
|
+
((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.endsWith("}"))) {
|
|
91
|
+
// If the current part of the candidate is a "template" part
|
|
92
|
+
// it is a match with the actual path part on hand
|
|
93
|
+
// skip as the parameterized part can match anything
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
// If the candidate part is not a template and
|
|
97
|
+
// the parts don't match mark the candidate as not found
|
|
98
|
+
// to move on with the next candidate path.
|
|
99
|
+
if (candidateParts[i] !== pathParts[i]) {
|
|
100
|
+
found = false;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// We finished evaluating the current candidate parts
|
|
105
|
+
// if all parts matched we return the success values form
|
|
106
|
+
// the path mapping.
|
|
107
|
+
if (found) {
|
|
108
|
+
return value;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// No match was found, return an empty array.
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
function hasParametrizedPath(path) {
|
|
116
|
+
return path.includes("/{");
|
|
117
|
+
}
|
|
118
|
+
function getPathFromMapKey(mapKey) {
|
|
119
|
+
const pathStart = mapKey.indexOf("/");
|
|
120
|
+
return mapKey.slice(pathStart);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Copyright (c) Microsoft Corporation.
|
|
124
|
+
/**
|
|
125
|
+
* Helper function that builds a Poller object to help polling a long running operation.
|
|
126
|
+
* @param client - Client to use for sending the request to get additional pages.
|
|
127
|
+
* @param initialResponse - The initial response.
|
|
128
|
+
* @param options - Options to set a resume state or custom polling interval.
|
|
129
|
+
* @returns - A poller object to poll for operation state updates and eventually get the final response.
|
|
130
|
+
*/
|
|
131
|
+
function getLongRunningPoller(client, initialResponse, options = {}) {
|
|
132
|
+
const poller = {
|
|
133
|
+
requestMethod: initialResponse.request.method,
|
|
134
|
+
requestPath: initialResponse.request.url,
|
|
135
|
+
sendInitialRequest: async () => {
|
|
136
|
+
// In the case of Rest Clients we are building the LRO poller object from a response that's the reason
|
|
137
|
+
// we are not triggering the initial request here, just extracting the information from the
|
|
138
|
+
// response we were provided.
|
|
139
|
+
return getLroResponse(initialResponse);
|
|
140
|
+
},
|
|
141
|
+
sendPollRequest: async (path) => {
|
|
142
|
+
// This is the callback that is going to be called to poll the service
|
|
143
|
+
// to get the latest status. We use the client provided and the polling path
|
|
144
|
+
// which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location
|
|
145
|
+
// depending on the lro pattern that the service implements. If non is provided we default to the initial path.
|
|
146
|
+
const response = await client
|
|
147
|
+
.pathUnchecked(path !== null && path !== void 0 ? path : initialResponse.request.url)
|
|
148
|
+
.get();
|
|
149
|
+
const lroResponse = getLroResponse(response);
|
|
150
|
+
lroResponse.rawResponse.headers["x-ms-original-url"] =
|
|
151
|
+
initialResponse.request.url;
|
|
152
|
+
return lroResponse;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
return new coreLro.LroEngine(poller, options);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Converts a Rest Client response to a response that the LRO engine knows about
|
|
159
|
+
* @param response - a rest client http response
|
|
160
|
+
* @returns - An LRO response that the LRO engine can work with
|
|
161
|
+
*/
|
|
162
|
+
function getLroResponse(response) {
|
|
163
|
+
if (Number.isNaN(response.status)) {
|
|
164
|
+
throw new TypeError(`Status code of the response is not a number. Value: ${response.status}`);
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
flatResponse: response,
|
|
168
|
+
rawResponse: Object.assign(Object.assign({}, response), { statusCode: Number.parseInt(response.status), body: response.body })
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Copyright (c) Microsoft Corporation.
|
|
173
|
+
function MapsSearch(credential, clientIdOrOptions = {}, maybeOptions = {}) {
|
|
174
|
+
const options = typeof clientIdOrOptions === "string" ? maybeOptions : clientIdOrOptions;
|
|
175
|
+
/**
|
|
176
|
+
* maps service requires a header "ms-x-client-id", which is different from the standard AAD.
|
|
177
|
+
* So we need to do our own implementation.
|
|
178
|
+
* This customized authentication is following by this guide: https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/RLC-customization.md#custom-authentication
|
|
179
|
+
*/
|
|
180
|
+
if (coreAuth.isTokenCredential(credential)) {
|
|
181
|
+
const clientId = typeof clientIdOrOptions === "string" ? clientIdOrOptions : "";
|
|
182
|
+
if (!clientId) {
|
|
183
|
+
throw Error("Client id is needed for TokenCredential");
|
|
184
|
+
}
|
|
185
|
+
const client = createClient(undefined, options);
|
|
186
|
+
client.pipeline.addPolicy(coreRestPipeline.bearerTokenAuthenticationPolicy({
|
|
187
|
+
credential,
|
|
188
|
+
scopes: `${options.baseUrl || "https://atlas.microsoft.com"}/.default`,
|
|
189
|
+
}));
|
|
190
|
+
client.pipeline.addPolicy(mapsCommon.createMapsClientIdPolicy(clientId));
|
|
191
|
+
return client;
|
|
192
|
+
}
|
|
193
|
+
return createClient(credential, options);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Copyright (c) Microsoft Corporation.
|
|
197
|
+
// Licensed under the MIT license.
|
|
198
|
+
/**
|
|
199
|
+
* Create batch items for the batch request.
|
|
200
|
+
*
|
|
201
|
+
* @param requests - The list of queries to process.
|
|
202
|
+
* @returns - The BatchRequestItem object.
|
|
203
|
+
*/
|
|
204
|
+
function createBatchItems(requests) {
|
|
205
|
+
return requests.map((r) => ({
|
|
206
|
+
query: Object.entries(r)
|
|
207
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
208
|
+
.join("&"),
|
|
209
|
+
}));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Copyright (c) Microsoft Corporation.
|
|
213
|
+
|
|
214
|
+
exports.createBatchItems = createBatchItems;
|
|
215
|
+
exports["default"] = MapsSearch;
|
|
216
|
+
exports.getLongRunningPoller = getLongRunningPoller;
|
|
217
|
+
exports.isUnexpected = isUnexpected;
|
|
218
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/generated/mapsSearchClient.ts","../src/generated/isUnexpected.ts","../src/generated/pollingHelper.ts","../src/MapsSearch.ts","../src/createBatchItems.ts","../src/index.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { getClient, ClientOptions } from \"@azure-rest/core-client\";\nimport { KeyCredential } from \"@azure/core-auth\";\nimport { MapsSearchClient } from \"./clientDefinitions\";\n\n/**\n * Initialize a new instance of the class MapsSearchClient class.\n * @param credentials type: KeyCredential\n */\nexport default function createClient(\n credentials: KeyCredential,\n options: ClientOptions = {}\n): MapsSearchClient {\n const baseUrl = options.baseUrl ?? `https://atlas.microsoft.com`;\n options.apiVersion = options.apiVersion ?? \"1.0\";\n options = {\n ...options,\n credentials: {\n apiKeyHeaderName: \"subscription-key\"\n }\n };\n\n const userAgentInfo = `azsdk-js-maps-search-rest/1.0.0-beta.1`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`\n : `${userAgentInfo}`;\n options = {\n ...options,\n userAgentOptions: {\n userAgentPrefix\n }\n };\n\n const client = getClient(baseUrl, credentials, options) as MapsSearchClient;\n\n return client;\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n SearchListPolygons200Response,\n SearchListPolygonsDefaultResponse,\n SearchFuzzySearch200Response,\n SearchFuzzySearchDefaultResponse,\n SearchSearchPointOfInterest200Response,\n SearchSearchPointOfInterestDefaultResponse,\n SearchSearchNearbyPointOfInterest200Response,\n SearchSearchNearbyPointOfInterestDefaultResponse,\n SearchSearchPointOfInterestCategory200Response,\n SearchSearchPointOfInterestCategoryDefaultResponse,\n SearchGetPointOfInterestCategoryTree200Response,\n SearchGetPointOfInterestCategoryTreeDefaultResponse,\n SearchSearchAddress200Response,\n SearchSearchAddressDefaultResponse,\n SearchReverseSearchAddress200Response,\n SearchReverseSearchAddressDefaultResponse,\n SearchReverseSearchCrossStreetAddress200Response,\n SearchReverseSearchCrossStreetAddressDefaultResponse,\n SearchSearchStructuredAddress200Response,\n SearchSearchStructuredAddressDefaultResponse,\n SearchSearchInsideGeometry200Response,\n SearchSearchInsideGeometryDefaultResponse,\n SearchSearchAlongRoute200Response,\n SearchSearchAlongRouteDefaultResponse,\n SearchFuzzySearchBatchSync200Response,\n SearchFuzzySearchBatchSync408Response,\n SearchFuzzySearchBatchSyncDefaultResponse,\n SearchSearchAddressBatchSync200Response,\n SearchSearchAddressBatchSync408Response,\n SearchSearchAddressBatchSyncDefaultResponse,\n SearchReverseSearchAddressBatchSync200Response,\n SearchReverseSearchAddressBatchSync408Response,\n SearchReverseSearchAddressBatchSyncDefaultResponse\n} from \"./responses\";\n\nconst responseMap: Record<string, string[]> = {\n \"GET /search/polygon/{format}\": [\"200\"],\n \"GET /search/fuzzy/{format}\": [\"200\"],\n \"GET /search/poi/{format}\": [\"200\"],\n \"GET /search/nearby/{format}\": [\"200\"],\n \"GET /search/poi/category/{format}\": [\"200\"],\n \"GET /search/poi/category/tree/{format}\": [\"200\"],\n \"GET /search/address/{format}\": [\"200\"],\n \"GET /search/address/reverse/{format}\": [\"200\"],\n \"GET /search/address/reverse/crossStreet/{format}\": [\"200\"],\n \"GET /search/address/structured/{format}\": [\"200\"],\n \"POST /search/geometry/{format}\": [\"200\"],\n \"POST /search/alongRoute/{format}\": [\"200\"],\n \"POST /search/fuzzy/batch/sync/{format}\": [\"200\"],\n \"POST /search/fuzzy/batch/{format}\": [\"200\", \"202\"],\n \"GET /search/fuzzy/batch/{format}\": [\"200\", \"202\"],\n \"POST /search/address/batch/sync/{format}\": [\"200\"],\n \"POST /search/address/batch/{format}\": [\"200\", \"202\"],\n \"GET /search/address/batch/{format}\": [\"200\", \"202\"],\n \"POST /search/address/reverse/batch/sync/{format}\": [\"200\"],\n \"POST /search/address/reverse/batch/{format}\": [\"200\", \"202\"],\n \"GET /search/address/reverse/batch/{format}\": [\"200\", \"202\"]\n};\n\nexport function isUnexpected(\n response: SearchListPolygons200Response | SearchListPolygonsDefaultResponse\n): response is SearchListPolygonsDefaultResponse;\nexport function isUnexpected(\n response: SearchFuzzySearch200Response | SearchFuzzySearchDefaultResponse\n): response is SearchFuzzySearchDefaultResponse;\nexport function isUnexpected(\n response:\n | SearchSearchPointOfInterest200Response\n | SearchSearchPointOfInterestDefaultResponse\n): response is SearchSearchPointOfInterestDefaultResponse;\nexport function isUnexpected(\n response:\n | SearchSearchNearbyPointOfInterest200Response\n | SearchSearchNearbyPointOfInterestDefaultResponse\n): response is SearchSearchNearbyPointOfInterestDefaultResponse;\nexport function isUnexpected(\n response:\n | SearchSearchPointOfInterestCategory200Response\n | SearchSearchPointOfInterestCategoryDefaultResponse\n): response is SearchSearchPointOfInterestCategoryDefaultResponse;\nexport function isUnexpected(\n response:\n | SearchGetPointOfInterestCategoryTree200Response\n | SearchGetPointOfInterestCategoryTreeDefaultResponse\n): response is SearchGetPointOfInterestCategoryTreeDefaultResponse;\nexport function isUnexpected(\n response: SearchSearchAddress200Response | SearchSearchAddressDefaultResponse\n): response is SearchSearchAddressDefaultResponse;\nexport function isUnexpected(\n response:\n | SearchReverseSearchAddress200Response\n | SearchReverseSearchAddressDefaultResponse\n): response is SearchReverseSearchAddressDefaultResponse;\nexport function isUnexpected(\n response:\n | SearchReverseSearchCrossStreetAddress200Response\n | SearchReverseSearchCrossStreetAddressDefaultResponse\n): response is SearchReverseSearchCrossStreetAddressDefaultResponse;\nexport function isUnexpected(\n response:\n | SearchSearchStructuredAddress200Response\n | SearchSearchStructuredAddressDefaultResponse\n): response is SearchSearchStructuredAddressDefaultResponse;\nexport function isUnexpected(\n response:\n | SearchSearchInsideGeometry200Response\n | SearchSearchInsideGeometryDefaultResponse\n): response is SearchSearchInsideGeometryDefaultResponse;\nexport function isUnexpected(\n response:\n | SearchSearchAlongRoute200Response\n | SearchSearchAlongRouteDefaultResponse\n): response is SearchSearchAlongRouteDefaultResponse;\nexport function isUnexpected(\n response:\n | SearchFuzzySearchBatchSync200Response\n | SearchFuzzySearchBatchSync408Response\n | SearchFuzzySearchBatchSyncDefaultResponse\n): response is SearchFuzzySearchBatchSync408Response;\nexport function isUnexpected(\n response:\n | SearchSearchAddressBatchSync200Response\n | SearchSearchAddressBatchSync408Response\n | SearchSearchAddressBatchSyncDefaultResponse\n): response is SearchSearchAddressBatchSync408Response;\nexport function isUnexpected(\n response:\n | SearchReverseSearchAddressBatchSync200Response\n | SearchReverseSearchAddressBatchSync408Response\n | SearchReverseSearchAddressBatchSyncDefaultResponse\n): response is SearchReverseSearchAddressBatchSync408Response;\nexport function isUnexpected(\n response:\n | SearchListPolygons200Response\n | SearchListPolygonsDefaultResponse\n | SearchFuzzySearch200Response\n | SearchFuzzySearchDefaultResponse\n | SearchSearchPointOfInterest200Response\n | SearchSearchPointOfInterestDefaultResponse\n | SearchSearchNearbyPointOfInterest200Response\n | SearchSearchNearbyPointOfInterestDefaultResponse\n | SearchSearchPointOfInterestCategory200Response\n | SearchSearchPointOfInterestCategoryDefaultResponse\n | SearchGetPointOfInterestCategoryTree200Response\n | SearchGetPointOfInterestCategoryTreeDefaultResponse\n | SearchSearchAddress200Response\n | SearchSearchAddressDefaultResponse\n | SearchReverseSearchAddress200Response\n | SearchReverseSearchAddressDefaultResponse\n | SearchReverseSearchCrossStreetAddress200Response\n | SearchReverseSearchCrossStreetAddressDefaultResponse\n | SearchSearchStructuredAddress200Response\n | SearchSearchStructuredAddressDefaultResponse\n | SearchSearchInsideGeometry200Response\n | SearchSearchInsideGeometryDefaultResponse\n | SearchSearchAlongRoute200Response\n | SearchSearchAlongRouteDefaultResponse\n | SearchFuzzySearchBatchSync200Response\n | SearchFuzzySearchBatchSync408Response\n | SearchFuzzySearchBatchSyncDefaultResponse\n | SearchSearchAddressBatchSync200Response\n | SearchSearchAddressBatchSync408Response\n | SearchSearchAddressBatchSyncDefaultResponse\n | SearchReverseSearchAddressBatchSync200Response\n | SearchReverseSearchAddressBatchSync408Response\n | SearchReverseSearchAddressBatchSyncDefaultResponse\n): response is\n | SearchListPolygonsDefaultResponse\n | SearchFuzzySearchDefaultResponse\n | SearchSearchPointOfInterestDefaultResponse\n | SearchSearchNearbyPointOfInterestDefaultResponse\n | SearchSearchPointOfInterestCategoryDefaultResponse\n | SearchGetPointOfInterestCategoryTreeDefaultResponse\n | SearchSearchAddressDefaultResponse\n | SearchReverseSearchAddressDefaultResponse\n | SearchReverseSearchCrossStreetAddressDefaultResponse\n | SearchSearchStructuredAddressDefaultResponse\n | SearchSearchInsideGeometryDefaultResponse\n | SearchSearchAlongRouteDefaultResponse\n | SearchFuzzySearchBatchSync408Response\n | SearchFuzzySearchBatchSyncDefaultResponse\n | SearchSearchAddressBatchSync408Response\n | SearchSearchAddressBatchSyncDefaultResponse\n | SearchReverseSearchAddressBatchSync408Response\n | SearchReverseSearchAddressBatchSyncDefaultResponse {\n const lroOriginal = response.headers[\"x-ms-original-url\"];\n const url = new URL(lroOriginal ?? response.request.url);\n const method = response.request.method;\n let pathDetails = responseMap[`${method} ${url.pathname}`];\n if (!pathDetails) {\n pathDetails = geParametrizedPathSuccess(method, url.pathname);\n }\n return !pathDetails.includes(response.status);\n}\n\nfunction geParametrizedPathSuccess(method: string, path: string): string[] {\n const pathParts = path.split(\"/\");\n\n // Iterate the responseMap to find a match\n for (const [key, value] of Object.entries(responseMap)) {\n // Extracting the path from the map key which is in format\n // GET /path/foo\n if (!key.startsWith(method)) {\n continue;\n }\n const candidatePath = getPathFromMapKey(key);\n // Get each part of the url path\n const candidateParts = candidatePath.split(\"/\");\n\n // If the candidate and actual paths don't match in size\n // we move on to the next candidate path\n if (\n candidateParts.length === pathParts.length &&\n hasParametrizedPath(key)\n ) {\n // track if we have found a match to return the values found.\n let found = true;\n for (let i = 0; i < candidateParts.length; i++) {\n if (\n candidateParts[i]?.startsWith(\"{\") &&\n candidateParts[i]?.endsWith(\"}\")\n ) {\n // If the current part of the candidate is a \"template\" part\n // it is a match with the actual path part on hand\n // skip as the parameterized part can match anything\n continue;\n }\n\n // If the candidate part is not a template and\n // the parts don't match mark the candidate as not found\n // to move on with the next candidate path.\n if (candidateParts[i] !== pathParts[i]) {\n found = false;\n break;\n }\n }\n\n // We finished evaluating the current candidate parts\n // if all parts matched we return the success values form\n // the path mapping.\n if (found) {\n return value;\n }\n }\n }\n\n // No match was found, return an empty array.\n return [];\n}\n\nfunction hasParametrizedPath(path: string): boolean {\n return path.includes(\"/{\");\n}\n\nfunction getPathFromMapKey(mapKey: string): string {\n const pathStart = mapKey.indexOf(\"/\");\n return mapKey.slice(pathStart);\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Client, HttpResponse } from \"@azure-rest/core-client\";\nimport {\n LongRunningOperation,\n LroEngine,\n LroEngineOptions,\n LroResponse,\n PollerLike,\n PollOperationState\n} from \"@azure/core-lro\";\n\n/**\n * Helper function that builds a Poller object to help polling a long running operation.\n * @param client - Client to use for sending the request to get additional pages.\n * @param initialResponse - The initial response.\n * @param options - Options to set a resume state or custom polling interval.\n * @returns - A poller object to poll for operation state updates and eventually get the final response.\n */\nexport function getLongRunningPoller<TResult extends HttpResponse>(\n client: Client,\n initialResponse: TResult,\n options: LroEngineOptions<TResult, PollOperationState<TResult>> = {}\n): PollerLike<PollOperationState<TResult>, TResult> {\n const poller: LongRunningOperation<TResult> = {\n requestMethod: initialResponse.request.method,\n requestPath: initialResponse.request.url,\n sendInitialRequest: async () => {\n // In the case of Rest Clients we are building the LRO poller object from a response that's the reason\n // we are not triggering the initial request here, just extracting the information from the\n // response we were provided.\n return getLroResponse(initialResponse);\n },\n sendPollRequest: async (path) => {\n // This is the callback that is going to be called to poll the service\n // to get the latest status. We use the client provided and the polling path\n // which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location\n // depending on the lro pattern that the service implements. If non is provided we default to the initial path.\n const response = await client\n .pathUnchecked(path ?? initialResponse.request.url)\n .get();\n const lroResponse = getLroResponse(response as TResult);\n lroResponse.rawResponse.headers[\"x-ms-original-url\"] =\n initialResponse.request.url;\n return lroResponse;\n }\n };\n\n return new LroEngine(poller, options);\n}\n\n/**\n * Converts a Rest Client response to a response that the LRO engine knows about\n * @param response - a rest client http response\n * @returns - An LRO response that the LRO engine can work with\n */\nfunction getLroResponse<TResult extends HttpResponse>(\n response: TResult\n): LroResponse<TResult> {\n if (Number.isNaN(response.status)) {\n throw new TypeError(\n `Status code of the response is not a number. Value: ${response.status}`\n );\n }\n\n return {\n flatResponse: response,\n rawResponse: {\n ...response,\n statusCode: Number.parseInt(response.status),\n body: response.body\n }\n };\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { ClientOptions } from \"@azure-rest/core-client\";\nimport { AzureKeyCredential, TokenCredential, isTokenCredential } from \"@azure/core-auth\";\nimport { createMapsClientIdPolicy } from \"@azure/maps-common\";\nimport { MapsSearchClient } from \"./generated\";\nimport createClient from \"./generated\";\nimport { bearerTokenAuthenticationPolicy } from \"@azure/core-rest-pipeline\";\n\n/**\n * Creates an instance of MapsSearchClient from a subscription key.\n *\n * @example\n * ```ts\n * import MapsSearch from \"@azure-rest/maps-search\";\n * import { AzureKeyCredential } from \"@azure/core-auth\";\n *\n * const credential = new AzureKeyCredential(\"<subscription-key>\");\n * const client = MapsSearch(credential);\n *```\n *\n * @param credential - An AzureKeyCredential instance used to authenticate requests to the service\n * @param options - Options used to configure the Search Client\n */\nexport default function MapsSearch(\n credential: AzureKeyCredential,\n options?: ClientOptions\n): MapsSearchClient;\n/**\n * Creates an instance of MapsSearch from an Azure Identity `TokenCredential`.\n *\n * @example\n * ```ts\n * import MapsSearch from \"@azure/maps-search\";\n * import { DefaultAzureCredential } from \"@azure/identity\";\n *\n * const credential = new DefaultAzureCredential();\n * const client = MapsSearch(credential, \"<maps-account-client-id>\");\n *```\n *\n * @param credential - An TokenCredential instance used to authenticate requests to the service\n * @param mapsAccountClientId - The Azure Maps client id of a specific map resource\n * @param options - Options used to configure the Search Client\n */\nexport default function MapsSearch(\n credential: TokenCredential,\n mapsAccountClientId: string,\n options?: ClientOptions\n): MapsSearchClient;\nexport default function MapsSearch(\n credential: TokenCredential | AzureKeyCredential,\n clientIdOrOptions: string | ClientOptions = {},\n maybeOptions: ClientOptions = {}\n): MapsSearchClient {\n const options = typeof clientIdOrOptions === \"string\" ? maybeOptions : clientIdOrOptions;\n\n /**\n * maps service requires a header \"ms-x-client-id\", which is different from the standard AAD.\n * So we need to do our own implementation.\n * This customized authentication is following by this guide: https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/RLC-customization.md#custom-authentication\n */\n if (isTokenCredential(credential)) {\n const clientId = typeof clientIdOrOptions === \"string\" ? clientIdOrOptions : \"\";\n if (!clientId) {\n throw Error(\"Client id is needed for TokenCredential\");\n }\n const client = createClient(undefined as any, options);\n client.pipeline.addPolicy(\n bearerTokenAuthenticationPolicy({\n credential,\n scopes: `${options.baseUrl || \"https://atlas.microsoft.com\"}/.default`,\n })\n );\n client.pipeline.addPolicy(createMapsClientIdPolicy(clientId));\n return client;\n }\n return createClient(credential, options);\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { BatchRequestItem } from \"./generated\";\n\n/**\n * Create batch items for the batch request.\n *\n * @param requests - The list of queries to process.\n * @returns - The BatchRequestItem object.\n */\nexport function createBatchItems<T extends Record<string, any>>(\n requests: Array<T>\n): Array<BatchRequestItem> {\n return requests.map((r) => ({\n query: Object.entries(r)\n .map(([k, v]) => `${k}=${v}`)\n .join(\"&\"),\n }));\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport MapsSearch from \"./MapsSearch\";\n\nexport * from \"./createBatchItems\";\nexport * from \"./generated\";\nexport default MapsSearch;\n"],"names":["getClient","LroEngine","isTokenCredential","bearerTokenAuthenticationPolicy","createMapsClientIdPolicy"],"mappings":";;;;;;;;;;AAAA;AAOA;;;AAGG;AACqB,SAAA,YAAY,CAClC,WAA0B,EAC1B,UAAyB,EAAE,EAAA;;IAE3B,MAAM,OAAO,GAAG,CAAA,EAAA,GAAA,OAAO,CAAC,OAAO,MAAA,IAAA,IAAA,EAAA,KA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AA,CAAC,CACH,CAAC;QACF,MAAM,CAAC,QAAQ,CAAC,SAAS,CAACC,mCAAwB,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC9D,QAAA,OAAO,MAAM,CAAC;AACf,KAAA;AACD,IAAA,OAAO,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AAC3C;;AC9EA;AACA;AAIA;;;;;AAKG;AACG,SAAU,gBAAgB,CAC9B,QAAkB,EAAA;IAElB,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM;AAC1B,QAAA,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;AACrB,aAAA,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAG,EAAA,CAAC,CAAI,CAAA,EAAA,CAAC,EAAE,CAAC;aAC5B,IAAI,CAAC,GAAG,CAAC;AACb,KAAA,CAAC,CAAC,CAAC;AACN;;ACnBA;;;;;;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
import { isTokenCredential } from "@azure/core-auth";
|
|
4
|
+
import { createMapsClientIdPolicy } from "@azure/maps-common";
|
|
5
|
+
import createClient from "./generated";
|
|
6
|
+
import { bearerTokenAuthenticationPolicy } from "@azure/core-rest-pipeline";
|
|
7
|
+
export default function MapsSearch(credential, clientIdOrOptions = {}, maybeOptions = {}) {
|
|
8
|
+
const options = typeof clientIdOrOptions === "string" ? maybeOptions : clientIdOrOptions;
|
|
9
|
+
/**
|
|
10
|
+
* maps service requires a header "ms-x-client-id", which is different from the standard AAD.
|
|
11
|
+
* So we need to do our own implementation.
|
|
12
|
+
* This customized authentication is following by this guide: https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/RLC-customization.md#custom-authentication
|
|
13
|
+
*/
|
|
14
|
+
if (isTokenCredential(credential)) {
|
|
15
|
+
const clientId = typeof clientIdOrOptions === "string" ? clientIdOrOptions : "";
|
|
16
|
+
if (!clientId) {
|
|
17
|
+
throw Error("Client id is needed for TokenCredential");
|
|
18
|
+
}
|
|
19
|
+
const client = createClient(undefined, options);
|
|
20
|
+
client.pipeline.addPolicy(bearerTokenAuthenticationPolicy({
|
|
21
|
+
credential,
|
|
22
|
+
scopes: `${options.baseUrl || "https://atlas.microsoft.com"}/.default`,
|
|
23
|
+
}));
|
|
24
|
+
client.pipeline.addPolicy(createMapsClientIdPolicy(clientId));
|
|
25
|
+
return client;
|
|
26
|
+
}
|
|
27
|
+
return createClient(credential, options);
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=MapsSearch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapsSearch.js","sourceRoot":"","sources":["../../src/MapsSearch.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAuC,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,YAAY,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AA0C5E,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,UAAgD,EAChD,oBAA4C,EAAE,EAC9C,eAA8B,EAAE;IAEhC,MAAM,OAAO,GAAG,OAAO,iBAAiB,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,iBAAiB,CAAC;IAEzF;;;;OAIG;IACH,IAAI,iBAAiB,CAAC,UAAU,CAAC,EAAE;QACjC,MAAM,QAAQ,GAAG,OAAO,iBAAiB,KAAK,QAAQ,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC;QAChF,IAAI,CAAC,QAAQ,EAAE;YACb,MAAM,KAAK,CAAC,yCAAyC,CAAC,CAAC;SACxD;QACD,MAAM,MAAM,GAAG,YAAY,CAAC,SAAgB,EAAE,OAAO,CAAC,CAAC;QACvD,MAAM,CAAC,QAAQ,CAAC,SAAS,CACvB,+BAA+B,CAAC;YAC9B,UAAU;YACV,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,IAAI,6BAA6B,WAAW;SACvE,CAAC,CACH,CAAC;QACF,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC9D,OAAO,MAAM,CAAC;KACf;IACD,OAAO,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { ClientOptions } from \"@azure-rest/core-client\";\nimport { AzureKeyCredential, TokenCredential, isTokenCredential } from \"@azure/core-auth\";\nimport { createMapsClientIdPolicy } from \"@azure/maps-common\";\nimport { MapsSearchClient } from \"./generated\";\nimport createClient from \"./generated\";\nimport { bearerTokenAuthenticationPolicy } from \"@azure/core-rest-pipeline\";\n\n/**\n * Creates an instance of MapsSearchClient from a subscription key.\n *\n * @example\n * ```ts\n * import MapsSearch from \"@azure-rest/maps-search\";\n * import { AzureKeyCredential } from \"@azure/core-auth\";\n *\n * const credential = new AzureKeyCredential(\"<subscription-key>\");\n * const client = MapsSearch(credential);\n *```\n *\n * @param credential - An AzureKeyCredential instance used to authenticate requests to the service\n * @param options - Options used to configure the Search Client\n */\nexport default function MapsSearch(\n credential: AzureKeyCredential,\n options?: ClientOptions\n): MapsSearchClient;\n/**\n * Creates an instance of MapsSearch from an Azure Identity `TokenCredential`.\n *\n * @example\n * ```ts\n * import MapsSearch from \"@azure/maps-search\";\n * import { DefaultAzureCredential } from \"@azure/identity\";\n *\n * const credential = new DefaultAzureCredential();\n * const client = MapsSearch(credential, \"<maps-account-client-id>\");\n *```\n *\n * @param credential - An TokenCredential instance used to authenticate requests to the service\n * @param mapsAccountClientId - The Azure Maps client id of a specific map resource\n * @param options - Options used to configure the Search Client\n */\nexport default function MapsSearch(\n credential: TokenCredential,\n mapsAccountClientId: string,\n options?: ClientOptions\n): MapsSearchClient;\nexport default function MapsSearch(\n credential: TokenCredential | AzureKeyCredential,\n clientIdOrOptions: string | ClientOptions = {},\n maybeOptions: ClientOptions = {}\n): MapsSearchClient {\n const options = typeof clientIdOrOptions === \"string\" ? maybeOptions : clientIdOrOptions;\n\n /**\n * maps service requires a header \"ms-x-client-id\", which is different from the standard AAD.\n * So we need to do our own implementation.\n * This customized authentication is following by this guide: https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/RLC-customization.md#custom-authentication\n */\n if (isTokenCredential(credential)) {\n const clientId = typeof clientIdOrOptions === \"string\" ? clientIdOrOptions : \"\";\n if (!clientId) {\n throw Error(\"Client id is needed for TokenCredential\");\n }\n const client = createClient(undefined as any, options);\n client.pipeline.addPolicy(\n bearerTokenAuthenticationPolicy({\n credential,\n scopes: `${options.baseUrl || \"https://atlas.microsoft.com\"}/.default`,\n })\n );\n client.pipeline.addPolicy(createMapsClientIdPolicy(clientId));\n return client;\n }\n return createClient(credential, options);\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
/**
|
|
4
|
+
* Create batch items for the batch request.
|
|
5
|
+
*
|
|
6
|
+
* @param requests - The list of queries to process.
|
|
7
|
+
* @returns - The BatchRequestItem object.
|
|
8
|
+
*/
|
|
9
|
+
export function createBatchItems(requests) {
|
|
10
|
+
return requests.map((r) => ({
|
|
11
|
+
query: Object.entries(r)
|
|
12
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
13
|
+
.join("&"),
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=createBatchItems.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBatchItems.js","sourceRoot":"","sources":["../../src/createBatchItems.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,QAAkB;IAElB,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC1B,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;aACrB,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;aAC5B,IAAI,CAAC,GAAG,CAAC;KACb,CAAC,CAAC,CAAC;AACN,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { BatchRequestItem } from \"./generated\";\n\n/**\n * Create batch items for the batch request.\n *\n * @param requests - The list of queries to process.\n * @returns - The BatchRequestItem object.\n */\nexport function createBatchItems<T extends Record<string, any>>(\n requests: Array<T>\n): Array<BatchRequestItem> {\n return requests.map((r) => ({\n query: Object.entries(r)\n .map(([k, v]) => `${k}=${v}`)\n .join(\"&\"),\n }));\n}\n"]}
|