@proofoftech/flowsafe 0.1.0
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/CHANGELOG.md +21 -0
- package/LICENSE +202 -0
- package/README.md +273 -0
- package/dist/approval-api/contract.d.ts +45 -0
- package/dist/approval-api/contract.d.ts.map +1 -0
- package/dist/approval-api/contract.js +37 -0
- package/dist/approval-api/contract.js.map +1 -0
- package/dist/approval-api/d1-store.d.ts +52 -0
- package/dist/approval-api/d1-store.d.ts.map +1 -0
- package/dist/approval-api/d1-store.js +468 -0
- package/dist/approval-api/d1-store.js.map +1 -0
- package/dist/approval-api/grants.d.ts +52 -0
- package/dist/approval-api/grants.d.ts.map +1 -0
- package/dist/approval-api/grants.js +200 -0
- package/dist/approval-api/grants.js.map +1 -0
- package/dist/approval-api/index.d.ts +21 -0
- package/dist/approval-api/index.d.ts.map +1 -0
- package/dist/approval-api/index.js +18 -0
- package/dist/approval-api/index.js.map +1 -0
- package/dist/approval-api/retention.d.ts +32 -0
- package/dist/approval-api/retention.d.ts.map +1 -0
- package/dist/approval-api/retention.js +81 -0
- package/dist/approval-api/retention.js.map +1 -0
- package/dist/approval-api/router.d.ts +51 -0
- package/dist/approval-api/router.d.ts.map +1 -0
- package/dist/approval-api/router.js +245 -0
- package/dist/approval-api/router.js.map +1 -0
- package/dist/approval-api/service.d.ts +134 -0
- package/dist/approval-api/service.d.ts.map +1 -0
- package/dist/approval-api/service.js +537 -0
- package/dist/approval-api/service.js.map +1 -0
- package/dist/approval-api/store.d.ts +126 -0
- package/dist/approval-api/store.d.ts.map +1 -0
- package/dist/approval-api/store.js +189 -0
- package/dist/approval-api/store.js.map +1 -0
- package/dist/approval-api/tenant-brand.d.ts +35 -0
- package/dist/approval-api/tenant-brand.d.ts.map +1 -0
- package/dist/approval-api/tenant-brand.js +18 -0
- package/dist/approval-api/tenant-brand.js.map +1 -0
- package/dist/approval-api/tenant-context.d.ts +44 -0
- package/dist/approval-api/tenant-context.d.ts.map +1 -0
- package/dist/approval-api/tenant-context.js +49 -0
- package/dist/approval-api/tenant-context.js.map +1 -0
- package/dist/approval-api/tenant-store.d.ts +36 -0
- package/dist/approval-api/tenant-store.d.ts.map +1 -0
- package/dist/approval-api/tenant-store.js +122 -0
- package/dist/approval-api/tenant-store.js.map +1 -0
- package/dist/approval-api/types.d.ts +247 -0
- package/dist/approval-api/types.d.ts.map +1 -0
- package/dist/approval-api/types.js +157 -0
- package/dist/approval-api/types.js.map +1 -0
- package/dist/approval-ui/App.d.ts +11 -0
- package/dist/approval-ui/App.d.ts.map +1 -0
- package/dist/approval-ui/App.js +15 -0
- package/dist/approval-ui/App.js.map +1 -0
- package/dist/approval-ui/DetailView.d.ts +13 -0
- package/dist/approval-ui/DetailView.d.ts.map +1 -0
- package/dist/approval-ui/DetailView.js +20 -0
- package/dist/approval-ui/DetailView.js.map +1 -0
- package/dist/approval-ui/MetricsView.d.ts +7 -0
- package/dist/approval-ui/MetricsView.d.ts.map +1 -0
- package/dist/approval-ui/MetricsView.js +22 -0
- package/dist/approval-ui/MetricsView.js.map +1 -0
- package/dist/approval-ui/QueueView.d.ts +11 -0
- package/dist/approval-ui/QueueView.d.ts.map +1 -0
- package/dist/approval-ui/QueueView.js +59 -0
- package/dist/approval-ui/QueueView.js.map +1 -0
- package/dist/approval-ui/client.d.ts +34 -0
- package/dist/approval-ui/client.d.ts.map +1 -0
- package/dist/approval-ui/client.js +103 -0
- package/dist/approval-ui/client.js.map +1 -0
- package/dist/approval-ui/components.d.ts +125 -0
- package/dist/approval-ui/components.d.ts.map +1 -0
- package/dist/approval-ui/components.js +54 -0
- package/dist/approval-ui/components.js.map +1 -0
- package/dist/approval-ui/index.d.ts +21 -0
- package/dist/approval-ui/index.d.ts.map +1 -0
- package/dist/approval-ui/index.js +21 -0
- package/dist/approval-ui/index.js.map +1 -0
- package/dist/approval-ui/mount.d.ts +23 -0
- package/dist/approval-ui/mount.d.ts.map +1 -0
- package/dist/approval-ui/mount.js +17 -0
- package/dist/approval-ui/mount.js.map +1 -0
- package/dist/approval-ui/tips.d.ts +32 -0
- package/dist/approval-ui/tips.d.ts.map +1 -0
- package/dist/approval-ui/tips.js +32 -0
- package/dist/approval-ui/tips.js.map +1 -0
- package/dist/approval-ui/use-approval-dashboard.d.ts +70 -0
- package/dist/approval-ui/use-approval-dashboard.d.ts.map +1 -0
- package/dist/approval-ui/use-approval-dashboard.js +148 -0
- package/dist/approval-ui/use-approval-dashboard.js.map +1 -0
- package/dist/approval-ui/view-model.d.ts +24 -0
- package/dist/approval-ui/view-model.d.ts.map +1 -0
- package/dist/approval-ui/view-model.js +62 -0
- package/dist/approval-ui/view-model.js.map +1 -0
- package/dist/artifacts/index.d.ts +123 -0
- package/dist/artifacts/index.d.ts.map +1 -0
- package/dist/artifacts/index.js +223 -0
- package/dist/artifacts/index.js.map +1 -0
- package/dist/audit-export/index.d.ts +71 -0
- package/dist/audit-export/index.d.ts.map +1 -0
- package/dist/audit-export/index.js +124 -0
- package/dist/audit-export/index.js.map +1 -0
- package/dist/do-runner/breakwater-keys.d.ts +23 -0
- package/dist/do-runner/breakwater-keys.d.ts.map +1 -0
- package/dist/do-runner/breakwater-keys.js +38 -0
- package/dist/do-runner/breakwater-keys.js.map +1 -0
- package/dist/do-runner/cf-types.d.ts +26 -0
- package/dist/do-runner/cf-types.d.ts.map +1 -0
- package/dist/do-runner/cf-types.js +13 -0
- package/dist/do-runner/cf-types.js.map +1 -0
- package/dist/do-runner/d1-storage.d.ts +128 -0
- package/dist/do-runner/d1-storage.d.ts.map +1 -0
- package/dist/do-runner/d1-storage.js +287 -0
- package/dist/do-runner/d1-storage.js.map +1 -0
- package/dist/do-runner/durable-object.d.ts +28 -0
- package/dist/do-runner/durable-object.d.ts.map +1 -0
- package/dist/do-runner/durable-object.js +164 -0
- package/dist/do-runner/durable-object.js.map +1 -0
- package/dist/do-runner/index.d.ts +12 -0
- package/dist/do-runner/index.d.ts.map +1 -0
- package/dist/do-runner/index.js +11 -0
- package/dist/do-runner/index.js.map +1 -0
- package/dist/do-runner/init.d.ts +38 -0
- package/dist/do-runner/init.d.ts.map +1 -0
- package/dist/do-runner/init.js +45 -0
- package/dist/do-runner/init.js.map +1 -0
- package/dist/do-runner/path-safe-id.d.ts +19 -0
- package/dist/do-runner/path-safe-id.d.ts.map +1 -0
- package/dist/do-runner/path-safe-id.js +70 -0
- package/dist/do-runner/path-safe-id.js.map +1 -0
- package/dist/do-runner/resume-ledger.d.ts +48 -0
- package/dist/do-runner/resume-ledger.d.ts.map +1 -0
- package/dist/do-runner/resume-ledger.js +59 -0
- package/dist/do-runner/resume-ledger.js.map +1 -0
- package/dist/do-runner/runtime.d.ts +161 -0
- package/dist/do-runner/runtime.d.ts.map +1 -0
- package/dist/do-runner/runtime.js +509 -0
- package/dist/do-runner/runtime.js.map +1 -0
- package/dist/host-kit/approval-bridge.d.ts +109 -0
- package/dist/host-kit/approval-bridge.d.ts.map +1 -0
- package/dist/host-kit/approval-bridge.js +262 -0
- package/dist/host-kit/approval-bridge.js.map +1 -0
- package/dist/host-kit/bearer-auth.d.ts +19 -0
- package/dist/host-kit/bearer-auth.d.ts.map +1 -0
- package/dist/host-kit/bearer-auth.js +67 -0
- package/dist/host-kit/bearer-auth.js.map +1 -0
- package/dist/host-kit/do-response.d.ts +13 -0
- package/dist/host-kit/do-response.d.ts.map +1 -0
- package/dist/host-kit/do-response.js +24 -0
- package/dist/host-kit/do-response.js.map +1 -0
- package/dist/host-kit/do-run-topology.d.ts +32 -0
- package/dist/host-kit/do-run-topology.d.ts.map +1 -0
- package/dist/host-kit/do-run-topology.js +39 -0
- package/dist/host-kit/do-run-topology.js.map +1 -0
- package/dist/host-kit/env-vars.d.ts +26 -0
- package/dist/host-kit/env-vars.d.ts.map +1 -0
- package/dist/host-kit/env-vars.js +48 -0
- package/dist/host-kit/env-vars.js.map +1 -0
- package/dist/host-kit/host-approval-service.d.ts +125 -0
- package/dist/host-kit/host-approval-service.d.ts.map +1 -0
- package/dist/host-kit/host-approval-service.js +187 -0
- package/dist/host-kit/host-approval-service.js.map +1 -0
- package/dist/host-kit/index.d.ts +18 -0
- package/dist/host-kit/index.d.ts.map +1 -0
- package/dist/host-kit/index.js +34 -0
- package/dist/host-kit/index.js.map +1 -0
- package/dist/host-kit/module.d.ts +34 -0
- package/dist/host-kit/module.d.ts.map +1 -0
- package/dist/host-kit/module.js +17 -0
- package/dist/host-kit/module.js.map +1 -0
- package/dist/host-kit/registration.d.ts +11 -0
- package/dist/host-kit/registration.d.ts.map +1 -0
- package/dist/host-kit/registration.js +21 -0
- package/dist/host-kit/registration.js.map +1 -0
- package/dist/host-kit/run-route-error.d.ts +11 -0
- package/dist/host-kit/run-route-error.d.ts.map +1 -0
- package/dist/host-kit/run-route-error.js +22 -0
- package/dist/host-kit/run-route-error.js.map +1 -0
- package/dist/host-kit/run-router.d.ts +60 -0
- package/dist/host-kit/run-router.d.ts.map +1 -0
- package/dist/host-kit/run-router.js +212 -0
- package/dist/host-kit/run-router.js.map +1 -0
- package/dist/host-kit/subdomain-check.d.ts +23 -0
- package/dist/host-kit/subdomain-check.d.ts.map +1 -0
- package/dist/host-kit/subdomain-check.js +60 -0
- package/dist/host-kit/subdomain-check.js.map +1 -0
- package/dist/host-kit/tenant-registry.d.ts +51 -0
- package/dist/host-kit/tenant-registry.d.ts.map +1 -0
- package/dist/host-kit/tenant-registry.js +87 -0
- package/dist/host-kit/tenant-registry.js.map +1 -0
- package/dist/host-kit/verifier.d.ts +63 -0
- package/dist/host-kit/verifier.d.ts.map +1 -0
- package/dist/host-kit/verifier.js +191 -0
- package/dist/host-kit/verifier.js.map +1 -0
- package/dist/host-kit/workflow-meta.d.ts +25 -0
- package/dist/host-kit/workflow-meta.d.ts.map +1 -0
- package/dist/host-kit/workflow-meta.js +12 -0
- package/dist/host-kit/workflow-meta.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/package.json +95 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Hover-tip copy for the dashboard's domain terms, rendered through the
|
|
2
|
+
// InfoTip slot. One source so QueueView/DetailView/MetricsView never drift
|
|
3
|
+
// and consumers can reuse the same explanations in their own surfaces.
|
|
4
|
+
// DOM-free on purpose: compiles in the main (workers-typed) pass too.
|
|
5
|
+
const STATUS_TIPS = {
|
|
6
|
+
pending: 'Awaiting a decision and unclaimed. Any actor with the reviewer or admin role can claim or decide it.',
|
|
7
|
+
claimed: 'A reviewer marked this request as theirs to review. Claiming is optional bookkeeping; anyone authorized can still decide it.',
|
|
8
|
+
approved: 'Decided affirmatively. The decision minted a grant bound to this exact suspension and the run resumed server-side.',
|
|
9
|
+
rejected: 'Decided negatively. No grant was minted; the run resumed server-side to a declined outcome.',
|
|
10
|
+
escalated: 'Past its SLA deadline and flagged by the sweep. Escalation raises visibility only; the request is still fully decidable.',
|
|
11
|
+
};
|
|
12
|
+
const METRIC_TIPS = {
|
|
13
|
+
Open: 'Requests still awaiting a decision: pending, claimed, or escalated.',
|
|
14
|
+
'SLA breached': 'Open requests past their SLA deadline, counted whether or not the 15-minute sweep has marked them escalated yet.',
|
|
15
|
+
Escalations: 'Requests ever escalated by the sweep, including ones decided since. Escalation never closes a request.',
|
|
16
|
+
Decided: 'Requests resolved either way: approved plus rejected.',
|
|
17
|
+
Approved: 'Decisions that minted a grant bound to their exact suspension.',
|
|
18
|
+
Rejected: 'Decisions that resumed the run to a declined outcome. No grant was minted.',
|
|
19
|
+
'Avg resolution': "Mean time from request creation to decision, across decided requests. Shows '—' until something has been decided.",
|
|
20
|
+
};
|
|
21
|
+
export const APPROVAL_TIPS = {
|
|
22
|
+
sla: 'Each request carries a decide-by deadline (4 hours here). A cron sweep every 15 minutes marks overdue requests as escalated.',
|
|
23
|
+
statusColumn: 'pending → claimed → approved/rejected; escalated when the SLA sweep flags an overdue request.',
|
|
24
|
+
priority: 'low, normal, high, or critical, set when a request is created. Approvals auto-queued from a suspension default to normal.',
|
|
25
|
+
claim: "Marks you as the reviewer working this request so others don't double-handle it. Optional; deciding does not require a prior claim.",
|
|
26
|
+
delegate: 'Reassigns the claim to another reviewer. Last write wins by design: it moves a pointer and guards no side effect.',
|
|
27
|
+
grantsOnApprove: 'Connector ids this approval unlocks, for one resumed leg of this exact suspension only. Approving here never unlocks a later gate.',
|
|
28
|
+
decision: 'The durable decision record. Approve derived a grant for the suspended leg; reject resumed the run to a declined outcome.',
|
|
29
|
+
status: STATUS_TIPS,
|
|
30
|
+
metrics: METRIC_TIPS,
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=tips.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tips.js","sourceRoot":"","sources":["../../src/approval-ui/tips.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,2EAA2E;AAC3E,uEAAuE;AACvE,sEAAsE;AAItE,MAAM,WAAW,GAAmC;IAClD,OAAO,EACL,sGAAsG;IACxG,OAAO,EACL,8HAA8H;IAChI,QAAQ,EACN,oHAAoH;IACtH,QAAQ,EACN,6FAA6F;IAC/F,SAAS,EACP,0HAA0H;CAC7H,CAAC;AAEF,MAAM,WAAW,GAAG;IAClB,IAAI,EAAE,qEAAqE;IAC3E,cAAc,EACZ,kHAAkH;IACpH,WAAW,EACT,wGAAwG;IAC1G,OAAO,EAAE,uDAAuD;IAChE,QAAQ,EAAE,gEAAgE;IAC1E,QAAQ,EACN,4EAA4E;IAC9E,gBAAgB,EACd,mHAAmH;CAC7G,CAAC;AAIX,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,GAAG,EAAE,8HAA8H;IACnI,YAAY,EACV,+FAA+F;IACjG,QAAQ,EACN,2HAA2H;IAC7H,KAAK,EACH,qIAAqI;IACvI,QAAQ,EACN,mHAAmH;IACrH,eAAe,EACb,oIAAoI;IACtI,QAAQ,EACN,2HAA2H;IAC7H,MAAM,EAAE,WAAW;IACnB,OAAO,EAAE,WAAW;CACZ,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { ApprovalDecision, ApprovalListFilter, ApprovalMetrics, ApprovalRecord } from '../approval-api/types.js';
|
|
2
|
+
import type { ApprovalApiClient } from './client.js';
|
|
3
|
+
/**
|
|
4
|
+
* The dashboard's default queue slice: open (non-terminal) requests only,
|
|
5
|
+
* page-bounded at 100 in REVIEWER order. The bound is D3 — an unfiltered
|
|
6
|
+
* client.list() repeated every poll is a full-table scan on every open
|
|
7
|
+
* dashboard (2026-07-11 audit). orderBy: 'reviewer' makes the server rank
|
|
8
|
+
* priority → SLA → FIFO BEFORE cutting the page, so the 100 rows are the
|
|
9
|
+
* top of the queue — under the default FIFO cut, a fresh critical request
|
|
10
|
+
* beyond the oldest 100 never reached the dashboard at all (2026-07-11
|
|
11
|
+
* review). This is the fallback whenever a caller does not override
|
|
12
|
+
* UseApprovalDashboardOptions.filter.
|
|
13
|
+
*/
|
|
14
|
+
export declare const DEFAULT_QUEUE_FILTER: ApprovalListFilter;
|
|
15
|
+
/**
|
|
16
|
+
* Render-stable identity for a filter: its JSON serialization. The hook keys
|
|
17
|
+
* refresh() on this VALUE instead of the object reference, so the natural
|
|
18
|
+
* `useApprovalDashboard(client, { filter: { status: 'pending' } })` — a new
|
|
19
|
+
* object identity every render — polls on the configured interval instead of
|
|
20
|
+
* looping list/metrics requests back-to-back (2026-07-11 review), while a
|
|
21
|
+
* filter that CHANGES value still refetches immediately. Key order follows
|
|
22
|
+
* the caller's literal, which is constant across that caller's renders — the
|
|
23
|
+
* only stability this needs.
|
|
24
|
+
*/
|
|
25
|
+
export declare function approvalFilterKey(filter: ApprovalListFilter): string;
|
|
26
|
+
/**
|
|
27
|
+
* One poll's worth of dashboard data. DOM-free and hook-free — pulled out of
|
|
28
|
+
* refresh() so the filter wiring (which ApprovalListFilter reaches
|
|
29
|
+
* client.list) is testable without mounting the hook (the package's default
|
|
30
|
+
* no-renderer stance; the one exception is
|
|
31
|
+
* use-approval-dashboard.render.test.ts, which mounts the hook on happy-dom
|
|
32
|
+
* to pin the dependency-identity wiring — see README). metrics() is
|
|
33
|
+
* deliberately called with no filter: it always summarizes the whole tenant
|
|
34
|
+
* queue, independent of the queue view's slice.
|
|
35
|
+
*/
|
|
36
|
+
export declare function fetchDashboardSnapshot(client: Pick<ApprovalApiClient, 'list' | 'metrics'>, filter: ApprovalListFilter): Promise<{
|
|
37
|
+
records: ApprovalRecord[];
|
|
38
|
+
metrics: ApprovalMetrics;
|
|
39
|
+
}>;
|
|
40
|
+
export interface UseApprovalDashboardOptions {
|
|
41
|
+
/** Queue/metrics refresh cadence; <= 0 disables polling. Default 10s. */
|
|
42
|
+
pollIntervalMs?: number;
|
|
43
|
+
/** Injectable clock (deterministic SLA countdowns in tests/stories). */
|
|
44
|
+
now?: () => number;
|
|
45
|
+
/**
|
|
46
|
+
* The queue list filter, re-applied on every poll. Default:
|
|
47
|
+
* DEFAULT_QUEUE_FILTER (open statuses, limit 100) — bounded so the
|
|
48
|
+
* dashboard never issues an unfiltered full-table scan.
|
|
49
|
+
*/
|
|
50
|
+
filter?: ApprovalListFilter;
|
|
51
|
+
}
|
|
52
|
+
export interface ApprovalDashboardState {
|
|
53
|
+
/** Queue in reviewer order (priority → deadline → FIFO). */
|
|
54
|
+
records: ApprovalRecord[];
|
|
55
|
+
metrics: ApprovalMetrics | null;
|
|
56
|
+
/** Derived from the fetched list — never stale after a refresh. */
|
|
57
|
+
selected: ApprovalRecord | null;
|
|
58
|
+
selectedId: string | null;
|
|
59
|
+
error: string | null;
|
|
60
|
+
/** True while a claim/decide/delegate mutation is in flight. */
|
|
61
|
+
busy: boolean;
|
|
62
|
+
nowMs: number;
|
|
63
|
+
select: (id: string) => void;
|
|
64
|
+
decide: (decision: ApprovalDecision, comment: string) => void;
|
|
65
|
+
claim: () => void;
|
|
66
|
+
delegate: (to: string) => void;
|
|
67
|
+
refresh: () => Promise<void>;
|
|
68
|
+
}
|
|
69
|
+
export declare function useApprovalDashboard(client: ApprovalApiClient, { pollIntervalMs, now, filter, }?: UseApprovalDashboardOptions): ApprovalDashboardState;
|
|
70
|
+
//# sourceMappingURL=use-approval-dashboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-approval-dashboard.d.ts","sourceRoot":"","sources":["../../src/approval-ui/use-approval-dashboard.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACf,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGrD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,EAAE,kBAIlC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,CAEpE;AAED;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAC,EACnD,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC;IAAE,OAAO,EAAE,cAAc,EAAE,CAAC;IAAC,OAAO,EAAE,eAAe,CAAA;CAAE,CAAC,CAMlE;AAED,MAAM,WAAW,2BAA2B;IAC1C,yEAAyE;IACzE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,wEAAwE;IACxE,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB;;;;OAIG;IACH,MAAM,CAAC,EAAE,kBAAkB,CAAC;CAC7B;AAED,MAAM,WAAW,sBAAsB;IACrC,4DAA4D;IAC5D,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,OAAO,EAAE,eAAe,GAAG,IAAI,CAAC;IAChC,mEAAmE;IACnE,QAAQ,EAAE,cAAc,GAAG,IAAI,CAAC;IAChC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,gEAAgE;IAChE,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B,MAAM,EAAE,CAAC,QAAQ,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9D,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,iBAAiB,EACzB,EACE,cAAuB,EACvB,GAAc,EACd,MAA6B,GAC9B,GAAE,2BAAgC,GAClC,sBAAsB,CAkHxB"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// Headless core of the approval dashboard: all data + interaction logic, no
|
|
2
|
+
// markup. A consumer can drive a fully custom UI from this hook alone, or use
|
|
3
|
+
// the slot-based views (App/QueueView/…) that render it through injected
|
|
4
|
+
// components. React-only (no DOM globals), but UI-pass-only — excluded from the
|
|
5
|
+
// main workers-typed tsc pass alongside the .tsx views.
|
|
6
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
7
|
+
import { OPEN_STATUSES } from '../approval-api/types.js';
|
|
8
|
+
import { sortQueue } from './view-model.js';
|
|
9
|
+
/**
|
|
10
|
+
* The dashboard's default queue slice: open (non-terminal) requests only,
|
|
11
|
+
* page-bounded at 100 in REVIEWER order. The bound is D3 — an unfiltered
|
|
12
|
+
* client.list() repeated every poll is a full-table scan on every open
|
|
13
|
+
* dashboard (2026-07-11 audit). orderBy: 'reviewer' makes the server rank
|
|
14
|
+
* priority → SLA → FIFO BEFORE cutting the page, so the 100 rows are the
|
|
15
|
+
* top of the queue — under the default FIFO cut, a fresh critical request
|
|
16
|
+
* beyond the oldest 100 never reached the dashboard at all (2026-07-11
|
|
17
|
+
* review). This is the fallback whenever a caller does not override
|
|
18
|
+
* UseApprovalDashboardOptions.filter.
|
|
19
|
+
*/
|
|
20
|
+
export const DEFAULT_QUEUE_FILTER = {
|
|
21
|
+
status: [...OPEN_STATUSES],
|
|
22
|
+
limit: 100,
|
|
23
|
+
orderBy: 'reviewer',
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Render-stable identity for a filter: its JSON serialization. The hook keys
|
|
27
|
+
* refresh() on this VALUE instead of the object reference, so the natural
|
|
28
|
+
* `useApprovalDashboard(client, { filter: { status: 'pending' } })` — a new
|
|
29
|
+
* object identity every render — polls on the configured interval instead of
|
|
30
|
+
* looping list/metrics requests back-to-back (2026-07-11 review), while a
|
|
31
|
+
* filter that CHANGES value still refetches immediately. Key order follows
|
|
32
|
+
* the caller's literal, which is constant across that caller's renders — the
|
|
33
|
+
* only stability this needs.
|
|
34
|
+
*/
|
|
35
|
+
export function approvalFilterKey(filter) {
|
|
36
|
+
return JSON.stringify(filter);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* One poll's worth of dashboard data. DOM-free and hook-free — pulled out of
|
|
40
|
+
* refresh() so the filter wiring (which ApprovalListFilter reaches
|
|
41
|
+
* client.list) is testable without mounting the hook (the package's default
|
|
42
|
+
* no-renderer stance; the one exception is
|
|
43
|
+
* use-approval-dashboard.render.test.ts, which mounts the hook on happy-dom
|
|
44
|
+
* to pin the dependency-identity wiring — see README). metrics() is
|
|
45
|
+
* deliberately called with no filter: it always summarizes the whole tenant
|
|
46
|
+
* queue, independent of the queue view's slice.
|
|
47
|
+
*/
|
|
48
|
+
export async function fetchDashboardSnapshot(client, filter) {
|
|
49
|
+
const [records, metrics] = await Promise.all([
|
|
50
|
+
client.list(filter),
|
|
51
|
+
client.metrics(),
|
|
52
|
+
]);
|
|
53
|
+
return { records, metrics };
|
|
54
|
+
}
|
|
55
|
+
export function useApprovalDashboard(client, { pollIntervalMs = 10_000, now = Date.now, filter = DEFAULT_QUEUE_FILTER, } = {}) {
|
|
56
|
+
const [records, setRecords] = useState([]);
|
|
57
|
+
const [metrics, setMetrics] = useState(null);
|
|
58
|
+
const [selectedId, setSelectedId] = useState(null);
|
|
59
|
+
const [error, setError] = useState(null);
|
|
60
|
+
const [busy, setBusy] = useState(false);
|
|
61
|
+
const [nowMs, setNowMs] = useState(now);
|
|
62
|
+
// Latest-ref for the injected clock: an inline `now` (a fixed test/story
|
|
63
|
+
// clock) is a new function identity every render — the same request-loop
|
|
64
|
+
// class as an inline filter, but a function cannot be value-keyed, so it
|
|
65
|
+
// rides a ref and refresh() reads it at call time.
|
|
66
|
+
const nowRef = useRef(now);
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
nowRef.current = now;
|
|
69
|
+
});
|
|
70
|
+
// Value identity for the filter (see approvalFilterKey): rebuilt from the
|
|
71
|
+
// key alone so the memo depends on nothing identity-unstable. Without
|
|
72
|
+
// this, an inline filter recreated refresh() every render, whose effect
|
|
73
|
+
// refetched immediately, whose state updates rendered again — an unbounded
|
|
74
|
+
// request loop that never reached the poll interval (2026-07-11 review).
|
|
75
|
+
const filterKey = approvalFilterKey(filter);
|
|
76
|
+
const stableFilter = useMemo(() => JSON.parse(filterKey), [filterKey]);
|
|
77
|
+
// `client` stays an identity dependency on purpose: a NEW client means a
|
|
78
|
+
// new endpoint/authorization (the showcase actor switcher), which must
|
|
79
|
+
// refetch immediately — unlike filter/now, its identity carries meaning.
|
|
80
|
+
const refresh = useCallback(async () => {
|
|
81
|
+
try {
|
|
82
|
+
const { records: nextRecords, metrics: nextMetrics } = await fetchDashboardSnapshot(client, stableFilter);
|
|
83
|
+
setRecords(nextRecords);
|
|
84
|
+
setMetrics(nextMetrics);
|
|
85
|
+
setNowMs(nowRef.current());
|
|
86
|
+
setError(null);
|
|
87
|
+
}
|
|
88
|
+
catch (cause) {
|
|
89
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
90
|
+
}
|
|
91
|
+
}, [client, stableFilter]);
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
void refresh();
|
|
94
|
+
if (pollIntervalMs <= 0)
|
|
95
|
+
return;
|
|
96
|
+
const timer = setInterval(() => {
|
|
97
|
+
void refresh();
|
|
98
|
+
}, pollIntervalMs);
|
|
99
|
+
return () => clearInterval(timer);
|
|
100
|
+
}, [refresh, pollIntervalMs]);
|
|
101
|
+
// Selection is derived — the queue refresh may change or remove the record.
|
|
102
|
+
const selected = records.find((record) => record.id === selectedId) ?? null;
|
|
103
|
+
const act = useCallback(async (action) => {
|
|
104
|
+
setBusy(true);
|
|
105
|
+
try {
|
|
106
|
+
await action();
|
|
107
|
+
await refresh();
|
|
108
|
+
}
|
|
109
|
+
catch (cause) {
|
|
110
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
setBusy(false);
|
|
114
|
+
}
|
|
115
|
+
}, [refresh]);
|
|
116
|
+
const decide = useCallback((decision, comment) => {
|
|
117
|
+
if (!selected)
|
|
118
|
+
return;
|
|
119
|
+
void act(() => client.decide(selected.id, decision, comment === '' ? undefined : comment));
|
|
120
|
+
}, [act, client, selected]);
|
|
121
|
+
const claim = useCallback(() => {
|
|
122
|
+
if (!selected)
|
|
123
|
+
return;
|
|
124
|
+
void act(() => client.claim(selected.id));
|
|
125
|
+
}, [act, client, selected]);
|
|
126
|
+
const delegate = useCallback((to) => {
|
|
127
|
+
if (!selected)
|
|
128
|
+
return;
|
|
129
|
+
void act(() => client.delegate(selected.id, to));
|
|
130
|
+
}, [act, client, selected]);
|
|
131
|
+
return {
|
|
132
|
+
// Idempotent under DEFAULT_QUEUE_FILTER (the server already returns
|
|
133
|
+
// reviewer order); load-bearing for caller filters without orderBy.
|
|
134
|
+
records: sortQueue(records),
|
|
135
|
+
metrics,
|
|
136
|
+
selected,
|
|
137
|
+
selectedId,
|
|
138
|
+
error,
|
|
139
|
+
busy,
|
|
140
|
+
nowMs,
|
|
141
|
+
select: setSelectedId,
|
|
142
|
+
decide,
|
|
143
|
+
claim,
|
|
144
|
+
delegate,
|
|
145
|
+
refresh,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=use-approval-dashboard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-approval-dashboard.js","sourceRoot":"","sources":["../../src/approval-ui/use-approval-dashboard.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,8EAA8E;AAC9E,yEAAyE;AACzE,gFAAgF;AAChF,wDAAwD;AAExD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAQ1E,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAuB;IACtD,MAAM,EAAE,CAAC,GAAG,aAAa,CAAC;IAC1B,KAAK,EAAE,GAAG;IACV,OAAO,EAAE,UAAU;CACpB,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAA0B;IAC1D,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,MAAmD,EACnD,MAA0B;IAE1B,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC3C,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;QACnB,MAAM,CAAC,OAAO,EAAE;KACjB,CAAC,CAAC;IACH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAC9B,CAAC;AAiCD,MAAM,UAAU,oBAAoB,CAClC,MAAyB,EACzB,EACE,cAAc,GAAG,M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KAAK;QACL,MAAM,EAAE,aAAa;QACrB,MAAM;QACN,KAAK;QACL,QAAQ;QACR,OAAO;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ApprovalRecord } from '../approval-api/types.js';
|
|
2
|
+
export type SlaState = 'none' | 'ok' | 'warning' | 'breached';
|
|
3
|
+
/** Remaining time under this threshold renders as a warning. */
|
|
4
|
+
export declare const DEFAULT_SLA_WARNING_MS: number;
|
|
5
|
+
/** Milliseconds until the SLA deadline (negative = overdue); null without one. */
|
|
6
|
+
export declare function msRemaining(record: Pick<ApprovalRecord, 'slaDeadlineAt'>, nowMs: number): number | null;
|
|
7
|
+
export declare function slaStateOf(record: Pick<ApprovalRecord, 'slaDeadlineAt'>, nowMs: number, warningMs?: number): SlaState;
|
|
8
|
+
/** '2d 4h' | '2h 5m' | '3m' | '45s' for a non-negative duration. */
|
|
9
|
+
export declare function formatDuration(ms: number): string;
|
|
10
|
+
/** Human SLA cell: 'no SLA' | '<duration> left' | 'overdue by <duration>'. */
|
|
11
|
+
export declare function formatSlaCountdown(record: Pick<ApprovalRecord, 'slaDeadlineAt'>, nowMs: number): string;
|
|
12
|
+
/**
|
|
13
|
+
* Reviewer-facing queue order: priority first, then nearest SLA deadline
|
|
14
|
+
* (records without one last), then FIFO. Delegates to the shared
|
|
15
|
+
* byReviewerOrder (approval-api/types.ts) — the SAME rule the stores apply
|
|
16
|
+
* server-side under ApprovalListFilter.orderBy: 'reviewer', so a bounded
|
|
17
|
+
* page and this client-side sort can never rank differently (2026-07-11
|
|
18
|
+
* review: a page cut in a different order hid high-priority records).
|
|
19
|
+
* Non-mutating.
|
|
20
|
+
*/
|
|
21
|
+
export declare function sortQueue(records: readonly ApprovalRecord[]): ApprovalRecord[];
|
|
22
|
+
/** Metrics cell for avgResolutionSeconds. */
|
|
23
|
+
export declare function formatResolution(seconds: number | null): string;
|
|
24
|
+
//# sourceMappingURL=view-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view-model.d.ts","sourceRoot":"","sources":["../../src/approval-ui/view-model.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,cAAc,EAAmB,MAAM,0BAA0B,CAAC;AAEhF,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,UAAU,CAAC;AAE9D,gEAAgE;AAChE,eAAO,MAAM,sBAAsB,QAAiB,CAAC;AAErD,kFAAkF;AAClF,wBAAgB,WAAW,CACzB,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,eAAe,CAAC,EAC7C,KAAK,EAAE,MAAM,GACZ,MAAM,GAAG,IAAI,CAGf;AAED,wBAAgB,UAAU,CACxB,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,eAAe,CAAC,EAC7C,KAAK,EAAE,MAAM,EACb,SAAS,GAAE,MAA+B,GACzC,QAAQ,CAKV;AAED,oEAAoE;AACpE,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CASjD;AAED,8EAA8E;AAC9E,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,eAAe,CAAC,EAC7C,KAAK,EAAE,MAAM,GACZ,MAAM,CAKR;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,SAAS,cAAc,EAAE,GACjC,cAAc,EAAE,CAElB;AAED,6CAA6C;AAC7C,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAG/D"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Pure presentation logic for the dashboard — SLA math, queue ordering,
|
|
2
|
+
// formatting. Kept out of the components so it runs under plain vitest with
|
|
3
|
+
// no DOM, and the .tsx files stay declarative shells.
|
|
4
|
+
import { byReviewerOrder } from '../approval-api/types.js';
|
|
5
|
+
/** Remaining time under this threshold renders as a warning. */
|
|
6
|
+
export const DEFAULT_SLA_WARNING_MS = 15 * 60 * 1000;
|
|
7
|
+
/** Milliseconds until the SLA deadline (negative = overdue); null without one. */
|
|
8
|
+
export function msRemaining(record, nowMs) {
|
|
9
|
+
if (record.slaDeadlineAt === undefined)
|
|
10
|
+
return null;
|
|
11
|
+
return Date.parse(record.slaDeadlineAt) - nowMs;
|
|
12
|
+
}
|
|
13
|
+
export function slaStateOf(record, nowMs, warningMs = DEFAULT_SLA_WARNING_MS) {
|
|
14
|
+
const remaining = msRemaining(record, nowMs);
|
|
15
|
+
if (remaining === null)
|
|
16
|
+
return 'none';
|
|
17
|
+
if (remaining <= 0)
|
|
18
|
+
return 'breached';
|
|
19
|
+
return remaining <= warningMs ? 'warning' : 'ok';
|
|
20
|
+
}
|
|
21
|
+
/** '2d 4h' | '2h 5m' | '3m' | '45s' for a non-negative duration. */
|
|
22
|
+
export function formatDuration(ms) {
|
|
23
|
+
const seconds = Math.floor(Math.max(0, ms) / 1000);
|
|
24
|
+
const days = Math.floor(seconds / 86400);
|
|
25
|
+
const hours = Math.floor((seconds % 86400) / 3600);
|
|
26
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
27
|
+
if (days > 0)
|
|
28
|
+
return `${days}d ${hours}h`;
|
|
29
|
+
if (hours > 0)
|
|
30
|
+
return `${hours}h ${minutes}m`;
|
|
31
|
+
if (minutes > 0)
|
|
32
|
+
return `${minutes}m`;
|
|
33
|
+
return `${seconds % 60}s`;
|
|
34
|
+
}
|
|
35
|
+
/** Human SLA cell: 'no SLA' | '<duration> left' | 'overdue by <duration>'. */
|
|
36
|
+
export function formatSlaCountdown(record, nowMs) {
|
|
37
|
+
const remaining = msRemaining(record, nowMs);
|
|
38
|
+
if (remaining === null)
|
|
39
|
+
return 'no SLA';
|
|
40
|
+
if (remaining <= 0)
|
|
41
|
+
return `overdue by ${formatDuration(-remaining)}`;
|
|
42
|
+
return `${formatDuration(remaining)} left`;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Reviewer-facing queue order: priority first, then nearest SLA deadline
|
|
46
|
+
* (records without one last), then FIFO. Delegates to the shared
|
|
47
|
+
* byReviewerOrder (approval-api/types.ts) — the SAME rule the stores apply
|
|
48
|
+
* server-side under ApprovalListFilter.orderBy: 'reviewer', so a bounded
|
|
49
|
+
* page and this client-side sort can never rank differently (2026-07-11
|
|
50
|
+
* review: a page cut in a different order hid high-priority records).
|
|
51
|
+
* Non-mutating.
|
|
52
|
+
*/
|
|
53
|
+
export function sortQueue(records) {
|
|
54
|
+
return [...records].sort(byReviewerOrder);
|
|
55
|
+
}
|
|
56
|
+
/** Metrics cell for avgResolutionSeconds. */
|
|
57
|
+
export function formatResolution(seconds) {
|
|
58
|
+
if (seconds === null)
|
|
59
|
+
return '—';
|
|
60
|
+
return formatDuration(seconds * 1000);
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=view-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view-model.js","sourceRoot":"","sources":["../../src/approval-ui/view-model.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,4EAA4E;AAC5E,sDAAsD;AAEtD,OAAO,EAAuB,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAIhF,gEAAgE;AAChE,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAErD,kFAAkF;AAClF,MAAM,UAAU,WAAW,CACzB,MAA6C,EAC7C,KAAa;IAEb,IAAI,MAAM,CAAC,aAAa,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACpD,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,KAAK,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,UAAU,CACxB,MAA6C,EAC7C,KAAa,EACb,YAAoB,sBAAsB;IAE1C,MAAM,SAAS,GAAG,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC7C,IAAI,SAAS,KAAK,IAAI;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AC,OAAO,CAAC;AAC7C,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CACvB,OAAkC;IAElC,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;AAC5C,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,gBAAgB,CAAC,OAAsB;IACrD,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,GAAG,CAAC;IACjC,OAAO,cAAc,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/** Bodies R2's put() accepts; the in-memory bucket normalizes them all. */
|
|
2
|
+
export type ArtifactBody = string | ArrayBuffer | ArrayBufferView | Blob | ReadableStream;
|
|
3
|
+
/** Structural subset of an R2Object (list results, put's return). */
|
|
4
|
+
export interface ArtifactBucketObject {
|
|
5
|
+
readonly key: string;
|
|
6
|
+
readonly size: number;
|
|
7
|
+
readonly uploaded: Date;
|
|
8
|
+
readonly httpMetadata?: {
|
|
9
|
+
contentType?: string;
|
|
10
|
+
};
|
|
11
|
+
readonly customMetadata?: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
/** Structural subset of an R2ObjectBody (get's return). */
|
|
14
|
+
export interface ArtifactBucketObjectBody extends ArtifactBucketObject {
|
|
15
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
16
|
+
text(): Promise<string>;
|
|
17
|
+
}
|
|
18
|
+
export interface ArtifactBucketListResult {
|
|
19
|
+
objects: ArtifactBucketObject[];
|
|
20
|
+
truncated: boolean;
|
|
21
|
+
cursor?: string;
|
|
22
|
+
}
|
|
23
|
+
/** Structural subset of a Cloudflare R2Bucket binding. */
|
|
24
|
+
export interface ArtifactBucket {
|
|
25
|
+
put(key: string, value: ArtifactBody, options?: {
|
|
26
|
+
httpMetadata?: {
|
|
27
|
+
contentType?: string;
|
|
28
|
+
};
|
|
29
|
+
customMetadata?: Record<string, string>;
|
|
30
|
+
}): Promise<ArtifactBucketObject | null>;
|
|
31
|
+
get(key: string): Promise<ArtifactBucketObjectBody | null>;
|
|
32
|
+
delete(key: string): Promise<void>;
|
|
33
|
+
list(options?: {
|
|
34
|
+
prefix?: string;
|
|
35
|
+
cursor?: string;
|
|
36
|
+
}): Promise<ArtifactBucketListResult>;
|
|
37
|
+
}
|
|
38
|
+
export interface ArtifactRef {
|
|
39
|
+
workflowId: string;
|
|
40
|
+
runId: string;
|
|
41
|
+
/** Path-safe segments joined by '/', e.g. 'reports/summary.md'. */
|
|
42
|
+
name: string;
|
|
43
|
+
}
|
|
44
|
+
export interface ArtifactRecord extends ArtifactRef {
|
|
45
|
+
/** Full object key: `[keyPrefix/]workflowId/runId/name`. */
|
|
46
|
+
key: string;
|
|
47
|
+
size?: number;
|
|
48
|
+
contentType?: string;
|
|
49
|
+
/** ISO 8601. */
|
|
50
|
+
uploadedAt?: string;
|
|
51
|
+
metadata?: Record<string, string>;
|
|
52
|
+
}
|
|
53
|
+
export interface PutArtifactOptions {
|
|
54
|
+
contentType?: string;
|
|
55
|
+
metadata?: Record<string, string>;
|
|
56
|
+
}
|
|
57
|
+
export interface ArtifactContent {
|
|
58
|
+
record: ArtifactRecord;
|
|
59
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
60
|
+
text(): Promise<string>;
|
|
61
|
+
}
|
|
62
|
+
export interface ListArtifactsScope {
|
|
63
|
+
workflowId: string;
|
|
64
|
+
runId: string;
|
|
65
|
+
/** Optional name prefix filter, e.g. 'reports/'. */
|
|
66
|
+
namePrefix?: string;
|
|
67
|
+
}
|
|
68
|
+
export declare class InvalidArtifactRefError extends Error {
|
|
69
|
+
constructor(message: string);
|
|
70
|
+
}
|
|
71
|
+
export interface R2ArtifactStoreOptions {
|
|
72
|
+
/** Keyspace prefix inside the bucket, e.g. 'artifacts'. Default: none. */
|
|
73
|
+
keyPrefix?: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Workflow artifact store over an R2 bucket (or any ArtifactBucket, e.g.
|
|
77
|
+
* InMemoryArtifactBucket in tests/dev). Typical step usage:
|
|
78
|
+
*
|
|
79
|
+
* const artifacts = new R2ArtifactStore(env.ARTIFACTS);
|
|
80
|
+
* await artifacts.put(
|
|
81
|
+
* { workflowId, runId, name: 'reports/summary.md' },
|
|
82
|
+
* markdown,
|
|
83
|
+
* { contentType: 'text/markdown' },
|
|
84
|
+
* );
|
|
85
|
+
*/
|
|
86
|
+
export declare class R2ArtifactStore {
|
|
87
|
+
#private;
|
|
88
|
+
constructor(bucket: ArtifactBucket, options?: R2ArtifactStoreOptions);
|
|
89
|
+
put(ref: ArtifactRef, body: ArtifactBody, options?: PutArtifactOptions): Promise<ArtifactRecord>;
|
|
90
|
+
get(ref: ArtifactRef): Promise<ArtifactContent | undefined>;
|
|
91
|
+
/** All artifacts of a run (cursor pagination drained), sorted by name. */
|
|
92
|
+
list(scope: ListArtifactsScope): Promise<ArtifactRecord[]>;
|
|
93
|
+
delete(ref: ArtifactRef): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Delete every artifact of a run; returns the count. Idempotent (a
|
|
96
|
+
* deleted run lists nothing). The purges call it: pass this store as
|
|
97
|
+
* `artifactStore` to BOTH purgeExpiredWorkflowRuns (per aged-out run,
|
|
98
|
+
* with its snapshot row) and purgeTenant (per surviving run at
|
|
99
|
+
* offboarding) — the snapshot rows are the only enumerable record of a
|
|
100
|
+
* run's artifact keys, so an unpaired retention purge strands them.
|
|
101
|
+
*/
|
|
102
|
+
deleteRun(workflowId: string, runId: string): Promise<number>;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* ArtifactBucket for tests and local dev — same subset R2 implements, one
|
|
106
|
+
* page per list() (truncated: false), bodies normalized to bytes on put.
|
|
107
|
+
*/
|
|
108
|
+
export declare class InMemoryArtifactBucket implements ArtifactBucket {
|
|
109
|
+
#private;
|
|
110
|
+
put(key: string, value: ArtifactBody, options?: {
|
|
111
|
+
httpMetadata?: {
|
|
112
|
+
contentType?: string;
|
|
113
|
+
};
|
|
114
|
+
customMetadata?: Record<string, string>;
|
|
115
|
+
}): Promise<ArtifactBucketObject | null>;
|
|
116
|
+
get(key: string): Promise<ArtifactBucketObjectBody | null>;
|
|
117
|
+
delete(key: string): Promise<void>;
|
|
118
|
+
list(options?: {
|
|
119
|
+
prefix?: string;
|
|
120
|
+
cursor?: string;
|
|
121
|
+
}): Promise<ArtifactBucketListResult>;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/artifacts/index.ts"],"names":[],"mappings":"AAiBA,2EAA2E;AAC3E,MAAM,MAAM,YAAY,GACpB,MAAM,GACN,WAAW,GACX,eAAe,GACf,IAAI,GACJ,cAAc,CAAC;AAEnB,qEAAqE;AACrE,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC;IACxB,QAAQ,CAAC,YAAY,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACjD,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClD;AAED,2DAA2D;AAC3D,MAAM,WAAW,wBAAyB,SAAQ,oBAAoB;IACpE,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IACpC,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACzB;AAED,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,oBAAoB,EAAE,CAAC;IAChC,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,0DAA0D;AAC1D,MAAM,WAAW,cAAc;IAC7B,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