@qontinui/ui-bridge-wrapper 0.7.0 → 0.7.2

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.
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- var url = require('url');
5
4
  var module$1 = require('module');
6
5
  var fs = require('fs');
7
6
  var ui_bridge_cli_args_star = require('@qontinui/ui-bridge-cli-args');
@@ -31,6 +30,12 @@ var __defProp = Object.defineProperty;
31
30
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
32
31
  var __getOwnPropNames = Object.getOwnPropertyNames;
33
32
  var __hasOwnProp = Object.prototype.hasOwnProperty;
33
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
34
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
35
+ }) : x)(function(x) {
36
+ if (typeof require !== "undefined") return require.apply(this, arguments);
37
+ throw Error('Dynamic require of "' + x + '" is not supported');
38
+ });
34
39
  var __copyProps = (to, from, except, desc) => {
35
40
  if (from && typeof from === "object" || typeof from === "function") {
36
41
  for (let key of __getOwnPropNames(from))
@@ -853,6 +858,42 @@ function createTransport(config) {
853
858
  var cli_args_exports = {};
854
859
  __reExport(cli_args_exports, ui_bridge_cli_args_star__namespace);
855
860
 
861
+ // src/action-outcome.ts
862
+ var RETURNED_FAILURE_CODE = "ACTION_FAILED";
863
+ function isRecord(v) {
864
+ return typeof v === "object" && v !== null && !Array.isArray(v);
865
+ }
866
+ function nonEmptyString(v) {
867
+ return typeof v === "string" && v.length > 0 ? v : null;
868
+ }
869
+ function isReturnedFailure(result) {
870
+ return isRecord(result) && result.success === false;
871
+ }
872
+ function returnedFailureError(action, result) {
873
+ if (!isReturnedFailure(result)) return null;
874
+ const r = result;
875
+ const failureDetails = isRecord(r.failureDetails) ? r.failureDetails : null;
876
+ const errorObj = isRecord(r.error) ? r.error : null;
877
+ const code = nonEmptyString(failureDetails?.errorCode) ?? nonEmptyString(errorObj?.code) ?? RETURNED_FAILURE_CODE;
878
+ const message = nonEmptyString(r.error) ?? nonEmptyString(errorObj?.message) ?? nonEmptyString(failureDetails?.message) ?? `action '${action}' reported success: false`;
879
+ const details = failureDetails ?? errorObj ?? void 0;
880
+ const out = { code, message, source: "returned" };
881
+ if (details !== void 0) out.details = details;
882
+ return out;
883
+ }
884
+ function thrownError(err) {
885
+ if (err instanceof WrapperTransportError) {
886
+ const out = { code: err.code, message: err.message, source: "thrown" };
887
+ if (err.details !== void 0) out.details = err.details;
888
+ return out;
889
+ }
890
+ return {
891
+ code: "UNKNOWN",
892
+ message: err instanceof Error ? err.message : String(err),
893
+ source: "thrown"
894
+ };
895
+ }
896
+
856
897
  // src/inject-cli.ts
857
898
  var USAGE = `ui-bridge-inject \u2014 drive UI Bridge's injected transport against a UI-Bridge-free page
858
899
 
@@ -878,6 +919,28 @@ Exec (Variant A \u2014 one-shot; presence of any --exec/--exec-stdin selects thi
878
919
  --exec-stdin Read NDJSON lines from stdin; each line is
879
920
  {"action":"...","payload":{...}}
880
921
 
922
+ Exec output & exit code:
923
+ One JSON line per action, in order, on stdout \u2014 ALWAYS one line per action,
924
+ including failures. An action that succeeded prints {"action":..,"result":..}.
925
+ An action that FAILED additionally carries an "error" key:
926
+ {"action":..,"result":..,"error":{"code":..,"message":..,"source":"returned",
927
+ "details":{..}}}
928
+ A failure is EITHER thrown by the transport (source "thrown") OR returned by
929
+ the in-page handler as {"success":false,...} (source "returned") \u2014 a missing,
930
+ invisible or disabled element is the RETURNED kind, so "result" alone never
931
+ tells you whether the action did anything. Branch on "error"; "error.code" is
932
+ the handler's own errorCode (ELEMENT_NOT_FOUND / ELEMENT_NOT_VISIBLE /
933
+ ELEMENT_NOT_ENABLED / ...) and "error.details" is its full failureDetails,
934
+ unflattened.
935
+
936
+ A failed action does NOT abort the actions after it. Every action runs, each
937
+ gets its line, and the process exits 1 at the end if ANY action failed (0 if
938
+ all succeeded). This is the pre-existing behaviour of a thrown failure, kept
939
+ for a returned one so there is one convention rather than two \u2014 and it is
940
+ what keeps the one-line-per-action contract intact for a caller that pairs
941
+ N actions with N lines. A caller that wants stop-on-first-failure gets it by
942
+ running one action per invocation and checking the exit code.
943
+
881
944
  Optional:
882
945
  --storage-state <path> Seed the browser context from a Playwright storageState
883
946
  JSON file (cookies + localStorage) produced by
@@ -1314,22 +1377,18 @@ async function runExec(args, transport) {
1314
1377
  }
1315
1378
  try {
1316
1379
  const result = await transport.dispatch(action, payload);
1317
- process.stdout.write(`${JSON.stringify({ action, result })}
1318
- `);
1380
+ const returnedError = returnedFailureError(action, result);
1381
+ if (returnedError) anyError = true;
1382
+ process.stdout.write(
1383
+ `${JSON.stringify(
1384
+ returnedError ? { action, result, error: returnedError } : { action, result }
1385
+ )}
1386
+ `
1387
+ );
1319
1388
  } catch (err) {
1320
1389
  anyError = true;
1321
- if (err instanceof WrapperTransportError) {
1322
- process.stdout.write(
1323
- `${JSON.stringify({ action, error: { code: err.code, message: err.message } })}
1324
- `
1325
- );
1326
- } else {
1327
- const message = err instanceof Error ? err.message : String(err);
1328
- process.stdout.write(
1329
- `${JSON.stringify({ action, error: { code: "UNKNOWN", message } })}
1330
- `
1331
- );
1332
- }
1390
+ process.stdout.write(`${JSON.stringify({ action, error: thrownError(err) })}
1391
+ `);
1333
1392
  }
1334
1393
  }
1335
1394
  } finally {
@@ -1386,13 +1445,7 @@ async function runRelay(args, transport) {
1386
1445
  void shutdown("SIGTERM", 143);
1387
1446
  });
1388
1447
  }
1389
- var isMain = (() => {
1390
- try {
1391
- return process.argv[1] === url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('inject-cli.cjs', document.baseURI).href)));
1392
- } catch {
1393
- return false;
1394
- }
1395
- })();
1448
+ var isMain = typeof __require !== "undefined" && typeof module !== "undefined" && __require.main === module;
1396
1449
  if (isMain) {
1397
1450
  void main().catch((err) => {
1398
1451
  const msg = err instanceof Error ? err.message : String(err);