@halix/action-sdk 1.0.18 → 1.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +40 -14
  2. package/lib/cjs/content.js +257 -0
  3. package/lib/cjs/data-crud.js +296 -0
  4. package/lib/cjs/index.js +65 -672
  5. package/lib/cjs/lists.js +175 -0
  6. package/lib/cjs/sdk-general.js +92 -0
  7. package/lib/cjs/types/content.d.ts +119 -0
  8. package/lib/cjs/types/content.d.ts.map +1 -0
  9. package/lib/cjs/types/data-crud.d.ts +156 -0
  10. package/lib/cjs/types/data-crud.d.ts.map +1 -0
  11. package/lib/cjs/types/index.d.ts +8 -578
  12. package/lib/cjs/types/index.d.ts.map +1 -1
  13. package/lib/cjs/types/lists.d.ts +212 -0
  14. package/lib/cjs/types/lists.d.ts.map +1 -0
  15. package/lib/cjs/types/sdk-general.d.ts +263 -0
  16. package/lib/cjs/types/sdk-general.d.ts.map +1 -0
  17. package/lib/cjs/types/utilities.d.ts +73 -0
  18. package/lib/cjs/types/utilities.d.ts.map +1 -0
  19. package/lib/cjs/utilities.js +131 -0
  20. package/lib/esm/content.js +228 -0
  21. package/lib/esm/content.js.map +1 -0
  22. package/lib/esm/data-crud.js +263 -0
  23. package/lib/esm/data-crud.js.map +1 -0
  24. package/lib/esm/index.js.map +1 -1
  25. package/lib/esm/index.mjs +38 -664
  26. package/lib/esm/lists.js +157 -0
  27. package/lib/esm/lists.js.map +1 -0
  28. package/lib/esm/sdk-general.js +138 -0
  29. package/lib/esm/sdk-general.js.map +1 -0
  30. package/lib/esm/types/content.d.ts +118 -0
  31. package/lib/esm/types/data-crud.d.ts +155 -0
  32. package/lib/esm/types/index.d.ts +8 -578
  33. package/lib/esm/types/lists.d.ts +211 -0
  34. package/lib/esm/types/sdk-general.d.ts +262 -0
  35. package/lib/esm/types/utilities.d.ts +72 -0
  36. package/lib/esm/utilities.js +126 -0
  37. package/lib/esm/utilities.js.map +1 -0
  38. package/package.json +20 -3
package/README.md CHANGED
@@ -39,29 +39,29 @@ export const handler = async (event) => {
39
39
  // Refresh the object from the server
40
40
  let fullObj;
41
41
  try {
42
- fullObj = await hx.getObject("exampleType", obj.objKey);
42
+ fullObj = await hx.getObject('exampleType', obj.objKey);
43
43
  } catch (err) {
44
- console.error("Error fetching object", err);
45
- return hx.prepareErrorResponse("Failed to retrieve data");
44
+ console.error('Error fetching object', err);
45
+ return hx.prepareErrorResponse('Failed to retrieve data');
46
46
  }
47
47
 
48
48
  // Perform updates or logic
49
- fullObj.status = "Updated";
49
+ fullObj.status = 'Updated';
50
50
 
51
51
  // Save the updated object
52
52
  let saved;
53
53
  try {
54
- saved = await hx.saveRelatedObject("parentType", fullObj.parentKey, "exampleType", fullObj);
54
+ saved = await hx.saveRelatedObject('parentType', fullObj.parentKey, 'exampleType', fullObj);
55
55
  } catch (err) {
56
- console.error("Error saving object", err);
57
- return hx.prepareErrorResponse("Failed to save data");
56
+ console.error('Error saving object', err);
57
+ return hx.prepareErrorResponse('Failed to save data');
58
58
  }
59
59
 
60
60
  // Return a success response
61
61
  return hx.prepareSuccessResponse({
62
- responseType: "formTemplateAction",
62
+ responseType: 'formTemplateAction',
63
63
  updatedSubject: saved,
64
- successMessage: "Object saved successfully",
64
+ successMessage: 'Object saved successfully',
65
65
  isError: false
66
66
  });
67
67
  };
@@ -86,14 +86,40 @@ This action pattern is typical for use in Halix’s Lambda-style runtime environ
86
86
  | Function | Description |
87
87
  |----------|-------------|
