@halix/action-sdk 1.0.25 → 1.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,101 @@
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.getAggregateData = getAggregateData;
24
+ exports.getAggregateDataAsObservable = getAggregateDataAsObservable;
25
+ /**
26
+ * @module @halix/action-sdk/data-aggregate
27
+ * @description Data aggregation operations for the Halix Platform action SDK. This module provides functions
28
+ * for performing aggregate queries (count, sum, average, etc.) on data objects grouped by specified fields.
29
+ * Results are returned as aggregated data suitable for charts, reports, and analytics dashboards.
30
+ *
31
+ * Key features:
32
+ * - Group data by one or more fields
33
+ * - Apply transformations to grouping fields (date functions, string functions)
34
+ * - Calculate aggregations (count, sum, average, min, max, median)
35
+ * - Sort aggregated results
36
+ * - Filter data before aggregation
37
+ * - Parent-child relationship scoping for security
38
+ */
39
+ const axios_1 = __importDefault(require("axios"));
40
+ const rxjs_1 = require("rxjs");
41
+ const sdk_general_1 = require("./sdk-general");
42
+ // ================================================================================
43
+ // DATA AGGREGATION FUNCTIONS
44
+ // ================================================================================
45
+ /**
46
+ * Performs data aggregation operations (count, sum, average, etc.) on grouped data.
47
+ * Supports filtering, grouping with transforms, sorting, and multiple aggregations.
48
+ *
49
+ * @param request - Aggregation configuration including dataElementId, parent scope, groups, aggregations
50
+ * @returns Promise<AggregationResponse> with aggregated data array
51
+ *
52
+ * @example
53
+ * const results = await getAggregateData({
54
+ * dataElementId: 'order',
55
+ * parentDataElementId: 'company',
56
+ * parentKey: orgProxyKey,
57
+ * groups: [{
58
+ * groupField: 'status',
59
+ * groupDirection: 'asc'
60
+ * }],
61
+ * aggregations: [{
62
+ * aggregation: 'Count',
63
+ * aggregationField: 'objKey'
64
+ * }, {
65
+ * aggregation: 'Sum',
66
+ * aggregationField: 'totalAmount'
67
+ * }]
68
+ * });
69
+ */
70
+ function getAggregateData(request) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ if (!sdk_general_1.getAuthToken) {
73
+ const errorMessage = 'SDK not initialized.';
74
+ console.error(errorMessage);
75
+ throw new Error(errorMessage);
76
+ }
77
+ const url = `${sdk_general_1.serviceAddress}/sandboxes/${sdk_general_1.sandboxKey}/aggregateData`;
78
+ // Build headers with authentication token
79
+ let authToken = yield (0, rxjs_1.lastValueFrom)((0, sdk_general_1.getAuthToken)());
80
+ let headers = {
81
+ Authorization: `Bearer ${authToken}`
82
+ };
83
+ console.log("Sending POST request to " + url + " with token " + authToken);
84
+ // Make the API request
85
+ let response = yield axios_1.default.post(url, request, { headers });
86
+ return response.data;
87
+ });
88
+ }
89
+ /**
90
+ * Observable version of getAggregateData. See getAggregateData for details.
91
+ *
92
+ * @example
93
+ * getAggregateDataAsObservable({
94
+ * dataElementId: 'order',
95
+ * groups: [{ groupField: 'status', groupDirection: 'asc' }],
96
+ * aggregations: [{ aggregation: 'Count', aggregationField: 'objKey' }]
97
+ * }).subscribe(response => console.log(response.data));
98
+ */
99
+ function getAggregateDataAsObservable(request) {
100
+ return (0, rxjs_1.from)(getAggregateData(request));
101
+ }
package/lib/cjs/index.js CHANGED
@@ -8,7 +8,7 @@
8
8
  // Unauthorized use outside the Halix platform is prohibited.
