open-index/open-npm huggingface dataset:
npm package: @heyhru/business-dms-approval
Description: DMS approval workflow domain logic: service, model, sql
Latest version: 0.6.2

# @heyhru/business-dms-approval

DMS approval workflow domain logic: service, model, sql.

## Exports

### Direct route handlers

```ts
import {
  approvalList,
  approvalGet,
  approvalCreate,
  approvalApprove,
  approvalReject,
} from "@heyhru/business-dms-approval";

app.post("/approvals/list", approvalList);
app.post("/approvals/get", approvalGet);
app.post("/approvals/create", approvalCreate);
app.post("/approvals/approve", approvalApprove);
app.post("/approvals/reject", approvalReject);
```

### Curried handler (encryptionKey required)

```ts
import { approvalExecute } from "@heyhru/business-dms-approval";

app.post("/approvals/execute", approvalExecute(config.encryptionKey));
```

`approvalExecute` uses `FastifyBaseLogger` (via `req.log`) internally — no additional logger setup needed.
npm package: @heyhru/business-dms-audit
Description: DMS audit log domain logic: service, model, sql
Latest version: 0.6.1

# @heyhru/business-dms-audit

DMS audit log domain logic: service, model, sql.

## Exports

### `writeAuditLog(entry)` — cross-module function

Records an audit log entry. Called by other service modules (e.g. approvals).

```ts
import { writeAuditLog } from "@heyhru/business-dms-audit";

await writeAuditLog({
  userId: "user-id",
  dataSourceId: "ds-id",
  action: "DML_EXECUTE",
  sqlText: "UPDATE ...",
  resultSummary: "1 rows affected",
  ipAddress: "1.2.3.4",
});
```

### `logList(req, reply)` — Fastify route handler

Lists audit logs with optional filters. Bind directly to a route.

```ts
import { logList } from "@heyhru/business-dms-audit";

app.post("/logs/list", logList);
```

**Request body** (all optional):

| Field          | Type   | Description                   |
| -------------- | ------ | ----------------------------- |
| `userId`       | string | Filter by user                |
| `dataSourceId` | string | Filter by data source         |
| `limit`        | string | Max results (default 50)      |
| `offset`       | string | Pagination offset (default 0) |
npm package: @heyhru/business-dms-datasource
Description: DMS data source domain logic: service, model, sql, pool management
Latest version: 0.7.1

# @heyhru/business-dms-datasource

DMS data source domain logic: service, model, sql, and connection pool management.

## Exports

### Route handlers

```ts
import {
  datasourceList,
  datasourceGet,
  datasourceCreate,
  datasourceDelete,
} from "@heyhru/business-dms-datasource";

// Direct handlers (no encryptionKey needed)
app.post("/datasources/list", datasourceList);
app.post("/datasources/get", datasourceGet);
app.post("/datasources/delete", datasourceDelete);

// Curried handlers (encryptionKey required)
app.post("/datasources/create", datasourceCreate(config.encryptionKey));
app.post("/datasources/update", datasourceUpdate(config.encryptionKey));
```

### Cross-module functions

```ts
import {
  getDataSourceWithPassword,
  getPool,
  getPoolForDatabase,
} from "@heyhru/business-dms-datasource";

// Decrypt password and return full data source object
const ds = await getDataSourceWithPassword(dataSourceId, config.encryptionKey);

// Get or create a connection pool
const pool = getPool(ds);

// Get pool for a specific database within an instance
const pool = await getPoolForDatabase(dataSourceId, database, config.encryptionKey);
```

## Types

```ts
import type { DbPool, DataSourceWithPassword } from "@heyhru/business-dms-datasource";
```
npm package: @heyhru/business-dms-saved-sql
Description: DMS saved SQL domain logic: service, model, sql
Latest version: 0.6.1

# @heyhru/business-dms-saved-sql

DMS saved SQL domain logic: service, model, sql.

## API

### Route handlers (Fastify)

The following functions are route-facing handlers with signature `(req: FastifyRequest, reply: FastifyReply)`. Register them directly on a Fastify instance.

