ezhst 1.1.0 → 1.3.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/dist/commands/auth.js +35 -5
- package/dist/index.js +7 -6
- package/dist/lib/api.js +13 -1
- package/package.json +1 -1
- package/skill/SKILL.md +9 -12
package/dist/commands/auth.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { input, password } from "@inquirer/prompts";
|
|
2
|
-
import { json, request } from "../lib/api.js";
|
|
2
|
+
import { ApiError, json, request } from "../lib/api.js";
|
|
3
3
|
import { clearConfig, readConfig, writeConfig } from "../lib/config.js";
|
|
4
|
-
import { log, output, required } from "../lib/ui.js";
|
|
4
|
+
import { isInteractive, log, output, required } from "../lib/ui.js";
|
|
5
5
|
const apiUrlFrom = (api) => (api ?? readConfig().apiUrl).replace(/\/$/, "");
|
|
6
6
|
const askEmail = () => input({ message: "Email" });
|
|
7
7
|
const askPassword = () => password({ message: "Password", mask: "*" });
|
|
@@ -9,11 +9,35 @@ const saveSession = (apiUrl, token, user, message) => {
|
|
|
9
9
|
writeConfig({ apiUrl, token });
|
|
10
10
|
output({ user, token }, () => {
|
|
11
11
|
log.success(`${message} ${user.name} <${user.email}>`);
|
|
12
|
-
if (!user.verified) {
|
|
13
|
-
log.warn("Verify your email
|
|
12
|
+
if (!user.verified && !isInteractive()) {
|
|
13
|
+
log.warn("Verify your email before using EasyHost: run `ezhst verify <code>` with the 6-digit code we emailed you.");
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
|
+
const askForCode = async (user) => {
|
|
18
|
+
if (user.verified || !isInteractive()) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
log.info(`We emailed a 6-digit code to ${user.email}. Enter it to finish (press Enter to skip for now).`);
|
|
22
|
+
while (true) {
|
|
23
|
+
const code = (await input({ message: "Verification code" })).trim();
|
|
24
|
+
if (!code) {
|
|
25
|
+
log.warn("Skipped. Run `ezhst verify <code>` before using other commands.");
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const result = await request("/auth/verify-email", json("POST", { code }));
|
|
30
|
+
log.success(result.message);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (!(error instanceof ApiError)) {
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
log.error(error.message);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
17
41
|
export const register = async (options) => {
|
|
18
42
|
const apiUrl = apiUrlFrom(options.api);
|
|
19
43
|
writeConfig({ apiUrl });
|
|
@@ -22,6 +46,7 @@ export const register = async (options) => {
|
|
|
22
46
|
const secret = await required(options.password, "--password", askPassword);
|
|
23
47
|
const { token, user } = await request("/auth/register", json("POST", { name, email, password: secret }));
|
|
24
48
|
saveSession(apiUrl, token, user, "Account created for");
|
|
49
|
+
await askForCode(user);
|
|
25
50
|
};
|
|
26
51
|
export const login = async (options) => {
|
|
27
52
|
const apiUrl = apiUrlFrom(options.api);
|
|
@@ -30,6 +55,7 @@ export const login = async (options) => {
|
|
|
30
55
|
const secret = await required(options.password, "--password", askPassword);
|
|
31
56
|
const { token, user } = await request("/auth/login", json("POST", { email, password: secret }));
|
|
32
57
|
saveSession(apiUrl, token, user, "Logged in as");
|
|
58
|
+
await askForCode(user);
|
|
33
59
|
};
|
|
34
60
|
export const logout = () => {
|
|
35
61
|
clearConfig();
|
|
@@ -41,11 +67,15 @@ export const whoami = async () => {
|
|
|
41
67
|
output({ user, apiUrl }, () => {
|
|
42
68
|
log.info(`${user.name} <${user.email}>`);
|
|
43
69
|
if (!user.verified) {
|
|
44
|
-
log.warn("Email not verified");
|
|
70
|
+
log.warn("Email not verified. Run `ezhst verify <code>`.");
|
|
45
71
|
}
|
|
46
72
|
log.dim(apiUrl);
|
|
47
73
|
});
|
|
48
74
|
};
|
|
75
|
+
export const verify = async (code) => {
|
|
76
|
+
const result = await request("/auth/verify-email", json("POST", { code }));
|
|
77
|
+
output(result, () => log.success(result.message));
|
|
78
|
+
};
|
|
49
79
|
export const resendVerification = async () => {
|
|
50
80
|
const result = await request("/auth/resend-verification", { method: "POST" });
|
|
51
81
|
output(result, () => log.success(result.message));
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from "commander";
|
|
3
3
|
import { readFileSync } from "node:fs";
|
|
4
|
-
import { forgotPassword, login, logout, register, resendVerification, whoami } from "./commands/auth.js";
|
|
4
|
+
import { forgotPassword, login, logout, register, resendVerification, verify, whoami } from "./commands/auth.js";
|
|
5
5
|
import { createApp, deleteApp, listApps } from "./commands/apps.js";
|
|
6
6
|
import { createSchedule, deleteSchedule, listSchedules, scheduleLogs, setScheduleState, updateSchedule } from "./commands/schedules.js";
|
|
7
7
|
import { createProject, deleteProject, link, listProjects, logs, projectInfo, renameProject, start, stop } from "./commands/projects.js";
|
|
@@ -23,7 +23,7 @@ if (!packageMetadata || typeof packageMetadata !== "object" || !("version" in pa
|
|
|
23
23
|
const program = new Command();
|
|
24
24
|
program
|
|
25
25
|
.name("ezhst")
|
|
26
|
-
.description("EasyHost from the terminal: deploy apps and manage storage
|
|
26
|
+
.description("EasyHost from the terminal: deploy apps and manage storage and databases")
|
|
27
27
|
.version(packageMetadata.version)
|
|
28
28
|
.option("--json", "Print machine-readable JSON")
|
|
29
29
|
.hook("preAction", (_command, action) => {
|
|
@@ -48,7 +48,8 @@ program
|
|
|
48
48
|
.action(login);
|
|
49
49
|
program.command("logout").description("Log out").action(logout);
|
|
50
50
|
program.command("whoami").description("Show the logged in user").action(whoami);
|
|
51
|
-
program.command("
|
|
51
|
+
program.command("verify").description("Verify your email with the 6-digit code").argument("<code>").action(verify);
|
|
52
|
+
program.command("resend-verification").description("Email a new verification code").action(resendVerification);
|
|
52
53
|
program.command("forgot-password").description("Email a password reset link").option("--email <email>").action(forgotPassword);
|
|
53
54
|
const projects = program.command("projects").description("Manage projects");
|
|
54
55
|
projects.command("list").description("List projects").action(listProjects);
|
|
@@ -91,7 +92,7 @@ appScoped(domains.command("list").description("List domains and the DNS target")
|
|
|
91
92
|
appScoped(domains.command("add").description("Add a domain").argument("<hostname>")).action(addDomain);
|
|
92
93
|
appScoped(domains.command("verify").description("Check DNS and issue HTTPS").argument("<hostname>")).action(verifyDomain);
|
|
93
94
|
appScoped(domains.command("remove").description("Remove a domain").argument("<hostname>")).action(removeDomain);
|
|
94
|
-
const apps = program.command("apps").description("Manage up to
|
|
95
|
+
const apps = program.command("apps").description("Manage up to three apps per project");
|
|
95
96
|
scoped(apps.command("list").description("List apps in a project")).action(listApps);
|
|
96
97
|
scoped(apps.command("create").description("Create an app").argument("<name>")).action(createApp);
|
|
97
98
|
appScoped(apps.command("delete").description("Delete one app and its deployments").option("--yes", "Confirm")).action(deleteApp);
|
|
@@ -126,7 +127,7 @@ scoped(db.command("query").description("Run SQL").argument("[sql]").option("--fi
|
|
|
126
127
|
scoped(db.command("rows").description("Browse a table").argument("<table>").option("--page <n>", "Page", "1")).action(tableRows);
|
|
127
128
|
scoped(db.command("reset-password").description("Rotate the database password")).action(resetDatabasePassword);
|
|
128
129
|
scoped(db.command("delete").description("Delete the database and its data").option("--yes", "Confirm")).action(deleteDatabase);
|
|
129
|
-
const email = program.command("email").description("Transactional email");
|
|
130
|
+
const email = program.command("email", { hidden: true }).description("Transactional email (coming soon)");
|
|
130
131
|
scoped(email.command("info").description("Show the sender address and usage")).action(emailInfo);
|
|
131
132
|
const sender = email.command("sender").description("Sender address");
|
|
132
133
|
scoped(sender.command("create").description("Create <username>@easyhost.fun").argument("<username>")).action(createSender);
|
|
@@ -140,7 +141,7 @@ scoped(email
|
|
|
140
141
|
.option("--text <body>")
|
|
141
142
|
.option("--html <html>")).action(sendEmail);
|
|
142
143
|
scoped(email.command("logs").description("Show sent emails").option("--page <n>", "Page", "1")).action(emailLogs);
|
|
143
|
-
const keys = program.command("keys").description("API keys for the HTTP API");
|
|
144
|
+
const keys = program.command("keys", { hidden: true }).description("API keys for the HTTP API");
|
|
144
145
|
scoped(keys.command("list").description("List API keys")).action(listKeys);
|
|
145
146
|
scoped(keys.command("create").description("Create an API key").argument("<name>")).action(createKey);
|
|
146
147
|
scoped(keys.command("revoke").description("Revoke an API key").argument("<id>")).action(revokeKey);
|
package/dist/lib/api.js
CHANGED
|
@@ -29,7 +29,19 @@ export const request = async (pathname, init = {}, projectId) => {
|
|
|
29
29
|
if (res.status === 401 && !pathname.startsWith("/auth/")) {
|
|
30
30
|
throw new ApiError("Not logged in. Run `ezhst login` or set EZHST_TOKEN.", 401);
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
if (data.code === "EMAIL_NOT_VERIFIED") {
|
|
33
|
+
throw new ApiError("Your email is not verified. Run `ezhst verify <code>` with the 6-digit code from your inbox, or `ezhst resend-verification` to get a new code.", res.status);
|
|
34
|
+
}
|
|
35
|
+
if (data.code === "EMAIL_COMING_SOON") {
|
|
36
|
+
throw new ApiError("Email is coming soon. It is not available on EasyHost yet.", res.status);
|
|
37
|
+
}
|
|
38
|
+
if (typeof data.error === "string") {
|
|
39
|
+
throw new ApiError(data.error, res.status);
|
|
40
|
+
}
|
|
41
|
+
if (res.status >= 500) {
|
|
42
|
+
throw new ApiError(`EasyHost is having trouble right now (status ${res.status}). Try again in a minute.`, res.status);
|
|
43
|
+
}
|
|
44
|
+
throw new ApiError(`Request failed with status ${res.status}.`, res.status);
|
|
33
45
|
}
|
|
34
46
|
return data;
|
|
35
47
|
};
|
package/package.json
CHANGED
package/skill/SKILL.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: easyhost
|
|
3
|
-
description: Deploy and manage apps on EasyHost (free hosting) with the ezhst CLI. Use when the user asks to deploy, host, publish or ship a Node.js app to EasyHost, or to manage its environment variables, build settings, logs, custom domains, S3 storage
|
|
3
|
+
description: Deploy and manage apps on EasyHost (free hosting) with the ezhst CLI. Use when the user asks to deploy, host, publish or ship a Node.js app to EasyHost, or to manage its environment variables, build settings, logs, custom domains, S3 storage or Postgres database.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# EasyHost
|
|
7
7
|
|
|
8
|
-
EasyHost is free hosting for Node.js apps with built-in S3 storage
|
|
8
|
+
EasyHost is free hosting for Node.js apps with built-in S3 storage and Postgres (email is coming soon). It is in beta. Everything is done through the `ezhst` CLI. Run it with `npx ezhst <command>` (or `ezhst` if installed globally with `npm i -g ezhst`).
|
|
9
9
|
|
|
10
10
|
## Rules for agents
|
|
11
11
|
|
|
@@ -21,12 +21,12 @@ EasyHost is free hosting for Node.js apps with built-in S3 storage, Postgres and
|
|
|
21
21
|
Check first: `npx ezhst whoami --json`. If it fails with "Not logged in":
|
|
22
22
|
|
|
23
23
|
- Existing account: ask the user for email and password, then `npx ezhst login --email <email> --password <password> --json`
|
|
24
|
-
- New account: ask for name, email and password, then `npx ezhst register --name <name> --email <email> --password <password> --json`.
|
|
24
|
+
- New account: ask for name, email and password, then `npx ezhst register --name <name> --email <email> --password <password> --json`. Verification is mandatory: ask the user for the 6-digit code from their inbox and run `npx ezhst verify <code> --json` before any other command (`npx ezhst resend-verification` sends a new code).
|
|
25
25
|
- CI: set `EZHST_TOKEN` instead of logging in.
|
|
26
26
|
|
|
27
27
|
## 2. Pick or create a project
|
|
28
28
|
|
|
29
|
-
A project contains up to
|
|
29
|
+
A project contains up to three apps, five schedules, and shared storage and database. Each app has its own slug and URL: `https://<app-slug>.easyhost.fun`. Existing project apps retain their URLs.
|
|
30
30
|
|
|
31
31
|
```
|
|
32
32
|
npx ezhst projects list --json
|
|
@@ -86,9 +86,7 @@ Database (Postgres, one per project):
|
|
|
86
86
|
- `db create <name> | info | query "<sql>" | query --file <file.sql> | rows <table> [--page n] | reset-password | delete --yes`
|
|
87
87
|
- `db info --json` returns `connectionString` and `shadowConnectionString` (for `prisma migrate dev`). Set `DATABASE_URL` with `env set`, and run migrations from the local machine against it (for Prisma: `prisma migrate deploy`).
|
|
88
88
|
|
|
89
|
-
Email
|
|
90
|
-
- `email sender create <username>`, `email info`, `email send --from <address> --to <address> --subject <text> --text <body>` (or `--html`), `email logs`, `email sender delete`
|
|
91
|
-
- From app code: `POST https://api.easyhost.fun/api/v1/email/send` with header `Authorization: Bearer <api key>` and JSON `{ "from", "to", "subject", "text" | "html" }`. Create the key with `keys create <name>` and store it with `env set EASYHOST_API_KEY=...`.
|
|
89
|
+
Email: coming soon. The `email` commands and the email API return "Email is coming soon." Do not set up or send email on EasyHost yet.
|
|
92
90
|
|
|
93
91
|
Schedules (up to five per project, intervals in minutes):
|
|
94
92
|
- `schedules list`, `schedules create <name> --url <url> --every <minutes> [--method POST] [--headers '<json>'] [--body '<text>'] [--paused]`
|
|
@@ -96,18 +94,17 @@ Schedules (up to five per project, intervals in minutes):
|
|
|
96
94
|
- `schedules pause <id>`, `schedules resume <id>`, `schedules logs <id>`, `schedules delete <id> --yes`
|
|
97
95
|
- Public HTTP/HTTPS URLs only, intervals 1 to 43200 minutes, 30-second timeout, no redirects. First call follows one interval; saving/resuming restarts it. Latest 100 runs retained, latest 10 shown. Missed intervals are skipped; execution has up to 10 seconds of polling delay. Requests in progress may finish after pausing/deleting.
|
|
98
96
|
|
|
99
|
-
API keys:
|
|
100
|
-
- `keys list | create <name> | revoke <id>` (a key is shown only once)
|
|
101
|
-
|
|
102
97
|
Members:
|
|
103
98
|
- `members list | invite <email> | revoke <email> | remove <email> --yes | leave --yes`. Only the owner can invite, revoke, remove, rename or delete the project. Members can do everything else.
|
|
104
99
|
- `accept-invite <link-or-token>` joins a project. The logged-in email must match the invited email.
|
|
105
100
|
|
|
106
101
|
Account:
|
|
107
|
-
- `whoami`, `logout`, `resend-verification`, `forgot-password --email <email>`
|
|
102
|
+
- `whoami`, `logout`, `verify <code>`, `resend-verification`, `forgot-password --email <email>`
|
|
103
|
+
- If a command fails with "Your email is not verified", ask the user for the 6-digit code from their inbox and run `verify <code>`. Codes expire after 10 minutes; `resend-verification` sends a new one (once a minute).
|
|
104
|
+
- Limit errors ("You can have at most 3 projects.", "Each project can have at most 3 apps.") are hard limits: suggest deleting something the user no longer needs.
|
|
108
105
|
|
|
109
106
|
## Limits
|
|
110
107
|
|
|
111
|
-
Free:
|
|
108
|
+
Free: 3 projects. Per project: three apps, five schedules, one bucket and one database. One build at a time; 512 MB RAM and 1 CPU per app.
|
|
112
109
|
|
|
113
110
|
Docs: https://easyhost.fun/docs
|