@qontinui/ui-bridge-wrapper 0.7.1 → 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.
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Classify the outcome of a UI Bridge action for a CLI's error channel.
3
+ *
4
+ * WHY THIS EXISTS
5
+ *
6
+ * The in-page dispatcher reserves `throw` for a handful of cases (an unknown
7
+ * action id, mostly) and *returns* a structured failure for everything a
8
+ * caller actually hits — a missing element, an invisible one, a disabled one.
9
+ * `createActionFailure` (packages/ui-bridge/src/react/commandHandlers.ts)
10
+ * builds that envelope:
11
+ *
12
+ * { success: false, error: "Element x not found",
13
+ * failureDetails: { errorCode: "ELEMENT_NOT_FOUND", ... } }
14
+ *
15
+ * and `InjectedContext.execute` hands it back verbatim
16
+ * (src/transports/injected.ts). So a CLI that keys failure off `catch` alone
17
+ * prints that object as a *result* and exits 0: the caller reads the documented
18
+ * error channel, sees nothing, and reports a clean run for a page the action
19
+ * never changed. Measured on 0.7.1 — `ui-bridge-inject --exec
20
+ * 'executeElementAction {"id":"no-such-element",...}'` printed the
21
+ * ELEMENT_NOT_FOUND envelope under `result` and exited 0. A consumer that
22
+ * scripts a click and then snapshots gets a successful-looking run in which the
23
+ * click never happened.
24
+ *
25
+ * This module is the one place that answers "did that action actually do what
26
+ * it was asked?", so every bin gives the same answer. It invents no envelope:
27
+ * `{ success: false, error, failureDetails }` is already the repo-wide shape
28
+ * for a returned failure, and `{ code, message }` is already what the CLIs put
29
+ * on their `error` key for a thrown one.
30
+ */
31
+ /**
32
+ * The CLI-level error envelope written to an output line's `error` key.
33
+ *
34
+ * `details` carries the handler's own structured diagnostics UNFLATTENED — the
35
+ * whole `failureDetails` object for a returned failure, `WrapperTransportError.details`
36
+ * for a thrown one — so a caller can still branch on `ELEMENT_NOT_FOUND` vs
37
+ * `ELEMENT_NOT_VISIBLE` vs `ELEMENT_NOT_ENABLED`, read `retryRecommended`, or
38
+ * follow `suggestedActions` instead of parsing a message string.
39
+ */
40
+ export interface CliActionError {
41
+ /** Machine-readable code — `failureDetails.errorCode` where the handler set one. */
42
+ code: string;
43
+ message: string;
44
+ /** How the failure reached us: the handler returned it, or it was thrown. */
45
+ source: 'returned' | 'thrown';
46
+ /** The handler's structured diagnostics, verbatim. Omitted when there are none. */
47
+ details?: unknown;
48
+ }
49
+ /** Fallback code for a returned failure that named none of its own. */
50
+ export declare const RETURNED_FAILURE_CODE = "ACTION_FAILED";
51
+ /**
52
+ * True when `result` is a handler result that reports its own failure.
53
+ *
54
+ * The predicate is deliberately narrow — an explicit `success === false` — so
55
+ * it cannot misread a result that merely *lacks* a `success` field (a control
56
+ * snapshot, a find result, an element state) as a failure. That is the same
57
+ * signal every returned-failure site in the SDK sets; see the ~190 `success:
58
+ * false` returns across packages/ui-bridge/src.
59
+ */
60
+ export declare function isReturnedFailure(result: unknown): boolean;
61
+ /**
62
+ * Map a *returned* failure onto the CLI error envelope, or `null` when the
63
+ * result is not a failure at all (the overwhelmingly common case — this runs on
64
+ * every successful action too, so it stays cheap and total).
65
+ *
66
+ * `action` is used only to build a last-resort message for a handler that
67
+ * returned `{ success: false }` and nothing else.
68
+ */
69
+ export declare function returnedFailureError(action: string, result: unknown): CliActionError | null;
70
+ /** Map a *thrown* error onto the same envelope. */
71
+ export declare function thrownError(err: unknown): CliActionError;
72
+ //# sourceMappingURL=action-outcome.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-outcome.d.ts","sourceRoot":"","sources":["../src/action-outcome.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAIH;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAc;IAC7B,oFAAoF;IACpF,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,6EAA6E;IAC7E,MAAM,EAAE,UAAU,GAAG,QAAQ,CAAC;IAC9B,mFAAmF;IACnF,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,uEAAuE;AACvE,eAAO,MAAM,qBAAqB,kBAAkB,CAAC;AAUrD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAE1D;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,cAAc,GAAG,IAAI,CAyB3F;AAED,mDAAmD;AACnD,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,cAAc,CAcxD"}
@@ -3,7 +3,6 @@
3
3
 
4
4
  var fs = require('fs');
5
5
  var path = require('path');
6
- var url = require('url');
7
6
  var module$1 = require('module');
