@riddledc/riddle-proof 0.7.159 → 0.7.161
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/README.md +15 -5
- package/dist/{chunk-TBTMD5WV.js → chunk-ZE2U5EML.js} +274 -12
- package/dist/cli.cjs +326 -20
- package/dist/cli.js +53 -9
- package/dist/index.cjs +274 -12
- package/dist/index.js +1 -1
- package/dist/profile.cjs +274 -12
- package/dist/profile.d.cts +3 -1
- package/dist/profile.d.ts +3 -1
- package/dist/profile.js +1 -1
- package/dist/proof-run-engine.d.cts +3 -3
- package/dist/proof-run-engine.d.ts +3 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -8782,6 +8782,7 @@ var RIDDLE_PROOF_PROFILE_SETUP_ACTION_TYPES = [
|
|
|
8782
8782
|
"fill",
|
|
8783
8783
|
"set_input_value",
|
|
8784
8784
|
"set_range_value",
|
|
8785
|
+
"canvas_signature",
|
|
8785
8786
|
"assert_text_visible",
|
|
8786
8787
|
"assert_text_absent",
|
|
8787
8788
|
"assert_selector_count",
|
|
@@ -9283,6 +9284,26 @@ function profileSetupRangeValueReceipts(results) {
|
|
|
9283
9284
|
reason: result.reason ?? result.error ?? null
|
|
9284
9285
|
}));
|
|
9285
9286
|
}
|
|
9287
|
+
function profileSetupCanvasSignatureReceipts(results) {
|
|
9288
|
+
return results.filter((result) => profileSetupResultAction(result) === "canvas_signature").map((result) => ({
|
|
9289
|
+
ordinal: result.ordinal ?? null,
|
|
9290
|
+
ok: result.ok !== false,
|
|
9291
|
+
selector: result.selector ?? null,
|
|
9292
|
+
frame_selector: result.frame_selector ?? null,
|
|
9293
|
+
label: result.label ?? null,
|
|
9294
|
+
hash: result.hash ?? null,
|
|
9295
|
+
data_length: result.data_length ?? null,
|
|
9296
|
+
width: result.width ?? null,
|
|
9297
|
+
height: result.height ?? null,
|
|
9298
|
+
css_width: result.css_width ?? null,
|
|
9299
|
+
css_height: result.css_height ?? null,
|
|
9300
|
+
compare_to: result.compare_to ?? null,
|
|
9301
|
+
previous_hash: result.previous_hash ?? null,
|
|
9302
|
+
changed: result.changed ?? null,
|
|
9303
|
+
return_stored_to: result.return_stored_to ?? null,
|
|
9304
|
+
reason: result.reason ?? result.error ?? null
|
|
9305
|
+
}));
|
|
9306
|
+
}
|
|
9286
9307
|
function sampleProfileSetupSummaryItems(items, limit) {
|
|
9287
9308
|
if (items.length <= limit) return items;
|
|
9288
9309
|
const firstCount = Math.floor(limit / 2);
|
|
@@ -9327,6 +9348,8 @@ function profileSetupSummary(viewports, actionCount, expectedActionCountByViewpo
|
|
|
9327
9348
|
const sampledWindowEvalReceipts = sampleProfileSetupSummaryItems(windowEvalReceipts, 8);
|
|
9328
9349
|
const rangeValueReceipts = profileSetupRangeValueReceipts(results);
|
|
9329
9350
|
const sampledRangeValueReceipts = sampleProfileSetupSummaryItems(rangeValueReceipts, 8);
|
|
9351
|
+
const canvasSignatureReceipts = profileSetupCanvasSignatureReceipts(results);
|
|
9352
|
+
const sampledCanvasSignatureReceipts = sampleProfileSetupSummaryItems(canvasSignatureReceipts, 8);
|
|
9330
9353
|
const clickedItems = results.filter((result) => profileSetupResultAction(result) === "click" && result.ok !== false).map((result) => {
|
|
9331
9354
|
const clickCount = typeof result.click_count === "number" && Number.isFinite(result.click_count) && result.click_count > 1 ? result.click_count : void 0;
|
|
9332
9355
|
return {
|
|
@@ -9378,6 +9401,9 @@ function profileSetupSummary(viewports, actionCount, expectedActionCountByViewpo
|
|
|
9378
9401
|
set_range_value_total: rangeValueReceipts.length,
|
|
9379
9402
|
set_range_value_truncated: rangeValueReceipts.length > sampledRangeValueReceipts.length,
|
|
9380
9403
|
set_range_value: sampledRangeValueReceipts,
|
|
9404
|
+
canvas_signature_total: canvasSignatureReceipts.length,
|
|
9405
|
+
canvas_signature_truncated: canvasSignatureReceipts.length > sampledCanvasSignatureReceipts.length,
|
|
9406
|
+
canvas_signature: sampledCanvasSignatureReceipts,
|
|
9381
9407
|
clicked,
|
|
9382
9408
|
text_samples,
|
|
9383
9409
|
failed: failed.map((result) => ({
|
|
@@ -9430,7 +9456,7 @@ function isSupportedCheckType(value) {
|
|
|
9430
9456
|
}
|
|
9431
9457
|
function normalizeSetupActionType(value, index) {
|
|
9432
9458
|
const normalizedInput = String(value || "").trim().replace(/-/g, "_");
|
|
9433
|
-
const normalized = normalizedInput === "clear_browser_storage" ? "clear_storage" : normalizedInput === "reset_console" || normalizedInput === "clear_browser_console" || normalizedInput === "reset_browser_console" ? "clear_console" : normalizedInput === "pointer_drag" || normalizedInput === "mouse_drag" || normalizedInput === "drag_to" ? "drag" : normalizedInput === "keyboard_press" || normalizedInput === "key_press" ? "press" : normalizedInput === "set_slider_value" || normalizedInput === "slider_value" || normalizedInput === "set_slider" || normalizedInput === "set_range" || normalizedInput === "range_value" || normalizedInput === "range_input" || normalizedInput === "set_range_input" ? "set_range_value" : normalizedInput === "capture_screenshot" || normalizedInput === "save_screenshot" || normalizedInput === "setup_screenshot" ? "screenshot" : normalizedInput === "accept_dialog" || normalizedInput === "accept_dialogs" || normalizedInput === "confirm_dialog" || normalizedInput === "set_dialog_response" ? "dialog_response" : normalizedInput === "dismiss_dialog" || normalizedInput === "dismiss_dialogs" || normalizedInput === "cancel_dialog" ? "dialog_response" : normalizedInput === "window_call_until" || normalizedInput === "call_until" || normalizedInput === "window_call_repeat_until" || normalizedInput === "repeat_window_call_until" ? "window_call_until" : normalizedInput === "window_evaluate" || normalizedInput === "browser_eval" || normalizedInput === "browser_evaluate" || normalizedInput === "evaluate_script" || normalizedInput === "profile_script" ? "window_eval" : normalizedInput;
|
|
9459
|
+
const normalized = normalizedInput === "clear_browser_storage" ? "clear_storage" : normalizedInput === "reset_console" || normalizedInput === "clear_browser_console" || normalizedInput === "reset_browser_console" ? "clear_console" : normalizedInput === "pointer_drag" || normalizedInput === "mouse_drag" || normalizedInput === "drag_to" ? "drag" : normalizedInput === "keyboard_press" || normalizedInput === "key_press" ? "press" : normalizedInput === "set_slider_value" || normalizedInput === "slider_value" || normalizedInput === "set_slider" || normalizedInput === "set_range" || normalizedInput === "range_value" || normalizedInput === "range_input" || normalizedInput === "set_range_input" ? "set_range_value" : normalizedInput === "canvas_hash" || normalizedInput === "capture_canvas_hash" || normalizedInput === "capture_canvas_signature" || normalizedInput === "canvas_state_signature" ? "canvas_signature" : normalizedInput === "capture_screenshot" || normalizedInput === "save_screenshot" || normalizedInput === "setup_screenshot" ? "screenshot" : normalizedInput === "accept_dialog" || normalizedInput === "accept_dialogs" || normalizedInput === "confirm_dialog" || normalizedInput === "set_dialog_response" ? "dialog_response" : normalizedInput === "dismiss_dialog" || normalizedInput === "dismiss_dialogs" || normalizedInput === "cancel_dialog" ? "dialog_response" : normalizedInput === "window_call_until" || normalizedInput === "call_until" || normalizedInput === "window_call_repeat_until" || normalizedInput === "repeat_window_call_until" ? "window_call_until" : normalizedInput === "window_evaluate" || normalizedInput === "browser_eval" || normalizedInput === "browser_evaluate" || normalizedInput === "evaluate_script" || normalizedInput === "profile_script" ? "window_eval" : normalizedInput;
|
|
9434
9460
|
if (RIDDLE_PROOF_PROFILE_SETUP_ACTION_TYPES.includes(normalized)) {
|
|
9435
9461
|
return normalized;
|
|
9436
9462
|
}
|
|
@@ -9559,7 +9585,7 @@ function normalizeSetupAction(input, index) {
|
|
|
9559
9585
|
if (frameIndex !== void 0 && (!Number.isInteger(frameIndex) || frameIndex < 0)) {
|
|
9560
9586
|
throw new Error(`target.setup_actions[${index}].frame_index must be a non-negative integer.`);
|
|
9561
9587
|
}
|
|
9562
|
-
if ((type === "click" || type === "drag" || type === "fill" || type === "set_input_value" || type === "set_range_value" || type === "wait_for_selector" || type === "wait_for_text" || type === "assert_text_visible" || type === "assert_text_absent" || type === "assert_selector_count") && !selector) {
|
|
9588
|
+
if ((type === "click" || type === "drag" || type === "fill" || type === "set_input_value" || type === "set_range_value" || type === "canvas_signature" || type === "wait_for_selector" || type === "wait_for_text" || type === "assert_text_visible" || type === "assert_text_absent" || type === "assert_selector_count") && !selector) {
|
|
9563
9589
|
throw new Error(`target.setup_actions[${index}] ${type} requires selector.`);
|
|
9564
9590
|
}
|
|
9565
9591
|
const fromX = numberValue3(valueFromOwn(input, "from_x", "fromX", "start_x", "startX", "x1"));
|
|
@@ -9653,7 +9679,11 @@ function normalizeSetupAction(input, index) {
|
|
|
9653
9679
|
"assign_return_to",
|
|
9654
9680
|
"assignReturnTo",
|
|
9655
9681
|
"return_state_path",
|
|
9656
|
-
"returnStatePath"
|
|
9682
|
+
"returnStatePath",
|
|
9683
|
+
"store_signature_to",
|
|
9684
|
+
"storeSignatureTo",
|
|
9685
|
+
"signature_path",
|
|
9686
|
+
"signaturePath"
|
|
9657
9687
|
);
|
|
9658
9688
|
const captureReturn = input.capture_return === false || input.captureReturn === false || input.include_return === false || input.includeReturn === false || input.omit_return === true || input.omitReturn === true ? false : void 0;
|
|
9659
9689
|
const untilPath = stringFromOwn(input, "until_path", "untilPath", "until_state_path", "untilStatePath", "until_window_path", "untilWindowPath", "until");
|
|
@@ -9705,6 +9735,8 @@ function normalizeSetupAction(input, index) {
|
|
|
9705
9735
|
store_return_to: storeReturnTo,
|
|
9706
9736
|
capture_return: captureReturn,
|
|
9707
9737
|
return_summary_fields: normalizeReturnSummaryFields(input, index),
|
|
9738
|
+
compare_to: stringFromOwn(input, "compare_to", "compareTo", "previous_signature_path", "previousSignaturePath", "previous_path", "previousPath", "changed_from", "changedFrom"),
|
|
9739
|
+
expect_changed: booleanValue(valueFromOwn(input, "expect_changed", "expectChanged", "should_change", "shouldChange", "changed")),
|
|
9708
9740
|
until_path: untilPath,
|
|
9709
9741
|
until_expected_value: hasUntilExpectedValue ? toJsonValue(valueFromOwn(input, "until_expected_value", "untilExpectedValue", "until_expected", "untilExpected", "until_value", "untilValue", "expected_value", "expectedValue", "expected")) : void 0,
|
|
9710
9742
|
max_calls: maxCalls,
|
|
@@ -12831,6 +12863,28 @@ function profileSetupRangeValueReceipts(results) {
|
|
|
12831
12863
|
reason: result.reason || result.error || null,
|
|
12832
12864
|
}));
|
|
12833
12865
|
}
|
|
12866
|
+
function profileSetupCanvasSignatureReceipts(results) {
|
|
12867
|
+
return (results || [])
|
|
12868
|
+
.filter((result) => result && profileSetupResultAction(result) === "canvas_signature")
|
|
12869
|
+
.map((result) => ({
|
|
12870
|
+
ordinal: result.ordinal ?? null,
|
|
12871
|
+
ok: result.ok !== false,
|
|
12872
|
+
selector: result.selector ?? null,
|
|
12873
|
+
frame_selector: result.frame_selector ?? null,
|
|
12874
|
+
label: result.label ?? null,
|
|
12875
|
+
hash: result.hash ?? null,
|
|
12876
|
+
data_length: result.data_length ?? null,
|
|
12877
|
+
width: result.width ?? null,
|
|
12878
|
+
height: result.height ?? null,
|
|
12879
|
+
css_width: result.css_width ?? null,
|
|
12880
|
+
css_height: result.css_height ?? null,
|
|
12881
|
+
compare_to: result.compare_to ?? null,
|
|
12882
|
+
previous_hash: result.previous_hash ?? null,
|
|
12883
|
+
changed: result.changed ?? null,
|
|
12884
|
+
return_stored_to: result.return_stored_to ?? null,
|
|
12885
|
+
reason: result.reason || result.error || null,
|
|
12886
|
+
}));
|
|
12887
|
+
}
|
|
12834
12888
|
function sampleProfileSetupSummaryItems(items, limit) {
|
|
12835
12889
|
if ((items || []).length <= limit) return items || [];
|
|
12836
12890
|
const firstCount = Math.floor(limit / 2);
|
|
@@ -12889,6 +12943,8 @@ function profileSetupSummary(viewports, actionCount, expectedActionCountsByViewp
|
|
|
12889
12943
|
const sampledWindowEvalReceipts = sampleProfileSetupSummaryItems(windowEvalReceipts, 8);
|
|
12890
12944
|
const rangeValueReceipts = profileSetupRangeValueReceipts(results);
|
|
12891
12945
|
const sampledRangeValueReceipts = sampleProfileSetupSummaryItems(rangeValueReceipts, 8);
|
|
12946
|
+
const canvasSignatureReceipts = profileSetupCanvasSignatureReceipts(results);
|
|
12947
|
+
const sampledCanvasSignatureReceipts = sampleProfileSetupSummaryItems(canvasSignatureReceipts, 8);
|
|
12892
12948
|
const clickedItems = results
|
|
12893
12949
|
.filter((result) => result && profileSetupResultAction(result) === "click" && result.ok !== false)
|
|
12894
12950
|
.map((result) => {
|
|
@@ -12950,6 +13006,9 @@ function profileSetupSummary(viewports, actionCount, expectedActionCountsByViewp
|
|
|
12950
13006
|
set_range_value_total: rangeValueReceipts.length,
|
|
12951
13007
|
set_range_value_truncated: rangeValueReceipts.length > sampledRangeValueReceipts.length,
|
|
12952
13008
|
set_range_value: sampledRangeValueReceipts,
|
|
13009
|
+
canvas_signature_total: canvasSignatureReceipts.length,
|
|
13010
|
+
canvas_signature_truncated: canvasSignatureReceipts.length > sampledCanvasSignatureReceipts.length,
|
|
13011
|
+
canvas_signature: sampledCanvasSignatureReceipts,
|
|
12953
13012
|
clicked,
|
|
12954
13013
|
text_samples: textSamples,
|
|
12955
13014
|
failed: failed.map((result) => ({
|
|
@@ -14424,6 +14483,54 @@ async function executeSetupAction(action, ordinal, viewport) {
|
|
|
14424
14483
|
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
14425
14484
|
const rect = element.getBoundingClientRect();
|
|
14426
14485
|
const pointerId = payload.pointerType === "touch" ? 11 : 12;
|
|
14486
|
+
const capturedPointers = new Set();
|
|
14487
|
+
const originalOwnSetPointerCapture = Object.getOwnPropertyDescriptor(element, "setPointerCapture");
|
|
14488
|
+
const originalOwnReleasePointerCapture = Object.getOwnPropertyDescriptor(element, "releasePointerCapture");
|
|
14489
|
+
const originalOwnHasPointerCapture = Object.getOwnPropertyDescriptor(element, "hasPointerCapture");
|
|
14490
|
+
const originalSetPointerCapture = typeof element.setPointerCapture === "function" ? element.setPointerCapture.bind(element) : undefined;
|
|
14491
|
+
const originalReleasePointerCapture = typeof element.releasePointerCapture === "function" ? element.releasePointerCapture.bind(element) : undefined;
|
|
14492
|
+
const originalHasPointerCapture = typeof element.hasPointerCapture === "function" ? element.hasPointerCapture.bind(element) : undefined;
|
|
14493
|
+
const restorePointerCapture = () => {
|
|
14494
|
+
if (originalOwnSetPointerCapture) Object.defineProperty(element, "setPointerCapture", originalOwnSetPointerCapture);
|
|
14495
|
+
else delete (element as any).setPointerCapture;
|
|
14496
|
+
if (originalOwnReleasePointerCapture) Object.defineProperty(element, "releasePointerCapture", originalOwnReleasePointerCapture);
|
|
14497
|
+
else delete (element as any).releasePointerCapture;
|
|
14498
|
+
if (originalOwnHasPointerCapture) Object.defineProperty(element, "hasPointerCapture", originalOwnHasPointerCapture);
|
|
14499
|
+
else delete (element as any).hasPointerCapture;
|
|
14500
|
+
};
|
|
14501
|
+
Object.defineProperty(element, "setPointerCapture", {
|
|
14502
|
+
configurable: true,
|
|
14503
|
+
value: (activePointerId) => {
|
|
14504
|
+
capturedPointers.add(activePointerId);
|
|
14505
|
+
try {
|
|
14506
|
+
return originalSetPointerCapture?.(activePointerId);
|
|
14507
|
+
} catch {
|
|
14508
|
+
return undefined;
|
|
14509
|
+
}
|
|
14510
|
+
},
|
|
14511
|
+
});
|
|
14512
|
+
Object.defineProperty(element, "releasePointerCapture", {
|
|
14513
|
+
configurable: true,
|
|
14514
|
+
value: (activePointerId) => {
|
|
14515
|
+
capturedPointers.delete(activePointerId);
|
|
14516
|
+
try {
|
|
14517
|
+
return originalReleasePointerCapture?.(activePointerId);
|
|
14518
|
+
} catch {
|
|
14519
|
+
return undefined;
|
|
14520
|
+
}
|
|
14521
|
+
},
|
|
14522
|
+
});
|
|
14523
|
+
Object.defineProperty(element, "hasPointerCapture", {
|
|
14524
|
+
configurable: true,
|
|
14525
|
+
value: (activePointerId) => {
|
|
14526
|
+
if (capturedPointers.has(activePointerId)) return true;
|
|
14527
|
+
try {
|
|
14528
|
+
return Boolean(originalHasPointerCapture?.(activePointerId));
|
|
14529
|
+
} catch {
|
|
14530
|
+
return false;
|
|
14531
|
+
}
|
|
14532
|
+
},
|
|
14533
|
+
});
|
|
14427
14534
|
const point = (progress) => ({
|
|
14428
14535
|
clientX: rect.left + payload.start.x + (payload.end.x - payload.start.x) * progress,
|
|
14429
14536
|
clientY: rect.top + payload.start.y + (payload.end.y - payload.start.y) * progress,
|
|
@@ -14443,16 +14550,20 @@ async function executeSetupAction(action, ordinal, viewport) {
|
|
|
14443
14550
|
clientY: coords.clientY,
|
|
14444
14551
|
}));
|
|
14445
14552
|
};
|
|
14446
|
-
|
|
14447
|
-
|
|
14448
|
-
|
|
14449
|
-
|
|
14450
|
-
|
|
14451
|
-
|
|
14553
|
+
try {
|
|
14554
|
+
dispatch("pointerover", 0);
|
|
14555
|
+
dispatch("pointerenter", 0);
|
|
14556
|
+
dispatch("pointerdown", 0);
|
|
14557
|
+
for (let step = 1; step <= payload.steps; step += 1) {
|
|
14558
|
+
dispatch("pointermove", step / payload.steps);
|
|
14559
|
+
if (payload.durationMs && payload.steps > 1) await wait(payload.durationMs / payload.steps);
|
|
14560
|
+
}
|
|
14561
|
+
dispatch("pointerup", 1);
|
|
14562
|
+
dispatch("pointerout", 1);
|
|
14563
|
+
dispatch("pointerleave", 1);
|
|
14564
|
+
} finally {
|
|
14565
|
+
restorePointerCapture();
|
|
14452
14566
|
}
|
|
14453
|
-
dispatch("pointerup", 1);
|
|
14454
|
-
dispatch("pointerout", 1);
|
|
14455
|
-
dispatch("pointerleave", 1);
|
|
14456
14567
|
}, {
|
|
14457
14568
|
pointerType,
|
|
14458
14569
|
start: localStart,
|
|
@@ -14492,6 +14603,7 @@ async function executeSetupAction(action, ordinal, viewport) {
|
|
|
14492
14603
|
to_x: toX,
|
|
14493
14604
|
to_y: toY,
|
|
14494
14605
|
pointer_type: pointerType,
|
|
14606
|
+
pointer_capture_polyfill: pointerType === "touch" || pointerType === "pen" ? true : undefined,
|
|
14495
14607
|
steps,
|
|
14496
14608
|
duration_ms: durationMs || undefined,
|
|
14497
14609
|
};
|
|
@@ -14965,6 +15077,156 @@ async function executeSetupAction(action, ordinal, viewport) {
|
|
|
14965
15077
|
reason: rangeResult && rangeResult.ok === true ? undefined : rangeResult?.reason || "range_value_not_set",
|
|
14966
15078
|
};
|
|
14967
15079
|
}
|
|
15080
|
+
if (type === "canvas_signature") {
|
|
15081
|
+
const scope = await setupActionScope(action, timeout);
|
|
15082
|
+
if (!scope.ok) return setupScopeFailure(base, scope);
|
|
15083
|
+
const locator = scope.context.locator(action.selector);
|
|
15084
|
+
const count = await locator.count();
|
|
15085
|
+
if (!count) return { ...base, ...setupScopeEvidence(scope), reason: "selector_not_found", count };
|
|
15086
|
+
const targetIndex = Number.isInteger(action.index) ? action.index : 0;
|
|
15087
|
+
if (targetIndex < 0 || targetIndex >= count) return { ...base, ...setupScopeEvidence(scope), reason: "index_out_of_range", count, target_index: targetIndex };
|
|
15088
|
+
const target = locator.nth(targetIndex);
|
|
15089
|
+
await target.waitFor({ state: "visible", timeout });
|
|
15090
|
+
const storeReturnTo = String(action.store_return_to || action.storeReturnTo || action.save_return_to || action.saveReturnTo || action.store_signature_to || action.storeSignatureTo || action.signature_path || action.signaturePath || "").trim();
|
|
15091
|
+
const compareTo = String(action.compare_to || action.compareTo || action.previous_signature_path || action.previousSignaturePath || action.previous_path || action.previousPath || action.changed_from || action.changedFrom || "").trim();
|
|
15092
|
+
const expectChanged = action.expect_changed === true || action.expectChanged === true || action.should_change === true || action.shouldChange === true || action.changed === true
|
|
15093
|
+
? true
|
|
15094
|
+
: action.expect_changed === false || action.expectChanged === false || action.should_change === false || action.shouldChange === false || action.changed === false
|
|
15095
|
+
? false
|
|
15096
|
+
: undefined;
|
|
15097
|
+
const signatureResult = await target.evaluate((element, payload) => {
|
|
15098
|
+
const toJsonValue = (value) => {
|
|
15099
|
+
if (value === null || value === undefined) return null;
|
|
15100
|
+
if (typeof value === "string" || typeof value === "boolean") return value;
|
|
15101
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : null;
|
|
15102
|
+
if (Array.isArray(value)) return value.map(toJsonValue);
|
|
15103
|
+
if (typeof value === "object") {
|
|
15104
|
+
return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, toJsonValue(child)]));
|
|
15105
|
+
}
|
|
15106
|
+
return String(value);
|
|
15107
|
+
};
|
|
15108
|
+
const pathParts = (path) => String(path || "").split(".").map((part) => part.trim()).filter(Boolean);
|
|
15109
|
+
const readWindowPath = (path) => {
|
|
15110
|
+
const parts = pathParts(path);
|
|
15111
|
+
if (parts[0] === "window") parts.shift();
|
|
15112
|
+
if (!parts.length) return { ok: false, reason: "missing_path" };
|
|
15113
|
+
let current = window;
|
|
15114
|
+
for (const part of parts) {
|
|
15115
|
+
if (current === null || current === undefined) return { ok: false, reason: "path_not_found", missing_part: part };
|
|
15116
|
+
current = current[part];
|
|
15117
|
+
if (current === undefined) return { ok: false, reason: "path_not_found", missing_part: part };
|
|
15118
|
+
}
|
|
15119
|
+
return { ok: true, value: toJsonValue(current) };
|
|
15120
|
+
};
|
|
15121
|
+
const storeWindowValue = (path, value) => {
|
|
15122
|
+
const parts = pathParts(path);
|
|
15123
|
+
if (parts[0] === "window") parts.shift();
|
|
15124
|
+
if (!parts.length) return { ok: false, reason: "missing_store_path" };
|
|
15125
|
+
let target = window;
|
|
15126
|
+
for (let index = 0; index < parts.length - 1; index += 1) {
|
|
15127
|
+
const part = parts[index];
|
|
15128
|
+
if (target[part] === null || typeof target[part] !== "object") target[part] = {};
|
|
15129
|
+
target = target[part];
|
|
15130
|
+
}
|
|
15131
|
+
target[parts[parts.length - 1]] = value;
|
|
15132
|
+
return { ok: true, path: parts.join(".") };
|
|
15133
|
+
};
|
|
15134
|
+
const hashText = (text) => {
|
|
15135
|
+
let hash = 2166136261;
|
|
15136
|
+
const step = Math.max(1, Math.floor((text.length || 1) / 4000));
|
|
15137
|
+
for (let index = 0; index < text.length; index += step) {
|
|
15138
|
+
hash ^= text.charCodeAt(index);
|
|
15139
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
15140
|
+
}
|
|
15141
|
+
return String(hash);
|
|
15142
|
+
};
|
|
15143
|
+
const tag = String(element && element.tagName ? element.tagName : "").toLowerCase();
|
|
15144
|
+
if (tag !== "canvas") return { ok: false, reason: "not_canvas_element", tag };
|
|
15145
|
+
const rect = element.getBoundingClientRect();
|
|
15146
|
+
let data = "";
|
|
15147
|
+
try {
|
|
15148
|
+
data = element.toDataURL("image/png");
|
|
15149
|
+
} catch (error) {
|
|
15150
|
+
return {
|
|
15151
|
+
ok: false,
|
|
15152
|
+
reason: "canvas_read_failed",
|
|
15153
|
+
error: String(error && error.message ? error.message : error).slice(0, 1000),
|
|
15154
|
+
width: element.width || 0,
|
|
15155
|
+
height: element.height || 0,
|
|
15156
|
+
css_width: Math.round(rect.width || 0),
|
|
15157
|
+
css_height: Math.round(rect.height || 0),
|
|
15158
|
+
};
|
|
15159
|
+
}
|
|
15160
|
+
const result = {
|
|
15161
|
+
ok: Boolean(element.width > 0 && element.height > 0 && data.length > 0),
|
|
15162
|
+
reason: element.width > 0 && element.height > 0 && data.length > 0 ? undefined : "empty_canvas_signature",
|
|
15163
|
+
hash: hashText(data),
|
|
15164
|
+
data_length: data.length,
|
|
15165
|
+
width: element.width || 0,
|
|
15166
|
+
height: element.height || 0,
|
|
15167
|
+
css_width: Math.round(rect.width || 0),
|
|
15168
|
+
css_height: Math.round(rect.height || 0),
|
|
15169
|
+
compare_to: payload.compareTo || undefined,
|
|
15170
|
+
previous_hash: null,
|
|
15171
|
+
changed: null,
|
|
15172
|
+
};
|
|
15173
|
+
if (payload.compareTo) {
|
|
15174
|
+
const previous = readWindowPath(payload.compareTo);
|
|
15175
|
+
if (!previous.ok) {
|
|
15176
|
+
result.ok = false;
|
|
15177
|
+
result.reason = previous.reason || "compare_path_not_found";
|
|
15178
|
+
result.missing_part = previous.missing_part || undefined;
|
|
15179
|
+
} else {
|
|
15180
|
+
const previousValue = previous.value;
|
|
15181
|
+
const previousHash = previousValue && typeof previousValue === "object" && !Array.isArray(previousValue)
|
|
15182
|
+
? previousValue.hash || previousValue.signature || previousValue.canvas_hash || null
|
|
15183
|
+
: typeof previousValue === "string"
|
|
15184
|
+
? previousValue
|
|
15185
|
+
: null;
|
|
15186
|
+
result.previous_hash = previousHash === null || previousHash === undefined ? null : String(previousHash);
|
|
15187
|
+
result.changed = result.previous_hash === null ? null : result.previous_hash !== result.hash;
|
|
15188
|
+
if (payload.expectChanged === true && result.changed !== true) {
|
|
15189
|
+
result.ok = false;
|
|
15190
|
+
result.reason = "canvas_signature_unchanged";
|
|
15191
|
+
} else if (payload.expectChanged === false && result.changed !== false) {
|
|
15192
|
+
result.ok = false;
|
|
15193
|
+
result.reason = "canvas_signature_changed";
|
|
15194
|
+
}
|
|
15195
|
+
}
|
|
15196
|
+
}
|
|
15197
|
+
if (payload.storeReturnTo) {
|
|
15198
|
+
const stored = storeWindowValue(payload.storeReturnTo, result);
|
|
15199
|
+
if (!stored.ok) {
|
|
15200
|
+
return { ...result, ok: false, reason: "signature_store_failed", store_reason: stored.reason };
|
|
15201
|
+
}
|
|
15202
|
+
return { ...result, return_stored_to: stored.path };
|
|
15203
|
+
}
|
|
15204
|
+
return result;
|
|
15205
|
+
}, { compareTo, expectChanged, storeReturnTo });
|
|
15206
|
+
return {
|
|
15207
|
+
...base,
|
|
15208
|
+
...setupScopeEvidence(scope),
|
|
15209
|
+
ok: signatureResult && signatureResult.ok === true,
|
|
15210
|
+
count,
|
|
15211
|
+
target_index: targetIndex,
|
|
15212
|
+
label: action.label || action.name || undefined,
|
|
15213
|
+
hash: signatureResult?.hash,
|
|
15214
|
+
data_length: signatureResult?.data_length,
|
|
15215
|
+
width: signatureResult?.width,
|
|
15216
|
+
height: signatureResult?.height,
|
|
15217
|
+
css_width: signatureResult?.css_width,
|
|
15218
|
+
css_height: signatureResult?.css_height,
|
|
15219
|
+
compare_to: signatureResult?.compare_to || compareTo || undefined,
|
|
15220
|
+
previous_hash: signatureResult?.previous_hash,
|
|
15221
|
+
changed: signatureResult?.changed,
|
|
15222
|
+
return_stored_to: signatureResult?.return_stored_to || storeReturnTo || undefined,
|
|
15223
|
+
missing_part: signatureResult?.missing_part || undefined,
|
|
15224
|
+
store_reason: signatureResult?.store_reason || undefined,
|
|
15225
|
+
tag: signatureResult?.tag,
|
|
15226
|
+
reason: signatureResult && signatureResult.ok === true ? undefined : signatureResult?.reason || "canvas_signature_failed",
|
|
15227
|
+
error: signatureResult?.error || undefined,
|
|
15228
|
+
};
|
|
15229
|
+
}
|
|
14968
15230
|
if (type === "assert_selector_count") {
|
|
14969
15231
|
const scope = await setupActionScope(action, timeout);
|
|
14970
15232
|
if (!scope.ok) return setupScopeFailure(base, scope);
|
package/dist/index.js
CHANGED
|
@@ -62,7 +62,7 @@ import {
|
|
|
62
62
|
resolveRiddleProofProfileTimeoutSec,
|
|
63
63
|
slugifyRiddleProofProfileName,
|
|
64
64
|
summarizeRiddleProofProfileResult
|
|
65
|
-
} from "./chunk-
|
|
65
|
+
} from "./chunk-ZE2U5EML.js";
|
|
66
66
|
import {
|
|
67
67
|
DEFAULT_RIDDLE_API_BASE_URL,
|
|
68
68
|
DEFAULT_RIDDLE_API_KEY_FILE,
|