@dads-framework/http 0.4.0 → 0.5.1
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 +90 -1
- package/dist/channels/channel-fan-out.d.ts +17 -0
- package/dist/channels/channel-fan-out.d.ts.map +1 -0
- package/dist/channels/channel-fan-out.js +2 -0
- package/dist/channels/channel-fan-out.js.map +1 -0
- package/dist/channels/channel-stream-routes.d.ts +33 -0
- package/dist/channels/channel-stream-routes.d.ts.map +1 -0
- package/dist/channels/channel-stream-routes.js +186 -0
- package/dist/channels/channel-stream-routes.js.map +1 -0
- package/dist/channels/in-process-channel-fan-out.d.ts +33 -0
- package/dist/channels/in-process-channel-fan-out.d.ts.map +1 -0
- package/dist/channels/in-process-channel-fan-out.js +115 -0
- package/dist/channels/in-process-channel-fan-out.js.map +1 -0
- package/dist/channels/index.d.ts +4 -0
- package/dist/channels/index.d.ts.map +1 -0
- package/dist/channels/index.js +4 -0
- package/dist/channels/index.js.map +1 -0
- package/dist/http.tsbuildinfo +1 -1
- package/dist/live-actions/execute-live-action.d.ts +26 -0
- package/dist/live-actions/execute-live-action.d.ts.map +1 -0
- package/dist/live-actions/execute-live-action.js +94 -0
- package/dist/live-actions/execute-live-action.js.map +1 -0
- package/dist/live-actions/index.d.ts +7 -0
- package/dist/live-actions/index.d.ts.map +1 -0
- package/dist/live-actions/index.js +7 -0
- package/dist/live-actions/index.js.map +1 -0
- package/dist/live-actions/live-action-registry.d.ts +16 -0
- package/dist/live-actions/live-action-registry.d.ts.map +1 -0
- package/dist/live-actions/live-action-registry.js +33 -0
- package/dist/live-actions/live-action-registry.js.map +1 -0
- package/dist/live-actions/live-action-routes.d.ts +69 -0
- package/dist/live-actions/live-action-routes.d.ts.map +1 -0
- package/dist/live-actions/live-action-routes.js +187 -0
- package/dist/live-actions/live-action-routes.js.map +1 -0
- package/dist/live-actions/live-action-run-store.d.ts +16 -0
- package/dist/live-actions/live-action-run-store.d.ts.map +1 -0
- package/dist/live-actions/live-action-run-store.js +47 -0
- package/dist/live-actions/live-action-run-store.js.map +1 -0
- package/dist/live-actions/live-action.d.ts +65 -0
- package/dist/live-actions/live-action.d.ts.map +1 -0
- package/dist/live-actions/live-action.js +49 -0
- package/dist/live-actions/live-action.js.map +1 -0
- package/dist/live-actions/redact-input.d.ts +9 -0
- package/dist/live-actions/redact-input.d.ts.map +1 -0
- package/dist/live-actions/redact-input.js +88 -0
- package/dist/live-actions/redact-input.js.map +1 -0
- package/dist/testing/fake-channel-fan-out.d.ts +23 -0
- package/dist/testing/fake-channel-fan-out.d.ts.map +1 -0
- package/dist/testing/fake-channel-fan-out.js +28 -0
- package/dist/testing/fake-channel-fan-out.js.map +1 -0
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +1 -0
- package/dist/testing/index.js.map +1 -1
- package/package.json +11 -3
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { LiveActionCaller, LiveActionDefinition } from "./live-action.js";
|
|
2
|
+
import type { LiveActionRunRecord, LiveActionRunStore } from "./live-action-run-store.js";
|
|
3
|
+
export type LiveActionExecutionAuthorizer<TInput = unknown> = (input: {
|
|
4
|
+
readonly caller: LiveActionCaller;
|
|
5
|
+
readonly action: LiveActionDefinition<TInput>;
|
|
6
|
+
}) => Promise<boolean>;
|
|
7
|
+
export type ExecuteLiveActionOptions<TInput = unknown> = {
|
|
8
|
+
readonly action: LiveActionDefinition<TInput>;
|
|
9
|
+
readonly caller: LiveActionCaller;
|
|
10
|
+
readonly reason: string;
|
|
11
|
+
readonly input: unknown;
|
|
12
|
+
readonly store: LiveActionRunStore;
|
|
13
|
+
readonly canExecute: LiveActionExecutionAuthorizer<TInput>;
|
|
14
|
+
readonly signal?: AbortSignal;
|
|
15
|
+
readonly now?: () => Date;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Authorize, validate, audit, and execute a live operational action.
|
|
19
|
+
*
|
|
20
|
+
* Authorization runs before input parsing so unauthorized callers cannot probe
|
|
21
|
+
* action schemas. A `"running"` audit row with redacted input is persisted
|
|
22
|
+
* before `action.execute` runs, and the row is finalized as `"succeeded"` or
|
|
23
|
+
* `"failed"` with `finishedAt` once execution settles.
|
|
24
|
+
*/
|
|
25
|
+
export declare function executeLiveAction<TInput>(options: ExecuteLiveActionOptions<TInput>): Promise<LiveActionRunRecord>;
|
|
26
|
+
//# sourceMappingURL=execute-live-action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute-live-action.d.ts","sourceRoot":"","sources":["../../src/live-actions/execute-live-action.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAG1F,MAAM,MAAM,6BAA6B,CAAC,MAAM,GAAG,OAAO,IAAI,CAAC,KAAK,EAAE;IACpE,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAC;CAC/C,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAEvB,MAAM,MAAM,wBAAwB,CAAC,MAAM,GAAG,OAAO,IAAI;IACvD,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC9C,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAC;IACnC,QAAQ,CAAC,UAAU,EAAE,6BAA6B,CAAC,MAAM,CAAC,CAAC;IAC3D,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B,CAAC;AASF;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CAAC,MAAM,EAC5C,OAAO,EAAE,wBAAwB,CAAC,MAAM,CAAC,GACxC,OAAO,CAAC,mBAAmB,CAAC,CAsC9B"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { mintUuidV7 } from "@dads-framework/core/contract";
|
|
2
|
+
import { notFound, validation } from "@dads-framework/core/errors";
|
|
3
|
+
import { redactActionInput } from "./redact-input.js";
|
|
4
|
+
function formatErrorMessage(error) {
|
|
5
|
+
if (error instanceof Error) {
|
|
6
|
+
return error.message;
|
|
7
|
+
}
|
|
8
|
+
return String(error);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Authorize, validate, audit, and execute a live operational action.
|
|
12
|
+
*
|
|
13
|
+
* Authorization runs before input parsing so unauthorized callers cannot probe
|
|
14
|
+
* action schemas. A `"running"` audit row with redacted input is persisted
|
|
15
|
+
* before `action.execute` runs, and the row is finalized as `"succeeded"` or
|
|
16
|
+
* `"failed"` with `finishedAt` once execution settles.
|
|
17
|
+
*/
|
|
18
|
+
export async function executeLiveAction(options) {
|
|
19
|
+
const allowed = await options.canExecute({ caller: options.caller, action: options.action });
|
|
20
|
+
if (!allowed) {
|
|
21
|
+
throw notFound("LIVE_ACTION_NOT_FOUND", "Live action not found");
|
|
22
|
+
}
|
|
23
|
+
const parsed = options.action.inputSchema.safeParse(options.input);
|
|
24
|
+
if (!parsed.success) {
|
|
25
|
+
throw validation("LIVE_ACTION_INVALID_INPUT", "Live action input failed validation", {
|
|
26
|
+
issues: parsed.error.issues,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const clock = options.now ?? (() => new Date());
|
|
30
|
+
const startedAt = clock();
|
|
31
|
+
const runId = mintUuidV7(startedAt.getTime());
|
|
32
|
+
const redactedInput = redactActionInput(parsed.data, options.action.redactInput === undefined ? undefined : (value) => options.action.redactInput?.(value));
|
|
33
|
+
const initialRecord = {
|
|
34
|
+
id: runId,
|
|
35
|
+
actionName: options.action.name,
|
|
36
|
+
dangerLevel: options.action.dangerLevel,
|
|
37
|
+
actorType: options.caller.type,
|
|
38
|
+
actorId: options.caller.id,
|
|
39
|
+
reason: options.reason,
|
|
40
|
+
redactedInput,
|
|
41
|
+
outcome: "running",
|
|
42
|
+
summary: null,
|
|
43
|
+
errorMessage: null,
|
|
44
|
+
startedAt,
|
|
45
|
+
finishedAt: null,
|
|
46
|
+
};
|
|
47
|
+
await options.store.recordStart(initialRecord);
|
|
48
|
+
return runAndFinalize(options, parsed.data, initialRecord, clock);
|
|
49
|
+
}
|
|
50
|
+
async function runAndFinalize(options, parsedInput, initialRecord, clock) {
|
|
51
|
+
try {
|
|
52
|
+
const result = await options.action.execute({
|
|
53
|
+
input: parsedInput,
|
|
54
|
+
caller: options.caller,
|
|
55
|
+
reason: options.reason,
|
|
56
|
+
runId: initialRecord.id,
|
|
57
|
+
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
58
|
+
});
|
|
59
|
+
const finishedAt = clock();
|
|
60
|
+
await options.store.recordFinish({
|
|
61
|
+
id: initialRecord.id,
|
|
62
|
+
outcome: "succeeded",
|
|
63
|
+
summary: result.summary,
|
|
64
|
+
errorMessage: null,
|
|
65
|
+
finishedAt,
|
|
66
|
+
});
|
|
67
|
+
return {
|
|
68
|
+
...initialRecord,
|
|
69
|
+
outcome: "succeeded",
|
|
70
|
+
summary: result.summary,
|
|
71
|
+
errorMessage: null,
|
|
72
|
+
finishedAt,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
const finishedAt = clock();
|
|
77
|
+
const errorMessage = formatErrorMessage(error);
|
|
78
|
+
await options.store.recordFinish({
|
|
79
|
+
id: initialRecord.id,
|
|
80
|
+
outcome: "failed",
|
|
81
|
+
summary: null,
|
|
82
|
+
errorMessage,
|
|
83
|
+
finishedAt,
|
|
84
|
+
});
|
|
85
|
+
return {
|
|
86
|
+
...initialRecord,
|
|
87
|
+
outcome: "failed",
|
|
88
|
+
summary: null,
|
|
89
|
+
errorMessage,
|
|
90
|
+
finishedAt,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=execute-live-action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute-live-action.js","sourceRoot":"","sources":["../../src/live-actions/execute-live-action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAInE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAkBtD,SAAS,kBAAkB,CAAC,KAAc;IACxC,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC,OAAO,CAAC;IACvB,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAyC;IAEzC,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC7F,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,QAAQ,CAAC,uBAAuB,EAAE,uBAAuB,CAAC,CAAC;IACnE,CAAC;IAED,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACnE,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,UAAU,CAAC,2BAA2B,EAAE,qCAAqC,EAAE;YACnF,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM;SAC5B,CAA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LiveActionCaller, type LiveActionContext, type LiveActionDangerLevel, type LiveActionDefinition, type LiveActionOutcome, type LiveActionPermission, type LiveActionResourcePermission, type LiveActionResult, type LiveActionSpec, } from "./live-action.js";
|
|
2
|
+
export { createLiveActionRegistry, LiveActionRegistry } from "./live-action-registry.js";
|
|
3
|
+
export { redactActionInput } from "./redact-input.js";
|
|
4
|
+
export { InMemoryLiveActionRunStore, type FinishLiveActionRunInput, type ListLiveActionRunsOptions, type LiveActionRunRecord, type LiveActionRunStore, } from "./live-action-run-store.js";
|
|
5
|
+
export { executeLiveAction, type ExecuteLiveActionOptions, type LiveActionExecutionAuthorizer, } from "./execute-live-action.js";
|
|
6
|
+
export { createLiveActionRoutes, liveActionDangerLevelSchema, liveActionOutcomeSchema, liveActionRunSchema, liveActionSummarySchema, type LiveActionAuthorizeInput, type LiveActionRoutesOptions, type LiveActionRunDto, type LiveActionSummary, } from "./live-action-routes.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/live-actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,gBAAgB,EAChB,kCAAkC,EAClC,wBAAwB,EACxB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,4BAA4B,EACjC,KAAK,gBAAgB,EACrB,KAAK,cAAc,GACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EACL,0BAA0B,EAC1B,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,GACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,iBAAiB,EACjB,KAAK,wBAAwB,EAC7B,KAAK,6BAA6B,GACnC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,sBAAsB,EACtB,2BAA2B,EAC3B,uBAAuB,EACvB,mBAAmB,EACnB,uBAAuB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,GACvB,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { assertValidLiveActionMetadata, defineLiveAction, LIVE_ACTION_MIN_DESCRIPTION_LENGTH, LIVE_ACTION_NAME_PATTERN, } from "./live-action.js";
|
|
2
|
+
export { createLiveActionRegistry, LiveActionRegistry } from "./live-action-registry.js";
|
|
3
|
+
export { redactActionInput } from "./redact-input.js";
|
|
4
|
+
export { InMemoryLiveActionRunStore, } from "./live-action-run-store.js";
|
|
5
|
+
export { executeLiveAction, } from "./execute-live-action.js";
|
|
6
|
+
export { createLiveActionRoutes, liveActionDangerLevelSchema, liveActionOutcomeSchema, liveActionRunSchema, liveActionSummarySchema, } from "./live-action-routes.js";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/live-actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,gBAAgB,EAChB,kCAAkC,EAClC,wBAAwB,GAUzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EACL,0BAA0B,GAK3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,iBAAiB,GAGlB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,sBAAsB,EACtB,2BAA2B,EAC3B,uBAAuB,EACvB,mBAAmB,EACnB,uBAAuB,GAKxB,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type LiveActionDefinition } from "./live-action.js";
|
|
2
|
+
/**
|
|
3
|
+
* In-memory registry of live operational actions.
|
|
4
|
+
*
|
|
5
|
+
* Rejects duplicate names and invalid metadata at registration time so action
|
|
6
|
+
* wiring errors fail immediately during startup.
|
|
7
|
+
*/
|
|
8
|
+
export declare class LiveActionRegistry {
|
|
9
|
+
private readonly actions;
|
|
10
|
+
register<TInput>(action: LiveActionDefinition<TInput>): this;
|
|
11
|
+
get(name: string): LiveActionDefinition | undefined;
|
|
12
|
+
list(): readonly LiveActionDefinition[];
|
|
13
|
+
}
|
|
14
|
+
/** Create a registry optionally seeded with initial live action definitions. */
|
|
15
|
+
export declare function createLiveActionRegistry(actions?: readonly LiveActionDefinition[]): LiveActionRegistry;
|
|
16
|
+
//# sourceMappingURL=live-action-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-action-registry.d.ts","sourceRoot":"","sources":["../../src/live-actions/live-action-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,KAAK,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE5F;;;;;GAKG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2C;IAEnE,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,oBAAoB,CAAC,MAAM,CAAC,GAAG,IAAI,CAO3D;IAED,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS,CAElD;IAED,IAAI,IAAI,SAAS,oBAAoB,EAAE,CAEtC;CACF;AAED,gFAAgF;AAChF,wBAAgB,wBAAwB,CAAC,OAAO,GAAE,SAAS,oBAAoB,EAAO,GAAG,kBAAkB,CAM1G"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { assertValidLiveActionMetadata } from "./live-action.js";
|
|
2
|
+
/**
|
|
3
|
+
* In-memory registry of live operational actions.
|
|
4
|
+
*
|
|
5
|
+
* Rejects duplicate names and invalid metadata at registration time so action
|
|
6
|
+
* wiring errors fail immediately during startup.
|
|
7
|
+
*/
|
|
8
|
+
export class LiveActionRegistry {
|
|
9
|
+
actions = new Map();
|
|
10
|
+
register(action) {
|
|
11
|
+
assertValidLiveActionMetadata(action);
|
|
12
|
+
if (this.actions.has(action.name)) {
|
|
13
|
+
throw new Error(`Live action "${action.name}" is already registered`);
|
|
14
|
+
}
|
|
15
|
+
this.actions.set(action.name, action);
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
get(name) {
|
|
19
|
+
return this.actions.get(name);
|
|
20
|
+
}
|
|
21
|
+
list() {
|
|
22
|
+
return [...this.actions.values()];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** Create a registry optionally seeded with initial live action definitions. */
|
|
26
|
+
export function createLiveActionRegistry(actions = []) {
|
|
27
|
+
const registry = new LiveActionRegistry();
|
|
28
|
+
for (const action of actions) {
|
|
29
|
+
registry.register(action);
|
|
30
|
+
}
|
|
31
|
+
return registry;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=live-action-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-action-registry.js","sourceRoot":"","sources":["../../src/live-actions/live-action-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAA6B,MAAM,kBAAkB,CAAC;AAE5F;;;;;GAKG;AACH,MAAM,OAAO,kBAAkB;IACZ,OAAO,GAAG,IAAI,GAAG,EAAgC,CAAC;IAEnE,QAAQ,CAAS,MAAoC;QACnD,6BAA6B,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,gBAAgB,MAAM,CAAC,IAAI,yBAAyB,CAAC,CAAC;QACxE,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,IAAI;QACF,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACpC,CAAC;CACF;AAED,gFAAgF;AAChF,MAAM,UAAU,wBAAwB,CAAC,OAAO,GAAoC,EAAE;IACpF,MAAM,QAAQ,GAAG,IAAI,kBAAkB,EAAE,CAAC;IAC1C,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type HttpRoute } from "../lib/route/route-group.js";
|
|
3
|
+
import type { LiveActionCaller, LiveActionDefinition } from "./live-action.js";
|
|
4
|
+
import type { LiveActionRegistry } from "./live-action-registry.js";
|
|
5
|
+
import type { LiveActionRunStore } from "./live-action-run-store.js";
|
|
6
|
+
export declare const liveActionDangerLevelSchema: z.ZodEnum<{
|
|
7
|
+
cautious: "cautious";
|
|
8
|
+
destructive: "destructive";
|
|
9
|
+
safe: "safe";
|
|
10
|
+
}>;
|
|
11
|
+
export declare const liveActionOutcomeSchema: z.ZodEnum<{
|
|
12
|
+
failed: "failed";
|
|
13
|
+
running: "running";
|
|
14
|
+
succeeded: "succeeded";
|
|
15
|
+
}>;
|
|
16
|
+
export declare const liveActionSummarySchema: z.ZodObject<{
|
|
17
|
+
name: z.ZodString;
|
|
18
|
+
description: z.ZodString;
|
|
19
|
+
dangerLevel: z.ZodEnum<{
|
|
20
|
+
cautious: "cautious";
|
|
21
|
+
destructive: "destructive";
|
|
22
|
+
safe: "safe";
|
|
23
|
+
}>;
|
|
24
|
+
}, z.core.$strict>;
|
|
25
|
+
export type LiveActionSummary = z.infer<typeof liveActionSummarySchema>;
|
|
26
|
+
export declare const liveActionRunSchema: z.ZodObject<{
|
|
27
|
+
id: z.ZodString;
|
|
28
|
+
actionName: z.ZodString;
|
|
29
|
+
dangerLevel: z.ZodEnum<{
|
|
30
|
+
cautious: "cautious";
|
|
31
|
+
destructive: "destructive";
|
|
32
|
+
safe: "safe";
|
|
33
|
+
}>;
|
|
34
|
+
actorType: z.ZodString;
|
|
35
|
+
actorId: z.ZodString;
|
|
36
|
+
reason: z.ZodString;
|
|
37
|
+
redactedInput: z.ZodUnknown;
|
|
38
|
+
outcome: z.ZodEnum<{
|
|
39
|
+
failed: "failed";
|
|
40
|
+
running: "running";
|
|
41
|
+
succeeded: "succeeded";
|
|
42
|
+
}>;
|
|
43
|
+
summary: z.ZodNullable<z.ZodString>;
|
|
44
|
+
errorMessage: z.ZodNullable<z.ZodString>;
|
|
45
|
+
startedAt: z.ZodISODateTime;
|
|
46
|
+
finishedAt: z.ZodNullable<z.ZodISODateTime>;
|
|
47
|
+
}, z.core.$strict>;
|
|
48
|
+
export type LiveActionRunDto = z.infer<typeof liveActionRunSchema>;
|
|
49
|
+
export type LiveActionAuthorizeInput = {
|
|
50
|
+
readonly subject: LiveActionCaller;
|
|
51
|
+
readonly action: LiveActionDefinition;
|
|
52
|
+
};
|
|
53
|
+
export type LiveActionRoutesOptions = {
|
|
54
|
+
readonly registry: LiveActionRegistry;
|
|
55
|
+
readonly store: LiveActionRunStore;
|
|
56
|
+
readonly authorize: (input: LiveActionAuthorizeInput) => Promise<boolean>;
|
|
57
|
+
readonly basePath?: string;
|
|
58
|
+
readonly now?: () => Date;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Create the audited HTTP route group for listing, executing, and inspecting
|
|
62
|
+
* live operational actions.
|
|
63
|
+
*
|
|
64
|
+
* Every route requires an authenticated session and enforces per-action
|
|
65
|
+
* authorization. Unauthorized actions are omitted from lists and answered with
|
|
66
|
+
* 404 on execution or run lookup so their existence is never revealed.
|
|
67
|
+
*/
|
|
68
|
+
export declare function createLiveActionRoutes(options: LiveActionRoutesOptions): HttpRoute[];
|
|
69
|
+
//# sourceMappingURL=live-action-routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-action-routes.d.ts","sourceRoot":"","sources":["../../src/live-actions/live-action-routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB,OAAO,EAAc,KAAK,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAEzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAAuB,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAM1F,eAAO,MAAM,2BAA2B;;;;EAA8C,CAAC;AAEvF,eAAO,MAAM,uBAAuB;;;;EAA6C,CAAC;AAElF,eAAO,MAAM,uBAAuB;;;;;;;;kBAIlC,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;kBAa9B,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAoBnE,MAAM,MAAM,wBAAwB,GAAG;IACrC,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,CAAC;IACtC,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,wBAAwB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1E,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B,CAAC;AAgDF;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,SAAS,EAAE,CAmGpF"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { paginationQuerySchema } from "@dads-framework/core/contract";
|
|
3
|
+
import { notFound } from "@dads-framework/core/errors";
|
|
4
|
+
import { HttpWiringError } from "../lib/http-errors.js";
|
|
5
|
+
import { requireSession } from "../lib/route/access.js";
|
|
6
|
+
import { getRoute } from "../lib/route/get-route.js";
|
|
7
|
+
import { listRoute } from "../lib/route/list-route.js";
|
|
8
|
+
import { postRoute } from "../lib/route/post-route.js";
|
|
9
|
+
import { routeGroup } from "../lib/route/route-group.js";
|
|
10
|
+
import { executeLiveAction } from "./execute-live-action.js";
|
|
11
|
+
const DEFAULT_LIVE_ACTIONS_BASE_PATH = "/live-actions";
|
|
12
|
+
const MIN_REASON_LENGTH = 5;
|
|
13
|
+
const MAX_RUN_LIST_LIMIT = 100;
|
|
14
|
+
export const liveActionDangerLevelSchema = z.enum(["safe", "cautious", "destructive"]);
|
|
15
|
+
export const liveActionOutcomeSchema = z.enum(["running", "succeeded", "failed"]);
|
|
16
|
+
export const liveActionSummarySchema = z.strictObject({
|
|
17
|
+
name: z.string(),
|
|
18
|
+
description: z.string(),
|
|
19
|
+
dangerLevel: liveActionDangerLevelSchema,
|
|
20
|
+
});
|
|
21
|
+
export const liveActionRunSchema = z.strictObject({
|
|
22
|
+
id: z.string(),
|
|
23
|
+
actionName: z.string(),
|
|
24
|
+
dangerLevel: liveActionDangerLevelSchema,
|
|
25
|
+
actorType: z.string(),
|
|
26
|
+
actorId: z.string(),
|
|
27
|
+
reason: z.string(),
|
|
28
|
+
redactedInput: z.unknown(),
|
|
29
|
+
outcome: liveActionOutcomeSchema,
|
|
30
|
+
summary: z.string().nullable(),
|
|
31
|
+
errorMessage: z.string().nullable(),
|
|
32
|
+
startedAt: z.iso.datetime(),
|
|
33
|
+
finishedAt: z.iso.datetime().nullable(),
|
|
34
|
+
});
|
|
35
|
+
const runLiveActionParamsSchema = z.strictObject({
|
|
36
|
+
name: z.string().min(1),
|
|
37
|
+
});
|
|
38
|
+
const runLiveActionBodySchema = z.strictObject({
|
|
39
|
+
reason: z.string().trim().min(MIN_REASON_LENGTH),
|
|
40
|
+
input: z.unknown().optional(),
|
|
41
|
+
});
|
|
42
|
+
const listLiveActionRunsQuerySchema = paginationQuerySchema.extend({
|
|
43
|
+
actionName: z.string().trim().min(1).optional(),
|
|
44
|
+
limit: z.coerce.number().int().min(1).max(MAX_RUN_LIST_LIMIT).optional(),
|
|
45
|
+
});
|
|
46
|
+
const getLiveActionRunParamsSchema = z.strictObject({
|
|
47
|
+
runId: z.string().min(1),
|
|
48
|
+
});
|
|
49
|
+
function normalizeBasePath(basePath) {
|
|
50
|
+
const raw = basePath ?? DEFAULT_LIVE_ACTIONS_BASE_PATH;
|
|
51
|
+
const trimmed = raw.endsWith("/") && raw.length > 1 ? raw.replace(/\/+$/, "") : raw;
|
|
52
|
+
if (!trimmed.startsWith("/") || trimmed.startsWith("//") || trimmed === "/") {
|
|
53
|
+
throw new HttpWiringError(`Live actions basePath must be a non-root mount-relative path, received "${raw}"`);
|
|
54
|
+
}
|
|
55
|
+
return trimmed;
|
|
56
|
+
}
|
|
57
|
+
function serializeRun(run) {
|
|
58
|
+
return {
|
|
59
|
+
id: run.id,
|
|
60
|
+
actionName: run.actionName,
|
|
61
|
+
dangerLevel: run.dangerLevel,
|
|
62
|
+
actorType: run.actorType,
|
|
63
|
+
actorId: run.actorId,
|
|
64
|
+
reason: run.reason,
|
|
65
|
+
redactedInput: run.redactedInput,
|
|
66
|
+
outcome: run.outcome,
|
|
67
|
+
summary: run.summary,
|
|
68
|
+
errorMessage: run.errorMessage,
|
|
69
|
+
startedAt: run.startedAt.toISOString(),
|
|
70
|
+
finishedAt: run.finishedAt === null ? null : run.finishedAt.toISOString(),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async function listAuthorizedActions(registry, authorize, subject) {
|
|
74
|
+
const authorized = [];
|
|
75
|
+
for (const action of registry.list()) {
|
|
76
|
+
const allowed = await authorize({ subject, action });
|
|
77
|
+
if (allowed) {
|
|
78
|
+
authorized.push(action);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return authorized;
|
|
82
|
+
}
|
|
83
|
+
function paginateItems(items, page, perPage) {
|
|
84
|
+
const start = (page - 1) * perPage;
|
|
85
|
+
return items.slice(start, start + perPage);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Create the audited HTTP route group for listing, executing, and inspecting
|
|
89
|
+
* live operational actions.
|
|
90
|
+
*
|
|
91
|
+
* Every route requires an authenticated session and enforces per-action
|
|
92
|
+
* authorization. Unauthorized actions are omitted from lists and answered with
|
|
93
|
+
* 404 on execution or run lookup so their existence is never revealed.
|
|
94
|
+
*/
|
|
95
|
+
export function createLiveActionRoutes(options) {
|
|
96
|
+
const basePath = normalizeBasePath(options.basePath);
|
|
97
|
+
const listActionsRoute = listRoute({
|
|
98
|
+
route: { method: "GET", template: basePath },
|
|
99
|
+
summary: "List live operational actions authorized for the current caller",
|
|
100
|
+
access: requireSession(),
|
|
101
|
+
query: paginationQuerySchema,
|
|
102
|
+
item: liveActionSummarySchema,
|
|
103
|
+
handler: async ({ subject, query }) => {
|
|
104
|
+
const actions = await listAuthorizedActions(options.registry, options.authorize, subject);
|
|
105
|
+
const summaries = actions.map((action) => ({
|
|
106
|
+
name: action.name,
|
|
107
|
+
description: action.description,
|
|
108
|
+
dangerLevel: action.dangerLevel,
|
|
109
|
+
}));
|
|
110
|
+
return {
|
|
111
|
+
items: paginateItems(summaries, query.page, query.perPage),
|
|
112
|
+
total: summaries.length,
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
const executeActionRoute = postRoute({
|
|
117
|
+
route: { method: "POST", template: `${basePath}/:name/runs` },
|
|
118
|
+
summary: "Execute a live operational action and persist its audit run record",
|
|
119
|
+
access: requireSession(),
|
|
120
|
+
params: runLiveActionParamsSchema,
|
|
121
|
+
body: runLiveActionBodySchema,
|
|
122
|
+
response: liveActionRunSchema,
|
|
123
|
+
handler: async ({ subject, params, body }) => {
|
|
124
|
+
const action = options.registry.get(params.name);
|
|
125
|
+
if (action === undefined) {
|
|
126
|
+
throw notFound("LIVE_ACTION_NOT_FOUND", "Live action not found");
|
|
127
|
+
}
|
|
128
|
+
const run = await executeLiveAction({
|
|
129
|
+
action,
|
|
130
|
+
caller: subject,
|
|
131
|
+
reason: body.reason,
|
|
132
|
+
input: body.input,
|
|
133
|
+
store: options.store,
|
|
134
|
+
canExecute: ({ caller, action: target }) => options.authorize({ subject: caller, action: target }),
|
|
135
|
+
...(options.now === undefined ? {} : { now: options.now }),
|
|
136
|
+
});
|
|
137
|
+
return serializeRun(run);
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
const listRunsRoute = listRoute({
|
|
141
|
+
route: { method: "GET", template: `${basePath}/runs` },
|
|
142
|
+
summary: "List recent live action runs for actions authorized to the caller",
|
|
143
|
+
access: requireSession(),
|
|
144
|
+
query: listLiveActionRunsQuerySchema,
|
|
145
|
+
item: liveActionRunSchema,
|
|
146
|
+
handler: async ({ subject, query }) => {
|
|
147
|
+
const authorizedActions = await listAuthorizedActions(options.registry, options.authorize, subject);
|
|
148
|
+
const authorizedNames = new Set(authorizedActions.map((action) => action.name));
|
|
149
|
+
if (query.actionName !== undefined && !authorizedNames.has(query.actionName)) {
|
|
150
|
+
return { items: [], total: 0 };
|
|
151
|
+
}
|
|
152
|
+
const runs = await options.store.listRecent(query.actionName === undefined ? undefined : { actionName: query.actionName });
|
|
153
|
+
const visibleRuns = runs.filter((run) => authorizedNames.has(run.actionName));
|
|
154
|
+
const pageItems = query.limit === undefined
|
|
155
|
+
? paginateItems(visibleRuns, query.page, query.perPage)
|
|
156
|
+
: visibleRuns.slice(0, query.limit);
|
|
157
|
+
return {
|
|
158
|
+
items: pageItems.map(serializeRun),
|
|
159
|
+
total: visibleRuns.length,
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
const getRunRoute = getRoute({
|
|
164
|
+
route: { method: "GET", template: `${basePath}/runs/:runId` },
|
|
165
|
+
summary: "Read a single live action run if authorized for its action",
|
|
166
|
+
access: requireSession(),
|
|
167
|
+
params: getLiveActionRunParamsSchema,
|
|
168
|
+
response: liveActionRunSchema,
|
|
169
|
+
handler: async ({ subject, params }) => {
|
|
170
|
+
const run = await options.store.getById(params.runId);
|
|
171
|
+
if (run === undefined) {
|
|
172
|
+
throw notFound("LIVE_ACTION_RUN_NOT_FOUND", "Live action run not found");
|
|
173
|
+
}
|
|
174
|
+
const action = options.registry.get(run.actionName);
|
|
175
|
+
if (action === undefined) {
|
|
176
|
+
throw notFound("LIVE_ACTION_RUN_NOT_FOUND", "Live action run not found");
|
|
177
|
+
}
|
|
178
|
+
const allowed = await options.authorize({ subject, action });
|
|
179
|
+
if (!allowed) {
|
|
180
|
+
throw notFound("LIVE_ACTION_RUN_NOT_FOUND", "Live action run not found");
|
|
181
|
+
}
|
|
182
|
+
return serializeRun(run);
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
return routeGroup("Live Actions", [listActionsRoute, executeActionRoute, listRunsRoute, getRunRoute]);
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=live-action-routes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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,CAAC,CAAC;YAC3E,CAAC;YACD,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;YAC7D,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,MAAM,QAAQ,CAAC,2BAA2B,EAAE,2BAA2B,CAAC,CAAC;YAC3E,CAAC;YACD,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;QAC3B,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,UAAU,CAAC,cAAc,EAAE,CAAC,gBAAgB,EAAE,kBAAkB,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC,CAAC;AACxG,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FinishLiveActionRunInput, ListRecentLiveActionRunsOptions, LiveActionRunRecord, LiveActionRunStore } from "@dads-framework/core/contract";
|
|
2
|
+
export type { FinishLiveActionRunInput, LiveActionRunRecord, LiveActionRunStore };
|
|
3
|
+
export type ListLiveActionRunsOptions = ListRecentLiveActionRunsOptions;
|
|
4
|
+
/**
|
|
5
|
+
* In-memory implementation of {@link LiveActionRunStore} for tests and
|
|
6
|
+
* single-process deployments.
|
|
7
|
+
*/
|
|
8
|
+
export declare class InMemoryLiveActionRunStore implements LiveActionRunStore {
|
|
9
|
+
private readonly entries;
|
|
10
|
+
private nextSequence;
|
|
11
|
+
recordStart(run: LiveActionRunRecord): Promise<void>;
|
|
12
|
+
recordFinish(input: FinishLiveActionRunInput): Promise<void>;
|
|
13
|
+
getById(id: string): Promise<LiveActionRunRecord | undefined>;
|
|
14
|
+
listRecent(options?: ListLiveActionRunsOptions): Promise<readonly LiveActionRunRecord[]>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=live-action-run-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-action-run-store.d.ts","sourceRoot":"","sources":["../../src/live-actions/live-action-run-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,+BAA+B,EAC/B,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,+BAA+B,CAAC;AAEvC,YAAY,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;AAClF,MAAM,MAAM,yBAAyB,GAAG,+BAA+B,CAAC;AAOxE;;;GAGG;AACH,qBAAa,0BAA2B,YAAW,kBAAkB;IACnE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkC;IAC1D,OAAO,CAAC,YAAY,CAAK;IAEzB,WAAW,CAAC,GAAG,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAUnD;IAED,YAAY,CAAC,KAAK,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgB3D;IAED,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAG5D;IAED,UAAU,CAAC,OAAO,GAAE,yBAA8B,GAAG,OAAO,CAAC,SAAS,mBAAmB,EAAE,CAAC,CAU3F;CACF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory implementation of {@link LiveActionRunStore} for tests and
|
|
3
|
+
* single-process deployments.
|
|
4
|
+
*/
|
|
5
|
+
export class InMemoryLiveActionRunStore {
|
|
6
|
+
entries = new Map();
|
|
7
|
+
nextSequence = 0;
|
|
8
|
+
recordStart(run) {
|
|
9
|
+
if (this.entries.has(run.id)) {
|
|
10
|
+
return Promise.reject(new Error(`Live action run "${run.id}" already exists`));
|
|
11
|
+
}
|
|
12
|
+
this.nextSequence += 1;
|
|
13
|
+
this.entries.set(run.id, {
|
|
14
|
+
sequence: this.nextSequence,
|
|
15
|
+
record: { ...run },
|
|
16
|
+
});
|
|
17
|
+
return Promise.resolve();
|
|
18
|
+
}
|
|
19
|
+
recordFinish(input) {
|
|
20
|
+
const existing = this.entries.get(input.id);
|
|
21
|
+
if (existing === undefined) {
|
|
22
|
+
return Promise.reject(new Error(`Live action run "${input.id}" does not exist`));
|
|
23
|
+
}
|
|
24
|
+
this.entries.set(input.id, {
|
|
25
|
+
sequence: existing.sequence,
|
|
26
|
+
record: {
|
|
27
|
+
...existing.record,
|
|
28
|
+
outcome: input.outcome,
|
|
29
|
+
summary: input.summary,
|
|
30
|
+
errorMessage: input.errorMessage,
|
|
31
|
+
finishedAt: input.finishedAt,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
return Promise.resolve();
|
|
35
|
+
}
|
|
36
|
+
getById(id) {
|
|
37
|
+
const entry = this.entries.get(id);
|
|
38
|
+
return Promise.resolve(entry === undefined ? undefined : { ...entry.record });
|
|
39
|
+
}
|
|
40
|
+
listRecent(options = {}) {
|
|
41
|
+
const filtered = [...this.entries.values()].filter((entry) => options.actionName === undefined || entry.record.actionName === options.actionName);
|
|
42
|
+
filtered.sort((left, right) => right.record.startedAt.getTime() - left.record.startedAt.getTime() || right.sequence - left.sequence);
|
|
43
|
+
const limited = options.limit === undefined ? filtered : filtered.slice(0, Math.max(0, Math.floor(options.limit)));
|
|
44
|
+
return Promise.resolve(limited.map((entry) => ({ ...entry.record })));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=live-action-run-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-action-run-store.js","sourceRoot":"","sources":["../../src/live-actions/live-action-run-store.ts"],"names":[],"mappings":"AAeA;;;GAGG;AACH,MAAM,OAAO,0BAA0B;IACpB,OAAO,GAAG,IAAI,GAAG,EAAuB,CAAC;IAClD,YAAY,GAAG,CAAC,CAAC;IAEzB,WAAW,CAAC,GAAwB;QAClC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YAC7B,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,oBAAoB,GAAG,CAAC,EAAE,kBAAkB,CAAC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A8B,EAAE;QAChD,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAChD,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,CAAC,UAAU,KAAK,OAAO,CAAC,UAAU,CAC9F,CAAC;QACF,QAAQ,CAAC,IAAI,CACX,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CACd,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CACvG,CAAC;QACF,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACnH,OAAO,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;IACxE,CAAC;CACF"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import { type PermissionToken } from "@dads-framework/access";
|
|
3
|
+
import type { LiveActionDangerLevel, LiveActionRunOutcome } from "@dads-framework/core/contract";
|
|
4
|
+
/** Valid action name format: lowercase dot/hyphen-separated segments (e.g. `cache.clear`, `billing.reconcile-invoices`). */
|
|
5
|
+
export declare const LIVE_ACTION_NAME_PATTERN: RegExp;
|
|
6
|
+
/** Minimum length of a live action description so operators always see clear intent. */
|
|
7
|
+
export declare const LIVE_ACTION_MIN_DESCRIPTION_LENGTH = 10;
|
|
8
|
+
export type { LiveActionDangerLevel };
|
|
9
|
+
export type LiveActionOutcome = LiveActionRunOutcome;
|
|
10
|
+
export type LiveActionCaller = {
|
|
11
|
+
readonly type: string;
|
|
12
|
+
readonly id: string;
|
|
13
|
+
};
|
|
14
|
+
export type LiveActionContext<TInput> = {
|
|
15
|
+
readonly input: TInput;
|
|
16
|
+
readonly caller: LiveActionCaller;
|
|
17
|
+
readonly reason: string;
|
|
18
|
+
readonly runId: string;
|
|
19
|
+
readonly signal?: AbortSignal;
|
|
20
|
+
};
|
|
21
|
+
export type LiveActionResult = {
|
|
22
|
+
readonly summary: string;
|
|
23
|
+
readonly details?: Readonly<Record<string, unknown>>;
|
|
24
|
+
};
|
|
25
|
+
export type LiveActionResourcePermission = {
|
|
26
|
+
readonly entity: string;
|
|
27
|
+
readonly permission: string;
|
|
28
|
+
readonly resourceId: string;
|
|
29
|
+
};
|
|
30
|
+
export type LiveActionPermission = PermissionToken | LiveActionResourcePermission;
|
|
31
|
+
export type LiveActionSpec<TInput> = {
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly description: string;
|
|
34
|
+
readonly dangerLevel: LiveActionDangerLevel;
|
|
35
|
+
readonly permission: LiveActionPermission;
|
|
36
|
+
readonly inputSchema: z.ZodType<TInput>;
|
|
37
|
+
readonly redactInput?: (input: TInput) => unknown;
|
|
38
|
+
readonly execute: (context: LiveActionContext<TInput>) => Promise<LiveActionResult>;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Validated live-action definition.
|
|
42
|
+
*
|
|
43
|
+
* Method syntax on `execute` and `redactInput` preserves typed action specs at
|
|
44
|
+
* definition sites while allowing heterogeneously typed actions to be stored in
|
|
45
|
+
* a single {@link LiveActionRegistry} after boundary validation via `inputSchema`.
|
|
46
|
+
*/
|
|
47
|
+
export type LiveActionDefinition<TInput = unknown> = {
|
|
48
|
+
readonly name: string;
|
|
49
|
+
readonly description: string;
|
|
50
|
+
readonly dangerLevel: LiveActionDangerLevel;
|
|
51
|
+
readonly permission: LiveActionPermission;
|
|
52
|
+
readonly inputSchema: z.ZodType<TInput>;
|
|
53
|
+
redactInput?(input: TInput): unknown;
|
|
54
|
+
execute(context: LiveActionContext<TInput>): Promise<LiveActionResult>;
|
|
55
|
+
};
|
|
56
|
+
/** Validate core metadata invariants shared by definition and registration. */
|
|
57
|
+
export declare function assertValidLiveActionMetadata(action: {
|
|
58
|
+
readonly name: string;
|
|
59
|
+
readonly description: string;
|
|
60
|
+
readonly dangerLevel: LiveActionDangerLevel;
|
|
61
|
+
readonly permission: LiveActionPermission;
|
|
62
|
+
}): void;
|
|
63
|
+
/** Define and validate an audited live-environment operational action. */
|
|
64
|
+
export declare function defineLiveAction<TInput>(spec: LiveActionSpec<TInput>): LiveActionDefinition<TInput>;
|
|
65
|
+
//# sourceMappingURL=live-action.d.ts.map
|