8
7
  var ui_bridge_cli_args_star = require('@qontinui/ui-bridge-cli-args');
9
8
 
@@ -36,6 +35,12 @@ var __defProp = Object.defineProperty;
36
35
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
37
36
  var __getOwnPropNames = Object.getOwnPropertyNames;
38
37
  var __hasOwnProp = Object.prototype.hasOwnProperty;
38
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
39
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
40
+ }) : x)(function(x) {
41
+ if (typeof require !== "undefined") return require.apply(this, arguments);
42
+ throw Error('Dynamic require of "' + x + '" is not supported');
43
+ });
39
44
  var __copyProps = (to, from, except, desc) => {
40
45
  if (from && typeof from === "object" || typeof from === "function") {
41
46
  for (let key of __getOwnPropNames(from))
@@ -984,6 +989,30 @@ async function loginDrive(page, { email, password, timeoutMs, log = () => {
984
989
  return { ok, finalUrl, landingPath, errorText };
985
990
  }
986
991
 
992
+ // src/action-outcome.ts
993
+ var RETURNED_FAILURE_CODE = "ACTION_FAILED";
994
+ function isRecord(v) {
995
+ return typeof v === "object" && v !== null && !Array.isArray(v);
996
+ }
997
+ function nonEmptyString(v) {
998
+ return typeof v === "string" && v.length > 0 ? v : null;
999
+ }
1000
+ function isReturnedFailure(result) {
1001
+ return isRecord(result) && result.success === false;
1002
+ }
1003
+ function returnedFailureError(action, result) {
1004
+ if (!isReturnedFailure(result)) return null;
1005
+ const r = result;
1006
+ const failureDetails = isRecord(r.failureDetails) ? r.failureDetails : null;
1007
+ const errorObj = isRecord(r.error) ? r.error : null;
1008
+ const code = nonEmptyString(failureDetails?.errorCode) ?? nonEmptyString(errorObj?.code) ?? RETURNED_FAILURE_CODE;
1009
+ const message = nonEmptyString(r.error) ?? nonEmptyString(errorObj?.message) ?? nonEmptyString(failureDetails?.message) ?? `action '${action}' reported success: false`;
1010
+ const details = failureDetails ?? errorObj ?? void 0;
1011
+ const out = { code, message, source: "returned" };
1012
+ if (details !== void 0) out.details = details;
1013
+ return out;
1014
+ }
1015
+
987
1016
  // src/capture-specs-cli.ts
988
1017
  var USAGE = `ui-bridge-capture-specs \u2014 log in and snapshot authed pages via the injected transport
989
1018
 
@@ -993,7 +1022,7 @@ Required (one of):
993
1022
 
994
1023
  Options:
995
1024
  --out <dir> Output dir for <slug>.snapshot.json files
996
- (default D:/qontinui-root/spec-capture).
1025
+ (default ./spec-capture, relative to cwd).
997
1026
  --origin <url> App origin (default https://qontinui.io).
998
1027
  --pages "slug=path,slug=path" Pages to capture (paths joined to --origin;
999
1028
  absolute http(s) URLs used verbatim). Default =
@@ -1010,7 +1039,7 @@ or set PLAYWRIGHT_BROWSERS_PATH).
1010
1039
 
1011
1040
  Exits non-zero if any capture bounced to login or errored.
1012
1041
  `;
1013
- var DEFAULT_OUT = "D:/qontinui-root/spec-capture";
1042
+ var DEFAULT_OUT = "spec-capture";
1014
1043
  var DEFAULT_ORIGIN = "https://qontinui.io";
1015
1044
  var DEFAULT_DEVICE = "c79a07d5-7e40-49b4-87fa-554c749f9644";
1016
1045
  var CaptureCliArgError = class extends Error {
@@ -1151,7 +1180,10 @@ ${USAGE}`);
1151
1180
  let snap = null;
1152
1181
  let err = null;
1153
1182
  try {
1154
- snap = await ctx.snapshot();
1183
+ const raw = await ctx.snapshot();
1184
+ const failure = returnedFailureError("getControlSnapshot", raw);
1185
+ if (failure) err = `${failure.code}: ${failure.message}`;
1186
+ else snap = raw;
1155
1187
  } catch (e) {
1156
1188
  err = e instanceof Error ? e.message : String(e);
1157
1189
  }
@@ -1205,13 +1237,7 @@ ${USAGE}`);
1205
1237
  }
1206
1238
  process.exit(code);
1207
1239
  }
1208
- var isMain = (() => {
1209
- try {
1210
- return process.argv[1] === url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('capture-specs-cli.cjs', document.baseURI).href)));
1211
- } catch {
1212
- return false;
1213
- }
1214
- })();
1240
+ var isMain = typeof __require !== "undefined" && typeof module !== "undefined" && __require.main === module;
1215
1241
  if (isMain) {
1216
1242
  void main().catch((err) => {
1217
1243
  const msg = err instanceof Error ? err.message : String(err);