create-heresay 0.2.4 → 0.2.5

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.4",
3
+ "version": "0.2.5",
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.4
1
+ 0.2.5
@@ -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.4';
2
+ export const VERSION = '0.2.5';
3
3
  //# sourceMappingURL=version.js.map
@@ -405,6 +405,15 @@
405
405
  ];
406
406
  }
407
407
 
408
+ /** The unused prompt token last made for an app in this tab (hst_<id>_<secret>), or set it. */
409
+ function promptToken(appId, token) {
410
+ var k = 'heresay.prompt-token.' + appId;
411
+ try {
412
+ if (token === undefined) return sessionStorage.getItem(k);
413
+ sessionStorage.setItem(k, token);
414
+ } catch (e) { return null; }
415
+ }
416
+
408
417
  /** One prompt that connects the repo, installs Heresay and waits for the test report. */
409
418
  function onePrompt(p, token) {
410
419
  var apple = platformOf(p.platform).apple;
@@ -441,11 +450,23 @@
441
450
  var promptBox = el('div', { class: 'copy-prompt' });
442
451
  var copyBtn = el('button', { class: 'btn primary', type: 'button', text: 'Copy prompt' });
443
452
  var copyNote = el('p', { class: 'hint', role: 'status', text: 'It connects the repo, installs Heresay and verifies it. This page ticks over by itself when it’s done.' });
444
- var promptText = null;
445
453
  function makePrompt() {
446
- if (promptText) return Promise.resolve(promptText);
447
- // No repo yet: the token binds to whichever repo the agent runs it in.
448
- return api('POST', '/agent-tokens', { app_ids: [p.id] }).then(function (b) { return (promptText = onePrompt(p, b.token)); });
454
+ // The same prompt every time for this app in this tab, so going back to explore while an
455
+ // agent works on it doesn't hand out a second token. A new one only once the last is used
456
+ // by a repo or revoked. No repo yet: the token binds to whichever repo runs it first.
457
+ var cached = promptToken(p.id);
458
+ var fresh = function () {
459
+ return api('POST', '/agent-tokens', { app_ids: [p.id] }).then(function (b) {
460
+ promptToken(p.id, b.token);
461
+ return onePrompt(p, b.token);
462
+ });
463
+ };
464
+ if (!cached) return fresh();
465
+ var id = cached.split('_')[1];
466
+ return api('GET', '/agent-tokens').then(function (b) {
467
+ var t = b.tokens.filter(function (x) { return x.id === id; })[0];
468
+ return t && !t.repo ? onePrompt(p, cached) : fresh();
469
+ });
449
470
  }
450
471
  copyBtn.onclick = function () {
451
472
  copyBtn.disabled = true;