Skip to content
Merged
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
93 changes: 64 additions & 29 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,28 @@
}
}
},
"500": {
"description": "Internal server error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
},
"responses": {
"200": {
...
"description": "Success"
},
"400": {
...
"description": "Bad Request"
},
"401": {
...
"description": "Unauthorized"
},
"402": {
...
"description": "Payment Required"
},
"409": {
"description": "Idempotency conflict",
Expand All @@ -143,16 +153,6 @@
}
},
"500": {}
},
"500": {
"description": "Internal server error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
}
}
}
Expand Down Expand Up @@ -358,14 +358,35 @@
"items": {
"type": "object",
"properties": {
"apiId": { "type": "string" },
"day": { "type": "string", "example": "2026-03-21" },
"type": { "type": "string", "enum": ["spike", "drop"] },
"calls": { "type": "integer" },
"revenue": { "type": "string" },
"baselineMean": { "type": "number" },
"stdDev": { "type": "number" },
"zScore": { "type": "number" }
"apiId": {
"type": "string"
},
"day": {
"type": "string",
"example": "2026-03-21"
},
"type": {
"type": "string",
"enum": [
"spike",
"drop"
]
},
"calls": {
"type": "integer"
},
"revenue": {
"type": "string"
},
"baselineMean": {
"type": "number"
},
"stdDev": {
"type": "number"
},
"zScore": {
"type": "number"
}
}
}
},
Expand All @@ -375,14 +396,28 @@
"window": {
"type": "object",
"properties": {
"from": { "type": "string", "format": "date-time" },
"to": { "type": "string", "format": "date-time" }
"from": {
"type": "string",
"format": "date-time"
},
"to": {
"type": "string",
"format": "date-time"
}
}
},
"threshold": { "type": "number" },
"minDataPoints": { "type": "integer" },
"seriesAnalyzed": { "type": "integer" },
"anomalyCount": { "type": "integer" }
"threshold": {
"type": "number"
},
"minDataPoints": {
"type": "integer"
},
"seriesAnalyzed": {
"type": "integer"
},
"anomalyCount": {
"type": "integer"
}
}
}
}
Expand Down Expand Up @@ -1812,4 +1847,4 @@
}
}
}
}
}
53 changes: 50 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/errors/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,10 @@ export const ErrorCode = {
UNSUPPORTED_MEDIA_TYPE: "UNSUPPORTED_MEDIA_TYPE",

/** Request is syntactically correct but semantically invalid */
UNPROCESSABLE_ENTITY: "UNPROCESSABLE_ENTITY"
UNPROCESSABLE_ENTITY: "UNPROCESSABLE_ENTITY",

/** Usage aggregate not found for the given developer */
USAGE_AGGREGATE_NOT_FOUND: "USAGE_AGGREGATE_NOT_FOUND"

} as const;

Expand Down
4 changes: 2 additions & 2 deletions src/repositories/apiRepository.drizzle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class DrizzleApiRepository implements ApiRepository {

// better-sqlite3's RunResult exposes the affected row count on `changes`.
// The database FK with ON DELETE CASCADE will automatically clean up endpoints.
return deleted.changes > 0;
return result.changes > 0;
}

async listByDeveloper(
Expand Down Expand Up @@ -232,7 +232,7 @@ export class DrizzleApiRepository implements ApiRepository {
.from(schema.apiEndpoints)
.where(eq(schema.apiEndpoints.api_id, apiId));

return rows.map((r) => ({
return rows.map((r: ApiEndpointInfo) => ({
path: r.path,
method: r.method,
price_per_call_usdc: r.price_per_call_usdc,
Expand Down
11 changes: 6 additions & 5 deletions src/routes/admin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Router } from 'express';
import { Router, type Response } from 'express';
import { adminAuth } from '../middleware/adminAuth.js';
import { createAdminIpAllowlist } from '../middleware/ipAllowlist.js';
import { findUsers } from '../repositories/userRepository.js';
Expand All @@ -13,7 +13,7 @@ import {
approveQuotaRequest,
rejectQuotaRequest,
} from '../services/quotaService.js';
import webhookKeysRouter from './admin/webhookKeys.js';
import { createAdminWebhooksRouter } from './admin/webhooks.js';
import { createAdminApisRouter } from './admin/apis.js';

const TRUST_PROXY = process.env.TRUST_PROXY_HEADERS === 'true';
Expand Down Expand Up @@ -60,7 +60,7 @@ router.get('/users', async (req, res, next) => {
}
});

router.get('/usage/:developerId', async (req, res, next) => {
router.get('/usage/:developerId', async (req, res: Response, next) => {
try {
const snapshot = await usageStore.getDeveloperUsageSnapshot(req.params.developerId);
if (!snapshot) {
Expand Down Expand Up @@ -197,11 +197,12 @@ router.post('/quota/requests/:id/reject', async (req, res, next) => {
});

// ---------------------------------------------------------------------------
// Webhook signing-key rotation
// Webhook signing-key rotation + delivery monitoring
// Mounts: POST /api/admin/webhooks/rotate-key
// GET /api/admin/webhooks/grace-window
// GET /api/admin/webhooks/monitor
// ---------------------------------------------------------------------------
router.use('/webhooks', webhookKeysRouter);
router.use('/webhooks', createAdminWebhooksRouter());

// ---------------------------------------------------------------------------
// API soft-delete and restore
Expand Down
Loading