@pleasenobugs/server 0.0.0-stage → 0.1.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.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -2
  3. package/dist/app.d.ts +27 -0
  4. package/dist/app.d.ts.map +1 -0
  5. package/dist/app.js +43 -0
  6. package/dist/app.js.map +1 -0
  7. package/dist/auth.d.ts +37 -0
  8. package/dist/auth.d.ts.map +1 -0
  9. package/dist/auth.js +108 -0
  10. package/dist/auth.js.map +1 -0
  11. package/dist/board.d.ts +23 -0
  12. package/dist/board.d.ts.map +1 -0
  13. package/dist/board.js +45 -0
  14. package/dist/board.js.map +1 -0
  15. package/dist/bootstrap.d.ts +27 -0
  16. package/dist/bootstrap.d.ts.map +1 -0
  17. package/dist/bootstrap.js +41 -0
  18. package/dist/bootstrap.js.map +1 -0
  19. package/dist/importer.d.ts +50 -0
  20. package/dist/importer.d.ts.map +1 -0
  21. package/dist/importer.js +85 -0
  22. package/dist/importer.js.map +1 -0
  23. package/dist/index.d.ts +12 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +10 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/limit.d.ts +14 -0
  28. package/dist/limit.d.ts.map +1 -0
  29. package/dist/limit.js +32 -0
  30. package/dist/limit.js.map +1 -0
  31. package/dist/main.d.ts +3 -0
  32. package/dist/main.d.ts.map +1 -0
  33. package/dist/main.js +171 -0
  34. package/dist/main.js.map +1 -0
  35. package/dist/memory-store.d.ts +59 -0
  36. package/dist/memory-store.d.ts.map +1 -0
  37. package/dist/memory-store.js +177 -0
  38. package/dist/memory-store.js.map +1 -0
  39. package/dist/projects.d.ts +64 -0
  40. package/dist/projects.d.ts.map +1 -0
  41. package/dist/projects.js +163 -0
  42. package/dist/projects.js.map +1 -0
  43. package/dist/router.d.ts +28 -0
  44. package/dist/router.d.ts.map +1 -0
  45. package/dist/router.js +391 -0
  46. package/dist/router.js.map +1 -0
  47. package/dist/sqlite-store.d.ts +61 -0
  48. package/dist/sqlite-store.d.ts.map +1 -0
  49. package/dist/sqlite-store.js +290 -0
  50. package/dist/sqlite-store.js.map +1 -0
  51. package/dist/store.d.ts +108 -0
  52. package/dist/store.d.ts.map +1 -0
  53. package/dist/store.js +2 -0
  54. package/dist/store.js.map +1 -0
  55. package/dist/telemetry.d.ts +83 -0
  56. package/dist/telemetry.d.ts.map +1 -0
  57. package/dist/telemetry.js +174 -0
  58. package/dist/telemetry.js.map +1 -0
  59. package/package.json +53 -4
