@sentinelconnector/cli 0.0.0-stage → 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 (77) hide show
  1. package/LICENSE +11 -0
  2. package/README.md +218 -2
  3. package/dist/api/client.d.ts +63 -0
  4. package/dist/api/client.js +115 -0
  5. package/dist/api/client.js.map +1 -0
  6. package/dist/api/config.d.ts +21 -0
  7. package/dist/api/config.js +62 -0
  8. package/dist/api/config.js.map +1 -0
  9. package/dist/api/errors.d.ts +34 -0
  10. package/dist/api/errors.js +92 -0
  11. package/dist/api/errors.js.map +1 -0
  12. package/dist/api/http.d.ts +24 -0
  13. package/dist/api/http.js +60 -0
  14. package/dist/api/http.js.map +1 -0
  15. package/dist/auth/credentials.d.ts +48 -0
  16. package/dist/auth/credentials.js +144 -0
  17. package/dist/auth/credentials.js.map +1 -0
  18. package/dist/auth/deviceFlow.d.ts +52 -0
  19. package/dist/auth/deviceFlow.js +106 -0
  20. package/dist/auth/deviceFlow.js.map +1 -0
  21. package/dist/auth/lock.d.ts +2 -0
  22. package/dist/auth/lock.js +86 -0
  23. package/dist/auth/lock.js.map +1 -0
  24. package/dist/auth/store.d.ts +87 -0
  25. package/dist/auth/store.js +281 -0
  26. package/dist/auth/store.js.map +1 -0
  27. package/dist/bin.d.ts +2 -0
  28. package/dist/bin.js +8 -0
  29. package/dist/bin.js.map +1 -0
  30. package/dist/cli.d.ts +11 -0
  31. package/dist/cli.js +111 -0
  32. package/dist/cli.js.map +1 -0
  33. package/dist/commands/mergeChecks.d.ts +9 -0
  34. package/dist/commands/mergeChecks.js +57 -0
  35. package/dist/commands/mergeChecks.js.map +1 -0
  36. package/dist/commands/routes.d.ts +21 -0
  37. package/dist/commands/routes.js +306 -0
  38. package/dist/commands/routes.js.map +1 -0
  39. package/dist/commands/session.d.ts +44 -0
  40. package/dist/commands/session.js +137 -0
  41. package/dist/commands/session.js.map +1 -0
  42. package/dist/context.d.ts +31 -0
  43. package/dist/context.js +42 -0
  44. package/dist/context.js.map +1 -0
  45. package/dist/journeys/mergeChecks.d.ts +70 -0
  46. package/dist/journeys/mergeChecks.js +127 -0
  47. package/dist/journeys/mergeChecks.js.map +1 -0
  48. package/dist/mcp/main.d.ts +13 -0
  49. package/dist/mcp/main.js +39 -0
  50. package/dist/mcp/main.js.map +1 -0
  51. package/dist/mcp/server.d.ts +181 -0
  52. package/dist/mcp/server.js +282 -0
  53. package/dist/mcp/server.js.map +1 -0
  54. package/dist/mcp/untrusted.d.ts +38 -0
  55. package/dist/mcp/untrusted.js +125 -0
  56. package/dist/mcp/untrusted.js.map +1 -0
  57. package/dist/mcp.d.ts +2 -0
  58. package/dist/mcp.js +7 -0
  59. package/dist/mcp.js.map +1 -0
  60. package/dist/mfa.d.ts +12 -0
  61. package/dist/mfa.js +29 -0
  62. package/dist/mfa.js.map +1 -0
  63. package/dist/prompt.d.ts +4 -0
  64. package/dist/prompt.js +54 -0
  65. package/dist/prompt.js.map +1 -0
  66. package/dist/routes/call.d.ts +26 -0
  67. package/dist/routes/call.js +120 -0
  68. package/dist/routes/call.js.map +1 -0
  69. package/dist/routes/catalogue.d.ts +47 -0
  70. package/dist/routes/catalogue.js +69 -0
  71. package/dist/routes/catalogue.js.map +1 -0
  72. package/dist/routes/routes.json +11367 -0
  73. package/dist/skill.d.ts +13 -0
  74. package/dist/skill.js +61 -0
  75. package/dist/skill.js.map +1 -0
  76. package/package.json +40 -4
  77. package/skills/sentinel/SKILL.md +150 -0
