norc-cli 0.1.2 → 0.1.7
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 +22 -3
- package/dist/index.js +88 -7
- package/package.json +9 -8
package/README.md
CHANGED
|
@@ -21,18 +21,37 @@ Requires Node.js >= 18.
|
|
|
21
21
|
## Setup
|
|
22
22
|
|
|
23
23
|
`norc login` / `norc pair` / `norc bridge` talk to the norc.app project by
|
|
24
|
-
default — nothing to configure.
|
|
24
|
+
default — nothing to configure. Two ways to connect this machine:
|
|
25
25
|
|
|
26
26
|
```sh
|
|
27
|
+
# Headless — one command, no email round trip. Generate a key at
|
|
28
|
+
# vault → Settings → API Keys, same key norc-mcp uses. Bare `norc login`
|
|
29
|
+
# prompts for it (input isn't echoed), so nothing sensitive ends up in
|
|
30
|
+
# shell history or a process listing.
|
|
31
|
+
norc login
|
|
32
|
+
|
|
33
|
+
# CI/non-interactive: pass the key via env, not a command argument
|
|
34
|
+
# (a --key value would show up in shell history and `ps`).
|
|
35
|
+
NORC_API_KEY=norc_sk_... norc login
|
|
36
|
+
|
|
37
|
+
# Interactive — needs your inbox
|
|
27
38
|
norc login you@example.com # one-time-code email login
|
|
28
39
|
norc pair # link this machine to your account
|
|
29
40
|
```
|
|
30
41
|
|
|
42
|
+
The headless path is the one to use on servers/CI/Raspberry Pis — no
|
|
43
|
+
inbox access needed, and it registers the machine in one step. `--key
|
|
44
|
+
<api-key>` also works if you must pass it inline (e.g. a script that
|
|
45
|
+
already has the key in an env var it controls), but prefer the prompt
|
|
46
|
+
or `NORC_API_KEY` — an inline argument is visible in shell history and
|
|
47
|
+
to anyone inspecting the process list.
|
|
48
|
+
|
|
31
49
|
## Usage
|
|
32
50
|
|
|
33
51
|
```text
|
|
34
|
-
norc login
|
|
35
|
-
norc pair
|
|
52
|
+
norc login [email] start email one-time-code login (prompts for an API key first if no email given; empty falls back to email)
|
|
53
|
+
norc login --key <api-key> log in + pair headlessly with a norc API key (vault → Settings → API Keys) — no email/browser
|
|
54
|
+
norc pair pair this machine with your norc account (after norc login)
|
|
36
55
|
norc jobs list list jobs in this machine's crontab
|
|
37
56
|
norc jobs add <schedule> <cmd> add a job (schedule in 5-field cron syntax)
|
|
38
57
|
norc jobs rm <id> remove a job by id
|
package/dist/index.js
CHANGED
|
@@ -21071,6 +21071,7 @@ var require_parser = __commonJS({
|
|
|
21071
21071
|
|
|
21072
21072
|
// src/index.ts
|
|
21073
21073
|
var import_promises4 = require("node:readline/promises");
|
|
21074
|
+
var import_node_os4 = require("node:os");
|
|
21074
21075
|
|
|
21075
21076
|
// ../../node_modules/.pnpm/@supabase+supabase-js@2.108.2/node_modules/@supabase/supabase-js/dist/index.mjs
|
|
21076
21077
|
var dist_exports = {};
|
|
@@ -30104,6 +30105,7 @@ if (shouldShowDeprecationWarning()) console.warn("\u26A0\uFE0F Node.js 18 and b
|
|
|
30104
30105
|
// src/supabase-config.ts
|
|
30105
30106
|
var DEFAULT_SUPABASE_URL = "https://eiuegfdaddrisfboijyy.supabase.co";
|
|
30106
30107
|
var DEFAULT_SUPABASE_ANON_KEY = "sb_publishable_qGCC0eLvfmXwL86zA1SLHA_q8rFMCcG";
|
|
30108
|
+
var DEFAULT_VAULT_URL = "https://vault.norc.app";
|
|
30107
30109
|
|
|
30108
30110
|
// src/config.ts
|
|
30109
30111
|
var import_promises = require("node:fs/promises");
|
|
@@ -30152,7 +30154,7 @@ var systemCrontabIo = {
|
|
|
30152
30154
|
|
|
30153
30155
|
// src/commands/login.ts
|
|
30154
30156
|
async function requestLogin(client, email) {
|
|
30155
|
-
const start = await client.auth.signInWithOtp({ email });
|
|
30157
|
+
const start = await client.auth.signInWithOtp({ email, options: { shouldCreateUser: false } });
|
|
30156
30158
|
if (start.error) return { ok: false, message: start.error.message };
|
|
30157
30159
|
return { ok: true };
|
|
30158
30160
|
}
|
|
@@ -30592,6 +30594,66 @@ async function runPairing(client, onProgress, opts = {}) {
|
|
|
30592
30594
|
onProgress({ phase: "expired" });
|
|
30593
30595
|
}
|
|
30594
30596
|
|
|
30597
|
+
// src/commands/pair-key.ts
|
|
30598
|
+
async function pairWithApiKey(fetchImpl, vaultUrl, apiKey, hostname2) {
|
|
30599
|
+
const res = await fetchImpl(`${vaultUrl}/api/v1/machines`, {
|
|
30600
|
+
method: "POST",
|
|
30601
|
+
headers: { authorization: `Bearer ${apiKey}`, "content-type": "application/json" },
|
|
30602
|
+
body: JSON.stringify({ hostname: hostname2 })
|
|
30603
|
+
});
|
|
30604
|
+
const body = await res.json().catch(() => ({}));
|
|
30605
|
+
if (!res.ok) return { ok: false, message: body.error ?? `pairing failed (${res.status})` };
|
|
30606
|
+
if (!body.machine_id || !body.device_token) return { ok: false, message: "malformed response from vault API" };
|
|
30607
|
+
return { ok: true, machineId: body.machine_id, deviceToken: body.device_token };
|
|
30608
|
+
}
|
|
30609
|
+
|
|
30610
|
+
// src/prompt-secret.ts
|
|
30611
|
+
var BACKSPACE = String.fromCharCode(127);
|
|
30612
|
+
var CTRL_C = String.fromCharCode(3);
|
|
30613
|
+
function promptSecret(question, { stdin, stdout } = { stdin: process.stdin, stdout: process.stdout }) {
|
|
30614
|
+
stdout.write(question);
|
|
30615
|
+
const isTTY = Boolean(stdin.isTTY) && typeof stdin.setRawMode === "function";
|
|
30616
|
+
return new Promise((resolve, reject) => {
|
|
30617
|
+
let input = "";
|
|
30618
|
+
const onData = (chunk) => {
|
|
30619
|
+
const str = chunk.toString();
|
|
30620
|
+
for (const char of str) {
|
|
30621
|
+
if (char === "\n" || char === "\r") {
|
|
30622
|
+
if (isTTY) stdout.write("\n");
|
|
30623
|
+
cleanup();
|
|
30624
|
+
resolve(input.trim());
|
|
30625
|
+
return;
|
|
30626
|
+
}
|
|
30627
|
+
if (char === CTRL_C) {
|
|
30628
|
+
cleanup();
|
|
30629
|
+
reject(new Error("aborted"));
|
|
30630
|
+
return;
|
|
30631
|
+
}
|
|
30632
|
+
if (isTTY && (char === BACKSPACE || char === "\b")) {
|
|
30633
|
+
input = input.slice(0, -1);
|
|
30634
|
+
continue;
|
|
30635
|
+
}
|
|
30636
|
+
input += char;
|
|
30637
|
+
}
|
|
30638
|
+
};
|
|
30639
|
+
function cleanup() {
|
|
30640
|
+
stdin.removeListener("data", onData);
|
|
30641
|
+
stdin.removeListener("end", onEnd);
|
|
30642
|
+
if (isTTY) stdin.setRawMode(false);
|
|
30643
|
+
stdin.pause?.();
|
|
30644
|
+
}
|
|
30645
|
+
const onEnd = () => {
|
|
30646
|
+
cleanup();
|
|
30647
|
+
resolve(input.trim());
|
|
30648
|
+
};
|
|
30649
|
+
if (isTTY) stdin.setRawMode(true);
|
|
30650
|
+
stdin.resume();
|
|
30651
|
+
stdin.setEncoding?.("utf8");
|
|
30652
|
+
stdin.on("data", onData);
|
|
30653
|
+
stdin.once?.("end", onEnd);
|
|
30654
|
+
});
|
|
30655
|
+
}
|
|
30656
|
+
|
|
30595
30657
|
// src/commands/jobs.ts
|
|
30596
30658
|
var import_node_crypto = require("node:crypto");
|
|
30597
30659
|
var CONTROL2 = /[\r\n\0]/;
|
|
@@ -31004,12 +31066,13 @@ async function uninstallService(deps = defaultServiceDeps(process.execPath)) {
|
|
|
31004
31066
|
}
|
|
31005
31067
|
|
|
31006
31068
|
// src/index.ts
|
|
31007
|
-
var VERSION = "0.1.
|
|
31069
|
+
var VERSION = "0.1.7";
|
|
31008
31070
|
var HELP = `norc \u2014 headless job scheduler CLI
|
|
31009
31071
|
|
|
31010
31072
|
Usage:
|
|
31011
|
-
norc login
|
|
31012
|
-
norc pair
|
|
31073
|
+
norc login [email] start email one-time-code login (prompts for an API key first if no email given; empty falls back to email)
|
|
31074
|
+
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
|
+
norc pair pair this machine with your norc account (after norc login)
|
|
31013
31076
|
norc jobs list list jobs in this machine's crontab
|
|
31014
31077
|
norc jobs add <schedule> <cmd> add a job (schedule in 5-field cron syntax)
|
|
31015
31078
|
norc jobs rm <id> remove a job by id
|
|
@@ -31033,7 +31096,25 @@ async function prompt(question) {
|
|
|
31033
31096
|
rl.close();
|
|
31034
31097
|
}
|
|
31035
31098
|
}
|
|
31036
|
-
async function cmdLogin(
|
|
31099
|
+
async function cmdLogin(args) {
|
|
31100
|
+
const keyFlagIndex = args.indexOf("--key");
|
|
31101
|
+
const vaultUrl = process.env.NORC_VAULT_URL ?? DEFAULT_VAULT_URL;
|
|
31102
|
+
let apiKey = keyFlagIndex !== -1 ? args[keyFlagIndex + 1] : process.env.NORC_API_KEY;
|
|
31103
|
+
const positionalEmail = args[0] && !args[0].startsWith("--") ? args[0] : void 0;
|
|
31104
|
+
if (!apiKey && !positionalEmail) {
|
|
31105
|
+
apiKey = await promptSecret(`API key (create one at ${vaultUrl}/settings/api-keys \u2014 press enter to use email instead): `);
|
|
31106
|
+
}
|
|
31107
|
+
if (apiKey) {
|
|
31108
|
+
const result2 = await pairWithApiKey(fetch, vaultUrl, apiKey, (0, import_node_os4.hostname)());
|
|
31109
|
+
if (!result2.ok) throw new Error(result2.message);
|
|
31110
|
+
const config2 = await loadConfig();
|
|
31111
|
+
config2.device = { machineId: result2.machineId, deviceToken: result2.deviceToken };
|
|
31112
|
+
await saveConfig(config2);
|
|
31113
|
+
console.log(`logged in. machine id: ${result2.machineId}`);
|
|
31114
|
+
return;
|
|
31115
|
+
}
|
|
31116
|
+
let email = positionalEmail;
|
|
31117
|
+
if (!email) email = await prompt("email: ");
|
|
31037
31118
|
if (!email) throw new Error("usage: norc login <email>");
|
|
31038
31119
|
const client = supabase();
|
|
31039
31120
|
const started = await requestLogin(client, email);
|
|
@@ -31045,7 +31126,7 @@ async function cmdLogin(email) {
|
|
|
31045
31126
|
const config = await loadConfig();
|
|
31046
31127
|
config.session = { email, accessToken: result.accessToken, refreshToken: result.refreshToken };
|
|
31047
31128
|
await saveConfig(config);
|
|
31048
|
-
console.log("logged in.");
|
|
31129
|
+
console.log("logged in. run `norc pair` next to register this machine.");
|
|
31049
31130
|
}
|
|
31050
31131
|
async function cmdPair() {
|
|
31051
31132
|
const client = supabase();
|
|
@@ -31122,7 +31203,7 @@ async function main() {
|
|
|
31122
31203
|
}
|
|
31123
31204
|
switch (cmd) {
|
|
31124
31205
|
case "login":
|
|
31125
|
-
return cmdLogin(args
|
|
31206
|
+
return cmdLogin(args);
|
|
31126
31207
|
case "pair":
|
|
31127
31208
|
return cmdPair();
|
|
31128
31209
|
case "jobs":
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "norc-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Headless cron job scheduler for norc — manage crontab, pair machines, run the bridge daemon.",
|
|
5
5
|
"homepage": "https://norc.app/cli",
|
|
6
6
|
"repository": {
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"norc": "dist/index.js"
|
|
26
26
|
},
|
|
27
27
|
"engines": {
|
|
28
|
-
"node": ">=
|
|
28
|
+
"node": ">=24"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"typecheck": "tsc --noEmit",
|
|
32
32
|
"test": "vitest run",
|
|
33
|
-
"build": "esbuild src/index.ts --bundle --platform=node --format=cjs --target=
|
|
33
|
+
"build": "esbuild src/index.ts --bundle --platform=node --format=cjs --target=node24 --banner:js=\"#!/usr/bin/env node\" --outfile=dist/index.js",
|
|
34
34
|
"build:binary": "bash scripts/build-binary.sh",
|
|
35
35
|
"prepublishOnly": "pnpm run build"
|
|
36
36
|
},
|
|
@@ -41,17 +41,18 @@
|
|
|
41
41
|
"@norc/types": "workspace:*",
|
|
42
42
|
"@supabase/supabase-js": "^2.47.0",
|
|
43
43
|
"@types/node": "^22.0.0",
|
|
44
|
-
"@yao-pkg/pkg": "^
|
|
44
|
+
"@yao-pkg/pkg": "^6.22.0",
|
|
45
45
|
"esbuild": "^0.23.0",
|
|
46
46
|
"typescript": "^5.5.0",
|
|
47
47
|
"vitest": "^2.0.0"
|
|
48
48
|
},
|
|
49
49
|
"pkg": {
|
|
50
50
|
"targets": [
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
51
|
+
"node24-linux-x64",
|
|
52
|
+
"node24-linux-arm64",
|
|
53
|
+
"node24-macos-x64",
|
|
54
|
+
"node24-macos-arm64",
|
|
55
|
+
"node24-win-x64"
|
|
55
56
|
],
|
|
56
57
|
"outputPath": "dist-bin"
|
|
57
58
|
}
|