reply-cli 0.2.0 → 0.3.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 +107 -144
- package/dist/api/headers.d.ts +4 -0
- package/dist/api/headers.js +13 -0
- package/dist/api/headers.js.map +1 -0
- package/dist/auth/oauth-flow.d.ts +38 -0
- package/dist/auth/oauth-flow.js +193 -0
- package/dist/auth/oauth-flow.js.map +1 -0
- package/dist/auth/pkce.d.ts +9 -0
- package/dist/auth/pkce.js +19 -0
- package/dist/auth/pkce.js.map +1 -0
- package/dist/auth/request-identity.d.ts +16 -0
- package/dist/auth/request-identity.js +67 -0
- package/dist/auth/request-identity.js.map +1 -0
- package/dist/auth/resolve.d.ts +23 -0
- package/dist/auth/resolve.js +55 -0
- package/dist/auth/resolve.js.map +1 -0
- package/dist/auth/status.d.ts +19 -0
- package/dist/auth/status.js +27 -0
- package/dist/auth/status.js.map +1 -0
- package/dist/auth/token.d.ts +29 -0
- package/dist/auth/token.js +39 -0
- package/dist/auth/token.js.map +1 -0
- package/dist/commands/api.d.ts +19 -0
- package/dist/commands/api.js +137 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/auth.d.ts +19 -3
- package/dist/commands/auth.js +251 -16
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/authed.d.ts +13 -0
- package/dist/commands/authed.js +20 -0
- package/dist/commands/authed.js.map +1 -0
- package/dist/commands/profile.d.ts +31 -0
- package/dist/commands/profile.js +348 -0
- package/dist/commands/profile.js.map +1 -0
- package/dist/commands/team.d.ts +17 -0
- package/dist/commands/team.js +146 -0
- package/dist/commands/team.js.map +1 -0
- package/dist/config.d.ts +14 -0
- package/dist/config.js +80 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +15 -0
- package/dist/context.js +17 -0
- package/dist/context.js.map +1 -0
- package/dist/credentials/file-store.d.ts +13 -0
- package/dist/credentials/file-store.js +88 -0
- package/dist/credentials/file-store.js.map +1 -0
- package/dist/credentials/types.d.ts +25 -0
- package/dist/credentials/types.js +3 -0
- package/dist/credentials/types.js.map +1 -0
- package/dist/index.js +97 -69
- package/dist/index.js.map +1 -1
- package/dist/profile.d.ts +51 -0
- package/dist/profile.js +295 -0
- package/dist/profile.js.map +1 -0
- package/dist/teams.d.ts +14 -0
- package/dist/teams.js +103 -0
- package/dist/teams.js.map +1 -0
- package/dist/utils/client.d.ts +19 -34
- package/dist/utils/client.js +123 -94
- package/dist/utils/client.js.map +1 -1
- package/dist/utils/errors.d.ts +47 -0
- package/dist/utils/errors.js +86 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/output.d.ts +7 -19
- package/dist/utils/output.js +39 -81
- package/dist/utils/output.js.map +1 -1
- package/package.json +10 -25
- package/dist/commands/contacts.d.ts +0 -35
- package/dist/commands/contacts.js +0 -412
- package/dist/commands/contacts.js.map +0 -1
- package/dist/commands/email-accounts.d.ts +0 -11
- package/dist/commands/email-accounts.js +0 -97
- package/dist/commands/email-accounts.js.map +0 -1
- package/dist/commands/inbox.d.ts +0 -30
- package/dist/commands/inbox.js +0 -225
- package/dist/commands/inbox.js.map +0 -1
- package/dist/commands/lists.d.ts +0 -20
- package/dist/commands/lists.js +0 -137
- package/dist/commands/lists.js.map +0 -1
- package/dist/commands/reports.d.ts +0 -10
- package/dist/commands/reports.js +0 -70
- package/dist/commands/reports.js.map +0 -1
- package/dist/commands/schedules.d.ts +0 -6
- package/dist/commands/schedules.js +0 -59
- package/dist/commands/schedules.js.map +0 -1
- package/dist/commands/sequence-contacts.d.ts +0 -19
- package/dist/commands/sequence-contacts.js +0 -129
- package/dist/commands/sequence-contacts.js.map +0 -1
- package/dist/commands/sequences-stats.d.ts +0 -42
- package/dist/commands/sequences-stats.js +0 -99
- package/dist/commands/sequences-stats.js.map +0 -1
- package/dist/commands/sequences.d.ts +0 -22
- package/dist/commands/sequences.js +0 -211
- package/dist/commands/sequences.js.map +0 -1
- package/dist/utils/auth.d.ts +0 -2
- package/dist/utils/auth.js +0 -33
- package/dist/utils/auth.js.map +0 -1
- package/dist/utils/command.d.ts +0 -18
- package/dist/utils/command.js +0 -51
- package/dist/utils/command.js.map +0 -1
- package/dist/utils/csv.d.ts +0 -19
- package/dist/utils/csv.js +0 -118
- package/dist/utils/csv.js.map +0 -1
- package/dist/utils/pagination.d.ts +0 -22
- package/dist/utils/pagination.js +0 -37
- package/dist/utils/pagination.js.map +0 -1
- package/dist/utils/resolve.d.ts +0 -4
- package/dist/utils/resolve.js +0 -34
- package/dist/utils/resolve.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,184 +1,147 @@
|
|
|
1
|
-
|
|
1
|
+
# Reply CLI
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
`reply` is the command-line interface for [Reply.io](https://reply.io). Sign in
|
|
4
|
+
once and every Reply.io API request runs as you — from your terminal or your
|
|
5
|
+
scripts. Today it handles authentication and identity, and `reply api` gives you
|
|
6
|
+
authenticated access to the full v3 API; higher-level commands for sequences,
|
|
7
|
+
contacts, and the inbox are on the way.
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
<a href="https://www.npmjs.com/package/reply-cli"><img src="https://img.shields.io/npm/v/reply-cli?color=black&label=npm" alt="npm version" /></a>
|
|
9
|
-
<img src="https://img.shields.io/badge/node-%3E%3D20-black" alt="node requirement" />
|
|
10
|
-
<img src="https://img.shields.io/badge/license-MIT-black" alt="license" />
|
|
11
|
-
</p>
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
## Overview
|
|
16
|
-
|
|
17
|
-
`reply-cli` is the command-line interface for the [Reply.io](https://reply.io) **v3 API**. It installs the `reply` command — deterministic, scriptable, and built for humans, CI, and AI agents alike:
|
|
9
|
+
## Installation
|
|
18
10
|
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
Requires [Node.js](https://nodejs.org) 20 or newer. The CLI is published to
|
|
12
|
+
GitHub Packages under the `@reply-team` scope, so point that scope at the
|
|
13
|
+
registry once, then install globally:
|
|
21
14
|
|
|
22
|
-
|
|
23
|
-
reply
|
|
24
|
-
|
|
25
|
-
reply contacts import prospects.csv --dry-run
|
|
15
|
+
```sh
|
|
16
|
+
echo "@reply-team:registry=https://npm.pkg.github.com" >> ~/.npmrc
|
|
17
|
+
npm install -g @reply-team/reply-cli
|
|
26
18
|
```
|
|
27
19
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
- **Shell scripts and CI** that automate outreach workflows
|
|
32
|
-
- **AI agents** (Claude Code, Codex, Cursor, and friends) that need a predictable execution layer — see the [Reply.io Agent Skill](https://github.com/replyio/reply-skill), which drives this CLI
|
|
33
|
-
|
|
34
|
-
---
|
|
20
|
+
```sh
|
|
21
|
+
reply --version
|
|
22
|
+
```
|
|
35
23
|
|
|
36
|
-
##
|
|
24
|
+
## Usage
|
|
37
25
|
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
npx -y reply-cli auth whoami
|
|
26
|
+
```sh
|
|
27
|
+
reply <command> [flags]
|
|
28
|
+
reply <command> --help
|
|
42
29
|
```
|
|
43
30
|
|
|
44
|
-
|
|
31
|
+
Run `reply --help` for the full command list. Add `--json` to any command for
|
|
32
|
+
machine-readable output suitable for scripts.
|
|
45
33
|
|
|
46
34
|
## Authentication
|
|
47
35
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
1. `--api-key <key>` flag
|
|
51
|
-
2. `REPLY_API_KEY` environment variable
|
|
52
|
-
3. `REPLY_API_KEY=...` in a `.env` file (current directory or up to 5 parent directories)
|
|
53
|
-
|
|
54
|
-
Verify your setup:
|
|
36
|
+
Log in through your browser with OAuth:
|
|
55
37
|
|
|
56
|
-
```
|
|
57
|
-
reply auth
|
|
58
|
-
# ✓ API key is valid.
|
|
38
|
+
```sh
|
|
39
|
+
reply auth login
|
|
59
40
|
```
|
|
60
41
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
## Commands
|
|
64
|
-
|
|
65
|
-
| Command | Description |
|
|
66
|
-
|---|---|
|
|
67
|
-
| `reply auth whoami` | Verify API key, show user and team |
|
|
68
|
-
| `reply contacts list\|get\|create\|update\|delete` | Contact CRUD (by ID or email) |
|
|
69
|
-
| `reply contacts search` | Filter contacts (`--term`, `--list`, `--sequence`, `--rule prop=cond:value`) |
|
|
70
|
-
| `reply contacts statuses <id\|email>` | Opt-out, call, meeting, and per-sequence status |
|
|
71
|
-
| `reply contacts import <file.csv>` | CSV import with auto column mapping, dedupe options, `--dry-run` |
|
|
72
|
-
| `reply lists list\|get\|create\|add-contacts` | Contact lists |
|
|
73
|
-
| `reply sequences list\|get\|create\|update` | Sequences (create accepts `--name` or full JSON config on stdin) |
|
|
74
|
-
| `reply sequences start\|pause\|archive <id>` | Sequence lifecycle (start/archive prompt for confirmation) |
|
|
75
|
-
| `reply sequences stats [id]` | Performance for one or all sequences (`--top`, `--preset`, `--from/--to`) |
|
|
76
|
-
| `reply sequences contacts list\|add\|remove <id>` | Contacts within a sequence |
|
|
77
|
-
| `reply inbox threads list\|get` | Inbox threads (`--unread`, `--category`, `--sequence`, `--search`) |
|
|
78
|
-
| `reply inbox reply <thread-id>` | Send a reply on a thread (confirmation-gated) |
|
|
79
|
-
| `reply inbox categories list\|assign` | Inbox categories |
|
|
80
|
-
| `reply reports emails` | Account-level email performance overview |
|
|
81
|
-
| `reply reports sequences` | Per-sequence performance table |
|
|
82
|
-
| `reply email-accounts list\|check` | Connected sending accounts |
|
|
83
|
-
| `reply schedules list\|get` | Sending schedules |
|
|
84
|
-
|
|
85
|
-
Run `reply <group> --help` for flags and examples on every command.
|
|
86
|
-
|
|
87
|
-
## JSON output & AI agents
|
|
88
|
-
|
|
89
|
-
Every command supports `--json` (compact) and `--pretty` (formatted). Data goes to **stdout**, status and errors go to **stderr** — safe to pipe:
|
|
90
|
-
|
|
91
|
-
```bash
|
|
92
|
-
reply sequences list --status active --json | jq '.items[].id'
|
|
93
|
-
reply contacts search --term "acme.com" --all --json | jq '.count'
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
Errors with `--json` emit a single machine-readable line on stderr:
|
|
42
|
+
Or store an API key, read from stdin so it never lands in your shell history:
|
|
97
43
|
|
|
98
|
-
```
|
|
99
|
-
|
|
44
|
+
```sh
|
|
45
|
+
reply auth login --with-token
|
|
100
46
|
```
|
|
101
47
|
|
|
102
|
-
|
|
48
|
+
Inspect and manage the active credential:
|
|
103
49
|
|
|
104
|
-
|
|
50
|
+
```sh
|
|
51
|
+
reply auth status # who you're signed in as, and how — no secrets shown
|
|
52
|
+
reply auth whoami # verify the stored credential against the API
|
|
53
|
+
reply auth logout # remove the stored credential
|
|
54
|
+
```
|
|
105
55
|
|
|
106
|
-
|
|
56
|
+
Pass a key for a single command with `--api-key` or the `REPLY_API_KEY`
|
|
57
|
+
environment variable; both take precedence over a stored login and are never
|
|
58
|
+
written to disk.
|
|
107
59
|
|
|
108
|
-
##
|
|
60
|
+
## Profiles
|
|
109
61
|
|
|
110
|
-
|
|
62
|
+
Profiles keep more than one Reply.io account signed in at once — each stores its
|
|
63
|
+
own credential. Name them however you like; account emails work well:
|
|
111
64
|
|
|
112
|
-
|
|
113
|
-
|
|
65
|
+
```sh
|
|
66
|
+
reply profile add alice@reply.io
|
|
67
|
+
reply profile use alice@reply.io # make it the active profile
|
|
68
|
+
reply auth login # signs in alice@reply.io
|
|
114
69
|
|
|
115
|
-
|
|
116
|
-
reply
|
|
117
|
-
reply contacts import prospects.csv --list 42 --skip-existing --yes --json
|
|
118
|
-
reply sequences contacts add 12345 --contacts john@co.com,jane@co.com --dry-run
|
|
119
|
-
reply sequences start 12345 --yes
|
|
70
|
+
reply profile list # '*' marks the active profile
|
|
71
|
+
reply --profile bob@reply.io auth whoami # override for a single command
|
|
120
72
|
```
|
|
121
73
|
|
|
122
|
-
|
|
74
|
+
The active profile is resolved as `--profile` → `REPLY_PROFILE` → the profile
|
|
75
|
+
set with `profile use` → the built-in default.
|
|
123
76
|
|
|
124
|
-
|
|
125
|
-
# Weekly performance digest
|
|
126
|
-
reply reports emails --preset lastWeek --json | jq '{delivered, replied, interested}'
|
|
77
|
+
Manage profiles after creating them:
|
|
127
78
|
|
|
128
|
-
|
|
129
|
-
reply
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
#
|
|
134
|
-
reply contacts import new-leads.csv --list 42 --skip-existing --yes --json
|
|
135
|
-
reply contacts search --list 42 --all --json | jq '.count'
|
|
136
|
-
reply sequences contacts add 12345 --contacts 111,222,333 --yes --json
|
|
79
|
+
```sh
|
|
80
|
+
reply profile show # inspect the current profile (no secrets)
|
|
81
|
+
reply profile show alice@reply.io # inspect a specific one
|
|
82
|
+
reply profile rename alice@reply.io ally # also moves the stored credential
|
|
83
|
+
reply profile unset ally team-id # clear a field (authority|api_base|team-id)
|
|
84
|
+
reply profile delete ally # remove it and its stored credential
|
|
137
85
|
```
|
|
138
86
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
87
|
+
`profile show` lists the backend URLs, pinned team, and which authorization
|
|
88
|
+
would be used (in priority order: `--api-key` → `REPLY_API_KEY` → stored
|
|
89
|
+
credential) — it never prints tokens or keys. `--authority` and `--api-base`
|
|
90
|
+
must be `http(s)` URLs.
|
|
142
91
|
|
|
143
|
-
|
|
144
|
-
|---|---|
|
|
145
|
-
| `reply accounts list\|check` | `reply email-accounts list\|check` |
|
|
146
|
-
| `reply sequence-contacts add\|add-bulk` | `reply sequences contacts add` |
|
|
147
|
-
| `reply sequence-contacts remove\|remove-all` | `reply sequences contacts remove` |
|
|
148
|
-
| `reply import preview --file x.csv` | `reply contacts import x.csv --dry-run` |
|
|
149
|
-
| `reply import upload --file x.csv --mapping …` | `reply contacts import x.csv` (auto-mapping; `--mapping` to override) |
|
|
150
|
-
| `reply contacts list --page 2` | `reply contacts list --skip 25` (or `--all`) |
|
|
151
|
-
| `reply contacts stats <email>` | `reply contacts statuses <email>` |
|
|
152
|
-
| `reply contacts mark-replied\|mark-finished\|opt-out` | removed (v1-only actions) — use `reply contacts update` / `sequences contacts remove` |
|
|
153
|
-
| `reply sequences clone` | removed for now — planned for 0.3 via v3 templates |
|
|
154
|
-
| `reply schedules create\|delete\|set-default` | removed for now (read-only in 0.2) |
|
|
155
|
-
| numeric sequence statuses (`0/2/4`) | strings: `new` \| `active` \| `paused` \| `archived` |
|
|
92
|
+
## Teams
|
|
156
93
|
|
|
157
|
-
|
|
94
|
+
A profile can pin a team (workspace); it's sent as `X-TEAM-ID`, with precedence
|
|
95
|
+
`--team-id` → `REPLY_TEAM_ID` → the profile's team. The `team` command sees and
|
|
96
|
+
sets the **current profile's** team:
|
|
158
97
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
98
|
+
```sh
|
|
99
|
+
reply team list # teams you can act in (* marks the profile's team)
|
|
100
|
+
reply team current # the profile's pinned team + the effective team (from whoami)
|
|
101
|
+
reply team use 1045 # verify 1045 is one of your teams, then pin it on the current profile
|
|
102
|
+
reply team clear # remove the pin
|
|
103
|
+
```
|
|
165
104
|
|
|
166
|
-
|
|
105
|
+
If a call needs a team and you're in more than one, the API answers with a
|
|
106
|
+
`TEAM_REQUIRED` error listing your teams — run `reply team use <id>` to pin one.
|
|
107
|
+
|
|
108
|
+
## Raw API access
|
|
109
|
+
|
|
110
|
+
`reply api` is a raw, authenticated passthrough to any v3 endpoint — the
|
|
111
|
+
agent/CI escape hatch. See the
|
|
112
|
+
[Reply API reference](https://docs.reply.io/api-reference/introduction) for the
|
|
113
|
+
full surface.
|
|
114
|
+
|
|
115
|
+
Use the path exactly as it appears in the docs (starting with `/v3`); the query
|
|
116
|
+
string goes in the path. The request URL is literally `api_base + path`, and the
|
|
117
|
+
profile stores the host **without** `/v3`, so the call's URL matches the docs. A
|
|
118
|
+
`--body` switches the method to POST (it also accepts `@file` or `-` for stdin).
|
|
119
|
+
|
|
120
|
+
```sh
|
|
121
|
+
reply api /v3/whoami # your identity + team
|
|
122
|
+
reply api /v3/sequences # list sequences
|
|
123
|
+
reply api /v3/contacts --pretty # list contacts, indented
|
|
124
|
+
reply api /v3/sequences/12345 # one sequence by id
|
|
125
|
+
reply api /v3/contacts --body @contact.json # create a contact (POST; body schema per the docs)
|
|
126
|
+
echo '<json>' | reply api /v3/contacts --body - # body from stdin
|
|
127
|
+
reply api /v3/whoami --verbose # full request/response on stderr
|
|
128
|
+
```
|
|
167
129
|
|
|
168
|
-
|
|
130
|
+
It prints `{ "code": <status>, "data": <body> }` and exits non-zero on HTTP
|
|
131
|
+
`>= 400`. On a team/user-resolution conflict it adds a short fix-it hint on
|
|
132
|
+
stderr. Add `--verbose` for a full request/response trace on stderr with
|
|
133
|
+
credentials redacted; stdout stays the plain JSON, so pipes keep working.
|
|
169
134
|
|
|
170
|
-
|
|
171
|
-
git clone https://github.com/replyio/reply-cli.git
|
|
172
|
-
cd reply-cli
|
|
173
|
-
npm install
|
|
174
|
-
npm run build # tsc → dist/
|
|
175
|
-
npm test # vitest unit tests (mocked fetch, no network)
|
|
176
|
-
REPLY_API_KEY=... npm run test:integration # live read-only smoke tests
|
|
177
|
-
node dist/index.js auth whoami
|
|
178
|
-
```
|
|
135
|
+
## Environment variables
|
|
179
136
|
|
|
180
|
-
|
|
137
|
+
| Variable | Description |
|
|
138
|
+
|----------|-------------|
|
|
139
|
+
| `REPLY_API_KEY` | API key used as the credential for the current invocation |
|
|
140
|
+
| `REPLY_PROFILE` | Profile to use (same as `--profile`) |
|
|
141
|
+
| `REPLY_TEAM_ID` | Team/workspace id sent as `X-TEAM-ID` (same as `--team-id`) |
|
|
142
|
+
| `REPLY_CONFIG_DIR` | Config directory (default `~/.config/reply`; `%APPDATA%\reply` on Windows) |
|
|
181
143
|
|
|
182
|
-
##
|
|
144
|
+
## Contributing
|
|
183
145
|
|
|
184
|
-
|
|
146
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for building from source, running the
|
|
147
|
+
tests, credential-store internals, and the release process.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HEADER_USER_EMAIL = exports.HEADER_USER_ID = exports.HEADER_TEAM_ID = void 0;
|
|
4
|
+
// Reply.io request headers, mirroring the backend's ReplyKnownHeaders. They pin
|
|
5
|
+
// the team/workspace context and, for organization API keys, identify the user
|
|
6
|
+
// the request acts on behalf of. Casing matches the backend constants verbatim.
|
|
7
|
+
const HEADER_TEAM_ID = 'X-TEAM-ID';
|
|
8
|
+
exports.HEADER_TEAM_ID = HEADER_TEAM_ID;
|
|
9
|
+
const HEADER_USER_ID = 'X-USER-ID';
|
|
10
|
+
exports.HEADER_USER_ID = HEADER_USER_ID;
|
|
11
|
+
const HEADER_USER_EMAIL = 'X-User-Email';
|
|
12
|
+
exports.HEADER_USER_EMAIL = HEADER_USER_EMAIL;
|
|
13
|
+
//# sourceMappingURL=headers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/api/headers.ts"],"names":[],"mappings":";;;AAAA,gFAAgF;AAChF,+EAA+E;AAC/E,gFAAgF;AAChF,MAAM,cAAc,GAAG,WAAW,CAAC;AAI3B,wCAAc;AAHtB,MAAM,cAAc,GAAG,WAAW,CAAC;AAGX,wCAAc;AAFtC,MAAM,iBAAiB,GAAG,cAAc,CAAC;AAED,8CAAiB"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Oauth_record } from '../credentials/types';
|
|
2
|
+
declare const CLIENT_ID = "Reply.Cli";
|
|
3
|
+
declare const SCOPE = "openid profile email reply-web-api offline_access";
|
|
4
|
+
declare const build_authorize_url: (p: {
|
|
5
|
+
authority: string;
|
|
6
|
+
client_id: string;
|
|
7
|
+
redirect_uri: string;
|
|
8
|
+
scope: string;
|
|
9
|
+
challenge: string;
|
|
10
|
+
state: string;
|
|
11
|
+
}) => string;
|
|
12
|
+
declare const browser_open_command: (platform: NodeJS.Platform, url: string) => {
|
|
13
|
+
command: string;
|
|
14
|
+
args: string[];
|
|
15
|
+
};
|
|
16
|
+
declare const exchange_code: (p: {
|
|
17
|
+
authority: string;
|
|
18
|
+
client_id: string;
|
|
19
|
+
redirect_uri: string;
|
|
20
|
+
code: string;
|
|
21
|
+
verifier: string;
|
|
22
|
+
now?: number;
|
|
23
|
+
}) => Promise<Oauth_record>;
|
|
24
|
+
declare const refresh_stored: (p: {
|
|
25
|
+
authority: string;
|
|
26
|
+
record: Oauth_record;
|
|
27
|
+
client_id?: string;
|
|
28
|
+
now?: number;
|
|
29
|
+
}) => Promise<Oauth_record>;
|
|
30
|
+
declare const run_login: (opts: {
|
|
31
|
+
authority: string;
|
|
32
|
+
client_id?: string;
|
|
33
|
+
scope?: string;
|
|
34
|
+
open?: (url: string) => void;
|
|
35
|
+
now?: number;
|
|
36
|
+
timeout_ms?: number;
|
|
37
|
+
}) => Promise<Oauth_record>;
|
|
38
|
+
export { CLIENT_ID, SCOPE, build_authorize_url, run_login, exchange_code, refresh_stored, browser_open_command, };
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.browser_open_command = exports.refresh_stored = exports.exchange_code = exports.run_login = exports.build_authorize_url = exports.SCOPE = exports.CLIENT_ID = void 0;
|
|
7
|
+
const http_1 = __importDefault(require("http"));
|
|
8
|
+
const child_process_1 = require("child_process");
|
|
9
|
+
const url_1 = require("url");
|
|
10
|
+
const errors_1 = require("../utils/errors");
|
|
11
|
+
const output_1 = require("../utils/output");
|
|
12
|
+
const pkce_1 = require("./pkce");
|
|
13
|
+
const token_1 = require("./token");
|
|
14
|
+
// Public PKCE client registered in IdentityServer (REPLY-51291 / REPLY-50627).
|
|
15
|
+
const CLIENT_ID = 'Reply.Cli';
|
|
16
|
+
exports.CLIENT_ID = CLIENT_ID;
|
|
17
|
+
const SCOPE = 'openid profile email reply-web-api offline_access';
|
|
18
|
+
exports.SCOPE = SCOPE;
|
|
19
|
+
const DEFAULT_TIMEOUT_MS = 300_000; // 5 minutes to complete the browser step
|
|
20
|
+
const build_authorize_url = (p) => {
|
|
21
|
+
const url = new url_1.URL('/connect/authorize', p.authority);
|
|
22
|
+
url.search = new URLSearchParams({
|
|
23
|
+
response_type: 'code',
|
|
24
|
+
client_id: p.client_id,
|
|
25
|
+
redirect_uri: p.redirect_uri,
|
|
26
|
+
scope: p.scope,
|
|
27
|
+
code_challenge: p.challenge,
|
|
28
|
+
code_challenge_method: 'S256',
|
|
29
|
+
state: p.state,
|
|
30
|
+
}).toString();
|
|
31
|
+
return url.toString();
|
|
32
|
+
};
|
|
33
|
+
exports.build_authorize_url = build_authorize_url;
|
|
34
|
+
const html_escape = (s) => s.replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
35
|
+
// Escapes both args so any reflected value (e.g. the `error` query param) can
|
|
36
|
+
// never inject markup into the loopback page.
|
|
37
|
+
const success_page = (title, body) => `<!doctype html><meta charset="utf-8"><title>${html_escape(title)}</title>`
|
|
38
|
+
+ `<body style="font-family:system-ui;max-width:32rem;margin:4rem auto;text-align:center">`
|
|
39
|
+
+ `<h1>${html_escape(title)}</h1><p>${html_escape(body)}</p></body>`;
|
|
40
|
+
// The opener + args for a platform. On Windows we use rundll32's
|
|
41
|
+
// FileProtocolHandler rather than `cmd /c start`, because `start` treats an
|
|
42
|
+
// unquoted `&` (which every OAuth URL has) as a command separator — rundll32
|
|
43
|
+
// takes the whole URL as a single argument, so it stays intact.
|
|
44
|
+
const browser_open_command = (platform, url) => {
|
|
45
|
+
if (platform === 'darwin') {
|
|
46
|
+
return { command: 'open', args: [url] };
|
|
47
|
+
}
|
|
48
|
+
if (platform === 'win32') {
|
|
49
|
+
return { command: 'rundll32', args: ['url.dll,FileProtocolHandler', url] };
|
|
50
|
+
}
|
|
51
|
+
return { command: 'xdg-open', args: [url] };
|
|
52
|
+
};
|
|
53
|
+
exports.browser_open_command = browser_open_command;
|
|
54
|
+
// Best-effort browser launch. A headless/missing-opener box emits 'error'
|
|
55
|
+
// asynchronously; that is ignored on purpose because the caller always prints
|
|
56
|
+
// the URL for manual opening as a fallback.
|
|
57
|
+
const open_browser = (url) => {
|
|
58
|
+
const { command, args } = browser_open_command(process.platform, url);
|
|
59
|
+
const child = (0, child_process_1.spawn)(command, args, { stdio: 'ignore', detached: true });
|
|
60
|
+
child.on('error', () => { });
|
|
61
|
+
child.unref();
|
|
62
|
+
};
|
|
63
|
+
// Start a loopback listener on 127.0.0.1:<random port>, drive the browser to
|
|
64
|
+
// the authorize endpoint, and resolve with the captured authorization code.
|
|
65
|
+
const capture_code = (p) => new Promise((resolve, reject) => {
|
|
66
|
+
let redirect_uri = '';
|
|
67
|
+
let settled = false;
|
|
68
|
+
const done = (fn) => {
|
|
69
|
+
if (settled) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
settled = true;
|
|
73
|
+
clearTimeout(timer);
|
|
74
|
+
server.close();
|
|
75
|
+
fn();
|
|
76
|
+
};
|
|
77
|
+
const server = http_1.default.createServer((req, res) => {
|
|
78
|
+
const url = new url_1.URL(req.url ?? '/', 'http://127.0.0.1');
|
|
79
|
+
if (url.pathname !== '/callback') {
|
|
80
|
+
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
81
|
+
res.end('Not found');
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const code = url.searchParams.get('code');
|
|
85
|
+
const state = url.searchParams.get('state');
|
|
86
|
+
const err = url.searchParams.get('error');
|
|
87
|
+
if (err) {
|
|
88
|
+
res.writeHead(400, { 'Content-Type': 'text/html' });
|
|
89
|
+
res.end(success_page('Login failed', `The authorization server returned: ${err}`));
|
|
90
|
+
done(() => reject(new errors_1.RuntimeError(`Authorization failed: ${err}`, { code: 'oauth.authorize' })));
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (!code || state !== p.state) {
|
|
94
|
+
res.writeHead(400, { 'Content-Type': 'text/html' });
|
|
95
|
+
res.end(success_page('Login failed', 'State mismatch or missing authorization code.'));
|
|
96
|
+
done(() => reject(new errors_1.RuntimeError('OAuth state mismatch — aborting to avoid a possible CSRF.', { code: 'oauth.state' })));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
100
|
+
res.end(success_page('Login complete', 'You can close this tab and return to the terminal.'));
|
|
101
|
+
done(() => resolve({ code, redirect_uri }));
|
|
102
|
+
});
|
|
103
|
+
const timer = setTimeout(() => {
|
|
104
|
+
done(() => reject(new errors_1.RuntimeError('Timed out waiting for the browser login.', {
|
|
105
|
+
code: 'oauth.timeout',
|
|
106
|
+
hint: 'Re-run the login and complete it in the browser.',
|
|
107
|
+
})));
|
|
108
|
+
}, p.timeout_ms);
|
|
109
|
+
if (typeof timer.unref === 'function') {
|
|
110
|
+
timer.unref();
|
|
111
|
+
}
|
|
112
|
+
server.on('error', e => done(() => reject(new errors_1.RuntimeError('Could not start the loopback listener.', {
|
|
113
|
+
code: 'oauth.loopback', detail: e.message,
|
|
114
|
+
}))));
|
|
115
|
+
// Port 0 = let the OS pick a free port; use the 127.0.0.1 IP literal in
|
|
116
|
+
// the redirect (RFC 8252 §8.3) — the IS loopback validator accepts any
|
|
117
|
+
// port on the portless registration.
|
|
118
|
+
server.listen(0, '127.0.0.1', () => {
|
|
119
|
+
const addr = server.address();
|
|
120
|
+
const port = typeof addr === 'object' && addr ? addr.port : 0;
|
|
121
|
+
redirect_uri = `http://127.0.0.1:${port}/callback`;
|
|
122
|
+
const authorize_url = build_authorize_url({
|
|
123
|
+
authority: p.authority, client_id: p.client_id, redirect_uri,
|
|
124
|
+
scope: p.scope, challenge: p.challenge, state: p.state,
|
|
125
|
+
});
|
|
126
|
+
(0, output_1.info)('Opening your browser to complete sign-in…');
|
|
127
|
+
(0, output_1.info)(`If it doesn't open, visit:\n ${authorize_url}`);
|
|
128
|
+
p.open(authorize_url);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
const parse_token_error = (text) => {
|
|
132
|
+
try {
|
|
133
|
+
const j = JSON.parse(text);
|
|
134
|
+
return j.error_description || j.error || text;
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return text;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const post_token = async (authority, body) => {
|
|
141
|
+
const res = await fetch(`${authority}/connect/token`, {
|
|
142
|
+
method: 'POST',
|
|
143
|
+
headers: {
|
|
144
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
145
|
+
'Accept': 'application/json',
|
|
146
|
+
},
|
|
147
|
+
body: body.toString(),
|
|
148
|
+
});
|
|
149
|
+
const text = await res.text();
|
|
150
|
+
if (!res.ok) {
|
|
151
|
+
throw new errors_1.RuntimeError('OAuth token request failed.', {
|
|
152
|
+
code: 'oauth.token',
|
|
153
|
+
detail: `HTTP ${res.status}: ${parse_token_error(text)}`,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return JSON.parse(text);
|
|
157
|
+
};
|
|
158
|
+
const exchange_code = async (p) => {
|
|
159
|
+
const now = p.now ?? Date.now();
|
|
160
|
+
const resp = await post_token(p.authority, (0, token_1.build_token_exchange_body)({
|
|
161
|
+
code: p.code, verifier: p.verifier, redirect_uri: p.redirect_uri, client_id: p.client_id,
|
|
162
|
+
}));
|
|
163
|
+
return (0, token_1.to_oauth_record)(resp, now);
|
|
164
|
+
};
|
|
165
|
+
exports.exchange_code = exchange_code;
|
|
166
|
+
const refresh_stored = async (p) => {
|
|
167
|
+
if (!p.record.refresh_token) {
|
|
168
|
+
throw new errors_1.RuntimeError('No refresh token available.', { code: 'oauth.refresh' });
|
|
169
|
+
}
|
|
170
|
+
const now = p.now ?? Date.now();
|
|
171
|
+
const resp = await post_token(p.authority, (0, token_1.build_refresh_body)({
|
|
172
|
+
refresh_token: p.record.refresh_token, client_id: p.client_id ?? CLIENT_ID,
|
|
173
|
+
}));
|
|
174
|
+
return (0, token_1.to_oauth_record)(resp, now, p.record);
|
|
175
|
+
};
|
|
176
|
+
exports.refresh_stored = refresh_stored;
|
|
177
|
+
// Full authorization-code + PKCE loopback login. `open` is injectable so the
|
|
178
|
+
// loopback can be exercised without a real browser/IdP in tests.
|
|
179
|
+
const run_login = async (opts) => {
|
|
180
|
+
const client_id = opts.client_id ?? CLIENT_ID;
|
|
181
|
+
const scope = opts.scope ?? SCOPE;
|
|
182
|
+
const { verifier, challenge } = (0, pkce_1.create_pkce)();
|
|
183
|
+
const state = (0, pkce_1.create_state)();
|
|
184
|
+
const { code, redirect_uri } = await capture_code({
|
|
185
|
+
authority: opts.authority,
|
|
186
|
+
client_id, scope, challenge, state,
|
|
187
|
+
open: opts.open ?? open_browser,
|
|
188
|
+
timeout_ms: opts.timeout_ms ?? DEFAULT_TIMEOUT_MS,
|
|
189
|
+
});
|
|
190
|
+
return exchange_code({ authority: opts.authority, client_id, redirect_uri, code, verifier, now: opts.now });
|
|
191
|
+
};
|
|
192
|
+
exports.run_login = run_login;
|
|
193
|
+
//# sourceMappingURL=oauth-flow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-flow.js","sourceRoot":"","sources":["../../src/auth/oauth-flow.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,iDAAoC;AACpC,6BAAwB;AACxB,4CAA6C;AAC7C,4CAAqC;AACrC,iCAAiD;AACjD,mCAKiB;AAGjB,+EAA+E;AAC/E,MAAM,SAAS,GAAG,WAAW,CAAC;AA8O1B,8BAAS;AA7Ob,MAAM,KAAK,GAAG,mDAAmD,CAAC;AA6OnD,sBAAK;AA5OpB,MAAM,kBAAkB,GAAG,OAAO,CAAC,CAAG,yCAAyC;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
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.create_state = exports.create_pkce = void 0;
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
const random_url_safe = (bytes = 32) => crypto_1.default.randomBytes(bytes).toString('base64url');
|
|
9
|
+
// RFC 7636 PKCE pair: a random verifier and its S256 challenge.
|
|
10
|
+
const create_pkce = () => {
|
|
11
|
+
const verifier = random_url_safe(32);
|
|
12
|
+
const challenge = crypto_1.default.createHash('sha256').update(verifier).digest('base64url');
|
|
13
|
+
return { verifier, challenge, method: 'S256' };
|
|
14
|
+
};
|
|
15
|
+
exports.create_pkce = create_pkce;
|
|
16
|
+
// Opaque anti-CSRF value echoed back on the authorize redirect.
|
|
17
|
+
const create_state = () => random_url_safe(32);
|
|
18
|
+
exports.create_state = create_state;
|
|
19
|
+
//# sourceMappingURL=pkce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pkce.js","sourceRoot":"","sources":["../../src/auth/pkce.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAQ5B,MAAM,eAAe,GAAG,CAAC,KAAK,GAAG,EAAE,EAAS,EAAE,CAC1C,gBAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAEpD,gEAAgE;AAChE,MAAM,WAAW,GAAG,GAAQ,EAAE;IAC1B,MAAM,QAAQ,GAAG,eAAe,CAAC,EAAE,CAAC,CAAC;IACrC,MAAM,SAAS,GAAG,gBAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IACnF,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAC,CAAC;AACjD,CAAC,CAAC;AAKM,kCAAW;AAHnB,gEAAgE;AAChE,MAAM,YAAY,GAAG,GAAU,EAAE,CAAA,eAAe,CAAC,EAAE,CAAC,CAAC;AAEhC,oCAAY"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Env } from '../config';
|
|
2
|
+
type Request_identity = {
|
|
3
|
+
headers: Record<string, string>;
|
|
4
|
+
warnings: string[];
|
|
5
|
+
};
|
|
6
|
+
type Resolve_identity_input = {
|
|
7
|
+
team_id_flag?: string;
|
|
8
|
+
user_id_flag?: string;
|
|
9
|
+
user_email_flag?: string;
|
|
10
|
+
env?: Env;
|
|
11
|
+
profile_team_id?: number;
|
|
12
|
+
credential_type: 'oauth' | 'api_key';
|
|
13
|
+
};
|
|
14
|
+
declare const resolve_request_identity: (input: Resolve_identity_input) => Request_identity;
|
|
15
|
+
export { resolve_request_identity };
|
|
16
|
+
export type { Request_identity, Resolve_identity_input };
|