@talkpilot/core-db
v1.0.26
Published
Core database package for centralized connections and ORM integration.
Maintainers
Readme
@talkpilot/core-db
A TypeScript-based core database management package designed to provide centralized database connections, ORM integrations, and client utilities for other projects. This package manages connections to both TalkPilot and Municipal MongoDB databases.
Features
- 🚀 Multi-Domain Database Management: Centralized handlers for both TalkPilot and Municipal Data domains.
- 📦 Reusable Getters: Standardized functions for fetching data from various collections (calls, agents, leads, cities, etc.).
- 🏗️ Type-safe: Built with TypeScript for full type safety across all your database interactions.
- 🛠️ Environment Aware: Configurable via environment variables or explicit parameters.
Installation
This package is intended to be used as a dependency in other projects. If you're working locally, you can install it using a file path:
# In your other project:
npm install /path/to/core-db
# or if published to a registry:
npm install @talkpilot/core-db
# or via GitHub
npm install github:talkpilot/core-dbQuick Start
1. Initialize Database Connections
You must initialize the database clients before using any of the getters.
import { mongodbClient, municipalDataMongodbClient } from '@talkpilot/core-db';
async function bootstrap() {
// Initialize TalkPilot DB
await mongodbClient.connect(process.env.TALKPILOT_MONGO_URI);
// Initialize Municipal Data DB (optional)
await municipalDataMongodbClient.connect(process.env.MUNICIPAL_MONGO_URI);
}
bootstrap().catch(console.error);2. Using Getters
Once initialized, you can import and use any of the exported database getters.
import { findAgents, findCities } from '@talkpilot/core-db';
async function getSummary() {
// Get all agents from TalkPilot DB
const agents = await findAgents();
console.log('Total Agents:', agents.length);
// Get all cities from Municipal Data DB
const cities = await findCities();
console.log('Total Cities:', cities.length);
}Available Domains
The package exports two main sets of tools:
TalkPilot Domain
Includes access to:
agents,calls,clients,flows,leads,phone_numbers,plans,results,sessions,subscriptions, etc.- Exported as root level functions or via
mongodbClient.
Municipal Domain
Includes access to:
cities,streets,departmentsSubjects,tickets.- Functions are prefixed where necessary or accessible via
getMunicipalDataDb.
Environment Variables
The clients will automatically attempt to use the following environment variables if no URI is provided to the connect() method:
MONGO_URIorMONGODB_URI: Primary MongoDB connection string.MONGODB_DB_NAME: Database name (defaults to 'municipal-data' for the municipal client if not specified).
Development
Setup
- Clone the repository and install dependencies:
git clone https://github.com/talkpilot/core-db.git
cd core-db
npm install- Build the project:
npm run buildThis will generate the dist/ directory with the compiled JavaScript and type definitions.
Publishing New Versions
To publish a new version of the package:
- Test your changes:
npm test- Update the version:
# Bumps patch version (0.1.0 -> 0.1.1)
npm version patch
# Or for minor changes (0.1.0 -> 0.2.0)
# npm version minor
# Or for major changes (0.1.0 -> 1.0.0)
# npm version major- Publish to npm:
Ensure you have the shared team token in your
~/.npmrc(see Development Guide). - Update in other repos:
npm update @talkpilot/core-dbLicense
MIT
Interested in contributing? Check out our Development Guide for standards and setup instructions.
Release Notes
1.0.16
- Fixed critical issues present in version 1.0.15.
- Warning: Version 1.0.15 is bugged and should not be used. Please use at least version 1.0.16.
1.0.20
- Added to Moked106Config this param: withNeedAttentionCalls
- withNeedAttentionCalls?: boolean
