fix(api): the API failed to start after moving the proposal limit to Redis

ProposalLimiter, in the presenters, asked for the RateLimitStore port,
which only the application layer sees, so Nest could not build it and
the container never became healthy. The count now lives in an
application service, ProposalQuota; the presenter only answers 429.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-13 21:01:38 +02:00
parent 3d8800e58c
commit 1383e15f3f
5 changed files with 50 additions and 12 deletions

View File

@@ -0,0 +1,22 @@
import { ProposalQuota } from './proposal-quota.service';
import { RateLimitStore } from './ports/rate-limit.store';
class MemoryStore extends RateLimitStore {
readonly counts = new Map<string, number>();
async hit(key: string): Promise<number> {
const count = (this.counts.get(key) ?? 0) + 1;
this.counts.set(key, count);
return count;
}
}
describe('ProposalQuota', () => {
it('lets five proposals through per address, then says no', async () => {
const quota = new ProposalQuota(new MemoryStore());
const answers = [];
for (let i = 0; i < 6; i++) answers.push(await quota.take('1.2.3.4'));
expect(answers).toEqual([true, true, true, true, true, false]);
expect(await quota.take('5.6.7.8')).toBe(true);
});
});