@voyantjs/action-ledger 0.52.2
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/canary.d.ts +17 -0
- package/dist/canary.d.ts.map +1 -0
- package/dist/canary.js +77 -0
- package/dist/capability.d.ts +73 -0
- package/dist/capability.d.ts.map +1 -0
- package/dist/capability.js +206 -0
- package/dist/fingerprint.d.ts +26 -0
- package/dist/fingerprint.d.ts.map +1 -0
- package/dist/fingerprint.js +55 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/request-context.d.ts +136 -0
- package/dist/request-context.d.ts.map +1 -0
- package/dist/request-context.js +237 -0
- package/dist/route-schemas.d.ts +739 -0
- package/dist/route-schemas.d.ts.map +1 -0
- package/dist/route-schemas.js +427 -0
- package/dist/routes.d.ts +1596 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +271 -0
- package/dist/schema.d.ts +1759 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +237 -0
- package/dist/service.d.ts +317 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +1025 -0
- package/dist/timeline.d.ts +67 -0
- package/dist/timeline.d.ts.map +1 -0
- package/dist/timeline.js +79 -0
- package/package.json +105 -0
package/dist/canary.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AnyDrizzleDb } from "@voyantjs/db";
|
|
2
|
+
export interface RunActionLedgerCanaryInput {
|
|
3
|
+
organizationId?: string | null;
|
|
4
|
+
principalId?: string | null;
|
|
5
|
+
idempotencyKey?: string | null;
|
|
6
|
+
payloadRef?: string | null;
|
|
7
|
+
now?: Date;
|
|
8
|
+
}
|
|
9
|
+
export interface RunActionLedgerCanaryResult {
|
|
10
|
+
ok: boolean;
|
|
11
|
+
actionId: string;
|
|
12
|
+
replayed: boolean;
|
|
13
|
+
observedWrite: boolean;
|
|
14
|
+
observedRelay: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare function runActionLedgerCanary(db: AnyDrizzleDb, input?: RunActionLedgerCanaryInput): Promise<RunActionLedgerCanaryResult>;
|
|
17
|
+
//# sourceMappingURL=canary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canary.d.ts","sourceRoot":"","sources":["../src/canary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAKhD,MAAM,WAAW,0BAA0B;IACzC,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,GAAG,CAAC,EAAE,IAAI,CAAA;CACX;AAED,MAAM,WAAW,2BAA2B;IAC1C,EAAE,EAAE,OAAO,CAAA;IACX,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,OAAO,CAAA;IACjB,aAAa,EAAE,OAAO,CAAA;IACtB,aAAa,EAAE,OAAO,CAAA;CACvB;AAED,wBAAsB,qBAAqB,CACzC,EAAE,EAAE,YAAY,EAChB,KAAK,GAAE,0BAA+B,GACrC,OAAO,CAAC,2BAA2B,CAAC,CA8EtC"}
|
package/dist/canary.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { buildIdempotencyFingerprint } from "./fingerprint.js";
|
|
2
|
+
import { actionLedgerService } from "./service.js";
|
|
3
|
+
export async function runActionLedgerCanary(db, input = {}) {
|
|
4
|
+
const now = input.now ?? new Date();
|
|
5
|
+
const idempotencyKey = input.idempotencyKey ?? `action-ledger-canary:${now.toISOString()}`;
|
|
6
|
+
const payloadRef = input.payloadRef ?? `action-ledger-canary:${idempotencyKey}`;
|
|
7
|
+
const idempotencyFingerprint = await buildIdempotencyFingerprint({
|
|
8
|
+
actionName: "action_ledger.canary.write",
|
|
9
|
+
actionVersion: "v1",
|
|
10
|
+
targetType: "action_ledger_canary",
|
|
11
|
+
targetId: idempotencyKey,
|
|
12
|
+
commandInput: { payloadRef },
|
|
13
|
+
});
|
|
14
|
+
const appendResult = await actionLedgerService.appendEntry(db, {
|
|
15
|
+
occurredAt: now,
|
|
16
|
+
actionName: "action_ledger.canary.write",
|
|
17
|
+
actionVersion: "v1",
|
|
18
|
+
actionKind: "execute",
|
|
19
|
+
status: "succeeded",
|
|
20
|
+
evaluatedRisk: "low",
|
|
21
|
+
actorType: "system",
|
|
22
|
+
principalType: "system",
|
|
23
|
+
principalId: input.principalId ?? "action-ledger-canary",
|
|
24
|
+
principalSubtype: null,
|
|
25
|
+
sessionId: null,
|
|
26
|
+
apiTokenId: null,
|
|
27
|
+
internalRequest: true,
|
|
28
|
+
delegatedByPrincipalType: null,
|
|
29
|
+
delegatedByPrincipalId: null,
|
|
30
|
+
delegationId: null,
|
|
31
|
+
callerType: "system",
|
|
32
|
+
organizationId: input.organizationId ?? null,
|
|
33
|
+
routeOrToolName: "action-ledger.canary",
|
|
34
|
+
workflowRunId: null,
|
|
35
|
+
workflowStepId: null,
|
|
36
|
+
correlationId: null,
|
|
37
|
+
causationActionId: null,
|
|
38
|
+
idempotencyScope: "action-ledger-canary",
|
|
39
|
+
idempotencyKey,
|
|
40
|
+
idempotencyFingerprint,
|
|
41
|
+
targetType: "action_ledger_canary",
|
|
42
|
+
targetId: idempotencyKey,
|
|
43
|
+
capabilityId: "action-ledger.canary",
|
|
44
|
+
capabilityVersion: "v1",
|
|
45
|
+
authorizationSource: "action-ledger.canary",
|
|
46
|
+
approvalId: null,
|
|
47
|
+
amendsActionId: null,
|
|
48
|
+
enqueueRelay: { payloadRef },
|
|
49
|
+
mutationDetail: {
|
|
50
|
+
commandInputRef: payloadRef,
|
|
51
|
+
commandResultRef: payloadRef,
|
|
52
|
+
summary: "Synthetic action ledger canary write",
|
|
53
|
+
reversalKind: "none",
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
const [entries, relay] = await Promise.all([
|
|
57
|
+
actionLedgerService.listEntries(db, {
|
|
58
|
+
targetType: "action_ledger_canary",
|
|
59
|
+
targetId: idempotencyKey,
|
|
60
|
+
actionName: "action_ledger.canary.write",
|
|
61
|
+
limit: 1,
|
|
62
|
+
}),
|
|
63
|
+
actionLedgerService.listRelayOutbox(db, {
|
|
64
|
+
actionId: appendResult.entry.id,
|
|
65
|
+
limit: 1,
|
|
66
|
+
}),
|
|
67
|
+
]);
|
|
68
|
+
const observedWrite = entries.entries.some((entry) => entry.id === appendResult.entry.id);
|
|
69
|
+
const observedRelay = relay.rows.some((row) => row.actionId === appendResult.entry.id);
|
|
70
|
+
return {
|
|
71
|
+
ok: observedWrite && observedRelay,
|
|
72
|
+
actionId: appendResult.entry.id,
|
|
73
|
+
replayed: appendResult.replayed,
|
|
74
|
+
observedWrite,
|
|
75
|
+
observedRelay,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { ActionLedgerEntry } from "./schema.js";
|
|
2
|
+
export declare const actionLedgerCapabilityLedgerPolicyValues: readonly ["none", "optional", "required"];
|
|
3
|
+
export declare const actionLedgerCapabilityApprovalPolicyValues: readonly ["none", "conditional", "required"];
|
|
4
|
+
export type ActionLedgerCapabilityRisk = ActionLedgerEntry["evaluatedRisk"];
|
|
5
|
+
export type ActionLedgerCapabilityLedgerPolicy = (typeof actionLedgerCapabilityLedgerPolicyValues)[number];
|
|
6
|
+
export type ActionLedgerCapabilityApprovalPolicy = (typeof actionLedgerCapabilityApprovalPolicyValues)[number];
|
|
7
|
+
export interface ActionLedgerCapabilityGrant {
|
|
8
|
+
resource: string;
|
|
9
|
+
action: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ActionLedgerCapabilityDefinition<TContext = unknown> {
|
|
12
|
+
id: string;
|
|
13
|
+
version: string;
|
|
14
|
+
resource: string;
|
|
15
|
+
action: string;
|
|
16
|
+
risk: ActionLedgerCapabilityRisk;
|
|
17
|
+
ledgerPolicy: ActionLedgerCapabilityLedgerPolicy;
|
|
18
|
+
approvalPolicy?: ActionLedgerCapabilityApprovalPolicy;
|
|
19
|
+
reversible?: boolean;
|
|
20
|
+
allowedActorTypes?: readonly string[];
|
|
21
|
+
requiredGrants?: readonly ActionLedgerCapabilityGrant[];
|
|
22
|
+
evaluateRisk?: (context: TContext) => ActionLedgerCapabilityRisk;
|
|
23
|
+
}
|
|
24
|
+
export interface ActionLedgerCapabilityRegistry<TDefinition extends ActionLedgerCapabilityDefinition = ActionLedgerCapabilityDefinition> {
|
|
25
|
+
definitions: readonly TDefinition[];
|
|
26
|
+
byKey: ReadonlyMap<string, TDefinition>;
|
|
27
|
+
}
|
|
28
|
+
export declare class ActionLedgerCapabilityRegistryError extends Error {
|
|
29
|
+
constructor(message: string);
|
|
30
|
+
}
|
|
31
|
+
export interface EvaluateActionLedgerCapabilityAccessInput<TContext = unknown> {
|
|
32
|
+
definition: ActionLedgerCapabilityDefinition<TContext>;
|
|
33
|
+
actor?: string | null;
|
|
34
|
+
callerType?: string | null;
|
|
35
|
+
scopes?: readonly string[] | null;
|
|
36
|
+
permissions?: Record<string, readonly string[]> | null;
|
|
37
|
+
isInternalRequest?: boolean | null;
|
|
38
|
+
riskContext?: TContext;
|
|
39
|
+
}
|
|
40
|
+
export type ActionLedgerCapabilityAccessReason = "internal_request" | "scope_grant" | "permission_grant" | "actor_allowed" | "actor_missing" | "actor_not_allowed" | "grant_missing";
|
|
41
|
+
export interface ActionLedgerCapabilityAccessResult {
|
|
42
|
+
allowed: boolean;
|
|
43
|
+
reason: ActionLedgerCapabilityAccessReason;
|
|
44
|
+
capabilityId: string;
|
|
45
|
+
capabilityVersion: string;
|
|
46
|
+
evaluatedRisk: ActionLedgerCapabilityRisk;
|
|
47
|
+
ledgerPolicy: ActionLedgerCapabilityLedgerPolicy;
|
|
48
|
+
approvalPolicy: ActionLedgerCapabilityApprovalPolicy;
|
|
49
|
+
authorizationSource: string;
|
|
50
|
+
grant: ActionLedgerCapabilityGrant | null;
|
|
51
|
+
}
|
|
52
|
+
export type ActionLedgerApprovalRequirementReason = "access_denied" | "policy_none" | "policy_required" | "conditional_policy_required" | "conditional_policy_not_required";
|
|
53
|
+
export interface EvaluateActionLedgerApprovalRequirementInput {
|
|
54
|
+
access: ActionLedgerCapabilityAccessResult;
|
|
55
|
+
conditionalApprovalRequired?: boolean | null;
|
|
56
|
+
reasonCode?: string | null;
|
|
57
|
+
}
|
|
58
|
+
export interface ActionLedgerApprovalRequirementResult {
|
|
59
|
+
required: boolean;
|
|
60
|
+
reason: ActionLedgerApprovalRequirementReason;
|
|
61
|
+
approvalPolicy: ActionLedgerCapabilityApprovalPolicy;
|
|
62
|
+
capabilityId: string;
|
|
63
|
+
capabilityVersion: string;
|
|
64
|
+
evaluatedRisk: ActionLedgerCapabilityRisk;
|
|
65
|
+
reasonCode: string | null;
|
|
66
|
+
}
|
|
67
|
+
export declare function createActionLedgerCapabilityRegistry<const TDefinition extends ActionLedgerCapabilityDefinition>(definitions: readonly TDefinition[]): ActionLedgerCapabilityRegistry<TDefinition>;
|
|
68
|
+
export declare function getActionLedgerCapability<TDefinition extends ActionLedgerCapabilityDefinition>(registry: ActionLedgerCapabilityRegistry<TDefinition>, id: string, version: string): TDefinition | null;
|
|
69
|
+
export declare function evaluateActionLedgerCapabilityRisk<TContext>(definition: ActionLedgerCapabilityDefinition<TContext>, context: TContext): ActionLedgerCapabilityRisk;
|
|
70
|
+
export declare function evaluateActionLedgerCapabilityAccess<TContext = unknown>(input: EvaluateActionLedgerCapabilityAccessInput<TContext>): ActionLedgerCapabilityAccessResult;
|
|
71
|
+
export declare function evaluateActionLedgerApprovalRequirement(input: EvaluateActionLedgerApprovalRequirementInput): ActionLedgerApprovalRequirementResult;
|
|
72
|
+
export declare function actionLedgerCapabilityKey(id: string, version: string): string;
|
|
73
|
+
//# sourceMappingURL=capability.d.ts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AC3B;AAED,MAAM,WAAW,qCAAqC;IACpD,QAAQ,EAAE,OAAO,CAAA;IACjB,MAAM,EAAE,qCAAqC,CAAA;IAC7C,cAAc,EAAE,oCAAoC,CAAA;IACpD,YAAY,EAAE,MAAM,CAAA;IACpB,iBAAiB,EAAE,MAAM,CAAA;IACzB,aAAa,EAAE,0BAA0B,CAAA;IACzC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;CAC1B;AASD,wBAAgB,oCAAoC,CAClD,KAAK,CAAC,WAAW,SAAS,gCAAgC,EAC1D,WAAW,EAAE,SAAS,WAAW,EAAE,GAAG,8BAA8B,CAAC,WAAW,CAAC,CAclF;AAED,wBAAgB,yBAAyB,CAAC,WAAW,SAAS,gCAAgC,EAC5F,QAAQ,EAAE,8BAA8B,CAAC,WAAW,CAAC,EACrD,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,MAAM,GACd,WAAW,GAAG,IAAI,CAEpB;AAED,wBAAgB,kCAAkC,CAAC,QAAQ,EACzD,UAAU,EAAE,gCAAgC,CAAC,QAAQ,CAAC,EACtD,OAAO,EAAE,QAAQ,GAChB,0BAA0B,CAG5B;AAED,wBAAgB,oCAAoC,CAAC,QAAQ,GAAG,OAAO,EACrE,KAAK,EAAE,yCAAyC,CAAC,QAAQ,CAAC,GACzD,kCAAkC,CAuFpC;AAED,wBAAgB,uCAAuC,CACrD,KAAK,EAAE,4CAA4C,GAClD,qCAAqC,CAyCvC;AAED,wBAAgB,yBAAyB,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAE7E"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
export const actionLedgerCapabilityLedgerPolicyValues = ["none", "optional", "required"];
|
|
2
|
+
export const actionLedgerCapabilityApprovalPolicyValues = [
|
|
3
|
+
"none",
|
|
4
|
+
"conditional",
|
|
5
|
+
"required",
|
|
6
|
+
];
|
|
7
|
+
export class ActionLedgerCapabilityRegistryError extends Error {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "ActionLedgerCapabilityRegistryError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const riskRank = {
|
|
14
|
+
low: 0,
|
|
15
|
+
medium: 1,
|
|
16
|
+
high: 2,
|
|
17
|
+
critical: 3,
|
|
18
|
+
};
|
|
19
|
+
export function createActionLedgerCapabilityRegistry(definitions) {
|
|
20
|
+
const byKey = new Map();
|
|
21
|
+
for (const definition of definitions) {
|
|
22
|
+
const key = actionLedgerCapabilityKey(definition.id, definition.version);
|
|
23
|
+
if (byKey.has(key)) {
|
|
24
|
+
throw new ActionLedgerCapabilityRegistryError(`Duplicate action ledger capability ${definition.id}@${definition.version}`);
|
|
25
|
+
}
|
|
26
|
+
byKey.set(key, definition);
|
|
27
|
+
}
|
|
28
|
+
return { definitions, byKey };
|
|
29
|
+
}
|
|
30
|
+
export function getActionLedgerCapability(registry, id, version) {
|
|
31
|
+
return registry.byKey.get(actionLedgerCapabilityKey(id, version)) ?? null;
|
|
32
|
+
}
|
|
33
|
+
export function evaluateActionLedgerCapabilityRisk(definition, context) {
|
|
34
|
+
const evaluatedRisk = definition.evaluateRisk?.(context) ?? definition.risk;
|
|
35
|
+
return riskRank[evaluatedRisk] > riskRank[definition.risk] ? evaluatedRisk : definition.risk;
|
|
36
|
+
}
|
|
37
|
+
export function evaluateActionLedgerCapabilityAccess(input) {
|
|
38
|
+
const { definition } = input;
|
|
39
|
+
const evaluatedRisk = "riskContext" in input
|
|
40
|
+
? evaluateActionLedgerCapabilityRisk(definition, input.riskContext)
|
|
41
|
+
: definition.risk;
|
|
42
|
+
const base = {
|
|
43
|
+
capabilityId: definition.id,
|
|
44
|
+
capabilityVersion: definition.version,
|
|
45
|
+
evaluatedRisk,
|
|
46
|
+
ledgerPolicy: definition.ledgerPolicy,
|
|
47
|
+
approvalPolicy: definition.approvalPolicy ?? "none",
|
|
48
|
+
};
|
|
49
|
+
if (input.isInternalRequest || input.callerType === "internal") {
|
|
50
|
+
return {
|
|
51
|
+
...base,
|
|
52
|
+
allowed: true,
|
|
53
|
+
reason: "internal_request",
|
|
54
|
+
authorizationSource: "internal_request",
|
|
55
|
+
grant: null,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const grant = findSatisfiedGrant(definition, input);
|
|
59
|
+
if (grant) {
|
|
60
|
+
return {
|
|
61
|
+
...base,
|
|
62
|
+
allowed: true,
|
|
63
|
+
reason: grant.source,
|
|
64
|
+
authorizationSource: grant.source === "scope_grant" ? "scope" : "api_token_permission",
|
|
65
|
+
grant: grant.grant,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (definition.requiredGrants && definition.requiredGrants.length > 0) {
|
|
69
|
+
return {
|
|
70
|
+
...base,
|
|
71
|
+
allowed: false,
|
|
72
|
+
reason: "grant_missing",
|
|
73
|
+
authorizationSource: input.callerType === "api_key" ? "api_token_permission" : "scope",
|
|
74
|
+
grant: null,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
if (input.callerType === "api_key") {
|
|
78
|
+
return {
|
|
79
|
+
...base,
|
|
80
|
+
allowed: false,
|
|
81
|
+
reason: "grant_missing",
|
|
82
|
+
authorizationSource: "api_token_permission",
|
|
83
|
+
grant: null,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const actor = normalizeNullableString(input.actor);
|
|
87
|
+
if (!actor) {
|
|
88
|
+
return {
|
|
89
|
+
...base,
|
|
90
|
+
allowed: false,
|
|
91
|
+
reason: "actor_missing",
|
|
92
|
+
authorizationSource: "actor_context",
|
|
93
|
+
grant: null,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (definition.allowedActorTypes &&
|
|
97
|
+
definition.allowedActorTypes.length > 0 &&
|
|
98
|
+
!definition.allowedActorTypes.includes(actor)) {
|
|
99
|
+
return {
|
|
100
|
+
...base,
|
|
101
|
+
allowed: false,
|
|
102
|
+
reason: "actor_not_allowed",
|
|
103
|
+
authorizationSource: "actor_context",
|
|
104
|
+
grant: null,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
...base,
|
|
109
|
+
allowed: true,
|
|
110
|
+
reason: "actor_allowed",
|
|
111
|
+
authorizationSource: "actor_context",
|
|
112
|
+
grant: null,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export function evaluateActionLedgerApprovalRequirement(input) {
|
|
116
|
+
const base = {
|
|
117
|
+
approvalPolicy: input.access.approvalPolicy,
|
|
118
|
+
capabilityId: input.access.capabilityId,
|
|
119
|
+
capabilityVersion: input.access.capabilityVersion,
|
|
120
|
+
evaluatedRisk: input.access.evaluatedRisk,
|
|
121
|
+
reasonCode: normalizeNullableString(input.reasonCode),
|
|
122
|
+
};
|
|
123
|
+
if (!input.access.allowed) {
|
|
124
|
+
return {
|
|
125
|
+
...base,
|
|
126
|
+
required: false,
|
|
127
|
+
reason: "access_denied",
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (input.access.approvalPolicy === "required") {
|
|
131
|
+
return {
|
|
132
|
+
...base,
|
|
133
|
+
required: true,
|
|
134
|
+
reason: "policy_required",
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
if (input.access.approvalPolicy === "conditional") {
|
|
138
|
+
return {
|
|
139
|
+
...base,
|
|
140
|
+
required: input.conditionalApprovalRequired === true,
|
|
141
|
+
reason: input.conditionalApprovalRequired === true
|
|
142
|
+
? "conditional_policy_required"
|
|
143
|
+
: "conditional_policy_not_required",
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
...base,
|
|
148
|
+
required: false,
|
|
149
|
+
reason: "policy_none",
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
export function actionLedgerCapabilityKey(id, version) {
|
|
153
|
+
return `${id}@${version}`;
|
|
154
|
+
}
|
|
155
|
+
function findSatisfiedGrant(definition, input) {
|
|
156
|
+
for (const grant of grantsForCapability(definition)) {
|
|
157
|
+
if (hasScopeGrant(input.scopes, grant)) {
|
|
158
|
+
return { source: "scope_grant", grant };
|
|
159
|
+
}
|
|
160
|
+
if (hasPermissionGrant(input.permissions, grant)) {
|
|
161
|
+
return { source: "permission_grant", grant };
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
function grantsForCapability(definition) {
|
|
167
|
+
if (definition.requiredGrants && definition.requiredGrants.length > 0) {
|
|
168
|
+
return definition.requiredGrants;
|
|
169
|
+
}
|
|
170
|
+
return [{ resource: definition.resource, action: definition.action }];
|
|
171
|
+
}
|
|
172
|
+
function hasPermissionGrant(permissions, grant) {
|
|
173
|
+
if (!permissions)
|
|
174
|
+
return false;
|
|
175
|
+
return hasGrant(permissions, grant);
|
|
176
|
+
}
|
|
177
|
+
function hasScopeGrant(scopes, grant) {
|
|
178
|
+
if (!scopes || scopes.length === 0)
|
|
179
|
+
return false;
|
|
180
|
+
const permissions = {};
|
|
181
|
+
for (const scope of scopes) {
|
|
182
|
+
const normalized = normalizeNullableString(scope);
|
|
183
|
+
if (!normalized)
|
|
184
|
+
continue;
|
|
185
|
+
if (normalized === "*") {
|
|
186
|
+
permissions["*"] = ["*"];
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
const [resource, action] = normalized.split(":", 2);
|
|
190
|
+
if (!resource || !action)
|
|
191
|
+
continue;
|
|
192
|
+
permissions[resource] = [...(permissions[resource] ?? []), action];
|
|
193
|
+
}
|
|
194
|
+
return hasGrant(permissions, grant);
|
|
195
|
+
}
|
|
196
|
+
function hasGrant(permissions, grant) {
|
|
197
|
+
return (permissions["*"]?.includes("*") === true ||
|
|
198
|
+
permissions["*"]?.includes(grant.action) === true ||
|
|
199
|
+
permissions[grant.resource]?.includes("*") === true ||
|
|
200
|
+
permissions[grant.resource]?.includes(grant.action) === true);
|
|
201
|
+
}
|
|
202
|
+
function normalizeNullableString(value) {
|
|
203
|
+
if (value === undefined || value === null || value === "")
|
|
204
|
+
return null;
|
|
205
|
+
return value;
|
|
206
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ActionLedgerCapabilityApprovalPolicy, ActionLedgerCapabilityRisk } from "./capability.js";
|
|
2
|
+
export declare function canonicalize(value: unknown): unknown;
|
|
3
|
+
export declare function canonicalJson(value: unknown): string;
|
|
4
|
+
export declare function sha256(value: unknown): Promise<string>;
|
|
5
|
+
export declare function buildIdempotencyFingerprint(input: {
|
|
6
|
+
actionName: string;
|
|
7
|
+
actionVersion: string;
|
|
8
|
+
targetType: string;
|
|
9
|
+
targetId: string;
|
|
10
|
+
commandInput?: unknown;
|
|
11
|
+
policyInputs?: unknown;
|
|
12
|
+
}): Promise<string>;
|
|
13
|
+
export interface BuildActionApprovalCommandFingerprintInput {
|
|
14
|
+
actionName: string;
|
|
15
|
+
actionVersion: string;
|
|
16
|
+
targetType: string;
|
|
17
|
+
targetId: string;
|
|
18
|
+
commandInput?: unknown;
|
|
19
|
+
approvalPolicy: ActionLedgerCapabilityApprovalPolicy;
|
|
20
|
+
capabilityId: string;
|
|
21
|
+
capabilityVersion: string;
|
|
22
|
+
evaluatedRisk: ActionLedgerCapabilityRisk;
|
|
23
|
+
reasonCode: string | null;
|
|
24
|
+
}
|
|
25
|
+
export declare function buildActionApprovalCommandFingerprint(input: BuildActionApprovalCommandFingerprintInput): Promise<string>;
|
|
26
|
+
//# sourceMappingURL=fingerprint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fingerprint.d.ts","sourceRoot":"","sources":["../src/fingerprint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oCAAoC,EACpC,0BAA0B,EAC3B,MAAM,iBAAiB,CAAA;AAExB,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAUpD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEpD;AAED,wBAAsB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAK5D;AAED,wBAAsB,2BAA2B,CAAC,KAAK,EAAE;IACvD,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,GAAG,OAAO,CAAC,MAAM,CAAC,CAElB;AAED,MAAM,WAAW,0CAA0C;IACzD,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,cAAc,EAAE,oCAAoC,CAAA;IACpD,YAAY,EAAE,MAAM,CAAA;IACpB,iBAAiB,EAAE,MAAM,CAAA;IACzB,aAAa,EAAE,0BAA0B,CAAA;IACzC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;CAC1B;AAED,wBAAsB,qCAAqC,CACzD,KAAK,EAAE,0CAA0C,GAChD,OAAO,CAAC,MAAM,CAAC,CAejB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export function canonicalize(value) {
|
|
2
|
+
if (value === undefined)
|
|
3
|
+
return null;
|
|
4
|
+
if (value === null || typeof value !== "object")
|
|
5
|
+
return value;
|
|
6
|
+
if (Array.isArray(value))
|
|
7
|
+
return value.map(canonicalize);
|
|
8
|
+
const sorted = {};
|
|
9
|
+
for (const key of Object.keys(value).sort()) {
|
|
10
|
+
sorted[key] = canonicalize(value[key]);
|
|
11
|
+
}
|
|
12
|
+
return sorted;
|
|
13
|
+
}
|
|
14
|
+
export function canonicalJson(value) {
|
|
15
|
+
return JSON.stringify(canonicalize(value));
|
|
16
|
+
}
|
|
17
|
+
export async function sha256(value) {
|
|
18
|
+
const text = canonicalJson(value);
|
|
19
|
+
const bytes = new TextEncoder().encode(text);
|
|
20
|
+
const digest = await getCrypto().subtle.digest("SHA-256", bytes);
|
|
21
|
+
return bytesToHex(new Uint8Array(digest));
|
|
22
|
+
}
|
|
23
|
+
export async function buildIdempotencyFingerprint(input) {
|
|
24
|
+
return `sha256:${await sha256(input)}`;
|
|
25
|
+
}
|
|
26
|
+
export async function buildActionApprovalCommandFingerprint(input) {
|
|
27
|
+
return buildIdempotencyFingerprint({
|
|
28
|
+
actionName: input.actionName,
|
|
29
|
+
actionVersion: input.actionVersion,
|
|
30
|
+
targetType: input.targetType,
|
|
31
|
+
targetId: input.targetId,
|
|
32
|
+
commandInput: input.commandInput ?? null,
|
|
33
|
+
policyInputs: {
|
|
34
|
+
approvalPolicy: input.approvalPolicy,
|
|
35
|
+
capabilityId: input.capabilityId,
|
|
36
|
+
capabilityVersion: input.capabilityVersion,
|
|
37
|
+
evaluatedRisk: input.evaluatedRisk,
|
|
38
|
+
reasonCode: input.reasonCode,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function getCrypto() {
|
|
43
|
+
const crypto = globalThis.crypto;
|
|
44
|
+
if (!crypto?.subtle) {
|
|
45
|
+
throw new Error("@voyantjs/action-ledger: globalThis.crypto.subtle is required for idempotency fingerprints.");
|
|
46
|
+
}
|
|
47
|
+
return crypto;
|
|
48
|
+
}
|
|
49
|
+
function bytesToHex(bytes) {
|
|
50
|
+
let out = "";
|
|
51
|
+
for (const byte of bytes) {
|
|
52
|
+
out += byte.toString(16).padStart(2, "0");
|
|
53
|
+
}
|
|
54
|
+
return out;
|
|
55
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { type RunActionLedgerCanaryInput, type RunActionLedgerCanaryResult, runActionLedgerCanary, } from "./canary.js";
|
|
2
|
+
export { type ActionLedgerApprovalRequirementReason, type ActionLedgerApprovalRequirementResult, type ActionLedgerCapabilityAccessReason, type ActionLedgerCapabilityAccessResult, type ActionLedgerCapabilityApprovalPolicy, type ActionLedgerCapabilityDefinition, type ActionLedgerCapabilityGrant, type ActionLedgerCapabilityLedgerPolicy, type ActionLedgerCapabilityRegistry, ActionLedgerCapabilityRegistryError, type ActionLedgerCapabilityRisk, actionLedgerCapabilityApprovalPolicyValues, actionLedgerCapabilityKey, actionLedgerCapabilityLedgerPolicyValues, createActionLedgerCapabilityRegistry, type EvaluateActionLedgerApprovalRequirementInput, type EvaluateActionLedgerCapabilityAccessInput, evaluateActionLedgerApprovalRequirement, evaluateActionLedgerCapabilityAccess, evaluateActionLedgerCapabilityRisk, getActionLedgerCapability, } from "./capability.js";
|
|
3
|
+
export { type BuildActionApprovalCommandFingerprintInput, buildActionApprovalCommandFingerprint, buildIdempotencyFingerprint, canonicalize, canonicalJson, sha256, } from "./fingerprint.js";
|
|
4
|
+
export { ACTION_LEDGER_APPROVAL_ID_HEADER, type ActionLedgerActorFields, type ActionLedgerApprovedExecutionFields, type ActionLedgerRequestContextValues, type ActionLedgerRequestMappingOptions, appendActionLedgerMutation, appendActionLedgerSensitiveRead, type BuildActionLedgerApprovalDecisionInput, type BuildActionLedgerApprovalRequestInput, type BuildActionLedgerApprovedExecutionFieldsInput, type BuildActionLedgerMutationInput, type BuildActionLedgerSensitiveReadInput, type BuildActionLedgerSensitiveReadInputForValue, buildActionLedgerApprovalDecisionInput, buildActionLedgerApprovalRequestInput, buildActionLedgerApprovedExecutionFields, buildActionLedgerMutationEntryInput, buildActionLedgerSensitiveReadEntryInput, decideActionLedgerApproval, ledgerSensitiveRead, mapActionLedgerRequestContext, requestActionLedgerApproval, } from "./request-context.js";
|
|
5
|
+
export { type ActionApprovalDecisionResponse, type ActionApprovalDetailResponse, type ActionApprovalGetResponse, type ActionApprovalListResponse, type ActionApprovalRequestResponse, type ActionApprovalResponse, type ActionDelegationGetResponse, type ActionDelegationListResponse, type ActionDelegationResponse, type ActionLedgerAdminRoutes, type ActionLedgerEntryDetailResponse, type ActionLedgerEntryResponse, type ActionLedgerGetResponse, type ActionLedgerListResponse, type ActionLedgerPayloadResponse, type ActionLedgerRelayOutboxListResponse, type ActionLedgerRelayOutboxResponse, type ActionLedgerReversalResponse, actionLedgerAdminRoutes, actionLedgerHonoModule, actionLedgerModule, } from "./routes.js";
|
|
6
|
+
export { type ActionApproval, type ActionDelegation, type ActionLedgerEntry, type ActionLedgerPayload, type ActionLedgerRelayOutbox, type ActionMutationDetail, type ActionSensitiveReadDetail, actionApprovals, actionDelegations, actionLedgerActionKindEnum, actionLedgerApprovalStatusEnum, actionLedgerEntries, actionLedgerPayloads, actionLedgerPrincipalTypeEnum, actionLedgerRedactionStatusEnum, actionLedgerRelayOutbox, actionLedgerRelayStatusEnum, actionLedgerReversalKindEnum, actionLedgerReversalOutcomeEnum, actionLedgerReversalStateEnum, actionLedgerRiskEnum, actionLedgerStatusEnum, actionMutationDetails, actionSensitiveReadDetails, type NewActionApproval, type NewActionDelegation, type NewActionLedgerEntry, type NewActionLedgerPayload, type NewActionLedgerRelayOutbox, type NewActionMutationDetail, type NewActionSensitiveReadDetail, } from "./schema.js";
|
|
7
|
+
export { ActionApprovalDecisionConflictError, ActionApprovalDecisionStatusError, type ActionApprovalListCursor, type ActionDelegationListCursor, ActionLedgerIdempotencyConflictError, type ActionLedgerListCursor, type ActionLedgerRelayOutboxListCursor, ActionLedgerReversalTargetError, type AppendActionLedgerEntryInput, type AppendActionLedgerEntryResult, actionLedgerService, type ClaimActionLedgerRelayOutboxInput, type ClaimActionLedgerRelayOutboxResult, type DecideActionApprovalInput, type DecideActionApprovalResult, type GetActionApprovalResult, type GetActionDelegationResult, type GetActionLedgerEntryResult, type ListActionApprovalsInput, type ListActionApprovalsResult, type ListActionDelegationsInput, type ListActionDelegationsResult, type ListActionLedgerEntriesInput, type ListActionLedgerEntriesResult, type ListActionLedgerRelayOutboxInput, type ListActionLedgerRelayOutboxResult, type MarkActionLedgerRelayOutboxFailedInput, type MarkActionLedgerRelayOutboxSucceededInput, type RecordActionLedgerReversalInput, type RecordActionLedgerReversalResult, type RequestActionApprovalInput, type RequestActionApprovalResult, type ValidateApprovedActionFailureReason, type ValidateApprovedActionInput, type ValidateApprovedActionResult, } from "./service.js";
|
|
8
|
+
export { type ActionLedgerSerializedEntry, type ActionLedgerTargetTimelineEntry, type ActionLedgerTargetTimelinePage, type ActionLedgerTargetTimelineQuery, type ActionLedgerTimelineCursor, actionLedgerTargetTimelineQuerySchema, buildActionLedgerTargetTimelinePage, serializeActionLedgerDate, serializeActionLedgerEntry, sortActionLedgerTimelineEntries, toActionLedgerTimelineCursor, } from "./timeline.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,2BAA2B,EAChC,qBAAqB,GACtB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,KAAK,qCAAqC,EAC1C,KAAK,qCAAqC,EAC1C,KAAK,kCAAkC,EACvC,KAAK,kCAAkC,EACvC,KAAK,oCAAoC,EACzC,KAAK,gCAAgC,EACrC,KAAK,2BAA2B,EAChC,KAAK,kCAAkC,EACvC,KAAK,8BAA8B,EACnC,mCAAmC,EACnC,KAAK,0BAA0B,EAC/B,0CAA0C,EAC1C,yBAAyB,EACzB,wCAAwC,EACxC,oCAAoC,EACpC,KAAK,4CAA4C,EACjD,KAAK,yCAAyC,EAC9C,uCAAuC,EACvC,oCAAoC,EACpC,kCAAkC,EAClC,yBAAyB,GAC1B,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,KAAK,0CAA0C,EAC/C,qCAAqC,EACrC,2BAA2B,EAC3B,YAAY,EACZ,aAAa,EACb,MAAM,GACP,MAAM,kBAAkB,CAAA;AACzB,OAAO,EACL,gCAAgC,EAChC,KAAK,uBAAuB,EAC5B,KAAK,mCAAmC,EACxC,KAAK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egistryError, actionLedgerCapabilityApprovalPolicyValues, actionLedgerCapabilityKey, actionLedgerCapabilityLedgerPolicyValues, createActionLedgerCapabilityRegistry, evaluateActionLedgerApprovalRequirement, evaluateActionLedgerCapabilityAccess, evaluateActionLedgerCapabilityRisk, getActionLedgerCapability, } from "./capability.js";
|
|
3
|
+
export { buildActionApprovalCommandFingerprint, buildIdempotencyFingerprint, canonicalize, canonicalJson, sha256, } from "./fingerprint.js";
|
|
4
|
+
export { ACTION_LEDGER_APPROVAL_ID_HEADER, appendActionLedgerMutation, appendActionLedgerSensitiveRead, buildActionLedgerApprovalDecisionInput, buildActionLedgerApprovalRequestInput, buildActionLedgerApprovedExecutionFields, buildActionLedgerMutationEntryInput, buildActionLedgerSensitiveReadEntryInput, decideActionLedgerApproval, ledgerSensitiveRead, mapActionLedgerRequestContext, requestActionLedgerApproval, } from "./request-context.js";
|
|
5
|
+
export { actionLedgerAdminRoutes, actionLedgerHonoModule, actionLedgerModule, } from "./routes.js";
|
|
6
|
+
export { actionApprovals, actionDelegations, actionLedgerActionKindEnum, actionLedgerApprovalStatusEnum, actionLedgerEntries, actionLedgerPayloads, actionLedgerPrincipalTypeEnum, actionLedgerRedactionStatusEnum, actionLedgerRelayOutbox, actionLedgerRelayStatusEnum, actionLedgerReversalKindEnum, actionLedgerReversalOutcomeEnum, actionLedgerReversalStateEnum, actionLedgerRiskEnum, actionLedgerStatusEnum, actionMutationDetails, actionSensitiveReadDetails, } from "./schema.js";
|
|
7
|
+
export { ActionApprovalDecisionConflictError, ActionApprovalDecisionStatusError, ActionLedgerIdempotencyConflictError, ActionLedgerReversalTargetError, actionLedgerService, } from "./service.js";
|
|
8
|
+
export { actionLedgerTargetTimelineQuerySchema, buildActionLedgerTargetTimelinePage, serializeActionLedgerDate, serializeActionLedgerEntry, sortActionLedgerTimelineEntries, toActionLedgerTimelineCursor, } from "./timeline.js";
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { AnyDrizzleDb } from "@voyantjs/db";
|
|
2
|
+
import type { ActionApproval, ActionLedgerEntry, NewActionMutationDetail } from "./schema.js";
|
|
3
|
+
import type { AppendActionLedgerEntryInput, AppendActionLedgerEntryResult, DecideActionApprovalInput, DecideActionApprovalResult, RequestActionApprovalInput, RequestActionApprovalResult } from "./service.js";
|
|
4
|
+
export declare const ACTION_LEDGER_APPROVAL_ID_HEADER = "action-approval-id";
|
|
5
|
+
export interface ActionLedgerRequestContextValues {
|
|
6
|
+
userId?: string | null;
|
|
7
|
+
agentId?: string | null;
|
|
8
|
+
workflowPrincipalId?: string | null;
|
|
9
|
+
principalSubtype?: string | null;
|
|
10
|
+
sessionId?: string | null;
|
|
11
|
+
apiTokenId?: string | null;
|
|
12
|
+
apiKeyId?: string | null;
|
|
13
|
+
callerType?: string | null;
|
|
14
|
+
actor?: string | null;
|
|
15
|
+
isInternalRequest?: boolean | null;
|
|
16
|
+
organizationId?: string | null;
|
|
17
|
+
workflowRunId?: string | null;
|
|
18
|
+
workflowStepId?: string | null;
|
|
19
|
+
correlationId?: string | null;
|
|
20
|
+
}
|
|
21
|
+
export interface ActionLedgerActorFields {
|
|
22
|
+
actorType: string | null;
|
|
23
|
+
principalType: ActionLedgerEntry["principalType"];
|
|
24
|
+
principalId: string;
|
|
25
|
+
principalSubtype: string | null;
|
|
26
|
+
sessionId: string | null;
|
|
27
|
+
apiTokenId: string | null;
|
|
28
|
+
internalRequest: boolean;
|
|
29
|
+
callerType: string | null;
|
|
30
|
+
organizationId: string | null;
|
|
31
|
+
workflowRunId: string | null;
|
|
32
|
+
workflowStepId: string | null;
|
|
33
|
+
correlationId: string | null;
|
|
34
|
+
}
|
|
35
|
+
export interface ActionLedgerRequestMappingOptions {
|
|
36
|
+
fallbackPrincipalId?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface BuildActionLedgerSensitiveReadInput extends CommonActionLedgerRouteInput, ActionLedgerRequestMappingOptions {
|
|
39
|
+
status?: Extract<ActionLedgerEntry["status"], "succeeded" | "denied" | "failed">;
|
|
40
|
+
reasonCode?: string | null;
|
|
41
|
+
disclosedFieldSet?: string[] | null;
|
|
42
|
+
disclosureSummary?: string | null;
|
|
43
|
+
decisionPolicy?: string | null;
|
|
44
|
+
}
|
|
45
|
+
export type BuildActionLedgerSensitiveReadInputForValue<T> = BuildActionLedgerSensitiveReadInput | ((value: T) => BuildActionLedgerSensitiveReadInput);
|
|
46
|
+
export interface BuildActionLedgerMutationInput extends CommonActionLedgerRouteInput, ActionLedgerRequestMappingOptions {
|
|
47
|
+
actionKind: Extract<ActionLedgerEntry["actionKind"], "create" | "update" | "delete" | "execute">;
|
|
48
|
+
status?: ActionLedgerEntry["status"];
|
|
49
|
+
mutationDetail?: Omit<NewActionMutationDetail, "actionId">;
|
|
50
|
+
}
|
|
51
|
+
export interface BuildActionLedgerApprovalRequestInput extends Omit<BuildActionLedgerMutationInput, "status"> {
|
|
52
|
+
approval: {
|
|
53
|
+
requestedByPrincipalId?: string | null;
|
|
54
|
+
assignedToPrincipalId?: string | null;
|
|
55
|
+
delegatedFromPrincipalId?: string | null;
|
|
56
|
+
policyName: string;
|
|
57
|
+
policyVersion: string;
|
|
58
|
+
targetSnapshotRef?: string | null;
|
|
59
|
+
riskSnapshot?: ActionApproval["riskSnapshot"] | null;
|
|
60
|
+
reasonCode?: string | null;
|
|
61
|
+
expiresAt?: Date | string | null;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export interface BuildActionLedgerApprovalDecisionInput extends ActionLedgerRequestMappingOptions {
|
|
65
|
+
context: ActionLedgerRequestContextValues;
|
|
66
|
+
id: string;
|
|
67
|
+
status: Exclude<ActionApproval["status"], "pending">;
|
|
68
|
+
decidedByPrincipalId?: string | null;
|
|
69
|
+
decidedAt?: Date | string | null;
|
|
70
|
+
actionName: string;
|
|
71
|
+
actionVersion?: string;
|
|
72
|
+
evaluatedRisk?: ActionLedgerEntry["evaluatedRisk"];
|
|
73
|
+
targetType?: string;
|
|
74
|
+
targetId?: string;
|
|
75
|
+
routeOrToolName?: string | null;
|
|
76
|
+
capabilityId?: string | null;
|
|
77
|
+
capabilityVersion?: string | null;
|
|
78
|
+
authorizationSource?: string | null;
|
|
79
|
+
idempotencyScope?: string | null;
|
|
80
|
+
idempotencyKey?: string | null;
|
|
81
|
+
idempotencyFingerprint?: string | null;
|
|
82
|
+
payloads?: AppendActionLedgerEntryInput["payloads"];
|
|
83
|
+
enqueueRelay?: AppendActionLedgerEntryInput["enqueueRelay"];
|
|
84
|
+
organizationId?: string | null;
|
|
85
|
+
workflowRunId?: string | null;
|
|
86
|
+
workflowStepId?: string | null;
|
|
87
|
+
correlationId?: string | null;
|
|
88
|
+
}
|
|
89
|
+
export interface BuildActionLedgerApprovedExecutionFieldsInput {
|
|
90
|
+
requestedActionId: string;
|
|
91
|
+
approvalId: string;
|
|
92
|
+
idempotencyFingerprint: string;
|
|
93
|
+
}
|
|
94
|
+
export interface ActionLedgerApprovedExecutionFields {
|
|
95
|
+
causationActionId: string;
|
|
96
|
+
approvalId: string;
|
|
97
|
+
idempotencyScope: string;
|
|
98
|
+
idempotencyKey: string;
|
|
99
|
+
idempotencyFingerprint: string;
|
|
100
|
+
}
|
|
101
|
+
interface CommonActionLedgerRouteInput {
|
|
102
|
+
context: ActionLedgerRequestContextValues;
|
|
103
|
+
actionName: string;
|
|
104
|
+
actionVersion?: string;
|
|
105
|
+
evaluatedRisk?: ActionLedgerEntry["evaluatedRisk"];
|
|
106
|
+
targetType: string;
|
|
107
|
+
targetId: string;
|
|
108
|
+
routeOrToolName?: string | null;
|
|
109
|
+
capabilityId?: string | null;
|
|
110
|
+
capabilityVersion?: string | null;
|
|
111
|
+
authorizationSource?: string | null;
|
|
112
|
+
causationActionId?: string | null;
|
|
113
|
+
approvalId?: string | null;
|
|
114
|
+
idempotencyScope?: string | null;
|
|
115
|
+
idempotencyKey?: string | null;
|
|
116
|
+
idempotencyFingerprint?: string | null;
|
|
117
|
+
payloads?: AppendActionLedgerEntryInput["payloads"];
|
|
118
|
+
enqueueRelay?: AppendActionLedgerEntryInput["enqueueRelay"];
|
|
119
|
+
organizationId?: string | null;
|
|
120
|
+
workflowRunId?: string | null;
|
|
121
|
+
workflowStepId?: string | null;
|
|
122
|
+
correlationId?: string | null;
|
|
123
|
+
}
|
|
124
|
+
export declare function mapActionLedgerRequestContext(context: ActionLedgerRequestContextValues, options?: ActionLedgerRequestMappingOptions): ActionLedgerActorFields;
|
|
125
|
+
export declare function buildActionLedgerSensitiveReadEntryInput(input: BuildActionLedgerSensitiveReadInput): AppendActionLedgerEntryInput;
|
|
126
|
+
export declare function appendActionLedgerSensitiveRead(db: AnyDrizzleDb, input: BuildActionLedgerSensitiveReadInput): Promise<AppendActionLedgerEntryResult>;
|
|
127
|
+
export declare function ledgerSensitiveRead<T>(db: AnyDrizzleDb, input: BuildActionLedgerSensitiveReadInputForValue<T>, read: () => T | Promise<T>): Promise<T>;
|
|
128
|
+
export declare function buildActionLedgerMutationEntryInput(input: BuildActionLedgerMutationInput): AppendActionLedgerEntryInput;
|
|
129
|
+
export declare function appendActionLedgerMutation(db: AnyDrizzleDb, input: BuildActionLedgerMutationInput): Promise<AppendActionLedgerEntryResult>;
|
|
130
|
+
export declare function buildActionLedgerApprovalRequestInput(input: BuildActionLedgerApprovalRequestInput): RequestActionApprovalInput;
|
|
131
|
+
export declare function requestActionLedgerApproval(db: AnyDrizzleDb, input: BuildActionLedgerApprovalRequestInput): Promise<RequestActionApprovalResult>;
|
|
132
|
+
export declare function buildActionLedgerApprovalDecisionInput(input: BuildActionLedgerApprovalDecisionInput): DecideActionApprovalInput;
|
|
133
|
+
export declare function decideActionLedgerApproval(db: AnyDrizzleDb, input: BuildActionLedgerApprovalDecisionInput): Promise<DecideActionApprovalResult | null>;
|
|
134
|
+
export declare function buildActionLedgerApprovedExecutionFields(input: BuildActionLedgerApprovedExecutionFieldsInput): ActionLedgerApprovedExecutionFields;
|
|
135
|
+
export {};
|
|
136
|
+
//# sourceMappingURL=request-context.d.ts.map
|