loopengine 0.4.5 → 0.4.6
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/core/audit-store.d.ts +5 -24
- package/dist/core/audit-store.js +12 -33
- package/dist/core/workflow-runs.d.ts +3 -0
- package/dist/core/workflow-runs.js +10 -1
- package/dist/core/workspace-roles.js +2 -0
- package/dist/index.d.ts +3 -4
- package/dist/index.js +3 -4
- package/dist/web/agents-config-page.js +54 -13
- package/dist/web/audit-admin.d.ts +3 -1
- package/dist/web/audit-admin.js +2 -1
- package/dist/web/audit-page.js +18 -14
- package/dist/web/console-shell.js +3 -1
- package/dist/web/inbox-admin.d.ts +17 -0
- package/dist/web/inbox-admin.js +32 -7
- package/dist/web/inbox-page.js +140 -23
- package/dist/web/workflow-audit-report.js +1 -1
- package/dist/web/workflow-audit.d.ts +2 -6
- package/dist/web/workflow-audit.js +1 -1
- package/dist/web/workflow-evidence.d.ts +21 -0
- package/dist/web/workflow-evidence.js +84 -1
- package/package.json +1 -3
- package/dist/core/audit-anchor.d.ts +0 -39
- package/dist/core/audit-anchor.js +0 -90
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
// Anchors the audit log's hash chain (core/audit-store.ts) outside the
|
|
2
|
-
// workspace: once a day, the latest event's id and hash go to
|
|
3
|
-
// loopengine.co (POST /api/workspace/audit-anchors), which keeps them
|
|
4
|
-
// where the workspace can't rewrite them. Checking the log
|
|
5
|
-
// (GET /audit/verify) fetches them back (GET on the same path) and
|
|
6
|
-
// matches each against the chain, so rewriting the whole chain to hide a
|
|
7
|
-
// change still shows.
|
|
8
|
-
//
|
|
9
|
-
// Signed like the workspace's other reports (web/lever-events-sync.ts):
|
|
10
|
-
// X-LoopEngine-Workspace names the workspace (from LOOPENGINE_PUBLIC_URL),
|
|
11
|
-
// X-LoopEngine-Signature is t=<unix seconds>,v1=<HMAC-SHA256 of
|
|
12
|
-
// "<t>.<body>"> with LOOPENGINE_TRUSTED_PROXY_SECRET (an empty body for
|
|
13
|
-
// the GET). Off outside LoopEngine Cloud: the anchors are then only kept
|
|
14
|
-
// in the workspace's own database, which shows a changed event but not a
|
|
15
|
-
// rewritten chain.
|
|
16
|
-
import { createHmac } from 'node:crypto';
|
|
17
|
-
import { lastAnchor, latestEventHash, noteAnchor } from './audit-store.js';
|
|
18
|
-
export const AUDIT_ANCHORS_PATH = '/api/workspace/audit-anchors';
|
|
19
|
-
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
20
|
-
/** Where anchors go and how to sign, or why they stay local. */
|
|
21
|
-
export function anchorConfig(env = process.env) {
|
|
22
|
-
const secret = env.LOOPENGINE_TRUSTED_PROXY_SECRET;
|
|
23
|
-
if (!secret)
|
|
24
|
-
return { off: 'not a LoopEngine Cloud workspace' };
|
|
25
|
-
let slug;
|
|
26
|
-
try {
|
|
27
|
-
slug = env.LOOPENGINE_PUBLIC_URL ? new URL(env.LOOPENGINE_PUBLIC_URL).hostname.split('.')[0] : undefined;
|
|
28
|
-
}
|
|
29
|
-
catch { }
|
|
30
|
-
if (!slug)
|
|
31
|
-
return { off: 'LOOPENGINE_PUBLIC_URL is needed to name the workspace' };
|
|
32
|
-
return { url: `${(env.LOOPENGINE_CONTROL_PLANE_URL || 'https://loopengine.co').replace(/\/+$/, '')}${AUDIT_ANCHORS_PATH}`, slug, secret };
|
|
33
|
-
}
|
|
34
|
-
export function signAnchorRequest(body, timestamp, secret) {
|
|
35
|
-
return `t=${timestamp},v1=${createHmac('sha256', secret).update(`${timestamp}.${body}`).digest('hex')}`;
|
|
36
|
-
}
|
|
37
|
-
function headers(config, body) {
|
|
38
|
-
return { 'content-type': 'application/json', 'x-loopengine-workspace': config.slug, 'x-loopengine-signature': signAnchorRequest(body, Math.floor(Date.now() / 1000), config.secret) };
|
|
39
|
-
}
|
|
40
|
-
/** Anchors the latest event, unless it already is. Never throws. Off
|
|
41
|
-
* Cloud, the anchor is noted only here. */
|
|
42
|
-
export async function anchorLatest(config = anchorConfig(), fetchImpl = fetch) {
|
|
43
|
-
const latest = latestEventHash();
|
|
44
|
-
if (!latest)
|
|
45
|
-
return { status: 'nothing-new' };
|
|
46
|
-
const last = lastAnchor();
|
|
47
|
-
if (last && last.eventId === latest.id && (last.sentAt || 'off' in config))
|
|
48
|
-
return { status: 'nothing-new' };
|
|
49
|
-
if ('off' in config) {
|
|
50
|
-
noteAnchor({ eventId: latest.id, hash: latest.hash, at: latest.at });
|
|
51
|
-
return { status: 'kept-here', eventId: latest.id };
|
|
52
|
-
}
|
|
53
|
-
const body = JSON.stringify({ eventId: latest.id, hash: latest.hash, eventAt: latest.at });
|
|
54
|
-
try {
|
|
55
|
-
const res = await fetchImpl(config.url, { method: 'POST', headers: headers(config, body), body, signal: AbortSignal.timeout(15_000) });
|
|
56
|
-
if (!res.ok)
|
|
57
|
-
return { status: 'failed', reason: `loopengine.co answered ${res.status}` };
|
|
58
|
-
}
|
|
59
|
-
catch (err) {
|
|
60
|
-
return { status: 'failed', reason: `couldn't reach ${config.url}: ${err instanceof Error ? err.message : String(err)}` };
|
|
61
|
-
}
|
|
62
|
-
noteAnchor({ eventId: latest.id, hash: latest.hash, at: latest.at, sentAt: new Date().toISOString() });
|
|
63
|
-
return { status: 'sent', eventId: latest.id };
|
|
64
|
-
}
|
|
65
|
-
/** The anchors kept at loopengine.co, or undefined off Cloud or when
|
|
66
|
-
* they can't be fetched (with why). */
|
|
67
|
-
export async function fetchAnchors(config = anchorConfig(), fetchImpl = fetch) {
|
|
68
|
-
if ('off' in config)
|
|
69
|
-
return { unavailable: config.off };
|
|
70
|
-
try {
|
|
71
|
-
const res = await fetchImpl(config.url, { headers: headers(config, ''), signal: AbortSignal.timeout(15_000) });
|
|
72
|
-
if (!res.ok)
|
|
73
|
-
return { unavailable: `loopengine.co answered ${res.status}` };
|
|
74
|
-
const body = (await res.json());
|
|
75
|
-
const anchors = (body.anchors ?? []).flatMap((a) => (typeof a.eventId === 'number' && typeof a.hash === 'string' ? [{ eventId: a.eventId, hash: a.hash }] : []));
|
|
76
|
-
return { anchors };
|
|
77
|
-
}
|
|
78
|
-
catch (err) {
|
|
79
|
-
return { unavailable: `couldn't reach loopengine.co: ${err instanceof Error ? err.message : String(err)}` };
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
/** Anchors now (a minute after start) and then daily. */
|
|
83
|
-
export function startAuditAnchoring(log = () => { }) {
|
|
84
|
-
const run = () => void anchorLatest().then((r) => {
|
|
85
|
-
if (r.status === 'failed')
|
|
86
|
-
log(`[loopengine] couldn't anchor the audit log: ${r.reason}`);
|
|
87
|
-
});
|
|
88
|
-
setTimeout(run, 60_000).unref();
|
|
89
|
-
setInterval(run, DAY_MS).unref();
|
|
90
|
-
}
|