@profullstack/waitlist 0.15.1 → 0.16.1

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": "@profullstack/waitlist",
3
- "version": "0.15.1",
3
+ "version": "0.16.1",
4
4
  "description": "Email waitlist for any launch page: a <waitlist-form> web component, a live signup chart, and a static-site builder on @profullstack/css + @profullstack/charts.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/build.js CHANGED
@@ -202,10 +202,7 @@ export function shellHtml(s, { head, main, footers = '', slot = baseSlot(s) }) {
202
202
  <meta name="viewport" content="width=device-width, initial-scale=1">
203
203
  ${s.ab ? abHeadScript(s.ab, s.look) : ''}
204
204
  ${head}
205
- <link rel="stylesheet" href="assets/profullstack.css">
206
- <link rel="stylesheet" href="assets/looks.css">
207
- <link rel="stylesheet" href="assets/charts.css">
208
- <link rel="stylesheet" href="assets/waitlist.css">
205
+ <link rel="stylesheet" href="assets/site.css">
209
206
  ${slot.head.join('\n')}
210
207
  </head>
211
208
  <body class="waitlist-page">
@@ -215,7 +212,7 @@ ${navHtml(s, { community: s.community ?? null, esc })}
215
212
  ${main}
216
213
  </main>
217
214
  ${footZoneHtml(s, footers)}
218
- <script src="assets/charts.global.js"></script>
215
+ <script defer src="assets/charts.global.js"></script>
219
216
  <script type="module" src="assets/waitlist.js"></script>
220
217
  ${slot.scripts.join('\n')}
221
218
  ${s.pwa ? '<script>if("serviceWorker"in navigator){var m=document.querySelector(\'link[rel="manifest"]\');if(m)navigator.serviceWorker.register(new URL("sw.js",m.href)).catch(function(){})}</script>' : ''}
@@ -248,6 +245,31 @@ export function pageHtml(s, { footers = '', noindex = false, slot = baseSlot(s)
248
245
  return shellHtml(s, { head: `${headTags(s, { noindex })}\n${jsonLdTag(s)}`, main, footers, slot });
249
246
  }
250
247
 
248
+ /**
249
+ * Every stylesheet a page needs, as one file.
250
+ *
251
+ * The page used to link four stylesheets, and profullstack.css @imports three
252
+ * more, which a browser only discovers after the first has arrived. That is
253
+ * seven requests in two rounds before anything paints, and one slow answer
254
+ * from a gateway holds the whole page blank. One file is one request.
255
+ *
256
+ * Order is the cascade order the separate files had: profullstack.css with its
257
+ * @imports put in where they stood (its @layer statement stays first), then
258
+ * looks, charts and the waitlist layer. The separate files are still written,
259
+ * for anything that links them by name.
260
+ */
261
+ export async function bundleCss(cssDir, chartsCss, waitlistCss) {
262
+ const read = (f) => readFile(f, 'utf8');
263
+ let base = await read(join(cssDir, 'profullstack.css'));
264
+ for (const m of [...base.matchAll(/@import\s+url\(["']?\.\/([\w.-]+\.css)["']?\)\s*;/g)]) {
265
+ base = base.replace(m[0], `/* ${m[1]} */\n${await read(join(cssDir, m[1]))}`);
266
+ }
267
+ if (/@import\b/.test(base.replace(/\/\*[\s\S]*?\*\//g, ''))) throw new Error('profullstack.css has an @import the bundler does not know how to inline');
268
+ const rest = [];
269
+ for (const [label, file] of [['looks.css', join(cssDir, 'looks.css')], ['charts.css', chartsCss], ['waitlist.css', waitlistCss]]) rest.push(`/* ${label} */\n${await read(file)}`);
270
+ return [base, ...rest].join('\n');
271
+ }
272
+
251
273
  /** Square icon in the look's colors (takes a normalized spec or a bare name). */
252
274
  export function iconSvg(s) {
253
275
  return lookIconSvg(typeof s === 'string' ? normalize({ name: s }) : s);
@@ -288,6 +310,7 @@ export async function buildSite(spec, out, { footers = true, images = true, fetc
288
310
  await copyFile(join(chartsDir, 'charts.css'), join(out, 'assets', 'charts.css'));
289
311
  await copyFile(join(here, 'index.js'), join(out, 'assets', 'waitlist.js'));
290
312
  await copyFile(join(here, 'waitlist.css'), join(out, 'assets', 'waitlist.css'));
313
+ await writeFile(join(out, 'assets', 'site.css'), await bundleCss(cssDir, join(chartsDir, 'charts.css'), join(here, 'waitlist.css')));
291
314
  const icon = iconSvg(s);
292
315
  await writeFile(join(out, 'assets', 'icon.svg'), icon);
293
316
  const og = ogSvg(s);
@@ -369,7 +392,9 @@ async function writeSearch(s, search, out, { footers, slot, ver, images }) {
369
392
  async function writeBuilder(s, out, { footers, slot, ver }) {
370
393
  const dir = join(out, BUILDER_PATH);
371
394
  await mkdir(dir, { recursive: true });
372
- const pageSlot = { ...slot, cards: [], sections: [] };
395
+ const pageSlot = { ...slot, cards: [], sections: [], scripts: [...slot.scripts, '<script type="module" src="assets/builder.js"></script>'] };
396
+ await mkdir(join(out, 'assets'), { recursive: true });
397
+ await copyFile(join(here, 'builder-client.js'), join(out, 'assets', 'builder.js'));
373
398
  const { html } = builderPageHtml(s, {
374
399
  rebase,
375
400
  chrome: ({ head, body, spec }) => withAssetVersion(shellHtml(spec, { head, main: `${body}\n<section class="card stack" aria-label="Waitlist"><h2>Get ${esc(s.title)} when it opens</h2>${slot.hero.join('\n')}</section>`, footers, slot: pageSlot }), ver),
@@ -0,0 +1,147 @@
1
+ // <site-builder>: build a feature for this site with feature.agent, right on the
2
+ // Build page, and list the features the site's admin published.
3
+ //
4
+ // feature.agent (https://feature.agent.pit.world) is keyless to start: the first
5
+ // build makes an anonymous account (30-day trial, no card) and its fa_ key stays in
6
+ // this browser's localStorage, sent only to feature.agent. A finished feature is
7
+ // shared with one click; the site's admin publishes the link on git.<name>, and it
8
+ // then shows here for everyone (from pit.world/api/forge, which pit-forge serves).
9
+ //
10
+ // Config is the JSON script inside the element (src/builder.js builderClientConfig).
11
+
12
+ const KEY = 'site-builder:fa-key';
13
+
14
+ async function call(url, init) {
15
+ try {
16
+ const res = await fetch(url, init);
17
+ const body = await res.json().catch(() => ({}));
18
+ return { ok: res.ok, status: res.status, body };
19
+ } catch {
20
+ return { ok: false, status: 0, body: {} };
21
+ }
22
+ }
23
+
24
+ export function explain(status, body) {
25
+ const msg = body?.error?.message || (typeof body?.error === 'string' ? body.error : '');
26
+ if (status === 0) return 'feature.agent could not be reached from this page. Try again in a minute.';
27
+ if (status === 429) return msg || 'That is all the builds for today on this browser. Come back tomorrow, or go Pro on feature.agent.';
28
+ return msg || `feature.agent answered ${status}. Try again.`;
29
+ }
30
+
31
+ const store = () => {
32
+ try { return localStorage; } catch { return null; }
33
+ };
34
+
35
+ const h = (tag, props = {}, ...kids) => {
36
+ const n = document.createElement(tag);
37
+ for (const [k, v] of Object.entries(props)) {
38
+ if (k === 'class') n.className = v;
39
+ else if (k.startsWith('on')) n.addEventListener(k.slice(2), v);
40
+ else if (v !== false && v != null) n.setAttribute(k, v === true ? '' : v);
41
+ }
42
+ for (const k of kids) if (k != null) n.append(k);
43
+ return n;
44
+ };
45
+
46
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
47
+
48
+ if (typeof HTMLElement !== 'undefined') {
49
+ class SiteBuilder extends HTMLElement {
50
+ #cfg = null;
51
+ #busy = false;
52
+ #step = '';
53
+ #error = '';
54
+ #feature = null;
55
+ #published = [];
56
+
57
+ async connectedCallback() {
58
+ if (this.#cfg) return;
59
+ try { this.#cfg = JSON.parse(this.querySelector('script[type="application/json"]')?.textContent || 'null'); } catch { this.#cfg = null; }
60
+ if (!this.#cfg?.fa) return; // keep the static links
61
+ this.#render();
62
+ const r = await call(`${this.#cfg.forge}/sites/${encodeURIComponent(this.#cfg.name)}`);
63
+ if (r.ok && Array.isArray(r.body.features)) {
64
+ this.#published = r.body.features;
65
+ this.#render();
66
+ }
67
+ }
68
+
69
+ async #key() {
70
+ const s = store();
71
+ const have = s?.getItem(KEY);
72
+ if (have) return have;
73
+ const r = await call(`${this.#cfg.fa}/api/v1/signup`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ label: `builder on ${this.#cfg.site}` }) });
74
+ if (!r.ok || !r.body.key) throw new Error(explain(r.status, r.body));
75
+ s?.setItem(KEY, r.body.key);
76
+ return r.body.key;
77
+ }
78
+
79
+ async #build(prompt) {
80
+ if (this.#busy || prompt.trim().length < 4) return;
81
+ this.#busy = true;
82
+ this.#error = '';
83
+ this.#feature = null;
84
+ this.#step = 'Starting';
85
+ this.#render();
86
+ try {
87
+ const key = await this.#key();
88
+ const auth = { authorization: `Bearer ${key}`, 'content-type': 'application/json' };
89
+ const start = await call(`${this.#cfg.fa}/api/v1/features/build`, { method: 'POST', headers: auth, body: JSON.stringify({ url: this.#cfg.url, prompt }) });
90
+ if (start.status === 401) store()?.removeItem(KEY);
91
+ if (!start.ok || !start.body.job) throw new Error(explain(start.status, start.body));
92
+ for (let i = 0; i < 90; i++) {
93
+ await sleep(2000);
94
+ const j = await call(`${this.#cfg.fa}/api/v1/jobs/${start.body.job}`, { headers: auth });
95
+ if (!j.ok) continue;
96
+ this.#step = j.body.step || this.#step;
97
+ this.#render();
98
+ if (j.body.state === 'failed') throw new Error(j.body.error || 'the build failed; try again');
99
+ if (j.body.state === 'done' || j.body.result?.feature) {
100
+ this.#feature = j.body.result?.feature ?? null;
101
+ break;
102
+ }
103
+ }
104
+ if (!this.#feature) throw new Error('the build is taking long; it will be in your feature.agent account');
105
+ } catch (e) {
106
+ this.#error = e.message;
107
+ } finally {
108
+ this.#busy = false;
109
+ this.#render();
110
+ }
111
+ }
112
+
113
+ async #share() {
114
+ const f = this.#feature;
115
+ if (!f) return;
116
+ const key = store()?.getItem(KEY);
117
+ const r = await call(`${this.#cfg.fa}/api/v1/features/${f.id}/share`, { method: 'POST', headers: { authorization: `Bearer ${key}`, 'content-type': 'application/json' }, body: '{"on":true}' });
118
+ if (r.ok) this.#feature = r.body;
119
+ else this.#error = explain(r.status, r.body);
120
+ this.#render();
121
+ }
122
+
123
+ #render() {
124
+ const cfg = this.#cfg;
125
+ const out = [];
126
+ if (this.#published.length)
127
+ out.push(h('div', { class: 'stack' }, h('h3', {}, `Features published on ${cfg.site}`), h('ul', {}, ...this.#published.map((f) => h('li', {}, h('a', { href: f.url, rel: 'noopener' }, f.title || f.slug), f.summary ? ` — ${f.summary}` : '')))));
128
+ const ta = h('textarea', { rows: '3', placeholder: `Describe a feature for ${cfg.site}, e.g. "a dark mode toggle" or "a button that copies the page link"`, 'aria-label': 'Feature description', disabled: this.#busy });
129
+ out.push(
130
+ h('form', { class: 'stack', onsubmit: (e) => { e.preventDefault(); void this.#build(ta.value); } }, ta,
131
+ h('p', {}, h('button', { type: 'submit', class: 'button', disabled: this.#busy }, this.#busy ? `${this.#step}…` : 'Build it with feature.agent'))),
132
+ );
133
+ if (this.#error) out.push(h('p', { class: 'advisor-error', role: 'alert' }, this.#error));
134
+ const f = this.#feature;
135
+ if (f) {
136
+ out.push(h('div', { class: 'card stack' }, h('h3', {}, f.name || 'Your feature'), f.summary ? h('p', {}, f.summary) : null,
137
+ h('details', {}, h('summary', {}, 'The code'), h('pre', {}, h('code', {}, `${f.css ? `/* CSS */\n${f.css}\n\n` : ''}${f.js || ''}`))),
138
+ f.share_url
139
+ ? h('p', {}, 'Shared: ', h('a', { href: f.share_url, rel: 'noopener' }, f.share_url), `. Install it with the feature.agent extension, or send the link to the ${cfg.site} admin to publish it on `, h('a', { href: cfg.git }, cfg.git.replace(/^https:\/\//, '').replace(/\/$/, '')), '.')
140
+ : h('p', {}, h('button', { type: 'button', class: 'button', onclick: () => void this.#share() }, 'Share it'), ' to install it with the feature.agent extension or propose it for the site.')));
141
+ }
142
+ out.push(h('p', { class: 'muted' }, 'No card, no sign-up: the first build makes a feature.agent trial key in this browser (30 days, then a few builds a day free).'));
143
+ this.querySelector('.site-builder-live')?.replaceChildren(...out);
144
+ }
145
+ }
146
+ if (!customElements.get('site-builder')) customElements.define('site-builder', SiteBuilder);
147
+ }
package/src/builder.js CHANGED
@@ -17,6 +17,21 @@ export const BUILDER_PATH = 'builder/';
17
17
  export const FEATURE_AGENT = 'https://feature.agent.pit.world';
18
18
  export const DBML_DB = 'https://dbml.db.pit.world';
19
19
  export const C0MPUTE = 'https://c0mpute.com';
20
+ /** pit-forge's public JSON (pit.world proxies it): published features, repos, open data. */
21
+ export const FORGE_API = 'https://pit.world/api/forge';
22
+
23
+ /** git.<name> and db.<name>: the name's free git host and open database (pit-forge). */
24
+ export function forgeHosts(s) {
25
+ const name = String(s.name ?? '').toLowerCase();
26
+ if (!/^[a-z0-9-]+(\.[a-z0-9-]+)+$/.test(name)) return null;
27
+ return { git: `https://git.${name}.pit.world/`, db: `https://db.${name}.pit.world/` };
28
+ }
29
+
30
+ /** What <site-builder> (src/builder-client.js) needs, baked into the page. */
31
+ export function builderClientConfig(s) {
32
+ const f = forgeHosts(s);
33
+ return { site: s.host, name: s.name, url: s.url, fa: FEATURE_AGENT, forge: FORGE_API, git: f?.git ?? null };
34
+ }
20
35
  /** dbml.db refuses to share a project whose encoded form is longer than this. */
21
36
  export const DBML_SHARE_MAX = 15000;
22
37
  const DBML_MAX_CHARS = 60_000;
@@ -153,6 +168,7 @@ export function builderPageHtml(s, { chrome, rebase }) {
153
168
  const b = s.builder;
154
169
  const cmd = builderCommands(s);
155
170
  const ref = encodeURIComponent(s.host);
171
+ const forge = forgeHosts(s);
156
172
  const body = `<header class="waitlist-hero stack" data-space="md">
157
173
  <p class="waitlist-kicker"><a href="../">← ${esc(s.title)}</a> <span class="badge">Build</span></p>
158
174
  <h1>${esc(m.h1)}</h1>
@@ -163,17 +179,20 @@ export function builderPageHtml(s, { chrome, rebase }) {
163
179
  <p>${b.repo ? `The ${esc(s.title)} repo is public and kept by the network. Clone it:` : `There is no shared ${esc(s.title)} repo yet. Start one: public repos are kept by the network and free to clone.`}</p>
164
180
  ${pre(cmd.code)}
165
181
  <p class="muted">Repos are signed by your key and kept in three copies. Private repos are end-to-end encrypted.</p>
182
+ ${forge ? `<p><a class="button" href="${esc(forge.git)}" rel="noopener">${esc(s.name)} on git</a> Free git for ${esc(s.title)}'s open-source and public-domain projects: browse, clone, and (for the name's holder) add repos.</p>` : ''}
166
183
  </section>
167
184
  <section class="card stack" aria-labelledby="build-data"><h2 id="build-data">2. Data</h2>
168
185
  <p>${b.dbml ? `The ${esc(s.title)} schema` : `A starting schema for ${esc(s.title)}`} is a plain <a href="${esc(m.url)}schema.dbml">schema.dbml</a> file on this site. Open it in dbml.db to edit, review and diagram it, then turn it into a live Postgres on the network.</p>
169
186
  <p><a class="button" href="${esc(b.schema || dbmlEditorUrl(builderSchema(s)) || `${DBML_DB}/playground/`)}" rel="noopener">Open the schema in dbml.db</a></p>
170
187
  ${pre(cmd.data)}
171
188
  <p class="muted">For agents: dbml.db speaks MCP at <code>${DBML_DB}/mcp</code>.</p>
189
+ ${forge ? `<p><a class="button" href="${esc(forge.db)}" rel="noopener">${esc(s.name)} open data</a> The site's database: what its admin publishes, as a table, JSON or CSV.</p>` : ''}
172
190
  </section>
173
191
  <section class="card stack" aria-labelledby="build-features"><h2 id="build-features">3. Features</h2>
174
- <p><a href="${FEATURE_AGENT}/?ref=${ref}" rel="noopener">feature.agent</a> builds a feature for any site from a description and runs it in your browser. Use it to prototype what ${esc(s.title)} should do, on the sites you already use.</p>
192
+ <p><a href="${FEATURE_AGENT}/?ref=${ref}" rel="noopener">feature.agent</a> builds a feature for ${esc(s.title)} from a description. Describe it here; share what it builds, and the site's admin can publish it.</p>
193
+ <site-builder><script type="application/json">${JSON.stringify(builderClientConfig(s)).replace(/</g, '\\u003c')}</script><div class="site-builder-live stack">
175
194
  <p><a class="button" href="${FEATURE_AGENT}/?ref=${ref}" rel="noopener">Try feature.agent</a></p>
176
- <p class="muted">30-day trial, no card. Then a few builds a day free, or Pro.</p>
195
+ <p class="muted">30-day trial, no card. Then a few builds a day free, or Pro.</p></div></site-builder>
177
196
  </section>
178
197
  <section class="card stack" aria-labelledby="build-ideas"><h2 id="build-ideas">4. Ideas</h2>
179
198
  <p>Say what you want built, or pick up what someone else asked for.</p>