@bonsae/nrg 0.21.1 → 0.22.0

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 (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -3
  3. package/package.json +14 -9
  4. package/schemas/labels.schema.json +15 -5
  5. package/server/index.cjs +2 -1346
  6. package/test/client/component/index.js +41 -224
  7. package/test/client/component/setup.js +201 -1475
  8. package/test/client/e2e/config.js +12 -0
  9. package/test/client/e2e/index.js +422 -199
  10. package/test/client/unit/index.js +19 -32
  11. package/test/client/unit/setup.js +28 -21
  12. package/test/server/integration/index.js +2 -26
  13. package/test/server/unit/index.js +2 -184
  14. package/types/client.d.ts +1 -259
  15. package/types/server.d.ts +1 -892
  16. package/types/test-client-component.d.ts +7 -143
  17. package/types/test-client-e2e.d.ts +0 -6
  18. package/types/test-client-unit.d.ts +11 -105
  19. package/types/test-server-integration.d.ts +73 -49
  20. package/types/test-server-unit.d.ts +26 -2
  21. package/types/vite.d.ts +2 -0
  22. package/vite/index.js +381 -150
  23. package/server/resources/nrg-client.js +0 -7495
  24. package/test/client/component/nrg.css +0 -1
  25. package/types/shims/brands.d.ts +0 -32
  26. package/types/shims/client/form/components/node-red-config-input.vue.d.ts +0 -125
  27. package/types/shims/client/form/components/node-red-editor-input.vue.d.ts +0 -124
  28. package/types/shims/client/form/components/node-red-input-label.vue.d.ts +0 -34
  29. package/types/shims/client/form/components/node-red-input.vue.d.ts +0 -123
  30. package/types/shims/client/form/components/node-red-json-schema-form.vue.d.ts +0 -772
  31. package/types/shims/client/form/components/node-red-select-input.vue.d.ts +0 -132
  32. package/types/shims/client/form/components/node-red-toggle.vue.d.ts +0 -36
  33. package/types/shims/client/form/components/node-red-typed-input.vue.d.ts +0 -151
  34. package/types/shims/client/globals.d.ts +0 -320
  35. package/types/shims/client/types.d.ts +0 -220
  36. package/types/shims/components.d.ts +0 -23
  37. package/types/shims/constants.d.ts +0 -4
  38. package/types/shims/schema-options.d.ts +0 -24
  39. package/types/shims/shims-vue.d.ts +0 -5
  40. package/types/shims/typebox.d.ts +0 -10
package/server/index.cjs CHANGED
@@ -1,1346 +1,2 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/core/server/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- CompletePortSchema: () => CompletePortSchema,
34
- ConfigNode: () => ConfigNode,
35
- ErrorPortSchema: () => ErrorPortSchema,
36
- IONode: () => IONode,
37
- Node: () => Node,
38
- NodeSourceSchema: () => NodeSourceSchema,
39
- NrgError: () => NrgError,
40
- SchemaType: () => SchemaType,
41
- StatusPortSchema: () => StatusPortSchema,
42
- defineConfigNode: () => defineConfigNode,
43
- defineIONode: () => defineIONode,
44
- defineModule: () => defineModule,
45
- defineSchema: () => defineSchema,
46
- registerType: () => registerType,
47
- registerTypes: () => registerTypes
48
- });
49
- module.exports = __toCommonJS(index_exports);
50
-
51
- // src/core/server/nodes/utils.ts
52
- var import_typebox = require("@sinclair/typebox");
53
-
54
- // src/core/errors.ts
55
- var NrgError = class _NrgError extends Error {
56
- constructor(message) {
57
- super(message);
58
- this.name = "NrgError";
59
- Object.setPrototypeOf(this, _NrgError.prototype);
60
- }
61
- };
62
-
63
- // src/core/server/typed-input.ts
64
- var TypedInput = class {
65
- constructor(RED, node, input) {
66
- this.RED = RED;
67
- this.node = node;
68
- this.input = input;
69
- }
70
- resolvers = {
71
- // evaluateNodeProperty returns the node ID string for "node" type —
72
- // resolve it to the actual node instance via RED.nodes.getNode,
73
- // then surface the NRG wrapper if available.
74
- node: (raw) => {
75
- if (typeof raw === "string") {
76
- const node = this.RED.nodes.getNode(raw);
77
- return node?._node ?? node ?? raw;
78
- }
79
- return raw?._node ?? raw;
80
- }
81
- };
82
- get type() {
83
- return this.input.type;
84
- }
85
- get value() {
86
- return this.input.value;
87
- }
88
- resolve(msg) {
89
- return new Promise((resolve, reject) => {
90
- this.RED.util.evaluateNodeProperty(
91
- this.input.value,
92
- this.input.type,
93
- this.node,
94
- msg,
95
- (err, raw) => {
96
- if (err) return reject(err);
97
- const post = this.resolvers[this.input.type];
98
- resolve(post ? post(raw) : raw);
99
- }
100
- );
101
- });
102
- }
103
- };
104
-
105
- // src/core/server/nodes/utils.ts
106
- function isSchemaLike(obj) {
107
- return obj != null && typeof obj === "object" && import_typebox.Kind in obj;
108
- }
109
- function setupContext(context, store) {
110
- return {
111
- get: (key) => new Promise(
112
- (resolve, reject) => context.get(
113
- key,
114
- store,
115
- (error, value) => error ? reject(error) : resolve(value)
116
- )
117
- ),
118
- set: (key, value) => new Promise(
119
- (resolve, reject) => context.set(
120
- key,
121
- value,
122
- store,
123
- (error) => error ? reject(error) : resolve()
124
- )
125
- ),
126
- keys: () => new Promise(
127
- (resolve, reject) => context.keys(store, (error, k) => error ? reject(error) : resolve(k))
128
- )
129
- };
130
- }
131
- function setupConfigProxy(opts) {
132
- const { RED, node, config, schema } = opts;
133
- const SKIP_PROPS = /* @__PURE__ */ new Set(["id", "_id", "_users"]);
134
- const nodeRefProps = /* @__PURE__ */ new Set();
135
- const typedInputProps = /* @__PURE__ */ new Set();
136
- if (schema?.properties) {
137
- for (const [key, propSchema] of Object.entries(schema.properties)) {
138
- const s = propSchema;
139
- if (s?.["x-nrg-node-type"]) nodeRefProps.add(key);
140
- if (s?.["x-nrg-typed-input"]) typedInputProps.add(key);
141
- }
142
- }
143
- const cache = /* @__PURE__ */ new WeakMap();
144
- const createProxy = (obj) => {
145
- const cached = cache.get(obj);
146
- if (cached) return cached;
147
- if (Array.isArray(obj)) {
148
- const mapped = obj.map(
149
- (item) => item && typeof item === "object" ? createProxy(item) : item
150
- );
151
- cache.set(obj, mapped);
152
- return mapped;
153
- }
154
- const proxy = new Proxy(obj, {
155
- get(target, prop) {
156
- if (typeof prop === "symbol") return target[prop];
157
- if (SKIP_PROPS.has(prop)) return target[prop];
158
- const value = target[prop];
159
- if (typeof value === "string" && value.length > 0 && nodeRefProps.has(prop)) {
160
- return RED.nodes.getNode(value)?._node ?? value;
161
- }
162
- if (typedInputProps.has(prop) && value && typeof value === "object" && "type" in value && "value" in value) {
163
- let ref = cache.get(value);
164
- if (!ref) {
165
- ref = new TypedInput(RED, node, value);
166
- cache.set(value, ref);
167
- }
168
- return ref;
169
- }
170
- if (value && typeof value === "object") {
171
- return createProxy(value);
172
- }
173
- return value;
174
- },
175
- set(_target, prop) {
176
- throw new NrgError(
177
- `Cannot set property '${String(prop)}' on read-only node config`
178
- );
179
- }
180
- });
181
- cache.set(obj, proxy);
182
- return proxy;
183
- };
184
- return createProxy(config);
185
- }
186
-
187
- // src/core/server/utils.ts
188
- function getCredentialsFromSchema(schema) {
189
- const result = {};
190
- for (const [key, value] of Object.entries(schema.properties)) {
191
- const property = value;
192
- result[key] = {
193
- // NOTE: required is always false because it is controlled by the JSON Schema and AJV validation instead of using node-red client core
194
- required: false,
195
- type: property.format === "password" ? "password" : "text",
196
- value: property.default ?? void 0
197
- };
198
- }
199
- return result;
200
- }
201
-
202
- // src/core/server/nodes/symbols.ts
203
- var WIRE_HANDLERS = Symbol.for("nrg.wireHandlers");
204
-
205
- // src/core/server/nodes/node.ts
206
- var cachedSettingsMap = /* @__PURE__ */ new WeakMap();
207
- var Node = class _Node {
208
- static type;
209
- static category;
210
- static configSchema;
211
- static credentialsSchema;
212
- static settingsSchema;
213
- static validateSettings(RED) {
214
- if (!this.settingsSchema) return;
215
- RED.log.info("Validating settings");
216
- const prefix = this.type.replace(/-./g, (x) => x[1].toUpperCase());
217
- const properties = this.settingsSchema.properties;
218
- const settings = {};
219
- for (const key of Object.keys(properties)) {
220
- const settingKey = prefix + key.charAt(0).toUpperCase() + key.slice(1);
221
- const value = RED.settings[settingKey];
222
- if (value !== void 0) {
223
- settings[key] = value;
224
- }
225
- }
226
- for (const [key, prop] of Object.entries(properties)) {
227
- if (settings[key] === void 0) {
228
- const defaultValue = prop.default ?? prop._default;
229
- if (defaultValue !== void 0) {
230
- settings[key] = defaultValue;
231
- }
232
- }
233
- }
234
- RED.validator.validate(settings, this.settingsSchema, {
235
- cacheKey: this.settingsSchema.$id || `${this.type}:settings`,
236
- throwOnError: true
237
- });
238
- cachedSettingsMap.set(this, settings);
239
- RED.log.info("Settings are valid");
240
- }
241
- static #buildSettings(NC) {
242
- if (!NC.settingsSchema) return;
243
- const settings = {};
244
- const prefix = NC.type.replace(/-./g, (x) => x[1].toUpperCase());
245
- for (const [key, prop] of Object.entries(NC.settingsSchema.properties)) {
246
- const settingKey = prefix + key.charAt(0).toUpperCase() + key.slice(1);
247
- settings[settingKey] = {
248
- value: prop.default,
249
- exportable: prop.exportable ?? false
250
- };
251
- }
252
- return settings;
253
- }
254
- /**
255
- * Registers this node class with Node-RED. Handles instance creation,
256
- * event handler wiring, settings validation, and the user's registered() hook.
257
- */
258
- static async register(RED) {
259
- const NodeClass = this;
260
- if (NodeClass.color && !/^#[0-9A-Fa-f]{6}$/.test(NodeClass.color)) {
261
- throw new NrgError(
262
- `Invalid color for ${NodeClass.type}: ${NodeClass.color} color must be in hex format`
263
- );
264
- }
265
- RED.nodes.registerType(
266
- NodeClass.type,
267
- function(config) {
268
- RED.nodes.createNode(this, config);
269
- const node = new NodeClass(RED, this, config, this.credentials);
270
- Object.defineProperty(this, "_node", {
271
- value: node,
272
- writable: false,
273
- configurable: false,
274
- enumerable: false
275
- });
276
- const createdPromise = Promise.resolve(node.created?.()).catch(
277
- (error) => {
278
- const message = error instanceof Error ? error.message : String(error);
279
- this.error("Error during created hook: " + message);
280
- throw error;
281
- }
282
- );
283
- createdPromise.catch(() => {
284
- });
285
- node[WIRE_HANDLERS](this, createdPromise);
286
- },
287
- {
288
- credentials: NodeClass.credentialsSchema ? getCredentialsFromSchema(NodeClass.credentialsSchema) : {},
289
- settings: _Node.#buildSettings(this)
290
- }
291
- );
292
- NodeClass.validateSettings(RED);
293
- try {
294
- await Promise.resolve(NodeClass.registered?.(RED));
295
- } catch (error) {
296
- const message = error instanceof Error ? error.message : String(error);
297
- RED.log.error(
298
- `Error during registered hook for ${NodeClass.type}: ${message}`
299
- );
300
- }
301
- }
302
- RED;
303
- node;
304
- context;
305
- config;
306
- timers = /* @__PURE__ */ new Set();
307
- intervals = /* @__PURE__ */ new Set();
308
- constructor(RED, node, config, credentials) {
309
- this.RED = RED;
310
- this.node = node;
311
- const constructor = this.constructor;
312
- if (constructor.configSchema) {
313
- this.log("Validating configs");
314
- const configResult = this.RED.validator.validate(
315
- config,
316
- constructor.configSchema,
317
- {
318
- cacheKey: constructor.configSchema.$id || `${constructor.type}:configs-schema`,
319
- throwOnError: false
320
- }
321
- );
322
- if (!configResult.valid && configResult.errors?.length) {
323
- this.warn(
324
- `Config validation errors: ${configResult.errors.map((e) => `${e.instancePath} ${e.message}`).join("; ")}`
325
- );
326
- }
327
- }
328
- this.config = setupConfigProxy({
329
- RED,
330
- node,
331
- config,
332
- schema: constructor.configSchema
333
- });
334
- if (constructor.credentialsSchema && credentials) {
335
- this.log("Validating credentials");
336
- const credResult = this.RED.validator.validate(
337
- credentials,
338
- constructor.credentialsSchema,
339
- {
340
- cacheKey: constructor.credentialsSchema.$id || `${constructor.type}:credentials-schema`,
341
- throwOnError: false
342
- }
343
- );
344
- if (!credResult.valid && credResult.errors?.length) {
345
- this.warn(
346
- `Credentials validation errors: ${credResult.errors.map((e) => `${e.instancePath} ${e.message}`).join("; ")}`
347
- );
348
- }
349
- }
350
- }
351
- [WIRE_HANDLERS](nodeRedNode, createdPromise) {
352
- nodeRedNode.on(
353
- "close",
354
- async (removed, done) => {
355
- try {
356
- this.log("Calling closed");
357
- await this.#closed(removed);
358
- this.log("Node was closed");
359
- done();
360
- } catch (error) {
361
- if (error instanceof Error) {
362
- this.error("Error while closing node: " + error.message);
363
- done(error);
364
- } else {
365
- this.error("Unknown error occurred while closing node");
366
- done(new Error("Unknown error occurred while closing node"));
367
- }
368
- }
369
- }
370
- );
371
- }
372
- async #closed(removed) {
373
- try {
374
- await Promise.resolve(this.closed?.(removed));
375
- } finally {
376
- this.log("clearing timers and intervals");
377
- this.timers.forEach((t) => clearTimeout(t));
378
- this.intervals.forEach((i) => clearInterval(i));
379
- this.timers.clear();
380
- this.intervals.clear();
381
- this.log("timers and intervals cleared");
382
- }
383
- }
384
- i18n(key, substitutions) {
385
- const nodeType = this.constructor.type;
386
- return this.RED._(`${nodeType}.${key}`, substitutions);
387
- }
388
- setTimeout(fn, ms) {
389
- const timer = setTimeout(() => {
390
- this.timers.delete(timer);
391
- fn();
392
- }, ms);
393
- this.timers.add(timer);
394
- return timer;
395
- }
396
- setInterval(fn, ms) {
397
- const interval = setInterval(fn, ms);
398
- this.intervals.add(interval);
399
- return interval;
400
- }
401
- clearTimeout(timer) {
402
- clearTimeout(timer);
403
- this.timers.delete(timer);
404
- }
405
- clearInterval(interval) {
406
- clearInterval(interval);
407
- this.intervals.delete(interval);
408
- }
409
- on(event, callback) {
410
- this.node.on(event, callback);
411
- }
412
- log(msg) {
413
- this.node.log(msg);
414
- }
415
- warn(message) {
416
- this.node.warn(message);
417
- }
418
- error(message, msg) {
419
- this.node.error(message, msg);
420
- }
421
- get id() {
422
- return this.node.id;
423
- }
424
- get name() {
425
- return this.node.name;
426
- }
427
- get z() {
428
- return this.node.z;
429
- }
430
- get credentials() {
431
- return this.node.credentials;
432
- }
433
- get settings() {
434
- const constructor = this.constructor;
435
- return cachedSettingsMap.get(constructor) ?? {};
436
- }
437
- };
438
-
439
- // src/core/server/nodes/io-node.ts
440
- var RETURN_PROPERTY_PATTERN = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
441
- var INPUT_KEY = "input";
442
- var IONode = class extends Node {
443
- static align;
444
- static color;
445
- static inputSchema;
446
- // outputsSchema accepts any schema shape: the raw sent value (per port) is
447
- // validated, and results are frequently non-objects.
448
- static outputsSchema;
449
- static validateInput = false;
450
- static validateOutput = false;
451
- static get inputs() {
452
- return this.inputSchema ? 1 : 0;
453
- }
454
- static get outputs() {
455
- const s = this.outputsSchema;
456
- if (!s) return 0;
457
- if (Array.isArray(s)) return s.length;
458
- if (isSchemaLike(s)) return 1;
459
- const keys = Object.keys(s);
460
- for (const key of keys) {
461
- if (/^\d+$/.test(key)) {
462
- throw new NrgError(
463
- `outputsSchema record key "${key}" in ${this.type} looks numeric. Use descriptive string names (e.g. "success", "failure") to avoid JavaScript object key ordering issues.`
464
- );
465
- }
466
- if (key === "error" || key === "complete" || key === "status") {
467
- throw new NrgError(
468
- `outputsSchema record key "${key}" in ${this.type} is reserved for built-in ports. Use a different name (e.g. "failed" instead of "error").`
469
- );
470
- }
471
- }
472
- return keys.length;
473
- }
474
- #send;
475
- /**
476
- * Most recent input message — the spread base for output wrapping. Not
477
- * cleared after input() so late async sends merge with the last received
478
- * message.
479
- */
480
- #currentInputMsg;
481
- context;
482
- constructor(RED, node, config, credentials) {
483
- super(RED, node, config, credentials);
484
- const context = node.context();
485
- const fn = (scope, store) => {
486
- const target = scope === "global" ? context.global : scope === "flow" ? context.flow : context;
487
- return setupContext(target, store);
488
- };
489
- fn.node = setupContext(context);
490
- fn.flow = setupContext(context.flow);
491
- fn.global = setupContext(context.global);
492
- this.context = fn;
493
- const outputReturnProperties = this.config.outputReturnProperties;
494
- if (outputReturnProperties) {
495
- for (const [port, key] of Object.entries(outputReturnProperties)) {
496
- if (typeof key === "string" && key.trim() && !RETURN_PROPERTY_PATTERN.test(key.trim())) {
497
- throw new NrgError(
498
- `Invalid return property "${key}" for output port ${port} in ${this.constructor.type} \u2014 it must be a valid JavaScript identifier (letters, digits, _, $; not starting with a digit)`
499
- );
500
- }
501
- }
502
- }
503
- }
504
- [WIRE_HANDLERS](nodeRedNode, createdPromise) {
505
- super[WIRE_HANDLERS](nodeRedNode, createdPromise);
506
- const NC = this.constructor;
507
- nodeRedNode.on(
508
- "input",
509
- async (msg, send, done) => {
510
- try {
511
- await createdPromise;
512
- } catch {
513
- done(new Error("Node failed to initialize"));
514
- return;
515
- }
516
- try {
517
- nodeRedNode.log("Calling input");
518
- this.#currentInputMsg = msg;
519
- await Promise.resolve(this.#input(msg, send));
520
- this.#sendToPort("complete", {
521
- ...msg,
522
- complete: {
523
- source: this.#nodeSource()
524
- },
525
- [INPUT_KEY]: msg
526
- });
527
- done();
528
- nodeRedNode.log("Input processed");
529
- } catch (error) {
530
- const errorMsg = error instanceof Error ? error.message : "Unknown error during input handling";
531
- this.#sendToPort("error", {
532
- ...msg,
533
- error: {
534
- message: errorMsg,
535
- source: this.#nodeSource()
536
- },
537
- [INPUT_KEY]: msg
538
- });
539
- if (error instanceof Error) {
540
- nodeRedNode.error(
541
- "Error while processing input: " + error.message,
542
- msg
543
- );
544
- done(error);
545
- } else {
546
- nodeRedNode.error(
547
- "Unknown error occurred during input handling",
548
- msg
549
- );
550
- done(new Error(errorMsg));
551
- }
552
- }
553
- }
554
- );
555
- }
556
- input(msg) {
557
- }
558
- async #input(msg, send) {
559
- const NodeClass = this.constructor;
560
- const shouldValidateInput = this.config.validateInput ?? NodeClass.validateInput;
561
- if (shouldValidateInput && NodeClass.inputSchema) {
562
- this.log("Validating input");
563
- this.RED.validator.validate(msg, NodeClass.inputSchema, {
564
- cacheKey: NodeClass.inputSchema.$id || `${NodeClass.type}:input-schema`,
565
- throwOnError: true
566
- });
567
- this.log("Input is valid");
568
- }
569
- this.#send = send;
570
- try {
571
- await Promise.resolve(this.input(msg));
572
- } finally {
573
- this.#send = void 0;
574
- }
575
- }
576
- send(msg) {
577
- const sendsValue = this.baseOutputs <= 1;
578
- if (Array.isArray(msg) && !sendsValue) {
579
- const slots = msg.slice(0, this.baseOutputs);
580
- const out = slots.map((m, port) => {
581
- if (m == null) return m;
582
- this.#validatePort(m, port);
583
- return this.#wrapOutgoing(m, this.#resolveContextMode(port), port);
584
- });
585
- this.#deliver(out);
586
- return;
587
- }
588
- if (msg == null) {
589
- this.#deliver(msg);
590
- return;
591
- }
592
- this.#validatePort(msg, 0);
593
- this.#deliver(this.#wrapOutgoing(msg, this.#resolveContextMode(0), 0));
594
- }
595
- #deliver(out) {
596
- if (this.#send) {
597
- this.#send(out);
598
- } else {
599
- this.node.send(out);
600
- }
601
- }
602
- /**
603
- * Per-port output validation. A port validates when its flow-author flag
604
- * (`config.validateOutputs[port]`) — or the node's static `validateOutput`
605
- * fallback — is on and a schema exists for that port.
606
- */
607
- #validatePort(value, port) {
608
- const NodeClass = this.constructor;
609
- const configured = this.config.validateOutputs?.[port];
610
- if (!(configured ?? NodeClass.validateOutput)) return;
611
- const schema = this.#outputSchemaForPort(port);
612
- if (!schema) return;
613
- this.log("Validating output");
614
- this.RED.validator.validate(value, schema, {
615
- cacheKey: schema.$id || `${NodeClass.type}:output-schema:${port}`,
616
- throwOnError: true
617
- });
618
- this.log("Output is valid");
619
- }
620
- /** Resolves the output schema for a base-output port: array → `[port]`,
621
- * record → the port-th value, single schema → itself. */
622
- #outputSchemaForPort(port) {
623
- const raw = this.constructor.outputsSchema;
624
- if (!raw) return void 0;
625
- if (Array.isArray(raw)) return raw[port];
626
- if (isSchemaLike(raw)) return raw;
627
- return Object.values(raw)[port];
628
- }
629
- /**
630
- * The return key for an output port — `"output"` unless a custom one is set
631
- * via `outputReturnProperties[port]` (author default and/or flow-author
632
- * override, only possible when the node declares `outputReturnProperties`).
633
- * `this.send(x)` always means "x is the value at this port's return key",
634
- * never "x is the whole outgoing message".
635
- */
636
- #returnPropertyKey(port) {
637
- const configured = this.config.outputReturnProperties?.[port];
638
- if (typeof configured === "string" && configured.trim()) {
639
- return configured.trim();
640
- }
641
- return "output";
642
- }
643
- /**
644
- * Resolves the context mode for a base-output port from the flow author's
645
- * per-port config (`config.outputContextModes[port]`, written by the editor
646
- * when the node declares `outputContextModes`), falling back to `"carry"`.
647
- */
648
- #resolveContextMode(port) {
649
- return this.config.outputContextModes?.[port] ?? "carry";
650
- }
651
- /**
652
- * Merges a sent value into the incoming message at the returnProperty key so
653
- * upstream message properties propagate. A fresh base is built per call so
654
- * multi-port sends never share an object.
655
- */
656
- #wrapOutgoing(value, mode, port) {
657
- const key = this.#returnPropertyKey(port);
658
- const input = this.#currentInputMsg ?? {};
659
- if (mode === "reset") {
660
- return { [key]: value };
661
- }
662
- if (mode === "trace") {
663
- return { ...input, [key]: value, [INPUT_KEY]: input };
664
- }
665
- return { ...input, [key]: value };
666
- }
667
- // --- Built-in port management ---
668
- get baseOutputs() {
669
- return this.constructor.outputs ?? 0;
670
- }
671
- get totalOutputs() {
672
- const config = this.config;
673
- let count = this.baseOutputs;
674
- if (config.errorPort) count++;
675
- if (config.completePort) count++;
676
- if (config.statusPort) count++;
677
- return count;
678
- }
679
- /**
680
- * Send a message to a specific output port by index or name.
681
- * Custom named ports are resolved from `outputsSchema` when it is a record.
682
- * Numeric indices refer to the base output ports (0-based).
683
- *
684
- * Built-in ports (`"error"`, `"complete"`, `"status"`) are managed by the
685
- * framework and cannot be sent to directly. Use `this.status()` for status,
686
- * throw an error or call `this.error()` for the error port, and the complete
687
- * port is sent automatically on successful input processing.
688
- */
689
- sendToPort(port, msg) {
690
- if (port === "error" || port === "complete" || port === "status") {
691
- throw new NrgError(
692
- `sendToPort("${port}") is not allowed. Built-in ports are managed by the framework.`
693
- );
694
- }
695
- const portIndex = typeof port === "number" ? port : this.#getNamedPortIndex(port);
696
- const mode = this.#resolveContextMode(portIndex ?? 0);
697
- this.#sendToPort(
698
- port,
699
- msg == null ? msg : this.#wrapOutgoing(msg, mode, portIndex ?? 0)
700
- );
701
- }
702
- #sendToPort(port, msg) {
703
- let portIndex;
704
- if (typeof port === "number") {
705
- portIndex = port;
706
- } else if (port === "error" || port === "complete" || port === "status") {
707
- portIndex = this.#getBuiltinPortIndex(port);
708
- if (portIndex === null) return;
709
- } else {
710
- portIndex = this.#getNamedPortIndex(port);
711
- if (portIndex === null) return;
712
- }
713
- const out = new Array(this.totalOutputs);
714
- out[portIndex] = msg;
715
- this.node.send(out);
716
- }
717
- #getNamedPortIndex(name) {
718
- const schema = this.constructor.outputsSchema;
719
- if (!schema || Array.isArray(schema) || isSchemaLike(schema)) return null;
720
- const idx = Object.keys(schema).indexOf(name);
721
- return idx === -1 ? null : idx;
722
- }
723
- #getBuiltinPortIndex(name) {
724
- const config = this.config;
725
- if (name === "error") {
726
- return config.errorPort ? this.baseOutputs : null;
727
- }
728
- let idx = this.baseOutputs;
729
- if (config.errorPort) idx++;
730
- if (name === "complete") {
731
- return config.completePort ? idx : null;
732
- }
733
- if (config.completePort) idx++;
734
- return config.statusPort ? idx : null;
735
- }
736
- #nodeSource() {
737
- return {
738
- id: this.id,
739
- type: this.constructor.type,
740
- name: this.name
741
- };
742
- }
743
- status(status) {
744
- this.node.status(status);
745
- this.#sendToPort("status", {
746
- status,
747
- source: this.#nodeSource()
748
- });
749
- }
750
- error(message, msg) {
751
- super.error(message, msg);
752
- if (msg) {
753
- this.#sendToPort("error", {
754
- ...msg,
755
- error: {
756
- message,
757
- source: this.#nodeSource()
758
- },
759
- [INPUT_KEY]: msg
760
- });
761
- }
762
- }
763
- updateWires(wires) {
764
- this.node.updateWires(wires);
765
- }
766
- receive(msg) {
767
- this.node.receive(msg);
768
- }
769
- get x() {
770
- return this.node.x;
771
- }
772
- get y() {
773
- return this.node.y;
774
- }
775
- get g() {
776
- return this.node.g;
777
- }
778
- get wires() {
779
- return this.node.wires;
780
- }
781
- get credentials() {
782
- return this.node.credentials;
783
- }
784
- };
785
-
786
- // src/core/server/nodes/config-node.ts
787
- var ConfigNode = class extends Node {
788
- static category = "config";
789
- context;
790
- constructor(RED, node, config, credentials) {
791
- super(RED, node, config, credentials);
792
- const context = node.context();
793
- const fn = (scope, store) => {
794
- const target = scope === "global" ? context.global : context;
795
- return setupContext(target, store);
796
- };
797
- fn.node = setupContext(context);
798
- fn.global = setupContext(context.global);
799
- this.context = fn;
800
- }
801
- get userIds() {
802
- return this.config._users;
803
- }
804
- get users() {
805
- return this.userIds.map((id) => this.RED.nodes.getNode(id)?._node).filter((node) => node != null);
806
- }
807
- getUser(index) {
808
- const id = this.userIds[index];
809
- if (!id) return void 0;
810
- return this.RED.nodes.getNode(id)?._node;
811
- }
812
- get credentials() {
813
- return this.node.credentials;
814
- }
815
- };
816
-
817
- // src/core/server/nodes/factories.ts
818
- function defineIONode(def) {
819
- const NodeClass = class extends IONode {
820
- static type = def.type;
821
- static category = def.category ?? "function";
822
- static color = def.color ?? "#a6bbcf";
823
- static align = def.align;
824
- static configSchema = def.configSchema;
825
- static credentialsSchema = def.credentialsSchema;
826
- static settingsSchema = def.settingsSchema;
827
- static inputSchema = def.inputSchema;
828
- static outputsSchema = def.outputsSchema;
829
- static validateInput = def.validateInput ?? false;
830
- static validateOutput = def.validateOutput ?? false;
831
- static registered(RED) {
832
- return def.registered?.(RED);
833
- }
834
- async input(msg) {
835
- if (def.input) return def.input.call(this, msg);
836
- }
837
- async created() {
838
- if (def.created) return def.created.call(this);
839
- }
840
- async closed(removed) {
841
- if (def.closed) return def.closed.call(this, removed);
842
- }
843
- };
844
- Object.defineProperty(NodeClass, "name", {
845
- value: def.type.replace(
846
- /(^|-)(\w)/g,
847
- (_, __, c) => c.toUpperCase()
848
- ),
849
- configurable: true
850
- });
851
- return NodeClass;
852
- }
853
- function defineConfigNode(def) {
854
- const NodeClass = class extends ConfigNode {
855
- static type = def.type;
856
- static configSchema = def.configSchema;
857
- static credentialsSchema = def.credentialsSchema;
858
- static settingsSchema = def.settingsSchema;
859
- static registered(RED) {
860
- return def.registered?.(RED);
861
- }
862
- async created() {
863
- if (def.created) return def.created.call(this);
864
- }
865
- async closed(removed) {
866
- if (def.closed) return def.closed.call(this, removed);
867
- }
868
- };
869
- Object.defineProperty(NodeClass, "name", {
870
- value: def.type.replace(
871
- /(^|-)(\w)/g,
872
- (_, __, c) => c.toUpperCase()
873
- ),
874
- configurable: true
875
- });
876
- return NodeClass;
877
- }
878
-
879
- // src/core/validator.ts
880
- var import_ajv = __toESM(require("ajv"), 1);
881
- var import_ajv_formats = __toESM(require("ajv-formats"), 1);
882
- var import_ajv_errors = __toESM(require("ajv-errors"), 1);
883
- var Validator = class {
884
- ajv;
885
- constructor(options) {
886
- const { customKeywords, customFormats, ...ajvOptions } = options || {};
887
- this.ajv = new import_ajv.default({
888
- allErrors: true,
889
- code: {
890
- source: false
891
- },
892
- coerceTypes: true,
893
- removeAdditional: false,
894
- strict: false,
895
- strictSchema: false,
896
- useDefaults: true,
897
- validateFormats: true,
898
- // NOTE: typebox handles validation via typescript
899
- // NOTE: if true, types that are not serializable JSON, like Function, would not work
900
- validateSchema: false,
901
- verbose: true,
902
- ...ajvOptions
903
- });
904
- (0, import_ajv_formats.default)(this.ajv);
905
- (0, import_ajv_errors.default)(this.ajv);
906
- this.addCustomKeywords(customKeywords || []);
907
- this.addCustomFormats(customFormats || {});
908
- }
909
- /**
910
- * Add custom keywords to the validator
911
- */
912
- addCustomKeywords(keywords) {
913
- if (!keywords) return;
914
- keywords.forEach((keyword) => {
915
- this.ajv.addKeyword(keyword);
916
- });
917
- }
918
- /**
919
- * Add custom formats to the validator
920
- */
921
- addCustomFormats(formats) {
922
- if (!formats) return;
923
- Object.entries(formats).forEach(([name, validator]) => {
924
- if (validator instanceof RegExp) {
925
- this.ajv.addFormat(name, validator);
926
- } else {
927
- this.ajv.addFormat(name, { validate: validator });
928
- }
929
- });
930
- }
931
- /**
932
- * Create a validator function with caching
933
- * @param schema - JSON Schema to validate against
934
- * @param cacheKey - Optional cache key for reusing validators
935
- */
936
- createValidator(schema, cacheKey) {
937
- if (cacheKey && !schema.$id) {
938
- schema.$id = cacheKey;
939
- }
940
- if (schema.$id) {
941
- const cached = this.ajv.getSchema(schema.$id);
942
- if (cached) return cached;
943
- }
944
- const validator = this.ajv.compile(schema);
945
- return validator;
946
- }
947
- /**
948
- * Validate data against a schema and return a structured result
949
- */
950
- validate(data, schema, options) {
951
- const validator = this.createValidator(schema, options?.cacheKey);
952
- const valid = validator(data);
953
- if (!valid) {
954
- const errorMessage = this.formatErrors(validator.errors);
955
- if (options?.throwOnError) {
956
- throw new ValidationError(errorMessage, validator.errors || []);
957
- }
958
- return {
959
- valid: false,
960
- errors: validator.errors || void 0,
961
- errorMessage
962
- };
963
- }
964
- return {
965
- valid: true,
966
- data
967
- };
968
- }
969
- /**
970
- * Format errors into a human-readable string
971
- */
972
- formatErrors(errors, options) {
973
- if (!errors || errors.length === 0) {
974
- return "No errors";
975
- }
976
- return this.ajv.errorsText(errors, {
977
- separator: "; ",
978
- dataVar: "data",
979
- ...options
980
- });
981
- }
982
- /**
983
- * Get detailed error information
984
- */
985
- getDetailedErrors(errors) {
986
- if (!errors || errors.length === 0) return [];
987
- return errors.map((error) => ({
988
- field: error.instancePath || "/",
989
- message: error.message || "Validation failed",
990
- keyword: error.keyword,
991
- params: error.params,
992
- schemaPath: error.schemaPath
993
- }));
994
- }
995
- /**
996
- * Add a schema to the validator for reference
997
- */
998
- addSchema(schema, key) {
999
- this.ajv.addSchema(schema, key);
1000
- return this;
1001
- }
1002
- /**
1003
- * Remove a schema from the validator
1004
- */
1005
- removeSchema(key) {
1006
- this.ajv.removeSchema(key);
1007
- return this;
1008
- }
1009
- };
1010
- var ValidationError = class _ValidationError extends Error {
1011
- constructor(message, errors) {
1012
- super(message);
1013
- this.errors = errors;
1014
- this.name = "ValidationError";
1015
- Object.setPrototypeOf(this, _ValidationError.prototype);
1016
- }
1017
- };
1018
-
1019
- // src/core/server/validation.ts
1020
- function initValidator(RED) {
1021
- if (RED.validator) return;
1022
- const nrg = {
1023
- validator: new Validator({
1024
- customKeywords: [
1025
- {
1026
- keyword: "x-nrg-skip-validation",
1027
- schemaType: "boolean",
1028
- valid: true
1029
- },
1030
- {
1031
- keyword: "x-nrg-node-type",
1032
- type: "string",
1033
- validate: (schemaValue, dataValue) => {
1034
- if (!dataValue) return true;
1035
- const node = RED.nodes.getNode(dataValue);
1036
- return node?.type === schemaValue;
1037
- }
1038
- }
1039
- ],
1040
- customFormats: {
1041
- "node-id": /^[a-zA-Z0-9-_]+$/,
1042
- "flow-id": /^[a-f0-9]{16}$/,
1043
- "topic-path": (data) => /^[a-zA-Z0-9/_-]+$/.test(data)
1044
- }
1045
- })
1046
- };
1047
- Object.defineProperty(RED, "_nrg", {
1048
- value: nrg,
1049
- writable: false,
1050
- enumerable: false,
1051
- configurable: false
1052
- });
1053
- Object.defineProperty(RED, "validator", {
1054
- get: () => nrg.validator,
1055
- enumerable: false,
1056
- configurable: false
1057
- });
1058
- }
1059
-
1060
- // src/core/server/api/assets.ts
1061
- var import_path = __toESM(require("path"), 1);
1062
- var import_fs = __toESM(require("fs"), 1);
1063
- var import_module = require("module");
1064
- function serveFile(filePath) {
1065
- return (_req, res, next) => {
1066
- if (!import_fs.default.existsSync(filePath)) return next();
1067
- res.setHeader("Content-Type", "application/javascript");
1068
- import_fs.default.createReadStream(filePath).pipe(res);
1069
- };
1070
- }
1071
- function initAssetsRoutes(router) {
1072
- const resourcesDir = import_path.default.resolve(__dirname, "./resources");
1073
- if (!import_fs.default.existsSync(resourcesDir)) return;
1074
- const _require = (0, import_module.createRequire)(import_path.default.join(__dirname, "package.json"));
1075
- const vueFile = process.env.NODE_ENV !== "production" ? _require.resolve("vue/dist/vue.esm-browser.js") : _require.resolve("vue/dist/vue.esm-browser.prod.js");
1076
- router.get(
1077
- "/nrg/assets/nrg-client.js",
1078
- serveFile(import_path.default.join(resourcesDir, "nrg-client.js"))
1079
- );
1080
- router.get("/nrg/assets/vue.esm-browser.prod.js", serveFile(vueFile));
1081
- router.get("/nrg/assets/vue.esm-browser.js", serveFile(vueFile));
1082
- }
1083
-
1084
- // src/core/server/api/routes.ts
1085
- var _initialized = false;
1086
- function initRoutes(RED) {
1087
- if (_initialized) return;
1088
- _initialized = true;
1089
- initAssetsRoutes(RED.httpAdmin);
1090
- }
1091
-
1092
- // src/core/server/registration.ts
1093
- async function registerType(RED, NodeClass) {
1094
- RED.log.debug(`Registering Type: ${NodeClass.type}`);
1095
- if (!(NodeClass.prototype instanceof Node)) {
1096
- throw new NrgError(
1097
- `${NodeClass.name} must extend IONode or ConfigNode classes`
1098
- );
1099
- }
1100
- if (!NodeClass.type) {
1101
- throw new NrgError("type must be provided when registering the node");
1102
- }
1103
- await NodeClass.register(RED);
1104
- RED.log.debug(`Type registered: ${NodeClass.type}`);
1105
- }
1106
- function registerTypes(nodes) {
1107
- const fn = Object.assign(
1108
- async function(RED) {
1109
- initValidator(RED);
1110
- initRoutes(RED);
1111
- try {
1112
- RED.log.info("Registering node types in series");
1113
- for (const NodeClass of nodes) {
1114
- await registerType(RED, NodeClass);
1115
- }
1116
- RED.log.info("All node types registered in series");
1117
- } catch (error) {
1118
- RED.log.error("Error registering node types:", error);
1119
- throw error;
1120
- }
1121
- },
1122
- { nodes }
1123
- );
1124
- return fn;
1125
- }
1126
-
1127
- // src/core/constants.ts
1128
- var TYPED_INPUT_TYPES = [
1129
- "msg",
1130
- "flow",
1131
- "global",
1132
- "str",
1133
- "num",
1134
- "bool",
1135
- "json",
1136
- "bin",
1137
- "re",
1138
- "jsonata",
1139
- "date",
1140
- "env",
1141
- "node",
1142
- "cred"
1143
- ];
1144
-
1145
- // src/core/server/schemas/type.ts
1146
- var import_typebox2 = require("@sinclair/typebox");
1147
- var import_rules = require("ajv/dist/compile/rules");
1148
- function NodeRef(nodeClass, options) {
1149
- return {
1150
- ...import_typebox2.Type.String({
1151
- description: options?.description || `Reference to ${nodeClass.type}`,
1152
- format: "node-id"
1153
- }),
1154
- "x-nrg-node-type": nodeClass.type,
1155
- ...options,
1156
- [import_typebox2.Kind]: "NodeRef"
1157
- };
1158
- }
1159
- function TypedInput2(options) {
1160
- return {
1161
- ...TypedInputSchema,
1162
- "x-nrg-typed-input": true,
1163
- ...options,
1164
- [import_typebox2.Kind]: "TypedInput"
1165
- };
1166
- }
1167
- function OutputReturnProperties(options) {
1168
- return import_typebox2.Type.Record(
1169
- import_typebox2.Type.Number(),
1170
- import_typebox2.Type.String({ pattern: "^[A-Za-z_$][A-Za-z0-9_$]*$" }),
1171
- {
1172
- description: "Per-port return property, keyed by output port index. A missing entry falls back to `output`.",
1173
- default: {},
1174
- ...options
1175
- }
1176
- );
1177
- }
1178
- function OutputContextModes(options) {
1179
- return import_typebox2.Type.Record(
1180
- import_typebox2.Type.Number(),
1181
- import_typebox2.Type.Union([
1182
- import_typebox2.Type.Literal("carry"),
1183
- import_typebox2.Type.Literal("trace"),
1184
- import_typebox2.Type.Literal("reset")
1185
- ]),
1186
- {
1187
- description: "Per-port context mode, keyed by output port index. A missing entry falls back to `carry`.",
1188
- default: {},
1189
- ...options
1190
- }
1191
- );
1192
- }
1193
- var SchemaType = Object.assign({}, import_typebox2.Type, {
1194
- NodeRef,
1195
- TypedInput: TypedInput2,
1196
- OutputReturnProperties,
1197
- OutputContextModes
1198
- });
1199
- function markNonValidatable(schema) {
1200
- const type = schema.type;
1201
- const hasInvalidType = type !== void 0 && (Array.isArray(type) ? !type.every(import_rules.isJSONType) : !(0, import_rules.isJSONType)(type));
1202
- if (hasInvalidType) {
1203
- schema["x-nrg-skip-validation"] = true;
1204
- if (schema.default !== void 0) {
1205
- schema._default = schema.default;
1206
- delete schema.default;
1207
- }
1208
- delete schema.type;
1209
- }
1210
- if (schema.properties) {
1211
- for (const prop of Object.values(schema.properties)) {
1212
- markNonValidatable(prop);
1213
- }
1214
- }
1215
- if (schema.items) {
1216
- markNonValidatable(schema.items);
1217
- }
1218
- if (schema.anyOf) {
1219
- schema.anyOf.forEach((s) => markNonValidatable(s));
1220
- }
1221
- if (schema.allOf) {
1222
- schema.allOf.forEach((s) => markNonValidatable(s));
1223
- }
1224
- if (schema.oneOf) {
1225
- schema.oneOf.forEach((s) => markNonValidatable(s));
1226
- }
1227
- return schema;
1228
- }
1229
- function defineSchema(properties, options) {
1230
- const schema = SchemaType.Object(properties, options);
1231
- return markNonValidatable(schema);
1232
- }
1233
-
1234
- // src/core/server/schemas/base.ts
1235
- var NodeConfigSchema = SchemaType.Object({
1236
- id: SchemaType.String(),
1237
- type: SchemaType.String(),
1238
- name: SchemaType.String(),
1239
- z: SchemaType.Optional(SchemaType.String())
1240
- });
1241
- var ConfigNodeConfigSchema = SchemaType.Object({
1242
- ...NodeConfigSchema.properties,
1243
- _users: SchemaType.Array(SchemaType.String())
1244
- });
1245
- var IONodeConfigSchema = SchemaType.Object({
1246
- ...NodeConfigSchema.properties,
1247
- wires: SchemaType.Array(
1248
- SchemaType.Array(SchemaType.String(), { default: [] }),
1249
- {
1250
- default: [[]]
1251
- }
1252
- ),
1253
- x: SchemaType.Number(),
1254
- y: SchemaType.Number(),
1255
- g: SchemaType.Optional(SchemaType.String())
1256
- });
1257
- var TypedInputSchema = SchemaType.Object(
1258
- {
1259
- value: SchemaType.Union(
1260
- [
1261
- SchemaType.String(),
1262
- SchemaType.Number(),
1263
- SchemaType.Boolean(),
1264
- SchemaType.Null()
1265
- ],
1266
- {
1267
- description: "The actual value entered or selected.",
1268
- default: ""
1269
- }
1270
- ),
1271
- type: SchemaType.Union(
1272
- TYPED_INPUT_TYPES.map((type) => SchemaType.Literal(type)),
1273
- {
1274
- description: "The type of the value (string, number, message property, etc.)",
1275
- default: "str"
1276
- }
1277
- )
1278
- },
1279
- {
1280
- description: "Represents a Node-RED TypedInput value and its type.",
1281
- default: {
1282
- type: "str",
1283
- value: ""
1284
- }
1285
- }
1286
- );
1287
- var NodeSourceSchema = SchemaType.Object({
1288
- id: SchemaType.String(),
1289
- type: SchemaType.String(),
1290
- name: SchemaType.String()
1291
- });
1292
- var ErrorPortSchema = SchemaType.Object({
1293
- error: SchemaType.Object({
1294
- message: SchemaType.String(),
1295
- source: NodeSourceSchema
1296
- })
1297
- });
1298
- var CompletePortSchema = SchemaType.Object({
1299
- complete: SchemaType.Object({
1300
- source: NodeSourceSchema
1301
- })
1302
- });
1303
- var StatusPortSchema = SchemaType.Object({
1304
- status: SchemaType.Union([
1305
- SchemaType.Object({
1306
- fill: SchemaType.Optional(
1307
- SchemaType.Union([
1308
- SchemaType.Literal("red"),
1309
- SchemaType.Literal("green")
1310
- ])
1311
- ),
1312
- shape: SchemaType.Optional(
1313
- SchemaType.Union([
1314
- SchemaType.Literal("dot"),
1315
- SchemaType.Literal("string")
1316
- ])
1317
- ),
1318
- text: SchemaType.Optional(SchemaType.String())
1319
- }),
1320
- SchemaType.String()
1321
- ]),
1322
- source: NodeSourceSchema
1323
- });
1324
-
1325
- // src/core/server/index.ts
1326
- function defineModule(definition) {
1327
- return definition;
1328
- }
1329
- // Annotate the CommonJS export names for ESM import in node:
1330
- 0 && (module.exports = {
1331
- CompletePortSchema,
1332
- ConfigNode,
1333
- ErrorPortSchema,
1334
- IONode,
1335
- Node,
1336
- NodeSourceSchema,
1337
- NrgError,
1338
- SchemaType,
1339
- StatusPortSchema,
1340
- defineConfigNode,
1341
- defineIONode,
1342
- defineModule,
1343
- defineSchema,
1344
- registerType,
1345
- registerTypes
1346
- });
1
+ 'use strict';
2
+ module.exports = require("@bonsae/nrg-runtime/server");