@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
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Halix SDK License v1.0
|
|
3
|
+
// Copyright (c) 2025 halix.io LLC.
|
|
4
|
+
//
|
|
5
|
+
// This source code is licensed for use **only** within applications
|
|
6
|
+
// running on the Halix platform, in accordance with Halix SDK guidelines.
|
|
7
|
+
//
|
|
8
|
+
// Unauthorized use outside the Halix platform is prohibited.
|
|
9
|
+
// Full license terms available in the LICENSE file.
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.sortObjectArray = sortObjectArray;
|
|
12
|
+
exports.compareValues = compareValues;
|
|
13
|
+
exports.getValueFromObject = getValueFromObject;
|
|
14
|
+
exports.debounceFn = debounceFn;
|
|
15
|
+
// ================================================================================
|
|
16
|
+
// UTILITY FUNCTIONS
|
|
17
|
+
// ================================================================================
|
|
18
|
+
/**
|
|
19
|
+
* sortObjectArray is a helper function that sorts the passed array in place by the given
|
|
20
|
+
* attributes. Sorting by nested attributes in the form of a delimited attribute string are
|
|
21
|
+
* supported (e.g., "attribute.nestedAttribute").
|
|
22
|
+
*
|
|
23
|
+
* @param array - The array to sort
|
|
24
|
+
* @param sort - Array of sort field specifications
|
|
25
|
+
* @returns The sorted array
|
|
26
|
+
*/
|
|
27
|
+
function sortObjectArray(array, sort) {
|
|
28
|
+
return array.sort((a, b) => {
|
|
29
|
+
let comparison = 0;
|
|
30
|
+
for (let s of sort) {
|
|
31
|
+
let valueA = getValueFromObject(a, s.attributeId);
|
|
32
|
+
let valueB = getValueFromObject(b, s.attributeId);
|
|
33
|
+
comparison = compareValues(valueA, valueB, !!s.descending, !!s.caseInsensitive);
|
|
34
|
+
if (comparison !== 0) {
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return comparison;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* compareValues is a helper function that compares two values for sorting purposes. If the values
|
|
43
|
+
* are strings, the comparison is case-insensitive. If the values are numbers, the comparison is
|
|
44
|
+
* performed numerically.
|
|
45
|
+
*
|
|
46
|
+
* @param valueA - First value to compare
|
|
47
|
+
* @param valueB - Second value to compare
|
|
48
|
+
* @param descending - Whether to sort in descending order
|
|
49
|
+
* @param caseInsensitive - Whether to perform case-insensitive comparison for strings
|
|
50
|
+
*
|
|
51
|
+
* @returns Comparison result (-1, 0, or 1)
|
|
52
|
+
*/
|
|
53
|
+
function compareValues(valueA, valueB, descending, caseInsensitive) {
|
|
54
|
+
if (caseInsensitive && (typeof valueA === 'string' || valueA instanceof String)) {
|
|
55
|
+
if (valueA && valueB) {
|
|
56
|
+
let comp = valueA.toLowerCase().localeCompare(valueB.toLowerCase());
|
|
57
|
+
if (descending) {
|
|
58
|
+
comp = comp * -1;
|
|
59
|
+
}
|
|
60
|
+
return comp;
|
|
61
|
+
}
|
|
62
|
+
else if (valueA && !valueB) {
|
|
63
|
+
return -1;
|
|
64
|
+
}
|
|
65
|
+
else if (!valueA && valueB) {
|
|
66
|
+
return 1;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
if (valueA < valueB) {
|
|
74
|
+
return (descending ? 1 : -1);
|
|
75
|
+
}
|
|
76
|
+
if (valueA > valueB) {
|
|
77
|
+
return (descending ? -1 : 1);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* getValueFromObject is a helper function that extracts a value from an object using a dot-notation
|
|
84
|
+
* path. The path can include relationships. Relationship IDs may include a colon delimiter (e.g.,
|
|
85
|
+
* "accountMember:ownerAccountMemberKey") to specify the key of the related object. This is useful
|
|
86
|
+
* when an element has more than one relationship to the same object type. Otherwise, if only one
|
|
87
|
+
* relationship to the same object type exists, the key may be specified without the relationship ID
|
|
88
|
+
* (e.g., simply, "accountMember").
|
|
89
|
+
*
|
|
90
|
+
* @param object - The object to extract value from
|
|
91
|
+
* @param attribute - The attribute path (e.g., "user.address.city")
|
|
92
|
+
*
|
|
93
|
+
* @returns The extracted value
|
|
94
|
+
*/
|
|
95
|
+
function getValueFromObject(object, attribute) {
|
|
96
|
+
let components = attribute.split(".");
|
|
97
|
+
let value = object;
|
|
98
|
+
for (let component of components) {
|
|
99
|
+
if (value) {
|
|
100
|
+
// If a relationship specifies a key, it will be in the format [datatype]:[key]. Otherwise the colon
|
|
101
|
+
// delimiter will not be present.
|
|
102
|
+
// The related value will be in a field named after the key. For example: accountMember:ownerAccountMemberKey
|
|
103
|
+
// the related owner account member will be in a field called "ownerAccountMember".
|
|
104
|
+
let compSplit = component.split(":");
|
|
105
|
+
if (compSplit.length > 1) {
|
|
106
|
+
let keyField = compSplit[1];
|
|
107
|
+
value = value[keyField.replace("Key", "")];
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
value = value[component];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return value;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* debounceFn is a utility function that debounces a function call. It is used to prevent multiple
|
|
118
|
+
* calls to the same function within a short period of time.
|
|
119
|
+
*
|
|
120
|
+
* @param fn - The function to debounce
|
|
121
|
+
* @param wait - The number of milliseconds to wait before calling the function
|
|
122
|
+
*
|
|
123
|
+
* @returns The debounced function
|
|
124
|
+
*/
|
|
125
|
+
function debounceFn(fn, wait = 200) {
|
|
126
|
+
let timeout;
|
|
127
|
+
return (...args) => {
|
|
128
|
+
clearTimeout(timeout);
|
|
129
|
+
timeout = setTimeout(() => fn(...args), wait);
|
|
130
|
+
};
|
|
131
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
// Halix SDK License v1.0
|
|
2
|
+
// Copyright (c) 2025 halix.io LLC.
|
|
3
|
+
//
|
|
4
|
+
// This source code is licensed for use **only** within applications
|
|
5
|
+
// running on the Halix platform, in accordance with Halix SDK guidelines.
|
|
6
|
+
//
|
|
7
|
+
// Unauthorized use outside the Halix platform is prohibited.
|
|
8
|
+
// Full license terms available in the LICENSE file.
|
|
9
|
+
/**
|
|
10
|
+
* @module @halix/action-sdk/content
|
|
11
|
+
* @description Content resource management functions for the Halix Platform action SDK. This module
|
|
12
|
+
* handles file uploads, content resources, and file storage operations.
|
|
13
|
+
*
|
|
14
|
+
* Key features:
|
|
15
|
+
* - Retrieve content resources (images, documents, etc.)
|
|
16
|
+
* - Upload/save content resources (images, documents, etc.)
|
|
17
|
+
*/
|
|
18
|
+
import axios from 'axios';
|
|
19
|
+
import { from, lastValueFrom } from 'rxjs';
|
|
20
|
+
import { sandboxKey, serviceAddress, getAuthToken, userContext } from './sdk-general';
|
|
21
|
+
// ================================================================================
|
|
22
|
+
// CONTENT RESOURCE FUNCTIONS
|
|
23
|
+
// ================================================================================
|
|
24
|
+
/**
|
|
25
|
+
* getOrCreateResource retrieves an existing content resource by its key, or creates a new one
|
|
26
|
+
* if the key is not provided. If a resource key is provided, it attempts to fetch the existing
|
|
27
|
+
* resource from the server. If no key is provided, it creates a new resource with the specified
|
|
28
|
+
* properties.
|
|
29
|
+
*
|
|
30
|
+
* @param resourceKey - Optional key of the existing resource to retrieve
|
|
31
|
+
* @param fileToUpload - Optional file or blob to upload
|
|
32
|
+
* @param publicFlag - Whether the resource should be public
|
|
33
|
+
* @param resourceType - The type of resource
|
|
34
|
+
* @param tags - Array of tags for the resource
|
|
35
|
+
*
|
|
36
|
+
* @returns Promise resolving to a ContentResource
|
|
37
|
+
*/
|
|
38
|
+
export async function getOrCreateResource(resourceKey, fileToUpload, publicFlag, resourceType, tags) {
|
|
39
|
+
if (!userContext) {
|
|
40
|
+
throw new Error("userContext is required but not available; check that the initialize function has been called");
|
|
41
|
+
}
|
|
42
|
+
if (resourceKey) {
|
|
43
|
+
let url = `${serviceAddress}/sandboxes/${sandboxKey}/contentResource/${resourceKey}`;
|
|
44
|
+
let authToken = await lastValueFrom(getAuthToken());
|
|
45
|
+
console.log("Sending GET request to " + url + " with token " + authToken);
|
|
46
|
+
let response = await axios.get(url, {
|
|
47
|
+
headers: { "Authorization": `Bearer ${authToken}` },
|
|
48
|
+
});
|
|
49
|
+
let resource = response.data;
|
|
50
|
+
if (fileToUpload) {
|
|
51
|
+
resource.contentType = fileToUpload.type;
|
|
52
|
+
// Null out the name and extension; the server will set these if they are blank
|
|
53
|
+
resource.name = null;
|
|
54
|
+
resource.extension = null;
|
|
55
|
+
}
|
|
56
|
+
return resource;
|
|
57
|
+
}
|
|
58
|
+
let newResource = {
|
|
59
|
+
isPublic: publicFlag,
|
|
60
|
+
resourceType: resourceType,
|
|
61
|
+
tags: tags,
|
|
62
|
+
organizationKey: userContext.orgKey,
|
|
63
|
+
sandboxKey: sandboxKey,
|
|
64
|
+
userKey: userContext.user.objKey
|
|
65
|
+
};
|
|
66
|
+
if (fileToUpload) {
|
|
67
|
+
newResource.contentType = fileToUpload.type;
|
|
68
|
+
// Null out the name and extension; the server will set these if they are blank
|
|
69
|
+
newResource.name = null;
|
|
70
|
+
newResource.extension = null;
|
|
71
|
+
}
|
|
72
|
+
return newResource;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* getOrCreateResourceAsObservable retrieves an existing content resource by its key, or creates a new one
|
|
76
|
+
* if the key is not provided. If a resource key is provided, it attempts to fetch the existing
|
|
77
|
+
* resource from the server. If no key is provided, it creates a new resource with the specified
|
|
78
|
+
* properties.
|
|
79
|
+
*
|
|
80
|
+
* @param resourceKey - Optional key of the existing resource to retrieve
|
|
81
|
+
* @param fileToUpload - Optional file or blob to upload
|
|
82
|
+
* @param publicFlag - Whether the resource should be public
|
|
83
|
+
* @param resourceType - The type of resource
|
|
84
|
+
* @param tags - Array of tags for the resource
|
|
85
|
+
*
|
|
86
|
+
* @returns Observable resolving to a ContentResource
|
|
87
|
+
*/
|
|
88
|
+
export function getOrCreateResourceAsObservable(resourceKey, fileToUpload, publicFlag, resourceType, tags) {
|
|
89
|
+
return from(getOrCreateResource(resourceKey, fileToUpload, publicFlag, resourceType, tags));
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* saveResource saves a content resource to the server. The resource is saved with appropriate
|
|
93
|
+
* ownership parameters based on the current context (solution builder vs regular organization view).
|
|
94
|
+
*
|
|
95
|
+
* @param resource - The ContentResource to save
|
|
96
|
+
*
|
|
97
|
+
* @returns Promise resolving to the saved ContentResource
|
|
98
|
+
*/
|
|
99
|
+
export async function saveResource(resource) {
|
|
100
|
+
if (!userContext) {
|
|
101
|
+
throw new Error("userContext is required but not available; check that the initialize function has been called");
|
|
102
|
+
}
|
|
103
|
+
let params = {};
|
|
104
|
+
if (userContext.orgProxy.objType === "Solution") {
|
|
105
|
+
// When in the solution builder view, content is owned by the solution. The solution key is the org proxy key in
|
|
106
|
+
// the builder view.
|
|
107
|
+
params.solutionKey = userContext.orgProxyKey;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
params.organizationKey = userContext.orgKey;
|
|
111
|
+
params.userKey = userContext.user.objKey;
|
|
112
|
+
}
|
|
113
|
+
let url = `${serviceAddress}/sandboxes/${sandboxKey}/contentResource`;
|
|
114
|
+
let authToken = await lastValueFrom(getAuthToken());
|
|
115
|
+
console.log("Sending POST request to " + url + " with token " + authToken);
|
|
116
|
+
let response = await axios.post(url, JSON.stringify(resource), {
|
|
117
|
+
headers: { "Authorization": `Bearer ${authToken}` },
|
|
118
|
+
params: params,
|
|
119
|
+
});
|
|
120
|
+
return response.data;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* saveResourceAsObservable saves a content resource to the server. The resource is saved with appropriate
|
|
124
|
+
* ownership parameters based on the current context (solution builder vs regular organization view).
|
|
125
|
+
*
|
|
126
|
+
* @param resource - The ContentResource to save
|
|
127
|
+
*
|
|
128
|
+
* @returns Observable resolving to the saved ContentResource
|
|
129
|
+
*/
|
|
130
|
+
export function saveResourceAsObservable(resource) {
|
|
131
|
+
return from(saveResource(resource));
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* sendFileContents uploads file contents to the server for a specific resource. The file is uploaded
|
|
135
|
+
* via FormData with the appropriate scope and public flag settings.
|
|
136
|
+
*
|
|
137
|
+
* @param resourceKey - The key of the resource to upload file contents for
|
|
138
|
+
* @param fileToUpload - The file or blob to upload
|
|
139
|
+
* @param publicFlag - Whether the file should be public
|
|
140
|
+
*
|
|
141
|
+
* @returns Promise resolving to true if upload was successful
|
|
142
|
+
*/
|
|
143
|
+
export async function sendFileContents(resourceKey, fileToUpload, publicFlag) {
|
|
144
|
+
if (!userContext) {
|
|
145
|
+
throw new Error("userContext is required but not available; check that the initialize function has been called");
|
|
146
|
+
}
|
|
147
|
+
let url = `${serviceAddress}/filecontent/${sandboxKey}/${resourceKey}`;
|
|
148
|
+
let authToken = await lastValueFrom(getAuthToken());
|
|
149
|
+
console.log("Sending file upload request to " + url + " with token " + authToken);
|
|
150
|
+
let formData = new FormData();
|
|
151
|
+
formData.append("fileUpload", fileToUpload);
|
|
152
|
+
formData.append("scopeKeyPath", userContext.orgProxyKey);
|
|
153
|
+
formData.append("public", String(publicFlag));
|
|
154
|
+
let response = await axios.post(url, formData, {
|
|
155
|
+
headers: {
|
|
156
|
+
"Authorization": `Bearer ${authToken}`,
|
|
157
|
+
"Content-Type": "multipart/form-data"
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
return response.status === 204;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* sendFileContentsAsObservable uploads file contents to the server for a specific resource. The file is uploaded
|
|
164
|
+
* via FormData with the appropriate scope and public flag settings.
|
|
165
|
+
*
|
|
166
|
+
* @param resourceKey - The key of the resource to upload file contents for
|
|
167
|
+
* @param fileToUpload - The file or blob to upload
|
|
168
|
+
* @param publicFlag - Whether the file should be public
|
|
169
|
+
*
|
|
170
|
+
* @returns Observable resolving to true if upload was successful
|
|
171
|
+
*/
|
|
172
|
+
export function sendFileContentsAsObservable(resourceKey, fileToUpload, publicFlag) {
|
|
173
|
+
return from(sendFileContents(resourceKey, fileToUpload, publicFlag));
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* createOrUpdateResource creates a new content resource or updates an existing one, then uploads
|
|
177
|
+
* the file contents to that resource. If a resourceKey is provided, it updates the existing resource;
|
|
178
|
+
* otherwise, it creates a new resource and uploads the file to the newly created resource.
|
|
179
|
+
*
|
|
180
|
+
* @param resourceKey - Optional key of the existing resource to update; if not provided, a new resource is created
|
|
181
|
+
* @param fileToUpload - The file or blob to upload
|
|
182
|
+
* @param publicFlag - Whether the resource should be public
|
|
183
|
+
* @param resourceType - The type of resource
|
|
184
|
+
* @param tags - Array of tags for the resource
|
|
185
|
+
*
|
|
186
|
+
* @returns Promise resolving to the ContentResource with uploaded file
|
|
187
|
+
*/
|
|
188
|
+
export async function createOrUpdateResource(resourceKey, fileToUpload, publicFlag, resourceType, tags) {
|
|
189
|
+
if (!userContext) {
|
|
190
|
+
throw new Error("userContext is required but not available; check that the initialize function has been called");
|
|
191
|
+
}
|
|
192
|
+
// Get or create the resource
|
|
193
|
+
let resource = await getOrCreateResource(resourceKey, fileToUpload, publicFlag, resourceType, tags);
|
|
194
|
+
// Save the resource to get the objKey if it's new
|
|
195
|
+
let savedResource = await saveResource(resource);
|
|
196
|
+
// Upload the file contents
|
|
197
|
+
if (!savedResource.objKey) {
|
|
198
|
+
throw new Error("Resource was saved but no objKey was returned");
|
|
199
|
+
}
|
|
200
|
+
let uploadSuccess = await sendFileContents(savedResource.objKey, fileToUpload, publicFlag);
|
|
201
|
+
if (!uploadSuccess) {
|
|
202
|
+
throw new Error("Failed to upload file contents");
|
|
203
|
+
}
|
|
204
|
+
// Get the updated resource with file metadata
|
|
205
|
+
let updatedResource = await getOrCreateResource(savedResource.objKey, fileToUpload, publicFlag, resourceType, []);
|
|
206
|
+
// Set the name if it's not set and we have a File with a name
|
|
207
|
+
if (updatedResource && !updatedResource.name && fileToUpload instanceof File) {
|
|
208
|
+
updatedResource.name = fileToUpload.name;
|
|
209
|
+
}
|
|
210
|
+
return updatedResource;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* createOrUpdateResourceAsObservable creates a new content resource or updates an existing one, then uploads
|
|
214
|
+
* the file contents to that resource. If a resourceKey is provided, it updates the existing resource;
|
|
215
|
+
* otherwise, it creates a new resource and uploads the file to the newly created resource.
|
|
216
|
+
*
|
|
217
|
+
* @param resourceKey - Optional key of the existing resource to update; if not provided, a new resource is created
|
|
218
|
+
* @param fileToUpload - The file or blob to upload
|
|
219
|
+
* @param publicFlag - Whether the resource should be public
|
|
220
|
+
* @param resourceType - The type of resource
|
|
221
|
+
* @param tags - Array of tags for the resource
|
|
222
|
+
*
|
|
223
|
+
* @returns Observable resolving to the ContentResource with uploaded file
|
|
224
|
+
*/
|
|
225
|
+
export function createOrUpdateResourceAsObservable(resourceKey, fileToUpload, publicFlag, resourceType, tags) {
|
|
226
|
+
return from(createOrUpdateResource(resourceKey, fileToUpload, publicFlag, resourceType, tags));
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.js","sourceRoot":"","sources":["../../src/content.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,mCAAmC;AACnC,EAAE;AACF,oEAAoE;AACpE,0EAA0E;AAC1E,EAAE;AACF,6DAA6D;AAC7D,oDAAoD;AAEpD;;;;;;;;GAQG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAc,aAAa,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AA0BtF,mFAAmF;AACnF,6BAA6B;AAC7B,mFAAmF;AAEnF;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,WAA0B,EAAE,YAAgC,EAAE,UAAmB,EAAE,YAAoB,EAAE,IAAc;IAE7J,IAAI,CAAC,WAAW,EAAE,CAAC;QACf,MAAM,IAAI,KA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,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC;AACnG,CAAC"}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
// Halix SDK License v1.0
|
|
2
|
+
// Copyright (c) 2025 halix.io LLC.
|
|
3
|
+
//
|
|
4
|
+
// This source code is licensed for use **only** within applications
|
|
5
|
+
// running on the Halix platform, in accordance with Halix SDK guidelines.
|
|
6
|
+
//
|
|
7
|
+
// Unauthorized use outside the Halix platform is prohibited.
|
|
8
|
+
// Full license terms available in the LICENSE file.
|
|
9
|
+
/**
|
|
10
|
+
* @module @halix/action-sdk/data-crud
|
|
11
|
+
* @description Data CRUD operations for the Halix Platform action SDK. This module provides functions
|
|
12
|
+
* for creating, reading, updating, and deleting data objects through the Halix data service API.
|
|
13
|
+
* Note: for list-like displays, the `lists` module is preferred.
|
|
14
|
+
*
|
|
15
|
+
* Key features:
|
|
16
|
+
* - Retrieve one object a time
|
|
17
|
+
* - Retrieve all objects related to a parent object
|
|
18
|
+
* - Save a single object
|
|
19
|
+
* - Delete a single or multiple objects
|
|
20
|
+
*/
|
|
21
|
+
import axios from 'axios';
|
|
22
|
+
import { from, lastValueFrom } from 'rxjs';
|
|
23
|
+
import { sandboxKey, serviceAddress, getAuthToken, userContext } from './sdk-general';
|
|
24
|
+
// ================================================================================
|
|
25
|
+
// DATA RETRIEVAL FUNCTIONS
|
|
26
|
+
// ================================================================================
|
|
27
|
+
/**
|
|
28
|
+
* getObject retrieves a single object from the database by its data element ID and key.
|
|
29
|
+
*
|
|
30
|
+
* @param dataElementId - The ID of the data element
|
|
31
|
+
* @param key - The key of the object
|
|
32
|
+
* @param fetchedRelationships - Optional array of relationships to fetch; if provided, the returned
|
|
33
|
+
* object will include the specified related objects as nested objects
|
|
34
|
+
* @returns Promise resolving to the object data
|
|
35
|
+
*/
|
|
36
|
+
export async function getObject(dataElementId, key, fetchedRelationships) {
|
|
37
|
+
let params;
|
|
38
|
+
if (fetchedRelationships) {
|
|
39
|
+
let p = {};
|
|
40
|
+
if (fetchedRelationships) {
|
|
41
|
+
p.fetchedRelationships = fetchedRelationships.join(",");
|
|
42
|
+
}
|
|
43
|
+
params = new URLSearchParams(p);
|
|
44
|
+
}
|
|
45
|
+
let url = `${serviceAddress}/schema/sandboxes/${sandboxKey}/${dataElementId}/${key}`;
|
|
46
|
+
let authToken = await lastValueFrom(getAuthToken());
|
|
47
|
+
console.log("Sending GET request to " + url + " with token " + authToken);
|
|
48
|
+
let response = await axios.get(url, {
|
|
49
|
+
headers: { "Authorization": `Bearer ${authToken}` },
|
|
50
|
+
params: params,
|
|
51
|
+
});
|
|
52
|
+
return response.data;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* getObjectAsObservable retrieves a single object from the database by its data element ID and key.
|
|
56
|
+
*
|
|
57
|
+
* @param dataElementId - The ID of the data element
|
|
58
|
+
* @param key - The key of the object
|
|
59
|
+
* @param fetchedRelationships - Optional array of relationships to fetch; if provided, the returned
|
|
60
|
+
* object will include the specified related objects as nested objects
|
|
61
|
+
*
|
|
62
|
+
* @returns Observable resolving to the object data
|
|
63
|
+
*/
|
|
64
|
+
export function getObjectAsObservable(dataElementId, key, fetchedRelationships) {
|
|
65
|
+
return from(getObject(dataElementId, key, fetchedRelationships));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* getRelatedObjects retrieves an array of objects from the the database. The objects returned are
|
|
69
|
+
* related to a parent through a defined relationship in the schema. In a typical setup, action's
|
|
70
|
+
* auth token must have scope access to the parent object in order to access all of its related
|
|
71
|
+
* objects.
|
|
72
|
+
*
|
|
73
|
+
* It is common to use getRelatedObjects to retrieve all objects belonging to the current user proxy
|
|
74
|
+
* or organization proxy. For example, in a user context where the current user proxy element is
|
|
75
|
+
* "customer," an action might want to retrieve all "purchase" objects related to the current
|
|
76
|
+
* customer. Similarly, in an organization context where the current organization proxy is
|
|
77
|
+
* "business," an action might want to retrieve all "employee" objects related to the current
|
|
78
|
+
* business.
|
|
79
|
+
*
|
|
80
|
+
* @param parentElementId - The ID of the parent element
|
|
81
|
+
* @param parentKey - The key of the parent object
|
|
82
|
+
* @param elementId - The ID of the element
|
|
83
|
+
* @param filter - Optional filter criteria for the query; if not provided, all related objects will
|
|
84
|
+
* be returned
|
|
85
|
+
* @param fetchedRelationships - Optional array of relationships to fetch; if provided, the returned
|
|
86
|
+
* objects will include the specified related objects as nested objects
|
|
87
|
+
*
|
|
88
|
+
* @returns Promise resolving to an array of objects
|
|
89
|
+
*/
|
|
90
|
+
export async function getRelatedObjects(parentElementId, parentKey, elementId, filter, fetchedRelationships) {
|
|
91
|
+
let params;
|
|
92
|
+
if (filter || fetchedRelationships) {
|
|
93
|
+
let p = {};
|
|
94
|
+
if (filter) {
|
|
95
|
+
p.filter = filter;
|
|
96
|
+
}
|
|
97
|
+
if (fetchedRelationships) {
|
|
98
|
+
p.fetchedRelationships = fetchedRelationships.join(",");
|
|
99
|
+
}
|
|
100
|
+
params = new URLSearchParams(p);
|
|
101
|
+
}
|
|
102
|
+
let url = `${serviceAddress}/schema/sandboxes/${sandboxKey}/${parentElementId}/${parentKey}/${elementId}`;
|
|
103
|
+
let authToken = await lastValueFrom(getAuthToken());
|
|
104
|
+
console.log("Sending GET request to " + url + " with token " + authToken);
|
|
105
|
+
let response = await axios.get(url, {
|
|
106
|
+
headers: { "Authorization": `Bearer ${authToken}` },
|
|
107
|
+
params: params,
|
|
108
|
+
});
|
|
109
|
+
return response.data;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* getRelatedObjectsAsObservable retrieves an array of objects from the the database. The objects
|
|
113
|
+
* returned are related to a parent through a defined relationship in the schema. In a typical
|
|
114
|
+
* setup, action's auth token must have scope access to the parent object in order to access all of
|
|
115
|
+
* its related objects.
|
|
116
|
+
*
|
|
117
|
+
* It is common to use getRelatedObjects to retrieve all objects belonging to the current user proxy
|
|
118
|
+
* or organization proxy. For example, in a user context where the current user proxy element is
|
|
119
|
+
* "customer," an action might want to retrieve all "purchase" objects related to the current
|
|
120
|
+
* customer. Similarly, in an organization context where the current organization proxy is
|
|
121
|
+
* "business," an action might want to retrieve all "employee" objects related to the current
|
|
122
|
+
* business.
|
|
123
|
+
*
|
|
124
|
+
* @param parentElementId - The ID of the parent element
|
|
125
|
+
* @param parentKey - The key of the parent element
|
|
126
|
+
* @param elementId - The ID of the element
|
|
127
|
+
* @param filter - Optional filter criteria for the query; if not provided, all related objects will
|
|
128
|
+
* be returned
|
|
129
|
+
* @param fetchedRelationships - Optional array of relationships to fetch; if provided, the returned
|
|
130
|
+
* objects will include the specified related objects as nested objects
|
|
131
|
+
*
|
|
132
|
+
* @returns Observable resolving to an array of objects
|
|
133
|
+
*/
|
|
134
|
+
export function getRelatedObjectsAsObservable(parentElementId, parentKey, elementId, filter, fetchedRelationships) {
|
|
135
|
+
return from(getRelatedObjects(parentElementId, parentKey, elementId, filter, fetchedRelationships));
|
|
136
|
+
}
|
|
137
|
+
// ================================================================================
|
|
138
|
+
// DATA SAVE FUNCTIONS
|
|
139
|
+
// ================================================================================
|
|
140
|
+
/**
|
|
141
|
+
* saveRelatedObject saves a related object to the database. The objectToSave is saved, and its
|
|
142
|
+
* relationship to the parent object is established based on the relationship specified in the
|
|
143
|
+
* schema. The objectToSave must have a relationship to the parent object and the user must have
|
|
144
|
+
* scope access to the parent object.
|
|
145
|
+
*
|
|
146
|
+
* @param parentElementId - The ID of the parent element
|
|
147
|
+
* @param parentKey - The key of the parent object
|
|
148
|
+
* @param elementId - The element ID of the object to save
|
|
149
|
+
* @param objectToSave - The object data to save (as a JSON string)
|
|
150
|
+
* @param opts - Optional save options
|
|
151
|
+
*
|
|
152
|
+
* @returns Promise resolving to saved object, including any updates made to the object during the
|
|
153
|
+
* save operation (such as assigning an objKey if the object is new), or the assignment of
|
|
154
|
+
* calculated values
|
|
155
|
+
*/
|
|
156
|
+
export async function saveRelatedObject(parentElementId, parentKey, elementId, objectToSave, opts) {
|
|
157
|
+
let url = `${serviceAddress}/schema/sandboxes/${sandboxKey}/${parentElementId}/${parentKey}/${elementId}`;
|
|
158
|
+
if (opts?.bypassValidation === false) {
|
|
159
|
+
url += "?bypassValidation=false";
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
url += "?bypassValidation=true";
|
|
163
|
+
}
|
|
164
|
+
let authToken = await lastValueFrom(getAuthToken());
|
|
165
|
+
console.log("Sending POST request to " + url + " with token " + authToken);
|
|
166
|
+
let response = await axios.post(url, objectToSave, {
|
|
167
|
+
headers: { "Authorization": `Bearer ${authToken}` },
|
|
168
|
+
});
|
|
169
|
+
return response.data;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* saveRelatedObjectAsObservable saves a related object to the database. The objectToSave is saved,
|
|
173
|
+
* and its relationship to the parent object is established based on the relationship specified in
|
|
174
|
+
* the schema. The objectToSave must have a relationship to the parent object and the user must have
|
|
175
|
+
* scope access to the parent object.
|
|
176
|
+
*
|
|
177
|
+
* @param parentElementId - The ID of the parent element
|
|
178
|
+
* @param parentKey - The key of the parent object
|
|
179
|
+
* @param elementId - The element ID of the object to save
|
|
180
|
+
* @param objectToSave - The object data to save (as a JSON string)
|
|
181
|
+
* @param opts - Optional save options
|
|
182
|
+
*
|
|
183
|
+
* @returns Observable resolving to saved object, including any updates made to the object during
|
|
184
|
+
* the save operation (such as assigning an objKey if the object is new), or the assignment of
|
|
185
|
+
* calculated values
|
|
186
|
+
*/
|
|
187
|
+
export function saveRelatedObjectAsObservable(parentElementId, parentKey, elementId, objectToSave, opts) {
|
|
188
|
+
return from(saveRelatedObject(parentElementId, parentKey, elementId, objectToSave, opts));
|
|
189
|
+
}
|
|
190
|
+
// ================================================================================
|
|
191
|
+
// DATA DELETE FUNCTIONS
|
|
192
|
+
// ================================================================================
|
|
193
|
+
/**
|
|
194
|
+
* deleteRelatedObject deletes a single object related to a specific parent.
|
|
195
|
+
*
|
|
196
|
+
* @param parentElementId - The ID of the parent element
|
|
197
|
+
* @param parentKey - The key of the parent object
|
|
198
|
+
* @param childElementId - The ID of the child element to delete
|
|
199
|
+
* @param childKey - The key of the child object to delete
|
|
200
|
+
*
|
|
201
|
+
* @returns Promise resolving to true if deletion was successful
|
|
202
|
+
*/
|
|
203
|
+
export async function deleteRelatedObject(parentElementId, parentKey, childElementId, childKey) {
|
|
204
|
+
if (!userContext) {
|
|
205
|
+
throw new Error("userContext is required but not available; check that the initialize function has been called");
|
|
206
|
+
}
|
|
207
|
+
let url = `${serviceAddress}/schema/sandboxes/${sandboxKey}/${parentElementId}/${parentKey}/${childElementId}/${childKey}`;
|
|
208
|
+
let authToken = await lastValueFrom(getAuthToken());
|
|
209
|
+
console.log("Sending DELETE request to " + url + " with token " + authToken);
|
|
210
|
+
let response = await axios.delete(url, {
|
|
211
|
+
headers: { "Authorization": `Bearer ${authToken}` },
|
|
212
|
+
});
|
|
213
|
+
return response.status === 204;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* deleteRelatedObjectAsObservable deletes a single object related to a specific parent.
|
|
217
|
+
*
|
|
218
|
+
* @param parentElementId - The ID of the parent element
|
|
219
|
+
* @param parentKey - The key of the parent object
|
|
220
|
+
* @param childElementId - The ID of the child element to delete
|
|
221
|
+
* @param childKey - The key of the child object to delete
|
|
222
|
+
*
|
|
223
|
+
* @returns Observable resolving to true if deletion was successful
|
|
224
|
+
*/
|
|
225
|
+
export function deleteRelatedObjectAsObservable(parentElementId, parentKey, childElementId, childKey) {
|
|
226
|
+
return from(deleteRelatedObject(parentElementId, parentKey, childElementId, childKey));
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* deleteRelatedObjects deletes multiple objects related to a specific parent.
|
|
230
|
+
*
|
|
231
|
+
* @param parentElementId - The ID of the parent element
|
|
232
|
+
* @param parentKey - The key of the parent object
|
|
233
|
+
* @param childElementId - The ID of the child element to delete
|
|
234
|
+
* @param childKeys - Array of keys of the child objects to delete
|
|
235
|
+
*
|
|
236
|
+
* @returns Promise resolving to true if deletion was successful
|
|
237
|
+
*/
|
|
238
|
+
export async function deleteRelatedObjects(parentElementId, parentKey, childElementId, childKeys) {
|
|
239
|
+
if (!userContext) {
|
|
240
|
+
throw new Error("userContext is required but not available; check that the initialize function has been called");
|
|
241
|
+
}
|
|
242
|
+
let url = `${serviceAddress}/schema/sandboxes/${sandboxKey}/${parentElementId}/${parentKey}/${childElementId}`;
|
|
243
|
+
let authToken = await lastValueFrom(getAuthToken());
|
|
244
|
+
console.log("Sending DELETE request to " + url + " with token " + authToken);
|
|
245
|
+
let response = await axios.delete(url, {
|
|
246
|
+
headers: { "Authorization": `Bearer ${authToken}` },
|
|
247
|
+
params: { keys: childKeys.join(",") },
|
|
248
|
+
});
|
|
249
|
+
return response.status === 204;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* deleteRelatedObjectsAsObservable deletes multiple objects related to a specific parent.
|
|
253
|
+
*
|
|
254
|
+
* @param parentElementId - The ID of the parent element
|
|
255
|
+
* @param parentKey - The key of the parent object
|
|
256
|
+
* @param childElementId - The ID of the child element to delete
|
|
257
|
+
* @param childKeys - Array of keys of the child objects to delete
|
|
258
|
+
*
|
|
259
|
+
* @returns Observable resolving to true if deletion was successful
|
|
260
|
+
*/
|
|
261
|
+
export function deleteRelatedObjectsAsObservable(parentElementId, parentKey, childElementId, childKeys) {
|
|
262
|
+
return from(deleteRelatedObjects(parentElementId, parentKey, childElementId, childKeys));
|
|
263
|
+
}
|
|
264
|
+
//# sourceMappingURL=data-crud.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-crud.js","sourceRoot":"","sources":["../../src/data-crud.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,mCAAmC;AACnC,EAAE;AACF,oEAAoE;AACpE,0EAA0E;AAC1E,EAAE;AACF,6DAA6D;AAC7D,oDAAoD;AAEpD;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAc,aAA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