pleasenobugs 0.2.0 → 0.3.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 (39) hide show
  1. package/README.md +108 -30
  2. package/dist/chunks/demo-CL3oK-zC.js +212 -0
  3. package/dist/chunks/index--SJW3aE-.js +2749 -0
  4. package/dist/client.js +139 -107
  5. package/dist/index.js +9 -10
  6. package/dist/pleasenobugs.iife.js +2 -2
  7. package/dist/types/client.d.ts +59 -1
  8. package/dist/types/client.d.ts.map +1 -1
  9. package/dist/types/demo.d.ts +39 -3
  10. package/dist/types/demo.d.ts.map +1 -1
  11. package/dist/types/element.d.ts +17 -12
  12. package/dist/types/element.d.ts.map +1 -1
  13. package/dist/types/filter.d.ts +66 -0
  14. package/dist/types/filter.d.ts.map +1 -0
  15. package/dist/types/i18n.d.ts +212 -526
  16. package/dist/types/i18n.d.ts.map +1 -1
  17. package/dist/types/index.d.ts +4 -3
  18. package/dist/types/index.d.ts.map +1 -1
  19. package/dist/types/readonly.d.ts +1 -1
  20. package/dist/types/readonly.d.ts.map +1 -1
  21. package/dist/types/ui/App.d.ts +4 -3
  22. package/dist/types/ui/App.d.ts.map +1 -1
  23. package/dist/types/ui/Compose.d.ts +5 -4
  24. package/dist/types/ui/Compose.d.ts.map +1 -1
  25. package/dist/types/ui/Manage.d.ts +60 -0
  26. package/dist/types/ui/Manage.d.ts.map +1 -0
  27. package/dist/types/ui/PostCard.d.ts +50 -5
  28. package/dist/types/ui/PostCard.d.ts.map +1 -1
  29. package/dist/types/ui/Sheets.d.ts +32 -28
  30. package/dist/types/ui/Sheets.d.ts.map +1 -1
  31. package/dist/types/ui/Talk.d.ts +57 -0
  32. package/dist/types/ui/Talk.d.ts.map +1 -0
  33. package/dist/types/ui/Updates.d.ts +37 -0
  34. package/dist/types/ui/Updates.d.ts.map +1 -0
  35. package/dist/types/ui/icons.d.ts +16 -0
  36. package/dist/types/ui/icons.d.ts.map +1 -1
  37. package/package.json +3 -3
  38. package/dist/chunks/demo-nnvUgJyJ.js +0 -107
  39. package/dist/chunks/index-13DToKWI.js +0 -1751
