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: 2 additions & 2 deletions apps/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rssamplifier/web",
"version": "0.2.2",
"version": "0.2.3",
"private": true,
"type": "module",
"scripts": {
Expand All @@ -11,7 +11,7 @@
},
"dependencies": {
"@logicsrc/openaccess": "^0.3.1",
"@profullstack/contact-form": "0.3.0",
"@profullstack/contact-form": "0.3.2",
"@profullstack/footer": "latest",
"@profullstack/leaderboard": "^0.3.1",
"@profullstack/notifications": "^0.1.4",
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/lib/salesContact.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export function makeSalesContact(deps = {}) {
name: 'use_case',
type: 'textarea',
label: 'What do you want the corpus for?',
errorLabel: 'Your use case',
placeholder:
'What do you want the corpus for?\n\nWhich streams you need, roughly what scale, how often you would pull, and what it is being used to build.',
rows: 5,
Expand All @@ -121,7 +122,8 @@ export function makeSalesContact(deps = {}) {
verify: async (_body, req) => {
const since = new Date(Date.now() - WINDOW_MS).toISOString();
const recent = await store.enquiryCountFrom(client(), ipHashOf(ipOf(req)), since);
return recent >= MAX_PER_WINDOW ? TOO_MANY : true;
// Answered as a rate limit (429, ?error=limited), the same as the guard's own.
return recent >= MAX_PER_WINDOW ? { kind: 'limited', error: TOO_MANY } : true;
},
persist: async (s, verdict) => {
const v = s.values ?? {};
Expand Down
22 changes: 20 additions & 2 deletions apps/web/test/sales-contact.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,36 @@ test('a use case under ten characters is refused', async () => {
assert.equal(res.status, 400);
assert.deepEqual(await res.json(), {
ok: false,
error: 'What do you want the corpus for? is too short (10 characters at least)',
error: 'Your use case is too short (10 characters at least)',
});
assert.equal(rows.length, 0);
});

test('the per-address limit kept in the database still applies', async () => {
const { form, rows } = harness({ recent: MAX_PER_WINDOW });
const res = await form.POST(json({ ...answers, fg_token: await token() }));
assert.equal(res.status, 429);
assert.equal((await res.json()).error, TOO_MANY);
assert.equal(rows.length, 0);
});

test('a plain form post over the database limit comes back as ?error=limited with the hour message', async () => {
const { form, rows } = harness({ recent: MAX_PER_WINDOW });
const body = new URLSearchParams({ ...answers, fg_token: await token() });
const res = await form.POST(
new Request('http://localhost/api/sales/contact', {
method: 'POST',
headers: { 'content-type': 'application/x-www-form-urlencoded', 'x-forwarded-for': '203.0.113.10' },
body,
}),
);
assert.equal(res.status, 303);
const location = new URL(res.headers.get('location'), 'http://localhost');
assert.equal(location.searchParams.get('error'), 'limited');
assert.equal(form.errorMessage(location.searchParams), TOO_MANY);
assert.equal(rows.length, 0);
});

test('a plain form post is sent back to the form, with a message the page will show', async () => {
const { form } = harness();
const body = new URLSearchParams({ ...answers, use_case: 'x', fg_token: await token() });
Expand All @@ -129,7 +147,7 @@ test('a plain form post is sent back to the form, with a message the page will s
assert.equal(location.searchParams.get('field'), 'use_case');
assert.equal(
form.errorMessage(location.searchParams),
'What do you want the corpus for? is too short (10 characters at least)',
'Your use case is too short (10 characters at least)',
);
});

Expand Down
6 changes: 3 additions & 3 deletions bun.lock

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rssamplifier.com",
"version": "0.2.2",
"version": "0.2.3",
"private": true,
"type": "module",
"description": "Agent-first public RSS directory. Submit a URL, a list or an OPML file; every blog gets its own page.",
Expand Down
Loading