@nestica/cli 0.3.0 → 0.4.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 +4 -1
- package/dist/cli.js +176 -85
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -74,7 +74,10 @@ Global flags: `-H/--base-url`, `--api-key`, `--profile`,
|
|
|
74
74
|
needs the Firebase project's web OAuth client id):
|
|
75
75
|
`nestica login --google --google-client-id <id> --api-key <key>`
|
|
76
76
|
|
|
77
|
-
`logout` deletes the session file.
|
|
77
|
+
`logout` deletes the session file. Running `login` while already
|
|
78
|
+
signed in just reports the current session — `logout` first to switch
|
|
79
|
+
accounts (ID tokens refresh automatically, so re-login is never needed
|
|
80
|
+
to renew them).
|
|
78
81
|
|
|
79
82
|
### set-profile
|
|
80
83
|
|
package/dist/cli.js
CHANGED
|
@@ -3380,7 +3380,7 @@ var program = new Command();
|
|
|
3380
3380
|
// package.json
|
|
3381
3381
|
var package_default = {
|
|
3382
3382
|
name: "@nestica/cli",
|
|
3383
|
-
version: "0.
|
|
3383
|
+
version: "0.4.0",
|
|
3384
3384
|
type: "module",
|
|
3385
3385
|
description: "Command-line client for the Nestica REST API",
|
|
3386
3386
|
license: "MIT",
|
|
@@ -3788,40 +3788,148 @@ ${url2}`
|
|
|
3788
3788
|
}
|
|
3789
3789
|
}
|
|
3790
3790
|
|
|
3791
|
-
// src/
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3791
|
+
// src/output/colors.ts
|
|
3792
|
+
var IDENTITY_COLORS = {
|
|
3793
|
+
dim: (text) => text,
|
|
3794
|
+
bold: (text) => text,
|
|
3795
|
+
cyan: (text) => text,
|
|
3796
|
+
green: (text) => text,
|
|
3797
|
+
yellow: (text) => text,
|
|
3798
|
+
red: (text) => text,
|
|
3799
|
+
magenta: (text) => text
|
|
3800
|
+
};
|
|
3801
|
+
function wrap(code) {
|
|
3802
|
+
return (text) => `\x1B[${code}m${text}\x1B[0m`;
|
|
3803
|
+
}
|
|
3804
|
+
var ANSI_COLORS = {
|
|
3805
|
+
dim: wrap("2"),
|
|
3806
|
+
bold: wrap("1"),
|
|
3807
|
+
cyan: wrap("36"),
|
|
3808
|
+
green: wrap("32"),
|
|
3809
|
+
yellow: wrap("33"),
|
|
3810
|
+
red: wrap("31"),
|
|
3811
|
+
magenta: wrap("35")
|
|
3812
|
+
};
|
|
3813
|
+
function pickColors(options) {
|
|
3814
|
+
const stream = options.stream ?? process.stdout;
|
|
3815
|
+
if (options.noColor || process.env["NO_COLOR"] !== void 0 || !stream.isTTY) {
|
|
3816
|
+
return IDENTITY_COLORS;
|
|
3802
3817
|
}
|
|
3818
|
+
return ANSI_COLORS;
|
|
3803
3819
|
}
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3820
|
+
|
|
3821
|
+
// src/commands/prompt.ts
|
|
3822
|
+
import { createInterface, emitKeypressEvents } from "node:readline";
|
|
3823
|
+
var lines = [];
|
|
3824
|
+
var reader;
|
|
3825
|
+
var closed = false;
|
|
3826
|
+
var resolveLine;
|
|
3827
|
+
function ensureReader() {
|
|
3828
|
+
if (reader || closed) {
|
|
3829
|
+
return;
|
|
3830
|
+
}
|
|
3831
|
+
reader = createInterface({ input: process.stdin, output: process.stdout });
|
|
3832
|
+
reader.on("line", (line) => {
|
|
3833
|
+
lines.push(line);
|
|
3834
|
+
resolveLine?.();
|
|
3835
|
+
resolveLine = void 0;
|
|
3808
3836
|
});
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3837
|
+
reader.on("close", () => {
|
|
3838
|
+
closed = true;
|
|
3839
|
+
resolveLine?.();
|
|
3840
|
+
resolveLine = void 0;
|
|
3841
|
+
});
|
|
3842
|
+
}
|
|
3843
|
+
async function nextLine() {
|
|
3844
|
+
ensureReader();
|
|
3845
|
+
if (lines.length > 0) {
|
|
3846
|
+
return lines.shift() ?? "";
|
|
3847
|
+
}
|
|
3848
|
+
if (closed) {
|
|
3849
|
+
return "";
|
|
3818
3850
|
}
|
|
3851
|
+
await new Promise((resolve) => {
|
|
3852
|
+
resolveLine = resolve;
|
|
3853
|
+
});
|
|
3854
|
+
return lines.shift() ?? "";
|
|
3855
|
+
}
|
|
3856
|
+
function closePrompts() {
|
|
3857
|
+
reader?.close();
|
|
3858
|
+
reader = void 0;
|
|
3859
|
+
closed = false;
|
|
3860
|
+
}
|
|
3861
|
+
async function prompt(label2) {
|
|
3862
|
+
process.stdout.write(`${label2} `);
|
|
3863
|
+
return (await nextLine()).trim();
|
|
3864
|
+
}
|
|
3865
|
+
async function promptHidden(label2) {
|
|
3866
|
+
process.stdout.write(`${label2} `);
|
|
3867
|
+
if (!process.stdin.isTTY) {
|
|
3868
|
+
const answer = await nextLine();
|
|
3869
|
+
return answer.replace(/\r$/, "");
|
|
3870
|
+
}
|
|
3871
|
+
if (lines.length > 0) {
|
|
3872
|
+
return lines.shift()?.replace(/\r$/, "") ?? "";
|
|
3873
|
+
}
|
|
3874
|
+
closePrompts();
|
|
3875
|
+
const input = process.stdin;
|
|
3876
|
+
return new Promise((resolve) => {
|
|
3877
|
+
let value = "";
|
|
3878
|
+
const onKey = (ch, key) => {
|
|
3879
|
+
if (key.ctrl && (key.name === "c" || key.name === "d")) {
|
|
3880
|
+
restore();
|
|
3881
|
+
process.stdout.write("\n");
|
|
3882
|
+
process.kill(process.pid, "SIGINT");
|
|
3883
|
+
return;
|
|
3884
|
+
}
|
|
3885
|
+
if (key.name === "return" || key.name === "enter") {
|
|
3886
|
+
restore();
|
|
3887
|
+
process.stdout.write("\n");
|
|
3888
|
+
resolve(value);
|
|
3889
|
+
return;
|
|
3890
|
+
}
|
|
3891
|
+
if (key.name === "backspace") {
|
|
3892
|
+
value = value.slice(0, -1);
|
|
3893
|
+
process.stdout.write("\b \b");
|
|
3894
|
+
return;
|
|
3895
|
+
}
|
|
3896
|
+
if (typeof ch === "string" && ch.length === 1 && !key.ctrl && !key.meta) {
|
|
3897
|
+
value += ch;
|
|
3898
|
+
process.stdout.write("*");
|
|
3899
|
+
}
|
|
3900
|
+
};
|
|
3901
|
+
const restore = () => {
|
|
3902
|
+
input.removeListener("keypress", onKey);
|
|
3903
|
+
input.removeListener("end", onEnd);
|
|
3904
|
+
input.pause();
|
|
3905
|
+
if (input.isRaw) {
|
|
3906
|
+
input.setRawMode(false);
|
|
3907
|
+
}
|
|
3908
|
+
};
|
|
3909
|
+
const onEnd = () => {
|
|
3910
|
+
restore();
|
|
3911
|
+
process.stdout.write("\n");
|
|
3912
|
+
resolve(value);
|
|
3913
|
+
};
|
|
3914
|
+
emitKeypressEvents(input);
|
|
3915
|
+
input.on("keypress", onKey);
|
|
3916
|
+
input.once("end", onEnd);
|
|
3917
|
+
input.setRawMode(true);
|
|
3918
|
+
input.resume();
|
|
3919
|
+
});
|
|
3819
3920
|
}
|
|
3820
3921
|
|
|
3821
3922
|
// src/commands/login.ts
|
|
3822
3923
|
var EXPIRY_MARGIN_MS = 6e4;
|
|
3823
3924
|
async function loginAction(options) {
|
|
3824
3925
|
const session = loadSession();
|
|
3926
|
+
if (session.idToken) {
|
|
3927
|
+
const identity = session.email ?? session.uid;
|
|
3928
|
+
console.log(`Session: ${sessionPath()}`);
|
|
3929
|
+
console.log("Run `nestica logout` first to change account.");
|
|
3930
|
+
console.log(pickColors({}).green(`Already logged in as ${identity}.`));
|
|
3931
|
+
return;
|
|
3932
|
+
}
|
|
3825
3933
|
const connection = resolveConnection(
|
|
3826
3934
|
{ baseUrl: options.baseUrl, apiKey: options.apiKey },
|
|
3827
3935
|
session
|
|
@@ -3832,21 +3940,27 @@ async function loginAction(options) {
|
|
|
3832
3940
|
);
|
|
3833
3941
|
}
|
|
3834
3942
|
const result = options.google ? await googleLogin(connection.apiKey, connection.baseUrl, options, session) : await passwordLogin(connection.baseUrl, connection.apiKey, options);
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3943
|
+
const path2 = sessionPath();
|
|
3944
|
+
saveSession(
|
|
3945
|
+
{
|
|
3946
|
+
...session,
|
|
3947
|
+
baseUrl: connection.baseUrl,
|
|
3948
|
+
apiKey: connection.apiKey,
|
|
3949
|
+
email: result.email ?? session.email,
|
|
3950
|
+
uid: result.uid,
|
|
3951
|
+
idToken: result.idToken,
|
|
3952
|
+
refreshToken: result.refreshToken,
|
|
3953
|
+
expiresAt: Date.now() + result.expiresIn * 1e3 - EXPIRY_MARGIN_MS
|
|
3954
|
+
},
|
|
3955
|
+
path2
|
|
3956
|
+
);
|
|
3957
|
+
console.log(`Session saved to ${path2}`);
|
|
3958
|
+
console.log(pickColors({}).green(`Logged in as ${result.email ?? result.uid}.`));
|
|
3846
3959
|
}
|
|
3847
3960
|
async function passwordLogin(baseUrl, apiKey, options) {
|
|
3848
|
-
const email3 = options.email ?? await prompt("Email:
|
|
3849
|
-
const password = options.password ?? await promptHidden("Password:
|
|
3961
|
+
const email3 = options.email ?? await prompt("Email:");
|
|
3962
|
+
const password = options.password ?? await promptHidden("Password:");
|
|
3963
|
+
closePrompts();
|
|
3850
3964
|
if (!email3 || !password) {
|
|
3851
3965
|
throw new Error("Email and password are required.");
|
|
3852
3966
|
}
|
|
@@ -3865,10 +3979,16 @@ async function googleLogin(apiKey, baseUrl, options, session) {
|
|
|
3865
3979
|
|
|
3866
3980
|
// src/commands/logout.ts
|
|
3867
3981
|
function logoutAction() {
|
|
3982
|
+
const session = loadSession();
|
|
3868
3983
|
if (removeSession()) {
|
|
3869
|
-
|
|
3984
|
+
const identity = session.email ?? session.uid;
|
|
3985
|
+
console.log(`Session removed: ${sessionPath()}`);
|
|
3986
|
+
console.log(
|
|
3987
|
+
pickColors({}).green(identity ? `Logged out as ${identity}.` : "Logged out.")
|
|
3988
|
+
);
|
|
3870
3989
|
} else {
|
|
3871
|
-
console.log(
|
|
3990
|
+
console.log(`(no session file at ${sessionPath()})`);
|
|
3991
|
+
console.log(pickColors({}).green("Not logged in."));
|
|
3872
3992
|
}
|
|
3873
3993
|
}
|
|
3874
3994
|
|
|
@@ -3886,7 +4006,7 @@ function withComma(block) {
|
|
|
3886
4006
|
const last = block.pop() ?? "";
|
|
3887
4007
|
return [...block, `${last},`];
|
|
3888
4008
|
}
|
|
3889
|
-
function
|
|
4009
|
+
function lines2(value, colors, depth) {
|
|
3890
4010
|
const pad = " ".repeat(depth);
|
|
3891
4011
|
const inner = " ".repeat(depth + 1);
|
|
3892
4012
|
if (value === null) {
|
|
@@ -3906,7 +4026,7 @@ function lines(value, colors, depth) {
|
|
|
3906
4026
|
}
|
|
3907
4027
|
const out2 = [pad + colors.dim("[")];
|
|
3908
4028
|
value.forEach((item, index) => {
|
|
3909
|
-
const block =
|
|
4029
|
+
const block = lines2(item, colors, depth + 1);
|
|
3910
4030
|
out2.push(...index < value.length - 1 ? withComma(block) : block);
|
|
3911
4031
|
});
|
|
3912
4032
|
out2.push(pad + colors.dim("]"));
|
|
@@ -3918,7 +4038,7 @@ function lines(value, colors, depth) {
|
|
|
3918
4038
|
}
|
|
3919
4039
|
const out = [pad + colors.dim("{")];
|
|
3920
4040
|
entries.forEach(([key, val], index) => {
|
|
3921
|
-
const block =
|
|
4041
|
+
const block = lines2(val, colors, depth + 1);
|
|
3922
4042
|
const first = block[0] ?? "";
|
|
3923
4043
|
block[0] = `${inner}${colors.cyan(JSON.stringify(key))}: ${first.slice(inner.length)}`;
|
|
3924
4044
|
out.push(...index < entries.length - 1 ? withComma(block) : block);
|
|
@@ -3927,7 +4047,7 @@ function lines(value, colors, depth) {
|
|
|
3927
4047
|
return out;
|
|
3928
4048
|
}
|
|
3929
4049
|
function prettyJson(value, colors) {
|
|
3930
|
-
return
|
|
4050
|
+
return lines2(value, colors, 0).join("\n");
|
|
3931
4051
|
}
|
|
3932
4052
|
function compactJson(value) {
|
|
3933
4053
|
return JSON.stringify(value);
|
|
@@ -4122,8 +4242,9 @@ async function pickProfile(ctx) {
|
|
|
4122
4242
|
items.forEach((profile, index2) => {
|
|
4123
4243
|
console.log(`${index2 + 1}. ${profile.name ?? profile.id}`);
|
|
4124
4244
|
});
|
|
4125
|
-
const answer = await prompt("Select a profile [1]:
|
|
4126
|
-
|
|
4245
|
+
const answer = await prompt("Select a profile [1]:");
|
|
4246
|
+
closePrompts();
|
|
4247
|
+
const index = answer === "" ? 0 : Number(answer) - 1;
|
|
4127
4248
|
const chosen = items[index];
|
|
4128
4249
|
if (!Number.isInteger(index) || index < 0 || chosen === void 0) {
|
|
4129
4250
|
throw new Error(`Pick a number between 1 and ${items.length}.`);
|
|
@@ -4257,36 +4378,6 @@ function makeClient(deps) {
|
|
|
4257
4378
|
};
|
|
4258
4379
|
}
|
|
4259
4380
|
|
|
4260
|
-
// src/output/colors.ts
|
|
4261
|
-
var IDENTITY_COLORS = {
|
|
4262
|
-
dim: (text) => text,
|
|
4263
|
-
bold: (text) => text,
|
|
4264
|
-
cyan: (text) => text,
|
|
4265
|
-
green: (text) => text,
|
|
4266
|
-
yellow: (text) => text,
|
|
4267
|
-
red: (text) => text,
|
|
4268
|
-
magenta: (text) => text
|
|
4269
|
-
};
|
|
4270
|
-
function wrap(code) {
|
|
4271
|
-
return (text) => `\x1B[${code}m${text}\x1B[0m`;
|
|
4272
|
-
}
|
|
4273
|
-
var ANSI_COLORS = {
|
|
4274
|
-
dim: wrap("2"),
|
|
4275
|
-
bold: wrap("1"),
|
|
4276
|
-
cyan: wrap("36"),
|
|
4277
|
-
green: wrap("32"),
|
|
4278
|
-
yellow: wrap("33"),
|
|
4279
|
-
red: wrap("31"),
|
|
4280
|
-
magenta: wrap("35")
|
|
4281
|
-
};
|
|
4282
|
-
function pickColors(options) {
|
|
4283
|
-
const stream = options.stream ?? process.stdout;
|
|
4284
|
-
if (options.noColor || process.env["NO_COLOR"] !== void 0 || !stream.isTTY) {
|
|
4285
|
-
return IDENTITY_COLORS;
|
|
4286
|
-
}
|
|
4287
|
-
return ANSI_COLORS;
|
|
4288
|
-
}
|
|
4289
|
-
|
|
4290
4381
|
// ../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/external.js
|
|
4291
4382
|
var external_exports = {};
|
|
4292
4383
|
__export(external_exports, {
|
|
@@ -5711,14 +5802,14 @@ function toDotPath(_path) {
|
|
|
5711
5802
|
return segs.join("");
|
|
5712
5803
|
}
|
|
5713
5804
|
function prettifyError(error51) {
|
|
5714
|
-
const
|
|
5805
|
+
const lines3 = [];
|
|
5715
5806
|
const issues = [...error51.issues].sort((a, b) => (a.path ?? []).length - (b.path ?? []).length);
|
|
5716
5807
|
for (const issue2 of issues) {
|
|
5717
|
-
|
|
5808
|
+
lines3.push(`\u2716 ${issue2.message}`);
|
|
5718
5809
|
if (issue2.path?.length)
|
|
5719
|
-
|
|
5810
|
+
lines3.push(` \u2192 at ${toDotPath(issue2.path)}`);
|
|
5720
5811
|
}
|
|
5721
|
-
return
|
|
5812
|
+
return lines3.join("\n");
|
|
5722
5813
|
}
|
|
5723
5814
|
|
|
5724
5815
|
// ../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/parse.js
|
|
@@ -6536,9 +6627,9 @@ var Doc = class {
|
|
|
6536
6627
|
return;
|
|
6537
6628
|
}
|
|
6538
6629
|
const content = arg;
|
|
6539
|
-
const
|
|
6540
|
-
const minIndent = Math.min(...
|
|
6541
|
-
const dedented =
|
|
6630
|
+
const lines3 = content.split("\n").filter((x) => x);
|
|
6631
|
+
const minIndent = Math.min(...lines3.map((x) => x.length - x.trimStart().length));
|
|
6632
|
+
const dedented = lines3.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
|
|
6542
6633
|
for (const line of dedented) {
|
|
6543
6634
|
this.content.push(line);
|
|
6544
6635
|
}
|
|
@@ -6547,8 +6638,8 @@ var Doc = class {
|
|
|
6547
6638
|
const F = Function;
|
|
6548
6639
|
const args = this?.args;
|
|
6549
6640
|
const content = this?.content ?? [``];
|
|
6550
|
-
const
|
|
6551
|
-
return new F(...args,
|
|
6641
|
+
const lines3 = [...content.map((x) => ` ${x}`)];
|
|
6642
|
+
return new F(...args, lines3.join("\n"));
|
|
6552
6643
|
}
|
|
6553
6644
|
};
|
|
6554
6645
|
|