From 7d552701dc31b52bef0ad3605c609213fec06d76 Mon Sep 17 00:00:00 2001 From: Kim Gustyr Date: Thu, 16 Jul 2026 15:56:34 +0100 Subject: [PATCH 01/89] =?UTF-8?q?feat!:=20rewrite=20as=20a=20Go=20CLI=20?= =?UTF-8?q?=E2=80=94=20browser=20OAuth=20login=20PoC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove the TypeScript/oclif CLI entirely and start over in Go + cobra, per the installation & auth design (docs/design/001-installation-and-auth.md). The PoC implements interactive auth against the core OAuth 2.1 server (Flagsmith/flagsmith#8029): - `flagsmith login`: authorization-code + PKCE on a loopback listener (literal 127.0.0.1/[::1], RFC 8252), endpoints discovered via RFC 8414 metadata, explicit `management-api` scope, `--no-browser` for headless - credentials in the OS keychain, 0600-file fallback - `flagsmith auth status` / `auth token`: transparent refresh-token rotation (server grace period 120s) - `flagsmith logout`: server-side revocation + local removal Verified end-to-end against ghcr.io/flagsmith/flagsmith:pr-8029. beep boop --- .editorconfig | 11 - .eslintignore | 1 - .eslintrc | 6 - .gitignore | 15 +- .mocharc.json | 12 - .nvmrc | 1 - .release-please-manifest.json | 1 - CHANGELOG.md | 80 - README.md | 143 +- bin/dev | 17 - bin/dev.cmd | 3 - bin/run | 5 - bin/run.cmd | 3 - docs/design/001-installation-and-auth.md | 147 + example/.gitignore | 25 - example/README.md | 17 - example/package-lock.json | 29634 --------------------- example/package.json | 48 - example/public/favicon.ico | Bin 3870 -> 0 bytes example/public/index.html | 43 - example/public/logo192.png | Bin 5347 -> 0 bytes example/public/logo512.png | Bin 9664 -> 0 bytes example/public/manifest.json | 25 - example/public/robots.txt | 3 - example/src/App.tsx | 29 - example/src/index.css | 13 - example/src/index.tsx | 13 - example/tsconfig.json | 26 - go.mod | 17 + go.sum | 31 + internal/api/client.go | 39 + internal/auth/oauth.go | 268 + internal/auth/store.go | 108 + internal/cmd/auth.go | 74 + internal/cmd/login.go | 46 + internal/cmd/logout.go | 38 + internal/cmd/root.go | 32 + main.go | 7 + package.json | 81 - release-please-config.json | 62 - src/commands/get/index.ts | 120 - src/index.ts | 1 - tsconfig.json | 15 - 43 files changed, 826 insertions(+), 30434 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintignore delete mode 100644 .eslintrc delete mode 100644 .mocharc.json delete mode 100644 .nvmrc delete mode 100644 .release-please-manifest.json delete mode 100644 CHANGELOG.md delete mode 100755 bin/dev delete mode 100644 bin/dev.cmd delete mode 100755 bin/run delete mode 100644 bin/run.cmd create mode 100644 docs/design/001-installation-and-auth.md delete mode 100644 example/.gitignore delete mode 100644 example/README.md delete mode 100644 example/package-lock.json delete mode 100644 example/package.json delete mode 100644 example/public/favicon.ico delete mode 100644 example/public/index.html delete mode 100644 example/public/logo192.png delete mode 100644 example/public/logo512.png delete mode 100644 example/public/manifest.json delete mode 100644 example/public/robots.txt delete mode 100644 example/src/App.tsx delete mode 100644 example/src/index.css delete mode 100644 example/src/index.tsx delete mode 100644 example/tsconfig.json create mode 100644 go.mod create mode 100644 go.sum create mode 100644 internal/api/client.go create mode 100644 internal/auth/oauth.go create mode 100644 internal/auth/store.go create mode 100644 internal/cmd/auth.go create mode 100644 internal/cmd/login.go create mode 100644 internal/cmd/logout.go create mode 100644 internal/cmd/root.go create mode 100644 main.go delete mode 100644 package.json delete mode 100644 release-please-config.json delete mode 100644 src/commands/get/index.ts delete mode 100644 src/index.ts delete mode 100644 tsconfig.json diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index beffa30..0000000 --- a/.editorconfig +++ /dev/null @@ -1,11 +0,0 @@ -root = true - -[*] -indent_style = space -indent_size = 2 -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -[*.md] -trim_trailing_whitespace = false diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 9b1c8b1..0000000 --- a/.eslintignore +++ /dev/null @@ -1 +0,0 @@ -/dist diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 7b84619..0000000 --- a/.eslintrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": [ - "oclif", - "oclif-typescript" - ] -} diff --git a/.gitignore b/.gitignore index 12865b1..a94b49e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,3 @@ -*-debug.log -*-error.log -/.nyc_output -/dist -/lib -/package-lock.json -/tmp -/yarn.lock -node_modules -oclif.manifest.json -.idea -flagsmith.json +/flagsmith +/dist/ +*.test diff --git a/.mocharc.json b/.mocharc.json deleted file mode 100644 index 4a09d14..0000000 --- a/.mocharc.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "require": [ - "test/helpers/init.js", - "ts-node/register" - ], - "watch-extensions": [ - "ts" - ], - "recursive": true, - "reporter": "spec", - "timeout": 60000 -} diff --git a/.nvmrc b/.nvmrc deleted file mode 100644 index a45fd52..0000000 --- a/.nvmrc +++ /dev/null @@ -1 +0,0 @@ -24 diff --git a/.release-please-manifest.json b/.release-please-manifest.json deleted file mode 100644 index 8d6e472..0000000 --- a/.release-please-manifest.json +++ /dev/null @@ -1 +0,0 @@ -{".":"1.1.0"} diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index eafae8c..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,80 +0,0 @@ -# Changelog - -## [1.1.0](https://github.com/Flagsmith/flagsmith-cli/compare/v1.0.0...v1.1.0) (2026-05-27) - - -### Features - -* migrate npm package to [@flagsmith](https://github.com/flagsmith) organization scope ([#40](https://github.com/Flagsmith/flagsmith-cli/issues/40)) ([3b96bf3](https://github.com/Flagsmith/flagsmith-cli/commit/3b96bf33ed5d4397430381c65e9417b216b2e0e8)) - - -### CI - -* add NPM trusted publishing and release please ([#33](https://github.com/Flagsmith/flagsmith-cli/issues/33)) ([d6fe2bc](https://github.com/Flagsmith/flagsmith-cli/commit/d6fe2bc84accaae327d7afe6ac71f86b82337d7c)) -* fix npm trusted publishing ([#36](https://github.com/Flagsmith/flagsmith-cli/issues/36)) ([f76d21c](https://github.com/Flagsmith/flagsmith-cli/commit/f76d21c4e6d9f036237de92a1621fd9994c41346)) - - -### Other - -* Add build and test workflow, fix npm audit issues ([fa5d5da](https://github.com/Flagsmith/flagsmith-cli/commit/fa5d5da19e1ae552ca2c93a9f2473f9287ec9630)) -* **main:** release 0.2.2 ([#34](https://github.com/Flagsmith/flagsmith-cli/issues/34)) ([7759431](https://github.com/Flagsmith/flagsmith-cli/commit/775943112431f5ad40a9b196023c2f466d17a44d)) -* **main:** release 0.2.3 ([#37](https://github.com/Flagsmith/flagsmith-cli/issues/37)) ([80a5064](https://github.com/Flagsmith/flagsmith-cli/commit/80a50645d20af1924ca8f55b1c017bb655e834a3)) -* Remove amannn/action-semantic-pull-request workflow ([#38](https://github.com/Flagsmith/flagsmith-cli/issues/38)) ([a069831](https://github.com/Flagsmith/flagsmith-cli/commit/a0698319d3def4461ac3344a89f30a092b30e48c)) - -## [0.2.3](https://github.com/Flagsmith/flagsmith-cli/compare/v0.2.2...v0.2.3) (2025-11-24) - - -### CI - -* fix npm trusted publishing ([#36](https://github.com/Flagsmith/flagsmith-cli/issues/36)) ([f76d21c](https://github.com/Flagsmith/flagsmith-cli/commit/f76d21c4e6d9f036237de92a1621fd9994c41346)) - -## [0.2.2](https://github.com/Flagsmith/flagsmith-cli/compare/0.2.1...v0.2.2) (2025-11-06) - - -### CI - -* add NPM trusted publishing and release please ([#33](https://github.com/Flagsmith/flagsmith-cli/issues/33)) ([d6fe2bc](https://github.com/Flagsmith/flagsmith-cli/commit/d6fe2bc84accaae327d7afe6ac71f86b82337d7c)) - - -### Other - -* Add build and test workflow, fix npm audit issues ([fa5d5da](https://github.com/Flagsmith/flagsmith-cli/commit/fa5d5da19e1ae552ca2c93a9f2473f9287ec9630)) - - -## [0.2.1 - Update Flagsmith sdk](https://github.com/Flagsmith/flagsmith-cli/releases/tag/0.2.1) - 2025-03-20 - -Merges [#25](https://github.com/Flagsmith/flagsmith-cli/pull/25) - -[Changes][0.2.1] - - - -## [0.1.3 - Adds prettify flag -p](https://github.com/Flagsmith/flagsmith-cli/releases/tag/0.1.3) - 2023-05-29 - -[#12](https://github.com/Flagsmith/flagsmith-cli/pull/12) - -[Changes][0.1.3] - - - -## [0.1.2 - Add Identity flag -i](https://github.com/Flagsmith/flagsmith-cli/releases/tag/0.1.2) - 2023-05-29 - -[#11](https://github.com/Flagsmith/flagsmith-cli/pull/11) - -[Changes][0.1.2] - - - -## [0.1.1 - Fix api-input in a wrong const](https://github.com/Flagsmith/flagsmith-cli/releases/tag/0.1.1) - 2023-01-20 - -Merges [#10](https://github.com/Flagsmith/flagsmith-cli/pull/10), thank you very much [@vladaCizek](https://github.com/vladaCizek)! πŸš€ - -[Changes][0.1.1] - - -[0.2.1]: https://github.com/Flagsmith/flagsmith-cli/compare/0.1.3...0.2.1 -[0.1.3]: https://github.com/Flagsmith/flagsmith-cli/compare/0.1.2...0.1.3 -[0.1.2]: https://github.com/Flagsmith/flagsmith-cli/compare/0.1.1...0.1.2 -[0.1.1]: https://github.com/Flagsmith/flagsmith-cli/tree/0.1.1 - - diff --git a/README.md b/README.md index 0e7e3cc..4b61b4b 100644 --- a/README.md +++ b/README.md @@ -1,137 +1,26 @@ - +# Flagsmith CLI -@flagsmith/cli -================= +The next-generation Flagsmith command-line interface. Currently a proof of +concept focused on installation and authentication β€” see +[docs/design/001-installation-and-auth.md](docs/design/001-installation-and-auth.md). -Retrieve Flagsmith state from an API and store it in a file. +## Build -This CLI can be used to bake default flags into your application as part of CI/CD, this provides support for offline applications and is also advised as part of our [Defensive Coding and Default Flags Documentation](https://docs.flagsmith.com/guides-and-examples/defensive-coding). An example of this can be seen [here](./example). - - -# Populating defaultFlags in your Project - -The steps to using this to provide default flags are as follows. An example of this can be found [here](./example). The main steps to achieving this are as follows: - - -1. Install the cli ``npm i @flagsmith/cli --save-dev`` -2. Call the cli as part of postinstall to create a ``flagsmith.json`` file: - -```export FLAGSMITH_ENVIRONMENT=API_KEY``` - -``` -"postinstall": "flagsmith get" +```sh +go build -o flagsmith . ``` -An example of this can be seen [here](./example/src/index.tsx). -3. In your application, import the outputted JSON and initialise the client with the json ``flagsmith.init({state:json, environmentID: json.environmentID})`` -**Example:** +## Use -```typescript -import flagsmith from '@flagsmith/flagsmith' -import state from './flagsmith.json' - -flagsmith.init({state, environmentID: state.environmentID}) +```sh +flagsmith login # browser-based OAuth (PKCE, loopback) +flagsmith auth status # identity, credential source, token expiry +flagsmith auth token # print an access token for curl/scripts +flagsmith logout # revoke and remove the stored session ``` -**Example with React:** - -```jsx -import state from './flagsmith.json' -ReactDOM.render( - - - , - document.getElementById('root') -); -``` - - -# Usage - Global - -```sh-session -$ npm install -g @flagsmith/cli -$ flagsmith COMMAND -running command... -$ flagsmith (--version) -flagsmith-cli/0.1.2 darwin-arm64 node-v18.13.0 -$ flagsmith --help [COMMAND] -USAGE - $ flagsmith COMMAND -... -``` - -# Commands - -* [`flagsmith get [ENVIRONMENT]`](#flagsmith-get-environment) -* [`flagsmith help [COMMANDS]`](#flagsmith-help-commands) - -## `flagsmith get [ENVIRONMENT]` - -Retrieve flagsmith features from the Flagsmith API and output them to a file. - -``` -USAGE - $ flagsmith get [ENVIRONMENT] [-o ] [-a ] [-t - -i ] [-p] [-e flags|environment] - -ARGUMENTS - ENVIRONMENT The flagsmith environment key to use, defaults to the environment - variable FLAGSMITH_ENVIRONMENT - -FLAGS - -a, --api= [default: https://edge.api.flagsmith.com/api/v1/] The - API URL to fetch the feature flags from - -e, --entity=