@xrmforge/helpers 0.11.0 → 0.13.0
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 +61 -1
- package/dist/index.js +18 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -133,6 +133,56 @@ declare function parseMultiSelect(value: unknown, emptyAsNull: true): number[] |
|
|
|
133
133
|
* ```
|
|
134
134
|
*/
|
|
135
135
|
declare function selectExpand(fields: string[], expand: string): string;
|
|
136
|
+
/**
|
|
137
|
+
* Read a single-valued expanded navigation property from a Web API response as a
|
|
138
|
+
* typed object (F-MK9-08).
|
|
139
|
+
*
|
|
140
|
+
* When a record is loaded with `$expand` on a single-valued lookup, the nested
|
|
141
|
+
* record arrives under the navigation property name as a plain object. This
|
|
142
|
+
* returns it typed as `Partial<T>` (use the generated Entity interface for `T`).
|
|
143
|
+
* `Partial<T>` is deliberate and honest: a partial `$select` inside the `$expand`
|
|
144
|
+
* only returns the selected fields, so the others are genuinely absent.
|
|
145
|
+
*
|
|
146
|
+
* Replaces the hand-cast `entity['nav'] as { ... }`. There is no compile-time
|
|
147
|
+
* binding that `nav` matches `T` (same loose binding as {@link parseLookup}).
|
|
148
|
+
*
|
|
149
|
+
* @param entity - The raw Web API response object (the parent record)
|
|
150
|
+
* @param nav - Navigation property name (use a `XxxNavigationProperties` member)
|
|
151
|
+
* @returns The expanded record as `Partial<T>`, or `null` if absent/empty
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* const opp = await Xrm.WebApi.retrieveRecord(EntityNames.Opportunity, id,
|
|
156
|
+
* selectExpand([OpportunityFields.Name], `${OpportunityNav.MarkantRoleId}($select=markant_name)`));
|
|
157
|
+
* const role = expanded<MarkantRole>(opp, OpportunityNav.MarkantRoleId);
|
|
158
|
+
* role?.markant_name; // string | undefined (Partial)
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
declare function expanded<T>(entity: Record<string, unknown>, nav: string): Partial<T> | null;
|
|
162
|
+
/**
|
|
163
|
+
* Read a collection-valued expanded navigation property from a Web API response as
|
|
164
|
+
* a typed array (F-MK9-08).
|
|
165
|
+
*
|
|
166
|
+
* When a record is loaded with `$expand` on a 1:N / N:N navigation property, the
|
|
167
|
+
* related records arrive under the navigation property name as an array. This
|
|
168
|
+
* returns them typed as `Partial<T>[]` (use the generated Entity interface for
|
|
169
|
+
* `T`). `Partial<T>` is deliberate: a partial `$select` only returns the selected
|
|
170
|
+
* fields. Returns an empty array when the navigation property is absent.
|
|
171
|
+
*
|
|
172
|
+
* @param entity - The raw Web API response object (the parent record)
|
|
173
|
+
* @param nav - Collection navigation property name
|
|
174
|
+
* @returns The expanded records as `Partial<T>[]` (empty array if absent)
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```typescript
|
|
178
|
+
* const account = await Xrm.WebApi.retrieveRecord(EntityNames.Account, id,
|
|
179
|
+
* selectExpand([AccountFields.Name], 'contact_customer_accounts($select=fullname)'));
|
|
180
|
+
* for (const contact of expandedMany<Contact>(account, 'contact_customer_accounts')) {
|
|
181
|
+
* contact.fullname; // string | undefined (Partial)
|
|
182
|
+
* }
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
declare function expandedMany<T>(entity: Record<string, unknown>, nav: string): Partial<T>[];
|
|
136
186
|
/**
|
|
137
187
|
* Extract the first lookup value from a FormContext lookup attribute.
|
|
138
188
|
*
|
|
@@ -831,6 +881,12 @@ interface AppNotificationOptions {
|
|
|
831
881
|
showCloseButton?: boolean;
|
|
832
882
|
/** Optional action button. */
|
|
833
883
|
action?: Xrm.App.Action;
|
|
884
|
+
/**
|
|
885
|
+
* Auto-clear the banner after this many milliseconds (fire-and-forget). Omit or
|
|
886
|
+
* set to <= 0 to keep the banner until it is dismissed manually. Saves callers
|
|
887
|
+
* from wiring up their own `setTimeout` + `clearGlobalNotification`.
|
|
888
|
+
*/
|
|
889
|
+
autoHideMs?: number;
|
|
834
890
|
}
|
|
835
891
|
/**
|
|
836
892
|
* Show a global app-level notification banner and return its id.
|
|
@@ -846,6 +902,10 @@ interface AppNotificationOptions {
|
|
|
846
902
|
*
|
|
847
903
|
* @example
|
|
848
904
|
* const id = await addAppNotification(lang.saved, AppNotificationLevel.Success, { showCloseButton: true });
|
|
905
|
+
*
|
|
906
|
+
* @example
|
|
907
|
+
* // Transient banner that clears itself after 4 seconds:
|
|
908
|
+
* await addAppNotification(lang.saved, AppNotificationLevel.Success, { autoHideMs: 4000 });
|
|
849
909
|
*/
|
|
850
910
|
declare function addAppNotification(message: string, level: AppNotificationLevel, options?: AppNotificationOptions): Promise<string>;
|
|
851
911
|
|
|
@@ -890,4 +950,4 @@ declare function clearEnvironmentVariableCache(): void;
|
|
|
890
950
|
*/
|
|
891
951
|
declare function getEnvironmentVariable(schemaName: string): Promise<string | null>;
|
|
892
952
|
|
|
893
|
-
export { AppNotificationLevel, type AppNotificationOptions, BindingType, type BoundActionExecutor, type BoundActionWithParamsExecutor, type BoundFunctionExecutor, ClientState, ClientType, type CloudFlowOptions, DisplayState, type FormFields, FormNotificationLevel, FormType, type FormTypeInfoProtocol, OperationType, type ParameterMeta, type ParameterMetaMap, RequiredLevel, SaveMode, StructuralProperty, SubmitMode, type TypedForm, type UnboundActionExecutor, type UnboundActionWithParamsExecutor, type UnboundFunctionExecutor, addAppNotification, callCloudFlow, clearAndSubmit, clearEnvironmentVariableCache, createBoundAction, createBoundFunction, createUnboundAction, createUnboundFunction, executeMultiple, executeRequest, formLookup, formLookupId, formLookupIdUnsafe, formLookupUnsafe, getEnvironmentVariable, isFormType, isUnsavedRecord, normalizeGuid, parseFormattedValue, parseLookup, parseLookups, parseMultiSelect, select, selectExpand, setAndSubmit, setUnsafeAndSubmit, typedForm, withProgress };
|
|
953
|
+
export { AppNotificationLevel, type AppNotificationOptions, BindingType, type BoundActionExecutor, type BoundActionWithParamsExecutor, type BoundFunctionExecutor, ClientState, ClientType, type CloudFlowOptions, DisplayState, type FormFields, FormNotificationLevel, FormType, type FormTypeInfoProtocol, OperationType, type ParameterMeta, type ParameterMetaMap, RequiredLevel, SaveMode, StructuralProperty, SubmitMode, type TypedForm, type UnboundActionExecutor, type UnboundActionWithParamsExecutor, type UnboundFunctionExecutor, addAppNotification, callCloudFlow, clearAndSubmit, clearEnvironmentVariableCache, createBoundAction, createBoundFunction, createUnboundAction, createUnboundFunction, executeMultiple, executeRequest, expanded, expandedMany, formLookup, formLookupId, formLookupIdUnsafe, formLookupUnsafe, getEnvironmentVariable, isFormType, isUnsavedRecord, normalizeGuid, parseFormattedValue, parseLookup, parseLookups, parseMultiSelect, select, selectExpand, setAndSubmit, setUnsafeAndSubmit, typedForm, withProgress };
|
package/dist/index.js
CHANGED
|
@@ -45,6 +45,15 @@ function selectExpand(fields, expand) {
|
|
|
45
45
|
if (expand) parts.push(`$expand=${expand}`);
|
|
46
46
|
return parts.length > 0 ? `?${parts.join("&")}` : "";
|
|
47
47
|
}
|
|
48
|
+
function expanded(entity, nav) {
|
|
49
|
+
const value = entity[nav];
|
|
50
|
+
if (value == null || typeof value !== "object" || Array.isArray(value)) return null;
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
function expandedMany(entity, nav) {
|
|
54
|
+
const value = entity[nav];
|
|
55
|
+
return Array.isArray(value) ? value : [];
|
|
56
|
+
}
|
|
48
57
|
function formLookup(attr) {
|
|
49
58
|
const values = attr.getValue();
|
|
50
59
|
if (!values || values.length === 0) return null;
|
|
@@ -457,7 +466,13 @@ async function addAppNotification(message, level, options = {}) {
|
|
|
457
466
|
showCloseButton: options.showCloseButton ?? false,
|
|
458
467
|
...options.action ? { action: options.action } : {}
|
|
459
468
|
};
|
|
460
|
-
|
|
469
|
+
const id = await Xrm.App.addGlobalNotification(notification);
|
|
470
|
+
if (options.autoHideMs !== void 0 && options.autoHideMs > 0) {
|
|
471
|
+
setTimeout(() => {
|
|
472
|
+
void Xrm.App.clearGlobalNotification(id);
|
|
473
|
+
}, options.autoHideMs);
|
|
474
|
+
}
|
|
475
|
+
return id;
|
|
461
476
|
}
|
|
462
477
|
|
|
463
478
|
// src/environment.ts
|
|
@@ -507,6 +522,8 @@ export {
|
|
|
507
522
|
createUnboundFunction,
|
|
508
523
|
executeMultiple,
|
|
509
524
|
executeRequest,
|
|
525
|
+
expanded,
|
|
526
|
+
expandedMany,
|
|
510
527
|
formLookup,
|
|
511
528
|
formLookupId,
|
|
512
529
|
formLookupIdUnsafe,
|
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","../src/cloud-flow.ts","../src/form-submit.ts","../src/app-notification.ts","../src/environment.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 * Parse a MultiSelect OptionSet value into a number array.\r\n *\r\n * MultiSelect OptionSets come back in different shapes: the Web API returns a\r\n * comma-separated string (`\"595300000,595300001\"`), a form attribute returns a\r\n * `number[]`. This normalizes all shapes (comma string, number[], single number,\r\n * null/undefined) to a clean `number[]` (empty/whitespace parts dropped).\r\n *\r\n * @param value - The raw value (comma string, number[], number, or null)\r\n * @param emptyAsNull - When `true`, an empty result yields `null` instead of `[]`\r\n * (handy for `setValue`, which treats `null` as \"clear\")\r\n * @returns The parsed option values\r\n *\r\n * @example\r\n * // Web API response -> number[] for comparison:\r\n * const types = parseMultiSelect(account.markant_customertypemulticode);\r\n * if (types.includes(CustomerType.Industry)) { ... }\r\n *\r\n * // Writing back to a form field (empty -> null clears it):\r\n * form.markant_customertypemulticode.setValue(parseMultiSelect(raw, true));\r\n */\r\nexport function parseMultiSelect(value: unknown): number[];\r\nexport function parseMultiSelect(value: unknown, emptyAsNull: false): number[];\r\nexport function parseMultiSelect(value: unknown, emptyAsNull: true): number[] | null;\r\nexport function parseMultiSelect(value: unknown, emptyAsNull = false): number[] | null {\r\n let nums: number[];\r\n if (value == null) {\r\n nums = [];\r\n } else if (Array.isArray(value)) {\r\n nums = value.map((v) => Number(v)).filter(Number.isFinite);\r\n } else if (typeof value === 'number') {\r\n nums = [value];\r\n } else if (typeof value === 'string') {\r\n // Drop empty parts BEFORE Number(): Number('') is 0, not NaN, which would\r\n // otherwise sneak a spurious 0 in from a trailing comma.\r\n nums = value\r\n .split(',')\r\n .map((s) => s.trim())\r\n .filter((s) => s !== '')\r\n .map(Number)\r\n .filter(Number.isFinite);\r\n } else {\r\n nums = [];\r\n }\r\n return nums.length === 0 && emptyAsNull ? null : nums;\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/**\r\n * Off-form variant of {@link formLookupId}: read a lookup that is loaded by D365\r\n * but not on the current form layout, reached via the typedForm `$unsafe` proxy.\r\n *\r\n * `$unsafe(nav)` returns `Attribute | null`; this bundles the null check and the\r\n * lookup cast so callers avoid the repetitive\r\n * `form.$unsafe(Nav.X) as Xrm.Attributes.LookupAttribute | null` (F-LMA8-N2).\r\n * Pass the BLANK navigation property name (e.g. a `XxxNavigationProperties` member),\r\n * never the `_value`-form entity Fields enum.\r\n *\r\n * @param form - The typedForm proxy (anything exposing `$unsafe`)\r\n * @param navProperty - The lookup navigation property name (blank, not `_value`-form)\r\n * @returns Normalized GUID (no braces), or null if the field is absent or empty\r\n */\r\nexport function formLookupIdUnsafe(\r\n form: { $unsafe(name: string): Xrm.Attributes.Attribute | null },\r\n navProperty: string,\r\n): string | null {\r\n const attr = form.$unsafe(navProperty);\r\n if (attr == null) return null;\r\n return formLookupId(attr as unknown as { getValue(): { id: string }[] | null });\r\n}\r\n\r\n/**\r\n * Off-form variant of {@link formLookup}: full lookup value (id + name + entityType)\r\n * for an off-form lookup reached via the typedForm `$unsafe` proxy.\r\n *\r\n * @param form - The typedForm proxy (anything exposing `$unsafe`)\r\n * @param navProperty - The lookup navigation property name (blank, not `_value`-form)\r\n * @returns Normalized lookup value, or null if the field is absent or empty\r\n */\r\nexport function formLookupUnsafe(\r\n form: { $unsafe(name: string): Xrm.Attributes.Attribute | null },\r\n navProperty: string,\r\n): { id: string; name: string; entityType: string } | null {\r\n const attr = form.$unsafe(navProperty);\r\n if (attr == null) return null;\r\n return formLookup(\r\n attr as unknown as {\r\n getValue(): { id: string; name?: string; entityType: string }[] | null;\r\n },\r\n );\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/**\r\n * Form type (formContext.ui.getFormType()).\r\n *\r\n * WARNING: XrmEnum.FormType from @types/xrm is a const enum that does NOT exist\r\n * at runtime. esbuild does not resolve const enums from .d.ts files. Using\r\n * XrmEnum.FormType.Create in code produces \"XrmEnum is not defined\" at runtime.\r\n * Use this FormType enum instead (same values, zero runtime overhead).\r\n */\r\nexport const enum FormType {\r\n Undefined = 0,\r\n Create = 1,\r\n Update = 2,\r\n ReadOnly = 3,\r\n Disabled = 4,\r\n BulkEdit = 6,\r\n}\r\n\r\n/**\r\n * True when the form is currently shown in the given {@link FormType}.\r\n *\r\n * `formContext.ui.getFormType()` is typed as `XrmEnum.FormType` (from\r\n * @types/xrm), which is a nominally distinct type from the {@link FormType}\r\n * const enum above. A direct `getFormType() === FormType.Create` therefore\r\n * fails to compile under `strict` with TS2367 (\"This comparison appears to be\r\n * unintentional because the types have no overlap\"). Relational operators\r\n * (`>`/`<`) slip past TS2367 but cannot express an exact match. This helper\r\n * bridges both numeric enums for the equality case without a hand-written cast.\r\n *\r\n * @example\r\n * if (isFormType(form.$context, FormType.Create)) {\r\n * // only on create\r\n * }\r\n */\r\nexport function isFormType(formContext: Xrm.FormContext, formType: FormType): boolean {\r\n return (formContext.ui.getFormType() as number) === (formType as number);\r\n}\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/**\r\n * App-level (global) notification level for Xrm.App.addGlobalNotification.\r\n *\r\n * Mirrors XrmEnum.AppNotificationLevel, which (like all XrmEnum const enums) does\r\n * NOT exist at runtime. Use this enum; {@link addAppNotification} applies the cast\r\n * to the @types/xrm typings at a single boundary.\r\n */\r\nexport const enum AppNotificationLevel {\r\n Success = 1,\r\n Error = 2,\r\n Warning = 3,\r\n Information = 4,\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 (errors propagate to the handler wrapper)\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): void action throws on failure, so just await it\r\n * import { WinQuote } from '../generated/actions/quote';\r\n * 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 ? void : 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 ? void : 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 ? void : 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 ? void : 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 ? void : 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 ? void : TResult>;\r\n }\r\n return undefined as TResult extends void ? void : 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 ? void : 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 ? void : TResult>;\r\n }\r\n return undefined as TResult extends void ? void : 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 an Xrm progress indicator.\r\n *\r\n * Shows a progress spinner before the operation and closes it afterwards\r\n * (success or failure). Errors are NOT displayed here; they propagate to the\r\n * caller so the single error UI is owned by the handler wrapper\r\n * (`wrapHandler`/`wrapCommand`). Showing an error dialog here too would produce\r\n * a duplicate error UI (dialog + form notification) when `withProgress` runs\r\n * inside a wrapped command (the common ribbon case).\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 * // Inside a wrapCommand handler: the wrapper shows the error notification.\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 } 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 { AccountLMFirmaFormTypeInfo } from '../../generated/forms/account.js';\n *\n * const form = typedForm<AccountLMFirmaFormTypeInfo>(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.controls.name; // Control access (typed)\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 */\n/**\n * Type extraction uses duck typing: if TForm has a `fields` property,\n * it's a TypeInfo interface (from typegen >= 0.10.0). Otherwise, fall\n * back to Conditional Type inference on getAttribute overloads.\n *\n * Duck typing (`TForm extends { fields: infer F }`) is more robust than\n * matching against FormTypeInfoProtocol because it doesn't require\n * structural compatibility of attributes/controls/form across packages.\n */\ntype ExtractFields<TForm> =\n TForm extends { fields: infer F extends string } ? F :\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 { attributes: infer A extends Record<string, Xrm.Attributes.Attribute> } ? A :\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 { controls: infer C extends Record<string, Xrm.Controls.Control> } ? C :\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 { form: infer FC } ? FC :\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 * - `controls.fieldName` 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 /**\n * Direct field access: form.fieldName returns the typed Attribute.\n *\n * Non-nullable because the field is in the generated FormXml. If a field\n * is NOT in the generated interface, it won't compile, forcing you to use\n * $unsafe() which IS nullable. This is the compiler warning: a compile\n * error that says \"this field is not on the form, use $unsafe()\".\n */\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: ExtractFormContext<TForm>;\n\n /**\n * Typed control access via form.controls.fieldname.\n *\n * Returns the specific control type from the generated ControlMap\n * (LookupControl, NumberControl, etc.). No cast needed.\n *\n * @example\n * ```typescript\n * form.controls.customerid.setEntityTypes([EntityNames.Account]);\n * form.controls.revenue.setVisible(false);\n * form.controls.name.setDisabled(true);\n * ```\n */\n readonly controls: {\n readonly [K in TFields]: K extends keyof TCtrlMap\n ? TCtrlMap[K]\n : Xrm.Controls.Control;\n };\n\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 *\n * @example\n * ```typescript\n * form.$unsafe(OpportunityFields.VslBeauftragung)?.setValue(closeDate);\n * ```\n */\n $unsafe(name: string): Xrm.Attributes.Attribute | null;\n};\n\n/**\n * Wraps an Xrm Attribute so that setValue() automatically calls setSubmitMode('always').\n *\n * D365 AutoSave only submits \"dirty\" fields. Programmatically set values via setValue()\n * are NOT marked dirty by default, causing silent data loss on AutoSave. This proxy\n * intercepts setValue() and automatically marks the field for submission.\n *\n * This is intentionally invisible to the developer: they write `form.name.setValue('X')`\n * and the framework handles the rest. No more forgotten setSubmitMode calls.\n */\nfunction wrapAttributeWithAutoSubmit(attr: Xrm.Attributes.Attribute): Xrm.Attributes.Attribute {\n return new Proxy(attr, {\n get(target, prop) {\n if (prop === 'setValue') {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Xrm.Attributes.Attribute.setValue has varying signatures per attribute type\n return (value: any) => {\n target.setValue(value);\n target.setSubmitMode('always');\n };\n }\n const val = (target as unknown as Record<string | symbol, unknown>)[prop];\n if (typeof val === 'function') return val.bind(target);\n return val;\n },\n });\n}\n\n/**\n * Create a typed form proxy around a FormContext.\n *\n * Pass the generated FormTypeInfo interface as type parameter (typegen >= 0.9.2).\n * It bundles the field/attribute/control maps so type extraction works across\n * package boundaries; the bare form interface resolves to `never` in consumer\n * projects (overload inference on getAttribute is unreliable across packages, TS 5.9+).\n *\n * @example\n * ```typescript\n * // Pass the generated <Form>TypeInfo type, not the bare form interface.\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 === 'controls') {\n return new Proxy({} as Record<string, Xrm.Controls.Control>, {\n get(_, controlName) {\n if (typeof controlName !== 'string') return undefined;\n return formContext.getControl(controlName);\n },\n });\n }\n if (prop === '$unsafe') {\n return (name: string) => formContext.getAttribute(name);\n }\n const attr = formContext.getAttribute(prop);\n if (attr) return wrapAttributeWithAutoSubmit(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 === 'controls' || 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/**\n * Whether the form's record is not yet persisted (Create form / unsaved).\n *\n * Treats BOTH \"no id\" representations as unsaved: an empty string (some Create\n * forms return `\"\"` from `getId()`) and the null GUID\n * `00000000-0000-0000-0000-000000000000` (the other variant). Use this instead of\n * ad-hoc `getId() === ''` checks, which miss the null-GUID case (F-MK8-N4b).\n *\n * @param formContext - The form context (`executionContext.getFormContext()`)\n * @returns true if the record has no real id yet\n */\nexport function isUnsavedRecord(formContext: {\n data: { entity: { getId(): string } };\n}): boolean {\n const id = normalizeGuid(formContext.data.entity.getId());\n return !id || id === '00000000-0000-0000-0000-000000000000';\n}\n\n// ─── Legacy Exports ──────────────────────────────────────────────────────────\n\n/** @deprecated Use ExtractFields<TForm> instead */\nexport type FormFields<TForm> = ExtractFields<TForm>;\n","/**\r\n * @xrmforge/helpers - Power Automate Cloud Flow caller\r\n *\r\n * Browser-safe, typed wrapper around a Power Automate cloud flow triggered by an\r\n * HTTP request (\"When an HTTP request is received\"). Replaces the hand-written\r\n * fetch wrappers that legacy D365 form scripts use for cloud-flow calls.\r\n *\r\n * The trigger URL contains a SAS signature and is environment-specific: pass it in\r\n * as a parameter (e.g. read from configuration), never hard-code it in source.\r\n * Custom API / Dataverse-proxied calls are a different concern and are covered by\r\n * `createUnboundAction`; this helper is for the direct HTTP-trigger case. Because\r\n * the call runs in the browser, the flow's CORS settings must allow the Dynamics\r\n * origin.\r\n *\r\n * Zero Node.js dependencies (uses the global `fetch`). For a progress spinner,\r\n * compose with `withProgress`: `withProgress('...', () => callCloudFlow(url, body))`.\r\n *\r\n * @example\r\n * ```typescript\r\n * import { callCloudFlow } from '@xrmforge/helpers';\r\n *\r\n * interface PriceRequest { quoteId: string; }\r\n * interface PriceResponse { total: number; currency: string; }\r\n *\r\n * // FLOW_URL comes from configuration, never hard-coded in source.\r\n * const price = await callCloudFlow<PriceRequest, PriceResponse>(\r\n * FLOW_URL,\r\n * { quoteId },\r\n * );\r\n * console.log(price.total, price.currency);\r\n * ```\r\n */\r\n\r\n/** Options for {@link callCloudFlow}. */\r\nexport interface CloudFlowOptions {\r\n /** HTTP method (default `'POST'`; HTTP-trigger flows are usually POST). */\r\n method?: string;\r\n /** Extra request headers, merged over the defaults (the caller's values win). */\r\n headers?: Record<string, string>;\r\n /** AbortSignal to cancel the request (e.g. a timeout or form unload). */\r\n signal?: AbortSignal;\r\n}\r\n\r\n/**\r\n * Call a Power Automate cloud flow via its HTTP request trigger URL.\r\n *\r\n * Sends `body` as JSON for methods that carry a body (anything but GET/HEAD), and\r\n * returns the parsed response: parsed JSON when the flow responds with\r\n * `application/json`, the raw text for other content types, or `undefined` for an\r\n * empty / `204 No Content` response. Throws on any non-2xx HTTP status, with the\r\n * status code and the response body included in the error message.\r\n *\r\n * @typeParam TReq - Shape of the request body.\r\n * @typeParam TRes - Shape of the parsed response.\r\n * @param triggerUrl - The flow's HTTP trigger URL (contains a SAS signature; pass\r\n * from configuration, never hard-code it).\r\n * @param body - Request payload, JSON-serialized when present.\r\n * @param options - Optional HTTP method, extra headers, and abort signal.\r\n * @returns The parsed flow response.\r\n * @throws {Error} If the flow responds with a non-2xx status.\r\n */\r\nexport async function callCloudFlow<TReq = unknown, TRes = unknown>(\r\n triggerUrl: string,\r\n body?: TReq,\r\n options: CloudFlowOptions = {},\r\n): Promise<TRes> {\r\n const method = options.method ?? 'POST';\r\n const hasBody = body !== undefined && method !== 'GET' && method !== 'HEAD';\r\n\r\n const headers: Record<string, string> = {};\r\n if (hasBody) headers['Content-Type'] = 'application/json';\r\n if (options.headers) Object.assign(headers, options.headers);\r\n\r\n const response = await fetch(triggerUrl, {\r\n method,\r\n headers,\r\n body: hasBody ? JSON.stringify(body) : undefined,\r\n signal: options.signal,\r\n });\r\n\r\n if (!response.ok) {\r\n const errorText = await response.text().catch(() => '');\r\n throw new Error(\r\n `Cloud flow call failed (HTTP ${response.status} ${response.statusText})` +\r\n (errorText ? `: ${errorText}` : ''),\r\n );\r\n }\r\n\r\n if (response.status === 204) {\r\n return undefined as TRes;\r\n }\r\n\r\n const contentType = response.headers.get('content-type') ?? '';\r\n if (contentType.includes('application/json')) {\r\n return (await response.json()) as TRes;\r\n }\r\n const text = await response.text();\r\n return (text === '' ? undefined : text) as TRes;\r\n}\r\n","/**\n * @xrmforge/helpers - Attribute submit helpers\n *\n * Set or clear an attribute and force it to be submitted (SubmitMode.Always).\n * D365 AutoSave only submits dirty attributes; programmatically set values on\n * locked/calculated or off-form fields can otherwise be silently dropped.\n */\n\nimport { SubmitMode } from './xrm-constants.js';\n\n/**\n * Clear an attribute (`setValue(null)`) and force it to be submitted.\n *\n * Prefer this over a generic `setAndSubmit(attr, null)`: passing a literal `null`\n * as the value makes TypeScript infer the value type as `null` and fights the\n * attribute's real value type (F-LMA7-09). A dedicated clear helper has no value\n * parameter, so there is nothing to mis-infer.\n *\n * @param attr - A settable attribute (e.g. `form.revenue` from the typedForm proxy)\n */\nexport function clearAndSubmit(attr: {\n setValue(value: null): void;\n setSubmitMode(mode: Xrm.SubmitMode): void;\n}): void {\n attr.setValue(null);\n attr.setSubmitMode(SubmitMode.Always);\n}\n\n/**\n * Set an off-form attribute (loaded by D365 but not on the current form layout,\n * reached via the typedForm `$unsafe` proxy) and force submit.\n *\n * The typedForm proxy only exposes on-form fields; off-form fields go through\n * `$unsafe()`, which returns `Attribute | null`. This helper bundles the null\n * check, `setValue` and `setSubmitMode(Always)` (F-LMA7-07). For on-form fields\n * use the typed proxy directly (`form.field.setValue(v)` + `setSubmitMode`).\n *\n * @param form - The typedForm proxy (anything exposing `$unsafe`)\n * @param field - The off-form attribute logical name (use an entity Fields enum, never a raw string)\n * @param value - The value to set (off-form fields are untyped)\n * @returns `true` if the field existed and was set, `false` if it was absent\n */\nexport function setUnsafeAndSubmit(\n form: { $unsafe(name: string): Xrm.Attributes.Attribute | null },\n field: string,\n value: unknown,\n): boolean {\n const attr = form.$unsafe(field);\n if (attr == null) return false;\n (attr as { setValue(value: unknown): void }).setValue(value);\n attr.setSubmitMode(SubmitMode.Always);\n return true;\n}\n\n/**\n * Set an on-form attribute's value and force it to be submitted (`SubmitMode.Always`).\n *\n * The single most common programmatic-set idiom: D365 AutoSave only submits dirty\n * attributes, so a value set in code without `setSubmitMode(Always)` can be silently\n * dropped. This collapses the two-line `attr.setValue(v); attr.setSubmitMode(Always)`\n * into one type-safe call (the value type is taken from the attribute's `setValue`,\n * so `setAndSubmit(form.revenue, 150000)` rejects a wrong-typed value).\n *\n * Use the typedForm proxy attribute directly (`setAndSubmit(form.revenue, 150000)`).\n * For off-form fields use {@link setUnsafeAndSubmit} (bundles the `$unsafe` null check);\n * to clear a value use {@link clearAndSubmit} (avoids mis-inferring the type from `null`).\n *\n * Explicit opt-in by design: it deliberately does NOT change `setValue` semantics.\n * Some programmatic sets legitimately must NOT submit (read-only display fields,\n * fields set only to trigger an onChange).\n *\n * @param attr - A settable attribute (e.g. `form.revenue` from the typedForm proxy)\n * @param value - The value to set; its type is taken from the attribute's `setValue`\n */\nexport function setAndSubmit<T>(\n attr: { setValue(value: T): void; setSubmitMode(mode: Xrm.SubmitMode): void },\n value: T,\n): void {\n attr.setValue(value);\n attr.setSubmitMode(SubmitMode.Always);\n}\n","/**\n * @xrmforge/helpers - App-level (global) notification helper\n *\n * Wraps Xrm.App.addGlobalNotification and hides the XrmEnum.AppNotificationLevel\n * runtime gap (XrmEnum const enums do not exist at runtime; see AGENT.md pitfall).\n */\n\nimport type { AppNotificationLevel } from './xrm-constants.js';\n\n/** Banner is the only supported global-notification type. */\nconst NOTIFICATION_TYPE_BANNER = 2;\n\n/** Options for {@link addAppNotification}. */\nexport interface AppNotificationOptions {\n /** Show a close (X) button on the banner (default: false). */\n showCloseButton?: boolean;\n /** Optional action button. */\n action?: Xrm.App.Action;\n}\n\n/**\n * Show a global app-level notification banner and return its id.\n *\n * Pass an {@link AppNotificationLevel} (Success/Error/Warning/Information). The\n * cast to the @types/xrm `XrmEnum.AppNotificationLevel` (which has no runtime\n * representation) happens here, once, instead of at every call site.\n *\n * @param message - The banner message\n * @param level - The notification level\n * @param options - Optional banner settings\n * @returns The created notification id (pass to `Xrm.App.clearGlobalNotification`)\n *\n * @example\n * const id = await addAppNotification(lang.saved, AppNotificationLevel.Success, { showCloseButton: true });\n */\nexport async function addAppNotification(\n message: string,\n level: AppNotificationLevel,\n options: AppNotificationOptions = {},\n): Promise<string> {\n const notification: Xrm.App.Notification = {\n type: NOTIFICATION_TYPE_BANNER as Xrm.App.Notification['type'],\n // XrmEnum.AppNotificationLevel has no runtime value; AppNotificationLevel carries\n // the same numbers. Cast at this single boundary to satisfy the typings.\n level: level as unknown as XrmEnum.AppNotificationLevel,\n message,\n showCloseButton: options.showCloseButton ?? false,\n ...(options.action ? { action: options.action } : {}),\n };\n return Xrm.App.addGlobalNotification(notification);\n}\n","/**\n * @xrmforge/helpers - Environment variable reader\n *\n * Read Dataverse environment variables (definition + current value) from form\n * scripts, with in-memory caching for the form session. Typically used by\n * cloud-flow integrations to load Flow URLs without hardcoding (F-MK8-N4a).\n *\n * The definition entity (`environmentvariabledefinition`) and the 1:N relationship\n * to its values (`environmentvariabledefinition_environmentvariablevalue`) are fixed\n * Dataverse system names, so they are hardwired here (typegen only emits Lookup\n * navigation properties, not 1:N collection navs).\n */\n\nconst cache = new Map<string, string | null>();\n\n/**\n * Clear the in-memory environment-variable cache.\n *\n * Useful in tests (call between cases) or to force a re-read after a value changed\n * during the form session.\n */\nexport function clearEnvironmentVariableCache(): void {\n cache.clear();\n}\n\n/**\n * Read a Dataverse environment variable by schema name.\n *\n * Returns the current value if one is set, otherwise the definition's default\n * value, otherwise `null` (definition not found or no value anywhere). Results are\n * cached per schema name for the form session; repeated reads hit the cache.\n *\n * WebApi errors are NOT swallowed: they propagate to the caller (the handler wrapper\n * owns the error UI). A missing definition is a normal `null`, not an error.\n *\n * @param schemaName - The environment variable's schema name (e.g. 'new_FlowUrl')\n * @returns The resolved value, or null if not found / empty\n *\n * @example\n * ```typescript\n * import { getEnvironmentVariable, callCloudFlow } from '@xrmforge/helpers';\n * const url = await getEnvironmentVariable(Constants.VerifyFlowUrlSchemaName);\n * if (url) await callCloudFlow(url, payload);\n * ```\n */\nexport async function getEnvironmentVariable(schemaName: string): Promise<string | null> {\n if (cache.has(schemaName)) return cache.get(schemaName) ?? null;\n\n // Escape single quotes for the OData string literal (defense-in-depth, Goldene Regel 7).\n const safe = schemaName.replace(/'/g, \"''\");\n const query =\n `?$select=defaultvalue&$filter=schemaname eq '${safe}'` +\n `&$expand=environmentvariabledefinition_environmentvariablevalue($select=value)&$top=1`;\n\n const result = await Xrm.WebApi.retrieveMultipleRecords('environmentvariabledefinition', query);\n\n let value: string | null = null;\n const def = result.entities[0] as\n | {\n defaultvalue?: string | null;\n environmentvariabledefinition_environmentvariablevalue?: { value?: string | null }[];\n }\n | undefined;\n if (def) {\n const values = def.environmentvariabledefinition_environmentvariablevalue;\n const current = Array.isArray(values) && values.length > 0 ? values[0]?.value : undefined;\n if (current != null && current !== '') {\n value = current;\n } else if (def.defaultvalue != null && def.defaultvalue !== '') {\n value = def.defaultvalue;\n }\n }\n\n cache.set(schem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D,QAAM,SAAS,MAAM,IAAI,OAAO,wBAAwB,iCAAiC,KAAK;AAE9F,MAAI,QAAuB;AAC3B,QAAM,MAAM,OAAO,SAAS,CAAC;AAM7B,MAAI,KAAK;AACP,UAAM,SAAS,IAAI;AACnB,UAAM,UAAU,MAAM,QAAQ,MAAM,KAAK,OAAO,SAAS,IAAI,OAAO,CAAC,GAAG,QAAQ;AAChF,QAAI,WAAW,QAAQ,YAAY,IAAI;AACrC,cAAQ;AAAA,IACV,WAAW,IAAI,gBAAgB,QAAQ,IAAI,iBAAiB,IAAI;AAC9D,cAAQ,IAAI;AAAA,IACd;AAAA,EACF;AAEA,QAAM,IAAI,YAAY,KAAK;AAC3B,SAAO;AACT;","names":["DisplayState","FormType","FormNotificationLevel","AppNotificationLevel","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","../src/cloud-flow.ts","../src/form-submit.ts","../src/app-notification.ts","../src/environment.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 * Parse a MultiSelect OptionSet value into a number array.\r\n *\r\n * MultiSelect OptionSets come back in different shapes: the Web API returns a\r\n * comma-separated string (`\"595300000,595300001\"`), a form attribute returns a\r\n * `number[]`. This normalizes all shapes (comma string, number[], single number,\r\n * null/undefined) to a clean `number[]` (empty/whitespace parts dropped).\r\n *\r\n * @param value - The raw value (comma string, number[], number, or null)\r\n * @param emptyAsNull - When `true`, an empty result yields `null` instead of `[]`\r\n * (handy for `setValue`, which treats `null` as \"clear\")\r\n * @returns The parsed option values\r\n *\r\n * @example\r\n * // Web API response -> number[] for comparison:\r\n * const types = parseMultiSelect(account.markant_customertypemulticode);\r\n * if (types.includes(CustomerType.Industry)) { ... }\r\n *\r\n * // Writing back to a form field (empty -> null clears it):\r\n * form.markant_customertypemulticode.setValue(parseMultiSelect(raw, true));\r\n */\r\nexport function parseMultiSelect(value: unknown): number[];\r\nexport function parseMultiSelect(value: unknown, emptyAsNull: false): number[];\r\nexport function parseMultiSelect(value: unknown, emptyAsNull: true): number[] | null;\r\nexport function parseMultiSelect(value: unknown, emptyAsNull = false): number[] | null {\r\n let nums: number[];\r\n if (value == null) {\r\n nums = [];\r\n } else if (Array.isArray(value)) {\r\n nums = value.map((v) => Number(v)).filter(Number.isFinite);\r\n } else if (typeof value === 'number') {\r\n nums = [value];\r\n } else if (typeof value === 'string') {\r\n // Drop empty parts BEFORE Number(): Number('') is 0, not NaN, which would\r\n // otherwise sneak a spurious 0 in from a trailing comma.\r\n nums = value\r\n .split(',')\r\n .map((s) => s.trim())\r\n .filter((s) => s !== '')\r\n .map(Number)\r\n .filter(Number.isFinite);\r\n } else {\r\n nums = [];\r\n }\r\n return nums.length === 0 && emptyAsNull ? null : nums;\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/**\r\n * Read a single-valued expanded navigation property from a Web API response as a\r\n * typed object (F-MK9-08).\r\n *\r\n * When a record is loaded with `$expand` on a single-valued lookup, the nested\r\n * record arrives under the navigation property name as a plain object. This\r\n * returns it typed as `Partial<T>` (use the generated Entity interface for `T`).\r\n * `Partial<T>` is deliberate and honest: a partial `$select` inside the `$expand`\r\n * only returns the selected fields, so the others are genuinely absent.\r\n *\r\n * Replaces the hand-cast `entity['nav'] as { ... }`. There is no compile-time\r\n * binding that `nav` matches `T` (same loose binding as {@link parseLookup}).\r\n *\r\n * @param entity - The raw Web API response object (the parent record)\r\n * @param nav - Navigation property name (use a `XxxNavigationProperties` member)\r\n * @returns The expanded record as `Partial<T>`, or `null` if absent/empty\r\n *\r\n * @example\r\n * ```typescript\r\n * const opp = await Xrm.WebApi.retrieveRecord(EntityNames.Opportunity, id,\r\n * selectExpand([OpportunityFields.Name], `${OpportunityNav.MarkantRoleId}($select=markant_name)`));\r\n * const role = expanded<MarkantRole>(opp, OpportunityNav.MarkantRoleId);\r\n * role?.markant_name; // string | undefined (Partial)\r\n * ```\r\n */\r\nexport function expanded<T>(entity: Record<string, unknown>, nav: string): Partial<T> | null {\r\n const value = entity[nav];\r\n if (value == null || typeof value !== 'object' || Array.isArray(value)) return null;\r\n return value as Partial<T>;\r\n}\r\n\r\n/**\r\n * Read a collection-valued expanded navigation property from a Web API response as\r\n * a typed array (F-MK9-08).\r\n *\r\n * When a record is loaded with `$expand` on a 1:N / N:N navigation property, the\r\n * related records arrive under the navigation property name as an array. This\r\n * returns them typed as `Partial<T>[]` (use the generated Entity interface for\r\n * `T`). `Partial<T>` is deliberate: a partial `$select` only returns the selected\r\n * fields. Returns an empty array when the navigation property is absent.\r\n *\r\n * @param entity - The raw Web API response object (the parent record)\r\n * @param nav - Collection navigation property name\r\n * @returns The expanded records as `Partial<T>[]` (empty array if absent)\r\n *\r\n * @example\r\n * ```typescript\r\n * const account = await Xrm.WebApi.retrieveRecord(EntityNames.Account, id,\r\n * selectExpand([AccountFields.Name], 'contact_customer_accounts($select=fullname)'));\r\n * for (const contact of expandedMany<Contact>(account, 'contact_customer_accounts')) {\r\n * contact.fullname; // string | undefined (Partial)\r\n * }\r\n * ```\r\n */\r\nexport function expandedMany<T>(entity: Record<string, unknown>, nav: string): Partial<T>[] {\r\n const value = entity[nav];\r\n return Array.isArray(value) ? (value as Partial<T>[]) : [];\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/**\r\n * Off-form variant of {@link formLookupId}: read a lookup that is loaded by D365\r\n * but not on the current form layout, reached via the typedForm `$unsafe` proxy.\r\n *\r\n * `$unsafe(nav)` returns `Attribute | null`; this bundles the null check and the\r\n * lookup cast so callers avoid the repetitive\r\n * `form.$unsafe(Nav.X) as Xrm.Attributes.LookupAttribute | null` (F-LMA8-N2).\r\n * Pass the BLANK navigation property name (e.g. a `XxxNavigationProperties` member),\r\n * never the `_value`-form entity Fields enum.\r\n *\r\n * @param form - The typedForm proxy (anything exposing `$unsafe`)\r\n * @param navProperty - The lookup navigation property name (blank, not `_value`-form)\r\n * @returns Normalized GUID (no braces), or null if the field is absent or empty\r\n */\r\nexport function formLookupIdUnsafe(\r\n form: { $unsafe(name: string): Xrm.Attributes.Attribute | null },\r\n navProperty: string,\r\n): string | null {\r\n const attr = form.$unsafe(navProperty);\r\n if (attr == null) return null;\r\n return formLookupId(attr as unknown as { getValue(): { id: string }[] | null });\r\n}\r\n\r\n/**\r\n * Off-form variant of {@link formLookup}: full lookup value (id + name + entityType)\r\n * for an off-form lookup reached via the typedForm `$unsafe` proxy.\r\n *\r\n * @param form - The typedForm proxy (anything exposing `$unsafe`)\r\n * @param navProperty - The lookup navigation property name (blank, not `_value`-form)\r\n * @returns Normalized lookup value, or null if the field is absent or empty\r\n */\r\nexport function formLookupUnsafe(\r\n form: { $unsafe(name: string): Xrm.Attributes.Attribute | null },\r\n navProperty: string,\r\n): { id: string; name: string; entityType: string } | null {\r\n const attr = form.$unsafe(navProperty);\r\n if (attr == null) return null;\r\n return formLookup(\r\n attr as unknown as {\r\n getValue(): { id: string; name?: string; entityType: string }[] | null;\r\n },\r\n );\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/**\r\n * Form type (formContext.ui.getFormType()).\r\n *\r\n * WARNING: XrmEnum.FormType from @types/xrm is a const enum that does NOT exist\r\n * at runtime. esbuild does not resolve const enums from .d.ts files. Using\r\n * XrmEnum.FormType.Create in code produces \"XrmEnum is not defined\" at runtime.\r\n * Use this FormType enum instead (same values, zero runtime overhead).\r\n */\r\nexport const enum FormType {\r\n Undefined = 0,\r\n Create = 1,\r\n Update = 2,\r\n ReadOnly = 3,\r\n Disabled = 4,\r\n BulkEdit = 6,\r\n}\r\n\r\n/**\r\n * True when the form is currently shown in the given {@link FormType}.\r\n *\r\n * `formContext.ui.getFormType()` is typed as `XrmEnum.FormType` (from\r\n * @types/xrm), which is a nominally distinct type from the {@link FormType}\r\n * const enum above. A direct `getFormType() === FormType.Create` therefore\r\n * fails to compile under `strict` with TS2367 (\"This comparison appears to be\r\n * unintentional because the types have no overlap\"). Relational operators\r\n * (`>`/`<`) slip past TS2367 but cannot express an exact match. This helper\r\n * bridges both numeric enums for the equality case without a hand-written cast.\r\n *\r\n * @example\r\n * if (isFormType(form.$context, FormType.Create)) {\r\n * // only on create\r\n * }\r\n */\r\nexport function isFormType(formContext: Xrm.FormContext, formType: FormType): boolean {\r\n return (formContext.ui.getFormType() as number) === (formType as number);\r\n}\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/**\r\n * App-level (global) notification level for Xrm.App.addGlobalNotification.\r\n *\r\n * Mirrors XrmEnum.AppNotificationLevel, which (like all XrmEnum const enums) does\r\n * NOT exist at runtime. Use this enum; {@link addAppNotification} applies the cast\r\n * to the @types/xrm typings at a single boundary.\r\n */\r\nexport const enum AppNotificationLevel {\r\n Success = 1,\r\n Error = 2,\r\n Warning = 3,\r\n Information = 4,\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 (errors propagate to the handler wrapper)\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): void action throws on failure, so just await it\r\n * import { WinQuote } from '../generated/actions/quote';\r\n * 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 ? void : 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 ? void : 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 ? void : 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 ? void : 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 ? void : 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 ? void : TResult>;\r\n }\r\n return undefined as TResult extends void ? void : 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 ? void : 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 ? void : TResult>;\r\n }\r\n return undefined as TResult extends void ? void : 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 an Xrm progress indicator.\r\n *\r\n * Shows a progress spinner before the operation and closes it afterwards\r\n * (success or failure). Errors are NOT displayed here; they propagate to the\r\n * caller so the single error UI is owned by the handler wrapper\r\n * (`wrapHandler`/`wrapCommand`). Showing an error dialog here too would produce\r\n * a duplicate error UI (dialog + form notification) when `withProgress` runs\r\n * inside a wrapped command (the common ribbon case).\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 * // Inside a wrapCommand handler: the wrapper shows the error notification.\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 } 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 { AccountLMFirmaFormTypeInfo } from '../../generated/forms/account.js';\n *\n * const form = typedForm<AccountLMFirmaFormTypeInfo>(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.controls.name; // Control access (typed)\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 */\n/**\n * Type extraction uses duck typing: if TForm has a `fields` property,\n * it's a TypeInfo interface (from typegen >= 0.10.0). Otherwise, fall\n * back to Conditional Type inference on getAttribute overloads.\n *\n * Duck typing (`TForm extends { fields: infer F }`) is more robust than\n * matching against FormTypeInfoProtocol because it doesn't require\n * structural compatibility of attributes/controls/form across packages.\n */\ntype ExtractFields<TForm> =\n TForm extends { fields: infer F extends string } ? F :\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 { attributes: infer A extends Record<string, Xrm.Attributes.Attribute> } ? A :\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 { controls: infer C extends Record<string, Xrm.Controls.Control> } ? C :\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 { form: infer FC } ? FC :\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 * - `controls.fieldName` 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 /**\n * Direct field access: form.fieldName returns the typed Attribute.\n *\n * Non-nullable because the field is in the generated FormXml. If a field\n * is NOT in the generated interface, it won't compile, forcing you to use\n * $unsafe() which IS nullable. This is the compiler warning: a compile\n * error that says \"this field is not on the form, use $unsafe()\".\n */\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: ExtractFormContext<TForm>;\n\n /**\n * Typed control access via form.controls.fieldname.\n *\n * Returns the specific control type from the generated ControlMap\n * (LookupControl, NumberControl, etc.). No cast needed.\n *\n * @example\n * ```typescript\n * form.controls.customerid.setEntityTypes([EntityNames.Account]);\n * form.controls.revenue.setVisible(false);\n * form.controls.name.setDisabled(true);\n * ```\n */\n readonly controls: {\n readonly [K in TFields]: K extends keyof TCtrlMap\n ? TCtrlMap[K]\n : Xrm.Controls.Control;\n };\n\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 *\n * @example\n * ```typescript\n * form.$unsafe(OpportunityFields.VslBeauftragung)?.setValue(closeDate);\n * ```\n */\n $unsafe(name: string): Xrm.Attributes.Attribute | null;\n};\n\n/**\n * Wraps an Xrm Attribute so that setValue() automatically calls setSubmitMode('always').\n *\n * D365 AutoSave only submits \"dirty\" fields. Programmatically set values via setValue()\n * are NOT marked dirty by default, causing silent data loss on AutoSave. This proxy\n * intercepts setValue() and automatically marks the field for submission.\n *\n * This is intentionally invisible to the developer: they write `form.name.setValue('X')`\n * and the framework handles the rest. No more forgotten setSubmitMode calls.\n */\nfunction wrapAttributeWithAutoSubmit(attr: Xrm.Attributes.Attribute): Xrm.Attributes.Attribute {\n return new Proxy(attr, {\n get(target, prop) {\n if (prop === 'setValue') {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Xrm.Attributes.Attribute.setValue has varying signatures per attribute type\n return (value: any) => {\n target.setValue(value);\n target.setSubmitMode('always');\n };\n }\n const val = (target as unknown as Record<string | symbol, unknown>)[prop];\n if (typeof val === 'function') return val.bind(target);\n return val;\n },\n });\n}\n\n/**\n * Create a typed form proxy around a FormContext.\n *\n * Pass the generated FormTypeInfo interface as type parameter (typegen >= 0.9.2).\n * It bundles the field/attribute/control maps so type extraction works across\n * package boundaries; the bare form interface resolves to `never` in consumer\n * projects (overload inference on getAttribute is unreliable across packages, TS 5.9+).\n *\n * @example\n * ```typescript\n * // Pass the generated <Form>TypeInfo type, not the bare form interface.\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 === 'controls') {\n return new Proxy({} as Record<string, Xrm.Controls.Control>, {\n get(_, controlName) {\n if (typeof controlName !== 'string') return undefined;\n return formContext.getControl(controlName);\n },\n });\n }\n if (prop === '$unsafe') {\n return (name: string) => formContext.getAttribute(name);\n }\n const attr = formContext.getAttribute(prop);\n if (attr) return wrapAttributeWithAutoSubmit(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 === 'controls' || 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/**\n * Whether the form's record is not yet persisted (Create form / unsaved).\n *\n * Treats BOTH \"no id\" representations as unsaved: an empty string (some Create\n * forms return `\"\"` from `getId()`) and the null GUID\n * `00000000-0000-0000-0000-000000000000` (the other variant). Use this instead of\n * ad-hoc `getId() === ''` checks, which miss the null-GUID case (F-MK8-N4b).\n *\n * @param formContext - The form context (`executionContext.getFormContext()`)\n * @returns true if the record has no real id yet\n */\nexport function isUnsavedRecord(formContext: {\n data: { entity: { getId(): string } };\n}): boolean {\n const id = normalizeGuid(formContext.data.entity.getId());\n return !id || id === '00000000-0000-0000-0000-000000000000';\n}\n\n// ─── Legacy Exports ──────────────────────────────────────────────────────────\n\n/** @deprecated Use ExtractFields<TForm> instead */\nexport type FormFields<TForm> = ExtractFields<TForm>;\n","/**\r\n * @xrmforge/helpers - Power Automate Cloud Flow caller\r\n *\r\n * Browser-safe, typed wrapper around a Power Automate cloud flow triggered by an\r\n * HTTP request (\"When an HTTP request is received\"). Replaces the hand-written\r\n * fetch wrappers that legacy D365 form scripts use for cloud-flow calls.\r\n *\r\n * The trigger URL contains a SAS signature and is environment-specific: pass it in\r\n * as a parameter (e.g. read from configuration), never hard-code it in source.\r\n * Custom API / Dataverse-proxied calls are a different concern and are covered by\r\n * `createUnboundAction`; this helper is for the direct HTTP-trigger case. Because\r\n * the call runs in the browser, the flow's CORS settings must allow the Dynamics\r\n * origin.\r\n *\r\n * Zero Node.js dependencies (uses the global `fetch`). For a progress spinner,\r\n * compose with `withProgress`: `withProgress('...', () => callCloudFlow(url, body))`.\r\n *\r\n * @example\r\n * ```typescript\r\n * import { callCloudFlow } from '@xrmforge/helpers';\r\n *\r\n * interface PriceRequest { quoteId: string; }\r\n * interface PriceResponse { total: number; currency: string; }\r\n *\r\n * // FLOW_URL comes from configuration, never hard-coded in source.\r\n * const price = await callCloudFlow<PriceRequest, PriceResponse>(\r\n * FLOW_URL,\r\n * { quoteId },\r\n * );\r\n * console.log(price.total, price.currency);\r\n * ```\r\n */\r\n\r\n/** Options for {@link callCloudFlow}. */\r\nexport interface CloudFlowOptions {\r\n /** HTTP method (default `'POST'`; HTTP-trigger flows are usually POST). */\r\n method?: string;\r\n /** Extra request headers, merged over the defaults (the caller's values win). */\r\n headers?: Record<string, string>;\r\n /** AbortSignal to cancel the request (e.g. a timeout or form unload). */\r\n signal?: AbortSignal;\r\n}\r\n\r\n/**\r\n * Call a Power Automate cloud flow via its HTTP request trigger URL.\r\n *\r\n * Sends `body` as JSON for methods that carry a body (anything but GET/HEAD), and\r\n * returns the parsed response: parsed JSON when the flow responds with\r\n * `application/json`, the raw text for other content types, or `undefined` for an\r\n * empty / `204 No Content` response. Throws on any non-2xx HTTP status, with the\r\n * status code and the response body included in the error message.\r\n *\r\n * @typeParam TReq - Shape of the request body.\r\n * @typeParam TRes - Shape of the parsed response.\r\n * @param triggerUrl - The flow's HTTP trigger URL (contains a SAS signature; pass\r\n * from configuration, never hard-code it).\r\n * @param body - Request payload, JSON-serialized when present.\r\n * @param options - Optional HTTP method, extra headers, and abort signal.\r\n * @returns The parsed flow response.\r\n * @throws {Error} If the flow responds with a non-2xx status.\r\n */\r\nexport async function callCloudFlow<TReq = unknown, TRes = unknown>(\r\n triggerUrl: string,\r\n body?: TReq,\r\n options: CloudFlowOptions = {},\r\n): Promise<TRes> {\r\n const method = options.method ?? 'POST';\r\n const hasBody = body !== undefined && method !== 'GET' && method !== 'HEAD';\r\n\r\n const headers: Record<string, string> = {};\r\n if (hasBody) headers['Content-Type'] = 'application/json';\r\n if (options.headers) Object.assign(headers, options.headers);\r\n\r\n const response = await fetch(triggerUrl, {\r\n method,\r\n headers,\r\n body: hasBody ? JSON.stringify(body) : undefined,\r\n signal: options.signal,\r\n });\r\n\r\n if (!response.ok) {\r\n const errorText = await response.text().catch(() => '');\r\n throw new Error(\r\n `Cloud flow call failed (HTTP ${response.status} ${response.statusText})` +\r\n (errorText ? `: ${errorText}` : ''),\r\n );\r\n }\r\n\r\n if (response.status === 204) {\r\n return undefined as TRes;\r\n }\r\n\r\n const contentType = response.headers.get('content-type') ?? '';\r\n if (contentType.includes('application/json')) {\r\n return (await response.json()) as TRes;\r\n }\r\n const text = await response.text();\r\n return (text === '' ? undefined : text) as TRes;\r\n}\r\n","/**\n * @xrmforge/helpers - Attribute submit helpers\n *\n * Set or clear an attribute and force it to be submitted (SubmitMode.Always).\n * D365 AutoSave only submits dirty attributes; programmatically set values on\n * locked/calculated or off-form fields can otherwise be silently dropped.\n */\n\nimport { SubmitMode } from './xrm-constants.js';\n\n/**\n * Clear an attribute (`setValue(null)`) and force it to be submitted.\n *\n * Prefer this over a generic `setAndSubmit(attr, null)`: passing a literal `null`\n * as the value makes TypeScript infer the value type as `null` and fights the\n * attribute's real value type (F-LMA7-09). A dedicated clear helper has no value\n * parameter, so there is nothing to mis-infer.\n *\n * @param attr - A settable attribute (e.g. `form.revenue` from the typedForm proxy)\n */\nexport function clearAndSubmit(attr: {\n setValue(value: null): void;\n setSubmitMode(mode: Xrm.SubmitMode): void;\n}): void {\n attr.setValue(null);\n attr.setSubmitMode(SubmitMode.Always);\n}\n\n/**\n * Set an off-form attribute (loaded by D365 but not on the current form layout,\n * reached via the typedForm `$unsafe` proxy) and force submit.\n *\n * The typedForm proxy only exposes on-form fields; off-form fields go through\n * `$unsafe()`, which returns `Attribute | null`. This helper bundles the null\n * check, `setValue` and `setSubmitMode(Always)` (F-LMA7-07). For on-form fields\n * use the typed proxy directly (`form.field.setValue(v)` + `setSubmitMode`).\n *\n * @param form - The typedForm proxy (anything exposing `$unsafe`)\n * @param field - The off-form attribute logical name (use an entity Fields enum, never a raw string)\n * @param value - The value to set (off-form fields are untyped)\n * @returns `true` if the field existed and was set, `false` if it was absent\n */\nexport function setUnsafeAndSubmit(\n form: { $unsafe(name: string): Xrm.Attributes.Attribute | null },\n field: string,\n value: unknown,\n): boolean {\n const attr = form.$unsafe(field);\n if (attr == null) return false;\n (attr as { setValue(value: unknown): void }).setValue(value);\n attr.setSubmitMode(SubmitMode.Always);\n return true;\n}\n\n/**\n * Set an on-form attribute's value and force it to be submitted (`SubmitMode.Always`).\n *\n * The single most common programmatic-set idiom: D365 AutoSave only submits dirty\n * attributes, so a value set in code without `setSubmitMode(Always)` can be silently\n * dropped. This collapses the two-line `attr.setValue(v); attr.setSubmitMode(Always)`\n * into one type-safe call (the value type is taken from the attribute's `setValue`,\n * so `setAndSubmit(form.revenue, 150000)` rejects a wrong-typed value).\n *\n * Use the typedForm proxy attribute directly (`setAndSubmit(form.revenue, 150000)`).\n * For off-form fields use {@link setUnsafeAndSubmit} (bundles the `$unsafe` null check);\n * to clear a value use {@link clearAndSubmit} (avoids mis-inferring the type from `null`).\n *\n * Explicit opt-in by design: it deliberately does NOT change `setValue` semantics.\n * Some programmatic sets legitimately must NOT submit (read-only display fields,\n * fields set only to trigger an onChange).\n *\n * @param attr - A settable attribute (e.g. `form.revenue` from the typedForm proxy)\n * @param value - The value to set; its type is taken from the attribute's `setValue`\n */\nexport function setAndSubmit<T>(\n attr: { setValue(value: T): void; setSubmitMode(mode: Xrm.SubmitMode): void },\n value: T,\n): void {\n attr.setValue(value);\n attr.setSubmitMode(SubmitMode.Always);\n}\n","/**\n * @xrmforge/helpers - App-level (global) notification helper\n *\n * Wraps Xrm.App.addGlobalNotification and hides the XrmEnum.AppNotificationLevel\n * runtime gap (XrmEnum const enums do not exist at runtime; see AGENT.md pitfall).\n */\n\nimport type { AppNotificationLevel } from './xrm-constants.js';\n\n/** Banner is the only supported global-notification type. */\nconst NOTIFICATION_TYPE_BANNER = 2;\n\n/** Options for {@link addAppNotification}. */\nexport interface AppNotificationOptions {\n /** Show a close (X) button on the banner (default: false). */\n showCloseButton?: boolean;\n /** Optional action button. */\n action?: Xrm.App.Action;\n /**\n * Auto-clear the banner after this many milliseconds (fire-and-forget). Omit or\n * set to <= 0 to keep the banner until it is dismissed manually. Saves callers\n * from wiring up their own `setTimeout` + `clearGlobalNotification`.\n */\n autoHideMs?: number;\n}\n\n/**\n * Show a global app-level notification banner and return its id.\n *\n * Pass an {@link AppNotificationLevel} (Success/Error/Warning/Information). The\n * cast to the @types/xrm `XrmEnum.AppNotificationLevel` (which has no runtime\n * representation) happens here, once, instead of at every call site.\n *\n * @param message - The banner message\n * @param level - The notification level\n * @param options - Optional banner settings\n * @returns The created notification id (pass to `Xrm.App.clearGlobalNotification`)\n *\n * @example\n * const id = await addAppNotification(lang.saved, AppNotificationLevel.Success, { showCloseButton: true });\n *\n * @example\n * // Transient banner that clears itself after 4 seconds:\n * await addAppNotification(lang.saved, AppNotificationLevel.Success, { autoHideMs: 4000 });\n */\nexport async function addAppNotification(\n message: string,\n level: AppNotificationLevel,\n options: AppNotificationOptions = {},\n): Promise<string> {\n const notification: Xrm.App.Notification = {\n type: NOTIFICATION_TYPE_BANNER as Xrm.App.Notification['type'],\n // XrmEnum.AppNotificationLevel has no runtime value; AppNotificationLevel carries\n // the same numbers. Cast at this single boundary to satisfy the typings.\n level: level as unknown as XrmEnum.AppNotificationLevel,\n message,\n showCloseButton: options.showCloseButton ?? false,\n ...(options.action ? { action: options.action } : {}),\n };\n const id = await Xrm.App.addGlobalNotification(notification);\n if (options.autoHideMs !== undefined && options.autoHideMs > 0) {\n // Fire-and-forget: schedule removal without forcing callers to await it.\n setTimeout(() => {\n void Xrm.App.clearGlobalNotification(id);\n }, options.autoHideMs);\n }\n return id;\n}\n","/**\n * @xrmforge/helpers - Environment variable reader\n *\n * Read Dataverse environment variables (definition + current value) from form\n * scripts, with in-memory caching for the form session. Typically used by\n * cloud-flow integrations to load Flow URLs without hardcoding (F-MK8-N4a).\n *\n * The definition entity (`environmentvariabledefinition`) and the 1:N relationship\n * to its values (`environmentvariabledefinition_environmentvariablevalue`) are fixed\n * Dataverse system names, so they are hardwired here (typegen only emits Lookup\n * navigation properties, not 1:N collection navs).\n */\n\nconst cache = new Map<string, string | null>();\n\n/**\n * Clear the in-memory environment-variable cache.\n *\n * Useful in tests (call between cases) or to force a re-read after a value changed\n * during the form session.\n */\nexport function clearEnvironmentVariableCache(): void {\n cache.clear();\n}\n\n/**\n * Read a Dataverse environment variable by schema name.\n *\n * Returns the current value if one is set, otherwise the definition's default\n * value, otherwise `null` (definition not found or no value anywhere). Results are\n * cached per schema name for the form session; repeated reads hit the cache.\n *\n * WebApi errors are NOT swallowed: they propagate to the caller (the handler wrapper\n * owns the error UI). A missing definition is a normal `null`, not an error.\n *\n * @param schemaName - The environment variable's schema name (e.g. 'new_FlowUrl')\n * @returns The resolved value, or null if not found / empty\n *\n * @example\n * ```typescript\n * import { getEnvironmentVariable, callCloudFlow } from '@xrmforge/helpers';\n * const url = await getEnvironmentVariable(Constants.VerifyFlowUrlSchemaName);\n * if (url) await callCloudFlow(url, payload);\n * ```\n */\nexport async function getEnvironmentVariable(schemaName: string): Promise<string | null> {\n if (cache.has(schemaName)) return cache.get(schemaName) ?? null;\n\n // Escape single quotes for the OData string literal (defense-in-depth, Goldene Regel 7).\n const safe = schemaName.replace(/'/g, \"''\");\n const query =\n `?$select=defaultvalue&$filter=schemaname eq '${safe}'` +\n `&$expand=environmentvariabledefinition_environmentvariablevalue($select=value)&$top=1`;\n\n const result = await Xrm.WebApi.retrieveMultipleRecords('environmentvariabledefinition', query);\n\n let value: string | null = null;\n const def = result.entities[0] as\n | {\n defaultvalue?: string | null;\n environmentvariabledefinition_environmentvariablevalue?: { value?: string | null }[];\n }\n | undefined;\n if (def) {\n const values = def.environmentvariabledefinition_environmentvariablevalue;\n const current = Array.isArray(values) && values.length > 0 ? values[0]?.value : undefined;\n if (current != null && current !== '') {\n value = current;\n } else if (def.defaultvalue != null && def.defaultvalue !== '') {\n value = def.defaultvalue;\n }\n }\n\n cache.set(schemaName, value);\n return value;\n}\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,SAA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I;AAGtD,QAAM,SAAS,MAAM,IAAI,OAAO,wBAAwB,iCAAiC,KAAK;AAE9F,MAAI,QAAuB;AAC3B,QAAM,MAAM,OAAO,SAAS,CAAC;AAM7B,MAAI,KAAK;AACP,UAAM,SAAS,IAAI;AACnB,UAAM,UAAU,MAAM,QAAQ,MAAM,KAAK,OAAO,SAAS,IAAI,OAAO,CAAC,GAAG,QAAQ;AAChF,QAAI,WAAW,QAAQ,YAAY,IAAI;AACrC,cAAQ;AAAA,IACV,WAAW,IAAI,gBAAgB,QAAQ,IAAI,iBAAiB,IAAI;AAC9D,cAAQ,IAAI;AAAA,IACd;AAAA,EACF;AAEA,QAAM,IAAI,YAAY,KAAK;AAC3B,SAAO;AACT;","names":["DisplayState","FormType","FormNotificationLevel","AppNotificationLevel","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
|
+
"version": "0.13.0",
|
|
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",
|