npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mild-ts/azure-rest-client

v0.2.1

Published

Azure Rest Client Helper for TypeScript

Downloads

1

Readme

@mild-ts/azure-rest-client

Azure Rest Client Helper for TypeScript extended from @mild-ts/rest-client, support Azure Credential by default.

CI

Installation

npm i @mild-ts/azure-rest-client

Examples

import { AzureRestClient } from '@mild-ts/azure-rest-client';

async function main() {
  const client = new AzureRestClient();
  /**
   * https://learn.microsoft.com/en-us/rest/api/appservice/web-apps/get
   */
  const res = await client.request(
    'GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}?api-version=2022-03-01',
    {
      params: {
        subscriptionId: '29523625-6fa5-4d9a-86bc-da000544be7d',
        resourceGroupName: 'rg-thadaw-demo-multi-app',
        name: 'thadaw-demo-multi-app-ant',
      },
    }
  );
  console.log(res.status);
  console.log(res.data);
}

main();

Documentation

Authentication

This package use DefaultAzureCredential from @azure/identity. The following credential types will be tried, in order:

  1. Environment Credential: This method uses environment variables to authenticate. You would need to set the AZURE_TENANT_ID, AZURE_CLIENT_ID, and AZURE_CLIENT_SECRET environment variables with your Azure tenant ID, client ID, and client secret, respectively.

  2. Managed Identity Credential: This method uses a managed identity to authenticate. If you're running your code in Azure, you can enable managed identity for your app and use it to authenticate.

  3. Azure CLI Credential: This method uses the Azure CLI to authenticate. You would need to install the Azure CLI on your machine and run az login to authenticate.

  4. Azure PowerShell Credential: This method uses Azure PowerShell to authenticate. You would need to install Azure PowerShell on your machine and run Connect-AzAccount to authenticate.

You can read more Azure Identity client library for JavaScript.

Every request sent by AzureRestClient will be added Authentication header getting from the DefaultAzureCredential.

Environment Credential

  1. Open the Azure CLI and log in to your Azure account using the az login command.

  2. Run the following command to create a new service principal and assign it a role:

    az ad sp create-for-rbac --name <SERVICE_PRINCIPAL_NAME> --role <ROLE_NAME>

    Replace <SERVICE_PRINCIPAL_NAME> with a name for your service principal and <ROLE_NAME> with the name of the Azure role you want to assign to the service principal. For example, if you want to assign the "Contributor" ro le, you can use --role Contributor.

  3. The command will output the following information:

    {
      "appId": "<CLIENT_ID>",
      "displayName": "<SERVICE_PRINCIPAL_NAME>",
      "name": "<SERVICE_PRINCIPAL_NAME>",
      "password": "<CLIENT_SECRET>",
      "tenant": "<TENANT_ID>"
    }

    Note down the values of <CLIENT_ID>, <CLIENT_SECRET>, and <TENANT_ID> - you will need these for authentication later.

You can now use the client ID, client secret, and tenant ID to authenticate with Azure. For example, you can use them to create a DefaultAzureCredential object in your code.