9
9
  // Full license terms available in the LICENSE file.
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.debounceFn = exports.getValueFromObject = exports.compareValues = exports.sortObjectArray = exports.massDeleteAsObservable = exports.massDelete = exports.massEditAsObservable = exports.massEdit = exports.getListDataAsObservable = exports.getListData = exports.getPreferenceAsObservable = exports.getPreference = exports.sendMessageAsObservable = exports.sendMessage = exports.MessageMethod = exports.createOrUpdateResourceAsObservable = exports.createOrUpdateResource = exports.sendFileContentsAsObservable = exports.sendFileContents = exports.saveResourceAsObservable = exports.saveResource = exports.getOrCreateResourceAsObservable = exports.getOrCreateResource = exports.deleteRelatedObjectsAsObservable = exports.deleteRelatedObjects = exports.deleteRelatedObjectAsObservable = exports.deleteRelatedObject = exports.saveRelatedObjectAsObservable = exports.saveRelatedObject = exports.getRelatedObjectsAsObservable = exports.getRelatedObjects = exports.getObjectAsObservable = exports.getObject = exports.prepareErrorResponse = exports.prepareSuccessResponse = exports.initialize = exports.useBody = exports.params = exports.userContext = exports.actionSubject = exports.serviceAddress = exports.sandboxKey = exports.getAuthToken = void 0;
11
+ exports.debounceFn = exports.getValueFromObject = exports.compareValues = exports.sortObjectArray = exports.getAggregateDataAsObservable = exports.getAggregateData = exports.massDeleteAsObservable = exports.massDelete = exports.massEditAsObservable = exports.massEdit = exports.getListDataAsObservable = exports.getListData = exports.getPreferenceAsObservable = exports.getPreference = exports.sendMessageAsObservable = exports.sendMessage = exports.MessageMethod = exports.createOrUpdateResourceAsObservable = exports.createOrUpdateResource = exports.sendFileContentsAsObservable = exports.sendFileContents = exports.saveResourceAsObservable = exports.saveResource = exports.getOrCreateResourceAsObservable = exports.getOrCreateResource = exports.deleteRelatedObjectsAsObservable = exports.deleteRelatedObjects = exports.deleteRelatedObjectAsObservable = exports.deleteRelatedObject = exports.saveRelatedObjectAsObservable = exports.saveRelatedObject = exports.getRelatedObjectsAsObservable = exports.getRelatedObjects = exports.getObjectAsObservable = exports.getObject = exports.prepareErrorResponse = exports.prepareSuccessResponse = exports.initialize = exports.useBody = exports.params = exports.userContext = exports.actionSubject = exports.serviceAddress = exports.sandboxKey = exports.getAuthToken = void 0;
12
12
  /**
13
13
  * @module @halix/action-sdk
14
14
  * @description Halix Platform action SDK for developing NodeJS Lambda-based actions on the Halix
@@ -89,6 +89,13 @@ Object.defineProperty(exports, "massEditAsObservable", { enumerable: true, get:
89
89
  Object.defineProperty(exports, "massDelete", { enumerable: true, get: function () { return lists_1.massDelete; } });
90
90
  Object.defineProperty(exports, "massDeleteAsObservable", { enumerable: true, get: function () { return lists_1.massDeleteAsObservable; } });
91
91
  // ================================================================================
92
+ // DATA AGGREGATE FUNCTIONS
93
+ // ================================================================================
94
+ var data_aggregate_1 = require("./data-aggregate");
95
+ // Functions
96
+ Object.defineProperty(exports, "getAggregateData", { enumerable: true, get: function () { return data_aggregate_1.getAggregateData; } });
97
+ Object.defineProperty(exports, "getAggregateDataAsObservable", { enumerable: true, get: function () { return data_aggregate_1.getAggregateDataAsObservable; } });
98
+ // ================================================================================
92
99
  // UTILITY FUNCTIONS
93
100
  // ================================================================================
94
101
  var utilities_1 = require("./utilities");
@@ -0,0 +1,140 @@
1
+ import { Observable } from 'rxjs';
2
+ /**
3
+ * TransformType specifies the type of transformation to apply to a group field.
4
+ */
5
+ export type TransformType = 'Year' | 'Month' | 'Week' | 'Day' | 'Hour' | 'Minute' | 'Substring';
6
+ /**
7
+ * AggregationType specifies the type of aggregation to perform on a field.
8
+ */
9
+ export type AggregationType = 'Average' | 'Count' | 'Sum' | 'Max' | 'Min' | 'Median';
10
+ /**
11
+ * AggregationGroupTransform represents a transform function with parameters to be applied to a group field.
12
+ */
13
+ export interface AggregationGroupTransform {
14
+ /** The transformation function to apply */
15
+ transform: TransformType;
16
+ /** Arguments for the transformation function */
17
+ args?: {
18
+ [key: string]: any;
19
+ };
20
+ }
21
+ /**
22
+ * AggregationGroup defines a grouping field with optional transforms and sort direction.
23
+ */
24
+ export interface AggregationGroup {
25
+ /** The field to group by (can include relationship paths with dots, e.g. "customer.lastName") */
26
+ groupField: string;
27
+ /** Sort direction for this group ('asc' or 'desc') */
28
+ groupDirection: 'asc' | 'desc';
29
+ /** Optional transforms to apply to the grouping field */
30
+ transforms?: AggregationGroupTransform[];
31
+ }
32
+ /**
33
+ * AggregationSort defines a secondary sort field for aggregated results.
34
+ */
35
+ export interface AggregationSort {
36
+ /** The field to sort by (can include relationship paths with dots) */
37
+ sortField: string;
38
+ /** Sort direction ('asc' or 'desc') */
39
+ sortDirection: 'asc' | 'desc';
40
+ /** The aggregation type to sort by (must match an aggregation in the request) */
41
+ sortAggregation: AggregationType;
42
+ }
43
+ /**
44
+ * Aggregation defines an aggregation operation to perform on a field.
45
+ */
46
+ export interface Aggregation {
47
+ /** The aggregation function to apply ('Average', 'Count', 'Sum', 'Max', 'Min', 'Median') */
48
+ aggregation: AggregationType;
49
+ /** The field to aggregate (can include relationship paths with dots) */
50
+ aggregationField: string;
51
+ }
52
+ /**
53
+ * AggregationRequest defines the parameters for an aggregation query.
54
+ * The data scope is controlled by parentDataElementId, parentKey, and dataElementId.
55
+ */
56
+ export interface AggregationRequest {
57
+ /**
58
+ * The ID of the data element to aggregate.
59
+ */
60
+ dataElementId: string;
61
+ /**
62
+ * The ID of the parent data element that defines the overall scope of records.
63
+ * The dataElementId must be related to this through a foreign key or key array.
64
+ */
65
+ parentDataElementId?: string;
66
+ /**
67
+ * The key of a parent object that all records must be related to.
68
+ * Works with parentDataElementId to scope results.
69
+ */
70
+ parentKey?: string;
71
+ /**
72
+ * Optional field to specify the foreign key field on the data element that defines
73
+ * the relationship to the parent. If omitted, a derived key is assumed.
74
+ */
75
+ parentKeyField?: string;
76
+ /**
77
+ * Filter expression to limit records before aggregation.
78
+ * @see the filter-expressions module for filter syntax and examples
79
+ */
80
+ filter?: string;
81
+ /**
82
+ * List of grouping specifications. Groups are formed by field values with optional transforms.
83
+ * Results will be grouped by these fields in the order specified.
84
+ */
85
+ groups: AggregationGroup[];
86
+ /**
87
+ * List of secondary sort specifications for the aggregated results.
88
+ * Groups are the primary sorts; these are additional sorting criteria.
89
+ */
90
+ sort?: AggregationSort[];
91
+ /**
92
+ * List of aggregation operations to perform on the grouped data.
93
+ */
94
+ aggregations: Aggregation[];
95
+ }
96
+ /**
97
+ * AggregationResponse wraps the aggregated data results.
98
+ */
99
+ export interface AggregationResponse {
100
+ /** The aggregated data results */
101
+ data: any[];
102
+ }
103
+ /**
104
+ * Performs data aggregation operations (count, sum, average, etc.) on grouped data.
105
+ * Supports filtering, grouping with transforms, sorting, and multiple aggregations.
106
+ *
107
+ * @param request - Aggregation configuration including dataElementId, parent scope, groups, aggregations
108
+ * @returns Promise<AggregationResponse> with aggregated data array
109
+ *
110
+ * @example
111
+ * const results = await getAggregateData({
112
+ * dataElementId: 'order',
113
+ * parentDataElementId: 'company',
114
+ * parentKey: orgProxyKey,
115
+ * groups: [{
116
+ * groupField: 'status',
117
+ * groupDirection: 'asc'
118
+ * }],
119
+ * aggregations: [{
120
+ * aggregation: 'Count',
121
+ * aggregationField: 'objKey'
122
+ * }, {
123
+ * aggregation: 'Sum',
124
+ * aggregationField: 'totalAmount'
125
+ * }]
126
+ * });
127
+ */
128
+ export declare function getAggregateData(request: AggregationRequest): Promise<AggregationResponse>;
129
+ /**
130
+ * Observable version of getAggregateData. See getAggregateData for details.
131
+ *
132
+ * @example
133
+ * getAggregateDataAsObservable({
134
+ * dataElementId: 'order',
135
+ * groups: [{ groupField: 'status', groupDirection: 'asc' }],
136
+ * aggregations: [{ aggregation: 'Count', aggregationField: 'objKey' }]
137
+ * }).subscribe(response => console.log(response.data));
138
+ */
139
+ export declare function getAggregateDataAsObservable(request: AggregationRequest): Observable<AggregationResponse>;
140
+ //# sourceMappingURL=data-aggregate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-aggregate.d.ts","sourceRoot":"","sources":["../../../src/data-aggregate.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAQ,UAAU,EAAiB,MAAM,MAAM,CAAC;AAOvD;;GAEG;AACH,MAAM,MAAM,aAAa,GACnB,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,GACrD,WAAW,CAAC;AAElB;;GAEG;AACH,MAAM,MAAM,eAAe,GACrB,SAAS,GAAG,OAAO,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACtC,2CAA2C;IAC3C,SAAS,EAAE,aAAa,CAAC;IACzB,gDAAgD;IAChD,IAAI,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,iGAAiG;IACjG,UAAU,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,cAAc,EAAE,KAAK,GAAG,MAAM,CAAC;IAC/B,yDAAyD;IACzD,UAAU,CAAC,EAAE,yBAAyB,EAAE,CAAC;CAC5C;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,sEAAsE;IACtE,SAAS,EAAE,MAAM,CAAC;IAClB,uCAAuC;IACvC,aAAa,EAAE,KAAK,GAAG,MAAM,CAAC;IAC9B,iFAAiF;IACjF,eAAe,EAAE,eAAe,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,4FAA4F;IAC5F,WAAW,EAAE,eAAe,CAAC;IAC7B,wEAAwE;IACxE,gBAAgB,EAAE,MAAM,CAAC;CAC5B;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IAC/B;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,MAAM,EAAE,gBAAgB,EAAE,CAAC;IAE3B;;;OAGG;IACH,IAAI,CAAC,EAAE,eAAe,EAAE,CAAC;IAEzB;;OAEG;IACH,YAAY,EAAE,WAAW,EAAE,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,kCAAkC;IAClC,IAAI,EAAE,GAAG,EAAE,CAAC;CACf;AAMD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAqBhG;AAED;;;;;;;;;GASG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,kBAAkB,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAEzG"}
@@ -10,5 +10,6 @@ export { MessageMethod, type MessageRequest, sendMessage, sendMessageAsObservabl
10
10
  export { getPreference, getPreferenceAsObservable } from './preferences';
11
11
  export { type FilterExpression } from './filter-expressions';
12
12
  export { type SortField, type DataSortField, type BaseListDataRequest, type PagedListDataRequest, type ListDataResponse, type ListDataOptions, type ListDataSearchOptions, type MassEditValueType, type MassEditRequest, type MassDeleteRequest, type MassChangeResponse, getListData, getListDataAsObservable, massEdit, massEditAsObservable, massDelete, massDeleteAsObservable } from './lists';
13
+ export { type AggregationRequest, type AggregationResponse, type AggregationGroup, type AggregationSort, type Aggregation, type AggregationGroupTransform, type TransformType, type AggregationType, getAggregateData, getAggregateDataAsObservable } from './data-aggregate';
13
14
  export { sortObjectArray, compareValues, getValueFromObject, debounceFn } from './utilities';
14
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
-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,yBAAyB,EAC5B,MAAM,eAAe,CAAC;AAMvB,OAAO,EACH,KAAK,gBAAgB,EACxB,MAAM,sBAAsB,CAAC;AAM9B,OAAO,EAEH,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EAGvB,WAAW,EACX,uBAAuB,EACvB,QAAQ,EACR,oBAAoB,EACpB,UAAU,EACV,sBAAsB,EACzB,MAAM,SAAS,CAAC;AAMjB,OAAO,EAEH,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,yBAAyB,EAC9B,KAAK,aAAa,EAClB,KAAK,eAAe,EAGpB,gBAAgB,EAChB,4BAA4B,EAC/B,MAAM,kBAAkB,CAAC;AAM1B,OAAO,EACH,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,UAAU,EACb,MAAM,aAAa,CAAC"}
@@ -0,0 +1,84 @@
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-aggregate
11
+ * @description Data aggregation operations for the Halix Platform action SDK. This module provides functions
12
+ * for performing aggregate queries (count, sum, average, etc.) on data objects grouped by specified fields.
13
+ * Results are returned as aggregated data suitable for charts, reports, and analytics dashboards.
14
+ *
15
+ * Key features:
16
+ * - Group data by one or more fields
17
+ * - Apply transformations to grouping fields (date functions, string functions)
18
+ * - Calculate aggregations (count, sum, average, min, max, median)
19
+ * - Sort aggregated results
20
+ * - Filter data before aggregation
21
+ * - Parent-child relationship scoping for security
22
+ */
23
+ import axios from 'axios';
24
+ import { from, lastValueFrom } from 'rxjs';
25
+ import { sandboxKey, serviceAddress, getAuthToken } from './sdk-general';
26
+ // ================================================================================
27
+ // DATA AGGREGATION FUNCTIONS
28
+ // ================================================================================
29
+ /**
30
+ * Performs data aggregation operations (count, sum, average, etc.) on grouped data.
31
+ * Supports filtering, grouping with transforms, sorting, and multiple aggregations.
32
+ *
33
+ * @param request - Aggregation configuration including dataElementId, parent scope, groups, aggregations
34
+ * @returns Promise<AggregationResponse> with aggregated data array
35
+ *
36
+ * @example
37
+ * const results = await getAggregateData({
38
+ * dataElementId: 'order',
39
+ * parentDataElementId: 'company',
40
+ * parentKey: orgProxyKey,
41
+ * groups: [{
42
+ * groupField: 'status',
43
+ * groupDirection: 'asc'
44
+ * }],
45
+ * aggregations: [{
46
+ * aggregation: 'Count',
47
+ * aggregationField: 'objKey'
48
+ * }, {
49
+ * aggregation: 'Sum',
50
+ * aggregationField: 'totalAmount'
51
+ * }]
52
+ * });
53
+ */
54
+ export async function getAggregateData(request) {
55
+ if (!getAuthToken) {
56
+ const errorMessage = 'SDK not initialized.';
57
+ console.error(errorMessage);
58
+ throw new Error(errorMessage);
59
+ }
60
+ const url = `${serviceAddress}/sandboxes/${sandboxKey}/aggregateData`;
61
+ // Build headers with authentication token
62
+ let authToken = await lastValueFrom(getAuthToken());
63
+ let headers = {
64
+ Authorization: `Bearer ${authToken}`
65
+ };
66
+ console.log("Sending POST request to " + url + " with token " + authToken);
67
+ // Make the API request
68
+ let response = await axios.post(url, request, { headers });
69
+ return response.data;
70
+ }
71
+ /**
72
+ * Observable version of getAggregateData. See getAggregateData for details.
73
+ *
74
+ * @example
75
+ * getAggregateDataAsObservable({
76
+ * dataElementId: 'order',
77
+ * groups: [{ groupField: 'status', groupDirection: 'asc' }],
78
+ * aggregations: [{ aggregation: 'Count', aggregationField: 'objKey' }]
79
+ * }).subscribe(response => console.log(response.data));
80
+ */
81
+ export function getAggregateDataAsObservable(request) {
82
+ return from(getAggregateData(request));
83
+ }
84
+ //# sourceMappingURL=data-aggregate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-aggregate.js","sourceRoot":"","sources":["../../src/data-aggregate.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,mCAAmC;AACnC,EAAE;AACF,oEAAoE;AACpE,0EAA0E;AAC1E,EAAE;AACF,6DAA6D;AAC7D,oDAAoD;AAEpD;;;;;;;;;;;;;GAaG;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,MAAM,eAAe,CAAC;AA2HzE,mFAAmF;AACnF,6BAA6B;AAC7B,mFAAmF;AAEnF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAA2B;IAC9D,IAAI,CAAC,YAAY,EAAE,CAAC;QAChB,MAAM,YAAY,GAAG,sBAAsB,CAAC;QAC5C,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;IAClC,CAAC;IAED,MAAM,GAAG,GAAG,GAAG,cAAc,cAAc,UAAU,gBAAgB,CAAC;IAEtE,0CAA0C;IAC1C,IAAI,SAAS,GAAG,MAAM,aAAa,CAAC,YAAY,EAAE,CAAC,CAAC;IACpD,IAAI,OAAO,GAAQ;QACf,aAAa,EAAE,UAAU,SAAS,EAAE;KACvC,CAAC;IAEF,OAAO,CAAC,GAAG,CAAC,0BAA0B,GAAG,GAAG,GAAG,cAAc,GAAG,SAAS,CAAC,CAAC;IAE3E,uBAAuB;IACvB,IAAI,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IAE3D,OAAO,QAAQ,CAAC,IAAI,CAAC;AACzB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,4BAA4B,CAAC,OAA2B;IACpE,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;AAC3C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,mCAAmC;AACnC,EAAE;AACF,oEAAoE;AACpE,0EAA0E;AAC1E,EAAE;AACF,6DAA6D;AAC7D,oDAAoD;AAEpD;;;;GAIG;AAEH,mFAAmF;AACnF,sDAAsD;AACtD,mFAAmF;AAEnF,OAAO;AACH,UAAU;AACV,YAAY,EACZ,UAAU,EACV,cAAc,EACd,aAAa,EACb,WAAW,EACX,MAAM,EACN,OAAO;AAEP,iBAAiB;AACjB,UAAU;AAkBV,mBAAmB;AACnB,sBAAsB,EACtB,oBAAoB,EACvB,MAAM,eAAe,CAAC;AAEvB,mFAAmF;AACnF,sBAAsB;AACtB,mFAAmF;AAEnF,OAAO;AAIH,iBAAiB;AACjB,SAAS,EACT,qBAAqB,EACrB,iBAAiB,EACjB,6BAA6B;AAE7B,YAAY;AACZ,iBAAiB,EACjB,6BAA6B;AAE7B,cAAc;AACd,mBAAmB,EACnB,+BAA+B,EAC/B,oBAAoB,EACpB,gCAAgC,EACnC,MAAM,aAAa,CAAC;AAErB,mFAAmF;AACnF,oBAAoB;AACpB,mFAAmF;AAEnF,OAAO;AAIH,oBAAoB;AACpB,mBAAmB,EACnB,+BAA+B,EAC/B,YAAY,EACZ,wBAAwB,EACxB,gBAAgB,EAChB,4BAA4B,EAC5B,sBAAsB,EACtB,kCAAkC,EACrC,MAAM,WAAW,CAAC;AAEnB,mFAAmF;AACnF,sBAAsB;AACtB,mFAAmF;AAEnF,OAAO;AACH,kBAAkB;AAClB,aAAa;AAKb,sBAAsB;AACtB,WAAW,EACX,uBAAuB,EAC1B,MAAM,aAAa,CAAC;AAErB,mFAAmF;AACnF,uBAAuB;AACvB,mFAAmF;AAEnF,OAAO;AACH,uBAAuB;AACvB,aAAa,EACb,yBAAyB,EAC5B,MAAM,eAAe,CAAC;AAUvB,mFAAmF;AACnF,sBAAsB;AACtB,mFAAmF;AAEnF,OAAO;AAcH,YAAY;AACZ,WAAW,EACX,uBAAuB,EACvB,QAAQ,EACR,oBAAoB,EACpB,UAAU,EACV,sBAAsB,EACzB,MAAM,SAAS,CAAC;AAEjB,mFAAmF;AACnF,oBAAoB;AACpB,mFAAmF;AAEnF,OAAO,EACH,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,UAAU,EACb,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,mCAAmC;AACnC,EAAE;AACF,oEAAoE;AACpE,0EAA0E;AAC1E,EAAE;AACF,6DAA6D;AAC7D,oDAAoD;AAEpD;;;;GAIG;AAEH,mFAAmF;AACnF,sDAAsD;AACtD,mFAAmF;AAEnF,OAAO;AACH,UAAU;AACV,YAAY,EACZ,UAAU,EACV,cAAc,EACd,aAAa,EACb,WAAW,EACX,MAAM,EACN,OAAO;AAEP,iBAAiB;AACjB,UAAU;AAkBV,mBAAmB;AACnB,sBAAsB,EACtB,oBAAoB,EACvB,MAAM,eAAe,CAAC;AAEvB,mFAAmF;AACnF,sBAAsB;AACtB,mFAAmF;AAEnF,OAAO;AAIH,iBAAiB;AACjB,SAAS,EACT,qBAAqB,EACrB,iBAAiB,EACjB,6BAA6B;AAE7B,YAAY;AACZ,iBAAiB,EACjB,6BAA6B;AAE7B,cAAc;AACd,mBAAmB,EACnB,+BAA+B,EAC/B,oBAAoB,EACpB,gCAAgC,EACnC,MAAM,aAAa,CAAC;AAErB,mFAAmF;AACnF,oBAAoB;AACpB,mFAAmF;AAEnF,OAAO;AAIH,oBAAoB;AACpB,mBAAmB,EACnB,+BAA+B,EAC/B,YAAY,EACZ,wBAAwB,EACxB,gBAAgB,EAChB,4BAA4B,EAC5B,sBAAsB,EACtB,kCAAkC,EACrC,MAAM,WAAW,CAAC;AAEnB,mFAAmF;AACnF,sBAAsB;AACtB,mFAAmF;AAEnF,OAAO;AACH,kBAAkB;AAClB,aAAa;AAKb,sBAAsB;AACtB,WAAW,EACX,uBAAuB,EAC1B,MAAM,aAAa,CAAC;AAErB,mFAAmF;AACnF,uBAAuB;AACvB,mFAAmF;AAEnF,OAAO;AACH,uBAAuB;AACvB,aAAa,EACb,yBAAyB,EAC5B,MAAM,eAAe,CAAC;AAUvB,mFAAmF;AACnF,sBAAsB;AACtB,mFAAmF;AAEnF,OAAO;AAcH,YAAY;AACZ,WAAW,EACX,uBAAuB,EACvB,QAAQ,EACR,oBAAoB,EACpB,UAAU,EACV,sBAAsB,EACzB,MAAM,SAAS,CAAC;AAEjB,mFAAmF;AACnF,2BAA2B;AAC3B,mFAAmF;AAEnF,OAAO;AAWH,YAAY;AACZ,gBAAgB,EAChB,4BAA4B,EAC/B,MAAM,kBAAkB,CAAC;AAE1B,mFAAmF;AACnF,oBAAoB;AACpB,mFAAmF;AAEnF,OAAO,EACH,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,UAAU,EACb,MAAM,aAAa,CAAC"}
package/lib/esm/index.mjs CHANGED
@@ -58,6 +58,12 @@ export {
58
58
  // Functions
59
59
  getListData, getListDataAsObservable, massEdit, massEditAsObservable, massDelete, massDeleteAsObservable } from './lists';
60
60
  // ================================================================================
61
+ // DATA AGGREGATE FUNCTIONS
62
+ // ================================================================================
63
+ export {
64
+ // Functions
65
+ getAggregateData, getAggregateDataAsObservable } from './data-aggregate';
66
+ // ================================================================================
61
67
  // UTILITY FUNCTIONS
62
68
  // ================================================================================
63
69
  export { sortObjectArray, compareValues, getValueFromObject, debounceFn } from './utilities';
@@ -0,0 +1,139 @@
1
+ import { Observable } from 'rxjs';
2
+ /**
3
+ * TransformType specifies the type of transformation to apply to a group field.
4
+ */
5
+ export type TransformType = 'Year' | 'Month' | 'Week' | 'Day' | 'Hour' | 'Minute' | 'Substring';
6
+ /**
7
+ * AggregationType specifies the type of aggregation to perform on a field.
8
+ */
9
+ export type AggregationType = 'Average' | 'Count' | 'Sum' | 'Max' | 'Min' | 'Median';
10
+ /**
11
+ * AggregationGroupTransform represents a transform function with parameters to be applied to a group field.
12
+ */
13
+ export interface AggregationGroupTransform {
14
+ /** The transformation function to apply */
15
+ transform: TransformType;
16
+ /** Arguments for the transformation function */
17
+ args?: {
18
+ [key: string]: any;
19
+ };
20
+ }
21
+ /**
22
+ * AggregationGroup defines a grouping field with optional transforms and sort direction.
23
+ */
24
+ export interface AggregationGroup {
25
+ /** The field to group by (can include relationship paths with dots, e.g. "customer.lastName") */
26
+ groupField: string;
27
+ /** Sort direction for this group ('asc' or 'desc') */
28
+ groupDirection: 'asc' | 'desc';
29
+ /** Optional transforms to apply to the grouping field */
30
+ transforms?: AggregationGroupTransform[];
31
+ }
32
+ /**
33
+ * AggregationSort defines a secondary sort field for aggregated results.
34
+ */
35
+ export interface AggregationSort {
36
+ /** The field to sort by (can include relationship paths with dots) */
37
+ sortField: string;
38
+ /** Sort direction ('asc' or 'desc') */
39
+ sortDirection: 'asc' | 'desc';
40
+ /** The aggregation type to sort by (must match an aggregation in the request) */
41
+ sortAggregation: AggregationType;
42
+ }
43
+ /**
44
+ * Aggregation defines an aggregation operation to perform on a field.
45
+ */
46
+ export interface Aggregation {
47
+ /** The aggregation function to apply ('Average', 'Count', 'Sum', 'Max', 'Min', 'Median') */
48
+ aggregation: AggregationType;
49
+ /** The field to aggregate (can include relationship paths with dots) */
50
+ aggregationField: string;
51
+ }
52
+ /**
53
+ * AggregationRequest defines the parameters for an aggregation query.
54
+ * The data scope is controlled by parentDataElementId, parentKey, and dataElementId.
55
+ */
56
+ export interface AggregationRequest {
57
+ /**
58
+ * The ID of the data element to aggregate.
59
+ */
60
+ dataElementId: string;
61
+ /**
62
+ * The ID of the parent data element that defines the overall scope of records.
63
+ * The dataElementId must be related to this through a foreign key or key array.
64
+ */
65
+ parentDataElementId?: string;
66
+ /**
67
+ * The key of a parent object that all records must be related to.
68
+ * Works with parentDataElementId to scope results.
69
+ */
70
+ parentKey?: string;
71
+ /**
72
+ * Optional field to specify the foreign key field on the data element that defines
73
+ * the relationship to the parent. If omitted, a derived key is assumed.
74
+ */
75
+ parentKeyField?: string;
76
+ /**
77
+ * Filter expression to limit records before aggregation.
78
+ * @see the filter-expressions module for filter syntax and examples
79
+ */
80
+ filter?: string;
81
+ /**
82
+ * List of grouping specifications. Groups are formed by field values with optional transforms.
83
+ * Results will be grouped by these fields in the order specified.
84
+ */
85
+ groups: AggregationGroup[];
86
+ /**
87
+ * List of secondary sort specifications for the aggregated results.
88
+ * Groups are the primary sorts; these are additional sorting criteria.
89
+ */
90
+ sort?: AggregationSort[];
91
+ /**
92
+ * List of aggregation operations to perform on the grouped data.
93
+ */
94
+ aggregations: Aggregation[];
95
+ }
96
+ /**
97
+ * AggregationResponse wraps the aggregated data results.
98
+ */
99
+ export interface AggregationResponse {
100
+ /** The aggregated data results */
101
+ data: any[];
102
+ }
103
+ /**
104
+ * Performs data aggregation operations (count, sum, average, etc.) on grouped data.
105
+ * Supports filtering, grouping with transforms, sorting, and multiple aggregations.
106
+ *
107
+ * @param request - Aggregation configuration including dataElementId, parent scope, groups, aggregations
108
+ * @returns Promise<AggregationResponse> with aggregated data array
109
+ *
110
+ * @example
111
+ * const results = await getAggregateData({
112
+ * dataElementId: 'order',
113
+ * parentDataElementId: 'company',
114
+ * parentKey: orgProxyKey,
115
+ * groups: [{
116
+ * groupField: 'status',
117
+ * groupDirection: 'asc'
118
+ * }],
119
+ * aggregations: [{
120
+ * aggregation: 'Count',
121
+ * aggregationField: 'objKey'
122
+ * }, {
123
+ * aggregation: 'Sum',
124
+ * aggregationField: 'totalAmount'
125
+ * }]
126
+ * });
127
+ */
128
+ export declare function getAggregateData(request: AggregationRequest): Promise<AggregationResponse>;
129
+ /**
130
+ * Observable version of getAggregateData. See getAggregateData for details.
131
+ *
132
+ * @example
133
+ * getAggregateDataAsObservable({
134
+ * dataElementId: 'order',
135
+ * groups: [{ groupField: 'status', groupDirection: 'asc' }],
136
+ * aggregations: [{ aggregation: 'Count', aggregationField: 'objKey' }]
137
+ * }).subscribe(response => console.log(response.data));
138
+ */
139
+ export declare function getAggregateDataAsObservable(request: AggregationRequest): Observable<AggregationResponse>;
@@ -10,4 +10,5 @@ export { MessageMethod, type MessageRequest, sendMessage, sendMessageAsObservabl
10
10
  export { getPreference, getPreferenceAsObservable } from './preferences';
11
11
  export { type FilterExpression } from './filter-expressions';
12
12
  export { type SortField, type DataSortField, type BaseListDataRequest, type PagedListDataRequest, type ListDataResponse, type ListDataOptions, type ListDataSearchOptions, type MassEditValueType, type MassEditRequest, type MassDeleteRequest, type MassChangeResponse, getListData, getListDataAsObservable, massEdit, massEditAsObservable, massDelete, massDeleteAsObservable } from './lists';
13
+ export { type AggregationRequest, type AggregationResponse, type AggregationGroup, type AggregationSort, type Aggregation, type AggregationGroupTransform, type TransformType, type AggregationType, getAggregateData, getAggregateDataAsObservable } from './data-aggregate';
13
14
  export { sortObjectArray, compareValues, getValueFromObject, debounceFn } from './utilities';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@halix/action-sdk",
3
- "version": "1.0.25",
3
+ "version": "1.0.26",
4
4
  "description": "Halix Platform action SDK",
5
5
  "types": "./lib/cjs/types/index.d.ts",
6
6
  "main": "./lib/cjs/index.js",