norc-cli 0.1.8 → 0.1.9
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 +11 -2
- package/dist/index.js +95 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ norc login
|
|
|
35
35
|
NORC_API_KEY=norc_sk_... norc login
|
|
36
36
|
|
|
37
37
|
# Interactive — needs your inbox
|
|
38
|
-
norc login you@example.com # one-time-code email login
|
|
38
|
+
norc login --email you@example.com # one-time-code email login
|
|
39
39
|
norc pair # link this machine to your account
|
|
40
40
|
```
|
|
41
41
|
|
|
@@ -49,7 +49,7 @@ to anyone inspecting the process list.
|
|
|
49
49
|
## Usage
|
|
50
50
|
|
|
51
51
|
```text
|
|
52
|
-
norc login
|
|
52
|
+
norc login --email <email> start email one-time-code login (prompts for an API key first if no email given; empty falls back to email)
|
|
53
53
|
norc login --key <api-key> log in + pair headlessly with a norc API key (vault → Settings → API Keys) — no email/browser
|
|
54
54
|
norc pair pair this machine with your norc account (after norc login)
|
|
55
55
|
norc jobs list list jobs in this machine's crontab
|
|
@@ -63,6 +63,15 @@ norc service install register+start the per-user background service
|
|
|
63
63
|
norc service uninstall stop+remove the per-user background service
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
+
Add `--debug` (or set `NORC_DEBUG=1`) to any command for step-by-step tracing — which backend URLs/config paths are in play, and full request/response detail for every network call (secrets shown as a redacted prefix only, e.g. `norc_sk_test1234…(28 chars)`):
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
norc login --key norc_sk_... --debug
|
|
70
|
+
NORC_DEBUG=1 norc login
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Useful for anything that fails with a generic message like `pairing failed (500)` — `--debug` shows the raw server response instead.
|
|
74
|
+
|
|
66
75
|
## Background service
|
|
67
76
|
|
|
68
77
|
`norc service install` registers a per-user background service (LaunchAgent on macOS) that runs the bridge daemon automatically. Uninstall it before removing the CLI:
|
package/dist/index.js
CHANGED
|
@@ -21303,8 +21303,8 @@ var PostgrestBuilder = class {
|
|
|
21303
21303
|
* .retry(false)
|
|
21304
21304
|
* ```
|
|
21305
21305
|
*/
|
|
21306
|
-
retry(
|
|
21307
|
-
this.retryEnabled =
|
|
21306
|
+
retry(enabled2) {
|
|
21307
|
+
this.retryEnabled = enabled2;
|
|
21308
21308
|
return this;
|
|
21309
21309
|
}
|
|
21310
21310
|
then(onfulfilled, onrejected) {
|
|
@@ -30111,19 +30111,51 @@ var DEFAULT_VAULT_URL = "https://vault.norc.app";
|
|
|
30111
30111
|
var import_promises = require("node:fs/promises");
|
|
30112
30112
|
var import_node_os = require("node:os");
|
|
30113
30113
|
var import_node_path = require("node:path");
|
|
30114
|
+
|
|
30115
|
+
// src/debug.ts
|
|
30116
|
+
var enabled = false;
|
|
30117
|
+
function setDebugEnabled(value) {
|
|
30118
|
+
enabled = value;
|
|
30119
|
+
}
|
|
30120
|
+
function isDebugEnabled() {
|
|
30121
|
+
return enabled;
|
|
30122
|
+
}
|
|
30123
|
+
function debugLog(...args) {
|
|
30124
|
+
if (!enabled) return;
|
|
30125
|
+
console.error("[debug]", ...args);
|
|
30126
|
+
}
|
|
30127
|
+
function redactSecret(value) {
|
|
30128
|
+
if (!value) return "(none)";
|
|
30129
|
+
if (value.length <= 12) return "***";
|
|
30130
|
+
return `${value.slice(0, 12)}\u2026(${value.length} chars)`;
|
|
30131
|
+
}
|
|
30132
|
+
function redactArgs(args) {
|
|
30133
|
+
return args.map((arg, i) => {
|
|
30134
|
+
const flag = args[i - 1];
|
|
30135
|
+
if (flag === "--key") return redactSecret(arg);
|
|
30136
|
+
if (flag === "--email") return "[redacted email]";
|
|
30137
|
+
return arg;
|
|
30138
|
+
});
|
|
30139
|
+
}
|
|
30140
|
+
|
|
30141
|
+
// src/config.ts
|
|
30114
30142
|
function configPath() {
|
|
30115
30143
|
return (0, import_node_path.join)((0, import_node_os.homedir)(), ".config", "norc", "config.json");
|
|
30116
30144
|
}
|
|
30117
30145
|
async function loadConfig(path = configPath()) {
|
|
30118
30146
|
try {
|
|
30119
|
-
|
|
30120
|
-
|
|
30147
|
+
const config = JSON.parse(await (0, import_promises.readFile)(path, "utf8"));
|
|
30148
|
+
debugLog("config: loaded", path, "\u2014 has session:", Boolean(config.session), "has device:", Boolean(config.device));
|
|
30149
|
+
return config;
|
|
30150
|
+
} catch (e) {
|
|
30151
|
+
debugLog("config: no existing config at", path, "(", e instanceof Error ? e.message : String(e), ") \u2014 starting empty");
|
|
30121
30152
|
return {};
|
|
30122
30153
|
}
|
|
30123
30154
|
}
|
|
30124
30155
|
async function saveConfig(config, path = configPath()) {
|
|
30125
30156
|
await (0, import_promises.mkdir)((0, import_node_path.join)(path, ".."), { recursive: true, mode: 448 });
|
|
30126
30157
|
await (0, import_promises.writeFile)(path, JSON.stringify(config, null, 2), { mode: 384 });
|
|
30158
|
+
debugLog("config: saved", path, "\u2014 has session:", Boolean(config.session), "has device:", Boolean(config.device));
|
|
30127
30159
|
}
|
|
30128
30160
|
|
|
30129
30161
|
// src/crontab-io.ts
|
|
@@ -30596,12 +30628,22 @@ async function runPairing(client, onProgress, opts = {}) {
|
|
|
30596
30628
|
|
|
30597
30629
|
// src/commands/pair-key.ts
|
|
30598
30630
|
async function pairWithApiKey(fetchImpl, vaultUrl, apiKey, hostname2) {
|
|
30599
|
-
const
|
|
30631
|
+
const url = `${vaultUrl}/api/v1/machines`;
|
|
30632
|
+
debugLog("POST", url, { authorization: `Bearer ${redactSecret(apiKey)}`, hostname: hostname2 });
|
|
30633
|
+
const res = await fetchImpl(url, {
|
|
30600
30634
|
method: "POST",
|
|
30601
30635
|
headers: { authorization: `Bearer ${apiKey}`, "content-type": "application/json" },
|
|
30602
30636
|
body: JSON.stringify({ hostname: hostname2 })
|
|
30603
30637
|
});
|
|
30604
|
-
const
|
|
30638
|
+
const rawText = await res.text().catch(() => "");
|
|
30639
|
+
let body;
|
|
30640
|
+
try {
|
|
30641
|
+
body = JSON.parse(rawText);
|
|
30642
|
+
} catch {
|
|
30643
|
+
body = {};
|
|
30644
|
+
}
|
|
30645
|
+
const loggedBody = body.device_token ? { ...body, device_token: redactSecret(body.device_token) } : rawText.slice(0, 2e3);
|
|
30646
|
+
debugLog("response status:", res.status, "body:", loggedBody);
|
|
30605
30647
|
if (!res.ok) return { ok: false, message: body.error ?? `pairing failed (${res.status})` };
|
|
30606
30648
|
if (!body.machine_id || !body.device_token) return { ok: false, message: "malformed response from vault API" };
|
|
30607
30649
|
return { ok: true, machineId: body.machine_id, deviceToken: body.device_token };
|
|
@@ -30610,14 +30652,29 @@ async function pairWithApiKey(fetchImpl, vaultUrl, apiKey, hostname2) {
|
|
|
30610
30652
|
// src/prompt-secret.ts
|
|
30611
30653
|
var BACKSPACE = String.fromCharCode(127);
|
|
30612
30654
|
var CTRL_C = String.fromCharCode(3);
|
|
30655
|
+
var PASTE_START = "\x1B[200~";
|
|
30656
|
+
var PASTE_END = "\x1B[201~";
|
|
30657
|
+
var MAX_MARKER_LEN = Math.max(PASTE_START.length, PASTE_END.length);
|
|
30658
|
+
function stripPasteMarkers(text) {
|
|
30659
|
+
const stripped = text.split(PASTE_START).join("").split(PASTE_END).join("");
|
|
30660
|
+
for (let len = Math.min(MAX_MARKER_LEN - 1, stripped.length); len > 0; len--) {
|
|
30661
|
+
const suffix = stripped.slice(-len);
|
|
30662
|
+
if (PASTE_START.startsWith(suffix) || PASTE_END.startsWith(suffix)) {
|
|
30663
|
+
return { ready: stripped.slice(0, -len), pending: suffix };
|
|
30664
|
+
}
|
|
30665
|
+
}
|
|
30666
|
+
return { ready: stripped, pending: "" };
|
|
30667
|
+
}
|
|
30613
30668
|
function promptSecret(question, { stdin, stdout } = { stdin: process.stdin, stdout: process.stdout }) {
|
|
30614
30669
|
stdout.write(question);
|
|
30615
30670
|
const isTTY = Boolean(stdin.isTTY) && typeof stdin.setRawMode === "function";
|
|
30616
30671
|
return new Promise((resolve, reject) => {
|
|
30617
30672
|
let input = "";
|
|
30673
|
+
let carry = "";
|
|
30618
30674
|
const onData = (chunk) => {
|
|
30619
|
-
const
|
|
30620
|
-
|
|
30675
|
+
const { ready, pending } = stripPasteMarkers(carry + chunk.toString());
|
|
30676
|
+
carry = pending;
|
|
30677
|
+
for (const char of ready) {
|
|
30621
30678
|
if (char === "\n" || char === "\r") {
|
|
30622
30679
|
if (isTTY) stdout.write("\n");
|
|
30623
30680
|
cleanup();
|
|
@@ -30644,7 +30701,7 @@ function promptSecret(question, { stdin, stdout } = { stdin: process.stdin, stdo
|
|
|
30644
30701
|
}
|
|
30645
30702
|
const onEnd = () => {
|
|
30646
30703
|
cleanup();
|
|
30647
|
-
resolve(input.trim());
|
|
30704
|
+
resolve((input + carry).trim());
|
|
30648
30705
|
};
|
|
30649
30706
|
if (isTTY) stdin.setRawMode(true);
|
|
30650
30707
|
stdin.resume();
|
|
@@ -30690,8 +30747,8 @@ async function withJob(io, id, fn) {
|
|
|
30690
30747
|
function removeJob(io, id) {
|
|
30691
30748
|
return withJob(io, id, () => null);
|
|
30692
30749
|
}
|
|
30693
|
-
function setEnabled(io, id,
|
|
30694
|
-
return withJob(io, id, (e) => ({ ...e, enabled }));
|
|
30750
|
+
function setEnabled(io, id, enabled2) {
|
|
30751
|
+
return withJob(io, id, (e) => ({ ...e, enabled: enabled2 }));
|
|
30695
30752
|
}
|
|
30696
30753
|
|
|
30697
30754
|
// src/commands/runs.ts
|
|
@@ -31066,11 +31123,11 @@ async function uninstallService(deps = defaultServiceDeps(process.execPath)) {
|
|
|
31066
31123
|
}
|
|
31067
31124
|
|
|
31068
31125
|
// src/index.ts
|
|
31069
|
-
var VERSION = "0.1.
|
|
31126
|
+
var VERSION = "0.1.9";
|
|
31070
31127
|
var HELP = `norc \u2014 headless job scheduler CLI
|
|
31071
31128
|
|
|
31072
31129
|
Usage:
|
|
31073
|
-
norc login
|
|
31130
|
+
norc login --email <email> start email one-time-code login (prompts for an API key first if no email given; empty falls back to email)
|
|
31074
31131
|
norc login --key <api-key> log in + pair headlessly with a norc API key (vault \u2192 Settings \u2192 API Keys) \u2014 no email/browser
|
|
31075
31132
|
norc pair pair this machine with your norc account (after norc login)
|
|
31076
31133
|
norc jobs list list jobs in this machine's crontab
|
|
@@ -31082,6 +31139,10 @@ Usage:
|
|
|
31082
31139
|
norc bridge run the bridge daemon (stay online, admin from norc web)
|
|
31083
31140
|
norc service install register+start the per-user background service
|
|
31084
31141
|
norc service uninstall stop+remove the per-user background service
|
|
31142
|
+
|
|
31143
|
+
Add --debug (or set NORC_DEBUG=1) to any command for step-by-step tracing \u2014
|
|
31144
|
+
which backend URLs/config paths are in play, and full request/response
|
|
31145
|
+
detail for every network call (secrets shown as a redacted prefix only).
|
|
31085
31146
|
`;
|
|
31086
31147
|
function supabase() {
|
|
31087
31148
|
const url = process.env.NORC_SUPABASE_URL ?? DEFAULT_SUPABASE_URL;
|
|
@@ -31098,14 +31159,20 @@ async function prompt(question) {
|
|
|
31098
31159
|
}
|
|
31099
31160
|
async function cmdLogin(args) {
|
|
31100
31161
|
const keyFlagIndex = args.indexOf("--key");
|
|
31162
|
+
const emailFlagIndex = args.indexOf("--email");
|
|
31101
31163
|
const vaultUrl = process.env.NORC_VAULT_URL ?? DEFAULT_VAULT_URL;
|
|
31102
31164
|
let apiKey = keyFlagIndex !== -1 ? args[keyFlagIndex + 1] : process.env.NORC_API_KEY;
|
|
31103
|
-
const positionalEmail =
|
|
31165
|
+
const positionalEmail = emailFlagIndex !== -1 ? args[emailFlagIndex + 1] : void 0;
|
|
31166
|
+
debugLog("login: --key present:", keyFlagIndex !== -1, "NORC_API_KEY set:", Boolean(process.env.NORC_API_KEY), "--email:", positionalEmail ?? "(none)");
|
|
31104
31167
|
if (!apiKey && !positionalEmail) {
|
|
31168
|
+
debugLog("login: no --key/--email/NORC_API_KEY given, prompting for API key");
|
|
31105
31169
|
apiKey = await promptSecret(`API key (create one at ${vaultUrl}/settings/api-keys \u2014 press enter to use email instead): `);
|
|
31170
|
+
debugLog("login: prompt returned key:", redactSecret(apiKey));
|
|
31106
31171
|
}
|
|
31107
31172
|
if (apiKey) {
|
|
31173
|
+
debugLog("login: using API-key path, POST", `${vaultUrl}/api/v1/machines`, "key:", redactSecret(apiKey));
|
|
31108
31174
|
const result2 = await pairWithApiKey(fetch, vaultUrl, apiKey, (0, import_node_os4.hostname)());
|
|
31175
|
+
debugLog("login: pairWithApiKey result:", result2.ok ? { ok: true, machineId: result2.machineId, deviceToken: redactSecret(result2.deviceToken) } : result2);
|
|
31109
31176
|
if (!result2.ok) throw new Error(result2.message);
|
|
31110
31177
|
const config2 = await loadConfig();
|
|
31111
31178
|
config2.device = { machineId: result2.machineId, deviceToken: result2.deviceToken };
|
|
@@ -31113,15 +31180,18 @@ async function cmdLogin(args) {
|
|
|
31113
31180
|
console.log(`logged in. machine id: ${result2.machineId}`);
|
|
31114
31181
|
return;
|
|
31115
31182
|
}
|
|
31183
|
+
debugLog("login: falling through to email OTP path \u2014 no API key ended up set");
|
|
31116
31184
|
let email = positionalEmail;
|
|
31117
31185
|
if (!email) email = await prompt("email: ");
|
|
31118
|
-
if (!email) throw new Error("usage: norc login <email>");
|
|
31186
|
+
if (!email) throw new Error("usage: norc login --email <email>");
|
|
31119
31187
|
const client = supabase();
|
|
31120
31188
|
const started = await requestLogin(client, email);
|
|
31189
|
+
debugLog("login: requestLogin result:", started);
|
|
31121
31190
|
if (!started.ok) throw new Error(started.message);
|
|
31122
31191
|
console.log(`code sent to ${email}`);
|
|
31123
31192
|
const code = await prompt("enter the code from your email: ");
|
|
31124
31193
|
const result = await verifyLogin(client, email, code);
|
|
31194
|
+
debugLog("login: verifyLogin result:", result.ok ? { ok: true } : result);
|
|
31125
31195
|
if (!result.ok) throw new Error(result.message);
|
|
31126
31196
|
const config = await loadConfig();
|
|
31127
31197
|
config.session = { email, accessToken: result.accessToken, refreshToken: result.refreshToken };
|
|
@@ -31192,7 +31262,15 @@ async function cmdBridge() {
|
|
|
31192
31262
|
await runBridge({ supabaseUrl: url, anonKey }, systemCrontabIo);
|
|
31193
31263
|
}
|
|
31194
31264
|
async function main() {
|
|
31195
|
-
const
|
|
31265
|
+
const rawArgs = process.argv.slice(2);
|
|
31266
|
+
const debugFlagIndex = rawArgs.indexOf("--debug");
|
|
31267
|
+
const debug = debugFlagIndex !== -1 || process.env.NORC_DEBUG === "1";
|
|
31268
|
+
setDebugEnabled(debug);
|
|
31269
|
+
const argv = debugFlagIndex !== -1 ? [...rawArgs.slice(0, debugFlagIndex), ...rawArgs.slice(debugFlagIndex + 1)] : rawArgs;
|
|
31270
|
+
const [cmd, ...args] = argv;
|
|
31271
|
+
debugLog("command:", cmd || "(none)", "args:", redactArgs(args));
|
|
31272
|
+
debugLog("vault url:", process.env.NORC_VAULT_URL ?? DEFAULT_VAULT_URL, process.env.NORC_VAULT_URL ? "(NORC_VAULT_URL override)" : "(default)");
|
|
31273
|
+
debugLog("supabase url:", process.env.NORC_SUPABASE_URL ?? DEFAULT_SUPABASE_URL, process.env.NORC_SUPABASE_URL ? "(NORC_SUPABASE_URL override)" : "(default)");
|
|
31196
31274
|
if (!cmd || cmd === "--help" || cmd === "-h") {
|
|
31197
31275
|
console.log(HELP);
|
|
31198
31276
|
return;
|
|
@@ -31241,5 +31319,6 @@ async function main() {
|
|
|
31241
31319
|
}
|
|
31242
31320
|
main().catch((e) => {
|
|
31243
31321
|
console.error(`error: ${e instanceof Error ? e.message : String(e)}`);
|
|
31322
|
+
if (isDebugEnabled() && e instanceof Error && e.stack) console.error(e.stack);
|
|
31244
31323
|
process.exitCode = 1;
|
|
31245
31324
|
});
|