cursedbelt-server 4.68.0 β 4.70.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* ```
|
|
15
15
|
*
|
|
16
16
|
* π΄ The door trusts nothing it is sent: every string is capped, the app's own query-key redaction
|
|
17
|
-
* ({@link REDACTED_QUERY_KEY},
|
|
17
|
+
* ({@link REDACTED_QUERY_KEY}, cursedbelt-core's, the copy `cursedbelt`'s reporter imports too) runs again
|
|
18
18
|
* here, and the account is the session's, never the body's. It may be mounted outside the session
|
|
19
19
|
* gate (a page that cannot sign in is exactly the page with a problem), so two bounds hold whoever
|
|
20
20
|
* calls it: at most {@link ClientIssuesOptions.maxRowsPerHour} rows an hour per app, and rows older
|
|
@@ -24,14 +24,13 @@
|
|
|
24
24
|
*/
|
|
25
25
|
import type { Context } from "hono";
|
|
26
26
|
import { Hono } from "hono";
|
|
27
|
+
import { REDACTED_QUERY_KEY, redactQueryValues } from "cursedbelt-core/redact";
|
|
27
28
|
import type { D1LikeDatabase } from "../d1/types.js";
|
|
28
29
|
export declare const CLIENT_ISSUES_PATH = "/api/client-issues";
|
|
29
30
|
/** The table and its index, as one-line DDL for the app's schema. */
|
|
30
31
|
export declare const CLIENT_ISSUES_DDL: readonly string[];
|
|
31
|
-
/**
|
|
32
|
-
export
|
|
33
|
-
/** Every `key=value` whose key is a {@link REDACTED_QUERY_KEY}, its value replaced by `β¦`. */
|
|
34
|
-
export declare function redactQueryValues(text: string): string;
|
|
32
|
+
/** The redaction is cursedbelt-core's ONE copy (forge task 4887) β the browser's reporter imports the same. */
|
|
33
|
+
export { REDACTED_QUERY_KEY, redactQueryValues };
|
|
35
34
|
/**
|
|
36
35
|
* The words of a title with what varies between occurrences taken out β numbers, ids, hosts,
|
|
37
36
|
* quoted names β so "Video 42 is stuck" and "Video 97 is stuck" are one group for autopilot.
|
|
@@ -72,6 +71,11 @@ export interface ClientIssuesOptions {
|
|
|
72
71
|
db: D1LikeDatabase | ((c: Context) => D1LikeDatabase);
|
|
73
72
|
/** The session's account, when there is one. Never read from the body. */
|
|
74
73
|
resolveUser?: (c: Context) => string | null;
|
|
74
|
+
/**
|
|
75
|
+
* The build the server runs (a commit), stamped on every row whose body named none β a page
|
|
76
|
+
* rarely knows its own build, and the Worker always does (forge task 4865).
|
|
77
|
+
*/
|
|
78
|
+
build?: string | ((c: Context) => string | null | undefined);
|
|
75
79
|
/** Rows older than this are deleted on each write. Default 14 days. */
|
|
76
80
|
retentionMs?: number;
|
|
77
81
|
/** Reports past this many in the last hour are refused (429). Default 600. */
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { Hono } from "hono";
|
|
2
|
+
import { REDACTED_QUERY_KEY, redactQueryValues } from "cursedbelt-core/redact";
|
|
2
3
|
export const CLIENT_ISSUES_PATH = "/api/client-issues";
|
|
3
4
|
/** The table and its index, as one-line DDL for the app's schema. */
|
|
4
5
|
export const CLIENT_ISSUES_DDL = [
|
|
5
6
|
"CREATE TABLE IF NOT EXISTS client_issues ( id INTEGER PRIMARY KEY AUTOINCREMENT, at INTEGER NOT NULL, change TEXT NOT NULL, issue_id TEXT NOT NULL, area TEXT NOT NULL, stem TEXT NOT NULL, tone TEXT NOT NULL, outlook TEXT NOT NULL, title TEXT NOT NULL, occurrences INTEGER NOT NULL DEFAULT 1, started_at INTEGER NOT NULL, ended_at INTEGER, resolution TEXT NOT NULL DEFAULT '', page TEXT NOT NULL DEFAULT '', build TEXT NOT NULL DEFAULT '', user_agent TEXT NOT NULL DEFAULT '', user_key TEXT NOT NULL DEFAULT '', facts TEXT NOT NULL DEFAULT '[]', report TEXT NOT NULL DEFAULT '' )",
|
|
6
7
|
"CREATE INDEX IF NOT EXISTS idx_client_issues_at ON client_issues (at)",
|
|
7
8
|
];
|
|
8
|
-
/**
|
|
9
|
-
export
|
|
10
|
-
/** Every `key=value` whose key is a {@link REDACTED_QUERY_KEY}, its value replaced by `β¦`. */
|
|
11
|
-
export function redactQueryValues(text) {
|
|
12
|
-
return text.replace(/([?&;]([^=&#\s]+)=)([^&#;\s]*)/g, (whole, head, key) => REDACTED_QUERY_KEY.test(key) ? `${head}β¦` : whole);
|
|
13
|
-
}
|
|
9
|
+
/** The redaction is cursedbelt-core's ONE copy (forge task 4887) β the browser's reporter imports the same. */
|
|
10
|
+
export { REDACTED_QUERY_KEY, redactQueryValues };
|
|
14
11
|
/**
|
|
15
12
|
* The words of a title with what varies between occurrences taken out β numbers, ids, hosts,
|
|
16
13
|
* quoted names β so "Video 42 is stuck" and "Video 97 is stuck" are one group for autopilot.
|
|
@@ -134,6 +131,10 @@ export function clientIssuesHandler(options) {
|
|
|
134
131
|
});
|
|
135
132
|
if ("error" in door)
|
|
136
133
|
return c.json({ error: door.error }, 400);
|
|
134
|
+
if (!door.row.build && options.build) {
|
|
135
|
+
const build = typeof options.build === "function" ? options.build(c) : options.build;
|
|
136
|
+
door.row.build = cap(build, 80);
|
|
137
|
+
}
|
|
137
138
|
const db = typeof options.db === "function" ? options.db(c) : options.db;
|
|
138
139
|
const outcome = await recordClientIssueD1(db, door.row, bounds);
|
|
139
140
|
if (outcome === "capped")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cursedbelt-server",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.70.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "The app-facing Bun/Hono server tier of the cursedbelt split β storage, sharing, activity, guard, sync. React-free; cursedbelt-core below it.",
|
|
@@ -400,7 +400,7 @@
|
|
|
400
400
|
},
|
|
401
401
|
"dependencies": {
|
|
402
402
|
"argon2id": "1.0.1",
|
|
403
|
-
"cursedbelt-core": "^2.
|
|
403
|
+
"cursedbelt-core": "^2.18.0",
|
|
404
404
|
"cursedops": ">=0.8.1 <1.0.0",
|
|
405
405
|
"cwip": "^4.6.0",
|
|
406
406
|
"jose": "^6.2.3"
|
|
@@ -441,7 +441,7 @@
|
|
|
441
441
|
"@node-rs/argon2": "^2.0.2",
|
|
442
442
|
"@types/bun": "^1.3.14",
|
|
443
443
|
"@types/node": "^24",
|
|
444
|
-
"cursedbelt": "^5.
|
|
444
|
+
"cursedbelt": "^5.141.0",
|
|
445
445
|
"hono": "4.12.28",
|
|
446
446
|
"kysely": "^0.28.17",
|
|
447
447
|
"kysely-bun-sqlite": "^0.4.0",
|
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { Database } from 'bun:sqlite';
|
|
6
6
|
import { describe, expect, test } from 'bun:test';
|
|
7
|
-
import {
|
|
8
|
-
import { createRequire } from 'node:module';
|
|
7
|
+
import { REDACTED_QUERY_KEY as coreKey, redactQueryValues as coreRedact } from 'cursedbelt-core/redact';
|
|
9
8
|
import { Hono } from 'hono';
|
|
10
9
|
import { createLocalD1 } from '../d1/local.js';
|
|
11
10
|
import {
|
|
@@ -89,6 +88,21 @@ describe('clientIssuesHandler is the same door, for a literal route', () => {
|
|
|
89
88
|
});
|
|
90
89
|
});
|
|
91
90
|
|
|
91
|
+
describe('π΄ a row names the build that saw it (forge task 4865)', () => {
|
|
92
|
+
test('a body without a build gets the serverβs; a body with one keeps its own', async () => {
|
|
93
|
+
const { sqlite, db } = fresh();
|
|
94
|
+
const app = new Hono<{ Bindings: { COMMIT: string } }>().post(
|
|
95
|
+
'/api/client-issues',
|
|
96
|
+
clientIssuesHandler({ db, build: (c) => (c.env as { COMMIT: string }).COMMIT }),
|
|
97
|
+
);
|
|
98
|
+
const send = (body: unknown) =>
|
|
99
|
+
app.request('/api/client-issues', { method: 'POST', body: JSON.stringify(body) }, { COMMIT: '0123abcd' });
|
|
100
|
+
expect((await send(report({ build: '' }))).status).toBe(204);
|
|
101
|
+
expect((await send(report({ build: 'page999' }))).status).toBe(204);
|
|
102
|
+
expect(sqlite.query('SELECT build FROM client_issues ORDER BY id').all()).toEqual([{ build: '0123abcd' }, { build: 'page999' }]);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
92
106
|
describe('π΄ the door is bounded whoever calls it', () => {
|
|
93
107
|
test('past maxRowsPerHour it answers 429 and writes nothing more', async () => {
|
|
94
108
|
const { sqlite, db } = fresh();
|
|
@@ -122,18 +136,9 @@ describe('issueStem groups what varies between occurrences', () => {
|
|
|
122
136
|
});
|
|
123
137
|
});
|
|
124
138
|
|
|
125
|
-
describe('π΄ the redaction is
|
|
126
|
-
test('
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const version = (JSON.parse(readFileSync(manifest, 'utf8')) as { version: string }).version;
|
|
130
|
-
const belt = (await import('cursedbelt/react/notifications')) as { REDACTED_QUERY_KEY?: RegExp };
|
|
131
|
-
const [major = 0, minor = 0] = version.split('.').map(Number);
|
|
132
|
-
// 5.140.0 is the first cursedbelt with the export; the publish bumps this devDependency past it.
|
|
133
|
-
if (major > 5 || (major === 5 && minor >= 140)) expect(belt.REDACTED_QUERY_KEY).toBeDefined();
|
|
134
|
-
if (belt.REDACTED_QUERY_KEY) {
|
|
135
|
-
expect(REDACTED_QUERY_KEY.source).toBe(belt.REDACTED_QUERY_KEY.source);
|
|
136
|
-
expect(REDACTED_QUERY_KEY.flags).toBe(belt.REDACTED_QUERY_KEY.flags);
|
|
137
|
-
}
|
|
139
|
+
describe('π΄ the redaction is cursedbelt-coreβs one copy, not a second that drifts', () => {
|
|
140
|
+
test('the door redacts with the very object cursedbelt-core exports', () => {
|
|
141
|
+
expect(REDACTED_QUERY_KEY).toBe(coreKey);
|
|
142
|
+
expect(redactQueryValues).toBe(coreRedact);
|
|
138
143
|
});
|
|
139
144
|
});
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* ```
|
|
15
15
|
*
|
|
16
16
|
* π΄ The door trusts nothing it is sent: every string is capped, the app's own query-key redaction
|
|
17
|
-
* ({@link REDACTED_QUERY_KEY},
|
|
17
|
+
* ({@link REDACTED_QUERY_KEY}, cursedbelt-core's, the copy `cursedbelt`'s reporter imports too) runs again
|
|
18
18
|
* here, and the account is the session's, never the body's. It may be mounted outside the session
|
|
19
19
|
* gate (a page that cannot sign in is exactly the page with a problem), so two bounds hold whoever
|
|
20
20
|
* calls it: at most {@link ClientIssuesOptions.maxRowsPerHour} rows an hour per app, and rows older
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
*/
|
|
25
25
|
import type { Context } from "hono";
|
|
26
26
|
import { Hono } from "hono";
|
|
27
|
+
import { REDACTED_QUERY_KEY, redactQueryValues } from "cursedbelt-core/redact";
|
|
27
28
|
import type { D1LikeDatabase } from "../d1/types.js";
|
|
28
29
|
|
|
29
30
|
export const CLIENT_ISSUES_PATH = "/api/client-issues";
|
|
@@ -34,15 +35,8 @@ export const CLIENT_ISSUES_DDL: readonly string[] = [
|
|
|
34
35
|
"CREATE INDEX IF NOT EXISTS idx_client_issues_at ON client_issues (at)",
|
|
35
36
|
];
|
|
36
37
|
|
|
37
|
-
/**
|
|
38
|
-
export
|
|
39
|
-
|
|
40
|
-
/** Every `key=value` whose key is a {@link REDACTED_QUERY_KEY}, its value replaced by `β¦`. */
|
|
41
|
-
export function redactQueryValues(text: string): string {
|
|
42
|
-
return text.replace(/([?&;]([^=&#\s]+)=)([^&#;\s]*)/g, (whole, head: string, key: string) =>
|
|
43
|
-
REDACTED_QUERY_KEY.test(key) ? `${head}β¦` : whole,
|
|
44
|
-
);
|
|
45
|
-
}
|
|
38
|
+
/** The redaction is cursedbelt-core's ONE copy (forge task 4887) β the browser's reporter imports the same. */
|
|
39
|
+
export { REDACTED_QUERY_KEY, redactQueryValues };
|
|
46
40
|
|
|
47
41
|
/**
|
|
48
42
|
* The words of a title with what varies between occurrences taken out β numbers, ids, hosts,
|
|
@@ -155,6 +149,11 @@ export interface ClientIssuesOptions {
|
|
|
155
149
|
db: D1LikeDatabase | ((c: Context) => D1LikeDatabase);
|
|
156
150
|
/** The session's account, when there is one. Never read from the body. */
|
|
157
151
|
resolveUser?: (c: Context) => string | null;
|
|
152
|
+
/**
|
|
153
|
+
* The build the server runs (a commit), stamped on every row whose body named none β a page
|
|
154
|
+
* rarely knows its own build, and the Worker always does (forge task 4865).
|
|
155
|
+
*/
|
|
156
|
+
build?: string | ((c: Context) => string | null | undefined);
|
|
158
157
|
/** Rows older than this are deleted on each write. Default 14 days. */
|
|
159
158
|
retentionMs?: number;
|
|
160
159
|
/** Reports past this many in the last hour are refused (429). Default 600. */
|
|
@@ -206,6 +205,10 @@ export function clientIssuesHandler(options: ClientIssuesOptions): (c: Context)
|
|
|
206
205
|
userKey: options.resolveUser?.(c) ?? null,
|
|
207
206
|
});
|
|
208
207
|
if ("error" in door) return c.json({ error: door.error }, 400);
|
|
208
|
+
if (!door.row.build && options.build) {
|
|
209
|
+
const build = typeof options.build === "function" ? options.build(c) : options.build;
|
|
210
|
+
door.row.build = cap(build, 80);
|
|
211
|
+
}
|
|
209
212
|
const db = typeof options.db === "function" ? options.db(c) : options.db;
|
|
210
213
|
const outcome = await recordClientIssueD1(db, door.row, bounds);
|
|
211
214
|
if (outcome === "capped") return c.json({ error: "too many reports this hour" }, 429);
|