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

@xrmforge/typegen

v0.20.0

Published

TypeScript declaration generator for Dynamics 365 / Dataverse

Readme

@xrmforge/typegen

npm version license

The type-generation engine of XrmForge. Reads Dynamics 365 / Dataverse metadata and generates TypeScript declarations that extend @types/xrm (never replace it), so your generated types coexist with PCF controls and the rest of the Microsoft ecosystem.

Most users do not call this package directly -- they use @xrmforge/cli (xrmforge generate), which wraps this engine. Install @xrmforge/typegen directly only when you want to embed generation in your own Node.js tooling. For the full framework docs, see the XrmForge repository.


What it generates

For each entity, typegen emits flat ES modules (.ts files) -- one file per concern, imported and processed by your bundler. No declare namespace, no ambient .d.ts.

generated/
  entities/account.ts      export interface Account { ... }       // typed Web API response objects
  fields/account.ts        export const enum AccountFields         // $select / $filter (already _value form)
                           export const enum AccountNavigationProperties  // parseLookup / $expand / @odata.bind
  optionsets/account.ts    export const enum IndustryCode ...       // every picklist/status/state field
  forms/account.ts         Union + maps + Fields enum + Form interface + FormTypeInfo + MockValues
  actions/quote.ts         export const WinQuote = createBoundAction(...)  // typed Custom API executors
  entity-names.ts          export const enum EntityNames
  index.ts                 barrel re-export

Each generated artifact is a compile-time contract:

  • Entity interfaces -- all attributes correctly typed (string, number, boolean, Lookup, OptionSet, DateTime).
  • Form interfaces -- per-form getAttribute() / getControl() overloads. Only fields actually on the form are valid; no string fallback, no any.
  • OptionSet enums -- const enum, inlined by TypeScript (zero runtime overhead).
  • Fields / NavigationProperties enums -- type-safe $select and lookup navigation.
  • Action / Function executors -- generated from Custom API metadata, with typed parameters and responses.
  • Dual-language JSDoc -- /** Account Name | Firmenname */ when --secondary-language is set.

Usage via the CLI (recommended)

npm install --save-dev @xrmforge/cli @types/xrm
npx xrmforge generate --url https://myorg.crm4.dynamics.com --auth interactive \
  --tenant-id YOUR_TENANT_ID --client-id 51f81489-12ee-4a9e-aaae-a2591f45987d \
  --entities account,contact --output ./generated

See @xrmforge/cli for every flag, authentication method, incremental caching (--cache), and drift detection (--check).


Programmatic API

Install directly when embedding generation in your own tooling:

npm install @xrmforge/typegen @types/xrm

The high-level entry point is the orchestrator, which runs the full pipeline (authenticate, read metadata, generate, write). It takes a credential and a config:

import { TypeGenerationOrchestrator, createCredential } from '@xrmforge/typegen';

// 1. Build a credential from an auth config
//    (method: 'interactive' | 'client-credentials' | 'device-code' | 'token')
const credential = createCredential({
  method: 'interactive',
  tenantId: 'YOUR_TENANT_ID',
  clientId: '51f81489-12ee-4a9e-aaae-a2591f45987d',
});

// 2. Run the pipeline
const orchestrator = new TypeGenerationOrchestrator(credential, {
  environmentUrl: 'https://myorg.crm4.dynamics.com',
  entities: ['account', 'contact'],
  outputDir: './generated',
  labelConfig: { primaryLanguage: 1033, secondaryLanguage: 1031 },
});

const result = await orchestrator.generate();
console.log(`Generated ${result.totalFiles} files`);

For finer control, the building blocks are exported individually:

| Area | Exports | |------|---------| | Orchestration | TypeGenerationOrchestrator, types GenerateConfig, GenerationResult, CheckResult, CheckFinding, CacheStats | | Authentication | createCredential, types AuthConfig, ClientCredentialsAuth, InteractiveAuth, DeviceCodeAuth | | HTTP | DataverseHttpClient (ReadOnly-default, retry, rate-limit), type HttpClientOptions | | Metadata | MetadataClient, MetadataCache, ChangeDetector, parseForm, plus rich metadata types (EntityMetadata, AttributeMetadata, OptionSetMetadata, SystemFormMetadata, ...) | | Code generators | generateEntityInterface, generateFormInterface, generateOptionSetEnum, generateEntityFieldsEnum, generateActionModule, generateEntityNamesEnum, ... | | Type mapping | getEntityPropertyType, getFormAttributeType, toSafeIdentifier, toPascalCase, isLookupType, ... | | Logging | Logger, ConsoleLogSink, JsonLogSink, SilentLogSink, LogLevel, configureLogging | | Errors | XrmForgeError, AuthenticationError, ApiRequestError, MetadataError, GenerationError, ConfigError, isXrmForgeError, isRateLimitError |

Node.js only. This package pulls in @azure/identity and Node APIs. Do not import it in browser/form-script code -- use @xrmforge/helpers for the browser runtime. The @xrmforge/eslint-plugin rule no-typegen-import enforces this.


Peer dependency

@types/xrm (>= 9.0.0) -- the generated types build on top of it.

Documentation

Full guide and generated-type patterns: XrmForge on GitHub.

License

MIT (c) XrmForge Contributors.