@deaduchiha/orbito 0.1.0 → 0.1.1
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/orbito.js +76 -19
- package/package.json +1 -1
package/dist/orbito.js
CHANGED
|
@@ -2157,7 +2157,7 @@ var {
|
|
|
2157
2157
|
// package.json
|
|
2158
2158
|
var package_default = {
|
|
2159
2159
|
name: "@deaduchiha/orbito",
|
|
2160
|
-
version: "0.1.
|
|
2160
|
+
version: "0.1.1",
|
|
2161
2161
|
description: "Deploy, follow logs and check migrations of apps on an Orbito server",
|
|
2162
2162
|
license: "UNLICENSED",
|
|
2163
2163
|
bin: {
|
|
@@ -7845,6 +7845,13 @@ function realRuntime() {
|
|
|
7845
7845
|
resolve(/^y(es)?$/i.test(a.trim()));
|
|
7846
7846
|
});
|
|
7847
7847
|
}),
|
|
7848
|
+
ask: (question) => new Promise((resolve) => {
|
|
7849
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stderr });
|
|
7850
|
+
rl.question(question, (a) => {
|
|
7851
|
+
rl.close();
|
|
7852
|
+
resolve(a);
|
|
7853
|
+
});
|
|
7854
|
+
}),
|
|
7848
7855
|
onInterrupt: (fn) => {
|
|
7849
7856
|
process.on("SIGINT", fn);
|
|
7850
7857
|
return () => process.off("SIGINT", fn);
|
|
@@ -8036,10 +8043,10 @@ async function run(argv, rt) {
|
|
|
8036
8043
|
throw new CliError(`This server does not speak CLI API ${API_VERSION}. Update the CLI or the server.`, EXIT.invalid);
|
|
8037
8044
|
return caps.data;
|
|
8038
8045
|
}
|
|
8039
|
-
|
|
8046
|
+
async function loginTo(serverUrl) {
|
|
8040
8047
|
let server;
|
|
8041
8048
|
try {
|
|
8042
|
-
server = new URL(
|
|
8049
|
+
server = new URL(serverUrl);
|
|
8043
8050
|
} catch {
|
|
8044
8051
|
throw new CliError("--server must be a URL", EXIT.invalid);
|
|
8045
8052
|
}
|
|
@@ -8048,7 +8055,10 @@ async function run(argv, rt) {
|
|
|
8048
8055
|
try {
|
|
8049
8056
|
return await rt.fetch(auth(p), {
|
|
8050
8057
|
method: "POST",
|
|
8051
|
-
headers: {
|
|
8058
|
+
headers: {
|
|
8059
|
+
"content-type": "application/json",
|
|
8060
|
+
origin: server.origin
|
|
8061
|
+
},
|
|
8052
8062
|
body: JSON.stringify(body)
|
|
8053
8063
|
});
|
|
8054
8064
|
} catch (e) {
|
|
@@ -8079,7 +8089,10 @@ async function run(argv, rt) {
|
|
|
8079
8089
|
sessionToken: body.access_token,
|
|
8080
8090
|
label: `orbito cli on ${rt.hostname}`
|
|
8081
8091
|
});
|
|
8082
|
-
saveCredential(rt, server.origin, {
|
|
8092
|
+
saveCredential(rt, server.origin, {
|
|
8093
|
+
token: ex.token,
|
|
8094
|
+
expiresAt: ex.expiresAt
|
|
8095
|
+
});
|
|
8083
8096
|
say(`Logged in to ${server.origin}. Apps: ${ex.apps.map((a) => `${a.id} (${a.level})`).join(", ") || "none yet"}`);
|
|
8084
8097
|
if (g().json)
|
|
8085
8098
|
emit({ type: "login", server: server.origin, apps: ex.apps });
|
|
@@ -8098,7 +8111,8 @@ async function run(argv, rt) {
|
|
|
8098
8111
|
throw new CliError(`Login failed: ${body.error ?? t.status}`, EXIT.failed);
|
|
8099
8112
|
}
|
|
8100
8113
|
throw new CliError("The login code expired. Run orbito login again.", EXIT.denied);
|
|
8101
|
-
}
|
|
8114
|
+
}
|
|
8115
|
+
program.command("login").description("authorize this machine through your browser").requiredOption("--server <url>", "Orbito server, for example https://orbito.example.com").action((o) => loginTo(o.server));
|
|
8102
8116
|
program.command("logout").description("revoke and remove the machine credential").option("--server <url>", "defaults to the server in orbito.json").action(async (o) => {
|
|
8103
8117
|
const server = o.server ?? cfg().server;
|
|
8104
8118
|
const token = loadToken(rt, server);
|
|
@@ -8125,27 +8139,60 @@ async function run(argv, rt) {
|
|
|
8125
8139
|
rt.out(` ${a.id} ${a.level} ${a.name}
|
|
8126
8140
|
`);
|
|
8127
8141
|
});
|
|
8128
|
-
program.command("init").description("
|
|
8142
|
+
program.command("init").description("link this repository to an Orbito app (asks what it needs)").option("--app <id>", "the app id; omit to pick from the apps you can reach").option("--server <url>", "Orbito server (defaults to the one in an existing orbito.json)").option("--scripts", "add deploy, tail, deploy:status and db:remote:status to package.json").action(async (o) => {
|
|
8129
8143
|
let server = o.server;
|
|
8130
8144
|
if (!server) {
|
|
8131
8145
|
try {
|
|
8132
8146
|
server = loadConfig(rt, g().config).server;
|
|
8133
8147
|
} catch {
|
|
8134
|
-
|
|
8148
|
+
if (!rt.isTTY)
|
|
8149
|
+
throw new CliError("Pass --server <url> the first time.", EXIT.invalid);
|
|
8150
|
+
const a = (await rt.ask("Orbito server (for example orbito.example.com): ")).trim();
|
|
8151
|
+
if (!a)
|
|
8152
|
+
throw new CliError("Cancelled.", EXIT.invalid);
|
|
8153
|
+
server = /^https?:\/\//.test(a) ? a : `https://${a}`;
|
|
8135
8154
|
}
|
|
8136
8155
|
}
|
|
8137
|
-
|
|
8138
|
-
|
|
8139
|
-
|
|
8156
|
+
try {
|
|
8157
|
+
server = new URL(server).origin;
|
|
8158
|
+
} catch {
|
|
8159
|
+
throw new CliError("The server must be a URL, for example https://orbito.example.com", EXIT.invalid);
|
|
8160
|
+
}
|
|
8161
|
+
if (!loadToken(rt, server)) {
|
|
8162
|
+
info(`Not logged in to ${server} yet, logging in first.`);
|
|
8163
|
+
await loginTo(server);
|
|
8164
|
+
}
|
|
8165
|
+
const me = await clientFor(server).call("GET", "/me");
|
|
8166
|
+
let app = o.app;
|
|
8167
|
+
if (!app) {
|
|
8168
|
+
if (me.apps.length === 0)
|
|
8169
|
+
throw new CliError("You have no apps on this server yet. Ask an administrator for access.", EXIT.denied);
|
|
8170
|
+
if (me.apps.length === 1)
|
|
8171
|
+
app = me.apps[0].id;
|
|
8172
|
+
else {
|
|
8173
|
+
const list = me.apps.map((a, i) => ` ${i + 1}) ${a.id} (${a.level}) ${a.name}`).join(`
|
|
8174
|
+
`);
|
|
8175
|
+
if (!rt.isTTY)
|
|
8176
|
+
throw new CliError(`Pass --app <id>. Apps you can use:
|
|
8177
|
+
${list}`, EXIT.invalid);
|
|
8178
|
+
info(`Which app is this repository?
|
|
8179
|
+
${list}`);
|
|
8180
|
+
const n = Number((await rt.ask("Number: ")).trim());
|
|
8181
|
+
if (!Number.isInteger(n) || n < 1 || n > me.apps.length)
|
|
8182
|
+
throw new CliError("Cancelled.", EXIT.invalid);
|
|
8183
|
+
app = me.apps[n - 1].id;
|
|
8184
|
+
}
|
|
8185
|
+
}
|
|
8186
|
+
const mine = me.apps.find((a) => a.id === app);
|
|
8140
8187
|
if (!mine)
|
|
8141
|
-
throw new CliError(`You have no access to an app named '${
|
|
8188
|
+
throw new CliError(`You have no access to an app named '${app}'. Apps you can use: ${me.apps.map((a) => a.id).join(", ") || "none"}. If an administrator just gave you access, run: orbito login --server ${server}`, EXIT.denied);
|
|
8142
8189
|
const file = writeConfig(rt, {
|
|
8143
|
-
$schema: "./node_modules/@orbito/
|
|
8190
|
+
$schema: "./node_modules/@deaduchiha/orbito/config.schema.json",
|
|
8144
8191
|
version: 1,
|
|
8145
|
-
server
|
|
8146
|
-
appId:
|
|
8192
|
+
server,
|
|
8193
|
+
appId: app
|
|
8147
8194
|
}, g().config);
|
|
8148
|
-
say(`
|
|
8195
|
+
say(`Linked to '${app}' on ${server} (you have '${mine.level}'). Wrote ${file}; commit it, credentials stay outside the repository.`);
|
|
8149
8196
|
const pkgFile = path3.join(path3.dirname(file), "package.json");
|
|
8150
8197
|
if (fs3.existsSync(pkgFile)) {
|
|
8151
8198
|
const pkg = JSON.parse(fs3.readFileSync(pkgFile, "utf8"));
|
|
@@ -8154,7 +8201,7 @@ async function run(argv, rt) {
|
|
|
8154
8201
|
say(`package.json scripts to add:
|
|
8155
8202
|
${add.map(([k, v]) => ` "${k}": "${v}"`).join(`
|
|
8156
8203
|
`)}`);
|
|
8157
|
-
const yes = o.scripts || rt.isTTY && await rt.
|
|
8204
|
+
const yes = o.scripts || rt.isTTY && !/^n/i.test((await rt.ask("Add them? [Y/n] ")).trim());
|
|
8158
8205
|
if (yes) {
|
|
8159
8206
|
pkg.scripts = { ...pkg.scripts, ...Object.fromEntries(add) };
|
|
8160
8207
|
fs3.writeFileSync(pkgFile, JSON.stringify(pkg, null, 2) + `
|
|
@@ -8164,6 +8211,8 @@ ${add.map(([k, v]) => ` "${k}": "${v}"`).join(`
|
|
|
8164
8211
|
say("Not added. Pass --scripts to add them.");
|
|
8165
8212
|
}
|
|
8166
8213
|
}
|
|
8214
|
+
say(`
|
|
8215
|
+
Next: orbito doctor then orbito deploy --dry-run`);
|
|
8167
8216
|
});
|
|
8168
8217
|
const configCmd = program.command("config").description("configuration commands");
|
|
8169
8218
|
configCmd.command("validate").description("validate orbito.json and server compatibility").action(async () => {
|
|
@@ -8411,7 +8460,11 @@ ${add.map(([k, v]) => ` "${k}": "${v}"`).join(`
|
|
|
8411
8460
|
try {
|
|
8412
8461
|
results.push({ check: name, ok: true, detail: await fn() });
|
|
8413
8462
|
} catch (e) {
|
|
8414
|
-
results.push({
|
|
8463
|
+
results.push({
|
|
8464
|
+
check: name,
|
|
8465
|
+
ok: false,
|
|
8466
|
+
detail: e.message
|
|
8467
|
+
});
|
|
8415
8468
|
}
|
|
8416
8469
|
};
|
|
8417
8470
|
let c = null;
|
|
@@ -8455,7 +8508,11 @@ ${add.map(([k, v]) => ` "${k}": "${v}"`).join(`
|
|
|
8455
8508
|
return e.exitCode === 0 ? EXIT.ok : EXIT.invalid;
|
|
8456
8509
|
const err = e;
|
|
8457
8510
|
if (g().json)
|
|
8458
|
-
emit({
|
|
8511
|
+
emit({
|
|
8512
|
+
type: "error",
|
|
8513
|
+
error: err.message,
|
|
8514
|
+
code: e instanceof ApiFailure ? e.code : "error"
|
|
8515
|
+
});
|
|
8459
8516
|
else
|
|
8460
8517
|
info(err.message);
|
|
8461
8518
|
return e instanceof CliError ? e.exit : EXIT.failed;
|