@sqid-dev/playground 0.1.2 → 0.1.3

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": "@sqid-dev/playground",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "A real-looking website (Driftwood, a desk company) with a Sqid panel docked on the side: watch a visitor get identified, try the scenarios and recipes, see the record that goes out, then go live on your own site.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/public/panel.js CHANGED
@@ -334,15 +334,15 @@
334
334
  <div class="pg-card">
335
335
  <b>Paying for it</b>
336
336
  <p class="pg-p small">The Sandbox is free. A real site uses prepaid credits on the Developer plan: $0.25 each. Add a card and you get 25 welcome credits. Nothing is charged unless you buy credits or turn on auto-reload. With no credits left, your site stops identifying new visitors until you add more.</p>
337
- <div class="pg-row pg-wrap"><a class="pg-btn accent" href="${esc(CONSOLE())}/billing" target="_blank" rel="noopener">Add a card</a><a href="https://sqid.dev/pricing" target="_blank" rel="noopener" class="small">Pricing</a></div>
337
+ <div class="pg-row pg-wrap"><a class="pg-btn accent" href="${esc(CONSOLE())}/billing?add=card" target="_blank" rel="noopener">Add a card</a><a href="https://sqid.dev/pricing" target="_blank" rel="noopener" class="small">Pricing</a></div>
338
338
  </div>
339
339
  <button class="pg-link" data-act="more" aria-expanded="${!!S.showMore}">${S.showMore ? 'Hide other ways' : 'Other ways: from my code editor, or inside my product'}</button>
340
340
  ${S.showMore ? `
341
341
  <div class="pg-card">
342
342
  <b>From my code editor</b>
343
- <p class="pg-p small">Claude Code adds the code to your layout and writes the webhook handler for your framework.</p>
344
- <pre class="pg-mono">claude mcp add --transport http sqid https://mcp.sqid.dev/mcp
345
- /sqid:setup</pre>
343
+ <p class="pg-p small">Claude Code adds the code to your layout and writes the webhook handler for your framework. In a terminal:</p>
344
+ <pre class="pg-mono">claude mcp add --transport http sqid https://mcp.sqid.dev/mcp</pre>
345
+ <p class="pg-p small">Then in Claude Code: <span class="pg-mono">/mcp</span>, pick sqid, Authenticate (your browser signs you in), and type <span class="pg-mono">/sqid:setup</span>. <a href="https://docs.sqid.dev/getting-started/agents" target="_blank" rel="noopener">Step by step</a></p>
346
346
  <pre class="pg-mono">npx -y @sqid-dev/sqid init</pre>
347
347
  </div>
348
348
  <div class="pg-card">
package/src/sqid.js CHANGED
@@ -159,7 +159,7 @@ export class Bridge {
159
159
 
160
160
  // Go live: a real site on the account, with its snippet.
161
161
  async createSite({ name, url }){
162
- let origins = toOrigins(url);
162
+ let origins = withTwins(toOrigins(url));
163
163
  if(!origins.length){ throw Object.assign(new Error('Give the site\'s public URL, e.g. https://www.example.com'), { status : 400 }); }
164
164
  let me = await this.api('GET', '/api/sqid/me', { flags : this.flags });
165
165
  if(!me?.account?.hasSubscription){
@@ -200,3 +200,22 @@ export function localRecord(traits = {}){
200
200
  source : 'your database (mock)'
201
201
  };
202
202
  }
203
+
204
+ // A public site is usually reached both with and without "www.": add the other one, so a visitor on
205
+ // www.example.com is not refused because the site was created for example.com. Only for https
206
+ // hosts: "www.x.y" adds "x.y", a bare two-label "x.y" adds "www.x.y". Local hosts, IPs and other
207
+ // subdomains are left as given.
208
+ function withTwins(origins){
209
+ let out = [...origins];
210
+ for(let o of origins){
211
+ try{
212
+ let u = new URL(o);
213
+ if(u.protocol !== 'https:' || /^[\d.]+$/.test(u.hostname) || u.hostname === 'localhost'){ continue; }
214
+ let h = u.hostname, twin = null;
215
+ if(h.startsWith('www.')){ twin = h.slice(4); }
216
+ else if(h.split('.').length === 2){ twin = `www.${h}`; }
217
+ if(twin && twin.includes('.')){ let t = `https://${twin}${u.port ? ':' + u.port : ''}`; if(!out.includes(t)){ out.push(t); } }
218
+ }catch(error){ /* skip */ }
219
+ }
220
+ return out;
221
+ }