|
| 1 | +# Azure Impact client library for JavaScript |
| 2 | + |
| 3 | +This package contains an isomorphic SDK (runs both in Node.js and in browsers) for Azure Impact client. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +Key links: |
| 8 | + |
| 9 | +- [Source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/impactreporting/arm-impactreporting) |
| 10 | +- [Package (NPM)](https://www.npmjs.com/package/@azure/arm-impactreporting) |
| 11 | +- [API reference documentation](https://learn.microsoft.com/javascript/api/@azure/arm-impactreporting?view=azure-node-preview) |
| 12 | +- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/impactreporting/arm-impactreporting/samples) |
| 13 | + |
| 14 | +## Getting started |
| 15 | + |
| 16 | +### Currently supported environments |
| 17 | + |
| 18 | +- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule) |
| 19 | +- Latest versions of Safari, Chrome, Edge and Firefox. |
| 20 | + |
| 21 | +See our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details. |
| 22 | + |
| 23 | +### Prerequisites |
| 24 | + |
| 25 | +- An [Azure subscription][azure_sub]. |
| 26 | + |
| 27 | +### Install the `@azure/arm-impactreporting` package |
| 28 | + |
| 29 | +Install the Azure Impact client library for JavaScript with `npm`: |
| 30 | + |
| 31 | +```bash |
| 32 | +npm install @azure/arm-impactreporting |
| 33 | +``` |
| 34 | + |
| 35 | +### Create and authenticate a `ImpactClient` |
| 36 | + |
| 37 | +To create a client object to access the Azure Impact API, you will need the `endpoint` of your Azure Impact resource and a `credential`. The Azure Impact client can use Azure Active Directory credentials to authenticate. |
| 38 | +You can find the endpoint for your Azure Impact resource in the [Azure Portal][azure_portal]. |
| 39 | + |
| 40 | +You can authenticate with Azure Active Directory using a credential from the [@azure/identity][azure_identity] library or [an existing AAD Token](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token). |
| 41 | + |
| 42 | +To use the [DefaultAzureCredential][defaultazurecredential] provider shown below, or other credential providers provided with the Azure SDK, please install the `@azure/identity` package: |
| 43 | + |
| 44 | +```bash |
| 45 | +npm install @azure/identity |
| 46 | +``` |
| 47 | + |
| 48 | +You will also need to **register a new AAD application and grant access to Azure Impact** by assigning the suitable role to your service principal (note: roles such as `"Owner"` will not grant the necessary permissions). |
| 49 | + |
| 50 | +For more information about how to create an Azure AD Application check out [this guide](https://learn.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal). |
| 51 | + |
| 52 | +Using Node.js and Node-like environments, you can use the `DefaultAzureCredential` class to authenticate the client. |
| 53 | + |
| 54 | +```ts snippet:ReadmeSampleCreateClient_Node |
| 55 | +import { ImpactClient } from "../src/index.js"; |
| 56 | +import { DefaultAzureCredential } from "@azure/identity"; |
| 57 | + |
| 58 | +const subscriptionId = "00000000-0000-0000-0000-000000000000"; |
| 59 | +const client = new ImpactClient(new DefaultAzureCredential(), subscriptionId); |
| 60 | +``` |
| 61 | + |
| 62 | +For browser environments, use the `InteractiveBrowserCredential` from the `@azure/identity` package to authenticate. |
| 63 | + |
| 64 | +```ts snippet:ReadmeSampleCreateClient_Browser |
| 65 | +import { InteractiveBrowserCredential } from "@azure/identity"; |
| 66 | +import { ImpactClient } from "../src/index.js"; |
| 67 | + |
| 68 | +const subscriptionId = "00000000-0000-0000-0000-000000000000"; |
| 69 | +const credential = new InteractiveBrowserCredential({ |
| 70 | + tenantId: "<YOUR_TENANT_ID>", |
| 71 | + clientId: "<YOUR_CLIENT_ID>", |
| 72 | +}); |
| 73 | +const client = new ImpactClient(credential, subscriptionId); |
| 74 | +``` |
| 75 | + |
| 76 | + |
| 77 | +### JavaScript Bundle |
| 78 | +To use this client library in the browser, first you need to use a bundler. For details on how to do this, please refer to our [bundling documentation](https://aka.ms/AzureSDKBundling). |
| 79 | + |
| 80 | +## Key concepts |
| 81 | + |
| 82 | +### ImpactClient |
| 83 | + |
| 84 | +`ImpactClient` is the primary interface for developers using the Azure Impact client library. Explore the methods on this client object to understand the different features of the Azure Impact service that you can access. |
| 85 | + |
| 86 | +## Troubleshooting |
| 87 | + |
| 88 | +### Logging |
| 89 | + |
| 90 | +Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`: |
| 91 | + |
| 92 | +```ts snippet:SetLogLevel |
| 93 | +import { setLogLevel } from "@azure/logger"; |
| 94 | + |
| 95 | +setLogLevel("info"); |
| 96 | +``` |
| 97 | + |
| 98 | +For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger). |
| 99 | + |
| 100 | +## Next steps |
| 101 | + |
| 102 | +Please take a look at the [samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/impactreporting/arm-impactreporting/samples) directory for detailed examples on how to use this library. |
| 103 | + |
| 104 | +## Contributing |
| 105 | + |
| 106 | +If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test the code. |
| 107 | + |
| 108 | +## Related projects |
| 109 | + |
| 110 | +- [Microsoft Azure SDK for JavaScript](https://github.com/Azure/azure-sdk-for-js) |
| 111 | + |
| 112 | +[azure_sub]: https://azure.microsoft.com/free/ |
| 113 | +[azure_portal]: https://portal.azure.com |
| 114 | +[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity |
| 115 | +[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential |
0 commit comments