@resconet/qp-bridge 0.0.1-alpha.9 → 1.0.0-alpha.26
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 +638 -6
- package/index.js +1 -1
- package/index.mjs +1496 -1196
- package/lib/qp-bridge-types.d.ts +360 -0
- package/lib/qp-bridge.d.ts +244 -8
- package/package.json +1 -1
package/lib/qp-bridge.d.ts
CHANGED
|
@@ -1,11 +1,76 @@
|
|
|
1
|
-
import { Group, Question, QuestionOptional } from './qp-bridge-types';
|
|
1
|
+
import { Entity, Group, GroupOptional, MediaItem, Question, QuestionOptional } from './qp-bridge-types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a MediaItem from the provided parameters and content.
|
|
4
|
+
*
|
|
5
|
+
* @param name - Name of the media item.
|
|
6
|
+
* @param mimeType - MIME type of the media item.
|
|
7
|
+
* @param content - Content as File, Blob, base64 string, or ArrayBuffer.
|
|
8
|
+
* @param id - Optional id for the media item. If not provided, a UUID will be generated.
|
|
9
|
+
* @returns MediaItem object with blobUrl generated from the content.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createMediaItem(name: string, mimeType: string, content: File): MediaItem;
|
|
12
|
+
/**
|
|
13
|
+
* @param name - Name of the media item.
|
|
14
|
+
* @param mimeType - MIME type of the media item.
|
|
15
|
+
* @param content - Content as Blob.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createMediaItem(name: string, mimeType: string, content: Blob): MediaItem;
|
|
18
|
+
/**
|
|
19
|
+
* @param name - Name of the media item.
|
|
20
|
+
* @param mimeType - MIME type of the media item.
|
|
21
|
+
* @param content - Content as base64 string or binary string.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createMediaItem(name: string, mimeType: string, content: string): MediaItem;
|
|
24
|
+
/**
|
|
25
|
+
* @param name - Name of the media item.
|
|
26
|
+
* @param mimeType - MIME type of the media item.
|
|
27
|
+
* @param content - Content as ArrayBuffer.
|
|
28
|
+
*/
|
|
29
|
+
export declare function createMediaItem(name: string, mimeType: string, content: ArrayBuffer): MediaItem;
|
|
30
|
+
export declare function createMediaItem(name: string, mimeType: string, content: File | Blob | string | ArrayBuffer, id?: string): MediaItem;
|
|
31
|
+
/**
|
|
32
|
+
* Updates a MediaItem with the provided changes.
|
|
33
|
+
*
|
|
34
|
+
* @param mediaItem - The original MediaItem to update.
|
|
35
|
+
* @param updates - Object containing properties to update (name, mimeType, content).
|
|
36
|
+
* @returns Updated MediaItem object.
|
|
37
|
+
*/
|
|
38
|
+
export declare function updateMediaItem(mediaItem: MediaItem, updates: {
|
|
39
|
+
content: File;
|
|
40
|
+
}): MediaItem;
|
|
41
|
+
/**
|
|
42
|
+
* @param mediaItem - The original MediaItem to update.
|
|
43
|
+
* @param updates - Object containing content as Blob.
|
|
44
|
+
*/
|
|
45
|
+
export declare function updateMediaItem(mediaItem: MediaItem, updates: {
|
|
46
|
+
content: Blob;
|
|
47
|
+
}): MediaItem;
|
|
48
|
+
/**
|
|
49
|
+
* @param mediaItem - The original MediaItem to update.
|
|
50
|
+
* @param updates - Object containing content as base64 string or binary string.
|
|
51
|
+
*/
|
|
52
|
+
export declare function updateMediaItem(mediaItem: MediaItem, updates: {
|
|
53
|
+
content: string;
|
|
54
|
+
}): MediaItem;
|
|
55
|
+
/**
|
|
56
|
+
* @param mediaItem - The original MediaItem to update.
|
|
57
|
+
* @param updates - Object containing content as ArrayBuffer.
|
|
58
|
+
*/
|
|
59
|
+
export declare function updateMediaItem(mediaItem: MediaItem, updates: {
|
|
60
|
+
content: ArrayBuffer;
|
|
61
|
+
}): MediaItem;
|
|
62
|
+
export declare function updateMediaItem(mediaItem: MediaItem, updates: Partial<{
|
|
63
|
+
name: string;
|
|
64
|
+
mimeType: string;
|
|
65
|
+
content: File | Blob | string | ArrayBuffer;
|
|
66
|
+
}>): MediaItem;
|
|
2
67
|
/**
|
|
3
68
|
* Sets the answer for a specific question in the questionnaire.
|
|
4
69
|
*
|
|
5
70
|
* @param {string} questionName - Name of the question for which the answer is being set.
|
|
6
71
|
* @param {*} answer - The answer to set for the question. Can be any type.
|
|
7
72
|
* @returns {Promise<void>} A promise that resolves when the answer has been successfully set.
|
|
8
|
-
* @throws {Error} Throws if the
|
|
73
|
+
* @throws {Error} Throws if the operation fails.
|
|
9
74
|
* @example
|
|
10
75
|
* ```typescript
|
|
11
76
|
* await setAnswer('favoriteColor', 'blue');
|
|
@@ -18,7 +83,7 @@ export declare function setAnswer(questionName: string, answer: unknown): Promis
|
|
|
18
83
|
*
|
|
19
84
|
* @param {string} name - The name of the question to retrieve.
|
|
20
85
|
* @returns {Promise<Question>} A promise that resolves to the question object.
|
|
21
|
-
* @throws {Error} Throws if the
|
|
86
|
+
* @throws {Error} Throws if the question is not found or the operation fails.
|
|
22
87
|
* @example
|
|
23
88
|
* ```typescript
|
|
24
89
|
* const question = await getQuestion('favoriteColor');
|
|
@@ -32,7 +97,7 @@ export declare function getQuestion(name: string): Promise<Question>;
|
|
|
32
97
|
* @param {string} name - The name of the question to update. This is a unique identifier and cannot be changed.
|
|
33
98
|
* @param {QuestionOptional} questionData - The updated question data excluding the name property.
|
|
34
99
|
* @returns {Promise<void>} A promise that resolves when the question has been successfully updated.
|
|
35
|
-
* @throws {Error} Throws if the
|
|
100
|
+
* @throws {Error} Throws if the question is not found or the operation fails.
|
|
36
101
|
* @example
|
|
37
102
|
* ```typescript
|
|
38
103
|
* await setQuestion('favoriteColor', { label: 'What is your favorite color?' });
|
|
@@ -44,7 +109,7 @@ export declare function setQuestion(name: string, questionData: QuestionOptional
|
|
|
44
109
|
*
|
|
45
110
|
* @param {string} name - The name of the group to retrieve.
|
|
46
111
|
* @returns {Promise<Group>} A promise that resolves to the group object.
|
|
47
|
-
* @throws {Error} Throws if the
|
|
112
|
+
* @throws {Error} Throws if the group is not found or the operation fails.
|
|
48
113
|
* @example
|
|
49
114
|
* ```typescript
|
|
50
115
|
* const group = await getGroup('personalInfo');
|
|
@@ -54,16 +119,28 @@ export declare function setQuestion(name: string, questionData: QuestionOptional
|
|
|
54
119
|
* ```
|
|
55
120
|
*/
|
|
56
121
|
export declare function getGroup(name: string): Promise<Group>;
|
|
122
|
+
/**
|
|
123
|
+
* Updates a group in the questionnaire.
|
|
124
|
+
*
|
|
125
|
+
* @param {string} name - The name of the group to update. This is a unique identifier and cannot be changed.
|
|
126
|
+
* @param {GroupOptional} groupData - The updated group data excluding the name property.
|
|
127
|
+
* @returns {Promise<void>} A promise that resolves when the group has been successfully updated.
|
|
128
|
+
* @throws {Error} Throws if the group is not found or the operation fails.
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* await setGroup('personalInfo', { label: 'Personal Information', hidden: false, collapsed: true });
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export declare function setGroup(name: string, groupData: GroupOptional): Promise<void>;
|
|
57
135
|
/**
|
|
58
136
|
* Subscribes to changes in answers for questions.
|
|
59
|
-
*
|
|
60
|
-
* and invokes the provided listener whenever an answer changes.
|
|
137
|
+
* Calls the provided listener whenever an answer changes in the questionnaire.
|
|
61
138
|
* @param listener - A function that will be called with the question name and the new answer whenever an answer changes.
|
|
62
139
|
* @return An object with a `cancelSubscription` method to stop listening for changes.
|
|
63
140
|
* @example
|
|
64
141
|
* ```typescript
|
|
65
142
|
* import { onAnswerChange } from 'qp-bridge';
|
|
66
|
-
* const {
|
|
143
|
+
* const { cancelSubscription } = onAnswerChange((question, answer) => {
|
|
67
144
|
* console.log(`Answer for ${question} changed to:`, answer);
|
|
68
145
|
* });
|
|
69
146
|
*
|
|
@@ -74,3 +151,162 @@ export declare function getGroup(name: string): Promise<Group>;
|
|
|
74
151
|
export declare function onAnswerChange(listener: (question: string, answer: unknown) => void): {
|
|
75
152
|
cancelSubscription: () => void;
|
|
76
153
|
};
|
|
154
|
+
/**
|
|
155
|
+
* Wraps an asynchronous action with a busy indicator in the host application.
|
|
156
|
+
* Shows a loading indicator during the execution of the provided action,
|
|
157
|
+
* ensuring the UI reflects the busy state appropriately.
|
|
158
|
+
*
|
|
159
|
+
* @typeParam T - The resolved type of the provided async action.
|
|
160
|
+
* @param action - A function returning a promise whose execution should be wrapped.
|
|
161
|
+
* @returns A promise resolving to the value returned by the action.
|
|
162
|
+
* @throws Propagates any error thrown/rejected by the provided action.
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* const result = await withBusyIndicator(async () => {
|
|
166
|
+
* await setAnswer('favoriteColor', 'blue');
|
|
167
|
+
* return 'done';
|
|
168
|
+
* });
|
|
169
|
+
* console.log(result); // 'done'
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export declare function withBusyIndicator<T>(action: () => Promise<T>): Promise<T>;
|
|
173
|
+
/**
|
|
174
|
+
* Saves the current questionnaire state.
|
|
175
|
+
* Triggers a save operation for the questionnaire data.
|
|
176
|
+
*
|
|
177
|
+
* @returns {Promise<void>} A promise that resolves when the questionnaire has been successfully saved.
|
|
178
|
+
* @throws {Error} Throws if the save operation fails.
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* await saveQuestionnaire();
|
|
182
|
+
* console.log('Questionnaire saved successfully');
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
export declare function saveQuestionnaire(): Promise<void>;
|
|
186
|
+
/**
|
|
187
|
+
* Completes and closes the current questionnaire.
|
|
188
|
+
* Triggers the complete and close operation for the questionnaire.
|
|
189
|
+
*
|
|
190
|
+
* @returns {Promise<void>} A promise that resolves when the questionnaire has been successfully completed and closed.
|
|
191
|
+
* @throws {Error} Throws if the complete and close operation fails.
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* await completeAndCloseQuestionnaire();
|
|
195
|
+
* console.log('Questionnaire completed and closed successfully');
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
export declare function completeAndCloseQuestionnaire(): Promise<void>;
|
|
199
|
+
/**
|
|
200
|
+
* Executes a custom command by its name.
|
|
201
|
+
* Triggers the execution of any user-defined command in the questionnaire.
|
|
202
|
+
*
|
|
203
|
+
* @param {string} commandName - The name of the command to execute.
|
|
204
|
+
* @returns {Promise<void>} A promise that resolves when the command has been successfully executed.
|
|
205
|
+
* @throws {Error} Throws if the command is not found or the execution fails.
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* await executeCustomCommand('MyCustomCommand');
|
|
209
|
+
* console.log('Custom command executed successfully');
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
export declare function executeCustomCommand(commandName: string): Promise<void>;
|
|
213
|
+
type Validator = () => Promise<boolean>;
|
|
214
|
+
/**
|
|
215
|
+
* Registers a validator function to be called when a save event occurs.
|
|
216
|
+
* Useful for validating data before saving the questionnaire.
|
|
217
|
+
*
|
|
218
|
+
* @param validator - A function returning a Promise resolving to a boolean indicating if the save is valid.
|
|
219
|
+
* @returns An object with a `cancelSubscription` method to unregister the validator.
|
|
220
|
+
* @example
|
|
221
|
+
* ```typescript
|
|
222
|
+
* import { onSave } from 'qp-bridge';
|
|
223
|
+
* const { cancelSubscription } = onSave(async () => {
|
|
224
|
+
* // perform validation logic
|
|
225
|
+
* return true;
|
|
226
|
+
* });
|
|
227
|
+
*
|
|
228
|
+
* // To stop listening for save events:
|
|
229
|
+
* cancelSubscription();
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
export declare function onSave(validator: Validator): {
|
|
233
|
+
cancelSubscription: () => void;
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* Fetches entities from the CRM system using the provided FetchXML query.
|
|
237
|
+
*
|
|
238
|
+
* @param {string} fetchXml - The FetchXML query string to execute.
|
|
239
|
+
* @returns {Promise<Entity[]>} A promise that resolves to an array of entities.
|
|
240
|
+
* @throws {Error} Throws if the fetch operation fails or if no entities are found.
|
|
241
|
+
* @example
|
|
242
|
+
* ```typescript
|
|
243
|
+
* const fetchXml = `<fetch top="10">
|
|
244
|
+
* <entity name="contact">
|
|
245
|
+
* <attribute name="firstname" />
|
|
246
|
+
* <attribute name="lastname" />
|
|
247
|
+
* </entity>
|
|
248
|
+
* </fetch>`;
|
|
249
|
+
* const entities = await fetchEntities(fetchXml);
|
|
250
|
+
* console.log(entities); // Array of contact entities
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
export declare function fetchEntities(fetchXml: string): Promise<Entity[]>;
|
|
254
|
+
/**
|
|
255
|
+
* Retrieves a single entity by its name and ID from the CRM system.
|
|
256
|
+
*
|
|
257
|
+
* @param {string} entityName - The name of the entity to retrieve (e.g., "contact", "account").
|
|
258
|
+
* @param {string} id - The unique identifier of the entity.
|
|
259
|
+
* @returns {Promise<Entity>} A promise that resolves to the entity object.
|
|
260
|
+
* @throws {Error} Throws if the entity is not found or the operation fails.
|
|
261
|
+
* @example
|
|
262
|
+
* ```typescript
|
|
263
|
+
* const contact = await getEntityById('contact', '12345678-1234-1234-1234-123456789abc');
|
|
264
|
+
* console.log(contact.attributes.firstname); // Entity firstname attribute
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
export declare function getEntityById(entityName: string, id: string): Promise<Entity>;
|
|
268
|
+
/**
|
|
269
|
+
* Repeats a specific group within a repeatable group by creating a copy of the group at the specified index.
|
|
270
|
+
* The parent group must be a repeatable group and the index must refer to an existing group instance.
|
|
271
|
+
*
|
|
272
|
+
* @param {string} repeatableGroupName - The name of the parent repeatable group.
|
|
273
|
+
* @param {number} groupIndex - The index (0-based) of the group instance to repeat.
|
|
274
|
+
* @returns {Promise<void>} A promise that resolves when the group has been successfully repeated.
|
|
275
|
+
* @throws {Error} Throws if the parent group is not found, is not a repeatable group, the index is invalid, or the operation fails.
|
|
276
|
+
* @example
|
|
277
|
+
* ```typescript
|
|
278
|
+
* await repeatGroup('personalInfoRepeatable', 1);
|
|
279
|
+
* console.log('Group repeated successfully');
|
|
280
|
+
* ```
|
|
281
|
+
*/
|
|
282
|
+
export declare function repeatGroup(repeatableGroupName: string, groupIndex: number): Promise<void>;
|
|
283
|
+
/**
|
|
284
|
+
* Adds a new group instance to a repeatable group.
|
|
285
|
+
* The specified name must refer to a repeatable group.
|
|
286
|
+
*
|
|
287
|
+
* @param {string} repeatableGroupName - The name of the repeatable group to add a new instance to.
|
|
288
|
+
* @returns {Promise<void>} A promise that resolves when the new group has been successfully added.
|
|
289
|
+
* @throws {Error} Throws if the repeatable group is not found or the operation fails.
|
|
290
|
+
* @example
|
|
291
|
+
* ```typescript
|
|
292
|
+
* await addNewGroup('personalInfoRepeatable');
|
|
293
|
+
* console.log('New group added successfully');
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
export declare function addNewGroup(repeatableGroupName: string): Promise<void>;
|
|
297
|
+
/**
|
|
298
|
+
* Deletes a specific group instance from a repeatable group by index.
|
|
299
|
+
* The parent group must be a repeatable group and the index must refer to an existing group instance.
|
|
300
|
+
*
|
|
301
|
+
* @param {string} repeatableGroupName - The name of the parent repeatable group.
|
|
302
|
+
* @param {number} groupIndex - The index (0-based) of the group instance to delete.
|
|
303
|
+
* @returns {Promise<void>} A promise that resolves when the group has been successfully deleted.
|
|
304
|
+
* @throws {Error} Throws if the parent group is not found, is not a repeatable group, the index is invalid, or the operation fails.
|
|
305
|
+
* @example
|
|
306
|
+
* ```typescript
|
|
307
|
+
* await deleteGroup('personalInfoRepeatable', 1);
|
|
308
|
+
* console.log('Group deleted successfully');
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
export declare function deleteGroup(repeatableGroupName: string, groupIndex: number): Promise<void>;
|
|
312
|
+
export {};
|