@azure-rest/maps-geolocation 1.0.0-beta.2 → 1.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,7 +16,7 @@ Key links:
16
16
 
17
17
  ### Currently supported environments
18
18
 
19
- - [LTS versions of Node.js](https://nodejs.org/about/releases/)
19
+ - [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
20
20
  - Latest versions of Safari, Chrome, Edge and Firefox.
21
21
 
22
22
  ### Prerequisites
@@ -40,21 +40,21 @@ npm install @azure-rest/maps-geolocation
40
40
 
41
41
  ### Create and authenticate a `MapsGeolocationClient`
42
42
 
43
- You'll need a `credential` instance for authentication when creating the `MapsGeolocationClient` instance used to access the Azure Maps render APIs. You can use either an Azure Active Directory (Azure AD) credential or an Azure subscription key to authenticate. For more information on authentication, see [Authentication with Azure Maps][az_map_auth].
43
+ You'll need a `credential` instance for authentication when creating the `MapsGeolocationClient` instance used to access the Azure Maps render APIs. You can use either a Microsoft Entra ID credential or an Azure subscription key to authenticate. For more information on authentication, see [Authentication with Azure Maps][az_map_auth].
44
44
 
45
- #### Using an Azure AD credential
45
+ #### Using an Microsoft Entra ID credential
46
46
 
47
- To use an [Azure Active Directory (AAD) token credential](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token),
47
+ To use an [Microsoft Entra ID token credential](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token),
48
48
  provide an instance of the desired credential type obtained from the
49
49
  [@azure/identity](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) library.
50
50
 
51
- To authenticate with AAD, you must first `npm` install [`@azure/identity`](https://www.npmjs.com/package/@azure/identity)
51
+ To authenticate with Microsoft Entra ID, you must first `npm` install [`@azure/identity`](https://www.npmjs.com/package/@azure/identity)
52
52
 
53
53
  After setup, you can choose which type of [credential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) from `@azure/identity` to use.
54
54
  As an example, [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential)
55
55
  can be used to authenticate the client.
56
56
 
57
- You'll need to register the new Azure AD application and grant access to Azure Maps by assigning the required role to your service principal. For more information, see [Host a daemon on non-Azure resources](https://learn.microsoft.com/azure/azure-maps/how-to-secure-daemon-app#host-a-daemon-on-non-azure-resources). Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
57
+ You'll need to register the new Microsoft Entra ID application and grant access to Azure Maps by assigning the required role to your service principal. For more information, see [Host a daemon on non-Azure resources](https://learn.microsoft.com/azure/azure-maps/how-to-secure-daemon-app#host-a-daemon-on-non-azure-resources). Set the values of the client ID, tenant ID, and client secret of the Microsoft Entra ID application as environment variables:
58
58
  `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`.
59
59
 
60
60
  You will also need to specify the Azure Maps resource you intend to use by specifying the `clientId` in the client options.
@@ -69,7 +69,7 @@ const client = MapsGeolocation(credential, "<maps-account-client-id>");
69
69
 
70
70
  #### Using a Subscription Key Credential
71
71
 
72
- You can authenticate with your Azure Maps Subscription Key. Please install the `@azure/core-auth` package:
72
+ You can authenticate with your Azure Maps Subscription Key. Please install the["@azure/core-auth"](https://www.npmjs.com/package/@azure/core-auth)package:
73
73
 
74
74
  ```bash
75
75
  npm install @azure/core-auth
@@ -82,6 +82,52 @@ const credential = new AzureKeyCredential("<subscription-key>");
82
82
  const client = MapsGeolocation(credential);
83
83
  ```
84
84
 
85
+ #### Using a Shared Access Signature (SAS) Token Credential
86
+
87
+ Shared access signature (SAS) tokens are authentication tokens created using the JSON Web token (JWT) format and are cryptographically signed to prove authentication for an application to the Azure Maps REST API.
88
+
89
+ You can get the SAS token using [`AzureMapsManagementClient.accounts.listSas`](https://learn.microsoft.com/javascript/api/%40azure/arm-maps/accounts?view=azure-node-latest#@azure-arm-maps-accounts-listsas) from ["@azure/arm-maps"](https://www.npmjs.com/package/@azure/arm-maps) package. Please follow the section [Create and authenticate a `AzureMapsManagementClient`](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/maps/arm-maps#create-and-authenticate-a-azuremapsmanagementclient) to setup first.
90
+
91
+ Second, follow [Managed identities for Azure Maps](https://techcommunity.microsoft.com/t5/azure-maps-blog/managed-identities-for-azure-maps/ba-p/3666312) to create a managed identity for your Azure Maps account. Copy the principal ID (object ID) of the managed identity.
92
+
93
+ Third, you will need to install["@azure/core-auth"](https://www.npmjs.com/package/@azure/core-auth)package to use `AzureSASCredential`:
94
+
95
+ ```bash
96
+ npm install @azure/core-auth
97
+ ```
98
+
99
+ Finally, you can use the SAS token to authenticate the client:
100
+
101
+ ```javascript
102
+ const MapsGeolocation = require("@azure-rest/maps-geolocation").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 = MapsGeolocation(sasCredential);
129
+ ```
130
+
85
131
  ## Key concepts
86
132
 
87
133
  ### MapsGeolocationClient
package/dist/index.js CHANGED
@@ -4,36 +4,58 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var coreAuth = require('@azure/core-auth');
6
6
  var mapsCommon = require('@azure/maps-common');
7
+ var tslib = require('tslib');
7
8
  var coreClient = require('@azure-rest/core-client');
9
+ var logger$1 = require('@azure/logger');
8
10
  var coreRestPipeline = require('@azure/core-rest-pipeline');
9
11
 
10
12
  // Copyright (c) Microsoft Corporation.
13
+ // Licensed under the MIT License.
14
+ const logger = logger$1.createClientLogger("maps-geolocation");
15
+
16
+ // Copyright (c) Microsoft Corporation.
17
+ // Licensed under the MIT License.
11
18
  /**
12
- * Initialize a new instance of the class MapsGeolocationClient class.
13
- * @param credentials type: KeyCredential
19
+ * Initialize a new instance of `MapsGeolocationClient`
20
+ * @param credentials - uniquely identify client credential
21
+ * @param options - the parameter for all optional parameters
14
22
  */
15
- function createClient(credentials, options = {}) {
16
- var _a, _b;
17
- const baseUrl = (_a = options.baseUrl) !== null && _a !== void 0 ? _a : `https://atlas.microsoft.com`;
18
- options.apiVersion = (_b = options.apiVersion) !== null && _b !== void 0 ? _b : "1.0";
19
- options = Object.assign(Object.assign({}, options), { credentials: {
20
- apiKeyHeaderName: "subscription-key"
21
- } });
22
- const userAgentInfo = `azsdk-js-maps-geolocation-rest/1.0.0-beta.1`;
23
+ function createClient(credentials, _a = {}) {
24
+ var _b, _c, _d, _e, _f, _g;
25
+ var { apiVersion = "1.0" } = _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-geolocation-rest/1.0.0-beta.4`;
23
28
  const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
24
29
  ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
25
30
  : `${userAgentInfo}`;
26
31
  options = Object.assign(Object.assign({}, options), { userAgentOptions: {
27
- userAgentPrefix
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",
28
37
  } });
29
- const client = coreClient.getClient(baseUrl, credentials, options);
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);
50
+ },
51
+ });
30
52
  return client;
31
53
  }
32
54
 
33
55
  // Copyright (c) Microsoft Corporation.
34
- // Licensed under the MIT license.
56
+ // Licensed under the MIT License.
35
57
  const responseMap = {
36
- "GET /geolocation/ip/{format}": ["200"]
58
+ "GET /geolocation/ip/{format}": ["200"],
37
59
  };
38
60
  function isUnexpected(response) {
39
61
  const lroOriginal = response.headers["x-ms-original-url"];
@@ -41,13 +63,17 @@ function isUnexpected(response) {
41
63
  const method = response.request.method;
42
64
  let pathDetails = responseMap[`${method} ${url.pathname}`];
43
65
  if (!pathDetails) {
44
- pathDetails = geParametrizedPathSuccess(method, url.pathname);
66
+ pathDetails = getParametrizedPathSuccess(method, url.pathname);
45
67
  }
46
68
  return !pathDetails.includes(response.status);
47
69
  }
48
- function geParametrizedPathSuccess(method, path) {
49
- var _a, _b;
70
+ function getParametrizedPathSuccess(method, path) {
71
+ var _a, _b, _c, _d;
50
72
  const pathParts = path.split("/");
73
+ // Traverse list to match the longest candidate
74
+ // matchedLen: the length of candidate path
75
+ // matchedValue: the matched status code array
76
+ let matchedLen = -1, matchedValue = [];
51
77
  // Iterate the responseMap to find a match
52
78
  for (const [key, value] of Object.entries(responseMap)) {
53
79
  // Extracting the path from the map key which is in format
@@ -58,41 +84,39 @@ function geParametrizedPathSuccess(method, path) {
58
84
  const candidatePath = getPathFromMapKey(key);
59
85
  // Get each part of the url path
60
86
  const candidateParts = candidatePath.split("/");
61
- // If the candidate and actual paths don't match in size
62
- // we move on to the next candidate path
63
- if (candidateParts.length === pathParts.length &&
64
- hasParametrizedPath(key)) {
65
- // track if we have found a match to return the values found.
66
- let found = true;
67
- for (let i = 0; i < candidateParts.length; i++) {
68
- if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) &&
69
- ((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.endsWith("}"))) {
70
- // If the current part of the candidate is a "template" part
71
- // it is a match with the actual path part on hand
72
- // skip as the parameterized part can match anything
73
- continue;
74
- }
75
- // If the candidate part is not a template and
76
- // the parts don't match mark the candidate as not found
77
- // to move on with the next candidate path.
78
- if (candidateParts[i] !== pathParts[i]) {
87
+ // track if we have found a match to return the values found.
88
+ let found = true;
89
+ for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
90
+ if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) &&
91
+ ((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.indexOf("}")) !== -1) {
92
+ const start = candidateParts[i].indexOf("}") + 1, end = (_c = candidateParts[i]) === null || _c === void 0 ? void 0 : _c.length;
93
+ // If the current part of the candidate is a "template" part
94
+ // Try to use the suffix of pattern to match the path
95
+ // {guid} ==> $
96
+ // {guid}:export ==> :export$
97
+ const isMatched = new RegExp(`${(_d = candidateParts[i]) === null || _d === void 0 ? void 0 : _d.slice(start, end)}`).test(pathParts[j] || "");
98
+ if (!isMatched) {
79
99
  found = false;
80
100
  break;
81
101
  }
102
+ continue;
82
103
  }
83
- // We finished evaluating the current candidate parts
84
- // if all parts matched we return the success values form
85
- // the path mapping.
86
- if (found) {
87
- return value;
104
+ // If the candidate part is not a template and
105
+ // the parts don't match mark the candidate as not found
106
+ // to move on with the next candidate path.
107
+ if (candidateParts[i] !== pathParts[j]) {
108
+ found = false;
109
+ break;
88
110
  }
89
111
  }
112
+ // We finished evaluating the current candidate parts
113
+ // Update the matched value if and only if we found the longer pattern
114
+ if (found && candidatePath.length > matchedLen) {
115
+ matchedLen = candidatePath.length;
116
+ matchedValue = value;
117
+ }
90
118
  }
91
- // No match was found, return an empty array.
92
- return [];
93
- }
94
- function hasParametrizedPath(path) {
95
- return path.includes("/{");
119
+ return matchedValue;
96
120
  }
97
121
  function getPathFromMapKey(mapKey) {
98
122
  const pathStart = mapKey.indexOf("/");
@@ -100,10 +124,11 @@ function getPathFromMapKey(mapKey) {
100
124
  }
101
125
 
102
126
  // Copyright (c) Microsoft Corporation.
127
+ // Licensed under the MIT License.
103
128
  function MapsGeolocation(credential, clientIdOrOptions = {}, maybeOptions = {}) {
104
129
  const options = typeof clientIdOrOptions === "string" ? maybeOptions : clientIdOrOptions;
105
130
  /**
106
- * maps service requires a header "ms-x-client-id", which is different from the standard AAD.
131
+ * maps service requires a header "ms-x-client-id", which is different from the standard Microsoft Entra ID.
107
132
  * So we need to do our own implementation.
108
133
  * This customized authentication is following by this guide: https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/RLC-customization.md#custom-authentication
109
134
  */
@@ -115,16 +140,28 @@ function MapsGeolocation(credential, clientIdOrOptions = {}, maybeOptions = {})
115
140
  const client = createClient(undefined, options);
116
141
  client.pipeline.addPolicy(coreRestPipeline.bearerTokenAuthenticationPolicy({
117
142
  credential,
118
- scopes: `${options.baseUrl || "https://atlas.microsoft.com"}/.default`,
143
+ scopes: "https://atlas.microsoft.com/.default",
119
144
  }));
120
145
  client.pipeline.addPolicy(mapsCommon.createMapsClientIdPolicy(clientId));
121
146
  return client;
122
147
  }
148
+ if (coreAuth.isSASCredential(credential)) {
149
+ const client = createClient(undefined, options);
150
+ client.pipeline.addPolicy({
151
+ name: "mapsSASCredentialPolicy",
152
+ async sendRequest(request, next) {
153
+ request.headers.set("Authorization", `jwt-sas ${credential.signature}`);
154
+ return next(request);
155
+ },
156
+ });
157
+ return client;
158
+ }
123
159
  return createClient(credential, options);
124
160
  }
125
161
 
126
162
  // Copyright (c) Microsoft Corporation.
163
+ // Licensed under the MIT License.
127
164
 
128
- exports["default"] = MapsGeolocation;
165
+ exports.default = MapsGeolocation;
129
166
  exports.isUnexpected = isUnexpected;
130
167
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/generated/mapsGeolocationClient.ts","../src/generated/isUnexpected.ts","../src/MapsGeolocation.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 { MapsGeolocationClient } from \"./clientDefinitions\";\n\n/**\n * Initialize a new instance of the class MapsGeolocationClient class.\n * @param credentials type: KeyCredential\n */\nexport default function createClient(\n credentials: KeyCredential,\n options: ClientOptions = {}\n): MapsGeolocationClient {\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-geolocation-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(\n baseUrl,\n credentials,\n options\n ) as MapsGeolocationClient;\n\n return client;\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n GeolocationGetLocation200Response,\n GeolocationGetLocationDefaultResponse\n} from \"./responses\";\n\nconst responseMap: Record<string, string[]> = {\n \"GET /geolocation/ip/{format}\": [\"200\"]\n};\n\nexport function isUnexpected(\n response:\n | GeolocationGetLocation200Response\n | GeolocationGetLocationDefaultResponse\n): response is GeolocationGetLocationDefaultResponse;\nexport function isUnexpected(\n response:\n | GeolocationGetLocation200Response\n | GeolocationGetLocationDefaultResponse\n): response is GeolocationGetLocationDefaultResponse {\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 { ClientOptions } from \"@azure-rest/core-client\";\nimport { AzureKeyCredential, TokenCredential, isTokenCredential } from \"@azure/core-auth\";\nimport { createMapsClientIdPolicy } from \"@azure/maps-common\";\nimport { MapsGeolocationClient } from \"./generated\";\nimport createClient from \"./generated\";\nimport { bearerTokenAuthenticationPolicy } from \"@azure/core-rest-pipeline\";\n\n/**\n * Creates an instance of MapsGeolocationClient from a subscription key.\n *\n * @example\n * ```ts\n * import MapsGeolocation from \"@azure-rest/maps-geolocation\";\n * import { AzureKeyCredential } from \"@azure/core-auth\";\n *\n * const credential = new AzureKeyCredential(\"<subscription-key>\");\n * const client = MapsGeolocation(credential);\n *```\n *\n * @param credential - An AzureKeyCredential instance used to authenticate requests to the service\n * @param options - Options used to configure the Geolocation Client\n */\nexport default function MapsGeolocation(\n credential: AzureKeyCredential,\n options?: ClientOptions\n): MapsGeolocationClient;\n/**\n * Creates an instance of MapsGeolocation from an Azure Identity `TokenCredential`.\n *\n * @example\n * ```ts\n * import MapsGeolocation from \"@azure/maps-geo-location\";\n * import { DefaultAzureCredential } from \"@azure/identity\";\n *\n * const credential = new DefaultAzureCredential();\n * const client = MapsGeolocation(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 Route Client\n */\nexport default function MapsGeolocation(\n credential: TokenCredential,\n mapsAccountClientId: string,\n options?: ClientOptions\n): MapsGeolocationClient;\nexport default function MapsGeolocation(\n credential: TokenCredential | AzureKeyCredential,\n clientIdOrOptions: string | ClientOptions = {},\n maybeOptions: ClientOptions = {}\n): MapsGeolocationClient {\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 MapsGeolocation from \"./MapsGeolocation\";\n\nexport * from \"./generated\";\nexport default MapsGeolocation;\n"],"names":["getClient","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,KAAA,KAAA,CAAA,GAAA,EAAA,GAAI,6BAA6B,CAAC;IACjE,OAAO,CAAC,UAAU,GAAG,CAAA,EAAA,GAAA,OAAO,CAAC,UAAU,MAAI,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAA,KAAK,CAAC;AACjD,IAAA,OAAO,GACF,MAAA,CAAA,MAAA,CAAA,MAAA,CA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AA;AACvE,SAAA,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;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../generated/logger.ts","../generated/mapsGeolocationClient.ts","../generated/isUnexpected.ts","../src/MapsGeolocation.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-geolocation\");\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 { MapsGeolocationClient } from \"./clientDefinitions\";\n\n/** The optional parameters for the client */\nexport interface MapsGeolocationClientOptions extends ClientOptions {\n /** The api version option of the client */\n apiVersion?: string;\n}\n\n/**\n * Initialize a new instance of `MapsGeolocationClient`\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 = \"1.0\", ...options }: MapsGeolocationClientOptions = {},\n): MapsGeolocationClient {\n const endpointUrl =\n options.endpoint ?? options.baseUrl ?? `https://atlas.microsoft.com`;\n const userAgentInfo = `azsdk-js-maps-geolocation-rest/1.0.0-beta.4`;\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 MapsGeolocationClient;\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 GeolocationGetLocation200Response,\n GeolocationGetLocationDefaultResponse,\n} from \"./responses\";\n\nconst responseMap: Record<string, string[]> = {\n \"GET /geolocation/ip/{format}\": [\"200\"],\n};\n\nexport function isUnexpected(\n response:\n | GeolocationGetLocation200Response\n | GeolocationGetLocationDefaultResponse,\n): response is GeolocationGetLocationDefaultResponse;\nexport function isUnexpected(\n response:\n | GeolocationGetLocation200Response\n | GeolocationGetLocationDefaultResponse,\n): response is GeolocationGetLocationDefaultResponse {\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 { MapsGeolocationClient } from \"../generated\";\nimport createClient from \"../generated\";\nimport { bearerTokenAuthenticationPolicy } from \"@azure/core-rest-pipeline\";\n\n/**\n * Creates an instance of MapsGeolocationClient from a subscription key.\n *\n * @example\n * ```ts\n * import MapsGeolocation from \"@azure-rest/maps-geolocation\";\n * import { AzureKeyCredential } from \"@azure/core-auth\";\n *\n * const credential = new AzureKeyCredential(\"<subscription-key>\");\n * const client = MapsGeolocation(credential);\n *```\n *\n * @param credential - An AzureKeyCredential instance used to authenticate requests to the service\n * @param options - Options used to configure the Geolocation Client\n */\nexport default function MapsGeolocation(\n credential: AzureKeyCredential,\n options?: ClientOptions,\n): MapsGeolocationClient;\n/**\n * Creates an instance of MapsGeolocation from an Azure Identity `TokenCredential`.\n *\n * @example\n * ```ts\n * import MapsGeolocation from \"@azure-rest/maps-geo-location\";\n * import { DefaultAzureCredential } from \"@azure/identity\";\n *\n * const credential = new DefaultAzureCredential();\n * const client = MapsGeolocation(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 Route Client\n */\nexport default function MapsGeolocation(\n credential: TokenCredential,\n mapsAccountClientId: string,\n options?: ClientOptions,\n): MapsGeolocationClient;\n/**\n * Creates an instance of MapsGeolocation from an Azure Identity `AzureSASCredential`.\n *\n * @example\n * ```ts\n * import MapsGeolocation from \"@azure-rest/maps-geo-location\";\n * import { AzureSASCredential } from \"@azure/core-auth\";\n *\n * const credential = new AzureSASCredential(\"<SAS Token>\");\n * const client = MapsGeolocation(credential);\n * ```\n *\n * @param credential - An AzureSASCredential instance used to authenticate requests to the service\n * @param options - Options used to configure the Geolocation Client\n */\nexport default function MapsGeolocation(\n credential: AzureSASCredential,\n options?: ClientOptions,\n): MapsGeolocationClient;\nexport default function MapsGeolocation(\n credential: TokenCredential | AzureKeyCredential | AzureSASCredential,\n clientIdOrOptions: string | ClientOptions = {},\n maybeOptions: ClientOptions = {},\n): MapsGeolocationClient {\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.\n\nimport MapsGeolocation from \"./MapsGeolocation\";\n\nexport * from \"../generated\";\nexport default MapsGeolocation;\n"],"names":["createClientLogger","__rest","getClient","isTokenCredential","bearerTokenAuthenticationPolicy","createMapsClientIdPolicy","isSASCredential"],"mappings":";;;;;;;;;;;AAAA;AACA;AAGO,MAAM,MAAM,GAAGA,2BAAkB,CAAC,kBAAkB,CAAC;;ACJ5D;AACA;AAaA;;;;AAIG;AACqB,SAAA,YAAY,CAClC,WAA0B,EAC1B,KAAmE,EAAE,EAAA;;QAArE,EAAE,UAAU,GAAG,KAAK,EAAA,GAAA,EAAiD,EAA5C,OAAO,GAAAC,YAAA,CAAA,EAAA,EAAhC,cAAkC,CAAF;AAEhC,IAAA,MAAM,WAAW,GACf,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,OAAO,CAAC,QAAQ,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAI,OAAO,CAAC,OAAO,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAI,6BAA6B;IACtE,MAAM,aAAa,GAAG,CAAA,2CAAA,CAA6C;IACnE,MAAM,eAAe,GACnB,OAAO,CAAC,gBAAgB,IAAI,OAAO,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U;AACV,YAAA,MAAM,EAAE,sCAAsC;AAC/C,SAAA,CAAC,CACH;QACD,MAAM,CAAC,QAAQ,CAAC,SAAS,CAACC,mCAAwB,CAAC,QAAQ,CAAC,CAAC;AAC7D,QAAA,OAAO,MAAM;;AAGf,IAAA,IAAIC,wBAAe,CAAC,UAAU,CAAC,EAAE;QAC/B,MAAM,MAAM,GAAG,YAAY,CAAC,SAAgB,EAAE,OAAO,CAAC;AACtD,QAAA,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC;AACxB,YAAA,IAAI,EAAE,yBAAyB;AAC/B,YAAA,MAAM,WAAW,CAAC,OAAO,EAAE,IAAI,EAAA;AAC7B,gBAAA,OAAO,CAAC,OAAO,CAAC,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 license.
3
- import { isTokenCredential } from "@azure/core-auth";
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 "./generated";
5
+ import createClient from "../generated";
6
6
  import { bearerTokenAuthenticationPolicy } from "@azure/core-rest-pipeline";
7
7
  export default function MapsGeolocation(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 AAD.
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,11 +19,22 @@ export default function MapsGeolocation(credential, clientIdOrOptions = {}, mayb
19
19
  const client = createClient(undefined, options);
20
20
  client.pipeline.addPolicy(bearerTokenAuthenticationPolicy({
21
21
  credential,
22
- scopes: `${options.baseUrl || "https://atlas.microsoft.com"}/.default`,
22
+ scopes: "https://atlas.microsoft.com/.default",
23
23
  }));
24
24
  client.pipeline.addPolicy(createMapsClientIdPolicy(clientId));
25
25
  return client;
26
26
  }
27
+ if (isSASCredential(credential)) {
28
+ const client = createClient(undefined, options);
29
+ client.pipeline.addPolicy({
30
+ name: "mapsSASCredentialPolicy",
31
+ async sendRequest(request, next) {
32
+ request.headers.set("Authorization", `jwt-sas ${credential.signature}`);
33
+ return next(request);
34
+ },
35
+ });
36
+ return client;
37
+ }
27
38
  return createClient(credential, options);
28
39
  }
29
40
  //# sourceMappingURL=MapsGeolocation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MapsGeolocation.js","sourceRoot":"","sources":["../../src/MapsGeolocation.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,eAAe,CACrC,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 { MapsGeolocationClient } from \"./generated\";\nimport createClient from \"./generated\";\nimport { bearerTokenAuthenticationPolicy } from \"@azure/core-rest-pipeline\";\n\n/**\n * Creates an instance of MapsGeolocationClient from a subscription key.\n *\n * @example\n * ```ts\n * import MapsGeolocation from \"@azure-rest/maps-geolocation\";\n * import { AzureKeyCredential } from \"@azure/core-auth\";\n *\n * const credential = new AzureKeyCredential(\"<subscription-key>\");\n * const client = MapsGeolocation(credential);\n *```\n *\n * @param credential - An AzureKeyCredential instance used to authenticate requests to the service\n * @param options - Options used to configure the Geolocation Client\n */\nexport default function MapsGeolocation(\n credential: AzureKeyCredential,\n options?: ClientOptions\n): MapsGeolocationClient;\n/**\n * Creates an instance of MapsGeolocation from an Azure Identity `TokenCredential`.\n *\n * @example\n * ```ts\n * import MapsGeolocation from \"@azure/maps-geo-location\";\n * import { DefaultAzureCredential } from \"@azure/identity\";\n *\n * const credential = new DefaultAzureCredential();\n * const client = MapsGeolocation(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 Route Client\n */\nexport default function MapsGeolocation(\n credential: TokenCredential,\n mapsAccountClientId: string,\n options?: ClientOptions\n): MapsGeolocationClient;\nexport default function MapsGeolocation(\n credential: TokenCredential | AzureKeyCredential,\n clientIdOrOptions: string | ClientOptions = {},\n maybeOptions: ClientOptions = {}\n): MapsGeolocationClient {\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"]}
1
+ {"version":3,"file":"MapsGeolocation.js","sourceRoot":"","sources":["../../src/MapsGeolocation.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,MAA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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 { MapsGeolocationClient } from \"../generated\";\nimport createClient from \"../generated\";\nimport { bearerTokenAuthenticationPolicy } from \"@azure/core-rest-pipeline\";\n\n/**\n * Creates an instance of MapsGeolocationClient from a subscription key.\n *\n * @example\n * ```ts\n * import MapsGeolocation from \"@azure-rest/maps-geolocation\";\n * import { AzureKeyCredential } from \"@azure/core-auth\";\n *\n * const credential = new AzureKeyCredential(\"<subscription-key>\");\n * const client = MapsGeolocation(credential);\n *```\n *\n * @param credential - An AzureKeyCredential instance used to authenticate requests to the service\n * @param options - Options used to configure the Geolocation Client\n */\nexport default function MapsGeolocation(\n credential: AzureKeyCredential,\n options?: ClientOptions,\n): MapsGeolocationClient;\n/**\n * Creates an instance of MapsGeolocation from an Azure Identity `TokenCredential`.\n *\n * @example\n * ```ts\n * import MapsGeolocation from \"@azure-rest/maps-geo-location\";\n * import { DefaultAzureCredential } from \"@azure/identity\";\n *\n * const credential = new DefaultAzureCredential();\n * const client = MapsGeolocation(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 Route Client\n */\nexport default function MapsGeolocation(\n credential: TokenCredential,\n mapsAccountClientId: string,\n options?: ClientOptions,\n): MapsGeolocationClient;\n/**\n * Creates an instance of MapsGeolocation from an Azure Identity `AzureSASCredential`.\n *\n * @example\n * ```ts\n * import MapsGeolocation from \"@azure-rest/maps-geo-location\";\n * import { AzureSASCredential } from \"@azure/core-auth\";\n *\n * const credential = new AzureSASCredential(\"<SAS Token>\");\n * const client = MapsGeolocation(credential);\n * ```\n *\n * @param credential - An AzureSASCredential instance used to authenticate requests to the service\n * @param options - Options used to configure the Geolocation Client\n */\nexport default function MapsGeolocation(\n credential: AzureSASCredential,\n options?: ClientOptions,\n): MapsGeolocationClient;\nexport default function MapsGeolocation(\n credential: TokenCredential | AzureKeyCredential | AzureSASCredential,\n clientIdOrOptions: string | ClientOptions = {},\n maybeOptions: ClientOptions = {},\n): MapsGeolocationClient {\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"]}
@@ -1,6 +1,6 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT license.
2
+ // Licensed under the MIT License.
3
3
  import MapsGeolocation from "./MapsGeolocation";
4
- export * from "./generated";
4
+ export * from "../generated";
5
5
  export default MapsGeolocation;
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;AAElC,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAEhD,cAAc,aAAa,CAAC;AAC5B,eAAe,eAAe,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport MapsGeolocation from \"./MapsGeolocation\";\n\nexport * from \"./generated\";\nexport default MapsGeolocation;\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAEhD,cAAc,cAAc,CAAC;AAC7B,eAAe,eAAe,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport MapsGeolocation from \"./MapsGeolocation\";\n\nexport * from \"../generated\";\nexport default MapsGeolocation;\n"]}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@azure-rest/maps-geolocation",
3
3
  "sdk-type": "client",
4
4
  "author": "Microsoft Corporation",
5
- "version": "1.0.0-beta.2",
5
+ "version": "1.0.0-beta.4",
6
6
  "description": "A generated SDK for MapsGeolocationClient.",
7
7
  "keywords": [
8
8
  "node",
@@ -29,78 +29,75 @@
29
29
  "review/*"
30
30
  ],
31
31
  "engines": {
32
- "node": ">=14.0.0"
32
+ "node": ">=18.0.0"
33
33
  },
34
34
  "scripts": {
35
- "audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
36
- "build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1",
37
- "build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1",
35
+ "build": "npm run clean && tsc -p . && dev-tool run bundle && dev-tool run vendored mkdirp ./review && dev-tool run extract-api",
36
+ "build:browser": "tsc -p . && dev-tool run bundle",
37
+ "build:debug": "tsc -p . && dev-tool run bundle && dev-tool run extract-api",
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
- "check-format": "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",
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": "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 && api-extractor run --local",
45
- "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
44
+ "extract-api": "dev-tool run vendored rimraf review && dev-tool run vendored mkdirp ./review && dev-tool run extract-api",
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
- "integration-test": "npm run integration-test:node && npm run integration-test:browser",
50
- "lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]",
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
- "build": "npm run clean && tsc -p . && dev-tool run bundle && mkdirp ./review && api-extractor run --local"
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-rest/core-client": "^1.0.0",
64
65
  "@azure/core-auth": "^1.3.0",
65
- "@azure-rest/core-client": "1.0.0-beta.10",
66
66
  "@azure/core-rest-pipeline": "^1.8.0",
67
67
  "@azure/maps-common": "1.0.0-beta.2",
68
+ "@azure/logger": "^1.0.0",
68
69
  "tslib": "^2.2.0"
69
70
  },
70
71
  "devDependencies": {
71
- "@microsoft/api-extractor": "^7.31.1",
72
- "autorest": "latest",
73
- "@types/node": "^14.0.0",
74
- "dotenv": "^16.0.0",
75
- "eslint": "^8.0.0",
76
- "mkdirp": "^1.0.4",
77
- "prettier": "^2.5.1",
78
- "rimraf": "^3.0.0",
79
- "source-map-support": "^0.5.9",
80
- "typescript": "~5.0.0",
81
- "@azure/dev-tool": "^1.0.0",
82
- "@azure/eslint-plugin-azure-sdk": "^3.0.0",
83
72
  "@azure-tools/test-credential": "^1.0.0",
84
- "@azure/identity": "^2.0.1",
85
73
  "@azure-tools/test-recorder": "^3.0.0",
86
- "mocha": "^7.1.1",
87
- "@types/mocha": "^7.0.2",
88
- "mocha-junit-reporter": "^1.18.0",
89
- "cross-env": "^7.0.2",
74
+ "@azure-tools/test-utils": "~1.0.0",
75
+ "@azure/core-util": "^1.9.0",
76
+ "@azure/dev-tool": "^1.0.0",
77
+ "@azure/eslint-plugin-azure-sdk": "^3.0.0",
78
+ "@azure/identity": "^4.0.1",
90
79
  "@types/chai": "^4.2.8",
80
+ "@types/mocha": "^10.0.0",
81
+ "@types/node": "^18.0.0",
82
+ "autorest": "latest",
91
83
  "chai": "^4.2.0",
84
+ "dotenv": "^16.0.0",
85
+ "eslint": "^9.9.0",
86
+ "karma": "^6.2.0",
92
87
  "karma-chrome-launcher": "^3.0.0",
93
88
  "karma-coverage": "^2.0.0",
94
89
  "karma-env-preprocessor": "^0.1.1",
95
90
  "karma-firefox-launcher": "^1.1.0",
96
91
  "karma-junit-reporter": "^2.0.1",
97
- "karma-mocha-reporter": "^2.2.5",
98
92
  "karma-mocha": "^2.0.1",
93
+ "karma-mocha-reporter": "^2.2.5",
99
94
  "karma-source-map-support": "~1.4.0",
100
95
  "karma-sourcemap-loader": "^0.3.8",
101
- "karma": "^6.2.0",
102
- "nyc": "^15.0.0",
103
- "@azure/test-utils": "~1.0.0"
96
+ "mocha": "^10.0.0",
97
+ "nyc": "^17.0.0",
98
+ "source-map-support": "^0.5.9",
99
+ "ts-node": "^10.0.0",
100
+ "typescript": "~5.6.2"
104
101
  },
105
102
  "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/maps/maps-geolocation-rest/README.md",
106
103
  "//metadata": {
@@ -4,32 +4,33 @@
4
4
 
5
5
  ```ts
6
6
 
7
- import { AzureKeyCredential } from '@azure/core-auth';
7
+ import type { AzureKeyCredential } from '@azure/core-auth';
8
+ import type { AzureSASCredential } from '@azure/core-auth';
8
9
  import { Client } from '@azure-rest/core-client';
9
10
  import { ClientOptions } from '@azure-rest/core-client';
10
11
  import { HttpResponse } from '@azure-rest/core-client';
11
12
  import { RequestParameters } from '@azure-rest/core-client';
12
13
  import { StreamableMethod } from '@azure-rest/core-client';
13
- import { TokenCredential } from '@azure/core-auth';
14
+ import type { TokenCredential } from '@azure/core-auth';
14
15
 
15
16
  // @public
16
17
  export interface CountryRegionOutput {
17
- isoCode?: string;
18
+ readonly isoCode?: string;
18
19
  }
19
20
 
20
21
  // @public
21
22
  export interface ErrorAdditionalInfoOutput {
22
- info?: Record<string, unknown>;
23
- type?: string;
23
+ readonly info?: Record<string, unknown>;
24
+ readonly type?: string;
24
25
  }
25
26
 
26
27
  // @public
27
28
  export interface ErrorDetailOutput {
28
- additionalInfo?: Array<ErrorAdditionalInfoOutput>;
29
- code?: string;
30
- details?: Array<ErrorDetailOutput>;
31
- message?: string;
32
- target?: string;
29
+ readonly additionalInfo?: Array<ErrorAdditionalInfoOutput>;
30
+ readonly code?: string;
31
+ readonly details?: Array<ErrorDetailOutput>;
32
+ readonly message?: string;
33
+ readonly target?: string;
33
34
  }
34
35
 
35
36
  // @public
@@ -74,8 +75,8 @@ export interface GetLocation {
74
75
 
75
76
  // @public
76
77
  export interface IpAddressToLocationResultOutput {
77
- countryRegion?: CountryRegionOutput;
78
- ipAddress?: string;
78
+ readonly countryRegion?: CountryRegionOutput;
79
+ readonly ipAddress?: string;
79
80
  }
80
81
 
81
82
  // @public (undocumented)
@@ -86,6 +87,9 @@ function MapsGeolocation(credential: AzureKeyCredential, options?: ClientOptions
86
87
 
87
88
  // @public
88
89
  function MapsGeolocation(credential: TokenCredential, mapsAccountClientId: string, options?: ClientOptions): MapsGeolocationClient;
90
+
91
+ // @public
92
+ function MapsGeolocation(credential: AzureSASCredential, options?: ClientOptions): MapsGeolocationClient;
89
93
  export default MapsGeolocation;
90
94
 
91
95
  // @public (undocumented)
@@ -93,6 +97,11 @@ export type MapsGeolocationClient = Client & {
93
97
  path: Routes;
94
98
  };
95
99
 
100
+ // @public
101
+ export interface MapsGeolocationClientOptions extends ClientOptions {
102
+ apiVersion?: string;
103
+ }
104
+
96
105
  // @public (undocumented)
97
106
  export interface Routes {
98
107
  (path: "/geolocation/ip/{format}", format: "json"): GetLocation;
@@ -1,37 +1,38 @@
1
- import { AzureKeyCredential } from '@azure/core-auth';
1
+ import type { AzureKeyCredential } from '@azure/core-auth';
2
+ import type { AzureSASCredential } from '@azure/core-auth';
2
3
  import { Client } from '@azure-rest/core-client';
3
4
  import { ClientOptions } from '@azure-rest/core-client';
4
5
  import { HttpResponse } from '@azure-rest/core-client';
5
6
  import { RequestParameters } from '@azure-rest/core-client';
6
7
  import { StreamableMethod } from '@azure-rest/core-client';
7
- import { TokenCredential } from '@azure/core-auth';
8
+ import type { TokenCredential } from '@azure/core-auth';
8
9
 
9
10
  /** The object containing the country/region information. */
10
11
  export declare interface CountryRegionOutput {
11
12
  /** The IP Address's 2-character code [(ISO 3166-1)](https://www.iso.org/iso-3166-country-codes.html) of the country or region. Please note, IP address in ranges reserved for special purpose will return Null for country/region. */
12
- isoCode?: string;
13
+ readonly isoCode?: string;
13
14
  }
14
15
 
15
16
  /** The resource management error additional info. */
16
17
  export declare interface ErrorAdditionalInfoOutput {
17
18
  /** The additional info type. */
18
- type?: string;
19
+ readonly type?: string;
19
20
  /** The additional info. */
20
- info?: Record<string, unknown>;
21
+ readonly info?: Record<string, unknown>;
21
22
  }
22
23
 
23
24
  /** The error detail. */
24
25
  export declare interface ErrorDetailOutput {
25
26
  /** The error code. */
26
- code?: string;
27
+ readonly code?: string;
27
28
  /** The error message. */
28
- message?: string;
29
+ readonly message?: string;
29
30
  /** The error target. */
30
- target?: string;
31
+ readonly target?: string;
31
32
  /** The error details. */
32
- details?: Array<ErrorDetailOutput>;
33
+ readonly details?: Array<ErrorDetailOutput>;
33
34
  /** The error additional info. */
34
- additionalInfo?: Array<ErrorAdditionalInfoOutput>;
35
+ readonly additionalInfo?: Array<ErrorAdditionalInfoOutput>;
35
36
  }
36
37
 
37
38
  /** Common error response for all Azure Resource Manager APIs to return error details for failed operations. (This also follows the OData error response format.). */
@@ -41,10 +42,8 @@ export declare interface ErrorResponseOutput {
41
42
  }
42
43
 
43
44
  /**
44
- * **Applies to:** see pricing [tiers](https://aka.ms/AzureMapsPricingTier).
45
45
  *
46
- *
47
- * This service will return the ISO country code for the provided IP address. Developers can use this information to block or alter certain content based on geographical locations where the application is being viewed from.
46
+ * The `Get IP To Location` API is an HTTP `GET` request that, given an IP address, returns the ISO country code from which that IP address is located. Developers can use this information to block or alter certain content based on geographical locations where the application is being viewed from.
48
47
  */
49
48
  export declare interface GeolocationGetLocation200Response extends HttpResponse {
50
49
  status: "200";
@@ -52,10 +51,8 @@ export declare interface GeolocationGetLocation200Response extends HttpResponse
52
51
  }
53
52
 
54
53
  /**
55
- * **Applies to:** see pricing [tiers](https://aka.ms/AzureMapsPricingTier).
56
- *
57
54
  *
58
- * This service will return the ISO country code for the provided IP address. Developers can use this information to block or alter certain content based on geographical locations where the application is being viewed from.
55
+ * The `Get IP To Location` API is an HTTP `GET` request that, given an IP address, returns the ISO country code from which that IP address is located. Developers can use this information to block or alter certain content based on geographical locations where the application is being viewed from.
59
56
  */
60
57
  export declare interface GeolocationGetLocationDefaultResponse extends HttpResponse {
61
58
  status: string;
@@ -75,10 +72,8 @@ export declare interface GeolocationGetLocationQueryParamProperties {
75
72
 
76
73
  export declare interface GetLocation {
77
74
  /**
78
- * **Applies to:** see pricing [tiers](https://aka.ms/AzureMapsPricingTier).
79
75
  *
80
- *
81
- * This service will return the ISO country code for the provided IP address. Developers can use this information to block or alter certain content based on geographical locations where the application is being viewed from.
76
+ * The `Get IP To Location` API is an HTTP `GET` request that, given an IP address, returns the ISO country code from which that IP address is located. Developers can use this information to block or alter certain content based on geographical locations where the application is being viewed from.
82
77
  */
83
78
  get(options: GeolocationGetLocationParameters): StreamableMethod<GeolocationGetLocation200Response | GeolocationGetLocationDefaultResponse>;
84
79
  }
@@ -86,9 +81,9 @@ export declare interface GetLocation {
86
81
  /** This object is returned from a successful call to IP Address to country/region API */
87
82
  export declare interface IpAddressToLocationResultOutput {
88
83
  /** The object containing the country/region information. */
89
- countryRegion?: CountryRegionOutput;
84
+ readonly countryRegion?: CountryRegionOutput;
90
85
  /** The IP Address of the request. */
91
- ipAddress?: string;
86
+ readonly ipAddress?: string;
92
87
  }
93
88
 
94
89
  export declare function isUnexpected(response: GeolocationGetLocation200Response | GeolocationGetLocationDefaultResponse): response is GeolocationGetLocationDefaultResponse;
@@ -115,7 +110,7 @@ declare function MapsGeolocation(credential: AzureKeyCredential, options?: Clien
115
110
  *
116
111
  * @example
117
112
  * ```ts
118
- * import MapsGeolocation from "@azure/maps-geo-location";
113
+ * import MapsGeolocation from "@azure-rest/maps-geo-location";
119
114
  * import { DefaultAzureCredential } from "@azure/identity";
120
115
  *
121
116
  * const credential = new DefaultAzureCredential();
@@ -127,12 +122,35 @@ declare function MapsGeolocation(credential: AzureKeyCredential, options?: Clien
127
122
  * @param options - Options used to configure the Route Client
128
123
  */
129
124
  declare function MapsGeolocation(credential: TokenCredential, mapsAccountClientId: string, options?: ClientOptions): MapsGeolocationClient;
125
+
126
+ /**
127
+ * Creates an instance of MapsGeolocation from an Azure Identity `AzureSASCredential`.
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * import MapsGeolocation from "@azure-rest/maps-geo-location";
132
+ * import { AzureSASCredential } from "@azure/core-auth";
133
+ *
134
+ * const credential = new AzureSASCredential("<SAS Token>");
135
+ * const client = MapsGeolocation(credential);
136
+ * ```
137
+ *
138
+ * @param credential - An AzureSASCredential instance used to authenticate requests to the service
139
+ * @param options - Options used to configure the Geolocation Client
140
+ */
141
+ declare function MapsGeolocation(credential: AzureSASCredential, options?: ClientOptions): MapsGeolocationClient;
130
142
  export default MapsGeolocation;
131
143
 
132
144
  export declare type MapsGeolocationClient = Client & {
133
145
  path: Routes;
134
146
  };
135
147
 
148
+ /** The optional parameters for the client */
149
+ export declare interface MapsGeolocationClientOptions extends ClientOptions {
150
+ /** The api version option of the client */
151
+ apiVersion?: string;
152
+ }
153
+
136
154
  export declare interface Routes {
137
155
  /** Resource for '/geolocation/ip/\{format\}' has methods for the following verbs: get */
138
156
  (path: "/geolocation/ip/{format}", format: "json"): GetLocation;
@@ -1,4 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT license.
3
- export {};
4
- //# sourceMappingURL=clientDefinitions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"clientDefinitions.js","sourceRoot":"","sources":["../../../src/generated/clientDefinitions.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { GeolocationGetLocationParameters } from \"./parameters\";\nimport {\n GeolocationGetLocation200Response,\n GeolocationGetLocationDefaultResponse\n} from \"./responses\";\nimport { Client, StreamableMethod } from \"@azure-rest/core-client\";\n\nexport interface GetLocation {\n /**\n * **Applies to:** see pricing [tiers](https://aka.ms/AzureMapsPricingTier).\n *\n *\n * This service will return the ISO country code for the provided IP address. Developers can use this information to block or alter certain content based on geographical locations where the application is being viewed from.\n */\n get(\n options: GeolocationGetLocationParameters\n ): StreamableMethod<\n GeolocationGetLocation200Response | GeolocationGetLocationDefaultResponse\n >;\n}\n\nexport interface Routes {\n /** Resource for '/geolocation/ip/\\{format\\}' has methods for the following verbs: get */\n (path: \"/geolocation/ip/{format}\", format: \"json\"): GetLocation;\n}\n\nexport type MapsGeolocationClient = Client & {\n path: Routes;\n};\n"]}
@@ -1,11 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT license.
3
- import MapsGeolocationClient from "./mapsGeolocationClient";
4
- export * from "./mapsGeolocationClient";
5
- export * from "./parameters";
6
- export * from "./responses";
7
- export * from "./clientDefinitions";
8
- export * from "./isUnexpected";
9
- export * from "./outputModels";
10
- export default MapsGeolocationClient;
11
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/generated/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAE5D,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAE/B,eAAe,qBAAqB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport MapsGeolocationClient from \"./mapsGeolocationClient\";\n\nexport * from \"./mapsGeolocationClient\";\nexport * from \"./parameters\";\nexport * from \"./responses\";\nexport * from \"./clientDefinitions\";\nexport * from \"./isUnexpected\";\nexport * from \"./outputModels\";\n\nexport default MapsGeolocationClient;\n"]}
@@ -1,69 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT license.
3
- const responseMap = {
4
- "GET /geolocation/ip/{format}": ["200"]
5
- };
6
- export function isUnexpected(response) {
7
- const lroOriginal = response.headers["x-ms-original-url"];
8
- const url = new URL(lroOriginal !== null && lroOriginal !== void 0 ? lroOriginal : response.request.url);
9
- const method = response.request.method;
10
- let pathDetails = responseMap[`${method} ${url.pathname}`];
11
- if (!pathDetails) {
12
- pathDetails = geParametrizedPathSuccess(method, url.pathname);
13
- }
14
- return !pathDetails.includes(response.status);
15
- }
16
- function geParametrizedPathSuccess(method, path) {
17
- var _a, _b;
18
- const pathParts = path.split("/");
19
- // Iterate the responseMap to find a match
20
- for (const [key, value] of Object.entries(responseMap)) {
21
- // Extracting the path from the map key which is in format
22
- // GET /path/foo
23
- if (!key.startsWith(method)) {
24
- continue;
25
- }
26
- const candidatePath = getPathFromMapKey(key);
27
- // Get each part of the url path
28
- const candidateParts = candidatePath.split("/");
29
- // If the candidate and actual paths don't match in size
30
- // we move on to the next candidate path
31
- if (candidateParts.length === pathParts.length &&
32
- hasParametrizedPath(key)) {
33
- // track if we have found a match to return the values found.
34
- let found = true;
35
- for (let i = 0; i < candidateParts.length; i++) {
36
- if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) &&
37
- ((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.endsWith("}"))) {
38
- // If the current part of the candidate is a "template" part
39
- // it is a match with the actual path part on hand
40
- // skip as the parameterized part can match anything
41
- continue;
42
- }
43
- // If the candidate part is not a template and
44
- // the parts don't match mark the candidate as not found
45
- // to move on with the next candidate path.
46
- if (candidateParts[i] !== pathParts[i]) {
47
- found = false;
48
- break;
49
- }
50
- }
51
- // We finished evaluating the current candidate parts
52
- // if all parts matched we return the success values form
53
- // the path mapping.
54
- if (found) {
55
- return value;
56
- }
57
- }
58
- }
59
- // No match was found, return an empty array.
60
- return [];
61
- }
62
- function hasParametrizedPath(path) {
63
- return path.includes("/{");
64
- }
65
- function getPathFromMapKey(mapKey) {
66
- const pathStart = mapKey.indexOf("/");
67
- return mapKey.slice(pathStart);
68
- }
69
- //# sourceMappingURL=isUnexpected.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isUnexpected.js","sourceRoot":"","sources":["../../../src/generated/isUnexpected.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAOlC,MAAM,WAAW,GAA6B;IAC5C,8BAA8B,EAAE,CAAC,KAAK,CAAC;CACxC,CAAC;AAOF,MAAM,UAAU,YAAY,CAC1B,QAEyC;IAEzC,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC1D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACzD,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC;IACvC,IAAI,WAAW,GAAG,WAAW,CAAC,GAAG,MAAM,IAAI,GAAG,CAAC,QAAQ,EAA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C3C,IAAI,cAAc,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE;oBACtC,KAAK,GAAG,KAAK,CAAC;oBACd,MAAM;iBACP;aACF;YAED,qDAAqD;YACrD,yDAAyD;YACzD,oBAAoB;YACpB,IAAI,KAAK,EAAE;gBACT,OAAO,KAAK,CAAC;aACd;SACF;KACF;IAED,6CAA6C;IAC7C,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,SAAS,mBAAmB,CAAC,IAAY;IACvC,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAc;IACvC,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACtC,OAAO,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACjC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n GeolocationGetLocation200Response,\n GeolocationGetLocationDefaultResponse\n} from \"./responses\";\n\nconst responseMap: Record<string, string[]> = {\n \"GET /geolocation/ip/{format}\": [\"200\"]\n};\n\nexport function isUnexpected(\n response:\n | GeolocationGetLocation200Response\n | GeolocationGetLocationDefaultResponse\n): response is GeolocationGetLocationDefaultResponse;\nexport function isUnexpected(\n response:\n | GeolocationGetLocation200Response\n | GeolocationGetLocationDefaultResponse\n): response is GeolocationGetLocationDefaultResponse {\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"]}
@@ -1,25 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT license.
3
- import { getClient } from "@azure-rest/core-client";
4
- /**
5
- * Initialize a new instance of the class MapsGeolocationClient class.
6
- * @param credentials type: KeyCredential
7
- */
8
- export default function createClient(credentials, options = {}) {
9
- var _a, _b;
10
- const baseUrl = (_a = options.baseUrl) !== null && _a !== void 0 ? _a : `https://atlas.microsoft.com`;
11
- options.apiVersion = (_b = options.apiVersion) !== null && _b !== void 0 ? _b : "1.0";
12
- options = Object.assign(Object.assign({}, options), { credentials: {
13
- apiKeyHeaderName: "subscription-key"
14
- } });
15
- const userAgentInfo = `azsdk-js-maps-geolocation-rest/1.0.0-beta.1`;
16
- const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
17
- ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
18
- : `${userAgentInfo}`;
19
- options = Object.assign(Object.assign({}, options), { userAgentOptions: {
20
- userAgentPrefix
21
- } });
22
- const client = getClient(baseUrl, credentials, options);
23
- return client;
24
- }
25
- //# sourceMappingURL=mapsGeolocationClient.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mapsGeolocationClient.js","sourceRoot":"","sources":["../../../src/generated/mapsGeolocationClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,SAAS,EAAiB,MAAM,yBAAyB,CAAC;AAInE;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,WAA0B,EAC1B,UAAyB,EAAE;;IAE3B,MAAM,OAAO,GAAG,MAAA,OAAO,CAAC,OAAO,mCAAI,6BAA6B,CAAC;IACjE,OAAO,CAAC,UAAU,GAAG,MAAA,OAAO,CAAC,UAAU,mCAAI,KAAK,CAAC;IACjD,OAAO,mCACF,OAAO,KACV,WAAW,EAAE;YACX,gBAAgB,EAAE,kBAAkB;SACrC,GACF,CAAC;IAEF,MAAM,aAAa,GAAG,6CAA6C,CAAC;IACpE,MAAM,eAAe,GACnB,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC,eAAe;QAClE,CAAC,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,eAAe,IAAI,aAAa,EAAE;QAChE,CAAC,CAAC,GAAG,aAAa,EAAE,CAAC;IACzB,OAAO,mCACF,OAAO,KACV,gBAAgB,EAAE;YAChB,eAAe;SAChB,GACF,CAAC;IAEF,MAAM,MAAM,GAAG,SAAS,CACtB,OAAO,EACP,WAAW,EACX,OAAO,CACiB,CAAC;IAE3B,OAAO,MAAM,CAAC;AAChB,CAAC","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 { MapsGeolocationClient } from \"./clientDefinitions\";\n\n/**\n * Initialize a new instance of the class MapsGeolocationClient class.\n * @param credentials type: KeyCredential\n */\nexport default function createClient(\n credentials: KeyCredential,\n options: ClientOptions = {}\n): MapsGeolocationClient {\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-geolocation-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(\n baseUrl,\n credentials,\n options\n ) as MapsGeolocationClient;\n\n return client;\n}\n"]}
@@ -1,4 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT license.
3
- export {};
4
- //# sourceMappingURL=outputModels.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"outputModels.js","sourceRoot":"","sources":["../../../src/generated/outputModels.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/** This object is returned from a successful call to IP Address to country/region API */\nexport interface IpAddressToLocationResultOutput {\n /** The object containing the country/region information. */\n countryRegion?: CountryRegionOutput;\n /** The IP Address of the request. */\n ipAddress?: string;\n}\n\n/** The object containing the country/region information. */\nexport interface CountryRegionOutput {\n /** The IP Address's 2-character code [(ISO 3166-1)](https://www.iso.org/iso-3166-country-codes.html) of the country or region. Please note, IP address in ranges reserved for special purpose will return Null for country/region. */\n isoCode?: string;\n}\n\n/** Common error response for all Azure Resource Manager APIs to return error details for failed operations. (This also follows the OData error response format.). */\nexport interface ErrorResponseOutput {\n /** The error object. */\n error?: ErrorDetailOutput;\n}\n\n/** The error detail. */\nexport interface ErrorDetailOutput {\n /** The error code. */\n code?: string;\n /** The error message. */\n message?: string;\n /** The error target. */\n target?: string;\n /** The error details. */\n details?: Array<ErrorDetailOutput>;\n /** The error additional info. */\n additionalInfo?: Array<ErrorAdditionalInfoOutput>;\n}\n\n/** The resource management error additional info. */\nexport interface ErrorAdditionalInfoOutput {\n /** The additional info type. */\n type?: string;\n /** The additional info. */\n info?: Record<string, unknown>;\n}\n"]}
@@ -1,4 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT license.
3
- export {};
4
- //# sourceMappingURL=parameters.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parameters.js","sourceRoot":"","sources":["../../../src/generated/parameters.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { RequestParameters } from \"@azure-rest/core-client\";\n\nexport interface GeolocationGetLocationQueryParamProperties {\n /** The IP address. Both IPv4 and IPv6 are allowed. */\n ip: string;\n}\n\nexport interface GeolocationGetLocationQueryParam {\n queryParameters: GeolocationGetLocationQueryParamProperties;\n}\n\nexport type GeolocationGetLocationParameters = GeolocationGetLocationQueryParam &\n RequestParameters;\n"]}
@@ -1,4 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT license.
3
- export {};
4
- //# sourceMappingURL=responses.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"responses.js","sourceRoot":"","sources":["../../../src/generated/responses.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { HttpResponse } from \"@azure-rest/core-client\";\nimport {\n IpAddressToLocationResultOutput,\n ErrorResponseOutput\n} from \"./outputModels\";\n\n/**\n * **Applies to:** see pricing [tiers](https://aka.ms/AzureMapsPricingTier).\n *\n *\n * This service will return the ISO country code for the provided IP address. Developers can use this information to block or alter certain content based on geographical locations where the application is being viewed from.\n */\nexport interface GeolocationGetLocation200Response extends HttpResponse {\n status: \"200\";\n body: IpAddressToLocationResultOutput;\n}\n\n/**\n * **Applies to:** see pricing [tiers](https://aka.ms/AzureMapsPricingTier).\n *\n *\n * This service will return the ISO country code for the provided IP address. Developers can use this information to block or alter certain content based on geographical locations where the application is being viewed from.\n */\nexport interface GeolocationGetLocationDefaultResponse extends HttpResponse {\n status: string;\n body: ErrorResponseOutput;\n}\n"]}