@superintern/sites 0.1.0 → 0.2.0
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/CHANGELOG.md +9 -0
- package/README.md +5 -2
- package/bin/sites.mjs +20 -2
- package/package.json +1 -1
- package/src/cli/api.mjs +29 -0
- package/src/cli/commands.mjs +69 -4
- package/src/cli/git.mjs +1 -1
- package/src/cli/package-info.mjs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changes to @superintern/sites
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
- `sites accounts`: whether customers can sign in to a site, and how
|
|
6
|
+
(customer accounts with a code by email, passwords, Google, Microsoft).
|
|
7
|
+
`--sign-in on`, `--passwords on`, `--google on`, `--microsoft on` (or
|
|
8
|
+
`off`) switch them, the same switches as the website's Settings tab; only
|
|
9
|
+
what is given changes. Needs a key that can change websites. Inside a
|
|
10
|
+
site's folder it needs no name.
|
|
11
|
+
|
|
3
12
|
## 0.1.0
|
|
4
13
|
|
|
5
14
|
The first version on npm.
|
package/README.md
CHANGED
|
@@ -80,14 +80,17 @@ sites remove <name> remove the site for good; you type its
|
|
|
80
80
|
sites open <name> open the site's address in your browser
|
|
81
81
|
sites tables [<name>] what the business's CRM lets the site show
|
|
82
82
|
sites rows <table> [<name>] the first rows of one of those tables
|
|
83
|
+
sites accounts [<name>] whether customers can sign in, and how
|
|
84
|
+
sites accounts [<name>] --sign-in on --passwords on
|
|
85
|
+
let customers sign in, with a password too
|
|
83
86
|
sites link in a site's folder: tie it to this copy of sites
|
|
84
87
|
sites --version which version of sites this is
|
|
85
88
|
sites --help every option
|
|
86
89
|
```
|
|
87
90
|
|
|
88
91
|
A site's name is 3 to 40 lowercase letters, digits and single hyphens. It
|
|
89
|
-
becomes the site's address. Inside a site's folder, `status`, `tables
|
|
90
|
-
`rows` need no name.
|
|
92
|
+
becomes the site's address. Inside a site's folder, `status`, `tables`,
|
|
93
|
+
`rows` and `accounts` need no name.
|
|
91
94
|
|
|
92
95
|
`sites status --wait` ends with exit code 0 when your push was built and is
|
|
93
96
|
ready to publish, 1 when it failed (what to fix is printed), and 2 when it
|
package/bin/sites.mjs
CHANGED
|
@@ -28,11 +28,15 @@ const USAGE = `Usage:
|
|
|
28
28
|
sites clone <slug> Bring an existing site's files here
|
|
29
29
|
sites tables [<slug>] What the business's CRM lets the site show
|
|
30
30
|
sites rows <table> [<slug>] The first rows of one of those tables
|
|
31
|
+
sites accounts [<slug>] Whether customers can sign in to the site, and how
|
|
32
|
+
sites accounts [<slug>] --sign-in on|off [--passwords on|off]
|
|
33
|
+
Switch customer accounts (and passwords, --google,
|
|
34
|
+
--microsoft) on or off
|
|
31
35
|
sites link In a site's folder: tie it to this copy of sites
|
|
32
36
|
sites logout Remove your saved key
|
|
33
37
|
sites --version Which version of sites this is
|
|
34
38
|
|
|
35
|
-
In a site's folder, status, tables and
|
|
39
|
+
In a site's folder, status, tables, rows and accounts need no <slug>. A table is named by its
|
|
36
40
|
name (in quotes when it has a space), its slug or its id.
|
|
37
41
|
|
|
38
42
|
A push never changes the live site. After a push, the site is built and
|
|
@@ -51,7 +55,9 @@ Options:
|
|
|
51
55
|
--limit <n> With rows: how many rows to show. Default: 5. At most 50.
|
|
52
56
|
--site <slug> With tables and rows: the site, the same as naming it
|
|
53
57
|
after the command.
|
|
54
|
-
--
|
|
58
|
+
--sign-in, --passwords, --google, --microsoft <on|off>
|
|
59
|
+
With accounts: what to switch. Only what is given changes.
|
|
60
|
+
--json With list, status and accounts: print everything as JSON.
|
|
55
61
|
With tables and rows: print the service's reply.
|
|
56
62
|
--no-check With login: save the key without checking it.
|
|
57
63
|
--yes With remove: don't ask to type the site's name. For scripts.
|
|
@@ -85,6 +91,10 @@ async function main() {
|
|
|
85
91
|
json: { type: "boolean" },
|
|
86
92
|
limit: { type: "string" },
|
|
87
93
|
site: { type: "string" },
|
|
94
|
+
"sign-in": { type: "string" },
|
|
95
|
+
passwords: { type: "string" },
|
|
96
|
+
google: { type: "string" },
|
|
97
|
+
microsoft: { type: "string" },
|
|
88
98
|
"no-check": { type: "boolean" },
|
|
89
99
|
yes: { type: "boolean" },
|
|
90
100
|
help: { type: "boolean", short: "h" },
|
|
@@ -158,6 +168,14 @@ async function main() {
|
|
|
158
168
|
return commands.tables(ctx, slug, { json: values.json, site: values.site });
|
|
159
169
|
case "rows":
|
|
160
170
|
return commands.rows(ctx, rest[0], rest[1], { json: values.json, limit: values.limit, site: values.site });
|
|
171
|
+
case "accounts":
|
|
172
|
+
return commands.accounts(ctx, slug, {
|
|
173
|
+
signIn: values["sign-in"],
|
|
174
|
+
passwords: values.passwords,
|
|
175
|
+
google: values.google,
|
|
176
|
+
microsoft: values.microsoft,
|
|
177
|
+
json: values.json,
|
|
178
|
+
});
|
|
161
179
|
case "link":
|
|
162
180
|
return commands.link(ctx);
|
|
163
181
|
// A site's build runs this and reads the one line it prints.
|
package/package.json
CHANGED
package/src/cli/api.mjs
CHANGED
|
@@ -292,6 +292,27 @@ export function createApi({ base, key, fetch: doFetch = fetch }) {
|
|
|
292
292
|
return (await call("POST", `/sites/${encodeURIComponent(id)}/remove`, { confirm: slug })).site;
|
|
293
293
|
},
|
|
294
294
|
|
|
295
|
+
/**
|
|
296
|
+
* Whether customers may sign in to the site, and how: `{enabled,
|
|
297
|
+
* passwords, providers: {google: {enabled, available}, microsoft: …}}`.
|
|
298
|
+
* A key that may only look is enough.
|
|
299
|
+
* @param {string} id @returns {Promise<SignInSwitches>}
|
|
300
|
+
*/
|
|
301
|
+
async signInSwitches(id) {
|
|
302
|
+
return call("GET", `/sites/${encodeURIComponent(id)}/customers/sign-in`);
|
|
303
|
+
},
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Switch customer sign-in: only what is sent changes (`enabled`,
|
|
307
|
+
* `passwords`, `google`, `microsoft`, each true or false). Needs a key that
|
|
308
|
+
* may change sites.
|
|
309
|
+
* @param {string} id @param {Partial<Record<"enabled" | "passwords" | "google" | "microsoft", boolean>>} changes
|
|
310
|
+
* @returns {Promise<SignInSwitches>}
|
|
311
|
+
*/
|
|
312
|
+
async switchSignIn(id, changes) {
|
|
313
|
+
return call("POST", `/sites/${encodeURIComponent(id)}/customers/sign-in`, changes);
|
|
314
|
+
},
|
|
315
|
+
|
|
295
316
|
/**
|
|
296
317
|
* A pass to read what this site's business made public in its CRM. A key
|
|
297
318
|
* that may only look (`sites.read`) is enough.
|
|
@@ -345,4 +366,12 @@ export function createApi({ base, key, fetch: doFetch = fetch }) {
|
|
|
345
366
|
* @property {string | null} name_free_for_others_at when another business may take its name
|
|
346
367
|
*/
|
|
347
368
|
|
|
369
|
+
/**
|
|
370
|
+
* Customer sign-in on a site.
|
|
371
|
+
* @typedef {object} SignInSwitches
|
|
372
|
+
* @property {boolean} enabled customers may sign in, with a code by email
|
|
373
|
+
* @property {boolean} passwords they may also choose a password
|
|
374
|
+
* @property {Record<string, { enabled?: boolean, available?: boolean }>} [providers] Google and Microsoft
|
|
375
|
+
*/
|
|
376
|
+
|
|
348
377
|
/** @typedef {ReturnType<typeof createApi>} Api */
|
package/src/cli/commands.mjs
CHANGED
|
@@ -449,13 +449,13 @@ export async function tables(ctx, slugArg, options = {}) {
|
|
|
449
449
|
ctx.out(`See real values before you write a page: sites rows ${shellWord(example)}${asked}`);
|
|
450
450
|
}
|
|
451
451
|
ctx.out("");
|
|
452
|
-
ctx.out("To show a table on the site, add its line under crmTables in src/site.config.ts, then read it in a page:");
|
|
452
|
+
ctx.out("To show a table on the site, add its line under crmTables in src/site.config.ts, then read it in a data page (one with export const prerender = false):");
|
|
453
453
|
const lists = listNames(found);
|
|
454
454
|
found.forEach((one, index) => {
|
|
455
455
|
const list = lists[index] ?? "table";
|
|
456
456
|
if (index > 0) ctx.out("");
|
|
457
457
|
ctx.out(` ${/^[a-z][a-z0-9_]*$/.test(list) ? list : JSON.stringify(list)}: ${JSON.stringify(oneLine(one.name))},`);
|
|
458
|
-
ctx.out(`
|
|
458
|
+
ctx.out(` await loadRows(Astro, ${JSON.stringify(list)})`);
|
|
459
459
|
});
|
|
460
460
|
return 0;
|
|
461
461
|
}
|
|
@@ -528,6 +528,71 @@ export async function rows(ctx, tableArg, slugArg, options = {}) {
|
|
|
528
528
|
return 0;
|
|
529
529
|
}
|
|
530
530
|
|
|
531
|
+
/** The switches `sites accounts` takes, as the service names them. */
|
|
532
|
+
const SIGN_IN_FLAGS = /** @type {const} */ ([
|
|
533
|
+
["signIn", "enabled", "Customer accounts"],
|
|
534
|
+
["passwords", "passwords", "Passwords"],
|
|
535
|
+
["google", "google", "Google"],
|
|
536
|
+
["microsoft", "microsoft", "Microsoft"],
|
|
537
|
+
]);
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Show whether customers may sign in to the site, and switch it: customer
|
|
541
|
+
* accounts (a code by email), passwords, Google and Microsoft. Only what is
|
|
542
|
+
* given changes. The same switches as the website's Settings tab.
|
|
543
|
+
* @param {Context} ctx @param {string | undefined} slugArg
|
|
544
|
+
* @param {{ signIn?: string, passwords?: string, google?: string, microsoft?: string, json?: boolean }} [options]
|
|
545
|
+
*/
|
|
546
|
+
export async function accounts(ctx, slugArg, options = {}) {
|
|
547
|
+
/** @type {Record<string, boolean>} */
|
|
548
|
+
const changes = {};
|
|
549
|
+
for (const [option, name, label] of SIGN_IN_FLAGS) {
|
|
550
|
+
const value = options[option];
|
|
551
|
+
if (value === undefined) continue;
|
|
552
|
+
const word = String(value).trim().toLowerCase();
|
|
553
|
+
if (word !== "on" && word !== "off") {
|
|
554
|
+
throw new CliError(`${label}: say on or off, as in --${option === "signIn" ? "sign-in" : option} on.`);
|
|
555
|
+
}
|
|
556
|
+
changes[name] = word === "on";
|
|
557
|
+
}
|
|
558
|
+
const slug = await siteSlug(ctx, [slugArg], "sites accounts <slug>");
|
|
559
|
+
const api = await signedIn(ctx);
|
|
560
|
+
const site = await findSite(ctx, api, slug);
|
|
561
|
+
let state;
|
|
562
|
+
try {
|
|
563
|
+
state = Object.keys(changes).length ? await api.switchSignIn(site.id, changes) : await api.signInSwitches(site.id);
|
|
564
|
+
} catch (error) {
|
|
565
|
+
if (error instanceof ApiError && error.status === 403 && error.code === "read_only") {
|
|
566
|
+
throw new CliError("Your key can only look at websites. Make one that can change websites (Website, Keys), then: sites login", 3);
|
|
567
|
+
}
|
|
568
|
+
if (error instanceof ApiError && (error.status === 403 || (error.status === 404 && error.code !== "not_found"))) {
|
|
569
|
+
throw new CliError(
|
|
570
|
+
`This service doesn't let a key switch customer accounts yet. Switch them in SuperIntern: the website's Settings tab, Customer accounts. Nothing was changed.`,
|
|
571
|
+
3,
|
|
572
|
+
);
|
|
573
|
+
}
|
|
574
|
+
throw (await keyMayNot(api, error, "switch customer accounts")) ?? friendly(error, slug);
|
|
575
|
+
}
|
|
576
|
+
if (options.json) {
|
|
577
|
+
ctx.out(jsonText(state, 2));
|
|
578
|
+
return 0;
|
|
579
|
+
}
|
|
580
|
+
const word = (/** @type {unknown} */ on) => (on ? "on" : "off");
|
|
581
|
+
const providers = state?.providers ?? {};
|
|
582
|
+
ctx.out(`Customer accounts on ${slug}: ${word(state?.enabled)}`);
|
|
583
|
+
ctx.out(` Passwords: ${word(state?.passwords)}`);
|
|
584
|
+
for (const [name, label] of /** @type {const} */ ([["google", "Google"], ["microsoft", "Microsoft"]])) {
|
|
585
|
+
const provider = providers[name] ?? {};
|
|
586
|
+
ctx.out(` ${`${label}:`.padEnd(11)} ${word(provider.enabled)}${provider.available === false ? " (not available yet)" : ""}`);
|
|
587
|
+
}
|
|
588
|
+
if (state?.enabled) {
|
|
589
|
+
ctx.out(`Customers sign in at ${addressOf(site)}/sign-in. Everyone who signs in is added to your People.`);
|
|
590
|
+
} else {
|
|
591
|
+
ctx.out(`Switch them on with: sites accounts ${slug} --sign-in on --passwords on`);
|
|
592
|
+
}
|
|
593
|
+
return 0;
|
|
594
|
+
}
|
|
595
|
+
|
|
531
596
|
/**
|
|
532
597
|
* What a site's build calls to read the CRM on a person's computer: one line
|
|
533
598
|
* of JSON, `{"url", "token", "expires_at"}`, and nothing else. The build
|
|
@@ -770,7 +835,7 @@ function rowLimit(ctx, value) {
|
|
|
770
835
|
}
|
|
771
836
|
|
|
772
837
|
/**
|
|
773
|
-
* The name pages read each table by (`
|
|
838
|
+
* The name pages read each table by (`loadRows(Astro, "events")`): made from the
|
|
774
839
|
* table's name, or its slug when the name has no letter a list's name can
|
|
775
840
|
* hold (one in another script, say), or "table". No two tables in one
|
|
776
841
|
* listing get the same name: a second one gets a 2, a third a 3.
|
|
@@ -1058,7 +1123,7 @@ async function clone(ctx, site, dir) {
|
|
|
1058
1123
|
dataHelper: dataHelperCommand({ node: ctx.self.node, script: ctx.self.script, environment: ctx.environment.name, slug }),
|
|
1059
1124
|
starterUrl: gitUrl(ctx.environment, STARTER_SLUG),
|
|
1060
1125
|
});
|
|
1061
|
-
ctx.note(`The remote "${STARTER_REMOTE}" is the
|
|
1126
|
+
ctx.note(`The remote "${STARTER_REMOTE}" is the template every site starts from, to read what it has now. Never merge it into the site: it would bring the template's sample content back (and a site made since 18 Nov 2026 shares no history with it, so git refuses). In a site built on the site kit, the platform's parts (chat, shop, sign-in, the checks) come from the kit: SuperIntern installs smaller updates itself, and a bigger one waits in the draft for the owner to publish.`);
|
|
1062
1127
|
|
|
1063
1128
|
// Git on this computer may not know who is committing; then it guesses (on
|
|
1064
1129
|
// a Mac, from the account's name and the computer's network address) or, on
|
package/src/cli/git.mjs
CHANGED
|
@@ -16,7 +16,7 @@ import { spawn } from "node:child_process";
|
|
|
16
16
|
/** Git needs a username; the git address ignores it. */
|
|
17
17
|
const USERNAME = "sites";
|
|
18
18
|
|
|
19
|
-
/** The remote a site keeps for
|
|
19
|
+
/** The remote a site keeps for reading the template it started from: read, never merged. */
|
|
20
20
|
export const STARTER_REMOTE = "starter";
|
|
21
21
|
|
|
22
22
|
/**
|
package/src/cli/package-info.mjs
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
export const PACKAGE_NAME = "@superintern/sites";
|
|
10
10
|
|
|
11
11
|
/** Raise it, add an entry to npm/CHANGELOG.md, then tag `sites-v<version>`. */
|
|
12
|
-
export const PACKAGE_VERSION = "0.
|
|
12
|
+
export const PACKAGE_VERSION = "0.2.0";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* The licence the package is published under, as npm spells it (an SPDX
|