package/dist/client.js CHANGED
@@ -1,37 +1,37 @@
1
- function L(e) {
2
- return e.replace(/\s+/g, "").toUpperCase();
1
+ function O(t) {
2
+ return t.replace(/\s+/g, "").toUpperCase();
3
3
  }
4
- const U = 30 * 24 * 60 * 60 * 1e3, A = 5 * 60 * 1e3;
5
- function D(e) {
4
+ const D = 30 * 24 * 60 * 60 * 1e3, z = 5 * 60 * 1e3;
5
+ function A(t) {
6
6
  return [
7
7
  "PleaseNoBugs login",
8
- `Project: ${e.project}`,
9
- `Origin: ${C(e.origin)}`,
10
- `Issued: ${new Date(e.issued).toISOString()}`
8
+ `Project: ${t.project}`,
9
+ `Origin: ${U(t.origin)}`,
10
+ `Issued: ${new Date(t.issued).toISOString()}`
11
11
  ].join(`
12
12
  `);
13
13
  }
14
- function C(e) {
14
+ function U(t) {
15
15
  try {
16
- return new URL(e).origin;
16
+ return new URL(t).origin;
17
17
  } catch {
18
- return e;
18
+ return t;
19
19
  }
20
20
  }
21
- function j(e, r = Date.now()) {
22
- return Number.isFinite(e) && e <= r + A && r - e <= U;
21
+ function C(t, r = Date.now()) {
22
+ return Number.isFinite(t) && t <= r + z && r - t <= D;
23
23
  }
24
- function G(e) {
25
- return `Nimiq ${M(JSON.stringify(e))}`;
24
+ function G(t) {
25
+ return `Nimiq ${M(JSON.stringify(t))}`;
26
26
  }
27
- function M(e) {
28
- const r = new TextEncoder().encode(e);
27
+ function M(t) {
28
+ const r = new TextEncoder().encode(t);
29
29
  let o = "";
30
30
  for (const i of r)
31
31
  o += String.fromCharCode(i);
32
32
  return btoa(o).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
33
33
  }
34
- const x = [
34
+ const R = [
35
35
  // Dutch
36
36
  "aan",
37
37
  "als",
@@ -111,186 +111,218 @@ const x = [
111
111
  // Every board is about an app
112
112
  "app"
113
113
  ];
114
- function B(e = []) {
115
- const r = /* @__PURE__ */ new Set([...x, ...[...e].map((n) => n.toLowerCase())]), o = /* @__PURE__ */ new WeakMap(), i = (n) => new Set(n.toLowerCase().replace(/[^\p{L}\p{N}\s]/gu, " ").split(/\s+/).filter((f) => f.length >= 4 && !r.has(f)));
116
- return function(f, m, p = 3) {
117
- const d = i(m);
118
- return d.size < 2 ? [] : f.map((s) => {
119
- let u = o.get(s);
120
- u || (u = i(s.text), o.set(s, u));
121
- let g = 0;
122
- for (const T of d)
123
- u.has(T) && g++;
124
- return { post: s, shared: g };
125
- }).filter((s) => s.shared >= 2).sort((s, u) => u.shared - s.shared || u.post.votes - s.post.votes).slice(0, p).map((s) => s.post);
114
+ function B(t = []) {
115
+ const r = /* @__PURE__ */ new Set([...R, ...[...t].map((n) => n.toLowerCase())]), o = /* @__PURE__ */ new WeakMap(), i = (n) => new Set(n.toLowerCase().replace(/[^\p{L}\p{N}\s]/gu, " ").split(/\s+/).filter((h) => h.length >= 4 && !r.has(h)));
116
+ return function(h, w, y = 3) {
117
+ const g = i(w);
118
+ return g.size < 2 ? [] : h.map((a) => {
119
+ let l = o.get(a);
120
+ l || (l = i(a.text), o.set(a, l));
121
+ let m = 0;
122
+ for (const I of g)
123
+ l.has(I) && m++;
124
+ return { post: a, shared: m };
125
+ }).filter((a) => a.shared >= 2).sort((a, l) => l.shared - a.shared || l.post.votes - a.post.votes).slice(0, y).map((a) => a.post);
126
126
  };
127
127
  }
128
- function H(e, r) {
129
- const o = [...e];
128
+ function H(t, r) {
129
+ const o = [...t];
130
130
  return r === "new" ? o.sort((i, n) => n.at - i.at) : o.sort((i, n) => n.votes - i.votes || n.at - i.at);
131
131
  }
132
- class $ extends Error {
132
+ class T extends Error {
133
133
  constructor(r, o) {
134
134
  super(o ?? r), this.reason = r, this.name = "SignerError";
135
135
  }
136
136
  }
137
- const J = 2e3;
138
- function R() {
137
+ const x = 2e3;
138
+ function J() {
139
139
  return typeof window < "u" && !!window.nimiq;
140
140
  }
141
- function F(e) {
141
+ function F(t) {
142
142
  return window.nimiq ? Promise.resolve(window.nimiq) : new Promise((r, o) => {
143
143
  const i = Date.now(), n = setInterval(() => {
144
- window.nimiq ? (clearInterval(n), r(window.nimiq)) : Date.now() - i > e && (clearInterval(n), o(new $("no_wallet", "Not running inside Nimiq Pay")));
144
+ window.nimiq ? (clearInterval(n), r(window.nimiq)) : Date.now() - i > t && (clearInterval(n), o(new T("no_wallet", "Not running inside Nimiq Pay")));
145
145
  }, 50);
146
146
  });
147
147
  }
148
- function K(e = J) {
148
+ function K(t = x) {
149
149
  return async (r) => {
150
- const o = await F(e), i = await o.listAccounts();
151
- if (!Array.isArray(i) || !i.length) throw new $("no_account");
150
+ const o = await F(t), i = await o.listAccounts();
151
+ if (!Array.isArray(i) || !i.length) throw new T("no_account");
152
152
  const n = await o.sign(r);
153
153
  if (!n || !("signature" in n))
154
- throw new $("declined", n && "error" in n ? n.error.message : void 0);
154
+ throw new T("declined", n && "error" in n ? n.error.message : void 0);
155
155
  return { address: i[0], publicKey: n.publicKey, signature: n.signature };
156
156
  };
157
157
  }
158
- function Q(e) {
159
- const r = e.server.replace(/\/+$/, ""), o = e.project, i = C(e.origin ?? (typeof location < "u" ? location.origin : "")), n = e.signer === null ? void 0 : e.signer ?? (R() ? K() : void 0), f = e.fetch ?? globalThis.fetch.bind(globalThis), m = e.storage === void 0 ? W() : e.storage, p = `pleasenobugs.proof.${o}.${i}`;
160
- let d = T(), s = null, u = !1;
161
- function g() {
162
- if (u || !e.appLogin) return null;
163
- const t = typeof e.appLogin == "function" ? e.appLogin() : e.appLogin;
164
- return t ? { ...t, origin: i, issued: 0 } : null;
158
+ function Q(t) {
159
+ const r = t.server.replace(/\/+$/, ""), o = t.project, i = U(t.origin ?? (typeof location < "u" ? location.origin : "")), n = t.signer === null ? void 0 : t.signer ?? (J() ? K() : void 0), h = t.fetch ?? globalThis.fetch.bind(globalThis), w = t.storage === void 0 ? W() : t.storage, y = `pleasenobugs.proof.${o}.${i}`;
160
+ let g = I(), a = null, l = !1;
161
+ function m() {
162
+ if (l || !t.appLogin) return null;
163
+ const e = typeof t.appLogin == "function" ? t.appLogin() : t.appLogin;
164
+ return e ? { ...e, origin: i, issued: 0 } : null;
165
165
  }
166
- function T() {
166
+ function I() {
167
167
  try {
168
- const t = m?.getItem(p);
169
- if (!t) return null;
170
- const a = JSON.parse(t);
171
- return j(a.issued) ? a : null;
168
+ const e = w?.getItem(y);
169
+ if (!e) return null;
170
+ const s = JSON.parse(e);
171
+ return C(s.issued) ? s : null;
172
172
  } catch {
173
173
  return null;
174
174
  }
175
175
  }
176
- function S(t) {
177
- d = t;
176
+ function S(e) {
177
+ g = e;
178
178
  try {
179
- t ? m?.setItem(p, JSON.stringify(t)) : m?.removeItem(p);
179
+ e ? w?.setItem(y, JSON.stringify(e)) : w?.removeItem(y);
180
180
  } catch {
181
181
  }
182
182
  }
183
183
  function q() {
184
- const t = g();
185
- return t || (d && !j(d.issued) && S(null), d);
184
+ const e = m();
185
+ return e || (g && !C(g.issued) && S(null), g);
186
186
  }
187
- function N() {
188
- const t = g();
189
- return t ? Promise.resolve({ ok: !0, data: L(t.address) }) : n ? s || (s = (async () => {
187
+ function E() {
188
+ const e = m();
189
+ return e ? Promise.resolve({ ok: !0, data: O(e.address) }) : n ? a || (a = (async () => {
190
190
  try {
191
- const a = Date.now(), c = await n(D({ project: o, origin: i, issued: a }));
192
- return S({ ...c, origin: i, issued: a }), { ok: !0, data: L(c.address) };
193
- } catch (a) {
194
- return a instanceof $ && a.reason === "no_wallet" ? { ok: !1, status: 0, error: "no_signer" } : { ok: !1, status: 0, error: "declined" };
191
+ const s = Date.now(), c = await n(A({ project: o, origin: i, issued: s }));
192
+ return S({ ...c, origin: i, issued: s }), { ok: !0, data: O(c.address) };
193
+ } catch (s) {
194
+ return s instanceof T && s.reason === "no_wallet" ? { ok: !1, status: 0, error: "no_signer" } : { ok: !1, status: 0, error: "declined" };
195
195
  } finally {
196
- s = null;
196
+ a = null;
197
197
  }
198
- })(), s) : Promise.resolve({ ok: !1, status: 0, error: "no_signer" });
198
+ })(), a) : Promise.resolve({ ok: !1, status: 0, error: "no_signer" });
199
199
  }
200
- async function l(t, a, c) {
201
- const I = async (v) => {
202
- const _ = {};
203
- c.body !== void 0 && (_["content-type"] = "application/json"), v && (_.authorization = G(v));
204
- let w;
200
+ async function u(e, s, c) {
201
+ const $ = async (v) => {
202
+ const L = {};
203
+ c.body !== void 0 && (L["content-type"] = "application/json"), v && (L.authorization = G(v));
204
+ let p;
205
205
  try {
206
- w = await f(`${r}${a}`, {
207
- method: t,
208
- headers: _,
206
+ p = await h(`${r}${s}`, {
207
+ method: e,
208
+ headers: L,
209
209
  ...c.body !== void 0 ? { body: JSON.stringify(c.body) } : {}
210
210
  });
211
211
  } catch {
212
212
  return { ok: !1, status: 0, error: "network" };
213
213
  }
214
- if (w.ok && c.blob) {
215
- const E = await w.blob().catch(() => null);
216
- return E ? { ok: !0, data: E } : { ok: !1, status: 0, error: "network" };
214
+ if (p.ok && c.blob) {
215
+ const _ = await p.blob().catch(() => null);
216
+ return _ ? { ok: !0, data: _ } : { ok: !1, status: 0, error: "network" };
217
217
  }
218
- const k = await w.json().catch(() => null);
219
- if (w.ok) return { ok: !0, data: k };
220
- const z = k && typeof k.error == "string" ? k.error : "internal";
221
- return { ok: !1, status: w.status, error: z, body: k };
218
+ const k = await p.json().catch(() => null);
219
+ if (p.ok) return { ok: !0, data: k };
220
+ const j = k && typeof k.error == "string" ? k.error : "internal";
221
+ return { ok: !1, status: p.status, error: j, body: k };
222
222
  };
223
- if (c.auth === "none") return I(null);
223
+ if (c.auth === "none") return $(null);
224
224
  let b = q();
225
225
  if (!b && c.auth === "required") {
226
- const v = await N();
226
+ const v = await E();
227
227
  if (!v.ok) return v;
228
228
  b = q();
229
229
  }
230
- const P = await I(b);
230
+ const P = await $(b);
231
231
  if (P.ok || P.status !== 401 || !b) return P;
232
- if (b.message !== void 0 ? u = !0 : S(null), c.auth === "optional") return I(null);
233
- const O = await N();
234
- return O.ok ? I(q()) : O;
232
+ if (b.message !== void 0 ? l = !0 : S(null), c.auth === "optional") return $(null);
233
+ const N = await E();
234
+ return N.ok ? $(q()) : N;
235
235
  }
236
- const h = (t = "") => `/v1/projects/${encodeURIComponent(o)}${t}`, y = (t) => h(`/posts/${encodeURIComponent(t)}`);
236
+ const d = (e = "") => `/v1/projects/${encodeURIComponent(o)}${e}`, f = (e) => d(`/posts/${encodeURIComponent(e)}`);
237
237
  return {
238
238
  /** The project this client talks to. */
239
239
  project: o,
240
240
  /** Whether the user can be signed in at all: a signer, or an app login. */
241
241
  get canSign() {
242
- return !!n || g() !== null;
242
+ return !!n || m() !== null;
243
243
  },
244
244
  /** The signed-in address, if a proof is stored. */
245
245
  address() {
246
- const t = q();
247
- return t ? L(t.address) : null;
246
+ const e = q();
247
+ return e ? O(e.address) : null;
248
248
  },
249
- signIn: N,
249
+ signIn: E,
250
250
  /** Forget the stored proof. The next write asks the wallet again. */
251
251
  signOut() {
252
252
  S(null);
253
253
  },
254
254
  /** The whole board, plus `me` when signed in. Never prompts. */
255
- board: () => l("GET", h("/posts"), { auth: "optional" }),
256
- me: () => l("GET", h("/me"), { auth: "required" }),
257
- answers: () => l("GET", h("/answers"), { auth: "required" }),
255
+ board: () => u("GET", d("/posts"), { auth: "optional" }),
256
+ me: () => u("GET", d("/me"), { auth: "required" }),
257
+ answers: () => u("GET", d("/answers"), { auth: "required" }),
258
258
  /**
259
259
  * Write one. A review needs `rating` (1 to 5); a bug or an idea may carry
260
260
  * `shot`, a screenshot as base64. It goes on the board for everyone only
261
261
  * with `board: true`, which says the user agreed; without it only the
262
262
  * project's owners see it.
263
263
  */
264
- post: (t) => l("POST", h("/posts"), { body: t, auth: "required" }),
264
+ post: (e) => u("POST", d("/posts"), { body: e, auth: "required" }),
265
265
  /** A post's screenshot: anybody's for one on the board, owners' for any. */
266
- shot: (t) => l("GET", `${y(t)}/shot`, { auth: "optional", blob: !0 }),
266
+ shot: (e) => u("GET", `${f(e)}/shot`, { auth: "optional", blob: !0 }),
267
267
  /**
268
268
  * Where a screenshot on the board can be read without a proof, for an
269
269
  * `<img>` to load by itself.
270
270
  */
271
- shotUrl: (t) => `${r}${y(t)}/shot`,
272
- vote: (t, a) => l("POST", `${y(t)}/vote`, {
273
- body: { up: a },
271
+ shotUrl: (e) => `${r}${f(e)}/shot`,
272
+ vote: (e, s) => u("POST", `${f(e)}/vote`, {
273
+ body: { up: s },
274
274
  auth: "required"
275
275
  }),
276
- remove: (t) => l("DELETE", y(t), { auth: "required" }),
277
- setName: (t) => l("PUT", h("/me"), { body: { name: t }, auth: "required" }),
278
- manage: (t, a) => l("POST", `${y(t)}/manage`, { body: a, auth: "required" })
276
+ remove: (e) => u("DELETE", f(e), { auth: "required" }),
277
+ setName: (e) => u("PUT", d("/me"), { body: { name: e }, auth: "required" }),
278
+ /**
279
+ * An owner answering a post. `fix` says where the fix is, on a bug or an
280
+ * idea set to done: `{ version?, link? }`, the link on github.com or
281
+ * gitlab.com. Moving a post away from done takes its fix away by itself.
282
+ */
283
+ manage: (e, s) => u("POST", `${f(e)}/manage`, { body: s, auth: "required" }),
284
+ /**
285
+ * Write under a post: an owner for the app, whenever they like; its
286
+ * author only right after the app, on a bug or an idea that is not done
287
+ * (`not_your_turn`, `closed` otherwise). `message.id` is yours to mint.
288
+ */
289
+ say: (e, s) => u("POST", `${f(e)}/messages`, { body: s, auth: "required" }),
290
+ /**
291
+ * Change your own last message before anybody answered it (`text`), or,
292
+ * as an owner, take an author's message off the board or put it back
293
+ * (`hidden`).
294
+ */
295
+ editMessage: (e, s, c) => u("PATCH", `${f(e)}/messages/${encodeURIComponent(s)}`, {
296
+ body: c,
297
+ auth: "required"
298
+ }),
299
+ /** Take your own last message back, before anybody answered it. */
300
+ unsay: (e, s) => u("DELETE", `${f(e)}/messages/${encodeURIComponent(s)}`, { auth: "required" }),
301
+ /** What changed in the app, newest first. Anybody's to read; never prompts. */
302
+ updates: () => u("GET", d("/updates"), { auth: "optional" }),
303
+ /**
304
+ * An owner writing one. `link` is a page on github.com or gitlab.com;
305
+ * `posts` are the bugs and ideas it fixed, which go to done with its
306
+ * version and link.
307
+ */
308
+ postUpdate: (e) => u("POST", d("/updates"), { body: e, auth: "required" }),
309
+ /** An owner taking one off the page. The posts it fixed stay done. */
310
+ removeUpdate: (e) => u("DELETE", d(`/updates/${encodeURIComponent(e)}`), { auth: "required" })
279
311
  };
280
312
  }
281
313
  function W() {
282
314
  try {
283
- const e = globalThis.localStorage, r = "__pleasenobugs__";
284
- return e.setItem(r, "1"), e.removeItem(r), e;
315
+ const t = globalThis.localStorage, r = "__pleasenobugs__";
316
+ return t.setItem(r, "1"), t.removeItem(r), t;
285
317
  } catch {
286
318
  return null;
287
319
  }
288
320
  }
289
321
  export {
290
- $ as SignerError,
322
+ T as SignerError,
291
323
  Q as createClient,
292
324
  B as createMatcher,
293
- R as insideNimiqPay,
325
+ J as insideNimiqPay,
294
326
  K as nimiqPaySigner,
295
327
  H as sortPosts
296
328
  };
package/dist/index.js CHANGED
@@ -1,13 +1,12 @@
1
- import { P as a, o, r as i } from "./chunks/index-13DToKWI.js";
2
- import { SignerError as t, createClient as n, createMatcher as m, insideNimiqPay as P, nimiqPaySigner as l, sortPosts as c } from "./client.js";
1
+ import { P as o, o as i } from "./chunks/index--SJW3aE-.js";
2
+ import { SignerError as a, createClient as s, createMatcher as n, insideNimiqPay as m, nimiqPaySigner as P, sortPosts as c } from "./client.js";
3
3
  export {
4
- a as PleaseNoBugsElement,
5
- t as SignerError,
6
- n as createClient,
7
- m as createMatcher,
8
- P as insideNimiqPay,
9
- l as nimiqPaySigner,
10
- o as open,
11
- i as readableOn,
4
+ o as PleaseNoBugsElement,
5
+ a as SignerError,
6
+ s as createClient,
7
+ n as createMatcher,
8
+ m as insideNimiqPay,
9
+ P as nimiqPaySigner,
10
+ i as open,
12
11
  c as sortPosts
13
12
  };