cursedbelt-server 4.69.0 โ†’ 4.71.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}, byte-identical to `cursedbelt`'s โ€” the spec compares them) runs again
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
- /** ๐Ÿ”ด Must equal `cursedbelt/react/notifications`' `REDACTED_QUERY_KEY` โ€” `d1.spec.ts` compares them. */
32
- export declare const REDACTED_QUERY_KEY: RegExp;
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.
@@ -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
- /** ๐Ÿ”ด Must equal `cursedbelt/react/notifications`' `REDACTED_QUERY_KEY` โ€” `d1.spec.ts` compares them. */
9
- export const REDACTED_QUERY_KEY = /token|sig|signature|key|secret|password|code|exp/i;
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.
@@ -30,6 +30,11 @@ export interface TubeApiVideo {
30
30
  channelTitle: string;
31
31
  thumbnail: string;
32
32
  url: string;
33
+ /**
34
+ * When the VIDEO went up (`contentDetails.videoPublishedAt`), epoch ms โ€” not `snippet.publishedAt`,
35
+ * which is when it was added to the playlist. `null` when the reply carries none (a private video).
36
+ */
37
+ publishedAt: number | null;
33
38
  }
34
39
  export interface TubeApiPlaylist {
35
40
  id: string;
@@ -3,6 +3,13 @@ const API_BASE = "https://www.googleapis.com/youtube/v3";
3
3
  export const youtubeThumbnailUrl = (videoId) => videoId ? `https://i.ytimg.com/vi/${videoId}/mqdefault.jpg` : "";
4
4
  /** Read-only, and nothing else. See the header. */
5
5
  export const YOUTUBE_READONLY_SCOPE = "https://www.googleapis.com/auth/youtube.readonly";
6
+ /** An RFC 3339 stamp as epoch ms, or `null` for anything absent or unparseable. */
7
+ const epochMs = (stamp) => {
8
+ if (typeof stamp !== "string" || !stamp)
9
+ return null;
10
+ const ms = Date.parse(stamp);
11
+ return Number.isFinite(ms) ? ms : null;
12
+ };
6
13
  /**
7
14
  * `medium` first, deliberately. `default` is 120ร—90 and looks like a thumbnail from 2009 on
8
15
  * a retina phone; `maxres` does not exist for most videos, so preferring it would leave
@@ -135,6 +142,7 @@ export function createYouTubeApi(fetchImpl = fetch) {
135
142
  channelTitle: String(snippet.videoOwnerChannelTitle ?? ""),
136
143
  thumbnail: pickThumb(snippet.thumbnails) || youtubeThumbnailUrl(videoId),
137
144
  url: watchUrl(videoId),
145
+ publishedAt: epochMs(details.videoPublishedAt),
138
146
  };
139
147
  })
140
148
  .filter((v) => v.videoId && !UNPLAYABLE_TITLES.has(v.title)),
@@ -188,6 +196,8 @@ export function createYouTubeApi(fetchImpl = fetch) {
188
196
  channelTitle: String(snippet.channelTitle ?? ""),
189
197
  thumbnail: pickThumb(snippet.thumbnails) || youtubeThumbnailUrl(videoId),
190
198
  url: watchUrl(videoId),
199
+ // On a `videos` row the snippet IS the video's, so its publishedAt is the upload.
200
+ publishedAt: epochMs(snippet.publishedAt),
191
201
  };
192
202
  })
193
203
  .filter((v) => v.videoId),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cursedbelt-server",
3
- "version": "4.69.0",
3
+ "version": "4.71.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.1.1",
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.140.0",
444
+ "cursedbelt": "^6.1.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 { readFileSync } from 'node:fs';
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 {
@@ -137,18 +136,9 @@ describe('issueStem groups what varies between occurrences', () => {
137
136
  });
138
137
  });
139
138
 
140
- describe('๐Ÿ”ด the redaction is the pageโ€™s own rule, not a second copy that drifts', () => {
141
- test('equals cursedbeltโ€™s REDACTED_QUERY_KEY once the installed cursedbelt exports it', async () => {
142
- const require = createRequire(import.meta.url);
143
- const manifest = require.resolve('cursedbelt/package.json');
144
- const version = (JSON.parse(readFileSync(manifest, 'utf8')) as { version: string }).version;
145
- const belt = (await import('cursedbelt/react/notifications')) as { REDACTED_QUERY_KEY?: RegExp };
146
- const [major = 0, minor = 0] = version.split('.').map(Number);
147
- // 5.140.0 is the first cursedbelt with the export; the publish bumps this devDependency past it.
148
- if (major > 5 || (major === 5 && minor >= 140)) expect(belt.REDACTED_QUERY_KEY).toBeDefined();
149
- if (belt.REDACTED_QUERY_KEY) {
150
- expect(REDACTED_QUERY_KEY.source).toBe(belt.REDACTED_QUERY_KEY.source);
151
- expect(REDACTED_QUERY_KEY.flags).toBe(belt.REDACTED_QUERY_KEY.flags);
152
- }
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);
153
143
  });
154
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}, byte-identical to `cursedbelt`'s โ€” the spec compares them) runs again
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
- /** ๐Ÿ”ด Must equal `cursedbelt/react/notifications`' `REDACTED_QUERY_KEY` โ€” `d1.spec.ts` compares them. */
38
- export const REDACTED_QUERY_KEY = /token|sig|signature|key|secret|password|code|exp/i;
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,
@@ -21,9 +21,9 @@ const fakeGoogle = (handler: Handler) => {
21
21
  return { seen, api: createYouTubeApi(fetchImpl) };
22
22
  };
23
23
 
24
- const item = (videoId: string, title = `Video ${videoId}`) => ({
25
- snippet: { title, videoOwnerChannelTitle: "Chan", thumbnails: {} },
26
- contentDetails: { videoId },
24
+ const item = (videoId: string, title = `Video ${videoId}`, videoPublishedAt?: string) => ({
25
+ snippet: { title, videoOwnerChannelTitle: "Chan", thumbnails: {}, publishedAt: "2030-01-01T00:00:00Z" },
26
+ contentDetails: { videoId, ...(videoPublishedAt ? { videoPublishedAt } : {}) },
27
27
  });
28
28
 
29
29
  describe("createYouTubeApi", () => {
@@ -43,6 +43,7 @@ describe("createYouTubeApi", () => {
43
43
  channelTitle: "Chan",
44
44
  thumbnail: youtubeThumbnailUrl("a1"),
45
45
  url: "https://www.youtube.com/watch?v=a1",
46
+ publishedAt: null,
46
47
  },
47
48
  ],
48
49
  },
@@ -51,6 +52,29 @@ describe("createYouTubeApi", () => {
51
52
  expect(seen[0]?.searchParams.get("playlistId")).toBe("PL1");
52
53
  });
53
54
 
55
+ test("a video's date is when IT went up (contentDetails), never when it joined the playlist (snippet)", async () => {
56
+ const { api } = fakeGoogle(() => ({
57
+ body: { items: [item("d1", "Dated", "2019-06-01T12:00:00Z"), item("d2", "Undated"), item("d3", "Garbled", "soon")] },
58
+ }));
59
+ const page = await api.playlistItems("tok", "PL1");
60
+ expect(page.status === "ok" ? page.value.items.map((v) => v.publishedAt) : []).toEqual([
61
+ Date.UTC(2019, 5, 1, 12),
62
+ null,
63
+ null,
64
+ ]);
65
+ });
66
+
67
+ test("a liked video's date is its own snippet's โ€” on a videos row the snippet is the video", async () => {
68
+ const { api, seen } = fakeGoogle(() => ({
69
+ body: { items: [{ id: "L1", snippet: { title: "Liked", channelTitle: "C", publishedAt: "2021-02-03T00:00:00Z" } }] },
70
+ }));
71
+ const page = await api.liked("tok");
72
+ expect(page.status === "ok" ? page.value.items.map((v) => [v.videoId, v.publishedAt]) : []).toEqual([
73
+ ["L1", Date.UTC(2021, 1, 3)],
74
+ ]);
75
+ expect(seen[0]?.searchParams.get("myRating")).toBe("like");
76
+ });
77
+
54
78
  test("๐Ÿ”ด every page is walked, and a list stopped at the cap SAYS so", async () => {
55
79
  const { api } = fakeGoogle((url) => {
56
80
  const at = Number(url.searchParams.get("pageToken") ?? "0");
@@ -36,8 +36,20 @@ export interface TubeApiVideo {
36
36
  channelTitle: string;
37
37
  thumbnail: string;
38
38
  url: string;
39
+ /**
40
+ * When the VIDEO went up (`contentDetails.videoPublishedAt`), epoch ms โ€” not `snippet.publishedAt`,
41
+ * which is when it was added to the playlist. `null` when the reply carries none (a private video).
42
+ */
43
+ publishedAt: number | null;
39
44
  }
40
45
 
46
+ /** An RFC 3339 stamp as epoch ms, or `null` for anything absent or unparseable. */
47
+ const epochMs = (stamp: unknown): number | null => {
48
+ if (typeof stamp !== "string" || !stamp) return null;
49
+ const ms = Date.parse(stamp);
50
+ return Number.isFinite(ms) ? ms : null;
51
+ };
52
+
41
53
  export interface TubeApiPlaylist {
42
54
  id: string;
43
55
  title: string;
@@ -224,6 +236,7 @@ export function createYouTubeApi(fetchImpl: FetchLike = fetch) {
224
236
  channelTitle: String(snippet.videoOwnerChannelTitle ?? ""),
225
237
  thumbnail: pickThumb(snippet.thumbnails as Thumbs) || youtubeThumbnailUrl(videoId),
226
238
  url: watchUrl(videoId),
239
+ publishedAt: epochMs(details.videoPublishedAt),
227
240
  };
228
241
  })
229
242
  .filter((v) => v.videoId && !UNPLAYABLE_TITLES.has(v.title)),
@@ -289,6 +302,8 @@ export function createYouTubeApi(fetchImpl: FetchLike = fetch) {
289
302
  channelTitle: String(snippet.channelTitle ?? ""),
290
303
  thumbnail: pickThumb(snippet.thumbnails as Thumbs) || youtubeThumbnailUrl(videoId),
291
304
  url: watchUrl(videoId),
305
+ // On a `videos` row the snippet IS the video's, so its publishedAt is the upload.
306
+ publishedAt: epochMs(snippet.publishedAt),
292
307
  };
293
308
  })
294
309
  .filter((v) => v.videoId),