@getbrevo/cli 2.0.1 → 2.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/CHANGELOG.md +221 -0
- package/README.md +8 -5
- package/agent-context/AGENTS.md +59 -15
- package/agent-context/SKILL.md +70 -14
- package/dist/{templates → bin}/files/AGENTS.md.tmpl +11 -1
- package/dist/{templates → bin}/files/CLAUDE.md.tmpl +8 -0
- package/dist/{templates → bin}/files/README.md.tmpl +11 -14
- package/dist/bin/files/app-config.json.tmpl +16 -0
- package/dist/{templates → bin}/files/src/oauth/.env.example.tmpl +8 -0
- package/dist/{templates → bin}/files/src/oauth/.env.local.tmpl +2 -0
- package/dist/{templates → bin}/files/src/oauth/handler.js.tmpl +49 -7
- package/dist/{templates → bin}/files/src/oauth/server.js.tmpl +20 -14
- package/dist/{templates → bin}/files/src/oauth/token-store.js.tmpl +19 -0
- package/dist/bin/index.js +660 -221
- package/dist/bin/index.js.map +7 -1
- package/package.json +6 -4
- package/dist/api/client.d.ts +0 -25
- package/dist/api/client.d.ts.map +0 -1
- package/dist/api/client.js +0 -205
- package/dist/api/client.js.map +0 -1
- package/dist/bin/index.d.ts +0 -3
- package/dist/bin/index.d.ts.map +0 -1
- package/dist/commands/app/create.d.ts +0 -8
- package/dist/commands/app/create.d.ts.map +0 -1
- package/dist/commands/app/create.js +0 -325
- package/dist/commands/app/create.js.map +0 -1
- package/dist/commands/app/credentials.d.ts +0 -6
- package/dist/commands/app/credentials.d.ts.map +0 -1
- package/dist/commands/app/credentials.js +0 -114
- package/dist/commands/app/credentials.js.map +0 -1
- package/dist/commands/app/delete.d.ts +0 -6
- package/dist/commands/app/delete.d.ts.map +0 -1
- package/dist/commands/app/delete.js +0 -167
- package/dist/commands/app/delete.js.map +0 -1
- package/dist/commands/app/list.d.ts +0 -4
- package/dist/commands/app/list.d.ts.map +0 -1
- package/dist/commands/app/list.js +0 -71
- package/dist/commands/app/list.js.map +0 -1
- package/dist/commands/app/scaffold.d.ts +0 -5
- package/dist/commands/app/scaffold.d.ts.map +0 -1
- package/dist/commands/app/scaffold.js +0 -213
- package/dist/commands/app/scaffold.js.map +0 -1
- package/dist/commands/app/scopes.d.ts +0 -2
- package/dist/commands/app/scopes.d.ts.map +0 -1
- package/dist/commands/app/scopes.js +0 -81
- package/dist/commands/app/scopes.js.map +0 -1
- package/dist/commands/app/start.d.ts +0 -5
- package/dist/commands/app/start.d.ts.map +0 -1
- package/dist/commands/app/start.js +0 -220
- package/dist/commands/app/start.js.map +0 -1
- package/dist/commands/app/update.d.ts +0 -2
- package/dist/commands/app/update.d.ts.map +0 -1
- package/dist/commands/app/update.js +0 -444
- package/dist/commands/app/update.js.map +0 -1
- package/dist/commands/definitions.d.ts +0 -5
- package/dist/commands/definitions.d.ts.map +0 -1
- package/dist/commands/definitions.js +0 -262
- package/dist/commands/definitions.js.map +0 -1
- package/dist/commands/init.d.ts +0 -2
- package/dist/commands/init.d.ts.map +0 -1
- package/dist/commands/init.js +0 -106
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/login.d.ts +0 -6
- package/dist/commands/login.d.ts.map +0 -1
- package/dist/commands/login.js +0 -251
- package/dist/commands/login.js.map +0 -1
- package/dist/commands/logout.d.ts +0 -5
- package/dist/commands/logout.d.ts.map +0 -1
- package/dist/commands/logout.js +0 -54
- package/dist/commands/logout.js.map +0 -1
- package/dist/commands/skill/install.d.ts +0 -4
- package/dist/commands/skill/install.d.ts.map +0 -1
- package/dist/commands/skill/install.js +0 -29
- package/dist/commands/skill/install.js.map +0 -1
- package/dist/commands/skill/uninstall.d.ts +0 -4
- package/dist/commands/skill/uninstall.d.ts.map +0 -1
- package/dist/commands/skill/uninstall.js +0 -23
- package/dist/commands/skill/uninstall.js.map +0 -1
- package/dist/commands/whoami.d.ts +0 -4
- package/dist/commands/whoami.d.ts.map +0 -1
- package/dist/commands/whoami.js +0 -85
- package/dist/commands/whoami.js.map +0 -1
- package/dist/container.d.ts +0 -7
- package/dist/container.d.ts.map +0 -1
- package/dist/container.js +0 -28
- package/dist/container.js.map +0 -1
- package/dist/lang/en.d.ts +0 -161
- package/dist/lang/en.d.ts.map +0 -1
- package/dist/lang/en.js +0 -188
- package/dist/lang/en.js.map +0 -1
- package/dist/lib/abort.d.ts +0 -3
- package/dist/lib/abort.d.ts.map +0 -1
- package/dist/lib/abort.js +0 -30
- package/dist/lib/abort.js.map +0 -1
- package/dist/lib/auth-guard.d.ts +0 -3
- package/dist/lib/auth-guard.d.ts.map +0 -1
- package/dist/lib/auth-guard.js +0 -47
- package/dist/lib/auth-guard.js.map +0 -1
- package/dist/lib/browser.d.ts +0 -2
- package/dist/lib/browser.d.ts.map +0 -1
- package/dist/lib/browser.js +0 -16
- package/dist/lib/browser.js.map +0 -1
- package/dist/lib/cli-version.d.ts +0 -2
- package/dist/lib/cli-version.d.ts.map +0 -1
- package/dist/lib/cli-version.js +0 -59
- package/dist/lib/cli-version.js.map +0 -1
- package/dist/lib/command-handler.d.ts +0 -10
- package/dist/lib/command-handler.d.ts.map +0 -1
- package/dist/lib/command-handler.js +0 -16
- package/dist/lib/command-handler.js.map +0 -1
- package/dist/lib/command-registry.d.ts +0 -28
- package/dist/lib/command-registry.d.ts.map +0 -1
- package/dist/lib/command-registry.js +0 -54
- package/dist/lib/command-registry.js.map +0 -1
- package/dist/lib/config.d.ts +0 -83
- package/dist/lib/config.d.ts.map +0 -1
- package/dist/lib/config.js +0 -430
- package/dist/lib/config.js.map +0 -1
- package/dist/lib/constants.d.ts +0 -48
- package/dist/lib/constants.d.ts.map +0 -1
- package/dist/lib/constants.js +0 -121
- package/dist/lib/constants.js.map +0 -1
- package/dist/lib/errors.d.ts +0 -30
- package/dist/lib/errors.d.ts.map +0 -1
- package/dist/lib/errors.js +0 -66
- package/dist/lib/errors.js.map +0 -1
- package/dist/lib/exit-codes.d.ts +0 -9
- package/dist/lib/exit-codes.d.ts.map +0 -1
- package/dist/lib/exit-codes.js +0 -12
- package/dist/lib/exit-codes.js.map +0 -1
- package/dist/lib/hidden-input.d.ts +0 -2
- package/dist/lib/hidden-input.d.ts.map +0 -1
- package/dist/lib/hidden-input.js +0 -78
- package/dist/lib/hidden-input.js.map +0 -1
- package/dist/lib/json-output.d.ts +0 -6
- package/dist/lib/json-output.d.ts.map +0 -1
- package/dist/lib/json-output.js +0 -11
- package/dist/lib/json-output.js.map +0 -1
- package/dist/lib/logger.d.ts +0 -11
- package/dist/lib/logger.d.ts.map +0 -1
- package/dist/lib/logger.js +0 -110
- package/dist/lib/logger.js.map +0 -1
- package/dist/lib/port.d.ts +0 -25
- package/dist/lib/port.d.ts.map +0 -1
- package/dist/lib/port.js +0 -103
- package/dist/lib/port.js.map +0 -1
- package/dist/lib/telemetry.d.ts +0 -9
- package/dist/lib/telemetry.d.ts.map +0 -1
- package/dist/lib/telemetry.js +0 -57
- package/dist/lib/telemetry.js.map +0 -1
- package/dist/lib/ui.d.ts +0 -14
- package/dist/lib/ui.d.ts.map +0 -1
- package/dist/lib/ui.js +0 -75
- package/dist/lib/ui.js.map +0 -1
- package/dist/lib/update-notifier.d.ts +0 -37
- package/dist/lib/update-notifier.d.ts.map +0 -1
- package/dist/lib/update-notifier.js +0 -298
- package/dist/lib/update-notifier.js.map +0 -1
- package/dist/lib/validators.d.ts +0 -55
- package/dist/lib/validators.d.ts.map +0 -1
- package/dist/lib/validators.js +0 -166
- package/dist/lib/validators.js.map +0 -1
- package/dist/services/account.d.ts +0 -8
- package/dist/services/account.d.ts.map +0 -1
- package/dist/services/account.js +0 -15
- package/dist/services/account.js.map +0 -1
- package/dist/services/app.d.ts +0 -38
- package/dist/services/app.d.ts.map +0 -1
- package/dist/services/app.js +0 -145
- package/dist/services/app.js.map +0 -1
- package/dist/services/browser-auth.d.ts +0 -15
- package/dist/services/browser-auth.d.ts.map +0 -1
- package/dist/services/browser-auth.js +0 -188
- package/dist/services/browser-auth.js.map +0 -1
- package/dist/services/normalize-app-id.d.ts +0 -12
- package/dist/services/normalize-app-id.d.ts.map +0 -1
- package/dist/services/normalize-app-id.js +0 -38
- package/dist/services/normalize-app-id.js.map +0 -1
- package/dist/services/oauth-metadata.d.ts +0 -7
- package/dist/services/oauth-metadata.d.ts.map +0 -1
- package/dist/services/oauth-metadata.js +0 -43
- package/dist/services/oauth-metadata.js.map +0 -1
- package/dist/services/oauth-refresh.d.ts +0 -14
- package/dist/services/oauth-refresh.d.ts.map +0 -1
- package/dist/services/oauth-refresh.js +0 -70
- package/dist/services/oauth-refresh.js.map +0 -1
- package/dist/services/scopes-html.d.ts +0 -3
- package/dist/services/scopes-html.d.ts.map +0 -1
- package/dist/services/scopes-html.js +0 -516
- package/dist/services/scopes-html.js.map +0 -1
- package/dist/services/scopes-web.d.ts +0 -12
- package/dist/services/scopes-web.d.ts.map +0 -1
- package/dist/services/scopes-web.js +0 -95
- package/dist/services/scopes-web.js.map +0 -1
- package/dist/services/skill.d.ts +0 -48
- package/dist/services/skill.d.ts.map +0 -1
- package/dist/services/skill.js +0 -223
- package/dist/services/skill.js.map +0 -1
- package/dist/skills/index.d.ts +0 -47
- package/dist/skills/index.d.ts.map +0 -1
- package/dist/skills/index.js +0 -61
- package/dist/skills/index.js.map +0 -1
- package/dist/templates/files/app-config.json.tmpl +0 -25
- package/dist/templates/index.d.ts +0 -36
- package/dist/templates/index.d.ts.map +0 -1
- package/dist/templates/index.js +0 -105
- package/dist/templates/index.js.map +0 -1
- package/dist/types.d.ts +0 -32
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
- /package/dist/{templates → bin}/files/gitignore.tmpl +0 -0
- /package/dist/{templates → bin}/files/src/oauth/package.json.tmpl +0 -0
package/agent-context/SKILL.md
CHANGED
|
@@ -7,6 +7,18 @@ description: Use when working in a project that uses the Brevo Developer CLI (th
|
|
|
7
7
|
|
|
8
8
|
This project uses the Brevo Developer CLI to create and manage Brevo OAuth applications. Treat the `brevo` binary as the canonical entry point — don't shell out to `curl https://api.brevo.com/...` for things the CLI already covers.
|
|
9
9
|
|
|
10
|
+
## `brevo --help` is the source of truth
|
|
11
|
+
|
|
12
|
+
Brevo features that haven't been released are **not built into the published CLI at all** — not as hidden commands, not behind a flag or an env var. `brevo --help` and `brevo app --help` list everything the binary can do. Treat that as the complete surface and build from it.
|
|
13
|
+
|
|
14
|
+
What this means in practice:
|
|
15
|
+
|
|
16
|
+
- **If a command isn't in `--help`, it doesn't exist here.** Invoking it gives Commander's `unknown command` and exit `1`. That is a final answer, not a transient failure and not a permissions problem — there is no flag, config edit, account setting, or environment variable that reveals it. Don't retry, don't hunt for an alternative route, and don't tell the user to get access. Say the feature isn't available in this CLI and offer the nearest thing that works.
|
|
17
|
+
- **Don't act on a command you remember rather than one you can see.** Your recollection of the Brevo CLI may include commands from a newer or unreleased build. `--help` in the current session is the only reliable source.
|
|
18
|
+
- **A flag can be rejected even when its command exists.** `--distribution` is a real flag, but a value tied to an unreleased feature is refused with *"That command is not available yet. It is part of a Brevo feature that has not been released."* Same rule: it's final. Use `--distribution private`.
|
|
19
|
+
|
|
20
|
+
The Brevo API enforces the same boundaries independently, so nothing is gained by trying to route around the CLI — a hand-rolled `curl` hits the platform's own refusal.
|
|
21
|
+
|
|
10
22
|
> **Reading this from the repo rather than `~/.claude/skills/brevo-cli/`?**
|
|
11
23
|
>
|
|
12
24
|
> - **If you're Claude Code** (CLI or desktop app — any agent that reads `~/.claude/skills/`): install it as a skill with `brevo skill:cli install` so your tooling loads it natively and keeps it auto-refreshed. The repo copy is bundled with the npm package; the installed copy is what Claude actually consumes. Note: the Claude Desktop **chat** app does not read `~/.claude/skills/`, so the installed skill won't load there — only Claude Code surfaces pick it up.
|
|
@@ -40,54 +52,98 @@ Don't fall back to raw HTTP against `api.brevo.com` — the `brevo` binary is th
|
|
|
40
52
|
- "Authenticate" → `brevo login` (or `BREVO_API_KEY=xkeysib-... brevo login` for CI)
|
|
41
53
|
- "Who am I logged in as?" → `brevo whoami --json`
|
|
42
54
|
- "Show / pick an app" → `brevo app list --json`
|
|
43
|
-
- "Create an app" → `brevo app create --name "<name>" --distribution private --redirect-uri <url> --json` (add `--logo-uri <https://…>` to set the app logo at creation time; new apps default to scopes `contacts:read`, `contacts:write`, `crm:read`, `crm:write`).
|
|
44
|
-
- "Update app metadata" → `brevo app
|
|
45
|
-
- "Get client credentials" → `brevo app credentials --app-id <id> --json` (add `--reveal-secret` to print the secret)
|
|
46
|
-
- "
|
|
55
|
+
- "Create an app" → `brevo app create --name "<name>" --distribution private --redirect-uri <url> --json` (add `--logo-uri <https://…>` to set the app logo at creation time; new apps default to scopes `contacts:read`, `contacts:write`, `crm:read`, `crm:write`). **Use `--distribution private`** — check `brevo app create --help` for the values your account accepts, and don't pass one it doesn't list. **Fails immediately if run from a directory that already has `app-config.json`** — `cd` elsewhere first, or use `brevo app scaffold` in that directory instead. Otherwise resolves (creates/`cd`s into) its target directory, creates the app, and writes the **basic project structure** (`app-config.json` + `.gitignore`/`AGENTS.md`/`CLAUDE.md`/`README.md`). It scaffolds a feature (the OAuth test server) **only** when the interactive confirm (*"Scaffold the Test OAuth App?"*, default yes) is answered yes — there is no separate "which feature?" question while the CLI ships one; **non-interactive runs (`--json` or piped) stay base-only** — run `brevo app scaffold` afterward to add the OAuth code. Under `--json`, the response's `directory` field is where it landed and `scaffolded` is the base file count; check for `scaffoldSkipped` instead of `scaffolded` if that directory already existed (both directory setup and scaffolding are skipped together in that case, but the app is still created).
|
|
56
|
+
- "Update app metadata" → edit the relevant field(s) in `app-config.json` (`appName`, `auth.redirectUris`, `auth.scopes`, `logoUri`, `version`) (older projects may still say `auth.redirectUrls` — the CLI reads it and migrates the file to `redirectUris` on its next write), then run `brevo app upload --json` (no `--app-id`/`--name`/`--redirect-uri`/`--scope`/`--logo-uri` flags exist — `upload` always pushes the whole file, resolved only from cwd's `app-config.json`). **`distribution_type` is immutable** — it's set at `app create` time and cannot be changed via `upload`; if the local value differs from the server, `upload` errors and tells you to restore it (create a new app to get a different distribution). **There is no `brevo app update`** — it was removed, with no shim and no flag-for-flag equivalent; if you find it in a user's script, CI job, README, or your own recollection, replace it with the edit-then-`upload` flow above. Invoking it — with any of the old flags, with `--help`, or as `brevo app help update` — prints a message naming `brevo app upload` and exits `1` **without uploading anything**, so a `1` from `brevo app update` means the command is gone, not that an upload failed.
|
|
57
|
+
- "Get client credentials" → `brevo app credentials --app-id <id> --json` (add `--reveal-secret` to print the secret). **`--app-id` is not optional here** — without it the command wants an interactive app picker, and under `--json`/off a TTY it refuses with exit `1` rather than prompting.
|
|
58
|
+
- "Set up a project for an app that already exists" → `brevo app scaffold --app-id <id>` (`brevo app list` gives the IDs). Fetches the app and writes `app-config.json` + the base files, then adds a feature as below. Interactively it asks which directory to write into first (default `./<slugified app name>`); under `--json`/off a TTY it uses the current one. **This is the only way to get an `app-config.json` for an existing app** — `brevo app create` makes a *new* app, and `brevo app upload` only ever reads the project in the current directory. It refuses if the directory is already linked to a *different* app; pointing it at the app the directory is already linked to is a no-op. **Interactively you can omit `--app-id`**: plain `brevo app scaffold` in a directory with no `app-config.json` says so, asks *"Set up a project for an app you already have?"* (default yes), and on yes lists the account's apps so you can pick one — no need to look the ID up first. **Every interactive bootstrap (picker or `--app-id`) then asks `Output directory:`, defaulted to `./<the app's name slugified>`** — the same question `brevo app create` asks — creates that directory and `cd`s into it, so the files don't land in whatever folder you happened to be standing in; answer `.` to use the current directory instead. It then writes the project (`app-config.json` + the base files), shows what it wrote, and asks *"Scaffold the Test OAuth App?"* (default yes) — declining is normal and leaves the project in place, exit `0`. The *Next steps* box opens with `cd <dir>`, because the CLI can only move its own process, never your shell. **Under `--json` or off a TTY there is no directory question and the files go into the current directory**, so scripted `brevo app scaffold --app-id <id>` runs are unchanged — `mkdir` and `cd` yourself first if you want them somewhere specific. Answering **no** is a normal outcome, not an error: it exits `0` after printing the remaining routes (`brevo app create` here, or `cd` into an existing project). **Always pass `--app-id` when scripting** — the offer needs a terminal, so under `--json` or off a TTY the command errors instead of prompting. **If the directory you point it at already holds a project, the bootstrap is a refresh, not a fresh write**: the config found there is diffed against the server and rewritten only on consent (*"…will update app-config.json to match the server. Continue?"*, default yes) — answering **Merge** at the directory question does not suppress that, because merging keeps the file that exists and so would skip the very file a bootstrap is for. No drift means `app-config.json` is left alone with a one-line notice, and the feature still gets added. A directory holding a project for a **different** app is refused outright, naming both apps. Two refusals apply to both forms, before any write: that different-app case, and the directory must not be **inside** an existing project (a nested second `app-config.json` would make a later `brevo app upload` push the wrong app).
|
|
59
|
+
- "Add a feature (e.g. the OAuth test server) to an existing project" → `brevo app scaffold` (run **inside** the project directory; it reads the linked app from `app-config.json`, so `--app-id` is only needed to bootstrap a directory that has none). Not needed right after `app create` if you already accepted the feature prompt there. If feature files already exist it prompts Overwrite / Merge / Cancel (default Merge); pass `--overwrite` to force a full overwrite without prompting. **The scaffolded OAuth flow is the confidential-client flow:** `/auth/callback` authenticates the token exchange with the `CLIENT_SECRET` written into the scaffolded `.env.local`.
|
|
47
60
|
- "Run the OAuth test server" → `brevo app start oauth --port 3009` (must be inside the scaffolded directory)
|
|
48
|
-
- "Delete an app" → `brevo app delete --app-id <id> --force`
|
|
61
|
+
- "Delete an app" → `brevo app delete --app-id <id> --force`. **`--app-id` is not optional here either** — omitting it means an interactive picker, which under `--json`/off a TTY is refused with exit `1`. Never script a delete without naming the app.
|
|
49
62
|
- "List supported OAuth scopes" → `brevo app available-scopes --json`
|
|
50
63
|
- "Sign out" → `brevo logout --force`
|
|
51
64
|
|
|
52
65
|
## Hard rules
|
|
53
66
|
|
|
54
|
-
1. **Always pass `--json`** when you intend to parse output. Every command supports it.
|
|
67
|
+
1. **Always pass `--json`** when you intend to parse output. Every command supports it, **on success and on failure alike** — a failing `--json` run writes a single `{"error": {...}}` document to stdout (see *JSON errors* below), so you can read the reason instead of only seeing a non-zero exit.
|
|
55
68
|
2. **Never print, log, or commit** API keys (`xkeysib-…`), client secrets, refresh tokens, or contents of `~/.brevo/credentials.json` / `.env.local`. Redact before sharing diagnostics.
|
|
56
69
|
3. **Don't use `--api-key`** — the flag was removed. Use the `BREVO_API_KEY` env var.
|
|
57
|
-
4.
|
|
70
|
+
4. **`brevo app create` refuses to run inside an already-linked directory** (`app-config.json` present) — `cd` elsewhere or use `brevo app scaffold` there instead. **`brevo app scaffold` requires an `app-config.json` in the current directory unless you pass `--app-id` or answer its bootstrap offer** (it adds a feature to an already-created project); with none present and no `--app-id` it offers to set the directory up for an existing app when interactive, and otherwise errors, listing the three ways out (`cd` into a project, `--app-id` to set this directory up for an app you already have, or `brevo app create` for a new one). With `--app-id <id>` in a directory that has no config it fetches that app, asks (interactively only) which directory to write into — default `./<slugified app name>`, `.` to stay put — writes `app-config.json` + the base files there, and continues; that is the migration path off the removed `brevo app update --app-id`, and off a TTY or under `--json` it writes into the current directory with no prompt. If the directory it is told to write into already holds a project for the **same** app, it diffs that config against the server and rewrites it only on consent — the directory prompt's **Merge** answer does not silently skip the refresh, and no drift leaves `app-config.json` untouched with a notice. It refuses (before any network call) if the directory is already linked to a *different* app — whether that is the directory the command ran in or the one it was pointed at — or if the directory is **inside** an existing app project (a nested second `app-config.json` would make a later `brevo app upload` from there push the wrong app — `cd` to the project root or outside it). It reads the linked app from that config, diffs the config against the server, and if fields drifted it tells you and (on consent) rewrites `app-config.json` to match before writing the feature files. When any feature file already exists it prompts **Overwrite / Merge / Cancel** (default **Merge** — existing, e.g. hand-edited, files are kept; Cancel aborts). Pass `--overwrite` to force a full overwrite and skip that prompt (works interactively and under `--json`). **Under `--json` it never prompts**: a config diff comes back as `{ "cancelled": true, "reason": "...", "diffs": [...] }`; otherwise it scaffolds the feature (merging existing files unless `--overwrite` is passed) and returns `{ "scaffolded": <n>, "directory": "..." }`.
|
|
58
71
|
5. **Prefer flag-driven over interactive** in agent contexts: `--name`, `--app-id`, `--force`, `--yes` so the command doesn't block on prompts.
|
|
72
|
+
6. **Write only the `app-config.json` keys this file documents.** `brevo app upload` validates the whole file and rejects keys it doesn't recognise, so an invented block fails at upload rather than doing anything useful.
|
|
59
73
|
|
|
60
74
|
## Locating the linked app
|
|
61
75
|
|
|
62
|
-
If `app-config.json` exists in the working directory, it pins the app — `brevo app
|
|
76
|
+
If `app-config.json` exists in the working directory, it pins the app — `brevo app upload` and `brevo app start` use it automatically. `brevo app start` accepts an `--app-id` override to target a different app; `upload` does **not** — it only ever reads cwd's `app-config.json`, hard-erroring if that file is missing, invalid, or lacks `appId`.
|
|
77
|
+
|
|
78
|
+
`app-config.json` carries an optional top-level `logoUri` string. When set, `brevo app upload` pushes it as `logo_uri`; when empty / absent, the field is left untouched on the API.
|
|
79
|
+
|
|
80
|
+
`app-config.json` also carries a top-level `version` string, shown by `brevo app create`/`brevo app list`. `brevo app upload` sends it on the wire as `version` (falling back to the server's current value if locally absent) and writes back whatever version the server confirms after a successful upload.
|
|
63
81
|
|
|
64
|
-
`app-config.json`
|
|
82
|
+
`brevo app credentials` also backfills a legacy `app-config.json` toward the current shape: when the file exists in cwd and its `appId` matches the app being inspected, any missing top-level `version` / `distribution_type` is filled in from the server (fill-only-when-missing — an existing local value is never overwritten). This runs silently in all modes; human output prints a one-line note when something was written. It's how projects that are never `upload`ed still converge.
|
|
65
83
|
|
|
66
84
|
## Scopes
|
|
67
85
|
|
|
68
|
-
- New apps created via `brevo app create` default to `contacts:read`, `contacts:write`, `crm:read`, `crm:write`. The CLI prints the default set on success and points to `brevo app
|
|
69
|
-
-
|
|
86
|
+
- New apps created via `brevo app create` default to `contacts:read`, `contacts:write`, `crm:read`, `crm:write`. The CLI prints the default set on success and points to editing `app-config.json` + `brevo app upload` for changes.
|
|
87
|
+
- To add, remove, or change scopes: edit `auth.scopes` in `app-config.json` directly, then run `brevo app upload`. Comma- or whitespace-separated values are normalized on read, whether they sit in a single array entry (`["crm:read", "crm:write, campaigns:read"]`) or replace the array entirely (`"crm:write, campaigns:read"`) — either becomes two scopes. To see what's currently set, run `brevo app credentials --app-id <id> --json`.
|
|
70
88
|
- `brevo app available-scopes [--json] [--web]` lists the OAuth scopes the IdP currently supports. It reads a **public** catalog and works **without `brevo login`** (no API key needed). Text output groups names by category (e.g. `account`, `data_crm`, `messaging`); `--json` returns a flat `{ scopes: string[] }` of names. OIDC-reserved scopes (`openid`, `profile`, `email`, `offline_access`) and magic wildcards are excluded. The CLI validates scope **format** locally (must match `[A-Za-z0-9][A-Za-z0-9:_.-]*`) but does **not** validate that a scope is recognized by the IdP — use `app available-scopes` to confirm spelling before passing an unfamiliar scope.
|
|
71
89
|
- Passing `--web` to `brevo app available-scopes` **also opens a browser** to a styled local page (loopback `http://127.0.0.1:<port>/`) and stays running until Ctrl+C. Without `--web` the command exits after printing the list — TTY detection no longer triggers the browser. `--json` always suppresses the browser, so agent invocations using `--json` behave the same regardless of `--web`.
|
|
72
90
|
|
|
73
91
|
### Legacy `'all'` scope deprecation
|
|
74
92
|
|
|
75
|
-
The legacy catch-all `'all'` OAuth scope is deprecated. The CLI **blocks** `brevo app
|
|
93
|
+
The legacy catch-all `'all'` OAuth scope is deprecated. The CLI **blocks** `brevo app upload` and `brevo app start oauth` when scopes still contain `'all'` (no escape hatch, no silent rewrite); the only mutating path that proceeds is editing `auth.scopes` in `app-config.json` and running `upload`. To handle a legacy app:
|
|
76
94
|
|
|
77
95
|
1. **Detect** `'all'` in `auth.scopes` of a local `app-config.json`, or on a remote app via `brevo app list --json` — affected apps carry `"legacy_all_scope": true` (text output appends `(legacy 'all' — deprecated)` to the scopes line).
|
|
78
96
|
2. **Prompt the user to pick granular scopes** — use `brevo app available-scopes --json` for the catalog, or fall back to the four defaults (`contacts:read`, `contacts:write`, `crm:read`, `crm:write`).
|
|
79
|
-
3. **Migrate**
|
|
97
|
+
3. **Migrate** by editing `auth.scopes` in `app-config.json` to replace `'all'` with the granular scopes your integration uses, then run `brevo app upload` (the summary shows a "Migrating from legacy 'all' scope" line and `all (removed)`).
|
|
80
98
|
|
|
81
|
-
`
|
|
99
|
+
Writing `app-config.json` for an app whose remote scopes contain `'all'` never propagates it: the file keeps the app's remaining granular scopes (or the four default scopes when `'all'` was the only scope), with a one-line substitution notice (suppressed under `--json`). This applies when `brevo app create` writes the base config, and when `brevo app scaffold` rewrites it after a detected server drift. Note the substitution is local-only — the remote app still needs the `app-config.json` edit + `brevo app upload` migration above.
|
|
82
100
|
|
|
83
101
|
## Exit codes
|
|
84
102
|
|
|
85
103
|
`0` success · `1` general error · `2` aborted · `3` auth failure · `4` network · `5` not found.
|
|
86
104
|
|
|
105
|
+
## JSON errors
|
|
106
|
+
|
|
107
|
+
Under `--json`, a command that fails writes **one** JSON document to stdout describing the failure, and the human-readable message still goes to stderr. The `error` key is the discriminator — no success payload has one:
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{ "error": { "name": "CliError", "message": "Not authenticated. Run: brevo login", "exitCode": 1 } }
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
`name` is the error class (`CliError`, `ApiError`, `AuthExpiredError`, `AbortError`), `message` is the same text printed to stderr, and `exitCode` matches the process exit code. An `ApiError` adds `statusCode` (the HTTP status) and, when the API classified the failure, `code` — one of `AUTH_INVALID`, `AUTH_EXPIRED`, `ACCESS_DENIED`, `APP_NOT_FOUND`, `REDIRECT_INVALID`, `PORT_IN_USE`, `NETWORK_ERROR`, `RATE_LIMITED`, `APP_LIMIT_REACHED`, `REGISTRY_ERROR`, `AUTH_GATEWAY`:
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
{ "error": { "name": "ApiError", "message": "App not found", "exitCode": 5, "code": "APP_NOT_FOUND", "statusCode": 404 } }
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Two things to rely on: stdout is always **exactly one** parseable document, and commands that describe their own failure keep doing so instead of emitting this envelope — `brevo whoami --json` still returns `{"authenticated": false, "reason": "no_key"}` (exit `1`). Check for `error` first, then fall back to the command's own shape.
|
|
120
|
+
|
|
121
|
+
## Command help
|
|
122
|
+
|
|
123
|
+
`brevo --help` prints the grouped overview of every command. `brevo <command> --help` prints that command's own usage line, arguments, flags, and examples — e.g. `brevo app scaffold --help` documents `--app-id` / `--overwrite` / `--json`. When you need to confirm a flag exists on the version actually installed, read it from there rather than assuming from this file.
|
|
124
|
+
|
|
87
125
|
## Forced update
|
|
88
126
|
|
|
89
127
|
When the installed CLI is a full **major** version behind the latest npm release, every command except `--help` / `--version` prints a blocking update banner to stderr and exits `1` **without running** — so a `brevo` call that suddenly exits `1` with an update banner means the CLI must be upgraded (`npm install -g @getbrevo/cli` or `yarn global add @getbrevo/cli`) before it will work. The gate honors the same opt-outs as the soft update notice (`BREVO_NO_UPDATE_NOTIFIER=1`, `--no-update-notifier`, CI, non-TTY), so it never fires in those contexts.
|
|
90
128
|
|
|
129
|
+
## Update notice wording
|
|
130
|
+
|
|
131
|
+
The update banner's first line comes from the app-store service (`GET /cli/info`). It is called directly rather than through the v3 API gateway and requires no API key, so it works while logged out or with expired credentials. It runs once per invocation, **before** the command, and the response is cached at `~/.brevo/cli-info-cache.json` for **15 minutes**, keyed to the installed `cliVersion` — so reworded text or a new block reaches the CLI within minutes rather than after the old 12h npm-style TTL, without a network call on every single command. Whether an update banner appears is still decided from the npm registry, exactly as before, and a failed call just means the banner uses local wording (a failed call never overwrites a good cache entry). `BREVO_APP_STORE_URL` overrides that service's base URL for non-production testing.
|
|
132
|
+
|
|
133
|
+
## Server-side block
|
|
134
|
+
|
|
135
|
+
The same response may carry `"is_blocked": true`. When it does, every command except `--help` / `--version` prints a banner to stderr and exits `1` **without running** — a separate mechanism from the major-version gate above, and one the server can turn on without shipping a new CLI.
|
|
136
|
+
|
|
137
|
+
Those two are exempt from the **block**, not from the lookup: they still call `/cli/info` and still render the server's wording on their update banner. They simply never exit non-zero because of it, so a blocked CLI can always still report what version it is.
|
|
138
|
+
|
|
139
|
+
Two things to know when you hit this:
|
|
140
|
+
|
|
141
|
+
- **The notice opt-outs do not apply.** `BREVO_NO_UPDATE_NOTIFIER=1`, `--no-update-notifier`, CI, and a non-TTY all suppress the *notice*; none of them suppress a block. Don't suggest them as a workaround — the only fix is upgrading the CLI.
|
|
142
|
+
- **It fails open.** A timeout, a non-2xx, or an unparseable body lets the command run normally; only a literal `true` blocks. So a network problem never manifests as a block.
|
|
143
|
+
- **A block can persist up to 15 minutes after the server lifts it, and vice versa**, because the whole response is cached. If you need a verdict that reflects the server's *current* state, delete `~/.brevo/cli-info-cache.json` (or bump the version) before checking.
|
|
144
|
+
|
|
145
|
+
The soft (non-blocking) notice also prints after a command **fails**, not just after it succeeds — so stderr can hold the error message followed by the update box. This does not change exit codes: a failing command still exits with its own code, and the box is never printed twice in one run. A Ctrl-C abort skips it. If you parse stderr strictly, suppress the notice with `BREVO_NO_UPDATE_NOTIFIER=1` or `--no-update-notifier`.
|
|
146
|
+
|
|
91
147
|
## Before sharing or committing output
|
|
92
148
|
|
|
93
149
|
* [ ] No `xkeysib-…` API keys, client secrets, refresh tokens, or contents of `~/.brevo/credentials.json` / `.env.local` in messages, logs, or diffs.
|
|
@@ -33,11 +33,21 @@ Implements the authorization code flow to obtain access tokens for the Brevo API
|
|
|
33
33
|
- Other grant types supported by the Brevo OAuth server but not wired into this scaffold: `client_credentials`
|
|
34
34
|
|
|
35
35
|
## OAuth flow
|
|
36
|
+
{{#if private}}
|
|
36
37
|
1. `/auth/login` — generates CSRF state, redirects user to `{OAUTH_BASE}/realms/{realm}/oauth/authorize`
|
|
37
38
|
2. User authorizes -> OAuth server redirects to `/auth/callback` with an auth code
|
|
38
|
-
3. Server validates state, exchanges code for access + refresh tokens via `POST /realms/{realm}/oauth/token`
|
|
39
|
+
3. Server validates state, exchanges code for access + refresh tokens via `POST /realms/{realm}/oauth/token` (authenticated with `client_secret`)
|
|
39
40
|
4. Verifies connection via `GET /realms/{realm}/oauth/userinfo`
|
|
40
41
|
5. `/auth/refresh` — refreshes tokens using `refresh_token` grant
|
|
42
|
+
{{/if}}
|
|
43
|
+
{{#if public}}
|
|
44
|
+
This is a **public app** — the flow uses **PKCE (RFC 7636)** and sends **no `client_secret`**:
|
|
45
|
+
1. `/auth/login` — generates CSRF state + a PKCE `code_verifier`, then redirects user to `{OAUTH_BASE}/realms/{realm}/oauth/authorize` with `code_challenge` (S256) + `code_challenge_method=S256`
|
|
46
|
+
2. User authorizes -> OAuth server redirects to `/auth/callback` with an auth code
|
|
47
|
+
3. Server validates state, exchanges code + `code_verifier` (no `client_secret`) for access + refresh tokens via `POST /realms/{realm}/oauth/token`
|
|
48
|
+
4. Verifies connection via `GET /realms/{realm}/oauth/userinfo`
|
|
49
|
+
5. `/auth/refresh` — refreshes tokens using `refresh_token` grant (no `client_secret`)
|
|
50
|
+
{{/if}}
|
|
41
51
|
|
|
42
52
|
## Development
|
|
43
53
|
```bash
|
|
@@ -47,9 +47,17 @@ brevo app start oauth # port is read from app-config.json; override with
|
|
|
47
47
|
| `GET /realms/{realm}/.well-known/openid-configuration` | OIDC discovery |
|
|
48
48
|
|
|
49
49
|
## Key flows
|
|
50
|
+
{{#if private}}
|
|
50
51
|
- `/auth/login` — generates random CSRF state, redirects to OAuth authorize endpoint
|
|
51
52
|
- `/auth/callback` — validates state, POSTs code to `/realms/{realm}/oauth/token`, stores tokens
|
|
52
53
|
- `/auth/refresh` — refreshes tokens using `refresh_token` grant
|
|
54
|
+
{{/if}}
|
|
55
|
+
{{#if public}}
|
|
56
|
+
This is a **public app**, so the flow uses **PKCE (RFC 7636)** and no client secret:
|
|
57
|
+
- `/auth/login` — generates random CSRF state **and a PKCE `code_verifier`**, then redirects to the OAuth authorize endpoint sending `code_challenge` (S256 hash of the verifier) + `code_challenge_method=S256`. The verifier is stored server-side and never sent to the browser.
|
|
58
|
+
- `/auth/callback` — validates state, POSTs code **plus the `code_verifier`** (no `client_secret`) to `/realms/{realm}/oauth/token`, stores tokens
|
|
59
|
+
- `/auth/refresh` — refreshes tokens using the `refresh_token` grant (no `client_secret`)
|
|
60
|
+
{{/if}}
|
|
53
61
|
|
|
54
62
|
## Next steps
|
|
55
63
|
- Replace the in-memory token store in `src/oauth/token-store.js` with a real database (the global singleton is process-local so data is lost on restart, and it is not session-isolated, so multiple users/sessions/tabs can read or overwrite the same in-memory tokens)
|
|
@@ -55,28 +55,25 @@ Brevo OAuth integration for testing and implementing app authorization flows, sc
|
|
|
55
55
|
|
|
56
56
|
## Updating your app
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
`brevo app upload` has no edit flags — it always pushes the full contents of `app-config.json`. To change something, edit the file, then run:
|
|
59
59
|
|
|
60
60
|
```bash
|
|
61
|
-
brevo app
|
|
62
|
-
brevo app update --redirect-url https://myapp.com/callback
|
|
63
|
-
brevo app update --name "New Name" --redirect-url https://myapp.com/callback
|
|
64
|
-
brevo app update --logo-uri https://example.com/logo.png
|
|
61
|
+
brevo app upload
|
|
65
62
|
```
|
|
66
63
|
|
|
67
|
-
|
|
64
|
+
For example, to rename the app or add a redirect URL, edit `appName` or `auth.redirectUris` in `app-config.json`:
|
|
68
65
|
|
|
69
|
-
|
|
66
|
+
```bash
|
|
67
|
+
# 1. Edit app-config.json (e.g. change "appName", or append to "auth.redirectUris")
|
|
68
|
+
# 2. Push the change
|
|
69
|
+
brevo app upload
|
|
70
|
+
```
|
|
70
71
|
|
|
71
|
-
|
|
72
|
-
- Run `brevo app update` **without flags** to replace the remote configuration with the local file.
|
|
73
|
-
- When flags are provided, the local `app-config.json` is updated automatically after a successful API call.
|
|
72
|
+
`brevo app upload` always fetches the current server state first and shows a diff before pushing — review it before confirming (or pass `--yes` to skip the prompt).
|
|
74
73
|
|
|
75
|
-
|
|
74
|
+
To avoid unintentionally accumulating stale redirect URLs over time, periodically review `auth.redirectUris` in `app-config.json` and remove obsolete entries before running `brevo app upload`.
|
|
76
75
|
|
|
77
|
-
|
|
78
|
-
brevo app update --app-id {{APP_ID}} --name "New Name"
|
|
79
|
-
```
|
|
76
|
+
`brevo app upload` has no `--app-id` flag — it always resolves the app from this directory's `app-config.json`. To manage a different app, `cd` into that app's project directory (or use `brevo app credentials --app-id <id>` to inspect it without editing).
|
|
80
77
|
|
|
81
78
|
## Docs
|
|
82
79
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"appId": "{{APP_ID}}",
|
|
3
|
+
"appName": "{{APP_NAME}}",
|
|
4
|
+
"version": "{{APP_VERSION}}",
|
|
5
|
+
"logoUri": "{{LOGO_URI}}",
|
|
6
|
+
"distribution_type": "{{DISTRIBUTION}}",
|
|
7
|
+
{{#if ui_app}}
|
|
8
|
+
"ui_app": {{UI_APP_JSON}},
|
|
9
|
+
{{/if}}
|
|
10
|
+
"auth": {
|
|
11
|
+
{{#if oauth}}
|
|
12
|
+
"scopes": {{SCOPES_JSON}},
|
|
13
|
+
"redirectUris": {{REDIRECT_URLS_JSON}}
|
|
14
|
+
{{/if}}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
# Brevo OAuth Credentials — copy this file to .env.local and fill in your values
|
|
2
|
+
{{#if private}}
|
|
2
3
|
# Get CLIENT_ID and CLIENT_SECRET: brevo app credentials --reveal-secret
|
|
4
|
+
{{/if}}
|
|
5
|
+
{{#if public}}
|
|
6
|
+
# Get CLIENT_ID: brevo app credentials
|
|
7
|
+
# This is a public app — it uses PKCE (RFC 7636) and no client secret.
|
|
8
|
+
{{/if}}
|
|
3
9
|
|
|
4
10
|
CLIENT_ID=your_client_id_here
|
|
11
|
+
{{#if private}}
|
|
5
12
|
CLIENT_SECRET=your_client_secret_here
|
|
13
|
+
{{/if}}
|
|
6
14
|
REDIRECT_URI={{REDIRECT_URI}}
|
|
7
15
|
|
|
8
16
|
# OAuth server
|
|
@@ -38,7 +38,9 @@ const REVEAL_SCRIPT =
|
|
|
38
38
|
'<script>document.querySelectorAll(".reveal-btn").forEach(function(btn){btn.addEventListener("click",function(){btn.parentElement.querySelector(".token-value").classList.add("revealed");btn.classList.add("hidden")})});</script>';
|
|
39
39
|
|
|
40
40
|
const CLIENT_ID = process.env.CLIENT_ID;
|
|
41
|
+
{{#if private}}
|
|
41
42
|
const CLIENT_SECRET = process.env.CLIENT_SECRET;
|
|
43
|
+
{{/if}}
|
|
42
44
|
const REDIRECT_URI = process.env.REDIRECT_URI || '{{REDIRECT_URI}}';
|
|
43
45
|
const OAUTH_BASE = process.env.OAUTH_BASE || '{{OAUTH_BASE}}';
|
|
44
46
|
const OAUTH_REALM = process.env.OAUTH_REALM || '{{OAUTH_REALM}}';
|
|
@@ -55,19 +57,48 @@ try {
|
|
|
55
57
|
console.warn('Warning: Could not read app-config.json — defaulting scopes to "all".');
|
|
56
58
|
}
|
|
57
59
|
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
// Build the OAuth authorization URL. Extracted so /auth/login and the
|
|
61
|
+
// server.js landing page render the exact same URL — no drift between the two.
|
|
62
|
+
{{#if public}}
|
|
63
|
+
// `codeChallenge` is the PKCE (RFC 7636) S256 challenge. Base64url output is
|
|
64
|
+
// already URL-safe, so it is not re-encoded (matching the `state` treatment).
|
|
65
|
+
function buildAuthorizeUrl({ state, codeChallenge }) {
|
|
66
|
+
{{/if}}
|
|
67
|
+
{{#if private}}
|
|
68
|
+
function buildAuthorizeUrl({ state }) {
|
|
69
|
+
{{/if}}
|
|
70
|
+
let authUrl = `${realmPath}/authorize?` +
|
|
64
71
|
`response_type=code` +
|
|
65
72
|
`&client_id=${encodeURIComponent(CLIENT_ID)}` +
|
|
66
73
|
`&redirect_uri=${encodeURIComponent(REDIRECT_URI)}` +
|
|
67
74
|
`&state=${state}` +
|
|
68
75
|
`&scope=${encodeURIComponent(SCOPES)}`;
|
|
76
|
+
{{#if public}}
|
|
77
|
+
authUrl += `&code_challenge=${codeChallenge}&code_challenge_method=S256`;
|
|
78
|
+
{{/if}}
|
|
79
|
+
return authUrl;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Step 1: Redirect user to authorization page
|
|
83
|
+
router.get('/login', (req, res) => {
|
|
84
|
+
const crypto = require('crypto');
|
|
85
|
+
const state = crypto.randomBytes(16).toString('hex');
|
|
86
|
+
tokenStore.setState(state);
|
|
87
|
+
{{#if public}}
|
|
88
|
+
|
|
89
|
+
// PKCE (RFC 7636): create a high-entropy verifier, keep it server-side, and
|
|
90
|
+
// send only its SHA-256 (S256) hash on the authorize request. The verifier
|
|
91
|
+
// itself is presented only later, on the token exchange in /auth/callback.
|
|
92
|
+
const codeVerifier = crypto.randomBytes(32).toString('base64url');
|
|
93
|
+
const codeChallenge = crypto.createHash('sha256').update(codeVerifier).digest('base64url');
|
|
94
|
+
tokenStore.setVerifier(codeVerifier);
|
|
95
|
+
|
|
96
|
+
res.redirect(buildAuthorizeUrl({ state, codeChallenge }));
|
|
97
|
+
{{/if}}
|
|
98
|
+
{{#if private}}
|
|
69
99
|
|
|
70
|
-
res.redirect(
|
|
100
|
+
res.redirect(buildAuthorizeUrl({ state }));
|
|
101
|
+
{{/if}}
|
|
71
102
|
});
|
|
72
103
|
|
|
73
104
|
// Step 2: Handle the OAuth callback
|
|
@@ -94,7 +125,14 @@ router.get('/callback', async (req, res) => {
|
|
|
94
125
|
new URLSearchParams({
|
|
95
126
|
grant_type: 'authorization_code',
|
|
96
127
|
client_id: CLIENT_ID,
|
|
128
|
+
{{#if private}}
|
|
97
129
|
client_secret: CLIENT_SECRET,
|
|
130
|
+
{{/if}}
|
|
131
|
+
{{#if public}}
|
|
132
|
+
// PKCE (RFC 7636): prove possession of the verifier generated in /login.
|
|
133
|
+
// Public clients hold no secret, so this replaces client_secret entirely.
|
|
134
|
+
code_verifier: tokenStore.getVerifier(),
|
|
135
|
+
{{/if}}
|
|
98
136
|
code,
|
|
99
137
|
redirect_uri: REDIRECT_URI,
|
|
100
138
|
}),
|
|
@@ -165,7 +203,9 @@ router.get('/refresh', async (req, res) => {
|
|
|
165
203
|
new URLSearchParams({
|
|
166
204
|
grant_type: 'refresh_token',
|
|
167
205
|
client_id: CLIENT_ID,
|
|
206
|
+
{{#if private}}
|
|
168
207
|
client_secret: CLIENT_SECRET,
|
|
208
|
+
{{/if}}
|
|
169
209
|
refresh_token: refreshToken,
|
|
170
210
|
}),
|
|
171
211
|
{ headers: { 'Content-Type': 'application/x-www-form-urlencoded' } },
|
|
@@ -204,3 +244,5 @@ router.get('/refresh', async (req, res) => {
|
|
|
204
244
|
});
|
|
205
245
|
|
|
206
246
|
module.exports = router;
|
|
247
|
+
// Exposed so server.js renders the same authorize URL the /login redirect uses.
|
|
248
|
+
module.exports.buildAuthorizeUrl = buildAuthorizeUrl;
|
|
@@ -14,11 +14,21 @@ if (!fs.existsSync(envPath)) {
|
|
|
14
14
|
|
|
15
15
|
require('dotenv').config({ path: envPath });
|
|
16
16
|
|
|
17
|
+
{{#if private}}
|
|
17
18
|
if (!process.env.CLIENT_ID || !process.env.CLIENT_SECRET) {
|
|
18
19
|
console.error('\nError: CLIENT_ID and CLIENT_SECRET must be set in .env.local');
|
|
19
20
|
console.error('Get your credentials with: brevo app credentials --reveal-secret\n');
|
|
20
21
|
process.exit(1);
|
|
21
22
|
}
|
|
23
|
+
{{/if}}
|
|
24
|
+
{{#if public}}
|
|
25
|
+
// Public apps use PKCE (RFC 7636) — no client secret is involved.
|
|
26
|
+
if (!process.env.CLIENT_ID) {
|
|
27
|
+
console.error('\nError: CLIENT_ID must be set in .env.local');
|
|
28
|
+
console.error('Get your credentials with: brevo app credentials\n');
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
{{/if}}
|
|
22
32
|
|
|
23
33
|
if (!process.env.OAUTH_BASE || process.env.OAUTH_BASE.startsWith('{{')) {
|
|
24
34
|
console.error('\nError: OAUTH_BASE is not set or contains a placeholder.');
|
|
@@ -33,24 +43,20 @@ if (!process.env.OAUTH_REALM || process.env.OAUTH_REALM.startsWith('{{')) {
|
|
|
33
43
|
|
|
34
44
|
const express = require('express');
|
|
35
45
|
const authRouter = require('./handler');
|
|
46
|
+
const { buildAuthorizeUrl } = authRouter;
|
|
36
47
|
|
|
37
48
|
const app = express();
|
|
38
49
|
const PORT = process.env.PORT || 3009;
|
|
39
50
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
+ `?response_type=code`
|
|
50
|
-
+ `&client_id=${encodeURIComponent(process.env.CLIENT_ID)}`
|
|
51
|
-
+ `&redirect_uri=${encodeURIComponent(REDIRECT_URI)}`
|
|
52
|
-
+ `&state=[random]`
|
|
53
|
-
+ `&scope=${encodeURIComponent(SCOPES)}`;
|
|
51
|
+
// Build the displayed authorization URL with the same helper /auth/login uses,
|
|
52
|
+
// so what the landing page shows always matches what the redirect actually
|
|
53
|
+
// sends. Placeholders (`[random]` state) stand in for the per-request values.
|
|
54
|
+
{{#if private}}
|
|
55
|
+
const AUTH_URL = buildAuthorizeUrl({ state: '[random]' });
|
|
56
|
+
{{/if}}
|
|
57
|
+
{{#if public}}
|
|
58
|
+
const AUTH_URL = buildAuthorizeUrl({ state: '[random]', codeChallenge: '[generated-per-login]' });
|
|
59
|
+
{{/if}}
|
|
54
60
|
|
|
55
61
|
app.use('/auth', authRouter);
|
|
56
62
|
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
let tokens = {};
|
|
4
4
|
let csrfState = null;
|
|
5
|
+
{{#if public}}
|
|
6
|
+
let codeVerifier = null;
|
|
7
|
+
{{/if}}
|
|
5
8
|
|
|
6
9
|
module.exports = {
|
|
7
10
|
saveTokens({ access_token, refresh_token, expires_in }) {
|
|
@@ -31,9 +34,25 @@ module.exports = {
|
|
|
31
34
|
getState() {
|
|
32
35
|
return csrfState;
|
|
33
36
|
},
|
|
37
|
+
{{#if public}}
|
|
38
|
+
|
|
39
|
+
// PKCE (RFC 7636): stash the code_verifier between /auth/login and
|
|
40
|
+
// /auth/callback. Same process-local, non-session-isolated limitation as the
|
|
41
|
+
// token store above — replace with your database in production.
|
|
42
|
+
setVerifier(verifier) {
|
|
43
|
+
codeVerifier = verifier;
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
getVerifier() {
|
|
47
|
+
return codeVerifier;
|
|
48
|
+
},
|
|
49
|
+
{{/if}}
|
|
34
50
|
|
|
35
51
|
clear() {
|
|
36
52
|
tokens = {};
|
|
37
53
|
csrfState = null;
|
|
54
|
+
{{#if public}}
|
|
55
|
+
codeVerifier = null;
|
|
56
|
+
{{/if}}
|
|
38
57
|
},
|
|
39
58
|
};
|