@halix/action-sdk 1.0.19 → 1.0.21
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/lib/cjs/content.js +257 -0
- package/lib/cjs/data-crud.js +297 -0
- package/lib/cjs/index.js +53 -678
- package/lib/cjs/lists.js +175 -0
- package/lib/cjs/sdk-general.js +92 -0
- package/lib/cjs/types/content.d.ts +119 -0
- package/lib/cjs/types/content.d.ts.map +1 -0
- package/lib/cjs/types/data-crud.d.ts +156 -0
- package/lib/cjs/types/data-crud.d.ts.map +1 -0
- package/lib/cjs/types/index.d.ts +8 -578
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/cjs/types/lists.d.ts +212 -0
- package/lib/cjs/types/lists.d.ts.map +1 -0
- package/lib/cjs/types/sdk-general.d.ts +263 -0
- package/lib/cjs/types/sdk-general.d.ts.map +1 -0
- package/lib/cjs/types/utilities.d.ts +73 -0
- package/lib/cjs/types/utilities.d.ts.map +1 -0
- package/lib/cjs/utilities.js +131 -0
- package/lib/esm/content.js +228 -0
- package/lib/esm/content.js.map +1 -0
- package/lib/esm/data-crud.js +264 -0
- package/lib/esm/data-crud.js.map +1 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/index.mjs +26 -673
- package/lib/esm/lists.js +157 -0
- package/lib/esm/lists.js.map +1 -0
- package/lib/esm/sdk-general.js +138 -0
- package/lib/esm/sdk-general.js.map +1 -0
- package/lib/esm/types/content.d.ts +118 -0
- package/lib/esm/types/data-crud.d.ts +155 -0
- package/lib/esm/types/index.d.ts +8 -578
- package/lib/esm/types/lists.d.ts +211 -0
- package/lib/esm/types/sdk-general.d.ts +262 -0
- package/lib/esm/types/utilities.d.ts +72 -0
- package/lib/esm/utilities.js +126 -0
- package/lib/esm/utilities.js.map +1 -0
- package/package.json +12 -1
package/lib/esm/index.mjs
CHANGED
|
@@ -9,689 +9,42 @@
|
|
|
9
9
|
/**
|
|
10
10
|
* @module @halix/action-sdk
|
|
11
11
|
* @description Halix Platform action SDK for developing NodeJS Lambda-based actions on the Halix
|
|
12
|
-
* platform.
|
|
13
|
-
* requests to the Halix data service, and returning structured action responses back to the Halix
|
|
14
|
-
* platform.
|
|
12
|
+
* platform. This is the main entry point that provides a unified interface for all SDK functionality.
|
|
15
13
|
*/
|
|
16
|
-
import axios from 'axios';
|
|
17
|
-
import { from, of, lastValueFrom } from 'rxjs';
|
|
18
14
|
// ================================================================================
|
|
19
|
-
//
|
|
15
|
+
// SDK GENERAL - GLOBALS, INITIALIZATION, COMMON TYPES
|
|
20
16
|
// ================================================================================
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
* sandboxKey contains the sandbox key identifier; identifies the sandbox that the action handler is
|
|
29
|
-
* running in. The sandbox identifies the current solution. This value is set upon calling the
|
|
30
|
-
* initialize function with incoming event data.
|
|
31
|
-
*/
|
|
32
|
-
export let sandboxKey;
|
|
33
|
-
/**
|
|
34
|
-
* serviceAddress contains the URL of the Halix service that the action handler can use to make API
|
|
35
|
-
* requests to. This value is set upon calling the initialize function with incoming event data.
|
|
36
|
-
*/
|
|
37
|
-
export let serviceAddress;
|
|
38
|
-
/**
|
|
39
|
-
* actionSubject contains the identifier of the subject of the action. The subject is the object
|
|
40
|
-
* that the action is being performed on. The action subject's contents will differ depending on the
|
|
41
|
-
* context in which the action is being executed. This value is set upon calling the initialize
|
|
42
|
-
* function with incoming event data.
|
|
43
|
-
* - for formTemplateActions, the action subject is the data being edited on the form
|
|
44
|
-
* - for pageTemplateActions, the action subject is record containing the context variables and
|
|
45
|
-
* their corresponding values on the page
|
|
46
|
-
* - for objectSaveActions, the action subject is the object being saved
|
|
47
|
-
* - for calculatedFieldActions, the action subject is the object containing the calculated field
|
|
48
|
-
* - for singleValueActions, the action subject may differ depending on the caller
|
|
49
|
-
*/
|
|
50
|
-
export let actionSubject;
|
|
51
|
-
/**
|
|
52
|
-
* userContext contains the user context information for the user that is executing the action.
|
|
53
|
-
* This value is set upon calling the initialize function with incoming event data.
|
|
54
|
-
*/
|
|
55
|
-
export let userContext;
|
|
56
|
-
/**
|
|
57
|
-
* params contains the parameters passed to the action. If an input dialog is used, params will
|
|
58
|
-
* contain the values entered in the dialog. This value is set upon calling the initialize
|
|
59
|
-
* function with incoming event data.
|
|
60
|
-
*/
|
|
61
|
-
export let params;
|
|
62
|
-
/**
|
|
63
|
-
* useBody is a flag indicating how responses should be formatted. If true, the response will be
|
|
64
|
-
* returned as an object with the HTTP response code and ActionResponse in the body field. If false,
|
|
65
|
-
* the ActionResponse will be returned directly. Typically, this does not need to be set by the
|
|
66
|
-
* action handler and should remain false.
|
|
67
|
-
*/
|
|
68
|
-
export let useBody;
|
|
69
|
-
/**
|
|
70
|
-
* initialize initializes the SDK with event data. This should be called at the beginning of the
|
|
71
|
-
* action handler to set up the SDK with incoming information, including context information, input
|
|
72
|
-
* parameters, and authentication information needed to make API requests to the Halix service.
|
|
73
|
-
*
|
|
74
|
-
* @param event - The event object containing authentication and context information
|
|
75
|
-
*/
|
|
76
|
-
export function initialize(event) {
|
|
77
|
-
let body = event;
|
|
78
|
-
if (event.body) {
|
|
79
|
-
body = event.body;
|
|
80
|
-
useBody = true;
|
|
81
|
-
}
|
|
82
|
-
if (body) {
|
|
83
|
-
({ sandboxKey, serviceAddress, actionSubject, userContext, params } = body);
|
|
84
|
-
if (body.authToken) {
|
|
85
|
-
getAuthToken = () => of(body.authToken);
|
|
86
|
-
}
|
|
87
|
-
else if (body.authTokenRetriever) {
|
|
88
|
-
getAuthToken = body.authTokenRetriever;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
// ================================================================================
|
|
93
|
-
// RESPONSE HELPER FUNCTIONS
|
|
17
|
+
export {
|
|
18
|
+
// Globals
|
|
19
|
+
getAuthToken, sandboxKey, serviceAddress, actionSubject, userContext, params, useBody,
|
|
20
|
+
// Initialization
|
|
21
|
+
initialize,
|
|
22
|
+
// Response Helpers
|
|
23
|
+
prepareSuccessResponse, prepareErrorResponse } from './sdk-general';
|
|
94
24
|
// ================================================================================
|
|
95
|
-
|
|
96
|
-
* prepareSuccessResponse prepares a success response in the appropriate format. The action handler
|
|
97
|
-
* should return an ActionResponse response when the action is successful. If useBody is true, the
|
|
98
|
-
* response will be returned as an object with the HTTP response code and the ActionResponse in the
|
|
99
|
-
* body field. If useBody is false, the ActionResponse will be returned directly.
|
|
100
|
-
*
|
|
101
|
-
* @param successResponse - The value to return
|
|
102
|
-
*
|
|
103
|
-
* @returns Formatted success response; an ActionResponse unless useBody is true
|
|
104
|
-
*/
|
|
105
|
-
export function prepareSuccessResponse(successResponse) {
|
|
106
|
-
if (useBody) {
|
|
107
|
-
return {
|
|
108
|
-
statusCode: 200,
|
|
109
|
-
body: JSON.stringify(successResponse)
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
return successResponse;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* prepareErrorResponse prepares an error response in the appropriate format. The action handler
|
|
116
|
-
* should return an ErrorResponse response when the action is not successful. If useBody is true,
|
|
117
|
-
* the response will be returned as an object with the HTTP response code and the ErrorResponse in
|
|
118
|
-
* the body field. If useBody is false, the ErrorResponse will be returned directly.
|
|
119
|
-
*
|
|
120
|
-
* @param errorMessage - The error message
|
|
121
|
-
*
|
|
122
|
-
* @returns Formatted error response; an ErrorResponse unless useBody is true
|
|
123
|
-
*/
|
|
124
|
-
export function prepareErrorResponse(errorMessage) {
|
|
125
|
-
if (useBody) {
|
|
126
|
-
return {
|
|
127
|
-
statusCode: 400,
|
|
128
|
-
body: JSON.stringify({ errorMessage })
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
return { errorMessage, responseType: "error" };
|
|
132
|
-
}
|
|
133
|
-
// ================================================================================
|
|
134
|
-
// DATA RETRIEVAL FUNCTIONS
|
|
25
|
+
// DATA CRUD FUNCTIONS
|
|
135
26
|
// ================================================================================
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
* @returns Promise resolving to the object data
|
|
144
|
-
*/
|
|
145
|
-
export async function getObject(dataElementId, key, fetchedRelationships) {
|
|
146
|
-
let params;
|
|
147
|
-
if (fetchedRelationships) {
|
|
148
|
-
let p = {};
|
|
149
|
-
if (fetchedRelationships) {
|
|
150
|
-
p.fetchedRelationships = fetchedRelationships.join(",");
|
|
151
|
-
}
|
|
152
|
-
params = new URLSearchParams(p);
|
|
153
|
-
}
|
|
154
|
-
let url = `${serviceAddress}/schema/sandboxes/${sandboxKey}/${dataElementId}/${key}`;
|
|
155
|
-
let authToken = await lastValueFrom(getAuthToken());
|
|
156
|
-
console.log("Sending GET request to " + url + " with token " + authToken);
|
|
157
|
-
let response = await axios.get(url, {
|
|
158
|
-
headers: { "Authorization": `Bearer ${authToken}` },
|
|
159
|
-
params: params,
|
|
160
|
-
});
|
|
161
|
-
return response.data;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* getObjectAsObservable retrieves a single object from the database by its data element ID and key.
|
|
165
|
-
*
|
|
166
|
-
* @param dataElementId - The ID of the data element
|
|
167
|
-
* @param key - The key of the object
|
|
168
|
-
* @param fetchedRelationships - Optional array of relationships to fetch; if provided, the returned
|
|
169
|
-
* object will include the specified related objects as nested objects
|
|
170
|
-
*
|
|
171
|
-
* @returns Observable resolving to the object data
|
|
172
|
-
*/
|
|
173
|
-
export function getObjectAsObservable(dataElementId, key, fetchedRelationships) {
|
|
174
|
-
return from(getObject(dataElementId, key, fetchedRelationships));
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* getRelatedObjects retrieves an array of objects from the the database. The objects returned are
|
|
178
|
-
* related to a parent through a defined relationship in the schema. In a typical setup, action's
|
|
179
|
-
* auth token must have scope access to the parent object in order to access all of its related
|
|
180
|
-
* objects.
|
|
181
|
-
*
|
|
182
|
-
* It is common to use getRelatedObjects to retrieve all objects belonging to the current user proxy
|
|
183
|
-
* or organization proxy. For example, in a user context where the current user proxy element is
|
|
184
|
-
* "customer," an action might want to retrieve all "purchase" objects related to the current
|
|
185
|
-
* customer. Similarly, in an organization context where the current organization proxy is
|
|
186
|
-
* "business," an action might want to retrieve all "employee" objects related to the current
|
|
187
|
-
* business.
|
|
188
|
-
*
|
|
189
|
-
* @param parentElementId - The ID of the parent element
|
|
190
|
-
* @param parentKey - The key of the parent object
|
|
191
|
-
* @param elementId - The ID of the element
|
|
192
|
-
* @param filter - Optional filter criteria for the query; if not provided, all related objects will
|
|
193
|
-
* be returned
|
|
194
|
-
* @param fetchedRelationships - Optional array of relationships to fetch; if provided, the returned
|
|
195
|
-
* objects will include the specified related objects as nested objects
|
|
196
|
-
*
|
|
197
|
-
* @returns Promise resolving to an array of objects
|
|
198
|
-
*/
|
|
199
|
-
export async function getRelatedObjects(parentElementId, parentKey, elementId, filter, fetchedRelationships) {
|
|
200
|
-
let params;
|
|
201
|
-
if (filter || fetchedRelationships) {
|
|
202
|
-
let p = {};
|
|
203
|
-
if (filter) {
|
|
204
|
-
p.filter = filter;
|
|
205
|
-
}
|
|
206
|
-
if (fetchedRelationships) {
|
|
207
|
-
p.fetchedRelationships = fetchedRelationships.join(",");
|
|
208
|
-
}
|
|
209
|
-
params = new URLSearchParams(p);
|
|
210
|
-
}
|
|
211
|
-
let url = `${serviceAddress}/schema/sandboxes/${sandboxKey}/${parentElementId}/${parentKey}/${elementId}`;
|
|
212
|
-
let authToken = await lastValueFrom(getAuthToken());
|
|
213
|
-
console.log("Sending GET request to " + url + " with token " + authToken);
|
|
214
|
-
let response = await axios.get(url, {
|
|
215
|
-
headers: { "Authorization": `Bearer ${authToken}` },
|
|
216
|
-
params: params,
|
|
217
|
-
});
|
|
218
|
-
return response.data;
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* getRelatedObjectsAsObservable retrieves an array of objects from the the database. The objects
|
|
222
|
-
* returned are related to a parent through a defined relationship in the schema. In a typical
|
|
223
|
-
* setup, action's auth token must have scope access to the parent object in order to access all of
|
|
224
|
-
* its related objects.
|
|
225
|
-
*
|
|
226
|
-
* It is common to use getRelatedObjects to retrieve all objects belonging to the current user proxy
|
|
227
|
-
* or organization proxy. For example, in a user context where the current user proxy element is
|
|
228
|
-
* "customer," an action might want to retrieve all "purchase" objects related to the current
|
|
229
|
-
* customer. Similarly, in an organization context where the current organization proxy is
|
|
230
|
-
* "business," an action might want to retrieve all "employee" objects related to the current
|
|
231
|
-
* business.
|
|
232
|
-
*
|
|
233
|
-
* @param parentElementId - The ID of the parent element
|
|
234
|
-
* @param parentKey - The key of the parent element
|
|
235
|
-
* @param elementId - The ID of the element
|
|
236
|
-
* @param filter - Optional filter criteria for the query; if not provided, all related objects will
|
|
237
|
-
* be returned
|
|
238
|
-
* @param fetchedRelationships - Optional array of relationships to fetch; if provided, the returned
|
|
239
|
-
* objects will include the specified related objects as nested objects
|
|
240
|
-
*
|
|
241
|
-
* @returns Observable resolving to an array of objects
|
|
242
|
-
*/
|
|
243
|
-
export function getRelatedObjectsAsObservable(parentElementId, parentKey, elementId, filter, fetchedRelationships) {
|
|
244
|
-
return from(getRelatedObjects(parentElementId, parentKey, elementId, filter, fetchedRelationships));
|
|
245
|
-
}
|
|
246
|
-
// ================================================================================
|
|
247
|
-
// DATA SAVE FUNCTIONS
|
|
248
|
-
// ================================================================================
|
|
249
|
-
/**
|
|
250
|
-
* saveRelatedObject saves a related object to the database. The objectToSave is saved, and its
|
|
251
|
-
* relationship to the parent object is established based on the relationship specified in the
|
|
252
|
-
* schema. The objectToSave must have a relationship to the parent object and the user must have
|
|
253
|
-
* scope access to the parent object.
|
|
254
|
-
*
|
|
255
|
-
* @param parentElementId - The ID of the parent element
|
|
256
|
-
* @param parentKey - The key of the parent object
|
|
257
|
-
* @param elementId - The element ID of the object to save
|
|
258
|
-
* @param objectToSave - The object data to save (as a JSON string)
|
|
259
|
-
* @param opts - Optional save options
|
|
260
|
-
*
|
|
261
|
-
* @returns Promise resolving to saved object, including any updates made to the object during the
|
|
262
|
-
* save operation (such as assigning an objKey if the object is new), or the assignment of
|
|
263
|
-
* calculated values
|
|
264
|
-
*/
|
|
265
|
-
export async function saveRelatedObject(parentElementId, parentKey, elementId, objectToSave, opts) {
|
|
266
|
-
let url = `${serviceAddress}/schema/sandboxes/${sandboxKey}/${parentElementId}/${parentKey}/${elementId}`;
|
|
267
|
-
if (opts?.bypassValidation === false) {
|
|
268
|
-
url += "?bypassValidation=false";
|
|
269
|
-
}
|
|
270
|
-
else {
|
|
271
|
-
url += "?bypassValidation=true";
|
|
272
|
-
}
|
|
273
|
-
let authToken = await lastValueFrom(getAuthToken());
|
|
274
|
-
console.log("Sending POST request to " + url + " with token " + authToken);
|
|
275
|
-
let response = await axios.post(url, objectToSave, {
|
|
276
|
-
headers: { "Authorization": `Bearer ${authToken}` },
|
|
277
|
-
});
|
|
278
|
-
return response.data;
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* saveRelatedObjectAsObservable saves a related object to the database. The objectToSave is saved,
|
|
282
|
-
* and its relationship to the parent object is established based on the relationship specified in
|
|
283
|
-
* the schema. The objectToSave must have a relationship to the parent object and the user must have
|
|
284
|
-
* scope access to the parent object.
|
|
285
|
-
*
|
|
286
|
-
* @param parentElementId - The ID of the parent element
|
|
287
|
-
* @param parentKey - The key of the parent object
|
|
288
|
-
* @param elementId - The element ID of the object to save
|
|
289
|
-
* @param objectToSave - The object data to save (as a JSON string)
|
|
290
|
-
* @param opts - Optional save options
|
|
291
|
-
*
|
|
292
|
-
* @returns Observable resolving to saved object, including any updates made to the object during
|
|
293
|
-
* the save operation (such as assigning an objKey if the object is new), or the assignment of
|
|
294
|
-
* calculated values
|
|
295
|
-
*/
|
|
296
|
-
export function saveRelatedObjectAsObservable(parentElementId, parentKey, elementId, objectToSave, opts) {
|
|
297
|
-
return from(saveRelatedObject(parentElementId, parentKey, elementId, objectToSave, opts));
|
|
298
|
-
}
|
|
27
|
+
export {
|
|
28
|
+
// Data Retrieval
|
|
29
|
+
getObject, getObjectAsObservable, getRelatedObjects, getRelatedObjectsAsObservable,
|
|
30
|
+
// Data Save
|
|
31
|
+
saveRelatedObject, saveRelatedObjectAsObservable,
|
|
32
|
+
// Data Delete
|
|
33
|
+
deleteRelatedObject, deleteRelatedObjectAsObservable, deleteRelatedObjects, deleteRelatedObjectsAsObservable } from './data-crud';
|
|
299
34
|
// ================================================================================
|
|
300
|
-
//
|
|
35
|
+
// CONTENT FUNCTIONS
|
|
301
36
|
// ================================================================================
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
* @param parentElementId - The ID of the parent element
|
|
306
|
-
* @param parentKey - The key of the parent object
|
|
307
|
-
* @param childElementId - The ID of the child element to delete
|
|
308
|
-
* @param childKey - The key of the child object to delete
|
|
309
|
-
*
|
|
310
|
-
* @returns Promise resolving to true if deletion was successful
|
|
311
|
-
*/
|
|
312
|
-
export async function deleteRelatedObject(parentElementId, parentKey, childElementId, childKey) {
|
|
313
|
-
if (!userContext) {
|
|
314
|
-
throw new Error("userContext is required but not available; check that the initialize function has been called");
|
|
315
|
-
}
|
|
316
|
-
let url = `${serviceAddress}/schema/sandboxes/${sandboxKey}/${parentElementId}/${parentKey}/${childElementId}/${childKey}`;
|
|
317
|
-
let authToken = await lastValueFrom(getAuthToken());
|
|
318
|
-
console.log("Sending DELETE request to " + url + " with token " + authToken);
|
|
319
|
-
let response = await axios.delete(url, {
|
|
320
|
-
headers: { "Authorization": `Bearer ${authToken}` },
|
|
321
|
-
});
|
|
322
|
-
return response.status === 204;
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* deleteRelatedObjectAsObservable deletes a single object related to a specific parent.
|
|
326
|
-
*
|
|
327
|
-
* @param parentElementId - The ID of the parent element
|
|
328
|
-
* @param parentKey - The key of the parent object
|
|
329
|
-
* @param childElementId - The ID of the child element to delete
|
|
330
|
-
* @param childKey - The key of the child object to delete
|
|
331
|
-
*
|
|
332
|
-
* @returns Observable resolving to true if deletion was successful
|
|
333
|
-
*/
|
|
334
|
-
export function deleteRelatedObjectAsObservable(parentElementId, parentKey, childElementId, childKey) {
|
|
335
|
-
return from(deleteRelatedObject(parentElementId, parentKey, childElementId, childKey));
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* deleteRelatedObjects deletes multiple objects related to a specific parent.
|
|
339
|
-
*
|
|
340
|
-
* @param parentElementId - The ID of the parent element
|
|
341
|
-
* @param parentKey - The key of the parent object
|
|
342
|
-
* @param childElementId - The ID of the child element to delete
|
|
343
|
-
* @param childKeys - Array of keys of the child objects to delete
|
|
344
|
-
*
|
|
345
|
-
* @returns Promise resolving to true if deletion was successful
|
|
346
|
-
*/
|
|
347
|
-
export async function deleteRelatedObjects(parentElementId, parentKey, childElementId, childKeys) {
|
|
348
|
-
if (!userContext) {
|
|
349
|
-
throw new Error("userContext is required but not available; check that the initialize function has been called");
|
|
350
|
-
}
|
|
351
|
-
let url = `${serviceAddress}/schema/sandboxes/${sandboxKey}/${parentElementId}/${parentKey}/${childElementId}`;
|
|
352
|
-
let authToken = await lastValueFrom(getAuthToken());
|
|
353
|
-
console.log("Sending DELETE request to " + url + " with token " + authToken);
|
|
354
|
-
let response = await axios.delete(url, {
|
|
355
|
-
headers: { "Authorization": `Bearer ${authToken}` },
|
|
356
|
-
params: { keys: childKeys.join(",") },
|
|
357
|
-
});
|
|
358
|
-
return response.status === 204;
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
361
|
-
* deleteRelatedObjectsAsObservable deletes multiple objects related to a specific parent.
|
|
362
|
-
*
|
|
363
|
-
* @param parentElementId - The ID of the parent element
|
|
364
|
-
* @param parentKey - The key of the parent object
|
|
365
|
-
* @param childElementId - The ID of the child element to delete
|
|
366
|
-
* @param childKeys - Array of keys of the child objects to delete
|
|
367
|
-
*
|
|
368
|
-
* @returns Observable resolving to true if deletion was successful
|
|
369
|
-
*/
|
|
370
|
-
export function deleteRelatedObjectsAsObservable(parentElementId, parentKey, childElementId, childKeys) {
|
|
371
|
-
return from(deleteRelatedObjects(parentElementId, parentKey, childElementId, childKeys));
|
|
372
|
-
}
|
|
37
|
+
export {
|
|
38
|
+
// Content Functions
|
|
39
|
+
getOrCreateResource, getOrCreateResourceAsObservable, saveResource, saveResourceAsObservable, sendFileContents, sendFileContentsAsObservable, createOrUpdateResource, createOrUpdateResourceAsObservable } from './content';
|
|
373
40
|
// ================================================================================
|
|
374
|
-
//
|
|
41
|
+
// LIST DATA FUNCTIONS
|
|
375
42
|
// ================================================================================
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
* resource from the server. If no key is provided, it creates a new resource with the specified
|
|
380
|
-
* properties.
|
|
381
|
-
*
|
|
382
|
-
* @param resourceKey - Optional key of the existing resource to retrieve
|
|
383
|
-
* @param fileToUpload - Optional file or blob to upload
|
|
384
|
-
* @param publicFlag - Whether the resource should be public
|
|
385
|
-
* @param resourceType - The type of resource
|
|
386
|
-
* @param tags - Array of tags for the resource
|
|
387
|
-
*
|
|
388
|
-
* @returns Promise resolving to a ContentResource
|
|
389
|
-
*/
|
|
390
|
-
export async function getOrCreateResource(resourceKey, fileToUpload, publicFlag, resourceType, tags) {
|
|
391
|
-
if (!userContext) {
|
|
392
|
-
throw new Error("userContext is required but not available; check that the initialize function has been called");
|
|
393
|
-
}
|
|
394
|
-
if (resourceKey) {
|
|
395
|
-
let url = `${serviceAddress}/sandboxes/${sandboxKey}/contentResource/${resourceKey}`;
|
|
396
|
-
let authToken = await lastValueFrom(getAuthToken());
|
|
397
|
-
console.log("Sending GET request to " + url + " with token " + authToken);
|
|
398
|
-
let response = await axios.get(url, {
|
|
399
|
-
headers: { "Authorization": `Bearer ${authToken}` },
|
|
400
|
-
});
|
|
401
|
-
let resource = response.data;
|
|
402
|
-
if (fileToUpload) {
|
|
403
|
-
resource.contentType = fileToUpload.type;
|
|
404
|
-
// Null out the name and extension; the server will set these if they are blank
|
|
405
|
-
resource.name = null;
|
|
406
|
-
resource.extension = null;
|
|
407
|
-
}
|
|
408
|
-
return resource;
|
|
409
|
-
}
|
|
410
|
-
let newResource = {
|
|
411
|
-
isPublic: publicFlag,
|
|
412
|
-
resourceType: resourceType,
|
|
413
|
-
tags: tags,
|
|
414
|
-
organizationKey: userContext.orgKey,
|
|
415
|
-
sandboxKey: sandboxKey,
|
|
416
|
-
userKey: userContext.user.objKey
|
|
417
|
-
};
|
|
418
|
-
if (fileToUpload) {
|
|
419
|
-
newResource.contentType = fileToUpload.type;
|
|
420
|
-
// Null out the name and extension; the server will set these if they are blank
|
|
421
|
-
newResource.name = null;
|
|
422
|
-
newResource.extension = null;
|
|
423
|
-
}
|
|
424
|
-
return newResource;
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* getOrCreateResourceAsObservable retrieves an existing content resource by its key, or creates a new one
|
|
428
|
-
* if the key is not provided. If a resource key is provided, it attempts to fetch the existing
|
|
429
|
-
* resource from the server. If no key is provided, it creates a new resource with the specified
|
|
430
|
-
* properties.
|
|
431
|
-
*
|
|
432
|
-
* @param resourceKey - Optional key of the existing resource to retrieve
|
|
433
|
-
* @param fileToUpload - Optional file or blob to upload
|
|
434
|
-
* @param publicFlag - Whether the resource should be public
|
|
435
|
-
* @param resourceType - The type of resource
|
|
436
|
-
* @param tags - Array of tags for the resource
|
|
437
|
-
*
|
|
438
|
-
* @returns Observable resolving to a ContentResource
|
|
439
|
-
*/
|
|
440
|
-
export function getOrCreateResourceAsObservable(resourceKey, fileToUpload, publicFlag, resourceType, tags) {
|
|
441
|
-
return from(getOrCreateResource(resourceKey, fileToUpload, publicFlag, resourceType, tags));
|
|
442
|
-
}
|
|
443
|
-
/**
|
|
444
|
-
* saveResource saves a content resource to the server. The resource is saved with appropriate
|
|
445
|
-
* ownership parameters based on the current context (solution builder vs regular organization view).
|
|
446
|
-
*
|
|
447
|
-
* @param resource - The ContentResource to save
|
|
448
|
-
*
|
|
449
|
-
* @returns Promise resolving to the saved ContentResource
|
|
450
|
-
*/
|
|
451
|
-
export async function saveResource(resource) {
|
|
452
|
-
if (!userContext) {
|
|
453
|
-
throw new Error("userContext is required but not available; check that the initialize function has been called");
|
|
454
|
-
}
|
|
455
|
-
let params = {};
|
|
456
|
-
if (userContext.orgProxy.objType === "Solution") {
|
|
457
|
-
// When in the solution builder view, content is owned by the solution. The solution key is the org proxy key in
|
|
458
|
-
// the builder view.
|
|
459
|
-
params.solutionKey = userContext.orgProxyKey;
|
|
460
|
-
}
|
|
461
|
-
else {
|
|
462
|
-
params.organizationKey = userContext.orgKey;
|
|
463
|
-
params.userKey = userContext.user.objKey;
|
|
464
|
-
}
|
|
465
|
-
let url = `${serviceAddress}/sandboxes/${sandboxKey}/contentResource`;
|
|
466
|
-
let authToken = await lastValueFrom(getAuthToken());
|
|
467
|
-
console.log("Sending POST request to " + url + " with token " + authToken);
|
|
468
|
-
let response = await axios.post(url, JSON.stringify(resource), {
|
|
469
|
-
headers: { "Authorization": `Bearer ${authToken}` },
|
|
470
|
-
params: params,
|
|
471
|
-
});
|
|
472
|
-
return response.data;
|
|
473
|
-
}
|
|
474
|
-
/**
|
|
475
|
-
* saveResourceAsObservable saves a content resource to the server. The resource is saved with appropriate
|
|
476
|
-
* ownership parameters based on the current context (solution builder vs regular organization view).
|
|
477
|
-
*
|
|
478
|
-
* @param resource - The ContentResource to save
|
|
479
|
-
*
|
|
480
|
-
* @returns Observable resolving to the saved ContentResource
|
|
481
|
-
*/
|
|
482
|
-
export function saveResourceAsObservable(resource) {
|
|
483
|
-
return from(saveResource(resource));
|
|
484
|
-
}
|
|
485
|
-
/**
|
|
486
|
-
* sendFileContents uploads file contents to the server for a specific resource. The file is uploaded
|
|
487
|
-
* via FormData with the appropriate scope and public flag settings.
|
|
488
|
-
*
|
|
489
|
-
* @param resourceKey - The key of the resource to upload file contents for
|
|
490
|
-
* @param fileToUpload - The file or blob to upload
|
|
491
|
-
* @param publicFlag - Whether the file should be public
|
|
492
|
-
*
|
|
493
|
-
* @returns Promise resolving to true if upload was successful
|
|
494
|
-
*/
|
|
495
|
-
export async function sendFileContents(resourceKey, fileToUpload, publicFlag) {
|
|
496
|
-
if (!userContext) {
|
|
497
|
-
throw new Error("userContext is required but not available; check that the initialize function has been called");
|
|
498
|
-
}
|
|
499
|
-
let url = `${serviceAddress}/filecontent/${sandboxKey}/${resourceKey}`;
|
|
500
|
-
let authToken = await lastValueFrom(getAuthToken());
|
|
501
|
-
console.log("Sending file upload request to " + url + " with token " + authToken);
|
|
502
|
-
let formData = new FormData();
|
|
503
|
-
formData.append("fileUpload", fileToUpload);
|
|
504
|
-
formData.append("scopeKeyPath", userContext.orgProxyKey);
|
|
505
|
-
formData.append("public", String(publicFlag));
|
|
506
|
-
let response = await axios.post(url, formData, {
|
|
507
|
-
headers: {
|
|
508
|
-
"Authorization": `Bearer ${authToken}`,
|
|
509
|
-
"Content-Type": "multipart/form-data"
|
|
510
|
-
},
|
|
511
|
-
});
|
|
512
|
-
return response.status === 204;
|
|
513
|
-
}
|
|
514
|
-
/**
|
|
515
|
-
* sendFileContentsAsObservable uploads file contents to the server for a specific resource. The file is uploaded
|
|
516
|
-
* via FormData with the appropriate scope and public flag settings.
|
|
517
|
-
*
|
|
518
|
-
* @param resourceKey - The key of the resource to upload file contents for
|
|
519
|
-
* @param fileToUpload - The file or blob to upload
|
|
520
|
-
* @param publicFlag - Whether the file should be public
|
|
521
|
-
*
|
|
522
|
-
* @returns Observable resolving to true if upload was successful
|
|
523
|
-
*/
|
|
524
|
-
export function sendFileContentsAsObservable(resourceKey, fileToUpload, publicFlag) {
|
|
525
|
-
return from(sendFileContents(resourceKey, fileToUpload, publicFlag));
|
|
526
|
-
}
|
|
527
|
-
/**
|
|
528
|
-
* createOrUpdateResource creates a new content resource or updates an existing one, then uploads
|
|
529
|
-
* the file contents to that resource. If a resourceKey is provided, it updates the existing resource;
|
|
530
|
-
* otherwise, it creates a new resource and uploads the file to the newly created resource.
|
|
531
|
-
*
|
|
532
|
-
* @param resourceKey - Optional key of the existing resource to update; if not provided, a new resource is created
|
|
533
|
-
* @param fileToUpload - The file or blob to upload
|
|
534
|
-
* @param publicFlag - Whether the resource should be public
|
|
535
|
-
* @param resourceType - The type of resource
|
|
536
|
-
* @param tags - Array of tags for the resource
|
|
537
|
-
*
|
|
538
|
-
* @returns Promise resolving to the ContentResource with uploaded file
|
|
539
|
-
*/
|
|
540
|
-
export async function createOrUpdateResource(resourceKey, fileToUpload, publicFlag, resourceType, tags) {
|
|
541
|
-
if (!userContext) {
|
|
542
|
-
throw new Error("userContext is required but not available; check that the initialize function has been called");
|
|
543
|
-
}
|
|
544
|
-
// Get or create the resource
|
|
545
|
-
let resource = await getOrCreateResource(resourceKey, fileToUpload, publicFlag, resourceType, tags);
|
|
546
|
-
// Save the resource to get the objKey if it's new
|
|
547
|
-
let savedResource = await saveResource(resource);
|
|
548
|
-
// Upload the file contents
|
|
549
|
-
if (!savedResource.objKey) {
|
|
550
|
-
throw new Error("Resource was saved but no objKey was returned");
|
|
551
|
-
}
|
|
552
|
-
let uploadSuccess = await sendFileContents(savedResource.objKey, fileToUpload, publicFlag);
|
|
553
|
-
if (!uploadSuccess) {
|
|
554
|
-
throw new Error("Failed to upload file contents");
|
|
555
|
-
}
|
|
556
|
-
// Get the updated resource with file metadata
|
|
557
|
-
let updatedResource = await getOrCreateResource(savedResource.objKey, fileToUpload, publicFlag, resourceType, []);
|
|
558
|
-
// Set the name if it's not set and we have a File with a name
|
|
559
|
-
if (updatedResource && !updatedResource.name && fileToUpload instanceof File) {
|
|
560
|
-
updatedResource.name = fileToUpload.name;
|
|
561
|
-
}
|
|
562
|
-
return updatedResource;
|
|
563
|
-
}
|
|
564
|
-
/**
|
|
565
|
-
* createOrUpdateResourceAsObservable creates a new content resource or updates an existing one, then uploads
|
|
566
|
-
* the file contents to that resource. If a resourceKey is provided, it updates the existing resource;
|
|
567
|
-
* otherwise, it creates a new resource and uploads the file to the newly created resource.
|
|
568
|
-
*
|
|
569
|
-
* @param resourceKey - Optional key of the existing resource to update; if not provided, a new resource is created
|
|
570
|
-
* @param fileToUpload - The file or blob to upload
|
|
571
|
-
* @param publicFlag - Whether the resource should be public
|
|
572
|
-
* @param resourceType - The type of resource
|
|
573
|
-
* @param tags - Array of tags for the resource
|
|
574
|
-
*
|
|
575
|
-
* @returns Observable resolving to the ContentResource with uploaded file
|
|
576
|
-
*/
|
|
577
|
-
export function createOrUpdateResourceAsObservable(resourceKey, fileToUpload, publicFlag, resourceType, tags) {
|
|
578
|
-
return from(createOrUpdateResource(resourceKey, fileToUpload, publicFlag, resourceType, tags));
|
|
579
|
-
}
|
|
43
|
+
export {
|
|
44
|
+
// Functions
|
|
45
|
+
getListData, getListDataAsObservable } from './lists';
|
|
580
46
|
// ================================================================================
|
|
581
47
|
// UTILITY FUNCTIONS
|
|
582
48
|
// ================================================================================
|
|
583
|
-
|
|
584
|
-
* sortObjectArray is a helper function that sorts the passed array in place by the given
|
|
585
|
-
* attributes. Sorting by nested attributes in the form of a delimited attribute string are
|
|
586
|
-
* supported (e.g., "attribute.nestedAttribute").
|
|
587
|
-
*
|
|
588
|
-
* @param array - The array to sort
|
|
589
|
-
* @param sort - Array of sort field specifications
|
|
590
|
-
* @returns The sorted array
|
|
591
|
-
*/
|
|
592
|
-
export function sortObjectArray(array, sort) {
|
|
593
|
-
return array.sort((a, b) => {
|
|
594
|
-
let comparison = 0;
|
|
595
|
-
for (let s of sort) {
|
|
596
|
-
let valueA = getValueFromObject(a, s.attributeId);
|
|
597
|
-
let valueB = getValueFromObject(b, s.attributeId);
|
|
598
|
-
comparison = compareValues(valueA, valueB, !!s.descending, !!s.caseInsensitive);
|
|
599
|
-
if (comparison !== 0) {
|
|
600
|
-
break;
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
return comparison;
|
|
604
|
-
});
|
|
605
|
-
}
|
|
606
|
-
/**
|
|
607
|
-
* compareValues is a helper function that compares two values for sorting purposes. If the values
|
|
608
|
-
* are strings, the comparison is case-insensitive. If the values are numbers, the comparison is
|
|
609
|
-
* performed numerically.
|
|
610
|
-
*
|
|
611
|
-
* @param valueA - First value to compare
|
|
612
|
-
* @param valueB - Second value to compare
|
|
613
|
-
* @param descending - Whether to sort in descending order
|
|
614
|
-
* @param caseInsensitive - Whether to perform case-insensitive comparison for strings
|
|
615
|
-
*
|
|
616
|
-
* @returns Comparison result (-1, 0, or 1)
|
|
617
|
-
*/
|
|
618
|
-
export function compareValues(valueA, valueB, descending, caseInsensitive) {
|
|
619
|
-
if (caseInsensitive && (typeof valueA === 'string' || valueA instanceof String)) {
|
|
620
|
-
if (valueA && valueB) {
|
|
621
|
-
let comp = valueA.toLowerCase().localeCompare(valueB.toLowerCase());
|
|
622
|
-
if (descending) {
|
|
623
|
-
comp = comp * -1;
|
|
624
|
-
}
|
|
625
|
-
return comp;
|
|
626
|
-
}
|
|
627
|
-
else if (valueA && !valueB) {
|
|
628
|
-
return -1;
|
|
629
|
-
}
|
|
630
|
-
else if (!valueA && valueB) {
|
|
631
|
-
return 1;
|
|
632
|
-
}
|
|
633
|
-
else {
|
|
634
|
-
return 0;
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
else {
|
|
638
|
-
if (valueA < valueB) {
|
|
639
|
-
return (descending ? 1 : -1);
|
|
640
|
-
}
|
|
641
|
-
if (valueA > valueB) {
|
|
642
|
-
return (descending ? -1 : 1);
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
return 0;
|
|
646
|
-
}
|
|
647
|
-
/**
|
|
648
|
-
* getValueFromObject is a helper function that extracts a value from an object using a dot-notation
|
|
649
|
-
* path. The path can include relationships. Relationship IDs may include a colon delimiter (e.g.,
|
|
650
|
-
* "accountMember:ownerAccountMemberKey") to specify the key of the related object. This is useful
|
|
651
|
-
* when an element has more than one relationship to the same object type. Otherwise, if only one
|
|
652
|
-
* relationship to the same object type exists, the key may be specified without the relationship ID
|
|
653
|
-
* (e.g., simply, "accountMember").
|
|
654
|
-
*
|
|
655
|
-
* @param object - The object to extract value from
|
|
656
|
-
* @param attribute - The attribute path (e.g., "user.address.city")
|
|
657
|
-
*
|
|
658
|
-
* @returns The extracted value
|
|
659
|
-
*/
|
|
660
|
-
export function getValueFromObject(object, attribute) {
|
|
661
|
-
let components = attribute.split(".");
|
|
662
|
-
let value = object;
|
|
663
|
-
for (let component of components) {
|
|
664
|
-
if (value) {
|
|
665
|
-
// If a relationship specifies a key, it will be in the format [datatype]:[key]. Otherwise the colon
|
|
666
|
-
// delimiter will not be present.
|
|
667
|
-
// The related value will be in a field named after the key. For example: accountMember:ownerAccountMemberKey
|
|
668
|
-
// the related owner account member will be in a field called "ownerAccountMember".
|
|
669
|
-
let compSplit = component.split(":");
|
|
670
|
-
if (compSplit.length > 1) {
|
|
671
|
-
let keyField = compSplit[1];
|
|
672
|
-
value = value[keyField.replace("Key", "")];
|
|
673
|
-
}
|
|
674
|
-
else {
|
|
675
|
-
value = value[component];
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
return value;
|
|
680
|
-
}
|
|
681
|
-
/**
|
|
682
|
-
* debounceFn is a utility function that debounces a function call. It is used to prevent multiple
|
|
683
|
-
* calls to the same function within a short period of time.
|
|
684
|
-
*
|
|
685
|
-
* @param fn - The function to debounce
|
|
686
|
-
* @param wait - The number of milliseconds to wait before calling the function
|
|
687
|
-
*
|
|
688
|
-
* @returns The debounced function
|
|
689
|
-
*/
|
|
690
|
-
export function debounceFn(fn, wait = 200) {
|
|
691
|
-
let timeout;
|
|
692
|
-
return (...args) => {
|
|
693
|
-
clearTimeout(timeout);
|
|
694
|
-
timeout = setTimeout(() => fn(...args), wait);
|
|
695
|
-
};
|
|
696
|
-
}
|
|
49
|
+
export { sortObjectArray, compareValues, getValueFromObject, debounceFn } from './utilities';
|
|
697
50
|
//# sourceMappingURL=index.js.map
|