package/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Copyright (c) 2026 TrueCMS Pty. Ltd. (ABN 63 133 456 005). All rights reserved.
2
+
3
+ This software is proprietary. It is not open source and no licence to it is
4
+ granted except as follows: you may install and use it only to access the
5
+ Sentinel Connector service, and only under the Sentinel Connector Terms of
6
+ Service (https://sentinelconnector.io/terms). You may not copy, modify,
7
+ distribute, sublicense or reverse engineer it, except as those Terms or the
8
+ law expressly allow.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, TO THE EXTENT
11
+ THE LAW ALLOWS. THE TERMS OF SERVICE GOVERN ANY LIABILITY.
package/README.md CHANGED
@@ -1,3 +1,219 @@
1
- # Temporary Holding Version
1
+ # @sentinelconnector/cli
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
+ The Sentinel command-line tool (`sentinel`) and MCP server (`sentinel-mcp`)
4
+ for customers: your organisations, sites, findings, reports and Patching, from
5
+ a terminal or an AI agent. Epic truecms/sentinel#1618. The server contract is
6
+ `docs/PUBLIC_CLI_MCP.md` in truecms/sentinel.
7
+
8
+ > **Not open to customers yet.** The package is published ahead of the
9
+ > service. Until Sentinel turns the customer CLI on, `sentinel login` and every
10
+ > command answer 404 (Not Found).
11
+
12
+ - Node.js 20.10 or later, TypeScript (ESM).
13
+ - Proprietary: `UNLICENSED`, all rights reserved; use is allowed only under
14
+ the Sentinel Connector Terms of Service (see `LICENSE`).
15
+ - Published as `@sentinelconnector/cli` once the owner set-up in "Releasing"
16
+ is done; until then, install from a checkout with
17
+ `npm install && npm run build -w @sentinelconnector/cli && npm link -w @sentinelconnector/cli`.
18
+ - Self-contained: nothing here imports the admin package, and
19
+ `npm run pack:check` fails when the packed files would hold an admin file,
20
+ the admin schema or an admin route. Run it before any release.
21
+ - The server must have `PUBLIC_CLI_ENABLED` on. While it is off, every route
22
+ below answers 404.
23
+
24
+ ## Signing in
25
+
26
+ ```bash
27
+ sentinel login # browser sign-in, reads only
28
+ sentinel login --write # ask to allow changes; tick "Allow changes" and confirm with your code
29
+ sentinel whoami
30
+ sentinel logout # the server ends the sign-in
31
+ ```
32
+
33
+ The sign-in is the OAuth 2.0 device flow. The CLI prints a link and a code
34
+ and opens the browser when it can. Over SSH, or with `--no-browser`, open the
35
+ link on any device. A sign-in is kept per API URL in the OS keychain, or in an
36
+ AES-256-GCM encrypted file (mode 0600) when there is no keychain. Its 15-minute
37
+ access token renews itself, and the sign-in ends after 30 days unused or 90
38
+ days at most.
39
+
40
+ | Variable | Use |
41
+ | --- | --- |
42
+ | `SENTINEL_API_URL` | Another API than production (`https://api.sentinelconnector.io`), such as UAT. https only, except localhost |
43
+ | `SENTINEL_TOKEN` | A personal API token (`snt_pat_…`) from the dashboard (Profile, API tokens). Wins over a stored sign-in: for scripts, CI and a headless MCP host |
44
+ | `SENTINEL_ENVIRONMENT` | The environment you expect (`uat`, `production`). The CLI stops after the first call, before anything else is sent, when the server is another one |
45
+ | `SENTINEL_DASHBOARD_URL` | The dashboard's address, for links to steps only a person can take. Learned at `login` otherwise |
46
+ | `SENTINEL_CREDENTIAL_STORE` | `keychain` or `file` to force a store |
47
+ | `SENTINEL_CREDENTIALS_PASSPHRASE` | Passphrase for the encrypted file when there is no keychain (otherwise you are asked) |
48
+ | `SENTINEL_CONFIG_DIR` | Where the encrypted file and lock files live (default `~/.config/sentinel`) |
49
+
50
+ Credentials are never accepted as arguments and never printed. The keychain
51
+ entries and the config folder are not the admin CLI's.
52
+
53
+ ## Commands
54
+
55
+ Every customer route that has a CLI policy in truecms/sentinel
56
+ `app/core/cli_routes.py` is a command, grouped by its first path segment and
57
+ named after its handler:
58
+
59
+ ```bash
60
+ sentinel routes site certificate # find a command by words
61
+ sentinel sites read-site <site-uuid> # JSON answer; --out file.json to save it
62
+ sentinel api GET /api/v1/sites/ # any customer route by path, even one this build does not know
63
+ ```
64
+
65
+ Path parameters are positional. Query parameters and body fields are
66
+ `--kebab-case` options. A field named like one of the CLI's own options gets a
67
+ `query-` or `body-` prefix. `--body '<json>'` or `--body-file` sets the whole
68
+ body.
69
+
70
+ | Policy | What the CLI does |
71
+ | --- | --- |
72
+ | `read` | Calls it |
73
+ | `write` | Names the environment, API and person, shows the call and asks first (`--yes` for scripts) |
74
+ | `mfa` | As `write`, then asks for your authenticator or recovery code and sends the step-up token. Needs `sentinel login` and a terminal. A personal token is refused before anything is sent |
75
+ | `browser`, `dashboard_only` | Sends nothing and gives the dashboard link |
76
+
77
+ ### Required checks (truecms/sentinel#1930)
78
+
79
+ ```bash
80
+ sentinel patching merge-checks show <site-uuid>
81
+ sentinel patching merge-checks acknowledge <site-uuid>
82
+ ```
83
+
84
+ `show` reads the repository's required checks from the Git host now, and says
85
+ whether the acknowledgement is current. Rules that could not be read are
86
+ "unknown", never "none".
87
+
88
+ `acknowledge` is for an organisation administrator. It reads the host again,
89
+ says what Autopilot will do:
90
+
91
+ - with required checks, it merges when each one passed, whatever else failed;
92
+ - with none, it merges even when CI fails.
93
+
94
+ The person types `acknowledge` and their code. The CLI then sends exactly what
95
+ was shown, so a host that changed meanwhile answers 409 `merge_checks_changed`.
96
+
97
+ The routes leave the served schema while `PATCHING_MERGE_CHECKS_ENABLED` is
98
+ off, and answer 404.
99
+
100
+ | Exit code | Meaning |
101
+ | --- | --- |
102
+ | 0 | Done |
103
+ | 1 | Error |
104
+ | 2 | Usage error, or a change asked without a terminal or `--yes` |
105
+ | 3 | Network failure |
106
+ | 4 | Not signed in, or the sign-in or token stopped working |
107
+ | 5 | Wrong environment |
108
+ | 10 | Refused: by the server, a declined prompt, or a step for a person or the dashboard |
109
+ | 13 | A change got no answer and may have been made: check before trying again |
110
+
111
+ ## MCP server (`sentinel-mcp`)
112
+
113
+ An MCP server over stdio for an AI agent acting as you. It uses
114
+ `SENTINEL_TOKEN` when set, otherwise your `sentinel login` sign-in for
115
+ `SENTINEL_API_URL`.
116
+
117
+ ```bash
118
+ claude mcp add sentinel --env SENTINEL_TOKEN=snt_pat_… -- sentinel-mcp
119
+ ```
120
+
121
+ | Tool | Does |
122
+ | --- | --- |
123
+ | `sentinel_find` | Finds operations by words, with their policy |
124
+ | `sentinel_describe` | One operation's parameters and body fields |
125
+ | `sentinel_read` | Runs a `read` operation |
126
+ | `sentinel_change` | Runs a `write` operation. The first call only returns what would be sent; `confirm: true` sends it |
127
+ | `patching_merge_checks_read` | A site's required checks and acknowledgement state, with the dashboard link to acknowledge |
128
+
129
+ `mfa`, `browser` and `dashboard_only` operations are never run: the tool
130
+ returns the dashboard link for the person, and the agent is told never to ask
131
+ for or pass on a code. Every answer goes back inside an
132
+ `<untrusted-data nonce="…">` block with secret-named fields blanked and
133
+ credentials redacted.
134
+
135
+ The server also serves the skill as the `sentinel` prompt and the
136
+ `sentinel://skill` resource.
137
+
138
+ ## The skill
139
+
140
+ `skills/sentinel/SKILL.md` (Agent Skills format) explains the platform,
141
+ the safe order for common jobs, what needs a person, and how to read errors.
142
+ It names features and journeys, not routes.
143
+
144
+ ```bash
145
+ sentinel skill install # ~/.claude/skills/sentinel and ~/.codex/skills/sentinel
146
+ sentinel skill show
147
+ ```
148
+
149
+ Project rule (truecms/sentinel `CLAUDE.md`): when a customer journey changes,
150
+ update the skill here in the same release and link the pull requests.
151
+
152
+ ## Updating the routes
153
+
154
+ `src/routes/routes.json` is generated. Export Sentinel's OpenAPI with the
155
+ release flags of the routes you need on, and the route policies, then:
156
+
157
+ ```bash
158
+ npm run routes:update -w @sentinelconnector/cli -- <openapi.json> <policies.json>
159
+ ```
160
+
161
+ `<policies.json>` is `GET /api/v1/account/cli/routes`, or
162
+ `cli_routes.listing()` on the server. Only routes with a policy are kept, so
163
+ no admin route can reach this package, and the script fails if one has a
164
+ policy. It writes `openapi/customer.json` (not published) and
165
+ `src/routes/routes.json`. It lists routes the server has a policy for but the
166
+ schema did not serve. Those are behind a flag that was off: they still work
167
+ through `sentinel api`.
168
+
169
+ Before publishing, regenerate from a schema with only released features on,
170
+ so the package does not name unreleased routes, and write the flags that were
171
+ on in `CHANGELOG.md`. Export from the Sentinel commit being released, with
172
+ `PUBLIC_CLI_ENABLED` and the flags production has on; `cli_routes.listing()`
173
+ gives the policies. Routes left out still work through `sentinel api`, and
174
+ the guided commands (such as `sentinel patching merge-checks`) stay in the
175
+ package; the server answers 404 until their feature is on.
176
+
177
+ When two routes in a group would get the same command name, routes under
178
+ different sub-paths are prefixed with it (`account cli-list-sessions` and
179
+ `account browser-extensions-list-sessions`).
180
+
181
+ ## Releasing
182
+
183
+ `.github/workflows/release-cli.yml` publishes this package, and only this
184
+ package, to npm with trusted publishing (OIDC): no npm token is stored, and
185
+ no provenance is made because the repository is private.
186
+
187
+ 1. Regenerate the routes from the released-only schema (above) and run
188
+ `npm run lint`, `npm test`, `npm run build -w @sentinelconnector/cli` and
189
+ `npm run pack:check -w @sentinelconnector/cli` at the repository root.
190
+ 2. Set the version in `packages/cli/package.json` and add its section to
191
+ `packages/cli/CHANGELOG.md`, with the flags the routes were built with.
192
+ 3. Merge to `main`, then push the tag `cli-v<version>` (or run the workflow
193
+ by hand on `main`).
194
+ 4. The `check` job lints, tests, builds, packs this package and runs
195
+ `pack:check` on the tarball itself: it fails on any admin file, admin
196
+ route, admin CLI path, `openapi/` file or admin credential name, and
197
+ on any tarball that is not `@sentinelconnector/cli`. A tag must match the
198
+ package version.
199
+ 5. The `publish` job runs in the `npm` environment (approval once required
200
+ reviewers are available, see below), checks the tarball name again and
201
+ publishes it.
202
+
203
+ The root package (the admin CLI) stays `"private": true` and the workflow
204
+ never packs it. This package is public on npm (`publishConfig.access`) but
205
+ proprietary (`UNLICENSED`, see `LICENSE`). Nothing is published until npm
206
+ trusts the workflow.
207
+
208
+ Owner set-up before the first release (name and licence are decided:
209
+ `@sentinelconnector/cli`, proprietary): configure trusted publishing for this package
210
+ on npm (the `@sentinelconnector` organisation, this repository, the workflow
211
+ file `release-cli.yml` and the environment `npm`); require 2FA for the
212
+ organisation's members. The `npm` environment exists and accepts deployments
213
+ only from `main` and `cli-v*` tags. GitHub offers required reviewers on a
214
+ private repository only on Enterprise, so until then the approval step is not
215
+ enforced: anyone who can push a `cli-v*` tag can publish.
216
+
217
+ npm adds a trusted publisher only to a package that exists, so the first
218
+ release (`0.1.0`) is published by hand by an organisation member with 2FA.
219
+ Later releases go through a `cli-v<version>` tag.
@@ -0,0 +1,63 @@
1
+ /**
2
+ * The Sentinel customer API client shared by the CLI and the MCP server.
3
+ *
4
+ * Every request carries the credential as a bearer token and names the client
5
+ * in X-Sentinel-Client (attribution only). Before the first call the client
6
+ * asks `GET /account/cli/whoami` which environment the server is, and stops
7
+ * when SENTINEL_ENVIRONMENT or the stored sign-in names another one. A 401
8
+ * from a CLI sign-in renews it once and retries. Errors are SentinelApiError,
9
+ * never containing the credential.
10
+ */
11
+ import type { Credential } from '../auth/credentials.js';
12
+ import { type Fetch, type HttpOptions } from './http.js';
13
+ export type SentinelClientName = 'cli' | 'mcp';
14
+ /** The step-up token from `POST /auth/mfa/step-up`, needed by `mfa` routes. */
15
+ export declare const MFA_TOKEN_HEADER = "X-MFA-Token";
16
+ export declare const WHOAMI_PATH = "/api/v1/account/cli/whoami";
17
+ export declare const ENVIRONMENT_PATH = "/api/v1/account/cli/environment";
18
+ export interface Whoami {
19
+ user: {
20
+ id: number;
21
+ email: string;
22
+ full_name: string | null;
23
+ };
24
+ environment: string;
25
+ credential: {
26
+ kind: 'cli_session' | 'personal_token';
27
+ id: number;
28
+ scopes: string[];
29
+ client: SentinelClientName;
30
+ expires_at: string;
31
+ } | null;
32
+ }
33
+ export interface ClientOptions {
34
+ apiUrl: string;
35
+ credential: Credential;
36
+ client?: SentinelClientName;
37
+ fetch?: Fetch;
38
+ timeoutMs?: number;
39
+ /** Where SENTINEL_ENVIRONMENT is read from (tests). */
40
+ env?: NodeJS.ProcessEnv;
41
+ }
42
+ export interface RequestOptions {
43
+ query?: Record<string, unknown>;
44
+ body?: unknown;
45
+ headers?: Record<string, string>;
46
+ }
47
+ export interface SentinelClient {
48
+ readonly apiUrl: string;
49
+ readonly credential: Credential;
50
+ readonly http: HttpOptions;
51
+ /** The signed-in person and environment, asked once. */
52
+ whoami(): Promise<Whoami>;
53
+ /** One call; `path` starts with /api/v1. Throws SentinelApiError on a non-2xx answer. */
54
+ request<T = unknown>(method: string, path: string, options?: RequestOptions): Promise<T>;
55
+ }
56
+ /**
57
+ * The deployment's name from the public, credential-free environment route,
58
+ * or undefined when the server does not answer it (a network rule may close
59
+ * it). It is the same route the admin CLI reads; it takes no credential and
60
+ * returns only the name.
61
+ */
62
+ export declare function environmentOf(apiUrl: string, http: HttpOptions): Promise<string | undefined>;
63
+ export declare function createSentinelClient(options: ClientOptions): SentinelClient;
@@ -0,0 +1,115 @@
1
+ import { ENVIRONMENT_ENV } from './config.js';
2
+ import { EnvironmentMismatchError, errorFromResponse } from './errors.js';
3
+ import { CLIENT_HEADER, DEFAULT_TIMEOUT_MS, send } from './http.js';
4
+ /** The step-up token from `POST /auth/mfa/step-up`, needed by `mfa` routes. */
5
+ export const MFA_TOKEN_HEADER = 'X-MFA-Token';
6
+ export const WHOAMI_PATH = '/api/v1/account/cli/whoami';
7
+ export const ENVIRONMENT_PATH = '/api/v1/account/cli/environment';
8
+ function queryString(query) {
9
+ if (!query)
10
+ return '';
11
+ const params = new URLSearchParams();
12
+ for (const [name, value] of Object.entries(query)) {
13
+ if (value === undefined || value === null)
14
+ continue;
15
+ for (const item of Array.isArray(value) ? value : [value])
16
+ params.append(name, String(item));
17
+ }
18
+ const text = params.toString();
19
+ return text ? `?${text}` : '';
20
+ }
21
+ /**
22
+ * The deployment's name from the public, credential-free environment route,
23
+ * or undefined when the server does not answer it (a network rule may close
24
+ * it). It is the same route the admin CLI reads; it takes no credential and
25
+ * returns only the name.
26
+ */
27
+ export async function environmentOf(apiUrl, http) {
28
+ try {
29
+ const response = await send(new Request(`${apiUrl}${ENVIRONMENT_PATH}`, { headers: { Accept: 'application/json' } }), http);
30
+ if (!response.ok)
31
+ return undefined;
32
+ const body = (await response.json());
33
+ return typeof body.environment === 'string' ? body.environment : undefined;
34
+ }
35
+ catch {
36
+ return undefined;
37
+ }
38
+ }
39
+ export function createSentinelClient(options) {
40
+ const { apiUrl, credential } = options;
41
+ const http = { fetch: options.fetch, timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS };
42
+ const env = options.env ?? process.env;
43
+ const raw = async (method, path, request = {}) => {
44
+ const build = async () => {
45
+ const headers = new Headers({ Accept: 'application/json', ...request.headers });
46
+ headers.set('Authorization', `Bearer ${await credential.accessToken()}`);
47
+ headers.set(CLIENT_HEADER, options.client ?? 'cli');
48
+ let body;
49
+ if (request.body !== undefined) {
50
+ headers.set('Content-Type', 'application/json');
51
+ body = JSON.stringify(request.body);
52
+ }
53
+ return new Request(`${apiUrl}${path}${queryString(request.query)}`, { method, headers, body });
54
+ };
55
+ const response = await send(await build(), http);
56
+ if (response.status === 401 && (await credential.renew()))
57
+ return send(await build(), http);
58
+ return response;
59
+ };
60
+ const expectedEnvironment = env[ENVIRONMENT_ENV]?.trim() || credential.environment;
61
+ const check = (actual) => {
62
+ const expected = env[ENVIRONMENT_ENV]?.trim();
63
+ if (expected && expected !== actual)
64
+ throw new EnvironmentMismatchError(expected, actual);
65
+ if (credential.environment && credential.environment !== actual) {
66
+ throw new EnvironmentMismatchError(credential.environment, actual);
67
+ }
68
+ };
69
+ let me;
70
+ const whoami = () => {
71
+ me ??= (async () => {
72
+ if (expectedEnvironment) {
73
+ // Before any credential leaves the machine: the server's name, asked
74
+ // without one. A server that does not answer it is checked below,
75
+ // after whoami.
76
+ const named = await environmentOf(apiUrl, http);
77
+ if (named)
78
+ check(named);
79
+ }
80
+ const response = await raw('GET', WHOAMI_PATH);
81
+ if (!response.ok)
82
+ throw await errorFromResponse(response);
83
+ const answer = (await response.json());
84
+ check(answer.environment);
85
+ return answer;
86
+ })().catch((error) => {
87
+ me = undefined;
88
+ throw error;
89
+ });
90
+ return me;
91
+ };
92
+ return {
93
+ apiUrl,
94
+ credential,
95
+ http,
96
+ whoami,
97
+ async request(method, path, request = {}) {
98
+ // Nothing else is sent until the server proved it is the right environment.
99
+ await whoami();
100
+ const response = await raw(method, path, request);
101
+ if (!response.ok)
102
+ throw await errorFromResponse(response);
103
+ if (response.status === 204)
104
+ return undefined;
105
+ const type = response.headers.get('Content-Type') ?? '';
106
+ if (type.includes('json'))
107
+ return (await response.json());
108
+ // A text file (CSV export) as text; anything else (PDF, images) as bytes.
109
+ if (/^text\//.test(type))
110
+ return (await response.text());
111
+ return new Uint8Array(await response.arrayBuffer());
112
+ },
113
+ };
114
+ }
115
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAgC,IAAI,EAAE,MAAM,WAAW,CAAC;AAGlG,+EAA+E;AAC/E,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAC;AAC9C,MAAM,CAAC,MAAM,WAAW,GAAG,4BAA4B,CAAC;AACxD,MAAM,CAAC,MAAM,gBAAgB,GAAG,iCAAiC,CAAC;AAwClE,SAAS,WAAW,CAAC,KAA0C;IAC7D,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;IACrC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAClD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;YAAE,SAAS;QACpD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/F,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAC/B,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AAChC,CAAC;AAED;;;;;GA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1D,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;gBAAE,OAAO,SAAc,CAAC;YACnD,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC;YACxD,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAAE,OAAO,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAM,CAAC;YAC/D,0EAA0E;YAC1E,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;gBAAE,OAAO,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAM,CAAC;YAC9D,OAAO,IAAI,UAAU,CAAC,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAM,CAAC;QAC3D,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,21 @@
1
+ export declare const API_URL_ENV = "SENTINEL_API_URL";
2
+ /** A personal API token (`snt_pat_…`) for scripts, CI and a headless MCP host. */
3
+ export declare const TOKEN_ENV = "SENTINEL_TOKEN";
4
+ /** Optional: the environment the caller expects, such as `production`. */
5
+ export declare const ENVIRONMENT_ENV = "SENTINEL_ENVIRONMENT";
6
+ export declare const CONFIG_DIR_ENV = "SENTINEL_CONFIG_DIR";
7
+ /** The dashboard's address, for links to steps only a person can take there. */
8
+ export declare const DASHBOARD_URL_ENV = "SENTINEL_DASHBOARD_URL";
9
+ /** Sentinel's production API: customers need not set anything. */
10
+ export declare const DEFAULT_API_URL = "https://api.sentinelconnector.io";
11
+ /**
12
+ * The API origin, such as `https://api.example.com`. Accepts the URL with or
13
+ * without `/api/v1` and a trailing slash. Only https, except for localhost, so
14
+ * a credential never crosses the network in clear text.
15
+ */
16
+ export declare function normalizeApiUrl(value: string): string;
17
+ /** The API URL from `--api-url`, then SENTINEL_API_URL, then production. */
18
+ export declare function resolveApiUrl(option: string | undefined, env?: NodeJS.ProcessEnv): string;
19
+ /** A dashboard origin from a setting or a sign-in link; undefined when it is not one. */
20
+ export declare function dashboardOrigin(value: string | undefined): string | undefined;
21
+ export declare function configDir(env?: NodeJS.ProcessEnv): string;
@@ -0,0 +1,62 @@
1
+ /** Where the CLI talks to and where it keeps its files. */
2
+ import { homedir } from 'node:os';
3
+ import { join } from 'node:path';
4
+ import { SentinelError } from './errors.js';
5
+ export const API_URL_ENV = 'SENTINEL_API_URL';
6
+ /** A personal API token (`snt_pat_…`) for scripts, CI and a headless MCP host. */
7
+ export const TOKEN_ENV = 'SENTINEL_TOKEN';
8
+ /** Optional: the environment the caller expects, such as `production`. */
9
+ export const ENVIRONMENT_ENV = 'SENTINEL_ENVIRONMENT';
10
+ export const CONFIG_DIR_ENV = 'SENTINEL_CONFIG_DIR';
11
+ /** The dashboard's address, for links to steps only a person can take there. */
12
+ export const DASHBOARD_URL_ENV = 'SENTINEL_DASHBOARD_URL';
13
+ /** Sentinel's production API: customers need not set anything. */
14
+ export const DEFAULT_API_URL = 'https://api.sentinelconnector.io';
15
+ /**
16
+ * The API origin, such as `https://api.example.com`. Accepts the URL with or
17
+ * without `/api/v1` and a trailing slash. Only https, except for localhost, so
18
+ * a credential never crosses the network in clear text.
19
+ */
20
+ export function normalizeApiUrl(value) {
21
+ let url;
22
+ try {
23
+ url = new URL(value.trim());
24
+ }
25
+ catch {
26
+ throw new SentinelError(`${API_URL_ENV} is not a URL: ${value}`, 2);
27
+ }
28
+ const local = ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname) || url.hostname.endsWith('.localhost');
29
+ if (url.protocol !== 'https:' && !(url.protocol === 'http:' && local)) {
30
+ throw new SentinelError(`${API_URL_ENV} must use https:// (http:// only for localhost).`, 2);
31
+ }
32
+ if (url.username || url.password || url.search || url.hash) {
33
+ throw new SentinelError(`${API_URL_ENV} must not contain credentials, a query or a fragment.`, 2);
34
+ }
35
+ const path = url.pathname.replace(/\/+$/, '').replace(/\/api\/v1$/, '');
36
+ return `${url.origin}${path}`;
37
+ }
38
+ /** The API URL from `--api-url`, then SENTINEL_API_URL, then production. */
39
+ export function resolveApiUrl(option, env = process.env) {
40
+ return normalizeApiUrl(option ?? env[API_URL_ENV] ?? DEFAULT_API_URL);
41
+ }
42
+ /** A dashboard origin from a setting or a sign-in link; undefined when it is not one. */
43
+ export function dashboardOrigin(value) {
44
+ if (!value)
45
+ return undefined;
46
+ try {
47
+ const url = new URL(value);
48
+ const local = ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);
49
+ return url.protocol === 'https:' || (url.protocol === 'http:' && local) ? url.origin : undefined;
50
+ }
51
+ catch {
52
+ return undefined;
53
+ }
54
+ }
55
+ export function configDir(env = process.env) {
56
+ if (env[CONFIG_DIR_ENV])
57
+ return env[CONFIG_DIR_ENV];
58
+ if (process.platform === 'win32' && env.APPDATA)
59
+ return join(env.APPDATA, 'sentinel');
60
+ return join(env.XDG_CONFIG_HOME || join(homedir(), '.config'), 'sentinel');
61
+ }
62
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/api/config.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,MAAM,WAAW,GAAG,kBAAkB,CAAC;AAC9C,kFAAkF;AAClF,MAAM,CAAC,MAAM,SAAS,GAAG,gBAAgB,CAAC;AAC1C,0EAA0E;AAC1E,MAAM,CAAC,MAAM,eAAe,GAAG,sBAAsB,CAAC;AACtD,MAAM,CAAC,MAAM,cAAc,GAAG,qBAAqB,CAAC;AACpD,gFAAgF;AAChF,MAAM,CAAC,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AAE1D,kEAAkE;AAClE,MAAM,CAAC,MAAM,eAAe,GAAG,kCAAkC,CAAC;AAElE;;;;GAIG;AACH,MAAM,UAAU,eAAe,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yFAAyF;AACzF,MAAM,UAAU,eAAe,CAAC,KAAyB;IACvD,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;QAC3B,MAAM,KAAK,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACzE,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,CAAC,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IACnG,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,MAAyB,OAAO,CAAC,GAAG;IAC5D,IAAI,GAAG,CAAC,cAAc,CAAC;QAAE,OAAO,GAAG,CAAC,cAAc,CAAC,CAAC;IACpD,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IACtF,OAAO,IAAI,CAAC,GAAG,CAAC,eAAe,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,EAAE,UAAU,CAAC,CAAC;AAC7E,CAAC"}
@@ -0,0 +1,34 @@
1
+ /** Errors the API client raises. Messages never contain a credential. */
2
+ export declare class SentinelError extends Error {
3
+ /** Process exit code the CLI uses for this error. */
4
+ readonly exitCode: number;
5
+ constructor(message: string, exitCode?: number);
6
+ }
7
+ /** A non-2xx answer from Sentinel. A 401 (the credential stopped working) exits 4; any other refusal 10. */
8
+ export declare class SentinelApiError extends SentinelError {
9
+ readonly status: number;
10
+ /** The API's stable error code, such as `mfa_needs_person`, when it gave one. */
11
+ readonly code: string | undefined;
12
+ /** The parsed `detail` (or the whole body), for callers that need its fields. */
13
+ readonly detail: unknown;
14
+ constructor(status: number, code: string | undefined, message: string, detail: unknown);
15
+ }
16
+ /**
17
+ * Server text as one plain line: no control characters (newlines included),
18
+ * so it cannot rewrite the terminal or add lines, and no bidirectional or
19
+ * invisible characters, so it cannot display as something else.
20
+ */
21
+ export declare function printable(value: string): string;
22
+ /** No usable credential: not signed in, or the sign-in ended. */
23
+ export declare class NotSignedInError extends SentinelError {
24
+ constructor(message?: string);
25
+ }
26
+ /** The credential was made for another Sentinel environment. */
27
+ export declare class EnvironmentMismatchError extends SentinelError {
28
+ constructor(expected: string, actual: string);
29
+ }
30
+ /** Blank out anything shaped like a Sentinel credential. */
31
+ export declare function redact(text: string): string;
32
+ /** The error a failed response stands for, from FastAPI's `{detail}` shapes. */
33
+ export declare function errorFromResponse(response: Response): Promise<SentinelApiError>;
34
+ export declare function errorFromBody(status: number, body: unknown): SentinelApiError;
@@ -0,0 +1,92 @@
1
+ /** Errors the API client raises. Messages never contain a credential. */
2
+ export class SentinelError extends Error {
3
+ /** Process exit code the CLI uses for this error. */
4
+ exitCode;
5
+ constructor(message, exitCode = 1) {
6
+ super(message);
7
+ this.name = new.target.name;
8
+ this.exitCode = exitCode;
9
+ }
10
+ }
11
+ /** A non-2xx answer from Sentinel. A 401 (the credential stopped working) exits 4; any other refusal 10. */
12
+ export class SentinelApiError extends SentinelError {
13
+ status;
14
+ /** The API's stable error code, such as `mfa_needs_person`, when it gave one. */
15
+ code;
16
+ /** The parsed `detail` (or the whole body), for callers that need its fields. */
17
+ detail;
18
+ constructor(status, code, message, detail) {
19
+ super(message, status === 401 ? 4 : status >= 400 && status < 500 ? 10 : 1);
20
+ this.status = status;
21
+ this.code = code;
22
+ this.detail = detail;
23
+ }
24
+ }
25
+ /**
26
+ * Server text as one plain line: no control characters (newlines included),
27
+ * so it cannot rewrite the terminal or add lines, and no bidirectional or
28
+ * invisible characters, so it cannot display as something else.
29
+ */
30
+ export function printable(value) {
31
+ // eslint-disable-next-line no-control-regex
32
+ return value.replace(/[\u0000-\u001f\u007f-\u009f\u200b-\u200f\u202a-\u202e\u2066-\u2069\ufeff]/g, '');
33
+ }
34
+ /** No usable credential: not signed in, or the sign-in ended. */
35
+ export class NotSignedInError extends SentinelError {
36
+ constructor(message = 'Not signed in. Run `sentinel login`, or set SENTINEL_TOKEN to a personal API token.') {
37
+ super(message, 4);
38
+ }
39
+ }
40
+ /** The credential was made for another Sentinel environment. */
41
+ export class EnvironmentMismatchError extends SentinelError {
42
+ constructor(expected, actual) {
43
+ super(`Refusing to continue: expected the "${printable(expected)}" environment, ` +
44
+ `but the server is "${printable(actual)}". Check SENTINEL_API_URL.`, 5);
45
+ }
46
+ }
47
+ // Customer CLI access and refresh tokens and personal API tokens, plus the
48
+ // admin shapes in case one is pasted where it does not belong.
49
+ const SECRET = /snt_(?:cua|cur|pat|adm|cli|clr)_[0-9A-Za-z]{46}/g;
50
+ /** Blank out anything shaped like a Sentinel credential. */
51
+ export function redact(text) {
52
+ return text.replace(SECRET, (match) => `${match.slice(0, 8)}…`);
53
+ }
54
+ /** The error a failed response stands for, from FastAPI's `{detail}` shapes. */
55
+ export async function errorFromResponse(response) {
56
+ let body;
57
+ try {
58
+ body = await response.json();
59
+ }
60
+ catch {
61
+ body = undefined;
62
+ }
63
+ return errorFromBody(response.status, body);
64
+ }
65
+ export function errorFromBody(status, body) {
66
+ const detail = body && typeof body === 'object' && 'detail' in body ? body.detail : body;
67
+ let code;
68
+ let message = `HTTP ${status}`;
69
+ if (typeof detail === 'string') {
70
+ code = /^[a-z][a-z0-9_]*$/.test(detail) ? detail : undefined;
71
+ message = detail;
72
+ }
73
+ else if (detail && typeof detail === 'object' && !Array.isArray(detail)) {
74
+ const fields = detail;
75
+ if (typeof fields.code === 'string')
76
+ code = fields.code;
77
+ if (typeof fields.message === 'string')
78
+ message = fields.message;
79
+ else if (typeof fields.error_description === 'string')
80
+ message = fields.error_description;
81
+ if (typeof fields.error === 'string')
82
+ code = fields.error;
83
+ if (message === `HTTP ${status}` && code)
84
+ message = code;
85
+ }
86
+ else if (Array.isArray(detail)) {
87
+ code = 'validation_error';
88
+ message = 'The request was not valid.';
89
+ }
90
+ return new SentinelApiError(status, code, printable(redact(message)), detail);
91
+ }
92
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/api/errors.ts"],"names":[],"mappings":"AAAA,yEAAyE;AAEzE,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,qDAAqD;IAC5C,QAAQ,CAAS;IAE1B,YAAY,OAAe,EAAE,QAAQ,GAAG,CAAC;QACvC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;QAC5B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAED,4GAA4G;AAC5G,MAAM,OAAO,gBAAiB,SAAQ,aAAa;IACxC,MAAM,CAAS;IACxB,iFAAiF;IACxE,IAAI,CAAqB;IAClC,iFAAiF;IACxE,MAAM,CAAU;IAEzB,YAAY,MAAc,EAAE,IAAwB,EAAE,OAAe,EAAE,MAAe;QACpF,KAAK,CAAC,OAAO,EAAE,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5E,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,4CAA4C;IAC5C,OAAO,KAAK,CAAC,OAAO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