shiply-cli 0.14.1 → 0.14.2

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.
Files changed (2) hide show
  1. package/dist/domain.js +38 -3
  2. package/package.json +1 -1
package/dist/domain.js CHANGED
@@ -24,11 +24,46 @@ export async function domainConnect(ctx, domain) {
24
24
  const r = await api(`${base}/api/v1/custom-domains/${enc(domain)}/connect`, { method: 'POST', headers: headers(ctx.apiKey), body: '{}' });
25
25
  console.log(`Open this link in your browser to connect ${domain}:\n ${r.url}`);
26
26
  }
27
- export async function domainSubAdd(ctx, hostname, slug) {
28
- const parts = hostname.split('.');
29
- // NOTE: naive registrable-domain split (last two labels) wrong for multi-label TLDs like co.uk; the dashboard avoids this by passing the parent domain explicitly.
27
+ /** Common 2-label public suffixes. Not exhaustive — but covers the registrar
28
+ * ccTLDs we've seen in the wild (au, uk, nz, za, br, in, jp, kr, mx, co...).
29
+ * For anything else we fall back to the last-two-labels heuristic, which is
30
+ * correct for the vast majority of TLDs. A future improvement is to ship the
31
+ * Public Suffix List as data; this keeps the CLI bundle tiny. */
32
+ const TWO_LABEL_SUFFIXES = new Set([
33
+ 'com.au', 'net.au', 'org.au', 'edu.au', 'gov.au', 'id.au',
34
+ 'co.uk', 'org.uk', 'me.uk', 'gov.uk', 'ac.uk', 'net.uk',
35
+ 'co.nz', 'net.nz', 'org.nz', 'govt.nz',
36
+ 'co.za', 'org.za', 'web.za',
37
+ 'com.br', 'net.br', 'org.br', 'gov.br',
38
+ 'co.in', 'net.in', 'org.in', 'gov.in',
39
+ 'co.jp', 'or.jp', 'ne.jp', 'go.jp', 'ac.jp',
40
+ 'co.kr', 'or.kr', 'ne.kr', 'go.kr',
41
+ 'com.mx', 'org.mx', 'gob.mx',
42
+ 'co.id', 'or.id', 'ac.id', 'go.id',
43
+ 'com.sg', 'org.sg', 'edu.sg', 'gov.sg',
44
+ 'com.hk', 'org.hk', 'edu.hk', 'gov.hk',
45
+ 'com.tw', 'org.tw', 'gov.tw',
46
+ ]);
47
+ /** Split hostname into (parent, subdomain) using a small Public Suffix List.
48
+ * parts.slice(-2).join('.') is wrong for `paidsooner.com.au` (treats `com.au`
49
+ * as the parent — that bug shipped phantom state to prod). */
50
+ export function splitRegistrable(hostname) {
51
+ const parts = hostname.toLowerCase().split('.');
52
+ // Try a 2-label public suffix first (e.g. com.au, co.uk).
53
+ if (parts.length >= 3) {
54
+ const twoLabel = parts.slice(-2).join('.');
55
+ if (TWO_LABEL_SUFFIXES.has(twoLabel)) {
56
+ const domain = parts.slice(-3).join('.');
57
+ const subdomain = parts.slice(0, -3).join('.') || '@';
58
+ return { domain, subdomain };
59
+ }
60
+ }
30
61
  const domain = parts.slice(-2).join('.');
31
62
  const subdomain = parts.slice(0, -2).join('.') || '@';
63
+ return { domain, subdomain };
64
+ }
65
+ export async function domainSubAdd(ctx, hostname, slug) {
66
+ const { domain, subdomain } = splitRegistrable(hostname);
32
67
  const base = resolveBase(ctx.base);
33
68
  const r = await api(`${base}/api/v1/custom-domains/${enc(domain)}/subdomains`, { method: 'POST', headers: headers(ctx.apiKey), body: JSON.stringify({ subdomain, slug }) });
34
69
  if (r.autoConnected) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shiply-cli",
3
- "version": "0.14.1",
3
+ "version": "0.14.2",
4
4
  "description": "Publish static sites to shiply.now from the command line — instant web hosting for agents.",
5
5
  "license": "MIT",
6
6
  "type": "module",