@pptb/types 1.0.19-beta.2 → 1.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dataverseAPI.d.ts +776 -0
  2. package/package.json +1 -1
package/dataverseAPI.d.ts CHANGED
@@ -58,6 +58,36 @@ declare namespace DataverseAPI {
58
58
  [key: string]: unknown;
59
59
  }
60
60
 
61
+ /**
62
+ * EntityReference for Function parameters
63
+ * User-friendly format that accepts entity logical name instead of requiring manual entity set name pluralization
64
+ *
65
+ * @example
66
+ * // User-friendly format (recommended)
67
+ * const target: EntityReference = {
68
+ * entityLogicalName: 'account',
69
+ * id: 'guid-here'
70
+ * };
71
+ *
72
+ * @example
73
+ * // Advanced format (also supported)
74
+ * const target = {
75
+ * '@odata.id': 'accounts(guid-here)'
76
+ * };
77
+ */
78
+ export interface EntityReference {
79
+ /**
80
+ * Logical name of the entity (e.g., 'account', 'contact', 'systemuser')
81
+ * Will be automatically converted to entity set name (e.g., 'accounts', 'contacts', 'systemusers')
82
+ */
83
+ entityLogicalName: string;
84
+
85
+ /**
86
+ * GUID of the record
87
+ */
88
+ id: string;
89
+ }
90
+
61
91
  /**
62
92
  * Execute operation request
63
93
  */
@@ -84,10 +114,202 @@ declare namespace DataverseAPI {
84
114
 
85
115
  /**
86
116
  * Parameters to pass to the operation
117
+ *
118
+ * ## For Functions (GET requests):
119
+ * Parameters are passed in the URL query string using parameter aliases.
120
+ *
121
+ * ### Parameter Types:
122
+ * - **Primitives**:
123
+ * - Strings: Automatically wrapped in single quotes (e.g., 'Pacific Standard Time')
124
+ * - Numbers: Passed as-is (e.g., 1033)
125
+ * - Booleans: Lowercase true/false
126
+ * - null: Passed as null
127
+ *
128
+ * - **EntityReference**:
129
+ * - Recommended: `{ entityLogicalName: 'account', id: 'guid' }`
130
+ * - Advanced: `{ '@odata.id': 'accounts(guid)' }`
131
+ *
132
+ * - **Enum values**:
133
+ * - Must use Microsoft.Dynamics.CRM prefix format
134
+ * - Single value: `"Microsoft.Dynamics.CRM.EntityFilters'Entity'"`
135
+ * - Multiple values: `"Microsoft.Dynamics.CRM.EntityFilters'Entity,Attributes,Relationships'"`
136
+ *
137
+ * - **Complex objects**: Will be JSON serialized (e.g., PagingInfo)
138
+ * - **Arrays**: Will be JSON serialized
139
+ *
140
+ * ## For Actions (POST requests):
141
+ * All parameters are passed in the request body as JSON.
142
+ *
143
+ * @example
144
+ * // WhoAmI - Unbound function with no parameters
145
+ * {
146
+ * operationName: 'WhoAmI',
147
+ * operationType: 'function'
148
+ * // No parameters needed
149
+ * }
150
+ *
151
+ * @example
152
+ * // RetrieveUserQueues - Bound function with boolean parameter
153
+ * {
154
+ * entityName: 'systemuser',
155
+ * entityId: 'user-guid-here',
156
+ * operationName: 'RetrieveUserQueues',
157
+ * operationType: 'function',
158
+ * parameters: {
159
+ * IncludePublic: true
160
+ * }
161
+ * }
162
+ *
163
+ * @example
164
+ * // CalculateRollupField - Unbound function with EntityReference and string
165
+ * {
166
+ * operationName: 'CalculateRollupField',
167
+ * operationType: 'function',
168
+ * parameters: {
169
+ * Target: { entityLogicalName: 'account', id: 'account-guid-here' },
170
+ * FieldName: 'new_totalrevenue'
171
+ * }
172
+ * }
173
+ *
174
+ * @example
175
+ * // GetTimeZoneCodeByLocalizedName - Unbound function with string and number
176
+ * {
177
+ * operationName: 'GetTimeZoneCodeByLocalizedName',
178
+ * operationType: 'function',
179
+ * parameters: {
180
+ * LocalizedStandardName: 'Pacific Standard Time',
181
+ * LocaleId: 1033
182
+ * }
183
+ * }
184
+ *
185
+ * @example
186
+ * // RetrieveAllEntities - Unbound function with enum and boolean
187
+ * {
188
+ * operationName: 'RetrieveAllEntities',
189
+ * operationType: 'function',
190
+ * parameters: {
191
+ * EntityFilters: "Microsoft.Dynamics.CRM.EntityFilters'Entity,Attributes,Relationships'",
192
+ * RetrieveAsIfPublished: false
193
+ * }
194
+ * }
195
+ *
196
+ * @example
197
+ * // RetrieveAttributeChangeHistory - Unbound function with EntityReference, string, and complex object
198
+ * {
199
+ * operationName: 'RetrieveAttributeChangeHistory',
200
+ * operationType: 'function',
201
+ * parameters: {
202
+ * Target: { entityLogicalName: 'account', id: 'account-guid-here' },
203
+ * AttributeLogicalName: 'name',
204
+ * PagingInfo: {
205
+ * PageNumber: 1,
206
+ * Count: 10,
207
+ * ReturnTotalRecordCount: true
208
+ * }
209
+ * }
210
+ * }
211
+ *
212
+ * @example
213
+ * // ImportSolution - Unbound action with parameters in body
214
+ * {
215
+ * operationName: 'ImportSolution',
216
+ * operationType: 'action',
217
+ * parameters: {
218
+ * CustomizationFile: 'base64-encoded-solution-zip',
219
+ * PublishWorkflows: true,
220
+ * OverwriteUnmanagedCustomizations: false
221
+ * }
222
+ * }
87
223
  */
88
224
  parameters?: Record<string, unknown>;
89
225
  }