88
88
  | `initialize(event)` | Initializes the SDK with event context |
89
- | `getObject(...)`, `getRelatedObjects(...)` | Retrieve objects from the Halix data layer |
90
- | `saveRelatedObject(...)` | Save objects and establish relationships |
89
+ | `getObject(...)` / `getObjectAsObservable(...)` | Retrieve a single object |
90
+ | `getRelatedObjects(...)` / `getRelatedObjectsAsObservable(...)` | Retrieve related objects |
91
+ | `saveRelatedObject(...)` / `saveRelatedObjectAsObservable(...)` | Save objects and relationships |
92
+ | `deleteRelatedObject(...)` / `deleteRelatedObjectAsObservable(...)` | Delete a single related object |
93
+ | `deleteRelatedObjects(...)` / `deleteRelatedObjectsAsObservable(...)` | Delete multiple related objects (uses `keys` query param) |
91
94
  | `prepareSuccessResponse(...)` | Create a success response |
92
95
  | `prepareErrorResponse(...)` | Create an error response |
93
- | `sortObjectArray(...)` | Utility to sort object arrays |
94
- | `getValueFromObject(...)` | Access nested or relationship-based attributes |
95
96
 
96
- See [Full Documentation](https://mmastrangelo.github.io/halixsdk/) for more information.
97
+ Notes:
98
+ - Functions that interact with services require `initialize(event)` to have been called; they depend on `userContext`, `sandboxKey`, and `serviceAddress`.
99
+
100
+ ---
101
+
102
+ ## 📦 Content Resource Helpers
103
+
104
+ These helpers simplify working with content resources and file uploads.
105
+
106
+ | Function | Description |
107
+ |----------|-------------|
108
+ | `getOrCreateResource(...)` / `getOrCreateResourceAsObservable(...)` | Retrieve an existing content resource by key or create a new one |
109
+ | `saveResource(...)` / `saveResourceAsObservable(...)` | Persist a content resource |
110
+ | `sendFileContents(resourceKey, file, publicFlag)` / `sendFileContentsAsObservable(...)` | Upload file contents (multipart/form-data) to a content resource |
111
+ | `createOrUpdateResource(resourceKey?, file, publicFlag, resourceType, tags)` / `createOrUpdateResourceAsObservable(...)` | Create or update a resource and upload the file in one call |
112
+
113
+ ---
114
+
115
+ ## 🧪 Utilities
116
+
117
+ | Function | Description |
118
+ |----------|-------------|
119
+ | `getValueFromObject(object, attribute)` | Access nested or relationship-based attributes |
120
+ | `debounceFn(fn, wait?)` | Debounce utility for throttling calls |
121
+ | `compareValues(a, b, descending, caseInsensitive)` | Utility comparer for sorting |
122
+ | `sortObjectArray(array, sort)` | Utility to sort object arrays |
97
123
 
98
124
  ---
99
125
 
@@ -0,0 +1,257 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
11
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
12
+ return new (P || (P = Promise))(function (resolve, reject) {
13
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
14
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
15
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
17
+ });
18
+ };
19
+ var __importDefault = (this && this.__importDefault) || function (mod) {
20
+ return (mod && mod.__esModule) ? mod : { "default": mod };
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.getOrCreateResource = getOrCreateResource;
24
+ exports.getOrCreateResourceAsObservable = getOrCreateResourceAsObservable;
25
+ exports.saveResource = saveResource;
26
+ exports.saveResourceAsObservable = saveResourceAsObservable;
27
+ exports.sendFileContents = sendFileContents;
28
+ exports.sendFileContentsAsObservable = sendFileContentsAsObservable;
29
+ exports.createOrUpdateResource = createOrUpdateResource;
30
+ exports.createOrUpdateResourceAsObservable = createOrUpdateResourceAsObservable;
31
+ /**
32
+ * @module @halix/action-sdk/content
33
+ * @description Content resource management functions for the Halix Platform action SDK. This module
34
+ * handles file uploads, content resources, and file storage operations.
35
+ *
36
+ * Key features:
37
+ * - Retrieve content resources (images, documents, etc.)
38
+ * - Upload/save content resources (images, documents, etc.)
39
+ */
40
+ const axios_1 = __importDefault(require("axios"));
41
+ const rxjs_1 = require("rxjs");
42
+ const sdk_general_1 = require("./sdk-general");
43
+ // ================================================================================
44
+ // CONTENT RESOURCE FUNCTIONS
45
+ // ================================================================================
46
+ /**
47
+ * getOrCreateResource retrieves an existing content resource by its key, or creates a new one
48
+ * if the key is not provided. If a resource key is provided, it attempts to fetch the existing
49
+ * resource from the server. If no key is provided, it creates a new resource with the specified
50
+ * properties.
51
+ *
52
+ * @param resourceKey - Optional key of the existing resource to retrieve
53
+ * @param fileToUpload - Optional file or blob to upload
54
+ * @param publicFlag - Whether the resource should be public
55
+ * @param resourceType - The type of resource
56
+ * @param tags - Array of tags for the resource
57
+ *
58
+ * @returns Promise resolving to a ContentResource
59
+ */
60
+ function getOrCreateResource(resourceKey, fileToUpload, publicFlag, resourceType, tags) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ if (!sdk_general_1.userContext) {
63
+ throw new Error("userContext is required but not available; check that the initialize function has been called");
64
+ }
65
+ if (resourceKey) {
66
+ let url = `${sdk_general_1.serviceAddress}/sandboxes/${sdk_general_1.sandboxKey}/contentResource/${resourceKey}`;
67
+ let authToken = yield (0, rxjs_1.lastValueFrom)((0, sdk_general_1.getAuthToken)());
68
+ console.log("Sending GET request to " + url + " with token " + authToken);
69
+ let response = yield axios_1.default.get(url, {
70
+ headers: { "Authorization": `Bearer ${authToken}` },
71
+ });
72
+ let resource = response.data;
73
+ if (fileToUpload) {
74
+ resource.contentType = fileToUpload.type;
75
+ // Null out the name and extension; the server will set these if they are blank
76
+ resource.name = null;
77
+ resource.extension = null;
78
+ }
79
+ return resource;
80
+ }
81
+ let newResource = {
82
+ isPublic: publicFlag,
83
+ resourceType: resourceType,
84
+ tags: tags,
85
+ organizationKey: sdk_general_1.userContext.orgKey,
86
+ sandboxKey: sdk_general_1.sandboxKey,
87
+ userKey: sdk_general_1.userContext.user.objKey
88
+ };
89
+ if (fileToUpload) {
90
+ newResource.contentType = fileToUpload.type;
91
+ // Null out the name and extension; the server will set these if they are blank
92
+ newResource.name = null;
93
+ newResource.extension = null;
94
+ }
95
+ return newResource;
96
+ });
97
+ }
98
+ /**
99
+ * getOrCreateResourceAsObservable retrieves an existing content resource by its key, or creates a new one
100
+ * if the key is not provided. If a resource key is provided, it attempts to fetch the existing
101
+ * resource from the server. If no key is provided, it creates a new resource with the specified
102
+ * properties.
103
+ *
104
+ * @param resourceKey - Optional key of the existing resource to retrieve
105
+ * @param fileToUpload - Optional file or blob to upload
106
+ * @param publicFlag - Whether the resource should be public
107
+ * @param resourceType - The type of resource
108
+ * @param tags - Array of tags for the resource
109
+ *
110
+ * @returns Observable resolving to a ContentResource
111
+ */
112
+ function getOrCreateResourceAsObservable(resourceKey, fileToUpload, publicFlag, resourceType, tags) {
113
+ return (0, rxjs_1.from)(getOrCreateResource(resourceKey, fileToUpload, publicFlag, resourceType, tags));
114
+ }
115
+ /**
116
+ * saveResource saves a content resource to the server. The resource is saved with appropriate
117
+ * ownership parameters based on the current context (solution builder vs regular organization view).
118
+ *
119
+ * @param resource - The ContentResource to save
120
+ *
121
+ * @returns Promise resolving to the saved ContentResource
122
+ */
123
+ function saveResource(resource) {
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ if (!sdk_general_1.userContext) {
126
+ throw new Error("userContext is required but not available; check that the initialize function has been called");
127
+ }
128
+ let params = {};
129
+ if (sdk_general_1.userContext.orgProxy.objType === "Solution") {
130
+ // When in the solution builder view, content is owned by the solution. The solution key is the org proxy key in
131
+ // the builder view.
132
+ params.solutionKey = sdk_general_1.userContext.orgProxyKey;
133
+ }
134
+ else {
135
+ params.organizationKey = sdk_general_1.userContext.orgKey;
136
+ params.userKey = sdk_general_1.userContext.user.objKey;
137
+ }
138
+ let url = `${sdk_general_1.serviceAddress}/sandboxes/${sdk_general_1.sandboxKey}/contentResource`;
139
+ let authToken = yield (0, rxjs_1.lastValueFrom)((0, sdk_general_1.getAuthToken)());
140
+ console.log("Sending POST request to " + url + " with token " + authToken);
141
+ let response = yield axios_1.default.post(url, JSON.stringify(resource), {
142
+ headers: { "Authorization": `Bearer ${authToken}` },
143
+ params: params,
144
+ });
145
+ return response.data;
146
+ });
147
+ }
148
+ /**
149
+ * saveResourceAsObservable saves a content resource to the server. The resource is saved with appropriate
150
+ * ownership parameters based on the current context (solution builder vs regular organization view).
151
+ *
152
+ * @param resource - The ContentResource to save
153
+ *
154
+ * @returns Observable resolving to the saved ContentResource
155
+ */
156
+ function saveResourceAsObservable(resource) {
157
+ return (0, rxjs_1.from)(saveResource(resource));
158
+ }
159
+ /**
160
+ * sendFileContents uploads file contents to the server for a specific resource. The file is uploaded
161
+ * via FormData with the appropriate scope and public flag settings.
162
+ *
163
+ * @param resourceKey - The key of the resource to upload file contents for
164
+ * @param fileToUpload - The file or blob to upload
165
+ * @param publicFlag - Whether the file should be public
166
+ *
167
+ * @returns Promise resolving to true if upload was successful
168
+ */
169
+ function sendFileContents(resourceKey, fileToUpload, publicFlag) {
170
+ return __awaiter(this, void 0, void 0, function* () {
171
+ if (!sdk_general_1.userContext) {
172
+ throw new Error("userContext is required but not available; check that the initialize function has been called");
173
+ }
174
+ let url = `${sdk_general_1.serviceAddress}/filecontent/${sdk_general_1.sandboxKey}/${resourceKey}`;
175
+ let authToken = yield (0, rxjs_1.lastValueFrom)((0, sdk_general_1.getAuthToken)());
176
+ console.log("Sending file upload request to " + url + " with token " + authToken);
177
+ let formData = new FormData();
178
+ formData.append("fileUpload", fileToUpload);
179
+ formData.append("scopeKeyPath", sdk_general_1.userContext.orgProxyKey);
180
+ formData.append("public", String(publicFlag));
181
+ let response = yield axios_1.default.post(url, formData, {
182
+ headers: {
183
+ "Authorization": `Bearer ${authToken}`,
184
+ "Content-Type": "multipart/form-data"
185
+ },
186
+ });
187
+ return response.status === 204;
188
+ });
189
+ }
190
+ /**
191
+ * sendFileContentsAsObservable uploads file contents to the server for a specific resource. The file is uploaded
192
+ * via FormData with the appropriate scope and public flag settings.
193
+ *
194
+ * @param resourceKey - The key of the resource to upload file contents for
195
+ * @param fileToUpload - The file or blob to upload
196
+ * @param publicFlag - Whether the file should be public
197
+ *
198
+ * @returns Observable resolving to true if upload was successful
199
+ */
200
+ function sendFileContentsAsObservable(resourceKey, fileToUpload, publicFlag) {
201
+ return (0, rxjs_1.from)(sendFileContents(resourceKey, fileToUpload, publicFlag));
202
+ }
203
+ /**
204
+ * createOrUpdateResource creates a new content resource or updates an existing one, then uploads
205
+ * the file contents to that resource. If a resourceKey is provided, it updates the existing resource;
206
+ * otherwise, it creates a new resource and uploads the file to the newly created resource.
207
+ *
208
+ * @param resourceKey - Optional key of the existing resource to update; if not provided, a new resource is created
209
+ * @param fileToUpload - The file or blob to upload
210
+ * @param publicFlag - Whether the resource should be public
211
+ * @param resourceType - The type of resource
212
+ * @param tags - Array of tags for the resource
213
+ *
214
+ * @returns Promise resolving to the ContentResource with uploaded file
215
+ */
216
+ function createOrUpdateResource(resourceKey, fileToUpload, publicFlag, resourceType, tags) {
217
+ return __awaiter(this, void 0, void 0, function* () {
218
+ if (!sdk_general_1.userContext) {
219
+ throw new Error("userContext is required but not available; check that the initialize function has been called");
220
+ }
221
+ // Get or create the resource
222
+ let resource = yield getOrCreateResource(resourceKey, fileToUpload, publicFlag, resourceType, tags);
223
+ // Save the resource to get the objKey if it's new
224
+ let savedResource = yield saveResource(resource);
225
+ // Upload the file contents
226
+ if (!savedResource.objKey) {
227
+ throw new Error("Resource was saved but no objKey was returned");
228
+ }
229
+ let uploadSuccess = yield sendFileContents(savedResource.objKey, fileToUpload, publicFlag);
230
+ if (!uploadSuccess) {
231
+ throw new Error("Failed to upload file contents");
232
+ }
233
+ // Get the updated resource with file metadata
234
+ let updatedResource = yield getOrCreateResource(savedResource.objKey, fileToUpload, publicFlag, resourceType, []);
235
+ // Set the name if it's not set and we have a File with a name
236
+ if (updatedResource && !updatedResource.name && fileToUpload instanceof File) {
237
+ updatedResource.name = fileToUpload.name;
238
+ }
239
+ return updatedResource;
240
+ });
241
+ }
242
+ /**
243
+ * createOrUpdateResourceAsObservable creates a new content resource or updates an existing one, then uploads
244
+ * the file contents to that resource. If a resourceKey is provided, it updates the existing resource;
245
+ * otherwise, it creates a new resource and uploads the file to the newly created resource.
246
+ *
247
+ * @param resourceKey - Optional key of the existing resource to update; if not provided, a new resource is created
248
+ * @param fileToUpload - The file or blob to upload
249
+ * @param publicFlag - Whether the resource should be public
250
+ * @param resourceType - The type of resource
251
+ * @param tags - Array of tags for the resource
252
+ *
253
+ * @returns Observable resolving to the ContentResource with uploaded file
254
+ */
255
+ function createOrUpdateResourceAsObservable(resourceKey, fileToUpload, publicFlag, resourceType, tags) {
256
+ return (0, rxjs_1.from)(createOrUpdateResource(resourceKey, fileToUpload, publicFlag, resourceType, tags));
257
+ }
@@ -0,0 +1,296 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
11
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
12
+ return new (P || (P = Promise))(function (resolve, reject) {
13
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
14
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
15
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
17
+ });
18
+ };
19
+ var __importDefault = (this && this.__importDefault) || function (mod) {
20
+ return (mod && mod.__esModule) ? mod : { "default": mod };
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.getObject = getObject;
24
+ exports.getObjectAsObservable = getObjectAsObservable;
25
+ exports.getRelatedObjects = getRelatedObjects;
26
+ exports.getRelatedObjectsAsObservable = getRelatedObjectsAsObservable;
27
+ exports.saveRelatedObject = saveRelatedObject;
28
+ exports.saveRelatedObjectAsObservable = saveRelatedObjectAsObservable;
29
+ exports.deleteRelatedObject = deleteRelatedObject;
30
+ exports.deleteRelatedObjectAsObservable = deleteRelatedObjectAsObservable;
31
+ exports.deleteRelatedObjects = deleteRelatedObjects;
32
+ exports.deleteRelatedObjectsAsObservable = deleteRelatedObjectsAsObservable;
33
+ /**
34
+ * @module @halix/action-sdk/data-crud
35
+ * @description Data CRUD operations for the Halix Platform action SDK. This module provides functions
36
+ * for creating, reading, updating, and deleting data objects through the Halix data service API.
37
+ *
38
+ * Key features:
39
+ * - Retrieve one object a time
40
+ * - Retrieve all objects related to a parent object
41
+ * - Save a single object
42
+ * - Delete a single or multiple objects
43
+ */
44
+ const axios_1 = __importDefault(require("axios"));
45
+ const rxjs_1 = require("rxjs");
46
+ const sdk_general_1 = require("./sdk-general");
47
+ // ================================================================================
48
+ // DATA RETRIEVAL FUNCTIONS
49
+ // ================================================================================
50
+ /**
51
+ * getObject retrieves a single object from the database by its data element ID and key.
52
+ *
53
+ * @param dataElementId - The ID of the data element
54
+ * @param key - The key of the object
55
+ * @param fetchedRelationships - Optional array of relationships to fetch; if provided, the returned
56
+ * object will include the specified related objects as nested objects
57
+ * @returns Promise resolving to the object data
58
+ */
59
+ function getObject(dataElementId, key, fetchedRelationships) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ let params;
62
+ if (fetchedRelationships) {
63
+ let p = {};
64
+ if (fetchedRelationships) {
65
+ p.fetchedRelationships = fetchedRelationships.join(",");
66
+ }
67
+ params = new URLSearchParams(p);
68
+ }
69
+ let url = `${sdk_general_1.serviceAddress}/schema/sandboxes/${sdk_general_1.sandboxKey}/${dataElementId}/${key}`;
70
+ let authToken = yield (0, rxjs_1.lastValueFrom)((0, sdk_general_1.getAuthToken)());
71
+ console.log("Sending GET request to " + url + " with token " + authToken);
72
+ let response = yield axios_1.default.get(url, {
73
+ headers: { "Authorization": `Bearer ${authToken}` },
74
+ params: params,
75
+ });
76
+ return response.data;
77
+ });
78
+ }
79
+ /**
80
+ * getObjectAsObservable retrieves a single object from the database by its data element ID and key.
81
+ *
82
+ * @param dataElementId - The ID of the data element
83
+ * @param key - The key of the object
84
+ * @param fetchedRelationships - Optional array of relationships to fetch; if provided, the returned
85
+ * object will include the specified related objects as nested objects
86
+ *
87
+ * @returns Observable resolving to the object data
88
+ */
89
+ function getObjectAsObservable(dataElementId, key, fetchedRelationships) {
90
+ return (0, rxjs_1.from)(getObject(dataElementId, key, fetchedRelationships));
91
+ }
92
+ /**
93
+ * getRelatedObjects retrieves an array of objects from the the database. The objects returned are
94
+ * related to a parent through a defined relationship in the schema. In a typical setup, action's
95
+ * auth token must have scope access to the parent object in order to access all of its related
96
+ * objects.
97
+ *
98
+ * It is common to use getRelatedObjects to retrieve all objects belonging to the current user proxy
99
+ * or organization proxy. For example, in a user context where the current user proxy element is
100
+ * "customer," an action might want to retrieve all "purchase" objects related to the current
101
+ * customer. Similarly, in an organization context where the current organization proxy is
102
+ * "business," an action might want to retrieve all "employee" objects related to the current
103
+ * business.
104
+ *
105
+ * @param parentElementId - The ID of the parent element
106
+ * @param parentKey - The key of the parent object
107
+ * @param elementId - The ID of the element
108
+ * @param filter - Optional filter criteria for the query; if not provided, all related objects will
109
+ * be returned
110
+ * @param fetchedRelationships - Optional array of relationships to fetch; if provided, the returned
111
+ * objects will include the specified related objects as nested objects
112
+ *
113
+ * @returns Promise resolving to an array of objects
114
+ */
115
+ function getRelatedObjects(parentElementId, parentKey, elementId, filter, fetchedRelationships) {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ let params;
118
+ if (filter || fetchedRelationships) {
119
+ let p = {};
120
+ if (filter) {
121
+ p.filter = filter;
122
+ }
123
+ if (fetchedRelationships) {
124
+ p.fetchedRelationships = fetchedRelationships.join(",");
125
+ }
126
+ params = new URLSearchParams(p);
127
+ }
128
+ let url = `${sdk_general_1.serviceAddress}/schema/sandboxes/${sdk_general_1.sandboxKey}/${parentElementId}/${parentKey}/${elementId}`;
129
+ let authToken = yield (0, rxjs_1.lastValueFrom)((0, sdk_general_1.getAuthToken)());
130
+ console.log("Sending GET request to " + url + " with token " + authToken);
131
+ let response = yield axios_1.default.get(url, {
132
+ headers: { "Authorization": `Bearer ${authToken}` },
133
+ params: params,
134
+ });
135
+ return response.data;
136
+ });
137
+ }
138
+ /**
139
+ * getRelatedObjectsAsObservable retrieves an array of objects from the the database. The objects
140
+ * returned are related to a parent through a defined relationship in the schema. In a typical
141
+ * setup, action's auth token must have scope access to the parent object in order to access all of
142
+ * its related objects.
143
+ *
144
+ * It is common to use getRelatedObjects to retrieve all objects belonging to the current user proxy
145
+ * or organization proxy. For example, in a user context where the current user proxy element is
146
+ * "customer," an action might want to retrieve all "purchase" objects related to the current
147
+ * customer. Similarly, in an organization context where the current organization proxy is
148
+ * "business," an action might want to retrieve all "employee" objects related to the current
149
+ * business.
150
+ *
151
+ * @param parentElementId - The ID of the parent element
152
+ * @param parentKey - The key of the parent element
153
+ * @param elementId - The ID of the element
154
+ * @param filter - Optional filter criteria for the query; if not provided, all related objects will
155
+ * be returned
156
+ * @param fetchedRelationships - Optional array of relationships to fetch; if provided, the returned
157
+ * objects will include the specified related objects as nested objects
158
+ *
159
+ * @returns Observable resolving to an array of objects
160
+ */
161
+ function getRelatedObjectsAsObservable(parentElementId, parentKey, elementId, filter, fetchedRelationships) {
162
+ return (0, rxjs_1.from)(getRelatedObjects(parentElementId, parentKey, elementId, filter, fetchedRelationships));
163
+ }
164
+ // ================================================================================
165
+ // DATA SAVE FUNCTIONS
166
+ // ================================================================================
167
+ /**
168
+ * saveRelatedObject saves a related object to the database. The objectToSave is saved, and its
169
+ * relationship to the parent object is established based on the relationship specified in the
170
+ * schema. The objectToSave must have a relationship to the parent object and the user must have
171
+ * scope access to the parent object.
172
+ *
173
+ * @param parentElementId - The ID of the parent element
174
+ * @param parentKey - The key of the parent object
175
+ * @param elementId - The element ID of the object to save
176
+ * @param objectToSave - The object data to save (as a JSON string)
177
+ * @param opts - Optional save options
178
+ *
179
+ * @returns Promise resolving to saved object, including any updates made to the object during the
180
+ * save operation (such as assigning an objKey if the object is new), or the assignment of
181
+ * calculated values
182
+ */
183
+ function saveRelatedObject(parentElementId, parentKey, elementId, objectToSave, opts) {
184
+ return __awaiter(this, void 0, void 0, function* () {
185
+ let url = `${sdk_general_1.serviceAddress}/schema/sandboxes/${sdk_general_1.sandboxKey}/${parentElementId}/${parentKey}/${elementId}`;
186
+ if ((opts === null || opts === void 0 ? void 0 : opts.bypassValidation) === false) {
187
+ url += "?bypassValidation=false";
188
+ }
189
+ else {
190
+ url += "?bypassValidation=true";
191
+ }
192
+ let authToken = yield (0, rxjs_1.lastValueFrom)((0, sdk_general_1.getAuthToken)());
193
+ console.log("Sending POST request to " + url + " with token " + authToken);
194
+ let response = yield axios_1.default.post(url, objectToSave, {
195
+ headers: { "Authorization": `Bearer ${authToken}` },
196
+ });
197
+ return response.data;
198
+ });
199
+ }
200
+ /**
201
+ * saveRelatedObjectAsObservable saves a related object to the database. The objectToSave is saved,
202
+ * and its relationship to the parent object is established based on the relationship specified in
203
+ * the schema. The objectToSave must have a relationship to the parent object and the user must have
204
+ * scope access to the parent object.
205
+ *
206
+ * @param parentElementId - The ID of the parent element
207
+ * @param parentKey - The key of the parent object
208
+ * @param elementId - The element ID of the object to save
209
+ * @param objectToSave - The object data to save (as a JSON string)
210
+ * @param opts - Optional save options
211
+ *
212
+ * @returns Observable resolving to saved object, including any updates made to the object during
213
+ * the save operation (such as assigning an objKey if the object is new), or the assignment of
214
+ * calculated values
215
+ */
216
+ function saveRelatedObjectAsObservable(parentElementId, parentKey, elementId, objectToSave, opts) {
217
+ return (0, rxjs_1.from)(saveRelatedObject(parentElementId, parentKey, elementId, objectToSave, opts));
218
+ }
219
+ // ================================================================================
220
+ // DATA DELETE FUNCTIONS
221
+ // ================================================================================
222
+ /**
223
+ * deleteRelatedObject deletes a single object related to a specific parent.
224
+ *
225
+ * @param parentElementId - The ID of the parent element
226
+ * @param parentKey - The key of the parent object
227
+ * @param childElementId - The ID of the child element to delete
228
+ * @param childKey - The key of the child object to delete
229
+ *
230
+ * @returns Promise resolving to true if deletion was successful
231
+ */
232
+ function deleteRelatedObject(parentElementId, parentKey, childElementId, childKey) {
233
+ return __awaiter(this, void 0, void 0, function* () {
234
+ if (!sdk_general_1.userContext) {
235
+ throw new Error("userContext is required but not available; check that the initialize function has been called");
236
+ }
237
+ let url = `${sdk_general_1.serviceAddress}/schema/sandboxes/${sdk_general_1.sandboxKey}/${parentElementId}/${parentKey}/${childElementId}/${childKey}`;
238
+ let authToken = yield (0, rxjs_1.lastValueFrom)((0, sdk_general_1.getAuthToken)());
239
+ console.log("Sending DELETE request to " + url + " with token " + authToken);
240
+ let response = yield axios_1.default.delete(url, {
241
+ headers: { "Authorization": `Bearer ${authToken}` },
242
+ });
243
+ return response.status === 204;
244
+ });
245
+ }
246
+ /**
247
+ * deleteRelatedObjectAsObservable deletes a single object related to a specific parent.
248
+ *
249
+ * @param parentElementId - The ID of the parent element
250
+ * @param parentKey - The key of the parent object
251
+ * @param childElementId - The ID of the child element to delete
252
+ * @param childKey - The key of the child object to delete
253
+ *
254
+ * @returns Observable resolving to true if deletion was successful
255
+ */
256
+ function deleteRelatedObjectAsObservable(parentElementId, parentKey, childElementId, childKey) {
257
+ return (0, rxjs_1.from)(deleteRelatedObject(parentElementId, parentKey, childElementId, childKey));
258
+ }
259
+ /**
260
+ * deleteRelatedObjects deletes multiple objects related to a specific parent.
261
+ *
262
+ * @param parentElementId - The ID of the parent element
263
+ * @param parentKey - The key of the parent object
264
+ * @param childElementId - The ID of the child element to delete
265
+ * @param childKeys - Array of keys of the child objects to delete
266
+ *
267
+ * @returns Promise resolving to true if deletion was successful
268
+ */
269
+ function deleteRelatedObjects(parentElementId, parentKey, childElementId, childKeys) {
270
+ return __awaiter(this, void 0, void 0, function* () {
271
+ if (!sdk_general_1.userContext) {
272
+ throw new Error("userContext is required but not available; check that the initialize function has been called");
273
+ }
274
+ let url = `${sdk_general_1.serviceAddress}/schema/sandboxes/${sdk_general_1.sandboxKey}/${parentElementId}/${parentKey}/${childElementId}`;
275
+ let authToken = yield (0, rxjs_1.lastValueFrom)((0, sdk_general_1.getAuthToken)());
276
+ console.log("Sending DELETE request to " + url + " with token " + authToken);
277
+ let response = yield axios_1.default.delete(url, {
278
+ headers: { "Authorization": `Bearer ${authToken}` },
279
+ params: { keys: childKeys.join(",") },
280
+ });
281
+ return response.status === 204;
282
+ });
283
+ }
284
+ /**
285
+ * deleteRelatedObjectsAsObservable deletes multiple objects related to a specific parent.
286
+ *
287
+ * @param parentElementId - The ID of the parent element
288
+ * @param parentKey - The key of the parent object
289
+ * @param childElementId - The ID of the child element to delete
290
+ * @param childKeys - Array of keys of the child objects to delete
291
+ *
292
+ * @returns Observable resolving to true if deletion was successful
293
+ */
294
+ function deleteRelatedObjectsAsObservable(parentElementId, parentKey, childElementId, childKeys) {
295
+ return (0, rxjs_1.from)(deleteRelatedObjects(parentElementId, parentKey, childElementId, childKeys));
296
+ }