create-heresay 0.2.5 → 0.2.6
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 +1 -1
- package/release/VERSION +1 -1
- package/release/functions/lib/core/agent.js +1 -1
- package/release/functions/lib/core/handler.js +12 -4
- package/release/functions/lib/core/types.js +1 -0
- package/release/functions/lib/core/version.js +1 -1
- package/release/public/dashboard.js +53 -10
- package/release/public/docs.html +5 -4
- package/release/public/guides/install-apple.md +13 -4
- package/release/public/guides/install-web.md +17 -4
- package/release/public/sdk.js +43 -38
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-heresay",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
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.
|
|
1
|
+
0.2.6
|
|
@@ -282,7 +282,7 @@ 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
286
|
framework_detected: !!p.framework_detected, key: p.key, allowed_origins: p.allowed_origins,
|
|
287
287
|
});
|
|
288
288
|
//# 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
|
|
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,11 @@ 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' });
|
|
404
406
|
const project = {
|
|
405
407
|
id: newId('p_', 9), name, platform, framework: framework ? framework.toLowerCase() : null,
|
|
408
|
+
sign_in: isSignIn(body.sign_in) ? body.sign_in : null,
|
|
406
409
|
key: newId('pk_', 18), allowed_origins: [...new Set(origins)], created_by: me.email,
|
|
407
410
|
created_at: new Date(deps.now()).toISOString(),
|
|
408
411
|
};
|
|
@@ -430,6 +433,11 @@ async function updateProject(project, me, req, deps) {
|
|
|
430
433
|
patch.framework = f ? f.toLowerCase() : null;
|
|
431
434
|
patch.framework_detected = false;
|
|
432
435
|
}
|
|
436
|
+
if (body.sign_in !== undefined) {
|
|
437
|
+
if (body.sign_in !== null && !isSignIn(body.sign_in))
|
|
438
|
+
return json(400, { error: 'sign_in must be yes, no or null' });
|
|
439
|
+
patch.sign_in = body.sign_in;
|
|
440
|
+
}
|
|
433
441
|
if (body.allowed_origins !== undefined) {
|
|
434
442
|
const origins = [];
|
|
435
443
|
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) => ({
|
|
@@ -296,9 +296,24 @@
|
|
|
296
296
|
},
|
|
297
297
|
}));
|
|
298
298
|
});
|
|
299
|
+
// Signed-in apps pass who it is to Heresay, so the person reporting is never asked their name.
|
|
300
|
+
var signIn = editing && editing.sign_in ? editing.sign_in : 'unknown';
|
|
301
|
+
var signChips = el('div', { class: 'chips', role: 'radiogroup', 'aria-label': 'Do people sign in?' });
|
|
302
|
+
[['yes', 'Yes, they sign in'], ['no', 'No, anyone can use it'], ['unknown', 'Not sure']].forEach(function (c) {
|
|
303
|
+
signChips.appendChild(el('button', {
|
|
304
|
+
type: 'button', role: 'radio', 'aria-checked': String(c[0] === signIn), text: c[1],
|
|
305
|
+
onclick: function (e) {
|
|
306
|
+
signIn = c[0];
|
|
307
|
+
signChips.querySelectorAll('button').forEach(function (b) { b.setAttribute('aria-checked', String(b === e.target)); });
|
|
308
|
+
},
|
|
309
|
+
}));
|
|
310
|
+
});
|
|
311
|
+
var signField = el('div', { class: 'field' }, [el('span', { class: 'lbl' }, ['Do people sign in to your app? ', el('span', { class: 'opt', text: 'optional' })]), signChips,
|
|
312
|
+
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
313
|
var form = el('form', { class: 'form' }, native ? [
|
|
300
314
|
el('label', {}, ['Name', el('input', { name: 'name', required: true, maxlength: '80', placeholder: 'Acme for ' + platformOf(platform).label, autocomplete: 'off' })]),
|
|
301
315
|
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.' }),
|
|
316
|
+
signField,
|
|
302
317
|
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
318
|
err,
|
|
304
319
|
] : [
|
|
@@ -307,6 +322,7 @@
|
|
|
307
322
|
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
323
|
el('label', {}, ['Where it runs', el('textarea', { name: 'origins', rows: '3', placeholder: 'https://app.example.com\nhttp://localhost:3000' })]),
|
|
309
324
|
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.' }),
|
|
325
|
+
signField,
|
|
310
326
|
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
327
|
err,
|
|
312
328
|
]);
|
|
@@ -314,7 +330,7 @@
|
|
|
314
330
|
e.preventDefault();
|
|
315
331
|
err.textContent = '';
|
|
316
332
|
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 };
|
|
333
|
+
var body = { name: form.name.value, platform: platform, framework: native ? 'swiftui' : (fw === 'unknown' ? null : fw), allowed_origins: origins, sign_in: signIn === 'unknown' ? null : signIn };
|
|
318
334
|
// Editing keeps the key, so a line already pasted into the app keeps working.
|
|
319
335
|
(editing ? api('PATCH', '/projects/' + editing.id, body) : api('POST', '/projects', body))
|
|
320
336
|
.then(function (b) {
|
|
@@ -377,11 +393,29 @@
|
|
|
377
393
|
codeBlock(SWIFT_PACKAGE),
|
|
378
394
|
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
395
|
codeBlock(code),
|
|
380
|
-
el('p', { class: 'hint', html: 'Optional: <code>Heresay.
|
|
396
|
+
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.' }),
|
|
381
397
|
];
|
|
382
398
|
}
|
|
383
399
|
|
|
400
|
+
/** Signed-in apps: the one call that tells Heresay who it is. Required when they said yes. */
|
|
401
|
+
function identifyStep(p) {
|
|
402
|
+
var apple = platformOf(p.platform).apple;
|
|
403
|
+
var code = apple
|
|
404
|
+
? '// after sign-in\nHeresay.identify(id: user.id, label: user.name, email: user.email)\n\n// after sign-out\nHeresay.identify()'
|
|
405
|
+
: '// after sign-in\nwindow.Heresay?.identify({ id: user.id, label: user.name, email: user.email });\n\n// after sign-out\nwindow.Heresay?.identify();';
|
|
406
|
+
if (p.sign_in === 'yes') {
|
|
407
|
+
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)];
|
|
408
|
+
}
|
|
409
|
+
if (p.sign_in === 'no') return [];
|
|
410
|
+
return [el('details', { class: 'where' }, [el('summary', { text: 'Do people sign in to your app?' }),
|
|
411
|
+
el('p', { text: 'Then tell Heresay who is signed in, so nobody types their name to send a report:' }), codeBlock(code)])];
|
|
412
|
+
}
|
|
413
|
+
|
|
384
414
|
function byHand(p) {
|
|
415
|
+
return byHandSteps(p).concat(identifyStep(p));
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function byHandSteps(p) {
|
|
385
419
|
if (platformOf(p.platform).apple) return appleByHand(p);
|
|
386
420
|
var fw = p.framework;
|
|
387
421
|
if (fw && fw !== 'other') {
|
|
@@ -658,17 +692,26 @@
|
|
|
658
692
|
|
|
659
693
|
function ctxLine(c) {
|
|
660
694
|
return [c.page_title, c.route, c.app_version && ('v' + c.app_version), c.platform, c.os, c.browser,
|
|
661
|
-
c.viewport
|
|
695
|
+
c.viewport]
|
|
662
696
|
.filter(Boolean).join(' · ');
|
|
663
697
|
}
|
|
664
698
|
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
699
|
+
var mailto = function (e) { return el('a', { href: 'mailto:' + encodeURIComponent(e).replace(/%40/g, '@'), text: 'Reply' }); };
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Who sent it. "Signed in" is what the app said (identify); "From" is what the reporter typed
|
|
703
|
+
* in Preferences, their words, not verified.
|
|
704
|
+
*/
|
|
705
|
+
function reporterLine(c, rp) {
|
|
706
|
+
rp = rp || {};
|
|
707
|
+
var app = [c.user_label || c.user_id, c.user_email].filter(Boolean).join(' · ');
|
|
708
|
+
var typed = [rp.name, rp.email].filter(Boolean).join(' · ');
|
|
709
|
+
if (!app && !typed && !rp.note) return null;
|
|
710
|
+
var reply = c.user_email || rp.email;
|
|
669
711
|
return el('div', { class: 'ctx' }, [
|
|
670
|
-
|
|
671
|
-
|
|
712
|
+
app ? el('span', {}, [document.createTextNode('Signed in: ' + app + ' ')]) : null,
|
|
713
|
+
!app && typed ? el('span', {}, [document.createTextNode('From: ' + typed + ' ')]) : null,
|
|
714
|
+
reply ? mailto(reply) : null,
|
|
672
715
|
rp.note ? el('div', { text: 'About their setup: ' + rp.note }) : null,
|
|
673
716
|
]);
|
|
674
717
|
}
|
|
@@ -747,7 +790,7 @@
|
|
|
747
790
|
el('p', { class: 'text', text: r.text }),
|
|
748
791
|
el('div', { class: 'ctx', text: ctxLine(r.context) }),
|
|
749
792
|
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),
|
|
793
|
+
reporterLine(r.context, r.reporter),
|
|
751
794
|
r.decline_reason ? el('div', { class: 'reason', text: 'Declined: ' + r.decline_reason }) : null,
|
|
752
795
|
r.fix_note ? el('div', { class: 'reason', text: 'Told them: ' + r.fix_note }) : null,
|
|
753
796
|
r.status === 'accepted' && brief ? el('div', { class: 'brief-line' }, [
|
package/release/public/docs.html
CHANGED
|
@@ -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,15 @@
|
|
|
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
|
|
87
|
+
<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
88
|
<tr><td><code>Heresay.close()</code></td><td>Close the panel.</td></tr></table>
|
|
88
89
|
<p>Each report also carries the page it came from: its title, its address without the query string, and the window size.</p>
|
|
89
90
|
<pre><code><span class="k">// after your user signs in</span>
|
|
90
|
-
Heresay.identify({ id: user.id, label: user.name });
|
|
91
|
+
Heresay.identify({ id: user.id, label: user.name, email: user.email });
|
|
91
92
|
|
|
92
93
|
<span class="k">// single-page apps: name screens as the user moves</span>
|
|
93
94
|
router.afterEach((to) => Heresay.setScreen(to.name));</code></pre>
|
|
@@ -155,7 +156,7 @@ connect-src ORIGIN;</code></pre>
|
|
|
155
156
|
WindowGroup { ContentView().heresayReportButton() } <span class="k">// iOS: a Report button in the corner</span>
|
|
156
157
|
}
|
|
157
158
|
}</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>
|
|
159
|
+
<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.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
160
|
|
|
160
161
|
<h2 id="rest">Other platforms</h2>
|
|
161
162
|
<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,26 @@ 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.
|
|
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. Optional
|
|
44
55
|
|
|
45
|
-
- Signed-in users: `Heresay.identify(id: user.id, label: user.name)` after sign-in,
|
|
46
|
-
`Heresay.identify()` after sign-out.
|
|
47
56
|
- Screens: `Heresay.setScreen("Checkout")` in `.onAppear` of the main screens.
|
|
48
57
|
- The app version is read from the bundle (`CFBundleShortVersionString` and build).
|
|
49
58
|
- A brand colour: `Heresay.configure(key:url:accent: .purple)`.
|
|
50
59
|
|
|
51
60
|
Change nothing else in the app.
|
|
52
61
|
|
|
53
|
-
##
|
|
62
|
+
## 6. Prove it
|
|
54
63
|
|
|
55
64
|
Call `check_install`: it finds the key in this repo's code by itself (`found_in_code`). Build and
|
|
56
65
|
run on a simulator or device and `seen_running` shows the SDK loaded. To test the whole path,
|
|
@@ -27,17 +27,30 @@ 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.
|
|
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. Optional, when the app has them
|
|
31
46
|
|
|
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
47
|
- A version: add `data-version="<version>"` to the tag (from package.json, a build env var, ...).
|
|
35
48
|
- Screens that change without the URL changing: `window.Heresay?.setScreen("<name>")` on each change.
|
|
36
49
|
- A brand colour: `data-accent="#rrggbb"` (hex only).
|
|
37
50
|
|
|
38
51
|
Change nothing else in the app.
|
|
39
52
|
|
|
40
|
-
##
|
|
53
|
+
## 5. Prove it
|
|
41
54
|
|
|
42
55
|
Call `check_install`. It finds the key in this repo's code by itself (`found_in_code`). Then run
|
|
43
56
|
the app and open it in a browser: `seen_running` shows the SDK loaded there. To test the whole
|
package/release/public/sdk.js
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
* Optional attributes: data-version, data-user-id, data-user-label, data-position ("left"),
|
|
7
7
|
* data-accent ("#0f766e"; a hex colour, to match the host app. Defaults to Heresay peacock).
|
|
8
8
|
* Optional calls, any time after the script runs:
|
|
9
|
-
* Feedback.identify({ id, label }) who
|
|
9
|
+
* Feedback.identify({ id, label, email }) who is signed in; then nobody is asked their name
|
|
10
10
|
* Feedback.setVersion("1.4.0")
|
|
11
11
|
* Feedback.setScreen("Checkout") for apps whose URL does not change per screen
|
|
12
12
|
* Feedback.open()
|
|
13
|
-
* Feedback.openPreferences()
|
|
13
|
+
* Feedback.openPreferences() a note about their setup, and a name and email if not signed in
|
|
14
14
|
*
|
|
15
15
|
* No account, no cookies. The reporter is a random per-device id kept in localStorage, and
|
|
16
16
|
* that id is also what lets them see what happened to their own reports. Their preferences are
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
version: script.getAttribute('data-version') || null,
|
|
34
34
|
userId: script.getAttribute('data-user-id') || null,
|
|
35
35
|
userLabel: script.getAttribute('data-user-label') || null,
|
|
36
|
+
userEmail: script.getAttribute('data-user-email') || null,
|
|
36
37
|
screen: null,
|
|
37
38
|
type: null,
|
|
38
39
|
reports: [],
|
|
@@ -81,8 +82,8 @@
|
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
/**
|
|
84
|
-
* What the reporter chose to tell the team
|
|
85
|
-
*
|
|
85
|
+
* What the reporter chose to tell the team. Per device and per app. Everything is optional;
|
|
86
|
+
* an empty field is simply not sent.
|
|
86
87
|
*/
|
|
87
88
|
var PREFS_KEY = 'fbsdk.prefs.' + KEY;
|
|
88
89
|
function prefs() {
|
|
@@ -92,15 +93,16 @@
|
|
|
92
93
|
} catch (e) { return {}; }
|
|
93
94
|
}
|
|
94
95
|
function savePrefs(p) { save(PREFS_KEY, JSON.stringify(p)); }
|
|
96
|
+
/** The host app said who is signed in. Then it speaks for them, and nobody types a name. */
|
|
97
|
+
function identified() { return !!(state.userId || state.userLabel || state.userEmail); }
|
|
95
98
|
function reporter() {
|
|
96
99
|
var p = prefs();
|
|
97
|
-
var
|
|
100
|
+
var mine = !identified();
|
|
101
|
+
var r = { name: mine && p.name || null, email: mine && p.email || null, note: p.note || null };
|
|
98
102
|
return r.name || r.email || r.note ? r : null;
|
|
99
103
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return p === 'left' || p === 'right' ? p : (script.getAttribute('data-position') === 'left' ? 'left' : 'right');
|
|
103
|
-
}
|
|
104
|
+
/** Where the button sits is the developer's choice (data-position), not the reporter's. */
|
|
105
|
+
var LEFT = script.getAttribute('data-position') === 'left';
|
|
104
106
|
|
|
105
107
|
// ---- context ---------------------------------------------------------------------------
|
|
106
108
|
|
|
@@ -158,6 +160,7 @@
|
|
|
158
160
|
browser: p.browser,
|
|
159
161
|
user_id: state.userId,
|
|
160
162
|
user_label: state.userLabel,
|
|
163
|
+
user_email: state.userEmail,
|
|
161
164
|
framework: framework(),
|
|
162
165
|
page_title: (document.title || '').trim() || null,
|
|
163
166
|
page_url: pageUrl(),
|
|
@@ -246,9 +249,9 @@
|
|
|
246
249
|
'.field>span i{font-style:normal;font-weight:400;color:var(--fb-mute)}',
|
|
247
250
|
'.field textarea{min-height:64px}',
|
|
248
251
|
'.hint{display:block;font-size:12px;color:var(--fb-mute);margin-top:4px}',
|
|
249
|
-
'.
|
|
250
|
-
'.
|
|
251
|
-
'.
|
|
252
|
+
'.who{display:flex;gap:10px;align-items:center;padding:10px 12px;margin:0 0 12px;border-radius:10px;background:var(--fb-line)}',
|
|
253
|
+
'.who b{display:block}',
|
|
254
|
+
'.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
255
|
'.link{border:0;background:none;padding:0;cursor:pointer;color:var(--fb-mute);text-decoration:underline;font-size:12px}',
|
|
253
256
|
'.row{display:flex;justify-content:space-between;align-items:center;margin-top:10px;gap:8px}',
|
|
254
257
|
'.small{font-size:12px;color:var(--fb-mute)}',
|
|
@@ -309,7 +312,7 @@
|
|
|
309
312
|
}
|
|
310
313
|
var fabDot = el('span', { class: 'dot', hidden: '' });
|
|
311
314
|
var fab = el('button', {
|
|
312
|
-
class: 'fab' + (
|
|
315
|
+
class: 'fab' + (LEFT ? ' left' : ''),
|
|
313
316
|
type: 'button', 'aria-haspopup': 'dialog', onclick: function () { open(); },
|
|
314
317
|
}, [markEl(), el('span', { text: 'Report' }), fabDot]);
|
|
315
318
|
root.appendChild(fab);
|
|
@@ -328,7 +331,7 @@
|
|
|
328
331
|
if (scrim || dead) return;
|
|
329
332
|
lastFocus = document.activeElement;
|
|
330
333
|
view = which || (unseen() ? 'mine' : 'new');
|
|
331
|
-
scrim = el('div', { class: 'scrim' + (
|
|
334
|
+
scrim = el('div', { class: 'scrim' + (LEFT ? ' left' : ''), onclick: function (e) { if (e.target === scrim) close(); } });
|
|
332
335
|
scrim.addEventListener('keydown', function (e) { if (e.key === 'Escape') close(); });
|
|
333
336
|
root.appendChild(scrim);
|
|
334
337
|
renderPanel();
|
|
@@ -361,7 +364,7 @@
|
|
|
361
364
|
view === 'new' ? formView() : view === 'prefs' ? prefsView() : listView(),
|
|
362
365
|
]);
|
|
363
366
|
scrim.appendChild(panel);
|
|
364
|
-
var first = panel.querySelector(view === 'new' ? '.type' : view === 'prefs' ? 'input' : '.tab[aria-selected=true]');
|
|
367
|
+
var first = panel.querySelector(view === 'new' ? '.type' : view === 'prefs' ? 'input,textarea' : '.tab[aria-selected=true]');
|
|
365
368
|
if (first) first.focus();
|
|
366
369
|
}
|
|
367
370
|
|
|
@@ -418,6 +421,7 @@
|
|
|
418
421
|
|
|
419
422
|
function prefsView() {
|
|
420
423
|
var p = prefs();
|
|
424
|
+
var signedIn = identified();
|
|
421
425
|
var status = el('span', { class: 'small', role: 'status' });
|
|
422
426
|
var field = function (label, input, hint) {
|
|
423
427
|
return el('label', { class: 'field' }, [
|
|
@@ -429,23 +433,23 @@
|
|
|
429
433
|
var email = el('input', { type: 'email', maxlength: '200', autocomplete: 'email' });
|
|
430
434
|
var note = el('textarea', { maxlength: '500', placeholder: 'For example: I use a screen reader, or I am usually on slow Wi-Fi.' });
|
|
431
435
|
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
436
|
var err = el('div', { class: 'err', role: 'alert' });
|
|
444
437
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
438
|
+
// Signed in: the app already told the team who this is. Say so, and ask nothing twice.
|
|
439
|
+
var who = null;
|
|
440
|
+
if (signedIn) {
|
|
441
|
+
var shown = state.userLabel || state.userEmail || 'your account';
|
|
442
|
+
var initials = (state.userLabel || state.userEmail || '?').split(/[\s@.]+/).filter(Boolean).slice(0, 2)
|
|
443
|
+
.map(function (w) { return w[0].toUpperCase(); }).join('');
|
|
444
|
+
who = el('div', { class: 'who' }, [
|
|
445
|
+
el('span', { class: 'avatar', 'aria-hidden': 'true', text: initials }),
|
|
446
|
+
el('div', {}, [
|
|
447
|
+
el('b', { text: 'Signed in as ' + shown }),
|
|
448
|
+
el('span', { class: 'small', text: state.userEmail && state.userLabel
|
|
449
|
+
? state.userEmail + '. The team sees this with each report and can reply.'
|
|
450
|
+
: 'The team sees this with each report.' }),
|
|
451
|
+
]),
|
|
452
|
+
]);
|
|
449
453
|
}
|
|
450
454
|
|
|
451
455
|
return el('form', {
|
|
@@ -454,20 +458,19 @@
|
|
|
454
458
|
e.preventDefault();
|
|
455
459
|
err.textContent = '';
|
|
456
460
|
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
|
-
|
|
461
|
+
if (!signedIn && em && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(em)) { err.textContent = 'That email does not look right.'; email.focus(); return; }
|
|
462
|
+
savePrefs(signedIn ? { name: p.name, email: p.email, note: note.value.trim() }
|
|
463
|
+
: { name: name.value.trim(), email: em, note: note.value.trim() });
|
|
459
464
|
status.textContent = 'Saved on this device.';
|
|
460
465
|
},
|
|
461
466
|
}, [
|
|
462
|
-
|
|
463
|
-
field('Your name', name),
|
|
464
|
-
field('Email', email, 'Only if you are happy for the team to reply to you.'),
|
|
467
|
+
who,
|
|
468
|
+
signedIn ? null : field('Your name', name),
|
|
469
|
+
signedIn ? null : field('Email', email, 'Only if you are happy for the team to reply to you.'),
|
|
465
470
|
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
471
|
el('div', { class: 'row' }, [
|
|
468
472
|
el('button', { class: 'link', type: 'button', text: 'Clear all', onclick: function () {
|
|
469
|
-
|
|
470
|
-
view = 'prefs';
|
|
473
|
+
savePrefs({});
|
|
471
474
|
renderPanel();
|
|
472
475
|
} }),
|
|
473
476
|
el('span', {}, [status, document.createTextNode(' '), el('button', { class: 'send', type: 'submit', text: 'Save' })]),
|
|
@@ -519,6 +522,8 @@
|
|
|
519
522
|
u = u || {};
|
|
520
523
|
state.userId = u.id != null ? String(u.id) : null;
|
|
521
524
|
state.userLabel = u.label != null ? String(u.label) : null;
|
|
525
|
+
state.userEmail = u.email != null ? String(u.email) : null;
|
|
526
|
+
if (scrim && view === 'prefs') renderPanel();
|
|
522
527
|
},
|
|
523
528
|
setVersion: function (v) { state.version = v != null ? String(v) : null; },
|
|
524
529
|
setScreen: function (s) { state.screen = s != null ? String(s) : null; },
|