| Function         | Route action              | Description                                                                          |
| ---------------- | ------------------------- | ------------------------------------------------------------------------------------ |
| `savedSqlList`   | `POST /saved-sqls/list`   | List saved SQLs for the authenticated user                                           |
| `savedSqlCreate` | `POST /saved-sqls/create` | Create a saved SQL (`name`, `sqlText` required; `dataSourceId`, `database` optional) |
| `savedSqlUpdate` | `POST /saved-sqls/update` | Update `name` or `sqlText` by `id`                                                   |
| `savedSqlDelete` | `POST /saved-sqls/delete` | Delete a saved SQL by `id`                                                           |

All endpoints are user-scoped: operations are restricted to the authenticated user's own records.
npm package: @heyhru/business-dms-user
Description: DMS user domain logic: service, model, sql
Latest version: 0.6.1

# @heyhru/business-dms-user

DMS user domain logic: service, model, sql.

## API

### `getUserByUsername(username: string)`

Look up a user by username. Returns the full user row (including `password_hash`) or `undefined`.

Used by auth service for login and password change.

### `updateUserPassword(id: string, hash: string)`

Update the `password_hash` for a user by ID.

### Route handlers (Fastify)

The following functions are route-facing handlers with signature `(req: FastifyRequest, reply: FastifyReply)`. Register them directly on a Fastify instance.

| Function     | Route action         | Description                      |
| ------------ | -------------------- | -------------------------------- |
| `userList`   | `POST /users/list`   | List all users                   |
| `userGet`    | `POST /users/get`    | Get a user by `id` in body       |
| `userCreate` | `POST /users/create` | Create a user, hashes password   |
| `userUpdate` | `POST /users/update` | Update `email` or `role` by `id` |
| `userDelete` | `POST /users/delete` | Delete a user by `id`            |
npm package: @heyhru/common-util-fetch
Description: Shared HTTP fetch wrapper based on axios, usable on web/server/RN
Latest version: 0.6.0

# @heyhru/common-util-fetch

