create-heresay 0.2.45 → 0.2.47

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.45",
3
+ "version": "0.2.47",
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.45
1
+ 0.2.47
@@ -28,6 +28,10 @@
28
28
  "**/node_modules/**"
29
29
  ],
30
30
  "rewrites": [
31
+ {
32
+ "source": "/",
33
+ "destination": "/app/index.html"
34
+ },
31
35
  {
32
36
  "source": "/v1/**",
33
37
  "function": {
@@ -235,7 +235,7 @@ async function findApp(v, deps) {
235
235
  throw new ToolError(`No app called "${want}". The apps are: ${ps.map((p) => p.name).join(', ') || 'none yet'}.`);
236
236
  return hit;
237
237
  }
238
- const dashboardLink = (req, deps, p) => `${baseUrl(req, deps)}/app/#/apps/${p.id}`;
238
+ const dashboardLink = (req, deps, p) => `${baseUrl(req, deps)}/#/apps/${p.id}`;
239
239
  const appNames = (ps) => ps.map((p) => `${p.name} (${p.platform})`).join(', ');
240
240
  /** A preview, nothing sent: which app, what type, the text, and where else it could go. */
241
241
  async function draftRequest(a, member, via, deps) {
@@ -237,7 +237,7 @@ export async function notify(event, project, reportId, deps) {
237
237
  const found = await deps.store.getReport(project.id, reportId).catch(() => null);
238
238
  const type = (found && TYPE[found.type]) || null;
239
239
  const origin = deps.selfOrigins?.[0];
240
- const link = origin ? `${origin}/app/#/apps/${encodeURIComponent(project.id)}` : null;
240
+ const link = origin ? `${origin}/#/apps/${encodeURIComponent(project.id)}` : null;
241
241
  const meta = [type ? `${type[0]} ${type[1]}` : null, reportId];
242
242
  const text = [`${emoji} ${head} · ${project.name}`, `${labels[event]}.`, meta.filter(Boolean).join(' · ')].join('\n') + (link ? `\n${link}` : '');
243
243
  // Telegram gets bold and a link; the app name is the team's own, escaped, and nothing from a reporter is in it.
@@ -170,7 +170,7 @@ export async function authorize(req, deps) {
170
170
  if (v)
171
171
  keep.set(k, v);
172
172
  }
173
- return json(302, { redirect: true }, { location: `${baseUrl(req, deps)}/app/#/authorize?${keep}` });
173
+ return json(302, { redirect: true }, { location: `${baseUrl(req, deps)}/#/authorize?${keep}` });
174
174
  }
175
175
  /** What the dashboard shows on the "Allow?" page, before anyone says yes. */
176
176
  export async function describeAsk(q, deps) {
@@ -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.45';
2
+ export const VERSION = '0.2.47';
3
3
  //# sourceMappingURL=version.js.map
@@ -156,7 +156,10 @@ function reserved(res, path) {
156
156
  }
157
157
  async function file(res, path) {
158
158
  let rel = path === '/sdk/v1.js' ? '/sdk.js' : path;
159
- if (rel.endsWith('/'))
159
+ // The dashboard is the root of a Heresay; /app/ is its older address and keeps working.
160
+ if (rel === '/')
161
+ rel = '/app/index.html';
162
+ else if (rel.endsWith('/'))
160
163
  rel += 'index.html';
161
164
  const full = join(PUBLIC_DIR, normalize(rel));
162
165
  if (!full.startsWith(PUBLIC_DIR + '/') || rel.split('/').some((p) => p.startsWith('.'))) {
@@ -188,7 +188,7 @@
188
188
  gateMsg('Sending…');
189
189
  // A chat app sent them here to say yes: come back to that page after the link.
190
190
  if (/^#\/authorize\?/.test(location.hash)) localStorage.setItem('heresay.after', JSON.stringify({ hash: location.hash, at: Date.now() }));
191
- auth.sendSignInLinkToEmail(email, { url: location.origin + '/app/', handleCodeInApp: true })
191
+ auth.sendSignInLinkToEmail(email, { url: location.origin + '/', handleCodeInApp: true })
192
192
  .then(function () {
193
193
  localStorage.setItem('heresay.email', email);
194
194
  gateMsg('Check your inbox at ' + email + '. The link signs you in here. It can take a minute, and may land in spam.');
@@ -201,11 +201,11 @@
201
201
 
202
202
  function finishLink(email) {
203
203
  auth.signInWithEmailLink(email, location.href)
204
- .then(function () { localStorage.removeItem('heresay.email'); history.replaceState(null, '', '/app/'); finishingLink = false; })
204
+ .then(function () { localStorage.removeItem('heresay.email'); history.replaceState(null, '', location.pathname); finishingLink = false; })
205
205
  .catch(function (x) {
206
206
  gateMsg(x.code === 'auth/invalid-action-code'
207
207
  ? 'That link has expired or was already used. Ask for a new one.' : x.message, true);
208
- history.replaceState(null, '', '/app/'); finishingLink = false;
208
+ history.replaceState(null, '', location.pathname); finishingLink = false;
209
209
  $('link-form').querySelector('button').textContent = 'Email me a sign-in link';
210
210
  });
211
211
  }
@@ -233,7 +233,7 @@
233
233
  try {
234
234
  var after = JSON.parse(localStorage.getItem('heresay.after') || 'null');
235
235
  localStorage.removeItem('heresay.after');
236
- if (after && Date.now() - after.at < 15 * 60000 && !location.hash) history.replaceState(null, '', '/app/' + after.hash);
236
+ if (after && Date.now() - after.at < 15 * 60000 && !location.hash) history.replaceState(null, '', location.pathname + after.hash);
237
237
  } catch (e) { /* nothing saved */ }
238
238
  route(); // first, so the view is already waiting when the app is shown
239
239
  show('app');
@@ -2767,7 +2767,7 @@
2767
2767
  draw(b.members);
2768
2768
  form.reset();
2769
2769
  err.className = 'ok-msg';
2770
- err.textContent = 'Added. Send them this address; they sign in with that email: ' + location.origin + '/app/';
2770
+ err.textContent = 'Added. Send them this address; they sign in with that email: ' + location.origin;
2771
2771
  }).catch(function (x) { err.className = 'err'; err.textContent = x.message; });
2772
2772
  };
2773
2773
  view.appendChild(el('section', { class: 'card' }, [el('h2', { text: 'Add someone' }), form]));
@@ -12,8 +12,8 @@
12
12
  <body>
13
13
  <div class="wrap">
14
14
  <nav class="nav" aria-label="Main">
15
- <a href="/" aria-label="Heresay home"><img src="/logo.svg" alt="Heresay" height="34"></a>
16
- <div class="links"><a href="/#how">How it works</a><a href="/docs.html">Docs</a><a class="keep" href="/app/">Sign in</a></div>
15
+ <a href="https://sibhimanyu.github.io/heresay/" aria-label="Heresay home"><img src="/logo.svg" alt="Heresay" height="34"></a>
16
+ <div class="links"><a href="https://sibhimanyu.github.io/heresay/how-it-works.html">How it works</a><a href="/docs.html">Docs</a><a class="keep" href="/">Sign in</a></div>
17
17
  <a class="btn btn-p btn-sm" href="#self-host">Set up</a>
18
18
  </nav>
19
19
 
@@ -36,7 +36,7 @@
36
36
 
37
37
  <h2 id="quick-start">Add it to an app</h2>
38
38
  <ol>
39
- <li><a href="/app/">Sign in</a> to your dashboard and choose <b>Add an app</b>. Pick the platform, give it a name, and list the websites it runs on, for example <code>https://app.example.com</code> and <code>http://localhost:3000</code>.</li>
39
+ <li><a href="/">Sign in</a> to your dashboard and choose <b>Add an app</b>. Pick the platform, give it a name, and list the websites it runs on, for example <code>https://app.example.com</code> and <code>http://localhost:3000</code>.</li>
40
40
  <li>Copy the line the dashboard shows you (it has steps for Next.js, Nuxt and others too) and paste it before <code>&lt;/body&gt;</code> on every page:</li>
41
41
  </ol>
42
42
  <pre><code><span class="k">&lt;script</span> src="ORIGIN/sdk/v1.js" data-key="pk_your_key" defer<span class="k">&gt;&lt;/script&gt;</span></code></pre>
@@ -214,7 +214,7 @@ connect-src ORIGIN;</code></pre>
214
214
  </main>
215
215
  </div>
216
216
  </div>
217
- <footer class="site"><div class="wrap"><span>© 2026 Heresay</span><span><a href="/">Home</a> · <a href="/app/">Sign in</a></span></div></footer>
217
+ <footer class="site"><div class="wrap"><span>© 2026 Heresay</span><span><a href="https://sibhimanyu.github.io/heresay/">Home</a> · <a href="/">Sign in</a></span></div></footer>
218
218
  <script>
219
219
  document.querySelectorAll('[data-origin]').forEach(function (el) { el.innerHTML = el.innerHTML.replace(/ORIGIN/g, location.origin); });
220
220
  </script>
package/src/cli.mjs CHANGED
@@ -61,7 +61,8 @@ const HELP = `
61
61
 
62
62
  Setup flags, to skip questions:
63
63
  --name <name> --project-id <id> --region us-central1|asia-south1|europe-west1
64
- --billing <account> --owner <email> --yes (take every default, never ask)
64
+ --billing <account> --owner <email> --site <name> (your address: <name>.web.app)
65
+ --yes (take every default, never ask)
65
66
 
66
67
  Free plan, no billing (Spark): the API runs on a host you choose instead of Cloud Functions.
67
68
  --lite --origin https://your-host.example see docs/lite.md
@@ -92,9 +93,12 @@ function openInBrowser(target) {
92
93
  }
93
94
 
94
95
  /** The named Hosting site a saved Heresay lives on, from its saved address. */
95
- const savedSite = (rec) => /^https:\/\/([a-z0-9-]+)\.web\.app$/.exec(rec?.url ?? '')?.[1];
96
+ const savedSite = (id, rec) => {
97
+ const site = /^https:\/\/([a-z0-9-]+)\.web\.app$/.exec(rec?.url ?? '')?.[1];
98
+ return site && site !== id ? site : undefined; // the project's default site isn't a named one
99
+ };
96
100
  const savedCtx = (id, rec) => ({ id, name: rec.name, region: rec.region, billing: rec.billing, owner: rec.owner,
97
- lite: rec.lite, origin: rec.origin, site: savedSite(rec), onlySite: rec.only_site });
101
+ lite: rec.lite, origin: rec.origin, site: savedSite(id, rec), onlySite: rec.only_site });
98
102
 
99
103
  const slug = (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
100
104
  function suggestId(name) {
@@ -187,7 +191,7 @@ async function setup(args) {
187
191
  'This sets up your own Heresay in your Google account:',
188
192
  '',
189
193
  ` ${peacock('•')} A new Firebase project, owned by you`,
190
- ` ${peacock('•')} Its database, sign-in and hosting`,
194
+ ` ${peacock('•')} Its database, sign-in, and an address like heresay-<name>.web.app`,
191
195
  ` ${peacock('•')} The Heresay dashboard, API and SDK, deployed to it`,
192
196
  '',
193
197
  'Heresay’s API runs on Cloud Functions, which needs Firebase’s',
@@ -242,7 +246,9 @@ async function setup(args) {
242
246
  validate: (v) => (!v || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v) ? undefined : 'That isn’t an email address'),
243
247
  })));
244
248
 
245
- ctx = { id, name, region, billing, owner, version, account: email, lite, origin };
249
+ const askedSite = args.site ? String(args.site).toLowerCase() : undefined;
250
+ if (askedSite && !steps.validSite(askedSite)) { p.log.error(`${askedSite} can’t be an address: 6 to 30 lowercase letters, digits and dashes, starting with a letter.`); process.exit(1); }
251
+ ctx = { id, name, region, billing, owner, version, account: email, lite, origin, askedSite };
246
252
  state.update(id, { name, region, billing, owner, lite, origin, url: lite ? origin : url(id), created_at: new Date().toISOString(), done: {} });
247
253
  if (!args.yes) p.log.message(pc.dim('You can add teammates in the dashboard later.'));
248
254
  }
@@ -262,7 +268,7 @@ async function setup(args) {
262
268
  pc.dim(' docker build -t heresay-lite . && docker run --rm -p 8080:8080 --env-file lite.env heresay-lite'),
263
269
  '',
264
270
  `On a host, build that folder as a Docker service and add each line of lite.env as an environment variable. It must answer at ${pc.bold(ctx.origin)}.`,
265
- `Then open ${ctx.origin}/app/ and sign in as ${ctx.owner}. Check with: npx create-heresay status`,
271
+ `Then open ${ctx.origin} and sign in as ${ctx.owner}. Check with: npx create-heresay status`,
266
272
  ].join('\n'), 'Your Heresay is ready for a host');
267
273
  p.outro('Every report gets a hearing.');
268
274
  return;
@@ -278,7 +284,7 @@ async function setup(args) {
278
284
  ].join('\n'), 'Your Heresay is live');
279
285
  if (!args.yes && process.stdout.isTTY) {
280
286
  const open = bail(await p.confirm({ message: 'Open it now?' }));
281
- if (open) openInBrowser(url(ctx.id) + '/app/');
287
+ if (open) openInBrowser(url(ctx.id));
282
288
  }
283
289
  p.outro('Every report gets a hearing.');
284
290
  }
@@ -326,6 +332,7 @@ const BUILD = [
326
332
  ['project', 'Creating the project', 'Project created', steps.project],
327
333
  ['billing', 'Linking billing', 'Billing linked', steps.billing],
328
334
  ['services', 'Switching on services', 'Services switched on', steps.services],
335
+ ['site', 'Choosing your address', 'Address reserved', steps.site],
329
336
  ['database', 'Creating the database', 'Database created', steps.database],
330
337
  ['signin', 'Setting up sign-in', 'Sign-in set up', steps.signIn],
331
338
  ['owner', 'Adding you as owner', 'Owner added', steps.owner],
@@ -361,6 +368,7 @@ async function build(ctx, only) {
361
368
  const secs = Math.round((Date.now() - started) / 1000);
362
369
  s.stop(`${title.padEnd(22)} ${pc.dim(String(detail ?? ''))}${secs > 20 ? pc.dim(` (${secs}s)`) : ''}`);
363
370
  state.markDone(ctx.id, key);
371
+ if (key === 'site' && ctx.site) state.update(ctx.id, { url: `https://${ctx.site}.web.app` });
364
372
  if (key === 'signin' && ctx.googleError) {
365
373
  p.log.warn(`Google sign-in couldn’t be switched on (${ctx.googleError}). Email links work. To add Google later: https://console.firebase.google.com/project/${ctx.id}/authentication/providers`);
366
374
  }
@@ -432,7 +440,7 @@ async function status() {
432
440
  const rec = all[id];
433
441
  const h = await health(id);
434
442
  const lines = [
435
- `${pc.dim('Dashboard')} ${url(id)}/app/`,
443
+ `${pc.dim('Dashboard')} ${url(id)}`,
436
444
  `${pc.dim('Region ')} ${rec.region}`,
437
445
  `${pc.dim('Version ')} ${h ? h.version : pc.red('not answering')}${h && h.version !== bundled ? pc.dim(` (${bundled} available: npx create-heresay update)`) : ''}`,
438
446
  `${pc.dim('Setup ')} ${rec.done?.verify ? 'complete' : pc.yellow('unfinished: run npx create-heresay to carry on')}`,
@@ -444,8 +452,8 @@ async function status() {
444
452
 
445
453
  async function open(args) {
446
454
  const id = await pickInstance('open', args);
447
- openInBrowser(`${url(id)}/app/`);
448
- console.log(`${url(id)}/app/`);
455
+ openInBrowser(url(id));
456
+ console.log(url(id));
449
457
  }
450
458
 
451
459
  async function removeCmd(args) {
@@ -519,7 +527,7 @@ async function restoreCmd(args) {
519
527
  s.start('Writing');
520
528
  try { await backup.restore(g, b, { base: FS, project: id, say: (m) => s.message(m) }); } catch (e) { s.error('Stopped part way; run it again to finish'); fail(e); }
521
529
  s.stop(`Restored ${b.documents.length} documents`);
522
- p.outro(`Sign in at ${url(id)}/app/ with a team email. Reconnect repos with npx heresay connect --url ${url(id)}.`);
530
+ p.outro(`Sign in at ${url(id)} with a team email. Reconnect repos with npx heresay connect --url ${url(id)}.`);
523
531
  }
524
532
 
525
533
  export async function main(argv) {
package/src/steps.mjs CHANGED
@@ -112,6 +112,65 @@ export async function services(ctx, say) {
112
112
  return 'Firestore, Functions, Auth, Hosting';
113
113
  }
114
114
 
115
+ // ---- 3b. address ------------------------------------------------------------------------
116
+ //
117
+ // The project id carries a random tail (heresay-acme-7k2q) because project ids are global and
118
+ // permanent. The address people type and paste into their apps shouldn't: a named Hosting site
119
+ // gives heresay-acme.web.app, and it can later move to another project without changing.
120
+
121
+ const HOSTING = 'https://firebasehosting.googleapis.com/v1beta1';
122
+
123
+ /** Site names to try, best first: the one asked for, else heresay-<name>, then with the project's tail. */
124
+ export function siteCandidates(name, id, asked) {
125
+ if (asked) return [asked];
126
+ const slug = String(name ?? '').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
127
+ // Shorten the name, never the suffix, and never leave a dangling or doubled dash.
128
+ const join = (...parts) => {
129
+ const suffix = parts.slice(1).join('-');
130
+ const room = 30 - (suffix ? suffix.length + 1 : 0);
131
+ const head = parts[0].slice(0, room).replace(/-+$/, '');
132
+ return (suffix ? `${head}-${suffix}` : head).replace(/-{2,}/g, '-');
133
+ };
134
+ const base = join(slug ? `heresay-${slug}` : 'heresay');
135
+ const out = [base, join(base, 'team'), join(base, id.split('-').pop())].filter((c) => validSite(c));
136
+ return [...new Set(out)];
137
+ }
138
+ export const validSite = (s) => /^[a-z][a-z0-9-]{4,28}[a-z0-9]$/.test(s);
139
+
140
+ /** True if created, false if the name is taken (by anyone). Retries only while Hosting is still switching on. */
141
+ async function createSite(project, siteId) {
142
+ const until = Date.now() + 90_000;
143
+ for (;;) {
144
+ try {
145
+ await g('POST', `${HOSTING}/projects/${project}/sites?siteId=${siteId}`, { project, body: {} });
146
+ return true;
147
+ } catch (e) {
148
+ if (e.status === 409 || /already exists|unavailable|not available|taken|reserved/i.test(e.message)) return false;
149
+ if ((e.status === 403 || e.status === 404) && Date.now() < until) { await new Promise((r) => setTimeout(r, 5000)); continue; }
150
+ throw e;
151
+ }
152
+ }
153
+ }
154
+
155
+ export async function site(ctx, say) {
156
+ if (ctx.site) {
157
+ const mine = await g('GET', `${HOSTING}/projects/${ctx.id}/sites/${ctx.site}`, { project: ctx.id, missingOk: true });
158
+ if (mine) return `${ctx.site}.web.app`;
159
+ }
160
+ const tried = [];
161
+ for (const c of siteCandidates(ctx.name, ctx.id, ctx.askedSite)) {
162
+ say(`Reserving ${c}.web.app`);
163
+ // Ours already (a run that stopped right after reserving it): use it, don't count it as taken.
164
+ const ours = await g('GET', `${HOSTING}/projects/${ctx.id}/sites/${c}`, { project: ctx.id, missingOk: true }).catch(() => null);
165
+ if (ours || await createSite(ctx.id, c)) { ctx.site = c; return `${c}.web.app`; }
166
+ tried.push(c);
167
+ }
168
+ if (ctx.askedSite) throw new StepError(`${ctx.askedSite}.web.app is taken.`, 'Run this again with another --site name.');
169
+ // Every nice name is taken: the project's default address still works.
170
+ ctx.site = null;
171
+ return `${ctx.id}.web.app (${tried.join(', ')} taken)`;
172
+ }
173
+
115
174
  // ---- 4. database ------------------------------------------------------------------------
116
175
 
117
176
  export async function database(ctx, say) {
@@ -305,8 +364,9 @@ export async function verify(ctx, say) {
305
364
  for (;;) {
306
365
  try {
307
366
  const h = await (await fetch(`${base}/v1/health`)).json();
308
- const app = await fetch(`${base}/app/`);
309
- if (h.ok && app.ok) return `API ${h.version}, dashboard loads`;
367
+ // The dashboard is the site's root page; check it really is the dashboard, not a leftover page.
368
+ const app = await fetch(`${base}/`);
369
+ if (h.ok && app.ok && (await app.text()).includes('/dashboard.js')) return `API ${h.version}, dashboard loads`;
310
370
  } catch { /* hosting can take a moment to answer on a new site */ }
311
371
  if (Date.now() > until) {
312
372
  throw new StepError(`${base} isn’t answering yet.`, 'New sites can take a few minutes. Run npx create-heresay status in a little while.');
@@ -1,15 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1">
6
- <title>Heresay</title>
7
- <meta http-equiv="refresh" content="0; url=/app/">
8
- <link rel="icon" href="/favicon.svg" type="image/svg+xml">
9
- <style>body{font:16px/1.6 system-ui,sans-serif;color:#15171c;max-width:32rem;margin:15vh auto;padding:0 24px;text-align:center}a{color:#0b5e57}small{display:block;margin-top:24px;color:#5b6472}</style>
10
- </head>
11
- <body>
12
- <p><a href="/app/">Open the Heresay dashboard</a></p>
13
- <small><a href="https://sibhimanyu.github.io/heresay/">What is Heresay?</a></small>
14
- </body>
15
- </html>