-
Notifications
You must be signed in to change notification settings - Fork 2
CLI v2: OAuth, JSON output, and automation-first overhaul #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nicped
wants to merge
120
commits into
main
Choose a base branch
from
v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
120 commits
Select commit
Hold shift + click to select a range
ed74ff5
Create README.md
frederik5480 eb1bfa7
Fixing bug in login command, adding query and command commands for ge…
frederik5480 8154759
Added interactive mode for queries, this will ask for each query para…
frederik5480 cf36e84
Updating readme
frederik5480 fdd6ca3
Removing latest option from swift, adding nightly option to swift
frederik5480 05268d5
Files are now being unzipped when extracting them
frederik5480 85d99fb
Fixing extract bug and changing addinprovider in install command to p…
frederik5480 ad789a4
Suggestion to code highlight command parameters
nicped c2f0aba
Fix missing
nicped d79c7c9
Merge pull request #1 from dynamicweb/parameter-highlight-in-readme
frederik5480 967a6fa
Moving uploadFile to files, adding flag to use with file and destination
frederik5480 ca55895
Merge pull request #2 from dynamicweb/feature/import-files
frederik5480 0afd0b3
Changing where we send form data to now send the new structure of { m…
frederik5480 4f6dd0a
Changing back the command command to simply just use the structure gi…
frederik5480 af72b77
Merge pull request #3 from dynamicweb/sending-json-over-formdata
frederik5480 a708b72
Update readme.md to reflect the management API json changes
frederik5480 e645f23
Fixes #8
frederik5480 bf1c74a
Updated readme.md
frederik5480 6b7b56a
Update readme.md
frederik5480 fec28e9
Update readme.me
frederik5480 ea6133b
Fixes #4
frederik5480 9171a1c
Fixes #7
frederik5480 724e5df
Merge pull request #13 from dynamicweb/bugfix/swift-out-path
frederik5480 e6db820
Merge pull request #12 from dynamicweb/files-exporting-fix
frederik5480 f68bdea
Adding proper content-type header for database command
frederik5480 3961bc9
Merge pull request #16 from dynamicweb/database-command-json-header
frederik5480 1d6b9cd
Fixes #15
frederik5480 903d571
Merge pull request #17 from dynamicweb/export-files-raw
frederik5480 a07e7c8
Update README.md
frederik5480 e374b6d
Fixing directory and file listing query not working
frederik5480 0841d03
Allowing setting protocol when setting up environments, https by default
frederik5480 480b8fd
Changing upload to use another endpoint specific for file upload inst…
frederik5480 ac14195
Merge branch 'main' into allow-protocols-for-environments
frederik5480 cbebde0
Merge pull request #18 from dynamicweb/files-upload-fix
nicped bcdcafe
Merge branch 'main' into allow-protocols-for-environments
frederik5480 e22a292
Merge pull request #19 from dynamicweb/allow-protocols-for-environments
frederik5480 76e4434
Fixing downloading of root files folder
frederik5480 91cda9a
Combining protocl and host in interactive, adding user messages when …
frederik5480 3b8df10
Changing api key to detail CLI instead of addin, letting files export…
frederik5480 202ced0
Merge pull request #21 from dynamicweb/error-messages-protocol-revamp
frederik5480 df14c32
Merge pull request #20 from dynamicweb/files-and-api-key-improvements
frederik5480 49d3611
Fixing dw install to the adjusted AddinInstall
frederik5480 70d27f2
Adding error response
frederik5480 7377db4
Removing console log line
frederik5480 c5ae1fc
Removing another log line
frederik5480 2b5c012
Merge pull request #22 from dynamicweb/frn/fixing-dw-install
frederik5480 2151ae2
Update package.json
frederik5480 9528e80
Allowing importing a folder to DW
frederik5480 0677922
Merge pull request #23 from dynamicweb/frn/allow-folder-upload
frederik5480 7e72957
Upping version
frederik5480 24b0d00
Allowing specifically setting protocol, host and apiKey for a CLI com…
frederik5480 38af9d4
Merge pull request #24 from dynamicweb/frn/procotol-host-apikey-override
frederik5480 e176f26
Creating missing directories when uploading files
frederik5480 06eb6b9
Removing old overwrite functionality, now relying on dw upload endpoi…
frederik5480 9911e41
Merge pull request #28 from dynamicweb/frn/files-overwrite-fix
frederik5480 d27e082
Adding missing argument for recursive import
frederik5480 e640214
Merge pull request #29 from dynamicweb/frn/files-create-subdir-fix
frederik5480 1495f8b
Adding overwrite when uploading addin when using dw install
frederik5480 dadc698
Merge pull request #30 from dynamicweb/frn/upload-addin-overwrite
frederik5480 08446a5
Adding exit code on errors and allowing wildcard for filenames in dw …
frederik5480 0a23192
Fix merge conflicts
frederik5480 fe83092
Merge pull request #31 from dynamicweb/frn/resolve-wildcard-filename-…
frederik5480 fcfc987
Fixing importing files and folders
frederik5480 2090d68
Merge pull request #32 from dynamicweb/frn/import-files-and-folders-b…
frederik5480 2cd44fd
Adding + as a valid filename when uploading and fixing i and l for qu…
frederik5480 2ae819c
Merge pull request #33 from dynamicweb/frn/query-list-and-filename-fix
frederik5480 b0cde46
Fixed wildcard replace logic
dw-jea cf15b19
Merge pull request #34 from dynamicweb/jea/file-upload-fails
frederik5480 1aefd16
Upping version
frederik5480 6d581e3
Fixing dw login and adding queue property to dw install
frederik5480 e3b35e2
Improved the download experience
dw-jea 100430a
Merge pull request #37 from dynamicweb/jea/downloader-improvements
dw-jea 80ee293
Upping to v 1.0.14
frederik5480 ef8d03e
Do not throw error on download
dw-jea 3b0b1f4
Merge pull request #39 from dynamicweb/jea/do-not-throw-error-if-file…
dw-jea 2944cbb
Version change to 1.0.15
dw-jea d76ff39
Added possibility to export single file by using 'dw files {file path…
StanislavSmetaninSSM ad8cc9f
Added warning which shows when open CLI from Git Bash with enabled pa…
StanislavSmetaninSSM f394e03
Changes according to code review.
StanislavSmetaninSSM a030605
Merge pull request #43 from dynamicweb/ssm/25797-git_bash_issue
StanislavSmetaninSSM dfe3bb6
Merge branch 'main' into ssm/24794-download_single_file
StanislavSmetaninSSM a2d3b50
Merge pull request #42 from dynamicweb/ssm/24794-download_single_file
StanislavSmetaninSSM e9dfe4c
Implemented chunked upload
dw-jea 940acc8
Merge pull request #44 from dynamicweb/jea/25494-upload-files-in-chunks
dw-jea ba771aa
Updated version number to 1.0.16
dw-jea bd79e86
Update env.js
nicped 9a49729
Update files.js
nicped c62ff49
Update env.js
nicped a1959a2
Replace yargs-interactive with @inquirer/prompts and clean up depende…
nicped 7796637
Fix multiple bugs across the CLI codebase
nicped 240c48b
Merge pull request #45 from dynamicweb/nicped-patch-1-1
nicped bfc1e32
Merge pull request #46 from dynamicweb/nicped-patch-1
nicped 5a0b98a
Bump version to 1.1.0
nicped 57b753c
Prepare npm package for publish
nicped eb1cf1d
Enhance download functionality with verbose logging and parameter upd…
nicped 4866e98
Bump
nicped dbeed54
Add CLI v2 documentation article
nicped 0cb0502
CLI v2: OAuth, JSON output, automation-first overhaul
nicped f4b3fb5
Add delete, copy, and move operations to the files command
nicped 9b366ed
Add changelog and what's new section for v2
nicped 3fd5ce9
Refactor command handling and improve output logging across CLI commands
nicped a664294
Fix JSON mode issues: skip interactive prompts, respect --host overri…
nicped 472778d
Refactor command error handling: consolidate createCommandError funct…
nicped a7c20e2
Update Swift version in documentation examples to v2.3.0
nicped 4219653
Add CLAUDE.md for project documentation and enhance file upload logging
nicped 5474983
Fix install upload output handling
nicped a08d5ea
Bump version to 1.1.2
nicped b8b7758
Merge pull request #48 from dynamicweb/fix/install-output-envelope
nicped 32ba49c
Add unit test suite and QA smoke harness; export internal functions f…
nicped 5623304
Refactor command handling and improve error handling across multiple …
nicped 7017369
Bump version
nicped a4b5de5
Merge branch 'main' into v2
nicped 48fb464
Update README to clarify CLI functionality and improve tool comparison
nicped 6da8cf9
Fix duplicate parseJsonSafe in files.js, OAuth login with --host boot…
nicped da460b4
Bump version to 2.0.0-preview.1 and switch status codes from HTTP to 0/1
nicped 5a88a21
Update README to reflect status code changes from HTTP 200 to 0 for c…
nicped 3361360
Update README to reflect branch target change from 2.0.0-beta.0 to 2.…
nicped cd65abb
Add dw folders command and bump version to 2.0.0-preview.2
nicped 35314f0
Fix --oauth not recognized on non-login commands and stale env read a…
nicped 3852e9f
Add support for --oauth option for OAuth client credentials authentic…
nicped File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Changelog | ||
|
|
||
| ## 2.0.0-beta.0 | ||
|
|
||
| ### Breaking changes | ||
|
|
||
| - **Version bumped to 2.0.0** -- this release contains breaking changes to command output, option names, and authentication behavior. | ||
| - **`--json` flag replaced by `--output json`** -- the old `--json` flag is deprecated and will be removed in a future release. All commands now use `--output json` for structured output. | ||
| - **`--iamstupid` replaced by `--dangerouslyIncludeLogsAndCache`** -- the old flag is deprecated and will be removed in a future release. | ||
| - **Error handling changed** -- commands that previously printed an error and exited silently now throw structured errors. In JSON mode, errors are returned in the `errors` array with `ok: false`. The CLI exits with code `1` on any error. | ||
|
|
||
| ### New features | ||
|
|
||
| - **OAuth client credentials authentication** -- the CLI now supports OAuth 2.0 client credentials for headless and CI/CD authentication. Use `dw login --oauth` to configure an environment, or pass `--auth oauth` with `--clientIdEnv`/`--clientSecretEnv` (or `--clientId`/`--clientSecret`) on any command. | ||
| - **Structured JSON output on all API commands** -- `env`, `login`, `files`, `query`, `command`, and `install` all support `--output json`, returning a consistent envelope with `ok`, `command`, `operation`, `status`, `data`, `errors`, and `meta` fields. | ||
| - **File delete operations** -- `dw files <path> --delete` removes files and directories from the environment. Combine with `--empty` to clear a directory without removing it. | ||
| - **File copy operations** -- `dw files <path> --copy <destination>` copies files and directories within the environment. | ||
| - **File move operations** -- `dw files <path> --move <destination>` moves files and directories within the environment. Combine with `--overwrite` to replace existing files at the destination. | ||
| - **Global OAuth flags** -- `--auth`, `--clientId`, `--clientSecret`, `--clientIdEnv`, and `--clientSecretEnv` are available as global options on all commands. | ||
| - **Authentication precedence** -- when multiple auth indicators are present, the CLI resolves them in order: `--apiKey` > OAuth > saved user > interactive prompt. Use `--auth user` to force user auth when an environment is configured for OAuth. | ||
| - **Base command shows auth type** -- `dw` with no arguments now displays the current authentication type (OAuth or user) alongside environment info. | ||
|
|
||
| ### Improvements | ||
|
|
||
| - **Consistent error model** -- all commands use a shared `createCommandError` helper that produces errors with `message`, `status`, and `details`. In JSON mode these are serialized into the `errors` array. | ||
| - **Human output suppressed in JSON mode** -- when `--output json` is active, all `console.log` output is suppressed. Only the JSON envelope is written to stdout, making it safe to pipe. | ||
| - **Interactive prompts skipped in JSON mode** -- delete confirmations and other interactive prompts are skipped when `--output json` is set, enabling fully non-interactive scripted usage. | ||
| - **Better host override handling** -- `--host` now works with OAuth credentials, not just `--apiKey`. | ||
| - **Null-safe config access** -- environment and user lookups use optional chaining to avoid crashes on missing config keys. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## Project Overview | ||
|
|
||
| `@dynamicweb/cli` is a Node.js CLI (`dw`) for managing DynamicWeb 10 CMS solutions. It handles authentication, file archive operations, Admin API queries/commands, add-in installation, database exports, and Swift release downloads. The binary is registered as `dw`. | ||
|
|
||
| ## Development Setup | ||
|
|
||
| ```bash | ||
| npm install | ||
| npm install -g . # Makes 'dw' available globally from source | ||
| dw --help | ||
| ``` | ||
|
|
||
| No build step — pure ESM JavaScript (`"type": "module"`), Node.js >=20.12.0 required. | ||
|
|
||
| No test framework or linting is configured yet. | ||
|
|
||
| ## Code Architecture | ||
|
|
||
| ### Entry Point | ||
|
|
||
| [bin/index.js](bin/index.js) bootstraps yargs with global options and registers all commands. `setupConfig()` runs at startup to initialize `~/.dwc`. | ||
|
|
||
| ### Command Structure | ||
|
|
||
| All commands live in [bin/commands/](bin/commands/). Each exports a `*Command()` function returning a yargs command object with `command`, `describe`, `builder`, and `handler` properties. | ||
|
|
||
| Every command handler follows the same pattern: | ||
|
|
||
| ```js | ||
| handler: async (argv) => { | ||
| const output = createXxxOutput(argv); // local output envelope | ||
| try { | ||
| let env = await setupEnv(argv, output); // from env.js | ||
| let user = await setupUser(argv, env); // from login.js | ||
| // ... API calls with node-fetch | ||
| } catch (err) { | ||
| output.fail(err); | ||
| process.exitCode = 1; | ||
| } finally { | ||
| output.finish(); // prints JSON if --output json | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Key Shared Modules | ||
|
|
||
| - **[bin/commands/env.js](bin/commands/env.js)** — `setupEnv()`, `getAgent()` (keep-alive HTTP/HTTPS agents), `createCommandError()`, `isJsonOutput()`, `interactiveEnv()` | ||
| - **[bin/commands/login.js](bin/commands/login.js)** — `setupUser()`, OAuth token fetch, interactive login, API key creation | ||
| - **[bin/commands/config.js](bin/commands/config.js)** — `getConfig()`, `updateConfig()`, `setupConfig()` — manages `~/.dwc` JSON file | ||
| - **[bin/utils.js](bin/utils.js)** — `createThrottledStatusUpdater()` (500ms throttle), `formatBytes()`, `formatElapsed()` | ||
| - **[bin/downloader.js](bin/downloader.js)** — streams HTTP responses with a progress callback | ||
| - **[bin/extractor.js](bin/extractor.js)** — ZIP extraction with progress callback | ||
|
|
||
| ### Output Envelope | ||
|
|
||
| Each command creates a local output object (see `createEnvOutput` in [bin/commands/env.js:256](bin/commands/env.js#L256) as the canonical example): | ||
|
|
||
| ```js | ||
| { ok, command, operation, status, data: [], errors: [], meta: {} } | ||
| ``` | ||
|
|
||
| - `output.addData(entry)` — push to `data[]` | ||
| - `output.log(...args)` — console.log only when not in JSON mode | ||
| - `output.fail(err)` — sets `ok: false`, pushes to `errors[]` | ||
| - `output.finish()` — prints `JSON.stringify(response)` if `--output json` | ||
|
|
||
| ### Authentication | ||
|
|
||
| `shouldUseOAuth()` in [bin/commands/login.js](bin/commands/login.js) decides auth mode from flags, env config, or CLI args. Both paths converge to `user.apiKey` for API calls. | ||
|
|
||
| - **User auth**: interactive login → creates a DW API key stored in `~/.dwc` | ||
| - **OAuth**: fetches access token from `/Admin/OAuth/token`; token not cached between commands | ||
|
|
||
| ### Config File (`~/.dwc`) | ||
|
|
||
| ```json | ||
| { | ||
| "env": { | ||
| "<name>": { | ||
| "host": "localhost:6001", | ||
| "protocol": "https", | ||
| "users": { "<username>": { "apiKey": "prefix.key" } }, | ||
| "auth": { "type": "oauth_client_credentials", "clientIdEnv": "...", "clientSecretEnv": "..." }, | ||
| "current": { "user": "...", "authType": "user|oauth_client_credentials" } | ||
| } | ||
| }, | ||
| "current": { "env": "<name>" } | ||
| } | ||
| ``` | ||
|
|
||
| ### Global CLI Flags | ||
|
|
||
| All commands inherit: `--verbose/-v`, `--host`, `--protocol`, `--apiKey`, `--auth user|oauth`, `--clientId`, `--clientSecret`, `--clientIdEnv`, `--clientSecretEnv`, `--output json`. | ||
|
|
||
| When `--output json` is set, interactive prompts are skipped and the structured envelope is printed to stdout. All other logging must go through `output.log()` (not `console.log()` directly) so it is suppressed in JSON mode. | ||
|
|
||
| ### HTTPS Agent | ||
|
|
||
| The HTTPS agent in [bin/commands/env.js:13](bin/commands/env.js#L13) sets `rejectUnauthorized: false` intentionally to support self-signed certificates in dev environments. | ||
|
|
||
| ### Git Bash Warning | ||
|
|
||
| On Windows Git Bash (`MSYSTEM` env var set), the CLI warns about path conversion unless `MSYS_NO_PATHCONV=1`. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.