@inboxychat/cli 0.0.0-stage → 0.2.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 CHANGED
@@ -1,3 +1,179 @@
1
- # Temporary Holding Version
1
+ # @inboxychat/cli — `inboxy`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A command line for agencies and support: check a key, read orders, contacts and
4
+ usage, and diagnose a setup. It supports public reads and audited, explicitly confirmed operation adapters.
5
+
6
+ Published on npm as [`@inboxychat/cli`](https://www.npmjs.com/package/@inboxychat/cli).
7
+ Full guide (English and Arabic): https://inboxy.chat/developers/cli
8
+
9
+ ## Install
10
+
11
+ Needs Node.js 20.3 or newer.
12
+
13
+ ```bash
14
+ npm i -g @inboxychat/cli
15
+ inboxy --version
16
+ # or without installing:
17
+ npx -y -p @inboxychat/cli inboxy --help
18
+ ```
19
+
20
+ Create the key in the Inboxy dashboard as a company admin (Developers → API,
21
+ `/developer-center/api`), with only the scopes you need
22
+ (`orders:read`, `contacts:read`, `analytics:read`, ...) and an expiry.
23
+
24
+ ### From this repository
25
+
26
+ ```bash
27
+ pnpm install
28
+ pnpm --filter @inboxychat/cli build # builds the SDK too
29
+ node packages/inboxy-cli/dist/bin.js --help
30
+ ```
31
+
32
+ ## Sign in
33
+
34
+ ```bash
35
+ inboxy auth login # browser approval on a terminal
36
+ pbpaste | inboxy auth login # or pipe a key (not a TTY; stays out of shell history)
37
+ inboxy auth login --profile client-a # one profile per company (agencies)
38
+ inboxy auth status # where the key comes from + is it accepted
39
+ inboxy auth logout --profile client-a
40
+ ```
41
+
42
+ On a terminal, `inboxy auth login` opens Inboxy in the browser. You approve the
43
+ code, and the CLI stores the API key that approval mints. The key is never a
44
+ command-line argument: `inboxy auth login <key>` or a `--key` / `--token` /
45
+ `--api-key` flag on any command is refused (exit 2) without echoing what was
46
+ typed. When stdin is not a terminal, the same command reads a key from the pipe instead.
47
+
48
+ It is stored in the OS keychain (macOS Keychain via `security`, Linux Secret Service via
49
+ `secret-tool`; the secret goes to those tools on stdin, not argv). Without a
50
+ keychain (or with `--store file`) it goes into the config file with mode `0600`
51
+ in a `0700` directory; a config file other users can read is refused.
52
+
53
+ Config: `$INBOXY_CONFIG_DIR`, else `$XDG_CONFIG_HOME/inboxy`, else
54
+ `~/.config/inboxy/config.json`. It holds the API URL and where the key lives.
55
+
56
+ `INBOXY_API_KEY` / `INBOXY_API_URL` / `INBOXY_PROFILE` override everything.
57
+ `INBOXY_KEYCHAIN=off` disables the keychain.
58
+
59
+ ## Commands
60
+
61
+ ```
62
+ inboxy whoami company, key name, scopes, expiry, rate limits
63
+ inboxy usage plan usage against limits
64
+ inboxy stores list connected-store count vs plan limit (*)
65
+ inboxy orders list [--status pending] [--payment-status ..] [--fulfillment-status ..]
66
+ [--source shopify] [--store <id>] [--contact <id>] [--search <text>]
67
+ [--after <iso>] [--before <iso>]
68
+ inboxy orders get <id>
69
+ inboxy contacts search [text] [--status ..] [--stage lead] [--tags <ids>]
70
+ [--created-after <iso>] [--created-before <iso>]
71
+ inboxy doctor URL, key, key format, reachability, scopes,
72
+ key expiry, clock skew, config permissions
73
+ ```
74
+
75
+ (\*) The public API has no stores route yet, so `stores list` shows the count
76
+ from plan usage and says so (`items: null` in JSON). Per-store health is in the
77
+ dashboard.
78
+
79
+ Paging: `--limit 1-100`, `--cursor <nextCursor>`, or `--all` (follows cursors,
80
+ up to `--max-pages`, default 10). Global: `--json`, `--profile`, `--url`,
81
+ `--timeout <ms>`. Global options may come before or after the command.
82
+
83
+ ## `--json`
84
+
85
+ One document on stdout, schema version 1 (fields may be added, never renamed or removed):
86
+
87
+ ```json
88
+ { "schemaVersion": 1, "ok": true, "command": "orders list",
89
+ "data": [ ... ], "meta": { "limit": 20, "hasMore": true, "nextCursor": "...", "pages": 1 } }
90
+
91
+ { "schemaVersion": 1, "ok": false, "command": "orders list",
92
+ "error": { "kind": "forbidden", "code": "INSUFFICIENT_PERMISSIONS", "status": 403,
93
+ "message": "This API key does not have the \"orders:read\" scope. ...",
94
+ "details": { "requiredScope": "orders:read" }, "retryAfterSeconds": null } }
95
+ ```
96
+
97
+ `data` items are the public API v1 objects unchanged.
98
+
99
+ ## Exit codes
100
+
101
+ | Code | Meaning |
102
+ | ---- | ------------------------------------------------------------------------- |
103
+ | 0 | OK |
104
+ | 1 | Unexpected error |
105
+ | 2 | Usage error (bad flag, bad value, invalid id) — nothing was sent |
106
+ | 3 | Configuration: no key, bad URL, config file permissions, no keychain |
107
+ | 4 | Key refused (401) |
108
+ | 5 | Forbidden (403): missing scope, company paused, key owner no longer admin |
109
+ | 6 | Not found (404) |
110
+ | 7 | Rate limited (429) — see `retryAfterSeconds` |
111
+ | 8 | Network error, timeout or cancelled |
112
+ | 9 | Server error or a response that is not the API envelope |
113
+ | 10 | `doctor` found at least one failing check |
114
+
115
+ ## Safety
116
+
117
+ - The key is never printed. Errors and JSON pass through redaction (any
118
+ `inboxy_…` value, any `Bearer …` value and the exact key in use), even when a
119
+ server message echoes the header back. Status output shows only the 8-character
120
+ prefix the dashboard also shows.
121
+ - No shell: inputs reach the API only as validated, percent-encoded path
122
+ segments or query values; ids must be 1–64 letters, digits, `_` or `-`.
123
+ - HTTPS only (plain `http://` for `localhost` only); redirects are refused.
124
+
125
+ ## Tests
126
+
127
+ ```bash
128
+ pnpm --filter @inboxychat/cli test
129
+ ```
130
+
131
+ `test/cli.e2e.test.ts` runs the built binary against the local mock API:
132
+ every command, paging, filters, exit codes, the key never in stdout/stderr,
133
+ no shell interpolation, auth login/status/logout with the 0600 file, refusal
134
+ of a world-readable config, profiles per company, and doctor (clock skew,
135
+ scopes, expiry, refused key, unreachable URL). `test/cli.inprocess.test.ts`
136
+ covers the keychain path with a fake keychain and redaction of a key echoed by
137
+ the server. The macOS Keychain adapter was also checked once by hand with a
138
+ throwaway entry (store, update, read, delete).
139
+
140
+ ## Audited operations
141
+
142
+ `inboxy operations list` and `operations inspect <id>` expose the same 80 schemas
143
+ as the SDK and MCP. `operations preview <id> --input '<json>' --idempotency-key
144
+ <unique-key>` validates locally without credentials or network access. Review the
145
+ payload and warning, then explicitly approve with `operations run <id> --input
146
+ '<same-json>' --idempotency-key <same-key> --confirm <preview-hash>`.
147
+ Use `--json` for structured output. Do not put sensitive input in shell history;
148
+ call the SDK directly when inputs contain private material. A changed payload or
149
+ key invalidates confirmation. No automatic retry occurs. Existing API scopes,
150
+ roles and tenant isolation apply. This is bounded coverage, not full UI parity;
151
+ see [SDK operation boundaries](../inboxy-sdk/README.md#audited-operation-adapters).
152
+
153
+
154
+ ### Expanded operation coverage
155
+
156
+ The source catalog now has 80 operations (553 discovery routes). Added inbox
157
+ assignment/status/labels/internal notes; separate one-message text sending;
158
+ reviewed AI text knowledge and channel assignments; manual orders, state/payment/
159
+ fulfillment records; product/category creation and updates. Inspect the catalog
160
+ for exact schemas. Media/templates/bulk sends, scheduling, order cancellation/
161
+ refunds, URL/file knowledge ingestion and complete automation coverage remain out
162
+ of scope. Orders may trigger configured automation; payment-record changes do not
163
+ charge a payment provider.
164
+
165
+ For a send, preview `inbox.message.send` with `conversationId`, `target` containing
166
+ `contactId`, `channelId`, `channelType` (uppercase enum), and `body.content`.
167
+ Inspect the conversation first and approve the exact recipient, channel and full
168
+ text. CLI uses `messages send --input <same-json> --idempotency-key <same-key>
169
+ --confirm <hash>`; MCP uses the separate `message_send` tool with identical input,
170
+ idempotencyKey and confirmation. Generic operation execution in CLI/MCP refuses
171
+ sends. The SDK dispatch includes a confirmed-target header, validated against the
172
+ current tenant conversation before send; a mismatch requires a new inspection and
173
+ approval. Stable clientMessageId supplements the existing idempotency middleware.
174
+
175
+ The lifecycle slice adds contact status/stage/assignment/internal notes, tag management and bounded flat custom-field replacement. It adds automation graph/run inspection, inactive draft creation and pause, plus campaign audience estimation, pause and cancel. Tag changes may trigger configured automations. Automation graph editing/publish remain unavailable; a preview estimate does not authorize scheduling.
176
+
177
+ Workflow activation: first execute `automations.activation.preview`, show the entire returned preview, then pass it unchanged as `body.approval` to `automations.activate` with an exact confirmation and idempotency key. The server rechecks tenant, published version/hash, complete preview and workflow revision in a transaction. MCP uses `lifecycle_activate`; CLI uses `lifecycle activate <operation>`. The generic operation runner refuses activate effects, including AI publish/channel changes. `automations.simulate` uses existing dry services and skips external side effects.
178
+
179
+ Campaign delivery uses `campaigns.approval` to resolve a complete snapshot (audience, sender, template/content, limits and exact time). Pass that unchanged in `body.approval` to `campaigns.send`, `campaigns.resume` or `campaigns.schedule`, preview locally, then obtain explicit approval. MCP requires `campaign_send` or `campaign_schedule`; CLI requires `campaigns send <operation>` or `campaigns schedule`. The server freezes approval and checks it again before delivery. These actions can send real customer messages and consume budget. Keep the same idempotency key for recovery. Version 0.2.0 is prepared locally; publication and API deployment are separate release steps.
package/dist/bin.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=bin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":""}
package/dist/bin.js ADDED
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from 'node:child_process';
3
+ import { runCli } from './cli.js';
4
+ /** Opens an http(s) URL in the OS browser. Argument array only — no shell. */
5
+ function openBrowser(url) {
6
+ let parsed;
7
+ try {
8
+ parsed = new URL(url);
9
+ }
10
+ catch {
11
+ return;
12
+ }
13
+ if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:')
14
+ return;
15
+ const command = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'cmd' : 'xdg-open';
16
+ const args = process.platform === 'win32' ? ['/c', 'start', '', url] : [url];
17
+ const child = spawn(command, args, { stdio: 'ignore', detached: true, windowsHide: true });
18
+ child.on('error', () => undefined);
19
+ child.unref();
20
+ }
21
+ async function readAll(stream) {
22
+ let data = '';
23
+ stream.setEncoding('utf8');
24
+ for await (const chunk of stream)
25
+ data += chunk;
26
+ return data;
27
+ }
28
+ /** Reads a line from the terminal without echoing it. */
29
+ function promptHidden(prompt) {
30
+ const stdin = process.stdin;
31
+ process.stderr.write(prompt);
32
+ return new Promise((resolve) => {
33
+ let input = '';
34
+ stdin.setRawMode(true);
35
+ stdin.resume();
36
+ stdin.setEncoding('utf8');
37
+ const onData = (chunk) => {
38
+ for (const ch of chunk) {
39
+ if (ch === '\r' || ch === '\n' || ch === '\u0004') {
40
+ stdin.setRawMode(false);
41
+ stdin.pause();
42
+ stdin.off('data', onData);
43
+ process.stderr.write('\n');
44
+ resolve(input);
45
+ return;
46
+ }
47
+ if (ch === '\u0003') {
48
+ stdin.setRawMode(false);
49
+ process.stderr.write('\n');
50
+ process.exit(130);
51
+ }
52
+ if (ch === '\u007f' || ch === '\b')
53
+ input = input.slice(0, -1);
54
+ else
55
+ input += ch;
56
+ }
57
+ };
58
+ stdin.on('data', onData);
59
+ });
60
+ }
61
+ const io = {
62
+ stdout: (t) => process.stdout.write(t),
63
+ stderr: (t) => process.stderr.write(t),
64
+ readSecret: (prompt) => (process.stdin.isTTY ? promptHidden(prompt) : readAll(process.stdin)),
65
+ interactive: Boolean(process.stdin.isTTY),
66
+ openUrl: openBrowser,
67
+ env: process.env,
68
+ now: () => Date.now(),
69
+ };
70
+ runCli(process.argv.slice(2), io).then((code) => {
71
+ process.exitCode = code;
72
+ }, () => {
73
+ process.stderr.write('inboxy: unexpected failure\n');
74
+ process.exitCode = 1;
75
+ });
76
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC,8EAA8E;AAC9E,SAAS,WAAW,CAAC,GAAW;IAC9B,IAAI,MAAW,CAAC;IAChB,IAAI,CAAC;QACH,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,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACtC,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACtC,UAAU,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC7F,WAAW,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;IACzC,OAAO,EAAE,WAAW;IACpB,GAAG,EAAE,OAAO,CAAC,GAAG;IAChB,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;CACtB,CAAC;AAEF,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CACpC,CAAC,IAAI,EAAE,EAAE;IACP,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;AAC1B,CAAC,EACD,GAAG,EAAE;IACH,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;IACrD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CACF,CAAC"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { type Keychain } from '@inboxychat/sdk';
2
+ import { type CliIO } from './output.js';
3
+ export declare const CLI_VERSION = "0.2.0";
4
+ export interface CliDeps {
5
+ /** Override the OS keychain (tests); undefined = detect, null = none. */
6
+ keychain?: Keychain | null;
7
+ }
8
+ /** Commands that only touch local configuration (no capability behind them). */
9
+ export declare const LOCAL_COMMANDS: readonly ["auth login", "auth logout", "auth status", "doctor"];
10
+ /**
11
+ * Data commands: each is the adapter of one registered capability (UX26-F,
12
+ * apps/api/src/lib/capabilities). A command without one is not offered.
13
+ */
14
+ export declare const DATA_COMMANDS: string[];
15
+ export declare const OPERATION_COMMANDS: readonly ["operations list", "operations inspect", "operations preview", "operations run", "messages send", "lifecycle activate", "campaigns send", "campaigns schedule"];
16
+ export declare function runCli(argv: string[], io: CliIO, deps?: CliDeps): Promise<number>;
17
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AASA,OAAO,EAuBL,KAAK,QAAQ,EAKd,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAmC,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAE1E,eAAO,MAAM,WAAW,UAAU,CAAC;AAmEnC,MAAM,WAAW,OAAO;IACtB,yEAAyE;IACzE,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;CAC5B;AA6DD,gFAAgF;AAChF,eAAO,MAAM,cAAc,iEAAkE,CAAC;AAE9F;;;GAGG;AACH,eAAO,MAAM,aAAa,UAEzB,CAAC;AAEF,eAAO,MAAM,kBAAkB,2KASrB,CAAC;AAaX,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,GAAE,OAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CA6f3F"}