create-heresay 0.2.5 → 0.2.7

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.5",
3
+ "version": "0.2.7",
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.5
1
+ 0.2.7
@@ -282,7 +282,8 @@ export async function agent(p, req, deps, body, prompt, createProject, toReporte
282
282
  return json(404, { error: 'not found' });
283
283
  }
284
284
  const appView = (p) => ({
285
- id: p.id, name: p.name, platform: p.platform, framework: p.framework,
285
+ id: p.id, name: p.name, platform: p.platform, framework: p.framework, sign_in: p.sign_in ?? null,
286
+ product_id: p.product_id ?? p.id,
286
287
  framework_detected: !!p.framework_detected, key: p.key, allowed_origins: p.allowed_origins,
287
288
  });
288
289
  //# sourceMappingURL=agent.js.map
@@ -1,6 +1,6 @@
1
1
  import { createHash, randomBytes } from 'node:crypto';
2
2
  import { agent, normaliseRepo, reposFor, tokens } from './agent.js';
3
- import { LIMITS, PLATFORMS, REPORT_ORDER, REPORT_TYPES, isFramework, isPlatform, isReportType, toReporterView, } from './types.js';
3
+ import { LIMITS, PLATFORMS, REPORT_ORDER, REPORT_TYPES, isFramework, isPlatform, isReportType, isSignIn, toReporterView, } from './types.js';
4
4
  /**
5
5
  * Fixed windows. The public endpoint has no login, so each of these is a separate line of
6
6
  * defence: the device id is chosen by the client and can be rotated, the IP limit catches that,
@@ -46,7 +46,7 @@ export function parseContext(v) {
46
46
  const f = (k) => str(c[k], LIMITS.contextFieldMax);
47
47
  return {
48
48
  route: f('route'), app_version: f('app_version'), platform: f('platform'), os: f('os'),
49
- browser: f('browser'), user_id: f('user_id'), user_label: f('user_label'),
49
+ browser: f('browser'), user_id: f('user_id'), user_label: f('user_label'), user_email: email(c.user_email),
50
50
  framework: isFramework(c.framework) ? c.framework : null,
51
51
  page_title: f('page_title'), page_url: pageUrl(c.page_url),
52
52
  viewport: typeof c.viewport === 'string' && /^\d{1,5}x\d{1,5}$/.test(c.viewport) ? c.viewport : null,
@@ -68,13 +68,13 @@ function pageUrl(v) {
68
68
  }
69
69
  }
70
70
  const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
71
+ const email = (v) => { const e = str(v, LIMITS.emailMax); return e && EMAIL.test(e) ? e : null; };
71
72
  /** The reporter's own preferences. Anything malformed is dropped, never refused. */
72
73
  export function parseReporter(v) {
73
74
  const c = (v && typeof v === 'object' ? v : {});
74
- const email = str(c.email, LIMITS.emailMax);
75
75
  const r = {
76
76
  name: str(c.name, LIMITS.nameMax),
77
- email: email && EMAIL.test(email) ? email : null,
77
+ email: email(c.email),
78
78
  note: str(c.note, LIMITS.noteMax),
79
79
  };
80
80
  return r.name || r.email || r.note ? r : null;
@@ -401,8 +401,21 @@ async function createProject(me, req, deps) {
401
401
  }
402
402
  origins.push(normaliseOrigin(u.origin));
403
403
  }
404
+ if (body.sign_in != null && !isSignIn(body.sign_in))
405
+ return json(400, { error: 'sign_in must be yes, no or null' });
406
+ // Another platform of an existing product: it has to be one.
407
+ let product_id = null;
408
+ if (body.product_id != null) {
409
+ const want = str(body.product_id, 40);
410
+ const all = await deps.store.listProjects();
411
+ if (!want || !all.some((x) => (x.product_id ?? x.id) === want))
412
+ return json(400, { error: 'no such product to add a platform to' });
413
+ product_id = want;
414
+ }
404
415
  const project = {
405
416
  id: newId('p_', 9), name, platform, framework: framework ? framework.toLowerCase() : null,
417
+ sign_in: isSignIn(body.sign_in) ? body.sign_in : null,
418
+ product_id,
406
419
  key: newId('pk_', 18), allowed_origins: [...new Set(origins)], created_by: me.email,
407
420
  created_at: new Date(deps.now()).toISOString(),
408
421
  };
@@ -430,6 +443,11 @@ async function updateProject(project, me, req, deps) {
430
443
  patch.framework = f ? f.toLowerCase() : null;
431
444
  patch.framework_detected = false;
432
445
  }