@@ -0,0 +1,61 @@
1
+ import type { Answer, Project } from '@pleasenobugs/core';
2
+ import type { PostPatch, PostRow, PostWithVotes, ProjectStats, Store, TelemetryRow } from './store.js';
3
+ /**
4
+ * One SQLite file, which is what a self-hoster wants: no database server, a
5
+ * backup is a file copy.
6
+ *
7
+ * **Built on `node:sqlite`, which ships inside Node 22.13+.** That is the
8
+ * whole reason it was chosen over `better-sqlite3`: a native module has to be
9
+ * compiled on install, and on Windows or a slim container that is where people
10
+ * give up. Node still labels it experimental and prints one warning at start;
11
+ * the API it exposes has been stable since it landed.
12
+ *
13
+ * Its own entry point (`@pleasenobugs/server/sqlite`) so that importing the
14
+ * server for another store never loads it, and never prints that warning.
15
+ *
16
+ * Synchronous underneath, so every method finishes before anything else runs,
17
+ * which is what makes `vote()` and `createPost()` atomic without a transaction
18
+ * spanning an await.
19
+ *
20
+ * @example
21
+ * import { SqliteStore } from '@pleasenobugs/server/sqlite';
22
+ * const store = new SqliteStore('./pleasenobugs.db'); // or ':memory:'
23
+ */
24
+ export declare class SqliteStore implements Store {
25
+ private db;
26
+ constructor(path: string);
27
+ /** Close the file. Tests use it; a server normally runs until it is killed. */
28
+ close(): void;
29
+ private all;
30
+ private get;
31
+ private run;
32
+ getProject(id: string): Promise<Project | null>;
33
+ putProject(project: Project): Promise<void>;
34
+ /**
35
+ * A scan over every project, filtered here. Owners live inside the JSON, and
36
+ * a second table to index them would be one more thing to keep in step for a
37
+ * query the dashboard runs once per visit. Fine into the thousands; past that
38
+ * it wants an owners table.
39
+ */
40
+ projectsOwnedBy(address: string): Promise<Project[]>;
41
+ projects(): Promise<Project[]>;
42
+ projectStats(projectId: string): Promise<ProjectStats>;
43
+ getMeta(key: string): Promise<string | null>;
44
+ setMeta(key: string, value: string): Promise<void>;
45
+ putTelemetry(r: TelemetryRow): Promise<void>;
46
+ telemetry(): Promise<TelemetryRow[]>;
47
+ posts(projectId: string, reader: string | null): Promise<PostWithVotes[]>;
48
+ getPost(projectId: string, id: string): Promise<PostRow | null>;
49
+ createPost(row: PostRow): Promise<boolean>;
50
+ updatePost(projectId: string, id: string, patch: PostPatch): Promise<void>;
51
+ deletePost(projectId: string, id: string): Promise<void>;
52
+ vote(projectId: string, id: string, voter: string, up: boolean): Promise<number>;
53
+ countByAuthorSince(projectId: string, author: string, since: number): Promise<number>;
54
+ countSince(projectId: string, since: number): Promise<number>;
55
+ answersFor(projectId: string, author: string, limit: number): Promise<Answer[]>;
56
+ names(projectId: string, addresses: string[]): Promise<Map<string, string>>;
57
+ setName(projectId: string, address: string, name: string | undefined): Promise<void>;
58
+ getSeen(projectId: string, owner: string): Promise<number>;
59
+ setSeen(projectId: string, owner: string, at: number): Promise<void>;
60
+ }
61
+ //# sourceMappingURL=sqlite-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-store.d.ts","sourceRoot":"","sources":["../src/sqlite-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAqC,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7F,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAWvG;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,WAAY,YAAW,KAAK;IACvC,OAAO,CAAC,EAAE,CAAW;gBAET,IAAI,EAAE,MAAM;IAy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a/E,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE;IAc5C,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS;IAgBpE,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAKxC,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;CAS3D"}
@@ -0,0 +1,290 @@
1
+ import { createRequire } from 'node:module';
2
+ /*
3
+ * Loaded through `require` rather than an import, for one reason: Vite (which
4
+ * vitest runs on) strips the `node:` prefix and then does not recognise
5
+ * `sqlite` as a built-in, because it is too new for Vite's list. `require` is
6
+ * never seen by Vite and resolves the same module in production. The type
7
+ * import above is erased, so it has the same problem nowhere.
8
+ */
9
+ const { DatabaseSync } = createRequire(import.meta.url)('node:sqlite');
10
+ /**
11
+ * One SQLite file, which is what a self-hoster wants: no database server, a
12
+ * backup is a file copy.
13
+ *
14
+ * **Built on `node:sqlite`, which ships inside Node 22.13+.** That is the
15
+ * whole reason it was chosen over `better-sqlite3`: a native module has to be
16
+ * compiled on install, and on Windows or a slim container that is where people
17
+ * give up. Node still labels it experimental and prints one warning at start;
18
+ * the API it exposes has been stable since it landed.
19
+ *
20
+ * Its own entry point (`@pleasenobugs/server/sqlite`) so that importing the
21
+ * server for another store never loads it, and never prints that warning.
22
+ *
23
+ * Synchronous underneath, so every method finishes before anything else runs,
24
+ * which is what makes `vote()` and `createPost()` atomic without a transaction
25
+ * spanning an await.
26
+ *
27
+ * @example
28
+ * import { SqliteStore } from '@pleasenobugs/server/sqlite';
29
+ * const store = new SqliteStore('./pleasenobugs.db'); // or ':memory:'
30
+ */
31
+ export class SqliteStore {
32
+ db;
33
+ constructor(path) {
34
+ this.db = new DatabaseSync(path);
35
+ this.db.exec(`
36
+ PRAGMA journal_mode = WAL;
37
+ PRAGMA foreign_keys = ON;
38
+ CREATE TABLE IF NOT EXISTS meta (key TEXT PRIMARY KEY, value TEXT NOT NULL);
39
+ CREATE TABLE IF NOT EXISTS projects (id TEXT PRIMARY KEY, data TEXT NOT NULL);
40
+ CREATE TABLE IF NOT EXISTS posts (
41
+ project_id TEXT NOT NULL,
42
+ id TEXT NOT NULL,
43
+ author TEXT NOT NULL,
44
+ anon INTEGER NOT NULL,
45
+ kind TEXT NOT NULL,
46
+ text TEXT NOT NULL,
47
+ at INTEGER NOT NULL,
48
+ status TEXT NOT NULL,
49
+ reply_text TEXT,
50
+ reply_at INTEGER,
51
+ hidden INTEGER NOT NULL DEFAULT 0,
52
+ context TEXT,
53
+ answered_at INTEGER,
54
+ PRIMARY KEY (project_id, id)
55
+ );
56
+ CREATE INDEX IF NOT EXISTS posts_by_author ON posts (project_id, author, at);
57
+ CREATE TABLE IF NOT EXISTS votes (
58
+ project_id TEXT NOT NULL,
59
+ post_id TEXT NOT NULL,
60
+ voter TEXT NOT NULL,
61
+ PRIMARY KEY (project_id, post_id, voter)
62
+ );
63
+ CREATE TABLE IF NOT EXISTS names (
64
+ project_id TEXT NOT NULL,
65
+ address TEXT NOT NULL,
66
+ name TEXT NOT NULL,
67
+ PRIMARY KEY (project_id, address)
68
+ );
69
+ CREATE TABLE IF NOT EXISTS seen (
70
+ project_id TEXT NOT NULL,
71
+ owner TEXT NOT NULL,
72
+ at INTEGER NOT NULL,
73
+ PRIMARY KEY (project_id, owner)
74
+ );
75
+ CREATE TABLE IF NOT EXISTS telemetry (
76
+ instance TEXT NOT NULL,
77
+ project TEXT NOT NULL,
78
+ version TEXT NOT NULL,
79
+ bugs INTEGER NOT NULL,
80
+ ideas INTEGER NOT NULL,
81
+ bugs_done INTEGER NOT NULL,
82
+ ideas_done INTEGER NOT NULL,
83
+ received_at INTEGER NOT NULL,
84
+ PRIMARY KEY (instance, project)
85
+ );
86
+ INSERT OR IGNORE INTO meta (key, value) VALUES ('schema', '1');
87
+ `);
88
+ }
89
+ /** Close the file. Tests use it; a server normally runs until it is killed. */
90
+ close() {
91
+ this.db.close();
92
+ }
93
+ all(sql, ...params) {
94
+ return this.db.prepare(sql).all(...params);
95
+ }
96
+ get(sql, ...params) {
97
+ return this.db.prepare(sql).get(...params);
98
+ }
99
+ run(sql, ...params) {
100
+ return this.db.prepare(sql).run(...params);
101
+ }
102
+ // ---- Projects ----
103
+ async getProject(id) {
104
+ const row = this.get('SELECT data FROM projects WHERE id = ?', id);
105
+ return row ? JSON.parse(String(row.data)) : null;
106
+ }
107
+ async putProject(project) {
108
+ this.run('INSERT INTO projects (id, data) VALUES (?, ?) ON CONFLICT(id) DO UPDATE SET data = excluded.data', project.id, JSON.stringify(project));
109
+ }
110
+ /**
111
+ * A scan over every project, filtered here. Owners live inside the JSON, and
112
+ * a second table to index them would be one more thing to keep in step for a
113
+ * query the dashboard runs once per visit. Fine into the thousands; past that
114
+ * it wants an owners table.
115
+ */
116
+ async projectsOwnedBy(address) {
117
+ return this.all('SELECT data FROM projects')
118
+ .map((r) => JSON.parse(String(r.data)))
119
+ .filter((p) => p.owners.includes(address));
120
+ }
121
+ async projects() {
122
+ return this.all('SELECT data FROM projects').map((r) => JSON.parse(String(r.data)));
123
+ }
124
+ async projectStats(projectId) {
125
+ const row = this.get(`SELECT
126
+ SUM(kind = 'bug') AS bugs,
127
+ SUM(kind = 'idea') AS ideas,
128
+ SUM(kind = 'bug' AND status = 'done') AS bugs_done,
129
+ SUM(kind = 'idea' AND status = 'done') AS ideas_done
130
+ FROM posts WHERE project_id = ? AND hidden = 0`, projectId);
131
+ return {
132
+ bugs: Number(row?.bugs ?? 0),
133
+ ideas: Number(row?.ideas ?? 0),
134
+ bugsDone: Number(row?.bugs_done ?? 0),
135
+ ideasDone: Number(row?.ideas_done ?? 0),
136
+ };
137
+ }
138
+ // ---- This installation ----
139
+ async getMeta(key) {
140
+ const row = this.get('SELECT value FROM meta WHERE key = ?', key);
141
+ return row ? String(row.value) : null;
142
+ }
143
+ async setMeta(key, value) {
144
+ this.run('INSERT INTO meta (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value', key, value);
145
+ }
146
+ // ---- Telemetry received ----
147
+ async putTelemetry(r) {
148
+ this.run(`INSERT INTO telemetry (instance, project, version, bugs, ideas, bugs_done, ideas_done, received_at)
149
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
150
+ ON CONFLICT(instance, project) DO UPDATE SET
151
+ version = excluded.version, bugs = excluded.bugs, ideas = excluded.ideas,
152
+ bugs_done = excluded.bugs_done, ideas_done = excluded.ideas_done, received_at = excluded.received_at`, r.instance, r.project, r.version, r.bugs, r.ideas, r.bugsDone, r.ideasDone, r.receivedAt);
153
+ }
154
+ async telemetry() {
155
+ return this.all('SELECT * FROM telemetry').map((r) => ({
156
+ instance: String(r.instance),
157
+ project: String(r.project),
158
+ version: String(r.version),
159
+ bugs: Number(r.bugs),
160
+ ideas: Number(r.ideas),
161
+ bugsDone: Number(r.bugs_done),
162
+ ideasDone: Number(r.ideas_done),
163
+ receivedAt: Number(r.received_at),
164
+ }));
165
+ }
166
+ // ---- Posts ----
167
+ async posts(projectId, reader) {
168
+ return this.all(`SELECT p.*,
169
+ (SELECT COUNT(*) FROM votes v WHERE v.project_id = p.project_id AND v.post_id = p.id) AS votes,
170
+ EXISTS (SELECT 1 FROM votes v
171
+ WHERE v.project_id = p.project_id AND v.post_id = p.id AND v.voter = ?) AS voted
172
+ FROM posts p WHERE p.project_id = ?`, reader ?? '', projectId).map((r) => ({ ...toRow(r), votes: Number(r.votes), voted: Number(r.voted) === 1 }));
173
+ }
174
+ async getPost(projectId, id) {
175
+ const row = this.get('SELECT * FROM posts WHERE project_id = ? AND id = ?', projectId, id);
176
+ return row ? toRow(row) : null;
177
+ }
178
+ async createPost(row) {
179
+ const inserted = this.run(`INSERT OR IGNORE INTO posts
180
+ (project_id, id, author, anon, kind, text, at, status, reply_text, reply_at, hidden, context, answered_at)
181
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, row.projectId, row.id, row.author, row.anon ? 1 : 0, row.kind, row.text, row.at, row.status, row.reply?.text ?? null, row.reply?.at ?? null, row.hidden ? 1 : 0, row.context ? JSON.stringify(row.context) : null, row.answeredAt ?? null);
182
+ if (Number(inserted.changes) === 0)
183
+ return false;
184
+ this.run('INSERT OR IGNORE INTO votes (project_id, post_id, voter) VALUES (?, ?, ?)', row.projectId, row.id, row.author);
185
+ return true;
186
+ }
187
+ async updatePost(projectId, id, patch) {
188
+ const sets = [];
189
+ const params = [];
190
+ if (patch.status !== undefined) {
191
+ sets.push('status = ?');
192
+ params.push(patch.status);
193
+ }
194
+ if (patch.reply !== undefined) {
195
+ sets.push('reply_text = ?', 'reply_at = ?');
196
+ params.push(patch.reply?.text ?? null, patch.reply?.at ?? null);
197
+ }
198
+ if (patch.hidden !== undefined) {
199
+ sets.push('hidden = ?');
200
+ params.push(patch.hidden ? 1 : 0);
201
+ }
202
+ if (patch.answeredAt !== undefined) {
203
+ sets.push('answered_at = ?');
204
+ params.push(patch.answeredAt);
205
+ }
206
+ if (!sets.length)
207
+ return;
208
+ this.run(`UPDATE posts SET ${sets.join(', ')} WHERE project_id = ? AND id = ?`, ...params, projectId, id);
209
+ }
210
+ async deletePost(projectId, id) {
211
+ this.run('DELETE FROM votes WHERE project_id = ? AND post_id = ?', projectId, id);
212
+ this.run('DELETE FROM posts WHERE project_id = ? AND id = ?', projectId, id);
213
+ }
214
+ async vote(projectId, id, voter, up) {
215
+ if (up) {
216
+ this.run('INSERT OR IGNORE INTO votes (project_id, post_id, voter) VALUES (?, ?, ?)', projectId, id, voter);
217
+ }
218
+ else {
219
+ this.run('DELETE FROM votes WHERE project_id = ? AND post_id = ? AND voter = ?', projectId, id, voter);
220
+ }
221
+ const row = this.get('SELECT COUNT(*) AS n FROM votes WHERE project_id = ? AND post_id = ?', projectId, id);
222
+ return Number(row?.n ?? 0);
223
+ }
224
+ async countByAuthorSince(projectId, author, since) {
225
+ const row = this.get('SELECT COUNT(*) AS n FROM posts WHERE project_id = ? AND author = ? AND at > ?', projectId, author, since);
226
+ return Number(row?.n ?? 0);
227
+ }
228
+ async countSince(projectId, since) {
229
+ const row = this.get('SELECT COUNT(*) AS n FROM posts WHERE project_id = ? AND at > ?', projectId, since);
230
+ return Number(row?.n ?? 0);
231
+ }
232
+ async answersFor(projectId, author, limit) {
233
+ return this.all(`SELECT id, text, answered_at FROM posts
234
+ WHERE project_id = ? AND author = ? AND answered_at IS NOT NULL
235
+ ORDER BY answered_at DESC LIMIT ?`, projectId, author, limit).map((r) => ({ id: String(r.id), text: String(r.text), at: Number(r.answered_at) }));
236
+ }
237
+ // ---- Names ----
238
+ async names(projectId, addresses) {
239
+ const out = new Map();
240
+ if (!addresses.length)
241
+ return out;
242
+ const marks = addresses.map(() => '?').join(', ');
243
+ for (const r of this.all(`SELECT address, name FROM names WHERE project_id = ? AND address IN (${marks})`, projectId, ...addresses)) {
244
+ out.set(String(r.address), String(r.name));
245
+ }
246
+ return out;
247
+ }
248
+ async setName(projectId, address, name) {
249
+ if (name) {
250
+ this.run(`INSERT INTO names (project_id, address, name) VALUES (?, ?, ?)
251
+ ON CONFLICT(project_id, address) DO UPDATE SET name = excluded.name`, projectId, address, name);
252
+ }
253
+ else {
254
+ this.run('DELETE FROM names WHERE project_id = ? AND address = ?', projectId, address);
255
+ }
256
+ }
257
+ // ---- Seen ----
258
+ async getSeen(projectId, owner) {
259
+ const row = this.get('SELECT at FROM seen WHERE project_id = ? AND owner = ?', projectId, owner);
260
+ return Number(row?.at ?? 0);
261
+ }
262
+ async setSeen(projectId, owner, at) {
263
+ this.run(`INSERT INTO seen (project_id, owner, at) VALUES (?, ?, ?)
264
+ ON CONFLICT(project_id, owner) DO UPDATE SET at = excluded.at`, projectId, owner, at);
265
+ }
266
+ }
267
+ /** A database row back into the shape the rest of the server speaks. */
268
+ function toRow(r) {
269
+ const row = {
270
+ projectId: String(r.project_id),
271
+ id: String(r.id),
272
+ author: String(r.author),
273
+ anon: Number(r.anon) === 1,
274
+ kind: String(r.kind),
275
+ text: String(r.text),
276
+ at: Number(r.at),
277
+ status: String(r.status),
278
+ };
279
+ if (r.reply_text !== null && r.reply_text !== undefined) {
280
+ row.reply = { text: String(r.reply_text), at: Number(r.reply_at) };
281
+ }
282
+ if (Number(r.hidden) === 1)
283
+ row.hidden = true;
284
+ if (typeof r.context === 'string')
285
+ row.context = JSON.parse(r.context);
286
+ if (r.answered_at !== null && r.answered_at !== undefined)
287
+ row.answeredAt = Number(r.answered_at);
288
+ return row;
289
+ }
290
+ //# sourceMappingURL=sqlite-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-store.js","sourceRoot":"","sources":["../src/sqlite-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAK5C;;;;;;GAMG;AACH,MAAM,EAAE,YAAY,EAAE,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,aAAa,CAAiC,CAAC;AAEvG;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,WAAW;IACd,EAAE,CAAW;IAErB,YAAY,IAAY;QACtB,IAAI,CAAC,EAAE,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAoDZ,CAAC,CAAC;IACL,CAAC;IAED,+EAA+E;IAC/E,KAAK;QACH,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;IAEO,GAAG,CAAC,GAAW,EAAE,GAAG,MAAuB;QACjD,OAAO,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,MAAM,CAA8B,CAAC;IAC1E,CAAC;IAEO,GAAG,CAAC,GAAW,EAAE,GA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AE,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;QACxB,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;QAC1B,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAa;QAChC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;QACpB,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAe;KACvC,CAAC;IACF,IAAI,CAAC,CAAC,UAAU,KAAK,IAAI,IAAI,CAAC,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QACxD,GAAG,CAAC,KAAK,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;IACrE,CAAC;IACD,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;QAAE,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC;IAC9C,IAAI,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ;QAAE,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAgB,CAAC;IACtF,IAAI,CAAC,CAAC,WAAW,KAAK,IAAI,IAAI,CAAC,CAAC,WAAW,KAAK,SAAS;QAAE,GAAG,CAAC,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IAClG,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,108 @@
1
+ import type { Answer, PostContext, PostKind, PostReply, PostStatus, Project } from '@pleasenobugs/core';
2
+ /**
3
+ * Where a board keeps its rows, behind one interface so the same server runs on
4
+ * an in-memory map, an SQLite file or Postgres.
5
+ *
6
+ * **Every method is async**, even where both shipped stores answer at once,
7
+ * because a database over a network cannot, and an interface that assumed
8
+ * otherwise would have to break the day somebody wrote one.
9
+ *
10
+ * **The awkward operations are the store's job, not the router's.** Voting is
11
+ * the example: done as read-the-post, change-the-list, write-it-back, two votes
12
+ * arriving together lose one. So the interface has `vote()` and leaves it to
13
+ * each store to make that atomic (a primary key in SQL, a single synchronous
14
+ * block in memory). A new store has to pass the shared contract tests in
15
+ * `store.test.ts`, which is the definition of "works".
16
+ *
17
+ * Addresses arrive here already normalised (`normalizeAddress` in core).
18
+ */
19
+ /** A post as stored. Votes live apart from it; see {@link Store.vote}. */
20
+ export interface PostRow {
21
+ projectId: string;
22
+ id: string;
23
+ /** The author. Stored whether or not it may be shown, never sent anywhere. */
24
+ author: string;
25
+ anon: boolean;
26
+ kind: PostKind;
27
+ text: string;
28
+ at: number;
29
+ status: PostStatus;
30
+ reply?: PostReply;
31
+ hidden?: boolean;
32
+ context?: PostContext;
33
+ /**
34
+ * When an owner last set a status on it or wrote under it. Its own field
35
+ * rather than `reply.at`, because a status moved with nothing written is an
36
+ * answer too. Nothing else touches it, so a vote cannot lift somebody's news.
37
+ */
38
+ answeredAt?: number;
39
+ }
40
+ /** A post plus its vote count and whether one particular reader voted. */
41
+ export interface PostWithVotes extends PostRow {
42
+ votes: number;
43
+ voted: boolean;
44
+ }
45
+ /** What `updatePost` may change. `null` removes a field. */
46
+ export interface PostPatch {
47
+ status?: PostStatus;
48
+ reply?: PostReply | null;
49
+ hidden?: boolean;
50
+ answeredAt?: number;
51
+ }
52
+ /** How much one board has had, for telemetry. Hidden posts are not counted. */
53
+ export interface ProjectStats {
54
+ bugs: number;
55
+ ideas: number;
56
+ /** Bugs an owner has marked done: fixed. */
57
+ bugsDone: number;
58
+ /** Ideas an owner has marked done: built. */
59
+ ideasDone: number;
60
+ }
61
+ /** The latest telemetry one installation sent about one of its projects. */
62
+ export interface TelemetryRow extends ProjectStats {
63
+ instance: string;
64
+ project: string;
65
+ version: string;
66
+ receivedAt: number;
67
+ }
68
+ export interface Store {
69
+ getProject(id: string): Promise<Project | null>;
70
+ /** Insert or replace. */
71
+ putProject(project: Project): Promise<void>;
72
+ projectsOwnedBy(address: string): Promise<Project[]>;
73
+ /** Every project on this server. */
74
+ projects(): Promise<Project[]>;
75
+ projectStats(projectId: string): Promise<ProjectStats>;
76
+ /** A small key-value table: the installation's own id lives here. */
77
+ getMeta(key: string): Promise<string | null>;
78
+ setMeta(key: string, value: string): Promise<void>;
79
+ /** Keeps only the latest row per installation and project name. */
80
+ putTelemetry(row: TelemetryRow): Promise<void>;
81
+ telemetry(): Promise<TelemetryRow[]>;
82
+ /** Every post on a board, hidden ones included; the router filters. */
83
+ posts(projectId: string, reader: string | null): Promise<PostWithVotes[]>;
84
+ getPost(projectId: string, id: string): Promise<PostRow | null>;
85
+ /**
86
+ * Write a new post **and the author's own vote** in one step, since the
87
+ * number means "how many want this" and the author is one of them.
88
+ * Answers false, writing nothing, when the id is taken.
89
+ */
90
+ createPost(row: PostRow): Promise<boolean>;
91
+ updatePost(projectId: string, id: string, patch: PostPatch): Promise<void>;
92
+ /** Removes the post and its votes. */
93
+ deletePost(projectId: string, id: string): Promise<void>;
94
+ /** Add or remove one wallet's vote, atomically. Answers the new count. */
95
+ vote(projectId: string, id: string, voter: string, up: boolean): Promise<number>;
96
+ /** How many posts this wallet wrote on this board after `since`. */
97
+ countByAuthorSince(projectId: string, author: string, since: number): Promise<number>;
98
+ /** How many posts anybody wrote on this board after `since`. */
99
+ countSince(projectId: string, since: number): Promise<number>;
100
+ /** This wallet's answered posts, newest answer first. */
101
+ answersFor(projectId: string, author: string, limit: number): Promise<Answer[]>;
102
+ names(projectId: string, addresses: string[]): Promise<Map<string, string>>;
103
+ /** Empty or undefined clears it. */
104
+ setName(projectId: string, address: string, name: string | undefined): Promise<void>;
105
+ getSeen(projectId: string, owner: string): Promise<number>;
106
+ setSeen(projectId: string, owner: string, at: number): Promise<void>;
107
+ }
108
+ //# sour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AM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtE"}
package/dist/store.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":""}
@@ -0,0 +1,83 @@
1
+ import express from 'express';
2
+ import type { ProjectStats, Store, TelemetryRow } from './store.js';
3
+ /**
4
+ * How many bugs and ideas PleaseNoBugs has carried, and how many were fixed or
5
+ * built. That is the whole of what leaves a server, once a day.
6
+ *
7
+ * **What is sent**, per project: its name, how many bugs and ideas it has, and
8
+ * how many of each an owner marked done. Plus a random id for the installation,
9
+ * so a server is not counted twice, and the version. **Never** a post's text,
10
+ * a wallet address, a display name, a vote or an origin.
11
+ *
12
+ * **On unless switched off** (`PNB_TELEMETRY=off`), and said out loud at start
13
+ * so nobody has to read the source to find out. Hidden posts are not counted:
14
+ * those are spam an owner took down, not feedback.
15
+ *
16
+ * The counts are cumulative, so the collector keeps only the latest report per
17
+ * installation and project, and a report sent twice changes nothing.
18
+ */
19
+ /**
20
+ * Where reports go unless `PNB_TELEMETRY_URL` says otherwise: the makers'
21
+ * server, which collects with `PNB_COLLECT=on`. Every published version keeps
22
+ * sending here for as long as it runs, so this Railway service must keep its
23
+ * name and its domain.
24
+ */
25
+ export declare const DEFAULT_TELEMETRY_URL = "https://pleasenobugs-production.up.railway.app/telemetry";
26
+ export declare const TELEMETRY_EVERY_MS: number;
27
+ export interface TelemetryReport {
28
+ instance: string;
29
+ version: string;
30
+ projects: (ProjectStats & {
31
+ name: string;
32
+ })[];
33
+ }
34
+ /** This installation's id, made on first use and kept in the database. */
35
+ export declare function instanceId(store: Store): Promise<string>;
36
+ /** Everything a report would say, so it can be logged before it is sent. */
37
+ export declare function buildReport(store: Store, version: string): Promise<TelemetryReport>;
38
+ /** The line a server prints at start, saying exactly what it sends and how to stop it. */
39
+ export declare function telemetryNotice(url: string): string;
40
+ /** Send one report. Answers whether it arrived; never throws. */
41
+ export declare function sendReport(url: string, report: TelemetryReport, doFetch?: typeof fetch): Promise<boolean>;
42
+ /**
43
+ * Report now-ish and then once a day, for as long as the process runs.
44
+ * Answers a function that stops it. The timers are `unref`'d so they never
45
+ * keep a process alive that is otherwise done.
46
+ */
47
+ export declare function startTelemetry(options: {
48
+ store: Store;
49
+ url: string;
50
+ version: string;
51
+ }): () => void;
52
+ /**
53
+ * A report as received, or null. Strict, because anybody can post one: these
54
+ * are vanity numbers, and the most a liar can do is inflate them, but nothing
55
+ * odd gets stored.
56
+ */
57
+ export declare function readReport(body: unknown): TelemetryReport | null;
58
+ export interface TelemetrySummary {
59
+ /** Installations heard from in the last 30 days. */
60
+ installations: number;
61
+ /** Projects ever reported, across every installation. */
62
+ projects: number;
63
+ bugs: number;
64
+ ideas: number;
65
+ bugsDone: number;
66
+ ideasDone: number;
67
+ }
68
+ /**
69
+ * The totals across everything ever reported. A server that went quiet keeps
70
+ * its numbers in the totals, because what it carried was still carried; it
71
+ * only stops counting as an installation.
72
+ */
73
+ export declare function summarize(rows: TelemetryRow[], now: number): TelemetrySummary;
74
+ /**
75
+ * The two routes of a collecting server (`PNB_COLLECT=on`).
76
+ *
77
+ * `POST /telemetry` takes a report. `GET /telemetry/summary` answers the
78
+ * totals and nothing per project: the names of other people's apps are not
79
+ * published here. They are read on the server itself with
80
+ * `pleasenobugs-server telemetry`.
81
+ */
82
+ export declare function telemetryRouter(store: Store, now?: () => number): express.Router;
83
+ //# sourceMappingURL=telemetry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEpE;;;;;;;;;;;;;;;GAeG;AAEH;;;;;GA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