@xrmforge/typegen 0.6.0 → 0.7.1

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.
Files changed (44) hide show
  1. package/MIGRATION.md +14 -3
  2. package/dist/index.d.ts +203 -2
  3. package/docs/architecture/00-README.md +26 -0
  4. package/docs/architecture/01-executive-summary.md +11 -0
  5. package/docs/architecture/02-packages.md +110 -0
  6. package/docs/architecture/03-generated-types.md +176 -0
  7. package/docs/architecture/04-cli.md +58 -0
  8. package/docs/architecture/05-build.md +50 -0
  9. package/docs/architecture/06-incremental.md +42 -0
  10. package/docs/architecture/07-http-client.md +59 -0
  11. package/docs/architecture/08-authentication.md +18 -0
  12. package/docs/architecture/09-testing.md +55 -0
  13. package/docs/architecture/10-eslint-plugin.md +82 -0
  14. package/docs/architecture/11-agent-md.md +38 -0
  15. package/docs/architecture/12-xrm-pitfalls.md +14 -0
  16. package/docs/architecture/13-helpers.md +50 -0
  17. package/docs/architecture/14-showcases.md +21 -0
  18. package/docs/architecture/15-ci-cd.md +49 -0
  19. package/docs/architecture/16-technical-debt.md +17 -0
  20. package/docs/architecture/17-roadmap.md +25 -0
  21. package/docs/architecture/18-design-principles.md +22 -0
  22. package/docs/architektur/00-README.md +26 -0
  23. package/docs/architektur/01-zusammenfassung.md +11 -0
  24. package/docs/architektur/02-packages.md +110 -0
  25. package/docs/architektur/03-generierte-typen.md +176 -0
  26. package/docs/architektur/04-cli.md +58 -0
  27. package/docs/architektur/05-build.md +50 -0
  28. package/docs/architektur/06-inkrementell.md +42 -0
  29. package/docs/architektur/07-http-client.md +59 -0
  30. package/docs/architektur/08-authentifizierung.md +18 -0
  31. package/docs/architektur/09-testing.md +55 -0
  32. package/docs/architektur/10-eslint-plugin.md +82 -0
  33. package/docs/architektur/11-agent-md.md +38 -0
  34. package/docs/architektur/12-xrm-fallstricke.md +14 -0
  35. package/docs/architektur/13-helpers.md +50 -0
  36. package/docs/architektur/14-showcases.md +21 -0
  37. package/docs/architektur/15-ci-cd.md +49 -0
  38. package/docs/architektur/16-technische-schulden.md +17 -0
  39. package/docs/architektur/17-roadmap.md +25 -0
  40. package/docs/architektur/18-designprinzipien.md +22 -0
  41. package/package.json +4 -8
  42. package/dist/helpers.d.ts +0 -203
  43. package/dist/helpers.js +0 -120
  44. package/dist/helpers.js.map +0 -1
package/MIGRATION.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  How to convert legacy Dynamics 365 JavaScript to type-safe TypeScript with XrmForge.
4
4
 
5
+ ## Breaking Changes in v0.7.0
6
+
7
+ - The `@xrmforge/typegen/helpers` subpath export has been removed.
8
+ - All browser-safe runtime code (`select`, `parseLookup`, `parseFormattedValue`,
9
+ `withProgress`, Xrm constants, Action/Function executors, `typedForm`) is now
10
+ in the new package `@xrmforge/helpers`.
11
+ - Update imports: `import { select } from '@xrmforge/typegen/helpers'` becomes
12
+ `import { select } from '@xrmforge/helpers'`.
13
+ - `@xrmforge/formhelpers` has been removed. `typedForm()` is now in
14
+ `@xrmforge/helpers`.
15
+
5
16
  ## Step 1: Initialize Project
6
17
 
