coolhand-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 +201 -0
- package/README.md +119 -0
- package/dist/auth/callback-server.d.ts +13 -0
- package/dist/auth/callback-server.d.ts.map +1 -0
- package/dist/auth/callback-server.js +133 -0
- package/dist/auth/callback-server.js.map +1 -0
- package/dist/auth/open-browser.d.ts +8 -0
- package/dist/auth/open-browser.d.ts.map +1 -0
- package/dist/auth/open-browser.js +31 -0
- package/dist/auth/open-browser.js.map +1 -0
- package/dist/auth/state.d.ts +3 -0
- package/dist/auth/state.d.ts.map +1 -0
- package/dist/auth/state.js +16 -0
- package/dist/auth/state.js.map +1 -0
- package/dist/auth/success-page.d.ts +3 -0
- package/dist/auth/success-page.d.ts.map +1 -0
- package/dist/auth/success-page.js +176 -0
- package/dist/auth/success-page.js.map +1 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +14 -0
- package/dist/bin.js.map +1 -0
- package/dist/cli.d.ts +9 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +187 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/accounts.d.ts +3 -0
- package/dist/commands/accounts.d.ts.map +1 -0
- package/dist/commands/accounts.js +59 -0
- package/dist/commands/accounts.js.map +1 -0
- package/dist/commands/clients.d.ts +3 -0
- package/dist/commands/clients.d.ts.map +1 -0
- package/dist/commands/clients.js +59 -0
- package/dist/commands/clients.js.map +1 -0
- package/dist/commands/login.d.ts +3 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +119 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +3 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/logout.js +39 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/status.d.ts +5 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +37 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/whoami.d.ts +3 -0
- package/dist/commands/whoami.d.ts.map +1 -0
- package/dist/commands/whoami.js +20 -0
- package/dist/commands/whoami.js.map +1 -0
- package/dist/config.d.ts +11 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +127 -0
- package/dist/config.js.map +1 -0
- package/dist/env-file.d.ts +12 -0
- package/dist/env-file.d.ts.map +1 -0
- package/dist/env-file.js +62 -0
- package/dist/env-file.js.map +1 -0
- package/dist/errors.d.ts +13 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +16 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +8 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +29 -0
- package/dist/logger.js.map +1 -0
- package/dist/mask.d.ts +7 -0
- package/dist/mask.d.ts.map +1 -0
- package/dist/mask.js +12 -0
- package/dist/mask.js.map +1 -0
- package/dist/types.d.ts +52 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +11 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +11 -0
- package/dist/version.js.map +1 -0
- package/package.json +74 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# coolhand-cli
|
|
2
|
+
|
|
3
|
+
Command-line authentication helper for [Coolhand](https://coolhandlabs.com). Opens a browser, captures your public API token via a localhost callback (same flow as `gh auth login` and `gcloud auth login`), and stores it in `~/.coolhand/config.json`.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
One-shot, no install:
|
|
8
|
+
```bash
|
|
9
|
+
npx coolhand-cli login
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Globally:
|
|
13
|
+
```bash
|
|
14
|
+
npm install -g coolhand-cli
|
|
15
|
+
coolhand login
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Requires Node 20 or newer.
|
|
19
|
+
|
|
20
|
+
## Commands
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
coolhand login [--base-url URL] [--write-env PATH] [--client-id ID] [--json]
|
|
24
|
+
coolhand logout [--client-id ID | --all] [--json]
|
|
25
|
+
coolhand status [--client-id ID] [--json]
|
|
26
|
+
coolhand whoami [--client-id ID]
|
|
27
|
+
coolhand clients [use <id>] [--json]
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### login
|
|
31
|
+
|
|
32
|
+
Opens your browser to the Coolhand consent page, listens on `127.0.0.1` for the callback, and stores the returned token. The token is the **public** `api_key` for the client you select — the same key you would use with `coolhand-node`, `coolhand-python`, or the `coolhand-js` widget.
|
|
33
|
+
|
|
34
|
+
`--write-env PATH` will additionally set `COOLHAND_API_KEY=<token>` in the target `.env` file (idempotent — replaces an existing value rather than appending a duplicate).
|
|
35
|
+
|
|
36
|
+
### status
|
|
37
|
+
|
|
38
|
+
`coolhand status --json` is the programmatic check used by integrations:
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"configured": true,
|
|
43
|
+
"clients": [
|
|
44
|
+
{"client_id": "acme", "client_name": "Acme Inc",
|
|
45
|
+
"masked_token": "e885b463…1148", "base_url": "https://coolhandlabs.com"}
|
|
46
|
+
],
|
|
47
|
+
"default_client_id": "acme"
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Exit code is `0` if a token is configured for the default (or requested) client, `1` otherwise.
|
|
52
|
+
|
|
53
|
+
### clients
|
|
54
|
+
|
|
55
|
+
Multiple clients can be stored at once. `coolhand clients` lists them, `coolhand clients use <id>` switches the default. Each `coolhand login` adds (or refreshes) one entry, keyed by the server-assigned `client_id`.
|
|
56
|
+
|
|
57
|
+
## Security
|
|
58
|
+
|
|
59
|
+
- The callback listener binds to `127.0.0.1` only — never reachable from the LAN.
|
|
60
|
+
- Tokens are delivered through a one-shot localhost redirect; subsequent calls to the listener get `410 Gone`.
|
|
61
|
+
- CSRF protection: every login generates a random `state` value verified with `crypto.timingSafeEqual` before any token is accepted.
|
|
62
|
+
- `~/.coolhand/config.json` is written atomically with mode `0o600`; the parent directory is `0o700`.
|
|
63
|
+
- Raw tokens are never printed to stdout or stderr. JSON output uses a masked form (e.g. `e885b463…1148`).
|
|
64
|
+
- Zero runtime dependencies — minimal supply-chain surface for the auth flow.
|
|
65
|
+
|
|
66
|
+
## Programmatic use
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { run, loadConfig, getClient, maskToken } from 'coolhand-cli';
|
|
70
|
+
|
|
71
|
+
await run(['login', '--json']);
|
|
72
|
+
|
|
73
|
+
const cfg = await loadConfig();
|
|
74
|
+
const client = getClient(cfg);
|
|
75
|
+
console.log(maskToken(client!.api_key));
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The CLI is shipped as an ES module. Importers must be ESM as well, or use a dynamic `import()`.
|
|
79
|
+
|
|
80
|
+
## Use with AI agents
|
|
81
|
+
|
|
82
|
+
coolhand-cli is designed to be invoked by AI agents and automated workflows, not just humans at a terminal. Two patterns make this straightforward:
|
|
83
|
+
|
|
84
|
+
**Check auth before starting work:**
|
|
85
|
+
```bash
|
|
86
|
+
coolhand status --json # exit 0 = token present, exit 1 = not configured
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Wire up the API key in one step:**
|
|
90
|
+
```bash
|
|
91
|
+
coolhand login --write-env .env
|
|
92
|
+
# sets COOLHAND_API_KEY=<token> in .env, idempotent on re-run
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The CLI works especially well with the [Coolhand feedback collection skill](https://github.com/Coolhand-Labs/feedback-collection-skill) for Claude Code. The skill scans your project for LLM inference calls and implements best-practice human feedback collection — it reads `COOLHAND_API_KEY` from the environment, which `coolhand login --write-env .env` puts in place.
|
|
96
|
+
|
|
97
|
+
## Configuration file
|
|
98
|
+
|
|
99
|
+
Located at `$HOME/.coolhand/config.json` (override with `COOLHAND_CONFIG_DIR` for testing). Schema:
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{
|
|
103
|
+
"version": 1,
|
|
104
|
+
"default_client_id": "acme",
|
|
105
|
+
"clients": {
|
|
106
|
+
"acme": {
|
|
107
|
+
"client_id": "acme",
|
|
108
|
+
"client_name": "Acme Inc",
|
|
109
|
+
"api_key": "e885b463541f1d1c6002268f32bbb7c82d9a350437bd587eb429504005831148",
|
|
110
|
+
"base_url": "https://coolhandlabs.com",
|
|
111
|
+
"saved_at": "2026-05-12T18:04:11.000Z"
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
Apache-2.0
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CallbackResult } from '../types.js';
|
|
2
|
+
export interface StartCallbackServerOptions {
|
|
3
|
+
expectedState: string;
|
|
4
|
+
timeoutMs: number;
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
}
|
|
7
|
+
export interface CallbackServerHandle {
|
|
8
|
+
port: number;
|
|
9
|
+
result: Promise<CallbackResult>;
|
|
10
|
+
close(): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export declare function startCallbackServer(opts: StartCallbackServerOptions): Promise<CallbackServerHandle>;
|
|
13
|
+
//# sourceMappingURL=callback-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callback-server.d.ts","sourceRoot":"","sources":["../../src/auth/callback-server.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAIlD,MAAM,WAAW,0BAA0B;IACzC,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IAChC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,0BAA0B,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAwJzG"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { createServer } from 'http';
|
|
2
|
+
import { CliError } from '../errors.js';
|
|
3
|
+
import { safeEqual } from './state.js';
|
|
4
|
+
import { SUCCESS_HTML, errorHtml } from './success-page.js';
|
|
5
|
+
const LOOPBACK = '127.0.0.1';
|
|
6
|
+
export async function startCallbackServer(opts) {
|
|
7
|
+
let resolveResult;
|
|
8
|
+
let rejectResult;
|
|
9
|
+
const result = new Promise((resolve, reject) => {
|
|
10
|
+
resolveResult = resolve;
|
|
11
|
+
rejectResult = reject;
|
|
12
|
+
});
|
|
13
|
+
let consumed = false;
|
|
14
|
+
let timer;
|
|
15
|
+
const server = createServer((req, res) => {
|
|
16
|
+
handleRequest(req, res);
|
|
17
|
+
});
|
|
18
|
+
function closeServerSoon() {
|
|
19
|
+
setImmediate(() => {
|
|
20
|
+
server.close();
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function handleRequest(req, res) {
|
|
24
|
+
const url = new URL(req.url ?? '/', `http://${LOOPBACK}`);
|
|
25
|
+
if (req.method !== 'GET') {
|
|
26
|
+
res.statusCode = 405;
|
|
27
|
+
res.setHeader('Allow', 'GET');
|
|
28
|
+
res.end();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (url.pathname !== '/callback') {
|
|
32
|
+
res.statusCode = 404;
|
|
33
|
+
res.end();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (consumed) {
|
|
37
|
+
res.statusCode = 410;
|
|
38
|
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
39
|
+
res.end(errorHtml('This callback has already been processed. You can close this tab.'));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const token = url.searchParams.get('token');
|
|
43
|
+
const state = url.searchParams.get('state');
|
|
44
|
+
const clientName = url.searchParams.get('client_name');
|
|
45
|
+
const clientId = url.searchParams.get('client_id');
|
|
46
|
+
if (!state || !safeEqual(state, opts.expectedState)) {
|
|
47
|
+
consumed = true;
|
|
48
|
+
res.statusCode = 400;
|
|
49
|
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
50
|
+
res.end(errorHtml('State parameter mismatch. This may be a forged or stale request.'));
|
|
51
|
+
rejectResult(new CliError('STATE_MISMATCH', 'Callback state did not match the expected value.'));
|
|
52
|
+
closeServerSoon();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (!token || !clientId || !clientName) {
|
|
56
|
+
consumed = true;
|
|
57
|
+
res.statusCode = 400;
|
|
58
|
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
59
|
+
res.end(errorHtml('Callback was missing required parameters.'));
|
|
60
|
+
rejectResult(new CliError('INVALID_CALLBACK', 'Callback was missing token, client_id, or client_name. Make sure your Coolhand server is up to date.'));
|
|
61
|
+
closeServerSoon();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
consumed = true;
|
|
65
|
+
res.statusCode = 200;
|
|
66
|
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
67
|
+
res.end(SUCCESS_HTML);
|
|
68
|
+
resolveResult({ token, clientName, clientId });
|
|
69
|
+
closeServerSoon();
|
|
70
|
+
}
|
|
71
|
+
await new Promise((resolve, reject) => {
|
|
72
|
+
server.once('error', reject);
|
|
73
|
+
server.listen(0, LOOPBACK, () => {
|
|
74
|
+
server.removeListener('error', reject);
|
|
75
|
+
resolve();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
const address = server.address();
|
|
79
|
+
if (!address || typeof address === 'string') {
|
|
80
|
+
server.close();
|
|
81
|
+
throw new CliError('INVALID_REDIRECT_URI', 'Could not determine local callback port.');
|
|
82
|
+
}
|
|
83
|
+
const port = address.port;
|
|
84
|
+
timer = setTimeout(() => {
|
|
85
|
+
if (!consumed) {
|
|
86
|
+
consumed = true;
|
|
87
|
+
rejectResult(new CliError('TIMEOUT', `No callback received within ${opts.timeoutMs}ms.`));
|
|
88
|
+
closeServerSoon();
|
|
89
|
+
}
|
|
90
|
+
}, opts.timeoutMs);
|
|
91
|
+
timer.unref?.();
|
|
92
|
+
if (opts.signal) {
|
|
93
|
+
if (opts.signal.aborted) {
|
|
94
|
+
if (!consumed) {
|
|
95
|
+
consumed = true;
|
|
96
|
+
rejectResult(new CliError('TIMEOUT', 'Operation aborted before callback received.'));
|
|
97
|
+
closeServerSoon();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
opts.signal.addEventListener('abort', () => {
|
|
102
|
+
if (!consumed) {
|
|
103
|
+
consumed = true;
|
|
104
|
+
rejectResult(new CliError('TIMEOUT', 'Operation aborted before callback received.'));
|
|
105
|
+
closeServerSoon();
|
|
106
|
+
}
|
|
107
|
+
}, { once: true });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const cleanup = () => {
|
|
111
|
+
if (timer) {
|
|
112
|
+
clearTimeout(timer);
|
|
113
|
+
timer = undefined;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
result.finally(cleanup).catch(() => undefined);
|
|
117
|
+
async function close() {
|
|
118
|
+
cleanup();
|
|
119
|
+
if (!consumed) {
|
|
120
|
+
consumed = true;
|
|
121
|
+
rejectResult(new CliError('TIMEOUT', 'Callback server closed before receiving a request.'));
|
|
122
|
+
}
|
|
123
|
+
await new Promise((resolve) => {
|
|
124
|
+
if (!server.listening) {
|
|
125
|
+
resolve();
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
server.close(() => resolve());
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return { port, result, close };
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=callback-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callback-server.js","sourceRoot":"","sources":["../../src/auth/callback-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA2C,MAAM,MAAM,CAAC;AAE7E,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG5D,MAAM,QAAQ,GAAG,WAAW,CAAC;AAc7B,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,IAAgC;IACxE,IAAI,aAA+C,CAAC;IACpD,IAAI,YAAmC,CAAC;IACxC,MAAM,MAAM,GAAG,IAAI,OAAO,CAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC7D,aAAa,GAAG,OAAO,CAAC;QACxB,YAAY,GAAG,MAAM,CAAC;IACxB,CAAC,CAAC,CAAC;IAEH,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,IAAI,KAAiC,CAAC;IAEtC,MAAM,MAAM,GAAW,YAAY,CAAC,CAAC,GAAoB,EAAE,GAAmB,EAAE,EAAE;QAChF,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;IAEH,SAAS,eAAe;QACtB,YAAY,CAAC,GAAG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,EAAE,6CAA6C,CAAC,CAAC,CAAC;oBACrF,eAAe,EAAE,CAAC;gBACpB,CAAC;YACH,CAAC,EACD,EAAE,IAAI,EAAE,IAAI,EAAE,CACf,CAAC;QACJ,CAAC;IACH,CAAC;IAED,MAAM,OAAO,GAAG,GAAS,EAAE;QACzB,IAAI,KAAK,EAAE,CAAC;YACV,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,KAAK,GAAG,SAAS,CAAC;QACpB,CAAC;IACH,CAAC,CAAC;IACF,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAE/C,KAAK,UAAU,KAAK;QAClB,OAAO,EAAE,CAAC;QACV,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,QAAQ,GAAG,IAAI,CAAC;YAChB,YAAY,CAAC,IAAI,QAAQ,CAAC,SAAS,EAAE,oDAAoD,CAAC,CAAC,CAAC;QAC9F,CAAC;QACD,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YAClC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;gBACtB,OAAO,EAAE,CAAC;gBACV,OAAO;YACT,CAAC;YACD,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
interface OpenBrowserDeps {
|
|
3
|
+
platform?: NodeJS.Platform;
|
|
4
|
+
spawnFn?: typeof spawn;
|
|
5
|
+
}
|
|
6
|
+
export declare function openBrowser(url: string, deps?: OpenBrowserDeps): Promise<void>;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=open-browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-browser.d.ts","sourceRoot":"","sources":["../../src/auth/open-browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAGtC,UAAU,eAAe;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC3B,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;CACxB;AAED,wBAAsB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,eAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CA0BxF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
import { logger } from '../logger.js';
|
|
3
|
+
export async function openBrowser(url, deps = {}) {
|
|
4
|
+
const platform = deps.platform ?? process.platform;
|
|
5
|
+
const spawnFn = deps.spawnFn ?? spawn;
|
|
6
|
+
let command;
|
|
7
|
+
let args;
|
|
8
|
+
if (platform === 'darwin') {
|
|
9
|
+
command = 'open';
|
|
10
|
+
args = [url];
|
|
11
|
+
}
|
|
12
|
+
else if (platform === 'win32') {
|
|
13
|
+
command = 'cmd';
|
|
14
|
+
args = ['/c', 'start', '""', url];
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
command = 'xdg-open';
|
|
18
|
+
args = [url];
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
const child = spawnFn(command, args, { detached: true, stdio: 'ignore' });
|
|
22
|
+
child.on('error', (err) => {
|
|
23
|
+
logger.warn(`Failed to open browser (${command}): ${err.message}. Open the URL manually.`);
|
|
24
|
+
});
|
|
25
|
+
child.unref();
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
logger.warn(`Failed to launch browser (${command}): ${err.message}. Open the URL manually.`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=open-browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open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OAAO,MAAO,GAAa,CAAC,OAAO,0BAA0B,CAAC,CAAC;IAC1G,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/auth/state.ts"],"names":[],"mappings":"AAEA,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAUvD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { randomBytes, timingSafeEqual } from 'crypto';
|
|
2
|
+
export function generateState() {
|
|
3
|
+
return randomBytes(16).toString('hex');
|
|
4
|
+
}
|
|
5
|
+
export function safeEqual(a, b) {
|
|
6
|
+
if (typeof a !== 'string' || typeof b !== 'string') {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
const aBuf = Buffer.from(a, 'utf8');
|
|
10
|
+
const bBuf = Buffer.from(b, 'utf8');
|
|
11
|
+
if (aBuf.length !== bBuf.length) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
return timingSafeEqual(aBuf, bBuf);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/auth/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEtD,MAAM,UAAU,aAAa;IAC3B,OAAO,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,CAAS,EAAE,CAAS;IAC5C,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QACnD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACpC,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const SUCCESS_HTML = "<!doctype html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\">\n <title>Coolhand \u2014 Token captured</title>\n <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n <meta name=\"color-scheme\" content=\"dark\">\n <meta name=\"robots\" content=\"noindex\">\n <style>\n * { box-sizing: border-box; margin: 0; padding: 0; }\n html, body { height: 100%; }\n body {\n font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,\n \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif;\n background: hsl(222.2 84% 4.9%);\n color: hsl(210 40% 98%);\n display: flex;\n align-items: center;\n justify-content: center;\n min-height: 100vh;\n padding: 24px;\n line-height: 1.5;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n }\n .wrap { width: 100%; max-width: 440px; }\n .brand {\n text-align: center;\n margin-bottom: 32px;\n }\n .brand-logo {\n height: 157px;\n width: auto;\n max-width: 100%;\n display: inline-block;\n }\n .brand-text {\n display: none;\n font-size: 13px;\n font-weight: 600;\n letter-spacing: 0.15em;\n text-transform: uppercase;\n color: hsl(215 20.2% 65.1%);\n align-items: center;\n justify-content: center;\n }\n .brand-dot {\n display: inline-block;\n width: 8px;\n height: 8px;\n border-radius: 50%;\n background: hsl(217.2 91.2% 59.8%);\n margin-right: 8px;\n vertical-align: middle;\n transform: translateY(-1px);\n }\n .card {\n background: hsl(222.2 84% 4.9%);\n border: 1px solid hsl(217.2 32.6% 17.5%);\n border-radius: 12px;\n padding: 40px 32px 32px;\n text-align: center;\n box-shadow: 0 24px 48px -16px rgba(0, 0, 0, 0.5);\n }\n .icon-wrap {\n width: 64px;\n height: 64px;\n border-radius: 50%;\n display: flex;\n align-items: center;\n justify-content: center;\n margin: 0 auto 20px;\n }\n .icon-svg { width: 32px; height: 32px; }\n h1 {\n font-size: 20px;\n font-weight: 600;\n color: hsl(210 40% 98%);\n margin-bottom: 8px;\n letter-spacing: -0.01em;\n }\n p {\n color: hsl(215 20.2% 65.1%);\n font-size: 14px;\n }\n p + p { margin-top: 12px; }\n .foot {\n text-align: center;\n margin-top: 24px;\n font-size: 12px;\n color: hsl(215 20.2% 65.1%);\n }\n</style>\n</head>\n<body>\n <main class=\"wrap\">\n \n <div class=\"brand\">\n <img src=\"https://coolhandlabs.com/coolhand-logo.png\" alt=\"Coolhand\"\n class=\"brand-logo\"\n onerror=\"this.style.display='none'; this.nextElementSibling.style.display='inline-flex';\">\n <span class=\"brand-text\"><span class=\"brand-dot\"></span>coolhand</span>\n </div>\n\n <div class=\"card\">\n <div class=\"icon-wrap\" style=\"background: hsl(217.2 91.2% 59.8% / 0.12);\">\n <svg class=\"icon-svg\" viewBox=\"0 0 24 24\" fill=\"none\"\n stroke=\"hsl(217.2 91.2% 59.8%)\" stroke-width=\"2.5\"\n stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\">\n <polyline points=\"20 6 9 17 4 12\"></polyline>\n </svg>\n </div>\n <h1>Token captured</h1>\n <p>You can close this tab and return to your terminal.</p>\n </div>\n <p class=\"foot\">coolhand-cli received your API token securely.</p>\n</main>\n</body>\n</html>\n";
|
|
2
|
+
export declare function errorHtml(message: string): string;
|
|
3
|
+
//# sourceMappingURL=success-page.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"success-page.d.ts","sourceRoot":"","sources":["../../src/auth/success-page.ts"],"names":[],"mappings":"AAoHA,eAAO,MAAM,YAAY,0zGAcxB,CAAC;AAEF,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CA8CjD"}
|