@hahnpro/flow-sdk 2026.4.3 → 2026.4.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hahnpro/flow-sdk",
3
- "version": "2026.4.3",
3
+ "version": "2026.4.5",
4
4
  "description": "SDK for building Flow Modules",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -17,7 +17,7 @@
17
17
  "access": "public"
18
18
  },
19
19
  "dependencies": {
20
- "@hahnpro/hpc-api": "2026.4.3",
20
+ "@hahnpro/hpc-api": "2026.4.5",
21
21
  "@nats-io/jetstream": "3.3.1",
22
22
  "@nats-io/nats-core": "3.3.1",
23
23
  "@nats-io/transport-node": "3.3.1",
@@ -1,14 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FlowApplication = void 0;
4
- const tslib_1 = require("tslib");
5
4
  require("reflect-metadata");
6
5
  const perf_hooks_1 = require("perf_hooks");
7
6
  const hpc_api_1 = require("@hahnpro/hpc-api");
8
7
  const jetstream_1 = require("@nats-io/jetstream");
9
8
  const cloudevents_1 = require("cloudevents");
10
9
  const lodash_1 = require("lodash");
11
- const object_sizeof_1 = tslib_1.__importDefault(require("object-sizeof"));
12
10
  const rxjs_1 = require("rxjs");
13
11
  const operators_1 = require("rxjs/operators");
14
12
  const ContextManager_1 = require("./ContextManager");
@@ -17,7 +15,7 @@ const FlowEvent_1 = require("./FlowEvent");
17
15
  const FlowLogger_1 = require("./FlowLogger");
18
16
  const nats_1 = require("./nats");
19
17
  const utils_1 = require("./utils");
20
- const MAX_EVENT_SIZE_BYTES = +process.env.MAX_EVENT_SIZE_BYTES || 512 * 1024; // 512kb
18
+ const MAX_FLOW_LOG_DATA_SIZE_BYTES = +(process.env.MAX_FLOW_LOG_DATA_SIZE_BYTES ?? utils_1.DEFAULT_MAX_FLOW_LOG_DATA_SIZE_BYTES);
21
19
  const WARN_EVENT_PROCESSING_SEC = +process.env.WARN_EVENT_PROCESSING_SEC || 60;
22
20
  const WARN_EVENT_QUEUE_SIZE = +process.env.WARN_EVENT_QUEUE_SIZE || 100;
23
21
  class FlowApplication {
@@ -198,9 +196,7 @@ class FlowApplication {
198
196
  let natsEvent;
199
197
  try {
200
198
  const formatedEvent = event.format();
201
- if ((0, object_sizeof_1.default)(formatedEvent) > MAX_EVENT_SIZE_BYTES) {
202
- formatedEvent.data = (0, utils_1.truncate)(formatedEvent.data);
203
- }
199
+ formatedEvent.data = (0, utils_1.prepareFlowLogData)(formatedEvent.data, MAX_FLOW_LOG_DATA_SIZE_BYTES);
204
200
  natsEvent = {
205
201
  source: `hpc/flow-application`,
206
202
  type: `${nats_1.natsFlowsPrefixFlowDeployment}.flowlogs`,
@@ -48,3 +48,5 @@ export declare function runPyScript(scriptPath: string, data: any): Promise<any>
48
48
  * Truncates an object or string to the specified max length and depth
49
49
  */
50
50
  export declare function truncate(msg: any, depth?: number, maxStringLength?: number): string;
51
+ export declare const DEFAULT_MAX_FLOW_LOG_DATA_SIZE_BYTES: number;
52
+ export declare function prepareFlowLogData(data: unknown, maxSizeBytes?: number): Record<string, unknown>;
package/src/lib/utils.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_MAX_FLOW_LOG_DATA_SIZE_BYTES = void 0;
3
4
  exports.fillTemplate = fillTemplate;
4
5
  exports.toArray = toArray;
5
6
  exports.delay = delay;
@@ -8,12 +9,14 @@ exports.deleteFiles = deleteFiles;
8
9
  exports.handleApiError = handleApiError;
9
10
  exports.runPyScript = runPyScript;
10
11
  exports.truncate = truncate;
12
+ exports.prepareFlowLogData = prepareFlowLogData;
11
13
  const tslib_1 = require("tslib");
12
14
  const fs_1 = require("fs");
13
15
  const path_1 = require("path");
14
16
  const util_1 = require("util");
15
17
  const axios_1 = require("axios");
16
18
  const isPlainObject_1 = tslib_1.__importDefault(require("lodash/isPlainObject"));
19
+ const object_sizeof_1 = tslib_1.__importDefault(require("object-sizeof"));
17
20
  const python_shell_1 = require("python-shell");
18
21
  const string_interp_1 = tslib_1.__importDefault(require("string-interp"));
19
22
  function fillTemplate(value, ...templateVariables) {
@@ -163,3 +166,23 @@ function truncate(msg, depth = 4, maxStringLength = 1000) {
163
166
  }
164
167
  return truncated;
165
168
  }
169
+ exports.DEFAULT_MAX_FLOW_LOG_DATA_SIZE_BYTES = 64 * 1024;
170
+ function prepareFlowLogData(data, maxSizeBytes = exports.DEFAULT_MAX_FLOW_LOG_DATA_SIZE_BYTES) {
171
+ const originalSizeBytes = (0, object_sizeof_1.default)(data);
172
+ if (originalSizeBytes <= maxSizeBytes) {
173
+ if ((0, isPlainObject_1.default)(data)) {
174
+ return data;
175
+ }
176
+ if (typeof data === 'string') {
177
+ return { message: data };
178
+ }
179
+ return { value: data };
180
+ }
181
+ return {
182
+ message: `Flow log data was truncated because it exceeded ${maxSizeBytes} bytes.`,
183
+ value: truncate(data),
184
+ truncated: true,
185
+ originalSizeBytes,
186
+ maxSizeBytes,
187
+ };
188
+ }