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
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ jobs:
- name: Lint OpenAPI spec
run: npx @redocly/cli lint openapi.yaml

- name: Lint source (ESLint)
run: npx eslint .
continue-on-error: true

- name: Run tests
run: npm test

Expand Down
16 changes: 16 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

// Minimal ESLint flat config (Issue #231) — a starting point for consistent
// code style, not a full ruleset. Run with: npx eslint .
module.exports = [
{
files: ['src/**/*.js'],
languageOptions: {
ecmaVersion: 2022,
sourceType: 'commonjs',
},
rules: {
'no-unused-vars': 'warn',
},
},
];
3 changes: 2 additions & 1 deletion src/middleware/errorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ function errorHandler(err, req, res, _next) {
message = 'Request body is too large';
} else if (err.status || err.statusCode) {
status = err.status || err.statusCode;
code = 'FORBIDDEN';
const STATUS_CODES = { 400: 'VALIDATION_ERROR', 401: 'UNAUTHORIZED', 403: 'FORBIDDEN', 404: 'NOT_FOUND', 429: 'RATE_LIMITED' };
code = STATUS_CODES[status] || 'INTERNAL_ERROR';
message = err.message || 'Request rejected';
}

Expand Down
6 changes: 3 additions & 3 deletions src/services/webhookDispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ function withDeliveryTrace(traceId, fn) {
return requestContext.run({ requestId: traceId }, fn);
}

async function postOnce(url, headers, body) {
async function postOnce(url, headers, body, timeoutMs) {
return axios.post(url, body, {
headers,
timeout: config.webhooks.timeoutMs,
timeout: timeoutMs ?? config.webhooks.timeoutMs,
transformRequest: [(data) => data],
validateStatus: () => true,
});
Expand Down Expand Up @@ -136,7 +136,7 @@ async function attempt(deliveryId) {
let networkError = null;

try {
const res = await postOnce(webhook.url, headers, body);
const res = await postOnce(webhook.url, headers, body, webhook.timeoutMs);
responseStatus = res.status;
} catch (err) {
networkError = err.message || 'network error';
Expand Down
6 changes: 5 additions & 1 deletion src/validation/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const { z } = require('zod');
const webhookEvents = require('../services/webhookEvents');
const config = require('../config');

const stellarPublicKeySchema = z
.string()
Expand Down Expand Up @@ -99,7 +100,10 @@ const keyCreateBodySchema = z.object({
});

const alertCreateBodySchema = z.object({
asset: assetCodeSchema,
asset: assetCodeSchema.refine(
(code) => config.watchedAssets.length === 0 || config.watchedAssets.includes(code),
{ message: 'Asset code is not in the list of watched Stellar assets' },
),
type: z.enum(['above', 'below', 'change_pct']),
threshold_usd: z.number().positive(),
webhook_url: httpUrlSchema,
Expand Down