Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,116 @@
# tracker-utils

A Node.js utility library for backend services, providing database, caching, messaging, security, logging, and other common infrastructure helpers.

**Requires Node.js >= 18.0.0**

## Installation

```bash
npm install tracker-utils
```

## Modules

| Module | Description |
|--------|-------------|
| **BufferWriter** | Buffer writing utilities |
| **Cache** | Caching layer (Memcached) |
| **Db** | MongoDB database connection (Mongoose) |
| **DbUtil** | Database helper utilities |
| **Messaging** | Message queue abstraction (Google Cloud Pub/Sub) |
| **Redis** | Redis client |
| **Registry** | Registry / service registration utilities |
| **Security** | ID generation, hashing (MD5), IP masking, AES encryption/decryption, base64 |
| **TrafficDistribution** | Traffic distribution utilities |
| **ArrayMethods** | Array helper methods |
| **StringMethods** | String helper methods |
| **Mailer** | Email sending (Mailgun) |
| **Request** | HTTP request utilities |
| **RequestV2** | HTTP client (Got-based) |
| **CloudStorage** | Google Cloud Storage client |
| **Logger** | Winston-based logging |
| **DevTool** | Development utilities |
| **UrlUtil** | URL parsing and manipulation |
| **Tools** | General helpers (`handleShutdown`, `sleep`) |

## Usage

### Messaging (Pub/Sub)

```javascript
const { Messaging } = require('tracker-utils');

const pubsub = Messaging.Factory.make('pubsub', {
project: 'your-gcp-project',
topic: 'your-topic',
subscription: 'your-subscription',
handler(message) {
console.log(String(message.data));
message.ack();
},
});

await pubsub.send('Hello, world!');
await pubsub.receive();
```

### Security

```javascript
const { Security } = require('tracker-utils');
const security = new Security();

security.id(); // ULID-style unique ID
security.md5('string'); // MD5 hash
security.maskIp(ip); // Mask last octet for privacy
security.encrypt(text, key);
security.decrypt(cipherText, key);
```

### Logger

```javascript
const { Logger } = require('tracker-utils');

Logger.info('message');
Logger.error('error', { err });
```

### Database (MongoDB)

```javascript
const { Db } = require('tracker-utils');

// Use Db for Mongoose connection and models
```

### Redis & Cache

```javascript
const { Redis, Cache } = require('tracker-utils');

// Redis client and Memcached-based cache
```

### Tools

```javascript
const { Tools } = require('tracker-utils');

Tools.sleep(1000); // Promise-based delay (ms)
Tools.handleShutdown(cb); // Graceful shutdown handler
```

## Development

- **Linting / format:** Prettier (see `prettier.config.js`)
- **Editor:** `.editorconfig` is included
- **CI:** Security scan (CodeQL) runs on pull requests to `master`

Pull requests are welcome. Please use the [pull request template](.github/PULL_REQUEST_TEMPLATE.md) when submitting changes.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix platform name capitalization (“GitHub”).

Line 111 uses “Github”; the official capitalization is “GitHub”.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~111-~111: The official name of this software platform is spelled with a capital “H”.
Context: ...e. Please use the pull request template when submitti...

(GITHUB)

🤖 Prompt for AI Agents
In `@README.md` at line 111, Update the README.md occurrence of the platform name
from "Github" to the correct capitalization "GitHub" in the sentence that
references the pull request template (the line containing "Pull requests are
welcome. Please use the [pull request
template](.github/PULL_REQUEST_TEMPLATE.md) when submitting changes.").


## License

See [LICENSE](LICENSE).

Loading