Skip to content
Open
Show file tree
Hide file tree
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
61 changes: 23 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,20 @@ API gateway, usage metering, and billing services for the Callora API marketplac

## Vault repository behavior

<<<<<<< HEAD
Endpoint:

`GET /api/developers/analytics`

Authentication:

- Requires `x-user-id` header (developer identity for now).

Query params:

- `from` (required): ISO date/time
- `to` (required): ISO date/time
- `groupBy` (optional): `day | week | month` (default: `day`)
- `apiId` (optional): filters to one API (must belong to authenticated developer)
- `includeTop` (optional): set to `true` to include `topEndpoints` and anonymized `topUsers`
=======
- Enforces one vault per user per network.
- `balanceSnapshot` is stored in smallest units using non-negative integer `bigint` values.
- `findByUserId` is network-aware and returns the vault for a specific user/network pair.
>>>>>>> main

Developer analytics endpoint:

- `GET /api/developers/analytics`
- Requires `x-user-id` header (developer identity for now)
- Query params:
- `from` (required): ISO date/time
- `to` (required): ISO date/time
- `groupBy` (optional): `day | week | month` (default: `day`)
- `apiId` (optional): filters to one API (must belong to authenticated developer)
- `includeTop` (optional): set to `true` to include `topEndpoints` and anonymized `topUsers`

## Local setup

Expand All @@ -52,38 +45,36 @@ Query params:
npm install
npm run dev
```
<<<<<<< HEAD
3. API base: `http://localhost:3000`

3. API base: [http://localhost:3000](http://localhost:3000). Example: [http://localhost:3000/api/health](http://localhost:3000/api/health).

### Docker Setup

You can run the entire stack (API and PostgreSQL) locally using Docker Compose:

```bash
docker compose up --build
```
The API will be available at http://localhost:3000, and the PostgreSQL database will be mapped to local port 5432.
=======

3. API base: [http://localhost:3000](http://localhost:3000). Example: [http://localhost:3000/api/health](http://localhost:3000/api/health).
>>>>>>> main
The API will be available at http://localhost:3000, and the PostgreSQL database will be mapped to local port 5432.

## Scripts

| Command | Description |
|---|---|
| `npm run dev` | Run with tsx watch (no build) |
| `npm run build` | Compile TypeScript to `dist/` |
| `npm start` | Run compiled `dist/index.js` |
| `npm test` | Run unit tests |
| `npm run test:coverage` | Run unit tests with coverage |
| Command | Description |
| ----------------------- | ----------------------------- |
| `npm run dev` | Run with tsx watch (no build) |
| `npm run build` | Compile TypeScript to `dist/` |
| `npm start` | Run compiled `dist/index.js` |
| `npm test` | Run unit tests |
| `npm run test:coverage` | Run unit tests with coverage |

### Observability (Prometheus Metrics)

The application exposes a standard Prometheus text-format metrics endpoint at `GET /api/metrics`.
It automatically tracks `http_requests_total`, `http_request_duration_seconds`, and default Node.js system metrics.

#### Production Security:

In production (NODE_ENV=production), this endpoint is protected. You must configure the METRICS_API_KEY environment variable and scrape the endpoint using an authorization header:
Authorization: Bearer <YOUR_METRICS_API_KEY>

Expand All @@ -102,12 +93,6 @@ callora-backend/

## Environment

<<<<<<< HEAD
- `PORT` — HTTP port (default: 3000). Optional for local dev.

This repo is part of [Callora](https://github.com/your-org/callora). Frontend: `callora-frontend`. Contracts: `callora-contracts`.
=======
- `PORT` - HTTP port (default: 3000). Optional for local dev.

This repo is part of [Callora](https://github.com/your-org/callora). Frontend: `callora-frontend`. Contracts: `callora-contracts`.
>>>>>>> main
40 changes: 27 additions & 13 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import globals from 'globals';
import tsParser from '@typescript-eslint/parser';
import tsPlugin from '@typescript-eslint/eslint-plugin';

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
export default [
{
ignores: ['dist/**', 'node_modules/**']
},
{
files: ['**/*.ts'],
languageOptions: {
globals: {
...globals.node,
...globals.jest,
parser: tsParser,
parserOptions: {
sourceType: 'module'
},
globals: {
console: 'readonly',
process: 'readonly',
module: 'readonly',
require: 'readonly',
describe: 'readonly',
it: 'readonly',
expect: 'readonly',
jest: 'readonly'
}
},
},
{
ignores: ['dist/', 'node_modules/'],
plugins: {
'@typescript-eslint': tsPlugin
},
rules: {
...tsPlugin.configs.recommended.rules
}
}
);
];
10 changes: 10 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest/presets/default-esm',
testEnvironment: 'node',
testMatch: ['**/?(*.)+(spec|test).ts'],
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1'
}
};
Loading