7
18
  ```bash
@@ -86,8 +97,8 @@ export function onLoad(executionContext: Xrm.Events.EventContext): void {
86
97
  var value = formContext.getAttribute("primarycontactid").getValue();
87
98
  var id = value[0].id.replace("{","").replace("}","");
88
99
 
89
- // After: use parseLookup from @xrmforge/typegen
90
- import { parseLookup } from '@xrmforge/typegen/helpers';
100
+ // After: use parseLookup from @xrmforge/helpers
101
+ import { parseLookup } from '@xrmforge/helpers';
91
102
  const contact = parseLookup(form.getAttribute(Fields.PrimaryContactId));
92
103
  if (contact) {
93
104
  console.log(contact.id); // already clean GUID
@@ -102,7 +113,7 @@ Xrm.WebApi.retrieveMultipleRecords("account",
102
113
  "?$select=name,revenue&$filter=statecode eq 0");
103
114
 
104
115
  // After: use Fields enum for $select
105
- import { select } from '@xrmforge/typegen/helpers';
116
+ import { select } from '@xrmforge/helpers';
106
117
  import { AccountFields } from '../../typings/entities/account';
107
118
  Xrm.WebApi.retrieveMultipleRecords("account",
108
119
  `?$select=${select(AccountFields.Name, AccountFields.Revenue)}&$filter=statecode eq 0`);
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { TokenCredential } from '@azure/identity';
2
- export { BindingType, ClientState, ClientType, DisplayState, FormNotificationLevel, OperationType, RequiredLevel, SaveMode, StructuralProperty, SubmitMode, parseFormattedValue, parseLookup, parseLookups, select, selectExpand } from './helpers.js';
3
2
 
4
3
  /**
5
4
  * @xrmforge/typegen - Error Types
@@ -1452,6 +1451,208 @@ interface EntityNamesGeneratorOptions {
1452
1451
  */
1453
1452
  declare function generateEntityNamesEnum(entityNames: string[], options?: EntityNamesGeneratorOptions): string;
1454
1453
 
1454
+ /**
1455
+ * @xrmforge/typegen - Web API Helper Functions
1456
+ *
1457
+ * Lightweight utility functions for building OData query strings
1458
+ * with type-safe field names from generated Fields enums.
1459
+ *
1460
+ * Zero runtime overhead when used with const enums (values are inlined).
1461
+ *
1462
+ * @example
1463
+ * ```typescript
1464
+ * import { select } from '@xrmforge/typegen';
1465
+ *
1466
+ * Xrm.WebApi.retrieveRecord(ref.entityType, ref.id, select(
1467
+ * AccountFields.Name,
1468
+ * AccountFields.WebsiteUrl,
1469
+ * AccountFields.Address1Line1,
1470
+ * ));
1471
+ * ```
1472
+ */
1473
+ /**
1474
+ * Build an OData $select query string from field names.
1475
+ *
1476
+ * @param fields - Field names (use generated Fields enum for type safety)
1477
+ * @returns OData query string (e.g. "?$select=name,websiteurl,address1_line1")
1478
+ */
1479
+ declare function select(...fields: string[]): string;
1480
+ /**
1481
+ * Parse a lookup field from a Dataverse Web API response into a LookupValue.
1482
+ *
1483
+ * Dataverse returns lookups as `_fieldname_value` with OData annotations:
1484
+ * - `_fieldname_value` (GUID)
1485
+ * - `_fieldname_value@OData.Community.Display.V1.FormattedValue` (display name)
1486
+ * - `_fieldname_value@Microsoft.Dynamics.CRM.lookuplogicalname` (entity type)
1487
+ *
1488
+ * This function extracts all three into an `Xrm.LookupValue` object.
1489
+ *
1490
+ * @param response - The raw Web API response object
1491
+ * @param navigationProperty - Navigation property name (use NavigationProperties enum for type safety)
1492
+ * @returns Xrm.LookupValue or null if the lookup is empty
1493
+ *
1494
+ * @example
1495
+ * ```typescript
1496
+ * // Mit NavigationProperties-Enum (empfohlen, keine Raw-Strings):
1497
+ * parseLookup(result, AccountNav.Country);
1498
+ *
1499
+ * // Oder mit Navigation Property Name direkt:
1500
+ * parseLookup(result, 'markant_address1_countryid');
1501
+ * ```
1502
+ */
1503
+ declare function parseLookup(response: Record<string, unknown>, navigationProperty: string): {
1504
+ id: string;
1505
+ name: string;
1506
+ entityType: string;
1507
+ } | null;
1508
+ /**
1509
+ * Parse multiple lookup fields from a Dataverse Web API response at once.
1510
+ *
1511
+ * @param response - The raw Web API response object
1512
+ * @param navigationProperties - Navigation property names to parse
1513
+ * @returns Map of navigation property name to LookupValue (null entries omitted)
1514
+ *
1515
+ * @example
1516
+ * ```typescript
1517
+ * const lookups = parseLookups(result, ['markant_address1_countryid', 'parentaccountid']);
1518
+ * formContext.getAttribute(Fields.Country).setValue(
1519
+ * lookups.markant_address1_countryid ? [lookups.markant_address1_countryid] : null
1520
+ * );
1521
+ * ```
1522
+ */
1523
+ declare function parseLookups(response: Record<string, unknown>, navigationProperties: string[]): Record<string, {
1524
+ id: string;
1525
+ name: string;
1526
+ entityType: string;
1527
+ } | null>;
1528
+ /**
1529
+ * Get the formatted (display) value of any field from a Web API response.
1530
+ *
1531
+ * Works for OptionSets, Lookups, DateTimes, Money, and other formatted fields.
1532
+ *
1533
+ * @param response - The raw Web API response object
1534
+ * @param fieldName - The field logical name (e.g. "statecode", "createdon")
1535
+ * @returns The formatted string value, or null if not available
1536
+ *
1537
+ * @example
1538
+ * ```typescript
1539
+ * const status = parseFormattedValue(result, 'statecode');
1540
+ * // "Active" (statt 0)
1541
+ * ```
1542
+ */
1543
+ declare function parseFormattedValue(response: Record<string, unknown>, fieldName: string): string | null;
1544
+ /**
1545
+ * Build an OData $select and $expand query string.
1546
+ *
1547
+ * @param fields - Field names to select
1548
+ * @param expand - Navigation property to expand (optional)
1549
+ * @returns OData query string
1550
+ *
1551
+ * @example
1552
+ * ```typescript
1553
+ * Xrm.WebApi.retrieveRecord("account", id, selectExpand(
1554
+ * [AccountFields.Name, AccountFields.WebsiteUrl],
1555
+ * "primarycontactid($select=fullname,emailaddress1)"
1556
+ * ));
1557
+ * ```
1558
+ */
1559
+ declare function selectExpand(fields: string[], expand: string): string;
1560
+
1561
+ /**
1562
+ * @xrmforge/typegen - Xrm API Constants
1563
+ *
1564
+ * Const enums for all common Xrm string/number constants.
1565
+ * Eliminates raw strings in D365 form scripts.
1566
+ *
1567
+ * @types/xrm defines these as string literal types for compile-time checking,
1568
+ * but does NOT provide runtime constants (XrmEnum is not available at runtime).
1569
+ * These const enums are erased at compile time (zero runtime overhead).
1570
+ *
1571
+ * @example
1572
+ * ```typescript
1573
+ * // Statt Raw-String:
1574
+ * if (tab.getDisplayState() === 'expanded') { ... }
1575
+ *
1576
+ * // Mit XrmForge-Konstante:
1577
+ * if (tab.getDisplayState() === XrmConstants.DisplayState.Expanded) { ... }
1578
+ * ```
1579
+ */
1580
+ /** Tab/Section display state */
1581
+ declare const enum DisplayState {
1582
+ Expanded = "expanded",
1583
+ Collapsed = "collapsed"
1584
+ }
1585
+ /** Form notification level (formContext.ui.setFormNotification) */
1586
+ declare const enum FormNotificationLevel {
1587
+ Error = "ERROR",
1588
+ Warning = "WARNING",
1589
+ Info = "INFO"
1590
+ }
1591
+ /** Attribute required level (attribute.setRequiredLevel) */
1592
+ declare const enum RequiredLevel {
1593
+ None = "none",
1594
+ Required = "required",
1595
+ Recommended = "recommended"
1596
+ }
1597
+ /** Attribute submit mode (attribute.setSubmitMode) */
1598
+ declare const enum SubmitMode {
1599
+ Always = "always",
1600
+ Never = "never",
1601
+ Dirty = "dirty"
1602
+ }
1603
+ /** Save mode (eventArgs.getSaveMode()) */
1604
+ declare const enum SaveMode {
1605
+ Save = 1,
1606
+ SaveAndClose = 2,
1607
+ Deactivate = 5,
1608
+ Reactivate = 6,
1609
+ Send = 7,
1610
+ Disqualify = 15,
1611
+ Qualify = 16,
1612
+ Assign = 47,
1613
+ SaveAsCompleted = 58,
1614
+ SaveAndNew = 59,
1615
+ AutoSave = 70
1616
+ }
1617
+ /** Client type (Xrm.Utility.getGlobalContext().client.getClient()) */
1618
+ declare const enum ClientType {
1619
+ Web = "Web",
1620
+ Outlook = "Outlook",
1621
+ Mobile = "Mobile"
1622
+ }
1623
+ /** Client state (Xrm.Utility.getGlobalContext().client.getClientState()) */
1624
+ declare const enum ClientState {
1625
+ Online = "Online",
1626
+ Offline = "Offline"
1627
+ }
1628
+ /** Operation type for Xrm.WebApi.execute getMetadata().operationType */
1629
+ declare const enum OperationType {
1630
+ /** Custom Action or OOB Action (POST) */
1631
+ Action = 0,
1632
+ /** Custom Function or OOB Function (GET) */
1633
+ Function = 1,
1634
+ /** CRUD operation (Create, Retrieve, Update, Delete) */
1635
+ CRUD = 2
1636
+ }
1637
+ /** Structural property for getMetadata().parameterTypes[].structuralProperty */
1638
+ declare const enum StructuralProperty {
1639
+ Unknown = 0,
1640
+ PrimitiveType = 1,
1641
+ ComplexType = 2,
1642
+ EnumerationType = 3,
1643
+ Collection = 4,
1644
+ EntityType = 5
1645
+ }
1646
+ /** Binding type for Custom API definitions */
1647
+ declare const enum BindingType {
1648
+ /** Nicht an eine Entity gebunden (global aufrufbar) */
1649
+ Global = 0,
1650
+ /** An einen einzelnen Entity-Datensatz gebunden */
1651
+ Entity = 1,
1652
+ /** An eine Entity-Collection gebunden */
1653
+ EntityCollection = 2
1654
+ }
1655
+
1455
1656
  /**
1456
1657
  * @xrmforge/typegen - Action/Function Runtime Helpers
1457
1658
  *
@@ -1800,4 +2001,4 @@ declare class TypeGenerationOrchestrator {
1800
2001
  private getPicklistAttributes;
1801
2002
  }
1802
2003
 
1803
- export { type ActionGeneratorOptions, ApiRequestError, type AttributeMetadata, type AuthConfig, type AuthMethod, AuthenticationError, type BoundActionExecutor, type BoundActionWithParamsExecutor, type BoundFunctionExecutor, type CacheStats, type ChangeDetectionResult, ChangeDetector, type ClientCredentialsAuth, ConfigError, ConsoleLogSink, type CustomApiTypeInfo, DEFAULT_LABEL_CONFIG, DataverseHttpClient, type DateTimeAttributeMetadata, type DecimalAttributeMetadata, type DeviceCodeAuth, type EntityFieldsGeneratorOptions, type EntityGenerationResult, type EntityGeneratorOptions, type EntityMetadata, type EntityNamesGeneratorOptions, type EntityTypeInfo, ErrorCode, FastXmlParser, type FormControl, type FormGeneratorOptions, type FormSection, type FormTab, type GenerateConfig, type GeneratedFile, GenerationError, type GenerationResult, type GroupedCustomApis, type HttpClientOptions, type IntegerAttributeMetadata, type InteractiveAuth, JsonLogSink, type Label, type LabelConfig, type LocalizedLabel, type LogEntry, LogLevel, type LogSink, Logger, type LookupAttributeMetadata, type ManyToManyRelationshipMetadata, MetadataCache, MetadataClient, MetadataError, type MoneyAttributeMetadata, type OneToManyRelationshipMetadata, type OptionMetadata, type OptionSetGeneratorOptions, type OptionSetMetadata, type ParameterMeta, type ParameterMetaMap, type ParsedForm, type PicklistAttributeMetadata, SilentLogSink, type SolutionComponent, type StateAttributeMetadata, type StatusAttributeMetadata, type StringAttributeMetadata, type SystemFormMetadata, TypeGenerationOrchestrator, type UnboundActionExecutor, type UnboundActionWithParamsExecutor, type UnboundFunctionExecutor, type XmlElement, type XmlParser, XrmForgeError, configureLogging, createBoundAction, createBoundFunction, createCredential, createLogger, createUnboundAction, createUnboundFunction, defaultXmlParser, disambiguateEnumMembers, executeMultiple, executeRequest, extractControlFields, getJSDocLabel as formatDualLabel, generateActionDeclarations, generateActionModule, generateActivityPartyInterface, generateEntityFieldsEnum, generateEntityForms, generateEntityInterface, generateEntityNamesEnum, generateEntityNavigationProperties, generateEntityOptionSets, generateEnumMembers, generateFormInterface, generateOptionSetEnum, getEntityPropertyType, getFormAttributeType, getFormControlType, getFormMockValueType, getJSDocLabel, getLabelLanguagesParam, getPrimaryLabel, getSecondaryLabel, groupCustomApis, isLookupType, isPartyListType, isRateLimitError, isXrmForgeError, labelToIdentifier, parseForm, shouldIncludeInEntityInterface, toLookupValueProperty, toPascalCase, toSafeIdentifier, withProgress };
2004
+ export { type ActionGeneratorOptions, ApiRequestError, type AttributeMetadata, type AuthConfig, type AuthMethod, AuthenticationError, BindingType, type BoundActionExecutor, type BoundActionWithParamsExecutor, type BoundFunctionExecutor, type CacheStats, type ChangeDetectionResult, ChangeDetector, type ClientCredentialsAuth, ClientState, ClientType, ConfigError, ConsoleLogSink, type CustomApiTypeInfo, DEFAULT_LABEL_CONFIG, DataverseHttpClient, type DateTimeAttributeMetadata, type DecimalAttributeMetadata, type DeviceCodeAuth, DisplayState, type EntityFieldsGeneratorOptions, type EntityGenerationResult, type EntityGeneratorOptions, type EntityMetadata, type EntityNamesGeneratorOptions, type EntityTypeInfo, ErrorCode, FastXmlParser, type FormControl, type FormGeneratorOptions, FormNotificationLevel, type FormSection, type FormTab, type GenerateConfig, type GeneratedFile, GenerationError, type GenerationResult, type GroupedCustomApis, type HttpClientOptions, type IntegerAttributeMetadata, type InteractiveAuth, JsonLogSink, type Label, type LabelConfig, type LocalizedLabel, type LogEntry, LogLevel, type LogSink, Logger, type LookupAttributeMetadata, type ManyToManyRelationshipMetadata, MetadataCache, MetadataClient, MetadataError, type MoneyAttributeMetadata, type OneToManyRelationshipMetadata, OperationType, type OptionMetadata, type OptionSetGeneratorOptions, type OptionSetMetadata, type ParameterMeta, type ParameterMetaMap, type ParsedForm, type PicklistAttributeMetadata, RequiredLevel, SaveMode, SilentLogSink, type SolutionComponent, type StateAttributeMetadata, type StatusAttributeMetadata, type StringAttributeMetadata, StructuralProperty, SubmitMode, type SystemFormMetadata, TypeGenerationOrchestrator, type UnboundActionExecutor, type UnboundActionWithParamsExecutor, type UnboundFunctionExecutor, type XmlElement, type XmlParser, XrmForgeError, configureLogging, createBoundAction, createBoundFunction, createCredential, createLogger, createUnboundAction, createUnboundFunction, defaultXmlParser, disambiguateEnumMembers, executeMultiple, executeRequest, extractControlFields, getJSDocLabel as formatDualLabel, generateActionDeclarations, generateActionModule, generateActivityPartyInterface, generateEntityFieldsEnum, generateEntityForms, generateEntityInterface, generateEntityNamesEnum, generateEntityNavigationProperties, generateEntityOptionSets, generateEnumMembers, generateFormInterface, generateOptionSetEnum, getEntityPropertyType, getFormAttributeType, getFormControlType, getFormMockValueType, getJSDocLabel, getLabelLanguagesParam, getPrimaryLabel, getSecondaryLabel, groupCustomApis, isLookupType, isPartyListType, isRateLimitError, isXrmForgeError, labelToIdentifier, parseForm, parseFormattedValue, parseLookup, parseLookups, select, selectExpand, shouldIncludeInEntityInterface, toLookupValueProperty, toPascalCase, toSafeIdentifier, withProgress };
@@ -0,0 +1,26 @@
1
+ # XrmForge Architecture
2
+
3
+ > **Status:** Living document describing the current implementation state.
4
+ > **Last updated:** 2026-04-04 (Session 10)
5
+ > **Version:** 7 packages, 666+ tests across all packages.
6
+
7
+ ## Chapters
8
+
9
+ 1. [Executive Summary](01-executive-summary.md)
10
+ 2. [Package Architecture](02-packages.md)
11
+ 3. [Generated Types](03-generated-types.md)
12
+ 4. [CLI Commands](04-cli.md)
13
+ 5. [Build Architecture](05-build.md)
14
+ 6. [Incremental Generation](06-incremental.md)
15
+ 7. [HTTP Client](07-http-client.md)
16
+ 8. [Authentication](08-authentication.md)
17
+ 9. [Testing Framework](09-testing.md)
18
+ 10. [ESLint Plugin](10-eslint-plugin.md)
19
+ 11. [AGENT.md System](11-agent-md.md)
20
+ 12. [@types/xrm Pitfalls](12-xrm-pitfalls.md)
21
+ 13. [@xrmforge/helpers Package](13-helpers.md)
22
+ 14. [Showcases](14-showcases.md)
23
+ 15. [CI/CD](15-ci-cd.md)
24
+ 16. [Technical Debt](16-technical-debt.md)
25
+ 17. [Roadmap](17-roadmap.md)
26
+ 18. [Design Principles](18-design-principles.md)
@@ -0,0 +1,11 @@
1
+ # Executive Summary
2
+
3
+ XrmForge is an open-source TypeScript toolkit for type-safe Dynamics 365 / Dataverse WebResource development. It generates TypeScript declarations from live Dataverse metadata, turning runtime string errors into compile-time type errors.
4
+
5
+ **Core value proposition:** Every field name, OptionSet value, tab name, entity name, and subgrid name becomes a typed constant with IDE autocomplete and compile-time validation.
6
+
7
+ **Target audience:** D365 developers who write form scripts (WebResources) in JavaScript/TypeScript and want compile-time safety, zero magic strings, and modern tooling (esbuild, vitest, ESLint).
8
+
9
+ **Tech stack:** TypeScript, pnpm monorepo with Turborepo, esbuild for IIFE bundles, vitest for testing, @azure/identity for authentication, fast-xml-parser for FormXml parsing.
10
+
11
+ **npm organization:** [@xrmforge](https://www.npmjs.com/org/xrmforge)
@@ -0,0 +1,110 @@
1
+ # Package Architecture
2
+
3
+ ## Package Overview
4
+
5
+ | Package | Version | Tests | Description |
6
+ |---------|---------|-------|-------------|
7
+ | @xrmforge/typegen | 0.6.0 | 444 | Core: type generation engine, metadata client, HTTP client, helpers |
8
+ | @xrmforge/cli | 0.4.2 | 10 | CLI: generate, build, init commands |
9
+ | @xrmforge/testing | 0.2.0 | 76 | Test utilities: createFormMock, fireOnChange, setupXrmMock |
10
+ | @xrmforge/helpers | 0.1.0 | 59 | Browser-safe runtime: select(), parseLookup(), typedForm(), Xrm constants, Action executors |
11
+ | @xrmforge/webapi | 0.1.0 | 45 | Type-safe Xrm.WebApi client with QueryBuilder |
12
+ | @xrmforge/devkit | 0.4.0 | 42 | Build orchestration, scaffolding, AGENT.md generation |
13
+ | @xrmforge/eslint-plugin | 0.2.0 | 32 | 5 D365-specific ESLint rules |
14
+
15
+ **Total:** 708 tests across 7 packages.
16
+
17
+ ## Dependency Graph
18
+
19
+ ```
20
+ @xrmforge/cli
21
+ |-- @xrmforge/typegen (generate command)
22
+ |-- @xrmforge/devkit (build + init commands)
23
+ '-- commander (CLI framework)
24
+
25
+ @xrmforge/typegen
26
+ |-- @azure/identity (authentication)
27
+ '-- fast-xml-parser (FormXml parsing)
28
+
29
+ @xrmforge/devkit
30
+ '-- esbuild (IIFE bundling)
31
+
32
+ @xrmforge/testing (no runtime deps)
33
+ @xrmforge/helpers (no runtime deps)
34
+ @xrmforge/webapi (no runtime deps)
35
+ @xrmforge/eslint-plugin (ESLint peer dep)
36
+ ```
37
+
38
+ ## Package Details
39
+
40
+ ### @xrmforge/typegen
41
+
42
+ The core package. Contains:
43
+
44
+ - **TypeGenerationOrchestrator** - Coordinates the entire generation pipeline
45
+ - **MetadataClient** - Queries Dataverse metadata (entities, forms, OptionSets, Custom APIs)
46
+ - **DataverseHttpClient** - Resilient REST client with retry, rate limiting, concurrency control
47
+ - **ChangeDetector** - Incremental generation via RetrieveMetadataChanges
48
+ - **MetadataCache** - Filesystem-based caching with version stamps
49
+ - **Generators** - Entity interfaces, form interfaces, OptionSet enums, Fields enums, EntityNames, Navigation Properties, Action/Function executors
50
+ - **Helpers** - select(), parseLookup(), parseFormattedValue() (moved to @xrmforge/helpers)
51
+ - **Xrm Constants** - DisplayState, FormNotificationLevel, RequiredLevel, SubmitMode, SaveMode, ClientType, ClientState (moved to @xrmforge/helpers)
52
+ - **Authentication** - createCredential() factory for 4 auth methods
53
+ - **Logging** - Scoped loggers with pluggable sinks (Console, JSON, Silent)
54
+ - **Errors** - Structured error hierarchy with ErrorCode enum (AUTH_1xxx, API_2xxx, META_3xxx, GEN_4xxx, CONFIG_5xxx)
55
+
56
+ ### @xrmforge/cli
57
+
58
+ Command-line interface built with commander.js. Three commands:
59
+ - `xrmforge generate` - Orchestrates TypeGenerationOrchestrator
60
+ - `xrmforge build` - Delegates to devkit build()
61
+ - `xrmforge init` - Delegates to devkit scaffoldProject()
62
+
63
+ ### @xrmforge/testing
64
+
65
+ FormContext mocking for unit tests:
66
+ - `createFormMock<TForm>(values)` - Creates a complete mock from simple key-value pairs
67
+ - `MockAttribute` - getValue/setValue, dirty tracking, onChange handlers, required level, submit mode
68
+ - `MockControl` - visible, disabled, label, notifications
69
+ - `MockUi` - Form notifications, tab/section stubs
70
+ - `MockEntity` - Entity ID, name, primary attribute
71
+ - `fireOnChange(fieldName)` - Triggers registered onChange handlers
72
+ - `setupXrmMock(options)` / `teardownXrmMock()` - Global Xrm mock with WebApi/Navigation stubs
73
+
74
+ ### @xrmforge/helpers
75
+
76
+ Consolidates all browser-safe runtime code. Zero Node.js dependencies. Contains:
77
+ - **Web API helpers** - select(), parseLookup(), parseFormattedValue()
78
+ - **Xrm constants** - DisplayState, SubmitMode, RequiredLevel, SaveMode, ClientType, ClientState, FormNotificationLevel, OperationType
79
+ - **Action/Function executors** - createBoundAction(), executeRequest(), withProgress()
80
+ - **typedForm() proxy** - Proxy-based FormContext wrapper where `form.name` delegates to `getAttribute('name')`
81
+
82
+ ### @xrmforge/webapi
83
+
84
+ Type-safe wrapper around Xrm.WebApi:
85
+ - `retrieve<T>(entityName, id, query)` - Single record
86
+ - `retrieveMultiple<T>(entityName, query, options)` - With pagination (maxPages)
87
+ - `create(entityName, data)` - Returns record ID
88
+ - `update(entityName, id, data)` - Void
89
+ - `remove(entityName, id)` - Void
90
+ - `QueryBuilder` - Fluent API: `.select().filter().orderBy().top().expand().build()`
91
+ - `WebApiError` - Structured errors with statusCode, errorCode, innerMessage
92
+
93
+ ### @xrmforge/devkit
94
+
95
+ Build orchestration and project scaffolding:
96
+ - `build(config)` - Parallel esbuild IIFE builds via Promise.allSettled
97
+ - `watch(config)` - esbuild watch mode with rebuild callbacks
98
+ - `scaffoldProject(config)` - Generates 11 project files from templates
99
+ - `validateBuildConfig(config)` / `resolveBuildConfig(config)` - Config validation
100
+ - `BuildError` with codes: CONFIG_INVALID, ENTRY_NOT_FOUND, BUILD_FAILED, WATCH_ERROR
101
+ - Template system: 7 text templates in `src/scaffold/templates/`, loaded via `template-loader.ts`
102
+
103
+ ### @xrmforge/eslint-plugin
104
+
105
+ 5 rules for D365 form scripts (ESLint v9 flat config):
106
+ - `no-xrm-page` (error) - Forbids deprecated Xrm.Page API
107
+ - `no-magic-optionset` (warn) - Forbids magic numbers in OptionSet comparisons
108
+ - `no-sync-webapi` (error) - Forbids synchronous XMLHttpRequest
109
+ - `require-error-handling` (warn) - Requires try/catch in async on* event handlers
110
+ - `require-namespace` (warn) - Forbids window/globalThis assignments
@@ -0,0 +1,176 @@
1
+ # Generated Types
2
+
3
+ Running `xrmforge generate` produces the following TypeScript declarations:
4
+
5
+ ### 3.1 Entity Interfaces (`entities/{entity}.d.ts`)
6
+
7
+ ```typescript
8
+ declare namespace XrmForge.Entities {
9
+ /** Account | Konto */
10
+ interface Account {
11
+ /** Account Name | Kontoname */
12
+ name: string | null;
13
+ accountid: string | null;
14
+ revenue: number | null;
15
+ _parentaccountid_value: string | null; // Lookup GUID
16
+ // ...
17
+ }
18
+ }
19
+ ```
20
+
21
+ **Type mapping:** String/Memo/EntityName to `string`, Integer/BigInt/Decimal/Double/Money to `number`, Boolean to `boolean`, DateTime/Uniqueidentifier/Lookup to `string`, Picklist/State/Status to `number`.
22
+
23
+ ### 3.2 Entity Fields Enums (`entities/{entity}.d.ts`)
24
+
25
+ ```typescript
26
+ declare namespace XrmForge.Entities {
27
+ const enum AccountFields {
28
+ /** Account Name | Kontoname */
29
+ Name = 'name',
30
+ Revenue = 'revenue',
31
+ // all readable attributes
32
+ }
33
+ }
34
+ ```
35
+
36
+ Used for Web API `$select`: `select(AccountFields.Name, AccountFields.Revenue)`.
37
+
38
+ ### 3.3 Navigation Properties (`entities/{entity}.d.ts`)
39
+
40
+ ```typescript
41
+ declare namespace XrmForge.Entities {
42
+ const enum AccountNavigation {
43
+ PrimaryContactId = 'primarycontactid',
44
+ ContactCustomerAccounts = 'contact_customer_accounts',
45
+ // OneToMany + ManyToMany relationships
46
+ }
47
+ }
48
+ ```
49
+
50
+ ### 3.4 Form Interfaces (`forms/{entity}.d.ts`)
51
+
52
+ ```typescript
53
+ declare namespace XrmForge.Forms.Account {
54
+ // Union type restricting valid field names
55
+ type AccountMainFormFields = 'name' | 'telephone1' | 'revenue';
56
+
57
+ // Mapped type: field name to Xrm attribute type
58
+ type AccountMainFormAttributeMap = {
59
+ name: Xrm.Attributes.StringAttribute;
60
+ telephone1: Xrm.Attributes.StringAttribute;
61
+ revenue: Xrm.Attributes.NumberAttribute;
62
+ };
63
+
64
+ // Mapped type: field name to Xrm control type
65
+ type AccountMainFormControlMap = {
66
+ name: Xrm.Controls.StringControl;
67
+ telephone1: Xrm.Controls.StringControl;
68
+ revenue: Xrm.Controls.NumberControl;
69
+ };
70
+
71
+ // Fields enum for autocomplete
72
+ const enum AccountMainFormFieldsEnum {
73
+ /** Account Name | Kontoname */
74
+ AccountName = 'name',
75
+ Telephone1 = 'telephone1',
76
+ Revenue = 'revenue',
77
+ }
78
+
79
+ // Type-safe FormContext with overloaded getAttribute/getControl
80
+ interface AccountMainForm extends Omit<Xrm.FormContext, 'getAttribute' | 'getControl'> {
81
+ getAttribute<K extends AccountMainFormFields>(name: K): AccountMainFormAttributeMap[K];
82
+ getAttribute(index: number): Xrm.Attributes.Attribute;
83
+ getAttribute(): Xrm.Attributes.Attribute[];
84
+
85
+ getControl<K extends AccountMainFormFields>(name: K): AccountMainFormControlMap[K];
86
+ getControl(index: number): Xrm.Controls.Control;
87
+ getControl(): Xrm.Controls.Control[];
88
+ }
89
+ }
90
+ ```
91
+
92
+ **Special controls** are typed based on their FormXml ClassID:
93
+ - Subgrid: `Xrm.Controls.GridControl`
94
+ - Editable Grid: `Xrm.Controls.GridControl`
95
+ - Quick View: `Xrm.Controls.QuickFormControl`
96
+ - Web Resource / iFrame: `Xrm.Controls.IframeControl`
97
+
98
+ ### 3.5 Tabs/Sections/Subgrids/QuickViews Enums
99
+
100
+ ```typescript
101
+ const enum AccountMainFormTabs { Summary = 'SUMMARY_TAB', Details = 'DETAILS_TAB' }
102
+ const enum AccountMainFormSections { General = 'GENERAL', Address = 'ADDRESS' }
103
+ const enum AccountMainFormSubgrids { Contacts = 'Contacts_Subgrid' }
104
+ const enum AccountMainFormQuickViews { ContactPreview = 'ContactQuickView' }
105
+ ```
106
+
107
+ ### 3.6 OptionSet Enums (`optionsets/{entity}.d.ts`)
108
+
109
+ ```typescript
110
+ declare namespace XrmForge.OptionSets.Account {
111
+ /** Account Category Code | Kontokategoriecode */
112
+ const enum AccountCategoryCode {
113
+ /** Preferred Customer | Bevorzugter Kunde */
114
+ PreferredCustomer = 1,
115
+ Standard = 2,
116
+ }
117
+ }
118
+ ```
119
+
120
+ Includes Picklist, Status, State, and MultiSelectPicklist attributes. Duplicate labels are disambiguated with `_{Value}` suffix.
121
+
122
+ ### 3.7 EntityNames Enum (`entity-names.d.ts`)
123
+
124
+ ```typescript
125
+ declare namespace XrmForge {
126
+ const enum EntityNames {
127
+ Account = 'account',
128
+ Contact = 'contact',
129
+ // all entities in scope
130
+ }
131
+ }
132
+ ```
133
+
134
+ ### 3.8 MockValues Types (in form interfaces)
135
+
136
+ ```typescript
137
+ type AccountMainFormMockValues = {
138
+ name?: string | null;
139
+ telephone1?: string | null;
140
+ revenue?: number | null;
141
+ };
142
+ ```
143
+
144
+ Used with `createFormMock<AccountMainForm, AccountMainFormMockValues>({ name: 'Test' })`.
145
+
146
+ ### 3.9 Action/Function Executors (`actions/{entity|global}.d.ts` + `.ts`)
147
+
148
+ **Declaration (.d.ts):**
149
+ ```typescript
150
+ declare namespace XrmForge.Actions {
151
+ interface NormalizePhoneParams { Input: string; AllowSuspicious?: boolean; }
152
+ interface NormalizePhoneResult { Normalized: string; Status: number; }
153
+ }
154
+ ```
155
+
156
+ **Runtime module (.ts):**
157
+ ```typescript
158
+ import { createUnboundAction } from '@xrmforge/typegen';
159
+ export const NormalizePhone = createUnboundAction<NormalizePhoneParams, NormalizePhoneResult>(
160
+ 'markant_NormalizePhone',
161
+ { Input: { typeName: 'String', structuralProperty: 1 } }
162
+ );
163
+ // Usage: const result = await NormalizePhone.execute({ Input: '123' });
164
+ ```
165
+
166
+ Factory functions: `createBoundAction`, `createUnboundAction`, `createBoundFunction`, `createUnboundFunction`. Batch execution via `executeMultiple()`, progress UI via `withProgress()`.
167
+
168
+ ### 3.10 Dual-Language Labels
169
+
170
+ All generated JSDoc comments support dual-language labels:
171
+ ```typescript
172
+ /** Account Name | Kontoname */
173
+ Name = 'name',
174
+ ```
175
+
176
+ German umlauts are transliterated in identifiers: ae, oe, ue, ss (e.g. "Ubergeordnet" becomes `Uebergeordnet`).
@@ -0,0 +1,58 @@
1
+ # CLI Commands
2
+
3
+ ### 4.1 `xrmforge generate`
4
+
5
+ Generates TypeScript declarations from a Dataverse environment.
6
+
7
+ | Flag | Type | Default | Description |
8
+ |------|------|---------|-------------|
9
+ | `--url <url>` | string | required | Dataverse environment URL |
10
+ | `--auth <method>` | string | required | Auth method: client-credentials, interactive, device-code, token |
11
+ | `--tenant-id <id>` | string | varies | Azure AD tenant ID |
12
+ | `--client-id <id>` | string | varies | Azure AD application ID |
13
+ | `--client-secret <s>` | string | varies | Client secret (client-credentials only) |
14
+ | `--token <token>` | string | varies | Pre-acquired bearer token (token auth only) |
15
+ | `--entities <list>` | string | - | Comma-separated entity logical names |
16
+ | `--solutions <list>` | string | - | Comma-separated solution unique names |
17
+ | `--output <dir>` | string | ./typings | Output directory |
18
+ | `--label-language <n>` | string | 1033 | Primary label language (LCID) |
19
+ | `--secondary-language <n>` | string | - | Secondary label language for JSDoc |
20
+ | `--no-forms` | flag | - | Skip form interface generation |
21
+ | `--no-optionsets` | flag | - | Skip OptionSet enum generation |
22
+ | `--actions` | flag | false | Generate Custom API executors |
23
+ | `--actions-filter <prefix>` | string | - | Filter Custom APIs by uniquename prefix |
24
+ | `--cache` | flag | false | Enable metadata caching for incremental generation |
25
+ | `--no-cache` | flag | - | Force full metadata refresh |
26
+ | `--cache-dir <dir>` | string | .xrmforge/cache | Cache directory |
27
+ | `-v, --verbose` | flag | false | Debug logging |
28
+
29
+ At least one of `--entities` or `--solutions` is required.
30
+
31
+ ### 4.2 `xrmforge build`
32
+
33
+ Builds WebResources as IIFE bundles using esbuild (via @xrmforge/devkit).
34
+
35
+ | Flag | Type | Default | Description |
36
+ |------|------|---------|-------------|
37
+ | `--watch` | flag | false | Watch mode with incremental rebuilds |
38
+ | `--minify` | flag | from config | Override minification setting |
39
+ | `--no-sourcemap` | flag | - | Disable source maps |
40
+ | `--out-dir <dir>` | string | from config | Override output directory |
41
+ | `-v, --verbose` | flag | false | Show error stacks |
42
+
43
+ Reads configuration from `xrmforge.config.json`.
44
+
45
+ ### 4.3 `xrmforge init`
46
+
47
+ Scaffolds a new D365 form scripting project.
48
+
49
+ | Flag | Type | Default | Description |
50
+ |------|------|---------|-------------|
51
+ | `[dir]` | positional | . | Target directory |
52
+ | `--name <name>` | string | dir name | Project name for package.json |
53
+ | `--prefix <prefix>` | string | contoso | Publisher prefix |
54
+ | `--namespace <ns>` | string | PascalCase(prefix) | Base namespace for scripts |
55
+ | `--skip-install` | flag | false | Skip npm install |
56
+ | `--force` | flag | false | Allow non-empty directories |
57
+
58
+ Generates 11 files: package.json, tsconfig.json, xrmforge.config.json, vitest.config.ts, .gitignore, AGENT.md, example-form.ts, example-form.test.ts, typings/.gitkeep, GitHub Actions CI, Azure DevOps Pipeline.