@xrmforge/helpers 0.3.0 → 0.4.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.
package/dist/index.d.ts CHANGED
@@ -407,108 +407,127 @@ declare function withProgress<T>(message: string, operation: () => Promise<T>):
407
407
  * to form fields. Instead of `form.getAttribute("name").setValue("X")`,
408
408
  * write `form.name.setValue("X")`.
409
409
  *
410
- * Works with generated form types from @xrmforge/typegen. The generated
411
- * forms export Fields, AttributeMap, and ControlMap types that TypedForm uses
412
- * for full compile-time type safety.
410
+ * Works with generated form types from @xrmforge/typegen. Since v0.9.2,
411
+ * typegen generates a `FormTypeInfo` interface per form that bundles
412
+ * Fields, AttributeMap, and ControlMap for reliable type extraction.
413
413
  *
414
414
  * @example
415
415
  * ```typescript
416
416
  * import { typedForm } from '@xrmforge/helpers';
417
417
  * import type { AccountLMFirmaForm } from '../../generated/forms/account.js';
418
- * import { AccountLMFirmaFormFieldsEnum as Fields } from '../../generated/forms/account.js';
419
418
  *
420
- * export const onLoad = wrapHandler('LM.Account.onLoad', logger, (ctx) => {
421
- * const form = typedForm<AccountLMFirmaForm>(ctx.getFormContext());
422
- *
423
- * // Direct field access - fully typed
424
- * const name = form.name.getValue(); // string | null (StringAttribute)
425
- * form.revenue.setValue(150000); // NumberAttribute
426
- * const parent = form.parentaccountid.getValue(); // LookupValue[] | null
427
- *
428
- * // Control access
429
- * form.$control('name').setDisabled(true);
430
- *
431
- * // Full FormContext for ui, data, tabs
432
- * form.$context.ui.setFormNotification('Loaded', FormNotificationLevel.Info, 'load');
433
- *
434
- * // Fields enum still works for addOnChange, WebApi queries, etc.
435
- * form.$context.getAttribute(Fields.Name).addOnChange(() => { ... });
436
- * });
419
+ * const form = typedForm<AccountLMFirmaForm>(ctx.getFormContext());
420
+ * form.name.getValue(); // string | null (typed)
421
+ * form.revenue.setValue(150000); // NumberAttribute (typed)
422
+ * form.$context.ui.tabs.get(...); // Full FormContext access
423
+ * form.$control('name'); // Control access
424
+ * form.$unsafe('off_form_field'); // Access fields not on the form
437
425
  * ```
438
426
  */
439
427
  /**
440
- * Extract the Fields union type from a generated Form interface.
441
- *
442
- * Generated interfaces follow the pattern:
443
- * getAttribute<K extends SomeFormFields>(name: K): SomeFormAttributeMap[K];
444
- * getAttribute(index: number): Xrm.Attributes.Attribute;
445
- * getAttribute(): Xrm.Attributes.Attribute[];
446
- *
447
- * TypeScript resolves overloaded function types to the LAST matching signature.
448
- * For our generated interfaces, the generic overload is first, so conditional
449
- * type inference on the function signature gets the wrong overload.
428
+ * Protocol interface generated by typegen for each form.
429
+ * Bundles Fields, AttributeMap, and ControlMap so typedForm can extract
430
+ * them reliably without fragile Conditional Type inference on overloads.
450
431
  *
451
- * Solution: We use a different extraction strategy. The generated interfaces
452
- * extend Omit<Xrm.FormContext, 'getAttribute' | 'getControl'>, so we know
453
- * the first getAttribute overload has the K constraint. We extract it by
454
- * matching on the mapped return type pattern.
432
+ * Generated as: `export interface MyFormTypeInfo { fields: ...; attributes: ...; controls: ...; form: ...; }`
455
433
  */
456
- type ExtractFields<TForm> = TForm extends {
457
- getAttribute<K extends infer F>(name: K): unknown;
458
- } ? F extends string ? F : never : never;
434
+ interface FormTypeInfoProtocol {
435
+ fields: string;
436
+ attributes: Record<string, Xrm.Attributes.Attribute>;
437
+ controls: Record<string, Xrm.Controls.Control>;
438
+ form: object;
439
+ }
459
440
  /**
460
- * Extract the AttributeMap from a generated Form interface.
441
+ * Extract Fields from a Form interface.
461
442
  *
462
- * Maps each field name to its Xrm.Attributes type by calling getAttribute
463
- * with each specific field name from the Fields union.
443
+ * Strategy: Check if TForm has a companion TypeInfo interface (generated by
444
+ * typegen >= 0.9.2). If so, extract fields directly. Otherwise, fall back
445
+ * to Conditional Type inference on getAttribute (works in same compilation
446
+ * unit but may fail across package boundaries in TS 5.9+).
464
447
  */
465
- type ExtractAttributeMap<TForm, TFields extends string> = {
448
+ type ExtractFields<TForm> = TForm extends FormTypeInfoProtocol ? TForm['fields'] : TForm extends {
449
+ getAttribute<K extends infer F>(name: K): unknown;
450
+ } ? F extends string ? F : never : never;
451
+ type ExtractAttributeMap<TForm, TFields extends string> = TForm extends FormTypeInfoProtocol ? TForm['attributes'] : {
466
452
  [K in TFields]: TForm extends {
467
453
  getAttribute(name: K): infer R;
468
454
  } ? R extends Xrm.Attributes.Attribute ? R : Xrm.Attributes.Attribute : Xrm.Attributes.Attribute;
469
455
  };
470
- /**
471
- * Extract the ControlMap from a generated Form interface.
472
- */
473
- type ExtractControlMap<TForm, TFields extends string> = {
456
+ type ExtractControlMap<TForm, TFields extends string> = TForm extends FormTypeInfoProtocol ? TForm['controls'] : {
474
457
  [K in TFields]: TForm extends {
475
458
  getControl(name: K): infer R;
476
459
  } ? R extends Xrm.Controls.Control ? R : Xrm.Controls.Control : Xrm.Controls.Control;
477
460
  };
461
+ type ExtractFormContext<TForm> = TForm extends FormTypeInfoProtocol ? TForm['form'] : TForm extends Xrm.FormContext ? TForm : Xrm.FormContext;
478
462
  /**
479
463
  * TypedForm: proxy type that maps field names to their attribute types.
480
464
  *
481
465
  * Provides direct property access to form fields (e.g. `form.name` returns
482
- * the StringAttribute), plus `$context` for full FormContext access and
483
- * `$control(name)` for typed control access.
466
+ * the StringAttribute), plus:
467
+ * - `$context` for full FormContext access (ui, data, tabs, getAttribute with addOnChange)
468
+ * - `$control(name)` for typed control access
469
+ * - `$unsafe(name)` for off-form field access (fields loaded by D365 but not on the form)
484
470
  */
485
471
  type TypedForm<TForm, TFields extends string = ExtractFields<TForm>, TAttrMap extends Record<string, Xrm.Attributes.Attribute> = ExtractAttributeMap<TForm, TFields>, TCtrlMap extends Record<string, Xrm.Controls.Control> = ExtractControlMap<TForm, TFields>> = {
486
472
  /** Direct field access: form.fieldName returns the typed Attribute */
487
473
  readonly [K in TFields]: K extends keyof TAttrMap ? TAttrMap[K] : Xrm.Attributes.Attribute;
488
474
  } & {
489
- /** Access the underlying FormContext for ui, data, tabs, etc. */
490
- readonly $context: TForm extends Xrm.FormContext ? TForm : Xrm.FormContext;
475
+ /** Access the underlying FormContext for ui, data, tabs, addOnChange, etc. */
476
+ readonly $context: ExtractFormContext<TForm>;
491
477
  /** Access a typed control by field name */
492
478
  $control<K extends TFields>(name: K): K extends keyof TCtrlMap ? TCtrlMap[K] : Xrm.Controls.Control;
479
+ /**
480
+ * Access an off-form field (loaded by D365 but not on the current form layout).
481
+ * Returns null if the attribute does not exist.
482
+ * Use this for fields like 'lm_genehmigt' that are not in the form definition
483
+ * but are accessible at runtime via formContext.getAttribute().
484
+ */
485
+ $unsafe(name: string): Xrm.Attributes.Attribute | null;
493
486
  };
494
487
  /**
495
488
  * Create a typed form proxy around a FormContext.
496
489
  *
497
- * The proxy intercepts property access and delegates to getAttribute().
498
- * Special properties `$context` and `$control` provide access to the full
499
- * FormContext and controls respectively.
490
+ * Accepts either a Form interface or a FormTypeInfo interface as type parameter.
491
+ * When using FormTypeInfo (generated by typegen >= 0.9.2), type extraction is
492
+ * guaranteed to work across all TypeScript versions.
500
493
  *
501
- * Usage with a single type parameter (recommended):
494
+ * @example
502
495
  * ```typescript
496
+ * // Recommended: use Form interface directly (requires typegen >= 0.9.2 for TypeInfo)
503
497
  * const form = typedForm<AccountLMFirmaForm>(ctx.getFormContext());
504
- * form.name.getValue(); // typed as StringAttribute
498
+ *
499
+ * // Alternative: use TypeInfo for explicit type extraction
500
+ * const form = typedForm<AccountLMFirmaFormTypeInfo>(ctx.getFormContext());
505
501
  * ```
506
502
  *
507
503
  * @param formContext - The Xrm.FormContext from executionContext.getFormContext()
508
504
  * @returns A proxy with direct typed property access to form fields
509
505
  */
510
506
  declare function typedForm<TForm>(formContext: Xrm.FormContext): TypedForm<TForm>;
507
+ /**
508
+ * Normalize a GUID: strip curly braces and lowercase.
509
+ *
510
+ * Use this for GUIDs from sources other than formLookupId():
511
+ * - `formContext.data.entity.getId()` returns GUIDs with braces
512
+ * - WebApi `_value` fields may have braces depending on annotations
513
+ * - Custom API responses may return GUIDs in varying formats
514
+ *
515
+ * formLookupId() already normalizes internally, so this is NOT needed for
516
+ * lookup field access. Only use for getId(), WebApi responses, and comparisons.
517
+ *
518
+ * @param guid - A GUID string, possibly with braces and mixed case
519
+ * @returns Normalized GUID (lowercase, no braces), or empty string if null/empty
520
+ *
521
+ * @example
522
+ * ```typescript
523
+ * const recordId = normalizeGuid(form.$context.data.entity.getId());
524
+ * // "{A1B2C3D4-...}" -> "a1b2c3d4-..."
525
+ *
526
+ * const currencyId = normalizeGuid(result._transactioncurrencyid_value as string);
527
+ * ```
528
+ */
529
+ declare function normalizeGuid(guid: string | null | undefined): string;
511
530
  /** @deprecated Use ExtractFields<TForm> instead */
512
531
  type FormFields<TForm> = ExtractFields<TForm>;
513
532
 
514
- export { BindingType, type BoundActionExecutor, type BoundActionWithParamsExecutor, type BoundFunctionExecutor, ClientState, ClientType, DisplayState, type FormFields, FormNotificationLevel, OperationType, type ParameterMeta, type ParameterMetaMap, RequiredLevel, SaveMode, StructuralProperty, SubmitMode, type TypedForm, type UnboundActionExecutor, type UnboundActionWithParamsExecutor, type UnboundFunctionExecutor, createBoundAction, createBoundFunction, createUnboundAction, createUnboundFunction, executeMultiple, executeRequest, formLookup, formLookupId, parseFormattedValue, parseLookup, parseLookups, select, selectExpand, typedForm, withProgress };
533
+ export { BindingType, type BoundActionExecutor, type BoundActionWithParamsExecutor, type BoundFunctionExecutor, ClientState, ClientType, DisplayState, type FormFields, FormNotificationLevel, type FormTypeInfoProtocol, OperationType, type ParameterMeta, type ParameterMetaMap, RequiredLevel, SaveMode, StructuralProperty, SubmitMode, type TypedForm, type UnboundActionExecutor, type UnboundActionWithParamsExecutor, type UnboundFunctionExecutor, createBoundAction, createBoundFunction, createUnboundAction, createUnboundFunction, executeMultiple, executeRequest, formLookup, formLookupId, normalizeGuid, parseFormattedValue, parseLookup, parseLookups, select, selectExpand, typedForm, withProgress };
package/dist/index.js CHANGED
@@ -308,6 +308,9 @@ function typedForm(formContext) {
308
308
  if (prop === "$control") {
309
309
  return (name) => formContext.getControl(name);
310
310
  }
311
+ if (prop === "$unsafe") {
312
+ return (name) => formContext.getAttribute(name);
313
+ }
311
314
  const attr = formContext.getAttribute(prop);
312
315
  if (attr) return attr;
313
316
  return formContext[prop];
@@ -319,11 +322,15 @@ function typedForm(formContext) {
319
322
  },
320
323
  has(_target, prop) {
321
324
  if (typeof prop !== "string") return false;
322
- if (prop === "$context" || prop === "$control") return true;
325
+ if (prop === "$context" || prop === "$control" || prop === "$unsafe") return true;
323
326
  return formContext.getAttribute(prop) !== null;
324
327
  }
325
328
  });
326
329
  }
