@openluxeco/cli 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/LICENSE +21 -0
- package/README.md +83 -0
- package/bin/openluxe.js +14 -0
- package/package.json +42 -0
- package/src/api.js +67 -0
- package/src/auth.js +92 -0
- package/src/cli.js +164 -0
- package/src/config.js +37 -0
- package/src/resources.js +181 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 OpenLuxe
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# OpenLuxe CLI
|
|
2
|
+
|
|
3
|
+
The official command-line client for the OpenLuxe v1 API. Built for humans
|
|
4
|
+
and for terminal AI agents (Claude Code, etc.) — sign in once with your
|
|
5
|
+
OpenLuxe web account, then drive the whole API from the shell.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g @openluxeco/cli
|
|
11
|
+
# or run without installing:
|
|
12
|
+
npx @openluxeco/cli help
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Requires Node.js 18+.
|
|
16
|
+
|
|
17
|
+
## Sign in
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
openluxe auth login
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
This uses the OAuth 2.0 device flow — exactly like signing in to other
|
|
24
|
+
modern CLIs:
|
|
25
|
+
|
|
26
|
+
1. The CLI prints a short code and opens your browser.
|
|
27
|
+
2. You sign in to openluxe.co (if not already) and approve the device.
|
|
28
|
+
3. The CLI receives a personal access token and stores it at
|
|
29
|
+
`~/.openluxe/credentials.json` (chmod 600).
|
|
30
|
+
|
|
31
|
+
It works headless / over SSH too — the URL + code are printed, so you can
|
|
32
|
+
open them on any device.
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
openluxe auth status # who am I?
|
|
36
|
+
openluxe auth logout # forget the local token
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Revoke a CLI token anytime from **Settings → Integrations** on the web.
|
|
40
|
+
|
|
41
|
+
## Use it
|
|
42
|
+
|
|
43
|
+
Typed resource commands:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
openluxe contacts list --per_page 5
|
|
47
|
+
openluxe contacts get 42
|
|
48
|
+
openluxe notes create --contact 42 --body "Followed up by phone"
|
|
49
|
+
openluxe render create -d '{"surface":"crm.dashboard","format":"pdf"}'
|
|
50
|
+
openluxe webhooks events
|
|
51
|
+
openluxe me show
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Run `openluxe <resource>` to see its commands, or `openluxe help` for the
|
|
55
|
+
full list.
|
|
56
|
+
|
|
57
|
+
Raw passthrough to any v1 endpoint:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
openluxe api GET /contacts --per_page 5
|
|
61
|
+
openluxe api POST /notes -d '{"contact_id":1,"body":"hi"}'
|
|
62
|
+
openluxe api DELETE /notes/9
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## For AI agents
|
|
66
|
+
|
|
67
|
+
Point your agent at the binary. Every endpoint is reachable via the typed
|
|
68
|
+
commands or `openluxe api <METHOD> <path>`. Output is always JSON on stdout;
|
|
69
|
+
errors go to stderr with a non-zero exit code, so it composes cleanly in
|
|
70
|
+
scripts and tool-use loops.
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
export OPENLUXE_API_URL=https://openluxe.co # default; override for staging/local
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Environment
|
|
77
|
+
|
|
78
|
+
| Var | Purpose |
|
|
79
|
+
|---|---|
|
|
80
|
+
| `OPENLUXE_API_URL` | API base (default `https://openluxe.co`) |
|
|
81
|
+
| `OPENLUXE_INSECURE=1` | Skip TLS verification — only for self-signed local/staging boxes (or pass `--insecure`). Off by default. |
|
|
82
|
+
|
|
83
|
+
Credentials: `~/.openluxe/credentials.json`
|
package/bin/openluxe.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Opt-in escape hatch for self-signed certs (local Herd / staging boxes).
|
|
4
|
+
// Default stays fully secure — only relaxes when explicitly requested.
|
|
5
|
+
if (process.env.OPENLUXE_INSECURE === '1' || process.argv.includes('--insecure')) {
|
|
6
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
import { run } from '../src/cli.js';
|
|
10
|
+
|
|
11
|
+
run(process.argv.slice(2)).catch((e) => {
|
|
12
|
+
console.error(`\x1b[31m✗ ${e?.message || e}\x1b[0m`);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openluxeco/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Official OpenLuxe command-line client — drive the OpenLuxe v1 API from your terminal or an AI agent.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"openluxe": "bin/openluxe.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"src",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=18"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"start": "node bin/openluxe.js"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/OpenLabs-co/openluxe-cli.git"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/OpenLabs-co/openluxe-cli/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/OpenLabs-co/openluxe-cli#readme",
|
|
29
|
+
"author": "OpenLuxe",
|
|
30
|
+
"keywords": [
|
|
31
|
+
"openluxe",
|
|
32
|
+
"cli",
|
|
33
|
+
"api",
|
|
34
|
+
"real-estate",
|
|
35
|
+
"crm",
|
|
36
|
+
"ai-agent"
|
|
37
|
+
],
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/api.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { load } from './config.js';
|
|
2
|
+
|
|
3
|
+
export class ApiError extends Error {
|
|
4
|
+
constructor(status, detail, body) {
|
|
5
|
+
super(detail || `HTTP ${status}`);
|
|
6
|
+
this.status = status;
|
|
7
|
+
this.body = body;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Perform an authenticated v1 API request. `path` is everything after
|
|
13
|
+
* /api/v1 (e.g. "/contacts"). `query` is an object, `body` is JSON-able.
|
|
14
|
+
*/
|
|
15
|
+
export async function request(method, path, { query, body, token, base } = {}) {
|
|
16
|
+
const cfg = load();
|
|
17
|
+
const apiBase = base || cfg.base;
|
|
18
|
+
const bearer = token || cfg.token;
|
|
19
|
+
|
|
20
|
+
const url = new URL(apiBase.replace(/\/$/, '') + '/api/v1' + (path.startsWith('/') ? path : '/' + path));
|
|
21
|
+
if (query) {
|
|
22
|
+
for (const [k, v] of Object.entries(query)) {
|
|
23
|
+
if (v !== undefined && v !== null) url.searchParams.set(k, v);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const headers = { Accept: 'application/json' };
|
|
28
|
+
if (bearer) headers.Authorization = `Bearer ${bearer}`;
|
|
29
|
+
const init = { method, headers };
|
|
30
|
+
if (body !== undefined && body !== null) {
|
|
31
|
+
headers['Content-Type'] = 'application/json';
|
|
32
|
+
init.body = typeof body === 'string' ? body : JSON.stringify(body);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let res;
|
|
36
|
+
try {
|
|
37
|
+
res = await fetch(url, init);
|
|
38
|
+
} catch (e) {
|
|
39
|
+
throw new ApiError(0, `Network error: ${e.message}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const text = await res.text();
|
|
43
|
+
let parsed;
|
|
44
|
+
try { parsed = text ? JSON.parse(text) : null; } catch { parsed = text; }
|
|
45
|
+
|
|
46
|
+
if (!res.ok) {
|
|
47
|
+
const detail = parsed && typeof parsed === 'object'
|
|
48
|
+
? (parsed.detail || parsed.message || parsed.error || `HTTP ${res.status}`)
|
|
49
|
+
: `HTTP ${res.status}`;
|
|
50
|
+
throw new ApiError(res.status, detail, parsed);
|
|
51
|
+
}
|
|
52
|
+
return parsed;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Unauthenticated POST used only by the device-auth handshake. */
|
|
56
|
+
export async function postPublic(base, path, body) {
|
|
57
|
+
const url = base.replace(/\/$/, '') + '/api/v1' + path;
|
|
58
|
+
const res = await fetch(url, {
|
|
59
|
+
method: 'POST',
|
|
60
|
+
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
|
61
|
+
body: JSON.stringify(body || {}),
|
|
62
|
+
});
|
|
63
|
+
const text = await res.text();
|
|
64
|
+
let parsed;
|
|
65
|
+
try { parsed = text ? JSON.parse(text) : null; } catch { parsed = text; }
|
|
66
|
+
return { ok: res.ok, status: res.status, data: parsed };
|
|
67
|
+
}
|
package/src/auth.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { hostname, userInfo } from 'node:os';
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { load, save, clear, credentialsPath } from './config.js';
|
|
4
|
+
import { postPublic } from './api.js';
|
|
5
|
+
|
|
6
|
+
const DEFAULT_BASE = process.env.OPENLUXE_API_URL || 'https://openluxe.co';
|
|
7
|
+
|
|
8
|
+
function openBrowser(url) {
|
|
9
|
+
const cmd = process.platform === 'darwin' ? 'open'
|
|
10
|
+
: process.platform === 'win32' ? 'cmd' : 'xdg-open';
|
|
11
|
+
const args = process.platform === 'win32' ? ['/c', 'start', '', url] : [url];
|
|
12
|
+
try {
|
|
13
|
+
const child = spawn(cmd, args, { stdio: 'ignore', detached: true });
|
|
14
|
+
child.on('error', () => {});
|
|
15
|
+
child.unref();
|
|
16
|
+
} catch { /* headless / no browser — the printed URL is the fallback */ }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
20
|
+
|
|
21
|
+
export async function login({ base } = {}) {
|
|
22
|
+
const apiBase = base || process.env.OPENLUXE_API_URL || load().base || DEFAULT_BASE;
|
|
23
|
+
|
|
24
|
+
const start = await postPublic(apiBase, '/cli/auth/start', {
|
|
25
|
+
client_name: 'OpenLuxe CLI',
|
|
26
|
+
client_hostname: `${userInfo().username}@${hostname()}`,
|
|
27
|
+
});
|
|
28
|
+
if (!start.ok) {
|
|
29
|
+
console.error(`Could not start login: ${start.data?.detail || start.status}`);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const { device_code, user_code, verification_uri_complete, verification_uri, interval, expires_in } = start.data;
|
|
34
|
+
|
|
35
|
+
console.log('');
|
|
36
|
+
console.log(' Authorize this device by visiting:');
|
|
37
|
+
console.log(` \x1b[36m${verification_uri_complete || verification_uri}\x1b[0m`);
|
|
38
|
+
console.log('');
|
|
39
|
+
console.log(` Confirm this code: \x1b[1m${user_code}\x1b[0m`);
|
|
40
|
+
console.log('');
|
|
41
|
+
console.log(' Opening your browser… (sign in if prompted, then approve)');
|
|
42
|
+
console.log('');
|
|
43
|
+
openBrowser(verification_uri_complete || verification_uri);
|
|
44
|
+
|
|
45
|
+
const deadline = Date.now() + expires_in * 1000;
|
|
46
|
+
let wait = (interval || 5) * 1000;
|
|
47
|
+
|
|
48
|
+
while (Date.now() < deadline) {
|
|
49
|
+
await sleep(wait);
|
|
50
|
+
const poll = await postPublic(apiBase, '/cli/auth/poll', { device_code });
|
|
51
|
+
|
|
52
|
+
if (poll.ok && poll.data?.status === 'authorized') {
|
|
53
|
+
save({ base: apiBase, token: poll.data.token, user: poll.data.user });
|
|
54
|
+
const who = poll.data.user?.email || poll.data.user?.name || 'your account';
|
|
55
|
+
console.log(`\x1b[32m✓ Signed in as ${who}\x1b[0m`);
|
|
56
|
+
console.log(` Token stored at ${credentialsPath}`);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (poll.ok && poll.data?.status === 'pending') {
|
|
60
|
+
continue; // keep waiting
|
|
61
|
+
}
|
|
62
|
+
if (poll.status === 429) {
|
|
63
|
+
wait += 2000; // server asked us to slow down
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (poll.status === 410 || poll.status === 403) {
|
|
67
|
+
console.error(`\x1b[31m✗ ${poll.data?.detail || 'Authorization failed.'}\x1b[0m`);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
console.error('\x1b[31m✗ Timed out waiting for authorization.\x1b[0m');
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function logout() {
|
|
76
|
+
const { user } = load();
|
|
77
|
+
clear();
|
|
78
|
+
console.log('Signed out locally. The token still exists server-side —');
|
|
79
|
+
console.log('revoke it at Settings → Integrations if this device is compromised.');
|
|
80
|
+
if (user?.email) console.log(`(was: ${user.email})`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function status() {
|
|
84
|
+
const { base, token, user } = load();
|
|
85
|
+
if (!token) {
|
|
86
|
+
console.log('Not signed in. Run: openluxe auth login');
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
console.log(`Signed in: ${user?.email || user?.name || 'unknown'}`);
|
|
90
|
+
console.log(`API: ${base}`);
|
|
91
|
+
console.log(`Credentials ${credentialsPath}`);
|
|
92
|
+
}
|
package/src/cli.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { request, ApiError } from './api.js';
|
|
2
|
+
import { RESOURCES } from './resources.js';
|
|
3
|
+
import * as auth from './auth.js';
|
|
4
|
+
import { load } from './config.js';
|
|
5
|
+
|
|
6
|
+
const C = {
|
|
7
|
+
dim: (s) => `\x1b[2m${s}\x1b[0m`,
|
|
8
|
+
bold: (s) => `\x1b[1m${s}\x1b[0m`,
|
|
9
|
+
cyan: (s) => `\x1b[36m${s}\x1b[0m`,
|
|
10
|
+
red: (s) => `\x1b[31m${s}\x1b[0m`,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Tokenize argv into { positionals, flags, body }.
|
|
15
|
+
* --key value | --key=value | --flag (boolean) | -d '<json>'
|
|
16
|
+
*/
|
|
17
|
+
function parseArgs(argv) {
|
|
18
|
+
const positionals = [];
|
|
19
|
+
const flags = {};
|
|
20
|
+
let body;
|
|
21
|
+
for (let i = 0; i < argv.length; i++) {
|
|
22
|
+
const a = argv[i];
|
|
23
|
+
if (a === '-d' || a === '--data') {
|
|
24
|
+
const raw = argv[++i];
|
|
25
|
+
try { body = JSON.parse(raw); } catch { die(`-d expects valid JSON, got: ${raw}`); }
|
|
26
|
+
} else if (a.startsWith('--')) {
|
|
27
|
+
const eq = a.indexOf('=');
|
|
28
|
+
if (eq !== -1) {
|
|
29
|
+
flags[a.slice(2, eq)] = a.slice(eq + 1);
|
|
30
|
+
} else {
|
|
31
|
+
const key = a.slice(2);
|
|
32
|
+
const next = argv[i + 1];
|
|
33
|
+
if (next === undefined || next.startsWith('--')) {
|
|
34
|
+
flags[key] = true;
|
|
35
|
+
} else {
|
|
36
|
+
flags[key] = next;
|
|
37
|
+
i++;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
positionals.push(a);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return { positionals, flags, body };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function die(msg) {
|
|
48
|
+
console.error(C.red(`✗ ${msg}`));
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function out(data) {
|
|
53
|
+
process.stdout.write(typeof data === 'string' ? data + '\n' : JSON.stringify(data, null, 2) + '\n');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function callApi(method, path, { positionals = [], flags = {}, body }) {
|
|
57
|
+
// Fill :placeholders from --flag of the same name, else positionals in order.
|
|
58
|
+
const used = new Set();
|
|
59
|
+
let pi = 0;
|
|
60
|
+
const filled = path.replace(/:([A-Za-z_]+)/g, (_, name) => {
|
|
61
|
+
if (flags[name] !== undefined) { used.add(name); return encodeURIComponent(flags[name]); }
|
|
62
|
+
const v = positionals[pi++];
|
|
63
|
+
if (v === undefined) die(`Missing path argument: ${name}`);
|
|
64
|
+
return encodeURIComponent(v);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const rest = {};
|
|
68
|
+
for (const [k, v] of Object.entries(flags)) if (!used.has(k)) rest[k] = v;
|
|
69
|
+
|
|
70
|
+
let query, payload;
|
|
71
|
+
if (method === 'GET' || method === 'DELETE') {
|
|
72
|
+
query = rest;
|
|
73
|
+
} else {
|
|
74
|
+
payload = { ...(body || {}), ...rest };
|
|
75
|
+
if (Object.keys(payload).length === 0) payload = body;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
const res = await request(method, filled, { query, body: payload });
|
|
80
|
+
out(res);
|
|
81
|
+
} catch (e) {
|
|
82
|
+
if (e instanceof ApiError) {
|
|
83
|
+
console.error(C.red(`✗ ${e.status} ${e.message}`));
|
|
84
|
+
if (e.body && typeof e.body === 'object') console.error(C.dim(JSON.stringify(e.body, null, 2)));
|
|
85
|
+
if (e.status === 401) console.error(C.dim(' Run: openluxe auth login'));
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
die(e.message);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function topHelp() {
|
|
93
|
+
const { token, user, base } = load();
|
|
94
|
+
console.log(`
|
|
95
|
+
${C.bold('openluxe')} — OpenLuxe API command-line client
|
|
96
|
+
|
|
97
|
+
${C.bold('USAGE')}
|
|
98
|
+
openluxe <command> [args] [--flags] [-d '<json>']
|
|
99
|
+
|
|
100
|
+
${C.bold('AUTH')}
|
|
101
|
+
auth login Sign in via your browser (device flow)
|
|
102
|
+
auth logout Forget the local token
|
|
103
|
+
auth status Show who you're signed in as
|
|
104
|
+
|
|
105
|
+
${C.bold('RAW')}
|
|
106
|
+
api <METHOD> <path> Call any v1 endpoint directly
|
|
107
|
+
e.g. openluxe api GET /contacts --per_page 5
|
|
108
|
+
openluxe api POST /notes -d '{"contact_id":1,"body":"hi"}'
|
|
109
|
+
|
|
110
|
+
${C.bold('RESOURCES')}
|
|
111
|
+
${Object.entries(RESOURCES).map(([g, r]) => ` ${g.padEnd(16)} ${C.dim(r.summary)}`).join('\n')}
|
|
112
|
+
|
|
113
|
+
Run ${C.cyan('openluxe <resource>')} to see its commands.
|
|
114
|
+
|
|
115
|
+
${C.bold('STATE')}
|
|
116
|
+
${token ? `signed in as ${user?.email || 'unknown'}` : 'not signed in — run: openluxe auth login'}
|
|
117
|
+
API: ${base}
|
|
118
|
+
`);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function groupHelp(group) {
|
|
122
|
+
const r = RESOURCES[group];
|
|
123
|
+
console.log(`\n${C.bold('openluxe ' + group)} — ${r.summary}\n`);
|
|
124
|
+
for (const [name, c] of Object.entries(r.commands)) {
|
|
125
|
+
console.log(` ${(group + ' ' + name).padEnd(28)} ${C.dim(`${c.method} ${c.path}`)}${c.summary ? ' ' + c.summary : ''}`);
|
|
126
|
+
}
|
|
127
|
+
console.log('');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export async function run(argv) {
|
|
131
|
+
const [cmd, ...rest] = argv;
|
|
132
|
+
|
|
133
|
+
if (!cmd || cmd === 'help' || cmd === '--help' || cmd === '-h') return topHelp();
|
|
134
|
+
if (cmd === '--version' || cmd === '-v') return out('openluxe 0.1.0');
|
|
135
|
+
|
|
136
|
+
if (cmd === 'auth') {
|
|
137
|
+
const sub = rest[0];
|
|
138
|
+
const { flags } = parseArgs(rest.slice(1));
|
|
139
|
+
if (sub === 'login') return auth.login({ base: flags.base });
|
|
140
|
+
if (sub === 'logout') return auth.logout();
|
|
141
|
+
if (sub === 'status') return auth.status();
|
|
142
|
+
return die(`Unknown auth command: ${sub || '(none)'} — try login | logout | status`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (cmd === 'api') {
|
|
146
|
+
const method = (rest[0] || '').toUpperCase();
|
|
147
|
+
const path = rest[1];
|
|
148
|
+
if (!method || !path) return die("usage: openluxe api <METHOD> <path> [-d '<json>'] [--query val]");
|
|
149
|
+
const { flags, body } = parseArgs(rest.slice(2));
|
|
150
|
+
return callApi(method, path, { flags, body });
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const group = RESOURCES[cmd];
|
|
154
|
+
if (!group) return die(`Unknown command: ${cmd}. Run 'openluxe help'.`);
|
|
155
|
+
|
|
156
|
+
const subName = rest[0];
|
|
157
|
+
if (!subName || subName === '--help' || subName === '-h') return groupHelp(cmd);
|
|
158
|
+
|
|
159
|
+
const command = group.commands[subName];
|
|
160
|
+
if (!command) return die(`Unknown '${cmd}' command: ${subName}. Run 'openluxe ${cmd}' for options.`);
|
|
161
|
+
|
|
162
|
+
const { positionals, flags, body } = parseArgs(rest.slice(1));
|
|
163
|
+
return callApi(command.method, command.path, { positionals, flags, body });
|
|
164
|
+
}
|
package/src/config.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { homedir } from 'node:os';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { mkdirSync, readFileSync, writeFileSync, existsSync, chmodSync, rmSync } from 'node:fs';
|
|
4
|
+
|
|
5
|
+
const DIR = join(homedir(), '.openluxe');
|
|
6
|
+
const FILE = join(DIR, 'credentials.json');
|
|
7
|
+
|
|
8
|
+
const DEFAULT_BASE = process.env.OPENLUXE_API_URL || 'https://openluxe.co';
|
|
9
|
+
|
|
10
|
+
export function load() {
|
|
11
|
+
if (!existsSync(FILE)) {
|
|
12
|
+
return { base: DEFAULT_BASE, token: null, user: null };
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const data = JSON.parse(readFileSync(FILE, 'utf8'));
|
|
16
|
+
return {
|
|
17
|
+
base: process.env.OPENLUXE_API_URL || data.base || DEFAULT_BASE,
|
|
18
|
+
token: data.token || null,
|
|
19
|
+
user: data.user || null,
|
|
20
|
+
};
|
|
21
|
+
} catch {
|
|
22
|
+
return { base: DEFAULT_BASE, token: null, user: null };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function save({ base, token, user }) {
|
|
27
|
+
mkdirSync(DIR, { recursive: true });
|
|
28
|
+
writeFileSync(FILE, JSON.stringify({ base, token, user }, null, 2));
|
|
29
|
+
// Credentials file holds a bearer token — lock it down to the owner.
|
|
30
|
+
try { chmodSync(FILE, 0o600); } catch { /* best effort (e.g. Windows) */ }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function clear() {
|
|
34
|
+
if (existsSync(FILE)) rmSync(FILE);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const credentialsPath = FILE;
|
package/src/resources.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declarative map of typed resource commands over the OpenLuxe v1 API.
|
|
3
|
+
*
|
|
4
|
+
* Each command: { method, path, summary, params? }
|
|
5
|
+
* - `path` may contain :placeholders, filled from positional args (in order)
|
|
6
|
+
* or a matching --flag.
|
|
7
|
+
* - For GET: leftover --flags become query string.
|
|
8
|
+
* - For POST/PATCH: --flags + `-d '<json>'` merge into the JSON body.
|
|
9
|
+
*
|
|
10
|
+
* This is intentionally data-driven so the CLI mirrors the API surface
|
|
11
|
+
* without 100+ hand-written command files.
|
|
12
|
+
*/
|
|
13
|
+
export const RESOURCES = {
|
|
14
|
+
contacts: {
|
|
15
|
+
summary: 'CRM contacts',
|
|
16
|
+
commands: {
|
|
17
|
+
list: { method: 'GET', path: '/contacts', summary: 'List your contacts' },
|
|
18
|
+
get: { method: 'GET', path: '/contacts/:contact', summary: 'Show one contact' },
|
|
19
|
+
create: { method: 'POST', path: '/contacts', summary: 'Create a contact' },
|
|
20
|
+
update: { method: 'PATCH', path: '/contacts/:contact', summary: 'Update a contact' },
|
|
21
|
+
delete: { method: 'DELETE', path: '/contacts/:contact', summary: 'Delete a contact' },
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
notes: {
|
|
25
|
+
summary: 'CRM notes',
|
|
26
|
+
commands: {
|
|
27
|
+
list: { method: 'GET', path: '/notes', summary: 'List notes' },
|
|
28
|
+
get: { method: 'GET', path: '/notes/:note' },
|
|
29
|
+
create: { method: 'POST', path: '/notes', summary: 'Create a note' },
|
|
30
|
+
update: { method: 'PATCH', path: '/notes/:note' },
|
|
31
|
+
delete: { method: 'DELETE', path: '/notes/:note' },
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
reminders: {
|
|
35
|
+
summary: 'CRM reminders',
|
|
36
|
+
commands: {
|
|
37
|
+
list: { method: 'GET', path: '/reminders' },
|
|
38
|
+
get: { method: 'GET', path: '/reminders/:reminder' },
|
|
39
|
+
create: { method: 'POST', path: '/reminders' },
|
|
40
|
+
update: { method: 'PATCH', path: '/reminders/:reminder' },
|
|
41
|
+
delete: { method: 'DELETE', path: '/reminders/:reminder' },
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
tasks: {
|
|
45
|
+
summary: 'CRM tasks',
|
|
46
|
+
commands: {
|
|
47
|
+
list: { method: 'GET', path: '/tasks' },
|
|
48
|
+
get: { method: 'GET', path: '/tasks/:task' },
|
|
49
|
+
create: { method: 'POST', path: '/tasks' },
|
|
50
|
+
update: { method: 'PATCH', path: '/tasks/:task' },
|
|
51
|
+
delete: { method: 'DELETE', path: '/tasks/:task' },
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
deals: {
|
|
55
|
+
summary: 'CRM deals (read-only in v1)',
|
|
56
|
+
commands: {
|
|
57
|
+
list: { method: 'GET', path: '/deals' },
|
|
58
|
+
get: { method: 'GET', path: '/deals/:deal' },
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
'contact-lists': {
|
|
62
|
+
summary: 'Contact lists',
|
|
63
|
+
commands: {
|
|
64
|
+
list: { method: 'GET', path: '/contact-lists' },
|
|
65
|
+
get: { method: 'GET', path: '/contact-lists/:list' },
|
|
66
|
+
create: { method: 'POST', path: '/contact-lists' },
|
|
67
|
+
update: { method: 'PATCH', path: '/contact-lists/:list' },
|
|
68
|
+
delete: { method: 'DELETE', path: '/contact-lists/:list' },
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
listings: {
|
|
72
|
+
summary: 'Property listings (read-only in v1)',
|
|
73
|
+
commands: {
|
|
74
|
+
list: { method: 'GET', path: '/listings' },
|
|
75
|
+
get: { method: 'GET', path: '/listings/:listing' },
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
showings: {
|
|
79
|
+
summary: 'Listing showings',
|
|
80
|
+
commands: {
|
|
81
|
+
list: { method: 'GET', path: '/showings' },
|
|
82
|
+
get: { method: 'GET', path: '/showings/:showing' },
|
|
83
|
+
create: { method: 'POST', path: '/showings' },
|
|
84
|
+
update: { method: 'PATCH', path: '/showings/:showing' },
|
|
85
|
+
delete: { method: 'DELETE', path: '/showings/:showing' },
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
'open-houses': {
|
|
89
|
+
summary: 'Open houses',
|
|
90
|
+
commands: {
|
|
91
|
+
list: { method: 'GET', path: '/open-houses' },
|
|
92
|
+
get: { method: 'GET', path: '/open-houses/:openHouse' },
|
|
93
|
+
attendees: { method: 'GET', path: '/open-houses/:openHouse/attendees' },
|
|
94
|
+
create: { method: 'POST', path: '/open-houses' },
|
|
95
|
+
update: { method: 'PATCH', path: '/open-houses/:openHouse' },
|
|
96
|
+
delete: { method: 'DELETE', path: '/open-houses/:openHouse' },
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
'store-products': {
|
|
100
|
+
summary: 'Store products (read-only in v1)',
|
|
101
|
+
commands: {
|
|
102
|
+
list: { method: 'GET', path: '/store/products' },
|
|
103
|
+
get: { method: 'GET', path: '/store/products/:product' },
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
webinars: {
|
|
107
|
+
summary: 'Webinars',
|
|
108
|
+
commands: {
|
|
109
|
+
list: { method: 'GET', path: '/webinars' },
|
|
110
|
+
get: { method: 'GET', path: '/webinars/:webinar' },
|
|
111
|
+
registrations: { method: 'GET', path: '/webinars/:webinar/registrations' },
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
travel: {
|
|
115
|
+
summary: 'Travel bookings (read-only)',
|
|
116
|
+
commands: {
|
|
117
|
+
flights: { method: 'GET', path: '/travel/flights' },
|
|
118
|
+
stays: { method: 'GET', path: '/travel/stays' },
|
|
119
|
+
cars: { method: 'GET', path: '/travel/cars' },
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
escrow: {
|
|
123
|
+
summary: 'Escrow transactions (read-only)',
|
|
124
|
+
commands: {
|
|
125
|
+
list: { method: 'GET', path: '/escrow' },
|
|
126
|
+
get: { method: 'GET', path: '/escrow/:escrow' },
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
courses: {
|
|
130
|
+
summary: 'Courses',
|
|
131
|
+
commands: {
|
|
132
|
+
list: { method: 'GET', path: '/courses' },
|
|
133
|
+
get: { method: 'GET', path: '/courses/:course' },
|
|
134
|
+
enrollments: { method: 'GET', path: '/course-enrollments' },
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
credits: {
|
|
138
|
+
summary: 'Credit balance & ledger',
|
|
139
|
+
commands: {
|
|
140
|
+
balance: { method: 'GET', path: '/credits/balance' },
|
|
141
|
+
ledger: { method: 'GET', path: '/credits/ledger' },
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
webhooks: {
|
|
145
|
+
summary: 'Outbound webhook subscriptions',
|
|
146
|
+
commands: {
|
|
147
|
+
list: { method: 'GET', path: '/webhooks' },
|
|
148
|
+
events: { method: 'GET', path: '/webhooks/events', summary: 'List subscribable event types' },
|
|
149
|
+
get: { method: 'GET', path: '/webhooks/:webhook' },
|
|
150
|
+
create: { method: 'POST', path: '/webhooks', summary: 'Create a subscription (secret shown once)' },
|
|
151
|
+
update: { method: 'PATCH', path: '/webhooks/:webhook' },
|
|
152
|
+
delete: { method: 'DELETE', path: '/webhooks/:webhook' },
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
render: {
|
|
156
|
+
summary: 'Headless PNG/PDF render of a UI surface',
|
|
157
|
+
commands: {
|
|
158
|
+
create: { method: 'POST', path: '/render', summary: 'Queue a render (surface=, format=)' },
|
|
159
|
+
get: { method: 'GET', path: '/render/:render', summary: 'Poll render status / get URL' },
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
skills: {
|
|
163
|
+
summary: 'Skills library (read-only)',
|
|
164
|
+
commands: {
|
|
165
|
+
list: { method: 'GET', path: '/skills' },
|
|
166
|
+
get: { method: 'GET', path: '/skills/:slug' },
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
search: {
|
|
170
|
+
summary: 'Universal record search',
|
|
171
|
+
commands: {
|
|
172
|
+
query: { method: 'GET', path: '/search', summary: 'Search (q=...)' },
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
me: {
|
|
176
|
+
summary: 'Your token / identity',
|
|
177
|
+
commands: {
|
|
178
|
+
show: { method: 'GET', path: '/me', summary: 'Who am I + token scopes' },
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
};
|