90
226
 
227
+ /**
228
+ * Localized label for metadata display names and descriptions
229
+ */
230
+ export interface LocalizedLabel {
231
+ "@odata.type"?: "Microsoft.Dynamics.CRM.LocalizedLabel";
232
+ Label: string;
233
+ LanguageCode: number;
234
+ }
235
+
236
+ /**
237
+ * Label structure for metadata properties
238
+ */
239
+ export interface Label {
240
+ "@odata.type"?: "Microsoft.Dynamics.CRM.Label";
241
+ LocalizedLabels: LocalizedLabel[];
242
+ UserLocalizedLabel?: LocalizedLabel;
243
+ }
244
+
245
+ /**
246
+ * Attribute metadata types for Dataverse columns
247
+ * Used with getAttributeODataType() to generate full Microsoft.Dynamics.CRM.*AttributeMetadata type strings
248
+ */
249
+ export enum AttributeMetadataType {
250
+ /** Single-line text field */
251
+ String = "String",
252
+ /** Multi-line text field */
253
+ Memo = "Memo",
254
+ /** Whole number */
255
+ Integer = "Integer",
256
+ /** Big integer (large whole number) */
257
+ BigInt = "BigInt",
258
+ /** Decimal number */
259
+ Decimal = "Decimal",
260
+ /** Floating point number */
261
+ Double = "Double",
262
+ /** Currency field */
263
+ Money = "Money",
264
+ /** Yes/No (boolean) field */
265
+ Boolean = "Boolean",
266
+ /** Date and time */
267
+ DateTime = "DateTime",
268
+ /** Lookup (foreign key reference) */
269
+ Lookup = "Lookup",
270
+ /** Choice (option set/picklist) */
271
+ Picklist = "Picklist",
272
+ /** Multi-select choice */
273
+ MultiSelectPicklist = "MultiSelectPicklist",
274
+ /** State field (active/inactive) */
275
+ State = "State",
276
+ /** Status field (status reason) */
277
+ Status = "Status",
278
+ /** Owner field */
279
+ Owner = "Owner",
280
+ /** Customer field (Account or Contact lookup) */
281
+ Customer = "Customer",
282
+ /** File attachment field */
283
+ File = "File",
284
+ /** Image field */
285
+ Image = "Image",
286
+ /** Unique identifier (GUID) */
287
+ UniqueIdentifier = "UniqueIdentifier",
288
+ }
289
+
290
+ /**
291
+ * Options for metadata CRUD operations
292
+ */
293
+ export interface MetadataOperationOptions {
294
+ /**
295
+ * Associate metadata changes with a specific solution
296
+ * Uses MSCRM.SolutionUniqueName header
297
+ */
298
+ solutionUniqueName?: string;
299
+
300
+ /**
301
+ * Preserve existing localized labels during PUT operations
302
+ * Uses MSCRM.MergeLabels header (defaults to true for updates)
303
+ */
304
+ mergeLabels?: boolean;
305
+
306
+ /**
307
+ * Force fresh metadata read after create/update operations
308
+ * Uses Consistency: Strong header to bypass cache
309
+ */
310
+ consistencyStrong?: boolean;
311
+ }
312
+
91
313
  /**
92
314
  * Dataverse Web API for CRUD operations, queries, and metadata
93
315
  */
