ncx-common-repo
v1.0.15
Published
## Overview
Readme
Common Functions Handling Repository
Overview
This repository contains reusable, framework-agnostic common functions that can be shared across multiple Node.js applications. The goal of this package is to provide pure business logic utilities without tightly coupling them to infrastructure layers such as databases, Redis, or external services.
This package follows Clean Architecture and Dependency Injection principles, allowing the consuming application to inject its own database, cache, logger, or workflow implementations.
Features
- Reusable across multiple projects
- No direct dependency on MySQL, Redis, or external services
- Dependency Injection based design
- Easily testable
- Production-ready structure
- Lightweight and fast
Installation
Using npm
npm install @your-org/common-functionsUsing yarn
yarn add @your-org/common-functionsProject Structure
common-functions/
├ src/
│ ├ handleGetSpecificBranchDetails.js
│ ├ transformBranchData.js
│
├ index.js
├ package.json
├ README.md
└ types.d.ts (optional)Usage
This package requires external dependencies like database, Redis, and workflow trigger to be injected from the consuming application.
Example
const {
handleGetSpecificBranchDetails
} = require('@your-org/common-functions');
const db = await getConnection();
const redis = redisClient;
await handleGetSpecificBranchDetails({
TAOCInstId: 123,
listReplyTitle: "Branch Name",
existingSession,
sessionId,
db,
redis,
workflowTrigger: async ({
branchData,
postContentMaster,
existingSession,
sessionId
}) => {
await WorkFlowTriggerForResponder(
{},
'',
existingSession,
sessionId,
'APIInteractiveClick',
14,
null,
null,
'API_GetSpecificBranchDetails',
{
branchData,
postContentMaster
}
);
}
});Function API
handleGetSpecificBranchDetails(options)
Parameters
| Parameter | Type | Required | Description | | --------------- | -------- | -------- | ------------------------- | | TAOCInstId | number | Yes | Branch Instance ID | | listReplyTitle | string | Yes | User reply title | | existingSession | object | Yes | Existing session object | | sessionId | string | Yes | Session ID | | db | object | Yes | Database client instance | | redis | object | Yes | Redis client instance | | workflowTrigger | function | Yes | Workflow handler function | | logger | object | No | Custom logger |
Returns
{
branchData: Array,
postContentMaster: Object
}Dependency Injection Pattern
This package does NOT create:
- Database connections
- Redis connections
- Workflow handlers
These must be provided by the application.
Example:
Application Layer → injects → Common Functions PackageError Handling
All errors are thrown back to the caller.
Example:
try {
await handleGetSpecificBranchDetails(...)
}
catch(err){
console.error(err);
}Testing
Example using Jest:
npm testMock dependencies:
const mockDb = {
query: jest.fn()
};Publishing
Update version:
npm version patchPublish:
npm publishPrivate publish:
npm publish --access restrictedVersioning
This project follows Semantic Versioning:
MAJOR.MINOR.PATCHExample:
1.0.0Best Practices
Recommended usage:
- Inject dependencies
- Do not modify internal logic
- Handle logging in application layer
Avoid:
- Creating DB connections inside this package
- Creating Redis connections inside this package
Example Use Cases
This package can be used in:
- Backend services
- Worker services
- Cron jobs
- Microservices
- Serverless functions
Contributing
Steps:
1. Fork repository
2. Create feature branch
3. Commit changes
4. Create Pull RequestLicense
ISC
Author
NeuronCX
Support
Contact:
[email protected]