330
+ function normalizeGuid(guid) {
331
+ if (!guid) return "";
332
+ return guid.replace(/[{}]/g, "").toLowerCase();
333
+ }
327
334
  export {
328
335
  BindingType,
329
336
  ClientState,
@@ -343,6 +350,7 @@ export {
343
350
  executeRequest,
344
351
  formLookup,
345
352
  formLookupId,
353
+ normalizeGuid,
346
354
  parseFormattedValue,
347
355
  parseLookup,
348
356
  parseLookups,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/webapi-helpers.ts","../src/xrm-constants.ts","../src/action-runtime.ts","../src/typed-form.ts"],"sourcesContent":["/**\r\n * @xrmforge/helpers - Web API Helper Functions\r\n *\r\n * Lightweight utility functions for building OData query strings\r\n * with type-safe field names from generated Fields enums.\r\n *\r\n * Zero runtime overhead when used with const enums (values are inlined).\r\n *\r\n * @example\r\n * ```typescript\r\n * import { select } from '@xrmforge/helpers';\r\n *\r\n * Xrm.WebApi.retrieveRecord(ref.entityType, ref.id, select(\r\n * AccountFields.Name,\r\n * AccountFields.WebsiteUrl,\r\n * AccountFields.Address1Line1,\r\n * ));\r\n * ```\r\n */\r\n\r\n/**\r\n * Build an OData $select query string from field names.\r\n *\r\n * Accepts either variadic arguments or a single array:\r\n * - `select(Fields.Name, Fields.Email)` (variadic)\r\n * - `select([Fields.Name, Fields.Email])` (array)\r\n *\r\n * @param fields - Field names (use generated Fields enum for type safety)\r\n * @returns OData query string (e.g. \"?$select=name,websiteurl,address1_line1\")\r\n */\r\nexport function select(fields: string[]): string;\r\nexport function select(...fields: string[]): string;\r\nexport function select(...args: string[] | [string[]]): string {\r\n const fields = args.length === 1 && Array.isArray(args[0]) ? args[0] : args as string[];\r\n if (fields.length === 0) return '';\r\n return `?$select=${fields.join(',')}`;\r\n}\r\n\r\n/**\r\n * Parse a lookup field from a Dataverse Web API response into a LookupValue.\r\n *\r\n * Dataverse returns lookups as `_fieldname_value` with OData annotations:\r\n * - `_fieldname_value` (GUID)\r\n * - `_fieldname_value@OData.Community.Display.V1.FormattedValue` (display name)\r\n * - `_fieldname_value@Microsoft.Dynamics.CRM.lookuplogicalname` (entity type)\r\n *\r\n * This function extracts all three into an `Xrm.LookupValue` object.\r\n *\r\n * @param response - The raw Web API response object\r\n * @param navigationProperty - Navigation property name (use NavigationProperties enum for type safety)\r\n * @returns Xrm.LookupValue or null if the lookup is empty\r\n *\r\n * @example\r\n * ```typescript\r\n * // With NavigationProperties enum (recommended):\r\n * parseLookup(result, AccountNav.Country);\r\n *\r\n * // Or with navigation property name directly:\r\n * parseLookup(result, 'markant_address1_countryid');\r\n * ```\r\n */\r\nexport function parseLookup(\r\n response: Record<string, unknown>,\r\n navigationProperty: string,\r\n): { id: string; name: string; entityType: string } | null {\r\n const key = `_${navigationProperty}_value`;\r\n const id = response[key] as string | undefined;\r\n if (!id) return null;\r\n\r\n return {\r\n id,\r\n name: (response[`${key}@OData.Community.Display.V1.FormattedValue`] as string) ?? '',\r\n entityType: (response[`${key}@Microsoft.Dynamics.CRM.lookuplogicalname`] as string) ?? '',\r\n };\r\n}\r\n\r\n/**\r\n * Parse multiple lookup fields from a Dataverse Web API response at once.\r\n *\r\n * @param response - The raw Web API response object\r\n * @param navigationProperties - Navigation property names to parse\r\n * @returns Map of navigation property name to LookupValue (null entries omitted)\r\n *\r\n * @example\r\n * ```typescript\r\n * const lookups = parseLookups(result, ['markant_address1_countryid', 'parentaccountid']);\r\n * formContext.getAttribute(Fields.Country).setValue(\r\n * lookups.markant_address1_countryid ? [lookups.markant_address1_countryid] : null\r\n * );\r\n * ```\r\n */\r\nexport function parseLookups(\r\n response: Record<string, unknown>,\r\n navigationProperties: string[],\r\n): Record<string, { id: string; name: string; entityType: string } | null> {\r\n const result: Record<string, { id: string; name: string; entityType: string } | null> = {};\r\n for (const prop of navigationProperties) {\r\n result[prop] = parseLookup(response, prop);\r\n }\r\n return result;\r\n}\r\n\r\n/**\r\n * Get the formatted (display) value of any field from a Web API response.\r\n *\r\n * Works for OptionSets, Lookups, DateTimes, Money, and other formatted fields.\r\n *\r\n * @param response - The raw Web API response object\r\n * @param fieldName - The field logical name (e.g. \"statecode\", \"createdon\")\r\n * @returns The formatted string value, or null if not available\r\n *\r\n * @example\r\n * ```typescript\r\n * const status = parseFormattedValue(result, 'statecode');\r\n * // \"Active\" (instead of 0)\r\n * ```\r\n */\r\nexport function parseFormattedValue(\r\n response: Record<string, unknown>,\r\n fieldName: string,\r\n): string | null {\r\n return (response[`${fieldName}@OData.Community.Display.V1.FormattedValue`] as string) ?? null;\r\n}\r\n\r\n/**\r\n * Build an OData $select and $expand query string.\r\n *\r\n * @param fields - Field names to select\r\n * @param expand - Navigation property to expand (optional)\r\n * @returns OData query string\r\n *\r\n * @example\r\n * ```typescript\r\n * Xrm.WebApi.retrieveRecord(\"account\", id, selectExpand(\r\n * [AccountFields.Name, AccountFields.WebsiteUrl],\r\n * \"primarycontactid($select=fullname,emailaddress1)\"\r\n * ));\r\n * ```\r\n */\r\nexport function selectExpand(fields: string[], expand: string): string {\r\n const parts: string[] = [];\r\n if (fields.length > 0) parts.push(`$select=${fields.join(',')}`);\r\n if (expand) parts.push(`$expand=${expand}`);\r\n return parts.length > 0 ? `?${parts.join('&')}` : '';\r\n}\r\n\r\n// ─── Form Lookup Helpers ────────────────────────────────────────────────────\r\n\r\n/**\r\n * Extract the first lookup value from a FormContext lookup attribute.\r\n *\r\n * Centralizes the common pattern of reading a lookup from a form field,\r\n * handling null/empty arrays, and normalizing the GUID (removing braces).\r\n *\r\n * @param attr - A lookup attribute from formContext.getAttribute()\r\n * @returns Xrm.LookupValue with normalized id (no braces), or null if empty\r\n *\r\n * @example\r\n * ```typescript\r\n * import { formLookup } from '@xrmforge/helpers';\r\n * const customer = formLookup(form.getAttribute(Fields.CustomerId));\r\n * if (customer) {\r\n * console.log(customer.id, customer.name, customer.entityType);\r\n * }\r\n * ```\r\n */\r\nexport function formLookup(\r\n attr: { getValue(): { id: string; name?: string; entityType: string }[] | null },\r\n): { id: string; name: string; entityType: string } | null {\r\n const values = attr.getValue();\r\n if (!values || values.length === 0) return null;\r\n const first = values[0]!;\r\n return {\r\n id: first.id.replace(/[{}]/g, ''),\r\n name: first.name ?? '',\r\n entityType: first.entityType,\r\n };\r\n}\r\n\r\n/**\r\n * Extract just the normalized GUID from a FormContext lookup attribute.\r\n *\r\n * Shorthand for the most common lookup use case: getting the record ID\r\n * for a Web API call or comparison.\r\n *\r\n * @param attr - A lookup attribute from formContext.getAttribute()\r\n * @returns Normalized GUID string (no braces), or null if empty\r\n *\r\n * @example\r\n * ```typescript\r\n * import { formLookupId } from '@xrmforge/helpers';\r\n * const accountId = formLookupId(form.getAttribute(Fields.AccountId));\r\n * if (accountId) {\r\n * await Xrm.WebApi.retrieveRecord(EntityNames.Account, accountId, select(...));\r\n * }\r\n * ```\r\n */\r\nexport function formLookupId(\r\n attr: { getValue(): { id: string }[] | null },\r\n): string | null {\r\n const values = attr.getValue();\r\n if (!values || values.length === 0) return null;\r\n return values[0]!.id.replace(/[{}]/g, '');\r\n}\r\n","/**\r\n * @xrmforge/helpers - Xrm API Constants\r\n *\r\n * Const enums for all common Xrm string/number constants.\r\n * Eliminates raw strings in D365 form scripts.\r\n *\r\n * @types/xrm defines these as string literal types for compile-time checking,\r\n * but does NOT provide runtime constants (XrmEnum is not available at runtime).\r\n * These const enums are erased at compile time (zero runtime overhead).\r\n *\r\n * @example\r\n * ```typescript\r\n * import { DisplayState } from '@xrmforge/helpers';\r\n *\r\n * if (tab.getDisplayState() === DisplayState.Expanded) { ... }\r\n * ```\r\n */\r\n\r\n/** Tab/Section display state */\r\nexport const enum DisplayState {\r\n Expanded = 'expanded',\r\n Collapsed = 'collapsed',\r\n}\r\n\r\n// FormType: use XrmEnum.FormType from @types/xrm (already defined as const enum there)\r\n\r\n/** Form notification level (formContext.ui.setFormNotification) */\r\nexport const enum FormNotificationLevel {\r\n Error = 'ERROR',\r\n Warning = 'WARNING',\r\n Info = 'INFO',\r\n}\r\n\r\n/** Attribute required level (attribute.setRequiredLevel) */\r\nexport const enum RequiredLevel {\r\n None = 'none',\r\n Required = 'required',\r\n Recommended = 'recommended',\r\n}\r\n\r\n/** Attribute submit mode (attribute.setSubmitMode) */\r\nexport const enum SubmitMode {\r\n Always = 'always',\r\n Never = 'never',\r\n Dirty = 'dirty',\r\n}\r\n\r\n/** Save mode (eventArgs.getSaveMode()) */\r\nexport const enum SaveMode {\r\n Save = 1,\r\n SaveAndClose = 2,\r\n Deactivate = 5,\r\n Reactivate = 6,\r\n Send = 7,\r\n Disqualify = 15,\r\n Qualify = 16,\r\n Assign = 47,\r\n SaveAsCompleted = 58,\r\n SaveAndNew = 59,\r\n AutoSave = 70,\r\n}\r\n\r\n/** Client type (Xrm.Utility.getGlobalContext().client.getClient()) */\r\nexport const enum ClientType {\r\n Web = 'Web',\r\n Outlook = 'Outlook',\r\n Mobile = 'Mobile',\r\n}\r\n\r\n/** Client state (Xrm.Utility.getGlobalContext().client.getClientState()) */\r\nexport const enum ClientState {\r\n Online = 'Online',\r\n Offline = 'Offline',\r\n}\r\n\r\n// WebApi Execute Constants\r\n\r\n/** Operation type for Xrm.WebApi.execute getMetadata().operationType */\r\nexport const enum OperationType {\r\n /** Custom Action or OOB Action (POST) */\r\n Action = 0,\r\n /** Custom Function or OOB Function (GET) */\r\n Function = 1,\r\n /** CRUD operation (Create, Retrieve, Update, Delete) */\r\n CRUD = 2,\r\n}\r\n\r\n/** Structural property for getMetadata().parameterTypes[].structuralProperty */\r\nexport const enum StructuralProperty {\r\n Unknown = 0,\r\n PrimitiveType = 1,\r\n ComplexType = 2,\r\n EnumerationType = 3,\r\n Collection = 4,\r\n EntityType = 5,\r\n}\r\n\r\n/** Binding type for Custom API definitions */\r\nexport const enum BindingType {\r\n /** Not bound to an entity (globally callable) */\r\n Global = 0,\r\n /** Bound to a single entity record */\r\n Entity = 1,\r\n /** Bound to an entity collection */\r\n EntityCollection = 2,\r\n}\r\n","/**\r\n * @xrmforge/helpers - Action/Function Runtime Helpers\r\n *\r\n * Factory functions for type-safe Custom API execution.\r\n * These are imported by generated action/function modules.\r\n *\r\n * Design:\r\n * - `createBoundAction` / `createUnboundAction`: Produce executor objects\r\n * with `.execute()` (calls Xrm.WebApi) and `.request()` (for executeMultiple)\r\n * - `executeRequest`: Central execute wrapper (single place for the `as any` cast)\r\n * - `withProgress`: Convenience wrapper with progress indicator + error dialog\r\n *\r\n * @example\r\n * ```typescript\r\n * // Generated code (in generated/actions/quote.ts):\r\n * import { createBoundAction } from '@xrmforge/helpers';\r\n * export const WinQuote = createBoundAction('markant_winquote', 'quote');\r\n *\r\n * // Developer code (in quote-form.ts):\r\n * import { WinQuote } from '../generated/actions/quote';\r\n * const response = await WinQuote.execute(recordId);\r\n * ```\r\n */\r\n\r\nimport { OperationType, StructuralProperty } from './xrm-constants.js';\r\n\r\n// Types\r\n\r\n/** Parameter metadata for getMetadata().parameterTypes */\r\nexport interface ParameterMeta {\r\n typeName: string;\r\n structuralProperty: number;\r\n}\r\n\r\n/** Map of parameter names to their OData metadata */\r\nexport type ParameterMetaMap = Record<string, ParameterMeta>;\r\n\r\n/** Executor for a bound action without additional parameters */\r\nexport interface BoundActionExecutor<TResult = void> {\r\n execute(recordId: string): Promise<TResult extends void ? Response : TResult>;\r\n request(recordId: string): Record<string, unknown>;\r\n}\r\n\r\n/** Executor for a bound action with typed parameters */\r\nexport interface BoundActionWithParamsExecutor<TParams, TResult = void> {\r\n execute(recordId: string, params: TParams): Promise<TResult extends void ? Response : TResult>;\r\n request(recordId: string, params: TParams): Record<string, unknown>;\r\n}\r\n\r\n/** Executor for an unbound action without parameters */\r\nexport interface UnboundActionExecutor<TResult = void> {\r\n execute(): Promise<TResult extends void ? Response : TResult>;\r\n request(): Record<string, unknown>;\r\n}\r\n\r\n/** Executor for an unbound action with typed parameters and optional typed response */\r\nexport interface UnboundActionWithParamsExecutor<TParams, TResult = void> {\r\n execute(params: TParams): Promise<TResult extends void ? Response : TResult>;\r\n request(params: TParams): Record<string, unknown>;\r\n}\r\n\r\n/** Executor for an unbound function with typed response */\r\nexport interface UnboundFunctionExecutor<TResult> {\r\n execute(): Promise<TResult>;\r\n request(): Record<string, unknown>;\r\n}\r\n\r\n/** Executor for a bound function with typed response */\r\nexport interface BoundFunctionExecutor<TResult> {\r\n execute(recordId: string): Promise<TResult>;\r\n request(recordId: string): Record<string, unknown>;\r\n}\r\n\r\n// Central Execute\r\n\r\n/**\r\n * Execute a single request via Xrm.WebApi.online.execute().\r\n *\r\n * This is the ONLY place in the entire framework where the `as any` cast happens.\r\n * All generated executors call this function internally.\r\n */\r\nexport function executeRequest(request: Record<string, unknown>): Promise<Response> {\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n return (Xrm.WebApi as any).online.execute(request) as Promise<Response>;\r\n}\r\n\r\n/**\r\n * Execute multiple requests via Xrm.WebApi.online.executeMultiple().\r\n *\r\n * @param requests - Array of request objects (from `.request()` factories).\r\n * Wrap a subset in an inner array for transactional changeset execution.\r\n */\r\nexport function executeMultiple(\r\n requests: Array<Record<string, unknown> | Array<Record<string, unknown>>>,\r\n): Promise<Response[]> {\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n return (Xrm.WebApi as any).online.executeMultiple(requests) as Promise<Response[]>;\r\n}\r\n\r\n// Request Builder (internal)\r\n\r\nfunction cleanRecordId(id: string): string {\r\n return id.replace(/[{}]/g, '');\r\n}\r\n\r\nfunction buildBoundRequest(\r\n operationName: string,\r\n entityLogicalName: string,\r\n operationType: OperationType,\r\n recordId: string,\r\n paramMeta?: ParameterMetaMap,\r\n params?: Record<string, unknown>,\r\n): Record<string, unknown> {\r\n const parameterTypes: Record<string, ParameterMeta> = {\r\n entity: {\r\n typeName: `mscrm.${entityLogicalName}`,\r\n structuralProperty: StructuralProperty.EntityType,\r\n },\r\n };\r\n\r\n if (paramMeta) {\r\n for (const [key, meta] of Object.entries(paramMeta)) {\r\n parameterTypes[key] = meta;\r\n }\r\n }\r\n\r\n const request: Record<string, unknown> = {\r\n getMetadata: () => ({\r\n boundParameter: 'entity',\r\n parameterTypes,\r\n operationName,\r\n operationType,\r\n }),\r\n entity: {\r\n id: cleanRecordId(recordId),\r\n entityType: entityLogicalName,\r\n },\r\n };\r\n\r\n if (params) {\r\n for (const [key, value] of Object.entries(params)) {\r\n request[key] = value;\r\n }\r\n }\r\n\r\n return request;\r\n}\r\n\r\nfunction buildUnboundRequest(\r\n operationName: string,\r\n operationType: OperationType,\r\n paramMeta?: ParameterMetaMap,\r\n params?: Record<string, unknown>,\r\n): Record<string, unknown> {\r\n const parameterTypes: Record<string, ParameterMeta> = {};\r\n\r\n if (paramMeta) {\r\n for (const [key, meta] of Object.entries(paramMeta)) {\r\n parameterTypes[key] = meta;\r\n }\r\n }\r\n\r\n const request: Record<string, unknown> = {\r\n getMetadata: () => ({\r\n boundParameter: null,\r\n parameterTypes,\r\n operationName,\r\n operationType,\r\n }),\r\n };\r\n\r\n if (params) {\r\n for (const [key, value] of Object.entries(params)) {\r\n request[key] = value;\r\n }\r\n }\r\n\r\n return request;\r\n}\r\n\r\n// Action Factories\r\n\r\n/**\r\n * Create an executor for a bound action (entity-bound) without parameters or typed response.\r\n *\r\n * @param operationName - Custom API unique name (e.g. \"markant_winquote\")\r\n * @param entityLogicalName - Entity logical name (e.g. \"quote\")\r\n */\r\nexport function createBoundAction(\r\n operationName: string,\r\n entityLogicalName: string,\r\n): BoundActionExecutor;\r\n\r\n/**\r\n * Create an executor for a bound action without parameters but with typed response.\r\n *\r\n * @param operationName - Custom API unique name\r\n * @param entityLogicalName - Entity logical name\r\n */\r\nexport function createBoundAction<TResult>(\r\n operationName: string,\r\n entityLogicalName: string,\r\n): BoundActionExecutor<TResult>;\r\n\r\n/**\r\n * Create an executor for a bound action with typed parameters and optional typed response.\r\n *\r\n * @param operationName - Custom API unique name\r\n * @param entityLogicalName - Entity logical name\r\n * @param paramMeta - Parameter metadata map (parameter name to OData type info)\r\n */\r\nexport function createBoundAction<\r\n TParams extends Record<string, unknown>,\r\n TResult = void,\r\n>(\r\n operationName: string,\r\n entityLogicalName: string,\r\n paramMeta: ParameterMetaMap,\r\n): BoundActionWithParamsExecutor<TParams, TResult>;\r\n\r\nexport function createBoundAction<\r\n TParams extends Record<string, unknown>,\r\n TResult = void,\r\n>(\r\n operationName: string,\r\n entityLogicalName: string,\r\n paramMeta?: ParameterMetaMap,\r\n): BoundActionExecutor<TResult> | BoundActionWithParamsExecutor<TParams, TResult> {\r\n return {\r\n async execute(recordId: string, params?: TParams): Promise<TResult extends void ? Response : TResult> {\r\n const req = buildBoundRequest(\r\n operationName, entityLogicalName, OperationType.Action,\r\n recordId, paramMeta, params,\r\n );\r\n const response = await executeRequest(req);\r\n if (!response.ok) {\r\n const errorText = await response.text();\r\n throw new Error(errorText);\r\n }\r\n // Parse JSON when response properties are defined (TResult is not void)\r\n if (response.status !== 204) {\r\n return response.json() as Promise<TResult extends void ? Response : TResult>;\r\n }\r\n return response as TResult extends void ? Response : TResult;\r\n },\r\n request(recordId: string, params?: TParams): Record<string, unknown> {\r\n return buildBoundRequest(\r\n operationName, entityLogicalName, OperationType.Action,\r\n recordId, paramMeta, params,\r\n );\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Create an executor for an unbound (global) action without parameters or typed response.\r\n *\r\n * @param operationName - Custom API unique name\r\n */\r\nexport function createUnboundAction(\r\n operationName: string,\r\n): UnboundActionExecutor;\r\n\r\n/**\r\n * Create an executor for an unbound action without parameters but with typed response.\r\n *\r\n * @param operationName - Custom API unique name\r\n */\r\nexport function createUnboundAction<TResult>(\r\n operationName: string,\r\n): UnboundActionExecutor<TResult>;\r\n\r\n/**\r\n * Create an executor for an unbound action with typed parameters and optional typed response.\r\n *\r\n * @param operationName - Custom API unique name\r\n * @param paramMeta - Parameter metadata map\r\n */\r\nexport function createUnboundAction<\r\n TParams extends Record<string, unknown>,\r\n TResult = void,\r\n>(\r\n operationName: string,\r\n paramMeta: ParameterMetaMap,\r\n): UnboundActionWithParamsExecutor<TParams, TResult>;\r\n\r\nexport function createUnboundAction<\r\n TParams extends Record<string, unknown>,\r\n TResult = void,\r\n>(\r\n operationName: string,\r\n paramMeta?: ParameterMetaMap,\r\n): UnboundActionExecutor | UnboundActionWithParamsExecutor<TParams, TResult> {\r\n return {\r\n async execute(params?: TParams): Promise<TResult extends void ? Response : TResult> {\r\n const req = buildUnboundRequest(\r\n operationName, OperationType.Action, paramMeta, params,\r\n );\r\n const response = await executeRequest(req);\r\n if (!response.ok) {\r\n const errorText = await response.text();\r\n throw new Error(errorText);\r\n }\r\n if (response.status !== 204) {\r\n return response.json() as Promise<TResult extends void ? Response : TResult>;\r\n }\r\n return response as TResult extends void ? Response : TResult;\r\n },\r\n request(params?: TParams): Record<string, unknown> {\r\n return buildUnboundRequest(\r\n operationName, OperationType.Action, paramMeta, params,\r\n );\r\n },\r\n };\r\n}\r\n\r\n// Function Factories\r\n\r\n/**\r\n * Create an executor for an unbound (global) function with typed response.\r\n *\r\n * @param operationName - Function name (e.g. \"WhoAmI\")\r\n */\r\nexport function createUnboundFunction<TResult>(\r\n operationName: string,\r\n): UnboundFunctionExecutor<TResult> {\r\n return {\r\n async execute(): Promise<TResult> {\r\n const req = buildUnboundRequest(operationName, OperationType.Function);\r\n const response = await executeRequest(req);\r\n if (!response.ok) {\r\n const errorText = await response.text();\r\n throw new Error(errorText);\r\n }\r\n return response.json() as Promise<TResult>;\r\n },\r\n request(): Record<string, unknown> {\r\n return buildUnboundRequest(operationName, OperationType.Function);\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Create an executor for a bound function with typed response.\r\n *\r\n * @param operationName - Function name\r\n * @param entityLogicalName - Entity logical name\r\n */\r\nexport function createBoundFunction<TResult>(\r\n operationName: string,\r\n entityLogicalName: string,\r\n): BoundFunctionExecutor<TResult> {\r\n return {\r\n async execute(recordId: string): Promise<TResult> {\r\n const req = buildBoundRequest(\r\n operationName, entityLogicalName, OperationType.Function, recordId,\r\n );\r\n const response = await executeRequest(req);\r\n if (!response.ok) {\r\n const errorText = await response.text();\r\n throw new Error(errorText);\r\n }\r\n return response.json() as Promise<TResult>;\r\n },\r\n request(recordId: string): Record<string, unknown> {\r\n return buildBoundRequest(\r\n operationName, entityLogicalName, OperationType.Function, recordId,\r\n );\r\n },\r\n };\r\n}\r\n\r\n// Convenience\r\n\r\n/**\r\n * Execute an async operation with Xrm progress indicator.\r\n *\r\n * Shows a progress spinner before the operation, closes it after,\r\n * and shows an error dialog on failure.\r\n *\r\n * @param message - Progress indicator message (e.g. \"Processing quote...\")\r\n * @param operation - Async function to execute\r\n * @returns The result of the operation\r\n *\r\n * @example\r\n * ```typescript\r\n * await withProgress('Processing quote...', () => WinQuote.execute(recordId));\r\n * ```\r\n */\r\nexport async function withProgress<T>(\r\n message: string,\r\n operation: () => Promise<T>,\r\n): Promise<T> {\r\n Xrm.Utility.showProgressIndicator(message);\r\n try {\r\n return await operation();\r\n } catch (error: unknown) {\r\n const msg = error instanceof Error ? error.message : String(error);\r\n Xrm.Navigation.openErrorDialog({ message: msg });\r\n throw error;\r\n } finally {\r\n Xrm.Utility.closeProgressIndicator();\r\n }\r\n}\r\n","/**\n * @xrmforge/helpers - TypedForm Proxy\n *\n * Creates a proxy around Xrm.FormContext that allows direct property access\n * to form fields. Instead of `form.getAttribute(\"name\").setValue(\"X\")`,\n * write `form.name.setValue(\"X\")`.\n *\n * Works with generated form types from @xrmforge/typegen. The generated\n * forms export Fields, AttributeMap, and ControlMap types that TypedForm uses\n * for full compile-time type safety.\n *\n * @example\n * ```typescript\n * import { typedForm } from '@xrmforge/helpers';\n * import type { AccountLMFirmaForm } from '../../generated/forms/account.js';\n * import { AccountLMFirmaFormFieldsEnum as Fields } from '../../generated/forms/account.js';\n *\n * export const onLoad = wrapHandler('LM.Account.onLoad', logger, (ctx) => {\n * const form = typedForm<AccountLMFirmaForm>(ctx.getFormContext());\n *\n * // Direct field access - fully typed\n * const name = form.name.getValue(); // string | null (StringAttribute)\n * form.revenue.setValue(150000); // NumberAttribute\n * const parent = form.parentaccountid.getValue(); // LookupValue[] | null\n *\n * // Control access\n * form.$control('name').setDisabled(true);\n *\n * // Full FormContext for ui, data, tabs\n * form.$context.ui.setFormNotification('Loaded', FormNotificationLevel.Info, 'load');\n *\n * // Fields enum still works for addOnChange, WebApi queries, etc.\n * form.$context.getAttribute(Fields.Name).addOnChange(() => { ... });\n * });\n * ```\n */\n\n// ─── Type Extraction from Generated Form Interfaces ──────────────────────────\n\n/**\n * Extract the Fields union type from a generated Form interface.\n *\n * Generated interfaces follow the pattern:\n * getAttribute<K extends SomeFormFields>(name: K): SomeFormAttributeMap[K];\n * getAttribute(index: number): Xrm.Attributes.Attribute;\n * getAttribute(): Xrm.Attributes.Attribute[];\n *\n * TypeScript resolves overloaded function types to the LAST matching signature.\n * For our generated interfaces, the generic overload is first, so conditional\n * type inference on the function signature gets the wrong overload.\n *\n * Solution: We use a different extraction strategy. The generated interfaces\n * extend Omit<Xrm.FormContext, 'getAttribute' | 'getControl'>, so we know\n * the first getAttribute overload has the K constraint. We extract it by\n * matching on the mapped return type pattern.\n */\ntype ExtractFields<TForm> =\n TForm extends { getAttribute<K extends infer F>(name: K): unknown }\n ? F extends string ? F : never\n : never;\n\n/**\n * Extract the AttributeMap from a generated Form interface.\n *\n * Maps each field name to its Xrm.Attributes type by calling getAttribute\n * with each specific field name from the Fields union.\n */\ntype ExtractAttributeMap<TForm, TFields extends string> = {\n [K in TFields]: TForm extends { getAttribute(name: K): infer R }\n ? R extends Xrm.Attributes.Attribute ? R : Xrm.Attributes.Attribute\n : Xrm.Attributes.Attribute;\n};\n\n/**\n * Extract the ControlMap from a generated Form interface.\n */\ntype ExtractControlMap<TForm, TFields extends string> = {\n [K in TFields]: TForm extends { getControl(name: K): infer R }\n ? R extends Xrm.Controls.Control ? R : Xrm.Controls.Control\n : Xrm.Controls.Control;\n};\n\n// ─── TypedForm Type ──────────────────────────────────────────────────────────\n\n/**\n * TypedForm: proxy type that maps field names to their attribute types.\n *\n * Provides direct property access to form fields (e.g. `form.name` returns\n * the StringAttribute), plus `$context` for full FormContext access and\n * `$control(name)` for typed control access.\n */\nexport type TypedForm<\n TForm,\n TFields extends string = ExtractFields<TForm>,\n TAttrMap extends Record<string, Xrm.Attributes.Attribute> = ExtractAttributeMap<TForm, TFields>,\n TCtrlMap extends Record<string, Xrm.Controls.Control> = ExtractControlMap<TForm, TFields>,\n> = {\n /** Direct field access: form.fieldName returns the typed Attribute */\n readonly [K in TFields]: K extends keyof TAttrMap\n ? TAttrMap[K]\n : Xrm.Attributes.Attribute;\n} & {\n /** Access the underlying FormContext for ui, data, tabs, etc. */\n readonly $context: TForm extends Xrm.FormContext ? TForm : Xrm.FormContext;\n /** Access a typed control by field name */\n $control<K extends TFields>(name: K): K extends keyof TCtrlMap ? TCtrlMap[K] : Xrm.Controls.Control;\n};\n\n/**\n * Create a typed form proxy around a FormContext.\n *\n * The proxy intercepts property access and delegates to getAttribute().\n * Special properties `$context` and `$control` provide access to the full\n * FormContext and controls respectively.\n *\n * Usage with a single type parameter (recommended):\n * ```typescript\n * const form = typedForm<AccountLMFirmaForm>(ctx.getFormContext());\n * form.name.getValue(); // typed as StringAttribute\n * ```\n *\n * @param formContext - The Xrm.FormContext from executionContext.getFormContext()\n * @returns A proxy with direct typed property access to form fields\n */\nexport function typedForm<TForm>(\n formContext: Xrm.FormContext,\n): TypedForm<TForm> {\n return new Proxy(formContext as unknown as TypedForm<TForm>, {\n get(_target, prop) {\n // Symbols and non-string keys: delegate to formContext\n if (typeof prop !== 'string') {\n return (formContext as unknown as Record<symbol, unknown>)[prop];\n }\n if (prop === '$context') return formContext;\n if (prop === '$control') {\n return (name: string) => formContext.getControl(name);\n }\n // Try getAttribute first (form field access)\n const attr = formContext.getAttribute(prop);\n if (attr) return attr;\n // Fallback to FormContext properties (data, ui, etc.)\n return (formContext as unknown as Record<string, unknown>)[prop];\n },\n\n set(_target, prop, _value) {\n throw new TypeError(\n `Cannot assign to '${String(prop)}'. Use form.${String(prop)}.setValue() instead.`,\n );\n },\n\n has(_target, prop) {\n if (typeof prop !== 'string') return false;\n if (prop === '$context' || prop === '$control') return true;\n return formContext.getAttribute(prop) !== null;\n },\n });\n}\n\n// ─── Legacy Exports (backwards compatible) ───────────────────────────────────\n\n/** @deprecated Use ExtractFields<TForm> instead */\nexport type FormFields<TForm> = ExtractFields<TForm>;\n"],"mappings":";AAgCO,SAAS,UAAU,MAAqC;AAC7D,QAAM,SAAS,KAAK,WAAW,KAAK,MAAM,QAAQ,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI;AACvE,MAAI,OAAO,WAAW,EAAG,QAAO;AAChC,SAAO,YAAY,OAAO,KAAK,GAAG,CAAC;AACrC;AAyBO,SAAS,YACd,UACA,oBACyD;AACzD,QAAM,MAAM,IAAI,kBAAkB;AAClC,QAAM,KAAK,SAAS,GAAG;AACvB,MAAI,CAAC,GAAI,QAAO;AAEhB,SAAO;AAAA,IACL;AAAA,IACA,MAAO,SAAS,GAAG,GAAG,4CAA4C,KAAgB;AAAA,IAClF,YAAa,SAAS,GAAG,GAAG,2CAA2C,KAAgB;AAAA,EACzF;AACF;AAiBO,SAAS,aACd,UACA,sBACyE;AACzE,QAAM,SAAkF,CAAC;AACzF,aAAW,QAAQ,sBAAsB;AACvC,WAAO,IAAI,IAAI,YAAY,UAAU,IAAI;AAAA,EAC3C;AACA,SAAO;AACT;AAiBO,SAAS,oBACd,UACA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,SAAS,YAAY;AACvB,eAAO,CAAC,SAAiB,YAAY,WAAW,IAAI;AAAA,MACtD;AAEA,YAAM,OAAO,YAAY,aAAa,IAAI;AAC1C,UAAI,KAAM,QAAO;AAEjB,aAAQ,YAAmD,IAAI;AAAA,IACjE;AAAA,IAEA,IAAI,SAAS,MAAM,QAAQ;AACzB,YAAM,IAAI;AAAA,QACR,qBAAqB,OAAO,IAAI,CAAC,eAAe,OAAO,IAAI,CAAC;AAAA,MAC9D;AAAA,IACF;AAAA,IAEA,IAAI,SAAS,MAAM;AACjB,UAAI,OAAO,SAAS,SAAU,QAAO;AACrC,UAAI,SAAS,cAAc,SAAS,WAAY,QAAO;AACvD,aAAO,YAAY,aAAa,IAAI,MAAM;AAAA,IAC5C;AAAA,EACF,CAAC;AACH;","names":["DisplayState","FormNotificationLevel","RequiredLevel","SubmitMode","SaveMode","ClientType","ClientState","OperationType","StructuralProperty","BindingType"]}
1
+ {"version":3,"sources":["../src/webapi-helpers.ts","../src/xrm-constants.ts","../src/action-runtime.ts","../src/typed-form.ts"],"sourcesContent":["/**\r\n * @xrmforge/helpers - Web API Helper Functions\r\n *\r\n * Lightweight utility functions for building OData query strings\r\n * with type-safe field names from generated Fields enums.\r\n *\r\n * Zero runtime overhead when used with const enums (values are inlined).\r\n *\r\n * @example\r\n * ```typescript\r\n * import { select } from '@xrmforge/helpers';\r\n *\r\n * Xrm.WebApi.retrieveRecord(ref.entityType, ref.id, select(\r\n * AccountFields.Name,\r\n * AccountFields.WebsiteUrl,\r\n * AccountFields.Address1Line1,\r\n * ));\r\n * ```\r\n */\r\n\r\n/**\r\n * Build an OData $select query string from field names.\r\n *\r\n * Accepts either variadic arguments or a single array:\r\n * - `select(Fields.Name, Fields.Email)` (variadic)\r\n * - `select([Fields.Name, Fields.Email])` (array)\r\n *\r\n * @param fields - Field names (use generated Fields enum for type safety)\r\n * @returns OData query string (e.g. \"?$select=name,websiteurl,address1_line1\")\r\n */\r\nexport function select(fields: string[]): string;\r\nexport function select(...fields: string[]): string;\r\nexport function select(...args: string[] | [string[]]): string {\r\n const fields = args.length === 1 && Array.isArray(args[0]) ? args[0] : args as string[];\r\n if (fields.length === 0) return '';\r\n return `?$select=${fields.join(',')}`;\r\n}\r\n\r\n/**\r\n * Parse a lookup field from a Dataverse Web API response into a LookupValue.\r\n *\r\n * Dataverse returns lookups as `_fieldname_value` with OData annotations:\r\n * - `_fieldname_value` (GUID)\r\n * - `_fieldname_value@OData.Community.Display.V1.FormattedValue` (display name)\r\n * - `_fieldname_value@Microsoft.Dynamics.CRM.lookuplogicalname` (entity type)\r\n *\r\n * This function extracts all three into an `Xrm.LookupValue` object.\r\n *\r\n * @param response - The raw Web API response object\r\n * @param navigationProperty - Navigation property name (use NavigationProperties enum for type safety)\r\n * @returns Xrm.LookupValue or null if the lookup is empty\r\n *\r\n * @example\r\n * ```typescript\r\n * // With NavigationProperties enum (recommended):\r\n * parseLookup(result, AccountNav.Country);\r\n *\r\n * // Or with navigation property name directly:\r\n * parseLookup(result, 'markant_address1_countryid');\r\n * ```\r\n */\r\nexport function parseLookup(\r\n response: Record<string, unknown>,\r\n navigationProperty: string,\r\n): { id: string; name: string; entityType: string } | null {\r\n const key = `_${navigationProperty}_value`;\r\n const id = response[key] as string | undefined;\r\n if (!id) return null;\r\n\r\n return {\r\n id,\r\n name: (response[`${key}@OData.Community.Display.V1.FormattedValue`] as string) ?? '',\r\n entityType: (response[`${key}@Microsoft.Dynamics.CRM.lookuplogicalname`] as string) ?? '',\r\n };\r\n}\r\n\r\n/**\r\n * Parse multiple lookup fields from a Dataverse Web API response at once.\r\n *\r\n * @param response - The raw Web API response object\r\n * @param navigationProperties - Navigation property names to parse\r\n * @returns Map of navigation property name to LookupValue (null entries omitted)\r\n *\r\n * @example\r\n * ```typescript\r\n * const lookups = parseLookups(result, ['markant_address1_countryid', 'parentaccountid']);\r\n * formContext.getAttribute(Fields.Country).setValue(\r\n * lookups.markant_address1_countryid ? [lookups.markant_address1_countryid] : null\r\n * );\r\n * ```\r\n */\r\nexport function parseLookups(\r\n response: Record<string, unknown>,\r\n navigationProperties: string[],\r\n): Record<string, { id: string; name: string; entityType: string } | null> {\r\n const result: Record<string, { id: string; name: string; entityType: string } | null> = {};\r\n for (const prop of navigationProperties) {\r\n result[prop] = parseLookup(response, prop);\r\n }\r\n return result;\r\n}\r\n\r\n/**\r\n * Get the formatted (display) value of any field from a Web API response.\r\n *\r\n * Works for OptionSets, Lookups, DateTimes, Money, and other formatted fields.\r\n *\r\n * @param response - The raw Web API response object\r\n * @param fieldName - The field logical name (e.g. \"statecode\", \"createdon\")\r\n * @returns The formatted string value, or null if not available\r\n *\r\n * @example\r\n * ```typescript\r\n * const status = parseFormattedValue(result, 'statecode');\r\n * // \"Active\" (instead of 0)\r\n * ```\r\n */\r\nexport function parseFormattedValue(\r\n response: Record<string, unknown>,\r\n fieldName: string,\r\n): string | null {\r\n return (response[`${fieldName}@OData.Community.Display.V1.FormattedValue`] as string) ?? null;\r\n}\r\n\r\n/**\r\n * Build an OData $select and $expand query string.\r\n *\r\n * @param fields - Field names to select\r\n * @param expand - Navigation property to expand (optional)\r\n * @returns OData query string\r\n *\r\n * @example\r\n * ```typescript\r\n * Xrm.WebApi.retrieveRecord(\"account\", id, selectExpand(\r\n * [AccountFields.Name, AccountFields.WebsiteUrl],\r\n * \"primarycontactid($select=fullname,emailaddress1)\"\r\n * ));\r\n * ```\r\n */\r\nexport function selectExpand(fields: string[], expand: string): string {\r\n const parts: string[] = [];\r\n if (fields.length > 0) parts.push(`$select=${fields.join(',')}`);\r\n if (expand) parts.push(`$expand=${expand}`);\r\n return parts.length > 0 ? `?${parts.join('&')}` : '';\r\n}\r\n\r\n// ─── Form Lookup Helpers ────────────────────────────────────────────────────\r\n\r\n/**\r\n * Extract the first lookup value from a FormContext lookup attribute.\r\n *\r\n * Centralizes the common pattern of reading a lookup from a form field,\r\n * handling null/empty arrays, and normalizing the GUID (removing braces).\r\n *\r\n * @param attr - A lookup attribute from formContext.getAttribute()\r\n * @returns Xrm.LookupValue with normalized id (no braces), or null if empty\r\n *\r\n * @example\r\n * ```typescript\r\n * import { formLookup } from '@xrmforge/helpers';\r\n * const customer = formLookup(form.getAttribute(Fields.CustomerId));\r\n * if (customer) {\r\n * console.log(customer.id, customer.name, customer.entityType);\r\n * }\r\n * ```\r\n */\r\nexport function formLookup(\r\n attr: { getValue(): { id: string; name?: string; entityType: string }[] | null },\r\n): { id: string; name: string; entityType: string } | null {\r\n const values = attr.getValue();\r\n if (!values || values.length === 0) return null;\r\n const first = values[0]!;\r\n return {\r\n id: first.id.replace(/[{}]/g, ''),\r\n name: first.name ?? '',\r\n entityType: first.entityType,\r\n };\r\n}\r\n\r\n/**\r\n * Extract just the normalized GUID from a FormContext lookup attribute.\r\n *\r\n * Shorthand for the most common lookup use case: getting the record ID\r\n * for a Web API call or comparison.\r\n *\r\n * @param attr - A lookup attribute from formContext.getAttribute()\r\n * @returns Normalized GUID string (no braces), or null if empty\r\n *\r\n * @example\r\n * ```typescript\r\n * import { formLookupId } from '@xrmforge/helpers';\r\n * const accountId = formLookupId(form.getAttribute(Fields.AccountId));\r\n * if (accountId) {\r\n * await Xrm.WebApi.retrieveRecord(EntityNames.Account, accountId, select(...));\r\n * }\r\n * ```\r\n */\r\nexport function formLookupId(\r\n attr: { getValue(): { id: string }[] | null },\r\n): string | null {\r\n const values = attr.getValue();\r\n if (!values || values.length === 0) return null;\r\n return values[0]!.id.replace(/[{}]/g, '');\r\n}\r\n","/**\r\n * @xrmforge/helpers - Xrm API Constants\r\n *\r\n * Const enums for all common Xrm string/number constants.\r\n * Eliminates raw strings in D365 form scripts.\r\n *\r\n * @types/xrm defines these as string literal types for compile-time checking,\r\n * but does NOT provide runtime constants (XrmEnum is not available at runtime).\r\n * These const enums are erased at compile time (zero runtime overhead).\r\n *\r\n * @example\r\n * ```typescript\r\n * import { DisplayState } from '@xrmforge/helpers';\r\n *\r\n * if (tab.getDisplayState() === DisplayState.Expanded) { ... }\r\n * ```\r\n */\r\n\r\n/** Tab/Section display state */\r\nexport const enum DisplayState {\r\n Expanded = 'expanded',\r\n Collapsed = 'collapsed',\r\n}\r\n\r\n// FormType: use XrmEnum.FormType from @types/xrm (already defined as const enum there)\r\n\r\n/** Form notification level (formContext.ui.setFormNotification) */\r\nexport const enum FormNotificationLevel {\r\n Error = 'ERROR',\r\n Warning = 'WARNING',\r\n Info = 'INFO',\r\n}\r\n\r\n/** Attribute required level (attribute.setRequiredLevel) */\r\nexport const enum RequiredLevel {\r\n None = 'none',\r\n Required = 'required',\r\n Recommended = 'recommended',\r\n}\r\n\r\n/** Attribute submit mode (attribute.setSubmitMode) */\r\nexport const enum SubmitMode {\r\n Always = 'always',\r\n Never = 'never',\r\n Dirty = 'dirty',\r\n}\r\n\r\n/** Save mode (eventArgs.getSaveMode()) */\r\nexport const enum SaveMode {\r\n Save = 1,\r\n SaveAndClose = 2,\r\n Deactivate = 5,\r\n Reactivate = 6,\r\n Send = 7,\r\n Disqualify = 15,\r\n Qualify = 16,\r\n Assign = 47,\r\n SaveAsCompleted = 58,\r\n SaveAndNew = 59,\r\n AutoSave = 70,\r\n}\r\n\r\n/** Client type (Xrm.Utility.getGlobalContext().client.getClient()) */\r\nexport const enum ClientType {\r\n Web = 'Web',\r\n Outlook = 'Outlook',\r\n Mobile = 'Mobile',\r\n}\r\n\r\n/** Client state (Xrm.Utility.getGlobalContext().client.getClientState()) */\r\nexport const enum ClientState {\r\n Online = 'Online',\r\n Offline = 'Offline',\r\n}\r\n\r\n// WebApi Execute Constants\r\n\r\n/** Operation type for Xrm.WebApi.execute getMetadata().operationType */\r\nexport const enum OperationType {\r\n /** Custom Action or OOB Action (POST) */\r\n Action = 0,\r\n /** Custom Function or OOB Function (GET) */\r\n Function = 1,\r\n /** CRUD operation (Create, Retrieve, Update, Delete) */\r\n CRUD = 2,\r\n}\r\n\r\n/** Structural property for getMetadata().parameterTypes[].structuralProperty */\r\nexport const enum StructuralProperty {\r\n Unknown = 0,\r\n PrimitiveType = 1,\r\n ComplexType = 2,\r\n EnumerationType = 3,\r\n Collection = 4,\r\n EntityType = 5,\r\n}\r\n\r\n/** Binding type for Custom API definitions */\r\nexport const enum BindingType {\r\n /** Not bound to an entity (globally callable) */\r\n Global = 0,\r\n /** Bound to a single entity record */\r\n Entity = 1,\r\n /** Bound to an entity collection */\r\n EntityCollection = 2,\r\n}\r\n","/**\r\n * @xrmforge/helpers - Action/Function Runtime Helpers\r\n *\r\n * Factory functions for type-safe Custom API execution.\r\n * These are imported by generated action/function modules.\r\n *\r\n * Design:\r\n * - `createBoundAction` / `createUnboundAction`: Produce executor objects\r\n * with `.execute()` (calls Xrm.WebApi) and `.request()` (for executeMultiple)\r\n * - `executeRequest`: Central execute wrapper (single place for the `as any` cast)\r\n * - `withProgress`: Convenience wrapper with progress indicator + error dialog\r\n *\r\n * @example\r\n * ```typescript\r\n * // Generated code (in generated/actions/quote.ts):\r\n * import { createBoundAction } from '@xrmforge/helpers';\r\n * export const WinQuote = createBoundAction('markant_winquote', 'quote');\r\n *\r\n * // Developer code (in quote-form.ts):\r\n * import { WinQuote } from '../generated/actions/quote';\r\n * const response = await WinQuote.execute(recordId);\r\n * ```\r\n */\r\n\r\nimport { OperationType, StructuralProperty } from './xrm-constants.js';\r\n\r\n// Types\r\n\r\n/** Parameter metadata for getMetadata().parameterTypes */\r\nexport interface ParameterMeta {\r\n typeName: string;\r\n structuralProperty: number;\r\n}\r\n\r\n/** Map of parameter names to their OData metadata */\r\nexport type ParameterMetaMap = Record<string, ParameterMeta>;\r\n\r\n/** Executor for a bound action without additional parameters */\r\nexport interface BoundActionExecutor<TResult = void> {\r\n execute(recordId: string): Promise<TResult extends void ? Response : TResult>;\r\n request(recordId: string): Record<string, unknown>;\r\n}\r\n\r\n/** Executor for a bound action with typed parameters */\r\nexport interface BoundActionWithParamsExecutor<TParams, TResult = void> {\r\n execute(recordId: string, params: TParams): Promise<TResult extends void ? Response : TResult>;\r\n request(recordId: string, params: TParams): Record<string, unknown>;\r\n}\r\n\r\n/** Executor for an unbound action without parameters */\r\nexport interface UnboundActionExecutor<TResult = void> {\r\n execute(): Promise<TResult extends void ? Response : TResult>;\r\n request(): Record<string, unknown>;\r\n}\r\n\r\n/** Executor for an unbound action with typed parameters and optional typed response */\r\nexport interface UnboundActionWithParamsExecutor<TParams, TResult = void> {\r\n execute(params: TParams): Promise<TResult extends void ? Response : TResult>;\r\n request(params: TParams): Record<string, unknown>;\r\n}\r\n\r\n/** Executor for an unbound function with typed response */\r\nexport interface UnboundFunctionExecutor<TResult> {\r\n execute(): Promise<TResult>;\r\n request(): Record<string, unknown>;\r\n}\r\n\r\n/** Executor for a bound function with typed response */\r\nexport interface BoundFunctionExecutor<TResult> {\r\n execute(recordId: string): Promise<TResult>;\r\n request(recordId: string): Record<string, unknown>;\r\n}\r\n\r\n// Central Execute\r\n\r\n/**\r\n * Execute a single request via Xrm.WebApi.online.execute().\r\n *\r\n * This is the ONLY place in the entire framework where the `as any` cast happens.\r\n * All generated executors call this function internally.\r\n */\r\nexport function executeRequest(request: Record<string, unknown>): Promise<Response> {\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n return (Xrm.WebApi as any).online.execute(request) as Promise<Response>;\r\n}\r\n\r\n/**\r\n * Execute multiple requests via Xrm.WebApi.online.executeMultiple().\r\n *\r\n * @param requests - Array of request objects (from `.request()` factories).\r\n * Wrap a subset in an inner array for transactional changeset execution.\r\n */\r\nexport function executeMultiple(\r\n requests: Array<Record<string, unknown> | Array<Record<string, unknown>>>,\r\n): Promise<Response[]> {\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n return (Xrm.WebApi as any).online.executeMultiple(requests) as Promise<Response[]>;\r\n}\r\n\r\n// Request Builder (internal)\r\n\r\nfunction cleanRecordId(id: string): string {\r\n return id.replace(/[{}]/g, '');\r\n}\r\n\r\nfunction buildBoundRequest(\r\n operationName: string,\r\n entityLogicalName: string,\r\n operationType: OperationType,\r\n recordId: string,\r\n paramMeta?: ParameterMetaMap,\r\n params?: Record<string, unknown>,\r\n): Record<string, unknown> {\r\n const parameterTypes: Record<string, ParameterMeta> = {\r\n entity: {\r\n typeName: `mscrm.${entityLogicalName}`,\r\n structuralProperty: StructuralProperty.EntityType,\r\n },\r\n };\r\n\r\n if (paramMeta) {\r\n for (const [key, meta] of Object.entries(paramMeta)) {\r\n parameterTypes[key] = meta;\r\n }\r\n }\r\n\r\n const request: Record<string, unknown> = {\r\n getMetadata: () => ({\r\n boundParameter: 'entity',\r\n parameterTypes,\r\n operationName,\r\n operationType,\r\n }),\r\n entity: {\r\n id: cleanRecordId(recordId),\r\n entityType: entityLogicalName,\r\n },\r\n };\r\n\r\n if (params) {\r\n for (const [key, value] of Object.entries(params)) {\r\n request[key] = value;\r\n }\r\n }\r\n\r\n return request;\r\n}\r\n\r\nfunction buildUnboundRequest(\r\n operationName: string,\r\n operationType: OperationType,\r\n paramMeta?: ParameterMetaMap,\r\n params?: Record<string, unknown>,\r\n): Record<string, unknown> {\r\n const parameterTypes: Record<string, ParameterMeta> = {};\r\n\r\n if (paramMeta) {\r\n for (const [key, meta] of Object.entries(paramMeta)) {\r\n parameterTypes[key] = meta;\r\n }\r\n }\r\n\r\n const request: Record<string, unknown> = {\r\n getMetadata: () => ({\r\n boundParameter: null,\r\n parameterTypes,\r\n operationName,\r\n operationType,\r\n }),\r\n };\r\n\r\n if (params) {\r\n for (const [key, value] of Object.entries(params)) {\r\n request[key] = value;\r\n }\r\n }\r\n\r\n return request;\r\n}\r\n\r\n// Action Factories\r\n\r\n/**\r\n * Create an executor for a bound action (entity-bound) without parameters or typed response.\r\n *\r\n * @param operationName - Custom API unique name (e.g. \"markant_winquote\")\r\n * @param entityLogicalName - Entity logical name (e.g. \"quote\")\r\n */\r\nexport function createBoundAction(\r\n operationName: string,\r\n entityLogicalName: string,\r\n): BoundActionExecutor;\r\n\r\n/**\r\n * Create an executor for a bound action without parameters but with typed response.\r\n *\r\n * @param operationName - Custom API unique name\r\n * @param entityLogicalName - Entity logical name\r\n */\r\nexport function createBoundAction<TResult>(\r\n operationName: string,\r\n entityLogicalName: string,\r\n): BoundActionExecutor<TResult>;\r\n\r\n/**\r\n * Create an executor for a bound action with typed parameters and optional typed response.\r\n *\r\n * @param operationName - Custom API unique name\r\n * @param entityLogicalName - Entity logical name\r\n * @param paramMeta - Parameter metadata map (parameter name to OData type info)\r\n */\r\nexport function createBoundAction<\r\n TParams extends Record<string, unknown>,\r\n TResult = void,\r\n>(\r\n operationName: string,\r\n entityLogicalName: string,\r\n paramMeta: ParameterMetaMap,\r\n): BoundActionWithParamsExecutor<TParams, TResult>;\r\n\r\nexport function createBoundAction<\r\n TParams extends Record<string, unknown>,\r\n TResult = void,\r\n>(\r\n operationName: string,\r\n entityLogicalName: string,\r\n paramMeta?: ParameterMetaMap,\r\n): BoundActionExecutor<TResult> | BoundActionWithParamsExecutor<TParams, TResult> {\r\n return {\r\n async execute(recordId: string, params?: TParams): Promise<TResult extends void ? Response : TResult> {\r\n const req = buildBoundRequest(\r\n operationName, entityLogicalName, OperationType.Action,\r\n recordId, paramMeta, params,\r\n );\r\n const response = await executeRequest(req);\r\n if (!response.ok) {\r\n const errorText = await response.text();\r\n throw new Error(errorText);\r\n }\r\n // Parse JSON when response properties are defined (TResult is not void)\r\n if (response.status !== 204) {\r\n return response.json() as Promise<TResult extends void ? Response : TResult>;\r\n }\r\n return response as TResult extends void ? Response : TResult;\r\n },\r\n request(recordId: string, params?: TParams): Record<string, unknown> {\r\n return buildBoundRequest(\r\n operationName, entityLogicalName, OperationType.Action,\r\n recordId, paramMeta, params,\r\n );\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Create an executor for an unbound (global) action without parameters or typed response.\r\n *\r\n * @param operationName - Custom API unique name\r\n */\r\nexport function createUnboundAction(\r\n operationName: string,\r\n): UnboundActionExecutor;\r\n\r\n/**\r\n * Create an executor for an unbound action without parameters but with typed response.\r\n *\r\n * @param operationName - Custom API unique name\r\n */\r\nexport function createUnboundAction<TResult>(\r\n operationName: string,\r\n): UnboundActionExecutor<TResult>;\r\n\r\n/**\r\n * Create an executor for an unbound action with typed parameters and optional typed response.\r\n *\r\n * @param operationName - Custom API unique name\r\n * @param paramMeta - Parameter metadata map\r\n */\r\nexport function createUnboundAction<\r\n TParams extends Record<string, unknown>,\r\n TResult = void,\r\n>(\r\n operationName: string,\r\n paramMeta: ParameterMetaMap,\r\n): UnboundActionWithParamsExecutor<TParams, TResult>;\r\n\r\nexport function createUnboundAction<\r\n TParams extends Record<string, unknown>,\r\n TResult = void,\r\n>(\r\n operationName: string,\r\n paramMeta?: ParameterMetaMap,\r\n): UnboundActionExecutor | UnboundActionWithParamsExecutor<TParams, TResult> {\r\n return {\r\n async execute(params?: TParams): Promise<TResult extends void ? Response : TResult> {\r\n const req = buildUnboundRequest(\r\n operationName, OperationType.Action, paramMeta, params,\r\n );\r\n const response = await executeRequest(req);\r\n if (!response.ok) {\r\n const errorText = await response.text();\r\n throw new Error(errorText);\r\n }\r\n if (response.status !== 204) {\r\n return response.json() as Promise<TResult extends void ? Response : TResult>;\r\n }\r\n return response as TResult extends void ? Response : TResult;\r\n },\r\n request(params?: TParams): Record<string, unknown> {\r\n return buildUnboundRequest(\r\n operationName, OperationType.Action, paramMeta, params,\r\n );\r\n },\r\n };\r\n}\r\n\r\n// Function Factories\r\n\r\n/**\r\n * Create an executor for an unbound (global) function with typed response.\r\n *\r\n * @param operationName - Function name (e.g. \"WhoAmI\")\r\n */\r\nexport function createUnboundFunction<TResult>(\r\n operationName: string,\r\n): UnboundFunctionExecutor<TResult> {\r\n return {\r\n async execute(): Promise<TResult> {\r\n const req = buildUnboundRequest(operationName, OperationType.Function);\r\n const response = await executeRequest(req);\r\n if (!response.ok) {\r\n const errorText = await response.text();\r\n throw new Error(errorText);\r\n }\r\n return response.json() as Promise<TResult>;\r\n },\r\n request(): Record<string, unknown> {\r\n return buildUnboundRequest(operationName, OperationType.Function);\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Create an executor for a bound function with typed response.\r\n *\r\n * @param operationName - Function name\r\n * @param entityLogicalName - Entity logical name\r\n */\r\nexport function createBoundFunction<TResult>(\r\n operationName: string,\r\n entityLogicalName: string,\r\n): BoundFunctionExecutor<TResult> {\r\n return {\r\n async execute(recordId: string): Promise<TResult> {\r\n const req = buildBoundRequest(\r\n operationName, entityLogicalName, OperationType.Function, recordId,\r\n );\r\n const response = await executeRequest(req);\r\n if (!response.ok) {\r\n const errorText = await response.text();\r\n throw new Error(errorText);\r\n }\r\n return response.json() as Promise<TResult>;\r\n },\r\n request(recordId: string): Record<string, unknown> {\r\n return buildBoundRequest(\r\n operationName, entityLogicalName, OperationType.Function, recordId,\r\n );\r\n },\r\n };\r\n}\r\n\r\n// Convenience\r\n\r\n/**\r\n * Execute an async operation with Xrm progress indicator.\r\n *\r\n * Shows a progress spinner before the operation, closes it after,\r\n * and shows an error dialog on failure.\r\n *\r\n * @param message - Progress indicator message (e.g. \"Processing quote...\")\r\n * @param operation - Async function to execute\r\n * @returns The result of the operation\r\n *\r\n * @example\r\n * ```typescript\r\n * await withProgress('Processing quote...', () => WinQuote.execute(recordId));\r\n * ```\r\n */\r\nexport async function withProgress<T>(\r\n message: string,\r\n operation: () => Promise<T>,\r\n): Promise<T> {\r\n Xrm.Utility.showProgressIndicator(message);\r\n try {\r\n return await operation();\r\n } catch (error: unknown) {\r\n const msg = error instanceof Error ? error.message : String(error);\r\n Xrm.Navigation.openErrorDialog({ message: msg });\r\n throw error;\r\n } finally {\r\n Xrm.Utility.closeProgressIndicator();\r\n }\r\n}\r\n","/**\n * @xrmforge/helpers - TypedForm Proxy\n *\n * Creates a proxy around Xrm.FormContext that allows direct property access\n * to form fields. Instead of `form.getAttribute(\"name\").setValue(\"X\")`,\n * write `form.name.setValue(\"X\")`.\n *\n * Works with generated form types from @xrmforge/typegen. Since v0.9.2,\n * typegen generates a `FormTypeInfo` interface per form that bundles\n * Fields, AttributeMap, and ControlMap for reliable type extraction.\n *\n * @example\n * ```typescript\n * import { typedForm } from '@xrmforge/helpers';\n * import type { AccountLMFirmaForm } from '../../generated/forms/account.js';\n *\n * const form = typedForm<AccountLMFirmaForm>(ctx.getFormContext());\n * form.name.getValue(); // string | null (typed)\n * form.revenue.setValue(150000); // NumberAttribute (typed)\n * form.$context.ui.tabs.get(...); // Full FormContext access\n * form.$control('name'); // Control access\n * form.$unsafe('off_form_field'); // Access fields not on the form\n * ```\n */\n\n// ─── FormTypeInfo Protocol ───────────────────────────────────────────────────\n\n/**\n * Protocol interface generated by typegen for each form.\n * Bundles Fields, AttributeMap, and ControlMap so typedForm can extract\n * them reliably without fragile Conditional Type inference on overloads.\n *\n * Generated as: `export interface MyFormTypeInfo { fields: ...; attributes: ...; controls: ...; form: ...; }`\n */\nexport interface FormTypeInfoProtocol {\n fields: string;\n attributes: Record<string, Xrm.Attributes.Attribute>;\n controls: Record<string, Xrm.Controls.Control>;\n form: object;\n}\n\n// ─── Type Extraction ─────────────────────────────────────────────────────────\n\n/**\n * Extract Fields from a Form interface.\n *\n * Strategy: Check if TForm has a companion TypeInfo interface (generated by\n * typegen >= 0.9.2). If so, extract fields directly. Otherwise, fall back\n * to Conditional Type inference on getAttribute (works in same compilation\n * unit but may fail across package boundaries in TS 5.9+).\n */\ntype ExtractFields<TForm> =\n TForm extends FormTypeInfoProtocol ? TForm['fields'] :\n TForm extends { getAttribute<K extends infer F>(name: K): unknown }\n ? F extends string ? F : never\n : never;\n\ntype ExtractAttributeMap<TForm, TFields extends string> =\n TForm extends FormTypeInfoProtocol ? TForm['attributes'] :\n { [K in TFields]: TForm extends { getAttribute(name: K): infer R }\n ? R extends Xrm.Attributes.Attribute ? R : Xrm.Attributes.Attribute\n : Xrm.Attributes.Attribute;\n };\n\ntype ExtractControlMap<TForm, TFields extends string> =\n TForm extends FormTypeInfoProtocol ? TForm['controls'] :\n { [K in TFields]: TForm extends { getControl(name: K): infer R }\n ? R extends Xrm.Controls.Control ? R : Xrm.Controls.Control\n : Xrm.Controls.Control;\n };\n\ntype ExtractFormContext<TForm> =\n TForm extends FormTypeInfoProtocol ? TForm['form'] :\n TForm extends Xrm.FormContext ? TForm :\n Xrm.FormContext;\n\n// ─── TypedForm Type ──────────────────────────────────────────────────────────\n\n/**\n * TypedForm: proxy type that maps field names to their attribute types.\n *\n * Provides direct property access to form fields (e.g. `form.name` returns\n * the StringAttribute), plus:\n * - `$context` for full FormContext access (ui, data, tabs, getAttribute with addOnChange)\n * - `$control(name)` for typed control access\n * - `$unsafe(name)` for off-form field access (fields loaded by D365 but not on the form)\n */\nexport type TypedForm<\n TForm,\n TFields extends string = ExtractFields<TForm>,\n TAttrMap extends Record<string, Xrm.Attributes.Attribute> = ExtractAttributeMap<TForm, TFields>,\n TCtrlMap extends Record<string, Xrm.Controls.Control> = ExtractControlMap<TForm, TFields>,\n> = {\n /** Direct field access: form.fieldName returns the typed Attribute */\n readonly [K in TFields]: K extends keyof TAttrMap\n ? TAttrMap[K]\n : Xrm.Attributes.Attribute;\n} & {\n /** Access the underlying FormContext for ui, data, tabs, addOnChange, etc. */\n readonly $context: ExtractFormContext<TForm>;\n /** Access a typed control by field name */\n $control<K extends TFields>(name: K): K extends keyof TCtrlMap ? TCtrlMap[K] : Xrm.Controls.Control;\n /**\n * Access an off-form field (loaded by D365 but not on the current form layout).\n * Returns null if the attribute does not exist.\n * Use this for fields like 'lm_genehmigt' that are not in the form definition\n * but are accessible at runtime via formContext.getAttribute().\n */\n $unsafe(name: string): Xrm.Attributes.Attribute | null;\n};\n\n/**\n * Create a typed form proxy around a FormContext.\n *\n * Accepts either a Form interface or a FormTypeInfo interface as type parameter.\n * When using FormTypeInfo (generated by typegen >= 0.9.2), type extraction is\n * guaranteed to work across all TypeScript versions.\n *\n * @example\n * ```typescript\n * // Recommended: use Form interface directly (requires typegen >= 0.9.2 for TypeInfo)\n * const form = typedForm<AccountLMFirmaForm>(ctx.getFormContext());\n *\n * // Alternative: use TypeInfo for explicit type extraction\n * const form = typedForm<AccountLMFirmaFormTypeInfo>(ctx.getFormContext());\n * ```\n *\n * @param formContext - The Xrm.FormContext from executionContext.getFormContext()\n * @returns A proxy with direct typed property access to form fields\n */\nexport function typedForm<TForm>(\n formContext: Xrm.FormContext,\n): TypedForm<TForm> {\n return new Proxy(formContext as unknown as TypedForm<TForm>, {\n get(_target, prop) {\n if (typeof prop !== 'string') {\n return (formContext as unknown as Record<symbol, unknown>)[prop];\n }\n if (prop === '$context') return formContext;\n if (prop === '$control') {\n return (name: string) => formContext.getControl(name);\n }\n if (prop === '$unsafe') {\n return (name: string) => formContext.getAttribute(name);\n }\n const attr = formContext.getAttribute(prop);\n if (attr) return attr;\n return (formContext as unknown as Record<string, unknown>)[prop];\n },\n\n set(_target, prop, _value) {\n throw new TypeError(\n `Cannot assign to '${String(prop)}'. Use form.${String(prop)}.setValue() instead.`,\n );\n },\n\n has(_target, prop) {\n if (typeof prop !== 'string') return false;\n if (prop === '$context' || prop === '$control' || prop === '$unsafe') return true;\n return formContext.getAttribute(prop) !== null;\n },\n });\n}\n\n// ─── normalizeGuid ───────────────────────────────────────────────────────────\n\n/**\n * Normalize a GUID: strip curly braces and lowercase.\n *\n * Use this for GUIDs from sources other than formLookupId():\n * - `formContext.data.entity.getId()` returns GUIDs with braces\n * - WebApi `_value` fields may have braces depending on annotations\n * - Custom API responses may return GUIDs in varying formats\n *\n * formLookupId() already normalizes internally, so this is NOT needed for\n * lookup field access. Only use for getId(), WebApi responses, and comparisons.\n *\n * @param guid - A GUID string, possibly with braces and mixed case\n * @returns Normalized GUID (lowercase, no braces), or empty string if null/empty\n *\n * @example\n * ```typescript\n * const recordId = normalizeGuid(form.$context.data.entity.getId());\n * // \"{A1B2C3D4-...}\" -> \"a1b2c3d4-...\"\n *\n * const currencyId = normalizeGuid(result._transactioncurrencyid_value as string);\n * ```\n */\nexport function normalizeGuid(guid: string | null | undefined): string {\n if (!guid) return '';\n return guid.replace(/[{}]/g, '').toLowerCase();\n}\n\n// ─── Legacy Exports ──────────────────────────────────────────────────────────\n\n/** @deprecated Use ExtractFields<TForm> instead */\nexport type FormFields<TForm> = ExtractFields<TForm>;\n"],"mappings":";AAgCO,SAAS,UAAU,MAAqC;AAC7D,QAAM,SAAS,KAAK,WAAW,KAAK,MAAM,QAAQ,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI;AACvE,MAAI,OAAO,WAAW,EAAG,QAAO;AAChC,SAAO,YAAY,OAAO,KAAK,GAAG,CAAC;AACrC;AAyBO,SAAS,YACd,UACA,oBACyD;AACzD,QAAM,MAAM,IAAI,kBAAkB;AAClC,QAAM,KAAK,SAAS,GAAG;AACvB,MAAI,CAAC,GAAI,QAAO;AAEhB,SAAO;AAAA,IACL;AAAA,IACA,MAAO,SAAS,GAAG,GAAG,4CAA4C,KAAgB;AAAA,IAClF,YAAa,SAAS,GAAG,GAAG,2CAA2C,KAAgB;AAAA,EACzF;AACF;AAiBO,SAAS,aACd,UACA,sBACyE;AACzE,QAAM,SAAkF,CAAC;AACzF,aAAW,QAAQ,sBAAsB;AACvC,WAAO,IAAI,IAAI,YAAY,UAAU,IAAI;AAAA,EAC3C;AACA,SAAO;AACT;AAiBO,SAAS,oBACd,UACA,WACe;AACf,SAAQ,SAAS,GAAG,SAAS,4CAA4C,KAAgB;AAC3F;AAiBO,SAAS,aAAa,QAAkB,QAAwB;AACrE,QAAM,QAAkB,CAAC;AACzB,MAAI,OAAO,SAAS,EAAG,OAAM,KAAK,WAAW,OAAO,KAAK,GAAG,CAAC,EAAE;AAC/D,MAAI,OAAQ,OAAM,KAAK,WAAW,MAAM,EAAE;AAC1C,SAAO,MAAM,SAAS,IAAI,IAAI,MAAM,KAAK,GAAG,CAAC,KAAK;AACpD;AAsBO,SAAS,WACd,MACyD;AACzD,QAAM,SAAS,KAAK,SAAS;AAC7B,MAAI,CAAC,UAAU,OAAO,WAAW,EAAG,QAAO;AAC3C,QAAM,QAAQ,OAAO,CAAC;AACtB,SAAO;AAAA,IACL,IAAI,MAAM,GAAG,QA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QAAO;AAC7E,aAAO,YAAY,aAAa,IAAI,MAAM;AAAA,IAC5C;AAAA,EACF,CAAC;AACH;AA0BO,SAAS,cAAc,MAAyC;AACrE,MAAI,CAAC,KAAM,QAAO;AAClB,SAAO,KAAK,QAAQ,SAAS,EAAE,EAAE,YAAY;AAC/C;","names":["DisplayState","FormNotificationLevel","RequiredLevel","SubmitMode","SaveMode","ClientType","ClientState","OperationType","StructuralProperty","BindingType"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xrmforge/helpers",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Browser-safe runtime helpers for Dynamics 365 form scripts: select(), parseLookup(), typedForm(), Xrm constants, Action/Function executors",
5
5
  "keywords": [
6
6
  "dynamics-365",