@commissionsight/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.
Files changed (92) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +248 -0
  3. package/bin/cs.mjs +2 -0
  4. package/dist/commands/admin.d.ts +7 -0
  5. package/dist/commands/admin.js +409 -0
  6. package/dist/commands/auth.d.ts +7 -0
  7. package/dist/commands/auth.js +107 -0
  8. package/dist/commands/batch.d.ts +2 -0
  9. package/dist/commands/batch.js +68 -0
  10. package/dist/commands/billing.d.ts +6 -0
  11. package/dist/commands/billing.js +75 -0
  12. package/dist/commands/carrier.d.ts +6 -0
  13. package/dist/commands/carrier.js +111 -0
  14. package/dist/commands/completion.d.ts +6 -0
  15. package/dist/commands/completion.js +56 -0
  16. package/dist/commands/context.d.ts +6 -0
  17. package/dist/commands/context.js +73 -0
  18. package/dist/commands/file.d.ts +6 -0
  19. package/dist/commands/file.js +97 -0
  20. package/dist/commands/job.d.ts +2 -0
  21. package/dist/commands/job.js +186 -0
  22. package/dist/commands/member.d.ts +5 -0
  23. package/dist/commands/member.js +91 -0
  24. package/dist/commands/meta.d.ts +7 -0
  25. package/dist/commands/meta.js +36 -0
  26. package/dist/commands/rate.d.ts +5 -0
  27. package/dist/commands/rate.js +69 -0
  28. package/dist/commands/registry.d.ts +14 -0
  29. package/dist/commands/registry.js +56 -0
  30. package/dist/commands/report.d.ts +2 -0
  31. package/dist/commands/report.js +168 -0
  32. package/dist/commands/session.d.ts +5 -0
  33. package/dist/commands/session.js +21 -0
  34. package/dist/commands/team.d.ts +5 -0
  35. package/dist/commands/team.js +61 -0
  36. package/dist/commands/upload.d.ts +85 -0
  37. package/dist/commands/upload.js +111 -0
  38. package/dist/commands/webhook.d.ts +5 -0
  39. package/dist/commands/webhook.js +56 -0
  40. package/dist/commands/workspace.d.ts +8 -0
  41. package/dist/commands/workspace.js +65 -0
  42. package/dist/config/schema.d.ts +21 -0
  43. package/dist/config/schema.js +33 -0
  44. package/dist/config/store.d.ts +17 -0
  45. package/dist/config/store.js +74 -0
  46. package/dist/context.d.ts +22 -0
  47. package/dist/context.js +100 -0
  48. package/dist/errors.d.ts +37 -0
  49. package/dist/errors.js +70 -0
  50. package/dist/globals.d.ts +10 -0
  51. package/dist/globals.js +38 -0
  52. package/dist/io.d.ts +28 -0
  53. package/dist/io.js +28 -0
  54. package/dist/lib/batch.d.ts +52 -0
  55. package/dist/lib/batch.js +0 -0
  56. package/dist/lib/confirm.d.ts +2 -0
  57. package/dist/lib/confirm.js +23 -0
  58. package/dist/lib/file.d.ts +6 -0
  59. package/dist/lib/file.js +43 -0
  60. package/dist/lib/input.d.ts +2 -0
  61. package/dist/lib/input.js +35 -0
  62. package/dist/lib/paginate.d.ts +33 -0
  63. package/dist/lib/paginate.js +47 -0
  64. package/dist/lib/period.d.ts +15 -0
  65. package/dist/lib/period.js +43 -0
  66. package/dist/lib/poll.d.ts +14 -0
  67. package/dist/lib/poll.js +17 -0
  68. package/dist/lib/resolve.d.ts +30 -0
  69. package/dist/lib/resolve.js +81 -0
  70. package/dist/main.d.ts +1 -0
  71. package/dist/main.js +17 -0
  72. package/dist/output/color.d.ts +26 -0
  73. package/dist/output/color.js +37 -0
  74. package/dist/output/csv.d.ts +25 -0
  75. package/dist/output/csv.js +119 -0
  76. package/dist/output/envelope.d.ts +29 -0
  77. package/dist/output/envelope.js +66 -0
  78. package/dist/output/help.d.ts +7 -0
  79. package/dist/output/help.js +57 -0
  80. package/dist/output/print.d.ts +14 -0
  81. package/dist/output/print.js +70 -0
  82. package/dist/output/schema-tree.d.ts +32 -0
  83. package/dist/output/schema-tree.js +33 -0
  84. package/dist/router.d.ts +6 -0
  85. package/dist/router.js +267 -0
  86. package/dist/types.d.ts +66 -0
  87. package/dist/types.js +1 -0
  88. package/dist/util.d.ts +11 -0
  89. package/dist/util.js +39 -0
  90. package/dist/version.d.ts +2 -0
  91. package/dist/version.js +41 -0
  92. package/package.json +53 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) CommissionSight
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,248 @@
1
+ # @commissionsight/cli
2
+
3
+ Command-line interface for the [CommissionSight](https://commissionsight.com) API
4
+ — authentication, workspace selection, and statement uploads for **any carrier,
5
+ any period, in any workspace**. A thin, faithful wrapper over
6
+ [`@commissionsight/sdk`](https://www.npmjs.com/package/@commissionsight/sdk).
7
+
8
+ It is designed to be driven by **humans and by AI coding agents** (Claude Code,
9
+ Cursor, etc.) running locally: every command is fully non-interactive, supports
10
+ machine-readable `--json` output, and returns deterministic exit codes.
11
+
12
+ ```bash
13
+ npm install -g @commissionsight/cli
14
+ cs --version
15
+ ```
16
+
17
+ Binaries: `cs` (and the alias `commissionsight`). Requires **Node ≥ 20**.
18
+
19
+ ---
20
+
21
+ ## Quick start
22
+
23
+ ```bash
24
+ # 1. Authenticate (token issued by CommissionSight; piped, never in argv)
25
+ printf '%s' "$COMMISSIONSIGHT_TOKEN" | cs auth login --token-stdin
26
+ cs auth status # verifies via me()
27
+
28
+ # 2. Pick a workspace (only needed on multi-workspace accounts)
29
+ cs workspace list
30
+ cs workspace use "Main Book"
31
+
32
+ # 3. Upload a statement — any carrier, any period, any workspace
33
+ cs upload ./aetna-2026-05.xlsx --carrier aetna --period 2026-05 --wait --results --json
34
+
35
+ # 4. Bulk upload a folder (idempotent, resumable, mixed carriers/periods)
36
+ cs upload batch ./statements --workspace "Main Book" --wait --report ./ingest.json
37
+ ```
38
+
39
+ ---
40
+
41
+ ## Using this CLI from an AI agent (Claude Code, etc.)
42
+
43
+ This section is the contract an autonomous agent should rely on. Everything here
44
+ is stable and machine-checkable.
45
+
46
+ ### 1. Discover the surface programmatically — don't guess
47
+
48
+ ```bash
49
+ cs schema --json
50
+ ```
51
+
52
+ Returns the **entire** command/flag tree as JSON: every command, its positional
53
+ args (with `required`/`variadic`), and every option (`type`, `short`, `desc`,
54
+ `choices`, `default`). Parse this instead of memorizing commands. Shape:
55
+
56
+ ```json
57
+ {
58
+ "ok": true,
59
+ "data": {
60
+ "name": "cs",
61
+ "version": "0.1.0",
62
+ "globalOptions": [ { "flag": "json", "type": "boolean", "desc": "…" }, … ],
63
+ "commands": [
64
+ {
65
+ "command": "upload",
66
+ "path": ["upload"],
67
+ "summary": "Upload a statement for a carrier + period",
68
+ "args": [ { "name": "file", "required": true, "variadic": false } ],
69
+ "options": [ { "flag": "carrier", "type": "string", "desc": "…" }, … ]
70
+ },
71
+
72
+ ]
73
+ }
74
+ }
75
+ ```
76
+
77
+ ### 2. Always pass `--json` — parse only stdout
78
+
79
+ In `--json` mode, **stdout carries exactly one JSON value: the envelope.** All
80
+ human chrome (spinners, progress, warnings) goes to **stderr**. So an agent can
81
+ safely `JSON.parse(stdout)` without stripping anything.
82
+
83
+ - **Success** (exit 0):
84
+ ```json
85
+ { "ok": true, "data": <command result> }
86
+ ```
87
+ - **Failure** (nonzero exit):
88
+ ```json
89
+ { "ok": false, "error": { "status": 409, "code": "period_exists", "message": "…", "body": { … } } }
90
+ ```
91
+
92
+ `error.code` is a stable slug derived from the API's problem+json body
93
+ (`period_exists`, `already_retracted`, …) or `null`. Branch on `error.code` /
94
+ `error.status`, not on `message` text.
95
+
96
+ ### 3. Use exit codes for control flow
97
+
98
+ | Code | Meaning | Typical agent reaction |
99
+ |---|---|---|
100
+ | 0 | Success | continue |
101
+ | 1 | Unexpected/internal error (incl. a job that finished `failed`) | inspect `error.message`; surface to user |
102
+ | 2 | Usage error (bad flags/args) | fix the invocation |
103
+ | 3 | Auth error (401/403) | token missing/invalid/insufficient — re-auth |
104
+ | 4 | Not found (404) | the id/ref doesn't exist |
105
+ | 5 | Conflict (409), e.g. `period_exists` | retry with `--replace` |
106
+ | 6 | Validation (400/422) | inputs rejected; read `error.body` |
107
+ | 7 | Rate limited (429) | back off and retry |
108
+ | 124 | Timeout (`--wait` exceeded `--timeout`) | poll again or raise `--timeout` |
109
+
110
+ ### 4. Stay non-interactive
111
+
112
+ - **Token**: prefer `COMMISSIONSIGHT_TOKEN` in the environment, or
113
+ `--token-stdin` (pipe it). Avoid `--token <t>` — it lands in process listings
114
+ and shell history.
115
+ - **Destructive ops** (`file retract|purge`, `team remove`, `rate delete`,
116
+ `webhook delete`, `admin … purge-files`, `admin user delete`) require `--yes`
117
+ / `-y` when there's no TTY. Without it they exit `2` and perform nothing.
118
+ - **Carrier refs** accept an id, slug, or case-insensitive name; an ambiguous
119
+ name exits `2` and lists candidates on stderr.
120
+ - **Periods** are `--period YYYY-MM` (or `--year` + `--month`).
121
+
122
+ ### 5. Idempotency makes retries safe
123
+
124
+ `cs upload` derives an idempotency key per file
125
+ (`<context>-<carrierSlug>-<period>-<sha8(file)>`). Re-running the same upload or
126
+ the same `upload batch` is safe and **resumable**: already-ingested
127
+ carrier+periods come back as `skipped`, not duplicated. Override with
128
+ `--idempotency-key` if you need to.
129
+
130
+ ### 6. Recipes
131
+
132
+ ```bash
133
+ # Upload and block until scored, get rows back as JSON in one call
134
+ cs upload ./uhc-2026-05.csv --carrier uhc --period 2026-05 \
135
+ --wait --results --json
136
+ # → data.upload.{jobId,fileId}, data.results[] (scored ResultRows)
137
+
138
+ # Handle "period already exists" deterministically
139
+ cs upload ./aetna-2026-05.xlsx --carrier aetna --period 2026-05 --json
140
+ # exit 5 + error.code=period_exists → re-run with --replace:
141
+ cs upload ./aetna-2026-05.xlsx --carrier aetna --period 2026-05 --replace --json
142
+
143
+ # Bulk ingest a directory, keep going past failures, write a machine report
144
+ cs upload batch ./statements --continue-on-error --report ./out.json --json
145
+ # data.{total,uploaded,replaced,skipped,failed,unmatched,outcomes[]}
146
+
147
+ # Pull a full month rollup as JSON, or export rows as CSV
148
+ cs report rollup --period 2026-05 --json
149
+ cs job results <jobId> --all --csv -o ./scored.csv
150
+
151
+ # Export exception (rejected) rows for a job
152
+ cs job exceptions <jobId> -o ./exceptions.csv # exit 4 if none/purged
153
+
154
+ # Audit a single member across every period
155
+ cs member journey <memberRefId> --json
156
+ ```
157
+
158
+ ### 7. Multiple environments
159
+
160
+ Contexts bundle a base URL + token + default workspace. Switch with
161
+ `--context <name>` on any command, or set the active one:
162
+
163
+ ```bash
164
+ cs context add staging --base-url https://staging.api.commissionsight.com/v1
165
+ printf '%s' "$STAGING_TOKEN" | cs context add staging --token-stdin
166
+ cs context use staging
167
+ ```
168
+
169
+ ---
170
+
171
+ ## Authentication & config
172
+
173
+ Auth is a per-account **API bearer token** issued by CommissionSight (there is no
174
+ email/password login in the API). Token resolution precedence (highest first):
175
+
176
+ 1. `--token <t>` (discouraged — visible in shell history)
177
+ 2. `--token-file <path>` / `--token-stdin` (preferred for scripts)
178
+ 3. `COMMISSIONSIGHT_TOKEN` env var
179
+ 4. active context token in the config file
180
+
181
+ Config lives at `${XDG_CONFIG_HOME:-~/.config}/commissionsight/config.json`
182
+ (dir `0700`, file `0600`). The token is never printed — `auth status` shows a
183
+ masked suffix (`…a1b2`). `--base-url` / `COMMISSIONSIGHT_BASE_URL` override the
184
+ API base (default `https://api.commissionsight.com/v1`).
185
+
186
+ ---
187
+
188
+ ## Global flags
189
+
190
+ | Flag | Purpose |
191
+ |---|---|
192
+ | `--json` (or `CS_OUTPUT=json`) | Emit only the envelope on stdout |
193
+ | `--quiet` / `-q` | Suppress human chrome |
194
+ | `--no-color` (or `NO_COLOR`) | Disable ANSI color |
195
+ | `--yes` / `-y` | Assume "yes" for destructive confirmations |
196
+ | `--token` / `--token-file` / `--token-stdin` | Token sources |
197
+ | `--base-url <url>` | Override API base URL |
198
+ | `--context <name>` | Use a named config context |
199
+ | `--help` / `-h`, `--version` / `-V` | Help / version |
200
+
201
+ ---
202
+
203
+ ## Command reference
204
+
205
+ 100 commands across these groups (run `cs <group> --help`, or `cs schema --json`
206
+ for the full machine-readable tree).
207
+
208
+ | Group | Commands |
209
+ |---|---|
210
+ | **Session** | `whoami` · `health` · `version` · `schema` · `completion bash\|zsh\|fish` |
211
+ | **Auth** | `auth login` · `auth status` · `auth logout` · `auth token issue` |
212
+ | **Context** | `context list\|current\|use\|add\|remove` |
213
+ | **Workspace** | `workspace list` · `workspace create <name>` · `workspace use <name\|id>` |
214
+ | **Carrier** | `carrier list` · `carrier get` · `carrier config list\|get\|create\|test\|infer` |
215
+ | **Upload** | `upload <file>` · `upload batch <target>` |
216
+ | **File** | `file list\|get\|rescore\|retract\|purge\|rescore-stale` |
217
+ | **Job** | `job list\|get\|wait\|results\|deltas\|exceptions\|retry` |
218
+ | **Member / Policy** | `member list\|get\|timeline\|journey\|last-seen` · `policy journey` |
219
+ | **Team / Audit** | `team list\|invite\|remove` · `audit list` |
220
+ | **Reports** | `report rollup\|compare\|attrition\|attrition-series\|data-quality\|chargebacks` |
221
+ | **Rates** | `rate list\|set\|delete` |
222
+ | **Webhooks** | `webhook list\|create\|delete` |
223
+ | **Billing** | `billing get\|preview\|update` |
224
+ | **Admin** | `admin account *` · `admin token *` · `admin carrier *` · `admin user *` · `admin job *` · `admin allowlist add` · `admin metrics\|logs\|revenue\|cron-runs` |
225
+
226
+ List commands accept `--limit`, `--all` (auto-paginate), and `--offset` or
227
+ `--cursor` as appropriate; result/report commands accept `--csv` (with `-o` to
228
+ write a file). Reports take `--period`/`--carrier`/`--from`/`--to` as listed in
229
+ `--help`.
230
+
231
+ ### Notes & limitations
232
+
233
+ - **Workspace creation** (`cs workspace create <name>`) requires
234
+ `@commissionsight/sdk` **≥ 2.3.0** (`createWorkspace` → `POST /workspaces`).
235
+ The command is capability-gated: on an older SDK it fails with a clear,
236
+ actionable message instead of silently no-opping.
237
+ - **Report workspace scoping**: the API documents an optional `?workspaceId` on
238
+ reports, but the SDK's report methods do not yet accept it, so `cs report *`
239
+ omits `--workspace`. As a thin wrapper the CLI never bypasses the SDK; this
240
+ lands when the SDK exposes the parameter.
241
+ - **Stripe payment-method / setup-intent** flows are web-app only and out of
242
+ scope; use `cs billing get/preview/update` for billing details.
243
+
244
+ ---
245
+
246
+ ## License
247
+
248
+ MIT © CommissionSight
package/bin/cs.mjs ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import('../dist/main.js').then((m) => m.run(process.argv.slice(2)));
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Admin namespace (plan §6.12) — maps the entire `client.admin.*` surface 1:1.
3
+ * Every call is wrapped by `adminGate`, which turns a 401/403 into exit 3 with
4
+ * an "admin token required" message so non-admin tokens fail clearly.
5
+ */
6
+ import type { Cmd } from '../types.js';
7
+ export declare function adminCommands(): Cmd[];