embarko 0.0.0-stage → 0.1.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/README.md CHANGED
@@ -1,3 +1,65 @@
1
- # Temporary Holding Version
1
+ # embarko
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Deploy apps to [Embarko](https://embarko.ai) from your terminal or your AI agent.
4
+
5
+ ```bash
6
+ npx embarko setup
7
+ ```
8
+
9
+ One command that:
10
+
11
+ 1. installs the `embarko` CLI,
12
+ 2. adds the Embarko deploy skill to the AI agents on your machine (Claude Code, Cursor, Codex and others),
13
+ 3. adds the Embarko MCP server to Claude Code, Cursor, Codex, OpenCode, GitHub Copilot CLI and Factory Droid, where installed,
14
+ 4. signs you in through the browser.
15
+
16
+ Use `--dry-run` to see what it would change first.
17
+
18
+ ## Quick start
19
+
20
+ ```bash
21
+ embarko login # sign in (or sign up) in the browser
22
+ cd my-app
23
+ embarko deploy # live at https://<app-name>.embarko.app
24
+ ```
25
+
26
+ Or just ask your AI agent to "deploy this app to Embarko".
27
+
28
+ Not signed in, `deploy` still works: the app is temporary (deleted after 24 hours) and the
29
+ reply has a link to keep it.
30
+
31
+ ## Commands
32
+
33
+ | Command | What it does |
34
+ | --- | --- |
35
+ | `embarko setup` | Everything above |
36
+ | `embarko login` | Sign in (or sign up) in the browser. `--token <t>` saves a token you already have |
37
+ | `embarko logout` | Forget the saved sign-in |
38
+ | `embarko whoami` | Which workspace you're signed in to |
39
+ | `embarko deploy [dir]` | Pack the folder and deploy it, then wait until it's live |
40
+ | `embarko status [app]` | Is it live? |
41
+ | `embarko logs [app]` | Recent output of a server app |
42
+
43
+ Run `embarko <command> --help` for each command's options.
44
+
45
+ ## Signing in
46
+
47
+ `embarko login` opens your browser to sign in, then returns to the terminal by itself. Your
48
+ token is saved in `~/.embarko/credentials`, readable only by you. The Embarko skill reads the
49
+ same file, so your AI agent deploys as you too. `EMBARKO_TOKEN` or `DEPLOY_TOKEN` in the
50
+ environment is used instead of the file, which suits CI.
51
+
52
+ ## Environment
53
+
54
+ | Variable | Default |
55
+ | --- | --- |
56
+ | `EMBARKO_TOKEN` / `DEPLOY_TOKEN` | Token to use instead of the saved one |
57
+ | `EMBARKO_AGENT_NAME` | Shown in the deploy history (`claude-code` is detected) |
58
+ | `EMBARKO_API_URL` | `https://ship.embarko.ai` |
59
+ | `EMBARKO_SITE_URL` | `https://embarko.ai` |
60
+ | `EMBARKO_MCP_URL` | `https://mcp.embarko.ai/mcp` |
61
+ | `EMBARKO_CREDENTIALS_FILE` | `~/.embarko/credentials` |
62
+
63
+ No dependencies; needs Node 18.18+ and `tar` (built into macOS, Linux and Windows 10+).
64
+
65
+ Docs: [embarko.ai/docs](https://embarko.ai/docs) · Help: [embarko.ai/support](https://embarko.ai/support)
package/bin/embarko.js ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import { main } from "../src/cli.js";
3
+
4
+ main(process.argv.slice(2)).then(
5
+ (code) => process.exit(code ?? 0),
6
+ (err) => {
7
+ console.error(`embarko: ${err?.message ?? err}`);
8
+ if (process.env.EMBARKO_DEBUG) console.error(err?.stack);
9
+ process.exit(1);
10
+ },
11
+ );
package/package.json CHANGED
@@ -1,6 +1,34 @@
1
1
  {
2
2
  "name": "embarko",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Deploy apps to Embarko from your terminal or your AI agent, and set up the Embarko skill and MCP server in one command.",
5
+ "type": "module",
6
+ "bin": {
7
+ "embarko": "bin/embarko.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "src",
12
+ "README.md"
13
+ ],
14
+ "engines": {
15
+ "node": ">=18.18"
16
+ },
17
+ "scripts": {
18
+ "test": "node --test"
19
+ },
20
+ "keywords": [
21
+ "embarko",
22
+ "deploy",
23
+ "hosting",
24
+ "cli",
25
+ "mcp",
26
+ "ai-agent"
27
+ ],
28
+ "homepage": "https://embarko.ai",
29
+ "bugs": {
30
+ "url": "https://embarko.ai/support"
31
+ },
32
+ "author": "Embarko",
33
+ "license": "MIT"
34
+ }
package/src/cli.js ADDED
@@ -0,0 +1,78 @@
1
+ import { parseArgs } from "node:util";
2
+ import { readFileSync } from "node:fs";
3
+
4
+ const COMMANDS = {
5
+ setup: () => import("./commands/setup.js"),
6
+ login: () => import("./commands/login.js"),
7
+ logout: () => import("./commands/logout.js"),
8
+ whoami: () => import("./commands/whoami.js"),
9
+ deploy: () => import("./commands/deploy.js"),
10
+ status: () => import("./commands/status.js"),
11
+ logs: () => import("./commands/logs.js"),
12
+ };
13
+
14
+ // `insta`-style aliases, so `npx embarko agent setup` works too.
15
+ const ALIASES = { agent: "setup" };
16
+
17
+ const HELP = `embarko — deploy apps to Embarko (https://embarko.ai)
18
+
19
+ Usage:
20
+ embarko setup Install the CLI, the Embarko skill and the MCP server
21
+ in every AI tool on this machine, then sign in
22
+ embarko login Sign in through the browser (or --token <token>)
23
+ embarko logout Forget the saved sign-in on this machine
24
+ embarko whoami Show which workspace you are signed in to
25
+ embarko deploy [dir] Deploy a folder (default: current folder)
26
+ embarko status [app] Is the app live?
27
+ embarko logs [app] Recent output of a server app
28
+
29
+ Run "embarko <command> --help" for a command's options.
30
+ Docs: https://embarko.ai/docs`;
31
+
32
+ export async function main(argv) {
33
+ const [first, ...rest] = argv;
34
+ if (!first || first === "-h" || first === "--help" || first === "help") {
35
+ console.log(HELP);
36
+ return 0;
37
+ }
38
+ if (first === "-v" || first === "--version") {
39
+ console.log(version());
40
+ return 0;
41
+ }
42
+
43
+ let name = ALIASES[first] ?? first;
44
+ let args = rest;
45
+ // `embarko agent setup` → setup
46
+ if (first === "agent" && rest[0] === "setup") args = rest.slice(1);
47
+ // `embarko setup agent` → setup
48
+ if (name === "setup" && args[0] === "agent") args = args.slice(1);
49
+
50
+ const load = COMMANDS[name];
51
+ if (!load) {
52
+ console.error(`embarko: unknown command "${first}".\n\n${HELP}`);
53
+ return 1;
54
+ }
55
+ const command = await load();
56
+ let parsed;
57
+ try {
58
+ parsed = parseArgs({
59
+ args,
60
+ options: { help: { type: "boolean", short: "h" }, ...command.options },
61
+ allowPositionals: true,
62
+ strict: true,
63
+ });
64
+ } catch (err) {
65
+ console.error(`embarko ${name}: ${err.message}\n\n${command.usage}`);
66
+ return 1;
67
+ }
68
+ if (parsed.values.help) {
69
+ console.log(command.usage);
70
+ return 0;
71
+ }
72
+ return command.run(parsed.values, parsed.positionals);
73
+ }
74
+
75
+ export function version() {
76
+ const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
77
+ return pkg.version;
78
+ }
@@ -0,0 +1,207 @@
1
+ import { existsSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { agentName, errorText, request, SHIP_URL } from "../lib/api.js";
4
+ import { resolveToken } from "../lib/credentials.js";
5
+ import { appNameProblem, packDir, preflight, resolveAppName, resolveVersion } from "../lib/pack.js";
6
+ import { pollStatus, sleep } from "../lib/poll.js";
7
+ import { step, line, kv } from "../lib/out.js";
8
+
9
+ export const options = {
10
+ name: { type: "string", short: "n" },
11
+ version: { type: "string" },
12
+ "app-type": { type: "string" },
13
+ agent: { type: "string" },
14
+ "no-wait": { type: "boolean" },
15
+ json: { type: "boolean" },
16
+ };
17
+
18
+ export const usage = `Usage: embarko deploy [dir] [options]
19
+
20
+ Packs the folder (default: current folder) and deploys it. No Dockerfile
21
+ needed. Signed in, the app goes to your workspace; not signed in, it deploys
22
+ as a temporary app (deleted after 24h unless you keep it with the claim link).
23
+
24
+ Options:
25
+ -n, --name <name> App name, also the address <name>.embarko.app
26
+ (default: package.json "name" or the folder name)
27
+ --version <v> Version label (default: git short SHA or a timestamp)
28
+ --app-type <text> What the app is for, e.g. "portfolio" (optional)
29
+ --agent <name> Which AI agent is deploying (default: detected)
30
+ --no-wait Don't wait for the app to go live
31
+ --json Print the final reply as JSON`;
32
+
33
+ export async function run(values, positionals) {
34
+ const dir = path.resolve(positionals[0] ?? ".");
35
+ if (!existsSync(dir) || !statSync(dir).isDirectory()) throw new Error(`${dir} is not a folder`);
36
+
37
+ const { name, source } = resolveAppName(dir, values.name);
38
+ const problem = appNameProblem(name);
39
+ if (problem) {
40
+ throw new Error(`app name "${name}" (from ${source}) won't be accepted: ${problem}.\nApp names are 3-63 lowercase letters, digits and dashes. Pass one with --name.`);
41
+ }
42
+ const pre = preflight(dir);
43
+ if (pre) throw new Error(pre);
44
+
45
+ const version = resolveVersion(dir, values.version);
46
+ const { token, source: tokenSource } = resolveToken();
47
+ const quiet = values.json;
48
+
49
+ if (!quiet) {
50
+ step(`App: ${name} Version: ${version}`);
51
+ if (token) step(`Deploying as you (token from ${tokenSource}).`);
52
+ else step("Not signed in: deploying a temporary app, deleted after 24h unless kept.\n Run `embarko login` first to deploy straight into your workspace.");
53
+ }
54
+
55
+ const { file, tmp, venvs } = packDir(dir, name);
56
+ let reply;
57
+ try {
58
+ if (!quiet && venvs.length) step(`Leaving out virtual environment(s): ${venvs.join(", ")}`);
59
+ const size = statSync(file).size;
60
+ if (!quiet) step(`Uploading ${(size / 1024).toFixed(0)} KB...`);
61
+
62
+ const form = new FormData();
63
+ form.append("source", new Blob([readFileSync(file)], { type: "application/gzip" }), `${name}.tar.gz`);
64
+ const headers = { "X-App-Name": name, "X-App-Version": version };
65
+ const agent = agentName(values.agent);
66
+ if (agent) headers["X-Agent-Name"] = agent;
67
+ if (values["app-type"]) headers["X-App-Type"] = values["app-type"];
68
+ if (process.env.EMBARKO_LP_VARIANT) headers["lp_variant"] = process.env.EMBARKO_LP_VARIANT;
69
+
70
+ reply = await request("/apps", { method: "POST", token, headers, body: form });
71
+ } finally {
72
+ rmSync(tmp, { recursive: true, force: true });
73
+ }
74
+
75
+ const data = reply.data;
76
+ if (!data.success) {
77
+ if (quiet) console.log(JSON.stringify(data, null, 2));
78
+ throw new Error(`deploy failed: ${errorText(data, `HTTP ${reply.status}`)}`);
79
+ }
80
+
81
+ saveAppId(dir, data.app?.id, quiet);
82
+ for (const n of data.notices ?? []) line(` notice [${n.code}] ${n.detail}`);
83
+
84
+ const claimUrl = data.links?.claim;
85
+ let final = data;
86
+ if (data.status !== "live" && !values["no-wait"]) {
87
+ const statusUrl = data.links?.status;
88
+ if (!statusUrl) {
89
+ if (!quiet) step("Deploy accepted, but the reply has no status link. Check `embarko status` before calling it done.");
90
+ } else {
91
+ if (!quiet) step("Building...");
92
+ let lastShown = null;
93
+ const result = await pollStatus(statusUrl, {
94
+ token,
95
+ kind: data.app?.kind,
96
+ onTick: (s) => {
97
+ if (!quiet && s && s !== lastShown) {
98
+ line(` ${s}`);
99
+ lastShown = s;
100
+ }
101
+ },
102
+ });
103
+ final = result.data ?? data;
104
+ if (result.timedOut) {
105
+ if (quiet) console.log(JSON.stringify({ ...final, claim: claimUrl }, null, 2));
106
+ throw new Error(`still not live after 15 minutes. Check \`embarko status ${name}\` and \`embarko logs ${name}\`.`);
107
+ }
108
+ }
109
+ }
110
+
111
+ if (quiet) {
112
+ console.log(JSON.stringify({ ...final, links: { ...final.links, claim: claimUrl } }, null, 2));
113
+ return final.status === "live" || values["no-wait"] ? 0 : 1;
114
+ }
115
+
116
+ switch (final.status) {
117
+ case "live": {
118
+ step("Live.");
119
+ if (final.links?.app) kv("URL", final.links.app);
120
+ if (claimUrl) {
121
+ kv("Keep it", claimUrl);
122
+ line(" Open that link and sign in, or the app is deleted after 24 hours.");
123
+ }
124
+ for (const w of [...(data.warnings ?? []), ...(final.warnings ?? [])]) line(` warning [${w.code}] ${w.detail}`);
125
+ if (data.links?.runSchedules) return (await runSchedulesOnce(data.links.runSchedules, token)) ? 0 : 1;
126
+ return 0;
127
+ }
128
+ case "failed":
129
+ case "crashed": {
130
+ step(`Deploy ${final.status}.`);
131
+ if (final.error) line(` ${final.error}`);
132
+ if (final.links?.logs) {
133
+ const { data: logs } = await request(final.links.logs, { token });
134
+ if (logs?.logs) {
135
+ step("Logs:");
136
+ line(logs.logs);
137
+ }
138
+ }
139
+ if (final.next) kv("Next", final.next);
140
+ return 1;
141
+ }
142
+ default:
143
+ if (values["no-wait"]) {
144
+ step(`Accepted (${final.status ?? "building"}). Check with: embarko status ${name}`);
145
+ if (claimUrl) kv("Keep it", claimUrl);
146
+ return 0;
147
+ }
148
+ step(`Status: ${final.status}`);
149
+ if (final.next) kv("Next", final.next);
150
+ return 1;
151
+ }
152
+ }
153
+
154
+ // app.id goes in embarko.json so the next deploy reaches this app even after
155
+ // a rename in the dashboard. Other keys are kept as they are.
156
+ function saveAppId(dir, id, quiet) {
157
+ if (!id) return;
158
+ const file = path.join(dir, "embarko.json");
159
+ try {
160
+ const config = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : {};
161
+ if (config.appId === id) return;
162
+ const previous = config.appId;
163
+ config.appId = id;
164
+ writeFileSync(file, JSON.stringify(config, null, 2) + "\n");
165
+ if (!quiet) step(`Wrote appId to embarko.json (${previous ? "updated" : "saved"}). Commit it with the app.`);
166
+ } catch {
167
+ if (!quiet) step(`Could not write appId to embarko.json. Add "appId": "${id}" to it by hand.`);
168
+ }
169
+ }
170
+
171
+ // Runs each schedule once now the app is live: the check that it works.
172
+ async function runSchedulesOnce(url, token) {
173
+ let reply;
174
+ for (let i = 0; i < 5; i++) {
175
+ reply = (await request(url, { method: "POST", token })).data;
176
+ if (reply?.code !== "no_schedules") break;
177
+ await sleep(3000);
178
+ }
179
+ const runs = reply?.runs ?? [];
180
+ if (!runs.length) {
181
+ step("Could not start the schedules' test run:");
182
+ line(JSON.stringify(reply));
183
+ return false;
184
+ }
185
+ step("Running each schedule once to check it works...");
186
+ let ok = true;
187
+ for (const r of runs) {
188
+ if (!r.statusUrl) {
189
+ line(` ${r.path}: already running, not started again`);
190
+ continue;
191
+ }
192
+ let run;
193
+ for (let i = 0; i < 70; i++) {
194
+ run = (await request(`${SHIP_URL}${r.statusUrl}`, { token })).data;
195
+ if (run?.terminal) break;
196
+ await sleep(5000);
197
+ }
198
+ const excerpt = String(run?.responseExcerpt ?? "").slice(0, 200);
199
+ if (run?.outcome === "ok") line(` ${r.path}: ok (${run.httpStatus}) ${excerpt}`);
200
+ else {
201
+ ok = false;
202
+ line(` ${r.path}: ${run?.outcome ?? "no result"} — ${run?.error ?? ""} ${excerpt}`);
203
+ }
204
+ }
205
+ if (!ok) step("The app is live, but a schedule's test run failed. Fix that route (2xx, accepts Authorization: Bearer $CRON_SECRET) and deploy again.");
206
+ return ok;
207
+ }
@@ -0,0 +1,165 @@
1
+ import { createHash, randomBytes } from "node:crypto";
2
+ import http from "node:http";
3
+ import { errorText, request, SITE_URL } from "../lib/api.js";
4
+ import { saveToken } from "../lib/credentials.js";
5
+ import { openBrowser } from "../lib/open.js";
6
+ import { kv, line, step } from "../lib/out.js";
7
+
8
+ export const options = {
9
+ token: { type: "string" },
10
+ "no-browser": { type: "boolean" },
11
+ timeout: { type: "string" },
12
+ };
13
+
14
+ export const usage = `Usage: embarko login [--token <token>] [--no-browser]
15
+
16
+ Opens Embarko in your browser to sign in (or sign up), then saves a token
17
+ in ~/.embarko/credentials. The same sign-in works for new and existing
18
+ accounts.
19
+
20
+ Options:
21
+ --token <token> Save a token you already have (from the dashboard or
22
+ the deploy-token email) instead of using the browser
23
+ --no-browser Print the sign-in link instead of opening it
24
+ --timeout <sec> How long to wait for the browser (default: 300)`;
25
+
26
+ const CALLBACK_PATH = "/embarko-cli/callback";
27
+
28
+ export async function run(values) {
29
+ if (values.token) return saveExistingToken(values.token.trim());
30
+
31
+ const result = await browserLogin({
32
+ openIt: !values["no-browser"],
33
+ timeoutMs: (Number(values.timeout) || 300) * 1000,
34
+ });
35
+ const file = saveToken(result.accessToken, {
36
+ companyId: result.companyId,
37
+ companyName: result.companyName,
38
+ kind: result.kind,
39
+ tokenId: result.tokenId,
40
+ });
41
+ step(`Signed in${result.companyName ? ` to ${result.companyName}` : ""}. Token saved in ${file}.`);
42
+ return 0;
43
+ }
44
+
45
+ // Loopback redirect (RFC 8252): listen on a random port of 127.0.0.1, send the
46
+ // browser to the connector sign-in page with that as redirect_uri, and swap the
47
+ // one-time code it comes back with for a token. No polling. PKCE (S256) binds
48
+ // the code to this process: only the verifier kept here can redeem it.
49
+ export async function browserLogin({ openIt = true, timeoutMs = 300_000 } = {}) {
50
+ const state = randomBytes(24).toString("base64url");
51
+ const codeVerifier = randomBytes(32).toString("base64url");
52
+ const codeChallenge = createHash("sha256").update(codeVerifier).digest("base64url");
53
+ let settle;
54
+ const done = new Promise((resolve, reject) => (settle = { resolve, reject }));
55
+
56
+ const server = http.createServer((req, res) => {
57
+ const url = new URL(req.url, "http://127.0.0.1");
58
+ if (url.pathname !== CALLBACK_PATH) {
59
+ res.writeHead(404).end();
60
+ return;
61
+ }
62
+ const q = url.searchParams;
63
+ // A request without our state is not our sign-in (another tab, a stale
64
+ // link): ignore it and keep waiting.
65
+ if (q.get("state") !== state) {
66
+ page(res, 400, "This sign-in link doesn't match the one the terminal is waiting for. Start again with `embarko login`.");
67
+ return;
68
+ }
69
+ if (q.get("error")) {
70
+ page(res, 400, "Sign-in didn't complete. You can close this tab and try again.");
71
+ settle.reject(new Error(`sign-in failed: ${q.get("error_description") || q.get("error")}`));
72
+ return;
73
+ }
74
+ const code = q.get("code");
75
+ if (!code) {
76
+ page(res, 400, "No sign-in code came back. Start again with `embarko login`.");
77
+ settle.reject(new Error("no code in the sign-in redirect"));
78
+ return;
79
+ }
80
+ exchange(code, codeVerifier).then(
81
+ (data) => {
82
+ page(res, 200, `Signed in${data.companyName ? ` to ${escapeHtml(data.companyName)}` : ""}. You can close this tab and go back to the terminal.`);
83
+ settle.resolve(data);
84
+ },
85
+ (err) => {
86
+ page(res, 400, escapeHtml(err.message));
87
+ settle.reject(err);
88
+ },
89
+ );
90
+ });
91
+
92
+ await new Promise((resolve, reject) => {
93
+ server.once("error", reject);
94
+ server.listen(0, "127.0.0.1", resolve);
95
+ });
96
+ const { port } = server.address();
97
+ const redirectUri = `http://127.0.0.1:${port}${CALLBACK_PATH}`;
98
+ const loginUrl = `${SITE_URL}/connector/login?${new URLSearchParams({
99
+ redirect_uri: redirectUri,
100
+ state,
101
+ code_challenge: codeChallenge,
102
+ code_challenge_method: "S256",
103
+ })}`;
104
+
105
+ const timer = setTimeout(() => {
106
+ settle.reject(
107
+ new Error(
108
+ "timed out waiting for the browser.\n" +
109
+ " If the browser ended on the Embarko dashboard instead of a \"Signed in\" page, this Embarko\n" +
110
+ " server doesn't accept CLI sign-in yet. Sign in to the dashboard, create a deploy token,\n" +
111
+ " and run: embarko login --token <token>",
112
+ ),
113
+ );
114
+ }, timeoutMs);
115
+
116
+ step("Sign in to Embarko in your browser.");
117
+ kv("If it doesn't open, go to", loginUrl);
118
+ if (openIt && !openBrowser(loginUrl)) line(" (could not open a browser automatically)");
119
+ line(" Waiting...");
120
+
121
+ try {
122
+ return await done;
123
+ } finally {
124
+ clearTimeout(timer);
125
+ server.closeAllConnections?.();
126
+ server.close();
127
+ }
128
+ }
129
+
130
+ async function exchange(code, codeVerifier) {
131
+ const { status, data } = await request("/api/connector/token", { method: "POST", json: { code, code_verifier: codeVerifier } });
132
+ if (status === 409 && data.error === "no_company") {
133
+ throw new Error(`this account has no workspace yet. Finish setup at ${SITE_URL}/app, then run \`embarko login\` again.`);
134
+ }
135
+ if (status !== 201 && status !== 200) throw new Error(`could not finish sign-in: ${errorText(data, `HTTP ${status}`)}`);
136
+ return { ...data, accessToken: data.access_token ?? data.accessToken };
137
+ }
138
+
139
+ async function saveExistingToken(token) {
140
+ const data = await validateToken(token);
141
+ if (!data) throw new Error("that token isn't valid. Check it and try again.");
142
+ const file = saveToken(token, { companyId: data.companyId, kind: data.kind, tokenId: data.tokenId });
143
+ step(`Token saved in ${file}.`);
144
+ return 0;
145
+ }
146
+
147
+ // { valid, companyId, kind, tokenId }, or null for a token Embarko rejects.
148
+ // Anything else (a 5xx, a rate limit) throws: it says nothing about the token.
149
+ export async function validateToken(token) {
150
+ const { status, data } = await request("/api/connector/token/validate", { token });
151
+ if (status === 200 && data.valid) return data;
152
+ if (status === 401 || status === 403) return null;
153
+ throw new Error(`could not check the token with Embarko: ${errorText(data, `HTTP ${status}`)}`);
154
+ }
155
+
156
+ function page(res, status, message) {
157
+ res.writeHead(status, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store" });
158
+ res.end(`<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Embarko CLI</title></head>
159
+ <body style="font-family:system-ui,sans-serif;max-width:520px;margin:96px auto;padding:0 16px;color:#111">
160
+ <h1 style="font-size:22px">Embarko</h1><p style="font-size:16px;line-height:1.5">${message}</p></body></html>`);
161
+ }
162
+
163
+ function escapeHtml(s) {
164
+ return String(s).replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);
165
+ }
@@ -0,0 +1,18 @@
1
+ import { clearToken, credentialsPath } from "../lib/credentials.js";
2
+ import { step } from "../lib/out.js";
3
+
4
+ export const options = {};
5
+
6
+ export const usage = `Usage: embarko logout
7
+
8
+ Deletes the saved token from this machine. The token itself stays valid
9
+ until you revoke it on the Embarko dashboard (Settings → Tokens).`;
10
+
11
+ export async function run() {
12
+ if (clearToken()) step(`Signed out: removed ${credentialsPath()}.`);
13
+ else step("Not signed in on this machine.");
14
+ if (process.env.EMBARKO_TOKEN || process.env.DEPLOY_TOKEN) {
15
+ step("Note: a token is still set in your environment (EMBARKO_TOKEN or DEPLOY_TOKEN).");
16
+ }
17
+ return 0;
18
+ }
@@ -0,0 +1,39 @@
1
+ import { errorText, request } from "../lib/api.js";
2
+ import { resolveToken } from "../lib/credentials.js";
3
+ import { resolveAppName } from "../lib/pack.js";
4
+
5
+ export const options = {
6
+ stream: { type: "string", short: "s" },
7
+ json: { type: "boolean" },
8
+ };
9
+
10
+ export const usage = `Usage: embarko logs [app] [--stream stderr|stdout] [--json]
11
+
12
+ About the last 8KB of a server app's output (a snapshot, not a stream).
13
+ After a failed build you get that build's log. Static sites have no logs.
14
+
15
+ Options:
16
+ -s, --stream <name> stderr (default) or stdout`;
17
+
18
+ export async function run(values, positionals) {
19
+ const name = positionals[0] ?? resolveAppName(".").name;
20
+ const stream = values.stream ?? "stderr";
21
+ if (!["stderr", "stdout"].includes(stream)) throw new Error("--stream must be stderr or stdout");
22
+ const { token } = resolveToken();
23
+ const { status, data } = await request(`/apps/${encodeURIComponent(name)}/logs?stream=${stream}`, { token });
24
+ if (values.json) {
25
+ console.log(JSON.stringify(data, null, 2));
26
+ return status === 200 ? 0 : 1;
27
+ }
28
+ if (status !== 200) {
29
+ const hint = status === 404 && !token ? "\nIf the app has been kept (claimed), sign in first: embarko login" : "";
30
+ throw new Error(`${errorText(data, `HTTP ${status}`)}${hint}`);
31
+ }
32
+ if (data.available === false) {
33
+ console.log(data.message ?? "No logs for this app (static sites have none).");
34
+ return 0;
35
+ }
36
+ if (data.source === "build") console.error("(log of the last failed build)");
37
+ process.stdout.write(String(data.logs ?? "") + (String(data.logs ?? "").endsWith("\n") ? "" : "\n"));
38
+ return 0;
39
+ }