create-heresay 0.2.46 → 0.2.48

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-heresay",
3
- "version": "0.2.46",
3
+ "version": "0.2.48",
4
4
  "description": "Set up your own Heresay: in-app feedback that every report gets a hearing. Creates a Firebase project in your Google account and deploys the dashboard, API and SDK to it.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/release/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.46
1
+ 0.2.48
@@ -425,6 +425,10 @@ async function submit(req, deps) {
425
425
  const { project, headers } = got;
426
426
  if (!validDeviceId(body.device_id))
427
427
  return json(400, { error: 'bad device_id' }, headers);
428
+ // Sent by the SDK itself after a crash: always Broken (never the client's say), marked as such.
429
+ const auto = body.auto === 'crash';
430
+ if (auto)
431
+ body.type = 'broken';
428
432
  if (!isReportType(body.type)) {
429
433
  // Refused, never defaulted: the type is the one thing the reporter judged, and it sets
430
434
  // the order the developer reads in.
@@ -449,6 +453,7 @@ async function submit(req, deps) {
449
453
  id: newId('r_'), project_id: project.id, device_id: body.device_id, type: body.type, text,
450
454
  context: parseContext(body.context), reporter: parseReporter(body.reporter), trail: parseTrail(body.trail),
451
455
  status: 'open', decline_reason: null, fix_note: null, created_at: at, updated_at: at, triaged_by: null,
456
+ ...(auto ? { source: 'crash' } : {}),
452
457
  };
453
458
  await deps.store.createReport(report);
454
459
  await markSeen(project, req, body, deps);
@@ -458,7 +463,7 @@ async function submit(req, deps) {
458
463
  if (!project.framework && report.context.framework && !fromSelf) {
459
464
  await deps.store.updateProject(project.id, { framework: report.context.framework, framework_detected: true });
460
465
  }
461
- deps.log('api.report_created', { project_id: project.id, report_id: report.id, type: report.type });
466
+ deps.log('api.report_created', { project_id: project.id, report_id: report.id, type: report.type, ...(auto ? { auto: 'crash' } : {}) });
462
467
  await notify('new_report', project, report.id, deps);
463
468
  return json(201, { report: toReporterView(report) }, headers);
464
469
  }
@@ -1,3 +1,3 @@
1
1
  /** The Heresay release. Bumped by the release script; the CLI and /v1/health report it. */
2
- export const VERSION = '0.2.46';
2
+ export const VERSION = '0.2.48';
3
3
  //# sourceMappingURL=version.js.map
@@ -2,7 +2,7 @@
2
2
  --broken:#b3261e; --confusing:#8a5100; --improvement:#2d5da8; --idea:#6b4fa8;
3
3
  --edge:#cfd4da; --chip:#eceef1; --faint:#8b93a1; --ink:#15171c;
4
4
  --t-broken:#fbeceb; --t-confusing:#fbf1e3; --t-improvement:#eaf0fa; --t-idea:#f1edf9;
5
- --chat-bg:#eef2ff; --chat-fg:#3730a3; --agent-bg:#fef3c7; --agent-fg:#92400e; --sug-bg:#fff7ed; --sug-fg:#7c2d12; --ver-bg:#dcfce7; --ver-fg:#166534;
5
+ --chat-bg:#eef2ff; --chat-fg:#3730a3; --agent-bg:#fef3c7; --agent-fg:#92400e; --crash-bg:#ffe4e6; --crash-fg:#9f1239; --sug-bg:#fff7ed; --sug-fg:#7c2d12; --ver-bg:#dcfce7; --ver-fg:#166534;
6
6
  color-scheme:light;
7
7
  --head:"Bricolage Grotesque", system-ui, sans-serif; --mono:"JetBrains Mono", ui-monospace, monospace; }
8
8
  * { box-sizing:border-box; }
@@ -445,6 +445,7 @@ a.platform:hover { border-color:var(--acc); box-shadow:0 0 0 3px var(--mist); }
445
445
  .src-sdk { --src-bg:var(--mist); --src-fg:var(--deep); }
446
446
  .src-chat { --src-bg:var(--chat-bg); --src-fg:var(--chat-fg); }
447
447
  .src-agent { --src-bg:var(--agent-bg); --src-fg:var(--agent-fg); }
448
+ .src-crash { --src-bg:var(--crash-bg); --src-fg:var(--crash-fg); }
448
449
  .src-label { color:var(--src-fg); font-weight:600; }
449
450
  .src-label::before { content:''; display:inline-block; width:6px; height:6px; border-radius:50%; background:currentColor; margin-right:5px; vertical-align:1px; }
450
451
 
@@ -1336,7 +1336,7 @@
1336
1336
  advanced.appendChild(el('label', {}, ['Type ', el('select', { 'aria-label': 'Report type', onchange: function () { type = this.value; render(); } },
1337
1337
  [el('option', { value: 'all', text: 'All types' })].concat(Object.keys(TYPE_LABEL).map(function (t) { return el('option', { value: t, text: TYPE_LABEL[t] }); })))]));
1338
1338
  advanced.appendChild(el('label', {}, ['Source ', el('select', { 'aria-label': 'Report source', onchange: function () { source = this.value; render(); } },
1339
- [['all', 'All sources'], ['sdk', 'In-app'], ['chat', 'Chat apps'], ['agent', 'Agents']].map(function (t) { return el('option', { value: t[0], text: t[1] }); }))]));
1339
+ [['all', 'All sources'], ['sdk', 'In-app'], ['crash', 'Crashes'], ['chat', 'Chat apps'], ['agent', 'Agents']].map(function (t) { return el('option', { value: t[0], text: t[1] }); }))]));
1340
1340
  var heading = el('h1', { text: p ? productName(p) : 'Inbox' });