446
+ if (body.sign_in !== undefined) {
447
+ if (body.sign_in !== null && !isSignIn(body.sign_in))
448
+ return json(400, { error: 'sign_in must be yes, no or null' });
449
+ patch.sign_in = body.sign_in;
450
+ }
433
451
  if (body.allowed_origins !== undefined) {
434
452
  const origins = [];
435
453
  for (const o of Array.isArray(body.allowed_origins) ? body.allowed_origins : []) {
@@ -12,6 +12,7 @@ export const FRAMEWORKS = ['html', 'react', 'next', 'vue', 'nuxt', 'svelte', 'an
12
12
  export const isFramework = (v) => typeof v === 'string' && FRAMEWORKS.includes(v);
13
13
  export const PLATFORMS = ['web', 'ios', 'macos', 'android', 'react-native', 'flutter'];
14
14
  export const isPlatform = (v) => typeof v === 'string' && PLATFORMS.includes(v);
15
+ export const isSignIn = (v) => v === 'yes' || v === 'no';
15
16
  /** A claim nobody has touched for this long is dropped, so a crashed agent can't block a brief. */
16
17
  export const CLAIM_TTL_MS = 24 * 3600_000;
17
18
  export const toReporterView = (r) => ({
@@ -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.5';
2
+ export const VERSION = '0.2.7';
3
3
  //# sourceMappingURL=version.js.map
@@ -65,6 +65,22 @@ input:focus, textarea:focus, select:focus { outline:2px solid var(--acc); outlin
65
65
  .app-card .mute { font-size:13px; }
66
66
  .app-card .count { grid-column:1 / -1; margin-top:10px; font-size:13px; color:var(--mute); }
67
67
  .app-card .count.on { color:var(--deep); font-weight:700; }
68
+ .product-card { display:flex; flex-direction:column; border:1px solid var(--line); border-radius:16px; overflow:hidden; }
69
+ .product-card .app-card { border:0; border-radius:0; }
70
+ .product-card .app-card:hover { background:var(--soft); }
71
+ .product-card.single .app-card { padding-bottom:10px; }
72
+ .product-head { display:flex; justify-content:space-between; align-items:baseline; gap:10px; padding:16px 18px 6px; }
73
+ .product-head b { font-size:17px; }
74
+ .platform-line { padding:12px 18px; border-top:1px solid var(--line) !important; grid-template-columns:auto 1fr auto; }
75
+ .platform-line .count { grid-column:auto; margin:0; }
76
+ .add-platform { font-size:13px; font-weight:600; text-decoration:none; }
77
+ .product-card.single .add-platform { padding:0 18px 14px; }
78
+ .add-platform:hover { text-decoration:underline; }
79
+ .platform.added { color:var(--mute); background:var(--soft); border-color:transparent; }
80
+ .pill.platform-pill { color:var(--mute); border:1px solid var(--line); border-radius:999px; padding:0 8px; font-weight:600; }
81
+ .product-platforms .repos-line { margin:0 0 6px; }
82
+ .product-platforms { margin:-10px 0 18px; }
83
+ .platforms-filter { margin-bottom:8px; }
68
84
  .picon { width:40px; height:40px; border-radius:12px; background:var(--mist); display:inline-flex; align-items:center; justify-content:center; flex:none; }
69
85
  .picon svg { width:22px; height:22px; fill:none; stroke:var(--deep); stroke-width:1.7; stroke-linecap:round; stroke-linejoin:round; }
70
86
 
@@ -193,6 +193,14 @@
193
193
  icon: '<path d="M14 3 5 12l3 3L20 3zM14 12l-5 5 5 5h6l-5-5 5-5z"/>' },
194
194
  ];
195
195
  var platformOf = function (id) { return PLATFORMS.filter(function (x) { return x.id === id; })[0] || PLATFORMS[0]; };
196
+ /** Apps that are platforms of one product share its id: the first app's. */
197
+ var productOf = function (p) { return p.product_id || p.id; };
198
+ var siblings = function (p) {
199
+ var mine = projects.filter(function (x) { return productOf(x) === productOf(p); });
200
+ if (!mine.some(function (x) { return x.id === p.id; })) mine.push(p);
201
+ return mine.sort(function (a, b) { return a.created_at.localeCompare(b.created_at); });
202
+ };
203
+ var productName = function (p) { return siblings(p)[0].name; };
196
204
  var icon = function (p) { return el('span', { class: 'picon', html: '<svg viewBox="0 0 24 24" aria-hidden="true">' + p.icon + '</svg>' }); };
197
205
 
198
206
  function appsView(view) {
@@ -211,21 +219,34 @@
211
219
  el('a', { class: 'btn primary', href: '#/new', text: 'Add an app' }),
212
220
  ]));
213
221
  var grid = el('div', { class: 'apps' });
214
- projects.forEach(function (p) {
215
- var count = el('span', { class: 'count', text: ' ' });
216
- var card = el('a', { class: 'app-card', href: '#/apps/' + p.id }, [
217
- icon(platformOf(p.platform)),
218
- el('div', {}, [el('b', { text: p.name }), el('span', { class: 'mute', text: platformOf(p.platform).label + (p.framework ? ' · ' + frameworkLabel(p.framework) : '') })]),
219
- count,
220
- ]);
221
- grid.appendChild(card);
222
- api('GET', '/projects/' + p.id + '/reports').then(function (r) {
223
- var open = r.reports.filter(function (x) { return x.status === 'open'; }).length;
224
- // No report yet means setup isn't proven: send them back to finish it.
225
- if (!r.reports.length && !p.sdk_seen && !p.code_found) { card.href = '#/apps/' + p.id + '/setup'; count.textContent = 'Setup not finished'; count.className = 'count todo'; return; }
226
- count.textContent = !r.reports.length ? 'No reports yet' : open ? open + ' open' : 'All answered';
227
- if (open) count.className = 'count on';
222
+ // One card per product; one line per platform in it, each with its own state.
223
+ var seen = {};
224
+ projects.forEach(function (first) {
225
+ if (seen[productOf(first)]) return;
226
+ seen[productOf(first)] = true;
227
+ var sibs = siblings(first);
228
+ var many = sibs.length > 1;
229
+ var rows = sibs.map(function (p) {
230
+ var count = el('span', { class: 'count', text: ' ' });
231
+ var line = el('a', { class: 'app-card' + (many ? ' platform-line' : ''), href: '#/apps/' + p.id }, [
232
+ icon(platformOf(p.platform)),
233
+ el('div', {}, [el('b', { text: many ? platformOf(p.platform).label : p.name }),
234
+ el('span', { class: 'mute', text: many ? (p.framework ? frameworkLabel(p.framework) : ' ') : platformOf(p.platform).label + (p.framework ? ' · ' + frameworkLabel(p.framework) : '') })]),
235
+ count,
236
+ ]);
237
+ api('GET', '/projects/' + p.id + '/reports').then(function (r) {
238
+ var open = r.reports.filter(function (x) { return x.status === 'open'; }).length;
239
+ // No report yet means setup isn't proven: send them back to finish it.
240
+ if (!r.reports.length && !p.sdk_seen && !p.code_found) { line.href = '#/apps/' + p.id + '/setup'; count.textContent = 'Setup not finished'; count.className = 'count todo'; return; }
241
+ count.textContent = !r.reports.length ? 'No reports yet' : open ? open + ' open' : 'All answered';
242
+ if (open) count.className = 'count on';
243
+ });
244
+ return line;
228
245
  });
246
+ var add = el('a', { class: 'add-platform', href: '#/new?product=' + productOf(first), text: '+ Add a platform' });
247
+ grid.appendChild(many
248
+ ? el('div', { class: 'product-card' }, [el('div', { class: 'product-head' }, [el('b', { text: first.name }), add])].concat(rows))
249
+ : el('div', { class: 'product-card single' }, [rows[0], add]));
229
250
  });
230
251
  view.appendChild(grid);
231
252
  });
@@ -238,14 +259,15 @@
238
259
  ['unknown', 'Not sure'], ['html', 'Plain HTML'], ['react', 'React'], ['next', 'Next.js'], ['vue', 'Vue'], ['nuxt', 'Nuxt'],
239
260
  ['svelte', 'SvelteKit'], ['angular', 'Angular'], ['other', 'Something else'],
240
261
  ];
241
- function frameworkLabel(id) { var f = FRAMEWORKS.filter(function (x) { return x[0] === id; })[0]; return f ? f[1] : id; }
262
+ var NATIVE_LABELS = { swiftui: 'SwiftUI', uikit: 'UIKit', appkit: 'AppKit' };
263
+ function frameworkLabel(id) { var f = FRAMEWORKS.filter(function (x) { return x[0] === id; })[0]; return f ? f[1] : NATIVE_LABELS[id] || id; }
242
264
 
243
265
  /**
244
266
  * The four steps. Earlier ones are links, so you can go back and change things; later ones
245
267
  * aren't, because each step needs the one before it. `tested` marks the last step done.
246
268
  */
247
- function stepper(active, p, tested) {
248
- var q = p ? '?app=' + p.id : '';
269
+ function stepper(active, p, tested, query) {
270
+ var q = p ? '?app=' + p.id : (query || '');
249
271
  var links = ['#/new' + q, p ? '#/new/' + p.platform + q : null, p ? '#/apps/' + p.id + '/setup' : null, null];
250
272
  var names = ['Platform', 'Details', 'Install', 'Test'];
251
273
  return el('ol', { class: 'steps' }, names.map(function (s, i) {
@@ -260,28 +282,43 @@
260
282
  /** Adding an app, or with ?app=<id>, going back to change one that already exists. */
261
283
  function newAppView(view, platform, query) {
262
284
  var editId = query && query.get('app');
263
- if (editId) return withProject(editId, function (p) { drawNewApp(view, platform, p); });
264
- drawNewApp(view, platform, null);
285
+ var productId = query && query.get('product');
286
+ if (editId) return withProject(editId, function (p) { drawNewApp(view, platform, p, null); });
287
+ if (productId) {
288
+ return api('GET', '/projects').then(function (b) {
289
+ projects = b.projects;
290
+ var first = projects.filter(function (x) { return productOf(x) === productId; })[0];
291
+ if (!first) { location.hash = '#/'; return; }
292
+ drawNewApp(view, platform, null, first);
293
+ });
294
+ }
295
+ drawNewApp(view, platform, null, null);
265
296
  }
266
297
 
267
- function drawNewApp(view, platform, editing) {
268
- var q = editing ? '?app=' + editing.id : '';
298
+ /** `sibling`: adding another platform to that app's product, not a new product. */
299
+ function drawNewApp(view, platform, editing, sibling) {
300
+ var q = editing ? '?app=' + editing.id : sibling ? '?product=' + productOf(sibling) : '';
301
+ var has = sibling ? siblings(sibling) : [];
269
302
  if (!platform) {
270
- view.appendChild(stepper(1, editing));
271
- view.appendChild(el('h1', { text: 'What are you adding Heresay to?' }));
303
+ view.appendChild(stepper(1, editing, false, q));
304
+ view.appendChild(el('h1', { text: sibling ? 'Add a platform to ' + productName(sibling) : 'What are you adding Heresay to?' }));
305
+ if (sibling) view.appendChild(el('p', { class: 'mute', text: 'Its reports join the same inbox. Each platform gets its own key and install steps.' }));
272
306
  var grid = el('div', { class: 'platforms' });
273
307
  PLATFORMS.forEach(function (p) {
274
- grid.appendChild(el(p.ready ? 'a' : 'div', {
275
- class: 'platform' + (p.ready ? '' : ' soon') + (editing && editing.platform === p.id ? ' current' : ''), href: p.ready ? '#/new/' + p.id + q : null,
276
- 'aria-disabled': p.ready ? null : 'true',
277
- }, [icon(p), el('b', { text: p.label }), el('span', { class: 'mute', text: p.note }), p.ready ? null : el('span', { class: 'tag', text: 'Soon' })]));
308
+ var there = has.filter(function (x) { return x.platform === p.id; })[0];
309
+ grid.appendChild(el(p.ready && !there ? 'a' : 'div', {
310
+ class: 'platform' + (p.ready ? '' : ' soon') + (there ? ' added' : '') + (editing && editing.platform === p.id ? ' current' : ''),
311
+ href: p.ready && !there ? '#/new/' + p.id + q : null,
312
+ 'aria-disabled': p.ready && !there ? null : 'true',
313
+ }, [icon(p), el('b', { text: p.label }), el('span', { class: 'mute', text: p.note }),
314
+ there ? el('span', { class: 'tag', text: 'Added' }) : p.ready ? null : el('span', { class: 'tag', text: 'Soon' })]));
278
315
  });
279
316
  view.appendChild(grid);
280
317
  view.appendChild(el('p', { class: 'mute small', text: 'Other platforms can already send reports through the API. See the docs, under Other platforms.' }));
281
318
  return;
282
319
  }
283
320
 
284
- view.appendChild(stepper(2, editing));
321
+ view.appendChild(stepper(2, editing, false, q));
285
322
  var native = !!platformOf(platform).apple;
286
323
  view.appendChild(el('h1', { text: 'About your ' + platformOf(platform).label + ' app' }));
287
324
  var err = el('p', { class: 'err', role: 'alert' });
@@ -296,9 +333,24 @@
296
333
  },
297
334
  }));
298
335
  });
336
+ // Signed-in apps pass who it is to Heresay, so the person reporting is never asked their name.
337
+ var signIn = editing && editing.sign_in ? editing.sign_in : sibling && sibling.sign_in ? sibling.sign_in : 'unknown';
338
+ var signChips = el('div', { class: 'chips', role: 'radiogroup', 'aria-label': 'Do people sign in?' });
339
+ [['yes', 'Yes, they sign in'], ['no', 'No, anyone can use it'], ['unknown', 'Not sure']].forEach(function (c) {
340
+ signChips.appendChild(el('button', {
341
+ type: 'button', role: 'radio', 'aria-checked': String(c[0] === signIn), text: c[1],
342
+ onclick: function (e) {
343
+ signIn = c[0];
344
+ signChips.querySelectorAll('button').forEach(function (b) { b.setAttribute('aria-checked', String(b === e.target)); });
345
+ },
346
+ }));
347
+ });
348
+ var signField = el('div', { class: 'field' }, [el('span', { class: 'lbl' }, ['Do people sign in to your app? ', el('span', { class: 'opt', text: 'optional' })]), signChips,
349
+ el('p', { class: 'hint', text: 'If they do, your app tells Heresay who is signed in, so nobody types their name to send a report, and you can reply to them. Many users with many logins is fine: it follows whoever is signed in on that device.' })]);
299
350
  var form = el('form', { class: 'form' }, native ? [
300
351
  el('label', {}, ['Name', el('input', { name: 'name', required: true, maxlength: '80', placeholder: 'Acme for ' + platformOf(platform).label, autocomplete: 'off' })]),
301
352
  el('p', { class: 'hint', text: 'Native apps have no web address to lock the key to, so any copy of your app can send reports. The per-device, per-network and per-app rate limits still apply.' }),
353
+ signField,
302
354
  el('div', { class: 'row' }, [el('a', { class: 'btn ghost', href: '#/new' + q, text: 'Back' }), el('button', { class: 'btn primary', text: editing ? 'Save and continue' : 'Create app' })]),
303
355
  err,
304
356
  ] : [
@@ -307,6 +359,7 @@
307
359
  el('p', { class: 'hint', text: 'Only changes the install steps we show. Not sure? Leave it: your coding agent can work it out, and the general steps work everywhere.' })]),
308
360
  el('label', {}, ['Where it runs', el('textarea', { name: 'origins', rows: '3', placeholder: 'https://app.example.com\nhttp://localhost:3000' })]),
309
361
  el('p', { class: 'hint', text: 'One address per line: your live site and anywhere you test it. Only these sites can send reports with this app’s key. Leave it empty to allow any site while you try things out.' }),
362
+ signField,
310
363
  el('div', { class: 'row' }, [el('a', { class: 'btn ghost', href: '#/new' + q, text: 'Back' }), el('button', { class: 'btn primary', text: editing ? 'Save and continue' : 'Create app' })]),
311
364
  err,
312
365
  ]);
@@ -314,7 +367,8 @@
314
367
  e.preventDefault();
315
368
  err.textContent = '';
316
369
  var origins = native ? [] : form.origins.value.split(/[\s,]+/).map(function (s) { return s.trim(); }).filter(Boolean);
317
- var body = { name: form.name.value, platform: platform, framework: native ? 'swiftui' : (fw === 'unknown' ? null : fw), allowed_origins: origins };
370
+ var body = { name: form.name.value, platform: platform, framework: native ? 'swiftui' : (fw === 'unknown' ? null : fw), allowed_origins: origins, sign_in: signIn === 'unknown' ? null : signIn };
371
+ if (sibling) body.product_id = productOf(sibling);
318
372
  // Editing keeps the key, so a line already pasted into the app keeps working.
319
373
  (editing ? api('PATCH', '/projects/' + editing.id, body) : api('POST', '/projects', body))
320
374
  .then(function (b) {
@@ -327,6 +381,10 @@
327
381
  if (editing) {
328
382
  form.name.value = editing.name;
329
383
  if (!native) form.origins.value = editing.allowed_origins.join('\n');
384
+ } else if (sibling) {
385
+ form.name.value = productName(sibling);
386
+ var web = has.filter(function (x) { return x.allowed_origins.length; })[0];
387
+ if (!native && web) form.origins.value = web.allowed_origins.join('\n');
330
388
  }
331
389
  form.name.focus();
332
390
  }
@@ -377,11 +435,41 @@
377
435
  codeBlock(SWIFT_PACKAGE),
378
436
  el('p', { html: '<b>2.</b> Configure it once, where your app starts, and add the ' + (mac ? 'menu item (Help › Report a Problem…)' : 'Report button') + ':' }),
379
437
  codeBlock(code),
380
- el('p', { class: 'hint', html: 'Optional: <code>Heresay.identify(id:label:)</code> after sign-in, <code>Heresay.setScreen("Checkout")</code> as people move around, and <code>Heresay.present()</code> to open it from your own button. Needs iOS 16 or macOS 13.' }),
438
+ el('p', { class: 'hint', html: 'Optional: <code>Heresay.setScreen("Checkout")</code> as people move around, and <code>Heresay.present()</code> to open it from your own button. Needs iOS 16 or macOS 13.' }),
439
+ ];
440
+ }
441
+
442
+ /** Signed-in apps: the one call that tells Heresay who it is. Required when they said yes. */
443
+ function identifyStep(p) {
444
+ var apple = platformOf(p.platform).apple;
445
+ var code = apple
446
+ ? '// after sign-in\nHeresay.identify(id: user.id, label: user.name, email: user.email)\n\n// after sign-out\nHeresay.identify()'
447
+ : '// after sign-in\nwindow.Heresay?.identify({ id: user.id, label: user.name, email: user.email });\n\n// after sign-out\nwindow.Heresay?.identify();';
448
+ if (p.sign_in === 'yes') {
449
+ return [el('p', { html: '<b>Then, where your app signs people in,</b> tell Heresay who it is. Nobody is asked their name, and you can reply to them:' }), codeBlock(code)];
450
+ }
451
+ if (p.sign_in === 'no') return [];
452
+ return [el('details', { class: 'where' }, [el('summary', { text: 'Do people sign in to your app?' }),
453
+ el('p', { text: 'Then tell Heresay who is signed in, so nobody types their name to send a report:' }), codeBlock(code)])];
454
+ }
455
+
456
+ /** People who never noticed the button can't use it: a one-time introduction, shown by Heresay. */
457
+ function introStep(p) {
458
+ var apple = platformOf(p.platform).apple;
459
+ return apple ? [
460
+ el('p', { html: '<b>Last, tell people it’s there.</b> ' + (p.platform === 'macos' ? 'Under Help, nobody finds it by chance. ' : '') + 'Once the main screen appears, after sign-in and onboarding, show the one-time introduction. It says where to find Heresay and offers to open it:' }),
461
+ codeBlock('MainView()\n .onAppear { Heresay.introduce() } // once per install; later calls do nothing'),
462
+ ] : [
463
+ el('p', { html: '<b>Last, tell people it’s there.</b> Add <code>data-intro="auto"</code> to the tag for a one-time bubble over the button. Apps with sign-in or onboarding: call this once the main screen appears instead:' }),
464
+ codeBlock('window.Heresay?.introduce(); // once per device; later calls do nothing'),
381
465
  ];
382
466
  }
383
467
 
384
468
  function byHand(p) {
469
+ return byHandSteps(p).concat(identifyStep(p), introStep(p));
470
+ }
471
+
472
+ function byHandSteps(p) {
385
473
  if (platformOf(p.platform).apple) return appleByHand(p);
386
474
  var fw = p.framework;
387
475
  if (fw && fw !== 'other') {
@@ -424,7 +512,7 @@
424
512
  '',
425
513
  ' npx -y heresay@latest connect --url ' + location.origin + ' --token ' + token + ' --yes',
426
514
  '',
427
- '2. Print the install steps for this app and follow them. They include the app\'s key and exactly where the code goes' + (apple ? ' (a Swift package and one line of setup).' : ', for any framework.'),
515
+ '2. Print the install steps for this app and follow them. They include the app\'s key and exactly where the code goes' + (apple ? ' (a Swift package and one line of setup)' : ', for any framework') + '. Follow every required step, including telling the people who use the app that Heresay is there: call introduce() once the main screen appears, so it isn\'t hidden' + (apple ? ' under a menu' : ' in a corner') + '.',
428
516
  '',
429
517
  ' npx -y heresay@latest install ' + p.id,
430
518
  '',
@@ -432,7 +520,7 @@
432
520
  '',
433
521
  ' npx -y heresay@latest check ' + p.id,
434
522
  '',
435
- ' You are done when it prints "installed": true. If it doesn\'t, fix what it says and run it again.',
523
+ ' You are done when it prints "installed": true and an empty "todo" list. If not, do what it says and run it again.',
436
524
  '',
437
525
  'Change nothing else in the app.',
438
526
  ].join('\n');
@@ -580,6 +668,7 @@
580
668
  rs.slice(0, 5).forEach(function (r) {
581
669
  feed.appendChild(el('li', { class: !first && !known[r.id] ? 'fresh' : '' }, [
582
670
  el('span', { class: 'pill ' + r.type, text: TYPE_LABEL[r.type] }),
671
+ showPlatform ? el('span', { class: 'pill platform-pill', text: platformOf(p.platform).label }) : null,
583
672
  el('span', { class: 'feed-text', text: r.text }),
584
673
  el('span', { class: 'mute small', text: [r.context.route, r.context.platform, new Date(r.created_at).toLocaleTimeString()].filter(Boolean).join(' · ') }),
585
674
  ]));
@@ -596,59 +685,120 @@
596
685
 
597
686
  var filter = 'open';
598
687
 
688
+ /** Most urgent first, oldest first within a type, as the server sorts one app's reports. */
689
+ var TYPE_ORDER = { broken: 0, confusing: 1, improvement: 2, idea: 3 };
690
+ function triageSort(rs) {
691
+ return rs.slice().sort(function (a, b) {
692
+ return ((a.status === 'open' ? 0 : 1) - (b.status === 'open' ? 0 : 1))
693
+ || (TYPE_ORDER[a.type] - TYPE_ORDER[b.type])
694
+ || a.created_at.localeCompare(b.created_at);
695
+ });
696
+ }
697
+
698
+ /**
699
+ * One inbox for a product: every platform's reports together, each marked with where it came
700
+ * from. Install, delete and repos stay per platform, because keys and code differ.
701
+ */
599
702
  function reportsView(view, p) {
600
703
  var reports = [];
704
+ var sibs = [p];
705
+ var where = 'all';
601
706
  var filters = el('nav', { class: 'filters', 'aria-label': 'Filter' });
707
+ var platformBar = el('nav', { class: 'filters platforms-filter', 'aria-label': 'Platform' });
602
708
  var list = el('div', { class: 'reports' });
603
709
  var empty = el('p', { class: 'empty' });
604
- var ctx = { repos: [], briefs: {} };
605
- var repoLine = el('p', { class: 'repos-line' });
710
+ var ctxs = {};
711
+ var head = el('div', { class: 'head' });
712
+ var platformsBox = el('div', { class: 'product-platforms' });
606
713
  view.appendChild(el('a', { class: 'back', href: '#/', text: '← All apps' }));
607
- view.appendChild(el('div', { class: 'head' }, [
608
- el('div', { class: 'title' }, [icon(platformOf(p.platform)), el('div', {}, [el('h1', { text: p.name }),
609
- p.framework ? el('span', { class: 'mute small', text: frameworkLabel(p.framework) + (p.framework_detected ? ' (detected)' : '') }) : null])]),
610
- el('div', { class: 'row tight' }, [
611
- el('a', { class: 'btn', href: '#/apps/' + p.id + '/setup', text: 'Install' }),
612
- el('a', { class: 'btn ghost', href: '#/apps/' + p.id + '/delete', text: 'Delete…' }),
613
- ]),
614
- ]));
615
- view.appendChild(repoLine);
714
+ view.appendChild(head);
715
+ view.appendChild(platformsBox);
716
+ view.appendChild(platformBar);
616
717
  view.appendChild(filters);
617
718
  view.appendChild(list);
618
719
  view.appendChild(empty);
619
720
 
721
+ function drawHead() {
722
+ head.textContent = '';
723
+ var many = sibs.length > 1;
724
+ head.appendChild(el('div', { class: 'title' }, [
725
+ many ? el('span', { class: 'picon', html: '<svg viewBox="0 0 24 24" aria-hidden="true"><rect x="3" y="3" width="8" height="8" rx="2"/><rect x="13" y="3" width="8" height="8" rx="2"/><rect x="3" y="13" width="8" height="8" rx="2"/><path d="M17 13v8M13 17h8"/></svg>' }) : icon(platformOf(p.platform)),
726
+ el('div', {}, [el('h1', { text: productName(p) }),
727
+ el('span', { class: 'mute small', text: many ? sibs.map(function (x) { return platformOf(x.platform).label; }).join(' · ')
728
+ : (p.framework ? frameworkLabel(p.framework) + (p.framework_detected ? ' (detected)' : '') : platformOf(p.platform).label) })])]));
729
+ head.appendChild(el('div', { class: 'row tight' }, [
730
+ el('a', { class: 'btn ghost', href: '#/new?product=' + productOf(p), text: '+ Add a platform' }),
731
+ many ? null : el('a', { class: 'btn', href: '#/apps/' + p.id + '/setup', text: 'Install' }),
732
+ many ? null : el('a', { class: 'btn ghost', href: '#/apps/' + p.id + '/delete', text: 'Delete…' }),
733
+ ]));
734
+ }
735
+
736
+ /** Per platform: where agents fix it, and its own Install and Delete. */
737
+ function drawPlatforms() {
738
+ platformsBox.textContent = '';
739
+ var many = sibs.length > 1;
740
+ sibs.forEach(function (x) {
741
+ var repos = (ctxs[x.id] || {}).repos || [];
742
+ platformsBox.appendChild(el('p', { class: 'repos-line' }, [
743
+ many ? el('b', { text: platformOf(x.platform).label + ': ' }) : null,
744
+ document.createTextNode(repos.length ? 'Agents fix these in ' + repos.join(', ') + ' · ' : 'No repo connected for agents yet · '),
745
+ el('a', { href: '#/connect?app=' + x.id, text: 'Connect a repo' }),
746
+ many ? document.createTextNode(' · ') : null,
747
+ many ? el('a', { href: '#/apps/' + x.id + '/setup', text: 'Install' }) : null,
748
+ many ? document.createTextNode(' · ') : null,
749
+ many ? el('a', { href: '#/apps/' + x.id + '/delete', text: 'Delete…' }) : null,
750
+ ]));
751
+ });
752
+ }
753
+
620
754
  function load() {
621
- return Promise.all([
622
- api('GET', '/projects/' + p.id + '/reports'),
623
- api('GET', '/projects/' + p.id + '/repos'),
624
- ]).then(function (x) {
625
- reports = x[0].reports; ctx.briefs = x[0].briefs || {}; ctx.repos = x[1].repos;
626
- repoLine.textContent = '';
627
- repoLine.appendChild(document.createTextNode(ctx.repos.length
628
- ? 'Agents fix these in: ' + ctx.repos.join(', ') + ' · ' : 'No repo connected for agents yet · '));
629
- repoLine.appendChild(el('a', { href: '#/connect?app=' + p.id, text: 'Connect a repo' }));
755
+ return api('GET', '/projects').then(function (b) {
756
+ projects = b.projects;
757
+ sibs = siblings(p);
758
+ drawHead();
759
+ return Promise.all(sibs.map(function (x) {
760
+ return Promise.all([api('GET', '/projects/' + x.id + '/reports'), api('GET', '/projects/' + x.id + '/repos')])
761
+ .then(function (r) { ctxs[x.id] = { briefs: r[0].briefs || {}, repos: r[1].repos, project: x, reports: r[0].reports }; });
762
+ }));
763
+ }).then(function () {
764
+ reports = triageSort([].concat.apply([], sibs.map(function (x) { return ctxs[x.id].reports; })));
765
+ drawPlatforms();
630
766
  render();
631
767
  });
632
768
  }
633
769
 
634
770
  function render() {
771
+ var many = sibs.length > 1;
772
+ platformBar.textContent = '';
773
+ platformBar.hidden = !many;
774
+ if (many) {
775
+ [{ id: 'all', label: 'All platforms' }].concat(sibs.map(function (x) { return { id: x.id, label: platformOf(x.platform).label }; })).forEach(function (f) {
776
+ var n = f.id === 'all' ? reports.length : reports.filter(function (r) { return r.project_id === f.id; }).length;
777
+ platformBar.appendChild(el('button', { 'aria-pressed': String(where === f.id), onclick: function () { where = f.id; render(); } },
778
+ [f.label + ' ', el('span', { class: 'n', text: String(n) })]));
779
+ });
780
+ }
781
+ var here = reports.filter(function (r) { return where === 'all' || r.project_id === where; });
635
782
  filters.textContent = '';
636
783
  ['open', 'accepted', 'fixed', 'declined', 'all'].forEach(function (f) {
637
- var n = f === 'all' ? reports.length : reports.filter(function (r) { return r.status === f; }).length;
784
+ var n = f === 'all' ? here.length : here.filter(function (r) { return r.status === f; }).length;
638
785
  filters.appendChild(el('button', {
639
786
  'aria-pressed': String(filter === f),
640
787
  onclick: function () { filter = f; render(); },
641
788
  }, [(f === 'all' ? 'All' : STATUS_LABEL[f]) + ' ', el('span', { class: 'n', text: String(n) })]));
642
789
  });
643
790
  list.textContent = '';
644
- var shown = reports.filter(function (r) { return filter === 'all' || r.status === filter; });
791
+ var shown = here.filter(function (r) { return filter === 'all' || r.status === filter; });
645
792
  empty.hidden = shown.length > 0;
646
793
  empty.textContent = '';
647
- if (!reports.length) {
794
+ if (!here.length) {
648
795
  empty.appendChild(document.createTextNode('No reports yet. '));
649
- empty.appendChild(el('a', { href: '#/apps/' + p.id + '/setup', text: 'Check the install' }));
796
+ empty.appendChild(el('a', { href: '#/apps/' + (where === 'all' ? p.id : where) + '/setup', text: 'Check the install' }));
650
797
  } else empty.textContent = filter === 'open' ? 'Nothing waiting. Every report has had its hearing.' : 'Nothing here.';
651
- shown.forEach(function (r) { list.appendChild(row(p, r, load, ctx)); });
798
+ shown.forEach(function (r) {
799
+ var c = ctxs[r.project_id];
800
+ list.appendChild(row(c.project, r, load, c, many));
801
+ });
652
802
  }
653
803
 
654
804
  load();
@@ -658,22 +808,31 @@
658
808
 
659
809
  function ctxLine(c) {
660
810
  return [c.page_title, c.route, c.app_version && ('v' + c.app_version), c.platform, c.os, c.browser,
661
- c.viewport, c.user_label || c.user_id]
811
+ c.viewport]
662
812
  .filter(Boolean).join(' · ');
663
813
  }
664
814
 
665
- /** What the reporter said about themselves, in the SDK's Preferences. Their words, not verified. */
666
- function reporterLine(rp) {
667
- if (!rp) return null;
668
- var who = [rp.name, rp.email].filter(Boolean).join(' · ');
815
+ var mailto = function (e) { return el('a', { href: 'mailto:' + encodeURIComponent(e).replace(/%40/g, '@'), text: 'Reply' }); };
816
+
817
+ /**
818
+ * Who sent it. "Signed in" is what the app said (identify); "From" is what the reporter typed
819
+ * in Preferences, their words, not verified.
820
+ */
821
+ function reporterLine(c, rp) {
822
+ rp = rp || {};
823
+ var app = [c.user_label || c.user_id, c.user_email].filter(Boolean).join(' · ');
824
+ var typed = [rp.name, rp.email].filter(Boolean).join(' · ');
825
+ if (!app && !typed && !rp.note) return null;
826
+ var reply = c.user_email || rp.email;
669
827
  return el('div', { class: 'ctx' }, [
670
- who ? el('span', {}, [document.createTextNode('From: ' + who + ' ')]) : null,
671
- rp.email ? el('a', { href: 'mailto:' + encodeURIComponent(rp.email).replace(/%40/g, '@'), text: 'Reply' }) : null,
828
+ app ? el('span', {}, [document.createTextNode('Signed in: ' + app + ' ')]) : null,
829
+ !app && typed ? el('span', {}, [document.createTextNode('From: ' + typed + ' ')]) : null,
830
+ reply ? mailto(reply) : null,
672
831
  rp.note ? el('div', { text: 'About their setup: ' + rp.note }) : null,
673
832
  ]);
674
833
  }
675
834
 
676
- function row(p, r, reload, ctx) {
835
+ function row(p, r, reload, ctx, showPlatform) {
677
836
  var brief = ctx.briefs[r.id];
678
837
  var err = el('span', { class: 'err' });
679
838
  var actions = el('div', { class: 'actions' });
@@ -741,13 +900,14 @@
741
900
  return el('article', { class: 'report' }, [
742
901
  el('div', { class: 'meta' }, [
743
902
  el('span', { class: 'pill ' + r.type, text: TYPE_LABEL[r.type] }),
903
+ showPlatform ? el('span', { class: 'pill platform-pill', text: platformOf(p.platform).label }) : null,
744
904
  el('time', { datetime: r.created_at, text: new Date(r.created_at).toLocaleString() }),
745
905
  el('span', { class: 'status s-' + r.status, text: STATUS_LABEL[r.status] }),
746
906
  ]),
747
907
  el('p', { class: 'text', text: r.text }),
748
908
  el('div', { class: 'ctx', text: ctxLine(r.context) }),
749
909
  r.context.page_url ? el('div', { class: 'ctx' }, [el('a', { href: r.context.page_url, target: '_blank', rel: 'noopener noreferrer', text: r.context.page_url })]) : null,
750
- reporterLine(r.reporter),
910
+ reporterLine(r.context, r.reporter),
751
911
  r.decline_reason ? el('div', { class: 'reason', text: 'Declined: ' + r.decline_reason }) : null,
752
912
  r.fix_note ? el('div', { class: 'reason', text: 'Told them: ' + r.fix_note }) : null,
753
913
  r.status === 'accepted' && brief ? el('div', { class: 'brief-line' }, [
@@ -67,6 +67,7 @@
67
67
  <tr><td><code>data-version</code></td><td><code>1.4.0</code></td><td>Your app's version, attached to every report.</td></tr>
68
68
  <tr><td><code>data-user-id</code></td><td><code>u_1842</code></td><td>Who the user is, in your system.</td></tr>
69
69
  <tr><td><code>data-user-label</code></td><td><code>Asha K.</code></td><td>A name to show in your dashboard.</td></tr>
70
+ <tr><td><code>data-user-email</code></td><td><code>asha@example.com</code></td><td>Their email, so you can reply. Or use <code>identify</code> below.</td></tr>
70
71
  <tr><td><code>data-accent</code></td><td><code>#6d28d9</code></td><td>Your brand colour for the Send button and selected states. Hex only. Text on it switches to white or black automatically.</td></tr>
71
72
  <tr><td><code>data-position</code></td><td><code>left</code></td><td>Put the button in the bottom-left corner instead of the right.</td></tr>
72
73
  <tr><td><code>data-api</code></td><td><code>https://…/v1</code></td><td>Rarely needed. Where your Heresay API lives, if it is not at the same address as <code>sdk.js</code>.</td></tr></table>
@@ -79,15 +80,16 @@
79
80
  <h2 id="api">JavaScript API</h2>
80
81
  <p>The script creates <code>window.Heresay</code> (also available as <code>window.Feedback</code>). Call these any time after it loads.</p>
81
82
  <table><tr><th>Call</th><th>What it does</th></tr>
82
- <tr><td><code>Heresay.identify({ id, label })</code></td><td>Tell Heresay who is signed in. Call it after login; pass nothing to clear it.</td></tr>
83
+ <tr><td><code>Heresay.identify({ id, label, email })</code></td><td>Tell Heresay who is signed in. Call it after login; pass nothing to clear it. Then nobody is asked their name to send a report, and with <code>email</code> you can reply to them. Apps with many users and logins need nothing more: it follows whoever is signed in on that device.</td></tr>
83
84
  <tr><td><code>Heresay.setVersion("1.4.0")</code></td><td>Set or change the app version.</td></tr>
84
85
  <tr><td><code>Heresay.setScreen("Checkout")</code></td><td>Name the current screen, for apps whose URL doesn't change between screens.</td></tr>
85
86
  <tr><td><code>Heresay.open()</code></td><td>Open the report form from your own button or menu item.</td></tr>
86
- <tr><td><code>Heresay.openPreferences()</code></td><td>Open the Preferences tab. There, the person can add a name, an email for replies and a note about their setup (sent with every report), and move the button left or right. It's all optional and saved on their device.</td></tr>
87
+ <tr><td><code>Heresay.introduce()</code></td><td>Once per device, a small bubble over the button says what it's for, so people know it exists. Call it when your main screen is up (after sign-in or onboarding), or add <code>data-intro="auto"</code> to the tag. Later calls do nothing.</td></tr>
88
+ <tr><td><code>Heresay.openPreferences()</code></td><td>Open the Preferences tab: a note about their setup, sent with every report. People who aren't signed in can also add a name and an email for replies. It's all optional and saved on their device. Where the button sits is yours to choose, with <code>data-position</code>.</td></tr>
87
89
  <tr><td><code>Heresay.close()</code></td><td>Close the panel.</td></tr></table>
88
90
  <p>Each report also carries the page it came from: its title, its address without the query string, and the window size.</p>
89
91
  <pre><code><span class="k">// after your user signs in</span>
90
- Heresay.identify({ id: user.id, label: user.name });
92
+ Heresay.identify({ id: user.id, label: user.name, email: user.email });
91
93
 
92
94
  <span class="k">// single-page apps: name screens as the user moves</span>
93
95
  router.afterEach((to) =&gt; Heresay.setScreen(to.name));</code></pre>
@@ -155,7 +157,7 @@ connect-src ORIGIN;</code></pre>
155
157
  WindowGroup { ContentView().heresayReportButton() } <span class="k">// iOS: a Report button in the corner</span>
156
158
  }
157
159
  }</code></pre>
158
- <p>On macOS, use <code>ContentView().heresay()</code> and add <code>.commands { HeresayCommands() }</code> for <b>Help › Report a Problem…</b> (⌥⌘R). The same calls as the web SDK exist: <code>Heresay.identify(id:label:)</code>, <code>Heresay.setScreen(_:)</code>, <code>Heresay.present()</code>, and <code>Heresay.send(_:text:)</code> for your own UI. The app version comes from the bundle. Native apps have no web origin to lock the key to; the rate limits still apply.</p>
160
+ <p>On macOS, use <code>ContentView().heresay()</code> and add <code>.commands { HeresayCommands() }</code> for <b>Help › Report a Problem…</b> (⌥⌘R). The same calls as the web SDK exist: <code>Heresay.identify(id:label:email:)</code>, <code>Heresay.presentPreferences()</code>, <code>Heresay.introduce()</code> (once per install, an alert saying where to find it; call it when the main screen appears), <code>Heresay.setScreen(_:)</code>, <code>Heresay.present()</code>, and <code>Heresay.send(_:text:)</code> for your own UI. The app version comes from the bundle. Native apps have no web origin to lock the key to; the rate limits still apply.</p>
159
161
 
160
162
  <h2 id="rest">Other platforms</h2>
161
163
  <p>Android, React Native and Flutter SDKs are on the way. Until then, any app can talk to the same API. Both calls take a JSON body.</p>
@@ -40,17 +40,42 @@ On macOS use `ContentView().heresay()` and add `.commands { HeresayCommands() }`
40
40
  `WindowGroup`: that adds Help › Report a Problem… (⌥⌘R). Apps with their own feedback button
41
41
  call `Heresay.present()` from it and use `.heresay()` instead of the corner button.
42
42
 
43
- ## 4. Optional
43
+ ## 4. Who is signed in (required if people sign in)
44
+
45
+ Where the app learns who is signed in, and on sign-out:
46
+
47
+ ```swift
48
+ Heresay.identify(id: user.id, label: user.name, email: user.email)
49
+ Heresay.identify() // after sign-out
50
+ ```
51
+
52
+ Then nobody is asked their name to send a report, and the team can reply to them.
53
+
54
+ ## 5. Tell people it's there (required)
55
+
56
+ On macOS the report window lives under Help, and on iOS it's a small button; people who have never
57
+ seen it won't go looking. Call `Heresay.introduce()` once the person reaches the app's main
58
+ screen: after sign-in and after any onboarding, never over a login or first-run screen. It shows a
59
+ native alert, once per install, that says where to find it (Help › Report a Problem… (⌥⌘R) on
60
+ macOS, the Report button on iOS) and offers to open it. Later calls do nothing, so this is fine:
61
+
62
+ ```swift
63
+ MainView()
64
+ .onAppear { Heresay.introduce() }
65
+ ```
66
+
67
+ If the app already has a "What's new" or announcements screen, add a line there too. Don't
68
+ build a custom dialog for this; `introduce()` is the one.
69
+
70
+ ## 6. Optional
44
71
 
45
- - Signed-in users: `Heresay.identify(id: user.id, label: user.name)` after sign-in,
46
- `Heresay.identify()` after sign-out.
47
72
  - Screens: `Heresay.setScreen("Checkout")` in `.onAppear` of the main screens.
48
73
  - The app version is read from the bundle (`CFBundleShortVersionString` and build).
49
74
  - A brand colour: `Heresay.configure(key:url:accent: .purple)`.
50
75
 
51
76
  Change nothing else in the app.
52
77
 
53
- ## 5. Prove it
78
+ ## 7. Prove it
54
79
 
55
80
  Call `check_install`: it finds the key in this repo's code by itself (`found_in_code`). Build and
56
81
  run on a simulator or device and `seen_running` shows the SDK loaded. To test the whole path,
@@ -27,17 +27,45 @@ fine in source control. Put the tag as late as possible, loaded once:
27
27
 
28
28
  If a Content Security Policy is set, allow the Heresay origin in `script-src` and `connect-src`.
29
29
 
30
- ## 3. Optional, when the app has them
30
+ ## 3. Who is signed in (required if people sign in)
31
+
32
+ If the app has sign-in, tell Heresay who it is wherever the signed-in user becomes known (the
33
+ auth provider's listener, the session hook, the layout that reads the user), and clear it on
34
+ sign-out:
35
+
36
+ ```js
37
+ window.Heresay?.identify({ id: user.id, label: user.name, email: user.email });
38
+ window.Heresay?.identify(); // after sign-out
39
+ ```
40
+
41
+ Then the person is never asked their name to send a report, and the team can reply to them. It
42
+ follows whoever is signed in on that device, so apps with many users and many logins need
43
+ nothing else. Use the fields the app already has; leave out any it doesn't.
44
+
45
+ ## 4. Tell people it's there (required)
46
+
47
+ People who have never seen the Report button won't go looking for it. Heresay has a one-time
48
+ introduction: a small bubble over the button saying what it's for, shown once per device.
49
+
50
+ - Most apps: add `data-intro="auto"` to the tag. It appears a few seconds after the first page
51
+ load.
52
+ - Apps with sign-in, onboarding or a first-run tour: leave the attribute off and call
53
+ `window.Heresay?.introduce()` once the person reaches the main screen, so it never covers a
54
+ login form or competes with the tour. Calling it again later does nothing.
55
+ - If the app already has a "What's new" or announcements area, add a line there too, e.g.
56
+ "New: tell us what's broken or could be better with the Report button."
57
+
58
+ Don't build a custom dialog for this; `introduce()` is the one.
59
+
60
+ ## 5. Optional, when the app has them
31
61
 
32
- - Signed-in users: after sign-in call `window.Heresay?.identify({ id: user.id, label: user.name })`,
33
- and `window.Heresay?.identify()` after sign-out.
34
62
  - A version: add `data-version="<version>"` to the tag (from package.json, a build env var, ...).
35
63
  - Screens that change without the URL changing: `window.Heresay?.setScreen("<name>")` on each change.
36
64
  - A brand colour: `data-accent="#rrggbb"` (hex only).
37
65
 
38
66
  Change nothing else in the app.
39
67
 
40
- ## 4. Prove it
68
+ ## 6. Prove it
41
69
 
42
70
  Call `check_install`. It finds the key in this repo's code by itself (`found_in_code`). Then run
43
71
  the app and open it in a browser: `seen_running` shows the SDK loaded there. To test the whole
@@ -14,6 +14,10 @@ sees the outcome in the app, including the note you write when you mark it fixed
14
14
  3. **Claim before you start** (`claim_brief`), so another agent doesn't do the same work.
15
15
  4. **The fix note is for the reporter**, not for developers. See `write-note`.
16
16
  5. **Wrong repo?** `handoff` it to the repo where the fix belongs, with what you learned.
17
+ 6. **An install tells people it exists.** Call `introduce()` once the main screen appears, so
18
+ the people using the app learn there's a way to report things. On macOS it lives under Help,
19
+ where nobody looks unprompted. `check_install` lists anything still owed in `todo`; the
20
+ install isn't done until that list is empty.
17
21
 
18
22
  ## Which topic next
19
23
 
@@ -4,13 +4,15 @@
4
4
  * <script src="https://<sdk-host>/sdk.js" data-key="pk_..." defer></script>
5
5
  *
6
6
  * Optional attributes: data-version, data-user-id, data-user-label, data-position ("left"),
7
+ * data-intro ("auto": introduce the button a few seconds after the first page load),
7
8
  * data-accent ("#0f766e"; a hex colour, to match the host app. Defaults to Heresay peacock).
8
9
  * Optional calls, any time after the script runs:
9
- * Feedback.identify({ id, label }) who the host app says the user is
10
+ * Feedback.identify({ id, label, email }) who is signed in; then nobody is asked their name
10
11
  * Feedback.setVersion("1.4.0")
11
12
  * Feedback.setScreen("Checkout") for apps whose URL does not change per screen
12
13
  * Feedback.open()
13
- * Feedback.openPreferences() the reporter's own name, email, setup note and button side
14
+ * Feedback.introduce() once per device: a bubble saying the Report button is there
15
+ * Feedback.openPreferences() a note about their setup, and a name and email if not signed in
14
16
  *
15
17
  * No account, no cookies. The reporter is a random per-device id kept in localStorage, and
16
18
  * that id is also what lets them see what happened to their own reports. Their preferences are
@@ -33,6 +35,7 @@
33
35
  version: script.getAttribute('data-version') || null,
34
36
  userId: script.getAttribute('data-user-id') || null,
35
37
  userLabel: script.getAttribute('data-user-label') || null,
38
+ userEmail: script.getAttribute('data-user-email') || null,
36
39
  screen: null,
37
40
  type: null,
38
41
  reports: [],
@@ -81,8 +84,8 @@
81
84
  }
82
85
 
83
86
  /**
84
- * What the reporter chose to tell the team, and where they want the button. Per device and
85
- * per app. Everything is optional; an empty field is simply not sent.
87
+ * What the reporter chose to tell the team. Per device and per app. Everything is optional;
88
+ * an empty field is simply not sent.
86
89
  */
87
90
  var PREFS_KEY = 'fbsdk.prefs.' + KEY;
88
91
  function prefs() {
@@ -92,15 +95,16 @@
92
95
  } catch (e) { return {}; }
93
96
  }
94
97
  function savePrefs(p) { save(PREFS_KEY, JSON.stringify(p)); }
98
+ /** The host app said who is signed in. Then it speaks for them, and nobody types a name. */
99
+ function identified() { return !!(state.userId || state.userLabel || state.userEmail); }
95
100
  function reporter() {
96
101
  var p = prefs();
97
- var r = { name: p.name || null, email: p.email || null, note: p.note || null };
102
+ var mine = !identified();
103
+ var r = { name: mine && p.name || null, email: mine && p.email || null, note: p.note || null };
98
104
  return r.name || r.email || r.note ? r : null;
99
105
  }
100
- function side() {
101
- var p = prefs().side;
102
- return p === 'left' || p === 'right' ? p : (script.getAttribute('data-position') === 'left' ? 'left' : 'right');
103
- }
106
+ /** Where the button sits is the developer's choice (data-position), not the reporter's. */
107
+ var LEFT = script.getAttribute('data-position') === 'left';
104
108
 
105
109
  // ---- context ---------------------------------------------------------------------------
106
110
 
@@ -158,6 +162,7 @@
158
162
  browser: p.browser,
159
163
  user_id: state.userId,
160
164
  user_label: state.userLabel,
165
+ user_email: state.userEmail,
161
166
  framework: framework(),
162
167
  page_title: (document.title || '').trim() || null,
163
168
  page_url: pageUrl(),
@@ -221,6 +226,17 @@
221
226
  'padding:9px 14px;border-radius:999px;border:1px solid var(--fb-line);background:var(--fb-bg);color:var(--fb-fg);',
222
227
  'box-shadow:0 4px 14px rgba(0,0,0,.18);cursor:pointer;font-weight:600}',
223
228
  '.fab.left{right:auto;left:20px}',
229
+ '.intro{position:fixed;bottom:72px;right:20px;z-index:2147483000;width:min(300px,calc(100vw - 40px));padding:14px 16px;',
230
+ 'background:var(--fb-bg);border:1px solid var(--fb-line);border-radius:14px;box-shadow:0 12px 32px rgba(0,0,0,.22);animation:fb-in .25s ease-out}',
231
+ '.intro.left{right:auto;left:20px}',
232
+ '.intro:after{content:"";position:absolute;bottom:-7px;right:36px;width:12px;height:12px;background:var(--fb-bg);',
233
+ 'border-right:1px solid var(--fb-line);border-bottom:1px solid var(--fb-line);transform:rotate(45deg)}',
234
+ '.intro.left:after{right:auto;left:36px}',
235
+ '.intro b{display:block;margin-bottom:4px;font-weight:700}',
236
+ '.intro p{margin:0 0 12px;color:var(--fb-mute);font-size:13px}',
237
+ '.intro .row{margin-top:0;justify-content:flex-end}',
238
+ '@keyframes fb-in{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}',
239
+ '@media (prefers-reduced-motion:reduce){.intro{animation:none}}',
224
240
  '.mark{display:inline-flex;color:var(--fb-mark)}.mark svg{display:block}',
225
241
  '.dot{width:8px;height:8px;border-radius:50%;background:var(--fb-acc)}',
226
242
  '.scrim{position:fixed;inset:0;z-index:2147483001;background:rgba(0,0,0,.35);display:flex;align-items:flex-end;justify-content:flex-end;padding:16px}',
@@ -246,9 +262,9 @@
246
262
  '.field>span i{font-style:normal;font-weight:400;color:var(--fb-mute)}',
247
263
  '.field textarea{min-height:64px}',
248
264
  '.hint{display:block;font-size:12px;color:var(--fb-mute);margin-top:4px}',
249
- '.seg{display:flex;gap:6px}',
250
- '.seg button{flex:1;padding:8px;border:1px solid var(--fb-line);border-radius:10px;background:none;cursor:pointer}',
251
- '.seg button[aria-pressed=true]{border-color:var(--fb-acc);box-shadow:inset 0 0 0 1px var(--fb-acc)}',
265
+ '.who{display:flex;gap:10px;align-items:center;padding:10px 12px;margin:0 0 12px;border-radius:10px;background:var(--fb-line)}',
266
+ '.who b{display:block}',
267
+ '.avatar{flex:none;width:32px;height:32px;border-radius:50%;display:grid;place-items:center;background:var(--fb-acc);color:var(--fb-acc-fg);font-weight:700;font-size:13px}',
252
268
  '.link{border:0;background:none;padding:0;cursor:pointer;color:var(--fb-mute);text-decoration:underline;font-size:12px}',
253
269
  '.row{display:flex;justify-content:space-between;align-items:center;margin-top:10px;gap:8px}',
254
270
  '.small{font-size:12px;color:var(--fb-mute)}',
@@ -309,7 +325,7 @@
309
325
  }
310
326
  var fabDot = el('span', { class: 'dot', hidden: '' });
311
327
  var fab = el('button', {
312
- class: 'fab' + (side() === 'left' ? ' left' : ''),
328
+ class: 'fab' + (LEFT ? ' left' : ''),
313
329
  type: 'button', 'aria-haspopup': 'dialog', onclick: function () { open(); },
314
330
  }, [markEl(), el('span', { text: 'Report' }), fabDot]);
315
331
  root.appendChild(fab);
@@ -326,9 +342,10 @@
326
342
 
327
343
  function open(which) {
328
344
  if (scrim || dead) return;
345
+ if (bubble) { bubble.remove(); bubble = null; }
329
346
  lastFocus = document.activeElement;
330
347
  view = which || (unseen() ? 'mine' : 'new');
331
- scrim = el('div', { class: 'scrim' + (side() === 'left' ? ' left' : ''), onclick: function (e) { if (e.target === scrim) close(); } });
348
+ scrim = el('div', { class: 'scrim' + (LEFT ? ' left' : ''), onclick: function (e) { if (e.target === scrim) close(); } });
332
349
  scrim.addEventListener('keydown', function (e) { if (e.key === 'Escape') close(); });
333
350
  root.appendChild(scrim);
334
351
  renderPanel();
@@ -361,7 +378,7 @@
361
378
  view === 'new' ? formView() : view === 'prefs' ? prefsView() : listView(),
362
379
  ]);
363
380
  scrim.appendChild(panel);
364
- var first = panel.querySelector(view === 'new' ? '.type' : view === 'prefs' ? 'input' : '.tab[aria-selected=true]');
381
+ var first = panel.querySelector(view === 'new' ? '.type' : view === 'prefs' ? 'input,textarea' : '.tab[aria-selected=true]');
365
382
  if (first) first.focus();
366
383
  }
367
384
 
@@ -418,6 +435,7 @@
418
435
 
419
436
  function prefsView() {
420
437
  var p = prefs();
438
+ var signedIn = identified();
421
439
  var status = el('span', { class: 'small', role: 'status' });
422
440
  var field = function (label, input, hint) {
423
441
  return el('label', { class: 'field' }, [
@@ -429,23 +447,23 @@
429
447
  var email = el('input', { type: 'email', maxlength: '200', autocomplete: 'email' });
430
448
  var note = el('textarea', { maxlength: '500', placeholder: 'For example: I use a screen reader, or I am usually on slow Wi-Fi.' });
431
449
  name.value = p.name || ''; email.value = p.email || ''; note.value = p.note || '';
432
- var where = side();
433
- var sideBtn = function (id, label) {
434
- return el('button', {
435
- type: 'button', 'aria-pressed': String(where === id), 'data-side': id,
436
- onclick: function () {
437
- where = id;
438
- Array.prototype.forEach.call(seg.children, function (b) { b.setAttribute('aria-pressed', String(b.getAttribute('data-side') === id)); });
439
- },
440
- }, [document.createTextNode(label)]);
441
- };
442
- var seg = el('div', { class: 'seg', role: 'group', 'aria-label': 'Button position' }, [sideBtn('left', 'Left'), sideBtn('right', 'Right')]);
443
450
  var err = el('div', { class: 'err', role: 'alert' });
444
451
 
445
- function apply(next) {
446
- savePrefs(next);
447
- fab.classList.toggle('left', side() === 'left');
448
- if (scrim) scrim.classList.toggle('left', side() === 'left');
452
+ // Signed in: the app already told the team who this is. Say so, and ask nothing twice.
453
+ var who = null;
454
+ if (signedIn) {
455
+ var shown = state.userLabel || state.userEmail || 'your account';
456
+ var initials = (state.userLabel || state.userEmail || '?').split(/[\s@.]+/).filter(Boolean).slice(0, 2)
457
+ .map(function (w) { return w[0].toUpperCase(); }).join('');
458
+ who = el('div', { class: 'who' }, [
459
+ el('span', { class: 'avatar', 'aria-hidden': 'true', text: initials }),
460
+ el('div', {}, [
461
+ el('b', { text: 'Signed in as ' + shown }),
462
+ el('span', { class: 'small', text: state.userEmail && state.userLabel
463
+ ? state.userEmail + '. The team sees this with each report and can reply.'
464
+ : 'The team sees this with each report.' }),
465
+ ]),
466
+ ]);
449
467
  }
450
468
 
451
469
  return el('form', {
@@ -454,20 +472,19 @@
454
472
  e.preventDefault();
455
473
  err.textContent = '';
456
474
  var em = email.value.trim();
457
- if (em && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(em)) { err.textContent = 'That email does not look right.'; email.focus(); return; }
458
- apply({ name: name.value.trim(), email: em, note: note.value.trim(), side: where });
475
+ if (!signedIn && em && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(em)) { err.textContent = 'That email does not look right.'; email.focus(); return; }
476
+ savePrefs(signedIn ? { name: p.name, email: p.email, note: note.value.trim() }
477
+ : { name: name.value.trim(), email: em, note: note.value.trim() });
459
478
  status.textContent = 'Saved on this device.';
460
479
  },
461
480
  }, [
462
- state.userLabel ? el('p', { class: 'small', text: 'The app already tells the team you are ' + state.userLabel + '.' }) : null,
463
- field('Your name', name),
464
- field('Email', email, 'Only if you are happy for the team to reply to you.'),
481
+ who,
482
+ signedIn ? null : field('Your name', name),
483
+ signedIn ? null : field('Email', email, 'Only if you are happy for the team to reply to you.'),
465
484
  field('About your setup', note, 'Sent with every report, so you only say it once.'),
466
- el('div', { class: 'field' }, [el('span', { text: 'Button position' }), seg]),
467
485
  el('div', { class: 'row' }, [
468
486
  el('button', { class: 'link', type: 'button', text: 'Clear all', onclick: function () {
469
- apply({});
470
- view = 'prefs';
487
+ savePrefs({});
471
488
  renderPanel();
472
489
  } }),
473
490
  el('span', {}, [status, document.createTextNode(' '), el('button', { class: 'send', type: 'submit', text: 'Save' })]),
@@ -506,10 +523,34 @@
506
523
  });
507
524
  }
508
525
 
526
+ // ---- introduction ----------------------------------------------------------------------
527
+
528
+ // People can't use a button they never noticed. Once per device and app, a bubble says what it
529
+ // is for. The host app picks the moment (introduce()), or data-intro="auto" does it on load.
530
+ var INTRO_KEY = 'fbsdk.introduced.' + KEY;
531
+ var bubble = null;
532
+ function introduce() {
533
+ if (dead || bubble || scrim || load(INTRO_KEY)) return false;
534
+ save(INTRO_KEY, new Date().toISOString());
535
+ var done = function () { if (bubble) { bubble.remove(); bubble = null; } };
536
+ bubble = el('div', { class: 'intro' + (LEFT ? ' left' : ''), role: 'dialog', 'aria-label': 'About the Report button' }, [
537
+ el('b', { text: 'Something not right? Tell the team.' }),
538
+ el('p', { text: 'Use Report to say what is broken, confusing or could be better. A person reads every report, and you will see what happens to yours right here.' }),
539
+ el('div', { class: 'row' }, [
540
+ el('button', { class: 'link', type: 'button', text: 'Got it', onclick: done }),
541
+ el('button', { class: 'send', type: 'button', text: 'Try it', onclick: function () { done(); open('new'); } }),
542
+ ]),
543
+ ]);
544
+ bubble.addEventListener('keydown', function (e) { if (e.key === 'Escape') done(); });
545
+ root.appendChild(bubble);
546
+ return true;
547
+ }
548
+
509
549
  function mount() {
510
550
  if (dead) return;
511
551
  if (!host.isConnected) document.body.appendChild(host);
512
552
  refresh();
553
+ if (script.getAttribute('data-intro') === 'auto') setTimeout(introduce, 3000);
513
554
  }
514
555
  if (document.body) mount(); else document.addEventListener('DOMContentLoaded', mount);
515
556
 
@@ -519,11 +560,15 @@
519
560
  u = u || {};
520
561
  state.userId = u.id != null ? String(u.id) : null;
521
562
  state.userLabel = u.label != null ? String(u.label) : null;
563
+ state.userEmail = u.email != null ? String(u.email) : null;
564
+ if (scrim && view === 'prefs') renderPanel();
522
565
  },
523
566
  setVersion: function (v) { state.version = v != null ? String(v) : null; },
524
567
  setScreen: function (s) { state.screen = s != null ? String(s) : null; },
525
568
  open: function () { open('new'); },
526
569
  openPreferences: function () { open('prefs'); },
570
+ /** Show the one-time introduction now. False if it was already shown on this device. */
571
+ introduce: function () { return introduce(); },
527
572
  close: close,
528
573
  };
529
574
  })();