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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@edirect/dynamics

v11.0.58

Published

Microsoft Dynamics 365 integration module for eDirect NestJS applications. Handles OAuth2 token acquisition (password grant and client credentials), automatic token refresh, and provides `get`, `post`, and `patch` methods for Dynamics API calls.

Readme

@edirect/dynamics

Microsoft Dynamics 365 integration module for eDirect NestJS applications. Handles OAuth2 token acquisition (password grant and client credentials), automatic token refresh, and provides get, post, and patch methods for Dynamics API calls.

Features

  • OAuth2 password grant and client_credentials grant support
  • Automatic token caching and refresh (falls back to full re-auth on refresh failure)
  • get, post, patch HTTP methods with automatic Bearer token injection
  • DYNAMICS_ENABLED flag to safely disable all Dynamics calls without removing code
  • NestJS module — integrates with @edirect/config

Installation

pnpm add @edirect/dynamics
# or
npm install @edirect/dynamics

Setup

1. Set environment variables

DYNAMICS_TOKEN_URL=https://login.windows.net/YOUR_TENANT_ID/oauth2/token
DYNAMICS_CLIENT_ID=your-client-id
DYNAMICS_CLIENT_SECRET=your-client-secret       # required for client_credentials grant
[email protected]  # required for password grant
DYNAMICS_PASSWORD=your-dynamics-password           # required for password grant
DYNAMICS_RESOURCE=https://yourorg.crm.dynamics.com
DYNAMICS_ENABLED=true

2. Register DynamicsModule in your AppModule

import { Module } from '@nestjs/common';
import { DynamicsModule } from '@edirect/dynamics';

@Module({
  imports: [DynamicsModule],
})
export class AppModule {}

3. Inject and use DynamicsService

import { Injectable } from '@nestjs/common';
import { DynamicsService } from '@edirect/dynamics';

@Injectable()
export class PolicySyncService {
  constructor(private readonly dynamics: DynamicsService) {}

  // POST using password grant (default)
  async createContact(data: object): Promise<object | null> {
    return this.dynamics.post(
      'https://yourorg.crm.dynamics.com/api/data/v9.2/contacts',
      data,
    );
  }

  // PATCH using password grant
  async updateContact(id: string, data: object): Promise<object | null> {
    return this.dynamics.patch(
      `https://yourorg.crm.dynamics.com/api/data/v9.2/contacts(${id})`,
      data,
    );
  }

  // GET using client_credentials grant
  async getAccounts(): Promise<object | null> {
    return this.dynamics.get(
      'https://yourorg.crm.dynamics.com/api/data/v9.2/accounts',
      {},
      'client_credentials',
    );
  }
}

API

DynamicsService

get(url, options?, grantType?): Promise<object | null>

Performs a GET request to the Dynamics API. Returns null if DYNAMICS_ENABLED is false.

| Parameter | Type | Default | Description | | ----------- | ------------------------------------ | ------------ | -------------------------------- | | url | string | — | Full Dynamics API endpoint URL | | options | AxiosRequestConfig | — | Additional Axios request options | | grantType | 'password' \| 'client_credentials' | 'password' | OAuth2 grant type to use |

post(url, data, options?, grantType?): Promise<object | null>

Performs a POST request. Returns null if DYNAMICS_ENABLED is false.

patch(url, data, options?, grantType?): Promise<object | null>

Performs a PATCH request. Returns null if DYNAMICS_ENABLED is false.

getAccessToken(): Promise<ITokenSet>

Acquires a token using the password grant. Automatically refreshes if expired.

getAccessTokenByClientCredentials(): Promise<ITokenSet>

Acquires a token using client_credentials grant.

getRefreshToken(): Promise<ITokenSet>

Refreshes the current token. Falls back to getAccessToken() on failure.

Environment Variables

| Variable | Description | Required For | | ------------------------ | ----------------------------------------------------------------- | -------------------- | | DYNAMICS_TOKEN_URL | Azure AD OAuth2 token endpoint | All grant types | | DYNAMICS_CLIENT_ID | Application client ID | All grant types | | DYNAMICS_CLIENT_SECRET | Client secret | client_credentials | | DYNAMICS_USER_NAME | Service account username | password | | DYNAMICS_PASSWORD | Service account password | password | | DYNAMICS_RESOURCE | Dynamics CRM resource URL | All grant types | | DYNAMICS_ENABLED | Set to 'true' to enable; any other value disables all API calls | All |

Token Flow

1. First call → acquire token (password or client_credentials)
2. Subsequent calls → if token not expired, use refresh_token grant
3. If refresh fails → fall back to full re-authentication
4. Token is cached in memory (service singleton)