Shared HTTP fetch wrapper based on [axios](https://axios-http.com), usable on web, server, and React Native.

## Installation

```bash
pnpm add @heyhru/common-util-fetch
```

## Usage

```ts
import { create } from "@heyhru/common-util-fetch";

const client = create({
  baseURL: "https://api.example.com",
  getToken: () => localStorage.getItem("token"), // optional: attach Bearer token
  onUnauthorized: () => {
    localStorage.removeItem("token");
    window.location.href = "/login";
  },
});

// GET
const user = await client.get<User>("/users/1");

// POST
const created = await client.post<User>("/users", { name: "Alice" });

// PUT
const updated = await client.put<User>("/users/1", { name: "Bob" });

// DELETE
await client.delete("/users/1");
```

## API

### `create(config)`

| Option            | Type                                              | Default  | Description                                       |
| ----------------- | ------------------------------------------------- | -------- | ------------------------------------------------- |
| `baseURL`         | `string`                                          | required | Base URL for all requests                         |
| `getToken`        | `() => string \| null \| Promise<string \| null>` | —        | Called before each request to attach Bearer token |
| `withCredentials` | `boolean`                                         | `false`  | Send cookies with cross-origin requests           |
| `onUnauthorized`  | `() => void`                                      | —        | Called when a 401 response is received            |

Returns a `FetchClient` with `get`, `post`, `put`, `delete` methods. All methods return `response.data` directly.
npm package: @heyhru/common-util-logger
Description: Shared logger based on pino, usable on web and server
Latest version: 0.6.0

# @heyhru/common-util-logger

Shared logger based on [pino](https://github.com/pinojs/pino), usable on both server and browser.

## Usage

```ts
import { createLogger } from "@heyhru/common-util-logger";

const logger = createLogger({ name: "my-service" });

logger.info("server started");
logger.error({ err }, "request failed");
logger.debug({ userId }, "user login");

// Child logger with bound context
const reqLogger = logger.child({ requestId: "abc-123" });
reqLogger.info("handling request");
```

## Options

| Option | Type   | Default                             | Description       |
| ------ | ------ | ----------------------------------- | ----------------- |
| name   | string | —                                   | Logger name       |
| level  | string | `debug` (dev) / `info` (production) | Minimum log level |

## Log Levels

| Level | Value | Usage                  |
| ----- | ----- | ---------------------- |
| fatal | 60    | Process about to crash |
| error | 50    | Runtime errors         |
| warn  | 40    | Warnings               |
| info  | 30    | General information    |
| debug | 20    | Debug details          |
| trace | 10    | Fine-grained tracing   |

## Environment Behavior

- **Development** (`NODE_ENV !== 'production'`): defaults to `debug` level, uses `pino-pretty` for colorized output (server only)
- **Production**: defaults to `info` level, outputs JSON to stdout
- **Browser**: uses `console` methods, no `pino-pretty`
npm package: @heyhru/server-plugin-jwt
Description: JWT utilities: sign and verify tokens
Latest version: 0.6.0

# @heyhru/server-util-jwt

JWT utilities: sign and verify tokens.

## Install

```bash
pnpm add @heyhru/server-util-jwt
```

## API

### `signToken(payload, secret, expiresIn)`

Sign a JWT token.

```ts
import { signToken } from "@heyhru/server-util-jwt";

const token = signToken({ userId: "123" }, "secret", "24h");
```

### `verifyToken<T>(token, secret)`

Verify and decode a JWT token.

```ts
import { verifyToken } from "@heyhru/server-util-jwt";

const payload = verifyToken<{ userId: string }>(token, "secret");
```
npm package: @heyhru/server-plugin-mysql
Description: MySQL connection pool with unified execute interface
Latest version: 0.7.0

# @heyhru/server-util-mysql

MySQL connection pool with unified `DbPool` interface.

## Install

```bash
pnpm add @heyhru/server-util-mysql
```

## API

### `createPool(config): DbPool`

Create a MySQL connection pool.

```ts
import { createPool } from "@heyhru/server-util-mysql";

const pool = createPool({
  host: "localhost",
  port: 3306,
  database: "mydb",
  username: "root",
  password: "password",
  poolMax: 10,
});

const rows = await pool.execute("SELECT * FROM users");
await pool.end();
```

### `DbPool` interface

```ts
interface DbPool {
  execute(sql: string): Promise<unknown[]>;
  end(): Promise<void>;
}
```
npm package: @heyhru/server-plugin-pg
Description: PostgreSQL connection pool with unified execute interface
Latest version: 0.7.0

# @heyhru/server-util-pg

PostgreSQL connection pool with unified `DbPool` interface.

## Install

```bash
pnpm add @heyhru/server-util-pg
```

## API

### `createPool(config): DbPool`

Create a PostgreSQL connection pool.

```ts
import { createPool } from "@heyhru/server-util-pg";

const pool = createPool({
  host: "localhost",
  port: 5432,
  database: "mydb",
  username: "postgres",
  password: "password",
  poolMin: 2,
  poolMax: 10,
});

const rows = await pool.execute("SELECT * FROM users");
await pool.end();
```

### `DbPool` interface

```ts
interface DbPool {
  execute(sql: string): Promise<unknown[]>;
  end(): Promise<void>;
}
```
npm package: @heyhru/server-util-crypto
Description: Cryptographic utilities: AES-256-GCM encryption and scrypt password hashing
Latest version: 0.6.0

# @heyhru/server-util-crypto

Cryptographic utilities: AES-256-GCM encryption and scrypt password hashing. Zero external dependencies — built on `node:crypto`.

## Usage

```ts
import { encrypt, decrypt, hashPassword, verifyPassword } from "@heyhru/server-util-crypto";

// AES-256-GCM encryption (requires a 32-byte key)
const key = "your-32-byte-encryption-key-here";
const ciphertext = encrypt("sensitive data", key);
const plaintext = decrypt(ciphertext, key);

// scrypt password hashing
const hash = await hashPassword("user-password");
const isValid = await verifyPassword("user-password", hash);
```

## API

### `encrypt(plaintext: string, key: string): string`

Encrypt a string using AES-256-GCM. Returns `iv:tag:ciphertext` in hex.

### `decrypt(ciphertext: string, key: string): string`

Decrypt a string produced by `encrypt()`.

### `hashPassword(password: string): Promise<string>`

Hash a password using scrypt. Returns `salt:hash` in hex.

### `verifyPassword(password: string, hash: string): Promise<boolean>`

Verify a password against a hash produced by `hashPassword()`.
npm package: @heyhru/server-util-jwt
Description: JWT utilities: sign and verify tokens
Latest version: 0.1.2

# @heyhru/server-util-jwt

JWT utilities: sign and verify tokens.

## Install

```bash
pnpm add @heyhru/server-util-jwt
```

## API

### `signToken(payload, secret, expiresIn)`

Sign a JWT token.

```ts
import { signToken } from "@heyhru/server-util-jwt";

const token = signToken({ userId: "123" }, "secret", "24h");
```

### `verifyToken<T>(token, secret)`

Verify and decode a JWT token.

```ts
import { verifyToken } from "@heyhru/server-util-jwt";

const payload = verifyToken<{ userId: string }>(token, "secret");
```
npm package: @heyhru/server-util-mysql
Description: MySQL connection pool with unified execute interface
Latest version: 0.1.2

# @heyhru/server-util-mysql

MySQL connection pool with unified `DbPool` interface.

## Install

```bash
pnpm add @heyhru/server-util-mysql
```

## API

### `createPool(config): DbPool`

Create a MySQL connection pool.

```ts
import { createPool } from "@heyhru/server-util-mysql";

const pool = createPool({
  host: "localhost",
  port: 3306,
  database: "mydb",
  username: "root",
  password: "password",
  poolMax: 10,
});

const rows = await pool.execute("SELECT * FROM users");
await pool.end();
```

### `DbPool` interface

```ts
interface DbPool {
  execute(sql: string): Promise<unknown[]>;
  end(): Promise<void>;
}
```
npm package: @heyhru/server-util-pg
Description: PostgreSQL connection pool with unified execute interface
Latest version: 0.1.3

# @heyhru/server-util-pg

PostgreSQL connection pool with unified `DbPool` interface.

## Install

```bash
pnpm add @heyhru/server-util-pg
```

## API

### `createPool(config): DbPool`

Create a PostgreSQL connection pool.

```ts
import { createPool } from "@heyhru/server-util-pg";

const pool = createPool({
  host: "localhost",
  port: 5432,
  database: "mydb",
  username: "postgres",
  password: "password",
  poolMin: 2,
  poolMax: 10,
});

const rows = await pool.execute("SELECT * FROM users");
await pool.end();
```

### `DbPool` interface

```ts
interface DbPool {
  execute(sql: string): Promise<unknown[]>;
  end(): Promise<void>;
}
```
npm package: @heyhru/server-util-sqlite
Description: SQLite connection manager built on better-sqlite3
Latest version: 0.1.2

# @heyhru/server-util-sqlite

SQLite connection manager built on [better-sqlite3](https://github.com/WiseLibs/better-sqlite3).

## Usage

```ts
import { createSqlite, getSqlite, closeSqlite } from "@heyhru/server-util-sqlite";

// Initialize once at startup
createSqlite({
  path: "./data.db",
  pragmas: { journal_mode: "WAL", foreign_keys: "ON" }, // these are defaults
});

// Use anywhere in the app
const db = getSqlite();
const rows = db.prepare("SELECT * FROM users").all();

// Close on shutdown
closeSqlite();
```

## API

### `createSqlite(options: SqliteOptions): Database`

Initialize the SQLite connection. Throws if already initialized.

**Options:**

| Property  | Type                    | Required | Default                                       |
| --------- | ----------------------- | -------- | --------------------------------------------- |
| `path`    | `string`                | Yes      | —                                             |
| `pragmas` | `Record<string,string>` | No       | `{ journal_mode: "WAL", foreign_keys: "ON" }` |

### `getSqlite(): Database`

Get the initialized instance. Throws if not initialized.

### `closeSqlite(): void`

Close the connection and reset the instance. Safe to call when not initialized.