import { serializeOperationMetadata } from "@open-mercato/shared/lib/commands/operationMetadata";
function withOperationMetadata(response, logEntry, fallback) {
  if (!logEntry?.undoToken || !logEntry.id || !logEntry.commandId) return response;
  response.headers.set(
    "x-om-operation",
    serializeOperationMetadata({
      id: logEntry.id,
      undoToken: logEntry.undoToken,
      commandId: logEntry.commandId,
      actionLabel: logEntry.actionLabel ?? null,
      resourceKind: logEntry.resourceKind ?? fallback.resourceKind,
      resourceId: logEntry.resourceId ?? fallback.resourceId,
      executedAt: logEntry.createdAt instanceof Date ? logEntry.createdAt.toISOString() : (/* @__PURE__ */ new Date()).toISOString()
    })
  );
  return response;
}
export {
  withOperationMetadata
};
//# sourceMappingURL=operationMetadata.js.map
