@resconet/qp-bridge 0.0.1-alpha.9 → 1.0.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/README.md CHANGED
@@ -7,7 +7,7 @@ A JavaScript bridge library for communication between iframes in Questionnaire a
7
7
 
8
8
  ## Description
9
9
 
10
- qp-bridge provides a simple and reliable way to communicate between components in questionnaire environments. It handles messaging, serialization, and error handling for seamless interaction.
10
+ qp-bridge provides a simple and reliable way to communicate between questionnaire and users logic.
11
11
 
12
12
  ## Installation
13
13
 
@@ -41,11 +41,352 @@ await setAnswer("numericQuestion", 42);
41
41
 
42
42
  ## Functions
43
43
 
44
+ - [createMediaItem](#createmediaitem)
45
+ - [createMediaItem](#createmediaitem)
46
+ - [createMediaItem](#createmediaitem)
47
+ - [createMediaItem](#createmediaitem)
48
+ - [createMediaItem](#createmediaitem)
49
+ - [createMediaItem](#createmediaitem)
50
+ - [updateMediaItem](#updatemediaitem)
51
+ - [updateMediaItem](#updatemediaitem)
52
+ - [updateMediaItem](#updatemediaitem)
53
+ - [updateMediaItem](#updatemediaitem)
54
+ - [updateMediaItem](#updatemediaitem)
55
+ - [updateMediaItem](#updatemediaitem)
44
56
  - [setAnswer](#setanswer)
45
57
  - [getQuestion](#getquestion)
46
58
  - [setQuestion](#setquestion)
47
59
  - [getGroup](#getgroup)
60
+ - [setGroup](#setgroup)
48
61
  - [onAnswerChange](#onanswerchange)
62
+ - [withBusyIndicator](#withbusyindicator)
63
+ - [saveQuestionnaire](#savequestionnaire)
64
+ - [completeAndCloseQuestionnaire](#completeandclosequestionnaire)
65
+ - [executeCustomCommand](#executecustomcommand)
66
+ - [onSave](#onsave)
67
+ - [fetchEntities](#fetchentities)
68
+ - [getEntityById](#getentitybyid)
69
+ - [repeatGroup](#repeatgroup)
70
+ - [addNewGroup](#addnewgroup)
71
+ - [deleteGroup](#deletegroup)
72
+
73
+ ### createMediaItem
74
+
75
+ Creates a MediaItem from the provided parameters and content.
76
+
77
+ | Function | Type |
78
+ | ---------- | ---------- |
79
+ | `createMediaItem` | `{ (name: string, mimeType: string, content: File): { id: string; name: string; mimeType: string; blobUrl: string; }; (name: string, mimeType: string, content: Blob): { id: string; name: string; mimeType: string; blobUrl: string; }; (name: string, mimeType: string, content: string): { ...; }; (name: string, mimeType:...` |
80
+
81
+ Parameters:
82
+
83
+ * `name`: - Name of the media item.
84
+ * `mimeType`: - MIME type of the media item.
85
+ * `content`: - Content as File, Blob, base64 string, or ArrayBuffer.
86
+ * `id`: - Optional id for the media item. If not provided, a UUID will be generated.
87
+ * `name`: - Name of the media item.
88
+ * `mimeType`: - MIME type of the media item.
89
+ * `content`: - Content as Blob.
90
+ * `name`: - Name of the media item.
91
+ * `mimeType`: - MIME type of the media item.
92
+ * `content`: - Content as base64 string or binary string.
93
+ * `name`: - Name of the media item.
94
+ * `mimeType`: - MIME type of the media item.
95
+ * `content`: - Content as ArrayBuffer.
96
+
97
+
98
+ Returns:
99
+
100
+ MediaItem object with blobUrl generated from the content.
101
+
102
+ ### createMediaItem
103
+
104
+ Creates a MediaItem from the provided parameters and content.
105
+
106
+ | Function | Type |
107
+ | ---------- | ---------- |
108
+ | `createMediaItem` | `{ (name: string, mimeType: string, content: File): { id: string; name: string; mimeType: string; blobUrl: string; }; (name: string, mimeType: string, content: Blob): { id: string; name: string; mimeType: string; blobUrl: string; }; (name: string, mimeType: string, content: string): { ...; }; (name: string, mimeType:...` |
109
+
110
+ Parameters:
111
+
112
+ * `name`: - Name of the media item.
113
+ * `mimeType`: - MIME type of the media item.
114
+ * `content`: - Content as File, Blob, base64 string, or ArrayBuffer.
115
+ * `id`: - Optional id for the media item. If not provided, a UUID will be generated.
116
+ * `name`: - Name of the media item.
117
+ * `mimeType`: - MIME type of the media item.
118
+ * `content`: - Content as Blob.
119
+ * `name`: - Name of the media item.
120
+ * `mimeType`: - MIME type of the media item.
121
+ * `content`: - Content as base64 string or binary string.
122
+ * `name`: - Name of the media item.
123
+ * `mimeType`: - MIME type of the media item.
124
+ * `content`: - Content as ArrayBuffer.
125
+
126
+
127
+ Returns:
128
+
129
+ MediaItem object with blobUrl generated from the content.
130
+
131
+ ### createMediaItem
132
+
133
+ Creates a MediaItem from the provided parameters and content.
134
+
135
+ | Function | Type |
136
+ | ---------- | ---------- |
137
+ | `createMediaItem` | `{ (name: string, mimeType: string, content: File): { id: string; name: string; mimeType: string; blobUrl: string; }; (name: string, mimeType: string, content: Blob): { id: string; name: string; mimeType: string; blobUrl: string; }; (name: string, mimeType: string, content: string): { ...; }; (name: string, mimeType:...` |
138
+
139
+ Parameters:
140
+
141
+ * `name`: - Name of the media item.
142
+ * `mimeType`: - MIME type of the media item.
143
+ * `content`: - Content as File, Blob, base64 string, or ArrayBuffer.
144
+ * `id`: - Optional id for the media item. If not provided, a UUID will be generated.
145
+ * `name`: - Name of the media item.
146
+ * `mimeType`: - MIME type of the media item.
147
+ * `content`: - Content as Blob.
148
+ * `name`: - Name of the media item.
149
+ * `mimeType`: - MIME type of the media item.
150
+ * `content`: - Content as base64 string or binary string.
151
+ * `name`: - Name of the media item.
152
+ * `mimeType`: - MIME type of the media item.
153
+ * `content`: - Content as ArrayBuffer.
154
+
155
+
156
+ Returns:
157
+
158
+ MediaItem object with blobUrl generated from the content.
159
+
160
+ ### createMediaItem
161
+
162
+ Creates a MediaItem from the provided parameters and content.
163
+
164
+ | Function | Type |
165
+ | ---------- | ---------- |
166
+ | `createMediaItem` | `{ (name: string, mimeType: string, content: File): { id: string; name: string; mimeType: string; blobUrl: string; }; (name: string, mimeType: string, content: Blob): { id: string; name: string; mimeType: string; blobUrl: string; }; (name: string, mimeType: string, content: string): { ...; }; (name: string, mimeType:...` |
167
+
168
+ Parameters:
169
+
170
+ * `name`: - Name of the media item.
171
+ * `mimeType`: - MIME type of the media item.
172
+ * `content`: - Content as File, Blob, base64 string, or ArrayBuffer.
173
+ * `id`: - Optional id for the media item. If not provided, a UUID will be generated.
174
+ * `name`: - Name of the media item.
175
+ * `mimeType`: - MIME type of the media item.
176
+ * `content`: - Content as Blob.
177
+ * `name`: - Name of the media item.
178
+ * `mimeType`: - MIME type of the media item.
179
+ * `content`: - Content as base64 string or binary string.
180
+ * `name`: - Name of the media item.
181
+ * `mimeType`: - MIME type of the media item.
182
+ * `content`: - Content as ArrayBuffer.
183
+
184
+
185
+ Returns:
186
+
187
+ MediaItem object with blobUrl generated from the content.
188
+
189
+ ### createMediaItem
190
+
191
+ Creates a MediaItem from the provided parameters and content.
192
+
193
+ | Function | Type |
194
+ | ---------- | ---------- |
195
+ | `createMediaItem` | `{ (name: string, mimeType: string, content: File): { id: string; name: string; mimeType: string; blobUrl: string; }; (name: string, mimeType: string, content: Blob): { id: string; name: string; mimeType: string; blobUrl: string; }; (name: string, mimeType: string, content: string): { ...; }; (name: string, mimeType:...` |
196
+
197
+ Parameters:
198
+
199
+ * `name`: - Name of the media item.
200
+ * `mimeType`: - MIME type of the media item.
201
+ * `content`: - Content as File, Blob, base64 string, or ArrayBuffer.
202
+ * `id`: - Optional id for the media item. If not provided, a UUID will be generated.
203
+ * `name`: - Name of the media item.
204
+ * `mimeType`: - MIME type of the media item.
205
+ * `content`: - Content as Blob.
206
+ * `name`: - Name of the media item.
207
+ * `mimeType`: - MIME type of the media item.
208
+ * `content`: - Content as base64 string or binary string.
209
+ * `name`: - Name of the media item.
210
+ * `mimeType`: - MIME type of the media item.
211
+ * `content`: - Content as ArrayBuffer.
212
+
213
+
214
+ Returns:
215
+
216
+ MediaItem object with blobUrl generated from the content.
217
+
218
+ ### createMediaItem
219
+
220
+ Creates a MediaItem from the provided parameters and content.
221
+
222
+ | Function | Type |
223
+ | ---------- | ---------- |
224
+ | `createMediaItem` | `{ (name: string, mimeType: string, content: File): { id: string; name: string; mimeType: string; blobUrl: string; }; (name: string, mimeType: string, content: Blob): { id: string; name: string; mimeType: string; blobUrl: string; }; (name: string, mimeType: string, content: string): { ...; }; (name: string, mimeType:...` |
225
+
226
+ Parameters:
227
+
228
+ * `name`: - Name of the media item.
229
+ * `mimeType`: - MIME type of the media item.
230
+ * `content`: - Content as File, Blob, base64 string, or ArrayBuffer.
231
+ * `id`: - Optional id for the media item. If not provided, a UUID will be generated.
232
+ * `name`: - Name of the media item.
233
+ * `mimeType`: - MIME type of the media item.
234
+ * `content`: - Content as Blob.
235
+ * `name`: - Name of the media item.
236
+ * `mimeType`: - MIME type of the media item.
237
+ * `content`: - Content as base64 string or binary string.
238
+ * `name`: - Name of the media item.
239
+ * `mimeType`: - MIME type of the media item.
240
+ * `content`: - Content as ArrayBuffer.
241
+
242
+
243
+ Returns:
244
+
245
+ MediaItem object with blobUrl generated from the content.
246
+
247
+ ### updateMediaItem
248
+
249
+ Updates a MediaItem with the provided changes.
250
+
251
+ | Function | Type |
252
+ | ---------- | ---------- |
253
+ | `updateMediaItem` | `{ (mediaItem: { id: string; name: string; mimeType: string; blobUrl: string; }, updates: { content: File; }): { id: string; name: string; mimeType: string; blobUrl: string; }; (mediaItem: { id: string; name: string; mimeType: string; blobUrl: string; }, updates: { ...; }): { ...; }; (mediaItem: { ...; }, updates: { ...` |
254
+
255
+ Parameters:
256
+
257
+ * `mediaItem`: - The original MediaItem to update.
258
+ * `updates`: - Object containing properties to update (name, mimeType, content).
259
+ * `mediaItem`: - The original MediaItem to update.
260
+ * `updates`: - Object containing content as Blob.
261
+ * `mediaItem`: - The original MediaItem to update.
262
+ * `updates`: - Object containing content as base64 string or binary string.
263
+ * `mediaItem`: - The original MediaItem to update.
264
+ * `updates`: - Object containing content as ArrayBuffer.
265
+
266
+
267
+ Returns:
268
+
269
+ Updated MediaItem object.
270
+
271
+ ### updateMediaItem
272
+
273
+ Updates a MediaItem with the provided changes.
274
+
275
+ | Function | Type |
276
+ | ---------- | ---------- |
277
+ | `updateMediaItem` | `{ (mediaItem: { id: string; name: string; mimeType: string; blobUrl: string; }, updates: { content: File; }): { id: string; name: string; mimeType: string; blobUrl: string; }; (mediaItem: { id: string; name: string; mimeType: string; blobUrl: string; }, updates: { ...; }): { ...; }; (mediaItem: { ...; }, updates: { ...` |
278
+
279
+ Parameters:
280
+
281
+ * `mediaItem`: - The original MediaItem to update.
282
+ * `updates`: - Object containing properties to update (name, mimeType, content).
283
+ * `mediaItem`: - The original MediaItem to update.
284
+ * `updates`: - Object containing content as Blob.
285
+ * `mediaItem`: - The original MediaItem to update.
286
+ * `updates`: - Object containing content as base64 string or binary string.
287
+ * `mediaItem`: - The original MediaItem to update.
288
+ * `updates`: - Object containing content as ArrayBuffer.
289
+
290
+
291
+ Returns:
292
+
293
+ Updated MediaItem object.
294
+
295
+ ### updateMediaItem
296
+
297
+ Updates a MediaItem with the provided changes.
298
+
299
+ | Function | Type |
300
+ | ---------- | ---------- |
301
+ | `updateMediaItem` | `{ (mediaItem: { id: string; name: string; mimeType: string; blobUrl: string; }, updates: { content: File; }): { id: string; name: string; mimeType: string; blobUrl: string; }; (mediaItem: { id: string; name: string; mimeType: string; blobUrl: string; }, updates: { ...; }): { ...; }; (mediaItem: { ...; }, updates: { ...` |
302
+
303
+ Parameters:
304
+
305
+ * `mediaItem`: - The original MediaItem to update.
306
+ * `updates`: - Object containing properties to update (name, mimeType, content).
307
+ * `mediaItem`: - The original MediaItem to update.
308
+ * `updates`: - Object containing content as Blob.
309
+ * `mediaItem`: - The original MediaItem to update.
310
+ * `updates`: - Object containing content as base64 string or binary string.
311
+ * `mediaItem`: - The original MediaItem to update.
312
+ * `updates`: - Object containing content as ArrayBuffer.
313
+
314
+
315
+ Returns:
316
+
317
+ Updated MediaItem object.
318
+
319
+ ### updateMediaItem
320
+
321
+ Updates a MediaItem with the provided changes.
322
+
323
+ | Function | Type |
324
+ | ---------- | ---------- |
325
+ | `updateMediaItem` | `{ (mediaItem: { id: string; name: string; mimeType: string; blobUrl: string; }, updates: { content: File; }): { id: string; name: string; mimeType: string; blobUrl: string; }; (mediaItem: { id: string; name: string; mimeType: string; blobUrl: string; }, updates: { ...; }): { ...; }; (mediaItem: { ...; }, updates: { ...` |
326
+
327
+ Parameters:
328
+
329
+ * `mediaItem`: - The original MediaItem to update.
330
+ * `updates`: - Object containing properties to update (name, mimeType, content).
331
+ * `mediaItem`: - The original MediaItem to update.
332
+ * `updates`: - Object containing content as Blob.
333
+ * `mediaItem`: - The original MediaItem to update.
334
+ * `updates`: - Object containing content as base64 string or binary string.
335
+ * `mediaItem`: - The original MediaItem to update.
336
+ * `updates`: - Object containing content as ArrayBuffer.
337
+
338
+
339
+ Returns:
340
+
341
+ Updated MediaItem object.
342
+
343
+ ### updateMediaItem
344
+
345
+ Updates a MediaItem with the provided changes.
346
+
347
+ | Function | Type |
348
+ | ---------- | ---------- |
349
+ | `updateMediaItem` | `{ (mediaItem: { id: string; name: string; mimeType: string; blobUrl: string; }, updates: { content: File; }): { id: string; name: string; mimeType: string; blobUrl: string; }; (mediaItem: { id: string; name: string; mimeType: string; blobUrl: string; }, updates: { ...; }): { ...; }; (mediaItem: { ...; }, updates: { ...` |
350
+
351
+ Parameters:
352
+
353
+ * `mediaItem`: - The original MediaItem to update.
354
+ * `updates`: - Object containing properties to update (name, mimeType, content).
355
+ * `mediaItem`: - The original MediaItem to update.
356
+ * `updates`: - Object containing content as Blob.
357
+ * `mediaItem`: - The original MediaItem to update.
358
+ * `updates`: - Object containing content as base64 string or binary string.
359
+ * `mediaItem`: - The original MediaItem to update.
360
+ * `updates`: - Object containing content as ArrayBuffer.
361
+
362
+
363
+ Returns:
364
+
365
+ Updated MediaItem object.
366
+
367
+ ### updateMediaItem
368
+
369
+ Updates a MediaItem with the provided changes.
370
+
371
+ | Function | Type |
372
+ | ---------- | ---------- |
373
+ | `updateMediaItem` | `{ (mediaItem: { id: string; name: string; mimeType: string; blobUrl: string; }, updates: { content: File; }): { id: string; name: string; mimeType: string; blobUrl: string; }; (mediaItem: { id: string; name: string; mimeType: string; blobUrl: string; }, updates: { ...; }): { ...; }; (mediaItem: { ...; }, updates: { ...` |
374
+
375
+ Parameters:
376
+
377
+ * `mediaItem`: - The original MediaItem to update.
378
+ * `updates`: - Object containing properties to update (name, mimeType, content).
379
+ * `mediaItem`: - The original MediaItem to update.
380
+ * `updates`: - Object containing content as Blob.
381
+ * `mediaItem`: - The original MediaItem to update.
382
+ * `updates`: - Object containing content as base64 string or binary string.
383
+ * `mediaItem`: - The original MediaItem to update.
384
+ * `updates`: - Object containing content as ArrayBuffer.
385
+
386
+
387
+ Returns:
388
+
389
+ Updated MediaItem object.
49
390
 
50
391
  ### setAnswer
51
392
 
@@ -78,7 +419,7 @@ Retrieves a question by its name from the questionnaire.
78
419
 
79
420
  | Function | Type |
80
421
  | ---------- | ---------- |
81
- | `getQuestion` | `(name: string) => Promise<{ label: string; description: string; disabled: boolean; required: boolean; hidden: boolean; semanticColor?: string or undefined; }>` |
422
+ | `getQuestion` | `(name: string) => Promise<{ label: string; description: string; disabled: boolean; required: boolean; hidden: boolean; semanticColor?: string or undefined; errorMessage?: string or undefined; answer?: unknown; }>` |
82
423
 
83
424
  Parameters:
84
425
 
@@ -103,7 +444,7 @@ Updates a question in the questionnaire.
103
444
 
104
445
  | Function | Type |
105
446
  | ---------- | ---------- |
106
- | `setQuestion` | `(name: string, questionData: { semanticColor?: string or undefined; label?: string or undefined; description?: string or undefined; disabled?: boolean or undefined; required?: boolean or undefined; hidden?: boolean or undefined; }) => Promise<...>` |
447
+ | `setQuestion` | `(name: string, questionData: { semanticColor?: string or undefined; label?: string or undefined; description?: string or undefined; disabled?: boolean or undefined; required?: boolean or undefined; hidden?: boolean or undefined; errorMessage?: string or undefined; answer?: unknown; }) => Promise<...>` |
107
448
 
108
449
  Parameters:
109
450
 
@@ -149,11 +490,35 @@ console.log(group.collapsed); // Outputs whether the group is collapsed
149
490
  ```
150
491
 
151
492
 
493
+ ### setGroup
494
+
495
+ Updates a group in the questionnaire.
496
+
497
+ | Function | Type |
498
+ | ---------- | ---------- |
499
+ | `setGroup` | `(name: string, groupData: { label?: string or undefined; hidden?: boolean or undefined; collapsed?: boolean or undefined; }) => Promise<void>` |
500
+
501
+ Parameters:
502
+
503
+ * `name`: - The name of the group to update. This is a unique identifier and cannot be changed.
504
+ * `groupData`: - The updated group data excluding the name property.
505
+
506
+
507
+ Returns:
508
+
509
+ A promise that resolves when the group has been successfully updated.
510
+
511
+ Examples:
512
+
513
+ ```typescript
514
+ await setGroup('personalInfo', { label: 'Personal Information', hidden: false, collapsed: true });
515
+ ```
516
+
517
+
152
518
  ### onAnswerChange
153
519
 
154
520
  Subscribes to changes in answers for questions.
155
- This function listens for messages from the parent window
156
- and invokes the provided listener whenever an answer changes.
521
+ Calls the provided listener whenever an answer changes in the questionnaire.
157
522
 
158
523
  | Function | Type |
159
524
  | ---------- | ---------- |
@@ -168,7 +533,7 @@ Examples:
168
533
 
169
534
  ```typescript
170
535
  import { onAnswerChange } from 'qp-bridge';
171
- const { cancelSubsctiprion } = onAnswerChange((question, answer) => {
536
+ const { cancelSubscription } = onAnswerChange((question, answer) => {
172
537
  console.log(`Answer for ${question} changed to:`, answer);
173
538
  });
174
539
 
@@ -177,6 +542,273 @@ cancelSubscription();
177
542
  ```
178
543
 
179
544
 
545
+ ### withBusyIndicator
546
+
547
+ Wraps an asynchronous action with a busy indicator in the host application.
548
+ Shows a loading indicator during the execution of the provided action,
549
+ ensuring the UI reflects the busy state appropriately.
550
+
551
+ | Function | Type |
552
+ | ---------- | ---------- |
553
+ | `withBusyIndicator` | `<T>(action: () => Promise<T>) => Promise<T>` |
554
+
555
+ Parameters:
556
+
557
+ * `action`: - A function returning a promise whose execution should be wrapped.
558
+
559
+
560
+ Returns:
561
+
562
+ A promise resolving to the value returned by the action.
563
+
564
+ Examples:
565
+
566
+ ```typescript
567
+ const result = await withBusyIndicator(async () => {
568
+ await setAnswer('favoriteColor', 'blue');
569
+ return 'done';
570
+ });
571
+ console.log(result); // 'done'
572
+ ```
573
+
574
+
575
+ ### saveQuestionnaire
576
+
577
+ Saves the current questionnaire state.
578
+ Triggers a save operation for the questionnaire data.
579
+
580
+ | Function | Type |
581
+ | ---------- | ---------- |
582
+ | `saveQuestionnaire` | `() => Promise<void>` |
583
+
584
+ Returns:
585
+
586
+ A promise that resolves when the questionnaire has been successfully saved.
587
+
588
+ Examples:
589
+
590
+ ```typescript
591
+ await saveQuestionnaire();
592
+ console.log('Questionnaire saved successfully');
593
+ ```
594
+
595
+
596
+ ### completeAndCloseQuestionnaire
597
+
598
+ Completes and closes the current questionnaire.
599
+ Triggers the complete and close operation for the questionnaire.
600
+
601
+ | Function | Type |
602
+ | ---------- | ---------- |
603
+ | `completeAndCloseQuestionnaire` | `() => Promise<void>` |
604
+
605
+ Returns:
606
+
607
+ A promise that resolves when the questionnaire has been successfully completed and closed.
608
+
609
+ Examples:
610
+
611
+ ```typescript
612
+ await completeAndCloseQuestionnaire();
613
+ console.log('Questionnaire completed and closed successfully');
614
+ ```
615
+
616
+
617
+ ### executeCustomCommand
618
+
619
+ Executes a custom command by its name.
620
+ Triggers the execution of any user-defined command in the questionnaire.
621
+
622
+ | Function | Type |
623
+ | ---------- | ---------- |
624
+ | `executeCustomCommand` | `(commandName: string) => Promise<void>` |
625
+
626
+ Parameters:
627
+
628
+ * `commandName`: - The name of the command to execute.
629
+
630
+
631
+ Returns:
632
+
633
+ A promise that resolves when the command has been successfully executed.
634
+
635
+ Examples:
636
+
637
+ ```typescript
638
+ await executeCustomCommand('MyCustomCommand');
639
+ console.log('Custom command executed successfully');
640
+ ```
641
+
642
+
643
+ ### onSave
644
+
645
+ Registers a validator function to be called when a save event occurs.
646
+ Useful for validating data before saving the questionnaire.
647
+
648
+ | Function | Type |
649
+ | ---------- | ---------- |
650
+ | `onSave` | `(validator: Validator) => { cancelSubscription: () => void; }` |
651
+
652
+ Parameters:
653
+
654
+ * `validator`: - A function returning a Promise resolving to a boolean indicating if the save is valid.
655
+
656
+
657
+ Returns:
658
+
659
+ An object with a `cancelSubscription` method to unregister the validator.
660
+
661
+ Examples:
662
+
663
+ ```typescript
664
+ import { onSave } from 'qp-bridge';
665
+ const { cancelSubscription } = onSave(async () => {
666
+ // perform validation logic
667
+ return true;
668
+ });
669
+
670
+ // To stop listening for save events:
671
+ cancelSubscription();
672
+ ```
673
+
674
+
675
+ ### fetchEntities
676
+
677
+ Fetches entities from the CRM system using the provided FetchXML query.
678
+
679
+ | Function | Type |
680
+ | ---------- | ---------- |
681
+ | `fetchEntities` | `(fetchXml: string) => Promise<Record<string, unknown>[]>` |
682
+
683
+ Parameters:
684
+
685
+ * `fetchXml`: - The FetchXML query string to execute.
686
+
687
+
688
+ Returns:
689
+
690
+ A promise that resolves to an array of entities.
691
+
692
+ Examples:
693
+
694
+ ```typescript
695
+ const fetchXml = `<fetch top="10">
696
+ <entity name="contact">
697
+ <attribute name="firstname" />
698
+ <attribute name="lastname" />
699
+ </entity>
700
+ </fetch>`;
701
+ const entities = await fetchEntities(fetchXml);
702
+ console.log(entities); // Array of contact entities
703
+ ```
704
+
705
+
706
+ ### getEntityById
707
+
708
+ Retrieves a single entity by its name and ID from the CRM system.
709
+
710
+ | Function | Type |
711
+ | ---------- | ---------- |
712
+ | `getEntityById` | `(entityName: string, id: string) => Promise<Record<string, unknown>>` |
713
+
714
+ Parameters:
715
+
716
+ * `entityName`: - The name of the entity to retrieve (e.g., "contact", "account").
717
+ * `id`: - The unique identifier of the entity.
718
+
719
+
720
+ Returns:
721
+
722
+ A promise that resolves to the entity object.
723
+
724
+ Examples:
725
+
726
+ ```typescript
727
+ const contact = await getEntityById('contact', '12345678-1234-1234-1234-123456789abc');
728
+ console.log(contact.attributes.firstname); // Entity firstname attribute
729
+ ```
730
+
731
+
732
+ ### repeatGroup
733
+
734
+ Repeats a specific group within a repeatable group by creating a copy of the group at the specified index.
735
+ The parent group must be a repeatable group and the index must refer to an existing group instance.
736
+
737
+ | Function | Type |
738
+ | ---------- | ---------- |
739
+ | `repeatGroup` | `(repeatableGroupName: string, groupIndex: number) => Promise<void>` |
740
+
741
+ Parameters:
742
+
743
+ * `repeatableGroupName`: - The name of the parent repeatable group.
744
+ * `groupIndex`: - The index (0-based) of the group instance to repeat.
745
+
746
+
747
+ Returns:
748
+
749
+ A promise that resolves when the group has been successfully repeated.
750
+
751
+ Examples:
752
+
753
+ ```typescript
754
+ await repeatGroup('personalInfoRepeatable', 1);
755
+ console.log('Group repeated successfully');
756
+ ```
757
+
758
+
759
+ ### addNewGroup
760
+
761
+ Adds a new group instance to a repeatable group.
762
+ The specified name must refer to a repeatable group.
763
+
764
+ | Function | Type |
765
+ | ---------- | ---------- |
766
+ | `addNewGroup` | `(repeatableGroupName: string) => Promise<void>` |
767
+
768
+ Parameters:
769
+
770
+ * `repeatableGroupName`: - The name of the repeatable group to add a new instance to.
771
+
772
+
773
+ Returns:
774
+
775
+ A promise that resolves when the new group has been successfully added.
776
+
777
+ Examples:
778
+
779
+ ```typescript
780
+ await addNewGroup('personalInfoRepeatable');
781
+ console.log('New group added successfully');
782
+ ```
783
+
784
+
785
+ ### deleteGroup
786
+
787
+ Deletes a specific group instance from a repeatable group by index.
788
+ The parent group must be a repeatable group and the index must refer to an existing group instance.
789
+
790
+ | Function | Type |
791
+ | ---------- | ---------- |
792
+ | `deleteGroup` | `(repeatableGroupName: string, groupIndex: number) => Promise<void>` |
793
+
794
+ Parameters:
795
+
796
+ * `repeatableGroupName`: - The name of the parent repeatable group.
797
+ * `groupIndex`: - The index (0-based) of the group instance to delete.
798
+
799
+
800
+ Returns:
801
+
802
+ A promise that resolves when the group has been successfully deleted.
803
+
804
+ Examples:
805
+
806
+ ```typescript
807
+ await deleteGroup('personalInfoRepeatable', 1);
808
+ console.log('Group deleted successfully');
809
+ ```
810
+
811
+
180
812
 
181
813
 
182
814
  <!-- TSDOC_END -->