cursedbelt-server 4.68.0 → 4.69.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.
@@ -72,6 +72,11 @@ export interface ClientIssuesOptions {
72
72
  db: D1LikeDatabase | ((c: Context) => D1LikeDatabase);
73
73
  /** The session's account, when there is one. Never read from the body. */
74
74
  resolveUser?: (c: Context) => string | null;
75
+ /**
76
+ * The build the server runs (a commit), stamped on every row whose body named none — a page
77
+ * rarely knows its own build, and the Worker always does (forge task 4865).
78
+ */
79
+ build?: string | ((c: Context) => string | null | undefined);
75
80
  /** Rows older than this are deleted on each write. Default 14 days. */
76
81
  retentionMs?: number;
77
82
  /** Reports past this many in the last hour are refused (429). Default 600. */
@@ -134,6 +134,10 @@ export function clientIssuesHandler(options) {
134
134
  });
135
135
  if ("error" in door)
136
136
  return c.json({ error: door.error }, 400);
137
+ if (!door.row.build && options.build) {
138
+ const build = typeof options.build === "function" ? options.build(c) : options.build;
139
+ door.row.build = cap(build, 80);
140
+ }
137
141
  const db = typeof options.db === "function" ? options.db(c) : options.db;
138
142
  const outcome = await recordClientIssueD1(db, door.row, bounds);
139
143
  if (outcome === "capped")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cursedbelt-server",
3
- "version": "4.68.0",
3
+ "version": "4.69.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.",
@@ -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.138.0",
444
+ "cursedbelt": "^5.140.0",
445
445
  "hono": "4.12.28",
446
446
  "kysely": "^0.28.17",
447
447
  "kysely-bun-sqlite": "^0.4.0",
@@ -89,6 +89,21 @@ describe('clientIssuesHandler is the same door, for a literal route', () => {
89
89
  });
90
90
  });
91
91
 
92
+ describe('🔴 a row names the build that saw it (forge task 4865)', () => {
93
+ test('a body without a build gets the server’s; a body with one keeps its own', async () => {
94
+ const { sqlite, db } = fresh();
95
+ const app = new Hono<{ Bindings: { COMMIT: string } }>().post(
96
+ '/api/client-issues',
97
+ clientIssuesHandler({ db, build: (c) => (c.env as { COMMIT: string }).COMMIT }),
98
+ );
99
+ const send = (body: unknown) =>
100
+ app.request('/api/client-issues', { method: 'POST', body: JSON.stringify(body) }, { COMMIT: '0123abcd' });
101
+ expect((await send(report({ build: '' }))).status).toBe(204);
102
+ expect((await send(report({ build: 'page999' }))).status).toBe(204);
103
+ expect(sqlite.query('SELECT build FROM client_issues ORDER BY id').all()).toEqual([{ build: '0123abcd' }, { build: 'page999' }]);
104
+ });
105
+ });
106
+
92
107
  describe('🔴 the door is bounded whoever calls it', () => {
93
108
  test('past maxRowsPerHour it answers 429 and writes nothing more', async () => {
94
109
  const { sqlite, db } = fresh();
@@ -155,6 +155,11 @@ export interface ClientIssuesOptions {
155
155
  db: D1LikeDatabase | ((c: Context) => D1LikeDatabase);
156
156
  /** The session's account, when there is one. Never read from the body. */
157
157
  resolveUser?: (c: Context) => string | null;
158
+ /**
159
+ * The build the server runs (a commit), stamped on every row whose body named none — a page
160
+ * rarely knows its own build, and the Worker always does (forge task 4865).
161
+ */
162
+ build?: string | ((c: Context) => string | null | undefined);
158
163
  /** Rows older than this are deleted on each write. Default 14 days. */
159
164
  retentionMs?: number;
160
165
  /** Reports past this many in the last hour are refused (429). Default 600. */
@@ -206,6 +211,10 @@ export function clientIssuesHandler(options: ClientIssuesOptions): (c: Context)
206
211
  userKey: options.resolveUser?.(c) ?? null,
207
212
  });
208
213
  if ("error" in door) return c.json({ error: door.error }, 400);
214
+ if (!door.row.build && options.build) {
215
+ const build = typeof options.build === "function" ? options.build(c) : options.build;
216
+ door.row.build = cap(build, 80);
217
+ }
209
218
  const db = typeof options.db === "function" ? options.db(c) : options.db;
210
219
  const outcome = await recordClientIssueD1(db, door.row, bounds);
211
220
  if (outcome === "capped") return c.json({ error: "too many reports this hour" }, 429);