@apilift/cli 1.8.14 → 1.8.15-dev.1794699960.e4e1a04acda82805b3c1010b7c04db2ff20dddcd
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.
|
@@ -19945,6 +19945,7 @@ var CaptureError = class extends Error {
|
|
|
19945
19945
|
var json3 = (value) => JSON.stringify(value);
|
|
19946
19946
|
var readJson = (value) => JSON.parse(String(value));
|
|
19947
19947
|
var scopeTtl = { inspect: 3e4, execute: 12e4, capture: 72e5 };
|
|
19948
|
+
var captureDrainMs = 2e4;
|
|
19948
19949
|
var pidAlive = (candidate2) => {
|
|
19949
19950
|
try {
|
|
19950
19951
|
process.kill(candidate2, 0);
|
|
@@ -20054,6 +20055,7 @@ var CaptureStore = class {
|
|
|
20054
20055
|
if (!columns.some((column) => column.name === "retained_at")) this.db.exec("ALTER TABLE scopes ADD COLUMN retained_at REAL");
|
|
20055
20056
|
if (!columns.some((column) => column.name === "recording_id")) this.db.exec("ALTER TABLE scopes ADD COLUMN recording_id TEXT");
|
|
20056
20057
|
if (!columns.some((column) => column.name === "recording_id")) this.db.exec(`UPDATE scopes SET recording_id=COALESCE(json_extract(window_json,'$.transactionId'),(SELECT json_extract(entry_json,'$.transactionId') FROM capture_entries WHERE scope_id=scopes.id ORDER BY seq DESC LIMIT 1)) WHERE kind='capture'`);
|
|
20058
|
+
if (!columns.some((column) => column.name === "drain_expires_at")) this.db.exec("ALTER TABLE scopes ADD COLUMN drain_expires_at REAL");
|
|
20057
20059
|
if (!hadCandidates) this.db.exec(`INSERT OR IGNORE INTO capture_body_refs (scope_id,digest,bytes) SELECT scope_id,json_extract(entry_json,'$.reqBodyArtifact.sha256'),json_extract(entry_json,'$.reqBodyArtifact.bytes') FROM capture_candidates WHERE json_extract(entry_json,'$.reqBodyArtifact.sha256') IS NOT NULL UNION ALL SELECT scope_id,json_extract(entry_json,'$.resBodyArtifact.sha256'),json_extract(entry_json,'$.resBodyArtifact.bytes') FROM capture_candidates WHERE json_extract(entry_json,'$.resBodyArtifact.sha256') IS NOT NULL`);
|
|
20058
20060
|
this.db.prepare("UPDATE jobs SET status='uncertain' WHERE status='dispatched'").run();
|
|
20059
20061
|
this.db.exec("COMMIT");
|
|
@@ -20084,11 +20086,19 @@ var CaptureStore = class {
|
|
|
20084
20086
|
}
|
|
20085
20087
|
prune() {
|
|
20086
20088
|
const now = this.clock();
|
|
20087
|
-
const rows = this.db.prepare("SELECT id,owner_pid,owner_started_at,expires_at FROM scopes WHERE retained_at IS NULL").all();
|
|
20088
|
-
const stale = rows.filter((row) => row.expires_at <= now || !this.alive(row.owner_pid, row.owner_started_at));
|
|
20089
|
+
const rows = this.db.prepare("SELECT id,owner_pid,owner_started_at,expires_at,drain_expires_at FROM scopes WHERE retained_at IS NULL").all();
|
|
20090
|
+
const stale = rows.filter((row) => row.expires_at <= now || this.unfinishedDrainExpired(row.id, row.drain_expires_at, now) || !this.alive(row.owner_pid, row.owner_started_at));
|
|
20089
20091
|
for (const row of stale) this.releaseStaleScope(row.id);
|
|
20090
20092
|
this.db.prepare("DELETE FROM bridge_demands WHERE expires_at <= ?").run(now);
|
|
20091
20093
|
}
|
|
20094
|
+
unfinishedDrainExpired(id2, deadline, now) {
|
|
20095
|
+
return deadline !== null && deadline <= now && Boolean(this.db.prepare(`
|
|
20096
|
+
SELECT 1 FROM capture_candidates WHERE scope_id=? AND (
|
|
20097
|
+
json_extract(entry_json,'$.pending')=1 OR json_extract(entry_json,'$.reqBodyState')='pending'
|
|
20098
|
+
OR json_extract(entry_json,'$.resBodyState')='pending'
|
|
20099
|
+
) LIMIT 1
|
|
20100
|
+
`).get(id2));
|
|
20101
|
+
}
|
|
20092
20102
|
releaseStaleScope(id2) {
|
|
20093
20103
|
const capture = this.db.prepare("SELECT kind,window_json FROM scopes WHERE id=?").get(id2);
|
|
20094
20104
|
if (capture?.kind === "capture" && this.db.prepare("SELECT 1 FROM capture_candidates WHERE scope_id=? LIMIT 1").get(id2)) {
|
|
@@ -20099,7 +20109,8 @@ var CaptureStore = class {
|
|
|
20099
20109
|
}
|
|
20100
20110
|
row(id2, freshOwner = false) {
|
|
20101
20111
|
let row = this.db.prepare("SELECT * FROM scopes WHERE id=?").get(id2);
|
|
20102
|
-
|
|
20112
|
+
const now = this.clock();
|
|
20113
|
+
if (row && row.retained_at === null && (Number(row.expires_at) <= now || this.unfinishedDrainExpired(id2, row.drain_expires_at, now) || !(freshOwner ? this.alive(Number(row.owner_pid), Number(row.owner_started_at), true) : this.alive(Number(row.owner_pid), Number(row.owner_started_at))))) {
|
|
20103
20114
|
this.releaseStaleScope(id2);
|
|
20104
20115
|
row = this.db.prepare("SELECT * FROM scopes WHERE id=?").get(id2);
|
|
20105
20116
|
}
|
|
@@ -20223,7 +20234,18 @@ var CaptureStore = class {
|
|
|
20223
20234
|
return row ? { status: row.status, ...row.result_json ? { result: readJson(row.result_json) } : {} } : null;
|
|
20224
20235
|
}
|
|
20225
20236
|
acknowledgeJob(id2) {
|
|
20226
|
-
this.
|
|
20237
|
+
this.transaction(() => {
|
|
20238
|
+
this.db.prepare(`
|
|
20239
|
+
UPDATE scopes SET drain_expires_at=COALESCE(drain_expires_at, ?)
|
|
20240
|
+
WHERE kind='capture' AND window_json IS NULL AND retained_at IS NULL
|
|
20241
|
+
AND EXISTS (SELECT 1 FROM jobs
|
|
20242
|
+
WHERE id=? AND scope_id=scopes.id AND status='delivered'
|
|
20243
|
+
AND json_extract(envelope_json,'$.job.kind')='stop'
|
|
20244
|
+
AND json_extract(result_json,'$.boundaryConfirmed')=1
|
|
20245
|
+
AND json_extract(result_json,'$.transactionId')=scopes.recording_id)
|
|
20246
|
+
`).run(this.clock() + captureDrainMs, id2);
|
|
20247
|
+
this.db.prepare("DELETE FROM jobs WHERE id=? AND status IN ('delivered','uncertain')").run(id2);
|
|
20248
|
+
});
|
|
20227
20249
|
this.emit();
|
|
20228
20250
|
}
|
|
20229
20251
|
active() {
|
|
@@ -20291,7 +20313,10 @@ var CaptureStore = class {
|
|
|
20291
20313
|
if (row.kind === "inspect") throw new CaptureError("inspect-only", "Inspect scopes have no claim heartbeat");
|
|
20292
20314
|
if (row.claim_client_id && request2.payload.clientId !== row.claim_client_id) throw new CaptureError("client-mismatch", "Another extension client owns this claim");
|
|
20293
20315
|
if (request2.payload.origin && request2.payload.origin !== row.page_origin) throw new CaptureError("origin-mismatch", "Heartbeat origin does not match the scope");
|
|
20294
|
-
|
|
20316
|
+
if (row.kind !== "capture" || !row.recording_id || row.window_json) {
|
|
20317
|
+
const expiresAt = row.kind === "capture" ? Math.min(Number(row.activated_at) + scopeTtl.capture, row.window_json ? now + scopeTtl.capture : now + 12e4) : now + scopeTtl.execute;
|
|
20318
|
+
this.db.prepare("UPDATE scopes SET expires_at=? WHERE id=?").run(expiresAt, scopeId);
|
|
20319
|
+
}
|
|
20295
20320
|
if (request2.payload.lost) this.db.prepare("UPDATE scopes SET claim_tab_id=NULL,claim_selector=NULL WHERE id=?").run(scopeId);
|
|
20296
20321
|
return { ackThrough: Number(row.ack_through), captureBatchMax: 32 };
|
|
20297
20322
|
}
|
package/dist/apilift.js
CHANGED
|
@@ -41309,7 +41309,7 @@ var init_client2 = __esm({
|
|
|
41309
41309
|
// src/commands/browser.ts
|
|
41310
41310
|
import { realpathSync as realpathSync4 } from "node:fs";
|
|
41311
41311
|
import { dirname as dirname3, join as join10 } from "node:path";
|
|
41312
|
-
async function releaseStoppedCaptureForUse(state, sessionId, appId, client) {
|
|
41312
|
+
async function releaseStoppedCaptureForUse(state, sessionId, appId, client, sessionLabel) {
|
|
41313
41313
|
const has2 = (table) => Boolean(state.db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name=?").get(table));
|
|
41314
41314
|
const installation = state.installation();
|
|
41315
41315
|
const current = installation && has2("discovery_session_capture") ? state.db.prepare(
|
|
@@ -41324,7 +41324,8 @@ async function releaseStoppedCaptureForUse(state, sessionId, appId, client) {
|
|
|
41324
41324
|
for (const row of rows) {
|
|
41325
41325
|
const admitted = JSON.parse(row.entries_json ?? "[]");
|
|
41326
41326
|
if (table === "discovery_session_capture" && active2.has(row.scope_id) && admitted.some(({ entry: entry2 }) => entry2.pending || entry2.reqBodyState === "pending" || entry2.resBodyState === "pending")) {
|
|
41327
|
-
|
|
41327
|
+
const cancel = `apilift${sessionLabel ? ` --session ${sessionLabel}` : ""} discover capture cancel`;
|
|
41328
|
+
throw new BrowserControlError(`The stopped recording is collecting admitted data. To release the tab now and keep captured evidence, run ${cancel}.`, "capture-collecting");
|
|
41328
41329
|
}
|
|
41329
41330
|
if (active2.has(row.scope_id)) await client.retainScope(row.scope_id);
|
|
41330
41331
|
state.db.prepare(`UPDATE ${table} SET evidence_scope_id=COALESCE(evidence_scope_id,scope_id),scope_id=NULL WHERE draft_id=? AND scope_id=? AND phase='closed'`).run(row.draft_id, row.scope_id);
|
|
@@ -42590,7 +42591,7 @@ Private historical result: ${error62.path}
|
|
|
42590
42591
|
let httpStatus;
|
|
42591
42592
|
let output2;
|
|
42592
42593
|
try {
|
|
42593
|
-
if (liveBrowser) await releaseStoppedCaptureForUse(state, session.id, bundle2.app.id, liveBrowser);
|
|
42594
|
+
if (liveBrowser) await releaseStoppedCaptureForUse(state, session.id, bundle2.app.id, liveBrowser, invocation.sessionLabel);
|
|
42594
42595
|
const deadline = Date.now() + 2e4;
|
|
42595
42596
|
if (action.request.prepare) prepared = await prepareWithRead(action.request, transport, inputs.values, generated, sendRequest, void 0, responseSecrets, action.response?.prepared);
|
|
42596
42597
|
if (operation2 && canonicalJson(fileDigests(prepared)) !== canonicalJson(originalFiles)) throw new BrowserControlError("A local input file changed during preparation. Retry with stable input bytes", "operation-input-file-changed");
|
|
@@ -46569,24 +46570,26 @@ async function releaseCapture(state, draftId, row, root2, table = "discovery_cap
|
|
|
46569
46570
|
state.db.prepare(`UPDATE ${table} SET evidence_scope_id=COALESCE(evidence_scope_id,scope_id),scope_id=NULL WHERE draft_id=?`).run(draftId);
|
|
46570
46571
|
}
|
|
46571
46572
|
async function refreshClosedCapture(state, row, root2, releaseAuth = false) {
|
|
46572
|
-
|
|
46573
|
-
|
|
46573
|
+
const scope2 = row.scope_id ?? row.evidence_scope_id;
|
|
46574
|
+
if (row.phase !== "closed" || !scope2) return row;
|
|
46574
46575
|
if (pendingCapture(row)) {
|
|
46575
46576
|
const entries = captureEntries(row);
|
|
46577
|
+
const scopeBeforeRefresh = row.scope_id;
|
|
46578
|
+
let missing2 = false;
|
|
46576
46579
|
let latest;
|
|
46580
|
+
const client = await captureClient(root2, false);
|
|
46577
46581
|
try {
|
|
46578
|
-
const client = await captureClient(root2, false);
|
|
46579
46582
|
latest = new Map((await retainedCaptureEntries(client, scope2)).map((item) => [item.seq, item]));
|
|
46580
46583
|
} catch (error62) {
|
|
46581
46584
|
if (error62.code !== "scope-expired") throw error62;
|
|
46582
46585
|
latest = /* @__PURE__ */ new Map();
|
|
46583
|
-
|
|
46586
|
+
missing2 = true;
|
|
46584
46587
|
}
|
|
46585
46588
|
const refreshed = entries.map((item) => {
|
|
46586
46589
|
if (!pendingEntry(item)) return item;
|
|
46587
46590
|
const update2 = latest.get(item.seq);
|
|
46588
46591
|
if (update2 && update2.entry.captureId === item.entry.captureId && update2.entry.transactionId === row.transaction_id && JSON.stringify(update2.entry) !== JSON.stringify(item.entry)) return update2;
|
|
46589
|
-
if (
|
|
46592
|
+
if (!missing2) return item;
|
|
46590
46593
|
return { ...item, entry: {
|
|
46591
46594
|
...item.entry,
|
|
46592
46595
|
pending: false,
|
|
@@ -46595,9 +46598,10 @@ async function refreshClosedCapture(state, row, root2, releaseAuth = false) {
|
|
|
46595
46598
|
...item.entry.resBodyState === "pending" ? { resBodyState: "failed" } : {}
|
|
46596
46599
|
} };
|
|
46597
46600
|
});
|
|
46598
|
-
|
|
46599
|
-
|
|
46600
|
-
|
|
46601
|
+
const released = missing2 || row.scope_id !== null && refreshed.some(pendingEntry) && !(await client.scopes()).scopes.some((candidate2) => candidate2.id === scope2);
|
|
46602
|
+
if (refreshed.some((item, index2) => item !== entries[index2]) || released) {
|
|
46603
|
+
row = { ...row, entries_json: JSON.stringify(refreshed), scope_id: released ? null : row.scope_id };
|
|
46604
|
+
state.db.prepare("UPDATE discovery_session_capture SET entries_json=?,scope_id=? WHERE draft_id=? AND scope_id IS ?").run(row.entries_json, row.scope_id, row.draft_id, scopeBeforeRefresh);
|
|
46601
46605
|
writeCaptureCatalog(row, root2);
|
|
46602
46606
|
}
|
|
46603
46607
|
}
|
|
@@ -46897,7 +46901,7 @@ async function captureDraft(invocation, api, state, store, session, root2) {
|
|
|
46897
46901
|
const key2 = invocation.key;
|
|
46898
46902
|
let recording = current.appId ? captures.latest(session.id, current.appId, invocation.options.recording) : null;
|
|
46899
46903
|
if (recording && ["discoverCaptureStop", "discoverCaptureAuth"].includes(key2)) recording = await refreshClosedCapture(state, recording, root2);
|
|
46900
|
-
if (recording?.
|
|
46904
|
+
if (recording?.phase === "closed" && ["discoverCaptureList", "discoverCaptureShow"].includes(key2)) {
|
|
46901
46905
|
let release;
|
|
46902
46906
|
try {
|
|
46903
46907
|
release = lockDiscovery(root2, session.id);
|
|
@@ -46919,7 +46923,8 @@ async function captureDraft(invocation, api, state, store, session, root2) {
|
|
|
46919
46923
|
if (!current.appId) return fail5("Publish the app shell before recording. No recording started.\n");
|
|
46920
46924
|
const active2 = captures.active(session.id);
|
|
46921
46925
|
if (active2 && active2.phase !== "closed") return fail5("Stop or cancel the existing recording before starting another.\n");
|
|
46922
|
-
if (active2 && (await refreshClosedCapture(state, active2, root2, true)).scope_id) return fail5(
|
|
46926
|
+
if (active2 && (await refreshClosedCapture(state, active2, root2, true)).scope_id) return fail5(`The stopped recording is still collecting. To release the tab now and keep captured evidence, run ${command4(invocation, "discover capture cancel")}.
|
|
46927
|
+
`, 12);
|
|
46923
46928
|
const app2 = await api.call("getApp", { params: { app: current.appId } });
|
|
46924
46929
|
const origin = new URL(app2.origin).origin;
|
|
46925
46930
|
const installation = state.installation();
|
|
@@ -46960,10 +46965,11 @@ async function captureDraft(invocation, api, state, store, session, root2) {
|
|
|
46960
46965
|
if ((key2 === "discoverCaptureCancel" || key2 === "discoverCaptureStop") && row.phase === "lost") return ok4(`Recording admission is closed because the recorder lease ended. Its stop boundary was not confirmed. Inspect app state before any mutation; retained evidence and drafts remain available. No app operation was repeated.
|
|
46961
46966
|
`);
|
|
46962
46967
|
if (key2 === "discoverCaptureCancel" && row.phase === "closed") {
|
|
46963
|
-
|
|
46968
|
+
await releaseCapture(state, id2, row, root2, table);
|
|
46969
|
+
return ok4(`Stopped recording released its tab. Captured evidence remains available: ${command4(invocation, "discover capture list")}
|
|
46964
46970
|
`);
|
|
46965
46971
|
}
|
|
46966
|
-
if (key2 === "discoverCaptureCancel" &&
|
|
46972
|
+
if (key2 === "discoverCaptureCancel" && row.phase === "cancelled") {
|
|
46967
46973
|
if (row.scope_id) {
|
|
46968
46974
|
try {
|
|
46969
46975
|
await (await captureClient(root2, false)).retainScope(row.scope_id);
|
|
@@ -47497,7 +47503,8 @@ Record a UI workflow: ${command4(invocation, "discover capture start")}
|
|
|
47497
47503
|
const setup = setupTarget(source);
|
|
47498
47504
|
if (key2 === "discoverTransportProbe") {
|
|
47499
47505
|
if (!setup) return fail5("Supply a transport definition file.\n");
|
|
47500
|
-
if (active2?.phase === "closed" && (await refreshClosedCapture(state, active2, root2, true)).scope_id) return fail5(
|
|
47506
|
+
if (active2?.phase === "closed" && (await refreshClosedCapture(state, active2, root2, true)).scope_id) return fail5(`The stopped recording is still collecting. To release the tab now and keep captured evidence, run ${command4(invocation, "discover capture cancel")}.
|
|
47507
|
+
`, 12);
|
|
47501
47508
|
return await probeTransport(invocation, api, state, session, fetcher, root2, setup, source, path2);
|
|
47502
47509
|
}
|
|
47503
47510
|
if (setup) return key2 === "discoverCheck" ? await checkSetupFile(invocation, api, setup, source, path2) : await publishSetup(invocation, api, state, store, session, root2, setup, source, path2);
|
|
@@ -47593,7 +47600,8 @@ Record a UI workflow: ${command4(invocation, "discover capture start")}
|
|
|
47593
47600
|
if (key2 === "discoverClose") {
|
|
47594
47601
|
if (!current) return ok4("No discovery session is open.\n");
|
|
47595
47602
|
if (legacyRecording) return fail5("Settle the retained recording with discover capture cancel first.\n", 8);
|
|
47596
|
-
if (active2 && (await refreshClosedCapture(state, active2, root2, true)).scope_id) return fail5(
|
|
47603
|
+
if (active2 && (await refreshClosedCapture(state, active2, root2, true)).scope_id) return fail5(`Admitted requests are still collecting. To release the tab now, run ${command4(invocation, "discover capture cancel")}.
|
|
47604
|
+
`, 12);
|
|
47597
47605
|
const installation = state.installation();
|
|
47598
47606
|
if (installation) await api.call("releaseSession", { params: { id: apiSessionId(installation.id, session) } });
|
|
47599
47607
|
await captures.close(session.id, async (id2) => (await captureClient(root2, false)).closeScope(id2), root2);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apilift/cli",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.15-dev.1794699960.e4e1a04acda82805b3c1010b7c04db2ff20dddcd",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"engines": {
|
|
38
38
|
"node": ">=24.16.0 <27"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "e4e1a04acda82805b3c1010b7c04db2ff20dddcd",
|
|
41
41
|
"repository": {
|
|
42
42
|
"type": "git",
|
|
43
43
|
"url": "git+https://github.com/egor-sergeev/apilift.git",
|