@@ -713,6 +935,560 @@ declare namespace DataverseAPI {
713
935
  * const status = await dataverseAPI.getImportJobStatus(importJobId, 'secondary');
714
936
  */
715
937
  getImportJobStatus: (importJobId: string, connectionTarget?: "primary" | "secondary") => Promise<Record<string, unknown>>;
938
+
939
+ // ========================================
940
+ // Metadata Helper Utilities
941
+ // ========================================
942
+
943
+ /**
944
+ * Build a Label structure for metadata display names and descriptions
945
+ * Helper utility to simplify creating localized labels for metadata operations
946
+ *
947
+ * @param text - Display text for the label
948
+ * @param languageCode - Optional language code (defaults to 1033 for English)
949
+ * @returns Label object with properly formatted LocalizedLabels array
950
+ *
951
+ * @example
952
+ * const label = dataverseAPI.buildLabel("Account Name");
953
+ * // Returns: { LocalizedLabels: [{ Label: "Account Name", LanguageCode: 1033 }] }
954
+ *
955
+ * @example
956
+ * // Create label with specific language code
957
+ * const frenchLabel = dataverseAPI.buildLabel("Nom du compte", 1036);
958
+ */
959
+ buildLabel: (text: string, languageCode?: number) => Label;
960
+
961
+ /**
962
+ * Get the OData type string for an attribute metadata type
963
+ * Converts AttributeMetadataType enum to full Microsoft.Dynamics.CRM type path
964
+ *
965
+ * @param attributeType - Attribute metadata type enum value
966
+ * @returns Full OData type string (e.g., "Microsoft.Dynamics.CRM.StringAttributeMetadata")
967
+ *
968
+ * @example
969
+ * const odataType = dataverseAPI.getAttributeODataType(DataverseAPI.AttributeMetadataType.String);
970
+ * // Returns: "Microsoft.Dynamics.CRM.StringAttributeMetadata"
971
+ *
972
+ * @example
973
+ * // Use in attribute definition
974
+ * const attributeDef = {
975
+ * "@odata.type": dataverseAPI.getAttributeODataType(DataverseAPI.AttributeMetadataType.Integer),
976
+ * "SchemaName": "new_priority",
977
+ * "DisplayName": dataverseAPI.buildLabel("Priority")
978
+ * };
979
+ */
980
+ getAttributeODataType: (attributeType: AttributeMetadataType) => string;
981
+
982
+ // ========================================
983
+ // Entity (Table) Metadata CRUD Operations
984
+ // ========================================
985
+
986
+ /**
987
+ * Create a new entity (table) definition in Dataverse
988
+ * NOTE: Metadata changes require explicit publishCustomizations() call to become active
989
+ *
990
+ * @param entityDefinition - Entity metadata payload (must include SchemaName, DisplayName, OwnershipType, and at least one Attribute with IsPrimaryName=true)
991
+ * @param options - Optional metadata operation options (solution assignment, etc.)
992
+ * @param connectionTarget - Optional connection target for multi-connection tools ('primary' or 'secondary'). Defaults to 'primary'.
993
+ * @returns Object containing the created entity's MetadataId
994
+ *
995
+ * @example
996
+ * // Create a new custom table
997
+ * const result = await dataverseAPI.createEntityDefinition({
998
+ * "@odata.type": "Microsoft.Dynamics.CRM.EntityMetadata",
999
+ * "SchemaName": "new_project",
1000
+ * "DisplayName": dataverseAPI.buildLabel("Project"),
1001
+ * "DisplayCollectionName": dataverseAPI.buildLabel("Projects"),
1002
+ * "Description": dataverseAPI.buildLabel("Project tracking table"),
1003
+ * "OwnershipType": "UserOwned",
1004
+ * "HasActivities": true,
1005
+ * "HasNotes": true,
1006
+ * "Attributes": [{
1007
+ * "@odata.type": dataverseAPI.getAttributeODataType(DataverseAPI.AttributeMetadataType.String),
1008
+ * "SchemaName": "new_name",
1009
+ * "RequiredLevel": { "Value": "None" },
1010
+ * "MaxLength": 100,
1011
+ * "FormatName": { "Value": "Text" },
1012
+ * "IsPrimaryName": true,
1013
+ * "DisplayName": dataverseAPI.buildLabel("Project Name"),
1014
+ * "Description": dataverseAPI.buildLabel("The name of the project")
1015
+ * }]
1016
+ * }, {
1017
+ * solutionUniqueName: "MySolution"
1018
+ * });
1019
+ *
1020
+ * console.log("Created entity with MetadataId:", result.id);
1021
+ *
1022
+ * // IMPORTANT: Publish customizations to make changes active
1023
+ * await dataverseAPI.publishCustomizations("new_project");
1024
+ */
1025
+ createEntityDefinition: (entityDefinition: Record<string, unknown>, options?: MetadataOperationOptions, connectionTarget?: "primary" | "secondary") => Promise<{ id: string }>;
1026
+
1027
+ /**
1028
+ * Update an entity (table) definition
1029
+ * NOTE: Uses PUT method which requires the FULL entity definition (retrieve-modify-PUT pattern)
1030
+ * NOTE: Metadata changes require explicit publishCustomizations() call to become active
1031
+ *
1032
+ * @param entityIdentifier - Entity LogicalName or MetadataId
1033
+ * @param entityDefinition - Complete entity metadata payload with all properties
1034
+ * @param options - Optional metadata operation options (mergeLabels defaults to true to preserve translations)
1035
+ * @param connectionTarget - Optional connection target for multi-connection tools ('primary' or 'secondary'). Defaults to 'primary'.
1036
+ *
1037
+ * @example
1038
+ * // Retrieve-Modify-PUT Pattern for updating entity metadata
1039
+ *
1040
+ * // Step 1: Retrieve current entity definition
1041
+ * const currentDef = await dataverseAPI.getEntityMetadata("new_project", true);
1042
+ *
1043
+ * // Step 2: Modify desired properties (must include ALL properties, not just changes)
1044
+ * currentDef.DisplayName = dataverseAPI.buildLabel("Updated Project Name");
1045
+ * currentDef.Description = dataverseAPI.buildLabel("Updated description");
1046
+ *
1047
+ * // Step 3: PUT the entire definition back (mergeLabels=true preserves other language translations)
1048
+ * await dataverseAPI.updateEntityDefinition("new_project", currentDef, {
1049
+ * mergeLabels: true, // Preserve existing translations
1050
+ * solutionUniqueName: "MySolution"
1051
+ * });
1052
+ *
1053
+ * // Step 4: Publish customizations to activate changes
1054
+ * await dataverseAPI.publishCustomizations("new_project");
1055
+ *
1056
+ * @example
1057
+ * // Update using MetadataId instead of LogicalName
1058
+ * await dataverseAPI.updateEntityDefinition(
1059
+ * "70816501-edb9-4740-a16c-6a5efbc05d84",
1060
+ * updatedDefinition,
1061
+ * { mergeLabels: true }
1062
+ * );
1063
+ */
1064
+ updateEntityDefinition: (entityIdentifier: string, entityDefinition: Record<string, unknown>, options?: MetadataOperationOptions, connectionTarget?: "primary" | "secondary") => Promise<void>;
1065
+
1066
+ /**
1067
+ * Delete an entity (table) definition
1068
+ * WARNING: This is a destructive operation that removes the table and all its data
1069
+ *
1070
+ * @param entityIdentifier - Entity LogicalName or MetadataId
1071
+ * @param connectionTarget - Optional connection target for multi-connection tools ('primary' or 'secondary'). Defaults to 'primary'.
1072
+ *
1073
+ * @example
1074
+ * // Delete a custom table (will fail if dependencies exist)
1075
+ * await dataverseAPI.deleteEntityDefinition("new_project");
1076
+ *
1077
+ * @example
1078
+ * // Delete using MetadataId
1079
+ * await dataverseAPI.deleteEntityDefinition("70816501-edb9-4740-a16c-6a5efbc05d84");
1080
+ */
1081
+ deleteEntityDefinition: (entityIdentifier: string, connectionTarget?: "primary" | "secondary") => Promise<void>;
1082
+
1083
+ // ========================================
1084
+ // Attribute (Column) Metadata CRUD Operations
1085
+ // ========================================
1086
+
1087
+ /**
1088
+ * Create a new attribute (column) on an existing entity
1089
+ * NOTE: Metadata changes require explicit publishCustomizations() call to become active
1090
+ *
1091
+ * @param entityLogicalName - Logical name of the entity to add the attribute to
1092
+ * @param attributeDefinition - Attribute metadata payload (must include @odata.type, SchemaName, DisplayName)
1093
+ * @param options - Optional metadata operation options
1094
+ * @param connectionTarget - Optional connection target for multi-connection tools ('primary' or 'secondary'). Defaults to 'primary'.
1095
+ * @returns Object containing the created attribute's MetadataId
1096
+ *
1097
+ * @example
1098
+ * // Create a text column
1099
+ * const result = await dataverseAPI.createAttribute("new_project", {
1100
+ * "@odata.type": dataverseAPI.getAttributeODataType(DataverseAPI.AttributeMetadataType.String),
1101
+ * "SchemaName": "new_description",
1102
+ * "DisplayName": dataverseAPI.buildLabel("Description"),
1103
+ * "Description": dataverseAPI.buildLabel("Project description"),
1104
+ * "RequiredLevel": { "Value": "None" },
1105
+ * "MaxLength": 500,
1106
+ * "FormatName": { "Value": "Text" }
1107
+ * }, {
1108
+ * solutionUniqueName: "MySolution"
1109
+ * });
1110
+ *
1111
+ * console.log("Created attribute with MetadataId:", result.id);
1112
+ * await dataverseAPI.publishCustomizations("new_project");
1113
+ *
1114
+ * @example
1115
+ * // Create a whole number column
1116
+ * await dataverseAPI.createAttribute("new_project", {
1117
+ * "@odata.type": dataverseAPI.getAttributeODataType(DataverseAPI.AttributeMetadataType.Integer),
1118
+ * "SchemaName": "new_priority",
1119
+ * "DisplayName": dataverseAPI.buildLabel("Priority"),
1120
+ * "RequiredLevel": { "Value": "None" },
1121
+ * "MinValue": 1,
1122
+ * "MaxValue": 100
1123
+ * });
1124
+ * await dataverseAPI.publishCustomizations("new_project");
1125
+ *
1126
+ * @example
1127
+ * // Create a choice (picklist) column
1128
+ * await dataverseAPI.createAttribute("new_project", {
1129
+ * "@odata.type": dataverseAPI.getAttributeODataType(DataverseAPI.AttributeMetadataType.Picklist),
1130
+ * "SchemaName": "new_status",
1131
+ * "DisplayName": dataverseAPI.buildLabel("Status"),
1132
+ * "RequiredLevel": { "Value": "None" },
1133
+ * "OptionSet": {
1134
+ * "@odata.type": "Microsoft.Dynamics.CRM.OptionSetMetadata",
1135
+ * "OptionSetType": "Picklist",
1136
+ * "Options": [
1137
+ * { "Value": 1, "Label": dataverseAPI.buildLabel("Active") },
1138
+ * { "Value": 2, "Label": dataverseAPI.buildLabel("On Hold") },
1139
+ * { "Value": 3, "Label": dataverseAPI.buildLabel("Completed") }
1140
+ * ]
1141
+ * }
1142
+ * });
1143
+ * await dataverseAPI.publishCustomizations("new_project");
1144
+ */
1145
+ createAttribute: (entityLogicalName: string, attributeDefinition: Record<string, unknown>, options?: MetadataOperationOptions, connectionTarget?: "primary" | "secondary") => Promise<{ id: string }>;
1146
+
1147
+ /**
1148
+ * Update an attribute (column) definition
1149
+ * NOTE: Uses PUT method which requires the FULL attribute definition (retrieve-modify-PUT pattern)
1150
+ * NOTE: Metadata changes require explicit publishCustomizations() call to become active
1151
+ *
1152
+ * @param entityLogicalName - Logical name of the entity
1153
+ * @param attributeIdentifier - Attribute LogicalName or MetadataId
1154
+ * @param attributeDefinition - Complete attribute metadata payload
1155
+ * @param options - Optional metadata operation options (mergeLabels defaults to true)
1156
+ * @param connectionTarget - Optional connection target for multi-connection tools ('primary' or 'secondary'). Defaults to 'primary'.
1157
+ *
1158
+ * @example
1159
+ * // Retrieve-Modify-PUT Pattern for updating attribute metadata
1160
+ *
1161
+ * // Step 1: Retrieve current attribute definition
1162
+ * const currentAttr = await dataverseAPI.getEntityRelatedMetadata(
1163
+ * "new_project",
1164
+ * "Attributes(LogicalName='new_description')"
1165
+ * );
1166
+ *
1167
+ * // Step 2: Modify desired properties
1168
+ * currentAttr.DisplayName = dataverseAPI.buildLabel("Updated Description");
1169
+ * currentAttr.MaxLength = 1000; // Increase max length
1170
+ *
1171
+ * // Step 3: PUT entire definition back
1172
+ * await dataverseAPI.updateAttribute(
1173
+ * "new_project",
1174
+ * "new_description",
1175
+ * currentAttr,
1176
+ * { mergeLabels: true }
1177
+ * );
1178
+ *
1179
+ * // Step 4: Publish customizations
1180
+ * await dataverseAPI.publishCustomizations("new_project");
1181
+ */
1182
+ updateAttribute: (entityLogicalName: string, attributeIdentifier: string, attributeDefinition: Record<string, unknown>, options?: MetadataOperationOptions, connectionTarget?: "primary" | "secondary") => Promise<void>;
1183
+
1184
+ /**
1185
+ * Delete an attribute (column) from an entity
1186
+ * WARNING: This is a destructive operation that removes the column and all its data
1187
+ *
1188
+ * @param entityLogicalName - Logical name of the entity
1189
+ * @param attributeIdentifier - Attribute LogicalName or MetadataId
1190
+ * @param connectionTarget - Optional connection target for multi-connection tools ('primary' or 'secondary'). Defaults to 'primary'.
1191
+ *
1192
+ * @example
1193
+ * await dataverseAPI.deleteAttribute("new_project", "new_description");
1194
+ *
1195
+ * @example
1196
+ * // Delete using MetadataId
1197
+ * await dataverseAPI.deleteAttribute("new_project", "00aa00aa-bb11-cc22-dd33-44ee44ee44ee");
1198
+ */
1199
+ deleteAttribute: (entityLogicalName: string, attributeIdentifier: string, connectionTarget?: "primary" | "secondary") => Promise<void>;
1200
+
1201
+ /**
1202
+ * Create a polymorphic lookup attribute (Customer/Regarding field)
1203
+ * Creates a lookup that can reference multiple entity types
1204
+ * NOTE: Metadata changes require explicit publishCustomizations() call to become active
1205
+ *
1206
+ * @param entityLogicalName - Logical name of the entity to add the attribute to
1207
+ * @param attributeDefinition - Lookup attribute metadata with Targets array
1208
+ * @param options - Optional metadata operation options
1209
+ * @returns Object containing the created attribute's MetadataId
1210
+ * @param connectionTarget - Optional connection target ("primary" or "secondary")
1211
+ *
1212
+ * @example
1213
+ * // Create a Customer lookup (Account or Contact)
1214
+ * const result = await dataverseAPI.createPolymorphicLookupAttribute("new_order", {
1215
+ * "@odata.type": "Microsoft.Dynamics.CRM.LookupAttributeMetadata",
1216
+ * "SchemaName": "new_CustomerId",
1217
+ * "LogicalName": "new_customerid",
1218
+ * "DisplayName": buildLabel("Customer"),
1219
+ * "Description": buildLabel("Customer for this order"),
1220
+ * "RequiredLevel": { Value: "None", CanBeChanged: true, ManagedPropertyLogicalName: "canmodifyrequirementlevelsettings" },
1221
+ * "AttributeType": "Lookup",
1222
+ * "AttributeTypeName": { Value: "LookupType" },
1223
+ * "Targets": ["account", "contact"]
1224
+ * });
1225
+ * await dataverseAPI.publishCustomizations();
1226
+ */
1227
+ createPolymorphicLookupAttribute: (
1228
+ entityLogicalName: string,
1229
+ attributeDefinition: Record<string, unknown>,
1230
+ options?: Record<string, unknown>,
1231
+ connectionTarget?: "primary" | "secondary",
1232
+ ) => Promise<{ AttributeId: string }>;
1233
+
1234
+ // ========================================
1235
+ // Relationship Metadata CRUD Operations
1236
+ // ========================================
1237
+
1238
+ /**
1239
+ * Create a new relationship (1:N or N:N)
1240
+ * NOTE: Metadata changes require explicit publishCustomizations() call to become active
1241
+ *
1242
+ * @param relationshipDefinition - Relationship metadata payload (must include @odata.type for OneToManyRelationshipMetadata or ManyToManyRelationshipMetadata)
1243
+ * @param options - Optional metadata operation options
1244
+ * @param connectionTarget - Optional connection target for multi-connection tools ('primary' or 'secondary'). Defaults to 'primary'.
1245
+ * @returns Object containing the created relationship's MetadataId
1246
+ *
1247
+ * @example
1248
+ * // Create 1:N relationship (Project -> Tasks)
1249
+ * const result = await dataverseAPI.createRelationship({
1250
+ * "@odata.type": "Microsoft.Dynamics.CRM.OneToManyRelationshipMetadata",
1251
+ * "SchemaName": "new_project_tasks",
1252
+ * "ReferencedEntity": "new_project",
1253
+ * "ReferencedAttribute": "new_projectid",
1254
+ * "ReferencingEntity": "task",
1255
+ * "CascadeConfiguration": {
1256
+ * "Assign": "NoCascade",
1257
+ * "Delete": "RemoveLink",
1258
+ * "Merge": "NoCascade",
1259
+ * "Reparent": "NoCascade",
1260
+ * "Share": "NoCascade",
1261
+ * "Unshare": "NoCascade"
1262
+ * },
1263
+ * "Lookup": {
1264
+ * "@odata.type": dataverseAPI.getAttributeODataType(DataverseAPI.AttributeMetadataType.Lookup),
1265
+ * "SchemaName": "new_projectid",
1266
+ * "DisplayName": dataverseAPI.buildLabel("Project"),
1267
+ * "RequiredLevel": { "Value": "None" }
1268
+ * }
1269
+ * }, {
1270
+ * solutionUniqueName: "MySolution"
1271
+ * });
1272
+ *
1273
+ * await dataverseAPI.publishCustomizations();
1274
+ *
1275
+ * @example
1276
+ * // Create N:N relationship (Projects <-> Users)
1277
+ * await dataverseAPI.createRelationship({
1278
+ * "@odata.type": "Microsoft.Dynamics.CRM.ManyToManyRelationshipMetadata",
1279
+ * "SchemaName": "new_project_systemuser",
1280
+ * "Entity1LogicalName": "new_project",
1281
+ * "Entity2LogicalName": "systemuser",
1282
+ * "IntersectEntityName": "new_project_systemuser"
1283
+ * });
1284
+ * await dataverseAPI.publishCustomizations();
1285
+ */
1286
+ createRelationship: (relationshipDefinition: Record<string, unknown>, options?: MetadataOperationOptions, connectionTarget?: "primary" | "secondary") => Promise<{ id: string }>;
1287
+
1288
+ /**
1289
+ * Update a relationship definition
1290
+ * NOTE: Uses PUT method which requires the FULL relationship definition (retrieve-modify-PUT pattern)
1291
+ * NOTE: Metadata changes require explicit publishCustomizations() call to become active
1292
+ *
1293
+ * @param relationshipIdentifier - Relationship SchemaName or MetadataId
1294
+ * @param relationshipDefinition - Complete relationship metadata payload
1295
+ * @param options - Optional metadata operation options (mergeLabels defaults to true)
1296
+ * @param connectionTarget - Optional connection target for multi-connection tools ('primary' or 'secondary'). Defaults to 'primary'.
1297
+ */
1298
+ updateRelationship: (relationshipIdentifier: string, relationshipDefinition: Record<string, unknown>, options?: MetadataOperationOptions, connectionTarget?: "primary" | "secondary") => Promise<void>;
1299
+
1300
+ /**
1301
+ * Delete a relationship
1302
+ * WARNING: This removes the relationship and any associated lookup columns
1303
+ *
1304
+ * @param relationshipIdentifier - Relationship SchemaName or MetadataId
1305
+ * @param connectionTarget - Optional connection target for multi-connection tools ('primary' or 'secondary'). Defaults to 'primary'.
1306
+ *
1307
+ * @example
1308
+ * await dataverseAPI.deleteRelationship("new_project_tasks");
1309
+ */
1310
+ deleteRelationship: (relationshipIdentifier: string, connectionTarget?: "primary" | "secondary") => Promise<void>;
1311
+
1312
+ // ========================================
1313
+ // Global Option Set (Choice) CRUD Operations
1314
+ // ========================================
1315
+
1316
+ /**
1317
+ * Create a new global option set (global choice)
1318
+ * NOTE: Metadata changes require explicit publishCustomizations() call to become active
1319
+ *
1320
+ * @param optionSetDefinition - Global option set metadata payload
1321
+ * @param options - Optional metadata operation options
1322
+ * @param connectionTarget - Optional connection target for multi-connection tools ('primary' or 'secondary'). Defaults to 'primary'.
1323
+ * @returns Object containing the created option set's MetadataId
1324
+ *
1325
+ * @example
1326
+ * const result = await dataverseAPI.createGlobalOptionSet({
1327
+ * "@odata.type": "Microsoft.Dynamics.CRM.OptionSetMetadata",
1328
+ * "Name": "new_projectstatus",
1329
+ * "DisplayName": dataverseAPI.buildLabel("Project Status"),
1330
+ * "Description": dataverseAPI.buildLabel("Global choice for project status"),
1331
+ * "OptionSetType": "Picklist",
1332
+ * "IsGlobal": true,
1333
+ * "Options": [
1334
+ * { "Value": 1, "Label": dataverseAPI.buildLabel("Active") },
1335
+ * { "Value": 2, "Label": dataverseAPI.buildLabel("On Hold") },
1336
+ * { "Value": 3, "Label": dataverseAPI.buildLabel("Completed") },
1337
+ * { "Value": 4, "Label": dataverseAPI.buildLabel("Cancelled") }
1338
+ * ]
1339
+ * }, {
1340
+ * solutionUniqueName: "MySolution"
1341
+ * });
1342
+ *
1343
+ * await dataverseAPI.publishCustomizations();
1344
+ */
1345
+ createGlobalOptionSet: (optionSetDefinition: Record<string, unknown>, options?: MetadataOperationOptions, connectionTarget?: "primary" | "secondary") => Promise<{ id: string }>;
1346
+
1347
+ /**
1348
+ * Update a global option set definition
1349
+ * NOTE: Uses PUT method which requires the FULL option set definition (retrieve-modify-PUT pattern)
1350
+ * NOTE: Metadata changes require explicit publishCustomizations() call to become active
1351
+ *
1352
+ * @param optionSetIdentifier - Option set Name or MetadataId
1353
+ * @param optionSetDefinition - Complete option set metadata payload
1354
+ * @param options - Optional metadata operation options (mergeLabels defaults to true)
1355
+ * @param connectionTarget - Optional connection target for multi-connection tools ('primary' or 'secondary'). Defaults to 'primary'.
1356
+ */
1357
+ updateGlobalOptionSet: (optionSetIdentifier: string, optionSetDefinition: Record<string, unknown>, options?: MetadataOperationOptions, connectionTarget?: "primary" | "secondary") => Promise<void>;
1358
+
1359
+ /**
1360
+ * Delete a global option set
1361
+ * WARNING: This will fail if any attributes reference this global option set
1362
+ *
1363
+ * @param optionSetIdentifier - Option set Name or MetadataId
1364
+ * @param connectionTarget - Optional connection target for multi-connection tools ('primary' or 'secondary'). Defaults to 'primary'.
1365
+ *
1366
+ * @example
1367
+ * await dataverseAPI.deleteGlobalOptionSet("new_projectstatus");
1368
+ */
1369
+ deleteGlobalOptionSet: (optionSetIdentifier: string, connectionTarget?: "primary" | "secondary") => Promise<void>;
1370
+
1371
+ // ========================================
1372
+ // Option Value Modification Actions
1373
+ // ========================================
1374
+
1375
+ /**
1376
+ * Insert a new option value into a local or global option set
1377
+ * NOTE: Works for both local option sets (specify EntityLogicalName + AttributeLogicalName)
1378
+ * and global option sets (specify OptionSetName)
1379
+ * NOTE: Metadata changes require explicit publishCustomizations() call to become active
1380
+ *
1381
+ * @param params - Parameters for inserting the option value
1382
+ * @param connectionTarget - Optional connection target for multi-connection tools ('primary' or 'secondary'). Defaults to 'primary'.
1383
+ * @returns Result of the insert operation
1384
+ *
1385
+ * @example
1386
+ * // Insert into local option set on an entity
1387
+ * await dataverseAPI.insertOptionValue({
1388
+ * EntityLogicalName: "new_project",
1389
+ * AttributeLogicalName: "new_priority",
1390
+ * Value: 4,
1391
+ * Label: dataverseAPI.buildLabel("Critical"),
1392
+ * Description: dataverseAPI.buildLabel("Highest priority level")
1393
+ * });
1394
+ * await dataverseAPI.publishCustomizations("new_project");
1395
+ *
1396
+ * @example
1397
+ * // Insert into global option set
1398
+ * await dataverseAPI.insertOptionValue({
1399
+ * OptionSetName: "new_projectstatus",
1400
+ * Value: 5,
1401
+ * Label: dataverseAPI.buildLabel("Archived"),
1402
+ * SolutionUniqueName: "MySolution"
1403
+ * });
1404
+ * await dataverseAPI.publishCustomizations();
1405
+ */
1406
+ insertOptionValue: (params: Record<string, unknown>, connectionTarget?: "primary" | "secondary") => Promise<Record<string, unknown>>;
1407
+
1408
+ /**
1409
+ * Update an existing option value in a local or global option set
1410
+ * NOTE: Metadata changes require explicit publishCustomizations() call to become active
1411
+ *
1412
+ * @param params - Parameters for updating the option value
1413
+ * @param connectionTarget - Optional connection target for multi-connection tools ('primary' or 'secondary'). Defaults to 'primary'.
1414
+ * @returns Result of the update operation
1415
+ *
1416
+ * @example
1417
+ * // Update option label in local option set
1418
+ * await dataverseAPI.updateOptionValue({
1419
+ * EntityLogicalName: "new_project",
1420
+ * AttributeLogicalName: "new_priority",
1421
+ * Value: 4,
1422
+ * Label: dataverseAPI.buildLabel("High Priority"),
1423
+ * MergeLabels: true // Preserve other language translations
1424
+ * });
1425
+ * await dataverseAPI.publishCustomizations("new_project");
1426
+ *
1427
+ * @example
1428
+ * // Update option in global option set
1429
+ * await dataverseAPI.updateOptionValue({
1430
+ * OptionSetName: "new_projectstatus",
1431
+ * Value: 5,
1432
+ * Label: dataverseAPI.buildLabel("Closed"),
1433
+ * MergeLabels: true
1434
+ * });
1435
+ * await dataverseAPI.publishCustomizations();
1436
+ */
1437
+ updateOptionValue: (params: Record<string, unknown>, connectionTarget?: "primary" | "secondary") => Promise<Record<string, unknown>>;
1438
+
1439
+ /**
1440
+ * Delete an option value from a local or global option set
1441
+ * NOTE: Metadata changes require explicit publishCustomizations() call to become active
1442
+ *
1443
+ * @param params - Parameters for deleting the option value
1444
+ * @param connectionTarget - Optional connection target for multi-connection tools ('primary' or 'secondary'). Defaults to 'primary'.
1445
+ * @returns Result of the delete operation
1446
+ *
1447
+ * @example
1448
+ * // Delete option from local option set
1449
+ * await dataverseAPI.deleteOptionValue({
1450
+ * EntityLogicalName: "new_project",
1451
+ * AttributeLogicalName: "new_priority",
1452
+ * Value: 4
1453
+ * });
1454
+ * await dataverseAPI.publishCustomizations("new_project");
1455
+ *
1456
+ * @example
1457
+ * // Delete option from global option set
1458
+ * await dataverseAPI.deleteOptionValue({
1459
+ * OptionSetName: "new_projectstatus",
1460
+ * Value: 5
1461
+ * });
1462
+ * await dataverseAPI.publishCustomizations();
1463
+ */
1464
+ deleteOptionValue: (params: Record<string, unknown>, connectionTarget?: "primary" | "secondary") => Promise<Record<string, unknown>>;
1465
+
1466
+ /**
1467
+ * Reorder options in a local or global option set
1468
+ * NOTE: Metadata changes require explicit publishCustomizations() call to become active
1469
+ *
1470
+ * @param params - Parameters for ordering options
1471
+ * @param connectionTarget - Optional connection target for multi-connection tools ('primary' or 'secondary'). Defaults to 'primary'.
1472
+ * @returns Result of the order operation
1473
+ *
1474
+ * @example
1475
+ * // Reorder options in local option set
1476
+ * await dataverseAPI.orderOption({
1477
+ * EntityLogicalName: "new_project",
1478
+ * AttributeLogicalName: "new_priority",
1479
+ * Values: [3, 1, 2, 4] // Reorder by option values
1480
+ * });
1481
+ * await dataverseAPI.publishCustomizations("new_project");
1482
+ *
1483
+ * @example
1484
+ * // Reorder global option set
1485
+ * await dataverseAPI.orderOption({
1486
+ * OptionSetName: "new_projectstatus",
1487
+ * Values: [1, 2, 3, 5, 4]
1488
+ * });
1489
+ * await dataverseAPI.publishCustomizations();
1490
+ */
1491
+ orderOption: (params: Record<string, unknown>, connectionTarget?: "primary" | "secondary") => Promise<Record<string, unknown>>;
716
1492
  }
717
1493
  }
718
1494
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pptb/types",
3
- "version": "1.0.19-beta.2",
3
+ "version": "1.0.19",
4
4
  "description": "TypeScript type definitions for Power Platform ToolBox API",
5
5
  "main": "index.d.ts",
6
6
  "types": "index.d.ts",