npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@cowris/walletdb-client

v1.1.1

Published

This is a Prisma and MongoDB Client package for the Cowris WalletDB. It provides a simple interface to interact with the Wallet databases(Source of truth and read replica), allowing you to perform CRUD operations on wallet and transaction data and related

Readme

Cowris WalletDB Client

Overview

@cowris/walletdb-client is a shared database access package for the Cowris Wallet Service. It provides a unified interface to interact with both the PostgreSQL source of truth and the MongoDB read replica for wallets and transaction data.

This package is intended to be used by internal Cowris services such as services-wallet, enabling them to perform secure, consistent, and high-performance reads and writes across all wallet-related operations.


Tech Stack

  • PostgreSQL (Main WalletDB — Source of Truth)
  • MongoDB (Read Replica — optimized for fast read access)
  • Prisma (ORM for PostgreSQL)
  • Mongoose (ODM for MongoDB)
  • Node.js (CommonJS module format)

Features

  • Connects to Cowris Wallet PostgreSQL via Prisma

  • Connects to Cowris MongoDB replica using Mongoose

  • Shared models for:

    • Wallets
    • Transactions
    • Funding
    • Withdrawals
    • Reversals
    • Transfers
  • Singleton pattern for connection management

  • Safe for use across multiple microservices

  • Lazy MongoDB initialization (connectMongo())


Installation

npm install @cowris/walletdb-client

Environment Variables

Ensure the following variables are defined in your consumer service’s .env:

# PostgreSQL
WALLET_DATABASE_URL=

# MongoDB
MONGO_WALLETDB_URL=

Setup the database in microservice

Add this under scripts in package.json in the microservice

"setup-prisma:walletdb": "node node_modules/@cowris/walletdb-client/scripts/migrate.js || echo 'Migration failed. Please install the cowris walletdb client. Run `npm install @cowris/walletdb-client` to install it.'"

Usage

1. Import the package

const {
  prisma,
  connectMongo,
  WalletModel,
  TransactionModel,
  FundingModel,
  TransferModel,
  WithdrawalModel,
  ReversalModel,
} = require('@cowris/walletdb-client');

2. Initialize MongoDB connection (only once)

await connectMongo(); // Safe to call multiple times, only connects once

3. Use the Prisma client (PostgreSQL)

const wallet = await prisma.wallet.findMany({
  where: { user_id: 'user_123' },
});

4. Use the Mongoose models (MongoDB)

const mongoWallet = await WalletModel.findOne({ user_id: 'user_123' });

Available Models

| Model | Type | Description | | ------------------ | ------------ | ---------------------------------------------- | | WalletModel | Mongoose | Wallet read replica (MongoDB) | | TransactionModel | Mongoose | Transaction replica (MongoDB) | | FundingModel | Mongoose | Funding details (MongoDB) | | WithdrawalModel | Mongoose | Withdrawal details (MongoDB) | | TransferModel | Mongoose | Transfer details (MongoDB) | | ReversalModel | Mongoose | Reversal details (MongoDB) | | prisma | PrismaClient | PostgreSQL client (CRUD on Wallet/Transaction) |


Schema Locations

  • PostgreSQL Schema (Prisma): ./prisma/schema.prisma
  • MongoDB Models: ./mongodb/models/*.model.js

Design Consideration

This dual-database architecture allows us to:

  • Perform consistent writes to PostgreSQL (the source of truth)
  • Enable high-speed reads using MongoDB, reducing query latency

Data is synchronized from PostgreSQL to MongoDB via Change Data Capture (CDC) using Apache Kafka.


Publishing (Internal Only)

To publish a new version after changes:

npm version patch   # or minor / major
npm publish --access public

License

MIT License © Cowris Technologies