pleasenobugs 0.3.0 → 0.4.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.
package/README.md CHANGED
@@ -42,11 +42,11 @@ menuItem.onclick = () => open({ project: 'YOUR_PROJECT_ID', server: 'https://YOU
42
42
  | `start` | `tiles` (default) or `board`: what opens first. A `readonly` board is always the board. |
43
43
  | `theme` | `nimiq` (default): the Nimiq Foundation's 2026 brand, navy on white with a gold round button. `nimiq-dark`: the same on navy. |
44
44
  | `lang` | The language of your `strings`, so dates follow it: `nl` writes "14 sep". English by default. |
45
- | `app-name` | What answers are signed with ("Shitti says"). Defaults to the project's name. |
46
- | `name` | A display name you already know, offered when the user chooses to show theirs. |
45
+ | `app-name` | What answers are signed with ("My app says"). Defaults to the project's name. |
46
+ | `name` | A display name you already know, filled in for a user who has not chosen one on this board yet. |
47
47
  | `kinds` | Which kinds to offer, of the ones your project takes: `bug,idea,review` by default. `kinds="bug,idea"` leaves reviews off the tiles and out of the list. |
48
48
  | `screenshots` | Who sees screenshots on bugs and ideas. On the board for everyone by default, each one only after its author ticks that everyone may see it. `owners` keeps them for your eyes only; `off` leaves the "Add a screenshot" button out. An unknown value counts as `owners`. The project's own rule (`PNB_PROJECT_SCREENSHOTS` on the server) wins when it is stricter. |
49
- | `names` | `off` leaves out "Show my name", so every post is anonymous. For a board on a public page. |
49
+ | `names` | `off` leaves out the name field and the "Post anonymously" switch: every post is anonymous, with no name and no identicon. |
50
50
  | `readonly` | The board to read and scroll through, nothing else: no **+**, no votes (the count still shows), no "Sign in", and it never asks a wallet or sends a proof, not even inside Nimiq Pay. Every post shows as anonymous and without its screenshot, whatever its author chose, because a read-only board is usually shown somewhere other than the app its authors wrote for. |
51
51
  | `demo` | A board of sample posts in the page's memory, with no server: `<please-no-bugs demo>`. Voting and writing work, nothing is sent or stored, and a reload starts over. For trying the widget, or showing it off. `demo="owner"` is the same board as its owner sees it: answer, set a status and "Fixed in", write updates. |
52
52
  | `screen` | With `demo` only: hold one screen in view, `button`, `tiles`, `board`, `write`, `sent` or `updates`. What the website's Make it yours uses to show each part. |
@@ -69,6 +69,12 @@ Tapping **+** opens three tiles: **Report a bug**, **Share an idea** and
69
69
  board with the average on top, so people can see what others like about your
70
70
  app. One review per wallet.
71
71
 
72
+ A post goes out with **the user's wallet identicon and a name** they fill in
73
+ once per board, never their address. Changing the name changes it on their
74
+ earlier posts too. **"Post anonymously"** leaves both off. The identicon is
75
+ drawn by your PleaseNoBugs server (`/v1/identicons/…`), like screenshots, so
76
+ the page needs that server in its `img-src`.
77
+
72
78
  A bug or an idea can carry **a screenshot, shown on the board** under the
73
79
  post, so everybody can see what is meant. Before picking one the user reads
74
80
  that everyone will see it and should check it for a balance, an address or a
@@ -218,9 +224,19 @@ to the widget and nobody signs twice:
218
224
  board.appLogin = { address, publicKey, signature, message: 'Sign in to My app' };
219
225
  ```
220
226
 
221
- The project has to list that exact message first (`loginMessages`, through the
222
- dashboard or `create-project --login-message`). Set `appLogin` to `null` when
223
- the user logs out of your app.
227
+ The project has to accept that message first: set `PNB_PROJECT_LOGIN_MESSAGE`
228
+ on your server (on a server that already runs, set it and restart; with one
229
+ project it is added to that one), or use the dashboard or
230
+ `create-project --login-message`. If your login message changes every time,
231
+ because it carries a date or a random code, give its fixed start followed by
232
+ `*`, like `Sign in to My app*` (at least 12 characters before the `*`). Set
233
+ `appLogin` to `null` when the user logs out of your app.
234
+
235
+ This is how a mini app in Nimiq Pay, or a website with its own wallet login,
236
+ lets its users post and vote without signing anything again. Without it, the
237
+ widget asks the wallet to sign once by itself, at the first vote or post:
238
+ inside Nimiq Pay a short confirmation, kept for a month; in a browser through
239
+ the Nimiq Hub, kept until the tab closes.
224
240
 
225
241
  ## Signing outside Nimiq Pay
226
242
 
@@ -238,8 +254,13 @@ document.querySelector('please-no-bugs').signer = async (message) => {
238
254
  };
239
255
  ```
240
256
 
241
- Without a signer outside Nimiq Pay, the board is read-only and says so when
242
- somebody tries to post.
257
+ With a signer and outside Nimiq Pay, the board offers **"Sign in with Nimiq"**
258
+ on top until the user has signed in, since signing opens a wallet window
259
+ there. Without a signer outside Nimiq Pay, the board is read-only and says
260
+ "Sign in with your Nimiq wallet to post and vote" when somebody tries to post.
261
+ On a website with its own wallet login, that is the moment to hand the login
262
+ over with `appLogin` (above): set it once the user has signed in to your site,
263
+ and back to `null` when they sign out.
243
264
 
244
265
  ## Headless
245
266
 
@@ -0,0 +1,358 @@
1
+ function T(t) {
2
+ return t.replace(/\s+/g, "").toUpperCase();
3
+ }
4
+ const M = 30 * 24 * 60 * 60 * 1e3, x = 5 * 60 * 1e3;
5
+ function J(t) {
6
+ return [
7
+ "PleaseNoBugs login",
8
+ `Project: ${t.project}`,
9
+ `Origin: ${D(t.origin)}`,
10
+ `Issued: ${new Date(t.issued).toISOString()}`
11
+ ].join(`
12
+ `);
13
+ }
14
+ function D(t) {
15
+ try {
16
+ return new URL(t).origin;
17
+ } catch {
18
+ return t;
19
+ }
20
+ }
21
+ function A(t, n = Date.now()) {
22
+ return Number.isFinite(t) && t <= n + x && n - t <= M;
23
+ }
24
+ function F(t) {
25
+ return `Nimiq ${K(JSON.stringify(t))}`;
26
+ }
27
+ function K(t) {
28
+ const n = new TextEncoder().encode(t);
29
+ let o = "";
30
+ for (const a of n)
31
+ o += String.fromCharCode(a);
32
+ return btoa(o).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
33
+ }
34
+ const W = [
35
+ // Dutch
36
+ "aan",
37
+ "als",
38
+ "bij",
39
+ "dan",
40
+ "dat",
41
+ "deze",
42
+ "die",
43
+ "dit",
44
+ "een",
45
+ "heb",
46
+ "het",
47
+ "ik",
48
+ "is",
49
+ "kan",
50
+ "kun",
51
+ "maar",
52
+ "met",
53
+ "mijn",
54
+ "niet",
55
+ "ook",
56
+ "van",
57
+ "voor",
58
+ "wil",
59
+ "word",
60
+ "wordt",
61
+ "zijn",
62
+ "zou",
63
+ "graag",
64
+ "meer",
65
+ "moet",
66
+ // English
67
+ "and",
68
+ "are",
69
+ "but",
70
+ "can",
71
+ "for",
72
+ "have",
73
+ "more",
74
+ "not",
75
+ "should",
76
+ "that",
77
+ "the",
78
+ "this",
79
+ "want",
80
+ "when",
81
+ "with",
82
+ "would",
83
+ "you",
84
+ "your",
85
+ // German
86
+ "aber",
87
+ "auch",
88
+ "bitte",
89
+ "dass",
90
+ "denn",
91
+ "ein",
92
+ "eine",
93
+ "einen",
94
+ "gerne",
95
+ "ich",
96
+ "ist",
97
+ "kann",
98
+ "mehr",
99
+ "mein",
100
+ "meine",
101
+ "nicht",
102
+ "oder",
103
+ "sein",
104
+ "sollte",
105
+ "und",
106
+ "wenn",
107
+ "werden",
108
+ "wird",
109
+ "wollen",
110
+ "möchte",
111
+ // Every board is about an app
112
+ "app"
113
+ ];
114
+ function Z(t = []) {
115
+ const n = /* @__PURE__ */ new Set([...W, ...[...t].map((r) => r.toLowerCase())]), o = /* @__PURE__ */ new WeakMap(), a = (r) => new Set(r.toLowerCase().replace(/[^\p{L}\p{N}\s]/gu, " ").split(/\s+/).filter((m) => m.length >= 4 && !n.has(m)));
116
+ return function(m, q, w = 3) {
117
+ const p = a(q);
118
+ return p.size < 2 ? [] : m.map((u) => {
119
+ let l = o.get(u);
120
+ l || (l = a(u.text), o.set(u, l));
121
+ let d = 0;
122
+ for (const h of p)
123
+ l.has(h) && d++;
124
+ return { post: u, shared: d };
125
+ }).filter((u) => u.shared >= 2).sort((u, l) => l.shared - u.shared || l.post.votes - u.post.votes).slice(0, w).map((u) => u.post);
126
+ };
127
+ }
128
+ function ee(t, n) {
129
+ const o = [...t];
130
+ return n === "new" ? o.sort((a, r) => r.at - a.at) : o.sort((a, r) => r.votes - a.votes || r.at - a.at);
131
+ }
132
+ class E extends Error {
133
+ constructor(n, o) {
134
+ super(o ?? n), this.reason = n, this.name = "SignerError";
135
+ }
136
+ }
137
+ const B = 2e3;
138
+ function j() {
139
+ return typeof window < "u" && !!window.nimiq;
140
+ }
141
+ function H(t) {
142
+ return window.nimiq ? Promise.resolve(window.nimiq) : new Promise((n, o) => {
143
+ const a = Date.now(), r = setInterval(() => {
144
+ window.nimiq ? (clearInterval(r), n(window.nimiq)) : Date.now() - a > t && (clearInterval(r), o(new E("no_wallet", "Not running inside Nimiq Pay")));
145
+ }, 50);
146
+ });
147
+ }
148
+ function Q(t = B) {
149
+ return async (n) => {
150
+ const o = await H(t), a = await o.listAccounts();
151
+ if (!Array.isArray(a) || !a.length) throw new E("no_account");
152
+ const r = await o.sign(n);
153
+ if (!r || !("signature" in r))
154
+ throw new E("declined", r && "error" in r ? r.error.message : void 0);
155
+ return { address: a[0], publicKey: r.publicKey, signature: r.signature };
156
+ };
157
+ }
158
+ async function V() {
159
+ try {
160
+ const t = await window.nimiq?.listAccounts();
161
+ return Array.isArray(t) && t.length ? t[0] : null;
162
+ } catch {
163
+ return null;
164
+ }
165
+ }
166
+ function te(t) {
167
+ const n = t.server.replace(/\/+$/, ""), o = t.project, a = D(t.origin ?? (typeof location < "u" ? location.origin : "")), r = t.signer === null ? void 0 : t.signer ?? (j() ? Q() : void 0), m = t.fetch ?? globalThis.fetch.bind(globalThis), q = j(), w = `pleasenobugs.proof.${o}.${a}`, p = t.storage === void 0 ? q ? Y() : X(w) : t.storage, u = t.account ?? (t.signer === void 0 && q ? V : void 0);
168
+ let l = 0, d = R(), h = null, N = !1;
169
+ function P() {
170
+ if (N || !t.appLogin) return null;
171
+ const e = typeof t.appLogin == "function" ? t.appLogin() : t.appLogin;
172
+ return e ? { ...e, origin: a, issued: 0 } : null;
173
+ }
174
+ function R() {
175
+ try {
176
+ const e = p?.getItem(w);
177
+ if (!e) return null;
178
+ const s = JSON.parse(e);
179
+ return A(s.issued) ? s : null;
180
+ } catch {
181
+ return null;
182
+ }
183
+ }
184
+ function b(e) {
185
+ d = e;
186
+ try {
187
+ e ? p?.setItem(w, JSON.stringify(e)) : p?.removeItem(w);
188
+ } catch {
189
+ }
190
+ }
191
+ async function z() {
192
+ if (!u || !d || Date.now() - l < 3e4) return;
193
+ l = Date.now();
194
+ const e = await u();
195
+ e && d && T(e) !== T(d.address) && b(null);
196
+ }
197
+ function $() {
198
+ const e = P();
199
+ return e || (d && !A(d.issued) && b(null), d);
200
+ }
201
+ function _() {
202
+ const e = P();
203
+ return e ? Promise.resolve({ ok: !0, data: T(e.address) }) : r ? h || (h = (async () => {
204
+ try {
205
+ const s = Date.now(), c = await r(J({ project: o, origin: a, issued: s }));
206
+ return b({ ...c, origin: a, issued: s }), { ok: !0, data: T(c.address) };
207
+ } catch (s) {
208
+ return s instanceof E && s.reason === "no_wallet" ? { ok: !1, status: 0, error: "no_signer" } : { ok: !1, status: 0, error: "declined" };
209
+ } finally {
210
+ h = null;
211
+ }
212
+ })(), h) : Promise.resolve({ ok: !1, status: 0, error: "no_signer" });
213
+ }
214
+ async function i(e, s, c) {
215
+ c.auth !== "none" && await z();
216
+ const I = async (S) => {
217
+ const O = {};
218
+ c.body !== void 0 && (O["content-type"] = "application/json"), S && (O.authorization = F(S));
219
+ let y;
220
+ try {
221
+ y = await m(`${n}${s}`, {
222
+ method: e,
223
+ headers: O,
224
+ ...c.body !== void 0 ? { body: JSON.stringify(c.body) } : {}
225
+ });
226
+ } catch {
227
+ return { ok: !1, status: 0, error: "network" };
228
+ }
229
+ if (y.ok && c.blob) {
230
+ const U = await y.blob().catch(() => null);
231
+ return U ? { ok: !0, data: U } : { ok: !1, status: 0, error: "network" };
232
+ }
233
+ const k = await y.json().catch(() => null);
234
+ if (y.ok) return { ok: !0, data: k };
235
+ const G = k && typeof k.error == "string" ? k.error : "internal";
236
+ return { ok: !1, status: y.status, error: G, body: k };
237
+ };
238
+ if (c.auth === "none") return I(null);
239
+ let v = $();
240
+ if (!v && c.auth === "required") {
241
+ const S = await _();
242
+ if (!S.ok) return S;
243
+ v = $();
244
+ }
245
+ const L = await I(v);
246
+ if (L.ok || L.status !== 401 || !v) return L;
247
+ if (v.message !== void 0 ? N = !0 : b(null), c.auth === "optional") return I(null);
248
+ const C = await _();
249
+ return C.ok ? I($()) : C;
250
+ }
251
+ const f = (e = "") => `/v1/projects/${encodeURIComponent(o)}${e}`, g = (e) => f(`/posts/${encodeURIComponent(e)}`);
252
+ return {
253
+ /** The project this client talks to. */
254
+ project: o,
255
+ /** Whether the user can be signed in at all: a signer, or an app login. */
256
+ get canSign() {
257
+ return !!r || P() !== null;
258
+ },
259
+ /** The signed-in address, if a proof is stored. */
260
+ address() {
261
+ const e = $();
262
+ return e ? T(e.address) : null;
263
+ },
264
+ signIn: _,
265
+ /** Forget the stored proof. The next write asks the wallet again. */
266
+ signOut() {
267
+ b(null);
268
+ },
269
+ /** The whole board, plus `me` when signed in. Never prompts. */
270
+ board: () => i("GET", f("/posts"), { auth: "optional" }),
271
+ me: () => i("GET", f("/me"), { auth: "required" }),
272
+ answers: () => i("GET", f("/answers"), { auth: "required" }),
273
+ /**
274
+ * Write one. A review needs `rating` (1 to 5); a bug or an idea may carry
275
+ * `shot`, a screenshot as base64. It goes on the board for everyone only
276
+ * with `board: true`, which says the user agreed; without it only the
277
+ * project's owners see it.
278
+ */
279
+ post: (e) => i("POST", f("/posts"), { body: e, auth: "required" }),
280
+ /** A post's screenshot: anybody's for one on the board, owners' for any. */
281
+ shot: (e) => i("GET", `${g(e)}/shot`, { auth: "optional", blob: !0 }),
282
+ /**
283
+ * Where a screenshot on the board can be read without a proof, for an
284
+ * `<img>` to load by itself.
285
+ */
286
+ shotUrl: (e) => `${n}${g(e)}/shot`,
287
+ /** Where the server draws an identicon, by the code a post carries in `face`. */
288
+ faceUrl: (e) => `${n}/v1/identicons/${encodeURIComponent(e)}.svg`,
289
+ vote: (e, s) => i("POST", `${g(e)}/vote`, {
290
+ body: { up: s },
291
+ auth: "required"
292
+ }),
293
+ remove: (e) => i("DELETE", g(e), { auth: "required" }),
294
+ setName: (e) => i("PUT", f("/me"), { body: { name: e }, auth: "required" }),
295
+ /**
296
+ * An owner answering a post. `fix` says where the fix is, on a bug or an
297
+ * idea set to done: `{ version?, link? }`, the link on github.com or
298
+ * gitlab.com. Moving a post away from done takes its fix away by itself.
299
+ */
300
+ manage: (e, s) => i("POST", `${g(e)}/manage`, { body: s, auth: "required" }),
301
+ /**
302
+ * Write under a post: an owner for the app, whenever they like; its
303
+ * author only right after the app, on a bug or an idea that is not done
304
+ * (`not_your_turn`, `closed` otherwise). `message.id` is yours to mint.
305
+ */
306
+ say: (e, s) => i("POST", `${g(e)}/messages`, { body: s, auth: "required" }),
307
+ /**
308
+ * Change your own last message before anybody answered it (`text`), or,
309
+ * as an owner, take an author's message off the board or put it back
310
+ * (`hidden`).
311
+ */
312
+ editMessage: (e, s, c) => i("PATCH", `${g(e)}/messages/${encodeURIComponent(s)}`, {
313
+ body: c,
314
+ auth: "required"
315
+ }),
316
+ /** Take your own last message back, before anybody answered it. */
317
+ unsay: (e, s) => i("DELETE", `${g(e)}/messages/${encodeURIComponent(s)}`, { auth: "required" }),
318
+ /** What changed in the app, newest first. Anybody's to read; never prompts. */
319
+ updates: () => i("GET", f("/updates"), { auth: "optional" }),
320
+ /**
321
+ * An owner writing one. `link` is a page on github.com or gitlab.com;
322
+ * `posts` are the bugs and ideas it fixed, which go to done with its
323
+ * version and link.
324
+ */
325
+ postUpdate: (e) => i("POST", f("/updates"), { body: e, auth: "required" }),
326
+ /** An owner taking one off the page. The posts it fixed stay done. */
327
+ removeUpdate: (e) => i("DELETE", f(`/updates/${encodeURIComponent(e)}`), { auth: "required" })
328
+ };
329
+ }
330
+ function X(t) {
331
+ try {
332
+ globalThis.localStorage?.removeItem(t);
333
+ } catch {
334
+ }
335
+ try {
336
+ const n = globalThis.sessionStorage, o = "__pleasenobugs__";
337
+ return n.setItem(o, "1"), n.removeItem(o), n;
338
+ } catch {
339
+ return null;
340
+ }
341
+ }
342
+ function Y() {
343
+ try {
344
+ const t = globalThis.localStorage, n = "__pleasenobugs__";
345
+ return t.setItem(n, "1"), t.removeItem(n), t;
346
+ } catch {
347
+ return null;
348
+ }
349
+ }
350
+ export {
351
+ E as S,
352
+ te as a,
353
+ T as b,
354
+ Z as c,
355
+ j as i,
356
+ Q as n,
357
+ ee as s
358
+ };
@@ -0,0 +1,232 @@
1
+ import { b as T } from "./client-CkFi6gmV.js";
2
+ import { D as y, c as O, l as D, a as P, i as U, b as E } from "./index-B1dIQO6N.js";
3
+ function $(s) {
4
+ return C(N(s)).slice(0, 12).replace(/\D/g, "0");
5
+ }
6
+ function N(s) {
7
+ return T(s).replace(/(.{4})(?=.)/g, "$1 ");
8
+ }
9
+ function C(s) {
10
+ const d = ("" + s.split("").map((l) => Number(l.charCodeAt(0)) + 3).reduce((l, c) => l * (1 - l) * L(c), 0.5)).split("").reduce((l, c) => c + l, "");
11
+ return d.replace(".", d[5]).substr(4, 17).padEnd(13, d[5]);
12
+ }
13
+ function L(s) {
14
+ let d = 1 / s;
15
+ for (let l = 0; l < 100; l++)
16
+ d = (1 - d) * d * 3.569956786876;
17
+ return d;
18
+ }
19
+ function j({ owner: s = !1, samples: d } = {}) {
20
+ const l = Date.now();
21
+ let c = (d ?? I).map((t, e) => ({
22
+ id: `demo-${e}`,
23
+ kind: t.kind,
24
+ text: t.text,
25
+ at: l - (t.ago ?? _),
26
+ status: t.status ?? "open",
27
+ votes: t.votes ?? 1,
28
+ voted: !1,
29
+ // A visitor's own; an owner is never the author of a sample.
30
+ mine: !s && !!t.mine,
31
+ // A made-up wallet per name, so each sample author has an identicon of their own.
32
+ ...t.who ? { who: t.who, face: $(`NQ00 ${t.who}`) } : {},
33
+ ...t.rating ? { rating: t.rating } : {},
34
+ ...F(e, t, l - (t.ago ?? _)),
35
+ ...t.fix ? { fix: { version: t.fix, link: A } } : {},
36
+ // What the app sent along, which only owners see.
37
+ ...s && t.context ? { context: { ...t.context } } : {}
38
+ })), m = (d ? [] : q).map((t, e) => ({
39
+ id: `demo-update-${e}`,
40
+ title: t.title,
41
+ text: t.text,
42
+ version: t.version,
43
+ link: A,
44
+ at: l - t.ago,
45
+ posts: t.posts.map((o) => `demo-${o}`)
46
+ })), p, v = y.perDay;
47
+ const x = /* @__PURE__ */ new Map(), u = (t) => S({ ok: !0, data: t }), r = (t, e) => S({ ok: !1, status: t, error: e }), h = (t) => c.find((e) => e.id === t), w = (t, e) => {
48
+ e.length ? t.thread = e : delete t.thread;
49
+ const o = E(e);
50
+ o ? t.reply = o : delete t.reply;
51
+ }, g = (t) => s ? "app" : t.mine ? "author" : null;
52
+ return {
53
+ project: "demo",
54
+ canSign: !0,
55
+ address: () => M,
56
+ signIn: () => u(M),
57
+ signOut() {
58
+ },
59
+ // At once, without the wait: the tiles are there while the panel grows,
60
+ // instead of a spinner they replace halfway.
61
+ board: () => Promise.resolve({
62
+ ok: !0,
63
+ data: {
64
+ project: { id: "demo", name: "Demo app", rules: { ...y, kinds: [...y.kinds] } },
65
+ posts: c.map((t) => ({ ...t })),
66
+ me: { owner: s, left: v, face: b, ...p ? { name: p } : {} },
67
+ updates: m.length
68
+ }
69
+ }),
70
+ me: () => u({ owner: s, left: v, face: b, ...p ? { name: p } : {} }),
71
+ answers: () => u({ answers: [] }),
72
+ post(t) {
73
+ return v <= 0 ? r(429, "too_many") : t.kind === "review" && c.some((e) => e.mine && e.kind === "review") ? r(409, "reviewed") : (v -= 1, c = [
74
+ {
75
+ id: t.id,
76
+ kind: t.kind,
77
+ text: t.text,
78
+ at: Date.now(),
79
+ status: "open",
80
+ votes: 1,
81
+ voted: !0,
82
+ mine: !0,
83
+ ...t.anon ? {} : { face: b, ...p ? { who: p } : {} },
84
+ ...t.kind === "review" ? { rating: t.rating } : {},
85
+ ...t.shot?.board ? { shot: !0 } : {}
86
+ },
87
+ ...c
88
+ ], t.shot?.board && x.set(t.id, `data:${t.shot.type};base64,${t.shot.data}`), u({ ok: !0, left: v }));
89
+ },
90
+ // The visitor's own screenshots on the board; nothing else exists here.
91
+ shot: async (t) => {
92
+ const e = x.get(t);
93
+ return e ? u(await (await fetch(e)).blob()) : r(404, "not_found");
94
+ },
95
+ shotUrl: (t) => x.get(t) ?? "",
96
+ // No server to draw it: the card shows the stand-in in the identicon's colour.
97
+ faceUrl: () => "",
98
+ vote(t, e) {
99
+ const o = h(t);
100
+ return o ? (o.voted !== e && (o.votes += e ? 1 : -1), o.voted = e, u({ ok: !0, votes: o.votes, voted: o.voted })) : r(404, "not_found");
101
+ },
102
+ remove(t) {
103
+ const e = h(t);
104
+ return e ? (c = c.filter((o) => o !== e), x.delete(t), u({ ok: !0 })) : r(404, "not_found");
105
+ },
106
+ setName(t) {
107
+ p = t.trim() || void 0;
108
+ for (const e of c) e.mine && e.face !== void 0 && (e.who = p);
109
+ return u({ ok: !0, ...p ? { name: p } : {} });
110
+ },
111
+ // As the server: one change for all of it, and a fix only on a done
112
+ // bug or idea, gone as soon as it stands anywhere else.
113
+ manage(t, e) {
114
+ if (!s) return r(403, "not_owner");
115
+ const o = h(t);
116
+ if (!o) return r(404, "not_found");
117
+ if (e.status && o.kind !== "review" && (o.status = e.status), e.reply !== void 0) {
118
+ const n = e.reply.trim(), i = o.thread ?? [], a = D(i);
119
+ n !== (E(i)?.text ?? "") && (a?.from === "app" ? w(
120
+ o,
121
+ n ? i.map((f) => f === a ? { ...f, text: n, edited: Date.now() } : f) : i.filter((f) => f !== a)
122
+ ) : n && w(o, [...i, { id: `reply-${Date.now()}`, from: "app", text: n, at: Date.now() }]));
123
+ }
124
+ if (e.hidden !== void 0 && (e.hidden ? o.hidden = !0 : delete o.hidden), e.approved && delete o.pending, o.status !== "done" || o.kind === "review") delete o.fix;
125
+ else if (e.fix !== void 0) {
126
+ const n = e.fix && O(e.fix);
127
+ if (e.fix && !n) return r(400, "bad_request");
128
+ n && (n.version || n.link) ? o.fix = n : delete o.fix;
129
+ }
130
+ return u({ ok: !0 });
131
+ },
132
+ // The conversation, by the server's rules (see `authorMayAnswer`).
133
+ say(t, e) {
134
+ const o = h(t);
135
+ if (!o) return r(404, "not_found");
136
+ const n = g(o), i = e.text.trim();
137
+ if (!i || i.length > y.replyMax) return r(400, "bad_request");
138
+ if (!n) return r(403, "not_yours");
139
+ if (n === "author" && !P(o))
140
+ return r(409, o.kind === "review" || U(o.status) ? "closed" : "not_your_turn");
141
+ if (n === "app" && o.kind === "review" && o.thread?.some((f) => f.from === "app")) return r(409, "not_your_turn");
142
+ const a = { id: e.id, from: n, text: i, at: Date.now() };
143
+ return w(o, [...o.thread ?? [], a]), u({ ok: !0, message: a });
144
+ },
145
+ editMessage(t, e, o) {
146
+ const n = h(t), i = n?.thread?.find((f) => f.id === e);
147
+ if (!n || !i) return r(404, "not_found");
148
+ let a = { ...i };
149
+ if (o.hidden !== void 0) {
150
+ if (!s) return r(403, "not_owner");
151
+ if (i.from !== "author") return r(400, "bad_request");
152
+ o.hidden ? a.hidden = !0 : delete a.hidden;
153
+ }
154
+ if (o.text !== void 0) {
155
+ const f = o.text.trim();
156
+ if (!f || f.length > y.replyMax) return r(400, "bad_request");
157
+ if (g(n) !== i.from) return r(403, "not_yours");
158
+ if (D(n.thread)?.id !== i.id) return r(409, "not_your_turn");
159
+ f !== i.text && (a = { ...a, text: f, edited: Date.now() });
160
+ }
161
+ return w(n, (n.thread ?? []).map((f) => f === i ? a : f)), u({ ok: !0, message: a });
162
+ },
163
+ unsay(t, e) {
164
+ const o = h(t), n = o?.thread?.find((i) => i.id === e);
165
+ return !o || !n ? r(404, "not_found") : g(o) !== n.from ? r(403, "not_yours") : D(o.thread)?.id !== n.id ? r(409, "not_your_turn") : (w(o, (o.thread ?? []).filter((i) => i !== n)), u({ ok: !0 }));
166
+ },
167
+ // Only those whose posts are still here, like the server; at once, like
168
+ // the board, so the page is there to read rather than a spinner first.
169
+ updates: () => Promise.resolve({
170
+ ok: !0,
171
+ data: { updates: m.map((t) => ({ ...t, posts: t.posts.filter((e) => !!h(e)) })) }
172
+ }),
173
+ // The bugs and ideas it names go to done, with its version and link.
174
+ postUpdate(t) {
175
+ if (!s) return r(403, "not_owner");
176
+ const e = O({ version: t.version ?? "", link: t.link });
177
+ if (!t.title.trim() || !e?.link) return r(400, "bad_request");
178
+ const o = (t.posts ?? []).filter((i) => {
179
+ const a = h(i);
180
+ return a && a.kind !== "review";
181
+ });
182
+ for (const i of o) {
183
+ const a = h(i);
184
+ a.status = "done", a.fix = e;
185
+ }
186
+ const n = {
187
+ id: t.id,
188
+ title: t.title.trim(),
189
+ ...t.text?.trim() ? { text: t.text.trim() } : {},
190
+ ...e.version ? { version: e.version } : {},
191
+ link: e.link,
192
+ at: Date.now(),
193
+ posts: o
194
+ };
195
+ return m = [n, ...m], u({ ok: !0, update: n });
196
+ },
197
+ removeUpdate(t) {
198
+ return s ? m.some((e) => e.id === t) ? (m = m.filter((e) => e.id !== t), u({ ok: !0 })) : r(404, "not_found") : r(403, "not_owner");
199
+ }
200
+ };
201
+ }
202
+ const M = "NQ00 DEMO DEMO DEMO DEMO DEMO DEMO DEMO DEMO", b = $(M), A = "https://github.com/lennylenders/PleaseNoBugs/releases";
203
+ function S(s) {
204
+ return new Promise((d) => setTimeout(() => d(s), 250));
205
+ }
206
+ const _ = 36e5, k = 24 * _;
207
+ function F(s, d, l) {
208
+ const c = d.thread ?? (d.reply ? [["app", d.reply]] : []);
209
+ if (!c.length) return {};
210
+ const m = c.map(([v, x], u) => ({
211
+ id: `demo-${s}-m${u}`,
212
+ from: v,
213
+ text: x,
214
+ at: l + (u + 1) * 5 * 6e4
215
+ })), p = E(m);
216
+ return { thread: m, ...p ? { reply: p } : {} };
217
+ }
218
+ const q = [
219
+ { title: "Switching accounts works again", text: "The send button stayed grey after you switched accounts. It now follows the account you picked.", version: "1.4.2", ago: 2 * k, posts: [1] },
220
+ { title: "Opens faster", text: "About twice as fast on older phones.", version: "1.4.0", ago: 21 * k, posts: [] }
221
+ ], I = [
222
+ { kind: "idea", text: "A dark mode that follows my phone", votes: 24, ago: 6 * k, status: "planned", who: "Mira", reply: "On its way in the next release." },
223
+ { kind: "bug", text: "The send button does nothing after I switch accounts", votes: 17, ago: 2 * k, status: "done", fix: "1.4.2", reply: "Thanks for the steps, that made it easy to find." },
224
+ { kind: "review", text: "Fast, simple and it never asks me twice. Love it.", votes: 9, ago: 3 * k, rating: 5, who: "Joost" },
225
+ { kind: "idea", text: "Let me pin my favourite contacts to the top", votes: 12, ago: 4 * _, mine: !0, thread: [["app", "Good one! Pinned at the top of the list, or on a Favourites tab of their own?"]] },
226
+ { kind: "review", text: "Does what it says. The history screen could be clearer.", votes: 4, ago: 9 * k, rating: 4 },
227
+ { kind: "bug", text: "Amounts over 1,000 overlap the currency on small phones", votes: 6, ago: 20 * _, who: "Sam", context: { version: "1.4.2", screen: "Send" }, thread: [["app", "Thanks! Which phone is it, and which currency?"], ["author", "An iPhone SE, in euros."]] },
228
+ { kind: "idea", text: "Export my history as a CSV file", votes: 3, ago: 12 * k, status: "declined", reply: "Not for now: it would mean storing more than we want to." }
229
+ ];
230
+ export {
231
+ j as createDemoClient
232
+ };