@classytic/shared-types

v1.0.1

Published

Shared TypeScript interfaces and types for Classytic packages (revenue, payroll, etc.)

Readme

@classytic/shared-types

Shared TypeScript interfaces and types for Classytic packages.

Overview

This package provides unified type definitions used across the Classytic ecosystem:

  • @classytic/revenue - Revenue management system
  • @classytic/payroll - Payroll management system
  • Other Classytic packages

Installation

npm install @classytic/shared-types

Usage

Transaction Interface

The ITransaction interface is a unified type that works with both revenue and payroll packages:

import type { ITransaction } from '@classytic/shared-types';

// Use in your Mongoose schema
import mongoose, { Schema } from 'mongoose';

const TransactionSchema = new Schema<ITransaction>({
  organizationId: { type: Schema.Types.ObjectId, required: true },
  amount: { type: Number, required: true },
  type: { type: String, required: true },
  flow: { type: String, enum: ['inflow', 'outflow'], required: true },
  // ... all other fields
});

export const Transaction = mongoose.model<ITransaction>('Transaction', TransactionSchema);

Type Guards

import { isTransaction } from '@classytic/shared-types';

if (isTransaction(someObject)) {
  // TypeScript knows this is an ITransaction
  console.log(someObject.amount);
}

Helpers

import { toTransactionObject } from '@classytic/shared-types';

const plainObject = toTransactionObject(transactionDocument);

Package-Specific Fields

The unified interface includes fields for both revenue and payroll packages:

Shared fields (used by both):

  • organizationId, amount, type, flow, status
  • currency, fee, tax, net
  • taxDetails, method, gateway, paymentDetails
  • date, metadata, reconciliation

Revenue-specific (optional for payroll):

  • commission, splits, escrow
  • verifiedAt, refundedAmount, refundedAt
  • lineItems, webhook

Payroll-specific (optional for revenue):

  • employeeId
  • breakdown.period, breakdown.workingDays
  • processedAt, processedBy

Benefits

Single source of truth - One interface for all packages ✅ Type safety - Full TypeScript support ✅ Flexibility - Package-specific fields are optional ✅ Simplicity - No discriminators, no complexity

License

MIT © Sadman Chowdhury