pleasenobugs 0.4.0 → 0.5.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.
@@ -0,0 +1,240 @@
1
+ import { b as P, d as C } from "./client-C6NaBcR4.js";
2
+ import { D as _, c as S, l as O, a as N, i as L, b as A } from "./index-DNGYeoDU.js";
3
+ function U(s) {
4
+ return F(R(s)).slice(0, 12).replace(/\D/g, "0");
5
+ }
6
+ function R(s) {
7
+ return P(s).replace(/(.{4})(?=.)/g, "$1 ");
8
+ }
9
+ function F(s) {
10
+ const d = ("" + s.split("").map((f) => Number(f.charCodeAt(0)) + 3).reduce((f, h) => f * (1 - f) * I(h), 0.5)).split("").reduce((f, h) => h + f, "");
11
+ return d.replace(".", d[5]).substr(4, 17).padEnd(13, d[5]);
12
+ }
13
+ function I(s) {
14
+ let d = 1 / s;
15
+ for (let f = 0; f < 100; f++)
16
+ d = (1 - d) * d * 3.569956786876;
17
+ return d;
18
+ }
19
+ function z({
20
+ owner: s = !1,
21
+ samples: d,
22
+ identicons: f
23
+ } = {}) {
24
+ const h = Date.now();
25
+ let p = (d ?? j).map((t, e) => ({
26
+ id: `demo-${e}`,
27
+ kind: t.kind,
28
+ text: t.text,
29
+ at: h - (t.ago ?? g),
30
+ status: t.status ?? "open",
31
+ votes: t.votes ?? 1,
32
+ voted: !1,
33
+ // A visitor's own; an owner is never the author of a sample.
34
+ mine: !s && !!t.mine,
35
+ // A made-up wallet per name, so each sample author has an identicon of their
36
+ // own; the visitor's own posts (`mine`) carry the visitor's, also where the
37
+ // owner reads them, so one person has one picture on both sides.
38
+ ...t.who ? { who: t.who, face: t.mine ? D : U(`NQ00 ${t.who}`) } : {},
39
+ ...t.rating ? { rating: t.rating } : {},
40
+ ...q(e, t, h - (t.ago ?? g)),
41
+ ...t.fix ? { fix: { version: t.fix, link: $ } } : {},
42
+ // What the app sent along, which only owners see.
43
+ ...s && t.context ? { context: { ...t.context } } : {}
44
+ })), m = (d ? [] : H).map((t, e) => ({
45
+ id: `demo-update-${e}`,
46
+ title: t.title,
47
+ text: t.text,
48
+ version: t.version,
49
+ link: $,
50
+ at: h - t.ago,
51
+ posts: t.posts.map((o) => `demo-${o}`)
52
+ })), c, k = _.perDay;
53
+ const w = /* @__PURE__ */ new Map(), l = (t) => T({ ok: !0, data: t }), r = (t, e) => T({ ok: !1, status: t, error: e }), v = (t) => p.find((e) => e.id === t), y = (t, e) => {
54
+ e.length ? t.thread = e : delete t.thread;
55
+ const o = A(e);
56
+ o ? t.reply = o : delete t.reply;
57
+ }, M = (t) => s ? "app" : t.mine ? "author" : null;
58
+ return {
59
+ project: "demo",
60
+ canSign: !0,
61
+ address: () => E,
62
+ signIn: () => l(E),
63
+ signOut() {
64
+ },
65
+ // At once, without the wait: the tiles are there while the panel grows,
66
+ // instead of a spinner they replace halfway.
67
+ board: () => Promise.resolve({
68
+ ok: !0,
69
+ data: {
70
+ project: { id: "demo", name: "Demo app", rules: { ..._, kinds: [..._.kinds] } },
71
+ posts: p.map((t) => ({ ...t })),
72
+ me: { owner: s, left: k, face: D, short: b, ...c ? { name: c } : {} },
73
+ updates: m.length
74
+ }
75
+ }),
76
+ me: () => l({ owner: s, left: k, face: D, short: b, ...c ? { name: c } : {} }),
77
+ answers: () => l({ answers: [] }),
78
+ post(t) {
79
+ return k <= 0 ? r(429, "too_many") : t.kind === "review" && p.some((e) => e.mine && e.kind === "review") ? r(409, "reviewed") : (k -= 1, p = [
80
+ {
81
+ id: t.id,
82
+ kind: t.kind,
83
+ text: t.text,
84
+ at: Date.now(),
85
+ status: "open",
86
+ votes: 1,
87
+ voted: !0,
88
+ mine: !0,
89
+ ...t.anon ? {} : { face: D, ...c ? { who: c } : { short: b } },
90
+ ...t.kind === "review" ? { rating: t.rating } : {},
91
+ ...t.shot?.board ? { shot: !0 } : {}
92
+ },
93
+ ...p
94
+ ], t.shot?.board && w.set(t.id, `data:${t.shot.type};base64,${t.shot.data}`), l({ ok: !0, left: k }));
95
+ },
96
+ // The visitor's own screenshots on the board; nothing else exists here.
97
+ shot: async (t) => {
98
+ const e = w.get(t);
99
+ return e ? l(await (await fetch(e)).blob()) : r(404, "not_found");
100
+ },
101
+ shotUrl: (t) => w.get(t) ?? "",
102
+ // A server only to draw them, nothing else: without one, the card shows
103
+ // the stand-in in the identicon's colour.
104
+ faceUrl: (t) => f ? `${f.replace(/\/+$/, "")}/v1/identicons/${encodeURIComponent(t)}.svg` : "",
105
+ vote(t, e) {
106
+ const o = v(t);
107
+ return o ? (o.voted !== e && (o.votes += e ? 1 : -1), o.voted = e, l({ ok: !0, votes: o.votes, voted: o.voted })) : r(404, "not_found");
108
+ },
109
+ remove(t) {
110
+ const e = v(t);
111
+ return e ? (p = p.filter((o) => o !== e), w.delete(t), l({ ok: !0 })) : r(404, "not_found");
112
+ },
113
+ setName(t) {
114
+ c = t.trim() || void 0;
115
+ for (const e of p)
116
+ !e.mine || e.face === void 0 || (c ? (e.who = c, delete e.short) : (delete e.who, e.short = b));
117
+ return l({ ok: !0, ...c ? { name: c } : {} });
118
+ },
119
+ // As the server: one change for all of it, and a fix only on a done
120
+ // bug or idea, gone as soon as it stands anywhere else.
121
+ manage(t, e) {
122
+ if (!s) return r(403, "not_owner");
123
+ const o = v(t);
124
+ if (!o) return r(404, "not_found");
125
+ if (e.status && o.kind !== "review" && (o.status = e.status), e.reply !== void 0) {
126
+ const n = e.reply.trim(), i = o.thread ?? [], a = O(i);
127
+ n !== (A(i)?.text ?? "") && (a?.from === "app" ? y(
128
+ o,
129
+ n ? i.map((u) => u === a ? { ...u, text: n, edited: Date.now() } : u) : i.filter((u) => u !== a)
130
+ ) : n && y(o, [...i, { id: `reply-${Date.now()}`, from: "app", text: n, at: Date.now() }]));
131
+ }
132
+ 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;
133
+ else if (e.fix !== void 0) {
134
+ const n = e.fix && S(e.fix);
135
+ if (e.fix && !n) return r(400, "bad_request");
136
+ n && (n.version || n.link) ? o.fix = n : delete o.fix;
137
+ }
138
+ return l({ ok: !0 });
139
+ },
140
+ // The conversation, by the server's rules (see `authorMayAnswer`).
141
+ say(t, e) {
142
+ const o = v(t);
143
+ if (!o) return r(404, "not_found");
144
+ const n = M(o), i = e.text.trim();
145
+ if (!i || i.length > _.replyMax) return r(400, "bad_request");
146
+ if (!n) return r(403, "not_yours");
147
+ if (n === "author" && !N(o))
148
+ return r(409, o.kind === "review" || L(o.status) ? "closed" : "not_your_turn");
149
+ if (n === "app" && o.kind === "review" && o.thread?.some((u) => u.from === "app")) return r(409, "not_your_turn");
150
+ const a = { id: e.id, from: n, text: i, at: Date.now() };
151
+ return y(o, [...o.thread ?? [], a]), l({ ok: !0, message: a });
152
+ },
153
+ editMessage(t, e, o) {
154
+ const n = v(t), i = n?.thread?.find((u) => u.id === e);
155
+ if (!n || !i) return r(404, "not_found");
156
+ let a = { ...i };
157
+ if (o.hidden !== void 0) {
158
+ if (!s) return r(403, "not_owner");
159
+ if (i.from !== "author") return r(400, "bad_request");
160
+ o.hidden ? a.hidden = !0 : delete a.hidden;
161
+ }
162
+ if (o.text !== void 0) {
163
+ const u = o.text.trim();
164
+ if (!u || u.length > _.replyMax) return r(400, "bad_request");
165
+ if (M(n) !== i.from) return r(403, "not_yours");
166
+ if (O(n.thread)?.id !== i.id) return r(409, "not_your_turn");
167
+ u !== i.text && (a = { ...a, text: u, edited: Date.now() });
168
+ }
169
+ return y(n, (n.thread ?? []).map((u) => u === i ? a : u)), l({ ok: !0, message: a });
170
+ },
171
+ unsay(t, e) {
172
+ const o = v(t), n = o?.thread?.find((i) => i.id === e);
173
+ return !o || !n ? r(404, "not_found") : M(o) !== n.from ? r(403, "not_yours") : O(o.thread)?.id !== n.id ? r(409, "not_your_turn") : (y(o, (o.thread ?? []).filter((i) => i !== n)), l({ ok: !0 }));
174
+ },
175
+ // Only those whose posts are still here, like the server; at once, like
176
+ // the board, so the page is there to read rather than a spinner first.
177
+ updates: () => Promise.resolve({
178
+ ok: !0,
179
+ data: { updates: m.map((t) => ({ ...t, posts: t.posts.filter((e) => !!v(e)) })) }
180
+ }),
181
+ // The bugs and ideas it names go to done, with its version and link.
182
+ postUpdate(t) {
183
+ if (!s) return r(403, "not_owner");
184
+ const e = S({ version: t.version ?? "", link: t.link });
185
+ if (!t.title.trim() || !e?.link) return r(400, "bad_request");
186
+ const o = (t.posts ?? []).filter((i) => {
187
+ const a = v(i);
188
+ return a && a.kind !== "review";
189
+ });
190
+ for (const i of o) {
191
+ const a = v(i);
192
+ a.status = "done", a.fix = e;
193
+ }
194
+ const n = {
195
+ id: t.id,
196
+ title: t.title.trim(),
197
+ ...t.text?.trim() ? { text: t.text.trim() } : {},
198
+ ...e.version ? { version: e.version } : {},
199
+ link: e.link,
200
+ at: Date.now(),
201
+ posts: o
202
+ };
203
+ return m = [n, ...m], l({ ok: !0, update: n });
204
+ },
205
+ removeUpdate(t) {
206
+ return s ? m.some((e) => e.id === t) ? (m = m.filter((e) => e.id !== t), l({ ok: !0 })) : r(404, "not_found") : r(403, "not_owner");
207
+ }
208
+ };
209
+ }
210
+ const E = "NQ00 DEMO DEMO DEMO DEMO DEMO DEMO DEMO DEMO", D = U(E), b = C(E), $ = "https://github.com/lennylenders/PleaseNoBugs/releases";
211
+ function T(s) {
212
+ return new Promise((d) => setTimeout(() => d(s), 250));
213
+ }
214
+ const g = 36e5, x = 24 * g;
215
+ function q(s, d, f) {
216
+ const h = d.thread ?? (d.reply ? [["app", d.reply]] : []);
217
+ if (!h.length) return {};
218
+ const p = h.map(([c, k], w) => ({
219
+ id: `demo-${s}-m${w}`,
220
+ from: c,
221
+ text: k,
222
+ at: f + (w + 1) * 5 * 6e4
223
+ })), m = A(p);
224
+ return { thread: p, ...m ? { reply: m } : {} };
225
+ }
226
+ const H = [
227
+ { 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 * x, posts: [1] },
228
+ { title: "Opens faster", text: "About twice as fast on older phones.", version: "1.4.0", ago: 21 * x, posts: [] }
229
+ ], j = [
230
+ { kind: "idea", text: "A dark mode that follows my phone", votes: 24, ago: 6 * x, status: "planned", who: "Mira", reply: "On its way in the next release." },
231
+ { kind: "bug", text: "The send button does nothing after I switch accounts", votes: 17, ago: 2 * x, status: "done", fix: "1.4.2", reply: "Thanks for the steps, that made it easy to find." },
232
+ { kind: "review", text: "Fast, simple and it never asks me twice. Love it.", votes: 9, ago: 3 * x, rating: 5, who: "Joost" },
233
+ { kind: "idea", text: "Let me pin my favourite contacts to the top", votes: 12, ago: 4 * g, mine: !0, thread: [["app", "Good one! Pinned at the top of the list, or on a Favourites tab of their own?"]] },
234
+ { kind: "review", text: "Does what it says. The history screen could be clearer.", votes: 4, ago: 9 * x, rating: 4 },
235
+ { kind: "bug", text: "Amounts over 1,000 overlap the currency on small phones", votes: 6, ago: 20 * g, 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."]] },
236
+ { kind: "idea", text: "Export my history as a CSV file", votes: 3, ago: 12 * x, status: "declined", reply: "Not for now: it would mean storing more than we want to." }
237
+ ];
238
+ export {
239
+ z as createDemoClient
240
+ };