1341
1341
  var controls = el('div', { class: 'inbox-controls' }, [productSelect, platformSelect, filterButton]);
1342
1342
  var productTools = el('details', { class: 'inbox-app-tools', hidden: !p }, [el('summary', { text: 'Manage app' })]);
@@ -1642,8 +1642,8 @@
1642
1642
  }
1643
1643
 
1644
1644
  // Where a report came from, worded and coloured the same in the list and on the report.
1645
- function sourceLabel(r) { return r.source === 'agent' ? 'From an agent' : r.source === 'chat' ? 'From ' + (r.via || 'a chat app') : 'From the app'; }
1646
- function fromApp(r) { return (r.source || 'sdk') === 'sdk'; }
1645
+ function sourceLabel(r) { return r.source === 'agent' ? 'From an agent' : r.source === 'chat' ? 'From ' + (r.via || 'a chat app') : r.source === 'crash' ? 'Sent automatically after a crash' : 'From the app'; }
1646
+ function fromApp(r) { var s = r.source || 'sdk'; return s === 'sdk' || s === 'crash'; }
1647
1647
  function sourceTag(r, cls) { return el('span', { class: cls + ' src-' + (r.source || 'sdk'), text: sourceLabel(r) }); }
1648
1648
 
1649
1649
  function deviceView(c) {
@@ -1,51 +1,118 @@
1
1
  {
2
2
  "about": "Features added to Heresay since apps were first installed. An agent in a connected repo checks these with whats_new, tells the person what's new, and asks before adding any. `detect` is what the code contains once a feature is in; `platforms` limits it to those apps; `sign_in` limits it to apps that answered that.",
3
3
  "changes": [
4
+ {
5
+ "id": "crash-reports",
6
+ "since": "0.2.48",
7
+ "title": "Get crash reports without anyone sending them",
8
+ "summary": "With crashReports: .send, a Mac or iOS app reports a run that ended badly (a crash, a hang, running out of memory, a force quit) by itself at the next launch, with what happened before it and how it crashed. It arrives even when the app crashes on every launch, as long as Heresay.configure runs first. It waits in the inbox for a person like any report. Off until the app turns it on; it sends diagnostics without asking, so the app's privacy details should say so.",
9
+ "platforms": [
10
+ "ios",
11
+ "macos"
12
+ ],
13
+ "detect": [
14
+ "crashReports:"
15
+ ],
16
+ "how": {
17
+ "ios": "guide customize-apple, Crash reports",
18
+ "macos": "guide customize-apple, Crash reports"
19
+ }
20
+ },
4
21
  {
5
22
  "id": "nudge",
6
23
  "since": "0.2.21",
7
24
  "title": "Offer help when someone seems stuck",
8
25
  "summary": "A small note by the Report button asks “Something not working?” when someone presses a button again and again with nothing happening, hits an error right after a click, or sees requests fail (web), clicks a disabled control again and again (macOS), or comes back after a crash (iOS and macOS). And “Stuck on something?” when someone seems unsure: typing that stopped, going back and forth between the same few pages or screens, a field refused again and again. It opens the form as Broken or Confusing, with what happened attached. Watched on the device, never sent; once per visit, and quiet for a week after “Not now”. Off until the app turns it on.",
9
- "platforms": ["web", "ios", "macos"],
10
- "detect": ["data-nudge", "nudge:", "nudge()"],
11
- "how": { "web": "guide customize-web, Offering help", "ios": "guide customize-apple, Offering help", "macos": "guide customize-apple, Offering help" }
26
+ "platforms": [
27
+ "web",
28
+ "ios",
29
+ "macos"
30
+ ],
31
+ "detect": [
32
+ "data-nudge",
33
+ "nudge:",
34
+ "nudge()"
35
+ ],
36
+ "how": {
37
+ "web": "guide customize-web, Offering help",
38
+ "ios": "guide customize-apple, Offering help",
39
+ "macos": "guide customize-apple, Offering help"
40
+ }
12
41
  },
13
42
  {
14
43
  "id": "design-apple",
15
44
  "since": "0.2.11",
16
45
  "title": "Make Heresay fit the app",
17
46
  "summary": "The Swift package takes a HeresayStyle: another corner or clear a tab bar, say “Feedback” instead of “Report”, a quieter button, the app's light or dark theme, French, Tamil or Hindi, a half-height or full-screen sheet, or only some report types. The dashboard's Design page shows each choice and gives the Swift.",
18
- "platforms": ["ios", "macos"],
19
- "detect": ["HeresayStyle("],
20
- "how": { "ios": "guide customize-apple", "macos": "guide customize-apple" }
47
+ "platforms": [
48
+ "ios",
49
+ "macos"
50
+ ],
51
+ "detect": [
52
+ "HeresayStyle("
53
+ ],
54
+ "how": {
55
+ "ios": "guide customize-apple",
56
+ "macos": "guide customize-apple"
57
+ }
21
58
  },
22
59
  {
23
60
  "id": "design-web",
24
61
  "since": "0.2.11",
25
62
  "title": "Make the Report button fit the app",
26
63
  "summary": "The web widget can take the app's colour (the logo follows it), sit in another corner or clear a chat bubble, say “Feedback” instead of “Report”, follow the app's light or dark theme, speak French, Tamil or Hindi, or have no floating button when the app has its own feedback menu item. The dashboard's Design page shows each choice on the real widget.",
27
- "platforms": ["web"],
28
- "detect": ["data-accent", "data-hide-on", "data-backdrop", "data-preferences"],
29
- "how": { "web": "guide customize-web" }
64
+ "platforms": [
65
+ "web"
66
+ ],
67
+ "detect": [
68
+ "data-accent",
69
+ "data-hide-on",
70
+ "data-backdrop",
71
+ "data-preferences"
72
+ ],
73
+ "how": {
74
+ "web": "guide customize-web"
75
+ }
30
76
  },
31
77
  {
32
78
  "id": "introduce",
33
79
  "since": "0.2.7",
34
80
  "title": "Tell people Heresay is there",
35
81
  "summary": "A one-time introduction, so the people using the app know they can report things. On macOS it names Help › Report a Problem… (⌥⌘R), on iOS the Report button, on the web a bubble over the button. Shown once per device.",
36
- "platforms": ["web", "ios", "macos"],
37
- "detect": ["introduce(", "data-intro"],
38
- "how": { "web": "guide install-web, step 4", "ios": "guide install-apple, step 5", "macos": "guide install-apple, step 5" }
82
+ "platforms": [
83
+ "web",
84
+ "ios",
85
+ "macos"
86
+ ],
87
+ "detect": [
88
+ "introduce(",
89
+ "data-intro"
90
+ ],
91
+ "how": {
92
+ "web": "guide install-web, step 4",
93
+ "ios": "guide install-apple, step 5",
94
+ "macos": "guide install-apple, step 5"
95
+ }
39
96
  },
40
97
  {
41
98
  "id": "identify-email",
42
99
  "since": "0.2.6",
43
100
  "title": "Signed-in people are never asked who they are",
44
101
  "summary": "When the app tells Heresay who is signed in (id, name, email), the report form stops asking for a name and email, and the team can reply to them.",
45
- "platforms": ["web", "ios", "macos"],
102
+ "platforms": [
103
+ "web",
104
+ "ios",
105
+ "macos"
106
+ ],
46
107
  "sign_in": "yes",
47
- "detect": ["identify("],
48
- "how": { "web": "guide install-web, step 3", "ios": "guide install-apple, step 4", "macos": "guide install-apple, step 4" }
108
+ "detect": [
109
+ "identify("
110
+ ],
111
+ "how": {
112
+ "web": "guide install-web, step 3",
113
+ "ios": "guide install-apple, step 4",
114
+ "macos": "guide install-apple, step 4"
115
+ }
49
116
  }
50
117
  ]
51
118
  }
@@ -83,6 +83,27 @@ asked.
83
83
  | --- | --- |
84
84
  | `configure(…, nudge:)` | `[]` (default, off) · `.all` · `.clicks` (macOS: a disabled control clicked 3 times in 10 s, or one spot clicked 5 times in 2 s; leave it out for games and drawing apps) · `.crash` (the app crashed last time; once, at the next launch) · `.circles` (6 screen changes in a minute among at most 3 screens; needs named screens) · `.stalled` (typed, then 45 s still editing with nothing more: the keyboard still up on iOS; search fields don't count). The last two say "Stuck on something?" and open as Confusing. |
85
85
 
86
+ **Crash reports**
87
+
88
+ Off by default: a crash waits on the device and goes with the next report someone sends. Turn on
89
+ `crashReports: .send` when the team wants every crash, including ones nobody reports, for example
90
+ an app that crashes on launch for some people:
91
+
92
+ ```swift
93
+ Heresay.configure(key: "KEY", url: URL(string: "HERESAY_URL")!, crashReports: .send)
94
+ ```
95
+
96
+ At the next launch after a run that ended badly (a crash, a hang the system killed, running out
97
+ of memory, a force quit), Heresay reports it as Broken, with that run's last five minutes, the
98
+ app's logged errors and, once macOS or iOS hands it over, how it crashed. It shows in the inbox as
99
+ "Sent automatically after a crash" and waits for a person like any report. Once per bad run, at
100
+ most three a day per device. It goes as a background upload, so it arrives even if the app
101
+ crashes again straight away, as long as `configure` runs first: keep it the first line of the
102
+ `App`'s `init`, before anything that could crash.
103
+
104
+ It sends diagnostics without asking, so tell the person: their privacy policy should say so, and
105
+ on the App Store their privacy details should list Crash Data and Other Diagnostic Data.
106
+
86
107
  Screens make the trail readable: if the app has several screens and doesn't name them yet, add
87
108
  `.heresayScreen("<name>")` to each screen's root view.
88
109
 
package/src/cli.mjs CHANGED
@@ -61,7 +61,8 @@ const HELP = `
61
61
 
62
62
  Setup flags, to skip questions:
63
63
  --name <name> --project-id <id> --region us-central1|asia-south1|europe-west1
64
- --billing <account> --owner <email> --yes (take every default, never ask)
64
+ --billing <account> --owner <email> --site <name> (your address: <name>.web.app)
65
+ --yes (take every default, never ask)
65
66
 
66
67
  Free plan, no billing (Spark): the API runs on a host you choose instead of Cloud Functions.
67
68
  --lite --origin https://your-host.example see docs/lite.md
@@ -92,9 +93,12 @@ function openInBrowser(target) {
92
93
  }
93
94
 
94
95
  /** The named Hosting site a saved Heresay lives on, from its saved address. */
95
- const savedSite = (rec) => /^https:\/\/([a-z0-9-]+)\.web\.app$/.exec(rec?.url ?? '')?.[1];
96
+ const savedSite = (id, rec) => {
97
+ const site = /^https:\/\/([a-z0-9-]+)\.web\.app$/.exec(rec?.url ?? '')?.[1];
98
+ return site && site !== id ? site : undefined; // the project's default site isn't a named one
99
+ };
96
100
  const savedCtx = (id, rec) => ({ id, name: rec.name, region: rec.region, billing: rec.billing, owner: rec.owner,
97
- lite: rec.lite, origin: rec.origin, site: savedSite(rec), onlySite: rec.only_site });
101
+ lite: rec.lite, origin: rec.origin, site: savedSite(id, rec), onlySite: rec.only_site });
98
102
 
99
103
  const slug = (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
100
104
  function suggestId(name) {
@@ -187,7 +191,7 @@ async function setup(args) {
187
191
  'This sets up your own Heresay in your Google account:',
188
192
  '',
189
193
  ` ${peacock('•')} A new Firebase project, owned by you`,
190
- ` ${peacock('•')} Its database, sign-in and hosting`,
194
+ ` ${peacock('•')} Its database, sign-in, and an address like heresay-<name>.web.app`,
191
195
  ` ${peacock('•')} The Heresay dashboard, API and SDK, deployed to it`,
192
196
  '',
193
197
  'Heresay’s API runs on Cloud Functions, which needs Firebase’s',
@@ -242,7 +246,9 @@ async function setup(args) {
242
246
  validate: (v) => (!v || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v) ? undefined : 'That isn’t an email address'),
243
247
  })));
244
248
 
245
- ctx = { id, name, region, billing, owner, version, account: email, lite, origin };
249
+ const askedSite = args.site ? String(args.site).toLowerCase() : undefined;
250
+ if (askedSite && !steps.validSite(askedSite)) { p.log.error(`${askedSite} can’t be an address: 6 to 30 lowercase letters, digits and dashes, starting with a letter.`); process.exit(1); }
251
+ ctx = { id, name, region, billing, owner, version, account: email, lite, origin, askedSite };
246
252
  state.update(id, { name, region, billing, owner, lite, origin, url: lite ? origin : url(id), created_at: new Date().toISOString(), done: {} });
247
253
  if (!args.yes) p.log.message(pc.dim('You can add teammates in the dashboard later.'));
248
254
  }
@@ -326,6 +332,7 @@ const BUILD = [
326
332
  ['project', 'Creating the project', 'Project created', steps.project],
327
333
  ['billing', 'Linking billing', 'Billing linked', steps.billing],
328
334
  ['services', 'Switching on services', 'Services switched on', steps.services],
335
+ ['site', 'Choosing your address', 'Address reserved', steps.site],
329
336
  ['database', 'Creating the database', 'Database created', steps.database],
330
337
  ['signin', 'Setting up sign-in', 'Sign-in set up', steps.signIn],
331
338
  ['owner', 'Adding you as owner', 'Owner added', steps.owner],
@@ -361,6 +368,7 @@ async function build(ctx, only) {
361
368
  const secs = Math.round((Date.now() - started) / 1000);
362
369
  s.stop(`${title.padEnd(22)} ${pc.dim(String(detail ?? ''))}${secs > 20 ? pc.dim(` (${secs}s)`) : ''}`);
363
370
  state.markDone(ctx.id, key);
371
+ if (key === 'site' && ctx.site) state.update(ctx.id, { url: `https://${ctx.site}.web.app` });
364
372
  if (key === 'signin' && ctx.googleError) {
365
373
  p.log.warn(`Google sign-in couldn’t be switched on (${ctx.googleError}). Email links work. To add Google later: https://console.firebase.google.com/project/${ctx.id}/authentication/providers`);
366
374
  }
package/src/steps.mjs CHANGED
@@ -112,6 +112,65 @@ export async function services(ctx, say) {
112
112
  return 'Firestore, Functions, Auth, Hosting';
113
113
  }
114
114
 
115
+ // ---- 3b. address ------------------------------------------------------------------------
116
+ //
117
+ // The project id carries a random tail (heresay-acme-7k2q) because project ids are global and
118
+ // permanent. The address people type and paste into their apps shouldn't: a named Hosting site
119
+ // gives heresay-acme.web.app, and it can later move to another project without changing.
120
+
121
+ const HOSTING = 'https://firebasehosting.googleapis.com/v1beta1';
122
+
123
+ /** Site names to try, best first: the one asked for, else heresay-<name>, then with the project's tail. */
124
+ export function siteCandidates(name, id, asked) {
125
+ if (asked) return [asked];
126
+ const slug = String(name ?? '').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
127
+ // Shorten the name, never the suffix, and never leave a dangling or doubled dash.
128
+ const join = (...parts) => {
129
+ const suffix = parts.slice(1).join('-');
130
+ const room = 30 - (suffix ? suffix.length + 1 : 0);
131
+ const head = parts[0].slice(0, room).replace(/-+$/, '');
132
+ return (suffix ? `${head}-${suffix}` : head).replace(/-{2,}/g, '-');
133
+ };
134
+ const base = join(slug ? `heresay-${slug}` : 'heresay');
135
+ const out = [base, join(base, 'team'), join(base, id.split('-').pop())].filter((c) => validSite(c));
136
+ return [...new Set(out)];
137
+ }
138
+ export const validSite = (s) => /^[a-z][a-z0-9-]{4,28}[a-z0-9]$/.test(s);
139
+
140
+ /** True if created, false if the name is taken (by anyone). Retries only while Hosting is still switching on. */
141
+ async function createSite(project, siteId) {
142
+ const until = Date.now() + 90_000;
143
+ for (;;) {
144
+ try {
145
+ await g('POST', `${HOSTING}/projects/${project}/sites?siteId=${siteId}`, { project, body: {} });
146
+ return true;
147
+ } catch (e) {
148
+ if (e.status === 409 || /already exists|unavailable|not available|taken|reserved/i.test(e.message)) return false;
149
+ if ((e.status === 403 || e.status === 404) && Date.now() < until) { await new Promise((r) => setTimeout(r, 5000)); continue; }
150
+ throw e;
151
+ }
152
+ }
153
+ }
154
+
155
+ export async function site(ctx, say) {
156
+ if (ctx.site) {
157
+ const mine = await g('GET', `${HOSTING}/projects/${ctx.id}/sites/${ctx.site}`, { project: ctx.id, missingOk: true });
158
+ if (mine) return `${ctx.site}.web.app`;
159
+ }
160
+ const tried = [];
161
+ for (const c of siteCandidates(ctx.name, ctx.id, ctx.askedSite)) {
162
+ say(`Reserving ${c}.web.app`);
163
+ // Ours already (a run that stopped right after reserving it): use it, don't count it as taken.
164
+ const ours = await g('GET', `${HOSTING}/projects/${ctx.id}/sites/${c}`, { project: ctx.id, missingOk: true }).catch(() => null);
165
+ if (ours || await createSite(ctx.id, c)) { ctx.site = c; return `${c}.web.app`; }
166
+ tried.push(c);
167
+ }
168
+ if (ctx.askedSite) throw new StepError(`${ctx.askedSite}.web.app is taken.`, 'Run this again with another --site name.');
169
+ // Every nice name is taken: the project's default address still works.
170
+ ctx.site = null;
171
+ return `${ctx.id}.web.app (${tried.join(', ')} taken)`;
172
+ }
173
+
115
174
  // ---- 4. database ------------------------------------------------------------------------
116
175
 
117
176
  export async function database(ctx, say) {