@azure-rest/maps-search 2.0.0-beta.1 → 2.0.0-beta.2
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 +47 -47
- package/dist/index.js +40 -29
- package/dist/index.js.map +1 -1
- package/dist-esm/src/MapsSearch.js +5 -5
- package/dist-esm/src/MapsSearch.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/logger.js +1 -1
- package/dist-esm/src/logger.js.map +1 -1
- package/package.json +31 -35
- package/review/maps-search.api.md +8 -3
- package/types/maps-search-rest.d.ts +43 -94
- 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 -12
- package/dist-esm/src/generated/index.js.map +0 -1
- package/dist-esm/src/generated/isUnexpected.js +0 -74
- package/dist-esm/src/generated/isUnexpected.js.map +0 -1
- package/dist-esm/src/generated/mapsSearchClient.js +0 -32
- package/dist-esm/src/generated/mapsSearchClient.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 -55
- 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
|
@@ -45,19 +45,19 @@ npm install @azure-rest/maps-search
|
|
|
45
45
|
|
|
46
46
|
### Create and authenticate a `MapsSearchClient`
|
|
47
47
|
|
|
48
|
-
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
|
|
48
|
+
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 a Microsoft Entra ID credential or an Azure Key credential to authenticate.
|
|
49
49
|
|
|
50
|
-
#### Using
|
|
50
|
+
#### Using a Microsoft Entra ID Credential
|
|
51
51
|
|
|
52
|
-
You can authenticate with
|
|
52
|
+
You can authenticate with Microsoft Entra ID 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:
|
|
53
53
|
|
|
54
54
|
```bash
|
|
55
55
|
npm install @azure/identity
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
You will also need to register a new
|
|
58
|
+
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.
|
|
59
59
|
|
|
60
|
-
Set the values of the client ID, tenant ID, and client secret of the
|
|
60
|
+
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`.
|
|
61
61
|
|
|
62
62
|
You will also need to specify the Azure Maps resource you intend to use by specifying the `clientId` in the client options.
|
|
63
63
|
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.
|
|
@@ -99,33 +99,33 @@ npm install @azure/core-auth
|
|
|
99
99
|
Finally, you can use the SAS token to authenticate the client:
|
|
100
100
|
|
|
101
101
|
```javascript
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
102
|
+
const MapsSearch = require("@azure-rest/maps-search").default;
|
|
103
|
+
const { AzureSASCredential } = require("@azure/core-auth");
|
|
104
|
+
const { DefaultAzureCredential } = require("@azure/identity");
|
|
105
|
+
const { AzureMapsManagementClient } = require("@azure/arm-maps");
|
|
106
|
+
|
|
107
|
+
const subscriptionId = "<subscription ID of the map account>";
|
|
108
|
+
const resourceGroupName = "<resource group name of the map account>";
|
|
109
|
+
const accountName = "<name of the map account>";
|
|
110
|
+
const mapsAccountSasParameters = {
|
|
111
|
+
start: "<start time in ISO format>", // e.g. "2023-11-24T03:51:53.161Z"
|
|
112
|
+
expiry: "<expiry time in ISO format>", // maximum value to start + 1 day
|
|
113
|
+
maxRatePerSecond: 500,
|
|
114
|
+
principalId: "<principle ID (object ID) of the managed identity>",
|
|
115
|
+
signingKey: "primaryKey",
|
|
116
|
+
};
|
|
117
|
+
const credential = new DefaultAzureCredential();
|
|
118
|
+
const managementClient = new AzureMapsManagementClient(credential, subscriptionId);
|
|
119
|
+
const { accountSasToken } = await managementClient.accounts.listSas(
|
|
120
|
+
resourceGroupName,
|
|
121
|
+
accountName,
|
|
122
|
+
mapsAccountSasParameters,
|
|
123
|
+
);
|
|
124
|
+
if (accountSasToken === undefined) {
|
|
125
|
+
throw new Error("No accountSasToken was found for the Maps Account.");
|
|
126
|
+
}
|
|
127
|
+
const sasCredential = new AzureSASCredential(accountSasToken);
|
|
128
|
+
const client = MapsSearch(sasCredential);
|
|
129
129
|
```
|
|
130
130
|
|
|
131
131
|
## Key concepts
|
|
@@ -153,7 +153,7 @@ const { isUnexpected } = require("@azure-rest/maps-search");
|
|
|
153
153
|
/** Initialize the MapsSearchClient */
|
|
154
154
|
const client = MapsSearch(new AzureKeyCredential("<subscription-key>"));
|
|
155
155
|
|
|
156
|
-
async function main(){
|
|
156
|
+
async function main() {
|
|
157
157
|
/** Make a request to the geocoding API */
|
|
158
158
|
const response = await client
|
|
159
159
|
.path("/geocode")
|
|
@@ -167,10 +167,10 @@ async function main(){
|
|
|
167
167
|
console.log(`No coordinates found for the address.`);
|
|
168
168
|
} else {
|
|
169
169
|
console.log(`The followings are the possible coordinates of the address:`);
|
|
170
|
-
for(const result of response.body.features) {
|
|
170
|
+
for (const result of response.body.features) {
|
|
171
171
|
const [lon, lat] = result.geometry.coordinates;
|
|
172
172
|
console.log(`Latitude: ${lat}, Longitude ${lon}`);
|
|
173
|
-
console.log("Postal code: ", result.properties?.address?.postalCode)
|
|
173
|
+
console.log("Postal code: ", result.properties?.address?.postalCode);
|
|
174
174
|
console.log("Admin districts: ", result.properties?.address?.adminDistricts?.join(", "));
|
|
175
175
|
console.log("Country region: ", result.properties?.address?.countryRegion);
|
|
176
176
|
}
|
|
@@ -178,8 +178,8 @@ async function main(){
|
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
main().catch((err) => {
|
|
181
|
-
|
|
182
|
-
})
|
|
181
|
+
console.log(err);
|
|
182
|
+
});
|
|
183
183
|
```
|
|
184
184
|
|
|
185
185
|
### Make a Reverse Address Search to translate coordinate location to street address
|
|
@@ -195,7 +195,7 @@ const { isUnexpected } = require("@azure-rest/maps-search");
|
|
|
195
195
|
/** Initialize the MapsSearchClient */
|
|
196
196
|
const client = MapsSearch(new AzureKeyCredential("<subscription-key>"));
|
|
197
197
|
|
|
198
|
-
async function main(){
|
|
198
|
+
async function main() {
|
|
199
199
|
/** Make the request. */
|
|
200
200
|
const response = await client.path("/reverseGeocode").get({
|
|
201
201
|
queryParameters: { coordinates: [-121.89, 37.337] }, // [longitude, latitude],
|
|
@@ -208,7 +208,7 @@ async function main(){
|
|
|
208
208
|
console.log("No results found.");
|
|
209
209
|
} else {
|
|
210
210
|
/** Log the response body. */
|
|
211
|
-
for(const feature of response.body.features) {
|
|
211
|
+
for (const feature of response.body.features) {
|
|
212
212
|
if (feature.properties?.address?.formattedAddress) {
|
|
213
213
|
console.log(feature.properties.address.formattedAddress);
|
|
214
214
|
} else {
|
|
@@ -219,8 +219,8 @@ async function main(){
|
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
main().catch((err) => {
|
|
222
|
-
|
|
223
|
-
})
|
|
222
|
+
console.log(err);
|
|
223
|
+
});
|
|
224
224
|
```
|
|
225
225
|
|
|
226
226
|
## Use V1 SDK
|
|
@@ -263,7 +263,7 @@ async function searchNearby(address) {
|
|
|
263
263
|
}
|
|
264
264
|
|
|
265
265
|
const [lon, lat] = geocodeResponse.body.features[0].geometry.coordinates;
|
|
266
|
-
|
|
266
|
+
|
|
267
267
|
/** Make a request to the search nearby API */
|
|
268
268
|
const nearByResponse = await clientV1.path("/search/nearby/{format}", "json").get({
|
|
269
269
|
queryParameters: { lat, lon },
|
|
@@ -273,22 +273,22 @@ async function searchNearby(address) {
|
|
|
273
273
|
throw nearByResponse.body.error;
|
|
274
274
|
}
|
|
275
275
|
/** Log response body */
|
|
276
|
-
for(const results of nearByResponse.body.results) {
|
|
276
|
+
for (const results of nearByResponse.body.results) {
|
|
277
277
|
console.log(
|
|
278
278
|
`${result.poi ? result.poi.name + ":" : ""} ${result.address.freeformAddress}. (${
|
|
279
279
|
result.position.lat
|
|
280
|
-
}, ${result.position.lon})\n
|
|
280
|
+
}, ${result.position.lon})\n`,
|
|
281
281
|
);
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
284
|
|
|
285
|
-
async function main(){
|
|
285
|
+
async function main() {
|
|
286
286
|
searchNearBy("15127 NE 24th Street, Redmond, WA 98052");
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
main().catch((err) => {
|
|
290
|
-
|
|
291
|
-
})
|
|
290
|
+
console.log(err);
|
|
291
|
+
});
|
|
292
292
|
```
|
|
293
293
|
|
|
294
294
|
## Troubleshooting
|
package/dist/index.js
CHANGED
|
@@ -4,56 +4,66 @@ 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');
|
|
8
9
|
var logger$1 = require('@azure/logger');
|
|
9
10
|
var coreRestPipeline = require('@azure/core-rest-pipeline');
|
|
10
11
|
|
|
11
12
|
// Copyright (c) Microsoft Corporation.
|
|
12
|
-
// Licensed under the MIT
|
|
13
|
+
// Licensed under the MIT License.
|
|
13
14
|
const logger = logger$1.createClientLogger("maps-search");
|
|
14
15
|
|
|
15
16
|
// Copyright (c) Microsoft Corporation.
|
|
16
|
-
// Licensed under the MIT
|
|
17
|
+
// Licensed under the MIT License.
|
|
17
18
|
/**
|
|
18
19
|
* Initialize a new instance of `MapsSearchClient`
|
|
19
20
|
* @param credentials - uniquely identify client credential
|
|
20
21
|
* @param options - the parameter for all optional parameters
|
|
21
22
|
*/
|
|
22
|
-
function createClient(credentials,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
23
|
+
function createClient(credentials, _a = {}) {
|
|
24
|
+
var _b, _c, _d, _e, _f, _g;
|
|
25
|
+
var { apiVersion = "2023-06-01" } = _a, options = tslib.__rest(_a, ["apiVersion"]);
|
|
26
|
+
const endpointUrl = (_c = (_b = options.endpoint) !== null && _b !== void 0 ? _b : options.baseUrl) !== null && _c !== void 0 ? _c : `https://atlas.microsoft.com`;
|
|
27
|
+
const userAgentInfo = `azsdk-js-maps-search-rest/2.0.0-beta.2`;
|
|
26
28
|
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
27
29
|
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
|
|
28
30
|
: `${userAgentInfo}`;
|
|
29
|
-
options = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
options = Object.assign(Object.assign({}, options), { userAgentOptions: {
|
|
32
|
+
userAgentPrefix,
|
|
33
|
+
}, loggingOptions: {
|
|
34
|
+
logger: (_e = (_d = options.loggingOptions) === null || _d === void 0 ? void 0 : _d.logger) !== null && _e !== void 0 ? _e : logger.info,
|
|
35
|
+
}, credentials: {
|
|
36
|
+
apiKeyHeaderName: (_g = (_f = options.credentials) === null || _f === void 0 ? void 0 : _f.apiKeyHeaderName) !== null && _g !== void 0 ? _g : "subscription-key",
|
|
37
|
+
} });
|
|
38
|
+
const client = coreClient.getClient(endpointUrl, credentials, options);
|
|
39
|
+
client.pipeline.removePolicy({ name: "ApiVersionPolicy" });
|
|
40
|
+
client.pipeline.addPolicy({
|
|
41
|
+
name: "ClientApiVersionPolicy",
|
|
42
|
+
sendRequest: (req, next) => {
|
|
43
|
+
// Use the apiVersion defined in request url directly
|
|
44
|
+
// Append one if there is no apiVersion and we have one at client options
|
|
45
|
+
const url = new URL(req.url);
|
|
46
|
+
if (!url.searchParams.get("api-version") && apiVersion) {
|
|
47
|
+
req.url = `${req.url}${Array.from(url.searchParams.keys()).length > 0 ? "&" : "?"}api-version=${apiVersion}`;
|
|
48
|
+
}
|
|
49
|
+
return next(req);
|
|
36
50
|
},
|
|
37
|
-
|
|
38
|
-
apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "subscription-key"
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
const client = coreClient.getClient(baseUrl, credentials, options);
|
|
51
|
+
});
|
|
42
52
|
return client;
|
|
43
53
|
}
|
|
44
54
|
|
|
45
55
|
// Copyright (c) Microsoft Corporation.
|
|
46
|
-
// Licensed under the MIT
|
|
56
|
+
// Licensed under the MIT License.
|
|
47
57
|
const responseMap = {
|
|
48
58
|
"GET /geocode": ["200"],
|
|
49
59
|
"POST /geocode:batch": ["200"],
|
|
50
60
|
"GET /search/polygon": ["200"],
|
|
51
61
|
"GET /reverseGeocode": ["200"],
|
|
52
|
-
"POST /reverseGeocode:batch": ["200"]
|
|
62
|
+
"POST /reverseGeocode:batch": ["200"],
|
|
53
63
|
};
|
|
54
64
|
function isUnexpected(response) {
|
|
55
65
|
const lroOriginal = response.headers["x-ms-original-url"];
|
|
56
|
-
const url = new URL(lroOriginal
|
|
66
|
+
const url = new URL(lroOriginal !== null && lroOriginal !== void 0 ? lroOriginal : response.request.url);
|
|
57
67
|
const method = response.request.method;
|
|
58
68
|
let pathDetails = responseMap[`${method} ${url.pathname}`];
|
|
59
69
|
if (!pathDetails) {
|
|
@@ -62,6 +72,7 @@ function isUnexpected(response) {
|
|
|
62
72
|
return !pathDetails.includes(response.status);
|
|
63
73
|
}
|
|
64
74
|
function getParametrizedPathSuccess(method, path) {
|
|
75
|
+
var _a, _b, _c, _d;
|
|
65
76
|
const pathParts = path.split("/");
|
|
66
77
|
// Traverse list to match the longest candidate
|
|
67
78
|
// matchedLen: the length of candidate path
|
|
@@ -80,14 +91,14 @@ function getParametrizedPathSuccess(method, path) {
|
|
|
80
91
|
// track if we have found a match to return the values found.
|
|
81
92
|
let found = true;
|
|
82
93
|
for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
|
|
83
|
-
if (candidateParts[i]
|
|
84
|
-
candidateParts[i]
|
|
85
|
-
const start = candidateParts[i].indexOf("}") + 1, end = candidateParts[i]
|
|
94
|
+
if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) &&
|
|
95
|
+
((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.indexOf("}")) !== -1) {
|
|
96
|
+
const start = candidateParts[i].indexOf("}") + 1, end = (_c = candidateParts[i]) === null || _c === void 0 ? void 0 : _c.length;
|
|
86
97
|
// If the current part of the candidate is a "template" part
|
|
87
98
|
// Try to use the suffix of pattern to match the path
|
|
88
99
|
// {guid} ==> $
|
|
89
100
|
// {guid}:export ==> :export$
|
|
90
|
-
const isMatched = new RegExp(`${candidateParts[i]
|
|
101
|
+
const isMatched = new RegExp(`${(_d = candidateParts[i]) === null || _d === void 0 ? void 0 : _d.slice(start, end)}`).test(pathParts[j] || "");
|
|
91
102
|
if (!isMatched) {
|
|
92
103
|
found = false;
|
|
93
104
|
break;
|
|
@@ -117,11 +128,11 @@ function getPathFromMapKey(mapKey) {
|
|
|
117
128
|
}
|
|
118
129
|
|
|
119
130
|
// Copyright (c) Microsoft Corporation.
|
|
120
|
-
// Licensed under the MIT
|
|
131
|
+
// Licensed under the MIT License.
|
|
121
132
|
function MapsSearch(credential, clientIdOrOptions = {}, maybeOptions = {}) {
|
|
122
133
|
const options = typeof clientIdOrOptions === "string" ? maybeOptions : clientIdOrOptions;
|
|
123
134
|
/**
|
|
124
|
-
* maps service requires a header "ms-x-client-id", which is different from the standard
|
|
135
|
+
* maps service requires a header "ms-x-client-id", which is different from the standard Microsoft Entra ID.
|
|
125
136
|
* So we need to do our own implementation.
|
|
126
137
|
* This customized authentication is following by this guide: https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/RLC-customization.md#custom-authentication
|
|
127
138
|
*/
|
|
@@ -133,7 +144,7 @@ function MapsSearch(credential, clientIdOrOptions = {}, maybeOptions = {}) {
|
|
|
133
144
|
const client = createClient(undefined, options);
|
|
134
145
|
client.pipeline.addPolicy(coreRestPipeline.bearerTokenAuthenticationPolicy({
|
|
135
146
|
credential,
|
|
136
|
-
scopes:
|
|
147
|
+
scopes: "https://atlas.microsoft.com/.default",
|
|
137
148
|
}));
|
|
138
149
|
client.pipeline.addPolicy(mapsCommon.createMapsClientIdPolicy(clientId));
|
|
139
150
|
return client;
|
|
@@ -153,7 +164,7 @@ function MapsSearch(credential, clientIdOrOptions = {}, maybeOptions = {}) {
|
|
|
153
164
|
}
|
|
154
165
|
|
|
155
166
|
// Copyright (c) Microsoft Corporation.
|
|
156
|
-
// Licensed under the MIT
|
|
167
|
+
// Licensed under the MIT License.
|
|
157
168
|
|
|
158
169
|
exports.default = MapsSearch;
|
|
159
170
|
exports.isUnexpected = isUnexpected;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/logger.ts","../src/generated/mapsSearchClient.ts","../src/generated/isUnexpected.ts","../src/MapsSearch.ts","../src/index.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { createClientLogger } from \"@azure/logger\";\nexport const logger = createClientLogger(\"maps-search\");\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { getClient, ClientOptions } from \"@azure-rest/core-client\";\nimport { logger } from \"../logger\";\nimport { KeyCredential } from \"@azure/core-auth\";\nimport { MapsSearchClient } from \"./clientDefinitions\";\n\n/**\n * Initialize a new instance of `MapsSearchClient`\n * @param credentials - uniquely identify client credential\n * @param options - the parameter for all optional parameters\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 ?? \"2023-06-01\";\n const userAgentInfo = `azsdk-js-maps-search-rest/2.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 loggingOptions: {\n logger: options.loggingOptions?.logger ?? logger.info\n },\n credentials: {\n apiKeyHeaderName:\n options.credentials?.apiKeyHeaderName ?? \"subscription-key\"\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 SearchGetGeocoding200Response,\n SearchGetGeocodingDefaultResponse,\n SearchGetGeocodingBatch200Response,\n SearchGetGeocodingBatchDefaultResponse,\n SearchGetPolygon200Response,\n SearchGetPolygonDefaultResponse,\n SearchGetReverseGeocoding200Response,\n SearchGetReverseGeocodingDefaultResponse,\n SearchGetReverseGeocodingBatch200Response,\n SearchGetReverseGeocodingBatchDefaultResponse\n} from \"./responses\";\n\nconst responseMap: Record<string, string[]> = {\n \"GET /geocode\": [\"200\"],\n \"POST /geocode:batch\": [\"200\"],\n \"GET /search/polygon\": [\"200\"],\n \"GET /reverseGeocode\": [\"200\"],\n \"POST /reverseGeocode:batch\": [\"200\"]\n};\n\nexport function isUnexpected(\n response: SearchGetGeocoding200Response | SearchGetGeocodingDefaultResponse\n): response is SearchGetGeocodingDefaultResponse;\nexport function isUnexpected(\n response:\n | SearchGetGeocodingBatch200Response\n | SearchGetGeocodingBatchDefaultResponse\n): response is SearchGetGeocodingBatchDefaultResponse;\nexport function isUnexpected(\n response: SearchGetPolygon200Response | SearchGetPolygonDefaultResponse\n): response is SearchGetPolygonDefaultResponse;\nexport function isUnexpected(\n response:\n | SearchGetReverseGeocoding200Response\n | SearchGetReverseGeocodingDefaultResponse\n): response is SearchGetReverseGeocodingDefaultResponse;\nexport function isUnexpected(\n response:\n | SearchGetReverseGeocodingBatch200Response\n | SearchGetReverseGeocodingBatchDefaultResponse\n): response is SearchGetReverseGeocodingBatchDefaultResponse;\nexport function isUnexpected(\n response:\n | SearchGetGeocoding200Response\n | SearchGetGeocodingDefaultResponse\n | SearchGetGeocodingBatch200Response\n | SearchGetGeocodingBatchDefaultResponse\n | SearchGetPolygon200Response\n | SearchGetPolygonDefaultResponse\n | SearchGetReverseGeocoding200Response\n | SearchGetReverseGeocodingDefaultResponse\n | SearchGetReverseGeocodingBatch200Response\n | SearchGetReverseGeocodingBatchDefaultResponse\n): response is\n | SearchGetGeocodingDefaultResponse\n | SearchGetGeocodingBatchDefaultResponse\n | SearchGetPolygonDefaultResponse\n | SearchGetReverseGeocodingDefaultResponse\n | SearchGetReverseGeocodingBatchDefaultResponse {\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 = getParametrizedPathSuccess(method, url.pathname);\n }\n return !pathDetails.includes(response.status);\n}\n\nfunction getParametrizedPathSuccess(method: string, path: string): string[] {\n const pathParts = path.split(\"/\");\n\n // Traverse list to match the longest candidate\n // matchedLen: the length of candidate path\n // matchedValue: the matched status code array\n let matchedLen = -1,\n matchedValue: string[] = [];\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 // track if we have found a match to return the values found.\n let found = true;\n for (\n let i = candidateParts.length - 1, j = pathParts.length - 1;\n i >= 1 && j >= 1;\n i--, j--\n ) {\n if (\n candidateParts[i]?.startsWith(\"{\") &&\n candidateParts[i]?.indexOf(\"}\") !== -1\n ) {\n const start = candidateParts[i]!.indexOf(\"}\") + 1,\n end = candidateParts[i]?.length;\n // If the current part of the candidate is a \"template\" part\n // Try to use the suffix of pattern to match the path\n // {guid} ==> $\n // {guid}:export ==> :export$\n const isMatched = new RegExp(\n `${candidateParts[i]?.slice(start, end)}`\n ).test(pathParts[j] || \"\");\n\n if (!isMatched) {\n found = false;\n break;\n }\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[j]) {\n found = false;\n break;\n }\n }\n\n // We finished evaluating the current candidate parts\n // Update the matched value if and only if we found the longer pattern\n if (found && candidatePath.length > matchedLen) {\n matchedLen = candidatePath.length;\n matchedValue = value;\n }\n }\n\n return matchedValue;\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 { ClientOptions } from \"@azure-rest/core-client\";\nimport {\n AzureKeyCredential,\n AzureSASCredential,\n TokenCredential,\n isSASCredential,\n isTokenCredential,\n} 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-rest/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;\n/**\n * Creates an instance of MapsSearch from an Azure Identity `AzureSASCredential`.\n *\n * @example\n * ```ts\n * import MapsSearch from \"@azure-rest/maps-search\";\n * import { AzureSASCredential } from \"@azure/core-auth\";\n *\n * const credential = new AzureSASCredential(\"<SAS Token>\");\n * const client = MapsSearch(credential);\n * ```\n *\n * @param credential - An AzureSASCredential 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: AzureSASCredential,\n options?: ClientOptions,\n): MapsSearchClient;\nexport default function MapsSearch(\n credential: TokenCredential | AzureKeyCredential | AzureSASCredential,\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\n if (isSASCredential(credential)) {\n const client = createClient(undefined as any, options);\n client.pipeline.addPolicy({\n name: \"mapsSASCredentialPolicy\",\n async sendRequest(request, next) {\n request.headers.set(\"Authorization\", `jwt-sas ${credential.signature}`);\n return next(request);\n },\n });\n return client;\n }\n\n return createClient(credential, options);\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport MapsSearch from \"./MapsSearch\";\n\nexport * from \"./generated\";\nexport default MapsSearch;\n"],"names":["createClientLogger","getClient","isTokenCredential","bearerTokenAuthenticationPolicy","createMapsClientIdPolicy","isSASCredential"],"mappings":";;;;;;;;;;AAAA;AACA;AAGO,MAAM,MAAM,GAAGA,2BAAkB,CAAC,aAAa,CAAC;;ACJvD;AACA;AAOA;;;;AAIG;AACqB,SAAA,YAAY,CAClC,WAA0B,EAC1B,UAAyB,EAAE,EAAA;AAE3B,IAAA,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,6BAA6B,CAAC;IACjE,OAAO,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,YAAY,CAAC;I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/mapsSearchClient.ts","../generated/isUnexpected.ts","../src/MapsSearch.ts","../src/index.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { createClientLogger } from \"@azure/logger\";\nexport const logger = createClientLogger(\"maps-search\");\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { getClient, ClientOptions } from \"@azure-rest/core-client\";\nimport { logger } from \"./logger\";\nimport { KeyCredential } from \"@azure/core-auth\";\nimport { MapsSearchClient } from \"./clientDefinitions\";\n\n/** The optional parameters for the client */\nexport interface MapsSearchClientOptions extends ClientOptions {\n /** The api version option of the client */\n apiVersion?: string;\n}\n\n/**\n * Initialize a new instance of `MapsSearchClient`\n * @param credentials - uniquely identify client credential\n * @param options - the parameter for all optional parameters\n */\nexport default function createClient(\n credentials: KeyCredential,\n { apiVersion = \"2023-06-01\", ...options }: MapsSearchClientOptions = {},\n): MapsSearchClient {\n const endpointUrl =\n options.endpoint ?? options.baseUrl ?? `https://atlas.microsoft.com`;\n const userAgentInfo = `azsdk-js-maps-search-rest/2.0.0-beta.2`;\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 loggingOptions: {\n logger: options.loggingOptions?.logger ?? logger.info,\n },\n credentials: {\n apiKeyHeaderName:\n options.credentials?.apiKeyHeaderName ?? \"subscription-key\",\n },\n };\n const client = getClient(\n endpointUrl,\n credentials,\n options,\n ) as MapsSearchClient;\n\n client.pipeline.removePolicy({ name: \"ApiVersionPolicy\" });\n client.pipeline.addPolicy({\n name: \"ClientApiVersionPolicy\",\n sendRequest: (req, next) => {\n // Use the apiVersion defined in request url directly\n // Append one if there is no apiVersion and we have one at client options\n const url = new URL(req.url);\n if (!url.searchParams.get(\"api-version\") && apiVersion) {\n req.url = `${req.url}${\n Array.from(url.searchParams.keys()).length > 0 ? \"&\" : \"?\"\n }api-version=${apiVersion}`;\n }\n\n return next(req);\n },\n });\n\n return client;\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport {\n SearchGetGeocoding200Response,\n SearchGetGeocodingDefaultResponse,\n SearchGetGeocodingBatch200Response,\n SearchGetGeocodingBatchDefaultResponse,\n SearchGetPolygon200Response,\n SearchGetPolygonDefaultResponse,\n SearchGetReverseGeocoding200Response,\n SearchGetReverseGeocodingDefaultResponse,\n SearchGetReverseGeocodingBatch200Response,\n SearchGetReverseGeocodingBatchDefaultResponse,\n} from \"./responses\";\n\nconst responseMap: Record<string, string[]> = {\n \"GET /geocode\": [\"200\"],\n \"POST /geocode:batch\": [\"200\"],\n \"GET /search/polygon\": [\"200\"],\n \"GET /reverseGeocode\": [\"200\"],\n \"POST /reverseGeocode:batch\": [\"200\"],\n};\n\nexport function isUnexpected(\n response: SearchGetGeocoding200Response | SearchGetGeocodingDefaultResponse,\n): response is SearchGetGeocodingDefaultResponse;\nexport function isUnexpected(\n response:\n | SearchGetGeocodingBatch200Response\n | SearchGetGeocodingBatchDefaultResponse,\n): response is SearchGetGeocodingBatchDefaultResponse;\nexport function isUnexpected(\n response: SearchGetPolygon200Response | SearchGetPolygonDefaultResponse,\n): response is SearchGetPolygonDefaultResponse;\nexport function isUnexpected(\n response:\n | SearchGetReverseGeocoding200Response\n | SearchGetReverseGeocodingDefaultResponse,\n): response is SearchGetReverseGeocodingDefaultResponse;\nexport function isUnexpected(\n response:\n | SearchGetReverseGeocodingBatch200Response\n | SearchGetReverseGeocodingBatchDefaultResponse,\n): response is SearchGetReverseGeocodingBatchDefaultResponse;\nexport function isUnexpected(\n response:\n | SearchGetGeocoding200Response\n | SearchGetGeocodingDefaultResponse\n | SearchGetGeocodingBatch200Response\n | SearchGetGeocodingBatchDefaultResponse\n | SearchGetPolygon200Response\n | SearchGetPolygonDefaultResponse\n | SearchGetReverseGeocoding200Response\n | SearchGetReverseGeocodingDefaultResponse\n | SearchGetReverseGeocodingBatch200Response\n | SearchGetReverseGeocodingBatchDefaultResponse,\n): response is\n | SearchGetGeocodingDefaultResponse\n | SearchGetGeocodingBatchDefaultResponse\n | SearchGetPolygonDefaultResponse\n | SearchGetReverseGeocodingDefaultResponse\n | SearchGetReverseGeocodingBatchDefaultResponse {\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 = getParametrizedPathSuccess(method, url.pathname);\n }\n return !pathDetails.includes(response.status);\n}\n\nfunction getParametrizedPathSuccess(method: string, path: string): string[] {\n const pathParts = path.split(\"/\");\n\n // Traverse list to match the longest candidate\n // matchedLen: the length of candidate path\n // matchedValue: the matched status code array\n let matchedLen = -1,\n matchedValue: string[] = [];\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 // track if we have found a match to return the values found.\n let found = true;\n for (\n let i = candidateParts.length - 1, j = pathParts.length - 1;\n i >= 1 && j >= 1;\n i--, j--\n ) {\n if (\n candidateParts[i]?.startsWith(\"{\") &&\n candidateParts[i]?.indexOf(\"}\") !== -1\n ) {\n const start = candidateParts[i]!.indexOf(\"}\") + 1,\n end = candidateParts[i]?.length;\n // If the current part of the candidate is a \"template\" part\n // Try to use the suffix of pattern to match the path\n // {guid} ==> $\n // {guid}:export ==> :export$\n const isMatched = new RegExp(\n `${candidateParts[i]?.slice(start, end)}`,\n ).test(pathParts[j] || \"\");\n\n if (!isMatched) {\n found = false;\n break;\n }\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[j]) {\n found = false;\n break;\n }\n }\n\n // We finished evaluating the current candidate parts\n // Update the matched value if and only if we found the longer pattern\n if (found && candidatePath.length > matchedLen) {\n matchedLen = candidatePath.length;\n matchedValue = value;\n }\n }\n\n return matchedValue;\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 type { ClientOptions } from \"@azure-rest/core-client\";\nimport type { AzureKeyCredential, AzureSASCredential, TokenCredential } from \"@azure/core-auth\";\nimport { isSASCredential, isTokenCredential } from \"@azure/core-auth\";\nimport { createMapsClientIdPolicy } from \"@azure/maps-common\";\nimport type { 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-rest/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;\n/**\n * Creates an instance of MapsSearch from an Azure Identity `AzureSASCredential`.\n *\n * @example\n * ```ts\n * import MapsSearch from \"@azure-rest/maps-search\";\n * import { AzureSASCredential } from \"@azure/core-auth\";\n *\n * const credential = new AzureSASCredential(\"<SAS Token>\");\n * const client = MapsSearch(credential);\n * ```\n *\n * @param credential - An AzureSASCredential 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: AzureSASCredential,\n options?: ClientOptions,\n): MapsSearchClient;\nexport default function MapsSearch(\n credential: TokenCredential | AzureKeyCredential | AzureSASCredential,\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 Microsoft Entra ID.\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: \"https://atlas.microsoft.com/.default\",\n }),\n );\n client.pipeline.addPolicy(createMapsClientIdPolicy(clientId));\n return client;\n }\n\n if (isSASCredential(credential)) {\n const client = createClient(undefined as any, options);\n client.pipeline.addPolicy({\n name: \"mapsSASCredentialPolicy\",\n async sendRequest(request, next) {\n request.headers.set(\"Authorization\", `jwt-sas ${credential.signature}`);\n return next(request);\n },\n });\n return client;\n }\n\n return createClient(credential, options);\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport MapsSearch from \"./MapsSearch\";\n\nexport * from \"../generated\";\nexport default MapsSearch;\n"],"names":["createClientLogger","__rest","getClient","isTokenCredential","bearerTokenAuthenticationPolicy","createMapsClientI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GAAG,CAAC,eAAe,EAAE,CAAA,QAAA,EAAW,UAAU,CAAC,SAAS,CAAA,CAAE,CAAC;AACvE,gBAAA,OAAO,IAAI,CAAC,OAAO,CAAC;aACrB;AACF,SAAA,CAAC;AACF,QAAA,OAAO,MAAM;;AAGf,IAAA,OAAO,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC;AAC1C;;AC/GA;AACA;;;;;"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT
|
|
3
|
-
import { isSASCredential, isTokenCredential
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { isSASCredential, isTokenCredential } from "@azure/core-auth";
|
|
4
4
|
import { createMapsClientIdPolicy } from "@azure/maps-common";
|
|
5
|
-
import createClient from "
|
|
5
|
+
import createClient from "../generated";
|
|
6
6
|
import { bearerTokenAuthenticationPolicy } from "@azure/core-rest-pipeline";
|
|
7
7
|
export default function MapsSearch(credential, clientIdOrOptions = {}, maybeOptions = {}) {
|
|
8
8
|
const options = typeof clientIdOrOptions === "string" ? maybeOptions : clientIdOrOptions;
|
|
9
9
|
/**
|
|
10
|
-
* maps service requires a header "ms-x-client-id", which is different from the standard
|
|
10
|
+
* maps service requires a header "ms-x-client-id", which is different from the standard Microsoft Entra ID.
|
|
11
11
|
* So we need to do our own implementation.
|
|
12
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
13
|
*/
|
|
@@ -19,7 +19,7 @@ export default function MapsSearch(credential, clientIdOrOptions = {}, maybeOpti
|
|
|
19
19
|
const client = createClient(undefined, options);
|
|
20
20
|
client.pipeline.addPolicy(bearerTokenAuthenticationPolicy({
|
|
21
21
|
credential,
|
|
22
|
-
scopes:
|
|
22
|
+
scopes: "https://atlas.microsoft.com/.default",
|
|
23
23
|
}));
|
|
24
24
|
client.pipeline.addPolicy(createMapsClientIdPolicy(clientId));
|
|
25
25
|
return client;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapsSearch.js","sourceRoot":"","sources":["../../src/MapsSearch.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;
|
|
1
|
+
{"version":3,"file":"MapsSearch.js","sourceRoot":"","sources":["../../src/MapsSearch.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,YAAY,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AA6D5E,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,UAAqE,EACrE,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,CAAC;QAClC,MAAM,QAAQ,GAAG,OAAO,iBAAiB,KAAK,QAAQ,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC;QAChF,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,KAAK,CAAC,yCAAyC,CAAC,CAAC;QACzD,CAAC;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,sCAAsC;SAC/C,CAAC,CACH,CAAC;QACF,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC9D,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC;QAChC,MAAM,MAAM,GAAG,YAAY,CAAC,SAAgB,EAAE,OAAO,CAAC,CAAC;QACvD,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC;YACxB,IAAI,EAAE,yBAAyB;YAC/B,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI;gBAC7B,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,WAAW,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC;gBACxE,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;YACvB,CAAC;SACF,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ClientOptions } from \"@azure-rest/core-client\";\nimport type { AzureKeyCredential, AzureSASCredential, TokenCredential } from \"@azure/core-auth\";\nimport { isSASCredential, isTokenCredential } from \"@azure/core-auth\";\nimport { createMapsClientIdPolicy } from \"@azure/maps-common\";\nimport type { 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-rest/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;\n/**\n * Creates an instance of MapsSearch from an Azure Identity `AzureSASCredential`.\n *\n * @example\n * ```ts\n * import MapsSearch from \"@azure-rest/maps-search\";\n * import { AzureSASCredential } from \"@azure/core-auth\";\n *\n * const credential = new AzureSASCredential(\"<SAS Token>\");\n * const client = MapsSearch(credential);\n * ```\n *\n * @param credential - An AzureSASCredential 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: AzureSASCredential,\n options?: ClientOptions,\n): MapsSearchClient;\nexport default function MapsSearch(\n credential: TokenCredential | AzureKeyCredential | AzureSASCredential,\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 Microsoft Entra ID.\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: \"https://atlas.microsoft.com/.default\",\n }),\n );\n client.pipeline.addPolicy(createMapsClientIdPolicy(clientId));\n return client;\n }\n\n if (isSASCredential(credential)) {\n const client = createClient(undefined as any, options);\n client.pipeline.addPolicy({\n name: \"mapsSASCredentialPolicy\",\n async sendRequest(request, next) {\n request.headers.set(\"Authorization\", `jwt-sas ${credential.signature}`);\n return next(request);\n },\n });\n return client;\n }\n\n return createClient(credential, options);\n}\n"]}
|
package/dist-esm/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
3
|
import MapsSearch from "./MapsSearch";
|
|
4
|
-
export * from "
|
|
4
|
+
export * from "../generated";
|
|
5
5
|
export default MapsSearch;
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,UAAU,MAAM,cAAc,CAAC;AAEtC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,UAAU,MAAM,cAAc,CAAC;AAEtC,cAAc,cAAc,CAAC;AAC7B,eAAe,UAAU,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport MapsSearch from \"./MapsSearch\";\n\nexport * from \"../generated\";\nexport default MapsSearch;\n"]}
|
package/dist-esm/src/logger.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.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
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.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(\"maps-search\");\n"]}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@azure-rest/maps-search",
|
|
3
3
|
"sdk-type": "client",
|
|
4
4
|
"author": "Microsoft Corporation",
|
|
5
|
-
"version": "2.0.0-beta.
|
|
5
|
+
"version": "2.0.0-beta.2",
|
|
6
6
|
"description": "A generated SDK for MapsSearchClient.",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"node",
|
|
@@ -32,77 +32,73 @@
|
|
|
32
32
|
"node": ">=18.0.0"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
|
-
"
|
|
35
|
+
"build": "npm run clean && tsc -p . && dev-tool run bundle && dev-tool run vendored mkdirp ./review && dev-tool run extract-api",
|
|
36
36
|
"build:browser": "tsc -p . && dev-tool run bundle",
|
|
37
|
+
"build:debug": "tsc -p . && dev-tool run bundle && dev-tool run extract-api",
|
|
37
38
|
"build:node": "tsc -p . && dev-tool run bundle --browser-test false",
|
|
38
39
|
"build:samples": "dev-tool samples publish --force",
|
|
39
40
|
"build:test": "tsc -p . && dev-tool run bundle",
|
|
40
|
-
"build:debug": "tsc -p . && dev-tool run bundle && api-extractor run --local",
|
|
41
41
|
"check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
|
|
42
|
-
"clean": "rimraf dist dist-browser dist-esm test-dist temp types *.tgz *.log",
|
|
42
|
+
"clean": "dev-tool run vendored rimraf --glob dist dist-browser dist-esm test-dist temp types *.tgz *.log",
|
|
43
43
|
"execute:samples": "dev-tool samples run samples-dev",
|
|
44
|
-
"extract-api": "rimraf review && mkdirp ./review &&
|
|
44
|
+
"extract-api": "dev-tool run vendored rimraf review && dev-tool run vendored mkdirp ./review && dev-tool run extract-api",
|
|
45
45
|
"format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
|
|
46
46
|
"generate:client": "autorest --typescript swagger/README.md && npm run format",
|
|
47
|
+
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
|
|
47
48
|
"integration-test:browser": "dev-tool run test:browser",
|
|
48
49
|
"integration-test:node": "dev-tool run test:node-js-input -- --timeout 5000000 'dist-esm/test/**/*.spec.js'",
|
|
49
|
-
"
|
|
50
|
-
"lint:fix": "eslint package.json api-extractor.json src test --
|
|
51
|
-
"lint": "eslint package.json api-extractor.json src test --ext .ts",
|
|
50
|
+
"lint": "eslint package.json api-extractor.json src test",
|
|
51
|
+
"lint:fix": "eslint package.json api-extractor.json src test --fix --fix-type [problem,suggestion]",
|
|
52
52
|
"pack": "npm pack 2>&1",
|
|
53
|
+
"test": "npm run clean && npm run build:test && npm run unit-test",
|
|
53
54
|
"test:browser": "npm run clean && npm run build:test && npm run unit-test:browser",
|
|
54
55
|
"test:node": "npm run clean && npm run build:test && npm run unit-test:node",
|
|
55
|
-
"test": "npm run clean && npm run build:test && npm run unit-test",
|
|
56
56
|
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
|
|
57
|
-
"unit-test:node": "dev-tool run test:node-ts-input -- --timeout 1200000 --exclude 'test/**/browser/*.spec.ts' 'test/**/*.spec.ts'",
|
|
58
57
|
"unit-test:browser": "dev-tool run test:browser",
|
|
59
|
-
"
|
|
58
|
+
"unit-test:node": "dev-tool run test:node-ts-input -- --timeout 1200000 --exclude 'test/**/browser/*.spec.ts' 'test/**/*.spec.ts'",
|
|
59
|
+
"update-snippets": "echo skipped"
|
|
60
60
|
},
|
|
61
61
|
"sideEffects": false,
|
|
62
62
|
"autoPublish": false,
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@azure/core-auth": "^1.3.0",
|
|
65
64
|
"@azure-rest/core-client": "^1.0.0",
|
|
66
|
-
"@azure/core-
|
|
67
|
-
"tslib": "^2.2.0",
|
|
65
|
+
"@azure/core-auth": "^1.3.0",
|
|
68
66
|
"@azure/core-lro": "^2.2.0",
|
|
67
|
+
"@azure/core-rest-pipeline": "^1.8.0",
|
|
68
|
+
"@azure/logger": "^1.0.4",
|
|
69
69
|
"@azure/maps-common": "1.0.0-beta.2",
|
|
70
|
-
"
|
|
70
|
+
"tslib": "^2.2.0"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@microsoft/api-extractor": "^7.31.1",
|
|
74
|
-
"autorest": "latest",
|
|
75
|
-
"@types/node": "^18.0.0",
|
|
76
|
-
"dotenv": "^16.0.0",
|
|
77
|
-
"eslint": "^8.0.0",
|
|
78
|
-
"mkdirp": "^1.0.4",
|
|
79
|
-
"rimraf": "^3.0.0",
|
|
80
|
-
"source-map-support": "^0.5.9",
|
|
81
|
-
"typescript": "~5.2.0",
|
|
82
|
-
"@azure/dev-tool": "^1.0.0",
|
|
83
|
-
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
|
|
84
73
|
"@azure-tools/test-credential": "^1.0.0",
|
|
85
|
-
"@azure/identity": "^3.3.0",
|
|
86
74
|
"@azure-tools/test-recorder": "^3.0.0",
|
|
87
|
-
"
|
|
88
|
-
"@
|
|
89
|
-
"
|
|
75
|
+
"@azure-tools/test-utils": "~1.0.0",
|
|
76
|
+
"@azure/core-util": "^1.9.0",
|
|
77
|
+
"@azure/dev-tool": "^1.0.0",
|
|
78
|
+
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
|
|
79
|
+
"@azure/identity": "^4.0.1",
|
|
90
80
|
"@types/chai": "^4.2.8",
|
|
81
|
+
"@types/mocha": "^10.0.0",
|
|
82
|
+
"@types/node": "^18.0.0",
|
|
83
|
+
"autorest": "latest",
|
|
91
84
|
"chai": "^4.2.0",
|
|
85
|
+
"dotenv": "^16.0.0",
|
|
86
|
+
"eslint": "^9.9.0",
|
|
87
|
+
"karma": "^6.2.0",
|
|
92
88
|
"karma-chrome-launcher": "^3.0.0",
|
|
93
89
|
"karma-coverage": "^2.0.0",
|
|
94
90
|
"karma-env-preprocessor": "^0.1.1",
|
|
95
91
|
"karma-firefox-launcher": "^1.1.0",
|
|
96
92
|
"karma-junit-reporter": "^2.0.1",
|
|
97
|
-
"karma-mocha-reporter": "^2.2.5",
|
|
98
93
|
"karma-mocha": "^2.0.1",
|
|
94
|
+
"karma-mocha-reporter": "^2.2.5",
|
|
99
95
|
"karma-source-map-support": "~1.4.0",
|
|
100
96
|
"karma-sourcemap-loader": "^0.3.8",
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
"
|
|
97
|
+
"mocha": "^10.0.0",
|
|
98
|
+
"nyc": "^17.0.0",
|
|
99
|
+
"source-map-support": "^0.5.9",
|
|
104
100
|
"ts-node": "^10.0.0",
|
|
105
|
-
"
|
|
101
|
+
"typescript": "~5.6.2"
|
|
106
102
|
},
|
|
107
103
|
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/maps/maps-search-rest/README.md",
|
|
108
104
|
"//metadata": {
|