77 type BoundApproval ,
88 type PolicyOperation ,
99} from "@siteops/core" ;
10+ import type { z } from "zod" ;
1011
1112import { ApprovalError , ApprovalService } from "../approvals/index.js" ;
1213import { CAPABILITIES , type LocalAuth } from "../auth/index.js" ;
@@ -16,13 +17,15 @@ import {
1617 ApprovalInputSchema ,
1718 DraftInputSchema ,
1819 IdParamsSchema ,
20+ OperationPayloadSchema ,
1921} from "./contracts.js" ;
2022import { registerExecuteRoute } from "./execute-route.js" ;
2123import { loadPolicyContext } from "./policy-context.js" ;
2224import { authorizeRequest } from "./security.js" ;
2325
2426export interface DraftRecord {
2527 readonly operation : PolicyOperation ;
28+ readonly payload : z . infer < typeof OperationPayloadSchema > | null ;
2629}
2730
2831export interface JobRouteOptions {
@@ -97,7 +100,7 @@ export function registerJobRoutes(
97100 const now = options . now ( ) ;
98101 options . database
99102 . prepare (
100- "INSERT INTO operations (id, schema_version, owner_id, generation, target_id, resource_kind, resource_id, capability, operation_class, payload_digest, state, created_at, updated_at) VALUES (?, 1, ?, 1, ?, ?, ?, ?, ?, ?, 'drafted', ?, ?)" ,
103+ "INSERT INTO operations (id, schema_version, owner_id, generation, target_id, resource_kind, resource_id, capability, operation_class, payload_digest, impact_digest, actor_channel, payload_json, state, created_at, updated_at) VALUES (?, 1, ?, 1, ?, ?, ? , ?, ?, ?, ?, ?, ?, 'drafted', ?, ?)" ,
101104 )
102105 . run (
103106 operation . id ,
@@ -108,10 +111,16 @@ export function registerJobRoutes(
108111 operation . capability ,
109112 operation . operationClass ,
110113 operation . payloadDigest ,
114+ operation . declaredImpact . digest ,
115+ actor . channel ,
116+ input . data . payload === null ? null : JSON . stringify ( input . data . payload ) ,
111117 now ,
112118 now ,
113119 ) ;
114- drafts . set ( operation . id , { operation : context . operation } ) ;
120+ drafts . set ( operation . id , {
121+ operation : context . operation ,
122+ payload : input . data . payload ,
123+ } ) ;
115124 options . audit . append ( {
116125 actorId : actor . id ,
117126 action : "job:drafted" ,
@@ -147,6 +156,27 @@ export function registerJobRoutes(
147156 input . data . expiresAt ,
148157 input . data . typedAcknowledgement ,
149158 ) ;
159+ options . database
160+ . prepare (
161+ "INSERT INTO approvals (id, schema_version, owner_id, generation, operation_id, target_id, resource_id, payload_digest, capability, operation_class, impact_digest, approved_by, approved_at, expires_at, state, typed_acknowledgement, created_at, updated_at) VALUES (?, 1, ?, 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'active', ?, ?, ?)" ,
162+ )
163+ . run (
164+ approval . id ,
165+ approval . actorId ,
166+ approval . operationId ,
167+ approval . targetId ,
168+ approval . resource . id ,
169+ approval . payloadDigest ,
170+ approval . capability ,
171+ approval . operationClass ,
172+ approval . impactDigest ,
173+ actor . id ,
174+ approval . approvedAt ,
175+ approval . expiresAt ,
176+ approval . typedAcknowledgement ,
177+ approval . approvedAt ,
178+ approval . approvedAt ,
179+ ) ;
150180 approved . set ( approval . id , approval ) ;
151181 options . audit . append ( {
152182 actorId : actor . id ,
0 commit comments