@vortexm/vjt 0.1.3 → 0.1.4

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/dist/index.js CHANGED
@@ -3682,6 +3682,16 @@ function logRuntimeError(scope, error, details) {
3682
3682
  }
3683
3683
  console.error("[VJT error]", payload);
3684
3684
  }
3685
+ function logRuntimeDebug(enabled, scope, payload) {
3686
+ if (!enabled) {
3687
+ return;
3688
+ }
3689
+ if (payload === void 0) {
3690
+ console.log("[VJT debug]", scope);
3691
+ return;
3692
+ }
3693
+ console.log("[VJT debug]", scope, payload);
3694
+ }
3685
3695
 
3686
3696
  // src/lib/security.ts
3687
3697
  var BLOCKED_OBJECT_KEYS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
@@ -3838,6 +3848,7 @@ function sanitizeSchemaValue(schema, value, path = "value") {
3838
3848
 
3839
3849
  // src/lib/network.ts
3840
3850
  var NetworkRuntime = class {
3851
+ debugLogging;
3841
3852
  requestsMap;
3842
3853
  sseConfigs;
3843
3854
  backendUrl;
@@ -3845,6 +3856,7 @@ var NetworkRuntime = class {
3845
3856
  runActions;
3846
3857
  rerenderRoot;
3847
3858
  constructor(options) {
3859
+ this.debugLogging = options.debugLogging;
3848
3860
  this.requestsMap = options.requestsMap;
3849
3861
  this.sseConfigs = options.sseConfigs;
3850
3862
  this.backendUrl = options.backendUrl;
@@ -3907,12 +3919,19 @@ var NetworkRuntime = class {
3907
3919
  if (!safeRequestUrl) {
3908
3920
  throw new Error(`Request ${requestName} has unsafe url`);
3909
3921
  }
3922
+ const requestBody = JSON.stringify(requestEnvelope);
3923
+ logRuntimeDebug(this.debugLogging, "request", {
3924
+ requestName,
3925
+ url: safeRequestUrl,
3926
+ envelope: requestEnvelope,
3927
+ body: requestBody
3928
+ });
3910
3929
  const response = await fetch(safeRequestUrl, {
3911
3930
  method: "POST",
3912
3931
  headers: {
3913
3932
  "Content-Type": "application/json"
3914
3933
  },
3915
- body: JSON.stringify(requestEnvelope)
3934
+ body: requestBody
3916
3935
  });
3917
3936
  const responseText = await response.text();
3918
3937
  if (!response.ok) {
@@ -3928,12 +3947,19 @@ var NetworkRuntime = class {
3928
3947
  throw new Error(`Request ${requestName} returned non-JSON response: ${responseText.slice(0, 120)}`);
3929
3948
  }
3930
3949
  if (json.error) {
3931
- throw new Error(`Request ${requestName} returned JSON-RPC error: ${String(json.error.message ?? "unknown error")}`);
3950
+ throw new Error(`Request ${requestName} returned JSON-RPC error: ${this.stringifyPrimitive(json.error.message ?? "unknown error")}`);
3932
3951
  }
3933
3952
  if (!definition.response) {
3934
3953
  throw new Error(`Request ${requestName} must define response schema`);
3935
3954
  }
3936
3955
  const result = sanitizeSchemaValue(definition.response, json.result, `response.${requestName}`);
3956
+ logRuntimeDebug(this.debugLogging, "response", {
3957
+ requestName,
3958
+ url: safeRequestUrl,
3959
+ status: response.status,
3960
+ json,
3961
+ result
3962
+ });
3937
3963
  if (definition.onResponse?.length) {
3938
3964
  await this.runActions(definition.onResponse, null, {
3939
3965
  currentValue: null,
@@ -4011,6 +4037,12 @@ var NetworkRuntime = class {
4011
4037
  const message = eventDefinition.message ? sanitizeSchemaValue(eventDefinition.message, parsedMessage, `sse.${eventDefinition.name}`) : (() => {
4012
4038
  throw new Error(`SSE event ${eventDefinition.name} must define message schema`);
4013
4039
  })();
4040
+ logRuntimeDebug(this.debugLogging, "sse", {
4041
+ eventName: eventDefinition.name,
4042
+ raw: event.data,
4043
+ parsedMessage,
4044
+ message
4045
+ });
4014
4046
  if (!eventDefinition.onEvent?.length) {
4015
4047
  return;
4016
4048
  }
@@ -4452,6 +4484,7 @@ var ReferenceRuntime = class {
4452
4484
 
4453
4485
  // src/lib/action-runtime.ts
4454
4486
  var ActionRuntime = class {
4487
+ debugLogging;
4455
4488
  actionsMap;
4456
4489
  actionFunctions;
4457
4490
  nodeById;
@@ -4476,6 +4509,7 @@ var ActionRuntime = class {
4476
4509
  getInlineActions;
4477
4510
  isWidgetEnabled;
4478
4511
  constructor(options) {
4512
+ this.debugLogging = options.debugLogging;
4479
4513
  this.actionsMap = options.actionsMap;
4480
4514
  this.actionFunctions = options.actionFunctions;
4481
4515
  this.nodeById = options.nodeById;
@@ -4531,30 +4565,55 @@ var ActionRuntime = class {
4531
4565
  return this.getInlineActions(node);
4532
4566
  }
4533
4567
  async runSingleAction(action, inputValue, context) {
4534
- let output = await this.executeAction(action, inputValue, context);
4535
- if (action.andThen?.length) {
4536
- if (Array.isArray(output)) {
4537
- const collected = [];
4538
- for (const entry of output) {
4539
- if (entry === null || entry === void 0) {
4540
- continue;
4541
- }
4542
- const nestedOutput = await this.runActions(action.andThen, entry, { ...context, currentValue: entry });
4543
- if (nestedOutput !== null && nestedOutput !== void 0) {
4544
- collected.push(nestedOutput);
4568
+ const actionName = action.action.trim();
4569
+ try {
4570
+ let output = await this.executeAction(action, inputValue, context);
4571
+ if (action.andThen?.length) {
4572
+ if (Array.isArray(output)) {
4573
+ const collected = [];
4574
+ for (const entry of output) {
4575
+ if (entry === null || entry === void 0) {
4576
+ continue;
4577
+ }
4578
+ const nestedOutput = await this.runActions(action.andThen, entry, { ...context, currentValue: entry });
4579
+ if (nestedOutput !== null && nestedOutput !== void 0) {
4580
+ collected.push(nestedOutput);
4581
+ }
4545
4582
  }
4583
+ output = collected;
4584
+ } else if (output !== null && output !== void 0) {
4585
+ output = await this.runActions(action.andThen, output, { ...context, currentValue: output });
4586
+ } else {
4587
+ output = null;
4546
4588
  }
4547
- output = collected;
4548
- } else if (output !== null && output !== void 0) {
4549
- output = await this.runActions(action.andThen, output, { ...context, currentValue: output });
4550
- } else {
4551
- output = null;
4552
4589
  }
4590
+ logRuntimeDebug(this.debugLogging, "action-result", {
4591
+ action: actionName,
4592
+ output
4593
+ });
4594
+ return output;
4595
+ } catch (error) {
4596
+ logRuntimeError("action", error, {
4597
+ action: actionName,
4598
+ args: action.args,
4599
+ inputValue,
4600
+ currentValue: context.currentValue,
4601
+ responseValue: context.responseValue,
4602
+ pointer: context.pointer ?? null
4603
+ });
4604
+ throw error;
4553
4605
  }
4554
- return output;
4555
4606
  }
4556
4607
  async executeAction(action, inputValue, context) {
4557
4608
  const name = action.action.trim();
4609
+ logRuntimeDebug(this.debugLogging, "action", {
4610
+ action: name,
4611
+ args: action.args,
4612
+ inputValue,
4613
+ currentValue: context.currentValue,
4614
+ responseValue: context.responseValue,
4615
+ pointer: context.pointer ?? null
4616
+ });
4558
4617
  if (this.actionsMap[name]) {
4559
4618
  return this.runActions(this.actionsMap[name], inputValue, context);
4560
4619
  }
@@ -6112,6 +6171,7 @@ var RuntimeRenderer = class {
6112
6171
  systemEvents;
6113
6172
  resourceManager;
6114
6173
  actionFunctions;
6174
+ debugLogging;
6115
6175
  backendUrl;
6116
6176
  initialRuntimeSnapshot;
6117
6177
  onRuntimeSnapshot;
@@ -6152,6 +6212,7 @@ var RuntimeRenderer = class {
6152
6212
  this.sseConfigs = Array.isArray(resolvedSseConfigs) ? resolvedSseConfigs : resolvedSseConfigs ? [resolvedSseConfigs] : [];
6153
6213
  this.systemEvents = options.systemEvents ?? this.resourceManager?.getSystemEvents() ?? {};
6154
6214
  this.actionFunctions = options.actionFunctions ?? {};
6215
+ this.debugLogging = options.debugLogging === true;
6155
6216
  this.backendUrl = options.backendUrl;
6156
6217
  this.initialRuntimeSnapshot = options.runtimeSnapshot ? deepClone(options.runtimeSnapshot) : null;
6157
6218
  this.onRuntimeSnapshot = options.onRuntimeSnapshot;
@@ -6199,6 +6260,7 @@ var RuntimeRenderer = class {
6199
6260
  indexListElementNodes: (listNode, element, index) => this.indexListElementNodes(listNode, element, index)
6200
6261
  });
6201
6262
  this.networkRuntime = new NetworkRuntime({
6263
+ debugLogging: this.debugLogging,
6202
6264
  requestsMap: this.requestsMap,
6203
6265
  sseConfigs: this.sseConfigs,
6204
6266
  backendUrl: this.backendUrl,
@@ -6207,6 +6269,7 @@ var RuntimeRenderer = class {
6207
6269
  rerenderRoot: () => this.rerenderRoot()
6208
6270
  });
6209
6271
  this.actionRuntime = new ActionRuntime({
6272
+ debugLogging: this.debugLogging,
6210
6273
  actionsMap: this.actionsMap,
6211
6274
  actionFunctions: this.actionFunctions,
6212
6275
  nodeById: this.nodeById,
@@ -6252,7 +6315,9 @@ var RuntimeRenderer = class {
6252
6315
  this.applyRuntimeSnapshot(this.initialRuntimeSnapshot);
6253
6316
  }
6254
6317
  renderMarkup() {
6255
- return `${this.renderNode(this.description, "root", null)}${this.renderGlobalOverlays()}`;
6318
+ const markup = `${this.renderNode(this.description, "root", null)}${this.renderGlobalOverlays()}`;
6319
+ logRuntimeDebug(this.debugLogging, "html", markup);
6320
+ return markup;
6256
6321
  }
6257
6322
  mount(root, options = {}) {
6258
6323
  if (!(root instanceof HTMLElement)) {
@@ -8,6 +8,7 @@ export type ActionExecutionContext = {
8
8
  } | null;
9
9
  };
10
10
  type ActionRuntimeOptions = {
11
+ debugLogging: boolean;
11
12
  actionsMap: ActionMap;
12
13
  actionFunctions: Record<string, () => unknown>;
13
14
  nodeById: Map<string, DescriptionNode>;
@@ -48,6 +49,7 @@ type ActionRuntimeOptions = {
48
49
  isWidgetEnabled: (node: DescriptionNode, key: string) => boolean;
49
50
  };
50
51
  export declare class ActionRuntime {
52
+ private readonly debugLogging;
51
53
  private readonly actionsMap;
52
54
  private readonly actionFunctions;
53
55
  private readonly nodeById;
@@ -1 +1,2 @@
1
1
  export declare function logRuntimeError(scope: string, error: unknown, details?: Record<string, unknown>): void;
2
+ export declare function logRuntimeDebug(enabled: boolean, scope: string, payload?: unknown): void;
@@ -4,6 +4,7 @@ type ActionRunner = (actions: ActionDefinition[], inputValue: unknown, context:
4
4
  responseValue?: unknown;
5
5
  }) => Promise<unknown>;
6
6
  type NetworkRuntimeOptions = {
7
+ debugLogging: boolean;
7
8
  requestsMap: RequestMap;
8
9
  sseConfigs: SseConfig[];
9
10
  backendUrl?: string;
@@ -12,6 +13,7 @@ type NetworkRuntimeOptions = {
12
13
  rerenderRoot: () => Promise<void>;
13
14
  };
14
15
  export declare class NetworkRuntime {
16
+ private readonly debugLogging;
15
17
  private readonly requestsMap;
16
18
  private readonly sseConfigs;
17
19
  private readonly backendUrl?;
@@ -132,6 +132,7 @@ export type RenderJsonOptions = {
132
132
  i18n?: I18nMap;
133
133
  language?: string;
134
134
  theme?: Theme;
135
+ debugLogging?: boolean;
135
136
  actionsMap?: ActionMap;
136
137
  requestsMap?: RequestMap;
137
138
  sseConfigs?: SseConfigInput;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vortexm/vjt",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",