Single Source of Truth for GIRP (Guided Incident Response Platform) data structures. Contains the shared Mongoose models used across all GIRP microservices to keep data structures consistent.
npm install @girp/database-modelsRequires Node.js >= 20 and MongoDB via Mongoose 8.
const { TicketModel, Playbook, FormResult } = require("@girp/database-models");
const openTickets = await TicketModel.find({ state: "open" });| Model | Purpose |
|---|---|
Playbook |
Playbook / form definitions built with the GIRP Formbuilder |
PlaybookVersion |
Versioned playbook snapshots |
FormSession |
In-progress form fill sessions |
FormResult |
Completed form submissions |
TicketModel |
Incident tickets |
UserModel |
User accounts |
UserPreferences |
Per-user settings |
ApiToken |
API access tokens |
CounterModel |
Sequence counters (auto-increment IDs) |
Settings |
Global application settings |
The models register themselves on the default Mongoose connection — call mongoose.connect(...) in your service before using them.
Note: once the connection is established, the ticket and user models backfill missing
createdAt/updatedAt/rolesfields on existing documents (one idempotentupdateManyeach). This keeps documents created by older GIRP versions queryable.
TicketModel automatically records field changes in an embedded changelog.
Pass the acting user so entries are attributed:
// a) save() path — set the actor via $locals
const ticket = await TicketModel.findById(id);
ticket.$locals.userId = req.user._id;
ticket.state = "mitigation";
await ticket.save();
// b) query update path — pass the actor as a query option
await TicketModel.findByIdAndUpdate(
id,
{
$set: { state: "closed" },
$push: { comments: { comment_content: "Done", author: req.user._id } },
},
{ new: true, runValidators: true, userId: req.user._id }
);
// c) fetch the merged comment/changelog timeline (populated, newest first)
const timeline = await TicketModel.getTimelineById(id, { populate: true, order: "desc" });Licensed under the Sustainable Use License — see LICENSE.md.